diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0862a65 --- /dev/null +++ b/Makefile @@ -0,0 +1,495 @@ +# Top-level Mesa makefile + +TOP = . + +SUBDIRS = src + + +default: $(TOP)/configs/current + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE)) || exit 1 ; \ + fi \ + done + +all: default + + +doxygen: + cd doxygen && $(MAKE) + +clean: + -@touch $(TOP)/configs/current + -@for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) clean) ; \ + fi \ + done + -@test -s $(TOP)/configs/current || rm -f $(TOP)/configs/current + + +realclean: clean + -rm -rf lib* + -rm -f $(TOP)/configs/current + -rm -f $(TOP)/configs/autoconf + -rm -rf autom4te.cache + -find . '(' -name '*.o' -o -name '*.a' -o -name '*.so' -o \ + -name depend -o -name depend.bak ')' -exec rm -f '{}' ';' + + +distclean: realclean + + +install: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) install) || exit 1 ; \ + fi \ + done + + +.PHONY: default doxygen clean realclean distclean install + +# If there's no current configuration file +$(TOP)/configs/current: + @echo + @echo + @echo "Please choose a configuration from the following list:" + @ls -1 $(TOP)/configs | grep -v "current\|default\|CVS\|autoconf.*" + @echo + @echo "Then type 'make ' (ex: 'make linux-x86')" + @echo + @echo "Or, run './configure' then 'make'" + @echo "See './configure --help' for details" + @echo + @echo "(ignore the following error message)" + @exit 1 + + +# Rules to set/install a specific build configuration +aix \ +aix-64 \ +aix-64-static \ +aix-gcc \ +aix-static \ +autoconf \ +bluegene-osmesa \ +bluegene-xlc-osmesa \ +beos \ +catamount-osmesa-pgi \ +darwin \ +darwin-fat-32bit \ +darwin-fat-all \ +freebsd \ +freebsd-dri \ +freebsd-dri-amd64 \ +freebsd-dri-x86 \ +hpux10 \ +hpux10-gcc \ +hpux10-static \ +hpux11-32 \ +hpux11-32-static \ +hpux11-32-static-nothreads \ +hpux11-64 \ +hpux11-64-static \ +hpux11-ia64 \ +hpux11-ia64-static \ +hpux9 \ +hpux9-gcc \ +irix6-64 \ +irix6-64-static \ +irix6-n32 \ +irix6-n32-static \ +irix6-o32 \ +irix6-o32-static \ +linux \ +linux-i965 \ +linux-alpha \ +linux-alpha-static \ +linux-cell \ +linux-cell-debug \ +linux-debug \ +linux-dri \ +linux-dri-debug \ +linux-dri-x86 \ +linux-dri-x86-64 \ +linux-dri-ppc \ +linux-dri-xcb \ +linux-egl \ +linux-indirect \ +linux-fbdev \ +linux-ia64-icc \ +linux-ia64-icc-static \ +linux-icc \ +linux-icc-static \ +linux-llvm \ +linux-llvm-debug \ +linux-opengl-es \ +linux-osmesa \ +linux-osmesa-static \ +linux-osmesa16 \ +linux-osmesa16-static \ +linux-osmesa32 \ +linux-ppc \ +linux-ppc-static \ +linux-profile \ +linux-sparc \ +linux-sparc5 \ +linux-static \ +linux-ultrasparc \ +linux-tcc \ +linux-x86 \ +linux-x86-debug \ +linux-x86-32 \ +linux-x86-64 \ +linux-x86-64-debug \ +linux-x86-64-profile \ +linux-x86-64-static \ +linux-x86-profile \ +linux-x86-static \ +netbsd \ +openbsd \ +osf1 \ +osf1-static \ +solaris-x86 \ +solaris-x86-gcc \ +solaris-x86-gcc-static \ +sunos4 \ +sunos4-gcc \ +sunos4-static \ +sunos5 \ +sunos5-gcc \ +sunos5-64-gcc \ +sunos5-smp \ +sunos5-v8 \ +sunos5-v8-static \ +sunos5-v9 \ +sunos5-v9-static \ +sunos5-v9-cc-g++ \ +ultrix-gcc: + @ if test -f configs/current -o -L configs/current; then \ + if ! cmp configs/$@ configs/current > /dev/null; then \ + echo "Please run 'make realclean' before changing configs" ; \ + exit 1 ; \ + fi ; \ + else \ + cd configs && rm -f current && ln -s $@ current ; \ + fi + $(MAKE) default + + +# Rules for making release tarballs + +VERSION=7.10.2 +DIRECTORY = Mesa-$(VERSION) +LIB_NAME = MesaLib-$(VERSION) +GLUT_NAME = MesaGLUT-$(VERSION) + +# This is part of MAIN_FILES +MAIN_ES_FILES = \ + $(DIRECTORY)/src/mesa/main/*.xml \ + $(DIRECTORY)/src/mesa/main/*.py \ + $(DIRECTORY)/src/mesa/main/*.dtd + +MAIN_FILES = \ + $(DIRECTORY)/Makefile* \ + $(DIRECTORY)/configure \ + $(DIRECTORY)/configure.ac \ + $(DIRECTORY)/acinclude.m4 \ + $(DIRECTORY)/aclocal.m4 \ + $(DIRECTORY)/bin/config.guess \ + $(DIRECTORY)/bin/config.sub \ + $(DIRECTORY)/bin/install-sh \ + $(DIRECTORY)/bin/mklib \ + $(DIRECTORY)/bin/minstall \ + $(DIRECTORY)/bin/version.mk \ + $(DIRECTORY)/configs/[a-z]* \ + $(DIRECTORY)/docs/*.html \ + $(DIRECTORY)/docs/COPYING \ + $(DIRECTORY)/docs/README.* \ + $(DIRECTORY)/docs/RELNOTES* \ + $(DIRECTORY)/docs/*.spec \ + $(DIRECTORY)/include/GL/gl.h \ + $(DIRECTORY)/include/GL/glext.h \ + $(DIRECTORY)/include/GL/gl_mangle.h \ + $(DIRECTORY)/include/GL/glu.h \ + $(DIRECTORY)/include/GL/glu_mangle.h \ + $(DIRECTORY)/include/GL/glx.h \ + $(DIRECTORY)/include/GL/glxext.h \ + $(DIRECTORY)/include/GL/glx_mangle.h \ + $(DIRECTORY)/include/GL/glfbdev.h \ + $(DIRECTORY)/include/GL/mesa_wgl.h \ + $(DIRECTORY)/include/GL/osmesa.h \ + $(DIRECTORY)/include/GL/vms_x_fix.h \ + $(DIRECTORY)/include/GL/wglext.h \ + $(DIRECTORY)/include/GL/wmesa.h \ + $(DIRECTORY)/src/glsl/Makefile \ + $(DIRECTORY)/src/glsl/Makefile.template \ + $(DIRECTORY)/src/glsl/SConscript \ + $(DIRECTORY)/src/glsl/*.[ch] \ + $(DIRECTORY)/src/glsl/*.[cly]pp \ + $(DIRECTORY)/src/glsl/README \ + $(DIRECTORY)/src/glsl/glcpp/*.[chly] \ + $(DIRECTORY)/src/glsl/glcpp/README \ + $(DIRECTORY)/src/Makefile \ + $(DIRECTORY)/src/mesa/Makefile* \ + $(DIRECTORY)/src/mesa/sources.mak \ + $(DIRECTORY)/src/mesa/descrip.mms \ + $(DIRECTORY)/src/mesa/gl.pc.in \ + $(DIRECTORY)/src/mesa/osmesa.pc.in \ + $(DIRECTORY)/src/mesa/depend \ + $(MAIN_ES_FILES) \ + $(DIRECTORY)/src/mesa/main/*.[chS] \ + $(DIRECTORY)/src/mesa/main/descrip.mms \ + $(DIRECTORY)/src/mesa/math/*.[ch] \ + $(DIRECTORY)/src/mesa/math/descrip.mms \ + $(DIRECTORY)/src/mesa/program/*.[chly] \ + $(DIRECTORY)/src/mesa/program/*.cpp \ + $(DIRECTORY)/src/mesa/program/Makefile \ + $(DIRECTORY)/src/mesa/program/descrip.mms \ + $(DIRECTORY)/src/mesa/swrast/*.[ch] \ + $(DIRECTORY)/src/mesa/swrast/descrip.mms \ + $(DIRECTORY)/src/mesa/swrast_setup/*.[ch] \ + $(DIRECTORY)/src/mesa/swrast_setup/descrip.mms \ + $(DIRECTORY)/src/mesa/vbo/*.[chS] \ + $(DIRECTORY)/src/mesa/vbo/descrip.mms \ + $(DIRECTORY)/src/mesa/tnl/*.[chS] \ + $(DIRECTORY)/src/mesa/tnl/descrip.mms \ + $(DIRECTORY)/src/mesa/tnl_dd/*.[ch] \ + $(DIRECTORY)/src/mesa/tnl_dd/imm/*.[ch] \ + $(DIRECTORY)/src/mesa/tnl_dd/imm/NOTES.imm \ + $(DIRECTORY)/src/mesa/drivers/Makefile \ + $(DIRECTORY)/src/mesa/drivers/beos/*.cpp \ + $(DIRECTORY)/src/mesa/drivers/beos/Makefile \ + $(DIRECTORY)/src/mesa/drivers/common/*.[ch] \ + $(DIRECTORY)/src/mesa/drivers/common/descrip.mms \ + $(DIRECTORY)/src/mesa/drivers/fbdev/Makefile \ + $(DIRECTORY)/src/mesa/drivers/fbdev/glfbdev.c \ + $(DIRECTORY)/src/mesa/drivers/osmesa/Makefile \ + $(DIRECTORY)/src/mesa/drivers/osmesa/Makefile.win \ + $(DIRECTORY)/src/mesa/drivers/osmesa/descrip.mms \ + $(DIRECTORY)/src/mesa/drivers/osmesa/osmesa.def \ + $(DIRECTORY)/src/mesa/drivers/osmesa/*.[ch] \ + $(DIRECTORY)/src/mesa/drivers/windows/*/*.[ch] \ + $(DIRECTORY)/src/mesa/drivers/windows/*/*.def \ + $(DIRECTORY)/src/mesa/drivers/x11/Makefile \ + $(DIRECTORY)/src/mesa/drivers/x11/descrip.mms \ + $(DIRECTORY)/src/mesa/drivers/x11/*.[ch] \ + $(DIRECTORY)/src/mesa/ppc/*.[ch] \ + $(DIRECTORY)/src/mesa/sparc/*.[chS] \ + $(DIRECTORY)/src/mesa/x86/Makefile \ + $(DIRECTORY)/src/mesa/x86/*.[ch] \ + $(DIRECTORY)/src/mesa/x86/*.S \ + $(DIRECTORY)/src/mesa/x86/rtasm/*.[ch] \ + $(DIRECTORY)/src/mesa/x86-64/*.[chS] \ + $(DIRECTORY)/src/mesa/x86-64/Makefile \ + $(DIRECTORY)/windows/VC8/ + +MAPI_FILES = \ + $(DIRECTORY)/include/GLES/*.h \ + $(DIRECTORY)/include/GLES2/*.h \ + $(DIRECTORY)/include/VG/*.h \ + $(DIRECTORY)/src/mapi/es?api/Makefile \ + $(DIRECTORY)/src/mapi/es?api/*.pc.in \ + $(DIRECTORY)/src/mapi/glapi/gen/Makefile \ + $(DIRECTORY)/src/mapi/glapi/gen/*.xml \ + $(DIRECTORY)/src/mapi/glapi/gen/*.py \ + $(DIRECTORY)/src/mapi/glapi/gen/*.dtd \ + $(DIRECTORY)/src/mapi/glapi/gen-es/Makefile \ + $(DIRECTORY)/src/mapi/glapi/gen-es/*.xml \ + $(DIRECTORY)/src/mapi/glapi/gen-es/*.py \ + $(DIRECTORY)/src/mapi/glapi/Makefile \ + $(DIRECTORY)/src/mapi/glapi/SConscript \ + $(DIRECTORY)/src/mapi/glapi/sources.mak \ + $(DIRECTORY)/src/mapi/glapi/*.[chS] \ + $(DIRECTORY)/src/mapi/mapi/mapi_abi.py \ + $(DIRECTORY)/src/mapi/mapi/sources.mak \ + $(DIRECTORY)/src/mapi/mapi/*.[ch] \ + $(DIRECTORY)/src/mapi/vgapi/Makefile \ + $(DIRECTORY)/src/mapi/vgapi/vgapi.csv \ + $(DIRECTORY)/src/mapi/vgapi/vg.pc.in + +EGL_FILES = \ + $(DIRECTORY)/include/KHR/*.h \ + $(DIRECTORY)/include/EGL/*.h \ + $(DIRECTORY)/src/egl/Makefile \ + $(DIRECTORY)/src/egl/*/Makefile \ + $(DIRECTORY)/src/egl/*/Makefile.template \ + $(DIRECTORY)/src/egl/*/*.[ch] \ + $(DIRECTORY)/src/egl/*/*/Makefile \ + $(DIRECTORY)/src/egl/*/*/*.[ch] \ + $(DIRECTORY)/src/egl/main/*.pc.in \ + $(DIRECTORY)/src/egl/main/*.def + +GALLIUM_FILES = \ + $(DIRECTORY)/src/mesa/state_tracker/*[ch] \ + $(DIRECTORY)/src/gallium/Makefile \ + $(DIRECTORY)/src/gallium/Makefile.template \ + $(DIRECTORY)/src/gallium/SConscript \ + $(DIRECTORY)/src/gallium/targets/Makefile.dri \ + $(DIRECTORY)/src/gallium/targets/Makefile.xorg \ + $(DIRECTORY)/src/gallium/targets/SConscript.dri \ + $(DIRECTORY)/src/gallium/*/Makefile \ + $(DIRECTORY)/src/gallium/*/SConscript \ + $(DIRECTORY)/src/gallium/*/*/Makefile \ + $(DIRECTORY)/src/gallium/*/*/SConscript \ + $(DIRECTORY)/src/gallium/*/*/*.[ch] \ + $(DIRECTORY)/src/gallium/auxiliary/gallivm/*.cpp \ + $(DIRECTORY)/src/gallium/*/*/*.py \ + $(DIRECTORY)/src/gallium/*/*/*.csv \ + $(DIRECTORY)/src/gallium/*/*/*/Makefile \ + $(DIRECTORY)/src/gallium/*/*/*/SConscript \ + $(DIRECTORY)/src/gallium/*/*/*/*.[ch] \ + $(DIRECTORY)/src/gallium/*/*/*/*.py + + +DRI_FILES = \ + $(DIRECTORY)/include/GL/internal/dri_interface.h \ + $(DIRECTORY)/include/GL/internal/sarea.h \ + $(DIRECTORY)/src/glx/Makefile \ + $(DIRECTORY)/src/glx/*.[ch] \ + $(DIRECTORY)/src/mesa/drivers/dri/Makefile \ + $(DIRECTORY)/src/mesa/drivers/dri/Makefile.template \ + $(DIRECTORY)/src/mesa/drivers/dri/dri.pc.in \ + $(DIRECTORY)/src/mesa/drivers/dri/common/xmlpool/*.po \ + $(DIRECTORY)/src/mesa/drivers/dri/*/*.[chS] \ + $(DIRECTORY)/src/mesa/drivers/dri/*/*.cpp \ + $(DIRECTORY)/src/mesa/drivers/dri/*/*/*.[chS] \ + $(DIRECTORY)/src/mesa/drivers/dri/*/Makefile \ + $(DIRECTORY)/src/mesa/drivers/dri/*/*/Makefile \ + $(DIRECTORY)/src/mesa/drivers/dri/*/Doxyfile + +SGI_GLU_FILES = \ + $(DIRECTORY)/src/glu/Makefile \ + $(DIRECTORY)/src/glu/glu.pc.in \ + $(DIRECTORY)/src/glu/sgi/Makefile \ + $(DIRECTORY)/src/glu/sgi/Makefile.mgw \ + $(DIRECTORY)/src/glu/sgi/Makefile.win \ + $(DIRECTORY)/src/glu/sgi/glu.def \ + $(DIRECTORY)/src/glu/sgi/dummy.cc \ + $(DIRECTORY)/src/glu/sgi/glu.exports \ + $(DIRECTORY)/src/glu/sgi/glu.exports.darwin \ + $(DIRECTORY)/src/glu/sgi/mesaglu.opt \ + $(DIRECTORY)/src/glu/sgi/include/gluos.h \ + $(DIRECTORY)/src/glu/sgi/libnurbs/interface/*.h \ + $(DIRECTORY)/src/glu/sgi/libnurbs/interface/*.cc \ + $(DIRECTORY)/src/glu/sgi/libnurbs/internals/*.h \ + $(DIRECTORY)/src/glu/sgi/libnurbs/internals/*.cc \ + $(DIRECTORY)/src/glu/sgi/libnurbs/nurbtess/*.h \ + $(DIRECTORY)/src/glu/sgi/libnurbs/nurbtess/*.cc \ + $(DIRECTORY)/src/glu/sgi/libtess/README \ + $(DIRECTORY)/src/glu/sgi/libtess/alg-outline \ + $(DIRECTORY)/src/glu/sgi/libtess/*.[ch] \ + $(DIRECTORY)/src/glu/sgi/libutil/*.[ch] + +GLW_FILES = \ + $(DIRECTORY)/src/glw/*.[ch] \ + $(DIRECTORY)/src/glw/Makefile* \ + $(DIRECTORY)/src/glw/README \ + $(DIRECTORY)/src/glw/glw.pc.in \ + $(DIRECTORY)/src/glw/depend + +GLUT_FILES = \ + $(DIRECTORY)/include/GL/glut.h \ + $(DIRECTORY)/include/GL/glutf90.h \ + $(DIRECTORY)/src/glut/glx/Makefile* \ + $(DIRECTORY)/src/glut/glx/depend \ + $(DIRECTORY)/src/glut/glx/glut.pc.in \ + $(DIRECTORY)/src/glut/glx/*def \ + $(DIRECTORY)/src/glut/glx/*.[ch] \ + $(DIRECTORY)/src/glut/beos/*.[ch] \ + $(DIRECTORY)/src/glut/beos/*.cpp \ + $(DIRECTORY)/src/glut/beos/Makefile + +DEPEND_FILES = \ + $(TOP)/src/mesa/depend \ + $(TOP)/src/glx/depend \ + $(TOP)/src/glw/depend \ + $(TOP)/src/glut/glx/depend \ + $(TOP)/src/glu/sgi/depend + + +LIB_FILES = \ + $(MAIN_FILES) \ + $(MAPI_FILES) \ + $(ES_FILES) \ + $(EGL_FILES) \ + $(GALLIUM_FILES) \ + $(DRI_FILES) \ + $(SGI_GLU_FILES) \ + $(GLW_FILES) + + +# Everything for new a Mesa release: +tarballs: rm_depend configure aclocal.m4 lib_gz glut_gz \ + lib_bz2 glut_bz2 lib_zip glut_zip md5 + + +# Helper for autoconf builds +ACLOCAL = aclocal +ACLOCAL_FLAGS = +AUTOCONF = autoconf +AC_FLAGS = +aclocal.m4: configure.ac acinclude.m4 + $(ACLOCAL) $(ACLOCAL_FLAGS) +configure: configure.ac aclocal.m4 acinclude.m4 + $(AUTOCONF) $(AC_FLAGS) + +rm_depend: + @for dep in $(DEPEND_FILES) ; do \ + rm -f $$dep ; \ + touch $$dep ; \ + done + +rm_config: + rm -f configs/current + rm -f configs/autoconf + +lib_gz: rm_config + cd .. ; \ + tar -cf $(LIB_NAME).tar $(LIB_FILES) ; \ + gzip $(LIB_NAME).tar ; \ + mv $(LIB_NAME).tar.gz $(DIRECTORY) + +glut_gz: + cd .. ; \ + tar -cf $(GLUT_NAME).tar $(GLUT_FILES) ; \ + gzip $(GLUT_NAME).tar ; \ + mv $(GLUT_NAME).tar.gz $(DIRECTORY) + +lib_bz2: rm_config + cd .. ; \ + tar -cf $(LIB_NAME).tar $(LIB_FILES) ; \ + bzip2 $(LIB_NAME).tar ; \ + mv $(LIB_NAME).tar.bz2 $(DIRECTORY) + +glut_bz2: + cd .. ; \ + tar -cf $(GLUT_NAME).tar $(GLUT_FILES) ; \ + bzip2 $(GLUT_NAME).tar ; \ + mv $(GLUT_NAME).tar.bz2 $(DIRECTORY) + +lib_zip: rm_config + rm -f $(LIB_NAME).zip ; \ + cd .. ; \ + zip -qr $(LIB_NAME).zip $(LIB_FILES) ; \ + mv $(LIB_NAME).zip $(DIRECTORY) + +glut_zip: + rm -f $(GLUT_NAME).zip ; \ + cd .. ; \ + zip -qr $(GLUT_NAME).zip $(GLUT_FILES) ; \ + mv $(GLUT_NAME).zip $(DIRECTORY) + +md5: + @-md5sum $(LIB_NAME).tar.gz + @-md5sum $(LIB_NAME).tar.bz2 + @-md5sum $(LIB_NAME).zip + @-md5sum $(GLUT_NAME).tar.gz + @-md5sum $(GLUT_NAME).tar.bz2 + @-md5sum $(GLUT_NAME).zip + +.PHONY: tarballs rm_depend rm_config md5 \ + lib_gz glut_gz \ + lib_bz2 glut_bz2 \ + lib_zip glut_zip diff --git a/acinclude.m4 b/acinclude.m4 new file mode 100644 index 0000000..a5b389d --- /dev/null +++ b/acinclude.m4 @@ -0,0 +1,119 @@ +# A few convenience macros for Mesa, mostly to keep all the platform +# specifics out of configure.ac. + +# MESA_PIC_FLAGS() +# +# Find out whether to build PIC code using the option --enable-pic and +# the configure enable_static/enable_shared settings. If PIC is needed, +# figure out the necessary flags for the platform and compiler. +# +# The platform checks have been shamelessly taken from libtool and +# stripped down to just what's needed for Mesa. See _LT_COMPILER_PIC in +# /usr/share/aclocal/libtool.m4 or +# http://git.savannah.gnu.org/gitweb/?p=libtool.git;a=blob;f=libltdl/m4/libtool.m4;hb=HEAD +# +AC_DEFUN([MESA_PIC_FLAGS], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_ARG_VAR([PIC_FLAGS], [compiler flags for PIC code]) +AC_ARG_ENABLE([pic], + [AS_HELP_STRING([--disable-pic], + [compile PIC objects @<:@default=enabled for shared builds + on supported platforms@:>@])], + [enable_pic="$enableval" + test "x$enable_pic" = x && enable_pic=auto], + [enable_pic=auto]) +# disable PIC by default for static builds +if test "$enable_pic" = auto && test "$enable_static" = yes; then + enable_pic=no +fi +# if PIC hasn't been explicitly disabled, try to figure out the flags +if test "$enable_pic" != no; then + AC_MSG_CHECKING([for $CC option to produce PIC]) + # allow the user's flags to override + if test "x$PIC_FLAGS" = x; then + # see if we're using GCC + if test "x$GCC" = xyes; then + case "$host_os" in + aix*|beos*|cygwin*|irix5*|irix6*|osf3*|osf4*|osf5*) + # PIC is the default for these OSes. + ;; + mingw*|os2*|pw32*) + # This hack is so that the source file can tell whether + # it is being built for inclusion in a dll (and should + # export symbols for example). + PIC_FLAGS="-DDLL_EXPORT" + ;; + darwin*|rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + PIC_FLAGS="-fno-common" + ;; + hpux*) + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, + # but not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + ;; + *) + PIC_FLAGS="-fPIC" + ;; + esac + ;; + *) + # Everyone else on GCC uses -fPIC + PIC_FLAGS="-fPIC" + ;; + esac + else # !GCC + case "$host_os" in + hpux9*|hpux10*|hpux11*) + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, + # but not for PA HP-UX. + case "$host_cpu" in + hppa*64*|ia64*) + # +Z the default + ;; + *) + PIC_FLAGS="+Z" + ;; + esac + ;; + linux*|k*bsd*-gnu) + case `basename "$CC"` in + icc*|ecc*|ifort*) + PIC_FLAGS="-KPIC" + ;; + pgcc*|pgf77*|pgf90*|pgf95*) + # Portland Group compilers (*not* the Pentium gcc + # compiler, which looks to be a dead project) + PIC_FLAGS="-fpic" + ;; + ccc*) + # All Alpha code is PIC. + ;; + xl*) + # IBM XL C 8.0/Fortran 10.1 on PPC + PIC_FLAGS="-qpic" + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*|*Sun\ F*) + # Sun C 5.9 or Sun Fortran + PIC_FLAGS="-KPIC" + ;; + esac + esac + ;; + solaris*) + PIC_FLAGS="-KPIC" + ;; + sunos4*) + PIC_FLAGS="-PIC" + ;; + esac + fi # GCC + fi # PIC_FLAGS + AC_MSG_RESULT([$PIC_FLAGS]) +fi +AC_SUBST([PIC_FLAGS]) +])# MESA_PIC_FLAGS diff --git a/aclocal.m4 b/aclocal.m4 new file mode 100644 index 0000000..165d9bc --- /dev/null +++ b/aclocal.m4 @@ -0,0 +1,172 @@ +# generated automatically by aclocal 1.11.1 -*- Autoconf -*- + +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +# 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- +# serial 1 (pkg-config-0.24) +# +# Copyright © 2004 Scott James Remnant . +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# PKG_PROG_PKG_CONFIG([MIN-VERSION]) +# ---------------------------------- +AC_DEFUN([PKG_PROG_PKG_CONFIG], +[m4_pattern_forbid([^_?PKG_[A-Z_]+$]) +m4_pattern_allow([^PKG_CONFIG(_PATH)?$]) +AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility]) +AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path]) +AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path]) + +if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then + AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) +fi +if test -n "$PKG_CONFIG"; then + _pkg_min_version=m4_default([$1], [0.9.0]) + AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) + if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + PKG_CONFIG="" + fi +fi[]dnl +])# PKG_PROG_PKG_CONFIG + +# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +# +# Check to see whether a particular set of modules exists. Similar +# to PKG_CHECK_MODULES(), but does not set variables or print errors. +# +# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) +# only at the first occurence in configure.ac, so if the first place +# it's called might be skipped (such as if it is within an "if", you +# have to call PKG_CHECK_EXISTS manually +# -------------------------------------------------------------- +AC_DEFUN([PKG_CHECK_EXISTS], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl +if test -n "$PKG_CONFIG" && \ + AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then + m4_default([$2], [:]) +m4_ifvaln([$3], [else + $3])dnl +fi]) + +# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) +# --------------------------------------------- +m4_define([_PKG_CONFIG], +[if test -n "$$1"; then + pkg_cv_[]$1="$$1" + elif test -n "$PKG_CONFIG"; then + PKG_CHECK_EXISTS([$3], + [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`], + [pkg_failed=yes]) + else + pkg_failed=untried +fi[]dnl +])# _PKG_CONFIG + +# _PKG_SHORT_ERRORS_SUPPORTED +# ----------------------------- +AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG]) +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi[]dnl +])# _PKG_SHORT_ERRORS_SUPPORTED + + +# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], +# [ACTION-IF-NOT-FOUND]) +# +# +# Note that if there is a possibility the first call to +# PKG_CHECK_MODULES might not happen, you should be sure to include an +# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac +# +# +# -------------------------------------------------------------- +AC_DEFUN([PKG_CHECK_MODULES], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl +AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl +AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl + +pkg_failed=no +AC_MSG_CHECKING([for $1]) + +_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) +_PKG_CONFIG([$1][_LIBS], [libs], [$2]) + +m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS +and $1[]_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details.]) + +if test $pkg_failed = yes; then + AC_MSG_RESULT([no]) + _PKG_SHORT_ERRORS_SUPPORTED + if test $_pkg_short_errors_supported = yes; then + $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1` + else + $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD + + m4_default([$4], [AC_MSG_ERROR( +[Package requirements ($2) were not met: + +$$1_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +_PKG_TEXT]) + ]) +elif test $pkg_failed = untried; then + AC_MSG_RESULT([no]) + m4_default([$4], [AC_MSG_FAILURE( +[The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +_PKG_TEXT + +To get pkg-config, see .]) + ]) +else + $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS + $1[]_LIBS=$pkg_cv_[]$1[]_LIBS + AC_MSG_RESULT([yes]) + $3 +fi[]dnl +])# PKG_CHECK_MODULES + +m4_include([acinclude.m4]) diff --git a/bin/config.guess b/bin/config.guess new file mode 100755 index 0000000..e5716ee --- /dev/null +++ b/bin/config.guess @@ -0,0 +1,1555 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 +# Free Software Foundation, Inc. + +timestamp='2009-02-03' + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + + +# Originally written by Per Bothner . +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. +# +# The plan is that this can be called by configure scripts if you +# don't specify an explicit build system type. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, +2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + +trap 'exit 1' 1 2 15 + +# CC_FOR_BUILD -- compiler used by this script. Note that the use of a +# compiler to aid in system detection is discouraged as it requires +# temporary files to be created and, as you can see below, it is a +# headache to deal with in a portable fashion. + +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +# use `HOST_CC' if defined, but it is deprecated. + +# Portable tmp directory creation inspired by the Autoconf team. + +set_cc_for_build=' +trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; +trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; +: ${TMPDIR=/tmp} ; + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; +dummy=$tmp/dummy ; +tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; +case $CC_FOR_BUILD,$HOST_CC,$CC in + ,,) echo "int x;" > $dummy.c ; + for c in cc gcc c89 c99 ; do + if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then + CC_FOR_BUILD="$c"; break ; + fi ; + done ; + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found ; + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; +esac ; set_cc_for_build= ;' + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 1994-08-24) +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +# Note: order is significant - the case branches are not exclusive. + +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # + # Note: NetBSD doesn't particularly care about the vendor + # portion of the name. We always set it to "unknown". + sysctl="sysctl -n hw.machine_arch" + UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || echo unknown)` + case "${UNAME_MACHINE_ARCH}" in + armeb) machine=armeb-unknown ;; + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + sh5el) machine=sh5le-unknown ;; + *) machine=${UNAME_MACHINE_ARCH}-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently, or will in the future. + case "${UNAME_MACHINE_ARCH}" in + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + eval $set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep __ELF__ >/dev/null + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # The OS release + # Debian GNU/NetBSD machines have a different userland, and + # thus, need a distinct triplet. However, they do not need + # kernel version information, so it can be replaced with a + # suitable tag, in the style of linux-gnu. + case "${UNAME_VERSION}" in + Debian*) + release='-gnu' + ;; + *) + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + ;; + esac + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit ;; + *:OpenBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} + exit ;; + *:ekkoBSD:*:*) + echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} + exit ;; + *:SolidBSD:*:*) + echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} + exit ;; + macppc:MirBSD:*:*) + echo powerpc-unknown-mirbsd${UNAME_RELEASE} + exit ;; + *:MirBSD:*:*) + echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} + exit ;; + alpha:OSF1:*:*) + case $UNAME_RELEASE in + *4.0) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + ;; + *5.*) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + ;; + esac + # According to Compaq, /usr/sbin/psrinfo has been available on + # OSF/1 and Tru64 systems produced since 1995. I hope that + # covers most systems running today. This code pipes the CPU + # types through head -n 1, so we only detect the type of CPU 0. + ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` + case "$ALPHA_CPU_TYPE" in + "EV4 (21064)") + UNAME_MACHINE="alpha" ;; + "EV4.5 (21064)") + UNAME_MACHINE="alpha" ;; + "LCA4 (21066/21068)") + UNAME_MACHINE="alpha" ;; + "EV5 (21164)") + UNAME_MACHINE="alphaev5" ;; + "EV5.6 (21164A)") + UNAME_MACHINE="alphaev56" ;; + "EV5.6 (21164PC)") + UNAME_MACHINE="alphapca56" ;; + "EV5.7 (21164PC)") + UNAME_MACHINE="alphapca57" ;; + "EV6 (21264)") + UNAME_MACHINE="alphaev6" ;; + "EV6.7 (21264A)") + UNAME_MACHINE="alphaev67" ;; + "EV6.8CB (21264C)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8AL (21264B)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8CX (21264D)") + UNAME_MACHINE="alphaev68" ;; + "EV6.9A (21264/EV69A)") + UNAME_MACHINE="alphaev69" ;; + "EV7 (21364)") + UNAME_MACHINE="alphaev7" ;; + "EV7.9 (21364A)") + UNAME_MACHINE="alphaev79" ;; + esac + # A Pn.n version is a patched version. + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix + exit ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit ;; + Amiga*:UNIX_System_V:4.0:*) + echo m68k-unknown-sysv4 + exit ;; + *:[Aa]miga[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-amigaos + exit ;; + *:[Mm]orph[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-morphos + exit ;; + *:OS/390:*:*) + echo i370-ibm-openedition + exit ;; + *:z/VM:*:*) + echo s390-ibm-zvmoe + exit ;; + *:OS400:*:*) + echo powerpc-ibm-os400 + exit ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit ;; + arm:riscos:*:*|arm:RISCOS:*:*) + echo arm-unknown-riscos + exit ;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + echo hppa1.1-hitachi-hiuxmpp + exit ;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit ;; + NILE*:*:*:dcosx) + echo pyramid-pyramid-svr4 + exit ;; + DRS?6000:unix:4.0:6*) + echo sparc-icl-nx6 + exit ;; + DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) + case `/usr/bin/uname -p` in + sparc) echo sparc-icl-nx7; exit ;; + esac ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) + eval $set_cc_for_build + SUN_ARCH="i386" + # If there is a compiler, see if it is configured for 64-bit objects. + # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. + # This test works for both compilers. + if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + SUN_ARCH="x86_64" + fi + fi + echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:*:*) + case "`/usr/bin/arch -k`" in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + case "`/bin/arch`" in + sun3) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit ;; + aushp:SunOS:*:*) + echo sparc-auspex-sunos${UNAME_RELEASE} + exit ;; + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit ;; + m68k:machten:*:*) + echo m68k-apple-machten${UNAME_RELEASE} + exit ;; + powerpc:machten:*:*) + echo powerpc-apple-machten${UNAME_RELEASE} + exit ;; + RISC*:Mach:*:*) + echo mips-dec-mach_bsd4.3 + exit ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && + dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`$dummy $dummyarg` && + { echo "$SYSTEM_NAME"; exit; } + echo mips-mips-riscos${UNAME_RELEASE} + exit ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit ;; + Motorola:*:4.3:PL8-*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:Power_UNIX:*:*) + echo powerpc-harris-powerunix + exit ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] + then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} + fi + exit ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + echo i386-ibm-aix + exit ;; + ia64:AIX:*:*) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + exit ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` + then + echo "$SYSTEM_NAME" + else + echo rs6000-ibm-aix3.2.5 + fi + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit ;; + *:AIX:*:[456]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit ;; + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; + 9000/[678][0-9][0-9]) + if [ -x /usr/bin/getconf ]; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case "${sc_cpu_version}" in + 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 + 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case "${sc_kernel_bits}" in + 32) HP_ARCH="hppa2.0n" ;; + 64) HP_ARCH="hppa2.0w" ;; + '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 + esac ;; + esac + fi + if [ "${HP_ARCH}" = "" ]; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + test -z "$HP_ARCH" && HP_ARCH=hppa + fi ;; + esac + if [ ${HP_ARCH} = "hppa2.0w" ] + then + eval $set_cc_for_build + + # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating + # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler + # generating 64-bit code. GNU and HP use different nomenclature: + # + # $ CC_FOR_BUILD=cc ./config.guess + # => hppa2.0w-hp-hpux11.23 + # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess + # => hppa64-hp-hpux11.23 + + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | + grep __LP64__ >/dev/null + then + HP_ARCH="hppa2.0w" + else + HP_ARCH="hppa64" + fi + fi + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} + exit ;; + 3050*:HI-UX:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + echo unknown-hitachi-hiuxwe2 + exit ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + echo hppa1.1-hp-osf + exit ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit ;; + i*86:OSF1:*:*) + if [ -x /usr/sbin/sysversion ] ; then + echo ${UNAME_MACHINE}-unknown-osf1mk + else + echo ${UNAME_MACHINE}-unknown-osf1 + fi + exit ;; + parisc*:Lites*:*:*) + echo hppa1.1-hp-lites + exit ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + echo c34-convex-bsd + exit ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit ;; + CRAY*Y-MP:*:*:*) + echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*[A-Z]90:*:*:*) + echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*TS:*:*:*) + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*T3E:*:*:*) + echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*SV1:*:*:*) + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + *:UNICOS/mp:*:*) + echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` + echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` + echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + exit ;; + sparc*:BSD/OS:*:*) + echo sparc-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:FreeBSD:*:*) + case ${UNAME_MACHINE} in + pc98) + echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + amd64) + echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + *) + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + esac + exit ;; + i*:CYGWIN*:*) + echo ${UNAME_MACHINE}-pc-cygwin + exit ;; + *:MINGW*:*) + echo ${UNAME_MACHINE}-pc-mingw32 + exit ;; + i*:windows32*:*) + # uname -m includes "-pc" on this system. + echo ${UNAME_MACHINE}-mingw32 + exit ;; + i*:PW*:*) + echo ${UNAME_MACHINE}-pc-pw32 + exit ;; + *:Interix*:[3456]*) + case ${UNAME_MACHINE} in + x86) + echo i586-pc-interix${UNAME_RELEASE} + exit ;; + EM64T | authenticamd | genuineintel) + echo x86_64-unknown-interix${UNAME_RELEASE} + exit ;; + IA64) + echo ia64-unknown-interix${UNAME_RELEASE} + exit ;; + esac ;; + [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) + echo i${UNAME_MACHINE}-pc-mks + exit ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i586-pc-interix + exit ;; + i*:UWIN*:*) + echo ${UNAME_MACHINE}-pc-uwin + exit ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + echo x86_64-unknown-cygwin + exit ;; + p*:CYGWIN*:*) + echo powerpcle-unknown-cygwin + exit ;; + prep*:SunOS:5.*:*) + echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + *:GNU:*:*) + # the GNU system + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu + exit ;; + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix + exit ;; + arm*:Linux:*:*) + eval $set_cc_for_build + if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_EABI__ + then + echo ${UNAME_MACHINE}-unknown-linux-gnu + else + echo ${UNAME_MACHINE}-unknown-linux-gnueabi + fi + exit ;; + avr32*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + cris:Linux:*:*) + echo cris-axis-linux-gnu + exit ;; + crisv32:Linux:*:*) + echo crisv32-axis-linux-gnu + exit ;; + frv:Linux:*:*) + echo frv-unknown-linux-gnu + exit ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m32r*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + mips:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips + #undef mipsel + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mipsel + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips + #else + CPU= + #endif + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + mips64:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips64 + #undef mips64el + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mips64el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips64 + #else + CPU= + #endif + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + or32:Linux:*:*) + echo or32-unknown-linux-gnu + exit ;; + ppc:Linux:*:*) + echo powerpc-unknown-linux-gnu + exit ;; + ppc64:Linux:*:*) + echo powerpc64-unknown-linux-gnu + exit ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null + if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi + echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} + exit ;; + padre:Linux:*:*) + echo sparc-unknown-linux-gnu + exit ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) echo hppa1.1-unknown-linux-gnu ;; + PA8*) echo hppa2.0-unknown-linux-gnu ;; + *) echo hppa-unknown-linux-gnu ;; + esac + exit ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + echo hppa64-unknown-linux-gnu + exit ;; + s390:Linux:*:* | s390x:Linux:*:*) + echo ${UNAME_MACHINE}-ibm-linux + exit ;; + sh64*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sh*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + vax:Linux:*:*) + echo ${UNAME_MACHINE}-dec-linux-gnu + exit ;; + x86_64:Linux:*:*) + echo x86_64-unknown-linux-gnu + exit ;; + xtensa*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + i*86:Linux:*:*) + # The BFD linker knows what the default object file format is, so + # first see if it will tell us. cd to the root directory to prevent + # problems with other programs or directories called `ld' in the path. + # Set LC_ALL=C to ensure ld outputs messages in English. + ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ + | sed -ne '/supported targets:/!d + s/[ ][ ]*/ /g + s/.*supported targets: *// + s/ .*// + p'` + case "$ld_supported_targets" in + elf32-i386) + TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" + ;; + a.out-i386-linux) + echo "${UNAME_MACHINE}-pc-linux-gnuaout" + exit ;; + "") + # Either a pre-BFD a.out linker (linux-gnuoldld) or + # one that does not give us useful --help. + echo "${UNAME_MACHINE}-pc-linux-gnuoldld" + exit ;; + esac + # Determine whether the default compiler is a.out or elf + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + #ifdef __ELF__ + # ifdef __GLIBC__ + # if __GLIBC__ >= 2 + LIBC=gnu + # else + LIBC=gnulibc1 + # endif + # else + LIBC=gnulibc1 + # endif + #else + #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) + LIBC=gnu + #else + LIBC=gnuaout + #endif + #endif + #ifdef __dietlibc__ + LIBC=dietlibc + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^LIBC/{ + s: ::g + p + }'`" + test x"${LIBC}" != x && { + echo "${UNAME_MACHINE}-pc-linux-${LIBC}" + exit + } + test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } + ;; + i*86:DYNIX/ptx:4*:*) + # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. + # earlier versions are messed up and put the nodename in both + # sysname and nodename. + echo i386-sequent-sysv4 + exit ;; + i*86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + exit ;; + i*86:OS/2:*:*) + # If we were able to find `uname', then EMX Unix compatibility + # is probably installed. + echo ${UNAME_MACHINE}-pc-os2-emx + exit ;; + i*86:XTS-300:*:STOP) + echo ${UNAME_MACHINE}-unknown-stop + exit ;; + i*86:atheos:*:*) + echo ${UNAME_MACHINE}-unknown-atheos + exit ;; + i*86:syllable:*:*) + echo ${UNAME_MACHINE}-pc-syllable + exit ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) + echo i386-unknown-lynxos${UNAME_RELEASE} + exit ;; + i*86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp + exit ;; + i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) + UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + else + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + fi + exit ;; + i*86:*:5:[678]*) + # UnixWare 7.x, OpenUNIX and OpenServer 6. + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + exit ;; + i*86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` + (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 + echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-pc-sysv32 + fi + exit ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i386. + echo i386-pc-msdosdjgpp + exit ;; + Intel:Mach:3*:*) + echo i386-pc-mach3 + exit ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit ;; + mc68k:UNIX:SYSTEM5:3.51m) + echo m68k-convergent-sysv + exit ;; + M680?0:D-NIX:5.3:*) + echo m68k-diab-dnix + exit ;; + M68*:*:R3V[5678]*:*) + test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4; exit; } ;; + NCR*:*:4.2:* | MPRAS*:*:4.2:*) + OS_REL='.3' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + echo m68k-unknown-lynxos${UNAME_RELEASE} + exit ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit ;; + TSUNAMI:LynxOS:2.*:*) + echo sparc-unknown-lynxos${UNAME_RELEASE} + exit ;; + rs6000:LynxOS:2.*:*) + echo rs6000-unknown-lynxos${UNAME_RELEASE} + exit ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) + echo powerpc-unknown-lynxos${UNAME_RELEASE} + exit ;; + SM[BE]S:UNIX_SV:*:*) + echo mips-dde-sysv${UNAME_RELEASE} + exit ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + echo i586-unisys-sysv4 + exit ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes . + # How about differentiating between stratus architectures? -djm + echo hppa1.1-stratus-sysv4 + exit ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + echo i860-stratus-sysv4 + exit ;; + i*86:VOS:*:*) + # From Paul.Green@stratus.com. + echo ${UNAME_MACHINE}-stratus-vos + exit ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + echo hppa1.1-stratus-vos + exit ;; + mc68*:A/UX:*:*) + echo m68k-apple-aux${UNAME_RELEASE} + exit ;; + news*:NEWS-OS:6*:*) + echo mips-sony-newsos6 + exit ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if [ -d /usr/nec ]; then + echo mips-nec-sysv${UNAME_RELEASE} + else + echo mips-unknown-sysv${UNAME_RELEASE} + fi + exit ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + echo powerpc-be-beos + exit ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + echo powerpc-apple-beos + exit ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + echo i586-pc-beos + exit ;; + BePC:Haiku:*:*) # Haiku running on Intel PC compatible. + echo i586-pc-haiku + exit ;; + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit ;; + SX-6:SUPER-UX:*:*) + echo sx6-nec-superux${UNAME_RELEASE} + exit ;; + SX-7:SUPER-UX:*:*) + echo sx7-nec-superux${UNAME_RELEASE} + exit ;; + SX-8:SUPER-UX:*:*) + echo sx8-nec-superux${UNAME_RELEASE} + exit ;; + SX-8R:SUPER-UX:*:*) + echo sx8r-nec-superux${UNAME_RELEASE} + exit ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Darwin:*:*) + UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; + esac + echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} + exit ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + UNAME_PROCESSOR=`uname -p` + if test "$UNAME_PROCESSOR" = "x86"; then + UNAME_PROCESSOR=i386 + UNAME_MACHINE=pc + fi + echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} + exit ;; + *:QNX:*:4*) + echo i386-pc-qnx + exit ;; + NSE-?:NONSTOP_KERNEL:*:*) + echo nse-tandem-nsk${UNAME_RELEASE} + exit ;; + NSR-?:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} + exit ;; + *:NonStop-UX:*:*) + echo mips-compaq-nonstopux + exit ;; + BS2000:POSIX*:*:*) + echo bs2000-siemens-sysv + exit ;; + DS/*:UNIX_System_V:*:*) + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + exit ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "$cputype" = "386"; then + UNAME_MACHINE=i386 + else + UNAME_MACHINE="$cputype" + fi + echo ${UNAME_MACHINE}-unknown-plan9 + exit ;; + *:TOPS-10:*:*) + echo pdp10-unknown-tops10 + exit ;; + *:TENEX:*:*) + echo pdp10-unknown-tenex + exit ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + echo pdp10-dec-tops20 + exit ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + echo pdp10-xkl-tops20 + exit ;; + *:TOPS-20:*:*) + echo pdp10-unknown-tops20 + exit ;; + *:ITS:*:*) + echo pdp10-unknown-its + exit ;; + SEI:*:*:SEIUX) + echo mips-sei-seiux${UNAME_RELEASE} + exit ;; + *:DragonFly:*:*) + echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case "${UNAME_MACHINE}" in + A*) echo alpha-dec-vms ; exit ;; + I*) echo ia64-dec-vms ; exit ;; + V*) echo vax-dec-vms ; exit ;; + esac ;; + *:XENIX:*:SysV) + echo i386-pc-xenix + exit ;; + i*86:skyos:*:*) + echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' + exit ;; + i*86:rdos:*:*) + echo ${UNAME_MACHINE}-pc-rdos + exit ;; + i*86:AROS:*:*) + echo ${UNAME_MACHINE}-pc-aros + exit ;; +esac + +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + +eval $set_cc_for_build +cat >$dummy.c < +# include +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix\n"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); + +#endif + +#if defined (vax) +# if !defined (ultrix) +# include +# if defined (BSD) +# if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +# else +# if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# endif +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# else + printf ("vax-dec-ultrix\n"); exit (0); +# endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. + +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + c34*) + echo c34-convex-bsd + exit ;; + c38*) + echo c38-convex-bsd + exit ;; + c4*) + echo c4-convex-bsd + exit ;; + esac +fi + +cat >&2 < in order to provide the needed +information to handle your system. + +config.guess timestamp = $timestamp + +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = ${UNAME_MACHINE} +UNAME_RELEASE = ${UNAME_RELEASE} +UNAME_SYSTEM = ${UNAME_SYSTEM} +UNAME_VERSION = ${UNAME_VERSION} +EOF + +exit 1 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/bin/config.sub b/bin/config.sub new file mode 100755 index 0000000..d546a94 --- /dev/null +++ b/bin/config.sub @@ -0,0 +1,1685 @@ +#! /bin/sh +# Configuration validation subroutine script. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 +# Free Software Foundation, Inc. + +timestamp='2009-02-03' + +# This file is (in principle) common to ALL GNU software. +# The presence of a machine in this file suggests that SOME GNU software +# can handle that machine. It does not imply ALL GNU software can. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + + +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS + $0 [OPTION] ALIAS + +Canonicalize a configuration name. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.sub ($timestamp) + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, +2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo $1 + exit ;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; +esac + +# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). +# Here we must recognize all the valid KERNEL-OS combinations. +maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` +case $maybe_os in + nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ + uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ + kopensolaris*-gnu* | \ + storm-chaos* | os2-emx* | rtmk-nova*) + os=-$maybe_os + basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` + ;; + *) + basic_machine=`echo $1 | sed 's/-[^-]*$//'` + if [ $basic_machine != $1 ] + then os=`echo $1 | sed 's/.*-/-/'` + else os=; fi + ;; +esac + +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. + ;; + -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ + -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ + -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ + -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ + -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ + -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ + -apple | -axis | -knuth | -cray) + os= + basic_machine=$1 + ;; + -sim | -cisco | -oki | -wec | -winbond) + os= + basic_machine=$1 + ;; + -scout) + ;; + -wrs) + os=-vxworks + basic_machine=$1 + ;; + -chorusos*) + os=-chorusos + basic_machine=$1 + ;; + -chorusrdb) + os=-chorusrdb + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco6) + os=-sco5v6 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5) + os=-sco3.2v5 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -udk*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; + -psos*) + os=-psos + ;; + -mint | -mint[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; +esac + +# Decode aliases for certain CPU-COMPANY combinations. +case $basic_machine in + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + 1750a | 580 \ + | a29k \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ + | am33_2.0 \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ + | bfin \ + | c4x | clipper \ + | d10v | d30v | dlx | dsp16xx \ + | fido | fr30 | frv \ + | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | i370 | i860 | i960 | ia64 \ + | ip2k | iq2000 \ + | lm32 \ + | m32c | m32r | m32rle | m68000 | m68k | m88k \ + | maxq | mb | microblaze | mcore | mep | metag \ + | mips | mipsbe | mipseb | mipsel | mipsle \ + | mips16 \ + | mips64 | mips64el \ + | mips64octeon | mips64octeonel \ + | mips64orion | mips64orionel \ + | mips64r5900 | mips64r5900el \ + | mips64vr | mips64vrel \ + | mips64vr4100 | mips64vr4100el \ + | mips64vr4300 | mips64vr4300el \ + | mips64vr5000 | mips64vr5000el \ + | mips64vr5900 | mips64vr5900el \ + | mipsisa32 | mipsisa32el \ + | mipsisa32r2 | mipsisa32r2el \ + | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ + | mipsisa64sb1 | mipsisa64sb1el \ + | mipsisa64sr71k | mipsisa64sr71kel \ + | mipstx39 | mipstx39el \ + | mn10200 | mn10300 \ + | mt \ + | msp430 \ + | nios | nios2 \ + | ns16k | ns32k \ + | or32 \ + | pdp10 | pdp11 | pj | pjl \ + | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ + | pyramid \ + | score \ + | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ + | sh64 | sh64le \ + | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ + | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ + | spu | strongarm \ + | tahoe | thumb | tic4x | tic80 | tron \ + | v850 | v850e \ + | we32k \ + | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ + | z8k | z80) + basic_machine=$basic_machine-unknown + ;; + m6811 | m68hc11 | m6812 | m68hc12) + # Motorola 68HC11/12. + basic_machine=$basic_machine-unknown + os=-none + ;; + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + ;; + ms1) + basic_machine=mt-unknown + ;; + + # We use `pc' rather than `unknown' + # because (1) that's what they normally are, and + # (2) the word "unknown" tends to confuse beginning users. + i*86 | x86_64) + basic_machine=$basic_machine-pc + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + 580-* \ + | a29k-* \ + | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ + | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ + | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ + | avr-* | avr32-* \ + | bfin-* | bs2000-* \ + | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ + | clipper-* | craynv-* | cydra-* \ + | d10v-* | d30v-* | dlx-* \ + | elxsi-* \ + | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ + | h8300-* | h8500-* \ + | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ + | i*86-* | i860-* | i960-* | ia64-* \ + | ip2k-* | iq2000-* \ + | lm32-* \ + | m32c-* | m32r-* | m32rle-* \ + | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ + | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \ + | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ + | mips16-* \ + | mips64-* | mips64el-* \ + | mips64octeon-* | mips64octeonel-* \ + | mips64orion-* | mips64orionel-* \ + | mips64r5900-* | mips64r5900el-* \ + | mips64vr-* | mips64vrel-* \ + | mips64vr4100-* | mips64vr4100el-* \ + | mips64vr4300-* | mips64vr4300el-* \ + | mips64vr5000-* | mips64vr5000el-* \ + | mips64vr5900-* | mips64vr5900el-* \ + | mipsisa32-* | mipsisa32el-* \ + | mipsisa32r2-* | mipsisa32r2el-* \ + | mipsisa64-* | mipsisa64el-* \ + | mipsisa64r2-* | mipsisa64r2el-* \ + | mipsisa64sb1-* | mipsisa64sb1el-* \ + | mipsisa64sr71k-* | mipsisa64sr71kel-* \ + | mipstx39-* | mipstx39el-* \ + | mmix-* \ + | mt-* \ + | msp430-* \ + | nios-* | nios2-* \ + | none-* | np1-* | ns16k-* | ns32k-* \ + | orion-* \ + | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ + | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ + | pyramid-* \ + | romp-* | rs6000-* \ + | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ + | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ + | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ + | sparclite-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ + | tahoe-* | thumb-* \ + | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* | tile-* \ + | tron-* \ + | v850-* | v850e-* | vax-* \ + | we32k-* \ + | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ + | xstormy16-* | xtensa*-* \ + | ymp-* \ + | z8k-* | z80-*) + ;; + # Recognize the basic CPU types without company name, with glob match. + xtensa*) + basic_machine=$basic_machine-unknown + ;; + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 386bsd) + basic_machine=i386-unknown + os=-bsd + ;; + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + basic_machine=m68000-att + ;; + 3b*) + basic_machine=we32k-att + ;; + a29khif) + basic_machine=a29k-amd + os=-udi + ;; + abacus) + basic_machine=abacus-unknown + ;; + adobe68k) + basic_machine=m68010-adobe + os=-scout + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amd64) + basic_machine=x86_64-pc + ;; + amd64-*) + basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-unknown + ;; + amigaos | amigados) + basic_machine=m68k-unknown + os=-amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + os=-bsd + ;; + aros) + basic_machine=i386-pc + os=-aros + ;; + aux) + basic_machine=m68k-apple + os=-aux + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + blackfin) + basic_machine=bfin-unknown + os=-linux + ;; + blackfin-*) + basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux + ;; + c90) + basic_machine=c90-cray + os=-unicos + ;; + cegcc) + basic_machine=arm-unknown + os=-cegcc + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | j90) + basic_machine=j90-cray + os=-unicos + ;; + craynv) + basic_machine=craynv-cray + os=-unicosmp + ;; + cr16) + basic_machine=cr16-unknown + os=-elf + ;; + crds | unos) + basic_machine=m68k-crds + ;; + crisv32 | crisv32-* | etraxfs*) + basic_machine=crisv32-axis + ;; + cris | cris-* | etrax*) + basic_machine=cris-axis + ;; + crx) + basic_machine=crx-unknown + os=-elf + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec + ;; + decsystem10* | dec10*) + basic_machine=pdp10-dec + os=-tops10 + ;; + decsystem20* | dec20*) + basic_machine=pdp10-dec + os=-tops20 + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + basic_machine=m68k-motorola + ;; + delta88) + basic_machine=m88k-motorola + os=-sysv3 + ;; + dicos) + basic_machine=i686-pc + os=-dicos + ;; + djgpp) + basic_machine=i586-pc + os=-msdosdjgpp + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon + ;; + elxsi) + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + os=-ose + ;; + fx2800) + basic_machine=i860-alliant + ;; + genix) + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + go32) + basic_machine=i386-pc + os=-go32 + ;; + h3050r* | hiux*) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + h8300xray) + basic_machine=h8300-hitachi + os=-xray + ;; + h8500hms) + basic_machine=h8500-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + basic_machine=m68000-hp + ;; + hp9k3[2-9][0-9]) + basic_machine=m68k-hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + basic_machine=hppa1.1-hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hppa-next) + os=-nextstep3 + ;; + hppaosf) + basic_machine=hppa1.1-hp + os=-osf + ;; + hppro) + basic_machine=hppa1.1-hp + os=-proelf + ;; + i370-ibm* | ibm*) + basic_machine=i370-ibm + ;; +# I'm not sure what "Sysv32" means. Should this be sysv3.2? + i*86v32) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv32 + ;; + i*86v4*) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv4 + ;; + i*86v) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv + ;; + i*86sol2) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-solaris2 + ;; + i386mach) + basic_machine=i386-mach + os=-mach + ;; + i386-vsta | vsta) + basic_machine=i386-unknown + os=-vsta + ;; + iris | iris4d) + basic_machine=mips-sgi + case $os in + -irix*) + ;; + *) + os=-irix4 + ;; + esac + ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + m68knommu) + basic_machine=m68k-unknown + os=-linux + ;; + m68knommu-*) + basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + mingw32) + basic_machine=i386-pc + os=-mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + os=-mingw32ce + ;; + miniframe) + basic_machine=m68000-convergent + ;; + *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + monitor) + basic_machine=m68k-rom68k + os=-coff + ;; + morphos) + basic_machine=powerpc-unknown + os=-morphos + ;; + msdos) + basic_machine=i386-pc + os=-msdos + ;; + ms1-*) + basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` + ;; + mvs) + basic_machine=i370-ibm + os=-mvs + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + netbsd386) + basic_machine=i386-unknown + os=-netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + os=-linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos + ;; + news-3600 | risc-news) + basic_machine=mips-sony + os=-newsos + ;; + necv70) + basic_machine=v70-nec + os=-sysv + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) + ;; + -ns2*) + os=-nextstep2 + ;; + *) + os=-nextstep3 + ;; + esac + ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + mon960) + basic_machine=i960-intel + os=-mon960 + ;; + nonstopux) + basic_machine=mips-compaq + os=-nonstopux + ;; + np1) + basic_machine=np1-gould + ;; + nsr-tandem) + basic_machine=nsr-tandem + ;; + op50n-* | op60c-*) + basic_machine=hppa1.1-oki + os=-proelf + ;; + openrisc | openrisc-*) + basic_machine=or32-unknown + ;; + os400) + basic_machine=powerpc-ibm + os=-os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + os=-ose + ;; + os68k) + basic_machine=m68k-none + os=-os68k + ;; + pa-hitachi) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + parisc) + basic_machine=hppa-unknown + os=-linux + ;; + parisc-*) + basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux + ;; + pbd) + basic_machine=sparc-tti + ;; + pbb) + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pc98) + basic_machine=i386-pc + ;; + pc98-*) + basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium | p5 | k5 | k6 | nexgen | viac3) + basic_machine=i586-pc + ;; + pentiumpro | p6 | 6x86 | athlon | athlon_*) + basic_machine=i686-pc + ;; + pentiumii | pentium2 | pentiumiii | pentium3) + basic_machine=i686-pc + ;; + pentium4) + basic_machine=i786-pc + ;; + pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) + basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumpro-* | p6-* | 6x86-* | athlon-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium4-*) + basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pn) + basic_machine=pn-gould + ;; + power) basic_machine=power-ibm + ;; + ppc) basic_machine=powerpc-unknown + ;; + ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppcle | powerpclittle | ppc-le | powerpc-little) + basic_machine=powerpcle-unknown + ;; + ppcle-* | powerpclittle-*) + basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64) basic_machine=powerpc64-unknown + ;; + ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64le | powerpc64little | ppc64-le | powerpc64-little) + basic_machine=powerpc64le-unknown + ;; + ppc64le-* | powerpc64little-*) + basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ps2) + basic_machine=i386-ibm + ;; + pw32) + basic_machine=i586-unknown + os=-pw32 + ;; + rdos) + basic_machine=i386-pc + os=-rdos + ;; + rom68k) + basic_machine=m68k-rom68k + os=-coff + ;; + rm[46]00) + basic_machine=mips-siemens + ;; + rtpc | rtpc-*) + basic_machine=romp-ibm + ;; + s390 | s390-*) + basic_machine=s390-ibm + ;; + s390x | s390x-*) + basic_machine=s390x-ibm + ;; + sa29200) + basic_machine=a29k-amd + os=-udi + ;; + sb1) + basic_machine=mipsisa64sb1-unknown + ;; + sb1el) + basic_machine=mipsisa64sb1el-unknown + ;; + sde) + basic_machine=mipsisa32-sde + os=-elf + ;; + sei) + basic_machine=mips-sei + os=-seiux + ;; + sequent) + basic_machine=i386-sequent + ;; + sh) + basic_machine=sh-hitachi + os=-hms + ;; + sh5el) + basic_machine=sh5le-unknown + ;; + sh64) + basic_machine=sh64-unknown + ;; + sparclite-wrs | simso-wrs) + basic_machine=sparclite-wrs + os=-vxworks + ;; + sps7) + basic_machine=m68k-bull + os=-sysv2 + ;; + spur) + basic_machine=spur-unknown + ;; + st2000) + basic_machine=m68k-tandem + ;; + stratus) + basic_machine=i860-stratus + os=-sysv4 + ;; + sun2) + basic_machine=m68000-sun + ;; + sun2os3) + basic_machine=m68000-sun + os=-sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + os=-sunos4 + ;; + sun3os3) + basic_machine=m68k-sun + os=-sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + os=-sunos4 + ;; + sun4os3) + basic_machine=sparc-sun + os=-sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + os=-sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + os=-solaris2 + ;; + sun3 | sun3-*) + basic_machine=m68k-sun + ;; + sun4) + basic_machine=sparc-sun + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + ;; + sv1) + basic_machine=sv1-cray + os=-unicos + ;; + symmetry) + basic_machine=i386-sequent + os=-dynix + ;; + t3e) + basic_machine=alphaev5-cray + os=-unicos + ;; + t90) + basic_machine=t90-cray + os=-unicos + ;; + tic54x | c54x*) + basic_machine=tic54x-unknown + os=-coff + ;; + tic55x | c55x*) + basic_machine=tic55x-unknown + os=-coff + ;; + tic6x | c6x*) + basic_machine=tic6x-unknown + os=-coff + ;; + tile*) + basic_machine=tile-unknown + os=-linux-gnu + ;; + tx39) + basic_machine=mipstx39-unknown + ;; + tx39el) + basic_machine=mipstx39el-unknown + ;; + toad1) + basic_machine=pdp10-xkl + os=-tops20 + ;; + tower | tower-32) + basic_machine=m68k-ncr + ;; + tpf) + basic_machine=s390x-ibm + os=-tpf + ;; + udi29k) + basic_machine=a29k-amd + os=-udi + ;; + ultra3) + basic_machine=a29k-nyu + os=-sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + os=-none + ;; + vaxv) + basic_machine=vax-dec + os=-sysv + ;; + vms) + basic_machine=vax-dec + os=-vms + ;; + vpp*|vx|vx-*) + basic_machine=f301-fujitsu + ;; + vxworks960) + basic_machine=i960-wrs + os=-vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + os=-vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + os=-vxworks + ;; + w65*) + basic_machine=w65-wdc + os=-none + ;; + w89k-*) + basic_machine=hppa1.1-winbond + os=-proelf + ;; + xbox) + basic_machine=i686-pc + os=-mingw32 + ;; + xps | xps100) + basic_machine=xps100-honeywell + ;; + ymp) + basic_machine=ymp-cray + os=-unicos + ;; + z8k-*-coff) + basic_machine=z8k-unknown + os=-sim + ;; + z80-*-coff) + basic_machine=z80-unknown + os=-sim + ;; + none) + basic_machine=none-none + os=-none + ;; + +# Here we handle the default manufacturer of certain CPU types. It is in +# some cases the only manufacturer, in others, it is the most popular. + w89k) + basic_machine=hppa1.1-winbond + ;; + op50n) + basic_machine=hppa1.1-oki + ;; + op60c) + basic_machine=hppa1.1-oki + ;; + romp) + basic_machine=romp-ibm + ;; + mmix) + basic_machine=mmix-knuth + ;; + rs6000) + basic_machine=rs6000-ibm + ;; + vax) + basic_machine=vax-dec + ;; + pdp10) + # there are many clones, so DEC is not a safe bet + basic_machine=pdp10-unknown + ;; + pdp11) + basic_machine=pdp11-dec + ;; + we32k) + basic_machine=we32k-att + ;; + sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele) + basic_machine=sh-unknown + ;; + sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) + basic_machine=sparc-sun + ;; + cydra) + basic_machine=cydra-cydrome + ;; + orion) + basic_machine=orion-highlevel + ;; + orion105) + basic_machine=clipper-highlevel + ;; + mac | mpw | mac-mpw) + basic_machine=m68k-apple + ;; + pmac | pmac-mpw) + basic_machine=powerpc-apple + ;; + *-unknown) + # Make sure to match an already-canonicalized machine name. + ;; + *) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` + ;; + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if [ x"$os" != x"" ] +then +case $os in + # First match some system type aliases + # that might get confused with valid system types. + # -solaris* is a basic system type, with this one exception. + -solaris1 | -solaris1.*) + os=`echo $os | sed -e 's|solaris1|sunos4|'` + ;; + -solaris) + os=-solaris2 + ;; + -svr4*) + os=-sysv4 + ;; + -unixware*) + os=-sysv4.2uw + ;; + -gnu/linux*) + os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` + ;; + # First accept the basic system types. + # The portable systems comes first. + # Each alternative MUST END IN A *, to match a version number. + # -sysv* is not here because it comes later, after sysvr4. + -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ + | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -kopensolaris* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ + | -aos* | -aros* \ + | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ + | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ + | -openbsd* | -solidbsd* \ + | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ + | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ + | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ + | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ + | -chorusos* | -chorusrdb* | -cegcc* \ + | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ + | -uxpv* | -beos* | -mpeix* | -udk* \ + | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ + | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ + | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ + | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ + | -skyos* | -haiku* | -rdos* | -toppers* | -drops*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; + -qnx*) + case $basic_machine in + x86-* | i*86-*) + ;; + *) + os=-nto$os + ;; + esac + ;; + -nto-qnx*) + ;; + -nto*) + os=`echo $os | sed -e 's|nto|nto-qnx|'` + ;; + -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ + | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) + ;; + -mac*) + os=`echo $os | sed -e 's|mac|macos|'` + ;; + -linux-dietlibc) + os=-linux-dietlibc + ;; + -linux*) + os=`echo $os | sed -e 's|linux|linux-gnu|'` + ;; + -sunos5*) + os=`echo $os | sed -e 's|sunos5|solaris2|'` + ;; + -sunos6*) + os=`echo $os | sed -e 's|sunos6|solaris3|'` + ;; + -opened*) + os=-openedition + ;; + -os400*) + os=-os400 + ;; + -wince*) + os=-wince + ;; + -osfrose*) + os=-osfrose + ;; + -osf*) + os=-osf + ;; + -utek*) + os=-bsd + ;; + -dynix*) + os=-bsd + ;; + -acis*) + os=-aos + ;; + -atheos*) + os=-atheos + ;; + -syllable*) + os=-syllable + ;; + -386bsd) + os=-bsd + ;; + -ctix* | -uts*) + os=-sysv + ;; + -nova*) + os=-rtmk-nova + ;; + -ns2 ) + os=-nextstep2 + ;; + -nsk*) + os=-nsk + ;; + # Preserve the version number of sinix5. + -sinix5.*) + os=`echo $os | sed -e 's|sinix|sysv|'` + ;; + -sinix*) + os=-sysv4 + ;; + -tpf*) + os=-tpf + ;; + -triton*) + os=-sysv3 + ;; + -oss*) + os=-sysv3 + ;; + -svr4) + os=-sysv4 + ;; + -svr3) + os=-sysv3 + ;; + -sysvr4) + os=-sysv4 + ;; + # This must come after -sysvr4. + -sysv*) + ;; + -ose*) + os=-ose + ;; + -es1800*) + os=-ose + ;; + -xenix) + os=-xenix + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + os=-mint + ;; + -aros*) + os=-aros + ;; + -kaos*) + os=-kaos + ;; + -zvmoe) + os=-zvmoe + ;; + -dicos*) + os=-dicos + ;; + -none) + ;; + *) + # Get rid of the `-' at the beginning of $os. + os=`echo $os | sed 's/[^-]*-//'` + echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 + exit 1 + ;; +esac +else + +# Here we handle the default operating systems that come with various machines. +# The value should be what the vendor currently ships out the door with their +# machine or put another way, the most popular os provided with the machine. + +# Note that if you're going to try to match "-MANUFACTURER" here (say, +# "-sun"), then you have to tell the case statement up towards the top +# that MANUFACTURER isn't an operating system. Otherwise, code above +# will signal an error saying that MANUFACTURER isn't an operating +# system, and we'll never get to this point. + +case $basic_machine in + score-*) + os=-elf + ;; + spu-*) + os=-elf + ;; + *-acorn) + os=-riscix1.2 + ;; + arm*-rebel) + os=-linux + ;; + arm*-semi) + os=-aout + ;; + c4x-* | tic4x-*) + os=-coff + ;; + # This must come before the *-dec entry. + pdp10-*) + os=-tops20 + ;; + pdp11-*) + os=-none + ;; + *-dec | vax-*) + os=-ultrix4.2 + ;; + m68*-apollo) + os=-domain + ;; + i386-sun) + os=-sunos4.0.2 + ;; + m68000-sun) + os=-sunos3 + # This also exists in the configure program, but was not the + # default. + # os=-sunos4 + ;; + m68*-cisco) + os=-aout + ;; + mep-*) + os=-elf + ;; + mips*-cisco) + os=-elf + ;; + mips*-*) + os=-elf + ;; + or32-*) + os=-coff + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=-sysv3 + ;; + sparc-* | *-sun) + os=-sunos4.1.1 + ;; + *-be) + os=-beos + ;; + *-haiku) + os=-haiku + ;; + *-ibm) + os=-aix + ;; + *-knuth) + os=-mmixware + ;; + *-wec) + os=-proelf + ;; + *-winbond) + os=-proelf + ;; + *-oki) + os=-proelf + ;; + *-hp) + os=-hpux + ;; + *-hitachi) + os=-hiux + ;; + i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) + os=-sysv + ;; + *-cbm) + os=-amigaos + ;; + *-dg) + os=-dgux + ;; + *-dolphin) + os=-sysv3 + ;; + m68k-ccur) + os=-rtu + ;; + m88k-omron*) + os=-luna + ;; + *-next ) + os=-nextstep + ;; + *-sequent) + os=-ptx + ;; + *-crds) + os=-unos + ;; + *-ns) + os=-genix + ;; + i370-*) + os=-mvs + ;; + *-next) + os=-nextstep3 + ;; + *-gould) + os=-sysv + ;; + *-highlevel) + os=-bsd + ;; + *-encore) + os=-bsd + ;; + *-sgi) + os=-irix + ;; + *-siemens) + os=-sysv4 + ;; + *-masscomp) + os=-rtu + ;; + f30[01]-fujitsu | f700-fujitsu) + os=-uxpv + ;; + *-rom68k) + os=-coff + ;; + *-*bug) + os=-coff + ;; + *-apple) + os=-macos + ;; + *-atari*) + os=-mint + ;; + *) + os=-none + ;; +esac +fi + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) + vendor=acorn + ;; + -sunos*) + vendor=sun + ;; + -aix*) + vendor=ibm + ;; + -beos*) + vendor=be + ;; + -hpux*) + vendor=hp + ;; + -mpeix*) + vendor=hp + ;; + -hiux*) + vendor=hitachi + ;; + -unos*) + vendor=crds + ;; + -dgux*) + vendor=dg + ;; + -luna*) + vendor=omron + ;; + -genix*) + vendor=ns + ;; + -mvs* | -opened*) + vendor=ibm + ;; + -os400*) + vendor=ibm + ;; + -ptx*) + vendor=sequent + ;; + -tpf*) + vendor=ibm + ;; + -vxsim* | -vxworks* | -windiss*) + vendor=wrs + ;; + -aux*) + vendor=apple + ;; + -hms*) + vendor=hitachi + ;; + -mpw* | -macos*) + vendor=apple + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + vendor=atari + ;; + -vos*) + vendor=stratus + ;; + esac + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` + ;; +esac + +echo $basic_machine$os +exit + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/bin/install-sh b/bin/install-sh new file mode 120000 index 0000000..088407d --- /dev/null +++ b/bin/install-sh @@ -0,0 +1 @@ +minstall \ No newline at end of file diff --git a/bin/minstall b/bin/minstall new file mode 100755 index 0000000..094ec0c --- /dev/null +++ b/bin/minstall @@ -0,0 +1,112 @@ +#!/bin/sh + + +# A minimal replacement for 'install' that supports installing symbolic links. +# Only a limited number of options are supported: +# -d dir Create a directory +# -m mode Sets a file's mode when installing + + +# If these commands aren't portable, we'll need some "if (arch)" type stuff +SYMLINK="ln -s" +MKDIR="mkdir -p" +RM="rm -f" + +MODE="" + +if [ "$1" = "-d" ] ; then + # make a directory path + $MKDIR "$2" + exit 0 +fi + +if [ "$1" = "-m" ] ; then + # set file mode + MODE=$2 + shift 2 +fi + +# install file(s) into destination +if [ $# -ge 2 ] ; then + + # Last cmd line arg is the dest dir + for FILE in $@ ; do + DESTDIR="$FILE" + done + + # Loop over args, moving them to DEST directory + I=1 + for FILE in $@ ; do + if [ $I = $# ] ; then + # stop, don't want to install $DEST into $DEST + exit 0 + fi + + DEST=$DESTDIR + + # On CYGWIN, because DLLs are loaded by the native Win32 loader, + # they are installed in the executable path. Stub libraries used + # only for linking are installed in the library path + case `uname` in + CYGWIN*) + case $FILE in + *.dll) + DEST="$DEST/../bin" + ;; + *) + ;; + esac + ;; + *) + ;; + esac + + PWDSAVE=`pwd` + + # determine file's type + if [ -h "$FILE" ] ; then + #echo $FILE is a symlink + # Unfortunately, cp -d isn't universal so we have to + # use a work-around. + + # Use ls -l to find the target that the link points to + LL=`ls -l "$FILE"` + for L in $LL ; do + TARGET=$L + done + #echo $FILE is a symlink pointing to $TARGET + + FILE=`basename "$FILE"` + # Go to $DEST and make the link + cd "$DEST" # pushd + $RM "$FILE" + $SYMLINK "$TARGET" "$FILE" + cd "$PWDSAVE" # popd + + elif [ -f "$FILE" ] ; then + #echo "$FILE" is a regular file + # Only copy if the files differ + if ! cmp -s $FILE $DEST/`basename $FILE`; then + $RM "$DEST/`basename $FILE`" + cp "$FILE" "$DEST" + fi + if [ $MODE ] ; then + FILE=`basename "$FILE"` + chmod $MODE "$DEST/$FILE" + fi + else + echo "Unknown type of argument: " "$FILE" + exit 1 + fi + + I=`expr $I + 1` + done + + exit 0 +fi + +# If we get here, we didn't find anything to do +echo "Usage:" +echo " install -d dir Create named directory" +echo " install [-m mode] file [...] dest Install files in destination" + diff --git a/bin/mklib b/bin/mklib new file mode 100755 index 0000000..2f9223f --- /dev/null +++ b/bin/mklib @@ -0,0 +1,1031 @@ +#!/bin/sh + +# Make a shared library. +# This script should be useful for projects other than Mesa. +# Improvements/fixes are welcome. + + +# Copyright (C) 1999-2006 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. + + +# Clear CDPATH as the 'cd' command will echo stuff +# to stdout if it is set +unset CDPATH + +# Given a list of files, look for .a archives and unpack them. +# Return the original list of files minus the .a files plus the unpacked files. +# first param: name of a temp directory (to be deleted when finished) +# remaining params: list of .o and .a files +expand_archives() { + DIR=$1 + shift + FILES=$@ + NEWFILES="" + ORIG_DIR=`pwd` + mkdir -p "$DIR" + cd "$DIR" + for FILE in $FILES ; do + case $FILE in + *.a) + # extract the .o files from this .a archive + case $FILE in + /*) ;; + *) FILE="$ORIG_DIR/$FILE" ;; + esac + MEMBERS=`ar t $FILE` + ar x $FILE + for MEMBER in $MEMBERS ; do + NEWFILES="$NEWFILES $DIR/$MEMBER" + done + ;; + *) + # other file type, just add to list + NEWFILES="$NEWFILES $FILE" + ;; + esac + done + cd "$ORIG_DIR" + echo $NEWFILES +} + + +# Make static library with 'ar' +# params: +# options to ar +# 1 or 0 to indicate if ranlib should be run +# libname to make +# list of object files +# Return name of library we made +# Example: "make_ar_static_lib -ru 1 libfoo.a foo.o bar.o" +make_ar_static_lib() { + OPTS=$1 + shift; + RANLIB=$1 + shift; + LIBNAME=$1 + shift; + OBJECTS=$@ + + # remove existing lib, if present + rm -f ${LIBNAME} + + # make static lib + ar ${OPTS} ${LIBNAME} ${OBJECTS} + + # run ranlib + if [ ${RANLIB} = 1 ] ; then + ranlib ${LIBNAME} + fi + + echo ${LIBNAME} +} + + +# Print usage info. +usage() { + echo 'Usage: mklib [options] objects' + echo 'Create a shared library from object files.' + echo ' -o LIBRARY specifies the name of the resulting library, without' + echo ' the leading "lib" or any suffix.' + echo ' (eg: "-o GL" might result in "libGL.so" being made)' + echo ' -major N specifies major version number (default is 1)' + echo ' -minor N specifies minor version number (default is 0)' + echo ' -patch N specifies patch version number (default is 0)' + echo ' -lLIBRARY specifies a dependency on LIBRARY' + echo ' -LDIR search in DIR for library dependencies at build time' + echo ' -RDIR search in DIR for library dependencies at run time' + echo ' -linker L explicity specify the linker program to use (eg: gcc, g++)' + echo ' Not observed on all systems at this time.' + echo ' -ldflags OPT specify any additional linker flags in OPT' + echo ' -cplusplus link with C++ runtime' + echo ' -static make a static library (default is dynamic/shared)' + echo ' -dlopen make a shared library suitable for dynamic loading' + echo ' -install DIR put resulting library file(s) in DIR' + echo ' -arch ARCH override using `uname` to determine host system' + echo ' -archopt OPT specify an extra achitecture-specific option OPT' + echo ' -altopts OPTS alternate options to override all others' + echo " -noprefix don't prefix library name with 'lib' nor add any suffix" + echo ' -exports FILE only export the symbols listed in FILE' + echo ' -id NAME Sets the id of the dylib (Darwin)' + echo ' -h, --help display this information and exit' +} + + +# +# Option defaults +# +LIBNAME="" +MAJOR=1 +MINOR=0 +PATCH="" +DEPS="" +LINK="" +LDFLAGS="" +CPLUSPLUS=0 +STATIC=0 +DLOPEN=0 +INSTALLDIR="." +ARCH="auto" +ARCHOPT="" +NOPREFIX=0 +EXPORTS="" +ID="" + +# +# Parse arguments +# +while true +do + case $1 in + '-h' | '--help') + usage + exit 1 + ;; + '-o') + shift 1; + LIBNAME=$1 + ;; + '-major') + shift 1; + MAJOR=$1 + ;; + '-minor') + shift 1; + MINOR=$1 + ;; + '-patch') + shift 1; + PATCH=$1 + ;; + '-linker') + shift 1; + LINK=$1 + ;; + '-ldflags') + shift 1; + LDFLAGS=$1 + ;; + -l*) + DEPS="$DEPS $1" + ;; + -L*) + DEPS="$DEPS $1" + ;; + -R*) + DEPS="$DEPS $1" + ;; + -Wl*) + DEPS="$DEPS $1" + ;; + -pthread) + # this is a special case (see bugzilla 10876) + DEPS="$DEPS $1" + ;; + '-pthread') + DEPS="$DEPS -pthread" + ;; + '-cplusplus') + CPLUSPLUS=1 + ;; + '-static') + STATIC=1 + ;; + '-dlopen') + DLOPEN=1 + ;; + '-install') + shift 1; + INSTALLDIR=$1 + ;; + '-arch') + shift 1; + ARCH=$1 + ;; + '-archopt') + shift 1; + ARCHOPT=$1 + ;; + '-altopts') + shift 1; + ALTOPTS=$1 + ;; + '-noprefix') + NOPREFIX=1 + ;; + '-exports') + shift 1; + EXPORTS=$1 + ;; + '-id') + shift 1; + ID=$1 + ;; + -*) + echo "mklib: Unknown option: " $1 ; + exit 1 + ;; + *) + # This should be the first object file, stop parsing + break + esac + shift 1 +done +OBJECTS=$@ + + +if [ ${ARCH} = "auto" ] ; then + ARCH=`uname` +fi + + +if [ $STATIC = 1 ]; then + # filter out linker options inside object list + NEWOBJECTS="" + for OBJ in $OBJECTS ; do + case $OBJ in + -Wl,*) + echo "mklib: warning: ignoring $OBJ for static library" + ;; + *) + NEWOBJECTS="$NEWOBJECTS $OBJ" + ;; + esac + done + OBJECTS=$NEWOBJECTS +fi + + +# +# Error checking +# +if [ "x${LIBNAME}" = "x" ] ; then + echo "mklib: Error: no library name specified (-h for help)" + exit 1 +fi +if [ "x${OBJECTS}" = "x" ] ; then + echo "mklib: Error: no object files specified (-h for help)" + exit 1 +fi + + +# +# Debugging info +# +if [ ] ; then + echo "-----------------" + echo ARCH is $ARCH + echo LIBNAME is $LIBNAME + echo MAJOR is $MAJOR + echo MINOR is $MINOR + echo PATCH is $PATCH + echo DEPS are $DEPS + echo "EXPORTS in" $EXPORTS + echo ID is $ID + echo "-----------------" +fi + + +# +# OK, make the library now +# +case $ARCH in + + 'Linux' | 'OpenBSD' | 'DragonFly' | 'GNU' | GNU/*) + # we assume gcc + + if [ "x$LINK" = "x" ] ; then + # -linker was not specified so set default link command now + if [ $CPLUSPLUS = 1 ] ; then + LINK=g++ + else + LINK=gcc + fi + fi + + if [ $NOPREFIX = 1 ] ; then + # No "lib" or ".so" part + echo "mklib: Making" $ARCH "shared library: " ${LIBNAME} + case $ARCH in 'Linux' | 'GNU' | GNU/*) + OPTS="-Xlinker -Bsymbolic -shared" + ;; + *) + OPTS="-shared" + ;; + esac + + # Check if objects are 32-bit and we're running in 64-bit + # environment. If so, pass -m32 flag to linker. + set ${OBJECTS} + ABI32=`file $1 | grep 32-bit` + if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then + OPTS="-m32 ${OPTS}" + fi + + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + + rm -f ${LIBNAME} + # make lib + ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} + # finish up + FINAL_LIBS="${LIBNAME}" + elif [ $STATIC = 1 ] ; then + # make a static .a library + LIBNAME="lib${LIBNAME}.a" # prefix with "lib", suffix with ".a" + echo "mklib: Making" $ARCH "static library: " ${LIBNAME} + OPTS="-ru" + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + + # expand .a into .o files + NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS` + + # make static lib + FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}` + + # remove temporary extracted .o files + rm -rf ${LIBNAME}.obj + else + # make dynamic library + LIBNAME="lib${LIBNAME}" # prefix with "lib" + case $ARCH in 'Linux' | 'GNU' | GNU/*) + OPTS="-Xlinker -Bsymbolic -shared -Wl,-soname,${LIBNAME}.so.${MAJOR}" + ;; + *) + OPTS="-shared -Wl,-soname,${LIBNAME}.so.${MAJOR}" + ;; + esac + if [ $EXPORTS ] ; then + #OPTS="${OPTS} -Xlinker --retain-symbols-file ${EXPORTS}" + # Make the 'exptmp' file for --version-script option + echo "{" > exptmp + echo "global:" >> exptmp + sed 's/$/;/' ${EXPORTS} >> exptmp + echo "local:" >> exptmp + echo "*;" >> exptmp + echo "};" >> exptmp + OPTS="${OPTS} -Xlinker --version-script=exptmp" + # exptmp is removed below + fi + + # Check if objects are 32-bit and we're running in 64-bit + # environment. If so, pass -m32 flag to linker. + set ${OBJECTS} + ABI32=`file $1 | grep 32-bit` + if [ "${ABI32}" -a `uname -m` = "x86_64" ] ; then + OPTS="-m32 ${OPTS}" + fi + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + + if [ x${PATCH} = "x" ] ; then + VERSION="${MAJOR}.${MINOR}" + else + VERSION="${MAJOR}.${MINOR}.${PATCH}" + fi + + echo "mklib: Making" $ARCH "shared library: " ${LIBNAME}.so.${VERSION} + + # rm any old libs + rm -f ${LIBNAME}.so.${VERSION} + rm -f ${LIBNAME}.so.${MAJOR} + rm -f ${LIBNAME}.so + + # make lib + ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS} + # make usual symlinks + ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} + ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so + # finish up + FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so" +# rm -f exptmp + fi + ;; + + 'SunOS') + if [ $STATIC = 1 ] ; then + LIBNAME="lib${LIBNAME}.a" + echo "mklib: Making SunOS static library: " ${LIBNAME} + FINAL_LIBS=`make_ar_static_lib -ruc 0 ${LIBNAME} ${OBJECTS}` + else + if [ $NOPREFIX = 0 ] ; then + LIBNAME="lib${LIBNAME}.so" + fi + echo "mklib: Making SunOS shared library: " ${LIBNAME} + + if [ "x$LINK" = "x" ] ; then + # -linker was not specified, choose default linker now + if [ $CPLUSPLUS = 1 ] ; then + # determine linker and options for C++ code + if [ `which c++` ] ; then + # use Sun c++ + LINK="c++" + elif [ `type g++` ] ; then + # use g++ + LINK="g++" + else + echo "mklib: warning: can't find C++ compiler, trying CC." + LINK="CC" + fi + else + # use native Sun linker for C code + LINK="ld" + fi + fi + + # linker options + if [ ${LINK} = "ld" -o ${LINK} = "cc" -o ${LINK} = "CC" ] ; then + # SunOS tools, -G to make shared libs + OPTS="-G" + else + # gcc linker + # Check if objects are 32-bit and we're running in 64-bit + # environment. If so, pass -m32 flag to linker. + set ${OBJECTS} + ABI32=`file $1 | grep 32-bit` + if [ "${ABI32}" ] ; then + OPTS="-m32 -shared -Wl,-Bdynamic" + else + OPTS="-m64 -shared -Wl,-Bdynamic" + fi + fi + + # If using Sun C++ compiler, need to tell it not to add runpaths + # that are specific to the build machine + if [ ${LINK} = "CC" ] ; then + OPTS="${OPTS} -norunpath" + fi + + # Solaris linker requires explicitly listing the Standard C & C++ + # libraries in the link path when building shared objects + if [ ${LINK} = "CC" ] ; then + DEPS="${DEPS} -lCrun" + fi + DEPS="${DEPS} -lc" + + if [ $EXPORTS ] ; then + # Make the 'mapfile.scope' linker mapfile + echo "{" > mapfile.scope + echo "global:" >> mapfile.scope + sed 's/$/;/' ${EXPORTS} >> mapfile.scope + echo "local:" >> mapfile.scope + echo " *;" >> mapfile.scope + echo "};" >> mapfile.scope + OPTS="${OPTS} -Wl,-Mmapfile.scope" + fi + + # Check if objects are 64-bit + # file says: ELF 64-bit MSB relocatable SPARCV9 Version 1 + set ${OBJECTS} + if [ ${LINK} = "cc" -o ${LINK} = "CC" ] ; then + ABI64=`file $1 | grep "ELF 64-bit"` + if [ "${ABI64}" ] ; then + case `uname -p` in + sparc) OPTS="${OPTS} -xarch=v9" ;; + i386) OPTS="${OPTS} -xarch=amd64" ;; + esac + fi + fi + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + + # for debug: + #echo "mklib: linker is" ${LINK} ${OPTS} + if [ $NOPREFIX = 1 ] ; then + rm -f ${LIBNAME} + ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} + FINAL_LIBS="${LIBNAME}" + else + rm -f ${LIBNAME}.${MAJOR} ${LIBNAME} + ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.${MAJOR} -h ${LIBNAME}.${MAJOR} ${OBJECTS} ${DEPS} + ln -s ${LIBNAME}.${MAJOR} ${LIBNAME} + FINAL_LIBS="${LIBNAME}.${MAJOR} ${LIBNAME}" + fi + fi + ;; + + 'FreeBSD') + # we assume gcc + + if [ "x$LINK" = "x" ] ; then + # -linker was not specified so set default link command now + if [ $CPLUSPLUS = 1 ] ; then + LINK=g++ + else + LINK=gcc + fi + fi + + if [ $NOPREFIX = 1 ] ; then + # No "lib" or ".so" part + echo "mklib: Making FreeBSD shared library: " ${LIBNAME} + OPTS="-shared" + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + rm -f ${LIBNAME} + ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} + FINAL_LIBS=${LIBNAME} + elif [ $STATIC = 1 ] ; then + # make a static .a library + STLIB="lib${LIBNAME}.a" + echo "mklib: Making FreeBSD static library: " ${STLIB} + + # expand .a into .o files + NEW_OBJECTS=`expand_archives ${STLIB}.obj $OBJECTS` + + FINAL_LIBS=`make_ar_static_lib cq 1 ${STLIB} ${NEW_OBJECTS}` + + # remove temporary extracted .o files + rm -rf ${STLIB}.obj + else + # make dynamic library + SHLIB="lib${LIBNAME}.so.${MAJOR}" + OPTS="-shared -Wl,-soname,${SHLIB}" + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + echo "mklib: Making FreeBSD shared library: " ${SHLIB} + rm -f ${SHLIB} + ${LINK} ${OPTS} ${LDFLAGS} -o ${SHLIB} ${OBJECTS} ${DEPS} + ln -sf ${SHLIB} "lib${LIBNAME}.so" + FINAL_LIBS="${SHLIB} lib${LIBNAME}.so" + fi + ;; + + 'NetBSD') + if [ $STATIC = 1 ] ; then + LIBNAME="lib${LIBNAME}_pic.a" + echo "mklib: Making NetBSD PIC static library: " ${LIBNAME} + FINAL_LIBS=`make_ar_static_lib cq 1 ${LIBNAME} ${OBJECTS}` + else + LIBNAME="lib${LIBNAME}.so.${MAJOR}.${MINOR}" + echo "mklib: Making NetBSD PIC shared library: " ${LIBNAME} + rm -f ${LIBNAME} + ld -x -Bshareable -Bforcearchive -o ${LIBNAME} ${OBJECTS} + FINAL_LIBS=${LIBNAME} + fi + ;; + + 'IRIX' | 'IRIX64') + if [ $STATIC = 1 ] ; then + LIBNAME="lib${LIBNAME}.a" + FINAL_LIBS=`make_ar_static_lib rc 0 ${LIBNAME} ${OBJECTS}` + else + LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" + + # examine first object to determine ABI + set ${OBJECTS} + ABI_O32=`file $1 | grep 'ELF 32-bit'` + ABI_N32=`file $1 | grep 'ELF N32'` + ABI_N64=`file $1 | grep 'ELF 64-bit'` + if [ "${ABI_O32}" ] ; then + OPTS="-32 -shared -all" + ABI="o32-bit" + elif [ "${ABI_N32}" ] ; then + OPTS="-n32 -shared -all" + ABI="n32-bit" + elif [ "${ABI_N64}" ] ; then + OPTS="-64 -shared -all" + ABI="64-bit" + else + echo "Error: Unexpected IRIX ABI!" + exit 1 + fi + + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + + if [ $CPLUSPLUS = 1 ] ; then + LINK="CC" + else + LINK="ld" + fi + + echo "mklib: Making IRIX " ${ABI} " shared library: " ${LIBNAME} + ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} + FINAL_LIBS=${LIBNAME} + fi + ;; + + 'linux-cygwin') + LIBNAME="lib${LIBNAME}.a" + echo "mklib: Making linux-cygwin library: " ${LIBNAME} + rm -f ${LIBNAME} + gnuwin32ar ruv ${LIBNAME} ${OBJECTS} + FINAL_LIBS=${LIBNAME} + ;; + + 'HP-UX') + if [ $STATIC = 1 ] ; then + LIBNAME="lib${LIBNAME}.a" + echo "mklib: Making HP-UX static library: " ${LIBNAME} + FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}` + else + # HP uses a .2 for their current GL/GLU libraries + if [ ${LIBNAME} = "GL" -o ${LIBNAME} = "GLU" ] ; then + MAJOR=2 + fi + RUNLIB="lib${LIBNAME}.${MAJOR}" + DEVLIB="lib${LIBNAME}.sl" + echo "mklib: Making HP-UX shared library: " ${RUNLIB} ${DEVLIB} + ld -b -o ${RUNLIB} +b ${RUNLIB} ${OBJECTS} ${DEPS} + ln -s ${RUNLIB} ${DEVLIB} + FINAL_LIBS="${RUNLIB} ${DEVLIB}" + fi + ;; + + 'AIX' ) + # examine first object to determine ABI + set ${OBJECTS} + ABI_64=`file $1 | grep '64-bit'` + if [ "${ABI_64}" ] ; then + X64="-X64" + Q64="-q64" + OFILE=shr_64.o + else + OFILE=shr.o #Want to be consistent with the IBM libGL.a + fi + + if [ $STATIC = 1 ] ; then + LIBNAME="lib${LIBNAME}.a" + echo "mklib: Making AIX static library: " ${LIBNAME} + FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}` + else + EXPFILE="lib${LIBNAME}.exp" + LIBNAME="lib${LIBNAME}.a" # shared objects are still stored in the .a libraries + OPTS="-bE:${EXPFILE} -bM:SRE -bnoentry ${Q64}" + rm -f ${EXPFILE} ${OFILE} + NM="/bin/nm -eC ${X64}" + echo "#! /usr/lib/${LIBNAME}" > ${EXPFILE} + ${NM} ${OBJECTS} | awk '{ + if ((($2 == "T") || ($2 == "D") || ($2 == "B")) \ + && ( substr($1,1,1) != ".")) { + if (substr ($1, 1, 7) != "__sinit" && + substr ($1, 1, 7) != "__sterm") { + if (substr ($1, 1, 5) == "__tf1") + print (substr ($1, 7)) + else if (substr ($1, 1, 5) == "__tf9") + print (substr ($1, 15)) + else + print $1 + } + } + }' | sort -u >> ${EXPFILE} + + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + + # On AIX a shared library is linked differently when + # you want to dlopen the file + if [ $DLOPEN = "1" ] ; then + cc -G ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} + else + cc ${OPTS} ${LDFLAGS} -o ${OFILE} ${OBJECTS} ${DEPS} + ar ${X64} -r ${LIBNAME} ${OFILE} + fi + + FINAL_LIBS="${LIBNAME}" + fi + ;; + + 'OpenSTEP') + LIBNAME="lib${LIBNAME}.a" + echo "mklib: Making OpenSTEP static library: " ${LIBNAME} + libtool -static -o ${LIBNAME} - ${OBJECTS} + FINAL_LIBS=${LIBNAME} + ;; + + 'OSF1') + if [ $STATIC = 1 ] ; then + LIBNAME="lib${LIBNAME}.a" + echo "mklib: Making OSF/1 static library: " ${LIBNAME} + FINAL_LIBS=`make_ar_static_lib -ruv 0 ${LIBNAME} ${OBJECTS}` + else + VERSION="${MAJOR}.${MINOR}" + LIBNAME="lib${LIBNAME}.so" + echo "mklib: Making OSF/1 shared library: " ${LIBNAME} + if [ "x$LINK" = "x" ] ; then + if [ $CPLUSPLUS = 1 ] ; then + LINK=cxx + else + LINK=cc + fi + fi + rm -f ${LIBNAME}.${VERSION} + ${LINK} -o ${LIBNAME}.${VERSION} -shared -set_version ${VERSION} -soname ${LIBNAME}.${VERSION} -expect_unresolved \* -all ${OBJECTS} ${DEPS} + ln -sf ${LIBNAME}.${VERSION} ${LIBNAME} + FINAL_LIBS="${LIBNAME} ${LIBNAME}.${VERSION}" + fi + ;; + + 'Darwin') + if [ $STATIC = 1 ] ; then + LIBNAME="lib${LIBNAME}.a" + echo "mklib: Making Darwin static library: " ${LIBNAME} + OPTS="-ruvs" + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + + # expand .a into .o files + NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS` + + # make static lib + FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}` + + # remove temporary extracted .o files + rm -rf ${LIBNAME}.obj + + FINAL_LIBS=${LIBNAME} + else + # On Darwin a .bundle is used for a library that you want to dlopen + if [ $DLOPEN = "1" ] ; then + LIBSUFFIX="bundle" + OPTS="${ARCHOPT} -bundle -multiply_defined suppress" + else + LIBSUFFIX="dylib" + if [ -z "$ID" ] ; then + ID="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}" + fi + OPTS="${ARCHOPT} -dynamiclib -multiply_defined suppress -current_version ${MAJOR}.${MINOR}.0 -compatibility_version ${MAJOR}.${MINOR}.0 -install_name ${ID}" + fi + + if [ ${EXPORTS} ] ; then + if [ -f ${EXPORTS}".darwin" ] ; then + EXPORTS=$EXPORTS".darwin" + fi + OPTS="${OPTS} -exported_symbols_list ${EXPORTS}" + fi + + LINKNAME="lib${LIBNAME}.${MAJOR}.${LIBSUFFIX}" + LINKNAME2="lib${LIBNAME}.${LIBSUFFIX}" + LIBNAME="lib${LIBNAME}.${MAJOR}.${MINOR}.${LIBSUFFIX}" + + # examine first object to determine ABI + set ${OBJECTS} + ABIS=`lipo -info $1 | sed s/.*://` + for ABI in $ABIS; do + OPTS="${OPTS} -arch ${ABI}" + done + + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + + # XXX can we always add -isysroot /Developer/SDKs/MacOSX10.4u.sdk + # to OPTS here? + + # determine linker + if [ $CPLUSPLUS = 1 ] ; then + LINK="g++" + else + LINK="cc" + fi + + echo "mklib: Making Darwin shared library: " ${LIBNAME} + + ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} + ln -s ${LIBNAME} ${LINKNAME} + ln -s ${LIBNAME} ${LINKNAME2} + FINAL_LIBS="${LIBNAME} ${LINKNAME} ${LINKNAME2}" + fi + ;; + + 'LynxOS') + LIBNAME="lib${LIBNAME}.a" + echo "mklib: Making LynxOS static library: " ${LIBNAME} + FINAL_LIBS=`make_ar_static_lib -ru 0 ${LIBNAME} ${OBJECTS}` + ;; + + 'BeOS') + if [ $STATIC = 1 ] ; then + LIBNAME="lib${LIBNAME}.a" + echo "mklib: Making BeOS static library: " ${LIBNAME} + FINAL_LIBS=`make_ar_static_lib -cru 0 ${LIBNAME} ${OBJECTS}` + else + LIBNAME="lib${LIBNAME}.so" + echo "mklib: Making BeOS shared library: " ${LIBNAME} + gcc -nostart -Xlinker "-soname=${LIBNAME}" -L/Be/develop/lib/x86 -lbe ${DEPS} ${OBJECTS} -o "${LIBNAME}" + mimeset -f "${LIBNAME}" + # XXX remove the Mesa3D stuff here since mklib isn't mesa-specific. + setversion "${LIBNAME}" -app ${MAJOR} ${MINOR} ${PATCH} -short "Powered by Mesa3D!" -long "Powered by Mesa3D!" + fi + FINAL_LIBS=${LIBNAME} + ;; + + 'QNX') + LIBNAME="lib${LIBNAME}.a" + echo "mklib: Making QNX library: " ${LIBNAME} + wlib ${LIBNAME} ${OBJECTS} + FINAL_LIBS=${LIBNAME} + ;; + + 'MorphOS') + LIBNAME="lib${LIBNAME}.a" + echo "mklib: Making MorphOS library: " ${LIBNAME} + ppc-morphos-ar rc ${LIBNAME} ${OBJECTS} + FINAL_LIBS="${LIBNAME}" + ;; + + 'icc' | 'icc-istatic') + # Intel C compiler + # This should get merged into the Linux code, above, since this isn't + # really a different architecture. + LIBNAME="lib${LIBNAME}" # prefix with "lib" + + if [ $STATIC = 1 ] ; then + echo "mklib: Making Intel ICC static library: " ${LIBNAME}.a + LINK="ar" + OPTS="-ruv" + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + # make lib + ${LINK} ${OPTS} ${LIBNAME}.a ${OBJECTS} + # finish up + FINAL_LIBS="${LIBNAME}.a" + else + if [ $ARCH = icc-istatic ] ; then + OPTS="-shared -i-static -cxxlib-icc" + else + OPTS="-shared" + fi + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + VERSION="${MAJOR}.${MINOR}.${PATCH}" + echo "mklib: Making Intel ICC shared library: " ${LIBNAME}.so.${VERSION} + + if [ $CPLUSPLUS = 1 ] ; then + LINK="icpc" + else + LINK="icc" + fi + # rm any old libs + rm -f ${LIBNAME}.so.${VERSION} + rm -f ${LIBNAME}.so.${MAJOR} + rm -f ${LIBNAME}.so + # make lib + ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME}.so.${VERSION} ${OBJECTS} ${DEPS} + # make usual symlinks + ln -s ${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} + ln -s ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so + # finish up + FINAL_LIBS="${LIBNAME}.so.${VERSION} ${LIBNAME}.so.${MAJOR} ${LIBNAME}.so" + fi + ;; + + 'aix-gcc') + # AIX with gcc + if [ $STATIC = 1 ] ; then + LIBNAME="lib${LIBNAME}.a" + echo "mklib: Making AIX GCC static library: " ${LIBNAME} + FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}` + else + LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" + echo "mklib: Making AIX GCC shared library: " ${LIBNAME} + # remove old lib + rm -f ${LIBNAME} + # make the lib + gcc -shared -Wl,-G ${OBJECTS} ${DEPS} -o ${LIBNAME} + # NOTE: the application linking with this library must specify + # the -Wl,-brtl flags to gcc + FINAL_LIBS=${LIBNAME} + fi + ;; + + 'ultrix') + # XXX untested + if [ $STATIC = 0 ] ; then + echo "mklib: Warning shared libs not supported on Ultrix" + fi + LIBNAME="lib${LIBNAME}.a" + echo "mklib: Making static library for Ultrix: " ${LIBNAME} + FINAL_LIBS=`make_ar_static_lib ru 0 ${LIBNAME} ${OBJECTS}` + ;; + + CYGWIN*) + # GCC-based environment + + if [ "x$LINK" = "x" ] ; then + # -linker was not specified so set default link command now + if [ $CPLUSPLUS = 1 ] ; then + LINK=g++ + else + LINK=gcc + fi + fi + + if [ $NOPREFIX = 1 ] ; then + # No "lib" or ".so" part + echo "mklib: Making CYGWIN shared library: " ${LIBNAME} + OPTS="-shared -Wl,--enable-auto-image-base" + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + rm -f ${LIBNAME} + ${LINK} ${OPTS} ${LDFLAGS} -o ${LIBNAME} ${OBJECTS} ${DEPS} || exit $? + FINAL_LIBS=${LIBNAME} + else + CYGNAME="cyg${LIBNAME}" # prefix with "cyg" + LIBNAME="lib${LIBNAME}" # prefix with "lib" + + if [ $STATIC = 1 ] ; then + LIBNAME=${LIBNAME}.a + echo "mklib: Making CYGWIN static library: " ${LIBNAME} + OPTS="-ru" + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + + # expand .a into .o files + NEW_OBJECTS=`expand_archives ${LIBNAME}.obj $OBJECTS` + + FINAL_LIBS=`make_ar_static_lib ${OPTS} 1 ${LIBNAME} ${NEW_OBJECTS}` + + # remove temporary extracted .o files + rm -rf ${LIBNAME}.obj + else + OPTS="-shared -Wl,--enable-auto-image-base -Wl,-export-all -Wl,--out-implib=${LIBNAME}-${MAJOR}.dll.a" + if [ "${ALTOPTS}" ] ; then + OPTS=${ALTOPTS} + fi + echo "mklib: Making CYGWIN shared library: " ${CYGNAME}-${MAJOR}.dll + + # rm any old libs + rm -f ${CYGNAME}-${MAJOR}.dll + rm -f ${LIBNAME}-${MAJOR}.dll.a + rm -f ${LIBNAME}.dll.a + rm -f ${LIBNAME}.a + + # make lib + ${LINK} ${OPTS} ${LDFLAGS} -o ${CYGNAME}-${MAJOR}.dll ${OBJECTS} ${DEPS} || exit $? + # make usual symlinks + ln -s ${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a + # finish up + FINAL_LIBS="${LIBNAME}-${MAJOR}.dll.a ${LIBNAME}.dll.a" + # special case for installing in bin + FINAL_BINS="${CYGNAME}-${MAJOR}.dll" + fi + fi + ;; + + 'example') + # If you're adding support for a new architecture, you can + # start with this: + if [ $STATIC = 1 ] ; then + LIBNAME="lib${LIBNAME}.a" + echo "mklib: Making static library for example arch: " ${LIBNAME} + FINAL_LIBS=`make_ar_static_lib rv 0 ${LIBNAME} ${OBJECTS}` + else + LIBNAME="lib${LIBNAME}.so" # prefix with "lib", suffix with ".so" + echo "mklib: Making shared library for example arch: " ${LIBNAME} + ld -o ${LIBNAME} ${OBJECTS} ${DEPS} + FINAL_LIBS="${LIBNAME}" + fi + ;; + + *) + echo "mklib: ERROR: Don't know how to make a static/shared library for" ${ARCH} + echo "mklib: Please add necessary commands to mklib script." + ;; +esac + + +# +# Put library files into installation directory if specified. +# +if [ ${INSTALLDIR} != "." ] ; then + echo "mklib: Installing" ${FINAL_LIBS} "in" ${INSTALLDIR} + test -d ${INSTALLDIR} || mkdir -p ${INSTALLDIR} + mv ${FINAL_LIBS} ${INSTALLDIR}/ + + if [ "x${FINAL_BINS}" != "x" ] ; then + echo "mklib: Installing" ${FINAL_BINS} "in" ${INSTALLDIR} + mv ${FINAL_BINS} ${INSTALLDIR}/ + fi +fi diff --git a/bin/version.mk b/bin/version.mk new file mode 100755 index 0000000..ab20d79 --- /dev/null +++ b/bin/version.mk @@ -0,0 +1,17 @@ +#!/usr/bin/make -sf +# Print the various Mesa version fields. This is mostly used to add the +# version to configure. + +# This reflects that this script is usually called from the toplevel +TOP = . + +include $(TOP)/configs/default + +version: + @echo $(MESA_VERSION) +major: + @echo $(MESA_MAJOR) +minor: + @echo $(MESA_MINOR) +tiny: + @echo $(MESA_TINY) diff --git a/configs/aix b/configs/aix new file mode 100644 index 0000000..ebbf583 --- /dev/null +++ b/configs/aix @@ -0,0 +1,30 @@ +# Configuration for AIX, dynamic libs + +include $(TOP)/configs/default + +CONFIG_NAME = aix + +# Compiler and flags +CC = cc +CXX = xlC + +CFLAGS = -O -DAIXV3 -DPTHREADS +CXXFLAGS = -O -DAIXV3 -DPTHREADS + +# Misc tools and flags +MKLIB_OPTIONS = + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +GL_LIB_DEPS = -lX11 -lXext -lpthread -lm +GLU_LIB_DEPS = -L$(TOP)/lib -l$(GL_LIB) -lm -lC +GLUT_LIB_DEPS = -L$(TOP)/lib -l$(GLU_LIB) -l$(GL_LIB) -lXi -lXmu -lX11 -lm +GLW_LIB_DEPS = -L$(TOP)/lib -l$(GL_LIB) -lXm -lXt -lX11 +OSMESA_LIB_DEPS = -L$(TOP)/lib -l$(GL_LIB) +APP_LIB_DEPS = -L$(TOP)/lib -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXext -lXmu -lXi -lpthread -lm -lC + diff --git a/configs/aix-64 b/configs/aix-64 new file mode 100644 index 0000000..5d2edc5 --- /dev/null +++ b/configs/aix-64 @@ -0,0 +1,27 @@ +# Configuration for AIX 64-bit, dynamic libs + +include $(TOP)/configs/default + +CONFIG_NAME = aix-64 + +# Compiler and flags +CC = xlc +CXX = xlC + +CFLAGS = -q64 -qmaxmem=16384 -O -DAIXV3 -DPTHREADS +CXXFLAGS = -q64 -qmaxmem=16384 -O -DAIXV3 -DPTHREADS +LIB_DIR = lib64 + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +GL_LIB_DEPS = -lX11 -lXext -lm -lpthread +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm -lC +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lXi -lXmu -lX11 -lm +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lXm -lXt -lX11 +APP_LIB_DEPS = -L$(TOP)/lib64 -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXext -lXmu -lXi -lm -lpthread -lC + diff --git a/configs/aix-64-static b/configs/aix-64-static new file mode 100644 index 0000000..6910e89 --- /dev/null +++ b/configs/aix-64-static @@ -0,0 +1,25 @@ +# Configuration for AIX, static libs + +include $(TOP)/configs/default + +CONFIG_NAME = aix-64-static + +# Compiler and flags +CC = cc +CXX = xlC + +CFLAGS = -q64 -O -DAIXV3 -DPTHREADS +CXXFLAGS = -q64 -O -DAIXV3 -DPTHREADS +MKLIB_OPTIONS = -static +LIB_DIR = lib64 + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +APP_LIB_DEPS = -q64 -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) \ + -lX11 -lXext -lXmu -lXi -lm -lpthread -lC + diff --git a/configs/aix-gcc b/configs/aix-gcc new file mode 100644 index 0000000..3b964f3 --- /dev/null +++ b/configs/aix-gcc @@ -0,0 +1,23 @@ +# Configuration for AIX with gcc + +include $(TOP)/configs/default + +CONFIG_NAME = aix-gcc + +# Compiler and flags +CC = gcc +CXX = g++ + +CFLAGS = -O2 -DAIXV3 +CXXFLAGS = -O2 -DAIXV3 + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +MKLIB_OPTIONS = -arch aix-gcc +GL_LIB_DEPS = -lX11 -lXext -lm +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lXi -lXmu +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -Wl,-brtl -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm -lX11 -lXext -lXmu -lXi + diff --git a/configs/aix-static b/configs/aix-static new file mode 100644 index 0000000..5631843 --- /dev/null +++ b/configs/aix-static @@ -0,0 +1,25 @@ +# Configuration for AIX, static libs + +include $(TOP)/configs/default + +CONFIG_NAME = aix-static + +# Compiler and flags +CC = cc +CXX = xlC + +CFLAGS = -O -DAIXV3 -DPTHREADS +CXXFLAGS = -O -DAIXV3 -DPTHREADS +MKLIB_OPTIONS = -static + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) \ + -lX11 -lXext -lXmu -lXi -lm -lpthread -lC + + diff --git a/configs/autoconf.in b/configs/autoconf.in new file mode 100644 index 0000000..1538d9a --- /dev/null +++ b/configs/autoconf.in @@ -0,0 +1,196 @@ +# Autoconf configuration + +# Pull in the defaults +include $(TOP)/configs/default + +# This is generated by configure +CONFIG_NAME = autoconf + +# Compiler and flags +CC = @CC@ +CXX = @CXX@ +OPT_FLAGS = @OPT_FLAGS@ +ARCH_FLAGS = @ARCH_FLAGS@ +ASM_FLAGS = @ASM_FLAGS@ +PIC_FLAGS = @PIC_FLAGS@ +DEFINES = @DEFINES@ +API_DEFINES = @API_DEFINES@ +GLES_OVERLAY = @GLES_OVERLAY@ +CFLAGS = @CPPFLAGS@ @CFLAGS@ \ + $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(ASM_FLAGS) $(DEFINES) +CXXFLAGS = @CPPFLAGS@ @CXXFLAGS@ \ + $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(DEFINES) +LDFLAGS = @LDFLAGS@ +EXTRA_LIB_PATH = @EXTRA_LIB_PATH@ +RADEON_CFLAGS = @RADEON_CFLAGS@ +RADEON_LDFLAGS = @RADEON_LDFLAGS@ +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@ +GLW_CFLAGS = @GLW_CFLAGS@ +GLUT_CFLAGS = @GLUT_CFLAGS@ + +# dlopen +DLOPEN_LIBS = @DLOPEN_LIBS@ + +# Source selection +MESA_ASM_SOURCES = @MESA_ASM_SOURCES@ +GLAPI_ASM_SOURCES = @GLAPI_ASM_SOURCES@ + +# Misc tools and flags +MAKE = @MAKE@ +SHELL = @SHELL@ +MKLIB_OPTIONS = @MKLIB_OPTIONS@ +MKDEP = @MKDEP@ +MKDEP_OPTIONS = @MKDEP_OPTIONS@ +INSTALL = @INSTALL@ + +# Python and flags (generally only needed by the developers) +PYTHON2 = @PYTHON2@ +PYTHON_FLAGS = -t -O -O + +# Library names (base name) +GL_LIB = GL +GLU_LIB = GLU +GLUT_LIB = glut +GLW_LIB = GLw +OSMESA_LIB = @OSMESA_LIB@ +GLESv1_CM_LIB = GLESv1_CM +GLESv2_LIB = GLESv2 +VG_LIB = OpenVG + +# Library names (actual file names) +GL_LIB_NAME = @GL_LIB_NAME@ +GLU_LIB_NAME = @GLU_LIB_NAME@ +GLUT_LIB_NAME = @GLUT_LIB_NAME@ +GLW_LIB_NAME = @GLW_LIB_NAME@ +OSMESA_LIB_NAME = @OSMESA_LIB_NAME@ +EGL_LIB_NAME = @EGL_LIB_NAME@ +GLESv1_CM_LIB_NAME = @GLESv1_CM_LIB_NAME@ +GLESv2_LIB_NAME = @GLESv2_LIB_NAME@ +VG_LIB_NAME = @VG_LIB_NAME@ + +# Globs used to install the lib and all symlinks +GL_LIB_GLOB = @GL_LIB_GLOB@ +GLU_LIB_GLOB = @GLU_LIB_GLOB@ +GLUT_LIB_GLOB = @GLUT_LIB_GLOB@ +GLW_LIB_GLOB = @GLW_LIB_GLOB@ +OSMESA_LIB_GLOB = @OSMESA_LIB_GLOB@ +EGL_LIB_GLOB = @EGL_LIB_GLOB@ +GLESv1_CM_LIB_GLOB = @GLESv1_CM_LIB_GLOB@ +GLESv2_LIB_GLOB = @GLESv2_LIB_GLOB@ +VG_LIB_GLOB = @VG_LIB_GLOB@ + +# Directories to build +LIB_DIR = @LIB_DIR@ +SRC_DIRS = @SRC_DIRS@ +GLU_DIRS = @GLU_DIRS@ +DRIVER_DIRS = @DRIVER_DIRS@ +EGL_DRIVERS_DIRS = @EGL_DRIVERS_DIRS@ +GALLIUM_DIRS = @GALLIUM_DIRS@ +GALLIUM_DRIVERS_DIRS = @GALLIUM_DRIVERS_DIRS@ +GALLIUM_WINSYS_DIRS = @GALLIUM_WINSYS_DIRS@ +GALLIUM_TARGET_DIRS = @GALLIUM_TARGET_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) + +# Driver specific build vars +DRI_DIRS = @DRI_DIRS@ +EGL_PLATFORMS = @EGL_PLATFORMS@ +EGL_CLIENT_APIS = @EGL_CLIENT_APIS@ + +# Dependencies +X11_INCLUDES = @X11_INCLUDES@ + +# GLw motif setup +GLW_SOURCES = @GLW_SOURCES@ +MOTIF_CFLAGS = @MOTIF_CFLAGS@ + +# Library/program dependencies +GL_LIB_DEPS = $(EXTRA_LIB_PATH) @GL_LIB_DEPS@ +OSMESA_LIB_DEPS = -L$(TOP)/$(LIB_DIR) @OSMESA_MESA_DEPS@ \ + $(EXTRA_LIB_PATH) @OSMESA_LIB_DEPS@ +EGL_LIB_DEPS = $(EXTRA_LIB_PATH) @EGL_LIB_DEPS@ +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) @GLU_MESA_DEPS@ \ + $(EXTRA_LIB_PATH) @GLU_LIB_DEPS@ +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) @GLUT_MESA_DEPS@ \ + $(EXTRA_LIB_PATH) @GLUT_LIB_DEPS@ +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) @GLW_MESA_DEPS@ \ + $(EXTRA_LIB_PATH) @GLW_LIB_DEPS@ +APP_LIB_DEPS = $(EXTRA_LIB_PATH) @APP_LIB_DEPS@ +GLESv1_CM_LIB_DEPS = $(EXTRA_LIB_PATH) @GLESv1_CM_LIB_DEPS@ +GLESv2_LIB_DEPS = $(EXTRA_LIB_PATH) @GLESv2_LIB_DEPS@ +VG_LIB_DEPS = $(EXTRA_LIB_PATH) @VG_LIB_DEPS@ + +# DRI dependencies +DRI_LIB_DEPS = $(EXTRA_LIB_PATH) @DRI_LIB_DEPS@ +LIBDRM_CFLAGS = @LIBDRM_CFLAGS@ +LIBDRM_LIB = @LIBDRM_LIBS@ +DRI2PROTO_CFLAGS = @DRI2PROTO_CFLAGS@ +EXPAT_INCLUDES = @EXPAT_INCLUDES@ + +# Autoconf directories +prefix = @prefix@ +exec_prefix = @exec_prefix@ +libdir = @libdir@ +includedir = @includedir@ + +# Installation directories (for make install) +INSTALL_DIR = $(prefix) +INSTALL_LIB_DIR = $(libdir) +INSTALL_INC_DIR = $(includedir) + +# DRI installation directories +DRI_DRIVER_INSTALL_DIR = @DRI_DRIVER_INSTALL_DIR@ + +# Where libGL will look for DRI hardware drivers +DRI_DRIVER_SEARCH_DIR = @DRI_DRIVER_SEARCH_DIR@ + +# EGL driver install directory +EGL_DRIVER_INSTALL_DIR = @EGL_DRIVER_INSTALL_DIR@ + +# Xorg driver install directory (for xorg state-tracker) +XORG_DRIVER_INSTALL_DIR = @XORG_DRIVER_INSTALL_DIR@ + +# pkg-config substitutions +GL_PC_REQ_PRIV = @GL_PC_REQ_PRIV@ +GL_PC_LIB_PRIV = @GL_PC_LIB_PRIV@ +GL_PC_CFLAGS = @GL_PC_CFLAGS@ +DRI_PC_REQ_PRIV = @DRI_PC_REQ_PRIV@ +GLU_PC_REQ = @GLU_PC_REQ@ +GLU_PC_REQ_PRIV = @GLU_PC_REQ_PRIV@ +GLU_PC_LIB_PRIV = @GLU_PC_LIB_PRIV@ +GLU_PC_CFLAGS = @GLU_PC_CFLAGS@ +GLUT_PC_REQ_PRIV = @GLUT_PC_REQ_PRIV@ +GLUT_PC_LIB_PRIV = @GLUT_PC_LIB_PRIV@ +GLUT_PC_CFLAGS = @GLUT_PC_CFLAGS@ +GLW_PC_REQ_PRIV = @GLW_PC_REQ_PRIV@ +GLW_PC_LIB_PRIV = @GLW_PC_LIB_PRIV@ +GLW_PC_CFLAGS = @GLW_PC_CFLAGS@ +OSMESA_PC_REQ = @OSMESA_PC_REQ@ +OSMESA_PC_LIB_PRIV = @OSMESA_PC_LIB_PRIV@ +GLESv1_CM_PC_LIB_PRIV = @GLESv1_CM_PC_LIB_PRIV@ +GLESv2_PC_LIB_PRIV = @GLESv2_PC_LIB_PRIV@ +EGL_PC_REQ_PRIV = @GL_PC_REQ_PRIV@ +EGL_PC_LIB_PRIV = @GL_PC_LIB_PRIV@ +EGL_PC_CFLAGS = @GL_PC_CFLAGS@ + +XCB_DRI2_CFLAGS = @XCB_DRI2_CFLAGS@ +XCB_DRI2_LIBS = @XCB_DRI2_LIBS@ +LIBUDEV_CFLAGS = @LIBUDEV_CFLAGS@ +LIBUDEV_LIBS = @LIBUDEV_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 + +HAVE_XF86VIDMODE = @HAVE_XF86VIDMODE@ diff --git a/configs/beos b/configs/beos new file mode 100644 index 0000000..ac8d6fc --- /dev/null +++ b/configs/beos @@ -0,0 +1,103 @@ +# Configuration for BeOS +# Written by Philippe Houdoin + +include $(TOP)/configs/default + +CONFIG_NAME = beos + + +DEFINES = \ + -DBEOS_THREADS + +MACHINE=$(shell uname -m) +ifeq ($(MACHINE), BePC) + CPU = x86 +else + CPU = ppc +endif + +ifeq ($(CPU), x86) + # BeOS x86 settings + + DEFINES += \ + -DGNU_ASSEMBLER \ + -DUSE_X86_ASM \ + -DUSE_MMX_ASM \ + -DUSE_3DNOW_ASM \ + -DUSE_SSE_ASM + + MESA_ASM_SOURCES = $(X86_SOURCES) + GLAPI_ASM_SOURCES = $(X86_API) + + CC = gcc + CXX = g++ + LD = gcc + + CFLAGS = \ + -Wall -Wno-multichar -Wno-ctor-dtor-privacy \ + $(DEFINES) + + CXXFLAGS = $(CFLAGS) + + # Work around aliasing bugs - developers should comment this out + CFLAGS += -fno-strict-aliasing + CXXFLAGS += -fno-strict-aliasing + + LDFLAGS += -Xlinker + + ifdef DEBUG + CFLAGS += -g -O0 + LDFLAGS += -g + DEFINES += -DDEBUG + else + CFLAGS += -O3 + endif + + GLUT_CFLAGS = -fexceptions + +else + # BeOS PPC settings + + CC = mwcc + CXX = $(CC) + LD = mwldppc + + CFLAGS = \ + -w on -requireprotos \ + $(DEFINES) + + CXXFLAGS = $(CFLAGS) + + LDFLAGS += \ + -export pragma \ + -init _init_routine_ \ + -term _term_routine_ \ + -lroot \ + /boot/develop/lib/ppc/glue-noinit.a \ + /boot/develop/lib/ppc/init_term_dyn.o \ + /boot/develop/lib/ppc/start_dyn.o + + ifdef DEBUG + CFLAGS += -g -O0 + CXXFLAGS += -g -O0 + LDFLAGS += -g + else + CFLAGS += -O7 + CXXFLAGS += -O7 + endif + + GLUT_CFLAGS = -fexceptions +endif + +# Directories +SRC_DIRS = gallium mesa glu glut/beos +GLU_DIRS = sgi +DRIVER_DIRS = beos + +# Library/program dependencies +GL_LIB_DEPS = +OSMESA_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) +GLU_LIB_DEPS = +GLUT_LIB_DEPS = -lgame -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) +APP_LIB_DEPS = -lbe -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -l$(GLUT_LIB) + diff --git a/configs/bluegene-osmesa b/configs/bluegene-osmesa new file mode 100644 index 0000000..8851110 --- /dev/null +++ b/configs/bluegene-osmesa @@ -0,0 +1,32 @@ +# Configuration for building only libOSMesa on BlueGene, no Xlib driver +# This doesn't really have a lot of dependencies, so it should be usable +# on other (gcc-based) systems too. +# It uses static linking and disables multithreading. + +include $(TOP)/configs/default + +CONFIG_NAME = bluegene-osmesa + +# Compiler and flags +CC = /bgl/BlueLight/ppcfloor/blrts-gnu/bin/powerpc-bgl-blrts-gnu-gcc +CXX = /bgl/BlueLight/ppcfloor/blrts-gnu/bin/powerpc-bgl-blrts-gnu-g++ +CFLAGS = -O3 -ansi -pedantic -fPIC -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE +CXXFLAGS = -O3 -ansi -pedantic -fPIC -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURC + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +MKLIB_OPTIONS = -static + +OSMESA_LIB_NAME = libOSMesa.a + +# Directories +SRC_DIRS = mesa glu +DRIVER_DIRS = osmesa + + +# Dependencies +OSMESA_LIB_DEPS = -lm +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(OSMESA_LIB) +APP_LIB_DEPS = -lOSMesa -lGLU -lm diff --git a/configs/bluegene-xlc-osmesa b/configs/bluegene-xlc-osmesa new file mode 100644 index 0000000..292199a --- /dev/null +++ b/configs/bluegene-xlc-osmesa @@ -0,0 +1,28 @@ +# Configuration for building only libOSMesa on BlueGene using the IBM xlc compiler +# This doesn't really have a lot of dependencies, so it should be usable +# on similar systems too. +# It uses static linking and disables multithreading. + +include $(TOP)/configs/default + +CONFIG_NAME = bluegene-osmesa + +# Compiler and flags +CC = /opt/ibmcmp/vacpp/bg/8.0/bin/blrts_xlc +CXX = /opt/ibmcmp/vacpp/bg/8.0/bin/blrts_xlC +CFLAGS = -O3 -pedantic -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE +CXXFLAGS = -O3 -pedantic -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE + +MKLIB_OPTIONS = -static + +OSMESA_LIB_NAME = libOSMesa.a + +# Directories +SRC_DIRS = mesa glu +DRIVER_DIRS = osmesa + + +# Dependencies +OSMESA_LIB_DEPS = -lm +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(OSMESA_LIB) +APP_LIB_DEPS = -lOSMesa -lGLU -lm diff --git a/configs/catamount-osmesa-pgi b/configs/catamount-osmesa-pgi new file mode 100644 index 0000000..74fd53a --- /dev/null +++ b/configs/catamount-osmesa-pgi @@ -0,0 +1,31 @@ +# Configuration for building only libOSMesa on Cray Xt3 +# for the compute nodes running Catamount using the +# Portland Group compiler. The Portland Group toolchain has to be +# enabled before using "module switch PrgEnv-gnu PrgEnv-pgi" . +# This doesn't really have a lot of dependencies, so it should be usable +# on other similar systems too. +# It uses static linking and disables multithreading. + +include $(TOP)/configs/default + +CONFIG_NAME = catamount-osmesa-pgi + +# Compiler and flags +CC = cc +CXX = CC +CFLAGS = -target=catamount -fastsse -O3 -Mnontemporal -Mprefetch=distance:8,nta -fPIC -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE +CXXFLAGS = -target=catamount -fastsse -O3 -Mnontemporal -Mprefetch=distance:8,nta -fPIC -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE + +MKLIB_OPTIONS = -static + +OSMESA_LIB_NAME = libOSMesa.a + +# Directories +SRC_DIRS = mesa glu +DRIVER_DIRS = osmesa + + +# Dependencies +OSMESA_LIB_DEPS = -lm +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(OSMESA_LIB) +APP_LIB_DEPS = -lOSMesa -lGLU -lm diff --git a/configs/config.mgw b/configs/config.mgw new file mode 100644 index 0000000..af74fda --- /dev/null +++ b/configs/config.mgw @@ -0,0 +1,42 @@ +# MinGW config include file updated for Mesa 7.0 +# +# Updated : by Heromyth, on 2007-7-21 +# Email : zxpmyth@yahoo.com.cn +# Bugs : 1) All the default settings work fine. But the setting X86=1 can't work. +# The others havn't been tested yet. +# 2) The generated DLLs are *not* compatible with the ones built +# with the other compilers like VC8, especially for GLUT. +# 3) Although more tests are needed, it can be used individually! + +# The generated DLLs by MingW with STDCALL are not totally compatible +# with the ones linked by Microsoft's compilers. +# +# xxx_USING_STDCALL = 1 Compiling MESA with __stdcall. This is default! +# +# xxx_USING_STDCALL = 0 Compiling MESA without __stdcall. I like this:) +# + +# In fact, GL_USING_STDCALL and GLUT_USING_STDCALL can be +# different. For example: +# +# GL_USING_STDCALL = 0 +# GLUT_USING_STDCALL = 1 +# +# Suggested setting: +# +# ALL_USING_STDCALL = 1 +# +# That's default! +# + + +ALL_USING_STDCALL = 1 + + +ifeq ($(ALL_USING_STDCALL),1) + GL_USING_STDCALL = 1 + GLUT_USING_STDCALL = 1 +else + GL_USING_STDCALL = 0 + GLUT_USING_STDCALL = 0 +endif diff --git a/configs/darwin b/configs/darwin new file mode 100644 index 0000000..9906107 --- /dev/null +++ b/configs/darwin @@ -0,0 +1,59 @@ +# Configuration for Darwin / MacOS X, making dynamic libs + +include $(TOP)/configs/default + +CONFIG_NAME = darwin + +INSTALL_DIR = /usr/X11 + +X11_DIR = $(INSTALL_DIR) + +# Compiler and flags +CC = gcc +CXX = g++ +PIC_FLAGS = -fPIC +DEFINES = -D_DARWIN_C_SOURCE -DPTHREADS -D_GNU_SOURCE \ + -DGLX_ALIAS_UNSUPPORTED \ + -DGLX_DIRECT_RENDERING -DGLX_USE_APPLEGL + +# -DGLX_INDIRECT_RENDERING \ + +# -D_GNU_SOURCE - for src/mesa/main ... +# -DGLX_DIRECT_RENDERING - pulls in libdrm stuff in glx +# -DGLX_USE_APPLEGL - supposed to be used with GLX_DIRECT_RENDERING to use AGL rather than DRM, but doesn't compile +# -DIN_DRI_DRIVER + +ARCH_FLAGS += $(RC_CFLAGS) + +CFLAGS = -ggdb3 -Os -Wall -Wmissing-prototypes -std=c99 -ffast-math -fno-strict-aliasing \ + -I$(INSTALL_DIR)/include -I$(X11_DIR)/include $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(ASM_FLAGS) $(DEFINES) +CXXFLAGS = -ggdb3 -Os -Wall -fno-strict-aliasing \ + -I$(INSTALL_DIR)/include -I$(X11_DIR)/include $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(ASM_FLAGS) $(DEFINES) + +# Library names (actual file names) +GL_LIB_NAME = libGL.dylib +GLU_LIB_NAME = libGLU.dylib +GLUT_LIB_NAME = libglut.dylib +GLW_LIB_NAME = libGLw.dylib +OSMESA_LIB_NAME = libOSMesa.dylib + +# globs used to install the lib and all symlinks +GL_LIB_GLOB = libGL.*dylib +GLU_LIB_GLOB = libGLU.*dylib +GLUT_LIB_GLOB = libglut.*dylib +GLW_LIB_GLOB = libGLw.*dylib +OSMESA_LIB_GLOB = libOSMesa.*dylib + +GL_LIB_DEPS = -L$(INSTALL_DIR)/$(LIB_DIR) -L$(X11_DIR)/$(LIB_DIR) -lX11 -lXext -lm -lpthread +OSMESA_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -L$(INSTALL_DIR)/$(LIB_DIR) -L$(X11_DIR)/$(LIB_DIR) -lX11 -lXmu -lXi -lXext +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L$(INSTALL_DIR)/$(LIB_DIR) -L$(X11_DIR)/$(LIB_DIR) -lX11 -lXt +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -L$(INSTALL_DIR)/$(LIB_DIR) -L$(X11_DIR)/$(LIB_DIR) -lX11 -lXmu -lXt -lXi -lm + +# omit glw lib for now: +SRC_DIRS = glsl mapi/glapi mapi/vgapi glx/apple mesa gallium glu glut/glx +GLU_DIRS = sgi +DRIVER_DIRS = osmesa +#DRIVER_DIRS = dri +DRI_DIRS = swrast diff --git a/configs/darwin-fat-32bit b/configs/darwin-fat-32bit new file mode 100644 index 0000000..56bc6a3 --- /dev/null +++ b/configs/darwin-fat-32bit @@ -0,0 +1,7 @@ +# Configuration for Darwin / MacOS X, making 32bit fat dynamic libs + +RC_CFLAGS=-arch ppc -arch i386 + +include $(TOP)/configs/darwin + +CONFIG_NAME = darwin-fat-32bit diff --git a/configs/darwin-fat-all b/configs/darwin-fat-all new file mode 100644 index 0000000..b8668dc --- /dev/null +++ b/configs/darwin-fat-all @@ -0,0 +1,7 @@ +# Configuration for Darwin / MacOS X, making 32bit and 64bit fat dynamic libs + +RC_CFLAGS=-arch ppc -arch i386 -arch ppc64 -arch x86_64 + +include $(TOP)/configs/darwin + +CONFIG_NAME = darwin-fat-all diff --git a/configs/default b/configs/default new file mode 100644 index 0000000..2301a68 --- /dev/null +++ b/configs/default @@ -0,0 +1,176 @@ +# Default/template configuration + +# This is included by other config files which may override some +# of these variables. +# Think of this as a base class from which configs are derived. + + +CONFIG_NAME = default + +# Version info +MESA_MAJOR=7 +MESA_MINOR=10 +MESA_TINY=0 +MESA_VERSION = $(MESA_MAJOR).$(MESA_MINOR).$(MESA_TINY) + +# external projects. This should be useless now that we use libdrm. +DRM_SOURCE_PATH=$(TOP)/../drm + +# Compiler and flags +CC = cc +CXX = CC +HOST_CC = $(CC) +CFLAGS = -O +CXXFLAGS = -O +LDFLAGS = +HOST_CFLAGS = $(CFLAGS) +GLU_CFLAGS = + +# Compiler for building demos/tests/etc +APP_CC = $(CC) +APP_CXX = $(CXX) + +# Misc tools and flags +SHELL = /bin/sh +MKLIB = $(SHELL) $(TOP)/bin/mklib +MKLIB_OPTIONS = +MKDEP = makedepend +MKDEP_OPTIONS = -fdepend +MAKE = make + +# Use MINSTALL for installing libraries, INSTALL for everything else +MINSTALL = $(SHELL) $(TOP)/bin/minstall +INSTALL = $(MINSTALL) + +# Tools for regenerating glapi (generally only needed by the developers) +PYTHON2 = python +PYTHON_FLAGS = -t -O -O +INDENT = indent +INDENT_FLAGS = -i4 -nut -br -brs -npcs -ce -T GLubyte -T GLbyte -T Bool + +# Library names (base name) +GL_LIB = GL +GLU_LIB = GLU +GLUT_LIB = glut +GLW_LIB = GLw +OSMESA_LIB = OSMesa +EGL_LIB = EGL +GLESv1_CM_LIB = GLESv1_CM +GLESv2_LIB = GLESv2 +VG_LIB = OpenVG + + +# Library names (actual file names) +GL_LIB_NAME = lib$(GL_LIB).so +GLU_LIB_NAME = lib$(GLU_LIB).so +GLUT_LIB_NAME = lib$(GLUT_LIB).so +GLW_LIB_NAME = lib$(GLW_LIB).so +OSMESA_LIB_NAME = lib$(OSMESA_LIB).so +EGL_LIB_NAME = lib$(EGL_LIB).so +GLESv1_CM_LIB_NAME = lib$(GLESv1_CM_LIB).so +GLESv2_LIB_NAME = lib$(GLESv2_LIB).so +VG_LIB_NAME = lib$(VG_LIB).so + +# globs used to install the lib and all symlinks +GL_LIB_GLOB = $(GL_LIB_NAME)* +GLU_LIB_GLOB = $(GLU_LIB_NAME)* +GLUT_LIB_GLOB = $(GLUT_LIB_NAME)* +GLW_LIB_GLOB = $(GLW_LIB_NAME)* +OSMESA_LIB_GLOB = $(OSMESA_LIB_NAME)* +EGL_LIB_GLOB = $(EGL_LIB_NAME)* +GLESv1_CM_LIB_GLOB = $(GLESv1_CM_LIB_NAME)* +GLESv2_LIB_GLOB = $(GLESv2_LIB_NAME)* +VG_LIB_GLOB = $(VG_LIB_NAME)* + +# Optional assembly language optimization files for libGL +MESA_ASM_SOURCES = + +# GLw widget sources (Append "GLwMDrawA.c" here and add -lXm to GLW_LIB_DEPS in +# order to build the Motif widget too) +GLW_SOURCES = GLwDrawA.c +MOTIF_CFLAGS = -I/usr/include/Motif1.2 + + +# Directories to build +LIB_DIR = lib +SRC_DIRS = glsl mapi/glapi mapi/vgapi mesa \ + gallium egl gallium/winsys gallium/targets glu glut/glx glw +GLU_DIRS = sgi +DRIVER_DIRS = x11 osmesa + +# EGL drivers to build +EGL_DRIVERS_DIRS = glx + +# Gallium directories and +GALLIUM_DIRS = auxiliary drivers state_trackers +GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a +GALLIUM_DRIVERS_DIRS = softpipe trace rbug identity galahad i915 i965 svga r300 nvfx nv50 failover +GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a) +GALLIUM_WINSYS_DIRS = sw sw/xlib +GALLIUM_TARGET_DIRS = libgl-xlib +GALLIUM_STATE_TRACKERS_DIRS = glx vega + +# native platforms EGL should support +EGL_PLATFORMS = x11 +EGL_CLIENT_APIS = $(GL_LIB) + +# Library dependencies +#EXTRA_LIB_PATH ?= +GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lm -lpthread +EGL_LIB_DEPS = $(EXTRA_LIB_PATH) -ldl -lpthread +OSMESA_LIB_DEPS = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) +GLU_LIB_DEPS = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm +GLUT_LIB_DEPS = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXmu -lXi -lm +GLW_LIB_DEPS = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lXt -lX11 +APP_LIB_DEPS = $(EXTRA_LIB_PATH) -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm +GLESv1_CM_LIB_DEPS = $(EXTRA_LIB_PATH) -lpthread +GLESv2_LIB_DEPS = $(EXTRA_LIB_PATH) -lpthread +VG_LIB_DEPS = $(EXTRA_LIB_PATH) -lpthread + +# Program dependencies - specific GL/glut libraries added in Makefiles +APP_LIB_DEPS = -lm +X11_LIBS = -lX11 + +DLOPEN_LIBS = -ldl + +# Installation directories (for make install) +INSTALL_DIR = /usr/local +INSTALL_LIB_DIR = $(INSTALL_DIR)/$(LIB_DIR) +INSTALL_INC_DIR = $(INSTALL_DIR)/include +DRI_DRIVER_INSTALL_DIR = $(INSTALL_LIB_DIR)/dri + +# Where libGL will look for DRI hardware drivers +DRI_DRIVER_SEARCH_DIR = $(DRI_DRIVER_INSTALL_DIR) + +# EGL driver install directory +EGL_DRIVER_INSTALL_DIR = $(INSTALL_LIB_DIR)/egl + +# Xorg driver install directory (for xorg state-tracker) +XORG_DRIVER_INSTALL_DIR = $(INSTALL_LIB_DIR)/xorg/modules/drivers + +# pkg-config substitutions +GL_PC_REQ_PRIV = +GL_PC_LIB_PRIV = +GL_PC_CFLAGS = +DRI_PC_REQ_PRIV = +GLU_PC_REQ = gl +GLU_PC_REQ_PRIV = +GLU_PC_LIB_PRIV = +GLU_PC_CFLAGS = +GLUT_PC_REQ_PRIV = +GLUT_PC_LIB_PRIV = +GLUT_PC_CFLAGS = +GLW_PC_REQ_PRIV = +GLW_PC_LIB_PRIV = +GLW_PC_CFLAGS = +OSMESA_PC_REQ = +OSMESA_PC_LIB_PRIV = +GLESv1_CM_PC_REQ_PRIV = +GLESv1_CM_PC_LIB_PRIV = +GLESv1_CM_PC_CFLAGS = +GLESv2_PC_REQ_PRIV = +GLESv2_PC_LIB_PRIV = +GLESv2_PC_CFLAGS = +VG_PC_REQ_PRIV = +VG_PC_LIB_PRIV = +VG_PC_CFLAGS = diff --git a/configs/freebsd b/configs/freebsd new file mode 100644 index 0000000..976ddd1 --- /dev/null +++ b/configs/freebsd @@ -0,0 +1,31 @@ +# Configuration for FreeBSD + +include $(TOP)/configs/default + +CONFIG_NAME = FreeBSD + +# Compiler and flags +CC = cc +CXX = c++ +MAKE = gmake + +OPT_FLAGS = -O2 +PIC_FLAGS = -fPIC + +DEFINES = -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE -DUSE_XSHM \ + -DHZ=100 + +X11_INCLUDES = -I/usr/local/include + +CFLAGS += $(WARN_FLAGS) $(OPT_FLAGS) $(PIC_FLAGS) $(DEFINES) $(X11_INCLUDES) -ffast-math -pedantic + +CXXFLAGS += $(WARN_FLAGS) $(OPT_FLAGS) $(PIC_FLAGS) $(DEFINES) $(X11_INCLUDES) + +GLUT_CFLAGS = -fexceptions + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +EXTRA_LIB_PATH = -L/usr/local/lib +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) $(EXTRA_LIB_PATH) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lXext -lXmu -lXi -lX11 -lm diff --git a/configs/freebsd-dri b/configs/freebsd-dri new file mode 100644 index 0000000..a4aa82e --- /dev/null +++ b/configs/freebsd-dri @@ -0,0 +1,51 @@ +# -*-makefile-*- +# Configuration for freebsd-dri: FreeBSD DRI hardware drivers + +include $(TOP)/configs/freebsd + +CONFIG_NAME = freebsd-dri + +# Compiler and flags +CC = gcc +CXX = g++ +WARN_FLAGS = -Wall +OPT_FLAGS = -O -g + +EXPAT_INCLUDES = -I/usr/local/include +X11_INCLUDES = -I/usr/local/include +DEFINES = -DPTHREADS -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER \ + -DGLX_DIRECT_RENDERING -DGLX_INDIRECT_RENDERING \ + -DHAVE_ALIAS + +CFLAGS = $(WARN_FLAGS) $(OPT_FLAGS) $(PIC_FLAGS) -Wmissing-prototypes -std=c99 -Wundef -ffast-math \ + $(ASM_FLAGS) $(X11_INCLUDES) $(DEFINES) + +CXXFLAGS = $(WARN_FLAGS) $(OPT_FLAGS) $(PIC_FLAGS) $(DEFINES) -Wall -ansi -pedantic $(ASM_FLAGS) $(X11_INCLUDES) + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +ASM_SOURCES = +MESA_ASM_SOURCES = + +# Library/program dependencies +LIBDRM_CFLAGS = `pkg-config --cflags libdrm` +LIBDRM_LIB = `pkg-config --libs libdrm` +DRI_LIB_DEPS = -L/usr/local/lib -lm -pthread -lexpat $(LIBDRM_LIB) +GL_LIB_DEPS = -L/usr/local/lib -lX11 -lXext -lXxf86vm -lXdamage -lXfixes \ + -lm -pthread $(LIBDRM_LIB) + +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -L/usr/local/lib -lGLU -lGL -lX11 -lXmu -lXt -lXi -lm +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -L/usr/local/lib -lGL -lXt -lX11 + + +# Directories +SRC_DIRS = glx gallium mesa glu glut/glx glw +DRIVER_DIRS = dri + +DRM_SOURCE_PATH=$(TOP)/../drm + +DRI_DIRS = i810 i915 i965 mach64 mga r128 r200 r300 radeon tdfx \ + unichrome savage sis + diff --git a/configs/freebsd-dri-amd64 b/configs/freebsd-dri-amd64 new file mode 100644 index 0000000..bb6c361 --- /dev/null +++ b/configs/freebsd-dri-amd64 @@ -0,0 +1,10 @@ +# -*-makefile-*- +# Configuration for freebsd-dri-amd64: FreeBSD DRI hardware drivers + +include $(TOP)/configs/freebsd-dri + +CONFIG_NAME = freebsd-dri-x86-64 + +ASM_FLAGS = -DUSE_X86_64_ASM +MESA_ASM_SOURCES = $(X86-64_SOURCES) +GLAPI_ASM_SOURCES = $(X86-64_API) diff --git a/configs/freebsd-dri-x86 b/configs/freebsd-dri-x86 new file mode 100644 index 0000000..9475437 --- /dev/null +++ b/configs/freebsd-dri-x86 @@ -0,0 +1,13 @@ +# -*-makefile-*- +# Configuration for freebsd-dri: FreeBSD DRI hardware drivers + +include $(TOP)/configs/freebsd-dri + +CONFIG_NAME = freebsd-dri-x86 + +# Unnecessary on x86, generally. +PIC_FLAGS = + +ASM_FLAGS = -DUSE_X86_ASM -DUSE_MMX_ASM -DUSE_3DNOW_ASM -DUSE_SSE_ASM +MESA_ASM_SOURCES = $(X86_SOURCES) +GLAPI_ASM_SOURCES = $(X86_API) diff --git a/configs/hpux10 b/configs/hpux10 new file mode 100644 index 0000000..9ec08c0 --- /dev/null +++ b/configs/hpux10 @@ -0,0 +1,14 @@ +# Configuration for HPUX v10, shared libs + +include $(TOP)/configs/default + +CONFIG_NAME = hpux10 + +# Compiler and flags +CC = cc +CXX = aCC + +CFLAGS = -O +DAportable +z -Ae -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DUSE_XSHM +CXXFLAGS = -O +DAportable +Z -Ae -D_HPUX_SOURCE + +APP_LIB_DEPS = -$(TOP)/$(LIB_DIR) -L/usr/lib/X11R6 -L/usr/contrib/X11R6/lib -lXext -lXmu -lXi -lX11 -lm diff --git a/configs/hpux10-gcc b/configs/hpux10-gcc new file mode 100644 index 0000000..be396f8 --- /dev/null +++ b/configs/hpux10-gcc @@ -0,0 +1,20 @@ +# Configuration for HPUX v10, with gcc + +include $(TOP)/configs/default + +CONFIG_NAME = hpux10-gcc + +# Compiler and flags +CC = gcc +CXX = g++ + +CFLAGS = -ansi -O3 -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DUSE_XSHM +CXXFLAGS = -ansi -O3 -D_HPUX_SOURCE +GLUT_CFLAGS = -fexceptions + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -L/usr/lib/X11R6 -L/usr/contrib/X11R6/lib -lXext -lXmu -lXi -lX11 -lm + diff --git a/configs/hpux10-static b/configs/hpux10-static new file mode 100644 index 0000000..6101a4e --- /dev/null +++ b/configs/hpux10-static @@ -0,0 +1,30 @@ +# Configuration for HPUX v10, static libs + +include $(TOP)/configs/default + +CONFIG_NAME = hpux10-static + +# Compiler and flags +CC = cc +CXX = aCC + +CFLAGS = -O +DAportable +z -Ae -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DUSE_XSHM +CXXFLAGS = -O +DAportable +Z -Ae -D_HPUX_SOURCE + +MKLIB_OPTIONS = -static + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +# Library/program dependencies (static libs don't have dependencies) +GL_LIB_DEPS = +OSMESA_LIB_DEPS = +GLU_LIB_DEPS = +GLUT_LIB_DEPS = +GLW_LIB_DEPS = +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/X11R6/lib -lX11 -lXext -lXmu -lXt -lXi -lpthread -lm -lstdc++ +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/lib/X11R6 -L/usr/contrib/X11R6/lib -lXext -lXmu -lXi -lX11 -lm -lstdc++ diff --git a/configs/hpux11-32 b/configs/hpux11-32 new file mode 100644 index 0000000..035ef79 --- /dev/null +++ b/configs/hpux11-32 @@ -0,0 +1,30 @@ +# Configuration for HPUX v11 + +include $(TOP)/configs/default + +CONFIG_NAME = hpux11-32 + +# Compiler and flags +CC = cc +CXX = aCC + +CFLAGS = +z -Ae -O +Onolimit -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DUSE_XSHM -DPTHREADS + +CXXFLAGS = +z -Ae -O +Onolimit -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DPTHREADS + +MKLIB_OPTIONS = + + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +# Library/program dependencies +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) +GL_LIB_DEPS = -L/usr/lib/X11R6/ -L/usr/contrib/X11R6/lib/ -lXext -lXt -lXi -lX11 -lm -lpthread +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm -lCsup -lcl +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) $(GL_LIB_DEPS) +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(GL_LIB_DEPS) diff --git a/configs/hpux11-32-static b/configs/hpux11-32-static new file mode 100644 index 0000000..b8e8436 --- /dev/null +++ b/configs/hpux11-32-static @@ -0,0 +1,27 @@ +# Configuration for HPUX v11, static libs + +include $(TOP)/configs/default + +CONFIG_NAME = hpux11-32-static + +# Compiler and flags +CC = cc +CXX = aCC + +CFLAGS = -O +DA2.0 -Ae -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DUSE_XSHM -DPTHREADS + +CXXFLAGS = -O +DA2.0 -Ae -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DPTHREADS + +MKLIB_OPTIONS = -static + + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +# Library/program dependencies +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/lib/X11R6/ -L/usr/contrib/X11R6/lib/ -lXext -lXmu -lXt -lXi -lX11 -lm -lpthread -lCsup -lcl + diff --git a/configs/hpux11-32-static-nothreads b/configs/hpux11-32-static-nothreads new file mode 100644 index 0000000..cba166a --- /dev/null +++ b/configs/hpux11-32-static-nothreads @@ -0,0 +1,26 @@ +# Configuration for HPUX v11, static libs + +include $(TOP)/configs/default + +CONFIG_NAME = hpux11-32-static + +# Compiler and flags +CC = cc +CXX = aCC + +CFLAGS = -O +DA2.0 -Ae -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DUSE_XSHM + +CXXFLAGS = -O +DA2.0 -Ae -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include + +MKLIB_OPTIONS = -static + + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +# Library/program dependencies +APP_LIB_DEPS = -L/usr/lib/X11R6 -L/usr/contrib/X11R6/lib -lXext -lXmu -lXi -lX11 -lm diff --git a/configs/hpux11-64 b/configs/hpux11-64 new file mode 100644 index 0000000..3833c07 --- /dev/null +++ b/configs/hpux11-64 @@ -0,0 +1,31 @@ +# Configuration for HPUX v11, 64-bit + +include $(TOP)/configs/default + +CONFIG_NAME = hpux11-64 + +# Compiler and flags +CC = cc +CXX = aCC + +CFLAGS = +z -Ae +DD64 -O +Onolimit -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DUSE_XSHM -DPTHREADS + +CXXFLAGS = +z -Ae +DD64 -O +Onolimit -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DPTHREADS + +MKLIB_OPTIONS = + +LIB_DIR = lib64 + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +# Library/program dependencies +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) +GL_LIB_DEPS = -L/usr/lib/X11R6/pa20_64 -L/usr/contrib/X11R6/lib/pa20_64 -lXext -lXmu -lXt -lXi -lX11 -lm -lpthread +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm -lCsup -lcl +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) $(GL_LIB_DEPS) +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(GL_LIB_DEPS) diff --git a/configs/hpux11-64-static b/configs/hpux11-64-static new file mode 100644 index 0000000..32944f9 --- /dev/null +++ b/configs/hpux11-64-static @@ -0,0 +1,27 @@ +# Configuration for HPUX v11, 64-bit, static libs + +include $(TOP)/configs/default + +CONFIG_NAME = hpux11-64-static + +# Compiler and flags +CC = cc +CXX = aCC + +CFLAGS = -O +DA2.0W -Ae -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DUSE_XSHM -DPTHREADS + +CXXFLAGS = -O +DA2.0W -Ae -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DPTHREADS + +MKLIB_OPTIONS = -static + +LIB_DIR = lib64 + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +# Library/program dependencies +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/lib/X11R6/pa20_64 -L/usr/contrib/X11R6/lib/pa20_64 -lXext -lXmu -lXt -lXi -lX11 -lm -lpthread -lCsup -lcl diff --git a/configs/hpux11-ia64 b/configs/hpux11-ia64 new file mode 100644 index 0000000..b94560b --- /dev/null +++ b/configs/hpux11-ia64 @@ -0,0 +1,30 @@ +# Configuration for HPUX IA64 v11, 64-bit + +include $(TOP)/configs/default + +CONFIG_NAME = hpux11-ia64 + +# Compiler and flags +CC = cc +CXX = aCC + +CFLAGS = +z -Ae +DD64 -O +DSmckinley -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DUSE_XSHM -DPTHREADS + +CXXFLAGS = +z -Ae +DD64 -O +DSmckinley -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DPTHREADS + +MKLIB_OPTIONS = + +LIB_DIR = lib64 + +# Library names (actual file names) +GL_LIB_NAME = libGL.so +GLU_LIB_NAME = libGLU.so +GLUT_LIB_NAME = libglut.so +GLW_LIB_NAME = libGLw.so +OSMESA_LIB_NAME = libOSMesa.so + +# Library/program dependencies +GL_LIB_DEPS = -L/usr/lib/X11R6/ -L/usr/contrib/X11R6/lib/ -lXext -lXmu -lXt -lXi -lX11 -lm -lpthread +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm -lCsup -lcl +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) $(GL_LIB_DEPS) +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(GL_LIB_DEPS) diff --git a/configs/hpux11-ia64-static b/configs/hpux11-ia64-static new file mode 100644 index 0000000..e094c9f --- /dev/null +++ b/configs/hpux11-ia64-static @@ -0,0 +1,27 @@ +# Configuration for HPUX v11, 64-bit, static libs + +include $(TOP)/configs/default + +CONFIG_NAME = hpux11-ia64-static + +# Compiler and flags +CC = cc +CXX = aCC + +CFLAGS = -O +DD64 -Ae -D_HPUX_SOURCE +DSmckinley -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DUSE_XSHM -DPTHREADS + +CXXFLAGS = -O +DD64 -Ae -D_HPUX_SOURCE +DSmckinley -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DPTHREADS + +MKLIB_OPTIONS = -static + +LIB_DIR = lib64 + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +# Library/program dependencies +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/lib/X11R6 -L/usr/contrib/X11R6/lib -lXext -lXmu -lXi -lXt -lX11 -lpthread -lm -lCsup -lcl diff --git a/configs/hpux9 b/configs/hpux9 new file mode 100644 index 0000000..d0105e5 --- /dev/null +++ b/configs/hpux9 @@ -0,0 +1,16 @@ +# Configuration for HPUX v9, shared libs + +include $(TOP)/configs/default + +CONFIG_NAME = hpux9 + +# Compiler and flags +CC = cc +# XXX fix this +CXX = c++ + +CFLAGS = +z -O +Olibcalls +ESlit -Ae +Onolimit -D_HPUX_SOURCE -I/usr/include/X11R5 -DUSE_XSHM +CXXFLAGS = +z -O +Olibcalls +ESlit -Ae +Onolimit -D_HPUX_SOURCE -I/usr/include/X11R5 + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -L/usr/lib/X11R5 -s -Wl,+s,-B,nonfatal,-B,immediate -lXext -lXmu -lXi -lX11 -lm + diff --git a/configs/hpux9-gcc b/configs/hpux9-gcc new file mode 100644 index 0000000..df30420 --- /dev/null +++ b/configs/hpux9-gcc @@ -0,0 +1,14 @@ +# Configuration for HPUX v10, shared libs + +include $(TOP)/configs/default + +CONFIG_NAME = hpux9-gcc + +# Compiler and flags +CC = cc +CXX = aCC + +CFLAGS = -O +DAportable +z -Ae -D_HPUX_SOURCE -I/usr/include/X11R6 -I/usr/contrib/X11R6/include -DUSE_XSHM +CXXFLAGS = -O +DAportable +Z -Ae -D_HPUX_SOURCE + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -L/usr/lib/X11R6 -L/usr/contrib/X11R6/lib -lXext -lXmu -lXi -lX11 -lm diff --git a/configs/irix6-64 b/configs/irix6-64 new file mode 100644 index 0000000..aae6d78 --- /dev/null +++ b/configs/irix6-64 @@ -0,0 +1,17 @@ +# Configuration for IRIX 6.x, make n64 DSOs + +include $(TOP)/configs/default + +CONFIG_NAME = irix6-64 + +# Compiler and flags +CC = cc +CXX = CC +CFLAGS = -64 -O3 -ansi -woff 1068,1069,1174,1185,1209,1474,1552 -DUSE_XSHM -DPTHREADS +CXXFLAGS = -64 -O3 -ansi -woff 1174 -DPTHREADS + +GLW_SOURCES = GLwDrawA.c GLwMDrawA.c + +LIB_DIR = lib64 + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -64 -rpath $(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXmu -lXi -lpthread -lm diff --git a/configs/irix6-64-static b/configs/irix6-64-static new file mode 100644 index 0000000..ea9dabc --- /dev/null +++ b/configs/irix6-64-static @@ -0,0 +1,26 @@ +# Configuration for IRIX 6.x, make n64 static libs + +include $(TOP)/configs/default + +CONFIG_NAME = irix6-64-static + +# Compiler and flags +CC = cc +CXX = CC +CFLAGS = -64 -O3 -ansi -woff 1068,1069,1174,1185,1209,1474,1552 -DUSE_XSHM -DPTHREADS +CXXFLAGS = -64 -O3 -ansi -woff 1174 -DPTHREADS +MKLIB_OPTIONS = -static + +GLW_SOURCES = GLwDrawA.c GLwMDrawA.c + +LIB_DIR = lib64 + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -64 -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXext -lXmu -lXi -lpthread -lm -lC + +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + + diff --git a/configs/irix6-n32 b/configs/irix6-n32 new file mode 100644 index 0000000..8a78173 --- /dev/null +++ b/configs/irix6-n32 @@ -0,0 +1,17 @@ +# Configuration for IRIX 6.x, make n32 DSOs + +include $(TOP)/configs/default + +CONFIG_NAME = irix6-n32 + +# Compiler and flags +CC = cc +CXX = CC +CFLAGS = -n32 -mips3 -O3 -ansi -woff 1174,1521,1552 -DUSE_XSHM -DPTHREADS +CXXFLAGS = -n32 -mips3 -O3 -ansi -woff 1174,1552 -DPTHREADS + +GLW_SOURCES = GLwDrawA.c GLwMDrawA.c + +LIB_DIR = lib32 + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -n32 -rpath $(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXmu -lXi -lfpe -lpthread -lm diff --git a/configs/irix6-n32-static b/configs/irix6-n32-static new file mode 100644 index 0000000..fe47ccd --- /dev/null +++ b/configs/irix6-n32-static @@ -0,0 +1,25 @@ +# Configuration for IRIX 6.x, make n32 static libs + +include $(TOP)/configs/default + +CONFIG_NAME = irix6-n32-static + +# Compiler and flags +CC = cc +CXX = CC +CFLAGS = -n32 -mips2 -O2 -ansi -woff 1521,1552 -DUSE_XSHM -DPTHREADS +CXXFLAGS = -n32 -mips2 -O2 -ansi -woff 3262,3666 -DPTHREADS +MKLIB_OPTIONS = -static + +GLW_SOURCES = GLwDrawA.c GLwMDrawA.c + +LIB_DIR = lib32 + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -n32 -glut -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXext -lXmu -lXi -lpthread -lm -lC + +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + diff --git a/configs/irix6-o32 b/configs/irix6-o32 new file mode 100644 index 0000000..1e4c8c5 --- /dev/null +++ b/configs/irix6-o32 @@ -0,0 +1,18 @@ +# Configuration for IRIX 6.x, make o32 DSOs + +include $(TOP)/configs/default + +CONFIG_NAME = irix6-o32 + +# Compiler and flags +CC = cc +CXX = CC +CFLAGS = -32 -mips2 -O2 -ansi -woff 1521,1552 -DUSE_XSHM +CXXFLAGS = -32 -mips2 -O2 -ansi -woff 3262,3666 + +GLW_SOURCES = GLwDrawA.c GLwMDrawA.c + +LIB_DIR = lib32 + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -32 -rpath $(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXext -lXmu -lXi -lm + diff --git a/configs/irix6-o32-static b/configs/irix6-o32-static new file mode 100644 index 0000000..2d265df --- /dev/null +++ b/configs/irix6-o32-static @@ -0,0 +1,25 @@ +# Configuration for IRIX 6.x, make o32 static libs + +include $(TOP)/configs/default + +CONFIG_NAME = irix6-o32-static + +# Compiler and flags +CC = cc +CXX = CC +CFLAGS = -32 -mips2 -O2 -ansi -woff 1521,1552 -DUSE_XSHM +CXXFLAGS = -32 -mips2 -O2 -ansi -woff 3262,3666 +MKLIB_OPTIONS = -static + +GLW_SOURCES = GLwDrawA.c GLwMDrawA.c + +LIB_DIR = lib32 + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -32 -glut -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXext -lXmu -lXi -lm -lC + +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + diff --git a/configs/linux b/configs/linux new file mode 100644 index 0000000..c60f0d8 --- /dev/null +++ b/configs/linux @@ -0,0 +1,38 @@ +# Configuration for generic Linux + +include $(TOP)/configs/default + +CONFIG_NAME = linux + +# Compiler and flags +CC = gcc +CXX = g++ + +OPT_FLAGS = -O3 -g +PIC_FLAGS = -fPIC + +# Add '-DGLX_USE_TLS' to ARCH_FLAGS to enable TLS support. Add -m32 +# to build properly on 64-bit platforms. + +ARCH_FLAGS ?= + +DEFINES = -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE \ + -D_BSD_SOURCE -D_GNU_SOURCE \ + -DPTHREADS -DUSE_XSHM -DHAVE_POSIX_MEMALIGN + +X11_INCLUDES = -I/usr/X11R6/include + +CFLAGS = -Wall -Wmissing-prototypes -Wdeclaration-after-statement \ + -Wpointer-arith $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) \ + $(DEFINES) $(ASM_FLAGS) $(X11_INCLUDES) -std=c99 -ffast-math + +CXXFLAGS = -Wall -Wpointer-arith $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) \ + $(DEFINES) $(X11_INCLUDES) + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +GLUT_CFLAGS = -fexceptions + +EXTRA_LIB_PATH = -L/usr/X11R6/lib diff --git a/configs/linux-alpha b/configs/linux-alpha new file mode 100644 index 0000000..65bf0c2 --- /dev/null +++ b/configs/linux-alpha @@ -0,0 +1,22 @@ +# Configuration for Linux on Alpha + +include $(TOP)/configs/default + +CONFIG_NAME = linux-alpha + +# Compiler and flags +CC = gcc +CXX = g++ +CFLAGS = -O3 -mcpu=ev5 -ansi -mieee -pedantic -fPIC -D_XOPEN_SOURCE -DUSE_XSHM +CXXFLAGS = -O3 -mcpu=ev5 -ansi -mieee -pedantic -fPIC -D_XOPEN_SOURCE +GLUT_CFLAGS = -fexceptions + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +GL_LIB_DEPS = -L/usr/X11R6/lib -lX11 -lXext -lm -lpthread +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/X11R6/lib -lX11 -lXmu -lXt -lXi -lm +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L/usr/X11R6/lib -lXt -lX11 +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm + diff --git a/configs/linux-alpha-static b/configs/linux-alpha-static new file mode 100644 index 0000000..53808d7 --- /dev/null +++ b/configs/linux-alpha-static @@ -0,0 +1,31 @@ +# Configuration for Linux on Alpha, static libs + +include $(TOP)/configs/default + +CONFIG_NAME = linux-alpha-static + +# Compiler and flags +CC = gcc +CXX = g++ +CFLAGS = -O3 -mcpu=ev5 -ansi -mieee -pedantic -D_XOPEN_SOURCE -DUSE_XSHM +CXXFLAGS = -O3 -mcpu=ev5 -ansi -mieee -pedantic -D_XOPEN_SOURCE +GLUT_CFLAGS = -fexceptions +MKLIB_OPTIONS = -static +PIC_FLAGS = + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + + +GL_LIB_DEPS = -L/usr/X11R6/lib -lX11 -lXext -lm -lpthread +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/X11R6/lib -lX11 -lXmu -lXt -lXi -lm +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L/usr/X11R6/lib -lXt -lX11 +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm -L/usr/X11R6/lib -lX11 -lm diff --git a/configs/linux-cell b/configs/linux-cell new file mode 100644 index 0000000..606a11a --- /dev/null +++ b/configs/linux-cell @@ -0,0 +1,72 @@ +# linux-cell (non-debug build) + +include $(TOP)/configs/linux + +CONFIG_NAME = linux-cell + + +# Omiting other gallium drivers: +GALLIUM_DRIVERS_DIRS = cell softpipe trace rbug identity + + +# Compiler and flags +CC = ppu32-gcc +CXX = ppu32-g++ +HOST_CC = gcc +APP_CC = gcc +APP_CXX = g++ + +OPT_FLAGS = -O3 + +# Cell SDK location +## For SDK 2.1: (plus, remove -DSPU_MAIN_PARAM_LONG_LONG below) +#SDK = /opt/ibm/cell-sdk/prototype/sysroot/usr +## For SDK 3.0: +SDK = /opt/cell/sdk/usr + + + +COMMON_C_CPP_FLAGS = $(OPT_FLAGS) -Wall -Winline \ + -fPIC -m32 -mabi=altivec -maltivec \ + -I. -I$(SDK)/include \ + -DGALLIUM_CELL $(DEFINES) + +CFLAGS = $(COMMON_C_CPP_FLAGS) -Wmissing-prototypes -std=c99 + +CXXFLAGS = $(COMMON_C_CPP_FLAGS) + + +# Omitting glw here: +SRC_DIRS = glsl mapi/glapi mapi/vgapi mesa \ + gallium gallium/winsys gallium/targets glu glut/glx + +# Build no traditional Mesa drivers: +DRIVER_DIRS = + + +MKDEP_OPTIONS = -fdepend -Y + + +GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lm -lpthread \ + -L$(SDK)/lib -m32 -Wl,-m,elf32ppc -R$(SDK)/lib -lspe2 + + +CELL_SPU_LIB = $(TOP)/src/gallium/drivers/cell/spu/g3d_spu.a + + +### SPU stuff + +SPU_CC = spu-gcc + +SPU_CFLAGS = $(OPT_FLAGS) -W -Wall -Winline -Wmissing-prototypes -Wno-main \ + -I. -I$(SDK)/spu/include -I$(TOP)/src/mesa/ $(INCLUDE_DIRS) \ + -DSPU_MAIN_PARAM_LONG_LONG \ + -include spu_intrinsics.h + +SPU_LFLAGS = -L$(SDK)/spu/lib -Wl,-N -lmisc -lm + +SPU_AR = ppu-ar +SPU_AR_FLAGS = -qcs + +SPU_EMBED = ppu32-embedspu +SPU_EMBED_FLAGS = -m32 diff --git a/configs/linux-cell-debug b/configs/linux-cell-debug new file mode 100644 index 0000000..42f3245 --- /dev/null +++ b/configs/linux-cell-debug @@ -0,0 +1,10 @@ +# linux-cell-debug + +include $(TOP)/configs/linux-cell + +# just override name and OPT_FLAGS here: + +CONFIG_NAME = linux-cell-debug + +OPT_FLAGS = -g -DDEBUG + diff --git a/configs/linux-debug b/configs/linux-debug new file mode 100644 index 0000000..60e0b97 --- /dev/null +++ b/configs/linux-debug @@ -0,0 +1,9 @@ +# Configuration for debugging on Linux + +include $(TOP)/configs/linux + +CONFIG_NAME = linux-debug + +OPT_FLAGS = -g +#CFLAGS += -pedantic +DEFINES += -DDEBUG -DDEBUG_MATH diff --git a/configs/linux-dri b/configs/linux-dri new file mode 100644 index 0000000..1c94ed0 --- /dev/null +++ b/configs/linux-dri @@ -0,0 +1,71 @@ +# -*-makefile-*- +# Configuration for linux-dri: Linux DRI hardware drivers for XFree86 & others + +include $(TOP)/configs/default + +CONFIG_NAME = linux-dri + +# Compiler and flags +CC = gcc +CXX = g++ + +#MKDEP = /usr/X11R6/bin/makedepend +#MKDEP = gcc -M +#MKDEP_OPTIONS = -MF depend + +OPT_FLAGS = -O2 -g +PIC_FLAGS = -fPIC + +# Add '-DGLX_USE_TLS' to ARCH_FLAGS to enable TLS support. +ARCH_FLAGS ?= + +DEFINES = -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE \ + -D_BSD_SOURCE -D_GNU_SOURCE \ + -DPTHREADS -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER \ + -DGLX_DIRECT_RENDERING -DGLX_INDIRECT_RENDERING \ + -DHAVE_ALIAS -DHAVE_POSIX_MEMALIGN + +X11_INCLUDES = -I/usr/X11R6/include + +CFLAGS = -Wall -Wmissing-prototypes -std=c99 -ffast-math \ + $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(DEFINES) $(ASM_FLAGS) + +CXXFLAGS = -Wall $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(DEFINES) + +GLUT_CFLAGS = -fexceptions + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +MESA_ASM_SOURCES = + +# Library/program dependencies +EXTRA_LIB_PATH=-L/usr/X11R6/lib + +LIBDRM_CFLAGS = $(shell pkg-config --cflags libdrm) +LIBDRM_LIB = $(shell pkg-config --libs libdrm) +DRI_LIB_DEPS = $(EXTRA_LIB_PATH) -lm -lpthread -lexpat -ldl $(LIBDRM_LIB) +GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lXxf86vm -lXdamage -lXfixes \ + -lm -lpthread -ldl $(LIBDRM_LIB) + + +# Directories +SRC_DIRS := glx egl $(SRC_DIRS) + +# EGL directories +EGL_DRIVERS_DIRS = glx + +DRIVER_DIRS = dri +GALLIUM_WINSYS_DIRS = sw sw/xlib drm/vmware drm/intel drm/i965 +GALLIUM_TARGET_DIRS = +GALLIUM_STATE_TRACKERS_DIRS = egl + +DRI_DIRS = i810 i915 i965 mach64 mga r128 r200 r300 radeon \ + savage sis tdfx unichrome swrast + +INTEL_LIBS = `pkg-config --libs libdrm_intel` +INTEL_CFLAGS = `pkg-config --cflags libdrm_intel` + +RADEON_LIBS = `pkg-config --libs libdrm_radeon` +RADEON_CFLAGS = `pkg-config --cflags libdrm_radeon` diff --git a/configs/linux-dri-debug b/configs/linux-dri-debug new file mode 100644 index 0000000..0dbf428 --- /dev/null +++ b/configs/linux-dri-debug @@ -0,0 +1,16 @@ +# -*-makefile-*- +# Configuration for linux-dri-debug: Linux DRI hardware drivers for XFree86 & others + +include $(TOP)/configs/linux-dri + +CONFIG_NAME = linux-dri-debug +OPT_FLAGS = -O0 -g +ARCH_FLAGS = -DDEBUG + +# Helpful to reduce the amount of stuff that gets built sometimes: +#DRI_DIRS = i915tex i915 +#DRI_DIRS = i965 +#DRI_DIRS = radeon r200 r300 +#DRI_DIRS = unichrome sis +#DRI_DIRS = i810 mga r128 tdfx + diff --git a/configs/linux-dri-ppc b/configs/linux-dri-ppc new file mode 100644 index 0000000..a3a3ca8 --- /dev/null +++ b/configs/linux-dri-ppc @@ -0,0 +1,17 @@ +# -*-makefile-*- +# Configuration for linux-dri: Linux DRI hardware drivers for XFree86 & others + +include $(TOP)/configs/linux-dri + +CONFIG_NAME = linux-dri-ppc + +OPT_FLAGS = -Os -mcpu=603 +PIC_FLAGS = -fPIC + +ASM_FLAGS = -DUSE_PPC_ASM -DUSE_VMX_ASM +MESA_ASM_SOURCES = $(PPC_SOURCES) + +# Build only the drivers for cards that exist on PowerPC. At some point MGA +# will be added, but not yet. +DRI_DIRS = mach64 r128 r200 r300 radeon tdfx + diff --git a/configs/linux-dri-x86 b/configs/linux-dri-x86 new file mode 100644 index 0000000..4e7d45d --- /dev/null +++ b/configs/linux-dri-x86 @@ -0,0 +1,13 @@ +# -*-makefile-*- +# Configuration for linux-dri: Linux DRI hardware drivers for XFree86 & others + +include $(TOP)/configs/linux-dri + +CONFIG_NAME = linux-dri-x86 + +ARCH_FLAGS = -m32 -mmmx -msse -msse2 + +ASM_FLAGS = -DUSE_X86_ASM -DUSE_MMX_ASM -DUSE_3DNOW_ASM -DUSE_SSE_ASM +MESA_ASM_SOURCES = $(X86_SOURCES) +GLAPI_ASM_SOURCES = $(X86_API) + diff --git a/configs/linux-dri-x86-64 b/configs/linux-dri-x86-64 new file mode 100644 index 0000000..656cf61 --- /dev/null +++ b/configs/linux-dri-x86-64 @@ -0,0 +1,24 @@ +# -*-makefile-*- +# Configuration for linux-dri: Linux DRI hardware drivers for XFree86 & others + +include $(TOP)/configs/linux-dri + +CONFIG_NAME = linux-dri-x86-64 + +ARCH_FLAGS = -m64 + +ASM_FLAGS = -DUSE_X86_64_ASM +MESA_ASM_SOURCES = $(X86-64_SOURCES) +GLAPI_ASM_SOURCES = $(X86-64_API) + +LIB_DIR = lib64 + +# Library/program dependencies +EXTRA_LIB_PATH=-L/usr/X11R6/lib64 + +# sis is missing because it has not been converted to use +# the new interface. i810 are missing because there is no x86-64 +# system where they could *ever* be used. +# +DRI_DIRS = i915 i965 mach64 mga r128 r200 r300 radeon savage tdfx unichrome + diff --git a/configs/linux-dri-xcb b/configs/linux-dri-xcb new file mode 100644 index 0000000..8092a04 --- /dev/null +++ b/configs/linux-dri-xcb @@ -0,0 +1,54 @@ +# -*-makefile-*- +# Configuration for linux-dri: Linux DRI hardware drivers for XFree86 & others + +include $(TOP)/configs/default + +CONFIG_NAME = linux-dri-xcb + +# Compiler and flags +CC = gcc +CXX = g++ + +#MKDEP = /usr/X11R6/bin/makedepend +#MKDEP = gcc -M +#MKDEP_OPTIONS = -MF depend + +OPT_FLAGS = -g +PIC_FLAGS = -fPIC + +# Add '-DGLX_USE_TLS' to ARCH_FLAGS to enable TLS support. +ARCH_FLAGS ?= + +DEFINES = -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE \ + -D_BSD_SOURCE -D_GNU_SOURCE \ + -DPTHREADS -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER \ + -DGLX_DIRECT_RENDERING -DGLX_INDIRECT_RENDERING \ + -DHAVE_ALIAS -DUSE_XCB -DHAVE_POSIX_MEMALIGN + +X11_INCLUDES = $(shell pkg-config --cflags-only-I x11) $(shell pkg-config --cflags-only-I xcb) $(shell pkg-config --cflags-only-I x11-xcb) $(shell pkg-config --cflags-only-I xcb-glx) + +CFLAGS = -Wall -Wmissing-prototypes $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) \ + $(DEFINES) $(ASM_FLAGS) -std=c99 -ffast-math + +CXXFLAGS = -Wall $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(DEFINES) + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +MESA_ASM_SOURCES = + +# Library/program dependencies +EXTRA_LIB_PATH=$(shell pkg-config --libs-only-L x11) + +LIBDRM_CFLAGS = $(shell pkg-config --cflags libdrm) +LIBDRM_LIB = $(shell pkg-config --libs libdrm) +DRI_LIB_DEPS = $(EXTRA_LIB_PATH) -lm -lpthread -lexpat -ldl $(LIBDRM_LIB) +GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lXxf86vm -lm -lpthread -ldl \ + $(LIBDRM_LIB) $(shell pkg-config --libs xcb) $(shell pkg-config --libs x11-xcb) $(shell pkg-config --libs xcb-glx) + +SRC_DIRS = glx gallium mesa glu glut/glx glw + +DRIVER_DIRS = dri +DRI_DIRS = i810 i915 mach64 mga r128 r200 r300 radeon \ + savage sis tdfx unichrome diff --git a/configs/linux-egl b/configs/linux-egl new file mode 100644 index 0000000..6393e94 --- /dev/null +++ b/configs/linux-egl @@ -0,0 +1,56 @@ +# -*-makefile-*- +# Configuration for linux-dri: Linux DRI hardware drivers for XFree86 & others + +include $(TOP)/configs/default + +CONFIG_NAME = linux-dri + +# Compiler and flags +CC = gcc +CXX = g++ + +#MKDEP = /usr/X11R6/bin/makedepend +#MKDEP = gcc -M +#MKDEP_OPTIONS = -MF depend + +OPT_FLAGS = -O -g +PIC_FLAGS = -fPIC + +# Add '-DGLX_USE_TLS' to ARCH_FLAGS to enable TLS support. +ARCH_FLAGS ?= + +DEFINES = -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE \ + -D_BSD_SOURCE -D_GNU_SOURCE \ + -DPTHREADS -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER \ + -DGLX_DIRECT_RENDERING -DGLX_INDIRECT_RENDERING \ + -DHAVE_ALIAS -DHAVE_POSIX_MEMALIGN + +X11_INCLUDES = -I/usr/X11R6/include + +CFLAGS = -Wall -Wmissing-prototypes -std=c99 -ffast-math \ + $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(DEFINES) $(ASM_FLAGS) + +CXXFLAGS = -Wall $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(DEFINES) + + +MESA_ASM_SOURCES = + +# Library/program dependencies +EXTRA_LIB_PATH=-L/usr/X11R6/lib + +LIBDRM_CFLAGS = $(shell pkg-config --cflags libdrm) +LIBDRM_LIB = $(shell pkg-config --libs libdrm) +DRI_LIB_DEPS = $(EXTRA_LIB_PATH) -lm -lpthread -lexpat -ldl $(LIBDRM_LIB) +GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lXxf86vm -lXdamage -lXfixes \ + -lm -lpthread -ldl \ + $(LIBDRM_LIB) + + +# Directories +SRC_DIRS = gallium mesa gallium/winsys gallium/targets glu egl + +DRIVER_DIRS = dri +GALLIUM_WINSYS_DIRS = egl_drm +GALLIUM_TARGET_DIRS = + +DRI_DIRS = intel diff --git a/configs/linux-fbdev b/configs/linux-fbdev new file mode 100644 index 0000000..4fc6384 --- /dev/null +++ b/configs/linux-fbdev @@ -0,0 +1,18 @@ +# Configuration for Linux fbdev interface + +include $(TOP)/configs/linux + +CONFIG_NAME = linux-fbdev + +CFLAGS += -DUSE_GLFBDEV_DRIVER + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing + +SRC_DIRS += glut/fbdev +DRIVER_DIRS = fbdev osmesa + +GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lm -lpthread +OSMESA_LIB_DEPS = -lm -lpthread +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) $(EXTRA_LIB_PATH) -lgpm -lm + diff --git a/configs/linux-i965 b/configs/linux-i965 new file mode 100644 index 0000000..7656a2a --- /dev/null +++ b/configs/linux-i965 @@ -0,0 +1,9 @@ +# Configuration for standalone mode i965 debug + +include $(TOP)/configs/linux-debug + +CONFIG_NAME = linux-i965 + +GALLIUM_DRIVER_DIRS = i965 +GALLIUM_WINSYS_DIRS = drm/i965/xlib +GALLIUM_TARGET_DIRS = diff --git a/configs/linux-ia64-icc b/configs/linux-ia64-icc new file mode 100644 index 0000000..bd11897 --- /dev/null +++ b/configs/linux-ia64-icc @@ -0,0 +1,21 @@ +# Configuration for Linux with Intel C compiler + +include $(TOP)/configs/default + +CONFIG_NAME = linux-icc + +# Compiler and flags +CC = icc +CXX = icpc +CFLAGS = -O3 -ansi -KPIC -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE -DUSE_XSHM -DPTHREADS -I/usr/X11R6/include +CXXFLAGS = -O3 -ansi -KPIC -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE -DUSE_XSHM -DPTHREADS -I/usr/X11R6/include +GLUT_CFLAGS = -fexceptions +MKLIB_OPTIONS = -arch icc-istatic + +GL_LIB_DEPS = -L/usr/X11R6/lib -lX11 -lXext -lpthread +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/X11R6/lib -lX11 -lXmu -lXt -lXi +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(GL_LIB_DEPS) +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) + + diff --git a/configs/linux-ia64-icc-static b/configs/linux-ia64-icc-static new file mode 100644 index 0000000..ce8daf1 --- /dev/null +++ b/configs/linux-ia64-icc-static @@ -0,0 +1,27 @@ +# Configuration for Linux with Intel C compiler, static libs + +include $(TOP)/configs/default + +CONFIG_NAME = linux-icc-static + +# Compiler and flags +CC = icc +CXX = icpc +CFLAGS = -O3 -ansi -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE -DUSE_XSHM -DPTHREADS -I/usr/X11R6/include +CXXFLAGS = -O3 -ansi -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE -DUSE_XSHM -DPTHREADS -I/usr/X11R6/include +GLUT_CFLAGS = -fexceptions +MKLIB_OPTIONS = -static -arch icc-istatic + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +GL_LIB_DEPS = +GLU_LIB_DEPS = +GLUT_LIB_DEPS = +GLW_LIB_DEPS = +APP_LIB_DEPS = -i-static -cxxlib-icc -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/X11R6/lib -lX11 -lXmu -lXt -lXi -lpthread -lm -lcxa -lunwind + diff --git a/configs/linux-icc b/configs/linux-icc new file mode 100644 index 0000000..d90a1da --- /dev/null +++ b/configs/linux-icc @@ -0,0 +1,22 @@ +# Configuration for Linux with Intel C compiler + +include $(TOP)/configs/default + +CONFIG_NAME = linux-icc + +# Compiler and flags +CC = icc +CXX = g++ +CFLAGS = -O3 -tpp6 -axK -KPIC -D_GCC_LIMITS_H_ -D__GNUC__ -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE -DUSE_XSHM -DUSE_X86_ASM -DUSE_MMX_ASM -DUSE_3DNOW_ASM -DUSE_SSE_ASM -DPTHREADS -I/usr/X11R6/include +CXXFLAGS = -O3 +GLUT_CFLAGS = -fexceptions +MKLIB_OPTIONS = -arch icc + +GL_LIB_DEPS = -L/usr/X11R6/lib -lX11 -lXext -lm -lpthread +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/X11R6/lib -lX11 -lXmu -lXt -lXi -lm +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm + +MESA_ASM_SOURCES = $(X86_SOURCES) +GLAPI_ASM_SOURCES = $(X86_API) + + diff --git a/configs/linux-icc-static b/configs/linux-icc-static new file mode 100644 index 0000000..384db3b --- /dev/null +++ b/configs/linux-icc-static @@ -0,0 +1,27 @@ +# Configuration for Linux with Intel C compiler, static libs + +include $(TOP)/configs/default + +CONFIG_NAME = linux-icc-static + +# Compiler and flags +CC = icc +CXX = icpc +CFLAGS = -O3 -tpp6 -axK -D_GCC_LIMITS_H_ -D__GNUC__ -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE -DUSE_XSHM -DUSE_X86_ASM -DUSE_MMX_ASM -DUSE_3DNOW_ASM -DUSE_SSE_ASM -DPTHREADS -I/usr/X11R6/include +CXXFLAGS = -O3 -tpp6 -axK -DPTHREADS +GLUT_CFLAGS = -fexceptions +MKLIB_OPTIONS = -static -arch icc + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +GL_LIB_DEPS = +GLUT_LIB_DEPS = +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/X11R6/lib -lX11 -lXmu -lXt -lXi -lm -lpthread -lcxa -lunwind + +MESA_ASM_SOURCES = $(X86_SOURCES) +GLAPI_ASM_SOURCES = $(X86_API) diff --git a/configs/linux-indirect b/configs/linux-indirect new file mode 100644 index 0000000..272d34e --- /dev/null +++ b/configs/linux-indirect @@ -0,0 +1,51 @@ +# -*-makefile-*- +# Configuration for linux-indirect: Builds a libGL capable of indirect +# rendering, but *NOT* capable of direct rendering. + +include $(TOP)/configs/default + +CONFIG_NAME = linux-dri + +# Compiler and flags +CC = gcc +CXX = g++ + +#MKDEP = /usr/X11R6/bin/makedepend +#MKDEP = gcc -M +#MKDEP_OPTIONS = -MF depend + +WARN_FLAGS = -Wall +OPT_FLAGS = -O -g +PIC_FLAGS = -fPIC + +# Add '-DGLX_USE_TLS' to ARCH_FLAGS to enable TLS support. +ARCH_FLAGS ?= + +DEFINES = -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE \ + -D_BSD_SOURCE -D_GNU_SOURCE \ + -DGLX_INDIRECT_RENDERING \ + -DPTHREADS -DHAVE_ALIAS -DHAVE_POSIX_MEMALIGN + +X11_INCLUDES = -I/usr/X11R6/include + +CFLAGS = $(WARN_FLAGS) $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(DEFINES) \ + $(ASM_FLAGS) -std=c99 -ffast-math + +CXXFLAGS = $(WARN_FLAGS) $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(DEFINES) + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +MESA_ASM_SOURCES = + +# Library/program dependencies +EXTRA_LIB_PATH=-L/usr/X11R6/lib + +DRI_LIB_DEPS = $(EXTRA_LIB_PATH) -lm -lpthread -lexpat -ldl +GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lXxf86vm -lm -lpthread -ldl + + +# Directories +SRC_DIRS = glx glu glut/glx glw +DRIVER_DIRS = diff --git a/configs/linux-llvm b/configs/linux-llvm new file mode 100644 index 0000000..e699953 --- /dev/null +++ b/configs/linux-llvm @@ -0,0 +1,44 @@ +# -*-makefile-*- +# Configuration for Linux and LLVM with optimizations +# Builds the llvmpipe gallium driver + +include $(TOP)/configs/linux + +CONFIG_NAME = linux-llvm + +# Add llvmpipe driver +GALLIUM_DRIVERS_DIRS += llvmpipe + +OPT_FLAGS = -O3 -ansi -pedantic +ARCH_FLAGS = -mmmx -msse -msse2 -mstackrealign + +DEFINES += -DNDEBUG -DGALLIUM_LLVMPIPE -DHAVE_UDIS86 + +# override -std=c99 +CFLAGS += -std=gnu99 + +LLVM_VERSION := $(shell llvm-config --version) + +ifeq ($(LLVM_VERSION),) + $(warning Could not find LLVM! Make Sure 'llvm-config' is in the path) + MESA_LLVM=0 +else + MESA_LLVM=1 + HAVE_LLVM := 0x0$(subst .,0,$(LLVM_VERSION:svn=)) + DEFINES += -DHAVE_LLVM=$(HAVE_LLVM) +# $(info Using LLVM version: $(LLVM_VERSION)) +endif + +ifeq ($(MESA_LLVM),1) + LLVM_CFLAGS=`llvm-config --cppflags` + LLVM_CXXFLAGS=`llvm-config --cxxflags backend bitreader engine ipo interpreter instrumentation` -Wno-long-long + LLVM_LDFLAGS = $(shell llvm-config --ldflags backend bitreader engine ipo interpreter instrumentation) + LLVM_LIBS = $(shell llvm-config --libs backend bitwriter bitreader engine ipo interpreter instrumentation) + MKLIB_OPTIONS=-cplusplus +else + LLVM_CFLAGS= + LLVM_CXXFLAGS= +endif + +LD = g++ +GL_LIB_DEPS = $(LLVM_LDFLAGS) $(LLVM_LIBS) $(EXTRA_LIB_PATH) -lX11 -lXext -lm -lpthread -lstdc++ -ludis86 diff --git a/configs/linux-llvm-debug b/configs/linux-llvm-debug new file mode 100644 index 0000000..28bcfdb --- /dev/null +++ b/configs/linux-llvm-debug @@ -0,0 +1,12 @@ +# -*-makefile-*- +# Configuration for Linux and LLVM with debugging info +# Builds the llvmpipe gallium driver + +include $(TOP)/configs/linux-llvm + +CONFIG_NAME = linux-llvm-debug + +OPT_FLAGS = -g -ansi -pedantic + +DEFINES += -DDEBUG -UNDEBUG + diff --git a/configs/linux-opengl-es b/configs/linux-opengl-es new file mode 100644 index 0000000..93c0d47 --- /dev/null +++ b/configs/linux-opengl-es @@ -0,0 +1,28 @@ +# Configuration for OpenGL ES on Linux + +include $(TOP)/configs/linux + +CONFIG_NAME = linux-opengl-es + +# Directories to build +LIB_DIR = lib +SRC_DIRS = egl glsl mapi/es1api mapi/es2api mesa/es \ + gallium gallium/winsys gallium/targets + +# egl st needs this +DEFINES += -DGLX_DIRECT_RENDERING + +# no mesa or egl drivers +DRIVER_DIRS = +EGL_DRIVERS_DIRS = + +GALLIUM_DRIVERS_DIRS = softpipe + +# build libGLES*.so +GALLIUM_STATE_TRACKERS_DIRS = es + +# build egl_x11_{swrast,i915}.so +GALLIUM_DRIVERS_DIRS += trace rbug i915 +GALLIUM_STATE_TRACKERS_DIRS += egl +GALLIUM_WINSYS_DIRS += drm/intel +GALLIUM_TARGET_DIRS += egl-swrast egl-i915 diff --git a/configs/linux-osmesa b/configs/linux-osmesa new file mode 100644 index 0000000..4cc5e51 --- /dev/null +++ b/configs/linux-osmesa @@ -0,0 +1,27 @@ +# Configuration for building only libOSMesa on Linux, no Xlib driver +# This doesn't really have any Linux dependencies, so it should be usable +# on other (gcc-based) systems. + +include $(TOP)/configs/default + +CONFIG_NAME = linux-osmesa + +# Compiler and flags +CC = gcc +CXX = g++ +CFLAGS = -g -ansi -pedantic -fPIC -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE -D_GNU_SOURCE -DPTHREADS +CXXFLAGS = -O3 -ansi -pedantic -fPIC -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +# Directories +SRC_DIRS = mapi/glapi glsl mesa glu +DRIVER_DIRS = osmesa + + +# Dependencies +OSMESA_LIB_DEPS = -lm -lpthread -ldl +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(OSMESA_LIB) +APP_LIB_DEPS = -lm -lpthread diff --git a/configs/linux-osmesa-static b/configs/linux-osmesa-static new file mode 100644 index 0000000..7220794 --- /dev/null +++ b/configs/linux-osmesa-static @@ -0,0 +1,36 @@ +# Configuration for building static libOSMesa.a on Linux, no Xlib driver +# This doesn't really have any Linux dependencies, so it should be usable +# on other (gcc-based) systems. + +include $(TOP)/configs/default + +CONFIG_NAME = linux-osmesa + +# Compiler and flags +CC = gcc -m32 +CXX = g++ -m32 +CFLAGS = -O3 -ansi -pedantic -fPIC -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE -DPTHREADS +CXXFLAGS = -O3 -ansi -pedantic -fPIC -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE + +MKLIB_OPTIONS = -static + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +# Directories +SRC_DIRS = mesa glu +DRIVER_DIRS = osmesa + + +# Dependencies +GL_LIB_DEPS = +OSMESA_LIB_DEPS = +GLU_LIB_DEPS = +GLUT_LIB_DEPS = +GLW_LIB_DEPS = +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) \ + $(EXTRA_LIB_PATH) -lX11 -lXmu -lXt -lXi -lpthread -lstdc++ -lm diff --git a/configs/linux-osmesa16 b/configs/linux-osmesa16 new file mode 100644 index 0000000..e6c26a2 --- /dev/null +++ b/configs/linux-osmesa16 @@ -0,0 +1,30 @@ +# Configuration for 16 bits/channel OSMesa library on Linux + +include $(TOP)/configs/default + +CONFIG_NAME = linux-osmesa16 + +# Compiler and flags +CC = gcc +CXX = g++ +CFLAGS = -O3 -ansi -pedantic -fPIC -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE -DUSE_XSHM -DPTHREADS -I/usr/X11R6/include -DCHAN_BITS=16 -DDEFAULT_SOFTWARE_DEPTH_BITS=31 +CXXFLAGS = -O3 -ansi -pedantic -fPIC -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +# Library names +OSMESA_LIB = OSMesa16 +OSMESA_LIB_NAME = libOSMesa16.so + + +# Directories +SRC_DIRS = mapi/glapi glsl mesa glu +DRIVER_DIRS = osmesa + + +# Dependencies +OSMESA_LIB_DEPS = -lm -lpthread +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(OSMESA_LIB) +APP_LIB_DEPS = -lm -lpthread diff --git a/configs/linux-osmesa16-static b/configs/linux-osmesa16-static new file mode 100644 index 0000000..a6c0cab --- /dev/null +++ b/configs/linux-osmesa16-static @@ -0,0 +1,31 @@ +# Configuration for 16 bits/channel OSMesa library on Linux + +include $(TOP)/configs/default + +CONFIG_NAME = linux-osmesa16-static + +# Compiler and flags +CC = gcc +CXX = g++ +CFLAGS = -O3 -ansi -pedantic -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE -DUSE_XSHM -DPTHREADS -I/usr/X11R6/include -DCHAN_BITS=16 -DDEFAULT_SOFTWARE_DEPTH_BITS=31 +CXXFLAGS = -O3 -ansi -pedantic -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE +MKLIB_OPTIONS = -static +PIC_FLAGS = + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +# Library names +OSMESA_LIB = OSMesa16 +OSMESA_LIB_NAME = libOSMesa16.a + + +# Directories +SRC_DIRS = gallium mesa glu +DRIVER_DIRS = osmesa + + +# Dependencies +OSMESA_LIB_DEPS = -lm -lpthread +APP_LIB_DEPS = -lm -lpthread diff --git a/configs/linux-osmesa32 b/configs/linux-osmesa32 new file mode 100644 index 0000000..dafa31b --- /dev/null +++ b/configs/linux-osmesa32 @@ -0,0 +1,30 @@ +# Configuration for 32 bits/channel OSMesa library on Linux + +include $(TOP)/configs/default + +CONFIG_NAME = linux-osmesa32 + +# Compiler and flags +CC = gcc +CXX = g++ +CFLAGS = -O3 -ansi -pedantic -fPIC -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE -DUSE_XSHM -DPTHREADS -I/usr/X11R6/include -DCHAN_BITS=32 -DDEFAULT_SOFTWARE_DEPTH_BITS=31 +CXXFLAGS = -O3 -ansi -pedantic -fPIC -ffast-math -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +# Library names +OSMESA_LIB = OSMesa32 +OSMESA_LIB_NAME = libOSMesa32.so + + +# Directories +SRC_DIRS = mapi/glapi glsl mesa glu +DRIVER_DIRS = osmesa + + +# Dependencies +OSMESA_LIB_DEPS = -lm -lpthread +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(OSMESA_LIB) +APP_LIB_DEPS = -lm -lpthread diff --git a/configs/linux-ppc b/configs/linux-ppc new file mode 100644 index 0000000..13cfdeb --- /dev/null +++ b/configs/linux-ppc @@ -0,0 +1,9 @@ +# Configuration for Linux on PPC + +include $(TOP)/configs/linux + +CONFIG_NAME = linux-ppc + +OPT_FLAGS = -O3 -mcpu=603 -fsigned-char -funroll-loops + +# FIXME: Use of PowerPC assembly should be enabled here. \ No newline at end of file diff --git a/configs/linux-ppc-static b/configs/linux-ppc-static new file mode 100644 index 0000000..3f3dc55 --- /dev/null +++ b/configs/linux-ppc-static @@ -0,0 +1,15 @@ +# Configuration for Linux on PPC, static libs + +include $(TOP)/configs/linux-ppc + +CONFIG_NAME = linux-ppc-static + +MKLIB_OPTIONS = -static +PIC_FLAGS = + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a diff --git a/configs/linux-profile b/configs/linux-profile new file mode 100644 index 0000000..e3895dd --- /dev/null +++ b/configs/linux-profile @@ -0,0 +1,8 @@ +# Configuration for profiling on Linux with gprof + +include $(TOP)/configs/linux-static + +CONFIG_NAME = linux-profile + +OPT_FLAGS = -pg -g -O2 +DEFINES += -DNDEBUG diff --git a/configs/linux-sparc b/configs/linux-sparc new file mode 100644 index 0000000..346d438 --- /dev/null +++ b/configs/linux-sparc @@ -0,0 +1,9 @@ +# Configuration for Linux on Sparc + +include $(TOP)/configs/linux + +CONFIG_NAME = linux-sparc + +#ASM_FLAGS = -DUSE_SPARC_ASM +#MESA_ASM_SOURCES = $(SPARC_SOURCES) +#GLAPI_ASM_SOURCES = $(SPARC_API) diff --git a/configs/linux-sparc5 b/configs/linux-sparc5 new file mode 100644 index 0000000..e8848d2 --- /dev/null +++ b/configs/linux-sparc5 @@ -0,0 +1,7 @@ +# Configuration for Linux on Sparc5 + +include $(TOP)/configs/linux-sparc + +CONFIG_NAME = linux-sparc5 + +ARCH_FLAGS += -mcpu=ultrasparc diff --git a/configs/linux-static b/configs/linux-static new file mode 100644 index 0000000..907904b --- /dev/null +++ b/configs/linux-static @@ -0,0 +1,26 @@ +# Configuration for generic Linux, making static libs + +include $(TOP)/configs/linux + +CONFIG_NAME = linux-static + +MKLIB_OPTIONS = -static +PIC_FLAGS = + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +# Library/program dependencies (static libs don't have dependencies) +GL_LIB_DEPS = +OSMESA_LIB_DEPS = +GLU_LIB_DEPS = +GLUT_LIB_DEPS = +GLW_LIB_DEPS = + +# Need to specify all libraries we may need +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) \ + -l$(GL_LIB) -lm -L/usr/X11R6/lib/ -lX11 -lXext -lXmu -lXi -lpthread diff --git a/configs/linux-ultrasparc b/configs/linux-ultrasparc new file mode 100644 index 0000000..d6c838e --- /dev/null +++ b/configs/linux-ultrasparc @@ -0,0 +1,7 @@ +# Configuration for Linux on UltraSparc + +include $(TOP)/configs/linux-sparc + +CONFIG_NAME = linux-ultrasparc + +ARCH_FLAGS += -mv8 -mtune=ultrasparc diff --git a/configs/linux-x86 b/configs/linux-x86 new file mode 100644 index 0000000..5970b18 --- /dev/null +++ b/configs/linux-x86 @@ -0,0 +1,11 @@ +# Configuration for Linux with x86 optimizations + +include $(TOP)/configs/linux + +CONFIG_NAME = linux-x86 + +ARCH_FLAGS = -m32 -mmmx -msse -msse2 + +ASM_FLAGS = -DUSE_X86_ASM -DUSE_MMX_ASM -DUSE_3DNOW_ASM -DUSE_SSE_ASM +MESA_ASM_SOURCES = $(X86_SOURCES) +GLAPI_ASM_SOURCES = $(X86_API) diff --git a/configs/linux-x86-32 b/configs/linux-x86-32 new file mode 100644 index 0000000..f18ce7a --- /dev/null +++ b/configs/linux-x86-32 @@ -0,0 +1,7 @@ +# To build Linux x86 32-bit in an x86-64 environment + +include $(TOP)/configs/linux-x86 + +CONFIG_NAME = linux-x86-32 + +ARCH_FLAGS += -m32 diff --git a/configs/linux-x86-64 b/configs/linux-x86-64 new file mode 100644 index 0000000..c2441e0 --- /dev/null +++ b/configs/linux-x86-64 @@ -0,0 +1,14 @@ +# Configuration for Linux for 64-bit X86 (Opteron) + +include $(TOP)/configs/linux + +CONFIG_NAME = linux-x86-64 + +ARCH_FLAGS = -m64 + +MESA_ASM_SOURCES = $(X86-64_SOURCES) +GLAPI_ASM_SOURCES = $(X86-64_API) +ASM_FLAGS = -DUSE_X86_64_ASM + +LIB_DIR = lib64 +EXTRA_LIB_PATH = -L/usr/X11R6/lib64 diff --git a/configs/linux-x86-64-debug b/configs/linux-x86-64-debug new file mode 100644 index 0000000..6f631c0 --- /dev/null +++ b/configs/linux-x86-64-debug @@ -0,0 +1,8 @@ +# Configuration for Linux for 64-bit X86 (Opteron) + +include $(TOP)/configs/linux-x86-64 + +CONFIG_NAME = linux-x86-64-debug + +OPT_FLAGS = -g +DEFINES += -DDEBUG -DDEBUG_MATH diff --git a/configs/linux-x86-64-profile b/configs/linux-x86-64-profile new file mode 100644 index 0000000..6eb9c68 --- /dev/null +++ b/configs/linux-x86-64-profile @@ -0,0 +1,8 @@ +# Configuration for profiling on Linux for 64-bit X86 (Opteron) with gprof + +include $(TOP)/configs/linux-x86-64-static + +CONFIG_NAME = linux-x86-64-profile + +OPT_FLAGS = -pg -g -O2 +DEFINES += -DNDEBUG diff --git a/configs/linux-x86-64-static b/configs/linux-x86-64-static new file mode 100644 index 0000000..626d579 --- /dev/null +++ b/configs/linux-x86-64-static @@ -0,0 +1,27 @@ +# Configuration for Linux for 64-bit X86 (Opteron), static libs + +include $(TOP)/configs/linux-x86-64 + +CONFIG_NAME = linux-x86-64-static + +MKLIB_OPTIONS = -static +PIC_FLAGS = + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +# Library/program dependencies (static libs don't have dependencies) +GL_LIB_DEPS = +OSMESA_LIB_DEPS = +GLU_LIB_DEPS = +GLUT_LIB_DEPS = +GLW_LIB_DEPS = + +# Need to specify all libraries we may need +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -Wl,--start-group \ + -l$(GL_LIB) $(TOP)/src/mesa/pipe/softpipe/libsoftpipe.a -Wl,--end-group \ + $(EXTRA_LIB_PATH) -lX11 -lXext -lXmu -lXt -lXi -lpthread -lstdc++ -lm diff --git a/configs/linux-x86-debug b/configs/linux-x86-debug new file mode 100644 index 0000000..d35012f --- /dev/null +++ b/configs/linux-x86-debug @@ -0,0 +1,9 @@ +# Configuration for Linux with x86 code, but no gcc optimizations and +# debugging enabled. + +include $(TOP)/configs/linux-x86 + +CONFIG_NAME = linux-x86-debug + +OPT_FLAGS = -g +DEFINES += -DDEBUG -DDEBUG_MATH diff --git a/configs/linux-x86-profile b/configs/linux-x86-profile new file mode 100644 index 0000000..987b5f0 --- /dev/null +++ b/configs/linux-x86-profile @@ -0,0 +1,8 @@ +# Configuration for profiling on Linux with x86 optimizations with gprof + +include $(TOP)/configs/linux-x86-static + +CONFIG_NAME = linux-x86-profile + +OPT_FLAGS = -pg -g -O2 +DEFINES += -DNDEBUG diff --git a/configs/linux-x86-static b/configs/linux-x86-static new file mode 100644 index 0000000..16c8731 --- /dev/null +++ b/configs/linux-x86-static @@ -0,0 +1,26 @@ +# Configuration for Linux with x86 optimizations, static libs + +include $(TOP)/configs/linux-x86 + +CONFIG_NAME = linux-x86-static + +MKLIB_OPTIONS = -static +PIC_FLAGS = + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +# Library/program dependencies (static libs don't have dependencies) +GL_LIB_DEPS = +OSMESA_LIB_DEPS = +GLU_LIB_DEPS = +GLUT_LIB_DEPS = +GLW_LIB_DEPS = + +# Need to specify all libraries we may need +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) \ + -l$(GL_LIB) $(EXTRA_LIB_PATH) -lX11 -lXext -lXmu -lXt -lXi -lpthread -lstdc++ -lm diff --git a/configs/netbsd b/configs/netbsd new file mode 100644 index 0000000..aec4569 --- /dev/null +++ b/configs/netbsd @@ -0,0 +1,17 @@ +# Configuration for NetBSD + +include $(TOP)/configs/default + +CONFIG_NAME = netbsd + +# Compiler and flags +CC = gcc +CXX = g++ +CFLAGS = -O2 -fPIC -DUSE_XSHM -I/usr/X11R6/include -DHZ=100 +CXXFLAGS = -O2 -fPIC +GLUT_CFLAGS = -fexceptions +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -L/usr/X11R6/lib -lXext -lXmu -lXi -lX11 -lm + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing diff --git a/configs/openbsd b/configs/openbsd new file mode 100644 index 0000000..bd19fa8 --- /dev/null +++ b/configs/openbsd @@ -0,0 +1,22 @@ +# Configuration for OpenBSD + +include $(TOP)/configs/default + +CONFIG_NAME = openbsd + +# Compiler and flags +CC = gcc +CXX = g++ +CFLAGS = -O2 -fPIC -I/usr/X11R6/include -DUSE_XSHM -DHZ=100 +CXXFLAGS = -O2 -fPIC -I/usr/X11R6/include -DHZ=100 + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +GL_LIB_DEPS = -L/usr/X11R6/lib -lX11 -lXext -lm +OSMESA_LIB_DEPS = -lm +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/X11R6/lib -lX11 -lXext -lXmu -lXt -lXi -lm +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -L/usr/X11R6/lib -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm + diff --git a/configs/osf1 b/configs/osf1 new file mode 100644 index 0000000..88a2ecc --- /dev/null +++ b/configs/osf1 @@ -0,0 +1,16 @@ +# Configuration for OSF/1 + +include $(TOP)/configs/default + +CONFIG_NAME = osf1 + +# Compiler and flags +CC = cc +CXX = cxx +CFLAGS = -O0 -std1 -ieee_with_no_inexact -DUSE_XSHM -DPTHREADS -D_REENTRANT +CXXFLAGS = -O2 -std ansi -ieee -DPTHREADS -D_REENTRANT + +GL_LIB_DEPS = -lX11 -lXext -lm -lpthread +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXmu -lXt -lXi -lm +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lX11 -lXext -lXmu -lXi -lpthread -lm diff --git a/configs/osf1-static b/configs/osf1-static new file mode 100644 index 0000000..e00f7ce --- /dev/null +++ b/configs/osf1-static @@ -0,0 +1,17 @@ +# Configuration for OSF/1 + +include $(TOP)/configs/default + +CONFIG_NAME = osf1 + +# Compiler and flags +CC = cc +CXX = cxx +CFLAGS = -O2 -std1 -ieee_with_no_inexact -DUSE_XSHM -DPTHREADS -D_REENTRANT +CXXFLAGS = -O2 -std ansi -ieee -DPTHREADS -D_REENTRANT +MKLIB_OPTIONS = -static + +GL_LIB_DEPS = +GLU_LIB_DEPS = +GLUT_LIB_DEPS = +APP_LIB_DEPS = -noso -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -so_archive -lX11 -lXext -lXmu -lXi -lpthread -lm -lcxx diff --git a/configs/solaris-x86 b/configs/solaris-x86 new file mode 100644 index 0000000..a5a7a63 --- /dev/null +++ b/configs/solaris-x86 @@ -0,0 +1,18 @@ +# Configuration for Solaris on x86 + +include $(TOP)/configs/default + +CONFIG_NAME = solaris-x86 + +# Compiler and flags +CC = cc +CFLAGS = -Xa -xO3 -xpentium -KPIC -I/usr/openwin/include -DUSE_XSHM +MKLIB_OPTIONS = -static + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -L/usr/openwin/lib -R/usr/openwin/lib -lX11 -lXext -lXmu -lXi -lm -lglut -lGLU -lGL + +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a diff --git a/configs/solaris-x86-gcc b/configs/solaris-x86-gcc new file mode 100644 index 0000000..616bfdf --- /dev/null +++ b/configs/solaris-x86-gcc @@ -0,0 +1,21 @@ +# Configuration for Solaris on x86 with gcc, dynamic libs + +include $(TOP)/configs/default + +CONFIG_NAME = solaris-x86-gcc + +# Compiler and flags +CC = gcc +CXX = g++ +CFLAGS = -O3 -march=i486 -fPIC -I/usr/openwin/include -DUSE_XSHM +CXXFLAGS = -O3 -march=i486 -fPIC +GLUT_CFLAGS = -fexceptions + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +GL_LIB_DEPS = -L/usr/openwin/lib -lX11 -lXext -lm -lpthread +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/openwin/lib -lX11 -lXmu -lXt -lXi -lm +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -L/usr/openwin/lib -R/usr/openwin/lib -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm -lX11 -lXext -lXi -lXmu diff --git a/configs/solaris-x86-gcc-static b/configs/solaris-x86-gcc-static new file mode 100644 index 0000000..4850284 --- /dev/null +++ b/configs/solaris-x86-gcc-static @@ -0,0 +1,28 @@ +# Configuration for Solaris on x86 with gcc, static libs + +include $(TOP)/configs/default + +CONFIG_NAME = solaris-x86-gcc + +# Compiler and flags +CC = gcc +CXX = g++ +CFLAGS = -O3 -march=i486 -fPIC -I/usr/openwin/include -DUSE_XSHM +CXXFLAGS = -O3 -march=i486 -fPIC +GLUT_CFLAGS = -fexceptions +MKLIB_OPTIONS = -static + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +GL_LIB_DEPS = -L/usr/openwin/lib -lX11 -lXext -lm -lpthread +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/openwin/lib -lX11 -lXmu -lXt -lXi -lm +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -L/usr/openwin/lib -R/usr/openwin/lib -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm -lX11 -lXext -lXi -lXmu + +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a diff --git a/configs/sunos4 b/configs/sunos4 new file mode 100644 index 0000000..9e6627d --- /dev/null +++ b/configs/sunos4 @@ -0,0 +1,12 @@ +# Configuration for SunOS 4, shared libs + +include $(TOP)/configs/default + +CONFIG_NAME = sunos4 + +# Compiler and flags +CC = acc +CFLAGS = -Kpic -O -I/usr/include/X11R5 -DUSE_XSHM -DSUNOS4 +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -L/usr/lib/X11R5 -lX11 -lXext -lXmu -lXi -lm + + diff --git a/configs/sunos4-gcc b/configs/sunos4-gcc new file mode 100644 index 0000000..0942291 --- /dev/null +++ b/configs/sunos4-gcc @@ -0,0 +1,19 @@ +# Configuration for SunOS 4, with gcc, shared libs + +include $(TOP)/configs/default + +CONFIG_NAME = sunos4-gcc + +# Compiler and flags +CC = gcc +CXX = g++ +CFLAGS = -fPIC -O3 -I/usr/openwin/include -I/usr/include/X11R5 -I/usr/include/X11R5 -DUSE_XSHM -DSUNOS4 +CXXFLAGS = -fPIC -O3 -I/usr/openwin/include -DSUNOS4 +GLUT_CFLAGS = -fexceptions -DSOLARIS_2_4_BUG + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -L/usr/openwin/lib -lX11 -lXext -lXmu -lXi -lm + diff --git a/configs/sunos4-static b/configs/sunos4-static new file mode 100644 index 0000000..9135fa7 --- /dev/null +++ b/configs/sunos4-static @@ -0,0 +1,25 @@ +# Configuration for SunOS 4, static libs + +include $(TOP)/configs/default + +CONFIG_NAME = sunos4-static + +# Compiler and flags +CC = acc +CFLAGS = -O -DUSE_XSHM -DSUNOS4 +MKLIB_OPTIONS = -static + +# Library names (actual file names) +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +# Library/program dependencies (static libs don't have dependencies) +GL_LIB_DEPS = +OSMESA_LIB_DEPS = +GLU_LIB_DEPS = +GLUT_LIB_DEPS = +GLW_LIB_DEPS = +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/X11R6/lib -lX11 -lXext -lXmu -lXt -lXi -lpthread -lm diff --git a/configs/sunos5 b/configs/sunos5 new file mode 100644 index 0000000..6dd7539 --- /dev/null +++ b/configs/sunos5 @@ -0,0 +1,18 @@ +# Configuration for SunOS 5 + +include $(TOP)/configs/default + +CONFIG_NAME = sunos5 + +# Compiler and flags +CC = cc +CXX = c++ +CFLAGS = -KPIC -Xa -O -I/usr/openwin/include -I/usr/dt/include -DUSE_XSHM +CXXFLAGS = -KPIC -Xa -O -I/usr/openwin/include -I/usr/dt/include +GLUT_CFLAGS = -DSOLARIS_2_4_BUG + +GL_LIB_DEPS = -L/usr/openwin/lib -L/usr/dt/lib -lX11 -lXext -lXmu -lXi -lm +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lm +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L/usr/openwin/lib -lXt -lX11 +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -lCrun -lX11 -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm diff --git a/configs/sunos5-64-gcc b/configs/sunos5-64-gcc new file mode 100644 index 0000000..c03903f --- /dev/null +++ b/configs/sunos5-64-gcc @@ -0,0 +1,11 @@ +# Configuration for 64-bit SunOS 5, with gcc + +include $(TOP)/configs/sunos5-gcc + +CONFIG_NAME = sunos5-64-gcc + +# only set vars that differ from sunos5-gcc config + +OPT_FLAGS = -O3 -m64 -mcpu=ultrasparc -mv8plus -mvis -g -fomit-frame-pointer -pipe + +ARCH_FLAGS = -m64 diff --git a/configs/sunos5-gcc b/configs/sunos5-gcc new file mode 100644 index 0000000..571ff24 --- /dev/null +++ b/configs/sunos5-gcc @@ -0,0 +1,40 @@ +# Configuration for SunOS 5, with gcc + +include $(TOP)/configs/default + +CONFIG_NAME = sunos5-gcc + +# Compiler and flags +CC = gcc +CXX = g++ + +WARN_FLAGS = -Wall +OPT_FLAGS = -O3 -g -fomit-frame-pointer -pipe +PIC_FLAGS = -fPIC + +ARCH_FLAGS ?= + +DEFINES = -D_REENTRANT -DUSE_XSHM + +MESA_ASM_SOURCES = $(SPARC_SOURCES) +GLAPI_ASM_SOURCES = $(SPARC_API) +ASM_FLAGS = -DUSE_SPARC_ASM + +CFLAGS = $(WARN_FLAGS) $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(DEFINES) \ + $(ASM_FLAGS) -std=c99 -ffast-math -I/usr/openwin/include + +CXXFLAGS = $(WARN_FLAGS) $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(DEFINES) \ + -I/usr/openwin/include + +GLUT_CFLAGS = -fexceptions -DSOLARIS_2_4_BUG + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +# Library/program dependencies +EXTRA_LIB_PATH=-L/usr/openwin/lib + +GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lXmu -lXi -lm +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lm +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -lX11 -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm diff --git a/configs/sunos5-smp b/configs/sunos5-smp new file mode 100644 index 0000000..2740805 --- /dev/null +++ b/configs/sunos5-smp @@ -0,0 +1,19 @@ +# Configuration for SunOS 5, SMP systems + +include $(TOP)/configs/default + +CONFIG_NAME = sunos5-smp + +# Compiler and flags +CC = cc +CXX = c++ +CFLAGS = -KPIC -Xa -native -fast -xO5 -xlibmil -xsafe=mem -xdepend -I/usr/openwin/include -I/usr/dt/include -DUSE_XSHM -DSOLARIS_2_4_BUG +CXXFLAGS = -KPIC -Xa -native -fast -xO5 -xlibmil -xsafe=mem -xdepend -I/usr/openwin/include -I/usr/dt/include +GLUT_CFLAGS = -DSOLARIS_2_4_BUG + +GL_LIB_DEPS = -L/usr/openwin/lib -lX11 -lXext -lXmu -lXi -lm +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lm +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L/usr/openwin/lib -lXt -lX11 +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -lX11 -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm -lCrun + diff --git a/configs/sunos5-v8 b/configs/sunos5-v8 new file mode 100644 index 0000000..cdaf3ee --- /dev/null +++ b/configs/sunos5-v8 @@ -0,0 +1,18 @@ +# Configuration for SunOS 5 + +include $(TOP)/configs/default + +CONFIG_NAME = sunos5-v8 + +# Compiler and flags +CC = cc +CXX = CC +CFLAGS = -xarch=v8 -KPIC -O -I/usr/openwin/include -I/usr/dt/include -DUSE_XSHM -DPTHREADS +CXXFLAGS = -xarch=v8 -KPIC -O -I/usr/openwin/include -I/usr/dt/include -DPTHREADS +GLUT_CFLAGS = -DSOLARIS_2_4_BUG + +GL_LIB_DEPS = -L/usr/openwin/lib -L/usr/dt/lib -lX11 -lXext -lXmu -lXi -lm -lpthread +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm -lCstd -lCrun +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lm +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L/usr/openwin/lib -lXt -lX11 +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -lX11 -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm diff --git a/configs/sunos5-v8-static b/configs/sunos5-v8-static new file mode 100644 index 0000000..5e428b1 --- /dev/null +++ b/configs/sunos5-v8-static @@ -0,0 +1,16 @@ +# Configuration for SunOS 5 + +include $(TOP)/configs/default + +CONFIG_NAME = sunos5-v8-static + +MKLIB_OPTIONS = -static + +# Compiler and flags +CC = cc +CXX = CC +CFLAGS = -xarch=v8 -KPIC -O -I/usr/openwin/include -I/usr/dt/include -DUSE_XSHM -DPTHREADS +CXXFLAGS = -xarch=v8 -KPIC -O -I/usr/openwin/include -I/usr/dt/include -DPTHREADS +GLUT_CFLAGS = -DSOLARIS_2_4_BUG + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/openwin/lib -lXt -lX11 -lXext -lXmu -lXi -lpthread -lm -lCstd -lCrun diff --git a/configs/sunos5-v9 b/configs/sunos5-v9 new file mode 100644 index 0000000..ea2ab23 --- /dev/null +++ b/configs/sunos5-v9 @@ -0,0 +1,23 @@ +# Configuration for SunOS 5, SPARC V9 + +include $(TOP)/configs/default + +CONFIG_NAME = sunos5-v9 + +MKLIB_OPTIONS = -cplusplus + +LIB_DIR = lib64 + +# Compiler and flags +CC = cc +CXX = CC +CFLAGS = -xarch=v9 -KPIC -O -I/usr/openwin/include -I/usr/dt/include -DUSE_XSHM -DPTHREADS +CXXFLAGS = -xarch=v9 -KPIC -O -I/usr/openwin/include -I/usr/dt/include -DPTHREADS +GLUT_CFLAGS = -DSOLARIS_2_4_BUG + +GL_LIB_DEPS = -L/usr/openwin/lib -L/usr/dt/lib -lX11 -lXext -lXmu -lXi -lm -lpthread +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm -lCstd -lCrun +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lm +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L/usr/openwin/lib -lXt -lX11 +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -lX11 -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm + diff --git a/configs/sunos5-v9-cc-g++ b/configs/sunos5-v9-cc-g++ new file mode 100644 index 0000000..8656251 --- /dev/null +++ b/configs/sunos5-v9-cc-g++ @@ -0,0 +1,35 @@ +# Configuration for SunOS 5, SPARC V9 and cc/g++ (for C and C++ sources) + +include $(TOP)/configs/default + +CONFIG_NAME = sunos5-v9-cc-g++ + +MKLIB_OPTIONS = -cplusplus + +LIB_DIR = lib64 + +# Compiler and flags +CC = cc +CXX = g++ + +CXX_WARN_FLAGS = -Wall +CXX_PIC_FLAGS = -fPIC +CXX_OPT_FLAGS = -O3 -m64 -mcpu=ultrasparc -mv8plus -mvis -g -fomit-frame-pointer -pipe +CXX_ARCH_FLAGS = -m64 + + +CXXFLAGS = $(CXX_WARN_FLAGS) $(CXX_OPT_FLAGS) $(CXX_PIC_FLAGS) $(CXX_ARCH_FLAGS) $(DEFINES) \ + -I/usr/openwin/include + +# Work around aliasing bugs - developers should comment this out +CXXFLAGS += -fno-strict-aliasing + +CFLAGS = -xarch=v9 -KPIC -O -I/usr/openwin/include -I/usr/dt/include -DUSE_XSHM -DPTHREADS +#CXXFLAGS = -xarch=v9 -KPIC -O -I/usr/openwin/include -I/usr/dt/include -DPTHREADS +GLUT_CFLAGS = -DSOLARIS_2_4_BUG + +GL_LIB_DEPS = -L/usr/openwin/lib -L/usr/dt/lib -lX11 -lXext -lXmu -lXi -lm -lpthread +GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -lm -lCstd -lCrun +GLUT_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLU_LIB) -l$(GL_LIB) -lm +GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L/usr/openwin/lib -lXt -lX11 +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -lX11 -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lm diff --git a/configs/sunos5-v9-static b/configs/sunos5-v9-static new file mode 100644 index 0000000..4919570 --- /dev/null +++ b/configs/sunos5-v9-static @@ -0,0 +1,18 @@ +# Configuration for SunOS 5, SPARC V9, static libs + +include $(TOP)/configs/default + +CONFIG_NAME = sunos5-v9-static + +MKLIB_OPTIONS = -static -cplusplus + +LIB_DIR = lib64 + +# Compiler and flags +CC = cc +CXX = CC +CFLAGS = -xarch=v9 -KPIC -O -I/usr/openwin/include -I/usr/dt/include -DUSE_XSHM -DPTHREADS +CXXFLAGS = -xarch=v9 -KPIC -O -I/usr/openwin/include -I/usr/dt/include -DPTHREADS +GLUT_CFLAGS = -DSOLARIS_2_4_BUG + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -L/usr/openwin/lib -lXt -lX11 -lXext -lXmu -lXi -lpthread -lm -lCstd -lCrun diff --git a/configs/ultrix-gcc b/configs/ultrix-gcc new file mode 100644 index 0000000..455b693 --- /dev/null +++ b/configs/ultrix-gcc @@ -0,0 +1,25 @@ +# Configuration for Ultrix, with gcc + +include $(TOP)/configs/default + +CONFIG_NAME = ultrix-gcc + +# Compiler and flags +CC = gcc +CXX = g++ +CFLAGS = -pedantic -O2 +CXXFLAGS = -pedantic -O2 +GLUT_CFLAGS = -fexceptions +MKLIB_OPTIONS = -static + +# Work around aliasing bugs - developers should comment this out +CFLAGS += -fno-strict-aliasing +CXXFLAGS += -fno-strict-aliasing + +GL_LIB_NAME = libGL.a +GLU_LIB_NAME = libGLU.a +GLUT_LIB_NAME = libglut.a +GLW_LIB_NAME = libGLw.a +OSMESA_LIB_NAME = libOSMesa.a + +APP_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) -lXmu -lX11 -lXi -lm diff --git a/configure b/configure new file mode 100755 index 0000000..8c54de1 --- /dev/null +++ b/configure @@ -0,0 +1,10663 @@ +#! /bin/sh +# Guess values for system-dependent variables and create Makefiles. +# Generated by GNU Autoconf 2.66 for Mesa 7.10.0. +# +# Report bugs to . +# +# +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software +# Foundation, Inc. +# +# +# This configure script is free software; the Free Software Foundation +# gives unlimited permission to copy, distribute and modify it. +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in #( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in #(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +if test "x$CONFIG_SHELL" = x; then + as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi +" + as_required="as_fn_return () { (exit \$1); } +as_fn_success () { as_fn_return 0; } +as_fn_failure () { as_fn_return 1; } +as_fn_ret_success () { return 0; } +as_fn_ret_failure () { return 1; } + +exitcode=0 +as_fn_success || { exitcode=1; echo as_fn_success failed.; } +as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } +as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } +as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } +if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : + +else + exitcode=1; echo positional parameters were not saved. +fi +test x\$exitcode = x0 || exit 1" + as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO + as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO + eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && + test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 +test \$(( 1 + 1 )) = 2 || exit 1" + if (eval "$as_required") 2>/dev/null; then : + as_have_required=yes +else + as_have_required=no +fi + if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : + +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +as_found=false +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + as_found=: + case $as_dir in #( + /*) + for as_base in sh bash ksh sh5; do + # Try only shells that exist, to save several forks. + as_shell=$as_dir/$as_base + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : + CONFIG_SHELL=$as_shell as_have_required=yes + if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : + break 2 +fi +fi + done;; + esac + as_found=false +done +$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : + CONFIG_SHELL=$SHELL as_have_required=yes +fi; } +IFS=$as_save_IFS + + + if test "x$CONFIG_SHELL" != x; then : + # We cannot yet assume a decent shell, so we have to provide a + # neutralization value for shells without unset; and this also + # works around shells that cannot unset nonexistent variables. + BASH_ENV=/dev/null + ENV=/dev/null + (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV + export CONFIG_SHELL + exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"} +fi + + if test x$as_have_required = xno; then : + $as_echo "$0: This script requires a shell more modern than all" + $as_echo "$0: the shells that I found on your system." + if test x${ZSH_VERSION+set} = xset ; then + $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" + $as_echo "$0: be upgraded to zsh 4.3.4 or later." + else + $as_echo "$0: Please tell bug-autoconf@gnu.org and +$0: https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa +$0: about your system, including any error possibly output +$0: before this message. Then install a modern shell, or +$0: manually run the script under such a shell if you do +$0: have one." + fi + exit 1 +fi +fi +fi +SHELL=${CONFIG_SHELL-/bin/sh} +export SHELL +# Unset more variables known to interfere with behavior of common tools. +CLICOLOR_FORCE= GREP_OPTIONS= +unset CLICOLOR_FORCE GREP_OPTIONS + +## --------------------- ## +## M4sh Shell Functions. ## +## --------------------- ## +# as_fn_unset VAR +# --------------- +# Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset + +# as_fn_set_status STATUS +# ----------------------- +# Set $? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} # as_fn_set_status + +# as_fn_exit STATUS +# ----------------- +# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} # as_fn_exit + +# as_fn_mkdir_p +# ------------- +# Create "$as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" + + +} # as_fn_mkdir_p +# as_fn_append VAR VALUE +# ---------------------- +# Append the text in VALUE to the end of the definition contained in VAR. Take +# advantage of any shell optimizations that allow amortized linear growth over +# repeated appends, instead of the typical quadratic growth present in naive +# implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +# as_fn_arith ARG... +# ------------------ +# Perform arithmetic evaluation on the ARGs, and store the result in the +# global $as_val. Take advantage of shells that can avoid forks. The arguments +# must be portable across $(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +# as_fn_error STATUS ERROR [LINENO LOG_FD] +# ---------------------------------------- +# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are +# provided, also output the error to LOG_FD, referencing LINENO. Then exit the +# script with STATUS, using 1 if that was 0. +as_fn_error () +{ + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + fi + $as_echo "$as_me: error: $2" >&2 + as_fn_exit $as_status +} # as_fn_error + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + + + as_lineno_1=$LINENO as_lineno_1a=$LINENO + as_lineno_2=$LINENO as_lineno_2a=$LINENO + eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && + test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { + # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in #((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -p' + fi +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +test -n "$DJDIR" || exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# +ac_default_prefix=/usr/local +ac_clean_files= +ac_config_libobj_dir=. +LIBOBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= + +# Identity of this package. +PACKAGE_NAME='Mesa' +PACKAGE_TARNAME='mesa' +PACKAGE_VERSION='7.10.0' +PACKAGE_STRING='Mesa 7.10.0' +PACKAGE_BUGREPORT='https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa' +PACKAGE_URL='' + +# Factoring default headers for most tests. +ac_includes_default="\ +#include +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef STDC_HEADERS +# include +# include +#else +# ifdef HAVE_STDLIB_H +# include +# endif +#endif +#ifdef HAVE_STRING_H +# if !defined STDC_HEADERS && defined HAVE_MEMORY_H +# include +# endif +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +#ifdef HAVE_INTTYPES_H +# include +#endif +#ifdef HAVE_STDINT_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif" + +ac_subst_vars='LTLIBOBJS +LIBOBJS +XORG_DRIVER_INSTALL_DIR +EGL_DRIVER_INSTALL_DIR +EGL_PLATFORMS +XEXT_LIBS +XEXT_CFLAGS +EGL_CLIENT_APIS +VG_LIB_DEPS +LIBKMS_XORG_LIBS +LIBKMS_XORG_CFLAGS +LIBDRM_XORG_LIBS +LIBDRM_XORG_CFLAGS +XORG_LIBS +XORG_CFLAGS +LLVM_VERSION +LLVM_LDFLAGS +LLVM_LIBS +LLVM_CFLAGS +LLVM_CONFIG +PROGRAM_DIRS +APP_LIB_DEPS +GLUT_PC_CFLAGS +GLUT_PC_LIB_PRIV +GLUT_PC_REQ_PRIV +GLUT_MESA_DEPS +GLUT_LIB_DEPS +GLUT_LIBS +GLUT_CFLAGS +GLW_PC_CFLAGS +GLW_PC_LIB_PRIV +GLW_PC_REQ_PRIV +MOTIF_CFLAGS +GLW_SOURCES +GLW_MESA_DEPS +GLW_LIB_DEPS +MOTIF_CONFIG +GLW_LIBS +GLW_CFLAGS +GLU_PC_CFLAGS +GLU_PC_LIB_PRIV +GLU_PC_REQ_PRIV +GLU_PC_REQ +GLU_MESA_DEPS +GLU_LIB_DEPS +EGL_DRIVERS_DIRS +EGL_LIB_DEPS +LIBUDEV_LIBS +LIBUDEV_CFLAGS +XCB_DRI2_LIBS +XCB_DRI2_CFLAGS +OSMESA_PC_LIB_PRIV +OSMESA_PC_REQ +OSMESA_MESA_DEPS +OSMESA_LIB_DEPS +OSMESA_LIB +RADEON_LDFLAGS +RADEON_CFLAGS +INTEL_LIBS +INTEL_CFLAGS +DRI_LIB_DEPS +EXPAT_INCLUDES +DRI_DIRS +DRI_DRIVER_SEARCH_DIR +DRI_DRIVER_INSTALL_DIR +LIBDRM_RADEON_LIBS +LIBDRM_RADEON_CFLAGS +HAVE_XF86VIDMODE +GLESv2_PC_LIB_PRIV +GLESv2_LIB_DEPS +GLESv1_CM_PC_LIB_PRIV +GLESv1_CM_LIB_DEPS +DRI_PC_REQ_PRIV +GL_PC_CFLAGS +GL_PC_LIB_PRIV +GL_PC_REQ_PRIV +GL_LIB_DEPS +XCB_LIBS +XCB_CFLAGS +DRIGL_LIBS +DRIGL_CFLAGS +XF86VIDMODE_LIBS +XF86VIDMODE_CFLAGS +GLPROTO_LIBS +GLPROTO_CFLAGS +DRI2PROTO_LIBS +DRI2PROTO_CFLAGS +LIBDRM_LIBS +LIBDRM_CFLAGS +XLIBGL_LIBS +XLIBGL_CFLAGS +X_EXTRA_LIBS +X_LIBS +X_PRE_LIBS +X_CFLAGS +XMKMF +X11_LIBS +X11_CFLAGS +MESA_LLVM +GALLIUM_STATE_TRACKERS_DIRS +GALLIUM_DRIVERS_DIRS +GALLIUM_WINSYS_DIRS +GALLIUM_TARGET_DIRS +GALLIUM_DIRS +DRIVER_DIRS +GLU_DIRS +SRC_DIRS +GLES_OVERLAY +API_DEFINES +EGREP +GREP +DLOPEN_LIBS +PIC_FLAGS +GLAPI_ASM_SOURCES +MESA_ASM_SOURCES +ASM_FLAGS +VG_LIB_GLOB +GLESv2_LIB_GLOB +GLESv1_CM_LIB_GLOB +EGL_LIB_GLOB +OSMESA_LIB_GLOB +GLW_LIB_GLOB +GLUT_LIB_GLOB +GLU_LIB_GLOB +GL_LIB_GLOB +VG_LIB_NAME +GLESv2_LIB_NAME +GLESv1_CM_LIB_NAME +EGL_LIB_NAME +OSMESA_LIB_NAME +GLW_LIB_NAME +GLUT_LIB_NAME +GLU_LIB_NAME +GL_LIB_NAME +MKLIB_OPTIONS +ARCH_FLAGS +OPT_FLAGS +DEFINES +X11_INCLUDES +EXTRA_LIB_PATH +LIB_DIR +PKG_CONFIG_LIBDIR +PKG_CONFIG_PATH +PKG_CONFIG +MKDEP_OPTIONS +POSIX_SHELL +INSTALL_DATA +INSTALL_SCRIPT +INSTALL_PROGRAM +SED +MKDEP +PYTHON2 +MAKE +ac_ct_CXX +CXXFLAGS +CXX +CPP +OBJEXT +EXEEXT +ac_ct_CC +CPPFLAGS +LDFLAGS +CFLAGS +CC +host_os +host_vendor +host_cpu +host +build_os +build_vendor +build_cpu +build +target_alias +host_alias +build_alias +LIBS +ECHO_T +ECHO_N +ECHO_C +DEFS +mandir +localedir +libdir +psdir +pdfdir +dvidir +htmldir +infodir +docdir +oldincludedir +includedir +localstatedir +sharedstatedir +sysconfdir +datadir +datarootdir +libexecdir +sbindir +bindir +program_transform_name +prefix +exec_prefix +PACKAGE_URL +PACKAGE_BUGREPORT +PACKAGE_STRING +PACKAGE_VERSION +PACKAGE_TARNAME +PACKAGE_NAME +PATH_SEPARATOR +SHELL' +ac_subst_files='' +ac_user_opts=' +enable_option_checking +enable_32_bit +enable_64_bit +enable_static +enable_shared +enable_debug +enable_asm +enable_pic +enable_selinux +enable_opengl +enable_gles1 +enable_gles2 +enable_gles_overlay +enable_openvg +with_driver +with_x +enable_xcb +enable_glx_tls +with_dri_driverdir +with_dri_searchpath +enable_driglx_direct +with_dri_drivers +with_expat +enable_gl_osmesa +with_osmesa_bits +enable_egl +enable_glu +enable_glw +enable_motif +enable_glut +enable_gallium +enable_gallium_egl +with_state_trackers +with_egl_platforms +with_egl_displays +with_egl_driver_dir +with_xorg_driver_dir +with_max_width +with_max_height +enable_gallium_llvm +enable_gallium_svga +enable_gallium_i915 +enable_gallium_i965 +enable_gallium_radeon +enable_gallium_r600 +enable_gallium_nouveau +enable_gallium_swrast +enable_gallium_noop +' + ac_precious_vars='build_alias +host_alias +target_alias +CC +CFLAGS +LDFLAGS +LIBS +CPPFLAGS +CPP +CXX +CXXFLAGS +CCC +PKG_CONFIG +PKG_CONFIG_PATH +PKG_CONFIG_LIBDIR +EXTRA_LIB_PATH +X11_INCLUDES +OPT_FLAGS +ARCH_FLAGS +MKLIB_OPTIONS +PIC_FLAGS +X11_CFLAGS +X11_LIBS +XMKMF +XLIBGL_CFLAGS +XLIBGL_LIBS +LIBDRM_CFLAGS +LIBDRM_LIBS +DRI2PROTO_CFLAGS +DRI2PROTO_LIBS +GLPROTO_CFLAGS +GLPROTO_LIBS +XF86VIDMODE_CFLAGS +XF86VIDMODE_LIBS +DRIGL_CFLAGS +DRIGL_LIBS +XCB_CFLAGS +XCB_LIBS +LIBDRM_RADEON_CFLAGS +LIBDRM_RADEON_LIBS +INTEL_CFLAGS +INTEL_LIBS +XCB_DRI2_CFLAGS +XCB_DRI2_LIBS +LIBUDEV_CFLAGS +LIBUDEV_LIBS +GLW_CFLAGS +GLW_LIBS +GLUT_CFLAGS +GLUT_LIBS +XORG_CFLAGS +XORG_LIBS +LIBDRM_XORG_CFLAGS +LIBDRM_XORG_LIBS +LIBKMS_XORG_CFLAGS +LIBKMS_XORG_LIBS +XEXT_CFLAGS +XEXT_LIBS' + + +# Initialize some variables set by options. +ac_init_help= +ac_init_version=false +ac_unrecognized_opts= +ac_unrecognized_sep= +# The variables have the same names as the options, with +# dashes changed to underlines. +cache_file=/dev/null +exec_prefix=NONE +no_create= +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, +silent= +site= +srcdir= +verbose= +x_includes=NONE +x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) +bindir='${exec_prefix}/bin' +sbindir='${exec_prefix}/sbin' +libexecdir='${exec_prefix}/libexec' +datarootdir='${prefix}/share' +datadir='${datarootdir}' +sysconfdir='${prefix}/etc' +sharedstatedir='${prefix}/com' +localstatedir='${prefix}/var' +includedir='${prefix}/include' +oldincludedir='/usr/include' +docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' + +ac_prev= +ac_dashdash= +for ac_option +do + # If the previous option needs an argument, assign it. + if test -n "$ac_prev"; then + eval $ac_prev=\$ac_option + ac_prev= + continue + fi + + case $ac_option in + *=*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *) ac_optarg=yes ;; + esac + + # Accept the important Cygnus configure options, so we can diagnose typos. + + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; + + -bindir | --bindir | --bindi | --bind | --bin | --bi) + ac_prev=bindir ;; + -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) + bindir=$ac_optarg ;; + + -build | --build | --buil | --bui | --bu) + ac_prev=build_alias ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=*) + build_alias=$ac_optarg ;; + + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file=$ac_optarg ;; + + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) + ac_prev=datadir ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; + + -disable-* | --disable-*) + ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; + + -enable-* | --enable-*) + ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=\$ac_optarg ;; + + -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ + | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ + | --exec | --exe | --ex) + ac_prev=exec_prefix ;; + -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ + | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ + | --exec=* | --exe=* | --ex=*) + exec_prefix=$ac_optarg ;; + + -gas | --gas | --ga | --g) + # Obsolete; use --with-gas. + with_gas=yes ;; + + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; + + -host | --host | --hos | --ho) + ac_prev=host_alias ;; + -host=* | --host=* | --hos=* | --ho=*) + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; + + -includedir | --includedir | --includedi | --included | --include \ + | --includ | --inclu | --incl | --inc) + ac_prev=includedir ;; + -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ + | --includ=* | --inclu=* | --incl=* | --inc=*) + includedir=$ac_optarg ;; + + -infodir | --infodir | --infodi | --infod | --info | --inf) + ac_prev=infodir ;; + -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) + infodir=$ac_optarg ;; + + -libdir | --libdir | --libdi | --libd) + ac_prev=libdir ;; + -libdir=* | --libdir=* | --libdi=* | --libd=*) + libdir=$ac_optarg ;; + + -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ + | --libexe | --libex | --libe) + ac_prev=libexecdir ;; + -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ + | --libexe=* | --libex=* | --libe=*) + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; + + -localstatedir | --localstatedir | --localstatedi | --localstated \ + | --localstate | --localstat | --localsta | --localst | --locals) + ac_prev=localstatedir ;; + -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; + + -mandir | --mandir | --mandi | --mand | --man | --ma | --m) + ac_prev=mandir ;; + -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) + mandir=$ac_optarg ;; + + -nfp | --nfp | --nf) + # Obsolete; use --without-fp. + with_fp=no ;; + + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c | -n) + no_create=yes ;; + + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; + + -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ + | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ + | --oldin | --oldi | --old | --ol | --o) + ac_prev=oldincludedir ;; + -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ + | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ + | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) + oldincludedir=$ac_optarg ;; + + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix=$ac_optarg ;; + + -program-prefix | --program-prefix | --program-prefi | --program-pref \ + | --program-pre | --program-pr | --program-p) + ac_prev=program_prefix ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) + program_prefix=$ac_optarg ;; + + -program-suffix | --program-suffix | --program-suffi | --program-suff \ + | --program-suf | --program-su | --program-s) + ac_prev=program_suffix ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) + program_suffix=$ac_optarg ;; + + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- \ + | --program-transform | --program-transfor \ + | --program-transfo | --program-transf \ + | --program-trans | --program-tran \ + | --progr-tra | --program-tr | --program-t) + ac_prev=program_transform_name ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* \ + | --program-transfo=* | --program-transf=* \ + | --program-trans=* | --program-tran=* \ + | --progr-tra=* | --program-tr=* | --program-t=*) + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; + + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + silent=yes ;; + + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) + ac_prev=sbindir ;; + -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ + | --sbi=* | --sb=*) + sbindir=$ac_optarg ;; + + -sharedstatedir | --sharedstatedir | --sharedstatedi \ + | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ + | --sharedst | --shareds | --shared | --share | --shar \ + | --sha | --sh) + ac_prev=sharedstatedir ;; + -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ + | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ + | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ + | --sha=* | --sh=*) + sharedstatedir=$ac_optarg ;; + + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site=$ac_optarg ;; + + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir=$ac_optarg ;; + + -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ + | --syscon | --sysco | --sysc | --sys | --sy) + ac_prev=sysconfdir ;; + -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ + | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) + sysconfdir=$ac_optarg ;; + + -target | --target | --targe | --targ | --tar | --ta | --t) + ac_prev=target_alias ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target_alias=$ac_optarg ;; + + -v | -verbose | --verbose | --verbos | --verbo | --verb) + verbose=yes ;; + + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; + + -with-* | --with-*) + ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=\$ac_optarg ;; + + -without-* | --without-*) + ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=no ;; + + --x) + # Obsolete; use --with-x. + with_x=yes ;; + + -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ + | --x-incl | --x-inc | --x-in | --x-i) + ac_prev=x_includes ;; + -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ + | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) + x_includes=$ac_optarg ;; + + -x-libraries | --x-libraries | --x-librarie | --x-librari \ + | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) + ac_prev=x_libraries ;; + -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ + | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) + x_libraries=$ac_optarg ;; + + -*) as_fn_error $? "unrecognized option: \`$ac_option' +Try \`$0 --help' for more information" + ;; + + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + case $ac_envvar in #( + '' | [0-9]* | *[!_$as_cr_alnum]* ) + as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; + esac + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + + *) + # FIXME: should be removed in autoconf 3.0. + $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} + ;; + + esac +done + +if test -n "$ac_prev"; then + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + as_fn_error $? "missing argument to $ac_option" +fi + +if test -n "$ac_unrecognized_opts"; then + case $enable_option_checking in + no) ;; + fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; + *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; + esac +fi + +# Check all directory arguments for consistency. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir +do + eval ac_val=\$$ac_var + # Remove trailing slashes. + case $ac_val in + */ ) + ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` + eval $ac_var=\$ac_val;; + esac + # Be sure to have absolute directory names. + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; + esac + as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" +done + +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias + +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used" >&2 + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + as_fn_error $? "working directory cannot be determined" +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + as_fn_error $? "pwd does not report name of working directory" + + +# Find the source files, if location was not specified. +if test -z "$srcdir"; then + ac_srcdir_defaulted=yes + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$as_myself" || +$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_myself" : 'X\(//\)[^/]' \| \ + X"$as_myself" : 'X\(//\)$' \| \ + X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_myself" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + srcdir=$ac_confdir + if test ! -r "$srcdir/$ac_unique_file"; then + srcdir=.. + fi +else + ac_srcdir_defaulted=no +fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" +fi +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done + +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures Mesa 7.10.0 to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking ...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root [DATAROOTDIR/doc/mesa] + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF + +X features: + --x-includes=DIR X include files are in DIR + --x-libraries=DIR X library files are in DIR +These options are only used when the X libraries cannot be found by the +pkg-config utility. + +System types: + --build=BUILD configure for building on BUILD [guessed] + --host=HOST cross-compile to build programs to run on HOST [BUILD] +_ACEOF +fi + +if test -n "$ac_init_help"; then + case $ac_init_help in + short | recursive ) echo "Configuration of Mesa 7.10.0:";; + esac + cat <<\_ACEOF + +Optional Features: + --disable-option-checking ignore unrecognized --enable/--with options + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --enable-32-bit build 32-bit libraries [default=auto] + --enable-64-bit build 64-bit libraries [default=auto] + --enable-static build static libraries [default=disabled] + --disable-shared build shared libraries [default=enabled] + --enable-debug use debug compiler flags and macros + [default=disabled] + --disable-asm disable assembly usage [default=enabled on supported + plaforms] + --disable-pic compile PIC objects [default=enabled for shared + builds on supported platforms] + --enable-selinux Build SELinux-aware Mesa [default=disabled] + --disable-opengl disable support for standard OpenGL API [default=no] + --enable-gles1 enable support for OpenGL ES 1.x API [default=no] + --enable-gles2 enable support for OpenGL ES 2.x API [default=no] + --enable-gles-overlay build separate OpenGL ES only libraries [default=no] + --enable-openvg enable support for OpenVG API [default=no] + --enable-xcb use XCB for GLX [default=disabled] + --enable-glx-tls enable TLS support in GLX [default=disabled] + --disable-driglx-direct enable direct rendering in GLX and EGL for DRI + [default=enabled] + --enable-gl-osmesa enable OSMesa with libGL [default=enabled for xlib + driver] + --disable-egl disable EGL library [default=enabled] + --disable-glu enable OpenGL Utility library [default=enabled] + --disable-glw enable Xt/Motif widget library [default=enabled] + --enable-motif use Motif widgets in GLw [default=disabled] + --disable-glut enable GLUT library [default=enabled if source + available] + --disable-gallium build gallium [default=enabled] + --enable-gallium-egl enable gallium EGL state tracker [default=auto] + --enable-gallium-llvm build gallium LLVM support [default=disabled] + --enable-gallium-svga build gallium SVGA [default=disabled] + --enable-gallium-i915 build gallium i915 [default=disabled] + --enable-gallium-i965 build gallium i965 [default=disabled] + --enable-gallium-radeon build gallium radeon [default=disabled] + --enable-gallium-r600 build gallium radeon [default=disabled] + --enable-gallium-nouveau + build gallium nouveau [default=disabled] + --enable-gallium-swrast build gallium swrast [default=auto] + --enable-gallium-noop build gallium radeon [default=disabled] + +Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --with-driver=DRIVER driver for Mesa: xlib,dri,osmesa [default=dri when + available, or xlib] + --with-x use the X Window System + --with-dri-driverdir=DIR + directory for the DRI drivers [${libdir}/dri] + --with-dri-searchpath=DIRS... + semicolon delimited DRI driver search directories + [${libdir}/dri] + --with-dri-drivers[=DIRS...] + comma delimited DRI drivers list, e.g. + "swrast,i965,radeon" [default=auto] + --with-expat=DIR expat install directory + --with-osmesa-bits=BITS OSMesa channel bits and library name: 8, 16, 32 + [default=8] + --with-state-trackers[=DIRS...] + comma delimited state_trackers list, e.g. "egl,glx" + [default=auto] + --with-egl-platforms[=DIRS...] + comma delimited native platforms libEGL supports, + e.g. "x11,drm" [default=auto] + --with-egl-displays[=DIRS...] + DEPRECATED. Use --with-egl-platforms instead + --with-egl-driver-dir=DIR + directory for EGL drivers [[default=${libdir}/egl]] + --with-xorg-driver-dir=DIR + Default xorg driver + directory[[default=${libdir}/xorg/modules/drivers]] + --with-max-width=N Maximum framebuffer width (4096) + --with-max-height=N Maximum framebuffer height (4096) + +Some influential environment variables: + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + LIBS libraries to pass to the linker, e.g. -l + CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if + you have headers in a nonstandard directory + CPP C preprocessor + CXX C++ compiler command + CXXFLAGS C++ compiler flags + PKG_CONFIG path to pkg-config utility + PKG_CONFIG_PATH + directories to add to pkg-config's search path + PKG_CONFIG_LIBDIR + path overriding pkg-config's built-in search path + EXTRA_LIB_PATH + Extra -L paths for the linker + X11_INCLUDES + Extra -I paths for X11 headers + OPT_FLAGS Additional optimization flags for the compiler. Default is to + use CFLAGS. + ARCH_FLAGS Additional architecture specific flags for the compiler. Default + is to use CFLAGS. + MKLIB_OPTIONS + Options for the Mesa library script, mklib + PIC_FLAGS compiler flags for PIC code + X11_CFLAGS C compiler flags for X11, overriding pkg-config + X11_LIBS linker flags for X11, overriding pkg-config + XMKMF Path to xmkmf, Makefile generator for X Window System + XLIBGL_CFLAGS + C compiler flags for XLIBGL, overriding pkg-config + XLIBGL_LIBS linker flags for XLIBGL, overriding pkg-config + LIBDRM_CFLAGS + C compiler flags for LIBDRM, overriding pkg-config + LIBDRM_LIBS linker flags for LIBDRM, overriding pkg-config + DRI2PROTO_CFLAGS + C compiler flags for DRI2PROTO, overriding pkg-config + DRI2PROTO_LIBS + linker flags for DRI2PROTO, overriding pkg-config + GLPROTO_CFLAGS + C compiler flags for GLPROTO, overriding pkg-config + GLPROTO_LIBS + linker flags for GLPROTO, overriding pkg-config + XF86VIDMODE_CFLAGS + C compiler flags for XF86VIDMODE, overriding pkg-config + XF86VIDMODE_LIBS + linker flags for XF86VIDMODE, overriding pkg-config + DRIGL_CFLAGS + C compiler flags for DRIGL, overriding pkg-config + DRIGL_LIBS linker flags for DRIGL, overriding pkg-config + XCB_CFLAGS C compiler flags for XCB, overriding pkg-config + XCB_LIBS linker flags for XCB, overriding pkg-config + LIBDRM_RADEON_CFLAGS + C compiler flags for LIBDRM_RADEON, overriding pkg-config + LIBDRM_RADEON_LIBS + linker flags for LIBDRM_RADEON, overriding pkg-config + INTEL_CFLAGS + C compiler flags for INTEL, overriding pkg-config + INTEL_LIBS linker flags for INTEL, overriding pkg-config + XCB_DRI2_CFLAGS + C compiler flags for XCB_DRI2, overriding pkg-config + XCB_DRI2_LIBS + linker flags for XCB_DRI2, overriding pkg-config + LIBUDEV_CFLAGS + C compiler flags for LIBUDEV, overriding pkg-config + LIBUDEV_LIBS + linker flags for LIBUDEV, overriding pkg-config + GLW_CFLAGS C compiler flags for GLW, overriding pkg-config + GLW_LIBS linker flags for GLW, overriding pkg-config + GLUT_CFLAGS C compiler flags for GLUT, overriding pkg-config + GLUT_LIBS linker flags for GLUT, overriding pkg-config + XORG_CFLAGS C compiler flags for XORG, overriding pkg-config + XORG_LIBS linker flags for XORG, overriding pkg-config + LIBDRM_XORG_CFLAGS + C compiler flags for LIBDRM_XORG, overriding pkg-config + LIBDRM_XORG_LIBS + linker flags for LIBDRM_XORG, overriding pkg-config + LIBKMS_XORG_CFLAGS + C compiler flags for LIBKMS_XORG, overriding pkg-config + LIBKMS_XORG_LIBS + linker flags for LIBKMS_XORG, overriding pkg-config + XEXT_CFLAGS C compiler flags for XEXT, overriding pkg-config + XEXT_LIBS linker flags for XEXT, overriding pkg-config + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +See docs/autoconf.html for more details on the options for Mesa. + +Report bugs to . +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || + { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || + continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for guested configure. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +Mesa configure 7.10.0 +generated by GNU Autoconf 2.66 + +Copyright (C) 2010 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi + +## ------------------------ ## +## Autoconf initialization. ## +## ------------------------ ## + +# ac_fn_c_try_compile LINENO +# -------------------------- +# Try to compile conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext + if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + as_fn_set_status $ac_retval + +} # ac_fn_c_try_compile + +# ac_fn_c_try_cpp LINENO +# ---------------------- +# Try to preprocess conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_cpp () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + as_fn_set_status $ac_retval + +} # ac_fn_c_try_cpp + +# ac_fn_cxx_try_compile LINENO +# ---------------------------- +# Try to compile conftest.$ac_ext, and return whether this succeeded. +ac_fn_cxx_try_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext + if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + as_fn_set_status $ac_retval + +} # ac_fn_cxx_try_compile + +# ac_fn_c_try_link LINENO +# ----------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + $as_test_x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + as_fn_set_status $ac_retval + +} # ac_fn_c_try_link + +# ac_fn_c_check_func LINENO FUNC VAR +# ---------------------------------- +# Tests whether FUNC exists, setting the cache variable VAR accordingly +ac_fn_c_check_func () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval "test \"\${$3+set}\"" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +/* Define $2 to an innocuous variant, in case declares $2. + For example, HP-UX 11i declares gettimeofday. */ +#define $2 innocuous_$2 + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $2 (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $2 + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $2 (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$2 || defined __stub___$2 +choke me +#endif + +int +main () +{ +return $2 (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + +} # ac_fn_c_check_func + +# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES +# ------------------------------------------------------- +# Tests whether HEADER exists, giving a warning if it cannot be compiled using +# the include files in INCLUDES and setting the cache variable VAR +# accordingly. +ac_fn_c_check_header_mongrel () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if eval "test \"\${$3+set}\"" = set; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval "test \"\${$3+set}\"" = set; then : + $as_echo_n "(cached) " >&6 +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +else + # Is the header compilable? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 +$as_echo_n "checking $2 usability... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +#include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_header_compiler=yes +else + ac_header_compiler=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 +$as_echo "$ac_header_compiler" >&6; } + +# Is the header present? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 +$as_echo_n "checking $2 presence... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <$2> +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + ac_header_preproc=yes +else + ac_header_preproc=no +fi +rm -f conftest.err conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 +$as_echo "$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( + yes:no: ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 +$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} + ;; + no:yes:* ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 +$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 +$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 +$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 +$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} +( $as_echo "## ---------------------------------------------------------------------- ## +## Report this to https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa ## +## ---------------------------------------------------------------------- ##" + ) | sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval "test \"\${$3+set}\"" = set; then : + $as_echo_n "(cached) " >&6 +else + eval "$3=\$ac_header_compiler" +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +fi + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + +} # ac_fn_c_check_header_mongrel + +# ac_fn_c_try_run LINENO +# ---------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes +# that executables *can* be run. +ac_fn_c_try_run () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then : + ac_retval=0 +else + $as_echo "$as_me: program exited with status $ac_status" >&5 + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=$ac_status +fi + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + as_fn_set_status $ac_retval + +} # ac_fn_c_try_run + +# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES +# ------------------------------------------------------- +# Tests whether HEADER exists and can be compiled using the include files in +# INCLUDES, setting the cache variable VAR accordingly. +ac_fn_c_check_header_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval "test \"\${$3+set}\"" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +#include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + +} # ac_fn_c_check_header_compile +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by Mesa $as_me 7.10.0, which was +generated by GNU Autoconf 2.66. Invocation command line was + + $ $0 $@ + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + $as_echo "PATH: $as_dir" + done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; + 2) + as_fn_append ac_configure_args1 " '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + as_fn_append ac_configure_args " '$ac_arg'" + ;; + esac + done +done +{ ac_configure_args0=; unset ac_configure_args0;} +{ ac_configure_args1=; unset ac_configure_args1;} + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + $as_echo "## ---------------- ## +## Cache variables. ## +## ---------------- ##" + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + $as_echo "## ----------------- ## +## Output variables. ## +## ----------------- ##" + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + $as_echo "## ------------------- ## +## File substitutions. ## +## ------------------- ##" + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + $as_echo "## ----------- ## +## confdefs.h. ## +## ----------- ##" + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + $as_echo "$as_me: caught signal $ac_signal" + $as_echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +$as_echo "/* confdefs.h */" > confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_URL "$PACKAGE_URL" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer an explicitly selected file to automatically selected ones. +ac_site_file1=NONE +ac_site_file2=NONE +if test -n "$CONFIG_SITE"; then + # We do not want a PATH search for config.site. + case $CONFIG_SITE in #(( + -*) ac_site_file1=./$CONFIG_SITE;; + */*) ac_site_file1=$CONFIG_SITE;; + *) ac_site_file1=./$CONFIG_SITE;; + esac +elif test "x$prefix" != xNONE; then + ac_site_file1=$prefix/share/config.site + ac_site_file2=$prefix/etc/config.site +else + ac_site_file1=$ac_default_prefix/share/config.site + ac_site_file2=$ac_default_prefix/etc/config.site +fi +for ac_site_file in "$ac_site_file1" "$ac_site_file2" +do + test "x$ac_site_file" = xNONE && continue + if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 +$as_echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 + . "$ac_site_file" \ + || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "failed to load site script $ac_site_file +See \`config.log' for more details" "$LINENO" 5; } + fi +done + +if test -r "$cache_file"; then + # Some versions of bash will fail to source /dev/null (special files + # actually), so we avoid doing that. DJGPP emulates it as a regular file. + if test /dev/null != "$cache_file" && test -f "$cache_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 +$as_echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac + fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 +$as_echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + # differences in whitespace do not lead to failure. + ac_old_val_w=`echo x $ac_old_val` + ac_new_val_w=`echo x $ac_new_val` + if test "$ac_old_val_w" != "$ac_new_val_w"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 +$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + ac_cache_corrupted=: + else + { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 +$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} + eval $ac_var=\$ac_old_val + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 +$as_echo "$as_me: former value: \`$ac_old_val'" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 +$as_echo "$as_me: current value: \`$ac_new_val'" >&2;} + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) as_fn_append ac_configure_args " '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 +$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} + as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 +fi +## -------------------- ## +## Main body of script. ## +## -------------------- ## + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +ac_aux_dir= +for ac_dir in bin "$srcdir"/bin; do + if test -f "$ac_dir/install-sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install-sh -c" + break + elif test -f "$ac_dir/install.sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install.sh -c" + break + elif test -f "$ac_dir/shtool"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/shtool install -c" + break + fi +done +if test -z "$ac_aux_dir"; then + as_fn_error $? "cannot find install-sh, install.sh, or shtool in bin \"$srcdir\"/bin" "$LINENO" 5 +fi + +# These three variables are undocumented and unsupported, +# and are intended to be withdrawn in a future Autoconf release. +# They can cause serious problems if a builder's source tree is in a directory +# whose full name contains unusual characters. +ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. +ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. +ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. + + +# Make sure we can run config.sub. +$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || + as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 +$as_echo_n "checking build system type... " >&6; } +if test "${ac_cv_build+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_build_alias=$build_alias +test "x$ac_build_alias" = x && + ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` +test "x$ac_build_alias" = x && + as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 +ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || + as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 +$as_echo "$ac_cv_build" >&6; } +case $ac_cv_build in +*-*-*) ;; +*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; +esac +build=$ac_cv_build +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_build +shift +build_cpu=$1 +build_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +build_os=$* +IFS=$ac_save_IFS +case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 +$as_echo_n "checking host system type... " >&6; } +if test "${ac_cv_host+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test "x$host_alias" = x; then + ac_cv_host=$ac_cv_build +else + ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || + as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 +$as_echo "$ac_cv_host" >&6; } +case $ac_cv_host in +*-*-*) ;; +*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; +esac +host=$ac_cv_host +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_host +shift +host_cpu=$1 +host_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +host_os=$* +IFS=$ac_save_IFS +case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac + + + +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 + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "no acceptable C compiler found in \$PATH +See \`config.log' for more details" "$LINENO" 5; } + +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 +$as_echo_n "checking whether the C compiler works... " >&6; } +ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` + +# The possible output files: +ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" + +ac_rmfiles= +for ac_file in $ac_files +do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + * ) ac_rmfiles="$ac_rmfiles $ac_file";; + esac +done +rm -f $ac_rmfiles + +if { { ac_try="$ac_link_default" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link_default") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. +# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' +# in a Makefile. We should not override ac_cv_exeext if it was cached, +# so that the user can short-circuit this test for compilers unknown to +# Autoconf. +for ac_file in $ac_files '' +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + then :; else + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + fi + # We set ac_cv_exeext here because the later test for it is not + # safe: cross compilers may not add the suffix if given an `-o' + # argument, so we may need to know it at that point already. + # Even if this section looks crufty: it has the advantage of + # actually working. + break;; + * ) + break;; + esac +done +test "$ac_cv_exeext" = no && ac_cv_exeext= + +else + ac_file='' +fi +if test -z "$ac_file"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +$as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "C compiler cannot create executables +See \`config.log' for more details" "$LINENO" 5; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 +$as_echo_n "checking for C compiler default output file name... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 +$as_echo "$ac_file" >&6; } +ac_exeext=$ac_cv_exeext + +rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out +ac_clean_files=$ac_clean_files_save +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 +$as_echo_n "checking for suffix of executables... " >&6; } +if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + break;; + * ) break;; + esac +done +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details" "$LINENO" 5; } +fi +rm -f conftest conftest$ac_cv_exeext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 +$as_echo "$ac_cv_exeext" >&6; } + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +FILE *f = fopen ("conftest.out", "w"); + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +ac_clean_files="$ac_clean_files conftest.out" +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 +$as_echo_n "checking whether we are cross compiling... " >&6; } +if test "$cross_compiling" != yes; then + { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if { ac_try='./conftest$ac_cv_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details" "$LINENO" 5; } + fi + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 +$as_echo "$cross_compiling" >&6; } + +rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out +ac_clean_files=$ac_clean_files_save +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 +$as_echo_n "checking for suffix of object files... " >&6; } +if test "${ac_cv_objext+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + for ac_file in conftest.o conftest.obj conftest.*; do + test -f "$ac_file" || continue; + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot compute suffix of object files: cannot compile +See \`config.log' for more details" "$LINENO" 5; } +fi +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 +$as_echo "$ac_cv_objext" >&6; } +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 +$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } +if test "${ac_cv_c_compiler_gnu+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +$as_echo "$ac_cv_c_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GCC=yes +else + GCC= +fi +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +$as_echo_n "checking whether $CC accepts -g... " >&6; } +if test "${ac_cv_prog_cc_g+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +else + CFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +$as_echo "$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 +$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } +if test "${ac_cv_prog_cc_c89+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_c89=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } ;; + xno) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; +esac +if test "x$ac_cv_prog_cc_c89" != xno; then : + +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 +$as_echo_n "checking how to run the C preprocessor... " >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi +if test -z "$CPP"; then + if test "${ac_cv_prog_CPP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 +$as_echo "$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details" "$LINENO" 5; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "no acceptable C compiler found in \$PATH +See \`config.log' for more details" "$LINENO" 5; } + +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 +$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } +if test "${ac_cv_c_compiler_gnu+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +$as_echo "$ac_cv_c_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GCC=yes +else + GCC= +fi +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +$as_echo_n "checking whether $CC accepts -g... " >&6; } +if test "${ac_cv_prog_cc_g+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +else + CFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +$as_echo "$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 +$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } +if test "${ac_cv_prog_cc_c89+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_c89=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } ;; + xno) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; +esac +if test "x$ac_cv_prog_cc_c89" != xno; then : + +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +if test -z "$CXX"; then + if test -n "$CCC"; then + CXX=$CCC + else + if test -n "$ac_tool_prefix"; then + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CXX+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CXX"; then + ac_cv_prog_CXX="$CXX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CXX=$ac_cv_prog_CXX +if test -n "$CXX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5 +$as_echo "$CXX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CXX" && break + done +fi +if test -z "$CXX"; then + ac_ct_CXX=$CXX + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_CXX+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CXX"; then + ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CXX="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CXX=$ac_cv_prog_ac_ct_CXX +if test -n "$ac_ct_CXX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5 +$as_echo "$ac_ct_CXX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CXX" && break +done + + if test "x$ac_ct_CXX" = x; then + CXX="g++" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CXX=$ac_ct_CXX + fi +fi + + fi +fi +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C++ compiler" >&5 +$as_echo_n "checking whether we are using the GNU C++ compiler... " >&6; } +if test "${ac_cv_cxx_compiler_gnu+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_cxx_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5 +$as_echo "$ac_cv_cxx_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GXX=yes +else + GXX= +fi +ac_test_CXXFLAGS=${CXXFLAGS+set} +ac_save_CXXFLAGS=$CXXFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5 +$as_echo_n "checking whether $CXX accepts -g... " >&6; } +if test "${ac_cv_prog_cxx_g+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_save_cxx_werror_flag=$ac_cxx_werror_flag + ac_cxx_werror_flag=yes + ac_cv_prog_cxx_g=no + CXXFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_cv_prog_cxx_g=yes +else + CXXFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + +else + ac_cxx_werror_flag=$ac_save_cxx_werror_flag + CXXFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_cv_prog_cxx_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_cxx_werror_flag=$ac_save_cxx_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5 +$as_echo "$ac_cv_prog_cxx_g" >&6; } +if test "$ac_test_CXXFLAGS" = set; then + CXXFLAGS=$ac_save_CXXFLAGS +elif test $ac_cv_prog_cxx_g = yes; then + if test "$GXX" = yes; then + CXXFLAGS="-g -O2" + else + CXXFLAGS="-g" + fi +else + if test "$GXX" = yes; then + CXXFLAGS="-O2" + else + CXXFLAGS= + fi +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +for ac_prog in gmake make +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_MAKE+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$MAKE"; then + ac_cv_prog_MAKE="$MAKE" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_MAKE="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +MAKE=$ac_cv_prog_MAKE +if test -n "$MAKE"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAKE" >&5 +$as_echo "$MAKE" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$MAKE" && break +done + +for ac_prog in python2 python +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_PYTHON2+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$PYTHON2"; then + ac_cv_prog_PYTHON2="$PYTHON2" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_PYTHON2="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +PYTHON2=$ac_cv_prog_PYTHON2 +if test -n "$PYTHON2"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON2" >&5 +$as_echo "$PYTHON2" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$PYTHON2" && break +done + +# Extract the first word of "makedepend", so it can be a program name with args. +set dummy makedepend; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_path_MKDEP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + case $MKDEP in + [\\/]* | ?:[\\/]*) + ac_cv_path_MKDEP="$MKDEP" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_path_MKDEP="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +MKDEP=$ac_cv_path_MKDEP +if test -n "$MKDEP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDEP" >&5 +$as_echo "$MKDEP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +# Extract the first word of "sed", so it can be a program name with args. +set dummy sed; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_path_SED+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + case $SED in + [\\/]* | ?:[\\/]*) + ac_cv_path_SED="$SED" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_path_SED="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +SED=$ac_cv_path_SED +if test -n "$SED"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SED" >&5 +$as_echo "$SED" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + +if test "x$MKDEP" = "x"; then + as_fn_error $? "makedepend is required to build Mesa" "$LINENO" 5 +fi + +# Find a good install program. We prefer a C program (faster), +# so one script is as good as another. But avoid the broken or +# incompatible versions: +# SysV /etc/install, /usr/sbin/install +# SunOS /usr/etc/install +# IRIX /sbin/install +# AIX /bin/install +# AmigaOS /C/install, which installs bootblocks on floppy discs +# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag +# AFS /usr/afsws/bin/install, which mishandles nonexistent args +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" +# OS/2's system install, which has a completely different semantic +# ./install, which can be erroneously created by make from ./install.sh. +# Reject install programs that cannot install multiple files. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 +$as_echo_n "checking for a BSD-compatible install... " >&6; } +if test -z "$INSTALL"; then +if test "${ac_cv_path_install+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + # Account for people who put trailing slashes in PATH elements. +case $as_dir/ in #(( + ./ | .// | /[cC]/* | \ + /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ + ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ + /usr/ucb/* ) ;; + *) + # OSF1 and SCO ODT 3.0 have their own names for install. + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then + if test $ac_prog = install && + grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + elif test $ac_prog = install && + grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # program-specific install script used by HP pwplus--don't use. + : + else + rm -rf conftest.one conftest.two conftest.dir + echo one > conftest.one + echo two > conftest.two + mkdir conftest.dir + if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && + test -s conftest.one && test -s conftest.two && + test -s conftest.dir/conftest.one && + test -s conftest.dir/conftest.two + then + ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" + break 3 + fi + fi + fi + done + done + ;; +esac + + done +IFS=$as_save_IFS + +rm -rf conftest.one conftest.two conftest.dir + +fi + if test "${ac_cv_path_install+set}" = set; then + INSTALL=$ac_cv_path_install + else + # As a last resort, use the slow shell script. Don't cache a + # value for INSTALL within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + INSTALL=$ac_install_sh + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 +$as_echo "$INSTALL" >&6; } + +# Use test -z because SunOS4 sh mishandles braces in ${var-val}. +# It thinks the first close brace ends the variable substitution. +test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' + +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' + +test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' + +test "x$INSTALL" = "x$ac_install_sh" && INSTALL='$(MINSTALL)' + +case "$host_os" in +solaris*) + # Solaris /bin/sh is too old/non-POSIX compliant + for ac_prog in ksh93 ksh sh +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_path_POSIX_SHELL+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + case $POSIX_SHELL in + [\\/]* | ?:[\\/]*) + ac_cv_path_POSIX_SHELL="$POSIX_SHELL" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_path_POSIX_SHELL="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +POSIX_SHELL=$ac_cv_path_POSIX_SHELL +if test -n "$POSIX_SHELL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $POSIX_SHELL" >&5 +$as_echo "$POSIX_SHELL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$POSIX_SHELL" && break +done + + SHELL="$POSIX_SHELL" + ;; +esac + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiling with clang" >&5 +$as_echo_n "checking if compiling with clang... " >&6; } + + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + +#ifndef __clang__ + not clang +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + CLANG=yes +else + CLANG=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CLANG" >&5 +$as_echo "$CLANG" >&6; } + +if test "x$GCC" = xyes -a "x$CLANG" = xno; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether gcc version is sufficient" >&5 +$as_echo_n "checking whether gcc version is sufficient... " >&6; } + major=0 + minor=0 + + GCC_VERSION=`$CC -dumpversion` + if test $? -eq 0; then + major=`echo $GCC_VERSION | cut -d. -f1` + minor=`echo $GCC_VERSION | cut -d. -f1` + fi + + if test $major -lt 3 -o $major -eq 3 -a $minor -lt 3 ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + as_fn_error $? "If using GCC, version 3.3.0 or later is required." "$LINENO" 5 + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + fi +fi + + +MKDEP_OPTIONS=-fdepend +if test "x$GCC" = xyes; then + for dir in include include-fixed; do + GCC_INCLUDES=`$CC -print-file-name=$dir` + if test "x$GCC_INCLUDES" != x && \ + test "$GCC_INCLUDES" != "$dir" && \ + test -d "$GCC_INCLUDES"; then + MKDEP_OPTIONS="$MKDEP_OPTIONS -I$GCC_INCLUDES" + fi + done +fi + + + + + + + + + +if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args. +set dummy ${ac_tool_prefix}pkg-config; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_path_PKG_CONFIG+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + case $PKG_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +PKG_CONFIG=$ac_cv_path_PKG_CONFIG +if test -n "$PKG_CONFIG"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5 +$as_echo "$PKG_CONFIG" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_PKG_CONFIG"; then + ac_pt_PKG_CONFIG=$PKG_CONFIG + # Extract the first word of "pkg-config", so it can be a program name with args. +set dummy pkg-config; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_path_ac_pt_PKG_CONFIG+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_PKG_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG +if test -n "$ac_pt_PKG_CONFIG"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5 +$as_echo "$ac_pt_PKG_CONFIG" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_PKG_CONFIG" = x; then + PKG_CONFIG="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + PKG_CONFIG=$ac_pt_PKG_CONFIG + fi +else + PKG_CONFIG="$ac_cv_path_PKG_CONFIG" +fi + +fi +if test -n "$PKG_CONFIG"; then + _pkg_min_version=0.9.0 + { $as_echo "$as_me:${as_lineno-$LINENO}: checking pkg-config is at least version $_pkg_min_version" >&5 +$as_echo_n "checking pkg-config is at least version $_pkg_min_version... " >&6; } + if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + PKG_CONFIG="" + fi +fi + +LIB_DIR=`echo $libdir | $SED 's%.*/%%'` + + +_SAVE_LDFLAGS="$LDFLAGS" + + + +_SAVE_CPPFLAGS="$CPPFLAGS" + + + +DEFINES="" + +case "$host_os" in +linux*|*-gnu*|gnu*) + DEFINES="$DEFINES -D_GNU_SOURCE -DPTHREADS" + ;; +solaris*) + DEFINES="$DEFINES -DPTHREADS -DSVR4" + ;; +cygwin*) + DEFINES="$DEFINES -DPTHREADS" + ;; +esac + +if test "x$GCC" = xyes; then + CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -std=c99" + if test "x$CLANG" = "xno"; then + CFLAGS="$CFLAGS -ffast-math" + fi + + # Enable -fvisibility=hidden if using a gcc that supports it + save_CFLAGS="$CFLAGS" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -fvisibility=hidden" >&5 +$as_echo_n "checking whether $CC supports -fvisibility=hidden... " >&6; } + CFLAGS="$CFLAGS -fvisibility=hidden" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + CFLAGS="$save_CFLAGS" ; { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext; + + # Work around aliasing bugs - developers should comment this out + CFLAGS="$CFLAGS -fno-strict-aliasing" +fi +if test "x$GXX" = xyes; then + CXXFLAGS="$CXXFLAGS -Wall" + + # Enable -fvisibility=hidden if using a gcc that supports it + save_CXXFLAGS="$CXXFLAGS" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX supports -fvisibility=hidden" >&5 +$as_echo_n "checking whether $CXX supports -fvisibility=hidden... " >&6; } + CXXFLAGS="$CXXFLAGS -fvisibility=hidden" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + CXXFLAGS="$save_CXXFLAGS" ; { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext; + + # Work around aliasing bugs - developers should comment this out + CXXFLAGS="$CXXFLAGS -fno-strict-aliasing" +fi + + + + + + +# Check whether --enable-32-bit was given. +if test "${enable_32_bit+set}" = set; then : + enableval=$enable_32_bit; enable_32bit="$enableval" +else + enable_32bit=auto + +fi + +if test "x$enable_32bit" = xyes; then + if test "x$GCC" = xyes; then + CFLAGS="$CFLAGS -m32" + ARCH_FLAGS="$ARCH_FLAGS -m32" + fi + if test "x$GXX" = xyes; then + CXXFLAGS="$CXXFLAGS -m32" + fi +fi +# Check whether --enable-64-bit was given. +if test "${enable_64_bit+set}" = set; then : + enableval=$enable_64_bit; enable_64bit="$enableval" +else + enable_64bit=auto + +fi + +if test "x$enable_64bit" = xyes; then + if test "x$GCC" = xyes; then + CFLAGS="$CFLAGS -m64" + fi + if test "x$GXX" = xyes; then + CXXFLAGS="$CXXFLAGS -m64" + fi +fi + +# Check whether --enable-static was given. +if test "${enable_static+set}" = set; then : + enableval=$enable_static; enable_static="$enableval" +else + enable_static=no + +fi + +case "x$enable_static" in +xyes|xno ) ;; +x ) enable_static=no ;; +* ) + as_fn_error $? "Static library option '$enable_static' is not a valid" "$LINENO" 5 + ;; +esac +# Check whether --enable-shared was given. +if test "${enable_shared+set}" = set; then : + enableval=$enable_shared; enable_shared="$enableval" +else + enable_shared=yes + +fi + +case "x$enable_shared" in +xyes|xno ) ;; +x ) enable_shared=yes ;; +* ) + as_fn_error $? "Shared library option '$enable_shared' is not a valid" "$LINENO" 5 + ;; +esac + +case "x$enable_static$enable_shared" in +xyesyes ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Can't build static and shared libraries, disabling shared" >&5 +$as_echo "$as_me: WARNING: Can't build static and shared libraries, disabling shared" >&2;} + enable_shared=no + ;; +xnono ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Can't disable both static and shared libraries, enabling static" >&5 +$as_echo "$as_me: WARNING: Can't disable both static and shared libraries, enabling static" >&2;} + enable_static=yes + ;; +esac + + +if test "$enable_static" = yes; then + MKLIB_OPTIONS="$MKLIB_OPTIONS -static" +fi + + +# Check whether --enable-debug was given. +if test "${enable_debug+set}" = set; then : + enableval=$enable_debug; enable_debug="$enableval" +else + enable_debug=no + +fi + +if test "x$enable_debug" = xyes; then + DEFINES="$DEFINES -DDEBUG" + if test "x$GCC" = xyes; then + CFLAGS="$CFLAGS -g" + fi + if test "x$GXX" = xyes; then + CXXFLAGS="$CXXFLAGS -g" + fi +fi + +LIB_PREFIX_GLOB='lib' +LIB_VERSION_SEPARATOR='.' +if test "$enable_static" = yes; then + LIB_EXTENSION='a' +else + case "$host_os" in + darwin* ) + LIB_EXTENSION='dylib' ;; + cygwin* ) + LIB_PREFIX_GLOB='???' + LIB_VERSION_SEPARATOR='-' + LIB_EXTENSION='dll' ;; + aix* ) + LIB_EXTENSION='a' ;; + * ) + LIB_EXTENSION='so' ;; + esac +fi + +GL_LIB_NAME='lib$(GL_LIB).'${LIB_EXTENSION} +GLU_LIB_NAME='lib$(GLU_LIB).'${LIB_EXTENSION} +GLUT_LIB_NAME='lib$(GLUT_LIB).'${LIB_EXTENSION} +GLW_LIB_NAME='lib$(GLW_LIB).'${LIB_EXTENSION} +OSMESA_LIB_NAME='lib$(OSMESA_LIB).'${LIB_EXTENSION} +EGL_LIB_NAME='lib$(EGL_LIB).'${LIB_EXTENSION} +GLESv1_CM_LIB_NAME='lib$(GLESv1_CM_LIB).'${LIB_EXTENSION} +GLESv2_LIB_NAME='lib$(GLESv2_LIB).'${LIB_EXTENSION} +VG_LIB_NAME='lib$(VG_LIB).'${LIB_EXTENSION} + +GL_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GL_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +GLU_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLU_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +GLUT_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLUT_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +GLW_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLW_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +OSMESA_LIB_GLOB=${LIB_PREFIX_GLOB}'$(OSMESA_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +EGL_LIB_GLOB=${LIB_PREFIX_GLOB}'$(EGL_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +EGL_LIB_GLOB=${LIB_PREFIX_GLOB}'$(EGL_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +GLESv1_CM_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLESv1_CM_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +GLESv2_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLESv2_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +VG_LIB_GLOB=${LIB_PREFIX_GLOB}'$(VG_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' + + + + + + + + + + + + + + + + + + + + + +# Check whether --enable-asm was given. +if test "${enable_asm+set}" = set; then : + enableval=$enable_asm; enable_asm="$enableval" +else + enable_asm=yes + +fi + +asm_arch="" +ASM_FLAGS="" +MESA_ASM_SOURCES="" +GLAPI_ASM_SOURCES="" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable assembly" >&5 +$as_echo_n "checking whether to enable assembly... " >&6; } +test "x$enable_asm" = xno && { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +# disable if cross compiling on x86/x86_64 since we must run gen_matypes +if test "x$enable_asm" = xyes && test "x$cross_compiling" = xyes; then + case "$host_cpu" in + i?86 | x86_64) + enable_asm=no + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, cross compiling" >&5 +$as_echo "no, cross compiling" >&6; } + ;; + esac +fi +# check for supported arches +if test "x$enable_asm" = xyes; then + case "$host_cpu" in + i?86) + case "$host_os" in + linux* | *freebsd* | dragonfly*) + test "x$enable_64bit" = xyes && asm_arch=x86_64 || asm_arch=x86 + ;; + esac + ;; + x86_64) + case "$host_os" in + linux* | *freebsd* | dragonfly*) + test "x$enable_32bit" = xyes && asm_arch=x86 || asm_arch=x86_64 + ;; + esac + ;; + powerpc) + case "$host_os" in + linux*) + asm_arch=ppc + ;; + esac + ;; + sparc*) + case "$host_os" in + linux*) + asm_arch=sparc + ;; + esac + ;; + esac + + case "$asm_arch" in + x86) + ASM_FLAGS="-DUSE_X86_ASM -DUSE_MMX_ASM -DUSE_3DNOW_ASM -DUSE_SSE_ASM" + MESA_ASM_SOURCES='$(X86_SOURCES)' + GLAPI_ASM_SOURCES='$(X86_API)' + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes, x86" >&5 +$as_echo "yes, x86" >&6; } + ;; + x86_64) + ASM_FLAGS="-DUSE_X86_64_ASM" + MESA_ASM_SOURCES='$(X86-64_SOURCES)' + GLAPI_ASM_SOURCES='$(X86-64_API)' + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes, x86_64" >&5 +$as_echo "yes, x86_64" >&6; } + ;; + ppc) + ASM_FLAGS="-DUSE_PPC_ASM -DUSE_VMX_ASM" + MESA_ASM_SOURCES='$(PPC_SOURCES)' + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes, ppc" >&5 +$as_echo "yes, ppc" >&6; } + ;; + sparc) + ASM_FLAGS="-DUSE_SPARC_ASM" + MESA_ASM_SOURCES='$(SPARC_SOURCES)' + GLAPI_ASM_SOURCES='$(SPARC_API)' + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes, sparc" >&5 +$as_echo "yes, sparc" >&6; } + ;; + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, platform not supported" >&5 +$as_echo "no, platform not supported" >&6; } + ;; + esac +fi + + + + + +# Check whether --enable-pic was given. +if test "${enable_pic+set}" = set; then : + enableval=$enable_pic; enable_pic="$enableval" + test "x$enable_pic" = x && enable_pic=auto +else + enable_pic=auto +fi + +# disable PIC by default for static builds +if test "$enable_pic" = auto && test "$enable_static" = yes; then + enable_pic=no +fi +# if PIC hasn't been explicitly disabled, try to figure out the flags +if test "$enable_pic" != no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to produce PIC" >&5 +$as_echo_n "checking for $CC option to produce PIC... " >&6; } + # allow the user's flags to override + if test "x$PIC_FLAGS" = x; then + # see if we're using GCC + if test "x$GCC" = xyes; then + case "$host_os" in + aix*|beos*|cygwin*|irix5*|irix6*|osf3*|osf4*|osf5*) + # PIC is the default for these OSes. + ;; + mingw*|os2*|pw32*) + # This hack is so that the source file can tell whether + # it is being built for inclusion in a dll (and should + # export symbols for example). + PIC_FLAGS="-DDLL_EXPORT" + ;; + darwin*|rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + PIC_FLAGS="-fno-common" + ;; + hpux*) + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, + # but not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + ;; + *) + PIC_FLAGS="-fPIC" + ;; + esac + ;; + *) + # Everyone else on GCC uses -fPIC + PIC_FLAGS="-fPIC" + ;; + esac + else # !GCC + case "$host_os" in + hpux9*|hpux10*|hpux11*) + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, + # but not for PA HP-UX. + case "$host_cpu" in + hppa*64*|ia64*) + # +Z the default + ;; + *) + PIC_FLAGS="+Z" + ;; + esac + ;; + linux*|k*bsd*-gnu) + case `basename "$CC"` in + icc*|ecc*|ifort*) + PIC_FLAGS="-KPIC" + ;; + pgcc*|pgf77*|pgf90*|pgf95*) + # Portland Group compilers (*not* the Pentium gcc + # compiler, which looks to be a dead project) + PIC_FLAGS="-fpic" + ;; + ccc*) + # All Alpha code is PIC. + ;; + xl*) + # IBM XL C 8.0/Fortran 10.1 on PPC + PIC_FLAGS="-qpic" + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*|*Sun\ F*) + # Sun C 5.9 or Sun Fortran + PIC_FLAGS="-KPIC" + ;; + esac + esac + ;; + solaris*) + PIC_FLAGS="-KPIC" + ;; + sunos4*) + PIC_FLAGS="-PIC" + ;; + esac + fi # GCC + fi # PIC_FLAGS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PIC_FLAGS" >&5 +$as_echo "$PIC_FLAGS" >&6; } +fi + + + +ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen" +if test "x$ac_cv_func_dlopen" = x""yes; then : + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +$as_echo_n "checking for dlopen in -ldl... " >&6; } +if test "${ac_cv_lib_dl_dlopen+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldl $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dl_dlopen=yes +else + ac_cv_lib_dl_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +$as_echo "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = x""yes; then : + DLOPEN_LIBS="-ldl" +fi + +fi + + + +ac_fn_c_check_func "$LINENO" "posix_memalign" "ac_cv_func_posix_memalign" +if test "x$ac_cv_func_posix_memalign" = x""yes; then : + DEFINES="$DEFINES -DHAVE_POSIX_MEMALIGN" +fi + + +# Check whether --enable-selinux was given. +if test "${enable_selinux+set}" = set; then : + enableval=$enable_selinux; MESA_SELINUX="$enableval" +else + MESA_SELINUX=no +fi + +if test "x$enable_selinux" = "xyes"; then + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +$as_echo_n "checking for grep that handles long lines and -e... " >&6; } +if test "${ac_cv_path_GREP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$GREP"; then + ac_path_GREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in grep ggrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue +# Check for GNU ac_path_GREP and select it if it is found. + # Check for GNU $ac_path_GREP +case `"$ac_path_GREP" --version 2>&1` in +*GNU*) + ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'GREP' >> "conftest.nl" + "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_GREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_GREP="$ac_path_GREP" + ac_path_GREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_GREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_GREP"; then + as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_GREP=$GREP +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +$as_echo "$ac_cv_path_GREP" >&6; } + GREP="$ac_cv_path_GREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +$as_echo_n "checking for egrep... " >&6; } +if test "${ac_cv_path_EGREP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 + then ac_cv_path_EGREP="$GREP -E" + else + if test -z "$EGREP"; then + ac_path_EGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in egrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue +# Check for GNU ac_path_EGREP and select it if it is found. + # Check for GNU $ac_path_EGREP +case `"$ac_path_EGREP" --version 2>&1` in +*GNU*) + ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'EGREP' >> "conftest.nl" + "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_EGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_EGREP="$ac_path_EGREP" + ac_path_EGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_EGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_EGREP"; then + as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_EGREP=$EGREP +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +$as_echo "$ac_cv_path_EGREP" >&6; } + EGREP="$ac_cv_path_EGREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if test "${ac_cv_header_stdc+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "#define STDC_HEADERS 1" >>confdefs.h + +fi + +# On IRIX 5.3, sys/types and inttypes.h are conflicting. +for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ + inttypes.h stdint.h unistd.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default +" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +ac_fn_c_check_header_mongrel "$LINENO" "selinux/selinux.h" "ac_cv_header_selinux_selinux_h" "$ac_includes_default" +if test "x$ac_cv_header_selinux_selinux_h" = x""yes; then : + +else + as_fn_error $? "SELinux headers not found" "$LINENO" 5 +fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for is_selinux_enabled in -lselinux" >&5 +$as_echo_n "checking for is_selinux_enabled in -lselinux... " >&6; } +if test "${ac_cv_lib_selinux_is_selinux_enabled+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lselinux $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char is_selinux_enabled (); +int +main () +{ +return is_selinux_enabled (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_selinux_is_selinux_enabled=yes +else + ac_cv_lib_selinux_is_selinux_enabled=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_selinux_is_selinux_enabled" >&5 +$as_echo "$ac_cv_lib_selinux_is_selinux_enabled" >&6; } +if test "x$ac_cv_lib_selinux_is_selinux_enabled" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBSELINUX 1 +_ACEOF + + LIBS="-lselinux $LIBS" + +else + as_fn_error $? "SELinux library not found" "$LINENO" 5 +fi + + SELINUX_LIBS="-lselinux" + DEFINES="$DEFINES -DMESA_SELINUX" +fi + +# Check whether --enable-opengl was given. +if test "${enable_opengl+set}" = set; then : + enableval=$enable_opengl; enable_opengl="$enableval" +else + enable_opengl=yes +fi + +# Check whether --enable-gles1 was given. +if test "${enable_gles1+set}" = set; then : + enableval=$enable_gles1; enable_gles1="$enableval" +else + enable_gles1=no +fi + +# Check whether --enable-gles2 was given. +if test "${enable_gles2+set}" = set; then : + enableval=$enable_gles2; enable_gles2="$enableval" +else + enable_gles2=no +fi + +# Check whether --enable-gles-overlay was given. +if test "${enable_gles_overlay+set}" = set; then : + enableval=$enable_gles_overlay; enable_gles_overlay="$enableval" +else + enable_gles_overlay=no +fi + + +# Check whether --enable-openvg was given. +if test "${enable_openvg+set}" = set; then : + enableval=$enable_openvg; enable_openvg="$enableval" +else + enable_openvg=no +fi + + +if test "x$enable_openvg" = xno; then + case "x$with_state_trackers" in + x*vega*) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: vega state tracker is enabled without --enable-openvg" >&5 +$as_echo "$as_me: WARNING: vega state tracker is enabled without --enable-openvg" >&2;} + enable_openvg=yes + ;; + esac +fi + +if test "x$enable_opengl" = xno -a \ + "x$enable_gles1" = xno -a \ + "x$enable_gles2" = xno -a \ + "x$enable_gles_overlay" = xno -a \ + "x$enable_openvg" = xno; then + as_fn_error $? "at least one API should be enabled" "$LINENO" 5 +fi + +API_DEFINES="" +GLES_OVERLAY=0 +if test "x$enable_opengl" = xno; then + API_DEFINES="$API_DEFINES -DFEATURE_GL=0" +else + API_DEFINES="$API_DEFINES -DFEATURE_GL=1" +fi +if test "x$enable_gles1" = xyes; then + API_DEFINES="$API_DEFINES -DFEATURE_ES1=1" +fi +if test "x$enable_gles2" = xyes; then + API_DEFINES="$API_DEFINES -DFEATURE_ES2=1" +fi +if test "x$enable_gles_overlay" = xyes; then + GLES_OVERLAY=1 +fi + + + +default_driver="xlib" + +case "$host_os" in +linux*) + case "$host_cpu" in + i*86|x86_64|powerpc*|sparc*) default_driver="dri";; + esac + ;; +*freebsd* | dragonfly*) + case "$host_cpu" in + i*86|x86_64|powerpc*|sparc*) default_driver="dri";; + esac + ;; +esac + +if test "x$enable_opengl" = xno; then + default_driver="no" +fi + + +# Check whether --with-driver was given. +if test "${with_driver+set}" = set; then : + withval=$with_driver; mesa_driver="$withval" +else + mesa_driver="$default_driver" +fi + +case "x$mesa_driver" in +xxlib|xdri|xosmesa) + if test "x$enable_opengl" = xno; then + as_fn_error $? "Driver '$mesa_driver' requires OpenGL enabled" "$LINENO" 5 + fi + ;; +xno) + ;; +*) + as_fn_error $? "Driver '$mesa_driver' is not a valid option" "$LINENO" 5 + ;; +esac + + +CORE_DIRS="" + +SRC_DIRS="" +GLU_DIRS="sgi" +GALLIUM_DIRS="auxiliary drivers state_trackers" +GALLIUM_TARGET_DIRS="" +GALLIUM_WINSYS_DIRS="sw" +GALLIUM_DRIVERS_DIRS="softpipe failover galahad trace rbug identity" +GALLIUM_STATE_TRACKERS_DIRS="" + +# build glapi if OpenGL is enabled +if test "x$enable_opengl" = xyes; then + CORE_DIRS="$CORE_DIRS mapi/glapi" +fi + +# build es1api and es2api if OpenGL ES is enabled +case "x$enable_gles1$enable_gles2$enable_gles_overlay" in +x*yes*) + CORE_DIRS="$CORE_DIRS mapi/es1api mapi/es2api" + ;; +esac + +# build vgapi if OpenVG is enabled +if test "x$enable_openvg" = xyes; then + CORE_DIRS="$CORE_DIRS mapi/vgapi" +fi + +# build glsl and mesa if OpenGL or OpenGL ES is enabled +case "x$enable_opengl$enable_gles1$enable_gles2$enable_gles_overlay" in +x*yes*) + CORE_DIRS="$CORE_DIRS glsl mesa" + ;; +esac + +case "$mesa_driver" in +xlib) + DRIVER_DIRS="x11" + 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 sw/xlib sw/dri" + ;; +osmesa) + DRIVER_DIRS="osmesa" + ;; +no) + DRIVER_DRIS="" + ;; +esac + + + + + + + + + + +if test -n "$PKG_CONFIG"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking pkg-config files for X11 are available" >&5 +$as_echo_n "checking pkg-config files for X11 are available... " >&6; } + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11\""; } >&5 + ($PKG_CONFIG --exists --print-errors "x11") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + + x11_pkgconfig=yes + have_x=yes + +else + + x11_pkgconfig=no + +fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $x11_pkgconfig" >&5 +$as_echo "$x11_pkgconfig" >&6; } +else + x11_pkgconfig=no +fi +if test "$x11_pkgconfig" = yes; then + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for X11" >&5 +$as_echo_n "checking for X11... " >&6; } + +if test -n "$X11_CFLAGS"; then + pkg_cv_X11_CFLAGS="$X11_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11\""; } >&5 + ($PKG_CONFIG --exists --print-errors "x11") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_X11_CFLAGS=`$PKG_CONFIG --cflags "x11" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$X11_LIBS"; then + pkg_cv_X11_LIBS="$X11_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11\""; } >&5 + ($PKG_CONFIG --exists --print-errors "x11") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_X11_LIBS=`$PKG_CONFIG --libs "x11" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + X11_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "x11" 2>&1` + else + X11_PKG_ERRORS=`$PKG_CONFIG --print-errors "x11" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$X11_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements (x11) were not met: + +$X11_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables X11_CFLAGS +and X11_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables X11_CFLAGS +and X11_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } + +else + X11_CFLAGS=$pkg_cv_X11_CFLAGS + X11_LIBS=$pkg_cv_X11_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for X" >&5 +$as_echo_n "checking for X... " >&6; } + + +# Check whether --with-x was given. +if test "${with_x+set}" = set; then : + withval=$with_x; +fi + +# $have_x is `yes', `no', `disabled', or empty when we do not yet know. +if test "x$with_x" = xno; then + # The user explicitly disabled X. + have_x=disabled +else + case $x_includes,$x_libraries in #( + *\'*) as_fn_error $? "cannot use X directory names containing '" "$LINENO" 5;; #( + *,NONE | NONE,*) if test "${ac_cv_have_x+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + # One or both of the vars are not set, and there is no cached value. +ac_x_includes=no ac_x_libraries=no +rm -f -r conftest.dir +if mkdir conftest.dir; then + cd conftest.dir + cat >Imakefile <<'_ACEOF' +incroot: + @echo incroot='${INCROOT}' +usrlibdir: + @echo usrlibdir='${USRLIBDIR}' +libdir: + @echo libdir='${LIBDIR}' +_ACEOF + if (export CC; ${XMKMF-xmkmf}) >/dev/null 2>/dev/null && test -f Makefile; then + # GNU make sometimes prints "make[1]: Entering ...", which would confuse us. + for ac_var in incroot usrlibdir libdir; do + eval "ac_im_$ac_var=\`\${MAKE-make} $ac_var 2>/dev/null | sed -n 's/^$ac_var=//p'\`" + done + # Open Windows xmkmf reportedly sets LIBDIR instead of USRLIBDIR. + for ac_extension in a so sl dylib la dll; do + if test ! -f "$ac_im_usrlibdir/libX11.$ac_extension" && + test -f "$ac_im_libdir/libX11.$ac_extension"; then + ac_im_usrlibdir=$ac_im_libdir; break + fi + done + # Screen out bogus values from the imake configuration. They are + # bogus both because they are the default anyway, and because + # using them would break gcc on systems where it needs fixed includes. + case $ac_im_incroot in + /usr/include) ac_x_includes= ;; + *) test -f "$ac_im_incroot/X11/Xos.h" && ac_x_includes=$ac_im_incroot;; + esac + case $ac_im_usrlibdir in + /usr/lib | /usr/lib64 | /lib | /lib64) ;; + *) test -d "$ac_im_usrlibdir" && ac_x_libraries=$ac_im_usrlibdir ;; + esac + fi + cd .. + rm -f -r conftest.dir +fi + +# Standard set of common directories for X headers. +# Check X11 before X11Rn because it is often a symlink to the current release. +ac_x_header_dirs=' +/usr/X11/include +/usr/X11R7/include +/usr/X11R6/include +/usr/X11R5/include +/usr/X11R4/include + +/usr/include/X11 +/usr/include/X11R7 +/usr/include/X11R6 +/usr/include/X11R5 +/usr/include/X11R4 + +/usr/local/X11/include +/usr/local/X11R7/include +/usr/local/X11R6/include +/usr/local/X11R5/include +/usr/local/X11R4/include + +/usr/local/include/X11 +/usr/local/include/X11R7 +/usr/local/include/X11R6 +/usr/local/include/X11R5 +/usr/local/include/X11R4 + +/usr/X386/include +/usr/x386/include +/usr/XFree86/include/X11 + +/usr/include +/usr/local/include +/usr/unsupported/include +/usr/athena/include +/usr/local/x11r5/include +/usr/lpp/Xamples/include + +/usr/openwin/include +/usr/openwin/share/include' + +if test "$ac_x_includes" = no; then + # Guess where to find include files, by looking for Xlib.h. + # First, try using that file with no special directory specified. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # We can compile using X headers with no special include directory. +ac_x_includes= +else + for ac_dir in $ac_x_header_dirs; do + if test -r "$ac_dir/X11/Xlib.h"; then + ac_x_includes=$ac_dir + break + fi +done +fi +rm -f conftest.err conftest.$ac_ext +fi # $ac_x_includes = no + +if test "$ac_x_libraries" = no; then + # Check for the libraries. + # See if we find them without any special options. + # Don't add to $LIBS permanently. + ac_save_LIBS=$LIBS + LIBS="-lX11 $LIBS" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +XrmInitialize () + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + LIBS=$ac_save_LIBS +# We can link X programs with no special library path. +ac_x_libraries= +else + LIBS=$ac_save_LIBS +for ac_dir in `$as_echo "$ac_x_includes $ac_x_header_dirs" | sed s/include/lib/g` +do + # Don't even attempt the hair of trying to link an X program! + for ac_extension in a so sl dylib la dll; do + if test -r "$ac_dir/libX11.$ac_extension"; then + ac_x_libraries=$ac_dir + break 2 + fi + done +done +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi # $ac_x_libraries = no + +case $ac_x_includes,$ac_x_libraries in #( + no,* | *,no | *\'*) + # Didn't find X, or a directory has "'" in its name. + ac_cv_have_x="have_x=no";; #( + *) + # Record where we found X for the cache. + ac_cv_have_x="have_x=yes\ + ac_x_includes='$ac_x_includes'\ + ac_x_libraries='$ac_x_libraries'" +esac +fi +;; #( + *) have_x=yes;; + esac + eval "$ac_cv_have_x" +fi # $with_x != no + +if test "$have_x" != yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_x" >&5 +$as_echo "$have_x" >&6; } + no_x=yes +else + # If each of the values was on the command line, it overrides each guess. + test "x$x_includes" = xNONE && x_includes=$ac_x_includes + test "x$x_libraries" = xNONE && x_libraries=$ac_x_libraries + # Update the cache value to reflect the command line values. + ac_cv_have_x="have_x=yes\ + ac_x_includes='$x_includes'\ + ac_x_libraries='$x_libraries'" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: libraries $x_libraries, headers $x_includes" >&5 +$as_echo "libraries $x_libraries, headers $x_includes" >&6; } +fi + +if test "$no_x" = yes; then + # Not all programs may use this symbol, but it does not hurt to define it. + +$as_echo "#define X_DISPLAY_MISSING 1" >>confdefs.h + + X_CFLAGS= X_PRE_LIBS= X_LIBS= X_EXTRA_LIBS= +else + if test -n "$x_includes"; then + X_CFLAGS="$X_CFLAGS -I$x_includes" + fi + + # It would also be nice to do this for all -L options, not just this one. + if test -n "$x_libraries"; then + X_LIBS="$X_LIBS -L$x_libraries" + # For Solaris; some versions of Sun CC require a space after -R and + # others require no space. Words are not sufficient . . . . + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -R must be followed by a space" >&5 +$as_echo_n "checking whether -R must be followed by a space... " >&6; } + ac_xsave_LIBS=$LIBS; LIBS="$LIBS -R$x_libraries" + ac_xsave_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + X_LIBS="$X_LIBS -R$x_libraries" +else + LIBS="$ac_xsave_LIBS -R $x_libraries" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + X_LIBS="$X_LIBS -R $x_libraries" +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: neither works" >&5 +$as_echo "neither works" >&6; } +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + ac_c_werror_flag=$ac_xsave_c_werror_flag + LIBS=$ac_xsave_LIBS + fi + + # Check for system-dependent libraries X programs must link with. + # Do this before checking for the system-independent R6 libraries + # (-lICE), since we may need -lsocket or whatever for X linking. + + if test "$ISC" = yes; then + X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl_s -linet" + else + # Martyn Johnson says this is needed for Ultrix, if the X + # libraries were built with DECnet support. And Karl Berry says + # the Alpha needs dnet_stub (dnet does not exist). + ac_xsave_LIBS="$LIBS"; LIBS="$LIBS $X_LIBS -lX11" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char XOpenDisplay (); +int +main () +{ +return XOpenDisplay (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dnet_ntoa in -ldnet" >&5 +$as_echo_n "checking for dnet_ntoa in -ldnet... " >&6; } +if test "${ac_cv_lib_dnet_dnet_ntoa+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldnet $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dnet_ntoa (); +int +main () +{ +return dnet_ntoa (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dnet_dnet_ntoa=yes +else + ac_cv_lib_dnet_dnet_ntoa=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dnet_dnet_ntoa" >&5 +$as_echo "$ac_cv_lib_dnet_dnet_ntoa" >&6; } +if test "x$ac_cv_lib_dnet_dnet_ntoa" = x""yes; then : + X_EXTRA_LIBS="$X_EXTRA_LIBS -ldnet" +fi + + if test $ac_cv_lib_dnet_dnet_ntoa = no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dnet_ntoa in -ldnet_stub" >&5 +$as_echo_n "checking for dnet_ntoa in -ldnet_stub... " >&6; } +if test "${ac_cv_lib_dnet_stub_dnet_ntoa+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldnet_stub $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dnet_ntoa (); +int +main () +{ +return dnet_ntoa (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dnet_stub_dnet_ntoa=yes +else + ac_cv_lib_dnet_stub_dnet_ntoa=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dnet_stub_dnet_ntoa" >&5 +$as_echo "$ac_cv_lib_dnet_stub_dnet_ntoa" >&6; } +if test "x$ac_cv_lib_dnet_stub_dnet_ntoa" = x""yes; then : + X_EXTRA_LIBS="$X_EXTRA_LIBS -ldnet_stub" +fi + + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LIBS="$ac_xsave_LIBS" + + # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT, + # to get the SysV transport functions. + # Chad R. Larson says the Pyramis MIS-ES running DC/OSx (SVR4) + # needs -lnsl. + # The nsl library prevents programs from opening the X display + # on Irix 5.2, according to T.E. Dickey. + # The functions gethostbyname, getservbyname, and inet_addr are + # in -lbsd on LynxOS 3.0.1/i386, according to Lars Hecking. + ac_fn_c_check_func "$LINENO" "gethostbyname" "ac_cv_func_gethostbyname" +if test "x$ac_cv_func_gethostbyname" = x""yes; then : + +fi + + if test $ac_cv_func_gethostbyname = no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyname in -lnsl" >&5 +$as_echo_n "checking for gethostbyname in -lnsl... " >&6; } +if test "${ac_cv_lib_nsl_gethostbyname+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lnsl $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char gethostbyname (); +int +main () +{ +return gethostbyname (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_nsl_gethostbyname=yes +else + ac_cv_lib_nsl_gethostbyname=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_nsl_gethostbyname" >&5 +$as_echo "$ac_cv_lib_nsl_gethostbyname" >&6; } +if test "x$ac_cv_lib_nsl_gethostbyname" = x""yes; then : + X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl" +fi + + if test $ac_cv_lib_nsl_gethostbyname = no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyname in -lbsd" >&5 +$as_echo_n "checking for gethostbyname in -lbsd... " >&6; } +if test "${ac_cv_lib_bsd_gethostbyname+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lbsd $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char gethostbyname (); +int +main () +{ +return gethostbyname (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_bsd_gethostbyname=yes +else + ac_cv_lib_bsd_gethostbyname=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bsd_gethostbyname" >&5 +$as_echo "$ac_cv_lib_bsd_gethostbyname" >&6; } +if test "x$ac_cv_lib_bsd_gethostbyname" = x""yes; then : + X_EXTRA_LIBS="$X_EXTRA_LIBS -lbsd" +fi + + fi + fi + + # lieder@skyler.mavd.honeywell.com says without -lsocket, + # socket/setsockopt and other routines are undefined under SCO ODT + # 2.0. But -lsocket is broken on IRIX 5.2 (and is not necessary + # on later versions), says Simon Leinen: it contains gethostby* + # variants that don't use the name server (or something). -lsocket + # must be given before -lnsl if both are needed. We assume that + # if connect needs -lnsl, so does gethostbyname. + ac_fn_c_check_func "$LINENO" "connect" "ac_cv_func_connect" +if test "x$ac_cv_func_connect" = x""yes; then : + +fi + + if test $ac_cv_func_connect = no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for connect in -lsocket" >&5 +$as_echo_n "checking for connect in -lsocket... " >&6; } +if test "${ac_cv_lib_socket_connect+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lsocket $X_EXTRA_LIBS $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char connect (); +int +main () +{ +return connect (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_socket_connect=yes +else + ac_cv_lib_socket_connect=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_socket_connect" >&5 +$as_echo "$ac_cv_lib_socket_connect" >&6; } +if test "x$ac_cv_lib_socket_connect" = x""yes; then : + X_EXTRA_LIBS="-lsocket $X_EXTRA_LIBS" +fi + + fi + + # Guillermo Gomez says -lposix is necessary on A/UX. + ac_fn_c_check_func "$LINENO" "remove" "ac_cv_func_remove" +if test "x$ac_cv_func_remove" = x""yes; then : + +fi + + if test $ac_cv_func_remove = no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for remove in -lposix" >&5 +$as_echo_n "checking for remove in -lposix... " >&6; } +if test "${ac_cv_lib_posix_remove+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lposix $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char remove (); +int +main () +{ +return remove (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_posix_remove=yes +else + ac_cv_lib_posix_remove=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_posix_remove" >&5 +$as_echo "$ac_cv_lib_posix_remove" >&6; } +if test "x$ac_cv_lib_posix_remove" = x""yes; then : + X_EXTRA_LIBS="$X_EXTRA_LIBS -lposix" +fi + + fi + + # BSDI BSD/OS 2.1 needs -lipc for XOpenDisplay. + ac_fn_c_check_func "$LINENO" "shmat" "ac_cv_func_shmat" +if test "x$ac_cv_func_shmat" = x""yes; then : + +fi + + if test $ac_cv_func_shmat = no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shmat in -lipc" >&5 +$as_echo_n "checking for shmat in -lipc... " >&6; } +if test "${ac_cv_lib_ipc_shmat+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lipc $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char shmat (); +int +main () +{ +return shmat (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_ipc_shmat=yes +else + ac_cv_lib_ipc_shmat=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ipc_shmat" >&5 +$as_echo "$ac_cv_lib_ipc_shmat" >&6; } +if test "x$ac_cv_lib_ipc_shmat" = x""yes; then : + X_EXTRA_LIBS="$X_EXTRA_LIBS -lipc" +fi + + fi + fi + + # Check for libraries that X11R6 Xt/Xaw programs need. + ac_save_LDFLAGS=$LDFLAGS + test -n "$x_libraries" && LDFLAGS="$LDFLAGS -L$x_libraries" + # SM needs ICE to (dynamically) link under SunOS 4.x (so we have to + # check for ICE first), but we must link in the order -lSM -lICE or + # we get undefined symbols. So assume we have SM if we have ICE. + # These have to be linked with before -lX11, unlike the other + # libraries we check for below, so use a different variable. + # John Interrante, Karl Berry + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for IceConnectionNumber in -lICE" >&5 +$as_echo_n "checking for IceConnectionNumber in -lICE... " >&6; } +if test "${ac_cv_lib_ICE_IceConnectionNumber+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lICE $X_EXTRA_LIBS $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char IceConnectionNumber (); +int +main () +{ +return IceConnectionNumber (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_ICE_IceConnectionNumber=yes +else + ac_cv_lib_ICE_IceConnectionNumber=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ICE_IceConnectionNumber" >&5 +$as_echo "$ac_cv_lib_ICE_IceConnectionNumber" >&6; } +if test "x$ac_cv_lib_ICE_IceConnectionNumber" = x""yes; then : + X_PRE_LIBS="$X_PRE_LIBS -lSM -lICE" +fi + + LDFLAGS=$ac_save_LDFLAGS + +fi + + test -z "$X11_CFLAGS" && X11_CFLAGS="$X_CFLAGS" + test -z "$X11_LIBS" && X11_LIBS="$X_LIBS -lX11" + + +fi + + + +case "$mesa_driver" in +xlib|dri) + if test "$no_x" = yes; then + as_fn_error $? "X11 development libraries needed for $mesa_driver driver" "$LINENO" 5 + fi + ;; +esac + +# Check whether --enable-xcb was given. +if test "${enable_xcb+set}" = set; then : + enableval=$enable_xcb; enable_xcb="$enableval" +else + enable_xcb=no +fi + +if test "x$enable_xcb" = xyes; then + DEFINES="$DEFINES -DUSE_XCB" +else + enable_xcb=no +fi + +case "$mesa_driver" in +xlib) + if test "$x11_pkgconfig" = yes; then + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XLIBGL" >&5 +$as_echo_n "checking for XLIBGL... " >&6; } + +if test -n "$XLIBGL_CFLAGS"; then + pkg_cv_XLIBGL_CFLAGS="$XLIBGL_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11 xext\""; } >&5 + ($PKG_CONFIG --exists --print-errors "x11 xext") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_XLIBGL_CFLAGS=`$PKG_CONFIG --cflags "x11 xext" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$XLIBGL_LIBS"; then + pkg_cv_XLIBGL_LIBS="$XLIBGL_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11 xext\""; } >&5 + ($PKG_CONFIG --exists --print-errors "x11 xext") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_XLIBGL_LIBS=`$PKG_CONFIG --libs "x11 xext" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + XLIBGL_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "x11 xext" 2>&1` + else + XLIBGL_PKG_ERRORS=`$PKG_CONFIG --print-errors "x11 xext" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$XLIBGL_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements (x11 xext) were not met: + +$XLIBGL_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables XLIBGL_CFLAGS +and XLIBGL_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables XLIBGL_CFLAGS +and XLIBGL_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } + +else + XLIBGL_CFLAGS=$pkg_cv_XLIBGL_CFLAGS + XLIBGL_LIBS=$pkg_cv_XLIBGL_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +fi + GL_PC_REQ_PRIV="x11 xext" + X11_INCLUDES="$X11_INCLUDES $XLIBGL_CFLAGS" + GL_LIB_DEPS="$XLIBGL_LIBS" + else + # should check these... + X11_INCLUDES="$X11_INCLUDES $X_CFLAGS" + GL_LIB_DEPS="$X_LIBS -lX11 -lXext" + GL_PC_LIB_PRIV="$GL_LIB_DEPS" + GL_PC_CFLAGS="$X11_INCLUDES" + fi + GL_LIB_DEPS="$GL_LIB_DEPS $SELINUX_LIBS -lm -lpthread" + GL_PC_LIB_PRIV="$GL_PC_LIB_PRIV $SELINUX_LIBS -lm -lpthread" + + # if static, move the external libraries to the programs + # and empty the libraries for libGL + if test "$enable_static" = yes; then + APP_LIB_DEPS="$APP_LIB_DEPS $GL_LIB_DEPS" + GL_LIB_DEPS="" + fi + ;; +dri|no) # these checks are still desired when there is no mesa_driver + # DRI must be shared, I think + if test "$enable_static" = yes; then + as_fn_error $? "Can't use static libraries for DRI drivers" "$LINENO" 5 + fi + + # Check for libdrm + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBDRM" >&5 +$as_echo_n "checking for LIBDRM... " >&6; } + +if test -n "$LIBDRM_CFLAGS"; then + pkg_cv_LIBDRM_CFLAGS="$LIBDRM_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm >= \$LIBDRM_REQUIRED\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libdrm >= $LIBDRM_REQUIRED") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LIBDRM_CFLAGS=`$PKG_CONFIG --cflags "libdrm >= $LIBDRM_REQUIRED" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$LIBDRM_LIBS"; then + pkg_cv_LIBDRM_LIBS="$LIBDRM_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm >= \$LIBDRM_REQUIRED\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libdrm >= $LIBDRM_REQUIRED") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LIBDRM_LIBS=`$PKG_CONFIG --libs "libdrm >= $LIBDRM_REQUIRED" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + LIBDRM_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "libdrm >= $LIBDRM_REQUIRED" 2>&1` + else + LIBDRM_PKG_ERRORS=`$PKG_CONFIG --print-errors "libdrm >= $LIBDRM_REQUIRED" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$LIBDRM_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements (libdrm >= $LIBDRM_REQUIRED) were not met: + +$LIBDRM_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables LIBDRM_CFLAGS +and LIBDRM_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables LIBDRM_CFLAGS +and LIBDRM_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } + +else + LIBDRM_CFLAGS=$pkg_cv_LIBDRM_CFLAGS + LIBDRM_LIBS=$pkg_cv_LIBDRM_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +fi + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for DRI2PROTO" >&5 +$as_echo_n "checking for DRI2PROTO... " >&6; } + +if test -n "$DRI2PROTO_CFLAGS"; then + pkg_cv_DRI2PROTO_CFLAGS="$DRI2PROTO_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"dri2proto >= \$DRI2PROTO_REQUIRED\""; } >&5 + ($PKG_CONFIG --exists --print-errors "dri2proto >= $DRI2PROTO_REQUIRED") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_DRI2PROTO_CFLAGS=`$PKG_CONFIG --cflags "dri2proto >= $DRI2PROTO_REQUIRED" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$DRI2PROTO_LIBS"; then + pkg_cv_DRI2PROTO_LIBS="$DRI2PROTO_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"dri2proto >= \$DRI2PROTO_REQUIRED\""; } >&5 + ($PKG_CONFIG --exists --print-errors "dri2proto >= $DRI2PROTO_REQUIRED") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_DRI2PROTO_LIBS=`$PKG_CONFIG --libs "dri2proto >= $DRI2PROTO_REQUIRED" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + DRI2PROTO_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "dri2proto >= $DRI2PROTO_REQUIRED" 2>&1` + else + DRI2PROTO_PKG_ERRORS=`$PKG_CONFIG --print-errors "dri2proto >= $DRI2PROTO_REQUIRED" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$DRI2PROTO_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements (dri2proto >= $DRI2PROTO_REQUIRED) were not met: + +$DRI2PROTO_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables DRI2PROTO_CFLAGS +and DRI2PROTO_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables DRI2PROTO_CFLAGS +and DRI2PROTO_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } + +else + DRI2PROTO_CFLAGS=$pkg_cv_DRI2PROTO_CFLAGS + DRI2PROTO_LIBS=$pkg_cv_DRI2PROTO_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +fi + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GLPROTO" >&5 +$as_echo_n "checking for GLPROTO... " >&6; } + +if test -n "$GLPROTO_CFLAGS"; then + pkg_cv_GLPROTO_CFLAGS="$GLPROTO_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"glproto >= \$GLPROTO_REQUIRED\""; } >&5 + ($PKG_CONFIG --exists --print-errors "glproto >= $GLPROTO_REQUIRED") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GLPROTO_CFLAGS=`$PKG_CONFIG --cflags "glproto >= $GLPROTO_REQUIRED" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$GLPROTO_LIBS"; then + pkg_cv_GLPROTO_LIBS="$GLPROTO_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"glproto >= \$GLPROTO_REQUIRED\""; } >&5 + ($PKG_CONFIG --exists --print-errors "glproto >= $GLPROTO_REQUIRED") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GLPROTO_LIBS=`$PKG_CONFIG --libs "glproto >= $GLPROTO_REQUIRED" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + GLPROTO_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "glproto >= $GLPROTO_REQUIRED" 2>&1` + else + GLPROTO_PKG_ERRORS=`$PKG_CONFIG --print-errors "glproto >= $GLPROTO_REQUIRED" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$GLPROTO_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements (glproto >= $GLPROTO_REQUIRED) were not met: + +$GLPROTO_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables GLPROTO_CFLAGS +and GLPROTO_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables GLPROTO_CFLAGS +and GLPROTO_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } + +else + GLPROTO_CFLAGS=$pkg_cv_GLPROTO_CFLAGS + GLPROTO_LIBS=$pkg_cv_GLPROTO_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +fi + GL_PC_REQ_PRIV="libdrm >= $LIBDRM_REQUIRED dri2proto >= $DRI2PROTO_REQUIRED glproto >= $GLPROTO_REQUIRED" + DRI_PC_REQ_PRIV="libdrm >= $LIBDRM_REQUIRED" + + # find the DRI deps for libGL + if test "$x11_pkgconfig" = yes; then + dri_modules="x11 xext xdamage xfixes" + + # add xf86vidmode if available + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XF86VIDMODE" >&5 +$as_echo_n "checking for XF86VIDMODE... " >&6; } + +if test -n "$XF86VIDMODE_CFLAGS"; then + pkg_cv_XF86VIDMODE_CFLAGS="$XF86VIDMODE_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xxf86vm\""; } >&5 + ($PKG_CONFIG --exists --print-errors "xxf86vm") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_XF86VIDMODE_CFLAGS=`$PKG_CONFIG --cflags "xxf86vm" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$XF86VIDMODE_LIBS"; then + pkg_cv_XF86VIDMODE_LIBS="$XF86VIDMODE_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xxf86vm\""; } >&5 + ($PKG_CONFIG --exists --print-errors "xxf86vm") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_XF86VIDMODE_LIBS=`$PKG_CONFIG --libs "xxf86vm" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + XF86VIDMODE_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "xxf86vm" 2>&1` + else + XF86VIDMODE_PKG_ERRORS=`$PKG_CONFIG --print-errors "xxf86vm" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$XF86VIDMODE_PKG_ERRORS" >&5 + + HAVE_XF86VIDMODE=no +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + HAVE_XF86VIDMODE=no +else + XF86VIDMODE_CFLAGS=$pkg_cv_XF86VIDMODE_CFLAGS + XF86VIDMODE_LIBS=$pkg_cv_XF86VIDMODE_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + HAVE_XF86VIDMODE=yes +fi + if test "$HAVE_XF86VIDMODE" = yes ; then + dri_modules="$dri_modules xxf86vm" + fi + + # add xcb modules if necessary + if test "$enable_xcb" = yes; then + dri_modules="$dri_modules x11-xcb xcb-glx" + fi + + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for DRIGL" >&5 +$as_echo_n "checking for DRIGL... " >&6; } + +if test -n "$DRIGL_CFLAGS"; then + pkg_cv_DRIGL_CFLAGS="$DRIGL_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"\$dri_modules\""; } >&5 + ($PKG_CONFIG --exists --print-errors "$dri_modules") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_DRIGL_CFLAGS=`$PKG_CONFIG --cflags "$dri_modules" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$DRIGL_LIBS"; then + pkg_cv_DRIGL_LIBS="$DRIGL_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"\$dri_modules\""; } >&5 + ($PKG_CONFIG --exists --print-errors "$dri_modules") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_DRIGL_LIBS=`$PKG_CONFIG --libs "$dri_modules" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + DRIGL_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$dri_modules" 2>&1` + else + DRIGL_PKG_ERRORS=`$PKG_CONFIG --print-errors "$dri_modules" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$DRIGL_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements ($dri_modules) were not met: + +$DRIGL_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables DRIGL_CFLAGS +and DRIGL_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables DRIGL_CFLAGS +and DRIGL_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } + +else + DRIGL_CFLAGS=$pkg_cv_DRIGL_CFLAGS + DRIGL_LIBS=$pkg_cv_DRIGL_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +fi + GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV $dri_modules" + X11_INCLUDES="$X11_INCLUDES $DRIGL_CFLAGS" + GL_LIB_DEPS="$DRIGL_LIBS" + else + # should check these... + X11_INCLUDES="$X11_INCLUDES $X_CFLAGS" + GL_LIB_DEPS="$X_LIBS -lX11 -lXext -lXxf86vm -lXdamage -lXfixes" + GL_PC_LIB_PRIV="$GL_LIB_DEPS" + GL_PC_CFLAGS="$X11_INCLUDES" + + # XCB can only be used from pkg-config + if test "$enable_xcb" = yes; then + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XCB" >&5 +$as_echo_n "checking for XCB... " >&6; } + +if test -n "$XCB_CFLAGS"; then + pkg_cv_XCB_CFLAGS="$XCB_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11-xcb xcb-glx\""; } >&5 + ($PKG_CONFIG --exists --print-errors "x11-xcb xcb-glx") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_XCB_CFLAGS=`$PKG_CONFIG --cflags "x11-xcb xcb-glx" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$XCB_LIBS"; then + pkg_cv_XCB_LIBS="$XCB_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11-xcb xcb-glx\""; } >&5 + ($PKG_CONFIG --exists --print-errors "x11-xcb xcb-glx") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_XCB_LIBS=`$PKG_CONFIG --libs "x11-xcb xcb-glx" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + XCB_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "x11-xcb xcb-glx" 2>&1` + else + XCB_PKG_ERRORS=`$PKG_CONFIG --print-errors "x11-xcb xcb-glx" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$XCB_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements (x11-xcb xcb-glx) were not met: + +$XCB_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables XCB_CFLAGS +and XCB_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables XCB_CFLAGS +and XCB_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } + +else + XCB_CFLAGS=$pkg_cv_XCB_CFLAGS + XCB_LIBS=$pkg_cv_XCB_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +fi + GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV x11-xcb xcb-glx" + X11_INCLUDES="$X11_INCLUDES $XCB_CFLAGS" + GL_LIB_DEPS="$GL_LIB_DEPS $XCB_LIBS" + fi + fi + + # need DRM libs, -lpthread, etc. + GL_LIB_DEPS="$GL_LIB_DEPS $LIBDRM_LIBS -lm -lpthread $DLOPEN_LIBS" + GL_PC_LIB_PRIV="-lm -lpthread $DLOPEN_LIBS" + GLESv1_CM_LIB_DEPS="$LIBDRM_LIBS -lm -lpthread $DLOPEN_LIBS" + GLESv1_CM_PC_LIB_PRIV="-lm -lpthread $DLOPEN_LIBS" + GLESv2_LIB_DEPS="$LIBDRM_LIBS -lm -lpthread $DLOPEN_LIBS" + GLESv2_PC_LIB_PRIV="-lm -lpthread $DLOPEN_LIBS" + ;; +osmesa) + # No libGL for osmesa + GL_LIB_DEPS="" + ;; +esac + + + + + + + + + + + + + + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBDRM_RADEON" >&5 +$as_echo_n "checking for LIBDRM_RADEON... " >&6; } + +if test -n "$LIBDRM_RADEON_CFLAGS"; then + pkg_cv_LIBDRM_RADEON_CFLAGS="$LIBDRM_RADEON_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm_radeon libdrm >= \$LIBDRM_RADEON_REQUIRED\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libdrm_radeon libdrm >= $LIBDRM_RADEON_REQUIRED") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LIBDRM_RADEON_CFLAGS=`$PKG_CONFIG --cflags "libdrm_radeon libdrm >= $LIBDRM_RADEON_REQUIRED" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$LIBDRM_RADEON_LIBS"; then + pkg_cv_LIBDRM_RADEON_LIBS="$LIBDRM_RADEON_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm_radeon libdrm >= \$LIBDRM_RADEON_REQUIRED\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libdrm_radeon libdrm >= $LIBDRM_RADEON_REQUIRED") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LIBDRM_RADEON_LIBS=`$PKG_CONFIG --libs "libdrm_radeon libdrm >= $LIBDRM_RADEON_REQUIRED" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + LIBDRM_RADEON_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "libdrm_radeon libdrm >= $LIBDRM_RADEON_REQUIRED" 2>&1` + else + LIBDRM_RADEON_PKG_ERRORS=`$PKG_CONFIG --print-errors "libdrm_radeon libdrm >= $LIBDRM_RADEON_REQUIRED" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$LIBDRM_RADEON_PKG_ERRORS" >&5 + + HAVE_LIBDRM_RADEON=no +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + HAVE_LIBDRM_RADEON=no +else + LIBDRM_RADEON_CFLAGS=$pkg_cv_LIBDRM_RADEON_CFLAGS + LIBDRM_RADEON_LIBS=$pkg_cv_LIBDRM_RADEON_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + HAVE_LIBDRM_RADEON=yes +fi + +if test "$mesa_driver" = xlib; then + DEFINES="$DEFINES -DUSE_XSHM" +fi + +# Check whether --enable-glx-tls was given. +if test "${enable_glx_tls+set}" = set; then : + enableval=$enable_glx_tls; GLX_USE_TLS="$enableval" +else + GLX_USE_TLS=no +fi + + +# Check whether --with-dri-driverdir was given. +if test "${with_dri_driverdir+set}" = set; then : + withval=$with_dri_driverdir; DRI_DRIVER_INSTALL_DIR="$withval" +else + DRI_DRIVER_INSTALL_DIR='${libdir}/dri' +fi + + + +# Check whether --with-dri-searchpath was given. +if test "${with_dri_searchpath+set}" = set; then : + withval=$with_dri_searchpath; DRI_DRIVER_SEARCH_DIR="$withval" +else + DRI_DRIVER_SEARCH_DIR='${DRI_DRIVER_INSTALL_DIR}' +fi + + +# Check whether --enable-driglx-direct was given. +if test "${enable_driglx_direct+set}" = set; then : + enableval=$enable_driglx_direct; driglx_direct="$enableval" +else + driglx_direct="yes" +fi + + +# Check whether --with-dri-drivers was given. +if test "${with_dri_drivers+set}" = set; then : + withval=$with_dri_drivers; with_dri_drivers="$withval" +else + with_dri_drivers=yes +fi + +if test "x$with_dri_drivers" = x; then + with_dri_drivers=no +fi + +DRI_DIRS="" +case "$with_dri_drivers" in +no) ;; +yes) + DRI_DIRS="yes" + ;; +*) + # verify the requested driver directories exist + dri_drivers=`IFS=', '; echo $with_dri_drivers` + for driver in $dri_drivers; do + test -d "$srcdir/src/mesa/drivers/dri/$driver" || \ + as_fn_error $? "DRI driver directory '$driver' doesn't exist" "$LINENO" 5 + done + DRI_DIRS="$dri_drivers" + ;; +esac + +if test "$mesa_driver" = dri -o "$mesa_driver" = no; then + # Use TLS in GLX? + if test "x$GLX_USE_TLS" = xyes; then + DEFINES="$DEFINES -DGLX_USE_TLS -DPTHREADS" + fi + + # Platform specific settings and drivers to build + case "$host_os" in + linux*) + DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER" + if test "x$driglx_direct" = xyes; then + DEFINES="$DEFINES -DGLX_DIRECT_RENDERING" + fi + DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING -DHAVE_ALIAS" + + case "$host_cpu" in + x86_64) + # sis is missing because they have not be converted to use + # the new interface. i810 are missing because there is no + # x86-64 system where they could *ever* be used. + if test "x$DRI_DIRS" = "xyes"; then + DRI_DIRS="i915 i965 mach64 mga r128 r200 r300 r600 radeon \ + savage tdfx unichrome swrast" + fi + ;; + powerpc*) + # Build only the drivers for cards that exist on PowerPC. + # At some point MGA will be added, but not yet. + if test "x$DRI_DIRS" = "xyes"; then + DRI_DIRS="mach64 r128 r200 r300 r600 radeon tdfx swrast" + fi + ;; + sparc*) + # Build only the drivers for cards that exist on sparc` + if test "x$DRI_DIRS" = "xyes"; then + DRI_DIRS="mach64 r128 r200 r300 r600 radeon swrast" + fi + ;; + esac + ;; + freebsd* | dragonfly*) + DEFINES="$DEFINES -DPTHREADS -DUSE_EXTERNAL_DXTN_LIB=1" + DEFINES="$DEFINES -DIN_DRI_DRIVER -DHAVE_ALIAS" + DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING" + if test "x$driglx_direct" = xyes; then + DEFINES="$DEFINES -DGLX_DIRECT_RENDERING" + fi + if test "x$GXX" = xyes; then + CXXFLAGS="$CXXFLAGS -ansi -pedantic" + fi + + if test "x$DRI_DIRS" = "xyes"; then + DRI_DIRS="i810 i915 i965 mach64 mga r128 r200 r300 r600 radeon tdfx \ + unichrome savage sis swrast" + fi + ;; + gnu*) + DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER" + DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING -DHAVE_ALIAS" + ;; + solaris*) + DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER" + DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING" + if test "x$driglx_direct" = xyes; then + DEFINES="$DEFINES -DGLX_DIRECT_RENDERING" + fi + ;; + esac + + # default drivers + if test "x$DRI_DIRS" = "xyes"; then + DRI_DIRS="i810 i915 i965 mach64 mga r128 r200 r300 r600 radeon \ + savage sis tdfx unichrome swrast" + fi + + DRI_DIRS=`echo "$DRI_DIRS" | $SED 's/ */ /g'` + + # Check for expat + if test "$mesa_driver" = dri; then + EXPAT_INCLUDES="" + EXPAT_LIB=-lexpat + +# Check whether --with-expat was given. +if test "${with_expat+set}" = set; then : + withval=$with_expat; + EXPAT_INCLUDES="-I$withval/include" + CPPFLAGS="$CPPFLAGS $EXPAT_INCLUDES" + LDFLAGS="$LDFLAGS -L$withval/$LIB_DIR" + EXPAT_LIB="-L$withval/$LIB_DIR -lexpat" + +fi + + ac_fn_c_check_header_mongrel "$LINENO" "expat.h" "ac_cv_header_expat_h" "$ac_includes_default" +if test "x$ac_cv_header_expat_h" = x""yes; then : + +else + as_fn_error $? "Expat required for DRI." "$LINENO" 5 +fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for XML_ParserCreate in -lexpat" >&5 +$as_echo_n "checking for XML_ParserCreate in -lexpat... " >&6; } +if test "${ac_cv_lib_expat_XML_ParserCreate+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lexpat $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char XML_ParserCreate (); +int +main () +{ +return XML_ParserCreate (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_expat_XML_ParserCreate=yes +else + ac_cv_lib_expat_XML_ParserCreate=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_expat_XML_ParserCreate" >&5 +$as_echo "$ac_cv_lib_expat_XML_ParserCreate" >&6; } +if test "x$ac_cv_lib_expat_XML_ParserCreate" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBEXPAT 1 +_ACEOF + + LIBS="-lexpat $LIBS" + +else + as_fn_error $? "Expat required for DRI." "$LINENO" 5 +fi + + fi + + # put all the necessary libs together + DRI_LIB_DEPS="$SELINUX_LIBS $LIBDRM_LIBS $EXPAT_LIB -lm -lpthread $DLOPEN_LIBS" +fi + + + + +case $DRI_DIRS in +*i915*|*i965*) + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for INTEL" >&5 +$as_echo_n "checking for INTEL... " >&6; } + +if test -n "$INTEL_CFLAGS"; then + pkg_cv_INTEL_CFLAGS="$INTEL_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm_intel >= 2.4.21\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libdrm_intel >= 2.4.21") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_INTEL_CFLAGS=`$PKG_CONFIG --cflags "libdrm_intel >= 2.4.21" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$INTEL_LIBS"; then + pkg_cv_INTEL_LIBS="$INTEL_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm_intel >= 2.4.21\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libdrm_intel >= 2.4.21") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_INTEL_LIBS=`$PKG_CONFIG --libs "libdrm_intel >= 2.4.21" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + INTEL_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "libdrm_intel >= 2.4.21" 2>&1` + else + INTEL_PKG_ERRORS=`$PKG_CONFIG --print-errors "libdrm_intel >= 2.4.21" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$INTEL_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements (libdrm_intel >= 2.4.21) were not met: + +$INTEL_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables INTEL_CFLAGS +and INTEL_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables INTEL_CFLAGS +and INTEL_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } + +else + INTEL_CFLAGS=$pkg_cv_INTEL_CFLAGS + INTEL_LIBS=$pkg_cv_INTEL_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +fi + ;; +esac + +case $DRI_DIRS in +*radeon*|*r200*|*r300*|*r600*) + if test "x$HAVE_LIBDRM_RADEON" = xyes; then + RADEON_CFLAGS="-DHAVE_LIBDRM_RADEON=1 $LIBDRM_RADEON_CFLAGS" + RADEON_LDFLAGS=$LIBDRM_RADEON_LIBS + fi + ;; +esac + + + + +if test "$mesa_driver" = xlib; then + default_gl_osmesa=yes +else + default_gl_osmesa=no +fi +# Check whether --enable-gl-osmesa was given. +if test "${enable_gl_osmesa+set}" = set; then : + enableval=$enable_gl_osmesa; gl_osmesa="$enableval" +else + gl_osmesa="$default_gl_osmesa" +fi + +if test "x$gl_osmesa" = xyes; then + if test "x$enable_opengl" = xno; then + as_fn_error $? "OpenGL is not available for OSMesa driver" "$LINENO" 5 + fi + if test "$mesa_driver" = osmesa; then + as_fn_error $? "libGL is not available for OSMesa driver" "$LINENO" 5 + else + DRIVER_DIRS="$DRIVER_DIRS osmesa" + fi +fi + + +# Check whether --with-osmesa-bits was given. +if test "${with_osmesa_bits+set}" = set; then : + withval=$with_osmesa_bits; osmesa_bits="$withval" +else + osmesa_bits=8 +fi + +if test "$mesa_driver" != osmesa && test "x$osmesa_bits" != x8; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Ignoring OSMesa channel bits for non-OSMesa driver" >&5 +$as_echo "$as_me: WARNING: Ignoring OSMesa channel bits for non-OSMesa driver" >&2;} + osmesa_bits=8 +fi +case "x$osmesa_bits" in +x8) + OSMESA_LIB=OSMesa + ;; +x16|x32) + OSMESA_LIB="OSMesa$osmesa_bits" + DEFINES="$DEFINES -DCHAN_BITS=$osmesa_bits -DDEFAULT_SOFTWARE_DEPTH_BITS=31" + ;; +*) + as_fn_error $? "OSMesa bits '$osmesa_bits' is not a valid option" "$LINENO" 5 + ;; +esac + + +case "$DRIVER_DIRS" in +*osmesa*) + # only link libraries with osmesa if shared + if test "$enable_static" = no; then + OSMESA_LIB_DEPS="-lm -lpthread $SELINUX_LIBS $DLOPEN_LIBS" + else + OSMESA_LIB_DEPS="" + fi + OSMESA_MESA_DEPS="" + OSMESA_PC_LIB_PRIV="-lm -lpthread $SELINUX_LIBS $DLOPEN_LIBS" + ;; +esac + + + + + +# Check whether --enable-egl was given. +if test "${enable_egl+set}" = set; then : + enableval=$enable_egl; enable_egl="$enableval" +else + enable_egl=yes +fi + +if test "x$enable_egl" = xno; then + if test "x$mesa_driver" = xno; then + as_fn_error $? "cannot disable EGL when there is no mesa driver" "$LINENO" 5 + fi + if test "x$enable_openvg" = xyes; then + as_fn_error $? "cannot enable OpenVG without EGL" "$LINENO" 5 + fi +fi +if test "x$enable_egl" = xyes; then + SRC_DIRS="$SRC_DIRS egl" + EGL_LIB_DEPS="$DLOPEN_LIBS -lpthread" + EGL_DRIVERS_DIRS="" + if test "$enable_static" != yes; then + # build egl_glx when libGL is built + if test "$mesa_driver" = xlib -o "$mesa_driver" = dri; then + EGL_DRIVERS_DIRS="glx" + fi + + if test "$mesa_driver" = dri; then + # build egl_dri2 when xcb-dri2 is available + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XCB_DRI2" >&5 +$as_echo_n "checking for XCB_DRI2... " >&6; } + +if test -n "$XCB_DRI2_CFLAGS"; then + pkg_cv_XCB_DRI2_CFLAGS="$XCB_DRI2_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11-xcb xcb-dri2 xcb-xfixes\""; } >&5 + ($PKG_CONFIG --exists --print-errors "x11-xcb xcb-dri2 xcb-xfixes") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_XCB_DRI2_CFLAGS=`$PKG_CONFIG --cflags "x11-xcb xcb-dri2 xcb-xfixes" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$XCB_DRI2_LIBS"; then + pkg_cv_XCB_DRI2_LIBS="$XCB_DRI2_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11-xcb xcb-dri2 xcb-xfixes\""; } >&5 + ($PKG_CONFIG --exists --print-errors "x11-xcb xcb-dri2 xcb-xfixes") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_XCB_DRI2_LIBS=`$PKG_CONFIG --libs "x11-xcb xcb-dri2 xcb-xfixes" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + XCB_DRI2_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "x11-xcb xcb-dri2 xcb-xfixes" 2>&1` + else + XCB_DRI2_PKG_ERRORS=`$PKG_CONFIG --print-errors "x11-xcb xcb-dri2 xcb-xfixes" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$XCB_DRI2_PKG_ERRORS" >&5 + + have_xcb_dri2=no +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + have_xcb_dri2=no +else + XCB_DRI2_CFLAGS=$pkg_cv_XCB_DRI2_CFLAGS + XCB_DRI2_LIBS=$pkg_cv_XCB_DRI2_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + have_xcb_dri2=yes +fi + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBUDEV" >&5 +$as_echo_n "checking for LIBUDEV... " >&6; } + +if test -n "$LIBUDEV_CFLAGS"; then + pkg_cv_LIBUDEV_CFLAGS="$LIBUDEV_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libudev > 150\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libudev > 150") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LIBUDEV_CFLAGS=`$PKG_CONFIG --cflags "libudev > 150" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$LIBUDEV_LIBS"; then + pkg_cv_LIBUDEV_LIBS="$LIBUDEV_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libudev > 150\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libudev > 150") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LIBUDEV_LIBS=`$PKG_CONFIG --libs "libudev > 150" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + LIBUDEV_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "libudev > 150" 2>&1` + else + LIBUDEV_PKG_ERRORS=`$PKG_CONFIG --print-errors "libudev > 150" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$LIBUDEV_PKG_ERRORS" >&5 + + have_libudev=no +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + have_libudev=no +else + LIBUDEV_CFLAGS=$pkg_cv_LIBUDEV_CFLAGS + LIBUDEV_LIBS=$pkg_cv_LIBUDEV_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + have_libudev=yes +fi + + if test "$have_xcb_dri2" = yes; then + EGL_DRIVER_DRI2=dri2 + DEFINES="$DEFINES -DHAVE_XCB_DRI2" + if test "$have_libudev" = yes; then + DEFINES="$DEFINES -DHAVE_LIBUDEV" + fi + fi + fi + + EGL_DRIVERS_DIRS="$EGL_DRIVERS_DIRS $EGL_DRIVER_DRI2" + fi +fi + + + +# Check whether --enable-glu was given. +if test "${enable_glu+set}" = set; then : + enableval=$enable_glu; enable_glu="$enableval" +else + enable_glu=yes +fi + + +if test "x$enable_glu" = xyes -a "x$mesa_driver" = xno; then + { $as_echo "$as_me:${as_lineno-$LINENO}: Disabling GLU since there is no OpenGL driver" >&5 +$as_echo "$as_me: Disabling GLU since there is no OpenGL driver" >&6;} + enable_glu=no +fi + +if test "x$enable_glu" = xyes; then + SRC_DIRS="$SRC_DIRS glu" + + case "$mesa_driver" in + osmesa) + # Link libGLU to libOSMesa instead of libGL + GLU_LIB_DEPS="" + GLU_PC_REQ="osmesa" + if test "$enable_static" = no; then + GLU_MESA_DEPS='-l$(OSMESA_LIB)' + else + GLU_MESA_DEPS="" + fi + ;; + *) + # If static, empty GLU_LIB_DEPS and add libs for programs to link + GLU_PC_REQ="gl" + GLU_PC_LIB_PRIV="-lm" + if test "$enable_static" = no; then + GLU_LIB_DEPS="-lm" + GLU_MESA_DEPS='-l$(GL_LIB)' + else + GLU_LIB_DEPS="" + GLU_MESA_DEPS="" + APP_LIB_DEPS="$APP_LIB_DEPS -lstdc++" + fi + ;; + esac +fi +if test "$enable_static" = no; then + GLU_LIB_DEPS="$GLU_LIB_DEPS $OS_CPLUSPLUS_LIBS" +fi +GLU_PC_LIB_PRIV="$GLU_PC_LIB_PRIV $OS_CPLUSPLUS_LIBS" + + + + + + + +# Check whether --enable-glw was given. +if test "${enable_glw+set}" = set; then : + enableval=$enable_glw; enable_glw="$enableval" +else + enable_glw=yes +fi + +if test "x$enable_glw" = xyes; then + case "$mesa_driver" in + osmesa|no) + { $as_echo "$as_me:${as_lineno-$LINENO}: Disabling GLw since there is no OpenGL driver" >&5 +$as_echo "$as_me: Disabling GLw since there is no OpenGL driver" >&6;} + enable_glw=no + ;; + esac +fi +# Check whether --enable-motif was given. +if test "${enable_motif+set}" = set; then : + enableval=$enable_motif; enable_motif="$enableval" +else + enable_motif=no +fi + + +if test "x$enable_glw" = xyes; then + SRC_DIRS="$SRC_DIRS glw" + if test "$x11_pkgconfig" = yes; then + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GLW" >&5 +$as_echo_n "checking for GLW... " >&6; } + +if test -n "$GLW_CFLAGS"; then + pkg_cv_GLW_CFLAGS="$GLW_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11 xt\""; } >&5 + ($PKG_CONFIG --exists --print-errors "x11 xt") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GLW_CFLAGS=`$PKG_CONFIG --cflags "x11 xt" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$GLW_LIBS"; then + pkg_cv_GLW_LIBS="$GLW_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11 xt\""; } >&5 + ($PKG_CONFIG --exists --print-errors "x11 xt") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GLW_LIBS=`$PKG_CONFIG --libs "x11 xt" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + GLW_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "x11 xt" 2>&1` + else + GLW_PKG_ERRORS=`$PKG_CONFIG --print-errors "x11 xt" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$GLW_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements (x11 xt) were not met: + +$GLW_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables GLW_CFLAGS +and GLW_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables GLW_CFLAGS +and GLW_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } + +else + GLW_CFLAGS=$pkg_cv_GLW_CFLAGS + GLW_LIBS=$pkg_cv_GLW_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +fi + GLW_PC_REQ_PRIV="x11 xt" + GLW_LIB_DEPS="$GLW_LIBS" + else + # should check these... + GLW_LIB_DEPS="$X_LIBS -lXt -lX11" + GLW_PC_LIB_PRIV="$GLW_LIB_DEPS" + GLW_PC_CFLAGS="$X11_INCLUDES" + fi + + GLW_SOURCES="GLwDrawA.c" + MOTIF_CFLAGS= + if test "x$enable_motif" = xyes; then + GLW_SOURCES="$GLW_SOURCES GLwMDrawA.c" + # Extract the first word of "motif-config", so it can be a program name with args. +set dummy motif-config; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_path_MOTIF_CONFIG+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + case $MOTIF_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_MOTIF_CONFIG="$MOTIF_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_path_MOTIF_CONFIG="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + test -z "$ac_cv_path_MOTIF_CONFIG" && ac_cv_path_MOTIF_CONFIG="no" + ;; +esac +fi +MOTIF_CONFIG=$ac_cv_path_MOTIF_CONFIG +if test -n "$MOTIF_CONFIG"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MOTIF_CONFIG" >&5 +$as_echo "$MOTIF_CONFIG" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + if test "x$MOTIF_CONFIG" != xno; then + MOTIF_CFLAGS=`$MOTIF_CONFIG --cflags` + MOTIF_LIBS=`$MOTIF_CONFIG --libs` + else + ac_fn_c_check_header_mongrel "$LINENO" "Xm/PrimitiveP.h" "ac_cv_header_Xm_PrimitiveP_h" "$ac_includes_default" +if test "x$ac_cv_header_Xm_PrimitiveP_h" = x""yes; then : + +else + as_fn_error $? "Can't locate Motif headers" "$LINENO" 5 +fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for XmGetPixmap in -lXm" >&5 +$as_echo_n "checking for XmGetPixmap in -lXm... " >&6; } +if test "${ac_cv_lib_Xm_XmGetPixmap+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lXm $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char XmGetPixmap (); +int +main () +{ +return XmGetPixmap (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_Xm_XmGetPixmap=yes +else + ac_cv_lib_Xm_XmGetPixmap=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_Xm_XmGetPixmap" >&5 +$as_echo "$ac_cv_lib_Xm_XmGetPixmap" >&6; } +if test "x$ac_cv_lib_Xm_XmGetPixmap" = x""yes; then : + MOTIF_LIBS="-lXm" +else + as_fn_error $? "Can't locate Motif Xm library" "$LINENO" 5 +fi + + fi + # MOTIF_LIBS is prepended to GLW_LIB_DEPS since Xm needs Xt/X11 + GLW_LIB_DEPS="$MOTIF_LIBS $GLW_LIB_DEPS" + GLW_PC_LIB_PRIV="$MOTIF_LIBS $GLW_PC_LIB_PRIV" + GLW_PC_CFLAGS="$MOTIF_CFLAGS $GLW_PC_CFLAGS" + fi + + # If static, empty GLW_LIB_DEPS and add libs for programs to link + GLW_PC_LIB_PRIV="$GLW_PC_LIB_PRIV" + if test "$enable_static" = no; then + GLW_MESA_DEPS='-l$(GL_LIB)' + GLW_LIB_DEPS="$GLW_LIB_DEPS" + else + APP_LIB_DEPS="$APP_LIB_DEPS $GLW_LIB_DEPS" + GLW_LIB_DEPS="" + GLW_MESA_DEPS="" + fi +fi + + + + + + + + +if test -f "$srcdir/include/GL/glut.h"; then + default_glut=yes +else + default_glut=no +fi +# Check whether --enable-glut was given. +if test "${enable_glut+set}" = set; then : + enableval=$enable_glut; enable_glut="$enableval" +else + enable_glut="$default_glut" +fi + + +if test "x$enable_glut" = xyes; then + case "$mesa_driver" in + osmesa|no) + { $as_echo "$as_me:${as_lineno-$LINENO}: Disabling glut since there is no OpenGL driver" >&5 +$as_echo "$as_me: Disabling glut since there is no OpenGL driver" >&6;} + enable_glut=no + ;; + esac +fi +if test "x$enable_glu$enable_glut" = xnoyes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Disabling glut since GLU is disabled" >&5 +$as_echo "$as_me: WARNING: Disabling glut since GLU is disabled" >&2;} + enable_glut=no +fi + +if test "x$enable_glut" = xyes; then + SRC_DIRS="$SRC_DIRS glut/glx" + if test "$x11_pkgconfig" = yes; then + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GLUT" >&5 +$as_echo_n "checking for GLUT... " >&6; } + +if test -n "$GLUT_CFLAGS"; then + pkg_cv_GLUT_CFLAGS="$GLUT_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11 xmu xi\""; } >&5 + ($PKG_CONFIG --exists --print-errors "x11 xmu xi") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GLUT_CFLAGS=`$PKG_CONFIG --cflags "x11 xmu xi" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$GLUT_LIBS"; then + pkg_cv_GLUT_LIBS="$GLUT_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11 xmu xi\""; } >&5 + ($PKG_CONFIG --exists --print-errors "x11 xmu xi") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GLUT_LIBS=`$PKG_CONFIG --libs "x11 xmu xi" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + GLUT_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "x11 xmu xi" 2>&1` + else + GLUT_PKG_ERRORS=`$PKG_CONFIG --print-errors "x11 xmu xi" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$GLUT_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements (x11 xmu xi) were not met: + +$GLUT_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables GLUT_CFLAGS +and GLUT_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables GLUT_CFLAGS +and GLUT_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } + +else + GLUT_CFLAGS=$pkg_cv_GLUT_CFLAGS + GLUT_LIBS=$pkg_cv_GLUT_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +fi + GLUT_PC_REQ_PRIV="x11 xmu xi" + GLUT_LIB_DEPS="$GLUT_LIBS" + else + # should check these... + GLUT_LIB_DEPS="$X_LIBS -lX11 -lXmu -lXi" + GLUT_PC_LIB_PRIV="$GLUT_LIB_DEPS" + GLUT_PC_CFLAGS="$X11_INCLUDES" + fi + if test "x$GCC" = xyes; then + GLUT_CFLAGS="$GLUT_CFLAGS -fexceptions" + fi + GLUT_LIB_DEPS="$GLUT_LIB_DEPS -lm" + GLUT_PC_LIB_PRIV="$GLUT_PC_LIB_PRIV -lm" + + # If static, empty GLUT_LIB_DEPS and add libs for programs to link + if test "$enable_static" = no; then + GLUT_MESA_DEPS='-l$(GLU_LIB) -l$(GL_LIB)' + else + APP_LIB_DEPS="$APP_LIB_DEPS $GLUT_LIB_DEPS" + GLUT_LIB_DEPS="" + GLUT_MESA_DEPS="" + fi +fi + + + + + + + +if test "x$APP_LIB_DEPS" = x; then + case "$host_os" in + solaris*) + APP_LIB_DEPS="-lX11 -lsocket -lnsl -lm" + ;; + cygwin*) + APP_LIB_DEPS="-lX11" + ;; + *) + APP_LIB_DEPS="-lm" + ;; + esac +fi + + + +# Check whether --enable-gallium was given. +if test "${enable_gallium+set}" = set; then : + enableval=$enable_gallium; enable_gallium="$enableval" +else + enable_gallium=yes +fi + +if test "x$enable_gallium" = xno -a "x$enable_openvg" = xyes; then + as_fn_error $? "cannot enable OpenVG without Gallium" "$LINENO" 5 +fi +if test "x$enable_gallium" = xyes; then + SRC_DIRS="$SRC_DIRS gallium gallium/winsys gallium/targets" + ac_fn_c_check_header_mongrel "$LINENO" "udis86.h" "ac_cv_header_udis86_h" "$ac_includes_default" +if test "x$ac_cv_header_udis86_h" = x""yes; then : + HAS_UDIS86="yes" +else + HAS_UDIS86="no" +fi + + + # Extract the first word of "llvm-config", so it can be a program name with args. +set dummy llvm-config; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_path_LLVM_CONFIG+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + case $LLVM_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_LLVM_CONFIG="$LLVM_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_path_LLVM_CONFIG="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + test -z "$ac_cv_path_LLVM_CONFIG" && ac_cv_path_LLVM_CONFIG="no" + ;; +esac +fi +LLVM_CONFIG=$ac_cv_path_LLVM_CONFIG +if test -n "$LLVM_CONFIG"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LLVM_CONFIG" >&5 +$as_echo "$LLVM_CONFIG" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi + + + + + + + +# Check whether --enable-gallium-egl was given. +if test "${enable_gallium_egl+set}" = set; then : + enableval=$enable_gallium_egl; enable_gallium_egl="$enableval" +else + enable_gallium_egl=auto +fi + +if test "x$enable_gallium_egl" = xauto; then + case "$mesa_driver" in + dri|no) + enable_gallium_egl=$enable_egl + ;; + *) + enable_gallium_egl=$enable_openvg + ;; + esac +fi +case "x$enable_egl$enable_gallium_egl" in +xnoyes) + as_fn_error $? "cannot build Gallium EGL state tracker without EGL" "$LINENO" 5 +esac + + +# Check whether --with-state-trackers was given. +if test "${with_state_trackers+set}" = set; then : + withval=$with_state_trackers; with_state_trackers="$withval" +else + with_state_trackers=yes +fi + + +case "$with_state_trackers" in +no) + GALLIUM_STATE_TRACKERS_DIRS="" + ;; +yes) + # look at what else is built + case "$mesa_driver" in + xlib) + GALLIUM_STATE_TRACKERS_DIRS=glx + ;; + dri) + GALLIUM_STATE_TRACKERS_DIRS="dri" + HAVE_ST_DRI="yes" + # Have only tested st/xorg on 1.6.0 servers + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XORG" >&5 +$as_echo_n "checking for XORG... " >&6; } + +if test -n "$XORG_CFLAGS"; then + pkg_cv_XORG_CFLAGS="$XORG_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xorg-server >= 1.6.0 libdrm >= \$LIBDRM_XORG_REQUIRED libkms >= \$LIBKMS_XORG_REQUIRED\""; } >&5 + ($PKG_CONFIG --exists --print-errors "xorg-server >= 1.6.0 libdrm >= $LIBDRM_XORG_REQUIRED libkms >= $LIBKMS_XORG_REQUIRED") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_XORG_CFLAGS=`$PKG_CONFIG --cflags "xorg-server >= 1.6.0 libdrm >= $LIBDRM_XORG_REQUIRED libkms >= $LIBKMS_XORG_REQUIRED" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$XORG_LIBS"; then + pkg_cv_XORG_LIBS="$XORG_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xorg-server >= 1.6.0 libdrm >= \$LIBDRM_XORG_REQUIRED libkms >= \$LIBKMS_XORG_REQUIRED\""; } >&5 + ($PKG_CONFIG --exists --print-errors "xorg-server >= 1.6.0 libdrm >= $LIBDRM_XORG_REQUIRED libkms >= $LIBKMS_XORG_REQUIRED") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_XORG_LIBS=`$PKG_CONFIG --libs "xorg-server >= 1.6.0 libdrm >= $LIBDRM_XORG_REQUIRED libkms >= $LIBKMS_XORG_REQUIRED" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + XORG_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "xorg-server >= 1.6.0 libdrm >= $LIBDRM_XORG_REQUIRED libkms >= $LIBKMS_XORG_REQUIRED" 2>&1` + else + XORG_PKG_ERRORS=`$PKG_CONFIG --print-errors "xorg-server >= 1.6.0 libdrm >= $LIBDRM_XORG_REQUIRED libkms >= $LIBKMS_XORG_REQUIRED" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$XORG_PKG_ERRORS" >&5 + + HAVE_ST_XORG="no" +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + HAVE_ST_XORG="no" +else + XORG_CFLAGS=$pkg_cv_XORG_CFLAGS + XORG_LIBS=$pkg_cv_XORG_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + HAVE_ST_XORG="yes"; GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg" +fi + ;; + esac + + if test "x$enable_egl" = xyes; then + if test "$enable_openvg" = yes; then + GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS vega" + st_egl="yes" + fi + + if test "$enable_gallium_egl" = yes; then + GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl" + HAVE_ST_EGL="yes" + fi + fi + ;; +*) + # verify the requested state tracker exist + state_trackers="" + _state_trackers=`IFS=', '; echo $with_state_trackers` + for tracker in $_state_trackers; do + case "$tracker" in + dri) + if test "x$mesa_driver" != xdri; then + as_fn_error $? "cannot build dri state tracker without mesa driver set to dri" "$LINENO" 5 + fi + HAVE_ST_DRI="yes" + ;; + egl) + if test "x$enable_egl" != xyes; then + as_fn_error $? "cannot build egl state tracker without EGL library" "$LINENO" 5 + fi + HAVE_ST_EGL="yes" + ;; + xorg) + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XORG" >&5 +$as_echo_n "checking for XORG... " >&6; } + +if test -n "$XORG_CFLAGS"; then + pkg_cv_XORG_CFLAGS="$XORG_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xorg-server >= 1.6.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "xorg-server >= 1.6.0") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_XORG_CFLAGS=`$PKG_CONFIG --cflags "xorg-server >= 1.6.0" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$XORG_LIBS"; then + pkg_cv_XORG_LIBS="$XORG_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xorg-server >= 1.6.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "xorg-server >= 1.6.0") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_XORG_LIBS=`$PKG_CONFIG --libs "xorg-server >= 1.6.0" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + XORG_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "xorg-server >= 1.6.0" 2>&1` + else + XORG_PKG_ERRORS=`$PKG_CONFIG --print-errors "xorg-server >= 1.6.0" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$XORG_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements (xorg-server >= 1.6.0) were not met: + +$XORG_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables XORG_CFLAGS +and XORG_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables XORG_CFLAGS +and XORG_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } + +else + XORG_CFLAGS=$pkg_cv_XORG_CFLAGS + XORG_LIBS=$pkg_cv_XORG_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +fi + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBDRM_XORG" >&5 +$as_echo_n "checking for LIBDRM_XORG... " >&6; } + +if test -n "$LIBDRM_XORG_CFLAGS"; then + pkg_cv_LIBDRM_XORG_CFLAGS="$LIBDRM_XORG_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm >= \$LIBDRM_XORG_REQUIRED\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libdrm >= $LIBDRM_XORG_REQUIRED") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LIBDRM_XORG_CFLAGS=`$PKG_CONFIG --cflags "libdrm >= $LIBDRM_XORG_REQUIRED" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$LIBDRM_XORG_LIBS"; then + pkg_cv_LIBDRM_XORG_LIBS="$LIBDRM_XORG_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm >= \$LIBDRM_XORG_REQUIRED\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libdrm >= $LIBDRM_XORG_REQUIRED") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LIBDRM_XORG_LIBS=`$PKG_CONFIG --libs "libdrm >= $LIBDRM_XORG_REQUIRED" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + LIBDRM_XORG_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "libdrm >= $LIBDRM_XORG_REQUIRED" 2>&1` + else + LIBDRM_XORG_PKG_ERRORS=`$PKG_CONFIG --print-errors "libdrm >= $LIBDRM_XORG_REQUIRED" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$LIBDRM_XORG_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements (libdrm >= $LIBDRM_XORG_REQUIRED) were not met: + +$LIBDRM_XORG_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables LIBDRM_XORG_CFLAGS +and LIBDRM_XORG_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables LIBDRM_XORG_CFLAGS +and LIBDRM_XORG_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } + +else + LIBDRM_XORG_CFLAGS=$pkg_cv_LIBDRM_XORG_CFLAGS + LIBDRM_XORG_LIBS=$pkg_cv_LIBDRM_XORG_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +fi + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBKMS_XORG" >&5 +$as_echo_n "checking for LIBKMS_XORG... " >&6; } + +if test -n "$LIBKMS_XORG_CFLAGS"; then + pkg_cv_LIBKMS_XORG_CFLAGS="$LIBKMS_XORG_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libkms >= \$LIBKMS_XORG_REQUIRED\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libkms >= $LIBKMS_XORG_REQUIRED") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LIBKMS_XORG_CFLAGS=`$PKG_CONFIG --cflags "libkms >= $LIBKMS_XORG_REQUIRED" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$LIBKMS_XORG_LIBS"; then + pkg_cv_LIBKMS_XORG_LIBS="$LIBKMS_XORG_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libkms >= \$LIBKMS_XORG_REQUIRED\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libkms >= $LIBKMS_XORG_REQUIRED") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LIBKMS_XORG_LIBS=`$PKG_CONFIG --libs "libkms >= $LIBKMS_XORG_REQUIRED" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + LIBKMS_XORG_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "libkms >= $LIBKMS_XORG_REQUIRED" 2>&1` + else + LIBKMS_XORG_PKG_ERRORS=`$PKG_CONFIG --print-errors "libkms >= $LIBKMS_XORG_REQUIRED" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$LIBKMS_XORG_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements (libkms >= $LIBKMS_XORG_REQUIRED) were not met: + +$LIBKMS_XORG_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables LIBKMS_XORG_CFLAGS +and LIBKMS_XORG_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables LIBKMS_XORG_CFLAGS +and LIBKMS_XORG_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } + +else + LIBKMS_XORG_CFLAGS=$pkg_cv_LIBKMS_XORG_CFLAGS + LIBKMS_XORG_LIBS=$pkg_cv_LIBKMS_XORG_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +fi + HAVE_ST_XORG="yes" + ;; + vega) + if test "x$enable_openvg" != xyes; then + as_fn_error $? "cannot build vega state tracker without --enable-openvg" "$LINENO" 5 + fi + ;; + esac + + if test -n "$tracker"; then + test -d "$srcdir/src/gallium/state_trackers/$tracker" || \ + as_fn_error $? "state tracker '$tracker' doesn't exist" "$LINENO" 5 + if test -n "$state_trackers"; then + state_trackers="$state_trackers $tracker" + else + state_trackers="$tracker" + fi + fi + done + GALLIUM_STATE_TRACKERS_DIRS="$state_trackers" + ;; +esac + + +EGL_CLIENT_APIS="" +VG_LIB_DEPS="" + +case "x$enable_opengl$enable_gles1$enable_gles2" in +x*yes*) + EGL_CLIENT_APIS="$EGL_CLIENT_APIS "'$(GL_LIB)' + ;; +esac +if test "x$enable_gles_overlay" = xyes; then + EGL_CLIENT_APIS="$EGL_CLIENT_APIS "'$(GLESv1_CM_LIB) $(GLESv2_LIB)' +fi +if test "x$enable_openvg" = xyes; then + EGL_CLIENT_APIS="$EGL_CLIENT_APIS "'$(VG_LIB)' + VG_LIB_DEPS="$VG_LIB_DEPS -lpthread" +fi + + + + +if test "x$HAVE_ST_EGL" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl" +fi + +if test "x$HAVE_ST_XORG" = xyes; then + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XEXT" >&5 +$as_echo_n "checking for XEXT... " >&6; } + +if test -n "$XEXT_CFLAGS"; then + pkg_cv_XEXT_CFLAGS="$XEXT_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xextproto >= 7.0.99.1\""; } >&5 + ($PKG_CONFIG --exists --print-errors "xextproto >= 7.0.99.1") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_XEXT_CFLAGS=`$PKG_CONFIG --cflags "xextproto >= 7.0.99.1" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$XEXT_LIBS"; then + pkg_cv_XEXT_LIBS="$XEXT_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xextproto >= 7.0.99.1\""; } >&5 + ($PKG_CONFIG --exists --print-errors "xextproto >= 7.0.99.1") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_XEXT_LIBS=`$PKG_CONFIG --libs "xextproto >= 7.0.99.1" 2>/dev/null` +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + XEXT_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "xextproto >= 7.0.99.1" 2>&1` + else + XEXT_PKG_ERRORS=`$PKG_CONFIG --print-errors "xextproto >= 7.0.99.1" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$XEXT_PKG_ERRORS" >&5 + + HAVE_XEXTPROTO_71="no" +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + HAVE_XEXTPROTO_71="no" +else + XEXT_CFLAGS=$pkg_cv_XEXT_CFLAGS + XEXT_LIBS=$pkg_cv_XEXT_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + HAVE_XEXTPROTO_71="yes"; DEFINES="$DEFINES -DHAVE_XEXTPROTO_71" +fi +fi + + +# Check whether --with-egl-platforms was given. +if test "${with_egl_platforms+set}" = set; then : + withval=$with_egl_platforms; with_egl_platforms="$withval" +else + with_egl_platforms=yes +fi + + +# Check whether --with-egl-displays was given. +if test "${with_egl_displays+set}" = set; then : + withval=$with_egl_displays; with_egl_platforms="$withval" +fi + + +EGL_PLATFORMS="" +case "$with_egl_platforms" in +yes) + if test "x$enable_egl" = xyes && test "x$mesa_driver" != xosmesa; then + EGL_PLATFORMS="x11" + if test "$mesa_driver" = dri; then + EGL_PLATFORMS="$EGL_PLATFORMS drm" + fi + fi + ;; +*) + if test "x$enable_egl" != xyes; then + as_fn_error $? "cannot build egl state tracker without EGL library" "$LINENO" 5 + fi + # verify the requested driver directories exist + egl_platforms=`IFS=', '; echo $with_egl_platforms` + for plat in $egl_platforms; do + test -d "$srcdir/src/gallium/state_trackers/egl/$plat" || \ + as_fn_error $? "EGL platform '$plat' does't exist" "$LINENO" 5 + if test "$plat" = "fbdev"; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/fbdev" + fi + done + EGL_PLATFORMS="$egl_platforms" + ;; +esac + + + +# Check whether --with-egl-driver-dir was given. +if test "${with_egl_driver_dir+set}" = set; then : + withval=$with_egl_driver_dir; EGL_DRIVER_INSTALL_DIR="$withval" +else + EGL_DRIVER_INSTALL_DIR='${libdir}/egl' +fi + + + + +# Check whether --with-xorg-driver-dir was given. +if test "${with_xorg_driver_dir+set}" = set; then : + withval=$with_xorg_driver_dir; XORG_DRIVER_INSTALL_DIR="$withval" +else + XORG_DRIVER_INSTALL_DIR="${libdir}/xorg/modules/drivers" +fi + + + + +# Check whether --with-max-width was given. +if test "${with_max_width+set}" = set; then : + withval=$with_max_width; DEFINES="${DEFINES} -DMAX_WIDTH=${withval}"; + if test "${withval}" -gt "4096"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Large framebuffer: see s_tritemp.h comments." >&5 +$as_echo "$as_me: WARNING: Large framebuffer: see s_tritemp.h comments." >&2;} +fi + +fi + + +# Check whether --with-max-height was given. +if test "${with_max_height+set}" = set; then : + withval=$with_max_height; DEFINES="${DEFINES} -DMAX_HEIGHT=${withval}"; + if test "${withval}" -gt "4096"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Large framebuffer: see s_tritemp.h comments." >&5 +$as_echo "$as_me: WARNING: Large framebuffer: see s_tritemp.h comments." >&2;} +fi + +fi + + +# Check whether --enable-gallium-llvm was given. +if test "${enable_gallium_llvm+set}" = set; then : + enableval=$enable_gallium_llvm; enable_gallium_llvm="$enableval" +else + enable_gallium_llvm=auto +fi + +if test "x$enable_gallium_llvm" = xyes; then + if test "x$LLVM_CONFIG" != xno; then + LLVM_VERSION=`$LLVM_CONFIG --version` + LLVM_CFLAGS=`$LLVM_CONFIG --cppflags` + 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 + LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags` + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS llvmpipe" + DEFINES="$DEFINES -DGALLIUM_LLVMPIPE -D__STDC_CONSTANT_MACROS" + MESA_LLVM=1 + else + MESA_LLVM=0 + fi +else + MESA_LLVM=0 +fi + +gallium_check_st() { + if test "x$HAVE_ST_DRI" = 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_XORG" = xyes && test "x$3" != x; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $3" + fi +} + + +# Check whether --enable-gallium-svga was given. +if test "${enable_gallium_svga+set}" = set; then : + enableval=$enable_gallium_svga; enable_gallium_svga="$enableval" +else + enable_gallium_svga=auto +fi + +if test "x$enable_gallium_svga" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" + gallium_check_st "svga/drm" "dri-vmwgfx" "xorg-vmwgfx" +elif test "x$enable_gallium_svga" = xauto; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" +fi + +# Check whether --enable-gallium-i915 was given. +if test "${enable_gallium_i915+set}" = set; then : + enableval=$enable_gallium_i915; enable_gallium_i915="$enableval" +else + enable_gallium_i915=auto +fi + +if test "x$enable_gallium_i915" = xyes; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw" + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915" + gallium_check_st "i915/drm" "dri-i915" "xorg-i915" +elif test "x$enable_gallium_i915" = xauto; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw" + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915" +fi + +# Check whether --enable-gallium-i965 was given. +if test "${enable_gallium_i965+set}" = set; then : + enableval=$enable_gallium_i965; enable_gallium_i965="$enableval" +else + enable_gallium_i965=auto +fi + +if test "x$enable_gallium_i965" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i965" + gallium_check_st "i965/drm" "dri-i965" "xorg-i965" +elif test "x$enable_gallium_i965" = xauto; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i965" +fi + +# Check whether --enable-gallium-radeon was given. +if test "${enable_gallium_radeon+set}" = set; then : + enableval=$enable_gallium_radeon; enable_gallium_radeon="$enableval" +else + enable_gallium_radeon=auto +fi + +if test "x$enable_gallium_radeon" = xauto; then + if test "x$HAVE_LIBDRM_RADEON" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" + gallium_check_st "radeon/drm" "dri-r300" + else + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: libdrm_radeon is missing, not building gallium-radeon (r300)" >&5 +$as_echo "$as_me: WARNING: libdrm_radeon is missing, not building gallium-radeon (r300)" >&2;} + fi +fi +if test "x$enable_gallium_radeon" = xyes; then + if test "x$HAVE_LIBDRM_RADEON" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" + gallium_check_st "radeon/drm" "dri-r300" "xorg-radeon" + else + as_fn_error $? "libdrm_radeon is missing, cannot build gallium-radeon (r300)" "$LINENO" 5 + fi +fi + +# Check whether --enable-gallium-r600 was given. +if test "${enable_gallium_r600+set}" = set; then : + enableval=$enable_gallium_r600; enable_gallium_r600="$enableval" +else + enable_gallium_r600=auto +fi + +if test "x$enable_gallium_r600" = xyes; then + if test "x$HAVE_LIBDRM_RADEON" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r600" + gallium_check_st "r600/drm" "dri-r600" + else + as_fn_error $? "libdrm_radeon is missing, cannot build gallium-r600" "$LINENO" 5 + fi +fi + +# Check whether --enable-gallium-nouveau was given. +if test "${enable_gallium_nouveau+set}" = set; then : + enableval=$enable_gallium_nouveau; enable_gallium_nouveau="$enableval" +else + enable_gallium_nouveau=no +fi + +if test "x$enable_gallium_nouveau" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50" + gallium_check_st "nouveau/drm" "dri-nouveau" "xorg-nouveau" +fi + +# Check whether --enable-gallium-swrast was given. +if test "${enable_gallium_swrast+set}" = set; then : + enableval=$enable_gallium_swrast; enable_gallium_swrast="$enableval" +else + enable_gallium_swrast=auto +fi + +if test "x$enable_gallium_swrast" = xyes || test "x$enable_gallium_swrast" = xauto; then + if test "x$HAVE_ST_DRI" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-swrast" + fi +fi + +# Check whether --enable-gallium-noop was given. +if test "${enable_gallium_noop+set}" = set; then : + enableval=$enable_gallium_noop; enable_gallium_noop="$enableval" +else + enable_gallium_noop=auto +fi + +if test "x$enable_gallium_noop" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS noop" + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-noop" +fi + +SRC_DIRS="$CORE_DIRS $SRC_DIRS" + +LDFLAGS="$_SAVE_LDFLAGS" +CPPFLAGS="$_SAVE_CPPFLAGS" + +ac_config_files="$ac_config_files configs/autoconf" + + +ac_config_commands="$ac_config_commands configs" + + +cat >confcache <<\_ACEOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. +# +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. +# +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, we kill variables containing newlines. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes: double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \. + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + test "x$cache_file" != "x/dev/null" && + { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 +$as_echo "$as_me: updating cache $cache_file" >&6;} + cat confcache >$cache_file + else + { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 +$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} + fi +fi +rm -f confcache + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +# Transform confdefs.h into DEFS. +# Protect against shell expansion while executing Makefile rules. +# Protect against Makefile macro expansion. +# +# If the first sed substitution is executed (which looks for macros that +# take arguments), then branch to the quote section. Otherwise, +# look for a macro that doesn't take arguments. +ac_script=' +:mline +/\\$/{ + N + s,\\\n,, + b mline +} +t clear +:clear +s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\)/-D\1=\2/g +t quote +s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g +t quote +b any +:quote +s/[ `~#$^&*(){}\\|;'\''"<>?]/\\&/g +s/\[/\\&/g +s/\]/\\&/g +s/\$/$$/g +H +:any +${ + g + s/^\n// + s/\n/ /g + p +} +' +DEFS=`sed -n "$ac_script" confdefs.h` + + +ac_libobjs= +ac_ltlibobjs= +U= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`$as_echo "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" + as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + + + +: ${CONFIG_STATUS=./config.status} +ac_write_fail=0 +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files $CONFIG_STATUS" +{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 +$as_echo "$as_me: creating $CONFIG_STATUS" >&6;} +as_write_fail=0 +cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 +#! $SHELL +# Generated by $as_me. +# Run this file to recreate the current configuration. +# Compiler output produced by configure, useful for debugging +# configure, is in config.log if it exists. + +debug=false +ac_cs_recheck=false +ac_cs_silent=false + +SHELL=\${CONFIG_SHELL-$SHELL} +export SHELL +_ASEOF +cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in #( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in #(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + + +# as_fn_error STATUS ERROR [LINENO LOG_FD] +# ---------------------------------------- +# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are +# provided, also output the error to LOG_FD, referencing LINENO. Then exit the +# script with STATUS, using 1 if that was 0. +as_fn_error () +{ + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + fi + $as_echo "$as_me: error: $2" >&2 + as_fn_exit $as_status +} # as_fn_error + + +# as_fn_set_status STATUS +# ----------------------- +# Set $? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} # as_fn_set_status + +# as_fn_exit STATUS +# ----------------- +# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} # as_fn_exit + +# as_fn_unset VAR +# --------------- +# Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset +# as_fn_append VAR VALUE +# ---------------------- +# Append the text in VALUE to the end of the definition contained in VAR. Take +# advantage of any shell optimizations that allow amortized linear growth over +# repeated appends, instead of the typical quadratic growth present in naive +# implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +# as_fn_arith ARG... +# ------------------ +# Perform arithmetic evaluation on the ARGs, and store the result in the +# global $as_val. Take advantage of shells that can avoid forks. The arguments +# must be portable across $(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in #((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -p' + fi +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + + +# as_fn_mkdir_p +# ------------- +# Create "$as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" + + +} # as_fn_mkdir_p +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 +## ----------------------------------- ## +## Main body of $CONFIG_STATUS script. ## +## ----------------------------------- ## +_ASEOF +test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# Save the log message, to keep $0 and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by Mesa $as_me 7.10.0, which was +generated by GNU Autoconf 2.66. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +case $ac_config_files in *" +"*) set x $ac_config_files; shift; ac_config_files=$*;; +esac + + + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +# Files that config.status was made for. +config_files="$ac_config_files" +config_commands="$ac_config_commands" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +ac_cs_usage="\ +\`$as_me' instantiates files and other configuration actions +from templates according to the current configuration. Unless the files +and actions are specified as TAGs, all are instantiated by default. + +Usage: $0 [OPTION]... [TAG]... + + -h, --help print this help, then exit + -V, --version print version number and configuration settings, then exit + --config print configuration, then exit + -q, --quiet, --silent + do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + +Configuration files: +$config_files + +Configuration commands: +$config_commands + +Report bugs to ." + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" +ac_cs_version="\\ +Mesa config.status 7.10.0 +configured by $0, generated by GNU Autoconf 2.66, + with options \\"\$ac_cs_config\\" + +Copyright (C) 2010 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +INSTALL='$INSTALL' +test -n "\$AWK" || AWK=awk +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# The default lists apply if the user does not specify any file. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; + esac + + case $ac_option in + # Handling of the options. + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + $as_echo "$ac_cs_version"; exit ;; + --config | --confi | --conf | --con | --co | --c ) + $as_echo "$ac_cs_config"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append CONFIG_FILES " '$ac_optarg'" + ac_need_defaults=false;; + --he | --h | --help | --hel | -h ) + $as_echo "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; + + # This is an error. + -*) as_fn_error $? "unrecognized option: \`$1' +Try \`$0 --help' for more information." ;; + + *) as_fn_append ac_config_targets " $1" + ac_need_defaults=false ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +if \$ac_cs_recheck; then + set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + shift + \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 + CONFIG_SHELL='$SHELL' + export CONFIG_SHELL + exec "\$@" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX + $as_echo "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "configs/autoconf") CONFIG_FILES="$CONFIG_FILES configs/autoconf" ;; + "configs") CONFIG_COMMANDS="$CONFIG_COMMANDS configs" ;; + + *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; + esac +done + + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files + test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= + trap 'exit_status=$? + { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status +' 0 + trap 'as_fn_exit 1' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 + +# Set up the scripts for CONFIG_FILES section. +# No need to generate them if there are no CONFIG_FILES. +# This happens for instance with `./config.status config.h'. +if test -n "$CONFIG_FILES"; then + + +ac_cr=`echo X | tr X '\015'` +# On cygwin, bash can eat \r inside `` if the user requested igncr. +# But we know of no other shell where ac_cr would be empty at this +# point, so we can use a bashism as a fallback. +if test "x$ac_cr" = x; then + eval ac_cr=\$\'\\r\' +fi +ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` +if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then + ac_cs_awk_cr='\\r' +else + ac_cs_awk_cr=$ac_cr +fi + +echo 'BEGIN {' >"$tmp/subs1.awk" && +_ACEOF + + +{ + echo "cat >conf$$subs.awk <<_ACEOF" && + echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && + echo "_ACEOF" +} >conf$$subs.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 +ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + . ./conf$$subs.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 + + ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` + if test $ac_delim_n = $ac_delim_num; then + break + elif $ac_last_try; then + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done +rm -f conf$$subs.sh + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +cat >>"\$tmp/subs1.awk" <<\\_ACAWK && +_ACEOF +sed -n ' +h +s/^/S["/; s/!.*/"]=/ +p +g +s/^[^!]*!// +:repl +t repl +s/'"$ac_delim"'$// +t delim +:nl +h +s/\(.\{148\}\)..*/\1/ +t more1 +s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ +p +n +b repl +:more1 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t nl +:delim +h +s/\(.\{148\}\)..*/\1/ +t more2 +s/["\\]/\\&/g; s/^/"/; s/$/"/ +p +b +:more2 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t delim +' >$CONFIG_STATUS || ac_write_fail=1 +rm -f conf$$subs.awk +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +_ACAWK +cat >>"\$tmp/subs1.awk" <<_ACAWK && + for (key in S) S_is_set[key] = 1 + FS = "" + +} +{ + line = $ 0 + nfields = split(line, field, "@") + substed = 0 + len = length(field[1]) + for (i = 2; i < nfields; i++) { + key = field[i] + keylen = length(key) + if (S_is_set[key]) { + value = S[key] + line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) + len += length(value) + length(field[++i]) + substed = 1 + } else + len += 1 + keylen + } + + print line +} + +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then + sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" +else + cat +fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \ + || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 +_ACEOF + +# VPATH may cause trouble with some makes, so we remove sole $(srcdir), +# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ +h +s/// +s/^/:/ +s/[ ]*$/:/ +s/:\$(srcdir):/:/g +s/:\${srcdir}:/:/g +s/:@srcdir@:/:/g +s/^:*// +s/:*$// +x +s/\(=[ ]*\).*/\1/ +G +s/\n// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +fi # test -n "$CONFIG_FILES" + + +eval set X " :F $CONFIG_FILES :C $CONFIG_COMMANDS" +shift +for ac_tag +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; + esac + case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac + as_fn_append ac_file_inputs " '$ac_f'" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input='Generated from '` + $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' + `' by configure.' + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 +$as_echo "$as_me: creating $ac_file" >&6;} + fi + # Neutralize special characters interpreted by sed in replacement strings. + case $configure_input in #( + *\&* | *\|* | *\\* ) + ac_sed_conf_input=`$as_echo "$configure_input" | + sed 's/[\\\\&|]/\\\\&/g'`;; #( + *) ac_sed_conf_input=$configure_input;; + esac + + case $ac_tag in + *:-:* | *:-) cat >"$tmp/stdin" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; + esac + ;; + esac + + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + as_dir="$ac_dir"; as_fn_mkdir_p + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + + case $ac_mode in + :F) + # + # CONFIG_FILE + # + + case $INSTALL in + [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; + *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; + esac +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= +ac_sed_dataroot=' +/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p' +case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_sed_extra="$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s|@configure_input@|$ac_sed_conf_input|;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@top_build_prefix@&$ac_top_build_prefix&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +s&@INSTALL@&$ac_INSTALL&;t t +$ac_datarootdir_hack +" +eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } && + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined" >&5 +$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined" >&2;} + + rm -f "$tmp/stdin" + case $ac_file in + -) cat "$tmp/out" && rm -f "$tmp/out";; + *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";; + esac \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + ;; + + + :C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 +$as_echo "$as_me: executing $ac_file commands" >&6;} + ;; + esac + + + case $ac_file$ac_mode in + "configs":C) +if test -f configs/current || test -L configs/current; then + rm -f configs/current +fi +ln -s autoconf configs/current + ;; + + esac +done # for ac_tag + + +as_fn_exit 0 +_ACEOF +ac_clean_files=$ac_clean_files_save + +test $ac_write_fail = 0 || + as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || as_fn_exit 1 +fi +if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 +$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} +fi + + +echo "" +echo " prefix: $prefix" +echo " exec_prefix: $exec_prefix" +echo " libdir: $libdir" +echo " includedir: $includedir" + +echo "" +echo " OpenGL: $enable_opengl (ES1: $enable_gles1 ES2: $enable_gles2)" +echo " GLES overlay: $enable_gles_overlay" +echo " OpenVG: $enable_openvg" + +echo "" +echo " Driver: $mesa_driver" +if test "$mesa_driver" != no; then + if echo "$DRIVER_DIRS" | grep 'osmesa' >/dev/null 2>&1; then + echo " OSMesa: lib$OSMESA_LIB" + else + echo " OSMesa: no" + fi + if test "$mesa_driver" = dri; then + # cleanup the drivers var + dri_dirs=`echo $DRI_DIRS | $SED 's/^ *//;s/ */ /;s/ *$//'` + if test "x$DRI_DIRS" = x; then + echo " DRI drivers: no" + else + echo " DRI drivers: $dri_dirs" + fi + echo " DRI driver dir: $DRI_DRIVER_INSTALL_DIR" + echo " Use XCB: $enable_xcb" + fi +fi +echo "" +echo " GLU: $enable_glu" +echo " GLw: $enable_glw (Motif: $enable_motif)" +echo " glut: $enable_glut" + +echo "" +echo " EGL: $enable_egl" +if test "$enable_egl" = yes; then + echo " EGL platforms: $EGL_PLATFORMS" + + egl_drivers="" + for d in $EGL_DRIVERS_DIRS; do + egl_drivers="$egl_drivers egl_$d" + done + + if test "$enable_gallium" = yes -a "$HAVE_ST_EGL" = yes; then + echo " EGL drivers: ${egl_drivers} egl_gallium" + echo " EGL Gallium STs:$EGL_CLIENT_APIS" + else + echo " EGL drivers: $egl_drivers" + fi +fi + +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" + echo " Gallium dirs: $GALLIUM_DIRS" + echo " Target dirs: $GALLIUM_TARGET_DIRS" + echo " Winsys dirs: $GALLIUM_WINSYS_DIRS" + echo " Driver dirs: $GALLIUM_DRIVERS_DIRS" + echo " Trackers dirs: $GALLIUM_STATE_TRACKERS_DIRS" +else + echo " Gallium: no" +fi + +echo "" +echo " Shared libs: $enable_shared" +echo " Static libs: $enable_static" + +# cleanup the CFLAGS/CXXFLAGS/DEFINES vars +cflags=`echo $CFLAGS $OPT_FLAGS $PIC_FLAGS $ARCH_FLAGS | \ + $SED 's/^ *//;s/ */ /;s/ *$//'` +cxxflags=`echo $CXXFLAGS $OPT_FLAGS $PIC_FLAGS $ARCH_FLAGS | \ + $SED 's/^ *//;s/ */ /;s/ *$//'` +defines=`echo $DEFINES $ASM_FLAGS | $SED 's/^ *//;s/ */ /;s/ *$//'` +echo "" +echo " CFLAGS: $cflags" +echo " CXXFLAGS: $cxxflags" +echo " Macros: $defines" +echo "" +echo " PYTHON2: $PYTHON2" + +echo "" +echo " Run '${MAKE-make}' to build Mesa" +echo "" diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..6662b8a --- /dev/null +++ b/configure.ac @@ -0,0 +1,1838 @@ +dnl Process this file with autoconf to create configure. + +AC_PREREQ([2.59]) + +dnl Versioning - scrape the version from configs/default +m4_define([mesa_version], + [m4_esyscmd([${MAKE-make} -s -f bin/version.mk version | tr -d '\n' | tr -d '\r'])]) +m4_ifval(mesa_version,, + [m4_fatal([Failed to get the Mesa version from `make -f bin/version.mk version`])]) + +dnl Tell the user about autoconf.html in the --help output +m4_divert_once([HELP_END], [ +See docs/autoconf.html for more details on the options for Mesa.]) + +AC_INIT([Mesa],[mesa_version], + [https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa]) +AC_CONFIG_AUX_DIR([bin]) +AC_CANONICAL_HOST + +dnl Versions for external dependencies +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 +AC_PROG_CC +AC_PROG_CXX +AC_CHECK_PROGS([MAKE], [gmake make]) +AC_CHECK_PROGS([PYTHON2], [python2 python]) +AC_PATH_PROG([MKDEP], [makedepend]) +AC_PATH_PROG([SED], [sed]) + +if test "x$MKDEP" = "x"; then + AC_MSG_ERROR([makedepend is required to build Mesa]) +fi + +dnl Our fallback install-sh is a symlink to minstall. Use the existing +dnl configuration in that case. +AC_PROG_INSTALL +test "x$INSTALL" = "x$ac_install_sh" && INSTALL='$(MINSTALL)' + +dnl We need a POSIX shell for parts of the build. Assume we have one +dnl in most cases. +case "$host_os" in +solaris*) + # Solaris /bin/sh is too old/non-POSIX compliant + AC_PATH_PROGS(POSIX_SHELL, [ksh93 ksh sh]) + SHELL="$POSIX_SHELL" + ;; +esac + +dnl clang is mostly GCC-compatible, but its version is much lower, +dnl so we have to check for it. +AC_MSG_CHECKING([if compiling with clang]) + +AC_COMPILE_IFELSE( +[AC_LANG_PROGRAM([], [[ +#ifndef __clang__ + not clang +#endif +]])], +[CLANG=yes], [CLANG=no]) + +AC_MSG_RESULT([$CLANG]) + +dnl If we're using GCC, make sure that it is at least version 3.3.0. Older +dnl versions are explictly not supported. +if test "x$GCC" = xyes -a "x$CLANG" = xno; then + AC_MSG_CHECKING([whether gcc version is sufficient]) + major=0 + minor=0 + + GCC_VERSION=`$CC -dumpversion` + if test $? -eq 0; then + major=`echo $GCC_VERSION | cut -d. -f1` + minor=`echo $GCC_VERSION | cut -d. -f1` + fi + + if test $major -lt 3 -o $major -eq 3 -a $minor -lt 3 ; then + AC_MSG_RESULT([no]) + AC_MSG_ERROR([If using GCC, version 3.3.0 or later is required.]) + else + AC_MSG_RESULT([yes]) + fi +fi + + +MKDEP_OPTIONS=-fdepend +dnl Ask gcc where it's keeping its secret headers +if test "x$GCC" = xyes; then + for dir in include include-fixed; do + GCC_INCLUDES=`$CC -print-file-name=$dir` + if test "x$GCC_INCLUDES" != x && \ + test "$GCC_INCLUDES" != "$dir" && \ + test -d "$GCC_INCLUDES"; then + MKDEP_OPTIONS="$MKDEP_OPTIONS -I$GCC_INCLUDES" + fi + done +fi +AC_SUBST([MKDEP_OPTIONS]) + +dnl Make sure the pkg-config macros are defined +m4_ifndef([PKG_PROG_PKG_CONFIG], + [m4_fatal([Could not locate the pkg-config autoconf macros. + These are usually located in /usr/share/aclocal/pkg.m4. If your macros + are in a different location, try setting the environment variable + ACLOCAL="aclocal -I/other/macro/dir" before running autoreconf.])]) +PKG_PROG_PKG_CONFIG() + +dnl LIB_DIR - library basename +LIB_DIR=`echo $libdir | $SED 's%.*/%%'` +AC_SUBST([LIB_DIR]) + +dnl Cache LDFLAGS so we can add EXTRA_LIB_PATH and restore it later +_SAVE_LDFLAGS="$LDFLAGS" +AC_ARG_VAR([EXTRA_LIB_PATH],[Extra -L paths for the linker]) +AC_SUBST([EXTRA_LIB_PATH]) + +dnl Cache CPPFLAGS so we can add *_INCLUDES and restore it later +_SAVE_CPPFLAGS="$CPPFLAGS" +AC_ARG_VAR([X11_INCLUDES],[Extra -I paths for X11 headers]) +AC_SUBST([X11_INCLUDES]) + +dnl Compiler macros +DEFINES="" +AC_SUBST([DEFINES]) +case "$host_os" in +linux*|*-gnu*|gnu*) + DEFINES="$DEFINES -D_GNU_SOURCE -DPTHREADS" + ;; +solaris*) + DEFINES="$DEFINES -DPTHREADS -DSVR4" + ;; +cygwin*) + DEFINES="$DEFINES -DPTHREADS" + ;; +esac + +dnl Add flags for gcc and g++ +if test "x$GCC" = xyes; then + CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -std=c99" + if test "x$CLANG" = "xno"; then + CFLAGS="$CFLAGS -ffast-math" + fi + + # Enable -fvisibility=hidden if using a gcc that supports it + save_CFLAGS="$CFLAGS" + AC_MSG_CHECKING([whether $CC supports -fvisibility=hidden]) + CFLAGS="$CFLAGS -fvisibility=hidden" + AC_LINK_IFELSE([AC_LANG_PROGRAM()], AC_MSG_RESULT([yes]), + [CFLAGS="$save_CFLAGS" ; AC_MSG_RESULT([no])]); + + # Work around aliasing bugs - developers should comment this out + CFLAGS="$CFLAGS -fno-strict-aliasing" +fi +if test "x$GXX" = xyes; then + CXXFLAGS="$CXXFLAGS -Wall" + + # Enable -fvisibility=hidden if using a gcc that supports it + save_CXXFLAGS="$CXXFLAGS" + AC_MSG_CHECKING([whether $CXX supports -fvisibility=hidden]) + CXXFLAGS="$CXXFLAGS -fvisibility=hidden" + AC_LINK_IFELSE([AC_LANG_PROGRAM()], AC_MSG_RESULT([yes]), + [CXXFLAGS="$save_CXXFLAGS" ; AC_MSG_RESULT([no])]); + + # Work around aliasing bugs - developers should comment this out + CXXFLAGS="$CXXFLAGS -fno-strict-aliasing" +fi + +dnl These should be unnecessary, but let the user set them if they want +AC_ARG_VAR([OPT_FLAGS], [Additional optimization flags for the compiler. + Default is to use CFLAGS.]) +AC_ARG_VAR([ARCH_FLAGS], [Additional architecture specific flags for the + compiler. Default is to use CFLAGS.]) +AC_SUBST([OPT_FLAGS]) +AC_SUBST([ARCH_FLAGS]) + +dnl +dnl Hacks to enable 32 or 64 bit build +dnl +AC_ARG_ENABLE([32-bit], + [AS_HELP_STRING([--enable-32-bit], + [build 32-bit libraries @<:@default=auto@:>@])], + [enable_32bit="$enableval"], + [enable_32bit=auto] +) +if test "x$enable_32bit" = xyes; then + if test "x$GCC" = xyes; then + CFLAGS="$CFLAGS -m32" + ARCH_FLAGS="$ARCH_FLAGS -m32" + fi + if test "x$GXX" = xyes; then + CXXFLAGS="$CXXFLAGS -m32" + fi +fi +AC_ARG_ENABLE([64-bit], + [AS_HELP_STRING([--enable-64-bit], + [build 64-bit libraries @<:@default=auto@:>@])], + [enable_64bit="$enableval"], + [enable_64bit=auto] +) +if test "x$enable_64bit" = xyes; then + if test "x$GCC" = xyes; then + CFLAGS="$CFLAGS -m64" + fi + if test "x$GXX" = xyes; then + CXXFLAGS="$CXXFLAGS -m64" + fi +fi + +dnl +dnl shared/static libraries, mimic libtool options +dnl +AC_ARG_ENABLE([static], + [AS_HELP_STRING([--enable-static], + [build static libraries @<:@default=disabled@:>@])], + [enable_static="$enableval"], + [enable_static=no] +) +case "x$enable_static" in +xyes|xno ) ;; +x ) enable_static=no ;; +* ) + AC_MSG_ERROR([Static library option '$enable_static' is not a valid]) + ;; +esac +AC_ARG_ENABLE([shared], + [AS_HELP_STRING([--disable-shared], + [build shared libraries @<:@default=enabled@:>@])], + [enable_shared="$enableval"], + [enable_shared=yes] +) +case "x$enable_shared" in +xyes|xno ) ;; +x ) enable_shared=yes ;; +* ) + AC_MSG_ERROR([Shared library option '$enable_shared' is not a valid]) + ;; +esac + +dnl Can't have static and shared libraries, default to static if user +dnl explicitly requested. If both disabled, set to static since shared +dnl was explicitly requirested. +case "x$enable_static$enable_shared" in +xyesyes ) + AC_MSG_WARN([Can't build static and shared libraries, disabling shared]) + enable_shared=no + ;; +xnono ) + AC_MSG_WARN([Can't disable both static and shared libraries, enabling static]) + enable_static=yes + ;; +esac + +dnl +dnl mklib options +dnl +AC_ARG_VAR([MKLIB_OPTIONS],[Options for the Mesa library script, mklib]) +if test "$enable_static" = yes; then + MKLIB_OPTIONS="$MKLIB_OPTIONS -static" +fi +AC_SUBST([MKLIB_OPTIONS]) + +dnl +dnl other compiler options +dnl +AC_ARG_ENABLE([debug], + [AS_HELP_STRING([--enable-debug], + [use debug compiler flags and macros @<:@default=disabled@:>@])], + [enable_debug="$enableval"], + [enable_debug=no] +) +if test "x$enable_debug" = xyes; then + DEFINES="$DEFINES -DDEBUG" + if test "x$GCC" = xyes; then + CFLAGS="$CFLAGS -g" + fi + if test "x$GXX" = xyes; then + CXXFLAGS="$CXXFLAGS -g" + fi +fi + +dnl +dnl library names +dnl +LIB_PREFIX_GLOB='lib' +LIB_VERSION_SEPARATOR='.' +if test "$enable_static" = yes; then + LIB_EXTENSION='a' +else + case "$host_os" in + darwin* ) + LIB_EXTENSION='dylib' ;; + cygwin* ) + dnl prefix can be 'cyg' or 'lib' + LIB_PREFIX_GLOB='???' + LIB_VERSION_SEPARATOR='-' + LIB_EXTENSION='dll' ;; + aix* ) + LIB_EXTENSION='a' ;; + * ) + LIB_EXTENSION='so' ;; + esac +fi + +GL_LIB_NAME='lib$(GL_LIB).'${LIB_EXTENSION} +GLU_LIB_NAME='lib$(GLU_LIB).'${LIB_EXTENSION} +GLUT_LIB_NAME='lib$(GLUT_LIB).'${LIB_EXTENSION} +GLW_LIB_NAME='lib$(GLW_LIB).'${LIB_EXTENSION} +OSMESA_LIB_NAME='lib$(OSMESA_LIB).'${LIB_EXTENSION} +EGL_LIB_NAME='lib$(EGL_LIB).'${LIB_EXTENSION} +GLESv1_CM_LIB_NAME='lib$(GLESv1_CM_LIB).'${LIB_EXTENSION} +GLESv2_LIB_NAME='lib$(GLESv2_LIB).'${LIB_EXTENSION} +VG_LIB_NAME='lib$(VG_LIB).'${LIB_EXTENSION} + +GL_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GL_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +GLU_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLU_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +GLUT_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLUT_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +GLW_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLW_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +OSMESA_LIB_GLOB=${LIB_PREFIX_GLOB}'$(OSMESA_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +EGL_LIB_GLOB=${LIB_PREFIX_GLOB}'$(EGL_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +EGL_LIB_GLOB=${LIB_PREFIX_GLOB}'$(EGL_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +GLESv1_CM_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLESv1_CM_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +GLESv2_LIB_GLOB=${LIB_PREFIX_GLOB}'$(GLESv2_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' +VG_LIB_GLOB=${LIB_PREFIX_GLOB}'$(VG_LIB)'${LIB_VERSION_SEPARATOR}'*'${LIB_EXTENSION}'*' + +AC_SUBST([GL_LIB_NAME]) +AC_SUBST([GLU_LIB_NAME]) +AC_SUBST([GLUT_LIB_NAME]) +AC_SUBST([GLW_LIB_NAME]) +AC_SUBST([OSMESA_LIB_NAME]) +AC_SUBST([EGL_LIB_NAME]) +AC_SUBST([GLESv1_CM_LIB_NAME]) +AC_SUBST([GLESv2_LIB_NAME]) +AC_SUBST([VG_LIB_NAME]) + +AC_SUBST([GL_LIB_GLOB]) +AC_SUBST([GLU_LIB_GLOB]) +AC_SUBST([GLUT_LIB_GLOB]) +AC_SUBST([GLW_LIB_GLOB]) +AC_SUBST([OSMESA_LIB_GLOB]) +AC_SUBST([EGL_LIB_GLOB]) +AC_SUBST([GLESv1_CM_LIB_GLOB]) +AC_SUBST([GLESv2_LIB_GLOB]) +AC_SUBST([VG_LIB_GLOB]) + +dnl +dnl Arch/platform-specific settings +dnl +AC_ARG_ENABLE([asm], + [AS_HELP_STRING([--disable-asm], + [disable assembly usage @<:@default=enabled on supported plaforms@:>@])], + [enable_asm="$enableval"], + [enable_asm=yes] +) +asm_arch="" +ASM_FLAGS="" +MESA_ASM_SOURCES="" +GLAPI_ASM_SOURCES="" +AC_MSG_CHECKING([whether to enable assembly]) +test "x$enable_asm" = xno && AC_MSG_RESULT([no]) +# disable if cross compiling on x86/x86_64 since we must run gen_matypes +if test "x$enable_asm" = xyes && test "x$cross_compiling" = xyes; then + case "$host_cpu" in + i?86 | x86_64) + enable_asm=no + AC_MSG_RESULT([no, cross compiling]) + ;; + esac +fi +# check for supported arches +if test "x$enable_asm" = xyes; then + case "$host_cpu" in + i?86) + case "$host_os" in + linux* | *freebsd* | dragonfly*) + test "x$enable_64bit" = xyes && asm_arch=x86_64 || asm_arch=x86 + ;; + esac + ;; + x86_64) + case "$host_os" in + linux* | *freebsd* | dragonfly*) + test "x$enable_32bit" = xyes && asm_arch=x86 || asm_arch=x86_64 + ;; + esac + ;; + powerpc) + case "$host_os" in + linux*) + asm_arch=ppc + ;; + esac + ;; + sparc*) + case "$host_os" in + linux*) + asm_arch=sparc + ;; + esac + ;; + esac + + case "$asm_arch" in + x86) + ASM_FLAGS="-DUSE_X86_ASM -DUSE_MMX_ASM -DUSE_3DNOW_ASM -DUSE_SSE_ASM" + MESA_ASM_SOURCES='$(X86_SOURCES)' + GLAPI_ASM_SOURCES='$(X86_API)' + AC_MSG_RESULT([yes, x86]) + ;; + x86_64) + ASM_FLAGS="-DUSE_X86_64_ASM" + MESA_ASM_SOURCES='$(X86-64_SOURCES)' + GLAPI_ASM_SOURCES='$(X86-64_API)' + AC_MSG_RESULT([yes, x86_64]) + ;; + ppc) + ASM_FLAGS="-DUSE_PPC_ASM -DUSE_VMX_ASM" + MESA_ASM_SOURCES='$(PPC_SOURCES)' + AC_MSG_RESULT([yes, ppc]) + ;; + sparc) + ASM_FLAGS="-DUSE_SPARC_ASM" + MESA_ASM_SOURCES='$(SPARC_SOURCES)' + GLAPI_ASM_SOURCES='$(SPARC_API)' + AC_MSG_RESULT([yes, sparc]) + ;; + *) + AC_MSG_RESULT([no, platform not supported]) + ;; + esac +fi +AC_SUBST([ASM_FLAGS]) +AC_SUBST([MESA_ASM_SOURCES]) +AC_SUBST([GLAPI_ASM_SOURCES]) + +dnl PIC code macro +MESA_PIC_FLAGS + +dnl Check to see if dlopen is in default libraries (like Solaris, which +dnl has it in libc), or if libdl is needed to get it. +AC_CHECK_FUNC([dlopen], [], + [AC_CHECK_LIB([dl], [dlopen], [DLOPEN_LIBS="-ldl"])]) +AC_SUBST([DLOPEN_LIBS]) + +dnl See if posix_memalign is available +AC_CHECK_FUNC([posix_memalign], [DEFINES="$DEFINES -DHAVE_POSIX_MEMALIGN"]) + +dnl SELinux awareness. +AC_ARG_ENABLE([selinux], + [AS_HELP_STRING([--enable-selinux], + [Build SELinux-aware Mesa @<:@default=disabled@:>@])], + [MESA_SELINUX="$enableval"], + [MESA_SELINUX=no]) +if test "x$enable_selinux" = "xyes"; then + AC_CHECK_HEADER([selinux/selinux.h],[], + [AC_MSG_ERROR([SELinux headers not found])]) + AC_CHECK_LIB([selinux],[is_selinux_enabled],[], + [AC_MSG_ERROR([SELinux library not found])]) + SELINUX_LIBS="-lselinux" + DEFINES="$DEFINES -DMESA_SELINUX" +fi + +dnl Determine which APIs to support +AC_ARG_ENABLE([opengl], + [AS_HELP_STRING([--disable-opengl], + [disable support for standard OpenGL API @<:@default=no@:>@])], + [enable_opengl="$enableval"], + [enable_opengl=yes]) +AC_ARG_ENABLE([gles1], + [AS_HELP_STRING([--enable-gles1], + [enable support for OpenGL ES 1.x API @<:@default=no@:>@])], + [enable_gles1="$enableval"], + [enable_gles1=no]) +AC_ARG_ENABLE([gles2], + [AS_HELP_STRING([--enable-gles2], + [enable support for OpenGL ES 2.x API @<:@default=no@:>@])], + [enable_gles2="$enableval"], + [enable_gles2=no]) +AC_ARG_ENABLE([gles-overlay], + [AS_HELP_STRING([--enable-gles-overlay], + [build separate OpenGL ES only libraries @<:@default=no@:>@])], + [enable_gles_overlay="$enableval"], + [enable_gles_overlay=no]) + +AC_ARG_ENABLE([openvg], + [AS_HELP_STRING([--enable-openvg], + [enable support for OpenVG API @<:@default=no@:>@])], + [enable_openvg="$enableval"], + [enable_openvg=no]) + +dnl smooth the transition; should be removed eventually +if test "x$enable_openvg" = xno; then + case "x$with_state_trackers" in + x*vega*) + AC_MSG_WARN([vega state tracker is enabled without --enable-openvg]) + enable_openvg=yes + ;; + esac +fi + +if test "x$enable_opengl" = xno -a \ + "x$enable_gles1" = xno -a \ + "x$enable_gles2" = xno -a \ + "x$enable_gles_overlay" = xno -a \ + "x$enable_openvg" = xno; then + AC_MSG_ERROR([at least one API should be enabled]) +fi + +API_DEFINES="" +GLES_OVERLAY=0 +if test "x$enable_opengl" = xno; then + API_DEFINES="$API_DEFINES -DFEATURE_GL=0" +else + API_DEFINES="$API_DEFINES -DFEATURE_GL=1" +fi +if test "x$enable_gles1" = xyes; then + API_DEFINES="$API_DEFINES -DFEATURE_ES1=1" +fi +if test "x$enable_gles2" = xyes; then + API_DEFINES="$API_DEFINES -DFEATURE_ES2=1" +fi +if test "x$enable_gles_overlay" = xyes; then + GLES_OVERLAY=1 +fi +AC_SUBST([API_DEFINES]) +AC_SUBST([GLES_OVERLAY]) + +dnl +dnl Driver configuration. Options are xlib, dri and osmesa right now. +dnl More later: fbdev, ... +dnl +default_driver="xlib" + +case "$host_os" in +linux*) + case "$host_cpu" in + i*86|x86_64|powerpc*|sparc*) default_driver="dri";; + esac + ;; +*freebsd* | dragonfly*) + case "$host_cpu" in + i*86|x86_64|powerpc*|sparc*) default_driver="dri";; + esac + ;; +esac + +if test "x$enable_opengl" = xno; then + default_driver="no" +fi + +AC_ARG_WITH([driver], + [AS_HELP_STRING([--with-driver=DRIVER], + [driver for Mesa: xlib,dri,osmesa @<:@default=dri when available, or xlib@:>@])], + [mesa_driver="$withval"], + [mesa_driver="$default_driver"]) +dnl Check for valid option +case "x$mesa_driver" in +xxlib|xdri|xosmesa) + if test "x$enable_opengl" = xno; then + AC_MSG_ERROR([Driver '$mesa_driver' requires OpenGL enabled]) + fi + ;; +xno) + ;; +*) + AC_MSG_ERROR([Driver '$mesa_driver' is not a valid option]) + ;; +esac + +dnl +dnl Driver specific build directories +dnl + +dnl this variable will be prepended to SRC_DIRS and is not exported +CORE_DIRS="" + +SRC_DIRS="" +GLU_DIRS="sgi" +GALLIUM_DIRS="auxiliary drivers state_trackers" +GALLIUM_TARGET_DIRS="" +GALLIUM_WINSYS_DIRS="sw" +GALLIUM_DRIVERS_DIRS="softpipe failover galahad trace rbug identity" +GALLIUM_STATE_TRACKERS_DIRS="" + +# build glapi if OpenGL is enabled +if test "x$enable_opengl" = xyes; then + CORE_DIRS="$CORE_DIRS mapi/glapi" +fi + +# build es1api and es2api if OpenGL ES is enabled +case "x$enable_gles1$enable_gles2$enable_gles_overlay" in +x*yes*) + CORE_DIRS="$CORE_DIRS mapi/es1api mapi/es2api" + ;; +esac + +# build vgapi if OpenVG is enabled +if test "x$enable_openvg" = xyes; then + CORE_DIRS="$CORE_DIRS mapi/vgapi" +fi + +# build glsl and mesa if OpenGL or OpenGL ES is enabled +case "x$enable_opengl$enable_gles1$enable_gles2$enable_gles_overlay" in +x*yes*) + CORE_DIRS="$CORE_DIRS glsl mesa" + ;; +esac + +case "$mesa_driver" in +xlib) + DRIVER_DIRS="x11" + 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 sw/xlib sw/dri" + ;; +osmesa) + DRIVER_DIRS="osmesa" + ;; +no) + DRIVER_DRIS="" + ;; +esac +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_DRIVERS_DIRS]) +AC_SUBST([GALLIUM_STATE_TRACKERS_DIRS]) +AC_SUBST([MESA_LLVM]) + +dnl +dnl Find out if X is available. The variable have_x is set if libX11 is +dnl found to mimic AC_PATH_XTRA. +dnl +if test -n "$PKG_CONFIG"; then + AC_MSG_CHECKING([pkg-config files for X11 are available]) + PKG_CHECK_EXISTS([x11],[ + x11_pkgconfig=yes + have_x=yes + ],[ + x11_pkgconfig=no + ]) + AC_MSG_RESULT([$x11_pkgconfig]) +else + x11_pkgconfig=no +fi +dnl Use the autoconf macro if no pkg-config files +if test "$x11_pkgconfig" = yes; then + 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 +dnl pkg-config is not available. This must be right after AC_PATH_XTRA. +m4_divert_once([HELP_BEGIN], +[These options are only used when the X libraries cannot be found by the +pkg-config utility.]) + +dnl We need X for xlib and dri, so bomb now if it's not found +case "$mesa_driver" in +xlib|dri) + if test "$no_x" = yes; then + AC_MSG_ERROR([X11 development libraries needed for $mesa_driver driver]) + fi + ;; +esac + +dnl XCB - this is only used for GLX right now +AC_ARG_ENABLE([xcb], + [AS_HELP_STRING([--enable-xcb], + [use XCB for GLX @<:@default=disabled@:>@])], + [enable_xcb="$enableval"], + [enable_xcb=no]) +if test "x$enable_xcb" = xyes; then + DEFINES="$DEFINES -DUSE_XCB" +else + enable_xcb=no +fi + +dnl +dnl libGL configuration per driver +dnl +case "$mesa_driver" in +xlib) + if test "$x11_pkgconfig" = yes; then + PKG_CHECK_MODULES([XLIBGL], [x11 xext]) + GL_PC_REQ_PRIV="x11 xext" + X11_INCLUDES="$X11_INCLUDES $XLIBGL_CFLAGS" + GL_LIB_DEPS="$XLIBGL_LIBS" + else + # should check these... + X11_INCLUDES="$X11_INCLUDES $X_CFLAGS" + GL_LIB_DEPS="$X_LIBS -lX11 -lXext" + GL_PC_LIB_PRIV="$GL_LIB_DEPS" + GL_PC_CFLAGS="$X11_INCLUDES" + fi + GL_LIB_DEPS="$GL_LIB_DEPS $SELINUX_LIBS -lm -lpthread" + GL_PC_LIB_PRIV="$GL_PC_LIB_PRIV $SELINUX_LIBS -lm -lpthread" + + # if static, move the external libraries to the programs + # and empty the libraries for libGL + if test "$enable_static" = yes; then + APP_LIB_DEPS="$APP_LIB_DEPS $GL_LIB_DEPS" + GL_LIB_DEPS="" + fi + ;; +dri|no) # these checks are still desired when there is no mesa_driver + # DRI must be shared, I think + if test "$enable_static" = yes; then + AC_MSG_ERROR([Can't use static libraries for DRI drivers]) + fi + + # Check for libdrm + PKG_CHECK_MODULES([LIBDRM], [libdrm >= $LIBDRM_REQUIRED]) + PKG_CHECK_MODULES([DRI2PROTO], [dri2proto >= $DRI2PROTO_REQUIRED]) + PKG_CHECK_MODULES([GLPROTO], [glproto >= $GLPROTO_REQUIRED]) + GL_PC_REQ_PRIV="libdrm >= $LIBDRM_REQUIRED dri2proto >= $DRI2PROTO_REQUIRED glproto >= $GLPROTO_REQUIRED" + DRI_PC_REQ_PRIV="libdrm >= $LIBDRM_REQUIRED" + + # find the DRI deps for libGL + if test "$x11_pkgconfig" = yes; then + dri_modules="x11 xext xdamage xfixes" + + # add xf86vidmode if available + PKG_CHECK_MODULES([XF86VIDMODE], [xxf86vm], HAVE_XF86VIDMODE=yes, HAVE_XF86VIDMODE=no) + if test "$HAVE_XF86VIDMODE" = yes ; then + dri_modules="$dri_modules xxf86vm" + fi + + # add xcb modules if necessary + if test "$enable_xcb" = yes; then + dri_modules="$dri_modules x11-xcb xcb-glx" + fi + + PKG_CHECK_MODULES([DRIGL], [$dri_modules]) + GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV $dri_modules" + X11_INCLUDES="$X11_INCLUDES $DRIGL_CFLAGS" + GL_LIB_DEPS="$DRIGL_LIBS" + else + # should check these... + X11_INCLUDES="$X11_INCLUDES $X_CFLAGS" + GL_LIB_DEPS="$X_LIBS -lX11 -lXext -lXxf86vm -lXdamage -lXfixes" + GL_PC_LIB_PRIV="$GL_LIB_DEPS" + GL_PC_CFLAGS="$X11_INCLUDES" + + # XCB can only be used from pkg-config + if test "$enable_xcb" = yes; then + PKG_CHECK_MODULES([XCB],[x11-xcb xcb-glx]) + GL_PC_REQ_PRIV="$GL_PC_REQ_PRIV x11-xcb xcb-glx" + X11_INCLUDES="$X11_INCLUDES $XCB_CFLAGS" + GL_LIB_DEPS="$GL_LIB_DEPS $XCB_LIBS" + fi + fi + + # need DRM libs, -lpthread, etc. + GL_LIB_DEPS="$GL_LIB_DEPS $LIBDRM_LIBS -lm -lpthread $DLOPEN_LIBS" + GL_PC_LIB_PRIV="-lm -lpthread $DLOPEN_LIBS" + GLESv1_CM_LIB_DEPS="$LIBDRM_LIBS -lm -lpthread $DLOPEN_LIBS" + GLESv1_CM_PC_LIB_PRIV="-lm -lpthread $DLOPEN_LIBS" + GLESv2_LIB_DEPS="$LIBDRM_LIBS -lm -lpthread $DLOPEN_LIBS" + GLESv2_PC_LIB_PRIV="-lm -lpthread $DLOPEN_LIBS" + ;; +osmesa) + # No libGL for osmesa + GL_LIB_DEPS="" + ;; +esac +AC_SUBST([GL_LIB_DEPS]) +AC_SUBST([GL_PC_REQ_PRIV]) +AC_SUBST([GL_PC_LIB_PRIV]) +AC_SUBST([GL_PC_CFLAGS]) +AC_SUBST([DRI_PC_REQ_PRIV]) +AC_SUBST([GLESv1_CM_LIB_DEPS]) +AC_SUBST([GLESv1_CM_PC_LIB_PRIV]) +AC_SUBST([GLESv2_LIB_DEPS]) +AC_SUBST([GLESv2_PC_LIB_PRIV]) + + +AC_SUBST([HAVE_XF86VIDMODE]) + +PKG_CHECK_MODULES([LIBDRM_RADEON], + [libdrm_radeon libdrm >= $LIBDRM_RADEON_REQUIRED], + HAVE_LIBDRM_RADEON=yes, + HAVE_LIBDRM_RADEON=no) + +dnl +dnl More X11 setup +dnl +if test "$mesa_driver" = xlib; then + DEFINES="$DEFINES -DUSE_XSHM" +fi + +dnl +dnl More DRI setup +dnl +AC_ARG_ENABLE([glx-tls], + [AS_HELP_STRING([--enable-glx-tls], + [enable TLS support in GLX @<:@default=disabled@:>@])], + [GLX_USE_TLS="$enableval"], + [GLX_USE_TLS=no]) +dnl Directory for DRI drivers +AC_ARG_WITH([dri-driverdir], + [AS_HELP_STRING([--with-dri-driverdir=DIR], + [directory for the DRI drivers @<:@${libdir}/dri@:>@])], + [DRI_DRIVER_INSTALL_DIR="$withval"], + [DRI_DRIVER_INSTALL_DIR='${libdir}/dri']) +AC_SUBST([DRI_DRIVER_INSTALL_DIR]) +dnl Extra search path for DRI drivers +AC_ARG_WITH([dri-searchpath], + [AS_HELP_STRING([--with-dri-searchpath=DIRS...], + [semicolon delimited DRI driver search directories @<:@${libdir}/dri@:>@])], + [DRI_DRIVER_SEARCH_DIR="$withval"], + [DRI_DRIVER_SEARCH_DIR='${DRI_DRIVER_INSTALL_DIR}']) +AC_SUBST([DRI_DRIVER_SEARCH_DIR]) +dnl Direct rendering or just indirect rendering +AC_ARG_ENABLE([driglx-direct], + [AS_HELP_STRING([--disable-driglx-direct], + [enable direct rendering in GLX and EGL for DRI @<:@default=enabled@:>@])], + [driglx_direct="$enableval"], + [driglx_direct="yes"]) +dnl Which drivers to build - default is chosen by platform +AC_ARG_WITH([dri-drivers], + [AS_HELP_STRING([--with-dri-drivers@<:@=DIRS...@:>@], + [comma delimited DRI drivers list, e.g. + "swrast,i965,radeon" @<:@default=auto@:>@])], + [with_dri_drivers="$withval"], + [with_dri_drivers=yes]) +if test "x$with_dri_drivers" = x; then + with_dri_drivers=no +fi + +dnl If $with_dri_drivers is yes, directories will be added through +dnl platform checks +DRI_DIRS="" +case "$with_dri_drivers" in +no) ;; +yes) + DRI_DIRS="yes" + ;; +*) + # verify the requested driver directories exist + dri_drivers=`IFS=', '; echo $with_dri_drivers` + for driver in $dri_drivers; do + test -d "$srcdir/src/mesa/drivers/dri/$driver" || \ + AC_MSG_ERROR([DRI driver directory '$driver' doesn't exist]) + done + DRI_DIRS="$dri_drivers" + ;; +esac + +dnl Set DRI_DIRS, DEFINES and LIB_DEPS +if test "$mesa_driver" = dri -o "$mesa_driver" = no; then + # Use TLS in GLX? + if test "x$GLX_USE_TLS" = xyes; then + DEFINES="$DEFINES -DGLX_USE_TLS -DPTHREADS" + fi + + # Platform specific settings and drivers to build + case "$host_os" in + linux*) + DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER" + if test "x$driglx_direct" = xyes; then + DEFINES="$DEFINES -DGLX_DIRECT_RENDERING" + fi + DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING -DHAVE_ALIAS" + + case "$host_cpu" in + x86_64) + # sis is missing because they have not be converted to use + # the new interface. i810 are missing because there is no + # x86-64 system where they could *ever* be used. + if test "x$DRI_DIRS" = "xyes"; then + DRI_DIRS="i915 i965 mach64 mga r128 r200 r300 r600 radeon \ + savage tdfx unichrome swrast" + fi + ;; + powerpc*) + # Build only the drivers for cards that exist on PowerPC. + # At some point MGA will be added, but not yet. + if test "x$DRI_DIRS" = "xyes"; then + DRI_DIRS="mach64 r128 r200 r300 r600 radeon tdfx swrast" + fi + ;; + sparc*) + # Build only the drivers for cards that exist on sparc` + if test "x$DRI_DIRS" = "xyes"; then + DRI_DIRS="mach64 r128 r200 r300 r600 radeon swrast" + fi + ;; + esac + ;; + freebsd* | dragonfly*) + DEFINES="$DEFINES -DPTHREADS -DUSE_EXTERNAL_DXTN_LIB=1" + DEFINES="$DEFINES -DIN_DRI_DRIVER -DHAVE_ALIAS" + DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING" + if test "x$driglx_direct" = xyes; then + DEFINES="$DEFINES -DGLX_DIRECT_RENDERING" + fi + if test "x$GXX" = xyes; then + CXXFLAGS="$CXXFLAGS -ansi -pedantic" + fi + + if test "x$DRI_DIRS" = "xyes"; then + DRI_DIRS="i810 i915 i965 mach64 mga r128 r200 r300 r600 radeon tdfx \ + unichrome savage sis swrast" + fi + ;; + gnu*) + DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER" + DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING -DHAVE_ALIAS" + ;; + solaris*) + DEFINES="$DEFINES -DUSE_EXTERNAL_DXTN_LIB=1 -DIN_DRI_DRIVER" + DEFINES="$DEFINES -DGLX_INDIRECT_RENDERING" + if test "x$driglx_direct" = xyes; then + DEFINES="$DEFINES -DGLX_DIRECT_RENDERING" + fi + ;; + esac + + # default drivers + if test "x$DRI_DIRS" = "xyes"; then + DRI_DIRS="i810 i915 i965 mach64 mga r128 r200 r300 r600 radeon \ + savage sis tdfx unichrome swrast" + fi + + DRI_DIRS=`echo "$DRI_DIRS" | $SED 's/ */ /g'` + + # Check for expat + if test "$mesa_driver" = dri; then + EXPAT_INCLUDES="" + EXPAT_LIB=-lexpat + AC_ARG_WITH([expat], + [AS_HELP_STRING([--with-expat=DIR], + [expat install directory])],[ + EXPAT_INCLUDES="-I$withval/include" + CPPFLAGS="$CPPFLAGS $EXPAT_INCLUDES" + LDFLAGS="$LDFLAGS -L$withval/$LIB_DIR" + EXPAT_LIB="-L$withval/$LIB_DIR -lexpat" + ]) + AC_CHECK_HEADER([expat.h],[],[AC_MSG_ERROR([Expat required for DRI.])]) + AC_CHECK_LIB([expat],[XML_ParserCreate],[], + [AC_MSG_ERROR([Expat required for DRI.])]) + fi + + # put all the necessary libs together + DRI_LIB_DEPS="$SELINUX_LIBS $LIBDRM_LIBS $EXPAT_LIB -lm -lpthread $DLOPEN_LIBS" +fi +AC_SUBST([DRI_DIRS]) +AC_SUBST([EXPAT_INCLUDES]) +AC_SUBST([DRI_LIB_DEPS]) + +case $DRI_DIRS in +*i915*|*i965*) + PKG_CHECK_MODULES([INTEL], [libdrm_intel >= 2.4.21]) + ;; +esac + +case $DRI_DIRS in +*radeon*|*r200*|*r300*|*r600*) + if test "x$HAVE_LIBDRM_RADEON" = xyes; then + RADEON_CFLAGS="-DHAVE_LIBDRM_RADEON=1 $LIBDRM_RADEON_CFLAGS" + RADEON_LDFLAGS=$LIBDRM_RADEON_LIBS + fi + ;; +esac +AC_SUBST([RADEON_CFLAGS]) +AC_SUBST([RADEON_LDFLAGS]) + + +dnl +dnl OSMesa configuration +dnl +if test "$mesa_driver" = xlib; then + default_gl_osmesa=yes +else + default_gl_osmesa=no +fi +AC_ARG_ENABLE([gl-osmesa], + [AS_HELP_STRING([--enable-gl-osmesa], + [enable OSMesa with libGL @<:@default=enabled for xlib driver@:>@])], + [gl_osmesa="$enableval"], + [gl_osmesa="$default_gl_osmesa"]) +if test "x$gl_osmesa" = xyes; then + if test "x$enable_opengl" = xno; then + AC_MSG_ERROR([OpenGL is not available for OSMesa driver]) + fi + if test "$mesa_driver" = osmesa; then + AC_MSG_ERROR([libGL is not available for OSMesa driver]) + else + DRIVER_DIRS="$DRIVER_DIRS osmesa" + fi +fi + +dnl Configure the channel bits for OSMesa (libOSMesa, libOSMesa16, ...) +AC_ARG_WITH([osmesa-bits], + [AS_HELP_STRING([--with-osmesa-bits=BITS], + [OSMesa channel bits and library name: 8, 16, 32 @<:@default=8@:>@])], + [osmesa_bits="$withval"], + [osmesa_bits=8]) +if test "$mesa_driver" != osmesa && test "x$osmesa_bits" != x8; then + AC_MSG_WARN([Ignoring OSMesa channel bits for non-OSMesa driver]) + osmesa_bits=8 +fi +case "x$osmesa_bits" in +x8) + OSMESA_LIB=OSMesa + ;; +x16|x32) + OSMESA_LIB="OSMesa$osmesa_bits" + DEFINES="$DEFINES -DCHAN_BITS=$osmesa_bits -DDEFAULT_SOFTWARE_DEPTH_BITS=31" + ;; +*) + AC_MSG_ERROR([OSMesa bits '$osmesa_bits' is not a valid option]) + ;; +esac +AC_SUBST([OSMESA_LIB]) + +case "$DRIVER_DIRS" in +*osmesa*) + # only link libraries with osmesa if shared + if test "$enable_static" = no; then + OSMESA_LIB_DEPS="-lm -lpthread $SELINUX_LIBS $DLOPEN_LIBS" + else + OSMESA_LIB_DEPS="" + fi + OSMESA_MESA_DEPS="" + OSMESA_PC_LIB_PRIV="-lm -lpthread $SELINUX_LIBS $DLOPEN_LIBS" + ;; +esac +AC_SUBST([OSMESA_LIB_DEPS]) +AC_SUBST([OSMESA_MESA_DEPS]) +AC_SUBST([OSMESA_PC_REQ]) +AC_SUBST([OSMESA_PC_LIB_PRIV]) + +dnl +dnl EGL configuration +dnl +AC_ARG_ENABLE([egl], + [AS_HELP_STRING([--disable-egl], + [disable EGL library @<:@default=enabled@:>@])], + [enable_egl="$enableval"], + [enable_egl=yes]) +if test "x$enable_egl" = xno; then + if test "x$mesa_driver" = xno; then + AC_MSG_ERROR([cannot disable EGL when there is no mesa driver]) + fi + if test "x$enable_openvg" = xyes; then + AC_MSG_ERROR([cannot enable OpenVG without EGL]) + fi +fi +if test "x$enable_egl" = xyes; then + SRC_DIRS="$SRC_DIRS egl" + EGL_LIB_DEPS="$DLOPEN_LIBS -lpthread" + EGL_DRIVERS_DIRS="" + if test "$enable_static" != yes; then + # build egl_glx when libGL is built + if test "$mesa_driver" = xlib -o "$mesa_driver" = dri; then + EGL_DRIVERS_DIRS="glx" + fi + + if test "$mesa_driver" = dri; then + # build egl_dri2 when xcb-dri2 is available + PKG_CHECK_MODULES([XCB_DRI2], [x11-xcb xcb-dri2 xcb-xfixes], + [have_xcb_dri2=yes],[have_xcb_dri2=no]) + PKG_CHECK_MODULES([LIBUDEV], [libudev > 150], + [have_libudev=yes],[have_libudev=no]) + + if test "$have_xcb_dri2" = yes; then + EGL_DRIVER_DRI2=dri2 + DEFINES="$DEFINES -DHAVE_XCB_DRI2" + if test "$have_libudev" = yes; then + DEFINES="$DEFINES -DHAVE_LIBUDEV" + fi + fi + fi + + EGL_DRIVERS_DIRS="$EGL_DRIVERS_DIRS $EGL_DRIVER_DRI2" + fi +fi +AC_SUBST([EGL_LIB_DEPS]) +AC_SUBST([EGL_DRIVERS_DIRS]) + +dnl +dnl GLU configuration +dnl +AC_ARG_ENABLE([glu], + [AS_HELP_STRING([--disable-glu], + [enable OpenGL Utility library @<:@default=enabled@:>@])], + [enable_glu="$enableval"], + [enable_glu=yes]) + +if test "x$enable_glu" = xyes -a "x$mesa_driver" = xno; then + AC_MSG_NOTICE([Disabling GLU since there is no OpenGL driver]) + enable_glu=no +fi + +if test "x$enable_glu" = xyes; then + SRC_DIRS="$SRC_DIRS glu" + + case "$mesa_driver" in + osmesa) + # Link libGLU to libOSMesa instead of libGL + GLU_LIB_DEPS="" + GLU_PC_REQ="osmesa" + if test "$enable_static" = no; then + GLU_MESA_DEPS='-l$(OSMESA_LIB)' + else + GLU_MESA_DEPS="" + fi + ;; + *) + # If static, empty GLU_LIB_DEPS and add libs for programs to link + GLU_PC_REQ="gl" + GLU_PC_LIB_PRIV="-lm" + if test "$enable_static" = no; then + GLU_LIB_DEPS="-lm" + GLU_MESA_DEPS='-l$(GL_LIB)' + else + GLU_LIB_DEPS="" + GLU_MESA_DEPS="" + APP_LIB_DEPS="$APP_LIB_DEPS -lstdc++" + fi + ;; + esac +fi +if test "$enable_static" = no; then + GLU_LIB_DEPS="$GLU_LIB_DEPS $OS_CPLUSPLUS_LIBS" +fi +GLU_PC_LIB_PRIV="$GLU_PC_LIB_PRIV $OS_CPLUSPLUS_LIBS" +AC_SUBST([GLU_LIB_DEPS]) +AC_SUBST([GLU_MESA_DEPS]) +AC_SUBST([GLU_PC_REQ]) +AC_SUBST([GLU_PC_REQ_PRIV]) +AC_SUBST([GLU_PC_LIB_PRIV]) +AC_SUBST([GLU_PC_CFLAGS]) + +dnl +dnl GLw configuration +dnl +AC_ARG_ENABLE([glw], + [AS_HELP_STRING([--disable-glw], + [enable Xt/Motif widget library @<:@default=enabled@:>@])], + [enable_glw="$enableval"], + [enable_glw=yes]) +dnl Don't build GLw on osmesa +if test "x$enable_glw" = xyes; then + case "$mesa_driver" in + osmesa|no) + AC_MSG_NOTICE([Disabling GLw since there is no OpenGL driver]) + enable_glw=no + ;; + esac +fi +AC_ARG_ENABLE([motif], + [AS_HELP_STRING([--enable-motif], + [use Motif widgets in GLw @<:@default=disabled@:>@])], + [enable_motif="$enableval"], + [enable_motif=no]) + +if test "x$enable_glw" = xyes; then + SRC_DIRS="$SRC_DIRS glw" + if test "$x11_pkgconfig" = yes; then + PKG_CHECK_MODULES([GLW],[x11 xt]) + GLW_PC_REQ_PRIV="x11 xt" + GLW_LIB_DEPS="$GLW_LIBS" + else + # should check these... + GLW_LIB_DEPS="$X_LIBS -lXt -lX11" + GLW_PC_LIB_PRIV="$GLW_LIB_DEPS" + GLW_PC_CFLAGS="$X11_INCLUDES" + fi + + GLW_SOURCES="GLwDrawA.c" + MOTIF_CFLAGS= + if test "x$enable_motif" = xyes; then + GLW_SOURCES="$GLW_SOURCES GLwMDrawA.c" + AC_PATH_PROG([MOTIF_CONFIG], [motif-config], [no]) + if test "x$MOTIF_CONFIG" != xno; then + MOTIF_CFLAGS=`$MOTIF_CONFIG --cflags` + MOTIF_LIBS=`$MOTIF_CONFIG --libs` + else + AC_CHECK_HEADER([Xm/PrimitiveP.h], [], + [AC_MSG_ERROR([Can't locate Motif headers])]) + AC_CHECK_LIB([Xm], [XmGetPixmap], [MOTIF_LIBS="-lXm"], + [AC_MSG_ERROR([Can't locate Motif Xm library])]) + fi + # MOTIF_LIBS is prepended to GLW_LIB_DEPS since Xm needs Xt/X11 + GLW_LIB_DEPS="$MOTIF_LIBS $GLW_LIB_DEPS" + GLW_PC_LIB_PRIV="$MOTIF_LIBS $GLW_PC_LIB_PRIV" + GLW_PC_CFLAGS="$MOTIF_CFLAGS $GLW_PC_CFLAGS" + fi + + # If static, empty GLW_LIB_DEPS and add libs for programs to link + GLW_PC_LIB_PRIV="$GLW_PC_LIB_PRIV" + if test "$enable_static" = no; then + GLW_MESA_DEPS='-l$(GL_LIB)' + GLW_LIB_DEPS="$GLW_LIB_DEPS" + else + APP_LIB_DEPS="$APP_LIB_DEPS $GLW_LIB_DEPS" + GLW_LIB_DEPS="" + GLW_MESA_DEPS="" + fi +fi +AC_SUBST([GLW_LIB_DEPS]) +AC_SUBST([GLW_MESA_DEPS]) +AC_SUBST([GLW_SOURCES]) +AC_SUBST([MOTIF_CFLAGS]) +AC_SUBST([GLW_PC_REQ_PRIV]) +AC_SUBST([GLW_PC_LIB_PRIV]) +AC_SUBST([GLW_PC_CFLAGS]) + +dnl +dnl GLUT configuration +dnl +if test -f "$srcdir/include/GL/glut.h"; then + default_glut=yes +else + default_glut=no +fi +AC_ARG_ENABLE([glut], + [AS_HELP_STRING([--disable-glut], + [enable GLUT library @<:@default=enabled if source available@:>@])], + [enable_glut="$enableval"], + [enable_glut="$default_glut"]) + +dnl Don't build glut on osmesa +if test "x$enable_glut" = xyes; then + case "$mesa_driver" in + osmesa|no) + AC_MSG_NOTICE([Disabling glut since there is no OpenGL driver]) + enable_glut=no + ;; + esac +fi +dnl Can't build glut if GLU not available +if test "x$enable_glu$enable_glut" = xnoyes; then + AC_MSG_WARN([Disabling glut since GLU is disabled]) + enable_glut=no +fi + +if test "x$enable_glut" = xyes; then + SRC_DIRS="$SRC_DIRS glut/glx" + if test "$x11_pkgconfig" = yes; then + PKG_CHECK_MODULES([GLUT],[x11 xmu xi]) + GLUT_PC_REQ_PRIV="x11 xmu xi" + GLUT_LIB_DEPS="$GLUT_LIBS" + else + # should check these... + GLUT_LIB_DEPS="$X_LIBS -lX11 -lXmu -lXi" + GLUT_PC_LIB_PRIV="$GLUT_LIB_DEPS" + GLUT_PC_CFLAGS="$X11_INCLUDES" + fi + if test "x$GCC" = xyes; then + GLUT_CFLAGS="$GLUT_CFLAGS -fexceptions" + fi + GLUT_LIB_DEPS="$GLUT_LIB_DEPS -lm" + GLUT_PC_LIB_PRIV="$GLUT_PC_LIB_PRIV -lm" + + # If static, empty GLUT_LIB_DEPS and add libs for programs to link + if test "$enable_static" = no; then + GLUT_MESA_DEPS='-l$(GLU_LIB) -l$(GL_LIB)' + else + APP_LIB_DEPS="$APP_LIB_DEPS $GLUT_LIB_DEPS" + GLUT_LIB_DEPS="" + GLUT_MESA_DEPS="" + fi +fi +AC_SUBST([GLUT_LIB_DEPS]) +AC_SUBST([GLUT_MESA_DEPS]) +AC_SUBST([GLUT_CFLAGS]) +AC_SUBST([GLUT_PC_REQ_PRIV]) +AC_SUBST([GLUT_PC_LIB_PRIV]) +AC_SUBST([GLUT_PC_CFLAGS]) + +dnl +dnl Program library dependencies +dnl Only libm is added here if necessary as the libraries should +dnl be pulled in by the linker +dnl +if test "x$APP_LIB_DEPS" = x; then + case "$host_os" in + solaris*) + APP_LIB_DEPS="-lX11 -lsocket -lnsl -lm" + ;; + cygwin*) + APP_LIB_DEPS="-lX11" + ;; + *) + APP_LIB_DEPS="-lm" + ;; + esac +fi +AC_SUBST([APP_LIB_DEPS]) +AC_SUBST([PROGRAM_DIRS]) + +dnl +dnl Gallium configuration +dnl +AC_ARG_ENABLE([gallium], + [AS_HELP_STRING([--disable-gallium], + [build gallium @<:@default=enabled@:>@])], + [enable_gallium="$enableval"], + [enable_gallium=yes]) +if test "x$enable_gallium" = xno -a "x$enable_openvg" = xyes; then + AC_MSG_ERROR([cannot enable OpenVG without Gallium]) +fi +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]) +fi + +AC_SUBST([LLVM_CFLAGS]) +AC_SUBST([LLVM_LIBS]) +AC_SUBST([LLVM_LDFLAGS]) +AC_SUBST([LLVM_VERSION]) + +dnl +dnl Gallium state trackers configuration +dnl + +AC_ARG_ENABLE([gallium-egl], + [AS_HELP_STRING([--enable-gallium-egl], + [enable gallium EGL state tracker @<:@default=auto@:>@])], + [enable_gallium_egl="$enableval"], + [enable_gallium_egl=auto]) +if test "x$enable_gallium_egl" = xauto; then + case "$mesa_driver" in + dri|no) + enable_gallium_egl=$enable_egl + ;; + *) + enable_gallium_egl=$enable_openvg + ;; + esac +fi +case "x$enable_egl$enable_gallium_egl" in +xnoyes) + AC_MSG_ERROR([cannot build Gallium EGL state tracker without EGL]) +esac + +AC_ARG_WITH([state-trackers], + [AS_HELP_STRING([--with-state-trackers@<:@=DIRS...@:>@], + [comma delimited state_trackers list, e.g. + "egl,glx" @<:@default=auto@:>@])], + [with_state_trackers="$withval"], + [with_state_trackers=yes]) + +case "$with_state_trackers" in +no) + GALLIUM_STATE_TRACKERS_DIRS="" + ;; +yes) + # look at what else is built + case "$mesa_driver" in + xlib) + GALLIUM_STATE_TRACKERS_DIRS=glx + ;; + dri) + GALLIUM_STATE_TRACKERS_DIRS="dri" + HAVE_ST_DRI="yes" + # 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_ST_XORG="yes"; GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg", + HAVE_ST_XORG="no") + ;; + esac + + if test "x$enable_egl" = xyes; then + if test "$enable_openvg" = yes; then + GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS vega" + st_egl="yes" + fi + + if test "$enable_gallium_egl" = yes; then + GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl" + HAVE_ST_EGL="yes" + fi + fi + ;; +*) + # verify the requested state tracker exist + state_trackers="" + _state_trackers=`IFS=', '; echo $with_state_trackers` + for tracker in $_state_trackers; do + 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" + ;; + 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([XORG], [xorg-server >= 1.6.0]) + PKG_CHECK_MODULES([LIBDRM_XORG], [libdrm >= $LIBDRM_XORG_REQUIRED]) + PKG_CHECK_MODULES([LIBKMS_XORG], [libkms >= $LIBKMS_XORG_REQUIRED]) + HAVE_ST_XORG="yes" + ;; + vega) + if test "x$enable_openvg" != xyes; then + AC_MSG_ERROR([cannot build vega state tracker without --enable-openvg]) + fi + ;; + esac + + if test -n "$tracker"; then + test -d "$srcdir/src/gallium/state_trackers/$tracker" || \ + AC_MSG_ERROR([state tracker '$tracker' doesn't exist]) + if test -n "$state_trackers"; then + state_trackers="$state_trackers $tracker" + else + state_trackers="$tracker" + fi + fi + done + GALLIUM_STATE_TRACKERS_DIRS="$state_trackers" + ;; +esac + + +EGL_CLIENT_APIS="" +VG_LIB_DEPS="" + +case "x$enable_opengl$enable_gles1$enable_gles2" in +x*yes*) + EGL_CLIENT_APIS="$EGL_CLIENT_APIS "'$(GL_LIB)' + ;; +esac +if test "x$enable_gles_overlay" = xyes; then + EGL_CLIENT_APIS="$EGL_CLIENT_APIS "'$(GLESv1_CM_LIB) $(GLESv2_LIB)' +fi +if test "x$enable_openvg" = xyes; then + EGL_CLIENT_APIS="$EGL_CLIENT_APIS "'$(VG_LIB)' + VG_LIB_DEPS="$VG_LIB_DEPS -lpthread" +fi + +AC_SUBST([VG_LIB_DEPS]) +AC_SUBST([EGL_CLIENT_APIS]) + +if test "x$HAVE_ST_EGL" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl" +fi + +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") +fi + +AC_ARG_WITH([egl-platforms], + [AS_HELP_STRING([--with-egl-platforms@<:@=DIRS...@:>@], + [comma delimited native platforms libEGL supports, e.g. + "x11,drm" @<:@default=auto@:>@])], + [with_egl_platforms="$withval"], + [with_egl_platforms=yes]) +AC_ARG_WITH([egl-displays], + [AS_HELP_STRING([--with-egl-displays@<:@=DIRS...@:>@], + [DEPRECATED. Use --with-egl-platforms instead])], + [with_egl_platforms="$withval"]) + +EGL_PLATFORMS="" +case "$with_egl_platforms" in +yes) + if test "x$enable_egl" = xyes && test "x$mesa_driver" != xosmesa; then + EGL_PLATFORMS="x11" + if test "$mesa_driver" = dri; then + EGL_PLATFORMS="$EGL_PLATFORMS drm" + fi + fi + ;; +*) + if test "x$enable_egl" != xyes; then + AC_MSG_ERROR([cannot build egl state tracker without EGL library]) + fi + # verify the requested driver directories exist + egl_platforms=`IFS=', '; echo $with_egl_platforms` + for plat in $egl_platforms; do + test -d "$srcdir/src/gallium/state_trackers/egl/$plat" || \ + AC_MSG_ERROR([EGL platform '$plat' does't exist]) + if test "$plat" = "fbdev"; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/fbdev" + fi + done + EGL_PLATFORMS="$egl_platforms" + ;; +esac +AC_SUBST([EGL_PLATFORMS]) + +AC_ARG_WITH([egl-driver-dir], + [AS_HELP_STRING([--with-egl-driver-dir=DIR], + [directory for EGL drivers [[default=${libdir}/egl]]])], + [EGL_DRIVER_INSTALL_DIR="$withval"], + [EGL_DRIVER_INSTALL_DIR='${libdir}/egl']) +AC_SUBST([EGL_DRIVER_INSTALL_DIR]) + +AC_ARG_WITH([xorg-driver-dir], + [AS_HELP_STRING([--with-xorg-driver-dir=DIR], + [Default xorg driver directory[[default=${libdir}/xorg/modules/drivers]]])], + [XORG_DRIVER_INSTALL_DIR="$withval"], + [XORG_DRIVER_INSTALL_DIR="${libdir}/xorg/modules/drivers"]) +AC_SUBST([XORG_DRIVER_INSTALL_DIR]) + +AC_ARG_WITH([max-width], + [AS_HELP_STRING([--with-max-width=N], + [Maximum framebuffer width (4096)])], + [DEFINES="${DEFINES} -DMAX_WIDTH=${withval}"; + AS_IF([test "${withval}" -gt "4096"], + [AC_MSG_WARN([Large framebuffer: see s_tritemp.h comments.])])] +) +AC_ARG_WITH([max-height], + [AS_HELP_STRING([--with-max-height=N], + [Maximum framebuffer height (4096)])], + [DEFINES="${DEFINES} -DMAX_HEIGHT=${withval}"; + AS_IF([test "${withval}" -gt "4096"], + [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 + LLVM_VERSION=`$LLVM_CONFIG --version` + LLVM_CFLAGS=`$LLVM_CONFIG --cppflags` + 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 + LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags` + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS llvmpipe" + DEFINES="$DEFINES -DGALLIUM_LLVMPIPE -D__STDC_CONSTANT_MACROS" + MESA_LLVM=1 + else + MESA_LLVM=0 + fi +else + MESA_LLVM=0 +fi + +dnl +dnl Gallium helper functions +dnl +gallium_check_st() { + if test "x$HAVE_ST_DRI" = 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_XORG" = xyes && test "x$3" != x; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS $3" + fi +} + + +dnl +dnl Gallium SVGA configuration +dnl +AC_ARG_ENABLE([gallium-svga], + [AS_HELP_STRING([--enable-gallium-svga], + [build gallium SVGA @<:@default=disabled@:>@])], + [enable_gallium_svga="$enableval"], + [enable_gallium_svga=auto]) +if test "x$enable_gallium_svga" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" + gallium_check_st "svga/drm" "dri-vmwgfx" "xorg-vmwgfx" +elif test "x$enable_gallium_svga" = xauto; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" +fi + +dnl +dnl Gallium i915 configuration +dnl +AC_ARG_ENABLE([gallium-i915], + [AS_HELP_STRING([--enable-gallium-i915], + [build gallium i915 @<:@default=disabled@:>@])], + [enable_gallium_i915="$enableval"], + [enable_gallium_i915=auto]) +if test "x$enable_gallium_i915" = xyes; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw" + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915" + gallium_check_st "i915/drm" "dri-i915" "xorg-i915" +elif test "x$enable_gallium_i915" = xauto; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw" + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915" +fi + +dnl +dnl Gallium i965 configuration +dnl +AC_ARG_ENABLE([gallium-i965], + [AS_HELP_STRING([--enable-gallium-i965], + [build gallium i965 @<:@default=disabled@:>@])], + [enable_gallium_i965="$enableval"], + [enable_gallium_i965=auto]) +if test "x$enable_gallium_i965" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i965" + gallium_check_st "i965/drm" "dri-i965" "xorg-i965" +elif test "x$enable_gallium_i965" = xauto; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i965" +fi + +dnl +dnl Gallium Radeon r300g configuration +dnl +AC_ARG_ENABLE([gallium-radeon], + [AS_HELP_STRING([--enable-gallium-radeon], + [build gallium radeon @<:@default=disabled@:>@])], + [enable_gallium_radeon="$enableval"], + [enable_gallium_radeon=auto]) +if test "x$enable_gallium_radeon" = xauto; then + if test "x$HAVE_LIBDRM_RADEON" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" + gallium_check_st "radeon/drm" "dri-r300" + else + AC_MSG_WARN([libdrm_radeon is missing, not building gallium-radeon (r300)]) + fi +fi +if test "x$enable_gallium_radeon" = xyes; then + if test "x$HAVE_LIBDRM_RADEON" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" + gallium_check_st "radeon/drm" "dri-r300" "xorg-radeon" + else + AC_MSG_ERROR([libdrm_radeon is missing, cannot build gallium-radeon (r300)]) + fi +fi + +dnl +dnl Gallium Radeon r600g configuration +dnl +AC_ARG_ENABLE([gallium-r600], + [AS_HELP_STRING([--enable-gallium-r600], + [build gallium radeon @<:@default=disabled@:>@])], + [enable_gallium_r600="$enableval"], + [enable_gallium_r600=auto]) +if test "x$enable_gallium_r600" = xyes; then + if test "x$HAVE_LIBDRM_RADEON" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r600" + gallium_check_st "r600/drm" "dri-r600" + else + AC_MSG_ERROR([libdrm_radeon is missing, cannot build gallium-r600]) + fi +fi + +dnl +dnl Gallium Nouveau configuration +dnl +AC_ARG_ENABLE([gallium-nouveau], + [AS_HELP_STRING([--enable-gallium-nouveau], + [build gallium nouveau @<:@default=disabled@:>@])], + [enable_gallium_nouveau="$enableval"], + [enable_gallium_nouveau=no]) +if test "x$enable_gallium_nouveau" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50" + gallium_check_st "nouveau/drm" "dri-nouveau" "xorg-nouveau" +fi + +dnl +dnl Gallium swrast configuration +dnl +AC_ARG_ENABLE([gallium-swrast], + [AS_HELP_STRING([--enable-gallium-swrast], + [build gallium swrast @<:@default=auto@:>@])], + [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_DRI" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-swrast" + fi +fi + +dnl +dnl Gallium noop configuration +dnl +AC_ARG_ENABLE([gallium-noop], + [AS_HELP_STRING([--enable-gallium-noop], + [build gallium radeon @<:@default=disabled@:>@])], + [enable_gallium_noop="$enableval"], + [enable_gallium_noop=auto]) +if test "x$enable_gallium_noop" = xyes; then + GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS noop" + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-noop" +fi + +dnl prepend CORE_DIRS to SRC_DIRS +SRC_DIRS="$CORE_DIRS $SRC_DIRS" + +dnl Restore LDFLAGS and CPPFLAGS +LDFLAGS="$_SAVE_LDFLAGS" +CPPFLAGS="$_SAVE_CPPFLAGS" + +dnl Substitute the config +AC_CONFIG_FILES([configs/autoconf]) + +dnl Replace the configs/current symlink +AC_CONFIG_COMMANDS([configs],[ +if test -f configs/current || test -L configs/current; then + rm -f configs/current +fi +ln -s autoconf configs/current +]) + +AC_OUTPUT + +dnl +dnl Output some configuration info for the user +dnl +echo "" +echo " prefix: $prefix" +echo " exec_prefix: $exec_prefix" +echo " libdir: $libdir" +echo " includedir: $includedir" + +dnl API info +echo "" +echo " OpenGL: $enable_opengl (ES1: $enable_gles1 ES2: $enable_gles2)" +echo " GLES overlay: $enable_gles_overlay" +echo " OpenVG: $enable_openvg" + +dnl Driver info +echo "" +echo " Driver: $mesa_driver" +if test "$mesa_driver" != no; then + if echo "$DRIVER_DIRS" | grep 'osmesa' >/dev/null 2>&1; then + echo " OSMesa: lib$OSMESA_LIB" + else + echo " OSMesa: no" + fi + if test "$mesa_driver" = dri; then + # cleanup the drivers var + dri_dirs=`echo $DRI_DIRS | $SED 's/^ *//;s/ */ /;s/ *$//'` + if test "x$DRI_DIRS" = x; then + echo " DRI drivers: no" + else + echo " DRI drivers: $dri_dirs" + fi + echo " DRI driver dir: $DRI_DRIVER_INSTALL_DIR" + echo " Use XCB: $enable_xcb" + fi +fi +echo "" +echo " GLU: $enable_glu" +echo " GLw: $enable_glw (Motif: $enable_motif)" +echo " glut: $enable_glut" + +dnl EGL +echo "" +echo " EGL: $enable_egl" +if test "$enable_egl" = yes; then + echo " EGL platforms: $EGL_PLATFORMS" + + egl_drivers="" + for d in $EGL_DRIVERS_DIRS; do + egl_drivers="$egl_drivers egl_$d" + done + + if test "$enable_gallium" = yes -a "$HAVE_ST_EGL" = yes; then + echo " EGL drivers: ${egl_drivers} egl_gallium" + echo " EGL Gallium STs:$EGL_CLIENT_APIS" + else + echo " EGL drivers: $egl_drivers" + fi +fi + +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" + echo " Gallium dirs: $GALLIUM_DIRS" + echo " Target dirs: $GALLIUM_TARGET_DIRS" + echo " Winsys dirs: $GALLIUM_WINSYS_DIRS" + echo " Driver dirs: $GALLIUM_DRIVERS_DIRS" + echo " Trackers dirs: $GALLIUM_STATE_TRACKERS_DIRS" +else + echo " Gallium: no" +fi + +dnl Libraries +echo "" +echo " Shared libs: $enable_shared" +echo " Static libs: $enable_static" + +dnl Compiler options +# cleanup the CFLAGS/CXXFLAGS/DEFINES vars +cflags=`echo $CFLAGS $OPT_FLAGS $PIC_FLAGS $ARCH_FLAGS | \ + $SED 's/^ *//;s/ */ /;s/ *$//'` +cxxflags=`echo $CXXFLAGS $OPT_FLAGS $PIC_FLAGS $ARCH_FLAGS | \ + $SED 's/^ *//;s/ */ /;s/ *$//'` +defines=`echo $DEFINES $ASM_FLAGS | $SED 's/^ *//;s/ */ /;s/ *$//'` +echo "" +echo " CFLAGS: $cflags" +echo " CXXFLAGS: $cxxflags" +echo " Macros: $defines" +echo "" +echo " PYTHON2: $PYTHON2" + +echo "" +echo " Run '${MAKE-make}' to build Mesa" +echo "" diff --git a/docs/COPYING b/docs/COPYING new file mode 100644 index 0000000..b88946c --- /dev/null +++ b/docs/COPYING @@ -0,0 +1,490 @@ + +Some parts of Mesa are copyrighted under the GNU LGPL. See the +Mesa/docs/COPYRIGHT file for details. + +The following is the standard GNU copyright file. +---------------------------------------------------------------------- + + + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link a program with the library, you must provide +complete object files to the recipients so that they can relink them +with the library, after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +General Public License (also called "this License"). Each licensee is +addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also compile or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + c) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + d) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the source code distributed need not include anything that is normally +distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Library General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + diff --git a/docs/MESA_agp_offset.spec b/docs/MESA_agp_offset.spec new file mode 100644 index 0000000..8dcc723 --- /dev/null +++ b/docs/MESA_agp_offset.spec @@ -0,0 +1,95 @@ +Name + + MESA_agp_offset + +Name Strings + + GLX_MESA_agp_offset + +Contact + + Brian Paul, Tungsten Graphics, Inc. (brian.paul 'at' tungstengraphics.com) + Keith Whitwell, Tungsten Graphics, Inc. (keith 'at' tungstengraphics.com) + +Status + + Shipping (Mesa 4.0.4 and later. Only implemented in particular + XFree86/DRI drivers.) + +Version + + 1.0 + +Number + + TBD + +Dependencies + + OpenGL 1.0 or later is required + GLX_NV_vertex_array_range is required. + This extensions is written against the OpenGL 1.4 Specification. + +Overview + + This extensions provides a way to convert pointers in an AGP memory + region into byte offsets into the AGP aperture. + Note, this extension depends on GLX_NV_vertex_array_range, for which + no real specification exists. See GL_NV_vertex_array_range for more + information. + +IP Status + + None + +Issues + + None + +New Procedures and Functions + + unsigned int glXGetAGPOffsetMESA( const void *pointer ) + +New Tokens + + None + +Additions to the OpenGL 1.4 Specification + + None + +Additions to Chapter 3 the GLX 1.4 Specification (Functions and Errors) + + Add a new section, 3.6 as follows: + + 3.6 AGP Memory Access + + On "PC" computers, AGP memory can be allocated with glXAllocateMemoryNV + and freed with glXFreeMemoryNV. Sometimes it's useful to know where a + block of AGP memory is located with respect to the start of the AGP + aperature. The function + + GLuint glXGetAGPOffsetMESA( const GLvoid *pointer ) + + Returns the offset of the given memory block from the start of AGP + memory in basic machine units (i.e. bytes). If pointer is invalid + the value ~0 will be returned. + +GLX Protocol + + None. This is a client side-only extension. + +Errors + + glXGetAGPOffsetMESA will return ~0 if the pointer does not point to + an AGP memory region. + +New State + + None + +Revision History + + 20 September 2002 - Initial draft + 2 October 2002 - finished GLX chapter 3 additions + 27 July 2004 - use unsigned int instead of GLuint, void instead of GLvoid diff --git a/docs/MESA_copy_sub_buffer.spec b/docs/MESA_copy_sub_buffer.spec new file mode 100644 index 0000000..752a014 --- /dev/null +++ b/docs/MESA_copy_sub_buffer.spec @@ -0,0 +1,96 @@ +Name + + MESA_copy_sub_buffer + +Name Strings + + GLX_MESA_copy_sub_buffer + +Contact + + Brian Paul (brian.paul 'at' tungstengraphics.com) + +Status + + Shipping since Mesa 2.6 in February, 1998. + +Version + + Last Modified Date: 12 January 2009 + +Number + + 215 + +Dependencies + + OpenGL 1.0 or later is required. + GLX 1.0 or later is required. + +Overview + + The glxCopySubBufferMESA() function copies a rectangular region + of the back color buffer to the front color buffer. This can be + used to quickly repaint 3D windows in response to expose events + when the back color buffer cannot be damaged by other windows. + +IP Status + + Open-source; freely implementable. + +Issues + + None. + +New Procedures and Functions + + void glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable, + int x, int y, int width, int height ); + +New Tokens + + None. + +Additions to Chapter 3 of the GLX 1.3 Specification (Functions and Errors) + + Add to section 3.3.10 Double Buffering: + + The function + + void glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable, + int x, int y, int width, int height ); + + may be used to copy a rectangular region of the back color buffer to + the front color buffer. This can be used to quickly repaint 3D windows + in response to expose events when the back color buffer cannot be + damaged by other windows. + + and indicates the lower-left corner of the region to copy and + and indicate the size in pixels. Coordinate (0,0) + corresponds to the lower-left pixel of the window, like glReadPixels. + + If dpy and drawable are the display and drawable for the calling + thread's current context, glXCopySubBufferMESA performs an + implicit glFlush before it returns. Subsequent OpenGL commands + may be issued immediately after calling glXCopySubBufferMESA, but + are not executed until the copy is completed. + +GLX Protocol + + None at this time. The extension is implemented in terms of ordinary + Xlib protocol inside of Mesa. + +Errors + + None. + +New State + + None. + +Revision History + + 12 January 2009 Ian Romanick - Added language about implicit flush + and command completion. + 8 June 2000 Brian Paul - initial specification + diff --git a/docs/MESA_drm_image.spec b/docs/MESA_drm_image.spec new file mode 100644 index 0000000..c9853a7 --- /dev/null +++ b/docs/MESA_drm_image.spec @@ -0,0 +1,149 @@ +Name + + MESA_drm_image + +Name Strings + + EGL_MESA_drm_image + +Contact + + Kristian Høgsberg + +Status + + Proposal + +Version + + Version 2, August 25, 2010 + +Number + + EGL Extension #not assigned + +Dependencies + + Reguires EGL 1.4 or later. This extension is written against the + wording of the EGL 1.4 specification. + + EGL_KHR_base_image is required. + +Overview + + This extension provides entry points for integrating EGLImage with the + Linux DRM mode setting and memory management drivers. The extension + lets applications create EGLImages without a client API resource and + lets the application get the DRM buffer handles. + +IP Status + + Open-source; freely implementable. + +New Procedures and Functions + + EGLImageKHR eglCreateDRMImageMESA(EGLDisplay dpy, + const EGLint *attrib_list); + + EGLBoolean eglExportDRMImageMESA(EGLDisplay dpy, + EGLImageKHR image, + EGLint *name, + EGLint *handle, + EGLint *stride); + +New Tokens + + Accepted in the parameter of eglCreateDRMImageMESA: + + EGL_DRM_BUFFER_FORMAT_MESA 0x31D0 + EGL_DRM_BUFFER_USE_MESA 0x31D1 + + Accepted as values for the EGL_IMAGE_FORMAT_MESA attribute: + + EGL_DRM_BUFFER_FORMAT_ARGB32_MESA 0x31D2 + + Bits accepted in EGL_DRM_BUFFER_USE_MESA: + + EGL_DRM_BUFFER_USE_SCANOUT_MESA 0x0001 + EGL_DRM_BUFFER_USE_SHARE_MESA 0x0002 + + Accepted in the parameter of eglCreateImageKHR: + + EGL_DRM_BUFFER_MESA 0x31D3 + + Use when importing drm buffer: + + EGL_DRM_BUFFER_STRIDE_MESA 0x31D4 + EGL_DRM_BUFFER_FORMAT_MESA 0x31D0 + +Additions to the EGL 1.4 Specification: + + To create a DRM EGLImage, call + + EGLImageKHR eglCreateDRMImageMESA(EGLDisplay dpy, + const EGLint *attrib_list); + + In the attribute list, pass EGL_WIDTH, EGL_HEIGHT and format and + use in the attrib list using EGL_DRM_BUFFER_FORMAT_MESA and + EGL_DRM_BUFFER_USE_MESA. The only format specified by this + extension is EGL_DRM_BUFFER_FORMAT_ARGB32_MESA, where each pixel + is a CPU-endian, 32-bit quantity, with alpha in the upper 8 bits, + then red, then green, then blue. The bit values accepted by + EGL_DRM_BUFFER_USE_MESA are EGL_DRM_BUFFER_USE_SCANOUT_MESA and + EGL_DRM_BUFFER_USE_SHARE_MESA. EGL_DRM_BUFFER_USE_SCANOUT_MESA + requests that the created EGLImage should be usable as a scanout + buffer with the DRM kernel modesetting API. The + EGL_DRM_BUFFER_USE_SHARE_MESA bit requests that the EGLImage can + be shared with other processes by passing the underlying DRM + buffer name. + + To create a process local handle or a global DRM name for a + buffer, call + + EGLBoolean eglExportDRMImageMESA(EGLDisplay dpy, + EGLImageKHR image, + EGLint *name, + EGLint *handle, + EGLint *stride); + + If is non-NULL, a global name is assigned to the image and + written to , the handle (local to the DRM file descriptor, + for use with DRM kernel modesetting API) is written to if + non-NULL and the stride (in bytes) is written to , if + non-NULL. + + Import a shared buffer by calling eglCreateImageKHR with + EGL_DRM_BUFFER_MESA as the target, using EGL_WIDTH, EGL_HEIGHT, + EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_STRIDE_MESA + in the attrib list. + +Issues + + 1. Why don't we use eglCreateImageKHR with a target that + indicates that we want to create an EGLImage from scratch? + + RESOLVED: The eglCreateImageKHR entry point is reserved for + creating an EGLImage from an already existing client API + resource. This is fine when we're creating the EGLImage from + an existing DRM buffer name, it doesn't seem right to overload + the function to also allocate the underlying resource. + + 2. Why don't we use an eglQueryImageMESA type functions for + querying the DRM EGLImage attributes (name, handle, and stride)? + + RESOLVED: The eglQueryImage function has been proposed often, + but it goes against the EGLImage design. EGLImages are opaque + handles to a 2D array of pixels, which can be passed between + client APIs. By referenceing an EGLImage in a client API, the + EGLImage target (a texture, a renderbuffer or such) can be + used to query the attributes of the EGLImage. We don't have a + full client API for creating and querying DRM buffers, though, + so we use a new EGL extension entry point instead. + +Revision History + + Version 1, June 3, 2010 + Initial draft (Kristian Høgsberg) + Version 2, August 25, 2010 + Flesh out the extension a bit, add final EGL tokens, capture + some of the original discussion in the issues section. diff --git a/docs/MESA_pack_invert.spec b/docs/MESA_pack_invert.spec new file mode 100644 index 0000000..53d5fca --- /dev/null +++ b/docs/MESA_pack_invert.spec @@ -0,0 +1,138 @@ +Name + + MESA_pack_invert + +Name Strings + + GL_MESA_pack_invert + +Contact + + Brian Paul, Tungsten Graphics, Inc. (brian.paul 'at' tungstengraphics.com) + Keith Whitwell, Tungsten Graphics, Inc. (keith 'at' tungstengraphics.com) + +Status + + Shipping (Mesa 4.0.4 and later) + +Version + + 1.0 + +Number + + TBD + +Dependencies + + OpenGL 1.0 or later is required + This extensions is written against the OpenGL 1.4 Specification. + +Overview + + This extension adds a new pixel storage parameter to indicate that + images are to be packed in top-to-bottom order instead of OpenGL's + conventional bottom-to-top order. Only pixel packing can be + inverted (i.e. for glReadPixels, glGetTexImage, glGetConvolutionFilter, + etc). + + Almost all known image file formats store images in top-to-bottom + order. As it is, OpenGL reads images from the frame buffer in + bottom-to-top order. Thus, images usually have to be inverted before + writing them to a file with image I/O libraries. This extension + allows images to be read such that inverting isn't needed. + +IP Status + + None + +Issues + + 1. Should we also defined UNPACK_INVERT_MESA for glDrawPixels, etc? + + Resolved: No, we're only concerned with pixel packing. There are other + solutions for inverting images when using glDrawPixels (negative Y pixel + zoom) or glTexImage (invert the vertex T coordinates). It would be easy + enough to define a complementary extension for pixel packing in the + future if needed. + +New Procedures and Functions + + None + +New Tokens + + Accepted by the parameter of PixelStorei and PixelStoref + and the parameter of GetIntegerv, GetFloatv, GetDoublev + and GetBooleanv: + + PACK_INVERT_MESA 0x8758 + +Additions to Chapter 2 of the OpenGL 1.4 Specification (OpenGL Operation) + + None + +Additions to Chapter 3 of the OpenGL 1.4 Specification (Rasterization) + + None + +Additions to Chapter 4 of the OpenGL 1.4 Specification (Per-Fragment +Operations and the Frame Buffer) + + Add the following entry to table 4.4 (PixelStore parameters) on page 182: + + Parameter Name Type Initial Value Valid Range + --------------------------------------------------------- + PACK_INVERT_MESA boolean FALSE TRUE/FALSE + + In the section labeled "Placement in Client Memory" on page 184 + insert the following text into the paragraph before the sentence + that starts with "If the format is RED, GREEN, BLUE...": + + "The parameter PACK_INVERT_MESA controls whether the image is packed + in bottom-to-top order (the default) or top-to-bottom order. Equation + 3.8 is modified as follows: + + ... the first element of the Nth row is indicated by + + p + Nk, if PACK_INVERT_MESA is false + p + k * (H - 1) - Nk, if PACK_INVERT_MESA is true, where H is the + image height + " + +Additions to Chapter 5 of the OpenGL 1.4 Specification (Special Functions) + + None + +Additions to Chapter 6 of the OpenGL 1.4 Specification (State and +State Requests) + + None + +Additions to Appendix A of the OpenGL 1.4 Specification (Invariance) + + None + +Additions to the AGL/GLX/WGL Specifications + + None + +GLX Protocol + + None + +Errors + + None + +New State + + Add the following entry to table 6.20 (Pixels) on page 235: + + Get Value Type Get Cmd Initial Value Description Sec Attribute + -------------------------------------------------------------------------------------------------- + PACK_INVERT_MESA boolean GetBoolean FALSE Value of PACK_INVERT_MESA 4.3.2 pixel-store + +Revision History + + 21 September 2002 - Initial draft diff --git a/docs/MESA_pixmap_colormap.spec b/docs/MESA_pixmap_colormap.spec new file mode 100644 index 0000000..fb0b441 --- /dev/null +++ b/docs/MESA_pixmap_colormap.spec @@ -0,0 +1,90 @@ +Name + + MESA_pixmap_colormap + +Name Strings + + GLX_MESA_pixmap_colormap + +Contact + + Brian Paul (brian.paul 'at' tungstengraphics.com) + +Status + + Shipping since Mesa 1.2.8 in May, 1996. + +Version + + Last Modified Date: 8 June 2000 + +Number + + 216 + +Dependencies + + OpenGL 1.0 or later is required. + GLX 1.0 or later is required. + +Overview + + Since Mesa allows RGB rendering into drawables with PseudoColor, + StaticColor, GrayScale and StaticGray visuals, Mesa needs a colormap + in order to compute pixel values during rendering. + + The colormap associated with a window can be queried with normal + Xlib functions but there is no colormap associated with pixmaps. + + The glXCreateGLXPixmapMESA function is an alternative to glXCreateGLXPixmap + which allows specification of a colormap. + +IP Status + + Open-source; freely implementable. + +Issues + + None. + +New Procedures and Functions + + GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual, + Pixmap pixmap, Colormap cmap ); + +New Tokens + + None. + +Additions to Chapter 3 of the GLX 1.3 Specification (Functions and Errors) + + Add to section 3.4.2 Off Screen Rendering + + The Mesa implementation of GLX allows RGB rendering into X windows and + pixmaps of any visual class, not just TrueColor or DirectColor. In order + to compute pixel values from RGB values Mesa requires a colormap. + + The function + + GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual, + Pixmap pixmap, Colormap cmap ); + + allows one to create a GLXPixmap with a specific colormap. The image + rendered into the pixmap may then be copied to a window (which uses the + same colormap and visual) with the expected results. + +GLX Protocol + + None since this is a client-side extension. + +Errors + + None. + +New State + + None. + +Revision History + + 8 June 2000 - initial specification diff --git a/docs/MESA_release_buffers.spec b/docs/MESA_release_buffers.spec new file mode 100644 index 0000000..8db9350 --- /dev/null +++ b/docs/MESA_release_buffers.spec @@ -0,0 +1,85 @@ +Name + + MESA_release_buffers + +Name Strings + + GLX_MESA_release_buffers + +Contact + + Brian Paul (brian.paul 'at' tungstengraphics.com) + +Status + + Shipping since Mesa 2.0 in October, 1996. + +Version + + Last Modified Date: 8 June 2000 + +Number + + 217 + +Dependencies + + OpenGL 1.0 or later is required. + GLX 1.0 or later is required. + +Overview + + Mesa's implementation of GLX is entirely implemented on the client side. + Therefore, Mesa cannot immediately detect when an X window or pixmap is + destroyed in order to free any ancilliary data associated with the window + or pixmap. + + The glxMesaReleaseBuffers() function can be used to explicitly indicate + when the back color buffer, depth buffer, stencil buffer, and/or accum- + ulation buffer associated with a drawable can be freed. + +IP Status + + Open-source; freely implementable. + +Issues + + None. + +New Procedures and Functions + + Bool glXReleaseBuffersMESA( Display *dpy, GLXDrawable d ); + +New Tokens + + None. + +Additions to Chapter 3 of the GLX 1.3 Specification (Functions and Errors) + + The function + + Bool glXReleaseBuffersMESA( Display *dpy, GLXDrawable d ); + + causes all software ancilliary buffers (back buffer, depth, stencil, + accum, etc) associated with the named drawable to be immediately + deallocated. True is returned if is a valid Mesa GLX drawable, + else False is returned. After calling glXReleaseBuffersMESA, the + drawable should no longer be used for GL rendering. Results of + attempting to do so are undefined. + + +GLX Protocol + + None, since this is a client-side operation. + +Errors + + None. + +New State + + None. + +Revision History + + 8 June 2000 - initial specification diff --git a/docs/MESA_resize_buffers.spec b/docs/MESA_resize_buffers.spec new file mode 100644 index 0000000..533d017 --- /dev/null +++ b/docs/MESA_resize_buffers.spec @@ -0,0 +1,81 @@ +Name + + MESA_resize_buffers + +Name Strings + + GL_MESA_resize_buffers + +Contact + + Brian Paul (brian.paul 'at' tungstengraphics.com) + +Status + + Shipping (since Mesa version 2.2) + +Version + + +Number + + 196 + +Dependencies + + Mesa 2.2 or later is required. + +Overview + + Mesa is often used as a client library with no integration with + the computer's window system (an X server, for example). And since + Mesa does not have an event loop nor window system callbacks, it + cannot properly respond to window system events. In particular, + Mesa cannot automatically detect when a window has been resized. + + Mesa's glViewport command queries the current window size and updates + its internal data structors accordingly. This normally works fine + since most applications call glViewport in responce to window size + changes. + + In some situations, however, the application may not call glViewport + when a window size changes but would still like Mesa to adjust to + the new window size. This extension exports a new function to solve + this problem. + +New Procedures and Functions + + void glResizeBuffersMESA( void ) + +New Tokens + + none + +Additions to the OpenGL Specification (no particular section) + + The glResizeBuffersMESA command may be called when the client + determines that a window has been resized. Calling + glResizeBuffersMESA causes Mesa to query the current window size + and adjust its internal data structures. This may include + reallocating depth, stencil, alpha and accumulation buffers. + +Additions to the AGL/GLX/WGL Specifications + + None + +Errors + + INVALID_OPERATION is generated if ResizeBuffersMESA is called betweeen + Begin and End. + +New State + + None. + +New Implementation Dependent State + + None. + +Revision History + + * Revision 1.0 - Initial specification diff --git a/docs/MESA_set_3dfx_mode.spec b/docs/MESA_set_3dfx_mode.spec new file mode 100644 index 0000000..06d97ca --- /dev/null +++ b/docs/MESA_set_3dfx_mode.spec @@ -0,0 +1,85 @@ +Name + + MESA_set_3dfx_mode + +Name Strings + + GLX_MESA_set_3dfx_mode + +Contact + + Brian Paul (brian.paul 'at' tungstengraphics.com) + +Status + + Shipping since Mesa 2.6 in February, 1998. + +Version + + Last Modified Date: 8 June 2000 + +Number + + 218 + +Dependencies + + OpenGL 1.0 or later is required. + GLX 1.0 or later is required. + +Overview + + The Mesa Glide driver allows full-screen rendering or rendering into + an X window. The glXSet3DfxModeMESA() function allows an application + to switch between full-screen and windowed rendering. + +IP Status + + Open-source; freely implementable. + +Issues + + None. + +New Procedures and Functions + + GLboolean glXSet3DfxModeMESA( GLint mode ); + +New Tokens + + GLX_3DFX_WINDOW_MODE_MESA 0x1 + GLX_3DFX_FULLSCREEN_MODE_MESA 0x2 + +Additions to Chapter 3 of the GLX 1.3 Specification (Functions and Errors) + + The Mesa Glide device driver allows either rendering in full-screen + mode or rendering into an X window. An application can switch between + full-screen and window rendering with the command: + + GLboolean glXSet3DfxModeMESA( GLint mode ); + + may either be GLX_3DFX_WINDOW_MODE_MESA to indicate window + rendering or GLX_3DFX_FULLSCREEN_MODE_MESA to indicate full-screen mode. + + GL_TRUE is returned if is valid and the operation completed + normally. GL_FALSE is returned if is invalid or if the Glide + driver is not being used. + + Note that only one drawable and context can be created at any given + time with the Mesa Glide driver. + +GLX Protocol + + None since this is a client-side extension. + +Errors + + None. + +New State + + None. + +Revision History + + 8 June 2000 - initial specification diff --git a/docs/MESA_shader_debug.spec b/docs/MESA_shader_debug.spec new file mode 100644 index 0000000..fab92ab --- /dev/null +++ b/docs/MESA_shader_debug.spec @@ -0,0 +1,264 @@ +Name + + MESA_shader_debug + +Name Strings + + GL_MESA_shader_debug + +Contact + + Brian Paul (brian.paul 'at' tungstengraphics.com) + Michal Krol (mjkrol 'at' gmail.com) + +Status + + Obsolete. + +Version + + Last Modified Date: July 30, 2006 + Author Revision: 0.2 + +Number + + TBD + +Dependencies + + OpenGL 1.0 is required. + + The ARB_shader_objects extension is required. + + The ARB_shading_language_100 extension is required. + + The extension is written against the OpenGL 1.5 specification. + + The extension is written against the OpenGL Shading Language 1.10 + Specification. + +Overview + + This extension introduces a debug object that can be attached to + a program object to enable debugging. Vertex and/or fragment shader, + during execution, issue diagnostic function calls that are logged + to the debug object's log. A separate debug log for each shader type + is maintained. A debug object can be attached, detached and queried + at any time outside the Begin/End pair. Multiple debug objects can + be attached to a single program object. + +IP Status + + None + +Issues + + None + +New Procedures and Functions + + handleARB CreateDebugObjectMESA(void) + void ClearDebugLogMESA(handleARB obj, enum logType, enum shaderType) + void GetDebugLogMESA(handleARB obj, enum logType, enum shaderType, + sizei maxLength, sizei *length, + charARB *debugLog) + sizei GetDebugLogLengthMESA(handleARB obj, enum logType, + enum shaderType) + +New Types + + None + +New Tokens + + Returned by the parameter of GetObjectParameter{fi}vARB: + + DEBUG_OBJECT_MESA 0x8759 + + Accepted by the argument of ClearDebugLogMESA, + GetDebugLogLengthMESA and GetDebugLogMESA: + + DEBUG_PRINT_MESA 0x875A + DEBUG_ASSERT_MESA 0x875B + +Additions to Chapter 2 of the OpenGL 1.5 Specification +(OpenGL Operation) + + None + +Additions to Chapter 3 of the OpenGL 1.5 Specification (Rasterization) + + None + +Additions to Chapter 4 of the OpenGL 1.5 Specification (Per-Fragment +Operations and the Frame Buffer) + + None + +Additions to Chapter 5 of the OpenGL 1.5 Specification +(Special Functions) + + None + +Additions to Chapter 6 of the OpenGL 1.5 Specification (State and State +Requests) + + None + +Additions to Appendix A of the OpenGL 1.5 Specification (Invariance) + + None + +Additions to Chapter 1 of the OpenGL Shading Language 1.10 Specification +(Introduction) + + None + +Additions to Chapter 2 of the OpenGL Shading Language 1.10 Specification +(Overview of OpenGL Shading) + + None + +Additions to Chapter 3 of the OpenGL Shading Language 1.10 Specification +(Basics) + + None + +Additions to Chapter 4 of the OpenGL Shading Language 1.10 Specification +(Variables and Types) + + None + +Additions to Chapter 5 of the OpenGL Shading Language 1.10 Specification +(Operators and Expressions) + + None + +Additions to Chapter 6 of the OpenGL Shading Language 1.10 Specification +(Statements and Structure) + + None + +Additions to Chapter 7 of the OpenGL Shading Language 1.10 Specification +(Built-in Variables) + + None + +Additions to Chapter 8 of the OpenGL Shading Language 1.10 Specification +(Built-in Functions) + + Add a new section 8.10 "Debug Functions": + + Debug functions are available to both fragment and vertex shaders. + They are used to track the execution of a shader by logging + passed-in arguments to the debug object's log. Those values can be + retrieved by the application for inspection after shader execution + is complete. + + The text, if any, produced by any of these functions is appended + to each debug object that is attached to the program object. + There are different debug log types + + Add a new section 8.10.1 "Print Function": + + The following printMESA prototypes are available. + + void printMESA(const float value) + void printMESA(const int value) + void printMESA(const bool value) + void printMESA(const vec2 value) + void printMESA(const vec3 value) + void printMESA(const vec4 value) + void printMESA(const ivec2 value) + void printMESA(const ivec3 value) + void printMESA(const ivec4 value) + void printMESA(const bvec2 value) + void printMESA(const bvec3 value) + void printMESA(const bvec4 value) + void printMESA(const mat2 value) + void printMESA(const mat3 value) + void printMESA(const mat4 value) + void printMESA(const sampler1D value) + void printMESA(const sampler2D value) + void printMESA(const sampler3D value) + void printMESA(const samplerCube value) + void printMESA(const sampler1DShadow value) + void printMESA(const sampler2DShadow value) + + The printMESA function writes the argument to the "debug + print log" (XXX DEBUG_PRINT_MESA?). Each component is written in + text format (XXX format!) and is delimited by a white space (XXX 1 + or more?). + + Add a new section 8.10.2 "Assert Function": + + The following assertMESA prototypes are available. + + void assertMESA(const bool condition) + void assertMESA(const bool condition, const int cookie) + void assertMESA(const bool condition, const int cookie, + const int file, const int line) + + The assertMESA function checks if the argument is + true or false. If it is true, nothing happens. If it is false, + a diagnostic message is written to the "debug assert log". + The message contains the argument , , and + implementation dependent double-quoted string, each of this + delimited by a white space. If the argument is not present, + it is meant as if it was of value 0. If the arguments and + are not present, they are meant as if they were of values + __FILE__ and __LINE__, respectively. The following three calls + produce the same output, assuming they were issued from the same + file and line. + + assertMESA (false); + assertMESA (false, 0); + assertMESA (false, 0, __FILE__, __LINE__); + + The diagnostic message examples follow. + + 1 89 0 "" + 1 45 333 "all (lessThanEqual (fragColor, vec4 (1.0)))" + 1 66 1 "assertion failed in file 1, line 66, cookie 1" + +Additions to Chapter 9 of the OpenGL Shading Language 1.10 Specification +(Shading Language Grammar) + + None + +Additions to Chapter 10 of the OpenGL Shading Language 1.10 +Specification (Issues) + + None + +Additions to the AGL/EGL/GLX/WGL Specifications + + None + +GLX Protocol + + None + +Errors + + TBD + +New State + + TBD + +New Implementation Dependent State + + TBD + +Sample Code + + TBD + +Revision History + + 29 May 2006 + Initial draft. (Michal Krol) + 30 July 2006 + Add Overview, New Procedures and Functions, New Tokens sections. + Add sections 8.10.1, 8.10.2 to GLSL spec. diff --git a/docs/MESA_swap_control.spec b/docs/MESA_swap_control.spec new file mode 100644 index 0000000..856978b --- /dev/null +++ b/docs/MESA_swap_control.spec @@ -0,0 +1,129 @@ +Name + + MESA_swap_control + +Name Strings + + GLX_MESA_swap_control + +Contact + + Ian Romanick, IBM, idr at us.ibm.com + +Status + + Deployed in DRI drivers post-XFree86 4.3. + +Version + + Date: 5/1/2003 Revision: 1.1 + +Number + + ??? + +Dependencies + + None + + Based on GLX_SGI_swap_control version 1.9 and WGL_EXT_swap_control + version 1.5. + +Overview + + This extension allows an application to specify a minimum periodicity + of color buffer swaps, measured in video frame periods. + +Issues + + * Should implementations that export GLX_MESA_swap_control also export + GL_EXT_swap_control for compatibility with WGL_EXT_swap_control? + + UNRESOLVED. + +New Procedures and Functions + + int glXSwapIntervalMESA(unsigned int interval) + int glXGetSwapIntervalMESA(void) + +New Tokens + + None + +Additions to Chapter 2 of the 1.4 GL Specification (OpenGL Operation) + + None + +Additions to Chapter 3 of the 1.4 GL Specification (Rasterization) + + None + +Additions to Chapter 4 of the 1.4 GL Specification (Per-Fragment Operations +and the Framebuffer) + + None + +Additions to Chapter 5 of the 1.4 GL Specification (Special Functions) + + None + +Additions to Chapter 6 of the 1.4 GL Specification (State and State Requests) + + None + +Additions to the GLX 1.3 Specification + + [Add the following to Section 3.3.10 of the GLX Specification (Double + Buffering)] + + glXSwapIntervalMESA specifies the minimum number of video frame periods + per buffer swap. (e.g. a value of two means that the color buffers + will be swapped at most every other video frame.) A return value + of zero indicates success; otherwise an error occurred. The interval + takes effect when glXSwapBuffers is first called subsequent to the + glXSwapIntervalMESA call. + + A video frame period is the time required by the monitor to display a + full frame of video data. In the case of an interlaced monitor, + this is typically the time required to display both the even and odd + fields of a frame of video data. + + If is set to a value of 0, buffer swaps are not synchron- + ized to a video frame. The value is silently clamped to + the maximum implementation-dependent value supported before being + stored. + + The swap interval is not part of the render context state. It cannot + be pushed or popped. The current swap interval for the window + associated with the current context can be obtained by calling + glXGetSwapIntervalMESA. The default swap interval is 0. + + On XFree86, setting the environment variable LIBGL_THROTTLE_REFRESH sets + the swap interval to 1. + +Errors + + glXSwapIntervalMESA returns GLX_BAD_CONTEXT if there is no current + GLXContext or if the current context is not a direct rendering context. + +GLX Protocol + + None. This extension only extends to direct rendering contexts. + +New State + + Get Value Get Command Type Initial Value + --------- ----------- ---- ------------- + [swap interval] GetSwapInterval Z+ 0 + +New Implementation Dependent State + + None + + +Revision History + + 1.1, 5/1/03 Added the issues section and contact information. + Changed the default swap interval to 0. + 1.0, 3/17/03 Initial version based on GLX_SGI_swap_control and + WGL_EXT_swap_control. diff --git a/docs/MESA_swap_frame_usage.spec b/docs/MESA_swap_frame_usage.spec new file mode 100644 index 0000000..5023ead --- /dev/null +++ b/docs/MESA_swap_frame_usage.spec @@ -0,0 +1,201 @@ +Name + + MESA_swap_frame_usage + +Name Strings + + GLX_MESA_swap_frame_usage + +Contact + + Ian Romanick, IBM, idr at us.ibm.com + +Status + + Deployed in DRI drivers post-XFree86 4.3. + +Version + + Date: 5/1/2003 Revision: 1.1 + +Number + + ??? + +Dependencies + + GLX_SGI_swap_control affects the definition of this extension. + GLX_MESA_swap_control affects the definition of this extension. + GLX_OML_sync_control affects the definition of this extension. + + Based on WGL_I3D_swap_frame_usage version 1.3. + +Overview + + This extension allows an application to determine what portion of the + swap period has elapsed since the last swap operation completed. The + "usage" value is a floating point value on the range [0,max] which is + calculated as follows: + + td + percent = ---- + tf + + where td is the time measured from the last completed buffer swap (or + call to enable the statistic) to when the next buffer swap completes, tf + is the entire time for a frame which may be multiple screen refreshes + depending on the swap interval as set by the GLX_SGI_swap_control or + GLX_OML_sync_control extensions. + + The value, percent, indicates the amount of time spent between the + completion of the two swaps. If the value is in the range [0,1], the + buffer swap occurred within the time period required to maintain a + constant frame rate. If the value is in the range (1,max], a constant + frame rate was not achieved. The value indicates the number of frames + required to draw. + + This definition of "percent" differs slightly from + WGL_I3D_swap_frame_usage. In WGL_I3D_swap_frame_usage, the measurement + is taken from the completion of one swap to the issuance of the next. + This representation may not be as useful as measuring between + completions, as a significant amount of time may pass between the + issuance of a swap and the swap actually occurring. + + There is also a mechanism to determine whether a frame swap was + missed. + +New Procedures and Functions + + int glXGetFrameUsageMESA(Display *dpy, + GLXDrawable drawable, + float *usage) + + int glXBeginFrameTrackingMESA(Display *dpy, + GLXDrawable drawable) + + int glXEndFrameTrackingMESA(Display *dpy, + GLXDrawable drawable) + + int glXQueryFrameTrackingMESA(Display *dpy, + GLXDrawable drawable, + int64_t *swapCount, + int64_t *missedFrames, + float *lastMissedUsage) + +New Tokens + + None + +Additions to Chapter 2 of the 1.4 GL Specification (OpenGL Operation) + + None + +Additions to Chapter 3 of the 1.4 GL Specification (Rasterization) + + None + +Additions to Chapter 4 of the 1.4 GL Specification (Per-Fragment Operations +and the Framebuffer) + + None + +Additions to Chapter 5 of the 1.4 GL Specification (Special Functions) + + None + +Additions to Chapter 6 of the 1.4 GL Specification (State and State Requests) + + None + +Additions to the GLX 1.3 Specification + + The frame usage is measured as the percentage of the swap period elapsed + between two buffer-swap operations being committed. In unextended GLX the + swap period is the vertical refresh time. If SGI_swap_control or + MESA_swap_control are supported, the swap period is the vertical refresh + time multiplied by the swap interval (or one if the swap interval is set + to zero). + + If OML_sync_control is supported, the swap period is the vertical + refresh time multiplied by the divisor parameter to + glXSwapBuffersMscOML. The frame usage in this case is less than 1.0 if + the swap is committed before target_msc, and is greater than or equal to + 1.0 otherwise. The actual usage value is based on the divisor and is + never less than 0.0. + + int glXBeginFrameTrackingMESA(Display *dpy, + GLXDrawable drawable, + float *usage) + + glXGetFrameUsageMESA returns a floating-point value in + that represents the current swap usage, as defined above. + + Missed frame swaps can be tracked by calling the following function: + + int glXBeginFrameTrackingMESA(Display *dpy, + GLXDrawable drawable) + + glXBeginFrameTrackingMESA resets a "missed frame" count and + synchronizes with the next frame vertical sync before it returns. + If a swap is missed based in the rate control specified by the + set by glXSwapIntervalSGI or the default swap of once + per frame, the missed frame count is incremented. + + The current missed frame count and total number of swaps since + the last call to glXBeginFrameTrackingMESA can be obtained by + calling the following function: + + int glXQueryFrameTrackingMESA(Display *dpy, + GLXDrawable drawable, + int64_t *swapCount, + int64_t *missedFrames, + float *lastMissedUsage) + + The location pointed to by will be updated with the + number of swaps that have been committed. This value may not match the + number of swaps that have been requested since swaps may be + queued by the implementation. This function can be called at any + time and does not synchronize to vertical blank. + + The location pointed to by will contain the number + swaps that missed the specified frame. The frame usage for the + last missed frame is returned in the location pointed to by + . + + Frame tracking is disabled by calling the function + + int glXEndFrameTrackingMESA(Display *dpy, + GLXDrawable drawable) + + This function will not return until all swaps have occurred. The + application can call glXQueryFrameTrackingMESA for a final swap and + missed frame count. + + If these functions are successful, zero is returned. If the context + associated with dpy and drawable is not a direct context, + GLX_BAD_CONTEXT is returned. + +Errors + + If the function succeeds, zero is returned. If the function + fails, one of the following error codes is returned: + + GLX_BAD_CONTEXT The current rendering context is not a direct + context. + +GLX Protocol + + None. This extension only extends to direct rendering contexts. + +New State + + None + +New Implementation Dependent State + + None + +Revision History + + 1.1, 5/1/03 Added contact information. + 1.0, 3/17/03 Initial version based on WGL_I3D_swap_frame_usage. diff --git a/docs/MESA_texture_array.spec b/docs/MESA_texture_array.spec new file mode 100644 index 0000000..9dee65b --- /dev/null +++ b/docs/MESA_texture_array.spec @@ -0,0 +1,804 @@ +Name + + MESA_texture_array + +Name Strings + + GL_MESA_texture_array + +Contact + + Ian Romanick, IBM (idr 'at' us.ibm.com) + +IP Status + + No known IP issues. + +Status + + Shipping in Mesa 7.1 + +Version + + +Number + + TBD + +Dependencies + + OpenGL 1.2 or GL_EXT_texture3D is required. + + Support for ARB_fragment_program is assumed, but not required. + + Support for ARB_fragment_program_shadow is assumed, but not required. + + Support for EXT_framebuffer_object is assumed, but not required. + + Written based on the wording of the OpenGL 2.0 specification and + ARB_fragment_program_shadow but not dependent on them. + +Overview + + There are a number of circumstances where an application may wish to + blend two textures out of a larger set of textures. Moreover, in some + cases the selected textures may vary on a per-fragment basis within + a polygon. Several examples include: + + 1. High dynamic range textures. The application stores several + different "exposures" of an image as different textures. On a + per-fragment basis, the application selects which exposures are + used. + + 2. A terrain engine where the altitude of a point determines the + texture applied to it. If the transition is from beach sand to + grass to rocks to snow, the application will store each texture + in a different texture map, and dynamically select which two + textures to blend at run-time. + + 3. Storing short video clips in textures. Each depth slice is a + single frame of video. + + Several solutions to this problem have been proposed, but they either + involve using a separate texture unit for each texture map or using 3D + textures without mipmaps. Both of these options have major drawbacks. + + This extension provides a third alternative that eliminates the major + drawbacks of both previous methods. A new texture target, + TEXTURE_2D_ARRAY, is added that functions identically to TEXTURE_3D in + all aspects except the sizes of the non-base level images. In + traditional 3D texturing, the size of the N+1 LOD is half the size + of the N LOD in all three dimensions. For the TEXTURE_2D_ARRAY target, + the height and width of the N+1 LOD is halved, but the depth is the + same for all levels of detail. The texture then becomes an array of + 2D textures. The per-fragment texel is selected by the R texture + coordinate. + + References: + + http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=3;t=011557 + http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=3;t=000516 + http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=3;t=011903 + http://www.delphi3d.net/articles/viewarticle.php?article=terraintex.htm + +New Procedures and Functions + + All functions come directly from EXT_texture_array. + + void FramebufferTextureLayerEXT(enum target, enum attachment, + uint texture, int level, int layer); + +New Tokens + + All token names and values come directly from EXT_texture_array. + + Accepted by the parameter of Enable, Disable, and IsEnabled, by + the parameter of GetBooleanv, GetIntegerv, GetFloatv, and + GetDoublev, and by the parameter of TexImage3D, GetTexImage, + GetTexLevelParameteriv, GetTexLevelParameterfv, GetTexParameteriv, and + GetTexParameterfv: + + TEXTURE_1D_ARRAY_EXT 0x8C18 + TEXTURE_2D_ARRAY_EXT 0x8C1A + + Accepted by the parameter of TexImage2D, TexSubImage2D, + CopyTexImage2D, CopyTexSubImage2D, CompressedTexImage2D, + CompressedTexSubImage2D, GetTexLevelParameteriv, and + GetTexLevelParameterfv: + + TEXTURE_1D_ARRAY_EXT + PROXY_TEXTURE_1D_ARRAY_EXT 0x8C19 + + Accepted by the parameter of TexImage3D, TexSubImage3D, + CopyTexSubImage3D, CompressedTexImage3D, CompressedTexSubImage3D, + GetTexLevelParameteriv, and GetTexLevelParameterfv: + + TEXTURE_2D_ARRAY_EXT + PROXY_TEXTURE_2D_ARRAY_EXT 0x8C1B + + Accepted by the parameter of GetBooleanv, GetIntegerv, + GetFloatv, and GetDoublev + + TEXTURE_BINDING_1D_ARRAY_EXT 0x8C1C + TEXTURE_BINDING_2D_ARRAY_EXT 0x8C1D + MAX_ARRAY_TEXTURE_LAYERS_EXT 0x88FF + + Accepted by the parameter of TexParameterf, TexParameteri, + TexParameterfv, and TexParameteriv when the parameter is + TEXTURE_COMPARE_MODE_ARB: + + COMPARE_REF_DEPTH_TO_TEXTURE_EXT 0x884E + + (Note: COMPARE_REF_DEPTH_TO_TEXTURE_EXT is simply an alias for the + existing COMPARE_R_TO_TEXTURE token in OpenGL 2.0; the alternate name + reflects the fact that the R coordinate is not always used.) + + Accepted by the parameter of TexImage3D and + CompressedTexImage3D, and by the parameter of + CompressedTexSubImage3D: + + COMPRESSED_RGB_S3TC_DXT1_EXT + COMPRESSED_RGBA_S3TC_DXT1_EXT + COMPRESSED_RGBA_S3TC_DXT3_EXT + COMPRESSED_RGBA_S3TC_DXT5_EXT + + Accepted by the parameter of + GetFramebufferAttachmentParameterivEXT: + + FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4 + + (Note: FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER is simply an alias for the + FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT token provided in + EXT_framebuffer_object. This extension generalizes the notion of + "" to include layers of an array texture.) + +Additions to Chapter 2 of the OpenGL 2.0 Specification (OpenGL Operation) + + None + +Additions to Chapter 3 of the OpenGL 2.0 Specification (Rasterization) + + -- Section 3.8.1 "Texture Image Specification" + + Change the first paragraph (page 150) to say (spec changes identical to + EXT_texture_array): + + "The command + + void TexImage3D(enum target, int level, int internalformat, + sizei width, sizei height, sizei depth, int border, + enum format, enum type, void *data); + + is used to specify a three-dimensional texture image. target must be one + one of TEXTURE_3D for a three-dimensional texture or + TEXTURE_2D_ARRAY_EXT for an two-dimensional array texture. + Additionally, target may be either PROXY_TEXTURE_3D for a + three-dimensional proxy texture, or PROXY_TEXTURE_2D_ARRAY_EXT for a + two-dimensional proxy array texture." + + Change the fourth paragraph on page 151 to say (spec changes identical + to EXT_texture_array): + + "Textures with a base internal format of DEPTH_COMPONENT are supported + by texture image specification commands only if target is TEXTURE_1D, + TEXTURE_2D, TEXTURE_1D_ARRAY_EXT, TEXTURE_2D_ARRAY_EXT, + PROXY_TEXTURE_1D, PROXY_TEXTURE_2D, PROXY_TEXTURE_1D_ARRAY_EXT, or + PROXY_TEXTURE_2D_ARRAY_EXT. Using this format in conjunction with any + other target will result in an INVALID_OPERATION error." + + + Change the fourth paragraph on page 156 to say (spec changes identical + to EXT_texture_array): + + "The command + + void TexImage2D(enum target, int level, + int internalformat, sizei width, sizei height, + int border, enum format, enum type, void *data); + + is used to specify a two-dimensional texture image. target must be one + of TEXTURE_2D for a two-dimensional texture, TEXTURE_1D_ARRAY_EXT for a + one-dimensional array texture, or one of TEXTURE_CUBE_MAP_POSITIVE_X, + TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP_POSITIVE_Y, + TEXTURE_CUBE_MAP_NEGATIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z, or + TEXTURE_CUBE_MAP_NEGATIVE_Z for a cube map texture. Additionally, + target may be either PROXY_TEXTURE_2D for a two-dimensional proxy + texture, PROXY_TEXTURE_1D_ARRAY_EXT for a one-dimensional proxy array + texture, or PROXY TEXTURE_CUBE_MAP for a cube map proxy texture in the + special case discussed in section 3.8.11. The other parameters match + the corresponding parameters of TexImage3D. + + For the purposes of decoding the texture image, TexImage2D is + equivalent to calling TexImage3D with corresponding arguments and depth + of 1, except that + + * The border depth, d_b, is zero, and the depth of the image is + always 1 regardless of the value of border. + + * The border height, h_b, is zero if is + TEXTURE_1D_ARRAY_EXT, and otherwise. + + * Convolution will be performed on the image (possibly changing its + width and height) if SEPARABLE 2D or CONVOLUTION 2D is enabled. + + * UNPACK SKIP IMAGES is ignored." + + -- Section 3.8.2 "Alternate Texture Image Specification Commands" + + Change the second paragraph (page 159) (spec changes identical + to EXT_texture_array): + + "The command + + void CopyTexImage2D(enum target, int level, + enum internalformat, int x, int y, sizei width, + sizei height, int border); + + defines a two-dimensional texture image in exactly the manner of + TexImage2D, except that the image data are taken from the framebuffer + rather than from client memory. Currently, target must be one of + TEXTURE_2D, TEXTURE_1D_ARRAY_EXT, TEXTURE_CUBE_MAP_POSITIVE_X, + TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE MAP_POSITIVE_Y, + TEXTURE_CUBE_MAP_NEGATIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z, or + TEXTURE_CUBE_MAP_NEGATIVE_Z. + + + Change the last paragraph on page 160 to say (spec changes identical + to EXT_texture_array): + + "Currently the target arguments of TexSubImage1D and CopyTexSubImage1D + must be TEXTURE_1D, the target arguments of TexSubImage2D and + CopyTexSubImage2D must be one of TEXTURE_2D, TEXTURE_1D_ARRAY_EXT, + TEXTURE_CUBE_MAP_POSITIVE_X, TEXTURE_CUBE_MAP_NEGATIVE_X, + TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP_NEGATIVE_Y, + TEXTURE_CUBE_MAP_POSITIVE_Z, or TEXTURE_CUBE_MAP_NEGATIVE_Z, and the + target arguments of TexSubImage3D and CopyTexSubImage3D must be + TEXTURE_3D or TEXTURE_2D_ARRAY_EXT. ..." + + + -- Section 3.8.4 "Texture Parameters" + + Change the first paragraph (page 166) to say: + + "Various parameters control how the texel array is treated when + specified or changed, and when applied to a fragment. Each parameter is + set by calling + + void TexParameter{if}(enum target, enum pname, T param); + void TexParameter{if}v(enum target, enum pname, T params); + + target is the target, either TEXTURE_1D, TEXTURE_2D, TEXTURE_3D, + TEXTURE_CUBE_MAP, TEXTURE_1D_ARRAY_EXT, or TEXTURE_2D_ARRAY_EXT." + + + -- Section 3.8.8 "Texture Minification" in the section "Scale Factor and Level of Detail" + + Change the first paragraph (page 172) to say: + + "Let s(x,y) be the function that associates an s texture coordinate + with each set of window coordinates (x,y) that lie within a primitive; + define t(x,y) and r(x,y) analogously. Let u(x,y) = w_t * s(x,y), + v(x,y) = h_t * t(x,y), and w(x,y) = d_t * r(x,y), where w_t, h_t, + and d_t are as defined by equations 3.15, 3.16, and 3.17 with + w_s, h_s, and d_s equal to the width, height, and depth of the + image array whose level is level_base. For a one-dimensional + texture or a one-dimensional array texture, define v(x,y) = 0 and + w(x,y) = 0; for a two-dimensional texture or a two-dimensional array + texture, define w(x,y) = 0..." + + -- Section 3.8.8 "Texture Minification" in the section "Mipmapping" + + Change the third paragraph (page 174) to say: + + "For a two-dimensional texture, two-dimensional array texture, or + cube map texture," + + Change the fourth paragraph (page 174) to say: + + "And for a one-dimensional texture or a one-dimensional array texture," + + After the first paragraph (page 175) add: + + "For one-dimensional array textures, h_b and d_b are treated as 1, + regardless of the actual values, when performing mipmap calculations. + For two-dimensional array textures, d_b is always treated as one, + regardless of the actual value, when performing mipmap calculations." + + -- Section 3.8.8 "Automatic Mipmap Generation" in the section "Mipmapping" + + Change the third paragraph (page 176) to say (spec changes identical + to EXT_texture_array): + + "The contents of the derived arrays are computed by repeated, filtered + reduction of the level_base array. For one- and two-dimensional array + textures, each layer is filtered independently. ..." + + -- Section 3.8.8 "Manual Mipmap Generation" in the section "Mipmapping" + + Change first paragraph to say (spec changes identical to + EXT_texture_array): + + "Mipmaps can be generated manually with the command + + void GenerateMipmapEXT(enum target); + + where is one of TEXTURE_1D, TEXTURE_2D, TEXTURE_CUBE_MAP, + TEXTURE_3D, TEXTURE_1D_ARRAY, or TEXTURE_2D_ARRAY. Mipmap generation + affects the texture image attached to . ..." + + -- Section 3.8.10 "Texture Completeness" + + Change the second paragaph (page 177) to say (spec changes identical + to EXT_texture_array): + + "For one-, two-, or three-dimensional textures and one- or + two-dimensional array textures, a texture is complete if the following + conditions all hold true:" + + -- Section 3.8.11 "Texture State and Proxy State" + + Change the second and third paragraphs (page 179) to say (spec changes + identical to EXT_texture_array): + + "In addition to image arrays for one-, two-, and three-dimensional + textures, one- and two-dimensional array textures, and the six image + arrays for the cube map texture, partially instantiated image arrays + are maintained for one-, two-, and three-dimensional textures and one- + and two-dimensional array textures. Additionally, a single proxy image + array is maintained for the cube map texture. Each proxy image array + includes width, height, depth, border width, and internal format state + values, as well as state for the red, green, blue, alpha, luminance, + and intensity component resolutions. Proxy image arrays do not include + image data, nor do they include texture properties. When TexImage3D is + executed with target specified as PROXY_TEXTURE_3D, the + three-dimensional proxy state values of the specified level-of-detail + are recomputed and updated. If the image array would not be supported + by TexImage3D called with target set to TEXTURE 3D, no error is + generated, but the proxy width, height, depth, border width, and + component resolutions are set to zero. If the image array would be + supported by such a call to TexImage3D, the proxy state values are set + exactly as though the actual image array were being specified. No pixel + data are transferred or processed in either case. + + Proxy arrays for one- and two-dimensional textures and one- and + two-dimensional array textures are operated on in the same way when + TexImage1D is executed with target specified as PROXY_TEXTURE_1D, + TexImage2D is executed with target specified as PROXY_TEXTURE_2D or + PROXY_TEXTURE_1D_ARRAY_EXT, or TexImage3D is executed with target + specified as PROXY_TETXURE_2D_ARRAY_EXT." + + -- Section 3.8.12 "Texture Objects" + + Change section (page 180) to say (spec changes identical to + EXT_texture_array): + + "In addition to the default textures TEXTURE_1D, TEXTURE_2D, + TEXTURE_3D, TEXTURE_CUBE_MAP, TEXTURE_1D_ARRAY_EXT, and TEXTURE_2D_EXT, + named one-, two-, and three-dimensional, cube map, and one- and + two-dimensional array texture objects can be created and operated upon. + The name space for texture objects is the unsigned integers, with zero + reserved by the GL. + + A texture object is created by binding an unused name to TEXTURE_1D, + TEXTURE_2D, TEXTURE_3D, TEXTURE_CUBE_MAP, TEXTURE_1D_ARRAY_EXT, or + TEXTURE_2D_ARRAY_EXT. The binding is effected by calling + + void BindTexture(enum target, uint texture); + + with set to the desired texture target and set to + the unused name. The resulting texture object is a new state vector, + comprising all the state values listed in section 3.8.11, set to the + same initial values. If the new texture object is bound to TEXTURE_1D, + TEXTURE_2D, TEXTURE_3D, TEXTURE_CUBE_MAP, TEXTURE_1D_ARRAY_EXT, or + TEXTURE_2D_ARRAY_EXT, it is and remains a one-, two-, + three-dimensional, cube map, one- or two-dimensional array texture + respectively until it is deleted. + + BindTexture may also be used to bind an existing texture object to + either TEXTURE_1D, TEXTURE_2D, TEXTURE_3D, TEXTURE_CUBE_MAP, + TEXTURE_1D_ARRAY_EXT, or TEXTURE_2D_ARRAY_EXT. The error + INVALID_OPERATION is generated if an attempt is made to bind a texture + object of different dimensionality than the specified target. If the + bind is successful no change is made to the state of the bound texture + object, and any previous binding to target is broken. + + While a texture object is bound, GL operations on the target to which + it is bound affect the bound object, and queries of the target to which + it is bound return state from the bound object. If texture mapping of + the dimensionality of the target to which a texture object is bound is + enabled, the state of the bound texture object directs the texturing + operation. + + In the initial state, TEXTURE_1D, TEXTURE_2D, TEXTURE_3D, + TEXTURE_CUBE_MAP, TEXTURE_1D_ARRAY_EXT, and TEXTURE_2D_ARRAY_EXT have + one-, two-, three-dimensional, cube map, and one- and two-dimensional + array texture state vectors respectively associated with them. In order + that access to these initial textures not be lost, they are treated as + texture objects all of whose names are 0. The initial one-, two-, + three-dimensional, cube map, one- and two-dimensional array textures + are therefore operated upon, queried, and applied as TEXTURE_1D, + TEXTURE_2D, TEXTURE_3D, TEXTURE_CUBE_MAP, TEXTURE_1D_ARRAY_EXT, and + TEXTURE_2D_ARRAY_EXT respectively while 0 is bound to the corresponding + targets. + + Change second paragraph on page 181 to say (spec changes identical to + EXT_texture_array): + + "... If a texture that is currently bound to one of the targets + TEXTURE_1D, TEXTURE_2D, TEXTURE_3D, TEXTURE_CUBE_MAP, + TEXTURE_1D_ARRAY_EXT, or TEXTURE_2D_ARRAY_EXT is deleted, it is as + though BindTexture had been executed with the same target and texture + zero. ..." + + Change second paragraph on page 182 to say (spec changes identical to + EXT_texture_array): + + "The texture object name space, including the initial one-, two-, and + three dimensional, cube map, and one- and two-dimensional array texture + objects, is shared among all texture units. ..." + + + -- Section 3.8.14 "Depth Texture Comparison Modes" in "Texture Comparison Modes" + + Change second through fourth paragraphs (page 188) to say: + + "Let D_t be the depth texture value, in the range [0, 1]. For + texture lookups from one- and two-dimesional, rectangle, and + one-dimensional array targets, let R be the interpolated + texture coordinate, clamped to the range [0, 1]. For texture lookups + from two-dimesional array texture targets, let R be the interpolated + texture coordinate, clamped to the range [0, 1]. Then the + effective texture value L_t, I_t, or A_t is computed as follows: + + If the value of TEXTURE_COMPARE_MODE is NONE, then + + r = Dt + + If the value of TEXTURE_COMPARE_MODE is + COMPARE_REF_DEPTH_TO_TEXTURE_EXT), then r depends on the texture + comparison function as shown in table 3.27." + + -- Section 3.8.15 "Texture Application" + + Change the first paragraph (page 189) to say: + + "Texturing is enabled or disabled using the generic Enable and Disable + commands, respectively, with the symbolic constants TEXTURE_1D, + TEXTURE_2D, TEXTURE_3D, TEXTURE_CUBE_MAP, TEXTURE_1D_ARRAY_EXT, or + TEXTURE_2D_ARRAY_EXT to enable one-, two-, three-dimensional, cube + map, one-dimensional array, or two-dimensional array texture, + respectively. If both two- and one-dimensional textures are enabled, + the two-dimensional texture is used. If the three-dimensional and + either of the two- or one-dimensional textures is enabled, the + three-dimensional texture is used. If the cube map texture and any of + the three-, two-, or one-dimensional textures is enabled, then cube map + texturing is used. If one-dimensional array texture is enabled and any + of cube map, three-, two-, or one-dimensional textures is enabled, + one-dimensional array texturing is used. If two-dimensional array + texture is enabled and any of cube map, three-, two-, one-dimensional + textures or one-dimensional array texture is enabled, two-dimensional + array texturing is used..." + + -- Section 3.11.2 of ARB_fragment_program (Fragment Program Grammar and Restrictions): + + (mostly add to existing grammar rules) + + ::= "MESA_texture_array" + + ::= "1D" + | "2D" + | "3D" + | "CUBE" + | "RECT" + | (if program option is present) + | (if program option is present) + + ::= "ARRAY1D" + | "ARRAY2D" + + ::= "SHADOW1D" + | "SHADOW2D" + | "SHADOWRECT" + | (if program option is present) + + ::= "SHADOWARRAY1D" + | "SHADOWARRAY2D" + + + -- Add Section 3.11.4.5.4 "Texture Stack Option" + + "If a fragment program specifies the "MESA_texture_array" program + option, the rule is modified to add the texture targets + ARRAY1D and ARRAY2D (See Section 3.11.2)." + + -- Section 3.11.6 "Fragment Program Texture Instruction Set" + + (replace 1st and 2nd paragraphs with the following paragraphs) + + "The first three texture instructions described below specify the + mapping of 4-tuple input vectors to 4-tuple output vectors. + The sampling of the texture works as described in section 3.8, + except that texture environments and texture functions are not + applicable, and the texture enables hierarchy is replaced by explicit + references to the desired texture target (i.e., 1D, 2D, 3D, cube map, + rectangle, ARRAY1D, ARRAY2D). These texture instructions specify + how the 4-tuple is mapped into the coordinates used for sampling. The + following function is used to describe the texture sampling in the + descriptions below: + + vec4 TextureSample(vec4 coord, float lodBias, int texImageUnit, + enum texTarget); + + Note that not all four components of the texture coordinates + are used by all texture targets. Component usage for each + is defined in table X. + + coordinates used + texTarget Texture Type s t r layer shadow + ---------------- --------------------- ----- ----- ------ + 1D TEXTURE_1D x - - - - + 2D TEXTURE_2D x y - - - + 3D TEXTURE_3D x y z - - + CUBE TEXTURE_CUBE_MAP x y z - - + RECT TEXTURE_RECTANGLE_ARB x y - - - + ARRAY1D TEXTURE_1D_ARRAY_EXT x - - y - + ARRAY2D TEXTURE_2D_ARRAY_EXT x y - z - + SHADOW1D TEXTURE_1D x - - - z + SHADOW2D TEXTURE_2D x y - - z + SHADOWRECT TEXTURE_RECTANGLE_ARB x y - - z + SHADOWARRAY1D TEXTURE_1D_ARRAY_EXT x - - y z + SHADOWARRAY2D TEXTURE_2D_ARRAY_EXT x y - z w + + Table X: Texture types accessed for each of the , and + coordinate mappings. The "coordinates used" column indicate the + input values used for each coordinate of the texture lookup, the + layer selector for array textures, and the reference value for + texture comparisons." + + -- Section 3.11.6.2 "TXP: Project coordinate and map to color" + + Add to the end of the section: + + "A program will fail to load if the TXP instruction is used in + conjunction with the SHADOWARRAY2D target." + +Additions to Chapter 4 of the OpenGL 2.0 Specification (Per-Fragment Operations) + + -- Section 4.4.2.3 "Attaching Texture Images to a Framebuffer" + + Add to the end of the section (spec changes identical to + EXT_texture_array): + + "The command + + void FramebufferTextureLayerEXT(enum target, enum attachment, + uint texture, int level, int layer); + + operates identically to FramebufferTexture3DEXT, except that it + attaches a single layer of a three-dimensional texture or a one- or + two-dimensional array texture. is an integer indicating the + layer number, and is treated identically to the parameter in + FramebufferTexture3DEXT. The error INVALID_VALUE is generated if + is negative. The error INVALID_OPERATION is generated if + is non-zero and is not the name of a three dimensional + texture or one- or two-dimensional array texture. Unlike + FramebufferTexture3D, no parameter is accepted. + + If is non-zero and the command does not result in an error, + the framebuffer attachment state corresponding to is + updated as in the other FramebufferTexture commands, except that + FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT is set to ." + + -- Section 4.4.4.1 "Framebuffer Attachment Completeness" + + Add to the end of the list of completeness rules (spec changes + identical to EXT_texture_array): + + "* If FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT is TEXTURE and + FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT names a one- or + two-dimensional array texture, then + FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT must be smaller than the + number of layers in the texture." + +Additions to Chapter 5 of the OpenGL 2.0 Specification (Special Functions) + + -- Section 5.4 "Display Lists" + + Change the first paragraphi on page 242 to say (spec changes + identical to EXT_texture_array): + + "TexImage3D, TexImage2D, TexImage1D, Histogram, and ColorTable are + executed immediately when called with the corresponding proxy arguments + PROXY_TEXTURE_3D or PROXY_TEXTURE_2D_ARRAY_EXT; PROXY_TEXTURE_2D, + PROXY_TEXTURE_CUBE_MAP, or PROXY_TEXTURE_1D_ARRAY_EXT; + PROXY_TEXTURE_1D; PROXY_HISTOGRAM; and PROXY_COLOR_TABLE, + PROXY_POST_CONVOLUTION_COLOR_TABLE, or + PROXY_POST_COLOR_MATRIX_COLOR_TABLE." + +Additions to Chapter 6 of the OpenGL 2.0 Specification (State and State Requests) + + -- Section 6.1.3 "Enumerated Queries" + + Add after the line beginning "If the value of + FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT is TEXTURE" (spec changes + identical to EXT_texture_array): + + "If is FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT and the + texture object named FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT is a + three-dimensional texture or a one- or two-dimensional array texture, + then will contain the number of texture layer attached to the + attachment point. Otherwise, will contain the value zero." + + -- Section 6.1.4 "Texture Queries" + + Change the first three paragraphs (page 248) to say (spec changes + identical to EXT_texture_array): + + "The command + + void GetTexImage(enum tex, int lod, enum format, + enum type, void *img); + + is used to obtain texture images. It is somewhat different from the + other get commands; tex is a symbolic value indicating which texture + (or texture face in the case of a cube map texture target name) is to + be obtained. TEXTURE_1D, TEXTURE_2D, TEXTURE_3D, TEXTURE_1D_ARRAY_EXT, + and TEXTURE_2D_ARRAY_EXT indicate a one-, two-, or three-dimensional + texture, or one- or two-dimensional array texture, respectively. + TEXTURE_CUBE_MAP_POSITIVE_X, ... + + GetTexImage obtains... from the first image to the last for + three-dimensional textures. One- and two-dimensional array textures + are treated as two- and three-dimensional images, respectively, where + the layers are treated as rows or images. These groups are then... + + For three-dimensional and two-dimensional array textures, pixel storage + operations are applied as if the image were two-dimensional, except + that the additional pixel storage state values PACK_IMAGE_HEIGHT and + PACK_SKIP_IMAGES are applied. ..." + +Additions to Appendix A of the OpenGL 2.0 Specification (Invariance) + + None + +Additions to the AGL/GLX/WGL Specifications + + None + +GLX Protocol + + None + +Dependencies on ARB_fragment_program + + If ARB_fragment_program is not supported, the changes to section 3.11 + should be ignored. + +Dependencies on EXT_framebuffer_object + + If EXT_framebuffer_object is not supported, the changes to section + 3.8.8 ("Manual Mipmap Generation"), 4.4.2.3, and 6.1.3 should be ignored. + +Dependencies on EXT_texture_compression_s3tc and NV_texture_compression_vtc + + (Identical dependency as EXT_texture_array.) + + S3TC texture compression is supported for two-dimensional array textures. + When is TEXTURE_2D_ARRAY_EXT, each layer is stored independently + as a compressed two-dimensional textures. When specifying or querying + compressed images using one of the S3TC formats, the images are provided + and/or returned as a series of two-dimensional textures stored + consecutively in memory, with the layer closest to zero specified first. + For array textures, images are not arranged in 4x4x4 or 4x4x2 blocks as in + the three-dimensional compression format provided in the + EXT_texture_compression_vtc extension. Pixel store parameters, including + those specific to three-dimensional images, are ignored when compressed + image data are provided or returned, as in the + EXT_texture_compression_s3tc extension. + + S3TC compression is not supported for one-dimensional texture targets in + EXT_texture_compression_s3tc, and is not supported for one-dimensional + array textures in this extension. If compressed one-dimensional arrays + are needed, use a two-dimensional texture with a height of one. + + This extension allows the use of the four S3TC internal format types in + TexImage3D, CompressedTexImage3D, and CompressedTexSubImage3D calls. + +Errors + + None + +New State + + (add to table 6.15, p. 276) + + Initial + Get Value Type Get Command Value Description Sec. Attribute + ---------------------------- ----- ----------- ----- -------------------- ------ --------- + TEXTURE_BINDING_1D_ARRAY_EXT 2*xZ+ GetIntegerv 0 texture object bound 3.8.12 texture + to TEXTURE_1D_ARRAY + TEXTURE_BINDING_2D_ARRAY_EXT 2*xZ+ GetIntegerv 0 texture object bound 3.8.12 texture + to TEXTURE_2D_ARRAY + + +New Implementation Dependent State + + (add to Table 6.32, p. 293) + + Minimum + Get Value Type Get Command Value Description Sec. Attribute + ---------------------------- ---- ----------- ------- ------------------ ----- --------- + MAX_TEXTURE_ARRAY_LAYERS_EXT Z+ GetIntegerv 64 maximum number of 3.8.1 - + layers for texture + arrays + +Issues + + (1) Is "texture stack" a good name for this functionality? + + NO. The name is changed to "array texture" to match the + nomenclature used by GL_EXT_texture_array. + + (2) Should the R texture coordinate be treated as normalized or + un-normalized? If it were un-normalized, floor(R) could be thought + of as a direct index into the array texture. This may be more + convenient for applications. + + RESOLVED. All texture coordinates are normalized. The issue of + un-normalized texture coordinates has been discussed in the ARB + before and should be left for a layered extension. + + RE-RESOLVED. The R coordinate is un-normalized. Accessing an array + using [0, layers-1] coordinates is much more natural. + + (3) How does LOD selection work for stacked textures? + + RESOLVED. For 2D array textures the R coordinate is ignored, and + the LOD selection equations for 2D textures are used. For 1D + array textures the T coordinate is ignored, and the LOD selection + equations for 1D textures are used. The expected usage is in a + fragment program with an explicit LOD selection. + + (4) What is the maximum size of a 2D array texture? Is it the same + as for a 3D texture, or should a new query be added? How about for 1D + array textures? + + RESOLVED. A new query is added. + + (5) How are array textures exposed in GLSL? + + RESOLVED. Use GL_EXT_texture_array. + + (6) Should a 1D array texture also be exposed? + + RESOLVED. For orthogonality, yes. + + (7) How are stacked textures attached to framebuffer objects? + + RESOLVED. Layers of both one- and two-dimensional array textures + are attached using FreambufferTextureLayerEXT. Once attached, the + array texture layer behaves exactly as either a one- or + two-dimensional texture. + + (8) How is this extension related to GL_EXT_texture_array? + + This extension adapats GL_MESAX_texture_stack to the notation, + indexing, and FBO access of GL_EXT_texture_array. This extension + replaces the GLSL support of GL_EXT_texture_array with + GL_ARB_fragment_program support. + + Assembly program support is also provided by GL_NV_gpu_program4. + GL_NV_gpu_program4 also adds support for other features that are + specific to Nvidia hardware, while this extension adds only support + for array textures. + + Much of text of this extension that has changed since + GL_MESAX_texture_stack comes directly from either + GL_EXT_texture_array or GL_NV_gpu_program4. + +Revision History + + ||2005/11/15||0.1||idr||Initial draft MESAX version.|| + ||2005/12/07||0.2||idr||Added framebuffer object interactions.|| + ||2005/12/12||0.3||idr||Updated fragment program interactions.|| + ||2007/05/16||0.4||idr||Converted to MESA_texture_array. Brought in line with EXT_texture_array and NV_gpu_program4.|| diff --git a/docs/MESA_texture_signed_rgba.spec b/docs/MESA_texture_signed_rgba.spec new file mode 100644 index 0000000..49c8e9e --- /dev/null +++ b/docs/MESA_texture_signed_rgba.spec @@ -0,0 +1,214 @@ +Name + + MESA_texture_signed_rgba + +Name Strings + + GL_MESA_texture_signed_rgba + +Contact + + + +Notice + + + +IP Status + + No known IP issues + +Status + + + +Version + + 0.3, 2009-03-24 + +Number + + Not assigned ? + +Dependencies + + Written based on the wording of the OpenGL 2.0 specification. + + This extension trivially interacts with ARB_texture_float. + This extension shares some language with ARB_texture_compression_rgtc + but does not depend on it. + +Overview + + OpenGL prior to 3.1 does not support any signed texture formats. + ARB_texture_compression_rgtc introduces some compressed red and + red_green signed formats but no uncompressed ones, which might + still be useful. NV_texture_shader adds signed texture formats, + but also a lot of functionality which has been superceded by fragment + shaders. + It is usually possible to get the same functionality + using a unsigned format by doing scale and bias in a shader, but this + is undesirable since modern hardware has direct support for this. + This extension adds a signed 4-channel texture format by backporting + the relevant features from OpenGL 3.1, as a means to support this in + OpenGL implementations only supporting older versions. + +Issues + + 1) What should this extension be called? + + RESOLVED: MESA_texture_signed_rgba seems reasonable. + The rgba part is there because only 4 channel format is supported. + + + 2) Should the full set of signed formats (alpha, luminance, rgb, etc.) + be supported? + + RESOLVED: NO. To keep this extension simple, only add the most + universal format, rgba. alpha/luminance can't be trivially supported + since OpenGL 3.1 does not support them any longer, and there is some + implied dependency on ARB_texture_rg for red/red_green formats so + avoid all this. Likewise, only 8 bits per channel is supported. + + + 3) Should this extension use new enums for the texture formats? + + RESOLVED: NO. Same enums as those used in OpenGL 3.1. + + + 4) How are signed integer values mapped to floating-point values? + + RESOLVED: Same as described in issue 5) of + ARB_texture_compression_rgtc (quote): + A signed 8-bit two's complement value X is computed to + a floating-point value Xf with the formula: + + { X / 127.0, X > -128 + Xf = { + { -1.0, X == -128 + + This conversion means -1, 0, and +1 are all exactly representable, + however -128 and -127 both map to -1.0. Mapping -128 to -1.0 + avoids the numerical awkwardness of have a representable value + slightly more negative than -1.0. + + This conversion is intentionally NOT the "byte" conversion listed + in Table 2.9 for component conversions. That conversion says: + + Xf = (2*X + 1) / 255.0 + + The Table 2.9 conversion is incapable of exactly representing + zero. + + (Difference to ARB_texture_compression_rgtc): + This is the same mapping as OpenGL 3.1 uses. + This is also different to what NV_texture_shader used. + The above mapping should be considered the reference, but there + is some leeway so other mappings are allowed for implementations which + cannot do this. Particulary the mapping given in NV_texture_shader or + the standard OpenGL byte/float mapping is considered acceptable too, as + might be a mapping which represents -1.0 by -128, 0.0 by 0 and 1.0 by + 127 (that is, uses different scale factors for negative and positive + numbers). + Also, it is ok to store incoming GL_BYTE user data as-is, without + converting to GL_FLOAT (using the standard OpenGL float/byte mapping) + and converting back (using the mapping described here). + Other than those subtle issues there are no other non-standard + conversions used, so when using for instance CopyTexImage2D with + a framebuffer clamped to [0,1] all converted numbers will be in the range + [0, 127] (and not scaled and biased). + + + 5) How will signed components resulting from RGBA8_SNORM texture + fetches interact with fragment coloring? + + RESOLVED: Same as described in issue 6) of + ARB_texture_compression_rgtc (quote): + The specification language for this extension is silent + about clamping behavior leaving this to the core specification + and other extensions. The clamping or lack of clamping is left + to the core specification and other extensions. + + For assembly program extensions supporting texture fetches + (ARB_fragment_program, NV_fragment_program, NV_vertex_program3, + etc.) or the OpenGL Shading Language, these signed formats will + appear as expected with unclamped signed components as a result + of a texture fetch instruction. + + If ARB_color_buffer_float is supported, its clamping controls + will apply. + + NV_texture_shader extension, if supported, adds support for + fixed-point textures with signed components and relaxed the + fixed-function texture environment clamping appropriately. If the + NV_texture_shader extension is supported, its specified behavior + for the texture environment applies where intermediate values + are clamped to [-1,1] unless stated otherwise as in the case + of explicitly clamped to [0,1] for GL_COMBINE. or clamping the + linear interpolation weight to [0,1] for GL_DECAL and GL_BLEND. + + Otherwise, the conventional core texture environment clamps + incoming, intermediate, and output color components to [0,1]. + + This implies that the conventional texture environment + functionality of unextended OpenGL 1.5 or OpenGL 2.0 without + using GLSL (and with none of the extensions referred to above) + is unable to make proper use of the signed texture formats added + by this extension because the conventional texture environment + requires texture source colors to be clamped to [0,1]. Texture + filtering of these signed formats would be still signed, but + negative values generated post-filtering would be clamped to + zero by the core texture environment functionality. The + expectation is clearly that this extension would be co-implemented + with one of the previously referred to extensions or used with + GLSL for the new signed formats to be useful. + + + 6) Should the RGBA_SNORM tokens also be accepted by CopyTexImage + functions? + + RESOLVED: YES. + + + 7) What to do with GetTexParameter if ARB_texture_float is supported, + in particular what datatype should this return for TEXTURE_RED_TYPE_ARB, + TEXTURE_GREEN_TYPE_ARB, TEXTURE_BLUE_TYPE_ARB, TEXTURE_ALPHA_TYPE_ARB? + + RESOLVED: ARB_texture_float states type is either NONE, + UNSIGNED_NORMALIZED_ARB, or FLOAT. This extension adds a new enum, + SIGNED_NORMALIZED, which will be returned accordingly. This is the + same behaviour as in OpenGL 3.1. + + +New Tokens + + + Accepted by the parameter of + TexImage1D, TexImage2D, TexImage3D, CopyTexImage1D, and CopyTexImage2D: + + RGBA_SNORM 0x8F93 + RGBA8_SNORM 0x8F97 + + Returned by the parameter of GetTexLevelParameter: + + SIGNED_NORMALIZED 0x8F9C + + +Additions to Chapter 3 of the OpenGL 2.0 Specification (Rasterization): + + -- Section 3.8.1, Texture Image Specification + + Add to Table 3.16 (page 154): Sized internal formats + + Sized Base R G B A L I D + Internal Format Internal Format bits bits bits bits bits bits bits + --------------- --------------- ---- ---- ---- ---- ---- ---- ---- + RGBA8_SNORM RGBA 8 8 8 8 0 0 0 + + +Dependencies on ARB_texture_float extension: + + If ARB_texture_float is supported, GetTexParameter queries with + of TEXTURE_RED_TYPE_ARB, TEXTURE_GREEN_TYPE_ARB, TEXTURE_BLUE_TYPE_ARB or + TEXTURE_ALPHA_TYPE_ARB return SIGNED_NORMALIZED if + the base internal format is RGBA_SNORM. diff --git a/docs/MESA_window_pos.spec b/docs/MESA_window_pos.spec new file mode 100644 index 0000000..4d01f18 --- /dev/null +++ b/docs/MESA_window_pos.spec @@ -0,0 +1,126 @@ +Name + + MESA_window_pos + +Name Strings + + GL_MESA_window_pos + +Contact + + Brian Paul, brian.paul 'at' tungstengraphics.com + +Status + + Shipping (since Mesa version 1.2.8) + +Version + + +Number + + 197 + +Dependencies + + OpenGL 1.0 is required. + The extension is written against the OpenGL 1.2 Specification + +Overview + + In order to set the current raster position to a specific window + coordinate with the RasterPos command, the modelview matrix, projection + matrix and viewport must be set very carefully. Furthermore, if the + desired window coordinate is outside of the window's bounds one must + rely on a subtle side-effect of the Bitmap command in order to circumvent + frustum clipping. + + This extension provides a set of functions to directly set the + current raster position, bypassing the modelview matrix, the + projection matrix and the viewport to window mapping. Furthermore, + clip testing is not performed. + + This greatly simplifies the process of setting the current raster + position to a specific window coordinate prior to calling DrawPixels, + CopyPixels or Bitmap. + +New Procedures and Functions + + void WindowPos2dMESA(double x, double y) + void WindowPos2fMESA(float x, float y) + void WindowPos2iMESA(int x, int y) + void WindowPos2sMESA(short x, short y) + void WindowPos2ivMESA(const int *p) + void WindowPos2svMESA(const short *p) + void WindowPos2fvMESA(const float *p) + void WindowPos2dvMESA(const double *p) + void WindowPos3iMESA(int x, int y, int z) + void WindowPos3sMESA(short x, short y, short z) + void WindowPos3fMESA(float x, float y, float z) + void WindowPos3dMESA(double x, double y, double z) + void WindowPos3ivMESA(const int *p) + void WindowPos3svMESA(const short *p) + void WindowPos3fvMESA(const float *p) + void WindowPos3dvMESA(const double *p) + void WindowPos4iMESA(int x, int y, int z, int w) + void WindowPos4sMESA(short x, short y, short z, short w) + void WindowPos4fMESA(float x, float y, float z, float w) + void WindowPos4dMESA(double x, double y, double z, double ) + void WindowPos4ivMESA(const int *p) + void WindowPos4svMESA(const short *p) + void WindowPos4fvMESA(const float *p) + void WindowPos4dvMESA(const double *p) + +New Tokens + + none + +Additions to Chapter 2 of the OpenGL 1.2 Specification (OpenGL Operation) + + - (2.12, p. 41) Insert after third paragraph: + + Alternately, the current raster position may be set by one of the + WindowPosMESA commands: + + void WindowPos{234}{sidf}MESA( T coords ); + void WindowPos{234}{sidf}vMESA( T coords ); + + WindosPos4MESA takes four values indicating x, y, z, and w. + WindowPos3MESA (or WindowPos2MESA) is analaguos, but sets only + x, y, and z with w implicitly set to 1 (or only x and y with z + implicititly set to 0 and w implicitly set to 1). + + WindowPosMESA operates like RasterPos except that the current modelview + matrix, projection matrix and viewport parameters are ignored and the + clip test operation always passes. The current raster position values + are directly set to the parameters passed to WindowPosMESA. The current + color, color index and texture coordinate update the current raster + position's associated data. + +Additions to the AGL/GLX/WGL Specifications + + None + +GLX Protocol + + Not specified at this time. However, a protocol message very similar + to that of RasterPos is expected. + +Errors + + INVALID_OPERATION is generated if WindowPosMESA is called betweeen + Begin and End. + +New State + + None. + +New Implementation Dependent State + + None. + +Revision History + + * Revision 1.0 - Initial specification + * Revision 1.1 - Minor clean-up (7 Jan 2000, Brian Paul) + diff --git a/docs/MESA_ycbcr_texture.spec b/docs/MESA_ycbcr_texture.spec new file mode 100644 index 0000000..0fa1f7b --- /dev/null +++ b/docs/MESA_ycbcr_texture.spec @@ -0,0 +1,204 @@ +Name + + MESA_ycbcr_texture + +Name Strings + + GL_MESA_ycbcr_texture + +Contact + + Brian Paul, Tungsten Graphics, Inc. (brian.paul 'at' tungstengraphics.com) + Keith Whitwell, Tungsten Graphics, Inc. (keith 'at' tungstengraphics.com) + +Status + + Shipping (Mesa 4.0.4 and later) + +Version + + 1.0 + +Number + + TBD + +Dependencies + + OpenGL 1.0 or later is required + This extensions is written against the OpenGL 1.4 Specification. + NV_texture_rectangle effects the definition of this extension. + +Overview + + This extension supports texture images stored in the YCbCr format. + There is no support for converting YCbCr images to RGB or vice versa + during pixel transfer. The texture's YCbCr colors are converted to + RGB during texture sampling, after-which, all the usual per-fragment + operations take place. Only 2D texture images are supported (not + glDrawPixels, glReadPixels, etc). + + A YCbCr pixel (texel) is a 16-bit unsigned short with two components. + The first component is luminance (Y). For pixels in even-numbered + image columns, the second component is Cb. For pixels in odd-numbered + image columns, the second component is Cr. If one were to convert the + data to RGB one would need to examine two pixels from columns N and N+1 + (where N is even) to deduce the RGB color. + +IP Status + + None + +Issues + + None + +New Procedures and Functions + + None + +New Tokens + + Accepted by the and parameters of + TexImage2D and TexSubImage2D: + + YCBCR_MESA 0x8757 + + Accepted by the parameter of TexImage2D and TexSubImage2D: + + UNSIGNED_SHORT_8_8_MESA 0x85BA /* same as Apple's */ + UNSIGNED_SHORT_8_8_REV_MESA 0x85BB /* same as Apple's */ + +Additions to Chapter 2 of the OpenGL 1.4 Specification (OpenGL Operation) + + None + +Additions to Chapter 3 of the OpenGL 1.4 Specification (Rasterization) + + In section 3.6.4, Rasterization of Pixel Rectangles, on page 101, + add the following to Table 3.8 (Packed pixel formats): + + type Parameter GL Data Number of Matching + Token Name Type Components Pixel Formats + -------------- ------- ---------- ------------- + UNSIGNED_SHORT_8_8_MESA ushort 2 YCBCR_MESA + UNSIGNED_SHORT_8_8_REV_MESA ushort 2 YCBCR_MESA + + + In section 3.6.4, Rasterization of Pixel Rectangles, on page 102, + add the following to Table 3.10 (UNSIGNED_SHORT formats): + + UNSIGNED_SHORT_8_8_MESA: + + 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 + +-------------------------------+-------------------------------+ + | 1st | 2nd | + +-------------------------------+-------------------------------+ + + UNSIGNED_SHORT_8_8_REV_MESA: + + 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 + +-------------------------------+-------------------------------+ + | 2nd | 1st | + +-------------------------------+-------------------------------+ + + + In section 3.6.4, Rasterization of Pixel Rectangles, on page 104, + add the following to Table 3.12 (Packed pixel fiedl assignments): + + First Second Third Fourth + Format Element Element Element Element + ------ ------- ------- ------- ------- + YCBCR_MESA luminance chroma + + + In section 3.8.1, Texture Image Specification, on page 125, add + another item to the list of TexImage2D and TexImage3D equivalence + exceptions: + + * The value of internalformat and format may be YCBCR_MESA to + indicate that the image data is in YCbCr format. type must + be either UNSIGNED_SHORT_8_8_MESA or UNSIGNED_SHORT_8_8_REV_MESA + as seen in tables 3.8 and 3.10. Table 3.12 describes the mapping + between Y and Cb/Cr to the components. + If NV_texture_rectangle is supported target may also be + TEXTURE_RECTANGLE_NV or PROXY_TEXTURE_RECTANGLE_NV. + All pixel transfer operations are bypassed. The texture is stored as + YCbCr, not RGB. Queries of the texture's red, green and blue component + sizes will return zero. The YCbCr colors are converted to RGB during + texture sampling using an implementation dependent conversion. + + + In section 3.8.1, Texture Image Specification, on page 126, add + another item to the list of TexImage1D and TexImage2D equivalence + exceptions: + + * The value of internalformat and format can not be YCBCR_MESA. + + + In section 3.8.2, Alternate Texture Image Specification Commands, on + page 129, insert this paragraph after the first full paragraph on the + page: + + "If the internal storage format of the image being updated by + TexSubImage2D is YCBCR_MESA then format must be YCBCR_MESA. + The error INVALID_OPERATION will be generated otherwise." + + +Additions to Chapter 4 of the OpenGL 1.4 Specification (Per-Fragment +Operations and the Frame Buffer) + + None + +Additions to Chapter 5 of the OpenGL 1.4 Specification (Special Functions) + + None + +Additions to Chapter 6 of the OpenGL 1.4 Specification (State and +State Requests) + + None + +Additions to Appendix A of the OpenGL 1.4 Specification (Invariance) + + None + +Additions to the AGL/GLX/WGL Specifications + + None + +GLX Protocol + + None + +Errors + + INVALID_ENUM is generated by TexImage2D if is + MESA_YCBCR but is not MESA_YCBCR. + + INVALID_ENUM is generated by TexImage2D if is MESA_YCBCR but + is not MESA_YCBCR. + + INVALID_VALUE is generated by TexImage2D if is MESA_YCBCR and + is MESA_YCBCR and is not zero. + + INVALID_OPERATION is generated by TexSubImage2D if the internal image + format is YCBCR_MESA and is not YCBCR_MESA. + + INVALID_OPERATION is generated by CopyTexSubImage2D if the internal + image is YCBCR_MESA. + +New State + + Edit table 6.16 on page 231: change the type of TEXTURE_INTERNAL_FORMAT + from n x Z42 to n x Z43 to indicate that internal format may also be + YCBCR_MESA. + +Revision History + + 20 September 2002 - Initial draft + 29 April 2003 - minor updates + 3 September 2003 - further clarify when YCbCr->RGB conversion takes place + 19 September 2003 - a few more updates prior to submitting to extension + registry. + 3 April 2004 - fix assorted inaccuracies diff --git a/docs/README.3DFX b/docs/README.3DFX new file mode 100644 index 0000000..7feda6f --- /dev/null +++ b/docs/README.3DFX @@ -0,0 +1,830 @@ + + 3Dfx Glide device driver + + + +Requirements: +------------- + +A Voodoo-based videocard/accelerator +DOS (with DJGPP), Windows9x/2k (with MinGW), Linux +Glide3x library for your OS + +http://sourceforge.net/projects/glide/ + + + +How to compile: +--------------- + +DJGPP: + Place the Glide3 SDK in the top Mesa directory: + $(MESA)/glide3/include/ + 3dfx.h, g3ext.h, glide.h, glidesys.h, glideutl.h, sst1vid.h + $(MESA)/glide3/lib/ + libgld3x.a, libgld3i.a, glide3x.dxe + Type: + make -f Makefile.DJ X86=1 FX=1 + Look into the makefile for further information. + +MinGW: + Place the Glide3 SDK in the top Mesa directory: + $(MESA)/glide3/include/ + 3dfx.h, g3ext.h, glide.h, glidesys.h, glideutl.h, sst1vid.h + $(MESA)/glide3/lib/ + libglide3x.a, glide3x.dll + Type: + make -f Makefile.mgw X86=1 FX=1 + Look into the makefile for further information. + +Linux: + Place the Glide3 SDK in /usr/local/glide + /usr/local/glide/include/ + 3dfx.h, g3ext.h, glide.h, glidesys.h, glideutl.h, sst1vid.h + /usr/local/glide/lib/ + libglide3x.a, libglide3x.so + Type: + make linux-glide + or + make linux-x86-glide + + + +Compilation defines: +-------------------- + +FX_DEBUG + enable driver debug code +FX_TRAP_GLIDE + enable Glide trace code +FX_PACKEDCOLOR + use packed color in vertex structure +FX_TC_NAPALM + map GL_COMPRESSED_RGB[A] to FXT1. Works with VSA100-based cards only. +FX_COMPRESS_S3TC_AS_FXT1_HACK + map S3TC to FXT1 +FX_RESCALE_BIG_TEXURES_HACK + fake textures larger than HW can support + (see MESA_FX_MAXLOD environment variable) + + + +Environment variables: +---------------------- + +The following environment variables affect MesaFX. Those that affect Glide +only, are beyond the scope of this section. Entries that don't have a "Value" +field, can have any value whatsoever + ex: set MESA_FX_IGNORE_CMBEXT=y + +"Note" (*) means that the environment variable affects Glide, too; also, if +the var is not found in the environment, it is searched in windoze registry. +"Note" (!) means that the environment variable is not working as expected; +may have undefined effects, might have effects only at Glide level or might +not have any effect whatsoever. Caveat emptor! Those are to be revised soon. + +It is recommended to leave the envvars alone, so that Mesa/Glide will run with +default values. Use them only when you experience crashes or strange behavior. + +FX_GLIDE_NUM_TMU + OS: all + HW: dual-TMU cards (Voodoo2, Avenger, Napalm) + Desc: force single-TMU + Note: (*) + Value: "1" +FX_GLIDE_SWAPPENDINGCOUNT + OS: all + HW: all + Desc: max # of buffers allowed to build up + Note: (*) (!) + Value: "0", "1", "2", "3", "4", "5" or "6" +FX_GLIDE_SWAPINTERVAL + OS: all + HW: all + Desc: number of vertical retraces to wait before swapping + Note: (*) (!) works only at Glide-level? +SSTH3_SLI_AA_CONFIGURATION + OS: all + HW: VSA100-based cards + Desc: SLI/AA setup + Note: (*) (!) works only at Glide-level? + Value: + 1, 2, 4 chip cards + "0" - SLI & AA disable + "1" - SLI disabled, 2 sample AA enabled + 2, 4 chip cards + "2" - 2-way SLI enabled, AA disabled + "3" - 2-way SLI enabled, 2 sample AA enabled + "4" - SLI disabled, 4 sample AA enabled + 4 chip cards + "5" - 4-way SLI enabled, AA disabled + "6" - 4-way SLI enabled, 2 sample AA enabled + "7" - 2-way SLI enabled, 4 sample AA enabled + "8" - SLI disabled, 8 sample AA enabled +SST_DUALHEAD + OS: win32 + HW: ? + Desc: ? + Note: (!) disabled? +MESA_FX_NO_SIGNALS + OS: linux + HW: all + Desc: avoid installing signals + Note: (!) untested! +MESA_FX_INFO + OS: all + HW: all + Desc: verbose to stderr + Value: any; special value "r" to redirect stderr to MESA.LOG +MESA_FX_NOSNAP + OS: all + HW: Voodoo1, Rush, Banshee + Desc: do not snap vertices inside Mesa + Note: to be used with Glide3x that snaps vertices internally +MESA_FX_POINTCAST + OS: all + HW: dual-TMU cards (some Voodoo1, Voodoo2, Avenger, Napalm) + Desc: try to use pointcast palette + Note: may give adverse effects on UMA cards (Avenger, Napalm) +MESA_FX_IGNORE_PALEXT + OS: all + HW: all + Desc: disable 6666 palette +MESA_FX_IGNORE_PIXEXT + OS: all + HW: Napalm + Desc: force 565 16bpp mode (traditional Voodoo, no 32/15bpp) +MESA_FX_IGNORE_TEXFMT + OS: all + HW: Napalm + Desc: disable 32bit textures +MESA_FX_IGNORE_CMBEXT + OS: all + HW: Napalm + Desc: disable Napalm combiners (color/alpha/texture) + Note: this option allows dual-TMU cards perform single-pass + trilinear, but some advanced (multi)texturing modes + won't work (GL_EXT_texture_env_combine) +MESA_FX_IGNORE_MIREXT + OS: all + HW: all + Desc: disable mirror extension +MESA_FX_IGNORE_TEXUMA + OS: all + HW: all + Desc: disable UMA +MESA_FX_IGNORE_TEXUS2 + OS: all + HW: all + Desc: disable Texus2 +MESA_FX_MAXLOD + OS: all + HW: non VSA-100 cards + Desc: enable large texture support using SW rescaling + Value: + "9" - 512x512 textures + "10" - 1024x1024 textures + "11" - 2048x2048 textures +MESA_FX_ALLOW_VP + OS: all + HW: all + Desc: allow vertex program extensions +MESA_GLX_FX + OS: linux + HW: Voodoo1, Rush, Voodoo2 + Desc: display mode + Note: (!) experimental + Value: + "w" - windowed mode + "f" - fullscreen mode + "d" - disable glide driver + OS: win32 + HW: Rush, Banshee, Avenger, Napalm + Desc: display mode + Note: (!) experimental + Value: + "w" - windowed mode + + + +Contact: +-------- + +Daniel Borca +Hiroshi Morii + + + +WARNING! The info below this line is outdated (yet some of it useful). WARNING! +******************************************************************************* + + + +Info for Mesa 4.1 +----------------- + +The 3dfx Glide driver in Mesa is disabled by default. Not too many people +use this driver anymore and at some point down the road it will be dropped. + +To use/enable the Glide driver either do this: + +'./configure --with-glide=DIR' Where DIR is the location of Glide, like + /usr/ or /usr/local + +OR + +'make linux-x86-glide' If using the old-style Makefile system. + +The rest of this file hasn't changed since Mesa 3.3. Some of it's out of +date, but some is still valid. + + + +What do you need ? +------------------ + + - A PC with a 3Dfx Voodoo1/2 Graphics or Voodoo Rush based board + (Pure3D, Monster 3D, R3D, Obsidian, Stingray 128/3D, etc.). + The Quantum3D Obsidian3D-2 X-24 requires some special env. setting + under Linux (more information in the "Useful Glide Environment + Variables"); + + - The 3Dfx Glide library 2.3 or later for your OS (the 2.4 works fine). + The Voodoo2 requires the Glide library 2.51. The Glide 3.1 is not + compatible with the Glide 2.x so it doesn't work with the current + version of the driver; + + - A compiler supported by the Glide library (Micro$oft VC++ (tested), + Watcom (tested), GCC for Linux (tested), etc.); + + - It's nice to have two monitors - one for your normal graphics + card and one for your 3Dfx card. If something goes wrong with + an application using the 3Dfx hardware you can still see your + normal screen in order to recover. + + + +Tested on: +---------- + Windows 95 - David Bucciarelli + Windows NT - Henri Fousse + MS-DOS + Linux - Daryll Strauss, Brian Paul, David Bucciarelli + FreeBSD + BeOS - Duncan Wilcox + MacOS - Fazekas Miklos + + +What is able to do ? +-------------------- + + - It is able accelerate points, lines and polygon with flat + shading, gouraud shading, Z-buffer, texture mapping, blending, fog and + antialiasing (when possible). There is also the support for rendering + in a window with a slow trick for the Voodoo Graphics (available only + for Linux) and at full speed with the Voodoo Rush chipset. + Under Linux is also possible to switch on-the-fly between the fullscreen + and in-window rendering hack. + There is also the support for using more than one Voodoo Graphics in the + some application/PC (you can create one context for each board and use + multiple video outputs for driving monitors, videoprojectors or HMDs). + The driver is able to fallback to pure software rendering when afeature + isn't supported by the Voodoo hardware (however software rendering is + very slow compared to hardware supported rendering) + + + +How to compile: +--------------- + +Linux: +------ + Here are the basic steps for using the 3Dfx hardware with Mesa + on Linux: + + - You'll need the Glide library and headers. Mesa expects: + /usr/local/glide/include/*.h // all the Glide headers + /usr/local/glide/lib/libglide2x.so + + If your Glide libraries and headers are in a different directory + you'll have to modify the Mesa-config and mklib.glide files. + + - Unpack the MesaLib-3.1.tar.gz and MesaDemos-3.1.tar.gz archives; + + - If you're going to use a newer Mesa/Glide driver than v0.27 then + unpack the new driver archive over the Mesa directory. + + - In the Mesa-3.1 directory type "make linux-glide" + + - Compilation _should_ finish without errors; + + - Set your LD_LIBRARY_PATH environment variable so that the + libglide2x.so and Mesa library files can be found. For example: + setenv LD_LIBRARY_PATH "/usr/local/glide/lib:/SOMEDIR/Mesa-3.1/lib" + + - You'll have to run Glide-based programs as root or set the suid + bit on executables; + + - Try a demo: + cd gdemos + su + setenv MESA_GLX_FX f + ./gears (hit ESC to exit) + + - You can find the demos especially designed for the Voodoo driver in + in the Mesa-3.1/3Dfx/demos directory (type "make" in order to compile + everything). + +MacOS: +------ + Check the WEB page at http://valerie.inf.elte.hu/~boga/Mesa.html + +MS Windows: +----------- + + For the MSVC++: + - The glide2x.lib have to be in the default MSVC++ lib directory; + + - The Glide headers have to be in the default MSVC++ include directory; + + - You must have the vcvars32.bat script in your PATH; + + - Go to the directory Mesa-3.1 and run the mesafx.bat; + + - The script will compile everything (Mesa-3.1/lib/OpenGL32.{lib,dll}, + Mesa-3.1/lib/GLU32.{lib,dll}, Mesa-3.1/lib/GLUT32.{lib,dll} and + Voodoo demos); + + - At the end, you will be in the Mesa-3.1/3Dfx/demos directory; + + - Try some demo (fire.exe, teapot.exe, etc.) in order to check if + everything is OK (you can use Alt-Tab or Ctrl-F9 to switch between + the Voodoo screen and the windows desktop); + + - Remember to copy the Mesa OpenGL32.dll, GLU32.dll and GLUT32.dll in the + some directory were you run your Mesa based applications. + + - I think that you can easy change the Makefile.fx files in order + to work with other kind of compilers; + + - To discover how open the 3Dfx screen, read the sources under + the Mesa-3.1/3Dfx/demos directory. You can use the GLUT library or + the Diego Picciani's wgl emulator. + + NOTE: the MSVC++ 5.0 optimizer is really buggy. Also if you install the + SP3, you could have some problem (you can disable optimization in order + solve these kind of problems). + + +Doing more with Mesa & Linux Glide: +----------------------------------- + + The MESA_GLX_FX environment variable can be used to coax most + GLX-based programs into using Glide (and the __GLUT library + is GLX-based__). + + Full-screen 3Dfx rendering: + --------------------------- + + 1. Set the MESA_GLX_FX variable to "fullscreen": + + ksh: + export MESA_GLX_FX = "fullscreen" + csh: + setenv MESA_GLX_FX fullscreen + + 2. As root, run a GLX-based program (any GLUT demo on Linux). + + 3. Be careful: once the 3Dfx screen appears you won't be able + to see the GLUT windows on your X display. This can make using + the mouse tricky! One solution is to hook up your 3Dfx card to + a second monitor. If you can do this then set these env vars + first: + + setenv SST_VGA_PASS 1 + setenv SST_NOSHUTDOWN + + or for the Voodoo2: + + setenv SSTV2_VGA_PASS 1 + setenv SSTV2_NOSHUTDOWN + + Rendering into an X window with the help of the Voodoo hardware: + ---------------------------------------------------------------- + + 1. Start your X server in 16 bpp mode (XFree86: startx -- -bpp 16) + in order to have the best performance and the best visual + quality. However you can use any visual depth supported by X. + + 2. Set the following environment variables: + export MESA_GLX_FX="window" # to enable window rendering + export SST_VGA_PASS=1 # to stop video signal switching + export SST_NOSHUTDOWN=1 # to stop video signal switching + OR + setenv MESA_GLX_FX window + setenv SST_VGA_PASS 1 + setenv SST_NOSHUTDOWN 1 + + (the Voodoo2 requires to use "SSTV2_" instead "SST_"). + + 3. As root, try running a GLX-based program + + How does it work? We use the 3Dfx hardware to do rendering then + copy the image from the 3Dfx frame buffer into an X window when + the SwapBuffers() function is called. The problem with this + idea is it's slow. The image must be copied from the 3Dfx frame + buffer to main memory then copied into the X window (and when the X + visual depth doesn't match the Voodoo framebufffer bit per pixel, it + is required also a pixel format translation). + + NOTE: the in-window rendering feature only works with double-buffering. + + + On the fly switching between in window rendering and full screen rendering + -------------------------------------------------------------------------- + + The Mesa 2.6 has introduced the capability of switching + on-the-fly between the fullscreen/fullspeed rendering and the in-window + hack and vice versa. The on-the-fly switching requires a direct support + by the application but it is really easy to add. You have to start + your X server in 16 bpp mode and to add the following lines to your + application: + + #if defined(FX) && define(XMESA) + #include + + static int fullscreen=1; + #endif + + ... + + /* In the GLUT keyboard event callback */ + + #if defined(FX) && !define(WIN32) + case ' ': + fullscreen=(!fullscreen); + XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW); + break; + #endif + ... + + See the 3Dfx/demos/tunnel.c program + for an example. You have to set the -DXMESA flag in the Makefile's COPTS + to enable it. + + Rendering into an X window with the X11 software driver: + -------------------------------------------------------- + + Set the MESA_GLX_FX variable to "disable" your GLX-based program will use + the X11 software driver (the 3Dfx hardware isn't used at all). + + + +Useful Glide Environment Variables: +----------------------------------- + + - To disable the 3Dfx logo, set the FX_GLIDE_NO_SPLASH variable. + + - To disable video signal switching: + setenv SST_VGA_PASS 1 + setenv SST_NOSHUTDOWN + or for the Voodoo2: + setenv SSTV2_VGA_PASS 1 + setenv SSTV2_NOSHUTDOWN + + - To set the default screen refresh rate: + setenv SST_SCREENREFRESH=75 + + the supported values are 60, 70, 72, 75, 80, 85, 90, 100, 120. + + - To force the Mesa library to swap buffers as fast as possible, + without any vertical blanking synchronization (useful for benchmarks): + setenv FX_GLIDE_SWAPINTERVAL 0 + setenv SST_SWAP_EN_WAIT_ON_VIDSYNC 0 + + - You can slight improve the performances of your Voodoo1 board with + the following env. var.: + setenv SST_FASTMEM 1 + setenv SST_PCIRD 1 + setenv SST_GRXCLK 57 + + (don't use this setting with the Quantum3D 100SB or with any other + SLI configuration: it will hang everything !). + The following setting can be used with the Voodoo2: + setenv SSTV2_FASTMEM_RAS_READS=1 + setenv SSTV2_FASTPCIRD=1 + setenv SSTV2_GRXCLK=95 + + - The Quantum3D Obsidian3D-2 X-24 requires some special env. setting + in order to work under Linux: + + export SSTV2_FT_CLKDEL=5 + export SSTV2_TF0_CLKDEL=7 + export SSTV2_TF1_CLKDEL=7 + export SSTV2_TF2_CLKDEL=7 + export SSTV2_SLIM_VIN_CLKDEL=3 + export SSTV2_SLIM_VOUT_CLKDEL=2 + export SSTV2_SLIS_VIN_CLKDEL=3 + export SSTV2_SLIS_VOUT_CLKDEL=2 + + (Thanks to Phil Ross for this trick). + + + + +The Mesa/Voodoo Environment Variables: +-------------------------------------- + + - Only for Windows/Voodoo Rush users, if you define the + env. var. MESA_WGL_FX: + export MESA_WGL_FX=fullscreen + you will get fullscreen rendering; + + - Only for Windows/Voodoo Rush users, if you define the + env. var. MESA_WGL_FX: + export MESA_WGL_FX=window + you will get window rendering (default value); + + - Only for Linux users, you can find more informations about + the env. var. MESA_GLX_FX in the "Doing more with Mesa & Linux Glide" + section; + + - If you define the env. var. MESA_FX_SWAP_PENDING: + export MESA_FX_SWAP_PENDING=4 + you will able to set the maximum number of swapbuffers + commands in the Voodoo FIFO after a swapbuffer (default value: 2); + + - If you define the env. var. MESA_FX_INFO: + export MESA_FX_INFO=1 + you will get some useful statistic. + + - If you define the env. var. MESA_FX_NO_SIGNALS: + export MESA_FX_NO_SIGNALS=1 + Mesa/FX will not install atexit() or signal() handlers. + + + +Know BUGS and Problems: +----------------------- + + - fog doesn't work in the right way when using the glDepthRange() function; + + - Maximum texture size: 256x256 (this is an hardware limit); + + - Texture border aren't yet supported; + + - A GL_BLEND in a glTexEnv() is not supported (it is an hardware limit); + + - Use the glBindTexture extension (standard in OpenGL 1.1) for texture + mapping (the old way: glTexImage inside a display list, download + the texture map each time that you call the display list !!!); + + - Stencil buffer and Accumulation buffer are emulated in software (they are not + directly supported by the Hardware); + + - Color index mode not implemented (this is an hardware limit); + + - Thre is an know bug in the Linux Glide library so the in-window-rendering hack + and any other operations that requires to read the Voodoo frame buffer + (like the accumulation buffer support) doesn't work on Voodoo SLI cards. + + - The driver switch to pure software (_slow_) rendering when: + + - Stencil enabled; + - Using the Accumulation buffer; + - Blend enabled and blend equation != GL_FUNC_ADD_EXT; + - Color logic operation enabled and color logic operation != GL_COPY; + - Using GL_SEPARATE_SPECULAR_COLOR; + - The four values of glColorMask() aren't the some; + - Texture 1D or 3D enabled; + - Texture function is GL_BLEND; + - Using the Multitexture extension with Voodoo cards with only one TMU; + - Using the Multitexture extension with Voodoo cards with more than + one TMU, and texture function isn't GL_MODULATE; + - Point size is != 1.0 or point params vector != (1.0,0.0,0.0); + - Line width != 1.0 or using stipple lines. + - Using polygon offset or stipple polygons; + + NOTE: this is list is not yet complete. + + +Hints and Special Features: +--------------------------- + + - Under Linux and with a Voodoo Graphics board, you can use + XMesaSetFXmode(XMESA_FX_FULLSCREEN or XMESA_FX_WINDOW) in order to + switch on the fly between fullscreen rendering and the in-window-rendering + hack. + + - The driver is able to use all the texture memory available: 2/4MB on + Voodoo1 boards and 8MB (!) on high-end Voodoo1 and Voodoo2 boards. + + - Trilinear filtering is fully supported on Voodoo boards with two TMUs + (high-end Voodoo1 boards and Voodoo2 boards). When only one TMU is + available the driver fallback to bilinear filter also if you ask + for trilinear filtering. + + - The Voodoo driver support multiple Voodoo Graphics boards in the + some PC. Using this feature, you can write applications that use + multiple monitors, videoprojectors or HMDs for the output. See + Mesa-3.1/3Dfx/demos/tunnel2.c for an example of how setup one + context for each board. + + - The v0.19 introduces a new powerful texture memory manager: the + texture memory is used as a cache of the set of all defined texture + maps. You can now define several MBs of texture maps also with a 2MB + of texture memory (the texture memory manager will do automatically + all the swap out/swap in + texture memory work). The new texture memory manager has also + solved a lot of other bugs/no specs compliance/problems + related to the texture memory usage. + + - Use triangles and quads strip: they are a LOT faster than sparse + triangles and quads. + + - The Voodoo driver supports the GL_EXT_paletted_texture. it works + only with GL_COLOR_INDEX8_EXT, GL_RGBA palettes and the alpha value + is ignored because this is a limitation of the current Glide + version and of the Voodoo hardware. See Mesa-3.1/3Dfx/demos/paltex.c for + a demo of this extension. + + - The Voodoo driver directly supports 3Dfx Global Palette extension. + It was written for GLQuake and I think that it isn't a good idea + to use this extension for any other purpose (it is a trick). See + Mesa-3.1/3Dfx/demos/glbpaltex.c for a demo of this extension. + + - The Voodoo driver chooses the screen resolution according to the + requested window size. If you open a 640x480 window, you will get + a 640x480 screen resolution, if you open a 800x600 window, you + will get a 800x600 screen resolution, etc. + Most GLUT demos support the '-geometry' option, so you can choose + the screen resolution: 'tunnel -geometry 800x600'. + Clearly, you Voodoo board must have enough framebuffer RAM (otherwise + the window creation will fail). + + - The glGetString(GL_RENDERER) returns more information + about the hardware configuration: "Mesa Glide + CARD/ FB/ + TM/ TMU/" + where: CARD is the card used for the current context, + FB is the number of MB for the framebuffer, + TM is the number of MB for the texture memory, + TMU is the number of TMU. You can try to run + Mesa/demos/glinfo in order to have an example of the output. + +Did you find a lot BUGs and problems ? Good, send me an email. + + + +FAQ: +---- + +For a complete FAQ check the Bernd Kreimeier's Linux 3Dfx HOWTO +available at http://www.gamers.org/dEngine/xf3D (it includes also +a lot of informations not strictly related to Linux, so it can be +useful also if you don't use Linux) + +1. What is 3Dfx? + +3Dfx Interactive, Inc. is the company which builds the VooDoo 3-D graphics +chipset (and others) used in popular PC cards such as the Diamond Monster 3D +and the Orchid Righteous 3D (more informations at http://www.3dfx.com). + + +2. What is Glide? + +Glide is a "thin" programming interface for the 3Dfx hardware. It was +originally written for Windows/Intel but has been ported to Linux/Intel +by Daryll Strauss. + +3Dfx, Inc. should be applauded for allowing the Linux version of Glide +to be written. + +You can directly program with the Glide library if you wish. You can +obtain Glide from the "Developer" section of the 3Dfx website: www.3dfx.com +There's a Linux/Glide newsgroup at news://news.3dfx.com/3dfx.glide.linux + + +3. What is fxmesa? + +"fxmesa" is the name of the Mesa device driver for the 3Dfx Glide library. +It was written by David Bucciarelli and others. It works on both Linux +and Windows. Basically, it allows you to write and run OpenGL-style programs +on the 3Dfx hardware. + + +4. What is GLQuake? + +Quake is a very popular game from id software, Inc. See www.idsoftware.com +GLQuake is a version of Quake written for OpenGL. There is now a Linux +version of GLQuake with works with the Mesa/3Dfx/Glide combo. + +Here's what you need to run GLQuake on Linux: + PC with 100MHz Pentium or better + a 3Dfx-based card + Mesa 3.1 libraries: libMesaGL.so libMesaGLU.so + Glide 2.4 libraries: libglide2x.so libtexus.so + GLQuake for Linux. + +Also, the windows version of GLQuake works fine with the Mesa OpenGL32.dll, +you have only to copy the Mesa-3.1/lib/OpenGL32.dll in the GLQuake directory +in order to test 'MesaQuake'. + + +5. What is GLUT? + +GLUT is Mark Kilgard's OpenGL Utility Toolkit. It provides an API for +writing portable OpenGL programs with support for multiple windows, pop- +up menus, event handling, etc. + +Check the Mark's home page for more informations (http://reality.sgi.com/mjk_asd). + +Every OpenGL programmer should check out GLUT. + +GLUT on Linux uses GLX. + + +6. What is GLX? + +GLX is the OpenGL extension to the X Window System. I defines both a +programming API (glX*() functions) and a network protocol. Mesa implements +an emulation of GLX on Linux. A real GLX implementation would requires +hooks into the X server. The 3Dfx hardware can be used with GLX-based +programs via the MESA_GLX_FX environment variable. + + +7. Is the Voodoo driver able to use the 4Mb texture memory of +the Pure3D boards ? + +Yes, the Voodoo driver v0.20 includes the support for Voodoo +Graphics boards with more than 2Mb of texture memory. + + +8. Do the Voodoo driver support the Voodoo Rush under Windows ? + +Yes, Diego Picciani has developed the support for the Voodoo +Rush but David Bucciarelli has a Pure3D and a Monster3D and Brian Paul +has a Monster3D, so the new versions of the Mesa/Voodoo sometime are +not tested with the Voodoo Rush. + + +9. Do the Voodoo driver support the Voodoo Rush under Linux ? + +No because the Linux Glide doesn't (yet) support the Voodoo Rush. + + +10. Can I sell my Mesa/Voodoo based software and include +a binary copy of the Mesa in order to make the software +working out of the box ? + +Yes. + + +11. Which is the best make target for compiling the Mesa for +Linux GLQuake ('make linux-glide', 'make linux-386-glide', etc.) ? + +'make linux-386-opt-glide' for Voodoo1 and 'make linux-386-opt-V2-glide' +for Voodoo2 boards because it doesn't include the '-fPIC' +option (4-5% faster). + + +12. Can I use a Mesa compiled with a 'make linux-386-opt-V2-glide' +for my applications/programs/demos ? + +Yes, there is only one constrain: you can't run two Mesa applications +at the some time. This isn't a big issue with the today Voodoo Graphics. + + +Thanks to: +---------- + +Henri Fousse (he has written several parts of the v0.15 and the old GLUT + emulator for Win); + +Diego Picciani (he has developed all the Voodoo Rush support and the wgl + emulator); + +Daryll Strauss (for the Linux Glide and the first Linux support); + +Brian Paul (of course); + +Dave 'Zoid' Kirsch (for the Linux GLQuake and Linux Quake2test/Q2 ports) + +Bernd Kreimeier (for the Linux 3Dfx HOWTO and for pushing companies to offer + a better Linux support) + +3Dfx and Quantum3D (for actively supporting Linux) + +The most update places where find Mesa VooDoo driver related informations are +the Mesa mailing list and my driver WEB page +(http://www-hmw.caribel.pisa.it/fxmesa/index.shtml) + + +David Bucciarelli (davibu@tin.it) + +Humanware s.r.l. +Via XXIV Maggio 62 +Pisa, Italy +Tel./Fax +39-50-554108 +email: info.hmw@plus.it +www: www-hmw.caribel.pisa.it diff --git a/docs/README.AMIWIN b/docs/README.AMIWIN new file mode 100644 index 0000000..47cf696 --- /dev/null +++ b/docs/README.AMIWIN @@ -0,0 +1,181 @@ +AMIGA AMIWIN PORT of MESA: THE OPENGL SOFTWARE EMULATION +======================================================== +Port by Victor Ng-Thow-Hing (victorng@dgp.toronto.edu) +Original Author (Brian Paul (brianp@ssec.wisc.edu) + +Dec.1 , 1995: Port of release Mesa 1.2.5 + - Modifications made to minimize changes to Mesa distribution. + +Nov.25, 1995: Port of release Mesa 1.2.4 + + +HISTORY +======= +As a 3D graphics progammer, I was increasingly frustrated to see OpenGL +appearing on so many platforms EXCEPT the Amiga. Up to now, the task +of porting OpenGL directly from native Amiga drawing routines seemed like +a daunting task. However, two important events made this port possible. + +First of all, Brian Paul wrote Mesa, the OpenGL software emulator that +can be found on many platforms - except the Amiga and Atari (who cares +about the latter!). This was pretty ironic considering that Mesa was +originally prototyped on an Amiga! The second great event was when +Holger Kruse developed AmiWin, the X11R6 server for the Amiga (definitely +register for this great piece of software) and released a development kit +so one could compile X programs with SAS/C. + +Since Mesa had X routines as its primitive drawing operations, this made +a marriage of Mesa and Amiwin feasible. I copied over the sources from +an ftp site, played with the code, wrote some Smakefiles, and voila, +I had OpenGL programs displaying on my Amiga. + +Although the speed is nothing to be impressed about, this port can be +potentially useful to those who want to quickly test their code in +wireframe or perhaps learn more about programming with the OpenGL API. + +I hope Amiga developers will continue to write excellent software for +their machine, especially more X clients for Amiwin. If you have any +solutions so some of my problems in the porting notes, please send me +some email! + +See you around, +Vic. + +HOW TO CREATE THE LIBRARIES AND SAMPLE CODE +=========================================== + +Just run the shell script mklib.amiwin in the mesa directory. This will +make all the libraries and copy them into the mesa/lib directory. If you +don't want to compile everything, just go to the desired directory and +type smake in that directory. + +Change any of the variables in the smakefiles as necessary. You will REQUIRE +the Amiwin development kit to compile these libraries since you need X11.LIB +and the shareable X libraries. Some examples require the AmiTCP4.0 +net.lib static link library and related header files for unix related +header files and functions like sleep(). + +HOW TO USE THE MESA LIBRARIES +============================= + +Study the Smakefiles in the demos, samples and book directories for the +proper SAS/C options and linkable libraries to use. Basically aux calls +require Mesaaux.LIB, gl calls require MesaGL.LIB, glu calls MesaGLU.LIB, +tk calls Mesatk.LIB. There is a preliminary port of MesaGLUT.LIB toolkit +available in the lib directory with the other Mesa libraries. However, +it seems to cause crashes on some of the sample code. Someone else may want +to attempt a more stable port. + +PORTING NOTES TO AMIWIN +======================= + +My strategy of porting was to leave as much of the code untouched as +possible. I surrounded any amiga specific changes with +#ifdef AMIWIN ... #endif or #ifndef AMIWIN ... #endif preprocessor +symbols. The code was ported on an Amiga 2000, with Fusion 40 accelerator +and a Picasso II graphics card. The SAS/C 6.56 compiler was used, with +the AmiWin 2.16 X development kit. + +All compilations were done for a 68040 CPU with 68882 math coprocessor for +maximum speed. Please edit the smakefile for other compilers. +I wrote smakefiles for the directories I ported. I omitted the Windows +and Widgets directories. The former is for MS Windows and the latter +requires Motif, which is not easily available for the Amiga. + +Here are the changes I did per directory: + +* mesa +Nov. 25, 1995 v 1.2.4 + - added a mklib.amiwin shell script that will make all the libraries and + sample code for Mesa + - created this readme file: readme.AMIGA + +* mesa/include +Dec. 1, 1995 v 1.2.5 + - added the following to GL/xmesa.h + #ifdef AMIWIN + #include + extern struct Library *XLibBase; + #endif +NET CHANGE: xmesa.h + +* mesa/src +Nov. 25, 1995 v 1.2.4 + - added the necessary pragma calls for X functions to the following: + xmesa1.c, xmesa2.c, xmesa3.c, xfonts.c, glx.c + This prevents undefined symbols errors during the linking phase for + X library calls + - created smakefile +Dec. 1, 1995 v 1.2.5 + - removed AMIWIN includes from xmesa1.c, xmesa2.c, xmesa3.c, xfonts.c, + glx.c since they are now defined in include/GL/xmesa.h +NET CHANGE: smakefile + +* mesa/src-tk +Nov. 25, 1995 v 1.2.4 + - added the necessary pragma calls for X functions to the following: + private.h + - created smakefile +Dec. 1, 1995 v 1.2.5 + - removed AMIWIN includes from private.h since it is now defined in + include/GL/xmesa.h +NET CHANGE: smakefile + +* mesa/src-glu +Nov. 25, 1995 v 1.2.4 + - created smakefile +NET CHANGE: smakefile + +* mesa/src-aux +Nov. 25, 1995 v 1.2.4 + - added the necessary pragma calls for X functions to the following: + glaux.c + - created smakefile +NET CHANGE: glaux.c, smakefile + +* mesa/demos +Nov. 25, 1995 v 1.2.4 + - added the necessary pragma calls for X functions to the following: + xdemo.c, glxdemo.c, offset.c + - created smakefile + - put #ifndef AMIWIN ... #endif around sleep() calls in xdemo.c since + they are not part of AmigaDOS. +Dec. 1, 1995 v 1.2.5 + - removed AMIWIN defines from xdemo.c, glxdemo.c, offset.c since + already defined in include/GL/xmesa.h + - modified Smakefile to include header and includes from the AmiTCP4.0 + net.lib linkable library to provide unix-compatible sys/time.h and + the sleep() function + - removed AMIWIN defines in xdemo.c since sleep() now defined +NET CHANGE: smakefile + +* mesa/samples +Nov. 25, 1995 v 1.2.4 + - added the necessary pragma calls for X functions to the following: + oglinfo.c + - created smakefile + - put #ifndef AMIWIN ... #endif around sleep() in blendxor.c + - removed olympic from smakefile targets since not defined +Dec. 1, 1995 v 1.2.5 + - removed AMIWIN defines from oglinfo.c, since already defined in + include/GL/xmesa.h + - modified Smakefile to include header and includes from the AmiTCP4.0 + net.lib linkable library to provide unix-compatible sys/time.h and + the sleep() function + - removed AMIWIN defines in blendxor.c for sleep() + - added AMIWIN defines around _MACHTEN_ in olympic.c since xrandom() + functions are not defined in any libraries + - added olympic back into the Smakefile targets +NET CHANGE: smakefile, olympic.c + +* mesa/book +Nov. 25, 1995 v 1.2.4 +- created smakefile +- removed accpersp and dof from smakefile targets since the SAS/C compile seems to + confuse the near,far variables with near/far memory models. +NET CHANGE: smakefile + +* mesa/windows +Dec. 1, 1995 v 1.2.5 +- Removed directory to save space since this is only needed for Windows based + machines. diff --git a/docs/README.BEOS b/docs/README.BEOS new file mode 100644 index 0000000..efd84e8 --- /dev/null +++ b/docs/README.BEOS @@ -0,0 +1,136 @@ + + Mesa / BeOS Information + + + +* Introduction + +Brian Paul added in Mesa 3.1 a driver for BeOS R4.5 operating system. +This driver implements a clone of the BGLView class. This class, +derived from BView, allows OpenGL rendering into any BeOS window. His +driver was updated in Mesa 4.1 and again in version 6.1 by Philippe +Houdoin, who's maintaining this driver since. + +Any application which uses the BGLView should be able to use Mesa +instead of Be's OpenGL without changing any code. + +Since Be's OpenGL implementation (as of R5) is basically just the +SGI sample implementation, it's pretty slow. You'll see that Mesa +is considerably faster. + + +* Source Code + +The source code for the driver is in src/mesa/drivers/beos/ directory. +It's not 100% finished at this time but many GLUT-based demos are +working. No optimizations have been made at this time. + + +* Compiling + +Since Mesa 6.x, it can be build under BeOS with both the R5 builtin gcc version +or more recent gcc versions available for BeOS, like this gcc version 2.95.3 for BeOS +you can find at http://www.bebits.com/app/2157. +Anyway, keep in mind that to take full advantage of Mesa x86 optimizations, you better +want to use gcc 2.95.3 or sooner versions... + +To build Mesa-powered BeOS libGL.so version, open an Terminal window, +move to Mesa root folder and type this command: + +$ make beos + +Note that the "beos" argument is only needed the first time to setup build config. +Next times, typing "make" will be enough. + +When it finishes the Mesa based libGL.so library for +BeOS will be in the lib/ directory, along libglut.so library. +Several demo/test programs should have been build too under progs/* folders. +If it stop when building one of the progs/* programs, you may want to ignore it +and force make to move on next target by adding the -k make option: + +$ cd progs +$ make -k + +To install it as Be's default libGL.so replacement, put it in your +/boot/home/config/lib/ directory. All your GL/GLUT apps will use +the Mesa based then. + +By default, it build a non-debug version library. +The x86 (MMX, SSE and 3DNOW) optimizations are also supported for x86 target. +For PowerPC BeOS flavor, sorry, Mesa don't have ppc (Altivec) optimizations +yet. + +To build a DEBUG version, type instead this : + +$ DEBUG=1 make + + +* Example Programs + +Look under progs/beos/ for some BGLView-based programs. +You should find under progs/samples and progs/redbook directories GLUT-based programs too. +They all should have been compiled along with the Mesa library. + + +* GLUT + +A beta version of GLUT 3.7 port for BeOS, made by Jake Hamby, can be found at +http://anobject.com/jehamby/Code/Glut-3.7-x86.zip. +This is the version currently included in Mesa source code, and +build in lib/libglut.so. + +A previous 3.5 version of this GLUT BeOS port used to be available at +http://home.beoscentral.com/jehamby/Glut-3.5-x86.zip. + +They're special versions of GLUT for the BeOS platform. I don't +believe Mark Kilgard's normal GLUT distribution includes BeOS +support. + + +* Special Features + +Mesa's implementation of the BGLView class has an extra member +function: CopySubBufferMESA(). It basically works like SwapBuffers() +but it only copies a sub region from the back buffer to the front +buffer. This is a useful optimization for some applications. +If you use this method in your code be sure that you check at runtime +that you're actually using Mesa (with glGetString) so you don't +cause a fatal error when running with Be's OpenGL. + + +* Work Left To Do + +- BDirectWindow single buffering support is not implemented yet. +- Color index mode is not implemented yet. +- Reading pixels from the front buffer not implemented yet. +- There is also a BGLScreen class in BeOS for full-screen OpenGL rendering. + This should also be implemented for Mesa. +- Multiple renderers add-ons support, first step toward hardware acceleration + support. + +* Other contributors to this BeOS port + +Jake Hamby jhamby anobject com +Marcin Konicki ahwayakchih neoni net +Francois Revol revol free fr +Nathan Whitehorn nathanw uchicago edu + + +* Older BeOS Driver + +Mesa 2.6 had an earlier BeOS driver. It was based on Mesa's Off-screen +rendering interface, not BGLView. If you're interested in the older +driver you should get Mesa 2.6. + + +* BeOS and Glide + +Mesa 3.0 supported the 3Dfx/Glide library on Beos. Download Mesa 3.0 +if interested. Ideally, the 3Dfx/Glide support should be updated to +work with the new Mesa 3.1 BGLView implementation. + +The Glide library hasn't been updated for BeOS R4 and newer, to my knowledge, +as of February, 1999. + + +---------------------------------------------------------------------- diff --git a/docs/README.CYGWIN b/docs/README.CYGWIN new file mode 100644 index 0000000..58d5af3 --- /dev/null +++ b/docs/README.CYGWIN @@ -0,0 +1,256 @@ + + Mesa Cygwin/X11 Information + + +WARNING +======= + +If you installed X11 (packages xorg-x11-devel and xorg-x11-bin-dlls ) with the +latest setup.exe from Cygwin the GL (Mesa) libraries and include are already +installed in /usr/X11R6. + +The following will explain how to "replace" them. + +Installation +============ + +How to compile Mesa on Cygwin/X11 systems: + +1. Shared libs: + type 'make cygwin-sl'. + + When finished, the Mesa DLL will be in the Mesa-x.y/lib/ and + Mesa-x.y/bin directories. + + +2. Static libs: + type 'make cygwin-static'. + When finished, the Mesa libraries will be in the Mesa-x.y/lib/ directory. + +Header and library files: + After you've compiled Mesa and tried the demos I recommend the following + procedure for "installing" Mesa. + + Copy the Mesa include/GL directory to /usr/X11R6/include: + cp -a include/GL /usr/X11R6/include + + Copy the Mesa library files to /usr/X11R6/lib: + cp -a lib/* /usr/X11R6ocal/lib + + Copy the Mesa bin files (used by the DLL stuff) to /usr/X11R6/bin: + cp -a lib/cyg* /usr/X11R6/bin + +Xt/Motif widgets: + If you want to use Mesa or OpenGL in your Xt/Motif program you can build + the widgets found in either the widgets-mesa or widgets-sgi directories. + The former were written for Mesa and the later are the original SGI + widgets. Look in those directories for more information. + For the Motif widgets you must have downloaded the lesstif package. + + +Using the library +================= + +Configuration options: + The file src/mesa/main/config.h has many parameters which you can adjust + such as maximum number of lights, clipping planes, maximum texture size, + etc. In particular, you may want to change DEPTH_BITS from 16 to 32 + if a 16-bit depth buffer isn't precise enough for your application. + + +Shared libraries: + If you compile shared libraries (Win32 DLLS) you may have to set an + environment variable to specify where the Mesa libraries are located. + Set the PATH variable to include /your-dir/Mesa-2.6/bin. + Otherwise, when you try to run a demo it may fail with a message saying + that one or more DLL couldn't be found. + + +Xt/Motif Widgets: + Two versions of the Xt/Motif OpenGL drawing area widgets are included: + + widgets-sgi/ SGI's stock widgets + widgets-mesa/ Mesa-tuned widgets + + Look in those directories for details + + +Togl: + Togl is an OpenGL/Mesa widget for Tcl/Tk. + See http://togl.sourceforge.net for more information. + + + +X Display Modes: + Mesa supports RGB(A) rendering into almost any X visual type and depth. + + The glXChooseVisual function tries its best to pick an appropriate visual + for the given attribute list. However, if this doesn't suit your needs + you can force Mesa to use any X visual you want (any supported by your + X server that is) by setting the MESA_RGB_VISUAL and MESA_CI_VISUAL + environment variables. When an RGB visual is requested, glXChooseVisual + will first look if the MESA_RGB_VISUAL variable is defined. If so, it + will try to use the specified visual. Similarly, when a color index + visual is requested, glXChooseVisual will look for the MESA_CI_VISUAL + variable. + + The format of accepted values is: + Here are some examples: + + using the C-shell: + % setenv MESA_RGB_VISUAL "TrueColor 8" // 8-bit TrueColor + % setenv MESA_CI_VISUAL "PseudoColor 12" // 12-bit PseudoColor + % setenv MESA_RGB_VISUAL "PseudoColor 8" // 8-bit PseudoColor + + using the KornShell: + $ export MESA_RGB_VISUAL="TrueColor 8" + $ export MESA_CI_VISUAL="PseudoColor 12" + $ export MESA_RGB_VISUAL="PseudoColor 8" + + +Double buffering: + Mesa can use either an X Pixmap or XImage as the backbuffer when in + double buffer mode. Using GLX, the default is to use an XImage. The + MESA_BACK_BUFFER environment variable can override this. The valid + values for MESA_BACK_BUFFER are: Pixmap and XImage (only the first + letter is checked, case doesn't matter). + + A pixmap is faster when drawing simple lines and polygons while an + XImage is faster when Mesa has to do pixel-by-pixel rendering. If you + need depth buffering the XImage will almost surely be faster. Exper- + iment with the MESA_BACK_BUFFER variable to see which is faster for + your application. + + +Colormaps: + When using Mesa directly or with GLX, it's up to the application writer + to create a window with an appropriate colormap. The aux, tk, and GLUT + toolkits try to minimize colormap "flashing" by sharing colormaps when + possible. Specifically, if the visual and depth of the window matches + that of the root window, the root window's colormap will be shared by + the Mesa window. Otherwise, a new, private colormap will be allocated. + + When sharing the root colormap, Mesa may be unable to allocate the colors + it needs, resulting in poor color quality. This can happen when a + large number of colorcells in the root colormap are already allocated. + To prevent colormap sharing in aux, tk and GLUT, define the environment + variable MESA_PRIVATE_CMAP. The value isn't significant. + + +Gamma correction: + To compensate for the nonlinear relationship between pixel values + and displayed intensities, there is a gamma correction feature in + Mesa. Some systems, such as Silicon Graphics, support gamma + correction in hardware (man gamma) so you won't need to use Mesa's + gamma facility. Other systems, however, may need gamma adjustment + to produce images which look correct. If in the past you thought + Mesa's images were too dim, read on. + + Gamma correction is controlled with the MESA_GAMMA environment + variable. Its value is of the form "Gr Gg Gb" or just "G" where + Gr is the red gamma value, Gg is the green gamma value, Gb is the + blue gamma value and G is one gamma value to use for all three + channels. Each value is a positive real number typically in the + range 1.0 to 2.5. The defaults are all 1.0, effectively disabling + gamma correction. Examples using csh: + + % setenv MESA_GAMMA "2.3 2.2 2.4" // separate R,G,B values + % setenv MESA_GAMMA "2.0" // same gamma for R,G,B + + The demos/gamma.c program may help you to determine reasonable gamma + value for your display. With correct gamma values, the color intensities + displayed in the top row (drawn by dithering) should nearly match those + in the bottom row (drawn as grays). + + Alex De Bruyn reports that gamma values of 1.6, 1.6 and 1.9 work well + on HP displays using the HP-ColorRecovery technology. + + Mesa implements gamma correction with a lookup table which translates + a "linear" pixel value to a gamma-corrected pixel value. There is a + small performance penalty. Gamma correction only works in RGB mode. + Also be aware that pixel values read back from the frame buffer will + not be "un-corrected" so glReadPixels may not return the same data + drawn with glDrawPixels. + + For more information about gamma correction see: + http://www.inforamp.net/~poynton/notes/colour_and_gamma/GammaFAQ.html + + +Overlay Planes + + Overlay planes in the frame buffer are supported by Mesa but require + hardware and X server support. To determine if your X server has + overlay support you can test for the SERVER_OVERLAY_VISUALS property: + + xprop -root | grep SERVER_OVERLAY_VISUALS + + +HPCR glClear(GL_COLOR_BUFFER_BIT) dithering + + If you set the MESA_HPCR_CLEAR environment variable then dithering + will be used when clearing the color buffer. This is only applicable + to HP systems with the HPCR (Color Recovery) system. + + +Extensions +========== + There are three Mesa-specific GLX extensions at this time. + + GLX_MESA_pixmap_colormap + + This extension adds the GLX function: + + GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual, + Pixmap pixmap, Colormap cmap ) + + It is an alternative to the standard glXCreateGLXPixmap() function. + Since Mesa supports RGB rendering into any X visual, not just True- + Color or DirectColor, Mesa needs colormap information to convert RGB + values into pixel values. An X window carries this information but a + pixmap does not. This function associates a colormap to a GLX pixmap. + See the xdemos/glxpixmap.c file for an example of how to use this + extension. + + GLX_MESA_release_buffers + + Mesa associates a set of ancillary (depth, accumulation, stencil and + alpha) buffers with each X window it draws into. These ancillary + buffers are allocated for each X window the first time the X window + is passed to glXMakeCurrent(). Mesa, however, can't detect when an + X window has been destroyed in order to free the ancillary buffers. + + The best it can do is to check for recently destroyed windows whenever + the client calls the glXCreateContext() or glXDestroyContext() + functions. This may not be sufficient in all situations though. + + The GLX_MESA_release_buffers extension allows a client to explicitly + deallocate the ancillary buffers by calling glxReleaseBuffersMESA() + just before an X window is destroyed. For example: + + #ifdef GLX_MESA_release_buffers + glXReleaseBuffersMESA( dpy, window ); + #endif + XDestroyWindow( dpy, window ); + + This extension is new in Mesa 2.0. + + GLX_MESA_copy_sub_buffer + + This extension adds the glXCopySubBufferMESA() function. It works + like glXSwapBuffers() but only copies a sub-region of the window + instead of the whole window. + + This extension is new in Mesa version 2.6 + + + +Summary of X-related environment variables: + MESA_RGB_VISUAL - specifies the X visual and depth for RGB mode (X only) + MESA_CI_VISUAL - specifies the X visual and depth for CI mode (X only) + MESA_BACK_BUFFER - specifies how to implement the back color buffer (X only) + MESA_PRIVATE_CMAP - force aux/tk libraries to use private colormaps (X only) + MESA_GAMMA - gamma correction coefficients (X only) + + +---------------------------------------------------------------------- +README.CYGWIN - lassauge April 2004 - based on README.X11 diff --git a/docs/README.DJ b/docs/README.DJ new file mode 100644 index 0000000..5f783ac --- /dev/null +++ b/docs/README.DJ @@ -0,0 +1,275 @@ + Mesa 6.5 DOS/DJGPP Port v1.8 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + +Description: +~~~~~~~~~~~~ + +Well, guess what... this is the DOS port of Mesa 6.5, for DJGPP fans... Whoa! +The driver uses OSMesa to draw off screen, and then blits the buffer. This is +not terribly efficient, and has some drawbacks, but saves maintenance costs. + + + +Legal: +~~~~~~ + +Mesa copyright applies. + + + +Installation: +~~~~~~~~~~~~~ + +Unzip and type: + + make -f Makefile.DJ [OPTIONS...] + +Available options: + + Environment variables: + CPU optimize for the given processor. + default = pentium + GLIDE path to Glide3 SDK; used with FX. + default = $(TOP)/glide3 + FX=1 build for 3dfx Glide3. Note that this disables + compilation of most DMesa code and requires fxMesa. + As a consequence, you'll need the DJGPP Glide3 + library to build any application. + default = no + X86=1 optimize for x86 (if possible, use MMX, SSE, 3DNow). + default = no + + Targets: + all: build everything + libgl: build GL + libglu: build GLU + libglut: build GLUT + clean: remove object files + realclean: remove all generated files + + + +Tested on: + Video card: Radeon 9500 + DJGPP: djdev 2.04 + gcc v4.1.0 + make v3.80 + OS: DOS, Win98SE, WinXP (using Videoport driver) + + + +FAQ: +~~~~ + +1. Compilation + + Q) `make' barfs and exits because it cannot find some stupid file. + A) You need LFN support. + A) When compiling for Glide (FX=1), pay attention to Glide path. + + Q) Libraries built OK, but linker complains about `vsnprintf' every time I + compile some demo. + A) Upgrade to DJGPP 2.04. + A) Add `vsnprintf.c' to the CORE_SOURCES in `src/Makefile.DJ' (untested!). + A) Patch `src/mesa/main/imports.c' with the following line: + #define vsnprintf(buf, max, fmt, arg) vsprintf(buf, fmt, arg) + This hack should be safe in 90% of the cases, but if anything goes wrong, + don't come back to me crying. + + Q) `make' complains about DXE3 or something, yet it builds the libraries. + A) DXE3 refers to the DJGPP dynamic modules. You'll need either the latest + DJGPP distro, or download the separate package from my web page. Read the + DXE3 documentation on how to use them. + A) When compiling for Glide (FX=1), make sure `glide3x.dxe' can be found in + LD_LIBRARY_PATH (or top `lib' directory). + +2. Using Mesa for DJGPP + + Q) Every test I tried crashes badly. + A) If you have compiled with SSE and you're running under plain DOS, you + have to disable SSE at run-time. See environment variables below. + + Q) DMesa is so SLOOOW! The Win32 OpenGL performs so much better... + A) Is that a question? If you have a 3dfx Voodoo (any model), you're + lucky (check http://sourceforge.net/projects/glide for the DJGPP port). + If you haven't, sorry; everything is done in software. + + Q) I tried to set refresh rate w/ DMesa, but without success. + A) Refresh rate control works only for VESA 3.0 and the 3dfx driver (in + which case FX_GLIDE_REFRESH will be overwritten if it is defined and + is not 0). + + Q) I made a simple application and it does nothing. It exits right away. Not + even a blank screen. + A) Software drivers (VESA/VGA/NUL) must to be constructed as single-buffered + visuals. However, DMesaSwapBuffers must be called to get any output. + A) Another weird "feature" is that buffer width must be multiple of 8 (I'm a + lazy programmer and I found that the easiest way to keep buffer handling + at peak performance ;-). + + Q) I'm getting a "bad font!" fatal error. + A) Always use GLUT_STROKE_* and GLUT_BITMAP_* constants when dealing with + GLUT fonts. If you're using `glut.dxe', then make sure GLUT_STROKE_* and + GLUT_BITMAP_* are mapped to integer constants, not to the actual font + address (same mechanism used for Win32 _DLL). + + Q) What is NUL driver good for, if I don't get any output at all? + A) For debugging. The NUL driver is very much like OSMesa. Everything is + done just the same as VESA/VGA drivers, only it doesn't touch your video + hardware. You can query the actual buffer by issuing: + DMesaGetIntegerv(DMESA_GET_BUFFER_ADDR, &buffer); + and dump it to a file. + + Q) How do I query for a list of available video modes to choose as a visual? + A) This is an ugly hack, for which I'm sure I'll burn in hell. + First, query for a list of modes: + n = DMesaGetIntegerv(DMESA_GET_VIDEO_MODES, NULL); + If `n' is strictly positive, you allocate an array of pointers to a given + struct (which is guaranteed to be extended only - not changed in future): + struct { + int xres, yres; + int bpp; + } **l = malloc(n * sizeof(void *)); + Now pass the newly allocated buffer to fill in: + DMesaGetIntegerv(DMESA_GET_VIDEO_MODES, (GLint *)l); + And collect the info: + for (i = 0; i < n; i++) { + printf("%dx%d:%d\n", l[i]->xres, l[i]->yres, l[i]->bpp); + } + + Q) The GLUT is incomplete. + A) See below. + + + +libGLUT (the toolkit): +~~~~~~~~~~~~~~~~~~~~~~ + +Well, this "skeletal" GLUT implementation was taken from AllegGL project and +heavily changed. Thanks should go to Bernhard Tschirren, Mark Kilgard, Brian +Paul and probably others (or probably not ;-). GLUT functionality will be +extended only on an "as needed" basis. + +GLUT talks to hardware via PC_HW package which was put together from various +pieces I wrote long time ago. It consists from the keyboard, mouse and timer +drivers. + +My keyboard driver used only scancodes; as GLUT requires ASCII values for keys, +I borrowed the translation tables (and maybe more) from Allegro -- many thanks +to Shawn Hargreaves et co. Ctrl-Alt-Del (plus Ctrl-Alt-End, for Windows users) +will shut down the GLUT engine unconditionally: it will raise SIGINT, which in +turn will (hopefully) call the destructors, thus cleaning up your/my mess ;-) +NB: since the DJGPP guys ensured signal handlers won't go beyond program's +space (and since dynamic modules shall) the SIGINT can't be hooked (well, it +can, but it is useless), therefore you must live with the 'Exiting due to +signal SIGINT' message... + +The mouse driver is far from complete (lack of drawing, etc), but is enough to +make almost all the demos work. Supports the CuteMouse WheelAPI. + +The timer is pretty versatile for it supports multiple timers with different +frequencies. While not being the most accurate timer in the known universe, I +think it's OK. Take this example: you have timer A with a very high rate, and +then you have timer B with very low rate compared to A; now, A ticks OK, but +timer B will probably loose precision! + +As an addition, stdout and stderr are redirected and dumped upon exit. This +means that `printf' can be safely called during graphics. A bit of a hack, I +know, because all messages come in bulk, but I think it's better than nothing. +"Borrowed" from LIBRHUTI (Robert Hoehne). + +Window creating defaults: (0, 0, 300, 300), 16bpp. However, the video mode is +chosen in such a way that first window will fit. If you need high resolution +with small windows, set initial position far to the right (or way down); then +you can move them back to any position right before the main loop. + + + +Environment variables: +~~~~~~~~~~~~~~~~~~~~~~ + DMESA_NULDRV - (any value) force NUL driver + GLUT_FPS - print frames/second statistics to stderr + MESA_NO_SSE - (any value) safe option under pure DOS + DMESA_GLUT_REFRESH - set vertical screen refresh rate (VESA3) + DMESA_GLUT_BPP - set default bits per pixel (VGA needs 8) + DMESA_GLUT_ALPHA - set default alpha bits (8) + DMESA_GLUT_DEPTH - set default depth bits (16) + DMESA_GLUT_STENCIL - set default stencil bits (8) + DMESA_GLUT_ACCUM - set default accum bits (16) + + + +History: +~~~~~~~~ + +v1.0 (mar-2002) + initial release + +v1.1 (sep-2002) + + added 3dfx Glide3 support + + added refresh rate control + + added fonts in GLUT + * lots of minor changes + +v1.2 (nov-2002) + * synced w/ Mesa-4.1 + - removed dmesadxe.h + +v1.3 (mar-2003) + + enabled OpenGL 1.4 support + + added MMX clear/blit routines + + enabled SGI's GLU compilation + + added samples makefile + + added new GLUT functions + + added color-index modes + + added Matrox Millennium MGA2064W driver + + added 8bit FakeColor (thanks to Neil Funk) + + added VGA support (to keep Ben Decker happy) + ! fixed some compilation errors (reported by Chan Kar Heng) + * optimized driver for faster callback access... yeah, right :) + * overhauled virtual buffer and internal video drivers + * better fxMesa integration + * revamped GLUT + * switched to DXE3 + +v1.4 (dec-2003) + + enabled GLUT fonts with DXE + + truly added multi-window support in GLUT (for Adrian Woodward) + * accomodated makefiles with the new sourcetree + * fixed some ALPHA issues + * minor changes to PC_HW/timer interface + x hacked and slashed the 3dfx driver (w/ help from Hiroshi Morii) + +v1.5 (jan-2004) + + added interface to query available "visuals" (GLFW - Marcus Geelnard) + + added GLUT timer callback + - removed Matrox Millennium MGA2064W driver + x more changes to the 3dfx driver + +v1.6 (aug-2004) + + implemented NUL driver + + added DMesaGetProcAddress and glutGetProcAddress + * reorganized fxMesa wrapper to handle multiple contexts + ! fixed a horrible bug in VGA initialization routine + ! fixed partial clears + +v1.7 (???-2005) + + enabled OpenGL 2.0 support + + added support for sw texture compression + + added FreeGLUT specific functions + * no more GLX sources in DOS GLUT + * made GLUT timer callbacks less accurate but safer + +v1.8 (apr-2006) + * killed lots of code, the driver is now a front-end to OSMesa + * fixed problem with WinNT (http://www.volny.cz/martin.sulak/) + - removed 3dfx Glide3 support (temporarily?) + + + +Contact: +~~~~~~~~ + +Name: Daniel Borca +E-mail: dborca@users.sourceforge.net +WWW: http://www.geocities.com/dborca/ diff --git a/docs/README.GGI b/docs/README.GGI new file mode 100644 index 0000000..ddb6772 --- /dev/null +++ b/docs/README.GGI @@ -0,0 +1,26 @@ +GGIMesa for LibGGI 2.x + +Requirements: +------------- +LibGGI 2.0 or greater + +Installation: +------------- +To install GGIMesa, follow the instructions in INSTALL.GNU. If you +wish to install GGIGLUT as well, first install GGIMesa and then run + +make +make install (must be root) + +in ggi/ggiglut. + +Notes: +------ + +* Set the environment variables GGIMESA_DEBUG and/or GGIGLUT_DEBUG +to 255 to see lots of debugging output. + +* GGIGLUT contains support for all of the GLUT 3.6 API except for the +high-level primitive drawing functions, but many of the functions (in +particular the menu drawing functions) are just stubs. + diff --git a/docs/README.LYNXOS b/docs/README.LYNXOS new file mode 100644 index 0000000..e3ab980 --- /dev/null +++ b/docs/README.LYNXOS @@ -0,0 +1,64 @@ + +Mesa 3.0 for LynxOS builds in the following way: + +make lynxos + +This will build all the libraries and demo applications. You should have +around 400 megabytes free for everything since everything is done with +static +libraries. + +Before using this make file however, you should perform the following +actions: +0) cd to the Mesa-3.0 directory +1) Copy the GL directory under the include directory to /usr/include. +2) Copy the files in the lib directory to /lib. +3) Make links so that the Mesa libraries look like ordinary OpenGL +libraries +in /lib. This is important for compatibility with other OpenGL apps. This +is done as follows: + +cd /lib +ln -s libMesaGL.a libGL.a +ln -s libMesaGLU.a libGLU.a + +Mesa 3.0 includes the GLUT (GL Utility Toolkit) by default. +The demo applications are done using this toolkit. + +Mesa makefiles for building their apps could be used as well, but the +following one is much more concise. Note that the order of the X libraries +is important to the linker so that all symbols get resolved correctly. +Changing the order may result in having to list a library twice to make +sure all linkages are made correctly. + +----cut here for Makefile ----- + +FILES = your_app.x + +SPECIAL_INCLUDES = -I/usr/include/GL + +SPECIAL_CFLAGS = -g -ansi -pedantic -funroll-loops -ffast-math -DSHM + +SPECIAL_LIBS = -lglut -lGLU -lGL -lm -L/usr/X11/lib -lXext -lXmu -lXi \ +-lX11 -lbsd -g + +STANDARD_OFILES = $(FILES:.x=.o) + +%.o: %.c + gcc -c $(SPECIAL_CFLAGS) $(SPECIAL_INCLUDES) $< -o $@ + +all: $(STANDARD_OFILES) + gcc -o your_app $(STANDARD_OFILES) $(SPECIAL_LIBS) + + +----cut here for Makefile----- + +I have tested Mesa under LynxOS 3.0 and 3.01. It should build fine under +other +versions as well. Note, however, that LynxOS versions prior to 3.0 are not +binary compatible, so you will have to rebuild from source. + + +Vik Sohal +vik@lynx.com +January 13, 1999 diff --git a/docs/README.MINGW32 b/docs/README.MINGW32 new file mode 100644 index 0000000..9477b2b --- /dev/null +++ b/docs/README.MINGW32 @@ -0,0 +1,153 @@ + Mesa 6.1 for MinGW32 + ~~~~~~~~~~~~~~~~~~~~ + + + +Quick & dirty start: +-------------------- + + mingw32-make -f Makefile.mgw [OPTIONS...] + + Look into the corresponding makefiles for further information. + Check README.3DFX to find out how to compile Mesa Glide3 driver + with MinGW32! + + + +******************************************************************************* +The Mingw port for Mesa 3-D Graphics Library was created August 30, 1998 by Paul Garceau. + +Updated January 13, 2000; June 3, 2005 -- Paul Garceau + +DISCLAIMER: I make this port of the Mesa 3-D Graphics Library as a service +to the general public. I can, in no way support or make any guarantee that the +build will work for your system. + +Acknowledgements: + + Daniel Borca, whose work and commitment to maintaining the Mingw port of the Mesa 3-D Graphics Library has been, and will continue to be greatly appreciated by an overworked and underpaid developer such as myself. + Without the creative inspiration and personal commitment provided by Mumit Khan, Jan-Jaap Vanderhagen and Colin Peters, Mingw would never have existed. Acknowledgements also need to be given to all of the developers who have worked on Mingw, Mesa and Msys over the years. + Last, but certainly far from the least, Brian Paul, who has dedicated at least the last seven or eight years of his life to making Mesa 3-D Graphics Library what it is today and managing the development for all of those years. +********************************************************************************* + +Greetings, + + Feel free to modify or change things related to the Mingw build as you see fit, just remember that, the author of the current build may not be able to support any modifications you might want to make to the files which have been included for the build. + +Mesa core components are licensed under XFree-86 (for more on licensing of Mesa 3-D Graphics Library, check out the Mesa homepage (http://www.mesa3d.org). + +The Mingw generated libraries themselves are licensed under the GNU-LGPL license. Source code for Mingw can be found at http://www.mingw.org. For licensing terms on Mingw, please visit http://www.mingw.org. + + It is recommended that you use the latest "stable" release of Mingw. "Candidates" are beta testing distributions for Mingw. Mingw is available at http://www.mingw.org. + + This build has been tested under WinNT4/SP6. Win9x and WinNT5 remain untested by me. I have not tested any of the demos included with Mesa3d. + +Installation: + + This readme assumes that you already have extracted the necessary files to a working directory/folder that Mingw can use to build the Mesa3D libraries and that you know where that directory/folder is located on your Windows system. If you have any questions about how to set things up properly which is specific to Mesa3D, the folks on the Mesa3D mailing lists (http://www.mesa3d.org) would probably be happy to assist you. Also you can probably ask anyone on the Mingw mailing lists for any questions specific to Mingw (http://www.mingw.org) + +Targets and Environment variables used for Mingw build: + + Before going into the actual build of the libraries, here is a list of available targets for the make process: + + "all" or "libgl" -- this target will build libopengl.a, a static library. It will not build the demos, etc. + + clean -- this target will clean up most of the Mesa 3-D Graphics Library/object code from your hard drive. + + realclean -- this target will clean up all of the Mesa 3D Graphics Library and the Mesa object code that it can find. + + Environment Variables: + + The environment variables are used to determine what sort of graphics driver support needs to be included in the finished Mesa 3-D Graphics Library. + + GLIDE path to Glide3 SDK; used with FX. + default = $(TOP)/glide3 + FX=1 build for 3dfx Glide3. Note that this disables + compilation of most WMesa code and requires fxMesa. + As a consequence, you'll need the Win32 Glide3 + library to build any application. + default = no + ICD=1 build the installable client driver interface + (windows opengl driver interface) + default = no + X86=1 optimize for x86 (if possible, use MMX, SSE, 3DNow). + default = no + + +Running the Build: + + Launch Mingw. + From the Windows Command Prompt: + Set Environment Variables (as needed). + "cd" to your Mesa3D 'root' directory. + Enter "mingw32-make -f makefile.mgw + + That's all there is to it. + + Enjoy! + + Paul G. + Daniel Borca + + + +******This section is added by Heromyth ************* + +==================== +Updated on 2007-7-21 +==================== + +Notice: + 1) The generated DLLs are *not* compatible with the ones built +with the other compilers like VC8, especially for GLUT. + + 2) Although more tests are needed, it can be used individually! + + 3) You can set the options about whether using STDCALL to build MESA. The +config file is \configs\config.mgw. The default setting is that: + ALL_USING_STDCALL = 1 +, which means using STDCALL to build MESA. + + 4) Of course, you can MESA without using STDCALL,I like this:) +The setting is : + ALL_USING_STDCALL = 0 +To do this, however, you must modify wingdi.h which is in MingW's include dir. +For example, run: + notepad C:\MingW\include\wingdi.h +, and delete all the lines where all the wgl*() functions are. Because they would +be conflicted with the ones in \include\GL\mesa_wgl.h. + +>>>>>>>>>> Conflicted Functions List >>>>>>>>>> +WINGDIAPI BOOL WINAPI wglCopyContext(HGLRC,HGLRC,UINT); +WINGDIAPI HGLRC WINAPI wglCreateContext(HDC); +WINGDIAPI HGLRC WINAPI wglCreateLayerContext(HDC,int); +WINGDIAPI BOOL WINAPI wglDeleteContext(HGLRC); +WINGDIAPI BOOL WINAPI wglDescribeLayerPlane(HDC,int,int,UINT,LPLAYERPLANEDESCRIPTOR); +WINGDIAPI HGLRC WINAPI wglGetCurrentContext(void); +WINGDIAPI HDC WINAPI wglGetCurrentDC(void); +WINGDIAPI int WINAPI wglGetLayerPaletteEntries(HDC,int,int,int,COLORREF*); +WINGDIAPI PROC WINAPI wglGetProcAddress(LPCSTR); +WINGDIAPI BOOL WINAPI wglMakeCurrent(HDC,HGLRC); +WINGDIAPI BOOL WINAPI wglRealizeLayerPalette(HDC,int,BOOL); +WINGDIAPI int WINAPI wglSetLayerPaletteEntries(HDC,int,int,int,const COLORREF*); +WINGDIAPI BOOL WINAPI wglShareLists(HGLRC,HGLRC); +WINGDIAPI BOOL WINAPI wglSwapLayerBuffers(HDC,UINT); +WINGDIAPI BOOL WINAPI wglUseFontBitmapsA(HDC,DWORD,DWORD,DWORD); +WINGDIAPI BOOL WINAPI wglUseFontBitmapsW(HDC,DWORD,DWORD,DWORD); +WINGDIAPI BOOL WINAPI wglUseFontOutlinesA(HDC,DWORD,DWORD,DWORD,FLOAT,FLOAT,int,LPGLYPHMETRICSFLOAT); +WINGDIAPI BOOL WINAPI wglUseFontOutlinesW(HDC,DWORD,DWORD,DWORD,FLOAT,FLOAT,int,LPGLYPHMETRICSFLOAT); +<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +==================== +Updated on 2007-7-22 +==================== + I havn't thought that I would find a better way to solve my problems so soon. +I changed the method in which the import-libs and DLLs are made. After this update, +the DLLs of MESA are more optimized and more compatible. + It seems that there is no need to keep the building way of 'NO-STDCALL'.The +way of USING_STDCALL is so nice! The file \configs\config.mgw is +also not needed, and can be deleted safely! + + + +********************************************************************************* \ No newline at end of file diff --git a/docs/README.MITS b/docs/README.MITS new file mode 100644 index 0000000..a89176a --- /dev/null +++ b/docs/README.MITS @@ -0,0 +1,102 @@ + + Mesa 3.0 MITS Information + + +This software is distributed under the terms of the GNU Library +General Public License, see the LICENSE file for details. + + +This document is a preliminary introduction to help you get +started. For more detaile information consult the web page. + +http://10-dencies.zkm.de/~mesa/ + + + +Version 0.1 (Yes it's very alpha code so be warned!) +Contributors: + Emil Briggs (briggs@bucky.physics.ncsu.edu) + David Bucciarelli (tech.hmw@plus.it) + Andreas Schiffler (schiffler@zkm.de) + + + +1. Requirements: + Mesa 3.0. + An SMP capable machine running Linux 2.x + libpthread installed on your machine. + + +2. What does MITS stand for? + MITS stands for Mesa Internal Threading System. By adding + internal threading to Mesa it should be possible to improve + performance of OpenGL applications on SMP machines. + + +3. Do applications have to be recoded to take advantage of MITS? + No. The threading is internal to Mesa and transparent to + applications. + + +4. Will all applications benefit from the current implementation of MITS? + No. This implementation splits the processing of the vertex buffer + over two threads. There is a certain amount of overhead involved + with the thread synchronization and if there is not enough work + to be done the extra overhead outweighs any speedup from using + dual processors. You will not for example see any speedup when + running Quake because it uses GL_POLYGON and there is only one + polygon for each vertex buffer processed. Test results on a + dual 200 Mhz. Pentium Pro system show that one needs around + 100-200 vertices in the vertex buffer before any there is any + appreciable benefit from the threading. + + +5. Are there any parameters that I can tune to try to improve performance. + Yes. You can try to vary the size of the vertex buffer which is + define in VB_MAX located in the file src/vb.h from your top level + Mesa distribution. The number needs to be a multiple of 12 and + the optimum value will probably depend on the capabilities of + your machine and the particular application you are running. + + +6. Are there any ways I can modify the application to improve its + performance with the MITS? + Yes. Try to use as many vertices between each Begin/End pair + as possbile. This will reduce the thread synchronization + overhead. + + +7. What sort of speedups can I expect? + On some benchmarks performance gains of up to 30% have been + observerd. Others may see no gain at all and in a few rare + cases even some degradation. + + +8. What still needs to be done? + Lots of testing and benchmarking. + A portable implementation that works within the Mesa thread API. + Threading of additional areas of Mesa to improve performance + even more. + + + +Installation: + + 1. This assumes that you already have a working Mesa 3.0 installation + from source. + 2. Place the tarball MITS.tar.gz in your top level Mesa directory. + 3. Unzip it and untar it. It will replace the following files in + your Mesa source tree so back them up if you want to save them. + + + README.MITS + Make-config + Makefile + mklib.glide + src/vbxform.c + src/vb.h + + 4. Rebuild Mesa using the command + + make linux-386-glide-mits + diff --git a/docs/README.NeXT b/docs/README.NeXT new file mode 100644 index 0000000..1ad9a9e --- /dev/null +++ b/docs/README.NeXT @@ -0,0 +1,6 @@ +The NeXT support has now been incorporated into the OpenStep support. +You can build NeXT libraries simply by typing "make next", though before +linking they will need to be ranlib'd by hand. For more information see +the README.OpenStep file, together with the README files in OpenStep/Old_Demos. + +-Pete French. (pete@ohm.york.ac.uk) 28/5/1998 diff --git a/docs/README.OS2 b/docs/README.OS2 new file mode 100644 index 0000000..b3374ea --- /dev/null +++ b/docs/README.OS2 @@ -0,0 +1,96 @@ + README for port of Mesa 3.x to XFree86 on OS/2 (X/2) + (as of 19990514) + + + Contents: + + 1) Binary release + 2) Building from sources + 3) History + 4) Todo + 5) Mesa Home Page + + +1) Binary release + + Though the Mesa sources should build in a quite reasonable time even on + a 585 class machine a binary relase is available (check topic 4) for an URL) + This package includes: + + - lib/MesaGL.dll, MesaGL.a + - lib/MesaGLU.dll, MesaGLU.a + - lib/glut.dll, glut.a + - include/GL/*.h + + Installing this in your XFree86 tree will enable you to build and + run all applications compatible with Mesa (and the current DLL + interface, of course ;-) + As usual the OMF-style libraries can be created using emxomf. + (e.g. "emxomf foo.a" creates the foo.lib omf-style library). + The static libraries are rarely used and you have to rebuild + Mesa to get them. They're a supported target, so you get + them in a straightforward way (see below). + + The testing of these libraries was limited to the supplied + demos/examples and a quite small number of third-party apps. + No warranty ... as usual ... ;-) + + +2) Instructions to build Mesa 3.x for XFree86/OS2 from sources: + + Except the official Mesa source distribution you need: + - a recent version of XFree86 (3.3.x or above) including + the programming libraries + - EMX 0.9c (0.9d might work, never checked) + - GNU make + - REXX (!) + + The creation of the DLLs as well as of the static libraries + (if you want to have them) is handled in "mklib-emx.cmd", + a small REXX script. Perhaps not the best idea, but this + way it fits best in the scheme used to build libraries + on all platforms in Mesa 3.x. + + To actually build the libraries and demos, check mklib-emx.cmd + and modify it as desired. Then type + make os2-x11 + and wait for completion ;-) + + +3) History + + Initially Darren Abbott (abbott@hiwaay.net) ported Mesa versions 2.x + to XFree86 OS/2. This port might still be available from + http://fly.HiWAAY.net/~abbott/xfree86-os2/xfree86.html + + The current port picked up things during the beta test for 3.0. + No major changes in the source were done. The build mechanism under OS/2 + has been made very similar to other platforms (if you treat mklib-emx.cmd + as a "black box"). + Advantage is that X/2 is now a valid target and all files are + integrated in the official source distribution. + Disadvantage is that this port (i.e. the DLLs' interface itself) is + definitly NOT COMPATIBLE to those of version 2.x. + It's uncertain whether this would be at all possible but since there + a _very_ few those apps it's not worth to find out anyway. + Also some libs (MesaTK, MesaAUX) are withdrawn from the Mesa distribution, + and accordingly from the OS/2 port. + +4) Todo + + By now binary compatiblity is ensured by using the function names + as entry points instead of ordinals. This might cost performance and + is subject to change in future. In addition the supplied X86 assembler + source is not used yet. + +5) Mesa Home Page + + You can get the source code and more information about Mesa from + http://www.mesa3d.org/ + + The OS/2 ports should be available from + http://r350.ee.ntu.edu.tw/~hcchu/os2/ports + +-- +Alexander Mai +st002279@hrzpub.tu-darmstadt.de diff --git a/docs/README.OpenStep b/docs/README.OpenStep new file mode 100644 index 0000000..a566eca --- /dev/null +++ b/docs/README.OpenStep @@ -0,0 +1,35 @@ +This is a port of the GL and GLU libraries to NeXT/Apple object +orientated systems. As these systems have their own window handling +systems we simply use the offscreen rendering capability of Mesa +to generate bitmaps which may then be displayed by the application +with a View as required. Example pieces of code may be found in the +OpenStep directory. + +Sadly there are now a proliferation of different system that we need to +support compilation for: The original NextStep system, The OpenStep +system, the Rhapsody/Mac OS X system and also the windows implementations +of the latter two systems. This version of the code has been compiled and +tested under the following architectures: + + NextStep 3.3 + OpenStep 4.2 + Rhapsody DR2 + WebObjects for NT 3.5 + WebObjects for NT 4.0 + +All tests were done with Intel processors. Feedback on other systems would, +however, be appreciated ! + +On UNIX systems simply type "make openstep". Under Windows systems +with WebObjects run the "win32-openstep.sh" script from within the Bourne +shell provided with the development environment. In both cases this will +build the libraries and place them into the "lib" directory. Some examples +may be found in the OpenStep directory showing how to use the code in an +actual application (MesaView) as well as some command line demos. + +The CC variable may be specified on the command line for doing such things +as building FFAT libraries or using alternative compilers to the standard 'cc' +e.g. make CC='cc -arch m68k -arch i386' openstep" will build the libraries +with both intel and motorola architectures. + +-Pete French. (pete@ohm.york.ac.uk) 7/6/1999 diff --git a/docs/README.QUAKE b/docs/README.QUAKE new file mode 100644 index 0000000..e90c76a --- /dev/null +++ b/docs/README.QUAKE @@ -0,0 +1,207 @@ + + Info on using Mesa 3.0 with Linux Quake I and Quake II + + + +Disclaimer +---------- + +I am _not_ a Quake expert by any means. I pretty much only run it to +test Mesa. There have been a lot of questions about Linux Quake and +Mesa so I'm trying to provide some useful info here. If this file +doesn't help you then you should look elsewhere for help. The Mesa +mailing list or the news://news.3dfx.com/3dfx.linux.glide newsgroup +might be good. + +Again, all the information I have is in this file. Please don't email +me with questions. + +If you have information to contribute to this file please send it to +me at brianp@elastic.avid.com + + + +Linux Quake +----------- + +You can get Linux Quake from http://www.idsoftware.com/ + +Quake I and II for Linux were tested with, and include, Mesa 2.6. You +shouldn't have too many problems if you simply follow the instructions +in the Quake distribution. + + + +RedHat 5.0 Linux problems +------------------------- + +RedHat Linux 5.x uses the GNU C library ("glibc" or "libc6") whereas +previous RedHat and other Linux distributions use "libc5" for its +runtime C library. + +Linux Quake I and II were compiled for libc5. If you compile Mesa +on a RedHat 5.x system the resulting libMesaGL.so file will not work +with Linux Quake because of the different C runtime libraries. +The symptom of this is a segmentation fault soon after starting Quake. + +If you want to use a newer version of Mesa (like 3.x) with Quake on +RedHat 5.x then read on. + +The solution to the C library problem is to force Mesa to use libc5. +libc5 is in /usr/i486-linux-libc5/lib on RedHat 5.x systems. + +Emil Briggs (briggs@tick.physics.ncsu.edu) nicely gave me the following +info: + +> I only know what works on a RedHat 5.0 distribution. RH5 includes +> a full set of libraries for both libc5 and glibc. The loader ld.so +> uses the libc5 libraries in /usr/i486-linux-libc5/lib for programs +> linked against libc5 while it uses the glibc libraries in /lib and +> /usr/lib for programs linked against glibc. +> +> Anyway I changed line 41 of mklib.glide to +> GLIDELIBS="-L/usr/local/glide/lib -lglide2x -L/usr/i486-linux-libc5/lib" +> +> And I started quake2 up with a script like this +> #!/bin/csh +> setenv LD_LIBRARY_PATH /usr/i486-linux-libc5/lib +> setenv MESA_GLX_FX f +> ./quake2 +set vid_ref gl +> kbd_mode -a +> reset + + +I've already patched the mklib.glide file. You'll have to start Quake +with the script shown above though. + + + +********************** + +Daryll Strauss writes: + +Here's my thoughts on the problem. On a RH 5.x system, you can NOT build +a libc5 executable or library. Red Hat just doesn't include the right +stuff to do it. + +Since Quake is a libc5 based application, you are in trouble. You need +libc5 libraries. + +What can you do about it? Well there's a package called gcc5 that does +MOST of the right stuff to compile with libc5. (It brings back older +header files, makes appropriate symbolic links for libraries, and sets +up the compiler to use the correct directories) You can find gcc5 here: +ftp://ecg.mit.edu/pub/linux/gcc5-1.0-1.i386.rpm + +No, this isn't quite enough. There are still a few tricks to getting +Mesa to compile as a libc5 application. First you have to make sure that +every compile uses gcc5 instead of gcc. Second, in some cases the link +line actually lists -L/usr/lib which breaks gcc5 (because it forces you +to use the glibc version of things) + +If you get all the stuff correctly compiled with gcc5 it should work. +I've run Mesa 3.0B6 and its demos in a window with my Rush on a Red Hat +5.1 system. It is a big hassle, but it can be done. I've only made Quake +segfault, but I think that's from my libRush using the wrong libc. + +Yes, mixing libc5 and glibc is a major pain. I've been working to get +all my libraries compiling correctly with this setup. Someone should +make an RPM out of it and feed changes back to Brian once they get it +all working. If no one else has done so by the time I get the rest of my +stuff straightened out, I'll try to do it myself. + + - |Daryll + + + +********************* + +David Bucciarelli (tech.hmw@plus.it) writes: + +I'm using the Mesa-3.0beta7 and the RedHat 5.1 and QuakeII is +working fine for me. I had only to make a small change to the +Mesa-3.0/mklib.glide file, from: + + + GLIDELIBS="-L/usr/local/glide/lib -lglide2x +-L/usr/i486-linux-libc5/lib -lm" + +to: + + GLIDELIBS="-L/usr/i486-linux-libc5/lib -lglide2x" + +and to make two symbolic links: + +[david@localhost Mesa]$ ln -s libMesaGL.so libMesaGL.so.2 +[david@localhost Mesa]$ ln -s libMesaGLU.so libMesaGLU.so.2 + +I'm using the Daryll's Linux glide rpm for the Voodoo2 and glibc (it +includes also the Glide for the libc5). I'm not using the /dev/3Dfx and +running QuakeII as root with the following env. var: + +export +LD_LIBRARY_PATH=/dsk1/home/david/src/gl/Mesa/lib:/usr/i486-linux-libc5/lib + +I think that all problems are related to the glibc, Quake will never +work if you get the following output: + +[david@localhost Mesa]$ ldd lib/libMesaGL.so + libglide2x.so => /usr/lib/libglide2x.so (0x400f8000) + libm.so.6 => /lib/libm.so.6 (0x40244000) + libc.so.6 => /lib/libc.so.6 (0x4025d000) + /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00000000) + +You must get the following outputs: + +[david@localhost Mesa]# ldd lib/libMesaGL.so + libglide2x.so => /usr/i486-linux-libc5/lib/libglide2x.so +(0x400f3000) + +[root@localhost quake2]# ldd quake2 + libdl.so.1 => /lib/libdl.so.1 (0x40005000) + libm.so.5 => /usr/i486-linux-libc5/lib/libm.so.5 (0x40008000) + libc.so.5 => /usr/i486-linux-libc5/lib/libc.so.5 (0x40010000) + +[root@localhost quake2]# ldd ref_gl.so + libMesaGL.so.2 => +/dsk1/home/david/src/gl/Mesa/lib/libMesaGL.so.2 (0x400eb000) + libglide2x.so => /usr/i486-linux-libc5/lib/libglide2x.so +(0x401d9000) + libX11.so.6 => /usr/i486-linux-libc5/lib/libX11.so.6 +(0x40324000) + libXext.so.6 => /usr/i486-linux-libc5/lib/libXext.so.6 +(0x403b7000) + libvga.so.1 => /usr/i486-linux-libc5/lib/libvga.so.1 +(0x403c1000) + libm.so.5 => /usr/i486-linux-libc5/lib/libm.so.5 (0x403f5000) + libc.so.5 => /usr/i486-linux-libc5/lib/libc.so.5 (0x403fd000) + + +*********************** + +Steve Davies (steve@one47.demon.co.uk) writes: + + +Try using: + + export LD_LIBRARY_PATH=/usr/i486-linux-libc5/lib + ./quake2 +set vid_ref gl + +to start the game... Works for me, but assumes that you have the +compatability libc5 RPMs installed. + + +*************************** + +WWW resources - you may find additional Linux Quake help at these URLs: + + +http://quake.medina.net/howto + +http://webpages.mr.net/bobz + +http://www.linuxgames.com/quake2/ + + + +---------------------------------------------------------------------- diff --git a/docs/README.THREADS b/docs/README.THREADS new file mode 100644 index 0000000..fb6e0ff --- /dev/null +++ b/docs/README.THREADS @@ -0,0 +1,52 @@ + + +Mesa Threads README +------------------- + +Thread safety was introduced in Mesa 2.6 by John Stone and +Christoph Poliwoda. + +It was redesigned in Mesa 3.3 so that thread safety is +supported by default (on systems which support threads, +that is). There is no measurable penalty on single +threaded applications. + +NOTE that the only _driver_ which is thread safe at this time +is the OS/Mesa driver! + + +At present the mthreads code supports three thread APIS: + 1) POSIX threads (aka pthreads). + 2) Solaris / Unix International threads. + 3) Win32 threads (Win 95/NT). + +Support for other thread libraries can be added src/glthread.[ch] + + +In order to guarantee proper operation, it is +necessary for both Mesa and application code to use the same threads API. +So, if your application uses Sun's thread API, then you should build Mesa +using one of the targets for Sun threads. + +The mtdemos directory contains some example programs which use +multiple threads to render to osmesa rendering context(s). + +Linux users should be aware that there exist many different POSIX +threads packages. The best solution is the linuxthreads package +(http://pauillac.inria.fr/~xleroy/linuxthreads/) as this package is the +only one that really supports multiprocessor machines (AFAIK). See +http://pauillac.inria.fr/~xleroy/linuxthreads/README for further +information about the usage of linuxthreads. + +If you are interested in helping with thread safety work in Mesa +join the Mesa developers mailing list and post your proposal. + + +Regards, + John Stone -- j.stone@acm.org johns@cs.umr.edu + Christoph Poliwoda -- poliwoda@volumegraphics.com + + +Version info: + Mesa 2.6 - initial thread support. + Mesa 3.3 - thread support mostly rewritten (Brian Paul) diff --git a/docs/README.VMS b/docs/README.VMS new file mode 100644 index 0000000..6b02909 --- /dev/null +++ b/docs/README.VMS @@ -0,0 +1,38 @@ + +VMS support contributed by Jouk Jansen (joukj@hrem.stm.tudelft.nl) + + +The latest version was tested on a VMSAlpha7.2 system using DECC6.0, but +probably also works for other versions. + +At the moment only the libraries LIBMESGL.EXE/LIBMESGL.OLB, +LIBMESAGLU.EXE/LIBMESAGLU.OLB and LIBGLUT.EXE/LIBGLUT.OLB and the demos of the +directory [.DEMOS] can be build. +However, feel free to create the missing "decrip.mms-files" in the other +directories. + + The make files were tested +using the DIGITAL make utility called MMS. There is also a public domain +clone available (MMK) and I think, but it is not tested, that this +utility will give (hardly) any problem. + +To make everything just type MMS (or MMK) in the main directory of +mesagl. For MMS the deafult makefile is called descrip.mms, and +that is what I have called it. I included alse some config files, +all having mms somewhere in the name which all the makefiles need +(just as your unix makefiles). + +On Alpha platforms at default a sharable images for the libraries are created. +To get a static library make it by typing MMS/MACRO=(NOSHARE=1). +On VAX platforms only static libraries can be build. + +23-sep-2005 +changed default compilation to use /float=ieee/ieee=denorm. The reason for +this is that it makes Mesa on OpenVMS better compatible with other platforms +and other packages for VMS that I maintain. +For more information see + http://nchrem.tnw.tudelft.nl/openvms + https://bugs.freedesktop.org/show_bug.cgi?id=4270 +You may want to compile Mesa to use VAX-floating point arithmetic, instead +of IEEE floating point by removing the /float=IEEE/denorm flag from the +compiler options in the descrip.mms files. diff --git a/docs/README.WIN32 b/docs/README.WIN32 new file mode 100644 index 0000000..204b8e6 --- /dev/null +++ b/docs/README.WIN32 @@ -0,0 +1,140 @@ +File: docs/README.WIN32 + +Last updated: Apr 25, 2007 - Karl Schultz - kschultz@users.sourceforge.net + +Quick Start +----- ----- + +Unzip the MesaLib, MesaGLUT, and MesaDemos ZIP files into the same +directory. The libs and demos build separately, so if you do not care +about the demos or GLUT, you only need to unzip MesaLib. If you unzip +more than one ZIP file, they all need to be unzipped into the same +directory. Don't worry, you will not overwrite anything. + +The Windows build system uses Microsoft Visual Studio. Project files +for a specific version of Visual Studio are in their own directory in +the top-level "windows" directory. For example, Visual Studio 8 files +are in windows/VC8. + +Support has been dropped for versions of Visual Studio prior to 8. The +main reason is because Microsoft now provides a free compiler and +developer environment. Visual Studio Express can be found at + +http://msdn.microsoft.com/vstudio/express/visualc/default.aspx + +You'll also need the Platform SDK. Instructions for obtaining and +using the SDK with Visual Studio Express can be found at + +http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/ + +The project files to build the core Mesa library, Windows Mesa +drivers, OSMesa, and GLU are in the mesa directory. The project files +to build GLUT and some demo programs are in the progs directory. + +Makefiles are no longer shipped or supported, but can be generated +from the projects using Visual Studio. + + +Windows Drivers +------- ------- + +At this time, only the GDI driver is known to work. Most of the demos +in progs/demos should work with this driver. + +Source code also exists in the tree for other drivers in +src/mesa/drivers/windows, but the status of this code is unknown. + +The GDI driver operates basically by writing pixel spans into a DIB +section and then blitting the DIB to the window. The driver was +recently cleaned up and rewitten and so may have bugs or may be +missing some functionality. The older versions of the CVS source may +be useful in figuring out any problems, or report them to me. + +To build Mesa with the GDI driver, build the mesa, gdi, and glu +projects in the Visual Studio workspace found at + + windows/VC8/mesa/mesa.sln + +The osmesa DLL can also be built with the osmesa project. + +The build system creates a lib top-level directory and copies +resulting LIB and DLL files to this lib directory. The files are: + + OPENGL32.LIB, GLU32.LIB, OSMESA32.LIB + OPENGL32.DLL, GLU32.DLL, OSMESA32.DLL + +If the MesaDemos ZIP file was extracted, the DLL files are also copied +to the demos directory. This facilitates running the demos as described +below. + + +GLUT and Demos +---- --- ----- + +A Visual Studio workspace can be found at + + windows/VC8/progs/progs.sln + +It can be used to build GLUT and a few demos. The GLUT lib and DLL +are copied to the top-level lib directory, along with the Mesa libs. + +The demo build system expects to find the LIB files in the top level +lib directory, so you must build the Mesa libs first. The demo +executables are placed in the demos directory, because some of them +rely on data files found there. Also, the Mesa lib DLL's were copied +there by the Mesa lib build process. Therefore, you should be able to +simply run the demo executables from the demo directory. + +If you want to run the demos from the Visual Studio, you may have to +change the startup directory and explicitly state where the executables are. + +You may also build all the demo programs by using a makefile. Go to +the progs/demos directory and make sure you have executed VCVARS32.BAT +or whatever setup script is appropriate for your compiler. Then, + + nmake -f Makefile.win + +should build all the demos. + + +Build System Notes +----- ------ ----- + +VC8 +--- + +No notes. + + +General +------- + +After building, you can copy the above DLL files to a place in your +PATH such as $SystemRoot/SYSTEM32. If you don't like putting things +in a system directory, place them in the same directory as the +executable(s). Be careful about accidentially overwriting files of +the same name in the SYSTEM32 directory. + +The DLL files are built so that the external entry points use the +stdcall calling convention. + +Static LIB files are not built. The LIB files that are built with are +the linker import files associated with the DLL files. + +The si-glu sources are used to build the GLU libs. This was done +mainly to get the better tessellator code. + +To build "mangled" Mesa, add the preprocessor define USE_MGL_NAMESPACE +to the project settings. You will also need to edit src/mesa.def to +change all the gl* symbols to mgl*. Because this is easy to do with a +global replace operation in a text editor, no additional mangled +version of mesa.def is maintained or shipped. + +If you have a Windows-related build problem or question, it is +probably better to direct it to me (kschultz@users.sourceforge.net), +rather than directly to the other Mesa developers. I will help you as +much as I can. I also monitor the Mesa mailing lists and will answer +questions in this area there as well. + + +Karl Schultz diff --git a/docs/README.WINDML b/docs/README.WINDML new file mode 100644 index 0000000..448db71 --- /dev/null +++ b/docs/README.WINDML @@ -0,0 +1,146 @@ + + WindML Driver for Mesa 4.0 + + +Requirements +------------ + +Tornado 2 + WindML, Cumulative Patchs are recommended. + +I suppose you have a valid WindML installation. Double buffer hardware +gives better performance than double buffer software so if you can +compile your WindML driver with this option, just do it. I/O +redirection is adviced in target server. + + +Tested on +--------- + +During the development, my main target was a CoolMonster: +- Video card: CT69000 +- CPU: PENTIUM 266MHz + +and my host a Windows NT + Tornado 2. + + +Installation +------------ + +1. Mesa sources must be in root directory (C:\) + +2. Add the following line to your torVars.bat: +set MESA_BASE=C:\Mesa + +OR copy the new torVars.bat in your bin path: +c:/Mesa/src/ugl/tornado/torVars.sample -> +/mnt/nt/Tornado/host/x86-win32/bin/torVars (for example) + +3. In a command prompt: +$ torVars +$ cd c:\Mesa +$ make -f Makefile.ugl CPU=PENTIUM + +Take a long while... + +5. Include all the files from ugldemos folder to build some downloadable + application modules + +4. Download UGL/Mesa object files on target + +For example via the WindShell: +ld < c:\Tornado\target\lib\objMesaGL.o +ld < c:\Tornado\target\lib\objMesaUGL.o +ld < c:\Tornado\target\lib\objMesaGLU.o +ld < c:\Tornado\target\lib\objGLUTshapes.o +ld < c:\Tornado\target\lib\objMesaOS.o + +You can put the previous lines in a file and use: +< filename + +6. Download the application modules. + +7. In WindShell, run: +-> uglalldemos + +During the show some messages will appear, it provides some useful +information on key management. + + +Coding +------ + +Sample Usage: + +In addition to the usual ugl calls to initialize UGL, (may be find an +input driver), you must do the following to use the UGL/Mesa interface: + +1. Call uglMesaCreateContext() to create a UGL/Mesa rendering context, + given the display format. + +2. Call uglMesaMakeCurrent() to bind the UGL/Mesa buffers to an + UGL/Mesa Context and to make the context the current one. + +3. Make gl* calls to render your graphics. + +4. Use uglMesaSwapBuffers() when double buffering to swap front/back buffers. + +5. Before the UGL is destroyed, call MesaDestroyContext(). + +6. Before exiting, call if required uglEventQDestroy and then + uglDeinitialize(); + +Limitations +----------- + +I found the following limitations in my driver : + - Color Indexed management is only in 8 bits + - It's possible to mix UGL/OpenGL application with a software + double buffer + +Modifications +------------ + +New files in Mesa: +- Makefile.ugl +- rules.windmlmesa +- docs/README.UGL +- include/GL/uglmesa.h +- si-glu/Makefile.ugl +- src/Makefile.ugl +- src/ugl/torGLUTShapesInit.c +- src/ugl/torMesaUGLInit.c +- src/ugl/ugl_api.c +- src/ugl/ugl_dd.c +- src/ugl/ugl_glutshapes.c +- src/ugl/ugl_line.c +- src/ugl/ugl_span.c +- src/ugl/ugl_tri.c +- src/ugl/uglmesaP.h +- ugldemos/* + +Modified files in Tornado 2.0: +- c:\Tornado\host\x86-win32\bin\torVars.bat +rem Command line build environments +set WIND_HOST_TYPE=x86-win32 +set WIND_BASE=C:\Tornado +set MESA_BASE=C:\Mesa +set PATH=%WIND_BASE%\host\%WIND_HOST_TYPE%\bin;%PATH% +- c:\Tornado\target\config\comps\VxWorks\01uglmesa.cdf +- c:\Tornado\target\h\GL\* + +Todo +---- +- GCC 2.96, ASM compilation + +Thanks to: +---------- + +Precision Insight team for their great job around Mesa, XFree, and DRI. +Wind River Systems to take me as an intern. + + +Stephane Raimbault + + + +July 24, 2001 diff --git a/docs/RELNOTES-3.1 b/docs/RELNOTES-3.1 new file mode 100644 index 0000000..65324eb --- /dev/null +++ b/docs/RELNOTES-3.1 @@ -0,0 +1,145 @@ + + Mesa 3.1 release notes + + PLEASE READ!!!! + + +New copyright +------------- + +Mesa 3.1 will be distributed under an XFree86-style copyright instead +of the GNU LGPL. + + +New directories +--------------- + +All documentation files are now in the docs/ directory. +All shell scripts are now in the bin/ directory. + + +New library names +----------------- + +Formerly, the main Mesa library was named libMesaGL.so (or libMesaGL.a) +and the GLU library was named libMesaGLU.so (or libMesaGLU.a). + +Now, the main library is named libGL.so (or libGL.a) and the GLU library +is named libGLU.so (or libGLU.a). + +The change allows Mesa to be more easily substituted for OpenGL. +Specifically, the linker/loader on some Unix-like systems won't +allow libMesaGL.so to be used instead of libGL.so if the application +was linked with the former. + +Warning: if you have another OpenGL implementation installed on your +system (i.e. you have another OpenGL libGL.so) you'll have to be +carefull about which library (OpenGL or Mesa) you link against. Be +aware of -L linker flags and the value of the LD_LIBRARY_PATH environment +variable. + + +New library versioning +---------------------- + +Previously, the Mesa GL library was named libMesaGL.so.3.0 +To better support Linux/OpenGL standards, the Mesa GL library is now +named libGL.so.1.2.030100 This indicates version 1.2 of the OpenGL spec +and Mesa implementation 3.1.0 + +In the long term this will allow better interoperability with other +OpenGL implementations, especially on Linux. In the short term, +OpenGL apps may have to be relinked to use the new library naming. + + + +New makefiles +------------- + +The old Makefiles found in the various directories have been renamed +to Makefile.X11 in order to prevent filename collisions with autoconfig- +generated Makefiles. + +The top-level Makefile simply includes Makefile.X11 +If your top-level Makefile get's overwritten/destroyed you can restore +it by copying Makefile.X11 to Makefile + + +New extensions +-------------- + +GL_EXT_stencil_wrap + Implements two new stencil operations: GL_INCR_WRAP_EXT and + GL_DECR_WRAP_EXT which allow stencil increment and decrement + without clamping. + +GL_INGR_blend_func_separate + Allows specification of blend factors for RGB and Alpha independently. + (INGR = Intergraph) + +GL_ARB_multitexture + Multiple simultaneous textures. (ARB = Architecture Review Board) + +GL_NV_texgen_reflection + nVidia texgen extension for better reflection mapping. + +GL_PGI_misc_hints + Assorted transformation hints. + +GL_EXT_compiled_vertex_array + Compiled vertex arrays. + +GL_EXT_clip_volume_hint + Allows one to disable clip volume (frustum) testing. + + + +Extensions removed +------------------ + +GL_EXT_multitexture - obsolete in favor of GL_ARB_multitexture + + + +Config file +----------- + +By default, /etc/mesa.conf will be read when Mesa starts. This +file controls default hints, enable/disable of extensions, and +more. See the CONFIG file for documentation. + + + +Optimizations +------------- + +Keith Whitwell has contributed significant optimizations to Mesa's +vertex transformation code. Basically, the whole transformation +stage of Mesa has been rewritten. + +It's impossible to give a speedup factor. You'll just have to +try your app and see how it performs. + + + +Device Driver changes +--------------------- + +A bunch of new device driver functions have been added. See src/dd.h +Keith Harrison contributed many of them. I've been planning on adding +a bunch of functions like these to make writing hardware drivers easier. +More such function will probably be added in the near future. + + + +Miscellaneous +------------- + +util/glstate.c has some handy functions for debugging. Basically, it +offers a simple function for printing GL state variables. It's not +finished yet. There's a LOT more GLenum records to be added (see the +code). Anyone want to help? + + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-3.2 b/docs/RELNOTES-3.2 new file mode 100644 index 0000000..ec7d4f8 --- /dev/null +++ b/docs/RELNOTES-3.2 @@ -0,0 +1,11 @@ + + Mesa 3.2 release notes + + PLEASE READ!!!! + + +Mesa 3.2 is a stabilization of the Mesa 3.1 release. No new features +have been added. For a list of bug fixes please read the VERSIONS file. + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-3.2.1 b/docs/RELNOTES-3.2.1 new file mode 100644 index 0000000..d34efcc --- /dev/null +++ b/docs/RELNOTES-3.2.1 @@ -0,0 +1,31 @@ + + Mesa 3.2.1 release notes + + PLEASE READ!!!! + + + +The Mesa 3.2.1 release mainly just fixes bugs since the 3.2 release. +See the VERSIONS file for the exact list. + + + +GLU Polygon Tessellator +----------------------- + +The GLU tessellator has been reverted back to the version included +with Mesa 3.0 since it's more stable. The Mesa 3.1/3.2 tessellator +implemented the GLU 1.3 specification but suffered from a number of +bugs. + +Mesa implements GLU 1.1. + +Ideally, people should use the GLU 1.3 library included in SGI's +OpenGL Sample Implementation (SI) available from +http://oss.sgi.com/projects/ogl-sample/ +People are working to make easy-to-install Linux RPMs of the +GLU library. + + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-3.3 b/docs/RELNOTES-3.3 new file mode 100644 index 0000000..3850767 --- /dev/null +++ b/docs/RELNOTES-3.3 @@ -0,0 +1,270 @@ + + Mesa 3.3 release notes + + July 21, 2000 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 3.3) designate new developmental releases. +Even numbered versions (such as 3.2.1) designate stable releases. + +Mesa 3.3 has a undergone many internal changes since version 3.2 +and features a lot of new extensions. 3.3 is expected to be pretty +stable, but perhaps not as stable as 3.2 which has been used by +thousands of users over the past months. + +Everyone is encouraged to try Mesa 3.3. Bugs should be reported to +the Mesa bug database on www.sourceforge.net. + + + +Header file / GLenum changes +---------------------------- + +The gl.h and glu.h headers now use #defines to define all GL_* tokens +instead of C-language enums. This change improves Mesa/OpenGL +interoperability. + + + +New API dispatch code +--------------------- + +The core Mesa gl* functions are now implemented with a new dispatch +(jump table) which will allow simultaneous direct/indirect rendering. + +The code is found in the glapi*.[ch] files. + +Of interest: the actual "glFooBar" functions are generated with +templatized code defined in glapitemp.h and included by glapi.c +The glapitemp.h template should be reusable for all sorts of OpenGL +projects. + +The new dispatch code has also optimized with x86 assembly code. +This optimization eliminates copying the function arguments during +dispatch. + + + +New thread support +------------------ + +Thread support in Mesa has been rewritten. The glthread.[ch] files +replace mthreads.[ch]. Thread safety is always enabled (on platforms +which support threads, that is). There is virtually no performance +penalty for typical single-thread applications. See the glapi.c +file for details. + +The Xlib driver (XMesa) is now thread-safe as well. Be sure to +call XInitThreads() in your app first. See the xdemos/glthreads.c +demo for an example. + + + +Make configuration changes +-------------------------- + +If you use the old-style (non GNU automake) method to build Mesa note +that several of the configuration names have changed: + + Old name New name + ------------- ---------------- + linux-elf linux + linux linux-static + linux-386-elf linux-386 + linux-386 linux-386-static + etc. + + + +New extensions +-------------- + +GL_ARB_transpose_matrix + Adds glLoadTransposeMatrixARB() and glMultTransposeMatrixARB() + functions. + +GL_ARB_texture_cube_map + For cube-based reflection mapping. + +GL_EXT_texture_add_env + Adds GL_ADD texture environment mode. + See http://www.berkelium.com/OpenGL/EXT/texture_env_add.txt + +GL_EXT_texture_lod_bias + Allows mipmapped texture blurring and sharpening. + +GLX_EXT_visual_rating extension + This extension has no effect in stand-alone Mesa (used for DRI). + +GL_HP_occlusion_test + Used for bounding box occlusion testing (see demos/occlude.c). + +GL_SGIX_pixel_texture / GL_SGIS_pixel_texture + Lets glDraw/CopyPixels draw a texture coordinate image. + +GL_SGI_color_matrix + Adds a color matrix and another set of scale and bias parameters + to the glDraw/CopyPixels paths. + +GL_SGI_color_table + Adds additional color tables to the glDraw/Read/CopyPixels paths. + +GL_EXT_histogram + Compute histograms for glDraw/Read/CopyPixels. + +GL_EXT_blend_func_separate + This is the same as GL_INGR_blend_func_separate. + +GL_ARB_texture_cube_mapping + 6-face cube mapping, nicer than sphere mapping + +GL_EXT_texture_env_combine + For advanced texture environment effects. + + +Documentation for all these functions can be found at +http://oss.sgi.com/projects/ogl-sample/registry/ + + + +GLX_SGI_make_current_read functionality +--------------------------------------- + +The functionality of this extension is needed for GLX 1.3 (and required +for the Linux/OpenGL standards base). + +Implementing this function required a **DEVICE DRIVER CHANGE**. +The old SetBuffer() function has been replaced by SetReadBuffer() and +SetDrawBuffer(). All device drivers will have to be updated because +of this change. + +The new function, glXMakeContextCurrent(), in GLX 1.3 now works in Mesa. +The xdemos/wincopy.c program demonstrates it. + + + +Image-related code changes +-------------------------- + +The imaging path code used by glDrawPixels, glTexImage[123]D, +glTexSubImage[123], etc has been rewritten. It's now faster, +uses less memory and has several bug fixes. This work was +actually started in Mesa 3.1 with the glTexImage paths but has now +been carried over to glDrawPixels as well. + + + +Device driver interface changes +------------------------------- + +Added new functions for hardware stencil buffer support: + WriteStencilSpan + ReadStencilSpan + WriteStencilPixels + ReadStencilPixels + + +Removed old depth buffer functions: + AllocDepthBuffer + DepthTestSpan + DepthTestPixels + ReadDepthSpanFloat + ReadDepthSpanInt + + +Added new depth buffer functions: + WriteDepthSpan + ReadDepthSpan + WriteDepthPixels + ReadDepthPixels + + These functions always read/write 32-bit GLuints. This will allow + drivers to have anywhere from 0 to 32-bit Z buffers without + recompiling for 16 vs 32 bits as was previously needed. + + +New texture image functions + The entire interface for texture image specification has been updated. + With the new functions, it's optional for Mesa to keep an internal copy + of all textures. Texture download should be a lot faster when the extra + copy isn't made. + +Misc changes + TexEnv now takes a target argument + Removed UseGlobalTexturePalette (use Enable function instead) + + +Also added + ReadPixels + CopyPixels + + +The SetBufffer function has been replaced by SetDrawBuffer and +SetReadBuffer functions. This lets core Mesa independently +specify which buffer is to be used for reading and which for +drawing. + +The Clear function's mask parameter has changed. Instead of +mask being the flags specified by the user to glClear, the +mask is now a bitmask of the DD_*_BIT flags in dd.h. Now +multiple color buffers can be specified for clearing (ala +glDrawBuffers). The driver's Clear function must also +check the glColorMask glIndexMask, and glStencilMask settings +and do the right thing. See the X/Mesa, OS/Mesa, or FX/Mesa +drivers for examples. + + +The depth buffer changes shouldn't be hard to make for existing +drivers. In fact, it should simply the code. Be careful with +the depthBits value passed to gl_create_context(). 1 is a bad +value! It should normally be 0, 16, 24, or 32. + + +gl_create_framebuffer() takes new arguments which explicitly tell +core Mesa which ancillary buffers (depth, stencil, accum, alpha) +should be implemented in software. Mesa hardware drivers should +carefully set these flags depending on which buffers are in the +graphics card. + + + +Internal constants +------------------ + +Point and line size range and granularity limits are now stored +in the gl_constants struct, which is the Const member of GLcontext. +The limits are initialized from values in config.h but may be +overridden by device drivers to reflect the limits of that driver's +hardware. + +Also added constants for NumAuxBuffers and SubPixelBits. + + + +OpenGL Conformance +------------------ + +Mesa now passes all the OpenGL 1.1 conformance tests, except for +antialiased lines. AA lines fail on some, but not all, the tests. +In order to fix the remaining failures, a new AA line algorithm will +be needed (which computes coverage values for end-point fragments). +This will be done for Mesa 3.5/3.6. + + + +OpenGL 1.2 GL_ARB_imaging subset +-------------------------------- + +Mesa 3.3 implements all the features of GL_ARB_imaging except for +image convolution. This will (hopefully) be done for Mesa 3.5/3.6. + + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-3.4 b/docs/RELNOTES-3.4 new file mode 100644 index 0000000..657ccda --- /dev/null +++ b/docs/RELNOTES-3.4 @@ -0,0 +1,21 @@ + + Mesa 3.4 release notes + + November 3, 2000 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 3.3) designate new developmental releases. +Even numbered versions (such as 3.4) designate stable releases. + +Mesa 3.4 simply fixes bugs found in the Mesa 3.3 release. For details, +see the VERSIONS file. + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-3.4.1 b/docs/RELNOTES-3.4.1 new file mode 100644 index 0000000..73d75c6 --- /dev/null +++ b/docs/RELNOTES-3.4.1 @@ -0,0 +1,21 @@ + + Mesa 3.4.1 release notes + + February 9, 2001 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 3.3) designate new developmental releases. +Even numbered versions (such as 3.4) designate stable releases. + +Mesa 3.4.1 is a maintenance release that simply fixes bugs found since +the Mesa 3.4 release. For details, see the VERSIONS file. + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-3.4.2 b/docs/RELNOTES-3.4.2 new file mode 100644 index 0000000..9caea90 --- /dev/null +++ b/docs/RELNOTES-3.4.2 @@ -0,0 +1,21 @@ + + Mesa 3.4.2 release notes + + May 17, 2001 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 3.3) designate new developmental releases. +Even numbered versions (such as 3.4) designate stable releases. + +Mesa 3.4.2 is a maintenance release that simply fixes bugs found since +the Mesa 3.4.1 release. For details, see the VERSIONS file. + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-3.5 b/docs/RELNOTES-3.5 new file mode 100644 index 0000000..b2aa1b8 --- /dev/null +++ b/docs/RELNOTES-3.5 @@ -0,0 +1,227 @@ + + Mesa 3.5 release notes + + June 21, 2001 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 3.5) designate new developmental releases. +Even numbered versions (such as 3.4) designate stable releases. + +The biggest change in Mesa 3.5 is a complete overhaul of the source +code in order to make it more modular. This was driven by the DRI +hardware drivers. It simplifies the DRI drivers and opens the door +to hardware transform/clip/lighting (TCL). Keith Whitwell can take +the credit for that. + + + +Driver Support +-------------- + +The device driver interface in Mesa 3.5 has changed a lot since Mesa 3.4 +Not all of the older Mesa drivers have been updated. Here's the status: + +Driver Status +---------------------- ----------- +XMesa (Xlib) updated +OSMesa (off-screen) updated +FX (3dfx Voodoo1/2) updated +SVGA updated +GGI not updated +Windows/Win32 not updated +DOS/DJGPP not updated +BeOS not updated +Allegro not updated +D3D not updated +DOS not updated + +We're looking for volunteers to update the remaining drivers. Please +post to the Mesa3d-dev mailing list if you can help. + + + +GLU 1.3 +------- + +Mesa 3.5 includes the SGI Sample Implementation (SI) GLU library. +This version of GLU supports the GLU 1.3 specification. The old +Mesa GLU library implemented the 1.1 specification. The SI GLU +library should work much better. + +You'll need a C++ compiler to compile the SI GLU library. This may +be a problem on some systems. + + + +New Extensions +-------------- + +GL_EXT_convolution + Adds image convolution to glRead/Copy/DrawPixels/TexImage. + +GL_ARB_imaging + This is the optional imaging subset of OpenGL 1.2. + It's the GL_EXT_convolution, GL_HP_convolution_border_modes, + GL_EXT_histogram, GL_EXT_color_table, GL_EXT_color_subtable + GL_EXT_blend_color, GL_EXT_blend_minmax, GL_EXT_blend_subtract + and GL_SGI_color_matrix extensions all rolled together. + This is supported in all software renderers but not in all + hardware drivers (3dfx for example). + +GL_ARB_texture_compression + This is supported in Mesa but only used by the 3dfx DRI drivers + for Voodoo4 and later. + +GL_ARB_texture_env_add + This is identical to GL_EXT_texture_env_add. + +GL_NV_blend_square + Adds extra blend source and dest factors which allow squaring + of color values. + +GL_EXT_fog_coord + Allows specification of a per-vertex fog coordinate instead of + having fog always computed from the eye distance. + +GL_EXT_secondary_color + Allows specifying the secondary (specular) color for each vertex + instead of getting it only from lighting in GL_SEPARATE_SPECULAR_COLOR + mode. + +GL_ARB_texture_env_combine + Basically the same as GL_EXT_texture_env_combine + +GL_ARB_texture_env_add extension + Texture addition mode. + +GL_ARB_texture_env_dot3 extension + Dot product texture environment. + +GL_ARB_texture_border_clamp + Adds GL_CLAMP_TO_BORDER_ARB texture wrap mode + +GL_SGIX_depth_texture, GL_SGIX_shadow and GL_SGIX_shadow_ambient + Implements a shadow casting algorithm based on depth map textures + +GL_SGIS_generate_mipmap + Automatically generate lower mipmap images whenever the base mipmap + image is changed with glTexImage, glCopyTexImage, etc. + + + +libOSMesa.so +------------ + +libOSMesa.so is a new library which contains the OSMesa interface for +off-screen rendering. Apps which need the OSMesa interface should link +with both -lOSMesa and -lGL. This change was made so that stand-alone +Mesa works the same way as XFree86/DRI's libGL. + + + +Device Driver Changes / Core Mesa Changes +----------------------------------------- + +The ctx->Driver.LogicOp() function has been removed. It used to +be called during state update in order to determine if the driver +could do glLogicOp() operations, and if not, set the SWLogicOpEnabled +flag. Drivers should instead examine the LogicOp state themselves +and choose specialized point, line, and triangle functions appropriately, +or fall back to software rendering. The Xlib driver was the only driver +to use this function. And since the Xlib driver no longer draws +points, lines or triangles using Xlib, the LogicOp function isn't needed. + +The ctx->Driver.Dither() function has been removed. Drivers should +detect dither enable/disable via ctx->Driver.Enable() instead. + +The ctx->Driver.IndexMask() and ctx->Driver.ColorMask() functions +are now just called from glIndexMask and glColorMask like the other +GL state-changing functions. They are no longer called from inside +gl_update_state(). Also, they now return void. The change was made +mostly for sake of uniformity. + +The NEW_DRVSTATE[0123] flags have been removed. They weren't being used +and are obsolete w.r.t. the way state updates are done in DRI drivers. + + +Removed obsolete gl_create_visual() and gl_destroy_visual(). + +Renamed functions (new namespace): + +old new +gl_create_framebuffer _mesa_create_framebuffer +gl_destroy_framebuffer _mesa_destroy_framebuffer +gl_create_context _mesa_create_context +gl_destroy_context _mesa_destroy_context +gl_context_initialize _mesa_context_initialize +gl_copy_context _mesa_copy_context +gl_make_current _mesa_make_current +gl_make_current2 _mesa_make_current2 +gl_get_current_context _mesa_get_current_context +gl_flush_vb _mesa_flush_vb +gl_warning _mesa_warning +gl_compile_error _mesa_compile_error + + +All the drivers have been updated, but not all of them have been +tested since I can't test some platforms (DOS, Windows, Allegro, etc). + + +X/Mesa Driver +------------- + +The source files for the X/Mesa driver in src/X have been renamed. +The xmesa[1234].c files are gone. The new files are xm_api.c, +xm_dd.c, xm_line.c, xm_span.c and xm_tri.c. + + + +Multitexture +------------ + +Eight texture units are now supported by default. + + + +OpenGL SI related changes +------------------------- + +In an effort to make Mesa's internal interfaces more like the OpenGL +SI interfaces, a number of changes have been made: + +1. Importing the SI's glcore.h file which defines a number of +interface structures like __GLimports and __GLexports. + +2. Renamed "struct gl_context" to "struct __GLcontextRec". + +3. Added __glCoreCreateContext() and __glCoreNopDispatch() functions. + +4. The GLcontext member Visual is no longer a pointer. + +5. New file: imports.c to setup default import functions for Mesa. + + + + +16-bit color channels +--------------------- + +There's experimental support for 16-bit color channels (64-bit pixels) +in Mesa 3.5. Only the OSMesa interface can be used for 16-bit rendering. +Type "make linux-osmesa16" in the top-level directory to build the +special libOSMesa16.so library. + +This hasn't been tested very thoroughly yet so please file bug reports +if you have trouble. + +In the future I hope to implement support for 32-bit, floating point +color channels. + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-4.0 b/docs/RELNOTES-4.0 new file mode 100644 index 0000000..2f729db --- /dev/null +++ b/docs/RELNOTES-4.0 @@ -0,0 +1,162 @@ + + Mesa 4.0 release notes + + October 18, 2001 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 3.3) designate new developmental releases. +Even numbered versions (such as 3.4) designate stable releases. + +Mesa version 4.0 signifies two things: + + 1. A stabilization of the 3.5 development release + 2. Implementation of the OpenGL 1.3 specification + + +Note that the Mesa major version number is incremented with the OpenGL +minor version number: + + Mesa 1.x == OpenGL 1.0 + Mesa 2.x == OpenGL 1.1 + Mesa 3.x == OpenGL 1.2 + Mesa 4.x == OpenGL 1.3 + + + +New Features +------------ + +Mesa 3.5 already had all the new features of OpenGL 1.3, implemented as +extensions. These extensions were simply promoted to standard features: + + GL_ARB_multisample + GL_ARB_multitexture + GL_ARB_texture_border_clamp + GL_ARB_texture_compression + GL_ARB_texture_cube_map + GL_ARB_texture_env_add + GL_ARB_texture_env_combine + GL_ARB_texture_env_dot3 + GL_ARB_transpose_matrix + +In Mesa 4.0 the functions defined by these extensions are now available +without the "ARB" suffix. For example, glLoadTransposeMatrixf() is now +a standard API function. The new functions in OpenGL 1.3 and Mesa 4.0 are: + + glActiveTexture + glClientActiveTexture + glCompressedTexImage1D + glCompressedTexImage2D + glCompressedTexImage3D + glCompressedTexSubImage1D + glCompressedTexSubImage2D + glCompressedTexSubImage3D + glGetCompressedTexImage + glLoadTransposeMatrixd + glLoadTransposeMatrixf + glMultiTexCoord1d + glMultiTexCoord1dv + glMultiTexCoord1f + glMultiTexCoord1fv + glMultiTexCoord1i + glMultiTexCoord1iv + glMultiTexCoord1s + glMultiTexCoord1sv + glMultiTexCoord2d + glMultiTexCoord2dv + glMultiTexCoord2f + glMultiTexCoord2fv + glMultiTexCoord2i + glMultiTexCoord2iv + glMultiTexCoord2s + glMultiTexCoord2sv + glMultiTexCoord3d + glMultiTexCoord3dv + glMultiTexCoord3f + glMultiTexCoord3fv + glMultiTexCoord3i + glMultiTexCoord3iv + glMultiTexCoord3s + glMultiTexCoord3sv + glMultiTexCoord4d + glMultiTexCoord4dv + glMultiTexCoord4f + glMultiTexCoord4fv + glMultiTexCoord4i + glMultiTexCoord4iv + glMultiTexCoord4s + glMultiTexCoord4sv + glMultTransposeMatrixd + glMultTransposeMatrixf + glSampleCoverage + glSamplePass + + +GLX 1.4 is the companion to OpenGL 1.3. The only new features in GLX 1.4 +are support for multisampling and the GLX_ARB_get_proc_address extension. +glXGetProcAddress() is the only new function in GLX 1.4. + + + +Multisample and Texture Compression +----------------------------------- + +The OpenGL 1.3 specification allows the multisample and texture compression +features to essentially be no-ops. For example, if you query for multisample +support you'll find none, but the API functions work. + +Similarly, texture compression is not implemented by any of the software +drivers but you can specify a generic compressed texture format (like +GL_COMPRESSED_RGBA) to glTexImage2D and it'll be accepted. + + + +Device Drivers +-------------- + +Mesa advertises itself as either OpenGL 1.2 or OpenGL 1.3 depending on the +device driver. If the driver enables all the ARB extensions which are part +of OpenGL 1.3 then glGetString(GL_VERSION) will return "1.3". Otherwise, +it'll return "1.2". + +A number of Mesa's software drivers haven't been actively maintained for +some time. We rely on volunteers to maintain many of the drivers. +Here's the current status of all included drivers: + + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.3 +OSMesa (off-screen) implements OpenGL 1.3 +FX (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.3 +GGI needs updating +DOS/DJGPP needs updating +BeOS needs updating +Allegro needs updating +D3D needs updating +DOS needs updating + +Special thanks go to Karl Schultz for updating the Windows driver. + +The XFree86/DRI drivers have not yet been updated to use Mesa 4.0 as of +September 2001, but that should happen eventually. + + + +Other Changes +------------- + +See the VERSIONS file for more details about bug fixes, etc. in Mesa 4.0. + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-4.0.1 b/docs/RELNOTES-4.0.1 new file mode 100644 index 0000000..e84df6b --- /dev/null +++ b/docs/RELNOTES-4.0.1 @@ -0,0 +1,21 @@ + + Mesa 4.0.1 release notes + + December 17, 2001 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 3.3) designate new developmental releases. +Even numbered versions (such as 3.4) designate stable releases. + +Mesa 4.0.1 only contains bug fixes since version 4.0. + +See the docs/VERSIONS file for the list of bug fixes. + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-4.0.2 b/docs/RELNOTES-4.0.2 new file mode 100644 index 0000000..b476956 --- /dev/null +++ b/docs/RELNOTES-4.0.2 @@ -0,0 +1,49 @@ + + Mesa 4.0.2 release notes + + March 25, 2002 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 3.3) designate new developmental releases. +Even numbered versions (such as 3.4) designate stable releases. + +Mesa 4.0.2 only contains bug fixes and a new DOS driver since version 4.0.1. + +See the docs/VERSIONS file for the list of bug fixes. + + +Device Drivers +-------------- + +Mesa advertises itself as either OpenGL 1.2 or OpenGL 1.3 depending on the +device driver. If the driver enables all the ARB extensions which are part +of OpenGL 1.3 then glGetString(GL_VERSION) will return "1.3". Otherwise, +it'll return "1.2". + +A number of Mesa's software drivers haven't been actively maintained for +some time. We rely on volunteers to maintain many of the drivers. +Here's the current status of all included drivers: + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.3 +OSMesa (off-screen) implements OpenGL 1.3 +FX (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.3 +DOS/DJGPP implements OpenGL 1.3 (new in Mesa 4.0.2) +GGI needs updating +BeOS needs updating +Allegro needs updating +D3D needs updating + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-4.0.3 b/docs/RELNOTES-4.0.3 new file mode 100644 index 0000000..0b3e34b --- /dev/null +++ b/docs/RELNOTES-4.0.3 @@ -0,0 +1,51 @@ + + Mesa 4.0.3 release notes + + June 25, 2002 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 3.3) designate new developmental releases. +Even numbered versions (such as 3.4) designate stable releases. + +Mesa 4.0.3 basically just contains bug fixes version 4.0.2. + +See the docs/VERSIONS file for the list of bug fixes. + +The GGI driver has been updated, thanks to Filip Spacek. + + +Device Drivers +-------------- + +Mesa advertises itself as either OpenGL 1.2 or OpenGL 1.3 depending on the +device driver. If the driver enables all the ARB extensions which are part +of OpenGL 1.3 then glGetString(GL_VERSION) will return "1.3". Otherwise, +it'll return "1.2". + +A number of Mesa's software drivers haven't been actively maintained for +some time. We rely on volunteers to maintain many of the drivers. +Here's the current status of all included drivers: + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.3 +OSMesa (off-screen) implements OpenGL 1.3 +FX (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.3 +DOS/DJGPP implements OpenGL 1.3 (new in Mesa 4.0.2) +GGI implements OpenGL 1.3 +BeOS needs updating +Allegro needs updating +D3D needs updating + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-4.1 b/docs/RELNOTES-4.1 new file mode 100644 index 0000000..24e9299 --- /dev/null +++ b/docs/RELNOTES-4.1 @@ -0,0 +1,307 @@ + + Mesa 4.1 release notes + + October 29, 2002 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Even numbered versions (such as 4.0) designate stable releases. +Odd numbered versions (such as 4.1) designate new developmental releases. + + +New Features in Mesa 4.1 +------------------------ + +New extensions. Docs at http://oss.sgi.com/projects/ogl-sample/registry/ + +GL_NV_vertex_program + + NVIDIA's vertex programming extension + +GL_NV_vertex_program1_1 + + A few features built on top of GL_NV_vertex_program + +GL_ARB_window_pos + + This is the ARB-approved version of GL_MESA_window_pos + +GL_ARB_depth_texture + + This is the ARB-approved version of GL_SGIX_depth_texture. + It allows depth (Z buffer) data to be stored in textures. + This is used by GL_ARB_shadow + +GL_ARB_shadow + + Shadow mapping with depth textures. + This is the ARB-approved version of GL_SGIX_shadow. + +GL_ARB_shadow_ambient + + Allows one to specify the luminance of shadowed pixels. + This is the ARB-approved version of GL_SGIX_shadow_ambient. + +GL_EXT_shadow_funcs + + Extends the set of GL_ARB_shadow texture comparision functions to + include all eight of standard OpenGL dept-test functions. + +GL_ARB_point_parameters + + This is basically the same as GL_EXT_point_parameters. + +GL_ARB_texture_env_crossbar + + Allows any texture combine stage to reference any texture source unit. + +GL_NV_point_sprite + + For rendering points as textured quads. Useful for particle effects. + +GL_NV_texture_rectangle (new in 4.0.4 actually) + + Allows one to use textures with sizes that are not powers of two. + Note that mipmapping and several texture wrap modes are not allowed. + +GL_EXT_multi_draw_arrays + + Allows arrays of vertex arrays to be rendered with one call. + +GL_EXT_stencil_two_side + + Separate stencil modes for front and back-facing polygons. + +GLX_SGIX_fbconfig & GLX_SGIX_pbuffer + + Off-screen rendering support. + +GL_ATI_texture_mirror_once + + Adds two new texture wrap modes: GL_MIRROR_CLAMP_ATI and + GL_MIRROR_CLAMP_TO_EDGE_ATI. + + + +Device Driver Status +-------------------- + +A number of Mesa's software drivers haven't been actively maintained for +some time. We rely on volunteers to maintain many of these drivers. +Here's the current status of all included drivers: + + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.3 +OSMesa (off-screen) implements OpenGL 1.3 +FX (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.3 +DOS/DJGPP implements OpenGL 1.3 +GGI implements OpenGL 1.3 +BeOS needs updating (underway) +Allegro needs updating +D3D needs updating +DOS needs updating + + + +New features in GLUT +-------------------- + +1. Frames per second printing + + GLUT now looks for an environment variable called "GLUT_FPS". If it's + set, GLUT will print out a frames/second statistic to stderr when + glutSwapBuffers() is called. By default, frames/second is computed + and displayed once every 5 seconds. You can specify a different + interval (in milliseconds) when you set the env var. For example + 'export GLUT_FPS=1000' or 'setenv GLUT_FPS 1000' will set the interval + to one second. + + NOTE: the demo or application must call the glutInit() function for + this to work. Otherwise, the env var will be ignored. + + Finally, this feature may not be reliable in multi-window programs. + + +2. glutGetProcAddress() function + + The new function: + + void *glutGetProcAddress(const char *procName) + + is a wrapper for glXGetProcAddressARB() and wglGetProcAddress(). It + lets you dynamically get the address of an OpenGL function at runtime. + The GLUT_API_VERSION has been bumped to 5, but I haven't bumped the + GLUT version number from 3.7 since that's probably Mark Kilgard's role. + + This function should probably also be able to return the address of + GLUT functions themselves, but it doesn't do that yet. + + + +XXX Things To Do Yet XXXX +------------------------- + +isosurf with vertex program exhibits some missing triangles (probably +when recycling the vertex buffer for long prims). + + + +Porting Info +------------ + +If you're porting a DRI or other driver from Mesa 4.0.x to Mesa 4.1 here +are some things to change: + +1. ctx->Texture._ReallyEnabled is obsolete. + + Since there are now 5 texture targets (1D, 2D, 3D, cube and rect) that + left room for only 6 units (6*5 < 32) in this field. + This field is being replaced by ctx->Texture._EnabledUnits which has one + bit per texture unit. If the bit k of _EnabledUnits is set, that means + ctx->Texture.Unit[k]._ReallyEnabled is non-zero. You'll have to look at + ctx->Texture.Unit[k]._ReallyEnabled to learn if the 1D, 2D, 3D, cube or + rect texture is enabled for unit k. + + This also means that the constants TEXTURE1_*, TEXTURE2_*, etc are + obsolete. + + The tokens TEXTURE0_* have been replaced as well (since there's no + significance to the "0" part: + + old token new token + TEXTURE0_1D TEXTURE_1D_BIT + TEXTURE0_2D TEXTURE_2D_BIT + TEXTURE0_3D TEXTURE_3D_BIT + TEXTURE0_CUBE TEXTURE_CUBE_BIT + TEXTURE_RECT_BIT + + These tokens are only used for the ctx->Texture.Unit[i].Enabled and + ctx->Texture.Unit[i]._ReallyEnabled fields. Exactly 0 or 1 bits will + be set in _ReallyEnabled at any time! + + Q: "What's the purpose of Unit[i].Enabled vs Unit[i]._ReallyEnabled?" + A: The user can enable GL_TEXTURE_1D, GL_TEXTURE_2D, etc for any + texure unit all at once (an unusual thing to do). + OpenGL defines priorities that basically say GL_TEXTURE_2D has + higher priority than GL_TEXTURE_1D, etc. Also, just because a + texture target is enabled by the user doesn't mean we'll actually + use that texture! If a texture object is incomplete (missing mip- + map levels, etc) it's as if texturing is disabled for that target. + The _ReallyEnabled field will have a bit set ONLY if the texture + target is enabled and complete. This spares the driver writer from + examining a _lot_ of GL state to determine which texture target is + to be used. + + +2. Tnl tokens changes + + During the implementation of GL_NV_vertex_program some of the vertex + buffer code was changed. Specifically, the VERT_* bits defined in + tnl/t_context.h have been renamed to better match the conventions of + GL_NV_vertex_program. The old names are still present but obsolete. + Drivers should use the newer names. + + For example: VERT_RGBA is now VERT_BIT_COLOR0 and + VERT_SPEC_RGB is now VERT_BIT_COLOR1. + + + +3. Read/Draw Buffer changes + + The business of setting the current read/draw buffers in Mesa 4.0.x + was complicated. It's much simpler now in Mesa 4.1. + + Here are the changes: + + - Renamed ctx->Color.DrawDestMask to ctx->Color._DrawDestMask + - Removed ctx->Color.DriverDrawBuffer + - Removed ctx->Pixel.DriverReadBuffer + - Removed ctx->Color.MultiDrawBuffer + - Removed ctx->Driver.SetDrawBuffer() + - Removed swrast->Driver.SetReadBuffer(). + - Added ctx->Color._DrawDestMask - a bitmask of FRONT/BACK_LEFT/RIGHT_BIT + values to indicate the current draw buffers. + - Added ctx->Pixel._ReadSrcMask to indicate the source for pixel reading. + The value is _one_ of the FRONT/BACK_LEFT/RIGHT_BIT values. + - Added ctx->Driver.DrawBuffer() and ctx->Driver.ReadBuffer(). + These functions exactly correspond to glDrawBuffer and glReadBuffer calls. + Many drivers will set ctx->Driver.DrawBuffer = _swrast_DrawBuffer and + leave ctx->Draw.ReadBuffer NULL. + DRI drivers should implement their own function for ctx->Driver.DrawBuffer + and use it to set the current hardware drawing buffer. You'll probably + also want to check for GL_FRONT_AND_BACK mode and fall back to software. + Call _swrast_DrawBuffer() too, to update the swrast state. + - Added swrast->Driver.SetBuffer(). + This function should be implemented by all device drivers that use swrast. + Mesa will call it to specify the buffer to use for span reading AND + writing and point/line/triangle rendering. + There should be no confusion between current read or draw buffer anymore. + - Added swrast->CurrentBuffer to indicate which color buffer to read/draw. + Will be FRONT_LEFT_BIT, BACK_LEFT_BIT, FRONT_RIGHT_BIT or BACK_RIGHT_BIT. + This value is usually passed to swrast->Driver.SetBuffer(). + + +4. _mesa_create_context() changes. This function now takes a pointer to + a __GLimports object. The __GLimports structure contains function + pointers to system functions like fprintf(), malloc(), etc. + The _mesa_init_default_imports() function can be used to initialize + a __GLimports object. Most device drivers (like the DRI drivers) + should use this. + + +5. In tnl's struct vertex_buffer, the field "ProjectedClipCoords" + has been replaced by "NdcPtr" to better match the OpenGL spec's + terminology. + + +6. Since GL_EXT_stencil_two_side has been implemented, many of the + ctx->Stencil fields are now 2-element arrays. For example, + "GLenum Ref" is now "GLenum Ref[2]" The [0] elements are the front-face + values and the [1] elements are the back-face values. + ctx->Stencil.ActiveFace is 0 or 1 to indicate the current face for + the glStencilOp/Func/Mask() functions. + ctx->Stencil.TestTwoSide controls whether or not 1 or 2-sided stenciling + is enabled. + + +7. Removed ctx->Polygon._OffsetAny. Removed ctx->Polygon.OffsetMRD. + + +8. GLfloat / GLchan changes: + + - Changed ctx->Driver.ClearColor() to take GLfloat[4] instead of GLchan[4]. + ctx->Color.ClearColor is now GLfloat[4] too. + - Changed ctx->Driver.AlphaRef() to take GLfloat instead of GLchan. + - ctx->Color.AlphaRef is now GLfloat. + - texObj->BorderColor is now GLfloat[4]. texObj->_BorderChan is GLchan[4]. + + This is part of an effort to remove all GLchan types from core Mesa so + that someday we can support 8, 16 and 32-bit color channels dynamically + at runtime, instead of at compile-time. + + +9. GLboolean ctx->Tranform.ClipEnabled[MAX_CLIP_PLANES] has been replaced + by GLuint ctx->Transform.ClipPlanesEnabled. The later is a bitfield. + + +10. There's a new matrix_stack type in mtypes.h used for the Modelview, + Projection, Color and Texcoord matrix stacks. + + +11. The ctx->Current.* fields have changed a lot. Now, there's a + ctx->Current.Attrib[] array for all vertex attributes which matches + the NV vertex program conventions. + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-5.0 b/docs/RELNOTES-5.0 new file mode 100644 index 0000000..1b22996 --- /dev/null +++ b/docs/RELNOTES-5.0 @@ -0,0 +1,84 @@ + + Mesa 5.0 release notes + + November 13, 2002 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Even-numbered versions (such as 5.0) designate stable releases. +Odd-numbered versions (such as 4.1) designate new developmental releases. + +Mesa 5.0 is basically just a stabilization of Mesa 4.1. To see a list of +bug fixes, etc. see the VERSIONS file. + + + +New Features in Mesa 5.0 +------------------------ + +Mesa 5.0 supports OpenGL 1.4. Note Mesa's versioning convention: + + OpenGL Version Mesa Version + ------------------------------ + 1.0 1.x + 1.1 2.x + 1.2 3.x + 1.3 4.x + 1.4 5.x + +OpenGL 1.4 (and Mesa 5.0) incorporates the following OpenGL extensions as +standard features: + + GL_ARB_depth_texture + GL_ARB_shadow + GL_ARB_texture_env_crossbar + GL_ARB_texture_mirror_repeat + GL_ARB_window_pos + GL_EXT_blend_color + GL_EXT_blend_func_separate + GL_EXT_blend_logic_op + GL_EXT_blend_minmax + GL_EXT_blend_subtract + GL_EXT_fog_coord + GL_EXT_multi_draw_arrays + GL_EXT_point_parameters + GL_EXT_secondary_color + GL_EXT_stencil_wrap + GL_SGIS_generate_mipmap + + + +Device Driver Status +-------------------- + +A number of Mesa's software drivers haven't been actively maintained for +some time. We rely on volunteers to maintain many of these drivers. +Here's the current status of all included drivers: + + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.4 +OSMesa (off-screen) implements OpenGL 1.4 +FX (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.4 +DOS/DJGPP implements OpenGL 1.3 +GGI implements OpenGL 1.3 +DOS implements OpenGL 1.4 +BeOS needs updating (underway) +Allegro needs updating +D3D needs updating + +Note: supporting OpenGL 1.4 (vs. 1.3 or 1.2) usually only requires that the +driver call the _mesa_enable_1_4_extensions() function. + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-5.0.1 b/docs/RELNOTES-5.0.1 new file mode 100644 index 0000000..f37e9c4 --- /dev/null +++ b/docs/RELNOTES-5.0.1 @@ -0,0 +1,45 @@ + + Mesa 5.0.1 release notes + + March 30, 2003 + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Even-numbered versions (such as 5.0.x) designate stable releases. +Odd-numbered versions (such as 4.1.x) designate new developmental releases. + +Mesa 5.0.1 just fixes bugs found since the 5.0 release. See the VERSIONS +file for details. + + +Device Driver Status +-------------------- + +A number of Mesa's software drivers haven't been actively maintained for +some time. We rely on volunteers to maintain many of these drivers. +Here's the current status of all included drivers: + + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.4 +OSMesa (off-screen) implements OpenGL 1.4 +FX (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.4 +DJGPP implements OpenGL 1.4 +GGI implements OpenGL 1.3 +BeOS implements OpenGL 1.4 +Allegro needs updating +D3D needs updating + +Note: supporting OpenGL 1.4 (vs. 1.3 or 1.2) usually only requires that the +driver call the _mesa_enable_1_4_extensions() function. + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-5.0.2 b/docs/RELNOTES-5.0.2 new file mode 100644 index 0000000..d0e05b2 --- /dev/null +++ b/docs/RELNOTES-5.0.2 @@ -0,0 +1,45 @@ + + Mesa 5.0.2 release notes + + September 5, 2003 + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Even-numbered versions (such as 5.0.x) designate stable releases. +Odd-numbered versions (such as 4.1.x) designate new developmental releases. + +Mesa 5.0.2 just fixes bugs found since the 5.0.1 release. See the VERSIONS +file for details. + + +Device Driver Status +-------------------- + +A number of Mesa's software drivers haven't been actively maintained for +some time. We rely on volunteers to maintain many of these drivers. +Here's the current status of all included drivers: + + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.4 +OSMesa (off-screen) implements OpenGL 1.4 +FX (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.4 +DJGPP implements OpenGL 1.4 +GGI implements OpenGL 1.3 +BeOS implements OpenGL 1.4 +Allegro needs updating +D3D needs updating + +Note: supporting OpenGL 1.4 (vs. 1.3 or 1.2) usually only requires that the +driver call the _mesa_enable_1_4_extensions() function. + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-5.1 b/docs/RELNOTES-5.1 new file mode 100644 index 0000000..aed6e10 --- /dev/null +++ b/docs/RELNOTES-5.1 @@ -0,0 +1,279 @@ + + Mesa 5.1 release notes + + December 17, 2003 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Even-numbered versions (such as 5.0) designate stable releases. +Odd-numbered versions (such as 5.1) designate new developmental releases. + + +Bug fixes +--------- +See the VERSIONS file for a list of bugs fixed in this release. + + + +New Features in Mesa 5.1 +------------------------ + +GL_ARB_vertex_program / GL_ARB_fragment_program + Michal Krol and Karl Rasche implemented these extensions. Thanks! + Be aware that there may be some rough edges and lurking bugs. + +GL_ATI_texture_env_combine3 extension + This adds a few new texture combine modes. + Contributed by Ian Romanick. + +GL_SGI_texture_color_table + Adds a color table lookup to the RGBA texture path. There's a separate + color table for each texture unit. + Contributed by Eric Plante. + +GL_NV_fragment_program + NVIDIA's fragment-level programming feature. + Possible lurking bugs: + - the DDX and DDY commands aren't fully tested + - there may be bugs in the parser + - the TEX and TXP instructions both do perspective correction + - the pack/unpack instructions may not be correct + +GL_EXT_depth_bounds_test + This extension adds a scissor-like test for the Z axis. It's used to + optimize stencil-volume shadow algorithms. + +GL_NV_light_max_exponent + Lifts the 128 limit for max light exponent. + +GL_EXT_texture_rectangle + Identical to GL_NV_texture_rectangle + +GL_ARB_occlusion_query + Useful for visibility-based culling. + +GL_ARB_texture_non_power_of_two + Removes the restriction that texture dimensions must be powers of two. + +GL_ARB_vertex_buffer_object + Allows server-side vertex arrays, optimized host/card data transfers, etc. + +GL_ARB_point_sprite + ARB-approved version of GL_NV_point_sprite. Basically allows textures + to be applied to points. + +GL_IBM_multimode_draw_arrays + Allows multiple vertex arrays to be drawn with one call, including arrays + of different types of primitives. + +GL_SUN_multi_draw_arrays + An alias for GL_EXT_multi_draw_arrays, standard in OpenGL 1.4. + +Faster glDrawPixels / glCopyPixels in X11 driver + If your X screen is 32bpp, glDrawPixels to the front color buffer will + be accelerated (via XPutImage()) if the image format is GL_BGRA and the + type is GL_UNSIGNED_BYTE. No raster operations, such as depth test, + blend, fog, etc. can be enabled. + + If your X screen is 16bpp, glDrawPixels to the front color buffer will + be accelerated (via XPutImage()) if the image format is GL_RGB and the + type is GL_UNSIGNED_SHORT_5_6_5. No raster operations, such as depth + test, blend, fog, etc. can be enabled. + + glCopyPixels() calls for the front color buffer will be accelerated + (via XCopyArea()) if no raster operations, such as depth test, blend, + fog, pixel zoom, etc. are enabled. + + The speed-up over typical software rendering is a factor of 10 for + glDrawPixels and 100 for glCopyPixels. + + +With the addition of GL_ARB_occlusion_query, GL_ARB_vertex_buffer_object, +GL_ARB_texture_non_power_of_two and GL_EXT_shadow_funcs, Mesa 5.1 supports +all the new features of OpenGL 1.5. Mesa 6.0 (the next stable release) +will advertise GL_VERSION = "1.5". + + + +Vertex/Fragment program debugger +-------------------------------- + +GL_MESA_program_debug is an experimental extension to support +interactive debugging of vertex and fragment programs. See the +docs/MESA_program_debug.spec file for details. + +The bulk of the vertex/fragment program debugger is implemented +outside of Mesa. The GL_MESA_program_debug extension just has minimal +hooks for stopping running programs and inspecting programs. + +The progs/tests/debugger.c (only in CVS) program is an example of how +the extension can be used. Presently, the debugger code and demo code +is in the same file. Eventually the debugger code should be moved +into a reusable module. + +As it is now, the demo lets you set breakpoings in vertex/fragment +programs, single step, and print intermediate register values. It's +basically just a proof of concept. + + + +Directory tree reorganization +----------------------------- + +The directory structure for Mesa has been overhauled to improve its layout. +All source code for Mesa, GLU, GLUT, etc is now under the src/ directory +in appropriate subdirectories. + +The Mesa source code and drivers has been reorganized under src/mesa/. + +All demonstration programs and tests are now in subdirectories under progs/. + + + +Build System Changes +-------------------- + +The GNU automake/autoconf support has been removed. As it was, it seldom +worked on anything but Linux. The Mesa developers aren't big fans of +automake/autoconf/libtool and didn't have the time to maintain it. +If someone wants to contribute new automake/autoconf support (and is +willing to maintain it), it may be re-incorporated into Mesa, subject +to some requirements. + +The "old style" makefile system has been updated: + 1. Make-config has been trimmed down to fewer, modern configurations. + 2. Most of the bin/mklib.* scripts have been rolled into a new "mklib" + script that works on all sorts of systems. There are probably some + bugs in it, but it's been tested on Linux, SunOS 5.8 and IRIX 6.5. + Improvements/contributes are greatly appreciated. + 3. The Makefile.X11 files have been cleaned up in various ways + + + +Source File Changes +------------------- + +The mmath.[ch] files are obsolete. Their contents have been moved +into the imports.[ch] and macros.[ch] files. + +The files related to vertex and fragment programming have changed. +Old files: + vpexec.[ch] + vpparse.[ch] + vpstate.[ch] +New files: + program.[ch] - generic ARB/NV program code + arbprogram.[ch] - ARB program API functions + arbfragparse.[ch] - ARB fragment program parsing + arbvertparse.[ch] - ARB vertex program parsing + arbparse.[ch] - ARB vertex/fragment parsing + arbparse_syn.h - vertex/fragment program syntax + nvprogram.[ch] - NV program API functions + nvvertprog.h - NV vertex program definitions + nvfragprog.h - NV fragment program definitions + nvvertparse.[ch] - NV vertex program parser + nvfragparse.[ch] - NV fragment program parser + nvvertexec.[ch] - NV vertex program execution + swrast/s_nvfragprog.[ch] - NV fragment program execution + +The files related to per-vertex handling have changed. +Old files: + tnl/t_eval_api.c - old per-vertex code + tnl/t_imm_alloc.c - old per-vertex code + tnl/t_imm_api.c - old per-vertex code + tnl/t_imm_debug.c - old per-vertex code + tnl/t_imm_dlist.c - old per-vertex code + tnl/t_imm_elt.c - old per-vertex code + tnl/t_imm_eval.c - old per-vertex code + tnl/t_imm_exec.c - old per-vertex code + tnl/t_imm_fixup.c - old per-vertex code + tnl/t_vtx_sse.c - old per-vertex code + tnl/t_vtx_x86.c - old per-vertex code +New files: + tnl/t_save_api.c - new per-vertex code + tnl/t_save_loopback.c - new per-vertex code + tnl/t_save_playback.c - new per-vertex code + tnl/t_vtx_eval.c - old per-vertex code + +Other new files: + bufferobj.[ch] - GL_ARB_vertex_buffer_object functions + version.h - defines the Mesa version info + +Other removed files: + swrast/s_histogram.[ch] - moved into src/histogram.c + + + +Other Changes +------------- + +The ctx->Driver.CreateTexture function has been removed - it wasn't used. + +New device driver hook functions: + NewTextureObject - used to allocate struct gl_texture_objects + NewTextureImage - used to allocate struct gl_texture_images + +New ctx->Texture._EnabledCoordUnits field: + With the addition of GL_NV_fragment_program we may need to interpolate + various sets of texture coordinates even when the corresponding texture + unit is not enabled. That is, glEnable(GL_TEXTURE_xD) may never get + called but we still may have to interpolate texture coordinates across + triangles so that the fragment program will get them. + This new field indicates which sets of texture coordinates are needed. + If a bit is set in the ctx->Texture._EnabledUnits bitmask is set, the + same bit MUST be set in ctx->Texture._EnabledCoordUnits. + +The ctx->_TriangleCaps field is deprecated. + Instead of testing the DD_* bits in _TriangleCaps, you should instead + directly test the relevant state variables, or use one of the helper + functions like NEED_SECONDARY_COLOR() at the bottom of context.h + While testing _TriangleCaps bits was fast, it was kludgey, and setting + the bits in the first place could be error prone. + +New vertex processing code. + The code behind glBegin, glEnd, glVertex, glNormal, etc. has been + totally rewritten. It's a cleaner implementation now and should use + less memory. (Keith) + + + +To Do +----- +Add screen-awareness to fakeglx.c + + + + +Device Driver Status +-------------------- + +A number of Mesa's software drivers haven't been actively maintained for +some time. We rely on volunteers to maintain many of these drivers. +Here's the current status of all included drivers: + + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.4 +OSMesa (off-screen) implements OpenGL 1.4 +FX (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.4 +DJGPP implements OpenGL 1.4 +GGI implements OpenGL 1.3 +BeOS implements OpenGL 1.4 +Allegro needs updating +D3D needs updating + +Note: supporting OpenGL 1.4 (vs. 1.3 or 1.2) usually only requires that the +driver call the _mesa_enable_1_4_extensions() function. + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-6.0 b/docs/RELNOTES-6.0 new file mode 100644 index 0000000..1a3c2fb --- /dev/null +++ b/docs/RELNOTES-6.0 @@ -0,0 +1,86 @@ + + Mesa 6.0 release notes + + January 16, 2004 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 5.1) designate new developmental releases. +Even numbered versions (such as 6.0) designate stable releases. + +Mesa version 6.0 signifies two things: + + 1. A stabilization of the 5.1 development release + 2. Implementation of the OpenGL 1.5 specification. When you query + glGetString(GL_VERSION) "1.5" will be returned (as long as the + driver supports all the required features). + + +Note that the Mesa major version number is incremented with the OpenGL +minor version number: + + Mesa 1.x == OpenGL 1.0 + Mesa 2.x == OpenGL 1.1 + Mesa 3.x == OpenGL 1.2 + Mesa 4.x == OpenGL 1.3 + Mesa 5.x == OpenGL 1.4 + Mesa 6.x == OpenGL 1.5 + + + +New Features +------------ + +Mesa 5.1 already had all the new features of OpenGL 1.5, implemented as +extensions. These extensions were simply promoted to standard features: + + GL_ARB_occlusion_query extension + GL_ARB_texture_non_power_of_two extension + GL_ARB_vertex_buffer_object extension + GL_EXT_shadow_funcs + + + +Device Drivers +-------------- + +Mesa advertises itself as either OpenGL 1.2 or OpenGL 1.3 depending on +the device driver. For example, if the driver enables all the ARB +extensions which are part of OpenGL 1.3 then glGetString(GL_VERSION) +will return "1.3". Otherwise, it'll return "1.2". + +A number of Mesa's software drivers haven't been actively maintained for +some time. We rely on volunteers to maintain many of the drivers. +Here's the current status of all included drivers: + + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.5 +OSMesa (off-screen) implements OpenGL 1.5 +FX (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.5 +DJGPP implements OpenGL 1.5 +GGI implements OpenGL 1.3 +BeOS implements OpenGL 1.5 +Allegro needs updating +D3D needs updating + + + + +Other Changes +------------- + +See the VERSIONS file for more details about bug fixes, etc. in Mesa 6.0. + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-6.0.1 b/docs/RELNOTES-6.0.1 new file mode 100644 index 0000000..1444b9f --- /dev/null +++ b/docs/RELNOTES-6.0.1 @@ -0,0 +1,49 @@ + + Mesa 6.0.1 release notes + + April 2, 2003 + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Even-numbered versions (such as 6.0.x) designate stable releases. +Odd-numbered versions (such as 6.1.x) designate new developmental releases. + +Mesa 6.0.1 just fixes bugs found since the 6.0 release. See the VERSIONS +file for details. + + + +Device Drivers +-------------- + +Mesa advertises itself as supporting OpenGL 1.2, 1.3, 1.4 or 1.5 +depending on the device driver's capabilities. For example, if the +driver enables all the ARB extensions which are part of OpenGL 1.5 +then glGetString(GL_VERSION) will return "1.5". Otherwise, it'll +return "1.4" or the next lower version that implements all required +functionality. + +A number of Mesa's software drivers haven't been actively maintained for +some time. We rely on volunteers to maintain many of the drivers. +Here's the current status of all included drivers: + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.5 +OSMesa (off-screen) implements OpenGL 1.5 +FX (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.5 +DJGPP implements OpenGL 1.5 +GGI implements OpenGL 1.3 +BeOS implements OpenGL 1.5 +Allegro needs updating +D3D needs updating + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-6.1 b/docs/RELNOTES-6.1 new file mode 100644 index 0000000..8de64d1 --- /dev/null +++ b/docs/RELNOTES-6.1 @@ -0,0 +1,111 @@ + + Mesa 6.1 release notes + + August 18, 2004 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 6.1) designate new developmental releases. +Even numbered versions (such as 6.0) designate stable releases. + + +New Features +------------ + +Half-precision floating point (GLhalf) pixel formats are supported +in Mesa, but the feature isn't exposed yet since the ARB extension +hasn't been finalized yet. + + +Texture image handling +---------------------- + +The code which implements image conversion, pixel transfer ops, etc +for glTexImage commands has been rewritten. + +Now the gl_texture_format struct has a new StoreImage function +pointer. Each texture format must implement this function. The +function is totally responsible for converting the user's texture +image into the specific format. A few helper functions makes this +relatively simple. + +Overall, the code is much simpler, cleaner and easier to work with +now. Adding new texture formats is straight-forward and there's no +longer any distinction between "hardware" and "software" formats. + +Finally, the code for compressed texture images has been reorganized +as well. + +Removed files: + texutil.c + texutil.h + texutil_tmp.h + +New files: + texcompress_s3tc.c + texcompress_fxt1.c + + + +Driver / context changes +------------------------ + +The _mesa_create_context() and _mesa_initialize_context() function +parameters have changed. They now take a pointer to a struct +dd_function_table. Drivers can initialize this table by calling +_mesa_init_driver_functions(). Drivers should then plug in the special +functions they implement. In particular, the ctx->Driver.NewTextureObject +pointer _must_ be set so that the default texture objects created in +_mesa_create/initialize_context() are correctly built. + +The _mesa_init_driver_functions() function allows a lot of redundant code +to be removed from the device drivers (such as initializing +ctx->Driver.Accum to point to _swrast_Accum). Adding new functions to +the dd_function_table can be done with less hassle since the pointer can +be initialized in _mesa_init_driver_functions() rather than in _all_ the +drivers. + + +Device Drivers +-------------- + +Mesa advertises itself as supporting OpenGL 1.2, 1.3, 1.4 or 1.5 +depending on the device driver's capabilities. For example, if the +driver enables all the ARB extensions which are part of OpenGL 1.5 +then glGetString(GL_VERSION) will return "1.5". Otherwise, it'll +return "1.4" or the next lower version that implements all required +functionality. + +A number of Mesa's software drivers haven't been actively maintained for +some time. We rely on volunteers to maintain many of the drivers. +Here's the current status of all included drivers: + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.5 +OSMesa (off-screen) implements OpenGL 1.5 +Glide (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.5 +DJGPP implements OpenGL 1.5 +GGI implements OpenGL 1.3 +BeOS implements OpenGL 1.5 +Allegro needs updating +D3D needs updating + + + +Other Changes +------------- + +See the VERSIONS file for more details about bug fixes, etc. in Mesa 6.1. + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-6.2 b/docs/RELNOTES-6.2 new file mode 100644 index 0000000..06cfba0 --- /dev/null +++ b/docs/RELNOTES-6.2 @@ -0,0 +1,51 @@ + + Mesa 6.2 release notes + + October 2, 2004 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 6.1) designate new developmental releases. +Even numbered versions (such as 6.2) designate stable releases. + + +This release primarily just fixes bugs found in the Mesa 6.1 release. +See the VERSIONS file for details. + + +ToDo: PBO for polygon stipple, convolution filter, etc. + + + +Known Issues +------------ + +The GL_EXT_pixel_buffer_object extension isn't fully implemented for +functions like glPolygonStipple, glConvolutionFilter, glColorTable, +etc. The important functions like glRead/DrawPixels, glTex[Sub]Image, +and glBitmap work with PBOs. + + + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.5 +OSMesa (off-screen) implements OpenGL 1.5 +Glide (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.5 +DJGPP implements OpenGL 1.5 +GGI implements OpenGL 1.3 +BeOS implements OpenGL 1.5 +Allegro needs updating +D3D needs updating + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-6.2.1 b/docs/RELNOTES-6.2.1 new file mode 100644 index 0000000..c7baa5d --- /dev/null +++ b/docs/RELNOTES-6.2.1 @@ -0,0 +1,49 @@ + + Mesa 6.2.1 release notes + + December 9, 2004 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 6.1) designate new developmental releases. +Even numbered versions (such as 6.2.x) designate stable releases. + + +This release primarily just fixes bugs found in the Mesa 6.2 release. +See the VERSIONS file for details. + + + +Known Issues +------------ + +The GL_EXT_pixel_buffer_object extension isn't fully implemented for +functions like glPolygonStipple, glConvolutionFilter, glColorTable, +etc. The important functions like glRead/DrawPixels, glTex[Sub]Image, +and glBitmap work with PBOs. This has been fixed for Mesa 6.3. + + + + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.5 +OSMesa (off-screen) implements OpenGL 1.5 +Glide (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.5 +DJGPP implements OpenGL 1.5 +GGI implements OpenGL 1.3 +BeOS implements OpenGL 1.5 +Allegro needs updating +D3D needs updating + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-6.3 b/docs/RELNOTES-6.3 new file mode 100644 index 0000000..6b4dfaa --- /dev/null +++ b/docs/RELNOTES-6.3 @@ -0,0 +1,114 @@ + + Mesa 6.3 release notes + + July 20, 2005 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 6.3) designate new developmental releases. +Even numbered versions (such as 6.2) designate stable releases. + + + +New Features +------------ + +GL_ARB_draw_buffers - allows a fragment program to write to a number of + separate color buffers, instead of just one. + +GL_OES_read_format - allows one to query the fastest glReadPixels format + and datatype. + +GL_ARB_pixel_buffer_object - buffer objects for pixel read/write functions. + +GL_EXT_framebuffer_object - allows render-to-texture and provides a + window-system indepedent Pbuffer facility. + The Mesa CVS tree contains a couple tests of this extension. + +DirectFB driver, contributed by Claudio Ciccani. See docs/README.directfb +for details. + + + +Vertex/Fragment Program PRINT Instruction +----------------------------------------- + +The GL_NV_vertex_program and GL_NV_fragment_program languages have been +extended with a PRINT instruction. + + + +glDeleteTextures(), glDeletePrograms() and glDeleteBuffers() Changed +-------------------------------------------------------------------- + +To match the behaviour of other OpenGL implementations, glDeleteTextures, +glDeletePrograms and glDeleteBuffers have been modified so that: + + * The named texture/program/buffer ID is immediately freed for re-use. + + * The actual texture object, program or buffers isn't really deleted until + it is no longer bound in any rendering context (the reference count + is zero). + +Previously, the texture/program/buffer ID wasn't freed until the object +was really deleted. + +Note that textures, programs and buffers can be shared by several rendering +contexts so they can't be deleted until they're unbound in _all_ contexts. + + + +GL_EXT_framebuffer_object changes +--------------------------------- + +Implementing this extension involved changing a lot of code (for the better). + +The gl_framebuffer object now a collection of gl_renderbuffer objects. +Renderbuffers may store colors, stencil indices, or depth values. The +gl_framebuffer and gl_renderbuffer types are object-oriented in design. + +All the old RGB, color index, stencil and depth-related span functions for +reading/writing pixels from/to buffers has changed. Now, all pixels are +read/written through a set of common renderbuffer functions (methods). + +Most device drivers have been updated for these changes, but some haven't. + + + +To Do (someday) items +--------------------- + Switch to freeglut + Increase MAX_DRAWBUFFERS + driver hooks for BeginQuery/EndQuery + + + +Miscellaneous +------------- + +The main/get.c file is now generated with a Python script (get_gen.py). + + + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.5 +OSMesa (off-screen) implements OpenGL 1.5 +Glide (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.5 +DJGPP implements OpenGL 1.5 +GGI implements OpenGL 1.3 +BeOS implements OpenGL 1.5 +Allegro needs updating +D3D needs updating + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-6.3.1 b/docs/RELNOTES-6.3.1 new file mode 100644 index 0000000..eacc952 --- /dev/null +++ b/docs/RELNOTES-6.3.1 @@ -0,0 +1,48 @@ + + Mesa 6.3.1 release notes + + July XX, 2005 + + PLEASE READ!!!! + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 6.3) designate new developmental releases. +Even numbered versions (such as 6.2) designate stable releases. + + + +DRI drivers +----------- + +This release includes the DRI drivers and GLX code for hardware rendering. + + + +Bug fixes +--------- + +Bugs fixed in 6.3.1 are listed in the VERSIONS file. + + + +Driver Status +---------------------- --------------------- +XMesa (Xlib) implements OpenGL 1.5 +OSMesa (off-screen) implements OpenGL 1.5 +Glide (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.5 +DJGPP implements OpenGL 1.5 +GGI implements OpenGL 1.3 +BeOS implements OpenGL 1.5 +Allegro needs updating +D3D needs updating + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-6.3.2 b/docs/RELNOTES-6.3.2 new file mode 100644 index 0000000..e5243ef --- /dev/null +++ b/docs/RELNOTES-6.3.2 @@ -0,0 +1,36 @@ + + Mesa 6.3.2 Release Notes + + August 19, 2005 + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 6.3) designate new developmental releases. +Even numbered versions (such as 6.2) designate stable releases. + + +6.3.2 is primarily a bug-fix release. See the VERSIONS file for details. + + + +Driver Status +---------------------- ---------------------- +DRI drivers varies with the driver +XMesa (Xlib) implements OpenGL 1.5 +OSMesa (off-screen) implements OpenGL 1.5 +Glide (3dfx Voodoo1/2) implements OpenGL 1.3 +SVGA implements OpenGL 1.3 +Wind River UGL implements OpenGL 1.3 +Windows/Win32 implements OpenGL 1.5 +DJGPP implements OpenGL 1.5 +GGI implements OpenGL 1.3 +BeOS implements OpenGL 1.5 +Allegro needs updating +D3D needs updating + + +---------------------------------------------------------------------- diff --git a/docs/RELNOTES-6.4 b/docs/RELNOTES-6.4 new file mode 100644 index 0000000..1a945a1 --- /dev/null +++ b/docs/RELNOTES-6.4 @@ -0,0 +1,49 @@ + + Mesa 6.4 Release Notes + + October 24, 2005 + + + +Introduction +------------ + +Mesa uses an even/odd version number scheme like the Linux kernel. +Odd numbered versions (such as 6.3) designate new developmental releases. +Even numbered versions (such as 6.4) designate stable releases. + + +6.4 is a bug-fix release. See the VERSIONS file for details. + + + +GLUT tarball +------------ + +Starting with 6.4, the GLUT library sources are distributed in a separate +tarball. This was done at the request of Linux distro vendors who prefer +to use freeglut. + + + + +Driver Status +---------------------- ---------------------- +DRI drivers varies with the driver +XMesa (Xlib) implements OpenGL 1.5 +OSMesa (off-screen) implements OpenGL 1.5 +Windows/Win32 implements OpenGL 1.5 +Glide (3dfx Voodoo1/2) requires updates +SVGA requires updates +DJGPP requires updates +GGI requires updates +BeOS requires updates +Allegro requires updates +D3D requires updates + +The drivers which require updates mostly need to be updated to work +with the new gl_renderbuffer / gl_framebuffer infrastructure introduced +in Mesa 6.3. + + +---------------------------------------------------------------------- diff --git a/docs/autoconf.html b/docs/autoconf.html new file mode 100644 index 0000000..936ddcf --- /dev/null +++ b/docs/autoconf.html @@ -0,0 +1,289 @@ + + +Compilation and Installation using Autoconf + + + + + + +

Compilation and Installation using Autoconf

+ +
    +
  1. Basic Usage
  2. +
  3. Driver Options
  4. + +
  5. Library Options
  6. + +
  7. Demo Program Options
  8. +
+ + + +

1. Basic Usage

+ +

+The autoconf generated configure script can be used to guess your +platform and change various options for building Mesa. To use the +configure script, type: +

+ +
+    ./configure
+
+ +

+To see a short description of all the options, type ./configure +--help. If you are using a development snapshot and the configure +script does not exist, type ./autogen.sh to generate it +first. If you know the options you want to pass to +configure, you can pass them to autogen.sh. It +will run configure with these options after it is +generated. Once you have run configure and set the options +to your preference, type: +

+ +
+    make
+
+ +

+This will produce libGL.so and several other libraries depending on the +options you have chosen. Later, if you want to rebuild for a different +configuration run make realclean before rebuilding. +

+ +

+Some of the generic autoconf options are used with Mesa: + +

    +
  • --prefix=PREFIX - This is the root directory where +files will be installed by make install. The default is +/usr/local. +
  • +
  • --exec-prefix=EPREFIX - This is the root directory +where architecture-dependent files will be installed. In Mesa, this is +only used to derive the directory for the libraries. The default is +${prefix}. +
  • +
  • --libdir=LIBDIR - This option specifies the directory +where the GL libraries will be installed. The default is +${exec_prefix}/lib. It also serves as the name of the +library staging area in the source tree. For instance, if the option +--libdir=/usr/local/lib64 is used, the libraries will be +created in a lib64 directory at the top of the Mesa source +tree. +
  • +
  • --enable-static, --disable-shared - By default, Mesa +will build shared libraries. Either of these options will force static +libraries to be built. It is not currently possible to build static and +shared libraries in a single pass. +
  • +
  • CC, CFLAGS, CXX, CXXFLAGS - These environment variables +control the C and C++ compilers used during the build. By default, +gcc and g++ are used with the options +"-g -O2". +
  • +
  • LDFLAGS - An environment variable specifying flags to +pass when linking programs. These are normally empty, but can be used +to direct the linker to use libraries in nonstandard directories. For +example, LDFLAGS="-L/usr/X11R6/lib". +
  • +
  • PKG_CONFIG_PATH - When available, the +pkg-config utility is used to search for external libraries +on the system. This environment variable is used to control the search +path for pkg-config. For instance, setting +PKG_CONFIG_PATH=/usr/X11R6/lib/pkgconfig will search for +package metadata in /usr/X11R6 before the standard +directories. +
  • +
+

+ +

+There are also a few general options for altering the Mesa build: +

    +
  • --with-x - When the X11 development libraries are +needed, the pkg-config utility will +be used for locating them. If they cannot be found through +pkg-config a fallback routing using imake will +be used. In this case, the --with-x, +--x-includes and --x-libraries options can +control the use of X for Mesa. +
  • +
  • --enable-gl-osmesa - The OSMesa +library can be built on top of libGL for drivers that provide it. +This option controls whether to build libOSMesa. By default, this is +enabled for the Xlib driver and disabled otherwise. Note that this +option is different than using OSMesa as the driver. +
  • +
  • --enable-debug - This option will enable compiler +options and macros to aid in debugging the Mesa libraries. +
  • +
  • --disable-asm - There are assembly routines +available for a few architectures. These will be used by default if +one of these architectures is detected. This option ensures that +assembly will not be used. +
  • +
  • --enable-32-bit, --enable-64-bit - By default, the +build will compile code as directed by the environment variables +CC, CFLAGS, etc. If the compiler is +gcc, these options offer a helper to add the compiler flags +to force 32- or 64-bit code generation as used on the x86 and x86_64 +architectures. +
  • +
+

+ + + +

2. Driver Options

+ +

+There are several different driver modes that Mesa can use. These are +described in more detail in the basic +installation instructions. The Mesa driver is controlled through the +configure option --with-driver. There are currently three supported +options in the configure script. +

+ + + + + +

3. Library Options

+ +

+The configure script provides more fine grained control over the GL +libraries that will be built. More details on the specific GL libraries +can be found in the basic installation +instructions. + +

+

+ + +
+

4. Demo Program Options

+ +

+There are many demonstration programs in the MesaDemos tarball. If the +programs are available when ./configure is run, a subset of +the programs will be built depending on the driver and library options +chosen. See the directory progs for the full set of demos. + +

    +
  • --with-demos=DEMOS,DEMOS,... - This option allows a +specific set of demo programs to be built. For example, +--with-demos="xdemos,slang". Beware that if this option is +used, it will not be ensured that the necessary GL libraries will be +available. +
  • +
  • --without-demos - This completely disables building the +demo programs. It is equivalent to --with-demos=no. +
  • +
+

+ + + diff --git a/docs/banner.html b/docs/banner.html new file mode 100644 index 0000000..9cb27bb --- /dev/null +++ b/docs/banner.html @@ -0,0 +1,27 @@ + + + + Banner + + +
+ + + + + + + + +
+

+
The +Mesa 3D Graphics Library +

+
+


+

+
+ + diff --git a/docs/bugs.html b/docs/bugs.html new file mode 100644 index 0000000..4397339 --- /dev/null +++ b/docs/bugs.html @@ -0,0 +1,53 @@ + + +Mesa Bug Reporting + + + + + +

Bug Database

+ +

+The Mesa bug database is hosted on +freedesktop.org. +The old bug database on SourceForge is no longer used. +

+ +

+To file a Mesa bug, go to + +Bugzilla on freedesktop.org +

+ +

+Please follow these bug reporting guidelines: +

+ +
    +
  • Check if a new version of Mesa is available which might have fixed +the problem. +
  • Check if your bug is already reported in the database. +
  • Monitor your bug report for requests for additional information, etc. +
  • If you're reporting a crash, try to use your debugger (gdb) to get a stack +trace. Also, recompile Mesa in debug mode to get more detailed information. +
  • Describe in detail how to reproduce the bug, especially with games +and applications that the Mesa developers might not be familiar with. +
  • Provide a simple GLUT-based test program if possible +
+ +

+Bug reports will automatically be forwarded by bugzilla to the Mesa +developer's mailing list. +

+ +

+The easier a bug is to reproduce, the sooner it will be fixed. +Please do everything you can to facilitate quickly fixing bugs. +If your bug report is vague or your test program doesn't compile +easily, the problem may not be fixed very quickly. +

+ + + diff --git a/docs/cell.html b/docs/cell.html new file mode 100644 index 0000000..30626b6 --- /dev/null +++ b/docs/cell.html @@ -0,0 +1,138 @@ + + +Cell Driver + + + + + +

Mesa/Gallium Cell Driver

+ +

+The Mesa +Cell +driver is part of the +Gallium3D +architecture. +Tungsten Graphics did the original implementation of the Cell driver. +

+ + +

Source Code

+ +

+The latest Cell driver source code is on the master branch of the Mesa +git repository. +

+

+To build the driver you'll need the IBM Cell SDK (version 2.1 or 3.0). +To use the driver you'll need a Cell system, such as a PS3 running Linux, +or the Cell Simulator (untested, though). +

+ +

+If using Cell SDK 2.1, see the configs/linux-cell file for some +special changes. +

+ +

+To compile the code, run make linux-cell. +Or to build in debug mode, run make linux-cell-debug. +

+ +

+To use the library, make sure your current directory is the top of the +Mesa tree, then set LD_LIBRARY_PATH like this: +

+  export LD_LIBRARY_PATH=$PWD/lib/gallium:$PWD/lib/
+
+ +

+Verify that the Cell driver is being used by running +progs/xdemos/glxinfo and looking for: +

+  OpenGL renderer string: Gallium 0.3, Cell on Xlib
+
+ + +

Driver Implementation Summary

+ +

+Rasterization is parallelized across the SPUs in a tiled-based manner. +Batches of transformed triangles are sent to the SPUs (actually, pulled by from +main memory by the SPUs). +Each SPU loops over a set of 32x32-pixel screen tiles, rendering the triangles +into each tile. +Because of the limited SPU memory, framebuffer tiles are paged in/out of +SPU local store as needed. +Similarly, textures are tiled and brought into local store as needed. +

+ + +

Status

+ +

+As of October 2008, the driver runs quite a few OpenGL demos. +Features that work include: +

+
    +
  • Point/line/triangle rendering, glDrawPixels +
  • 2D, NPOT and cube texture maps with nearest/linear/mipmap filtering +
  • Dynamic SPU code generation for fragment shaders, but not complete +
  • Dynamic SPU code generation for fragment ops (blend, Z-test, etc), but not complete +
  • Dynamic PPU/PPC code generation for vertex shaders, but not complete +
+

+Performance has recently improved with the addition of PPC code generation +for vertex shaders, but the code quality isn't too great yet. +

+

+Another bottleneck is SwapBuffers. It may be the limiting factor for +many simple GL tests. +

+ + + +

Debug Options

+ +

+The CELL_DEBUG env var can be set to a comma-separated list of one or +more of the following debug options: +

+
    +
  • checker - use a different background clear color for each SPU. + This lets you see which SPU is rendering which screen tiles. +
  • sync - wait/synchronize after each DMA transfer +
  • asm - print generated SPU assembly code to stdout +
  • fragops - emit fragment ops debug messages +
  • fragopfallback - don't use codegen for fragment ops +
  • cmd - print SPU commands as their received +
  • cache - print texture cache statistics when program exits +
+

+Note that some of these options may only work for linux-cell-debug builds. +

+ +

+If the GALLIUM_NOPPC env var is set, PPC code generation will not be used +and vertex shaders will be run with the TGSI interpreter. +

+

+If the GALLIUM_NOCELL env var is set, the softpipe driver will be used +intead of the Cell driver. +This is useful for comparison/validation. +

+ + + +

Contributing

+ +

+If you're interested in contributing to the effort, familiarize yourself +with the code, join the mesa3d-dev mailing list, +and describe what you'd like to do. +

+ + + + diff --git a/docs/conform.html b/docs/conform.html new file mode 100644 index 0000000..3611f8c --- /dev/null +++ b/docs/conform.html @@ -0,0 +1,695 @@ + + +Conformance + + + + + +

Conformance

+ +

+The SGI OpenGL conformance tests verify correct operation of OpenGL +implementations. I, Brian Paul, have been given a copy of the tests +for testing Mesa. The tests are not publically available. +

+

+This file has the latest results of testing Mesa with the OpenGL 1.2 +conformance tests. Testing with the preliminary OpenGL 1.3 tests has +also been done. Mesa passes all the 1.3 tests. +

+

+The tests were run using the software X11 device driver on 24-bpp +and 16-bpp displays. +

+

+Mesa 4.0 and later pass all conformance tests at all path levels. +Note that this says nothing about the conformance of hardware drivers +based upon Mesa. +

+ + +
+
+COVERAGE TESTS
+--------------
+
+Test that all API functions accept the legal parameters and reject
+illegal parameters.  The result of each test is either pass or fail.
+
+% covgl
+OpenGL Coverage Test.
+Version 1.2
+
+covgl passed.
+
+covgl passed at 1.1 level.
+
+covgl passed at 1.2 level.
+
+covgl passed for ARB_multitexture.
+
+
+% covglu
+OpenGL GLU Coverage Test.
+Version 1.3
+
+covglu passed.
+
+covglu passed at 1.1 level.
+
+
+% covglx
+OpenGL X Coverage Test.
+Version 1.1.1
+
+covglx passed.
+
+
+% primtest -v
+Open GL Primitives Test.
+Version 1.2
+
+[lots of output deleted]
+
+292159 Combinations.
+primtest passed.
+
+
+
+
+GL CONFORMANCE TEST
+===================
+
+Render test images, read them back, then test for expected results.
+
+
+----------------------------------------------------------------------
+% conform -v 2
+
+OpenGL Conformance Test
+Version 1.2
+
+Setup Report.
+    Verbose level = 2.
+    Random number seed = 1.
+    Path inactive.
+
+Visual Report.
+    Display ID = 35. Indirect Rendering.
+    Double Buffered.
+    RGBA (5, 6, 5, 0).
+    Stencil (8).
+    Depth (16).
+    Accumulation (16, 16, 16, 16).
+
+Epsilon Report.
+    zero error epsilon = 0.000122.
+    RGBA error epsilon = 0.0324, 0.016, 0.0324, 0.000122.
+    Depth buffer error epsilon = 0.000137.
+    Stencil plane error epsilon = 0.00404.
+    Accumulation error epsilon = 0.000137, 0.000137, 0.000137, 0.000137.
+
+Default State test passed.
+Must Pass test passed.
+Divide By Zero test passed.
+Viewport Clamp test passed.
+Matrix Stack test passed.
+Matrix Stack Mixing test passed.
+Vertex Order test passed.
+Transformations test passed.
+Transformation Normal test passed.
+Viewport Transformation test passed.
+Buffer Clear test passed.
+Buffer Corners test passed.
+Buffer Color test passed.
+Color Ramp test passed.
+Mask test passed.
+Buffer Invariance test passed.
+Accumulation Buffer test passed.
+Select test passed.
+Feedback test passed.
+Scissor test passed.
+Alpha Plane Function test passed.
+Stencil Plane Clear test passed.
+Stencil Plane Corners test passed.
+Stencil Plane Operation test passed.
+Stencil Plane Function test passed.
+Depth Buffer Clear test passed.
+Depth Buffer Function test passed.
+Blend test passed.
+Dither test passed.
+LogicOp Function test does not exist for an RGB visual.
+DrawPixels test passed.
+CopyPixels test passed.
+Bitmap Rasterization test passed.
+Point Rasterization test passed.
+Anti-aliased Point test passed.
+Line Rasterization test passed.
+Line Stipple test passed.
+Anti-aliased Line test passed.
+Horizontal and Vertical Line test passed.
+Triangle Rasterization test passed.
+Triangle Tile test passed.
+Triangle Stipple test passed.
+Anti-aliased Triangles test passed.
+Quad Rasterization test passed.
+Polygon Face test passed.
+Polygon Cull test passed.
+Polygon Stipple test passed.
+Polygon Edge test passed.
+Ambient Material test passed.
+Ambient Scene test passed.
+Attenuation Position test passed.
+Diffuse Light test passed.
+Diffuse Material test passed.
+Diffuse Material Normal test passed.
+Diffuse Material Positioning test passed.
+Emissive Material test passed.
+Specular Exponent test passed.
+Specular Exponent Normal test passed.
+Specular Local Eye Half Angle test passed.
+Specular Light test passed.
+Specular Material test passed.
+Specular Normal test passed.
+Spot Positioning test passed.
+Spot Exponent and Positioning test passed.
+Spot Exponent and Direction test passed.
+Fog Exponential test passed.
+Fog Linear test passed.
+Texture Decal test passed.
+Texture Border test passed.
+Mipmaps Selection test passed.
+Mipmaps Interpolation test passed.
+Display Lists test passed.
+Evaluator test passed.
+Evaluator Color test passed.
+Texture Edge Clamp test passed.
+Packed Pixels test passed.
+Texture LOD test passed.
+Rescale Normal test passed.
+Color Table test passed.
+Convolution test passed.
+Convolution Border test passed.
+Histogram test passed.
+MinMax test passed.
+MultiTexture test passed.
+
+Conform passed.
+
+----------------------------------------------------------------------
+% conform -v 2 -p 1
+
+OpenGL Conformance Test
+Version 1.2
+
+Setup Report.
+    Verbose level = 2.
+    Random number seed = 1.
+    Path level = 1.
+
+Visual Report.
+    Display ID = 35. Indirect Rendering.
+    Double Buffered.
+    RGBA (5, 6, 5, 0).
+    Stencil (8).
+    Depth (16).
+    Accumulation (16, 16, 16, 16).
+
+Epsilon Report.
+    zero error epsilon = 0.000122.
+    RGBA error epsilon = 0.0324, 0.016, 0.0324, 0.000122.
+    Depth buffer error epsilon = 0.000137.
+    Stencil plane error epsilon = 0.00404.
+    Accumulation error epsilon = 0.000137, 0.000137, 0.000137, 0.000137.
+
+Default State test passed.
+Must Pass test passed.
+Divide By Zero test passed.
+Viewport Clamp test passed.
+Matrix Stack test passed.
+Matrix Stack Mixing test passed.
+Vertex Order test passed.
+Transformations test passed.
+Transformation Normal test passed.
+Viewport Transformation test passed.
+Buffer Clear test passed.
+Buffer Corners test passed.
+Buffer Color test passed.
+Color Ramp test passed.
+Mask test passed.
+Buffer Invariance test passed.
+Accumulation Buffer test passed.
+Select test passed.
+Feedback test passed.
+Scissor test passed.
+Alpha Plane Function test passed.
+Stencil Plane Clear test passed.
+Stencil Plane Corners test passed.
+Stencil Plane Operation test passed.
+Stencil Plane Function test passed.
+Depth Buffer Clear test passed.
+Depth Buffer Function test passed.
+Blend test passed.
+Dither test passed.
+LogicOp Function test does not exist for an RGB visual.
+DrawPixels test passed.
+CopyPixels test passed.
+Bitmap Rasterization test passed.
+Point Rasterization test passed.
+Anti-aliased Point test passed.
+Line Rasterization test passed.
+Line Stipple test passed.
+Anti-aliased Line test passed.
+Horizontal and Vertical Line test passed.
+Triangle Rasterization test passed.
+Triangle Tile test passed.
+Triangle Stipple test passed.
+Anti-aliased Triangles test passed.
+Quad Rasterization test passed.
+Polygon Face test passed.
+Polygon Cull test passed.
+Polygon Stipple test passed.
+Polygon Edge test passed.
+Ambient Material test passed.
+Ambient Scene test passed.
+Attenuation Position test passed.
+Diffuse Light test passed.
+Diffuse Material test passed.
+Diffuse Material Normal test passed.
+Diffuse Material Positioning test passed.
+Emissive Material test passed.
+Specular Exponent test passed.
+Specular Exponent Normal test passed.
+Specular Local Eye Half Angle test passed.
+Specular Light test passed.
+Specular Material test passed.
+Specular Normal test passed.
+Spot Positioning test passed.
+Spot Exponent and Positioning test passed.
+Spot Exponent and Direction test passed.
+Fog Exponential test passed.
+Fog Linear test passed.
+Texture Decal test passed.
+Texture Border test passed.
+Mipmaps Selection test passed.
+Mipmaps Interpolation test passed.
+Display Lists test passed.
+Evaluator test passed.
+Evaluator Color test passed.
+Texture Edge Clamp test passed.
+Packed Pixels test passed.
+Texture LOD test passed.
+Rescale Normal test passed.
+Color Table test passed.
+Convolution test passed.
+Convolution Border test passed.
+Histogram test passed.
+MinMax test passed.
+MultiTexture test passed.
+
+Conform passed.
+
+----------------------------------------------------------------------
+% conform -v 2 -p 2
+
+OpenGL Conformance Test
+Version 1.2
+
+Setup Report.
+    Verbose level = 2.
+    Random number seed = 1.
+    Path level = 2.
+
+Visual Report.
+    Display ID = 35. Indirect Rendering.
+    Double Buffered.
+    RGBA (5, 6, 5, 0).
+    Stencil (8).
+    Depth (16).
+    Accumulation (16, 16, 16, 16).
+
+Epsilon Report.
+    zero error epsilon = 0.000122.
+    RGBA error epsilon = 0.0324, 0.016, 0.0324, 0.000122.
+    Depth buffer error epsilon = 0.000137.
+    Stencil plane error epsilon = 0.00404.
+    Accumulation error epsilon = 0.000137, 0.000137, 0.000137, 0.000137.
+
+Default State test passed.
+Must Pass test passed.
+Divide By Zero test passed.
+Viewport Clamp test passed.
+Matrix Stack test passed.
+Matrix Stack Mixing test passed.
+Vertex Order test passed.
+Transformations test passed.
+Transformation Normal test passed.
+Viewport Transformation test passed.
+Buffer Clear test passed.
+Buffer Corners test passed.
+Buffer Color test passed.
+Color Ramp test passed.
+Mask test passed.
+Buffer Invariance test passed.
+Accumulation Buffer test passed.
+Select test passed.
+Feedback test passed.
+Scissor test passed.
+Alpha Plane Function test passed.
+Stencil Plane Clear test passed.
+Stencil Plane Corners test passed.
+Stencil Plane Operation test passed.
+Stencil Plane Function test passed.
+Depth Buffer Clear test passed.
+Depth Buffer Function test passed.
+Blend test passed.
+Dither test passed.
+LogicOp Function test does not exist for an RGB visual.
+DrawPixels test passed.
+CopyPixels test passed.
+Bitmap Rasterization test passed.
+Point Rasterization test passed.
+Anti-aliased Point test passed.
+Line Rasterization test passed.
+Line Stipple test passed.
+Anti-aliased Line test passed.
+Horizontal and Vertical Line test passed.
+Triangle Rasterization test passed.
+Triangle Tile test passed.
+Triangle Stipple test passed.
+Anti-aliased Triangles test passed.
+Quad Rasterization test passed.
+Polygon Face test passed.
+Polygon Cull test passed.
+Polygon Stipple test passed.
+Polygon Edge test passed.
+Ambient Material test passed.
+Ambient Scene test passed.
+Attenuation Position test passed.
+Diffuse Light test passed.
+Diffuse Material test passed.
+Diffuse Material Normal test passed.
+Diffuse Material Positioning test passed.
+Emissive Material test passed.
+Specular Exponent test passed.
+Specular Exponent Normal test passed.
+Specular Local Eye Half Angle test passed.
+Specular Light test passed.
+Specular Material test passed.
+Specular Normal test passed.
+Spot Positioning test passed.
+Spot Exponent and Positioning test passed.
+Spot Exponent and Direction test passed.
+Fog Exponential test passed.
+Fog Linear test passed.
+Texture Decal test passed.
+Texture Border test passed.
+Mipmaps Selection test passed.
+Mipmaps Interpolation test passed.
+Display Lists test passed.
+Evaluator test passed.
+Evaluator Color test passed.
+Texture Edge Clamp test passed.
+Packed Pixels test passed.
+Texture LOD test passed.
+Rescale Normal test passed.
+Color Table test passed.
+Convolution test passed.
+Convolution Border test passed.
+Histogram test passed.
+MinMax test passed.
+MultiTexture test passed.
+
+Conform passed.
+
+----------------------------------------------------------------------
+% conform -v 2 -p 3
+
+OpenGL Conformance Test
+Version 1.2
+
+Setup Report.
+    Verbose level = 2.
+    Random number seed = 1.
+    Path level = 3.
+
+Visual Report.
+    Display ID = 35. Indirect Rendering.
+    Double Buffered.
+    RGBA (5, 6, 5, 0).
+    Stencil (8).
+    Depth (16).
+    Accumulation (16, 16, 16, 16).
+
+Epsilon Report.
+    zero error epsilon = 0.000122.
+    RGBA error epsilon = 0.0324, 0.016, 0.0324, 0.000122.
+    Depth buffer error epsilon = 0.000137.
+    Stencil plane error epsilon = 0.00404.
+    Accumulation error epsilon = 0.000137, 0.000137, 0.000137, 0.000137.
+
+Default State test passed.
+Must Pass test passed.
+Divide By Zero test passed.
+Viewport Clamp test passed.
+Matrix Stack test passed.
+Matrix Stack Mixing test passed.
+Vertex Order test passed.
+Transformations test passed.
+Transformation Normal test passed.
+Viewport Transformation test passed.
+Buffer Clear test passed.
+Buffer Corners test passed.
+Buffer Color test passed.
+Color Ramp test passed.
+Mask test passed.
+Buffer Invariance test passed.
+Accumulation Buffer test passed.
+Select test passed.
+Feedback test passed.
+Scissor test passed.
+Alpha Plane Function test passed.
+Stencil Plane Clear test passed.
+Stencil Plane Corners test passed.
+Stencil Plane Operation test passed.
+Stencil Plane Function test passed.
+Depth Buffer Clear test passed.
+Depth Buffer Function test passed.
+Blend test passed.
+Dither test passed.
+LogicOp Function test does not exist for an RGB visual.
+DrawPixels test passed.
+CopyPixels test passed.
+Bitmap Rasterization test passed.
+Point Rasterization test passed.
+Anti-aliased Point test passed.
+Line Rasterization test passed.
+Line Stipple test passed.
+Anti-aliased Line test passed.
+Horizontal and Vertical Line test passed.
+Triangle Rasterization test passed.
+Triangle Tile test passed.
+Triangle Stipple test passed.
+Anti-aliased Triangles test passed.
+Quad Rasterization test passed.
+Polygon Face test passed.
+Polygon Cull test passed.
+Polygon Stipple test passed.
+Polygon Edge test passed.
+Ambient Material test passed.
+Ambient Scene test passed.
+Attenuation Position test passed.
+Diffuse Light test passed.
+Diffuse Material test passed.
+Diffuse Material Normal test passed.
+Diffuse Material Positioning test passed.
+Emissive Material test passed.
+Specular Exponent test passed.
+Specular Exponent Normal test passed.
+Specular Local Eye Half Angle test passed.
+Specular Light test passed.
+Specular Material test passed.
+Specular Normal test passed.
+Spot Positioning test passed.
+Spot Exponent and Positioning test passed.
+Spot Exponent and Direction test passed.
+Fog Exponential test passed.
+Fog Linear test passed.
+Texture Decal test passed.
+Texture Border test passed.
+Mipmaps Selection test passed.
+Mipmaps Interpolation test passed.
+Display Lists test passed.
+Evaluator test passed.
+Evaluator Color test passed.
+Texture Edge Clamp test passed.
+Packed Pixels test passed.
+Texture LOD test passed.
+Rescale Normal test passed.
+Color Table test passed.
+Convolution test passed.
+Convolution Border test passed.
+Histogram test passed.
+MinMax test passed.
+MultiTexture test passed.
+
+Conform passed.
+
+----------------------------------------------------------------------
+% conform -v 2 -p 4
+
+OpenGL Conformance Test
+Version 1.2
+
+Setup Report.
+    Verbose level = 2.
+    Random number seed = 1.
+    Path level = 4.
+
+Visual Report.
+    Display ID = 35. Indirect Rendering.
+    Double Buffered.
+    RGBA (5, 6, 5, 0).
+    Stencil (8).
+    Depth (16).
+    Accumulation (16, 16, 16, 16).
+
+Epsilon Report.
+    zero error epsilon = 0.000122.
+    RGBA error epsilon = 0.0324, 0.016, 0.0324, 0.000122.
+    Depth buffer error epsilon = 0.000137.
+    Stencil plane error epsilon = 0.00404.
+    Accumulation error epsilon = 0.000137, 0.000137, 0.000137, 0.000137.
+
+Default State test passed.
+Must Pass test passed.
+Divide By Zero test passed.
+Viewport Clamp test passed.
+Matrix Stack test passed.
+Matrix Stack Mixing test passed.
+Vertex Order test passed.
+Transformations test passed.
+Transformation Normal test passed.
+Viewport Transformation test passed.
+Buffer Clear test passed.
+Buffer Corners test passed.
+Buffer Color test passed.
+Color Ramp test passed.
+Mask test passed.
+Buffer Invariance test passed.
+Accumulation Buffer test passed.
+Select test passed.
+Feedback test passed.
+Scissor test passed.
+Alpha Plane Function test passed.
+Stencil Plane Clear test passed.
+Stencil Plane Corners test passed.
+Stencil Plane Operation test passed.
+Stencil Plane Function test passed.
+Depth Buffer Clear test passed.
+Depth Buffer Function test passed.
+Blend test passed.
+Dither test passed.
+LogicOp Function test does not exist for an RGB visual.
+DrawPixels test passed.
+CopyPixels test passed.
+Bitmap Rasterization test passed.
+Point Rasterization test passed.
+Anti-aliased Point test passed.
+Line Rasterization test passed.
+Line Stipple test passed.
+Anti-aliased Line test passed.
+Horizontal and Vertical Line test passed.
+Triangle Rasterization test passed.
+Triangle Tile test passed.
+Triangle Stipple test passed.
+Anti-aliased Triangles test passed.
+Quad Rasterization test passed.
+Polygon Face test passed.
+Polygon Cull test passed.
+Polygon Stipple test passed.
+Polygon Edge test passed.
+Ambient Material test passed.
+Ambient Scene test passed.
+Attenuation Position test passed.
+Diffuse Light test passed.
+Diffuse Material test passed.
+Diffuse Material Normal test passed.
+Diffuse Material Positioning test passed.
+Emissive Material test passed.
+Specular Exponent test passed.
+Specular Exponent Normal test passed.
+Specular Local Eye Half Angle test passed.
+Specular Light test passed.
+Specular Material test passed.
+Specular Normal test passed.
+Spot Positioning test passed.
+Spot Exponent and Positioning test passed.
+Spot Exponent and Direction test passed.
+Fog Exponential test passed.
+Fog Linear test passed.
+Texture Decal test passed.
+Texture Border test passed.
+Mipmaps Selection test passed.
+Mipmaps Interpolation test passed.
+Display Lists test passed.
+Evaluator test passed.
+Evaluator Color test passed.
+Texture Edge Clamp test passed.
+Packed Pixels test passed.
+Texture LOD test passed.
+Rescale Normal test passed.
+Color Table test passed.
+Convolution test passed.
+Convolution Border test passed.
+Histogram test passed.
+MinMax test passed.
+MultiTexture test passed.
+
+Conform passed.
+
+
+
+GLX CONFORMANCE TEST
+====================
+
+% conformx -v 2
+
+OpenGL X Conformance Test
+Version 1.1.1
+
+Setup Report.
+    Verbose level = 2.
+    Random number seed = 1.
+    Path inactive.
+
+Visual Report.
+    Display ID = 34. Direct Rendering.
+    Double Buffered.
+    RGBA (8, 8, 8, 0).
+    Stencil (8).
+    Depth (16).
+    Accumulation (16, 16, 16, 16).
+
+Epsilon Report.
+    zero error epsilon = 0.000122.
+    RGBA error epsilon = 0.00404, 0.00404, 0.00404, 0.000122.
+    Depth buffer error epsilon = 0.000137.
+    Stencil plane error epsilon = 0.00404.
+    Accumulation error epsilon = 0.000137, 0.000137, 0.000137, 0.000137.
+
+Default State test passed.
+glReadPixels() test passed.
+Font test passed.
+
+Conformx passed.
+
+
+
+ +NOTE: conformx passes for all machine path levels (-p option). + + + + diff --git a/docs/contents.html b/docs/contents.html new file mode 100644 index 0000000..cf1661e --- /dev/null +++ b/docs/contents.html @@ -0,0 +1,105 @@ + + +Contents + + + + + + + +Documentation + + +Download / Install + + +Resources + + +User Topics + + +Developer Topics + + +Links + + +Hosted by: +
+
+Sourceforge.net +
+ + + diff --git a/docs/debugging.html b/docs/debugging.html new file mode 100644 index 0000000..2df62f5 --- /dev/null +++ b/docs/debugging.html @@ -0,0 +1,38 @@ + + +Debugging Tips + + + + + +

Debugging Tips

+ +

+ Normally Mesa (and OpenGL) records but does not notify the user of + errors. It is up to the application to call + glGetError to check for errors. Mesa supports an + environment variable, MESA_DEBUG, to help with debugging. If + MESA_DEBUG is defined, a message will be printed to stdout whenever + an error occurs. +

+ +

+ More extensive error checking is done when Mesa is compiled with the + DEBUG symbol defined. You'll have to edit the Make-config file and + add -DDEBUG to the CFLAGS line for your system configuration. You may + also want to replace any optimization flags with the -g flag so you can + use your debugger. After you've edited Make-config type 'make clean' + before recompiling. +

+

+ In your debugger you can set a breakpoint in _mesa_error() to trap Mesa + errors. +

+

+ There is a display list printing/debugging facility. See the end of + src/dlist.c for details. +

+ + + diff --git a/docs/developers.html b/docs/developers.html new file mode 100644 index 0000000..8960e7c --- /dev/null +++ b/docs/developers.html @@ -0,0 +1,49 @@ + + +Developers + + + + + +

Developers

+ +

+Both professional and volunteer developers contribute to Mesa. +

+

+VMware +employs several of the main Mesa developers including Brian Paul +and Keith Whitwell. +

+ +

+In the past, Tungsten Graphics contracts implemented many Mesa features +including: +

+
    +
  • DRI drivers for Intel i965, i945, i915 and other chips +
  • Advanced memory manager and framebuffer object support +
  • Shading language compiler and OpenGL 2.0 support +
  • MiniGLX environment +
+ +

+Other companies including +Intel +and RedHat also actively contribute to the project. +Intel has recently contributed the new GLSL compiler in Mesa 7.9. +

+ +

+LunarG can be contacted +for custom Mesa / 3D graphics development. +

+ +

+Volunteers have made significant contributions to all parts of Mesa, including +complete device drivers. +

+ + + diff --git a/docs/devinfo.html b/docs/devinfo.html new file mode 100644 index 0000000..2d1c125 --- /dev/null +++ b/docs/devinfo.html @@ -0,0 +1,221 @@ + + +Development Notes + + + + + +

Development Notes

+ + +

Adding Extentions

+ +

+To add a new GL extension to Mesa you have to do at least the following. + +

    +
  • + If glext.h doesn't define the extension, edit include/GL/gl.h and add + code like this: +
    +     #ifndef GL_EXT_the_extension_name
    +     #define GL_EXT_the_extension_name 1
    +     /* declare the new enum tokens */
    +     /* prototype the new functions */
    +     /* TYPEDEFS for the new functions */
    +     #endif
    +   
    +
  • +
  • + In the src/mesa/glapi/ directory, add the new extension functions and + enums to the gl_API.xml file. + Then, a bunch of source files must be regenerated by executing the + corresponding Python scripts. +
  • +
  • + Add a new entry to the gl_extensions struct in mtypes.h +
  • +
  • + Update the extensions.c file. +
  • +
  • + From this point, the best way to proceed is to find another extension, + similar to the new one, that's already implemented in Mesa and use it + as an example. +
  • +
  • + If the new extension adds new GL state, the functions in get.c, enable.c + and attrib.c will most likely require new code. +
  • +
+ + + +

Coding Style

+ +

+Mesa's code style has changed over the years. Here's the latest. +

+ +

+Comment your code! It's extremely important that open-source code be +well documented. Also, strive to write clean, easily understandable code. +

+ +

+3-space indentation +

+ +

+If you use tabs, set them to 8 columns +

+ +

+Brace example: +

+
+	if (condition) {
+	   foo;
+	}
+	else {
+	   bar;
+	}
+
+ +

+Here's the GNU indent command which will best approximate my preferred style: +

+
+	indent -br -i3 -npcs --no-tabs infile.c -o outfile.c
+
+ + +

+Local variable name example: localVarName (no underscores) +

+ +

+Constants and macros are ALL_UPPERCASE, with _ between words +

+ +

+Global variables are not allowed. +

+ +

+Function name examples: +

+
+	glFooBar()       - a public GL entry point (in glapi_dispatch.c)
+	_mesa_FooBar()   - the internal immediate mode function
+	save_FooBar()    - retained mode (display list) function in dlist.c
+	foo_bar()        - a static (private) function
+	_mesa_foo_bar()  - an internal non-static Mesa function
+
+ + +

Making a New Mesa Release

+ +

+These are the instructions for making a new Mesa release. +

+ +

Get latest source files

+

+Use git to get the latest Mesa files from the git repository, from whatever +branch is relevant. +

+ + +

Verify and update version info

+

+Create/edit the docs/relnotes-x.y.html file to document what's new in the release. +Add the new relnotes-x.y.html file to relnotes.html. +

+ +

+Update the MESA_MAJOR, MESA_MINOR and MESA_TINY version numbers in +configs/default. +Also update the VERSION line in the top-level Makefile. +

+ +

+Make sure the values in src/mesa/main/version.h are correct. +

+ +

+Update docs/news.html. +

+ +

+Check in all updates to git. +

+ +

+Tag the files with the release name (in the form mesa_X_Y) +with: git tag -a mesa_X_Y +Then: git push origin mesa_X_Y +

+ + +

Make the tarballs

+

+Make a symbolic link from $(DIRECTORY) to 'Mesa'. For example, +ln -s Mesa Mesa-7.5 +This is needed in order to make a correct tar file in the next step. +

+ +

+Make the distribution files. From inside the Mesa directory: +

+	make tarballs
+
+ +

+After the tarballs are created, the md5 checksums for the files will +be computed. +Add them to the docs/relnotes-X.Y.html file. +

+ +

+Copy the distribution files to a temporary directory, unpack them, +compile everything, and run some demos to be sure everything works. +

+ +

Update the website and announce the release

+

+Follow the directions on SourceForge for creating a new "release" and +uploading the tarballs. +

+ +

+Basically, to upload the tarball files with: +
+ +rsync -avP ssh Mesa*-X.Y.* USERNAME@frs.sourceforge.net:uploads/ + +

+ +

+Update the web site by copying the docs/ directory's files to +/home/users/b/br/brianp/mesa-www/htdocs/ with: +
+ +sftp USERNAME,mesa3d@web.sourceforge.net + +

+ +

+Make an announcement on the mailing lists: + +mesa-dev@lists.freedesktop.org, +mesa-users@lists.freedesktop.org +and +mesa-announce@lists.freedesktop.org +

+ + + + + diff --git a/docs/dispatch.html b/docs/dispatch.html new file mode 100644 index 0000000..e5587c1 --- /dev/null +++ b/docs/dispatch.html @@ -0,0 +1,274 @@ + + +GL Dispatch in Mesa + + + + +

GL Dispatch in Mesa

+ +

Several factors combine to make efficient dispatch of OpenGL functions +fairly complicated. This document attempts to explain some of the issues +and introduce the reader to Mesa's implementation. Readers already familiar +with the issues around GL dispatch can safely skip ahead to the overview of Mesa's implementation.

+ +

1. Complexity of GL Dispatch

+ +

Every GL application has at least one object called a GL context. +This object, which is an implicit parameter to ever GL function, stores all +of the GL related state for the application. Every texture, every buffer +object, every enable, and much, much more is stored in the context. Since +an application can have more than one context, the context to be used is +selected by a window-system dependent function such as +glXMakeContextCurrent.

+ +

In environments that implement OpenGL with X-Windows using GLX, every GL +function, including the pointers returned by glXGetProcAddress, are +context independent. This means that no matter what context is +currently active, the same glVertex3fv function is used.

+ +

This creates the first bit of dispatch complexity. An application can +have two GL contexts. One context is a direct rendering context where +function calls are routed directly to a driver loaded within the +application's address space. The other context is an indirect rendering +context where function calls are converted to GLX protocol and sent to a +server. The same glVertex3fv has to do the right thing depending +on which context is current.

+ +

Highly optimized drivers or GLX protocol implementations may want to +change the behavior of GL functions depending on current state. For +example, glFogCoordf may operate differently depending on whether +or not fog is enabled.

+ +

In multi-threaded environments, it is possible for each thread to have a +differnt GL context current. This means that poor old glVertex3fv +has to know which GL context is current in the thread where it is being +called.

+ + +

2. Overview of Mesa's Implementation

+ +

Mesa uses two per-thread pointers. The first pointer stores the address +of the context current in the thread, and the second pointer stores the +address of the dispatch table associated with that context. The +dispatch table stores pointers to functions that actually implement +specific GL functions. Each time a new context is made current in a thread, +these pointers a updated.

+ +

The implementation of functions such as glVertex3fv becomes +conceptually simple:

+ +
    +
  • Fetch the current dispatch table pointer.
  • +
  • Fetch the pointer to the real glVertex3fv function from the +table.
  • +
  • Call the real function.
  • +
+ +

This can be implemented in just a few lines of C code. The file +src/mesa/glapi/glapitemp.h contains code very similar to this.

+ +
+ + +
+void glVertex3f(GLfloat x, GLfloat y, GLfloat z)
+{
+    const struct _glapi_table * const dispatch = GET_DISPATCH();
+    
+    (*dispatch->Vertex3f)(x, y, z);
+}
Sample dispatch function
+
+ +

The problem with this simple implementation is the large amount of +overhead that it adds to every GL function call.

+ +

In a multithreaded environment, a niave implementation of +GET_DISPATCH involves a call to pthread_getspecific or a +similar function. Mesa provides a wrapper function called +_glapi_get_dispatch that is used by default.

+ +

3. Optimizations

+ +

A number of optimizations have been made over the years to diminish the +performance hit imposed by GL dispatch. This section describes these +optimizations. The benefits of each optimization and the situations where +each can or cannot be used are listed.

+ +

3.1. Dual dispatch table pointers

+ +

The vast majority of OpenGL applications use the API in a single threaded +manner. That is, the application has only one thread that makes calls into +the GL. In these cases, not only do the calls to +pthread_getspecific hurt performance, but they are completely +unnecessary! It is possible to detect this common case and avoid these +calls.

+ +

Each time a new dispatch table is set, Mesa examines and records the ID +of the executing thread. If the same thread ID is always seen, Mesa knows +that the application is, from OpenGL's point of view, single threaded.

+ +

As long as an application is single threaded, Mesa stores a pointer to +the dispatch table in a global variable called _glapi_Dispatch. +The pointer is also stored in a per-thread location via +pthread_setspecific. When Mesa detects that an application has +become multithreaded, NULL is stored in _glapi_Dispatch.

+ +

Using this simple mechanism the dispatch functions can detect the +multithreaded case by comparing _glapi_Dispatch to NULL. +The resulting implementation of GET_DISPATCH is slightly more +complex, but it avoids the expensive pthread_getspecific call in +the common case.

+ +
+ + +
+#define GET_DISPATCH() \
+    (_glapi_Dispatch != NULL) \
+        ? _glapi_Dispatch : pthread_getspecific(&_glapi_Dispatch_key)
+
Improved GET_DISPATCH Implementation
+
+ +

3.2. ELF TLS

+ +

Starting with the 2.4.20 Linux kernel, each thread is allocated an area +of per-thread, global storage. Variables can be put in this area using some +extensions to GCC. By storing the dispatch table pointer in this area, the +expensive call to pthread_getspecific and the test of +_glapi_Dispatch can be avoided.

+ +

The dispatch table pointer is stored in a new variable called +_glapi_tls_Dispatch. A new variable name is used so that a single +libGL can implement both interfaces. This allows the libGL to operate with +direct rendering drivers that use either interface. Once the pointer is +properly declared, GET_DISPACH becomes a simple variable +reference.

+ +
+ + +
+extern __thread struct _glapi_table *_glapi_tls_Dispatch
+    __attribute__((tls_model("initial-exec")));
+
+#define GET_DISPATCH() _glapi_tls_Dispatch
+
TLS GET_DISPATCH Implementation
+
+ +

Use of this path is controlled by the preprocessor define +GLX_USE_TLS. Any platform capable of using TLS should use this as +the default dispatch method.

+ +

3.3. Assembly Language Dispatch Stubs

+ +

Many platforms has difficulty properly optimizing the tail-call in the +dispatch stubs. Platforms like x86 that pass parameters on the stack seem +to have even more difficulty optimizing these routines. All of the dispatch +routines are very short, and it is trivial to create optimal assembly +language versions. The amount of optimization provided by using assembly +stubs varies from platform to platform and application to application. +However, by using the assembly stubs, many platforms can use an additional +space optimization (see below).

+ +

The biggest hurdle to creating assembly stubs is handling the various +ways that the dispatch table pointer can be accessed. There are four +different methods that can be used:

+ +
    +
  1. Using _glapi_Dispatch directly in builds for non-multithreaded +environments.
  2. +
  3. Using _glapi_Dispatch and _glapi_get_dispatch in +multithreaded environments.
  4. +
  5. Using _glapi_Dispatch and pthread_getspecific in +multithreaded environments.
  6. +
  7. Using _glapi_tls_Dispatch directly in TLS enabled +multithreaded environments.
  8. +
+ +

People wishing to implement assembly stubs for new platforms should focus +on #4 if the new platform supports TLS. Otherwise, implement #2 followed by +#3. Environments that do not support multithreading are uncommon and not +terribly relevant.

+ +

Selection of the dispatch table pointer access method is controlled by a +few preprocessor defines.

+ +
    +
  • If GLX_USE_TLS is defined, method #4 is used.
  • +
  • If PTHREADS is defined, method #3 is used.
  • +
  • If any of PTHREADS, +WIN32_THREADS, or BEOS_THREADS +is defined, method #2 is used.
  • +
  • If none of the preceeding are defined, method #1 is used.
  • +
+ +

Two different techniques are used to handle the various different cases. +On x86 and SPARC, a macro called GL_STUB is used. In the preamble +of the assembly source file different implementations of the macro are +selected based on the defined preprocessor variables. The assmebly code +then consists of a series of invocations of the macros such as: + +

+ + +
+GL_STUB(Color3fv, _gloffset_Color3fv)
+
SPARC Assembly Implementation of glColor3fv
+
+ +

The benefit of this technique is that changes to the calling pattern +(i.e., addition of a new dispatch table pointer access method) require fewer +changed lines in the assembly code.

+ +

However, this technique can only be used on platforms where the function +implementation does not change based on the parameters passed to the +function. For example, since x86 passes all parameters on the stack, no +additional code is needed to save and restore function parameters around a +call to pthread_getspecific. Since x86-64 passes parameters in +registers, varying amounts of code needs to be inserted around the call to +pthread_getspecific to save and restore the GL function's +parameters.

+ +

The other technique, used by platforms like x86-64 that cannot use the +first technique, is to insert #ifdef within the assembly +implementation of each function. This makes the assembly file considerably +larger (e.g., 29,332 lines for glapi_x86-64.S versus 1,155 lines for +glapi_x86.S) and causes simple changes to the function +implementation to generate many lines of diffs. Since the assmebly files +are typically generated by scripts (see below), this +isn't a significant problem.

+ +

Once a new assembly file is created, it must be inserted in the build +system. There are two steps to this. The file must first be added to +src/mesa/sources. That gets the file built and linked. The second +step is to add the correct #ifdef magic to +src/mesa/glapi/glapi_dispatch.c to prevent the C version of the +dispatch functions from being built.

+ + +

3.4. Fixed-Length Dispatch Stubs

+ +

To implement glXGetProcAddress, Mesa stores a table that +associates function names with pointers to those functions. This table is +stored in src/mesa/glapi/glprocs.h. For different reasons on +different platforms, storing all of those pointers is inefficient. On most +platforms, including all known platforms that support TLS, we can avoid this +added overhead.

+ +

If the assembly stubs are all the same size, the pointer need not be +stored for every function. The location of the function can instead be +calculated by multiplying the size of the dispatch stub by the offset of the +function in the table. This value is then added to the address of the first +dispatch stub.

+ +

This path is activated by adding the correct #ifdef magic to +src/mesa/glapi/glapi.c just before glprocs.h is +included.

+ +
+

4. Automatic Generation of Dispatch Stubs

+ + + diff --git a/docs/download.html b/docs/download.html new file mode 100644 index 0000000..03fa60b --- /dev/null +++ b/docs/download.html @@ -0,0 +1,103 @@ + + +Getting Mesa + + + + + +

Downloading

+ +

+Primary Mesa download site: +freedesktop.org (FTP) +

+ +

+When a new release is coming, release candidates (betas) may be found +here. +

+ + +

+The Mesa package is named MesaLib-x.y.z.{tar.bz2, tar.gz, zip} where x.y.z +is the version. There are three types of compressed archives. +

+

+There's also the MesaGLUT-x.y.z.{tar.bz2, tar.gz, zip} packages which +contain Mark Kilgard's GLUT library. +This is optional. +Most Linux distributions include an implementation of GLUT (such as freeglut). +

+

+In the past, the Mesa demos collection was distributed as +MesaDemos-x.y.z.{tar.bz2, tar.gz, zip}. +Now, the + +Mesa demos are distributed separately. +

+ + +

Unpacking

+ +

+To unpack .tar.gz files: +

+
+	tar zxf MesaLib-x.y.z.tar.gz
+
+or +
+	gzcat MesaLib-x.y.z.tar.gz | tar xf -
+
+or +
+	gunzip MesaLib-x.y.z.tar.gz ; tar xf MesaLib-x.y.z.tar
+
+

+To unpack .tar.bz2 files: +

+
+	bunzip2 -c MesaLib-x.y.z.tar.gz | tar xf -
+
+

+To unpack .zip files: +

+
+	unzip MesaLib-x.y.z.zip
+
+ + +

Contents

+ +

+After unpacking you'll have these files and directories (among others): +

+
+Makefile	- top-level Makefile for most systems
+configs/	- makefile parameter files for various systems
+include/	- GL header (include) files
+bin/		- shell scripts for making shared libraries, etc
+docs/		- documentation
+src/		- source code for libraries
+src/mesa	- sources for the main Mesa library and device drivers
+src/gallium     - sources for Gallium and Gallium drivers
+src/glu		- libGLU source code
+src/glx		- sources for building libGL with full GLX and DRI support
+src/glw		- Xt/Motif/OpenGL widget code
+
+ +If you downloaded and unpacked the MesaGLUT.x.y.z package: +
+src/glut	- GLUT library source code
+
+ +

+Proceed to the compilation and installation +instructions. +

+ + + + diff --git a/docs/egl.html b/docs/egl.html new file mode 100644 index 0000000..33e9187 --- /dev/null +++ b/docs/egl.html @@ -0,0 +1,333 @@ + + +Mesa EGL + + + + + +

Mesa EGL

+ +

The current version of EGL in Mesa implements EGL 1.4. More information +about EGL can be found at + +http://www.khronos.org/egl/.

+ +

The Mesa's implementation of EGL uses a driver architecture. The main +library (libEGL) is window system neutral. It provides the EGL +API entry points and helper functions for use by the drivers. Drivers are +dynamically loaded by the main library and most of the EGL API calls are +directly dispatched to the drivers.

+ +

The driver in use decides the window system to support.

+ +

Build EGL

+ +
    +
  1. +

    Run configure with the desired client APIs and enable +the driver for your hardware. For example

    + +
    +  $ ./configure --enable-gles2 --enable-openvg --enable-gallium-nouveau
    +
    + +

    The main library and OpenGL is enabled by default. The first option above +enables OpenGL ES 2.x. The second option enables +OpenVG.

    + +
  2. + +
  3. Build and install Mesa as usual.
  4. +
+ +

In the given example, it will build and install libEGL, +libGL, libGLESv1_CM, libGLESv2, +libOpenVG, and one or more EGL drivers.

+ +

Configure Options

+ +

There are several options that control the build of EGL at configuration +time

+ +
    +
  • --enable-egl + +

    By default, EGL is enabled. When disabled, the main library and the drivers +will not be built.

    + +
  • + +
  • --with-egl-driver-dir + +

    The directory EGL drivers should be installed to. If not specified, EGL +drivers will be installed to ${libdir}/egl.

    + +
  • + +
  • --with-egl-platforms + +

    List the platforms (window systems) to support. Its argument is a comma +seprated string such as --with-egl-platforms=x11,drm. It decides +the platforms a driver may support. The first listed platform is also used by +the main library to decide the native platform: the platform the EGL native +types such as EGLNativeDisplayType or +EGLNativeWindowType defined for.

    + +

    The available platforms are x11, drm, +fbdev, and gdi. The gdi platform can +only be built with SCons. Unless for special needs, the build system should +select the right platforms automatically.

    + +
  • + +
  • --enable-gles1 and --enable-gles2 + +

    These options enable OpenGL ES support in OpenGL. The result is one big +internal library that supports multiple APIs.

    + +
  • + +
  • --enable-gles-overlay + +

    This option enables OpenGL ES as separate internal libraries. This is an +alternative approach to enable OpenGL ES.

    + +

    This is only supported by egl_gallium. For systems using DRI +drivers, --enable-gles1 and --enable-gles2 are +suggested instead as all drivers will benefit.

    + +
  • + +
  • --enable-openvg + +

    OpenVG must be explicitly enabled by this option.

    + +
  • + +
  • --enable-gallium-egl + +

    Explicitly enable or disable egl_gallium.

    + +
  • + +
+ +

Use EGL

+ +

Demos

+ +

There are demos for the client APIs supported by EGL. They can be found in +mesa/demos repository.

+ +

Environment Variables

+ +

There are several environment variables that control the behavior of EGL at +runtime

+ +
    +
  • EGL_DRIVERS_PATH + +

    By default, the main library will look for drivers in the directory where +the drivers are installed to. This variable specifies a list of +colon-separated directories where the main library will look for drivers, in +addition to the default directory. This variable is ignored for setuid/setgid +binaries.

    + +

    This variable is usually set to test an uninstalled build. For example, one +may set

    + +
    +  $ export LD_LIBRARY_PATH=$mesa/lib
    +  $ export EGL_DRIVERS_PATH=$mesa/lib/egl
    +
    + +

    to test a build without installation

    + +
  • + +
  • EGL_DRIVER + +

    This variable specifies a full path to an EGL driver and it forces the +specified EGL driver to be loaded. It comes in handy when one wants to test a +specific driver. This variable is ignored for setuid/setgid binaries.

    + +
  • + +
  • EGL_PLATFORM + +

    This variable specifies the native platform. The valid values are the same +as those for --with-egl-platforms. When the variable is not set, +the main library uses the first platform listed in +--with-egl-platforms as the native platform.

    + +

    Extensions like EGL_MESA_drm_display define new functions to +create displays for non-native platforms. These extensions are usually used by +applications that support non-native platforms. Setting this variable is +probably required only for some of the demos found in mesa/demo repository.

    + +
  • + +
  • EGL_LOG_LEVEL + +

    This changes the log level of the main library and the drivers. The valid +values are: debug, info, warning, and +fatal.

    + +
  • + +
  • EGL_SOFTWARE + +

    For drivers that support both hardware and software rendering, setting this +variable to true forces the use of software rendering.

    + +
  • +
+ +

EGL Drivers

+ +
    +
  • egl_dri2 + +

    This driver supports both x11 and drm platforms. +It functions as a DRI driver loader. For x11 support, it talks to +the X server directly using (XCB-)DRI2 protocol.

    + +

    This driver can share DRI drivers with libGL.

    + +
  • + +
  • egl_gallium + +

    This driver is based on Gallium3D. It supports all rendering APIs and +hardwares supported by Gallium3D. It is the only driver that supports OpenVG. +The supported platforms are X11, DRM, FBDEV, and GDI.

    + +

    This driver comes with its own hardware drivers +(pipe_<hw>) and client API modules +(st_<api>).

    + +
  • + +
  • egl_glx + +

    This driver provides a wrapper to GLX. It uses exclusively GLX to implement +the EGL API. It supports both direct and indirect rendering when the GLX does. +It is accelerated when the GLX is. As such, it cannot provide functions that +is not available in GLX or GLX extensions.

    +
  • +
+ +

Packaging

+ +

The ABI between the main library and its drivers are not stable. Nor is +there a plan to stabilize it at the moment. Of the EGL drivers, +egl_gallium has its own hardware drivers and client API modules. +They are considered internal to egl_gallium and there is also no +stable ABI between them. These should be kept in mind when packaging for +distribution.

+ +

Generally, egl_dri2 is preferred over egl_gallium +when the system already has DRI drivers. As egl_gallium is loaded +before egl_dri2 when both are available, egl_gallium +may either be disabled with --disable-gallium-egl or packaged +separately.

+ +

Developers

+ +

The sources of the main library and the classic drivers can be found at +src/egl/. The sources of the egl state tracker can +be found at src/gallium/state_trackers/egl/.

+ +

The suggested way to learn to write a EGL driver is to see how other drivers +are written. egl_glx should be a good reference. It works in any +environment that has GLX support, and it is simpler than most drivers.

+ +

Lifetime of Display Resources

+ +

Contexts and surfaces are examples of display resources. They might live +longer than the display that creates them.

+ +

In EGL, when a display is terminated through eglTerminate, all +display resources should be destroyed. Similarly, when a thread is released +throught eglReleaseThread, all current display resources should be +released. Another way to destory or release resources is through functions +such as eglDestroySurface or eglMakeCurrent.

+ +

When a resource that is current to some thread is destroyed, the resource +should not be destroyed immediately. EGL requires the resource to live until +it is no longer current. A driver usually calls +eglIs<Resource>Bound to check if a resource is bound +(current) to any thread in the destroy callbacks. If it is still bound, the +resource is not destroyed.

+ +

The main library will mark destroyed current resources as unlinked. In a +driver's MakeCurrent callback, +eglIs<Resource>Linked can then be called to check if a newly +released resource is linked to a display. If it is not, the last reference to +the resource is removed and the driver should destroy the resource. But it +should be careful here because MakeCurrent might be called with an +uninitialized display.

+ +

This is the only mechanism provided by the main library to help manage the +resources. The drivers are responsible to the correct behavior as defined by +EGL.

+ +

EGL_RENDER_BUFFER

+ +

In EGL, the color buffer a context should try to render to is decided by the +binding surface. It should try to render to the front buffer if the binding +surface has EGL_RENDER_BUFFER set to +EGL_SINGLE_BUFFER; If the same context is later bound to a +surface with EGL_RENDER_BUFFER set to +EGL_BACK_BUFFER, the context should try to render to the back +buffer. However, the context is allowed to make the final decision as to which +color buffer it wants to or is able to render to.

+ +

For pbuffer surfaces, the render buffer is always +EGL_BACK_BUFFER. And for pixmap surfaces, the render buffer is +always EGL_SINGLE_BUFFER. Unlike window surfaces, EGL spec +requires their EGL_RENDER_BUFFER values to be honored. As a +result, a driver should never set EGL_PIXMAP_BIT or +EGL_PBUFFER_BIT bits of a config if the contexts created with the +config won't be able to honor the EGL_RENDER_BUFFER of pixmap or +pbuffer surfaces.

+ +

It should also be noted that pixmap and pbuffer surfaces are assumed to be +single-buffered, in that eglSwapBuffers has no effect on them. It +is desirable that a driver allocates a private color buffer for each pbuffer +surface created. If the window system the driver supports has native pbuffers, +or if the native pixmaps have more than one color buffers, the driver should +carefully attach the native color buffers to the EGL surfaces, re-route them if +required.

+ +

There is no defined behavior as to, for example, how +glDrawBuffer interacts with EGL_RENDER_BUFFER. Right +now, it is desired that the draw buffer in a client API be fixed for pixmap and +pbuffer surfaces. Therefore, the driver is responsible to guarantee that the +client API renders to the specified render buffer for pixmap and pbuffer +surfaces.

+ +

EGLDisplay Mutex

+ +The EGLDisplay will be locked before calling any of the dispatch +functions (well, except for GetProcAddress which does not take an +EGLDisplay). This guarantees that the same dispatch function will +not be called with the sample display at the same time. If a driver has access +to an EGLDisplay without going through the EGL APIs, the driver +should as well lock the display before using it. + +

TODOs

+ +
    +
  • Pass the conformance tests
  • +
  • Mixed use of OpenGL, OpenGL ES 1.1, and OpenGL ES 2.0 is supported. But +which one of libGL.so, libGLESv1_CM.so, and +libGLESv2.so should an application link to? Bad things may happen +when, say, an application is linked to libGLESv2.so and +libcairo, which is linked to libGL.so instead.
  • + +
+ + + diff --git a/docs/envvars.html b/docs/envvars.html new file mode 100644 index 0000000..cdd158c --- /dev/null +++ b/docs/envvars.html @@ -0,0 +1,156 @@ + + +Environment Variables + + + + + +

Environment Variables

+ +

+Normally, no environment variables need to be set. Most of the environment +variables used by Mesa/Gallium are for debugging purposes, but they can +sometimes be useful for debugging end-user issues. +

+ + +

LibGL environment variables

+ +
    +
  • LIBGL_DEBUG - If defined debug information will be printed to stderr. + If set to 'verbose' additional information will be printed. +
  • LIBGL_DRIVERS_PATH - colon-separated list of paths to search for DRI drivers +
  • LIBGL_ALWAYS_INDIRECT - forces an indirect rendering context/connection. +
  • LIBGL_ALWAYS_SOFTWARE - if set, always use software rendering +
  • LIBGL_NO_DRAWARRAYS - if set do not use DrawArrays GLX protocol (for debugging) +
+ + + +

Core Mesa environment variables

+ +
    +
  • MESA_NO_ASM - if set, disables all assembly language optimizations +
  • MESA_NO_MMX - if set, disables Intel MMX optimizations +
  • MESA_NO_3DNOW - if set, disables AMD 3DNow! optimizations +
  • MESA_NO_SSE - if set, disables Intel SSE optimizations +
  • MESA_DEBUG - if set, error messages are printed to stderr. For example, + if the application generates a GL_INVALID_ENUM error, a corresponding error + message indicating where the error occured, and possibly why, will be + printed to stderr.
    + If the value of MESA_DEBUG is 'FP' floating point arithmetic errors will + generate exceptions. +
  • MESA_NO_DITHER - if set, disables dithering, overriding glEnable(GL_DITHER) +
  • MESA_TEX_PROG - if set, implement conventional texture env modes with +fragment programs (intended for developers only) +
  • MESA_TNL_PROG - if set, implement conventional vertex transformation +operations with vertex programs (intended for developers only). +Setting this variable automatically sets the MESA_TEX_PROG variable as well. +
  • MESA_EXTENSION_OVERRIDE - can be used to enable/disable extensions. +A value such as "GL_EXT_foo -GL_EXT_bar" will enable the GL_EXT_foo extension +and disable the GL_EXT_bar extension. +
  • MESA_GLSL - shading language compiler options +
+ + +

Mesa Xlib driver environment variables

+ +

+The following are only applicable to the Mesa Xlib software driver. +See the Xlib software driver page for details. +

+
    +
  • MESA_RGB_VISUAL - specifies the X visual and depth for RGB mode +
  • MESA_CI_VISUAL - specifies the X visual and depth for CI mode +
  • MESA_BACK_BUFFER - specifies how to implement the back color buffer, + either "pixmap" or "ximage" +
  • MESA_GAMMA - gamma correction coefficients for red, green, blue channels +
  • MESA_XSYNC - enable synchronous X behavior (for debugging only) +
  • MESA_GLX_FORCE_CI - if set, force GLX to treat 8bpp visuals as CI visuals +
  • MESA_GLX_FX - set to either "fullscreen" for full-screen rendering, + "window" to render into a window, or "disable" to disable the Glide driver. +
  • MESA_GLX_FORCE_ALPHA - if set, forces RGB windows to have an alpha channel. +
  • MESA_GLX_DEPTH_BITS - specifies default number of bits for depth buffer. +
  • MESA_GLX_ALPHA_BITS - specifies default number of bits for alpha channel. +
+ + +

i945/i965 driver environment variables (non-Gallium)

+ +
    +
  • INTEL_STRICT_CONFORMANCE - if set to 1, enable sw fallbacks to improve + OpenGL conformance. If set to 2, always use software rendering. +
  • INTEL_NO_BLIT - if set, disable hardware-accelerated glBitmap, + glCopyPixels, glDrawPixels. +
+ + +

Radeon R300 driver environment variables (non-Gallium)

+ +
    +
  • R300_NO_TCL - if set, disable hardware-accelerated Transform/Clip/Lighting. +
+ + +

EGL environment variables

+ +

+Mesa EGL supports different sets of environment variables. See the +Mesa EGL page for the details. +

+ + +

Gallium environment variables

+ +
    +
  • GALLIUM_PRINT_OPTIONS - if non-zero, print all the Gallium environment + variables which are used, and their current values. +
  • GALLIUM_NOSSE - if non-zero, do not use SSE runtime code generation for + shader execution +
  • GALLIUM_NOPPC - if non-zero, do not use PPC runtime code generation for + shader execution +
  • GALLIUM_DUMP_CPU - if non-zero, print information about the CPU on start-up +
  • TGSI_PRINT_SANITY - if set, do extra sanity checking on TGSI shaders and + print any errors to stderr. +
  • DRAW_FSE - ??? +
  • DRAW_NO_FSE - ??? +
  • DRAW_USE_LLVM - if set to zero, the draw module will not use LLVM to execute + shaders, vertex fetch, etc. +
+ +

Softpipe driver environment variables

+
    +
  • SOFTPIPE_DUMP_FS - if set, the softpipe driver will print fragment shaders + to stderr +
  • SOFTPIPE_DUMP_GS - if set, the softpipe driver will print geometry shaders + to stderr +
  • SOFTPIPE_NO_RAST - if set, rasterization is no-op'd. For profiling purposes. +
+ + +

LLVMpipe driver environment variables

+
    +
  • LP_NO_RAST - if set LLVMpipe will no-op rasterization +
  • LP_DEBUG - a comma-separated list of debug options is acceptec. See the + source code for details. +
  • LP_PERF - a comma-separated list of options to selectively no-op various + parts of the driver. See the source code for details. +
  • LP_NUM_THREADS - an integer indicating how many threads to use for rendering. + Zero turns of threading completely. The default value is the number of CPU + cores present. +
+ + +

+Other Gallium drivers have their own environment variables. These may change +frequently so the source code should be consulted for details. +

+ + +
+
+ + + + diff --git a/docs/extensions.html b/docs/extensions.html new file mode 100644 index 0000000..91ed20e --- /dev/null +++ b/docs/extensions.html @@ -0,0 +1,35 @@ + + +Mesa Extensions + + + + + +

Mesa Extensions

+ +

+A number of extensions have been developed especially for Mesa. +The specifications follow. +

+ + + + + + + diff --git a/docs/faq.html b/docs/faq.html new file mode 100644 index 0000000..65e279a --- /dev/null +++ b/docs/faq.html @@ -0,0 +1,397 @@ + + +Mesa FAQ + + + + + + +
+

Mesa Frequently Asked Questions

+Last updated: 21 August 2006 +
+ +
+
+

Index

+1. High-level Questions and Answers +
+2. Compilation and Installation Problems +
+3. Runtime / Rendering Problems +
+4. Developer Questions +
+
+
+ + + + +

1. High-level Questions and Answers

+ +

1.1 What is Mesa?

+

+Mesa is an open-source implementation of the OpenGL specification. +OpenGL is a programming library for writing interactive 3D applications. +See the OpenGL website for more +information. +

+

+Mesa 6.x supports the OpenGL 1.5 specification. +

+ + +

1.2 Does Mesa support/use graphics hardware?

+

+Yes. Specifically, Mesa serves as the OpenGL core for the open-source DRI +drivers for XFree86/X.org. See the DRI +website for more information. +

+

+There have been other hardware drivers for Mesa over the years (such as +the 3Dfx Glide/Voodoo driver, an old S3 driver, etc) but the DRI drivers +are the modern ones. +

+ +

1.3 What purpose does Mesa serve today?

+

+Hardware-accelerated OpenGL implementations are available for most popular +operating systems today. +Still, Mesa serves at least these purposes: +

+
    +
  • Mesa is used as the core of the open-source XFree86/X.org DRI + hardware drivers. +
  • +
  • Mesa is quite portable and allows OpenGL to be used on systems + that have no other OpenGL solution. +
  • +
  • Software rendering with Mesa serves as a reference for validating the + hardware drivers. +
  • +
  • A software implementation of OpenGL is useful for experimentation, + such as testing new rendering techniques. +
  • +
  • Mesa can render images with deep color channels: 16-bit integer + and 32-bit floating point color channels are supported. + This capability is only now appearing in hardware. +
  • +
  • Mesa's internal limits (max lights, clip planes, texture size, etc) can be + changed for special needs (hardware limits are hard to overcome). +
  • +
+ + +

1.4 What's the difference between"Stand-Alone" Mesa and the DRI drivers?

+

+Stand-alone Mesa is the original incarnation of Mesa. +On systems running the X Window System it does all its rendering through +the Xlib API: +

    +
  • The GLX API is supported, but it's really just an emulation of the + real thing. +
  • The GLX wire protocol is not supported and there's no OpenGL extension + loaded by the X server. +
  • There is no hardware acceleration. +
  • The OpenGL library, libGL.so, contains everything (the programming API, + the GLX functions and all the rendering code). +
+

+

+Alternately, Mesa acts as the core for a number of OpenGL hardware drivers +within the DRI (Direct Rendering Infrastructure): +

    +
  • The libGL.so library provides the GL and GLX API functions, a GLX + protocol encoder, and a device driver loader. +
  • The device driver modules (such as r200_dri.so) contain a built-in + copy of the core Mesa code. +
  • The X server loads the GLX module. + The GLX module decodes incoming GLX protocol and dispatches the commands + to a rendering module. + For the DRI, this module is basically a software Mesa renderer. +
+ + + +

1.5 How do I upgrade my DRI installation to use a new Mesa release?

+

+This wasn't easy in the past. +Now, the DRI drivers are included in the Mesa tree and can be compiled +separately from the X server. +Just follow the Mesa compilation instructions. +

+ + +

1.6 Are there other open-source implementations of OpenGL?

+

+Yes, SGI's +OpenGL Sample Implemenation (SI) is available. +The SI was written during the time that OpenGL was originally designed. +Unfortunately, development of the SI has stagnated. +Mesa is much more up to date with modern features and extensions. +

+ +

+Vincent is +an open-source implementation of OpenGL ES for mobile devices. + +

+miniGL +is a subset of OpenGL for PalmOS devices. + +

+TinyGL is a subset of OpenGL. +

+ +

+SoftGL +is an OpenGL subset for mobile devices. +

+ +

+Chromium +isn't a conventional OpenGL implementation (it's layered upon OpenGL), +but it does export the OpenGL API. It allows tiled rendering, sort-last +rendering, etc. +

+ +

+ClosedGL is an OpenGL subset library for TI +graphing calculators. +

+ +

+There may be other open OpenGL implementations, but Mesa is the most +popular and feature-complete. +

+ + + +
+
+ + + +

2. Compilation and Installation Problems

+ + +

2.1 What's the easiest way to install Mesa?

+

+If you're using a Linux-based system, your distro CD most likely already +has Mesa packages (like RPM or DEB) which you can easily install. +

+ + +

2.2 I get undefined symbols such as bgnpolygon, v3f, etc...

+

+You're application is written in IRIS GL, not OpenGL. +IRIS GL was the predecessor to OpenGL and is a different thing (almost) +entirely. +Mesa's not the solution. +

+ + +

2.3 Where is the GLUT library?

+

+GLUT (OpenGL Utility Toolkit) is in the separate MesaGLUT-x.y.z.tar.gz file. +If you don't already have GLUT installed, you should grab the MesaGLUT +package and compile it with the rest of Mesa. +

+ + + +

2.4 What's the proper place for the libraries and headers?

+

+On Linux-based systems you'll want to follow the +Linux ABI standard. +Basically you'll want the following: +

+
    +
  • /usr/include/GL/gl.h - the main OpenGL header +
  • /usr/include/GL/glu.h - the OpenGL GLU (utility) header +
  • /usr/include/GL/glx.h - the OpenGL GLX header +
  • /usr/include/GL/glext.h - the OpenGL extensions header +
  • /usr/include/GL/glxext.h - the OpenGL GLX extensions header +
  • /usr/include/GL/osmesa.h - the Mesa off-screen rendering header +
  • /usr/lib/libGL.so - a symlink to libGL.so.1 +
  • /usr/lib/libGL.so.1 - a symlink to libGL.so.1.xyz +
  • /usr/lib/libGL.so.xyz - the actual OpenGL/Mesa library. xyz denotes the +Mesa version number. +
  • /usr/lib/libGLU.so - a symlink to libGLU.so.1 +
  • /usr/lib/libGLU.so.1 - a symlink to libGLU.so.1.3.xyz +
  • /usr/lib/libGLU.so.xyz - the OpenGL Utility library. xyz denotes the Mesa +version number. +
+

+After installing XFree86/X.org and the DRI drivers, some of these files +may be symlinks into the /usr/X11R6/ tree. +

+

+The old-style Makefile system doesn't install the Mesa libraries; it's +up to you to copy them (and the headers) to the right place. +

+

+The GLUT header and library should go in the same directories. +

+
+
+ + + +

3. Runtime / Rendering Problems

+ +

3.1 Rendering is slow / why isn't my graphics hardware being used?

+

+Stand-alone Mesa (downloaded as MesaLib-x.y.z.tar.gz) doesn't have any +support for hardware acceleration (with the exception of the 3DFX Voodoo +driver). +

+

+What you really want is a DRI or NVIDIA (or another vendor's OpenGL) driver +for your particular hardware. +

+

+You can run the glxinfo program to learn about your OpenGL +library. +Look for the GL_VENDOR and GL_RENDERER values. +That will identify who's OpenGL library you're using and what sort of +hardware it has detected. +

+

+If your DRI-based driver isn't working, go to the +DRI website for trouble-shooting information. +

+ + +

3.2 I'm seeing errors in depth (Z) buffering. Why?

+

+Make sure the ratio of the far to near clipping planes isn't too great. +Look + here for details. +

+

+Mesa uses a 16-bit depth buffer by default which is smaller and faster +to clear than a 32-bit buffer but not as accurate. +If you need a deeper you can modify the parameters to + glXChooseVisual in your code. +

+ + +

3.3 Why Isn't depth buffering working at all?

+

+Be sure you're requesting a depth buffered-visual. If you set the MESA_DEBUG +environment variable it will warn you about trying to enable depth testing +when you don't have a depth buffer. +

+

Specifically, make sure glutInitDisplayMode is being called +with GLUT_DEPTH or glXChooseVisual is being +called with a non-zero value for GLX_DEPTH_SIZE. +

+

This discussion applies to stencil buffers, accumulation buffers and +alpha channels too. +

+ + +

3.4 Why does glGetString() always return NULL?

+

+Be sure you have an active/current OpenGL rendering context before +calling glGetString. +

+ + +

3.5 GL_POINTS and GL_LINES don't touch the right pixels

+

+If you're trying to draw a filled region by using GL_POINTS or GL_LINES +and seeing holes or gaps it's because of a float-to-int rounding problem. +But this is not a bug. +See Appendix H of the OpenGL Programming Guide - "OpenGL Correctness Tips". +Basically, applying a translation of (0.375, 0.375, 0.0) to your coordinates +will fix the problem. +

+ +

3.6 How can I change the maximum framebuffer size in Mesa's +swrast backend?

+

+These can be overridden by using the --with-max-width and +--with-max-height options. The two need not be equal. +

+Do note that Mesa uses these values to size some internal buffers, +so increasing these sizes will cause Mesa to require additional +memory. Furthermore, increasing these limits beyond 4096 +may introduce rasterization artifacts; see the leading comments in +src/mesa/swrast/s_tritemp.h. +

+ +
+
+ + + +

4. Developer Questions

+ +

4.1 How can I contribute?

+

+First, join the Mesa3d-dev +mailing list. +That's where Mesa development is discussed. +

+

+The +OpenGL Specification is the bible for OpenGL implemention work. +You should read it. +

+

Most of the Mesa development work involves implementing new OpenGL +extensions, writing hardware drivers (for the DRI), and code optimization. +

+ +

4.2 How do I write a new device driver?

+

+Unfortunately, writing a device driver isn't easy. +It requires detailed understanding of OpenGL, the Mesa code, and your +target hardware/operating system. +3D graphics are not simple. +

+

+The best way to get started is to use an existing driver as your starting +point. +For a software driver, the X11 and OSMesa drivers are good examples. +For a hardware driver, the Radeon and R200 DRI drivers are good examples. +

+

The DRI website has more information about writing hardware drivers. +The process isn't well document because the Mesa driver interface changes +over time, and we seldome have spare time for writing documentation. +That being said, many people have managed to figure out the process. +

+

+Joining the appropriate mailing lists and asking questions (and searching +the archives) is a good way to get information. +

+ + +

4.3 Why isn't GL_EXT_texture_compression_s3tc implemented in Mesa?

+

+The specification for the extension +indicates that there are intellectual property (IP) and/or patent issues +to be dealt with. +

+

We've been unsucessful in getting a response from S3 (or whoever owns +the IP nowadays) to indicate whether or not an open source project can +implement the extension (specifically the compression/decompression +algorithms). +

+

+In the mean time, a 3rd party plug-in library is available. +

+ + + + diff --git a/docs/fbdev-dri.html b/docs/fbdev-dri.html new file mode 100644 index 0000000..0eea5e8 --- /dev/null +++ b/docs/fbdev-dri.html @@ -0,0 +1,343 @@ +Mesa fbdev/DRI Environment + + + + + + + +

Mesa fbdev/DRI Drivers

+
+ +

NOTE: this information is obsolete and will be removed at +a future date

+ +

1. Introduction

+ +

+The fbdev/DRI environment supports hardware-accelerated 3D rendering without +the X window system. This is typically used for embedded applications. +

+ +

+Contributors to this project include Jon Smirl, Keith Whitwell and Dave Airlie. +

+ +

+Applications in the fbdev/DRI environment use +the MiniGLX interface to choose pixel +formats, create rendering contexts, etc. It's a subset of the GLX and +Xlib interfaces allowing some degree of application portability between +the X and X-less environments. +

+ +

+Note that this environment is not well-supported and these instructions +may not be completely up to date. +

+
+ + + +

2. Compilation

+

+ +

2.1 glxproto

+ +Get glxproto.h. Copy it to the /mesa/include/GL/ directory. +

+ +

2.2 libpciaccess

+

+Check if you have libpciaccess installed: +

+ +
pkg-config --modversion pciaccess
+
+

+If not you can download the latest code from: +

+
   git clone git://anongit.freedesktop.org/git/xorg/lib/libpciaccess
+
+

+Run autogen.sh to generate a configure file. autogen.sh uses autoconf +utility. This utility may not be installed with your linux distro, +check if it is available. if not you can use your package manager or +type: +

+
sudo apt-get install autoconf
+
+The next step is to install the libpciaccess library. +
make
+make install
+
+

Now your libpciaccess.a file is saved into /usr/local/lib +directory. If you have a libpciaccess.a in /usr/lib you may simply copy +and overwrite these files. Don't forget to copy libpciaccess.pc file to +/usr/lib/pkgconfig, which is also located in /usr/local/lib/pkgconfig/. +Or you may use the following system variables: +

+
export LD_LIBRARY_PATH=/usr/local/lib
+export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
+
+ +

2.3 drm

+ +

The next step is to compile the drm. DRM consists of two seperate parts, +the DRM client library(lindrm.so) and kernel device module(such as +radeon.ko). We need to make a small change in kernel device module. So +you need to download the kernel source. You may choose the nearest +mirror from www.kernel.org, or you are using Fedora Core 5, for +example, you may need to install RPMs such as: +kernel-smp-devel-2.16.15-1.2054_FC5.i686.rpm +kernel-devel-2.6.15-1.2054_FC5.i686.rpm +etc. You can find a detailed information here. +

+ +

You will find drm_drv.c at /usr/src/LINUX-VERSION/drivers/char/drm/. Edit this code and comment out the following part: +

+ +
+   /* ||
+   ((ioctl->flags & DRM_MASTER) && !priv->master)*/
+
+Now you are ready to compile your kernel. If your kernel version is +identical to the version you have compiled, you can simply over write +your new "ko" files over older ones. If you have compiled a different +kernel, you must configure your grub or lilo to be able to boot your +new kernel.

+You'll need fbdev header files. Check with: +

+
+   ls -l /usr/include/linux/fb.
+
+

This file may be missing if you have not installed linux header files. + + +

2.4 Mesa

+ +

Get latest development Mesa sources from git repository +(currently 7.1-prerelease) +

+
+   git clone git://anongit.freedesktop.org/git/mesa/mesa
+
+ +

You will need the makedepend utility which is a part of mesa project +to build your linux-solo. You probably wont have this utility. You can +download its source from following git repulsitory: +

+
+   git clone git://anongit.freedesktop.org/git/xorg/util/makedepend
+
+ +

Get the latest stable mesa version from SourceForge (currently 7.0.3) +http://sourceforge.net/project/showfiles.php?group_id=3 +

+ +

Copy the miniglx folder from 7.1-prerelease to 7.0.3. +You may also extract GLUT to 7.0.3 version at this step. +

+ +

Edit linux-solo.conf at /conf directory, just only compile the +graphics driver you need, delete the unwanted drivers names from the +list(some drivers are causing problems...) +

+
+   while(build==0)
+   {
+     make linux-solo
+
+     There will be some missing header files, copy them from 7.1-prerelease
+   }
+
+ +

+When complete you should have the following: +

+
    +
  • lib/libGL.so - the GL library which applications link with +
  • lib/*_dri_so - DRI drivers +
  • lib/miniglx.conf - sample MiniGLX config file +
  • progs/miniglx/* - several MiniGLX sample programs +
+ +To install these files into appropriate locations in system: +
+   make install
+
+ +Now your openGL libraries are copied to /usr/local/lib and +miniglx.conf is copied to /etc. You may copy them to /usr/lib and +overwrite your old GL libraries. Or you may export following variable: + +
+   export LIBGL_DRIVERS_PATH=/usr/local/lib
+
+
+ + +

3. Using fbdev/DRI

+ +

+If an X server currently running, exit/stop it so you're working from +the console. Following command shuts down the x window and also the multi user support. +

+
+   init 1
+
+ +

Also you may define the runlevel as 1 in "/etc/inittab". Your system +will always start in single user mode and without x-window with this +option set. +

3.1 Load Kernel Modules

+ +

+You'll need to load the kernel modules specific to your graphics hardware. +Typically, this consists of the agpgart module, an fbdev driver module +and the DRM kernel module. +

+

+As root, the kernel modules can be loaded as follows: +

+ +

+If you have Intel i915/i945 hardware: +

+
   modprobe agpgart            # the AGP GART module
+   modprobe intelfb            # the Intel fbdev driver
+   modprobe i915               # the i915/945 DRI kernel module
+
+ +

+If you have ATI Radeon/R200 hardware: +

+
   modprobe agpgart            # the AGP GART module
+   modprobe radeonfb           # the Radeon fbdev driver
+   modprobe radeon             # the Radeon DRI kernel module
+
+ +

+If you have ATI Rage 128 hardware: +

+
   modprobe agpgart            # the AGP GART module
+   modprobe aty128fb           # the Rage 128 fbdev driver
+   modprobe r128               # the Rage 128 DRI kernel module
+
+ +

+If you have Matrox G200/G400 hardware: +

+
   modprobe agpgart            # the AGP GART module
+   modprobe mgafb              # the Matrox fbdev driver
+   modprobe mga                # the Matrox DRI kernel module
+
+ +

+To verify that the agpgart, fbdev and drm modules are loaded: +

+
   ls -l /dev/agpgart /dev/fb* /dev/dri
+
+

+Alternately, use lsmod to inspect the currently installed modules. +If you have problems, look at the output of dmesg. +

+ + +

3.2 Configuration File

+ +

+review/edit /etc/miniglx.conf. +Alternately, the MINIGLX_CONF environment variable can be used to +indicate the location of miniglx.conf +

+ +To determine the pciBusID value, run lspci and examine the output. +For example: +

+
   /sbin/lspci:
+   00:02.0 VGA compatible controller: Intel Corporation 82915G/GV/910GL Express Chipset Family Graphics Controller (rev 04)
+
+

+00:02.0 indicates that pciBusID should be PCI:0:2:0 +

+ + + + +

3.3 Running fbdev/DRI Programs

+ +

+Make sure your LD_LIBRARY_PATH environment variable is set to the +location of the libGL.so library. You may need to append other paths +to LD_LIBRARY_PATH if libpciaccess.so is in a non-standard location, +for example. +

+ +

+Change to the Mesa/progs/miniglx/ directory and +start the sample_server program in the background: +

+
   ./sample_server &
+
+ +

+Then try running the miniglxtest program: +

+
   ./miniglxtest
+
+

+You should see a rotating quadrilateral which changes color as it rotates. +It will exit automatically after a bit. +

+ +

+If you run other tests in the miniglx/ directory, you may want to run +them from a remote shell so that you can stop them with ctrl-C. +

+
+ + +

4.0 Troubleshooting

+ +
    +
  1. +If you try to run miniglxtest and get the following: +
    +
       [miniglx] failed to probe chipset
    +   connect: Connection refused
    +   server connection lost
    +
    +It means that the sample_server process is not running. +
    +
    +
  2. +
+ + +

5.0 Programming Information

+ +

+OpenGL/Mesa is interfaced to fbdev via the MiniGLX interface. +MiniGLX is a subset of Xlib and GLX API functions which provides just +enough functionality to setup OpenGL rendering and respond to simple +input events. +

+ +

+Since MiniGLX is a subset of the usual Xlib and GLX APIs, programs written +to the MiniGLX API can also be run on full Xlib/GLX implementations. +This allows some degree of flexibility for software development and testing. +

+ +

+However, the MiniGLX API is not binary-compatible with full Xlib/GLX. +Some of the structures are different and some macros/functions work +differently. +See the GL/miniglx.h header file for details. +

+ + + + + diff --git a/docs/games.html b/docs/games.html new file mode 100644 index 0000000..dcf5cf2 --- /dev/null +++ b/docs/games.html @@ -0,0 +1,64 @@ + + +Games + + + + + +

Games

+ + + + + + \ No newline at end of file diff --git a/docs/glfbdev-driver.html b/docs/glfbdev-driver.html new file mode 100644 index 0000000..981df7c --- /dev/null +++ b/docs/glfbdev-driver.html @@ -0,0 +1,111 @@ + + +Mesa glFBDev Driver + + + + + +

Mesa glFBDev Driver

+ + +

1. Introduction

+ +

+The GLFBDev driver interface allows one to do OpenGL rendering into a +framebuffer managed with the Linux's fbdev interface. +

+ +

+Basically, the programmer uses the fbdev functions to initialize the +graphics hardware and setup the framebuffer. +Then, using a calls to Mesa's glFBDev API functions, one can render +into the framebuffer with the OpenGL API functions. +

+ +

+Note, only software rendering is supported; there is no hardware +acceleration. +

+ + +

+The GL/glfbdev.h header file defines the glFBDev interface. +

+ +

+The progs/fbdev/glfbdevtest.c demonstrates how to use the glFBDev interface. +

+ + +

+For more information about fbdev, see the + +Framebuffer Howto +

+

+You will need at minimum, a framebuffer device, check /dev/fb0 +

+ +

2. Compilation

+ +

+To compile Mesa with support for the glFBDev interface: +

+      make realclean
+      make linux-fbdev
+
+ +

+When compilation is finished look in progs/glfbdev/ for the glfbdevtest demo. +

+

3. Permissions

+ +

+Typically /dev/fb/0 is grouped to the video group. It may be useful to add +your user to the video group so the demos will not have to be run as root. +To use fbdevglut with the prefered tty input, you should add the user to the +tty group as well +

+ +

4. Using fbdevglut

+Almost all of the programs in the progs directory use glut, and they compile with fbdevglut. + +

+To compile the redbook sample programs: +

+       cd progs/redbook
+       make
+
+

+

glut features not supported: +

  • Overlays +
  • Subwindows +
  • Input devices other than Keyboard/Mouse +
  • No support for GLUT_MULTISAMPLE, GLUT_STEREO, or GLUT_LUMINANCE +
  • Cursor and Menu Support will flicker in GLUT_SINGLE mode + +

    Keyboard input is read by opening /dev/tty and reading keycodes in medium raw mode. +

    Mouse input is read from env var MOUSE, or /dev/gpmdata and should be in ms3 format. +To forward data in this format to /dev/gpmdata, run gpm with the -Rms3 option. +

    glutInit allows glut programs to pass parameters to the glut library, currently the +following options are supported for fbdevglut: +

  • -geometry widthxheight -- This will force the resolution to be widthxheight instead of autodetecting. +The modes are read from /etc/fb.modes +

  • -bpp -- This will force the bitdepth to the one specified +

  • -vt -- This allows you to specify the virtual terminal to attach keyboard input to. It is useful to specify when running inside screen. +

  • -mousespeed -- A floating point multiplication factor to increase mouse speed +

  • -nomouse -- Disable mouse support +

  • -nokeyboard -- Disable keyboard support (this will probably break mouse support as well) +

  • -stdin -- Use stdin for input instead of attaching to kbd in medium-raw mode. +This will make it impossible to detect keypresses like Shift+Tab, you will also need to specify -gpmmouse for mouse support. This option can be used with a debugger, and it is possible to single step a program with gdb and set the FRAMEBUFFER environment variable to a different framebuffer for display. The program will not be able to handle vt switching on it's own, so it will always display. +

  • -gpmmouse -- This will attempt to connect to the /dev/gpmctl socket using liblow +for mouse data. Gpm does not provide this data when in graphics mode, so vt switching +will briefly display text. This mode typically has no initial mouse delay. +

  • -- Ignore any additional arguments +

    Notes: +

    +1. The mouse pointer flickers in single buffering mode, as it must be rendered in software. Hopefully in the future there will be a way to access hardware cursors in fbdev devices. +

    + + diff --git a/docs/glu.html b/docs/glu.html new file mode 100644 index 0000000..8adaf42 --- /dev/null +++ b/docs/glu.html @@ -0,0 +1,45 @@ + + +SGI GLU + + + + + +

    SGI SI GLU

    + +(Silicon Graphics, Inc. Sample Implementation of the OpenGL Utility library) + +

    +SGI open-sourced their OpenGL Sample Implementation (SI) in January, 2000. +This includes the GLU library. +

    + +

    +The SI GLU library implements GLU version 1.3 whereas the original +Mesa GLU library only implemented version 1.2. +We recommend using the SI GLU library instead of Mesa's GLU library +since it's more up-to-date, complete and reliable. +We're no longer developing the original Mesa GLU library. +

    + +

    +The SI GLU library code is included in the Mesa distribution. +You don't have to download it separately. +

    + + +

    +Olivier Michel has made Linux RPMs of GLU for i386 and PowerPC. +You can download them from the +download area under Miscellaneous. +

    + +

    +Visit the +OpenGL Sample Implementation home page for more information about the SI. +

    + + + diff --git a/docs/helpwanted.html b/docs/helpwanted.html new file mode 100644 index 0000000..34afe49 --- /dev/null +++ b/docs/helpwanted.html @@ -0,0 +1,74 @@ + + +Help Wanted + + + + + +

    Help Wanted / To-Do List

    + +

    +We can always use more help with the Mesa project. +Here are some specific ideas and areas where help would be appreciated: +

    + +
      +
    1. +Driver patching and testing. +Patches are often posted to the mesa3d-dev mailing list, but aren't +immediately checked into git because not enough people are testing them. +Just applying patches, testing and reporting back is helpful. +
    2. +Driver debugging. +There are plenty of open bugs in the bug database. +
    3. +Remove aliasing warnings. +Enable gcc -Wstrict-aliasing=2 -fstrict-aliasing and track down aliasing +issues in the code. +
    4. +Windows driver building, testing and maintenance. +The Visual Studio project files aren't always updated in a timely manner +when new source files are added or old ones are removed. +Fixing these tends to delay new Mesa releases. +
    5. +Maintenance and testing of lesser-used drivers. +Drivers such as DOS/DJGPP, GGI, etc that aren't being maintained are being +deprecated starting in Mesa 7.3. +
    6. +Contribute more tests to +glean. +
    7. +Automatic testing. + +It would be great if someone would set up an automated system for grabbing +the latest Mesa code and run tests (such as glean) then report issues to +the mailing list. +
    + + +

    +If you want to do something new in Mesa, first join the Mesa developer's +mailing list. +Then post a message to propose what you want to do, just to make sure +there's no issues. +

    + +

    +Anyone is welcome to contribute code to the Mesa project. +By doing so, it's assumed that you agree to the code's licensing terms. +

    + +

    +Finally: +

    + +

      +
    1. Try to write high-quality code that follows the existing style. +
    2. Use uniform indentation, write comments, use meaningful identifiers, etc. +
    3. Test your code thoroughly. Include test programs if appropriate. +
    + + + + diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..eec4d72 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,29 @@ + + + + +Mesa Home Page + + + + + + + + + + + + + + + +<p>Sorry, this site requires frame support</p> + + + + + diff --git a/docs/install.html b/docs/install.html new file mode 100644 index 0000000..bfa3bb8 --- /dev/null +++ b/docs/install.html @@ -0,0 +1,346 @@ + + +Compiling and Installing + + + + + + +

    Compiling and Installing

    + +
      +
    1. Unix / X11 + +
    2. Windows +
    3. Building with SCons +
    4. Other +
    +
    + + + +

    1. Unix/X11 Compilation and Installation

    + + +
    +

    1.1 General prerequisites for building

    + +
      +
    • lex / yacc - for building the GLSL compiler. +On Linux systems, flex and bison are used. +Versions 2.5.35 and 2.4.1, respectively, (or later) should work. +
    • +
    • python - Python is needed for building the Gallium components. +Version 2.6.4 or later should work. +
    • +
    + + +
    +

    1.2 Prerequisites for DRI and hardware acceleration

    + +

    +The following are required for DRI-based hardware acceleration with Mesa: +

    + +
      +
    • dri2proto version 1.99.3 or later +
    • Linux 2.6.28 +
    • libDRM +version 2.4.15 or later +
    • Xorg server version 1.5 or later +
    +

    + + + +

    1.3 Building with Autoconf

    + +

    +Mesa may be built using autoconf. +This should work well on most GNU-based systems. +If that fails the traditional Mesa build system is available. + + + + +

    1.4 Building with traditional Makefiles

    + +

    +The traditional Mesa build system is based on a collection of pre-defined +system configurations. +

    +

    +To see the list of configurations, just type make. +Then choose a configuration from the list and type make +configname. +

    + +

    +Mesa may be built in several different ways using the predefined configurations: +

    +
      +
    • Stand-alone/Xlib mode - Mesa will be compiled as +a software renderer using Xlib to do all rendering. +The libGL.so library will be a self-contained rendering library that will +allow you to run OpenGL/GLX applications on any X server (regardless of +whether it supports the GLX X server extension). +You will not be able to use hardware 3D acceleration. +

      +To compile stand-alone Mesa type make in the top-level directory. +You'll see a list of supported system configurations. +Choose one from the list (such as linux-x86), and type: +

      +
      +    make linux-x86
      +
      +

      This will produce libGL.so and several other libraries

      +
    • + +
    • DRI/accelerated - The DRI hardware drivers for +accelerated OpenGL rendering (for ATI, Intel, Matrox, etc) will be built. +The libGL.so library will support the GLX extension and will load/use +the DRI hardware drivers. + + +

      +Build Mesa and the DRI hardware drivers by running +

      +
      +   make linux-dri
      +
      +

      +There are also linux-dri-x86, linux-dri-x86-64, +and linux-ppc configurations which are optimized for those +architectures. +

      +

      +Make sure you have the prerequisite versions of DRM and Xserver mentioned +above. +

      + +
    • + +
    + + +

    +Later, if you want to rebuild for a different configuration run +make realclean before rebuilding. +

    + + +
    +

    1.5 The libraries

    + +

    +When compilation has finished, look in the top-level lib/ +(or lib64/) directory. +You'll see a set of library files similar to this: +

    +
    +lrwxrwxrwx    1 brian    users          10 Mar 26 07:53 libGL.so -> libGL.so.1*
    +lrwxrwxrwx    1 brian    users          19 Mar 26 07:53 libGL.so.1 -> libGL.so.1.5.060100*
    +-rwxr-xr-x    1 brian    users     3375861 Mar 26 07:53 libGL.so.1.5.060100*
    +lrwxrwxrwx    1 brian    users          11 Mar 26 07:53 libGLU.so -> libGLU.so.1*
    +lrwxrwxrwx    1 brian    users          20 Mar 26 07:53 libGLU.so.1 -> libGLU.so.1.3.060100*
    +-rwxr-xr-x    1 brian    users      549269 Mar 26 07:53 libGLU.so.1.3.060100*
    +lrwxrwxrwx    1 brian    users          12 Mar 26 07:53 libglut.so -> libglut.so.3*
    +lrwxrwxrwx    1 brian    users          16 Mar 26 07:53 libglut.so.3 -> libglut.so.3.7.1*
    +-rwxr-xr-x    1 brian    users      597754 Mar 26 07:53 libglut.so.3.7.1*
    +lrwxrwxrwx    1 brian    users          11 Mar 26 08:04 libGLw.so -> libGLw.so.1*
    +lrwxrwxrwx    1 brian    users          15 Mar 26 08:04 libGLw.so.1 -> libGLw.so.1.0.0*
    +-rwxr-xr-x    1 brian    users       20750 Mar 26 08:04 libGLw.so.1.0.0*
    +lrwxrwxrwx    1 brian    users          14 Mar 26 07:53 libOSMesa.so -> libOSMesa.so.6*
    +lrwxrwxrwx    1 brian    users          23 Mar 26 07:53 libOSMesa.so.6 -> libOSMesa.so.6.1.060100*
    +-rwxr-xr-x    1 brian    users       23871 Mar 26 07:53 libOSMesa.so.6.1.060100*
    +
    + +

    +libGL is the main OpenGL library (i.e. Mesa). +
    +libGLU is the OpenGL Utility library. +
    +libglut is the GLUT library. +
    +libGLw is the Xt/Motif OpenGL drawing area widget library. +
    +libOSMesa is the OSMesa (Off-Screen) interface library. +

    + +

    +If you built the DRI hardware drivers, you'll also see the DRI drivers: +

    +
    +-rwxr-xr-x   1 brian users 15607851 Jul 21 12:11 ffb_dri.so
    +-rwxr-xr-x   1 brian users 15148747 Jul 21 12:11 i810_dri.so
    +-rwxr-xr-x   1 brian users 14497814 Jul 21 12:11 i830_dri.so
    +-rwxr-xr-x   1 brian users 16895413 Jul 21 12:11 i915_dri.so
    +-rwxr-xr-x   1 brian users 11320803 Jul 21 12:11 mach64_dri.so
    +-rwxr-xr-x   1 brian users 11418014 Jul 21 12:12 mga_dri.so
    +-rwxr-xr-x   1 brian users 11064426 Jul 21 12:12 r128_dri.so
    +-rwxr-xr-x   1 brian users 11849858 Jul 21 12:12 r200_dri.so
    +-rwxr-xr-x   1 brian users 16050488 Jul 21 12:11 r300_dri.so
    +-rwxr-xr-x   1 brian users 11757388 Jul 21 12:12 radeon_dri.so
    +-rwxr-xr-x   1 brian users 11232304 Jul 21 12:13 s3v_dri.so
    +-rwxr-xr-x   1 brian users 11062970 Jul 21 12:13 savage_dri.so
    +-rwxr-xr-x   1 brian users 11214212 Jul 21 12:13 sis_dri.so
    +-rwxr-xr-x   1 brian users 11368736 Jul 21 12:13 tdfx_dri.so
    +-rwxr-xr-x   1 brian users 10598868 Jul 21 12:13 trident_dri.so
    +-rwxr-xr-x   1 brian users 10997120 Jul 21 12:13 unichrome_dri.so
    +
    + +

    +If you built with Gallium support, look in lib/gallium/ for Gallium-based +versions of libGL and device drivers. +

    + + + +
    +

    1.6 Installing the header and library files

    + +

    +The standard location for the OpenGL header files on Unix-type systems is +in /usr/include/GL/. +The standard location for the libraries is /usr/lib/. +For more information see, the + +Linux/OpenGL ABI specification. +

    + +

    +If you'd like Mesa to co-exist with another implementation of OpenGL that's +already installed, you'll have to choose different directories, like +/usr/local/include/GL/ and /usr/local/lib/. +

    + +

    +To install Mesa's headers and libraries, run make install. +But first, check the Mesa/configs/default file and examine the values +of the INSTALL_DIR and DRI_DRIVER_INSTALL_DIR variables. +Change them if needed, then run make install. +

    + +

    +The variable +DESTDIR may also be used to install the contents to a temporary +staging directory. +This can be useful for package management. +For example: make install DESTDIR=/somepath/ +

    + +

    +Note: at runtime you can use the LD_LIBRARY_PATH environment variable +(on Linux at least) to switch +between the Mesa libraries and other vendor's libraries whenever you want. +This is a handy way to compare multiple OpenGL implementations. +

    + + + +

    1.7 Building OpenGL programs with pkg-config

    + +

    +Running make install will install package configuration files +for the pkg-config utility. +

    + +

    +When compiling your OpenGL application you can use pkg-config to determine +the proper compiler and linker flags. +

    + +

    +For example, compiling and linking a GLUT application can be done with: +

    +
    +   gcc `pkg-config --cflags --libs glut` mydemo.c -o mydemo
    +
    + +
    + +
    +

    2. Windows Compilation and Installation

    + +

    +Please see the instructions on building with SCons. +Alternatively see README.WIN32 file. +

    + + + + +

    3. Building with SCons

    + +

    +To build Mesa with SCons on Linux or Windows do +

    +
    +    scons
    +
    +

    +The build output will be placed in +build/platform-machine-debug/..., where platform is for +example linux or windows, machine is x86 or x86_64, optionally followed +by -debug for debug builds. +

    + +

    +To build Mesa with SCons for Windows on Linux using the MinGW crosscompiler toolchain do +

    +
    +    scons platform=windows toolchain=crossmingw machine=x86 statetrackers=mesa drivers=softpipe,trace winsys=gdi
    +
    +

    +This will create: +

    +
      +
    • build/windows-x86-debug/gallium/targets/libgl-gdi/opengl32.dll — Mesa + Gallium + softpipe, binary compatible with Windows's opengl32.dll +
    • build/windows-x86-debug/glut/glx/glut32.dll +
    • progs/build/windows-x86-debug/wgl/wglinfo.exe +
    • progs/build/windows-x86-debug/trivial/tri.exe +
    • and many other samples in progs/build/windows-x86-debug/... +
    +

    +Put them all in the same directory to test them. +

    + + +
    +

    4. Other systems

    + +

    +Documentation for other environments (some may be very out of date): +

    + +
    + + + + + + diff --git a/docs/intro.html b/docs/intro.html new file mode 100644 index 0000000..0806caf --- /dev/null +++ b/docs/intro.html @@ -0,0 +1,313 @@ + + +Mesa Introduction + + + + + +

    Introduction

    + +

    +Mesa is an open-source implementation of the +OpenGL specification - +a system for rendering interactive 3D graphics. +

    + +

    +A variety of device drivers allows Mesa to be used in many different +environments ranging from software emulation to complete hardware acceleration +for modern GPUs. +

    + +

    +Mesa ties into several other open-source projects: the +Direct Rendering +Infrastructure and X.org to +provide OpenGL support to users of X on Linux, FreeBSD and other operating +systems. +

    + + + +

    Project History

    + +

    +The Mesa project was originally started by Brian Paul. +Here's a short history of the project. +

    + +

    +August, 1993: I begin working on Mesa in my spare time. The project +has no name at that point. I was simply interested in writing a simple +3D graphics library that used the then-new OpenGL API. I was partially +inspired by the VOGL library which emulated a subset of IRIS GL. +I had been programming with IRIS GL since 1991. +

    + +

    +November 1994: I contact SGI to ask permission to distribute my OpenGL-like +graphics library on the internet. SGI was generally receptive to the +idea and after negotiations with SGI's legal department, I get permission +to release it. +

    + +

    +February 1995: Mesa 1.0 is released on the internet. I expected that +a few people would be interested in it, but not thousands. +I was soon receiving patches, new features and thank-you notes on a +daily basis. That encouraged me to continue working on Mesa. The +name Mesa just popped into my head one day. SGI had asked me not to use +the terms "Open" or "GL" in the project name and I didn't +want to make up a new acronym. Later, I heard of the Mesa programming +language and the Mesa spreadsheet for NeXTStep. +

    + +

    +In the early days, OpenGL wasn't available on too many systems. +It even took a while for SGI to support it across their product line. +Mesa filled a big hole during that time. +For a lot of people, Mesa was their first introduction to OpenGL. +I think SGI recognized that Mesa actually helped to promote +the OpenGL API, so they didn't feel threatened by the project. +

    + + +

    +1995-1996: I continue working on Mesa both during my spare time and during +my work hours at the Space Science and Engineering Center at the University +of Wisconsin in Madison. My supervisor, Bill Hibbard, lets me do this because +Mesa is now being using for the Vis5D project. +

    +October 1996: Mesa 2.0 is released. It implements the OpenGL 1.1 specification. +

    + +

    +March 1997: Mesa 2.2 is released. It supports the new 3dfx Voodoo graphics +card via the Glide library. It's the first really popular hardware OpenGL +implementation for Linux. +

    + +

    +September 1998: Mesa 3.0 is released. It's the first publicly-available +implementation of the OpenGL 1.2 API. +

    + +

    +March 1999: I attend my first OpenGL ARB meeting. I contribute to the +development of several official OpenGL extensions over the years. +

    + +

    +September 1999: I'm hired by Precision Insight, Inc. Mesa is a key +component of 3D hardware acceleration in the new DRI project for XFree86. +Drivers for 3dfx, 3dLabs, Intel, Matrox and ATI hardware soon follow. +

    + +

    +October 2001: Mesa 4.0 is released. +It implements the OpenGL 1.3 specification. +

    + + +

    +November 2001: I cofounded Tungsten Graphics, Inc. with Keith Whitwell, +Jens Owen, David Dawes and Frank LaMonica. +Tungsten Graphics was acquired by VMware in December 2008. +

    + +

    +November 2002: Mesa 5.0 is released. +It implements the OpenGL 1.4 specification. +

    + +

    +January 2003: Mesa 6.0 is released. It implements the OpenGL 1.5 +specification as well as the GL_ARB_vertex_program and +GL_ARB_fragment_program extensions. +

    + +

    +June 2007: Mesa 7.0 is released, implementing the OpenGL 2.1 specification +and OpenGL Shading Language. +

    + + +

    +Ongoing: Mesa is used as the core of many hardware OpenGL drivers for +the XFree86 and X.org X servers within the +DRI project. +I continue to enhance Mesa with new extensions and features. +

    + + + +

    Major Versions

    + +

    +This is a summary of the major versions of Mesa. +Mesa's major version number has been incremented whenever a new version +of the OpenGL specification is implemented. +

    + + +

    Version 7.x features

    +

    +Version 7.x of Mesa implements the OpenGL 2.1 API. The main feature +of OpenGL 2.x is the OpenGL Shading Language. +

    + + +

    Version 6.x features

    +

    +Version 6.x of Mesa implements the OpenGL 1.5 API with the following +extensions incorporated as standard features: +

    +
      +
    • GL_ARB_occlusion_query +
    • GL_ARB_vertex_buffer_object +
    • GL_EXT_shadow_funcs +
    +

    +Also note that several OpenGL tokens were renamed in OpenGL 1.5 +for the sake of consistency. +The old tokens are still available. +

    +
    +New Token                   Old Token
    +------------------------------------------------------------
    +GL_FOG_COORD_SRC            GL_FOG_COORDINATE_SOURCE
    +GL_FOG_COORD                GL_FOG_COORDINATE
    +GL_CURRENT_FOG_COORD        GL_CURRENT_FOG_COORDINATE
    +GL_FOG_COORD_ARRAY_TYPE     GL_FOG_COORDINATE_ARRAY_TYPE
    +GL_FOG_COORD_ARRAY_STRIDE   GL_FOG_COORDINATE_ARRAY_STRIDE
    +GL_FOG_COORD_ARRAY_POINTER  GL_FOG_COORDINATE_ARRAY_POINTER
    +GL_FOG_COORD_ARRAY          GL_FOG_COORDINATE_ARRAY
    +GL_SRC0_RGB                 GL_SOURCE0_RGB
    +GL_SRC1_RGB                 GL_SOURCE1_RGB
    +GL_SRC2_RGB                 GL_SOURCE2_RGB
    +GL_SRC0_ALPHA               GL_SOURCE0_ALPHA
    +GL_SRC1_ALPHA               GL_SOURCE1_ALPHA
    +GL_SRC2_ALPHA               GL_SOURCE2_ALPHA
    +
    +

    +See the + +OpenGL specification for more details. +

    + + + +

    Version 5.x features

    +

    +Version 5.x of Mesa implements the OpenGL 1.4 API with the following +extensions incorporated as standard features: +

    +
      +
    • GL_ARB_depth_texture +
    • GL_ARB_shadow +
    • GL_ARB_texture_env_crossbar +
    • GL_ARB_texture_mirror_repeat +
    • GL_ARB_window_pos +
    • GL_EXT_blend_color +
    • GL_EXT_blend_func_separate +
    • GL_EXT_blend_logic_op +
    • GL_EXT_blend_minmax +
    • GL_EXT_blend_subtract +
    • GL_EXT_fog_coord +
    • GL_EXT_multi_draw_arrays +
    • GL_EXT_point_parameters +
    • GL_EXT_secondary_color +
    • GL_EXT_stencil_wrap +
    • GL_EXT_texture_lod_bias (plus, a per-texture LOD bias parameter) +
    • GL_SGIS_generate_mipmap +
    + + +

    Version 4.x features

    + +

    +Version 4.x of Mesa implements the OpenGL 1.3 API with the following +extensions incorporated as standard features: +

    + +
      +
    • GL_ARB_multisample +
    • GL_ARB_multitexture +
    • GL_ARB_texture_border_clamp +
    • GL_ARB_texture_compression +
    • GL_ARB_texture_cube_map +
    • GL_ARB_texture_env_add +
    • GL_ARB_texture_env_combine +
    • GL_ARB_texture_env_dot3 +
    • GL_ARB_transpose_matrix +
    + +

    Version 3.x features

    + +

    +Version 3.x of Mesa implements the OpenGL 1.2 API with the following +features: +

    +
      +
    • BGR, BGRA and packed pixel formats +
    • New texture border clamp mode +
    • glDrawRangeElements() +
    • standard 3-D texturing +
    • advanced MIPMAP control +
    • separate specular color interpolation +
    + + +

    Version 2.x features

    +

    +Version 2.x of Mesa implements the OpenGL 1.1 API with the following +features. +

    +
      +
    • Texture mapping: +
        +
      • glAreTexturesResident +
      • glBindTexture +
      • glCopyTexImage1D +
      • glCopyTexImage2D +
      • glCopyTexSubImage1D +
      • glCopyTexSubImage2D +
      • glDeleteTextures +
      • glGenTextures +
      • glIsTexture +
      • glPrioritizeTextures +
      • glTexSubImage1D +
      • glTexSubImage2D +
      +
    • Vertex Arrays: +
        +
      • glArrayElement +
      • glColorPointer +
      • glDrawElements +
      • glEdgeFlagPointer +
      • glIndexPointer +
      • glInterleavedArrays +
      • glNormalPointer +
      • glTexCoordPointer +
      • glVertexPointer +
      +
    • Client state management: +
        +
      • glDisableClientState +
      • glEnableClientState +
      • glPopClientAttrib +
      • glPushClientAttrib +
      +
    • Misc: +
        +
      • glGetPointer +
      • glIndexub +
      • glIndexubv +
      • glPolygonOffset +
      +
    + + + + diff --git a/docs/libraries.html b/docs/libraries.html new file mode 100644 index 0000000..eaeb045 --- /dev/null +++ b/docs/libraries.html @@ -0,0 +1,57 @@ + + +Libraries and Toolkits + + + + + +

    Libraries and Toolkits

    + +
      +
    • Apprentice - free OpenInventor work-alike +
    • Coin - OSS Open Inventor clone +
    • Ch - OpenGL bindings for the Ch C/C++ interpreter +
    • FOX - GUI Library +
    • GL4Java - a Java wrapper for OpenGL +
    • GtkGLArea - OpenGL Gtk widget +
    • GtkGLArea-- - OpenGL Gtk-- widget for C++ +
    • GTKpas - OpenGL Gtk widget for FreePascal +
    • FreeGLUT - a GLUT work-alike +
    • Fortran77/90 bindings for OpenGL and Mesa - by William Mitchell +
    • GLOW - a GUI toolkit for GLUT and OpenGL +
    • Glt - an OpenGL C++ toolkit +
    • GLUT (GL Utility Toolkit) - by Mark Kilgard +
    • GuileGL - OpenGL and GtkGLArea language bindings for Guile +
    • IDL - Interactive Data Language +
    • JX - C++ application framework and GUI library +
    • MAM/VRS - object-oriented toolkit for 3D graphics +
    • MINOS - GUI library +
    • OglCLib - C++ wrapper for OpenGL +
    • Open Inventor - the Open Inventor toolkit from SGI +
    • Open Inventor - the Open Inventor toolkit from Template Graphics Software, Inc. +
    • OpenRM +- Open Source, multithreaded, parallel scene graph API +
    • +Open SG PLUS - a scene-graph library +
    • Open Scene Graph + - a scene-graph library +
    • OpenVRML +- a VRML parsing/display library with "lookat" - an example VRML browser +
    • PLIB - A collection of portable games libraries, including an OpenGL GUI and a simple Scene Graph API +
    • Pryan - an OpenInventor-like toolkit +
    • PyOpenGL - OpenGL interface for Python +
    • Quesa - QuickDraw3D-compatible library based on OpenGL, Mesa or Direct3D +
    • repGL - IRIS GL emulated with OpenGL +
    • SciTech MGL - A multiplatform (Windows, Linux, OS/2, DOS, QNX, SMX, RT-Target & more) graphics library +
    • SGL - a 3D Scene Graph Library +
    • SoFree - a free implementation of Open Inventor +
    • Togl - Tcl/Tk widget for OpenGL +
    • VLE - Virtual Reality Toolkit +
    • View3D Widget - 3-D GUI widget +
    • VTK - Visualization Toolkit +
    • YAJOGL - Yet Another Java GL Binding. +
    + + + \ No newline at end of file diff --git a/docs/license.html b/docs/license.html new file mode 100644 index 0000000..44b980d --- /dev/null +++ b/docs/license.html @@ -0,0 +1,117 @@ + + +License / Cppyright Information + + + + + +

    Disclaimer

    + +

    +Mesa is a 3-D graphics library with an API which is very similar to +that of OpenGL.* +To the extent that Mesa utilizes the OpenGL command syntax or state +machine, it is being used with authorization from Silicon Graphics, +Inc.(SGI). However, the author does not possess an OpenGL license +from SGI, and makes no claim that Mesa is in any way a compatible +replacement for OpenGL or associated with SGI. Those who want a +licensed implementation of OpenGL should contact a licensed +vendor. +

    + +

    +Please do not refer to the library as MesaGL (for legal +reasons). It's just Mesa or The Mesa 3-D graphics +library.
    +

    + +

    +* OpenGL is a trademark of Silicon Graphics Incorporated. +

    + + + +

    License / Copyright Information

    + +

    +The Mesa distribution consists of several components. Different copyrights +and licenses apply to different components. For example, GLUT is copyrighted +by Mark Kilgard, some demo programs are copyrighted by SGI, some of the Mesa +device drivers are copyrighted by their authors. See below for a list of +Mesa's main components and the license for each. +

    +

    +The core Mesa library is licensed according to the terms of the MIT license. +This allows integration with the XFree86, Xorg and DRI projects. +

    +

    +The default Mesa license is as follows: +

    + +
    +Copyright (C) 1999-2007  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.
    +
    + + +

    Attention, Contributors

    + +

    +When contributing to the Mesa project you must agree to the licensing terms +of the component to which you're contributing. +The following section lists the primary components of the Mesa distribution +and their respective licenses. +

    + + +

    Mesa Component Licenses

    + +
    +Component         Location               License
    +------------------------------------------------------------------
    +Main Mesa code    src/mesa/              Mesa (MIT)
    +
    +Device drivers    src/mesa/drivers/*     MIT, generally
    +
    +Ext headers       include/GL/glext.h     Khronos
    +                  include/GL/glxext.h
    +
    +GLUT              src/glut/              Mark Kilgard's copyright
    +
    +SGI GLU library   src/glu/sgi/           SGI Free B
    +
    +demo programs     progs/demos/           see source files
    +
    +X demos           progs/xdemos/          see source files
    +
    +SGI demos         progs/samples/         SGI license
    +
    +RedBook demos     progs/redbook/         SGI license
    +
    + +

    +In general, consult the source files for license terms. +

    + + + + diff --git a/docs/lists.html b/docs/lists.html new file mode 100644 index 0000000..1487891 --- /dev/null +++ b/docs/lists.html @@ -0,0 +1,83 @@ + + +Mesa Mailing Lists + + + + + +

    Mailing Lists

    + + +

    There are four Mesa 3D / DRI mailing lists: +

    + +
      +
    • mesa-users - intended for end-users of Mesa and DRI +drivers. Newbie questions are OK, but please try the general OpenGL +resources and Mesa/DRI documentation first. +
    • +
      +
    • mesa-dev - for Mesa, Gallium and DRI development +discussion. Not for beginners. +
    • +
      +
    • mesa-commit - relays git check-in messages +(for developers). +In general, people should not post to this list. +
    • +
      +
    • mesa-announce - announcements of new Mesa +versions are sent to this list. Very low traffic. +
    • +
    + +

    +Follow the links above for list archives. +

    + +

    +The old Mesa lists hosted at SourceForge are no longer in use. +The archives are still available, however: +mesa3d-announce, +mesa3d-users, +mesa3d-dev. +

    + + +

    For mailing lists about Direct Rendering Modules (drm) in Linux/BSD +kernels, see the + +DRI wiki. +

    + +

    +Notice: You must subscribe to these lists in order to post to them. +

    + + +
    + +

    OpenGL Forums

    + +

    +Here are some other OpenGL-related forums you might find useful: +

    + +
      +
    • OpenGL discussion forums at www.opengl.org
    • +
    • Usenet newsgroups: +
        +
      • comp.graphics.algorithms
      • +
      • comp.graphics.api.opengl
      • +
      • comp.os.linux.x
      • +
      +
    + + + diff --git a/docs/mangling.html b/docs/mangling.html new file mode 100644 index 0000000..5507154 --- /dev/null +++ b/docs/mangling.html @@ -0,0 +1,30 @@ + + +Function Name Mangling + + + + + +

    Function Name Mangling

    + +

    +If you want to use both Mesa and another OpenGL library in the same +application at the same time you may find it useful to compile Mesa with +name mangling. +This results in all the Mesa functions being prefixed with +mgl instead of gl. +

    + +

    +To do this, recompile Mesa with the compiler flag -DUSE_MGL_NAMESPACE. +Add the flag to CFLAGS in the configuration file which you want to use. +For example: +

    +CFLAGS += -DUSE_MGL_NAMESPACE
    +
    +

    + + + + diff --git a/docs/modelers.html b/docs/modelers.html new file mode 100644 index 0000000..aae9686 --- /dev/null +++ b/docs/modelers.html @@ -0,0 +1,68 @@ + + +Modelers, Renderers and Viewers + + + + + +

    Modelers, Renderers and Viewers

    + + + + + diff --git a/docs/news.html b/docs/news.html new file mode 100644 index 0000000..6791f98 --- /dev/null +++ b/docs/news.html @@ -0,0 +1,1343 @@ + + +Mesa News + + + + + + + +

    News

    + + +

    April 6, 2011

    + +

    +Mesa 7.10.2 is released. This is a bug +fix release release. +

    + +

    March 2, 2011

    + +

    +Mesa 7.10.1 is released. This is a bug +fix release release. +

    + +

    +Also, Mesa 7.9.2 is released. +This is a bug fix release. +

    + + +

    January 7, 2011

    + +

    +Mesa 7.10 (final) is released. This is a new +development release. +

    + +

    +Also, Mesa 7.9.1 (final) is released. +This is a bug fix release. +

    + + +

    October 4, 2010

    + +

    +Mesa 7.9 (final) is released. This is a new +development release. +

    + + +

    September 27, 2010

    + +

    +Mesa 7.9.0-rc1 is released. This is a +release candidate for the 7.9 development release. +

    + + +

    June 16, 2010

    + +

    +Mesa 7.8.2 is released. This is a bug-fix +release collecting fixes since the 7.8.1 release. +

    + + +

    April 5, 2010

    + +

    +Mesa 7.8.1 is released. This is a bug-fix +release for a few critical issues in the 7.8 release. +

    + + +

    March 28, 2010

    +

    +Mesa 7.7.1 is released. This is a bug-fix +release fixing issues found in the 7.7 release. +

    +

    +Also, Mesa 7.8 is released. This is a new +development release. +

    + + + +

    December 21, 2009

    +

    +Mesa 7.6.1 is released. This is a bug-fix +release fixing issues found in the 7.6 release. +

    +

    +Also, Mesa 7.7 is released. This is a new +development release. +

    + + +

    September 28, 2009

    +

    +Mesa 7.6 is released. This is a new feature +release. Those especially concerned about stability may want to wait for the +follow-on 7.6.1 bug-fix release. +

    +

    +Mesa 7.5.2 is also released. +This is a stable release fixing bugs since the 7.5.1 release. +

    + + +

    September 3, 2009

    +

    +Mesa 7.5.1 is released. +This is a bug-fix release which fixes bugs found in version 7.5. +

    + + +

    July 17, 2009

    +

    +Mesa 7.5 is released. +This is a new features release. People especially concerned about +stability may want to wait for the follow-on 7.5.1 bug-fix release. +

    + + +

    June 23, 2009

    +

    +Mesa 7.4.4 is released. +This is a stable release that fixes a regression in the i915/i965 drivers +that slipped into the 7.4.3 release. +

    + + +

    June 19, 2009

    +

    +Mesa 7.4.3 is released. +This is a stable release fixing bugs since the 7.4.2 release. +

    + + +

    May 15, 2009

    +

    +Mesa 7.4.2 is released. +This is a stable release fixing bugs since the 7.4.1 release. +

    + + +

    April 18, 2009

    +

    +Mesa 7.4.1 is released. +This is a stable release fixing bugs since the 7.4 release. +

    + + +

    March 27, 2009

    +

    +Mesa 7.4 is released. +This is a stable release fixing bugs since the 7.3 release. +

    + + +

    January 22, 2009

    +

    +Mesa 7.3 is released. +This is a new development release. +Mesa 7.4 will follow and will have bug fixes relative to 7.3. +

    + + +

    September 20, 2008

    +

    +Mesa 7.2 is released. +This is a stable, bug-fix release. +

    + + +

    August 26, 2008

    +

    +Mesa 7.1 is released. +This is a new development release. +It should be relatively stable, but those especially concerned about +stability should wait for the 7.2 release or use Mesa 7.0.4 (the +previous stable release). +

    + + +

    August 16, 2008

    +

    +Mesa 7.0.4 is released. +This is a bug-fix release. +

    + + +

    April 4, 2008

    +

    +Mesa 7.0.3 is released. +This is a bug-fix release. +

    + + +

    January 24, 2008

    + +

    +Added a new page describing the Mesa Cell driver. +

    + + + +

    November 13, 2007

    + +

    +Gallium3D is the codename for the new Mesa device driver architecture +which is currently under development. +

    +

    +Gallium3D development is taking place on the gallium-0.1 branch +of the git repository. +Currently, there's only a software-only driver and an Intel i915/945 driver +but other drivers will be coming... +

    + + +

    November 10, 2007

    +

    +Mesa 7.0.2 is released. +This is a bug-fix release. +

    + + +

    August 3, 2007

    +

    +Mesa 7.0.1 is released. +This is a bug-fix release. +

    + + +

    June 22, 2007

    +

    +Mesa 7.0 is released. +This is a stable release featuring OpenGL 2.1 support. +

    + + +

    April 27, 2007

    +

    +Mesa 6.5.3 is released. +This is a development release which will lead up to the Mesa 7.0 release +(which will advertise OpenGL 2.1 API support). +

    + + +

    March 26, 2007

    +

    +The new Shading Language compiler branch has been merged into the git +master branch. This is a step toward hardware support for the OpenGL +2.0 Shading Language and will be included in the next Mesa release. +In conjunction, Glean + has been updated with a new test that does over 130 tests of the +shading language and built-in functions. +

    + +

    April 2007

    +

    +Thomas Hellström of Tungsten Graphics has written a whitepaper +describing the new DRI memory management system. +

    + +

    December 5, 2006

    +

    +Mesa is now using git as its source code management system. +The previous CVS repository should no longer be used. +See the repository page for more information. +

    + +

    December 2, 2006

    +

    +Mesa 6.5.2 has been released. +This is a new development release. +

    + +

    September 15, 2006

    +

    +Mesa 6.5.1 has been released. +This is a new development release. +

    + +

    March 31, 2006

    +

    +Mesa 6.5 has been released. +This is a new development release. +

    + + +

    February 2, 2006

    +

    +Mesa 6.4.2 has been released. +This is stable, bug-fix release. +

    + + +

    November 29, 2005

    +

    +Mesa 6.4.1 has been released. +This is stable, bug-fix release. +

    + + + +

    October 24, 2005

    +

    +Mesa 6.4 has been released. +This is stable, bug-fix release. +

    + + +

    August 19, 2005

    +

    +Mesa 6.3.2 has been released. +Note: there was no public release of version 6.3.1. +

    +Changes in version 6.3.1 +

    +The MD5 checksums are: +

    +
    +98192e45ed8d69113688f89f90869346  MesaLib-6.3.2.tar.gz
    +0df27701df0924d17ddf41185efa8ce1  MesaLib-6.3.2.tar.bz2
    +ccb2423aab77fc7e81ce628734586140  MesaLib-6.3.2.zip
    +9d0fca0a7d051c34a0b485423fb3e85d  MesaDemos-6.3.2.tar.gz
    +96708868450c188205e42229b5d813c4  MesaDemos-6.3.2.tar.bz2
    +c5102501e609aa8996d832fafacb8ab9  MesaDemos-6.3.2.zip
    +
    + + +

    July 20, 2005

    +

    +Mesa 6.3 has been released. +This is a development release with new features, changes and bug fixes. +

    +
    +    New:
    +	- GL_EXT_framebuffer_object extension
    +	- GL_ARB_draw_buffers extension
    +	- GL_ARB_pixel_buffer_object extension
    +	- GL_OES_read_format extension (Ian Romanick)
    +	- DirectFB driver (Claudio Ciccani)
    +	- x86_64 vertex transformation code (Mikko T.)
    +    Changes:
    +	- added -stereo option for glxgears demo (Jacek Rosik)
    +	- updated the PBuffer demo code in xdemos/ directory
    +	- glDeleteTextures/Programs/Buffers() now makes the object ID
    +	  available for immediate re-use
    +	- assorted 64-bit clean-ups fixes (x86_64 and Win64)
    +	- lots of internal changes for GL_EXT_framebuffer_object
    +    Bug fixes:
    +	- some functions didn't support PBO functionality
    +	- glGetTexImage didn't convert color index images to RGBA as required
    +	- fragment program texcoords were sometimes wrong for points and lines
    +	- fixed problem with negative dot product in arbfplight, fplight demos
    +	- fixed bug in perspective correction of antialiased, textured lines
    +	- querying GL_POST_CONVOLUTION_ALPHA_BIAS_EXT returned wrong value
    +	- fixed a couple per-pixel fog bugs (Soju Matsumoto)
    +	- glGetBooleanv(GL_FRAGMENT_PROGRAM_BINDING_NV) was broken
    +	- fixed float parsing bug in ARB frag/vert programs (bug 2520)
    +	- XMesaGetDepthBuffer() returned incorrect value for bytesPerValue
    +	- GL_COLOR_MATERIAL with glColor3 didn't properly set diffuse alpha
    +	- glXChooseFBConfig() crashed if attribList pointer was NULL
    +	- program state.light[n].spot.direction.w was wrong value (bug 3083)
    +	- fragment program fog option required glEnable(GL_FOG) - wrong.
    +	- glColorTable() could produce a Mesa implementation error (bug 3135)
    +	- RasterPos could get corrupted by color index rendering path
    +	- Removed bad XTranslateCoordinates call when rendering to Pixmaps
    +	- glPopAttrib() didn't properly restore GL_TEXTURE_GEN enable state
    +	- fixed a few Darwin compilation problems
    +
    +

    +The MD5 checksums are: +

    +
    +0236f552d37514776945d5a013e5bb7b  MesaLib-6.3.tar.gz
    +60e1a8f78c4a8c7750a1e95753190986  MesaLib-6.3.tar.bz2
    +ca7c950fbace68c70caa822322db7223  MesaLib-6.3.zip
    +25ea801645b376c014051804fe4974b2  MesaDemos-6.3.tar.gz
    +9248e74872ea88c57ec25c900c295057  MesaDemos-6.3.tar.bz2
    +8537dfa734ef258dcc7272097558d434  MesaDemos-6.3.zip
    +
    + + +

    December 9, 2004

    +

    +Mesa 6.2.1 has been released. +This is a stable release which just fixes bugs since the 6.2 release. +

    +
    +    Bug fixes:
    +	- don't apply regular fog or color sum when using a fragment program
    +	- glProgramEnvParameter4fARB always generated an error on
    +	  GL_FRAGMENT_PROGRAM_ARB (fdo bug 1645)
    +	- glVertexAttrib3svNV and glVertexAttrib3svARB were broken
    +	- fixed width/height mix-up in glSeparableFilter2D()
    +	- fixed regression in glCopyPixels + convolution
    +	- glReadPixels from a clipped front color buffer didn't always work
    +	- glTexImage didn't accept GL_RED/GREEN/BLUE as the format
    +	- Attempting queries/accesses of VBO 0 weren't detected as errors
    +	- paletted textures failed if the palette had fewer than 256 entries
    +    Changes:
    +	- fixed a bunch of compiler warnings found with gcc 3.4
    +	- bug reports should to go bugzilla.freedesktop.org
    +
    +

    +The MD5 checksums are: +

    +
    +80008a92f6e055d3bfdde2cf331ec3fa  MesaLib-6.2.1.tar.gz
    +f43228cd2bf70f583ef3275c1c545421  MesaLib-6.2.1.tar.bz2
    +dec26cfd40116ad021020fea2d94f652  MesaLib-6.2.1.zip
    +2c7af3c986a7571c8713c8bfee7e49e3  MesaDemos-6.2.1.tar.gz
    +3cac74667b50bcbd4f67f594fb4224a2  MesaDemos-6.2.1.tar.bz2
    +75b3edd12eb2b370caf05f29b99e508a  MesaDemos-6.2.1.zip
    +
    + + +

    October 2, 2004

    +

    +Mesa 6.2 has been released. +This is a stable release which just fixes bugs since the 6.1 release. +

    +
    +    New:
    +	- enabled GL_ARB_texture_rectangle (same as GL_NV_texture_rectangle)
    +	- updated Doxygen support (Jose Fonseca)
    +    Changes:
    +	- some GGI driver updates (Christoph Egger, bug 1025977)
    +    Bug fixes:
    +	- Omit GL_ARB_texture_non_power_of_two from list of OpenGL 1.5 features
    +	- fixed a few compilation issues on IRIX
    +	- fixed a matrix classification bug (reported by Wes Bethel)
    +	- we weren't reseting the vertex/fragment program error state
    +	  before parsing (Dave Reveman)
    +	- adjust texcoords for sampling texture rectangles (Dave Reveman)
    +	- glGet*(GL_MAX_VERTEX_ATTRIBS_ARB) wasn't implemented
    +	- repeated calls to glDeleteTexture(t) could lead to a crash
    +	- fixed potential ref count bugs in VBOs and vertex/fragment programs
    +	- spriteblast demo didn't handle window size changes correctly
    +	- glTexSubImage didn't handle pixels=NULL correctly for PBOs
    +	- fixed color index mode glDrawPixels bug (Karl Schultz)
    +
    +

    +The MD5 checksums are: +

    +
    +9e8f34b059272dbb8e1f2c968b33bbf0  MesaLib-6.2.tar.gz
    +3d6a6362390b6a37d3cb2e615f3ac7db  MesaLib-6.2.tar.bz2
    +6cfd7895d28e695c0dbbed9469564091  MesaLib-6.2.zip
    +3e06e33b0809f09855cb60883b8bdfef  MesaDemos-6.2.tar.gz
    +9d160009c3dfdb35fe7e4088c9ba8f85  MesaDemos-6.2.tar.bz2
    +856f7ec947122eb3c8985ebc2f654dcd  MesaDemos-6.2.zip
    +
    + + +

    August 18, 2004

    +

    +Mesa 6.1 has been released. +This is a new development release (version 6.2 will be a stabilization +release). +

    +
    +    New:
    +	- Revamped Makefile system
    +	- glXUseRotatedXFont() utility (see xdemos/xuserotfont.c)
    +	- internal driver interface changes related to texture object
    +	  allocation, vertex/fragment programs, BlendEquationSeparate, etc.
    +	- option to walk triangle edges with double-precision floats
    +	  (Justin Novosad of Discreet) (see config.h file)
    +	- support for AUX buffers in software GLX driver
    +	- updated glext.h to version 24 and glxext.h to version 6
    +	- new MESA_GLX_FORCE_ALPHA and MESA_GLX_DEPTH_BITS env vars
    +	- updated BeOS support (Philippe Houdoin)
    +    Changes:
    +	- fragment fog interpolation is perspective corrected now
    +	- new glTexImage code, much cleaner, may be a bit faster
    +    Bug fixes:
    +	- glArrayElement in display lists didn't handle generic vertex attribs
    +	- glFogCoord didn't always work properly
    +	- ARB_fragment_program fog options didn't work
    +	- frag prog TEX instruction no longer incorrectly divides s,t,r by q
    +	- ARB frag prog TEX and TEXP instructions now use LOD=0
    +	- glTexEnviv in display lists didn't work
    +	- glRasterPos didn't do texgen or apply texture matrix
    +	- GL_DOUBLE-valued vertex arrays were broken in some cases
    +	- fixed texture rectangle edge/border sampling bugs
    +	- sampling an incomplete texture in a fragment program would segfault
    +	- glTexImage was missing a few error checks
    +	- fixed some minor glGetTexParameter glitches
    +	- GL_INTENSITY was mistakenly accepted as a  to glTexImage
    +	- fragment program writes to RC/HC register were broken
    +	- fixed a few glitches in GL_HP_occlusion_test extension
    +	- glBeginQueryARB and glEndQueryARB didn't work inside display lists
    +	- vertex program state references were broken
    +	- fixed triangle color interpolation bug on AIX (Shane Blackett)
    +	- fixed a number of minor memory leaks (bug #1002030)
    +
    +The MD5 checksums are: +

    +
    +c9284d295ebcd2e0486cc3cd54e5863c  MesaLib-6.1.tar.gz
    +5de1f53ec0709f60fc68fdfed57351f3  MesaLib-6.1.tar.bz2
    +483e77cac4789a5d36c42f3c0136d6d8  MesaLib-6.1.zip
    +8c46cfa6f9732acc6f6c25724aad0246  MesaDemos-6.1.tar.gz
    +89bfe0f6c69b39fd0ebd9fff481a4e9b  MesaDemos-6.1.tar.bz2
    +161268531fcc6f0c5a056430ee97e0c1  MesaDemos-6.1.zip
    +
    + + + +

    April 2, 2004

    + +

    +Mesa 6.0.1 has been released. +This release basically just fixes bugs since the 6.0. release. +

    +
    +    New:
    +	- upgraded glext.h to version 22
    +	- new build targets (Dan Schikore)
    +	- new linux-x86-opteron build target (Heath Feather)
    +    Bug fixes:
    +	- glBindProgramARB didn't update all necessary state
    +	- fixed build problems on OpenBSD
    +	- omit CVS directories from tarballs
    +	- glGetTexImage(GL_COLOR_INDEX) was broken
    +	- fixed an infinite loop in t&l module
    +	- silenced some valgrind warnings about using unitialized memory
    +	- fixed some compilation/link glitches on IRIX (Mike Stephens)
    +	- glBindProgram wasn't getting compiled into display lists
    +	- GLX_FBCONFIG_ID wasn't recognized in glXChooseFBConfig() (bug 888079)
    +	- two-sided lighting and vertex program didn't work (bug 887330)
    +	- stores to program parameter registers in vertex state programs
    +	  didn't work.
    +	- fixed glOrtho bug found with gcc 3.2.2 (RH9)
    +	- glXCreateWindow() wasn't fully implemented (bug 890894)
    +	- generic vertex attribute arrays didn't work in display lists
    +	- vertex buffer objects' default usage and access fields were wrong
    +	- glDrawArrays with start!=0 was broken
    +	- fragment program PK2H, UP2H, UP4B and UP4UB instructions were broken
    +	- linux-osmesa16-static config didn't work
    +	- fixed a few color index rendering problems (bug 910687)
    +	- glInterleavedArrays didn't respect GL_CLIENT_ACTIVE_TEXTURE
    +	- OSMesa RGB and BGR modes were broken
    +	- glProgramStringARB mistakenly required a null-terminated string
    +	- fragment program XPD instruction was incorrect
    +	- glGetMaterial() didn't work reliably
    +
    +The MD5 checksums are: +

    +
    +011be0e79666c7a6eb9693fbf9348653  MesaLib-6.0.1.tar.gz
    +b7f14088c5c2f14490d2739a91102112  MesaLib-6.0.1.tar.bz2
    +bf0510cf0a2b87d64cdd317eca3f1db1  MesaLib-6.0.1.zip
    +b7b648599e0aaee1c4ffc554a2a9139e  MesaDemos-6.0.1.tar.gz
    +dd6aadfd9ca8e1cfa90c6ee492bc6f43  MesaDemos-6.0.1.tar.bz2
    +eff71d59c211825e949199852f5a2316  MesaDemos-6.0.1.zip
    +
    + + + +

    January 16, 2004

    + +

    +Mesa 6.0 has been released. This is a stabilization of the 5.1 release +and primarily just incorporates bug fixes. +

    +
    +    New:
    +	- full OpenGL 1.5 support
    +	- updated GL/glext.h file to version 21
    +    Changes:
    +	- changed max framebuffer size to 4Kx4K (MAX_WIDTH/HEIGHT in config.h)
    +    Bug fixes:
    +	- fixed bug in UNCLAMPED_FLOAT_TO_UBYTE macro; solves a color
    +	  clamping issue
    +	- updated suno5-gcc configs
    +	- glColor3 functions sometimes resulted in undefined alpha values
    +	- fixed FP divide by zero error seen on VMS with xlockmore, others
    +	- fixed vertex/fragment program debug problem (bug 873011)
    +	- building on AIX with gcc works now
    +	- glDeleteProgramsARB failed for ARB fragment programs (bug 876160)
    +	- glDrawRangeElements tried to modify potentially read-only storage
    +	- updated files for building on Windows
    +
    + + + +

    December 28, 2003

    + +

    +The Mesa CVS server has been moved to +freedesktop.org because of problems with SourceForge's anonymous +CVS service. +

    + +

    Please see the CVS access page for details. +

    + + +

    December 17, 2003

    + +

    +Mesa 5.1 has been released. This is a new development release. +Mesa 6.0 will be the next stable release and will support all +OpenGL 1.5 features. +

    +
    +    New features:
    +	- reorganized directory tree
    +	- GL_ARB_vertex/fragment_program extensions (Michal Krol & Karl Rasche)
    +	- GL_ATI_texture_env_combine3 extension (Ian Romanick)
    +	- GL_SGI_texture_color_table extension (Eric Plante)
    +	- GL_NV_fragment_program extension
    +	- GL_NV_light_max_exponent extension
    +	- GL_EXT_texture_rectangle (identical to GL_NV_texture_rectangle)
    +	- GL_ARB_occlusion_query extension
    +	- GL_ARB_point_sprite extension
    +	- GL_ARB_texture_non_power_of_two extension
    +	- GL_IBM_multimode_draw_arrays extension
    +	- GL_EXT_texture_mirror_clamp extension (Ian Romanick)
    +	- GL_ARB_vertex_buffer_object extension
    +	- new X86 feature detection code (Petr Sebor)
    +	- less memory used for display lists and vertex buffers
    +	- demo of per-pixel lighting with a fragment program (demos/fplight.c)
    +	- new version (18) of glext.h header
    +	- new spriteblast.c demo of GL_ARB_point_sprite
    +	- faster glDrawPixels in X11 driver in some cases (see RELNOTES-5.1)
    +	- faster glCopyPixels in X11 driver in some cases (see RELNOTES-5.1)
    +    Bug fixes:
    +	- really enable OpenGL 1.4 features in DOS driver.
    +	- fixed issues in glDrawPixels and glCopyPixels for very wide images
    +	- glPixelMapf/ui/usv()'s size parameter is GLsizei, not GLint
    +	- fixed some texgen bugs reported by Daniel Borca
    +	- fixed wglMakeCurrent(NULL, NULL) bug (#835861)
    +	- fixed glTexSubImage3D z-offset bug (Cedric Gautier)
    +	- fixed RGBA blend enable bug (Ville Syrjala)
    +	- glAccum is supposed to be a no-op in selection/feedback mode
    +	- fixed texgen bug #597589 (John Popplewell)
    +    Changes:
    +	- dropped API trace feature (src/Trace/)
    +	- documentation overhaul.  merged with website content.  more html.
    +	- glxgears.c demo updated to use GLX swap rate extensions
    +	- glTexImage1/2/3D now allows width/height/depth = 0
    +	- disable SPARC asm code on Linux (bug 852204)
    +
    + +The MD5 checksums are: +

    +
    +78f452f6c55478471a744f07147612b5  MesaLib-5.1.tar.gz
    +67b3b8d3f7f4c8c44904551b851d01af  MesaLib-5.1.tar.bz2
    +6dd19ffa750ec7f634e370a987505c9d  MesaLib-5.1.zip
    +e0214d4ebb22409dfa9262f2b52fd828  MesaDemos-5.1.tar.gz
    +066c9aff4fd924405de1ae9bad5ec9a7  MesaDemos-5.1.tar.bz2
    +d2b5ba32b53e0ad0576c637a4cc1fb41  MesaDemos-5.1.zip
    +
    + + +

    November 12, 2003

    + +

    +New Mesa 5.0.2 tarballs have been uploaded to SourceForge which fix a +number of automake/libtool problems. +

    +

    +The new MD5 checksums are: +

    +
    +a9dcf3ff9ad1b7d6ce73a0df7cff8b5b  MesaLib-5.0.2.tar.gz
    +7b4bf9261657c2fca03796d4955e6f50  MesaLib-5.0.2.tar.bz2
    +79c141bddcbad557647535d02194f346  MesaLib-5.0.2.zip
    +952d9dc823dd818981d1a648d7b2668a  MesaDemos-5.0.2.tar.gz
    +b81fafff90995025d2f25ea02b786642  MesaDemos-5.0.2.tar.bz2
    +a21be975589e8a2d1871b6bb7874fffa  MesaDemos-5.0.2.zip
    +
    + + + +

    September 5, 2003

    + +

    +Mesa 5.0.2 has been released. This is a stable, bug-fix release. +

    +
    +    Bug fixes:
    +	- fixed texgen problem causing texcoord's Q to be zero (stex3d)
    +	- default GL_TEXTURE_COMPARE_MODE_ARB was wrong
    +	- GL_CURRENT_MATRIX_NV query was wrong
    +	- GL_CURRENT_MATRIX_STACK_DEPTH_NV query was off by one
    +	- GL_LIST_MODE query wasn't correct
    +	- GL_FOG_COORDINATE_SOURCE_EXT query wasn't supported
    +	- GL_SECONDARY_COLOR_ARRAY_SIZE_EXT query returned wrong value
    +	- blended, wide lines didn't always work correctly (bug 711595)
    +	- glVertexAttrib4svNV w component was always 1
    +	- fixed bug in GL_IBM_rasterpos_clip (missing return)
    +	- GL_DEPTH_TEXTURE_MODE = GL_ALPHA didn't work correctly
    +	- a few Solaris compilation fixes
    +	- fixed glClear() problem for DRI drivers (non-existant stencil, etc)
    +	- fixed int/REAL mixup in GLU NURBS curve evaluator (Eric Cazeaux)
    +	- fixed delete [] bug in SI GLU (bug 721765) (Diego Santa Cruz)
    +	- glFog() didn't clamp fog colors
    +	- fixed bad float/int conversion for GL_TEXTURE_PRIORITY in the
    +	  gl[Get]TexParameteri[v] functions
    +	- fixed invalid memory references in glTexGen functions (bug 781602)
    +	- integer-valued color arrays weren't handled correctly
    +	- glDrawPixels(GL_DEPTH_COMPONENT) with glPixelZoom didn't work
    +	- GL_EXT_texture_lod_bias is part of 1.4, overlooked in 5.0.1
    +    Changes:
    +	- build GLUT with -fexceptions so C++ apps propogate exceptions
    +
    + + + +

    June 2003

    + +

    +Mesa's directory tree has been overhauled. +Things are better organized now with some thought toward future needs. +

    +

    +In CVS, the latest Mesa 5.1 development code is now rooted under the +Mesa-newtree/ directory. The old top-level Mesa/ directory +holds the Mesa 5.0.x code which will be abandoned at some point. +

    + + + +

    March 30, 2003

    + +

    +Mesa 5.0.1 has been released. This is a stable, bug-fix release. +

    +
    +    New:
    +	- DOS driver updates from Daniel Borca
    +	- updated GL/gl_mangle.h file (Bill Hoffman)
    +    Bug fixes:
    +	- auto mipmap generation for cube maps was broken (bug 641363)
    +	- writing/clearing software alpha channels was unreliable
    +	- minor compilation fixes for OS/2 (Evgeny Kotsuba)
    +	- fixed some bad assertions found with shadowtex demo
    +	- fixed error checking bug in glCopyTexSubImage2D (bug 659020)
    +	- glRotate(angle, -x, 0, 0) was incorrect (bug 659677)
    +	- fixed potential segfault in texture object validation (bug 659012)
    +	- fixed some bogus code in _mesa_test_os_sse_exception_support (Linus)
    +	- fix fog stride bug in tnl code for h/w drivers (Michel Danzer)
    +	- fixed glActiveTexture / glMatrixMode(GL_TEXTURE) bug (#669080)
    +	- glGet(GL_CURRENT_SECONDARY_COLOR) should return 4 values, not 3
    +	- fixed compilation problem on Solaris7/x86 (bug 536406)
    +	- fixed prefetch bug in 3DNow! code (Felix Kuhling)
    +	- fixed NeXT build problem (FABSF macro)
    +	- glDrawPixels Z values when glPixelZoom!=1 were invalid (bug 687811)
    +	- zoomed glDraw/CopyPixels with clipping sometimes failed (bug 689964)
    +	- AA line and triangle Z values are now rounded, not truncated
    +	- fixed color interpolation bug when GLchan==GLfloat (bug 694461)
    +	- glArePrograms/TexturesResident() wasn't 100% correct (Jose Fonseca)
    +	- fixed a minor GL_COLOR_MATERIAL bug
    +	- NV vertex program EXP instruction was broken
    +	- glColorMask misbehaved with X window / pixmap rendering
    +	- fix autoconf/libtool GLU C++ linker problem on Linux (a total hack)
    +	- attempt to fix GGI compilation problem when MesaDemos not present
    +	- NV vertex program ARL-relative fetches didn't work
    +    Changes:
    +	- use glPolygonOffset in gloss demo to avoid z-fighting artifacts
    +	- updated winpos and pointblast demos to use ARB extensions
    +	- disable SPARC normal transformation code (bug 673938)
    +	- GLU fixes for OS/2 (Evgeny Kotsuba)
    +
    +

    +MD5 checksums follow: +

    +
    +b80f8b5d53a3e9f19b9fde5af0c542f0  MesaLib-5.0.1.tar.gz
    +513b4bbd7d38951f05027179063d876b  MesaLib-5.0.1.tar.bz2
    +eebd395678f4520d33b267e5d5c22651  MesaLib-5.0.1.zip
    +49d7feaec6dc1d2091d7c3cc72a9b320  MesaDemos-5.0.1.tar.gz
    +37190374a98c3c892f0698be9ca3acf0  MesaDemos-5.0.1.tar.bz2
    +becd8bf17f5791361b4a54ba2a78e5c9  MesaDemos-5.0.1.zip
    +
    + + + +

    March 7, 2003

    +

    +Website and documentation overhaul. +

    +

    +The website content and Mesa documentation (from the doc/ directory) have +been merged together. +All the documentation files have been entered into the CVS repository. +Many of the old plain-text files have been converted to html and modernized. +

    + + +

    November 13, 2002

    +

    Mesa 5.0 has been released. This is a stable release which +implements the OpenGL 1.4 specification. +

    New:
    +    - OpenGL 1.4 support (glGetString(GL_VERSION) returns "1.4")
    +    - removed some overlooked debugging code
    +    - glxinfo updated to support GLX_ARB_multisample
    +    - GLUT now support GLX_ARB_multisample
    +    - updated DOS driver (Daniel Borca)
    +Bug fixes:
    +    - GL_POINT and GL_LINE-mode polygons didn't obey cull state
    +    - fixed potential bug in _mesa_align_malloc/calloc()
    +    - fixed missing triangle bug when running vertex programs
    +    - fixed a few HPUX compilation problems
    +    - FX (Glide) driver didn't compile
    +    - setting GL_TEXTURE_BORDER_COLOR with glTexParameteriv() didn't work
    +    - a few EXT functions, like glGenTexturesEXT, were no-ops
    +    - a few OpenGL 1.4 functions like glFogCoord*, glBlendFuncSeparate,
    +      glMultiDrawArrays and glMultiDrawElements were missing
    +    - glGet*(GL_ACTIVE_STENCIL_FACE_EXT) was broken
    +    - Pentium 4 Mobile was mistakenly identified as having 3DNow!
    +    - fixed one-bit error in point/line fragment Z calculation
    +    - fixed potential segfault in fakeglx code
    +    - fixed color overflow problem in DOT3 texture env mode
    +
    + + +

    October 29, 2002

    +

    Mesa 4.1 has been released. This is a new development release. +For a stable release, get 4.0.4. +

    New:
    +    - GL_NV_vertex_program extension
    +    - GL_NV_vertex_program1_1 extension
    +    - GL_ARB_window_pos extension
    +    - GL_ARB_depth_texture extension
    +    - GL_ARB_shadow extension
    +    - GL_ARB_shadow_ambient extension
    +    - GL_EXT_shadow_funcs extension
    +    - GL_ARB_point_parameters extension
    +    - GL_ARB_texture_env_crossbar
    +    - GL_NV_point_sprite extension
    +    - GL_NV_texture_rectangle extension
    +    - GL_EXT_multi_draw_arrays extension
    +    - GL_EXT_stencil_two_side extension
    +    - GLX_SGIX_fbconfig and GLX_SGIX_pbuffer extensions
    +    - GL_ATI_texture_mirror_once extension (Ian Romanick)
    +    - massive overhaul/simplification of software rasterizer module,
    +      many contributions from Klaus Niederkrueger
    +    - faster software texturing in some cases (i.e. trilinear filtering)
    +    - new OSMesaGetProcAddress() function
    +    - more blend modes implemented with MMX code (Jose Fonseca)
    +    - added glutGetProcAddress() to GLUT
    +    - added GLUT_FPS env var to compute frames/second in glutSwapBuffers()
    +    - pbinfo and pbdemo PBuffer programs
    +    - glxinfo -v prints transprent pixel info (Gerd Sussner)
    +Bug fixes:
    +    - better mipmap LOD computation (prevents excessive blurriness)
    +    - OSMesaMakeCurrent() didn't recognize buffer size changes
    +    - assorted conformance fixes for 16-bit/channel rendering
    +    - texcombine alpha subtraction mode was broken
    +    - fixed some blend problems when GLchan==GLfloat (Gerk Huisma)
    +    - clamp colors to [0,1] in OSMesa if GLchan==GLfloat (Gerk Huisma)
    +    - fixed divide by zero error in NURBS tessellator (Jon Perry)
    +    - fixed GL_LINEAR fog bug by adding clamping
    +    - fixed FP exceptions found using Alpha CPU
    +    - 3dfx/glide driver render-to-window feature was broken
    +    - added missing GLX_TRANSPARENT_RGB token to glx.h
    +    - fixed error checking related to paletted textures
    +    - fixed reference count error in glDeleteTextures (Randy Fayan)
    +Changes:
    +    - New spec file and Python code to generate some GL dispatch files
    +    - Glide driver defaults to "no" with autoconf/automake
    +    - floating point color channels now clamped to [0,inf)
    +    - updated demos/stex3d with new options
    +
    + + +

    October 4, 2002

    +

    +The Mesa FAQ has been rewritten. +

    + +

    October 3, 2002

    +

    Mesa 4.0.4 has been released. This is a stable bug-fix release. +

        New:
    +	- GL_NV_texture_rectangle extension
    +	- updated glext.h header (version 17)
    +	- updated DOS driver (Daniel Borca)
    +	- updated BeOS R5 driver (Philippe Houdoin)
    +	- added GL_IBM_texture_mirror_repeat
    +	- glxinfo now takes -l option to print interesting OpenGL limits info
    +	- GL_MESA_ycbcr_texture extension
    +	- GL_APPLE_client_storage extension (for some DRI drivers only)
    +	- GL_MESA_pack_invert extension
    +    Bug fixes:
    +	- fixed GL_LINEAR fog bug by adding clamping
    +	- fixed FP exceptions found using Alpha CPU
    +	- 3dfx MESA_GLX_FX=window (render to window) didn't work
    +	- fixed memory leak in wglCreateContest (Karl Schultz)
    +	- define GLAPIENTRY and GLAPI if undefined in glu.h
    +	- wglGetProcAddress didn't handle all API functions
    +	- when testing for OpenGL 1.2 vs 1.3, check for GL_ARB_texture_cube_map
    +	- removed GL_MAX_CONVOLUTION_WIDTH/HEIGHT from glGetInteger/Float/etc()
    +	- error checking in compressed tex image functions had some glitches
    +	- fixed AIX compile problem in src/config.c
    +	- glGetTexImage was using pixel unpacking instead of packing params
    +	- auto-mipmap generation for cube maps was incorrect
    +    Changes:
    +	- max texture units reduced to six to accomodate texture rectangles
    +	- removed unfinished GL_MESA_sprite_point extension code
    +
    + +

    June 25, 2002

    +

    Mesa 4.0.3 has been released. This is a stable bug-fix release. +

        New:
    +    - updated GL/glext.h file (version 15)
    +    - corrected MMX blend code (Jose Fonseca)
    +    - support for software-based alpha planes in Windows driver
    +    - updated GGI driver (Filip Spacek)
    +    Bug fixes:
    +    - glext.h had wrong values for GL_DOT3_RGB[A]_EXT tokens
    +    - OSMesaMakeCurrent() didn't recognize buffer size changes
    +    - assorted conformance fixes for 16-bit/channel rendering
    +    - texcombine alpha subtraction mode was broken
    +    - fixed lighting bug with non-uniform scaling and display lists
    +    - fixed bug when deleting shared display lists
    +    - disabled SPARC cliptest assembly code (Mesa bug 544665)
    +    - fixed a couple Solaris compilation/link problems
    +    - blending clipped glDrawPixels didn't always work
    +    - glGetTexImage() didn't accept packed pixel types
    +    - glPixelMapu[is]v() could explode given too large of pixelmap
    +    - glGetTexParameter[if]v() didn't accept GL_TEXTURE_MAX_ANISOTROPY_EXT
    +    - glXCopyContext() could lead to segfaults
    +    - glCullFace(GL_FRONT_AND_BACK) didn't work (bug 572665)
    +    Changes:
    +    - lots of C++ (g++) code clean-ups
    +    - lots of T&L updates for the Radeon DRI driver
    +    Known bugs:
    +    - mipmap LOD computation (fixed for Mesa 4.1)
    +
    + +

    April 2, 2002

    +

    Mesa 4.0.2 has been released. This is a stable bug-fix release. +

        New:
    +      - New DOS (DJGPP) driver written by Daniel Borca
    +      - New driver interface functions for TCL drivers (such as Radeon DRI)
    +      - GL_RENDERER string returns "Mesa Offscreen16" or "Mesa Offscreen32"
    +        if using deep color channels
    +      - latest GL/glext.h and GL/glxext.h headers from SGI
    +    Bug fixes:
    +      - GL_BLEND with non-black texture env color wasn't always correct
    +      - GL_REPLACE with GL_RGB texture format wasn't always correct (alpha)
    +      - glTexEnviv( pname != GL_TEXTURE_ENV_COLOR ) was broken
    +      - glReadPixels was sometimes mistakenly clipped by the scissor box
    +      - glDraw/ReadPixels didn't catch all the errors that they should have
    +      - Fixed 24bpp rendering problem in Windows driver (Karl Schultz)
    +      - 16-bit GLchan mode fixes (m_trans_tmp.h, s_triangle.c)
    +      - Fixed 1-bit float->int conversion bug in glDrawPixels(GL_DEPTH_COMP)
    +      - glColorMask as sometimes effecting glXSwapBuffers()
    +      - fixed a potential bug in XMesaGarbageCollect()
    +      - N threads rendering into one window didn't work reliably
    +      - glCopyPixels didn't work for deep color channels
    +      - improved 8 -> 16bit/channel texture image conversion (Gerk Huisma)
    +      - glPopAttrib() didn't correctly restore user clip planes
    +      - user clip planes failed for some perspective projections (Chromium)
    +
    + +

    December 17, 2001

    +

    Mesa 4.0.1 has been released. This is a stable bug-fix release. +

        New:
    +      - better sub-pixel sample positions for AA triangles (Ray Tice)
    +      - slightly faster blending for (GL_ZERO, GL_ONE) and (GL_ONE, GL_ZERO)
    +    Bug fixes:
    +      - added missing break statements in glGet*() for multisample cases
    +      - fixed uninitialized hash table mutex bug (display lists / texobjs)
    +      - fixed bad teximage error check conditional (bug 476846)
    +      - fixed demos readtex.c compilation problem on Windows (Karl Schultz)
    +      - added missing glGet() query for GL_MAX_TEXTURE_LOD_BIAS_EXT
    +      - silence some compiler warnings (gcc 2.96)
    +      - enable the #define GL_VERSION_1_3 in GL/gl.h
    +      - added GL 1.3 and GLX 1.4 entries to gl_mangle.h and glx_mangle.h
    +      - fixed glu.h typedef problem found with MSDev 6.0
    +      - build libGL.so with -Bsymbolic (fixes bug found with Chromium)
    +      - added missing 'const' to glXGetContextIDEXT() in glxext.h
    +      - fixed a few glXGetProcAddress() errors (texture compression, etc)
    +      - fixed start index bug in compiled vertex arrays (Keith)
    +      - fixed compilation problems in src/SPARC/glapi_sparc.S
    +      - fixed triangle strip "parity" bug found in VTK medical1 demo (Keith)
    +      - use glXGetProcAddressARB in GLUT to avoid extension linking problems
    +      - provoking vertex of flat-shaded, color-index triangles was wrong
    +      - fixed a few display list bugs (GLUT walker, molecule, etc) (Keith)
    +      - glTexParameter didn't flush the vertex buffer (Ray Tice)
    +      - feedback attributes for glDraw/CopyPixels and glBitmap were wrong
    +      - fixed bug in normal length caching (ParaView lighting bug)
    +
    + +

    October 22, 2001

    +

    Mesa 4.0 has been released. This is a stable release. +

        New:
    +      - Mesa 4.0 implements the OpenGL 1.3 specification
    +      - GL_IBM_rasterpos_clip extension
    +      - GL_EXT_texture_edge_clamp extension (aka GL_SGIS_texture_edge_clamp)
    +      - GL_ARB_texture_mirrored_repeat extension
    +      - WindML UGL driver (Stephane Raimbault)
    +      - added OSMESA_MAX_WIDTH/HEIGHT queries
    +      - attempted compiliation fixes for Solaris 5, 7 and 8
    +      - updated glext.h and glxext.h files
    +      - updated Windows driver (Karl Schultz)
    +    Bug fixes:
    +      - added some missing GLX 1.3 tokens to include/GL/glx.h
    +      - GL_COLOR_MATRIX changes weren't recognized by teximage functions
    +      - glCopyPixels with scale and bias was broken
    +      - glRasterPos with lighting could segfault
    +      - glDeleteTextures could leave a dangling pointer
    +      - Proxy textures for cube maps didn't work
    +      - fixed a number of 16-bit color channel bugs
    +      - fixed a few minor memory leaks
    +      - GLX context sharing was broken in 3.5
    +      - fixed state-update bugs in glPopClientAttrib()
    +      - fixed glDrawRangeElements() bug
    +      - fixed a glPush/PopAttrib() bug related to texture binding
    +      - flat-shaded, textured lines were broken
    +      - fixed a dangling pointer problem in the XMesa code (Chris Burghart)
    +      - lighting didn't always produce the correct alpha value
    +      - fixed 3DNow! code to not read past end of arrays (Andrew Lewycky)
    +
    + + +

    June 21, 2001

    +

    Mesa 3.5 has been released. This is a new development release. +

        New:
    +	- internals of Mesa divided into modular pieces (Keith Whitwell)
    +	- 100% OpenGL 1.2 conformance (passes all conformance tests)
    +	- new AA line algorithm
    +	- GL_EXT_convolution extension
    +        - GL_ARB_imaging subset
    +        - OSMesaCreateContextExt() function
    +        - GL_ARB_texture_env_add extension (same as GL_EXT_texture_env_add)
    +        - GL_MAX_TEXTURE_UNITS_ARB now defaults to eight
    +        - GL_EXT_fog_coord extension (Keith Whitwell)
    +        - GL_EXT_secondary_color extension (Keith Whitwell)
    +        - GL_ARB_texture_env_add extension (same as GL_EXT_texture_env_add)
    +        - GL_SGIX_depth_texture extension
    +        - GL_SGIX_shadow and GL_SGIX_shadow_ambient extensions
    +        - demos/shadowtex.c demo of GL_SGIX_depth_texture and GL_SGIX_shadow
    +        - GL_ARB_texture_env_combine extension
    +        - GL_ARB_texture_env_dot3 extension
    +        - GL_ARB_texture_border_clamp (aka GL_SGIS_texture_border_clamp)
    +        - OSMesaCreateContextExt() function
    +        - libOSMesa.so library, contains the OSMesa driver interface
    +        - GL/glxext.h header file for GLX extensions
    +        - somewhat faster software texturing, fogging, depth testing
    +        - all color-index conformance tests now pass (only 8bpp tested)
    +        - SPARC assembly language TCL optimizations (David Miller)
    +        - GL_SGIS_generate_mipmap extension
    +    Bug Fixes:
    +        - fbiRev and tmuRev were unitialized when using Glide3
    +        - fixed a few color index mode conformance failures; all pass now
    +        - now appling antialiasing coverage to alpha after texturing
    +        - colors weren't getting clamped to [0,1] before color table lookup
    +        - fixed RISC alignment errors caused by COPY_4UBV macro
    +        - drawing wide, flat-shaded lines could cause a segfault
    +        - vertices now snapped to 1/16 pixel to fix rendering of tiny triangles
    +    Changes:
    +        - SGI's Sample Implementation (SI) 1.3 GLU library replaces Mesa GLU
    +        - new libOSMesa.so library, contains the OSMesa driver interface
    +
    + + +

    May 17, 2001

    +

    Mesa 3.4.2 has been released. This is basically just a bug-fix release. +Here's what's new:

    +
        Bug fixes:
    +        - deleting the currently bound texture could cause bad problems
    +        - using fog could result in random vertex alpha values
    +         - AA triangle rendering could touch pixels outside right window bound
    +        - fixed byteswapping problem in clear_32bit_ximage() function
    +        - fixed bugs in wglUseFontBitmapsA(), by Frank Warmerdam
    +        - fixed memory leak in glXUseXFont()
    +        - fragment sampling in AA triangle function was off by 1/2 pixel
    +        - Windows: reading pixels from framebuffer didn't always work
    +        - glConvolutionFilter2D could segfault or cause FP exception
    +        - fixed segfaults in FX and X drivers when using tex unit 1 but not 0
    +        - GL_NAND logicop didn't work right in RGBA mode
    +        - fixed a memory corruption bug in vertex buffer reset code
    +        - clearing the softwara alpha buffer with scissoring was broken
    +        - fixed a few color index mode fog bugs
    +        - fixed some bad assertions in color index mode
    +        - fixed FX line 'stipple' bug #420091
    +    Changes:
    +        - optimized writing mono-colored pixel spans to X pixmaps
    +        - increased max viewport size to 2048 x 2048
    +
    + + +

    April 29, 2001

    +

    New Mesa website

    +

    Mark Manning produced the new website.
    Thanks, Mark!

    + + +

    February 14, 2001

    +

    Mesa 3.4.1 has been released. Here's what's new:

    +
        New:
    +        - fixed some Linux build problems
    +        - fixed some Windows build problems
    +        - GL_EXT_texture_env_dot3 extension (Gareth Hughes)
    +    Bug fixes:
    +        - added RENDER_START/RENDER_FINISH macros for glCopyTexImage in DRI
    +        - various state-update code changes needed for DRI bugs
    +        - disabled pixel transfer ops in glColorTable commands, not needed
    +        - fixed bugs in glCopyConvolutionFilter1D/2D, glGetConvolutionFilter
    +        - updated sources and fixed compile problems in widgets-mesa/
    +        - GLX_PBUFFER enum value was wrong in glx.h
    +        - fixed a glColorMaterial lighting bug
    +        - fixed bad args to Read/WriteStencilSpan in h/w stencil clear function
    +        - glXCopySubBufferMESA() Y position was off by one
    +        - Error checking of glTexSubImage3D() was broken (bug 128775)
    +        - glPopAttrib() didn't restore all derived Mesa state correctly
    +        - Better glReadPixels accuracy for 16bpp color - fixes lots of OpenGL
    +          conformance problems at 16bpp.
    +        - clearing depth buffer with scissoring was broken, would segfault
    +        - OSMesaGetDepthBuffer() returned bad bytesPerValue value
    +        - fixed a line clipping bug (reported by Craig McDaniel)
    +        - fixed RGB color over/underflow bug for very tiny triangles
    +    Known problems:
    +        - NURBS or evaluator surfaces inside display lists don't always work
    +
    +

    +

    November 3, 2000

    +

    Mesa 3.4 has been released. Here's what's new since the 3.3 release:

    +
        New:
    +    - optimized glDrawPixels for glPixelZoom(1,-1)
    +    Bug Fixes:
    +    - widgets-mesa/src/*.c files were missing from 3.3 distro
    +    - include/GL/mesa_wgl.h file was missing from 3.3 distro
    +    - fixed some Win32 compile problems
    +    - texture object priorities weren't getting initialized to 1.0
    +    - glAreTexturesResident return value was wrong when using hardware
    +    - glXUseXFont segfaulted when using 3dfx driver (via MESA_GLX_FX)
    +    - glReadPixels with GLushort packed types was broken
    +    - fixed a few bugs in the GL_EXT_texture_env_combine texture code
    +    - glPush/PopAttrib(GL_ENABLE_BIT) mishandled multi-texture enables
    +    - fixed some typos/bugs in the VB code
    +    - glDrawPixels(GL_COLOR_INDEX) to RGB window didn't work
    +    - optimized glDrawPixels paths weren't being used
    +    - per-fragment fog calculation didn't work without a Z buffer
    +    - improved blending accuracy, fixes Glean  blendFunc test failures
    +    - glPixelStore(GL_PACK/UNPACK_SKIP_IMAGES) wasn't handled correctly
    +    - glXGetProcAddressARB() didn't always return the right address
    +    - gluBuild[12]DMipmaps() didn't grok the GL_BGR pixel format
    +    - texture matrix changes weren't always detected (GLUT projtex demo)
    +    - fixed random color problem in vertex fog code
    +    - fixed Glide-related bug that let Quake get a 24-bit Z buffer
    +    Changes:
    +    - finished internal support for compressed textures for DRI
    +
    +

    +

    April 24, 2000

    +

    Mesa 3.2 has been released. Here's what's new since the beta release:

    +
        Bug fixes:
    +    - fixed memcpy bugs in span.c
    +    - fixed missing glEnd problem in demos/tessdemo.c
    +    - fixed bug when clearing 24bpp Ximages
    +    - fixed clipping problem found in Unreal Tournament
    +    - fixed Loki's "ice bug" and "crazy triangles" seen in Heretic2
    +    - fixed Loki's 3dfx RGB vs BGR bug
    +    - fixed Loki's 3dfx smooth/flat shading bug in SoF
    +    Changes:
    +    - updated docs/README file
    +    - use bcopy() optimizations on FreeBSD
    +    - re-enabled the optimized persp_textured_triangle() function
    +
    +

    +

    March 23, 2000

    +

    I've just upload the Mesa 3.2 beta 1 files to SourceForge at http://sourceforge.net/project/filelist.php?group_id=3

    +

    3.2 (note even number) is a stabilization release of Mesa 3.1 meaning it's mainly +just bug fixes.

    +

    Here's what's changed: + +

      + Bug fixes: +
        + - mixed drawing of lines and bitmaps sometimes had wrong colors
        + - added missing glHintPGI() function
        + - fixed a polygon culling bug
        + - fixed bugs in gluPartialDisk()
        + - Z values in selection mode were wrong
        + - added missing tokens: +
          + GL_SMOOTH_POINT_SIZE_RANGE
          + GL_SMOOTH_POINT_SIZE_GRANULARITY
          + GL_SMOOTH_LINE_WIDTH_RANGE
          + GL_SMOOTH_LINE_WIDTH_GRANULARITY
          + GL_ALIASED_POINT_SIZE_RANGE
          + GL_ALIASED_LINE_WIDTH_RANGE +
        + - fixed glCopyPixels when copying from back to front buffer
        + - GL_EXT_compiled_vertex_array tokens had _SGI suffix instead of _EXT
        + - glDrawRangeElements(GL_LINES, 0, 1, 2, type, indices) was broken
        + - glDeleteTextures() didn't decrement reference count correctly
        + - GL_SRCA_ALPHA_SATURATE blend mode didn't work correctly
        + - Actual depth of transformation matrix stacks was off by one
        + - 24bpp visuals didn't address pixels correctly
        + - mipmap level of detail (lambda) calculation simplified, more accurate
        + - 101691 - Polygon clipping and GL_LINE
        + - 101928 - Polygon clipping and GL_LINE (same fix as above)
        + - 101808 - Non-glVertexArrays tristrip bug
        + - 101971 - find_last_3f on Dec OSF (worked around)
        + - 102369 - segv on dec osf (possibly a duplicate of the above)
        + - 102893 - orientations of modelview cause segfault +
      + New: +
        + - updated SVGA Linux driver
        + - added the MESA_FX_NO_SIGNALS env var, see docs/README.3DFX
        + - build libGLw.a (Xt/OpenGL drawing area widget) library by default
        + - changed -O2 to -O3 for a number of gcc configs +
      + Changes: +
        + - glXCopyContext's mask parameter is now unsigned long, per GLX spec +
      +
    + +

    Please report any problems with this release ASAP. Bugs should be filed on the +Mesa3D website at sourceforge.
    +After 3.2 is wrapped up I hope to release 3.3 beta 1 soon afterward.

    +

    -- Brian

    +

    +

    December 17, 1999

    +

    A Slashdot interview with Brian about Mesa (questions submitted by Slashdot readers) +can be found at http://slashdot.org/interviews/99/12/17/0927212.shtml.

    +

    +

    December 14, 1999

    +

    Mesa 3.1 is released!

    +

    +

    September 21, 1999

    +

    There appear to be two new files on the ftp site, MesaLib-3.1beta3.tar.gz +and MesaDemos-3.1beta3.tar.gz, +that seem to be... yes, I've just received confirmation from the beta center, they +are indeed the THIRD beta release of Mesa 3.1! Happy Days. Happy Days. Thanks +Keith Whitwell for preparing these for us during Brian's absence.

    +

    +

    August 30, 1999

    +

    I'm pleased to announce that I've accepted a position with Precision Insight, +Inc. effective October, 1999. I'll be leaving Avid Technology in September.

    +

    I've been working on Mesa in my spare time for over five years. With Precision +Insight I now have the opportunity to devote my full attention to advancing Mesa +and OpenGL on Linux.

    +

    While I'll be focused on Linux, the X Window System, and hardware acceleration, +my work will continue to be open sourced and available to any other programmers who +may want to contribute to it, or use it for other projects or platforms

    +

    PS: I'm going to be traveling until Sep 6 and won't be reading email until then.

    +

    +

    August 23, 1999

    +

    Anonymous CVS access is back online so suck up all the bandwidth you can afford. +Note that this is a new archive, so you will need to re-checkout the archive. That +means don't cvs update from a previous download.

    +

    +

    August 17, 1999

    +

    A report from the SIGGRAPH '99 Linux/OpenGL +BOF meeting is now available.

    +

    -Brian

    +

    +

    August 14, 1999

    +

    www.mesa3d.org is having technical problems due to hardware failures at VA Linux +systems. The Mac pages, ftp, and CVS services aren't fully restored yet. Please be +patient.

    +

    -Brian

    +

    +

    June 7, 1999

    +

    RPMS of the nVidia RIVA server can be found at ftp://ftp.mesa3d.org/mesa/misc/nVidia/.

    +

    +

    June 2, 1999

    +

    nVidia has released some Linux binaries for +xfree86 3.3.3.1, along with the full source, which includes GLX acceleration +based on Mesa 3.0. They can be downloaded from http://www.nvidia.com/Products.nsf/htmlmedia/software_drivers.html.

    +

    +

    May 24, 1999

    +

    Beta 2 of Mesa 3.1 has been make available at ftp://ftp.mesa3d.org/mesa/beta/. +If you are into the quake scene, you may want to try this out, as it contains some +optimizations specifically in the Q3A rendering path. +

    +

    May 13, 1999

    +

    For those interested in the integration of Mesa into XFree86 4.0, Precision Insight +has posted their lowlevel design documents at http://www.precisioninsight.com.

    +

    +

    May 13, 1999

    +
    May 1999 - John Carmack of id Software, Inc. has made a donation of
    +US$10,000 to the Mesa project to support its continuing development.
    +Mesa is a free implementation of the OpenGL 3D graphics library and id's
    +newest game, Quake 3 Arena, will use Mesa as the 3D renderer on Linux.
    +
    +The donation will go to Keith Whitwell, who has been optimizing Mesa to
    +improve performance on 3d hardware.  Thanks to Keith's work, many
    +applications using Mesa 3.1 will see a dramatic performance increase
    +over Mesa 3.0.  The donation will allow Keith to continue working on
    +Mesa full time for some time to come.
    +
    +For more information about Mesa see www.mesa3d.org.  For more
    +information about id Software, Inc. see www.idsoftware.com.
    +
    +--------------------------------
    +
    +This donation from John/id is very generous.  Keith and I are very
    +grateful.
    +
    +
    +

    +

    May 1, 1999

    +

    John Carmack made an interesting .plan update yesterday: + +

      + "I put together a document on optimizing OpenGL drivers for Q3 that + should be helpful to the various Linux 3D teams.
      +
      http://www.quake3arena.com/news/glopt.html" +
    + +

    +

    April 7, 1999

    +

    Updated the Mesa contributors section and added links to RPM Mesa packages.

    +

    +

    March 18, 1999

    +

    The new webpages are now online. Enjoy, and let me know if you find any errors. +

    +

    February 16, 1999

    +

    SGI releases its GLX +source code.

    +

    +

    January 22, 1999

    +

    www.mesa3d.org established

    + + +

    + + +
    + + diff --git a/docs/opengles.html b/docs/opengles.html new file mode 100644 index 0000000..63cc114 --- /dev/null +++ b/docs/opengles.html @@ -0,0 +1,80 @@ + + +OpenGL ES + + + + + +

    OpenGL ES

    + +

    Mesa implements OpenGL ES 1.1 and OpenGL ES 2.0. More informations about +OpenGL ES can be found at http://www.khronos.org/opengles/.

    + +

    OpenGL ES depends on a working EGL implementation. Please refer to +Mesa EGL for more information about EGL.

    + +

    Build the Libraries

    +
      +
    1. Run configure with --enable-gles-overlay and enable the Gallium driver for your hardware.
    2. +
    3. Build and install Mesa as usual.
    4. +
    + +Alternatively, if XCB-DRI2 is installed on the system, one can use +egl_dri2 EGL driver with OpenGL|ES-enabled DRI drivers + +
      +
    1. Run configure with --enable-gles1 --enable-gles2.
    2. +
    3. Build and install Mesa as usual.
    4. +
    + +

    Both methods will install libGLESv1_CM, libGLESv2, libEGL, and one or more +EGL drivers for your hardware.

    + +

    Run the Demos

    + +

    There are some demos in progs/egl/. You can use them to test +your build. For example,

    + +
    +  $ cd progs/egl/eglut
    +  $ make
    +  $ cd ../opengles1
    +  $ make
    +  $ ./torus_x11
    +
    + +

    Developers

    + +

    Internal Libraries

    + + + + + + + +
    Library NameUsed ByEnabledOpenGLOpenGL ES 1.xOpenGL ES 2.x
    libmesa.aClassic DRI driversyy--enable-gles1--enable-gles2
    libmesagallium.aGallium EGL and DRI driversyy--enable-gles1--enable-gles2
    libes1gallium.aGallium EGL drivers--enable-gles-overlaynyn
    libes2gallium.aGallium EGL drivers--enable-gles-overlaynny
    + +

    Dispatch Table

    + +

    OpenGL ES has an additional indirection when dispatching fucntions

    + +
    +  Mesa:       glFoo() --> _mesa_Foo()
    +  OpenGL ES:  glFoo() --> _es_Foo() --> _mesa_Foo()
    +
    + +

    The indirection serves several purposes

    + +
      +
    • When a function is in Mesa and the type matches, it checks the arguments and calls the Mesa function.
    • +
    • When a function is in Mesa but the type mismatches, it checks and converts the arguments before calling the Mesa function.
    • +
    • When a function is not available in Mesa, or accepts arguments that are not available in OpenGL, it provides its own implementation.
    • +
    + +

    Other than the last case, OpenGL ES uses APIspec.xml to generate functions to check and/or converts the arguments.

    + + + diff --git a/docs/openvg.html b/docs/openvg.html new file mode 100644 index 0000000..eff8c58 --- /dev/null +++ b/docs/openvg.html @@ -0,0 +1,52 @@ + + +OpenVG State Tracker + + + + + + + +

    OpenVG State Tracker

    + +

    +The current version of the OpenVG state tracker implements OpenVG 1.0. +

    +

    +More informations about OpenVG can be found at + +http://www.khronos.org/openvg/ . +

    +

    +The OpenVG state tracker depends on the Gallium architecture and a working EGL implementation. +Please refer to Mesa EGL for more information about EGL. +

    + + +

    Building the library

    +
      +
    1. Run configure with --enable-openvg. If you do +not need OpenGL, you can add --disable-opengl to save the +compilation time.
    2. + +
    3. Build and install Mesa as usual.
    4. +
    + +

    Sample build

    +A sample build looks as follows: +
    +  $ ./configure --disable-opengl --enable-openvg
    +  $ make
    +  $ make install
    +
    + +

    It will install libOpenVG.so, libEGL.so, and one +or more EGL drivers.

    + +

    OpenVG Demos

    + +

    OpenVG demos can be found in mesa/demos repository.

    + + + diff --git a/docs/osmesa.html b/docs/osmesa.html new file mode 100644 index 0000000..525da4d --- /dev/null +++ b/docs/osmesa.html @@ -0,0 +1,88 @@ + + +Off-screen Rendering + + + + + +

    Off-screen Rendering

    + + +

    +Mesa's off-screen rendering interface is used for rendering into +user-allocated blocks of memory. +That is, the GL_FRONT colorbuffer is actually a buffer in main memory, +rather than a window on your display. +There are no window system or operating system dependencies. +One potential application is to use Mesa as an off-line, batch-style renderer. +

    + +

    +The OSMesa API provides three basic functions for making off-screen +renderings: OSMesaCreateContext(), OSMesaMakeCurrent(), and +OSMesaDestroyContext(). See the Mesa/include/GL/osmesa.h header for +more information about the API functions. +

    + +

    +There are several examples of OSMesa in the progs/osdemos/ +directory. +

    + + +

    Deep color channels

    + +

    +For some applications 8-bit color channels don't have sufficient +precision. +OSMesa supports 16-bit and 32-bit color channels through the OSMesa interface. +When using 16-bit channels, channels are GLushorts and RGBA pixels occupy +8 bytes. +When using 32-bit channels, channels are GLfloats and RGBA pixels occupy +16 bytes. +

    + +

    +Before version 6.5.1, Mesa had to be recompiled to support exactly +one of 8, 16 or 32-bit channels. +With Mesa 6.5.1, Mesa can be compiled for either 8, 16 or 32-bit channels +and render into any of the smaller size channels. +For example, if Mesa's compiled for 32-bit channels, you can also render +16 and 8-bit channel images. +

    + +

    +To build Mesa/OSMesa for 16 and 8-bit color channel support: +

    +      make realclean
    +      make linux-osmesa16
    +
    + +

    +To build Mesa/OSMesa for 32, 16 and 8-bit color channel support: +

    +      make realclean
    +      make linux-osmesa32
    +
    + +

    +You'll wind up with a library named libOSMesa16.so or libOSMesa32.so. +Otherwise, most Mesa configurations build an 8-bit/channel libOSMesa.so library +by default. +

    + +

    +If performance is important, compile Mesa for the channel size you're +most interested in. +

    + +

    +If you need to compile on a non-Linux platform, copy Mesa/configs/linux-osmesa16 +to a new config file and edit it as needed. Then, add the new config name to +the top-level Makefile. Send a patch to the Mesa developers too, if you're +inclined. +

    + + + diff --git a/docs/perf.html b/docs/perf.html new file mode 100644 index 0000000..ee9c4b1 --- /dev/null +++ b/docs/perf.html @@ -0,0 +1,68 @@ + + +Performance Tips + + + + + +

    Performance Tips

    + +

    +Performance tips for software rendering: +

    +
      + +
    1. Turn off smooth shading when you don't need it (glShadeModel) +
    2. Turn off depth buffering when you don't need it. +
    3. Turn off dithering when not needed. +
    4. Use double buffering as it's often faster than single buffering +
    5. Compile in the X Shared Memory extension option if it's supported + on your system by adding -DSHM to CFLAGS and -lXext to XLIBS for + your system in the Make-config file. +
    6. Recompile Mesa with more optimization if possible. +
    7. Try to maximize the amount of drawing done between glBegin/glEnd pairs. +
    8. Use the MESA_BACK_BUFFER variable to find best performance in double + buffered mode. (X users only) +
    9. Optimized polygon rasterizers are employed when: + rendering into back buffer which is an XImage + RGB mode, not grayscale, not monochrome + depth buffering is GL_LESS, or disabled + flat or smooth shading + dithered or non-dithered + no other rasterization operations enabled (blending, stencil, etc) +
    10. Optimized line drawing is employed when: + rendering into back buffer which is an XImage + RGB mode, not grayscale, not monochrome + depth buffering is GL_LESS or disabled + flat shading + dithered or non-dithered + no other rasterization operations enabled (blending, stencil, etc) +
    11. Textured polygons are fastest when: + using a 3-component (RGB), 2-D texture + minification and magnification filters are GL_NEAREST + texture coordinate wrap modes for S and T are GL_REPEAT + GL_DECAL environment mode + glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST ) + depth buffering is GL_LESS or disabled +
    12. Lighting is fastest when: + Two-sided lighting is disabled + GL_LIGHT_MODEL_LOCAL_VIEWER is false + GL_COLOR_MATERIAL is disabled + No spot lights are used (all GL_SPOT_CUTOFFs are 180.0) + No local lights are used (all position W's are 0.0) + All material and light coefficients are >= zero +
    13. XFree86 users: if you want to use 24-bit color try starting your + X server in 32-bit per pixel mode for better performance. That is, + start your X server with + startx -- -bpp 32 + instead of + startx -- -bpp 24 +
    14. Try disabling dithering with the MESA_NO_DITHER environment variable. + If this env var is defined Mesa will disable dithering and the + command glEnable(GL_DITHER) will be ignored. +
    + + + + diff --git a/docs/precompiled.html b/docs/precompiled.html new file mode 100644 index 0000000..50cb2af --- /dev/null +++ b/docs/precompiled.html @@ -0,0 +1,20 @@ + + +Precompiled libraries + + + + + +

    Precompiled Libraries

    + +

    +In general, precompiled Mesa libraries are not available. +

    +

    +However, some Linux distros (such as Ubuntu) seem to closely track +Mesa and often have the latest Mesa release available as an update. +

    + + + diff --git a/docs/relnotes-6.4.1.html b/docs/relnotes-6.4.1.html new file mode 100644 index 0000000..3d6ff1c --- /dev/null +++ b/docs/relnotes-6.4.1.html @@ -0,0 +1,68 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 6.4.1 / November 29, 2006

    + +

    +Mesa 6.4.1 is a stable, bug-fix release. +

    + + +

    MD5 checksums

    +
    +698ceb574cf882b0226761f5913c0da9  MesaLib-6.4.1.tar.gz
    +ea148c828ec6f645526451db1b8556f1  MesaLib-6.4.1.tar.bz2
    +42e93279468975ed2bf3111b8721e5d9  MesaLib-6.4.1.zip
    +e3b0d50807fd2bdcd1a95aaddd786f13  MesaDemos-6.4.1.tar.gz
    +99df1fdcb98d391666b476ca6f1dda8a  MesaDemos-6.4.1.tar.bz2
    +b999d2c6d92fb4b7740a3dbd889348e3  MesaDemos-6.4.1.zip
    +eadfe01fe5ddfb1eb8227dd567b31635  MesaGLUT-6.4.1.tar.gz
    +bd003bb4f981a4f91dee4c38644d4f3f  MesaGLUT-6.4.1.tar.bz2
    +71c401c037088bf688a88afdaeb3420f  MesaGLUT-6.4.1.zip
    +
    + + +

    Bug fixes

    +
      +
    • redefining a vertex program string didn't take effect in TNL module +
    • fixed occasional segfault upon vertex/fragment parsing error +
    • vertex program LIT instruction didn't handle 0^0=1 correctly +
    • fragment program fog option didn't work with glDrawPixels, glBitmap +
    • USE_MGL_NAMESPACE didn't work for x86-64 +
    • OSMesa demos were missing from previous release tarballs +
    • fixed problem with float->ushort conversion in glClear (bug 4992) +
    • popping of GL_EYE_PLANE texgen state was broken (bug 4996) +
    • popping of GL_SPOT_DIRECTION light state was broken (bug 5005) +
    • fixed occasional triangle color interpolation problem on VMS +
    • work around invalid free() call (bug 5131) +
    • fixed BSD X server compilation problem by including stdint.h +
    + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa (Xlib)		implements OpenGL 1.5
    +OSMesa (off-screen)	implements OpenGL 1.5
    +Windows/Win32		implements OpenGL 1.5
    +Glide (3dfx Voodoo1/2)  requires updates	
    +SVGA			requires updates
    +DJGPP			requires updates
    +GGI			requires updates
    +BeOS			requires updates
    +Allegro			requires updates
    +D3D			requires updates
    +
    + + + diff --git a/docs/relnotes-6.4.2.html b/docs/relnotes-6.4.2.html new file mode 100644 index 0000000..f5a658f --- /dev/null +++ b/docs/relnotes-6.4.2.html @@ -0,0 +1,75 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 6.4.2 / February 2, 2006

    + +

    +Mesa 6.4.2 is a stable, bug-fix release. +

    + + +

    MD5 checksums

    +
    +cb0d745d520fa7c2bb9178058b763544  MesaLib-6.4.2.tar.gz
    +7674d2c603b5834259e4e5a820cefd5b  MesaLib-6.4.2.tar.bz2
    +d224e1325b33ff71a0f3893fc6b4d594  MesaLib-6.4.2.zip
    +d4b345d4588fc750cd3d34f3ac26673e  MesaDemos-6.4.2.tar.gz
    +9cae1ab874af533ce356bd7dfe2e0bb0  MesaDemos-6.4.2.tar.bz2
    +2da6e1d1245e441d27813595c6ba50de  MesaDemos-6.4.2.zip
    +84427d18c3453f0ea52388eeba7169b5  MesaGLUT-6.4.2.tar.gz
    +b157ba8ad1ea63260cf5339132e7aac6  MesaGLUT-6.4.2.tar.bz2
    +fe1523744fc05edc3811dfc6a1bf4181  MesaGLUT-6.4.2.zip
    +
    + + +

    New features

    +
      +
    • added OSMesaColorClamp() function/feature +
    • added wglGetExtensionStringARB() function +
    + +

    Changes

    +
      +
    • GLUT tarball +
      +Starting with 6.4, the GLUT library sources are distributed in a separate +tarball. This was done at the request of Linux distro vendors who prefer +to use freeglut. +
    + +

    Bug fixes

    +
      +
    • fixed some problems when building on Windows +
    • GLw header files weren't installed by installmesa script (bug 5396) +
    • GL/glfbdev.h file was missing from tarballs +
    • fixed TNL initialization bug which could lead to crash (bug 5791) +
    + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa (Xlib)		implements OpenGL 1.5
    +OSMesa (off-screen)	implements OpenGL 1.5
    +Windows/Win32		implements OpenGL 1.5
    +Glide (3dfx Voodoo1/2)  requires updates	
    +SVGA			requires updates
    +DJGPP			requires updates
    +GGI			requires updates
    +BeOS			requires updates
    +Allegro			requires updates
    +D3D			requires updates
    +
    + + + diff --git a/docs/relnotes-6.4.html b/docs/relnotes-6.4.html new file mode 100644 index 0000000..1fffa27 --- /dev/null +++ b/docs/relnotes-6.4.html @@ -0,0 +1,90 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 6.4 / October 24, 2005

    + +

    +Mesa 6.4 is a stable, bug-fix release. +

    + + +

    MD5 checksums

    +
    +1cce0c1eb4fd15e9dfe837a1ce0c9812  MesaLib-6.4.tar.gz
    +85a84e47a3f718f752f306b9e0954ef6  MesaLib-6.4.tar.bz2
    +b976fea4f3ee06354c53f91b6e3f2ffc  MesaLib-6.4.zip
    +d8734f2c69bcf7ef9f5ae454a85743ba  MesaDemos-6.4.tar.gz
    +1a8c4d4fc699233f5fdb902b8753099e  MesaDemos-6.4.tar.bz2
    +607ab7c7a7de0cc5febbdde2bfa03098  MesaDemos-6.4.zip
    +3260156f66174322a092be0767962d34  MesaGLUT-6.4.tar.gz
    +0465d053f83775f44a12dec4050dfd78  MesaGLUT-6.4.tar.bz2
    +02abfcdcdf72ba938ae00f6e3b70fbe0  MesaGLUT-6.4.zip
    +
    + + +

    New

    +
      +
    • Added a fast XOR line drawing function in Xlib driver +
    • Added support for GL_ARB_texture_mirrored_repeat to savage driver (supported only on Savage4 hardware). +
    + +

    Changes

    +
      +
    • Mesa now packaged in three parts: Library, Demos and GLUT +
    + +

    Bug fixes

    +
      +
    • GLX_X_RENDERABLE token wasn't accepted by glXChooseFBConfig +
    • Some files were present multiple times in the 6.3.2 tarballs +
    • r200_vtxtmp_x86.S file was missing from 6.3.2 tarball (bug 4207) +
    • glxgears_fbconfig demo didn't work (bug 4237) +
    • fixed bug when bilinear sampling 2d textures with borders +
    • glXCreatePbuffer() could segfault instead of returning 0 (bug 4235) +
    • fixed undefined frexp and rand in X.org libGLcore.a (bug 4242) +
    • fixed a few problems with proxy color tables (bug 4270) +
    • fixed precision problem in Z clearing (bug 4395) +
    • glBitmap, glDraw/CopyPixels mistakenly generated selection hits +
    • fixed potential segfault caused by reading pixels outside + of renderbuffer bounds +
    • glGetTexLevelParameter didn't accept GL_TEXTURE_DEPTH_SIZE_ARB +
    • fixed memory corruption bug involving software alpha buffers +
    • glReadPixels clipped by window bounds was sometimes broken +
    • glDraw/CopyPixels of stencil data ignored the stencil write mask +
    • glReadPixels from a texture bound to a framebuffer object didn't work +
    • glIsRender/FramebufferEXT weren't totally correct +
    • fixed a number of point size attenuation/fade bugs +
    • fixed glFogCoord bug 4729 +
    • GLX encoding for transpose matrix functions was broken +
    • fixed broken fragment program KIL and SWZ instructions +
    • fragment programs that wrote result.depth.z didn't work +
    + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa (Xlib)		implements OpenGL 1.5
    +OSMesa (off-screen)	implements OpenGL 1.5
    +Windows/Win32		implements OpenGL 1.5
    +Glide (3dfx Voodoo1/2)  requires updates	
    +SVGA			requires updates
    +DJGPP			requires updates
    +GGI			requires updates
    +BeOS			requires updates
    +Allegro			requires updates
    +D3D			requires updates
    +
    + + + diff --git a/docs/relnotes-6.5.1.html b/docs/relnotes-6.5.1.html new file mode 100644 index 0000000..0f03f93 --- /dev/null +++ b/docs/relnotes-6.5.1.html @@ -0,0 +1,139 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 6.5.1 Release Notes / September 15, 2006

    + +

    +Mesa 6.5.1 is a 6.5 follow-on development release mostly consisting of +bug fixes. +

    + + +

    MD5 checksums

    +
    +d9a555297319bb932a3192952d53d073  MesaLib-6.5.1.tar.gz
    +c46f2c6646a270911b791dd8e1c2d977  MesaLib-6.5.1.tar.bz2
    +939eaaff33322bfeafac784402b45f4f  MesaLib-6.5.1.zip
    +9e4bbe83c007bfbaa67449a81cc3d36a  MesaDemos-6.5.1.tar.gz
    +0f2794baf7a9d98b22caea9f78c6942d  MesaDemos-6.5.1.tar.bz2
    +14c77eab9cc7a265c331abf239927c1c  MesaDemos-6.5.1.zip
    +c5f87c23aaf4eaf1bda0d007ea98366c  MesaGLUT-6.5.1.tar.gz
    +2525642fe7f454e3e1a1aad01359b406  MesaGLUT-6.5.1.tar.bz2
    +e33b165c22551e23b58ede8767378543  MesaGLUT-6.5.1.zip
    +
    + + +

    New Features

    +
      +
    • Intel i965 "broadwater" DRI driver + +
    • GL_APPLE_vertex_array_object - allows encapsulation of a set of vertex + arrays in an object. + +
    • GL_EXT_texture_sRGB - non-linearly mapped texture formats + +
    • GL_EXT_gpu_program_parameters - addes a few new functions for setting + multiple vertex/fragment program parameters with one call. +
    • "engine" demo +
    • updated fbdev driver and GLUT for fbdev (Sean D'Epagnier) +
    • many updates to the DRI drivers +
    + +

    Changes

    +
      +
    • The glVertexAttribARB functions no longer alias the conventional + vertex attributes. +
    • glxinfo program prints more info with -l option +
    • GL_FRAGMENT_PROGRAM_NV and GL_FRAGMENT_PROGRAM_ARB are now + compatible, in terms of glBindProgramARB() +
    • The GL_ARB_vertex_program attribute vertex.weight is now + accepted by the parser, even though the GL_ARB_vertex_blend and + GL_EXT_vertex_weighting extensions aren't supported. + Allows Warcraft to run. +
    + +

    Bug fixes

    +
      +
    • fixed broken texture border handling for depth textures (bug 6498) +
    • removed the test for duplicated framebuffer attachments, per + version 117 of the GL_EXT_framebuffer_object specification +
    • fixed a few render-to-texture bugs, including render to depth texture +
    • clipping of lines against user-defined clip planes was broken (6512) +
    • assembly language dispatch for SPARC was broken (bug 6484) +
    • assorted compilation fixes on various Unix platforms (Dan Schikore) +
    • glPopAttrib could restore an invalid value for GL_DRAW_BUFFER +
    • assorted minor fixes for 16 and 32 bit/channel modes +
    • fixed assorted bugs in texture compression paths +
    • fixed indirect rendering vertex array crashes (bug 6863) +
    • glDrawPixels GL_INDEX_OFFSET didn't always work +
    • fixed convolution memory leak (bug 7077) +
    • rectangular depth textures didn't work +
    • invalid mode to glBegin didn't generate an error (bug 7142) +
    • 'normalized' parameter to glVertexAttribPointerARB didn't work +
    • disable bogus GLX_SGI_video_sync extension in xlib driver +
    • fixed R128 driver locking bug (Martijn van Oosterhout) +
    • using evaluators with vertex programs caused crashes (bug 7564) +
    • fragment.position wasn't set correctly for point/line primitives +
    • fixed parser bug for scalar sources for GL_NV_fragment_program +
    • max fragment program length was incorrectly 128, now 1024 +
    • writes to result.depth in fragment programs weren't clamped to [0,1] +
    • fixed potential dangling pointer bug in glBindProgram() +
    • fixed some memory leaks (and potential crashes) in Xlib driver +
    • fixed a number of build issues on HP-UX (Christopher Bell) +
    • accum buffer didn't work with OSMesa interface +
    + + +

    Internal code changes

    + +

    +A number of Mesa program-related structs were renamed. +For example struct vertex_program is now struct gl_vertex_program. +All the effected drivers have been updated. +

    + +

    Ian Romanick updated the GL API dispatch code in a number of ways. +First, many old/unused extensions were removed. +Second, the static entrypoints for some extensions were removed. +This means GL function pointers will have to be used more often +(e.g. use glXGetProcAddressARB()). +

    + + +

    To Do (someday) items

    +
      +
    • Switch to freeglut +
    • Increase MAX_DRAWBUFFERS +
    • Fix linux-glide target/driver. +
    • Fix lambda calculation for frag progs. +
    + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 1.5
    +OSMesa (off-screen)	implements OpenGL 1.5
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			implements OpenGL 1.3
    +Wind River UGL		implements OpenGL 1.3
    +Windows/Win32		implements OpenGL 1.5
    +DJGPP			implements OpenGL 1.5
    +GGI			implements OpenGL 1.3
    +BeOS			implements OpenGL 1.5
    +Allegro			needs updating
    +D3D			needs updating
    +
    + + + diff --git a/docs/relnotes-6.5.2.html b/docs/relnotes-6.5.2.html new file mode 100644 index 0000000..db2038a --- /dev/null +++ b/docs/relnotes-6.5.2.html @@ -0,0 +1,126 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 6.5.2 Release Notes / December 2, 2006

    + +

    +Mesa 6.5.2 is a 6.5 follow-on development release with a few new features +but mostly consisting of bug fixes. +

    + + +

    MD5 checksums

    +
    +11a033b078e090b3caaeb467234fe299  MesaLib-6.5.2.tar.gz
    +e4d894181f1859651658b3704633e10d  MesaLib-6.5.2.tar.bz2
    +63bf1d444fa738cca52ce1043e284021  MesaLib-6.5.2.zip
    +2b8f1375d16bda5f5a2304174cd5bcf7  MesaDemos-6.5.2.tar.gz
    +e870efe98d3a50be01ab211b9b2e25d9  MesaDemos-6.5.2.tar.bz2
    +d92cc6f5fee5ca75af0be04f9f4908f0  MesaDemos-6.5.2.zip
    +8d4d77e3a7132f4217bbc7c1ab157030  MesaGLUT-6.5.2.tar.gz
    +e84edbb11c69c8e408dfadd2ed08e95b  MesaGLUT-6.5.2.tar.bz2
    +c6d7134843ed5faf11f6686ecb5d2a2e  MesaGLUT-6.5.2.zip
    +
    + + +

    New features

    +
      +
    • New DRI memory manager system. Currently used by the i915tex driver. +Other DRI drivers will be updated to use the new memory manager in coming +months. +
      +To use the new driver you'll need the most recent DRM library and drivers +(version 2.2 or later) and a recent xf86-video-intel driver module from X.org. +
      +New features resulting from this work include: +
        +
      • EXT_framebuffer_objects, render to texture +
      • ARB_pixel_buffer_objects +
      • Accelerated CopyTexSubimage, DrawPixels, ReadPixels, CopyPixels +
      • Accelerated texture uploads from pixel buffer objects +
      • Potentially texturing directly from the pixel buffer object (zero +copy texturing). +
      +
    • New Intel i965 DRI driver +
    • New minstall script to replace normal install program +
    • Faster fragment program execution in software +
    • Added (or fixed) support for + GLX_SGI_make_current_read to the following drivers:
    • +
        +
      • radeon
      • +
      • savage
      • +
      • mga
      • +
      • tdfx
      • +
      +
    • Added support for ARB_occlusion_query to the tdfx driver (Ian +Romanick).
    • +
    + +

    Bug fixes

    +
      +
    • fixed invalid memory read while rendering textured points (bug 8320) +
    • fixed problems with freebsd-dri configuration (bug 8344) +
    • Mesa's fake glxGetCurrentContext() wasn't thread-aware +
    • OPTION NV_position_invariant didn't work in NV vertex programs +
    • glDrawPixels into a user-created framebuffer object could crash Xlib driver +
    • Line clipping was broken in some circumstances +
    • fragment.fogcoord register didn't always contain the correct value +
    • RGBA logicops didn't work reliably in some DRI drivers +
    • Fixed broken RGBA LogicOps in Intel DRI drivers +
    • Fixed some fragment program bugs in Intel i915 DRI driver +
    • Fixed glGetVertexAttribfvARB bug 8883 +
    • Implemented glGetUniform[fi]vARB() functions +
    • Fixed glDrawPixels(GL_COLOR_INDEX, GL_BITMAP) segfault (bug 9044) +
    • Fixed some gluBuild2DMipmaps() bugs (Greg McGarragh) +
    • Fixed broken "mgl" name mangling +
    • Indirect rending was broken for glMap* functions (bug 8899) +
    + + +

    Internal code changes

    + +
      +
    • The device driver functions ResizeBuffers and GetBufferSize have been +decprecated. +
    • OpenGL 2.0 and 2.1 support is nearly done. We need to do quite a bit +more testing of the shading language functions. +
    + + +

    To Do (someday) items

    +
      +
    • Switch to freeglut +
    • Increase MAX_DRAWBUFFERS +
    • Fix linux-glide target/driver. +
    • Improved lambda and derivative calculation for frag progs. +
    + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 1.5
    +OSMesa (off-screen)	implements OpenGL 1.5
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			implements OpenGL 1.3
    +Wind River UGL		implements OpenGL 1.3
    +Windows/Win32		implements OpenGL 1.5
    +DJGPP			implements OpenGL 1.5
    +GGI			implements OpenGL 1.3
    +BeOS			implements OpenGL 1.5
    +Allegro			needs updating
    +D3D			needs updating
    +
    + + + diff --git a/docs/relnotes-6.5.3.html b/docs/relnotes-6.5.3.html new file mode 100644 index 0000000..0d68d99 --- /dev/null +++ b/docs/relnotes-6.5.3.html @@ -0,0 +1,119 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 6.5.3 Release Notes / April 27, 2007

    + +

    +Mesa 6.5.3 is a development release with many changes and new features. +Mesa 7.0 is expected to follow shortly. +

    + + +

    MD5 checksums

    +
    +39f33ea64e34e2d5b20640b008b57649  MesaLib-6.5.3.tar.gz
    +46359457147c469745f24b5074a186f0  MesaLib-6.5.3.tar.bz2
    +a8946fa861634ce15971396f47992c41  MesaLib-6.5.3.zip
    +08e26948d57eaca74d02a530b2d8106e  MesaDemos-6.5.3.tar.gz
    +8af91773ab2653fe537499676b05f2e8  MesaDemos-6.5.3.tar.bz2
    +783f81b171bf89b0929abc894efd25a6  MesaDemos-6.5.3.zip
    +9467d415388fe1ad82991fb20704b812  MesaGLUT-6.5.3.tar.gz
    +360843e46b7ebb6909290b023f9b26fa  MesaGLUT-6.5.3.tar.bz2
    +7686065e5c15a30de08a1610860b6840  MesaGLUT-6.5.3.zip
    +
    + + +

    Shared library numbering

    +

    +Mesa 6.5.3 supports the OpenGL 2.0/2.1 API. However, the (unix) +shared library version is still 1.5 (i.e. libGL.so.1.5.xxxxxx). +Bumping the shared library version to 2.x would cause linking problems +with existing OpenGL applications. Since OpenGL 2.x is backward +compatible with OpenGL 1.x the shared library version number doesn't +have to be incremented (which would indicate an incompatible ABI). +

    +

    +Other OpenGL vendors name their OpenGL 2.x libraries libGL.so.1.0.xxxxx +for the same reason. +

    + + + +

    New features

    +
      +
    • OpenGL 2.0 and 2.1 API support. +
    • Entirely new Shading Language code generator. See the +Shading Language page for more information. +
    • Much faster software execution of vertex, fragment shaders. +
    • New vertex buffer object (vbo) infrastructure +
    • Updated glext.h file (version 39) +
    • Updated glxext.h file (version 19) +
    • GL_MAX_DRAWBUFFERS is now 4 (software rendering) so + "multiple render targets" are really supported. +
    + +

    Bug fixes

    +
      +
    • Fog was errantly applied when a fragment shader was enabled (bug 9346) +
    • glPush/PopClientAttrib didn't handle VBO bindings correctly (bug 9445) +
    • With 32-bit Z buffer, the fragment Z of lines and points was sometimes wrong. +
    • GL_POST_CONVOLUTION_ALPHA_BIAS/SCALE was broken. +
    • 1D convolution state could effect 2D image transfers +
    • Overlapping glCopyPixels with negative Y zoom didn't work (bug 10521) +
    • Fixed a number of framebuffer/renderbuffer reference counting bugs +
    • Fixed a few bugs in software-emulated alpha planes +
    • Assorted minor bug fixes in glCopy/DrawPixels, glPixelZoom, etc. +
    • Assorted DRI driver bug fixes. +
    • Fixed a number of bugs that prevented "depth-peeling" rendering from working. +
    + + +

    Internal code changes

    +
      +
    • Old array_cache module replaced by new vbo module. All geometry +rendering is now cast in the form of vertex buffer objects. +
    • Massive changes to the Shading Language compiler and related state. +
    • Vertex/fragment shaders are compiled into GPU instructions and +programs very similar to GL_ARB_vertex/fragment_program. +
    • Vertex and fragment programs are executed with the same code now. +
    • The SSE-optimized vertex program path has been removed since it didn't +support more than 12 temp registers, didn't support branching/looping, etc. +
    + + +

    To Do (someday) items

    +
      +
    • Switch to freeglut +
    • Fix linux-glide target/driver. +
    • Improved lambda and derivative calculation for frag progs. +
    + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 2.1
    +OSMesa (off-screen)	implements OpenGL 2.1
    +Windows/Win32		implements OpenGL 2.1
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			unsupported
    +Wind River UGL		unsupported
    +DJGPP			unsupported
    +GGI			unsupported
    +BeOS			unsupported
    +Allegro			unsupported
    +D3D			unsupported
    +
    + + + diff --git a/docs/relnotes-6.5.html b/docs/relnotes-6.5.html new file mode 100644 index 0000000..9d1d669 --- /dev/null +++ b/docs/relnotes-6.5.html @@ -0,0 +1,131 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 6.5 Release Notes / March 31, 2006

    + +

    +Mesa 6.5 is a new development release. +

    + + +

    MD5 checksums

    +
    +657be3b92f6dabc78a67ed9cb8d67813  MesaLib-6.5.tar.gz
    +61beda590bfc5b4a12e979d5f2d70d7a  MesaLib-6.5.tar.bz2
    +19d48b872d579d4f91466060804a59ac  MesaLib-6.5.zip
    +694ad3a7007010c7418a9c72d1cba5b7  MesaDemos-6.5.tar.gz
    +ab95b590dcd640726a2d89e62068c66e  MesaDemos-6.5.tar.bz2
    +b792c303fefd87294488e2b7eab976e5  MesaDemos-6.5.zip
    +ac1d585483617db0c91e5c15cb5ec3a3  MesaGLUT-6.5.tar.gz
    +59f0bf2b2ffb67fe23ee479f9b044f31  MesaGLUT-6.5.tar.bz2
    +005decb2136718e22222ac1c4805cd15  MesaGLUT-6.5.zip
    +
    + + + +

    New Features

    +
      +
    • OpenGL Shading language support +
      + This includes the GL_ARB_shader_objects, GL_ARB_shading_language_100, + GL_ARB_vertex_shader and GL_ARB_fragment_shader extensions. Most of + the work was done by Michal Krol. + There's probably a fair number of bugs since this is a pretty large, + complicated body of code. +
      + The OpenGL 2.0 interface to these features will be implemented in a + future version of Mesa, + +
    • GL_EXT_timer_query +
      + Used to measure the time of OpenGL operations at high precision. + Only supported in the software/Xlib driver at this time. + +
    • GL_EXT_packed_depth_stencil +
      + Defines a new GL_DEPTH_STENCIL_EXT pixel format. + +
    • GL_EXT_framebuffer_blit +
      + A simplified glCopyPixels-like feature for copying pixel rectangles. + +
    • GL_ARB_half_float_pixel +
      + Adds a new half-precision floating point format for image transfers, + such as for glDrawPixels, glReadPixels, glTexImage, etc. +
    + +

    Changes

    +
      +
    • removed GL_HP_occlusion_test (use GL_ARB_occlusion_query instead) +
    • removed GL_SGIX/SGIS_pixel_texture extensions +
    +

    Bug fixes

    +
      +
    • fixed glxcontextmodes.c datatype problem (bug 5835) +
    • fixed aix-gcc build/install bugs (bug 5874) +
    • fixed some bugs in texture env program generation +
    • glXCopyContext() didn't handle texture object bindings properly +
    • glXCopyContext() didn't copy all lighting state +
    • fixed FreeBSD config (Pedro Giffuni) +
    • fixed some minor framebuffer object bugs +
    • replaced dprintf() with _glu_printf() in GLU (bug 6244) +
    • fixed a number of thread safety bugs/regressions +
    • fixed a number of GLU tesselator bugs (John Shell, bug 6339) +
    • paletted texturing was broken w/ floating point palettes (K. Schultz) +
    • lots of assorted framebuffer object bug fixes +
    + + +

    Known Issues

    +
      +
    • Rendering to depth textures will not work. Rendering to GL_DEPTH_STENCIL +textures should work. +
    + + +

    Driver Interface Changes

    +
      +
    • Stencil: The Driver.StencilOp/Func/Mask() functions have been replaced by +the two-sided versions: Driver.Stencil*Separate(). +
    • Render-to-texture: The functions for rendering to textures have changed. +
    + + +

    To Do (someday) items

    +
      +
    • Switch to freeglut +
    • Increase MAX_DRAWBUFFERS +
    • Fix linux-glide target/driver. +
    • Fix lambda calculation for frag progs. +
    + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 1.5
    +OSMesa (off-screen)	implements OpenGL 1.5
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			implements OpenGL 1.3
    +Wind River UGL		implements OpenGL 1.3
    +Windows/Win32		implements OpenGL 1.5
    +DJGPP			implements OpenGL 1.5
    +GGI			implements OpenGL 1.3
    +BeOS			implements OpenGL 1.5
    +Allegro			needs updating
    +D3D			needs updating
    +
    + + + diff --git a/docs/relnotes-7.0.1.html b/docs/relnotes-7.0.1.html new file mode 100644 index 0000000..02713ad --- /dev/null +++ b/docs/relnotes-7.0.1.html @@ -0,0 +1,101 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.0.1 Release Notes / August 3, 2007

    + +

    +Mesa 7.0.1 is a stable release with bug fixes since version 7.0. +

    + + +

    MD5 checksums

    +
    +db55141a44b902fcc61d9265b7862c06  MesaLib-7.0.1.tar.gz
    +c056abd763e899114bf745c9eedbf9ad  MesaLib-7.0.1.tar.bz2
    +ecc2637547fae2b38271ae362d013afa  MesaLib-7.0.1.zip
    +b85a4a5be4e829f4a1165e4514b13183  MesaDemos-7.0.1.tar.gz
    +3b66b3268df12ca8a6c4e0c4c457912c  MesaDemos-7.0.1.tar.bz2
    +b1c18006f16e44e80fea66774c59b391  MesaDemos-7.0.1.zip
    +b87a69986839ae43ce12fc8e3dc1ebb4  MesaGLUT-7.0.1.tar.gz
    +25f30d0c1651997b4412366ba0572f7f  MesaGLUT-7.0.1.tar.bz2
    +676ee6682a6ce78a5540554fd975c03e  MesaGLUT-7.0.1.zip
    +
    + + +

    New features

    +
      +
    • Added a bluegene-osmesa build config +
    + +

    Bug fixes

    +
      +
    • Fixed some MingW build issues +
    • Added a few missing OpenGL 2.0 API entrypoints: +
        +
      • glVertexAttrib4bv +
      • glVertexAttrib4iv +
      • glVertexAttrib4ubv +
      • glVertexAttrib4uiv +
      • glVertexAttrib4usv +
      +
    • Fixed glDrawPixels(GL_STENCIL_INDEX) pixel transfer bug 11457 +
    • GLSL bug fix: added vec2(vec4) constructor +
    • GLSL bug fix: .strq and .rgba writemasks didn't always work +
    • Stencil pixel map didn't always work for glDrawPixels (bug 11475) +
    • Fixed polygon stipple bug in i915 driver +
    • Binding a zero-sized texture didn't disable texturing (bug 11309) +
    • Queries of GL_INFO_LOG_LENGTH, GL_SHADER_SOURCE_LENGTH didn't include +the terminating zero (bug 11588) +
    • glXChooseFBConfig() in Xlib driver didn't handle GLX_STEREO flag properly +
    • Fixed a GLSL function call bug (#11731) +
    • glPointParameteriv(GL_DISTANCE_ATTENUATION_EXT) didn't work (bug 11754) +
    • glGetAttribLocation() always returned 1 (bug 11774) +
    • Fixed a few memory-related bugs in GLU library +
    + + +

    Changes

    +
      +
    • The libOSMesa library version has been reverted to 6.5.3 (soname=6) +in order to avoid application linking issues. Otherwise, applications +previously linked with libOSMesa.so.6 would no longer link with libOSMesa.so.7 +
    • Dropped obsolete, unmaintained Windows project files for VC6 and VC7. +
    + + +

    To Do (someday) items

    +
      +
    • Switch to freeglut +
    • Fix linux-glide target/driver. +
    • Improved lambda and derivative calculation for frag progs. +
    + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 2.1
    +OSMesa (off-screen)	implements OpenGL 2.1
    +Windows/Win32		implements OpenGL 2.1
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			unsupported
    +Wind River UGL		unsupported
    +DJGPP			unsupported
    +GGI			unsupported
    +BeOS			unsupported
    +Allegro			unsupported
    +D3D			unsupported
    +
    + + + diff --git a/docs/relnotes-7.0.2.html b/docs/relnotes-7.0.2.html new file mode 100644 index 0000000..7a7c70f --- /dev/null +++ b/docs/relnotes-7.0.2.html @@ -0,0 +1,88 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.0.2 Release Notes / November 10, 2007

    + +

    +Mesa 7.0.2 is a stable release with bug fixes since version 7.0. +

    + + +

    MD5 checksums

    +
    +c9cf607f36e7e50172f5f9c7d552c34e  MesaLib-7.0.2.tar.gz
    +93e6ed7924ff069a4f883b4fce5349dc  MesaLib-7.0.2.tar.bz2
    +10c324c3613f90f059cb8429f700f300  MesaLib-7.0.2.zip
    +aa8b1244a5de1d23e5814bf9b67f1435  MesaDemos-7.0.2.tar.gz
    +11a10410bae7be85cf25bc7119966468  MesaDemos-7.0.2.tar.bz2
    +1dd0b5fd6d69430a2fd76a6adbfd8fff  MesaDemos-7.0.2.zip
    +a7dbf25c025955858bd2d89a6eb6db4c  MesaGLUT-7.0.2.tar.gz
    +3a33f8efc8c58a592a854cfc7a643286  MesaGLUT-7.0.2.tar.bz2
    +eba4ef2aa8c362ead81b54357f1903a3  MesaGLUT-7.0.2.zip
    +
    + + +

    New features

    +
      +
    • Updated Windows VC7 project files +
    • Added DESTDIR variable for 'make install' +
    • Added pkg-config files for gl, glu, glut and glw libraries +
    • Added bluegene-xlc-osmesa and catamount-osmesa-pgi configs +
    • Support for Intel G33/Q33/Q35 graphics chipsets +
    + +

    Bug fixes

    +
      +
    • Fixed a vertex buffer wrapping issue (bug 9962) +
    • Added mutex protection around texture object reference counters +
    • Added checking/support for additional chips in the i915/i945 family +(see 11978) +
    • Fixed a blending/banding issue (bug 11931) +
    • Fixed a GLU matrix inversion bug (#6748) +
    • Fixed problem with large glDrawArrays calls and indirect rendering (bug 12141) +
    • Fixed an assortment of i965 driver bugs +
    • Fixed x86-64 vertex transformation bug (12216) +
    • Fixed X server crash caused by multiple indirect rendering clients +
    • Parsing of state.texgen in ARB vertex/fragment programs didn't work (bug 12313) +
    • Fixed a glCopyPixels/glPixelZoom bug (12417) +
    • Fixed a bug when using glMaterial in display lists (bug 10604) +
    • Fixed a few GLUT/Fortran issues (Bill Mitchell) +
    • Fixed Blender crash bug (12164) +
    • Fixed some issues preventing cross-compiling +
    • Fixed up broken GL_ATI_separate_stencil extension +
    • glDrawArrays(count=0) led to a crash +
    • Fix SSE code gen memory leak, possible crash +
    • Fixed MMX 565 rgb conversion problem (bug 12614) +
    • Added -fno-strict-aliasing and -fPIC flags for gcc +
    • Fixed Blender crash in Unichrome driver (bug 13142) +
    + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 2.1
    +OSMesa (off-screen)	implements OpenGL 2.1
    +Windows/Win32		implements OpenGL 2.1
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			unsupported
    +Wind River UGL		unsupported
    +DJGPP			unsupported
    +GGI			unsupported
    +BeOS			unsupported
    +Allegro			unsupported
    +D3D			unsupported
    +
    + + + diff --git a/docs/relnotes-7.0.3.html b/docs/relnotes-7.0.3.html new file mode 100644 index 0000000..5c8efc7 --- /dev/null +++ b/docs/relnotes-7.0.3.html @@ -0,0 +1,84 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.0.3 Release Notes / April 4, 2008

    + +

    +Mesa 7.0.3 is a stable release with bug fixes since version 7.0.2. +

    + + +

    MD5 checksums

    +
    +3fd1cb76531b2515ef7db92d9a93dbf8  MesaLib-7.0.3.tar.gz
    +e6e6379d7793af40a6bc3ce1bace572e  MesaLib-7.0.3.tar.bz2
    +97882bac195229ee0b78cab82e0e3be1  MesaLib-7.0.3.zip
    +8abf6bbcb1661e7dd4ce73b3fbb85898  MesaDemos-7.0.3.tar.gz
    +47fd6863621d3c9c7dbb870ab7f0c303  MesaDemos-7.0.3.tar.bz2
    +99e442e14da1928f76a7297bb421a3af  MesaDemos-7.0.3.zip
    +2b50fe9fadc4709b57c52adef09fce3c  MesaGLUT-7.0.3.tar.gz
    +0ff23c4e91b238abae63a5fc9fa003e7  MesaGLUT-7.0.3.tar.bz2
    +70e83554a4462dad28e0d6e20f79aada  MesaGLUT-7.0.3.zip
    +
    + + +

    Bug fixes

    +
      +
    • Added missing glw.pc.in file to release tarball +
    • Fix GLUT/Fortran issues +
    • GLSL gl_FrontLightModelProduct.sceneColor variable wasn't defined +
    • Fix crash upon GLSL variable array indexes (not yet supported) +
    • Two-sided stencil test didn't work in software rendering +
    • Fix two-sided lighting bugs/crashes (bug 13368) +
    • GLSL gl_FrontFacing didn't work properly +
    • glGetActiveUniform returned incorrect sizes (bug 13751) +
    • Fix several bugs relating to uniforms and attributes in GLSL API (Bruce Merry, bug 13753) +
    • glTexImage3D(GL_PROXY_TEXTURE_3D) mis-set teximage depth field +
    • Fixed GLX indirect vertex array rendering bug (14197) +
    • Fixed crash when deleting framebuffer objects (bugs 13507, 14293) +
    • User-defined clip planes enabled for R300 (bug 9871) +
    • Fixed glBindTexture() crash upon bad target (bug 14514) +
    • Fixed potential crash in glDrawPixels(GL_DEPTH_COMPONENT) (bug 13915) +
    • Bad strings given to glProgramStringARB() didn't generate GL_INVALID_OPERATION +
    • Fixed minor point rasterization regression (bug 11016) +
    • state.texenv.color state var didn't work in GL_ARB_fragment_program (bug 14931) +
    • glBitmap from a PBO didn't always work +
    • glGetTexImage into a PBO didn't always work +
    • Comments at the end of ARB vertex/fragment programs crashed the parser +
    + +

    Changes

    +
      +
    • Updated glext.h to version 40 +
    + + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 2.1
    +OSMesa (off-screen)	implements OpenGL 2.1
    +Windows/Win32		implements OpenGL 2.1
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			unsupported
    +Wind River UGL		unsupported
    +DJGPP			unsupported
    +GGI			unsupported
    +BeOS			unsupported
    +Allegro			unsupported
    +D3D			unsupported
    +
    + + + diff --git a/docs/relnotes-7.0.4.html b/docs/relnotes-7.0.4.html new file mode 100644 index 0000000..f100d99 --- /dev/null +++ b/docs/relnotes-7.0.4.html @@ -0,0 +1,80 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.0.4 Release Notes / August 16, 2008

    + +

    +Mesa 7.0.4 is a stable release with bug fixes since version 7.0.3. +

    + + +

    MD5 checksums

    +
    +909afa3a01ae31478d363837681415ac  MesaLib-7.0.4.tar.gz
    +8d7bacbe0234742a5d08c8088c4619e9  MesaLib-7.0.4.tar.bz2
    +5e44261ef85b049a868e1785d9adc276  MesaLib-7.0.4.zip
    +53dcd77d37a819feaf50b5fcdd0a6e0f  MesaDemos-7.0.4.tar.gz
    +c1215b31c5f7b85f81eed3bfba07d556  MesaDemos-7.0.4.tar.bz2
    +b1825a7361f116b28d82d328077630b4  MesaDemos-7.0.4.zip
    +d7677d015f52602d1bf8b837fb717848  MesaGLUT-7.0.4.tar.gz
    +f5f8b46f7e763d9f7b7d1d115c1c44ee  MesaGLUT-7.0.4.tar.bz2
    +a786775271a02c62a3370b13b26bf48d  MesaGLUT-7.0.4.zip
    +
    + + +

    Bug fixes

    +
      +
    • define #extension GL_ARB_texture_rectangle in shading language +
    • fixed WIN32 compile problem in libGLU +
    • Fixed a per-vertex glMaterial bug which could cause bad lighting +
    • Fixed potential crash in AA/smoothed triangle rendering when using a fragment shader +
    • Fixed glDrawElement + VBO segfault (bug 16156) +
    • Fixed GLSL linker bug causing generic vertex attributes to get aliased +
    • Fixed stack overflow when using glPixelZoom on Windows +
    • Fixed broken all(bvec2) GLSL function, added misc missing bvec constructors +
    • ARB program "state.clip[n].plane" didn't parse correctly +
    • Fixed broken glGetUniformiv() (bug 13774) +
    + +

    Changes

    +
      +
    • Including the latest glext.h and glxext.h header files from Khronos +
    • Added support for DragonFly OS +
    • Added a build config for FreeBSD static libs (Anatolij Shkodin) +
    • Enabled GL_EXT_multi_draw_arrays extension in R200/R300 drivers +
    • Enabled GL_ARB_point_sprite extension in I965 driver +
    • Enabled GL_EXT_texture_sRGB extension in I965 driver +
    • Added support for GL shading language in I965 driver +
    + + + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 2.1
    +OSMesa (off-screen)	implements OpenGL 2.1
    +Windows/Win32		implements OpenGL 2.1
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			unsupported
    +Wind River UGL		unsupported
    +DJGPP			unsupported
    +GGI			unsupported
    +BeOS			unsupported
    +Allegro			unsupported
    +D3D			unsupported
    +
    + + + diff --git a/docs/relnotes-7.0.html b/docs/relnotes-7.0.html new file mode 100644 index 0000000..2c036b2 --- /dev/null +++ b/docs/relnotes-7.0.html @@ -0,0 +1,93 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.0 Release Notes / June 22, 2007

    + +

    +Mesa 7.0 is a stable release, featuring OpenGL 2.1 API support. +A number of bugs have been fixed since the 6.5.3 release. +

    + + +

    MD5 checksums

    +
    +35a1698986f7ac8dc435624ee9256cda  MesaLib-7.0.tar.gz
    +50c371455fa7532c04aa0a970f9bc51f  MesaLib-7.0.tar.bz2
    +bcedb6f43c97c1bc49e5cc7f12835722  MesaLib-7.0.zip
    +9bad332c7b74f59be96556135212ca9e  MesaDemos-7.0.tar.gz
    +fada2bc1f29da513e015fda1e3abd0c0  MesaDemos-7.0.tar.bz2
    +84e3bbe470d983ae32f1f0c779faf99e  MesaDemos-7.0.zip
    +76c7bb54f9850c689eba844f6daed332  MesaGLUT-7.0.tar.gz
    +4af28296e02772ef1de00e4e79bf3d12  MesaGLUT-7.0.tar.bz2
    +9043cb0b54cc03d1874728d74b12188c  MesaGLUT-7.0.zip
    +
    + + +

    New features

    +
      +
    • OpenGL 2.0 and 2.1 API support. +
    + +

    Bug fixes

    +
      +
    • Fixed a few fog-related bugs. +
    • Fixed broken GLSL mix() function. +
    • Fixed broken GLSL exp() functions. +
    • Fixed GLSL mod4(vec4, vec4) bug. +
    • Implemented GLSL asin(), acos(), atan() functions. +
    • Fixed an R300 driver bug that caused Xorg composite manager to crash +
    • Fixed R300 vertex program/matrix bug (10848) +
    • GLSL dFdx() and dFdy() work for fragment program inputs now (texcoords) +
    • Specifying an invalid texture unit as a sampler could lead to a crash +
    • The GLX protocol request for glXDestroyPBuffer() was incorrect (bug 10983) +
    • ARB vp state.light[n].half value was incorrect (bug 10987) +
    • Fixed a positional light source bug (bug 11009) +
    • Fixed point size attenuation problem (bug 11042) +
    • glPopAttrib didn't restore texture object's LOD bias (bug 11049) +
    • Fixed a TLS / TEXTREL problem (bug 7459) +
    + + +

    Internal code changes

    +
      +
    • Some texture code consolidation and simplifiction (Ian Romanick) +
    • R300 driver clean-ups. +
    + + +

    To Do (someday) items

    +
      +
    • Switch to freeglut +
    • Fix linux-glide target/driver. +
    • Improved lambda and derivative calculation for frag progs. +
    + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 2.1
    +OSMesa (off-screen)	implements OpenGL 2.1
    +Windows/Win32		implements OpenGL 2.1
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			unsupported
    +Wind River UGL		unsupported
    +DJGPP			unsupported
    +GGI			unsupported
    +BeOS			unsupported
    +Allegro			unsupported
    +D3D			unsupported
    +
    + + + diff --git a/docs/relnotes-7.1.html b/docs/relnotes-7.1.html new file mode 100644 index 0000000..e8a39c8 --- /dev/null +++ b/docs/relnotes-7.1.html @@ -0,0 +1,94 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.1 Release Notes / August 26, 2008

    + +

    +Mesa 7.1 is a new development release. +There have been many internal code changes since Mesa 7.0.x. +It should be relatively stable, but those who are especially concerned about +stability should wait for Mesa 7.2 or use Mesa 7.0.4 (the previous stable +release). +

    + +Note that this version of Mesa does not use the GEM memory manager. +The master branch of git uses GEM. +

    +

    +DRM version 2.3.1 should be used with Mesa 7.1 +

    + + +

    MD5 checksums

    +
    +971c2fe6e6949dc5ba200a6f97a6dc81  MesaLib-7.1.tar.gz
    +6bff7f532d16f90f944a400c8bd7074d  MesaLib-7.1.tar.bz2
    +d48224bf9d54c3da6776adb4869ba024  MesaLib-7.1.zip
    +3de268420efca43e9a19ab506cdfc993  MesaDemos-7.1.tar.gz
    +abfc9775e1462363af8ec160d1feb01f  MesaDemos-7.1.tar.bz2
    +f7b3623387c4036e9895cd9ac0dfad99  MesaDemos-7.1.zip
    +fdf348f78cd09304b6ff801ef8acc8eb  MesaGLUT-7.1.tar.gz
    +f6d88a4eeb02e98c7e92f1c895d3c76b  MesaGLUT-7.1.tar.bz2
    +4dc102a5ca51e1c41dde87d3f8c7b22a  MesaGLUT-7.1.zip
    +
    + + +

    New features

    +
      +
    • autoconf-based configuration (and clean-up of Makefiles) +
    • Assorted DRI driver enhancements +
    • Reduced dependencies between X server and Mesa +
    • GL_EXT_texture_from_pixmap extension for Xlib driver +
    • Support for the GL shading language with i965 driver (implemented by Intel) +
    • ATI R500 series support (Radeon X1300–X1950) in r300 DRI driver +
    + + +

    Bug fixes

    +
      +
    • Numerous GLSL fixes +
    • Fixed some error code/detection bugs in the GLSL-related API functions +
    • Lots of DRI driver fixes. +
    + + +

    To Do (someday) items

    +
      +
    • Remove the MEMCPY() and _mesa_memcpy() wrappers and just use memcpy(). +Probably do the same for malloc, calloc, etc. +The wrappers were useful in the past for memory debugging but now we +have valgrind. Not worried about SunOS 4 support anymore either... +
    • Switch to freeglut +
    • Fix linux-glide target/driver. +
    • Improved lambda and derivative calculation for frag progs. +
    + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 2.1
    +OSMesa (off-screen)	implements OpenGL 2.1
    +Windows/Win32		implements OpenGL 2.1
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			unsupported
    +Wind River UGL		unsupported
    +DJGPP			unsupported
    +GGI			unsupported
    +BeOS			unsupported
    +Allegro			unsupported
    +D3D			unsupported
    +
    + + + diff --git a/docs/relnotes-7.10.1.html b/docs/relnotes-7.10.1.html new file mode 100644 index 0000000..ba6e537 --- /dev/null +++ b/docs/relnotes-7.10.1.html @@ -0,0 +1,380 @@ + + + +Mesa Release Notes + + + + + + + + +

    Mesa 7.10.1 Release Notes / March 2, 2011

    + +

    +Mesa 7.10.1 is a bug fix release which fixes bugs found since the 7.10 release. +

    +

    +Mesa 7.10.1 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +4b4cee19f3bf16eb78bd4cc278ccf812  MesaLib-7.10.1.tar.gz
    +efe8da4d80c2a5d32a800770b8ce5dfa  MesaLib-7.10.1.tar.bz2
    +0fd2b1a025934de3f8cecf9fb9b57f4c  MesaLib-7.10.1.zip
    +42beb0f5188d544476c19496f725fa67  MesaGLUT-7.10.1.tar.gz
    +637bb8a20fdad89f7382b4ea83f896e3  MesaGLUT-7.10.1.tar.bz2
    +bdbf3ffb2606d6aa8afabb6c6243b91b  MesaGLUT-7.10.1.zip
    +
    + + +

    New features

    +

    None.

    + +

    Bug fixes

    +

    This list is likely incomplete.

    +
      +
    • Fix an off-by-one bug in a vsplit assertion.
    • +
    • Fix incorrect handling of layout qualifier +with in, out, attribute, and varying.
    • + +
    • Fix an i965 shader bug where the negative absolute value was generated instead of the absolute value of a negation.
    • + +
    • Fix numerous issues handling precision qualifiers in GLSL ES.
    • + +
    • Fixed a few GLX protocol encoder bugs (Julien Cristau)
    • + +
    • Assorted Gallium llvmpipe driver bug fixes
    • + +
    • Assorted Mesa/Gallium state tracker bug fixes
    • + +
    • Bug 26795 - gl_FragCoord off by one in Gallium drivers.
    • + +
    • Bug 29164 - [GLSL 1.20] invariant variable shouldn't be used before declaration
    • + +
    • Bug 29823 - GetUniform[if]v busted
    • + +
    • Bug 29927 - [glsl2] fail to compile shader with constructor for array of struct type
    • + +
    • Bug 30156 - [i965] After updating to Mesa 7.9, Civilization IV starts to show garbage
    • + +
    • Bug 31923 - [GLSL 1.20] allowing inconsistent centroid declaration between two vertex shaders
    • + +
    • Bug 31925 - [GLSL 1.20] "#pragma STDGL invariant(all)" fail
    • + +
    • Bug 32214 - [gles2]no link error happens when missing vertex shader or frag shader
    • + +
    • Bug 32375 - [gl gles2] Not able to get the attribute by function glGetVertexAttribfv
    • + +
    • Bug 32541 - Segmentation Fault while running an HDR (high dynamic range) rendering demo
    • + +
    • Bug 32569 - [gles2] glGetShaderPrecisionFormat not implemented yet
    • + +
    • Bug 32695 - [glsl] SIGSEGV glcpp/glcpp-parse.y:833
    • + +
    • Bug 32831 - [glsl] division by zero crashes GLSL compiler
    • + +
    • Bug 32910 - Keywords 'in' and 'out' not handled properly for GLSL 1.20 shaders
    • + +
    • Bug 33219 -[GLSL bisected] implicit sized array triggers segfault in ir_to_mesa_visitor::copy_propagate
    • + +
    • Bug 33306 - GLSL integer division by zero crashes GLSL compiler
    • + +
    • Bug 33308 -[glsl] ast_to_hir.cpp:3016: virtual ir_rvalue* ast_jump_statement::hir(exec_list*, _mesa_glsl_parse_state*): Assertion `ret != __null' failed.
    • + +
    • Bug 33316 - uniform array will be allocate one line more and initialize it when it was freed will abort
    • + +
    • Bug 33386 - Dubious assembler in read_rgba_span_x86.S
    • + +
    • Bug 33388 - Dubious assembler in xform4.S
    • + +
    • Bug 33433 - Error in x86-64 API dispatch code.
    • + +
    • Bug 33507 - [glsl] GLSL preprocessor modulus by zero crash
    • + +
    • Bug 33508 - [glsl] GLSL compiler modulus by zero crash
    • + +
    • Bug 33916 - Compiler accepts reserved operators % and %=
    • + +
    • Bug 34030 - [bisected] Starcraft 2: some effects are corrupted or too big
    • + +
    • Bug 34047 - Assert in _tnl_import_array() when using GLfixed vertex datatypes with GLESv2
    • + +
    • Bug 34114 - Sun Studio build fails due to standard library functions not being in global namespace
    • + +
    • Bug 34179 - Nouveau 3D driver: nv50_pc_emit.c:863 assertion error kills Compiz
    • + +
    • Bug 34198 - [GLSL] implicit sized array with index 0 used gets assertion
    • + +
    • Ubuntu bug 691653 - compiz crashes when using alt-tab (the radeon driver kills it)
    • + +
    • Meego bug 13005 - Graphics GLSL issue lead to camera preview fail on Pinetrail
    • + + + +
    + + +

    Changes

    +

    The full set of changes can be viewed by using the following GIT command:

    + +
    +  git log mesa-7.10..mesa-7.10.1
    +
    + +

    Alberto Milone (1): +

      +
    • r600c: add evergreen ARL support.
    • +

    + +

    Brian Paul (21): +

      +
    • draw: Fix an off-by-one bug in a vsplit assertion.
    • +
    • docs: add links to 7.9.1 and 7.10 release notes
    • +
    • docs: added news item for 7.9.1 and 7.10 release
    • +
    • gallivm: work around LLVM 2.6 bug when calling C functions
    • +
    • gallivm: fix copy&paste error from previous commit
    • +
    • mesa: fix a few format table mistakes, assertions
    • +
    • mesa: fix num_draw_buffers==0 in fixed-function fragment program generation
    • +
    • mesa: don't assert in GetIntegerIndexed, etc
    • +
    • mesa: check for dummy renderbuffer in _mesa_FramebufferRenderbufferEXT()
    • +
    • llvmpipe: make sure binning is active when we begin/end a query
    • +
    • st/mesa: fix incorrect fragcoord.x translation
    • +
    • softpipe: fix off-by-one error in setup_fragcoord_coeff()
    • +
    • cso: fix loop bound in cso_set_vertex_samplers()
    • +
    • st/mesa: fix incorrect glCopyPixels position on fallback path
    • +
    • st/mesa: set renderbuffer _BaseFormat in a few places
    • +
    • st/mesa: fix the default case in st_format_datatype()
    • +
    • st/mesa: need to translate clear color according to surface's base format
    • +
    • docs: update 7.9.2 release notes with Brian's cherry-picks
    • +
    • docs: add link to 7.10.1 release notes
    • +
    • mesa: implement glGetShaderPrecisionFormat()
    • +
    • docs: updated environment variable list
    • +

    + +

    Bryce Harrington (1): +

      +
    • r300g: Null pointer check for buffer deref in gallium winsys
    • +

    + +

    Chad Versace (20): +

      +
    • glsl: At link-time, check that globals have matching centroid qualifiers
    • +
    • glcpp: Fix segfault when validating macro redefinitions
    • +
    • glsl: Fix parser rule for type_specifier
    • +
    • glsl: Change default value of ast_type_specifier::precision
    • +
    • glsl: Add semantic checks for precision qualifiers
    • +
    • glsl: Add support for default precision statements
    • +
    • glsl: Remove redundant semantic check in parser
    • +
    • glsl: Fix semantic checks on precision qualifiers
    • +
    • glsl: Fix segfault due to missing printf argument
    • +
    • glsl: Mark 'in' variables at global scope as read-only
    • +
    • mesa: Refactor handling of extension strings
    • +
    • mesa: Add/remove extensions in extension string
    • +
    • mesa: Change dependencies of some OES extension strings
    • +
    • mesa: Change OES_point_sprite to depend on ARB_point_sprite
    • +
    • mesa: Change OES_standard_derivatives to be stand-alone extension
    • +
    • i915: Disable extension OES_standard_derivatives
    • +
    • glcpp: Raise error when modulus is zero
    • +
    • glsl: Set operators '%' and '%=' to be reserved when GLSL < 1.30
    • +
    • glsl: Reinstate constant-folding for division by zero
    • +
    • tnl: Add support for datatype GL_FIXED in vertex arrays
    • +

    + +

    Chia-I Wu (1): +

      +
    • mesa: Add glDepthRangef and glClearDepthf to APIspec.xml.
    • +

    + +

    Christoph Bumiller (1): +

      +
    • nv50,nvc0: do not forget to apply sign mode to saved TGSI inputs
    • +

    + +

    Cyril Brulebois (1): +

      +
    • Point to bugs.freedesktop.org rather than bugzilla.freedesktop.org
    • +

    + +

    Dave Airlie (3): +

      +
    • radeon/r200: fix fbo-clearmipmap + gen-teximage
    • +
    • radeon: calculate complete texture state inside TFP function
    • +
    • radeon: avoid segfault on 3D textures.
    • +

    + +

    Dimitry Andric (4): +

      +
    • mesa: s/movzx/movzbl/
    • +
    • mesa: s/movzxw/movzwl/ in read_rgba_span_x86.S
    • +
    • glapi: adding @ char before type specifier in glapi_x86.S
    • +
    • glapi: add @GOTPCREL relocation type
    • +

    + +

    Eric Anholt (16): +

      +
    • glsl: Fix the lowering of variable array indexing to not lose write_masks.
    • +
    • i965/fs: When producing ir_unop_abs of an operand, strip negate.
    • +
    • i965/vs: When MOVing to produce ABS, strip negate of the operand.
    • +
    • i965/fs: Do flat shading when appropriate.
    • +
    • i965: Avoid double-negation of immediate values in the VS.
    • +
    • intel: Make renderbuffer tiling choice match texture tiling choice.
    • +
    • i965: Fix dead pointers to fp->Parameters->ParameterValues[] after realloc.
    • +
    • docs: Add a relnote for the Civ IV on i965.
    • +
    • glapi: Add entrypoints and enums for GL_ARB_ES2_compatibility.
    • +
    • mesa: Add extension enable bit for GL_ARB_ES2_compatibility.
    • +
    • mesa: Add actual support for glReleaseShaderCompiler from ES2.
    • +
    • mesa: Add support for glDepthRangef and glClearDepthf.
    • +
    • mesa: Add getters for ARB_ES2_compatibility MAX_*_VECTORS.
    • +
    • mesa: Add getter for GL_SHADER_COMPILER with ARB_ES2_compatibility.
    • +
    • i965: Fix a bug in i965 compute-to-MRF.
    • +
    • i965/fs: Add a helper function for detecting math opcodes.
    • +

    + +

    Fredrik Höglund (1): +

      +
    • st/mesa: fix a regression from cae2bb76
    • +

    + +

    Ian Romanick (42): +

      +
    • docs: Add 7.10 md5sums
    • +
    • glsl: Support the 'invariant(all)' pragma
    • +
    • glcpp: Generate an error for division by zero
    • +
    • glsl: Add version_string containing properly formatted GLSL version
    • +
    • glsl & glcpp: Refresh autogenerated lexer and parser files.
    • +
    • glsl: Disallow 'in' and 'out' on globals in GLSL 1.20
    • +
    • glsl: Track variable usage, use that to enforce semantics
    • +
    • glsl: Allow 'in' and 'out' when 'layout' is also available
    • +
    • docs: Initial bits of 7.10.1 release notes
    • +
    • mesa: bump version to 7.10.1-devel
    • +
    • doc: Update 7.10.1 release notes
    • +
    • glsl: Emit errors or warnings when 'layout' is used with 'attribute' or 'varying'
    • +
    • docs: Update 7.10.1 release notes
    • +
    • glsl: Refresh autogenerated lexer and parser files.
    • +
    • glsl: Don't assert when the value returned by a function has no rvalue
    • +
    • linker: Set sizes for non-global arrays as well
    • +
    • linker: Propagate max_array_access while linking functions
    • +
    • docs: Update 7.10.1 release notes
    • +
    • mesa: glGetUniform only returns a single element of an array
    • +
    • linker: Generate link errors when ES shaders are missing stages
    • +
    • mesa: Fix error checks in GetVertexAttrib functions
    • +
    • Use C-style system headers in C++ code to avoid issues with std:: namespace
    • +
    • docs: Update 7.10.1 release notes
    • +
    • glapi: Regenerate for GL_ARB_ES2_compatibility.
    • +
    • mesa: Connect glGetShaderPrecisionFormat into the dispatch table
    • +
    • i965: Set correct values for range/precision of fragment shader types
    • +
    • i915: Set correct values for range/precision of fragment shader types
    • +
    • intel: Fix typeos from 3d028024 and 790ff232
    • +
    • glsl: Ensure that all GLSL versions are supported in the stand-alone compiler
    • +
    • glsl: Reject shader versions not supported by the implementation
    • +
    • mesa: Initial size for secondary color array is 3
    • +
    • glsl: Finish out the reduce/reduce error fixes
    • +
    • glsl: Regenerate compiler and glcpp files from cherry picks
    • +
    • linker: Fix off-by-one error implicit array sizing
    • +
    • docs: update 7.10.1 release notes with Ian's recent cherry picks
    • +
    • i915: Only mark a register as available if all components are written
    • +
    • i915: Calculate partial result to temp register first
    • +
    • i915: Force lowering of all types of indirect array accesses in the FS
    • +
    • docs: Update 7.10.1 with (hopefully) the last of the cherry picks
    • +
    • docs: Clean up bug fixes list
    • +
    • intel: Remove driver date and related bits from renderer string
    • +
    • mesa: set version string to 7.10.1 (final)
    • +

    + +

    Jian Zhao (1): +

      +
    • mesa: fix an error in uniform arrays in row calculating.
    • +

    + +

    Julien Cristau (3): +

      +
    • glx: fix request lengths
    • +
    • glx: fix GLXChangeDrawableAttributesSGIX request
    • +
    • glx: fix length of GLXGetFBConfigsSGIX
    • +

    + +

    Keith Packard (1): +

      +
    • glsl: Eliminate reduce/reduce conflicts in glsl grammar
    • +

    + +

    Kenneth Graunke (20): +

      +
    • glsl: Expose a public glsl_type::void_type const pointer.
    • +
    • glsl: Don't bother unsetting a destructor that was never set.
    • +
    • glsl, i965: Remove unnecessary talloc includes.
    • +
    • glcpp: Remove use of talloc reference counting.
    • +
    • ralloc: Add a fake implementation of ralloc based on talloc.
    • +
    • Convert everything from the talloc API to the ralloc API.
    • +
    • ralloc: a new MIT-licensed recursive memory allocator.
    • +
    • Remove talloc from the make and automake build systems.
    • +
    • Remove talloc from the SCons build system.
    • +
    • Remove the talloc sources from the Mesa repository.
    • +
    • glsl: Fix use of uninitialized values in _mesa_glsl_parse_state ctor.
    • +
    • i965/fs: Apply source modifier workarounds to POW as well.
    • +
    • i965: Fix shaders that write to gl_PointSize on Sandybridge.
    • +
    • i965/fs: Avoid register coalescing away gen6 MATH workarounds.
    • +
    • i965/fs: Correctly set up gl_FragCoord.w on Sandybridge.
    • +
    • i965: Increase Sandybridge point size clamp.
    • +
    • i965/fs: Refactor control flow stack handling.
    • +
    • i965: Increase Sandybridge point size clamp in the clip state.
    • +
    • glsl: Use reralloc instead of plain realloc.
    • +
    • Revert "i965/fs: Correctly set up gl_FragCoord.w on Sandybridge."
    • +

    + +

    Marek Olšák (4): +

      +
    • docs: fix messed up names with special characters in relnotes-7.10
    • +
    • docs: fix messed up names with special characters in relnotes-7.9.1
    • +
    • mesa: fix texture3D mipmap generation for UNSIGNED_BYTE_3_3_2
    • +
    • st/dri: Track drawable context bindings
    • +

    + +

    Paulo Zanoni (1): +

      +
    • dri_util: fail driCreateNewScreen if InitScreen is NULL
    • +

    + +

    Sam Hocevar (2): +

      +
    • docs: add glsl info
    • +
    • docs: fix glsl_compiler name
    • +

    + +

    Tom Fogal (1): +

      +
    • Regenerate gl_mangle.h.
    • +

    + +

    Tom Stellard (2): +

      +
    • r300/compiler: Disable register rename pass on r500
    • +
    • r300/compiler: Don't erase sources when converting RGB->Alpha
    • +

    + +

    Vinson Lee (3): +

      +
    • ralloc: Add missing va_end following va_copy.
    • +
    • mesa: Move declaration before code in extensions.c.
    • +
    • mesa: Move loop variable declarations outside for loop in extensions.c.
    • +

    + +

    nobled (1): +

      +
    • glx: Put null check before use
    • +

    + +

    + + + diff --git a/docs/relnotes-7.10.2.html b/docs/relnotes-7.10.2.html new file mode 100644 index 0000000..0e2eb0d --- /dev/null +++ b/docs/relnotes-7.10.2.html @@ -0,0 +1,201 @@ + + + +Mesa Release Notes + + + + + + + + +

    Mesa 7.10.2 Release Notes / TBD

    + +

    +Mesa 7.10.2 is a bug fix release which fixes bugs found since the 7.10 release. +

    +

    +Mesa 7.10.2 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +TBD
    +
    + + +

    New features

    +

    None.

    + +

    Bug fixes

    +

    This list is likely incomplete.

    +
      + +
    • Bug 29172 - Arrandale - Pill Popper Pops Pills
    • + +
    • Bug 31159 - shadow problem in 0ad game
    • + +
    • Bug 32688 - [RADEON:KMS:R300G] some games have a wireframe or outline visible
    • + +
    • Bug 32949 - [glsl wine] Need for Speed renders incorrectly with GLSL enabled
    • + +
    • Bug 34203 - [GLSL] fail to call long chains across shaders
    • + +
    • Bug 34376 - [GLSL] allowing assignment to unsized array +
        +
      • The commit message incorrectly + lists bug + 34367.
      • +
      +
    • + +
    • Bug 34370 - [GLSL] "i<5 && i<4" in for loop fails
    • + +
    • Bug 34374 - [GLSL] fail to redeclare an array using initializer
    • + +
    • Bug 35073 - [GM45] Alpha test is broken when rendering to FBO with no color attachment
    • + +
    • Bug 35483 - util_blit_pixels_writemask: crash in line 322 of src/gallium/auxiliary/util/u_blit.c
    • + + + +
    + + +

    Changes

    +

    The full set of changes can be viewed by using the following GIT command:

    + +
    +  git log mesa-7.10.1..mesa-7.10.2
    +
    + +

    Note: Reverted commits and the reverts are not included in this list.

    + +

    Alex Deucher (2): +

      +
    • r600c: add new ontario pci ids
    • +
    • r600g: add some additional ontario pci ids
    • +

    + +

    Benjamin Franzke (1): +

      +
    • st/dri: Fix surfaceless gl using contexts with previous bound surfaces
    • +

    + +

    Brian Paul (9): +

      +
    • docs: pull 7.9.2 release notes into 7.10 branch
    • +
    • docs: update news.html with 7.10.1 and 7.9.2 releases
    • +
    • docs: fill in 7.10.1 release data
    • +
    • docs: add, fix release notes links
    • +
    • docs: update info about Mesa packaging/contents
    • +
    • docs: update prerequisites, remove old demo info
    • +
    • mesa: Guard against null pointer deref in fbo validation
    • +
    • st/mesa: Apply LOD bias from correct texture unit
    • +
    • glsl: silence warning in printf() with a cast
    • +

    + +

    Chad Versace (1): +

      +
    • i965: Fix tex_swizzle when depth mode is GL_RED
    • +

    + +

    Dave Airlie (1): +

      +
    • r600: don't close fd on failed load
    • +

    + +

    Eric Anholt (2): +

      +
    • i965: Apply a workaround for the Ironlake "vertex flashing".
    • +
    • i965: Fix alpha testing when there is no color buffer in the FBO.
    • +

    + +

    Fabian Bieler (1): +

      +
    • st/mesa: Apply LOD from texture object
    • +

    + +

    Henri Verbeet (1): +

      +
    • st/mesa: Validate state before doing blits.
    • +

    + +

    Ian Romanick (13): +

      +
    • docs: Add 7.10.1 md5sums
    • +
    • glsl: Refactor AST-to-HIR code handling variable initializers
    • +
    • glsl: Refactor AST-to-HIR code handling variable redeclarations
    • +
    • glsl: Process redeclarations before initializers
    • +
    • glsl: Function signatures cannot have NULL return type
    • +
    • glsl: Add several function / call related validations
    • +
    • linker: Add imported functions to the linked IR
    • +
    • glsl: Use insert_before for lists instead of open coding it
    • +
    • glsl: Only allow unsized array assignment in an initializer
    • +
    • glcpp: Refresh autogenerated lexer files
    • +
    • docs: Initial bits of 7.10.2 release notes
    • +
    • mesa: set version string to 7.10.2
    • +
    • mesa: Remove nonexistant files from _FILES lists
    • +

    + +

    Jerome Glisse (1): +

      +
    • r600g: move user fence into base radeon structure
    • +

    + +

    José Fonseca (2): +

      +
    • mesa: Fix typo glGet*v(GL_TEXTURE_COORD_ARRAY_*).
    • +
    • mesa: More glGet* fixes.
    • +

    + +

    Kenneth Graunke (4): +

      +
    • glcpp: Rework lexer to use a SKIP state rather than REJECT.
    • +
    • glcpp: Remove trailing contexts from #if rules.
    • +
    • i965/fs: Fix linear gl_Color interpolation on pre-gen6 hardware.
    • +
    • glsl: Accept precision qualifiers on sampler types, but only in ES.
    • +

    + +

    Marek Olšák (15): +

      +
    • st/mesa: fix crash when DrawBuffer->_ColorDrawBuffers[0] is NULL
    • +
    • st/mesa: fail to alloc a renderbuffer if st_choose_renderbuffer_format fails
    • +
    • r300/compiler: fix the saturate modifier when applied to TEX instructions
    • +
    • r300/compiler: fix translating the src negate bits in pair_translate
    • +
    • r300/compiler: Abs doesn't cancel Negate (in the conversion to native swizzles)
    • +
    • r300/compiler: TEX instructions don't support negation on source arguments
    • +
    • r300/compiler: do not set TEX_IGNORE_UNCOVERED on r500
    • +
    • r300/compiler: saturate Z before the shadow comparison
    • +
    • r300/compiler: fix equal and notequal shadow compare functions
    • +
    • r300/compiler: remove unused variables
    • +
    • st/mesa: fix crash when using both user and vbo buffers with the same stride
    • +
    • r300g: fix alpha-test with no colorbuffer
    • +
    • r300g: tell the GLSL compiler to lower the continue opcode
    • +
    • r300/compiler: propagate SaturateMode down to the result of shadow comparison
    • +
    • r300/compiler: apply the texture swizzle to shadow pass and fail values too
    • +

    + +

    Michel Dänzer (1): +

      +
    • Use proper source row stride when getting depth/stencil texels.
    • +

    + +

    Tom Stellard (4): +

      +
    • r300/compiler: Use a 4-bit writemask in pair instructions
    • +
    • prog_optimize: Fix reallocating registers for shaders with loops
    • +
    • r300/compiler: Fix vertex shader MAD instructions with constant swizzles
    • +
    • r300/compiler: Don't try to convert RGB to Alpha in full instructions
    • +

    + + + diff --git a/docs/relnotes-7.10.html b/docs/relnotes-7.10.html new file mode 100644 index 0000000..3f4f229 --- /dev/null +++ b/docs/relnotes-7.10.html @@ -0,0 +1,2795 @@ + + + +Mesa Release Notes + + + + + + + + +

    Mesa 7.10 Release Notes / January 7, 2011

    + +

    +Mesa 7.10 is a new development release. +People who are concerned with stability and reliability should stick +with a previous release or wait for Mesa 7.10.1. +

    +

    +Mesa 7.10 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +0a70c15c135561824bdcae92bf232e43  MesaLib-7.10.tar.gz
    +33fb94eccc02cbb4d8d1365615e38e46  MesaLib-7.10.tar.bz2
    +5cafdc0eda0f9bf370b95c98df3338fa  MesaLib-7.10.zip
    +bc644be551ed585fc4f66c16b64a91c9  MesaGLUT-7.10.tar.gz
    +5c2677a155672352d62b177e4f0f92e8  MesaGLUT-7.10.tar.bz2
    +2ce5001f74496d1ba719ef74d910a5cf  MesaGLUT-7.10.zip
    +
    + + +

    New features

    +
      +
    • GL_ARB_explicit_attrib_location extension (Intel and software drivers). +
    • GL_ARB_texture_rg (Intel, software drivers, gallium drivers). +
    • GL_EXT_separate_shader_objects extension (Intel and software drivers). +
    • GL_NV_primitive_restart extension (Gallium softpipe, llvmpipe). +
    • New fragment shader back-end for i965-class hardware. +
    • Support for Sandybridge chipset in i965 DRI driver. +
    + + +

    Bug fixes

    +

    This list is likely incomplete.

    +
      +
    • Bug 28800 - [r300c, r300g] Texture corruption with World of Warcraft
    • + +
    • Bug 29420 - Amnesia / HPL2 RendererFeatTest - not rendering correctly
    • + +
    • Bug 29946 - [swrast] piglit valgrind glsl-array-bounds-04 fails
    • + +
    • Bug 30261 - [GLSL 1.20] allowing inconsistent invariant declaration between two vertex shaders
    • + +
    • Bug 30632 - [softpipe] state_tracker/st_manager.c:489: st_context_notify_invalid_framebuffer: Assertion `stfb && stfb->iface == stfbi' failed.
    • + +
    • Bug 30694 - wincopy will crash on Gallium drivers when going to front buffer
    • + +
    • Bug 30771 - [r600g] vert-tex glsl demo
    • + +
    • Bug 30787 - Invalid asm shader does not generate draw-time error when used with GLSL shader
    • + +
    • Bug 30974 - [llvmpipe] SIGABRT src/gallium/drivers/llvmpipe/lp_state_fs.c:779
    • + +
    • Bug 30993 - getFramebufferAttachmentParameteriv wrongly generates error
    • + +
    • Bug 31101 - [glsl2] abort() in ir_validate::visit_enter(ir_assignment *ir)
    • + +
    • Bug 31193 - [regression] aa43176e break water reflections
    • + +
    • Bug 31194 - The mesa meta save/restore code doesn't ref the current GLSL program
    • + +
    • Bug 31371 - glslparsertest: ir.cpp:358: ir_constant::ir_constant(const glsl_type*, const ir_constant_data*): Assertion `(type->base_type >= 0) && (type->base_type <= 3)' failed.
    • + +
    • Bug 31439 - Crash in glBufferSubData() with size == 0
    • + +
    • Bug 31495 - [i965 gles2c bisected] OpenGL ES 2.0 conformance GL2Tests_GetBIFD_input.run regressed
    • + +
    • Bug 31514 - isBuffer returns true for unbound buffers
    • + +
    • Bug 31560 - [tdfx] tdfx_tex.c:702: error: ‘const struct gl_color_table’ has no member named ‘Format’
    • + +
    • Bug 31617 - Radeon/Compiz: 'failed to attach dri2 front buffer', error case not handled
    • + +
    • Bug 31648 - [GLSL] array-struct-array gets assertion: `(size >= 1) && (size <= 4)' failed.
    • + +
    • Bug 31650 - [GLSL] varying gl_TexCoord fails to be re-declared to different size in the second shader
    • + +
    • Bug 31673 - GL_FRAGMENT_PRECISION_HIGH preprocessor macro undefined in GLSL ES
    • + +
    • Bug 31690 - i915 shader compiler fails to flatten if in Aquarium webgl demo.
    • + +
    • Bug 31832 - [i915] Bad renderbuffer format: 21
    • + +
    • Bug 31841 - [drm:radeon_cs_ioctl] *ERROR* Invalid command stream !
    • + +
    • Bug 31894 - Writing to gl_PointSize with GLES2 corrupts other varyings
    • + +
    • Bug 31909 - [i965] brw_fs.cpp:1461: void fs_visitor::emit_bool_to_cond_code(ir_rvalue*): Assertion `expr->operands[i]->type->is_scalar()' failed.
    • + +
    • Bug 31934 - [gallium] Mapping empty buffer object causes SIGSEGV
    • + +
    • Bug 31983 - [i915 gles2] "if (expression with builtin/varying variables) discard" breaks linkage
    • + +
    • Bug 31985 - [GLSL 1.20] initialized uniform array considered as "unsized"
    • + +
    • Bug 31987 - [gles2] if input a wrong pname(GL_NONE) to glGetBoolean, it will not case GL_INVALID_ENUM
    • + +
    • Bug 32035 - [GLSL bisected] comparing unsized array gets segfault
    • + +
    • Bug 32070 - llvmpipe renders stencil demo incorrectly
    • + +
    • Bug 32273 - assertion fails when starting vdrift 2010 release with shaders enabled
    • + +
    • Bug 32287 - [bisected GLSL] float-int failure
    • + +
    • Bug 32311 - [965 bisected] Array look-ups broken on GM45
    • + +
    • Bug 32520 - [gles2] glBlendFunc(GL_ZERO, GL_DST_COLOR) will result in GL_INVALID_ENUM
    • + +
    • Bug 32825 - egl_glx driver completely broken in 7.9 branch [fix in master]
    • + +
    • Bug -
    • + +
    • Bug -
    • + +
    + + +

    Changes

    +

    Adam Jackson (2): +

      +
    • i965: Update renderer strings for sandybridge
    • +
    • drivers/x11: unifdef XFree86Server
    • +

    + +

    Alex Deucher (30): +

      +
    • r600c: fix mipmap stride on evergreen
    • +
    • r600c: add reloc for CB_COLOR0_ATTRIB
    • +
    • r600c: pull over 6xx/7xx vertex fixes for evergreen
    • +
    • r600c: fix segfault in evergreen stencil code
    • +
    • r100: revalidate after radeon_update_renderbuffers
    • +
    • r600c: add missing radeon_prepare_render() call on evergreen
    • +
    • r600c: properly align mipmaps to group size
    • +
    • egl_dri2: Add radeon chip ids
    • +
    • r600c/evergreen: texture align is group_bytes just like 6xx/7xx
    • +
    • r600g: fix buffer alignment
    • +
    • r600g: All EVENT_WRITE packets need the EVENT_INDEX field
    • +
    • r600g: translate ARR instruction for evergreen
    • +
    • r600g: use meaningful defines for chiprev
    • +
    • r600g: use full range of VS resources for vertex samplers
    • +
    • r600g: fix additional EVENT_WRITE packet
    • +
    • r600g: fix some winsys functions to deal properly with evergreen
    • +
    • r600c: add Ontario Fusion APU support
    • +
    • r600g: add support for ontario APUs
    • +
    • r600c: fix VC flush on cedar and palm
    • +
    • gallium/egl: fix r300 vs r600 loading
    • +
    • r600c: fix some opcodes on evergreen
    • +
    • r600c: bump texture limits to hw limits
    • +
    • r600g: bump texture/cb limits appropriately for evergreen
    • +
    • radeon: bump mip tree levels to 15
    • +
    • r600g: fix rendering with a vertex attrib having a zero stride
    • +
    • r600g: remove useless switch statements
    • +
    • r600g: add support for NI (northern islands) asics
    • +
    • r600c: add support for NI asics
    • +
    • r600g: support up to 64 shader constants
    • +
    • r600c: fix up SQ setup in blit code for Ontario/NI
    • +

    + +

    Andre Maasikas (3): +

      +
    • r600c: fix buffer height setting in dri2 case
    • +
    • r600g: break alu clause earlier
    • +
    • r600g: fix evergreen interpolation setup
    • +

    + +

    Andrew Randrianasulu (2): +

      +
    • dri/nv04: Don't expose ARB_texture_env_combine/dot3.
    • +
    • dri/nv04: Enable eng3dm for A8/L8 textures.
    • +

    + +

    Aras Pranckevicius (2): +

      +
    • glsl: fix crash in loop analysis when some controls can't be determined
    • +
    • glsl: fix matrix type check in ir_algebraic
    • +

    + +

    Bas Nieuwenhuizen (3): +

      +
    • r600g: set ENABLE_KILL in the shader state in the new design
    • +
    • r600g: set ENABLE_KILL on evergreen too
    • +
    • r600g: use dirty list to track dirty blocks
    • +

    + +

    Ben Skeggs (3): +

      +
    • nv50: DST
    • +
    • nv50: DPH
    • +
    • nv50: silence some unknown get_param warnings
    • +

    + +

    Benjamin Franzke (2): +

      +
    • st/egl image: multiply drm buf-stride with blocksize
    • +
    • r600g: implement texture_get_handle (needed for eglExportDRMImageMESA)
    • +

    + +

    Brian Paul (296): +

      +
    • glx: add const qualifiers to __indirect_glMultiDrawArraysEXT()
    • +
    • glsl2: fix signed/unsigned comparison warning
    • +
    • llvmpipe: cast to silence warning
    • +
    • llvmpipe: s/boolean/unsigned/ in bitfield to silence warning
    • +
    • nv50: use unsigned int for bitfields to silence warnings
    • +
    • tgsi: fix incorrect usage_mask for shadow tex instructions
    • +
    • gallivm: expand AoS sampling to cover all filtering modes
    • +
    • gallivm: fix incorrect vector shuffle datatype
    • +
    • gallivm: move i32_vec_type inside the #ifdef
    • +
    • mesa: include mfeatures.h in formats.c
    • +
    • gallivm: fix wrong return value in bitwise functions
    • +
    • tgsi/sse: fix aos_to_soa() loop to handle num_inputs==0
    • +
    • gallivm: added missing case for PIPE_TEXTURE_RECT
    • +
    • gallium: better docs for pipe_rasterizer_state::sprite_coord_enable
    • +
    • gallium: rework handling of sprite_coord_enable state
    • +
    • gallium/docs: added new pipeline.txt diagram
    • +
    • mesa: don't call valid_texture_object() in non-debug builds
    • +
    • glsl2: silence compiler warnings in printf() calls
    • +
    • docs: remove old broken link
    • +
    • docs: mark as obsolete, remove dead links
    • +
    • llvmpipe: fix query bug when no there's no scene
    • +
    • gallivm: remove debug code
    • +
    • llvmpipe: maintain fragment shader state for draw module
    • +
    • llvmpipe: indentation fix
    • +
    • llvmpipe: reformatting, remove trailing whitespace, etc
    • +
    • llvmpipe: clean-up, comments in setup_point_coefficient()
    • +
    • llvmpipe: rename sprite field, add sprite_coord_origin
    • +
    • llvmpipe: implement sprite coord origin modes
    • +
    • draw: fix test for using the wide-point stage
    • +
    • llvmpipe: check bitshift against PIPE_MAX_SHADER_OUTPUTS
    • +
    • draw: check bitshift against PIPE_MAX_SHADER_OUTPUS
    • +
    • Merge branch 'sprite-coord'
    • +
    • draw: new draw_fs.[ch] files
    • +
    • glsl2: fix typo in error msg
    • +
    • gallivm: fix lp_build_sample_compare()
    • +
    • softpipe: add missing calls to set draw vertex samplers/views
    • +
    • mesa: don't advertise bogus GL_ARB_shading_language_120 extension
    • +
    • configs: remove egl-swrast target from linux-dri config
    • +
    • llvmpipe: fix sprite texcoord setup for non-projective texturing
    • +
    • mesa: fix assertions to handle srgb formats
    • +
    • st/mesa: add missing MESA_FORMAT_S8 case in st_mesa_format_to_pipe_format()
    • +
    • st/mesa: use the wrapped renderbuffer in CopyPixels()
    • +
    • llvmpipe: make min/max lod and lod bias dynamic state
    • +
    • llvmpipe: make texture border_color dynamic state
    • +
    • softpipe: fix repeat() function for NPOT textures
    • +
    • gallivm: fix repeat() function for NPOT textures
    • +
    • swrast: update comments for REMAINDER() macro
    • +
    • softpipe: rename sp_state_fs.c -> sp_state_shader.c
    • +
    • softpipe: make shader-related functions static
    • +
    • softpipe: make blend/stencil/depth functions static
    • +
    • softpipe: make sampler state functions static
    • +
    • softpipe: make vertex state functions static
    • +
    • softpipe: make rasterizer state functions static
    • +
    • softpipe: make stream out state functions static
    • +
    • softpipe: make clip state functions static
    • +
    • softpipe: minor asst. clean-ups
    • +
    • softpipe: allocate tile data on demand
    • +
    • llvmpipe: fix swizzling of texture border color
    • +
    • softpipe: fix swizzling of texture border color
    • +
    • draw: pass sampler state down to llvm jit state
    • +
    • gallivm: check for level=0 case in lp_build_minify()
    • +
    • gallivm: added some comments
    • +
    • draw: check for null sampler pointers
    • +
    • swrast: fix choose_depth_texture_level() to respect mipmap filtering state
    • +
    • st/mesa: replace assertion w/ conditional in framebuffer invalidation
    • +
    • glsl2: fix signed/unsigned comparison warning
    • +
    • st/xlib: add some comments
    • +
    • ir_to_mesa: assorted clean-ups, const qualifiers, new comments
    • +
    • mesa: remove assertion w/ undeclared variable texelBytes
    • +
    • gallivm: remove newlines
    • +
    • draw/llvmpipe: replace DRAW_MAX_TEXTURE_LEVELS with PIPE_MAX_TEXTURE_LEVELS
    • +
    • mesa: reformatting, comments, code movement
    • +
    • x11: fix breakage from gl_config::visualType removal
    • +
    • gallivm: work-around trilinear mipmap filtering regression with LLVM 2.8
    • +
    • mesa: remove post-convolution width/height vars
    • +
    • gallivm: add compile-time option to emit inst addrs and/or line numbers
    • +
    • llvmpipe: code to dump bytecode to file (disabled)
    • +
    • gallivm: added lp_build_print_vec4()
    • +
    • gallivm: added lp_build_load_volatile()
    • +
    • glsl: add ir_unop_round_even case to silence unhandled enum warning
    • +
    • st/mesa: fix regressions in glDrawPixels(GL_STENCIL_INDEX)
    • +
    • st/mesa: reformatting in st_cb_drawpixels.c
    • +
    • st/mesa: use GLuint to avoid problem w/ uint not defined on mingw32
    • +
    • st/mesa: update function name, comments
    • +
    • gallivm: use util_snprintf()
    • +
    • llvmpipe: remove lp_setup_coef*.c files from Makefile
    • +
    • mesa: fix mesa version string construction
    • +
    • gallivm: fix incorrect type for zero vector in emit_kilp()
    • +
    • llvmpipe/draw: always enable LLVMAddInstructionCombiningPass()
    • +
    • draw: use float version of LLVM Mul/Add instructions
    • +
    • draw: fix typo in comment
    • +
    • mesa: add GL_RG case to _mesa_source_buffer_exists()
    • +
    • mesa: add missing cases for packing red/green images
    • +
    • st/mesa: added cases for GL_COMPRESSED_RED/RG in st_choose_format()
    • +
    • docs: update texture red/green support in GL3.txt
    • +
    • docs: add GL_ARB_texture_rg to release notes
    • +
    • mesa: driver hook for primitive restart
    • +
    • mesa: set/get primitive restart state
    • +
    • mesa: API spec for primitive restart
    • +
    • mesa: regenerated files with primitive restart
    • +
    • mesa: plug in primitive restart function
    • +
    • vbo: support for primitive restart
    • +
    • gallium: new CAP, state for primitive restart
    • +
    • st/mesa: support for primitive restart
    • +
    • draw: implement primitive splitting for primitive restart
    • +
    • softpipe: enable primitive restart
    • +
    • llvmpipe: enable primitive restart
    • +
    • docs: added GL_NV_primitive_restart extension
    • +
    • Merge branch 'primitive-restart-cleanup'
    • +
    • winsys/xlib: formatting fixes
    • +
    • winsys/xlib: use Bool type for shm field
    • +
    • winsys/xlib: fix up allocation/dealloction of XImage
    • +
    • winsys/xlib: rename xm->xlib
    • +
    • galahad: silence warnings
    • +
    • mesa: move declaration before code
    • +
    • docs: updated GL3 status for primitive restart
    • +
    • mesa: 80-column wrapping
    • +
    • mesa: simplify fbo format checking code
    • +
    • mesa: split up the image.c file
    • +
    • mesa: add pixel packing for unscaled integer types
    • +
    • mesa: _mesa_ClearColorIuiEXT() and _mesa_ClearColorIiEXT()
    • +
    • mesa: _mesa_is_format_integer() function
    • +
    • mesa: minor reformatting, clean-ups
    • +
    • mesa: added _mesa_is_fragment_shader_active() helper
    • +
    • mesa: new glDrawPixels error check for integer formats
    • +
    • softpipe: added some texture sample debug code (disabled)
    • +
    • mesa: added new gl_extensions::EXT_gpu_shader4 field
    • +
    • mesa: added new gl_framebuffer::_IntegerColor field
    • +
    • mesa: added glGet query for GL_RGBA_INTEGER_MODE_EXT
    • +
    • mesa: compute _IntegerColor field in _mesa_test_framebuffer_completeness()
    • +
    • mesa: added cases for GL_EXT_texture_integer formats
    • +
    • mesa: added cases for GL_EXT_texture_integer
    • +
    • st/mesa: add format selection for signed/unsigned integer formats
    • +
    • mesa: simplify target_can_be_compressed() function
    • +
    • glapi: GL_EXT_texture_integer API
    • +
    • glapi: include/build EXT_texture_integer.xml
    • +
    • mesa: regenerated API files for GL_EXT_texture_integer
    • +
    • mesa: plug in GL_EXT_texture_integer functions
    • +
    • mesa: display list support for GL_EXT_texture_integer
    • +
    • st/mesa: be smarter choosing texture format for glDrawPixels()
    • +
    • softpipe: remove >32bpp color restriction
    • +
    • mesa: silence enum comparison warning
    • +
    • mesa: fix uninitialized var warning
    • +
    • xlib: silence unused var warning
    • +
    • util: use pointer_to_func() to silence warning
    • +
    • rtasm: use pointer_to_func() to silence warning
    • +
    • translate: use function typedefs, casts to silence warnings
    • +
    • translate: remove unused prototypes
    • +
    • mesa: additional glReadPixels error checks for GL_EXT_texture_integer
    • +
    • mesa: additional switch cases for GL_EXT_texture_integer
    • +
    • mesa: additional teximage error checks for GL_EXT_texture_integer
    • +
    • mesa: do integer FB / shader validation check in _mesa_valid_to_render()
    • +
    • mesa: call _mesa_valid_to_render() in glDrawPixels, glCopyPixels, glBitmap
    • +
    • mesa: remove the unused _mesa_is_fragment_shader_active() function
    • +
    • mesa: fix bug in _mesa_is_format_integer()
    • +
    • mesa: rename function to _mesa_is_format_integer_color()
    • +
    • mesa: remove 'normalized' parameter from _mesa_VertexAttribIPointer()
    • +
    • vbo: re-indent file
    • +
    • glapi: xml spec file for GL_EXT_gpu_shader4
    • +
    • glapi: include EXT_gpu_shader4.xml
    • +
    • glapi: regenerated API files
    • +
    • mesa: plug in stubs for glBindFragDataLocation(), glGetFragDataLocation()
    • +
    • mesa: add glGetUniformuiv(), plug in uint glUniform funcs
    • +
    • mesa: plug in more GL_EXT_gpu_shader4 functions
    • +
    • mesa: add new GLvertexformat entries for integer-valued attributes
    • +
    • mesa: implement integer-valued vertex attribute functions
    • +
    • mesa: add gl_client_array::Integer field and related vertex array state code
    • +
    • mesa: consolidate glVertex/Color/etcPointer() code
    • +
    • mesa: state/queries for GL_MIN/MAX_PROGRAM_TEXEL_OFFSET_EXT
    • +
    • mesa: glArrayElement support for integer-valued arrays
    • +
    • mesa: clean-up array element code
    • +
    • mesa: add extension table entry for GL_EXT_gpu_shader4
    • +
    • mesa: remove obsolete comment
    • +
    • mesa: fix incorrect type in _mesa_texstore_rgba_int16()
    • +
    • mesa: fix integer cases in _mesa_is_legal_format_and_type()
    • +
    • mesa: add const qualifier to _mesa_is_legal_format_and_type()
    • +
    • mesa: additional integer formats in _mesa_bytes_per_pixel()
    • +
    • mesa: pixel transfer ops do not apply to integer-valued textures
    • +
    • mesa: remove dead code
    • +
    • osmesa: fix renderbuffer memleak in OSMesaMakeCurrent()
    • +
    • mesa: use GLubyte for edge flag arrays
    • +
    • mesa: move the gl_config struct declaration
    • +
    • dri/util: add a bunch of comments
    • +
    • mesa: remove always-false conditional in check_compatible()
    • +
    • mesa: fix aux/accum comment and error message mixups
    • +
    • llvmpipe: assign context's frag shader pointer before using it
    • +
    • llvmpipe: add a cast
    • +
    • mesa: silence new warnings in texobj.c
    • +
    • egl/gdi: fix typo: xsurf->gsurf
    • +
    • mesa: code to unpack RGBA as uints
    • +
    • gallivm: implement scatter stores into temp register file
    • +
    • gallivm: add some LLVM var labels
    • +
    • gallivm: added debug code to dump temp registers
    • +
    • gallivm: add pixel offsets in scatter stores
    • +
    • gallivm: added lp_elem_type()
    • +
    • gallivm: implement execution mask for scatter stores
    • +
    • tgsi: remove unused function
    • +
    • llvmpipe: added some debug assertions, but disabled
    • +
    • gallivm: alloca() was called too often for temporary arrays
    • +
    • gallivm: add const qualifiers, fix comment string
    • +
    • softpipe: disable vertex texturing with draw/llvm
    • +
    • mesa: consolidate pixel packing/unpacking code
    • +
    • mesa: rename vars in pixel pack/unpack code
    • +
    • mesa: implement uint texstore code
    • +
    • mesa: remove stray GL_FLOAT case in _mesa_is_legal_format_and_type()
    • +
    • mesa: make fixed-pt and byte-valued arrays a runtime feature
    • +
    • softpipe: can't no-op depth test stage when occlusion query is enabled
    • +
    • mesa: no-op glBufferSubData() on size==0
    • +
    • mesa: #include mfeatures.h in enums.h
    • +
    • mesa: improve error message
    • +
    • mesa: add missing formats in _mesa_format_to_type_and_comps()
    • +
    • mesa: handle more pixel types in mipmap generation code
    • +
    • mesa: make glIsBuffer() return false for never bound buffers
    • +
    • mesa: fix glDeleteBuffers() regression
    • +
    • tdfx: s/Format/_BaseFormat/
    • +
    • mesa: consolidate assertions in teximage code
    • +
    • radeon: set gl_texture_image::TexFormat field in radeonSetTexBuffer2()
    • +
    • r600: set gl_texture_image::TexFormat field in r600SetTexBuffer2()
    • +
    • r200: set gl_texture_image::TexFormat field in r200SetTexBuffer2()
    • +
    • r300: set gl_texture_image::TexFormat field in r300SetTexBuffer2()
    • +
    • evergreen: set gl_texture_image::TexFormat field in evergreenSetTexBuffer()
    • +
    • st/mesa: fix glDrawPixels(depth/stencil) bugs
    • +
    • glsl: fix assorted MSVC warnings
    • +
    • mesa: add more work-arounds for acoshf(), asinhf(), atahf()
    • +
    • glsl: remove opt_constant_expression.cpp from SConscript
    • +
    • mesa: fix error messages and minor reindenting
    • +
    • mesa: whitespace cleanups
    • +
    • mesa: 80-column wrapping
    • +
    • mesa: reorder texture_error_check() params
    • +
    • mesa: minor clean-ups in context code
    • +
    • mesa: upgrade to glext.h version 66
    • +
    • mesa: pass gl_format to _mesa_init_teximage_fields()
    • +
    • mesa: fix error msg typo
    • +
    • glapi: rename GL3.xml to GL3x.xml as it covers all GL 3.x versions
    • +
    • mesa: hook up GL 3.x entrypoints
    • +
    • docs: update some GL 3.0 status
    • +
    • mesa: fix get_texture_dimensions() for texture array targets
    • +
    • swrast: init alpha value to 1.0 in opt_sample_rgb_2d()
    • +
    • glsl: fix off by one in register index assertion
    • +
    • glsl: use gl_register_file in a few places
    • +
    • mesa: rename, make _mesa_register_file_name() non-static
    • +
    • mesa: _mesa_valid_register_index() to validate register indexes
    • +
    • mesa: replace #defines with new gl_shader_type enum
    • +
    • mesa: use gl_shader_type enum
    • +
    • glsl: better handling of linker failures
    • +
    • glsl: start restoring some geometry shader code
    • +
    • mesa: add assertion and update comment in _mesa_format_image_size()
    • +
    • mesa: added _mesa_format_image_size64()
    • +
    • x11: remove test_proxy_teximage() function
    • +
    • st/mesa: fix mapping of zero-sized buffer objects
    • +
    • gallivm/llvmpipe: squash merge of the llvm-context branch
    • +
    • mesa: raise max texture sizes to 16K
    • +
    • softpipe: increase max texture size to 16K
    • +
    • mesa: replace large/MAX_WIDTH stack allocations with heap allocations
    • +
    • mesa: replace large/MAX_WIDTH stack allocations with heap allocations
    • +
    • swrast: avoid large stack allocations in blend code
    • +
    • swrast: avoid large stack allocations in tex combine code
    • +
    • st/mesa: avoid large stack allocations in readpixels code
    • +
    • mesa: replace more MAX_WIDTH stack allocations with heap allocations
    • +
    • gallivm/llvmpipe: remove lp_build_context::builder
    • +
    • gallivm: fix null builder pointers
    • +
    • mesa: fix GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME query
    • +
    • mesa: return GL_FRAMEBUFFER_DEFAULT as FBO attachment type
    • +
    • llvmpipe: fix broken stencil writemask
    • +
    • mesa: consolidate some compiler -D flags
    • +
    • swrast: allow GL_RG format in glDrawPixels()
    • +
    • swrast: fix indentation
    • +
    • swrast: accept GL_RG in glReadPixels()
    • +
    • swrast: restructure some glReadPixels() code
    • +
    • mesa: make glGet*(GL_NONE) generate GL_INVALID_ENUM
    • +
    • mesa: remove unneeded cast
    • +
    • mesa: update comments, remove dead code
    • +
    • st/mesa: new comment about updating state vars
    • +
    • mesa: add error margin to clip mask debug/check code
    • +
    • gallium/util: minor formatting fixes
    • +
    • mesa/llvm: use llvm-config --cppflags
    • +
    • st/mesa: fix mipmap generation bug
    • +
    • mesa: test for cube map completeness in glGenerateMipmap()
    • +
    • mesa: set gl_texture_object::_Complete=FALSE in incomplete()
    • +
    • mesa: consolidate glTexImage1/2/3D() code
    • +
    • mesa: simplify proxy texture code in texture_error_check()
    • +
    • mesa: consolidate the glTexSubImage1/2/3D() functions
    • +
    • mesa: consolidate glCopyTexImage1/2D() code
    • +
    • mesa: consolidate glCopyTexSubImage1/2/3D() functions
    • +
    • mesa: consolidate glCompressedTexImage1/2/3D() functions
    • +
    • mesa: make _mesa_test_proxy_teximage() easier to read
    • +
    • configure: use llvm-config --cppflags instead of --cflags
    • +
    • mesa: revamp error checking for compressed texture images
    • +
    • mesa: simplify target checking for TexImage functions
    • +
    • draw/llvm: don't flush in vs_llvm_delete()
    • +
    • tnl: Initialize gl_program_machine memory in run_vp.
    • +
    • tnl: a better way to initialize the gl_program_machine memory
    • +
    • mesa, st/mesa: disable GL_ARB_geometry_shader4
    • +
    • mesa/meta: fix broken assertion, rename stack depth var
    • +
    • glsl: new glsl_strtod() wrapper to fix decimal point interpretation
    • +
    • st/mesa: fix renderbuffer pointer check in st_Clear()
    • +

    + +

    Brian Rogers (1): +

      +
    • mesa: Add missing else in do_row_3D
    • +

    + +

    Chad Versace (25): +

      +
    • intel_extensions: Add ability to set GLSL version via environment
    • +
    • glsl: Add glsl_type::uvecN_type for N=2,3
    • +
    • glsl: Add lexer rules for uint and uvecN (N=2..4)
    • +
    • glsl: Changes in generated file glsl_lexer.cpp
    • +
    • glsl: Add lexer rules for << and >> in GLSL 1.30
    • +
    • glsl: Change generated file glsl_lexer.cpp
    • +
    • glsl: Implement ast-to-hir for binary shifts in GLSL 1.30
    • +
    • glsl: Implement constant expr evaluation for bitwise-not
    • +
    • glsl: Implement constant expr evaluation for bit-shift ops
    • +
    • glsl: Implement constant expr evaluation for bitwise logic ops
    • +
    • glsl: Fix ir validation for bit logic ops
    • +
    • glsl: Define shift_result_type() in ast_to_hir.cpp
    • +
    • glsl: Implement ast-to-hir for bit-shift-assignment
    • +
    • glsl: Define bit_logic_result_type() in ast_to_hir.cpp
    • +
    • glsl: Implement ast-to-hir for bit-logic ops
    • +
    • glsl: Fix lexer rule for ^=
    • +
    • glsl: Commit generated file glsl_lexer.cpp
    • +
    • glsl: Fix ast-to-hir for ARB_fragment_coord_conventions
    • +
    • mesa: Fix C++ includes in sampler.cpp
    • +
    • glsl: Fix ir_expression::constant_expression_value()
    • +
    • glsl: Fix erroneous cast in ast_jump_statement::hir()
    • +
    • glsl: Fix Doxygen tag file in recently renamed files
    • +
    • glsl: Improve usage message for glsl_compiler
    • +
    • glsl: Fix linker bug in cross_validate_globals()
    • +
    • glsl: In ast_to_hir, check sampler array indexing
    • +

    + +

    Chia-I Wu (149): +

      +
    • glapi: Fix build errors for ES.
    • +
    • glapi: Fix ES build errors again.
    • +
    • mesa: Update ES APIspec.xml.
    • +
    • st/xlib: Notify the context when the front/back buffers are swapped.
    • +
    • targets/egl: Use C++ compiler to link GL/ES state trackers.
    • +
    • libgl-xlib: Remove unused st_api_create_OpenGL.
    • +
    • st/egl: Split modeset code support to modeset.c.
    • +
    • st/egl: Rename kms backend to drm.
    • +
    • st/egl: s/kms/drm/ on the drm backend.
    • +
    • egl: Enable drm platform by default.
    • +
    • egl: Check extensions.
    • +
    • st/egl: Skip single-buffered configs in EGL.
    • +
    • mapi: Fix compiler warnings.
    • +
    • st/egl: Drop context argument from egl_g3d_get_egl_image.
    • +
    • targets/egl: Fix linking with libdrm.
    • +
    • st/vega: Fix version check in context creation.
    • +
    • egl: Use attribute names as the _EGLConfig member names.
    • +
    • egl: Access config attributes directly.
    • +
    • st/egl: Access _EGLConfig directly.
    • +
    • st/egl: Do not finish a fence that is NULL.
    • +
    • mesa: Remove unused vtxfmt_tmp.h.
    • +
    • egl_dri2: Drop the use of _egl[SG]etConfigKey.
    • +
    • egl_glx: Drop the use of [SG]ET_CONFIG_ATTRIB.
    • +
    • egl_glx: Fix borken driver.
    • +
    • egl: Move attributes in _EGLImage to _EGLImageAttribs.
    • +
    • egl: Parse image attributes with _eglParseImageAttribList.
    • +
    • egl: Move fallback routines to eglfallbacks.c.
    • +
    • egl: Drop dpy argument from the link functions.
    • +
    • egl: Minor changes to the _EGLConfig interface.
    • +
    • egl: Minor changes to the _EGLScreen interface.
    • +
    • egl: Fix _eglModeLookup.
    • +
    • st/egl: Fix native_mode refresh mode.
    • +
    • egl: Add reference count for resources.
    • +
    • egl: Use reference counting to replace IsLinked or IsBound.
    • +
    • egl: Fix a false negative check in _eglCheckMakeCurrent.
    • +
    • st/egl: Use resource reference count for egl_g3d_sync.
    • +
    • egl_dri2: Fix a typo that make glFlush be called at wrong time.
    • +
    • glapi: Do not use glapidispatch.h.
    • +
    • glapi: Move glapidispatch.h to core mesa.
    • +
    • glapi: Do not use glapioffsets.h.
    • +
    • glapi: Merge glapioffsets.h into glapidispath.h.
    • +
    • vbo: Use CALL_* macros.
    • +
    • mesa: Remove unnecessary glapitable.h includes.
    • +
    • autoconf: Better client API selection.
    • +
    • docs: Update egl and openvg docs.
    • +
    • autoconf: Update configuration info.
    • +
    • Merge branch 'glapi-reorg'
    • +
    • targets: Add missing quotes to Makefile.xorg.
    • +
    • autoconf: st/vega requires --enable-openvg.
    • +
    • st/mesa: Unreference the sampler view in st_bind_surface.
    • +
    • autoconf: Tidy configure output for EGL.
    • +
    • targets/egl: Fix a warning with --disable-opengl build.
    • +
    • egl: Rework _eglGetSearchPath.
    • +
    • mesa: Select FEATURE_remap_table when multiple APIs are enabled.
    • +
    • mesa: Allow contexts of different APIs to coexist.
    • +
    • egl: Set up the pthread key even TLS is used.
    • +
    • st/egl: Add native_surface::present callback.
    • +
    • st/egl: Use native_surface::present callback.
    • +
    • d3d1x: Use native_surface::present.
    • +
    • st/egl: Remove flush_frontbuffer and swap_buffers.
    • +
    • st/egl: Add support for swap interval and swap behavior.
    • +
    • st/egl: Add support for EGL_MATCH_NATIVE_PIXMAP.
    • +
    • st/egl: Add extern "C" wrapper to native.h.
    • +
    • st/egl: Add native_display_buffer interface.
    • +
    • st/egl: Use native_display_buffer for EGL_MESA_drm_image.
    • +
    • autoconf: Add --enable-gallium-egl.
    • +
    • docs: Update egl docs.
    • +
    • st/dri: Add support for surfaceless current contexts.
    • +
    • egl_dri2: Fix __DRI_DRI2 version 1 support.
    • +
    • st/vega: Do not wait NULL fences.
    • +
    • gallium: Add st_api::name.
    • +
    • gallium: Add st_context_iface::share to st_api.
    • +
    • st/wgl: Use st_context_iface::share for DrvShareLists.
    • +
    • st/glx: Replace MESA_VERSION_STRING by xmesa_get_name.
    • +
    • mesa: Clean up core.h.
    • +
    • scons: Define IN_DRI_DRIVER.
    • +
    • tgsi: Add STENCIL to text parser.
    • +
    • st/vega: vegaLookupSingle should validate the state.
    • +
    • st/vega: Set wrap_r for mask and blend samplers.
    • +
    • st/vega: Fix vgReadPixels with a subrectangle.
    • +
    • egl_dri2: Fix one context, multiple surfaces.
    • +
    • auxiliary: util_blit_pixels_tex should restore the viewport.
    • +
    • st/vega: Fix a crash with empty paths.
    • +
    • st/vega: Masks and surfaces should share orientation.
    • +
    • st/vega: No flipping in vg_prepare_blend_surface.
    • +
    • st/vega: Fix a typo in EXTENDED_BLENDER_OVER_FUNC.
    • +
    • llvmpipe: Fix build errors on x86.
    • +
    • st/vega: Overhaul renderer with renderer states.
    • +
    • st/vega: Add DRAWTEX renderer state.
    • +
    • st/vega: Add SCISSOR renderer state.
    • +
    • st/vega: Add CLEAR renderer state for vgClear.
    • +
    • st/vega: Add FILTER renderer state for image filtering.
    • +
    • st/vega: Use the renderer for vgMask.
    • +
    • st/vega: Add POLYGON_STENCIL and POLYGON_FILL renderer state.
    • +
    • st/vega: Delay fb state update to vg_validate_state.
    • +
    • st/vega: Use st_framebuffer for fb width/height.
    • +
    • st/vega: Move g3d states to renderer.
    • +
    • st/vega: Make shader_bind call into the renderer.
    • +
    • st/vega: vg_manager should care about only the color buffer.
    • +
    • st/vega: Clean up vg_context fields and functions.
    • +
    • st/vega: Clean up renderer fields and functions.
    • +
    • st/vega: vg_copy_texture and vg_copy_surface should share code.
    • +
    • st/vega: Get rid of renderer_copy_texture.
    • +
    • st/vega: Update to latest headers.
    • +
    • st/vega: Fix image sampler views for alpha-only formats.
    • +
    • st/vega: Make path_render and path_stroke take a matrix.
    • +
    • st/vega: Make image_draw take a matrix.
    • +
    • st/vega: Add primitive text support.
    • +
    • st/vega: Revive mask layer support.
    • +
    • st/vega: More flexible shader selection.
    • +
    • st/vega: Add color transformation support.
    • +
    • st/vega: Bump version to 1.1.
    • +
    • st/vega: Fix paint coordinates transformations.
    • +
    • st/vega: Fix negated logic in image_draw.
    • +
    • st/vega: Fix degenerate paints.
    • +
    • st/vega: Simplify radial gradient.
    • +
    • st/vega: Remove st_inlines.h.
    • +
    • st/vega: Delay blend texture creation until needed.
    • +
    • st/vega: Create drawing surface mask as needed.
    • +
    • st/vega: Initialize pipe states with renderer.
    • +
    • st/vega: Avoid unnecessary constant bufer upload.
    • +
    • st/vega: Destroy the pipe context with vg_context.
    • +
    • st/vega: polygon_array requires a deep free.
    • +
    • st/egl: Set pipe_resource::array_size to 1.
    • +
    • st/vega: Set pipe_resource::array_size to 1.
    • +
    • st/vega: Move vertex transformation to shader.
    • +
    • st/vega: Add a missing break.
    • +
    • st/vega: Add some comments to pipeline shaders.
    • +
    • st/vega: Refactor blend shaders.
    • +
    • st/vega: Move masking after blending.
    • +
    • st/vega: Add support for per-channel alpha.
    • +
    • st/vega: Blending should use premultiplied alpha.
    • +
    • st/vega: Fix VG_BLEND_MULTIPLY.
    • +
    • st/vega: Add blend shaders for all blend modes.
    • +
    • st/vega: Fix pipe blend state for various blend modes.
    • +
    • egl: _eglFilterArray should not allocate.
    • +
    • mapi: Rewrite mapi_abi.py to get rid of preprocessor magic.
    • +
    • vbo: Drop second ATTR macro.
    • +
    • vbo: Fix GLES2 glVertexAttrib.
    • +
    • mesa: Do not advertise GL_OES_texture_3D.
    • +
    • mesa: Fix GL_FIXED arrays.
    • +
    • mesa: Fix glTexCoordPointer with type GL_FIXED.
    • +
    • st/egl: Plug pbuffer leaks.
    • +
    • st/egl: Fix eglCopyBuffers.
    • +
    • st/egl: Assorted fixes for dri2_display_get_configs.
    • +
    • docs/egl: Update egl.html.
    • +
    • st/egl: Fix eglChooseConfig when configs is NULL.
    • +
    • docs: Add an example for EGL_DRIVERS_PATH.
    • +
    • autoconf: Fix --with-driver=xlib --enable-openvg.
    • +

    + +

    Chris Wilson (2): +

      +
    • i915g: Fix closure of full batch buffers
    • +
    • intel: Check for unsupported texture when finishing using as a render target
    • +

    + +

    Christoph Bumiller (80): +

      +
    • nv50: import new compiler
    • +
    • nouveau: update nouveau_class.h
    • +
    • nv50: introduce the big formats table
    • +
    • nv50: don't produce MOV immediate to output reg in store opt
    • +
    • nv50: change back accidentally swapped UNORM,SNORM vertex type
    • +
    • nv50: add/fix some license headers
    • +
    • nv50: simple reload elimination and local CSE
    • +
    • nv50: fix constant_operand opt mul by 2 case
    • +
    • nv50: permit usage of undefined TGSI TEMPs
    • +
    • nv50: add missing 2nd source for POW multiplication
    • +
    • nv50: add signed RGTC1 to format table, allow 2_10_10_10 for vbufs
    • +
    • nv50: fix for empty BBs
    • +
    • nv50: insert MOVs also for PHI sources from dominating block
    • +
    • nv50: explicitly set src type for SET ops
    • +
    • nv50: fixes for nested IFs
    • +
    • nv50: don't eliminate loads to dedicated values
    • +
    • nv50: fix constbuf validation
    • +
    • nv50: build proper phi functions in the first place
    • +
    • nv50: fix reg count
    • +
    • nv50: begin implementing loops
    • +
    • nv50: more constant folding
    • +
    • nv50: loops part 2
    • +
    • nv50: flatten simple IF/ELSE/ENDIF constructs
    • +
    • nv50: fix thinko in store to output reg possible check
    • +
    • nv50: generate JOINs for outermost IF clauses
    • +
    • nv50: more TGSI opcodes (SIN, SCS, ARL, RET, KILP)
    • +
    • nv50: fix PSIZ and PRIMID mapping
    • +
    • nv50: check dst compatibility in CSE
    • +
    • nv50: initialize edgeflag input index
    • +
    • nv50: emit predicate for interp
    • +
    • Merge remote branch 'origin/master' into nv50-compiler
    • +
    • nv50: DP2, fix ARL
    • +
    • nv50: yet another case we need a nop.exit
    • +
    • nv50: fix check for sprite/point coord enable
    • +
    • nv50: handle TEXTURE_SWIZZLE and GEOMETRY_SHADER4 caps
    • +
    • nv50: set the FragDepth output index
    • +
    • nv50: turn off verbose debug output by default
    • +
    • nv50: attempt at making more complicated loops work
    • +
    • nv50: SSG
    • +
    • nv50: make FrontFacing -1 or +1
    • +
    • nv50: re-add proper TEXBIAS sequence
    • +
    • nv50: make use of TGSI immediate type
    • +
    • nv50: must join SELECT inputs before MOV inputs
    • +
    • nv50: fix XPD, was negated
    • +
    • nv50: fix find_dom_frontier
    • +
    • nv50: fix build-predicate function
    • +
    • Merge remote branch 'origin/master' into nv50-compiler
    • +
    • nv50: load address register before using it, not after
    • +
    • nv50: save tgsi instructions
    • +
    • nv50: prepare for having multiple functions
    • +
    • nv50: don't parse again in tgsi_2_nc
    • +
    • nv50: use actual loads/stores if TEMPs are accessed indirectly
    • +
    • nv50: create value references with the right type
    • +
    • nv50: duplicate interps in load_proj_tex_coords
    • +
    • nv50: address regs are 16 bit
    • +
    • nv50: fix can_load check for 3rd source
    • +
    • nv50: reduce bb_reachable_by runtime from pot to linear
    • +
    • nv50: minor compiler fixes and cleanups
    • +
    • nv50: cannot move from local mem to output reg directly
    • +
    • nv50: newlines in shader bincode printing
    • +
    • nv50: match TEMP limit with nv50 ir builder
    • +
    • nv50: handle TGSI EXP and LOG again
    • +
    • nv50: check for immediates when turning MUL ADD into MAD
    • +
    • nv50: interp cannot write flags reg
    • +
    • nv50: MOV TEMP[0], -CONST[0] must be float32 negation
    • +
    • nv50: fix indirect CONST access with large or negative offsets
    • +
    • nv50: fix TXP depth comparison value
    • +
    • nv50: consider address register in reload elimination
    • +
    • nv50: improve and fix modifier folding optimization
    • +
    • nv50: put low limit on REG_ALLOC_TEMP and FP_RESULT_COUNT
    • +
    • Merge remote branch 'origin/nv50-compiler'
    • +
    • nv50: don't segfault on shaders with 0 instructions
    • +
    • nv50: get shader fixups/relocations into working state
    • +
    • nv50: add relocs for stack and local mem buffers
    • +
    • nv50: emit constbuf relocs before uploading constants
    • +
    • nv50: fix typo in fifo packet length limit
    • +
    • nv50: use formats table in nv50_surface.c
    • +
    • nv50: use CLEAR_BUFFERS for surface fills
    • +
    • nv50: fix/handle a few more PIPE_CAPs
    • +
    • nv50: fix GP state bind and validate
    • +

    + +

    Corbin Simpson (8): +

      +
    • r600g: Use align() instead of handrolled code.
    • +
    • r600g: Trivially deobfuscate r600_hw_states.
    • +
    • r600g: Deobfuscate and comment a few more functions in r600_hw_states.
    • +
    • r600g: Clean up some indentation and |= vs. | usage.
    • +
    • r600g: Fix false and true.
    • +
    • r600g: "tmp" is such a bad name for a texture.
    • +
    • r600g: Clean up PS setup.
    • +
    • r600g: Cleanup viewport floats.
    • +

    + +

    Daniel Lichtenberger (1): +

      +
    • radeon: fix potential segfault in renderbuffer update
    • +

    + +

    Daniel Vetter (21): +

      +
    • r200: revalidate after radeon_update_renderbuffers
    • +
    • i915g: rip out ->sw_tiled
    • +
    • i915g: s/hw_tiled/tiling
    • +
    • i915g: add pineview pci ids
    • +
    • i915g: kill RGBA/X formats
    • +
    • i915g: kill buf->map_gtt
    • +
    • i915g: kill idws->pool
    • +
    • i915g: drop alignment parameter from iws->buffer_create
    • +
    • i915g: add winsys function to create tiled buffers
    • +
    • i915g: switch to tiled allocations, kill set_fence
    • +
    • i915g: prepare winsys/batchbuffer for execbuf2
    • +
    • i915g: return tiling in iws->buffer_from_handle
    • +
    • i915g: implement unfenced color&depth buffer using tiling bits
    • +
    • i915g: implement unfenced relocs for textures using tiling bits
    • +
    • i915g: postpone mipmap/face offset calculation
    • +
    • i915g: don't pot-align stride for tiled buffers
    • +
    • i915g: enable X-tiling for textures
    • +
    • i915g: switch rendering to mipmapped textures to (x,y) offsets
    • +
    • i915g: enable x-tiling for render targets
    • +
    • i915g: assert(depth_surface->offset == 0)
    • +
    • i915g: track TODO items
    • +

    + +

    Dave Airlie (182): +

      +
    • r300g: fix buffer reuse issue caused by previous commit
    • +
    • r600g: pull r600_draw struct out into header
    • +
    • r600g: use index min/max + index buffer offset.
    • +
    • r600g: add vgt dma src defines
    • +
    • r600g: fixup texture state on evergreen.
    • +
    • r600g: fix texture bos and avoid doing depth blit on evergreen
    • +
    • r600g: hide radeon_ctx inside winsys.
    • +
    • r600g: attempt to abstract kernel bos from pipe driver.
    • +
    • r600g: move constant buffer creation behind winsys abstraction.
    • +
    • r600g: use malloc bufmgr for constant buffers
    • +
    • r600g: add support for kernel bo
    • +
    • r600g: add winsys bo caching.
    • +
    • r600g: add upload manager support.
    • +
    • r600g: fixup map flushing.
    • +
    • r600g: use calloc for ctx bo allocations
    • +
    • r600g: oops got the use_mem_constant the wrong way around.
    • +
    • r600g; add uses waterfall to asm cf for r6xx.
    • +
    • r600g: only emit uses waterfall on r6xx hw.
    • +
    • util/r300g: split the r300 index buffer modifier functions out to util
    • +
    • r600g: modify index buffers for sizes the hw can't deal with.
    • +
    • r600g: send correct surface base update for multi-cbufs
    • +
    • r600g: fix fbo-drawbuffers-maxtargets
    • +
    • r600g: clean up valgrind issues on maxtargets test.
    • +
    • r600g: drop debugging that snuck in
    • +
    • r600g: fix tiling support for ddx supplied buffers
    • +
    • r600g: add z16 to color setup
    • +
    • r600g: add color/texture support for more depth formats.
    • +
    • r600g: fix r700 cube map sizing.
    • +
    • r600g: fixup r700 CB_SHADER_CONTROL register.
    • +
    • r600g: add missing BC_INST wrapper for evergreen
    • +
    • r600g: only flush for the correct colorbuffer, not all of them.
    • +
    • r600g: deal with overflow of VTX/TEX CF clauses.
    • +
    • r600g: set back to correct codepaths.
    • +
    • r600g: fixup evergreen miptree setup.
    • +
    • r600g: fix eg texture borders.
    • +
    • r600g: fix typo in struct member name
    • +
    • r600g: cleanup some of the DB blit code
    • +
    • r600g: make stencil readback work
    • +
    • r600g: disable dirty handling on texture from depth code.
    • +
    • r600g: use floats instead of hex for blit vbo
    • +
    • r600g: fix depth readback on rv610 and other quirky variants.
    • +
    • r600g: fix typo in evergreen register list
    • +
    • u_blitter: add a custom blitter call passing a dsa cso
    • +
    • r600g: use blitter to do db->cb flushing.
    • +
    • r600g: fix warnings since last commit.
    • +
    • egl: fix build since 17eace581d25a626a7d75d9d1205d012cbb14a6e
    • +
    • r300g: fix point sprite coord.
    • +
    • r600g: add vert support for 16/16 and 16/16/16 floats.
    • +
    • r600g: add some more vertex format support.
    • +
    • r600g: some more vertex formats
    • +
    • r600g: fix draw-elements and draw-elements-base-vertex
    • +
    • r600g: drop index_offset parameter to index buffer translate.
    • +
    • r600g: fixup tex wrapping.
    • +
    • r600g: fixup VP->FP output->input routing.
    • +
    • r600g: fix typo in r700 alu emit
    • +
    • r600g: fixup sprite coord enable.
    • +
    • r600g: fix polygon mode
    • +
    • mesa/mipmap: fix warning since 1acadebd6270d3604b026842b8a21360968618a0
    • +
    • r600g: add eg poly mode code.
    • +
    • r600g: make index bias fix for evergreen
    • +
    • r600g: add eg db count control register.
    • +
    • r300g: fix glsl-fs-pointcoord
    • +
    • r600g: add evergreen texture resource properly.
    • +
    • r600g: fix db flush breaking config state
    • +
    • r600g: on evergreen the centroid isn't set in this register.
    • +
    • r600g: add back evergreen name.
    • +
    • r600g: add evergreen texture border support to new path
    • +
    • r600g: move radeon.h members around to add back map flushing.
    • +
    • r600g: add initial vertex translate support.
    • +
    • r600g: remove old assert from new codepath
    • +
    • Revert "r600g: add initial vertex translate support."
    • +
    • r600g: port r300g fix for X* formats in texformat code
    • +
    • r600g: add L8A8 unorm.
    • +
    • r600g: clean up some code from move to new paths.
    • +
    • r600g: return string for chip family
    • +
    • r600g: use Elements macro instead of manual sizeofs
    • +
    • r600g: fix evergreen depth flushing.
    • +
    • r600g: add winsys support for CTL constants.
    • +
    • r600g: drop depth quirk on evergreen
    • +
    • r600g: add reloc for evergreen color attrib
    • +
    • r600g: realign evergreen code with r600 code.
    • +
    • r600g: add assembler support for other vtx fetch fields.
    • +
    • r600g: fixup vertex format picking.
    • +
    • r600g: sync vertex/texture cache on resources on evergreen
    • +
    • r600g: add cb flushing for extra buffers + depth buffer on r600/evergreen
    • +
    • r600g: fix evergreen draw-buffers
    • +
    • r600g: flush SH cache on constant change on evergreen
    • +
    • r600g: only set the Z export if shader exports it.
    • +
    • r600g: setup basic loop consts on r600 + evergreen.
    • +
    • mesa/st: initial attempt at RG support for gallium drivers
    • +
    • r600g: break out of search for reloc bo after finding it.
    • +
    • r600g: the code to check whether a new vertex shader is needed was wrong
    • +
    • r600g: fix wwarning in bo_map function
    • +
    • r600g: TODO domain management
    • +
    • r600g: add bo fenced list.
    • +
    • pb: don't keep checking buffers after first busy
    • +
    • r600g: add bo busy backoff.
    • +
    • r600g: drop mman allocator
    • +
    • r600g: drop use_mem_constant.
    • +
    • r600g: avoid unneeded bo wait
    • +
    • pb: fix numDelayed accounting
    • +
    • r600g: add evergreen stencil support.
    • +
    • r600g: use format from the sampler view not from the texture.
    • +
    • r600g: fix Z export enable bits.
    • +
    • r600g: add some RG texture format support.
    • +
    • r600g: drop width/height per level storage.
    • +
    • r600g: fix input/output Z export mixup for evergreen.
    • +
    • r600g: evergreen has no request size bit in texture word4
    • +
    • r600g: enable vertex samplers.
    • +
    • r600g: add TXL opcode support.
    • +
    • r600g: don't run with scissors.
    • +
    • r600g: fix typo in vertex sampling on r600
    • +
    • gallium/tgsi: add support for stencil writes.
    • +
    • gallium/format: add support for X24S8 and S8X24 formats.
    • +
    • gallium/format: add X32_S8X24_USCALED format.
    • +
    • gallium/util: add S8 tile sampling support.
    • +
    • mesa: add support for FRAG_RESULT_STENCIL.
    • +
    • mesa: improve texstore for 8/24 formats and add texstore for S8.
    • +
    • softpipe: add support for shader stencil export capability
    • +
    • st/mesa: add option to choose a texture format that we won't render to.
    • +
    • st/mesa: use shader stencil export to accelerate shader drawpixels.
    • +
    • r600g: add support for S8, X24S8 and S8X24 sampler formats.
    • +
    • r600g: add shader stencil export support.
    • +
    • glsl: add support for shader stencil export
    • +
    • st/mesa: enable stencil shader export extension if supported
    • +
    • r600g: fix depth0 setting
    • +
    • r600g: fix scissor/cliprect confusion
    • +
    • r600g: store samplers/views across blit when we need to modify them
    • +
    • r600g: reduce size of context structure.
    • +
    • r600g: the vs/ps const arrays weren't actually being used.
    • +
    • r600g: add copy into tiled texture
    • +
    • r600g: split out miptree setup like r300g
    • +
    • r600g: use common texture object create function
    • +
    • r600g: rename pitch in texture to pitch_in_bytes
    • +
    • r600g: remove bpt and start using pitch_in_bytes/pixels.
    • +
    • r600g: fix transfer stride.
    • +
    • r600g: drop all use of unsigned long
    • +
    • r600g: use blitter for hw copy region
    • +
    • r600g: evergreen add stencil export bit
    • +
    • r600g: add missing eg reg definition
    • +
    • r600g: fix stencil export for evergreen harder
    • +
    • r600g: drop unused context members
    • +
    • r600g: only pick centroid coordinate when asked.
    • +
    • r600g: fixup pos/face ena/address properly
    • +
    • r600g: fixup typo in macro name
    • +
    • r600g: select linear interpolate if tgsi input requests it
    • +
    • r300g: clean up warning due to unknown cap.
    • +
    • tgsi: add scanner support for centroid inputs
    • +
    • r600g: evergreen interpolation support.
    • +
    • r600g: add evergreen ARL support.
    • +
    • r600g: switch to a common formats.h file since they are in different regs
    • +
    • r600g: add defines for tiling
    • +
    • r600g: get tiling info from kernel
    • +
    • r600g: set tiling bits in hw state
    • +
    • r600g: do proper tracking of views/samplers.
    • +
    • r600g: fix typo in tiling setup cb code.
    • +
    • r600g: depth needs to bound to ds
    • +
    • r600g: attempt to cleanup depth blit
    • +
    • r600g: fix transfer function for tiling.
    • +
    • r600g: retrieve tiling info from kernel for shared buffers.
    • +
    • r600g: all non-0 mipmap levels need to be w/h aligned to POT.
    • +
    • r600g: move to per-miplevel array mode.
    • +
    • r600g: start adding hooks for aligning width/height for tiles.
    • +
    • r600g: add r600 surface to store the aligned height.
    • +
    • r600g: introduce a per-driver resource flag for transfers.
    • +
    • r600g: add texture tiling alignment support.
    • +
    • r600g: add texture tiling enable under a debug option.
    • +
    • r600g: initial translate state support
    • +
    • r600g: start splitting out common code from eg/r600.
    • +
    • r600g: not fatal if we can't get tiling info from kernel
    • +
    • r600g: merge more of the common r600/evergreen state handling
    • +
    • r600g: drop more common state handling code
    • +
    • r600g: fix magic 0x1 ->flat shade ena
    • +
    • r600g: add assembler support for all the kcache fields.
    • +
    • gallium/noop: report GL 2.1
    • +
    • r600g: pick correct color swap for A8 fbos.
    • +
    • r300g/r600g: bump cache manager timeouts to 1s
    • +
    • r600g: it looks like r600 can handle dword offsets in the indices.
    • +
    • r300g: try and use all of vertex constant space
    • +
    • r300g: fixup rs690 tiling stride alignment calculations.
    • +
    • r600g: fix evergreen segfaults.
    • +
    • r600g: hack around property unknown issues.
    • +

    + +

    Eric Anholt (300): +

      +
    • glsl: Add definition of gl_TextureMatrix inverse/transpose builtins.
    • +
    • i965: Share the KIL_NV implementation between glsl and non-glsl.
    • +
    • i965: Also enable CC statistics when doing OQs.
    • +
    • i965: Track the windowizer's dispatch for kill pixel, promoted, and OQ
    • +
    • glsl: Rework assignments with write_masks to have LHS chan count match RHS.
    • +
    • glsl: Fix copy'n'wasted ir_noop_swizzle conditions.
    • +
    • ir_to_mesa: Only compare vector_elements present for any_nequal/all_equal
    • +
    • i965: Fix the vector/expression splitting for the write_mask change.
    • +
    • i965: When splitting vector variable assignment, ignore unset channels.
    • +
    • i965: Update expression splitting for the vector-result change to compares.
    • +
    • i965: Warning fix for vector result any_nequal/all_equal change.
    • +
    • mesa: Remove the non-required ARB_imaging extension.
    • +
    • mesa: Remove EXT_histogram.
    • +
    • mesa: Remove SGI_color_table.
    • +
    • mesa: Remove SGI_color_matrix.
    • +
    • mesa: Remove EXT_convolution.
    • +
    • intel: Remove disabled stencil drawpixels acceleration.
    • +
    • intel: Remove unnecessary minimum pitch alignment to 32 bytes.
    • +
    • intel: Replace my intel_texture_bitmap code with _mesa_meta_Bitmap.
    • +
    • radeon: Remove copied minimum pitch alignment code.
    • +
    • unichrome: Mostly revert my convolution removal changes.
    • +
    • intel: Remove dead intelIsTextureResident().
    • +
    • i915: Remove a dead if (0) block.
    • +
    • intel: Dead comment removal.
    • +
    • intel: Corresponding FinishRenderTexture debug to BeginRenderTexture.
    • +
    • i965: Add support for rendering to SARGB8 FBOs.
    • +
    • intel: Fix segfault on INTEL_DEBUG=fbo with unsupported framebuffers.
    • +
    • intel: Add fallback debug to glGenerateMipmap.
    • +
    • intel: More reverting of the sw fallback for depth texture border color.
    • +
    • intel: Improve some of the miptree debugging.
    • +
    • mesa: Fix type typo in glGenerateMipmap handling of GL_UNSIGNED_INT data.
    • +
    • glsl: Fix broadcast_index of lower_variable_index_to_cond_assign.
    • +
    • glsl: Add validation that a swizzle only references valid channels.
    • +
    • i965: Fix up writemasked assignments in the new FS.
    • +
    • i965: Remove swizzling of assignment to vector-splitting single-channel LHS.
    • +
    • i965: Handle all_equal/any_nequal in the new FS.
    • +
    • i965: Fix vector splitting RHS channel selection with sparse writemasks.
    • +
    • i965: Add support for dFdx()/dFdy() to the FS backend.
    • +
    • i965: Add support for attribute interpolation on Sandybridge.
    • +
    • i965: Set up inputs to the fragment shader according to FP InputsRead.
    • +
    • i965: Add support for POW in gen6 FS.
    • +
    • i965: Fix negation in the new FS backend.
    • +
    • i965: Actually track the "if" depth in loop in the new FS backend.
    • +
    • i965: Apply the same set of lowering passes to new FS as to Mesa IR.
    • +
    • i965: Fix valgrind complaint about base_ir for new FS debugging.
    • +
    • i965: Fix up the FS backend for the variable array indexing pass.
    • +
    • i965: Set the variable type when dereferencing an array.
    • +
    • i965: Add support for dereferencing structs to the new FS backend.
    • +
    • i965: Add support for struct, array, and matrix uniforms to FS backend.
    • +
    • i965: Fix all non-snb regression in the snb attribute interpolation commit.
    • +
    • i965: Fix up part of my Sandybridge attributes support patch.
    • +
    • i965: Add support for gl_FrontFacing to the new FS backend.
    • +
    • i965: Subtract instead of adding when computing y delta in new FS backend.
    • +
    • mesa: Pull ir_to_mesa's sampler number fetcher out to shared code.
    • +
    • i965: Set up sampler numbers in the FS backend.
    • +
    • i965: Add support for non-color render target write data to new FS backend.
    • +
    • i965: Add support for MRT to the new FS backend.
    • +
    • i965: Add support for ir_loop counters to the new FS backend.
    • +
    • i965: Add support for ARB_fragment_coord_conventions to the new FS backend.
    • +
    • glsl: Also update implicit sizes of varyings at link time.
    • +
    • i965: Do interpolation for varying matrices and arrays in the FS backend.
    • +
    • i965: Don't try to emit interpolation for unused varying slots.
    • +
    • i965: Fix array indexing of arrays of matrices.
    • +
    • i965: Clean up obsolete FINISHME comment.
    • +
    • mesa: Move the list of builtin uniform info from ir_to_mesa to shared code.
    • +
    • i965: Add support for builtin uniforms to the new FS backend.
    • +
    • i965: Fix use of undefined mem_ctx in vector splitting.
    • +
    • i956: Make new FS discard do its work in a temp, not the null reg!
    • +
    • i965: Clean up the virtual GRF handling.
    • +
    • ra: First cut at a graph-coloring register allocator for mesa.
    • +
    • i965: First cut at register allocation using graph coloring.
    • +
    • i965: Add live interval analysis and hook it up to the register allocator.
    • +
    • i965: Remove my "safety counter" code from loops.
    • +
    • i965: Fix whole-structure/array assignment in new FS.
    • +
    • mesa: Don't reference a W component in setting up a vec3 uniform component.
    • +
    • i965: Fix new FS handling of builtin uniforms with packed scalars in structs.
    • +
    • glsl: Add a lowering pass for texture projection.
    • +
    • i965: Use the lowering pass for texture projection.
    • +
    • i965: Split the gen4 and gen5 sampler handling apart.
    • +
    • i965: Add gen6 attribute interpolation to new FS backend.
    • +
    • i965: Fix the gen6 jump size for BREAK/CONT in new FS.
    • +
    • i965: Also increment attribute location when skipping unused slots.
    • +
    • i965: Pre-gen6, map VS outputs (not FS inputs) to URB setup in the new FS.
    • +
    • i965: Add real support for pre-gen5 texture sampling to the new FS.
    • +
    • i965: Fix up copy'n'pasteo from moving coordinate setup around for gen4.
    • +
    • i965: Restore the forcing of aligned pairs for delta_xy on chips with PLN.
    • +
    • i965: When producing a single channel swizzle, don't make a temporary.
    • +
    • i965: Add a sanity check for register allocation sizes.
    • +
    • i965: Fix off-by-ones in handling the last members of register classes.
    • +
    • i965: Don't try to emit code if we failed register allocation.
    • +
    • i965: Add support for EXT_texture_swizzle to the new FS backend.
    • +
    • i965: Set up swizzling of shadow compare results for GL_DEPTH_TEXTURE_MODE.
    • +
    • i965: Fix glean/texSwizzle regression in previous commit.
    • +
    • i965: Be more conservative on live interval calculation.
    • +
    • i965: Add trivial dead code elimination in the new FS backend.
    • +
    • i965: Add initial folding of constants into operand immediate slots.
    • +
    • i965: In disasm, gen6 fb writes don't put msg reg # in destreg_conditionalmod.
    • +
    • i965: Add support for gen6 FB writes to the new FS.
    • +
    • i965: Enable the constant propagation code.
    • +
    • i965: Also do constant propagation for the second operand of CMP.
    • +
    • i965: Add back gen6 headerless FB writes to the new FS backend.
    • +
    • i965: Gen6 no longer has the IFF instruction; always use IF.
    • +
    • i965: Fix up IF/ELSE/ENDIF for gen6.
    • +
    • i965: Fix botch in the header_present case in the new FS.
    • +
    • i965: Add some clarification of the WECtrl field.
    • +
    • i965: Don't do 1/w multiplication in new FS for gen6
    • +
    • i965: Gen6's sampler messages are the same as Ironlake.
    • +
    • i965: Refactor gl_FrontFacing setup out of general variable setup.
    • +
    • i965: Add support for gl_FrontFacing on gen6.
    • +
    • i965: Don't assume that WPOS is always provided on gen6 in the new FS.
    • +
    • i965: Fix gen6 pointsize handling to match pre-gen6.
    • +
    • i965: Disable emitting if () statements on gen6 until we really fix them.
    • +
    • i965: Normalize cubemap coordinates like is done in the Mesa IR path.
    • +
    • mesa: Simplify a bit of _mesa_add_state_reference using memcmp.
    • +
    • i965: Drop the check for duplicate _mesa_add_state_reference.
    • +
    • i965: Drop the check for YUV constants in the param list.
    • +
    • i965: Handle swizzles in the addition of YUV texture constants.
    • +
    • i965: Fix gen6 WM push constants updates.
    • +
    • i965: Fix new FS gen6 interpolation for sparsely-populated arrays.
    • +
    • i965: Enable attribute swizzling (repositioning) in the gen6 SF.
    • +
    • i965: Add register coalescing to the new FS backend.
    • +
    • i965: Split FS_OPCODE_DISCARD into two steps.
    • +
    • i965: Reduce register interference checks for changed FS_OPCODE_DISCARD.
    • +
    • i965: Move FS backend structures to a header.
    • +
    • i965: Give the math opcodes information on base mrf/mrf len.
    • +
    • i965: Give the FB write and texture opcodes the info on base MRF, like math.
    • +
    • i965: Compute to MRF in the new FS backend.
    • +
    • i965: Don't consider gen6 math instructions to write to MRFs.
    • +
    • i965: Add a couple of checks for gen6 math instruction limits.
    • +
    • i965: Don't compute-to-MRF in gen6 math instructions.
    • +
    • i965: Expand uniform args to gen6 math to full registers to get hstride == 1.
    • +
    • i965: Don't compute-to-MRF in gen6 VS math.
    • +
    • i965: Fix gen6 pixel_[xy] setup to avoid mixing int and float src operands.
    • +
    • i965: Always use the new FS backend on gen6.
    • +
    • i965: Fix missing "break;" in i2b/f2b, and missing AND of CMP result.
    • +
    • intel: Allow CopyTexSubImage to InternalFormat 3/4 textures, like RGB/RGBA.
    • +
    • i965: Don't rebase the index buffer to min 0 if any arrays are in VBOs.
    • +
    • i965: Add support for rescaling GL_TEXTURE_RECTANGLE coords to new FS.
    • +
    • i965: Set class_sizes[] for the aligned reg pair class.
    • +
    • i965: Update the live interval when coalescing regs.
    • +
    • i965: Add a pass to the FS to split virtual GRFs to float channels.
    • +
    • i965: Add a function for handling the move of boolean values to flag regs.
    • +
    • i965: Add peepholing of conditional mod generation from expressions.
    • +
    • i965: Enable the new FS backend on pre-gen6 as well.
    • +
    • i965: Fix texturing on pre-gen5.
    • +
    • i965: Set the type of the null register to fix gen6 FS comparisons.
    • +
    • i965: Disable the debug printf I added for FS disasm.
    • +
    • i965: Fix a weirdness in NOT handling.
    • +
    • i965: Fix assertion failure on gen6 BufferSubData to busy BO.
    • +
    • i965: Assert out on gen6 VS constant buffer reads that hang the GPU for now.
    • +
    • i965: Fix scissor-offscreen on gen6 like we did pre-gen6.
    • +
    • i965: Avoid blits in BufferCopySubdata on gen6.
    • +
    • i965: Tell the shader compiler when we expect depth writes for gen6.
    • +
    • i965: Remove the gen6 emit_mi_flushes I sprinkled around the driver.
    • +
    • i965: Disable thread dispatch when the FS doesn't do any work.
    • +
    • i965: Add EU emit support for gen6's new IF instruction with comparison.
    • +
    • i965: Set the source operand types for gen6 if/else/endif to integer.
    • +
    • i965: Use the new style of IF statement with embedded comparison on gen6.
    • +
    • i965: Split register allocation out of the ever-growing brw_fs.cpp.
    • +
    • i965: Fix gl_FrontFacing emit on pre-gen6.
    • +
    • i965: Add support for register spilling.
    • +
    • i965: Don't emit register spill offsets directly into g0.
    • +
    • i965: Correct scratch space allocation.
    • +
    • i965: Be more aggressive in tracking live/dead intervals within loops.
    • +
    • i965: Move the FS disasm/annotation printout to codegen time.
    • +
    • i965: Add support for pull constants to the new FS backend.
    • +
    • i965: Add EU code for dword scattered reads (constant buffer array indexing).
    • +
    • i965: Clarify an XXX comment in FB writes with real info.
    • +
    • i965: Use SENDC on the first render target write on gen6.
    • +
    • i965: Clear some undefined fields of g0 when using them for gen6 FB writes.
    • +
    • i965: Add disasm for the flag register.
    • +
    • i965: Add support for discard instructions on gen6.
    • +
    • i965: Handle new ir_unop_round_even in channel expression splitting.
    • +
    • i965: Fix typo in comment about state flags.
    • +
    • i965: Set up the constant buffer on gen6 when it's needed.
    • +
    • i965: Add support for constant buffer loads on gen6.
    • +
    • i965: Drop the eot argument to read messages, which can never be set.
    • +
    • i965: Fix VS URB entry sizing.
    • +
    • i965: Disable register spilling on gen6 until it's fixed.
    • +
    • i965: Make FS uniforms be the actual type of the uniform at upload time.
    • +
    • i965: Add user clip planes support to gen6.
    • +
    • i965: Update gen6 SF state when point state (sprite or attenuation) changes.
    • +
    • i965: Upload required gen6 VS push constants even when using pull constants.
    • +
    • i965: Update the gen6 stencil ref state when stencil state changes.
    • +
    • mesa: Make metaops use program refcounts instead of names.
    • +
    • mesa: Don't compute an unused texture completeness debug string.
    • +
    • intel: For batch, use GTT mapping instead of writing to a malloc and copying.
    • +
    • intel: Annotate debug printout checks with unlikely().
    • +
    • intel: Remove the magic unaligned memcpy code.
    • +
    • i965: Remove dead intel_structs.h file.
    • +
    • intel: Avoid taking logbase2 of several things that we max.
    • +
    • intel: Remove duplicated teximage miptree to object miptree promotion.
    • +
    • intel: Remove leftover dri1 locking fields in the context.
    • +
    • mesa: Fix delayed state flagging for EXT_sso-related program changes.
    • +
    • intel: Fix the client-side swapbuffers throttling.
    • +
    • Revert "intel: Fix the client-side swapbuffers throttling."
    • +
    • i965: Allow OPCODE_SWZ to put immediates in the first arg.
    • +
    • i965: Add support for math on constants in gen6 brw_wm_glsl.c path.
    • +
    • i965: Work around strangeness in swizzling/masking of gen6 math.
    • +
    • i965: re-enable gen6 IF statements in the fragment shader.
    • +
    • glsl: Free the loop state context when we free the loop state.
    • +
    • i965: Fix gl_FragCoord inversion when drawing to an FBO.
    • +
    • i965: Shut up spurious gcc warning about GLSL_TYPE enums.
    • +
    • mesa: Don't spam the console in a debug build unless some spam is requested.
    • +
    • i965: Add state dumping for sampler state.
    • +
    • i965: Add dumping of the sampler default color.
    • +
    • i965: Fail on loops on gen6 for now until we write the EU emit code for it.
    • +
    • i965: Eliminate dead code more aggressively.
    • +
    • mesa: Include C++ files in the makedepend of DRI drivers.
    • +
    • i965: Fix compute_to_mrf to not move a MRF write up into another live range.
    • +
    • i965: Just use memset() to clear most members in FS constructors.
    • +
    • i965: Remove extra n at the end of every instruction in INTEL_DEBUG=wm.
    • +
    • i965: Fold constants into the second arg of BRW_SEL as well.
    • +
    • glsl: Add a helper function for determining if an rvalue could be a saturate.
    • +
    • i965: Recognize saturates and turn them into a saturated mov.
    • +
    • ir_to_mesa: Detect and emit MOV_SATs for saturate constructs.
    • +
    • i965: Improve compute-to-mrf.
    • +
    • i965: Remove duplicate MRF writes in the FS backend.
    • +
    • i965: Move gen4 blend constant color to the gen4 blending file.
    • +
    • i965: Don't upload polygon stipple unless required.
    • +
    • i965: Don't upload line stipple pattern unless we're stippling.
    • +
    • i965: Don't upload line smooth params unless we're line smoothing.
    • +
    • i965: Use the new embedded compare in SEL on gen6 for VS MIN and MAX opcodes.
    • +
    • i965: Fix type of gl_FragData[] dereference for FB write.
    • +
    • glsl: Make the symbol table's add_function just use the function's name.
    • +
    • glsl: Make the symbol table's add_variable just use the variable's name.
    • +
    • glsl: Add a helper constructor for expressions that works out result type.
    • +
    • glsl: Fix structure and array comparisions.
    • +
    • glsl: Quiet unreachable no-return-from-function warning.
    • +
    • i965: Dump the WHILE jump distance on gen6.
    • +
    • i965: Add support for gen6 DO/WHILE ISA emit.
    • +
    • i965: Add support for gen6 BREAK ISA emit.
    • +
    • i965: Add support for gen6 CONTINUE instruction emit.
    • +
    • i965: Enable IF statements in the VS.
    • +
    • i965: Add support for loops in the VS.
    • +
    • glsl: Mark the array access for whole-array comparisons.
    • +
    • glsl: Fix flipped return of has_value() for array constants.
    • +
    • mesa: Add getters for the rest of the supported draw buffers.
    • +
    • mesa: Add getters for ARB_copy_buffer's attachment points.
    • +
    • intel: Add an env var override to execute for a different GPU revision.
    • +
    • i965: Update gen6 WM state on compiled program change, not just FP change.
    • +
    • i965: Update gen6 SF state on fragment program change too.
    • +
    • i965: Fix compile warning about missing opcodes.
    • +
    • i965: Move payload reg setup to compile, not lookup time.
    • +
    • i965: Provide delta_xy reg to gen6 non-GLSL path PINTERP.
    • +
    • i965: Fix up 16-wide gen6 FB writes after various refactoring.
    • +
    • i965: Don't smash a group of coordinates doing gen6 16-wide sampler headers.
    • +
    • i965: Fix gen6 interpolation setup for 16-wide.
    • +
    • i965: Fix up gen6 samplers for their usage by brw_wm_emit.c
    • +
    • i965: Make the sampler's implied move on gen6 be a raw move.
    • +
    • i965: Align gen6 push constant size to dispatch width.
    • +
    • i965: Add support for the instruction compression bits on gen6.
    • +
    • i965: Nuke brw_wm_glsl.c.
    • +
    • i965: Remove INTEL_DEBUG=glsl_force now that there's no brw_wm_glsl.c
    • +
    • i965: Fix comment about gen6_wm_constants.
    • +
    • i965: Handle saturates on gen6 math instructions.
    • +
    • i965: Always hand the absolute value to RSQ.
    • +
    • i965: Add disabled debug code for dumping out the WM constant payload.
    • +
    • i965: Work around gen6 ignoring source modifiers on math instructions.
    • +
    • i965: Fix flipped value of the not-embedded-in-if on gen6.
    • +
    • i965: Don't try to store gen6 (float) blend constant color in bytes.
    • +
    • i965: Set up the color masking for the first drawbuffer on gen6.
    • +
    • i965: Set up the per-render-target blend state on gen6.
    • +
    • i965: Set the render target index in gen6 fixed-function/ARB_fp path.
    • +
    • i965: Use the new pixel mask location for gen6 ARB_fp KIL instructions.
    • +
    • i965: Drop KIL_NV from the ff/ARB_fp path since it was only used for GLSL.
    • +
    • i965: Drop push-mode reladdr constant loading and always use constant_map.
    • +
    • i965: Fix VS constants regression pre-gen6.
    • +
    • i965: Clean up VS constant buffer location setup.
    • +
    • i965: Set up the correct texture border color state struct for Ironlake.
    • +
    • i965: Set render_cache_read_write surface state bit on gen6 constant surfs.
    • +
    • i965: remove unused variable since brw_wm_glsl.c removal.
    • +
    • intel: Use plain R8 and RG8 for COMPRESSED_RED and COMPRESSED_RG.
    • +
    • intel: Set the swizzling for depth textures using the GL_RED depth mode.
    • +
    • glsl: Correct the marking of InputsRead/OutputsWritten on in/out matrices.
    • +
    • i965: Correct the dp_read message descriptor setup on g4x.
    • +
    • intel: Include stdbool so we can stop using GLboolean when we want to.
    • +
    • i965: Fix ARL to work on gen6.
    • +
    • i956: Fix the old FP path fragment position setup on gen6.
    • +
    • i965: Fix gl_FragCoord.z setup on gen6.
    • +
    • i965: Add support for using the BLT ring on gen6.
    • +
    • intel: Update renderbuffers before looking up CopyTexImage's read buffer.
    • +
    • intel: Drop commented intel_flush from copy_teximage.
    • +
    • intel: Try to sanely check that formats match for CopyTexImage.
    • +
    • intel: Support glCopyTexImage() from XRGB8888 to ARGB8888.
    • +
    • i965: Avoid using float type for raw moves, to work around SNB issue.
    • +
    • i965: Set the alternative floating point mode on gen6 VS and WM.
    • +
    • i965: Add support for gen6 constant-index constant loading.
    • +
    • i965: Add support for gen6 reladdr VS constant loading.
    • +
    • i965: Improve the hacks for ARB_fp scalar^scalar POW on gen6.
    • +
    • i965: Factor out the ir comparision to BRW_CONDITIONAL_* code.
    • +
    • i965: Fix regression in FS comparisons on original gen4 due to gen6 changes.
    • +
    • i965: Do lowering of array indexing of a vector in the FS.
    • +
    • intel: Only do frame throttling at glFlush time when using frontbuffer.
    • +
    • intel: Handle forced swrast clears before other clear bits.
    • +
    • intel: Use tri clears when we don't know how to blit clear the format.
    • +
    • intel: Add spans code for the ARB_texture_rg support.
    • +
    • intel: Add a couple of helper functions to reduce rb code duplication.
    • +
    • intel: Fix segfaults from trying to use _ColorDrawBuffers in FBO validation.
    • +
    • intel: When validating an FBO's combined depth/stencil, use the given FBO.
    • +

    + +

    Fabian Bieler (2): +

      +
    • r600g: set address of pop instructions to next instruction
    • +
    • glsl: fix lowering conditional returns in subroutines
    • +

    + +

    Francisco Jerez (51): +

      +
    • dri/nv04: Fix PGRAPH_ERRORs when running OA.
    • +
    • dri/nv04: Mipmapping fixes.
    • +
    • dri/nv04: Align SIFM transfer dimensions.
    • +
    • dri/nv04: Fix up color mask.
    • +
    • dri/nv04: Fix maximum texture size.
    • +
    • dri/nv04: Fix provoking vertex.
    • +
    • dri/nouveau: Update nouveau_class.h.
    • +
    • dri/nouveau: Add some more extensions.
    • +
    • dri/nouveau: Fix glRenderbufferStorage with DEPTH_COMPONENT as internal format.
    • +
    • dri/nouveau: Don't request a fake front unnecessarily.
    • +
    • dri/nouveau: Don't reemit the BO state in nouveau_state_emit().
    • +
    • dri/nouveau: Cleanup references to the old FBOs on glMakeCurrent().
    • +
    • meta: Don't bind the created texture object in init_temp_texture().
    • +
    • dri/nv10: Fix the CLAMP texture wrap mode.
    • +
    • dri/nv04: Use nvgl_wrap_mode().
    • +
    • dri/nouveau: Remove unnecessary assertion.
    • +
    • dri/nouveau: Cleanup more references to old FBOs and VBOs.
    • +
    • dri/nv10-nv20: Fix texturing in some cases after a base level change.
    • +
    • dri/nouveau: Fix software mipmap generation on 1x1 textures.
    • +
    • dri/nouveau: Have a smaller amount of larger scratch buffers.
    • +
    • dri/nouveau: Remove unnecessary flush.
    • +
    • dri/nv10: Use fast Z clears.
    • +
    • dri/nouveau: Minor cleanup.
    • +
    • dri/nv10: Fake fast Z clears for pre-nv17 cards.
    • +
    • dri/nouveau: Initialize tile_flags when allocating a render target.
    • +
    • nouveau: Get larger push buffers.
    • +
    • dri/nouveau: Force a "slow" Z clear if we're getting a new depth buffer.
    • +
    • dri/nv20: Clear with the 3D engine.
    • +
    • dri/nouveau: Don't assert(0) on compressed internal formats.
    • +
    • dri/nv25: Bind a hierarchical depth buffer.
    • +
    • dri/nouveau: Call _mesa_update_state() after framebuffer invalidation.
    • +
    • dri/nouveau: Honor the access flags in nouveau_bufferobj_map_range.
    • +
    • dri/nouveau: Tell the vbo module we want real hardware BOs.
    • +
    • dri/nouveau: Split out the scratch helpers to a separate file.
    • +
    • dri/nouveau: Avoid recursion in nouveau_bo_context_reset().
    • +
    • dri/nouveau: Use a macro to iterate over the bound vertex attributes.
    • +
    • dri/nouveau: Split out array handling to its own file.
    • +
    • dri/nouveau: Optimize VBO binding re-emission.
    • +
    • dri/nouveau: Keep small DYNAMIC_DRAW vertex buffers in system ram.
    • +
    • dri/nouveau: Pipeline glTexSubImage texture transfers.
    • +
    • dri/nouveau: Fix type promotion issue on 32bit platforms.
    • +
    • dri/nouveau: Validate the framebuffer state on read buffer changes.
    • +
    • dri/nouveau: Re-emit the BO state when coming back from a software fallback.
    • +
    • meta: Don't leak alpha function/reference value changes.
    • +
    • meta: Fix incorrect rendering of the bitmap alpha component.
    • +
    • vbo: Avoid unnecessary copy to/from current in vertex format upgrade.
    • +
    • meta: Don't try to disable cube maps if the driver doesn't expose the extension.
    • +
    • meta: Handle bitmaps with alpha test enabled.
    • +
    • dri/nouveau: Split hardware/software TNL instantiation more cleanly.
    • +
    • dri/nouveau: Fix typo.
    • +
    • dri/nouveau: Kill a bunch of ternary operators.
    • +

    + +

    Fredrik Höglund (2): +

      +
    • r600g: Fix texture sampling with swizzled coords
    • +
    • r600g: fix pow(0, 0) evaluating to NaN
    • +

    + +

    Guillermo S. Romero (1): +

      +
    • r300g: Do not use buf param before checking for NULL.
    • +

    + +

    Henri Verbeet (19): +

      +
    • r600g: Flush upload buffers before draws instead of before flushes.
    • +
    • r600g: Check for other references before checking for existing mappings in radeon_bo_pb_map_internal().
    • +
    • r600g: Remove a redundant flush in r600_texture_transfer_map().
    • +
    • r600g: Buffer object maps imply a wait.
    • +
    • r600g: Respect PB_USAGE_UNSYNCHRONIZED in radeon_bo_pb_map_internal().
    • +
    • Revert "r600g: Flush upload buffers before draws instead of before flushes."
    • +
    • r600g: fix exports_ps to export a number not a mask.
    • +
    • r600g: Mention AMD in the renderer string.
    • +
    • r600g: Cleanup the fenced_bo list in r600_context_fini().
    • +
    • r600g: Evergreen has two extra frac_bits for the sampler LOD state.
    • +
    • r600: Evergreen has two extra frac_bits for the sampler LOD state.
    • +
    • r600g: Add PIPE_FORMAT_L8A8_UNORM for Evergreen as well.
    • +
    • r600g: Swizzle vertex data only once.
    • +
    • r600g: Synchronize supported color formats between Evergreen and r600/r700.
    • +
    • r600g: Fix the PIPE_FORMAT_L8A8_UNORM color swaps.
    • +
    • r600g: Fix the PIPE_FORMAT_A8_UNORM color swap for Evergreen as well.
    • +
    • r600g: Cleanup block bo references in r600_context_fini().
    • +
    • r600g: Cleanup fetch shader resources in r600_pipe_shader_destroy().
    • +
    • st/mesa: Handle wrapped depth buffers in st_copy_texsubimage().
    • +

    + +

    Hui Qi Tay (10): +

      +
    • llvmpipe: minor changes in llvm coefficient calcs
    • +
    • draw: cliptest and viewport done in a single loop in vertex shader
    • +
    • draw: added viewport and cliptest flags
    • +
    • draw: sanitize llvm variant key
    • +
    • draw: corrections for w coordinate
    • +
    • draw: corrections to allow for different cliptest cases
    • +
    • llvmpipe: Moved draw pipeline twoside function to llvm setup code
    • +
    • llvmpipe: added llvm offset setup code
    • +
    • llvmpipe: clean up polygon offset function in lp setup code
    • +
    • llvmpipe: fix such that offset/twoside function only does in-place modification
    • +

    + +

    Ian Romanick (102): +

      +
    • glsl2: Refactor testing for whether a deref is of a matrix or array
    • +
    • glsl2: Add flags to enable variable index lowering
    • +
    • glsl: Add doxygen comments
    • +
    • EGL DRI2: Silence piles of 'unused variable' warnings
    • +
    • EGL DRI2: Silence 'missing initializer' warnings
    • +
    • egl_glx: Silence piles of 'unused variable' warnings
    • +
    • egl: Fix several 'comparison between signed and unsigned integer' warnings
    • +
    • dri: Ensure that DRI driver cpp files are in tarballs
    • +
    • mesa: Force GL_ARB_copy_buffer to always be enabled
    • +
    • mesa: Force GL_SGIS_generate_mipmap to always be enabled
    • +
    • Remove GL_MESA_packed_depth_stencil
    • +
    • Remove GL_EXT_cull_vertex
    • +
    • Regenerate files changed by previous commit
    • +
    • Remove unnescessary initializations of UpdateTexturePalette
    • +
    • ARB_texture_rg: Add GLX protocol support
    • +
    • ARB_texture_rg: Correct some errors in RED / RG internal format handling
    • +
    • ARB_texture_rg: Add GL_TEXTURE_{RED,GREEN}_SIZE query support
    • +
    • ARB_texture_rg: Add GL_RED as a valid GL_DEPTH_TEXTURE_MODE
    • +
    • ARB_texture_rg: Handle RED and RG the same as RGB for tex env
    • +
    • ARB_texture_rg: Add R8, R16, RG88, and RG1616 internal formats
    • +
    • ARB_texture_rg: Allow RED and RG textures as FBO color buffer attachments
    • +
    • mesa: Enable GL_ARB_texture_rg in software paths
    • +
    • i965: Enable GL_ARB_texture_rg
    • +
    • mesa: Add ARB_texture_compression_rgtc as an alias for EXT_texture_compression_rgtc
    • +
    • ARB_texture_rg: Add GL_COMPRESSED_{RED,RG} cases in _mesa_is_color_format
    • +
    • mesa: Fix misplaced #endif
    • +
    • mesa: Trivial correction to comment
    • +
    • rgtc: Detect RGTC formats as color formats and as compressed formats
    • +
    • docs: Add list of bugs fixed in 7.9
    • +
    • docs: Import 7.9 release notes from 7.9 branch.
    • +
    • docs: Import 7.8.x release notes from 7.8 branch.
    • +
    • docs: download.html does not need to be updated for each release
    • +
    • docs: Update mailing lines from sf.net to freedesktop.org
    • +
    • docs: Import news updates from 7.9 branch
    • +
    • docs: added news item for 7.9 release
    • +
    • glsl: Fail linking if assign_attribute_locations fails
    • +
    • glsl: Refactor 'layout' grammar to match GLSL 1.60 spec grammar
    • +
    • glsl: Slight refactor of error / warning checking for ARB_fcc layout
    • +
    • glsl: Clear type_qualifier using memset
    • +
    • glsl: Wrap ast_type_qualifier contents in a struct in a union
    • +
    • glsl: Regenerate files modified by previous commits
    • +
    • glcpp: Add the define for ARB_explicit_attrib_location when present
    • +
    • glcpp: Regenerate files changes by previous commit
    • +
    • glsl: Add parser support for GL_ARB_explicit_attrib_location layouts
    • +
    • glsl: Regenerate files changes by previous commit
    • +
    • glsl: Track explicit location in AST to IR translation
    • +
    • glsl: Add linker support for explicit attribute locations
    • +
    • main: Enable GL_ARB_explicit_attrib_location for swrast
    • +
    • intel: Enable GL_ARB_explicit_attrib_location
    • +
    • glsl: Remove const decoration from inlined function parameters
    • +
    • docs: skeleton for 7.10 release notes
    • +
    • docs: Update status of GL 3.x related extensions
    • +
    • mesa: Validate assembly shaders when GLSL shaders are used
    • +
    • glsl: Fix incorrect assertion
    • +
    • linker: Reject shaders that have unresolved function calls
    • +
    • mesa: Silence unused variable warning
    • +
    • mesa: Refactor validation of shader targets
    • +
    • mesa: Clean up two 'comparison between signed and unsigned' warnings
    • +
    • mesa: Clean up various 'unused parameter' warnings in shaderapi
    • +
    • glsl: Slightly change the semantic of _LinkedShaders
    • +
    • linker: Trivial indention fix
    • +
    • i965: Fix indentation after commit 3322fbaf
    • +
    • linker: Improve handling of unread/unwritten shader inputs/outputs
    • +
    • glapi: Add GL_EXT_separate_shader_objects
    • +
    • glapi: Commit files changed by previous commit
    • +
    • mesa: Add infrastructure to track GL_EXT_separate_shader_objects
    • +
    • mesa: Skeletal support for GL_EXT_separate_shader_objects
    • +
    • mesa: Add display list support for GL_EXT_separate_shader_objects functions
    • +
    • mesa: Track an ActiveProgram distinct from CurrentProgram
    • +
    • Track separate programs for each stage
    • +
    • swrast: Enable GL_EXT_separate_shader_objects in software paths
    • +
    • intel: Enable GL_EXT_separate_shader_objects in Intel drivers
    • +
    • docs: add GL_EXT_separate_shader_objects to release notes
    • +
    • glsl: Fix incorrect gl_type of sampler2DArray and sampler1DArrayShadow
    • +
    • ir_to_mesa: Refactor code for emitting DP instructions
    • +
    • mesa: Allow query of MAX_SAMPLES with EXT_framebuffer_multisample
    • +
    • glsl: Refactor is_vec_{zero,one} to be methods of ir_constant
    • +
    • glsl: Simplify generation of swizzle for vector constructors
    • +
    • glsl: Make is_zero and is_one virtual methods of ir_rvalue
    • +
    • ir_to_mesa: Generate smarter code for some conditional moves
    • +
    • glsl: Add ir_unop_sin_reduced and ir_unop_cos_reduced
    • +
    • glsl: Eliminate assumptions about size of ir_expression::operands
    • +
    • glsl: Add ir_rvalue::is_negative_one predicate
    • +
    • glsl: Add unary ir_expression constructor
    • +
    • glsl: Add ir_quadop_vector expression
    • +
    • glsl: Fix matrix constructors with vector parameters
    • +
    • i915: Disallow alpha, red, RG, and sRGB as render targets
    • +
    • glsl: Use M_LOG2E constant instead of calling log2
    • +
    • glsl: Lower ir_binop_pow to a sequence of EXP2 and LOG2
    • +
    • i915: Request that POW instructions be lowered
    • +
    • i915: Correctly generate unconditional KIL instructions
    • +
    • glsl: Ensure that equality comparisons don't return a NULL IR tree
    • +
    • i965: Correctly emit constants for aggregate types (array, matrix, struct)
    • +
    • glsl: Inherrit type of declared variable from initializer
    • +
    • linker: Ensure that unsized arrays have a size after linking
    • +
    • linker: Fix regressions caused by previous commit
    • +
    • glsl: Inherrit type of declared variable from initializer after processing assignment
    • +
    • linker: Allow built-in arrays to have different sizes between shader stages
    • +
    • ir_to_mesa: Don't generate swizzles for record derefs of non-scalar/vectors
    • +
    • Refresh autogenerated file builtin_function.cpp.
    • +
    • glsl: Allow less restrictive uses of sampler array indexing in GLSL <= 1.20
    • +
    • docs: Import 7.9.1 release notes from 7.9 branch
    • +

    + +

    Jakob Bornecrantz (27): +

      +
    • rbug: Cast opcode to corrent int size
    • +
    • rbug: Add function to get opcode name string
    • +
    • scons: Link against talloc in the Gallium DRI drivers
    • +
    • i915g: Link with wrapper sw winsys with scons
    • +
    • tgsi: Actually care what check_soa_dependencies says
    • +
    • tgsi: Fix missing test before check
    • +
    • llvmpipe: Move makefile include to before targets
    • +
    • wrapper: Fix spelling
    • +
    • wrapper: Add a way to dewrap a pipe screen without destroying it
    • +
    • egl: Remove unnecessary headers
    • +
    • target-helpers: Remove per target software wrapper check
    • +
    • graw: Tidy graw xlib scons file a bit
    • +
    • scons: Remove old pipebuffer SConscript
    • +
    • scons: Detabify
    • +
    • scons: Check for pkg-config before trying to use it
    • +
    • scons: Check for libdrm_[intel|radeon] as well
    • +
    • scons: Move dependancy checks to the main gallium scons file
    • +
    • scons: Unify state tracker SConscripts
    • +
    • galahad: Correct the name of the scons library
    • +
    • graw: Use inline sw helper instead of roll your own loader
    • +
    • libgl-xlib: Use sw helper instead of roll your own
    • +
    • libgl-xlib: Use inline debug helper instead of non-inline version
    • +
    • graw: Use inline debug helper instead of non-inline version
    • +
    • gallium: Remove redundant sw and debug target helpers
    • +
    • i915g: Improve debug printing for textures
    • +
    • i915g: Make sure that new vbo gets updated
    • +
    • st/mesa: Unbind all constant buffers
    • +

    + +

    Jerome Glisse (75): +

      +
    • r600g: alternative command stream building from context
    • +
    • r600g: move chip class to radeon common structure
    • +
    • r600g: use pipe context for flushing inside map
    • +
    • r600g: add back reference check when mapping buffer
    • +
    • r600g: directly allocate bo for user buffer
    • +
    • r600g: fix multi buffer rendering
    • +
    • r600g: occlusion query for new design
    • +
    • r600g: flush color buffer after draw command
    • +
    • r600g: disable shader rebuild optimization & account cb flush packet
    • +
    • r600g: fix multiple occlusion query on same id
    • +
    • r600g: initial evergreen support in new path
    • +
    • r600g: fix typo in evergreen define (resource are in x range)
    • +
    • r600g: move use_mem_constants flags for new designs structure alignment
    • +
    • r600g: evergreen fix for new design
    • +
    • r600g: fix compilation after change to evergreend.h
    • +
    • r600g: fixup some evergreen register definitions
    • +
    • r600g: fix evergreen new path
    • +
    • r600g: fix reg definition
    • +
    • r600g: fix evergreen new path
    • +
    • r600g: bring over fix from old path to new path
    • +
    • r600g: fix vertex resource & polygon offset
    • +
    • r600g: disable early cull optimization when occlusion query running
    • +
    • r600g: move around variables to share depth uncompression code
    • +
    • r600g: use depth decompression in new path
    • +
    • r600g: fix index buffer drawing
    • +
    • r600g: build packet header once
    • +
    • r600g: fix pointsprite & resource unbinding
    • +
    • r600g: fix routing btw vertex & pixel shader
    • +
    • r600g: fix occlusion query after change to block structure
    • +
    • r600g: use ptr for blit depth uncompress function
    • +
    • r600g: fix remaining piglit issue in new design
    • +
    • r600g: switch to new design
    • +
    • r600g: suspend/resume occlusion query around clear/copy
    • +
    • r600g: avoid rebuilding the vertex shader if no change to input format
    • +
    • r600g: use a hash table instead of group
    • +
    • r600g: delete old path
    • +
    • r600g: cleanup
    • +
    • r600g: more cleanup
    • +
    • r600g: use constant buffer instead of register for constant
    • +
    • r600g: fix constant & literal src splitting, also fix mplayer gl2 shader
    • +
    • evergreeng: avoid overlapping border color btw VS & PS
    • +
    • r600g: indentation fixes
    • +
    • r600g: rename radeon_ws_bo to r600_bo
    • +
    • r600g: allow r600_bo to be a sub allocation of a big bo
    • +
    • r600g: use r600_bo for relocation argument, simplify code
    • +
    • r600g: rename radeon_ws_bo to r600_bo
    • +
    • r600g: remove dead label & fix indentation
    • +
    • r600g: store reloc information in bo structure
    • +
    • r600g: improve bo flushing
    • +
    • r600g: simplify block relocation
    • +
    • r600g: userspace fence to avoid kernel call for testing bo busy status
    • +
    • r600g: avoid segfault due to unintialized list pointer
    • +
    • r600g: fix dirty state handling
    • +
    • r600g: allow driver to work without submitting cmd to GPU
    • +
    • gallium/noop: no operation gallium driver
    • +
    • r600g: code cleanup (indent, trailing space, empty line ...)
    • +
    • r600g: fix occlusion query on evergreen (avoid lockup)
    • +
    • r600g: add fetch shader capabilities
    • +
    • r600g: dump raw shader output for debugging
    • +
    • r600g: update polygon offset only when rasterizer or zbuffer change
    • +
    • r600g: indentation fix
    • +
    • r600g: more indentation fix + warning silencing + dead code removal
    • +
    • r600g: build fetch shader from vertex elements
    • +
    • r600g: avoid useless shader rebuild at draw call
    • +
    • r600g: remove useless flush map
    • +
    • r600g: remove dead code
    • +
    • r600g: fix userspace fence against lastest kernel
    • +
    • r600g: avoid using pb* helper we are loosing previous cpu cycle with it
    • +
    • r600g: specialized upload manager
    • +
    • r600g: indentation cleanup
    • +
    • r600g: fix bo size when creating bo from handle
    • +
    • r600g: fix segfault when translating vertex buffer
    • +
    • r600g: need to reference upload buffer as the might still live accross flush
    • +
    • r600g: properly unset vertex buffer
    • +
    • r600g: avoid segfault
    • +

    + +

    Joakim Sindholt (3): +

      +
    • util/u_blitter: fix leak
    • +
    • radeong: fix leaks
    • +
    • r300g: silence guard band cap errors
    • +

    + +

    Johann Rudloff (3): +

      +
    • radeon: Implement EGL_MESA_no_surface_extension
    • +
    • radeon: Implement __DRI_IMAGE and EGL_MESA_image_drm
    • +
    • radeon: Implement GL_OES_EGL_image
    • +

    + +

    John Doe (3): +

      +
    • r600g: misc cleanup
    • +
    • r600g: don't double count dirty block
    • +
    • r600g: keep a mapping around for each bo
    • +

    + +

    Jon TURNEY (1): +

      +
    • Ensure -L$(TOP)/$(LIB_DIR) appears in link line before any -L in $LDFLAGS
    • +

    + +

    José Fonseca (128): +

      +
    • gallivm: Fix address register swizzle.
    • +
    • gallivm: Start collecting bitwise arithmetic helpers in a new module.
    • +
    • gallivm: Clamp indirect register indices to file_max.
    • +
    • util: linearized sRGB values don't fit into 8bits
    • +
    • llvmpipe: Default to no threading on single processor systems.
    • +
    • tgsi: Don't ignore indirect registers in tgsi_check_soa_dependencies
    • +
    • llvmpipe: Describe how to profile llvmpipe.
    • +
    • llvmpipe: When failing free fs shader too.
    • +
    • util: Flush stdout on util_format.
    • +
    • gallivm: Add unorm support to lp_build_lerp()
    • +
    • llvmpipe: Special case complementary and identify blend factors in SoA.
    • +
    • llvmpipe: Make rgb/alpha bland func/factors match, when there is no alpha.
    • +
    • draw: Prevent clipped vertices overflow.
    • +
    • draw: Fullfil the new min_lod/max_lod/lod_bias/border_color dynamic state
    • +
    • gallivm: Fetch the lod from the dynamic state when min_lod == max_lod.
    • +
    • gallivm: Remove dead experimental code.
    • +
    • llvmpipe: Decouple sampler view and sampler state updates.
    • +
    • scons: New build= option, with support for checked builds.
    • +
    • scons: New build= option, with support for checked builds.
    • +
    • trace: Fix set_index_buffer and draw_vbo tracing.
    • +
    • python/retrace: Handle set_index_buffer and draw_vbo.
    • +
    • gallivm: Use SSE4.1's ROUNDSS/ROUNDSD for scalar rounding.
    • +
    • gallivm: More comprehensive border usage logic.
    • +
    • retrace: Handle clear_render_target and clear_depth_stencil.
    • +
    • llvmpipe: Dump a few missing shader key flags.
    • +
    • llvmpipe: Fix perspective interpolation for point sprites.
    • +
    • llvmpipe: Fix sprite coord perspective interpolation of Q.
    • +
    • gallivm: Take the type signedness in consideration in round/ceil/floor.
    • +
    • gallivm: Use a faster (and less accurate) log2 in lod computation.
    • +
    • gallivm: Fast implementation of iround(log2(x))
    • +
    • gallivm: Combined ifloor & fract helper.
    • +
    • gallivm: Only apply min/max_lod when necessary.
    • +
    • gallivm: Compute lod as integer whenever possible.
    • +
    • util: Cleanup util_pack_z_stencil and friends.
    • +
    • llvmpipe: Cleanup depth-stencil clears.
    • +
    • gallivm: Vectorize the rho computation.
    • +
    • gallivm: Do not do mipfiltering when magnifying.
    • +
    • gallivm: Simplify lp_build_mipmap_level_sizes' interface.
    • +
    • gallivm: Don't compute the second mipmap level when frac(lod) == 0
    • +
    • gallivm: Use lp_build_ifloor_fract for lod computation.
    • +
    • gallivm: Clamp mipmap level and zero mip weight simultaneously.
    • +
    • gallivm: Fix copy'n'paste typo in previous commit.
    • +
    • gallivm: Implement brilinear filtering.
    • +
    • gallivm: Use the wrappers for SSE pack intrinsics.
    • +
    • gallivm: Avoid control flow for two-sided stencil test.
    • +
    • gallivm: Warn when doing inefficient integer comparisons.
    • +
    • gallivm: Move into the as much of the second level code as possible.
    • +
    • llvmpipe: First minify the texture size, then broadcast.
    • +
    • gallivm: Help for combined extraction and broadcasting.
    • +
    • gallivm: Do size computations simultanously for all dimensions (AoS).
    • +
    • llvmpipe: Prevent z > 1.0
    • +
    • llvmpipe: Fix MSVC build. Enable the new SSE2 code on non SSE3 systems.
    • +
    • gallivm: Handle code have ret correctly.
    • +
    • util: Defined M_SQRT2 when not available.
    • +
    • gallivm: Less code duplication in log computation.
    • +
    • gallivm: Special bri-linear computation path for unmodified rho.
    • +
    • gallivm: Don't generate Phis for execution mask.
    • +
    • gallivm: Use varilables instead of Phis for cubemap selection.
    • +
    • gallivm: Remove support for Phi generation.
    • +
    • gallivm: Factor out the SI->FP texture size conversion for SoA path too
    • +
    • gallivm: Simplify if/then/else implementation.
    • +
    • gallivm: Cleanup the rest of the flow module.
    • +
    • gallivm: Fix a long standing bug with nested if-then-else emission.
    • +
    • gallivm: Allow to disable bri-linear filtering with GALLIVM_DEBUG=no_brilinear runtime option
    • +
    • gallivm: Use variables instead of Phis in loops.
    • +
    • gallivm: Pass texture coords derivates as scalars.
    • +
    • llvmpipe: Remove outdated comment about stencil testing.
    • +
    • gallivm: Eliminate unsigned integer arithmetic from texture coordinates.
    • +
    • gallium: Define C99 restrict keyword where absent.
    • +
    • tgsi: Export some names for some tgsi enums.
    • +
    • gallivm: More detailed analysis of tgsi shaders.
    • +
    • llvmpipe: Use lp_tgsi_info.
    • +
    • llvmpipe: Do not dispose the execution engine.
    • +
    • llvmpipe: Fix MSVC build.
    • +
    • llmvpipe: improve mm_mullo_epi32
    • +
    • gallivm: Name anonymous union.
    • +
    • llvmpipe: Unbreak Z32_FLOAT.
    • +
    • gallivm: More accurate float -> 24bit & 32bit unorm conversion.
    • +
    • llvmpipe: Generalize the x8z24 fast path to all depth formats.
    • +
    • llvmpipe: Fix depth-stencil regression.
    • +
    • llvmpipe: Ensure z_shift and z_width is initialized.
    • +
    • gallivm: Fix SoA cubemap derivative computation.
    • +
    • llvmpipe: Fix bad refactoring.
    • +
    • llvmpipe: Initialize bld ctx via lp_build_context_init instead of ad-hoc and broken code.
    • +
    • gallivm: Comment lp_build_insert_new_block().
    • +
    • gallivm: Add a note about SSE4.1's nearest mode rounding.
    • +
    • llvmpipe: Don't test rounding of x.5 numbers.
    • +
    • gallium: Avoid using __doc__ in python scripts.
    • +
    • gallivm: always enable LLVMAddInstructionCombiningPass()
    • +
    • gallivm: Remove the EMMS opcodes.
    • +
    • mesa: Fix windows build (uint -> GLuint).
    • +
    • scons: Revamp how to specify targets to build.
    • +
    • scons: Fix MinGW cross-compilation.
    • +
    • scons: Some pipe drivers are not portable for MSVC
    • +
    • scons: Restore x11 tool behavior for backwards compatability.
    • +
    • scons: Disable python state tracker when swig is not present.
    • +
    • r600g: List recently added files in SConscript.
    • +
    • scons: Add aliases for several pipe drivers.
    • +
    • scons: i915 can't build on MSVC either.
    • +
    • scons: Propagate installation targets.
    • +
    • xorg/vmwgfx: Add missing source file to SConscript.
    • +
    • st/xorg: Add missing n to error message.
    • +
    • st/xorg: Detect libkms with scons too.
    • +
    • xorg/vmwgfx: Link libkms when available.
    • +
    • r600g: Swap the util_blitter_destroy call order.
    • +
    • gallivm: Allocate TEMP/OUT arrays only once.
    • +
    • libgl-gdi: Allow to pick softpipe/llvmpipe on runtime.
    • +
    • scons: Use inline wrap helpers more consistently.
    • +
    • svga: Use consistent hexadecimal representation on debug output.
    • +
    • scons: Alias for svga
    • +
    • wgl: Stub WGL_ARB_pbuffer support.
    • +
    • wgl: More complete WGL_ARB_pbuffer support.
    • +
    • svga: Silence debug printf.
    • +
    • scons: Move MSVS_VERSION option to common module.
    • +
    • vega: Remove extraneous ;
    • +
    • retrace: Some fixes.
    • +
    • util: C++ safe.
    • +
    • wgl: Fix double free. Remove dead code.
    • +
    • util: Plug leaks in util_destroy_gen_mipmap.
    • +
    • util: __builtin_frame_address() doesn't work on mingw.
    • +
    • util: Don't try to use imagehlp on mingw.
    • +
    • wgl: Unreference the current framebuffer after the make_current call.
    • +
    • WIN32_THREADS -> WIN32
    • +
    • mapi: Hack to avoid vgCreateFont being generated as vgCreateFontA.
    • +
    • wgl: Fix visual's buffer_mask configuration.
    • +
    • mesa: Temporary hack to prevent stack overflow on windows
    • +
    • mesa: Bump the number of bits in the register index.
    • +
    • llvmpipe: Plug fence leaks.
    • +

    + +

    Julien Cristau (1): +

      +
    • Makefile: don't include the same files twice in the tarball
    • +

    + +

    Keith Whitwell (89): +

      +
    • llvmpipe: brackets around macro arg
    • +
    • llvmpipe: remove duplicate code
    • +
    • llvmpipe: return zero from floor_pot(zero)
    • +
    • gallivm: make lp_build_sample_nop public
    • +
    • llvmpipe: add LP_PERF flag to disable various aspects of rasterization
    • +
    • llvmpipe: add DEBUG_FS to dump variant information
    • +
    • llvmpipe: use llvm for attribute interpolant calculation
    • +
    • graw: add frag-face shader
    • +
    • llvmpipe: fix flatshading in new line code
    • +
    • draw: don't apply flatshading to clipped tris with <3 verts
    • +
    • llvmpipe: handle FACING interpolants in line and point setup
    • +
    • llvmpipe: handle up to 8 planes in triangle binner
    • +
    • llvmpipe: make debug_fs_variant respect variant->nr_samplers
    • +
    • gallivm: don't apply zero lod_bias
    • +
    • llvmpipe: fail gracefully on oom in scene creation
    • +
    • llvmpipe: avoid overflow in triangle culling
    • +
    • gallivm: special case conversion 4x4f to 1x16ub
    • +
    • gallivm: round rather than truncate in new 4x4f->1x16ub conversion path
    • +
    • llvmpipe: clean up setup_tri a little
    • +
    • llvmpipe: add rast_tri_4_16 for small lines and points
    • +
    • llvmpipe: fix off-by-one in tri_16
    • +
    • llvmpipe: defer attribute interpolation until after mask and ztest
    • +
    • llvmpipe: use alloca for fs color outputs
    • +
    • llvmpipe: store zero into all alloca'd values
    • +
    • llvmpipe: dump fragment shader ir and asm when LP_DEBUG=fs
    • +
    • gallivm: specialized x8z24 depthtest path
    • +
    • gallivm: prefer blendvb for integer arguments
    • +
    • gallivm: simpler uint8->float conversions
    • +
    • llvmpipe: try to be sensible about whether to branch after mask updates
    • +
    • llvmpipe: clean up shader pre/postamble, try to catch more early-z
    • +
    • llvmpipe: simplified SSE2 swz/unswz routines
    • +
    • llvmpipe: try to do more of rast_tri_3_16 with intrinsics
    • +
    • llvmpipe: add debug helpers for epi32 etc
    • +
    • llvmpipe: try to keep plane c values small
    • +
    • llvmpipe: fix typo in last commit
    • +
    • gallium: move sse intrinsics debug helpers to u_sse.h
    • +
    • r600g: add missing file to sconscript
    • +
    • gallivm: don't branch on KILLs near end of shader
    • +
    • Revert "llvmpipe: try to keep plane c values small"
    • +
    • llvmpipe: make sure intrinsics code is guarded with PIPE_ARCH_SSE
    • +
    • llvmpipe: don't try to emit non-existent color outputs
    • +
    • r600/drm: fix segfaults in winsys create failure path
    • +
    • r600g: emit hardware linewidth
    • +
    • r600g: handle absolute modifier in shader translator
    • +
    • llvmpipe: reintroduce SET_STATE binner command
    • +
    • llvmpipe: don't pass frontfacing as a float
    • +
    • llvmpipe: slightly shrink the size of a binned triangle
    • +
    • llvmpipe: don't store plane.ei value in binned data
    • +
    • gallium: move some intrinsics helpers to u_sse.h
    • +
    • llvmpipe: do plane calculations with intrinsics
    • +
    • llvmpipe: use aligned loads/stores for plane values
    • +
    • llvmpipe: fix non-sse build after recent changes
    • +
    • llvmpipe: check shader outputs are non-null before using
    • +
    • llvmpipe: validate color outputs against key->nr_cbufs
    • +
    • llvmpipe: clean up fields in draw_llvm_variant_key
    • +
    • llvmpipe: remove setup fallback path
    • +
    • llvmpipe: fail cleanly on malloc failure in lp_setup_alloc_triangle
    • +
    • Merge remote branch 'origin/master' into lp-setup-llvm
    • +
    • llvmpipe: remove unused file
    • +
    • llvmpipe: remove unused arg from jit_setup_tri function
    • +
    • Merge branch 'llvm-cliptest-viewport'
    • +
    • draw: make sure viewport gets updated in draw llvm shader
    • +
    • llvmpipe: turn off draw offset/twoside when we can handle it
    • +
    • llvmpipe: avoid generating tri_16 for tris which extend past tile bounds
    • +
    • llvmpipe: guard against NULL task->query pointer
    • +
    • st/mesa: unbind constant buffer when not in use
    • +
    • r600g: propagate usage flags in texture transfers
    • +
    • r600g: propogate resource usage flags to winsys, use to choose bo domains
    • +
    • r600g: use a buffer in GTT as intermediate on texture up and downloads
    • +
    • r600g: remove unused flink, domain fields from r600_resource
    • +
    • r600g: set hardware pixel centers according to gl_rasterization_rules
    • +
    • evergreeng: protect against null constant buffers
    • +
    • r600g: don't call debug_get_bool_option for tiling more than once
    • +
    • evergreeng: respect linewidth state, use integer widths only
    • +
    • evergreeng: set hardware pixelcenters according to gl_rasterization_rules
    • +
    • r600g: avoid recursion with staged uploads
    • +
    • r600g: attempt to turn on DXTn formats
    • +
    • r600g: translate ARR instruction
    • +
    • r600: fix my pessimism about PIPE_TRANSFER_x flags
    • +
    • ws/r600: match bo_busy shared/fence logic in bo_wait
    • +
    • r600g: guard experimental s3tc code with R600_ENABLE_S3TC
    • +
    • r600g: do not try to use staging resource for depth textures
    • +
    • r600g: enforce minimum stride on render target texture images
    • +
    • llvmpipe: fix up twoside after recent changes
    • +
    • llvmpipe: twoside for specular color also
    • +
    • Merge branch 'lp-offset-twoside'
    • +
    • llvmpipe: raise dirty flag on transfers to bound constbuf
    • +
    • llvmpipe: remove misleading debug string
    • +
    • llvmpipe: shortcircuit some calls to set_scene_state
    • +

    + +

    Kenneth Graunke (94): +

      +
    • glsl: Change from has_builtin_signature to has_user_signature.
    • +
    • glsl: Don't print blank (function ...) headers for built-ins.
    • +
    • glsl: Properly handle nested structure types.
    • +
    • glsl/builtins: Fix equal and notEqual builtins.
    • +
    • glsl/builtins: Switch comparison functions to just return an expression.
    • +
    • glsl: Add comments to clarify the types of comparison binops.
    • +
    • glsl: Fix broken handling of ir_binop_equal and ir_binop_nequal.
    • +
    • glsl: "Copyright", not "Constantright"
    • +
    • i965: Fix incorrect batchbuffer size in gen6 clip state command.
    • +
    • i965: Use logical-not when emitting ir_unop_ceil.
    • +
    • glsl: Add front-end support for the "trunc" built-in.
    • +
    • glsl: Refresh autogenerated file builtin_function.cpp.
    • +
    • i965: Use RNDZ for ir_unop_trunc in the new FS.
    • +
    • i965: Correctly emit the RNDZ instruction.
    • +
    • i965: Clean up a warning in the old fragment backend.
    • +
    • glsl: Add a new ir_unop_round_even opcode for GLSL 1.30's roundEven.
    • +
    • glsl: Add front-end support for GLSL 1.30's roundEven built-in.
    • +
    • i965: Add support for ir_unop_round_even via the RNDE instruction.
    • +
    • glsl: Add support for the 1.30 round() built-in.
    • +
    • glsl: Refresh autogenerated file builtin_function.cpp.
    • +
    • glsl: Don't return NULL IR for erroneous bit-shift operators.
    • +
    • i965: Add missing "break" statement.
    • +
    • glsl: Fix copy and paste error in ast_bit_and node creation.
    • +
    • glsl: Regenerate parser files.
    • +
    • i965: Remove unused variable.
    • +
    • glsl: Remove useless ir_shader enumeration value.
    • +
    • mesa: Remove FEATURE_ARB_shading_language_120 macro.
    • +
    • glcpp: Return NEWLINE token for newlines inside multi-line comments.
    • +
    • glcpp: Refresh autogenerated lexer file.
    • +
    • glsl: Add support for GLSL 1.30's modf built-in.
    • +
    • glsl: Refresh autogenerated file builtin_function.cpp.
    • +
    • generate_builtins.py: Output large strings as arrays of characters.
    • +
    • Refresh autogenerated file builtin_function.cpp.
    • +
    • glsl: Fix constant component count in vector constructor emitting.
    • +
    • Fix build on systems where "python" is python 3.
    • +
    • i965: Add bit operation support to the fragment shader backend.
    • +
    • glsl: Remove unused ARRAY_SIZE macro.
    • +
    • glsl/builtins: Rename 'x' to 'y_over_x' in atan(float) implementation.
    • +
    • glsl/builtins: Clean up some ugly autogenerated code in atan.
    • +
    • Refresh autogenerated file builtin_function.cpp.
    • +
    • glsl: Don't print a useless space at the end of an S-Expression list.
    • +
    • ir_reader: Return a specific ir_dereference variant.
    • +
    • ir_reader: Remove useless error check.
    • +
    • ir_reader: Fix some potential NULL pointer dereferences.
    • +
    • ir_dead_functions: Actually free dead functions and signatures.
    • +
    • glsl: Remove unnecessary "unused variable" warning suppression.
    • +
    • glsl: Remove GLSL_TYPE_FUNCTION define.
    • +
    • glsl: Convert glsl_type::base_type from #define'd constants to an enum.
    • +
    • glsl: Rework reserved word/keyword handling in the lexer.
    • +
    • glsl: Add new keywords and reserved words for GLSL 1.30.
    • +
    • glsl: Add support for the 'u' and 'U' unsigned integer suffixes.
    • +
    • glsl: Refresh autogenerated lexer and parser files.
    • +
    • generate_builtins.py: Fix inconsistent use of tabs and spaces warning.
    • +
    • glsl: Implement the asinh, acosh, and atanh built-in functions.
    • +
    • glsl: Refresh autogenerated file builtin_function.cpp.
    • +
    • glsl: Add constant expression handling for asinh, acosh, and atanh.
    • +
    • glsl: Remove unused and out of date Makefile.am.
    • +
    • glsl: Rename various ir_* files to lower_* and opt_*.
    • +
    • glcpp: Define GL_FRAGMENT_PRECISION_HIGH if GLSL version >= 1.30.
    • +
    • Refresh autogenerated glcpp parser.
    • +
    • glsl: Fix constant expression handling for <, >, <=, >= on vectors.
    • +
    • glsl: Unconditionally define GL_FRAGMENT_PRECISION_HIGH in ES2 shaders.
    • +
    • Regenerate glcpp parser.
    • +
    • glsl: Reimplement the "cross" built-in without ir_binop_cross.
    • +
    • Refresh autogenerated file builtin_function.cpp.
    • +
    • glsl: Remove the ir_binop_cross opcode.
    • +
    • glsl: Refactor get_num_operands.
    • +
    • glsl: Simplify a type check by using type->is_integer().
    • +
    • glsl: Combine many instruction lowering passes into one.
    • +
    • mesa: Fix glGet of ES2's GL_MAX_*_VECTORS properties.
    • +
    • glsl: Don't inline function prototypes.
    • +
    • glsl: Use do_common_optimization in the standalone compiler.
    • +
    • glsl: Add a virtual as_discard() method.
    • +
    • glsl: Refactor out cloning of function prototypes.
    • +
    • glsl: Lazily import built-in function prototypes.
    • +
    • glsl: Remove anti-built-in hacks from the print visitor.
    • +
    • glsl/linker: Free any IR discarded by optimization passes.
    • +
    • glsl: Add an optimization pass to simplify discards.
    • +
    • glsl: Add a lowering pass to move discards out of if-statements.
    • +
    • glsl: Remove "discard" support from lower_jumps.
    • +
    • glsl: Add comments to lower_jumps (from the commit message).
    • +
    • ir_print_visitor: Print out constant structure values.
    • +
    • glsl: Factor out code which emits a new function into the IR stream.
    • +
    • symbol_table: Add support for adding a symbol at top-level/global scope.
    • +
    • glsl: Properly add functions during lazy built-in prototype importing.
    • +
    • glcpp: Don't emit SPACE tokens in conditional_tokens production.
    • +
    • Refresh autogenerated glcpp parser.
    • +
    • glsl: Clean up code by adding a new is_break() function.
    • +
    • glsl: Consider the "else" branch when looking for loop breaks.
    • +
    • Remove OES_compressed_paletted_texture from the ES2 extension list.
    • +
    • glsl/builtins: Compute the correct value for smoothstep(vec, vec, vec).
    • +
    • glsl: Support if-flattening beyond a given maximum nesting depth.
    • +
    • i965: Flatten if-statements beyond depth 16 on pre-gen6.
    • +
    • i965: Internally enable GL_NV_blend_square on ES2.
    • +

    + +

    Kristian Høgsberg (16): +

      +
    • glx: Hold on to drawables if we're just switching to another context
    • +
    • intel: Fix GL_ARB_shading_language_120 commit
    • +
    • dri2: Make createImageFromName() take a __DRIscreen instead of __DRIcontext
    • +
    • glx: Invalidate buffers after binding a drawable
    • +
    • dri: Pass the __DRIscreen and the __DRIscreen private back to image lookup
    • +
    • glx: Only remove drawables from the hash when we actually delete them
    • +
    • gles2: Add GL_EXT_texture_format_BGRA8888 support
    • +
    • Get rid of GL/internal/glcore.h
    • +
    • gl: Remove unused GLcontextModes fields
    • +
    • Rename GLvisual and __GLcontextModes to struct gl_config
    • +
    • Drop GLframebuffer typedef and just use struct gl_framebuffer
    • +
    • Drop GLcontext typedef and use struct gl_context instead
    • +
    • Drop the "neutral" tnl module
    • +
    • Only install vtxfmt tables for OpenGL
    • +
    • i965: Don't write mrf assignment for pointsize output
    • +
    • docs: Fix MESA_drm_image typo
    • +

    + +

    Krzysztof Smiechowicz (1): +

      +
    • nvfx: Pair os_malloc_aligned() with os_free_aligned().
    • +

    + +

    Luca Barbieri (84): +

      +
    • auxiliary: fix unintended fallthrough
    • +
    • glsl: add pass to lower variable array indexing to conditional assignments
    • +
    • auxiliary: fix depth-only and stencil-only clears
    • +
    • gallium: avoid the C++ keyword "template" in sw_winsys.h
    • +
    • softpipe: make z/s test always pass if no zsbuf, instead of crashing
    • +
    • tgsi: add switch/case opcodes to tgsi_opcode_tmp.h
    • +
    • softpipe: fix whitespace
    • +
    • d3d1x: add new Direct3D 10/11 COM state tracker for Gallium
    • +
    • d3d1x: add blob and signature extraction APIs
    • +
    • d3d1x: fix compilation with recent Wine versions installed
    • +
    • d3d1x: add missing file
    • +
    • d3d1x: actually enable and fix blob apis
    • +
    • d3d1x: fix build with compilers other than GCC 4.5
    • +
    • d3d1x: add template parameters to base class ctor calls for GCC 4.4
    • +
    • d3d1x: fix GCC 4.1/4.2 build
    • +
    • d3d1x: ignore errors while building docs
    • +
    • d3d1x: attempt to fix/workaround bug #30322
    • +
    • nvfx: remove gl_PointCoord hack
    • +
    • glx: decouple dri2.c and GLX, fixing Gallium EGL and d3d1x build
    • +
    • winsys: automatically build sw winsys needed by EGL and d3d1x
    • +
    • d3d1x: don't build progs automatically
    • +
    • d3d1x: add missing memory barrier
    • +
    • d3d1x: link with CXXFLAGS
    • +
    • d3d1x: fix cf analysis
    • +
    • d3d1x: fix warning
    • +
    • d3d1x: fix segfault when hashing
    • +
    • d3d1x: destroy native_display on adapter destruction
    • +
    • d3d1x: fix GUID declarations
    • +
    • d3d1x: redesign the HWND resolver interface
    • +
    • d3d1x: fix API name
    • +
    • d3d1x: define GUIDs in the normal way
    • +
    • d3d1x: add Wine dlls (tri, tex working, but no other testing)
    • +
    • d3d1x: properly reference count the backend
    • +
    • d3d1x: fix deadlocks on non-recursive mutex
    • +
    • d3d1x: bind NULL CSOs before destroying default CSOs on context dtor
    • +
    • d3d1x: initialize the mutex
    • +
    • d3d1x: autogenerate shader enums and text from def files
    • +
    • d3d1x: s/tpf/sm4/g
    • +
    • d3d1x: normalize whitespace
    • +
    • d3d1x: remove specstrings
    • +
    • d3d1x: minifix
    • +
    • d3d1x: rename context params
    • +
    • d3d11: rename screen params
    • +
    • d3d1x: rename params in misc and objects
    • +
    • d3d1x: rename parameters in dxgi
    • +
    • d3d11: obliterate IDL parameter names
    • +
    • d3d1x: remove specstrings.h include
    • +
    • d3d1x: flush the pipe context when presenting
    • +
    • d3d1x: remove another include specstrings.h
    • +
    • d3d1x: flush properly
    • +
    • d3d1x: add missing guid.cpp
    • +
    • d3d1x: fix build without system EGL/egl.h
    • +
    • d3d1x: add autogenerated files as prerequisites, so make builds them
    • +
    • d3d1x: obliterate IDL parameter names from d3d10.idl from Wine too
    • +
    • d3d1x: add shader dumping
    • +
    • d3d1x: add untested support for geometry shader translation
    • +
    • d3d1x: don't assert on unsupported resource types
    • +
    • d3d1x: fix CheckMultisampleQualityLevels
    • +
    • d3d1x: draw to the correct buffer
    • +
    • d3d1x: fix linking of dxbc2tgsi
    • +
    • nvfx: allow setting NULL constant buffers
    • +
    • nvfx: add RGB framebuffer format support in addition to BGR
    • +
    • d3d1x: don't crash on drivers not supporting vertex or geometry sampling
    • +
    • d3d1x: assert if X visual is not among enumerated visuals
    • +
    • d3d1x: stop using GLX in demos, just use the default visual
    • +
    • d3d1x: CRLF -> LF in progs
    • +
    • mesa: make makedepend an hard requirement
    • +
    • gallium: add $(PROGS_DEPS) as dependencies for $(PROGS)
    • +
    • d3d1x: fix parallel build
    • +
    • d3d1x: add private gitignore file
    • +
    • d3d1x: fix progs linking if not all EGL platforms are enabled
    • +
    • d3d1x: link progs with CXXFLAGS
    • +
    • d3d11: advertise IDXGIDevice1, not just IDXGIDevice
    • +
    • d3d11: ignore StructureByteStride
    • +
    • d3d1x: link to libdrm for X11 platform too
    • +
    • ureg: support centroid interpolation
    • +
    • d3d1x: support centroid interpolation
    • +
    • d3d1x: properly support specifying MipLevels as 0
    • +
    • d3d1x: put proper calling convention in headers, fixes 64-bit builds
    • +
    • d3d1x: rework DXGI for occlusion testing and default width/height
    • +
    • d3d1x: fix Map
    • +
    • d3d11: fix reference counting so devices get freed
    • +
    • d3d1x: work around crash in widl
    • +
    • glsl: Unroll loops with conditional breaks anywhere (not just the end)
    • +

    + +

    Lucas Stach (1): +

      +
    • nvfx: fill PIPE_CAP_PRIMITIVE_RESTART and PIPE_CAP_SHADER_STENCIL_EXPORT
    • +

    + +

    Marek Olšák (100): +

      +
    • r300g: prevent creating multiple winsys BOs for the same handle
    • +
    • r300g/swtcl: fix CS overrun
    • +
    • st/mesa: fix assertion failure in GetTexImage for cubemaps
    • +
    • util: make calling remove_from_list multiple times in a row safe
    • +
    • r300g: fixup long-lived BO maps being incorrectly unmapped when flushing
    • +
    • r300g: make accessing map_list and buffer_handles thread-safe
    • +
    • r300g: fix a copy-paste typo for logging
    • +
    • r300g: fix the border color for every format other than PIPE_FORMAT_B8G8R8A8
    • +
    • Build r300g by default
    • +
    • util: fix util_pack_color for B4G4R4A4
    • +
    • r300g: fix macrotiling on R350
    • +
    • r300g: code cleanups
    • +
    • r300/compiler: fix projective mapping of 2D NPOT textures
    • +
    • r300/compiler: do not use copy propagation if SaturateMode is used
    • +
    • r300/compiler: fix shadow sampling with swizzled coords
    • +
    • r300g: add support for 3D NPOT textures without mipmapping
    • +
    • r300g: fix swizzling of texture border color
    • +
    • configure.ac: look for libdrm_radeon before building gallium/r300,r600
    • +
    • configure.ac: do not build xorg-r300g by default
    • +
    • Makefile: ensure Gallium's Makefile.xorg and SConscript.dri are in the tarball
    • +
    • r300g: add support for formats beginning with X, like X8R8G8B8
    • +
    • r300g: fix conditional rendering in non-wait path
    • +
    • r300g: add support for R8G8 colorbuffers
    • +
    • r300g: add support for L8A8 colorbuffers
    • +
    • update release notes for Gallium
    • +
    • r300g: fix microtiling for 16-bits-per-channel formats
    • +
    • r300g: do not print get_param errors in non-debug build
    • +
    • r300g: say no to PIPE_CAP_STREAM_OUTPUT and PIPE_CAP_PRIMITIVE_RESTART
    • +
    • mesa: allow FBO attachments of formats LUMINANCE, LUMINANCE_ALPHA, and INTENSITY
    • +
    • r300g: fix texture border for 16-bits-per-channel formats
    • +
    • st/mesa: support RGBA16 and use it for RGBA12 as well
    • +
    • r300g: add a default channel ordering of texture border for unhandled formats
    • +
    • r300g: mention ATI in the renderer string
    • +
    • r300g: rename has_hyperz -> can_hyperz
    • +
    • r300g: turn magic numbers into names in the hyperz code
    • +
    • gallium: add CAPs for indirect addressing and lower it in st/mesa when needed
    • +
    • tgsi: fill out CAPs for indirect addressing
    • +
    • i915g: fill out CAPs for indirect addressing
    • +
    • i965g: fill out CAPs for indirect addressing
    • +
    • nv50: fill out CAPs for indirect addressing
    • +
    • nvfx: fill out CAPs for indirect addressing
    • +
    • r300g: fill out CAPs for indirect addressing
    • +
    • r600g: fill out CAPs for indirect addressing
    • +
    • svga: fill out CAPs for indirect addressing
    • +
    • r300g: fix texture border color for all texture formats
    • +
    • r300g: clean up redundancy in draw functions
    • +
    • r300g: return shader caps from Draw for SWTCL vertex shaders
    • +
    • r300g: remove the hack with OPCODE_RET
    • +
    • r300g: print FS inputs uninitialized due to hardware limits to stderr
    • +
    • r300g: fix rendering with no vertex elements
    • +
    • st/mesa: enable ARB_explicit_attrib_location and EXT_separate_shader_objects
    • +
    • docs: add GL 4.1 status
    • +
    • gallium: add PIPE_SHADER_CAP_SUBROUTINES
    • +
    • st/mesa: set MaxUniformComponents
    • +
    • u_blitter: use PIPE_TRANSFER_DISCARD to prevent cpu/gpu stall
    • +
    • r300/compiler: fix rc_rewrite_depth_out for it to work with any instruction
    • +
    • r300/compiler: remove duplicate function rc_mask_to_swz
    • +
    • r300/compiler: add a function for swizzling a mask
    • +
    • r300/compiler: move util functions to radeon_compiler_util
    • +
    • u_blitter: interpolate clear color using a GENERIC varying instead of COLOR
    • +
    • st/mesa: fix texture border color for RED and RG base formats
    • +
    • util: rename u_mempool -> u_slab
    • +
    • r300g: fix texture border color once again
    • +
    • r300/compiler: implement and lower OPCODE_CLAMP
    • +
    • ir_to_mesa: Add support for conditional discards.
    • +
    • r300g: fix texture swizzling with compressed textures on r400-r500
    • +
    • r300g: disable ARB_texture_swizzle if S3TC is enabled on r3xx-only
    • +
    • r300g: fix up cubemap texture offset computation
    • +
    • r300/compiler: disable the swizzle lowering pass in vertex shaders
    • +
    • r300g: fix build
    • +
    • r300g: use internal BO handle for add_buffer and write_reloc
    • +
    • r300g: implement simple transfer_inline_write for buffers
    • +
    • mesa, st/mesa: fix gl_FragCoord with FBOs in Gallium
    • +
    • r300g: fix pointer arithmetic with void* in transfer_inline_write
    • +
    • r300g: do not remove unused constants if we are not near the limit
    • +
    • r300g: add capability bit index_bias_supported
    • +
    • r300g: one more r500_index_bias_supported leftover
    • +
    • r300g: do not use the index parameter in set_constant_buffer
    • +
    • r300g: cleanup winsys
    • +
    • r300g: optimize looping over atoms
    • +
    • st/mesa: initialize key in st_vp_varient
    • +
    • u_blitter: use util_is_format_compatible in the assert
    • +
    • r300g: cache packet dwords of 3D_LOAD_VBPNTR in a command buffer if possible
    • +
    • r300g: validate buffers only if any of bound buffers is changed
    • +
    • r300g: also revalidate the SWTCL vertex buffer after its reallocation
    • +
    • r300/compiler: don't terminate regalloc if we surpass max temps limit
    • +
    • r300/compiler: add a function to query program stats (alu, tex, temps..)
    • +
    • r300/compiler: cleanup rc_run_compiler
    • +
    • r300/compiler: do not print pair/tex/presub program stats for vertex shaders
    • +
    • r300/compiler: handle DPH and XPD in rc_compute_sources_for_writemask
    • +
    • r300/compiler: make lowering passes possibly use up to two less temps
    • +
    • r300/compiler: remove at least unused immediates if externals cannot be removed
    • +
    • r300/compiler: fix LIT in VS
    • +
    • r300/compiler: fix swizzle lowering with a presubtract source operand
    • +
    • r300g: fix rendering with a vertex attrib having a zero stride
    • +
    • r300g: finally fix the texture corruption on r3xx-r4xx
    • +
    • r300g/swtcl: re-enable LLVM
    • +
    • r300g: mark vertex arrays as dirty after a buffer_offset change
    • +
    • mesa: fix texel store functions for some float formats
    • +
    • r300/compiler: disable the rename_regs pass for loops
    • +

    + +

    Mario Kleiner (1): +

      +
    • mesa/r300classic: Fix dri2Invalidate/radeon_prepare_render for page flipping.
    • +

    + +

    Mathias Fröhlich (3): +

      +
    • r300g: Avoid returning values in a static array, fixing a potential race
    • +
    • r600g: Only compare active vertex elements
    • +
    • st/mesa: Set PIPE_TRANSFER_DISCARD for GL_MAP_INVALIDATE_RANGE/BUFFFER_BIT
    • +

    + +

    Michal Krol (10): +

      +
    • svga: Fix relative addressing translation for pixel shaders.
    • +
    • svga: Integer constant register file has a separate namespace.
    • +
    • tgsi/exec: Cleanup the remaining arithmetic instructions.
    • +
    • tgsi/exec: Get rid of obsolete condition codes.
    • +
    • tgsi/build: Reduce interface clutter.
    • +
    • graw/gdi: Initial commit.
    • +
    • scons: Hook-up graw-gdi target.
    • +
    • graw/gdi: Fix window dimensions.
    • +
    • os: Open file streams in binary mode.
    • +
    • graw: Export graw_save_surface_to_file().
    • +

    + +

    Nicolas Kaiser (26): +

      +
    • swrast: remove duplicated include
    • +
    • egl: remove duplicated include
    • +
    • gallium/rtasm: remove duplicated include
    • +
    • gallium/util: remove duplicated include
    • +
    • gallium/i915: remove duplicated include
    • +
    • gallium/llvmpipe: remove duplicated include
    • +
    • gallium/softpipe: remove duplicated include
    • +
    • gallium/st: remove duplicated includes
    • +
    • gallium/winsys: remove duplicated include
    • +
    • glx: remove duplicated include
    • +
    • dri/common: remove duplicated include
    • +
    • dri/i810: remove duplicated include
    • +
    • dri/i915: remove duplicated include
    • +
    • dri/i965: remove duplicated include
    • +
    • dri/intel: remove duplicated include
    • +
    • dri/mga: remove duplicated include
    • +
    • dri/r128: remove duplicated include
    • +
    • dri/r300: remove duplicated include
    • +
    • dri/r600: remove duplicated include
    • +
    • dri/radeon: remove duplicated includes
    • +
    • dri/savage: remove duplicated include
    • +
    • main: remove duplicated includes
    • +
    • math: remove duplicated includes
    • +
    • st: remove duplicated include
    • +
    • i965g: use Elements macro instead of manual sizeofs
    • +
    • nv50: fix always true conditional in shader optimization
    • +

    + +

    Orion Poplawski (1): +

      +
    • osmesa: link against libtalloc
    • +

    + +

    Owen W. Taylor (1): +

      +
    • r600g: Fix location for clip plane registers
    • +

    + +

    Peter Clifton (3): +

      +
    • intel: Fix emit_linear_blit to use DWORD aligned width blits
    • +
    • intel: Add assert check for blitting alignment.
    • +
    • meta: Mask Stencil.Clear against stencilMax in _mesa_meta_Clear
    • +

    + +

    Robert Hooker (2): +

      +
    • intel: Add a new B43 pci id.
    • +
    • egl_dri2: Add missing intel chip ids.
    • +

    + +

    Roland Scheidegger (16): +

      +
    • gallivm: fix copy&paste bug
    • +
    • gallivm: don't use URem/UDiv when calculating offsets for blocks
    • +
    • gallivm: optimize yuv decoding
    • +
    • gallivm: fix trunc/itrunc comment
    • +
    • gallivm: faster iround implementation for sse2
    • +
    • gallivm: replace sub/floor/ifloor combo with ifloor_fract
    • +
    • gallivm: optimize some tex wrap mode calculations a bit
    • +
    • gallivm: more linear tex wrap mode calculation simplification
    • +
    • gallivm: avoid unnecessary URem in linear wrap repeat case
    • +
    • gallivm: optimize soa linear clamp to edge wrap mode a bit
    • +
    • gallivm: make use of new iround code in lp_bld_conv.
    • +
    • gallivm: fix different handling of [non]normalized coords in linear soa path
    • +
    • gallivm: only use lp_build_conv 4x4f -> 1x16 ub fastpath with sse2
    • +
    • r200: fix r200 large points
    • +
    • mesa: remove unneeded DD_POINT_SIZE and DD_LINE_WIDTH tricaps
    • +
    • gallium: support for array textures and related changes
    • +

    + +

    Shuang He (1): +

      +
    • mesa: allow GLfixed arrays for OpenGL ES 2.0
    • +

    + +

    Stephan Schmid (1): +

      +
    • r600g: fix relative addressing when splitting constant accesses
    • +

    + +

    Thomas Hellstrom (21): +

      +
    • st/xorg: Don't try to use option values before processing options
    • +
    • xorg/vmwgfx: Make vmwarectrl work also on 64-bit servers
    • +
    • st/xorg: Add a customizer option to get rid of annoying cursor update flicker
    • +
    • xorg/vmwgfx: Don't hide HW cursors when updating them
    • +
    • st/xorg: Don't try to remove invalid fbs
    • +
    • st/xorg: Fix typo
    • +
    • st/xorg, xorg/vmwgfx: Be a bit more frendly towards cross-compiling environments
    • +
    • st/xorg: Fix compilation errors for Xservers compiled without Composite
    • +
    • st/xorg: Don't use deprecated x*alloc / xfree functions
    • +
    • xorg/vmwgfx: Don't use deprecated x*alloc / xfree functions
    • +
    • st/xorg: Fix compilation for Xservers >= 1.10
    • +
    • mesa: Make sure we have the talloc cflags when using the talloc headers
    • +
    • egl: Add an include for size_t
    • +
    • mesa: Add talloc includes for gles
    • +
    • st/egl: Fix build for include files in nonstandard places
    • +
    • svga/drm: Optionally resolve calls to powf during link-time
    • +
    • gallium/targets: Trivial crosscompiling fix
    • +
    • st/xorg: Add a function to flush pending rendering and damage
    • +
    • gallium/targets/xorg-vmwgfx: Xv fixes
    • +
    • xorg/vmwgfx: Flush even if we don't autopaint the color key
    • +
    • xorg/vmwgfx: Don't clip video to viewport
    • +

    + +

    Tilman Sauerbeck (35): +

      +
    • r600g: Fixed a bo leak in r600_blit_state_ps_shader().
    • +
    • r600g: Use clamped math for RCP and RSQ.
    • +
    • r600g: Formatting fixes.
    • +
    • r600g: Added DB_SHADER_CONTROL defines.
    • +
    • r600g: Only set PA_SC_EDGERULE on rv770 and greater.
    • +
    • r600g: Enable PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED.
    • +
    • r600g: Fixed the shift in S_02880C_KILL_ENABLE.
    • +
    • glsl2: Empty functions can be inlined.
    • +
    • glsl2: Fixed cloning of ir_call error instructions.
    • +
    • r600g: Added support for TGSI_SEMANTIC_FACE.
    • +
    • gallium/docs: Fixed a typo in the SCS opcode description.
    • +
    • r600g: Honour destination operand's writemask in the SCS implementation.
    • +
    • r600g: Implemented the Z and W component write for the SCS opcode.
    • +
    • python/tests: Fixed tri.py for API and TGSI syntax changes.
    • +
    • r600g: Removed debug code.
    • +
    • gallium/docs: The RET opcode may appear anywhere in a subroutine.
    • +
    • r600g: Destroy the blitter.
    • +
    • r600g: Fixed two texture surface leaks in r600_blit_uncompress_depth().
    • +
    • r600g: Cleaned up index buffer reference handling in the draw module.
    • +
    • r600g: Fixed r600_vertex_element leak.
    • +
    • r600g: Added r600_pipe_shader_destroy().
    • +
    • r600g: Also clear bc data when we're destroying a shader.
    • +
    • r600g: In radeon_bo(), call LIST_INITHEAD early.
    • +
    • r600g: Destroy the blitter.
    • +
    • r600g: Removed unused 'ptr' argument from radeon_bo().
    • +
    • r600g: Made radeon_bo_pb_map_internal() actually call radeon_bo_map().
    • +
    • r600g: Fixed unmap condition in radeon_bo_pb_destroy().
    • +
    • r600g: Made radeon_bo::map_count signed.
    • +
    • r600g: We don't support PIPE_CAP_PRIMITIVE_RESTART.
    • +
    • r600g: Delete custom_dsa_flush on shutdown.
    • +
    • r600g: Fixed two memory leaks in winsys.
    • +
    • r600g: Destroy the winsys in r600_destroy_screen().
    • +
    • st/mesa: Reset the index buffer before destroying the pipe context.
    • +
    • st/mesa: Reset the constant buffers before destroying the pipe context.
    • +
    • r600g: Removed duplicated call to tgsi_split_literal_constant().
    • +

    + +

    Timo Wiren (1): +

      +
    • Fix typos in comments and debug output strings.
    • +

    + +

    Tom Fogal (3): +

      +
    • Implement x86_64 atomics for compilers w/o intrinsics.
    • +
    • Prefer intrinsics to handrolled atomic ops.
    • +
    • Revert "Prefer intrinsics to handrolled atomic ops."
    • +

    + +

    Tom Stellard (32): +

      +
    • r300/compiler: Refactor the pair instruction data structures
    • +
    • r300g: Always try to build libr300compiler.a
    • +
    • r300/compiler: Fix two mistakes in the presubtract optimization pass.
    • +
    • r300/compiler: Add more helper functions for iterating through sources
    • +
    • r300/compiler: Print immediate values after "dead constants" pass
    • +
    • r300/compiler: radeon_remove_constants.c: fix indentation
    • +
    • r300/compiler: Use rc_for_all_reads_src() in "dead constants" pass
    • +
    • r300/compiler: Fix segfault in error path
    • +
    • r300/compiler: Don't use rc_error() unless the error is unrecoverable
    • +
    • r300/compiler: Don't merge instructions that write output regs and ALU result
    • +
    • r300/compiler: Create a helper function for merging presubtract sources
    • +
    • r300/compiler: Fix incorrect assumption
    • +
    • r300/compiler: Clear empty registers after constant folding
    • +
    • r300/compiler: Add a new function for more efficient dataflow analysis
    • +
    • r300g: Add new debug option for logging vertex/fragment program stats
    • +
    • r300/compiler: Use rc_get_readers_normal() for presubtract optimizations
    • +
    • r300/compiler: Don't clobber presubtract sources during optimizations
    • +
    • r300/compiler: Don't track readers into an IF block.
    • +
    • r300/compiler: Make sure presubtract sources use supported swizzles
    • +
    • r300/compiler: Fix register allocator's handling of loops
    • +
    • r300/compiler: Fix instruction scheduling within IF blocks
    • +
    • r300/compiler: Use zero as the register index for unused sources
    • +
    • r300/compiler: Ignore alpha dest register when replicating the result
    • +
    • r300/compiler: Add rc_get_readers()
    • +
    • r300/compiler: Handle BREAK and CONTINUE in rc_get_readers()
    • +
    • r300/compiler: Track readers through branches in rc_get_readers()
    • +
    • r300/compiler: Convert RGB to alpha in the scheduler
    • +
    • r300/compiler: Use presubtract operations as much as possible
    • +
    • r300/compiler: Enable rename_reg pass for r500 cards
    • +
    • r300/compiler: Add a more efficient version of rc_find_free_temporary()
    • +
    • r300/compiler: Don't allow presubtract sources to be remapped twice
    • +
    • r300/compiler: Fix black terrain in Civ4
    • +

    + +

    Victor Tseng (1): +

      +
    • egl/i965: include inline_wrapper_sw_helper.h
    • +

    + +

    Viktor Novotný (6): +

      +
    • dri/nouveau: Import headers from rules-ng-ng
    • +
    • dri/nouveau: nv04: Use rules-ng-ng headers
    • +
    • dri/nouveau: nv10: Use rules-ng-ng headers
    • +
    • dri/nouveau nv20: Use rules-ng-ng headers
    • +
    • dri/nouveau: Remove nouveau_class.h, finishing switch to rules-ng-ng headers
    • +
    • dri/nouveau: Clean up magic numbers in get_rt_format
    • +

    + +

    Vinson Lee (214): +

      +
    • llvmpipe: Remove unnecessary header.
    • +
    • r600g: Remove unnecessary headers.
    • +
    • mesa: Include missing header in program.h.
    • +
    • glsl: Fix 'format not a string literal and no format arguments' warning.
    • +
    • r600g: Silence uninitialized variable warning.
    • +
    • r600g: Silence uninitialized variable warning.
    • +
    • nvfx: Silence uninitialized variable warnings.
    • +
    • r600g: Silence uninitialized variable warning.
    • +
    • r600g: Silence uninitialized variable warning.
    • +
    • r600g: Silence uninitialized variable warning.
    • +
    • r600g: Silence unused variable warning.
    • +
    • nv50: Update files in SConscript to match Makefile.
    • +
    • nv50: Remove unnecessary headers.
    • +
    • nv50: Silence uninitialized variable warning.
    • +
    • nv50: Silence uninitialized variable warning.
    • +
    • nv50: Silence uninitialized variable warning.
    • +
    • gallivm: Remove unnecessary headers.
    • +
    • draw: Remove unnecessary header.
    • +
    • nv50: Silence uninitialized variable warnings.
    • +
    • nv50: Fix 'control reaches end of non-void function' warning.
    • +
    • mesa/st: Silence uninitialized variable warning.
    • +
    • gallivm: Remove unnecessary header.
    • +
    • r600g: Remove unnecessary header.
    • +
    • r600g: Remove unnecessary headers.
    • +
    • r600g: Fix implicit declaration warning.
    • +
    • r600g: Fix memory leak on error path.
    • +
    • r600g: Silence uninitialized variable warning.
    • +
    • r600g: Silence unused variable warnings.
    • +
    • mesa: bump version to 7.10
    • +
    • ir_to_mesa: Remove unused member array_indexed from struct statevar_element.
    • +
    • mesa: Silence "'valid_texture_object' defined but not used" warning.
    • +
    • x86: Silence unused variable warning on Mac OS X.
    • +
    • glsl: Fix 'control reaches end of non-void function' warning.
    • +
    • nvfx: Remove const qualifer from nvfx_vertprog_translate.
    • +
    • nvfx: Silence uninitialized variable warnings.
    • +
    • r600g: Remove unused variable.
    • +
    • nv50: Silence missing initializer warning.
    • +
    • nv50: Remove dead initialization.
    • +
    • nv50: Remove dead initialization.
    • +
    • tgsi: Remove duplicate case value.
    • +
    • glut: Define markWindowHidden for non-Windows only.
    • +
    • glut: Define eventParser for non-Windows only.
    • +
    • r300g: Silence uninitialized variable warning.
    • +
    • intel: Fix implicit declaration of function '_mesa_meta_Bitmap' warning.
    • +
    • mesa: Remove unnecessary headers.
    • +
    • r600g: Remove unnecessary header.
    • +
    • unichrome: Remove unnecessary header.
    • +
    • intel: Remove unnecessary headers.
    • +
    • r600g: Remove unused variable.
    • +
    • r600g: Disable unused variables.
    • +
    • r600g: Remove unused variable.
    • +
    • r600g: Silence 'control reaches end of non-void function' warning.
    • +
    • r600g: Remove unused variable.
    • +
    • r600g: Remove unused variable.
    • +
    • r600g: Disable unused variables.
    • +
    • intel: Remove unnecessary header.
    • +
    • st/dri: Remove unnecessary header.
    • +
    • r600g: Remove unused variable.
    • +
    • r300g: Remove unused variable.
    • +
    • r600g: Don't return a value in function returning void.
    • +
    • r600g: Remove unused variables.
    • +
    • r600g: Include p_compiler.h instead of malloc.h.
    • +
    • r600g: Silence uninitialized variable warnings.
    • +
    • scons: Add MinGW-w64 prefixes for MinGW build.
    • +
    • dri: Add GET_PROGRAM_NAME definition for Mac OS X.
    • +
    • scons: Add program/sampler.cpp to SCons build.
    • +
    • mesa: Fix printf format warning.
    • +
    • mesa: Fix printf format warning.
    • +
    • mesa: Fix printf format warning.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r600g: Update SConscript.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r600g: Update SConscript.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r600g: Update SConscript.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r600g: Fix SCons build.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r300/compiler: Remove declaration before code.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • glsl: Remove unnecessary header.
    • +
    • savage: Remove unnecessary header.
    • +
    • r600g: Remove unused variable.
    • +
    • r600g: Remove unnecessary headers.
    • +
    • r600g: Fix SCons build.
    • +
    • r600g: Remove unnecessary header.
    • +
    • gallivm: Remove unnecessary header.
    • +
    • r600g: Silence uninitialized variable warning.
    • +
    • r600g: Silence uninitialized variable warning.
    • +
    • r600g: Silence uninitialized variable warning.
    • +
    • i915: Silence unused variable warning in non-debug builds.
    • +
    • i915: Silence unused variable warning in non-debug builds.
    • +
    • i965: Silence unused variable warning on non-debug builds.
    • +
    • i965: Silence unused variable warning on non-debug builds.
    • +
    • i965: Initialize member variables.
    • +
    • r300: Silence uninitialized variable warning.
    • +
    • tdfx: Silence unused variable warning on non-debug builds.
    • +
    • gallivm: Remove unnecessary header.
    • +
    • glsl: Initialize variable in ir_derefence_array::constant_expression_value
    • +
    • mesa: Add missing header to shaderobj.h.
    • +
    • llvmpipe: Return non-zero exit code for lp_test_round failures.
    • +
    • r300/compiler: Remove unused variable.
    • +
    • st/xorg: Fix memory leak on error path.
    • +
    • llvmpipe: Initialize state variable in debug_bin function.
    • +
    • llvmpipe: Initialize variable.
    • +
    • draw: Move loop variable declaration outside for loop.
    • +
    • r600g: Ensure r600_src is initialized in tgsi_exp function.
    • +
    • glsl: Add assert for unhandled ir_shader case.
    • +
    • swrast: Print out format on unexpected failure in _swrast_DrawPixels.
    • +
    • llvmpipe: Remove unnecessary header.
    • +
    • draw: Remove unnecessary header.
    • +
    • gallivm: Silence uninitialized variable warnings.
    • +
    • gallivm: Silence uninitialized variable warnings.
    • +
    • gallivm: Silence uninitialized variable warning.
    • +
    • r300g: Silence uninitialized variable warning.
    • +
    • mesa: Remove unnecessary headers.
    • +
    • r600g: Silence uninitialized variable warnings.
    • +
    • st/mesa: Remove unnecessary header.
    • +
    • mesa: Remove unnecessary header.
    • +
    • egl: Remove unnecessary headers.
    • +
    • swrast: Print out format on unexpected failure in _swrast_ReadPixels.
    • +
    • st/mesa: Silence uninitialized variable warning.
    • +
    • savage: Remove unnecessary header.
    • +
    • st/vega: Remove unnecessary headers.
    • +
    • dri/nouveau: Silence uninitialized variable warning.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • i965: Silence uninitialized variable warning.
    • +
    • i965: Silence uninitialized variable warning.
    • +
    • mesa: Clean up header file inclusion in accum.h.
    • +
    • mesa: Clean up header file inclusion in version.h.
    • +
    • mesa: Clean up header file inclusion in api_loopback.h.
    • +
    • mesa: Clean up header file inclusion in api_validate.h.
    • +
    • mesa: Include mfeatures.h in api_loopback for FEATURE_beginend.
    • +
    • mesa: Include mfeatures.h in api_validate.c for FEATURE_* symbols.
    • +
    • mesa: Clean up header file inclusion in arrayobj.h.
    • +
    • mesa: Clean up header file inclusion in atifragshader.h.
    • +
    • mesa: Clean up header file inclusion in attrib.h.
    • +
    • mesa: Clean up header file inclusion in blend.h.
    • +
    • mesa: Clean up header file inclusion in buffers.h.
    • +
    • mesa: Clean up header file inclusion in colortab.h.
    • +
    • mesa: Clean up header file inclusion in convolve.h.
    • +
    • mesa: Clean up header file inclusion in debug.h.
    • +
    • mesa: Clean up header file inclusion in depth.h.
    • +
    • mesa: Clean up header file inclusion in depthstencil.h.
    • +
    • mesa: Clean up header file inclusion in drawpix.h.
    • +
    • mesa: Clean up header file inclusion in drawtex.h.
    • +
    • mesa: Clean up header file inclusion in enable.h.
    • +
    • mesa: Clean up header file inclusion in extensions.h.
    • +
    • graw: Add struct pipe_surface forward declaration.
    • +
    • mesa: Clean up header file inclusion in fbobject.h.
    • +
    • mesa: Clean up header file inclusion in ffvertex_prog.h.
    • +
    • mesa: Clean up header file inclusion in fog.h.
    • +
    • mesa: Clean up header file inclusion in framebuffer.h.
    • +
    • mesa: Clean up header file inclusion in hint.h.
    • +
    • mesa: Clean up header file inclusion in histogram.h.
    • +
    • mesa: Clean up header file inclusion in image.h.
    • +
    • mesa: Add missing header and forward declarations in dd.h.
    • +
    • mesa: Clean up header file inclusion in light.h.
    • +
    • mesa: Clean up header file inclusion in lines.h.
    • +
    • mesa: Clean up header file inclusion in matrix.h.
    • +
    • mesa: Clean up header file inclusion in multisample.h.
    • +
    • mesa: Clean up header file inclusion in nvprogram.h.
    • +
    • winsys/xlib: Add cygwin to SConscript.
    • +
    • mesa: Clean up header file inclusion in pixel.h.
    • +
    • mesa: Clean up header file inclusion in pixelstore.h.
    • +
    • mesa: Fix printf format warnings.
    • +
    • mesa: Clean up header file inclusion in points.h.
    • +
    • i965: Silence uninitialized variable warning.
    • +
    • glsl: Add ir_constant_expression.cpp to SConscript.
    • +
    • mesa: Add definitions for inverse hyperbolic function on MSVC.
    • +
    • glsl: Fix 'control reaches end of non-void function' warning.
    • +
    • glsl: Add lower_vector.cpp to SConscript.
    • +
    • glsl: Fix type of label 'default' in switch statement.
    • +
    • st/mesa: Remove unnecessary headers.
    • +
    • swrast: Remove unnecessary header.
    • +
    • r600: Remove unnecesary header.
    • +
    • intel: Remove unnecessary header.
    • +
    • mesa: Clean up header file inclusion in polygon.h.
    • +
    • mesa: Clean up header file inclusion in rastpos.h.
    • +
    • mesa: Clean up header file inclusion in readpix.h.
    • +
    • mesa: Clean up header file inclusion in renderbuffer.h.
    • +
    • mesa: Clean up header file inclusion in scissor.h.
    • +
    • mesa: Clean up header file inclusion in shaderapi.h.
    • +
    • mesa: Clean up header file inclusion in shared.h.
    • +
    • mesa: Clean up header file inclusion in stencil.h.
    • +
    • r600: Remove unnecessary header.
    • +
    • llvmpipe: Remove unnecessary headers.
    • +
    • mesa: Clean up header file inclusion in syncobj.h.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • r300/compiler: Move declaration before code.
    • +
    • mesa: Clean up header file inclusion in texcompress.h.
    • +
    • st/vega: Silence uninitialized variable warning.
    • +
    • mesa: Clean up header file inclusion in texcompress_s3tc.h.
    • +
    • mesa: Clean up header file inclusion in texenvprogram.h.
    • +
    • mesa: Clean up header file inclusion in texformat.h.
    • +
    • mesa: Clean up header file inclusion in texgetimage.h.
    • +
    • mesa: Clean up header file inclusion in texobj.h.
    • +
    • gallium/noop: Add prototype for noop_init_state_functions.
    • +
    • mesa: Clean up header file inclusion in texrender.h.
    • +
    • mesa: Clean up header file inclusion in transformfeedback.h.
    • +
    • mesa: Clean up header file inclusion in varray.h.
    • +
    • mesa: Clean up header file inclusion in viewport.h.
    • +
    • r200: Silence uninitialized variable warning.
    • +
    • r600g: Fix SCons build.
    • +
    • i965: Silence uninitialized variable warning.
    • +

    + +

    Xavier Chantry (8): +

      +
    • nv50: fix size of outputs_written array
    • +
    • nv50: apply layout_mask to tile_flags
    • +
    • nvfx: only expose one rt on nv30
    • +
    • nvfx: fb->nr_cbufs <= 1 on nv30
    • +
    • nvfx: reset nvfx->hw_zeta
    • +
    • nvfx: fixes after array textures merge
    • +
    • init ps->context with util_surfaces_get and do_get
    • +
    • gallium/trace: check bind_vertex_sampler_states and set_vertex_sampler_views
    • +

    + +

    Xiang, Haihao (10): +

      +
    • mesa: fix regression from b4bb6680200b5a898583392f4c831c02f41e63f7
    • +
    • i965: add support for polygon mode on Sandybridge.
    • +
    • i965: fix for flat shading on Sandybridge
    • +
    • i965: set minimum/maximum Point Width on Sandybridge
    • +
    • meta: allow nested meta operations
    • +
    • i965: support for two-sided lighting on Sandybridge
    • +
    • i965: fix register region description
    • +
    • i965: use align1 access mode for instructions with execSize=1 in VS
    • +
    • i965: don't spawn GS thread for LINELOOP on Sandybridge
    • +
    • i965: use BLT to clear buffer if possible on Sandybridge
    • +

    + +

    Zack Rusin (8): +

      +
    • rbug: fix rbug when contexts are being destroyed
    • +
    • llvmpipe: fix rasterization of vertical lines on pixel boundaries
    • +
    • scons: build the xorg state trackers only when env includes drm
    • +
    • gallivm: implement indirect addressing of the output registers
    • +
    • gallivm: implement indirect addressing over inputs
    • +
    • gallivm: fix storing of the addr register
    • +
    • scons: add alias for identity
    • +
    • gallium/util: add states relevant to geometry shaders
    • +

    + +

    Zhenyu Wang (40): +

      +
    • i965: disasm quarter and write enable instruction control on sandybridge
    • +
    • i965: new state dump for sandybridge
    • +
    • i965: enable accumulator update in PS kernel too on sandybridge
    • +
    • i965: Fix color interpolation on sandybridge
    • +
    • i965: force zero in clipper to ignore RTAIndex on sandybridge
    • +
    • i965: fix point size setting in header on sandybridge
    • +
    • i965: ff sync message change for sandybridge
    • +
    • i965: ignore quads for GS kernel on sandybridge
    • +
    • i965: add sandybridge viewport state bo into validation list
    • +
    • i965: VS use SPF mode on sandybridge for now
    • +
    • i965: fix jump count on sandybridge
    • +
    • i965: Fix sampler on sandybridge
    • +
    • i965: fix const register count for sandybridge
    • +
    • i965: Add all device ids for sandybridge
    • +
    • i965: sandybridge pipe control workaround before write cache flush
    • +
    • i965: only allow SIMD8 kernel on sandybridge now
    • +
    • i965: don't do calculation for delta_xy on sandybridge
    • +
    • i965: fix pixel w interpolation on sandybridge
    • +
    • i965: enable polygon offset on sandybridge
    • +
    • i965: fix scissor state on sandybridge
    • +
    • i965: fix point sprite on sandybridge
    • +
    • i965: fix occlusion query on sandybridge
    • +
    • i965: fallback bitmap operation on sandybridge
    • +
    • i965: Always set tiling for depth buffer on sandybridge
    • +
    • i965: fallback lineloop on sandybridge for now
    • +
    • Revert "i965: Always set tiling for depth buffer on sandybridge"
    • +
    • i965: always set tiling for fbo depth buffer on sandybridge
    • +
    • i965: Fix GS hang on Sandybridge
    • +
    • Revert "i965: fallback lineloop on sandybridge for now"
    • +
    • i965: refresh wm push constant also for BRW_NEW_FRAMENT_PROGRAM on gen6
    • +
    • i965: fix dest type of 'endif' on sandybridge
    • +
    • Revert "i965: VS use SPF mode on sandybridge for now"
    • +
    • i965: also using align1 mode for math2 on sandybridge
    • +
    • i965: Fix GS state uploading on Sandybridge
    • +
    • i965: upload WM state for _NEW_POLYGON on sandybridge
    • +
    • i965: Use MI_FLUSH_DW for blt ring flush on sandybridge
    • +
    • i965: explicit tell header present for fb write on sandybridge
    • +
    • i965: Fix occlusion query on sandybridge
    • +
    • i965: Use last vertex convention for quad provoking vertex on sandybridge
    • +
    • i965: Fix provoking vertex select in clip state for sandybridge
    • +

    + +

    Zou Nan hai (1): +

      +
    • i965: skip too small size mipmap
    • +

    + +

    delphi (2): +

      +
    • draw: added userclip planes and updated variant_key
    • +
    • draw: some changes to allow for runtime changes to userclip planes
    • +

    + +

    nobled (3): +

      +
    • r300g: Abort if atom allocations fail
    • +
    • r300g: Abort if draw_create() fails
    • +
    • r300g: Drop unnecessary cast
    • +

    + +

    pontus lidman (1): +

      +
    • mesa: check for posix_memalign() errors
    • +

    + +

    richard (2): +

      +
    • evergreen : fix z format setting, enable stencil.
    • +
    • r600c : inline vertex format is not updated in an app, switch to use vfetch constants. For the 7.9 and 7.10 branches as well.
    • +

    + + + diff --git a/docs/relnotes-7.2.html b/docs/relnotes-7.2.html new file mode 100644 index 0000000..0ad3b5b --- /dev/null +++ b/docs/relnotes-7.2.html @@ -0,0 +1,104 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.2 Release Notes / 20 September 2008

    + +

    +Mesa 7.2 is a stable release fixing bugs found in 7.1, which was a +new development release. +

    +

    +Mesa 7.2 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +Note that this version of Mesa does not use the GEM memory manager. +The master branch of git uses GEM. +The prototype DRI2 code that was in 7.1 has also been removed. +

    +

    +DRM version 2.3.1 should be used with Mesa 7.2 +

    + + +

    MD5 checksums

    +
    +81a2a4b7cbfce7553f7ad8d924edbe2f  MesaLib-7.2.tar.gz
    +04d379292e023df0b0266825cb0dbde5  MesaLib-7.2.tar.bz2
    +8bc497a37977a55e987a4d1fabc3d882  MesaLib-7.2.zip
    +10c762e39486df395838af1d7b57e69c  MesaDemos-7.2.tar.gz
    +22e03dc4038cd63f32c21eb60994892b  MesaDemos-7.2.tar.bz2
    +1197bc4eb3bf44e291c14d4eb2e19381  MesaDemos-7.2.zip
    +42e3c6c6d156cd9dc545dbef72407354  MesaGLUT-7.2.tar.gz
    +f67daf93e12c4a459703bbf3e4004e31  MesaGLUT-7.2.tar.bz2
    +0390567eb2c2d12fbf82e8523fd77e2b  MesaGLUT-7.2.zip
    +
    + + +

    New features

    +
      +
    • i965 driver: added support for G41 chipset (Intel) +
    + + +

    Bug fixes

    +
      +
    • Fixed display list bug involving primitives split across lists (bug 17564) +
    • Fixed some issues with glBindAttribLocation() +
    • Fixed crash in _tnl_InvalidateState() found with Amira (bug 15834) +
    • Assorted bug fixes for Ming build +
    • Fixed some vertex/pixel buffer object reference counting bugs +
    • Fixed depth/stencil bug in i915/945 driver +
    • Fixed some shader flow control bugs in i965 driver +
    • Fixed a few tdfx driver bugs which prevented driver from working +
    • Fixed multisample enable/disable bug +
    + +

    Changes

    +
      +
    • Updated SGI header files with new license terms. +
    + + + +

    To Do (someday) items

    +
      +
    • Remove the MEMCPY() and _mesa_memcpy() wrappers and just use memcpy(). +Probably do the same for malloc, calloc, etc. +The wrappers were useful in the past for memory debugging but now we +have valgrind. Not worried about SunOS 4 support anymore either... +
    • Switch to freeglut +
    • Fix linux-glide target/driver. +
    • Improved lambda and derivative calculation for frag progs. +
    + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 2.1
    +OSMesa (off-screen)	implements OpenGL 2.1
    +Windows/Win32		implements OpenGL 2.1
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			unsupported
    +Wind River UGL		unsupported
    +DJGPP			unsupported
    +GGI			unsupported
    +BeOS			unsupported
    +Allegro			unsupported
    +D3D			unsupported
    +
    + + + diff --git a/docs/relnotes-7.3.html b/docs/relnotes-7.3.html new file mode 100644 index 0000000..df89884 --- /dev/null +++ b/docs/relnotes-7.3.html @@ -0,0 +1,93 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.3 Release Notes / 22 January 2009

    + +

    +Mesa 7.3 is a new development release. +Users especially concerned with stability should stick with latest +stable release: version 7.2. +

    +

    +Mesa 7.3 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +8ed03191432b22d118d88d6db497f304  MesaLib-7.3.tar.gz
    +781e7811a6ed5c97b2b8defefc8ffbc9  MesaLib-7.3.tar.bz2
    +3ccba9a1734ed6d4b3389e1535d90fbf  MesaLib-7.3.zip
    +d312e974b31043b13b61bac5fbf00b87  MesaDemos-7.3.tar.gz
    +3f0741394069bdf2329565a387396cda  MesaDemos-7.3.tar.bz2
    +4d0887fd4c66a824295cdd619f6d34cb  MesaDemos-7.3.zip
    +2d7661b66022bcb8878728f3d5bd33ab  MesaGLUT-7.3.tar.gz
    +abe8036a724c1a483bdad6b5a55ddc1a  MesaGLUT-7.3.tar.bz2
    +5f247819b47e2a7c62d07a6afe5262fb  MesaGLUT-7.3.zip
    +
    + + +

    New features

    +
      +
    • Support for GLSL 1.20 +
    • Intel DRI drivers now use GEM and DRI2 +
    + + +

    Bug fixes

    +
      +
    • Assorted GLSL bug fixes +
    • Assorted i965 driver fixes +
    • Fix for wglCreateLayerContext() in WGL/Windows driver +
    • Build fixes for OpenBSD and gcc 2.95 +
    • GLSL preprocessor handles #pragma now +
    • Fix incorrect transformation of GL_SPOT_DIRECTION +
    • Fixed several bugs (#18367 and #19625) in glXMakeContextCurrent() +
    • Assorted Windows build fixes +
    + +

    Changes

    +
      +
    • Deprecated the "XMesa" interface (include/GL/xmesa*.h files) +
    • Deprecated the "FXMesa" interface (include/GL/fxmesa.h file) +
    • Deprecated the "Allegro" interface (include/GL/amesa.h file) +
    • Removed include/GL/uglmesa.h header +
    • Removed include/GLView.h header for BeOS +
    + + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 2.1
    +OSMesa (off-screen)	implements OpenGL 2.1
    +Windows/Win32		implements OpenGL 2.1
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			unsupported
    +Wind River UGL		unsupported
    +DJGPP			unsupported
    +GGI			unsupported
    +BeOS			unsupported
    +Allegro			unsupported
    +D3D			unsupported
    +
    + + + diff --git a/docs/relnotes-7.4.1.html b/docs/relnotes-7.4.1.html new file mode 100644 index 0000000..40f4fb1 --- /dev/null +++ b/docs/relnotes-7.4.1.html @@ -0,0 +1,79 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.4.1 Release Notes / 18 April 2009

    + +

    +Mesa 7.4.1 is a stable development release fixing bugs since the 7.4 release. +

    +

    +Mesa 7.4.1 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +0c3a72f3295a53a134c04bd7d209ea62  MesaLib-7.4.1.tar.gz
    +423260578b653818ba66c2fcbde6d7ad  MesaLib-7.4.1.tar.bz2
    +84f78b154d4bd5c3ecc42eeff2e56676  MesaLib-7.4.1.zip
    +aa0ad323e59d6d10ff33ac0dde462a60  MesaDemos-7.4.1.tar.gz
    +1e169fb6abc2b45613f1c98a82dfe690  MesaDemos-7.4.1.tar.bz2
    +294e42be2d74176596c994ec23322fcf  MesaDemos-7.4.1.zip
    +92373bfa48e7b68dddf356e86b0e5699  MesaGLUT-7.4.1.tar.gz
    +336f3824b578b072211e0beecf4f04f4  MesaGLUT-7.4.1.tar.bz2
    +20751388d8ef16b42d25d9e3d705d101  MesaGLUT-7.4.1.zip
    +
    + + +

    Bug fixes

    +
      +
    • Fixed a two-sided lighting bug in fixed-function-to-GPU code generation +
    • Fixed some Darwin issues (Jeremy Huddleston) +
    • Indexing the GLSL gl_EyePlane[] or gl_ObjectPlane[] arrays with a variable + was broken, bug 20986 +
    • Fixed incorrect texture unit bias in TXB instruction +
    • glTexParameter settings weren't always propogated to drivers +
    • Assorted vertex/fragment program bug fixes +
    • Fixed point rendering in software rasterizer +
    • Fixed potential deadlock in object hash functions +
    • Fix a couple bugs surrounding front-buffer rendering with DRI2, but this + is not quite complete. +
    • Fixed glPopAttrib() bug when restoring user clip planes +
    + + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 2.1
    +OSMesa (off-screen)	implements OpenGL 2.1
    +Windows/Win32		implements OpenGL 2.1
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			unsupported
    +Wind River UGL		unsupported
    +DJGPP			unsupported
    +GGI			unsupported
    +BeOS			unsupported
    +Allegro			unsupported
    +D3D			unsupported
    +
    + + + diff --git a/docs/relnotes-7.4.2.html b/docs/relnotes-7.4.2.html new file mode 100644 index 0000000..7d066e4 --- /dev/null +++ b/docs/relnotes-7.4.2.html @@ -0,0 +1,74 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.4.2 Release Notes / May 15, 2009

    + +

    +Mesa 7.4.2 is a stable development release fixing bugs since the 7.4.1 release. +

    +

    +Mesa 7.4.2 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +172f5193154dad731387f97bd44ab68f  MesaLib-7.4.2.tar.gz
    +b10a76e32bde4645cfc34ea0416d7d8b  MesaLib-7.4.2.tar.bz2
    +cc6dfc2efd424cc342b84e6bcd78ce5d  MesaLib-7.4.2.zip
    +182a7e78aa7a480b3650a5c956dbddd1  MesaDemos-7.4.2.tar.gz
    +bf559a0485667a3bfa4513a23501579b  MesaDemos-7.4.2.tar.bz2
    +5379e622b65e8c22022dba34aeb6f4f9  MesaDemos-7.4.2.zip
    +7cc43c1c35bf6a279a16e063dea3b8c5  MesaGLUT-7.4.2.tar.gz
    +e0dfc44d537904a030861e5b3c760c11  MesaGLUT-7.4.2.tar.bz2
    +4a6cf5bbbac190d6ba97448b3098b7f4  MesaGLUT-7.4.2.zip
    +
    + + +

    Bug fixes

    +
      +
    • Fixed segfault when rendering to front buffer with DRI 1. +
    • Fixed swrast texture rectangle bug when wrap mode = GL_CLAMP_TO_BORDER and + filter mode = GL_LINEAR. (bug 21461) +
    • Fixed texture object mem leak during context destruction. +
    • Fixed a state validation bug in glCopyTex[Sub]Image() +
    • Fixed some i965 GLSL bugs. +
    • Fixed an R300 driver texture object bad memory reference. +
    + + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 2.1
    +OSMesa (off-screen)	implements OpenGL 2.1
    +Windows/Win32		implements OpenGL 2.1
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			unsupported
    +Wind River UGL		unsupported
    +DJGPP			unsupported
    +GGI			unsupported
    +BeOS			unsupported
    +Allegro			unsupported
    +D3D			unsupported
    +
    + + + diff --git a/docs/relnotes-7.4.3.html b/docs/relnotes-7.4.3.html new file mode 100644 index 0000000..35b5dcc --- /dev/null +++ b/docs/relnotes-7.4.3.html @@ -0,0 +1,79 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.4.3 Release Notes / 19 June 2009

    + +

    +Mesa 7.4.3 is a stable development release fixing bugs since the 7.4.2 release. +

    +

    +Mesa 7.4.3 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +34c5a6c47ed51f31c4fa36e269831352  MesaLib-7.4.3.tar.gz
    +70a983ba3deaa8bd63b18bbab283f698  MesaLib-7.4.3.tar.bz2
    +34f21b3205b271d575030aa98a2dda51  MesaLib-7.4.3.zip
    +56752b7adede212e6097afb10d0c0d59  MesaDemos-7.4.3.tar.gz
    +8ffa51c4833b1e298300a005e2d7ca2a  MesaDemos-7.4.3.tar.bz2
    +0037d24d41400d6fb9800ae55b8c863f  MesaDemos-7.4.3.zip
    +20e24f6692c0c90e7e3b220f79c4108d  MesaGLUT-7.4.3.tar.gz
    +03a4beeef74fc5ef0b1d6d04710e5a8a  MesaGLUT-7.4.3.tar.bz2
    +273788230adbdb9d57371309adedcf5f  MesaGLUT-7.4.3.zip
    +
    + + +

    Bug fixes

    +
      +
    • Fixed texture object reference counting bug (bug 21756) +
    • Allow depth/stencil textures to be attached to GL_STENCIL_ATTACHMENT point + (SF bug 2793846) +
    • Added missing glGet case for GL_VERTEX_ARRAY_BINDING_APPLE +
    • Fixed some OSMesa build issues +
    • Fixed a vertex buffer object crash +
    • Fixed broken glTexImage3D() when image type = GL_BITMAP +
    • Fixed some GLSL preprocessor bugs +
    • Fixed framebuffer mem leak in i945/i965 DRI drivers +
    • Fixed texture coordinate repeat bug in swrast (bug 21872) +
    • Fixed incorrect viewport clamping (lower bound is zero, not one) +
    • GLX fix for glean's makeCurrent test case +
    + + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 2.1
    +OSMesa (off-screen)	implements OpenGL 2.1
    +Windows/Win32		implements OpenGL 2.1
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			unsupported
    +Wind River UGL		unsupported
    +DJGPP			unsupported
    +GGI			unsupported
    +BeOS			unsupported
    +Allegro			unsupported
    +D3D			unsupported
    +
    + + + diff --git a/docs/relnotes-7.4.4.html b/docs/relnotes-7.4.4.html new file mode 100644 index 0000000..2a34568 --- /dev/null +++ b/docs/relnotes-7.4.4.html @@ -0,0 +1,68 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.4.4 Release Notes / 23 June 2009

    + +

    +Mesa 7.4.4 is a stable development release fixing bugs since the 7.4.3 release. +

    +

    +Mesa 7.4.4 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +0b56fe5a88ab0c3c5b2da5068f63f416  MesaLib-7.4.4.tar.gz
    +b66528d314c574dccbe0ed963cac5e93  MesaLib-7.4.4.tar.bz2
    +2818076f3ba23fa87fdfe4602a637a18  MesaLib-7.4.4.zip
    +3e77b208386c47b18165bce5ae317e2c  MesaDemos-7.4.4.tar.gz
    +628142ec9a54cd28cc027e6ce26cff47  MesaDemos-7.4.4.tar.bz2
    +d08a30d30ab7174859aa709cba6c726d  MesaDemos-7.4.4.zip
    +e6e91ba16e274d40cf3a97ad3218af01  MesaGLUT-7.4.4.tar.gz
    +e14bbb52517e8121b31f1387515365ab  MesaGLUT-7.4.4.tar.bz2
    +f10ed20469753c2b3d68c99854f80fd4  MesaGLUT-7.4.4.zip
    +
    + + +

    Bug fixes

    +
      +
    • Fixed i965/i915 segfault in screen destruction (bug 22408) +
    + + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 2.1
    +OSMesa (off-screen)	implements OpenGL 2.1
    +Windows/Win32		implements OpenGL 2.1
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			unsupported
    +Wind River UGL		unsupported
    +DJGPP			unsupported
    +GGI			unsupported
    +BeOS			unsupported
    +Allegro			unsupported
    +D3D			unsupported
    +
    + + + diff --git a/docs/relnotes-7.4.html b/docs/relnotes-7.4.html new file mode 100644 index 0000000..55ba019 --- /dev/null +++ b/docs/relnotes-7.4.html @@ -0,0 +1,89 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.4 Release Notes / 27 March 2009

    + +

    +Mesa 7.4 is a stable development release fixing bugs since the 7.3 release. +

    +

    +Mesa 7.4 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +ed6bd7437177307e51e16d0c7c381dfa  MesaLib-7.4.tar.gz
    +7ecddb341a2691e0dfdb02f697109834  MesaLib-7.4.tar.bz2
    +433e823f8245f9fd5f397e7b719a8e47  MesaLib-7.4.zip
    +656eee6128016fb237e01aa8dabbc703  MesaDemos-7.4.tar.gz
    +02816f10f30b1dc5e069e0f68c177c98  MesaDemos-7.4.tar.bz2
    +44a70d6db4aa4c64ecc47871b6aceee8  MesaDemos-7.4.zip
    +25f80db4f8645cd3e58e2c9af53ec341  MesaGLUT-7.4.tar.gz
    +04ec01caebde44f5b0d619f00716b368  MesaGLUT-7.4.tar.bz2
    +019dc213baecaa3cb1278847d41b8591  MesaGLUT-7.4.zip
    +
    + + +

    New features

    +
      +
    • Added MESA_GLX_FORCE_DIRECT env var for Xlib/software driver +
    • GLSL version 1.20 is returnd by the GL_SHADING_LANGUAGE_VERSION query +
    + + +

    Bug fixes

    +
      +
    • glGetActiveUniform() returned wrong size for some array types +
    • Fixed some error checking in glUniform() +
    • Fixed a potential glTexImage('proxy target') segfault +
    • Fixed bad reference counting for 1D/2D texture arrays +
    • Fixed VBO + glPush/PopClientAttrib() bug #19835 +
    • Assorted i965 driver bug fixes +
    • Fixed a Windows compilation failure in s_triangle.c +
    • Fixed a GLSL array indexing bug +
    • Fixes for building on Haiku +
    + +

    Changes

    +
      +
    • Updated GL/glxext.h to version 48 +
    • Assorted updates for building on Solaris +
    + + + +

    Driver Status

    + +
    +Driver			Status
    +----------------------	----------------------
    +DRI drivers		varies with the driver
    +XMesa/GLX (on Xlib)	implements OpenGL 2.1
    +OSMesa (off-screen)	implements OpenGL 2.1
    +Windows/Win32		implements OpenGL 2.1
    +Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
    +SVGA			unsupported
    +Wind River UGL		unsupported
    +DJGPP			unsupported
    +GGI			unsupported
    +BeOS			unsupported
    +Allegro			unsupported
    +D3D			unsupported
    +
    + + + diff --git a/docs/relnotes-7.5.1.html b/docs/relnotes-7.5.1.html new file mode 100644 index 0000000..1a4f608 --- /dev/null +++ b/docs/relnotes-7.5.1.html @@ -0,0 +1,72 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.5.1 Release Notes, 3 September 2009

    + +

    +Mesa 7.5.1 is a bug-fix release fixing issues found since the 7.5 release. +

    +

    +The main new feature of Mesa 7.5.x is the +Gallium3D infrastructure. +

    +

    +Mesa 7.5.1 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +d7269e93bc7484430637d54ced250876  MesaLib-7.5.1.tar.gz
    +877d6a4b24efc2b1d02aa553f262cba8  MesaLib-7.5.1.tar.bz2
    +23f4fb757a05c8396425681234ae20e5  MesaLib-7.5.1.zip
    +5af4bd113652108f5cec5113dad813f2  MesaDemos-7.5.1.tar.gz
    +785402e3b9f0e335538fcc6bf19f6987  MesaDemos-7.5.1.tar.bz2
    +950058cc6d6106e9c7d5876a03789fe9  MesaDemos-7.5.1.zip
    +cb52ce2c93389c2711cbe8d857ec5303  MesaGLUT-7.5.1.tar.gz
    +e3a9892e056d625c5353617a7c5b7e9c  MesaGLUT-7.5.1.tar.bz2
    +da1de364df148c94b4994006191a1e69  MesaGLUT-7.5.1.zip
    +
    + + +

    New features

    +
      +
    • Added configure --with-max-width=W, --with-max-height=H options to specify + max framebuffer, viewport size. +
    + + +

    Bug fixes

    +
      +
    • Added missing GLEW library to MesaDemos tarballs. +
    • Fixed swapbuffers jerkiness in Doom3/etc in Intel drivers. +
    • Fixed front buffer rendering bug in Intel drivers. +
    • Fixed minor GLX memory leaks. +
    • Fixed some texture env / fragment program state bugs. +
    • Fixed some Gallium glBlitFramebuffer() bugs +
    • Empty glBegin/glEnd() pair could cause divide by zero (bug 23489) +
    • Fixed Gallium glBitmap() Z position bug +
    • Setting arrays of sampler uniforms did not work +
    • Selection/Feedback mode didn't handle polygon culling correctly (bug 16866) +
    • Fixed 32/64-bit cross compilation issue in gen_matypes.c +
    • Fixed glXCreateGLXPixmap() for direct rendering. +
    • Fixed Gallium glCopyPixels(GL_STENCIL_INDEX) mispositioned image bug. +
    + + + + diff --git a/docs/relnotes-7.5.2.html b/docs/relnotes-7.5.2.html new file mode 100644 index 0000000..5c395d9 --- /dev/null +++ b/docs/relnotes-7.5.2.html @@ -0,0 +1,67 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.5.2 Release Notes, 28 September 2009

    + +

    +Mesa 7.5.2 is a bug-fix release fixing issues found since the 7.5.1 release. +

    +

    +The main new feature of Mesa 7.5.x is the +Gallium3D infrastructure. +

    +

    +Mesa 7.5.2 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +43a90191dd9f76cd65dcc1ac91f3be70  MesaLib-7.5.2.tar.gz
    +94e47a499f1226803869c2e37a6a8e3a  MesaLib-7.5.2.tar.bz2
    +1ecb822b567ad67a0617361d45206b67  MesaLib-7.5.2.zip
    +2718fdce7e075911d6147beb8f27104b  MesaDemos-7.5.2.tar.gz
    +4e0f5ccd58afe21eddcd94327d926e86  MesaDemos-7.5.2.tar.bz2
    +f621f8c223b278d7c8e49a012d56ca25  MesaDemos-7.5.2.zip
    +83c16c1d6bcfcc3f97aab5d2fe430b4c  MesaGLUT-7.5.2.tar.gz
    +e5d03bedae369ea3705783573bb33813  MesaGLUT-7.5.2.tar.bz2
    +e82ba28e00d653e6f437d32be8ca8481  MesaGLUT-7.5.2.zip
    +
    + + +

    New features

    +
      +
    • Detect B43 chipset in Intel driver +
    + + +

    Bug fixes

    +
      +
    • Assorted bug fixes for i965/i945 drivers +
    • Fixed Gallium glDrawPixels(GL_STENCIL_INDEX) failure. +
    • Fixed GLSL linker/preprocessor version directive issue seen in Wine + (such as bug 23946) +
    • glUseProgram() is now compiled into display lists (bug 23746). +
    • glUniform functions are now compiled into display lists +
    • Auto mipmap generation didn't work reliably with Gallium. +
    • Fixed random number usage in GLX code. +
    • Fixed invalid GL_OUT_OF_MEMORY error sometimes raised by glTexSubImage2D + when using Gallium. +
    + + + diff --git a/docs/relnotes-7.5.html b/docs/relnotes-7.5.html new file mode 100644 index 0000000..56deca6 --- /dev/null +++ b/docs/relnotes-7.5.html @@ -0,0 +1,102 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.5 Release Notes / 17 July 2009

    + +

    +Mesa 7.5 is a new development release. +People who are concerned with stability and reliability should stick +with the 7.4.x branch or wait for Mesa 7.5.1. +

    +

    +The main new feature of Mesa 7.5 is the +Gallium3D infrastructure. +

    +

    +Mesa 7.5 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    +

    +Note that the Mesa project is no longer using odd/even version numbers +to indicate development/stable releases. +The so-called development releases have been fairly stable. +If you're especially concerned with stability you should probably look for +"point" releases such as 7.5.1 which will be a bug-fix release. +

    + + +

    MD5 checksums

    +
    +553fd956e544727f30fbe249619b6286  MesaLib-7.5.tar.gz
    +459f332551f6ebb86f384d21dd15e1f0  MesaLib-7.5.tar.bz2
    +8c02c0e17a9025250d20424ae32f5163  MesaLib-7.5.zip
    +a188da2886fa5496ea0c2cda602b2eeb  MesaDemos-7.5.tar.gz
    +398ee8801814a00e47f6c2314e3dfddc  MesaDemos-7.5.tar.bz2
    +15a0c8ae013c54335a26335e1a98d609  MesaDemos-7.5.zip
    +81010147def5a644ba14f9bbb7a49a2a  MesaGLUT-7.5.tar.gz
    +baa7a1e850b6e39bae58868fd0684004  MesaGLUT-7.5.tar.bz2
    +265228418e4423fa328f2f5b7970cf08  MesaGLUT-7.5.zip
    +
    + + +

    New features

    +
      +
    • Gallium3D - this is the new architecture for OS-independent and + API-independent 3D drivers. + Gallium3D is intended for GPUs that fully support vertex/fragment shaders. + The Gallium3D drivers currently included are: +
        +
      • softpipe - a software/reference driver +
      • i915 - Intel 915/945 driver +
      • Cell - IBM/Sony/Toshiba Cell processor driver +
      • nouveau (for NVIDIA GPUs) and R300 for (AMD/ATI R300). + PLEASE NOTE: these drivers are incomplete and still under development. + It's probably NOT worthwhile to report any bugs unless you have patches. + +
      +
    • GL_ARB_framebuffer_object extension (software drivers, i965 driver) +
    • Reworked two-sided stencil support. +This allows a driver to support all three variations of two-sided stencil +including GL_ATI_separate_stencil, GL_EXT_stencil_two_side and OpenGL 2.0 +
    • GL_EXT_vertex_array_bgra extension (software drivers, i965 driver) +
    • GL_NV_texture_env_combine4 extension (software drivers, i965/i915 drivers) +
    • GL_EXT_texture_swizzle extension (software drivers, i965 driver) +
    • Updated SPARC assembly optimizations (David S. Miller) +
    • Initial support for separate compilation units in GLSL compiler. +
    • Increased max number of generic GLSL varying variables to 16 (formerly 8). +
    • GLSL linker now detects when too many varying variables are used. +
    • Optimize-out redundant glMaterial and glShadeModel calls in display lists +
    • Fixed gl_TextureMatrix[i][j] array indexing bug in GLSL compiler. +
    + + +

    Bug fixes

    +
      +
    • Lots of i965 driver bug fixes +
    • Fixed some GLSL preprocessor bugs +
    • GLSL: continue inside of a for-loop didn't work +
    + + +

    Changes

    +
      +
    • Remove support for GL_SGIX_shadow, GL_SGIX_shadow_ambient and +GL_SGIX_depth_texture extensions. Superseded by the ARB versions. +
    • Omitted some old Mesa demos from the release tarballs, added some others. +
    + + + diff --git a/docs/relnotes-7.6.1.html b/docs/relnotes-7.6.1.html new file mode 100644 index 0000000..1d0ecd2 --- /dev/null +++ b/docs/relnotes-7.6.1.html @@ -0,0 +1,80 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.6.1 Release Notes, 21 December 2009

    + +

    +Mesa 7.6.1 is a bug-fix release fixing issues since version 7.6. +

    +

    +Mesa 7.6.1 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +e80fabad2e3eb7990adae773d6aeacba  MesaLib-7.6.1.tar.gz
    +7db4617e9e10ad3aca1b64339fd71b7d  MesaLib-7.6.1.tar.bz2
    +dd3275dbf9833480d2e92d0c69b22abd  MesaLib-7.6.1.zip
    +f7fdcfe3c0f363e571c60f02f74368fb  MesaDemos-7.6.1.tar.gz
    +a4226f06732a02556fcf6be290b86dff  MesaDemos-7.6.1.tar.bz2
    +849425f356bd940726cebedfa79de176  MesaDemos-7.6.1.zip
    +d40cc7c5e337a85b674e27a8e494f52f  MesaGLUT-7.6.1.tar.gz
    +ca9aecb91f05b1da9fd7d5eeb19d47d7  MesaGLUT-7.6.1.tar.bz2
    +23fad8398004c977a1d8953079b72ca6  MesaGLUT-7.6.1.zip
    +
    + + +

    New features

    +
      +
    • Upgraded GL/glext.h to version 56, GL/glxext.h to version 25, + GL/wglext.h to version 17 +
    • New 3D driver, r600, for Radeon R6xx, R7xx hardware +
    + + +

    Bug fixes

    +
      +
    • Fixed crash caused by glXCopyContext() and glXDestroyContext(), bug 24217 +
    • glXQueryContext(GLX_RENDER_TYPE) returned wrong values (bug 24211) +
    • GLSL sqrt(0) returned unpredictable results +
    • Fixed default texture binding bug when a bound texture was deleted. +
    • r300: Work around an issue with very large fragment programs on R500. +
    • Fake glXQueryDrawable() didn't return good values (bug 24320) +
    • Fixed AUX buffer breakage (bug 24426). +
    • Fixed locale-dependent float parsing bug in GLSL compiler (bug 24531) +
    • Fixed Gallium Cell driver compilation failure. +
    • Fixed glGetTexLevelParameter(GL_TEXTURE_INTERNAL_FORMAT) query so that + it returns the actual compressed format chosen. +
    • Fixed glBitmap bugs in Intel drivers. +
    • Fixed a number of Microsoft Visual Studio compilation problems. +
    • Fixed clipping / provoking vertex bugs in i965 driver. +
    • Assorted build fixes for AIX. +
    • Endianness fixes for the DRI swrast driver (bug 22767).
    • +
    • Point sprite fixes for i915/945 driver. +
    • Fixed assorted memory leaks (usually on error paths) +
    • Fixed some GLSL compiler bugs (ex: 25579) +
    • Assorted build fixes for BlueGene +
    + +

    Changes

    +
      +
    • Removed old VC6, VC7 project files for Windows +
    + + + + diff --git a/docs/relnotes-7.6.html b/docs/relnotes-7.6.html new file mode 100644 index 0000000..410b6ef --- /dev/null +++ b/docs/relnotes-7.6.html @@ -0,0 +1,84 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.6 Release Notes, 28 September 2009

    + +

    +Mesa 7.6 is a new development release. +People who are concerned with stability and reliability should stick +with a previous release or wait for Mesa 7.6.1. +

    +

    +Mesa 7.6 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +5ffa7d7abf8973f57a1bc4f813e6dade  MesaLib-7.6.tar.gz
    +8c75f90cd0303cfac9e4b6d54f6759ca  MesaLib-7.6.tar.bz2
    +27fcfd69708599c978cb34ba5cd363e1  MesaLib-7.6.zip
    +e7befb3ae604f591806194a4da445628  MesaDemos-7.6.tar.gz
    +0ede7adf217951acd90dbe4551210c07  MesaDemos-7.6.tar.bz2
    +ed9298409cf6613bc0964525ca4afc8a  MesaDemos-7.6.zip
    +666955668e44ff14acf7d15dc78407d3  MesaGLUT-7.6.tar.gz
    +b8b59706f827d18d1b784a0ff98b4dc2  MesaGLUT-7.6.tar.bz2
    +c49c19c2bbef4f3b7f1389974dff25f4  MesaGLUT-7.6.zip
    +
    + + +

    New features

    +
      +
    • OpenVG front-end (state tracker for Gallium). +This was written by Zack Rusin at Tungsten Graphics. +
    • GL_ARB_vertex_array_object and GL_APPLE_vertex_array_object extensions + (supported in Gallium drivers, Intel DRI drivers, and software drivers)
    • +
    • GL_ARB_copy_buffer extension + (supported in Gallium drivers, Intel DRI drivers, and software drivers)
    • +
    • GL_ARB_map_buffer_range extension + (supported in Gallium drivers, Intel DRI drivers, and software drivers)
    • +
    • GL_ARB_seamless_cube_map extension + (supported in software drivers and i965 drivers)
    • +
    • GL_ARB_vertex_array_bgra (ARB synonym for GL_EXT_vertex_array_bgra)
    • +
    • GL_ARB_sync (supported in software drivers and Intel DRI drivers)
    • +
    • GL_EXT_provoking_vertex extension (supported in Gallium, i915, i965, and software drivers) +
    • Rewritten radeon/r200/r300 driver using a buffer manager +
    • radeon/r200/r300 GL_EXT_framebuffer_object support when used with + kernel memory manager +
    • radeon/r200/r300 support for GL_ARB_occlusion_query
    • +
    • r300 driver supports OpenGL 1.5
    • +
    • r300 driver support for GL_EXT_vertex_array_bgra, GL_EXT_texture_sRGB +
    • i915/945 driver support for GL_ARB_point_sprite, GL_EXT_stencil_two_side + and GL_ATI_separate_stencil extensions +
    • Rewritten assembler for GL_ARB_vertex_program / + GL_ARB_fragment_program.
    • +
    • Added configure --with-max-width=W, --with-max-height=H options to specify + max framebuffer, viewport size. +
    • Initial version of Gallium llvmpipe driver. This is a new driver based + on LLVM which makes exensive use of run-time code generation. This is + an "alpha" stage driver. See the src/gallium/drivers/llvmpipe/README + file for more information. +
    + + +

    Bug fixes

    +
      +
    • i965 DRI driver fixes, including support for "unlimited" size constant + buffers (GLSL uniforms) +
    + + + diff --git a/docs/relnotes-7.7.1.html b/docs/relnotes-7.7.1.html new file mode 100644 index 0000000..00b3671 --- /dev/null +++ b/docs/relnotes-7.7.1.html @@ -0,0 +1,60 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.7.1 Release Notes / March 28, 2010

    + +

    +Mesa 7.7.1 is a bug-fix release. +

    +

    +Mesa 7.7.1 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +3ab0638cfa7ce8157337a229cf0db2c4  MesaLib-7.7.1.tar.gz
    +46664d99e03f1e3ac078a7fea02af115  MesaLib-7.7.1.tar.bz2
    +4e73ba8abb59aff79485eb95d7cefff7  MesaLib-7.7.1.zip
    +bf1b108983995f7a712cf3343df1c918  MesaDemos-7.7.1.tar.gz
    +aeb39645d80d656e0adebaa09e5bcd03  MesaDemos-7.7.1.tar.bz2
    +01c49b7454fd292244eaf8bdc6ed8cf0  MesaDemos-7.7.1.zip
    +37ec6386693dcb6dc770d1efd63a7a93  MesaGLUT-7.7.1.tar.gz
    +1e16c85282f843791a21f7bc7b6a1ca8  MesaGLUT-7.7.1.tar.bz2
    +d352c9e36a8e4d1059f4abc017b131e0  MesaGLUT-7.7.1.zip
    +
    + + +

    Bug fixes

    +
      +
    • Assorted fixes to VMware SVGA gallium driver. +
    • Fixed broken blending to multiple color buffers in swrast driver. +
    • Allocate constants more tightly in GL_ARB_vertex/fragment parser. +
    • Fixed mipmap generation bug caused by invalid viewport state. +
    • Gallium SSE codegen for XPD didn't always work. +
    • Fixed Windows build. +
    • Fixed broken glMultiDrawElements(). +
    • Silence bogus GL errors generated in glxinfo. +
    • Fixed several render to texture bugs. +
    • Assorted bug fixes in Mesa/Gallium state tracker including + glCopy/DrawPixels() to FBOs. +
    • Assorted fixes to Gallium drivers. +
    • Fixed broken glPush/PopClientAttrib() for vertex arrays in GLX code. +
    + + + + diff --git a/docs/relnotes-7.7.html b/docs/relnotes-7.7.html new file mode 100644 index 0000000..c1ed654 --- /dev/null +++ b/docs/relnotes-7.7.html @@ -0,0 +1,70 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.7 Release Notes / 21 December 2009

    + +

    +Mesa 7.7 is a new development release. +People who are concerned with stability and reliability should stick +with a previous release or wait for Mesa 7.7.1. +

    +

    +Mesa 7.7 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +395c9516edf1ad54b0934d8db15557bf  MesaLib-7.7.tar.gz
    +e3fa64a1508bc23dd9de9dd2cea7cfb1  MesaLib-7.7.tar.bz2
    +e54903eb5e49c3969821fa16b32da245  MesaLib-7.7.zip
    +53b5b6f78e55de170d43c98cb6aaab7e  MesaDemos-7.7.tar.gz
    +6fd616b27b9826d0faa23e08e05d9435  MesaDemos-7.7.tar.bz2
    +240fe06159ad73d5e22c27033b66c80a  MesaDemos-7.7.zip
    +9fe11a904b2a9d8cd06cc52bc330b716  MesaGLUT-7.7.tar.gz
    +e8dceed05a59a2d3c2619d7d734587e3  MesaGLUT-7.7.tar.bz2
    +96af041d435349ee23ead4667ec36363  MesaGLUT-7.7.zip
    +
    + + +

    New features

    +
      +
    • VMware "SVGA" Gallium driver. This is a Gallium3D driver which targets the + VMware virtual graphics device. It allows Linux OpenGL guest applications + to utilize the 3D graphics hardware of the host operating system. +
    • GL_ARB_draw_elements_base_vertex (supported in Intel i965 and software drivers)
    • +
    • GL_ARB_depth_clamp (supported in Intel i965 DRI and software drivers)
    • +
    • GL_NV_depth_clamp (supported in Intel i965 DRI and software drivers)
    • +
    • GL_ARB_provoking_vertex (same as GL_EXT_provoking_vertex)
    • +
    • Wavefront .obj file loader/viewer demo (progs/demos/objviewer) +
    + + +

    Bug fixes

    +
      +
    • Many assorted i965 driver fixes. +
    • Many r300-gallium driver fixes; this driver is now considered unstable-quality instead of experimental-quality. +
    + + +

    Changes

    +
      +
    • New Mesa texture/surface format infrastructure +
    • Removed some unused Mesa device driver hooks +
    + + + diff --git a/docs/relnotes-7.8.1.html b/docs/relnotes-7.8.1.html new file mode 100644 index 0000000..1ba68fd --- /dev/null +++ b/docs/relnotes-7.8.1.html @@ -0,0 +1,62 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.8.1 Release Notes / April, 5, 2010

    + +

    +Mesa 7.8.1 fixes a couple critical bugs in the recent Mesa 7.8 release. Even +though this is a bug fix release, given its proximity to the 7.8 release, a +new development release, it should also be considered new development release. +People who are concerned with stability and reliability should stick +with a previous release, such as 7.7.1, or wait for Mesa 7.8.2. +

    +

    +Mesa 7.8.1 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +62e8e47cbd63741b4bbe634dcdc8a56a  MesaLib-7.8.1.tar.gz
    +25ec15f8e41fde6d206118cc786dbac4  MesaLib-7.8.1.tar.bz2
    +22b1153010ffdf513836ea9931159e80  MesaLib-7.8.1.zip
    +c9c0a830923d3820807a08c09d521b3e  MesaDemos-7.8.1.tar.gz
    +9ef47f911869657c6bf2f43ebce86b61  MesaDemos-7.8.1.tar.bz2
    +93720605eb3f784f9bcc289a4dd2ff52  MesaDemos-7.8.1.zip
    +ed1d0b1e960afe6a3768eab747cbdbd3  MesaGLUT-7.8.1.tar.gz
    +6bae516a44c6d26ff3152c960ab648e7  MesaGLUT-7.8.1.tar.bz2
    +ba306f603ea73c30ee0e7efa14dc5581  MesaGLUT-7.8.1.zip
    +
    + + +

    New features

    +

    None.

    + + +

    Bug fixes

    +
      +
    • Fix incorrect enums for GLX_INTEL_swap_event by updating glxext.h to + version 27 from OpenGL.org.
    • +
    • Fix compilation errors on non-GLX_DIRECT_RENDERING builds.
    • +
    • Various fixes for building Mesa on OS X.
    • +
    • Pass GLX drawable ID to dri2InvalidateBuffers. Fixes bug #27190.
    • +
    + + +

    Changes

    +

    None.

    + + diff --git a/docs/relnotes-7.8.2.html b/docs/relnotes-7.8.2.html new file mode 100644 index 0000000..1393b2e --- /dev/null +++ b/docs/relnotes-7.8.2.html @@ -0,0 +1,146 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.8.2 Release Notes / (date tbd)

    + +

    +Mesa 7.8.2 is a bug fix release which fixes bugs found since the 7.8.1 release. +

    +

    +Mesa 7.8.2 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +c89b63d253605ed40e8ac370d25a833c  MesaLib-7.8.2.tar.gz
    +6be2d343a0089bfd395ce02aaf8adb57  MesaLib-7.8.2.tar.bz2
    +a04ad3b06ac5ff3969a003fa7bbf7d5b  MesaLib-7.8.2.zip
    +7c213f92efeb471f0331670d5079d4c0  MesaDemos-7.8.2.tar.gz
    +757d9e2e06f48b1a52848be9b0307ced  MesaDemos-7.8.2.tar.bz2
    +8d0e5cfe68b8ebf90265d350ae2c48b1  MesaDemos-7.8.2.zip
    +b74482e3f44f35ed395c4aada4fd8240  MesaGLUT-7.8.2.tar.gz
    +a471807b65e49c325808ba4551be93ed  MesaGLUT-7.8.2.tar.bz2
    +9f190268c42be582ef66e47365ee61e3  MesaGLUT-7.8.2.zip
    +
    + + +

    New features

    +

    None.

    + + +

    Changes

    +
      +
    • Upgraded glext.h to version 61, and upgraded glxext.h +
    + + +

    Bug fixes

    +
      +
    • Fixed Gallium glDrawPixels(GL_DEPTH_COMPONENT). +
    • Fixed Gallium Cell driver to buildable, runable state +
    • Fixed bad error checking for glFramebufferRenderbuffer(attachment=GL_DEPTH_STENCIL_ATTACHMENT). +
    • Fixed incorrect Z coordinate handling in "meta" glDraw/CopyPixels. + Bug + #23670.
    • + +
    • Assorted i965 driver fixes. + Including but not limited to: +
        +
      • Fix scissoring when width or height is + 0. Bug + #27643. +
      • Fix bit allocation for number of color regions for + ARB_draw_buffers.
      • +
      • Set the correct provoking vertex for clipped first-mode + trifans. Bug + #24470.
      • +
      • Use R16G16B16A16_FLOAT for 3-component half-float.
      • +
      • Fix assertion for surface tile offset usage on Ironlake.
      • +
      • Fix cube map layouts on Ironlake.
      • +
      • When an RB gets a new region, clear the old from the state + cache. Bug + #24119.
      • +
      • Reject shaders with uninlined function calls instead of hanging.
      • +
      +
    • + +
    • Assorted i915 driver fixes. Including but not limited to: +
        +
      • Fixed texture LOD clamping in i915 driver. + Bug + #24846.
      • +
      • Fix off-by-one for drawing rectangle. + Bug + #27408.
      • +
      +
    • + +
    • Fixed hangs in etracer on 830 and 845 + chipsets. Bug + #26557.
    • +
    • Fixed tiling of small textures on all Intel drivers.
    • +
    • Fixed crash in Savage driver when using _mesa_CopyTexImage2D. + Bug + #27652.
    • + +
    • Assorted GLX fixes. Including but not limited to: +
        +
      • Fixed __glXInitializeVisualConfigFromTags's handling of + unrecognized fbconfig tags.
      • +
      • Fixed regression with GLX_USE_GL. +
      • Fixed config chooser logic for 'mask' matching.
      • +
      • Report swap events correctly in direct rendered case (DRI2)
      • +
      • Fixed build with dri2proto which doesn't define + X_DRI2SwapInterval.
      • +
      • Get GLX_SCREEN first in __glXQueryContextInfo. + Bug + #14245.
      • +
      +
    • + +
    • Assorted GLSL fixes. Including but not limited to: +
        +
      • Change variable declared assertion into conditional in GLSL + compiler. Bug + #27921.
      • +
      • Fix instruction indexing + bugs. Bug + #27566.
      • +
      • Updated uniform location / offset encoding to be more like + other implementations.
      • +
      • Don't overwrite a driver's shader infolog with generic failure + message.
      • +
      +
    • + +
    • Fixed OSMesa build for 16 and 32-bit color channel depth. +
    • Fixed OSMesa build with hidden symbol visibility. libOSMesa no longer links to libGL. + Bug + #28305. +
    • Fixed handling of multiple render targets in fixed-function + texture envrionmnent programs.
    • +
    • Fixed conversion errors in signed_rgba8888[rev] texel + fetch.
    • +
    • Don't set srcLevel on GL_TEXTURE_RECTANGLE_ARB targets.
    • +
    • Various build fixes for OpenBSD.
    • +
    • Various build fixes for OS X.
    • +
    • Various build fixes for GCC 3.3.
    • +
    + + + + diff --git a/docs/relnotes-7.8.3.html b/docs/relnotes-7.8.3.html new file mode 100644 index 0000000..1e9f433 --- /dev/null +++ b/docs/relnotes-7.8.3.html @@ -0,0 +1,89 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.8.3 Release Notes / (date tbd)

    + +

    +Mesa 7.8.3 is a bug fix release which fixes bugs found since the 7.8.2 release. +

    +

    +Mesa 7.8.3 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +x  MesaLib-7.8.3.tar.gz
    +x  MesaLib-7.8.3.tar.bz2
    +x  MesaLib-7.8.3.zip
    +x  MesaDemos-7.8.3.tar.gz
    +x  MesaDemos-7.8.3.tar.bz2
    +x  MesaDemos-7.8.3.zip
    +x  MesaGLUT-7.8.3.tar.gz
    +x  MesaGLUT-7.8.3.tar.bz2
    +x  MesaGLUT-7.8.3.zip
    +
    + + +

    New features

    +

    None.

    + + +

    Changes

    +
      +
    • The radeon driver should use less memory when searching for a valid mip +image.
    • +
    + + +

    Bug fixes

    +
      +
    • Fix unsupported FB with D24S8 (bug + 29116)
    • +
    • Fix ReadPixels crash when reading depth/stencil from an FBO
    • +
    • Fixed a bug rendering to 16-bit buffers using swrast.
    • +
    • Fixed a state tracker/TGSI bug that caused crashes when using Windows' + memory debugging features.
    • +
    • Fixed an issue rendering to 32-bit channels with swrast (bug + 29487)
    • +
    • GLSL: fix indirect gl_TextureMatrix addressing (bug + 28967)
    • +
    • GLSL: fix for bug + 27216
    • +
    • GLSL: fix zw fragcoord entries in some cases (bug + 29183)
    • +
    • Fix texture env generation in some cases (bug + 28169)
    • +
    • osmesa: a fix for calling OSMesaMakeCurrent twice was applied (bug + 10966
    • +
    • A bug was fixed which could cause Mesa to ignore the + MESA_EXTENSION_OVERRIDE environment variable.
    • +
    • A bug related to specular highlights on backfaces was fixed.
    • +
    • A radeon-specific issue with glCopyTex(Sub)Image was + corrected.
    • +
    • radeon/wine: flush command stream in more cases, fixing wine d3d9 + tests.
    • +
    • r600: fix sin+cos normalization.
    • +
    • r600: (properly) ignore GL_COORD_REPLACE when point sprites are + disabled.
    • +
    • radeon: avoid flushing when the context is not current.
    • +
    • r300c: a bug affecting unaligned BOs was fixed.
    • +
    • r300c: a hardlock caused by ARB_half_float_vertex incorrectly advertised on some chipsets.
    • +
    + + + + diff --git a/docs/relnotes-7.8.html b/docs/relnotes-7.8.html new file mode 100644 index 0000000..1fed087 --- /dev/null +++ b/docs/relnotes-7.8.html @@ -0,0 +1,70 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.8 Release Notes / March 28, 2010

    + +

    +Mesa 7.8 is a new development release. +People who are concerned with stability and reliability should stick +with a previous release or wait for Mesa 7.8.1. +

    +

    +Mesa 7.8 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +5fcfde5383eccb3e9fd665f08a0ea59b  MesaLib-7.8.tar.gz
    +85cb891eecb89aae4fdd3499cccd934b  MesaLib-7.8.tar.bz2
    +754f39593006effc1c8ec3c27c2f1296  MesaLib-7.8.zip
    +c3869c29fa6c3dbdd763f7428d271e12  MesaDemos-7.8.tar.gz
    +9fe8ec184c7f78691e43c4c0a7f97d56  MesaDemos-7.8.tar.bz2
    +063a96947f7b83d4ad789c6cf291b184  MesaDemos-7.8.zip
    +5f4246756b7daaddb4fb3f970cad1e28  MesaGLUT-7.8.tar.gz
    +ca7048a4aa7a437dcc84cc2c7d731336  MesaGLUT-7.8.tar.bz2
    +b54581aeb79b585b158d6a32f94feff2  MesaGLUT-7.8.zip
    +
    + + +

    New features

    +
      +
    • GL_NV_conditional_render extension (swrast driver only) +
    • GL_EXT_draw_buffers2 extension (swrast and i965 driver only) +
    • GL_ARB_fragment_coord_conventions extension (for swrast, i965, and Gallium drivers) +
    • GL_EXT_texture_array extension (swrast driver only) +
    • GL_APPLE_object_purgeable extension (swrast and i945/i965 DRI drivers) +
    • Much improved support for EGL in Mesa +
    • New state trackers for OpenGL ES 1.1 and 2.0 +
    • Dedicated documentation for Gallium +
    + + +

    Bug fixes

    +
      +
    • Massive improvements to the Gallium driver for R300-R500 Radeons; this + driver is now moderately stable but not terribly performant. +
    + + +

    Changes

    +
      +
    • Removed support for color-index rendering
    • +
    • Removed support for GCC versions earlier than 3.3.0.
    • +
    + + + diff --git a/docs/relnotes-7.9.1.html b/docs/relnotes-7.9.1.html new file mode 100644 index 0000000..bef4ef1 --- /dev/null +++ b/docs/relnotes-7.9.1.html @@ -0,0 +1,406 @@ + + + +Mesa Release Notes + + + + + + + + +

    Mesa 7.9.1 Release Notes / January 7, 2011

    + +

    +Mesa 7.9.1 is a bug fix release which fixes bugs found since the 7.9 release. +

    +

    +Mesa 7.9.1 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +78422843ea875ad4eac35b9b8584032b  MesaLib-7.9.1.tar.gz
    +07dc6cfb5928840b8b9df5bd1b3ae434  MesaLib-7.9.1.tar.bz2
    +c8eaea5b3c3d6dee784bd8c2db91c80f  MesaLib-7.9.1.zip
    +ee9ecae4ca56fbb2d14dc15e3a0a7640  MesaGLUT-7.9.1.tar.gz
    +41fc477d524e7dc5c84da8ef22422bea  MesaGLUT-7.9.1.tar.bz2
    +90b287229afdf19317aa989d19462e7a  MesaGLUT-7.9.1.zip
    +
    + + +

    New features

    +

    None.

    + +

    Bug fixes

    +

    This list is likely incomplete.

    +
      +
    • Bug 28800 - [r300c, r300g] Texture corruption with World of Warcraft
    • + +
    • Bug 29420 - Amnesia / HPL2 RendererFeatTest - not rendering correctly
    • + +
    • Bug 29946 - [swrast] piglit valgrind glsl-array-bounds-04 fails
    • + +
    • Bug 30261 - [GLSL 1.20] allowing inconsistent invariant declaration between two vertex shaders
    • + +
    • Bug 30632 - [softpipe] state_tracker/st_manager.c:489: st_context_notify_invalid_framebuffer: Assertion `stfb && stfb->iface == stfbi' failed.
    • + +
    • Bug 30694 - wincopy will crash on Gallium drivers when going to front buffer
    • + +
    • Bug 30787 - Invalid asm shader does not generate draw-time error when used with GLSL shader
    • + +
    • Bug 30993 - getFramebufferAttachmentParameteriv wrongly generates error
    • + +
    • Bug 31101 - [glsl2] abort() in ir_validate::visit_enter(ir_assignment *ir)
    • + +
    • Bug 31193 - [regression] aa43176e break water reflections
    • + +
    • Bug 31194 - The mesa meta save/restore code doesn't ref the current GLSL program
    • + +
    • Bug 31371 - glslparsertest: ir.cpp:358: ir_constant::ir_constant(const glsl_type*, const ir_constant_data*): Assertion `(type->base_type >= 0) && (type->base_type <= 3)' failed.
    • + +
    • Bug 31439 - Crash in glBufferSubData() with size == 0
    • + +
    • Bug 31495 - [i965 gles2c bisected] OpenGL ES 2.0 conformance GL2Tests_GetBIFD_input.run regressed
    • + +
    • Bug 31514 - isBuffer returns true for unbound buffers
    • + +
    • Bug 31560 - [tdfx] tdfx_tex.c:702: error: ‘const struct gl_color_table’ has no member named ‘Format’
    • + +
    • Bug 31617 - Radeon/Compiz: 'failed to attach dri2 front buffer', error case not handled
    • + +
    • Bug 31648 - [GLSL] array-struct-array gets assertion: `(size >= 1) && (size <= 4)' failed.
    • + +
    • Bug 31650 - [GLSL] varying gl_TexCoord fails to be re-declared to different size in the second shader
    • + +
    • Bug 31673 - GL_FRAGMENT_PRECISION_HIGH preprocessor macro undefined in GLSL ES
    • + +
    • Bug 31690 - i915 shader compiler fails to flatten if in Aquarium webgl demo.
    • + +
    • Bug 31832 - [i915] Bad renderbuffer format: 21
    • + +
    • Bug 31841 - [drm:radeon_cs_ioctl] *ERROR* Invalid command stream !
    • + +
    • Bug 31894 - Writing to gl_PointSize with GLES2 corrupts other varyings
    • + +
    • Bug 31909 - [i965] brw_fs.cpp:1461: void fs_visitor::emit_bool_to_cond_code(ir_rvalue*): Assertion `expr->operands[i]->type->is_scalar()' failed.
    • + +
    • Bug 31934 - [gallium] Mapping empty buffer object causes SIGSEGV
    • + +
    • Bug 31983 - [i915 gles2] "if (expression with builtin/varying variables) discard" breaks linkage
    • + +
    • Bug 31985 - [GLSL 1.20] initialized uniform array considered as "unsized"
    • + +
    • Bug 31987 - [gles2] if input a wrong pname(GL_NONE) to glGetBoolean, it will not case GL_INVALID_ENUM
    • + +
    • Bug 32035 - [GLSL bisected] comparing unsized array gets segfault
    • + +
    • Bug 32070 - llvmpipe renders stencil demo incorrectly
    • + +
    • Bug 32273 - assertion fails when starting vdrift 2010 release with shaders enabled
    • + +
    • Bug 32287 - [bisected GLSL] float-int failure
    • + +
    • Bug 32311 - [965 bisected] Array look-ups broken on GM45
    • + +
    • Bug 32520 - [gles2] glBlendFunc(GL_ZERO, GL_DST_COLOR) will result in GL_INVALID_ENUM
    • + +
    • Bug 32825 - egl_glx driver completely broken in 7.9 branch [fix in master]
    • +
    + + +

    Changes

    +

    The full set of changes can be viewed by using the following GIT command:

    + +
    +  git log mesa-7.9..mesa-7.9.1
    +
    + +

    Alex Deucher (5): +

      +
    • r100: revalidate after radeon_update_renderbuffers
    • +
    • r600c: add missing radeon_prepare_render() call on evergreen
    • +
    • r600c: properly align mipmaps to group size
    • +
    • gallium/egl: fix r300 vs r600 loading
    • +
    • r600c: fix some opcodes on evergreen
    • +

    + +

    Aras Pranckevicius (2): +

      +
    • glsl: fix crash in loop analysis when some controls can't be determined
    • +
    • glsl: fix matrix type check in ir_algebraic
    • +

    + +

    Brian Paul (27): +

      +
    • swrast: fix choose_depth_texture_level() to respect mipmap filtering state
    • +
    • st/mesa: replace assertion w/ conditional in framebuffer invalidation
    • +
    • egl/i965: include inline_wrapper_sw_helper.h
    • +
    • mesa: Add missing else in do_row_3D
    • +
    • mesa: add missing formats in _mesa_format_to_type_and_comps()
    • +
    • mesa: handle more pixel types in mipmap generation code
    • +
    • mesa: make glIsBuffer() return false for never bound buffers
    • +
    • mesa: fix glDeleteBuffers() regression
    • +
    • swrast: init alpha value to 1.0 in opt_sample_rgb_2d()
    • +
    • meta: Mask Stencil.Clear against stencilMax in _mesa_meta_Clear
    • +
    • st/mesa: fix mapping of zero-sized buffer objects
    • +
    • mesa: check for posix_memalign() errors
    • +
    • llvmpipe: fix broken stencil writemask
    • +
    • mesa: fix GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME query
    • +
    • mesa: return GL_FRAMEBUFFER_DEFAULT as FBO attachment type
    • +
    • mesa: make glGet*(GL_NONE) generate GL_INVALID_ENUM
    • +
    • mesa: test for cube map completeness in glGenerateMipmap()
    • +
    • tnl: Initialize gl_program_machine memory in run_vp.
    • +
    • tnl: a better way to initialize the gl_program_machine memory
    • +
    • mesa, st/mesa: disable GL_ARB_geometry_shader4
    • +
    • glsl: fix off by one in register index assertion
    • +
    • st/mesa: fix mipmap generation bug
    • +
    • glsl: new glsl_strtod() wrapper to fix decimal point interpretation
    • +
    • mesa: no-op glBufferSubData() on size==0
    • +
    • tdfx: s/Format/_BaseFormat/
    • +
    • st/mesa: fix renderbuffer pointer check in st_Clear()
    • +
    • mesa: Bump the number of bits in the register index.
    • +

    + +

    Chad Versace (5): +

      +
    • glsl: Fix lexer rule for ^=
    • +
    • glsl: Fix ast-to-hir for ARB_fragment_coord_conventions
    • +
    • glsl: Fix ir_expression::constant_expression_value()
    • +
    • glsl: Fix erroneous cast in ast_jump_statement::hir()
    • +
    • glsl: Fix linker bug in cross_validate_globals()
    • +

    + +

    Chia-I Wu (10): +

      +
    • targets/egl: Fix linking with libdrm.
    • +
    • st/vega: Fix version check in context creation.
    • +
    • st/egl: Do not finish a fence that is NULL.
    • +
    • egl: Fix a false negative check in _eglCheckMakeCurrent.
    • +
    • st/mesa: Unreference the sampler view in st_bind_surface.
    • +
    • egl_dri2: Fix __DRI_DRI2 version 1 support.
    • +
    • st/vega: Do not wait NULL fences.
    • +
    • mesa: Do not advertise GL_OES_texture_3D.
    • +
    • egl_glx: Fix borken driver.
    • +
    • egl: Check extensions.
    • +

    + +

    Daniel Lichtenberger (1): +

      +
    • radeon: fix potential segfault in renderbuffer update
    • +

    + +

    Daniel Vetter (1): +

      +
    • r200: revalidate after radeon_update_renderbuffers
    • +

    + +

    Dave Airlie (1): +

      +
    • r300g: fixup rs690 tiling stride alignment calculations.
    • +

    + +

    Eric Anholt (13): +

      +
    • intel: Allow CopyTexSubImage to InternalFormat 3/4 textures, like RGB/RGBA.
    • +
    • glsl: Free the loop state context when we free the loop state.
    • +
    • i965: Allow OPCODE_SWZ to put immediates in the first arg.
    • +
    • i965: Add support for rendering to SARGB8 FBOs.
    • +
    • glsl: Add a helper constructor for expressions that works out result type.
    • +
    • glsl: Fix structure and array comparisions.
    • +
    • glsl: Quiet unreachable no-return-from-function warning.
    • +
    • glsl: Mark the array access for whole-array comparisons.
    • +
    • glsl: Fix flipped return of has_value() for array constants.
    • +
    • mesa: Add getters for the rest of the supported draw buffers.
    • +
    • mesa: Add getters for ARB_copy_buffer's attachment points.
    • +
    • i965: Correct the dp_read message descriptor setup on g4x.
    • +
    • glsl: Correct the marking of InputsRead/OutputsWritten on in/out matrices.
    • +

    + +

    Fabian Bieler (1): +

      +
    • glsl: fix lowering conditional returns in subroutines
    • +

    + +

    Francisco Jerez (3): +

      +
    • meta: Don't leak alpha function/reference value changes.
    • +
    • meta: Fix incorrect rendering of the bitmap alpha component.
    • +
    • meta: Don't try to disable cube maps if the driver doesn't expose the extension.
    • +

    + +

    Henri Verbeet (2): +

      +
    • r600: Evergreen has two extra frac_bits for the sampler LOD state.
    • +
    • st/mesa: Handle wrapped depth buffers in st_copy_texsubimage().
    • +

    + +

    Ian Romanick (33): +

      +
    • Add 7.9 md5sums
    • +
    • docs: Import 7.8.x release notes from 7.8 branch.
    • +
    • docs: download.html does not need to be updated for each release
    • +
    • docs: Update mailing lines from sf.net to freedesktop.org
    • +
    • docs: added news item for 7.9 release
    • +
    • mesa: Validate assembly shaders when GLSL shaders are used
    • +
    • linker: Reject shaders that have unresolved function calls
    • +
    • mesa: Refactor validation of shader targets
    • +
    • glsl: Slightly change the semantic of _LinkedShaders
    • +
    • linker: Improve handling of unread/unwritten shader inputs/outputs
    • +
    • glsl: Commit lexer files changed by previous cherry picking
    • +
    • mesa: Make metaops use program refcounts instead of names.
    • +
    • glsl: Fix incorrect gl_type of sampler2DArray and sampler1DArrayShadow
    • +
    • mesa: Allow query of MAX_SAMPLES with EXT_framebuffer_multisample
    • +
    • glsl: better handling of linker failures
    • +
    • mesa: Fix glGet of ES2's GL_MAX_*_VECTORS properties.
    • +
    • i915: Disallow alpha, red, RG, and sRGB as render targets
    • +
    • glsl/linker: Free any IR discarded by optimization passes.
    • +
    • glsl: Add an optimization pass to simplify discards.
    • +
    • glsl: Add a lowering pass to move discards out of if-statements.
    • +
    • i915: Correctly generate unconditional KIL instructions
    • +
    • glsl: Add unary ir_expression constructor
    • +
    • glsl: Ensure that equality comparisons don't return a NULL IR tree
    • +
    • glcpp: Commit changes in generated files cause by previous commit
    • +
    • glsl: Inherrit type of declared variable from initializer
    • +
    • glsl: Inherrit type of declared variable from initializer after processing assignment
    • +
    • linker: Ensure that unsized arrays have a size after linking
    • +
    • linker: Fix regressions caused by previous commit
    • +
    • linker: Allow built-in arrays to have different sizes between shader stages
    • +
    • ir_to_mesa: Don't generate swizzles for record derefs of non-scalar/vectors
    • +
    • Refresh autogenerated file builtin_function.cpp.
    • +
    • docs: Initial set of release notes for 7.9.1
    • +
    • mesa: set version string to 7.9.1
    • +

    + +

    Julien Cristau (1): +

      +
    • Makefile: don't include the same files twice in the tarball
    • +

    + +

    Kenneth Graunke (19): +

      +
    • glcpp: Return NEWLINE token for newlines inside multi-line comments.
    • +
    • generate_builtins.py: Output large strings as arrays of characters.
    • +
    • glsl: Fix constant component count in vector constructor emitting.
    • +
    • ir_dead_functions: Actually free dead functions and signatures.
    • +
    • glcpp: Define GL_FRAGMENT_PRECISION_HIGH if GLSL version >= 1.30.
    • +
    • glsl: Unconditionally define GL_FRAGMENT_PRECISION_HIGH in ES2 shaders.
    • +
    • glsl: Fix constant expression handling for <, >, <=, >= on vectors.
    • +
    • glsl: Use do_common_optimization in the standalone compiler.
    • +
    • glsl: Don't inline function prototypes.
    • +
    • glsl: Add a virtual as_discard() method.
    • +
    • glsl: Remove "discard" support from lower_jumps.
    • +
    • glsl: Refactor get_num_operands.
    • +
    • glcpp: Don't emit SPACE tokens in conditional_tokens production.
    • +
    • glsl: Clean up code by adding a new is_break() function.
    • +
    • glsl: Consider the "else" branch when looking for loop breaks.
    • +
    • Remove OES_compressed_paletted_texture from the ES2 extension list.
    • +
    • glsl/builtins: Compute the correct value for smoothstep(vec, vec, vec).
    • +
    • Fix build on systems where "python" is python 3.
    • +
    • i965: Internally enable GL_NV_blend_square on ES2.
    • +

    + +

    Kristian Høgsberg (1): +

      +
    • i965: Don't write mrf assignment for pointsize output
    • +

    + +

    Luca Barbieri (1): +

      +
    • glsl: Unroll loops with conditional breaks anywhere (not just the end)
    • +

    + +

    Marek Olšák (17): +

      +
    • r300g: fix microtiling for 16-bits-per-channel formats
    • +
    • r300g: fix texture border for 16-bits-per-channel formats
    • +
    • r300g: add a default channel ordering of texture border for unhandled formats
    • +
    • r300g: fix texture border color for all texture formats
    • +
    • r300g: fix rendering with no vertex elements
    • +
    • r300/compiler: fix rc_rewrite_depth_out for it to work with any instruction
    • +
    • r300g: fix texture border color once again
    • +
    • r300g: fix texture swizzling with compressed textures on r400-r500
    • +
    • r300g: disable ARB_texture_swizzle if S3TC is enabled on r3xx-only
    • +
    • mesa, st/mesa: fix gl_FragCoord with FBOs in Gallium
    • +
    • st/mesa: initialize key in st_vp_varient
    • +
    • r300/compiler: fix swizzle lowering with a presubtract source operand
    • +
    • r300g: fix rendering with a vertex attrib having a zero stride
    • +
    • ir_to_mesa: Add support for conditional discards.
    • +
    • r300g: finally fix the texture corruption on r3xx-r4xx
    • +
    • mesa: fix texel store functions for some float formats
    • +
    • r300/compiler: disable the rename_regs pass for loops
    • +

    + +

    Mario Kleiner (1): +

      +
    • mesa/r300classic: Fix dri2Invalidate/radeon_prepare_render for page flipping.
    • +

    + +

    Peter Clifton (1): +

      +
    • intel: Fix emit_linear_blit to use DWORD aligned width blits
    • +

    + +

    Robert Hooker (2): +

      +
    • intel: Add a new B43 pci id.
    • +
    • egl_dri2: Add missing intel chip ids.
    • +

    + +

    Roland Scheidegger (1): +

      +
    • r200: fix r200 large points
    • +

    + +

    Thomas Hellstrom (17): +

      +
    • st/xorg: Don't try to use option values before processing options
    • +
    • xorg/vmwgfx: Make vmwarectrl work also on 64-bit servers
    • +
    • st/xorg: Add a customizer option to get rid of annoying cursor update flicker
    • +
    • xorg/vmwgfx: Don't hide HW cursors when updating them
    • +
    • st/xorg: Don't try to remove invalid fbs
    • +
    • st/xorg: Fix typo
    • +
    • st/xorg, xorg/vmwgfx: Be a bit more frendly towards cross-compiling environments
    • +
    • st/xorg: Fix compilation errors for Xservers compiled without Composite
    • +
    • st/xorg: Don't use deprecated x*alloc / xfree functions
    • +
    • xorg/vmwgfx: Don't use deprecated x*alloc / xfree functions
    • +
    • st/xorg: Fix compilation for Xservers >= 1.10
    • +
    • mesa: Make sure we have the talloc cflags when using the talloc headers
    • +
    • egl: Add an include for size_t
    • +
    • mesa: Add talloc includes for gles
    • +
    • st/egl: Fix build for include files in nonstandard places
    • +
    • svga/drm: Optionally resolve calls to powf during link-time
    • +
    • gallium/targets: Trivial crosscompiling fix
    • +

    + +

    Tom Stellard (7): +

      +
    • r300/compiler: Make sure presubtract sources use supported swizzles
    • +
    • r300/compiler: Fix register allocator's handling of loops
    • +
    • r300/compiler: Fix instruction scheduling within IF blocks
    • +
    • r300/compiler: Use zero as the register index for unused sources
    • +
    • r300/compiler: Ignore alpha dest register when replicating the result
    • +
    • r300/compiler: Use correct swizzles for all presubtract sources
    • +
    • r300/compiler: Don't allow presubtract sources to be remapped twice
    • +

    + +

    Vinson Lee (1): +

      +
    • glsl: Fix 'control reaches end of non-void function' warning.
    • +

    + +

    richard (1): +

      +
    • r600c : inline vertex format is not updated in an app, switch to use vfetch constants. For the 7.9 and 7.10 branches as well.
    • +

    + + + diff --git a/docs/relnotes-7.9.2.html b/docs/relnotes-7.9.2.html new file mode 100644 index 0000000..e8e1e4d --- /dev/null +++ b/docs/relnotes-7.9.2.html @@ -0,0 +1,336 @@ + + + +Mesa Release Notes + + + + + + + + +

    Mesa 7.9.2 Release Notes / March 2, 2011

    + +

    +Mesa 7.9.2 is a bug fix release which fixes bugs found since the 7.9.1 release. +

    +

    +Mesa 7.9.2 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +eb4ab8c1a03386def3ea34b1358e9cda  MesaLib-7.9.2.tar.gz
    +8f6d1474912787ce13bd35f3bae9938a  MesaLib-7.9.2.tar.bz2
    +427a81dd43ac97603768dc5c6af3df26  MesaLib-7.9.2.zip
    +aacb8f4db997e346db40c6066942140a  MesaGLUT-7.9.2.tar.gz
    +18abe6cff4fad8ad4752c7b7ab548e5d  MesaGLUT-7.9.2.tar.bz2
    +3189e5732d636c71baf3d8bc23ce7b11  MesaGLUT-7.9.2.zip
    +
    + + +

    New features

    +

    None.

    + +

    Bug fixes

    +

    This list is likely incomplete.

    +
      +
    • Fix an off-by-one bug in a vsplit assertion.
    • +
    • Fix incorrect handling of layout qualifier +with in, out, attribute, and varying.
    • + +
    • Fix an i965 GPU hang in GLSL shaders that contain an unconditional discard statement.
    • + +
    • Fix an i965 shader bug where the negative absolute value was generated instead of the absolute value of a negation.
    • + +
    • Fix numerous issues handling precision qualifiers in GLSL ES.
    • + +
    • Fixed a few GLX protocol encoder bugs (Julien Cristau)
    • + +
    • Assorted Gallium llvmpipe driver bug fixes
    • + +
    • Assorted Mesa/Gallium state tracker bug fixes
    • + +
    • Bug 26795 - gl_FragCoord off by one in Gallium drivers.
    • + +
    • Bug 29164 - [GLSL 1.20] invariant variable shouldn't be used before declaration
    • + +
    • Bug 29823 - GetUniform[if]v busted
    • + +
    • Bug 29927 - [glsl2] fail to compile shader with constructor for array of struct type
    • + +
    • Bug 30156 - [i965] After updating to Mesa 7.9, Civilization IV starts to show garbage
    • + +
    • Bug 31923 - [GLSL 1.20] allowing inconsistent centroid declaration between two vertex shaders
    • + +
    • Bug 31925 - [GLSL 1.20] "#pragma STDGL invariant(all)" fail
    • + +
    • Bug 32214 - [gles2]no link error happens when missing vertex shader or frag shader
    • + +
    • Bug 32375 - [gl gles2] Not able to get the attribute by function glGetVertexAttribfv
    • + +
    • Bug 32541 - Segmentation Fault while running an HDR (high dynamic range) rendering demo
    • + +
    • Bug 32569 - [gles2] glGetShaderPrecisionFormat not implemented yet
    • + +
    • Bug 32695 - [glsl] SIGSEGV glcpp/glcpp-parse.y:833
    • + +
    • Bug 32831 - [glsl] division by zero crashes GLSL compiler
    • + +
    • Bug 32910 - Keywords 'in' and 'out' not handled properly for GLSL 1.20 shaders
    • + +
    • Bug 33219 -[GLSL bisected] implicit sized array triggers segfault in ir_to_mesa_visitor::copy_propagate
    • + +
    • Bug 33306 - GLSL integer division by zero crashes GLSL compiler
    • + +
    • Bug 33308 -[glsl] ast_to_hir.cpp:3016: virtual ir_rvalue* ast_jump_statement::hir(exec_list*, _mesa_glsl_parse_state*): Assertion `ret != __null' failed.
    • + +
    • Bug 33316 - uniform array will be allocate one line more and initialize it when it was freed will abort
    • + +
    • Bug 33386 - Dubious assembler in read_rgba_span_x86.S
    • + +
    • Bug 33388 - Dubious assembler in xform4.S
    • + +
    • Bug 33433 - Error in x86-64 API dispatch code.
    • + +
    • Bug 33507 - [glsl] GLSL preprocessor modulus by zero crash
    • + +
    • Bug 33508 - [glsl] GLSL compiler modulus by zero crash
    • + +
    • Bug 33916 - Compiler accepts reserved operators % and %=
    • + +
    • Bug 34047 - Assert in _tnl_import_array() when using GLfixed vertex datatypes with GLESv2
    • + +
    • Bug 34114 - Sun Studio build fails due to standard library functions not being in global namespace
    • + +
    • Bug 34198 - [GLSL] implicit sized array with index 0 used gets assertion
    • + +
    • Ubuntu bug 691653 - compiz crashes when using alt-tab (the radeon driver kills it)
    • + +
    • Meego bug 13005 - Graphics GLSL issue lead to camera preview fail on Pinetrail
    • + + + +
    + + +

    Changes

    +

    The full set of changes can be viewed by using the following GIT command:

    + +
    +  git log mesa-7.9.1..mesa-7.9.2
    +
    + +

    Alberto Milone (1): +

      +
    • r600c: add evergreen ARL support.
    • +

    + +

    Brian Paul (19): +

      +
    • draw: Fix an off-by-one bug in a vsplit assertion.
    • +
    • mesa: fix a few format table mistakes, assertions
    • +
    • mesa: fix num_draw_buffers==0 in fixed-function fragment program generation
    • +
    • mesa: don't assert in GetIntegerIndexed, etc
    • +
    • mesa: check for dummy renderbuffer in _mesa_FramebufferRenderbufferEXT()
    • +
    • llvmpipe: make sure binning is active when we begin/end a query
    • +
    • st/mesa: fix incorrect fragcoord.x translation
    • +
    • softpipe: fix off-by-one error in setup_fragcoord_coeff()
    • +
    • cso: fix loop bound in cso_set_vertex_samplers()
    • +
    • st/mesa: set renderbuffer _BaseFormat in a few places
    • +
    • st/mesa: fix the default case in st_format_datatype()
    • +
    • st/mesa: need to translate clear color according to surface's base format
    • +
    • docs: update 7.9.2 release notes with Brian's cherry-picks
    • +
    • docs: add links to 7.9.1 and 7.9.2 release notes
    • +
    • mesa: include compiler.h for ASSERT macro
    • +
    • glsl: add ir_shader case in switch stmt to silence warning
    • +
    • glsl2: fix signed/unsigned comparison warning
    • +
    • mesa: implement glGetShaderPrecisionFormat()
    • +
    • docs: updated environment variable list
    • +

    + +

    Bryce Harrington (1): +

      +
    • r300g: Null pointer check for buffer deref in gallium winsys
    • +

    + +

    Chad Versace (14): +

      +
    • glsl: At link-time, check that globals have matching centroid qualifiers
    • +
    • glcpp: Fix segfault when validating macro redefinitions
    • +
    • glsl: Fix parser rule for type_specifier
    • +
    • glsl: Change default value of ast_type_specifier::precision
    • +
    • glsl: Add semantic checks for precision qualifiers
    • +
    • glsl: Add support for default precision statements
    • +
    • glsl: Remove redundant semantic check in parser
    • +
    • glsl: Fix semantic checks on precision qualifiers
    • +
    • glsl: Fix segfault due to missing printf argument
    • +
    • glsl: Mark 'in' variables at global scope as read-only
    • +
    • glcpp: Raise error when modulus is zero
    • +
    • glsl: Set operators '%' and '%=' to be reserved when GLSL < 1.30
    • +
    • glsl: Reinstate constant-folding for division by zero
    • +
    • tnl: Add support for datatype GL_FIXED in vertex arrays
    • +

    + +

    Chia-I Wu (1): +

      +
    • mesa: Add glDepthRangef and glClearDepthf to APIspec.xml.
    • +

    + +

    Chris Wilson (1): +

      +
    • intel: Check for unsupported texture when finishing using as a render target
    • +

    + +

    Cyril Brulebois (1): +

      +
    • Point to bugs.freedesktop.org rather than bugzilla.freedesktop.org
    • +

    + +

    Dave Airlie (2): +

      +
    • radeon/r200: fix fbo-clearmipmap + gen-teximage
    • +
    • radeon: avoid segfault on 3D textures.
    • +

    + +

    Dimitry Andric (4): +

      +
    • mesa: s/movzx/movzbl/
    • +
    • mesa: s/movzxw/movzwl/ in read_rgba_span_x86.S
    • +
    • glapi: adding @ char before type specifier in glapi_x86.S
    • +
    • glapi: add @GOTPCREL relocation type
    • +

    + +

    Eric Anholt (11): +

      +
    • i965: Avoid double-negation of immediate values in the VS.
    • +
    • docs: Add a relnote for the Civ IV on i965.
    • +
    • i965/vs: When MOVing to produce ABS, strip negate of the operand.
    • +
    • glsl: Fix the lowering of variable array indexing to not lose write_masks.
    • +
    • intel: Make renderbuffer tiling choice match texture tiling choice.
    • +
    • glapi: Add entrypoints and enums for GL_ARB_ES2_compatibility.
    • +
    • mesa: Add extension enable bit for GL_ARB_ES2_compatibility.
    • +
    • mesa: Add actual support for glReleaseShaderCompiler from ES2.
    • +
    • mesa: Add support for glDepthRangef and glClearDepthf.
    • +
    • mesa: Add getters for ARB_ES2_compatibility MAX_*_VECTORS.
    • +
    • mesa: Add getter for GL_SHADER_COMPILER with ARB_ES2_compatibility.
    • +

    + +

    Ian Romanick (42): +

      +
    • docs: Add 7.9.1 md5sums
    • +
    • glsl: Support the 'invariant(all)' pragma
    • +
    • glcpp: Generate an error for division by zero
    • +
    • glsl: Add version_string containing properly formatted GLSL version
    • +
    • glsl & glcpp: Refresh autogenerated lexer and parser files.
    • +
    • glsl: Disallow 'in' and 'out' on globals in GLSL 1.20
    • +
    • glsl: Track variable usage, use that to enforce semantics
    • +
    • glsl: Allow 'in' and 'out' when 'layout' is also available
    • +
    • docs: Initial set of release notes for 7.9.2
    • +
    • mesa: bump version to 7.9.2-devel
    • +
    • docs: Update 7.9.2 release notes
    • +
    • i965: Make OPCODE_KIL_NV do its work in a temp, not the null reg!
    • +
    • glsl: Refresh autogenerated lexer and parser files.
    • +
    • glsl: Don't assert when the value returned by a function has no rvalue
    • +
    • linker: Set sizes for non-global arrays as well
    • +
    • linker: Propagate max_array_access while linking functions
    • +
    • docs: Update 7.9.2 release notes
    • +
    • Use C-style system headers in C++ code to avoid issues with std:: namespace
    • +
    • mesa: glGetUniform only returns a single element of an array
    • +
    • linker: Generate link errors when ES shaders are missing stages
    • +
    • mesa: Fix error checks in GetVertexAttrib functions
    • +
    • docs: Update 7.9.2 release notes
    • +
    • mesa: Remove unsupported OES extensions
    • +
    • glapi: Regenerate for GL_ARB_ES2_compatibility.
    • +
    • mesa: Connect glGetShaderPrecisionFormat into the dispatch table
    • +
    • i965: Set correct values for range/precision of fragment shader types
    • +
    • i915: Set correct values for range/precision of fragment shader types
    • +
    • intel: Fix typeos from 3d028024 and 790ff232
    • +
    • glsl: Ensure that all GLSL versions are supported in the stand-alone compiler
    • +
    • glsl: Reject shader versions not supported by the implementation
    • +
    • mesa: Initial size for secondary color array is 3
    • +
    • glcpp: Regenerate files from recent cherry picks
    • +
    • glsl: Finish out the reduce/reduce error fixes
    • +
    • glsl: Regenerate compiler files from cherry picks
    • +
    • linker: Fix off-by-one error implicit array sizing
    • +
    • i915: Only mark a register as available if all components are written
    • +
    • i915: Calculate partial result to temp register first
    • +
    • i915: Force lowering of all types of indirect array accesses in the FS
    • +
    • docs: Update 7.9.2 release notes for recent cherry picks
    • +
    • docs: Clean up bug fixes list
    • +
    • intel: Remove driver date and related bits from renderer string
    • +
    • mesa: set version string to 7.9.2 (final)
    • +

    + +

    Jian Zhao (1): +

      +
    • mesa: fix an error in uniform arrays in row calculating.
    • +

    + +

    Julien Cristau (3): +

      +
    • glx: fix request lengths
    • +
    • glx: fix GLXChangeDrawableAttributesSGIX request
    • +
    • glx: fix length of GLXGetFBConfigsSGIX
    • +

    + +

    Keith Packard (1): +

      +
    • glsl: Eliminate reduce/reduce conflicts in glsl grammar
    • +

    + +

    Kenneth Graunke (12): +

      +
    • glsl: Expose a public glsl_type::void_type const pointer.
    • +
    • glsl: Don't bother unsetting a destructor that was never set.
    • +
    • glsl, i965: Remove unnecessary talloc includes.
    • +
    • glcpp: Remove use of talloc reference counting.
    • +
    • ralloc: Add a fake implementation of ralloc based on talloc.
    • +
    • Convert everything from the talloc API to the ralloc API.
    • +
    • ralloc: a new MIT-licensed recursive memory allocator.
    • +
    • Remove talloc from the make and automake build systems.
    • +
    • Remove talloc from the SCons build system.
    • +
    • Remove the talloc sources from the Mesa repository.
    • +
    • glsl: Fix use of uninitialized values in _mesa_glsl_parse_state ctor.
    • +
    • glsl: Use reralloc instead of plain realloc.
    • +

    + +

    Marek Olšák (3): +

      +
    • docs: fix messed up names with special characters in relnotes-7.9.1
    • +
    • mesa: fix texture3D mipmap generation for UNSIGNED_BYTE_3_3_2
    • +
    • st/dri: Track drawable context bindings
    • +

    + +

    Paulo Zanoni (1): +

      +
    • dri_util: fail driCreateNewScreen if InitScreen is NULL
    • +

    + +

    Sam Hocevar (2): +

      +
    • docs: add glsl info
    • +
    • docs: fix glsl_compiler name
    • +

    + +

    Vinson Lee (1): +

      +
    • ralloc: Add missing va_end following va_copy.
    • +

    + +

    nobled (1): +

      +
    • glx: Put null check before use
    • +

    +

    + + + diff --git a/docs/relnotes-7.9.html b/docs/relnotes-7.9.html new file mode 100644 index 0000000..fe1fd5e --- /dev/null +++ b/docs/relnotes-7.9.html @@ -0,0 +1,137 @@ + + +Mesa Release Notes + + + + + + + +

    Mesa 7.9 Release Notes / October 4, 2010

    + +

    +Mesa 7.9 is a new development release. +People who are concerned with stability and reliability should stick +with a previous release or wait for Mesa 7.9.1. +

    +

    +Mesa 7.9 implements the OpenGL 2.1 API, but the version reported by +glGetString(GL_VERSION) depends on the particular driver being used. +Some drivers don't support all the features required in OpenGL 2.1. +

    +

    +See the Compiling/Installing page for prerequisites +for DRI hardware acceleration. +

    + + +

    MD5 checksums

    +
    +ed65ab425b25895c7f473d0a5e6e64f8  MesaLib-7.9.tar.gz
    +82c740c49d572baa6da2b1a1eee90bca  MesaLib-7.9.tar.bz2
    +cd2b6ecec759b0457475e94bbb38fedb  MesaLib-7.9.zip
    +7b54af9fb9b1f6a1a65db2520f50848f  MesaGLUT-7.9.tar.gz
    +20d07419d1929f833fdb36bced290ad5  MesaGLUT-7.9.tar.bz2
    +62a7edecd7c92675cd6029b05217eb0a  MesaGLUT-7.9.zip
    +
    + + +

    New features

    +
      +
    • New, improved GLSL compiler written by Intel. + See the Shading Language page for + more information. +
    • New, very experimental Gallium driver for R600-R700 Radeons. +
    • Support for AMD Evergreen-based Radeons (HD 5xxx) +
    • GL_EXT_timer_query extension (i965 driver and softpipe only) +
    • GL_EXT_framebuffer_multisample extension (intel drivers, MAX_SAMPLES = 1) +
    • GL_ARB_texture_swizzle extension (alias of GL_EXT_texture_swizzle) +
    • GL_ARB_draw_elements_base_vertex, GL_ARB_fragment_program_shadow, + GL_ARB_window_pos, GL_EXT_gpu_program_parameters, + GL_ATI_texture_env_combine3, GL_MESA_pack_invert, and GL_OES_EGL_image + extensions in Gallium drivers +
    • GL_ARB_depth_clamp and GL_NV_depth_clamp extensions (in nv50 and r600 + Gallium drivers) +
    • GL_ARB_half_float_vertex extension (in nvfx, r300, r600, softpipe, + and llvmpipe Gallium drivers) +
    • GL_EXT_draw_buffers2 (in nv50, r600, softpipe, and llvmpipe Gallium + drivers) +
    • GL_EXT_texture_swizzle (in nvfx, r300, r600, softpipe, and llvmpipe + Gallium drivers) +
    • GL_ATI_texture_mirror_once (in nvfx, nv50, r300, r600, softpipe, and + llvmpipe Gallium drivers) +
    • GL_NV_conditional_render (in r300 Gallium driver) +
    • Initial "signs of life" support for Sandybridge hardware in i965 DRI + driver. +
    + + +

    Bug fixes

    +

    This list is likely incomplete.

    +
      +
    • Massive improvements to the Gallium driver for R300-R500 Radeons; this + driver is now considered stable for use as a DRI (OpenGL) driver. +
    • Bug 10908 - GLSL: gl_FogParamaters gl_Fog built-in uniform not functioning
    • +
    • Bug 13753 - Numerous bugs in GLSL uniform handling
    • +
    • Bug 16854 - GLSL function call at global scope causes SEGV
    • +
    • Bug 16856 - GLSL indexing of unsized array results in assertion failure
    • +
    • Bug 18659 - Crash in shader/slang/slang_codegen.c _slang_gen_function_call_name()
    • +
    • Bug 19089 - [GLSL] glsl1/shadow2D() cases fail
    • +
    • Bug 22622 - [GM965 GLSL] noise*() cause GPU lockup
    • +
    • Bug 23743 - For loop from 0 to 0 not optimized out
    • +
    • Bug 24553 - shader compilation times explode when using more () pairs
    • +
    • Bug 25664 - [GLSL] re-declaring an empty array fails to compile
    • +
    • Bug 25769 - [GLSL] "float" can be implicitly converted to "int"
    • +
    • Bug 25808 - [GLSL] const variable is modified successfully
    • +
    • Bug 25826 - [GLSL] declaring an unsized array then re-declaring with a size fails
    • +
    • Bug 25827 - [GLSL] vector constructor accepts too many arguments successfully
    • +
    • Bug 25829 - [GLSL] allowing non-void function without returning value
    • +
    • Bug 25830 - [GLSL] allowing non-constant-expression as const declaration initializer
    • +
    • Bug 25877 - [GLSL 1.10] implicit conversion from "int" to "float" should not be allowed
    • +
    • Bug 25878 - [GLSL] sampler is converted to int successfully
    • +
    • Bug 25994 - [GM45][GLSL] 'return' statement in vertex shader unsupported
    • +
    • Bug 25999 - [GLSL] embedded structure constructor fails to compile
    • +
    • Bug 26000 - [GLSL] allowing different parameter qualifier between the function definition and declaration
    • +
    • Bug 26001 - [GLSL 1.10] constructing matrix from matrix succeeds
    • +
    • Bug 26224 - [GLSL] Cannot get location of a uniform struct member
    • +
    • Bug 26990 - [GLSL] variable declaration in "while" fails to compile
    • +
    • Bug 27004 - [GLSL] allowing macro redefinition
    • +
    • Bug 27060 - [965] piglit glsl-fs-raytrace failure due to lack of function calls.
    • +
    • Bug 27216 - Assignment with a function call in an if statement causes an assertion failure
    • +
    • Bug 27261 - GLSL Compiler fails on the following vertex shader
    • +
    • Bug 27265 - GLSL Compiler doesnt link the attached vertex shader
    • +
    • Bug 27388 - [i965] piglit glsl-vs-arrays failure
    • +
    • Bug 27403 - GLSL struct causing "Invalid src register file ..." error
    • +
    • Bug 27914 - GLSL compiler uses MUL+ADD where it could use MAD
    • +
    • Bug 28055 - glsl-texcoord-array fails GLSL compilation
    • +
    • Bug 28374 - SIGSEGV shader/slang/slang_typeinfo.c:534
    • +
    • Bug 28748 - [i965] uninlined function calls support
    • +
    • Bug 28833 - piglit/shaders/glsl-texcoord-array fail
    • +
    • Bug 28834 - Add support for system fpclassify to GL_OES_query_matrix function for OpenBSD / NetBSD
    • +
    • Bug 28837 - varying vec4 index support
    • +
    • Bug 28845 - The GLU tesselator code has some warnings
    • +
    • Bug 28889 - [regression] wine game crash
    • +
    • Bug 28894 - slang build fails if absolute path contains spaces
    • +
    • Bug 28913 - [GLSL] allowing two version statements
    • +
    • Bug 28931 - Floating Point Exception in Warzone2100 Trunk version
    • +
    • Bug 28966 - [r300g] Dynamic branching 3 demo does not run
    • +
    • Bug 28967 - slang/slang_emit.c:350: storage_to_src_reg: Assertion `index >= 0' failed.
    • +
    • Bug 29013 - [r300g] translate_rgb_op: unknown opcode ILLEGAL OPCODE
    • +
    • Bug 29020 - [r300g] Wine d3d9 tests hardlock
    • +
    • Bug 29910 - Mesa advertises bogus GL_ARB_shading_language_120
    • +
    • Bug 30196 - [GLSL] gl_TextureMatrix{Inverse,Transpose,InverseTranspose} unsupported
    • +
    + + +

    Changes

    +
      +
    • The Mesa demo/test programs have been moved into a separate git +repository. +
    • GL/glext.h file upgraded to version 64 +
    • GL/glxext.h file upgraded to version 32 +
    • GL/wglext.h file upgraded to version 22 +
    + + + diff --git a/docs/relnotes.html b/docs/relnotes.html new file mode 100644 index 0000000..2f4872e --- /dev/null +++ b/docs/relnotes.html @@ -0,0 +1,87 @@ + + +Mesa Release Notes + + + + + +

    Release Notes

    + +

    +The release notes summarize what's new or changed in each Mesa release. +

    + + +Versions of Mesa prior to 6.4 are summarized in the +versions file and the following release notes. +

    + + + + + + diff --git a/docs/repository.html b/docs/repository.html new file mode 100644 index 0000000..954bd0d --- /dev/null +++ b/docs/repository.html @@ -0,0 +1,216 @@ + + +Code Repository + + + + + +

    Code Repository

    + +

    +Mesa uses git +as its source code management system. +

    + +The master git repository is hosted on +freedesktop.org. +

    + +

    +You may access the repository either as an +anonymous user (read-only) or as a +developer +(read/write). +

    + +

    +You may also +browse the main Mesa git repository and the +Mesa demos and tests git repository. +

    + + + +

    Anonymous git Access

    + +

    +To get the Mesa sources anonymously (read-only): +

    + +
      +
    1. Install the git software on your computer if needed.

      +
    2. Get an initial, local copy of the repository with: +
      +    git clone git://anongit.freedesktop.org/git/mesa/mesa
      +    
      +
    3. Later, you can update your tree from the master repository with: +
      +    git pull origin
      +    
      +
    4. If you also want the Mesa demos/tests repository: +
      +    git clone git://anongit.freedesktop.org/git/mesa/demos
      +    
      +
    + + +
    +

    Developer git Access

    + +

    +Mesa developers need to first have an account on +freedesktop.org. +To get an account, please ask Brian or the other Mesa developers for +permission. +Then, if there are no objections, follow this + +procedure. +

    + +

    +Once your account is established: +

    + +
      +
    1. Install the git software on your computer if needed.

      +
    2. Get an initial, local copy of the repository with: +
      +    git clone git+ssh://username@git.freedesktop.org/git/mesa/mesa
      +    
      + Replace username with your actual login name.

      +
    3. Later, you can update your tree from the master repository with: +
      +    git pull origin
      +    
      +
    4. If you also want the Mesa demos/tests repository: +
      +    git clone git+ssh://username@git.freedesktop.org/git/mesa/demos
      +    
      +
    + + +

    Windows Users

    + +

    +If you're +using git on Windows you'll want to enable automatic CR/LF conversion in +your local copy of the repository: +

    +
    +   git config --global core.autocrlf true
    +
    + +

    +This will cause git to convert all text files to CR+LF on checkout, +and to LF on commit. +

    +

    +Unix users don't need to set this option. +

    +
    + + + +

    Development Branches

    + +

    +At any given time, there may be several active branches in Mesa's +repository. +Generally, the trunk contains the latest development (unstable) +code while a branch has the latest stable code. +

    + +

    +The command git-branch will list all available branches. +

    + +

    +Questions about branch status/activity should be posted to the +mesa3d-dev mailing list. +

    + +

    Developer Git Tips

    + +
      +
    1. Setting up to edit the master branch +

      +If you try to do a pull by just saying git pull +and git complains that you have not specified a +branch, try: +

      +    git config branch.master.remote origin
      +    git config branch.master.merge master
      +
      +Otherwise, you have to say git pull origin master +each time you do a pull. +

      +
    2. Small changes to master +

      +If you are an experienced git user working on substancial modifications, +you are probably +working on a separate branch and would rebase your branch prior to +merging with master. +But for small changes to the master branch itself, +you also need to use the rebase feature in order to avoid an +unnecessary and distracting branch in master. +

      +

      +If it has been awhile since you've done the initial clone, try +

      +    git pull
      +
      +to get the latest files before you start working. +

      +

      +Make your changes and use +

      +    git add <files to commit>
      +    git commit
      +
      +to get your changes ready to push back into the fd.o repository. +

      +

      +It is possible (and likely) that someone has changed master since +you did your last pull. Even if your changes do not conflict with +their changes, git will make a fast-forward +merge branch, branching from the point in time +where you did your last pull and merging it to a point after the other changes. +

      +

      +To avoid this, +

      +    git pull --rebase
      +    git push
      +
      +If you are familiar with CVS or similar system, this is similar to doing a + cvs update in order to update your source tree to +the current repository state, instead of the time you did the last update. +(CVS doesn't work like git in this respect, but this is easiest way +to explain it.) +
      +In any case, your repository now looks like you made your changes after +all the other changes. +

      +

      +If the rebase resulted in conflicts or changes that could affect +the proper operation of your changes, you'll need to investigate +those before doing the push. +

      +

      +If you want the rebase action to be the default action, then +

      +    git config branch.master.rebase true
      +    git config --global branch.autosetuprebase=always
      +
      +

      +See Understanding Git Conceptually for a fairly clear explanation about all of this. +

      +
    + + + + + diff --git a/docs/science.html b/docs/science.html new file mode 100644 index 0000000..f55cf31 --- /dev/null +++ b/docs/science.html @@ -0,0 +1,72 @@ + + +Science and Technical + + + + + +

    Science and Technical

    + +
      +
    • Ch - OpenGL bindings for the Ch C/C++ interpreter +
    • CLEO3D - event displayer for the CLEOIII detector +
    • DINO - Visualizing + Structural Biology +
    • General + Mesh Viewer (GMV) - scientific vis. +
    • GiD - finite element + analysis +
    • glpoisson - A finite + element analysis program that simulates wave in an arbitrary region. +
    • GLWaves - + Electromagnetic wave visualization +
    • Gmsh - + finite element mesh generator / viewer +
    • gOpenMol + - computational chemistry +
    • GPS 3D - GPS-based map visualization +
    • Hitchhiker + - virtual solar system +
    • Hydra - physics + and engineering pkg +
    • Light Speed + - a real-time, interactive relativistic simulator +
    • LinkWinds - scientific + vis +
    • MathGL3d - Mathematica viewer +
    • Mathworks + - mathematics and visualization +
    • Medit - 3D surface mesh viewer +
    • MOLMOL + - molecular modeling and analysis +
    • Molscript - molecular + modeling +
    • +
    • OpenDX - Data visualization + system +
    • +
    • ORSA - An interactive tool for Celestial Mechanics +
    • +
    • ParaView - Scientific visualization package +
    • +
    • PHLEX - Finite element vis +
    • ROOT - Object Oriented Data + Analysis Framework +
    • SLFFEA - GNU finite element + package +
    • Spock - molecular + modeling +
    • Ssystem - solar + system simulation +
    • SPARROW - robot simulation +
    • Vis5D + - atmospheric visualization +
    • VMD - molecular + modeling +
    • Webots - 3-D mobile + robot simulator +
    + + + \ No newline at end of file diff --git a/docs/shading.html b/docs/shading.html new file mode 100644 index 0000000..aba3959 --- /dev/null +++ b/docs/shading.html @@ -0,0 +1,268 @@ + + +Shading Language Support + + + + + +

    Shading Language Support

    + +

    +This page describes the features and status of Mesa's support for the + +OpenGL Shading Language. +

    + +

    +Contents +

    + + + + + +

    Environment Variables

    + +

    +The MESA_GLSL environment variable can be set to a comma-separated +list of keywords to control some aspects of the GLSL compiler and shader +execution. These are generally used for debugging. +

    +
      +
    • dump - print GLSL shader code to stdout at link time +
    • log - log all GLSL shaders to files. + The filenames will be "shader_X.vert" or "shader_X.frag" where X + the shader ID. +
    • nopt - disable compiler optimizations +
    • opt - force compiler optimizations +
    • uniform - print message to stdout when glUniform is called +
    • nopvert - force vertex shaders to be a simple shader that just transforms + the vertex position with ftransform() and passes through the color and + texcoord[0] attributes. +
    • nopfrag - force fragment shader to be a simple shader that passes + through the color attribute. +
    • useprog - log glUseProgram calls to stderr +
    +

    +Example: export MESA_GLSL=dump,nopt +

    + + +
    +

    GLSL Version

    + +

    +The GLSL compiler currently supports version 1.20 of the shading language. +

    + +

    +Several GLSL extensions are also supported: +

    +
      +
    • GL_ARB_draw_buffers +
    • GL_ARB_texture_rectangle +
    • GL_ARB_fragment_coord_conventions +
    • GL_EXT_texture_array +
    + + +
    +

    Unsupported Features

    + +

    XXX update this section

    + +

    +The following features of the shading language are not yet fully supported +in Mesa: +

    + +
      +
    • Linking of multiple shaders does not always work. Currently, linking + is implemented through shader concatenation and re-compiling. This + doesn't always work because of some #pragma and preprocessor issues. +
    • gl_ClipVertex +
    • The gl_Color and gl_SecondaryColor varying vars are interpolated + without perspective correction +
    + +

    +All other major features of the shading language should function. +

    + + +
    +

    Implementation Notes

    + +
      +
    • Shading language programs are compiled into low-level programs + very similar to those of GL_ARB_vertex/fragment_program. +
    • All vector types (vec2, vec3, vec4, bvec2, etc) currently occupy full + float[4] registers. +
    • Float constants and variables are packed so that up to four floats + can occupy one program parameter/register. +
    • All function calls are inlined. +
    • Shaders which use too many registers will not compile. +
    • The quality of generated code is pretty good, register usage is fair. +
    • Shader error detection and reporting of errors (InfoLog) is not + very good yet. +
    • The ftransform() function doesn't necessarily match the results of + fixed-function transformation. +
    + +

    +These issues will be addressed/resolved in the future. +

    + + +
    +

    Programming Hints

    + +
      +
    • Use the built-in library functions whenever possible. + For example, instead of writing this: +
      +        float x = 1.0 / sqrt(y);
      +
      + Write this: +
      +        float x = inversesqrt(y);
      +
      +
    • +
    + + +
    +

    Stand-alone GLSL Compiler

    + +

    +The stand-alone GLSL compiler program can be used to compile GLSL shaders +into low-level GPU code. +

    + +

    +This tool is useful for: +

    +

      +
    • Inspecting GPU code to gain insight into compilation +
    • Generating initial GPU code for subsequent hand-tuning +
    • Debugging the GLSL compiler itself +
    + +

    +After building Mesa, the compiler can be found at src/glsl/glsl_compiler +

    + +

    +Here's an example of using the compiler to compile a vertex shader and +emit GL_ARB_vertex_program-style instructions: +

    +
    +    src/glsl/glsl_compiler --dump-ast myshader.vert
    +
    + +Options include +
      +
    • --dump-ast - dump GPU code +
    • --dump-hir - dump high-level IR code +
    • --dump-lir - dump low-level IR code +
    • --link - ??? +
    + + + + +
    +

    Compiler Implementation

    + +

    +The source code for Mesa's shading language compiler is in the +src/glsl/ directory. +

    + +

    +XXX provide some info about the compiler.... +

    + +

    +The final vertex and fragment programs may be interpreted in software +(see prog_execute.c) or translated into a specific hardware architecture +(see drivers/dri/i915/i915_fragprog.c for example). +

    + +

    Code Generation Options

    + +

    +Internally, there are several options that control the compiler's code +generation and instruction selection. +These options are seen in the gl_shader_state struct and may be set +by the device driver to indicate its preferences: + +

    +struct gl_shader_state
    +{
    +   ...
    +   /** Driver-selectable options: */
    +   GLboolean EmitHighLevelInstructions;
    +   GLboolean EmitCondCodes;
    +   GLboolean EmitComments;
    +};
    +
    + +
      +
    • EmitHighLevelInstructions +
      +This option controls instruction selection for loops and conditionals. +If the option is set high-level IF/ELSE/ENDIF, LOOP/ENDLOOP, CONT/BRK +instructions will be emitted. +Otherwise, those constructs will be implemented with BRA instructions. +
    • + +
    • EmitCondCodes +
      +If set, condition codes (ala GL_NV_fragment_program) will be used for +branching and looping. +Otherwise, ordinary registers will be used (the IF instruction will +examine the first operand's X component and do the if-part if non-zero). +This option is only relevant if EmitHighLevelInstructions is set. +
    • + +
    • EmitComments +
      +If set, instructions will be annoted with comments to help with debugging. +Extra NOP instructions will also be inserted. +
      + +
    + + +
    +

    Compiler Validation

    + +

    +Developers working on the GLSL compiler should test frequently to avoid +regressions. +

    + +

    +The Piglit project +has many GLSL tests and the +Glean glsl1 test +tests GLSL features. +

    + +

    +The Mesa demos repository also has some good GLSL tests. +

    + + + diff --git a/docs/sourcedocs.html b/docs/sourcedocs.html new file mode 100644 index 0000000..90538af --- /dev/null +++ b/docs/sourcedocs.html @@ -0,0 +1,37 @@ + + +Source Code Documentation + + + + + +

    Source Code Documentation

    + +

    +Doxygen +is used to automatically +produce cross-referenced documentation from the Mesa source code. +

    + +

    +The Doxygen configuration files and generated files are not included +in the normal Mesa distribution (they're very large). +To generate Doxygen documentation, download Mesa from CVS, change to +the doxygen directory and run make. +

    + +

    +For an example of Doxygen usage in Mesa, see a recent source file +such as bufferobj.c. +

    + + +

    +If you're reading this page from your local copy of Mesa, and have +run the doxygen scripts, you can read the documentation +here +

    + + + diff --git a/docs/sourcetree.html b/docs/sourcetree.html new file mode 100644 index 0000000..08a9a50 --- /dev/null +++ b/docs/sourcetree.html @@ -0,0 +1,166 @@ + + +Mesa Source Tree + + + + + +

    Mesa source code tree overview

    + +

    +This is a brief summary of Mesa's directory tree and what's contained in +each directory. +

    + + +
      +
    • docs - Documentation +
    • include - Public OpenGL header files +
    • src +
        +
      • egl - EGL library sources +
          +
        • docs - EGL documentation +
        • drivers - EGL drivers +
        • glsl - the GLSL compiler +
        • main - main EGL library implementation. This is where all + the EGL API functions are implemented, like eglCreateContext(). +
        +
      • mesa - Main Mesa sources +
          +
        • glapi - OpenGL API dispatch layer. This is where all the + GL entrypoints like glClear, glBegin, etc. are generated, as well as + the GL dispatch table. All GL function calls jump through the + dispatch table to functions found in main/. +
        • main - The core Mesa code (mainly state management) +
        • drivers - Mesa drivers (not used with Gallium) +
            +
          • common - code which may be shared by all drivers +
          • dri - Direct Rendering Infrastructure drivers +
              +
            • common - code shared by all DRI drivers +
            • i915 - driver for Intel i915/i945 +
            • i965 - driver for Intel i965 +
            • XXX more +
            +
          • x11 - Xlib-based software driver +
          • osmesa - off-screen software driver +
          • glslcompiler - a stand-alone GLSL compiler driver +
          • XXX more +
          +
        • es - OpenGL ES overlay, parallelly buildable with the core Mesa +
        • math - vertex array translation and transformation code + (not used with Gallium) +
        • ppc - Assembly code/optimizations for PPC systems + (not used with Gallium) +
        • shader - Vertex/fragment shader and GLSL compiler code +
        • sparc - Assembly code/optimizations for SPARC systems + (not used with Gallium) +
        • state_tracker - State tracker / driver for Gallium. This + is basically a Mesa device driver that speaks to Gallium. This + directory may be moved to src/mesa/drivers/gallium at some point. +
        • swrast - Software rasterization module. For drawing points, + lines, triangles, bitmaps, images, etc. in software. + (not used with Gallium) +
        • swrast_setup - Software primitive setup. Does things like + polygon culling, glPolygonMode, polygon offset, etc. + (not used with Gallium) +
        • tnl - Software vertex Transformation 'n Lighting. + (not used with Gallium) +
        • tnl_dd - TNL code for device drivers. + (not used with Gallium) +
        • vbo - Vertex Buffer Object code. All drawing with + glBegin/glEnd, glDrawArrays, display lists, etc. goes through this + module. The results is a well-defined set of vertex arrays which + are passed to the device driver (or tnl module) for rendering. +
        • vf - vertex format conversion (currently unused) +
        • x86 - Assembly code/optimizations for 32-bit x86 systems + (not used with Gallium) +
        • x86-64 - Assembly code/optimizations for 64-bit x86 systems + (not used with Gallium) +
        +
      • gallium - Gallium3D source code +
          +
        • include - Gallium3D header files which define the Gallium3D + interfaces +
        • drivers - Gallium3D device drivers +
            +
          • cell - Driver for Cell processor. +
          • i915 - Driver for Intel i915/i945. +
          • i965 - Driver for Intel i965. +
          • llvmpipe - Software driver using LLVM for runtime code generation. +
          • nv* - Drivers for NVIDIA GPUs. +
          • r300 - Driver for ATI/AMD R300. +
          • softpipe - Software reference driver. +
          • svga - Driver for VMware's SVGA virtual GPU. +
          • trace - Driver for tracing Gallium calls. +
          • XXX more +
          +
        • auxiliary - Gallium support code +
            +
          • draw - Software vertex processing and primitive assembly + module. This includes vertex program execution, clipping, culling + and optional stages for drawing wide lines, stippled lines, + polygon stippling, two-sided lighting, etc. + Intended for use by drivers for hardware that does not have + vertex shaders. + Geometry shaders will also be implemented in this module. +
          • cso_cache - Constant State Objects Cache. Used to filter out + redundant state changes between state trackers and drivers. +
          • gallivm - LLVM module for Gallium. For LLVM-based + compilation, optimization and code generation for TGSI shaders. + Incomplete. +
          • pipebuffer - utility module for managing buffers +
          • rbug - Gallium remote debug utility +
          • rtasm - run-time assembly/machine code generation. + Currently there's run-time code generation for x86/SSE, PowerPC + and Cell SPU. +
          • tgsi - TG Shader Infrastructure. Code for encoding, + manipulating and interpretting GPU programs. +
          • translate - module for translating vertex data from one format + to another. +
          • util - assorted utilities for arithmetic, hashing, surface + creation, memory management, 2D blitting, simple rendering, etc. +
          +
        • state_trackers - +
            +
          • dri - Meta state tracker for DRI drivers +
          • egl - Meta state tracker for EGL drivers +
          • es - OpenGL ES 1.x and 2.x state trackers +
          • g3dvl - +
          • glx - Meta state tracker for GLX +
          • python - +
          • vega - OpenVG 1.x state tracker +
          • wgl - +
          • xorg - Meta state tracker for Xorg video drivers +
          +
        • winsys - +
            +
          • drm - +
          • g3dvl - +
          • gdi - +
          • xlib - +
          +
        +
      +
        +
      • glu - The OpenGL Utility library +
          +
        • sgi - GLU from SGI +
        • mesa - Mesa version of GLU (deprecated) +
        +
      • glut - Mark Kilgard's OpenGL OpenGL Utility Toolkit library +
      • glx - The GLX library code for building libGL. This is used for + direct rendering drivers. It will dynamically load one of the + xxx_dri.so drivers. +
      • glw - Widgets for Xt/Motif. +
      • glew - OpenGL Extension Wrangler library (used by demo programs) +
      +
    • progs - OpenGL test and demonstration programs +
    • lib - where the GL libraries are placed +
    + + + + diff --git a/docs/subset-A.html b/docs/subset-A.html new file mode 100644 index 0000000..d576bb6 --- /dev/null +++ b/docs/subset-A.html @@ -0,0 +1,3578 @@ + + + + Mini GLX Specification + + + +

    +
    Mesa Subset Specification
    +

    +

    +
    +

    Tungsten Graphics, Inc.

    +

    February 26, 2003
    +

    +
    +

    +

    Copyright © 2002-2003 by Tungsten Graphics, Inc., +Cedar Park, Texas. All Rights Reserved.
    +
    +Permission is granted to make and distribute verbatim copies of this +document provided the copyright notice and this permission notice are +preserved on all copies.
    +

    +

    OpenGL is a trademark of Silicon +Graphics, Inc..

    +

    1. Introduction

    +This document describes a subset of the Mesa implemented by Tungsten +Graphics, Inc. for embedded devices.  Prior to reading this +document the reader should be familiar with the OpenGL 1.2.1 +specification dated April 1, 1999 (available from http://www.opengl.org/developers/documentation/specs.html.) + Experience with OpenGL programming is highly advisable.
    +

    +Tungsten Graphics, Inc. is working with industry standards +organizations +in an attempt to standardize this Mesa subset and any +other possible subsets +as a result of this work.
    +
    +Appendix A contains a list of issues of which some may not be resolved.
    +
    +To summarize, the following major features of Mesa are omitted from the +subset:
    +
      +
    • Vertex arrays
    • +
    • Texture coordinate generation
    • +
    • Lighting
    • +
    • Point size
    • +
    • Polygon stipple
    • +
    • DrawPixels, CopyPixels, PixelZoom
    • +
    • 1-D and 3-D textures
    • +
    • CopyTex[Sub]Image
    • +
    • Fog
    • +
    • Depth test
    • +
    • Color Index mode
    • +
    • Accumulation buffer
    • +
    • Feedback mode
    • +
    • Evaluators
    • +
    • Push/Pop attributes
    • +
    • Display lists
      +
    • +
    +

    Further reductions are made at a lower level of detail.
    +

    +

    Mesa function names are printed in bold +face.  Function parameters are printed in italics.
    +

    +

    The Tungsten Graphics, Inc. Mesa subset library is hereafter +referred to as the subset.
    +
    +

    +

    2. Primitive Specification

    +

    2.1 glBegin, glEnd and glVertex Commands

    +The basic rendering primitives are points, lines and triangles. + Quadrilaterals and polygons are composed of triangles. + Primitives are drawn with the glBegin +and glEnd commands and a subset +of the glVertex commands:
    +
    +
    void glBegin(GLenummode)
    +void glEnd(void)
    +
    +void glVertex2f(GLfloat x, GLfloat y)
    +void glVertex2fv(const GLfloat +*v)
    +void glVertex3f(GLfloat x, GLfloat y, GLfloat z)
    +void glVertex3fv(const GLfloat +*v)
    +
    +
    +The mode parameter to glBegin may be one of the following
    +
    +
    GL_POINTS - a series of individual +points
    +GL_LINES - a series of disjoint line segments
    +GL_LINE_STRIP - series of connected line segments
    +GL_LINE_LOOP - a closed loop of line segments
    +GL_TRIANGLES - a series of individual triangles
    +GL_TRIANGLE_STRIP - a connected strip of triangles
    +GL_TRIANGLE_FAN - a sequence of triangles all sharing a common vertex
    +GL_QUADS - a sequence of individual quadrilaterals
    +GL_QUAD_STRIP - a connected strip of quadrilaterals
    +GL_POLYGON - a closed, convex polygon
    +
    +
    +
    +The glVertex commands take two +or three floating point coordinates, or a pointer to an array of two or +three floating point coordinates.  Vertices are actually 4-element +homogeneous coordinates.  The fourth component, unspecified by the +subset's glVertex commands, is +one.
    +
    + +

    2.2 Other Per-vertex Commands
    +

    +The glColor and glTexCoord commands may be used to +specify colors and texture coordinates for each vertex:
    +
    +
    void glColor3f(GLfloatred, GLfloat green, GLfloat blue)
    +void glColor3fv(const GLfloat *rgb)
    +void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
    +void glColor4fv(const GLfloat *rgba)
    +void glTexCoord2f(GLfloat s, GLfloat t)
    +void glTexCoord2fv(const +GLfloat *c)
    +
    +
    +The glColor commands specify +the color and optionally, the alpha value, for subsequent vertices. + For the glColor3 commands, +alpha is set to one.
    +
    +The glTexCoord2 commands +specify the texture coordinate for subsequent vertices.  Texture +coordinates are actually four-component coordinates: (s, t, r, q). + The glTexCoord2 commands +set s and t explicitly.  The r and q components are zero and one, +respectively.
    +
    +Only glVertex, glColor and glTexCoord commands are allowed +between glBegin and glEnd.  Calling any other +command between glBegin and glEnd will result in the error +GL_INVALID_OPERATION.
    +
    +

    2.3 Unsupported Commands

    +None of the following commands related to primitive specification are +supported by the subset:
    +
    +
    Per-Vertex commands:
    +
    +
    +
    glVertex2d, +glVertex2i, glVertex2s, glVertex3d, glVertex3i, glVertex3s, glVertex4d, +glVertex4i, glVertex4s, glVertex2dv, glVertex2iv, glVertex2sv, +glVertex3dv, glVertex3iv, glVertex3sv, glVertex4dv, glVertex4iv, +glVertex4sv,
    +glNormal3b, glNormal3d, glNormal3f, glNormal3i, glNormal3s,
    glNormal3bv, glNormal3dv, glNormal3fv, +glNormal3iv, glNormal3sv,
    +glIndexd, glIndexf, glIndexi, glIndexs, glIndexub, glIndexdv, +glIndexfv, glIndexiv, glIndexsv, glIndexubv,
    +glColor3b, glColor3d, glColor3i, glColor3s, glColor3ub, glColor3ui, +glColor3us,
    glColor3bv, +glColor3dv, glColor3iv, glColor3sv, glColor3ubv, glColor3uiv, +glColor3usv, lColor4b, +glColor4d, glColor4i, glColor4s, glColor4ub, glColor4ui, glColor4us, glColor4bv, glColor4dv, glColor4iv, +glColor4sv, glColor4ubv, glColor4uiv, glColor4usv,
    +
    glTexCoord1d, glTexCoord1f, +glTexCoord1i, glTexCoord1s, glTexCoord2d, glTexCoord2i, glTexCoord2s, +glTexCoord3d, glTexCoord3f, glTexCoord3i, glTexCoord3s, glTexCoord4d, +glTexCoord4f, glTexCoord4i, glTexCoord4s, glTexCoord1dv, glTexCoord1fv, +glTexCoord1iv, glTexCoord1sv, glTexCoord2dv, glTexCoord2iv, +glTexCoord2sv, glTexCoord3dv, glTexCoord3fv, glTexCoord3iv, +glTexCoord3sv, glTexCoord4dv, glTexCoord4fv, glTexCoord4iv, +glTexCoord4sv,
    +glEdgeFlag, glEdgeFlagv

    +
    +
    +Vertex array commands:
    +
    glVertexPointer, +glColorPointer, glIndexPointer, glTexCoordPointer, glEdgeFlagPointer, +glNormalPointer, glInterleavedArrays, glArrayElement, glDrawArrays, +glDrawElements, glDrawRangeElements, glEnableClientState, +glDisableClientState
    +
    +
    +

    +Rectangle commands:
    +
    glRects, +glRecti, glRectf, glRectd, glRectsv, glRectiv, glRectfv, glRectdv,
    +
    +
    +
    +
    Lighting commands:
    +
    +
    glMaterialf, +glMateriali, glMaterialfv, glMaterialiv
    +

    +
    +
    Evaluator commands:
    +
    glEvalCoord1d, +glEvalCoord1f, glEvalCoord1dv, glEvalCoord1fv, glEvalCoord2d, glEvalCoord2f, +glEvalCoord2dv, glEvalCoord2fv,
    +
    glEvalPoint1, glEvalPoint2
    +
    +
    +
    +

    3. Coordinate Transformation

    +

    3.1 Vertex Transformation

    +Vertex coordinates are transformed by the current modelview and +projection matrices then mapped to window coordinates as specified by +the viewport.  The following coordinate transformation commands are +supported by the subset
    +
    +
    glMatrixMode(GLenum mode)
    +glLoadIdentity(void)
    +glPushMatrix(void)
    +glPopMatrix(void)
    +glLoadMatrixf(const GLfloat *m)
    +glMultMatrixf(const GLfloat *m)
    +glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
    +glTranslatef(GLfloat x, GLfloat y, GLfloat z)
    +glScalef(GLfloat x, GLfloat y, GLfloat z)
    +glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far)

    +glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far)
    +glViewport(GLint x, GLint y, GLsize width, GLsizei height)
    +
    +
    +The glMatrixMode command +specifies the current matrix. + The mode parameter may be GL_MODELVIEW or GL_PROJECTION to specify +the modelview matrix or projection matrix.  Subsequent matrix +commands will effect the current matrix.  Also associated with the +modelview and projection matrices are a modelview matrix stack and +projection matrix stack.
    +
    +The glLoadIdentity command +replaces the current matrix with the identity matrix.  The matrix +elements are specified in column-major order.
    +
    +The glPushMatrix command pushes +a copy of the current matrix onto either the modelview matrix stack or +the projection matrix stack.  The glPopMatrix +command replaces the current matrix with a copy of the top matrix off +the modelview matrix stack or projection matrix stack, the pops the +stack.  Matrix stacks are useful for traversing and rendering +hierarchical models.
    +
    +The glMultMatrixf command +post-multiplies the current matrix by the specified matrix.  The +matrix elements are specified in column-major order.
    +
    +The glRotatef command +post-multiplies the current matrix by a rotation matrix defined by the +angle and rotation axis defined by x, y and z.
    +
    +The glTranslatef command +post-multiplies the current matrix by a translation matrix defined by +the x, y and z translation parameters.
    +
    +The glScalef command +post-multiplies the current matrix by a scaling matrix defined by the x, y and z scale factors.
    +
    +The glFrustum command +post-multiplies the current matrix by a perspective projection matrix. + The near and far values specify the position of +the hither and yon Z-axis clipping planes.  The left, right, bottom and top parameters are the X and Y +extents at the near clipping plane.  glFrustum is normally used to modify +the projection matrix.
    +
    +The glOrtho command +post-multiplies the current matrix by an orthographic projection matrix. + The near and far values specify the position of +the hither and yon Z-axis clipping planes.  The left, right, bottom and top parameters specify the X and +Y-axis clipping planes.  glOrtho +is normally used to modify the projection matrix.
    +
    +The glViewport command +specifies the mapping of coordinates from normalized device coordinates +to window coordinates.  The x +and y parameters specify the +viewport's lower-left corner in the window and the width and height parameters specify the size +of the viewport.  glViewport +does not effect the current matrix.
    +
    +A coordinate transformed to window coordinates is hereafter known as (xw, +yw, zw).
    +
    +

    3.2 Clipping

    +View-volume clipping automatically discards or trims primitives which +lie completely or partially outside of the view volume specified by glFrustum and glOrtho.  Note that the glViewport command does not define a +clipping region.
    +
    +Clipping occurs in clip coordinate +space - the coordinates produced after applying the projection +matrix.
    +
    +

    3.3 Current Raster Position

    +The current raster position specifies the location for drawing images +with glBitmap.  The current +raster position is set with the commands:
    +
    +
    void glRasterPos2f(GLfloatx, GLfloat y)
    +void glRasterPos2fv(const +GLfloat *v)
    +void glRasterPos2i(GLint x, GLint y)
    +void glRasterPos2iv(const +GLint *v)
    +
    +
    +glRasterPos specifies a +4-component coordinate (x, y, 0, 1).  The coordinate is processed +like a vertex; it is transformed by the modelview matrix, the projection +matrix and mapped to the viewport.  The resulting window coordinate +is stored as the current raster position.  The coordinate is +clipped-tested against the frustum like a vertex.  If the +coordinate is clipped, then the current raster position becomes invalid +and subsequent glBitmap commands +have no effect.
    +
    +glRasterPos also updates the +current raster color and current raster texture coordinates.  The +current raster color is updated (copied) from the current color (as +specified by glColor). + The current raster texture coordinate is updated (copied) from the +current texture coordinate (as specified by glTexCoord).
    +
    +

    3.4 Unsupported Commands

    +The following commands related to vertex transformation are not +supported by the subset:
    +
    +
    User-defined clip plane commands:
    +
    glClipPlane
    +
    +
    +
    +
    Lighting and material commands:
    +
    glLightModeli, +glLightModelf, glLightModeliv, +glLightModelfv, glLightf, +glLighti, glLightfv, glLightiv, glColorMaterial
    +
    +
    +
    Automatic texture coordinate generation +commands:
    +
    +
    +
    glTexGend, +glTexGenf, glTexGeni, glTexGendv, +glTexGenfv, glTexGeniv,
    +
    +
    +Double-valued commands:
    +
    glLoadMatrixd, +glMultMatrixd, glRotated, glTranslated, glScaled
    +
    +
    +Depth Range command:
    +
    glDepthRange +(the near value is always 0.0 and the far value is always 1.0)
    +
    +
    +Extra RasterPos commands:
    +
    glRasterPos2d, +glRasterPos2s, glRasterPos3d, glRasterPos3f, glRasterPos3i, +glRasterPos3s, glRasterPos4d, glRasterPos4f, glRasterPos4i, +glRasterPos4s, glRasterPos2dv, glRasterPos2sv, glRasterPos3dv, +glRasterPos3fv, glRasterPos3iv, glRasterPos3sv, glRasterPos4dv, +glRasterPos4fv, glRasterPos4iv, glRasterPos4sv
    +
    +
    +
    +
    +

    4. Rasterization

    +This section describes the commands and options for drawing points, +lines, triangles and bitmaps.  Rasterization +is the term for the process which produces fragments from the geometric +description of a primitive (a point, line, polygon or bitmap).  For +example, given the two coordinates for the end-points of a line segment, +rasterization determines which pixels in the frame buffer are modified +to draw the line.  A +fragment is a tuple which consists of a window coordinate, colors and +texture coordinates.  The fragments produced by rasterization are +subsequently processed by the per-fragment operations described later.
    +
    +

    4.1 Point Rasterization

    +Points are rendered with the command sequence glBegin(GL_POINTS), glVertex, ... glEnd.  The window coordinate (xw, +yw, zw) is truncated to rasterize the point. + The truncated coordinate with its associated color and texture +coordinate is sent as a single fragment to the per-fragment processing +stages.
    +
    +The glPointSize command is not +supported; only 1-pixel points are supported.
    +
    +Point smoothing (antialiasing) is also not supported.
    +
    +

    4.2 Line Rasterization

    +Lines are rendered with the command sequence glBegin(mode), glVertex, glVertex, ... glEnd where mode is one of GL_LINES, +GL_LINE_STRIP or GL_LINE_LOOP.  Lines are rasterized as described +in the OpenGL specification.  Note that OpenGL specifies the half-open convention for drawing +lines: the last fragment in a line segment is omitted so that endpoint +pixels shared by two line segments will only be drawn once instead of +twice.
    +
    +

    4.2.1 Line Width

    +The width of lines can be controlled by
    +
    +
    void glLineWidth(GLfloatwidth)
    +
    +
    +where width is the line width +in pixels.  The width defaults to 1.0.  Attempting to set the +width to a value less than or equal to zero will raise the error +GL_INVALID_VALUE.
    +
    +

    4.2.2 Line Stipple
    +

    +Lines may be stippled (i.e. dashed) with the command
    +
    +
    glLineStipple(GLintfactor, GLushort pattern)
    +
    +
    +pattern describes an on/off +pattern for the fragments produced by rasterization and factor specifies how many subsequent +fragments are kept or culled for each pattern bit.  Line stippling +can be enabled or disabled by the commands glEnable(GL_LINE_STIPPLE) and glDisable(GL_LINE_STIPPLE).
    +
    +

    4.2.3 Line Antialiasing

    +Lines may be antialiased.  For antialiased lines, each fragment +produced by rasterization is assigned a coverage value which describes how +much of the fragment's area is considered to be inside the line.  Later, the +alpha value of each fragment is multiplied by the coverage value. + By blending the fragments into the frame buffer, the edges of +lines appear smoothed.
    +
    +Line antialiasing can be enabled or disabled with the commands glEnable(GL_LINE_SMOOTH) and glDisable(GL_LINE_SMOOTH).
    +
    +

    4.3 Polygon Rasterization

    +Polygons, quadrilaterals and triangles share the same polygon +rasterization options.
    +
    +Triangles are rendered by the command sequence glBegin(mode),glVertex, glVertex, ... glEnd where mode may be one of GL_TRIANGLES, +GL_TRIANGLE_STRIP or GL_TRIANGLE_FAN. + For GL_TRIANGLES mode, the number of vertices should be a multiple +of three - extra vertices will be ignored.  For GL_TRIANGLE_STRIP +and GL_TRIANGLE_FAN, at least three vertices should be specified. + If less than three are specified, nothing is drawn.  
    +
    +Quadrilaterals are rendered by +the command sequence glBegin(mode),glVertex, glVertex, ... glEnd where mode may be one of GL_QUADS or +GL_QUAD_STRIP.   For +GL_QUADS, the number of vertices should be a multiple of four - extra +vertices will be ignored.  For GL_QUAD_STRIP, the number of +vertices should be even and at least four.  Extra vertices (one) +will be ignored.
    +
    +Convex polygons are rendered +by the command sequence glBegin(GL_POLYGON),glVertex, glVertex, ... glEnd. + If less than three vertices are specified, nothing is drawn.
    +
    +

    4.3.1 Polygon Orientation

    +The winding order of vertices +(clockwise or counter-clockwise) is significant.  It is used to +determine the front-facing or back-facing orientation of polygons. + By default, a front-facing polygon's vertices are in +counter-clockwise order (in window coordinates).  Figures 2.4 and +2.5 of the OpenGL 1.2.1 specification illustrate the winding order for +front-facing triangles and quadrilaterals, respectively.
    +
    +The command
    +
    +
    void glFrontFace(GLenum mode)
    +
    +
    +specifies whether clockwise or counter-clockwise winding indicates a +front-facing polygon.  If mode +is GL_CW then polygons with clockwise winding are front-facing.  If mode is GL_CCW then polygons with +counter-clockwise winding are front-facing.  The default value is +GL_CCW.  If mode is not +GL_CCW or GL_CW then the error GL_INVALID_ENUM will be raised.
    +
    +

    4.3.2 Polygon Culling

    +Polygons may be culled (discarded) depending on whether they are +front-facing or back-facing.  The command
    +
    +
    void +glCullFace(GLenum mode)
    +
    +
    +specifies whether front-facing, back-facing or all polygons should be +culled.  If mode is +GL_FRONT then front-facing polygons will be culled.  If mode is GL_BACK then back-facing +polygons will be culled. Otherwise, if mode +is GL_FRONT_AND_BACK then all polygons will be culled.  Any other +value for mode will raise the +error GL_INVALID_ENUM.
    +
    +Polygon culling is enabled and disabled with the commands glEnable(GL_CULL_FACE) and glDisable(GL_CULL_FACE), +respectively.
    +
    +

    4.3.3 Polygon Antialiasing

    +Polygons may be antialiased in order to smooth their edges. + Polygon antialiasing is enabled and disabled with the commands glEnable(GL_POLYGON_SMOOTH) and glDisable(GL_POLYGON_SMOOTH).
    +
    +When polygon antialiasing is enabled each fragment produced by polygon, +triangle and quadrilateral rasterization will be given a coverage value which indicates how +much of the fragment is covered by the polygon.  Fragments +completely inside the polygon have coverage 1.0.  Fragments +completely outside the polygon have zero coverage (in theory). + Fragments which intersect the polygon's edge have a coverage value +in the range (0, 1).
    +
    +The fragment's alpha value is multiplied by the coverage value. + By enabling the appropriate blending mode, polygon edges will +appear smoothed.
    +
    +

    4.4 Shading

    +The command
    +
    +
    void glShadeModel(GLenummode)
    +
    +
    +determines whether colors are interpolated between vertices during +rasterization.  If mode is +GL_FLAT then vertex colors are not interpolated.  The color used +for drawing lines, triangles and quadrilaterals is that of the last +vertex used to specify each primitive.  For polygons, the color of +the first vertex specifies the color for the entire polygon.  If mode is GL_SMOOTH then vertex colors +are linearly interpolated to produce the fragment colors.
    +
    +

    4.5 Bitmap Rasterization

    +A bitmap is a monochromatic, binary image in which each image element +(or pixel) is represented by one bit.  Fragments are only generated +for the bits (pixels) which are set.  Bitmaps are commonly used to +draw text (glyphs) and markers.
    +
    +A bitmap is drawn with the command
    +
    +
    void glBitmap(GLsizeiwidth, GLsizei height, GLfloat xOrig, GLfloat yOrig, GLfloat xMove, GLfloat yMove, const  GLubyte *image)
    +
    +
    +width and height specify the image size in +pixels.  xOrig and yOrig specify the bitmap origin. + xMove and yMove are added to the current +raster position after the bitmap is rasterized.  image is a pointer to the bitmap +data.
    +
    +If the current raster position is not valid, glBitmap has no effect.
    +
    +

    4.5.1 Bitmap Unpacking

    +The first step in bitmap rendering is unpacking. + Unpacking is the process of extracting image data from +client memory subject to byte swapping, non-default row strides, etc. + The unpacking parameters are specified with the command
    +
    +
    void +glPixelStorei(GLenum pname, GLint value)
    +
    +
    +The following unpacking parameters may be set:
    +
    + + + + + + + + + + + + + + + + + + +
    Parameter (pname)
    +
    Value (value)
    +
    Default
    +
    GL_UNPACK_ROW_LENGTH
    +
    Width of the image in memory, in +pixels.
    +
    0
    +
    GL_UNPACK_LSB_FIRST
    +
    GL_FALSE indicates that the most +significant bit is unpacked first from each byte.  GL_TRUE +indicates that the least significant bit is unpacked first from each +byte.
    +
    GL_FALSE
    +
    +
    +
    +The GL_UNPACK_ROW_LENGTH specifies the stride (in pixels) for advancing +from one row of the image to the next.  If it's zero, the width parameter to glBitmap specifies the width of the +image in memory.
    +
    +GL_UNPACK_LSB_FIRST determines whether the least significant or most +significant bit in each byte is unpacked first.  Unpacking occurs +in left to right order (in image space).
    +
    +The value of bit (i, j) of the image (where i is the image row and j is +the image column) is found as follows:
    +
    +
    rowLength = (GL_UNPACK_ROW_LENGTH != 0) +? GL_UNPACK_ROW_LENGTH : width;
    +
    +byte = image[((rowLength + 7) +/ 8) * i + j / 8];
    +
    +if (GL_UNPACK_LSB_FIRST != 0)
    +    bitMask = 1 << (j % 8);
    +else
    +    bitMask = 128 >> (j % 8);
    +
    +if (byte & bitMask)
    +    bit = 1;
    +else
    +    bit = 0;
    +
    +
    + +

    4.5.2 Rasterization

    +If the current raster position is (xrp, yrp, zrp, +wrp), then the bitmap is rasterized according to the +following algorithm:
    +
    +for (j = 0; j < height; +j++) {
    +    for (i = 0; i < width; +i++) {
    +        if (bit(i,j)) {
    +            fragment.x = +floor(xrp - xOrig) ++ i;
    +            fragment.y = +floor(yrp - yOrig) ++ j;
    +            fragment.color += GL_CURRENT_RASTER_COLOR;
    +            +fragment.texture = GL_CURRENT_RASTER_TEXTURE_COORDS;
    +            +ProcessFragment(fragment)
    +         }
    +    }
    +}
    +
    +After the bitmap has been rendered the current raster position is +updated as follows:
    +
    +
    xrp = xrp + xMove
    +yrp = yrp + yMove
    +
    +
    +

    4.5.3 Per-fragment Operations

    +XXX supported?  See issue in appendix A.
    +
    +

    4.6 Unsupported Commands

    +The following commands related to rasterization are not supported by +the subset.
    +
    +
    Point commands:
    +
    glPointSize
    +
    +
    +Polygon commands:
    +
    glPolygonStipple
    +glPolygonOffset
    +glPolygonMode
    +
    +
    +
    +
    Pixel storage commands:
    +
    +
    glPixelStoref
    +
    +
    +
    +

    5. Texture Mapping
    +

    +There are four elements to texture mapping: texture coordinate +specification, texture image specification, texture sampling and texture +application.
    +
    +Texture mapping is enabled and disabled with the commands glEnable(GL_TEXTURE_2D) and glDisable(GL_TEXTURE_2D).
    +
    +

    5.1 Texture Image Specification

    +A texture image is specified with the command:
    +
    +
    void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
    +
    +
    +target must be GL_TEXTURE_2D. + level indicates the +mipmap level for mipmap textures.  internalFormat +is a hint to indicate the preferred internal storage format for the +texture.  width and height indicate the image size in +pixels (or texels).  border must +be zero.  format and type describe the pixel format and +data type for the incoming image.  pixels +points to the incoming texture image.  These parameters are +described in more detail below.
    +
    +

    5.1.1 Texture Image Size and Mipmaps

    +

    +Texture images must have dimensions (width and height) that are powers +of two. For example: 256 x 256, 32 x 1024, 1 x 8, etc.  That is, it +must be the case that width = +2n and height = 2m +for some positive integers n and m.
    +
    +Mipmapping is a method of antialiasing or filtering textures to improve +their appearance.  A mipmap is a set of images consisting of a base +image and a set of filtered, reduced-resolution images.  If the +base image (level=0) is of +width 2n and height 2m then the level 1 image must +be of width 2n-1 and height 2m-1.  Each mipmap +level is half the width and height of the previous level, or at least +one.  The last mipmap level has a width and height of one.
    +
    +The following is an example of a mipmap's image levels:
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    mipmap level
    +
    width
    +
    height
    +
    0
    +
    256
    +
    64
    +
    1
    +
    128
    +
    32
    +
    2
    +
    64
    +
    16
    +
    3
    +
    32
    +
    8
    +
    4
    +
    16
    +
    4
    +
    5
    +
    8
    +
    2
    +
    6
    +
    4
    +
    1
    +
    7
    +
    2
    +
    1
    +
    8
    +
    1
    +
    1
    +
    +
    +If the width or height parameters are not powers of +two, the error GL_INVALID_VALUE is raised.  If the image levels in +a mipmap do not satisfy the restrictions listed above the texture is +considered to be inconsistent +and the system will behave as if the texturing is disabled.
    +
    +

    5.1.2 Texture Image Formats and Unpacking

    +The glTexImage2D command's format and type parameters describe the format +of the incoming texture image.  Accepted values for format are GL_INTENSITY, GL_RGB and +GL_RGBA.  The type +parameter must be GL_UNSIGNED_BYTE.  Pixel component values are +thus in the range 0 through 255.
    +
    +If format is GL_INTENSITY then +the image has one byte per pixel which specifies the pixel's red, green, +blue and alpha values.
    +
    +If format is GL_RGB then the +image has three bytes per pixel which specify the pixel's red, green and +blue values (in that order).  The alpha value defaults to 255.
    +
    +If format is GL_RGBA then the +image has four bytes per pixel which specify the pixel's red, green, +blue and alpha values (in that order).
    +
    +The command
    +
    +
    void +glPixelStorei(GLenum pname, +GLint value)
    +
    +
    +controls the unpacking of texture image data from client memory.  pname may be GL_UNPACK_ROW_LENGTH to +indicate the stride, in pixels, between subsequent rows of the image in +client memory.  If GL_UNPACK_ROW_LENGTH is zero (the default) then +the width parameter to glTexImage2D determines the stride.
    +
    +

    5.1.3 Internal Texture Format

    +glTexImage2D converts the incoming +texture image to one of the supported internal texture formats.
    +
    +The internalFormat parameter +indicates the desired internal format for the texture and may be either +GL_INTENSITY8, GL_RGB5 or GL_RGBA8.
    +
    +If internalFormat is +GL_INTENSITY8 then the texture has one byte per texel (texture element) +which indicates the texel's intensity (or brightness).  The +intensity is obtained from the incoming image's red channel.
    +
    +If internalFormat is GL_RGB5 +then the texture is stored with two bytes per texel:  5 bits per +red value, 5 bits per green value and 5 bits per blue value.
    +
    +If internalFormat is +GL_RGBA8 then the texture is stored with four bytes per texel:  8 +bits for each of the red, green,  blue and alpha values.
    +
    +The internal format is also significant to texture application (see +section 5.4).
    +
    +

    5.2 Texture Coordinates

    +Texture coordinates control the mapping from local polygon space to +texture image space.  Texture coordinates are set for each vertex +with the glTexCoord commands. + During line and polygon rasterization the vertex's texture +coordinates are interpolated across the primitive to produce a texture +coordinate for each fragment.  The fragment texture coordinates are +used to sample the current texture image.
    +
    +Texture coordinates are normally in the range [0, 1].  Values +outside that range are processed according to the texture wrap mode.  The +texture wrap mode is set with the command
    +
    +
    void glTexParameteri(GLenum target, GLenum pname, GLint value)
    +
    +
    +target must be GL_TEXTURE_2D. + If pname is +GL_TEXTURE_WRAP_S or GL_TEXTURE_WRAP_T then value must be either +GL_CLAMP_TO_EDGE or GL_REPEAT.
    +
    +For GL_CLAMP_TO_EDGE, texture coordinates are effectively clamped to +the interval [0, 1].
    +
    +For GL_REPEAT, the integer part of texture coordinates is ignored; only +the fractional part of the texture coordinates is used.  This +allows texture images to repeated or tiled across an object.
    +
    +

    5.3 Texture Sampling

    +Texture sampling is the process of using texture coordinates to extract +a color from the texture image.  Multiple, weighted samples may be +taken from the texture and combined during the filtering step.
    +
    +During texture coordinate interpolation a level of detail value (lambda) is +computed for each fragment.  For a mipmapped texture, lambda +determines which level (or levels) of the mipmap will be sampled to +obtain the texture color.
    +
    +If lambda indicates that multiple texels map to a single screen pixel, +then the texture minification +filter will be used.  Otherwise, if lambda indicates that a single +texel maps to multiple screen pixels, then the texture magnification filter will be used.
    +
    +

    5.3.1 Texture Minification

    +The texture minification filter is set with the glTexParameteri command by setting target to GL_TEXTURE_2D, setting pname to GL_TEXTURE_MIN_FILTER and +setting value to GL_NEAREST, +GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST,  +GL_NEAREST_MIPMAP_LINEAR,   GL_LINEAR_MIPMAP_NEAREST or +GL_LINEAR_MIPMAP_LINEAR.
    +
    +GL_NEAREST samples the texel nearest the texture coordinate in the +level 0 texture image.
    +
    +GL_LINEAR samples the four texels around the texture coordinate in the +level 0 texture image.  The four texels are linearly weighted to +compute the final texel value.
    +
    +GL_NEAREST_MIPMAP_NEAREST samples the texel nearest the texture +coordinate in the level N texture image.  N is the level of detail +and is computed by the partial derivatives of the texture coordinates +with respect to the window coordinates.
    +
    +GL_NEAREST_MIPMAP_LINEAR samples two texels nearest the texture +coordinates in the level N and N+1 texture images.  The two texels +are linearly weighted to compute the final texel value.  N is the +level of detail and is computed by the partial derivatives of the +texture coordinates with respect to the window coordinates.
    +
    +GL_LINEAR_MIPMAP_NEAREST samples four texels around the texture +coordinate in the level N texture image.  The four texels are +linearly weighted to compute the final texel value.  N is the level +of detail and is computed by the partial derivatives of the texture +coordinates with respect to the window coordinates.
    +
    +GL_LINEAR_MIPMAP_LINEAR samples four texels around the texture +coordinate in the level N texture image and four texels around the +texture coordinate in the level N+1 texture image.  The eight +texels are linearly weighted to compute the final texel value.  N +is the level of detail and is computed by the partial derivatives of the +texture coordinates with respect to the window coordinates.
    +
    +Filter modes other than GL_LINEAR and GL_NEAREST requires that the +texture have a complete set of mipmaps.  If the mipmap is +incomplete, it is as if texturing is disabled.

    +

    5.3.2 Texture Magnification

    +The texture magnification filter is set with the glTexParameteri command +by setting target to +GL_TEXTURE_2D, setting pname to +GL_TEXTURE_MAG_FILTER and setting value +to GL_NEAREST or GL_LINEAR.
    +
    +GL_NEAREST samples the texel nearest the texture coordinate in the +level 0 texture image.
    +
    +GL_LINEAR samples the four texels around the texture coordinate in the +level 0 texture image.  The four texels are linearly weighted to +compute the final texel value.
    +
    +

    5.4 Texture Application

    +The sampled texture value is combined with the incoming fragment color +to produce a new fragment color.  The fragment and texture colors +are combined according to the texture environment mode and the current +texture's base internal format.  The texture environment mode is +set with the command
    +
    +
    void +glTexEnvi(GLenum target, +GLenum pname, GLint value)
    +
    +
    +target must be GL_TEXTURE_ENV. + If pname is +GL_TEXTURE_ENV_MODE then value +must be one of GL_REPLACE, GL_MODULATE, GL_DECAL, or GL_BLEND.
    +
    +There is also a texture environment +color that can factor into texture application.  The texture +environment color can be set with the command
    +
    +
    void +glTexEnvfv(GLenum target, +GLenum pname, const GLfloat *value)
    +
    +
    +target must be GL_TEXTURE_ENV. + If pname is +GL_TEXTURE_ENV_COLOR then value must +point to an array of four values which specify the red, green, blue, +and alpha values of the texture environment color.  The values are +clamped to the range [0, 1].  The default color is (0, 0, 0, 0).
    +
    +The following table describes the arithmetic used for each combination +of environment mode and base internal format.  (Rf, Gf, Bf, Af) is +the incoming fragment color.  (Rt, Gt, Bt, At) is the sampled +texture color.  Lt is the sampled texture luminance.  'It' is the sampled texture +intensity.  (Rc, Gc, Bc, Ac) is the texture environment color. + (Rv, Gv, Bv, Av) is the resulting value.
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Base Internal Format
    +
    GL_REPLACE
    +
    GL_MODULATE
    +
    GL_DECAL
    +
    GL_BLEND
    +
    GL_INTENSITY
    +
    Rv = It
    +Gv = It
    +Bv = It
    +Bf = It
    +
    Rv = Rf * It
    +Gv = Gf * It
    +Bv = Bf * It
    +Av = Af * It
    undefined
    +
    Rv = Rf*(1-It) + Rc*It
    +Gv = Gf*(1-It) + Gc*It
    +Bv = Bf*(1-It) + Bc*It
    +Av = Af*(1-It) + Ac*It
    GL_RGB
    +
    Rv = Rt
    +Gv = Gt
    +Bv = Bt
    +Av = Af
    +
    Rv = Rf * Rt
    +Gv = Gf * Gt
    +Bv = Bf * Bt
    +Av = Af
    +
    Rv = Rt
    +Gv = Gt
    +Bv = Bt
    +Av = Af
    Rv = Rf*(1-Rt) + Rc*Rt
    +Gv = Gf*(1-Gt) + Gc*Gt
    +Bv = Bf*(1-Bt) + Bc*Bt
    +Av = Af
    GL_RGBA
    +
    Rv = Rt
    +Gv = Gt
    +Bv = Bt
    +Av = At
    +
    Rv = Rf * Rt
    +Gv = Gf * Gt
    +Bv = Bf * Bt
    +Av = Af * At
    Rv = Rf*(1-At) + Rt*At
    +Gv = Gf*(1-At) + Gt*At
    +Bv = Bf*(1-At) + Bt*At
    +Av = Af
    +
    Rv = Rf*(1-Rt) + Rc*Rt
    +Gv = Gf*(1-Gt) + Gc*Gt
    +Bv = Bf*(1-Bt) + Bc*Bt
    +Av = Af*At
    +
    +
    +
    +

    5.5 Texture Objects

    +Texture objects encapsulate a set of texture images (mipmap) and +related state into a named object.  This facilitates use of +multiple textures in an application.  Texture objects are named +with GLuints (unsigned integers).  There is a default texture +object with the name/identifier zero which can never be deleted.
    +
    +

    5.5.1 Creating Texture Objects

    +A texture object is created by binding a new GLuint identifier to the +GL_TEXTURE_2D target with the command:
    +
    +
    void glBindTexture(GLenum target, GLuint textureID)
    +
    +
    +target must be GL_TEXTURE_2D. + textureID may be any +unsigned integer.  If textureID +does not name an existing texture object, a new texture object with that +ID will be created, initialized to the default state.  Whether the +ID is new or existed previously, that named texture object is bound as +the current texture object. + Subsequent glTexParameter andglTexImage2D calls will effect the +current texture object.
    +
    +

    5.5.2 Deleting Texture Objects

    +One or more texture objects may be deleted with the command:
    +
    +
    void glDeleteTextures(GLsizein, const GLuint *textureIDs)
    +
    +
    +textureIDs is an array of n texture IDs.  The named +texture objects will be deleted.  If the current texture object is +deleted the default texture object (number 0) will be bound as the +current texture object.
    +
    +

    5.5.3 Allocating Texture Object Identifiers

    +A list of new, unused texture IDs can be obtained by calling the command
    +
    +
    void glGenTextures(GLsizei n, GLuint *textureIDs)
    +
    +
    +An array of n unused texture +IDs will be returned in the textureIDs +array.
    +
    +
    +

    6. Per-fragment Operations

    +The fragments produced by rasterization are subjected to a number of +operations which either modify the fragment or test the fragment +(discarding the fragment if the test fails.)  This chapter +describes the per-fragment operations.  They are presented in the +order in which they're performed.  If a fragment fails a test it is +discarded and not subjected to subsequent tests or modifications.
    +
    +

    6.1 Scissor Test

    +The scissor test limits rendering to a 2-D rectangular region of the +framebuffer.  The command
    +
    +
    void glScissor(GLintx, GLint y, GLsizei width, GLsizei height)
    +
    +
    +defines a clipping region with the lower-left corner at (x, y) and the given width and height.  The scissor test is +enabled and disabled with the command glEnable(GL_SCISSOR_TEST) +and glDisable(GL_SCISSOR_TEST).
    +
    +If the incoming fragment's position is (xf, yf) +then the fragment will pass the test if x <= xf < x + width and y <= yf < y + height.  Otherwise, the +fragment is discarded.
    +
    +If width or height is less than zero the error +GL_INVALID_VALUE is raised.  The default scissor rectangle bounds +are (0, 0, w, h) where w is the initial window width and h is the +initial window height.  The scissor test is disabled by default.
    +
    +

    6.2 Alpha Test

    +The alpha test compares the fragment's alpha value against a reference +value and discards the fragment if the comparison fails.  The test +is specified by the command
    +
    +
    void glAlphaFunc(GLenummode, GLclampf reference)
    +
    +
    +mode specifies an inequality +and reference specifies a value +to compare against.  The following table lists all possible +modes and the +corresponding test:
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Comparison mode
    +
    The test passes if
    +
    GL_LESS
    +
    alpha < reference
    +
    GL_LEQUAL
    +
    alpha <= reference
    GL_GREATER
    +
    alpha > reference
    GL_GEQUAL
    +
    alpha >= reference
    GL_EQUAL
    +
    alpha == reference
    GL_NOTEQUAL
    +
    alpha != reference
    GL_NEVER
    +
    never pass
    +
    GL_ALWAYS
    +
    always passes
    +
    +
    +The reference parameter is +clamped to the range [0, 1].
    +
    +The alpha test is enabled and disabled with the commands glEnable(GL_ALPHA_TEST) and glDisable(GL_ALPHA_TEST).
    +
    +The default mode is GL_ALWAYS and the default reference value is 0.
    +
    +

    6.3 Stencil Test

    +The stencil buffer stores an N-bit integer value for each pixel in the +frame buffer.  The stencil test compares the stencil buffer value +at the fragment's position to a reference value and possibly discards +the fragment based on the outcome.  Furthermore, the stencil buffer +value may be updated or modified depending on the outcome.  If +there is no stencil buffer the stencil test is bypassed.
    +
    +Stenciling is controlled by the commands
    +
    +
    void glStencilFunc(GLenumfunc, GLint ref, GLuint mask)
    +void glStencilOp(GLenum stencilFail, GLenum depthTestFail, GLenum depthTestPass)
    +
    +
    +The glStencilFunc command controls the +stencil test while glStencilOp +command controls the how the stencil buffer is updated/modified after +the test.
    +
    +ref is clamped to the range [0, +2N-1] where N is the number of bits per stencil value in the +stencil buffer.
    +
    +The following table lists all possible values for the func parameter and when the stencil +test will pass.  Both the stencil buffer value and the stencil +reference value are bit-wise ANDed with the mask parameter before the test.
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Stencil func value
    +
    Stencil test passes if
    +
    GL_LESS
    +
    (ref&mask) < (stencil buffer value +& mask)
    +
    GL_LEQUAL
    +
    (ref +& mask) <= (stencil +buffer value & mask)
    GL_GREATER
    +
    (ref +& mask) > (stencil +buffer value & mask)
    GL_GEQUAL
    +
    (ref +& mask) >= (stencil +buffer value & mask)
    GL_EQUAL
    +
    (ref +& mask) == (stencil +buffer value & mask)
    GL_NOTEQUAL
    +
    (ref +& mask) != (stencil +buffer value & mask)
    GL_NEVER
    +
    never passes
    +
    GL_ALWAYS
    +
    always passes
    +
    +
    +
    +If the stencil test passes, the fragment is passed to the next +per-fragment operation.  Otherwise, if the stencil test fails, the +value in the stencil buffer is updated according to the value of the stencilFail parameter to glStencilOp.
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    stencilFail +value
    +
    New stencil buffer value
    +
    GL_KEEP
    +
    originalValue
    +
    GL_ZERO
    +
    0
    +
    GL_INVERT
    +
    BitWiseInvert(originalValue) +i.e. ~originalValue
    +
    GL_REPLACE
    +
    ref
    +
    GL_INCR
    +
    originalValue + 1, clamped to +[0, 2N-1]
    GL_DECR
    +
    originalValue - 1, clamped to +[0, 2N-1]
    +
    +
    +The depthTestFail and depthTestPass parameters to glStencilOp are ignored.  Values +for func and stencilFail other than those listed +in the table will cause the error GL_INVALID_ENUM to be raised.
    +
    +The stencil test is enabled and disabled with the commands glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
    +
    +The default stencil function is GL_ALWAYS.  The default stencil +reference value is 0.  The default stencil mask is ~0.  The +default stencil fail operation is GL_KEEP.
    +
    +Values written into the stencil buffer are masked with the command
    +
    +
    void glStencilMask(GLuintmask)
    +
    +
    +Only the bits which are set in mask +will be modified in the stencil buffer when written to.  If each +stencil buffer value has N bits, only the least significant N bits of mask are relevant.  The default +stencil mask is ~0.
    +
    +

    6.4 Blending and Logicop

    +Blending or a logic operation combines the incoming fragment color with +the destination frame buffer color according to a blending equation or +bit-wise Boolean logical operation.
    +
    +Blending is enabled and disabled with the commands glEnable(GL_BLEND) and glDisable(GL_BLEND).
    +
    +The logic operation is enabled and disabled with the commands glEnable(GL_LOGIC_OP) and glDisable(GL_LOGIC_OP).
    +
    +If both blending and the logic operation are enabled, the logic +operation has higher priority; blending is bypassed.
    +
    +

    6.4.1 Logic Op

    +The command
    +
    +
    void glLogicop(GLenummode)
    +
    +
    +Specifies the Boolean logic operation for combining the incoming +fragment color with the destination frame buffer color.  Both the +incoming fragment color and destination frame buffer colors are +interpreted as four-tuples of unsigned integer color components in the +range [0, 2N-1] where N is the number of bits per color +channel.  N may not be the same for all color channels.
    +
    +The following table lists all values for mode and the boolean arithmetic used +to combine the incoming fragment color value (src) with the destination framebuffer +color value (dst).  Standard ANSI C operators used.
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    LogicOp mode
    +
    Resulting channel value
    +
    GL_CLEAR
    +
    0
    +
    GL_SET
    +
    ~0
    +
    GL_COPY
    +
    src
    +
    GL_COPY_INVERTED
    +
    ~s
    +
    GL_NOOP
    +
    dst
    +
    GL_INVERT
    +
    ~dst
    +
    GL_AND
    +
    src & dst
    +
    GL_NAND
    +
    ~(src & dst)
    +
    GL_AND_REVERSE
    +
    src & ~dst
    +
    GL_AND_INVERTED
    +
    ~src & dst
    +
    GL_OR
    +
    src | dst
    +
    GL_NOR
    +
    ~(src | dst)
    +
    GL_OR_REVERSE
    +
    src | ~dst
    +
    GL_OR_INVERTED
    +
    ~src | dst
    +
    GL_XOR
    +
    src ^ dst
    +
    GL_EQUIV
    +
    ~(src ^ dst)
    +
    +
    +The fragment's color is replaced by the result of the logic operation.
    +
    +Specifying any value for mode +other than those listed in the above table will cause the error +GL_INVALID_ENUM to be raised.
    +
    +The default value for mode is +GL_COPY.  The logic operation is disabled by default.
    +
    +

    6.4.2 Blending

    +The command
    +
    +
    void glBlendFunc(GLenumsrcTerm, GLenum dstTerm)
    +
    +
    +specifies the terms of the blending equation.  If Cf = (Rf, Gf, +Bf, Af) is the incoming fragment color and Cb = (Rb, Gb, Bb, Ab) is the +frame buffer color, then the resulting color Cv = (Rv, Gv, Bv, Av) is +computed by:
    +
    +
    Cv = Cf * srcTerm + Cb * dstTerm
    +
    +
    +All possible values for srcTerm +and the corresponding arithmetic term are listed in the following table:
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    srcTerm
    +
    srcTermArithmetic
    +
    GL_ZERO
    +
    (0, 0, 0, 0)
    +
    GL_ONE
    +
    (1, 1, 1, 1)
    +
    GL_DST_COLOR
    +
    (Rb, Gb, Bb, Ab)
    +
    GL_ONE_MINUS_DST_COLOR
    +
    (1-Rb, 1-Gb, 1-Bb, 1-Ab)
    +
    GL_SRC_ALPHA
    +
    (Af, Af, Af, AF)
    +
    GL_ONE_MINUS_SRC_ALPHA
    +
    (1-Af, 1-Af, 1-Af, 1-Af)
    +
    GL_DST_ALPHA
    +
    (Ab, Ab, Ab, Ab)
    +
    GL_ONE_MINUS_DST_ALPHA
    +
    (1-Ab, 1-Ab, 1-Ab, 1-Ab)
    +
    GL_SRC_ALPHA_SATURATE
    +
    (m, m, m, 1) where m = MIN(Af, +1-Ab)
    +
    +
    +All possible values for srcTerm +and the corresponding arithmetic term are listed in the following table:
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    dstTerm
    +
    dstTermArithmetic
    +
    GL_ZERO
    +
    (0, 0, 0, 0)
    +
    GL_ONE
    +
    (1, 1, 1, 1)
    +
    GL_SRC_COLOR
    +
    (Rf, Gf, Bf, Af)
    +
    GL_ONE_MINUS_SRC_COLOR
    +
    (1-Rf, 1-Gf, 1-Bf, 1-Af)
    +
    GL_SRC_ALPHA
    +
    (Af, Af, Af, AF)
    +
    GL_ONE_MINUS_SRC_ALPHA
    +
    (1-Af, 1-Af, 1-Af, 1-Af)
    +
    GL_DST_ALPHA
    +
    (Ab, Ab, Ab, Ab)
    +
    GL_ONE_MINUS_DST_ALPHA
    +
    (1-Ab, 1-Ab, 1-Ab, 1-Ab)
    +
    +
    +The fragment's color is replaced by the result of the blending equation.
    +
    +Values for srcTerm and dstTerm other than those listed in +the table will cause the error GL_INVALID_ENUM to be raised.
    +
    +The default value for srcTerm +is GL_ONE.  The default value for dstTerm +is GL_ZERO.  Blending is disabled by default.
    +
    +

    6.5 Color Mask

    +The final fragment color is written into the current color buffer at +the end of the per-fragment operations.  Normally, all color +channels in the frame buffer are replaced with the final fragment color. + However, the command
    +
    +
    void glColorMask(GLbooleanredMask, GLboolean greenMask, GLboolean blueMask, GLboolean alphaMask)
    +
    +
    +allows selective writing to individual color channels.  If redMask is GL_TRUE then writing to +the red color channel is enabled, otherwise it's disabled. + Similarly, the green, blue and alpha channels can also be masked.
    +
    +Initially all four mask values are GL_TRUE.
    +
    +Color masking is not enabled/disabled with the glEnable/glDisable commands.
    +
    +

    7. Frame Buffer Operations

    +The frame buffer is considered to be a two-dimensional array of pixels. + The frame buffer is also organized into layers or logical buffers. + There may be a front color buffer, back color buffer and stencil +buffer.  A double-buffered frame buffer has both a front color +buffer and back color buffer.  A single-buffered framebuffer only +has a front color buffer.  Each pixel in a color buffer has a red, +green and blue value and an optional alpha value.
    +
    +

    7.1 Clearing Buffers

    +Buffers are cleared (set to uniform values) with the command
    +
    +
    void glClear(GLbitfieldbuffers)
    +
    +
    +buffers is a bitmask for which +the value may be the bitwise-OR of the values GL_COLOR_BUFFER_BIT and +GL_STENCIL_BUFFER_BIT.  If the GL_COLOR_BUFFER_BIT bit is +specified, the current color buffer will be cleared.  If the +GL_STENCIL_BUFFER_BIT bit is specified, the stencil buffer will be +cleared.
    +
    +The current color buffer is specified with the command
    +
    +
    void glDrawBuffer(GLenum buffer)
    +
    +
    +buffer may be either GL_FRONT, +GL_BACK or GL_NONE.  GL_FRONT indicates that the front color buffer +will be modified by glClear and +any drawing command.  GL_BACK indicates that the back color buffer +will be modified by glClear and +any drawing command.  GL_NONE indicates that neither color buffer +will be modified by glClear or +any drawing command.  GL_BACK is only valid for double-buffered +frame buffers.
    +
    +The current scissor rectangle, set by the glScissor command, effects glClear, limiting +the clear to the scissor rectangle, if it's enabled.  Furthermore, only the color channels enabled by glColorMask will be effected by glClear(GL_COLOR_BUFFER_BIT). + Likewise, only the stencil bits enabled by glStencilMask will be effected by glClear(GL_STENCIL_BUFFER_BIT).
    +
    +The current clear color is set with the command
    +
    +
    void glClearColor(GLclampfred, GLclampf green, GLclampf blue, GLclampf alpha)
    +
    +
    +Subsequent calls to glClear +will use the color (red, green, blue, +alpha) to clear the front or back color buffers.
    +
    +The current stencil clear value is set with the command
    +
    +
    void glClearStencil(GLintclearValue)
    +
    +
    +If the stencil buffer is N bits deep, the least significant N bits of clearValue will be used to clear the +stencil buffer.
    +
    +
    +

    8. Other Features

    +

    8.1 Frame Buffer Readback

    +A rectangular region of pixels can be read from the frame buffer and +placed in client memory with the command
    +
    +
    void glReadPixels(GLintx, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *data)
    +
    +
    +x and y specify the coordinate of the +lower-left corner of the region to read and width and height specify the size of the +rectangular region to read.  format +specifies the format of image data and must be either GL_RGB or +GL_RGBA.  type specify the +data type of the image data and must be either GL_UNSIGNED_BYTE or +GL_FLOAT.  Other values for format +or type will cause the error +GL_INVALID_ENUM to be raised.
    +
    +The framebuffer may contain 3-component colors (red, green, blue) or +4-component colors (red, green, blue, alpha).  If an alpha channel +is not present, alpha values default to 1.0.
    +
    +The frame buffer color components (red, green, blue, alpha) are either +converted to 8-bit unsigned integers in the range[0, 255] if type is GL_UNSIGNED_BYTE or +converted to floating point values in the range [0, 1] if type is GL_FLOAT.  The (red, +green, blue, alpha) tuples are then stored as GL_RGB triplets (by +dropping the alpha component) or GL_RGBA quadruples in client memory.
    +
    +Image data is packed into +client memory according to the pixel packing parameters which are set by +the command
    +
    +
    void glPixelStorei(GLenum pname, GLint value)
    +
    +
    +pname must be +GL_PACK_ROW_LENGTH.  value +indicates the stride (in pixels) between subsequent rows in the +destination image.  If GL_PACK_ROW_LENGTH is zero (the default) +then the width parameter to glReadPixels indicates the row stride.
    +
    +Pixel readback takes place as follows:
    +
    +
    if (GL_PACK_ROW_LENGTH == 0)
    +    rowLength = width;
    +else
    +    rowLength = GL_PACK_ROW_LENGTH
    +
    +if (format == GL_RGB) {
    +    for (i = 0; i < height; +i++) {
    +        for (j = 0; j < width; j++) {
    +            k = (i * +rowLength + j) * 3;
    +            data[k+0] = FrameBuffer(x + j, y + i).red;
    +            data[k+1] = FrameBuffer(x + j, y + i).green;
    +            data[k+2] = FrameBuffer(x + j, y + i).blue;
    +        }
    +    }
    +}
    +else {
    +    for (i = 0; i < height; +i++) {
    +        for (j = 0; j < width; j++) {
    +            k = (i * +rowLength + j) * 4;
    +            data[k+0] = FrameBuffer(x + j, y + i).red;
    +            data[k+1] = FrameBuffer(x + j, y + i).green;
    +            data[k+2] = FrameBuffer(x + j, y + i).blue;
    +            data[k+3] = FrameBuffer(x + j, y + i).alpha;
    +        }
    +    }
    +}
    +
    +
    +The function FrameBuffer(c, r) +returns the pixel in the frame buffer at column c of row r.  data is considered to be either a +GLubyte pointer or a GLfloat pointer, depending on the type parameter.  Similarly, the +FrameBuffer function returns either GLubyte values in the range [0, 255] +or GLfloat values in the range [0,1], depending on the type parameter.
    +
    +Pixels may be read from either the front or back color buffer. + The command
    +
    +
    void glReadBuffer(GLenumbuffer)
    +
    +
    +specifies the source for reading images with glReadPixels.  If buffer is GL_FRONT then front color +buffer is the source.  If buffer +is GL_BACK then the back color buffer is the source.  It is illegal +to specify GL_BACK when the color buffer is not double buffered. + Any invalid value for buffer +will raise the error GL_INVALID_ENUM.
    +
    +The default read source is GL_BACK if the frame buffer is double +buffered.  Otherwise, the default read source is GL_FRONT.
    +
    +

    8.2 Selection Mode

    +Selection mode is typically used to implement picking: determining which +primitive(s) are present at particular window positions.  The +command
    +
    +
    GLint glRenderMode(GLenummode)
    +
    +
    +is used to enable selection mode.  If mode is GL_SELECTION the graphics +library is put into selection mode.  If mode is GL_RENDER the graphic +library is put into normal rendering mode.  Any other value for mode will raise the error +GL_INVALID_ENUM.
    +
    +When in selection mode rendering commands will not effect the +framebuffer.  Instead, a record of the primitives that would have +been drawn is placed in the selection buffer.  The selection buffer +is specified with the command
    +
    +
    void glSelectionBuffer(GLsizein, GLuint *buffer)
    +
    +
    +buffer
    is an array of n +unsigned integers.  No more than n +values will be placed in the buffer.
    +
    +The name stack is a stack +(LIFO) of unsigned integer names.  The following commands +manipulate the name stack:
    +
    +
    void glInitNames(void)
    +void glPushName(GLuint name)
    +void glPopName(void)
    +void glLoadName(GLuint name)
    +
    +
    +glInitNames resets the name +stack to an empty state.  glPushName pushes the given name value onto the stack.  glPopName pops the top name from the +stack.  glLoadName replaces the top value on +the stack with the specified name. + Stack underflow and overflow conditions cause the errors +GL_STACK_OVERFLOW and GL_STACK_UNDERFLOW to be raised.
    +
    +While in selection mode, primitives (points, lines, polygons) are +transformed and clip-tested normally.  Primitives which aren't +discarded by clipping cause the hit data to be updated.  The hit +data consists of three pieces of information: a hit flag, a minimum Z +value and a maximum Z value.  First, the hit flag is set. + Then, for each of the primitive's vertices, the vertex Z value is +compared to the minimum and maximum Z values.  The minimum Z value +is updated if the vertex's Z value is less than the minimum Z value. + The maximum Z value is updated if the vertex's Z value is greater +than the maximum Z value.
    +
    +When any of glInitNames, glPushName, glPopName, glLoadName or glRenderMode are called and the hit +flag is set, a hit record is +written to the selection buffer.
    +
    +A hit record consists of a sequence of unsigned integers.  The +first value is the size of the name stack.  The second value is the +minimum Z value multiplied by 232-1.  The third value is +the maximum Z value multiplied by 232-1.  The remaining +values are the values in the name stack, in bottom to top order. + The hit flag is cleared after a hit record is written to the +selection buffer.  Hit records are places sequentially into the +selection buffer until it is full or selection mode is terminated.
    +
    +Selection mode is terminated by calling glRenderMode(GL_RENDER).   The +return value of glRenderMode +will be -1 if the selection buffer overflowed.  Otherwise, the +return value will indicate the number of values written into the +selection buffer.
    +
    +

    8.3 Synchronization

    +The command
    +
    +
    void glFlush(void)
    +
    +
    +makes the graphics library to flush all pending graphics commands. + The command
    +

    +void glFinish(void)
    +
    +
    +makes the graphics library flush the command queue and wait until those +commands are completed.  glFlush +will not return until all previous graphics commands have been fully +completed.
    +
    +These commands are typically used to force completion of rendering to +the front color buffer.  Otherwise, rendering to the front color +buffer may not appear.  The swapbuffers +command (part of the window system binding library) does an implicit +flush before swapping the front and back color buffers.  The glReadPixels command also does an +implicit flush before reading pixel data from the frame buffer.
    +
    +

    9. State Queries

    +The current value of nearly all library state variables can be queried. + This chapter describes the commands used for querying the value of +state variables.
    +
    +

    9.1 General State Queries

    +The command
    +
    +
    void glGetFloatv(GLenumpname, GLfloat *values)
    +
    +
    +returns the value(s) of the state variable specified by pname.  The following table +lists all accepted values for pname +and a description of the value(s).  Specifying any other value for pname causes the error +GL_INVALID_ENUM to be raised.
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Variable (pname)
    +
    Number of values
    +
    Value(s) Description
    +
    GL_ALPHA_BITS
    +
    1
    +
    Number of bits per alpha value +in the frame buffer.
    +
    GL_ALPHA_TEST
    +
    1
    +
    Zero if the alpha test is +disabled.
    +One if the alpha test is enabled.
    +
    GL_ALPHA_TEST_FUNC
    +
    1
    +
    The alpha test function.
    +
    GL_BLEND
    +
    1
    +
    Zero if blending is disabled.
    +One if blending is enabled.
    +
    GL_BLEND_DST
    +
    1
    +
    Blend destination function/term.
    +
    GL_BLEND_SRC
    +
    1
    +
    Blend source function/term.
    +
    GL_BLUE_BITS
    +
    1
    +
    Number of bits per blue value in +the frame buffer.
    +
    GL_COLOR_CLEAR_VALUE
    +
    4
    +
    Clear color (red, green, blue, +alpha).
    +
    GL_COLOR_WRITE_MASK
    +
    4
    +
    Color buffer writemask (red, +green, blue, alpha).
    +Zero if writing is disabled.
    +One if writing is enabled.
    +
    GL_CULL_FACE
    +
    1
    +
    Zero if polygon culling is +disabled.
    +One if polygon culling is enabled.
    +
    GL_CULL_FACE_MODE
    +
    1
    +
    Polygon cull mode: GL_FRONT, +GL_BACK or GL_FRONT_AND_BACK.
    +
    GL_CURRENT_COLOR
    +
    4
    +
    Current color (red, green, blue, +alpha).
    +
    GL_CURRENT_RASTER_COLOR
    +
    4
    +
    Current raster position color +(red, green, blue, alpha).
    +
    GL_CURRENT_RASTER_TEXTURE_COORDS
    +
    4
    +
    Current raster position texture +coordinates (s, t, r, q).
    +
    GL_CURRENT_RASTER_POSITION
    +
    4
    +
    Current raster position (x, y, +z, w).
    +
    GL_CURRENT_POSITION_VALID
    +
    1
    +
    Zero if current raster position +is invalid.
    +One if current raster position is valid.
    +
    GL_CURRENT_TEXTURE_COORDS
    +
    4
    +
    Current texture coordinates (s, +t, r, q)
    +
    GL_DOUBLEBUFFER
    +
    1
    +
    Zero if color buffer is +single-buffered.
    +One if color buffer is double-buffered.
    +
    GL_DRAW_BUFFER
    +
    1
    +
    Current color draw buffer: +GL_FRONT or GL_BACK.
    +
    GL_FRONT_FACE1
    +
    Polygon front-face winding: +GL_CW or GL_CCW.
    +
    GL_GREEN_BITS
    +
    1
    +
    Number of bits per green value +in the frame buffer.
    +
    GL_LINE_SMOOTH
    +
    1
    +
    Zero if line smoothing is +disabled.
    +One if line smoothing is enabled.
    +
    GL_LINE_STIPPLE
    +
    1
    +
    Zero if line stippling is +disabled.
    +One if line stippling is enabled.
    +
    GL_LINE_STIPPLE_PATTERN
    +
    1
    +
    Line stipple pattern.
    +
    GL_LINE_STIPPLE_REPEAT
    +
    1
    +
    Line stipple repeat factor.
    +
    GL_LINE_WIDTH
    +
    1
    +
    Line width in pixels.
    +
    GL_LINE_WIDTH_GRANULARITY
    +
    1
    +
    Aliased line width granularity.
    +
    GL_LINE_WIDTH_RANGE
    +
    2
    +
    Minimum and maximum aliased line +widths.
    +
    GL_ALIASED_LINE_WIDTH_RANGE
    +
    2
    +
    Minimum and maximum antialiased +line widths.
    GL_COLOR_LOGIC_OP
    +
    1
    +
    Zero if logicop is disabled.
    +One if logicop is enabled.
    +
    GL_LOGIC_OP_MODE
    +
    1
    +
    Logicop function.
    +
    GL_MATRIX_MODE
    +
    1
    +
    Matrix mode: GL_MODELVIEW or +GL_PROJECTION.
    +
    GL_MAX_MODELVIEW_STACK_DEPTH
    +
    1
    +
    Maximum size of the modelview +matrix stack.
    +
    GL_MAX_NAME_STACK_DEPTH
    +
    1
    +
    Maximum size of the selection +name stack.
    +
    GL_MAX_PROJECTION_STACK_DEPTH
    +
    1
    +
    Maximum size of the projection +matrix stack.
    +
    GL_MAX_TEXTURE_SIZE
    +
    1
    +
    Maximum 2D texture image width +and height.
    +
    GL_MAX_VIEWPORT_DIMS
    +
    2Maximum viewport width and +height in pixels.
    +
    GL_MODELVIEW_MATRIX
    +
    16
    +
    Current/top modelview matrix +values.
    +
    GL_MODELVIEW_MATRIX_STACK_DEPTH
    +
    1
    +
    Current size of the modelview +matrix stack.
    +
    GL_NAME_STACK_DEPTH
    +
    1
    +
    Current size of the selection +name stack.
    +
    GL_PACK_ROW_LENGTH
    +
    1
    +
    Pixel packing row length.
    +
    GL_POLYGON_SMOOTH
    +
    1
    +
    Zero if polygon smoothing is +disabled.
    +One if polygon smoothing is enabled.
    +
    GL_PROJECTION_MATRIX
    +
    16
    +
    Current/top projection matrix +values.
    +
    GL_PROJECTION_STACK_DEPTH
    +
    1
    +
    Current size of projection +matrix stack.
    +
    GL_READ_BUFFER
    +
    1
    +
    Current read buffer: GL_FRONT or +GL_BACK.
    +
    GL_RED_BITS
    +
    1
    +
    Number of bits per red value in +the frame buffer.
    +
    GL_RENDER_MODE
    +
    1
    +
    Current rendering mode: +GL_RENDER or GL_SELECTION.
    +
    GL_RGBA_MODE
    +
    1
    +
    Always one.
    +
    GL_SCISSOR_BOX
    +
    4
    +
    Scissor box (x, y, width, +height).
    +
    GL_SCISSOR_TEST
    +
    1
    +
    Zero if scissor test is disabled.
    +One if scissor test is enabled.
    +
    GL_SELECTION_BUFFER_SIZE
    +
    1
    +
    Size of selection buffer.
    +
    GL_SHADE_MODEL
    +
    1
    +
    Shade model: GL_FLAT or +GL_SMOOTH.
    +
    GL_STENCIL_BITS
    +
    1
    +
    Number of bits per stencil value +in the frame buffer.
    +
    GL_STENCIL_CLEAR_VALUE
    +
    1
    +
    Stencil buffer clear value.
    +
    GL_STENCIL_FAIL
    +
    1
    +
    Stencil fail operation.
    +
    GL_STENCIL_FUNC
    +
    1
    +
    Stencil function.
    +
    GL_STENCIL_REF
    +
    1
    +
    Stencil reference value.
    +
    GL_STENCIL_TEST
    +
    1
    +
    Zero if stencil test is disabled.
    +One if stencil test is enabled.
    +
    GL_STENCIL_VALUE_MASK
    +
    1
    +
    Stencil mask value.
    +
    GL_STENCIL_WRITE_MASK
    +
    1
    +
    Stencil buffer write mask.
    +
    GL_TEXTURE_2D
    +
    1
    +
    Zero if 2D texture mapping is +disabled.
    +One if 2D texture mapping is enabled.
    +
    GL_TEXTURE_BINDING_2D1
    +
    Name of currently bound 2D +texture object.
    +
    GL_TEXTURE_ENV_COLOR
    +
    4
    +
    Texture environment color (red, +green, blue, alpha).
    +
    GL_TEXTURE_ENV_MODE
    +
    1
    +
    Texture environment mode.
    +
    GL_UNPACK_ROW_LENGTH
    +
    1
    +
    Pixel unpacking row length.
    +
    GL_UNPACK_LSB_FIRST
    +
    1
    +
    Zero if most significant bit is +unpacked first for bitmaps.
    +One if least significant bit is unpacked first for bitmaps.
    +
    GL_VIEWPORT
    +
    4
    +
    Current viewport (x, y, width, +height).
    +
    +
    +
    +

    9.2 String Queries

    +The command
    +
    +
    const GLubyte *glGetString(GLenum name)
    +
    +
    +is used to query string-valued values.  The legal values for name are described in the following +table:
    +
    + + + + + + + + + + + + + + + + + + + + + + + +
    name
    +
    Return value
    +
    GL_VERSION
    +
    The library version, such as +"1.2".
    +
    GL_RENDERER
    +
    The renderer, such as "Mesa DRI +Radeon".
    +
    GL_VENDOR
    +
    The vendor of this +implementation, such as "Tungsten Graphics, Inc."
    +
    GL_EXTENSIONS
    +
    A white-space separated list of +the supported extensions.
    +
    +

    9.3 Error Queries

    +The command
    +
    +
    GLenum glGetError(void)
    +
    +
    +returns the current error code.  The current error code will be +set by a GL command when an error condition has been detected.  If +the current error code is already set, subsequent errors will not be +recorded.  The error code is reset/cleared to GL_NO_ERROR when glGetError returns.  The +following error codes are possible:
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Error code
    +
    Meaning
    +
    GL_NO_ERROR
    +
    No error has been recorded.
    +
    GL_INVALID_ENUM
    +
    An enum parameter had an invalid +value.
    +
    GL_INVALID_VALUE
    +
    A numeric parameter had an +invalid value.
    +
    GL_INVALID_OPERATION
    +
    A function was called when not +legal to do so.
    +
    GL_STACK_OVERFLOW
    +
    The current transformation +matrix stack is full.
    +
    GL_STACK_UNDERFLOW
    +
    The current transformation +matrix stack is empty.
    +
    GL_OUT_OF_MEMORY
    +
    The system ran out of dynamic +memory.
    +
    +
    +
    +

    10. Unsupported Features

    +This section lists other features and functions which are not supported +and not previously discussed.
    +
    +

    10.1 Feedback Mode

    +Feedback mode and the following related functions are not supported.
    +
    +
    glFeedbackBuffer
    +glPassThrough
    +
    +
    +

    10.2 1D and 3D Textures
    +

    +Only 2D texture images are supported.  The following functions +used to specify 1D and 3D texture images are not supported:
    +
    +
    glTexImage1D
    +glTexImage3D
    +glTexSubImage1D
    + glTexSubImage3D
    +glCopyTexImage1D
    + glCopyTexSubImage1D
    + glCopyTexSubImage3D
    +
    +
    +

    10.3 Alternate Texture Image Commands
    +

    +Texture images may only be specified with glTexImage2D.  The following +alternate texture image commands are not supported:
    +
    +
    glTexSubImage2D
    +glCopyTexImage2D
    +glCopyTexSubImage2D
    +
    +
    +

    10.4 Proxy Textures

    +Proxy textures are not supported and the GL_PROXY_TEXTURE_2D token is +not supported by any function.
    +
    +
    +

    10.5 Other Texture Commands

    +The following commands related to texture mapping are not supported by +the subset:
    +
    +
    glPrioritizeTextures
    +glAreTexturesResident
    +glIsTexture
    +glTexEnviv
    +glTexEnvf
    +glTexParameterf
    +glTexParameteriv
    +glTexParameterfv
    +
    +
    +
    +

    10.6 Copy and Draw Pixels
    +

    +The following commands are not supported:
    +
    +
    glDrawPixels
    +glCopyPixels
    +glPixelZoom
    +
    +
    +

    10.7 Color Index Mode
    +

    +Color index mode and the following related commands are not supported:
    +
    + +
    glIndexub
    +
    glIndexi
    +glIndexs
    +glIndexf
    +glIndexd
    +
    glIndexubv
    +
    glIndexiv
    +glIndexsv
    +glIndexfv
    +glIndexdv

    +glIndexMask
    +
    glClearIndex
    +glIndexPointer

    +
    +
    +

    10.8 Pixel Transfer Operations

    +The pixel transfer operations (scale, bias, look-up table, etc) are not +supported and the following commands are omitted:
    +
    +
    glPixelTransferf
    +glPixelTransferi
    +glPixelMapfv
    +glPixelMapuiv
    +glPixelMapusv
    +glGetPixelMapfv
    +glGetPixelMapuiv
    +glGetPixelMapusv
    +
    +
    +

    10.9 Hints

    +Hints and the following related command is not supported:
    +
    +
    glHint
    +

    +
    +

    10.10 State Query Commands
    +

    +The following state query commands are not supported:
    +
    +
    glGetBooleanv
    +glGetIntegerv
    +glGetDoublev
    +glGetPointerv
    +glGetTexEnvi
    +glGetTexEnvf
    +glGetTexParameteriv
    +glGetTexParameterfv
    +glGetTexLevelParameteriv
    +glGetTexLevelParameterfv
    +glGetTexImage
    +glGetClipPlane
    +
    +
    +

    10.11 Attribute Stacks

    +State attribute stacks and the following related commands are not +supported:
    +
    +
    glPushAttrib
    +glPopAtttrib
    +
    +
    +

    10.12 Double-Valued Functions

    +All functions which take double-precision floating point values, but +for which there is an equivalent single-precision valued function, are +omitted.  This includes, but is not limited to:
    +
    +
    glVertex2d
    +glVertex2dv
    +glVertex3d
    + glVertex3dv
    +glVertex4d
    + glVertex4dv
    +glColor3d
    +glColor3dv
    +glColor4d
    + glColor4dv
    +glTexCoord1d
    +glTexCoord1dv
    +glTexCoord2d
    + glTexCoord2dv
    +glTexCoord3d
    + glTexCoord3dv
    +glTexCoord4d
    + glTexCoord4dv
    +glRasterPos2d
    + glRasterPos2dv
    +glRasterPos3d
    + glRasterPos3dv
    +glRasterPos4d
    + glRasterPos4dv
    +glLoadMatrixd
    +glMultMatrixd
    +glScaled
    +glRotated
    +glTranslated
    +glRectd
    +glRectdv
    +

    +
    +

    10.13 Evaluators

    +Evaluators and the following related commands are not supported:
    +
    +
    glMap1f
    +glMap2d
    +glMap2f
    +glGetMapdv
    +glGetMapfv
    +glGetMapiv
    +glEvalCoord1d
    +glEvalCoord1f
    +glEvalCoord1dv
    +glEvalCoord1fv
    +glEvalCoord2d
    +glEvalCoord2f
    +glEvalCoord2dv
    +glEvalCoord2fv
    +glMapGrid1d
    +glMapGrid1f
    +glMapGrid2d
    +glMapGrid2f
    +glEvalPoint1
    +glEvalPoint2
    +glEvalMesh1
    +glEvalMesh2
    +
    +
    +

    10.14 Display Lists

    +Display lists and the following related commands are not supported:
    +
    +
    glIsList
    +glDeleteLists
    +glGenLists
    +glNewList
    +glEndList
    +glCallList
    +glCallLists
    +glListBase
    +
    +
    +

    10.15 Accumulation Buffer

    +The accumulation buffer and the following related commands are not +supported:
    +
    +
    glAccum
    +glClearAccum
    +
    +
    +

    10.16 Fog

    +Fog and the following related commands are not supported:
    +
    +
    glFogi
    +glFogf
    +glFogiv
    +glFogfv
    +
    +
    +

    10.17 Depth Test

    +Depth testing and the following related commands are not supported:
    +
    +
    glDepthFunc
    +glDepthMask
    +glDepthRange
    +glClearDepth
    +
    +
    +

    10.18 Imaging Subset

    +The OpenGL imaging subset (which implements features such as +convolution, histogram, min/max recording, color matrix and color +tables) is not supported.
    +
    +
    +

    Appendix A: Issues

    +This appendix lists documentation and subset issues with their current +status.  For items which are still open, the documentation (above) +follows the recommended solution.
    +
    +

    A.1 Vertex Arrays

    +Should vertex arrays be supported?  Is there a performance +advantage?
    +
    +RESOLUTION: No, there isn't enough of a performance advantage to +justify them.
    +
    +

    A.2 Polygon Antialiasing and Edge Flags

    +Should edge flags be supported for antialiasing?
    +
    +Edge flags don't effect antialiasing, at least not normally.  A +number of approaches to antialiasing have been summarized in email.
    +
    +RECOMMENDATION: don't support edge flags.  They don't effect +polygon antialiasing.
    +
    +RESOLUTION: closed, as of 26 Feb 2003.
    +
    +

    A.3 glRasterPos vs. glWindowPos

    +Should glRasterPos and/or glWindowPos commands be supported?
    +
    +RESOLUTION: Closed: implement glRasterPos commands, but not glWindowPos +commands.
    +
    +

    A.4 GL_IBM_rasterpos_clip extension

    +Should the GL_IBM_rasterpos_clip extension be implemented?
    +
    +RESOLUTION:  No.  It's not required.
    +
    +

    A.5 Image Formats and Types

    +Which image formats and types should be supported for glTexImage2D and glReadPixels?
    +
    +OpenGL specifies a large +variety of image formats and data types.  Only a few are commonly +used.
    +
    +RECOMMENDATION:  we propose a subset:
    +
    +For glTexImage2D only allow type=GL_UNSIGNED_BYTE and format=GL_RGBA, GL_RGB, +GL_INTENSITY.   Only allow internalFormat +to be GL_RGBA, GL_RGB or GL_INTENSITY as well.  Basically, only +support image formats/types that are directly supported by the Radeon +hardware.  This will allow glTexImage2D +to basically just use memcpy to +copy texture images.
    +
    +For glReadPixels, only allow type = GL_UNSIGNED_BYTE or GL_FLOAT. + Only allow format = +GL_RGB or GL_RGBA.  This is just enough to support the OpenGL +conformance tests.
    +
    +RESOLUTION: open
    +
    +

    A.6 Texture Environment Modes

    +Which texture environment modes should be supported?  OpenGL 1.2 +has GL_REPLACE, GL_MODULATE, GL_DECAL and GL_BLEND.  GL_DECAL isn't +defined for all base internal texture formats.  GL_ADD is another +useful mode.  Perhaps drop GL_DECAL mode and add GL_ADD mode.
    +
    +RECOMMENDATION: implement the standard modes GL_REPLACE, GL_MODULATE, +GL_DECAL and GL_BLEND.
    +
    +RESOLUTION: open
    +
    +

    A.7 Truncated Mipmaps and LOD Control

    +Should we support the GL_TEXTURE_BASE_LEVEL, GL_TEXTURE_MAX_LEVEL, +GL_TEXTURE_MIN_LOD and GL_TEXTURE_MAX_LOD texture parameters?
    +
    +RECOMMENDATION:  We propose omitting these features at this time, +in the interest of simplifying the driver.
    +
    +RESOLUTION: open
    +
    +

    A.8 Texture Priorities and Residency

    +Should the subset support texture priorities via glPrioritizeTextures and the glAreTexturesResident command?
    +
    +RECOMMENDATION:  Few applications use these features and +functions.  We propose omitting them to simplify the driver.
    +
    +RESOLUTION: open
    +
    +

    A.9 Pixel Pack/Unpack Alignment Control

    +Should we support the GL_PACK_ALIGNMENT and GL_UNPACK_ALIGNMENT options?
    +
    +These are used to align pixel data addresses to 1, 2 and 4-byte +multiples for glBitmap, glTexImage2D +and glReadPixels.  These +aren't strictly needed since the user can provide a 1, 2 or 4-byte +aligned address and appropriate GL_PACK_ROW_LENGTH or +GL_UNPACK_ROW_LENGTH values instead.
    +
    +RECOMMENDATION:  We recommend omitting them to simplify the driver.
    +
    +RESOLUTION: open
    +
    +

    A.10 Pixel Pack/Unpack Skip Rows/Pixels Control

    +Should we support the GL_UNPACK_SKIP_PIXELS, GL_UNPACK_SKIP_ROWS, +GL_PACK_SKIP_PIXELS and GL_PACK_SKIP_ROWS options for pixel +unpacking/packing?
    +
    +These options aren't really needed since the user can adjust the start +address and GL_PACK/UNPACK_ROW_LENGTH parameters to achieve the same +effect.
    +
    +RECOMMENDATION:  omit these parameters.
    +
    +RESOLUTION: open
    +
    +

    A.11 Texture State Queries

    +Should we support the command glGetTexEnvi/fv, +glGetTexParameteri/fv and glGetTexLevelParameteri/fv?
    +
    +RECOMMENDATION:  No. They're seldom needed and their +implementation is several hundred lines of code in length.
    +
    +RESOLUTION:  open
    +
    +

    A.12 glGetIntegerv, glGetBooleanv and glGetDoublev

    +Should we support the commands glGetIntegerv, +glGetBooleanv and glGetDoublev +in addition to glGetFloatv?
    +
    +RECOMMENDATION:  Omit the boolean, integer and double-valued +functions. All state values which can be queried by these commands can +be expressed as floating point values and queried with glGetFloatv.  The +implementation of the other three commands involves many lines of code.
    +
    +RESOLUTION:  open
    +
    +

    A.13 glBitmap and Per-Fragment Operations

    +Should bitmaps rendered with glBitmap +be subjected to the per-fragment operations?
    +
    +If bitmaps are implemented with points it will be easy to implement the +per-fragment operations.  Otherwise, it could be difficult.
    +
    +RECOMMENDATION:  Implement glBitmap by drawing points/pixels with +the hardware.  This will make supporting the per-fragments +trivially easy.  Also, it makes portrait-mode display relatively +easy.
    +
    +RESOLUTION:  open
    +
    +

    A.14 Reduced gl.h Header File

    +Should we produce a reduced gl.h header file which only defines the +tokens and functions which are implemented by the subset?
    +
    +RECOMMENDATION: yes.  It would be a useful reference to +programmers to quickly determine which functions and tokens are +supported.
    +
    +RESOLUTION: open
    +
    +

    A.15 glPolygonMode

    +Is glPolygonMode needed?
    +
    +RECOMMENDATION: No.  Omit it.
    +
    +RESOLUTION: closed, as of 26 Feb 2003
    +
    +
    +

    + + diff --git a/docs/subset.html b/docs/subset.html new file mode 100644 index 0000000..4ac2ead --- /dev/null +++ b/docs/subset.html @@ -0,0 +1,24 @@ + + +Mesa Subset Driver + + + + + +

    Mesa Subset Driver

    + +

    +In 2002/2003 Tungsten Graphics was contracted to develop a subset Mesa/Radeon +driver for an embedded environment. The result is a reduced-size DRI driver +for the ATI R200 chip, for use with +fbdev/DRI environment. +

    + +

    +The specification for this subset can be found +here. +

    + + + diff --git a/docs/systems.html b/docs/systems.html new file mode 100644 index 0000000..5137b07 --- /dev/null +++ b/docs/systems.html @@ -0,0 +1,71 @@ + + +Supported Systems and Drivers + + + + + +

    Supported Systems and Drivers

    + +

    +Mesa was originally designed for Unix/X11 systems and is still best +supported on those systems. All you need is an ANSI C compiler and the +X development environment to use Mesa. +

    + +

    +The DRI hardware drivers for the X.org server and XFree86 provide +hardware accelerated rendering for chips from ATI, Intel, Matrox, 3dfx +and others on Linux and FreeBSD. +

    + +

    +Drivers for other assorted platforms include: +the Amiga, Apple Macintosh, BeOS, NeXT, OS/2, MS-DOS, VMS, Windows +9x/NT, and Direct3D. +

    + +

    +Details about particular drivers follows: +

    + + + + +

    Deprecated Systems

    + +

    +These drivers have not been maintained and are being deprecated. +They can be saved if someone steps up to help. +

    + + + +And for historical reference: + + + + diff --git a/docs/thanks.html b/docs/thanks.html new file mode 100644 index 0000000..2031788 --- /dev/null +++ b/docs/thanks.html @@ -0,0 +1,134 @@ + + + +Acknowledgements + + + + + + +

    Acknowledgments

    + + +The following individuals and groups are to be acknowledged for their +contributions to Mesa over the years. +This list is far from complete and somewhat dated, unfortunately. + + +
      +
    • Early Mesa development was done while Brian was part of the +SSEC Visualization Project at the University of +Wisconsin. He'd like to thank Bill Hibbard for letting him work on +Mesa as part of that project. +
      +
      +
    • John Carmack of id Software, Inc. funded Keith Whitwell in 1999 in +order to optimize Mesa's vertex transformation module. This is a very +substantial piece of work. +
      +
      +
    • Precision Insight, Inc., VA Linux Systems, Inc., and most recently, +Tungsten Graphics, Inc. have supported the ongoing development of Mesa. +
      +
      +
    • The +Mesa +website is hosted by + +Sourceforge.net +
      +
      + +
    • The Mesa git repository is hosted by +freedesktop.org. +
      +
      + + +
    • alt.software contributed the Direct3D driver. + +
    • Bernd Barsuhn wrote the evaluator code for (splines, +patches) in Mesa. + +
    • Bernhard Tschirren wrote the Allegro DJGPP driver. + +
    • Bogdan Sikorski wrote the GLU NURBS and polygon tessellator +in Mesa. + +
    • Charlie Wallace wrote the MS-DOS driver. + +
    • CJ Beyer was the www.mesa3d.org webmaster. + +
    • Darren Abbott provided the OS/2 driver. + +
    • David Bucciarelli wrote and maintained the 3Dfx Glide +driver. Thousands of Linux/Quake players thank David! + +
    • Gareth Hughes wrote new GLU 1.2 Polygon Tessellation code +(now superceded by SGI SI GLU). + +
    • Holger Waechtler contributed AMD 3DNow! assembly code which +accelerates vertex transformation in Mesa 3.1. Holger also implemented +the GL_EXT_texture_env_combine extension. + +
    • Jeroen van der Zijp and Thorsten Ohl contributed the +Xt/Motif widget code. + +
    • John Stone provided the multi-threading support in Mesa 3.0. + +
    • John Watson assisted with web page design. + +
    • Josh Vanderhoof contributed Intel x86 assembly code which +accelerates vertex transformation in Mesa 3.x. + +
    • Jouk Jansen contributed and continues to maintain the VMS +support. + +
    • Karl Schultz has been maintaining the Windows driver. + +
    • Keith Whitwell has made extension contributions to Mesa +since 1999. + +
    • Kendall Bennett wrote the SciTech MGL driver. + +
    • Klaus Niederkrueger contributed many improvements to Mesa's +software rasterizer. + +
    • Mark Kilgard contributed antialiased line improvements and +several extensions. + +
    • Michael Pichler contributed many bug fixes + +
    • Miklos Fazekas wrote and maintains the Macintosh driver. + +
    • Pascal Thibaudeau wrote the NeXT driver. + +
    • Pedro Vazquez setup and maintains the Mesa Mailing list. + +
    • Randy Frank contributed many bug fixes. + +
    • Stefan Zivkovic wrote the Amiga driver. + +
    • Stephane Rehel provided the Cygnus Win32 support + +
    • Ted Jump maintained the +makefiles and project files for Windows 95/98/NT compilation for some time. + +
    • Uwe Maurer wrote the LibGGI driver for Mesa-3.0. + +
    • Victor Ng-Thow-Hing wrote the Amiwin driver for the Amiga. + +
    + +

    +Apologies to anyone who's been omitted. +Please send corrections and additions to Brian. +

    + + + + diff --git a/docs/utilities.html b/docs/utilities.html new file mode 100644 index 0000000..4693639 --- /dev/null +++ b/docs/utilities.html @@ -0,0 +1,26 @@ + + +Development Utilities + + + + + +

    Development Utilities

    + +
      + +
    • The Mesa distribution includes several utility routines in the +progs/util/ directory + +
    • Allen Akin's glean is a framework for OpenGL testing. + +
    • Valgrind is a very useful tool for tracking down +memory-related problems in your code. + +
    + + + \ No newline at end of file diff --git a/docs/utility.html b/docs/utility.html new file mode 100644 index 0000000..c7cad01 --- /dev/null +++ b/docs/utility.html @@ -0,0 +1,44 @@ + + +Utilities + + + + + +

    Utilities

    + + + + + + diff --git a/docs/versions.html b/docs/versions.html new file mode 100644 index 0000000..84b40fd --- /dev/null +++ b/docs/versions.html @@ -0,0 +1,1656 @@ + + +Mesa Version History + + + + + + + + +NOTE: Changes for Mesa 6.4 and later are documented in the corresponding +release notes file. + + + +

    Mesa Version History

    + + +

    1.0 beta February 1995

    +
      +
    • Initial release +
    + +

    1.1 beta March 4, 1995

    +Changes: +
      +
    • faster point and line drawing (2x faster) +
    • more systems supported, better Makefiles +
    • Renamed lib*.a files to avoid collisions +
    • many small bug fixes +
    +New: +
      +
    • pseudo-GLX functions added +
    • new implementation of evaluators (eval2.c) +
    • GLUT support +
    + +

    1.1.1 beta March 7, 1995

    +Changes: +
      +
    • Reverted from eval2.c to eval.c due to FPE on Linux +
    • more speed improvements +
    • more Makefile changes +
    + +

    1.1.2 beta March 14, 1995

    +New: +
      +
    • implementation of SGI's blending extensions +
    • glXUseXFont implemented +
    • added MESA_DEBUG environment variable support +
    +Changes: +
      +
    • Using eval2.c again +
    • more FPE-prevention checks (0-length normals are OK) +
    • a few small bug fixes +
    • much faster pixel logic ops! +
    • faster transformation arithmetic +
    + +

    1.1.3 beta March 31, 1995

    +New: +
      +
    • gluScaleImage() and gluBuild2DMipMaps() implemented +
    • Mesa widgets for Xt/Motif +
    • blendEXT demos +
    • added environment variables for selecting visuals +
    +Changes: +
      +
    • almost all GLUT demos work correctly now +
    • faster X device driver functions +
    • more bug fixes +
    + +

    1.1.4 beta April 20, 1995

    +Bug fixes: +
      +
    • missing #define SEEK_SET in src-tk/image.c +
    • compile glShadeModel into display lists +
    • fixed pow() domain error in src/light.c +
    • fixed "flickering bitmaps" in double buffer mode +
    • fixed tk.h and aux.h for C++ +
    • state of LIGHT_MODEL_LOCAL_VIEWER was inverted +
    +New features: +
      +
    • MUCH, MUCH nicer dithering in 8-bit RGB mode +
    • updated widgets and widget demos +
    • Implemented GLXPixmap functions +
    • Added GLU 1.1 and GLX 1.1 functions +
    • Changed the X/Mesa interface API, more versatile +
    • Implemented gluPartialDisk() +
    + +

    1.2 May 22, 1995

    +Bug fixes: +
      +
    • IRIX 4.x makefile problem +
    • modified tk to share root colormap as needed +
    • gluLookAt normalization problem +
    • suppress Expose, NoExpose events in swapbuffers +
    • glBitmap() and glDrawPixels() clipping +
    +New features: +
      +
    • GL_BLEND, GL_MODULATE, GL_DECAL, and GL_REPLACE_EXT texture + modes implemented +
    • texture maps stored more efficiently +
    • texture maps can be compiled into display lists +
    • Bogdan Sikorski's GLU polygon tesselation code +
    • Linas Vepstas's sweep and extrusion library +
    • glXCreateContext()'s shareList parameter works as it's supposed to. + XMesaCreateContext() updated to accept a shareList parameter too. +
    • Mesa can be compiled with real OpenGL .h files +
    • MESA_BACK_BUFFER environment variable +
    • better GLX error checking +
    + +

    1.2.1 June 22, 1995

    +Bug fixes: +
      +
    • X/Mesa double buffer window resize crash +
    • widgets now pass PointerMotion events +
    • X/Mesa incorrect default clear color and drawing color +
    • more robust X MIT-SHM support in X/Mesa +
    • glTexImage( format=GL_LUMINANCE ) didn't work +
    • GL_LINE mode polygons with line width > 1.0 could cause a crash +
    • numerous feedback bugs +
    • glReadPixels() from depth buffer was wrong +
    • error prone depth and stencil buffer allocation +New features: +
    • Preliminary Microsoft Windows driver +
    • Implemented a number of missing functions: glEvalCoord[12][df]v(), + glGet...(), etc. +
    • Added a few missing symbols to gl.h and glu.h +
    • Faster rendering of smooth-shaded, RGBA, depth-buffered polygons. +
    • Faster rendering of lines when width=2.0 +
    • Stencil-related functions now work in display lists +
    +Changes: +
      +
    • renamed aux.h as glaux.h (MS-DOS names can't start with aux) +
    • most filenames are in 8.3 format to accomodate MS-DOS +
    • use GLubytes to store arrays of colors instead of GLints +
    + +

    1.2.2 August 2, 1995

    +New features: +
      +
    • texture mapped points and lines +
    • NURBS! (but not 100% complete) +
    • viewports may safely extend beyond window boundaries +
    • MESA_PRIVATE_CMAP environment variable +
    • Grayscale X display support +
    • two new demos: demos/gears.c and demos/shadow.c +
    • MachTen for Macintosh configuration +
    +Bug fixes: +
      +
    • glGet*(GL_DEPTH_BITS) returned bytes, not bits +
    • point, line, and bitmap rasterization suffered from roundoff errors +
    • fixed a division by zero error in line clippping +
    • occasional wrong default background color really fixed! +
    • glDepthFunc(GL_ALWAYS) with glDepthMask(GL_FALSE) didn't work +
    • gluBuild2DMipmaps malloc problem fixed +
    • view volume clipping of smooth shaded lines resulted in bad colors +
    +Changes: +
      +
    • new visual selection method in glXChooseVisual() +
    • improved GLU quadric functions +
    • call XSync for glFinish and XFlush for glFlush +
    • glVertex() calls now use a function pointer to avoid conditionals +
    • removed contrib directory from Mesa tar file (available on ftp site) +
    • AIX shared library support +
    • Removed GLUenum type as it's not in OpenGL +
    + +

    1.2.3 September 26, 1995

    +New features: +
      +
    • Mesa header files now equivalent to SGI OpenGL headers +
    • Support for HP's Color Recovery dithering displays +
    • Faster vertex transformation +
    • Faster raster operations into X windows under certain conditions +
    • New configurations: HP w/ shared libs, Ultrix w/ GCC, Data General +
    • 4-bit visuals now supported +
    +Bug fixes: +
      +
    • glScissor bug fixed +
    • round-off errors in clipping lines against clip planes fixed +
    • byte swapping between hosts and display servers implemented +
    • glGetError() can be called without a current rendering context +
    • problem with accidentally culled polygons is fixed +
    • fixed some widget compilation problems +
    + +

    1.2.4 November 17, 1995

    +New features: +
      +
    • More speed improvements (lighting, fogging, polygon drawing) +
    • Window system and OS-independent off-screen rendering +
    • Preliminary Fortran bindings +
    • glPolygonOffsetEXT implemented +
    • glColorMask and glIndexMask now fully implemented +
    • glPixelZoom implemented +
    • display lists fully implemented +
    • gamma correction +
    • dithering in 8-bit TrueColor/DirectColor visuals +
    +Changes: +
      +
    • Improved device driver interface +
    • tk.h renamed to gltk.h to avoid conflicts with Tcl's Tk +
    • Dithering support moved from core into device driver +
    +Bug fixes: +
      +
    • glEnable/Disable( GL_LIGHTING ) didn't always take effect +
    • glReadPixels byte swapping was broken +
    • glMaterial with pname==GL_AMBIENT_AND_DIFFUSE was broken +
    • duplicate glColor4b() prototype in GL/gl.h removed +
    • stripes in wave -ci demo fixed +
    • GL_LINEAR_MIPMAP_NEAREST had wrong value +
    • bugs in HP Color Recovery support fixed +
    • fixed bug when blending lines, points, bitmaps outside of window +
    + +

    1.2.5 November 30, 1995

    +New Features: +
      +
    • updated MS Windows driver +
    • new implementation of StaticGray/GrayScale visual support +
    +Bug fixes: +
      +
    • pixelzooming with gamma correction or blending didn't work +
    • HP color recovery visual wasn't being picked by glXChooseVisual +
    • glClear didn't always observe glColorMask changes +
    • olympic and offset demos didn't compile on some Suns +
    • texcoord clamping wasn't correct +
    • a polygon optimization introduced an occasional sampling problem +
    + +

    1.2.6 January 26, 1996

    +New Features: +
      +
    • faster line and polygon rendering under certain conditions. See + Performance Tips 9 and 10 in README +
    • profiling +
    • lighting is a bit faster +
    • better perspective corrected texture mapping +
    • Amiga AmiWin (X11) support +
    • preliminary Linux SVGA driver +Changes: +
    • now using a 16-bit depth buffer, faster, smaller +
    • GL_NORMALIZE is disabled by default +
    +Bug fixes: +
      +
    • projective texture mapping +
    • fixed a memory leak in the context destroy function +
    • GL_POLYGON with less than 3 vertices caused a crash +
    • glGet*() returned wrong result for GL_INDEX_MODE +
    • reading pixels from an unmapped X window caused a BadMatch error +
    + +

    1.2.7 March 5, 1996

    +New: +
      +
    • faster lighting +
    • faster 16-bit TrueColor rendering on Linux +
    • faster 32-bit TrueColor rendering on Linux, HP, IBM +
    • non-depth-buffered XImage polygons are faster +
    • vertex array extension +
    • software alpha planes +
    • updated Macintosh driver +
    • new NeXT driver +
    • GLU quadric functions generate texture coordinates +
    • reflect.c demo - reflective, textured surface demo +
    +Changes: +
      +
    • gamma correction code moved into the X driver for better performance +
    +Bug fixes: +
      +
    • multiple glClipPlane()'s didn't work reliably +
    • glPolygonMode() didn't always work +
    • glCullFace( GL_FRONT_AND_BACK ) didn't work +
    • texture mapping with gamma correction was buggy +
    • floating point exceptions in texture coordinate interpolation +
    • XImage byte swapping didn't always work +
    • polygon edge flags weren't always used correctly +
    + +

    1.2.8 May 22, 1996

    +New: +
      +
    • overlay planes on X servers with the SERVER_OVERLAY_VISUALS property +
    • better monochrome output +
    • more IRIX 6.x configurations +
    • more robust RGB mode color allocation +
    • added MESA_XSYNC environment variable +
    • GLX_MESA_pixmap_colormap and GLX_EXT_visual_info extensions +
    • GL_MESA_window_pos extension +
    • faster glReadPixels/glDrawPixels for GL_DEPTH and GL_UNSIGNED_SHORT + and GL_UNSIGNED_INT +
    • driver for prototype Cirrus Mondello 3-D board +
    • updated AmigaDOS driver +
    • a few small speed optimizations in polygon rendering +
    +Changes: +
      +
    • internal device driver interface modified to simplify device + driver implementations and to support hardware Z buffers +
    • several changes to the X/Mesa interface (xmesa.h) +
    +Bug fixes: +
      +
    • fixed pow(0,0) domain error triggered on some systems +
    • glStencilClear() in a display list caused an infinite loop +
    • glRasterPos*() was sometimes off by +/-0.5 in X and Y +
    • color masking and blending were performed in wrong order +
    • auxSolidCylinder() sometimes drew a wire-frame cylinder +
    • fixed file writing bug in osdemo.c +
    • pixel mapping didn't always work +
    • the GL_GEQUAL stencil func didn't work +
    • the GL_INVERT stencil op didn't work +
    • the stencil write mask didn't work +
    • glPush/PopAttrib() didn't do enough error checking +
    • glIsList() didn't always work correctly +
    + +

    2.0 October 10, 1996

    +New: +
      +
    • Implements OpenGL 1.1 API functions +
    • all texture filtering modes supported (mipmapping) +
    • faster texture mapping, see Performance Tip 11 in README +
    • antialiased RGB points +
    • X support for line and polygon stippling +
    • glDrawBuffer( GL_FRONT_AND_BACK ) works +
    • util/ directory of useful stuff +
    • demos/texobj demo of texture objects +
    +Changes: +
      +
    • major internal changes for thread-safeness +
    • new device driver interface +
    • MESA_ALPHA env variable removed +
    • triangle rasterizer replaces polygon rasterizer +
    +Bug fixes: +
      +
    • glPopAttrib() bug +
    • glDrawBuffer(GL_NONE) works now +
    + +

    2.1 December 14, 1996

    +New: +
      +
    • VMS support +
    • MS-DOS driver +
    • OpenStep support +
    • updated, combined Windows 95/NT driver +
    • implemented glGetLighti() and glGetTexGen*() +
    • GLX does garbage collection of ancillary buffers +
    +Bug fixes: +
      +
    • removed unused _EXT constants from gl.h +
    • fixed polygon offset bugs +
    • Z coordinates of clipped lines were incorrect +
    • glEdgeFlag() in display lists didn't always work +
    • glLight*() in display lists didn't work +
    • fixed X line stipple bugs (Michael Pichler) +
    • glXUseXfonts XFreeFont/XFreeFontInfo bug fixed +
    • fixed a feedback bug +
    • glTexGen*() now transforms GL_EYE_PLANE by inverse modelview matrix +
    • polygons were sometimes culled instead of clipped +
    • triangle rasterizer suffered from float/int overflow exceptions +
    • fixed FP underflow exception in lighting (specular exponent) +
    • glEnable/glDisable of GL_EXT_vertex_array enums didn't work +
    • fixed free(NULL) in GLU tesselator code +
    • using 24-bit color on some X servers resulted in garbage rendering +
    • 32-bit per pixel mode for XFree86 now works +
    • glRotate(a,0,0,0) gave unpredictable results +
    • GL_LINE_STRIP with > 480 vertices had occasional clipping problems +
    • 8-bit TrueColor GLXPixmap rendering incorrectly required a colormap +
    • glMaterial() wasn't ignored when GL_COLOR_MATERIAL was enabled +
    • glEnable(GL_COLOR_MATERIAL) followed by glColor() didn't work right +
    • accumulation buffer was limited to positive values +
    • projective textures didn't work +
    • selection buffer overflows weren't handled correctly +
    +Changes: +
      +
    • restored the GL_EXT_polygon_offset extension +
    • slightly faster RGB dithering +
    • the SVGA driver works again +
    • Amiga driver now distributed separately +
    • NeXT driver updated for Mesa 2.x +
    + +

    2.2 March 14, 1997

    +New: +
      +
    • better color selection when dithering +
    • added GL_EXT_texture_object extension +
    • updated MS-DOS driver for DJGPP +
    • added openbsd make configuration +
    • faster dithered flat-shaded triangles +
    • various compilation problems with Motif widgets fixed +
    • gl.h, glx.h and glu.h name mangling option +
    • BeOS driver +
    • 3D texture mapping extension +
    • GL_MESA_resize_buffers extension +
    • morph3d, stex3d and spectex demos +
    • 3Dfx support +
    +Bug fixes: +
      +
    • glColorMaterial should finally work right in all respects +
    • linear interpolation of mipmap levels was incorrectly weighted +
    • readpix.c didn't compile on Macintosh +
    • GL_INVERT and related logic ops didn't work right +
    • glTexImage[12]D() didn't check its parameters consistantly +
    • fixed a memory leak in glTexImage[12]D() +
    • kludged around a SunOS 5.x/GCC compiler bug in the feedback code +
    • glReadPixels aborted instead of normally catching some errors +
    • a few 1.1 constants were missing or misnamed in gl.h +
    • glBegin(p); glBegin(q); didn't generate an error +
    • fixed a memory leak in GLX code +
    • clipping of concave polygons could cause a core dump +
    • 1-component alpha texture maps didn't work +
    • fixed a GLU polygon tesselator bug +
    • polygons with colinear vertices were sometimes culled +
    • feedback triangle colors were wrong when using smooth shading +
    • textures with borders didn't work correctly +
    • colors returned in feedback mode were wrong when using lighting +
    • spotlights didn't effect ambient lighting correctly +
    • gluPartialDisk() had a few bugs +
    +Changes: +
      +
    • device driver interface expanded to support texture mapping +
    • faster matrix inversion subroutine +
    • commented out #include "wmesa_extend.h" from src/wmesa.c +
    • fixed many compiler warnings in the demo programs +
    + +

    2.3 June 30, 1997

    +New: +
      +
    • Mesa distribution divided into two pieces: library code and demos +
    • faster vertex transformation, clip testing, lighting +
    • faster line drawing +
    • TrueColor visuals how have dithering (for depths < 24 bits) +
    • added MESA_NO_DITHER environment variable +
    • new device driver function: NearFar(), RenderVB(), RasterSetup() +
    • added LynxOS configuration +
    • added cygnus Win32 configuration +
    • added texcyl.c GLUT demo +
    • added XMesaDitherColor() to X/Mesa interface +
    • new NURBS code from Bogdan Sikorski +
    • added demos/shape.c (non-rectangular X window!) +
    +Bug fixes: +
      +
    • glEnable/DisableClientState() were missing from GL/gl.h +
    • GL_SPHERE_MAP texcoord generation didn't work correctly +
    • glXGetConfig() returned wrong number of depth, stencil, accum bits +
    • glDrawPixels feedback/selection didn't examine RasterPos valid bit +
    • black and white were reversed on some monochrome displays +
    • fixed potential image memory leak (wasn't setting reference counter) +
    • glDrawPixels sometimes didn't recognize some GL state changes +
    • gluProject/UnProject() didn't check for divide by zero +
    • stex3d demo called random() and srandom(), not portable +
    • fixed memory leaks in context.c and drawpix.c +
    • fixed NULL dereferencing problem in gl_update_texture_state() +
    • glReadPixels between glBegin/glEnd didn't generate an error. +
    • fixed memory leak in polygon tesselator (Randy Frank) +
    • fixed seg fault bug drawing flat-shaded, depth-tested lines +
    • clipped GL_TRIANGLE_STRIPs sometimes had wrong color when flat-shaded +
    • glBindTexture sometimes didn't work +
    • fixed a bug deep in glXReleaseBuffersMESA() +
    • fog was mistakenly applied to alpha +
    • glPopMatrix didn't set "dirty matrix" flag +
    • glPolygonStipple pattern was sometimes wrong +
    • glClear wasn't disabled during feedback and selection +
    • fixed memory leak in glTexSubImage[123]D +
    +Changes: +
      +
    • many library source files reorganized +
    • faster X color allocation, colors also freed when finished with them +
    • new texture sampling function pointer in texture objects +
    • incorporated 3Dfx VooDoo driver v0.16 into main source tree +
    • many 3Dfx driver updates +
    • cygnus Makefiles now included +
    • updated DOS driver +
    • made a few changes to dosmesa.c and wmesa.c (VB->Unclipped) +
    • internally, colors now stored in GLubytes, not GLfixed +
    • optimized changing of GL_SHININESS parameter +
    + +

    2.4 September 18, 1997

    +New: +
      +
    • updated 3Dfx Glide driver +
    • hacks for 3Dfx rendering into an X window or fullscreen +
    • added depth buffer access functions to X/Mesa and OS/Mesa interfaces +
    +Bug fixes: +
      +
    • pixel buffer could overflow with long, wide lines +
    • fixed FP underflow problems in lighting +
    • glTexSubImage1D() had an unitialized variable +
    • incomplete texture objects could cause a segfault +
    • glDrawPixels with GL_COMPILE_AND_EXECUTE caused infinite loop +
    • flat-shaded quads in a strip were miscolored if clipped +
    • mipmapped triangle lod computation now works correctly +
    • fixed a few under/overflow bugs in triangle rasterizer +
    • glArrayElement() assigned bad normal if normal array disabled +
    • changed argument to glXReleaseBuffersMESA() +
    • fixed small triangle underflow bugs in tritemp.h (hopefully) +
    • glBindTexture(target, 0) caused a crash +
    • glTexImage[123]D() with NULL image pointer caused crash +
    • glPixelStore parameters are now ignored during display list execution +
    • fixed a two-sided lighting w/ clipping bug (black vertices) +
    • textures with width!=height were sometimes mis-rendered +
    • "weird" projection matrices could cause div by 0, other fp errors +
    +Changes: +
      +
    • changed precompiled header symbol from PCH to PC_HEADER +
    • split api.c into api1.c and api2.c +
    • added hash.c source file (but not used yet) +
    • a few Sun and HP configuration file changes +
    • MESA_GLX_FX env var replaces MESA_FX_WINDOW and MESA_FX_FULLSCREEN +
    • fixed a few cygnus build problems (src/Makefile.cygnus, src/wmesa.c) +
    + +

    2.5 November 20, 1997

    +New: +
      +
    • updated 3Dfx driver (v20) for GLQuake +
    • added GL_EXT_paletted_texture extension +
    • added GL_EXT_shared_texture_palette extension +
    • added GL_EXT_point_parameters extension +
    • now including Mark Kilgard's GLUT library v3.6 +
    • new GLUT-based demos in gdemos/ +
    • added a few more Unix config targets +
    • added Intel X86 assembly language vertex transformation code +
    • 3Dfx/Glide driver for Mesa now recognizes SST_SCREENREFRESH env var +
    • Windows 95 S3 Virge driver +
    +Bug fixes: +
      +
    • glCopyTexImage?D would crash due to uninitialized variable +
    • glColor w/ glColorMaterial in a display list caused a bug +
    • fixed several glDrawPixels() and ReadPixels() bugs in 3Dfx driver +
    • glVertex4*() vertices weren't always projected correctly +
    • trying to use mipmapped textured points or lines caused crash +
    • glColor[34][fd]() values now clamped to [0,1] before int conversion +
    +Changes: +
      +
    • new device driver functions for texture mapping +
    • hash tables used for display list and texture object lookup +
    • fixed GLX visual handling code to avoid saving redundant visuals +
    • 3Dfx Glide libraries automatically linked to libMesaGL.so +
    • dropped the Cirrus Logic Mondello code since it's obsolete +
    • updated Cygnus Makefiles (Stephane Rehel) +
    • updated Windows MSVC++ Makefiles (Oleg Letsinsky) +
    • procedure for making library files has changed: scripts now take + a major and minor version arguments. Make-config changed a lot. +
    • new implementation of glTexSubImage2D() +
    • updated widgets-mesa directory to create libMesaGLwM.a (Motif widget) +
    • separate linux-glide and linux-386-glide configurations +
    + +

    2.6 February 12, 1998

    +New: +
      +
    • Windows WGL functions +
    • updated VMS, DOS, Windows, Cygnus, BeOS, Amiga compilation support +
    • v0.22 of 3Dfx Glide driver +
    • more X86 assembly language optimizations +
    • faster blending for some modes +
    • XMesaSetFXmode() to switch between 3Dfx window and full-screen mode +
    • added preliminary thread support +
    • added GLX_MESA_copy_sub_buffer extension +
    • some clipping optimizations +
    +Bug fixes: +
      +
    • fixed shading/material bug when drawing long primitive strips +
    • fixed clipping problem in long primitive strips +
    • fixed clipping bug when using 3Dfx driver +
    • fixed a problem when trying to use X fonts w/ 3Dfx driver +
    • fixed a texture filter bug in 3Dfx/Glide driver +
    • fixed bug in 3Dfx/Glide driver involving depth mask & clearing +
    • glLoadMatrix to set projection matrix confused the 3Dfx driver +
    • non-identity texture matrices didn't work with linux-386 configs +
    • glGenTextures() didn't reserve the returned texture IDs +
    • NULL proxy image sent to glTexImageXD() caused crash +
    • added texture state validation optimization (Henk Kok) +
    • fixed colormap reuse problem when using both RGB and CI windows +
    • 32bpp True/DirectColor X visuals weren't recognized +
    • fixed potential problem in evaluators memory allocation +
    • fixed assorted demo compilation bugs +
    +Changes: +
      +
    • replaced old Mesa/windows/ directory with Mesa/WIN32/ directory +
    • converted a few old glaux/gltk demos to GLUT +
    • renamed directories: demos -> xdemos, gdemos -> demos +
    + + +

    3.0 September 17, 1998

    +New: +
      +
    • OpenGL 1.2 API +
    • GL_EXT_abgr pixel format extension +
    • GL_SGIS_texture_edge_clamp extension +
    • GL_SGIS_multitexture extension (to be replaced by GL_ARB_multitex) +
    • GL_EXT_multitexture extension (to be replaced by GL_ARB_multitex) +
    • GL_EXT_rescale_normal extension and renormal.c demo +
    • GLX_SGI_video_sync extension (a no-op) +
    • antialiased lines +
    • glGetTexImage() now implemented +
    • glDraw/Copy/ReadPixels() optimizations +
    • optimized textured triangle code (Marten Stromberg) +
    • more optimization of dithered TrueColor triangles in X driver +
    • Linux GGI driver +
    • updated MGL driver +
    +Bug fixes: +
      +
    • lots of assorted compilation fixes +
    • glInitNames didn't write initial hit record +
    • glBitmap didn't always check for invalid raster position +
    • switching between GLX and OSMesa contexts caused a crash +
    • fixed uninitialized variable in Mesa widget code +
    • fixed typo in texture code which caused book/texgen to crash +
    • fixed texture sampling bug when filter=GL_LINEAR and wrap=GL_CLAMP +
    • gluDisk() in POINT or LINE mode sometimes failed +
    • fixed texture + fog bug +
    • GL_COMPILE_AND_EXECUTE mode didn't work reliably +
    • glMultMatrix in projection matrix mode w/ 3Dfx driver could fail +
    • glDrawPixels(color index pixels) weren't converted to RGBA +
    • fixed possible getenv() buffer overflow security bug +
    • glBitmap in feedback mode was offset by xOrig, yOrig params +
    • device driver's DrawPixels hook was never used +
    • glDrawPixels with zoomY!=1 and top/bottom clipping didn't work +
    • glDrawPixels optimized for GL_LUMINANCE, GL_LUMINANCE_ALPHA, GLubyte +
    • fixed MakeCurrent bug in GLwRedrawObjects() in MesaWorkstation.c +
    • glCopyTexSubImage2D() didn't work with 3Dfx driver +
    • lines with width = 2 could cause crash +
    • glClear with scissor rect sometimes cleared whole buffer +
    • glTexSubImage2D( .. GL_COLOR_INDEX .. ) didn't work +
    • glTexImageXD( .. GL_ABGR_EXT .. ) didn't work +
    • computation of inverse modelview matrix sometimes failed +
    • fixed GL_CLAMP mode texture sampling bug +
    • textured line interpolation was somewhat broken +
    • textured triangle interpolation was also somewhat broken +
    • glGet(MODELVIEW/PROJECTION/TEXTURE_MATRIX_STACK_DEPTH) off by one +
    • evaluator state wasn't fully initialized +
    • texture coordinate clipping was buggy +
    • evaluator surfaces could be mis-colored +
    • glAccum(GL_RETURN, s) didn't obey glColorMask() settings +
    • zero area polygons shouldn't be culled if polygon mode is point/line +
    • clipped width and height of glReadPixels was sometimes off by one +
    • blending with alpha = 0 or 1.0 wasn't always exact +
    • reading of pixels from clipped region was buggy +
    • minor tweaking of X visual management in GLX emulator +
    • glPolygonStipple now obeys pixel unpacking parameters +
    • glGetPolygonStipple now obeys pixel packing parameters +
    • interleaved vertex array texture coordinates were broken +
    • query of proxy texture internal format was broken +
    • alpha channel wasn't reliably cleared +
    • fixed divide by zero error in gluScaleImage if dest size = 1 x 1 +
    +Conformance bug fixes: +
      +
    • GL_SELECTION_BUFFER_POINTER and GL_SELECTION_BUFFER_SIZE were missing +
    • GL_TEXTURE_INTERNAL_FORMAT was missing +
    • glGet*(GL_POLYGON_STIPPLE) was broken +
    • glPush/PopAttrib() didn't save/restore all texture state +
    • glBitmap in feedback mode didn't work +
    • feedback of texture coords didn't always work +
    • glDrawPixels w/ format=GL_DEPTH_COMPONENT, type=GLbyte was broke +
    • glDrawPixels w/ format=GL_DEPTH_COMPONENT, type=GLubyte was broke +
    • glDrawPixels w/ format=GL_STENCIL_INDEX, type=GL_BITMAP was broke +
    +Changes: +
      +
    • upgraded GLUT to version 3.7 +
    • only GL and GLU library code included in MesaLib.tar.gz +
    • GLUT and all demos now in MesaDemos.tar.gz +
    • glaux and gltk libraries removed +
    • IRIX -n32 and -64 libs go in lib32/ and lib64/ directories +
    + + +

    3.1 beta 1 November 19, 1998

    +New: +
      +
    • GL_EXT_stencil_wrap extension +
    • GL_INGR_blend_func_separate extension +
    • GL_ARB_multitexture extension +
    • GL_NV_texgen_reflection extension +
    • newly optimized vertex transformation code +
    • updated GLUT 3.7 code +
    • better precision when using 32-bit Z buffer +
    • Allegro DJGPP driver +
    +Bug fixes: +
      +
    • glCopyPixels between front/back buffers didn't copy alpha correctly +
    • fixed out-of-bounds memory access in optimized 2-D texture code +
    • glPixelStorei didn't accept GL_PACK/UNPACK_IMAGE_HEIGHT parameter +
    • glGet*() didn't accept GL_MAX_3D_TEXTURE_SIZE parameter +
    • clipping of texture coordinates sometimes had bad R,Q values +
    • GL_CLAMP_TO_EDGE texture sampling was off by 0.5 texels +
    • glEdgeFlagPointer() now takes a GLvoid * instead of GLboolean * +
    • texture was sometimes applied twice with 3Dfx driver +
    • glPush/PopAttrib() fouled up texture object reference counts +
    • glDeleteLists(0, n) caused assertion failure +
    • bilinear texture sampling wasn't accurate enough +
    • glClear w/ glDepthMask(GL_FALSE) didn't work right on 3Dfx +
    • color components were reversed on big endian 32 bpp X visuals +
    +Changes: +
      +
    • removed GL_EXT_multitexture extension +
    + + +

    3.1 beta 2 May 24, 1999

    +New: +
      +
    • multi-textured points and lines (mjk@nvidia.com) +
    • optimized 24bpp X rendering (bernd.paysan@gmx.de) +
    • added allegro support (bernie-t@geocities.com) +
    • cleaned-up Windows-related stuff (Ted Jump) +
    • minor stereo changes (KendallB@scitechsoft.com) +
    • new BeOS driver which implements BGLView class +
    • new Direct3D driver (see src/D3D) +
    • more efficient filled gluCylinder() function +
    • utilities: util/showbuffer.[ch] and util/glstate.[ch] +
    • fixed some IRIX compiler warnings +
    • added support for building Mesa in XFree86 with + SGI's GLX (kevin@precisioninsight.com) +
    +Bug fixes: +
      +
    • a variety of Windows/Mesa bug fixes (mjk@nvidia.com) +
    • packed pixel images weren't unpacked correctly +
    • patches some win32 files in GLUT (mjk@nvidia.com) +
    • glTexImage[123]D() didn't accept internalFormat == GL_COLOR_INDEX +
    • fixed lighting bug in Keith's new shading code +
    • fixed texture segfault seen in Lament screensaver +
    • fixed miscellaneous low-memory bugs +
    • glClear(GL_COLOR_BUFFER_BIT) with RGBA or CI masking was broken +
    • GL_LINEAR sampling of 3D textures was broken +
    • fixed SVR4 'cc' compiler macro problem (dawes@xfree86.org) +
    • added GL_TEXTURE_PRIORITY fix (keithh@netcomuk.co.uk) +
    • fixed wide point and wide line conformance bugs (brianp) +
    +Changes: +
      +
    • some device driver changes (see src/dd.h) +
    • new copyright on core Mesa code +
    + + +

    3.1 beta 3 September 17, 1999

    +New: +
      +
    • optimized glAccum function +
    • optimized 24bpp rendering in XMesa driver +
    • GLU 1.2 polygon tessellator +
    +Bug Fixes: +
      +
    • glGetTexLevelParameter wasn't fully implemented +
    • glXUseXFont now handles multi-byte fonts +
    • glIsEnabled(GL_TEXTURE_2D / 3D) returned wrong result +
    • alpha channel of blending points, lines was sometimes incorrect +
    +Changes: +
      +
    • New library names: "libGL" instead of "libMesaGL" +
    • New library numbering: libGL.so.1.2.310 +
    • New subdirectories: docs/ and bin/ +
    • New Makefile-system (autoconf,automake,libtool) +
    + + +

    3.1 final December 14, 1999

    +New: +
      +
    • added demos/gloss.c +
    • added xdemos/glxdpyinfo.c +
    • added GLX_ARB_get_proc_address extension +
    • rewritten glTexImage code paths (faster, less memory, bug fixes) +
    +Bug Fixes: +
      +
    • several vertex array bug fixes +
    • overlapping glCopyPixels with pixel zooming now works +
    • glXUseXFont() bitmaps were vertically shifted by one pixel +
    • glCopyPixels with pixel zooming now works +
    + + +

    3.2 final April 24, 2000

    +Bug fixes: +
      +
    • fixed memcpy bugs in span.c +
    • fixed missing glEnd problem in demos/tessdemo.c +
    • fixed bug when clearing 24bpp Ximages +
    • fixed clipping problem found in Unreal Tournament +
    • fixed Loki's "ice bug" and "crazy triangles" seen in Heretic2 +
    • fixed Loki's 3dfx RGB vs BGR bug +
    • fixed Loki's 3dfx smooth/flat shading bug in SoF +
    +Changes: +
      +
    • updated docs/README file +
    • use bcopy() optimizations on FreeBSD +
    • re-enabled the optimized persp_textured_triangle() function +
    + + +

    3.2.1 July 19, 2000

    +Bug fixes: +
      +
    • gluBuild2DMipmaps() didn't accept GL_BGRA +
    • Fixed compile/makefile problems on IRIX +
    • fixed segfault in 3dfx driver when using GL selection/feedback +
    • no longer cull very, very tiny triangles +
    • blending w/ drawbuffer==GL_FRONT_BACK caused segfault (sw rendering) +
    • fixed Motif detection code in widgets-mesa/configure.in +
    • glColorMaterial and glMaterial updates to emissive and ambient + didn't always work right +
    • Specular highlights weren't always in the right place +
    • clipped GL_LINE mode polygons had interior lines appear +
    • blend term GL_ONE_MINUS_CONSTANT_ALPHA was broken +
    • GL_NICEST fog didn't always work with flat shading +
    • glRect commands in display lists were sometimes miscolored +
    • Line Z offset didn't always work +
    • fixed texgen normal vector problem (gloss's teapot) +
    • numerous GL conformance bugs fixed +
    +Changes: +
      +
    • glColorMask(false, false, false, false) handled better/faster +
    • reverted to old GLU polygon tessellator, GLU 1.1 +
    • updated Win32 build files +
    + + +

    3.3 July 21, 2000

    +New: +
      +
    • antialiased triangles now implemented +
    • GL_EXT_texture_env_add texture mode extension +
    • GLX 1.3 API +
    • support for separate draw/read buffers (ie GL_SGI_make_current_read) +
    • thread-safe API dispath +
    • improved glxinfo program +
    • demos/texdown program to measure texture download performance +
    • glext.h header file +
    • demos/geartrain program +
    • GL_EXT_texture_lod_bias extension +
    • demos/lodbias program +
    • further optimized glRead/DrawPixels for 16-bit TrueColor X visuals +
    • GLX_EXT_visual_rating extension (a no-op, however) +
    • GL_HP_occlusion_test extension (for X and OS/Mesa drivers) +
    • demos/occlude program +
    • GL_SGIS_pixel_texture and GL_SGIX_pixel_texture extensions +
    • demos/pixeltex program +
    • GL_SGI_color_matrix extension +
    • GL_SGI_color_table extension +
    • GL_EXT_histogram extension +
    • GL_ARB_texture_cube_map extension +
    • added xdemos/glxheads and xdemos/manywin +
    • demos/texenv.c demo +
    • GL_EXT_texture_env_combine extension (by Holger Waechtler) +
    • Xlib driver is now thread-safe (see xdemos/glthreads) +
        +Bug Fixes: +
      +
    • various GL conformance failures fixed since 3.2.1 +
    +Changes: +
      +
    • gl.h now uses #defines instead of C enums for all tokens +
    • glu.h now uses #defines instead of C enums for all tokens +
    • moved programs from 3Dfx/demos/ into demos/ directory +
    + + +

    3.4 November 3, 2000

    +New: +
      +
    • optimized glDrawPixels for glPixelZoom(1,-1) +Bug Fixes: +
    • widgets-mesa/src/*.c files were missing from 3.3 distro +
    • include/GL/mesa_wgl.h file was missing from 3.3 distro +
    • fixed some Win32 compile problems +
    • texture object priorities weren't getting initialized to 1.0 +
    • glAreTexturesResident return value was wrong when using hardware +
    • glXUseXFont segfaulted when using 3dfx driver (via MESA_GLX_FX) +
    • glReadPixels with GLushort packed types was broken +
    • fixed a few bugs in the GL_EXT_texture_env_combine texture code +
    • glPush/PopAttrib(GL_ENABLE_BIT) mishandled multi-texture enables +
    • fixed some typos/bugs in the VB code +
    • glDrawPixels(GL_COLOR_INDEX) to RGB window didn't work +
    • optimized glDrawPixels paths weren't being used +
    • per-fragment fog calculation didn't work without a Z buffer +
    • improved blending accuracy, fixes Glean blendFunc test failures +
    • glPixelStore(GL_PACK/UNPACK_SKIP_IMAGES) wasn't handled correctly +
    • glXGetProcAddressARB() didn't always return the right address +
    • gluBuild[12]DMipmaps() didn't grok the GL_BGR pixel format +
    • texture matrix changes weren't always detected (GLUT projtex demo) +
    • fixed random color problem in vertex fog code +
    • fixed Glide-related bug that let Quake get a 24-bit Z buffer +
        +Changes: +
      +
    • finished internal support for compressed textures for DRI +
    + + +

    3.4.1 February 14, 2001

    +New: +
      +
    • fixed some Linux build problems +
    • fixed some Windows build problems +
    • GL_EXT_texture_env_dot3 extension (Gareth Hughes) +
    +Bug fixes: +
      +
    • added RENDER_START/RENDER_FINISH macros for glCopyTexImage in DRI +
    • various state-update code changes needed for DRI bugs +
    • disabled pixel transfer ops in glColorTable commands, not needed +
    • fixed bugs in glCopyConvolutionFilter1D/2D, glGetConvolutionFilter +
    • updated sources and fixed compile problems in widgets-mesa/ +
    • GLX_PBUFFER enum value was wrong in glx.h +
    • fixed a glColorMaterial lighting bug +
    • fixed bad args to Read/WriteStencilSpan in h/w stencil clear function +
    • glXCopySubBufferMESA() Y position was off by one +
    • Error checking of glTexSubImage3D() was broken (bug 128775) +
    • glPopAttrib() didn't restore all derived Mesa state correctly +
    • Better glReadPixels accuracy for 16bpp color - fixes lots of OpenGL + conformance problems at 16bpp. +
    • clearing depth buffer with scissoring was broken, would segfault +
    • OSMesaGetDepthBuffer() returned bad bytesPerValue value +
    • fixed a line clipping bug (reported by Craig McDaniel) +
    • fixed RGB color over/underflow bug for very tiny triangles +
    +Known problems: +
      +
    • NURBS or evaluator surfaces inside display lists don't always work +
    + + +

    3.4.2 May 17, 2001

    +Bug fixes: +
      +
    • deleting the currently bound texture could cause bad problems +
    • using fog could result in random vertex alpha values +
    • AA triangle rendering could touch pixels outside right window bound +
    • fixed byteswapping problem in clear_32bit_ximage() function +
    • fixed bugs in wglUseFontBitmapsA(), by Frank Warmerdam +
    • fixed memory leak in glXUseXFont() +
    • fragment sampling in AA triangle function was off by 1/2 pixel +
    • Windows: reading pixels from framebuffer didn't always work +
    • glConvolutionFilter2D could segfault or cause FP exception +
    • fixed segfaults in FX and X drivers when using tex unit 1 but not 0 +
    • GL_NAND logicop didn't work right in RGBA mode +
    • fixed a memory corruption bug in vertex buffer reset code +
    • clearing the softwara alpha buffer with scissoring was broken +
    • fixed a few color index mode fog bugs +
    • fixed some bad assertions in color index mode +
    • fixed FX line 'stipple' bug #420091 +
    • fixed stencil buffer clear width/height typo +
    • fixed GL error glitches in gl[Client]ActiveTextureARB() +
    • fixed Windows compilation problem in texutil.c +
    • fixed 1/8-pixel AA triangle sampling error +
    +Changes: +
      +
    • optimized writing mono-colored pixel spans to X pixmaps +
    • increased max viewport size to 2048 x 2048 +
    + + +

    3.5 June 21, 2001

    +New: +
      +
    • internals of Mesa divided into modular pieces (Keith Whitwell) +
    • 100% OpenGL 1.2 conformance (passes all conformance tests) +
    • new AA line algorithm +
    • GL_EXT_convolution extension +
    • GL_ARB_imaging subset +
    • OSMesaCreateContextExt() function +
    • GL_ARB_texture_env_add extension (same as GL_EXT_texture_env_add) +
    • GL_MAX_TEXTURE_UNITS_ARB now defaults to eight +
    • GL_EXT_fog_coord extension (Keith Whitwell) +
    • GL_EXT_secondary_color extension (Keith Whitwell) +
    • GL_ARB_texture_env_add extension (same as GL_EXT_texture_env_add) +
    • GL_SGIX_depth_texture extension +
    • GL_SGIX_shadow and GL_SGIX_shadow_ambient extensions +
    • demos/shadowtex.c demo of GL_SGIX_depth_texture and GL_SGIX_shadow +
    • GL_ARB_texture_env_combine extension +
    • GL_ARB_texture_env_dot3 extension +
    • GL_ARB_texture_border_clamp (aka GL_SGIS_texture_border_clamp) +
    • OSMesaCreateContextExt() function +
    • libOSMesa.so library, contains the OSMesa driver interface +
    • GL/glxext.h header file for GLX extensions +
    • somewhat faster software texturing, fogging, depth testing +
    • all color-index conformance tests now pass (only 8bpp tested) +
    • SPARC assembly language TCL optimizations (David Miller) +
    • GL_SGIS_generate_mipmap extension +
    +Bug Fixes: +
      +
    • fbiRev and tmuRev were unitialized when using Glide3 +
    • fixed a few color index mode conformance failures; all pass now +
    • now appling antialiasing coverage to alpha after texturing +
    • colors weren't getting clamped to [0,1] before color table lookup +
    • fixed RISC alignment errors caused by COPY_4UBV macro +
    • drawing wide, flat-shaded lines could cause a segfault +
    • vertices now snapped to 1/16 pixel to fix rendering of tiny triangles +
    +Changes: +
      +
    • SGI's Sample Implementation (SI) 1.3 GLU library replaces Mesa GLU +
    • new libOSMesa.so library, contains the OSMesa driver interface +
    + + +

    4.0 October 22, 2001

    +New: +
      +
    • Mesa 4.0 implements the OpenGL 1.3 specification +
    • GL_IBM_rasterpos_clip extension +
    • GL_EXT_texture_edge_clamp extension (aka GL_SGIS_texture_edge_clamp) +
    • GL_ARB_texture_mirrored_repeat extension +
    • WindML UGL driver (Stephane Raimbault) +
    • added OSMESA_MAX_WIDTH/HEIGHT queries +
    • attempted compiliation fixes for Solaris 5, 7 and 8 +
    • updated glext.h and glxext.h files +
    • updated Windows driver (Karl Schultz) +
    +Bug fixes: +
      +
    • added some missing GLX 1.3 tokens to include/GL/glx.h +
    • GL_COLOR_MATRIX changes weren't recognized by teximage functions +
    • glCopyPixels with scale and bias was broken +
    • glRasterPos with lighting could segfault +
    • glDeleteTextures could leave a dangling pointer +
    • Proxy textures for cube maps didn't work +
    • fixed a number of 16-bit color channel bugs +
    • fixed a few minor memory leaks +
    • GLX context sharing was broken in 3.5 +
    • fixed state-update bugs in glPopClientAttrib() +
    • fixed glDrawRangeElements() bug +
    • fixed a glPush/PopAttrib() bug related to texture binding +
    • flat-shaded, textured lines were broken +
    • fixed a dangling pointer problem in the XMesa code (Chris Burghart) +
    • lighting didn't always produce the correct alpha value +
    • fixed 3DNow! code to not read past end of arrays (Andrew Lewycky) +
    + + +

    4.0.1 December 17, 2001

    +New: +
      +
    • better sub-pixel sample positions for AA triangles (Ray Tice) +
    • slightly faster blending for (GL_ZERO, GL_ONE) and (GL_ONE, GL_ZERO) +
    +Bug fixes: +
      +
    • added missing break statements in glGet*() for multisample cases +
    • fixed uninitialized hash table mutex bug (display lists / texobjs) +
    • fixed bad teximage error check conditional (bug 476846) +
    • fixed demos readtex.c compilation problem on Windows (Karl Schultz) +
    • added missing glGet() query for GL_MAX_TEXTURE_LOD_BIAS_EXT +
    • silence some compiler warnings (gcc 2.96) +
    • enable the #define GL_VERSION_1_3 in GL/gl.h +
    • added GL 1.3 and GLX 1.4 entries to gl_mangle.h and glx_mangle.h +
    • fixed glu.h typedef problem found with MSDev 6.0 +
    • build libGL.so with -Bsymbolic (fixes bug found with Chromium) +
    • added missing 'const' to glXGetContextIDEXT() in glxext.h +
    • fixed a few glXGetProcAddress() errors (texture compression, etc) +
    • fixed start index bug in compiled vertex arrays (Keith) +
    • fixed compilation problems in src/SPARC/glapi_sparc.S +
    • fixed triangle strip "parity" bug found in VTK medical1 demo (Keith) +
    • use glXGetProcAddressARB in GLUT to avoid extension linking problems +
    • provoking vertex of flat-shaded, color-index triangles was wrong +
    • fixed a few display list bugs (GLUT walker, molecule, etc) (Keith) +
    • glTexParameter didn't flush the vertex buffer (Ray Tice) +
    • feedback attributes for glDraw/CopyPixels and glBitmap were wrong +
    • fixed bug in normal length caching (ParaView lighting bug) +
    • fixed separate_specular color bug found in Chimera (18 Dec 2001) +
    + + +

    4.0.2 April 2, 2002

    +New: +
      +
    • New DOS (DJGPP) driver written by Daniel Borca +
    • New driver interface functions for TCL drivers (such as Radeon DRI) +
    • GL_RENDERER string returns "Mesa Offscreen16" or "Mesa Offscreen32" + if using deep color channels +
    • latest GL/glext.h and GL/glxext.h headers from SGI +
    +Bug fixes: +
      +
    • GL_BLEND with non-black texture env color wasn't always correct +
    • GL_REPLACE with GL_RGB texture format wasn't always correct (alpha) +
    • glTexEnviv( pname != GL_TEXTURE_ENV_COLOR ) was broken +
    • glReadPixels was sometimes mistakenly clipped by the scissor box +
    • glDraw/ReadPixels didn't catch all the errors that they should have +
    • Fixed 24bpp rendering problem in Windows driver (Karl Schultz) +
    • 16-bit GLchan mode fixes (m_trans_tmp.h, s_triangle.c) +
    • Fixed 1-bit float->int conversion bug in glDrawPixels(GL_DEPTH_COMP) +
    • glColorMask as sometimes effecting glXSwapBuffers() +
    • fixed a potential bug in XMesaGarbageCollect() +
    • N threads rendering into one window didn't work reliably +
    • glCopyPixels didn't work for deep color channels +
    • improved 8 -> 16bit/channel texture image conversion (Gerk Huisma) +
    • glPopAttrib() didn't correctly restore user clip planes +
    • user clip planes failed for some perspective projections (Chromium) +
    +Known bugs: +
      +
    • mipmap LOD computation +
    + + +

    4.0.3 June 25, 2002

    +New: +
      +
    • updated GL/glext.h file (version 15) +
    • corrected MMX blend code (Jose Fonseca) +
    • support for software-based alpha planes in Windows driver +
    • updated GGI driver (Filip Spacek) +
    +Bug fixes: +
      +
    • glext.h had wrong values for GL_DOT3_RGB[A]_EXT tokens +
    • OSMesaMakeCurrent() didn't recognize buffer size changes +
    • assorted conformance fixes for 16-bit/channel rendering +
    • texcombine alpha subtraction mode was broken +
    • fixed lighting bug with non-uniform scaling and display lists +
    • fixed bug when deleting shared display lists +
    • disabled SPARC cliptest assembly code (Mesa bug 544665) +
    • fixed a couple Solaris compilation/link problems +
    • blending clipped glDrawPixels didn't always work +
    • glGetTexImage() didn't accept packed pixel types +
    • glPixelMapu[is]v() could explode given too large of pixelmap +
    • glGetTexParameter[if]v() didn't accept GL_TEXTURE_MAX_ANISOTROPY_EXT +
    • glXCopyContext() could lead to segfaults +
    • glCullFace(GL_FRONT_AND_BACK) didn't work (bug 572665) +
    +Changes: +
      +
    • lots of C++ (g++) code clean-ups +
    • lots of T&L updates for the Radeon DRI driver +
    +Known bugs: +
      +
    • mipmap LOD computation (fixed for Mesa 4.1) +
    + + +

    4.0.4 October 3, 2002

    +New: +
      +
    • GL_NV_texture_rectangle extension +
    • updated glext.h header (version 17) +
    • updated DOS driver (Daniel Borca) +
    • updated BeOS R5 driver (Philippe Houdoin) +
    • added GL_IBM_texture_mirror_repeat +
    • glxinfo now takes -l option to print interesting OpenGL limits info +
    • GL_MESA_ycbcr_texture extension +
    • GL_APPLE_client_storage extension (for some DRI drivers only) +
    • GL_MESA_pack_invert extension +
    +Bug fixes: +
      +
    • fixed GL_LINEAR fog bug by adding clamping +
    • fixed FP exceptions found using Alpha CPU +
    • 3dfx MESA_GLX_FX=window (render to window) didn't work +
    • fixed memory leak in wglCreateContest (Karl Schultz) +
    • define GLAPIENTRY and GLAPI if undefined in glu.h +
    • wglGetProcAddress didn't handle all API functions +
    • when testing for OpenGL 1.2 vs 1.3, check for GL_ARB_texture_cube_map +
    • removed GL_MAX_CONVOLUTION_WIDTH/HEIGHT from glGetInteger/Float/etc() +
    • error checking in compressed tex image functions had some glitches +
    • fixed AIX compile problem in src/config.c +
    • glGetTexImage was using pixel unpacking instead of packing params +
    • auto-mipmap generation for cube maps was incorrect +
    +Changes: +
      +
    • max texture units reduced to six to accomodate texture rectangles +
    • removed unfinished GL_MESA_sprite_point extension code +
    + + +

    4.1 October 29, 2002

    +New: +
      +
    • GL_NV_vertex_program extension +
    • GL_NV_vertex_program1_1 extension +
    • GL_ARB_window_pos extension +
    • GL_ARB_depth_texture extension +
    • GL_ARB_shadow extension +
    • GL_ARB_shadow_ambient extension +
    • GL_EXT_shadow_funcs extension +
    • GL_ARB_point_parameters extension +
    • GL_ARB_texture_env_crossbar +
    • GL_NV_point_sprite extension +
    • GL_NV_texture_rectangle extension +
    • GL_EXT_multi_draw_arrays extension +
    • GL_EXT_stencil_two_side extension +
    • GLX_SGIX_fbconfig and GLX_SGIX_pbuffer extensions +
    • GL_ATI_texture_mirror_once extension (Ian Romanick) +
    • massive overhaul/simplification of software rasterizer module, + many contributions from Klaus Niederkrueger +
    • faster software texturing in some cases (i.e. trilinear filtering) +
    • new OSMesaGetProcAddress() function +
    • more blend modes implemented with MMX code (Jose Fonseca) +
    • added glutGetProcAddress() to GLUT +
    • added GLUT_FPS env var to compute frames/second in glutSwapBuffers() +
    • pbinfo and pbdemo PBuffer programs +
    • glxinfo -v prints transprent pixel info (Gerd Sussner) +
    +Bug fixes: +
      +
    • better mipmap LOD computation (prevents excessive blurriness) +
    • OSMesaMakeCurrent() didn't recognize buffer size changes +
    • assorted conformance fixes for 16-bit/channel rendering +
    • texcombine alpha subtraction mode was broken +
    • fixed some blend problems when GLchan==GLfloat (Gerk Huisma) +
    • clamp colors to [0,inf] in OSMesa if GLchan==GLfloat (Gerk Huisma) +
    • fixed divide by zero error in NURBS tessellator (Jon Perry) +
    • fixed GL_LINEAR fog bug by adding clamping +
    • fixed FP exceptions found using Alpha CPU +
    • 3dfx/glide driver render-to-window feature was broken +
    • added missing GLX_TRANSPARENT_RGB token to glx.h +
    • fixed error checking related to paletted textures +
    • fixed reference count error in glDeleteTextures (Randy Fayan) +
    +Changes: +
      +
    • New spec file and Python code to generate some GL dispatch files +
    • Glide driver defaults to "no" with autoconf/automake +
    • updated demos/stex3d with new options +
    + + +

    5.0 November 13, 2002

    +New: +
      +
    • OpenGL 1.4 support (glGetString(GL_VERSION) returns "1.4") +
    • removed some overlooked debugging code +
    • glxinfo updated to support GLX_ARB_multisample +
    • GLUT now support GLX_ARB_multisample +
    • updated DOS driver (Daniel Borca) +
    +Bug fixes: +
      +
    • GL_POINT and GL_LINE-mode polygons didn't obey cull state +
    • fixed potential bug in _mesa_align_malloc/calloc() +
    • fixed missing triangle bug when running vertex programs +
    • fixed a few HPUX compilation problems +
    • FX (Glide) driver didn't compile +
    • setting GL_TEXTURE_BORDER_COLOR with glTexParameteriv() didn't work +
    • a few EXT functions, like glGenTexturesEXT, were no-ops +
    • a few OpenGL 1.4 functions like glFogCoord*, glBlendFuncSeparate, + glMultiDrawArrays and glMultiDrawElements were missing +
    • glGet*(GL_ACTIVE_STENCIL_FACE_EXT) was broken +
    • Pentium 4 Mobile was mistakenly identified as having 3DNow! +
    • fixed one-bit error in point/line fragment Z calculation +
    • fixed potential segfault in fakeglx code +
    • fixed color overflow problem in DOT3 texture env mode +
    + + +

    5.0.1 March 30, 2003

    +New: +
      +
    • DOS driver updates from Daniel Borca +
    • updated GL/gl_mangle.h file (Bill Hoffman) +Bug fixes: +
    • auto mipmap generation for cube maps was broken (bug 641363) +
    • writing/clearing software alpha channels was unreliable +
    • minor compilation fixes for OS/2 (Evgeny Kotsuba) +
    • fixed some bad assertions found with shadowtex demo +
    • fixed error checking bug in glCopyTexSubImage2D (bug 659020) +
    • glRotate(angle, -x, 0, 0) was incorrect (bug 659677) +
    • fixed potential segfault in texture object validation (bug 659012) +
    • fixed some bogus code in _mesa_test_os_sse_exception_support (Linus) +
    • fix fog stride bug in tnl code for h/w drivers (Michel Danzer) +
    • fixed glActiveTexture / glMatrixMode(GL_TEXTURE) bug (#669080) +
    • glGet(GL_CURRENT_SECONDARY_COLOR) should return 4 values, not 3 +
    • fixed compilation problem on Solaris7/x86 (bug 536406) +
    • fixed prefetch bug in 3DNow! code (Felix Kuhling) +
    • fixed NeXT build problem (FABSF macro) +
    • glDrawPixels Z values when glPixelZoom!=1 were invalid (bug 687811) +
    • zoomed glDraw/CopyPixels with clipping sometimes failed (bug 689964) +
    • AA line and triangle Z values are now rounded, not truncated +
    • fixed color interpolation bug when GLchan==GLfloat (bug 694461) +
    • glArePrograms/TexturesResident() wasn't 100% correct (Jose Fonseca) +
    • fixed a minor GL_COLOR_MATERIAL bug +
    • NV vertex program EXP instruction was broken +
    • glColorMask misbehaved with X window / pixmap rendering +
    • fix autoconf/libtool GLU C++ linker problem on Linux (a total hack) +
    • attempt to fix GGI compilation problem when MesaDemos not present +
    • NV vertex program ARL-relative fetches didn't work +
    +Changes: +
      +
    • use glPolygonOffset in gloss demo to avoid z-fighting artifacts +
    • updated winpos and pointblast demos to use ARB extensions +
    • disable SPARC normal transformation code (bug 673938) +
    • GLU fixes for OS/2 (Evgeny Kotsuba) +
    + + +

    5.0.2 September 5, 2003

    +Bug fixes: +
      +
    • fixed texgen problem causing texcoord's Q to be zero (stex3d) +
    • default GL_TEXTURE_COMPARE_MODE_ARB was wrong +
    • GL_CURRENT_MATRIX_NV query was wrong +
    • GL_CURRENT_MATRIX_STACK_DEPTH_NV query was off by one +
    • GL_LIST_MODE query wasn't correct +
    • GL_FOG_COORDINATE_SOURCE_EXT query wasn't supported +
    • GL_SECONDARY_COLOR_ARRAY_SIZE_EXT query returned wrong value +
    • blended, wide lines didn't always work correctly (bug 711595) +
    • glVertexAttrib4svNV w component was always 1 +
    • fixed bug in GL_IBM_rasterpos_clip (missing return) +
    • GL_DEPTH_TEXTURE_MODE = GL_ALPHA didn't work correctly +
    • a few Solaris compilation fixes +
    • fixed glClear() problem for DRI drivers (non-existant stencil, etc) +
    • fixed int/REAL mixup in GLU NURBS curve evaluator (Eric Cazeaux) +
    • fixed delete [] bug in SI GLU (bug 721765) (Diego Santa Cruz) +
    • glFog() didn't clamp fog colors +
    • fixed bad float/int conversion for GL_TEXTURE_PRIORITY in the + gl[Get]TexParameteri[v] functions +
    • fixed invalid memory references in glTexGen functions (bug 781602) +
    • integer-valued color arrays weren't handled correctly +
    • glDrawPixels(GL_DEPTH_COMPONENT) with glPixelZoom didn't work +
    • GL_EXT_texture_lod_bias is part of 1.4, overlooked in 5.0.1 +
    +Changes: +
      +
    • build GLUT with -fexceptions so C++ apps propogate exceptions +
    + + +

    5.1 December 17, 2003

    +New: +
      +
    • reorganized directory tree +
    • GL_ARB_vertex/fragment_program extensions (Michal Krol & Karl Rasche) +
    • GL_ATI_texture_env_combine3 extension (Ian Romanick) +
    • GL_SGI_texture_color_table extension (Eric Plante) +
    • GL_NV_fragment_program extension +
    • GL_NV_light_max_exponent extension +
    • GL_EXT_texture_rectangle (identical to GL_NV_texture_rectangle) +
    • GL_ARB_occlusion_query extension +
    • GL_ARB_point_sprite extension +
    • GL_ARB_texture_non_power_of_two extension +
    • GL_IBM_multimode_draw_arrays extension +
    • GL_EXT_texture_mirror_clamp extension (Ian Romanick) +
    • GL_ARB_vertex_buffer_object extension +
    • new X86 feature detection code (Petr Sebor) +
    • less memory used for display lists and vertex buffers +
    • demo of per-pixel lighting with a fragment program (demos/fplight.c) +
    • new version (18) of glext.h header +
    • new spriteblast.c demo of GL_ARB_point_sprite +
    • faster glDrawPixels in X11 driver in some cases (see RELNOTES-5.1) +
    • faster glCopyPixels in X11 driver in some cases (see RELNOTES-5.1) +
    +Bug fixes: +
      +
    • really enable OpenGL 1.4 features in DOS driver. +
    • fixed issues in glDrawPixels and glCopyPixels for very wide images +
    • glPixelMapf/ui/usv()'s size parameter is GLsizei, not GLint +
    • fixed some texgen bugs reported by Daniel Borca +
    • fixed wglMakeCurrent(NULL, NULL) bug (#835861) +
    • fixed glTexSubImage3D z-offset bug (Cedric Gautier) +
    • fixed RGBA blend enable bug (Ville Syrjala) +
    • glAccum is supposed to be a no-op in selection/feedback mode +
    • fixed texgen bug #597589 (John Popplewell) +
    +Changes: +
      +
    • dropped API trace feature (src/Trace/) +
    • documentation overhaul. merged with website content. more html. +
    • glxgears.c demo updated to use GLX swap rate extensions +
    • glTexImage1/2/3D now allows width/height/depth = 0 +
    • disable SPARC asm code on Linux (bug 852204) +
    + + +

    6.0 January 16, 2004

    +New: +
      +
    • full OpenGL 1.5 support +
    • updated GL/glext.h file to version 21 +Changes: +
    • changed max framebuffer size to 4Kx4K (MAX_WIDTH/HEIGHT in config.h) +Bug fixes: +
    • fixed bug in UNCLAMPED_FLOAT_TO_UBYTE macro; solves a color + clamping issue +
    • updated suno5-gcc configs +
    • glColor3 functions sometimes resulted in undefined alpha values +
    • fixed FP divide by zero error seen on VMS with xlockmore, others +
    • fixed vertex/fragment program debug problem (bug 873011) +
    • building on AIX with gcc works now +
    • glDeleteProgramsARB failed for ARB fragment programs (bug 876160) +
    • glDrawRangeElements tried to modify potentially read-only storage +
    • updated files for building on Windows +
    + + +

    6.0.1 April 2, 2004

    +New: +
      +
    • upgraded glext.h to version 22 +
    • new build targets (Dan Schikore) +
    • new linux-x86-opteron build target (Heath Feather) +
    +Bug fixes: +
      +
    • glBindProgramARB didn't update all necessary state +
    • fixed build problems on OpenBSD +
    • omit CVS directories from tarballs +
    • glGetTexImage(GL_COLOR_INDEX) was broken +
    • fixed an infinite loop in t&l module +
    • silenced some valgrind warnings about using unitialized memory +
    • fixed some compilation/link glitches on IRIX (Mike Stephens) +
    • glBindProgram wasn't getting compiled into display lists +
    • GLX_FBCONFIG_ID wasn't recognized in glXChooseFBConfig() (bug 888079) +
    • two-sided lighting and vertex program didn't work (bug 887330) +
    • stores to program parameter registers in vertex state programs + didn't work. +
    • fixed glOrtho bug found with gcc 3.2.2 (RH9) +
    • glXCreateWindow() wasn't fully implemented (bug 890894) +
    • generic vertex attribute arrays didn't work in display lists +
    • vertex buffer objects' default usage and access fields were wrong +
    • glDrawArrays with start!=0 was broken +
    • fragment program PK2H, UP2H, UP4B and UP4UB instructions were broken +
    • linux-osmesa16-static config didn't work +
    • fixed a few color index rendering problems (bug 910687) +
    • glInterleavedArrays didn't respect GL_CLIENT_ACTIVE_TEXTURE +
    • OSMesa RGB and BGR modes were broken +
    • glProgramStringARB mistakenly required a null-terminated string +
    • fragment program XPD instruction was incorrect +
    • glGetMaterial() didn't work reliably +
    • ARB_fragment_program KIL instruction was incorrect +
    + + +

    6.1 August 18, 2004

    +New: +
      +
    • Revamped Makefile system +
    • glXUseRotatedXFont() utility (see xdemos/xuserotfont.c) +
    • internal driver interface changes related to texture object + allocation, vertex/fragment programs, BlendEquationSeparate, etc. +
    • option to walk triangle edges with double-precision floats + (Justin Novosad of Discreet) (see config.h file) +
    • support for AUX buffers in software GLX driver +
    • updated glext.h to version 24 and glxext.h to version 6 +
    • new MESA_GLX_FORCE_ALPHA and MESA_GLX_DEPTH_BITS env vars +
    • updated BeOS support (Philippe Houdoin) +
    +Changes: +
      +
    • fragment fog interpolation is perspective corrected now +
    • new glTexImage code, much cleaner, may be a bit faster +
    +Bug fixes: +
      +
    • glArrayElement in display lists didn't handle generic vertex attribs +
    • glFogCoord didn't always work properly +
    • ARB_fragment_program fog options didn't work +
    • frag prog TEX instruction no longer incorrectly divides s,t,r by q +
    • ARB frag prog TEX and TEXP instructions now use LOD=0 +
    • glTexEnviv in display lists didn't work +
    • glRasterPos didn't do texgen or apply texture matrix +
    • GL_DOUBLE-valued vertex arrays were broken in some cases +
    • fixed texture rectangle edge/border sampling bugs +
    • sampling an incomplete texture in a fragment program would segfault +
    • glTexImage was missing a few error checks +
    • fixed some minor glGetTexParameter glitches +
    • GL_INTENSITY was mistakenly accepted as a to glTexImage +
    • fragment program writes to RC/HC register were broken +
    • fixed a few glitches in GL_HP_occlusion_test extension +
    • glBeginQueryARB and glEndQueryARB didn't work inside display lists +
    • vertex program state references were broken +
    • fixed triangle color interpolation bug on AIX (Shane Blackett) +
    • fixed a number of minor memory leaks (bug #1002030) +
    + + +

    6.2 October 2, 2004

    +New: +
      +
    • enabled GL_ARB_texture_rectangle (same as GL_NV_texture_rectangle) +
    • updated Doxygen support (Jose Fonseca) +
    +Changes: +
      +
    • some GGI driver updates (Christoph Egger, bug 1025977) +
    +Bug fixes: +
      +
    • Omit GL_ARB_texture_non_power_of_two from list of OpenGL 1.5 features +
    • fixed a few compilation issues on IRIX +
    • fixed a matrix classification bug (reported by Wes Bethel) +
    • we weren't reseting the vertex/fragment program error state + before parsing (Dave Reveman) +
    • adjust texcoords for sampling texture rectangles (Dave Reveman) +
    • glGet*(GL_MAX_VERTEX_ATTRIBS_ARB) wasn't implemented +
    • repeated calls to glDeleteTexture(t) could lead to a crash +
    • fixed potential ref count bugs in VBOs and vertex/fragment programs +
    • spriteblast demo didn't handle window size changes correctly +
    • glTexSubImage didn't handle pixels=NULL correctly for PBOs +
    • fixed color index mode glDrawPixels bug (Karl Schultz) +
    + + +

    6.2.1 December 9, 2004

    +Bug fixes: +
      +
    • don't apply regular fog or color sum when using a fragment program +
    • glProgramEnvParameter4fARB always generated an error on + GL_FRAGMENT_PROGRAM_ARB (fdo bug 1645) +
    • glVertexAttrib3svNV and glVertexAttrib3svARB were broken +
    • fixed width/height mix-up in glSeparableFilter2D() +
    • fixed regression in glCopyPixels + convolution +
    • glReadPixels from a clipped front color buffer didn't always work +
    • glTexImage didn't accept GL_RED/GREEN/BLUE as the format +
    • Attempting queries/accesses of VBO 0 weren't detected as errors +
    • paletted textures failed if the palette had fewer than 256 entries +
    +Changes: +
      +
    • fixed a bunch of compiler warnings found with gcc 3.4 +
    • bug reports should to go bugzilla.freedesktop.org +
    + + +

    6.3 July 20, 2005

    +New: +
      +
    • GL_EXT_framebuffer_object extension +
    • GL_ARB_draw_buffers extension +
    • GL_ARB_pixel_buffer_object extension +
    • GL_OES_read_format extension (Ian Romanick) +
    • DirectFB driver (Claudio Ciccani) +
    • x86_64 vertex transformation code (Mikko T.) +
    • Updated GL/glext.h to version 29 +
    +Changes: +
      +
    • added -stereo option for glxgears demo (Jacek Rosik) +
    • updated the PBuffer demo code in xdemos/ directory +
    • glDeleteTextures/Programs/Buffers() now makes the object ID + available for immediate re-use +
    • assorted 64-bit clean-ups fixes (x86_64 and Win64) +
    • lots of internal changes for GL_EXT_framebuffer_object +
    +Bug fixes: +
      +
    • some functions didn't support PBO functionality +
    • glGetTexImage didn't convert color index images to RGBA as required +
    • fragment program texcoords were sometimes wrong for points and lines +
    • fixed problem with negative dot product in arbfplight, fplight demos +
    • fixed bug in perspective correction of antialiased, textured lines +
    • querying GL_POST_CONVOLUTION_ALPHA_BIAS_EXT returned wrong value +
    • fixed a couple per-pixel fog bugs (Soju Matsumoto) +
    • glGetBooleanv(GL_FRAGMENT_PROGRAM_BINDING_NV) was broken +
    • fixed float parsing bug in ARB frag/vert programs (bug 2520) +
    • XMesaGetDepthBuffer() returned incorrect value for bytesPerValue +
    • GL_COLOR_MATERIAL with glColor3 didn't properly set diffuse alpha +
    • glXChooseFBConfig() crashed if attribList pointer was NULL +
    • program state.light[n].spot.direction.w was wrong value (bug 3083) +
    • fragment program fog option required glEnable(GL_FOG) - wrong. +
    • glColorTable() could produce a Mesa implementation error (bug 3135) +
    • RasterPos could get corrupted by color index rendering path +
    • Removed bad XTranslateCoordinates call when rendering to Pixmaps +
    • glPopAttrib() didn't properly restore GL_TEXTURE_GEN enable state +
    • fixed a few Darwin compilation problems +
    + + +

    6.3.1

    +

    +This was an intermediate release for X.org which wasn't otherwise released.) +

    + + +

    6.3.2 August 19, 2005

    +New: +
      +
    • The distribution now includes the DRI drivers and GLX code +
    +Changes: +
      +
    • Made the DRI "new" driver interface standard, remove old code +
    +Bug fixes: +
      +
    • GL_ARB_vertex/fragment_shader were mistakenly listed in the + extensions string +
    • negative relative addressing in vertex programs was broken +
    • update/fix SPARC assembly code for vertex transformation +
    • fixed memory leak when freeing GLX drawables/renderbuffers +
    • fixed display list memory leak +
    • the GL_PIXEL_MAP_I_TO_I table is now floating point, not integer +
    • wglGetProcAddress() didn't handle wgl-functions +
    • fixed glxext.h cross-compile issue (Colin Harrison) +
    • assorted DRI driver fixes +
    + + + +NOTE: Changes for Mesa 6.4 and later are documented in the corresponding +
    release notes file. + + + + + diff --git a/docs/webmaster.html b/docs/webmaster.html new file mode 100644 index 0000000..16f4dc8 --- /dev/null +++ b/docs/webmaster.html @@ -0,0 +1,24 @@ + + +Mesa Introduction + + + + + +

    Webmaster

    + +

    +If you have problems, edits or additions for this website send them +to Brian +(brian.e.paul gmail.com). +

    + +

    +Mark Manning made the frame-based layout for the website. +Brian's modified it a lot since then. +

    + + + + diff --git a/docs/xlibdriver.html b/docs/xlibdriver.html new file mode 100644 index 0000000..d95f4d5 --- /dev/null +++ b/docs/xlibdriver.html @@ -0,0 +1,275 @@ + + +Xlib Software Driver + + + + + +

    Xlib Software Driver

    + +

    +Mesa's Xlib driver provides an emulation of the GLX interface so that +OpenGL programs which use the GLX API can render to any X display, even +those that don't support the GLX extension. +Effectively, the Xlib driver converts all OpenGL rendering into Xlib calls. +

    + +

    +The Xlib driver is the oldest Mesa driver and the most mature of Mesa's +software-only drivers. +

    + +

    +Since the Xlib driver emulates the GLX extension, it's not +totally conformant with a true GLX implementation. +The differences are fairly obscure, however. +

    + +

    +The unique features of the Xlib driver follows. +

    + + +

    X Visual Selection

    +

    +Mesa supports RGB(A) rendering into almost any X visual type and depth. +

    +

    +The glXChooseVisual function tries to choose the best X visual +for the given attribute list. However, if this doesn't suit your needs +you can force Mesa to use any X visual you want (any supported by your +X server that is) by setting the MESA_RGB_VISUAL and +MESA_CI_VISUAL +environment variables. +When an RGB visual is requested, glXChooseVisual +will first look if the MESA_RGB_VISUAL variable is defined. +If so, it will try to use the specified visual. +Similarly, when a color index visual is requested, glXChooseVisual will +look for the MESA_CI_VISUAL variable. +

    + +

    +The format of accepted values is: visual-class depth +

    +

    +Here are some examples: +

    +
    +   using csh:
    +	% setenv MESA_RGB_VISUAL "TrueColor 8"		// 8-bit TrueColor
    +	% setenv MESA_CI_VISUAL "PseudoColor 12"	// 12-bit PseudoColor
    +	% setenv MESA_RGB_VISUAL "PseudoColor 8"	// 8-bit PseudoColor
    +
    +   using bash:
    +	$ export MESA_RGB_VISUAL="TrueColor 8"
    +	$ export MESA_CI_VISUAL="PseudoColor 12"
    +	$ export MESA_RGB_VISUAL="PseudoColor 8"
    +
    + + +

    Double Buffering

    +

    +Mesa can use either an X Pixmap or XImage as the back color buffer when in +double-buffer mode. +The default is to use an XImage. +The MESA_BACK_BUFFER environment variable can override this. +The valid values for MESA_BACK_BUFFER are: Pixmap and +XImage (only the first letter is checked, case doesn't matter). +

    + +

    +Using XImage is almost always faster than a Pixmap since it resides in +the application's address space. +When glXSwapBuffers() is called, XPutImage() or XShmPutImage() is used +to transfer the XImage to the on-screen window. +

    +

    +A Pixmap may be faster when doing remote rendering of a simple scene. +Some OpenGL features will be very slow with a Pixmap (for example, blending +will require a round-trip message for pixel readback.) +

    +

    +Experiment with the MESA_BACK_BUFFER variable to see which is faster +for your application. +

    + + +

    Colormaps

    +

    +When using Mesa directly or with GLX, it's up to the application +writer to create a window with an appropriate colormap. The GLUT +toolkit tris to minimize colormap flashing by sharing +colormaps when possible. Specifically, if the visual and depth of the +window matches that of the root window, the root window's colormap +will be shared by the Mesa window. Otherwise, a new, private colormap +will be allocated. +

    + +

    +When sharing the root colormap, Mesa may be unable to allocate the colors +it needs, resulting in poor color quality. This can happen when a +large number of colorcells in the root colormap are already allocated. +To prevent colormap sharing in GLUT, set the +MESA_PRIVATE_CMAP environment variable. The value isn't +significant. +

    + + +

    Gamma Correction

    +

    +To compensate for the nonlinear relationship between pixel values +and displayed intensities, there is a gamma correction feature in +Mesa. Some systems, such as Silicon Graphics, support gamma +correction in hardware (man gamma) so you won't need to use Mesa's +gamma facility. Other systems, however, may need gamma adjustment +to produce images which look correct. If you believe that +Mesa's images are too dim, read on. +

    + +

    +Gamma correction is controlled with the MESA_GAMMA environment +variable. Its value is of the form Gr Gg Gb or just G where +Gr is the red gamma value, Gg is the green gamma value, Gb is the +blue gamma value and G is one gamma value to use for all three +channels. Each value is a positive real number typically in the +range 1.0 to 2.5. +The defaults are all 1.0, effectively disabling gamma correction. +Examples: +

    +
    +	% export MESA_GAMMA="2.3 2.2 2.4"	// separate R,G,B values
    +	% export MESA_GAMMA="2.0"		// same gamma for R,G,B
    +
    +

    +The progs/demos/gamma.c program may help you to determine reasonable gamma +value for your display. With correct gamma values, the color intensities +displayed in the top row (drawn by dithering) should nearly match those +in the bottom row (drawn as grays). +

    + +

    +Alex De Bruyn reports that gamma values of 1.6, 1.6 and 1.9 work well +on HP displays using the HP-ColorRecovery technology. +

    + +

    +Mesa implements gamma correction with a lookup table which translates +a "linear" pixel value to a gamma-corrected pixel value. There is a +small performance penalty. Gamma correction only works in RGB mode. +Also be aware that pixel values read back from the frame buffer will +not be "un-corrected" so glReadPixels may not return the same data +drawn with glDrawPixels. +

    + +

    +For more information about gamma correction see: + +

    + + +

    Overlay Planes

    +

    +Hardware overlay planes are supported by the Xlib driver. To +determine if your X server has overlay support you can test for the +SERVER_OVERLAY_VISUALS property: +

    +
    +	xprop -root | grep SERVER_OVERLAY_VISUALS
    +
    + + +

    HPCR Dithering

    +

    +If you set the MESA_HPCR_CLEAR environment variable then dithering +will be used when clearing the color buffer. This is only applicable +to HP systems with the HPCR (Color Recovery) feature. +This incurs a small performance penalty. +

    + + +

    Extensions

    +

    +The following MESA-specific extensions are implemented in the Xlib driver. +

    + +

    GLX_MESA_pixmap_colormap

    + +

    +This extension adds the GLX function: +

    +
    +    GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual,
    +                                      Pixmap pixmap, Colormap cmap )
    +
    +

    +It is an alternative to the standard glXCreateGLXPixmap() function. +Since Mesa supports RGB rendering into any X visual, not just True- +Color or DirectColor, Mesa needs colormap information to convert RGB +values into pixel values. An X window carries this information but a +pixmap does not. This function associates a colormap to a GLX pixmap. +See the xdemos/glxpixmap.c file for an example of how to use this +extension. +

    +

    +GLX_MESA_pixmap_colormap specification +

    + + +

    GLX_MESA_release_buffers

    +

    +Mesa associates a set of ancillary (depth, accumulation, stencil and +alpha) buffers with each X window it draws into. These ancillary +buffers are allocated for each X window the first time the X window +is passed to glXMakeCurrent(). Mesa, however, can't detect when an +X window has been destroyed in order to free the ancillary buffers. +

    +

    +The best it can do is to check for recently destroyed windows whenever +the client calls the glXCreateContext() or glXDestroyContext() +functions. This may not be sufficient in all situations though. +

    +

    +The GLX_MESA_release_buffers extension allows a client to explicitly +deallocate the ancillary buffers by calling glxReleaseBuffersMESA() +just before an X window is destroyed. For example: +

    +
    +         #ifdef GLX_MESA_release_buffers
    +            glXReleaseBuffersMESA( dpy, window );
    +         #endif
    +         XDestroyWindow( dpy, window );
    +
    +

    +GLX_MESA_release_buffers specification +

    +

    +This extension was added in Mesa 2.0. +

    + +

    GLX_MESA_copy_sub_buffer

    +

    +This extension adds the glXCopySubBufferMESA() function. It works +like glXSwapBuffers() but only copies a sub-region of the window +instead of the whole window. +

    +

    +GLX_MESA_copy_sub_buffer specification +

    +

    +This extension was added in Mesa 2.6 +

    + +

    Summary of X-related environment variables

    +
    +   MESA_RGB_VISUAL - specifies the X visual and depth for RGB mode (X only)
    +   MESA_CI_VISUAL - specifies the X visual and depth for CI mode (X only)
    +   MESA_BACK_BUFFER - specifies how to implement the back color buffer (X only)
    +   MESA_PRIVATE_CMAP - force aux/tk libraries to use private colormaps (X only)
    +   MESA_GAMMA - gamma correction coefficients (X only)
    +
    + + + + diff --git a/include/EGL/egl.h b/include/EGL/egl.h new file mode 100644 index 0000000..99ea342 --- /dev/null +++ b/include/EGL/egl.h @@ -0,0 +1,329 @@ +/* -*- mode: c; tab-width: 8; -*- */ +/* vi: set sw=4 ts=8: */ +/* Reference version of egl.h for EGL 1.4. + * $Revision: 9356 $ on $Date: 2009-10-21 02:52:25 -0700 (Wed, 21 Oct 2009) $ + */ + +/* +** Copyright (c) 2007-2009 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are 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 Materials. +** +** THE MATERIALS ARE 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 +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +#ifndef __egl_h_ +#define __egl_h_ + +/* All platform-dependent types and macro boilerplate (such as EGLAPI + * and EGLAPIENTRY) should go in eglplatform.h. + */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* EGL Types */ +/* EGLint is defined in eglplatform.h */ +typedef unsigned int EGLBoolean; +typedef unsigned int EGLenum; +typedef void *EGLConfig; +typedef void *EGLContext; +typedef void *EGLDisplay; +typedef void *EGLSurface; +typedef void *EGLClientBuffer; + +/* EGL Versioning */ +#define EGL_VERSION_1_0 1 +#define EGL_VERSION_1_1 1 +#define EGL_VERSION_1_2 1 +#define EGL_VERSION_1_3 1 +#define EGL_VERSION_1_4 1 + +/* EGL Enumerants. Bitmasks and other exceptional cases aside, most + * enums are assigned unique values starting at 0x3000. + */ + +/* EGL aliases */ +#define EGL_FALSE 0 +#define EGL_TRUE 1 + +/* Out-of-band handle values */ +#define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0) +#define EGL_NO_CONTEXT ((EGLContext)0) +#define EGL_NO_DISPLAY ((EGLDisplay)0) +#define EGL_NO_SURFACE ((EGLSurface)0) + +/* Out-of-band attribute value */ +#define EGL_DONT_CARE ((EGLint)-1) + +/* Errors / GetError return values */ +#define EGL_SUCCESS 0x3000 +#define EGL_NOT_INITIALIZED 0x3001 +#define EGL_BAD_ACCESS 0x3002 +#define EGL_BAD_ALLOC 0x3003 +#define EGL_BAD_ATTRIBUTE 0x3004 +#define EGL_BAD_CONFIG 0x3005 +#define EGL_BAD_CONTEXT 0x3006 +#define EGL_BAD_CURRENT_SURFACE 0x3007 +#define EGL_BAD_DISPLAY 0x3008 +#define EGL_BAD_MATCH 0x3009 +#define EGL_BAD_NATIVE_PIXMAP 0x300A +#define EGL_BAD_NATIVE_WINDOW 0x300B +#define EGL_BAD_PARAMETER 0x300C +#define EGL_BAD_SURFACE 0x300D +#define EGL_CONTEXT_LOST 0x300E /* EGL 1.1 - IMG_power_management */ + +/* Reserved 0x300F-0x301F for additional errors */ + +/* Config attributes */ +#define EGL_BUFFER_SIZE 0x3020 +#define EGL_ALPHA_SIZE 0x3021 +#define EGL_BLUE_SIZE 0x3022 +#define EGL_GREEN_SIZE 0x3023 +#define EGL_RED_SIZE 0x3024 +#define EGL_DEPTH_SIZE 0x3025 +#define EGL_STENCIL_SIZE 0x3026 +#define EGL_CONFIG_CAVEAT 0x3027 +#define EGL_CONFIG_ID 0x3028 +#define EGL_LEVEL 0x3029 +#define EGL_MAX_PBUFFER_HEIGHT 0x302A +#define EGL_MAX_PBUFFER_PIXELS 0x302B +#define EGL_MAX_PBUFFER_WIDTH 0x302C +#define EGL_NATIVE_RENDERABLE 0x302D +#define EGL_NATIVE_VISUAL_ID 0x302E +#define EGL_NATIVE_VISUAL_TYPE 0x302F +#define EGL_SAMPLES 0x3031 +#define EGL_SAMPLE_BUFFERS 0x3032 +#define EGL_SURFACE_TYPE 0x3033 +#define EGL_TRANSPARENT_TYPE 0x3034 +#define EGL_TRANSPARENT_BLUE_VALUE 0x3035 +#define EGL_TRANSPARENT_GREEN_VALUE 0x3036 +#define EGL_TRANSPARENT_RED_VALUE 0x3037 +#define EGL_NONE 0x3038 /* Attrib list terminator */ +#define EGL_BIND_TO_TEXTURE_RGB 0x3039 +#define EGL_BIND_TO_TEXTURE_RGBA 0x303A +#define EGL_MIN_SWAP_INTERVAL 0x303B +#define EGL_MAX_SWAP_INTERVAL 0x303C +#define EGL_LUMINANCE_SIZE 0x303D +#define EGL_ALPHA_MASK_SIZE 0x303E +#define EGL_COLOR_BUFFER_TYPE 0x303F +#define EGL_RENDERABLE_TYPE 0x3040 +#define EGL_MATCH_NATIVE_PIXMAP 0x3041 /* Pseudo-attribute (not queryable) */ +#define EGL_CONFORMANT 0x3042 + +/* Reserved 0x3041-0x304F for additional config attributes */ + +/* Config attribute values */ +#define EGL_SLOW_CONFIG 0x3050 /* EGL_CONFIG_CAVEAT value */ +#define EGL_NON_CONFORMANT_CONFIG 0x3051 /* EGL_CONFIG_CAVEAT value */ +#define EGL_TRANSPARENT_RGB 0x3052 /* EGL_TRANSPARENT_TYPE value */ +#define EGL_RGB_BUFFER 0x308E /* EGL_COLOR_BUFFER_TYPE value */ +#define EGL_LUMINANCE_BUFFER 0x308F /* EGL_COLOR_BUFFER_TYPE value */ + +/* More config attribute values, for EGL_TEXTURE_FORMAT */ +#define EGL_NO_TEXTURE 0x305C +#define EGL_TEXTURE_RGB 0x305D +#define EGL_TEXTURE_RGBA 0x305E +#define EGL_TEXTURE_2D 0x305F + +/* Config attribute mask bits */ +#define EGL_PBUFFER_BIT 0x0001 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_PIXMAP_BIT 0x0002 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_WINDOW_BIT 0x0004 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_VG_COLORSPACE_LINEAR_BIT 0x0020 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_VG_ALPHA_FORMAT_PRE_BIT 0x0040 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_MULTISAMPLE_RESOLVE_BOX_BIT 0x0200 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_SWAP_BEHAVIOR_PRESERVED_BIT 0x0400 /* EGL_SURFACE_TYPE mask bits */ + +#define EGL_OPENGL_ES_BIT 0x0001 /* EGL_RENDERABLE_TYPE mask bits */ +#define EGL_OPENVG_BIT 0x0002 /* EGL_RENDERABLE_TYPE mask bits */ +#define EGL_OPENGL_ES2_BIT 0x0004 /* EGL_RENDERABLE_TYPE mask bits */ +#define EGL_OPENGL_BIT 0x0008 /* EGL_RENDERABLE_TYPE mask bits */ + +/* QueryString targets */ +#define EGL_VENDOR 0x3053 +#define EGL_VERSION 0x3054 +#define EGL_EXTENSIONS 0x3055 +#define EGL_CLIENT_APIS 0x308D + +/* QuerySurface / SurfaceAttrib / CreatePbufferSurface targets */ +#define EGL_HEIGHT 0x3056 +#define EGL_WIDTH 0x3057 +#define EGL_LARGEST_PBUFFER 0x3058 +#define EGL_TEXTURE_FORMAT 0x3080 +#define EGL_TEXTURE_TARGET 0x3081 +#define EGL_MIPMAP_TEXTURE 0x3082 +#define EGL_MIPMAP_LEVEL 0x3083 +#define EGL_RENDER_BUFFER 0x3086 +#define EGL_VG_COLORSPACE 0x3087 +#define EGL_VG_ALPHA_FORMAT 0x3088 +#define EGL_HORIZONTAL_RESOLUTION 0x3090 +#define EGL_VERTICAL_RESOLUTION 0x3091 +#define EGL_PIXEL_ASPECT_RATIO 0x3092 +#define EGL_SWAP_BEHAVIOR 0x3093 +#define EGL_MULTISAMPLE_RESOLVE 0x3099 + +/* EGL_RENDER_BUFFER values / BindTexImage / ReleaseTexImage buffer targets */ +#define EGL_BACK_BUFFER 0x3084 +#define EGL_SINGLE_BUFFER 0x3085 + +/* OpenVG color spaces */ +#define EGL_VG_COLORSPACE_sRGB 0x3089 /* EGL_VG_COLORSPACE value */ +#define EGL_VG_COLORSPACE_LINEAR 0x308A /* EGL_VG_COLORSPACE value */ + +/* OpenVG alpha formats */ +#define EGL_VG_ALPHA_FORMAT_NONPRE 0x308B /* EGL_ALPHA_FORMAT value */ +#define EGL_VG_ALPHA_FORMAT_PRE 0x308C /* EGL_ALPHA_FORMAT value */ + +/* Constant scale factor by which fractional display resolutions & + * aspect ratio are scaled when queried as integer values. + */ +#define EGL_DISPLAY_SCALING 10000 + +/* Unknown display resolution/aspect ratio */ +#define EGL_UNKNOWN ((EGLint)-1) + +/* Back buffer swap behaviors */ +#define EGL_BUFFER_PRESERVED 0x3094 /* EGL_SWAP_BEHAVIOR value */ +#define EGL_BUFFER_DESTROYED 0x3095 /* EGL_SWAP_BEHAVIOR value */ + +/* CreatePbufferFromClientBuffer buffer types */ +#define EGL_OPENVG_IMAGE 0x3096 + +/* QueryContext targets */ +#define EGL_CONTEXT_CLIENT_TYPE 0x3097 + +/* CreateContext attributes */ +#define EGL_CONTEXT_CLIENT_VERSION 0x3098 + +/* Multisample resolution behaviors */ +#define EGL_MULTISAMPLE_RESOLVE_DEFAULT 0x309A /* EGL_MULTISAMPLE_RESOLVE value */ +#define EGL_MULTISAMPLE_RESOLVE_BOX 0x309B /* EGL_MULTISAMPLE_RESOLVE value */ + +/* BindAPI/QueryAPI targets */ +#define EGL_OPENGL_ES_API 0x30A0 +#define EGL_OPENVG_API 0x30A1 +#define EGL_OPENGL_API 0x30A2 + +/* GetCurrentSurface targets */ +#define EGL_DRAW 0x3059 +#define EGL_READ 0x305A + +/* WaitNative engines */ +#define EGL_CORE_NATIVE_ENGINE 0x305B + +/* EGL 1.2 tokens renamed for consistency in EGL 1.3 */ +#define EGL_COLORSPACE EGL_VG_COLORSPACE +#define EGL_ALPHA_FORMAT EGL_VG_ALPHA_FORMAT +#define EGL_COLORSPACE_sRGB EGL_VG_COLORSPACE_sRGB +#define EGL_COLORSPACE_LINEAR EGL_VG_COLORSPACE_LINEAR +#define EGL_ALPHA_FORMAT_NONPRE EGL_VG_ALPHA_FORMAT_NONPRE +#define EGL_ALPHA_FORMAT_PRE EGL_VG_ALPHA_FORMAT_PRE + +/* EGL extensions must request enum blocks from the Khronos + * API Registrar, who maintains the enumerant registry. Submit + * a bug in Khronos Bugzilla against task "Registry". + */ + + + +/* EGL Functions */ + +EGLAPI EGLint EGLAPIENTRY eglGetError(void); + +EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id); +EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor); +EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy); + +EGLAPI const char * EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name); + +EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, + EGLint config_size, EGLint *num_config); +EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, + EGLConfig *configs, EGLint config_size, + EGLint *num_config); +EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, + EGLint attribute, EGLint *value); + +EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, + EGLNativeWindowType win, + const EGLint *attrib_list); +EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list); +EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, + EGLNativePixmapType pixmap, + const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface); +EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay dpy, EGLSurface surface, + EGLint attribute, EGLint *value); + +EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api); +EGLAPI EGLenum EGLAPIENTRY eglQueryAPI(void); + +EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient(void); + +EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread(void); + +EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferFromClientBuffer( + EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, + EGLConfig config, const EGLint *attrib_list); + +EGLAPI EGLBoolean EGLAPIENTRY eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, + EGLint attribute, EGLint value); +EGLAPI EGLBoolean EGLAPIENTRY eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer); +EGLAPI EGLBoolean EGLAPIENTRY eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer); + + +EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval); + + +EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, + EGLContext share_context, + const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx); +EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, + EGLSurface read, EGLContext ctx); + +EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext(void); +EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw); +EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay(void); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext(EGLDisplay dpy, EGLContext ctx, + EGLint attribute, EGLint *value); + +EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL(void); +EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine); +EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface); +EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, + EGLNativePixmapType target); + +/* This is a generic function pointer type, whose name indicates it must + * be cast to the proper type *and calling convention* before use. + */ +typedef void (*__eglMustCastToProperFunctionPointerType)(void); + +/* Now, define eglGetProcAddress using the generic function ptr. type */ +EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY + eglGetProcAddress(const char *procname); + +#ifdef __cplusplus +} +#endif + +#endif /* __egl_h_ */ diff --git a/include/EGL/eglext.h b/include/EGL/eglext.h new file mode 100644 index 0000000..0460393 --- /dev/null +++ b/include/EGL/eglext.h @@ -0,0 +1,384 @@ +#ifndef __eglext_h_ +#define __eglext_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2010 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are 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 Materials. +** +** THE MATERIALS ARE 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 +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +#include + +/*************************************************************/ + +/* Header file version number */ +/* Current version at http://www.khronos.org/registry/egl/ */ +/* $Revision: 12124 $ on $Date: 2010-07-27 20:12:35 -0700 (Tue, 27 Jul 2010) $ */ +#define EGL_EGLEXT_VERSION 7 + +#ifndef EGL_KHR_config_attribs +#define EGL_KHR_config_attribs 1 +#define EGL_CONFORMANT_KHR 0x3042 /* EGLConfig attribute */ +#define EGL_VG_COLORSPACE_LINEAR_BIT_KHR 0x0020 /* EGL_SURFACE_TYPE bitfield */ +#define EGL_VG_ALPHA_FORMAT_PRE_BIT_KHR 0x0040 /* EGL_SURFACE_TYPE bitfield */ +#endif + +#ifndef EGL_KHR_lock_surface +#define EGL_KHR_lock_surface 1 +#define EGL_READ_SURFACE_BIT_KHR 0x0001 /* EGL_LOCK_USAGE_HINT_KHR bitfield */ +#define EGL_WRITE_SURFACE_BIT_KHR 0x0002 /* EGL_LOCK_USAGE_HINT_KHR bitfield */ +#define EGL_LOCK_SURFACE_BIT_KHR 0x0080 /* EGL_SURFACE_TYPE bitfield */ +#define EGL_OPTIMAL_FORMAT_BIT_KHR 0x0100 /* EGL_SURFACE_TYPE bitfield */ +#define EGL_MATCH_FORMAT_KHR 0x3043 /* EGLConfig attribute */ +#define EGL_FORMAT_RGB_565_EXACT_KHR 0x30C0 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_FORMAT_RGB_565_KHR 0x30C1 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_FORMAT_RGBA_8888_EXACT_KHR 0x30C2 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_FORMAT_RGBA_8888_KHR 0x30C3 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_MAP_PRESERVE_PIXELS_KHR 0x30C4 /* eglLockSurfaceKHR attribute */ +#define EGL_LOCK_USAGE_HINT_KHR 0x30C5 /* eglLockSurfaceKHR attribute */ +#define EGL_BITMAP_POINTER_KHR 0x30C6 /* eglQuerySurface attribute */ +#define EGL_BITMAP_PITCH_KHR 0x30C7 /* eglQuerySurface attribute */ +#define EGL_BITMAP_ORIGIN_KHR 0x30C8 /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_RED_OFFSET_KHR 0x30C9 /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR 0x30CA /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR 0x30CB /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR 0x30CC /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_LUMINANCE_OFFSET_KHR 0x30CD /* eglQuerySurface attribute */ +#define EGL_LOWER_LEFT_KHR 0x30CE /* EGL_BITMAP_ORIGIN_KHR value */ +#define EGL_UPPER_LEFT_KHR 0x30CF /* EGL_BITMAP_ORIGIN_KHR value */ +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglLockSurfaceKHR (EGLDisplay display, EGLSurface surface, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglUnlockSurfaceKHR (EGLDisplay display, EGLSurface surface); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLBoolean (EGLAPIENTRYP PFNEGLLOCKSURFACEKHRPROC) (EGLDisplay display, EGLSurface surface, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNLOCKSURFACEKHRPROC) (EGLDisplay display, EGLSurface surface); +#endif + +#ifndef EGL_KHR_image +#define EGL_KHR_image 1 +#define EGL_NATIVE_PIXMAP_KHR 0x30B0 /* eglCreateImageKHR target */ +typedef void *EGLImageKHR; +#define EGL_NO_IMAGE_KHR ((EGLImageKHR)0) +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLImageKHR EGLAPIENTRY eglCreateImageKHR (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImageKHR (EGLDisplay dpy, EGLImageKHR image); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image); +#endif + +#ifndef EGL_KHR_vg_parent_image +#define EGL_KHR_vg_parent_image 1 +#define EGL_VG_PARENT_IMAGE_KHR 0x30BA /* eglCreateImageKHR target */ +#endif + +#ifndef EGL_KHR_gl_texture_2D_image +#define EGL_KHR_gl_texture_2D_image 1 +#define EGL_GL_TEXTURE_2D_KHR 0x30B1 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_LEVEL_KHR 0x30BC /* eglCreateImageKHR attribute */ +#endif + +#ifndef EGL_KHR_gl_texture_cubemap_image +#define EGL_KHR_gl_texture_cubemap_image 1 +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR 0x30B3 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR 0x30B4 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR 0x30B5 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR 0x30B6 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR 0x30B7 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR 0x30B8 /* eglCreateImageKHR target */ +#endif + +#ifndef EGL_KHR_gl_texture_3D_image +#define EGL_KHR_gl_texture_3D_image 1 +#define EGL_GL_TEXTURE_3D_KHR 0x30B2 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_ZOFFSET_KHR 0x30BD /* eglCreateImageKHR attribute */ +#endif + +#ifndef EGL_KHR_gl_renderbuffer_image +#define EGL_KHR_gl_renderbuffer_image 1 +#define EGL_GL_RENDERBUFFER_KHR 0x30B9 /* eglCreateImageKHR target */ +#endif + +#ifndef EGL_MESA_drm_image +#define EGL_MESA_drm_image 1 +#define EGL_DRM_BUFFER_FORMAT_MESA 0x31D0 /* eglCreateImageKHR attribute */ +#define EGL_DRM_BUFFER_USE_MESA 0x31D1 + +/* EGL_DRM_BUFFER_FORMAT_MESA tokens */ +#define EGL_DRM_BUFFER_FORMAT_ARGB32_MESA 0x31D2 + +/* EGL_DRM_BUFFER_USE_MESA bits */ +#define EGL_DRM_BUFFER_USE_SCANOUT_MESA 0x0001 +#define EGL_DRM_BUFFER_USE_SHARE_MESA 0x0002 + +#define EGL_DRM_BUFFER_MESA 0x31D3 /* eglCreateImageKHR target */ +#define EGL_DRM_BUFFER_STRIDE_MESA 0x31D4 /* eglCreateImageKHR attribute */ + +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLImageKHR EGLAPIENTRY eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglExportDRMImageMESA(EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride); +#endif +typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEDRMIMAGEMESA) (EGLDisplay dpy, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDRMIMAGEMESA) (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride); +#endif + +#if KHRONOS_SUPPORT_INT64 /* EGLTimeKHR requires 64-bit uint support */ +#ifndef EGL_KHR_reusable_sync +#define EGL_KHR_reusable_sync 1 + +typedef void* EGLSyncKHR; +typedef khronos_utime_nanoseconds_t EGLTimeKHR; + +#define EGL_SYNC_STATUS_KHR 0x30F1 +#define EGL_SIGNALED_KHR 0x30F2 +#define EGL_UNSIGNALED_KHR 0x30F3 +#define EGL_TIMEOUT_EXPIRED_KHR 0x30F5 +#define EGL_CONDITION_SATISFIED_KHR 0x30F6 +#define EGL_SYNC_TYPE_KHR 0x30F7 +#define EGL_SYNC_REUSABLE_KHR 0x30FA +#define EGL_SYNC_FLUSH_COMMANDS_BIT_KHR 0x0001 /* eglClientWaitSyncKHR bitfield */ +#define EGL_FOREVER_KHR 0xFFFFFFFFFFFFFFFFull +#define EGL_NO_SYNC_KHR ((EGLSyncKHR)0) +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync); +EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout); +EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); +EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNCKHRPROC) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync); +typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value); +#endif +#endif + +/* EGL_MESA_screen extension >>> PRELIMINARY <<< */ +#ifndef EGL_MESA_screen_surface +#define EGL_MESA_screen_surface 1 + +#define EGL_BAD_SCREEN_MESA 0x4000 +#define EGL_BAD_MODE_MESA 0x4001 +#define EGL_SCREEN_COUNT_MESA 0x4002 +#define EGL_SCREEN_POSITION_MESA 0x4003 +#define EGL_SCREEN_POSITION_GRANULARITY_MESA 0x4004 +#define EGL_MODE_ID_MESA 0x4005 +#define EGL_REFRESH_RATE_MESA 0x4006 +#define EGL_OPTIMAL_MESA 0x4007 +#define EGL_INTERLACED_MESA 0x4008 +#define EGL_SCREEN_BIT_MESA 0x08 + +typedef khronos_uint32_t EGLScreenMESA; +typedef khronos_uint32_t EGLModeMESA; + +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglChooseModeMESA(EGLDisplay dpy, EGLScreenMESA screen, const EGLint *attrib_list, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes); +EGLAPI EGLBoolean EGLAPIENTRY eglGetModesMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes); +EGLAPI EGLBoolean EGLAPIENTRY eglGetModeAttribMESA(EGLDisplay dpy, EGLModeMESA mode, EGLint attribute, EGLint *value); +EGLAPI EGLBoolean EGLAPIENTRY eglGetScreensMESA(EGLDisplay dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens); +EGLAPI EGLSurface EGLAPIENTRY eglCreateScreenSurfaceMESA(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglShowScreenSurfaceMESA(EGLDisplay dpy, EGLint screen, EGLSurface surface, EGLModeMESA mode); +EGLAPI EGLBoolean EGLAPIENTRY eglScreenPositionMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryScreenMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLint attribute, EGLint *value); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryScreenSurfaceMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLSurface *surface); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryScreenModeMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode); +EGLAPI const char * EGLAPIENTRY eglQueryModeStringMESA(EGLDisplay dpy, EGLModeMESA mode); +#endif /* EGL_EGLEXT_PROTOTYPES */ + +typedef EGLBoolean (EGLAPIENTRYP PFNEGLCHOOSEMODEMESA) (EGLDisplay dpy, EGLScreenMESA screen, const EGLint *attrib_list, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETMODESMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLGetModeATTRIBMESA) (EGLDisplay dpy, EGLModeMESA mode, EGLint attribute, EGLint *value); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSCRREENSMESA) (EGLDisplay dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens); +typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATESCREENSURFACEMESA) (EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSHOWSCREENSURFACEMESA) (EGLDisplay dpy, EGLint screen, EGLSurface surface, EGLModeMESA mode); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSCREENPOSIITONMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSCREENMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLint attribute, EGLint *value); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSCREENSURFACEMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLSurface *surface); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSCREENMODEMESA) (EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode); +typedef const char * (EGLAPIENTRYP PFNEGLQUERYMODESTRINGMESA) (EGLDisplay dpy, EGLModeMESA mode); + +#endif /* EGL_MESA_screen_surface */ + + +#ifndef EGL_MESA_copy_context +#define EGL_MESA_copy_context 1 + +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglCopyContextMESA(EGLDisplay dpy, EGLContext source, EGLContext dest, EGLint mask); +#endif /* EGL_EGLEXT_PROTOTYPES */ + +typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOPYCONTEXTMESA) (EGLDisplay dpy, EGLContext source, EGLContext dest, EGLint mask); + +#endif /* EGL_MESA_copy_context */ + +#ifndef EGL_MESA_drm_display +#define EGL_MESA_drm_display 1 + +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLDisplay EGLAPIENTRY eglGetDRMDisplayMESA(int fd); +#endif /* EGL_EGLEXT_PROTOTYPES */ + +typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETDRMDISPLAYMESA) (int fd); + +#endif /* EGL_MESA_drm_display */ + +#ifndef EGL_KHR_image_base +#define EGL_KHR_image_base 1 +/* Most interfaces defined by EGL_KHR_image_pixmap above */ +#define EGL_IMAGE_PRESERVED_KHR 0x30D2 /* eglCreateImageKHR attribute */ +#endif + +#ifndef EGL_KHR_image_pixmap +#define EGL_KHR_image_pixmap 1 +/* Interfaces defined by EGL_KHR_image above */ +#endif + +#ifndef EGL_IMG_context_priority +#define EGL_IMG_context_priority 1 +#define EGL_CONTEXT_PRIORITY_LEVEL_IMG 0x3100 +#define EGL_CONTEXT_PRIORITY_HIGH_IMG 0x3101 +#define EGL_CONTEXT_PRIORITY_MEDIUM_IMG 0x3102 +#define EGL_CONTEXT_PRIORITY_LOW_IMG 0x3103 +#endif + +#ifndef EGL_KHR_lock_surface2 +#define EGL_KHR_lock_surface2 1 +#define EGL_BITMAP_PIXEL_SIZE_KHR 0x3110 +#endif + +#ifndef EGL_NV_coverage_sample +#define EGL_NV_coverage_sample 1 +#define EGL_COVERAGE_BUFFERS_NV 0x30E0 +#define EGL_COVERAGE_SAMPLES_NV 0x30E1 +#endif + +#ifndef EGL_NV_depth_nonlinear +#define EGL_NV_depth_nonlinear 1 +#define EGL_DEPTH_ENCODING_NV 0x30E2 +#define EGL_DEPTH_ENCODING_NONE_NV 0 +#define EGL_DEPTH_ENCODING_NONLINEAR_NV 0x30E3 +#endif + +#if KHRONOS_SUPPORT_INT64 /* EGLTimeNV requires 64-bit uint support */ +#ifndef EGL_NV_sync +#define EGL_NV_sync 1 +#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_NV 0x30E6 +#define EGL_SYNC_STATUS_NV 0x30E7 +#define EGL_SIGNALED_NV 0x30E8 +#define EGL_UNSIGNALED_NV 0x30E9 +#define EGL_SYNC_FLUSH_COMMANDS_BIT_NV 0x0001 +#define EGL_FOREVER_NV 0xFFFFFFFFFFFFFFFFull +#define EGL_ALREADY_SIGNALED_NV 0x30EA +#define EGL_TIMEOUT_EXPIRED_NV 0x30EB +#define EGL_CONDITION_SATISFIED_NV 0x30EC +#define EGL_SYNC_TYPE_NV 0x30ED +#define EGL_SYNC_CONDITION_NV 0x30EE +#define EGL_SYNC_FENCE_NV 0x30EF +#define EGL_NO_SYNC_NV ((EGLSyncNV)0) +typedef void* EGLSyncNV; +typedef khronos_utime_nanoseconds_t EGLTimeNV; +#ifdef EGL_EGLEXT_PROTOTYPES +EGLSyncNV eglCreateFenceSyncNV (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list); +EGLBoolean eglDestroySyncNV (EGLSyncNV sync); +EGLBoolean eglFenceNV (EGLSyncNV sync); +EGLint eglClientWaitSyncNV (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout); +EGLBoolean eglSignalSyncNV (EGLSyncNV sync, EGLenum mode); +EGLBoolean eglGetSyncAttribNV (EGLSyncNV sync, EGLint attribute, EGLint *value); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLSyncNV (EGLAPIENTRYP PFNEGLCREATEFENCESYNCNVPROC) (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCNVPROC) (EGLSyncNV sync); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLFENCENVPROC) (EGLSyncNV sync); +typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCNVPROC) (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCNVPROC) (EGLSyncNV sync, EGLenum mode); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBNVPROC) (EGLSyncNV sync, EGLint attribute, EGLint *value); +#endif +#endif + +#if KHRONOS_SUPPORT_INT64 /* Dependent on EGL_KHR_reusable_sync which requires 64-bit uint support */ +#ifndef EGL_KHR_fence_sync +#define EGL_KHR_fence_sync 1 +/* Reuses most tokens and entry points from EGL_KHR_reusable_sync */ +#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR 0x30F0 +#define EGL_SYNC_CONDITION_KHR 0x30F8 +#define EGL_SYNC_FENCE_KHR 0x30F9 +#endif +#endif + +#ifndef EGL_HI_clientpixmap +#define EGL_HI_clientpixmap 1 + +/* Surface Attribute */ +#define EGL_CLIENT_PIXMAP_POINTER_HI 0x8F74 +/* + * Structure representing a client pixmap + * (pixmap's data is in client-space memory). + */ +struct EGLClientPixmapHI +{ + void* pData; + EGLint iWidth; + EGLint iHeight; + EGLint iStride; +}; + +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurfaceHI(EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI* pixmap); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPIXMAPSURFACEHIPROC) (EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI* pixmap); +#endif /* EGL_HI_clientpixmap */ + +#ifndef EGL_HI_colorformats +#define EGL_HI_colorformats 1 +/* Config Attribute */ +#define EGL_COLOR_FORMAT_HI 0x8F70 +/* Color Formats */ +#define EGL_COLOR_RGB_HI 0x8F71 +#define EGL_COLOR_RGBA_HI 0x8F72 +#define EGL_COLOR_ARGB_HI 0x8F73 +#endif /* EGL_HI_colorformats */ + +#ifndef EGL_NOK_swap_region +#define EGL_NOK_swap_region 1 + +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint* rects); +#endif + +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOK) (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint* rects); +#endif + + +#ifndef EGL_NOK_texture_from_pixmap +#define EGL_NOK_texture_from_pixmap 1 + +#define EGL_Y_INVERTED_NOK 0x307F +#endif /* EGL_NOK_texture_from_pixmap */ + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/EGL/eglplatform.h b/include/EGL/eglplatform.h new file mode 100644 index 0000000..33a3e5f --- /dev/null +++ b/include/EGL/eglplatform.h @@ -0,0 +1,120 @@ +#ifndef __eglplatform_h_ +#define __eglplatform_h_ + +/* +** Copyright (c) 2007-2009 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are 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 Materials. +** +** THE MATERIALS ARE 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 +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Platform-specific types and definitions for egl.h + * $Revision: 9724 $ on $Date: 2009-12-02 02:05:33 -0800 (Wed, 02 Dec 2009) $ + * + * Adopters may modify khrplatform.h and this file to suit their platform. + * You are encouraged to submit all modifications to the Khronos group so that + * they can be included in future versions of this file. Please submit changes + * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) + * by filing a bug against product "EGL" component "Registry". + */ + +#include + +/* Macros used in EGL function prototype declarations. + * + * EGL functions should be prototyped as: + * + * EGLAPI return-type EGLAPIENTRY eglFunction(arguments); + * typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments); + * + * KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h + */ + +#ifndef EGLAPI +#define EGLAPI KHRONOS_APICALL +#endif + +#ifndef EGLAPIENTRY +#define EGLAPIENTRY KHRONOS_APIENTRY +#endif +#define EGLAPIENTRYP EGLAPIENTRY* + +/* The types NativeDisplayType, NativeWindowType, and NativePixmapType + * are aliases of window-system-dependent types, such as X Display * or + * Windows Device Context. They must be defined in platform-specific + * code below. The EGL-prefixed versions of Native*Type are the same + * types, renamed in EGL 1.3 so all types in the API start with "EGL". + */ + +#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */ +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#include + +typedef HDC EGLNativeDisplayType; +typedef HBITMAP EGLNativePixmapType; +typedef HWND EGLNativeWindowType; + +#elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */ + +typedef int EGLNativeDisplayType; +typedef void *EGLNativeWindowType; +typedef void *EGLNativePixmapType; + +#elif defined(__unix__) || defined(__unix) + +#ifdef MESA_EGL_NO_X11_HEADERS + +typedef void *EGLNativeDisplayType; +typedef khronos_uint32_t EGLNativePixmapType; +typedef khronos_uint32_t EGLNativeWindowType; + +#else + +/* X11 (tentative) */ +#include +#include + +typedef Display *EGLNativeDisplayType; +typedef Pixmap EGLNativePixmapType; +typedef Window EGLNativeWindowType; + +#endif /* MESA_EGL_NO_X11_HEADERS */ + +#else +#error "Platform not recognized" +#endif + +/* EGL 1.2 types, renamed for consistency in EGL 1.3 */ +typedef EGLNativeDisplayType NativeDisplayType; +typedef EGLNativePixmapType NativePixmapType; +typedef EGLNativeWindowType NativeWindowType; + + +/* Define EGLint. This must be a signed integral type large enough to contain + * all legal attribute names and values passed into and out of EGL, whether + * their type is boolean, bitmask, enumerant (symbolic constant), integer, + * handle, or other. While in general a 32-bit integer will suffice, if + * handles are 64 bit types, then EGLint should be defined as a signed 64-bit + * integer type. + */ +typedef khronos_int32_t EGLint; + +#endif /* __eglplatform_h */ diff --git a/include/GL/gl.h b/include/GL/gl.h new file mode 100644 index 0000000..8e5f138 --- /dev/null +++ b/include/GL/gl.h @@ -0,0 +1,2241 @@ +/* + * Mesa 3-D graphics library + * Version: 7.6 + * + * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 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 + * 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. + */ + + +#ifndef __gl_h_ +#define __gl_h_ + +#if defined(USE_MGL_NAMESPACE) +#include "gl_mangle.h" +#endif + + +/********************************************************************** + * Begin system-specific stuff. Do not do any of this when building + * for SciTech SNAP, as this is all done before this header file is + * included. + */ +#if !defined(__SCITECH_SNAP__) + +#if defined(__BEOS__) +#include /* to get some BeOS-isms */ +#endif + +#if !defined(OPENSTEP) && (defined(NeXT) || defined(NeXT_PDO)) +#define OPENSTEP +#endif + +#if defined(_WIN32) && !defined(__WIN32__) && !defined(__CYGWIN__) +#define __WIN32__ +#endif + +#if !defined(OPENSTEP) && (defined(__WIN32__) && !defined(__CYGWIN__)) +# if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(BUILD_GL32) /* tag specify we're building mesa as a DLL */ +# define GLAPI __declspec(dllexport) +# elif (defined(_MSC_VER) || defined(__MINGW32__)) && defined(_DLL) /* tag specifying we're building for DLL runtime support */ +# define GLAPI __declspec(dllimport) +# else /* for use with static link lib build of Win32 edition only */ +# define GLAPI extern +# endif /* _STATIC_MESA support */ +# if defined(__MINGW32__) && defined(GL_NO_STDCALL) || defined(UNDER_CE) /* The generated DLLs by MingW with STDCALL are not compatible with the ones done by Microsoft's compilers */ +# define GLAPIENTRY +# else +# define GLAPIENTRY __stdcall +# endif +#elif defined(__CYGWIN__) && defined(USE_OPENGL32) /* use native windows opengl32 */ +# define GLAPI extern +# define GLAPIENTRY __stdcall +#elif defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define GLAPI __attribute__((visibility("default"))) +# define GLAPIENTRY +#endif /* WIN32 && !CYGWIN */ + +#if (defined(__BEOS__) && defined(__POWERPC__)) || defined(__QUICKDRAW__) +# define PRAGMA_EXPORT_SUPPORTED 1 +#endif + +/* + * WINDOWS: Include windows.h here to define APIENTRY. + * It is also useful when applications include this file by + * including only glut.h, since glut.h depends on windows.h. + * Applications needing to include windows.h with parms other + * than "WIN32_LEAN_AND_MEAN" may include windows.h before + * glut.h or gl.h. + */ +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#include +#endif + +#if defined(_WIN32) && !defined(_WINGDI_) && !defined(_WIN32_WCE) \ + && !defined(_GNU_H_WINDOWS32_DEFINES) && !defined(OPENSTEP) \ + && !defined(__CYGWIN__) || defined(__MINGW32__) +#include +#endif + +#if defined(macintosh) && PRAGMA_IMPORT_SUPPORTED +#pragma import on +#endif + +#ifndef GLAPI +#define GLAPI extern +#endif + +#ifndef GLAPIENTRY +#define GLAPIENTRY +#endif + +#ifndef APIENTRY +#define APIENTRY GLAPIENTRY +#endif + +/* "P" suffix to be used for a pointer to a function */ +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif + +#ifndef GLAPIENTRYP +#define GLAPIENTRYP GLAPIENTRY * +#endif + +#ifdef CENTERLINE_CLPP +#define signed +#endif + +#if defined(PRAGMA_EXPORT_SUPPORTED) +#pragma export on +#endif + +#endif /* !__SCITECH_SNAP__ */ +/* + * End system-specific stuff. + **********************************************************************/ + + + +#ifdef __cplusplus +extern "C" { +#endif + + + +#define GL_VERSION_1_1 1 +#define GL_VERSION_1_2 1 +#define GL_VERSION_1_3 1 +#define GL_ARB_imaging 1 + + +/* + * Datatypes + */ +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef void GLvoid; +typedef signed char GLbyte; /* 1-byte signed */ +typedef short GLshort; /* 2-byte signed */ +typedef int GLint; /* 4-byte signed */ +typedef unsigned char GLubyte; /* 1-byte unsigned */ +typedef unsigned short GLushort; /* 2-byte unsigned */ +typedef unsigned int GLuint; /* 4-byte unsigned */ +typedef int GLsizei; /* 4-byte signed */ +typedef float GLfloat; /* single precision float */ +typedef float GLclampf; /* single precision float in [0,1] */ +typedef double GLdouble; /* double precision float */ +typedef double GLclampd; /* double precision float in [0,1] */ + + + +/* + * Constants + */ + +/* Boolean values */ +#define GL_FALSE 0x0 +#define GL_TRUE 0x1 + +/* Data types */ +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_INT 0x1404 +#define GL_UNSIGNED_INT 0x1405 +#define GL_FLOAT 0x1406 +#define GL_2_BYTES 0x1407 +#define GL_3_BYTES 0x1408 +#define GL_4_BYTES 0x1409 +#define GL_DOUBLE 0x140A + +/* Primitives */ +#define GL_POINTS 0x0000 +#define GL_LINES 0x0001 +#define GL_LINE_LOOP 0x0002 +#define GL_LINE_STRIP 0x0003 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_TRIANGLE_FAN 0x0006 +#define GL_QUADS 0x0007 +#define GL_QUAD_STRIP 0x0008 +#define GL_POLYGON 0x0009 + +/* Vertex Arrays */ +#define GL_VERTEX_ARRAY 0x8074 +#define GL_NORMAL_ARRAY 0x8075 +#define GL_COLOR_ARRAY 0x8076 +#define GL_INDEX_ARRAY 0x8077 +#define GL_TEXTURE_COORD_ARRAY 0x8078 +#define GL_EDGE_FLAG_ARRAY 0x8079 +#define GL_VERTEX_ARRAY_SIZE 0x807A +#define GL_VERTEX_ARRAY_TYPE 0x807B +#define GL_VERTEX_ARRAY_STRIDE 0x807C +#define GL_NORMAL_ARRAY_TYPE 0x807E +#define GL_NORMAL_ARRAY_STRIDE 0x807F +#define GL_COLOR_ARRAY_SIZE 0x8081 +#define GL_COLOR_ARRAY_TYPE 0x8082 +#define GL_COLOR_ARRAY_STRIDE 0x8083 +#define GL_INDEX_ARRAY_TYPE 0x8085 +#define GL_INDEX_ARRAY_STRIDE 0x8086 +#define GL_TEXTURE_COORD_ARRAY_SIZE 0x8088 +#define GL_TEXTURE_COORD_ARRAY_TYPE 0x8089 +#define GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A +#define GL_EDGE_FLAG_ARRAY_STRIDE 0x808C +#define GL_VERTEX_ARRAY_POINTER 0x808E +#define GL_NORMAL_ARRAY_POINTER 0x808F +#define GL_COLOR_ARRAY_POINTER 0x8090 +#define GL_INDEX_ARRAY_POINTER 0x8091 +#define GL_TEXTURE_COORD_ARRAY_POINTER 0x8092 +#define GL_EDGE_FLAG_ARRAY_POINTER 0x8093 +#define GL_V2F 0x2A20 +#define GL_V3F 0x2A21 +#define GL_C4UB_V2F 0x2A22 +#define GL_C4UB_V3F 0x2A23 +#define GL_C3F_V3F 0x2A24 +#define GL_N3F_V3F 0x2A25 +#define GL_C4F_N3F_V3F 0x2A26 +#define GL_T2F_V3F 0x2A27 +#define GL_T4F_V4F 0x2A28 +#define GL_T2F_C4UB_V3F 0x2A29 +#define GL_T2F_C3F_V3F 0x2A2A +#define GL_T2F_N3F_V3F 0x2A2B +#define GL_T2F_C4F_N3F_V3F 0x2A2C +#define GL_T4F_C4F_N3F_V4F 0x2A2D + +/* Matrix Mode */ +#define GL_MATRIX_MODE 0x0BA0 +#define GL_MODELVIEW 0x1700 +#define GL_PROJECTION 0x1701 +#define GL_TEXTURE 0x1702 + +/* Points */ +#define GL_POINT_SMOOTH 0x0B10 +#define GL_POINT_SIZE 0x0B11 +#define GL_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_POINT_SIZE_RANGE 0x0B12 + +/* Lines */ +#define GL_LINE_SMOOTH 0x0B20 +#define GL_LINE_STIPPLE 0x0B24 +#define GL_LINE_STIPPLE_PATTERN 0x0B25 +#define GL_LINE_STIPPLE_REPEAT 0x0B26 +#define GL_LINE_WIDTH 0x0B21 +#define GL_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_LINE_WIDTH_RANGE 0x0B22 + +/* Polygons */ +#define GL_POINT 0x1B00 +#define GL_LINE 0x1B01 +#define GL_FILL 0x1B02 +#define GL_CW 0x0900 +#define GL_CCW 0x0901 +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_POLYGON_MODE 0x0B40 +#define GL_POLYGON_SMOOTH 0x0B41 +#define GL_POLYGON_STIPPLE 0x0B42 +#define GL_EDGE_FLAG 0x0B43 +#define GL_CULL_FACE 0x0B44 +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +#define GL_POLYGON_OFFSET_POINT 0x2A01 +#define GL_POLYGON_OFFSET_LINE 0x2A02 +#define GL_POLYGON_OFFSET_FILL 0x8037 + +/* Display Lists */ +#define GL_COMPILE 0x1300 +#define GL_COMPILE_AND_EXECUTE 0x1301 +#define GL_LIST_BASE 0x0B32 +#define GL_LIST_INDEX 0x0B33 +#define GL_LIST_MODE 0x0B30 + +/* Depth buffer */ +#define GL_NEVER 0x0200 +#define GL_LESS 0x0201 +#define GL_EQUAL 0x0202 +#define GL_LEQUAL 0x0203 +#define GL_GREATER 0x0204 +#define GL_NOTEQUAL 0x0205 +#define GL_GEQUAL 0x0206 +#define GL_ALWAYS 0x0207 +#define GL_DEPTH_TEST 0x0B71 +#define GL_DEPTH_BITS 0x0D56 +#define GL_DEPTH_CLEAR_VALUE 0x0B73 +#define GL_DEPTH_FUNC 0x0B74 +#define GL_DEPTH_RANGE 0x0B70 +#define GL_DEPTH_WRITEMASK 0x0B72 +#define GL_DEPTH_COMPONENT 0x1902 + +/* Lighting */ +#define GL_LIGHTING 0x0B50 +#define GL_LIGHT0 0x4000 +#define GL_LIGHT1 0x4001 +#define GL_LIGHT2 0x4002 +#define GL_LIGHT3 0x4003 +#define GL_LIGHT4 0x4004 +#define GL_LIGHT5 0x4005 +#define GL_LIGHT6 0x4006 +#define GL_LIGHT7 0x4007 +#define GL_SPOT_EXPONENT 0x1205 +#define GL_SPOT_CUTOFF 0x1206 +#define GL_CONSTANT_ATTENUATION 0x1207 +#define GL_LINEAR_ATTENUATION 0x1208 +#define GL_QUADRATIC_ATTENUATION 0x1209 +#define GL_AMBIENT 0x1200 +#define GL_DIFFUSE 0x1201 +#define GL_SPECULAR 0x1202 +#define GL_SHININESS 0x1601 +#define GL_EMISSION 0x1600 +#define GL_POSITION 0x1203 +#define GL_SPOT_DIRECTION 0x1204 +#define GL_AMBIENT_AND_DIFFUSE 0x1602 +#define GL_COLOR_INDEXES 0x1603 +#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52 +#define GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51 +#define GL_LIGHT_MODEL_AMBIENT 0x0B53 +#define GL_FRONT_AND_BACK 0x0408 +#define GL_SHADE_MODEL 0x0B54 +#define GL_FLAT 0x1D00 +#define GL_SMOOTH 0x1D01 +#define GL_COLOR_MATERIAL 0x0B57 +#define GL_COLOR_MATERIAL_FACE 0x0B55 +#define GL_COLOR_MATERIAL_PARAMETER 0x0B56 +#define GL_NORMALIZE 0x0BA1 + +/* User clipping planes */ +#define GL_CLIP_PLANE0 0x3000 +#define GL_CLIP_PLANE1 0x3001 +#define GL_CLIP_PLANE2 0x3002 +#define GL_CLIP_PLANE3 0x3003 +#define GL_CLIP_PLANE4 0x3004 +#define GL_CLIP_PLANE5 0x3005 + +/* Accumulation buffer */ +#define GL_ACCUM_RED_BITS 0x0D58 +#define GL_ACCUM_GREEN_BITS 0x0D59 +#define GL_ACCUM_BLUE_BITS 0x0D5A +#define GL_ACCUM_ALPHA_BITS 0x0D5B +#define GL_ACCUM_CLEAR_VALUE 0x0B80 +#define GL_ACCUM 0x0100 +#define GL_ADD 0x0104 +#define GL_LOAD 0x0101 +#define GL_MULT 0x0103 +#define GL_RETURN 0x0102 + +/* Alpha testing */ +#define GL_ALPHA_TEST 0x0BC0 +#define GL_ALPHA_TEST_REF 0x0BC2 +#define GL_ALPHA_TEST_FUNC 0x0BC1 + +/* Blending */ +#define GL_BLEND 0x0BE2 +#define GL_BLEND_SRC 0x0BE1 +#define GL_BLEND_DST 0x0BE0 +#define GL_ZERO 0x0 +#define GL_ONE 0x1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 + +/* Render Mode */ +#define GL_FEEDBACK 0x1C01 +#define GL_RENDER 0x1C00 +#define GL_SELECT 0x1C02 + +/* Feedback */ +#define GL_2D 0x0600 +#define GL_3D 0x0601 +#define GL_3D_COLOR 0x0602 +#define GL_3D_COLOR_TEXTURE 0x0603 +#define GL_4D_COLOR_TEXTURE 0x0604 +#define GL_POINT_TOKEN 0x0701 +#define GL_LINE_TOKEN 0x0702 +#define GL_LINE_RESET_TOKEN 0x0707 +#define GL_POLYGON_TOKEN 0x0703 +#define GL_BITMAP_TOKEN 0x0704 +#define GL_DRAW_PIXEL_TOKEN 0x0705 +#define GL_COPY_PIXEL_TOKEN 0x0706 +#define GL_PASS_THROUGH_TOKEN 0x0700 +#define GL_FEEDBACK_BUFFER_POINTER 0x0DF0 +#define GL_FEEDBACK_BUFFER_SIZE 0x0DF1 +#define GL_FEEDBACK_BUFFER_TYPE 0x0DF2 + +/* Selection */ +#define GL_SELECTION_BUFFER_POINTER 0x0DF3 +#define GL_SELECTION_BUFFER_SIZE 0x0DF4 + +/* Fog */ +#define GL_FOG 0x0B60 +#define GL_FOG_MODE 0x0B65 +#define GL_FOG_DENSITY 0x0B62 +#define GL_FOG_COLOR 0x0B66 +#define GL_FOG_INDEX 0x0B61 +#define GL_FOG_START 0x0B63 +#define GL_FOG_END 0x0B64 +#define GL_LINEAR 0x2601 +#define GL_EXP 0x0800 +#define GL_EXP2 0x0801 + +/* Logic Ops */ +#define GL_LOGIC_OP 0x0BF1 +#define GL_INDEX_LOGIC_OP 0x0BF1 +#define GL_COLOR_LOGIC_OP 0x0BF2 +#define GL_LOGIC_OP_MODE 0x0BF0 +#define GL_CLEAR 0x1500 +#define GL_SET 0x150F +#define GL_COPY 0x1503 +#define GL_COPY_INVERTED 0x150C +#define GL_NOOP 0x1505 +#define GL_INVERT 0x150A +#define GL_AND 0x1501 +#define GL_NAND 0x150E +#define GL_OR 0x1507 +#define GL_NOR 0x1508 +#define GL_XOR 0x1506 +#define GL_EQUIV 0x1509 +#define GL_AND_REVERSE 0x1502 +#define GL_AND_INVERTED 0x1504 +#define GL_OR_REVERSE 0x150B +#define GL_OR_INVERTED 0x150D + +/* Stencil */ +#define GL_STENCIL_BITS 0x0D57 +#define GL_STENCIL_TEST 0x0B90 +#define GL_STENCIL_CLEAR_VALUE 0x0B91 +#define GL_STENCIL_FUNC 0x0B92 +#define GL_STENCIL_VALUE_MASK 0x0B93 +#define GL_STENCIL_FAIL 0x0B94 +#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 +#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 +#define GL_STENCIL_REF 0x0B97 +#define GL_STENCIL_WRITEMASK 0x0B98 +#define GL_STENCIL_INDEX 0x1901 +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 + +/* Buffers, Pixel Drawing/Reading */ +#define GL_NONE 0x0 +#define GL_LEFT 0x0406 +#define GL_RIGHT 0x0407 +/*GL_FRONT 0x0404 */ +/*GL_BACK 0x0405 */ +/*GL_FRONT_AND_BACK 0x0408 */ +#define GL_FRONT_LEFT 0x0400 +#define GL_FRONT_RIGHT 0x0401 +#define GL_BACK_LEFT 0x0402 +#define GL_BACK_RIGHT 0x0403 +#define GL_AUX0 0x0409 +#define GL_AUX1 0x040A +#define GL_AUX2 0x040B +#define GL_AUX3 0x040C +#define GL_COLOR_INDEX 0x1900 +#define GL_RED 0x1903 +#define GL_GREEN 0x1904 +#define GL_BLUE 0x1905 +#define GL_ALPHA 0x1906 +#define GL_LUMINANCE 0x1909 +#define GL_LUMINANCE_ALPHA 0x190A +#define GL_ALPHA_BITS 0x0D55 +#define GL_RED_BITS 0x0D52 +#define GL_GREEN_BITS 0x0D53 +#define GL_BLUE_BITS 0x0D54 +#define GL_INDEX_BITS 0x0D51 +#define GL_SUBPIXEL_BITS 0x0D50 +#define GL_AUX_BUFFERS 0x0C00 +#define GL_READ_BUFFER 0x0C02 +#define GL_DRAW_BUFFER 0x0C01 +#define GL_DOUBLEBUFFER 0x0C32 +#define GL_STEREO 0x0C33 +#define GL_BITMAP 0x1A00 +#define GL_COLOR 0x1800 +#define GL_DEPTH 0x1801 +#define GL_STENCIL 0x1802 +#define GL_DITHER 0x0BD0 +#define GL_RGB 0x1907 +#define GL_RGBA 0x1908 + +/* Implementation limits */ +#define GL_MAX_LIST_NESTING 0x0B31 +#define GL_MAX_EVAL_ORDER 0x0D30 +#define GL_MAX_LIGHTS 0x0D31 +#define GL_MAX_CLIP_PLANES 0x0D32 +#define GL_MAX_TEXTURE_SIZE 0x0D33 +#define GL_MAX_PIXEL_MAP_TABLE 0x0D34 +#define GL_MAX_ATTRIB_STACK_DEPTH 0x0D35 +#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36 +#define GL_MAX_NAME_STACK_DEPTH 0x0D37 +#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38 +#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39 +#define GL_MAX_VIEWPORT_DIMS 0x0D3A +#define GL_MAX_CLIENT_ATTRIB_STACK_DEPTH 0x0D3B + +/* Gets */ +#define GL_ATTRIB_STACK_DEPTH 0x0BB0 +#define GL_CLIENT_ATTRIB_STACK_DEPTH 0x0BB1 +#define GL_COLOR_CLEAR_VALUE 0x0C22 +#define GL_COLOR_WRITEMASK 0x0C23 +#define GL_CURRENT_INDEX 0x0B01 +#define GL_CURRENT_COLOR 0x0B00 +#define GL_CURRENT_NORMAL 0x0B02 +#define GL_CURRENT_RASTER_COLOR 0x0B04 +#define GL_CURRENT_RASTER_DISTANCE 0x0B09 +#define GL_CURRENT_RASTER_INDEX 0x0B05 +#define GL_CURRENT_RASTER_POSITION 0x0B07 +#define GL_CURRENT_RASTER_TEXTURE_COORDS 0x0B06 +#define GL_CURRENT_RASTER_POSITION_VALID 0x0B08 +#define GL_CURRENT_TEXTURE_COORDS 0x0B03 +#define GL_INDEX_CLEAR_VALUE 0x0C20 +#define GL_INDEX_MODE 0x0C30 +#define GL_INDEX_WRITEMASK 0x0C21 +#define GL_MODELVIEW_MATRIX 0x0BA6 +#define GL_MODELVIEW_STACK_DEPTH 0x0BA3 +#define GL_NAME_STACK_DEPTH 0x0D70 +#define GL_PROJECTION_MATRIX 0x0BA7 +#define GL_PROJECTION_STACK_DEPTH 0x0BA4 +#define GL_RENDER_MODE 0x0C40 +#define GL_RGBA_MODE 0x0C31 +#define GL_TEXTURE_MATRIX 0x0BA8 +#define GL_TEXTURE_STACK_DEPTH 0x0BA5 +#define GL_VIEWPORT 0x0BA2 + +/* Evaluators */ +#define GL_AUTO_NORMAL 0x0D80 +#define GL_MAP1_COLOR_4 0x0D90 +#define GL_MAP1_INDEX 0x0D91 +#define GL_MAP1_NORMAL 0x0D92 +#define GL_MAP1_TEXTURE_COORD_1 0x0D93 +#define GL_MAP1_TEXTURE_COORD_2 0x0D94 +#define GL_MAP1_TEXTURE_COORD_3 0x0D95 +#define GL_MAP1_TEXTURE_COORD_4 0x0D96 +#define GL_MAP1_VERTEX_3 0x0D97 +#define GL_MAP1_VERTEX_4 0x0D98 +#define GL_MAP2_COLOR_4 0x0DB0 +#define GL_MAP2_INDEX 0x0DB1 +#define GL_MAP2_NORMAL 0x0DB2 +#define GL_MAP2_TEXTURE_COORD_1 0x0DB3 +#define GL_MAP2_TEXTURE_COORD_2 0x0DB4 +#define GL_MAP2_TEXTURE_COORD_3 0x0DB5 +#define GL_MAP2_TEXTURE_COORD_4 0x0DB6 +#define GL_MAP2_VERTEX_3 0x0DB7 +#define GL_MAP2_VERTEX_4 0x0DB8 +#define GL_MAP1_GRID_DOMAIN 0x0DD0 +#define GL_MAP1_GRID_SEGMENTS 0x0DD1 +#define GL_MAP2_GRID_DOMAIN 0x0DD2 +#define GL_MAP2_GRID_SEGMENTS 0x0DD3 +#define GL_COEFF 0x0A00 +#define GL_ORDER 0x0A01 +#define GL_DOMAIN 0x0A02 + +/* Hints */ +#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50 +#define GL_POINT_SMOOTH_HINT 0x0C51 +#define GL_LINE_SMOOTH_HINT 0x0C52 +#define GL_POLYGON_SMOOTH_HINT 0x0C53 +#define GL_FOG_HINT 0x0C54 +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 + +/* Scissor box */ +#define GL_SCISSOR_BOX 0x0C10 +#define GL_SCISSOR_TEST 0x0C11 + +/* Pixel Mode / Transfer */ +#define GL_MAP_COLOR 0x0D10 +#define GL_MAP_STENCIL 0x0D11 +#define GL_INDEX_SHIFT 0x0D12 +#define GL_INDEX_OFFSET 0x0D13 +#define GL_RED_SCALE 0x0D14 +#define GL_RED_BIAS 0x0D15 +#define GL_GREEN_SCALE 0x0D18 +#define GL_GREEN_BIAS 0x0D19 +#define GL_BLUE_SCALE 0x0D1A +#define GL_BLUE_BIAS 0x0D1B +#define GL_ALPHA_SCALE 0x0D1C +#define GL_ALPHA_BIAS 0x0D1D +#define GL_DEPTH_SCALE 0x0D1E +#define GL_DEPTH_BIAS 0x0D1F +#define GL_PIXEL_MAP_S_TO_S_SIZE 0x0CB1 +#define GL_PIXEL_MAP_I_TO_I_SIZE 0x0CB0 +#define GL_PIXEL_MAP_I_TO_R_SIZE 0x0CB2 +#define GL_PIXEL_MAP_I_TO_G_SIZE 0x0CB3 +#define GL_PIXEL_MAP_I_TO_B_SIZE 0x0CB4 +#define GL_PIXEL_MAP_I_TO_A_SIZE 0x0CB5 +#define GL_PIXEL_MAP_R_TO_R_SIZE 0x0CB6 +#define GL_PIXEL_MAP_G_TO_G_SIZE 0x0CB7 +#define GL_PIXEL_MAP_B_TO_B_SIZE 0x0CB8 +#define GL_PIXEL_MAP_A_TO_A_SIZE 0x0CB9 +#define GL_PIXEL_MAP_S_TO_S 0x0C71 +#define GL_PIXEL_MAP_I_TO_I 0x0C70 +#define GL_PIXEL_MAP_I_TO_R 0x0C72 +#define GL_PIXEL_MAP_I_TO_G 0x0C73 +#define GL_PIXEL_MAP_I_TO_B 0x0C74 +#define GL_PIXEL_MAP_I_TO_A 0x0C75 +#define GL_PIXEL_MAP_R_TO_R 0x0C76 +#define GL_PIXEL_MAP_G_TO_G 0x0C77 +#define GL_PIXEL_MAP_B_TO_B 0x0C78 +#define GL_PIXEL_MAP_A_TO_A 0x0C79 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_PACK_LSB_FIRST 0x0D01 +#define GL_PACK_ROW_LENGTH 0x0D02 +#define GL_PACK_SKIP_PIXELS 0x0D04 +#define GL_PACK_SKIP_ROWS 0x0D03 +#define GL_PACK_SWAP_BYTES 0x0D00 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_UNPACK_LSB_FIRST 0x0CF1 +#define GL_UNPACK_ROW_LENGTH 0x0CF2 +#define GL_UNPACK_SKIP_PIXELS 0x0CF4 +#define GL_UNPACK_SKIP_ROWS 0x0CF3 +#define GL_UNPACK_SWAP_BYTES 0x0CF0 +#define GL_ZOOM_X 0x0D16 +#define GL_ZOOM_Y 0x0D17 + +/* Texture mapping */ +#define GL_TEXTURE_ENV 0x2300 +#define GL_TEXTURE_ENV_MODE 0x2200 +#define GL_TEXTURE_1D 0x0DE0 +#define GL_TEXTURE_2D 0x0DE1 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_ENV_COLOR 0x2201 +#define GL_TEXTURE_GEN_S 0x0C60 +#define GL_TEXTURE_GEN_T 0x0C61 +#define GL_TEXTURE_GEN_MODE 0x2500 +#define GL_TEXTURE_BORDER_COLOR 0x1004 +#define GL_TEXTURE_WIDTH 0x1000 +#define GL_TEXTURE_HEIGHT 0x1001 +#define GL_TEXTURE_BORDER 0x1005 +#define GL_TEXTURE_COMPONENTS 0x1003 +#define GL_TEXTURE_RED_SIZE 0x805C +#define GL_TEXTURE_GREEN_SIZE 0x805D +#define GL_TEXTURE_BLUE_SIZE 0x805E +#define GL_TEXTURE_ALPHA_SIZE 0x805F +#define GL_TEXTURE_LUMINANCE_SIZE 0x8060 +#define GL_TEXTURE_INTENSITY_SIZE 0x8061 +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 +#define GL_OBJECT_LINEAR 0x2401 +#define GL_OBJECT_PLANE 0x2501 +#define GL_EYE_LINEAR 0x2400 +#define GL_EYE_PLANE 0x2502 +#define GL_SPHERE_MAP 0x2402 +#define GL_DECAL 0x2101 +#define GL_MODULATE 0x2100 +#define GL_NEAREST 0x2600 +#define GL_REPEAT 0x2901 +#define GL_CLAMP 0x2900 +#define GL_S 0x2000 +#define GL_T 0x2001 +#define GL_R 0x2002 +#define GL_Q 0x2003 +#define GL_TEXTURE_GEN_R 0x0C62 +#define GL_TEXTURE_GEN_Q 0x0C63 + +/* Utility */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 + +/* Errors */ +#define GL_NO_ERROR 0x0 +#define GL_INVALID_ENUM 0x0500 +#define GL_INVALID_VALUE 0x0501 +#define GL_INVALID_OPERATION 0x0502 +#define GL_STACK_OVERFLOW 0x0503 +#define GL_STACK_UNDERFLOW 0x0504 +#define GL_OUT_OF_MEMORY 0x0505 + +/* glPush/PopAttrib bits */ +#define GL_CURRENT_BIT 0x00000001 +#define GL_POINT_BIT 0x00000002 +#define GL_LINE_BIT 0x00000004 +#define GL_POLYGON_BIT 0x00000008 +#define GL_POLYGON_STIPPLE_BIT 0x00000010 +#define GL_PIXEL_MODE_BIT 0x00000020 +#define GL_LIGHTING_BIT 0x00000040 +#define GL_FOG_BIT 0x00000080 +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_ACCUM_BUFFER_BIT 0x00000200 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_VIEWPORT_BIT 0x00000800 +#define GL_TRANSFORM_BIT 0x00001000 +#define GL_ENABLE_BIT 0x00002000 +#define GL_COLOR_BUFFER_BIT 0x00004000 +#define GL_HINT_BIT 0x00008000 +#define GL_EVAL_BIT 0x00010000 +#define GL_LIST_BIT 0x00020000 +#define GL_TEXTURE_BIT 0x00040000 +#define GL_SCISSOR_BIT 0x00080000 +#define GL_ALL_ATTRIB_BITS 0x000FFFFF + + +/* OpenGL 1.1 */ +#define GL_PROXY_TEXTURE_1D 0x8063 +#define GL_PROXY_TEXTURE_2D 0x8064 +#define GL_TEXTURE_PRIORITY 0x8066 +#define GL_TEXTURE_RESIDENT 0x8067 +#define GL_TEXTURE_BINDING_1D 0x8068 +#define GL_TEXTURE_BINDING_2D 0x8069 +#define GL_TEXTURE_INTERNAL_FORMAT 0x1003 +#define GL_ALPHA4 0x803B +#define GL_ALPHA8 0x803C +#define GL_ALPHA12 0x803D +#define GL_ALPHA16 0x803E +#define GL_LUMINANCE4 0x803F +#define GL_LUMINANCE8 0x8040 +#define GL_LUMINANCE12 0x8041 +#define GL_LUMINANCE16 0x8042 +#define GL_LUMINANCE4_ALPHA4 0x8043 +#define GL_LUMINANCE6_ALPHA2 0x8044 +#define GL_LUMINANCE8_ALPHA8 0x8045 +#define GL_LUMINANCE12_ALPHA4 0x8046 +#define GL_LUMINANCE12_ALPHA12 0x8047 +#define GL_LUMINANCE16_ALPHA16 0x8048 +#define GL_INTENSITY 0x8049 +#define GL_INTENSITY4 0x804A +#define GL_INTENSITY8 0x804B +#define GL_INTENSITY12 0x804C +#define GL_INTENSITY16 0x804D +#define GL_R3_G3_B2 0x2A10 +#define GL_RGB4 0x804F +#define GL_RGB5 0x8050 +#define GL_RGB8 0x8051 +#define GL_RGB10 0x8052 +#define GL_RGB12 0x8053 +#define GL_RGB16 0x8054 +#define GL_RGBA2 0x8055 +#define GL_RGBA4 0x8056 +#define GL_RGB5_A1 0x8057 +#define GL_RGBA8 0x8058 +#define GL_RGB10_A2 0x8059 +#define GL_RGBA12 0x805A +#define GL_RGBA16 0x805B +#define GL_CLIENT_PIXEL_STORE_BIT 0x00000001 +#define GL_CLIENT_VERTEX_ARRAY_BIT 0x00000002 +#define GL_ALL_CLIENT_ATTRIB_BITS 0xFFFFFFFF +#define GL_CLIENT_ALL_ATTRIB_BITS 0xFFFFFFFF + + + +/* + * Miscellaneous + */ + +GLAPI void GLAPIENTRY glClearIndex( GLfloat c ); + +GLAPI void GLAPIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ); + +GLAPI void GLAPIENTRY glClear( GLbitfield mask ); + +GLAPI void GLAPIENTRY glIndexMask( GLuint mask ); + +GLAPI void GLAPIENTRY glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha ); + +GLAPI void GLAPIENTRY glAlphaFunc( GLenum func, GLclampf ref ); + +GLAPI void GLAPIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor ); + +GLAPI void GLAPIENTRY glLogicOp( GLenum opcode ); + +GLAPI void GLAPIENTRY glCullFace( GLenum mode ); + +GLAPI void GLAPIENTRY glFrontFace( GLenum mode ); + +GLAPI void GLAPIENTRY glPointSize( GLfloat size ); + +GLAPI void GLAPIENTRY glLineWidth( GLfloat width ); + +GLAPI void GLAPIENTRY glLineStipple( GLint factor, GLushort pattern ); + +GLAPI void GLAPIENTRY glPolygonMode( GLenum face, GLenum mode ); + +GLAPI void GLAPIENTRY glPolygonOffset( GLfloat factor, GLfloat units ); + +GLAPI void GLAPIENTRY glPolygonStipple( const GLubyte *mask ); + +GLAPI void GLAPIENTRY glGetPolygonStipple( GLubyte *mask ); + +GLAPI void GLAPIENTRY glEdgeFlag( GLboolean flag ); + +GLAPI void GLAPIENTRY glEdgeFlagv( const GLboolean *flag ); + +GLAPI void GLAPIENTRY glScissor( GLint x, GLint y, GLsizei width, GLsizei height); + +GLAPI void GLAPIENTRY glClipPlane( GLenum plane, const GLdouble *equation ); + +GLAPI void GLAPIENTRY glGetClipPlane( GLenum plane, GLdouble *equation ); + +GLAPI void GLAPIENTRY glDrawBuffer( GLenum mode ); + +GLAPI void GLAPIENTRY glReadBuffer( GLenum mode ); + +GLAPI void GLAPIENTRY glEnable( GLenum cap ); + +GLAPI void GLAPIENTRY glDisable( GLenum cap ); + +GLAPI GLboolean GLAPIENTRY glIsEnabled( GLenum cap ); + + +GLAPI void GLAPIENTRY glEnableClientState( GLenum cap ); /* 1.1 */ + +GLAPI void GLAPIENTRY glDisableClientState( GLenum cap ); /* 1.1 */ + + +GLAPI void GLAPIENTRY glGetBooleanv( GLenum pname, GLboolean *params ); + +GLAPI void GLAPIENTRY glGetDoublev( GLenum pname, GLdouble *params ); + +GLAPI void GLAPIENTRY glGetFloatv( GLenum pname, GLfloat *params ); + +GLAPI void GLAPIENTRY glGetIntegerv( GLenum pname, GLint *params ); + + +GLAPI void GLAPIENTRY glPushAttrib( GLbitfield mask ); + +GLAPI void GLAPIENTRY glPopAttrib( void ); + + +GLAPI void GLAPIENTRY glPushClientAttrib( GLbitfield mask ); /* 1.1 */ + +GLAPI void GLAPIENTRY glPopClientAttrib( void ); /* 1.1 */ + + +GLAPI GLint GLAPIENTRY glRenderMode( GLenum mode ); + +GLAPI GLenum GLAPIENTRY glGetError( void ); + +GLAPI const GLubyte * GLAPIENTRY glGetString( GLenum name ); + +GLAPI void GLAPIENTRY glFinish( void ); + +GLAPI void GLAPIENTRY glFlush( void ); + +GLAPI void GLAPIENTRY glHint( GLenum target, GLenum mode ); + + +/* + * Depth Buffer + */ + +GLAPI void GLAPIENTRY glClearDepth( GLclampd depth ); + +GLAPI void GLAPIENTRY glDepthFunc( GLenum func ); + +GLAPI void GLAPIENTRY glDepthMask( GLboolean flag ); + +GLAPI void GLAPIENTRY glDepthRange( GLclampd near_val, GLclampd far_val ); + + +/* + * Accumulation Buffer + */ + +GLAPI void GLAPIENTRY glClearAccum( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha ); + +GLAPI void GLAPIENTRY glAccum( GLenum op, GLfloat value ); + + +/* + * Transformation + */ + +GLAPI void GLAPIENTRY glMatrixMode( GLenum mode ); + +GLAPI void GLAPIENTRY glOrtho( GLdouble left, GLdouble right, + GLdouble bottom, GLdouble top, + GLdouble near_val, GLdouble far_val ); + +GLAPI void GLAPIENTRY glFrustum( GLdouble left, GLdouble right, + GLdouble bottom, GLdouble top, + GLdouble near_val, GLdouble far_val ); + +GLAPI void GLAPIENTRY glViewport( GLint x, GLint y, + GLsizei width, GLsizei height ); + +GLAPI void GLAPIENTRY glPushMatrix( void ); + +GLAPI void GLAPIENTRY glPopMatrix( void ); + +GLAPI void GLAPIENTRY glLoadIdentity( void ); + +GLAPI void GLAPIENTRY glLoadMatrixd( const GLdouble *m ); +GLAPI void GLAPIENTRY glLoadMatrixf( const GLfloat *m ); + +GLAPI void GLAPIENTRY glMultMatrixd( const GLdouble *m ); +GLAPI void GLAPIENTRY glMultMatrixf( const GLfloat *m ); + +GLAPI void GLAPIENTRY glRotated( GLdouble angle, + GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glRotatef( GLfloat angle, + GLfloat x, GLfloat y, GLfloat z ); + +GLAPI void GLAPIENTRY glScaled( GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glScalef( GLfloat x, GLfloat y, GLfloat z ); + +GLAPI void GLAPIENTRY glTranslated( GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glTranslatef( GLfloat x, GLfloat y, GLfloat z ); + + +/* + * Display Lists + */ + +GLAPI GLboolean GLAPIENTRY glIsList( GLuint list ); + +GLAPI void GLAPIENTRY glDeleteLists( GLuint list, GLsizei range ); + +GLAPI GLuint GLAPIENTRY glGenLists( GLsizei range ); + +GLAPI void GLAPIENTRY glNewList( GLuint list, GLenum mode ); + +GLAPI void GLAPIENTRY glEndList( void ); + +GLAPI void GLAPIENTRY glCallList( GLuint list ); + +GLAPI void GLAPIENTRY glCallLists( GLsizei n, GLenum type, + const GLvoid *lists ); + +GLAPI void GLAPIENTRY glListBase( GLuint base ); + + +/* + * Drawing Functions + */ + +GLAPI void GLAPIENTRY glBegin( GLenum mode ); + +GLAPI void GLAPIENTRY glEnd( void ); + + +GLAPI void GLAPIENTRY glVertex2d( GLdouble x, GLdouble y ); +GLAPI void GLAPIENTRY glVertex2f( GLfloat x, GLfloat y ); +GLAPI void GLAPIENTRY glVertex2i( GLint x, GLint y ); +GLAPI void GLAPIENTRY glVertex2s( GLshort x, GLshort y ); + +GLAPI void GLAPIENTRY glVertex3d( GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glVertex3f( GLfloat x, GLfloat y, GLfloat z ); +GLAPI void GLAPIENTRY glVertex3i( GLint x, GLint y, GLint z ); +GLAPI void GLAPIENTRY glVertex3s( GLshort x, GLshort y, GLshort z ); + +GLAPI void GLAPIENTRY glVertex4d( GLdouble x, GLdouble y, GLdouble z, GLdouble w ); +GLAPI void GLAPIENTRY glVertex4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w ); +GLAPI void GLAPIENTRY glVertex4i( GLint x, GLint y, GLint z, GLint w ); +GLAPI void GLAPIENTRY glVertex4s( GLshort x, GLshort y, GLshort z, GLshort w ); + +GLAPI void GLAPIENTRY glVertex2dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glVertex2fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glVertex2iv( const GLint *v ); +GLAPI void GLAPIENTRY glVertex2sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glVertex3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glVertex3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glVertex3iv( const GLint *v ); +GLAPI void GLAPIENTRY glVertex3sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glVertex4dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glVertex4fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glVertex4iv( const GLint *v ); +GLAPI void GLAPIENTRY glVertex4sv( const GLshort *v ); + + +GLAPI void GLAPIENTRY glNormal3b( GLbyte nx, GLbyte ny, GLbyte nz ); +GLAPI void GLAPIENTRY glNormal3d( GLdouble nx, GLdouble ny, GLdouble nz ); +GLAPI void GLAPIENTRY glNormal3f( GLfloat nx, GLfloat ny, GLfloat nz ); +GLAPI void GLAPIENTRY glNormal3i( GLint nx, GLint ny, GLint nz ); +GLAPI void GLAPIENTRY glNormal3s( GLshort nx, GLshort ny, GLshort nz ); + +GLAPI void GLAPIENTRY glNormal3bv( const GLbyte *v ); +GLAPI void GLAPIENTRY glNormal3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glNormal3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glNormal3iv( const GLint *v ); +GLAPI void GLAPIENTRY glNormal3sv( const GLshort *v ); + + +GLAPI void GLAPIENTRY glIndexd( GLdouble c ); +GLAPI void GLAPIENTRY glIndexf( GLfloat c ); +GLAPI void GLAPIENTRY glIndexi( GLint c ); +GLAPI void GLAPIENTRY glIndexs( GLshort c ); +GLAPI void GLAPIENTRY glIndexub( GLubyte c ); /* 1.1 */ + +GLAPI void GLAPIENTRY glIndexdv( const GLdouble *c ); +GLAPI void GLAPIENTRY glIndexfv( const GLfloat *c ); +GLAPI void GLAPIENTRY glIndexiv( const GLint *c ); +GLAPI void GLAPIENTRY glIndexsv( const GLshort *c ); +GLAPI void GLAPIENTRY glIndexubv( const GLubyte *c ); /* 1.1 */ + +GLAPI void GLAPIENTRY glColor3b( GLbyte red, GLbyte green, GLbyte blue ); +GLAPI void GLAPIENTRY glColor3d( GLdouble red, GLdouble green, GLdouble blue ); +GLAPI void GLAPIENTRY glColor3f( GLfloat red, GLfloat green, GLfloat blue ); +GLAPI void GLAPIENTRY glColor3i( GLint red, GLint green, GLint blue ); +GLAPI void GLAPIENTRY glColor3s( GLshort red, GLshort green, GLshort blue ); +GLAPI void GLAPIENTRY glColor3ub( GLubyte red, GLubyte green, GLubyte blue ); +GLAPI void GLAPIENTRY glColor3ui( GLuint red, GLuint green, GLuint blue ); +GLAPI void GLAPIENTRY glColor3us( GLushort red, GLushort green, GLushort blue ); + +GLAPI void GLAPIENTRY glColor4b( GLbyte red, GLbyte green, + GLbyte blue, GLbyte alpha ); +GLAPI void GLAPIENTRY glColor4d( GLdouble red, GLdouble green, + GLdouble blue, GLdouble alpha ); +GLAPI void GLAPIENTRY glColor4f( GLfloat red, GLfloat green, + GLfloat blue, GLfloat alpha ); +GLAPI void GLAPIENTRY glColor4i( GLint red, GLint green, + GLint blue, GLint alpha ); +GLAPI void GLAPIENTRY glColor4s( GLshort red, GLshort green, + GLshort blue, GLshort alpha ); +GLAPI void GLAPIENTRY glColor4ub( GLubyte red, GLubyte green, + GLubyte blue, GLubyte alpha ); +GLAPI void GLAPIENTRY glColor4ui( GLuint red, GLuint green, + GLuint blue, GLuint alpha ); +GLAPI void GLAPIENTRY glColor4us( GLushort red, GLushort green, + GLushort blue, GLushort alpha ); + + +GLAPI void GLAPIENTRY glColor3bv( const GLbyte *v ); +GLAPI void GLAPIENTRY glColor3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glColor3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glColor3iv( const GLint *v ); +GLAPI void GLAPIENTRY glColor3sv( const GLshort *v ); +GLAPI void GLAPIENTRY glColor3ubv( const GLubyte *v ); +GLAPI void GLAPIENTRY glColor3uiv( const GLuint *v ); +GLAPI void GLAPIENTRY glColor3usv( const GLushort *v ); + +GLAPI void GLAPIENTRY glColor4bv( const GLbyte *v ); +GLAPI void GLAPIENTRY glColor4dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glColor4fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glColor4iv( const GLint *v ); +GLAPI void GLAPIENTRY glColor4sv( const GLshort *v ); +GLAPI void GLAPIENTRY glColor4ubv( const GLubyte *v ); +GLAPI void GLAPIENTRY glColor4uiv( const GLuint *v ); +GLAPI void GLAPIENTRY glColor4usv( const GLushort *v ); + + +GLAPI void GLAPIENTRY glTexCoord1d( GLdouble s ); +GLAPI void GLAPIENTRY glTexCoord1f( GLfloat s ); +GLAPI void GLAPIENTRY glTexCoord1i( GLint s ); +GLAPI void GLAPIENTRY glTexCoord1s( GLshort s ); + +GLAPI void GLAPIENTRY glTexCoord2d( GLdouble s, GLdouble t ); +GLAPI void GLAPIENTRY glTexCoord2f( GLfloat s, GLfloat t ); +GLAPI void GLAPIENTRY glTexCoord2i( GLint s, GLint t ); +GLAPI void GLAPIENTRY glTexCoord2s( GLshort s, GLshort t ); + +GLAPI void GLAPIENTRY glTexCoord3d( GLdouble s, GLdouble t, GLdouble r ); +GLAPI void GLAPIENTRY glTexCoord3f( GLfloat s, GLfloat t, GLfloat r ); +GLAPI void GLAPIENTRY glTexCoord3i( GLint s, GLint t, GLint r ); +GLAPI void GLAPIENTRY glTexCoord3s( GLshort s, GLshort t, GLshort r ); + +GLAPI void GLAPIENTRY glTexCoord4d( GLdouble s, GLdouble t, GLdouble r, GLdouble q ); +GLAPI void GLAPIENTRY glTexCoord4f( GLfloat s, GLfloat t, GLfloat r, GLfloat q ); +GLAPI void GLAPIENTRY glTexCoord4i( GLint s, GLint t, GLint r, GLint q ); +GLAPI void GLAPIENTRY glTexCoord4s( GLshort s, GLshort t, GLshort r, GLshort q ); + +GLAPI void GLAPIENTRY glTexCoord1dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glTexCoord1fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glTexCoord1iv( const GLint *v ); +GLAPI void GLAPIENTRY glTexCoord1sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glTexCoord2dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glTexCoord2fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glTexCoord2iv( const GLint *v ); +GLAPI void GLAPIENTRY glTexCoord2sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glTexCoord3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glTexCoord3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glTexCoord3iv( const GLint *v ); +GLAPI void GLAPIENTRY glTexCoord3sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glTexCoord4dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glTexCoord4fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glTexCoord4iv( const GLint *v ); +GLAPI void GLAPIENTRY glTexCoord4sv( const GLshort *v ); + + +GLAPI void GLAPIENTRY glRasterPos2d( GLdouble x, GLdouble y ); +GLAPI void GLAPIENTRY glRasterPos2f( GLfloat x, GLfloat y ); +GLAPI void GLAPIENTRY glRasterPos2i( GLint x, GLint y ); +GLAPI void GLAPIENTRY glRasterPos2s( GLshort x, GLshort y ); + +GLAPI void GLAPIENTRY glRasterPos3d( GLdouble x, GLdouble y, GLdouble z ); +GLAPI void GLAPIENTRY glRasterPos3f( GLfloat x, GLfloat y, GLfloat z ); +GLAPI void GLAPIENTRY glRasterPos3i( GLint x, GLint y, GLint z ); +GLAPI void GLAPIENTRY glRasterPos3s( GLshort x, GLshort y, GLshort z ); + +GLAPI void GLAPIENTRY glRasterPos4d( GLdouble x, GLdouble y, GLdouble z, GLdouble w ); +GLAPI void GLAPIENTRY glRasterPos4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w ); +GLAPI void GLAPIENTRY glRasterPos4i( GLint x, GLint y, GLint z, GLint w ); +GLAPI void GLAPIENTRY glRasterPos4s( GLshort x, GLshort y, GLshort z, GLshort w ); + +GLAPI void GLAPIENTRY glRasterPos2dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glRasterPos2fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glRasterPos2iv( const GLint *v ); +GLAPI void GLAPIENTRY glRasterPos2sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glRasterPos3dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glRasterPos3fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glRasterPos3iv( const GLint *v ); +GLAPI void GLAPIENTRY glRasterPos3sv( const GLshort *v ); + +GLAPI void GLAPIENTRY glRasterPos4dv( const GLdouble *v ); +GLAPI void GLAPIENTRY glRasterPos4fv( const GLfloat *v ); +GLAPI void GLAPIENTRY glRasterPos4iv( const GLint *v ); +GLAPI void GLAPIENTRY glRasterPos4sv( const GLshort *v ); + + +GLAPI void GLAPIENTRY glRectd( GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2 ); +GLAPI void GLAPIENTRY glRectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 ); +GLAPI void GLAPIENTRY glRecti( GLint x1, GLint y1, GLint x2, GLint y2 ); +GLAPI void GLAPIENTRY glRects( GLshort x1, GLshort y1, GLshort x2, GLshort y2 ); + + +GLAPI void GLAPIENTRY glRectdv( const GLdouble *v1, const GLdouble *v2 ); +GLAPI void GLAPIENTRY glRectfv( const GLfloat *v1, const GLfloat *v2 ); +GLAPI void GLAPIENTRY glRectiv( const GLint *v1, const GLint *v2 ); +GLAPI void GLAPIENTRY glRectsv( const GLshort *v1, const GLshort *v2 ); + + +/* + * Vertex Arrays (1.1) + */ + +GLAPI void GLAPIENTRY glVertexPointer( GLint size, GLenum type, + GLsizei stride, const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glNormalPointer( GLenum type, GLsizei stride, + const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glColorPointer( GLint size, GLenum type, + GLsizei stride, const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glIndexPointer( GLenum type, GLsizei stride, + const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glTexCoordPointer( GLint size, GLenum type, + GLsizei stride, const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glEdgeFlagPointer( GLsizei stride, const GLvoid *ptr ); + +GLAPI void GLAPIENTRY glGetPointerv( GLenum pname, GLvoid **params ); + +GLAPI void GLAPIENTRY glArrayElement( GLint i ); + +GLAPI void GLAPIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count ); + +GLAPI void GLAPIENTRY glDrawElements( GLenum mode, GLsizei count, + GLenum type, const GLvoid *indices ); + +GLAPI void GLAPIENTRY glInterleavedArrays( GLenum format, GLsizei stride, + const GLvoid *pointer ); + +/* + * Lighting + */ + +GLAPI void GLAPIENTRY glShadeModel( GLenum mode ); + +GLAPI void GLAPIENTRY glLightf( GLenum light, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glLighti( GLenum light, GLenum pname, GLint param ); +GLAPI void GLAPIENTRY glLightfv( GLenum light, GLenum pname, + const GLfloat *params ); +GLAPI void GLAPIENTRY glLightiv( GLenum light, GLenum pname, + const GLint *params ); + +GLAPI void GLAPIENTRY glGetLightfv( GLenum light, GLenum pname, + GLfloat *params ); +GLAPI void GLAPIENTRY glGetLightiv( GLenum light, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glLightModelf( GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glLightModeli( GLenum pname, GLint param ); +GLAPI void GLAPIENTRY glLightModelfv( GLenum pname, const GLfloat *params ); +GLAPI void GLAPIENTRY glLightModeliv( GLenum pname, const GLint *params ); + +GLAPI void GLAPIENTRY glMaterialf( GLenum face, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glMateriali( GLenum face, GLenum pname, GLint param ); +GLAPI void GLAPIENTRY glMaterialfv( GLenum face, GLenum pname, const GLfloat *params ); +GLAPI void GLAPIENTRY glMaterialiv( GLenum face, GLenum pname, const GLint *params ); + +GLAPI void GLAPIENTRY glGetMaterialfv( GLenum face, GLenum pname, GLfloat *params ); +GLAPI void GLAPIENTRY glGetMaterialiv( GLenum face, GLenum pname, GLint *params ); + +GLAPI void GLAPIENTRY glColorMaterial( GLenum face, GLenum mode ); + + +/* + * Raster functions + */ + +GLAPI void GLAPIENTRY glPixelZoom( GLfloat xfactor, GLfloat yfactor ); + +GLAPI void GLAPIENTRY glPixelStoref( GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glPixelStorei( GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glPixelTransferf( GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glPixelTransferi( GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glPixelMapfv( GLenum map, GLsizei mapsize, + const GLfloat *values ); +GLAPI void GLAPIENTRY glPixelMapuiv( GLenum map, GLsizei mapsize, + const GLuint *values ); +GLAPI void GLAPIENTRY glPixelMapusv( GLenum map, GLsizei mapsize, + const GLushort *values ); + +GLAPI void GLAPIENTRY glGetPixelMapfv( GLenum map, GLfloat *values ); +GLAPI void GLAPIENTRY glGetPixelMapuiv( GLenum map, GLuint *values ); +GLAPI void GLAPIENTRY glGetPixelMapusv( GLenum map, GLushort *values ); + +GLAPI void GLAPIENTRY glBitmap( GLsizei width, GLsizei height, + GLfloat xorig, GLfloat yorig, + GLfloat xmove, GLfloat ymove, + const GLubyte *bitmap ); + +GLAPI void GLAPIENTRY glReadPixels( GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + GLvoid *pixels ); + +GLAPI void GLAPIENTRY glDrawPixels( GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels ); + +GLAPI void GLAPIENTRY glCopyPixels( GLint x, GLint y, + GLsizei width, GLsizei height, + GLenum type ); + +/* + * Stenciling + */ + +GLAPI void GLAPIENTRY glStencilFunc( GLenum func, GLint ref, GLuint mask ); + +GLAPI void GLAPIENTRY glStencilMask( GLuint mask ); + +GLAPI void GLAPIENTRY glStencilOp( GLenum fail, GLenum zfail, GLenum zpass ); + +GLAPI void GLAPIENTRY glClearStencil( GLint s ); + + + +/* + * Texture mapping + */ + +GLAPI void GLAPIENTRY glTexGend( GLenum coord, GLenum pname, GLdouble param ); +GLAPI void GLAPIENTRY glTexGenf( GLenum coord, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glTexGeni( GLenum coord, GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glTexGendv( GLenum coord, GLenum pname, const GLdouble *params ); +GLAPI void GLAPIENTRY glTexGenfv( GLenum coord, GLenum pname, const GLfloat *params ); +GLAPI void GLAPIENTRY glTexGeniv( GLenum coord, GLenum pname, const GLint *params ); + +GLAPI void GLAPIENTRY glGetTexGendv( GLenum coord, GLenum pname, GLdouble *params ); +GLAPI void GLAPIENTRY glGetTexGenfv( GLenum coord, GLenum pname, GLfloat *params ); +GLAPI void GLAPIENTRY glGetTexGeniv( GLenum coord, GLenum pname, GLint *params ); + + +GLAPI void GLAPIENTRY glTexEnvf( GLenum target, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glTexEnvi( GLenum target, GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glTexEnvfv( GLenum target, GLenum pname, const GLfloat *params ); +GLAPI void GLAPIENTRY glTexEnviv( GLenum target, GLenum pname, const GLint *params ); + +GLAPI void GLAPIENTRY glGetTexEnvfv( GLenum target, GLenum pname, GLfloat *params ); +GLAPI void GLAPIENTRY glGetTexEnviv( GLenum target, GLenum pname, GLint *params ); + + +GLAPI void GLAPIENTRY glTexParameterf( GLenum target, GLenum pname, GLfloat param ); +GLAPI void GLAPIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glTexParameterfv( GLenum target, GLenum pname, + const GLfloat *params ); +GLAPI void GLAPIENTRY glTexParameteriv( GLenum target, GLenum pname, + const GLint *params ); + +GLAPI void GLAPIENTRY glGetTexParameterfv( GLenum target, + GLenum pname, GLfloat *params); +GLAPI void GLAPIENTRY glGetTexParameteriv( GLenum target, + GLenum pname, GLint *params ); + +GLAPI void GLAPIENTRY glGetTexLevelParameterfv( GLenum target, GLint level, + GLenum pname, GLfloat *params ); +GLAPI void GLAPIENTRY glGetTexLevelParameteriv( GLenum target, GLint level, + GLenum pname, GLint *params ); + + +GLAPI void GLAPIENTRY glTexImage1D( GLenum target, GLint level, + GLint internalFormat, + GLsizei width, GLint border, + GLenum format, GLenum type, + const GLvoid *pixels ); + +GLAPI void GLAPIENTRY glTexImage2D( GLenum target, GLint level, + GLint internalFormat, + GLsizei width, GLsizei height, + GLint border, GLenum format, GLenum type, + const GLvoid *pixels ); + +GLAPI void GLAPIENTRY glGetTexImage( GLenum target, GLint level, + GLenum format, GLenum type, + GLvoid *pixels ); + + +/* 1.1 functions */ + +GLAPI void GLAPIENTRY glGenTextures( GLsizei n, GLuint *textures ); + +GLAPI void GLAPIENTRY glDeleteTextures( GLsizei n, const GLuint *textures); + +GLAPI void GLAPIENTRY glBindTexture( GLenum target, GLuint texture ); + +GLAPI void GLAPIENTRY glPrioritizeTextures( GLsizei n, + const GLuint *textures, + const GLclampf *priorities ); + +GLAPI GLboolean GLAPIENTRY glAreTexturesResident( GLsizei n, + const GLuint *textures, + GLboolean *residences ); + +GLAPI GLboolean GLAPIENTRY glIsTexture( GLuint texture ); + + +GLAPI void GLAPIENTRY glTexSubImage1D( GLenum target, GLint level, + GLint xoffset, + GLsizei width, GLenum format, + GLenum type, const GLvoid *pixels ); + + +GLAPI void GLAPIENTRY glTexSubImage2D( GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels ); + + +GLAPI void GLAPIENTRY glCopyTexImage1D( GLenum target, GLint level, + GLenum internalformat, + GLint x, GLint y, + GLsizei width, GLint border ); + + +GLAPI void GLAPIENTRY glCopyTexImage2D( GLenum target, GLint level, + GLenum internalformat, + GLint x, GLint y, + GLsizei width, GLsizei height, + GLint border ); + + +GLAPI void GLAPIENTRY glCopyTexSubImage1D( GLenum target, GLint level, + GLint xoffset, GLint x, GLint y, + GLsizei width ); + + +GLAPI void GLAPIENTRY glCopyTexSubImage2D( GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint x, GLint y, + GLsizei width, GLsizei height ); + + +/* + * Evaluators + */ + +GLAPI void GLAPIENTRY glMap1d( GLenum target, GLdouble u1, GLdouble u2, + GLint stride, + GLint order, const GLdouble *points ); +GLAPI void GLAPIENTRY glMap1f( GLenum target, GLfloat u1, GLfloat u2, + GLint stride, + GLint order, const GLfloat *points ); + +GLAPI void GLAPIENTRY glMap2d( GLenum target, + GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, + GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, + const GLdouble *points ); +GLAPI void GLAPIENTRY glMap2f( GLenum target, + GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, + GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, + const GLfloat *points ); + +GLAPI void GLAPIENTRY glGetMapdv( GLenum target, GLenum query, GLdouble *v ); +GLAPI void GLAPIENTRY glGetMapfv( GLenum target, GLenum query, GLfloat *v ); +GLAPI void GLAPIENTRY glGetMapiv( GLenum target, GLenum query, GLint *v ); + +GLAPI void GLAPIENTRY glEvalCoord1d( GLdouble u ); +GLAPI void GLAPIENTRY glEvalCoord1f( GLfloat u ); + +GLAPI void GLAPIENTRY glEvalCoord1dv( const GLdouble *u ); +GLAPI void GLAPIENTRY glEvalCoord1fv( const GLfloat *u ); + +GLAPI void GLAPIENTRY glEvalCoord2d( GLdouble u, GLdouble v ); +GLAPI void GLAPIENTRY glEvalCoord2f( GLfloat u, GLfloat v ); + +GLAPI void GLAPIENTRY glEvalCoord2dv( const GLdouble *u ); +GLAPI void GLAPIENTRY glEvalCoord2fv( const GLfloat *u ); + +GLAPI void GLAPIENTRY glMapGrid1d( GLint un, GLdouble u1, GLdouble u2 ); +GLAPI void GLAPIENTRY glMapGrid1f( GLint un, GLfloat u1, GLfloat u2 ); + +GLAPI void GLAPIENTRY glMapGrid2d( GLint un, GLdouble u1, GLdouble u2, + GLint vn, GLdouble v1, GLdouble v2 ); +GLAPI void GLAPIENTRY glMapGrid2f( GLint un, GLfloat u1, GLfloat u2, + GLint vn, GLfloat v1, GLfloat v2 ); + +GLAPI void GLAPIENTRY glEvalPoint1( GLint i ); + +GLAPI void GLAPIENTRY glEvalPoint2( GLint i, GLint j ); + +GLAPI void GLAPIENTRY glEvalMesh1( GLenum mode, GLint i1, GLint i2 ); + +GLAPI void GLAPIENTRY glEvalMesh2( GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2 ); + + +/* + * Fog + */ + +GLAPI void GLAPIENTRY glFogf( GLenum pname, GLfloat param ); + +GLAPI void GLAPIENTRY glFogi( GLenum pname, GLint param ); + +GLAPI void GLAPIENTRY glFogfv( GLenum pname, const GLfloat *params ); + +GLAPI void GLAPIENTRY glFogiv( GLenum pname, const GLint *params ); + + +/* + * Selection and Feedback + */ + +GLAPI void GLAPIENTRY glFeedbackBuffer( GLsizei size, GLenum type, GLfloat *buffer ); + +GLAPI void GLAPIENTRY glPassThrough( GLfloat token ); + +GLAPI void GLAPIENTRY glSelectBuffer( GLsizei size, GLuint *buffer ); + +GLAPI void GLAPIENTRY glInitNames( void ); + +GLAPI void GLAPIENTRY glLoadName( GLuint name ); + +GLAPI void GLAPIENTRY glPushName( GLuint name ); + +GLAPI void GLAPIENTRY glPopName( void ); + + + +/* + * OpenGL 1.2 + */ + +#define GL_RESCALE_NORMAL 0x803A +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 +#define GL_BGR 0x80E0 +#define GL_BGRA 0x80E1 +#define GL_UNSIGNED_BYTE_3_3_2 0x8032 +#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 +#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#define GL_UNSIGNED_INT_8_8_8_8 0x8035 +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#define GL_UNSIGNED_INT_10_10_10_2 0x8036 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 +#define GL_SINGLE_COLOR 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR 0x81FA +#define GL_TEXTURE_MIN_LOD 0x813A +#define GL_TEXTURE_MAX_LOD 0x813B +#define GL_TEXTURE_BASE_LEVEL 0x813C +#define GL_TEXTURE_MAX_LEVEL 0x813D +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#define GL_PACK_SKIP_IMAGES 0x806B +#define GL_PACK_IMAGE_HEIGHT 0x806C +#define GL_UNPACK_SKIP_IMAGES 0x806D +#define GL_UNPACK_IMAGE_HEIGHT 0x806E +#define GL_TEXTURE_3D 0x806F +#define GL_PROXY_TEXTURE_3D 0x8070 +#define GL_TEXTURE_DEPTH 0x8071 +#define GL_TEXTURE_WRAP_R 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE 0x8073 +#define GL_TEXTURE_BINDING_3D 0x806A + +GLAPI void GLAPIENTRY glDrawRangeElements( GLenum mode, GLuint start, + GLuint end, GLsizei count, GLenum type, const GLvoid *indices ); + +GLAPI void GLAPIENTRY glTexImage3D( GLenum target, GLint level, + GLint internalFormat, + GLsizei width, GLsizei height, + GLsizei depth, GLint border, + GLenum format, GLenum type, + const GLvoid *pixels ); + +GLAPI void GLAPIENTRY glTexSubImage3D( GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint zoffset, GLsizei width, + GLsizei height, GLsizei depth, + GLenum format, + GLenum type, const GLvoid *pixels); + +GLAPI void GLAPIENTRY glCopyTexSubImage3D( GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint zoffset, GLint x, + GLint y, GLsizei width, + GLsizei height ); + +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); + + +/* + * GL_ARB_imaging + */ + +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_COLOR_TABLE 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2 +#define GL_PROXY_COLOR_TABLE 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5 +#define GL_COLOR_TABLE_SCALE 0x80D6 +#define GL_COLOR_TABLE_BIAS 0x80D7 +#define GL_COLOR_TABLE_FORMAT 0x80D8 +#define GL_COLOR_TABLE_WIDTH 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF +#define GL_CONVOLUTION_1D 0x8010 +#define GL_CONVOLUTION_2D 0x8011 +#define GL_SEPARABLE_2D 0x8012 +#define GL_CONVOLUTION_BORDER_MODE 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS 0x8015 +#define GL_REDUCE 0x8016 +#define GL_CONVOLUTION_FORMAT 0x8017 +#define GL_CONVOLUTION_WIDTH 0x8018 +#define GL_CONVOLUTION_HEIGHT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023 +#define GL_CONSTANT_BORDER 0x8151 +#define GL_REPLICATE_BORDER 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR 0x8154 +#define GL_COLOR_MATRIX 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB +#define GL_HISTOGRAM 0x8024 +#define GL_PROXY_HISTOGRAM 0x8025 +#define GL_HISTOGRAM_WIDTH 0x8026 +#define GL_HISTOGRAM_FORMAT 0x8027 +#define GL_HISTOGRAM_RED_SIZE 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C +#define GL_HISTOGRAM_SINK 0x802D +#define GL_MINMAX 0x802E +#define GL_MINMAX_FORMAT 0x802F +#define GL_MINMAX_SINK 0x8030 +#define GL_TABLE_TOO_LARGE 0x8031 +#define GL_BLEND_EQUATION 0x8009 +#define GL_MIN 0x8007 +#define GL_MAX 0x8008 +#define GL_FUNC_ADD 0x8006 +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B +#define GL_BLEND_COLOR 0x8005 + + +GLAPI void GLAPIENTRY glColorTable( GLenum target, GLenum internalformat, + GLsizei width, GLenum format, + GLenum type, const GLvoid *table ); + +GLAPI void GLAPIENTRY glColorSubTable( GLenum target, + GLsizei start, GLsizei count, + GLenum format, GLenum type, + const GLvoid *data ); + +GLAPI void GLAPIENTRY glColorTableParameteriv(GLenum target, GLenum pname, + const GLint *params); + +GLAPI void GLAPIENTRY glColorTableParameterfv(GLenum target, GLenum pname, + const GLfloat *params); + +GLAPI void GLAPIENTRY glCopyColorSubTable( GLenum target, GLsizei start, + GLint x, GLint y, GLsizei width ); + +GLAPI void GLAPIENTRY glCopyColorTable( GLenum target, GLenum internalformat, + GLint x, GLint y, GLsizei width ); + +GLAPI void GLAPIENTRY glGetColorTable( GLenum target, GLenum format, + GLenum type, GLvoid *table ); + +GLAPI void GLAPIENTRY glGetColorTableParameterfv( GLenum target, GLenum pname, + GLfloat *params ); + +GLAPI void GLAPIENTRY glGetColorTableParameteriv( GLenum target, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glBlendEquation( GLenum mode ); + +GLAPI void GLAPIENTRY glBlendColor( GLclampf red, GLclampf green, + GLclampf blue, GLclampf alpha ); + +GLAPI void GLAPIENTRY glHistogram( GLenum target, GLsizei width, + GLenum internalformat, GLboolean sink ); + +GLAPI void GLAPIENTRY glResetHistogram( GLenum target ); + +GLAPI void GLAPIENTRY glGetHistogram( GLenum target, GLboolean reset, + GLenum format, GLenum type, + GLvoid *values ); + +GLAPI void GLAPIENTRY glGetHistogramParameterfv( GLenum target, GLenum pname, + GLfloat *params ); + +GLAPI void GLAPIENTRY glGetHistogramParameteriv( GLenum target, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glMinmax( GLenum target, GLenum internalformat, + GLboolean sink ); + +GLAPI void GLAPIENTRY glResetMinmax( GLenum target ); + +GLAPI void GLAPIENTRY glGetMinmax( GLenum target, GLboolean reset, + GLenum format, GLenum types, + GLvoid *values ); + +GLAPI void GLAPIENTRY glGetMinmaxParameterfv( GLenum target, GLenum pname, + GLfloat *params ); + +GLAPI void GLAPIENTRY glGetMinmaxParameteriv( GLenum target, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glConvolutionFilter1D( GLenum target, + GLenum internalformat, GLsizei width, GLenum format, GLenum type, + const GLvoid *image ); + +GLAPI void GLAPIENTRY glConvolutionFilter2D( GLenum target, + GLenum internalformat, GLsizei width, GLsizei height, GLenum format, + GLenum type, const GLvoid *image ); + +GLAPI void GLAPIENTRY glConvolutionParameterf( GLenum target, GLenum pname, + GLfloat params ); + +GLAPI void GLAPIENTRY glConvolutionParameterfv( GLenum target, GLenum pname, + const GLfloat *params ); + +GLAPI void GLAPIENTRY glConvolutionParameteri( GLenum target, GLenum pname, + GLint params ); + +GLAPI void GLAPIENTRY glConvolutionParameteriv( GLenum target, GLenum pname, + const GLint *params ); + +GLAPI void GLAPIENTRY glCopyConvolutionFilter1D( GLenum target, + GLenum internalformat, GLint x, GLint y, GLsizei width ); + +GLAPI void GLAPIENTRY glCopyConvolutionFilter2D( GLenum target, + GLenum internalformat, GLint x, GLint y, GLsizei width, + GLsizei height); + +GLAPI void GLAPIENTRY glGetConvolutionFilter( GLenum target, GLenum format, + GLenum type, GLvoid *image ); + +GLAPI void GLAPIENTRY glGetConvolutionParameterfv( GLenum target, GLenum pname, + GLfloat *params ); + +GLAPI void GLAPIENTRY glGetConvolutionParameteriv( GLenum target, GLenum pname, + GLint *params ); + +GLAPI void GLAPIENTRY glSeparableFilter2D( GLenum target, + GLenum internalformat, GLsizei width, GLsizei height, GLenum format, + GLenum type, const GLvoid *row, const GLvoid *column ); + +GLAPI void GLAPIENTRY glGetSeparableFilter( GLenum target, GLenum format, + GLenum type, GLvoid *row, GLvoid *column, GLvoid *span ); + +typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); + + + +/* + * OpenGL 1.3 + */ + +/* multitexture */ +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 +#define GL_MAX_TEXTURE_UNITS 0x84E2 +/* texture_cube_map */ +#define GL_NORMAL_MAP 0x8511 +#define GL_REFLECTION_MAP 0x8512 +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C +/* texture_compression */ +#define GL_COMPRESSED_ALPHA 0x84E9 +#define GL_COMPRESSED_LUMINANCE 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB +#define GL_COMPRESSED_INTENSITY 0x84EC +#define GL_COMPRESSED_RGB 0x84ED +#define GL_COMPRESSED_RGBA 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 +#define GL_TEXTURE_COMPRESSED 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 +/* multisample */ +#define GL_MULTISAMPLE 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE 0x809F +#define GL_SAMPLE_COVERAGE 0x80A0 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB +#define GL_MULTISAMPLE_BIT 0x20000000 +/* transpose_matrix */ +#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6 +/* texture_env_combine */ +#define GL_COMBINE 0x8570 +#define GL_COMBINE_RGB 0x8571 +#define GL_COMBINE_ALPHA 0x8572 +#define GL_SOURCE0_RGB 0x8580 +#define GL_SOURCE1_RGB 0x8581 +#define GL_SOURCE2_RGB 0x8582 +#define GL_SOURCE0_ALPHA 0x8588 +#define GL_SOURCE1_ALPHA 0x8589 +#define GL_SOURCE2_ALPHA 0x858A +#define GL_OPERAND0_RGB 0x8590 +#define GL_OPERAND1_RGB 0x8591 +#define GL_OPERAND2_RGB 0x8592 +#define GL_OPERAND0_ALPHA 0x8598 +#define GL_OPERAND1_ALPHA 0x8599 +#define GL_OPERAND2_ALPHA 0x859A +#define GL_RGB_SCALE 0x8573 +#define GL_ADD_SIGNED 0x8574 +#define GL_INTERPOLATE 0x8575 +#define GL_SUBTRACT 0x84E7 +#define GL_CONSTANT 0x8576 +#define GL_PRIMARY_COLOR 0x8577 +#define GL_PREVIOUS 0x8578 +/* texture_env_dot3 */ +#define GL_DOT3_RGB 0x86AE +#define GL_DOT3_RGBA 0x86AF +/* texture_border_clamp */ +#define GL_CLAMP_TO_BORDER 0x812D + +GLAPI void GLAPIENTRY glActiveTexture( GLenum texture ); + +GLAPI void GLAPIENTRY glClientActiveTexture( GLenum texture ); + +GLAPI void GLAPIENTRY glCompressedTexImage1D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexImage3D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glCompressedTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data ); + +GLAPI void GLAPIENTRY glGetCompressedTexImage( GLenum target, GLint lod, GLvoid *img ); + +GLAPI void GLAPIENTRY glMultiTexCoord1d( GLenum target, GLdouble s ); + +GLAPI void GLAPIENTRY glMultiTexCoord1dv( GLenum target, const GLdouble *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord1f( GLenum target, GLfloat s ); + +GLAPI void GLAPIENTRY glMultiTexCoord1fv( GLenum target, const GLfloat *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord1i( GLenum target, GLint s ); + +GLAPI void GLAPIENTRY glMultiTexCoord1iv( GLenum target, const GLint *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord1s( GLenum target, GLshort s ); + +GLAPI void GLAPIENTRY glMultiTexCoord1sv( GLenum target, const GLshort *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord2d( GLenum target, GLdouble s, GLdouble t ); + +GLAPI void GLAPIENTRY glMultiTexCoord2dv( GLenum target, const GLdouble *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord2f( GLenum target, GLfloat s, GLfloat t ); + +GLAPI void GLAPIENTRY glMultiTexCoord2fv( GLenum target, const GLfloat *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord2i( GLenum target, GLint s, GLint t ); + +GLAPI void GLAPIENTRY glMultiTexCoord2iv( GLenum target, const GLint *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord2s( GLenum target, GLshort s, GLshort t ); + +GLAPI void GLAPIENTRY glMultiTexCoord2sv( GLenum target, const GLshort *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord3d( GLenum target, GLdouble s, GLdouble t, GLdouble r ); + +GLAPI void GLAPIENTRY glMultiTexCoord3dv( GLenum target, const GLdouble *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord3f( GLenum target, GLfloat s, GLfloat t, GLfloat r ); + +GLAPI void GLAPIENTRY glMultiTexCoord3fv( GLenum target, const GLfloat *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord3i( GLenum target, GLint s, GLint t, GLint r ); + +GLAPI void GLAPIENTRY glMultiTexCoord3iv( GLenum target, const GLint *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord3s( GLenum target, GLshort s, GLshort t, GLshort r ); + +GLAPI void GLAPIENTRY glMultiTexCoord3sv( GLenum target, const GLshort *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord4d( GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q ); + +GLAPI void GLAPIENTRY glMultiTexCoord4dv( GLenum target, const GLdouble *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord4f( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q ); + +GLAPI void GLAPIENTRY glMultiTexCoord4fv( GLenum target, const GLfloat *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord4i( GLenum target, GLint s, GLint t, GLint r, GLint q ); + +GLAPI void GLAPIENTRY glMultiTexCoord4iv( GLenum target, const GLint *v ); + +GLAPI void GLAPIENTRY glMultiTexCoord4s( GLenum target, GLshort s, GLshort t, GLshort r, GLshort q ); + +GLAPI void GLAPIENTRY glMultiTexCoord4sv( GLenum target, const GLshort *v ); + + +GLAPI void GLAPIENTRY glLoadTransposeMatrixd( const GLdouble m[16] ); + +GLAPI void GLAPIENTRY glLoadTransposeMatrixf( const GLfloat m[16] ); + +GLAPI void GLAPIENTRY glMultTransposeMatrixd( const GLdouble m[16] ); + +GLAPI void GLAPIENTRY glMultTransposeMatrixf( const GLfloat m[16] ); + +GLAPI void GLAPIENTRY glSampleCoverage( GLclampf value, GLboolean invert ); + + +typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img); + + + +/* + * GL_ARB_multitexture (ARB extension 1 and OpenGL 1.2.1) + */ +#ifndef GL_ARB_multitexture +#define GL_ARB_multitexture 1 + +#define GL_TEXTURE0_ARB 0x84C0 +#define GL_TEXTURE1_ARB 0x84C1 +#define GL_TEXTURE2_ARB 0x84C2 +#define GL_TEXTURE3_ARB 0x84C3 +#define GL_TEXTURE4_ARB 0x84C4 +#define GL_TEXTURE5_ARB 0x84C5 +#define GL_TEXTURE6_ARB 0x84C6 +#define GL_TEXTURE7_ARB 0x84C7 +#define GL_TEXTURE8_ARB 0x84C8 +#define GL_TEXTURE9_ARB 0x84C9 +#define GL_TEXTURE10_ARB 0x84CA +#define GL_TEXTURE11_ARB 0x84CB +#define GL_TEXTURE12_ARB 0x84CC +#define GL_TEXTURE13_ARB 0x84CD +#define GL_TEXTURE14_ARB 0x84CE +#define GL_TEXTURE15_ARB 0x84CF +#define GL_TEXTURE16_ARB 0x84D0 +#define GL_TEXTURE17_ARB 0x84D1 +#define GL_TEXTURE18_ARB 0x84D2 +#define GL_TEXTURE19_ARB 0x84D3 +#define GL_TEXTURE20_ARB 0x84D4 +#define GL_TEXTURE21_ARB 0x84D5 +#define GL_TEXTURE22_ARB 0x84D6 +#define GL_TEXTURE23_ARB 0x84D7 +#define GL_TEXTURE24_ARB 0x84D8 +#define GL_TEXTURE25_ARB 0x84D9 +#define GL_TEXTURE26_ARB 0x84DA +#define GL_TEXTURE27_ARB 0x84DB +#define GL_TEXTURE28_ARB 0x84DC +#define GL_TEXTURE29_ARB 0x84DD +#define GL_TEXTURE30_ARB 0x84DE +#define GL_TEXTURE31_ARB 0x84DF +#define GL_ACTIVE_TEXTURE_ARB 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1 +#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2 + +GLAPI void GLAPIENTRY glActiveTextureARB(GLenum texture); +GLAPI void GLAPIENTRY glClientActiveTextureARB(GLenum texture); +GLAPI void GLAPIENTRY glMultiTexCoord1dARB(GLenum target, GLdouble s); +GLAPI void GLAPIENTRY glMultiTexCoord1dvARB(GLenum target, const GLdouble *v); +GLAPI void GLAPIENTRY glMultiTexCoord1fARB(GLenum target, GLfloat s); +GLAPI void GLAPIENTRY glMultiTexCoord1fvARB(GLenum target, const GLfloat *v); +GLAPI void GLAPIENTRY glMultiTexCoord1iARB(GLenum target, GLint s); +GLAPI void GLAPIENTRY glMultiTexCoord1ivARB(GLenum target, const GLint *v); +GLAPI void GLAPIENTRY glMultiTexCoord1sARB(GLenum target, GLshort s); +GLAPI void GLAPIENTRY glMultiTexCoord1svARB(GLenum target, const GLshort *v); +GLAPI void GLAPIENTRY glMultiTexCoord2dARB(GLenum target, GLdouble s, GLdouble t); +GLAPI void GLAPIENTRY glMultiTexCoord2dvARB(GLenum target, const GLdouble *v); +GLAPI void GLAPIENTRY glMultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t); +GLAPI void GLAPIENTRY glMultiTexCoord2fvARB(GLenum target, const GLfloat *v); +GLAPI void GLAPIENTRY glMultiTexCoord2iARB(GLenum target, GLint s, GLint t); +GLAPI void GLAPIENTRY glMultiTexCoord2ivARB(GLenum target, const GLint *v); +GLAPI void GLAPIENTRY glMultiTexCoord2sARB(GLenum target, GLshort s, GLshort t); +GLAPI void GLAPIENTRY glMultiTexCoord2svARB(GLenum target, const GLshort *v); +GLAPI void GLAPIENTRY glMultiTexCoord3dARB(GLenum target, GLdouble s, GLdouble t, GLdouble r); +GLAPI void GLAPIENTRY glMultiTexCoord3dvARB(GLenum target, const GLdouble *v); +GLAPI void GLAPIENTRY glMultiTexCoord3fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r); +GLAPI void GLAPIENTRY glMultiTexCoord3fvARB(GLenum target, const GLfloat *v); +GLAPI void GLAPIENTRY glMultiTexCoord3iARB(GLenum target, GLint s, GLint t, GLint r); +GLAPI void GLAPIENTRY glMultiTexCoord3ivARB(GLenum target, const GLint *v); +GLAPI void GLAPIENTRY glMultiTexCoord3sARB(GLenum target, GLshort s, GLshort t, GLshort r); +GLAPI void GLAPIENTRY glMultiTexCoord3svARB(GLenum target, const GLshort *v); +GLAPI void GLAPIENTRY glMultiTexCoord4dARB(GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +GLAPI void GLAPIENTRY glMultiTexCoord4dvARB(GLenum target, const GLdouble *v); +GLAPI void GLAPIENTRY glMultiTexCoord4fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +GLAPI void GLAPIENTRY glMultiTexCoord4fvARB(GLenum target, const GLfloat *v); +GLAPI void GLAPIENTRY glMultiTexCoord4iARB(GLenum target, GLint s, GLint t, GLint r, GLint q); +GLAPI void GLAPIENTRY glMultiTexCoord4ivARB(GLenum target, const GLint *v); +GLAPI void GLAPIENTRY glMultiTexCoord4sARB(GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +GLAPI void GLAPIENTRY glMultiTexCoord4svARB(GLenum target, const GLshort *v); + +typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v); + +#endif /* GL_ARB_multitexture */ + + + +/* + * Define this token if you want "old-style" header file behaviour (extensions + * defined in gl.h). Otherwise, extensions will be included from glext.h. + */ +#if defined(GL_GLEXT_LEGACY) + +/* All extensions that used to be here are now found in glext.h */ + +#else /* GL_GLEXT_LEGACY */ + +#include + +#endif /* GL_GLEXT_LEGACY */ + + + +#if GL_ARB_shader_objects + +#ifndef GL_MESA_shader_debug +#define GL_MESA_shader_debug 1 + +#define GL_DEBUG_OBJECT_MESA 0x8759 +#define GL_DEBUG_PRINT_MESA 0x875A +#define GL_DEBUG_ASSERT_MESA 0x875B + +GLAPI GLhandleARB GLAPIENTRY glCreateDebugObjectMESA (void); +GLAPI void GLAPIENTRY glClearDebugLogMESA (GLhandleARB obj, GLenum logType, GLenum shaderType); +GLAPI void GLAPIENTRY glGetDebugLogMESA (GLhandleARB obj, GLenum logType, GLenum shaderType, GLsizei maxLength, + GLsizei *length, GLcharARB *debugLog); +GLAPI GLsizei GLAPIENTRY glGetDebugLogLengthMESA (GLhandleARB obj, GLenum logType, GLenum shaderType); + +#endif /* GL_MESA_shader_debug */ + +#endif /* GL_ARB_shader_objects */ + + +/* + * ???. GL_MESA_packed_depth_stencil + * XXX obsolete + */ +#ifndef GL_MESA_packed_depth_stencil +#define GL_MESA_packed_depth_stencil 1 + +#define GL_DEPTH_STENCIL_MESA 0x8750 +#define GL_UNSIGNED_INT_24_8_MESA 0x8751 +#define GL_UNSIGNED_INT_8_24_REV_MESA 0x8752 +#define GL_UNSIGNED_SHORT_15_1_MESA 0x8753 +#define GL_UNSIGNED_SHORT_1_15_REV_MESA 0x8754 + +#endif /* GL_MESA_packed_depth_stencil */ + + +#ifndef GL_MESA_program_debug +#define GL_MESA_program_debug 1 + +#define GL_FRAGMENT_PROGRAM_POSITION_MESA 0x8bb0 +#define GL_FRAGMENT_PROGRAM_CALLBACK_MESA 0x8bb1 +#define GL_FRAGMENT_PROGRAM_CALLBACK_FUNC_MESA 0x8bb2 +#define GL_FRAGMENT_PROGRAM_CALLBACK_DATA_MESA 0x8bb3 +#define GL_VERTEX_PROGRAM_POSITION_MESA 0x8bb4 +#define GL_VERTEX_PROGRAM_CALLBACK_MESA 0x8bb5 +#define GL_VERTEX_PROGRAM_CALLBACK_FUNC_MESA 0x8bb6 +#define GL_VERTEX_PROGRAM_CALLBACK_DATA_MESA 0x8bb7 + +typedef void (*GLprogramcallbackMESA)(GLenum target, GLvoid *data); + +GLAPI void GLAPIENTRY glProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback, GLvoid *data); + +GLAPI void GLAPIENTRY glGetProgramRegisterfvMESA(GLenum target, GLsizei len, const GLubyte *name, GLfloat *v); + +#endif /* GL_MESA_program_debug */ + + +#ifndef GL_MESA_texture_array +#define GL_MESA_texture_array 1 + +/* GL_MESA_texture_array uses the same enum values as GL_EXT_texture_array. + */ +#ifndef GL_EXT_texture_array + +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFramebufferTextureLayerEXT(GLenum target, + GLenum attachment, GLuint texture, GLint level, GLint layer); +#endif /* GL_GLEXT_PROTOTYPES */ + +#if 0 +/* (temporarily) disabled because of collision with typedef in glext.h + * that happens if apps include both gl.h and glext.h + */ +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYEREXTPROC) (GLenum target, + GLenum attachment, GLuint texture, GLint level, GLint layer); +#endif + +#define GL_TEXTURE_1D_ARRAY_EXT 0x8C18 +#define GL_PROXY_TEXTURE_1D_ARRAY_EXT 0x8C19 +#define GL_TEXTURE_2D_ARRAY_EXT 0x8C1A +#define GL_PROXY_TEXTURE_2D_ARRAY_EXT 0x8C1B +#define GL_TEXTURE_BINDING_1D_ARRAY_EXT 0x8C1C +#define GL_TEXTURE_BINDING_2D_ARRAY_EXT 0x8C1D +#define GL_MAX_ARRAY_TEXTURE_LAYERS_EXT 0x88FF +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4 +#endif + +#endif + + +#ifndef GL_ATI_blend_equation_separate +#define GL_ATI_blend_equation_separate 1 + +#define GL_ALPHA_BLEND_EQUATION_ATI 0x883D + +GLAPI void GLAPIENTRY glBlendEquationSeparateATI( GLenum modeRGB, GLenum modeA ); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEATIPROC) (GLenum modeRGB, GLenum modeA); + +#endif /* GL_ATI_blend_equation_separate */ + + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +typedef void* GLeglImageOES; +#endif + +#ifndef GL_OES_EGL_image +#define GL_OES_EGL_image 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image); +GLAPI void APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image); +#endif +typedef void (APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); +typedef void (APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image); +#endif + + +/** + ** NOTE!!!!! If you add new functions to this file, or update + ** glext.h be sure to regenerate the gl_mangle.h file. See comments + ** in that file for details. + **/ + + + +/********************************************************************** + * Begin system-specific stuff + */ +#if defined(PRAGMA_EXPORT_SUPPORTED) +#pragma export off +#endif + +#if defined(macintosh) && PRAGMA_IMPORT_SUPPORTED +#pragma import off +#endif +/* + * End system-specific stuff + **********************************************************************/ + + +#ifdef __cplusplus +} +#endif + +#endif /* __gl_h_ */ diff --git a/include/GL/gl_mangle.h b/include/GL/gl_mangle.h new file mode 100644 index 0000000..3684803 --- /dev/null +++ b/include/GL/gl_mangle.h @@ -0,0 +1,2311 @@ +#if 0 +#define GL_MANGLE_C1 "DO NOT EDIT!!! - TO REGENERATE from gl.h, EXECUTE THIS FILE IN SHELL (/bin/sh) and save the output" +#define GL_MANGLE_C2 "This file is used to create GL function protypes and aliases for the function names" + files="gl.h glext.h" +#define GL_MANGLE_C3 "get regeneration header - copy everything in this file above the 'REGENERATE_TO_END' line" + awk '!done; /^\/\*REGENERATE_TO_END/ {done=1}' $0 + echo "" +#define GL_MANGLE_C4 get aliases + grep '^GLAPI' $files | sed -e 's/.*ENTRY gl\([^( ]*\).*$/#define gl\1 MANGLE(\1)/' | sort | uniq + echo "" + echo "#endif /* GL_MANGLE_H */" + exit +#endif /* REGENERATION */ + +/* + * If you compile Mesa with USE_MGL_NAMESPACE defined then you can link + * your application both with OpenGL and Mesa. The Mesa functions will + * be redefined so they are prefixed with "mgl" instead of "gl". + * Mgl contributed by Randy Frank (rfrank@rsinc.com) + * Regneration code contributed by Ray Tice (rayt@ma.ultra.net) + */ + +#ifndef GL_MANGLE_H +#define GL_MANGLE_H + +#ifndef MANGLE +#define MANGLE(x) mgl##x +#endif /*MANGLE*/ + +/*REGENERATE_TO_END-----------ALL LINES BELOW HERE GET REPLACED ON REGENERATION */ + +#define glAccum MANGLE(Accum) +#define glActiveProgramEXT MANGLE(ActiveProgramEXT) +#define glActiveShaderProgram MANGLE(ActiveShaderProgram) +#define glActiveStencilFaceEXT MANGLE(ActiveStencilFaceEXT) +#define glActiveTextureARB MANGLE(ActiveTextureARB) +#define glActiveTexture MANGLE(ActiveTexture) +#define glActiveVaryingNV MANGLE(ActiveVaryingNV) +#define glAlphaFragmentOp1ATI MANGLE(AlphaFragmentOp1ATI) +#define glAlphaFragmentOp2ATI MANGLE(AlphaFragmentOp2ATI) +#define glAlphaFragmentOp3ATI MANGLE(AlphaFragmentOp3ATI) +#define glAlphaFunc MANGLE(AlphaFunc) +#define glApplyTextureEXT MANGLE(ApplyTextureEXT) +#define glAreProgramsResidentNV MANGLE(AreProgramsResidentNV) +#define glAreTexturesResidentEXT MANGLE(AreTexturesResidentEXT) +#define glAreTexturesResident MANGLE(AreTexturesResident) +#define glArrayElementEXT MANGLE(ArrayElementEXT) +#define glArrayElement MANGLE(ArrayElement) +#define glArrayObjectATI MANGLE(ArrayObjectATI) +#define glAsyncMarkerSGIX MANGLE(AsyncMarkerSGIX) +#define glAttachObjectARB MANGLE(AttachObjectARB) +#define glAttachShader MANGLE(AttachShader) +#define glBeginConditionalRender MANGLE(BeginConditionalRender) +#define glBeginConditionalRenderNV MANGLE(BeginConditionalRenderNV) +#define glBeginFragmentShaderATI MANGLE(BeginFragmentShaderATI) +#define glBegin MANGLE(Begin) +#define glBeginOcclusionQueryNV MANGLE(BeginOcclusionQueryNV) +#define glBeginPerfMonitorAMD MANGLE(BeginPerfMonitorAMD) +#define glBeginQueryARB MANGLE(BeginQueryARB) +#define glBeginQueryIndexed MANGLE(BeginQueryIndexed) +#define glBeginQuery MANGLE(BeginQuery) +#define glBeginTransformFeedbackEXT MANGLE(BeginTransformFeedbackEXT) +#define glBeginTransformFeedback MANGLE(BeginTransformFeedback) +#define glBeginTransformFeedbackNV MANGLE(BeginTransformFeedbackNV) +#define glBeginVertexShaderEXT MANGLE(BeginVertexShaderEXT) +#define glBeginVideoCaptureNV MANGLE(BeginVideoCaptureNV) +#define glBindAttribLocationARB MANGLE(BindAttribLocationARB) +#define glBindAttribLocation MANGLE(BindAttribLocation) +#define glBindBufferARB MANGLE(BindBufferARB) +#define glBindBufferBaseEXT MANGLE(BindBufferBaseEXT) +#define glBindBufferBase MANGLE(BindBufferBase) +#define glBindBufferBaseNV MANGLE(BindBufferBaseNV) +#define glBindBuffer MANGLE(BindBuffer) +#define glBindBufferOffsetEXT MANGLE(BindBufferOffsetEXT) +#define glBindBufferOffsetNV MANGLE(BindBufferOffsetNV) +#define glBindBufferRangeEXT MANGLE(BindBufferRangeEXT) +#define glBindBufferRange MANGLE(BindBufferRange) +#define glBindBufferRangeNV MANGLE(BindBufferRangeNV) +#define glBindFragDataLocationEXT MANGLE(BindFragDataLocationEXT) +#define glBindFragDataLocationIndexed MANGLE(BindFragDataLocationIndexed) +#define glBindFragDataLocation MANGLE(BindFragDataLocation) +#define glBindFragmentShaderATI MANGLE(BindFragmentShaderATI) +#define glBindFramebufferEXT MANGLE(BindFramebufferEXT) +#define glBindFramebuffer MANGLE(BindFramebuffer) +#define glBindImageTextureEXT MANGLE(BindImageTextureEXT) +#define glBindLightParameterEXT MANGLE(BindLightParameterEXT) +#define glBindMaterialParameterEXT MANGLE(BindMaterialParameterEXT) +#define glBindMultiTextureEXT MANGLE(BindMultiTextureEXT) +#define glBindParameterEXT MANGLE(BindParameterEXT) +#define glBindProgramARB MANGLE(BindProgramARB) +#define glBindProgramNV MANGLE(BindProgramNV) +#define glBindProgramPipeline MANGLE(BindProgramPipeline) +#define glBindRenderbufferEXT MANGLE(BindRenderbufferEXT) +#define glBindRenderbuffer MANGLE(BindRenderbuffer) +#define glBindSampler MANGLE(BindSampler) +#define glBindTexGenParameterEXT MANGLE(BindTexGenParameterEXT) +#define glBindTextureEXT MANGLE(BindTextureEXT) +#define glBindTexture MANGLE(BindTexture) +#define glBindTextureUnitParameterEXT MANGLE(BindTextureUnitParameterEXT) +#define glBindTransformFeedback MANGLE(BindTransformFeedback) +#define glBindTransformFeedbackNV MANGLE(BindTransformFeedbackNV) +#define glBindVertexArrayAPPLE MANGLE(BindVertexArrayAPPLE) +#define glBindVertexArray MANGLE(BindVertexArray) +#define glBindVertexShaderEXT MANGLE(BindVertexShaderEXT) +#define glBindVideoCaptureStreamBufferNV MANGLE(BindVideoCaptureStreamBufferNV) +#define glBindVideoCaptureStreamTextureNV MANGLE(BindVideoCaptureStreamTextureNV) +#define glBinormal3bEXT MANGLE(Binormal3bEXT) +#define glBinormal3bvEXT MANGLE(Binormal3bvEXT) +#define glBinormal3dEXT MANGLE(Binormal3dEXT) +#define glBinormal3dvEXT MANGLE(Binormal3dvEXT) +#define glBinormal3fEXT MANGLE(Binormal3fEXT) +#define glBinormal3fvEXT MANGLE(Binormal3fvEXT) +#define glBinormal3iEXT MANGLE(Binormal3iEXT) +#define glBinormal3ivEXT MANGLE(Binormal3ivEXT) +#define glBinormal3sEXT MANGLE(Binormal3sEXT) +#define glBinormal3svEXT MANGLE(Binormal3svEXT) +#define glBinormalPointerEXT MANGLE(BinormalPointerEXT) +#define glBitmap MANGLE(Bitmap) +#define glBlendColorEXT MANGLE(BlendColorEXT) +#define glBlendColor MANGLE(BlendColor) +#define glBlendEquationEXT MANGLE(BlendEquationEXT) +#define glBlendEquationiARB MANGLE(BlendEquationiARB) +#define glBlendEquationi MANGLE(BlendEquationi) +#define glBlendEquationIndexedAMD MANGLE(BlendEquationIndexedAMD) +#define glBlendEquation MANGLE(BlendEquation) +#define glBlendEquationSeparateATI MANGLE(BlendEquationSeparateATI) +#define glBlendEquationSeparateEXT MANGLE(BlendEquationSeparateEXT) +#define glBlendEquationSeparateiARB MANGLE(BlendEquationSeparateiARB) +#define glBlendEquationSeparatei MANGLE(BlendEquationSeparatei) +#define glBlendEquationSeparateIndexedAMD MANGLE(BlendEquationSeparateIndexedAMD) +#define glBlendEquationSeparate MANGLE(BlendEquationSeparate) +#define glBlendFunciARB MANGLE(BlendFunciARB) +#define glBlendFunci MANGLE(BlendFunci) +#define glBlendFuncIndexedAMD MANGLE(BlendFuncIndexedAMD) +#define glBlendFunc MANGLE(BlendFunc) +#define glBlendFuncSeparateEXT MANGLE(BlendFuncSeparateEXT) +#define glBlendFuncSeparateiARB MANGLE(BlendFuncSeparateiARB) +#define glBlendFuncSeparatei MANGLE(BlendFuncSeparatei) +#define glBlendFuncSeparateIndexedAMD MANGLE(BlendFuncSeparateIndexedAMD) +#define glBlendFuncSeparateINGR MANGLE(BlendFuncSeparateINGR) +#define glBlendFuncSeparate MANGLE(BlendFuncSeparate) +#define glBlitFramebufferEXT MANGLE(BlitFramebufferEXT) +#define glBlitFramebuffer MANGLE(BlitFramebuffer) +#define glBufferAddressRangeNV MANGLE(BufferAddressRangeNV) +#define glBufferDataARB MANGLE(BufferDataARB) +#define glBufferData MANGLE(BufferData) +#define glBufferParameteriAPPLE MANGLE(BufferParameteriAPPLE) +#define glBufferSubDataARB MANGLE(BufferSubDataARB) +#define glBufferSubData MANGLE(BufferSubData) +#define glCallList MANGLE(CallList) +#define glCallLists MANGLE(CallLists) +#define glCheckFramebufferStatusEXT MANGLE(CheckFramebufferStatusEXT) +#define glCheckFramebufferStatus MANGLE(CheckFramebufferStatus) +#define glCheckNamedFramebufferStatusEXT MANGLE(CheckNamedFramebufferStatusEXT) +#define glClampColorARB MANGLE(ClampColorARB) +#define glClampColor MANGLE(ClampColor) +#define glClearAccum MANGLE(ClearAccum) +#define glClearBufferfi MANGLE(ClearBufferfi) +#define glClearBufferfv MANGLE(ClearBufferfv) +#define glClearBufferiv MANGLE(ClearBufferiv) +#define glClearBufferuiv MANGLE(ClearBufferuiv) +#define glClearColorIiEXT MANGLE(ClearColorIiEXT) +#define glClearColorIuiEXT MANGLE(ClearColorIuiEXT) +#define glClearColor MANGLE(ClearColor) +#define glClearDebugLogMESA MANGLE(ClearDebugLogMESA) +#define glClearDepthdNV MANGLE(ClearDepthdNV) +#define glClearDepthf MANGLE(ClearDepthf) +#define glClearDepth MANGLE(ClearDepth) +#define glClearIndex MANGLE(ClearIndex) +#define glClear MANGLE(Clear) +#define glClearStencil MANGLE(ClearStencil) +#define glClientActiveTextureARB MANGLE(ClientActiveTextureARB) +#define glClientActiveTexture MANGLE(ClientActiveTexture) +#define glClientActiveVertexStreamATI MANGLE(ClientActiveVertexStreamATI) +#define glClientAttribDefaultEXT MANGLE(ClientAttribDefaultEXT) +#define glClientWaitSync MANGLE(ClientWaitSync) +#define glClipPlane MANGLE(ClipPlane) +#define glColor3b MANGLE(Color3b) +#define glColor3bv MANGLE(Color3bv) +#define glColor3d MANGLE(Color3d) +#define glColor3dv MANGLE(Color3dv) +#define glColor3f MANGLE(Color3f) +#define glColor3fVertex3fSUN MANGLE(Color3fVertex3fSUN) +#define glColor3fVertex3fvSUN MANGLE(Color3fVertex3fvSUN) +#define glColor3fv MANGLE(Color3fv) +#define glColor3hNV MANGLE(Color3hNV) +#define glColor3hvNV MANGLE(Color3hvNV) +#define glColor3i MANGLE(Color3i) +#define glColor3iv MANGLE(Color3iv) +#define glColor3s MANGLE(Color3s) +#define glColor3sv MANGLE(Color3sv) +#define glColor3ub MANGLE(Color3ub) +#define glColor3ubv MANGLE(Color3ubv) +#define glColor3ui MANGLE(Color3ui) +#define glColor3uiv MANGLE(Color3uiv) +#define glColor3us MANGLE(Color3us) +#define glColor3usv MANGLE(Color3usv) +#define glColor4b MANGLE(Color4b) +#define glColor4bv MANGLE(Color4bv) +#define glColor4d MANGLE(Color4d) +#define glColor4dv MANGLE(Color4dv) +#define glColor4f MANGLE(Color4f) +#define glColor4fNormal3fVertex3fSUN MANGLE(Color4fNormal3fVertex3fSUN) +#define glColor4fNormal3fVertex3fvSUN MANGLE(Color4fNormal3fVertex3fvSUN) +#define glColor4fv MANGLE(Color4fv) +#define glColor4hNV MANGLE(Color4hNV) +#define glColor4hvNV MANGLE(Color4hvNV) +#define glColor4i MANGLE(Color4i) +#define glColor4iv MANGLE(Color4iv) +#define glColor4s MANGLE(Color4s) +#define glColor4sv MANGLE(Color4sv) +#define glColor4ub MANGLE(Color4ub) +#define glColor4ubVertex2fSUN MANGLE(Color4ubVertex2fSUN) +#define glColor4ubVertex2fvSUN MANGLE(Color4ubVertex2fvSUN) +#define glColor4ubVertex3fSUN MANGLE(Color4ubVertex3fSUN) +#define glColor4ubVertex3fvSUN MANGLE(Color4ubVertex3fvSUN) +#define glColor4ubv MANGLE(Color4ubv) +#define glColor4ui MANGLE(Color4ui) +#define glColor4uiv MANGLE(Color4uiv) +#define glColor4us MANGLE(Color4us) +#define glColor4usv MANGLE(Color4usv) +#define glColorFormatNV MANGLE(ColorFormatNV) +#define glColorFragmentOp1ATI MANGLE(ColorFragmentOp1ATI) +#define glColorFragmentOp2ATI MANGLE(ColorFragmentOp2ATI) +#define glColorFragmentOp3ATI MANGLE(ColorFragmentOp3ATI) +#define glColorMaski MANGLE(ColorMaski) +#define glColorMaskIndexedEXT MANGLE(ColorMaskIndexedEXT) +#define glColorMask MANGLE(ColorMask) +#define glColorMaterial MANGLE(ColorMaterial) +#define glColorP3ui MANGLE(ColorP3ui) +#define glColorP3uiv MANGLE(ColorP3uiv) +#define glColorP4ui MANGLE(ColorP4ui) +#define glColorP4uiv MANGLE(ColorP4uiv) +#define glColorPointerEXT MANGLE(ColorPointerEXT) +#define glColorPointerListIBM MANGLE(ColorPointerListIBM) +#define glColorPointer MANGLE(ColorPointer) +#define glColorPointervINTEL MANGLE(ColorPointervINTEL) +#define glColorSubTableEXT MANGLE(ColorSubTableEXT) +#define glColorSubTable MANGLE(ColorSubTable) +#define glColorTableEXT MANGLE(ColorTableEXT) +#define glColorTable MANGLE(ColorTable) +#define glColorTableParameterfv MANGLE(ColorTableParameterfv) +#define glColorTableParameterfvSGI MANGLE(ColorTableParameterfvSGI) +#define glColorTableParameteriv MANGLE(ColorTableParameteriv) +#define glColorTableParameterivSGI MANGLE(ColorTableParameterivSGI) +#define glColorTableSGI MANGLE(ColorTableSGI) +#define glCombinerInputNV MANGLE(CombinerInputNV) +#define glCombinerOutputNV MANGLE(CombinerOutputNV) +#define glCombinerParameterfNV MANGLE(CombinerParameterfNV) +#define glCombinerParameterfvNV MANGLE(CombinerParameterfvNV) +#define glCombinerParameteriNV MANGLE(CombinerParameteriNV) +#define glCombinerParameterivNV MANGLE(CombinerParameterivNV) +#define glCombinerStageParameterfvNV MANGLE(CombinerStageParameterfvNV) +#define glCompileShaderARB MANGLE(CompileShaderARB) +#define glCompileShaderIncludeARB MANGLE(CompileShaderIncludeARB) +#define glCompileShader MANGLE(CompileShader) +#define glCompressedMultiTexImage1DEXT MANGLE(CompressedMultiTexImage1DEXT) +#define glCompressedMultiTexImage2DEXT MANGLE(CompressedMultiTexImage2DEXT) +#define glCompressedMultiTexImage3DEXT MANGLE(CompressedMultiTexImage3DEXT) +#define glCompressedMultiTexSubImage1DEXT MANGLE(CompressedMultiTexSubImage1DEXT) +#define glCompressedMultiTexSubImage2DEXT MANGLE(CompressedMultiTexSubImage2DEXT) +#define glCompressedMultiTexSubImage3DEXT MANGLE(CompressedMultiTexSubImage3DEXT) +#define glCompressedTexImage1DARB MANGLE(CompressedTexImage1DARB) +#define glCompressedTexImage1D MANGLE(CompressedTexImage1D) +#define glCompressedTexImage2DARB MANGLE(CompressedTexImage2DARB) +#define glCompressedTexImage2D MANGLE(CompressedTexImage2D) +#define glCompressedTexImage3DARB MANGLE(CompressedTexImage3DARB) +#define glCompressedTexImage3D MANGLE(CompressedTexImage3D) +#define glCompressedTexSubImage1DARB MANGLE(CompressedTexSubImage1DARB) +#define glCompressedTexSubImage1D MANGLE(CompressedTexSubImage1D) +#define glCompressedTexSubImage2DARB MANGLE(CompressedTexSubImage2DARB) +#define glCompressedTexSubImage2D MANGLE(CompressedTexSubImage2D) +#define glCompressedTexSubImage3DARB MANGLE(CompressedTexSubImage3DARB) +#define glCompressedTexSubImage3D MANGLE(CompressedTexSubImage3D) +#define glCompressedTextureImage1DEXT MANGLE(CompressedTextureImage1DEXT) +#define glCompressedTextureImage2DEXT MANGLE(CompressedTextureImage2DEXT) +#define glCompressedTextureImage3DEXT MANGLE(CompressedTextureImage3DEXT) +#define glCompressedTextureSubImage1DEXT MANGLE(CompressedTextureSubImage1DEXT) +#define glCompressedTextureSubImage2DEXT MANGLE(CompressedTextureSubImage2DEXT) +#define glCompressedTextureSubImage3DEXT MANGLE(CompressedTextureSubImage3DEXT) +#define glConvolutionFilter1DEXT MANGLE(ConvolutionFilter1DEXT) +#define glConvolutionFilter1D MANGLE(ConvolutionFilter1D) +#define glConvolutionFilter2DEXT MANGLE(ConvolutionFilter2DEXT) +#define glConvolutionFilter2D MANGLE(ConvolutionFilter2D) +#define glConvolutionParameterfEXT MANGLE(ConvolutionParameterfEXT) +#define glConvolutionParameterf MANGLE(ConvolutionParameterf) +#define glConvolutionParameterfvEXT MANGLE(ConvolutionParameterfvEXT) +#define glConvolutionParameterfv MANGLE(ConvolutionParameterfv) +#define glConvolutionParameteriEXT MANGLE(ConvolutionParameteriEXT) +#define glConvolutionParameteri MANGLE(ConvolutionParameteri) +#define glConvolutionParameterivEXT MANGLE(ConvolutionParameterivEXT) +#define glConvolutionParameteriv MANGLE(ConvolutionParameteriv) +#define glCopyBufferSubData MANGLE(CopyBufferSubData) +#define glCopyColorSubTableEXT MANGLE(CopyColorSubTableEXT) +#define glCopyColorSubTable MANGLE(CopyColorSubTable) +#define glCopyColorTable MANGLE(CopyColorTable) +#define glCopyColorTableSGI MANGLE(CopyColorTableSGI) +#define glCopyConvolutionFilter1DEXT MANGLE(CopyConvolutionFilter1DEXT) +#define glCopyConvolutionFilter1D MANGLE(CopyConvolutionFilter1D) +#define glCopyConvolutionFilter2DEXT MANGLE(CopyConvolutionFilter2DEXT) +#define glCopyConvolutionFilter2D MANGLE(CopyConvolutionFilter2D) +#define glCopyImageSubDataNV MANGLE(CopyImageSubDataNV) +#define glCopyMultiTexImage1DEXT MANGLE(CopyMultiTexImage1DEXT) +#define glCopyMultiTexImage2DEXT MANGLE(CopyMultiTexImage2DEXT) +#define glCopyMultiTexSubImage1DEXT MANGLE(CopyMultiTexSubImage1DEXT) +#define glCopyMultiTexSubImage2DEXT MANGLE(CopyMultiTexSubImage2DEXT) +#define glCopyMultiTexSubImage3DEXT MANGLE(CopyMultiTexSubImage3DEXT) +#define glCopyPixels MANGLE(CopyPixels) +#define glCopyTexImage1DEXT MANGLE(CopyTexImage1DEXT) +#define glCopyTexImage1D MANGLE(CopyTexImage1D) +#define glCopyTexImage2DEXT MANGLE(CopyTexImage2DEXT) +#define glCopyTexImage2D MANGLE(CopyTexImage2D) +#define glCopyTexSubImage1DEXT MANGLE(CopyTexSubImage1DEXT) +#define glCopyTexSubImage1D MANGLE(CopyTexSubImage1D) +#define glCopyTexSubImage2DEXT MANGLE(CopyTexSubImage2DEXT) +#define glCopyTexSubImage2D MANGLE(CopyTexSubImage2D) +#define glCopyTexSubImage3DEXT MANGLE(CopyTexSubImage3DEXT) +#define glCopyTexSubImage3D MANGLE(CopyTexSubImage3D) +#define glCopyTextureImage1DEXT MANGLE(CopyTextureImage1DEXT) +#define glCopyTextureImage2DEXT MANGLE(CopyTextureImage2DEXT) +#define glCopyTextureSubImage1DEXT MANGLE(CopyTextureSubImage1DEXT) +#define glCopyTextureSubImage2DEXT MANGLE(CopyTextureSubImage2DEXT) +#define glCopyTextureSubImage3DEXT MANGLE(CopyTextureSubImage3DEXT) +#define glCreateDebugObjectMESA MANGLE(CreateDebugObjectMESA) +#define glCreateProgram MANGLE(CreateProgram) +#define glCreateProgramObjectARB MANGLE(CreateProgramObjectARB) +#define glCreateShader MANGLE(CreateShader) +#define glCreateShaderObjectARB MANGLE(CreateShaderObjectARB) +#define glCreateShaderProgramEXT MANGLE(CreateShaderProgramEXT) +#define glCreateShaderProgramv MANGLE(CreateShaderProgramv) +#define glCreateSyncFromCLeventARB MANGLE(CreateSyncFromCLeventARB) +#define glCullFace MANGLE(CullFace) +#define glCullParameterdvEXT MANGLE(CullParameterdvEXT) +#define glCullParameterfvEXT MANGLE(CullParameterfvEXT) +#define glCurrentPaletteMatrixARB MANGLE(CurrentPaletteMatrixARB) +#define glDebugMessageCallbackAMD MANGLE(DebugMessageCallbackAMD) +#define glDebugMessageCallbackARB MANGLE(DebugMessageCallbackARB) +#define glDebugMessageControlARB MANGLE(DebugMessageControlARB) +#define glDebugMessageEnableAMD MANGLE(DebugMessageEnableAMD) +#define glDebugMessageInsertAMD MANGLE(DebugMessageInsertAMD) +#define glDebugMessageInsertARB MANGLE(DebugMessageInsertARB) +#define glDeformationMap3dSGIX MANGLE(DeformationMap3dSGIX) +#define glDeformationMap3fSGIX MANGLE(DeformationMap3fSGIX) +#define glDeformSGIX MANGLE(DeformSGIX) +#define glDeleteAsyncMarkersSGIX MANGLE(DeleteAsyncMarkersSGIX) +#define glDeleteBuffersARB MANGLE(DeleteBuffersARB) +#define glDeleteBuffers MANGLE(DeleteBuffers) +#define glDeleteFencesAPPLE MANGLE(DeleteFencesAPPLE) +#define glDeleteFencesNV MANGLE(DeleteFencesNV) +#define glDeleteFragmentShaderATI MANGLE(DeleteFragmentShaderATI) +#define glDeleteFramebuffersEXT MANGLE(DeleteFramebuffersEXT) +#define glDeleteFramebuffers MANGLE(DeleteFramebuffers) +#define glDeleteLists MANGLE(DeleteLists) +#define glDeleteNamedStringARB MANGLE(DeleteNamedStringARB) +#define glDeleteNamesAMD MANGLE(DeleteNamesAMD) +#define glDeleteObjectARB MANGLE(DeleteObjectARB) +#define glDeleteOcclusionQueriesNV MANGLE(DeleteOcclusionQueriesNV) +#define glDeletePerfMonitorsAMD MANGLE(DeletePerfMonitorsAMD) +#define glDeleteProgram MANGLE(DeleteProgram) +#define glDeleteProgramPipelines MANGLE(DeleteProgramPipelines) +#define glDeleteProgramsARB MANGLE(DeleteProgramsARB) +#define glDeleteProgramsNV MANGLE(DeleteProgramsNV) +#define glDeleteQueriesARB MANGLE(DeleteQueriesARB) +#define glDeleteQueries MANGLE(DeleteQueries) +#define glDeleteRenderbuffersEXT MANGLE(DeleteRenderbuffersEXT) +#define glDeleteRenderbuffers MANGLE(DeleteRenderbuffers) +#define glDeleteSamplers MANGLE(DeleteSamplers) +#define glDeleteShader MANGLE(DeleteShader) +#define glDeleteSync MANGLE(DeleteSync) +#define glDeleteTexturesEXT MANGLE(DeleteTexturesEXT) +#define glDeleteTextures MANGLE(DeleteTextures) +#define glDeleteTransformFeedbacks MANGLE(DeleteTransformFeedbacks) +#define glDeleteTransformFeedbacksNV MANGLE(DeleteTransformFeedbacksNV) +#define glDeleteVertexArraysAPPLE MANGLE(DeleteVertexArraysAPPLE) +#define glDeleteVertexArrays MANGLE(DeleteVertexArrays) +#define glDeleteVertexShaderEXT MANGLE(DeleteVertexShaderEXT) +#define glDepthBoundsdNV MANGLE(DepthBoundsdNV) +#define glDepthBoundsEXT MANGLE(DepthBoundsEXT) +#define glDepthFunc MANGLE(DepthFunc) +#define glDepthMask MANGLE(DepthMask) +#define glDepthRangeArrayv MANGLE(DepthRangeArrayv) +#define glDepthRangedNV MANGLE(DepthRangedNV) +#define glDepthRangef MANGLE(DepthRangef) +#define glDepthRangeIndexed MANGLE(DepthRangeIndexed) +#define glDepthRange MANGLE(DepthRange) +#define glDetachObjectARB MANGLE(DetachObjectARB) +#define glDetachShader MANGLE(DetachShader) +#define glDetailTexFuncSGIS MANGLE(DetailTexFuncSGIS) +#define glDisableClientStateIndexedEXT MANGLE(DisableClientStateIndexedEXT) +#define glDisableClientState MANGLE(DisableClientState) +#define glDisablei MANGLE(Disablei) +#define glDisableIndexedEXT MANGLE(DisableIndexedEXT) +#define glDisable MANGLE(Disable) +#define glDisableVariantClientStateEXT MANGLE(DisableVariantClientStateEXT) +#define glDisableVertexAttribAPPLE MANGLE(DisableVertexAttribAPPLE) +#define glDisableVertexAttribArrayARB MANGLE(DisableVertexAttribArrayARB) +#define glDisableVertexAttribArray MANGLE(DisableVertexAttribArray) +#define glDrawArraysEXT MANGLE(DrawArraysEXT) +#define glDrawArraysIndirect MANGLE(DrawArraysIndirect) +#define glDrawArraysInstancedARB MANGLE(DrawArraysInstancedARB) +#define glDrawArraysInstancedEXT MANGLE(DrawArraysInstancedEXT) +#define glDrawArraysInstanced MANGLE(DrawArraysInstanced) +#define glDrawArrays MANGLE(DrawArrays) +#define glDrawBuffer MANGLE(DrawBuffer) +#define glDrawBuffersARB MANGLE(DrawBuffersARB) +#define glDrawBuffersATI MANGLE(DrawBuffersATI) +#define glDrawBuffers MANGLE(DrawBuffers) +#define glDrawElementArrayAPPLE MANGLE(DrawElementArrayAPPLE) +#define glDrawElementArrayATI MANGLE(DrawElementArrayATI) +#define glDrawElementsBaseVertex MANGLE(DrawElementsBaseVertex) +#define glDrawElementsIndirect MANGLE(DrawElementsIndirect) +#define glDrawElementsInstancedARB MANGLE(DrawElementsInstancedARB) +#define glDrawElementsInstancedBaseVertex MANGLE(DrawElementsInstancedBaseVertex) +#define glDrawElementsInstancedEXT MANGLE(DrawElementsInstancedEXT) +#define glDrawElementsInstanced MANGLE(DrawElementsInstanced) +#define glDrawElements MANGLE(DrawElements) +#define glDrawMeshArraysSUN MANGLE(DrawMeshArraysSUN) +#define glDrawPixels MANGLE(DrawPixels) +#define glDrawRangeElementArrayAPPLE MANGLE(DrawRangeElementArrayAPPLE) +#define glDrawRangeElementArrayATI MANGLE(DrawRangeElementArrayATI) +#define glDrawRangeElementsBaseVertex MANGLE(DrawRangeElementsBaseVertex) +#define glDrawRangeElementsEXT MANGLE(DrawRangeElementsEXT) +#define glDrawRangeElements MANGLE(DrawRangeElements) +#define glDrawTransformFeedback MANGLE(DrawTransformFeedback) +#define glDrawTransformFeedbackNV MANGLE(DrawTransformFeedbackNV) +#define glDrawTransformFeedbackStream MANGLE(DrawTransformFeedbackStream) +#define glEdgeFlagFormatNV MANGLE(EdgeFlagFormatNV) +#define glEdgeFlag MANGLE(EdgeFlag) +#define glEdgeFlagPointerEXT MANGLE(EdgeFlagPointerEXT) +#define glEdgeFlagPointerListIBM MANGLE(EdgeFlagPointerListIBM) +#define glEdgeFlagPointer MANGLE(EdgeFlagPointer) +#define glEdgeFlagv MANGLE(EdgeFlagv) +#define glEGLImageTargetRenderbufferStorageOES MANGLE(EGLImageTargetRenderbufferStorageOES) +#define glEGLImageTargetTexture2DOES MANGLE(EGLImageTargetTexture2DOES) +#define glElementPointerAPPLE MANGLE(ElementPointerAPPLE) +#define glElementPointerATI MANGLE(ElementPointerATI) +#define glEnableClientStateIndexedEXT MANGLE(EnableClientStateIndexedEXT) +#define glEnableClientState MANGLE(EnableClientState) +#define glEnablei MANGLE(Enablei) +#define glEnableIndexedEXT MANGLE(EnableIndexedEXT) +#define glEnable MANGLE(Enable) +#define glEnableVariantClientStateEXT MANGLE(EnableVariantClientStateEXT) +#define glEnableVertexAttribAPPLE MANGLE(EnableVertexAttribAPPLE) +#define glEnableVertexAttribArrayARB MANGLE(EnableVertexAttribArrayARB) +#define glEnableVertexAttribArray MANGLE(EnableVertexAttribArray) +#define glEndConditionalRender MANGLE(EndConditionalRender) +#define glEndConditionalRenderNV MANGLE(EndConditionalRenderNV) +#define glEndFragmentShaderATI MANGLE(EndFragmentShaderATI) +#define glEndList MANGLE(EndList) +#define glEnd MANGLE(End) +#define glEndOcclusionQueryNV MANGLE(EndOcclusionQueryNV) +#define glEndPerfMonitorAMD MANGLE(EndPerfMonitorAMD) +#define glEndQueryARB MANGLE(EndQueryARB) +#define glEndQueryIndexed MANGLE(EndQueryIndexed) +#define glEndQuery MANGLE(EndQuery) +#define glEndTransformFeedbackEXT MANGLE(EndTransformFeedbackEXT) +#define glEndTransformFeedback MANGLE(EndTransformFeedback) +#define glEndTransformFeedbackNV MANGLE(EndTransformFeedbackNV) +#define glEndVertexShaderEXT MANGLE(EndVertexShaderEXT) +#define glEndVideoCaptureNV MANGLE(EndVideoCaptureNV) +#define glEvalCoord1d MANGLE(EvalCoord1d) +#define glEvalCoord1dv MANGLE(EvalCoord1dv) +#define glEvalCoord1f MANGLE(EvalCoord1f) +#define glEvalCoord1fv MANGLE(EvalCoord1fv) +#define glEvalCoord2d MANGLE(EvalCoord2d) +#define glEvalCoord2dv MANGLE(EvalCoord2dv) +#define glEvalCoord2f MANGLE(EvalCoord2f) +#define glEvalCoord2fv MANGLE(EvalCoord2fv) +#define glEvalMapsNV MANGLE(EvalMapsNV) +#define glEvalMesh1 MANGLE(EvalMesh1) +#define glEvalMesh2 MANGLE(EvalMesh2) +#define glEvalPoint1 MANGLE(EvalPoint1) +#define glEvalPoint2 MANGLE(EvalPoint2) +#define glExecuteProgramNV MANGLE(ExecuteProgramNV) +#define glExtractComponentEXT MANGLE(ExtractComponentEXT) +#define glFeedbackBuffer MANGLE(FeedbackBuffer) +#define glFenceSync MANGLE(FenceSync) +#define glFinalCombinerInputNV MANGLE(FinalCombinerInputNV) +#define glFinishAsyncSGIX MANGLE(FinishAsyncSGIX) +#define glFinishFenceAPPLE MANGLE(FinishFenceAPPLE) +#define glFinishFenceNV MANGLE(FinishFenceNV) +#define glFinish MANGLE(Finish) +#define glFinishObjectAPPLE MANGLE(FinishObjectAPPLE) +#define glFinishTextureSUNX MANGLE(FinishTextureSUNX) +#define glFlush MANGLE(Flush) +#define glFlushMappedBufferRangeAPPLE MANGLE(FlushMappedBufferRangeAPPLE) +#define glFlushMappedBufferRange MANGLE(FlushMappedBufferRange) +#define glFlushMappedNamedBufferRangeEXT MANGLE(FlushMappedNamedBufferRangeEXT) +#define glFlushPixelDataRangeNV MANGLE(FlushPixelDataRangeNV) +#define glFlushRasterSGIX MANGLE(FlushRasterSGIX) +#define glFlushVertexArrayRangeAPPLE MANGLE(FlushVertexArrayRangeAPPLE) +#define glFlushVertexArrayRangeNV MANGLE(FlushVertexArrayRangeNV) +#define glFogCoorddEXT MANGLE(FogCoorddEXT) +#define glFogCoordd MANGLE(FogCoordd) +#define glFogCoorddvEXT MANGLE(FogCoorddvEXT) +#define glFogCoorddv MANGLE(FogCoorddv) +#define glFogCoordfEXT MANGLE(FogCoordfEXT) +#define glFogCoordf MANGLE(FogCoordf) +#define glFogCoordFormatNV MANGLE(FogCoordFormatNV) +#define glFogCoordfvEXT MANGLE(FogCoordfvEXT) +#define glFogCoordfv MANGLE(FogCoordfv) +#define glFogCoordhNV MANGLE(FogCoordhNV) +#define glFogCoordhvNV MANGLE(FogCoordhvNV) +#define glFogCoordPointerEXT MANGLE(FogCoordPointerEXT) +#define glFogCoordPointerListIBM MANGLE(FogCoordPointerListIBM) +#define glFogCoordPointer MANGLE(FogCoordPointer) +#define glFogf MANGLE(Fogf) +#define glFogFuncSGIS MANGLE(FogFuncSGIS) +#define glFogfv MANGLE(Fogfv) +#define glFogi MANGLE(Fogi) +#define glFogiv MANGLE(Fogiv) +#define glFragmentColorMaterialSGIX MANGLE(FragmentColorMaterialSGIX) +#define glFragmentLightfSGIX MANGLE(FragmentLightfSGIX) +#define glFragmentLightfvSGIX MANGLE(FragmentLightfvSGIX) +#define glFragmentLightiSGIX MANGLE(FragmentLightiSGIX) +#define glFragmentLightivSGIX MANGLE(FragmentLightivSGIX) +#define glFragmentLightModelfSGIX MANGLE(FragmentLightModelfSGIX) +#define glFragmentLightModelfvSGIX MANGLE(FragmentLightModelfvSGIX) +#define glFragmentLightModeliSGIX MANGLE(FragmentLightModeliSGIX) +#define glFragmentLightModelivSGIX MANGLE(FragmentLightModelivSGIX) +#define glFragmentMaterialfSGIX MANGLE(FragmentMaterialfSGIX) +#define glFragmentMaterialfvSGIX MANGLE(FragmentMaterialfvSGIX) +#define glFragmentMaterialiSGIX MANGLE(FragmentMaterialiSGIX) +#define glFragmentMaterialivSGIX MANGLE(FragmentMaterialivSGIX) +#define glFramebufferDrawBufferEXT MANGLE(FramebufferDrawBufferEXT) +#define glFramebufferDrawBuffersEXT MANGLE(FramebufferDrawBuffersEXT) +#define glFramebufferReadBufferEXT MANGLE(FramebufferReadBufferEXT) +#define glFramebufferRenderbufferEXT MANGLE(FramebufferRenderbufferEXT) +#define glFramebufferRenderbuffer MANGLE(FramebufferRenderbuffer) +#define glFramebufferTexture1DEXT MANGLE(FramebufferTexture1DEXT) +#define glFramebufferTexture1D MANGLE(FramebufferTexture1D) +#define glFramebufferTexture2DEXT MANGLE(FramebufferTexture2DEXT) +#define glFramebufferTexture2D MANGLE(FramebufferTexture2D) +#define glFramebufferTexture3DEXT MANGLE(FramebufferTexture3DEXT) +#define glFramebufferTexture3D MANGLE(FramebufferTexture3D) +#define glFramebufferTextureARB MANGLE(FramebufferTextureARB) +#define glFramebufferTextureEXT MANGLE(FramebufferTextureEXT) +#define glFramebufferTextureFaceARB MANGLE(FramebufferTextureFaceARB) +#define glFramebufferTextureFaceEXT MANGLE(FramebufferTextureFaceEXT) +#define glFramebufferTextureLayerARB MANGLE(FramebufferTextureLayerARB) +#define glFramebufferTextureLayerEXT MANGLE(FramebufferTextureLayerEXT) +#define glFramebufferTextureLayer MANGLE(FramebufferTextureLayer) +#define glFramebufferTexture MANGLE(FramebufferTexture) +#define glFrameTerminatorGREMEDY MANGLE(FrameTerminatorGREMEDY) +#define glFrameZoomSGIX MANGLE(FrameZoomSGIX) +#define glFreeObjectBufferATI MANGLE(FreeObjectBufferATI) +#define glFrontFace MANGLE(FrontFace) +#define glFrustum MANGLE(Frustum) +#define glGenAsyncMarkersSGIX MANGLE(GenAsyncMarkersSGIX) +#define glGenBuffersARB MANGLE(GenBuffersARB) +#define glGenBuffers MANGLE(GenBuffers) +#define glGenerateMipmapEXT MANGLE(GenerateMipmapEXT) +#define glGenerateMipmap MANGLE(GenerateMipmap) +#define glGenerateMultiTexMipmapEXT MANGLE(GenerateMultiTexMipmapEXT) +#define glGenerateTextureMipmapEXT MANGLE(GenerateTextureMipmapEXT) +#define glGenFencesAPPLE MANGLE(GenFencesAPPLE) +#define glGenFencesNV MANGLE(GenFencesNV) +#define glGenFragmentShadersATI MANGLE(GenFragmentShadersATI) +#define glGenFramebuffersEXT MANGLE(GenFramebuffersEXT) +#define glGenFramebuffers MANGLE(GenFramebuffers) +#define glGenLists MANGLE(GenLists) +#define glGenNamesAMD MANGLE(GenNamesAMD) +#define glGenOcclusionQueriesNV MANGLE(GenOcclusionQueriesNV) +#define glGenPerfMonitorsAMD MANGLE(GenPerfMonitorsAMD) +#define glGenProgramPipelines MANGLE(GenProgramPipelines) +#define glGenProgramsARB MANGLE(GenProgramsARB) +#define glGenProgramsNV MANGLE(GenProgramsNV) +#define glGenQueriesARB MANGLE(GenQueriesARB) +#define glGenQueries MANGLE(GenQueries) +#define glGenRenderbuffersEXT MANGLE(GenRenderbuffersEXT) +#define glGenRenderbuffers MANGLE(GenRenderbuffers) +#define glGenSamplers MANGLE(GenSamplers) +#define glGenSymbolsEXT MANGLE(GenSymbolsEXT) +#define glGenTexturesEXT MANGLE(GenTexturesEXT) +#define glGenTextures MANGLE(GenTextures) +#define glGenTransformFeedbacks MANGLE(GenTransformFeedbacks) +#define glGenTransformFeedbacksNV MANGLE(GenTransformFeedbacksNV) +#define glGenVertexArraysAPPLE MANGLE(GenVertexArraysAPPLE) +#define glGenVertexArrays MANGLE(GenVertexArrays) +#define glGenVertexShadersEXT MANGLE(GenVertexShadersEXT) +#define glGetActiveAttribARB MANGLE(GetActiveAttribARB) +#define glGetActiveAttrib MANGLE(GetActiveAttrib) +#define glGetActiveSubroutineName MANGLE(GetActiveSubroutineName) +#define glGetActiveSubroutineUniformiv MANGLE(GetActiveSubroutineUniformiv) +#define glGetActiveSubroutineUniformName MANGLE(GetActiveSubroutineUniformName) +#define glGetActiveUniformARB MANGLE(GetActiveUniformARB) +#define glGetActiveUniformBlockiv MANGLE(GetActiveUniformBlockiv) +#define glGetActiveUniformBlockName MANGLE(GetActiveUniformBlockName) +#define glGetActiveUniform MANGLE(GetActiveUniform) +#define glGetActiveUniformName MANGLE(GetActiveUniformName) +#define glGetActiveUniformsiv MANGLE(GetActiveUniformsiv) +#define glGetActiveVaryingNV MANGLE(GetActiveVaryingNV) +#define glGetArrayObjectfvATI MANGLE(GetArrayObjectfvATI) +#define glGetArrayObjectivATI MANGLE(GetArrayObjectivATI) +#define glGetAttachedObjectsARB MANGLE(GetAttachedObjectsARB) +#define glGetAttachedShaders MANGLE(GetAttachedShaders) +#define glGetAttribLocationARB MANGLE(GetAttribLocationARB) +#define glGetAttribLocation MANGLE(GetAttribLocation) +#define glGetBooleanIndexedvEXT MANGLE(GetBooleanIndexedvEXT) +#define glGetBooleani_v MANGLE(GetBooleani_v) +#define glGetBooleanv MANGLE(GetBooleanv) +#define glGetBufferParameteri64v MANGLE(GetBufferParameteri64v) +#define glGetBufferParameterivARB MANGLE(GetBufferParameterivARB) +#define glGetBufferParameteriv MANGLE(GetBufferParameteriv) +#define glGetBufferParameterui64vNV MANGLE(GetBufferParameterui64vNV) +#define glGetBufferPointervARB MANGLE(GetBufferPointervARB) +#define glGetBufferPointerv MANGLE(GetBufferPointerv) +#define glGetBufferSubDataARB MANGLE(GetBufferSubDataARB) +#define glGetBufferSubData MANGLE(GetBufferSubData) +#define glGetClipPlane MANGLE(GetClipPlane) +#define glGetColorTableEXT MANGLE(GetColorTableEXT) +#define glGetColorTable MANGLE(GetColorTable) +#define glGetColorTableParameterfvEXT MANGLE(GetColorTableParameterfvEXT) +#define glGetColorTableParameterfv MANGLE(GetColorTableParameterfv) +#define glGetColorTableParameterfvSGI MANGLE(GetColorTableParameterfvSGI) +#define glGetColorTableParameterivEXT MANGLE(GetColorTableParameterivEXT) +#define glGetColorTableParameteriv MANGLE(GetColorTableParameteriv) +#define glGetColorTableParameterivSGI MANGLE(GetColorTableParameterivSGI) +#define glGetColorTableSGI MANGLE(GetColorTableSGI) +#define glGetCombinerInputParameterfvNV MANGLE(GetCombinerInputParameterfvNV) +#define glGetCombinerInputParameterivNV MANGLE(GetCombinerInputParameterivNV) +#define glGetCombinerOutputParameterfvNV MANGLE(GetCombinerOutputParameterfvNV) +#define glGetCombinerOutputParameterivNV MANGLE(GetCombinerOutputParameterivNV) +#define glGetCombinerStageParameterfvNV MANGLE(GetCombinerStageParameterfvNV) +#define glGetCompressedMultiTexImageEXT MANGLE(GetCompressedMultiTexImageEXT) +#define glGetCompressedTexImageARB MANGLE(GetCompressedTexImageARB) +#define glGetCompressedTexImage MANGLE(GetCompressedTexImage) +#define glGetCompressedTextureImageEXT MANGLE(GetCompressedTextureImageEXT) +#define glGetConvolutionFilterEXT MANGLE(GetConvolutionFilterEXT) +#define glGetConvolutionFilter MANGLE(GetConvolutionFilter) +#define glGetConvolutionParameterfvEXT MANGLE(GetConvolutionParameterfvEXT) +#define glGetConvolutionParameterfv MANGLE(GetConvolutionParameterfv) +#define glGetConvolutionParameterivEXT MANGLE(GetConvolutionParameterivEXT) +#define glGetConvolutionParameteriv MANGLE(GetConvolutionParameteriv) +#define glGetDebugLogLengthMESA MANGLE(GetDebugLogLengthMESA) +#define glGetDebugLogMESA MANGLE(GetDebugLogMESA) +#define glGetDebugMessageLogAMD MANGLE(GetDebugMessageLogAMD) +#define glGetDebugMessageLogARB MANGLE(GetDebugMessageLogARB) +#define glGetDetailTexFuncSGIS MANGLE(GetDetailTexFuncSGIS) +#define glGetDoubleIndexedvEXT MANGLE(GetDoubleIndexedvEXT) +#define glGetDoublei_v MANGLE(GetDoublei_v) +#define glGetDoublev MANGLE(GetDoublev) +#define glGetError MANGLE(GetError) +#define glGetFenceivNV MANGLE(GetFenceivNV) +#define glGetFinalCombinerInputParameterfvNV MANGLE(GetFinalCombinerInputParameterfvNV) +#define glGetFinalCombinerInputParameterivNV MANGLE(GetFinalCombinerInputParameterivNV) +#define glGetFloatIndexedvEXT MANGLE(GetFloatIndexedvEXT) +#define glGetFloati_v MANGLE(GetFloati_v) +#define glGetFloatv MANGLE(GetFloatv) +#define glGetFogFuncSGIS MANGLE(GetFogFuncSGIS) +#define glGetFragDataIndex MANGLE(GetFragDataIndex) +#define glGetFragDataLocationEXT MANGLE(GetFragDataLocationEXT) +#define glGetFragDataLocation MANGLE(GetFragDataLocation) +#define glGetFragmentLightfvSGIX MANGLE(GetFragmentLightfvSGIX) +#define glGetFragmentLightivSGIX MANGLE(GetFragmentLightivSGIX) +#define glGetFragmentMaterialfvSGIX MANGLE(GetFragmentMaterialfvSGIX) +#define glGetFragmentMaterialivSGIX MANGLE(GetFragmentMaterialivSGIX) +#define glGetFramebufferAttachmentParameterivEXT MANGLE(GetFramebufferAttachmentParameterivEXT) +#define glGetFramebufferAttachmentParameteriv MANGLE(GetFramebufferAttachmentParameteriv) +#define glGetFramebufferParameterivEXT MANGLE(GetFramebufferParameterivEXT) +#define glGetGraphicsResetStatusARB MANGLE(GetGraphicsResetStatusARB) +#define glGetHandleARB MANGLE(GetHandleARB) +#define glGetHistogramEXT MANGLE(GetHistogramEXT) +#define glGetHistogram MANGLE(GetHistogram) +#define glGetHistogramParameterfvEXT MANGLE(GetHistogramParameterfvEXT) +#define glGetHistogramParameterfv MANGLE(GetHistogramParameterfv) +#define glGetHistogramParameterivEXT MANGLE(GetHistogramParameterivEXT) +#define glGetHistogramParameteriv MANGLE(GetHistogramParameteriv) +#define glGetImageTransformParameterfvHP MANGLE(GetImageTransformParameterfvHP) +#define glGetImageTransformParameterivHP MANGLE(GetImageTransformParameterivHP) +#define glGetInfoLogARB MANGLE(GetInfoLogARB) +#define glGetInstrumentsSGIX MANGLE(GetInstrumentsSGIX) +#define glGetInteger64i_v MANGLE(GetInteger64i_v) +#define glGetInteger64v MANGLE(GetInteger64v) +#define glGetIntegerIndexedvEXT MANGLE(GetIntegerIndexedvEXT) +#define glGetIntegeri_v MANGLE(GetIntegeri_v) +#define glGetIntegerui64i_vNV MANGLE(GetIntegerui64i_vNV) +#define glGetIntegerui64vNV MANGLE(GetIntegerui64vNV) +#define glGetIntegerv MANGLE(GetIntegerv) +#define glGetInvariantBooleanvEXT MANGLE(GetInvariantBooleanvEXT) +#define glGetInvariantFloatvEXT MANGLE(GetInvariantFloatvEXT) +#define glGetInvariantIntegervEXT MANGLE(GetInvariantIntegervEXT) +#define glGetLightfv MANGLE(GetLightfv) +#define glGetLightiv MANGLE(GetLightiv) +#define glGetListParameterfvSGIX MANGLE(GetListParameterfvSGIX) +#define glGetListParameterivSGIX MANGLE(GetListParameterivSGIX) +#define glGetLocalConstantBooleanvEXT MANGLE(GetLocalConstantBooleanvEXT) +#define glGetLocalConstantFloatvEXT MANGLE(GetLocalConstantFloatvEXT) +#define glGetLocalConstantIntegervEXT MANGLE(GetLocalConstantIntegervEXT) +#define glGetMapAttribParameterfvNV MANGLE(GetMapAttribParameterfvNV) +#define glGetMapAttribParameterivNV MANGLE(GetMapAttribParameterivNV) +#define glGetMapControlPointsNV MANGLE(GetMapControlPointsNV) +#define glGetMapdv MANGLE(GetMapdv) +#define glGetMapfv MANGLE(GetMapfv) +#define glGetMapiv MANGLE(GetMapiv) +#define glGetMapParameterfvNV MANGLE(GetMapParameterfvNV) +#define glGetMapParameterivNV MANGLE(GetMapParameterivNV) +#define glGetMaterialfv MANGLE(GetMaterialfv) +#define glGetMaterialiv MANGLE(GetMaterialiv) +#define glGetMinmaxEXT MANGLE(GetMinmaxEXT) +#define glGetMinmax MANGLE(GetMinmax) +#define glGetMinmaxParameterfvEXT MANGLE(GetMinmaxParameterfvEXT) +#define glGetMinmaxParameterfv MANGLE(GetMinmaxParameterfv) +#define glGetMinmaxParameterivEXT MANGLE(GetMinmaxParameterivEXT) +#define glGetMinmaxParameteriv MANGLE(GetMinmaxParameteriv) +#define glGetMultisamplefv MANGLE(GetMultisamplefv) +#define glGetMultisamplefvNV MANGLE(GetMultisamplefvNV) +#define glGetMultiTexEnvfvEXT MANGLE(GetMultiTexEnvfvEXT) +#define glGetMultiTexEnvivEXT MANGLE(GetMultiTexEnvivEXT) +#define glGetMultiTexGendvEXT MANGLE(GetMultiTexGendvEXT) +#define glGetMultiTexGenfvEXT MANGLE(GetMultiTexGenfvEXT) +#define glGetMultiTexGenivEXT MANGLE(GetMultiTexGenivEXT) +#define glGetMultiTexImageEXT MANGLE(GetMultiTexImageEXT) +#define glGetMultiTexLevelParameterfvEXT MANGLE(GetMultiTexLevelParameterfvEXT) +#define glGetMultiTexLevelParameterivEXT MANGLE(GetMultiTexLevelParameterivEXT) +#define glGetMultiTexParameterfvEXT MANGLE(GetMultiTexParameterfvEXT) +#define glGetMultiTexParameterIivEXT MANGLE(GetMultiTexParameterIivEXT) +#define glGetMultiTexParameterIuivEXT MANGLE(GetMultiTexParameterIuivEXT) +#define glGetMultiTexParameterivEXT MANGLE(GetMultiTexParameterivEXT) +#define glGetNamedBufferParameterivEXT MANGLE(GetNamedBufferParameterivEXT) +#define glGetNamedBufferParameterui64vNV MANGLE(GetNamedBufferParameterui64vNV) +#define glGetNamedBufferPointervEXT MANGLE(GetNamedBufferPointervEXT) +#define glGetNamedBufferSubDataEXT MANGLE(GetNamedBufferSubDataEXT) +#define glGetNamedFramebufferAttachmentParameterivEXT MANGLE(GetNamedFramebufferAttachmentParameterivEXT) +#define glGetNamedProgramivEXT MANGLE(GetNamedProgramivEXT) +#define glGetNamedProgramLocalParameterdvEXT MANGLE(GetNamedProgramLocalParameterdvEXT) +#define glGetNamedProgramLocalParameterfvEXT MANGLE(GetNamedProgramLocalParameterfvEXT) +#define glGetNamedProgramLocalParameterIivEXT MANGLE(GetNamedProgramLocalParameterIivEXT) +#define glGetNamedProgramLocalParameterIuivEXT MANGLE(GetNamedProgramLocalParameterIuivEXT) +#define glGetNamedProgramStringEXT MANGLE(GetNamedProgramStringEXT) +#define glGetNamedRenderbufferParameterivEXT MANGLE(GetNamedRenderbufferParameterivEXT) +#define glGetNamedStringARB MANGLE(GetNamedStringARB) +#define glGetNamedStringivARB MANGLE(GetNamedStringivARB) +#define glGetnColorTableARB MANGLE(GetnColorTableARB) +#define glGetnCompressedTexImageARB MANGLE(GetnCompressedTexImageARB) +#define glGetnConvolutionFilterARB MANGLE(GetnConvolutionFilterARB) +#define glGetnHistogramARB MANGLE(GetnHistogramARB) +#define glGetnMapdvARB MANGLE(GetnMapdvARB) +#define glGetnMapfvARB MANGLE(GetnMapfvARB) +#define glGetnMapivARB MANGLE(GetnMapivARB) +#define glGetnMinmaxARB MANGLE(GetnMinmaxARB) +#define glGetnPixelMapfvARB MANGLE(GetnPixelMapfvARB) +#define glGetnPixelMapuivARB MANGLE(GetnPixelMapuivARB) +#define glGetnPixelMapusvARB MANGLE(GetnPixelMapusvARB) +#define glGetnPolygonStippleARB MANGLE(GetnPolygonStippleARB) +#define glGetnSeparableFilterARB MANGLE(GetnSeparableFilterARB) +#define glGetnTexImageARB MANGLE(GetnTexImageARB) +#define glGetnUniformdvARB MANGLE(GetnUniformdvARB) +#define glGetnUniformfvARB MANGLE(GetnUniformfvARB) +#define glGetnUniformivARB MANGLE(GetnUniformivARB) +#define glGetnUniformuivARB MANGLE(GetnUniformuivARB) +#define glGetObjectBufferfvATI MANGLE(GetObjectBufferfvATI) +#define glGetObjectBufferivATI MANGLE(GetObjectBufferivATI) +#define glGetObjectParameterfvARB MANGLE(GetObjectParameterfvARB) +#define glGetObjectParameterivAPPLE MANGLE(GetObjectParameterivAPPLE) +#define glGetObjectParameterivARB MANGLE(GetObjectParameterivARB) +#define glGetOcclusionQueryivNV MANGLE(GetOcclusionQueryivNV) +#define glGetOcclusionQueryuivNV MANGLE(GetOcclusionQueryuivNV) +#define glGetPerfMonitorCounterDataAMD MANGLE(GetPerfMonitorCounterDataAMD) +#define glGetPerfMonitorCounterInfoAMD MANGLE(GetPerfMonitorCounterInfoAMD) +#define glGetPerfMonitorCountersAMD MANGLE(GetPerfMonitorCountersAMD) +#define glGetPerfMonitorCounterStringAMD MANGLE(GetPerfMonitorCounterStringAMD) +#define glGetPerfMonitorGroupsAMD MANGLE(GetPerfMonitorGroupsAMD) +#define glGetPerfMonitorGroupStringAMD MANGLE(GetPerfMonitorGroupStringAMD) +#define glGetPixelMapfv MANGLE(GetPixelMapfv) +#define glGetPixelMapuiv MANGLE(GetPixelMapuiv) +#define glGetPixelMapusv MANGLE(GetPixelMapusv) +#define glGetPixelTexGenParameterfvSGIS MANGLE(GetPixelTexGenParameterfvSGIS) +#define glGetPixelTexGenParameterivSGIS MANGLE(GetPixelTexGenParameterivSGIS) +#define glGetPointerIndexedvEXT MANGLE(GetPointerIndexedvEXT) +#define glGetPointervEXT MANGLE(GetPointervEXT) +#define glGetPointerv MANGLE(GetPointerv) +#define glGetPolygonStipple MANGLE(GetPolygonStipple) +#define glGetProgramBinary MANGLE(GetProgramBinary) +#define glGetProgramEnvParameterdvARB MANGLE(GetProgramEnvParameterdvARB) +#define glGetProgramEnvParameterfvARB MANGLE(GetProgramEnvParameterfvARB) +#define glGetProgramEnvParameterIivNV MANGLE(GetProgramEnvParameterIivNV) +#define glGetProgramEnvParameterIuivNV MANGLE(GetProgramEnvParameterIuivNV) +#define glGetProgramInfoLog MANGLE(GetProgramInfoLog) +#define glGetProgramivARB MANGLE(GetProgramivARB) +#define glGetProgramiv MANGLE(GetProgramiv) +#define glGetProgramivNV MANGLE(GetProgramivNV) +#define glGetProgramLocalParameterdvARB MANGLE(GetProgramLocalParameterdvARB) +#define glGetProgramLocalParameterfvARB MANGLE(GetProgramLocalParameterfvARB) +#define glGetProgramLocalParameterIivNV MANGLE(GetProgramLocalParameterIivNV) +#define glGetProgramLocalParameterIuivNV MANGLE(GetProgramLocalParameterIuivNV) +#define glGetProgramNamedParameterdvNV MANGLE(GetProgramNamedParameterdvNV) +#define glGetProgramNamedParameterfvNV MANGLE(GetProgramNamedParameterfvNV) +#define glGetProgramParameterdvNV MANGLE(GetProgramParameterdvNV) +#define glGetProgramParameterfvNV MANGLE(GetProgramParameterfvNV) +#define glGetProgramPipelineInfoLog MANGLE(GetProgramPipelineInfoLog) +#define glGetProgramPipelineiv MANGLE(GetProgramPipelineiv) +#define glGetProgramRegisterfvMESA MANGLE(GetProgramRegisterfvMESA) +#define glGetProgramStageiv MANGLE(GetProgramStageiv) +#define glGetProgramStringARB MANGLE(GetProgramStringARB) +#define glGetProgramStringNV MANGLE(GetProgramStringNV) +#define glGetProgramSubroutineParameteruivNV MANGLE(GetProgramSubroutineParameteruivNV) +#define glGetQueryIndexediv MANGLE(GetQueryIndexediv) +#define glGetQueryivARB MANGLE(GetQueryivARB) +#define glGetQueryiv MANGLE(GetQueryiv) +#define glGetQueryObjecti64vEXT MANGLE(GetQueryObjecti64vEXT) +#define glGetQueryObjecti64v MANGLE(GetQueryObjecti64v) +#define glGetQueryObjectivARB MANGLE(GetQueryObjectivARB) +#define glGetQueryObjectiv MANGLE(GetQueryObjectiv) +#define glGetQueryObjectui64vEXT MANGLE(GetQueryObjectui64vEXT) +#define glGetQueryObjectui64v MANGLE(GetQueryObjectui64v) +#define glGetQueryObjectuivARB MANGLE(GetQueryObjectuivARB) +#define glGetQueryObjectuiv MANGLE(GetQueryObjectuiv) +#define glGetRenderbufferParameterivEXT MANGLE(GetRenderbufferParameterivEXT) +#define glGetRenderbufferParameteriv MANGLE(GetRenderbufferParameteriv) +#define glGetSamplerParameterfv MANGLE(GetSamplerParameterfv) +#define glGetSamplerParameterIiv MANGLE(GetSamplerParameterIiv) +#define glGetSamplerParameterIuiv MANGLE(GetSamplerParameterIuiv) +#define glGetSamplerParameteriv MANGLE(GetSamplerParameteriv) +#define glGetSeparableFilterEXT MANGLE(GetSeparableFilterEXT) +#define glGetSeparableFilter MANGLE(GetSeparableFilter) +#define glGetShaderInfoLog MANGLE(GetShaderInfoLog) +#define glGetShaderiv MANGLE(GetShaderiv) +#define glGetShaderPrecisionFormat MANGLE(GetShaderPrecisionFormat) +#define glGetShaderSourceARB MANGLE(GetShaderSourceARB) +#define glGetShaderSource MANGLE(GetShaderSource) +#define glGetSharpenTexFuncSGIS MANGLE(GetSharpenTexFuncSGIS) +#define glGetStringi MANGLE(GetStringi) +#define glGetString MANGLE(GetString) +#define glGetSubroutineIndex MANGLE(GetSubroutineIndex) +#define glGetSubroutineUniformLocation MANGLE(GetSubroutineUniformLocation) +#define glGetSynciv MANGLE(GetSynciv) +#define glGetTexBumpParameterfvATI MANGLE(GetTexBumpParameterfvATI) +#define glGetTexBumpParameterivATI MANGLE(GetTexBumpParameterivATI) +#define glGetTexEnvfv MANGLE(GetTexEnvfv) +#define glGetTexEnviv MANGLE(GetTexEnviv) +#define glGetTexFilterFuncSGIS MANGLE(GetTexFilterFuncSGIS) +#define glGetTexGendv MANGLE(GetTexGendv) +#define glGetTexGenfv MANGLE(GetTexGenfv) +#define glGetTexGeniv MANGLE(GetTexGeniv) +#define glGetTexImage MANGLE(GetTexImage) +#define glGetTexLevelParameterfv MANGLE(GetTexLevelParameterfv) +#define glGetTexLevelParameteriv MANGLE(GetTexLevelParameteriv) +#define glGetTexParameterfv MANGLE(GetTexParameterfv) +#define glGetTexParameterIivEXT MANGLE(GetTexParameterIivEXT) +#define glGetTexParameterIiv MANGLE(GetTexParameterIiv) +#define glGetTexParameterIuivEXT MANGLE(GetTexParameterIuivEXT) +#define glGetTexParameterIuiv MANGLE(GetTexParameterIuiv) +#define glGetTexParameteriv MANGLE(GetTexParameteriv) +#define glGetTexParameterPointervAPPLE MANGLE(GetTexParameterPointervAPPLE) +#define glGetTextureImageEXT MANGLE(GetTextureImageEXT) +#define glGetTextureLevelParameterfvEXT MANGLE(GetTextureLevelParameterfvEXT) +#define glGetTextureLevelParameterivEXT MANGLE(GetTextureLevelParameterivEXT) +#define glGetTextureParameterfvEXT MANGLE(GetTextureParameterfvEXT) +#define glGetTextureParameterIivEXT MANGLE(GetTextureParameterIivEXT) +#define glGetTextureParameterIuivEXT MANGLE(GetTextureParameterIuivEXT) +#define glGetTextureParameterivEXT MANGLE(GetTextureParameterivEXT) +#define glGetTrackMatrixivNV MANGLE(GetTrackMatrixivNV) +#define glGetTransformFeedbackVaryingEXT MANGLE(GetTransformFeedbackVaryingEXT) +#define glGetTransformFeedbackVarying MANGLE(GetTransformFeedbackVarying) +#define glGetTransformFeedbackVaryingNV MANGLE(GetTransformFeedbackVaryingNV) +#define glGetUniformBlockIndex MANGLE(GetUniformBlockIndex) +#define glGetUniformBufferSizeEXT MANGLE(GetUniformBufferSizeEXT) +#define glGetUniformdv MANGLE(GetUniformdv) +#define glGetUniformfvARB MANGLE(GetUniformfvARB) +#define glGetUniformfv MANGLE(GetUniformfv) +#define glGetUniformi64vNV MANGLE(GetUniformi64vNV) +#define glGetUniformIndices MANGLE(GetUniformIndices) +#define glGetUniformivARB MANGLE(GetUniformivARB) +#define glGetUniformiv MANGLE(GetUniformiv) +#define glGetUniformLocationARB MANGLE(GetUniformLocationARB) +#define glGetUniformLocation MANGLE(GetUniformLocation) +#define glGetUniformOffsetEXT MANGLE(GetUniformOffsetEXT) +#define glGetUniformSubroutineuiv MANGLE(GetUniformSubroutineuiv) +#define glGetUniformui64vNV MANGLE(GetUniformui64vNV) +#define glGetUniformuivEXT MANGLE(GetUniformuivEXT) +#define glGetUniformuiv MANGLE(GetUniformuiv) +#define glGetVariantArrayObjectfvATI MANGLE(GetVariantArrayObjectfvATI) +#define glGetVariantArrayObjectivATI MANGLE(GetVariantArrayObjectivATI) +#define glGetVariantBooleanvEXT MANGLE(GetVariantBooleanvEXT) +#define glGetVariantFloatvEXT MANGLE(GetVariantFloatvEXT) +#define glGetVariantIntegervEXT MANGLE(GetVariantIntegervEXT) +#define glGetVariantPointervEXT MANGLE(GetVariantPointervEXT) +#define glGetVaryingLocationNV MANGLE(GetVaryingLocationNV) +#define glGetVertexAttribArrayObjectfvATI MANGLE(GetVertexAttribArrayObjectfvATI) +#define glGetVertexAttribArrayObjectivATI MANGLE(GetVertexAttribArrayObjectivATI) +#define glGetVertexAttribdvARB MANGLE(GetVertexAttribdvARB) +#define glGetVertexAttribdv MANGLE(GetVertexAttribdv) +#define glGetVertexAttribdvNV MANGLE(GetVertexAttribdvNV) +#define glGetVertexAttribfvARB MANGLE(GetVertexAttribfvARB) +#define glGetVertexAttribfv MANGLE(GetVertexAttribfv) +#define glGetVertexAttribfvNV MANGLE(GetVertexAttribfvNV) +#define glGetVertexAttribIivEXT MANGLE(GetVertexAttribIivEXT) +#define glGetVertexAttribIiv MANGLE(GetVertexAttribIiv) +#define glGetVertexAttribIuivEXT MANGLE(GetVertexAttribIuivEXT) +#define glGetVertexAttribIuiv MANGLE(GetVertexAttribIuiv) +#define glGetVertexAttribivARB MANGLE(GetVertexAttribivARB) +#define glGetVertexAttribiv MANGLE(GetVertexAttribiv) +#define glGetVertexAttribivNV MANGLE(GetVertexAttribivNV) +#define glGetVertexAttribLdvEXT MANGLE(GetVertexAttribLdvEXT) +#define glGetVertexAttribLdv MANGLE(GetVertexAttribLdv) +#define glGetVertexAttribLi64vNV MANGLE(GetVertexAttribLi64vNV) +#define glGetVertexAttribLui64vNV MANGLE(GetVertexAttribLui64vNV) +#define glGetVertexAttribPointervARB MANGLE(GetVertexAttribPointervARB) +#define glGetVertexAttribPointerv MANGLE(GetVertexAttribPointerv) +#define glGetVertexAttribPointervNV MANGLE(GetVertexAttribPointervNV) +#define glGetVideoCaptureivNV MANGLE(GetVideoCaptureivNV) +#define glGetVideoCaptureStreamdvNV MANGLE(GetVideoCaptureStreamdvNV) +#define glGetVideoCaptureStreamfvNV MANGLE(GetVideoCaptureStreamfvNV) +#define glGetVideoCaptureStreamivNV MANGLE(GetVideoCaptureStreamivNV) +#define glGetVideoi64vNV MANGLE(GetVideoi64vNV) +#define glGetVideoivNV MANGLE(GetVideoivNV) +#define glGetVideoui64vNV MANGLE(GetVideoui64vNV) +#define glGetVideouivNV MANGLE(GetVideouivNV) +#define glGlobalAlphaFactorbSUN MANGLE(GlobalAlphaFactorbSUN) +#define glGlobalAlphaFactordSUN MANGLE(GlobalAlphaFactordSUN) +#define glGlobalAlphaFactorfSUN MANGLE(GlobalAlphaFactorfSUN) +#define glGlobalAlphaFactoriSUN MANGLE(GlobalAlphaFactoriSUN) +#define glGlobalAlphaFactorsSUN MANGLE(GlobalAlphaFactorsSUN) +#define glGlobalAlphaFactorubSUN MANGLE(GlobalAlphaFactorubSUN) +#define glGlobalAlphaFactoruiSUN MANGLE(GlobalAlphaFactoruiSUN) +#define glGlobalAlphaFactorusSUN MANGLE(GlobalAlphaFactorusSUN) +#define glHint MANGLE(Hint) +#define glHintPGI MANGLE(HintPGI) +#define glHistogramEXT MANGLE(HistogramEXT) +#define glHistogram MANGLE(Histogram) +#define glIglooInterfaceSGIX MANGLE(IglooInterfaceSGIX) +#define glImageTransformParameterfHP MANGLE(ImageTransformParameterfHP) +#define glImageTransformParameterfvHP MANGLE(ImageTransformParameterfvHP) +#define glImageTransformParameteriHP MANGLE(ImageTransformParameteriHP) +#define glImageTransformParameterivHP MANGLE(ImageTransformParameterivHP) +#define glIndexd MANGLE(Indexd) +#define glIndexdv MANGLE(Indexdv) +#define glIndexf MANGLE(Indexf) +#define glIndexFormatNV MANGLE(IndexFormatNV) +#define glIndexFuncEXT MANGLE(IndexFuncEXT) +#define glIndexfv MANGLE(Indexfv) +#define glIndexi MANGLE(Indexi) +#define glIndexiv MANGLE(Indexiv) +#define glIndexMask MANGLE(IndexMask) +#define glIndexMaterialEXT MANGLE(IndexMaterialEXT) +#define glIndexPointerEXT MANGLE(IndexPointerEXT) +#define glIndexPointerListIBM MANGLE(IndexPointerListIBM) +#define glIndexPointer MANGLE(IndexPointer) +#define glIndexs MANGLE(Indexs) +#define glIndexsv MANGLE(Indexsv) +#define glIndexub MANGLE(Indexub) +#define glIndexubv MANGLE(Indexubv) +#define glInitNames MANGLE(InitNames) +#define glInsertComponentEXT MANGLE(InsertComponentEXT) +#define glInstrumentsBufferSGIX MANGLE(InstrumentsBufferSGIX) +#define glInterleavedArrays MANGLE(InterleavedArrays) +#define glIsAsyncMarkerSGIX MANGLE(IsAsyncMarkerSGIX) +#define glIsBufferARB MANGLE(IsBufferARB) +#define glIsBuffer MANGLE(IsBuffer) +#define glIsBufferResidentNV MANGLE(IsBufferResidentNV) +#define glIsEnabledi MANGLE(IsEnabledi) +#define glIsEnabledIndexedEXT MANGLE(IsEnabledIndexedEXT) +#define glIsEnabled MANGLE(IsEnabled) +#define glIsFenceAPPLE MANGLE(IsFenceAPPLE) +#define glIsFenceNV MANGLE(IsFenceNV) +#define glIsFramebufferEXT MANGLE(IsFramebufferEXT) +#define glIsFramebuffer MANGLE(IsFramebuffer) +#define glIsList MANGLE(IsList) +#define glIsNameAMD MANGLE(IsNameAMD) +#define glIsNamedBufferResidentNV MANGLE(IsNamedBufferResidentNV) +#define glIsNamedStringARB MANGLE(IsNamedStringARB) +#define glIsObjectBufferATI MANGLE(IsObjectBufferATI) +#define glIsOcclusionQueryNV MANGLE(IsOcclusionQueryNV) +#define glIsProgramARB MANGLE(IsProgramARB) +#define glIsProgram MANGLE(IsProgram) +#define glIsProgramNV MANGLE(IsProgramNV) +#define glIsProgramPipeline MANGLE(IsProgramPipeline) +#define glIsQueryARB MANGLE(IsQueryARB) +#define glIsQuery MANGLE(IsQuery) +#define glIsRenderbufferEXT MANGLE(IsRenderbufferEXT) +#define glIsRenderbuffer MANGLE(IsRenderbuffer) +#define glIsSampler MANGLE(IsSampler) +#define glIsShader MANGLE(IsShader) +#define glIsSync MANGLE(IsSync) +#define glIsTextureEXT MANGLE(IsTextureEXT) +#define glIsTexture MANGLE(IsTexture) +#define glIsTransformFeedback MANGLE(IsTransformFeedback) +#define glIsTransformFeedbackNV MANGLE(IsTransformFeedbackNV) +#define glIsVariantEnabledEXT MANGLE(IsVariantEnabledEXT) +#define glIsVertexArrayAPPLE MANGLE(IsVertexArrayAPPLE) +#define glIsVertexArray MANGLE(IsVertexArray) +#define glIsVertexAttribEnabledAPPLE MANGLE(IsVertexAttribEnabledAPPLE) +#define glLightEnviSGIX MANGLE(LightEnviSGIX) +#define glLightf MANGLE(Lightf) +#define glLightfv MANGLE(Lightfv) +#define glLighti MANGLE(Lighti) +#define glLightiv MANGLE(Lightiv) +#define glLightModelf MANGLE(LightModelf) +#define glLightModelfv MANGLE(LightModelfv) +#define glLightModeli MANGLE(LightModeli) +#define glLightModeliv MANGLE(LightModeliv) +#define glLineStipple MANGLE(LineStipple) +#define glLineWidth MANGLE(LineWidth) +#define glLinkProgramARB MANGLE(LinkProgramARB) +#define glLinkProgram MANGLE(LinkProgram) +#define glListBase MANGLE(ListBase) +#define glListParameterfSGIX MANGLE(ListParameterfSGIX) +#define glListParameterfvSGIX MANGLE(ListParameterfvSGIX) +#define glListParameteriSGIX MANGLE(ListParameteriSGIX) +#define glListParameterivSGIX MANGLE(ListParameterivSGIX) +#define glLoadIdentityDeformationMapSGIX MANGLE(LoadIdentityDeformationMapSGIX) +#define glLoadIdentity MANGLE(LoadIdentity) +#define glLoadMatrixd MANGLE(LoadMatrixd) +#define glLoadMatrixf MANGLE(LoadMatrixf) +#define glLoadName MANGLE(LoadName) +#define glLoadProgramNV MANGLE(LoadProgramNV) +#define glLoadTransposeMatrixdARB MANGLE(LoadTransposeMatrixdARB) +#define glLoadTransposeMatrixd MANGLE(LoadTransposeMatrixd) +#define glLoadTransposeMatrixfARB MANGLE(LoadTransposeMatrixfARB) +#define glLoadTransposeMatrixf MANGLE(LoadTransposeMatrixf) +#define glLockArraysEXT MANGLE(LockArraysEXT) +#define glLogicOp MANGLE(LogicOp) +#define glMakeBufferNonResidentNV MANGLE(MakeBufferNonResidentNV) +#define glMakeBufferResidentNV MANGLE(MakeBufferResidentNV) +#define glMakeNamedBufferNonResidentNV MANGLE(MakeNamedBufferNonResidentNV) +#define glMakeNamedBufferResidentNV MANGLE(MakeNamedBufferResidentNV) +#define glMap1d MANGLE(Map1d) +#define glMap1f MANGLE(Map1f) +#define glMap2d MANGLE(Map2d) +#define glMap2f MANGLE(Map2f) +#define glMapBufferARB MANGLE(MapBufferARB) +#define glMapBuffer MANGLE(MapBuffer) +#define glMapBufferRange MANGLE(MapBufferRange) +#define glMapControlPointsNV MANGLE(MapControlPointsNV) +#define glMapGrid1d MANGLE(MapGrid1d) +#define glMapGrid1f MANGLE(MapGrid1f) +#define glMapGrid2d MANGLE(MapGrid2d) +#define glMapGrid2f MANGLE(MapGrid2f) +#define glMapNamedBufferEXT MANGLE(MapNamedBufferEXT) +#define glMapNamedBufferRangeEXT MANGLE(MapNamedBufferRangeEXT) +#define glMapObjectBufferATI MANGLE(MapObjectBufferATI) +#define glMapParameterfvNV MANGLE(MapParameterfvNV) +#define glMapParameterivNV MANGLE(MapParameterivNV) +#define glMapVertexAttrib1dAPPLE MANGLE(MapVertexAttrib1dAPPLE) +#define glMapVertexAttrib1fAPPLE MANGLE(MapVertexAttrib1fAPPLE) +#define glMapVertexAttrib2dAPPLE MANGLE(MapVertexAttrib2dAPPLE) +#define glMapVertexAttrib2fAPPLE MANGLE(MapVertexAttrib2fAPPLE) +#define glMaterialf MANGLE(Materialf) +#define glMaterialfv MANGLE(Materialfv) +#define glMateriali MANGLE(Materiali) +#define glMaterialiv MANGLE(Materialiv) +#define glMatrixFrustumEXT MANGLE(MatrixFrustumEXT) +#define glMatrixIndexPointerARB MANGLE(MatrixIndexPointerARB) +#define glMatrixIndexubvARB MANGLE(MatrixIndexubvARB) +#define glMatrixIndexuivARB MANGLE(MatrixIndexuivARB) +#define glMatrixIndexusvARB MANGLE(MatrixIndexusvARB) +#define glMatrixLoaddEXT MANGLE(MatrixLoaddEXT) +#define glMatrixLoadfEXT MANGLE(MatrixLoadfEXT) +#define glMatrixLoadIdentityEXT MANGLE(MatrixLoadIdentityEXT) +#define glMatrixLoadTransposedEXT MANGLE(MatrixLoadTransposedEXT) +#define glMatrixLoadTransposefEXT MANGLE(MatrixLoadTransposefEXT) +#define glMatrixMode MANGLE(MatrixMode) +#define glMatrixMultdEXT MANGLE(MatrixMultdEXT) +#define glMatrixMultfEXT MANGLE(MatrixMultfEXT) +#define glMatrixMultTransposedEXT MANGLE(MatrixMultTransposedEXT) +#define glMatrixMultTransposefEXT MANGLE(MatrixMultTransposefEXT) +#define glMatrixOrthoEXT MANGLE(MatrixOrthoEXT) +#define glMatrixPopEXT MANGLE(MatrixPopEXT) +#define glMatrixPushEXT MANGLE(MatrixPushEXT) +#define glMatrixRotatedEXT MANGLE(MatrixRotatedEXT) +#define glMatrixRotatefEXT MANGLE(MatrixRotatefEXT) +#define glMatrixScaledEXT MANGLE(MatrixScaledEXT) +#define glMatrixScalefEXT MANGLE(MatrixScalefEXT) +#define glMatrixTranslatedEXT MANGLE(MatrixTranslatedEXT) +#define glMatrixTranslatefEXT MANGLE(MatrixTranslatefEXT) +#define glMemoryBarrierEXT MANGLE(MemoryBarrierEXT) +#define glMinmaxEXT MANGLE(MinmaxEXT) +#define glMinmax MANGLE(Minmax) +#define glMinSampleShadingARB MANGLE(MinSampleShadingARB) +#define glMinSampleShading MANGLE(MinSampleShading) +#define glMultiDrawArraysEXT MANGLE(MultiDrawArraysEXT) +#define glMultiDrawArrays MANGLE(MultiDrawArrays) +#define glMultiDrawElementArrayAPPLE MANGLE(MultiDrawElementArrayAPPLE) +#define glMultiDrawElementsBaseVertex MANGLE(MultiDrawElementsBaseVertex) +#define glMultiDrawElementsEXT MANGLE(MultiDrawElementsEXT) +#define glMultiDrawElements MANGLE(MultiDrawElements) +#define glMultiDrawRangeElementArrayAPPLE MANGLE(MultiDrawRangeElementArrayAPPLE) +#define glMultiModeDrawArraysIBM MANGLE(MultiModeDrawArraysIBM) +#define glMultiModeDrawElementsIBM MANGLE(MultiModeDrawElementsIBM) +#define glMultiTexBufferEXT MANGLE(MultiTexBufferEXT) +#define glMultiTexCoord1dARB MANGLE(MultiTexCoord1dARB) +#define glMultiTexCoord1d MANGLE(MultiTexCoord1d) +#define glMultiTexCoord1dvARB MANGLE(MultiTexCoord1dvARB) +#define glMultiTexCoord1dv MANGLE(MultiTexCoord1dv) +#define glMultiTexCoord1fARB MANGLE(MultiTexCoord1fARB) +#define glMultiTexCoord1f MANGLE(MultiTexCoord1f) +#define glMultiTexCoord1fvARB MANGLE(MultiTexCoord1fvARB) +#define glMultiTexCoord1fv MANGLE(MultiTexCoord1fv) +#define glMultiTexCoord1hNV MANGLE(MultiTexCoord1hNV) +#define glMultiTexCoord1hvNV MANGLE(MultiTexCoord1hvNV) +#define glMultiTexCoord1iARB MANGLE(MultiTexCoord1iARB) +#define glMultiTexCoord1i MANGLE(MultiTexCoord1i) +#define glMultiTexCoord1ivARB MANGLE(MultiTexCoord1ivARB) +#define glMultiTexCoord1iv MANGLE(MultiTexCoord1iv) +#define glMultiTexCoord1sARB MANGLE(MultiTexCoord1sARB) +#define glMultiTexCoord1s MANGLE(MultiTexCoord1s) +#define glMultiTexCoord1svARB MANGLE(MultiTexCoord1svARB) +#define glMultiTexCoord1sv MANGLE(MultiTexCoord1sv) +#define glMultiTexCoord2dARB MANGLE(MultiTexCoord2dARB) +#define glMultiTexCoord2d MANGLE(MultiTexCoord2d) +#define glMultiTexCoord2dvARB MANGLE(MultiTexCoord2dvARB) +#define glMultiTexCoord2dv MANGLE(MultiTexCoord2dv) +#define glMultiTexCoord2fARB MANGLE(MultiTexCoord2fARB) +#define glMultiTexCoord2f MANGLE(MultiTexCoord2f) +#define glMultiTexCoord2fvARB MANGLE(MultiTexCoord2fvARB) +#define glMultiTexCoord2fv MANGLE(MultiTexCoord2fv) +#define glMultiTexCoord2hNV MANGLE(MultiTexCoord2hNV) +#define glMultiTexCoord2hvNV MANGLE(MultiTexCoord2hvNV) +#define glMultiTexCoord2iARB MANGLE(MultiTexCoord2iARB) +#define glMultiTexCoord2i MANGLE(MultiTexCoord2i) +#define glMultiTexCoord2ivARB MANGLE(MultiTexCoord2ivARB) +#define glMultiTexCoord2iv MANGLE(MultiTexCoord2iv) +#define glMultiTexCoord2sARB MANGLE(MultiTexCoord2sARB) +#define glMultiTexCoord2s MANGLE(MultiTexCoord2s) +#define glMultiTexCoord2svARB MANGLE(MultiTexCoord2svARB) +#define glMultiTexCoord2sv MANGLE(MultiTexCoord2sv) +#define glMultiTexCoord3dARB MANGLE(MultiTexCoord3dARB) +#define glMultiTexCoord3d MANGLE(MultiTexCoord3d) +#define glMultiTexCoord3dvARB MANGLE(MultiTexCoord3dvARB) +#define glMultiTexCoord3dv MANGLE(MultiTexCoord3dv) +#define glMultiTexCoord3fARB MANGLE(MultiTexCoord3fARB) +#define glMultiTexCoord3f MANGLE(MultiTexCoord3f) +#define glMultiTexCoord3fvARB MANGLE(MultiTexCoord3fvARB) +#define glMultiTexCoord3fv MANGLE(MultiTexCoord3fv) +#define glMultiTexCoord3hNV MANGLE(MultiTexCoord3hNV) +#define glMultiTexCoord3hvNV MANGLE(MultiTexCoord3hvNV) +#define glMultiTexCoord3iARB MANGLE(MultiTexCoord3iARB) +#define glMultiTexCoord3i MANGLE(MultiTexCoord3i) +#define glMultiTexCoord3ivARB MANGLE(MultiTexCoord3ivARB) +#define glMultiTexCoord3iv MANGLE(MultiTexCoord3iv) +#define glMultiTexCoord3sARB MANGLE(MultiTexCoord3sARB) +#define glMultiTexCoord3s MANGLE(MultiTexCoord3s) +#define glMultiTexCoord3svARB MANGLE(MultiTexCoord3svARB) +#define glMultiTexCoord3sv MANGLE(MultiTexCoord3sv) +#define glMultiTexCoord4dARB MANGLE(MultiTexCoord4dARB) +#define glMultiTexCoord4d MANGLE(MultiTexCoord4d) +#define glMultiTexCoord4dvARB MANGLE(MultiTexCoord4dvARB) +#define glMultiTexCoord4dv MANGLE(MultiTexCoord4dv) +#define glMultiTexCoord4fARB MANGLE(MultiTexCoord4fARB) +#define glMultiTexCoord4f MANGLE(MultiTexCoord4f) +#define glMultiTexCoord4fvARB MANGLE(MultiTexCoord4fvARB) +#define glMultiTexCoord4fv MANGLE(MultiTexCoord4fv) +#define glMultiTexCoord4hNV MANGLE(MultiTexCoord4hNV) +#define glMultiTexCoord4hvNV MANGLE(MultiTexCoord4hvNV) +#define glMultiTexCoord4iARB MANGLE(MultiTexCoord4iARB) +#define glMultiTexCoord4i MANGLE(MultiTexCoord4i) +#define glMultiTexCoord4ivARB MANGLE(MultiTexCoord4ivARB) +#define glMultiTexCoord4iv MANGLE(MultiTexCoord4iv) +#define glMultiTexCoord4sARB MANGLE(MultiTexCoord4sARB) +#define glMultiTexCoord4s MANGLE(MultiTexCoord4s) +#define glMultiTexCoord4svARB MANGLE(MultiTexCoord4svARB) +#define glMultiTexCoord4sv MANGLE(MultiTexCoord4sv) +#define glMultiTexCoordP1ui MANGLE(MultiTexCoordP1ui) +#define glMultiTexCoordP1uiv MANGLE(MultiTexCoordP1uiv) +#define glMultiTexCoordP2ui MANGLE(MultiTexCoordP2ui) +#define glMultiTexCoordP2uiv MANGLE(MultiTexCoordP2uiv) +#define glMultiTexCoordP3ui MANGLE(MultiTexCoordP3ui) +#define glMultiTexCoordP3uiv MANGLE(MultiTexCoordP3uiv) +#define glMultiTexCoordP4ui MANGLE(MultiTexCoordP4ui) +#define glMultiTexCoordP4uiv MANGLE(MultiTexCoordP4uiv) +#define glMultiTexCoordPointerEXT MANGLE(MultiTexCoordPointerEXT) +#define glMultiTexEnvfEXT MANGLE(MultiTexEnvfEXT) +#define glMultiTexEnvfvEXT MANGLE(MultiTexEnvfvEXT) +#define glMultiTexEnviEXT MANGLE(MultiTexEnviEXT) +#define glMultiTexEnvivEXT MANGLE(MultiTexEnvivEXT) +#define glMultiTexGendEXT MANGLE(MultiTexGendEXT) +#define glMultiTexGendvEXT MANGLE(MultiTexGendvEXT) +#define glMultiTexGenfEXT MANGLE(MultiTexGenfEXT) +#define glMultiTexGenfvEXT MANGLE(MultiTexGenfvEXT) +#define glMultiTexGeniEXT MANGLE(MultiTexGeniEXT) +#define glMultiTexGenivEXT MANGLE(MultiTexGenivEXT) +#define glMultiTexImage1DEXT MANGLE(MultiTexImage1DEXT) +#define glMultiTexImage2DEXT MANGLE(MultiTexImage2DEXT) +#define glMultiTexImage3DEXT MANGLE(MultiTexImage3DEXT) +#define glMultiTexParameterfEXT MANGLE(MultiTexParameterfEXT) +#define glMultiTexParameterfvEXT MANGLE(MultiTexParameterfvEXT) +#define glMultiTexParameteriEXT MANGLE(MultiTexParameteriEXT) +#define glMultiTexParameterIivEXT MANGLE(MultiTexParameterIivEXT) +#define glMultiTexParameterIuivEXT MANGLE(MultiTexParameterIuivEXT) +#define glMultiTexParameterivEXT MANGLE(MultiTexParameterivEXT) +#define glMultiTexRenderbufferEXT MANGLE(MultiTexRenderbufferEXT) +#define glMultiTexSubImage1DEXT MANGLE(MultiTexSubImage1DEXT) +#define glMultiTexSubImage2DEXT MANGLE(MultiTexSubImage2DEXT) +#define glMultiTexSubImage3DEXT MANGLE(MultiTexSubImage3DEXT) +#define glMultMatrixd MANGLE(MultMatrixd) +#define glMultMatrixf MANGLE(MultMatrixf) +#define glMultTransposeMatrixdARB MANGLE(MultTransposeMatrixdARB) +#define glMultTransposeMatrixd MANGLE(MultTransposeMatrixd) +#define glMultTransposeMatrixfARB MANGLE(MultTransposeMatrixfARB) +#define glMultTransposeMatrixf MANGLE(MultTransposeMatrixf) +#define glNamedBufferDataEXT MANGLE(NamedBufferDataEXT) +#define glNamedBufferSubDataEXT MANGLE(NamedBufferSubDataEXT) +#define glNamedCopyBufferSubDataEXT MANGLE(NamedCopyBufferSubDataEXT) +#define glNamedFramebufferRenderbufferEXT MANGLE(NamedFramebufferRenderbufferEXT) +#define glNamedFramebufferTexture1DEXT MANGLE(NamedFramebufferTexture1DEXT) +#define glNamedFramebufferTexture2DEXT MANGLE(NamedFramebufferTexture2DEXT) +#define glNamedFramebufferTexture3DEXT MANGLE(NamedFramebufferTexture3DEXT) +#define glNamedFramebufferTextureEXT MANGLE(NamedFramebufferTextureEXT) +#define glNamedFramebufferTextureFaceEXT MANGLE(NamedFramebufferTextureFaceEXT) +#define glNamedFramebufferTextureLayerEXT MANGLE(NamedFramebufferTextureLayerEXT) +#define glNamedProgramLocalParameter4dEXT MANGLE(NamedProgramLocalParameter4dEXT) +#define glNamedProgramLocalParameter4dvEXT MANGLE(NamedProgramLocalParameter4dvEXT) +#define glNamedProgramLocalParameter4fEXT MANGLE(NamedProgramLocalParameter4fEXT) +#define glNamedProgramLocalParameter4fvEXT MANGLE(NamedProgramLocalParameter4fvEXT) +#define glNamedProgramLocalParameterI4iEXT MANGLE(NamedProgramLocalParameterI4iEXT) +#define glNamedProgramLocalParameterI4ivEXT MANGLE(NamedProgramLocalParameterI4ivEXT) +#define glNamedProgramLocalParameterI4uiEXT MANGLE(NamedProgramLocalParameterI4uiEXT) +#define glNamedProgramLocalParameterI4uivEXT MANGLE(NamedProgramLocalParameterI4uivEXT) +#define glNamedProgramLocalParameters4fvEXT MANGLE(NamedProgramLocalParameters4fvEXT) +#define glNamedProgramLocalParametersI4ivEXT MANGLE(NamedProgramLocalParametersI4ivEXT) +#define glNamedProgramLocalParametersI4uivEXT MANGLE(NamedProgramLocalParametersI4uivEXT) +#define glNamedProgramStringEXT MANGLE(NamedProgramStringEXT) +#define glNamedRenderbufferStorageEXT MANGLE(NamedRenderbufferStorageEXT) +#define glNamedRenderbufferStorageMultisampleCoverageEXT MANGLE(NamedRenderbufferStorageMultisampleCoverageEXT) +#define glNamedRenderbufferStorageMultisampleEXT MANGLE(NamedRenderbufferStorageMultisampleEXT) +#define glNamedStringARB MANGLE(NamedStringARB) +#define glNewList MANGLE(NewList) +#define glNewObjectBufferATI MANGLE(NewObjectBufferATI) +#define glNormal3b MANGLE(Normal3b) +#define glNormal3bv MANGLE(Normal3bv) +#define glNormal3d MANGLE(Normal3d) +#define glNormal3dv MANGLE(Normal3dv) +#define glNormal3f MANGLE(Normal3f) +#define glNormal3fVertex3fSUN MANGLE(Normal3fVertex3fSUN) +#define glNormal3fVertex3fvSUN MANGLE(Normal3fVertex3fvSUN) +#define glNormal3fv MANGLE(Normal3fv) +#define glNormal3hNV MANGLE(Normal3hNV) +#define glNormal3hvNV MANGLE(Normal3hvNV) +#define glNormal3i MANGLE(Normal3i) +#define glNormal3iv MANGLE(Normal3iv) +#define glNormal3s MANGLE(Normal3s) +#define glNormal3sv MANGLE(Normal3sv) +#define glNormalFormatNV MANGLE(NormalFormatNV) +#define glNormalP3ui MANGLE(NormalP3ui) +#define glNormalP3uiv MANGLE(NormalP3uiv) +#define glNormalPointerEXT MANGLE(NormalPointerEXT) +#define glNormalPointerListIBM MANGLE(NormalPointerListIBM) +#define glNormalPointer MANGLE(NormalPointer) +#define glNormalPointervINTEL MANGLE(NormalPointervINTEL) +#define glNormalStream3bATI MANGLE(NormalStream3bATI) +#define glNormalStream3bvATI MANGLE(NormalStream3bvATI) +#define glNormalStream3dATI MANGLE(NormalStream3dATI) +#define glNormalStream3dvATI MANGLE(NormalStream3dvATI) +#define glNormalStream3fATI MANGLE(NormalStream3fATI) +#define glNormalStream3fvATI MANGLE(NormalStream3fvATI) +#define glNormalStream3iATI MANGLE(NormalStream3iATI) +#define glNormalStream3ivATI MANGLE(NormalStream3ivATI) +#define glNormalStream3sATI MANGLE(NormalStream3sATI) +#define glNormalStream3svATI MANGLE(NormalStream3svATI) +#define glObjectPurgeableAPPLE MANGLE(ObjectPurgeableAPPLE) +#define glObjectUnpurgeableAPPLE MANGLE(ObjectUnpurgeableAPPLE) +#define glOrtho MANGLE(Ortho) +#define glPassTexCoordATI MANGLE(PassTexCoordATI) +#define glPassThrough MANGLE(PassThrough) +#define glPatchParameterfv MANGLE(PatchParameterfv) +#define glPatchParameteri MANGLE(PatchParameteri) +#define glPauseTransformFeedback MANGLE(PauseTransformFeedback) +#define glPauseTransformFeedbackNV MANGLE(PauseTransformFeedbackNV) +#define glPixelDataRangeNV MANGLE(PixelDataRangeNV) +#define glPixelMapfv MANGLE(PixelMapfv) +#define glPixelMapuiv MANGLE(PixelMapuiv) +#define glPixelMapusv MANGLE(PixelMapusv) +#define glPixelStoref MANGLE(PixelStoref) +#define glPixelStorei MANGLE(PixelStorei) +#define glPixelTexGenParameterfSGIS MANGLE(PixelTexGenParameterfSGIS) +#define glPixelTexGenParameterfvSGIS MANGLE(PixelTexGenParameterfvSGIS) +#define glPixelTexGenParameteriSGIS MANGLE(PixelTexGenParameteriSGIS) +#define glPixelTexGenParameterivSGIS MANGLE(PixelTexGenParameterivSGIS) +#define glPixelTexGenSGIX MANGLE(PixelTexGenSGIX) +#define glPixelTransferf MANGLE(PixelTransferf) +#define glPixelTransferi MANGLE(PixelTransferi) +#define glPixelTransformParameterfEXT MANGLE(PixelTransformParameterfEXT) +#define glPixelTransformParameterfvEXT MANGLE(PixelTransformParameterfvEXT) +#define glPixelTransformParameteriEXT MANGLE(PixelTransformParameteriEXT) +#define glPixelTransformParameterivEXT MANGLE(PixelTransformParameterivEXT) +#define glPixelZoom MANGLE(PixelZoom) +#define glPNTrianglesfATI MANGLE(PNTrianglesfATI) +#define glPNTrianglesiATI MANGLE(PNTrianglesiATI) +#define glPointParameterfARB MANGLE(PointParameterfARB) +#define glPointParameterfEXT MANGLE(PointParameterfEXT) +#define glPointParameterf MANGLE(PointParameterf) +#define glPointParameterfSGIS MANGLE(PointParameterfSGIS) +#define glPointParameterfvARB MANGLE(PointParameterfvARB) +#define glPointParameterfvEXT MANGLE(PointParameterfvEXT) +#define glPointParameterfv MANGLE(PointParameterfv) +#define glPointParameterfvSGIS MANGLE(PointParameterfvSGIS) +#define glPointParameteri MANGLE(PointParameteri) +#define glPointParameteriNV MANGLE(PointParameteriNV) +#define glPointParameteriv MANGLE(PointParameteriv) +#define glPointParameterivNV MANGLE(PointParameterivNV) +#define glPointSize MANGLE(PointSize) +#define glPollAsyncSGIX MANGLE(PollAsyncSGIX) +#define glPollInstrumentsSGIX MANGLE(PollInstrumentsSGIX) +#define glPolygonMode MANGLE(PolygonMode) +#define glPolygonOffsetEXT MANGLE(PolygonOffsetEXT) +#define glPolygonOffset MANGLE(PolygonOffset) +#define glPolygonStipple MANGLE(PolygonStipple) +#define glPopAttrib MANGLE(PopAttrib) +#define glPopClientAttrib MANGLE(PopClientAttrib) +#define glPopMatrix MANGLE(PopMatrix) +#define glPopName MANGLE(PopName) +#define glPresentFrameDualFillNV MANGLE(PresentFrameDualFillNV) +#define glPresentFrameKeyedNV MANGLE(PresentFrameKeyedNV) +#define glPrimitiveRestartIndex MANGLE(PrimitiveRestartIndex) +#define glPrimitiveRestartIndexNV MANGLE(PrimitiveRestartIndexNV) +#define glPrimitiveRestartNV MANGLE(PrimitiveRestartNV) +#define glPrioritizeTexturesEXT MANGLE(PrioritizeTexturesEXT) +#define glPrioritizeTextures MANGLE(PrioritizeTextures) +#define glProgramBinary MANGLE(ProgramBinary) +#define glProgramBufferParametersfvNV MANGLE(ProgramBufferParametersfvNV) +#define glProgramBufferParametersIivNV MANGLE(ProgramBufferParametersIivNV) +#define glProgramBufferParametersIuivNV MANGLE(ProgramBufferParametersIuivNV) +#define glProgramCallbackMESA MANGLE(ProgramCallbackMESA) +#define glProgramEnvParameter4dARB MANGLE(ProgramEnvParameter4dARB) +#define glProgramEnvParameter4dvARB MANGLE(ProgramEnvParameter4dvARB) +#define glProgramEnvParameter4fARB MANGLE(ProgramEnvParameter4fARB) +#define glProgramEnvParameter4fvARB MANGLE(ProgramEnvParameter4fvARB) +#define glProgramEnvParameterI4iNV MANGLE(ProgramEnvParameterI4iNV) +#define glProgramEnvParameterI4ivNV MANGLE(ProgramEnvParameterI4ivNV) +#define glProgramEnvParameterI4uiNV MANGLE(ProgramEnvParameterI4uiNV) +#define glProgramEnvParameterI4uivNV MANGLE(ProgramEnvParameterI4uivNV) +#define glProgramEnvParameters4fvEXT MANGLE(ProgramEnvParameters4fvEXT) +#define glProgramEnvParametersI4ivNV MANGLE(ProgramEnvParametersI4ivNV) +#define glProgramEnvParametersI4uivNV MANGLE(ProgramEnvParametersI4uivNV) +#define glProgramLocalParameter4dARB MANGLE(ProgramLocalParameter4dARB) +#define glProgramLocalParameter4dvARB MANGLE(ProgramLocalParameter4dvARB) +#define glProgramLocalParameter4fARB MANGLE(ProgramLocalParameter4fARB) +#define glProgramLocalParameter4fvARB MANGLE(ProgramLocalParameter4fvARB) +#define glProgramLocalParameterI4iNV MANGLE(ProgramLocalParameterI4iNV) +#define glProgramLocalParameterI4ivNV MANGLE(ProgramLocalParameterI4ivNV) +#define glProgramLocalParameterI4uiNV MANGLE(ProgramLocalParameterI4uiNV) +#define glProgramLocalParameterI4uivNV MANGLE(ProgramLocalParameterI4uivNV) +#define glProgramLocalParameters4fvEXT MANGLE(ProgramLocalParameters4fvEXT) +#define glProgramLocalParametersI4ivNV MANGLE(ProgramLocalParametersI4ivNV) +#define glProgramLocalParametersI4uivNV MANGLE(ProgramLocalParametersI4uivNV) +#define glProgramNamedParameter4dNV MANGLE(ProgramNamedParameter4dNV) +#define glProgramNamedParameter4dvNV MANGLE(ProgramNamedParameter4dvNV) +#define glProgramNamedParameter4fNV MANGLE(ProgramNamedParameter4fNV) +#define glProgramNamedParameter4fvNV MANGLE(ProgramNamedParameter4fvNV) +#define glProgramParameter4dNV MANGLE(ProgramParameter4dNV) +#define glProgramParameter4dvNV MANGLE(ProgramParameter4dvNV) +#define glProgramParameter4fNV MANGLE(ProgramParameter4fNV) +#define glProgramParameter4fvNV MANGLE(ProgramParameter4fvNV) +#define glProgramParameteriARB MANGLE(ProgramParameteriARB) +#define glProgramParameteriEXT MANGLE(ProgramParameteriEXT) +#define glProgramParameteri MANGLE(ProgramParameteri) +#define glProgramParameters4dvNV MANGLE(ProgramParameters4dvNV) +#define glProgramParameters4fvNV MANGLE(ProgramParameters4fvNV) +#define glProgramStringARB MANGLE(ProgramStringARB) +#define glProgramSubroutineParametersuivNV MANGLE(ProgramSubroutineParametersuivNV) +#define glProgramUniform1dEXT MANGLE(ProgramUniform1dEXT) +#define glProgramUniform1d MANGLE(ProgramUniform1d) +#define glProgramUniform1dvEXT MANGLE(ProgramUniform1dvEXT) +#define glProgramUniform1dv MANGLE(ProgramUniform1dv) +#define glProgramUniform1fEXT MANGLE(ProgramUniform1fEXT) +#define glProgramUniform1f MANGLE(ProgramUniform1f) +#define glProgramUniform1fvEXT MANGLE(ProgramUniform1fvEXT) +#define glProgramUniform1fv MANGLE(ProgramUniform1fv) +#define glProgramUniform1i64NV MANGLE(ProgramUniform1i64NV) +#define glProgramUniform1i64vNV MANGLE(ProgramUniform1i64vNV) +#define glProgramUniform1iEXT MANGLE(ProgramUniform1iEXT) +#define glProgramUniform1i MANGLE(ProgramUniform1i) +#define glProgramUniform1ivEXT MANGLE(ProgramUniform1ivEXT) +#define glProgramUniform1iv MANGLE(ProgramUniform1iv) +#define glProgramUniform1ui64NV MANGLE(ProgramUniform1ui64NV) +#define glProgramUniform1ui64vNV MANGLE(ProgramUniform1ui64vNV) +#define glProgramUniform1uiEXT MANGLE(ProgramUniform1uiEXT) +#define glProgramUniform1ui MANGLE(ProgramUniform1ui) +#define glProgramUniform1uivEXT MANGLE(ProgramUniform1uivEXT) +#define glProgramUniform1uiv MANGLE(ProgramUniform1uiv) +#define glProgramUniform2dEXT MANGLE(ProgramUniform2dEXT) +#define glProgramUniform2d MANGLE(ProgramUniform2d) +#define glProgramUniform2dvEXT MANGLE(ProgramUniform2dvEXT) +#define glProgramUniform2dv MANGLE(ProgramUniform2dv) +#define glProgramUniform2fEXT MANGLE(ProgramUniform2fEXT) +#define glProgramUniform2f MANGLE(ProgramUniform2f) +#define glProgramUniform2fvEXT MANGLE(ProgramUniform2fvEXT) +#define glProgramUniform2fv MANGLE(ProgramUniform2fv) +#define glProgramUniform2i64NV MANGLE(ProgramUniform2i64NV) +#define glProgramUniform2i64vNV MANGLE(ProgramUniform2i64vNV) +#define glProgramUniform2iEXT MANGLE(ProgramUniform2iEXT) +#define glProgramUniform2i MANGLE(ProgramUniform2i) +#define glProgramUniform2ivEXT MANGLE(ProgramUniform2ivEXT) +#define glProgramUniform2iv MANGLE(ProgramUniform2iv) +#define glProgramUniform2ui64NV MANGLE(ProgramUniform2ui64NV) +#define glProgramUniform2ui64vNV MANGLE(ProgramUniform2ui64vNV) +#define glProgramUniform2uiEXT MANGLE(ProgramUniform2uiEXT) +#define glProgramUniform2ui MANGLE(ProgramUniform2ui) +#define glProgramUniform2uivEXT MANGLE(ProgramUniform2uivEXT) +#define glProgramUniform2uiv MANGLE(ProgramUniform2uiv) +#define glProgramUniform3dEXT MANGLE(ProgramUniform3dEXT) +#define glProgramUniform3d MANGLE(ProgramUniform3d) +#define glProgramUniform3dvEXT MANGLE(ProgramUniform3dvEXT) +#define glProgramUniform3dv MANGLE(ProgramUniform3dv) +#define glProgramUniform3fEXT MANGLE(ProgramUniform3fEXT) +#define glProgramUniform3f MANGLE(ProgramUniform3f) +#define glProgramUniform3fvEXT MANGLE(ProgramUniform3fvEXT) +#define glProgramUniform3fv MANGLE(ProgramUniform3fv) +#define glProgramUniform3i64NV MANGLE(ProgramUniform3i64NV) +#define glProgramUniform3i64vNV MANGLE(ProgramUniform3i64vNV) +#define glProgramUniform3iEXT MANGLE(ProgramUniform3iEXT) +#define glProgramUniform3i MANGLE(ProgramUniform3i) +#define glProgramUniform3ivEXT MANGLE(ProgramUniform3ivEXT) +#define glProgramUniform3iv MANGLE(ProgramUniform3iv) +#define glProgramUniform3ui64NV MANGLE(ProgramUniform3ui64NV) +#define glProgramUniform3ui64vNV MANGLE(ProgramUniform3ui64vNV) +#define glProgramUniform3uiEXT MANGLE(ProgramUniform3uiEXT) +#define glProgramUniform3ui MANGLE(ProgramUniform3ui) +#define glProgramUniform3uivEXT MANGLE(ProgramUniform3uivEXT) +#define glProgramUniform3uiv MANGLE(ProgramUniform3uiv) +#define glProgramUniform4dEXT MANGLE(ProgramUniform4dEXT) +#define glProgramUniform4d MANGLE(ProgramUniform4d) +#define glProgramUniform4dvEXT MANGLE(ProgramUniform4dvEXT) +#define glProgramUniform4dv MANGLE(ProgramUniform4dv) +#define glProgramUniform4fEXT MANGLE(ProgramUniform4fEXT) +#define glProgramUniform4f MANGLE(ProgramUniform4f) +#define glProgramUniform4fvEXT MANGLE(ProgramUniform4fvEXT) +#define glProgramUniform4fv MANGLE(ProgramUniform4fv) +#define glProgramUniform4i64NV MANGLE(ProgramUniform4i64NV) +#define glProgramUniform4i64vNV MANGLE(ProgramUniform4i64vNV) +#define glProgramUniform4iEXT MANGLE(ProgramUniform4iEXT) +#define glProgramUniform4i MANGLE(ProgramUniform4i) +#define glProgramUniform4ivEXT MANGLE(ProgramUniform4ivEXT) +#define glProgramUniform4iv MANGLE(ProgramUniform4iv) +#define glProgramUniform4ui64NV MANGLE(ProgramUniform4ui64NV) +#define glProgramUniform4ui64vNV MANGLE(ProgramUniform4ui64vNV) +#define glProgramUniform4uiEXT MANGLE(ProgramUniform4uiEXT) +#define glProgramUniform4ui MANGLE(ProgramUniform4ui) +#define glProgramUniform4uivEXT MANGLE(ProgramUniform4uivEXT) +#define glProgramUniform4uiv MANGLE(ProgramUniform4uiv) +#define glProgramUniformMatrix2dvEXT MANGLE(ProgramUniformMatrix2dvEXT) +#define glProgramUniformMatrix2dv MANGLE(ProgramUniformMatrix2dv) +#define glProgramUniformMatrix2fvEXT MANGLE(ProgramUniformMatrix2fvEXT) +#define glProgramUniformMatrix2fv MANGLE(ProgramUniformMatrix2fv) +#define glProgramUniformMatrix2x3dvEXT MANGLE(ProgramUniformMatrix2x3dvEXT) +#define glProgramUniformMatrix2x3dv MANGLE(ProgramUniformMatrix2x3dv) +#define glProgramUniformMatrix2x3fvEXT MANGLE(ProgramUniformMatrix2x3fvEXT) +#define glProgramUniformMatrix2x3fv MANGLE(ProgramUniformMatrix2x3fv) +#define glProgramUniformMatrix2x4dvEXT MANGLE(ProgramUniformMatrix2x4dvEXT) +#define glProgramUniformMatrix2x4dv MANGLE(ProgramUniformMatrix2x4dv) +#define glProgramUniformMatrix2x4fvEXT MANGLE(ProgramUniformMatrix2x4fvEXT) +#define glProgramUniformMatrix2x4fv MANGLE(ProgramUniformMatrix2x4fv) +#define glProgramUniformMatrix3dvEXT MANGLE(ProgramUniformMatrix3dvEXT) +#define glProgramUniformMatrix3dv MANGLE(ProgramUniformMatrix3dv) +#define glProgramUniformMatrix3fvEXT MANGLE(ProgramUniformMatrix3fvEXT) +#define glProgramUniformMatrix3fv MANGLE(ProgramUniformMatrix3fv) +#define glProgramUniformMatrix3x2dvEXT MANGLE(ProgramUniformMatrix3x2dvEXT) +#define glProgramUniformMatrix3x2dv MANGLE(ProgramUniformMatrix3x2dv) +#define glProgramUniformMatrix3x2fvEXT MANGLE(ProgramUniformMatrix3x2fvEXT) +#define glProgramUniformMatrix3x2fv MANGLE(ProgramUniformMatrix3x2fv) +#define glProgramUniformMatrix3x4dvEXT MANGLE(ProgramUniformMatrix3x4dvEXT) +#define glProgramUniformMatrix3x4dv MANGLE(ProgramUniformMatrix3x4dv) +#define glProgramUniformMatrix3x4fvEXT MANGLE(ProgramUniformMatrix3x4fvEXT) +#define glProgramUniformMatrix3x4fv MANGLE(ProgramUniformMatrix3x4fv) +#define glProgramUniformMatrix4dvEXT MANGLE(ProgramUniformMatrix4dvEXT) +#define glProgramUniformMatrix4dv MANGLE(ProgramUniformMatrix4dv) +#define glProgramUniformMatrix4fvEXT MANGLE(ProgramUniformMatrix4fvEXT) +#define glProgramUniformMatrix4fv MANGLE(ProgramUniformMatrix4fv) +#define glProgramUniformMatrix4x2dvEXT MANGLE(ProgramUniformMatrix4x2dvEXT) +#define glProgramUniformMatrix4x2dv MANGLE(ProgramUniformMatrix4x2dv) +#define glProgramUniformMatrix4x2fvEXT MANGLE(ProgramUniformMatrix4x2fvEXT) +#define glProgramUniformMatrix4x2fv MANGLE(ProgramUniformMatrix4x2fv) +#define glProgramUniformMatrix4x3dvEXT MANGLE(ProgramUniformMatrix4x3dvEXT) +#define glProgramUniformMatrix4x3dv MANGLE(ProgramUniformMatrix4x3dv) +#define glProgramUniformMatrix4x3fvEXT MANGLE(ProgramUniformMatrix4x3fvEXT) +#define glProgramUniformMatrix4x3fv MANGLE(ProgramUniformMatrix4x3fv) +#define glProgramUniformui64NV MANGLE(ProgramUniformui64NV) +#define glProgramUniformui64vNV MANGLE(ProgramUniformui64vNV) +#define glProgramVertexLimitNV MANGLE(ProgramVertexLimitNV) +#define glProvokingVertexEXT MANGLE(ProvokingVertexEXT) +#define glProvokingVertex MANGLE(ProvokingVertex) +#define glPushAttrib MANGLE(PushAttrib) +#define glPushClientAttribDefaultEXT MANGLE(PushClientAttribDefaultEXT) +#define glPushClientAttrib MANGLE(PushClientAttrib) +#define glPushMatrix MANGLE(PushMatrix) +#define glPushName MANGLE(PushName) +#define glQueryCounter MANGLE(QueryCounter) +#define glRasterPos2d MANGLE(RasterPos2d) +#define glRasterPos2dv MANGLE(RasterPos2dv) +#define glRasterPos2f MANGLE(RasterPos2f) +#define glRasterPos2fv MANGLE(RasterPos2fv) +#define glRasterPos2i MANGLE(RasterPos2i) +#define glRasterPos2iv MANGLE(RasterPos2iv) +#define glRasterPos2s MANGLE(RasterPos2s) +#define glRasterPos2sv MANGLE(RasterPos2sv) +#define glRasterPos3d MANGLE(RasterPos3d) +#define glRasterPos3dv MANGLE(RasterPos3dv) +#define glRasterPos3f MANGLE(RasterPos3f) +#define glRasterPos3fv MANGLE(RasterPos3fv) +#define glRasterPos3i MANGLE(RasterPos3i) +#define glRasterPos3iv MANGLE(RasterPos3iv) +#define glRasterPos3s MANGLE(RasterPos3s) +#define glRasterPos3sv MANGLE(RasterPos3sv) +#define glRasterPos4d MANGLE(RasterPos4d) +#define glRasterPos4dv MANGLE(RasterPos4dv) +#define glRasterPos4f MANGLE(RasterPos4f) +#define glRasterPos4fv MANGLE(RasterPos4fv) +#define glRasterPos4i MANGLE(RasterPos4i) +#define glRasterPos4iv MANGLE(RasterPos4iv) +#define glRasterPos4s MANGLE(RasterPos4s) +#define glRasterPos4sv MANGLE(RasterPos4sv) +#define glReadBuffer MANGLE(ReadBuffer) +#define glReadInstrumentsSGIX MANGLE(ReadInstrumentsSGIX) +#define glReadnPixelsARB MANGLE(ReadnPixelsARB) +#define glReadPixels MANGLE(ReadPixels) +#define glRectd MANGLE(Rectd) +#define glRectdv MANGLE(Rectdv) +#define glRectf MANGLE(Rectf) +#define glRectfv MANGLE(Rectfv) +#define glRecti MANGLE(Recti) +#define glRectiv MANGLE(Rectiv) +#define glRects MANGLE(Rects) +#define glRectsv MANGLE(Rectsv) +#define glReferencePlaneSGIX MANGLE(ReferencePlaneSGIX) +#define glReleaseShaderCompiler MANGLE(ReleaseShaderCompiler) +#define glRenderbufferStorageEXT MANGLE(RenderbufferStorageEXT) +#define glRenderbufferStorage MANGLE(RenderbufferStorage) +#define glRenderbufferStorageMultisampleCoverageNV MANGLE(RenderbufferStorageMultisampleCoverageNV) +#define glRenderbufferStorageMultisampleEXT MANGLE(RenderbufferStorageMultisampleEXT) +#define glRenderbufferStorageMultisample MANGLE(RenderbufferStorageMultisample) +#define glRenderMode MANGLE(RenderMode) +#define glReplacementCodePointerSUN MANGLE(ReplacementCodePointerSUN) +#define glReplacementCodeubSUN MANGLE(ReplacementCodeubSUN) +#define glReplacementCodeubvSUN MANGLE(ReplacementCodeubvSUN) +#define glReplacementCodeuiColor3fVertex3fSUN MANGLE(ReplacementCodeuiColor3fVertex3fSUN) +#define glReplacementCodeuiColor3fVertex3fvSUN MANGLE(ReplacementCodeuiColor3fVertex3fvSUN) +#define glReplacementCodeuiColor4fNormal3fVertex3fSUN MANGLE(ReplacementCodeuiColor4fNormal3fVertex3fSUN) +#define glReplacementCodeuiColor4fNormal3fVertex3fvSUN MANGLE(ReplacementCodeuiColor4fNormal3fVertex3fvSUN) +#define glReplacementCodeuiColor4ubVertex3fSUN MANGLE(ReplacementCodeuiColor4ubVertex3fSUN) +#define glReplacementCodeuiColor4ubVertex3fvSUN MANGLE(ReplacementCodeuiColor4ubVertex3fvSUN) +#define glReplacementCodeuiNormal3fVertex3fSUN MANGLE(ReplacementCodeuiNormal3fVertex3fSUN) +#define glReplacementCodeuiNormal3fVertex3fvSUN MANGLE(ReplacementCodeuiNormal3fVertex3fvSUN) +#define glReplacementCodeuiSUN MANGLE(ReplacementCodeuiSUN) +#define glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN MANGLE(ReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN) +#define glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN MANGLE(ReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN) +#define glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN MANGLE(ReplacementCodeuiTexCoord2fNormal3fVertex3fSUN) +#define glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN MANGLE(ReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN) +#define glReplacementCodeuiTexCoord2fVertex3fSUN MANGLE(ReplacementCodeuiTexCoord2fVertex3fSUN) +#define glReplacementCodeuiTexCoord2fVertex3fvSUN MANGLE(ReplacementCodeuiTexCoord2fVertex3fvSUN) +#define glReplacementCodeuiVertex3fSUN MANGLE(ReplacementCodeuiVertex3fSUN) +#define glReplacementCodeuiVertex3fvSUN MANGLE(ReplacementCodeuiVertex3fvSUN) +#define glReplacementCodeuivSUN MANGLE(ReplacementCodeuivSUN) +#define glReplacementCodeusSUN MANGLE(ReplacementCodeusSUN) +#define glReplacementCodeusvSUN MANGLE(ReplacementCodeusvSUN) +#define glRequestResidentProgramsNV MANGLE(RequestResidentProgramsNV) +#define glResetHistogramEXT MANGLE(ResetHistogramEXT) +#define glResetHistogram MANGLE(ResetHistogram) +#define glResetMinmaxEXT MANGLE(ResetMinmaxEXT) +#define glResetMinmax MANGLE(ResetMinmax) +#define glResizeBuffersMESA MANGLE(ResizeBuffersMESA) +#define glResumeTransformFeedback MANGLE(ResumeTransformFeedback) +#define glResumeTransformFeedbackNV MANGLE(ResumeTransformFeedbackNV) +#define glRotated MANGLE(Rotated) +#define glRotatef MANGLE(Rotatef) +#define glSampleCoverageARB MANGLE(SampleCoverageARB) +#define glSampleCoverage MANGLE(SampleCoverage) +#define glSampleMapATI MANGLE(SampleMapATI) +#define glSampleMaskEXT MANGLE(SampleMaskEXT) +#define glSampleMaski MANGLE(SampleMaski) +#define glSampleMaskIndexedNV MANGLE(SampleMaskIndexedNV) +#define glSampleMaskSGIS MANGLE(SampleMaskSGIS) +#define glSamplePatternEXT MANGLE(SamplePatternEXT) +#define glSamplePatternSGIS MANGLE(SamplePatternSGIS) +#define glSamplerParameterf MANGLE(SamplerParameterf) +#define glSamplerParameterfv MANGLE(SamplerParameterfv) +#define glSamplerParameterIiv MANGLE(SamplerParameterIiv) +#define glSamplerParameteri MANGLE(SamplerParameteri) +#define glSamplerParameterIuiv MANGLE(SamplerParameterIuiv) +#define glSamplerParameteriv MANGLE(SamplerParameteriv) +#define glScaled MANGLE(Scaled) +#define glScalef MANGLE(Scalef) +#define glScissorArrayv MANGLE(ScissorArrayv) +#define glScissorIndexed MANGLE(ScissorIndexed) +#define glScissorIndexedv MANGLE(ScissorIndexedv) +#define glScissor MANGLE(Scissor) +#define glSecondaryColor3bEXT MANGLE(SecondaryColor3bEXT) +#define glSecondaryColor3b MANGLE(SecondaryColor3b) +#define glSecondaryColor3bvEXT MANGLE(SecondaryColor3bvEXT) +#define glSecondaryColor3bv MANGLE(SecondaryColor3bv) +#define glSecondaryColor3dEXT MANGLE(SecondaryColor3dEXT) +#define glSecondaryColor3d MANGLE(SecondaryColor3d) +#define glSecondaryColor3dvEXT MANGLE(SecondaryColor3dvEXT) +#define glSecondaryColor3dv MANGLE(SecondaryColor3dv) +#define glSecondaryColor3fEXT MANGLE(SecondaryColor3fEXT) +#define glSecondaryColor3f MANGLE(SecondaryColor3f) +#define glSecondaryColor3fvEXT MANGLE(SecondaryColor3fvEXT) +#define glSecondaryColor3fv MANGLE(SecondaryColor3fv) +#define glSecondaryColor3hNV MANGLE(SecondaryColor3hNV) +#define glSecondaryColor3hvNV MANGLE(SecondaryColor3hvNV) +#define glSecondaryColor3iEXT MANGLE(SecondaryColor3iEXT) +#define glSecondaryColor3i MANGLE(SecondaryColor3i) +#define glSecondaryColor3ivEXT MANGLE(SecondaryColor3ivEXT) +#define glSecondaryColor3iv MANGLE(SecondaryColor3iv) +#define glSecondaryColor3sEXT MANGLE(SecondaryColor3sEXT) +#define glSecondaryColor3s MANGLE(SecondaryColor3s) +#define glSecondaryColor3svEXT MANGLE(SecondaryColor3svEXT) +#define glSecondaryColor3sv MANGLE(SecondaryColor3sv) +#define glSecondaryColor3ubEXT MANGLE(SecondaryColor3ubEXT) +#define glSecondaryColor3ub MANGLE(SecondaryColor3ub) +#define glSecondaryColor3ubvEXT MANGLE(SecondaryColor3ubvEXT) +#define glSecondaryColor3ubv MANGLE(SecondaryColor3ubv) +#define glSecondaryColor3uiEXT MANGLE(SecondaryColor3uiEXT) +#define glSecondaryColor3ui MANGLE(SecondaryColor3ui) +#define glSecondaryColor3uivEXT MANGLE(SecondaryColor3uivEXT) +#define glSecondaryColor3uiv MANGLE(SecondaryColor3uiv) +#define glSecondaryColor3usEXT MANGLE(SecondaryColor3usEXT) +#define glSecondaryColor3us MANGLE(SecondaryColor3us) +#define glSecondaryColor3usvEXT MANGLE(SecondaryColor3usvEXT) +#define glSecondaryColor3usv MANGLE(SecondaryColor3usv) +#define glSecondaryColorFormatNV MANGLE(SecondaryColorFormatNV) +#define glSecondaryColorP3ui MANGLE(SecondaryColorP3ui) +#define glSecondaryColorP3uiv MANGLE(SecondaryColorP3uiv) +#define glSecondaryColorPointerEXT MANGLE(SecondaryColorPointerEXT) +#define glSecondaryColorPointerListIBM MANGLE(SecondaryColorPointerListIBM) +#define glSecondaryColorPointer MANGLE(SecondaryColorPointer) +#define glSelectBuffer MANGLE(SelectBuffer) +#define glSelectPerfMonitorCountersAMD MANGLE(SelectPerfMonitorCountersAMD) +#define glSeparableFilter2DEXT MANGLE(SeparableFilter2DEXT) +#define glSeparableFilter2D MANGLE(SeparableFilter2D) +#define glSetFenceAPPLE MANGLE(SetFenceAPPLE) +#define glSetFenceNV MANGLE(SetFenceNV) +#define glSetFragmentShaderConstantATI MANGLE(SetFragmentShaderConstantATI) +#define glSetInvariantEXT MANGLE(SetInvariantEXT) +#define glSetLocalConstantEXT MANGLE(SetLocalConstantEXT) +#define glShadeModel MANGLE(ShadeModel) +#define glShaderBinary MANGLE(ShaderBinary) +#define glShaderOp1EXT MANGLE(ShaderOp1EXT) +#define glShaderOp2EXT MANGLE(ShaderOp2EXT) +#define glShaderOp3EXT MANGLE(ShaderOp3EXT) +#define glShaderSourceARB MANGLE(ShaderSourceARB) +#define glShaderSource MANGLE(ShaderSource) +#define glSharpenTexFuncSGIS MANGLE(SharpenTexFuncSGIS) +#define glSpriteParameterfSGIX MANGLE(SpriteParameterfSGIX) +#define glSpriteParameterfvSGIX MANGLE(SpriteParameterfvSGIX) +#define glSpriteParameteriSGIX MANGLE(SpriteParameteriSGIX) +#define glSpriteParameterivSGIX MANGLE(SpriteParameterivSGIX) +#define glStartInstrumentsSGIX MANGLE(StartInstrumentsSGIX) +#define glStencilClearTagEXT MANGLE(StencilClearTagEXT) +#define glStencilFunc MANGLE(StencilFunc) +#define glStencilFuncSeparateATI MANGLE(StencilFuncSeparateATI) +#define glStencilFuncSeparate MANGLE(StencilFuncSeparate) +#define glStencilMask MANGLE(StencilMask) +#define glStencilMaskSeparate MANGLE(StencilMaskSeparate) +#define glStencilOp MANGLE(StencilOp) +#define glStencilOpSeparateATI MANGLE(StencilOpSeparateATI) +#define glStencilOpSeparate MANGLE(StencilOpSeparate) +#define glStopInstrumentsSGIX MANGLE(StopInstrumentsSGIX) +#define glStringMarkerGREMEDY MANGLE(StringMarkerGREMEDY) +#define glSwizzleEXT MANGLE(SwizzleEXT) +#define glTagSampleBufferSGIX MANGLE(TagSampleBufferSGIX) +#define glTangent3bEXT MANGLE(Tangent3bEXT) +#define glTangent3bvEXT MANGLE(Tangent3bvEXT) +#define glTangent3dEXT MANGLE(Tangent3dEXT) +#define glTangent3dvEXT MANGLE(Tangent3dvEXT) +#define glTangent3fEXT MANGLE(Tangent3fEXT) +#define glTangent3fvEXT MANGLE(Tangent3fvEXT) +#define glTangent3iEXT MANGLE(Tangent3iEXT) +#define glTangent3ivEXT MANGLE(Tangent3ivEXT) +#define glTangent3sEXT MANGLE(Tangent3sEXT) +#define glTangent3svEXT MANGLE(Tangent3svEXT) +#define glTangentPointerEXT MANGLE(TangentPointerEXT) +#define glTbufferMask3DFX MANGLE(TbufferMask3DFX) +#define glTessellationFactorAMD MANGLE(TessellationFactorAMD) +#define glTessellationModeAMD MANGLE(TessellationModeAMD) +#define glTestFenceAPPLE MANGLE(TestFenceAPPLE) +#define glTestFenceNV MANGLE(TestFenceNV) +#define glTestObjectAPPLE MANGLE(TestObjectAPPLE) +#define glTexBufferARB MANGLE(TexBufferARB) +#define glTexBufferEXT MANGLE(TexBufferEXT) +#define glTexBuffer MANGLE(TexBuffer) +#define glTexBumpParameterfvATI MANGLE(TexBumpParameterfvATI) +#define glTexBumpParameterivATI MANGLE(TexBumpParameterivATI) +#define glTexCoord1d MANGLE(TexCoord1d) +#define glTexCoord1dv MANGLE(TexCoord1dv) +#define glTexCoord1f MANGLE(TexCoord1f) +#define glTexCoord1fv MANGLE(TexCoord1fv) +#define glTexCoord1hNV MANGLE(TexCoord1hNV) +#define glTexCoord1hvNV MANGLE(TexCoord1hvNV) +#define glTexCoord1i MANGLE(TexCoord1i) +#define glTexCoord1iv MANGLE(TexCoord1iv) +#define glTexCoord1s MANGLE(TexCoord1s) +#define glTexCoord1sv MANGLE(TexCoord1sv) +#define glTexCoord2d MANGLE(TexCoord2d) +#define glTexCoord2dv MANGLE(TexCoord2dv) +#define glTexCoord2fColor3fVertex3fSUN MANGLE(TexCoord2fColor3fVertex3fSUN) +#define glTexCoord2fColor3fVertex3fvSUN MANGLE(TexCoord2fColor3fVertex3fvSUN) +#define glTexCoord2fColor4fNormal3fVertex3fSUN MANGLE(TexCoord2fColor4fNormal3fVertex3fSUN) +#define glTexCoord2fColor4fNormal3fVertex3fvSUN MANGLE(TexCoord2fColor4fNormal3fVertex3fvSUN) +#define glTexCoord2fColor4ubVertex3fSUN MANGLE(TexCoord2fColor4ubVertex3fSUN) +#define glTexCoord2fColor4ubVertex3fvSUN MANGLE(TexCoord2fColor4ubVertex3fvSUN) +#define glTexCoord2f MANGLE(TexCoord2f) +#define glTexCoord2fNormal3fVertex3fSUN MANGLE(TexCoord2fNormal3fVertex3fSUN) +#define glTexCoord2fNormal3fVertex3fvSUN MANGLE(TexCoord2fNormal3fVertex3fvSUN) +#define glTexCoord2fVertex3fSUN MANGLE(TexCoord2fVertex3fSUN) +#define glTexCoord2fVertex3fvSUN MANGLE(TexCoord2fVertex3fvSUN) +#define glTexCoord2fv MANGLE(TexCoord2fv) +#define glTexCoord2hNV MANGLE(TexCoord2hNV) +#define glTexCoord2hvNV MANGLE(TexCoord2hvNV) +#define glTexCoord2i MANGLE(TexCoord2i) +#define glTexCoord2iv MANGLE(TexCoord2iv) +#define glTexCoord2s MANGLE(TexCoord2s) +#define glTexCoord2sv MANGLE(TexCoord2sv) +#define glTexCoord3d MANGLE(TexCoord3d) +#define glTexCoord3dv MANGLE(TexCoord3dv) +#define glTexCoord3f MANGLE(TexCoord3f) +#define glTexCoord3fv MANGLE(TexCoord3fv) +#define glTexCoord3hNV MANGLE(TexCoord3hNV) +#define glTexCoord3hvNV MANGLE(TexCoord3hvNV) +#define glTexCoord3i MANGLE(TexCoord3i) +#define glTexCoord3iv MANGLE(TexCoord3iv) +#define glTexCoord3s MANGLE(TexCoord3s) +#define glTexCoord3sv MANGLE(TexCoord3sv) +#define glTexCoord4d MANGLE(TexCoord4d) +#define glTexCoord4dv MANGLE(TexCoord4dv) +#define glTexCoord4fColor4fNormal3fVertex4fSUN MANGLE(TexCoord4fColor4fNormal3fVertex4fSUN) +#define glTexCoord4fColor4fNormal3fVertex4fvSUN MANGLE(TexCoord4fColor4fNormal3fVertex4fvSUN) +#define glTexCoord4f MANGLE(TexCoord4f) +#define glTexCoord4fVertex4fSUN MANGLE(TexCoord4fVertex4fSUN) +#define glTexCoord4fVertex4fvSUN MANGLE(TexCoord4fVertex4fvSUN) +#define glTexCoord4fv MANGLE(TexCoord4fv) +#define glTexCoord4hNV MANGLE(TexCoord4hNV) +#define glTexCoord4hvNV MANGLE(TexCoord4hvNV) +#define glTexCoord4i MANGLE(TexCoord4i) +#define glTexCoord4iv MANGLE(TexCoord4iv) +#define glTexCoord4s MANGLE(TexCoord4s) +#define glTexCoord4sv MANGLE(TexCoord4sv) +#define glTexCoordFormatNV MANGLE(TexCoordFormatNV) +#define glTexCoordP1ui MANGLE(TexCoordP1ui) +#define glTexCoordP1uiv MANGLE(TexCoordP1uiv) +#define glTexCoordP2ui MANGLE(TexCoordP2ui) +#define glTexCoordP2uiv MANGLE(TexCoordP2uiv) +#define glTexCoordP3ui MANGLE(TexCoordP3ui) +#define glTexCoordP3uiv MANGLE(TexCoordP3uiv) +#define glTexCoordP4ui MANGLE(TexCoordP4ui) +#define glTexCoordP4uiv MANGLE(TexCoordP4uiv) +#define glTexCoordPointerEXT MANGLE(TexCoordPointerEXT) +#define glTexCoordPointerListIBM MANGLE(TexCoordPointerListIBM) +#define glTexCoordPointer MANGLE(TexCoordPointer) +#define glTexCoordPointervINTEL MANGLE(TexCoordPointervINTEL) +#define glTexEnvf MANGLE(TexEnvf) +#define glTexEnvfv MANGLE(TexEnvfv) +#define glTexEnvi MANGLE(TexEnvi) +#define glTexEnviv MANGLE(TexEnviv) +#define glTexFilterFuncSGIS MANGLE(TexFilterFuncSGIS) +#define glTexGend MANGLE(TexGend) +#define glTexGendv MANGLE(TexGendv) +#define glTexGenf MANGLE(TexGenf) +#define glTexGenfv MANGLE(TexGenfv) +#define glTexGeni MANGLE(TexGeni) +#define glTexGeniv MANGLE(TexGeniv) +#define glTexImage1D MANGLE(TexImage1D) +#define glTexImage2D MANGLE(TexImage2D) +#define glTexImage2DMultisample MANGLE(TexImage2DMultisample) +#define glTexImage3DEXT MANGLE(TexImage3DEXT) +#define glTexImage3D MANGLE(TexImage3D) +#define glTexImage3DMultisample MANGLE(TexImage3DMultisample) +#define glTexImage4DSGIS MANGLE(TexImage4DSGIS) +#define glTexParameterf MANGLE(TexParameterf) +#define glTexParameterfv MANGLE(TexParameterfv) +#define glTexParameterIivEXT MANGLE(TexParameterIivEXT) +#define glTexParameterIiv MANGLE(TexParameterIiv) +#define glTexParameteri MANGLE(TexParameteri) +#define glTexParameterIuivEXT MANGLE(TexParameterIuivEXT) +#define glTexParameterIuiv MANGLE(TexParameterIuiv) +#define glTexParameteriv MANGLE(TexParameteriv) +#define glTexRenderbufferNV MANGLE(TexRenderbufferNV) +#define glTexSubImage1DEXT MANGLE(TexSubImage1DEXT) +#define glTexSubImage1D MANGLE(TexSubImage1D) +#define glTexSubImage2DEXT MANGLE(TexSubImage2DEXT) +#define glTexSubImage2D MANGLE(TexSubImage2D) +#define glTexSubImage3DEXT MANGLE(TexSubImage3DEXT) +#define glTexSubImage3D MANGLE(TexSubImage3D) +#define glTexSubImage4DSGIS MANGLE(TexSubImage4DSGIS) +#define glTextureBarrierNV MANGLE(TextureBarrierNV) +#define glTextureBufferEXT MANGLE(TextureBufferEXT) +#define glTextureColorMaskSGIS MANGLE(TextureColorMaskSGIS) +#define glTextureImage1DEXT MANGLE(TextureImage1DEXT) +#define glTextureImage2DEXT MANGLE(TextureImage2DEXT) +#define glTextureImage3DEXT MANGLE(TextureImage3DEXT) +#define glTextureLightEXT MANGLE(TextureLightEXT) +#define glTextureMaterialEXT MANGLE(TextureMaterialEXT) +#define glTextureNormalEXT MANGLE(TextureNormalEXT) +#define glTextureParameterfEXT MANGLE(TextureParameterfEXT) +#define glTextureParameterfvEXT MANGLE(TextureParameterfvEXT) +#define glTextureParameteriEXT MANGLE(TextureParameteriEXT) +#define glTextureParameterIivEXT MANGLE(TextureParameterIivEXT) +#define glTextureParameterIuivEXT MANGLE(TextureParameterIuivEXT) +#define glTextureParameterivEXT MANGLE(TextureParameterivEXT) +#define glTextureRangeAPPLE MANGLE(TextureRangeAPPLE) +#define glTextureRenderbufferEXT MANGLE(TextureRenderbufferEXT) +#define glTextureSubImage1DEXT MANGLE(TextureSubImage1DEXT) +#define glTextureSubImage2DEXT MANGLE(TextureSubImage2DEXT) +#define glTextureSubImage3DEXT MANGLE(TextureSubImage3DEXT) +#define glTrackMatrixNV MANGLE(TrackMatrixNV) +#define glTransformFeedbackAttribsNV MANGLE(TransformFeedbackAttribsNV) +#define glTransformFeedbackStreamAttribsNV MANGLE(TransformFeedbackStreamAttribsNV) +#define glTransformFeedbackVaryingsEXT MANGLE(TransformFeedbackVaryingsEXT) +#define glTransformFeedbackVaryings MANGLE(TransformFeedbackVaryings) +#define glTransformFeedbackVaryingsNV MANGLE(TransformFeedbackVaryingsNV) +#define glTranslated MANGLE(Translated) +#define glTranslatef MANGLE(Translatef) +#define glUniform1d MANGLE(Uniform1d) +#define glUniform1dv MANGLE(Uniform1dv) +#define glUniform1fARB MANGLE(Uniform1fARB) +#define glUniform1f MANGLE(Uniform1f) +#define glUniform1fvARB MANGLE(Uniform1fvARB) +#define glUniform1fv MANGLE(Uniform1fv) +#define glUniform1i64NV MANGLE(Uniform1i64NV) +#define glUniform1i64vNV MANGLE(Uniform1i64vNV) +#define glUniform1iARB MANGLE(Uniform1iARB) +#define glUniform1i MANGLE(Uniform1i) +#define glUniform1ivARB MANGLE(Uniform1ivARB) +#define glUniform1iv MANGLE(Uniform1iv) +#define glUniform1ui64NV MANGLE(Uniform1ui64NV) +#define glUniform1ui64vNV MANGLE(Uniform1ui64vNV) +#define glUniform1uiEXT MANGLE(Uniform1uiEXT) +#define glUniform1ui MANGLE(Uniform1ui) +#define glUniform1uivEXT MANGLE(Uniform1uivEXT) +#define glUniform1uiv MANGLE(Uniform1uiv) +#define glUniform2d MANGLE(Uniform2d) +#define glUniform2dv MANGLE(Uniform2dv) +#define glUniform2fARB MANGLE(Uniform2fARB) +#define glUniform2f MANGLE(Uniform2f) +#define glUniform2fvARB MANGLE(Uniform2fvARB) +#define glUniform2fv MANGLE(Uniform2fv) +#define glUniform2i64NV MANGLE(Uniform2i64NV) +#define glUniform2i64vNV MANGLE(Uniform2i64vNV) +#define glUniform2iARB MANGLE(Uniform2iARB) +#define glUniform2i MANGLE(Uniform2i) +#define glUniform2ivARB MANGLE(Uniform2ivARB) +#define glUniform2iv MANGLE(Uniform2iv) +#define glUniform2ui64NV MANGLE(Uniform2ui64NV) +#define glUniform2ui64vNV MANGLE(Uniform2ui64vNV) +#define glUniform2uiEXT MANGLE(Uniform2uiEXT) +#define glUniform2ui MANGLE(Uniform2ui) +#define glUniform2uivEXT MANGLE(Uniform2uivEXT) +#define glUniform2uiv MANGLE(Uniform2uiv) +#define glUniform3d MANGLE(Uniform3d) +#define glUniform3dv MANGLE(Uniform3dv) +#define glUniform3fARB MANGLE(Uniform3fARB) +#define glUniform3f MANGLE(Uniform3f) +#define glUniform3fvARB MANGLE(Uniform3fvARB) +#define glUniform3fv MANGLE(Uniform3fv) +#define glUniform3i64NV MANGLE(Uniform3i64NV) +#define glUniform3i64vNV MANGLE(Uniform3i64vNV) +#define glUniform3iARB MANGLE(Uniform3iARB) +#define glUniform3i MANGLE(Uniform3i) +#define glUniform3ivARB MANGLE(Uniform3ivARB) +#define glUniform3iv MANGLE(Uniform3iv) +#define glUniform3ui64NV MANGLE(Uniform3ui64NV) +#define glUniform3ui64vNV MANGLE(Uniform3ui64vNV) +#define glUniform3uiEXT MANGLE(Uniform3uiEXT) +#define glUniform3ui MANGLE(Uniform3ui) +#define glUniform3uivEXT MANGLE(Uniform3uivEXT) +#define glUniform3uiv MANGLE(Uniform3uiv) +#define glUniform4d MANGLE(Uniform4d) +#define glUniform4dv MANGLE(Uniform4dv) +#define glUniform4fARB MANGLE(Uniform4fARB) +#define glUniform4f MANGLE(Uniform4f) +#define glUniform4fvARB MANGLE(Uniform4fvARB) +#define glUniform4fv MANGLE(Uniform4fv) +#define glUniform4i64NV MANGLE(Uniform4i64NV) +#define glUniform4i64vNV MANGLE(Uniform4i64vNV) +#define glUniform4iARB MANGLE(Uniform4iARB) +#define glUniform4i MANGLE(Uniform4i) +#define glUniform4ivARB MANGLE(Uniform4ivARB) +#define glUniform4iv MANGLE(Uniform4iv) +#define glUniform4ui64NV MANGLE(Uniform4ui64NV) +#define glUniform4ui64vNV MANGLE(Uniform4ui64vNV) +#define glUniform4uiEXT MANGLE(Uniform4uiEXT) +#define glUniform4ui MANGLE(Uniform4ui) +#define glUniform4uivEXT MANGLE(Uniform4uivEXT) +#define glUniform4uiv MANGLE(Uniform4uiv) +#define glUniformBlockBinding MANGLE(UniformBlockBinding) +#define glUniformBufferEXT MANGLE(UniformBufferEXT) +#define glUniformMatrix2dv MANGLE(UniformMatrix2dv) +#define glUniformMatrix2fvARB MANGLE(UniformMatrix2fvARB) +#define glUniformMatrix2fv MANGLE(UniformMatrix2fv) +#define glUniformMatrix2x3dv MANGLE(UniformMatrix2x3dv) +#define glUniformMatrix2x3fv MANGLE(UniformMatrix2x3fv) +#define glUniformMatrix2x4dv MANGLE(UniformMatrix2x4dv) +#define glUniformMatrix2x4fv MANGLE(UniformMatrix2x4fv) +#define glUniformMatrix3dv MANGLE(UniformMatrix3dv) +#define glUniformMatrix3fvARB MANGLE(UniformMatrix3fvARB) +#define glUniformMatrix3fv MANGLE(UniformMatrix3fv) +#define glUniformMatrix3x2dv MANGLE(UniformMatrix3x2dv) +#define glUniformMatrix3x2fv MANGLE(UniformMatrix3x2fv) +#define glUniformMatrix3x4dv MANGLE(UniformMatrix3x4dv) +#define glUniformMatrix3x4fv MANGLE(UniformMatrix3x4fv) +#define glUniformMatrix4dv MANGLE(UniformMatrix4dv) +#define glUniformMatrix4fvARB MANGLE(UniformMatrix4fvARB) +#define glUniformMatrix4fv MANGLE(UniformMatrix4fv) +#define glUniformMatrix4x2dv MANGLE(UniformMatrix4x2dv) +#define glUniformMatrix4x2fv MANGLE(UniformMatrix4x2fv) +#define glUniformMatrix4x3dv MANGLE(UniformMatrix4x3dv) +#define glUniformMatrix4x3fv MANGLE(UniformMatrix4x3fv) +#define glUniformSubroutinesuiv MANGLE(UniformSubroutinesuiv) +#define glUniformui64NV MANGLE(Uniformui64NV) +#define glUniformui64vNV MANGLE(Uniformui64vNV) +#define glUnlockArraysEXT MANGLE(UnlockArraysEXT) +#define glUnmapBufferARB MANGLE(UnmapBufferARB) +#define glUnmapBuffer MANGLE(UnmapBuffer) +#define glUnmapNamedBufferEXT MANGLE(UnmapNamedBufferEXT) +#define glUnmapObjectBufferATI MANGLE(UnmapObjectBufferATI) +#define glUpdateObjectBufferATI MANGLE(UpdateObjectBufferATI) +#define glUseProgram MANGLE(UseProgram) +#define glUseProgramObjectARB MANGLE(UseProgramObjectARB) +#define glUseProgramStages MANGLE(UseProgramStages) +#define glUseShaderProgramEXT MANGLE(UseShaderProgramEXT) +#define glValidateProgramARB MANGLE(ValidateProgramARB) +#define glValidateProgram MANGLE(ValidateProgram) +#define glValidateProgramPipeline MANGLE(ValidateProgramPipeline) +#define glVariantArrayObjectATI MANGLE(VariantArrayObjectATI) +#define glVariantbvEXT MANGLE(VariantbvEXT) +#define glVariantdvEXT MANGLE(VariantdvEXT) +#define glVariantfvEXT MANGLE(VariantfvEXT) +#define glVariantivEXT MANGLE(VariantivEXT) +#define glVariantPointerEXT MANGLE(VariantPointerEXT) +#define glVariantsvEXT MANGLE(VariantsvEXT) +#define glVariantubvEXT MANGLE(VariantubvEXT) +#define glVariantuivEXT MANGLE(VariantuivEXT) +#define glVariantusvEXT MANGLE(VariantusvEXT) +#define glVDPAUFiniNV MANGLE(VDPAUFiniNV) +#define glVDPAUGetSurfaceivNV MANGLE(VDPAUGetSurfaceivNV) +#define glVDPAUInitNV MANGLE(VDPAUInitNV) +#define glVDPAUIsSurfaceNV MANGLE(VDPAUIsSurfaceNV) +#define glVDPAUMapSurfacesNV MANGLE(VDPAUMapSurfacesNV) +#define glVDPAURegisterOutputSurfaceNV MANGLE(VDPAURegisterOutputSurfaceNV) +#define glVDPAURegisterVideoSurfaceNV MANGLE(VDPAURegisterVideoSurfaceNV) +#define glVDPAUSurfaceAccessNV MANGLE(VDPAUSurfaceAccessNV) +#define glVDPAUUnmapSurfacesNV MANGLE(VDPAUUnmapSurfacesNV) +#define glVDPAUUnregisterSurfaceNV MANGLE(VDPAUUnregisterSurfaceNV) +#define glVertex2d MANGLE(Vertex2d) +#define glVertex2dv MANGLE(Vertex2dv) +#define glVertex2f MANGLE(Vertex2f) +#define glVertex2fv MANGLE(Vertex2fv) +#define glVertex2hNV MANGLE(Vertex2hNV) +#define glVertex2hvNV MANGLE(Vertex2hvNV) +#define glVertex2i MANGLE(Vertex2i) +#define glVertex2iv MANGLE(Vertex2iv) +#define glVertex2s MANGLE(Vertex2s) +#define glVertex2sv MANGLE(Vertex2sv) +#define glVertex3d MANGLE(Vertex3d) +#define glVertex3dv MANGLE(Vertex3dv) +#define glVertex3f MANGLE(Vertex3f) +#define glVertex3fv MANGLE(Vertex3fv) +#define glVertex3hNV MANGLE(Vertex3hNV) +#define glVertex3hvNV MANGLE(Vertex3hvNV) +#define glVertex3i MANGLE(Vertex3i) +#define glVertex3iv MANGLE(Vertex3iv) +#define glVertex3s MANGLE(Vertex3s) +#define glVertex3sv MANGLE(Vertex3sv) +#define glVertex4d MANGLE(Vertex4d) +#define glVertex4dv MANGLE(Vertex4dv) +#define glVertex4f MANGLE(Vertex4f) +#define glVertex4fv MANGLE(Vertex4fv) +#define glVertex4hNV MANGLE(Vertex4hNV) +#define glVertex4hvNV MANGLE(Vertex4hvNV) +#define glVertex4i MANGLE(Vertex4i) +#define glVertex4iv MANGLE(Vertex4iv) +#define glVertex4s MANGLE(Vertex4s) +#define glVertex4sv MANGLE(Vertex4sv) +#define glVertexArrayParameteriAPPLE MANGLE(VertexArrayParameteriAPPLE) +#define glVertexArrayRangeAPPLE MANGLE(VertexArrayRangeAPPLE) +#define glVertexArrayRangeNV MANGLE(VertexArrayRangeNV) +#define glVertexArrayVertexAttribLOffsetEXT MANGLE(VertexArrayVertexAttribLOffsetEXT) +#define glVertexAttrib1dARB MANGLE(VertexAttrib1dARB) +#define glVertexAttrib1d MANGLE(VertexAttrib1d) +#define glVertexAttrib1dNV MANGLE(VertexAttrib1dNV) +#define glVertexAttrib1dvARB MANGLE(VertexAttrib1dvARB) +#define glVertexAttrib1dv MANGLE(VertexAttrib1dv) +#define glVertexAttrib1dvNV MANGLE(VertexAttrib1dvNV) +#define glVertexAttrib1fARB MANGLE(VertexAttrib1fARB) +#define glVertexAttrib1f MANGLE(VertexAttrib1f) +#define glVertexAttrib1fNV MANGLE(VertexAttrib1fNV) +#define glVertexAttrib1fvARB MANGLE(VertexAttrib1fvARB) +#define glVertexAttrib1fv MANGLE(VertexAttrib1fv) +#define glVertexAttrib1fvNV MANGLE(VertexAttrib1fvNV) +#define glVertexAttrib1hNV MANGLE(VertexAttrib1hNV) +#define glVertexAttrib1hvNV MANGLE(VertexAttrib1hvNV) +#define glVertexAttrib1sARB MANGLE(VertexAttrib1sARB) +#define glVertexAttrib1s MANGLE(VertexAttrib1s) +#define glVertexAttrib1sNV MANGLE(VertexAttrib1sNV) +#define glVertexAttrib1svARB MANGLE(VertexAttrib1svARB) +#define glVertexAttrib1sv MANGLE(VertexAttrib1sv) +#define glVertexAttrib1svNV MANGLE(VertexAttrib1svNV) +#define glVertexAttrib2dARB MANGLE(VertexAttrib2dARB) +#define glVertexAttrib2d MANGLE(VertexAttrib2d) +#define glVertexAttrib2dNV MANGLE(VertexAttrib2dNV) +#define glVertexAttrib2dvARB MANGLE(VertexAttrib2dvARB) +#define glVertexAttrib2dv MANGLE(VertexAttrib2dv) +#define glVertexAttrib2dvNV MANGLE(VertexAttrib2dvNV) +#define glVertexAttrib2fARB MANGLE(VertexAttrib2fARB) +#define glVertexAttrib2f MANGLE(VertexAttrib2f) +#define glVertexAttrib2fNV MANGLE(VertexAttrib2fNV) +#define glVertexAttrib2fvARB MANGLE(VertexAttrib2fvARB) +#define glVertexAttrib2fv MANGLE(VertexAttrib2fv) +#define glVertexAttrib2fvNV MANGLE(VertexAttrib2fvNV) +#define glVertexAttrib2hNV MANGLE(VertexAttrib2hNV) +#define glVertexAttrib2hvNV MANGLE(VertexAttrib2hvNV) +#define glVertexAttrib2sARB MANGLE(VertexAttrib2sARB) +#define glVertexAttrib2s MANGLE(VertexAttrib2s) +#define glVertexAttrib2sNV MANGLE(VertexAttrib2sNV) +#define glVertexAttrib2svARB MANGLE(VertexAttrib2svARB) +#define glVertexAttrib2sv MANGLE(VertexAttrib2sv) +#define glVertexAttrib2svNV MANGLE(VertexAttrib2svNV) +#define glVertexAttrib3dARB MANGLE(VertexAttrib3dARB) +#define glVertexAttrib3d MANGLE(VertexAttrib3d) +#define glVertexAttrib3dNV MANGLE(VertexAttrib3dNV) +#define glVertexAttrib3dvARB MANGLE(VertexAttrib3dvARB) +#define glVertexAttrib3dv MANGLE(VertexAttrib3dv) +#define glVertexAttrib3dvNV MANGLE(VertexAttrib3dvNV) +#define glVertexAttrib3fARB MANGLE(VertexAttrib3fARB) +#define glVertexAttrib3f MANGLE(VertexAttrib3f) +#define glVertexAttrib3fNV MANGLE(VertexAttrib3fNV) +#define glVertexAttrib3fvARB MANGLE(VertexAttrib3fvARB) +#define glVertexAttrib3fv MANGLE(VertexAttrib3fv) +#define glVertexAttrib3fvNV MANGLE(VertexAttrib3fvNV) +#define glVertexAttrib3hNV MANGLE(VertexAttrib3hNV) +#define glVertexAttrib3hvNV MANGLE(VertexAttrib3hvNV) +#define glVertexAttrib3sARB MANGLE(VertexAttrib3sARB) +#define glVertexAttrib3s MANGLE(VertexAttrib3s) +#define glVertexAttrib3sNV MANGLE(VertexAttrib3sNV) +#define glVertexAttrib3svARB MANGLE(VertexAttrib3svARB) +#define glVertexAttrib3sv MANGLE(VertexAttrib3sv) +#define glVertexAttrib3svNV MANGLE(VertexAttrib3svNV) +#define glVertexAttrib4bvARB MANGLE(VertexAttrib4bvARB) +#define glVertexAttrib4bv MANGLE(VertexAttrib4bv) +#define glVertexAttrib4dARB MANGLE(VertexAttrib4dARB) +#define glVertexAttrib4d MANGLE(VertexAttrib4d) +#define glVertexAttrib4dNV MANGLE(VertexAttrib4dNV) +#define glVertexAttrib4dvARB MANGLE(VertexAttrib4dvARB) +#define glVertexAttrib4dv MANGLE(VertexAttrib4dv) +#define glVertexAttrib4dvNV MANGLE(VertexAttrib4dvNV) +#define glVertexAttrib4fARB MANGLE(VertexAttrib4fARB) +#define glVertexAttrib4f MANGLE(VertexAttrib4f) +#define glVertexAttrib4fNV MANGLE(VertexAttrib4fNV) +#define glVertexAttrib4fvARB MANGLE(VertexAttrib4fvARB) +#define glVertexAttrib4fv MANGLE(VertexAttrib4fv) +#define glVertexAttrib4fvNV MANGLE(VertexAttrib4fvNV) +#define glVertexAttrib4hNV MANGLE(VertexAttrib4hNV) +#define glVertexAttrib4hvNV MANGLE(VertexAttrib4hvNV) +#define glVertexAttrib4ivARB MANGLE(VertexAttrib4ivARB) +#define glVertexAttrib4iv MANGLE(VertexAttrib4iv) +#define glVertexAttrib4NbvARB MANGLE(VertexAttrib4NbvARB) +#define glVertexAttrib4Nbv MANGLE(VertexAttrib4Nbv) +#define glVertexAttrib4NivARB MANGLE(VertexAttrib4NivARB) +#define glVertexAttrib4Niv MANGLE(VertexAttrib4Niv) +#define glVertexAttrib4NsvARB MANGLE(VertexAttrib4NsvARB) +#define glVertexAttrib4Nsv MANGLE(VertexAttrib4Nsv) +#define glVertexAttrib4NubARB MANGLE(VertexAttrib4NubARB) +#define glVertexAttrib4Nub MANGLE(VertexAttrib4Nub) +#define glVertexAttrib4NubvARB MANGLE(VertexAttrib4NubvARB) +#define glVertexAttrib4Nubv MANGLE(VertexAttrib4Nubv) +#define glVertexAttrib4NuivARB MANGLE(VertexAttrib4NuivARB) +#define glVertexAttrib4Nuiv MANGLE(VertexAttrib4Nuiv) +#define glVertexAttrib4NusvARB MANGLE(VertexAttrib4NusvARB) +#define glVertexAttrib4Nusv MANGLE(VertexAttrib4Nusv) +#define glVertexAttrib4sARB MANGLE(VertexAttrib4sARB) +#define glVertexAttrib4s MANGLE(VertexAttrib4s) +#define glVertexAttrib4sNV MANGLE(VertexAttrib4sNV) +#define glVertexAttrib4svARB MANGLE(VertexAttrib4svARB) +#define glVertexAttrib4sv MANGLE(VertexAttrib4sv) +#define glVertexAttrib4svNV MANGLE(VertexAttrib4svNV) +#define glVertexAttrib4ubNV MANGLE(VertexAttrib4ubNV) +#define glVertexAttrib4ubvARB MANGLE(VertexAttrib4ubvARB) +#define glVertexAttrib4ubv MANGLE(VertexAttrib4ubv) +#define glVertexAttrib4ubvNV MANGLE(VertexAttrib4ubvNV) +#define glVertexAttrib4uivARB MANGLE(VertexAttrib4uivARB) +#define glVertexAttrib4uiv MANGLE(VertexAttrib4uiv) +#define glVertexAttrib4usvARB MANGLE(VertexAttrib4usvARB) +#define glVertexAttrib4usv MANGLE(VertexAttrib4usv) +#define glVertexAttribArrayObjectATI MANGLE(VertexAttribArrayObjectATI) +#define glVertexAttribDivisorARB MANGLE(VertexAttribDivisorARB) +#define glVertexAttribDivisor MANGLE(VertexAttribDivisor) +#define glVertexAttribFormatNV MANGLE(VertexAttribFormatNV) +#define glVertexAttribI1iEXT MANGLE(VertexAttribI1iEXT) +#define glVertexAttribI1i MANGLE(VertexAttribI1i) +#define glVertexAttribI1ivEXT MANGLE(VertexAttribI1ivEXT) +#define glVertexAttribI1iv MANGLE(VertexAttribI1iv) +#define glVertexAttribI1uiEXT MANGLE(VertexAttribI1uiEXT) +#define glVertexAttribI1ui MANGLE(VertexAttribI1ui) +#define glVertexAttribI1uivEXT MANGLE(VertexAttribI1uivEXT) +#define glVertexAttribI1uiv MANGLE(VertexAttribI1uiv) +#define glVertexAttribI2iEXT MANGLE(VertexAttribI2iEXT) +#define glVertexAttribI2i MANGLE(VertexAttribI2i) +#define glVertexAttribI2ivEXT MANGLE(VertexAttribI2ivEXT) +#define glVertexAttribI2iv MANGLE(VertexAttribI2iv) +#define glVertexAttribI2uiEXT MANGLE(VertexAttribI2uiEXT) +#define glVertexAttribI2ui MANGLE(VertexAttribI2ui) +#define glVertexAttribI2uivEXT MANGLE(VertexAttribI2uivEXT) +#define glVertexAttribI2uiv MANGLE(VertexAttribI2uiv) +#define glVertexAttribI3iEXT MANGLE(VertexAttribI3iEXT) +#define glVertexAttribI3i MANGLE(VertexAttribI3i) +#define glVertexAttribI3ivEXT MANGLE(VertexAttribI3ivEXT) +#define glVertexAttribI3iv MANGLE(VertexAttribI3iv) +#define glVertexAttribI3uiEXT MANGLE(VertexAttribI3uiEXT) +#define glVertexAttribI3ui MANGLE(VertexAttribI3ui) +#define glVertexAttribI3uivEXT MANGLE(VertexAttribI3uivEXT) +#define glVertexAttribI3uiv MANGLE(VertexAttribI3uiv) +#define glVertexAttribI4bvEXT MANGLE(VertexAttribI4bvEXT) +#define glVertexAttribI4bv MANGLE(VertexAttribI4bv) +#define glVertexAttribI4iEXT MANGLE(VertexAttribI4iEXT) +#define glVertexAttribI4i MANGLE(VertexAttribI4i) +#define glVertexAttribI4ivEXT MANGLE(VertexAttribI4ivEXT) +#define glVertexAttribI4iv MANGLE(VertexAttribI4iv) +#define glVertexAttribI4svEXT MANGLE(VertexAttribI4svEXT) +#define glVertexAttribI4sv MANGLE(VertexAttribI4sv) +#define glVertexAttribI4ubvEXT MANGLE(VertexAttribI4ubvEXT) +#define glVertexAttribI4ubv MANGLE(VertexAttribI4ubv) +#define glVertexAttribI4uiEXT MANGLE(VertexAttribI4uiEXT) +#define glVertexAttribI4ui MANGLE(VertexAttribI4ui) +#define glVertexAttribI4uivEXT MANGLE(VertexAttribI4uivEXT) +#define glVertexAttribI4uiv MANGLE(VertexAttribI4uiv) +#define glVertexAttribI4usvEXT MANGLE(VertexAttribI4usvEXT) +#define glVertexAttribI4usv MANGLE(VertexAttribI4usv) +#define glVertexAttribIFormatNV MANGLE(VertexAttribIFormatNV) +#define glVertexAttribIPointerEXT MANGLE(VertexAttribIPointerEXT) +#define glVertexAttribIPointer MANGLE(VertexAttribIPointer) +#define glVertexAttribL1dEXT MANGLE(VertexAttribL1dEXT) +#define glVertexAttribL1d MANGLE(VertexAttribL1d) +#define glVertexAttribL1dvEXT MANGLE(VertexAttribL1dvEXT) +#define glVertexAttribL1dv MANGLE(VertexAttribL1dv) +#define glVertexAttribL1i64NV MANGLE(VertexAttribL1i64NV) +#define glVertexAttribL1i64vNV MANGLE(VertexAttribL1i64vNV) +#define glVertexAttribL1ui64NV MANGLE(VertexAttribL1ui64NV) +#define glVertexAttribL1ui64vNV MANGLE(VertexAttribL1ui64vNV) +#define glVertexAttribL2dEXT MANGLE(VertexAttribL2dEXT) +#define glVertexAttribL2d MANGLE(VertexAttribL2d) +#define glVertexAttribL2dvEXT MANGLE(VertexAttribL2dvEXT) +#define glVertexAttribL2dv MANGLE(VertexAttribL2dv) +#define glVertexAttribL2i64NV MANGLE(VertexAttribL2i64NV) +#define glVertexAttribL2i64vNV MANGLE(VertexAttribL2i64vNV) +#define glVertexAttribL2ui64NV MANGLE(VertexAttribL2ui64NV) +#define glVertexAttribL2ui64vNV MANGLE(VertexAttribL2ui64vNV) +#define glVertexAttribL3dEXT MANGLE(VertexAttribL3dEXT) +#define glVertexAttribL3d MANGLE(VertexAttribL3d) +#define glVertexAttribL3dvEXT MANGLE(VertexAttribL3dvEXT) +#define glVertexAttribL3dv MANGLE(VertexAttribL3dv) +#define glVertexAttribL3i64NV MANGLE(VertexAttribL3i64NV) +#define glVertexAttribL3i64vNV MANGLE(VertexAttribL3i64vNV) +#define glVertexAttribL3ui64NV MANGLE(VertexAttribL3ui64NV) +#define glVertexAttribL3ui64vNV MANGLE(VertexAttribL3ui64vNV) +#define glVertexAttribL4dEXT MANGLE(VertexAttribL4dEXT) +#define glVertexAttribL4d MANGLE(VertexAttribL4d) +#define glVertexAttribL4dvEXT MANGLE(VertexAttribL4dvEXT) +#define glVertexAttribL4dv MANGLE(VertexAttribL4dv) +#define glVertexAttribL4i64NV MANGLE(VertexAttribL4i64NV) +#define glVertexAttribL4i64vNV MANGLE(VertexAttribL4i64vNV) +#define glVertexAttribL4ui64NV MANGLE(VertexAttribL4ui64NV) +#define glVertexAttribL4ui64vNV MANGLE(VertexAttribL4ui64vNV) +#define glVertexAttribLFormatNV MANGLE(VertexAttribLFormatNV) +#define glVertexAttribLPointerEXT MANGLE(VertexAttribLPointerEXT) +#define glVertexAttribLPointer MANGLE(VertexAttribLPointer) +#define glVertexAttribP1ui MANGLE(VertexAttribP1ui) +#define glVertexAttribP1uiv MANGLE(VertexAttribP1uiv) +#define glVertexAttribP2ui MANGLE(VertexAttribP2ui) +#define glVertexAttribP2uiv MANGLE(VertexAttribP2uiv) +#define glVertexAttribP3ui MANGLE(VertexAttribP3ui) +#define glVertexAttribP3uiv MANGLE(VertexAttribP3uiv) +#define glVertexAttribP4ui MANGLE(VertexAttribP4ui) +#define glVertexAttribP4uiv MANGLE(VertexAttribP4uiv) +#define glVertexAttribPointerARB MANGLE(VertexAttribPointerARB) +#define glVertexAttribPointer MANGLE(VertexAttribPointer) +#define glVertexAttribPointerNV MANGLE(VertexAttribPointerNV) +#define glVertexAttribs1dvNV MANGLE(VertexAttribs1dvNV) +#define glVertexAttribs1fvNV MANGLE(VertexAttribs1fvNV) +#define glVertexAttribs1hvNV MANGLE(VertexAttribs1hvNV) +#define glVertexAttribs1svNV MANGLE(VertexAttribs1svNV) +#define glVertexAttribs2dvNV MANGLE(VertexAttribs2dvNV) +#define glVertexAttribs2fvNV MANGLE(VertexAttribs2fvNV) +#define glVertexAttribs2hvNV MANGLE(VertexAttribs2hvNV) +#define glVertexAttribs2svNV MANGLE(VertexAttribs2svNV) +#define glVertexAttribs3dvNV MANGLE(VertexAttribs3dvNV) +#define glVertexAttribs3fvNV MANGLE(VertexAttribs3fvNV) +#define glVertexAttribs3hvNV MANGLE(VertexAttribs3hvNV) +#define glVertexAttribs3svNV MANGLE(VertexAttribs3svNV) +#define glVertexAttribs4dvNV MANGLE(VertexAttribs4dvNV) +#define glVertexAttribs4fvNV MANGLE(VertexAttribs4fvNV) +#define glVertexAttribs4hvNV MANGLE(VertexAttribs4hvNV) +#define glVertexAttribs4svNV MANGLE(VertexAttribs4svNV) +#define glVertexAttribs4ubvNV MANGLE(VertexAttribs4ubvNV) +#define glVertexBlendARB MANGLE(VertexBlendARB) +#define glVertexBlendEnvfATI MANGLE(VertexBlendEnvfATI) +#define glVertexBlendEnviATI MANGLE(VertexBlendEnviATI) +#define glVertexFormatNV MANGLE(VertexFormatNV) +#define glVertexP2ui MANGLE(VertexP2ui) +#define glVertexP2uiv MANGLE(VertexP2uiv) +#define glVertexP3ui MANGLE(VertexP3ui) +#define glVertexP3uiv MANGLE(VertexP3uiv) +#define glVertexP4ui MANGLE(VertexP4ui) +#define glVertexP4uiv MANGLE(VertexP4uiv) +#define glVertexPointerEXT MANGLE(VertexPointerEXT) +#define glVertexPointerListIBM MANGLE(VertexPointerListIBM) +#define glVertexPointer MANGLE(VertexPointer) +#define glVertexPointervINTEL MANGLE(VertexPointervINTEL) +#define glVertexStream1dATI MANGLE(VertexStream1dATI) +#define glVertexStream1dvATI MANGLE(VertexStream1dvATI) +#define glVertexStream1fATI MANGLE(VertexStream1fATI) +#define glVertexStream1fvATI MANGLE(VertexStream1fvATI) +#define glVertexStream1iATI MANGLE(VertexStream1iATI) +#define glVertexStream1ivATI MANGLE(VertexStream1ivATI) +#define glVertexStream1sATI MANGLE(VertexStream1sATI) +#define glVertexStream1svATI MANGLE(VertexStream1svATI) +#define glVertexStream2dATI MANGLE(VertexStream2dATI) +#define glVertexStream2dvATI MANGLE(VertexStream2dvATI) +#define glVertexStream2fATI MANGLE(VertexStream2fATI) +#define glVertexStream2fvATI MANGLE(VertexStream2fvATI) +#define glVertexStream2iATI MANGLE(VertexStream2iATI) +#define glVertexStream2ivATI MANGLE(VertexStream2ivATI) +#define glVertexStream2sATI MANGLE(VertexStream2sATI) +#define glVertexStream2svATI MANGLE(VertexStream2svATI) +#define glVertexStream3dATI MANGLE(VertexStream3dATI) +#define glVertexStream3dvATI MANGLE(VertexStream3dvATI) +#define glVertexStream3fATI MANGLE(VertexStream3fATI) +#define glVertexStream3fvATI MANGLE(VertexStream3fvATI) +#define glVertexStream3iATI MANGLE(VertexStream3iATI) +#define glVertexStream3ivATI MANGLE(VertexStream3ivATI) +#define glVertexStream3sATI MANGLE(VertexStream3sATI) +#define glVertexStream3svATI MANGLE(VertexStream3svATI) +#define glVertexStream4dATI MANGLE(VertexStream4dATI) +#define glVertexStream4dvATI MANGLE(VertexStream4dvATI) +#define glVertexStream4fATI MANGLE(VertexStream4fATI) +#define glVertexStream4fvATI MANGLE(VertexStream4fvATI) +#define glVertexStream4iATI MANGLE(VertexStream4iATI) +#define glVertexStream4ivATI MANGLE(VertexStream4ivATI) +#define glVertexStream4sATI MANGLE(VertexStream4sATI) +#define glVertexStream4svATI MANGLE(VertexStream4svATI) +#define glVertexWeightfEXT MANGLE(VertexWeightfEXT) +#define glVertexWeightfvEXT MANGLE(VertexWeightfvEXT) +#define glVertexWeighthNV MANGLE(VertexWeighthNV) +#define glVertexWeighthvNV MANGLE(VertexWeighthvNV) +#define glVertexWeightPointerEXT MANGLE(VertexWeightPointerEXT) +#define glVideoCaptureNV MANGLE(VideoCaptureNV) +#define glVideoCaptureStreamParameterdvNV MANGLE(VideoCaptureStreamParameterdvNV) +#define glVideoCaptureStreamParameterfvNV MANGLE(VideoCaptureStreamParameterfvNV) +#define glVideoCaptureStreamParameterivNV MANGLE(VideoCaptureStreamParameterivNV) +#define glViewportArrayv MANGLE(ViewportArrayv) +#define glViewportIndexedf MANGLE(ViewportIndexedf) +#define glViewportIndexedfv MANGLE(ViewportIndexedfv) +#define glViewport MANGLE(Viewport) +#define glWaitSync MANGLE(WaitSync) +#define glWeightbvARB MANGLE(WeightbvARB) +#define glWeightdvARB MANGLE(WeightdvARB) +#define glWeightfvARB MANGLE(WeightfvARB) +#define glWeightivARB MANGLE(WeightivARB) +#define glWeightPointerARB MANGLE(WeightPointerARB) +#define glWeightsvARB MANGLE(WeightsvARB) +#define glWeightubvARB MANGLE(WeightubvARB) +#define glWeightuivARB MANGLE(WeightuivARB) +#define glWeightusvARB MANGLE(WeightusvARB) +#define glWindowPos2dARB MANGLE(WindowPos2dARB) +#define glWindowPos2d MANGLE(WindowPos2d) +#define glWindowPos2dMESA MANGLE(WindowPos2dMESA) +#define glWindowPos2dvARB MANGLE(WindowPos2dvARB) +#define glWindowPos2dv MANGLE(WindowPos2dv) +#define glWindowPos2dvMESA MANGLE(WindowPos2dvMESA) +#define glWindowPos2fARB MANGLE(WindowPos2fARB) +#define glWindowPos2f MANGLE(WindowPos2f) +#define glWindowPos2fMESA MANGLE(WindowPos2fMESA) +#define glWindowPos2fvARB MANGLE(WindowPos2fvARB) +#define glWindowPos2fv MANGLE(WindowPos2fv) +#define glWindowPos2fvMESA MANGLE(WindowPos2fvMESA) +#define glWindowPos2iARB MANGLE(WindowPos2iARB) +#define glWindowPos2i MANGLE(WindowPos2i) +#define glWindowPos2iMESA MANGLE(WindowPos2iMESA) +#define glWindowPos2ivARB MANGLE(WindowPos2ivARB) +#define glWindowPos2iv MANGLE(WindowPos2iv) +#define glWindowPos2ivMESA MANGLE(WindowPos2ivMESA) +#define glWindowPos2sARB MANGLE(WindowPos2sARB) +#define glWindowPos2s MANGLE(WindowPos2s) +#define glWindowPos2sMESA MANGLE(WindowPos2sMESA) +#define glWindowPos2svARB MANGLE(WindowPos2svARB) +#define glWindowPos2sv MANGLE(WindowPos2sv) +#define glWindowPos2svMESA MANGLE(WindowPos2svMESA) +#define glWindowPos3dARB MANGLE(WindowPos3dARB) +#define glWindowPos3d MANGLE(WindowPos3d) +#define glWindowPos3dMESA MANGLE(WindowPos3dMESA) +#define glWindowPos3dvARB MANGLE(WindowPos3dvARB) +#define glWindowPos3dv MANGLE(WindowPos3dv) +#define glWindowPos3dvMESA MANGLE(WindowPos3dvMESA) +#define glWindowPos3fARB MANGLE(WindowPos3fARB) +#define glWindowPos3f MANGLE(WindowPos3f) +#define glWindowPos3fMESA MANGLE(WindowPos3fMESA) +#define glWindowPos3fvARB MANGLE(WindowPos3fvARB) +#define glWindowPos3fv MANGLE(WindowPos3fv) +#define glWindowPos3fvMESA MANGLE(WindowPos3fvMESA) +#define glWindowPos3iARB MANGLE(WindowPos3iARB) +#define glWindowPos3i MANGLE(WindowPos3i) +#define glWindowPos3iMESA MANGLE(WindowPos3iMESA) +#define glWindowPos3ivARB MANGLE(WindowPos3ivARB) +#define glWindowPos3iv MANGLE(WindowPos3iv) +#define glWindowPos3ivMESA MANGLE(WindowPos3ivMESA) +#define glWindowPos3sARB MANGLE(WindowPos3sARB) +#define glWindowPos3s MANGLE(WindowPos3s) +#define glWindowPos3sMESA MANGLE(WindowPos3sMESA) +#define glWindowPos3svARB MANGLE(WindowPos3svARB) +#define glWindowPos3sv MANGLE(WindowPos3sv) +#define glWindowPos3svMESA MANGLE(WindowPos3svMESA) +#define glWindowPos4dMESA MANGLE(WindowPos4dMESA) +#define glWindowPos4dvMESA MANGLE(WindowPos4dvMESA) +#define glWindowPos4fMESA MANGLE(WindowPos4fMESA) +#define glWindowPos4fvMESA MANGLE(WindowPos4fvMESA) +#define glWindowPos4iMESA MANGLE(WindowPos4iMESA) +#define glWindowPos4ivMESA MANGLE(WindowPos4ivMESA) +#define glWindowPos4sMESA MANGLE(WindowPos4sMESA) +#define glWindowPos4svMESA MANGLE(WindowPos4svMESA) +#define glWriteMaskEXT MANGLE(WriteMaskEXT) + +#endif /* GL_MANGLE_H */ diff --git a/include/GL/glext.h b/include/GL/glext.h new file mode 100644 index 0000000..9818cbc --- /dev/null +++ b/include/GL/glext.h @@ -0,0 +1,11039 @@ +#ifndef __glext_h_ +#define __glext_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2010 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are 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 Materials. +** +** THE MATERIALS ARE 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 +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Header file version number, required by OpenGL ABI for Linux */ +/* glext.h last updated $Date: 2010-11-03 18:59:30 -0700 (Wed, 03 Nov 2010) $ */ +/* Current version at http://www.opengl.org/registry/ */ +#define GL_GLEXT_VERSION 66 +/* Function declaration macros - to move into glplatform.h */ + +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif +#ifndef GLAPI +#define GLAPI extern +#endif + +/*************************************************************/ + +#ifndef GL_VERSION_1_2 +#define GL_UNSIGNED_BYTE_3_3_2 0x8032 +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_INT_8_8_8_8 0x8035 +#define GL_UNSIGNED_INT_10_10_10_2 0x8036 +#define GL_TEXTURE_BINDING_3D 0x806A +#define GL_PACK_SKIP_IMAGES 0x806B +#define GL_PACK_IMAGE_HEIGHT 0x806C +#define GL_UNPACK_SKIP_IMAGES 0x806D +#define GL_UNPACK_IMAGE_HEIGHT 0x806E +#define GL_TEXTURE_3D 0x806F +#define GL_PROXY_TEXTURE_3D 0x8070 +#define GL_TEXTURE_DEPTH 0x8071 +#define GL_TEXTURE_WRAP_R 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE 0x8073 +#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 +#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#define GL_BGR 0x80E0 +#define GL_BGRA 0x80E1 +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_TEXTURE_MIN_LOD 0x813A +#define GL_TEXTURE_MAX_LOD 0x813B +#define GL_TEXTURE_BASE_LEVEL 0x813C +#define GL_TEXTURE_MAX_LEVEL 0x813D +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#endif + +#ifndef GL_VERSION_1_2_DEPRECATED +#define GL_RESCALE_NORMAL 0x803A +#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 +#define GL_SINGLE_COLOR 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR 0x81FA +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#endif + +#ifndef GL_ARB_imaging +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_BLEND_COLOR 0x8005 +#define GL_FUNC_ADD 0x8006 +#define GL_MIN 0x8007 +#define GL_MAX 0x8008 +#define GL_BLEND_EQUATION 0x8009 +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B +#endif + +#ifndef GL_ARB_imaging_DEPRECATED +#define GL_CONVOLUTION_1D 0x8010 +#define GL_CONVOLUTION_2D 0x8011 +#define GL_SEPARABLE_2D 0x8012 +#define GL_CONVOLUTION_BORDER_MODE 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS 0x8015 +#define GL_REDUCE 0x8016 +#define GL_CONVOLUTION_FORMAT 0x8017 +#define GL_CONVOLUTION_WIDTH 0x8018 +#define GL_CONVOLUTION_HEIGHT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023 +#define GL_HISTOGRAM 0x8024 +#define GL_PROXY_HISTOGRAM 0x8025 +#define GL_HISTOGRAM_WIDTH 0x8026 +#define GL_HISTOGRAM_FORMAT 0x8027 +#define GL_HISTOGRAM_RED_SIZE 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C +#define GL_HISTOGRAM_SINK 0x802D +#define GL_MINMAX 0x802E +#define GL_MINMAX_FORMAT 0x802F +#define GL_MINMAX_SINK 0x8030 +#define GL_TABLE_TOO_LARGE 0x8031 +#define GL_COLOR_MATRIX 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB +#define GL_COLOR_TABLE 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2 +#define GL_PROXY_COLOR_TABLE 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5 +#define GL_COLOR_TABLE_SCALE 0x80D6 +#define GL_COLOR_TABLE_BIAS 0x80D7 +#define GL_COLOR_TABLE_FORMAT 0x80D8 +#define GL_COLOR_TABLE_WIDTH 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF +#define GL_CONSTANT_BORDER 0x8151 +#define GL_REPLICATE_BORDER 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR 0x8154 +#endif + +#ifndef GL_VERSION_1_3 +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_MULTISAMPLE 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE 0x809F +#define GL_SAMPLE_COVERAGE 0x80A0 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C +#define GL_COMPRESSED_RGB 0x84ED +#define GL_COMPRESSED_RGBA 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 +#define GL_TEXTURE_COMPRESSED 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 +#define GL_CLAMP_TO_BORDER 0x812D +#endif + +#ifndef GL_VERSION_1_3_DEPRECATED +#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 +#define GL_MAX_TEXTURE_UNITS 0x84E2 +#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6 +#define GL_MULTISAMPLE_BIT 0x20000000 +#define GL_NORMAL_MAP 0x8511 +#define GL_REFLECTION_MAP 0x8512 +#define GL_COMPRESSED_ALPHA 0x84E9 +#define GL_COMPRESSED_LUMINANCE 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB +#define GL_COMPRESSED_INTENSITY 0x84EC +#define GL_COMBINE 0x8570 +#define GL_COMBINE_RGB 0x8571 +#define GL_COMBINE_ALPHA 0x8572 +#define GL_SOURCE0_RGB 0x8580 +#define GL_SOURCE1_RGB 0x8581 +#define GL_SOURCE2_RGB 0x8582 +#define GL_SOURCE0_ALPHA 0x8588 +#define GL_SOURCE1_ALPHA 0x8589 +#define GL_SOURCE2_ALPHA 0x858A +#define GL_OPERAND0_RGB 0x8590 +#define GL_OPERAND1_RGB 0x8591 +#define GL_OPERAND2_RGB 0x8592 +#define GL_OPERAND0_ALPHA 0x8598 +#define GL_OPERAND1_ALPHA 0x8599 +#define GL_OPERAND2_ALPHA 0x859A +#define GL_RGB_SCALE 0x8573 +#define GL_ADD_SIGNED 0x8574 +#define GL_INTERPOLATE 0x8575 +#define GL_SUBTRACT 0x84E7 +#define GL_CONSTANT 0x8576 +#define GL_PRIMARY_COLOR 0x8577 +#define GL_PREVIOUS 0x8578 +#define GL_DOT3_RGB 0x86AE +#define GL_DOT3_RGBA 0x86AF +#endif + +#ifndef GL_VERSION_1_4 +#define GL_BLEND_DST_RGB 0x80C8 +#define GL_BLEND_SRC_RGB 0x80C9 +#define GL_BLEND_DST_ALPHA 0x80CA +#define GL_BLEND_SRC_ALPHA 0x80CB +#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 +#define GL_DEPTH_COMPONENT16 0x81A5 +#define GL_DEPTH_COMPONENT24 0x81A6 +#define GL_DEPTH_COMPONENT32 0x81A7 +#define GL_MIRRORED_REPEAT 0x8370 +#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD +#define GL_TEXTURE_LOD_BIAS 0x8501 +#define GL_INCR_WRAP 0x8507 +#define GL_DECR_WRAP 0x8508 +#define GL_TEXTURE_DEPTH_SIZE 0x884A +#define GL_TEXTURE_COMPARE_MODE 0x884C +#define GL_TEXTURE_COMPARE_FUNC 0x884D +#endif + +#ifndef GL_VERSION_1_4_DEPRECATED +#define GL_POINT_SIZE_MIN 0x8126 +#define GL_POINT_SIZE_MAX 0x8127 +#define GL_POINT_DISTANCE_ATTENUATION 0x8129 +#define GL_GENERATE_MIPMAP 0x8191 +#define GL_GENERATE_MIPMAP_HINT 0x8192 +#define GL_FOG_COORDINATE_SOURCE 0x8450 +#define GL_FOG_COORDINATE 0x8451 +#define GL_FRAGMENT_DEPTH 0x8452 +#define GL_CURRENT_FOG_COORDINATE 0x8453 +#define GL_FOG_COORDINATE_ARRAY_TYPE 0x8454 +#define GL_FOG_COORDINATE_ARRAY_STRIDE 0x8455 +#define GL_FOG_COORDINATE_ARRAY_POINTER 0x8456 +#define GL_FOG_COORDINATE_ARRAY 0x8457 +#define GL_COLOR_SUM 0x8458 +#define GL_CURRENT_SECONDARY_COLOR 0x8459 +#define GL_SECONDARY_COLOR_ARRAY_SIZE 0x845A +#define GL_SECONDARY_COLOR_ARRAY_TYPE 0x845B +#define GL_SECONDARY_COLOR_ARRAY_STRIDE 0x845C +#define GL_SECONDARY_COLOR_ARRAY_POINTER 0x845D +#define GL_SECONDARY_COLOR_ARRAY 0x845E +#define GL_TEXTURE_FILTER_CONTROL 0x8500 +#define GL_DEPTH_TEXTURE_MODE 0x884B +#define GL_COMPARE_R_TO_TEXTURE 0x884E +#endif + +#ifndef GL_VERSION_1_5 +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 +#define GL_QUERY_COUNTER_BITS 0x8864 +#define GL_CURRENT_QUERY 0x8865 +#define GL_QUERY_RESULT 0x8866 +#define GL_QUERY_RESULT_AVAILABLE 0x8867 +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F +#define GL_READ_ONLY 0x88B8 +#define GL_WRITE_ONLY 0x88B9 +#define GL_READ_WRITE 0x88BA +#define GL_BUFFER_ACCESS 0x88BB +#define GL_BUFFER_MAPPED 0x88BC +#define GL_BUFFER_MAP_POINTER 0x88BD +#define GL_STREAM_DRAW 0x88E0 +#define GL_STREAM_READ 0x88E1 +#define GL_STREAM_COPY 0x88E2 +#define GL_STATIC_DRAW 0x88E4 +#define GL_STATIC_READ 0x88E5 +#define GL_STATIC_COPY 0x88E6 +#define GL_DYNAMIC_DRAW 0x88E8 +#define GL_DYNAMIC_READ 0x88E9 +#define GL_DYNAMIC_COPY 0x88EA +#define GL_SAMPLES_PASSED 0x8914 +#endif + +#ifndef GL_VERSION_1_5_DEPRECATED +#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898 +#define GL_INDEX_ARRAY_BUFFER_BINDING 0x8899 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A +#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING 0x889B +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C +#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0x889D +#define GL_WEIGHT_ARRAY_BUFFER_BINDING 0x889E +#define GL_FOG_COORD_SRC 0x8450 +#define GL_FOG_COORD 0x8451 +#define GL_CURRENT_FOG_COORD 0x8453 +#define GL_FOG_COORD_ARRAY_TYPE 0x8454 +#define GL_FOG_COORD_ARRAY_STRIDE 0x8455 +#define GL_FOG_COORD_ARRAY_POINTER 0x8456 +#define GL_FOG_COORD_ARRAY 0x8457 +#define GL_FOG_COORD_ARRAY_BUFFER_BINDING 0x889D +#define GL_SRC0_RGB 0x8580 +#define GL_SRC1_RGB 0x8581 +#define GL_SRC2_RGB 0x8582 +#define GL_SRC0_ALPHA 0x8588 +#define GL_SRC1_ALPHA 0x8589 +#define GL_SRC2_ALPHA 0x858A +#endif + +#ifndef GL_VERSION_2_0 +#define GL_BLEND_EQUATION_RGB 0x8009 +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 +#define GL_CURRENT_VERTEX_ATTRIB 0x8626 +#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 +#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 +#define GL_STENCIL_BACK_FUNC 0x8800 +#define GL_STENCIL_BACK_FAIL 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 +#define GL_MAX_DRAW_BUFFERS 0x8824 +#define GL_DRAW_BUFFER0 0x8825 +#define GL_DRAW_BUFFER1 0x8826 +#define GL_DRAW_BUFFER2 0x8827 +#define GL_DRAW_BUFFER3 0x8828 +#define GL_DRAW_BUFFER4 0x8829 +#define GL_DRAW_BUFFER5 0x882A +#define GL_DRAW_BUFFER6 0x882B +#define GL_DRAW_BUFFER7 0x882C +#define GL_DRAW_BUFFER8 0x882D +#define GL_DRAW_BUFFER9 0x882E +#define GL_DRAW_BUFFER10 0x882F +#define GL_DRAW_BUFFER11 0x8830 +#define GL_DRAW_BUFFER12 0x8831 +#define GL_DRAW_BUFFER13 0x8832 +#define GL_DRAW_BUFFER14 0x8833 +#define GL_DRAW_BUFFER15 0x8834 +#define GL_BLEND_EQUATION_ALPHA 0x883D +#define GL_MAX_VERTEX_ATTRIBS 0x8869 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A +#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A +#define GL_MAX_VARYING_FLOATS 0x8B4B +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D +#define GL_SHADER_TYPE 0x8B4F +#define GL_FLOAT_VEC2 0x8B50 +#define GL_FLOAT_VEC3 0x8B51 +#define GL_FLOAT_VEC4 0x8B52 +#define GL_INT_VEC2 0x8B53 +#define GL_INT_VEC3 0x8B54 +#define GL_INT_VEC4 0x8B55 +#define GL_BOOL 0x8B56 +#define GL_BOOL_VEC2 0x8B57 +#define GL_BOOL_VEC3 0x8B58 +#define GL_BOOL_VEC4 0x8B59 +#define GL_FLOAT_MAT2 0x8B5A +#define GL_FLOAT_MAT3 0x8B5B +#define GL_FLOAT_MAT4 0x8B5C +#define GL_SAMPLER_1D 0x8B5D +#define GL_SAMPLER_2D 0x8B5E +#define GL_SAMPLER_3D 0x8B5F +#define GL_SAMPLER_CUBE 0x8B60 +#define GL_SAMPLER_1D_SHADOW 0x8B61 +#define GL_SAMPLER_2D_SHADOW 0x8B62 +#define GL_DELETE_STATUS 0x8B80 +#define GL_COMPILE_STATUS 0x8B81 +#define GL_LINK_STATUS 0x8B82 +#define GL_VALIDATE_STATUS 0x8B83 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_ATTACHED_SHADERS 0x8B85 +#define GL_ACTIVE_UNIFORMS 0x8B86 +#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 +#define GL_SHADER_SOURCE_LENGTH 0x8B88 +#define GL_ACTIVE_ATTRIBUTES 0x8B89 +#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B +#define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#define GL_CURRENT_PROGRAM 0x8B8D +#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0 +#define GL_LOWER_LEFT 0x8CA1 +#define GL_UPPER_LEFT 0x8CA2 +#define GL_STENCIL_BACK_REF 0x8CA3 +#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 +#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 +#endif + +#ifndef GL_VERSION_2_0_DEPRECATED +#define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643 +#define GL_POINT_SPRITE 0x8861 +#define GL_COORD_REPLACE 0x8862 +#define GL_MAX_TEXTURE_COORDS 0x8871 +#endif + +#ifndef GL_VERSION_2_1 +#define GL_PIXEL_PACK_BUFFER 0x88EB +#define GL_PIXEL_UNPACK_BUFFER 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF +#define GL_FLOAT_MAT2x3 0x8B65 +#define GL_FLOAT_MAT2x4 0x8B66 +#define GL_FLOAT_MAT3x2 0x8B67 +#define GL_FLOAT_MAT3x4 0x8B68 +#define GL_FLOAT_MAT4x2 0x8B69 +#define GL_FLOAT_MAT4x3 0x8B6A +#define GL_SRGB 0x8C40 +#define GL_SRGB8 0x8C41 +#define GL_SRGB_ALPHA 0x8C42 +#define GL_SRGB8_ALPHA8 0x8C43 +#define GL_COMPRESSED_SRGB 0x8C48 +#define GL_COMPRESSED_SRGB_ALPHA 0x8C49 +#endif + +#ifndef GL_VERSION_2_1_DEPRECATED +#define GL_CURRENT_RASTER_SECONDARY_COLOR 0x845F +#define GL_SLUMINANCE_ALPHA 0x8C44 +#define GL_SLUMINANCE8_ALPHA8 0x8C45 +#define GL_SLUMINANCE 0x8C46 +#define GL_SLUMINANCE8 0x8C47 +#define GL_COMPRESSED_SLUMINANCE 0x8C4A +#define GL_COMPRESSED_SLUMINANCE_ALPHA 0x8C4B +#endif + +#ifndef GL_VERSION_3_0 +#define GL_COMPARE_REF_TO_TEXTURE 0x884E +#define GL_CLIP_DISTANCE0 0x3000 +#define GL_CLIP_DISTANCE1 0x3001 +#define GL_CLIP_DISTANCE2 0x3002 +#define GL_CLIP_DISTANCE3 0x3003 +#define GL_CLIP_DISTANCE4 0x3004 +#define GL_CLIP_DISTANCE5 0x3005 +#define GL_CLIP_DISTANCE6 0x3006 +#define GL_CLIP_DISTANCE7 0x3007 +#define GL_MAX_CLIP_DISTANCES 0x0D32 +#define GL_MAJOR_VERSION 0x821B +#define GL_MINOR_VERSION 0x821C +#define GL_NUM_EXTENSIONS 0x821D +#define GL_CONTEXT_FLAGS 0x821E +#define GL_DEPTH_BUFFER 0x8223 +#define GL_STENCIL_BUFFER 0x8224 +#define GL_COMPRESSED_RED 0x8225 +#define GL_COMPRESSED_RG 0x8226 +#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x0001 +#define GL_RGBA32F 0x8814 +#define GL_RGB32F 0x8815 +#define GL_RGBA16F 0x881A +#define GL_RGB16F 0x881B +#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD +#define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF +#define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904 +#define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905 +#define GL_CLAMP_READ_COLOR 0x891C +#define GL_FIXED_ONLY 0x891D +#define GL_MAX_VARYING_COMPONENTS 0x8B4B +#define GL_TEXTURE_1D_ARRAY 0x8C18 +#define GL_PROXY_TEXTURE_1D_ARRAY 0x8C19 +#define GL_TEXTURE_2D_ARRAY 0x8C1A +#define GL_PROXY_TEXTURE_2D_ARRAY 0x8C1B +#define GL_TEXTURE_BINDING_1D_ARRAY 0x8C1C +#define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D +#define GL_R11F_G11F_B10F 0x8C3A +#define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B +#define GL_RGB9_E5 0x8C3D +#define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E +#define GL_TEXTURE_SHARED_SIZE 0x8C3F +#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH 0x8C76 +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE 0x8C7F +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS 0x8C80 +#define GL_TRANSFORM_FEEDBACK_VARYINGS 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_START 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE 0x8C85 +#define GL_PRIMITIVES_GENERATED 0x8C87 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN 0x8C88 +#define GL_RASTERIZER_DISCARD 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 0x8C8B +#define GL_INTERLEAVED_ATTRIBS 0x8C8C +#define GL_SEPARATE_ATTRIBS 0x8C8D +#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING 0x8C8F +#define GL_RGBA32UI 0x8D70 +#define GL_RGB32UI 0x8D71 +#define GL_RGBA16UI 0x8D76 +#define GL_RGB16UI 0x8D77 +#define GL_RGBA8UI 0x8D7C +#define GL_RGB8UI 0x8D7D +#define GL_RGBA32I 0x8D82 +#define GL_RGB32I 0x8D83 +#define GL_RGBA16I 0x8D88 +#define GL_RGB16I 0x8D89 +#define GL_RGBA8I 0x8D8E +#define GL_RGB8I 0x8D8F +#define GL_RED_INTEGER 0x8D94 +#define GL_GREEN_INTEGER 0x8D95 +#define GL_BLUE_INTEGER 0x8D96 +#define GL_RGB_INTEGER 0x8D98 +#define GL_RGBA_INTEGER 0x8D99 +#define GL_BGR_INTEGER 0x8D9A +#define GL_BGRA_INTEGER 0x8D9B +#define GL_SAMPLER_1D_ARRAY 0x8DC0 +#define GL_SAMPLER_2D_ARRAY 0x8DC1 +#define GL_SAMPLER_1D_ARRAY_SHADOW 0x8DC3 +#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4 +#define GL_SAMPLER_CUBE_SHADOW 0x8DC5 +#define GL_UNSIGNED_INT_VEC2 0x8DC6 +#define GL_UNSIGNED_INT_VEC3 0x8DC7 +#define GL_UNSIGNED_INT_VEC4 0x8DC8 +#define GL_INT_SAMPLER_1D 0x8DC9 +#define GL_INT_SAMPLER_2D 0x8DCA +#define GL_INT_SAMPLER_3D 0x8DCB +#define GL_INT_SAMPLER_CUBE 0x8DCC +#define GL_INT_SAMPLER_1D_ARRAY 0x8DCE +#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF +#define GL_UNSIGNED_INT_SAMPLER_1D 0x8DD1 +#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2 +#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3 +#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4 +#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY 0x8DD6 +#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7 +#define GL_QUERY_WAIT 0x8E13 +#define GL_QUERY_NO_WAIT 0x8E14 +#define GL_QUERY_BY_REGION_WAIT 0x8E15 +#define GL_QUERY_BY_REGION_NO_WAIT 0x8E16 +#define GL_BUFFER_ACCESS_FLAGS 0x911F +#define GL_BUFFER_MAP_LENGTH 0x9120 +#define GL_BUFFER_MAP_OFFSET 0x9121 +/* Reuse tokens from ARB_depth_buffer_float */ +/* reuse GL_DEPTH_COMPONENT32F */ +/* reuse GL_DEPTH32F_STENCIL8 */ +/* reuse GL_FLOAT_32_UNSIGNED_INT_24_8_REV */ +/* Reuse tokens from ARB_framebuffer_object */ +/* reuse GL_INVALID_FRAMEBUFFER_OPERATION */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE */ +/* reuse GL_FRAMEBUFFER_DEFAULT */ +/* reuse GL_FRAMEBUFFER_UNDEFINED */ +/* reuse GL_DEPTH_STENCIL_ATTACHMENT */ +/* reuse GL_INDEX */ +/* reuse GL_MAX_RENDERBUFFER_SIZE */ +/* reuse GL_DEPTH_STENCIL */ +/* reuse GL_UNSIGNED_INT_24_8 */ +/* reuse GL_DEPTH24_STENCIL8 */ +/* reuse GL_TEXTURE_STENCIL_SIZE */ +/* reuse GL_TEXTURE_RED_TYPE */ +/* reuse GL_TEXTURE_GREEN_TYPE */ +/* reuse GL_TEXTURE_BLUE_TYPE */ +/* reuse GL_TEXTURE_ALPHA_TYPE */ +/* reuse GL_TEXTURE_DEPTH_TYPE */ +/* reuse GL_UNSIGNED_NORMALIZED */ +/* reuse GL_FRAMEBUFFER_BINDING */ +/* reuse GL_DRAW_FRAMEBUFFER_BINDING */ +/* reuse GL_RENDERBUFFER_BINDING */ +/* reuse GL_READ_FRAMEBUFFER */ +/* reuse GL_DRAW_FRAMEBUFFER */ +/* reuse GL_READ_FRAMEBUFFER_BINDING */ +/* reuse GL_RENDERBUFFER_SAMPLES */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ +/* reuse GL_FRAMEBUFFER_COMPLETE */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER */ +/* reuse GL_FRAMEBUFFER_UNSUPPORTED */ +/* reuse GL_MAX_COLOR_ATTACHMENTS */ +/* reuse GL_COLOR_ATTACHMENT0 */ +/* reuse GL_COLOR_ATTACHMENT1 */ +/* reuse GL_COLOR_ATTACHMENT2 */ +/* reuse GL_COLOR_ATTACHMENT3 */ +/* reuse GL_COLOR_ATTACHMENT4 */ +/* reuse GL_COLOR_ATTACHMENT5 */ +/* reuse GL_COLOR_ATTACHMENT6 */ +/* reuse GL_COLOR_ATTACHMENT7 */ +/* reuse GL_COLOR_ATTACHMENT8 */ +/* reuse GL_COLOR_ATTACHMENT9 */ +/* reuse GL_COLOR_ATTACHMENT10 */ +/* reuse GL_COLOR_ATTACHMENT11 */ +/* reuse GL_COLOR_ATTACHMENT12 */ +/* reuse GL_COLOR_ATTACHMENT13 */ +/* reuse GL_COLOR_ATTACHMENT14 */ +/* reuse GL_COLOR_ATTACHMENT15 */ +/* reuse GL_DEPTH_ATTACHMENT */ +/* reuse GL_STENCIL_ATTACHMENT */ +/* reuse GL_FRAMEBUFFER */ +/* reuse GL_RENDERBUFFER */ +/* reuse GL_RENDERBUFFER_WIDTH */ +/* reuse GL_RENDERBUFFER_HEIGHT */ +/* reuse GL_RENDERBUFFER_INTERNAL_FORMAT */ +/* reuse GL_STENCIL_INDEX1 */ +/* reuse GL_STENCIL_INDEX4 */ +/* reuse GL_STENCIL_INDEX8 */ +/* reuse GL_STENCIL_INDEX16 */ +/* reuse GL_RENDERBUFFER_RED_SIZE */ +/* reuse GL_RENDERBUFFER_GREEN_SIZE */ +/* reuse GL_RENDERBUFFER_BLUE_SIZE */ +/* reuse GL_RENDERBUFFER_ALPHA_SIZE */ +/* reuse GL_RENDERBUFFER_DEPTH_SIZE */ +/* reuse GL_RENDERBUFFER_STENCIL_SIZE */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE */ +/* reuse GL_MAX_SAMPLES */ +/* Reuse tokens from ARB_framebuffer_sRGB */ +/* reuse GL_FRAMEBUFFER_SRGB */ +/* Reuse tokens from ARB_half_float_vertex */ +/* reuse GL_HALF_FLOAT */ +/* Reuse tokens from ARB_map_buffer_range */ +/* reuse GL_MAP_READ_BIT */ +/* reuse GL_MAP_WRITE_BIT */ +/* reuse GL_MAP_INVALIDATE_RANGE_BIT */ +/* reuse GL_MAP_INVALIDATE_BUFFER_BIT */ +/* reuse GL_MAP_FLUSH_EXPLICIT_BIT */ +/* reuse GL_MAP_UNSYNCHRONIZED_BIT */ +/* Reuse tokens from ARB_texture_compression_rgtc */ +/* reuse GL_COMPRESSED_RED_RGTC1 */ +/* reuse GL_COMPRESSED_SIGNED_RED_RGTC1 */ +/* reuse GL_COMPRESSED_RG_RGTC2 */ +/* reuse GL_COMPRESSED_SIGNED_RG_RGTC2 */ +/* Reuse tokens from ARB_texture_rg */ +/* reuse GL_RG */ +/* reuse GL_RG_INTEGER */ +/* reuse GL_R8 */ +/* reuse GL_R16 */ +/* reuse GL_RG8 */ +/* reuse GL_RG16 */ +/* reuse GL_R16F */ +/* reuse GL_R32F */ +/* reuse GL_RG16F */ +/* reuse GL_RG32F */ +/* reuse GL_R8I */ +/* reuse GL_R8UI */ +/* reuse GL_R16I */ +/* reuse GL_R16UI */ +/* reuse GL_R32I */ +/* reuse GL_R32UI */ +/* reuse GL_RG8I */ +/* reuse GL_RG8UI */ +/* reuse GL_RG16I */ +/* reuse GL_RG16UI */ +/* reuse GL_RG32I */ +/* reuse GL_RG32UI */ +/* Reuse tokens from ARB_vertex_array_object */ +/* reuse GL_VERTEX_ARRAY_BINDING */ +#endif + +#ifndef GL_VERSION_3_0_DEPRECATED +#define GL_CLAMP_VERTEX_COLOR 0x891A +#define GL_CLAMP_FRAGMENT_COLOR 0x891B +#define GL_ALPHA_INTEGER 0x8D97 +/* Reuse tokens from ARB_framebuffer_object */ +/* reuse GL_TEXTURE_LUMINANCE_TYPE */ +/* reuse GL_TEXTURE_INTENSITY_TYPE */ +#endif + +#ifndef GL_VERSION_3_1 +#define GL_SAMPLER_2D_RECT 0x8B63 +#define GL_SAMPLER_2D_RECT_SHADOW 0x8B64 +#define GL_SAMPLER_BUFFER 0x8DC2 +#define GL_INT_SAMPLER_2D_RECT 0x8DCD +#define GL_INT_SAMPLER_BUFFER 0x8DD0 +#define GL_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5 +#define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8 +#define GL_TEXTURE_BUFFER 0x8C2A +#define GL_MAX_TEXTURE_BUFFER_SIZE 0x8C2B +#define GL_TEXTURE_BINDING_BUFFER 0x8C2C +#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING 0x8C2D +#define GL_TEXTURE_BUFFER_FORMAT 0x8C2E +#define GL_TEXTURE_RECTANGLE 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE 0x84F8 +#define GL_RED_SNORM 0x8F90 +#define GL_RG_SNORM 0x8F91 +#define GL_RGB_SNORM 0x8F92 +#define GL_RGBA_SNORM 0x8F93 +#define GL_R8_SNORM 0x8F94 +#define GL_RG8_SNORM 0x8F95 +#define GL_RGB8_SNORM 0x8F96 +#define GL_RGBA8_SNORM 0x8F97 +#define GL_R16_SNORM 0x8F98 +#define GL_RG16_SNORM 0x8F99 +#define GL_RGB16_SNORM 0x8F9A +#define GL_RGBA16_SNORM 0x8F9B +#define GL_SIGNED_NORMALIZED 0x8F9C +#define GL_PRIMITIVE_RESTART 0x8F9D +#define GL_PRIMITIVE_RESTART_INDEX 0x8F9E +/* Reuse tokens from ARB_copy_buffer */ +/* reuse GL_COPY_READ_BUFFER */ +/* reuse GL_COPY_WRITE_BUFFER */ +/* Reuse tokens from ARB_draw_instanced (none) */ +/* Reuse tokens from ARB_uniform_buffer_object */ +/* reuse GL_UNIFORM_BUFFER */ +/* reuse GL_UNIFORM_BUFFER_BINDING */ +/* reuse GL_UNIFORM_BUFFER_START */ +/* reuse GL_UNIFORM_BUFFER_SIZE */ +/* reuse GL_MAX_VERTEX_UNIFORM_BLOCKS */ +/* reuse GL_MAX_FRAGMENT_UNIFORM_BLOCKS */ +/* reuse GL_MAX_COMBINED_UNIFORM_BLOCKS */ +/* reuse GL_MAX_UNIFORM_BUFFER_BINDINGS */ +/* reuse GL_MAX_UNIFORM_BLOCK_SIZE */ +/* reuse GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS */ +/* reuse GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT */ +/* reuse GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH */ +/* reuse GL_ACTIVE_UNIFORM_BLOCKS */ +/* reuse GL_UNIFORM_TYPE */ +/* reuse GL_UNIFORM_SIZE */ +/* reuse GL_UNIFORM_NAME_LENGTH */ +/* reuse GL_UNIFORM_BLOCK_INDEX */ +/* reuse GL_UNIFORM_OFFSET */ +/* reuse GL_UNIFORM_ARRAY_STRIDE */ +/* reuse GL_UNIFORM_MATRIX_STRIDE */ +/* reuse GL_UNIFORM_IS_ROW_MAJOR */ +/* reuse GL_UNIFORM_BLOCK_BINDING */ +/* reuse GL_UNIFORM_BLOCK_DATA_SIZE */ +/* reuse GL_UNIFORM_BLOCK_NAME_LENGTH */ +/* reuse GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS */ +/* reuse GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER */ +/* reuse GL_INVALID_INDEX */ +#endif + +#ifndef GL_VERSION_3_2 +#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001 +#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 +#define GL_LINES_ADJACENCY 0x000A +#define GL_LINE_STRIP_ADJACENCY 0x000B +#define GL_TRIANGLES_ADJACENCY 0x000C +#define GL_TRIANGLE_STRIP_ADJACENCY 0x000D +#define GL_PROGRAM_POINT_SIZE 0x8642 +#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS 0x8C29 +#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED 0x8DA7 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS 0x8DA8 +#define GL_GEOMETRY_SHADER 0x8DD9 +#define GL_GEOMETRY_VERTICES_OUT 0x8916 +#define GL_GEOMETRY_INPUT_TYPE 0x8917 +#define GL_GEOMETRY_OUTPUT_TYPE 0x8918 +#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS 0x8DDF +#define GL_MAX_GEOMETRY_OUTPUT_VERTICES 0x8DE0 +#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS 0x8DE1 +#define GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122 +#define GL_MAX_GEOMETRY_INPUT_COMPONENTS 0x9123 +#define GL_MAX_GEOMETRY_OUTPUT_COMPONENTS 0x9124 +#define GL_MAX_FRAGMENT_INPUT_COMPONENTS 0x9125 +#define GL_CONTEXT_PROFILE_MASK 0x9126 +/* reuse GL_MAX_VARYING_COMPONENTS */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ +/* Reuse tokens from ARB_depth_clamp */ +/* reuse GL_DEPTH_CLAMP */ +/* Reuse tokens from ARB_draw_elements_base_vertex (none) */ +/* Reuse tokens from ARB_fragment_coord_conventions (none) */ +/* Reuse tokens from ARB_provoking_vertex */ +/* reuse GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION */ +/* reuse GL_FIRST_VERTEX_CONVENTION */ +/* reuse GL_LAST_VERTEX_CONVENTION */ +/* reuse GL_PROVOKING_VERTEX */ +/* Reuse tokens from ARB_seamless_cube_map */ +/* reuse GL_TEXTURE_CUBE_MAP_SEAMLESS */ +/* Reuse tokens from ARB_sync */ +/* reuse GL_MAX_SERVER_WAIT_TIMEOUT */ +/* reuse GL_OBJECT_TYPE */ +/* reuse GL_SYNC_CONDITION */ +/* reuse GL_SYNC_STATUS */ +/* reuse GL_SYNC_FLAGS */ +/* reuse GL_SYNC_FENCE */ +/* reuse GL_SYNC_GPU_COMMANDS_COMPLETE */ +/* reuse GL_UNSIGNALED */ +/* reuse GL_SIGNALED */ +/* reuse GL_ALREADY_SIGNALED */ +/* reuse GL_TIMEOUT_EXPIRED */ +/* reuse GL_CONDITION_SATISFIED */ +/* reuse GL_WAIT_FAILED */ +/* reuse GL_TIMEOUT_IGNORED */ +/* reuse GL_SYNC_FLUSH_COMMANDS_BIT */ +/* reuse GL_TIMEOUT_IGNORED */ +/* Reuse tokens from ARB_texture_multisample */ +/* reuse GL_SAMPLE_POSITION */ +/* reuse GL_SAMPLE_MASK */ +/* reuse GL_SAMPLE_MASK_VALUE */ +/* reuse GL_MAX_SAMPLE_MASK_WORDS */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE */ +/* reuse GL_PROXY_TEXTURE_2D_MULTISAMPLE */ +/* reuse GL_TEXTURE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_TEXTURE_BINDING_2D_MULTISAMPLE */ +/* reuse GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_TEXTURE_SAMPLES */ +/* reuse GL_TEXTURE_FIXED_SAMPLE_LOCATIONS */ +/* reuse GL_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_INT_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE */ +/* reuse GL_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY */ +/* reuse GL_MAX_COLOR_TEXTURE_SAMPLES */ +/* reuse GL_MAX_DEPTH_TEXTURE_SAMPLES */ +/* reuse GL_MAX_INTEGER_SAMPLES */ +/* Don't need to reuse tokens from ARB_vertex_array_bgra since they're already in 1.2 core */ +#endif + +#ifndef GL_VERSION_3_3 +#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE +/* Reuse tokens from ARB_blend_func_extended */ +/* reuse GL_SRC1_COLOR */ +/* reuse GL_ONE_MINUS_SRC1_COLOR */ +/* reuse GL_ONE_MINUS_SRC1_ALPHA */ +/* reuse GL_MAX_DUAL_SOURCE_DRAW_BUFFERS */ +/* Reuse tokens from ARB_explicit_attrib_location (none) */ +/* Reuse tokens from ARB_occlusion_query2 */ +/* reuse GL_ANY_SAMPLES_PASSED */ +/* Reuse tokens from ARB_sampler_objects */ +/* reuse GL_SAMPLER_BINDING */ +/* Reuse tokens from ARB_shader_bit_encoding (none) */ +/* Reuse tokens from ARB_texture_rgb10_a2ui */ +/* reuse GL_RGB10_A2UI */ +/* Reuse tokens from ARB_texture_swizzle */ +/* reuse GL_TEXTURE_SWIZZLE_R */ +/* reuse GL_TEXTURE_SWIZZLE_G */ +/* reuse GL_TEXTURE_SWIZZLE_B */ +/* reuse GL_TEXTURE_SWIZZLE_A */ +/* reuse GL_TEXTURE_SWIZZLE_RGBA */ +/* Reuse tokens from ARB_timer_query */ +/* reuse GL_TIME_ELAPSED */ +/* reuse GL_TIMESTAMP */ +/* Reuse tokens from ARB_vertex_type_2_10_10_10_rev */ +/* reuse GL_INT_2_10_10_10_REV */ +#endif + +#ifndef GL_VERSION_4_0 +#define GL_SAMPLE_SHADING 0x8C36 +#define GL_MIN_SAMPLE_SHADING_VALUE 0x8C37 +#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5E +#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5F +#define GL_TEXTURE_CUBE_MAP_ARRAY 0x9009 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY 0x900A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY 0x900B +#define GL_SAMPLER_CUBE_MAP_ARRAY 0x900C +#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW 0x900D +#define GL_INT_SAMPLER_CUBE_MAP_ARRAY 0x900E +#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY 0x900F +/* Reuse tokens from ARB_texture_query_lod (none) */ +/* Reuse tokens from ARB_draw_buffers_blend (none) */ +/* Reuse tokens from ARB_draw_indirect */ +/* reuse GL_DRAW_INDIRECT_BUFFER */ +/* reuse GL_DRAW_INDIRECT_BUFFER_BINDING */ +/* Reuse tokens from ARB_gpu_shader5 */ +/* reuse GL_GEOMETRY_SHADER_INVOCATIONS */ +/* reuse GL_MAX_GEOMETRY_SHADER_INVOCATIONS */ +/* reuse GL_MIN_FRAGMENT_INTERPOLATION_OFFSET */ +/* reuse GL_MAX_FRAGMENT_INTERPOLATION_OFFSET */ +/* reuse GL_FRAGMENT_INTERPOLATION_OFFSET_BITS */ +/* reuse GL_MAX_VERTEX_STREAMS */ +/* Reuse tokens from ARB_gpu_shader_fp64 */ +/* reuse GL_DOUBLE_VEC2 */ +/* reuse GL_DOUBLE_VEC3 */ +/* reuse GL_DOUBLE_VEC4 */ +/* reuse GL_DOUBLE_MAT2 */ +/* reuse GL_DOUBLE_MAT3 */ +/* reuse GL_DOUBLE_MAT4 */ +/* reuse GL_DOUBLE_MAT2x3 */ +/* reuse GL_DOUBLE_MAT2x4 */ +/* reuse GL_DOUBLE_MAT3x2 */ +/* reuse GL_DOUBLE_MAT3x4 */ +/* reuse GL_DOUBLE_MAT4x2 */ +/* reuse GL_DOUBLE_MAT4x3 */ +/* Reuse tokens from ARB_shader_subroutine */ +/* reuse GL_ACTIVE_SUBROUTINES */ +/* reuse GL_ACTIVE_SUBROUTINE_UNIFORMS */ +/* reuse GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS */ +/* reuse GL_ACTIVE_SUBROUTINE_MAX_LENGTH */ +/* reuse GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH */ +/* reuse GL_MAX_SUBROUTINES */ +/* reuse GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS */ +/* reuse GL_NUM_COMPATIBLE_SUBROUTINES */ +/* reuse GL_COMPATIBLE_SUBROUTINES */ +/* Reuse tokens from ARB_tessellation_shader */ +/* reuse GL_PATCHES */ +/* reuse GL_PATCH_VERTICES */ +/* reuse GL_PATCH_DEFAULT_INNER_LEVEL */ +/* reuse GL_PATCH_DEFAULT_OUTER_LEVEL */ +/* reuse GL_TESS_CONTROL_OUTPUT_VERTICES */ +/* reuse GL_TESS_GEN_MODE */ +/* reuse GL_TESS_GEN_SPACING */ +/* reuse GL_TESS_GEN_VERTEX_ORDER */ +/* reuse GL_TESS_GEN_POINT_MODE */ +/* reuse GL_ISOLINES */ +/* reuse GL_FRACTIONAL_ODD */ +/* reuse GL_FRACTIONAL_EVEN */ +/* reuse GL_MAX_PATCH_VERTICES */ +/* reuse GL_MAX_TESS_GEN_LEVEL */ +/* reuse GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS */ +/* reuse GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS */ +/* reuse GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_PATCH_COMPONENTS */ +/* reuse GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS */ +/* reuse GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS */ +/* reuse GL_MAX_TESS_CONTROL_INPUT_COMPONENTS */ +/* reuse GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS */ +/* reuse GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS */ +/* reuse GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER */ +/* reuse GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER */ +/* reuse GL_TESS_EVALUATION_SHADER */ +/* reuse GL_TESS_CONTROL_SHADER */ +/* Reuse tokens from ARB_texture_buffer_object_rgb32 (none) */ +/* Reuse tokens from ARB_transform_feedback2 */ +/* reuse GL_TRANSFORM_FEEDBACK */ +/* reuse GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED */ +/* reuse GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE */ +/* reuse GL_TRANSFORM_FEEDBACK_BINDING */ +/* Reuse tokens from ARB_transform_feedback3 */ +/* reuse GL_MAX_TRANSFORM_FEEDBACK_BUFFERS */ +/* reuse GL_MAX_VERTEX_STREAMS */ +#endif + +#ifndef GL_VERSION_4_1 +/* Reuse tokens from ARB_ES2_compatibility */ +/* reuse GL_FIXED */ +/* reuse GL_IMPLEMENTATION_COLOR_READ_TYPE */ +/* reuse GL_IMPLEMENTATION_COLOR_READ_FORMAT */ +/* reuse GL_LOW_FLOAT */ +/* reuse GL_MEDIUM_FLOAT */ +/* reuse GL_HIGH_FLOAT */ +/* reuse GL_LOW_INT */ +/* reuse GL_MEDIUM_INT */ +/* reuse GL_HIGH_INT */ +/* reuse GL_SHADER_COMPILER */ +/* reuse GL_NUM_SHADER_BINARY_FORMATS */ +/* reuse GL_MAX_VERTEX_UNIFORM_VECTORS */ +/* reuse GL_MAX_VARYING_VECTORS */ +/* reuse GL_MAX_FRAGMENT_UNIFORM_VECTORS */ +/* Reuse tokens from ARB_get_program_binary */ +/* reuse GL_PROGRAM_BINARY_RETRIEVABLE_HINT */ +/* reuse GL_PROGRAM_BINARY_LENGTH */ +/* reuse GL_NUM_PROGRAM_BINARY_FORMATS */ +/* reuse GL_PROGRAM_BINARY_FORMATS */ +/* Reuse tokens from ARB_separate_shader_objects */ +/* reuse GL_VERTEX_SHADER_BIT */ +/* reuse GL_FRAGMENT_SHADER_BIT */ +/* reuse GL_GEOMETRY_SHADER_BIT */ +/* reuse GL_TESS_CONTROL_SHADER_BIT */ +/* reuse GL_TESS_EVALUATION_SHADER_BIT */ +/* reuse GL_ALL_SHADER_BITS */ +/* reuse GL_PROGRAM_SEPARABLE */ +/* reuse GL_ACTIVE_PROGRAM */ +/* reuse GL_PROGRAM_PIPELINE_BINDING */ +/* Reuse tokens from ARB_shader_precision (none) */ +/* Reuse tokens from ARB_vertex_attrib_64bit - all are in GL 3.0 and 4.0 already */ +/* Reuse tokens from ARB_viewport_array - some are in GL 1.1 and ARB_provoking_vertex already */ +/* reuse GL_MAX_VIEWPORTS */ +/* reuse GL_VIEWPORT_SUBPIXEL_BITS */ +/* reuse GL_VIEWPORT_BOUNDS_RANGE */ +/* reuse GL_LAYER_PROVOKING_VERTEX */ +/* reuse GL_VIEWPORT_INDEX_PROVOKING_VERTEX */ +/* reuse GL_UNDEFINED_VERTEX */ +#endif + +#ifndef GL_ARB_multitexture +#define GL_TEXTURE0_ARB 0x84C0 +#define GL_TEXTURE1_ARB 0x84C1 +#define GL_TEXTURE2_ARB 0x84C2 +#define GL_TEXTURE3_ARB 0x84C3 +#define GL_TEXTURE4_ARB 0x84C4 +#define GL_TEXTURE5_ARB 0x84C5 +#define GL_TEXTURE6_ARB 0x84C6 +#define GL_TEXTURE7_ARB 0x84C7 +#define GL_TEXTURE8_ARB 0x84C8 +#define GL_TEXTURE9_ARB 0x84C9 +#define GL_TEXTURE10_ARB 0x84CA +#define GL_TEXTURE11_ARB 0x84CB +#define GL_TEXTURE12_ARB 0x84CC +#define GL_TEXTURE13_ARB 0x84CD +#define GL_TEXTURE14_ARB 0x84CE +#define GL_TEXTURE15_ARB 0x84CF +#define GL_TEXTURE16_ARB 0x84D0 +#define GL_TEXTURE17_ARB 0x84D1 +#define GL_TEXTURE18_ARB 0x84D2 +#define GL_TEXTURE19_ARB 0x84D3 +#define GL_TEXTURE20_ARB 0x84D4 +#define GL_TEXTURE21_ARB 0x84D5 +#define GL_TEXTURE22_ARB 0x84D6 +#define GL_TEXTURE23_ARB 0x84D7 +#define GL_TEXTURE24_ARB 0x84D8 +#define GL_TEXTURE25_ARB 0x84D9 +#define GL_TEXTURE26_ARB 0x84DA +#define GL_TEXTURE27_ARB 0x84DB +#define GL_TEXTURE28_ARB 0x84DC +#define GL_TEXTURE29_ARB 0x84DD +#define GL_TEXTURE30_ARB 0x84DE +#define GL_TEXTURE31_ARB 0x84DF +#define GL_ACTIVE_TEXTURE_ARB 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1 +#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2 +#endif + +#ifndef GL_ARB_transpose_matrix +#define GL_TRANSPOSE_MODELVIEW_MATRIX_ARB 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX_ARB 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX_ARB 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX_ARB 0x84E6 +#endif + +#ifndef GL_ARB_multisample +#define GL_MULTISAMPLE_ARB 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F +#define GL_SAMPLE_COVERAGE_ARB 0x80A0 +#define GL_SAMPLE_BUFFERS_ARB 0x80A8 +#define GL_SAMPLES_ARB 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB +#define GL_MULTISAMPLE_BIT_ARB 0x20000000 +#endif + +#ifndef GL_ARB_texture_env_add +#endif + +#ifndef GL_ARB_texture_cube_map +#define GL_NORMAL_MAP_ARB 0x8511 +#define GL_REFLECTION_MAP_ARB 0x8512 +#define GL_TEXTURE_CUBE_MAP_ARB 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851C +#endif + +#ifndef GL_ARB_texture_compression +#define GL_COMPRESSED_ALPHA_ARB 0x84E9 +#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB +#define GL_COMPRESSED_INTENSITY_ARB 0x84EC +#define GL_COMPRESSED_RGB_ARB 0x84ED +#define GL_COMPRESSED_RGBA_ARB 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86A0 +#define GL_TEXTURE_COMPRESSED_ARB 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3 +#endif + +#ifndef GL_ARB_texture_border_clamp +#define GL_CLAMP_TO_BORDER_ARB 0x812D +#endif + +#ifndef GL_ARB_point_parameters +#define GL_POINT_SIZE_MIN_ARB 0x8126 +#define GL_POINT_SIZE_MAX_ARB 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_ARB 0x8128 +#define GL_POINT_DISTANCE_ATTENUATION_ARB 0x8129 +#endif + +#ifndef GL_ARB_vertex_blend +#define GL_MAX_VERTEX_UNITS_ARB 0x86A4 +#define GL_ACTIVE_VERTEX_UNITS_ARB 0x86A5 +#define GL_WEIGHT_SUM_UNITY_ARB 0x86A6 +#define GL_VERTEX_BLEND_ARB 0x86A7 +#define GL_CURRENT_WEIGHT_ARB 0x86A8 +#define GL_WEIGHT_ARRAY_TYPE_ARB 0x86A9 +#define GL_WEIGHT_ARRAY_STRIDE_ARB 0x86AA +#define GL_WEIGHT_ARRAY_SIZE_ARB 0x86AB +#define GL_WEIGHT_ARRAY_POINTER_ARB 0x86AC +#define GL_WEIGHT_ARRAY_ARB 0x86AD +#define GL_MODELVIEW0_ARB 0x1700 +#define GL_MODELVIEW1_ARB 0x850A +#define GL_MODELVIEW2_ARB 0x8722 +#define GL_MODELVIEW3_ARB 0x8723 +#define GL_MODELVIEW4_ARB 0x8724 +#define GL_MODELVIEW5_ARB 0x8725 +#define GL_MODELVIEW6_ARB 0x8726 +#define GL_MODELVIEW7_ARB 0x8727 +#define GL_MODELVIEW8_ARB 0x8728 +#define GL_MODELVIEW9_ARB 0x8729 +#define GL_MODELVIEW10_ARB 0x872A +#define GL_MODELVIEW11_ARB 0x872B +#define GL_MODELVIEW12_ARB 0x872C +#define GL_MODELVIEW13_ARB 0x872D +#define GL_MODELVIEW14_ARB 0x872E +#define GL_MODELVIEW15_ARB 0x872F +#define GL_MODELVIEW16_ARB 0x8730 +#define GL_MODELVIEW17_ARB 0x8731 +#define GL_MODELVIEW18_ARB 0x8732 +#define GL_MODELVIEW19_ARB 0x8733 +#define GL_MODELVIEW20_ARB 0x8734 +#define GL_MODELVIEW21_ARB 0x8735 +#define GL_MODELVIEW22_ARB 0x8736 +#define GL_MODELVIEW23_ARB 0x8737 +#define GL_MODELVIEW24_ARB 0x8738 +#define GL_MODELVIEW25_ARB 0x8739 +#define GL_MODELVIEW26_ARB 0x873A +#define GL_MODELVIEW27_ARB 0x873B +#define GL_MODELVIEW28_ARB 0x873C +#define GL_MODELVIEW29_ARB 0x873D +#define GL_MODELVIEW30_ARB 0x873E +#define GL_MODELVIEW31_ARB 0x873F +#endif + +#ifndef GL_ARB_matrix_palette +#define GL_MATRIX_PALETTE_ARB 0x8840 +#define GL_MAX_MATRIX_PALETTE_STACK_DEPTH_ARB 0x8841 +#define GL_MAX_PALETTE_MATRICES_ARB 0x8842 +#define GL_CURRENT_PALETTE_MATRIX_ARB 0x8843 +#define GL_MATRIX_INDEX_ARRAY_ARB 0x8844 +#define GL_CURRENT_MATRIX_INDEX_ARB 0x8845 +#define GL_MATRIX_INDEX_ARRAY_SIZE_ARB 0x8846 +#define GL_MATRIX_INDEX_ARRAY_TYPE_ARB 0x8847 +#define GL_MATRIX_INDEX_ARRAY_STRIDE_ARB 0x8848 +#define GL_MATRIX_INDEX_ARRAY_POINTER_ARB 0x8849 +#endif + +#ifndef GL_ARB_texture_env_combine +#define GL_COMBINE_ARB 0x8570 +#define GL_COMBINE_RGB_ARB 0x8571 +#define GL_COMBINE_ALPHA_ARB 0x8572 +#define GL_SOURCE0_RGB_ARB 0x8580 +#define GL_SOURCE1_RGB_ARB 0x8581 +#define GL_SOURCE2_RGB_ARB 0x8582 +#define GL_SOURCE0_ALPHA_ARB 0x8588 +#define GL_SOURCE1_ALPHA_ARB 0x8589 +#define GL_SOURCE2_ALPHA_ARB 0x858A +#define GL_OPERAND0_RGB_ARB 0x8590 +#define GL_OPERAND1_RGB_ARB 0x8591 +#define GL_OPERAND2_RGB_ARB 0x8592 +#define GL_OPERAND0_ALPHA_ARB 0x8598 +#define GL_OPERAND1_ALPHA_ARB 0x8599 +#define GL_OPERAND2_ALPHA_ARB 0x859A +#define GL_RGB_SCALE_ARB 0x8573 +#define GL_ADD_SIGNED_ARB 0x8574 +#define GL_INTERPOLATE_ARB 0x8575 +#define GL_SUBTRACT_ARB 0x84E7 +#define GL_CONSTANT_ARB 0x8576 +#define GL_PRIMARY_COLOR_ARB 0x8577 +#define GL_PREVIOUS_ARB 0x8578 +#endif + +#ifndef GL_ARB_texture_env_crossbar +#endif + +#ifndef GL_ARB_texture_env_dot3 +#define GL_DOT3_RGB_ARB 0x86AE +#define GL_DOT3_RGBA_ARB 0x86AF +#endif + +#ifndef GL_ARB_texture_mirrored_repeat +#define GL_MIRRORED_REPEAT_ARB 0x8370 +#endif + +#ifndef GL_ARB_depth_texture +#define GL_DEPTH_COMPONENT16_ARB 0x81A5 +#define GL_DEPTH_COMPONENT24_ARB 0x81A6 +#define GL_DEPTH_COMPONENT32_ARB 0x81A7 +#define GL_TEXTURE_DEPTH_SIZE_ARB 0x884A +#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B +#endif + +#ifndef GL_ARB_shadow +#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C +#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D +#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E +#endif + +#ifndef GL_ARB_shadow_ambient +#define GL_TEXTURE_COMPARE_FAIL_VALUE_ARB 0x80BF +#endif + +#ifndef GL_ARB_window_pos +#endif + +#ifndef GL_ARB_vertex_program +#define GL_COLOR_SUM_ARB 0x8458 +#define GL_VERTEX_PROGRAM_ARB 0x8620 +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB 0x8625 +#define GL_CURRENT_VERTEX_ATTRIB_ARB 0x8626 +#define GL_PROGRAM_LENGTH_ARB 0x8627 +#define GL_PROGRAM_STRING_ARB 0x8628 +#define GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E +#define GL_MAX_PROGRAM_MATRICES_ARB 0x862F +#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640 +#define GL_CURRENT_MATRIX_ARB 0x8641 +#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642 +#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643 +#define GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB 0x8645 +#define GL_PROGRAM_ERROR_POSITION_ARB 0x864B +#define GL_PROGRAM_BINDING_ARB 0x8677 +#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB 0x886A +#define GL_PROGRAM_ERROR_STRING_ARB 0x8874 +#define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875 +#define GL_PROGRAM_FORMAT_ARB 0x8876 +#define GL_PROGRAM_INSTRUCTIONS_ARB 0x88A0 +#define GL_MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1 +#define GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2 +#define GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3 +#define GL_PROGRAM_TEMPORARIES_ARB 0x88A4 +#define GL_MAX_PROGRAM_TEMPORARIES_ARB 0x88A5 +#define GL_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6 +#define GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7 +#define GL_PROGRAM_PARAMETERS_ARB 0x88A8 +#define GL_MAX_PROGRAM_PARAMETERS_ARB 0x88A9 +#define GL_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA +#define GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB +#define GL_PROGRAM_ATTRIBS_ARB 0x88AC +#define GL_MAX_PROGRAM_ATTRIBS_ARB 0x88AD +#define GL_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE +#define GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF +#define GL_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0 +#define GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1 +#define GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2 +#define GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3 +#define GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4 +#define GL_MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5 +#define GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6 +#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7 +#define GL_MATRIX0_ARB 0x88C0 +#define GL_MATRIX1_ARB 0x88C1 +#define GL_MATRIX2_ARB 0x88C2 +#define GL_MATRIX3_ARB 0x88C3 +#define GL_MATRIX4_ARB 0x88C4 +#define GL_MATRIX5_ARB 0x88C5 +#define GL_MATRIX6_ARB 0x88C6 +#define GL_MATRIX7_ARB 0x88C7 +#define GL_MATRIX8_ARB 0x88C8 +#define GL_MATRIX9_ARB 0x88C9 +#define GL_MATRIX10_ARB 0x88CA +#define GL_MATRIX11_ARB 0x88CB +#define GL_MATRIX12_ARB 0x88CC +#define GL_MATRIX13_ARB 0x88CD +#define GL_MATRIX14_ARB 0x88CE +#define GL_MATRIX15_ARB 0x88CF +#define GL_MATRIX16_ARB 0x88D0 +#define GL_MATRIX17_ARB 0x88D1 +#define GL_MATRIX18_ARB 0x88D2 +#define GL_MATRIX19_ARB 0x88D3 +#define GL_MATRIX20_ARB 0x88D4 +#define GL_MATRIX21_ARB 0x88D5 +#define GL_MATRIX22_ARB 0x88D6 +#define GL_MATRIX23_ARB 0x88D7 +#define GL_MATRIX24_ARB 0x88D8 +#define GL_MATRIX25_ARB 0x88D9 +#define GL_MATRIX26_ARB 0x88DA +#define GL_MATRIX27_ARB 0x88DB +#define GL_MATRIX28_ARB 0x88DC +#define GL_MATRIX29_ARB 0x88DD +#define GL_MATRIX30_ARB 0x88DE +#define GL_MATRIX31_ARB 0x88DF +#endif + +#ifndef GL_ARB_fragment_program +#define GL_FRAGMENT_PROGRAM_ARB 0x8804 +#define GL_PROGRAM_ALU_INSTRUCTIONS_ARB 0x8805 +#define GL_PROGRAM_TEX_INSTRUCTIONS_ARB 0x8806 +#define GL_PROGRAM_TEX_INDIRECTIONS_ARB 0x8807 +#define GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x8808 +#define GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x8809 +#define GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x880A +#define GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB 0x880B +#define GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB 0x880C +#define GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB 0x880D +#define GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x880E +#define GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x880F +#define GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x8810 +#define GL_MAX_TEXTURE_COORDS_ARB 0x8871 +#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872 +#endif + +#ifndef GL_ARB_vertex_buffer_object +#define GL_BUFFER_SIZE_ARB 0x8764 +#define GL_BUFFER_USAGE_ARB 0x8765 +#define GL_ARRAY_BUFFER_ARB 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893 +#define GL_ARRAY_BUFFER_BINDING_ARB 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB 0x8895 +#define GL_VERTEX_ARRAY_BUFFER_BINDING_ARB 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING_ARB 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING_ARB 0x8898 +#define GL_INDEX_ARRAY_BUFFER_BINDING_ARB 0x8899 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB 0x889A +#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB 0x889B +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB 0x889C +#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB 0x889D +#define GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB 0x889E +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB 0x889F +#define GL_READ_ONLY_ARB 0x88B8 +#define GL_WRITE_ONLY_ARB 0x88B9 +#define GL_READ_WRITE_ARB 0x88BA +#define GL_BUFFER_ACCESS_ARB 0x88BB +#define GL_BUFFER_MAPPED_ARB 0x88BC +#define GL_BUFFER_MAP_POINTER_ARB 0x88BD +#define GL_STREAM_DRAW_ARB 0x88E0 +#define GL_STREAM_READ_ARB 0x88E1 +#define GL_STREAM_COPY_ARB 0x88E2 +#define GL_STATIC_DRAW_ARB 0x88E4 +#define GL_STATIC_READ_ARB 0x88E5 +#define GL_STATIC_COPY_ARB 0x88E6 +#define GL_DYNAMIC_DRAW_ARB 0x88E8 +#define GL_DYNAMIC_READ_ARB 0x88E9 +#define GL_DYNAMIC_COPY_ARB 0x88EA +#endif + +#ifndef GL_ARB_occlusion_query +#define GL_QUERY_COUNTER_BITS_ARB 0x8864 +#define GL_CURRENT_QUERY_ARB 0x8865 +#define GL_QUERY_RESULT_ARB 0x8866 +#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867 +#define GL_SAMPLES_PASSED_ARB 0x8914 +#endif + +#ifndef GL_ARB_shader_objects +#define GL_PROGRAM_OBJECT_ARB 0x8B40 +#define GL_SHADER_OBJECT_ARB 0x8B48 +#define GL_OBJECT_TYPE_ARB 0x8B4E +#define GL_OBJECT_SUBTYPE_ARB 0x8B4F +#define GL_FLOAT_VEC2_ARB 0x8B50 +#define GL_FLOAT_VEC3_ARB 0x8B51 +#define GL_FLOAT_VEC4_ARB 0x8B52 +#define GL_INT_VEC2_ARB 0x8B53 +#define GL_INT_VEC3_ARB 0x8B54 +#define GL_INT_VEC4_ARB 0x8B55 +#define GL_BOOL_ARB 0x8B56 +#define GL_BOOL_VEC2_ARB 0x8B57 +#define GL_BOOL_VEC3_ARB 0x8B58 +#define GL_BOOL_VEC4_ARB 0x8B59 +#define GL_FLOAT_MAT2_ARB 0x8B5A +#define GL_FLOAT_MAT3_ARB 0x8B5B +#define GL_FLOAT_MAT4_ARB 0x8B5C +#define GL_SAMPLER_1D_ARB 0x8B5D +#define GL_SAMPLER_2D_ARB 0x8B5E +#define GL_SAMPLER_3D_ARB 0x8B5F +#define GL_SAMPLER_CUBE_ARB 0x8B60 +#define GL_SAMPLER_1D_SHADOW_ARB 0x8B61 +#define GL_SAMPLER_2D_SHADOW_ARB 0x8B62 +#define GL_SAMPLER_2D_RECT_ARB 0x8B63 +#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64 +#define GL_OBJECT_DELETE_STATUS_ARB 0x8B80 +#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81 +#define GL_OBJECT_LINK_STATUS_ARB 0x8B82 +#define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83 +#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84 +#define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85 +#define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86 +#define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87 +#define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88 +#endif + +#ifndef GL_ARB_vertex_shader +#define GL_VERTEX_SHADER_ARB 0x8B31 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A +#define GL_MAX_VARYING_FLOATS_ARB 0x8B4B +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB 0x8B4C +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D +#define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB 0x8B89 +#define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A +#endif + +#ifndef GL_ARB_fragment_shader +#define GL_FRAGMENT_SHADER_ARB 0x8B30 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49 +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB 0x8B8B +#endif + +#ifndef GL_ARB_shading_language_100 +#define GL_SHADING_LANGUAGE_VERSION_ARB 0x8B8C +#endif + +#ifndef GL_ARB_texture_non_power_of_two +#endif + +#ifndef GL_ARB_point_sprite +#define GL_POINT_SPRITE_ARB 0x8861 +#define GL_COORD_REPLACE_ARB 0x8862 +#endif + +#ifndef GL_ARB_fragment_program_shadow +#endif + +#ifndef GL_ARB_draw_buffers +#define GL_MAX_DRAW_BUFFERS_ARB 0x8824 +#define GL_DRAW_BUFFER0_ARB 0x8825 +#define GL_DRAW_BUFFER1_ARB 0x8826 +#define GL_DRAW_BUFFER2_ARB 0x8827 +#define GL_DRAW_BUFFER3_ARB 0x8828 +#define GL_DRAW_BUFFER4_ARB 0x8829 +#define GL_DRAW_BUFFER5_ARB 0x882A +#define GL_DRAW_BUFFER6_ARB 0x882B +#define GL_DRAW_BUFFER7_ARB 0x882C +#define GL_DRAW_BUFFER8_ARB 0x882D +#define GL_DRAW_BUFFER9_ARB 0x882E +#define GL_DRAW_BUFFER10_ARB 0x882F +#define GL_DRAW_BUFFER11_ARB 0x8830 +#define GL_DRAW_BUFFER12_ARB 0x8831 +#define GL_DRAW_BUFFER13_ARB 0x8832 +#define GL_DRAW_BUFFER14_ARB 0x8833 +#define GL_DRAW_BUFFER15_ARB 0x8834 +#endif + +#ifndef GL_ARB_texture_rectangle +#define GL_TEXTURE_RECTANGLE_ARB 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE_ARB 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE_ARB 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 +#endif + +#ifndef GL_ARB_color_buffer_float +#define GL_RGBA_FLOAT_MODE_ARB 0x8820 +#define GL_CLAMP_VERTEX_COLOR_ARB 0x891A +#define GL_CLAMP_FRAGMENT_COLOR_ARB 0x891B +#define GL_CLAMP_READ_COLOR_ARB 0x891C +#define GL_FIXED_ONLY_ARB 0x891D +#endif + +#ifndef GL_ARB_half_float_pixel +#define GL_HALF_FLOAT_ARB 0x140B +#endif + +#ifndef GL_ARB_texture_float +#define GL_TEXTURE_RED_TYPE_ARB 0x8C10 +#define GL_TEXTURE_GREEN_TYPE_ARB 0x8C11 +#define GL_TEXTURE_BLUE_TYPE_ARB 0x8C12 +#define GL_TEXTURE_ALPHA_TYPE_ARB 0x8C13 +#define GL_TEXTURE_LUMINANCE_TYPE_ARB 0x8C14 +#define GL_TEXTURE_INTENSITY_TYPE_ARB 0x8C15 +#define GL_TEXTURE_DEPTH_TYPE_ARB 0x8C16 +#define GL_UNSIGNED_NORMALIZED_ARB 0x8C17 +#define GL_RGBA32F_ARB 0x8814 +#define GL_RGB32F_ARB 0x8815 +#define GL_ALPHA32F_ARB 0x8816 +#define GL_INTENSITY32F_ARB 0x8817 +#define GL_LUMINANCE32F_ARB 0x8818 +#define GL_LUMINANCE_ALPHA32F_ARB 0x8819 +#define GL_RGBA16F_ARB 0x881A +#define GL_RGB16F_ARB 0x881B +#define GL_ALPHA16F_ARB 0x881C +#define GL_INTENSITY16F_ARB 0x881D +#define GL_LUMINANCE16F_ARB 0x881E +#define GL_LUMINANCE_ALPHA16F_ARB 0x881F +#endif + +#ifndef GL_ARB_pixel_buffer_object +#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB +#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF +#endif + +#ifndef GL_ARB_depth_buffer_float +#define GL_DEPTH_COMPONENT32F 0x8CAC +#define GL_DEPTH32F_STENCIL8 0x8CAD +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD +#endif + +#ifndef GL_ARB_draw_instanced +#endif + +#ifndef GL_ARB_framebuffer_object +#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 +#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 +#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 +#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212 +#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213 +#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214 +#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215 +#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216 +#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217 +#define GL_FRAMEBUFFER_DEFAULT 0x8218 +#define GL_FRAMEBUFFER_UNDEFINED 0x8219 +#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A +#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 +#define GL_DEPTH_STENCIL 0x84F9 +#define GL_UNSIGNED_INT_24_8 0x84FA +#define GL_DEPTH24_STENCIL8 0x88F0 +#define GL_TEXTURE_STENCIL_SIZE 0x88F1 +#define GL_TEXTURE_RED_TYPE 0x8C10 +#define GL_TEXTURE_GREEN_TYPE 0x8C11 +#define GL_TEXTURE_BLUE_TYPE 0x8C12 +#define GL_TEXTURE_ALPHA_TYPE 0x8C13 +#define GL_TEXTURE_DEPTH_TYPE 0x8C16 +#define GL_UNSIGNED_NORMALIZED 0x8C17 +#define GL_FRAMEBUFFER_BINDING 0x8CA6 +#define GL_DRAW_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING +#define GL_RENDERBUFFER_BINDING 0x8CA7 +#define GL_READ_FRAMEBUFFER 0x8CA8 +#define GL_DRAW_FRAMEBUFFER 0x8CA9 +#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA +#define GL_RENDERBUFFER_SAMPLES 0x8CAB +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 +#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC +#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD +#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#define GL_COLOR_ATTACHMENT1 0x8CE1 +#define GL_COLOR_ATTACHMENT2 0x8CE2 +#define GL_COLOR_ATTACHMENT3 0x8CE3 +#define GL_COLOR_ATTACHMENT4 0x8CE4 +#define GL_COLOR_ATTACHMENT5 0x8CE5 +#define GL_COLOR_ATTACHMENT6 0x8CE6 +#define GL_COLOR_ATTACHMENT7 0x8CE7 +#define GL_COLOR_ATTACHMENT8 0x8CE8 +#define GL_COLOR_ATTACHMENT9 0x8CE9 +#define GL_COLOR_ATTACHMENT10 0x8CEA +#define GL_COLOR_ATTACHMENT11 0x8CEB +#define GL_COLOR_ATTACHMENT12 0x8CEC +#define GL_COLOR_ATTACHMENT13 0x8CED +#define GL_COLOR_ATTACHMENT14 0x8CEE +#define GL_COLOR_ATTACHMENT15 0x8CEF +#define GL_DEPTH_ATTACHMENT 0x8D00 +#define GL_STENCIL_ATTACHMENT 0x8D20 +#define GL_FRAMEBUFFER 0x8D40 +#define GL_RENDERBUFFER 0x8D41 +#define GL_RENDERBUFFER_WIDTH 0x8D42 +#define GL_RENDERBUFFER_HEIGHT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 +#define GL_STENCIL_INDEX1 0x8D46 +#define GL_STENCIL_INDEX4 0x8D47 +#define GL_STENCIL_INDEX8 0x8D48 +#define GL_STENCIL_INDEX16 0x8D49 +#define GL_RENDERBUFFER_RED_SIZE 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 +#define GL_MAX_SAMPLES 0x8D57 +#endif + +#ifndef GL_ARB_framebuffer_object_DEPRECATED +#define GL_INDEX 0x8222 +#define GL_TEXTURE_LUMINANCE_TYPE 0x8C14 +#define GL_TEXTURE_INTENSITY_TYPE 0x8C15 +#endif + +#ifndef GL_ARB_framebuffer_sRGB +#define GL_FRAMEBUFFER_SRGB 0x8DB9 +#endif + +#ifndef GL_ARB_geometry_shader4 +#define GL_LINES_ADJACENCY_ARB 0x000A +#define GL_LINE_STRIP_ADJACENCY_ARB 0x000B +#define GL_TRIANGLES_ADJACENCY_ARB 0x000C +#define GL_TRIANGLE_STRIP_ADJACENCY_ARB 0x000D +#define GL_PROGRAM_POINT_SIZE_ARB 0x8642 +#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_ARB 0x8C29 +#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_ARB 0x8DA7 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB 0x8DA8 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB 0x8DA9 +#define GL_GEOMETRY_SHADER_ARB 0x8DD9 +#define GL_GEOMETRY_VERTICES_OUT_ARB 0x8DDA +#define GL_GEOMETRY_INPUT_TYPE_ARB 0x8DDB +#define GL_GEOMETRY_OUTPUT_TYPE_ARB 0x8DDC +#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_ARB 0x8DDD +#define GL_MAX_VERTEX_VARYING_COMPONENTS_ARB 0x8DDE +#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_ARB 0x8DDF +#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_ARB 0x8DE0 +#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_ARB 0x8DE1 +/* reuse GL_MAX_VARYING_COMPONENTS */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER */ +#endif + +#ifndef GL_ARB_half_float_vertex +#define GL_HALF_FLOAT 0x140B +#endif + +#ifndef GL_ARB_instanced_arrays +#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB 0x88FE +#endif + +#ifndef GL_ARB_map_buffer_range +#define GL_MAP_READ_BIT 0x0001 +#define GL_MAP_WRITE_BIT 0x0002 +#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004 +#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008 +#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010 +#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 +#endif + +#ifndef GL_ARB_texture_buffer_object +#define GL_TEXTURE_BUFFER_ARB 0x8C2A +#define GL_MAX_TEXTURE_BUFFER_SIZE_ARB 0x8C2B +#define GL_TEXTURE_BINDING_BUFFER_ARB 0x8C2C +#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB 0x8C2D +#define GL_TEXTURE_BUFFER_FORMAT_ARB 0x8C2E +#endif + +#ifndef GL_ARB_texture_compression_rgtc +#define GL_COMPRESSED_RED_RGTC1 0x8DBB +#define GL_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC +#define GL_COMPRESSED_RG_RGTC2 0x8DBD +#define GL_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE +#endif + +#ifndef GL_ARB_texture_rg +#define GL_RG 0x8227 +#define GL_RG_INTEGER 0x8228 +#define GL_R8 0x8229 +#define GL_R16 0x822A +#define GL_RG8 0x822B +#define GL_RG16 0x822C +#define GL_R16F 0x822D +#define GL_R32F 0x822E +#define GL_RG16F 0x822F +#define GL_RG32F 0x8230 +#define GL_R8I 0x8231 +#define GL_R8UI 0x8232 +#define GL_R16I 0x8233 +#define GL_R16UI 0x8234 +#define GL_R32I 0x8235 +#define GL_R32UI 0x8236 +#define GL_RG8I 0x8237 +#define GL_RG8UI 0x8238 +#define GL_RG16I 0x8239 +#define GL_RG16UI 0x823A +#define GL_RG32I 0x823B +#define GL_RG32UI 0x823C +#endif + +#ifndef GL_ARB_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING 0x85B5 +#endif + +#ifndef GL_ARB_uniform_buffer_object +#define GL_UNIFORM_BUFFER 0x8A11 +#define GL_UNIFORM_BUFFER_BINDING 0x8A28 +#define GL_UNIFORM_BUFFER_START 0x8A29 +#define GL_UNIFORM_BUFFER_SIZE 0x8A2A +#define GL_MAX_VERTEX_UNIFORM_BLOCKS 0x8A2B +#define GL_MAX_GEOMETRY_UNIFORM_BLOCKS 0x8A2C +#define GL_MAX_FRAGMENT_UNIFORM_BLOCKS 0x8A2D +#define GL_MAX_COMBINED_UNIFORM_BLOCKS 0x8A2E +#define GL_MAX_UNIFORM_BUFFER_BINDINGS 0x8A2F +#define GL_MAX_UNIFORM_BLOCK_SIZE 0x8A30 +#define GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS 0x8A31 +#define GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS 0x8A32 +#define GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS 0x8A33 +#define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT 0x8A34 +#define GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH 0x8A35 +#define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36 +#define GL_UNIFORM_TYPE 0x8A37 +#define GL_UNIFORM_SIZE 0x8A38 +#define GL_UNIFORM_NAME_LENGTH 0x8A39 +#define GL_UNIFORM_BLOCK_INDEX 0x8A3A +#define GL_UNIFORM_OFFSET 0x8A3B +#define GL_UNIFORM_ARRAY_STRIDE 0x8A3C +#define GL_UNIFORM_MATRIX_STRIDE 0x8A3D +#define GL_UNIFORM_IS_ROW_MAJOR 0x8A3E +#define GL_UNIFORM_BLOCK_BINDING 0x8A3F +#define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40 +#define GL_UNIFORM_BLOCK_NAME_LENGTH 0x8A41 +#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42 +#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 0x8A43 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER 0x8A44 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER 0x8A45 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 0x8A46 +#define GL_INVALID_INDEX 0xFFFFFFFFu +#endif + +#ifndef GL_ARB_compatibility +/* ARB_compatibility just defines tokens from core 3.0 */ +#endif + +#ifndef GL_ARB_copy_buffer +#define GL_COPY_READ_BUFFER 0x8F36 +#define GL_COPY_WRITE_BUFFER 0x8F37 +#endif + +#ifndef GL_ARB_shader_texture_lod +#endif + +#ifndef GL_ARB_depth_clamp +#define GL_DEPTH_CLAMP 0x864F +#endif + +#ifndef GL_ARB_draw_elements_base_vertex +#endif + +#ifndef GL_ARB_fragment_coord_conventions +#endif + +#ifndef GL_ARB_provoking_vertex +#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION 0x8E4C +#define GL_FIRST_VERTEX_CONVENTION 0x8E4D +#define GL_LAST_VERTEX_CONVENTION 0x8E4E +#define GL_PROVOKING_VERTEX 0x8E4F +#endif + +#ifndef GL_ARB_seamless_cube_map +#define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F +#endif + +#ifndef GL_ARB_sync +#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 +#define GL_OBJECT_TYPE 0x9112 +#define GL_SYNC_CONDITION 0x9113 +#define GL_SYNC_STATUS 0x9114 +#define GL_SYNC_FLAGS 0x9115 +#define GL_SYNC_FENCE 0x9116 +#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 +#define GL_UNSIGNALED 0x9118 +#define GL_SIGNALED 0x9119 +#define GL_ALREADY_SIGNALED 0x911A +#define GL_TIMEOUT_EXPIRED 0x911B +#define GL_CONDITION_SATISFIED 0x911C +#define GL_WAIT_FAILED 0x911D +#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 +#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull +#endif + +#ifndef GL_ARB_texture_multisample +#define GL_SAMPLE_POSITION 0x8E50 +#define GL_SAMPLE_MASK 0x8E51 +#define GL_SAMPLE_MASK_VALUE 0x8E52 +#define GL_MAX_SAMPLE_MASK_WORDS 0x8E59 +#define GL_TEXTURE_2D_MULTISAMPLE 0x9100 +#define GL_PROXY_TEXTURE_2D_MULTISAMPLE 0x9101 +#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102 +#define GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9103 +#define GL_TEXTURE_BINDING_2D_MULTISAMPLE 0x9104 +#define GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY 0x9105 +#define GL_TEXTURE_SAMPLES 0x9106 +#define GL_TEXTURE_FIXED_SAMPLE_LOCATIONS 0x9107 +#define GL_SAMPLER_2D_MULTISAMPLE 0x9108 +#define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109 +#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A +#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910B +#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910C +#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910D +#define GL_MAX_COLOR_TEXTURE_SAMPLES 0x910E +#define GL_MAX_DEPTH_TEXTURE_SAMPLES 0x910F +#define GL_MAX_INTEGER_SAMPLES 0x9110 +#endif + +#ifndef GL_ARB_vertex_array_bgra +/* reuse GL_BGRA */ +#endif + +#ifndef GL_ARB_draw_buffers_blend +#endif + +#ifndef GL_ARB_sample_shading +#define GL_SAMPLE_SHADING_ARB 0x8C36 +#define GL_MIN_SAMPLE_SHADING_VALUE_ARB 0x8C37 +#endif + +#ifndef GL_ARB_texture_cube_map_array +#define GL_TEXTURE_CUBE_MAP_ARRAY_ARB 0x9009 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB 0x900A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB 0x900B +#define GL_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900C +#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_ARB 0x900D +#define GL_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900E +#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900F +#endif + +#ifndef GL_ARB_texture_gather +#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5E +#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5F +#endif + +#ifndef GL_ARB_texture_query_lod +#endif + +#ifndef GL_ARB_shading_language_include +#define GL_SHADER_INCLUDE_ARB 0x8DAE +#define GL_NAMED_STRING_LENGTH_ARB 0x8DE9 +#define GL_NAMED_STRING_TYPE_ARB 0x8DEA +#endif + +#ifndef GL_ARB_texture_compression_bptc +#define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C +#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB 0x8E8D +#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB 0x8E8E +#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F +#endif + +#ifndef GL_ARB_blend_func_extended +#define GL_SRC1_COLOR 0x88F9 +/* reuse GL_SRC1_ALPHA */ +#define GL_ONE_MINUS_SRC1_COLOR 0x88FA +#define GL_ONE_MINUS_SRC1_ALPHA 0x88FB +#define GL_MAX_DUAL_SOURCE_DRAW_BUFFERS 0x88FC +#endif + +#ifndef GL_ARB_explicit_attrib_location +#endif + +#ifndef GL_ARB_occlusion_query2 +#define GL_ANY_SAMPLES_PASSED 0x8C2F +#endif + +#ifndef GL_ARB_sampler_objects +#define GL_SAMPLER_BINDING 0x8919 +#endif + +#ifndef GL_ARB_shader_bit_encoding +#endif + +#ifndef GL_ARB_texture_rgb10_a2ui +#define GL_RGB10_A2UI 0x906F +#endif + +#ifndef GL_ARB_texture_swizzle +#define GL_TEXTURE_SWIZZLE_R 0x8E42 +#define GL_TEXTURE_SWIZZLE_G 0x8E43 +#define GL_TEXTURE_SWIZZLE_B 0x8E44 +#define GL_TEXTURE_SWIZZLE_A 0x8E45 +#define GL_TEXTURE_SWIZZLE_RGBA 0x8E46 +#endif + +#ifndef GL_ARB_timer_query +#define GL_TIME_ELAPSED 0x88BF +#define GL_TIMESTAMP 0x8E28 +#endif + +#ifndef GL_ARB_vertex_type_2_10_10_10_rev +/* reuse GL_UNSIGNED_INT_2_10_10_10_REV */ +#define GL_INT_2_10_10_10_REV 0x8D9F +#endif + +#ifndef GL_ARB_draw_indirect +#define GL_DRAW_INDIRECT_BUFFER 0x8F3F +#define GL_DRAW_INDIRECT_BUFFER_BINDING 0x8F43 +#endif + +#ifndef GL_ARB_gpu_shader5 +#define GL_GEOMETRY_SHADER_INVOCATIONS 0x887F +#define GL_MAX_GEOMETRY_SHADER_INVOCATIONS 0x8E5A +#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET 0x8E5B +#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET 0x8E5C +#define GL_FRAGMENT_INTERPOLATION_OFFSET_BITS 0x8E5D +/* reuse GL_MAX_VERTEX_STREAMS */ +#endif + +#ifndef GL_ARB_gpu_shader_fp64 +/* reuse GL_DOUBLE */ +#define GL_DOUBLE_VEC2 0x8FFC +#define GL_DOUBLE_VEC3 0x8FFD +#define GL_DOUBLE_VEC4 0x8FFE +#define GL_DOUBLE_MAT2 0x8F46 +#define GL_DOUBLE_MAT3 0x8F47 +#define GL_DOUBLE_MAT4 0x8F48 +#define GL_DOUBLE_MAT2x3 0x8F49 +#define GL_DOUBLE_MAT2x4 0x8F4A +#define GL_DOUBLE_MAT3x2 0x8F4B +#define GL_DOUBLE_MAT3x4 0x8F4C +#define GL_DOUBLE_MAT4x2 0x8F4D +#define GL_DOUBLE_MAT4x3 0x8F4E +#endif + +#ifndef GL_ARB_shader_subroutine +#define GL_ACTIVE_SUBROUTINES 0x8DE5 +#define GL_ACTIVE_SUBROUTINE_UNIFORMS 0x8DE6 +#define GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS 0x8E47 +#define GL_ACTIVE_SUBROUTINE_MAX_LENGTH 0x8E48 +#define GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH 0x8E49 +#define GL_MAX_SUBROUTINES 0x8DE7 +#define GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS 0x8DE8 +#define GL_NUM_COMPATIBLE_SUBROUTINES 0x8E4A +#define GL_COMPATIBLE_SUBROUTINES 0x8E4B +/* reuse GL_UNIFORM_SIZE */ +/* reuse GL_UNIFORM_NAME_LENGTH */ +#endif + +#ifndef GL_ARB_tessellation_shader +#define GL_PATCHES 0x000E +#define GL_PATCH_VERTICES 0x8E72 +#define GL_PATCH_DEFAULT_INNER_LEVEL 0x8E73 +#define GL_PATCH_DEFAULT_OUTER_LEVEL 0x8E74 +#define GL_TESS_CONTROL_OUTPUT_VERTICES 0x8E75 +#define GL_TESS_GEN_MODE 0x8E76 +#define GL_TESS_GEN_SPACING 0x8E77 +#define GL_TESS_GEN_VERTEX_ORDER 0x8E78 +#define GL_TESS_GEN_POINT_MODE 0x8E79 +/* reuse GL_TRIANGLES */ +/* reuse GL_QUADS */ +#define GL_ISOLINES 0x8E7A +/* reuse GL_EQUAL */ +#define GL_FRACTIONAL_ODD 0x8E7B +#define GL_FRACTIONAL_EVEN 0x8E7C +/* reuse GL_CCW */ +/* reuse GL_CW */ +#define GL_MAX_PATCH_VERTICES 0x8E7D +#define GL_MAX_TESS_GEN_LEVEL 0x8E7E +#define GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E7F +#define GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E80 +#define GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS 0x8E81 +#define GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS 0x8E82 +#define GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS 0x8E83 +#define GL_MAX_TESS_PATCH_COMPONENTS 0x8E84 +#define GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS 0x8E85 +#define GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS 0x8E86 +#define GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS 0x8E89 +#define GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS 0x8E8A +#define GL_MAX_TESS_CONTROL_INPUT_COMPONENTS 0x886C +#define GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS 0x886D +#define GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E1E +#define GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E1F +#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER 0x84F0 +#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER 0x84F1 +#define GL_TESS_EVALUATION_SHADER 0x8E87 +#define GL_TESS_CONTROL_SHADER 0x8E88 +#endif + +#ifndef GL_ARB_texture_buffer_object_rgb32 +/* reuse GL_RGB32F */ +/* reuse GL_RGB32UI */ +/* reuse GL_RGB32I */ +#endif + +#ifndef GL_ARB_transform_feedback2 +#define GL_TRANSFORM_FEEDBACK 0x8E22 +#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED 0x8E23 +#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE 0x8E24 +#define GL_TRANSFORM_FEEDBACK_BINDING 0x8E25 +#endif + +#ifndef GL_ARB_transform_feedback3 +#define GL_MAX_TRANSFORM_FEEDBACK_BUFFERS 0x8E70 +#define GL_MAX_VERTEX_STREAMS 0x8E71 +#endif + +#ifndef GL_ARB_ES2_compatibility +#define GL_FIXED 0x140C +#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B +#define GL_LOW_FLOAT 0x8DF0 +#define GL_MEDIUM_FLOAT 0x8DF1 +#define GL_HIGH_FLOAT 0x8DF2 +#define GL_LOW_INT 0x8DF3 +#define GL_MEDIUM_INT 0x8DF4 +#define GL_HIGH_INT 0x8DF5 +#define GL_SHADER_COMPILER 0x8DFA +#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 +#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB +#define GL_MAX_VARYING_VECTORS 0x8DFC +#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD +#endif + +#ifndef GL_ARB_get_program_binary +#define GL_PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257 +#define GL_PROGRAM_BINARY_LENGTH 0x8741 +#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE +#define GL_PROGRAM_BINARY_FORMATS 0x87FF +#endif + +#ifndef GL_ARB_separate_shader_objects +#define GL_VERTEX_SHADER_BIT 0x00000001 +#define GL_FRAGMENT_SHADER_BIT 0x00000002 +#define GL_GEOMETRY_SHADER_BIT 0x00000004 +#define GL_TESS_CONTROL_SHADER_BIT 0x00000008 +#define GL_TESS_EVALUATION_SHADER_BIT 0x00000010 +#define GL_ALL_SHADER_BITS 0xFFFFFFFF +#define GL_PROGRAM_SEPARABLE 0x8258 +#define GL_ACTIVE_PROGRAM 0x8259 +#define GL_PROGRAM_PIPELINE_BINDING 0x825A +#endif + +#ifndef GL_ARB_shader_precision +#endif + +#ifndef GL_ARB_vertex_attrib_64bit +/* reuse GL_RGB32I */ +/* reuse GL_DOUBLE_VEC2 */ +/* reuse GL_DOUBLE_VEC3 */ +/* reuse GL_DOUBLE_VEC4 */ +/* reuse GL_DOUBLE_MAT2 */ +/* reuse GL_DOUBLE_MAT3 */ +/* reuse GL_DOUBLE_MAT4 */ +/* reuse GL_DOUBLE_MAT2x3 */ +/* reuse GL_DOUBLE_MAT2x4 */ +/* reuse GL_DOUBLE_MAT3x2 */ +/* reuse GL_DOUBLE_MAT3x4 */ +/* reuse GL_DOUBLE_MAT4x2 */ +/* reuse GL_DOUBLE_MAT4x3 */ +#endif + +#ifndef GL_ARB_viewport_array +/* reuse GL_SCISSOR_BOX */ +/* reuse GL_VIEWPORT */ +/* reuse GL_DEPTH_RANGE */ +/* reuse GL_SCISSOR_TEST */ +#define GL_MAX_VIEWPORTS 0x825B +#define GL_VIEWPORT_SUBPIXEL_BITS 0x825C +#define GL_VIEWPORT_BOUNDS_RANGE 0x825D +#define GL_LAYER_PROVOKING_VERTEX 0x825E +#define GL_VIEWPORT_INDEX_PROVOKING_VERTEX 0x825F +#define GL_UNDEFINED_VERTEX 0x8260 +/* reuse GL_FIRST_VERTEX_CONVENTION */ +/* reuse GL_LAST_VERTEX_CONVENTION */ +/* reuse GL_PROVOKING_VERTEX */ +#endif + +#ifndef GL_ARB_cl_event +#define GL_SYNC_CL_EVENT_ARB 0x8240 +#define GL_SYNC_CL_EVENT_COMPLETE_ARB 0x8241 +#endif + +#ifndef GL_ARB_debug_output +#define GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB 0x8242 +#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB 0x8243 +#define GL_DEBUG_CALLBACK_FUNCTION_ARB 0x8244 +#define GL_DEBUG_CALLBACK_USER_PARAM_ARB 0x8245 +#define GL_DEBUG_SOURCE_API_ARB 0x8246 +#define GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB 0x8247 +#define GL_DEBUG_SOURCE_SHADER_COMPILER_ARB 0x8248 +#define GL_DEBUG_SOURCE_THIRD_PARTY_ARB 0x8249 +#define GL_DEBUG_SOURCE_APPLICATION_ARB 0x824A +#define GL_DEBUG_SOURCE_OTHER_ARB 0x824B +#define GL_DEBUG_TYPE_ERROR_ARB 0x824C +#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB 0x824D +#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB 0x824E +#define GL_DEBUG_TYPE_PORTABILITY_ARB 0x824F +#define GL_DEBUG_TYPE_PERFORMANCE_ARB 0x8250 +#define GL_DEBUG_TYPE_OTHER_ARB 0x8251 +#define GL_MAX_DEBUG_MESSAGE_LENGTH_ARB 0x9143 +#define GL_MAX_DEBUG_LOGGED_MESSAGES_ARB 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES_ARB 0x9145 +#define GL_DEBUG_SEVERITY_HIGH_ARB 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM_ARB 0x9147 +#define GL_DEBUG_SEVERITY_LOW_ARB 0x9148 +#endif + +#ifndef GL_ARB_robustness +/* reuse GL_NO_ERROR */ +#define GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB 0x00000004 +#define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 +#define GL_GUILTY_CONTEXT_RESET_ARB 0x8253 +#define GL_INNOCENT_CONTEXT_RESET_ARB 0x8254 +#define GL_UNKNOWN_CONTEXT_RESET_ARB 0x8255 +#define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 +#define GL_NO_RESET_NOTIFICATION_ARB 0x8261 +#endif + +#ifndef GL_ARB_shader_stencil_export +#endif + +#ifndef GL_EXT_abgr +#define GL_ABGR_EXT 0x8000 +#endif + +#ifndef GL_EXT_blend_color +#define GL_CONSTANT_COLOR_EXT 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR_EXT 0x8002 +#define GL_CONSTANT_ALPHA_EXT 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA_EXT 0x8004 +#define GL_BLEND_COLOR_EXT 0x8005 +#endif + +#ifndef GL_EXT_polygon_offset +#define GL_POLYGON_OFFSET_EXT 0x8037 +#define GL_POLYGON_OFFSET_FACTOR_EXT 0x8038 +#define GL_POLYGON_OFFSET_BIAS_EXT 0x8039 +#endif + +#ifndef GL_EXT_texture +#define GL_ALPHA4_EXT 0x803B +#define GL_ALPHA8_EXT 0x803C +#define GL_ALPHA12_EXT 0x803D +#define GL_ALPHA16_EXT 0x803E +#define GL_LUMINANCE4_EXT 0x803F +#define GL_LUMINANCE8_EXT 0x8040 +#define GL_LUMINANCE12_EXT 0x8041 +#define GL_LUMINANCE16_EXT 0x8042 +#define GL_LUMINANCE4_ALPHA4_EXT 0x8043 +#define GL_LUMINANCE6_ALPHA2_EXT 0x8044 +#define GL_LUMINANCE8_ALPHA8_EXT 0x8045 +#define GL_LUMINANCE12_ALPHA4_EXT 0x8046 +#define GL_LUMINANCE12_ALPHA12_EXT 0x8047 +#define GL_LUMINANCE16_ALPHA16_EXT 0x8048 +#define GL_INTENSITY_EXT 0x8049 +#define GL_INTENSITY4_EXT 0x804A +#define GL_INTENSITY8_EXT 0x804B +#define GL_INTENSITY12_EXT 0x804C +#define GL_INTENSITY16_EXT 0x804D +#define GL_RGB2_EXT 0x804E +#define GL_RGB4_EXT 0x804F +#define GL_RGB5_EXT 0x8050 +#define GL_RGB8_EXT 0x8051 +#define GL_RGB10_EXT 0x8052 +#define GL_RGB12_EXT 0x8053 +#define GL_RGB16_EXT 0x8054 +#define GL_RGBA2_EXT 0x8055 +#define GL_RGBA4_EXT 0x8056 +#define GL_RGB5_A1_EXT 0x8057 +#define GL_RGBA8_EXT 0x8058 +#define GL_RGB10_A2_EXT 0x8059 +#define GL_RGBA12_EXT 0x805A +#define GL_RGBA16_EXT 0x805B +#define GL_TEXTURE_RED_SIZE_EXT 0x805C +#define GL_TEXTURE_GREEN_SIZE_EXT 0x805D +#define GL_TEXTURE_BLUE_SIZE_EXT 0x805E +#define GL_TEXTURE_ALPHA_SIZE_EXT 0x805F +#define GL_TEXTURE_LUMINANCE_SIZE_EXT 0x8060 +#define GL_TEXTURE_INTENSITY_SIZE_EXT 0x8061 +#define GL_REPLACE_EXT 0x8062 +#define GL_PROXY_TEXTURE_1D_EXT 0x8063 +#define GL_PROXY_TEXTURE_2D_EXT 0x8064 +#define GL_TEXTURE_TOO_LARGE_EXT 0x8065 +#endif + +#ifndef GL_EXT_texture3D +#define GL_PACK_SKIP_IMAGES_EXT 0x806B +#define GL_PACK_IMAGE_HEIGHT_EXT 0x806C +#define GL_UNPACK_SKIP_IMAGES_EXT 0x806D +#define GL_UNPACK_IMAGE_HEIGHT_EXT 0x806E +#define GL_TEXTURE_3D_EXT 0x806F +#define GL_PROXY_TEXTURE_3D_EXT 0x8070 +#define GL_TEXTURE_DEPTH_EXT 0x8071 +#define GL_TEXTURE_WRAP_R_EXT 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE_EXT 0x8073 +#endif + +#ifndef GL_SGIS_texture_filter4 +#define GL_FILTER4_SGIS 0x8146 +#define GL_TEXTURE_FILTER4_SIZE_SGIS 0x8147 +#endif + +#ifndef GL_EXT_subtexture +#endif + +#ifndef GL_EXT_copy_texture +#endif + +#ifndef GL_EXT_histogram +#define GL_HISTOGRAM_EXT 0x8024 +#define GL_PROXY_HISTOGRAM_EXT 0x8025 +#define GL_HISTOGRAM_WIDTH_EXT 0x8026 +#define GL_HISTOGRAM_FORMAT_EXT 0x8027 +#define GL_HISTOGRAM_RED_SIZE_EXT 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE_EXT 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE_EXT 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE_EXT 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE_EXT 0x802C +#define GL_HISTOGRAM_SINK_EXT 0x802D +#define GL_MINMAX_EXT 0x802E +#define GL_MINMAX_FORMAT_EXT 0x802F +#define GL_MINMAX_SINK_EXT 0x8030 +#define GL_TABLE_TOO_LARGE_EXT 0x8031 +#endif + +#ifndef GL_EXT_convolution +#define GL_CONVOLUTION_1D_EXT 0x8010 +#define GL_CONVOLUTION_2D_EXT 0x8011 +#define GL_SEPARABLE_2D_EXT 0x8012 +#define GL_CONVOLUTION_BORDER_MODE_EXT 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE_EXT 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS_EXT 0x8015 +#define GL_REDUCE_EXT 0x8016 +#define GL_CONVOLUTION_FORMAT_EXT 0x8017 +#define GL_CONVOLUTION_WIDTH_EXT 0x8018 +#define GL_CONVOLUTION_HEIGHT_EXT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH_EXT 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT_EXT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE_EXT 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE_EXT 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE_EXT 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE_EXT 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS_EXT 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS_EXT 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS_EXT 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS_EXT 0x8023 +#endif + +#ifndef GL_SGI_color_matrix +#define GL_COLOR_MATRIX_SGI 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE_SGI 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE_SGI 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE_SGI 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE_SGI 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS_SGI 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS_SGI 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS_SGI 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS_SGI 0x80BB +#endif + +#ifndef GL_SGI_color_table +#define GL_COLOR_TABLE_SGI 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D2 +#define GL_PROXY_COLOR_TABLE_SGI 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D5 +#define GL_COLOR_TABLE_SCALE_SGI 0x80D6 +#define GL_COLOR_TABLE_BIAS_SGI 0x80D7 +#define GL_COLOR_TABLE_FORMAT_SGI 0x80D8 +#define GL_COLOR_TABLE_WIDTH_SGI 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE_SGI 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE_SGI 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE_SGI 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE_SGI 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE_SGI 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE_SGI 0x80DF +#endif + +#ifndef GL_SGIS_pixel_texture +#define GL_PIXEL_TEXTURE_SGIS 0x8353 +#define GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS 0x8354 +#define GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS 0x8355 +#define GL_PIXEL_GROUP_COLOR_SGIS 0x8356 +#endif + +#ifndef GL_SGIX_pixel_texture +#define GL_PIXEL_TEX_GEN_SGIX 0x8139 +#define GL_PIXEL_TEX_GEN_MODE_SGIX 0x832B +#endif + +#ifndef GL_SGIS_texture4D +#define GL_PACK_SKIP_VOLUMES_SGIS 0x8130 +#define GL_PACK_IMAGE_DEPTH_SGIS 0x8131 +#define GL_UNPACK_SKIP_VOLUMES_SGIS 0x8132 +#define GL_UNPACK_IMAGE_DEPTH_SGIS 0x8133 +#define GL_TEXTURE_4D_SGIS 0x8134 +#define GL_PROXY_TEXTURE_4D_SGIS 0x8135 +#define GL_TEXTURE_4DSIZE_SGIS 0x8136 +#define GL_TEXTURE_WRAP_Q_SGIS 0x8137 +#define GL_MAX_4D_TEXTURE_SIZE_SGIS 0x8138 +#define GL_TEXTURE_4D_BINDING_SGIS 0x814F +#endif + +#ifndef GL_SGI_texture_color_table +#define GL_TEXTURE_COLOR_TABLE_SGI 0x80BC +#define GL_PROXY_TEXTURE_COLOR_TABLE_SGI 0x80BD +#endif + +#ifndef GL_EXT_cmyka +#define GL_CMYK_EXT 0x800C +#define GL_CMYKA_EXT 0x800D +#define GL_PACK_CMYK_HINT_EXT 0x800E +#define GL_UNPACK_CMYK_HINT_EXT 0x800F +#endif + +#ifndef GL_EXT_texture_object +#define GL_TEXTURE_PRIORITY_EXT 0x8066 +#define GL_TEXTURE_RESIDENT_EXT 0x8067 +#define GL_TEXTURE_1D_BINDING_EXT 0x8068 +#define GL_TEXTURE_2D_BINDING_EXT 0x8069 +#define GL_TEXTURE_3D_BINDING_EXT 0x806A +#endif + +#ifndef GL_SGIS_detail_texture +#define GL_DETAIL_TEXTURE_2D_SGIS 0x8095 +#define GL_DETAIL_TEXTURE_2D_BINDING_SGIS 0x8096 +#define GL_LINEAR_DETAIL_SGIS 0x8097 +#define GL_LINEAR_DETAIL_ALPHA_SGIS 0x8098 +#define GL_LINEAR_DETAIL_COLOR_SGIS 0x8099 +#define GL_DETAIL_TEXTURE_LEVEL_SGIS 0x809A +#define GL_DETAIL_TEXTURE_MODE_SGIS 0x809B +#define GL_DETAIL_TEXTURE_FUNC_POINTS_SGIS 0x809C +#endif + +#ifndef GL_SGIS_sharpen_texture +#define GL_LINEAR_SHARPEN_SGIS 0x80AD +#define GL_LINEAR_SHARPEN_ALPHA_SGIS 0x80AE +#define GL_LINEAR_SHARPEN_COLOR_SGIS 0x80AF +#define GL_SHARPEN_TEXTURE_FUNC_POINTS_SGIS 0x80B0 +#endif + +#ifndef GL_EXT_packed_pixels +#define GL_UNSIGNED_BYTE_3_3_2_EXT 0x8032 +#define GL_UNSIGNED_SHORT_4_4_4_4_EXT 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1_EXT 0x8034 +#define GL_UNSIGNED_INT_8_8_8_8_EXT 0x8035 +#define GL_UNSIGNED_INT_10_10_10_2_EXT 0x8036 +#endif + +#ifndef GL_SGIS_texture_lod +#define GL_TEXTURE_MIN_LOD_SGIS 0x813A +#define GL_TEXTURE_MAX_LOD_SGIS 0x813B +#define GL_TEXTURE_BASE_LEVEL_SGIS 0x813C +#define GL_TEXTURE_MAX_LEVEL_SGIS 0x813D +#endif + +#ifndef GL_SGIS_multisample +#define GL_MULTISAMPLE_SGIS 0x809D +#define GL_SAMPLE_ALPHA_TO_MASK_SGIS 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_SGIS 0x809F +#define GL_SAMPLE_MASK_SGIS 0x80A0 +#define GL_1PASS_SGIS 0x80A1 +#define GL_2PASS_0_SGIS 0x80A2 +#define GL_2PASS_1_SGIS 0x80A3 +#define GL_4PASS_0_SGIS 0x80A4 +#define GL_4PASS_1_SGIS 0x80A5 +#define GL_4PASS_2_SGIS 0x80A6 +#define GL_4PASS_3_SGIS 0x80A7 +#define GL_SAMPLE_BUFFERS_SGIS 0x80A8 +#define GL_SAMPLES_SGIS 0x80A9 +#define GL_SAMPLE_MASK_VALUE_SGIS 0x80AA +#define GL_SAMPLE_MASK_INVERT_SGIS 0x80AB +#define GL_SAMPLE_PATTERN_SGIS 0x80AC +#endif + +#ifndef GL_EXT_rescale_normal +#define GL_RESCALE_NORMAL_EXT 0x803A +#endif + +#ifndef GL_EXT_vertex_array +#define GL_VERTEX_ARRAY_EXT 0x8074 +#define GL_NORMAL_ARRAY_EXT 0x8075 +#define GL_COLOR_ARRAY_EXT 0x8076 +#define GL_INDEX_ARRAY_EXT 0x8077 +#define GL_TEXTURE_COORD_ARRAY_EXT 0x8078 +#define GL_EDGE_FLAG_ARRAY_EXT 0x8079 +#define GL_VERTEX_ARRAY_SIZE_EXT 0x807A +#define GL_VERTEX_ARRAY_TYPE_EXT 0x807B +#define GL_VERTEX_ARRAY_STRIDE_EXT 0x807C +#define GL_VERTEX_ARRAY_COUNT_EXT 0x807D +#define GL_NORMAL_ARRAY_TYPE_EXT 0x807E +#define GL_NORMAL_ARRAY_STRIDE_EXT 0x807F +#define GL_NORMAL_ARRAY_COUNT_EXT 0x8080 +#define GL_COLOR_ARRAY_SIZE_EXT 0x8081 +#define GL_COLOR_ARRAY_TYPE_EXT 0x8082 +#define GL_COLOR_ARRAY_STRIDE_EXT 0x8083 +#define GL_COLOR_ARRAY_COUNT_EXT 0x8084 +#define GL_INDEX_ARRAY_TYPE_EXT 0x8085 +#define GL_INDEX_ARRAY_STRIDE_EXT 0x8086 +#define GL_INDEX_ARRAY_COUNT_EXT 0x8087 +#define GL_TEXTURE_COORD_ARRAY_SIZE_EXT 0x8088 +#define GL_TEXTURE_COORD_ARRAY_TYPE_EXT 0x8089 +#define GL_TEXTURE_COORD_ARRAY_STRIDE_EXT 0x808A +#define GL_TEXTURE_COORD_ARRAY_COUNT_EXT 0x808B +#define GL_EDGE_FLAG_ARRAY_STRIDE_EXT 0x808C +#define GL_EDGE_FLAG_ARRAY_COUNT_EXT 0x808D +#define GL_VERTEX_ARRAY_POINTER_EXT 0x808E +#define GL_NORMAL_ARRAY_POINTER_EXT 0x808F +#define GL_COLOR_ARRAY_POINTER_EXT 0x8090 +#define GL_INDEX_ARRAY_POINTER_EXT 0x8091 +#define GL_TEXTURE_COORD_ARRAY_POINTER_EXT 0x8092 +#define GL_EDGE_FLAG_ARRAY_POINTER_EXT 0x8093 +#endif + +#ifndef GL_EXT_misc_attribute +#endif + +#ifndef GL_SGIS_generate_mipmap +#define GL_GENERATE_MIPMAP_SGIS 0x8191 +#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 +#endif + +#ifndef GL_SGIX_clipmap +#define GL_LINEAR_CLIPMAP_LINEAR_SGIX 0x8170 +#define GL_TEXTURE_CLIPMAP_CENTER_SGIX 0x8171 +#define GL_TEXTURE_CLIPMAP_FRAME_SGIX 0x8172 +#define GL_TEXTURE_CLIPMAP_OFFSET_SGIX 0x8173 +#define GL_TEXTURE_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8174 +#define GL_TEXTURE_CLIPMAP_LOD_OFFSET_SGIX 0x8175 +#define GL_TEXTURE_CLIPMAP_DEPTH_SGIX 0x8176 +#define GL_MAX_CLIPMAP_DEPTH_SGIX 0x8177 +#define GL_MAX_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8178 +#define GL_NEAREST_CLIPMAP_NEAREST_SGIX 0x844D +#define GL_NEAREST_CLIPMAP_LINEAR_SGIX 0x844E +#define GL_LINEAR_CLIPMAP_NEAREST_SGIX 0x844F +#endif + +#ifndef GL_SGIX_shadow +#define GL_TEXTURE_COMPARE_SGIX 0x819A +#define GL_TEXTURE_COMPARE_OPERATOR_SGIX 0x819B +#define GL_TEXTURE_LEQUAL_R_SGIX 0x819C +#define GL_TEXTURE_GEQUAL_R_SGIX 0x819D +#endif + +#ifndef GL_SGIS_texture_edge_clamp +#define GL_CLAMP_TO_EDGE_SGIS 0x812F +#endif + +#ifndef GL_SGIS_texture_border_clamp +#define GL_CLAMP_TO_BORDER_SGIS 0x812D +#endif + +#ifndef GL_EXT_blend_minmax +#define GL_FUNC_ADD_EXT 0x8006 +#define GL_MIN_EXT 0x8007 +#define GL_MAX_EXT 0x8008 +#define GL_BLEND_EQUATION_EXT 0x8009 +#endif + +#ifndef GL_EXT_blend_subtract +#define GL_FUNC_SUBTRACT_EXT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT_EXT 0x800B +#endif + +#ifndef GL_EXT_blend_logic_op +#endif + +#ifndef GL_SGIX_interlace +#define GL_INTERLACE_SGIX 0x8094 +#endif + +#ifndef GL_SGIX_pixel_tiles +#define GL_PIXEL_TILE_BEST_ALIGNMENT_SGIX 0x813E +#define GL_PIXEL_TILE_CACHE_INCREMENT_SGIX 0x813F +#define GL_PIXEL_TILE_WIDTH_SGIX 0x8140 +#define GL_PIXEL_TILE_HEIGHT_SGIX 0x8141 +#define GL_PIXEL_TILE_GRID_WIDTH_SGIX 0x8142 +#define GL_PIXEL_TILE_GRID_HEIGHT_SGIX 0x8143 +#define GL_PIXEL_TILE_GRID_DEPTH_SGIX 0x8144 +#define GL_PIXEL_TILE_CACHE_SIZE_SGIX 0x8145 +#endif + +#ifndef GL_SGIS_texture_select +#define GL_DUAL_ALPHA4_SGIS 0x8110 +#define GL_DUAL_ALPHA8_SGIS 0x8111 +#define GL_DUAL_ALPHA12_SGIS 0x8112 +#define GL_DUAL_ALPHA16_SGIS 0x8113 +#define GL_DUAL_LUMINANCE4_SGIS 0x8114 +#define GL_DUAL_LUMINANCE8_SGIS 0x8115 +#define GL_DUAL_LUMINANCE12_SGIS 0x8116 +#define GL_DUAL_LUMINANCE16_SGIS 0x8117 +#define GL_DUAL_INTENSITY4_SGIS 0x8118 +#define GL_DUAL_INTENSITY8_SGIS 0x8119 +#define GL_DUAL_INTENSITY12_SGIS 0x811A +#define GL_DUAL_INTENSITY16_SGIS 0x811B +#define GL_DUAL_LUMINANCE_ALPHA4_SGIS 0x811C +#define GL_DUAL_LUMINANCE_ALPHA8_SGIS 0x811D +#define GL_QUAD_ALPHA4_SGIS 0x811E +#define GL_QUAD_ALPHA8_SGIS 0x811F +#define GL_QUAD_LUMINANCE4_SGIS 0x8120 +#define GL_QUAD_LUMINANCE8_SGIS 0x8121 +#define GL_QUAD_INTENSITY4_SGIS 0x8122 +#define GL_QUAD_INTENSITY8_SGIS 0x8123 +#define GL_DUAL_TEXTURE_SELECT_SGIS 0x8124 +#define GL_QUAD_TEXTURE_SELECT_SGIS 0x8125 +#endif + +#ifndef GL_SGIX_sprite +#define GL_SPRITE_SGIX 0x8148 +#define GL_SPRITE_MODE_SGIX 0x8149 +#define GL_SPRITE_AXIS_SGIX 0x814A +#define GL_SPRITE_TRANSLATION_SGIX 0x814B +#define GL_SPRITE_AXIAL_SGIX 0x814C +#define GL_SPRITE_OBJECT_ALIGNED_SGIX 0x814D +#define GL_SPRITE_EYE_ALIGNED_SGIX 0x814E +#endif + +#ifndef GL_SGIX_texture_multi_buffer +#define GL_TEXTURE_MULTI_BUFFER_HINT_SGIX 0x812E +#endif + +#ifndef GL_EXT_point_parameters +#define GL_POINT_SIZE_MIN_EXT 0x8126 +#define GL_POINT_SIZE_MAX_EXT 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128 +#define GL_DISTANCE_ATTENUATION_EXT 0x8129 +#endif + +#ifndef GL_SGIS_point_parameters +#define GL_POINT_SIZE_MIN_SGIS 0x8126 +#define GL_POINT_SIZE_MAX_SGIS 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_SGIS 0x8128 +#define GL_DISTANCE_ATTENUATION_SGIS 0x8129 +#endif + +#ifndef GL_SGIX_instruments +#define GL_INSTRUMENT_BUFFER_POINTER_SGIX 0x8180 +#define GL_INSTRUMENT_MEASUREMENTS_SGIX 0x8181 +#endif + +#ifndef GL_SGIX_texture_scale_bias +#define GL_POST_TEXTURE_FILTER_BIAS_SGIX 0x8179 +#define GL_POST_TEXTURE_FILTER_SCALE_SGIX 0x817A +#define GL_POST_TEXTURE_FILTER_BIAS_RANGE_SGIX 0x817B +#define GL_POST_TEXTURE_FILTER_SCALE_RANGE_SGIX 0x817C +#endif + +#ifndef GL_SGIX_framezoom +#define GL_FRAMEZOOM_SGIX 0x818B +#define GL_FRAMEZOOM_FACTOR_SGIX 0x818C +#define GL_MAX_FRAMEZOOM_FACTOR_SGIX 0x818D +#endif + +#ifndef GL_SGIX_tag_sample_buffer +#endif + +#ifndef GL_FfdMaskSGIX +#define GL_TEXTURE_DEFORMATION_BIT_SGIX 0x00000001 +#define GL_GEOMETRY_DEFORMATION_BIT_SGIX 0x00000002 +#endif + +#ifndef GL_SGIX_polynomial_ffd +#define GL_GEOMETRY_DEFORMATION_SGIX 0x8194 +#define GL_TEXTURE_DEFORMATION_SGIX 0x8195 +#define GL_DEFORMATIONS_MASK_SGIX 0x8196 +#define GL_MAX_DEFORMATION_ORDER_SGIX 0x8197 +#endif + +#ifndef GL_SGIX_reference_plane +#define GL_REFERENCE_PLANE_SGIX 0x817D +#define GL_REFERENCE_PLANE_EQUATION_SGIX 0x817E +#endif + +#ifndef GL_SGIX_flush_raster +#endif + +#ifndef GL_SGIX_depth_texture +#define GL_DEPTH_COMPONENT16_SGIX 0x81A5 +#define GL_DEPTH_COMPONENT24_SGIX 0x81A6 +#define GL_DEPTH_COMPONENT32_SGIX 0x81A7 +#endif + +#ifndef GL_SGIS_fog_function +#define GL_FOG_FUNC_SGIS 0x812A +#define GL_FOG_FUNC_POINTS_SGIS 0x812B +#define GL_MAX_FOG_FUNC_POINTS_SGIS 0x812C +#endif + +#ifndef GL_SGIX_fog_offset +#define GL_FOG_OFFSET_SGIX 0x8198 +#define GL_FOG_OFFSET_VALUE_SGIX 0x8199 +#endif + +#ifndef GL_HP_image_transform +#define GL_IMAGE_SCALE_X_HP 0x8155 +#define GL_IMAGE_SCALE_Y_HP 0x8156 +#define GL_IMAGE_TRANSLATE_X_HP 0x8157 +#define GL_IMAGE_TRANSLATE_Y_HP 0x8158 +#define GL_IMAGE_ROTATE_ANGLE_HP 0x8159 +#define GL_IMAGE_ROTATE_ORIGIN_X_HP 0x815A +#define GL_IMAGE_ROTATE_ORIGIN_Y_HP 0x815B +#define GL_IMAGE_MAG_FILTER_HP 0x815C +#define GL_IMAGE_MIN_FILTER_HP 0x815D +#define GL_IMAGE_CUBIC_WEIGHT_HP 0x815E +#define GL_CUBIC_HP 0x815F +#define GL_AVERAGE_HP 0x8160 +#define GL_IMAGE_TRANSFORM_2D_HP 0x8161 +#define GL_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8162 +#define GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8163 +#endif + +#ifndef GL_HP_convolution_border_modes +#define GL_IGNORE_BORDER_HP 0x8150 +#define GL_CONSTANT_BORDER_HP 0x8151 +#define GL_REPLICATE_BORDER_HP 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR_HP 0x8154 +#endif + +#ifndef GL_INGR_palette_buffer +#endif + +#ifndef GL_SGIX_texture_add_env +#define GL_TEXTURE_ENV_BIAS_SGIX 0x80BE +#endif + +#ifndef GL_EXT_color_subtable +#endif + +#ifndef GL_PGI_vertex_hints +#define GL_VERTEX_DATA_HINT_PGI 0x1A22A +#define GL_VERTEX_CONSISTENT_HINT_PGI 0x1A22B +#define GL_MATERIAL_SIDE_HINT_PGI 0x1A22C +#define GL_MAX_VERTEX_HINT_PGI 0x1A22D +#define GL_COLOR3_BIT_PGI 0x00010000 +#define GL_COLOR4_BIT_PGI 0x00020000 +#define GL_EDGEFLAG_BIT_PGI 0x00040000 +#define GL_INDEX_BIT_PGI 0x00080000 +#define GL_MAT_AMBIENT_BIT_PGI 0x00100000 +#define GL_MAT_AMBIENT_AND_DIFFUSE_BIT_PGI 0x00200000 +#define GL_MAT_DIFFUSE_BIT_PGI 0x00400000 +#define GL_MAT_EMISSION_BIT_PGI 0x00800000 +#define GL_MAT_COLOR_INDEXES_BIT_PGI 0x01000000 +#define GL_MAT_SHININESS_BIT_PGI 0x02000000 +#define GL_MAT_SPECULAR_BIT_PGI 0x04000000 +#define GL_NORMAL_BIT_PGI 0x08000000 +#define GL_TEXCOORD1_BIT_PGI 0x10000000 +#define GL_TEXCOORD2_BIT_PGI 0x20000000 +#define GL_TEXCOORD3_BIT_PGI 0x40000000 +#define GL_TEXCOORD4_BIT_PGI 0x80000000 +#define GL_VERTEX23_BIT_PGI 0x00000004 +#define GL_VERTEX4_BIT_PGI 0x00000008 +#endif + +#ifndef GL_PGI_misc_hints +#define GL_PREFER_DOUBLEBUFFER_HINT_PGI 0x1A1F8 +#define GL_CONSERVE_MEMORY_HINT_PGI 0x1A1FD +#define GL_RECLAIM_MEMORY_HINT_PGI 0x1A1FE +#define GL_NATIVE_GRAPHICS_HANDLE_PGI 0x1A202 +#define GL_NATIVE_GRAPHICS_BEGIN_HINT_PGI 0x1A203 +#define GL_NATIVE_GRAPHICS_END_HINT_PGI 0x1A204 +#define GL_ALWAYS_FAST_HINT_PGI 0x1A20C +#define GL_ALWAYS_SOFT_HINT_PGI 0x1A20D +#define GL_ALLOW_DRAW_OBJ_HINT_PGI 0x1A20E +#define GL_ALLOW_DRAW_WIN_HINT_PGI 0x1A20F +#define GL_ALLOW_DRAW_FRG_HINT_PGI 0x1A210 +#define GL_ALLOW_DRAW_MEM_HINT_PGI 0x1A211 +#define GL_STRICT_DEPTHFUNC_HINT_PGI 0x1A216 +#define GL_STRICT_LIGHTING_HINT_PGI 0x1A217 +#define GL_STRICT_SCISSOR_HINT_PGI 0x1A218 +#define GL_FULL_STIPPLE_HINT_PGI 0x1A219 +#define GL_CLIP_NEAR_HINT_PGI 0x1A220 +#define GL_CLIP_FAR_HINT_PGI 0x1A221 +#define GL_WIDE_LINE_HINT_PGI 0x1A222 +#define GL_BACK_NORMALS_HINT_PGI 0x1A223 +#endif + +#ifndef GL_EXT_paletted_texture +#define GL_COLOR_INDEX1_EXT 0x80E2 +#define GL_COLOR_INDEX2_EXT 0x80E3 +#define GL_COLOR_INDEX4_EXT 0x80E4 +#define GL_COLOR_INDEX8_EXT 0x80E5 +#define GL_COLOR_INDEX12_EXT 0x80E6 +#define GL_COLOR_INDEX16_EXT 0x80E7 +#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED +#endif + +#ifndef GL_EXT_clip_volume_hint +#define GL_CLIP_VOLUME_CLIPPING_HINT_EXT 0x80F0 +#endif + +#ifndef GL_SGIX_list_priority +#define GL_LIST_PRIORITY_SGIX 0x8182 +#endif + +#ifndef GL_SGIX_ir_instrument1 +#define GL_IR_INSTRUMENT1_SGIX 0x817F +#endif + +#ifndef GL_SGIX_calligraphic_fragment +#define GL_CALLIGRAPHIC_FRAGMENT_SGIX 0x8183 +#endif + +#ifndef GL_SGIX_texture_lod_bias +#define GL_TEXTURE_LOD_BIAS_S_SGIX 0x818E +#define GL_TEXTURE_LOD_BIAS_T_SGIX 0x818F +#define GL_TEXTURE_LOD_BIAS_R_SGIX 0x8190 +#endif + +#ifndef GL_SGIX_shadow_ambient +#define GL_SHADOW_AMBIENT_SGIX 0x80BF +#endif + +#ifndef GL_EXT_index_texture +#endif + +#ifndef GL_EXT_index_material +#define GL_INDEX_MATERIAL_EXT 0x81B8 +#define GL_INDEX_MATERIAL_PARAMETER_EXT 0x81B9 +#define GL_INDEX_MATERIAL_FACE_EXT 0x81BA +#endif + +#ifndef GL_EXT_index_func +#define GL_INDEX_TEST_EXT 0x81B5 +#define GL_INDEX_TEST_FUNC_EXT 0x81B6 +#define GL_INDEX_TEST_REF_EXT 0x81B7 +#endif + +#ifndef GL_EXT_index_array_formats +#define GL_IUI_V2F_EXT 0x81AD +#define GL_IUI_V3F_EXT 0x81AE +#define GL_IUI_N3F_V2F_EXT 0x81AF +#define GL_IUI_N3F_V3F_EXT 0x81B0 +#define GL_T2F_IUI_V2F_EXT 0x81B1 +#define GL_T2F_IUI_V3F_EXT 0x81B2 +#define GL_T2F_IUI_N3F_V2F_EXT 0x81B3 +#define GL_T2F_IUI_N3F_V3F_EXT 0x81B4 +#endif + +#ifndef GL_EXT_compiled_vertex_array +#define GL_ARRAY_ELEMENT_LOCK_FIRST_EXT 0x81A8 +#define GL_ARRAY_ELEMENT_LOCK_COUNT_EXT 0x81A9 +#endif + +#ifndef GL_EXT_cull_vertex +#define GL_CULL_VERTEX_EXT 0x81AA +#define GL_CULL_VERTEX_EYE_POSITION_EXT 0x81AB +#define GL_CULL_VERTEX_OBJECT_POSITION_EXT 0x81AC +#endif + +#ifndef GL_SGIX_ycrcb +#define GL_YCRCB_422_SGIX 0x81BB +#define GL_YCRCB_444_SGIX 0x81BC +#endif + +#ifndef GL_SGIX_fragment_lighting +#define GL_FRAGMENT_LIGHTING_SGIX 0x8400 +#define GL_FRAGMENT_COLOR_MATERIAL_SGIX 0x8401 +#define GL_FRAGMENT_COLOR_MATERIAL_FACE_SGIX 0x8402 +#define GL_FRAGMENT_COLOR_MATERIAL_PARAMETER_SGIX 0x8403 +#define GL_MAX_FRAGMENT_LIGHTS_SGIX 0x8404 +#define GL_MAX_ACTIVE_LIGHTS_SGIX 0x8405 +#define GL_CURRENT_RASTER_NORMAL_SGIX 0x8406 +#define GL_LIGHT_ENV_MODE_SGIX 0x8407 +#define GL_FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_SGIX 0x8408 +#define GL_FRAGMENT_LIGHT_MODEL_TWO_SIDE_SGIX 0x8409 +#define GL_FRAGMENT_LIGHT_MODEL_AMBIENT_SGIX 0x840A +#define GL_FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX 0x840B +#define GL_FRAGMENT_LIGHT0_SGIX 0x840C +#define GL_FRAGMENT_LIGHT1_SGIX 0x840D +#define GL_FRAGMENT_LIGHT2_SGIX 0x840E +#define GL_FRAGMENT_LIGHT3_SGIX 0x840F +#define GL_FRAGMENT_LIGHT4_SGIX 0x8410 +#define GL_FRAGMENT_LIGHT5_SGIX 0x8411 +#define GL_FRAGMENT_LIGHT6_SGIX 0x8412 +#define GL_FRAGMENT_LIGHT7_SGIX 0x8413 +#endif + +#ifndef GL_IBM_rasterpos_clip +#define GL_RASTER_POSITION_UNCLIPPED_IBM 0x19262 +#endif + +#ifndef GL_HP_texture_lighting +#define GL_TEXTURE_LIGHTING_MODE_HP 0x8167 +#define GL_TEXTURE_POST_SPECULAR_HP 0x8168 +#define GL_TEXTURE_PRE_SPECULAR_HP 0x8169 +#endif + +#ifndef GL_EXT_draw_range_elements +#define GL_MAX_ELEMENTS_VERTICES_EXT 0x80E8 +#define GL_MAX_ELEMENTS_INDICES_EXT 0x80E9 +#endif + +#ifndef GL_WIN_phong_shading +#define GL_PHONG_WIN 0x80EA +#define GL_PHONG_HINT_WIN 0x80EB +#endif + +#ifndef GL_WIN_specular_fog +#define GL_FOG_SPECULAR_TEXTURE_WIN 0x80EC +#endif + +#ifndef GL_EXT_light_texture +#define GL_FRAGMENT_MATERIAL_EXT 0x8349 +#define GL_FRAGMENT_NORMAL_EXT 0x834A +#define GL_FRAGMENT_COLOR_EXT 0x834C +#define GL_ATTENUATION_EXT 0x834D +#define GL_SHADOW_ATTENUATION_EXT 0x834E +#define GL_TEXTURE_APPLICATION_MODE_EXT 0x834F +#define GL_TEXTURE_LIGHT_EXT 0x8350 +#define GL_TEXTURE_MATERIAL_FACE_EXT 0x8351 +#define GL_TEXTURE_MATERIAL_PARAMETER_EXT 0x8352 +/* reuse GL_FRAGMENT_DEPTH_EXT */ +#endif + +#ifndef GL_SGIX_blend_alpha_minmax +#define GL_ALPHA_MIN_SGIX 0x8320 +#define GL_ALPHA_MAX_SGIX 0x8321 +#endif + +#ifndef GL_SGIX_impact_pixel_texture +#define GL_PIXEL_TEX_GEN_Q_CEILING_SGIX 0x8184 +#define GL_PIXEL_TEX_GEN_Q_ROUND_SGIX 0x8185 +#define GL_PIXEL_TEX_GEN_Q_FLOOR_SGIX 0x8186 +#define GL_PIXEL_TEX_GEN_ALPHA_REPLACE_SGIX 0x8187 +#define GL_PIXEL_TEX_GEN_ALPHA_NO_REPLACE_SGIX 0x8188 +#define GL_PIXEL_TEX_GEN_ALPHA_LS_SGIX 0x8189 +#define GL_PIXEL_TEX_GEN_ALPHA_MS_SGIX 0x818A +#endif + +#ifndef GL_EXT_bgra +#define GL_BGR_EXT 0x80E0 +#define GL_BGRA_EXT 0x80E1 +#endif + +#ifndef GL_SGIX_async +#define GL_ASYNC_MARKER_SGIX 0x8329 +#endif + +#ifndef GL_SGIX_async_pixel +#define GL_ASYNC_TEX_IMAGE_SGIX 0x835C +#define GL_ASYNC_DRAW_PIXELS_SGIX 0x835D +#define GL_ASYNC_READ_PIXELS_SGIX 0x835E +#define GL_MAX_ASYNC_TEX_IMAGE_SGIX 0x835F +#define GL_MAX_ASYNC_DRAW_PIXELS_SGIX 0x8360 +#define GL_MAX_ASYNC_READ_PIXELS_SGIX 0x8361 +#endif + +#ifndef GL_SGIX_async_histogram +#define GL_ASYNC_HISTOGRAM_SGIX 0x832C +#define GL_MAX_ASYNC_HISTOGRAM_SGIX 0x832D +#endif + +#ifndef GL_INTEL_texture_scissor +#endif + +#ifndef GL_INTEL_parallel_arrays +#define GL_PARALLEL_ARRAYS_INTEL 0x83F4 +#define GL_VERTEX_ARRAY_PARALLEL_POINTERS_INTEL 0x83F5 +#define GL_NORMAL_ARRAY_PARALLEL_POINTERS_INTEL 0x83F6 +#define GL_COLOR_ARRAY_PARALLEL_POINTERS_INTEL 0x83F7 +#define GL_TEXTURE_COORD_ARRAY_PARALLEL_POINTERS_INTEL 0x83F8 +#endif + +#ifndef GL_HP_occlusion_test +#define GL_OCCLUSION_TEST_HP 0x8165 +#define GL_OCCLUSION_TEST_RESULT_HP 0x8166 +#endif + +#ifndef GL_EXT_pixel_transform +#define GL_PIXEL_TRANSFORM_2D_EXT 0x8330 +#define GL_PIXEL_MAG_FILTER_EXT 0x8331 +#define GL_PIXEL_MIN_FILTER_EXT 0x8332 +#define GL_PIXEL_CUBIC_WEIGHT_EXT 0x8333 +#define GL_CUBIC_EXT 0x8334 +#define GL_AVERAGE_EXT 0x8335 +#define GL_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8336 +#define GL_MAX_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8337 +#define GL_PIXEL_TRANSFORM_2D_MATRIX_EXT 0x8338 +#endif + +#ifndef GL_EXT_pixel_transform_color_table +#endif + +#ifndef GL_EXT_shared_texture_palette +#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB +#endif + +#ifndef GL_EXT_separate_specular_color +#define GL_LIGHT_MODEL_COLOR_CONTROL_EXT 0x81F8 +#define GL_SINGLE_COLOR_EXT 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR_EXT 0x81FA +#endif + +#ifndef GL_EXT_secondary_color +#define GL_COLOR_SUM_EXT 0x8458 +#define GL_CURRENT_SECONDARY_COLOR_EXT 0x8459 +#define GL_SECONDARY_COLOR_ARRAY_SIZE_EXT 0x845A +#define GL_SECONDARY_COLOR_ARRAY_TYPE_EXT 0x845B +#define GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT 0x845C +#define GL_SECONDARY_COLOR_ARRAY_POINTER_EXT 0x845D +#define GL_SECONDARY_COLOR_ARRAY_EXT 0x845E +#endif + +#ifndef GL_EXT_texture_perturb_normal +#define GL_PERTURB_EXT 0x85AE +#define GL_TEXTURE_NORMAL_EXT 0x85AF +#endif + +#ifndef GL_EXT_multi_draw_arrays +#endif + +#ifndef GL_EXT_fog_coord +#define GL_FOG_COORDINATE_SOURCE_EXT 0x8450 +#define GL_FOG_COORDINATE_EXT 0x8451 +#define GL_FRAGMENT_DEPTH_EXT 0x8452 +#define GL_CURRENT_FOG_COORDINATE_EXT 0x8453 +#define GL_FOG_COORDINATE_ARRAY_TYPE_EXT 0x8454 +#define GL_FOG_COORDINATE_ARRAY_STRIDE_EXT 0x8455 +#define GL_FOG_COORDINATE_ARRAY_POINTER_EXT 0x8456 +#define GL_FOG_COORDINATE_ARRAY_EXT 0x8457 +#endif + +#ifndef GL_REND_screen_coordinates +#define GL_SCREEN_COORDINATES_REND 0x8490 +#define GL_INVERTED_SCREEN_W_REND 0x8491 +#endif + +#ifndef GL_EXT_coordinate_frame +#define GL_TANGENT_ARRAY_EXT 0x8439 +#define GL_BINORMAL_ARRAY_EXT 0x843A +#define GL_CURRENT_TANGENT_EXT 0x843B +#define GL_CURRENT_BINORMAL_EXT 0x843C +#define GL_TANGENT_ARRAY_TYPE_EXT 0x843E +#define GL_TANGENT_ARRAY_STRIDE_EXT 0x843F +#define GL_BINORMAL_ARRAY_TYPE_EXT 0x8440 +#define GL_BINORMAL_ARRAY_STRIDE_EXT 0x8441 +#define GL_TANGENT_ARRAY_POINTER_EXT 0x8442 +#define GL_BINORMAL_ARRAY_POINTER_EXT 0x8443 +#define GL_MAP1_TANGENT_EXT 0x8444 +#define GL_MAP2_TANGENT_EXT 0x8445 +#define GL_MAP1_BINORMAL_EXT 0x8446 +#define GL_MAP2_BINORMAL_EXT 0x8447 +#endif + +#ifndef GL_EXT_texture_env_combine +#define GL_COMBINE_EXT 0x8570 +#define GL_COMBINE_RGB_EXT 0x8571 +#define GL_COMBINE_ALPHA_EXT 0x8572 +#define GL_RGB_SCALE_EXT 0x8573 +#define GL_ADD_SIGNED_EXT 0x8574 +#define GL_INTERPOLATE_EXT 0x8575 +#define GL_CONSTANT_EXT 0x8576 +#define GL_PRIMARY_COLOR_EXT 0x8577 +#define GL_PREVIOUS_EXT 0x8578 +#define GL_SOURCE0_RGB_EXT 0x8580 +#define GL_SOURCE1_RGB_EXT 0x8581 +#define GL_SOURCE2_RGB_EXT 0x8582 +#define GL_SOURCE0_ALPHA_EXT 0x8588 +#define GL_SOURCE1_ALPHA_EXT 0x8589 +#define GL_SOURCE2_ALPHA_EXT 0x858A +#define GL_OPERAND0_RGB_EXT 0x8590 +#define GL_OPERAND1_RGB_EXT 0x8591 +#define GL_OPERAND2_RGB_EXT 0x8592 +#define GL_OPERAND0_ALPHA_EXT 0x8598 +#define GL_OPERAND1_ALPHA_EXT 0x8599 +#define GL_OPERAND2_ALPHA_EXT 0x859A +#endif + +#ifndef GL_APPLE_specular_vector +#define GL_LIGHT_MODEL_SPECULAR_VECTOR_APPLE 0x85B0 +#endif + +#ifndef GL_APPLE_transform_hint +#define GL_TRANSFORM_HINT_APPLE 0x85B1 +#endif + +#ifndef GL_SGIX_fog_scale +#define GL_FOG_SCALE_SGIX 0x81FC +#define GL_FOG_SCALE_VALUE_SGIX 0x81FD +#endif + +#ifndef GL_SUNX_constant_data +#define GL_UNPACK_CONSTANT_DATA_SUNX 0x81D5 +#define GL_TEXTURE_CONSTANT_DATA_SUNX 0x81D6 +#endif + +#ifndef GL_SUN_global_alpha +#define GL_GLOBAL_ALPHA_SUN 0x81D9 +#define GL_GLOBAL_ALPHA_FACTOR_SUN 0x81DA +#endif + +#ifndef GL_SUN_triangle_list +#define GL_RESTART_SUN 0x0001 +#define GL_REPLACE_MIDDLE_SUN 0x0002 +#define GL_REPLACE_OLDEST_SUN 0x0003 +#define GL_TRIANGLE_LIST_SUN 0x81D7 +#define GL_REPLACEMENT_CODE_SUN 0x81D8 +#define GL_REPLACEMENT_CODE_ARRAY_SUN 0x85C0 +#define GL_REPLACEMENT_CODE_ARRAY_TYPE_SUN 0x85C1 +#define GL_REPLACEMENT_CODE_ARRAY_STRIDE_SUN 0x85C2 +#define GL_REPLACEMENT_CODE_ARRAY_POINTER_SUN 0x85C3 +#define GL_R1UI_V3F_SUN 0x85C4 +#define GL_R1UI_C4UB_V3F_SUN 0x85C5 +#define GL_R1UI_C3F_V3F_SUN 0x85C6 +#define GL_R1UI_N3F_V3F_SUN 0x85C7 +#define GL_R1UI_C4F_N3F_V3F_SUN 0x85C8 +#define GL_R1UI_T2F_V3F_SUN 0x85C9 +#define GL_R1UI_T2F_N3F_V3F_SUN 0x85CA +#define GL_R1UI_T2F_C4F_N3F_V3F_SUN 0x85CB +#endif + +#ifndef GL_SUN_vertex +#endif + +#ifndef GL_EXT_blend_func_separate +#define GL_BLEND_DST_RGB_EXT 0x80C8 +#define GL_BLEND_SRC_RGB_EXT 0x80C9 +#define GL_BLEND_DST_ALPHA_EXT 0x80CA +#define GL_BLEND_SRC_ALPHA_EXT 0x80CB +#endif + +#ifndef GL_INGR_color_clamp +#define GL_RED_MIN_CLAMP_INGR 0x8560 +#define GL_GREEN_MIN_CLAMP_INGR 0x8561 +#define GL_BLUE_MIN_CLAMP_INGR 0x8562 +#define GL_ALPHA_MIN_CLAMP_INGR 0x8563 +#define GL_RED_MAX_CLAMP_INGR 0x8564 +#define GL_GREEN_MAX_CLAMP_INGR 0x8565 +#define GL_BLUE_MAX_CLAMP_INGR 0x8566 +#define GL_ALPHA_MAX_CLAMP_INGR 0x8567 +#endif + +#ifndef GL_INGR_interlace_read +#define GL_INTERLACE_READ_INGR 0x8568 +#endif + +#ifndef GL_EXT_stencil_wrap +#define GL_INCR_WRAP_EXT 0x8507 +#define GL_DECR_WRAP_EXT 0x8508 +#endif + +#ifndef GL_EXT_422_pixels +#define GL_422_EXT 0x80CC +#define GL_422_REV_EXT 0x80CD +#define GL_422_AVERAGE_EXT 0x80CE +#define GL_422_REV_AVERAGE_EXT 0x80CF +#endif + +#ifndef GL_NV_texgen_reflection +#define GL_NORMAL_MAP_NV 0x8511 +#define GL_REFLECTION_MAP_NV 0x8512 +#endif + +#ifndef GL_EXT_texture_cube_map +#define GL_NORMAL_MAP_EXT 0x8511 +#define GL_REFLECTION_MAP_EXT 0x8512 +#define GL_TEXTURE_CUBE_MAP_EXT 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_EXT 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP_EXT 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_EXT 0x851C +#endif + +#ifndef GL_SUN_convolution_border_modes +#define GL_WRAP_BORDER_SUN 0x81D4 +#endif + +#ifndef GL_EXT_texture_env_add +#endif + +#ifndef GL_EXT_texture_lod_bias +#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD +#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500 +#define GL_TEXTURE_LOD_BIAS_EXT 0x8501 +#endif + +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF +#endif + +#ifndef GL_EXT_vertex_weighting +#define GL_MODELVIEW0_STACK_DEPTH_EXT GL_MODELVIEW_STACK_DEPTH +#define GL_MODELVIEW1_STACK_DEPTH_EXT 0x8502 +#define GL_MODELVIEW0_MATRIX_EXT GL_MODELVIEW_MATRIX +#define GL_MODELVIEW1_MATRIX_EXT 0x8506 +#define GL_VERTEX_WEIGHTING_EXT 0x8509 +#define GL_MODELVIEW0_EXT GL_MODELVIEW +#define GL_MODELVIEW1_EXT 0x850A +#define GL_CURRENT_VERTEX_WEIGHT_EXT 0x850B +#define GL_VERTEX_WEIGHT_ARRAY_EXT 0x850C +#define GL_VERTEX_WEIGHT_ARRAY_SIZE_EXT 0x850D +#define GL_VERTEX_WEIGHT_ARRAY_TYPE_EXT 0x850E +#define GL_VERTEX_WEIGHT_ARRAY_STRIDE_EXT 0x850F +#define GL_VERTEX_WEIGHT_ARRAY_POINTER_EXT 0x8510 +#endif + +#ifndef GL_NV_light_max_exponent +#define GL_MAX_SHININESS_NV 0x8504 +#define GL_MAX_SPOT_EXPONENT_NV 0x8505 +#endif + +#ifndef GL_NV_vertex_array_range +#define GL_VERTEX_ARRAY_RANGE_NV 0x851D +#define GL_VERTEX_ARRAY_RANGE_LENGTH_NV 0x851E +#define GL_VERTEX_ARRAY_RANGE_VALID_NV 0x851F +#define GL_MAX_VERTEX_ARRAY_RANGE_ELEMENT_NV 0x8520 +#define GL_VERTEX_ARRAY_RANGE_POINTER_NV 0x8521 +#endif + +#ifndef GL_NV_register_combiners +#define GL_REGISTER_COMBINERS_NV 0x8522 +#define GL_VARIABLE_A_NV 0x8523 +#define GL_VARIABLE_B_NV 0x8524 +#define GL_VARIABLE_C_NV 0x8525 +#define GL_VARIABLE_D_NV 0x8526 +#define GL_VARIABLE_E_NV 0x8527 +#define GL_VARIABLE_F_NV 0x8528 +#define GL_VARIABLE_G_NV 0x8529 +#define GL_CONSTANT_COLOR0_NV 0x852A +#define GL_CONSTANT_COLOR1_NV 0x852B +#define GL_PRIMARY_COLOR_NV 0x852C +#define GL_SECONDARY_COLOR_NV 0x852D +#define GL_SPARE0_NV 0x852E +#define GL_SPARE1_NV 0x852F +#define GL_DISCARD_NV 0x8530 +#define GL_E_TIMES_F_NV 0x8531 +#define GL_SPARE0_PLUS_SECONDARY_COLOR_NV 0x8532 +#define GL_UNSIGNED_IDENTITY_NV 0x8536 +#define GL_UNSIGNED_INVERT_NV 0x8537 +#define GL_EXPAND_NORMAL_NV 0x8538 +#define GL_EXPAND_NEGATE_NV 0x8539 +#define GL_HALF_BIAS_NORMAL_NV 0x853A +#define GL_HALF_BIAS_NEGATE_NV 0x853B +#define GL_SIGNED_IDENTITY_NV 0x853C +#define GL_SIGNED_NEGATE_NV 0x853D +#define GL_SCALE_BY_TWO_NV 0x853E +#define GL_SCALE_BY_FOUR_NV 0x853F +#define GL_SCALE_BY_ONE_HALF_NV 0x8540 +#define GL_BIAS_BY_NEGATIVE_ONE_HALF_NV 0x8541 +#define GL_COMBINER_INPUT_NV 0x8542 +#define GL_COMBINER_MAPPING_NV 0x8543 +#define GL_COMBINER_COMPONENT_USAGE_NV 0x8544 +#define GL_COMBINER_AB_DOT_PRODUCT_NV 0x8545 +#define GL_COMBINER_CD_DOT_PRODUCT_NV 0x8546 +#define GL_COMBINER_MUX_SUM_NV 0x8547 +#define GL_COMBINER_SCALE_NV 0x8548 +#define GL_COMBINER_BIAS_NV 0x8549 +#define GL_COMBINER_AB_OUTPUT_NV 0x854A +#define GL_COMBINER_CD_OUTPUT_NV 0x854B +#define GL_COMBINER_SUM_OUTPUT_NV 0x854C +#define GL_MAX_GENERAL_COMBINERS_NV 0x854D +#define GL_NUM_GENERAL_COMBINERS_NV 0x854E +#define GL_COLOR_SUM_CLAMP_NV 0x854F +#define GL_COMBINER0_NV 0x8550 +#define GL_COMBINER1_NV 0x8551 +#define GL_COMBINER2_NV 0x8552 +#define GL_COMBINER3_NV 0x8553 +#define GL_COMBINER4_NV 0x8554 +#define GL_COMBINER5_NV 0x8555 +#define GL_COMBINER6_NV 0x8556 +#define GL_COMBINER7_NV 0x8557 +/* reuse GL_TEXTURE0_ARB */ +/* reuse GL_TEXTURE1_ARB */ +/* reuse GL_ZERO */ +/* reuse GL_NONE */ +/* reuse GL_FOG */ +#endif + +#ifndef GL_NV_fog_distance +#define GL_FOG_DISTANCE_MODE_NV 0x855A +#define GL_EYE_RADIAL_NV 0x855B +#define GL_EYE_PLANE_ABSOLUTE_NV 0x855C +/* reuse GL_EYE_PLANE */ +#endif + +#ifndef GL_NV_texgen_emboss +#define GL_EMBOSS_LIGHT_NV 0x855D +#define GL_EMBOSS_CONSTANT_NV 0x855E +#define GL_EMBOSS_MAP_NV 0x855F +#endif + +#ifndef GL_NV_blend_square +#endif + +#ifndef GL_NV_texture_env_combine4 +#define GL_COMBINE4_NV 0x8503 +#define GL_SOURCE3_RGB_NV 0x8583 +#define GL_SOURCE3_ALPHA_NV 0x858B +#define GL_OPERAND3_RGB_NV 0x8593 +#define GL_OPERAND3_ALPHA_NV 0x859B +#endif + +#ifndef GL_MESA_resize_buffers +#endif + +#ifndef GL_MESA_window_pos +#endif + +#ifndef GL_EXT_texture_compression_s3tc +#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 +#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 +#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 +#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 +#endif + +#ifndef GL_IBM_cull_vertex +#define GL_CULL_VERTEX_IBM 103050 +#endif + +#ifndef GL_IBM_multimode_draw_arrays +#endif + +#ifndef GL_IBM_vertex_array_lists +#define GL_VERTEX_ARRAY_LIST_IBM 103070 +#define GL_NORMAL_ARRAY_LIST_IBM 103071 +#define GL_COLOR_ARRAY_LIST_IBM 103072 +#define GL_INDEX_ARRAY_LIST_IBM 103073 +#define GL_TEXTURE_COORD_ARRAY_LIST_IBM 103074 +#define GL_EDGE_FLAG_ARRAY_LIST_IBM 103075 +#define GL_FOG_COORDINATE_ARRAY_LIST_IBM 103076 +#define GL_SECONDARY_COLOR_ARRAY_LIST_IBM 103077 +#define GL_VERTEX_ARRAY_LIST_STRIDE_IBM 103080 +#define GL_NORMAL_ARRAY_LIST_STRIDE_IBM 103081 +#define GL_COLOR_ARRAY_LIST_STRIDE_IBM 103082 +#define GL_INDEX_ARRAY_LIST_STRIDE_IBM 103083 +#define GL_TEXTURE_COORD_ARRAY_LIST_STRIDE_IBM 103084 +#define GL_EDGE_FLAG_ARRAY_LIST_STRIDE_IBM 103085 +#define GL_FOG_COORDINATE_ARRAY_LIST_STRIDE_IBM 103086 +#define GL_SECONDARY_COLOR_ARRAY_LIST_STRIDE_IBM 103087 +#endif + +#ifndef GL_SGIX_subsample +#define GL_PACK_SUBSAMPLE_RATE_SGIX 0x85A0 +#define GL_UNPACK_SUBSAMPLE_RATE_SGIX 0x85A1 +#define GL_PIXEL_SUBSAMPLE_4444_SGIX 0x85A2 +#define GL_PIXEL_SUBSAMPLE_2424_SGIX 0x85A3 +#define GL_PIXEL_SUBSAMPLE_4242_SGIX 0x85A4 +#endif + +#ifndef GL_SGIX_ycrcb_subsample +#endif + +#ifndef GL_SGIX_ycrcba +#define GL_YCRCB_SGIX 0x8318 +#define GL_YCRCBA_SGIX 0x8319 +#endif + +#ifndef GL_SGI_depth_pass_instrument +#define GL_DEPTH_PASS_INSTRUMENT_SGIX 0x8310 +#define GL_DEPTH_PASS_INSTRUMENT_COUNTERS_SGIX 0x8311 +#define GL_DEPTH_PASS_INSTRUMENT_MAX_SGIX 0x8312 +#endif + +#ifndef GL_3DFX_texture_compression_FXT1 +#define GL_COMPRESSED_RGB_FXT1_3DFX 0x86B0 +#define GL_COMPRESSED_RGBA_FXT1_3DFX 0x86B1 +#endif + +#ifndef GL_3DFX_multisample +#define GL_MULTISAMPLE_3DFX 0x86B2 +#define GL_SAMPLE_BUFFERS_3DFX 0x86B3 +#define GL_SAMPLES_3DFX 0x86B4 +#define GL_MULTISAMPLE_BIT_3DFX 0x20000000 +#endif + +#ifndef GL_3DFX_tbuffer +#endif + +#ifndef GL_EXT_multisample +#define GL_MULTISAMPLE_EXT 0x809D +#define GL_SAMPLE_ALPHA_TO_MASK_EXT 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_EXT 0x809F +#define GL_SAMPLE_MASK_EXT 0x80A0 +#define GL_1PASS_EXT 0x80A1 +#define GL_2PASS_0_EXT 0x80A2 +#define GL_2PASS_1_EXT 0x80A3 +#define GL_4PASS_0_EXT 0x80A4 +#define GL_4PASS_1_EXT 0x80A5 +#define GL_4PASS_2_EXT 0x80A6 +#define GL_4PASS_3_EXT 0x80A7 +#define GL_SAMPLE_BUFFERS_EXT 0x80A8 +#define GL_SAMPLES_EXT 0x80A9 +#define GL_SAMPLE_MASK_VALUE_EXT 0x80AA +#define GL_SAMPLE_MASK_INVERT_EXT 0x80AB +#define GL_SAMPLE_PATTERN_EXT 0x80AC +#define GL_MULTISAMPLE_BIT_EXT 0x20000000 +#endif + +#ifndef GL_SGIX_vertex_preclip +#define GL_VERTEX_PRECLIP_SGIX 0x83EE +#define GL_VERTEX_PRECLIP_HINT_SGIX 0x83EF +#endif + +#ifndef GL_SGIX_convolution_accuracy +#define GL_CONVOLUTION_HINT_SGIX 0x8316 +#endif + +#ifndef GL_SGIX_resample +#define GL_PACK_RESAMPLE_SGIX 0x842C +#define GL_UNPACK_RESAMPLE_SGIX 0x842D +#define GL_RESAMPLE_REPLICATE_SGIX 0x842E +#define GL_RESAMPLE_ZERO_FILL_SGIX 0x842F +#define GL_RESAMPLE_DECIMATE_SGIX 0x8430 +#endif + +#ifndef GL_SGIS_point_line_texgen +#define GL_EYE_DISTANCE_TO_POINT_SGIS 0x81F0 +#define GL_OBJECT_DISTANCE_TO_POINT_SGIS 0x81F1 +#define GL_EYE_DISTANCE_TO_LINE_SGIS 0x81F2 +#define GL_OBJECT_DISTANCE_TO_LINE_SGIS 0x81F3 +#define GL_EYE_POINT_SGIS 0x81F4 +#define GL_OBJECT_POINT_SGIS 0x81F5 +#define GL_EYE_LINE_SGIS 0x81F6 +#define GL_OBJECT_LINE_SGIS 0x81F7 +#endif + +#ifndef GL_SGIS_texture_color_mask +#define GL_TEXTURE_COLOR_WRITEMASK_SGIS 0x81EF +#endif + +#ifndef GL_EXT_texture_env_dot3 +#define GL_DOT3_RGB_EXT 0x8740 +#define GL_DOT3_RGBA_EXT 0x8741 +#endif + +#ifndef GL_ATI_texture_mirror_once +#define GL_MIRROR_CLAMP_ATI 0x8742 +#define GL_MIRROR_CLAMP_TO_EDGE_ATI 0x8743 +#endif + +#ifndef GL_NV_fence +#define GL_ALL_COMPLETED_NV 0x84F2 +#define GL_FENCE_STATUS_NV 0x84F3 +#define GL_FENCE_CONDITION_NV 0x84F4 +#endif + +#ifndef GL_IBM_texture_mirrored_repeat +#define GL_MIRRORED_REPEAT_IBM 0x8370 +#endif + +#ifndef GL_NV_evaluators +#define GL_EVAL_2D_NV 0x86C0 +#define GL_EVAL_TRIANGULAR_2D_NV 0x86C1 +#define GL_MAP_TESSELLATION_NV 0x86C2 +#define GL_MAP_ATTRIB_U_ORDER_NV 0x86C3 +#define GL_MAP_ATTRIB_V_ORDER_NV 0x86C4 +#define GL_EVAL_FRACTIONAL_TESSELLATION_NV 0x86C5 +#define GL_EVAL_VERTEX_ATTRIB0_NV 0x86C6 +#define GL_EVAL_VERTEX_ATTRIB1_NV 0x86C7 +#define GL_EVAL_VERTEX_ATTRIB2_NV 0x86C8 +#define GL_EVAL_VERTEX_ATTRIB3_NV 0x86C9 +#define GL_EVAL_VERTEX_ATTRIB4_NV 0x86CA +#define GL_EVAL_VERTEX_ATTRIB5_NV 0x86CB +#define GL_EVAL_VERTEX_ATTRIB6_NV 0x86CC +#define GL_EVAL_VERTEX_ATTRIB7_NV 0x86CD +#define GL_EVAL_VERTEX_ATTRIB8_NV 0x86CE +#define GL_EVAL_VERTEX_ATTRIB9_NV 0x86CF +#define GL_EVAL_VERTEX_ATTRIB10_NV 0x86D0 +#define GL_EVAL_VERTEX_ATTRIB11_NV 0x86D1 +#define GL_EVAL_VERTEX_ATTRIB12_NV 0x86D2 +#define GL_EVAL_VERTEX_ATTRIB13_NV 0x86D3 +#define GL_EVAL_VERTEX_ATTRIB14_NV 0x86D4 +#define GL_EVAL_VERTEX_ATTRIB15_NV 0x86D5 +#define GL_MAX_MAP_TESSELLATION_NV 0x86D6 +#define GL_MAX_RATIONAL_EVAL_ORDER_NV 0x86D7 +#endif + +#ifndef GL_NV_packed_depth_stencil +#define GL_DEPTH_STENCIL_NV 0x84F9 +#define GL_UNSIGNED_INT_24_8_NV 0x84FA +#endif + +#ifndef GL_NV_register_combiners2 +#define GL_PER_STAGE_CONSTANTS_NV 0x8535 +#endif + +#ifndef GL_NV_texture_compression_vtc +#endif + +#ifndef GL_NV_texture_rectangle +#define GL_TEXTURE_RECTANGLE_NV 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE_NV 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE_NV 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8 +#endif + +#ifndef GL_NV_texture_shader +#define GL_OFFSET_TEXTURE_RECTANGLE_NV 0x864C +#define GL_OFFSET_TEXTURE_RECTANGLE_SCALE_NV 0x864D +#define GL_DOT_PRODUCT_TEXTURE_RECTANGLE_NV 0x864E +#define GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV 0x86D9 +#define GL_UNSIGNED_INT_S8_S8_8_8_NV 0x86DA +#define GL_UNSIGNED_INT_8_8_S8_S8_REV_NV 0x86DB +#define GL_DSDT_MAG_INTENSITY_NV 0x86DC +#define GL_SHADER_CONSISTENT_NV 0x86DD +#define GL_TEXTURE_SHADER_NV 0x86DE +#define GL_SHADER_OPERATION_NV 0x86DF +#define GL_CULL_MODES_NV 0x86E0 +#define GL_OFFSET_TEXTURE_MATRIX_NV 0x86E1 +#define GL_OFFSET_TEXTURE_SCALE_NV 0x86E2 +#define GL_OFFSET_TEXTURE_BIAS_NV 0x86E3 +#define GL_OFFSET_TEXTURE_2D_MATRIX_NV GL_OFFSET_TEXTURE_MATRIX_NV +#define GL_OFFSET_TEXTURE_2D_SCALE_NV GL_OFFSET_TEXTURE_SCALE_NV +#define GL_OFFSET_TEXTURE_2D_BIAS_NV GL_OFFSET_TEXTURE_BIAS_NV +#define GL_PREVIOUS_TEXTURE_INPUT_NV 0x86E4 +#define GL_CONST_EYE_NV 0x86E5 +#define GL_PASS_THROUGH_NV 0x86E6 +#define GL_CULL_FRAGMENT_NV 0x86E7 +#define GL_OFFSET_TEXTURE_2D_NV 0x86E8 +#define GL_DEPENDENT_AR_TEXTURE_2D_NV 0x86E9 +#define GL_DEPENDENT_GB_TEXTURE_2D_NV 0x86EA +#define GL_DOT_PRODUCT_NV 0x86EC +#define GL_DOT_PRODUCT_DEPTH_REPLACE_NV 0x86ED +#define GL_DOT_PRODUCT_TEXTURE_2D_NV 0x86EE +#define GL_DOT_PRODUCT_TEXTURE_CUBE_MAP_NV 0x86F0 +#define GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV 0x86F1 +#define GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV 0x86F2 +#define GL_DOT_PRODUCT_CONST_EYE_REFLECT_CUBE_MAP_NV 0x86F3 +#define GL_HILO_NV 0x86F4 +#define GL_DSDT_NV 0x86F5 +#define GL_DSDT_MAG_NV 0x86F6 +#define GL_DSDT_MAG_VIB_NV 0x86F7 +#define GL_HILO16_NV 0x86F8 +#define GL_SIGNED_HILO_NV 0x86F9 +#define GL_SIGNED_HILO16_NV 0x86FA +#define GL_SIGNED_RGBA_NV 0x86FB +#define GL_SIGNED_RGBA8_NV 0x86FC +#define GL_SIGNED_RGB_NV 0x86FE +#define GL_SIGNED_RGB8_NV 0x86FF +#define GL_SIGNED_LUMINANCE_NV 0x8701 +#define GL_SIGNED_LUMINANCE8_NV 0x8702 +#define GL_SIGNED_LUMINANCE_ALPHA_NV 0x8703 +#define GL_SIGNED_LUMINANCE8_ALPHA8_NV 0x8704 +#define GL_SIGNED_ALPHA_NV 0x8705 +#define GL_SIGNED_ALPHA8_NV 0x8706 +#define GL_SIGNED_INTENSITY_NV 0x8707 +#define GL_SIGNED_INTENSITY8_NV 0x8708 +#define GL_DSDT8_NV 0x8709 +#define GL_DSDT8_MAG8_NV 0x870A +#define GL_DSDT8_MAG8_INTENSITY8_NV 0x870B +#define GL_SIGNED_RGB_UNSIGNED_ALPHA_NV 0x870C +#define GL_SIGNED_RGB8_UNSIGNED_ALPHA8_NV 0x870D +#define GL_HI_SCALE_NV 0x870E +#define GL_LO_SCALE_NV 0x870F +#define GL_DS_SCALE_NV 0x8710 +#define GL_DT_SCALE_NV 0x8711 +#define GL_MAGNITUDE_SCALE_NV 0x8712 +#define GL_VIBRANCE_SCALE_NV 0x8713 +#define GL_HI_BIAS_NV 0x8714 +#define GL_LO_BIAS_NV 0x8715 +#define GL_DS_BIAS_NV 0x8716 +#define GL_DT_BIAS_NV 0x8717 +#define GL_MAGNITUDE_BIAS_NV 0x8718 +#define GL_VIBRANCE_BIAS_NV 0x8719 +#define GL_TEXTURE_BORDER_VALUES_NV 0x871A +#define GL_TEXTURE_HI_SIZE_NV 0x871B +#define GL_TEXTURE_LO_SIZE_NV 0x871C +#define GL_TEXTURE_DS_SIZE_NV 0x871D +#define GL_TEXTURE_DT_SIZE_NV 0x871E +#define GL_TEXTURE_MAG_SIZE_NV 0x871F +#endif + +#ifndef GL_NV_texture_shader2 +#define GL_DOT_PRODUCT_TEXTURE_3D_NV 0x86EF +#endif + +#ifndef GL_NV_vertex_array_range2 +#define GL_VERTEX_ARRAY_RANGE_WITHOUT_FLUSH_NV 0x8533 +#endif + +#ifndef GL_NV_vertex_program +#define GL_VERTEX_PROGRAM_NV 0x8620 +#define GL_VERTEX_STATE_PROGRAM_NV 0x8621 +#define GL_ATTRIB_ARRAY_SIZE_NV 0x8623 +#define GL_ATTRIB_ARRAY_STRIDE_NV 0x8624 +#define GL_ATTRIB_ARRAY_TYPE_NV 0x8625 +#define GL_CURRENT_ATTRIB_NV 0x8626 +#define GL_PROGRAM_LENGTH_NV 0x8627 +#define GL_PROGRAM_STRING_NV 0x8628 +#define GL_MODELVIEW_PROJECTION_NV 0x8629 +#define GL_IDENTITY_NV 0x862A +#define GL_INVERSE_NV 0x862B +#define GL_TRANSPOSE_NV 0x862C +#define GL_INVERSE_TRANSPOSE_NV 0x862D +#define GL_MAX_TRACK_MATRIX_STACK_DEPTH_NV 0x862E +#define GL_MAX_TRACK_MATRICES_NV 0x862F +#define GL_MATRIX0_NV 0x8630 +#define GL_MATRIX1_NV 0x8631 +#define GL_MATRIX2_NV 0x8632 +#define GL_MATRIX3_NV 0x8633 +#define GL_MATRIX4_NV 0x8634 +#define GL_MATRIX5_NV 0x8635 +#define GL_MATRIX6_NV 0x8636 +#define GL_MATRIX7_NV 0x8637 +#define GL_CURRENT_MATRIX_STACK_DEPTH_NV 0x8640 +#define GL_CURRENT_MATRIX_NV 0x8641 +#define GL_VERTEX_PROGRAM_POINT_SIZE_NV 0x8642 +#define GL_VERTEX_PROGRAM_TWO_SIDE_NV 0x8643 +#define GL_PROGRAM_PARAMETER_NV 0x8644 +#define GL_ATTRIB_ARRAY_POINTER_NV 0x8645 +#define GL_PROGRAM_TARGET_NV 0x8646 +#define GL_PROGRAM_RESIDENT_NV 0x8647 +#define GL_TRACK_MATRIX_NV 0x8648 +#define GL_TRACK_MATRIX_TRANSFORM_NV 0x8649 +#define GL_VERTEX_PROGRAM_BINDING_NV 0x864A +#define GL_PROGRAM_ERROR_POSITION_NV 0x864B +#define GL_VERTEX_ATTRIB_ARRAY0_NV 0x8650 +#define GL_VERTEX_ATTRIB_ARRAY1_NV 0x8651 +#define GL_VERTEX_ATTRIB_ARRAY2_NV 0x8652 +#define GL_VERTEX_ATTRIB_ARRAY3_NV 0x8653 +#define GL_VERTEX_ATTRIB_ARRAY4_NV 0x8654 +#define GL_VERTEX_ATTRIB_ARRAY5_NV 0x8655 +#define GL_VERTEX_ATTRIB_ARRAY6_NV 0x8656 +#define GL_VERTEX_ATTRIB_ARRAY7_NV 0x8657 +#define GL_VERTEX_ATTRIB_ARRAY8_NV 0x8658 +#define GL_VERTEX_ATTRIB_ARRAY9_NV 0x8659 +#define GL_VERTEX_ATTRIB_ARRAY10_NV 0x865A +#define GL_VERTEX_ATTRIB_ARRAY11_NV 0x865B +#define GL_VERTEX_ATTRIB_ARRAY12_NV 0x865C +#define GL_VERTEX_ATTRIB_ARRAY13_NV 0x865D +#define GL_VERTEX_ATTRIB_ARRAY14_NV 0x865E +#define GL_VERTEX_ATTRIB_ARRAY15_NV 0x865F +#define GL_MAP1_VERTEX_ATTRIB0_4_NV 0x8660 +#define GL_MAP1_VERTEX_ATTRIB1_4_NV 0x8661 +#define GL_MAP1_VERTEX_ATTRIB2_4_NV 0x8662 +#define GL_MAP1_VERTEX_ATTRIB3_4_NV 0x8663 +#define GL_MAP1_VERTEX_ATTRIB4_4_NV 0x8664 +#define GL_MAP1_VERTEX_ATTRIB5_4_NV 0x8665 +#define GL_MAP1_VERTEX_ATTRIB6_4_NV 0x8666 +#define GL_MAP1_VERTEX_ATTRIB7_4_NV 0x8667 +#define GL_MAP1_VERTEX_ATTRIB8_4_NV 0x8668 +#define GL_MAP1_VERTEX_ATTRIB9_4_NV 0x8669 +#define GL_MAP1_VERTEX_ATTRIB10_4_NV 0x866A +#define GL_MAP1_VERTEX_ATTRIB11_4_NV 0x866B +#define GL_MAP1_VERTEX_ATTRIB12_4_NV 0x866C +#define GL_MAP1_VERTEX_ATTRIB13_4_NV 0x866D +#define GL_MAP1_VERTEX_ATTRIB14_4_NV 0x866E +#define GL_MAP1_VERTEX_ATTRIB15_4_NV 0x866F +#define GL_MAP2_VERTEX_ATTRIB0_4_NV 0x8670 +#define GL_MAP2_VERTEX_ATTRIB1_4_NV 0x8671 +#define GL_MAP2_VERTEX_ATTRIB2_4_NV 0x8672 +#define GL_MAP2_VERTEX_ATTRIB3_4_NV 0x8673 +#define GL_MAP2_VERTEX_ATTRIB4_4_NV 0x8674 +#define GL_MAP2_VERTEX_ATTRIB5_4_NV 0x8675 +#define GL_MAP2_VERTEX_ATTRIB6_4_NV 0x8676 +#define GL_MAP2_VERTEX_ATTRIB7_4_NV 0x8677 +#define GL_MAP2_VERTEX_ATTRIB8_4_NV 0x8678 +#define GL_MAP2_VERTEX_ATTRIB9_4_NV 0x8679 +#define GL_MAP2_VERTEX_ATTRIB10_4_NV 0x867A +#define GL_MAP2_VERTEX_ATTRIB11_4_NV 0x867B +#define GL_MAP2_VERTEX_ATTRIB12_4_NV 0x867C +#define GL_MAP2_VERTEX_ATTRIB13_4_NV 0x867D +#define GL_MAP2_VERTEX_ATTRIB14_4_NV 0x867E +#define GL_MAP2_VERTEX_ATTRIB15_4_NV 0x867F +#endif + +#ifndef GL_SGIX_texture_coordinate_clamp +#define GL_TEXTURE_MAX_CLAMP_S_SGIX 0x8369 +#define GL_TEXTURE_MAX_CLAMP_T_SGIX 0x836A +#define GL_TEXTURE_MAX_CLAMP_R_SGIX 0x836B +#endif + +#ifndef GL_SGIX_scalebias_hint +#define GL_SCALEBIAS_HINT_SGIX 0x8322 +#endif + +#ifndef GL_OML_interlace +#define GL_INTERLACE_OML 0x8980 +#define GL_INTERLACE_READ_OML 0x8981 +#endif + +#ifndef GL_OML_subsample +#define GL_FORMAT_SUBSAMPLE_24_24_OML 0x8982 +#define GL_FORMAT_SUBSAMPLE_244_244_OML 0x8983 +#endif + +#ifndef GL_OML_resample +#define GL_PACK_RESAMPLE_OML 0x8984 +#define GL_UNPACK_RESAMPLE_OML 0x8985 +#define GL_RESAMPLE_REPLICATE_OML 0x8986 +#define GL_RESAMPLE_ZERO_FILL_OML 0x8987 +#define GL_RESAMPLE_AVERAGE_OML 0x8988 +#define GL_RESAMPLE_DECIMATE_OML 0x8989 +#endif + +#ifndef GL_NV_copy_depth_to_color +#define GL_DEPTH_STENCIL_TO_RGBA_NV 0x886E +#define GL_DEPTH_STENCIL_TO_BGRA_NV 0x886F +#endif + +#ifndef GL_ATI_envmap_bumpmap +#define GL_BUMP_ROT_MATRIX_ATI 0x8775 +#define GL_BUMP_ROT_MATRIX_SIZE_ATI 0x8776 +#define GL_BUMP_NUM_TEX_UNITS_ATI 0x8777 +#define GL_BUMP_TEX_UNITS_ATI 0x8778 +#define GL_DUDV_ATI 0x8779 +#define GL_DU8DV8_ATI 0x877A +#define GL_BUMP_ENVMAP_ATI 0x877B +#define GL_BUMP_TARGET_ATI 0x877C +#endif + +#ifndef GL_ATI_fragment_shader +#define GL_FRAGMENT_SHADER_ATI 0x8920 +#define GL_REG_0_ATI 0x8921 +#define GL_REG_1_ATI 0x8922 +#define GL_REG_2_ATI 0x8923 +#define GL_REG_3_ATI 0x8924 +#define GL_REG_4_ATI 0x8925 +#define GL_REG_5_ATI 0x8926 +#define GL_REG_6_ATI 0x8927 +#define GL_REG_7_ATI 0x8928 +#define GL_REG_8_ATI 0x8929 +#define GL_REG_9_ATI 0x892A +#define GL_REG_10_ATI 0x892B +#define GL_REG_11_ATI 0x892C +#define GL_REG_12_ATI 0x892D +#define GL_REG_13_ATI 0x892E +#define GL_REG_14_ATI 0x892F +#define GL_REG_15_ATI 0x8930 +#define GL_REG_16_ATI 0x8931 +#define GL_REG_17_ATI 0x8932 +#define GL_REG_18_ATI 0x8933 +#define GL_REG_19_ATI 0x8934 +#define GL_REG_20_ATI 0x8935 +#define GL_REG_21_ATI 0x8936 +#define GL_REG_22_ATI 0x8937 +#define GL_REG_23_ATI 0x8938 +#define GL_REG_24_ATI 0x8939 +#define GL_REG_25_ATI 0x893A +#define GL_REG_26_ATI 0x893B +#define GL_REG_27_ATI 0x893C +#define GL_REG_28_ATI 0x893D +#define GL_REG_29_ATI 0x893E +#define GL_REG_30_ATI 0x893F +#define GL_REG_31_ATI 0x8940 +#define GL_CON_0_ATI 0x8941 +#define GL_CON_1_ATI 0x8942 +#define GL_CON_2_ATI 0x8943 +#define GL_CON_3_ATI 0x8944 +#define GL_CON_4_ATI 0x8945 +#define GL_CON_5_ATI 0x8946 +#define GL_CON_6_ATI 0x8947 +#define GL_CON_7_ATI 0x8948 +#define GL_CON_8_ATI 0x8949 +#define GL_CON_9_ATI 0x894A +#define GL_CON_10_ATI 0x894B +#define GL_CON_11_ATI 0x894C +#define GL_CON_12_ATI 0x894D +#define GL_CON_13_ATI 0x894E +#define GL_CON_14_ATI 0x894F +#define GL_CON_15_ATI 0x8950 +#define GL_CON_16_ATI 0x8951 +#define GL_CON_17_ATI 0x8952 +#define GL_CON_18_ATI 0x8953 +#define GL_CON_19_ATI 0x8954 +#define GL_CON_20_ATI 0x8955 +#define GL_CON_21_ATI 0x8956 +#define GL_CON_22_ATI 0x8957 +#define GL_CON_23_ATI 0x8958 +#define GL_CON_24_ATI 0x8959 +#define GL_CON_25_ATI 0x895A +#define GL_CON_26_ATI 0x895B +#define GL_CON_27_ATI 0x895C +#define GL_CON_28_ATI 0x895D +#define GL_CON_29_ATI 0x895E +#define GL_CON_30_ATI 0x895F +#define GL_CON_31_ATI 0x8960 +#define GL_MOV_ATI 0x8961 +#define GL_ADD_ATI 0x8963 +#define GL_MUL_ATI 0x8964 +#define GL_SUB_ATI 0x8965 +#define GL_DOT3_ATI 0x8966 +#define GL_DOT4_ATI 0x8967 +#define GL_MAD_ATI 0x8968 +#define GL_LERP_ATI 0x8969 +#define GL_CND_ATI 0x896A +#define GL_CND0_ATI 0x896B +#define GL_DOT2_ADD_ATI 0x896C +#define GL_SECONDARY_INTERPOLATOR_ATI 0x896D +#define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E +#define GL_NUM_FRAGMENT_CONSTANTS_ATI 0x896F +#define GL_NUM_PASSES_ATI 0x8970 +#define GL_NUM_INSTRUCTIONS_PER_PASS_ATI 0x8971 +#define GL_NUM_INSTRUCTIONS_TOTAL_ATI 0x8972 +#define GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI 0x8973 +#define GL_NUM_LOOPBACK_COMPONENTS_ATI 0x8974 +#define GL_COLOR_ALPHA_PAIRING_ATI 0x8975 +#define GL_SWIZZLE_STR_ATI 0x8976 +#define GL_SWIZZLE_STQ_ATI 0x8977 +#define GL_SWIZZLE_STR_DR_ATI 0x8978 +#define GL_SWIZZLE_STQ_DQ_ATI 0x8979 +#define GL_SWIZZLE_STRQ_ATI 0x897A +#define GL_SWIZZLE_STRQ_DQ_ATI 0x897B +#define GL_RED_BIT_ATI 0x00000001 +#define GL_GREEN_BIT_ATI 0x00000002 +#define GL_BLUE_BIT_ATI 0x00000004 +#define GL_2X_BIT_ATI 0x00000001 +#define GL_4X_BIT_ATI 0x00000002 +#define GL_8X_BIT_ATI 0x00000004 +#define GL_HALF_BIT_ATI 0x00000008 +#define GL_QUARTER_BIT_ATI 0x00000010 +#define GL_EIGHTH_BIT_ATI 0x00000020 +#define GL_SATURATE_BIT_ATI 0x00000040 +#define GL_COMP_BIT_ATI 0x00000002 +#define GL_NEGATE_BIT_ATI 0x00000004 +#define GL_BIAS_BIT_ATI 0x00000008 +#endif + +#ifndef GL_ATI_pn_triangles +#define GL_PN_TRIANGLES_ATI 0x87F0 +#define GL_MAX_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F1 +#define GL_PN_TRIANGLES_POINT_MODE_ATI 0x87F2 +#define GL_PN_TRIANGLES_NORMAL_MODE_ATI 0x87F3 +#define GL_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F4 +#define GL_PN_TRIANGLES_POINT_MODE_LINEAR_ATI 0x87F5 +#define GL_PN_TRIANGLES_POINT_MODE_CUBIC_ATI 0x87F6 +#define GL_PN_TRIANGLES_NORMAL_MODE_LINEAR_ATI 0x87F7 +#define GL_PN_TRIANGLES_NORMAL_MODE_QUADRATIC_ATI 0x87F8 +#endif + +#ifndef GL_ATI_vertex_array_object +#define GL_STATIC_ATI 0x8760 +#define GL_DYNAMIC_ATI 0x8761 +#define GL_PRESERVE_ATI 0x8762 +#define GL_DISCARD_ATI 0x8763 +#define GL_OBJECT_BUFFER_SIZE_ATI 0x8764 +#define GL_OBJECT_BUFFER_USAGE_ATI 0x8765 +#define GL_ARRAY_OBJECT_BUFFER_ATI 0x8766 +#define GL_ARRAY_OBJECT_OFFSET_ATI 0x8767 +#endif + +#ifndef GL_EXT_vertex_shader +#define GL_VERTEX_SHADER_EXT 0x8780 +#define GL_VERTEX_SHADER_BINDING_EXT 0x8781 +#define GL_OP_INDEX_EXT 0x8782 +#define GL_OP_NEGATE_EXT 0x8783 +#define GL_OP_DOT3_EXT 0x8784 +#define GL_OP_DOT4_EXT 0x8785 +#define GL_OP_MUL_EXT 0x8786 +#define GL_OP_ADD_EXT 0x8787 +#define GL_OP_MADD_EXT 0x8788 +#define GL_OP_FRAC_EXT 0x8789 +#define GL_OP_MAX_EXT 0x878A +#define GL_OP_MIN_EXT 0x878B +#define GL_OP_SET_GE_EXT 0x878C +#define GL_OP_SET_LT_EXT 0x878D +#define GL_OP_CLAMP_EXT 0x878E +#define GL_OP_FLOOR_EXT 0x878F +#define GL_OP_ROUND_EXT 0x8790 +#define GL_OP_EXP_BASE_2_EXT 0x8791 +#define GL_OP_LOG_BASE_2_EXT 0x8792 +#define GL_OP_POWER_EXT 0x8793 +#define GL_OP_RECIP_EXT 0x8794 +#define GL_OP_RECIP_SQRT_EXT 0x8795 +#define GL_OP_SUB_EXT 0x8796 +#define GL_OP_CROSS_PRODUCT_EXT 0x8797 +#define GL_OP_MULTIPLY_MATRIX_EXT 0x8798 +#define GL_OP_MOV_EXT 0x8799 +#define GL_OUTPUT_VERTEX_EXT 0x879A +#define GL_OUTPUT_COLOR0_EXT 0x879B +#define GL_OUTPUT_COLOR1_EXT 0x879C +#define GL_OUTPUT_TEXTURE_COORD0_EXT 0x879D +#define GL_OUTPUT_TEXTURE_COORD1_EXT 0x879E +#define GL_OUTPUT_TEXTURE_COORD2_EXT 0x879F +#define GL_OUTPUT_TEXTURE_COORD3_EXT 0x87A0 +#define GL_OUTPUT_TEXTURE_COORD4_EXT 0x87A1 +#define GL_OUTPUT_TEXTURE_COORD5_EXT 0x87A2 +#define GL_OUTPUT_TEXTURE_COORD6_EXT 0x87A3 +#define GL_OUTPUT_TEXTURE_COORD7_EXT 0x87A4 +#define GL_OUTPUT_TEXTURE_COORD8_EXT 0x87A5 +#define GL_OUTPUT_TEXTURE_COORD9_EXT 0x87A6 +#define GL_OUTPUT_TEXTURE_COORD10_EXT 0x87A7 +#define GL_OUTPUT_TEXTURE_COORD11_EXT 0x87A8 +#define GL_OUTPUT_TEXTURE_COORD12_EXT 0x87A9 +#define GL_OUTPUT_TEXTURE_COORD13_EXT 0x87AA +#define GL_OUTPUT_TEXTURE_COORD14_EXT 0x87AB +#define GL_OUTPUT_TEXTURE_COORD15_EXT 0x87AC +#define GL_OUTPUT_TEXTURE_COORD16_EXT 0x87AD +#define GL_OUTPUT_TEXTURE_COORD17_EXT 0x87AE +#define GL_OUTPUT_TEXTURE_COORD18_EXT 0x87AF +#define GL_OUTPUT_TEXTURE_COORD19_EXT 0x87B0 +#define GL_OUTPUT_TEXTURE_COORD20_EXT 0x87B1 +#define GL_OUTPUT_TEXTURE_COORD21_EXT 0x87B2 +#define GL_OUTPUT_TEXTURE_COORD22_EXT 0x87B3 +#define GL_OUTPUT_TEXTURE_COORD23_EXT 0x87B4 +#define GL_OUTPUT_TEXTURE_COORD24_EXT 0x87B5 +#define GL_OUTPUT_TEXTURE_COORD25_EXT 0x87B6 +#define GL_OUTPUT_TEXTURE_COORD26_EXT 0x87B7 +#define GL_OUTPUT_TEXTURE_COORD27_EXT 0x87B8 +#define GL_OUTPUT_TEXTURE_COORD28_EXT 0x87B9 +#define GL_OUTPUT_TEXTURE_COORD29_EXT 0x87BA +#define GL_OUTPUT_TEXTURE_COORD30_EXT 0x87BB +#define GL_OUTPUT_TEXTURE_COORD31_EXT 0x87BC +#define GL_OUTPUT_FOG_EXT 0x87BD +#define GL_SCALAR_EXT 0x87BE +#define GL_VECTOR_EXT 0x87BF +#define GL_MATRIX_EXT 0x87C0 +#define GL_VARIANT_EXT 0x87C1 +#define GL_INVARIANT_EXT 0x87C2 +#define GL_LOCAL_CONSTANT_EXT 0x87C3 +#define GL_LOCAL_EXT 0x87C4 +#define GL_MAX_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87C5 +#define GL_MAX_VERTEX_SHADER_VARIANTS_EXT 0x87C6 +#define GL_MAX_VERTEX_SHADER_INVARIANTS_EXT 0x87C7 +#define GL_MAX_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87C8 +#define GL_MAX_VERTEX_SHADER_LOCALS_EXT 0x87C9 +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CA +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_VARIANTS_EXT 0x87CB +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87CC +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INVARIANTS_EXT 0x87CD +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCALS_EXT 0x87CE +#define GL_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CF +#define GL_VERTEX_SHADER_VARIANTS_EXT 0x87D0 +#define GL_VERTEX_SHADER_INVARIANTS_EXT 0x87D1 +#define GL_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87D2 +#define GL_VERTEX_SHADER_LOCALS_EXT 0x87D3 +#define GL_VERTEX_SHADER_OPTIMIZED_EXT 0x87D4 +#define GL_X_EXT 0x87D5 +#define GL_Y_EXT 0x87D6 +#define GL_Z_EXT 0x87D7 +#define GL_W_EXT 0x87D8 +#define GL_NEGATIVE_X_EXT 0x87D9 +#define GL_NEGATIVE_Y_EXT 0x87DA +#define GL_NEGATIVE_Z_EXT 0x87DB +#define GL_NEGATIVE_W_EXT 0x87DC +#define GL_ZERO_EXT 0x87DD +#define GL_ONE_EXT 0x87DE +#define GL_NEGATIVE_ONE_EXT 0x87DF +#define GL_NORMALIZED_RANGE_EXT 0x87E0 +#define GL_FULL_RANGE_EXT 0x87E1 +#define GL_CURRENT_VERTEX_EXT 0x87E2 +#define GL_MVP_MATRIX_EXT 0x87E3 +#define GL_VARIANT_VALUE_EXT 0x87E4 +#define GL_VARIANT_DATATYPE_EXT 0x87E5 +#define GL_VARIANT_ARRAY_STRIDE_EXT 0x87E6 +#define GL_VARIANT_ARRAY_TYPE_EXT 0x87E7 +#define GL_VARIANT_ARRAY_EXT 0x87E8 +#define GL_VARIANT_ARRAY_POINTER_EXT 0x87E9 +#define GL_INVARIANT_VALUE_EXT 0x87EA +#define GL_INVARIANT_DATATYPE_EXT 0x87EB +#define GL_LOCAL_CONSTANT_VALUE_EXT 0x87EC +#define GL_LOCAL_CONSTANT_DATATYPE_EXT 0x87ED +#endif + +#ifndef GL_ATI_vertex_streams +#define GL_MAX_VERTEX_STREAMS_ATI 0x876B +#define GL_VERTEX_STREAM0_ATI 0x876C +#define GL_VERTEX_STREAM1_ATI 0x876D +#define GL_VERTEX_STREAM2_ATI 0x876E +#define GL_VERTEX_STREAM3_ATI 0x876F +#define GL_VERTEX_STREAM4_ATI 0x8770 +#define GL_VERTEX_STREAM5_ATI 0x8771 +#define GL_VERTEX_STREAM6_ATI 0x8772 +#define GL_VERTEX_STREAM7_ATI 0x8773 +#define GL_VERTEX_SOURCE_ATI 0x8774 +#endif + +#ifndef GL_ATI_element_array +#define GL_ELEMENT_ARRAY_ATI 0x8768 +#define GL_ELEMENT_ARRAY_TYPE_ATI 0x8769 +#define GL_ELEMENT_ARRAY_POINTER_ATI 0x876A +#endif + +#ifndef GL_SUN_mesh_array +#define GL_QUAD_MESH_SUN 0x8614 +#define GL_TRIANGLE_MESH_SUN 0x8615 +#endif + +#ifndef GL_SUN_slice_accum +#define GL_SLICE_ACCUM_SUN 0x85CC +#endif + +#ifndef GL_NV_multisample_filter_hint +#define GL_MULTISAMPLE_FILTER_HINT_NV 0x8534 +#endif + +#ifndef GL_NV_depth_clamp +#define GL_DEPTH_CLAMP_NV 0x864F +#endif + +#ifndef GL_NV_occlusion_query +#define GL_PIXEL_COUNTER_BITS_NV 0x8864 +#define GL_CURRENT_OCCLUSION_QUERY_ID_NV 0x8865 +#define GL_PIXEL_COUNT_NV 0x8866 +#define GL_PIXEL_COUNT_AVAILABLE_NV 0x8867 +#endif + +#ifndef GL_NV_point_sprite +#define GL_POINT_SPRITE_NV 0x8861 +#define GL_COORD_REPLACE_NV 0x8862 +#define GL_POINT_SPRITE_R_MODE_NV 0x8863 +#endif + +#ifndef GL_NV_texture_shader3 +#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_NV 0x8850 +#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_SCALE_NV 0x8851 +#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8852 +#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_SCALE_NV 0x8853 +#define GL_OFFSET_HILO_TEXTURE_2D_NV 0x8854 +#define GL_OFFSET_HILO_TEXTURE_RECTANGLE_NV 0x8855 +#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_2D_NV 0x8856 +#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8857 +#define GL_DEPENDENT_HILO_TEXTURE_2D_NV 0x8858 +#define GL_DEPENDENT_RGB_TEXTURE_3D_NV 0x8859 +#define GL_DEPENDENT_RGB_TEXTURE_CUBE_MAP_NV 0x885A +#define GL_DOT_PRODUCT_PASS_THROUGH_NV 0x885B +#define GL_DOT_PRODUCT_TEXTURE_1D_NV 0x885C +#define GL_DOT_PRODUCT_AFFINE_DEPTH_REPLACE_NV 0x885D +#define GL_HILO8_NV 0x885E +#define GL_SIGNED_HILO8_NV 0x885F +#define GL_FORCE_BLUE_TO_ONE_NV 0x8860 +#endif + +#ifndef GL_NV_vertex_program1_1 +#endif + +#ifndef GL_EXT_shadow_funcs +#endif + +#ifndef GL_EXT_stencil_two_side +#define GL_STENCIL_TEST_TWO_SIDE_EXT 0x8910 +#define GL_ACTIVE_STENCIL_FACE_EXT 0x8911 +#endif + +#ifndef GL_ATI_text_fragment_shader +#define GL_TEXT_FRAGMENT_SHADER_ATI 0x8200 +#endif + +#ifndef GL_APPLE_client_storage +#define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2 +#endif + +#ifndef GL_APPLE_element_array +#define GL_ELEMENT_ARRAY_APPLE 0x8A0C +#define GL_ELEMENT_ARRAY_TYPE_APPLE 0x8A0D +#define GL_ELEMENT_ARRAY_POINTER_APPLE 0x8A0E +#endif + +#ifndef GL_APPLE_fence +#define GL_DRAW_PIXELS_APPLE 0x8A0A +#define GL_FENCE_APPLE 0x8A0B +#endif + +#ifndef GL_APPLE_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING_APPLE 0x85B5 +#endif + +#ifndef GL_APPLE_vertex_array_range +#define GL_VERTEX_ARRAY_RANGE_APPLE 0x851D +#define GL_VERTEX_ARRAY_RANGE_LENGTH_APPLE 0x851E +#define GL_VERTEX_ARRAY_STORAGE_HINT_APPLE 0x851F +#define GL_VERTEX_ARRAY_RANGE_POINTER_APPLE 0x8521 +#define GL_STORAGE_CLIENT_APPLE 0x85B4 +#define GL_STORAGE_CACHED_APPLE 0x85BE +#define GL_STORAGE_SHARED_APPLE 0x85BF +#endif + +#ifndef GL_APPLE_ycbcr_422 +#define GL_YCBCR_422_APPLE 0x85B9 +#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA +#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB +#endif + +#ifndef GL_S3_s3tc +#define GL_RGB_S3TC 0x83A0 +#define GL_RGB4_S3TC 0x83A1 +#define GL_RGBA_S3TC 0x83A2 +#define GL_RGBA4_S3TC 0x83A3 +#endif + +#ifndef GL_ATI_draw_buffers +#define GL_MAX_DRAW_BUFFERS_ATI 0x8824 +#define GL_DRAW_BUFFER0_ATI 0x8825 +#define GL_DRAW_BUFFER1_ATI 0x8826 +#define GL_DRAW_BUFFER2_ATI 0x8827 +#define GL_DRAW_BUFFER3_ATI 0x8828 +#define GL_DRAW_BUFFER4_ATI 0x8829 +#define GL_DRAW_BUFFER5_ATI 0x882A +#define GL_DRAW_BUFFER6_ATI 0x882B +#define GL_DRAW_BUFFER7_ATI 0x882C +#define GL_DRAW_BUFFER8_ATI 0x882D +#define GL_DRAW_BUFFER9_ATI 0x882E +#define GL_DRAW_BUFFER10_ATI 0x882F +#define GL_DRAW_BUFFER11_ATI 0x8830 +#define GL_DRAW_BUFFER12_ATI 0x8831 +#define GL_DRAW_BUFFER13_ATI 0x8832 +#define GL_DRAW_BUFFER14_ATI 0x8833 +#define GL_DRAW_BUFFER15_ATI 0x8834 +#endif + +#ifndef GL_ATI_pixel_format_float +#define GL_TYPE_RGBA_FLOAT_ATI 0x8820 +#define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835 +#endif + +#ifndef GL_ATI_texture_env_combine3 +#define GL_MODULATE_ADD_ATI 0x8744 +#define GL_MODULATE_SIGNED_ADD_ATI 0x8745 +#define GL_MODULATE_SUBTRACT_ATI 0x8746 +#endif + +#ifndef GL_ATI_texture_float +#define GL_RGBA_FLOAT32_ATI 0x8814 +#define GL_RGB_FLOAT32_ATI 0x8815 +#define GL_ALPHA_FLOAT32_ATI 0x8816 +#define GL_INTENSITY_FLOAT32_ATI 0x8817 +#define GL_LUMINANCE_FLOAT32_ATI 0x8818 +#define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819 +#define GL_RGBA_FLOAT16_ATI 0x881A +#define GL_RGB_FLOAT16_ATI 0x881B +#define GL_ALPHA_FLOAT16_ATI 0x881C +#define GL_INTENSITY_FLOAT16_ATI 0x881D +#define GL_LUMINANCE_FLOAT16_ATI 0x881E +#define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F +#endif + +#ifndef GL_NV_float_buffer +#define GL_FLOAT_R_NV 0x8880 +#define GL_FLOAT_RG_NV 0x8881 +#define GL_FLOAT_RGB_NV 0x8882 +#define GL_FLOAT_RGBA_NV 0x8883 +#define GL_FLOAT_R16_NV 0x8884 +#define GL_FLOAT_R32_NV 0x8885 +#define GL_FLOAT_RG16_NV 0x8886 +#define GL_FLOAT_RG32_NV 0x8887 +#define GL_FLOAT_RGB16_NV 0x8888 +#define GL_FLOAT_RGB32_NV 0x8889 +#define GL_FLOAT_RGBA16_NV 0x888A +#define GL_FLOAT_RGBA32_NV 0x888B +#define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C +#define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D +#define GL_FLOAT_RGBA_MODE_NV 0x888E +#endif + +#ifndef GL_NV_fragment_program +#define GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV 0x8868 +#define GL_FRAGMENT_PROGRAM_NV 0x8870 +#define GL_MAX_TEXTURE_COORDS_NV 0x8871 +#define GL_MAX_TEXTURE_IMAGE_UNITS_NV 0x8872 +#define GL_FRAGMENT_PROGRAM_BINDING_NV 0x8873 +#define GL_PROGRAM_ERROR_STRING_NV 0x8874 +#endif + +#ifndef GL_NV_half_float +#define GL_HALF_FLOAT_NV 0x140B +#endif + +#ifndef GL_NV_pixel_data_range +#define GL_WRITE_PIXEL_DATA_RANGE_NV 0x8878 +#define GL_READ_PIXEL_DATA_RANGE_NV 0x8879 +#define GL_WRITE_PIXEL_DATA_RANGE_LENGTH_NV 0x887A +#define GL_READ_PIXEL_DATA_RANGE_LENGTH_NV 0x887B +#define GL_WRITE_PIXEL_DATA_RANGE_POINTER_NV 0x887C +#define GL_READ_PIXEL_DATA_RANGE_POINTER_NV 0x887D +#endif + +#ifndef GL_NV_primitive_restart +#define GL_PRIMITIVE_RESTART_NV 0x8558 +#define GL_PRIMITIVE_RESTART_INDEX_NV 0x8559 +#endif + +#ifndef GL_NV_texture_expand_normal +#define GL_TEXTURE_UNSIGNED_REMAP_MODE_NV 0x888F +#endif + +#ifndef GL_NV_vertex_program2 +#endif + +#ifndef GL_ATI_map_object_buffer +#endif + +#ifndef GL_ATI_separate_stencil +#define GL_STENCIL_BACK_FUNC_ATI 0x8800 +#define GL_STENCIL_BACK_FAIL_ATI 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL_ATI 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS_ATI 0x8803 +#endif + +#ifndef GL_ATI_vertex_attrib_array_object +#endif + +#ifndef GL_OES_read_format +#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B +#endif + +#ifndef GL_EXT_depth_bounds_test +#define GL_DEPTH_BOUNDS_TEST_EXT 0x8890 +#define GL_DEPTH_BOUNDS_EXT 0x8891 +#endif + +#ifndef GL_EXT_texture_mirror_clamp +#define GL_MIRROR_CLAMP_EXT 0x8742 +#define GL_MIRROR_CLAMP_TO_EDGE_EXT 0x8743 +#define GL_MIRROR_CLAMP_TO_BORDER_EXT 0x8912 +#endif + +#ifndef GL_EXT_blend_equation_separate +#define GL_BLEND_EQUATION_RGB_EXT 0x8009 +#define GL_BLEND_EQUATION_ALPHA_EXT 0x883D +#endif + +#ifndef GL_MESA_pack_invert +#define GL_PACK_INVERT_MESA 0x8758 +#endif + +#ifndef GL_MESA_ycbcr_texture +#define GL_UNSIGNED_SHORT_8_8_MESA 0x85BA +#define GL_UNSIGNED_SHORT_8_8_REV_MESA 0x85BB +#define GL_YCBCR_MESA 0x8757 +#endif + +#ifndef GL_EXT_pixel_buffer_object +#define GL_PIXEL_PACK_BUFFER_EXT 0x88EB +#define GL_PIXEL_UNPACK_BUFFER_EXT 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING_EXT 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING_EXT 0x88EF +#endif + +#ifndef GL_NV_fragment_program_option +#endif + +#ifndef GL_NV_fragment_program2 +#define GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV 0x88F4 +#define GL_MAX_PROGRAM_CALL_DEPTH_NV 0x88F5 +#define GL_MAX_PROGRAM_IF_DEPTH_NV 0x88F6 +#define GL_MAX_PROGRAM_LOOP_DEPTH_NV 0x88F7 +#define GL_MAX_PROGRAM_LOOP_COUNT_NV 0x88F8 +#endif + +#ifndef GL_NV_vertex_program2_option +/* reuse GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV */ +/* reuse GL_MAX_PROGRAM_CALL_DEPTH_NV */ +#endif + +#ifndef GL_NV_vertex_program3 +/* reuse GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB */ +#endif + +#ifndef GL_EXT_framebuffer_object +#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506 +#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8 +#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6 +#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4 +#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9 +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC +#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD +#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF +#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0 +#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1 +#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2 +#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3 +#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4 +#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5 +#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6 +#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7 +#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8 +#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9 +#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA +#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB +#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC +#define GL_COLOR_ATTACHMENT13_EXT 0x8CED +#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE +#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF +#define GL_DEPTH_ATTACHMENT_EXT 0x8D00 +#define GL_STENCIL_ATTACHMENT_EXT 0x8D20 +#define GL_FRAMEBUFFER_EXT 0x8D40 +#define GL_RENDERBUFFER_EXT 0x8D41 +#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42 +#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44 +#define GL_STENCIL_INDEX1_EXT 0x8D46 +#define GL_STENCIL_INDEX4_EXT 0x8D47 +#define GL_STENCIL_INDEX8_EXT 0x8D48 +#define GL_STENCIL_INDEX16_EXT 0x8D49 +#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55 +#endif + +#ifndef GL_GREMEDY_string_marker +#endif + +#ifndef GL_EXT_packed_depth_stencil +#define GL_DEPTH_STENCIL_EXT 0x84F9 +#define GL_UNSIGNED_INT_24_8_EXT 0x84FA +#define GL_DEPTH24_STENCIL8_EXT 0x88F0 +#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1 +#endif + +#ifndef GL_EXT_stencil_clear_tag +#define GL_STENCIL_TAG_BITS_EXT 0x88F2 +#define GL_STENCIL_CLEAR_TAG_VALUE_EXT 0x88F3 +#endif + +#ifndef GL_EXT_texture_sRGB +#define GL_SRGB_EXT 0x8C40 +#define GL_SRGB8_EXT 0x8C41 +#define GL_SRGB_ALPHA_EXT 0x8C42 +#define GL_SRGB8_ALPHA8_EXT 0x8C43 +#define GL_SLUMINANCE_ALPHA_EXT 0x8C44 +#define GL_SLUMINANCE8_ALPHA8_EXT 0x8C45 +#define GL_SLUMINANCE_EXT 0x8C46 +#define GL_SLUMINANCE8_EXT 0x8C47 +#define GL_COMPRESSED_SRGB_EXT 0x8C48 +#define GL_COMPRESSED_SRGB_ALPHA_EXT 0x8C49 +#define GL_COMPRESSED_SLUMINANCE_EXT 0x8C4A +#define GL_COMPRESSED_SLUMINANCE_ALPHA_EXT 0x8C4B +#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F +#endif + +#ifndef GL_EXT_framebuffer_blit +#define GL_READ_FRAMEBUFFER_EXT 0x8CA8 +#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9 +#define GL_DRAW_FRAMEBUFFER_BINDING_EXT GL_FRAMEBUFFER_BINDING_EXT +#define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA +#endif + +#ifndef GL_EXT_framebuffer_multisample +#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56 +#define GL_MAX_SAMPLES_EXT 0x8D57 +#endif + +#ifndef GL_MESAX_texture_stack +#define GL_TEXTURE_1D_STACK_MESAX 0x8759 +#define GL_TEXTURE_2D_STACK_MESAX 0x875A +#define GL_PROXY_TEXTURE_1D_STACK_MESAX 0x875B +#define GL_PROXY_TEXTURE_2D_STACK_MESAX 0x875C +#define GL_TEXTURE_1D_STACK_BINDING_MESAX 0x875D +#define GL_TEXTURE_2D_STACK_BINDING_MESAX 0x875E +#endif + +#ifndef GL_EXT_timer_query +#define GL_TIME_ELAPSED_EXT 0x88BF +#endif + +#ifndef GL_EXT_gpu_program_parameters +#endif + +#ifndef GL_APPLE_flush_buffer_range +#define GL_BUFFER_SERIALIZED_MODIFY_APPLE 0x8A12 +#define GL_BUFFER_FLUSHING_UNMAP_APPLE 0x8A13 +#endif + +#ifndef GL_NV_gpu_program4 +#define GL_MIN_PROGRAM_TEXEL_OFFSET_NV 0x8904 +#define GL_MAX_PROGRAM_TEXEL_OFFSET_NV 0x8905 +#define GL_PROGRAM_ATTRIB_COMPONENTS_NV 0x8906 +#define GL_PROGRAM_RESULT_COMPONENTS_NV 0x8907 +#define GL_MAX_PROGRAM_ATTRIB_COMPONENTS_NV 0x8908 +#define GL_MAX_PROGRAM_RESULT_COMPONENTS_NV 0x8909 +#define GL_MAX_PROGRAM_GENERIC_ATTRIBS_NV 0x8DA5 +#define GL_MAX_PROGRAM_GENERIC_RESULTS_NV 0x8DA6 +#endif + +#ifndef GL_NV_geometry_program4 +#define GL_LINES_ADJACENCY_EXT 0x000A +#define GL_LINE_STRIP_ADJACENCY_EXT 0x000B +#define GL_TRIANGLES_ADJACENCY_EXT 0x000C +#define GL_TRIANGLE_STRIP_ADJACENCY_EXT 0x000D +#define GL_GEOMETRY_PROGRAM_NV 0x8C26 +#define GL_MAX_PROGRAM_OUTPUT_VERTICES_NV 0x8C27 +#define GL_MAX_PROGRAM_TOTAL_OUTPUT_COMPONENTS_NV 0x8C28 +#define GL_GEOMETRY_VERTICES_OUT_EXT 0x8DDA +#define GL_GEOMETRY_INPUT_TYPE_EXT 0x8DDB +#define GL_GEOMETRY_OUTPUT_TYPE_EXT 0x8DDC +#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT 0x8C29 +#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT 0x8DA7 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT 0x8DA8 +#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_EXT 0x8DA9 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4 +#define GL_PROGRAM_POINT_SIZE_EXT 0x8642 +#endif + +#ifndef GL_EXT_geometry_shader4 +#define GL_GEOMETRY_SHADER_EXT 0x8DD9 +/* reuse GL_GEOMETRY_VERTICES_OUT_EXT */ +/* reuse GL_GEOMETRY_INPUT_TYPE_EXT */ +/* reuse GL_GEOMETRY_OUTPUT_TYPE_EXT */ +/* reuse GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT */ +#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_EXT 0x8DDD +#define GL_MAX_VERTEX_VARYING_COMPONENTS_EXT 0x8DDE +#define GL_MAX_VARYING_COMPONENTS_EXT 0x8B4B +#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT 0x8DDF +#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT 0x8DE0 +#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT 0x8DE1 +/* reuse GL_LINES_ADJACENCY_EXT */ +/* reuse GL_LINE_STRIP_ADJACENCY_EXT */ +/* reuse GL_TRIANGLES_ADJACENCY_EXT */ +/* reuse GL_TRIANGLE_STRIP_ADJACENCY_EXT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT */ +/* reuse GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_EXT */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT */ +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT */ +/* reuse GL_PROGRAM_POINT_SIZE_EXT */ +#endif + +#ifndef GL_NV_vertex_program4 +#define GL_VERTEX_ATTRIB_ARRAY_INTEGER_NV 0x88FD +#endif + +#ifndef GL_EXT_gpu_shader4 +#define GL_SAMPLER_1D_ARRAY_EXT 0x8DC0 +#define GL_SAMPLER_2D_ARRAY_EXT 0x8DC1 +#define GL_SAMPLER_BUFFER_EXT 0x8DC2 +#define GL_SAMPLER_1D_ARRAY_SHADOW_EXT 0x8DC3 +#define GL_SAMPLER_2D_ARRAY_SHADOW_EXT 0x8DC4 +#define GL_SAMPLER_CUBE_SHADOW_EXT 0x8DC5 +#define GL_UNSIGNED_INT_VEC2_EXT 0x8DC6 +#define GL_UNSIGNED_INT_VEC3_EXT 0x8DC7 +#define GL_UNSIGNED_INT_VEC4_EXT 0x8DC8 +#define GL_INT_SAMPLER_1D_EXT 0x8DC9 +#define GL_INT_SAMPLER_2D_EXT 0x8DCA +#define GL_INT_SAMPLER_3D_EXT 0x8DCB +#define GL_INT_SAMPLER_CUBE_EXT 0x8DCC +#define GL_INT_SAMPLER_2D_RECT_EXT 0x8DCD +#define GL_INT_SAMPLER_1D_ARRAY_EXT 0x8DCE +#define GL_INT_SAMPLER_2D_ARRAY_EXT 0x8DCF +#define GL_INT_SAMPLER_BUFFER_EXT 0x8DD0 +#define GL_UNSIGNED_INT_SAMPLER_1D_EXT 0x8DD1 +#define GL_UNSIGNED_INT_SAMPLER_2D_EXT 0x8DD2 +#define GL_UNSIGNED_INT_SAMPLER_3D_EXT 0x8DD3 +#define GL_UNSIGNED_INT_SAMPLER_CUBE_EXT 0x8DD4 +#define GL_UNSIGNED_INT_SAMPLER_2D_RECT_EXT 0x8DD5 +#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY_EXT 0x8DD6 +#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY_EXT 0x8DD7 +#define GL_UNSIGNED_INT_SAMPLER_BUFFER_EXT 0x8DD8 +#endif + +#ifndef GL_EXT_draw_instanced +#endif + +#ifndef GL_EXT_packed_float +#define GL_R11F_G11F_B10F_EXT 0x8C3A +#define GL_UNSIGNED_INT_10F_11F_11F_REV_EXT 0x8C3B +#define GL_RGBA_SIGNED_COMPONENTS_EXT 0x8C3C +#endif + +#ifndef GL_EXT_texture_array +#define GL_TEXTURE_1D_ARRAY_EXT 0x8C18 +#define GL_PROXY_TEXTURE_1D_ARRAY_EXT 0x8C19 +#define GL_TEXTURE_2D_ARRAY_EXT 0x8C1A +#define GL_PROXY_TEXTURE_2D_ARRAY_EXT 0x8C1B +#define GL_TEXTURE_BINDING_1D_ARRAY_EXT 0x8C1C +#define GL_TEXTURE_BINDING_2D_ARRAY_EXT 0x8C1D +#define GL_MAX_ARRAY_TEXTURE_LAYERS_EXT 0x88FF +#define GL_COMPARE_REF_DEPTH_TO_TEXTURE_EXT 0x884E +/* reuse GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT */ +#endif + +#ifndef GL_EXT_texture_buffer_object +#define GL_TEXTURE_BUFFER_EXT 0x8C2A +#define GL_MAX_TEXTURE_BUFFER_SIZE_EXT 0x8C2B +#define GL_TEXTURE_BINDING_BUFFER_EXT 0x8C2C +#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_EXT 0x8C2D +#define GL_TEXTURE_BUFFER_FORMAT_EXT 0x8C2E +#endif + +#ifndef GL_EXT_texture_compression_latc +#define GL_COMPRESSED_LUMINANCE_LATC1_EXT 0x8C70 +#define GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT 0x8C71 +#define GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72 +#define GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT 0x8C73 +#endif + +#ifndef GL_EXT_texture_compression_rgtc +#define GL_COMPRESSED_RED_RGTC1_EXT 0x8DBB +#define GL_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC +#define GL_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD +#define GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE +#endif + +#ifndef GL_EXT_texture_shared_exponent +#define GL_RGB9_E5_EXT 0x8C3D +#define GL_UNSIGNED_INT_5_9_9_9_REV_EXT 0x8C3E +#define GL_TEXTURE_SHARED_SIZE_EXT 0x8C3F +#endif + +#ifndef GL_NV_depth_buffer_float +#define GL_DEPTH_COMPONENT32F_NV 0x8DAB +#define GL_DEPTH32F_STENCIL8_NV 0x8DAC +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV_NV 0x8DAD +#define GL_DEPTH_BUFFER_FLOAT_MODE_NV 0x8DAF +#endif + +#ifndef GL_NV_fragment_program4 +#endif + +#ifndef GL_NV_framebuffer_multisample_coverage +#define GL_RENDERBUFFER_COVERAGE_SAMPLES_NV 0x8CAB +#define GL_RENDERBUFFER_COLOR_SAMPLES_NV 0x8E10 +#define GL_MAX_MULTISAMPLE_COVERAGE_MODES_NV 0x8E11 +#define GL_MULTISAMPLE_COVERAGE_MODES_NV 0x8E12 +#endif + +#ifndef GL_EXT_framebuffer_sRGB +#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9 +#define GL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x8DBA +#endif + +#ifndef GL_NV_geometry_shader4 +#endif + +#ifndef GL_NV_parameter_buffer_object +#define GL_MAX_PROGRAM_PARAMETER_BUFFER_BINDINGS_NV 0x8DA0 +#define GL_MAX_PROGRAM_PARAMETER_BUFFER_SIZE_NV 0x8DA1 +#define GL_VERTEX_PROGRAM_PARAMETER_BUFFER_NV 0x8DA2 +#define GL_GEOMETRY_PROGRAM_PARAMETER_BUFFER_NV 0x8DA3 +#define GL_FRAGMENT_PROGRAM_PARAMETER_BUFFER_NV 0x8DA4 +#endif + +#ifndef GL_EXT_draw_buffers2 +#endif + +#ifndef GL_NV_transform_feedback +#define GL_BACK_PRIMARY_COLOR_NV 0x8C77 +#define GL_BACK_SECONDARY_COLOR_NV 0x8C78 +#define GL_TEXTURE_COORD_NV 0x8C79 +#define GL_CLIP_DISTANCE_NV 0x8C7A +#define GL_VERTEX_ID_NV 0x8C7B +#define GL_PRIMITIVE_ID_NV 0x8C7C +#define GL_GENERIC_ATTRIB_NV 0x8C7D +#define GL_TRANSFORM_FEEDBACK_ATTRIBS_NV 0x8C7E +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE_NV 0x8C7F +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_NV 0x8C80 +#define GL_ACTIVE_VARYINGS_NV 0x8C81 +#define GL_ACTIVE_VARYING_MAX_LENGTH_NV 0x8C82 +#define GL_TRANSFORM_FEEDBACK_VARYINGS_NV 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_START_NV 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE_NV 0x8C85 +#define GL_TRANSFORM_FEEDBACK_RECORD_NV 0x8C86 +#define GL_PRIMITIVES_GENERATED_NV 0x8C87 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_NV 0x8C88 +#define GL_RASTERIZER_DISCARD_NV 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_ATTRIBS_NV 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_NV 0x8C8B +#define GL_INTERLEAVED_ATTRIBS_NV 0x8C8C +#define GL_SEPARATE_ATTRIBS_NV 0x8C8D +#define GL_TRANSFORM_FEEDBACK_BUFFER_NV 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING_NV 0x8C8F +#define GL_LAYER_NV 0x8DAA +#define GL_NEXT_BUFFER_NV -2 +#define GL_SKIP_COMPONENTS4_NV -3 +#define GL_SKIP_COMPONENTS3_NV -4 +#define GL_SKIP_COMPONENTS2_NV -5 +#define GL_SKIP_COMPONENTS1_NV -6 +#endif + +#ifndef GL_EXT_bindable_uniform +#define GL_MAX_VERTEX_BINDABLE_UNIFORMS_EXT 0x8DE2 +#define GL_MAX_FRAGMENT_BINDABLE_UNIFORMS_EXT 0x8DE3 +#define GL_MAX_GEOMETRY_BINDABLE_UNIFORMS_EXT 0x8DE4 +#define GL_MAX_BINDABLE_UNIFORM_SIZE_EXT 0x8DED +#define GL_UNIFORM_BUFFER_EXT 0x8DEE +#define GL_UNIFORM_BUFFER_BINDING_EXT 0x8DEF +#endif + +#ifndef GL_EXT_texture_integer +#define GL_RGBA32UI_EXT 0x8D70 +#define GL_RGB32UI_EXT 0x8D71 +#define GL_ALPHA32UI_EXT 0x8D72 +#define GL_INTENSITY32UI_EXT 0x8D73 +#define GL_LUMINANCE32UI_EXT 0x8D74 +#define GL_LUMINANCE_ALPHA32UI_EXT 0x8D75 +#define GL_RGBA16UI_EXT 0x8D76 +#define GL_RGB16UI_EXT 0x8D77 +#define GL_ALPHA16UI_EXT 0x8D78 +#define GL_INTENSITY16UI_EXT 0x8D79 +#define GL_LUMINANCE16UI_EXT 0x8D7A +#define GL_LUMINANCE_ALPHA16UI_EXT 0x8D7B +#define GL_RGBA8UI_EXT 0x8D7C +#define GL_RGB8UI_EXT 0x8D7D +#define GL_ALPHA8UI_EXT 0x8D7E +#define GL_INTENSITY8UI_EXT 0x8D7F +#define GL_LUMINANCE8UI_EXT 0x8D80 +#define GL_LUMINANCE_ALPHA8UI_EXT 0x8D81 +#define GL_RGBA32I_EXT 0x8D82 +#define GL_RGB32I_EXT 0x8D83 +#define GL_ALPHA32I_EXT 0x8D84 +#define GL_INTENSITY32I_EXT 0x8D85 +#define GL_LUMINANCE32I_EXT 0x8D86 +#define GL_LUMINANCE_ALPHA32I_EXT 0x8D87 +#define GL_RGBA16I_EXT 0x8D88 +#define GL_RGB16I_EXT 0x8D89 +#define GL_ALPHA16I_EXT 0x8D8A +#define GL_INTENSITY16I_EXT 0x8D8B +#define GL_LUMINANCE16I_EXT 0x8D8C +#define GL_LUMINANCE_ALPHA16I_EXT 0x8D8D +#define GL_RGBA8I_EXT 0x8D8E +#define GL_RGB8I_EXT 0x8D8F +#define GL_ALPHA8I_EXT 0x8D90 +#define GL_INTENSITY8I_EXT 0x8D91 +#define GL_LUMINANCE8I_EXT 0x8D92 +#define GL_LUMINANCE_ALPHA8I_EXT 0x8D93 +#define GL_RED_INTEGER_EXT 0x8D94 +#define GL_GREEN_INTEGER_EXT 0x8D95 +#define GL_BLUE_INTEGER_EXT 0x8D96 +#define GL_ALPHA_INTEGER_EXT 0x8D97 +#define GL_RGB_INTEGER_EXT 0x8D98 +#define GL_RGBA_INTEGER_EXT 0x8D99 +#define GL_BGR_INTEGER_EXT 0x8D9A +#define GL_BGRA_INTEGER_EXT 0x8D9B +#define GL_LUMINANCE_INTEGER_EXT 0x8D9C +#define GL_LUMINANCE_ALPHA_INTEGER_EXT 0x8D9D +#define GL_RGBA_INTEGER_MODE_EXT 0x8D9E +#endif + +#ifndef GL_GREMEDY_frame_terminator +#endif + +#ifndef GL_NV_conditional_render +#define GL_QUERY_WAIT_NV 0x8E13 +#define GL_QUERY_NO_WAIT_NV 0x8E14 +#define GL_QUERY_BY_REGION_WAIT_NV 0x8E15 +#define GL_QUERY_BY_REGION_NO_WAIT_NV 0x8E16 +#endif + +#ifndef GL_NV_present_video +#define GL_FRAME_NV 0x8E26 +#define GL_FIELDS_NV 0x8E27 +#define GL_CURRENT_TIME_NV 0x8E28 +#define GL_NUM_FILL_STREAMS_NV 0x8E29 +#define GL_PRESENT_TIME_NV 0x8E2A +#define GL_PRESENT_DURATION_NV 0x8E2B +#endif + +#ifndef GL_EXT_transform_feedback +#define GL_TRANSFORM_FEEDBACK_BUFFER_EXT 0x8C8E +#define GL_TRANSFORM_FEEDBACK_BUFFER_START_EXT 0x8C84 +#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE_EXT 0x8C85 +#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING_EXT 0x8C8F +#define GL_INTERLEAVED_ATTRIBS_EXT 0x8C8C +#define GL_SEPARATE_ATTRIBS_EXT 0x8C8D +#define GL_PRIMITIVES_GENERATED_EXT 0x8C87 +#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_EXT 0x8C88 +#define GL_RASTERIZER_DISCARD_EXT 0x8C89 +#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT 0x8C8A +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_EXT 0x8C8B +#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT 0x8C80 +#define GL_TRANSFORM_FEEDBACK_VARYINGS_EXT 0x8C83 +#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE_EXT 0x8C7F +#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH_EXT 0x8C76 +#endif + +#ifndef GL_EXT_direct_state_access +#define GL_PROGRAM_MATRIX_EXT 0x8E2D +#define GL_TRANSPOSE_PROGRAM_MATRIX_EXT 0x8E2E +#define GL_PROGRAM_MATRIX_STACK_DEPTH_EXT 0x8E2F +#endif + +#ifndef GL_EXT_vertex_array_bgra +/* reuse GL_BGRA */ +#endif + +#ifndef GL_EXT_texture_swizzle +#define GL_TEXTURE_SWIZZLE_R_EXT 0x8E42 +#define GL_TEXTURE_SWIZZLE_G_EXT 0x8E43 +#define GL_TEXTURE_SWIZZLE_B_EXT 0x8E44 +#define GL_TEXTURE_SWIZZLE_A_EXT 0x8E45 +#define GL_TEXTURE_SWIZZLE_RGBA_EXT 0x8E46 +#endif + +#ifndef GL_NV_explicit_multisample +#define GL_SAMPLE_POSITION_NV 0x8E50 +#define GL_SAMPLE_MASK_NV 0x8E51 +#define GL_SAMPLE_MASK_VALUE_NV 0x8E52 +#define GL_TEXTURE_BINDING_RENDERBUFFER_NV 0x8E53 +#define GL_TEXTURE_RENDERBUFFER_DATA_STORE_BINDING_NV 0x8E54 +#define GL_TEXTURE_RENDERBUFFER_NV 0x8E55 +#define GL_SAMPLER_RENDERBUFFER_NV 0x8E56 +#define GL_INT_SAMPLER_RENDERBUFFER_NV 0x8E57 +#define GL_UNSIGNED_INT_SAMPLER_RENDERBUFFER_NV 0x8E58 +#define GL_MAX_SAMPLE_MASK_WORDS_NV 0x8E59 +#endif + +#ifndef GL_NV_transform_feedback2 +#define GL_TRANSFORM_FEEDBACK_NV 0x8E22 +#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED_NV 0x8E23 +#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE_NV 0x8E24 +#define GL_TRANSFORM_FEEDBACK_BINDING_NV 0x8E25 +#endif + +#ifndef GL_ATI_meminfo +#define GL_VBO_FREE_MEMORY_ATI 0x87FB +#define GL_TEXTURE_FREE_MEMORY_ATI 0x87FC +#define GL_RENDERBUFFER_FREE_MEMORY_ATI 0x87FD +#endif + +#ifndef GL_AMD_performance_monitor +#define GL_COUNTER_TYPE_AMD 0x8BC0 +#define GL_COUNTER_RANGE_AMD 0x8BC1 +#define GL_UNSIGNED_INT64_AMD 0x8BC2 +#define GL_PERCENTAGE_AMD 0x8BC3 +#define GL_PERFMON_RESULT_AVAILABLE_AMD 0x8BC4 +#define GL_PERFMON_RESULT_SIZE_AMD 0x8BC5 +#define GL_PERFMON_RESULT_AMD 0x8BC6 +#endif + +#ifndef GL_AMD_texture_texture4 +#endif + +#ifndef GL_AMD_vertex_shader_tesselator +#define GL_SAMPLER_BUFFER_AMD 0x9001 +#define GL_INT_SAMPLER_BUFFER_AMD 0x9002 +#define GL_UNSIGNED_INT_SAMPLER_BUFFER_AMD 0x9003 +#define GL_TESSELLATION_MODE_AMD 0x9004 +#define GL_TESSELLATION_FACTOR_AMD 0x9005 +#define GL_DISCRETE_AMD 0x9006 +#define GL_CONTINUOUS_AMD 0x9007 +#endif + +#ifndef GL_EXT_provoking_vertex +#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION_EXT 0x8E4C +#define GL_FIRST_VERTEX_CONVENTION_EXT 0x8E4D +#define GL_LAST_VERTEX_CONVENTION_EXT 0x8E4E +#define GL_PROVOKING_VERTEX_EXT 0x8E4F +#endif + +#ifndef GL_EXT_texture_snorm +#define GL_ALPHA_SNORM 0x9010 +#define GL_LUMINANCE_SNORM 0x9011 +#define GL_LUMINANCE_ALPHA_SNORM 0x9012 +#define GL_INTENSITY_SNORM 0x9013 +#define GL_ALPHA8_SNORM 0x9014 +#define GL_LUMINANCE8_SNORM 0x9015 +#define GL_LUMINANCE8_ALPHA8_SNORM 0x9016 +#define GL_INTENSITY8_SNORM 0x9017 +#define GL_ALPHA16_SNORM 0x9018 +#define GL_LUMINANCE16_SNORM 0x9019 +#define GL_LUMINANCE16_ALPHA16_SNORM 0x901A +#define GL_INTENSITY16_SNORM 0x901B +/* reuse GL_RED_SNORM */ +/* reuse GL_RG_SNORM */ +/* reuse GL_RGB_SNORM */ +/* reuse GL_RGBA_SNORM */ +/* reuse GL_R8_SNORM */ +/* reuse GL_RG8_SNORM */ +/* reuse GL_RGB8_SNORM */ +/* reuse GL_RGBA8_SNORM */ +/* reuse GL_R16_SNORM */ +/* reuse GL_RG16_SNORM */ +/* reuse GL_RGB16_SNORM */ +/* reuse GL_RGBA16_SNORM */ +/* reuse GL_SIGNED_NORMALIZED */ +#endif + +#ifndef GL_AMD_draw_buffers_blend +#endif + +#ifndef GL_APPLE_texture_range +#define GL_TEXTURE_RANGE_LENGTH_APPLE 0x85B7 +#define GL_TEXTURE_RANGE_POINTER_APPLE 0x85B8 +#define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC +#define GL_STORAGE_PRIVATE_APPLE 0x85BD +/* reuse GL_STORAGE_CACHED_APPLE */ +/* reuse GL_STORAGE_SHARED_APPLE */ +#endif + +#ifndef GL_APPLE_float_pixels +#define GL_HALF_APPLE 0x140B +#define GL_RGBA_FLOAT32_APPLE 0x8814 +#define GL_RGB_FLOAT32_APPLE 0x8815 +#define GL_ALPHA_FLOAT32_APPLE 0x8816 +#define GL_INTENSITY_FLOAT32_APPLE 0x8817 +#define GL_LUMINANCE_FLOAT32_APPLE 0x8818 +#define GL_LUMINANCE_ALPHA_FLOAT32_APPLE 0x8819 +#define GL_RGBA_FLOAT16_APPLE 0x881A +#define GL_RGB_FLOAT16_APPLE 0x881B +#define GL_ALPHA_FLOAT16_APPLE 0x881C +#define GL_INTENSITY_FLOAT16_APPLE 0x881D +#define GL_LUMINANCE_FLOAT16_APPLE 0x881E +#define GL_LUMINANCE_ALPHA_FLOAT16_APPLE 0x881F +#define GL_COLOR_FLOAT_APPLE 0x8A0F +#endif + +#ifndef GL_APPLE_vertex_program_evaluators +#define GL_VERTEX_ATTRIB_MAP1_APPLE 0x8A00 +#define GL_VERTEX_ATTRIB_MAP2_APPLE 0x8A01 +#define GL_VERTEX_ATTRIB_MAP1_SIZE_APPLE 0x8A02 +#define GL_VERTEX_ATTRIB_MAP1_COEFF_APPLE 0x8A03 +#define GL_VERTEX_ATTRIB_MAP1_ORDER_APPLE 0x8A04 +#define GL_VERTEX_ATTRIB_MAP1_DOMAIN_APPLE 0x8A05 +#define GL_VERTEX_ATTRIB_MAP2_SIZE_APPLE 0x8A06 +#define GL_VERTEX_ATTRIB_MAP2_COEFF_APPLE 0x8A07 +#define GL_VERTEX_ATTRIB_MAP2_ORDER_APPLE 0x8A08 +#define GL_VERTEX_ATTRIB_MAP2_DOMAIN_APPLE 0x8A09 +#endif + +#ifndef GL_APPLE_aux_depth_stencil +#define GL_AUX_DEPTH_STENCIL_APPLE 0x8A14 +#endif + +#ifndef GL_APPLE_object_purgeable +#define GL_BUFFER_OBJECT_APPLE 0x85B3 +#define GL_RELEASED_APPLE 0x8A19 +#define GL_VOLATILE_APPLE 0x8A1A +#define GL_RETAINED_APPLE 0x8A1B +#define GL_UNDEFINED_APPLE 0x8A1C +#define GL_PURGEABLE_APPLE 0x8A1D +#endif + +#ifndef GL_APPLE_row_bytes +#define GL_PACK_ROW_BYTES_APPLE 0x8A15 +#define GL_UNPACK_ROW_BYTES_APPLE 0x8A16 +#endif + +#ifndef GL_APPLE_rgb_422 +#define GL_RGB_422_APPLE 0x8A1F +/* reuse GL_UNSIGNED_SHORT_8_8_APPLE */ +/* reuse GL_UNSIGNED_SHORT_8_8_REV_APPLE */ +#endif + +#ifndef GL_NV_video_capture +#define GL_VIDEO_BUFFER_NV 0x9020 +#define GL_VIDEO_BUFFER_BINDING_NV 0x9021 +#define GL_FIELD_UPPER_NV 0x9022 +#define GL_FIELD_LOWER_NV 0x9023 +#define GL_NUM_VIDEO_CAPTURE_STREAMS_NV 0x9024 +#define GL_NEXT_VIDEO_CAPTURE_BUFFER_STATUS_NV 0x9025 +#define GL_VIDEO_CAPTURE_TO_422_SUPPORTED_NV 0x9026 +#define GL_LAST_VIDEO_CAPTURE_STATUS_NV 0x9027 +#define GL_VIDEO_BUFFER_PITCH_NV 0x9028 +#define GL_VIDEO_COLOR_CONVERSION_MATRIX_NV 0x9029 +#define GL_VIDEO_COLOR_CONVERSION_MAX_NV 0x902A +#define GL_VIDEO_COLOR_CONVERSION_MIN_NV 0x902B +#define GL_VIDEO_COLOR_CONVERSION_OFFSET_NV 0x902C +#define GL_VIDEO_BUFFER_INTERNAL_FORMAT_NV 0x902D +#define GL_PARTIAL_SUCCESS_NV 0x902E +#define GL_SUCCESS_NV 0x902F +#define GL_FAILURE_NV 0x9030 +#define GL_YCBYCR8_422_NV 0x9031 +#define GL_YCBAYCR8A_4224_NV 0x9032 +#define GL_Z6Y10Z6CB10Z6Y10Z6CR10_422_NV 0x9033 +#define GL_Z6Y10Z6CB10Z6A10Z6Y10Z6CR10Z6A10_4224_NV 0x9034 +#define GL_Z4Y12Z4CB12Z4Y12Z4CR12_422_NV 0x9035 +#define GL_Z4Y12Z4CB12Z4A12Z4Y12Z4CR12Z4A12_4224_NV 0x9036 +#define GL_Z4Y12Z4CB12Z4CR12_444_NV 0x9037 +#define GL_VIDEO_CAPTURE_FRAME_WIDTH_NV 0x9038 +#define GL_VIDEO_CAPTURE_FRAME_HEIGHT_NV 0x9039 +#define GL_VIDEO_CAPTURE_FIELD_UPPER_HEIGHT_NV 0x903A +#define GL_VIDEO_CAPTURE_FIELD_LOWER_HEIGHT_NV 0x903B +#define GL_VIDEO_CAPTURE_SURFACE_ORIGIN_NV 0x903C +#endif + +#ifndef GL_NV_copy_image +#endif + +#ifndef GL_EXT_separate_shader_objects +#define GL_ACTIVE_PROGRAM_EXT 0x8B8D +#endif + +#ifndef GL_NV_parameter_buffer_object2 +#endif + +#ifndef GL_NV_shader_buffer_load +#define GL_BUFFER_GPU_ADDRESS_NV 0x8F1D +#define GL_GPU_ADDRESS_NV 0x8F34 +#define GL_MAX_SHADER_BUFFER_ADDRESS_NV 0x8F35 +#endif + +#ifndef GL_NV_vertex_buffer_unified_memory +#define GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV 0x8F1E +#define GL_ELEMENT_ARRAY_UNIFIED_NV 0x8F1F +#define GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV 0x8F20 +#define GL_VERTEX_ARRAY_ADDRESS_NV 0x8F21 +#define GL_NORMAL_ARRAY_ADDRESS_NV 0x8F22 +#define GL_COLOR_ARRAY_ADDRESS_NV 0x8F23 +#define GL_INDEX_ARRAY_ADDRESS_NV 0x8F24 +#define GL_TEXTURE_COORD_ARRAY_ADDRESS_NV 0x8F25 +#define GL_EDGE_FLAG_ARRAY_ADDRESS_NV 0x8F26 +#define GL_SECONDARY_COLOR_ARRAY_ADDRESS_NV 0x8F27 +#define GL_FOG_COORD_ARRAY_ADDRESS_NV 0x8F28 +#define GL_ELEMENT_ARRAY_ADDRESS_NV 0x8F29 +#define GL_VERTEX_ATTRIB_ARRAY_LENGTH_NV 0x8F2A +#define GL_VERTEX_ARRAY_LENGTH_NV 0x8F2B +#define GL_NORMAL_ARRAY_LENGTH_NV 0x8F2C +#define GL_COLOR_ARRAY_LENGTH_NV 0x8F2D +#define GL_INDEX_ARRAY_LENGTH_NV 0x8F2E +#define GL_TEXTURE_COORD_ARRAY_LENGTH_NV 0x8F2F +#define GL_EDGE_FLAG_ARRAY_LENGTH_NV 0x8F30 +#define GL_SECONDARY_COLOR_ARRAY_LENGTH_NV 0x8F31 +#define GL_FOG_COORD_ARRAY_LENGTH_NV 0x8F32 +#define GL_ELEMENT_ARRAY_LENGTH_NV 0x8F33 +#define GL_DRAW_INDIRECT_UNIFIED_NV 0x8F40 +#define GL_DRAW_INDIRECT_ADDRESS_NV 0x8F41 +#define GL_DRAW_INDIRECT_LENGTH_NV 0x8F42 +#endif + +#ifndef GL_NV_texture_barrier +#endif + +#ifndef GL_AMD_shader_stencil_export +#endif + +#ifndef GL_AMD_seamless_cubemap_per_texture +/* reuse GL_TEXTURE_CUBE_MAP_SEAMLESS */ +#endif + +#ifndef GL_AMD_conservative_depth +#endif + +#ifndef GL_EXT_shader_image_load_store +#define GL_MAX_IMAGE_UNITS_EXT 0x8F38 +#define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS_EXT 0x8F39 +#define GL_IMAGE_BINDING_NAME_EXT 0x8F3A +#define GL_IMAGE_BINDING_LEVEL_EXT 0x8F3B +#define GL_IMAGE_BINDING_LAYERED_EXT 0x8F3C +#define GL_IMAGE_BINDING_LAYER_EXT 0x8F3D +#define GL_IMAGE_BINDING_ACCESS_EXT 0x8F3E +#define GL_IMAGE_1D_EXT 0x904C +#define GL_IMAGE_2D_EXT 0x904D +#define GL_IMAGE_3D_EXT 0x904E +#define GL_IMAGE_2D_RECT_EXT 0x904F +#define GL_IMAGE_CUBE_EXT 0x9050 +#define GL_IMAGE_BUFFER_EXT 0x9051 +#define GL_IMAGE_1D_ARRAY_EXT 0x9052 +#define GL_IMAGE_2D_ARRAY_EXT 0x9053 +#define GL_IMAGE_CUBE_MAP_ARRAY_EXT 0x9054 +#define GL_IMAGE_2D_MULTISAMPLE_EXT 0x9055 +#define GL_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x9056 +#define GL_INT_IMAGE_1D_EXT 0x9057 +#define GL_INT_IMAGE_2D_EXT 0x9058 +#define GL_INT_IMAGE_3D_EXT 0x9059 +#define GL_INT_IMAGE_2D_RECT_EXT 0x905A +#define GL_INT_IMAGE_CUBE_EXT 0x905B +#define GL_INT_IMAGE_BUFFER_EXT 0x905C +#define GL_INT_IMAGE_1D_ARRAY_EXT 0x905D +#define GL_INT_IMAGE_2D_ARRAY_EXT 0x905E +#define GL_INT_IMAGE_CUBE_MAP_ARRAY_EXT 0x905F +#define GL_INT_IMAGE_2D_MULTISAMPLE_EXT 0x9060 +#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x9061 +#define GL_UNSIGNED_INT_IMAGE_1D_EXT 0x9062 +#define GL_UNSIGNED_INT_IMAGE_2D_EXT 0x9063 +#define GL_UNSIGNED_INT_IMAGE_3D_EXT 0x9064 +#define GL_UNSIGNED_INT_IMAGE_2D_RECT_EXT 0x9065 +#define GL_UNSIGNED_INT_IMAGE_CUBE_EXT 0x9066 +#define GL_UNSIGNED_INT_IMAGE_BUFFER_EXT 0x9067 +#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY_EXT 0x9068 +#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY_EXT 0x9069 +#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY_EXT 0x906A +#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_EXT 0x906B +#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x906C +#define GL_MAX_IMAGE_SAMPLES_EXT 0x906D +#define GL_IMAGE_BINDING_FORMAT_EXT 0x906E +#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT_EXT 0x00000001 +#define GL_ELEMENT_ARRAY_BARRIER_BIT_EXT 0x00000002 +#define GL_UNIFORM_BARRIER_BIT_EXT 0x00000004 +#define GL_TEXTURE_FETCH_BARRIER_BIT_EXT 0x00000008 +#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT_EXT 0x00000020 +#define GL_COMMAND_BARRIER_BIT_EXT 0x00000040 +#define GL_PIXEL_BUFFER_BARRIER_BIT_EXT 0x00000080 +#define GL_TEXTURE_UPDATE_BARRIER_BIT_EXT 0x00000100 +#define GL_BUFFER_UPDATE_BARRIER_BIT_EXT 0x00000200 +#define GL_FRAMEBUFFER_BARRIER_BIT_EXT 0x00000400 +#define GL_TRANSFORM_FEEDBACK_BARRIER_BIT_EXT 0x00000800 +#define GL_ATOMIC_COUNTER_BARRIER_BIT_EXT 0x00001000 +#define GL_ALL_BARRIER_BITS_EXT 0xFFFFFFFF +#endif + +#ifndef GL_EXT_vertex_attrib_64bit +/* reuse GL_DOUBLE */ +#define GL_DOUBLE_VEC2_EXT 0x8FFC +#define GL_DOUBLE_VEC3_EXT 0x8FFD +#define GL_DOUBLE_VEC4_EXT 0x8FFE +#define GL_DOUBLE_MAT2_EXT 0x8F46 +#define GL_DOUBLE_MAT3_EXT 0x8F47 +#define GL_DOUBLE_MAT4_EXT 0x8F48 +#define GL_DOUBLE_MAT2x3_EXT 0x8F49 +#define GL_DOUBLE_MAT2x4_EXT 0x8F4A +#define GL_DOUBLE_MAT3x2_EXT 0x8F4B +#define GL_DOUBLE_MAT3x4_EXT 0x8F4C +#define GL_DOUBLE_MAT4x2_EXT 0x8F4D +#define GL_DOUBLE_MAT4x3_EXT 0x8F4E +#endif + +#ifndef GL_NV_gpu_program5 +#define GL_MAX_GEOMETRY_PROGRAM_INVOCATIONS_NV 0x8E5A +#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET_NV 0x8E5B +#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET_NV 0x8E5C +#define GL_FRAGMENT_PROGRAM_INTERPOLATION_OFFSET_BITS_NV 0x8E5D +#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_NV 0x8E5E +#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_NV 0x8E5F +#define GL_MAX_PROGRAM_SUBROUTINE_PARAMETERS_NV 0x8F44 +#define GL_MAX_PROGRAM_SUBROUTINE_NUM_NV 0x8F45 +#endif + +#ifndef GL_NV_gpu_shader5 +#define GL_INT64_NV 0x140E +#define GL_UNSIGNED_INT64_NV 0x140F +#define GL_INT8_NV 0x8FE0 +#define GL_INT8_VEC2_NV 0x8FE1 +#define GL_INT8_VEC3_NV 0x8FE2 +#define GL_INT8_VEC4_NV 0x8FE3 +#define GL_INT16_NV 0x8FE4 +#define GL_INT16_VEC2_NV 0x8FE5 +#define GL_INT16_VEC3_NV 0x8FE6 +#define GL_INT16_VEC4_NV 0x8FE7 +#define GL_INT64_VEC2_NV 0x8FE9 +#define GL_INT64_VEC3_NV 0x8FEA +#define GL_INT64_VEC4_NV 0x8FEB +#define GL_UNSIGNED_INT8_NV 0x8FEC +#define GL_UNSIGNED_INT8_VEC2_NV 0x8FED +#define GL_UNSIGNED_INT8_VEC3_NV 0x8FEE +#define GL_UNSIGNED_INT8_VEC4_NV 0x8FEF +#define GL_UNSIGNED_INT16_NV 0x8FF0 +#define GL_UNSIGNED_INT16_VEC2_NV 0x8FF1 +#define GL_UNSIGNED_INT16_VEC3_NV 0x8FF2 +#define GL_UNSIGNED_INT16_VEC4_NV 0x8FF3 +#define GL_UNSIGNED_INT64_VEC2_NV 0x8FF5 +#define GL_UNSIGNED_INT64_VEC3_NV 0x8FF6 +#define GL_UNSIGNED_INT64_VEC4_NV 0x8FF7 +#define GL_FLOAT16_NV 0x8FF8 +#define GL_FLOAT16_VEC2_NV 0x8FF9 +#define GL_FLOAT16_VEC3_NV 0x8FFA +#define GL_FLOAT16_VEC4_NV 0x8FFB +/* reuse GL_PATCHES */ +#endif + +#ifndef GL_NV_shader_buffer_store +#define GL_SHADER_GLOBAL_ACCESS_BARRIER_BIT_NV 0x00000010 +/* reuse GL_READ_WRITE */ +/* reuse GL_WRITE_ONLY */ +#endif + +#ifndef GL_NV_tessellation_program5 +#define GL_MAX_PROGRAM_PATCH_ATTRIBS_NV 0x86D8 +#define GL_TESS_CONTROL_PROGRAM_NV 0x891E +#define GL_TESS_EVALUATION_PROGRAM_NV 0x891F +#define GL_TESS_CONTROL_PROGRAM_PARAMETER_BUFFER_NV 0x8C74 +#define GL_TESS_EVALUATION_PROGRAM_PARAMETER_BUFFER_NV 0x8C75 +#endif + +#ifndef GL_NV_vertex_attrib_integer_64bit +/* reuse GL_INT64_NV */ +/* reuse GL_UNSIGNED_INT64_NV */ +#endif + +#ifndef GL_NV_multisample_coverage +#define GL_COVERAGE_SAMPLES_NV 0x80A9 +#define GL_COLOR_SAMPLES_NV 0x8E20 +#endif + +#ifndef GL_AMD_name_gen_delete +#define GL_DATA_BUFFER_AMD 0x9151 +#define GL_PERFORMANCE_MONITOR_AMD 0x9152 +#define GL_QUERY_OBJECT_AMD 0x9153 +#define GL_VERTEX_ARRAY_OBJECT_AMD 0x9154 +#define GL_SAMPLER_OBJECT_AMD 0x9155 +#endif + +#ifndef GL_AMD_debug_output +#define GL_MAX_DEBUG_LOGGED_MESSAGES_AMD 0x9144 +#define GL_DEBUG_LOGGED_MESSAGES_AMD 0x9145 +#define GL_DEBUG_SEVERITY_HIGH_AMD 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM_AMD 0x9147 +#define GL_DEBUG_SEVERITY_LOW_AMD 0x9148 +#define GL_DEBUG_CATEGORY_API_ERROR_AMD 0x9149 +#define GL_DEBUG_CATEGORY_WINDOW_SYSTEM_AMD 0x914A +#define GL_DEBUG_CATEGORY_DEPRECATION_AMD 0x914B +#define GL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR_AMD 0x914C +#define GL_DEBUG_CATEGORY_PERFORMANCE_AMD 0x914D +#define GL_DEBUG_CATEGORY_SHADER_COMPILER_AMD 0x914E +#define GL_DEBUG_CATEGORY_APPLICATION_AMD 0x914F +#define GL_DEBUG_CATEGORY_OTHER_AMD 0x9150 +#endif + +#ifndef GL_NV_vdpau_interop +#define GL_SURFACE_STATE_NV 0x86EB +#define GL_SURFACE_REGISTERED_NV 0x86FD +#define GL_SURFACE_MAPPED_NV 0x8700 +#define GL_WRITE_DISCARD_NV 0x88BE +#endif + +#ifndef GL_AMD_transform_feedback3_lines_triangles +#endif + +#ifndef GL_AMD_depth_clamp_separate +#define GL_DEPTH_CLAMP_NEAR_AMD 0x901E +#define GL_DEPTH_CLAMP_FAR_AMD 0x901F +#endif + + +/*************************************************************/ + +#include +#ifndef GL_VERSION_2_0 +/* GL type for program/shader text */ +typedef char GLchar; +#endif + +#ifndef GL_VERSION_1_5 +/* GL types for handling large vertex buffer objects */ +typedef ptrdiff_t GLintptr; +typedef ptrdiff_t GLsizeiptr; +#endif + +#ifndef GL_ARB_vertex_buffer_object +/* GL types for handling large vertex buffer objects */ +typedef ptrdiff_t GLintptrARB; +typedef ptrdiff_t GLsizeiptrARB; +#endif + +#ifndef GL_ARB_shader_objects +/* GL types for program/shader text and shader object handles */ +typedef char GLcharARB; +typedef unsigned int GLhandleARB; +#endif + +/* GL type for "half" precision (s10e5) float data in host memory */ +#ifndef GL_ARB_half_float_pixel +typedef unsigned short GLhalfARB; +#endif + +#ifndef GL_NV_half_float +typedef unsigned short GLhalfNV; +#endif + +#ifndef GLEXT_64_TYPES_DEFINED +/* This code block is duplicated in glxext.h, so must be protected */ +#define GLEXT_64_TYPES_DEFINED +/* Define int32_t, int64_t, and uint64_t types for UST/MSC */ +/* (as used in the GL_EXT_timer_query extension). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#include +#elif defined(__sun__) || defined(__digital__) +#include +#if defined(__STDC__) +#if defined(__arch64__) || defined(_LP64) +typedef long int int64_t; +typedef unsigned long int uint64_t; +#else +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#endif /* __arch64__ */ +#endif /* __STDC__ */ +#elif defined( __VMS ) || defined(__sgi) +#include +#elif defined(__SCO__) || defined(__USLC__) +#include +#elif defined(__UNIXOS2__) || defined(__SOL64__) +typedef long int int32_t; +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#elif defined(_WIN32) && defined(__GNUC__) +#include +#elif defined(_WIN32) +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +#else +/* Fallback if nothing above works */ +#include +#endif +#endif + +#ifndef GL_EXT_timer_query +typedef int64_t GLint64EXT; +typedef uint64_t GLuint64EXT; +#endif + +#ifndef GL_ARB_sync +typedef int64_t GLint64; +typedef uint64_t GLuint64; +typedef struct __GLsync *GLsync; +#endif + +#ifndef GL_ARB_cl_event +/* These incomplete types let us declare types compatible with OpenCL's cl_context and cl_event */ +struct _cl_context; +struct _cl_event; +#endif + +#ifndef GL_ARB_debug_output +typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); +#endif + +#ifndef GL_AMD_debug_output +typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam); +#endif + +#ifndef GL_NV_vdpau_interop +typedef GLintptr GLvdpauSurfaceNV; +#endif + +#ifndef GL_VERSION_1_2 +#define GL_VERSION_1_2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +GLAPI void APIENTRY glBlendEquation (GLenum mode); +GLAPI void APIENTRY glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +GLAPI void APIENTRY glTexImage3D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_VERSION_1_2_DEPRECATED +#define GL_VERSION_1_2_DEPRECATED 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTable (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +GLAPI void APIENTRY glColorTableParameterfv (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glColorTableParameteriv (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glCopyColorTable (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glGetColorTable (GLenum target, GLenum format, GLenum type, GLvoid *table); +GLAPI void APIENTRY glGetColorTableParameterfv (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetColorTableParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glColorSubTable (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); +GLAPI void APIENTRY glCopyColorSubTable (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glConvolutionFilter1D (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); +GLAPI void APIENTRY glConvolutionFilter2D (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); +GLAPI void APIENTRY glConvolutionParameterf (GLenum target, GLenum pname, GLfloat params); +GLAPI void APIENTRY glConvolutionParameterfv (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glConvolutionParameteri (GLenum target, GLenum pname, GLint params); +GLAPI void APIENTRY glConvolutionParameteriv (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glCopyConvolutionFilter1D (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyConvolutionFilter2D (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetConvolutionFilter (GLenum target, GLenum format, GLenum type, GLvoid *image); +GLAPI void APIENTRY glGetConvolutionParameterfv (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetConvolutionParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSeparableFilter (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); +GLAPI void APIENTRY glSeparableFilter2D (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); +GLAPI void APIENTRY glGetHistogram (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +GLAPI void APIENTRY glGetHistogramParameterfv (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetHistogramParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMinmax (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +GLAPI void APIENTRY glGetMinmaxParameterfv (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMinmaxParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glHistogram (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +GLAPI void APIENTRY glMinmax (GLenum target, GLenum internalformat, GLboolean sink); +GLAPI void APIENTRY glResetHistogram (GLenum target); +GLAPI void APIENTRY glResetMinmax (GLenum target); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIPROC) (GLenum target, GLenum pname, GLint params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTERPROC) (GLenum target, GLenum format, GLenum type, GLvoid *image); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSEPARABLEFILTERPROC) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); +typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMINMAXPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLHISTOGRAMPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLMINMAXPROC) (GLenum target, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLRESETHISTOGRAMPROC) (GLenum target); +typedef void (APIENTRYP PFNGLRESETMINMAXPROC) (GLenum target); +#endif + +#ifndef GL_VERSION_1_3 +#define GL_VERSION_1_3 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveTexture (GLenum texture); +GLAPI void APIENTRY glSampleCoverage (GLclampf value, GLboolean invert); +GLAPI void APIENTRY glCompressedTexImage3D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexImage1D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glGetCompressedTexImage (GLenum target, GLint level, GLvoid *img); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img); +#endif + +#ifndef GL_VERSION_1_3_DEPRECATED +#define GL_VERSION_1_3_DEPRECATED 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClientActiveTexture (GLenum texture); +GLAPI void APIENTRY glMultiTexCoord1d (GLenum target, GLdouble s); +GLAPI void APIENTRY glMultiTexCoord1dv (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord1f (GLenum target, GLfloat s); +GLAPI void APIENTRY glMultiTexCoord1fv (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord1i (GLenum target, GLint s); +GLAPI void APIENTRY glMultiTexCoord1iv (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord1s (GLenum target, GLshort s); +GLAPI void APIENTRY glMultiTexCoord1sv (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord2d (GLenum target, GLdouble s, GLdouble t); +GLAPI void APIENTRY glMultiTexCoord2dv (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord2f (GLenum target, GLfloat s, GLfloat t); +GLAPI void APIENTRY glMultiTexCoord2fv (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord2i (GLenum target, GLint s, GLint t); +GLAPI void APIENTRY glMultiTexCoord2iv (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord2s (GLenum target, GLshort s, GLshort t); +GLAPI void APIENTRY glMultiTexCoord2sv (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord3d (GLenum target, GLdouble s, GLdouble t, GLdouble r); +GLAPI void APIENTRY glMultiTexCoord3dv (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord3f (GLenum target, GLfloat s, GLfloat t, GLfloat r); +GLAPI void APIENTRY glMultiTexCoord3fv (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord3i (GLenum target, GLint s, GLint t, GLint r); +GLAPI void APIENTRY glMultiTexCoord3iv (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord3s (GLenum target, GLshort s, GLshort t, GLshort r); +GLAPI void APIENTRY glMultiTexCoord3sv (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord4d (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +GLAPI void APIENTRY glMultiTexCoord4dv (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord4f (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +GLAPI void APIENTRY glMultiTexCoord4fv (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord4i (GLenum target, GLint s, GLint t, GLint r, GLint q); +GLAPI void APIENTRY glMultiTexCoord4iv (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord4s (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +GLAPI void APIENTRY glMultiTexCoord4sv (GLenum target, const GLshort *v); +GLAPI void APIENTRY glLoadTransposeMatrixf (const GLfloat *m); +GLAPI void APIENTRY glLoadTransposeMatrixd (const GLdouble *m); +GLAPI void APIENTRY glMultTransposeMatrixf (const GLfloat *m); +GLAPI void APIENTRY glMultTransposeMatrixd (const GLdouble *m); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDPROC) (const GLdouble *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDPROC) (const GLdouble *m); +#endif + +#ifndef GL_VERSION_1_4 +#define GL_VERSION_1_4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +GLAPI void APIENTRY glMultiDrawArrays (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +GLAPI void APIENTRY glMultiDrawElements (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +GLAPI void APIENTRY glPointParameterf (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glPointParameteri (GLenum pname, GLint param); +GLAPI void APIENTRY glPointParameteriv (GLenum pname, const GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_VERSION_1_4_DEPRECATED +#define GL_VERSION_1_4_DEPRECATED 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogCoordf (GLfloat coord); +GLAPI void APIENTRY glFogCoordfv (const GLfloat *coord); +GLAPI void APIENTRY glFogCoordd (GLdouble coord); +GLAPI void APIENTRY glFogCoorddv (const GLdouble *coord); +GLAPI void APIENTRY glFogCoordPointer (GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glSecondaryColor3b (GLbyte red, GLbyte green, GLbyte blue); +GLAPI void APIENTRY glSecondaryColor3bv (const GLbyte *v); +GLAPI void APIENTRY glSecondaryColor3d (GLdouble red, GLdouble green, GLdouble blue); +GLAPI void APIENTRY glSecondaryColor3dv (const GLdouble *v); +GLAPI void APIENTRY glSecondaryColor3f (GLfloat red, GLfloat green, GLfloat blue); +GLAPI void APIENTRY glSecondaryColor3fv (const GLfloat *v); +GLAPI void APIENTRY glSecondaryColor3i (GLint red, GLint green, GLint blue); +GLAPI void APIENTRY glSecondaryColor3iv (const GLint *v); +GLAPI void APIENTRY glSecondaryColor3s (GLshort red, GLshort green, GLshort blue); +GLAPI void APIENTRY glSecondaryColor3sv (const GLshort *v); +GLAPI void APIENTRY glSecondaryColor3ub (GLubyte red, GLubyte green, GLubyte blue); +GLAPI void APIENTRY glSecondaryColor3ubv (const GLubyte *v); +GLAPI void APIENTRY glSecondaryColor3ui (GLuint red, GLuint green, GLuint blue); +GLAPI void APIENTRY glSecondaryColor3uiv (const GLuint *v); +GLAPI void APIENTRY glSecondaryColor3us (GLushort red, GLushort green, GLushort blue); +GLAPI void APIENTRY glSecondaryColor3usv (const GLushort *v); +GLAPI void APIENTRY glSecondaryColorPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glWindowPos2d (GLdouble x, GLdouble y); +GLAPI void APIENTRY glWindowPos2dv (const GLdouble *v); +GLAPI void APIENTRY glWindowPos2f (GLfloat x, GLfloat y); +GLAPI void APIENTRY glWindowPos2fv (const GLfloat *v); +GLAPI void APIENTRY glWindowPos2i (GLint x, GLint y); +GLAPI void APIENTRY glWindowPos2iv (const GLint *v); +GLAPI void APIENTRY glWindowPos2s (GLshort x, GLshort y); +GLAPI void APIENTRY glWindowPos2sv (const GLshort *v); +GLAPI void APIENTRY glWindowPos3d (GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glWindowPos3dv (const GLdouble *v); +GLAPI void APIENTRY glWindowPos3f (GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glWindowPos3fv (const GLfloat *v); +GLAPI void APIENTRY glWindowPos3i (GLint x, GLint y, GLint z); +GLAPI void APIENTRY glWindowPos3iv (const GLint *v); +GLAPI void APIENTRY glWindowPos3s (GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glWindowPos3sv (const GLshort *v); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFOGCOORDFPROC) (GLfloat coord); +typedef void (APIENTRYP PFNGLFOGCOORDFVPROC) (const GLfloat *coord); +typedef void (APIENTRYP PFNGLFOGCOORDDPROC) (GLdouble coord); +typedef void (APIENTRYP PFNGLFOGCOORDDVPROC) (const GLdouble *coord); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BPROC) (GLbyte red, GLbyte green, GLbyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DPROC) (GLdouble red, GLdouble green, GLdouble blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FPROC) (GLfloat red, GLfloat green, GLfloat blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IPROC) (GLint red, GLint green, GLint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SPROC) (GLshort red, GLshort green, GLshort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBPROC) (GLubyte red, GLubyte green, GLubyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVPROC) (const GLubyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIPROC) (GLuint red, GLuint green, GLuint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVPROC) (const GLuint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USPROC) (GLushort red, GLushort green, GLushort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVPROC) (const GLushort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLWINDOWPOS2DPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVPROC) (const GLshort *v); +#endif + +#ifndef GL_VERSION_1_5 +#define GL_VERSION_1_5 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenQueries (GLsizei n, GLuint *ids); +GLAPI void APIENTRY glDeleteQueries (GLsizei n, const GLuint *ids); +GLAPI GLboolean APIENTRY glIsQuery (GLuint id); +GLAPI void APIENTRY glBeginQuery (GLenum target, GLuint id); +GLAPI void APIENTRY glEndQuery (GLenum target); +GLAPI void APIENTRY glGetQueryiv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectiv (GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint *params); +GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer); +GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers); +GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers); +GLAPI GLboolean APIENTRY glIsBuffer (GLuint buffer); +GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); +GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); +GLAPI void APIENTRY glGetBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); +GLAPI GLvoid* APIENTRY glMapBuffer (GLenum target, GLenum access); +GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum target); +GLAPI void APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetBufferPointerv (GLenum target, GLenum pname, GLvoid* *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); +typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_VERSION_2_0 +#define GL_VERSION_2_0 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glDrawBuffers (GLsizei n, const GLenum *bufs); +GLAPI void APIENTRY glStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +GLAPI void APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask); +GLAPI void APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask); +GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader); +GLAPI void APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar *name); +GLAPI void APIENTRY glCompileShader (GLuint shader); +GLAPI GLuint APIENTRY glCreateProgram (void); +GLAPI GLuint APIENTRY glCreateShader (GLenum type); +GLAPI void APIENTRY glDeleteProgram (GLuint program); +GLAPI void APIENTRY glDeleteShader (GLuint shader); +GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader); +GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index); +GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index); +GLAPI void APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); +GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +GLAPI void APIENTRY glGetShaderSource (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); +GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat *params); +GLAPI void APIENTRY glGetUniformiv (GLuint program, GLint location, GLint *params); +GLAPI void APIENTRY glGetVertexAttribdv (GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid* *pointer); +GLAPI GLboolean APIENTRY glIsProgram (GLuint program); +GLAPI GLboolean APIENTRY glIsShader (GLuint shader); +GLAPI void APIENTRY glLinkProgram (GLuint program); +GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* *string, const GLint *length); +GLAPI void APIENTRY glUseProgram (GLuint program); +GLAPI void APIENTRY glUniform1f (GLint location, GLfloat v0); +GLAPI void APIENTRY glUniform2f (GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glUniform1i (GLint location, GLint v0); +GLAPI void APIENTRY glUniform2i (GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glUniform3i (GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glUniform4i (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glValidateProgram (GLuint program); +GLAPI void APIENTRY glVertexAttrib1d (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttrib1dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib1f (GLuint index, GLfloat x); +GLAPI void APIENTRY glVertexAttrib1fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib1s (GLuint index, GLshort x); +GLAPI void APIENTRY glVertexAttrib1sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib2d (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttrib2dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib2f (GLuint index, GLfloat x, GLfloat y); +GLAPI void APIENTRY glVertexAttrib2fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib2s (GLuint index, GLshort x, GLshort y); +GLAPI void APIENTRY glVertexAttrib2sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttrib3dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib3f (GLuint index, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glVertexAttrib3fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib3s (GLuint index, GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glVertexAttrib3sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4Nbv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4Niv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4Nsv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4Nub (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +GLAPI void APIENTRY glVertexAttrib4Nubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4Nuiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4Nusv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttrib4bv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttrib4dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib4f (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glVertexAttrib4fv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib4iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4s (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glVertexAttrib4sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4ubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4usv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs); +typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum face, GLenum func, GLint ref, GLuint mask); +typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, GLuint mask); +typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar *name); +typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader); +typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); +typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat *params); +typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program); +typedef GLboolean (APIENTRYP PFNGLISSHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* *string, const GLint *length); +typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_VERSION_2_1 +#define GL_VERSION_2_1 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUniformMatrix2x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix2x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +#endif + +#ifndef GL_VERSION_3_0 +#define GL_VERSION_3_0 1 +/* OpenGL 3.0 also reuses entry points from these extensions: */ +/* ARB_framebuffer_object */ +/* ARB_map_buffer_range */ +/* ARB_vertex_array_object */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorMaski (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +GLAPI void APIENTRY glGetBooleani_v (GLenum target, GLuint index, GLboolean *data); +GLAPI void APIENTRY glGetIntegeri_v (GLenum target, GLuint index, GLint *data); +GLAPI void APIENTRY glEnablei (GLenum target, GLuint index); +GLAPI void APIENTRY glDisablei (GLenum target, GLuint index); +GLAPI GLboolean APIENTRY glIsEnabledi (GLenum target, GLuint index); +GLAPI void APIENTRY glBeginTransformFeedback (GLenum primitiveMode); +GLAPI void APIENTRY glEndTransformFeedback (void); +GLAPI void APIENTRY glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glBindBufferBase (GLenum target, GLuint index, GLuint buffer); +GLAPI void APIENTRY glTransformFeedbackVaryings (GLuint program, GLsizei count, const GLchar* *varyings, GLenum bufferMode); +GLAPI void APIENTRY glGetTransformFeedbackVarying (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glClampColor (GLenum target, GLenum clamp); +GLAPI void APIENTRY glBeginConditionalRender (GLuint id, GLenum mode); +GLAPI void APIENTRY glEndConditionalRender (void); +GLAPI void APIENTRY glVertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glGetVertexAttribIiv (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribIuiv (GLuint index, GLenum pname, GLuint *params); +GLAPI void APIENTRY glVertexAttribI1i (GLuint index, GLint x); +GLAPI void APIENTRY glVertexAttribI2i (GLuint index, GLint x, GLint y); +GLAPI void APIENTRY glVertexAttribI3i (GLuint index, GLint x, GLint y, GLint z); +GLAPI void APIENTRY glVertexAttribI4i (GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glVertexAttribI1ui (GLuint index, GLuint x); +GLAPI void APIENTRY glVertexAttribI2ui (GLuint index, GLuint x, GLuint y); +GLAPI void APIENTRY glVertexAttribI3ui (GLuint index, GLuint x, GLuint y, GLuint z); +GLAPI void APIENTRY glVertexAttribI4ui (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glVertexAttribI1iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI2iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI3iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI4iv (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI1uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI2uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI3uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4uiv (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4bv (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttribI4sv (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttribI4ubv (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttribI4usv (GLuint index, const GLushort *v); +GLAPI void APIENTRY glGetUniformuiv (GLuint program, GLint location, GLuint *params); +GLAPI void APIENTRY glBindFragDataLocation (GLuint program, GLuint color, const GLchar *name); +GLAPI GLint APIENTRY glGetFragDataLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glUniform1ui (GLint location, GLuint v0); +GLAPI void APIENTRY glUniform2ui (GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glUniform3ui (GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glUniform4ui (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glUniform1uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform2uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform3uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform4uiv (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glTexParameterIiv (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTexParameterIuiv (GLenum target, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glGetTexParameterIiv (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTexParameterIuiv (GLenum target, GLenum pname, GLuint *params); +GLAPI void APIENTRY glClearBufferiv (GLenum buffer, GLint drawbuffer, const GLint *value); +GLAPI void APIENTRY glClearBufferuiv (GLenum buffer, GLint drawbuffer, const GLuint *value); +GLAPI void APIENTRY glClearBufferfv (GLenum buffer, GLint drawbuffer, const GLfloat *value); +GLAPI void APIENTRY glClearBufferfi (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +GLAPI const GLubyte * APIENTRY glGetStringi (GLenum name, GLuint index); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORMASKIPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data); +typedef void (APIENTRYP PFNGLENABLEIPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLDISABLEIPROC) (GLenum target, GLuint index); +typedef GLboolean (APIENTRYP PFNGLISENABLEDIPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKPROC) (GLenum primitiveMode); +typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLBINDBUFFERRANGEPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLBINDBUFFERBASEPROC) (GLenum target, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSPROC) (GLuint program, GLsizei count, const GLchar* *varyings, GLenum bufferMode); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLCLAMPCOLORPROC) (GLenum target, GLenum clamp); +typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERPROC) (GLuint id, GLenum mode); +typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERPROC) (void); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVPROC) (GLuint index, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IPROC) (GLuint index, GLint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IPROC) (GLuint index, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IPROC) (GLuint index, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIPROC) (GLuint index, GLuint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIPROC) (GLuint index, GLuint x, GLuint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLGETUNIFORMUIVPROC) (GLuint program, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONPROC) (GLuint program, GLuint color, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORM1UIPROC) (GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLUNIFORM2UIPROC) (GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLUNIFORM3UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLUNIFORM4UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLUNIFORM1UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM2UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM3UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM4UIVPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLCLEARBUFFERIVPROC) (GLenum buffer, GLint drawbuffer, const GLint *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERUIVPROC) (GLenum buffer, GLint drawbuffer, const GLuint *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERFVPROC) (GLenum buffer, GLint drawbuffer, const GLfloat *value); +typedef void (APIENTRYP PFNGLCLEARBUFFERFIPROC) (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); +typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index); +#endif + +#ifndef GL_VERSION_3_1 +#define GL_VERSION_3_1 1 +/* OpenGL 3.1 also reuses entry points from these extensions: */ +/* ARB_copy_buffer */ +/* ARB_uniform_buffer_object */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +GLAPI void APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +GLAPI void APIENTRY glTexBuffer (GLenum target, GLenum internalformat, GLuint buffer); +GLAPI void APIENTRY glPrimitiveRestartIndex (GLuint index); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +typedef void (APIENTRYP PFNGLTEXBUFFERPROC) (GLenum target, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC) (GLuint index); +#endif + +#ifndef GL_VERSION_3_2 +#define GL_VERSION_3_2 1 +/* OpenGL 3.2 also reuses entry points from these extensions: */ +/* ARB_draw_elements_base_vertex */ +/* ARB_provoking_vertex */ +/* ARB_sync */ +/* ARB_texture_multisample */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetInteger64i_v (GLenum target, GLuint index, GLint64 *data); +GLAPI void APIENTRY glGetBufferParameteri64v (GLenum target, GLenum pname, GLint64 *params); +GLAPI void APIENTRY glFramebufferTexture (GLenum target, GLenum attachment, GLuint texture, GLint level); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERI64VPROC) (GLenum target, GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); +#endif + +#ifndef GL_VERSION_3_3 +#define GL_VERSION_3_3 1 +/* OpenGL 3.3 also reuses entry points from these extensions: */ +/* ARB_blend_func_extended */ +/* ARB_sampler_objects */ +/* ARB_explicit_attrib_location, but it has none */ +/* ARB_occlusion_query2 (no entry points) */ +/* ARB_shader_bit_encoding (no entry points) */ +/* ARB_texture_rgb10_a2ui (no entry points) */ +/* ARB_texture_swizzle (no entry points) */ +/* ARB_timer_query */ +/* ARB_vertex_type_2_10_10_10_rev */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribDivisor (GLuint index, GLuint divisor); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORPROC) (GLuint index, GLuint divisor); +#endif + +#ifndef GL_VERSION_4_0 +#define GL_VERSION_4_0 1 +/* OpenGL 4.0 also reuses entry points from these extensions: */ +/* ARB_texture_query_lod (no entry points) */ +/* ARB_draw_indirect */ +/* ARB_gpu_shader5 (no entry points) */ +/* ARB_gpu_shader_fp64 */ +/* ARB_shader_subroutine */ +/* ARB_tessellation_shader */ +/* ARB_texture_buffer_object_rgb32 (no entry points) */ +/* ARB_texture_cube_map_array (no entry points) */ +/* ARB_texture_gather (no entry points) */ +/* ARB_transform_feedback2 */ +/* ARB_transform_feedback3 */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMinSampleShading (GLclampf value); +GLAPI void APIENTRY glBlendEquationi (GLuint buf, GLenum mode); +GLAPI void APIENTRY glBlendEquationSeparatei (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glBlendFunci (GLuint buf, GLenum src, GLenum dst); +GLAPI void APIENTRY glBlendFuncSeparatei (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMINSAMPLESHADINGPROC) (GLclampf value); +typedef void (APIENTRYP PFNGLBLENDEQUATIONIPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLBLENDFUNCIPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif + +#ifndef GL_VERSION_4_1 +#define GL_VERSION_4_1 1 +/* OpenGL 4.1 also reuses entry points from these extensions: */ +/* ARB_ES2_compatibility */ +/* ARB_get_program_binary */ +/* ARB_separate_shader_objects */ +/* ARB_shader_precision (no entry points) */ +/* ARB_vertex_attrib_64bit */ +/* ARB_viewport_array */ +#endif + +#ifndef GL_ARB_multitexture +#define GL_ARB_multitexture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveTextureARB (GLenum texture); +GLAPI void APIENTRY glClientActiveTextureARB (GLenum texture); +GLAPI void APIENTRY glMultiTexCoord1dARB (GLenum target, GLdouble s); +GLAPI void APIENTRY glMultiTexCoord1dvARB (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord1fARB (GLenum target, GLfloat s); +GLAPI void APIENTRY glMultiTexCoord1fvARB (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord1iARB (GLenum target, GLint s); +GLAPI void APIENTRY glMultiTexCoord1ivARB (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord1sARB (GLenum target, GLshort s); +GLAPI void APIENTRY glMultiTexCoord1svARB (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord2dARB (GLenum target, GLdouble s, GLdouble t); +GLAPI void APIENTRY glMultiTexCoord2dvARB (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord2fARB (GLenum target, GLfloat s, GLfloat t); +GLAPI void APIENTRY glMultiTexCoord2fvARB (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord2iARB (GLenum target, GLint s, GLint t); +GLAPI void APIENTRY glMultiTexCoord2ivARB (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord2sARB (GLenum target, GLshort s, GLshort t); +GLAPI void APIENTRY glMultiTexCoord2svARB (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord3dARB (GLenum target, GLdouble s, GLdouble t, GLdouble r); +GLAPI void APIENTRY glMultiTexCoord3dvARB (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord3fARB (GLenum target, GLfloat s, GLfloat t, GLfloat r); +GLAPI void APIENTRY glMultiTexCoord3fvARB (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord3iARB (GLenum target, GLint s, GLint t, GLint r); +GLAPI void APIENTRY glMultiTexCoord3ivARB (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord3sARB (GLenum target, GLshort s, GLshort t, GLshort r); +GLAPI void APIENTRY glMultiTexCoord3svARB (GLenum target, const GLshort *v); +GLAPI void APIENTRY glMultiTexCoord4dARB (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +GLAPI void APIENTRY glMultiTexCoord4dvARB (GLenum target, const GLdouble *v); +GLAPI void APIENTRY glMultiTexCoord4fARB (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +GLAPI void APIENTRY glMultiTexCoord4fvARB (GLenum target, const GLfloat *v); +GLAPI void APIENTRY glMultiTexCoord4iARB (GLenum target, GLint s, GLint t, GLint r, GLint q); +GLAPI void APIENTRY glMultiTexCoord4ivARB (GLenum target, const GLint *v); +GLAPI void APIENTRY glMultiTexCoord4sARB (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +GLAPI void APIENTRY glMultiTexCoord4svARB (GLenum target, const GLshort *v); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v); +#endif + +#ifndef GL_ARB_transpose_matrix +#define GL_ARB_transpose_matrix 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glLoadTransposeMatrixfARB (const GLfloat *m); +GLAPI void APIENTRY glLoadTransposeMatrixdARB (const GLdouble *m); +GLAPI void APIENTRY glMultTransposeMatrixfARB (const GLfloat *m); +GLAPI void APIENTRY glMultTransposeMatrixdARB (const GLdouble *m); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); +#endif + +#ifndef GL_ARB_multisample +#define GL_ARB_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleCoverageARB (GLclampf value, GLboolean invert); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEARBPROC) (GLclampf value, GLboolean invert); +#endif + +#ifndef GL_ARB_texture_env_add +#define GL_ARB_texture_env_add 1 +#endif + +#ifndef GL_ARB_texture_cube_map +#define GL_ARB_texture_cube_map 1 +#endif + +#ifndef GL_ARB_texture_compression +#define GL_ARB_texture_compression 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCompressedTexImage3DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexImage2DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexImage1DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage3DARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage2DARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glCompressedTexSubImage1DARB (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +GLAPI void APIENTRY glGetCompressedTexImageARB (GLenum target, GLint level, GLvoid *img); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint level, GLvoid *img); +#endif + +#ifndef GL_ARB_texture_border_clamp +#define GL_ARB_texture_border_clamp 1 +#endif + +#ifndef GL_ARB_point_parameters +#define GL_ARB_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfARB (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPointParameterfvARB (GLenum pname, const GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFARBPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVARBPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_ARB_vertex_blend +#define GL_ARB_vertex_blend 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWeightbvARB (GLint size, const GLbyte *weights); +GLAPI void APIENTRY glWeightsvARB (GLint size, const GLshort *weights); +GLAPI void APIENTRY glWeightivARB (GLint size, const GLint *weights); +GLAPI void APIENTRY glWeightfvARB (GLint size, const GLfloat *weights); +GLAPI void APIENTRY glWeightdvARB (GLint size, const GLdouble *weights); +GLAPI void APIENTRY glWeightubvARB (GLint size, const GLubyte *weights); +GLAPI void APIENTRY glWeightusvARB (GLint size, const GLushort *weights); +GLAPI void APIENTRY glWeightuivARB (GLint size, const GLuint *weights); +GLAPI void APIENTRY glWeightPointerARB (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glVertexBlendARB (GLint count); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWEIGHTBVARBPROC) (GLint size, const GLbyte *weights); +typedef void (APIENTRYP PFNGLWEIGHTSVARBPROC) (GLint size, const GLshort *weights); +typedef void (APIENTRYP PFNGLWEIGHTIVARBPROC) (GLint size, const GLint *weights); +typedef void (APIENTRYP PFNGLWEIGHTFVARBPROC) (GLint size, const GLfloat *weights); +typedef void (APIENTRYP PFNGLWEIGHTDVARBPROC) (GLint size, const GLdouble *weights); +typedef void (APIENTRYP PFNGLWEIGHTUBVARBPROC) (GLint size, const GLubyte *weights); +typedef void (APIENTRYP PFNGLWEIGHTUSVARBPROC) (GLint size, const GLushort *weights); +typedef void (APIENTRYP PFNGLWEIGHTUIVARBPROC) (GLint size, const GLuint *weights); +typedef void (APIENTRYP PFNGLWEIGHTPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXBLENDARBPROC) (GLint count); +#endif + +#ifndef GL_ARB_matrix_palette +#define GL_ARB_matrix_palette 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCurrentPaletteMatrixARB (GLint index); +GLAPI void APIENTRY glMatrixIndexubvARB (GLint size, const GLubyte *indices); +GLAPI void APIENTRY glMatrixIndexusvARB (GLint size, const GLushort *indices); +GLAPI void APIENTRY glMatrixIndexuivARB (GLint size, const GLuint *indices); +GLAPI void APIENTRY glMatrixIndexPointerARB (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCURRENTPALETTEMATRIXARBPROC) (GLint index); +typedef void (APIENTRYP PFNGLMATRIXINDEXUBVARBPROC) (GLint size, const GLubyte *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXUSVARBPROC) (GLint size, const GLushort *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXUIVARBPROC) (GLint size, const GLuint *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_ARB_texture_env_combine +#define GL_ARB_texture_env_combine 1 +#endif + +#ifndef GL_ARB_texture_env_crossbar +#define GL_ARB_texture_env_crossbar 1 +#endif + +#ifndef GL_ARB_texture_env_dot3 +#define GL_ARB_texture_env_dot3 1 +#endif + +#ifndef GL_ARB_texture_mirrored_repeat +#define GL_ARB_texture_mirrored_repeat 1 +#endif + +#ifndef GL_ARB_depth_texture +#define GL_ARB_depth_texture 1 +#endif + +#ifndef GL_ARB_shadow +#define GL_ARB_shadow 1 +#endif + +#ifndef GL_ARB_shadow_ambient +#define GL_ARB_shadow_ambient 1 +#endif + +#ifndef GL_ARB_window_pos +#define GL_ARB_window_pos 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWindowPos2dARB (GLdouble x, GLdouble y); +GLAPI void APIENTRY glWindowPos2dvARB (const GLdouble *v); +GLAPI void APIENTRY glWindowPos2fARB (GLfloat x, GLfloat y); +GLAPI void APIENTRY glWindowPos2fvARB (const GLfloat *v); +GLAPI void APIENTRY glWindowPos2iARB (GLint x, GLint y); +GLAPI void APIENTRY glWindowPos2ivARB (const GLint *v); +GLAPI void APIENTRY glWindowPos2sARB (GLshort x, GLshort y); +GLAPI void APIENTRY glWindowPos2svARB (const GLshort *v); +GLAPI void APIENTRY glWindowPos3dARB (GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glWindowPos3dvARB (const GLdouble *v); +GLAPI void APIENTRY glWindowPos3fARB (GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glWindowPos3fvARB (const GLfloat *v); +GLAPI void APIENTRY glWindowPos3iARB (GLint x, GLint y, GLint z); +GLAPI void APIENTRY glWindowPos3ivARB (const GLint *v); +GLAPI void APIENTRY glWindowPos3sARB (GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glWindowPos3svARB (const GLshort *v); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWINDOWPOS2DARBPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVARBPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FARBPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVARBPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IARBPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVARBPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SARBPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVARBPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DARBPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVARBPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FARBPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVARBPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IARBPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVARBPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SARBPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVARBPROC) (const GLshort *v); +#endif + +#ifndef GL_ARB_vertex_program +#define GL_ARB_vertex_program 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttrib1dARB (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttrib1dvARB (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib1fARB (GLuint index, GLfloat x); +GLAPI void APIENTRY glVertexAttrib1fvARB (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib1sARB (GLuint index, GLshort x); +GLAPI void APIENTRY glVertexAttrib1svARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib2dARB (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttrib2dvARB (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib2fARB (GLuint index, GLfloat x, GLfloat y); +GLAPI void APIENTRY glVertexAttrib2fvARB (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib2sARB (GLuint index, GLshort x, GLshort y); +GLAPI void APIENTRY glVertexAttrib2svARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib3dARB (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttrib3dvARB (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib3fARB (GLuint index, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glVertexAttrib3fvARB (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib3sARB (GLuint index, GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glVertexAttrib3svARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4NbvARB (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4NivARB (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4NsvARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4NubARB (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +GLAPI void APIENTRY glVertexAttrib4NubvARB (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4NuivARB (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4NusvARB (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttrib4bvARB (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttrib4dARB (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttrib4dvARB (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib4fARB (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glVertexAttrib4fvARB (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib4ivARB (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttrib4sARB (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glVertexAttrib4svARB (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4ubvARB (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttrib4uivARB (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttrib4usvARB (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttribPointerARB (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glEnableVertexAttribArrayARB (GLuint index); +GLAPI void APIENTRY glDisableVertexAttribArrayARB (GLuint index); +GLAPI void APIENTRY glProgramStringARB (GLenum target, GLenum format, GLsizei len, const GLvoid *string); +GLAPI void APIENTRY glBindProgramARB (GLenum target, GLuint program); +GLAPI void APIENTRY glDeleteProgramsARB (GLsizei n, const GLuint *programs); +GLAPI void APIENTRY glGenProgramsARB (GLsizei n, GLuint *programs); +GLAPI void APIENTRY glProgramEnvParameter4dARB (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramEnvParameter4dvARB (GLenum target, GLuint index, const GLdouble *params); +GLAPI void APIENTRY glProgramEnvParameter4fARB (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glProgramEnvParameter4fvARB (GLenum target, GLuint index, const GLfloat *params); +GLAPI void APIENTRY glProgramLocalParameter4dARB (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramLocalParameter4dvARB (GLenum target, GLuint index, const GLdouble *params); +GLAPI void APIENTRY glProgramLocalParameter4fARB (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glProgramLocalParameter4fvARB (GLenum target, GLuint index, const GLfloat *params); +GLAPI void APIENTRY glGetProgramEnvParameterdvARB (GLenum target, GLuint index, GLdouble *params); +GLAPI void APIENTRY glGetProgramEnvParameterfvARB (GLenum target, GLuint index, GLfloat *params); +GLAPI void APIENTRY glGetProgramLocalParameterdvARB (GLenum target, GLuint index, GLdouble *params); +GLAPI void APIENTRY glGetProgramLocalParameterfvARB (GLenum target, GLuint index, GLfloat *params); +GLAPI void APIENTRY glGetProgramivARB (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetProgramStringARB (GLenum target, GLenum pname, GLvoid *string); +GLAPI void APIENTRY glGetVertexAttribdvARB (GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetVertexAttribfvARB (GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVertexAttribivARB (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribPointervARB (GLuint index, GLenum pname, GLvoid* *pointer); +GLAPI GLboolean APIENTRY glIsProgramARB (GLuint program); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DARBPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FARBPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SARBPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DARBPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FARBPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SARBPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVARBPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVARBPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBARBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVARBPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVARBPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVARBPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVARBPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVARBPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVARBPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVARBPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVARBPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); +typedef void (APIENTRYP PFNGLPROGRAMSTRINGARBPROC) (GLenum target, GLenum format, GLsizei len, const GLvoid *string); +typedef void (APIENTRYP PFNGLBINDPROGRAMARBPROC) (GLenum target, GLuint program); +typedef void (APIENTRYP PFNGLDELETEPROGRAMSARBPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLGENPROGRAMSARBPROC) (GLsizei n, GLuint *programs); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGARBPROC) (GLenum target, GLenum pname, GLvoid *string); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVARBPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVARBPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVARBPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVARBPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMARBPROC) (GLuint program); +#endif + +#ifndef GL_ARB_fragment_program +#define GL_ARB_fragment_program 1 +/* All ARB_fragment_program entry points are shared with ARB_vertex_program. */ +#endif + +#ifndef GL_ARB_vertex_buffer_object +#define GL_ARB_vertex_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindBufferARB (GLenum target, GLuint buffer); +GLAPI void APIENTRY glDeleteBuffersARB (GLsizei n, const GLuint *buffers); +GLAPI void APIENTRY glGenBuffersARB (GLsizei n, GLuint *buffers); +GLAPI GLboolean APIENTRY glIsBufferARB (GLuint buffer); +GLAPI void APIENTRY glBufferDataARB (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); +GLAPI void APIENTRY glBufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data); +GLAPI void APIENTRY glGetBufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data); +GLAPI GLvoid* APIENTRY glMapBufferARB (GLenum target, GLenum access); +GLAPI GLboolean APIENTRY glUnmapBufferARB (GLenum target); +GLAPI void APIENTRY glGetBufferParameterivARB (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetBufferPointervARB (GLenum target, GLenum pname, GLvoid* *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); +typedef GLboolean (APIENTRYP PFNGLISBUFFERARBPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERARBPROC) (GLenum target, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERARBPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVARBPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_ARB_occlusion_query +#define GL_ARB_occlusion_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenQueriesARB (GLsizei n, GLuint *ids); +GLAPI void APIENTRY glDeleteQueriesARB (GLsizei n, const GLuint *ids); +GLAPI GLboolean APIENTRY glIsQueryARB (GLuint id); +GLAPI void APIENTRY glBeginQueryARB (GLenum target, GLuint id); +GLAPI void APIENTRY glEndQueryARB (GLenum target); +GLAPI void APIENTRY glGetQueryivARB (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectivARB (GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetQueryObjectuivARB (GLuint id, GLenum pname, GLuint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENQUERIESARBPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEQUERIESARBPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISQUERYARBPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINQUERYARBPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYARBPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVARBPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVARBPROC) (GLuint id, GLenum pname, GLuint *params); +#endif + +#ifndef GL_ARB_shader_objects +#define GL_ARB_shader_objects 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeleteObjectARB (GLhandleARB obj); +GLAPI GLhandleARB APIENTRY glGetHandleARB (GLenum pname); +GLAPI void APIENTRY glDetachObjectARB (GLhandleARB containerObj, GLhandleARB attachedObj); +GLAPI GLhandleARB APIENTRY glCreateShaderObjectARB (GLenum shaderType); +GLAPI void APIENTRY glShaderSourceARB (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); +GLAPI void APIENTRY glCompileShaderARB (GLhandleARB shaderObj); +GLAPI GLhandleARB APIENTRY glCreateProgramObjectARB (void); +GLAPI void APIENTRY glAttachObjectARB (GLhandleARB containerObj, GLhandleARB obj); +GLAPI void APIENTRY glLinkProgramARB (GLhandleARB programObj); +GLAPI void APIENTRY glUseProgramObjectARB (GLhandleARB programObj); +GLAPI void APIENTRY glValidateProgramARB (GLhandleARB programObj); +GLAPI void APIENTRY glUniform1fARB (GLint location, GLfloat v0); +GLAPI void APIENTRY glUniform2fARB (GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glUniform3fARB (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glUniform4fARB (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glUniform1iARB (GLint location, GLint v0); +GLAPI void APIENTRY glUniform2iARB (GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glUniform3iARB (GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glUniform4iARB (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glUniform1fvARB (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform2fvARB (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform3fvARB (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform4fvARB (GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glUniform1ivARB (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform2ivARB (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform3ivARB (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniform4ivARB (GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glUniformMatrix2fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix3fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glUniformMatrix4fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glGetObjectParameterfvARB (GLhandleARB obj, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetObjectParameterivARB (GLhandleARB obj, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetInfoLogARB (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); +GLAPI void APIENTRY glGetAttachedObjectsARB (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); +GLAPI GLint APIENTRY glGetUniformLocationARB (GLhandleARB programObj, const GLcharARB *name); +GLAPI void APIENTRY glGetActiveUniformARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +GLAPI void APIENTRY glGetUniformfvARB (GLhandleARB programObj, GLint location, GLfloat *params); +GLAPI void APIENTRY glGetUniformivARB (GLhandleARB programObj, GLint location, GLint *params); +GLAPI void APIENTRY glGetShaderSourceARB (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj); +typedef GLhandleARB (APIENTRYP PFNGLGETHANDLEARBPROC) (GLenum pname); +typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB attachedObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType); +typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); +typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); +typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); +typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUNIFORM1FARBPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FARBPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IARBPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERFVARBPROC) (GLhandleARB obj, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVARBPROC) (GLhandleARB obj, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETINFOLOGARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); +typedef void (APIENTRYP PFNGLGETATTACHEDOBJECTSARBPROC) (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVARBPROC) (GLhandleARB programObj, GLint location, GLfloat *params); +typedef void (APIENTRYP PFNGLGETUNIFORMIVARBPROC) (GLhandleARB programObj, GLint location, GLint *params); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); +#endif + +#ifndef GL_ARB_vertex_shader +#define GL_ARB_vertex_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindAttribLocationARB (GLhandleARB programObj, GLuint index, const GLcharARB *name); +GLAPI void APIENTRY glGetActiveAttribARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +GLAPI GLint APIENTRY glGetAttribLocationARB (GLhandleARB programObj, const GLcharARB *name); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONARBPROC) (GLhandleARB programObj, GLuint index, const GLcharARB *name); +typedef void (APIENTRYP PFNGLGETACTIVEATTRIBARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +#endif + +#ifndef GL_ARB_fragment_shader +#define GL_ARB_fragment_shader 1 +#endif + +#ifndef GL_ARB_shading_language_100 +#define GL_ARB_shading_language_100 1 +#endif + +#ifndef GL_ARB_texture_non_power_of_two +#define GL_ARB_texture_non_power_of_two 1 +#endif + +#ifndef GL_ARB_point_sprite +#define GL_ARB_point_sprite 1 +#endif + +#ifndef GL_ARB_fragment_program_shadow +#define GL_ARB_fragment_program_shadow 1 +#endif + +#ifndef GL_ARB_draw_buffers +#define GL_ARB_draw_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawBuffersARB (GLsizei n, const GLenum *bufs); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWBUFFERSARBPROC) (GLsizei n, const GLenum *bufs); +#endif + +#ifndef GL_ARB_texture_rectangle +#define GL_ARB_texture_rectangle 1 +#endif + +#ifndef GL_ARB_color_buffer_float +#define GL_ARB_color_buffer_float 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClampColorARB (GLenum target, GLenum clamp); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLAMPCOLORARBPROC) (GLenum target, GLenum clamp); +#endif + +#ifndef GL_ARB_half_float_pixel +#define GL_ARB_half_float_pixel 1 +#endif + +#ifndef GL_ARB_texture_float +#define GL_ARB_texture_float 1 +#endif + +#ifndef GL_ARB_pixel_buffer_object +#define GL_ARB_pixel_buffer_object 1 +#endif + +#ifndef GL_ARB_depth_buffer_float +#define GL_ARB_depth_buffer_float 1 +#endif + +#ifndef GL_ARB_draw_instanced +#define GL_ARB_draw_instanced 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstancedARB (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +GLAPI void APIENTRY glDrawElementsInstancedARB (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDARBPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDARBPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +#endif + +#ifndef GL_ARB_framebuffer_object +#define GL_ARB_framebuffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glIsRenderbuffer (GLuint renderbuffer); +GLAPI void APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer); +GLAPI void APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint *renderbuffers); +GLAPI void APIENTRY glGenRenderbuffers (GLsizei n, GLuint *renderbuffers); +GLAPI void APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint *params); +GLAPI GLboolean APIENTRY glIsFramebuffer (GLuint framebuffer); +GLAPI void APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer); +GLAPI void APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint *framebuffers); +GLAPI void APIENTRY glGenFramebuffers (GLsizei n, GLuint *framebuffers); +GLAPI GLenum APIENTRY glCheckFramebufferStatus (GLenum target); +GLAPI void APIENTRY glFramebufferTexture1D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture3D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +GLAPI void APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GLAPI void APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint *params); +GLAPI void APIENTRY glGenerateMipmap (GLenum target); +GLAPI void APIENTRY glBlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +GLAPI void APIENTRY glRenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glFramebufferTextureLayer (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFERPROC) (GLuint renderbuffer); +typedef void (APIENTRYP PFNGLBINDRENDERBUFFERPROC) (GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSPROC) (GLsizei n, const GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLGENRENDERBUFFERSPROC) (GLsizei n, GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFERPROC) (GLuint framebuffer); +typedef void (APIENTRYP PFNGLBINDFRAMEBUFFERPROC) (GLenum target, GLuint framebuffer); +typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSPROC) (GLsizei n, const GLuint *framebuffers); +typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSPROC) (GLsizei n, GLuint *framebuffers); +typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC) (GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATEMIPMAPPROC) (GLenum target); +typedef void (APIENTRYP PFNGLBLITFRAMEBUFFERPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +#endif + +#ifndef GL_ARB_framebuffer_sRGB +#define GL_ARB_framebuffer_sRGB 1 +#endif + +#ifndef GL_ARB_geometry_shader4 +#define GL_ARB_geometry_shader4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramParameteriARB (GLuint program, GLenum pname, GLint value); +GLAPI void APIENTRY glFramebufferTextureARB (GLenum target, GLenum attachment, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTextureLayerARB (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +GLAPI void APIENTRY glFramebufferTextureFaceARB (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIARBPROC) (GLuint program, GLenum pname, GLint value); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#endif + +#ifndef GL_ARB_half_float_vertex +#define GL_ARB_half_float_vertex 1 +#endif + +#ifndef GL_ARB_instanced_arrays +#define GL_ARB_instanced_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribDivisorARB (GLuint index, GLuint divisor); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORARBPROC) (GLuint index, GLuint divisor); +#endif + +#ifndef GL_ARB_map_buffer_range +#define GL_ARB_map_buffer_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLvoid* APIENTRY glMapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +GLAPI void APIENTRY glFlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length); +#endif + +#ifndef GL_ARB_texture_buffer_object +#define GL_ARB_texture_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBufferARB (GLenum target, GLenum internalformat, GLuint buffer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUFFERARBPROC) (GLenum target, GLenum internalformat, GLuint buffer); +#endif + +#ifndef GL_ARB_texture_compression_rgtc +#define GL_ARB_texture_compression_rgtc 1 +#endif + +#ifndef GL_ARB_texture_rg +#define GL_ARB_texture_rg 1 +#endif + +#ifndef GL_ARB_vertex_array_object +#define GL_ARB_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindVertexArray (GLuint array); +GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays); +GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays); +GLAPI GLboolean APIENTRY glIsVertexArray (GLuint array); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array); +typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays); +typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYPROC) (GLuint array); +#endif + +#ifndef GL_ARB_uniform_buffer_object +#define GL_ARB_uniform_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetUniformIndices (GLuint program, GLsizei uniformCount, const GLchar* *uniformNames, GLuint *uniformIndices); +GLAPI void APIENTRY glGetActiveUniformsiv (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetActiveUniformName (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); +GLAPI GLuint APIENTRY glGetUniformBlockIndex (GLuint program, const GLchar *uniformBlockName); +GLAPI void APIENTRY glGetActiveUniformBlockiv (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetActiveUniformBlockName (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); +GLAPI void APIENTRY glUniformBlockBinding (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETUNIFORMINDICESPROC) (GLuint program, GLsizei uniformCount, const GLchar* *uniformNames, GLuint *uniformIndices); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMSIVPROC) (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMNAMEPROC) (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName); +typedef GLuint (APIENTRYP PFNGLGETUNIFORMBLOCKINDEXPROC) (GLuint program, const GLchar *uniformBlockName); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKIVPROC) (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC) (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName); +typedef void (APIENTRYP PFNGLUNIFORMBLOCKBINDINGPROC) (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); +#endif + +#ifndef GL_ARB_compatibility +#define GL_ARB_compatibility 1 +#endif + +#ifndef GL_ARB_copy_buffer +#define GL_ARB_copy_buffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCopyBufferSubData (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +#endif + +#ifndef GL_ARB_shader_texture_lod +#define GL_ARB_shader_texture_lod 1 +#endif + +#ifndef GL_ARB_depth_clamp +#define GL_ARB_depth_clamp 1 +#endif + +#ifndef GL_ARB_draw_elements_base_vertex +#define GL_ARB_draw_elements_base_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +GLAPI void APIENTRY glDrawRangeElementsBaseVertex (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +GLAPI void APIENTRY glDrawElementsInstancedBaseVertex (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount, GLint basevertex); +GLAPI void APIENTRY glMultiDrawElementsBaseVertex (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount, const GLint *basevertex); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount, GLint basevertex); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount, const GLint *basevertex); +#endif + +#ifndef GL_ARB_fragment_coord_conventions +#define GL_ARB_fragment_coord_conventions 1 +#endif + +#ifndef GL_ARB_provoking_vertex +#define GL_ARB_provoking_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProvokingVertex (GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROVOKINGVERTEXPROC) (GLenum mode); +#endif + +#ifndef GL_ARB_seamless_cube_map +#define GL_ARB_seamless_cube_map 1 +#endif + +#ifndef GL_ARB_sync +#define GL_ARB_sync 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLsync APIENTRY glFenceSync (GLenum condition, GLbitfield flags); +GLAPI GLboolean APIENTRY glIsSync (GLsync sync); +GLAPI void APIENTRY glDeleteSync (GLsync sync); +GLAPI GLenum APIENTRY glClientWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GLAPI void APIENTRY glWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GLAPI void APIENTRY glGetInteger64v (GLenum pname, GLint64 *params); +GLAPI void APIENTRY glGetSynciv (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLsync (APIENTRYP PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags); +typedef GLboolean (APIENTRYP PFNGLISSYNCPROC) (GLsync sync); +typedef void (APIENTRYP PFNGLDELETESYNCPROC) (GLsync sync); +typedef GLenum (APIENTRYP PFNGLCLIENTWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (APIENTRYP PFNGLWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (APIENTRYP PFNGLGETINTEGER64VPROC) (GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLGETSYNCIVPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif + +#ifndef GL_ARB_texture_multisample +#define GL_ARB_texture_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage2DMultisample (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glTexImage3DMultisample (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +GLAPI void APIENTRY glGetMultisamplefv (GLenum pname, GLuint index, GLfloat *val); +GLAPI void APIENTRY glSampleMaski (GLuint index, GLbitfield mask); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); +typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVPROC) (GLenum pname, GLuint index, GLfloat *val); +typedef void (APIENTRYP PFNGLSAMPLEMASKIPROC) (GLuint index, GLbitfield mask); +#endif + +#ifndef GL_ARB_vertex_array_bgra +#define GL_ARB_vertex_array_bgra 1 +#endif + +#ifndef GL_ARB_draw_buffers_blend +#define GL_ARB_draw_buffers_blend 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationiARB (GLuint buf, GLenum mode); +GLAPI void APIENTRY glBlendEquationSeparateiARB (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +GLAPI void APIENTRY glBlendFunciARB (GLuint buf, GLenum src, GLenum dst); +GLAPI void APIENTRY glBlendFuncSeparateiARB (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONIARBPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIARBPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLBLENDFUNCIARBPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIARBPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif + +#ifndef GL_ARB_sample_shading +#define GL_ARB_sample_shading 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMinSampleShadingARB (GLclampf value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMINSAMPLESHADINGARBPROC) (GLclampf value); +#endif + +#ifndef GL_ARB_texture_cube_map_array +#define GL_ARB_texture_cube_map_array 1 +#endif + +#ifndef GL_ARB_texture_gather +#define GL_ARB_texture_gather 1 +#endif + +#ifndef GL_ARB_texture_query_lod +#define GL_ARB_texture_query_lod 1 +#endif + +#ifndef GL_ARB_shading_language_include +#define GL_ARB_shading_language_include 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glNamedStringARB (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); +GLAPI void APIENTRY glDeleteNamedStringARB (GLint namelen, const GLchar *name); +GLAPI void APIENTRY glCompileShaderIncludeARB (GLuint shader, GLsizei count, const GLchar* *path, const GLint *length); +GLAPI GLboolean APIENTRY glIsNamedStringARB (GLint namelen, const GLchar *name); +GLAPI void APIENTRY glGetNamedStringARB (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); +GLAPI void APIENTRY glGetNamedStringivARB (GLint namelen, const GLchar *name, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLNAMEDSTRINGARBPROC) (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string); +typedef void (APIENTRYP PFNGLDELETENAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); +typedef void (APIENTRYP PFNGLCOMPILESHADERINCLUDEARBPROC) (GLuint shader, GLsizei count, const GLchar* *path, const GLint *length); +typedef GLboolean (APIENTRYP PFNGLISNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name); +typedef void (APIENTRYP PFNGLGETNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string); +typedef void (APIENTRYP PFNGLGETNAMEDSTRINGIVARBPROC) (GLint namelen, const GLchar *name, GLenum pname, GLint *params); +#endif + +#ifndef GL_ARB_texture_compression_bptc +#define GL_ARB_texture_compression_bptc 1 +#endif + +#ifndef GL_ARB_blend_func_extended +#define GL_ARB_blend_func_extended 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindFragDataLocationIndexed (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); +GLAPI GLint APIENTRY glGetFragDataIndex (GLuint program, const GLchar *name); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONINDEXEDPROC) (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATAINDEXPROC) (GLuint program, const GLchar *name); +#endif + +#ifndef GL_ARB_explicit_attrib_location +#define GL_ARB_explicit_attrib_location 1 +#endif + +#ifndef GL_ARB_occlusion_query2 +#define GL_ARB_occlusion_query2 1 +#endif + +#ifndef GL_ARB_sampler_objects +#define GL_ARB_sampler_objects 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenSamplers (GLsizei count, GLuint *samplers); +GLAPI void APIENTRY glDeleteSamplers (GLsizei count, const GLuint *samplers); +GLAPI GLboolean APIENTRY glIsSampler (GLuint sampler); +GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler); +GLAPI void APIENTRY glSamplerParameteri (GLuint sampler, GLenum pname, GLint param); +GLAPI void APIENTRY glSamplerParameteriv (GLuint sampler, GLenum pname, const GLint *param); +GLAPI void APIENTRY glSamplerParameterf (GLuint sampler, GLenum pname, GLfloat param); +GLAPI void APIENTRY glSamplerParameterfv (GLuint sampler, GLenum pname, const GLfloat *param); +GLAPI void APIENTRY glSamplerParameterIiv (GLuint sampler, GLenum pname, const GLint *param); +GLAPI void APIENTRY glSamplerParameterIuiv (GLuint sampler, GLenum pname, const GLuint *param); +GLAPI void APIENTRY glGetSamplerParameteriv (GLuint sampler, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSamplerParameterIiv (GLuint sampler, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSamplerParameterfv (GLuint sampler, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetSamplerParameterIuiv (GLuint sampler, GLenum pname, GLuint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENSAMPLERSPROC) (GLsizei count, GLuint *samplers); +typedef void (APIENTRYP PFNGLDELETESAMPLERSPROC) (GLsizei count, const GLuint *samplers); +typedef GLboolean (APIENTRYP PFNGLISSAMPLERPROC) (GLuint sampler); +typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIPROC) (GLuint sampler, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFPROC) (GLuint sampler, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, const GLfloat *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, const GLuint *param); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, GLuint *params); +#endif + +#ifndef GL_ARB_texture_rgb10_a2ui +#define GL_ARB_texture_rgb10_a2ui 1 +#endif + +#ifndef GL_ARB_texture_swizzle +#define GL_ARB_texture_swizzle 1 +#endif + +#ifndef GL_ARB_timer_query +#define GL_ARB_timer_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glQueryCounter (GLuint id, GLenum target); +GLAPI void APIENTRY glGetQueryObjecti64v (GLuint id, GLenum pname, GLint64 *params); +GLAPI void APIENTRY glGetQueryObjectui64v (GLuint id, GLenum pname, GLuint64 *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLQUERYCOUNTERPROC) (GLuint id, GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VPROC) (GLuint id, GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VPROC) (GLuint id, GLenum pname, GLuint64 *params); +#endif + +#ifndef GL_ARB_vertex_type_2_10_10_10_rev +#define GL_ARB_vertex_type_2_10_10_10_rev 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexP2ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP2uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glVertexP3ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP3uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glVertexP4ui (GLenum type, GLuint value); +GLAPI void APIENTRY glVertexP4uiv (GLenum type, const GLuint *value); +GLAPI void APIENTRY glTexCoordP1ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP1uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP2ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP2uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP3ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP3uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glTexCoordP4ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glTexCoordP4uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP1ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP1uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP2ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP2uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP3ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP3uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glMultiTexCoordP4ui (GLenum texture, GLenum type, GLuint coords); +GLAPI void APIENTRY glMultiTexCoordP4uiv (GLenum texture, GLenum type, const GLuint *coords); +GLAPI void APIENTRY glNormalP3ui (GLenum type, GLuint coords); +GLAPI void APIENTRY glNormalP3uiv (GLenum type, const GLuint *coords); +GLAPI void APIENTRY glColorP3ui (GLenum type, GLuint color); +GLAPI void APIENTRY glColorP3uiv (GLenum type, const GLuint *color); +GLAPI void APIENTRY glColorP4ui (GLenum type, GLuint color); +GLAPI void APIENTRY glColorP4uiv (GLenum type, const GLuint *color); +GLAPI void APIENTRY glSecondaryColorP3ui (GLenum type, GLuint color); +GLAPI void APIENTRY glSecondaryColorP3uiv (GLenum type, const GLuint *color); +GLAPI void APIENTRY glVertexAttribP1ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP1uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP2ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP2uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP3ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP3uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +GLAPI void APIENTRY glVertexAttribP4ui (GLuint index, GLenum type, GLboolean normalized, GLuint value); +GLAPI void APIENTRY glVertexAttribP4uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXP2UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP2UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXP3UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP3UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXP4UIPROC) (GLenum type, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXP4UIVPROC) (GLenum type, const GLuint *value); +typedef void (APIENTRYP PFNGLTEXCOORDP1UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP1UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP2UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP2UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP3UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP3UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLTEXCOORDP4UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLTEXCOORDP4UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIPROC) (GLenum texture, GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIVPROC) (GLenum texture, GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLNORMALP3UIPROC) (GLenum type, GLuint coords); +typedef void (APIENTRYP PFNGLNORMALP3UIVPROC) (GLenum type, const GLuint *coords); +typedef void (APIENTRYP PFNGLCOLORP3UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLCOLORP3UIVPROC) (GLenum type, const GLuint *color); +typedef void (APIENTRYP PFNGLCOLORP4UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLCOLORP4UIVPROC) (GLenum type, const GLuint *color); +typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIPROC) (GLenum type, GLuint color); +typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIVPROC) (GLenum type, const GLuint *color); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value); +typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value); +#endif + +#ifndef GL_ARB_draw_indirect +#define GL_ARB_draw_indirect 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysIndirect (GLenum mode, const GLvoid *indirect); +GLAPI void APIENTRY glDrawElementsIndirect (GLenum mode, GLenum type, const GLvoid *indirect); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINDIRECTPROC) (GLenum mode, const GLvoid *indirect); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const GLvoid *indirect); +#endif + +#ifndef GL_ARB_gpu_shader5 +#define GL_ARB_gpu_shader5 1 +#endif + +#ifndef GL_ARB_gpu_shader_fp64 +#define GL_ARB_gpu_shader_fp64 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUniform1d (GLint location, GLdouble x); +GLAPI void APIENTRY glUniform2d (GLint location, GLdouble x, GLdouble y); +GLAPI void APIENTRY glUniform3d (GLint location, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glUniform4d (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glUniform1dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform2dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform3dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniform4dv (GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix2x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix3x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glUniformMatrix4x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glGetUniformdv (GLuint program, GLint location, GLdouble *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUNIFORM1DPROC) (GLint location, GLdouble x); +typedef void (APIENTRYP PFNGLUNIFORM2DPROC) (GLint location, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLUNIFORM3DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLUNIFORM4DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLUNIFORM1DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM2DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM3DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORM4DVPROC) (GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLGETUNIFORMDVPROC) (GLuint program, GLint location, GLdouble *params); +#endif + +#ifndef GL_ARB_shader_subroutine +#define GL_ARB_shader_subroutine 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLint APIENTRY glGetSubroutineUniformLocation (GLuint program, GLenum shadertype, const GLchar *name); +GLAPI GLuint APIENTRY glGetSubroutineIndex (GLuint program, GLenum shadertype, const GLchar *name); +GLAPI void APIENTRY glGetActiveSubroutineUniformiv (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); +GLAPI void APIENTRY glGetActiveSubroutineUniformName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glGetActiveSubroutineName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +GLAPI void APIENTRY glUniformSubroutinesuiv (GLenum shadertype, GLsizei count, const GLuint *indices); +GLAPI void APIENTRY glGetUniformSubroutineuiv (GLenum shadertype, GLint location, GLuint *params); +GLAPI void APIENTRY glGetProgramStageiv (GLuint program, GLenum shadertype, GLenum pname, GLint *values); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLint (APIENTRYP PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC) (GLuint program, GLenum shadertype, const GLchar *name); +typedef GLuint (APIENTRYP PFNGLGETSUBROUTINEINDEXPROC) (GLuint program, GLenum shadertype, const GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC) (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINENAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORMSUBROUTINESUIVPROC) (GLenum shadertype, GLsizei count, const GLuint *indices); +typedef void (APIENTRYP PFNGLGETUNIFORMSUBROUTINEUIVPROC) (GLenum shadertype, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTAGEIVPROC) (GLuint program, GLenum shadertype, GLenum pname, GLint *values); +#endif + +#ifndef GL_ARB_tessellation_shader +#define GL_ARB_tessellation_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPatchParameteri (GLenum pname, GLint value); +GLAPI void APIENTRY glPatchParameterfv (GLenum pname, const GLfloat *values); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPATCHPARAMETERIPROC) (GLenum pname, GLint value); +typedef void (APIENTRYP PFNGLPATCHPARAMETERFVPROC) (GLenum pname, const GLfloat *values); +#endif + +#ifndef GL_ARB_texture_buffer_object_rgb32 +#define GL_ARB_texture_buffer_object_rgb32 1 +#endif + +#ifndef GL_ARB_transform_feedback2 +#define GL_ARB_transform_feedback2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindTransformFeedback (GLenum target, GLuint id); +GLAPI void APIENTRY glDeleteTransformFeedbacks (GLsizei n, const GLuint *ids); +GLAPI void APIENTRY glGenTransformFeedbacks (GLsizei n, GLuint *ids); +GLAPI GLboolean APIENTRY glIsTransformFeedback (GLuint id); +GLAPI void APIENTRY glPauseTransformFeedback (void); +GLAPI void APIENTRY glResumeTransformFeedback (void); +GLAPI void APIENTRY glDrawTransformFeedback (GLenum mode, GLuint id); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSPROC) (GLsizei n, const GLuint *ids); +typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSPROC) (GLsizei n, GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKPROC) (GLuint id); +typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKPROC) (void); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKPROC) (GLenum mode, GLuint id); +#endif + +#ifndef GL_ARB_transform_feedback3 +#define GL_ARB_transform_feedback3 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawTransformFeedbackStream (GLenum mode, GLuint id, GLuint stream); +GLAPI void APIENTRY glBeginQueryIndexed (GLenum target, GLuint index, GLuint id); +GLAPI void APIENTRY glEndQueryIndexed (GLenum target, GLuint index); +GLAPI void APIENTRY glGetQueryIndexediv (GLenum target, GLuint index, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC) (GLenum mode, GLuint id, GLuint stream); +typedef void (APIENTRYP PFNGLBEGINQUERYINDEXEDPROC) (GLenum target, GLuint index, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYINDEXEDPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLGETQUERYINDEXEDIVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); +#endif + +#ifndef GL_ARB_ES2_compatibility +#define GL_ARB_ES2_compatibility 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReleaseShaderCompiler (void); +GLAPI void APIENTRY glShaderBinary (GLsizei count, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length); +GLAPI void APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); +GLAPI void APIENTRY glDepthRangef (GLclampf n, GLclampf f); +GLAPI void APIENTRY glClearDepthf (GLclampf d); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRELEASESHADERCOMPILERPROC) (void); +typedef void (APIENTRYP PFNGLSHADERBINARYPROC) (GLsizei count, const GLuint *shaders, GLenum binaryformat, const GLvoid *binary, GLsizei length); +typedef void (APIENTRYP PFNGLGETSHADERPRECISIONFORMATPROC) (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision); +typedef void (APIENTRYP PFNGLDEPTHRANGEFPROC) (GLclampf n, GLclampf f); +typedef void (APIENTRYP PFNGLCLEARDEPTHFPROC) (GLclampf d); +#endif + +#ifndef GL_ARB_get_program_binary +#define GL_ARB_get_program_binary 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetProgramBinary (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +GLAPI void APIENTRY glProgramBinary (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); +GLAPI void APIENTRY glProgramParameteri (GLuint program, GLenum pname, GLint value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETPROGRAMBINARYPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +typedef void (APIENTRYP PFNGLPROGRAMBINARYPROC) (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLsizei length); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIPROC) (GLuint program, GLenum pname, GLint value); +#endif + +#ifndef GL_ARB_separate_shader_objects +#define GL_ARB_separate_shader_objects 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUseProgramStages (GLuint pipeline, GLbitfield stages, GLuint program); +GLAPI void APIENTRY glActiveShaderProgram (GLuint pipeline, GLuint program); +GLAPI GLuint APIENTRY glCreateShaderProgramv (GLenum type, GLsizei count, const GLchar* *strings); +GLAPI void APIENTRY glBindProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glDeleteProgramPipelines (GLsizei n, const GLuint *pipelines); +GLAPI void APIENTRY glGenProgramPipelines (GLsizei n, GLuint *pipelines); +GLAPI GLboolean APIENTRY glIsProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glGetProgramPipelineiv (GLuint pipeline, GLenum pname, GLint *params); +GLAPI void APIENTRY glProgramUniform1i (GLuint program, GLint location, GLint v0); +GLAPI void APIENTRY glProgramUniform1iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform1f (GLuint program, GLint location, GLfloat v0); +GLAPI void APIENTRY glProgramUniform1fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform1d (GLuint program, GLint location, GLdouble v0); +GLAPI void APIENTRY glProgramUniform1dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform1ui (GLuint program, GLint location, GLuint v0); +GLAPI void APIENTRY glProgramUniform1uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform2i (GLuint program, GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glProgramUniform2iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform2f (GLuint program, GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glProgramUniform2fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform2d (GLuint program, GLint location, GLdouble v0, GLdouble v1); +GLAPI void APIENTRY glProgramUniform2dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform2ui (GLuint program, GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glProgramUniform2uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform3i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glProgramUniform3iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform3f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glProgramUniform3fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform3d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); +GLAPI void APIENTRY glProgramUniform3dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform3ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glProgramUniform3uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform4i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glProgramUniform4iv (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform4f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glProgramUniform4fv (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform4d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); +GLAPI void APIENTRY glProgramUniform4dv (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform4ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glProgramUniform4uiv (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniformMatrix2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glValidateProgramPipeline (GLuint pipeline); +GLAPI void APIENTRY glGetProgramPipelineInfoLog (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUSEPROGRAMSTAGESPROC) (GLuint pipeline, GLbitfield stages, GLuint program); +typedef void (APIENTRYP PFNGLACTIVESHADERPROGRAMPROC) (GLuint pipeline, GLuint program); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMVPROC) (GLenum type, GLsizei count, const GLchar* *strings); +typedef void (APIENTRYP PFNGLBINDPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLDELETEPROGRAMPIPELINESPROC) (GLsizei n, const GLuint *pipelines); +typedef void (APIENTRYP PFNGLGENPROGRAMPIPELINESPROC) (GLsizei n, GLuint *pipelines); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEIVPROC) (GLuint pipeline, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IPROC) (GLuint program, GLint location, GLint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FPROC) (GLuint program, GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DPROC) (GLuint program, GLint location, GLdouble v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIPROC) (GLuint program, GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IPROC) (GLuint program, GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEPROC) (GLuint pipeline); +typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGPROC) (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +#endif + +#ifndef GL_ARB_vertex_attrib_64bit +#define GL_ARB_vertex_attrib_64bit 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribL1d (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttribL2d (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttribL3d (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttribL4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttribL1dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL2dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL3dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL4dv (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribLPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glGetVertexAttribLdv (GLuint index, GLenum pname, GLdouble *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVPROC) (GLuint index, GLenum pname, GLdouble *params); +#endif + +#ifndef GL_ARB_viewport_array +#define GL_ARB_viewport_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glViewportArrayv (GLuint first, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glViewportIndexedf (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); +GLAPI void APIENTRY glViewportIndexedfv (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glScissorArrayv (GLuint first, GLsizei count, const GLint *v); +GLAPI void APIENTRY glScissorIndexed (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); +GLAPI void APIENTRY glScissorIndexedv (GLuint index, const GLint *v); +GLAPI void APIENTRY glDepthRangeArrayv (GLuint first, GLsizei count, const GLclampd *v); +GLAPI void APIENTRY glDepthRangeIndexed (GLuint index, GLclampd n, GLclampd f); +GLAPI void APIENTRY glGetFloati_v (GLenum target, GLuint index, GLfloat *data); +GLAPI void APIENTRY glGetDoublei_v (GLenum target, GLuint index, GLdouble *data); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVIEWPORTARRAYVPROC) (GLuint first, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h); +typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLSCISSORARRAYVPROC) (GLuint first, GLsizei count, const GLint *v); +typedef void (APIENTRYP PFNGLSCISSORINDEXEDPROC) (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLSCISSORINDEXEDVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLDEPTHRANGEARRAYVPROC) (GLuint first, GLsizei count, const GLclampd *v); +typedef void (APIENTRYP PFNGLDEPTHRANGEINDEXEDPROC) (GLuint index, GLclampd n, GLclampd f); +typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data); +typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data); +#endif + +#ifndef GL_ARB_cl_event +#define GL_ARB_cl_event 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLsync APIENTRY glCreateSyncFromCLeventARB (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLsync (APIENTRYP PFNGLCREATESYNCFROMCLEVENTARBPROC) (struct _cl_context * context, struct _cl_event * event, GLbitfield flags); +#endif + +#ifndef GL_ARB_debug_output +#define GL_ARB_debug_output 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDebugMessageControlARB (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +GLAPI void APIENTRY glDebugMessageInsertARB (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +GLAPI void APIENTRY glDebugMessageCallbackARB (GLDEBUGPROCARB callback, const GLvoid *userParam); +GLAPI GLuint APIENTRY glGetDebugMessageLogARB (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLARBPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTARBPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); +typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKARBPROC) (GLDEBUGPROCARB callback, const GLvoid *userParam); +typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGARBPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog); +#endif + +#ifndef GL_ARB_robustness +#define GL_ARB_robustness 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLenum APIENTRY glGetGraphicsResetStatusARB (void); +GLAPI void APIENTRY glGetnMapdvARB (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); +GLAPI void APIENTRY glGetnMapfvARB (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); +GLAPI void APIENTRY glGetnMapivARB (GLenum target, GLenum query, GLsizei bufSize, GLint *v); +GLAPI void APIENTRY glGetnPixelMapfvARB (GLenum map, GLsizei bufSize, GLfloat *values); +GLAPI void APIENTRY glGetnPixelMapuivARB (GLenum map, GLsizei bufSize, GLuint *values); +GLAPI void APIENTRY glGetnPixelMapusvARB (GLenum map, GLsizei bufSize, GLushort *values); +GLAPI void APIENTRY glGetnPolygonStippleARB (GLsizei bufSize, GLubyte *pattern); +GLAPI void APIENTRY glGetnColorTableARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *table); +GLAPI void APIENTRY glGetnConvolutionFilterARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *image); +GLAPI void APIENTRY glGetnSeparableFilterARB (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, GLvoid *row, GLsizei columnBufSize, GLvoid *column, GLvoid *span); +GLAPI void APIENTRY glGetnHistogramARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); +GLAPI void APIENTRY glGetnMinmaxARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); +GLAPI void APIENTRY glGetnTexImageARB (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, GLvoid *img); +GLAPI void APIENTRY glReadnPixelsARB (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data); +GLAPI void APIENTRY glGetnCompressedTexImageARB (GLenum target, GLint lod, GLsizei bufSize, GLvoid *img); +GLAPI void APIENTRY glGetnUniformfvARB (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); +GLAPI void APIENTRY glGetnUniformivARB (GLuint program, GLint location, GLsizei bufSize, GLint *params); +GLAPI void APIENTRY glGetnUniformuivARB (GLuint program, GLint location, GLsizei bufSize, GLuint *params); +GLAPI void APIENTRY glGetnUniformdvARB (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLenum (APIENTRYP PFNGLGETGRAPHICSRESETSTATUSARBPROC) (void); +typedef void (APIENTRYP PFNGLGETNMAPDVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v); +typedef void (APIENTRYP PFNGLGETNMAPFVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v); +typedef void (APIENTRYP PFNGLGETNMAPIVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLint *v); +typedef void (APIENTRYP PFNGLGETNPIXELMAPFVARBPROC) (GLenum map, GLsizei bufSize, GLfloat *values); +typedef void (APIENTRYP PFNGLGETNPIXELMAPUIVARBPROC) (GLenum map, GLsizei bufSize, GLuint *values); +typedef void (APIENTRYP PFNGLGETNPIXELMAPUSVARBPROC) (GLenum map, GLsizei bufSize, GLushort *values); +typedef void (APIENTRYP PFNGLGETNPOLYGONSTIPPLEARBPROC) (GLsizei bufSize, GLubyte *pattern); +typedef void (APIENTRYP PFNGLGETNCOLORTABLEARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *table); +typedef void (APIENTRYP PFNGLGETNCONVOLUTIONFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, GLvoid *image); +typedef void (APIENTRYP PFNGLGETNSEPARABLEFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, GLvoid *row, GLsizei columnBufSize, GLvoid *column, GLvoid *span); +typedef void (APIENTRYP PFNGLGETNHISTOGRAMARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); +typedef void (APIENTRYP PFNGLGETNMINMAXARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, GLvoid *values); +typedef void (APIENTRYP PFNGLGETNTEXIMAGEARBPROC) (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, GLvoid *img); +typedef void (APIENTRYP PFNGLREADNPIXELSARBPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data); +typedef void (APIENTRYP PFNGLGETNCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint lod, GLsizei bufSize, GLvoid *img); +typedef void (APIENTRYP PFNGLGETNUNIFORMFVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLfloat *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMUIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLuint *params); +typedef void (APIENTRYP PFNGLGETNUNIFORMDVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLdouble *params); +#endif + +#ifndef GL_ARB_shader_stencil_export +#define GL_ARB_shader_stencil_export 1 +#endif + +#ifndef GL_EXT_abgr +#define GL_EXT_abgr 1 +#endif + +#ifndef GL_EXT_blend_color +#define GL_EXT_blend_color 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendColorEXT (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDCOLOREXTPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +#endif + +#ifndef GL_EXT_polygon_offset +#define GL_EXT_polygon_offset 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPolygonOffsetEXT (GLfloat factor, GLfloat bias); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOLYGONOFFSETEXTPROC) (GLfloat factor, GLfloat bias); +#endif + +#ifndef GL_EXT_texture +#define GL_EXT_texture 1 +#endif + +#ifndef GL_EXT_texture3D +#define GL_EXT_texture3D 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage3DEXT (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTexSubImage3DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE3DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_SGIS_texture_filter4 +#define GL_SGIS_texture_filter4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetTexFilterFuncSGIS (GLenum target, GLenum filter, GLfloat *weights); +GLAPI void APIENTRY glTexFilterFuncSGIS (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLfloat *weights); +typedef void (APIENTRYP PFNGLTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights); +#endif + +#ifndef GL_EXT_subtexture +#define GL_EXT_subtexture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexSubImage1DEXT (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTexSubImage2DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_EXT_copy_texture +#define GL_EXT_copy_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCopyTexImage1DEXT (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +GLAPI void APIENTRY glCopyTexImage2DEXT (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GLAPI void APIENTRY glCopyTexSubImage1DEXT (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyTexSubImage2DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glCopyTexSubImage3DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_EXT_histogram +#define GL_EXT_histogram 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetHistogramEXT (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +GLAPI void APIENTRY glGetHistogramParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetHistogramParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMinmaxEXT (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +GLAPI void APIENTRY glGetMinmaxParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMinmaxParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glHistogramEXT (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +GLAPI void APIENTRY glMinmaxEXT (GLenum target, GLenum internalformat, GLboolean sink); +GLAPI void APIENTRY glResetHistogramEXT (GLenum target); +GLAPI void APIENTRY glResetMinmaxEXT (GLenum target); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETHISTOGRAMEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMINMAXEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLHISTOGRAMEXTPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLMINMAXEXTPROC) (GLenum target, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLRESETHISTOGRAMEXTPROC) (GLenum target); +typedef void (APIENTRYP PFNGLRESETMINMAXEXTPROC) (GLenum target); +#endif + +#ifndef GL_EXT_convolution +#define GL_EXT_convolution 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glConvolutionFilter1DEXT (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); +GLAPI void APIENTRY glConvolutionFilter2DEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); +GLAPI void APIENTRY glConvolutionParameterfEXT (GLenum target, GLenum pname, GLfloat params); +GLAPI void APIENTRY glConvolutionParameterfvEXT (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glConvolutionParameteriEXT (GLenum target, GLenum pname, GLint params); +GLAPI void APIENTRY glConvolutionParameterivEXT (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glCopyConvolutionFilter1DEXT (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyConvolutionFilter2DEXT (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetConvolutionFilterEXT (GLenum target, GLenum format, GLenum type, GLvoid *image); +GLAPI void APIENTRY glGetConvolutionParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetConvolutionParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetSeparableFilterEXT (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); +GLAPI void APIENTRY glSeparableFilter2DEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *image); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSEPARABLEFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); +typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); +#endif + +#ifndef GL_SGI_color_matrix +#define GL_SGI_color_matrix 1 +#endif + +#ifndef GL_SGI_color_table +#define GL_SGI_color_table 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTableSGI (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +GLAPI void APIENTRY glColorTableParameterfvSGI (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glColorTableParameterivSGI (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glCopyColorTableSGI (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glGetColorTableSGI (GLenum target, GLenum format, GLenum type, GLvoid *table); +GLAPI void APIENTRY glGetColorTableParameterfvSGI (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetColorTableParameterivSGI (GLenum target, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLGETCOLORTABLESGIPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, GLint *params); +#endif + +#ifndef GL_SGIX_pixel_texture +#define GL_SGIX_pixel_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTexGenSGIX (GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTEXGENSGIXPROC) (GLenum mode); +#endif + +#ifndef GL_SGIS_pixel_texture +#define GL_SGIS_pixel_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTexGenParameteriSGIS (GLenum pname, GLint param); +GLAPI void APIENTRY glPixelTexGenParameterivSGIS (GLenum pname, const GLint *params); +GLAPI void APIENTRY glPixelTexGenParameterfSGIS (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPixelTexGenParameterfvSGIS (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glGetPixelTexGenParameterivSGIS (GLenum pname, GLint *params); +GLAPI void APIENTRY glGetPixelTexGenParameterfvSGIS (GLenum pname, GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERISGISPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFSGISPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, GLfloat *params); +#endif + +#ifndef GL_SGIS_texture4D +#define GL_SGIS_texture4D 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage4DSGIS (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTexSubImage4DSGIS (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const GLvoid *pixels); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE4DSGISPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE4DSGISPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_SGI_texture_color_table +#define GL_SGI_texture_color_table 1 +#endif + +#ifndef GL_EXT_cmyka +#define GL_EXT_cmyka 1 +#endif + +#ifndef GL_EXT_texture_object +#define GL_EXT_texture_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glAreTexturesResidentEXT (GLsizei n, const GLuint *textures, GLboolean *residences); +GLAPI void APIENTRY glBindTextureEXT (GLenum target, GLuint texture); +GLAPI void APIENTRY glDeleteTexturesEXT (GLsizei n, const GLuint *textures); +GLAPI void APIENTRY glGenTexturesEXT (GLsizei n, GLuint *textures); +GLAPI GLboolean APIENTRY glIsTextureEXT (GLuint texture); +GLAPI void APIENTRY glPrioritizeTexturesEXT (GLsizei n, const GLuint *textures, const GLclampf *priorities); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLARETEXTURESRESIDENTEXTPROC) (GLsizei n, const GLuint *textures, GLboolean *residences); +typedef void (APIENTRYP PFNGLBINDTEXTUREEXTPROC) (GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLDELETETEXTURESEXTPROC) (GLsizei n, const GLuint *textures); +typedef void (APIENTRYP PFNGLGENTEXTURESEXTPROC) (GLsizei n, GLuint *textures); +typedef GLboolean (APIENTRYP PFNGLISTEXTUREEXTPROC) (GLuint texture); +typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESEXTPROC) (GLsizei n, const GLuint *textures, const GLclampf *priorities); +#endif + +#ifndef GL_SGIS_detail_texture +#define GL_SGIS_detail_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDetailTexFuncSGIS (GLenum target, GLsizei n, const GLfloat *points); +GLAPI void APIENTRY glGetDetailTexFuncSGIS (GLenum target, GLfloat *points); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDETAILTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETDETAILTEXFUNCSGISPROC) (GLenum target, GLfloat *points); +#endif + +#ifndef GL_SGIS_sharpen_texture +#define GL_SGIS_sharpen_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSharpenTexFuncSGIS (GLenum target, GLsizei n, const GLfloat *points); +GLAPI void APIENTRY glGetSharpenTexFuncSGIS (GLenum target, GLfloat *points); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSHARPENTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETSHARPENTEXFUNCSGISPROC) (GLenum target, GLfloat *points); +#endif + +#ifndef GL_EXT_packed_pixels +#define GL_EXT_packed_pixels 1 +#endif + +#ifndef GL_SGIS_texture_lod +#define GL_SGIS_texture_lod 1 +#endif + +#ifndef GL_SGIS_multisample +#define GL_SGIS_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleMaskSGIS (GLclampf value, GLboolean invert); +GLAPI void APIENTRY glSamplePatternSGIS (GLenum pattern); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLEMASKSGISPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLSAMPLEPATTERNSGISPROC) (GLenum pattern); +#endif + +#ifndef GL_EXT_rescale_normal +#define GL_EXT_rescale_normal 1 +#endif + +#ifndef GL_EXT_vertex_array +#define GL_EXT_vertex_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glArrayElementEXT (GLint i); +GLAPI void APIENTRY glColorPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +GLAPI void APIENTRY glDrawArraysEXT (GLenum mode, GLint first, GLsizei count); +GLAPI void APIENTRY glEdgeFlagPointerEXT (GLsizei stride, GLsizei count, const GLboolean *pointer); +GLAPI void APIENTRY glGetPointervEXT (GLenum pname, GLvoid* *params); +GLAPI void APIENTRY glIndexPointerEXT (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +GLAPI void APIENTRY glNormalPointerEXT (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +GLAPI void APIENTRY glTexCoordPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +GLAPI void APIENTRY glVertexPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLARRAYELEMENTEXTPROC) (GLint i); +typedef void (APIENTRYP PFNGLCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWARRAYSEXTPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLEDGEFLAGPOINTEREXTPROC) (GLsizei stride, GLsizei count, const GLboolean *pointer); +typedef void (APIENTRYP PFNGLGETPOINTERVEXTPROC) (GLenum pname, GLvoid* *params); +typedef void (APIENTRYP PFNGLINDEXPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLNORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_misc_attribute +#define GL_EXT_misc_attribute 1 +#endif + +#ifndef GL_SGIS_generate_mipmap +#define GL_SGIS_generate_mipmap 1 +#endif + +#ifndef GL_SGIX_clipmap +#define GL_SGIX_clipmap 1 +#endif + +#ifndef GL_SGIX_shadow +#define GL_SGIX_shadow 1 +#endif + +#ifndef GL_SGIS_texture_edge_clamp +#define GL_SGIS_texture_edge_clamp 1 +#endif + +#ifndef GL_SGIS_texture_border_clamp +#define GL_SGIS_texture_border_clamp 1 +#endif + +#ifndef GL_EXT_blend_minmax +#define GL_EXT_blend_minmax 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationEXT (GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONEXTPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_blend_subtract +#define GL_EXT_blend_subtract 1 +#endif + +#ifndef GL_EXT_blend_logic_op +#define GL_EXT_blend_logic_op 1 +#endif + +#ifndef GL_SGIX_interlace +#define GL_SGIX_interlace 1 +#endif + +#ifndef GL_SGIX_pixel_tiles +#define GL_SGIX_pixel_tiles 1 +#endif + +#ifndef GL_SGIX_texture_select +#define GL_SGIX_texture_select 1 +#endif + +#ifndef GL_SGIX_sprite +#define GL_SGIX_sprite 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSpriteParameterfSGIX (GLenum pname, GLfloat param); +GLAPI void APIENTRY glSpriteParameterfvSGIX (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glSpriteParameteriSGIX (GLenum pname, GLint param); +GLAPI void APIENTRY glSpriteParameterivSGIX (GLenum pname, const GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSPRITEPARAMETERFSGIXPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERFVSGIXPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERISGIXPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERIVSGIXPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_SGIX_texture_multi_buffer +#define GL_SGIX_texture_multi_buffer 1 +#endif + +#ifndef GL_EXT_point_parameters +#define GL_EXT_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfEXT (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPointParameterfvEXT (GLenum pname, const GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVEXTPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_SGIS_point_parameters +#define GL_SGIS_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfSGIS (GLenum pname, GLfloat param); +GLAPI void APIENTRY glPointParameterfvSGIS (GLenum pname, const GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFSGISPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_SGIX_instruments +#define GL_SGIX_instruments 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLint APIENTRY glGetInstrumentsSGIX (void); +GLAPI void APIENTRY glInstrumentsBufferSGIX (GLsizei size, GLint *buffer); +GLAPI GLint APIENTRY glPollInstrumentsSGIX (GLint *marker_p); +GLAPI void APIENTRY glReadInstrumentsSGIX (GLint marker); +GLAPI void APIENTRY glStartInstrumentsSGIX (void); +GLAPI void APIENTRY glStopInstrumentsSGIX (GLint marker); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLint (APIENTRYP PFNGLGETINSTRUMENTSSGIXPROC) (void); +typedef void (APIENTRYP PFNGLINSTRUMENTSBUFFERSGIXPROC) (GLsizei size, GLint *buffer); +typedef GLint (APIENTRYP PFNGLPOLLINSTRUMENTSSGIXPROC) (GLint *marker_p); +typedef void (APIENTRYP PFNGLREADINSTRUMENTSSGIXPROC) (GLint marker); +typedef void (APIENTRYP PFNGLSTARTINSTRUMENTSSGIXPROC) (void); +typedef void (APIENTRYP PFNGLSTOPINSTRUMENTSSGIXPROC) (GLint marker); +#endif + +#ifndef GL_SGIX_texture_scale_bias +#define GL_SGIX_texture_scale_bias 1 +#endif + +#ifndef GL_SGIX_framezoom +#define GL_SGIX_framezoom 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFrameZoomSGIX (GLint factor); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAMEZOOMSGIXPROC) (GLint factor); +#endif + +#ifndef GL_SGIX_tag_sample_buffer +#define GL_SGIX_tag_sample_buffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTagSampleBufferSGIX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTAGSAMPLEBUFFERSGIXPROC) (void); +#endif + +#ifndef GL_SGIX_polynomial_ffd +#define GL_SGIX_polynomial_ffd 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeformationMap3dSGIX (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points); +GLAPI void APIENTRY glDeformationMap3fSGIX (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points); +GLAPI void APIENTRY glDeformSGIX (GLbitfield mask); +GLAPI void APIENTRY glLoadIdentityDeformationMapSGIX (GLbitfield mask); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEFORMATIONMAP3DSGIXPROC) (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points); +typedef void (APIENTRYP PFNGLDEFORMATIONMAP3FSGIXPROC) (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points); +typedef void (APIENTRYP PFNGLDEFORMSGIXPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLLOADIDENTITYDEFORMATIONMAPSGIXPROC) (GLbitfield mask); +#endif + +#ifndef GL_SGIX_reference_plane +#define GL_SGIX_reference_plane 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReferencePlaneSGIX (const GLdouble *equation); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLREFERENCEPLANESGIXPROC) (const GLdouble *equation); +#endif + +#ifndef GL_SGIX_flush_raster +#define GL_SGIX_flush_raster 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFlushRasterSGIX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFLUSHRASTERSGIXPROC) (void); +#endif + +#ifndef GL_SGIX_depth_texture +#define GL_SGIX_depth_texture 1 +#endif + +#ifndef GL_SGIS_fog_function +#define GL_SGIS_fog_function 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogFuncSGIS (GLsizei n, const GLfloat *points); +GLAPI void APIENTRY glGetFogFuncSGIS (GLfloat *points); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFOGFUNCSGISPROC) (GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETFOGFUNCSGISPROC) (GLfloat *points); +#endif + +#ifndef GL_SGIX_fog_offset +#define GL_SGIX_fog_offset 1 +#endif + +#ifndef GL_HP_image_transform +#define GL_HP_image_transform 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glImageTransformParameteriHP (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glImageTransformParameterfHP (GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glImageTransformParameterivHP (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glImageTransformParameterfvHP (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glGetImageTransformParameterivHP (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetImageTransformParameterfvHP (GLenum target, GLenum pname, GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIHPPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFHPPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_HP_convolution_border_modes +#define GL_HP_convolution_border_modes 1 +#endif + +#ifndef GL_SGIX_texture_add_env +#define GL_SGIX_texture_add_env 1 +#endif + +#ifndef GL_EXT_color_subtable +#define GL_EXT_color_subtable 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorSubTableEXT (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); +GLAPI void APIENTRY glCopyColorSubTableEXT (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +#endif + +#ifndef GL_PGI_vertex_hints +#define GL_PGI_vertex_hints 1 +#endif + +#ifndef GL_PGI_misc_hints +#define GL_PGI_misc_hints 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glHintPGI (GLenum target, GLint mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLHINTPGIPROC) (GLenum target, GLint mode); +#endif + +#ifndef GL_EXT_paletted_texture +#define GL_EXT_paletted_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTableEXT (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +GLAPI void APIENTRY glGetColorTableEXT (GLenum target, GLenum format, GLenum type, GLvoid *data); +GLAPI void APIENTRY glGetColorTableParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetColorTableParameterfvEXT (GLenum target, GLenum pname, GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORTABLEEXTPROC) (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEEXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_EXT_clip_volume_hint +#define GL_EXT_clip_volume_hint 1 +#endif + +#ifndef GL_SGIX_list_priority +#define GL_SGIX_list_priority 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetListParameterfvSGIX (GLuint list, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetListParameterivSGIX (GLuint list, GLenum pname, GLint *params); +GLAPI void APIENTRY glListParameterfSGIX (GLuint list, GLenum pname, GLfloat param); +GLAPI void APIENTRY glListParameterfvSGIX (GLuint list, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glListParameteriSGIX (GLuint list, GLenum pname, GLint param); +GLAPI void APIENTRY glListParameterivSGIX (GLuint list, GLenum pname, const GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLLISTPARAMETERFSGIXPROC) (GLuint list, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLLISTPARAMETERISGIXPROC) (GLuint list, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, const GLint *params); +#endif + +#ifndef GL_SGIX_ir_instrument1 +#define GL_SGIX_ir_instrument1 1 +#endif + +#ifndef GL_SGIX_calligraphic_fragment +#define GL_SGIX_calligraphic_fragment 1 +#endif + +#ifndef GL_SGIX_texture_lod_bias +#define GL_SGIX_texture_lod_bias 1 +#endif + +#ifndef GL_SGIX_shadow_ambient +#define GL_SGIX_shadow_ambient 1 +#endif + +#ifndef GL_EXT_index_texture +#define GL_EXT_index_texture 1 +#endif + +#ifndef GL_EXT_index_material +#define GL_EXT_index_material 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIndexMaterialEXT (GLenum face, GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLINDEXMATERIALEXTPROC) (GLenum face, GLenum mode); +#endif + +#ifndef GL_EXT_index_func +#define GL_EXT_index_func 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIndexFuncEXT (GLenum func, GLclampf ref); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLINDEXFUNCEXTPROC) (GLenum func, GLclampf ref); +#endif + +#ifndef GL_EXT_index_array_formats +#define GL_EXT_index_array_formats 1 +#endif + +#ifndef GL_EXT_compiled_vertex_array +#define GL_EXT_compiled_vertex_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glLockArraysEXT (GLint first, GLsizei count); +GLAPI void APIENTRY glUnlockArraysEXT (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLUNLOCKARRAYSEXTPROC) (void); +#endif + +#ifndef GL_EXT_cull_vertex +#define GL_EXT_cull_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCullParameterdvEXT (GLenum pname, GLdouble *params); +GLAPI void APIENTRY glCullParameterfvEXT (GLenum pname, GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCULLPARAMETERDVEXTPROC) (GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLCULLPARAMETERFVEXTPROC) (GLenum pname, GLfloat *params); +#endif + +#ifndef GL_SGIX_ycrcb +#define GL_SGIX_ycrcb 1 +#endif + +#ifndef GL_SGIX_fragment_lighting +#define GL_SGIX_fragment_lighting 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFragmentColorMaterialSGIX (GLenum face, GLenum mode); +GLAPI void APIENTRY glFragmentLightfSGIX (GLenum light, GLenum pname, GLfloat param); +GLAPI void APIENTRY glFragmentLightfvSGIX (GLenum light, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glFragmentLightiSGIX (GLenum light, GLenum pname, GLint param); +GLAPI void APIENTRY glFragmentLightivSGIX (GLenum light, GLenum pname, const GLint *params); +GLAPI void APIENTRY glFragmentLightModelfSGIX (GLenum pname, GLfloat param); +GLAPI void APIENTRY glFragmentLightModelfvSGIX (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glFragmentLightModeliSGIX (GLenum pname, GLint param); +GLAPI void APIENTRY glFragmentLightModelivSGIX (GLenum pname, const GLint *params); +GLAPI void APIENTRY glFragmentMaterialfSGIX (GLenum face, GLenum pname, GLfloat param); +GLAPI void APIENTRY glFragmentMaterialfvSGIX (GLenum face, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glFragmentMaterialiSGIX (GLenum face, GLenum pname, GLint param); +GLAPI void APIENTRY glFragmentMaterialivSGIX (GLenum face, GLenum pname, const GLint *params); +GLAPI void APIENTRY glGetFragmentLightfvSGIX (GLenum light, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetFragmentLightivSGIX (GLenum light, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetFragmentMaterialfvSGIX (GLenum face, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetFragmentMaterialivSGIX (GLenum face, GLenum pname, GLint *params); +GLAPI void APIENTRY glLightEnviSGIX (GLenum pname, GLint param); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAGMENTCOLORMATERIALSGIXPROC) (GLenum face, GLenum mode); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFSGIXPROC) (GLenum light, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTISGIXPROC) (GLenum light, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFSGIXPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFVSGIXPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELISGIXPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELIVSGIXPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFSGIXPROC) (GLenum face, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALISGIXPROC) (GLenum face, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLLIGHTENVISGIXPROC) (GLenum pname, GLint param); +#endif + +#ifndef GL_IBM_rasterpos_clip +#define GL_IBM_rasterpos_clip 1 +#endif + +#ifndef GL_HP_texture_lighting +#define GL_HP_texture_lighting 1 +#endif + +#ifndef GL_EXT_draw_range_elements +#define GL_EXT_draw_range_elements 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawRangeElementsEXT (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +#endif + +#ifndef GL_WIN_phong_shading +#define GL_WIN_phong_shading 1 +#endif + +#ifndef GL_WIN_specular_fog +#define GL_WIN_specular_fog 1 +#endif + +#ifndef GL_EXT_light_texture +#define GL_EXT_light_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glApplyTextureEXT (GLenum mode); +GLAPI void APIENTRY glTextureLightEXT (GLenum pname); +GLAPI void APIENTRY glTextureMaterialEXT (GLenum face, GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLAPPLYTEXTUREEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLTEXTURELIGHTEXTPROC) (GLenum pname); +typedef void (APIENTRYP PFNGLTEXTUREMATERIALEXTPROC) (GLenum face, GLenum mode); +#endif + +#ifndef GL_SGIX_blend_alpha_minmax +#define GL_SGIX_blend_alpha_minmax 1 +#endif + +#ifndef GL_EXT_bgra +#define GL_EXT_bgra 1 +#endif + +#ifndef GL_SGIX_async +#define GL_SGIX_async 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glAsyncMarkerSGIX (GLuint marker); +GLAPI GLint APIENTRY glFinishAsyncSGIX (GLuint *markerp); +GLAPI GLint APIENTRY glPollAsyncSGIX (GLuint *markerp); +GLAPI GLuint APIENTRY glGenAsyncMarkersSGIX (GLsizei range); +GLAPI void APIENTRY glDeleteAsyncMarkersSGIX (GLuint marker, GLsizei range); +GLAPI GLboolean APIENTRY glIsAsyncMarkerSGIX (GLuint marker); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLASYNCMARKERSGIXPROC) (GLuint marker); +typedef GLint (APIENTRYP PFNGLFINISHASYNCSGIXPROC) (GLuint *markerp); +typedef GLint (APIENTRYP PFNGLPOLLASYNCSGIXPROC) (GLuint *markerp); +typedef GLuint (APIENTRYP PFNGLGENASYNCMARKERSSGIXPROC) (GLsizei range); +typedef void (APIENTRYP PFNGLDELETEASYNCMARKERSSGIXPROC) (GLuint marker, GLsizei range); +typedef GLboolean (APIENTRYP PFNGLISASYNCMARKERSGIXPROC) (GLuint marker); +#endif + +#ifndef GL_SGIX_async_pixel +#define GL_SGIX_async_pixel 1 +#endif + +#ifndef GL_SGIX_async_histogram +#define GL_SGIX_async_histogram 1 +#endif + +#ifndef GL_INTEL_parallel_arrays +#define GL_INTEL_parallel_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexPointervINTEL (GLint size, GLenum type, const GLvoid* *pointer); +GLAPI void APIENTRY glNormalPointervINTEL (GLenum type, const GLvoid* *pointer); +GLAPI void APIENTRY glColorPointervINTEL (GLint size, GLenum type, const GLvoid* *pointer); +GLAPI void APIENTRY glTexCoordPointervINTEL (GLint size, GLenum type, const GLvoid* *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLNORMALPOINTERVINTELPROC) (GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLCOLORPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +#endif + +#ifndef GL_HP_occlusion_test +#define GL_HP_occlusion_test 1 +#endif + +#ifndef GL_EXT_pixel_transform +#define GL_EXT_pixel_transform 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTransformParameteriEXT (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glPixelTransformParameterfEXT (GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glPixelTransformParameterivEXT (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glPixelTransformParameterfvEXT (GLenum target, GLenum pname, const GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_EXT_pixel_transform_color_table +#define GL_EXT_pixel_transform_color_table 1 +#endif + +#ifndef GL_EXT_shared_texture_palette +#define GL_EXT_shared_texture_palette 1 +#endif + +#ifndef GL_EXT_separate_specular_color +#define GL_EXT_separate_specular_color 1 +#endif + +#ifndef GL_EXT_secondary_color +#define GL_EXT_secondary_color 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSecondaryColor3bEXT (GLbyte red, GLbyte green, GLbyte blue); +GLAPI void APIENTRY glSecondaryColor3bvEXT (const GLbyte *v); +GLAPI void APIENTRY glSecondaryColor3dEXT (GLdouble red, GLdouble green, GLdouble blue); +GLAPI void APIENTRY glSecondaryColor3dvEXT (const GLdouble *v); +GLAPI void APIENTRY glSecondaryColor3fEXT (GLfloat red, GLfloat green, GLfloat blue); +GLAPI void APIENTRY glSecondaryColor3fvEXT (const GLfloat *v); +GLAPI void APIENTRY glSecondaryColor3iEXT (GLint red, GLint green, GLint blue); +GLAPI void APIENTRY glSecondaryColor3ivEXT (const GLint *v); +GLAPI void APIENTRY glSecondaryColor3sEXT (GLshort red, GLshort green, GLshort blue); +GLAPI void APIENTRY glSecondaryColor3svEXT (const GLshort *v); +GLAPI void APIENTRY glSecondaryColor3ubEXT (GLubyte red, GLubyte green, GLubyte blue); +GLAPI void APIENTRY glSecondaryColor3ubvEXT (const GLubyte *v); +GLAPI void APIENTRY glSecondaryColor3uiEXT (GLuint red, GLuint green, GLuint blue); +GLAPI void APIENTRY glSecondaryColor3uivEXT (const GLuint *v); +GLAPI void APIENTRY glSecondaryColor3usEXT (GLushort red, GLushort green, GLushort blue); +GLAPI void APIENTRY glSecondaryColor3usvEXT (const GLushort *v); +GLAPI void APIENTRY glSecondaryColorPointerEXT (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BEXTPROC) (GLbyte red, GLbyte green, GLbyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DEXTPROC) (GLdouble red, GLdouble green, GLdouble blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FEXTPROC) (GLfloat red, GLfloat green, GLfloat blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IEXTPROC) (GLint red, GLint green, GLint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SEXTPROC) (GLshort red, GLshort green, GLshort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBEXTPROC) (GLubyte red, GLubyte green, GLubyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVEXTPROC) (const GLubyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIEXTPROC) (GLuint red, GLuint green, GLuint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVEXTPROC) (const GLuint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USEXTPROC) (GLushort red, GLushort green, GLushort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVEXTPROC) (const GLushort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_texture_perturb_normal +#define GL_EXT_texture_perturb_normal 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureNormalEXT (GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTURENORMALEXTPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_multi_draw_arrays +#define GL_EXT_multi_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiDrawArraysEXT (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +GLAPI void APIENTRY glMultiDrawElementsEXT (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +#endif + +#ifndef GL_EXT_fog_coord +#define GL_EXT_fog_coord 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogCoordfEXT (GLfloat coord); +GLAPI void APIENTRY glFogCoordfvEXT (const GLfloat *coord); +GLAPI void APIENTRY glFogCoorddEXT (GLdouble coord); +GLAPI void APIENTRY glFogCoorddvEXT (const GLdouble *coord); +GLAPI void APIENTRY glFogCoordPointerEXT (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFOGCOORDFEXTPROC) (GLfloat coord); +typedef void (APIENTRYP PFNGLFOGCOORDFVEXTPROC) (const GLfloat *coord); +typedef void (APIENTRYP PFNGLFOGCOORDDEXTPROC) (GLdouble coord); +typedef void (APIENTRYP PFNGLFOGCOORDDVEXTPROC) (const GLdouble *coord); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_REND_screen_coordinates +#define GL_REND_screen_coordinates 1 +#endif + +#ifndef GL_EXT_coordinate_frame +#define GL_EXT_coordinate_frame 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTangent3bEXT (GLbyte tx, GLbyte ty, GLbyte tz); +GLAPI void APIENTRY glTangent3bvEXT (const GLbyte *v); +GLAPI void APIENTRY glTangent3dEXT (GLdouble tx, GLdouble ty, GLdouble tz); +GLAPI void APIENTRY glTangent3dvEXT (const GLdouble *v); +GLAPI void APIENTRY glTangent3fEXT (GLfloat tx, GLfloat ty, GLfloat tz); +GLAPI void APIENTRY glTangent3fvEXT (const GLfloat *v); +GLAPI void APIENTRY glTangent3iEXT (GLint tx, GLint ty, GLint tz); +GLAPI void APIENTRY glTangent3ivEXT (const GLint *v); +GLAPI void APIENTRY glTangent3sEXT (GLshort tx, GLshort ty, GLshort tz); +GLAPI void APIENTRY glTangent3svEXT (const GLshort *v); +GLAPI void APIENTRY glBinormal3bEXT (GLbyte bx, GLbyte by, GLbyte bz); +GLAPI void APIENTRY glBinormal3bvEXT (const GLbyte *v); +GLAPI void APIENTRY glBinormal3dEXT (GLdouble bx, GLdouble by, GLdouble bz); +GLAPI void APIENTRY glBinormal3dvEXT (const GLdouble *v); +GLAPI void APIENTRY glBinormal3fEXT (GLfloat bx, GLfloat by, GLfloat bz); +GLAPI void APIENTRY glBinormal3fvEXT (const GLfloat *v); +GLAPI void APIENTRY glBinormal3iEXT (GLint bx, GLint by, GLint bz); +GLAPI void APIENTRY glBinormal3ivEXT (const GLint *v); +GLAPI void APIENTRY glBinormal3sEXT (GLshort bx, GLshort by, GLshort bz); +GLAPI void APIENTRY glBinormal3svEXT (const GLshort *v); +GLAPI void APIENTRY glTangentPointerEXT (GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glBinormalPointerEXT (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTANGENT3BEXTPROC) (GLbyte tx, GLbyte ty, GLbyte tz); +typedef void (APIENTRYP PFNGLTANGENT3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLTANGENT3DEXTPROC) (GLdouble tx, GLdouble ty, GLdouble tz); +typedef void (APIENTRYP PFNGLTANGENT3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLTANGENT3FEXTPROC) (GLfloat tx, GLfloat ty, GLfloat tz); +typedef void (APIENTRYP PFNGLTANGENT3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLTANGENT3IEXTPROC) (GLint tx, GLint ty, GLint tz); +typedef void (APIENTRYP PFNGLTANGENT3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLTANGENT3SEXTPROC) (GLshort tx, GLshort ty, GLshort tz); +typedef void (APIENTRYP PFNGLTANGENT3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLBINORMAL3BEXTPROC) (GLbyte bx, GLbyte by, GLbyte bz); +typedef void (APIENTRYP PFNGLBINORMAL3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLBINORMAL3DEXTPROC) (GLdouble bx, GLdouble by, GLdouble bz); +typedef void (APIENTRYP PFNGLBINORMAL3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLBINORMAL3FEXTPROC) (GLfloat bx, GLfloat by, GLfloat bz); +typedef void (APIENTRYP PFNGLBINORMAL3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLBINORMAL3IEXTPROC) (GLint bx, GLint by, GLint bz); +typedef void (APIENTRYP PFNGLBINORMAL3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLBINORMAL3SEXTPROC) (GLshort bx, GLshort by, GLshort bz); +typedef void (APIENTRYP PFNGLBINORMAL3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLTANGENTPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLBINORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_texture_env_combine +#define GL_EXT_texture_env_combine 1 +#endif + +#ifndef GL_APPLE_specular_vector +#define GL_APPLE_specular_vector 1 +#endif + +#ifndef GL_APPLE_transform_hint +#define GL_APPLE_transform_hint 1 +#endif + +#ifndef GL_SGIX_fog_scale +#define GL_SGIX_fog_scale 1 +#endif + +#ifndef GL_SUNX_constant_data +#define GL_SUNX_constant_data 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFinishTextureSUNX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFINISHTEXTURESUNXPROC) (void); +#endif + +#ifndef GL_SUN_global_alpha +#define GL_SUN_global_alpha 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGlobalAlphaFactorbSUN (GLbyte factor); +GLAPI void APIENTRY glGlobalAlphaFactorsSUN (GLshort factor); +GLAPI void APIENTRY glGlobalAlphaFactoriSUN (GLint factor); +GLAPI void APIENTRY glGlobalAlphaFactorfSUN (GLfloat factor); +GLAPI void APIENTRY glGlobalAlphaFactordSUN (GLdouble factor); +GLAPI void APIENTRY glGlobalAlphaFactorubSUN (GLubyte factor); +GLAPI void APIENTRY glGlobalAlphaFactorusSUN (GLushort factor); +GLAPI void APIENTRY glGlobalAlphaFactoruiSUN (GLuint factor); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORBSUNPROC) (GLbyte factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORSSUNPROC) (GLshort factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORISUNPROC) (GLint factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORFSUNPROC) (GLfloat factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORDSUNPROC) (GLdouble factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUBSUNPROC) (GLubyte factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUSSUNPROC) (GLushort factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUISUNPROC) (GLuint factor); +#endif + +#ifndef GL_SUN_triangle_list +#define GL_SUN_triangle_list 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReplacementCodeuiSUN (GLuint code); +GLAPI void APIENTRY glReplacementCodeusSUN (GLushort code); +GLAPI void APIENTRY glReplacementCodeubSUN (GLubyte code); +GLAPI void APIENTRY glReplacementCodeuivSUN (const GLuint *code); +GLAPI void APIENTRY glReplacementCodeusvSUN (const GLushort *code); +GLAPI void APIENTRY glReplacementCodeubvSUN (const GLubyte *code); +GLAPI void APIENTRY glReplacementCodePointerSUN (GLenum type, GLsizei stride, const GLvoid* *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUISUNPROC) (GLuint code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSSUNPROC) (GLushort code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBSUNPROC) (GLubyte code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVSUNPROC) (const GLuint *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSVSUNPROC) (const GLushort *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBVSUNPROC) (const GLubyte *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEPOINTERSUNPROC) (GLenum type, GLsizei stride, const GLvoid* *pointer); +#endif + +#ifndef GL_SUN_vertex +#define GL_SUN_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColor4ubVertex2fSUN (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y); +GLAPI void APIENTRY glColor4ubVertex2fvSUN (const GLubyte *c, const GLfloat *v); +GLAPI void APIENTRY glColor4ubVertex3fSUN (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glColor4ubVertex3fvSUN (const GLubyte *c, const GLfloat *v); +GLAPI void APIENTRY glColor3fVertex3fSUN (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glColor3fVertex3fvSUN (const GLfloat *c, const GLfloat *v); +GLAPI void APIENTRY glNormal3fVertex3fSUN (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glNormal3fVertex3fvSUN (const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glColor4fNormal3fVertex3fSUN (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glColor4fNormal3fVertex3fvSUN (const GLfloat *c, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fVertex3fSUN (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fVertex3fvSUN (const GLfloat *tc, const GLfloat *v); +GLAPI void APIENTRY glTexCoord4fVertex4fSUN (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glTexCoord4fVertex4fvSUN (const GLfloat *tc, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fSUN (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fvSUN (const GLfloat *tc, const GLubyte *c, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fColor3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fColor3fVertex3fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fvSUN (const GLfloat *tc, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fSUN (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiVertex3fSUN (GLuint rc, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiVertex3fvSUN (const GLuint *rc, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fSUN (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fvSUN (const GLuint *rc, const GLubyte *c, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fSUN (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fvSUN (const GLuint *rc, const GLfloat *c, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fSUN (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fSUN (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FVSUNPROC) (const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FVSUNPROC) (const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FSUNPROC) (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FVSUNPROC) (const GLfloat *tc, const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FSUNPROC) (GLuint rc, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FSUNPROC) (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FVSUNPROC) (const GLuint *rc, const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +#endif + +#ifndef GL_EXT_blend_func_separate +#define GL_EXT_blend_func_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparateEXT (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEEXTPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif + +#ifndef GL_INGR_blend_func_separate +#define GL_INGR_blend_func_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparateINGR (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINGRPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif + +#ifndef GL_INGR_color_clamp +#define GL_INGR_color_clamp 1 +#endif + +#ifndef GL_INGR_interlace_read +#define GL_INGR_interlace_read 1 +#endif + +#ifndef GL_EXT_stencil_wrap +#define GL_EXT_stencil_wrap 1 +#endif + +#ifndef GL_EXT_422_pixels +#define GL_EXT_422_pixels 1 +#endif + +#ifndef GL_NV_texgen_reflection +#define GL_NV_texgen_reflection 1 +#endif + +#ifndef GL_SUN_convolution_border_modes +#define GL_SUN_convolution_border_modes 1 +#endif + +#ifndef GL_EXT_texture_env_add +#define GL_EXT_texture_env_add 1 +#endif + +#ifndef GL_EXT_texture_lod_bias +#define GL_EXT_texture_lod_bias 1 +#endif + +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_EXT_texture_filter_anisotropic 1 +#endif + +#ifndef GL_EXT_vertex_weighting +#define GL_EXT_vertex_weighting 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexWeightfEXT (GLfloat weight); +GLAPI void APIENTRY glVertexWeightfvEXT (const GLfloat *weight); +GLAPI void APIENTRY glVertexWeightPointerEXT (GLsizei size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXWEIGHTFEXTPROC) (GLfloat weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTFVEXTPROC) (const GLfloat *weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTPOINTEREXTPROC) (GLsizei size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_NV_light_max_exponent +#define GL_NV_light_max_exponent 1 +#endif + +#ifndef GL_NV_vertex_array_range +#define GL_NV_vertex_array_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFlushVertexArrayRangeNV (void); +GLAPI void APIENTRY glVertexArrayRangeNV (GLsizei length, const GLvoid *pointer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGENVPROC) (void); +typedef void (APIENTRYP PFNGLVERTEXARRAYRANGENVPROC) (GLsizei length, const GLvoid *pointer); +#endif + +#ifndef GL_NV_register_combiners +#define GL_NV_register_combiners 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCombinerParameterfvNV (GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glCombinerParameterfNV (GLenum pname, GLfloat param); +GLAPI void APIENTRY glCombinerParameterivNV (GLenum pname, const GLint *params); +GLAPI void APIENTRY glCombinerParameteriNV (GLenum pname, GLint param); +GLAPI void APIENTRY glCombinerInputNV (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +GLAPI void APIENTRY glCombinerOutputNV (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum); +GLAPI void APIENTRY glFinalCombinerInputNV (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +GLAPI void APIENTRY glGetCombinerInputParameterfvNV (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetCombinerInputParameterivNV (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetCombinerOutputParameterfvNV (GLenum stage, GLenum portion, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetCombinerOutputParameterivNV (GLenum stage, GLenum portion, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetFinalCombinerInputParameterfvNV (GLenum variable, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetFinalCombinerInputParameterivNV (GLenum variable, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFVNVPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFNVPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERIVNVPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERINVPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLCOMBINERINPUTNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +typedef void (APIENTRYP PFNGLCOMBINEROUTPUTNVPROC) (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum); +typedef void (APIENTRYP PFNGLFINALCOMBINERINPUTNVPROC) (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERFVNVPROC) (GLenum variable, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC) (GLenum variable, GLenum pname, GLint *params); +#endif + +#ifndef GL_NV_fog_distance +#define GL_NV_fog_distance 1 +#endif + +#ifndef GL_NV_texgen_emboss +#define GL_NV_texgen_emboss 1 +#endif + +#ifndef GL_NV_blend_square +#define GL_NV_blend_square 1 +#endif + +#ifndef GL_NV_texture_env_combine4 +#define GL_NV_texture_env_combine4 1 +#endif + +#ifndef GL_MESA_resize_buffers +#define GL_MESA_resize_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glResizeBuffersMESA (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRESIZEBUFFERSMESAPROC) (void); +#endif + +#ifndef GL_MESA_window_pos +#define GL_MESA_window_pos 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWindowPos2dMESA (GLdouble x, GLdouble y); +GLAPI void APIENTRY glWindowPos2dvMESA (const GLdouble *v); +GLAPI void APIENTRY glWindowPos2fMESA (GLfloat x, GLfloat y); +GLAPI void APIENTRY glWindowPos2fvMESA (const GLfloat *v); +GLAPI void APIENTRY glWindowPos2iMESA (GLint x, GLint y); +GLAPI void APIENTRY glWindowPos2ivMESA (const GLint *v); +GLAPI void APIENTRY glWindowPos2sMESA (GLshort x, GLshort y); +GLAPI void APIENTRY glWindowPos2svMESA (const GLshort *v); +GLAPI void APIENTRY glWindowPos3dMESA (GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glWindowPos3dvMESA (const GLdouble *v); +GLAPI void APIENTRY glWindowPos3fMESA (GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glWindowPos3fvMESA (const GLfloat *v); +GLAPI void APIENTRY glWindowPos3iMESA (GLint x, GLint y, GLint z); +GLAPI void APIENTRY glWindowPos3ivMESA (const GLint *v); +GLAPI void APIENTRY glWindowPos3sMESA (GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glWindowPos3svMESA (const GLshort *v); +GLAPI void APIENTRY glWindowPos4dMESA (GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glWindowPos4dvMESA (const GLdouble *v); +GLAPI void APIENTRY glWindowPos4fMESA (GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glWindowPos4fvMESA (const GLfloat *v); +GLAPI void APIENTRY glWindowPos4iMESA (GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glWindowPos4ivMESA (const GLint *v); +GLAPI void APIENTRY glWindowPos4sMESA (GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glWindowPos4svMESA (const GLshort *v); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWINDOWPOS2DMESAPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FMESAPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IMESAPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SMESAPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVMESAPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DMESAPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FMESAPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IMESAPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SMESAPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVMESAPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4DMESAPROC) (GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLWINDOWPOS4DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4FMESAPROC) (GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLWINDOWPOS4FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4IMESAPROC) (GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLWINDOWPOS4IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4SMESAPROC) (GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLWINDOWPOS4SVMESAPROC) (const GLshort *v); +#endif + +#ifndef GL_IBM_cull_vertex +#define GL_IBM_cull_vertex 1 +#endif + +#ifndef GL_IBM_multimode_draw_arrays +#define GL_IBM_multimode_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiModeDrawArraysIBM (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride); +GLAPI void APIENTRY glMultiModeDrawElementsIBM (const GLenum *mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount, GLint modestride); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMULTIMODEDRAWARRAYSIBMPROC) (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride); +typedef void (APIENTRYP PFNGLMULTIMODEDRAWELEMENTSIBMPROC) (const GLenum *mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount, GLint modestride); +#endif + +#ifndef GL_IBM_vertex_array_lists +#define GL_IBM_vertex_array_lists 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorPointerListIBM (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +GLAPI void APIENTRY glSecondaryColorPointerListIBM (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +GLAPI void APIENTRY glEdgeFlagPointerListIBM (GLint stride, const GLboolean* *pointer, GLint ptrstride); +GLAPI void APIENTRY glFogCoordPointerListIBM (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +GLAPI void APIENTRY glIndexPointerListIBM (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +GLAPI void APIENTRY glNormalPointerListIBM (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +GLAPI void APIENTRY glTexCoordPointerListIBM (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +GLAPI void APIENTRY glVertexPointerListIBM (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLEDGEFLAGPOINTERLISTIBMPROC) (GLint stride, const GLboolean* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLINDEXPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLNORMALPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLVERTEXPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +#endif + +#ifndef GL_SGIX_subsample +#define GL_SGIX_subsample 1 +#endif + +#ifndef GL_SGIX_ycrcba +#define GL_SGIX_ycrcba 1 +#endif + +#ifndef GL_SGIX_ycrcb_subsample +#define GL_SGIX_ycrcb_subsample 1 +#endif + +#ifndef GL_SGIX_depth_pass_instrument +#define GL_SGIX_depth_pass_instrument 1 +#endif + +#ifndef GL_3DFX_texture_compression_FXT1 +#define GL_3DFX_texture_compression_FXT1 1 +#endif + +#ifndef GL_3DFX_multisample +#define GL_3DFX_multisample 1 +#endif + +#ifndef GL_3DFX_tbuffer +#define GL_3DFX_tbuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTbufferMask3DFX (GLuint mask); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTBUFFERMASK3DFXPROC) (GLuint mask); +#endif + +#ifndef GL_EXT_multisample +#define GL_EXT_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleMaskEXT (GLclampf value, GLboolean invert); +GLAPI void APIENTRY glSamplePatternEXT (GLenum pattern); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLEMASKEXTPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLSAMPLEPATTERNEXTPROC) (GLenum pattern); +#endif + +#ifndef GL_SGIX_vertex_preclip +#define GL_SGIX_vertex_preclip 1 +#endif + +#ifndef GL_SGIX_convolution_accuracy +#define GL_SGIX_convolution_accuracy 1 +#endif + +#ifndef GL_SGIX_resample +#define GL_SGIX_resample 1 +#endif + +#ifndef GL_SGIS_point_line_texgen +#define GL_SGIS_point_line_texgen 1 +#endif + +#ifndef GL_SGIS_texture_color_mask +#define GL_SGIS_texture_color_mask 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureColorMaskSGIS (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTURECOLORMASKSGISPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +#endif + +#ifndef GL_SGIX_igloo_interface +#define GL_SGIX_igloo_interface 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIglooInterfaceSGIX (GLenum pname, const GLvoid *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLIGLOOINTERFACESGIXPROC) (GLenum pname, const GLvoid *params); +#endif + +#ifndef GL_EXT_texture_env_dot3 +#define GL_EXT_texture_env_dot3 1 +#endif + +#ifndef GL_ATI_texture_mirror_once +#define GL_ATI_texture_mirror_once 1 +#endif + +#ifndef GL_NV_fence +#define GL_NV_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeleteFencesNV (GLsizei n, const GLuint *fences); +GLAPI void APIENTRY glGenFencesNV (GLsizei n, GLuint *fences); +GLAPI GLboolean APIENTRY glIsFenceNV (GLuint fence); +GLAPI GLboolean APIENTRY glTestFenceNV (GLuint fence); +GLAPI void APIENTRY glGetFenceivNV (GLuint fence, GLenum pname, GLint *params); +GLAPI void APIENTRY glFinishFenceNV (GLuint fence); +GLAPI void APIENTRY glSetFenceNV (GLuint fence, GLenum condition); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences); +typedef void (APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences); +typedef GLboolean (APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition); +#endif + +#ifndef GL_NV_evaluators +#define GL_NV_evaluators 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMapControlPointsNV (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const GLvoid *points); +GLAPI void APIENTRY glMapParameterivNV (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glMapParameterfvNV (GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glGetMapControlPointsNV (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, GLvoid *points); +GLAPI void APIENTRY glGetMapParameterivNV (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMapParameterfvNV (GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMapAttribParameterivNV (GLenum target, GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMapAttribParameterfvNV (GLenum target, GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glEvalMapsNV (GLenum target, GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const GLvoid *points); +typedef void (APIENTRYP PFNGLMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, GLvoid *points); +typedef void (APIENTRYP PFNGLGETMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERIVNVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLEVALMAPSNVPROC) (GLenum target, GLenum mode); +#endif + +#ifndef GL_NV_packed_depth_stencil +#define GL_NV_packed_depth_stencil 1 +#endif + +#ifndef GL_NV_register_combiners2 +#define GL_NV_register_combiners2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCombinerStageParameterfvNV (GLenum stage, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glGetCombinerStageParameterfvNV (GLenum stage, GLenum pname, GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_NV_texture_compression_vtc +#define GL_NV_texture_compression_vtc 1 +#endif + +#ifndef GL_NV_texture_rectangle +#define GL_NV_texture_rectangle 1 +#endif + +#ifndef GL_NV_texture_shader +#define GL_NV_texture_shader 1 +#endif + +#ifndef GL_NV_texture_shader2 +#define GL_NV_texture_shader2 1 +#endif + +#ifndef GL_NV_vertex_array_range2 +#define GL_NV_vertex_array_range2 1 +#endif + +#ifndef GL_NV_vertex_program +#define GL_NV_vertex_program 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glAreProgramsResidentNV (GLsizei n, const GLuint *programs, GLboolean *residences); +GLAPI void APIENTRY glBindProgramNV (GLenum target, GLuint id); +GLAPI void APIENTRY glDeleteProgramsNV (GLsizei n, const GLuint *programs); +GLAPI void APIENTRY glExecuteProgramNV (GLenum target, GLuint id, const GLfloat *params); +GLAPI void APIENTRY glGenProgramsNV (GLsizei n, GLuint *programs); +GLAPI void APIENTRY glGetProgramParameterdvNV (GLenum target, GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetProgramParameterfvNV (GLenum target, GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetProgramivNV (GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetProgramStringNV (GLuint id, GLenum pname, GLubyte *program); +GLAPI void APIENTRY glGetTrackMatrixivNV (GLenum target, GLuint address, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribdvNV (GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetVertexAttribfvNV (GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVertexAttribivNV (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribPointervNV (GLuint index, GLenum pname, GLvoid* *pointer); +GLAPI GLboolean APIENTRY glIsProgramNV (GLuint id); +GLAPI void APIENTRY glLoadProgramNV (GLenum target, GLuint id, GLsizei len, const GLubyte *program); +GLAPI void APIENTRY glProgramParameter4dNV (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramParameter4dvNV (GLenum target, GLuint index, const GLdouble *v); +GLAPI void APIENTRY glProgramParameter4fNV (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glProgramParameter4fvNV (GLenum target, GLuint index, const GLfloat *v); +GLAPI void APIENTRY glProgramParameters4dvNV (GLenum target, GLuint index, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glProgramParameters4fvNV (GLenum target, GLuint index, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glRequestResidentProgramsNV (GLsizei n, const GLuint *programs); +GLAPI void APIENTRY glTrackMatrixNV (GLenum target, GLuint address, GLenum matrix, GLenum transform); +GLAPI void APIENTRY glVertexAttribPointerNV (GLuint index, GLint fsize, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glVertexAttrib1dNV (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttrib1dvNV (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib1fNV (GLuint index, GLfloat x); +GLAPI void APIENTRY glVertexAttrib1fvNV (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib1sNV (GLuint index, GLshort x); +GLAPI void APIENTRY glVertexAttrib1svNV (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib2dNV (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttrib2dvNV (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib2fNV (GLuint index, GLfloat x, GLfloat y); +GLAPI void APIENTRY glVertexAttrib2fvNV (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib2sNV (GLuint index, GLshort x, GLshort y); +GLAPI void APIENTRY glVertexAttrib2svNV (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib3dNV (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttrib3dvNV (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib3fNV (GLuint index, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glVertexAttrib3fvNV (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib3sNV (GLuint index, GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glVertexAttrib3svNV (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4dNV (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttrib4dvNV (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttrib4fNV (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glVertexAttrib4fvNV (GLuint index, const GLfloat *v); +GLAPI void APIENTRY glVertexAttrib4sNV (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glVertexAttrib4svNV (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttrib4ubNV (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +GLAPI void APIENTRY glVertexAttrib4ubvNV (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttribs1dvNV (GLuint index, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribs1fvNV (GLuint index, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glVertexAttribs1svNV (GLuint index, GLsizei count, const GLshort *v); +GLAPI void APIENTRY glVertexAttribs2dvNV (GLuint index, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribs2fvNV (GLuint index, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glVertexAttribs2svNV (GLuint index, GLsizei count, const GLshort *v); +GLAPI void APIENTRY glVertexAttribs3dvNV (GLuint index, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribs3fvNV (GLuint index, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glVertexAttribs3svNV (GLuint index, GLsizei count, const GLshort *v); +GLAPI void APIENTRY glVertexAttribs4dvNV (GLuint index, GLsizei count, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribs4fvNV (GLuint index, GLsizei count, const GLfloat *v); +GLAPI void APIENTRY glVertexAttribs4svNV (GLuint index, GLsizei count, const GLshort *v); +GLAPI void APIENTRY glVertexAttribs4ubvNV (GLuint index, GLsizei count, const GLubyte *v); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLAREPROGRAMSRESIDENTNVPROC) (GLsizei n, const GLuint *programs, GLboolean *residences); +typedef void (APIENTRYP PFNGLBINDPROGRAMNVPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETEPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLEXECUTEPROGRAMNVPROC) (GLenum target, GLuint id, const GLfloat *params); +typedef void (APIENTRYP PFNGLGENPROGRAMSNVPROC) (GLsizei n, GLuint *programs); +typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERDVNVPROC) (GLenum target, GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMIVNVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGNVPROC) (GLuint id, GLenum pname, GLubyte *program); +typedef void (APIENTRYP PFNGLGETTRACKMATRIXIVNVPROC) (GLenum target, GLuint address, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVNVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVNVPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVNVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVNVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLLOADPROGRAMNVPROC) (GLenum target, GLuint id, GLsizei len, const GLubyte *program); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DNVPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DVNVPROC) (GLenum target, GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FNVPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FVNVPROC) (GLenum target, GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4DVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4FVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLREQUESTRESIDENTPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLTRACKMATRIXNVPROC) (GLenum target, GLuint address, GLenum matrix, GLenum transform); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERNVPROC) (GLuint index, GLint fsize, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DNVPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FNVPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SNVPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DNVPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FNVPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SNVPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBNVPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVNVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4UBVNVPROC) (GLuint index, GLsizei count, const GLubyte *v); +#endif + +#ifndef GL_SGIX_texture_coordinate_clamp +#define GL_SGIX_texture_coordinate_clamp 1 +#endif + +#ifndef GL_SGIX_scalebias_hint +#define GL_SGIX_scalebias_hint 1 +#endif + +#ifndef GL_OML_interlace +#define GL_OML_interlace 1 +#endif + +#ifndef GL_OML_subsample +#define GL_OML_subsample 1 +#endif + +#ifndef GL_OML_resample +#define GL_OML_resample 1 +#endif + +#ifndef GL_NV_copy_depth_to_color +#define GL_NV_copy_depth_to_color 1 +#endif + +#ifndef GL_ATI_envmap_bumpmap +#define GL_ATI_envmap_bumpmap 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBumpParameterivATI (GLenum pname, const GLint *param); +GLAPI void APIENTRY glTexBumpParameterfvATI (GLenum pname, const GLfloat *param); +GLAPI void APIENTRY glGetTexBumpParameterivATI (GLenum pname, GLint *param); +GLAPI void APIENTRY glGetTexBumpParameterfvATI (GLenum pname, GLfloat *param); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERIVATIPROC) (GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERFVATIPROC) (GLenum pname, const GLfloat *param); +typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERIVATIPROC) (GLenum pname, GLint *param); +typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERFVATIPROC) (GLenum pname, GLfloat *param); +#endif + +#ifndef GL_ATI_fragment_shader +#define GL_ATI_fragment_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint APIENTRY glGenFragmentShadersATI (GLuint range); +GLAPI void APIENTRY glBindFragmentShaderATI (GLuint id); +GLAPI void APIENTRY glDeleteFragmentShaderATI (GLuint id); +GLAPI void APIENTRY glBeginFragmentShaderATI (void); +GLAPI void APIENTRY glEndFragmentShaderATI (void); +GLAPI void APIENTRY glPassTexCoordATI (GLuint dst, GLuint coord, GLenum swizzle); +GLAPI void APIENTRY glSampleMapATI (GLuint dst, GLuint interp, GLenum swizzle); +GLAPI void APIENTRY glColorFragmentOp1ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +GLAPI void APIENTRY glColorFragmentOp2ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +GLAPI void APIENTRY glColorFragmentOp3ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +GLAPI void APIENTRY glAlphaFragmentOp1ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +GLAPI void APIENTRY glAlphaFragmentOp2ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +GLAPI void APIENTRY glAlphaFragmentOp3ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +GLAPI void APIENTRY glSetFragmentShaderConstantATI (GLuint dst, const GLfloat *value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLuint (APIENTRYP PFNGLGENFRAGMENTSHADERSATIPROC) (GLuint range); +typedef void (APIENTRYP PFNGLBINDFRAGMENTSHADERATIPROC) (GLuint id); +typedef void (APIENTRYP PFNGLDELETEFRAGMENTSHADERATIPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINFRAGMENTSHADERATIPROC) (void); +typedef void (APIENTRYP PFNGLENDFRAGMENTSHADERATIPROC) (void); +typedef void (APIENTRYP PFNGLPASSTEXCOORDATIPROC) (GLuint dst, GLuint coord, GLenum swizzle); +typedef void (APIENTRYP PFNGLSAMPLEMAPATIPROC) (GLuint dst, GLuint interp, GLenum swizzle); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +typedef void (APIENTRYP PFNGLSETFRAGMENTSHADERCONSTANTATIPROC) (GLuint dst, const GLfloat *value); +#endif + +#ifndef GL_ATI_pn_triangles +#define GL_ATI_pn_triangles 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPNTrianglesiATI (GLenum pname, GLint param); +GLAPI void APIENTRY glPNTrianglesfATI (GLenum pname, GLfloat param); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPNTRIANGLESIATIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPNTRIANGLESFATIPROC) (GLenum pname, GLfloat param); +#endif + +#ifndef GL_ATI_vertex_array_object +#define GL_ATI_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint APIENTRY glNewObjectBufferATI (GLsizei size, const GLvoid *pointer, GLenum usage); +GLAPI GLboolean APIENTRY glIsObjectBufferATI (GLuint buffer); +GLAPI void APIENTRY glUpdateObjectBufferATI (GLuint buffer, GLuint offset, GLsizei size, const GLvoid *pointer, GLenum preserve); +GLAPI void APIENTRY glGetObjectBufferfvATI (GLuint buffer, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetObjectBufferivATI (GLuint buffer, GLenum pname, GLint *params); +GLAPI void APIENTRY glFreeObjectBufferATI (GLuint buffer); +GLAPI void APIENTRY glArrayObjectATI (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +GLAPI void APIENTRY glGetArrayObjectfvATI (GLenum array, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetArrayObjectivATI (GLenum array, GLenum pname, GLint *params); +GLAPI void APIENTRY glVariantArrayObjectATI (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +GLAPI void APIENTRY glGetVariantArrayObjectfvATI (GLuint id, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVariantArrayObjectivATI (GLuint id, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLuint (APIENTRYP PFNGLNEWOBJECTBUFFERATIPROC) (GLsizei size, const GLvoid *pointer, GLenum usage); +typedef GLboolean (APIENTRYP PFNGLISOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLUPDATEOBJECTBUFFERATIPROC) (GLuint buffer, GLuint offset, GLsizei size, const GLvoid *pointer, GLenum preserve); +typedef void (APIENTRYP PFNGLGETOBJECTBUFFERFVATIPROC) (GLuint buffer, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETOBJECTBUFFERIVATIPROC) (GLuint buffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLFREEOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLARRAYOBJECTATIPROC) (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETARRAYOBJECTFVATIPROC) (GLenum array, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETARRAYOBJECTIVATIPROC) (GLenum array, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLVARIANTARRAYOBJECTATIPROC) (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTFVATIPROC) (GLuint id, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTIVATIPROC) (GLuint id, GLenum pname, GLint *params); +#endif + +#ifndef GL_EXT_vertex_shader +#define GL_EXT_vertex_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginVertexShaderEXT (void); +GLAPI void APIENTRY glEndVertexShaderEXT (void); +GLAPI void APIENTRY glBindVertexShaderEXT (GLuint id); +GLAPI GLuint APIENTRY glGenVertexShadersEXT (GLuint range); +GLAPI void APIENTRY glDeleteVertexShaderEXT (GLuint id); +GLAPI void APIENTRY glShaderOp1EXT (GLenum op, GLuint res, GLuint arg1); +GLAPI void APIENTRY glShaderOp2EXT (GLenum op, GLuint res, GLuint arg1, GLuint arg2); +GLAPI void APIENTRY glShaderOp3EXT (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3); +GLAPI void APIENTRY glSwizzleEXT (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +GLAPI void APIENTRY glWriteMaskEXT (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +GLAPI void APIENTRY glInsertComponentEXT (GLuint res, GLuint src, GLuint num); +GLAPI void APIENTRY glExtractComponentEXT (GLuint res, GLuint src, GLuint num); +GLAPI GLuint APIENTRY glGenSymbolsEXT (GLenum datatype, GLenum storagetype, GLenum range, GLuint components); +GLAPI void APIENTRY glSetInvariantEXT (GLuint id, GLenum type, const GLvoid *addr); +GLAPI void APIENTRY glSetLocalConstantEXT (GLuint id, GLenum type, const GLvoid *addr); +GLAPI void APIENTRY glVariantbvEXT (GLuint id, const GLbyte *addr); +GLAPI void APIENTRY glVariantsvEXT (GLuint id, const GLshort *addr); +GLAPI void APIENTRY glVariantivEXT (GLuint id, const GLint *addr); +GLAPI void APIENTRY glVariantfvEXT (GLuint id, const GLfloat *addr); +GLAPI void APIENTRY glVariantdvEXT (GLuint id, const GLdouble *addr); +GLAPI void APIENTRY glVariantubvEXT (GLuint id, const GLubyte *addr); +GLAPI void APIENTRY glVariantusvEXT (GLuint id, const GLushort *addr); +GLAPI void APIENTRY glVariantuivEXT (GLuint id, const GLuint *addr); +GLAPI void APIENTRY glVariantPointerEXT (GLuint id, GLenum type, GLuint stride, const GLvoid *addr); +GLAPI void APIENTRY glEnableVariantClientStateEXT (GLuint id); +GLAPI void APIENTRY glDisableVariantClientStateEXT (GLuint id); +GLAPI GLuint APIENTRY glBindLightParameterEXT (GLenum light, GLenum value); +GLAPI GLuint APIENTRY glBindMaterialParameterEXT (GLenum face, GLenum value); +GLAPI GLuint APIENTRY glBindTexGenParameterEXT (GLenum unit, GLenum coord, GLenum value); +GLAPI GLuint APIENTRY glBindTextureUnitParameterEXT (GLenum unit, GLenum value); +GLAPI GLuint APIENTRY glBindParameterEXT (GLenum value); +GLAPI GLboolean APIENTRY glIsVariantEnabledEXT (GLuint id, GLenum cap); +GLAPI void APIENTRY glGetVariantBooleanvEXT (GLuint id, GLenum value, GLboolean *data); +GLAPI void APIENTRY glGetVariantIntegervEXT (GLuint id, GLenum value, GLint *data); +GLAPI void APIENTRY glGetVariantFloatvEXT (GLuint id, GLenum value, GLfloat *data); +GLAPI void APIENTRY glGetVariantPointervEXT (GLuint id, GLenum value, GLvoid* *data); +GLAPI void APIENTRY glGetInvariantBooleanvEXT (GLuint id, GLenum value, GLboolean *data); +GLAPI void APIENTRY glGetInvariantIntegervEXT (GLuint id, GLenum value, GLint *data); +GLAPI void APIENTRY glGetInvariantFloatvEXT (GLuint id, GLenum value, GLfloat *data); +GLAPI void APIENTRY glGetLocalConstantBooleanvEXT (GLuint id, GLenum value, GLboolean *data); +GLAPI void APIENTRY glGetLocalConstantIntegervEXT (GLuint id, GLenum value, GLint *data); +GLAPI void APIENTRY glGetLocalConstantFloatvEXT (GLuint id, GLenum value, GLfloat *data); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINVERTEXSHADEREXTPROC) (void); +typedef void (APIENTRYP PFNGLENDVERTEXSHADEREXTPROC) (void); +typedef void (APIENTRYP PFNGLBINDVERTEXSHADEREXTPROC) (GLuint id); +typedef GLuint (APIENTRYP PFNGLGENVERTEXSHADERSEXTPROC) (GLuint range); +typedef void (APIENTRYP PFNGLDELETEVERTEXSHADEREXTPROC) (GLuint id); +typedef void (APIENTRYP PFNGLSHADEROP1EXTPROC) (GLenum op, GLuint res, GLuint arg1); +typedef void (APIENTRYP PFNGLSHADEROP2EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2); +typedef void (APIENTRYP PFNGLSHADEROP3EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3); +typedef void (APIENTRYP PFNGLSWIZZLEEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +typedef void (APIENTRYP PFNGLWRITEMASKEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +typedef void (APIENTRYP PFNGLINSERTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); +typedef void (APIENTRYP PFNGLEXTRACTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); +typedef GLuint (APIENTRYP PFNGLGENSYMBOLSEXTPROC) (GLenum datatype, GLenum storagetype, GLenum range, GLuint components); +typedef void (APIENTRYP PFNGLSETINVARIANTEXTPROC) (GLuint id, GLenum type, const GLvoid *addr); +typedef void (APIENTRYP PFNGLSETLOCALCONSTANTEXTPROC) (GLuint id, GLenum type, const GLvoid *addr); +typedef void (APIENTRYP PFNGLVARIANTBVEXTPROC) (GLuint id, const GLbyte *addr); +typedef void (APIENTRYP PFNGLVARIANTSVEXTPROC) (GLuint id, const GLshort *addr); +typedef void (APIENTRYP PFNGLVARIANTIVEXTPROC) (GLuint id, const GLint *addr); +typedef void (APIENTRYP PFNGLVARIANTFVEXTPROC) (GLuint id, const GLfloat *addr); +typedef void (APIENTRYP PFNGLVARIANTDVEXTPROC) (GLuint id, const GLdouble *addr); +typedef void (APIENTRYP PFNGLVARIANTUBVEXTPROC) (GLuint id, const GLubyte *addr); +typedef void (APIENTRYP PFNGLVARIANTUSVEXTPROC) (GLuint id, const GLushort *addr); +typedef void (APIENTRYP PFNGLVARIANTUIVEXTPROC) (GLuint id, const GLuint *addr); +typedef void (APIENTRYP PFNGLVARIANTPOINTEREXTPROC) (GLuint id, GLenum type, GLuint stride, const GLvoid *addr); +typedef void (APIENTRYP PFNGLENABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); +typedef void (APIENTRYP PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); +typedef GLuint (APIENTRYP PFNGLBINDLIGHTPARAMETEREXTPROC) (GLenum light, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDMATERIALPARAMETEREXTPROC) (GLenum face, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDTEXGENPARAMETEREXTPROC) (GLenum unit, GLenum coord, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDTEXTUREUNITPARAMETEREXTPROC) (GLenum unit, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDPARAMETEREXTPROC) (GLenum value); +typedef GLboolean (APIENTRYP PFNGLISVARIANTENABLEDEXTPROC) (GLuint id, GLenum cap); +typedef void (APIENTRYP PFNGLGETVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +typedef void (APIENTRYP PFNGLGETVARIANTPOINTERVEXTPROC) (GLuint id, GLenum value, GLvoid* *data); +typedef void (APIENTRYP PFNGLGETINVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETINVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +#endif + +#ifndef GL_ATI_vertex_streams +#define GL_ATI_vertex_streams 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexStream1sATI (GLenum stream, GLshort x); +GLAPI void APIENTRY glVertexStream1svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glVertexStream1iATI (GLenum stream, GLint x); +GLAPI void APIENTRY glVertexStream1ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glVertexStream1fATI (GLenum stream, GLfloat x); +GLAPI void APIENTRY glVertexStream1fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glVertexStream1dATI (GLenum stream, GLdouble x); +GLAPI void APIENTRY glVertexStream1dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glVertexStream2sATI (GLenum stream, GLshort x, GLshort y); +GLAPI void APIENTRY glVertexStream2svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glVertexStream2iATI (GLenum stream, GLint x, GLint y); +GLAPI void APIENTRY glVertexStream2ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glVertexStream2fATI (GLenum stream, GLfloat x, GLfloat y); +GLAPI void APIENTRY glVertexStream2fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glVertexStream2dATI (GLenum stream, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexStream2dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glVertexStream3sATI (GLenum stream, GLshort x, GLshort y, GLshort z); +GLAPI void APIENTRY glVertexStream3svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glVertexStream3iATI (GLenum stream, GLint x, GLint y, GLint z); +GLAPI void APIENTRY glVertexStream3ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glVertexStream3fATI (GLenum stream, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glVertexStream3fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glVertexStream3dATI (GLenum stream, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexStream3dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glVertexStream4sATI (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w); +GLAPI void APIENTRY glVertexStream4svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glVertexStream4iATI (GLenum stream, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glVertexStream4ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glVertexStream4fATI (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glVertexStream4fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glVertexStream4dATI (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexStream4dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glNormalStream3bATI (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz); +GLAPI void APIENTRY glNormalStream3bvATI (GLenum stream, const GLbyte *coords); +GLAPI void APIENTRY glNormalStream3sATI (GLenum stream, GLshort nx, GLshort ny, GLshort nz); +GLAPI void APIENTRY glNormalStream3svATI (GLenum stream, const GLshort *coords); +GLAPI void APIENTRY glNormalStream3iATI (GLenum stream, GLint nx, GLint ny, GLint nz); +GLAPI void APIENTRY glNormalStream3ivATI (GLenum stream, const GLint *coords); +GLAPI void APIENTRY glNormalStream3fATI (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz); +GLAPI void APIENTRY glNormalStream3fvATI (GLenum stream, const GLfloat *coords); +GLAPI void APIENTRY glNormalStream3dATI (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz); +GLAPI void APIENTRY glNormalStream3dvATI (GLenum stream, const GLdouble *coords); +GLAPI void APIENTRY glClientActiveVertexStreamATI (GLenum stream); +GLAPI void APIENTRY glVertexBlendEnviATI (GLenum pname, GLint param); +GLAPI void APIENTRY glVertexBlendEnvfATI (GLenum pname, GLfloat param); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXSTREAM1SATIPROC) (GLenum stream, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1IATIPROC) (GLenum stream, GLint x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1FATIPROC) (GLenum stream, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1DATIPROC) (GLenum stream, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2SATIPROC) (GLenum stream, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2IATIPROC) (GLenum stream, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2FATIPROC) (GLenum stream, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2DATIPROC) (GLenum stream, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3IATIPROC) (GLenum stream, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4IATIPROC) (GLenum stream, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3BATIPROC) (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3BVATIPROC) (GLenum stream, const GLbyte *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3SATIPROC) (GLenum stream, GLshort nx, GLshort ny, GLshort nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3IATIPROC) (GLenum stream, GLint nx, GLint ny, GLint nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3FATIPROC) (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3DATIPROC) (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLCLIENTACTIVEVERTEXSTREAMATIPROC) (GLenum stream); +typedef void (APIENTRYP PFNGLVERTEXBLENDENVIATIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLVERTEXBLENDENVFATIPROC) (GLenum pname, GLfloat param); +#endif + +#ifndef GL_ATI_element_array +#define GL_ATI_element_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glElementPointerATI (GLenum type, const GLvoid *pointer); +GLAPI void APIENTRY glDrawElementArrayATI (GLenum mode, GLsizei count); +GLAPI void APIENTRY glDrawRangeElementArrayATI (GLenum mode, GLuint start, GLuint end, GLsizei count); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLELEMENTPOINTERATIPROC) (GLenum type, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYATIPROC) (GLenum mode, GLsizei count); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYATIPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count); +#endif + +#ifndef GL_SUN_mesh_array +#define GL_SUN_mesh_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawMeshArraysSUN (GLenum mode, GLint first, GLsizei count, GLsizei width); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWMESHARRAYSSUNPROC) (GLenum mode, GLint first, GLsizei count, GLsizei width); +#endif + +#ifndef GL_SUN_slice_accum +#define GL_SUN_slice_accum 1 +#endif + +#ifndef GL_NV_multisample_filter_hint +#define GL_NV_multisample_filter_hint 1 +#endif + +#ifndef GL_NV_depth_clamp +#define GL_NV_depth_clamp 1 +#endif + +#ifndef GL_NV_occlusion_query +#define GL_NV_occlusion_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenOcclusionQueriesNV (GLsizei n, GLuint *ids); +GLAPI void APIENTRY glDeleteOcclusionQueriesNV (GLsizei n, const GLuint *ids); +GLAPI GLboolean APIENTRY glIsOcclusionQueryNV (GLuint id); +GLAPI void APIENTRY glBeginOcclusionQueryNV (GLuint id); +GLAPI void APIENTRY glEndOcclusionQueryNV (void); +GLAPI void APIENTRY glGetOcclusionQueryivNV (GLuint id, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetOcclusionQueryuivNV (GLuint id, GLenum pname, GLuint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENOCCLUSIONQUERIESNVPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEOCCLUSIONQUERIESNVPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISOCCLUSIONQUERYNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINOCCLUSIONQUERYNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLENDOCCLUSIONQUERYNVPROC) (void); +typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYIVNVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYUIVNVPROC) (GLuint id, GLenum pname, GLuint *params); +#endif + +#ifndef GL_NV_point_sprite +#define GL_NV_point_sprite 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameteriNV (GLenum pname, GLint param); +GLAPI void APIENTRY glPointParameterivNV (GLenum pname, const GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERINVPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIVNVPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_NV_texture_shader3 +#define GL_NV_texture_shader3 1 +#endif + +#ifndef GL_NV_vertex_program1_1 +#define GL_NV_vertex_program1_1 1 +#endif + +#ifndef GL_EXT_shadow_funcs +#define GL_EXT_shadow_funcs 1 +#endif + +#ifndef GL_EXT_stencil_two_side +#define GL_EXT_stencil_two_side 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveStencilFaceEXT (GLenum face); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVESTENCILFACEEXTPROC) (GLenum face); +#endif + +#ifndef GL_ATI_text_fragment_shader +#define GL_ATI_text_fragment_shader 1 +#endif + +#ifndef GL_APPLE_client_storage +#define GL_APPLE_client_storage 1 +#endif + +#ifndef GL_APPLE_element_array +#define GL_APPLE_element_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glElementPointerAPPLE (GLenum type, const GLvoid *pointer); +GLAPI void APIENTRY glDrawElementArrayAPPLE (GLenum mode, GLint first, GLsizei count); +GLAPI void APIENTRY glDrawRangeElementArrayAPPLE (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count); +GLAPI void APIENTRY glMultiDrawElementArrayAPPLE (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +GLAPI void APIENTRY glMultiDrawRangeElementArrayAPPLE (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLELEMENTPOINTERAPPLEPROC) (GLenum type, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount); +#endif + +#ifndef GL_APPLE_fence +#define GL_APPLE_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenFencesAPPLE (GLsizei n, GLuint *fences); +GLAPI void APIENTRY glDeleteFencesAPPLE (GLsizei n, const GLuint *fences); +GLAPI void APIENTRY glSetFenceAPPLE (GLuint fence); +GLAPI GLboolean APIENTRY glIsFenceAPPLE (GLuint fence); +GLAPI GLboolean APIENTRY glTestFenceAPPLE (GLuint fence); +GLAPI void APIENTRY glFinishFenceAPPLE (GLuint fence); +GLAPI GLboolean APIENTRY glTestObjectAPPLE (GLenum object, GLuint name); +GLAPI void APIENTRY glFinishObjectAPPLE (GLenum object, GLint name); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENFENCESAPPLEPROC) (GLsizei n, GLuint *fences); +typedef void (APIENTRYP PFNGLDELETEFENCESAPPLEPROC) (GLsizei n, const GLuint *fences); +typedef void (APIENTRYP PFNGLSETFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLISFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTFENCEAPPLEPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLFINISHFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTOBJECTAPPLEPROC) (GLenum object, GLuint name); +typedef void (APIENTRYP PFNGLFINISHOBJECTAPPLEPROC) (GLenum object, GLint name); +#endif + +#ifndef GL_APPLE_vertex_array_object +#define GL_APPLE_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindVertexArrayAPPLE (GLuint array); +GLAPI void APIENTRY glDeleteVertexArraysAPPLE (GLsizei n, const GLuint *arrays); +GLAPI void APIENTRY glGenVertexArraysAPPLE (GLsizei n, GLuint *arrays); +GLAPI GLboolean APIENTRY glIsVertexArrayAPPLE (GLuint array); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDVERTEXARRAYAPPLEPROC) (GLuint array); +typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays); +typedef void (APIENTRYP PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array); +#endif + +#ifndef GL_APPLE_vertex_array_range +#define GL_APPLE_vertex_array_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexArrayRangeAPPLE (GLsizei length, GLvoid *pointer); +GLAPI void APIENTRY glFlushVertexArrayRangeAPPLE (GLsizei length, GLvoid *pointer); +GLAPI void APIENTRY glVertexArrayParameteriAPPLE (GLenum pname, GLint param); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXARRAYPARAMETERIAPPLEPROC) (GLenum pname, GLint param); +#endif + +#ifndef GL_APPLE_ycbcr_422 +#define GL_APPLE_ycbcr_422 1 +#endif + +#ifndef GL_S3_s3tc +#define GL_S3_s3tc 1 +#endif + +#ifndef GL_ATI_draw_buffers +#define GL_ATI_draw_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawBuffersATI (GLsizei n, const GLenum *bufs); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWBUFFERSATIPROC) (GLsizei n, const GLenum *bufs); +#endif + +#ifndef GL_ATI_pixel_format_float +#define GL_ATI_pixel_format_float 1 +/* This is really a WGL extension, but defines some associated GL enums. + * ATI does not export "GL_ATI_pixel_format_float" in the GL_EXTENSIONS string. + */ +#endif + +#ifndef GL_ATI_texture_env_combine3 +#define GL_ATI_texture_env_combine3 1 +#endif + +#ifndef GL_ATI_texture_float +#define GL_ATI_texture_float 1 +#endif + +#ifndef GL_NV_float_buffer +#define GL_NV_float_buffer 1 +#endif + +#ifndef GL_NV_fragment_program +#define GL_NV_fragment_program 1 +/* Some NV_fragment_program entry points are shared with ARB_vertex_program. */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramNamedParameter4fNV (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glProgramNamedParameter4dNV (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramNamedParameter4fvNV (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v); +GLAPI void APIENTRY glProgramNamedParameter4dvNV (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v); +GLAPI void APIENTRY glGetProgramNamedParameterfvNV (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params); +GLAPI void APIENTRY glGetProgramNamedParameterdvNV (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v); +typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERFVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERDVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params); +#endif + +#ifndef GL_NV_half_float +#define GL_NV_half_float 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertex2hNV (GLhalfNV x, GLhalfNV y); +GLAPI void APIENTRY glVertex2hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glVertex3hNV (GLhalfNV x, GLhalfNV y, GLhalfNV z); +GLAPI void APIENTRY glVertex3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glVertex4hNV (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +GLAPI void APIENTRY glVertex4hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glNormal3hNV (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz); +GLAPI void APIENTRY glNormal3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glColor3hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +GLAPI void APIENTRY glColor3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glColor4hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha); +GLAPI void APIENTRY glColor4hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glTexCoord1hNV (GLhalfNV s); +GLAPI void APIENTRY glTexCoord1hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glTexCoord2hNV (GLhalfNV s, GLhalfNV t); +GLAPI void APIENTRY glTexCoord2hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glTexCoord3hNV (GLhalfNV s, GLhalfNV t, GLhalfNV r); +GLAPI void APIENTRY glTexCoord3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glTexCoord4hNV (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +GLAPI void APIENTRY glTexCoord4hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glMultiTexCoord1hNV (GLenum target, GLhalfNV s); +GLAPI void APIENTRY glMultiTexCoord1hvNV (GLenum target, const GLhalfNV *v); +GLAPI void APIENTRY glMultiTexCoord2hNV (GLenum target, GLhalfNV s, GLhalfNV t); +GLAPI void APIENTRY glMultiTexCoord2hvNV (GLenum target, const GLhalfNV *v); +GLAPI void APIENTRY glMultiTexCoord3hNV (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r); +GLAPI void APIENTRY glMultiTexCoord3hvNV (GLenum target, const GLhalfNV *v); +GLAPI void APIENTRY glMultiTexCoord4hNV (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +GLAPI void APIENTRY glMultiTexCoord4hvNV (GLenum target, const GLhalfNV *v); +GLAPI void APIENTRY glFogCoordhNV (GLhalfNV fog); +GLAPI void APIENTRY glFogCoordhvNV (const GLhalfNV *fog); +GLAPI void APIENTRY glSecondaryColor3hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +GLAPI void APIENTRY glSecondaryColor3hvNV (const GLhalfNV *v); +GLAPI void APIENTRY glVertexWeighthNV (GLhalfNV weight); +GLAPI void APIENTRY glVertexWeighthvNV (const GLhalfNV *weight); +GLAPI void APIENTRY glVertexAttrib1hNV (GLuint index, GLhalfNV x); +GLAPI void APIENTRY glVertexAttrib1hvNV (GLuint index, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttrib2hNV (GLuint index, GLhalfNV x, GLhalfNV y); +GLAPI void APIENTRY glVertexAttrib2hvNV (GLuint index, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttrib3hNV (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z); +GLAPI void APIENTRY glVertexAttrib3hvNV (GLuint index, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttrib4hNV (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +GLAPI void APIENTRY glVertexAttrib4hvNV (GLuint index, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttribs1hvNV (GLuint index, GLsizei n, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttribs2hvNV (GLuint index, GLsizei n, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttribs3hvNV (GLuint index, GLsizei n, const GLhalfNV *v); +GLAPI void APIENTRY glVertexAttribs4hvNV (GLuint index, GLsizei n, const GLhalfNV *v); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEX2HNVPROC) (GLhalfNV x, GLhalfNV y); +typedef void (APIENTRYP PFNGLVERTEX2HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEX3HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z); +typedef void (APIENTRYP PFNGLVERTEX3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEX4HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +typedef void (APIENTRYP PFNGLVERTEX4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLNORMAL3HNVPROC) (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz); +typedef void (APIENTRYP PFNGLNORMAL3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +typedef void (APIENTRYP PFNGLCOLOR3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLCOLOR4HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha); +typedef void (APIENTRYP PFNGLCOLOR4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD1HNVPROC) (GLhalfNV s); +typedef void (APIENTRYP PFNGLTEXCOORD1HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD2HNVPROC) (GLhalfNV s, GLhalfNV t); +typedef void (APIENTRYP PFNGLTEXCOORD2HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD3HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r); +typedef void (APIENTRYP PFNGLTEXCOORD3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD4HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +typedef void (APIENTRYP PFNGLTEXCOORD4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1HNVPROC) (GLenum target, GLhalfNV s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLFOGCOORDHNVPROC) (GLhalfNV fog); +typedef void (APIENTRYP PFNGLFOGCOORDHVNVPROC) (const GLhalfNV *fog); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTHNVPROC) (GLhalfNV weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTHVNVPROC) (const GLhalfNV *weight); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1HNVPROC) (GLuint index, GLhalfNV x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +#endif + +#ifndef GL_NV_pixel_data_range +#define GL_NV_pixel_data_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelDataRangeNV (GLenum target, GLsizei length, GLvoid *pointer); +GLAPI void APIENTRY glFlushPixelDataRangeNV (GLenum target); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELDATARANGENVPROC) (GLenum target, GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLFLUSHPIXELDATARANGENVPROC) (GLenum target); +#endif + +#ifndef GL_NV_primitive_restart +#define GL_NV_primitive_restart 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPrimitiveRestartNV (void); +GLAPI void APIENTRY glPrimitiveRestartIndexNV (GLuint index); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTNVPROC) (void); +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXNVPROC) (GLuint index); +#endif + +#ifndef GL_NV_texture_expand_normal +#define GL_NV_texture_expand_normal 1 +#endif + +#ifndef GL_NV_vertex_program2 +#define GL_NV_vertex_program2 1 +#endif + +#ifndef GL_ATI_map_object_buffer +#define GL_ATI_map_object_buffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLvoid* APIENTRY glMapObjectBufferATI (GLuint buffer); +GLAPI void APIENTRY glUnmapObjectBufferATI (GLuint buffer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLvoid* (APIENTRYP PFNGLMAPOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLUNMAPOBJECTBUFFERATIPROC) (GLuint buffer); +#endif + +#ifndef GL_ATI_separate_stencil +#define GL_ATI_separate_stencil 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStencilOpSeparateATI (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +GLAPI void APIENTRY glStencilFuncSeparateATI (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEATIPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEATIPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); +#endif + +#ifndef GL_ATI_vertex_attrib_array_object +#define GL_ATI_vertex_attrib_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribArrayObjectATI (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset); +GLAPI void APIENTRY glGetVertexAttribArrayObjectfvATI (GLuint index, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVertexAttribArrayObjectivATI (GLuint index, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBARRAYOBJECTATIPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTFVATIPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTIVATIPROC) (GLuint index, GLenum pname, GLint *params); +#endif + +#ifndef GL_OES_read_format +#define GL_OES_read_format 1 +#endif + +#ifndef GL_EXT_depth_bounds_test +#define GL_EXT_depth_bounds_test 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDepthBoundsEXT (GLclampd zmin, GLclampd zmax); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEPTHBOUNDSEXTPROC) (GLclampd zmin, GLclampd zmax); +#endif + +#ifndef GL_EXT_texture_mirror_clamp +#define GL_EXT_texture_mirror_clamp 1 +#endif + +#ifndef GL_EXT_blend_equation_separate +#define GL_EXT_blend_equation_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationSeparateEXT (GLenum modeRGB, GLenum modeAlpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEEXTPROC) (GLenum modeRGB, GLenum modeAlpha); +#endif + +#ifndef GL_MESA_pack_invert +#define GL_MESA_pack_invert 1 +#endif + +#ifndef GL_MESA_ycbcr_texture +#define GL_MESA_ycbcr_texture 1 +#endif + +#ifndef GL_EXT_pixel_buffer_object +#define GL_EXT_pixel_buffer_object 1 +#endif + +#ifndef GL_NV_fragment_program_option +#define GL_NV_fragment_program_option 1 +#endif + +#ifndef GL_NV_fragment_program2 +#define GL_NV_fragment_program2 1 +#endif + +#ifndef GL_NV_vertex_program2_option +#define GL_NV_vertex_program2_option 1 +#endif + +#ifndef GL_NV_vertex_program3 +#define GL_NV_vertex_program3 1 +#endif + +#ifndef GL_EXT_framebuffer_object +#define GL_EXT_framebuffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glIsRenderbufferEXT (GLuint renderbuffer); +GLAPI void APIENTRY glBindRenderbufferEXT (GLenum target, GLuint renderbuffer); +GLAPI void APIENTRY glDeleteRenderbuffersEXT (GLsizei n, const GLuint *renderbuffers); +GLAPI void APIENTRY glGenRenderbuffersEXT (GLsizei n, GLuint *renderbuffers); +GLAPI void APIENTRY glRenderbufferStorageEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetRenderbufferParameterivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI GLboolean APIENTRY glIsFramebufferEXT (GLuint framebuffer); +GLAPI void APIENTRY glBindFramebufferEXT (GLenum target, GLuint framebuffer); +GLAPI void APIENTRY glDeleteFramebuffersEXT (GLsizei n, const GLuint *framebuffers); +GLAPI void APIENTRY glGenFramebuffersEXT (GLsizei n, GLuint *framebuffers); +GLAPI GLenum APIENTRY glCheckFramebufferStatusEXT (GLenum target); +GLAPI void APIENTRY glFramebufferTexture1DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture2DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTexture3DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +GLAPI void APIENTRY glFramebufferRenderbufferEXT (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GLAPI void APIENTRY glGetFramebufferAttachmentParameterivEXT (GLenum target, GLenum attachment, GLenum pname, GLint *params); +GLAPI void APIENTRY glGenerateMipmapEXT (GLenum target); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFEREXTPROC) (GLuint renderbuffer); +typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC) (GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFEREXTPROC) (GLuint framebuffer); +typedef void (APIENTRYP PFNGLBINDFRAMEBUFFEREXTPROC) (GLenum target, GLuint framebuffer); +typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSEXTPROC) (GLsizei n, const GLuint *framebuffers); +typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSEXTPROC) (GLsizei n, GLuint *framebuffers); +typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) (GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATEMIPMAPEXTPROC) (GLenum target); +#endif + +#ifndef GL_GREMEDY_string_marker +#define GL_GREMEDY_string_marker 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStringMarkerGREMEDY (GLsizei len, const GLvoid *string); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, const GLvoid *string); +#endif + +#ifndef GL_EXT_packed_depth_stencil +#define GL_EXT_packed_depth_stencil 1 +#endif + +#ifndef GL_EXT_stencil_clear_tag +#define GL_EXT_stencil_clear_tag 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStencilClearTagEXT (GLsizei stencilTagBits, GLuint stencilClearTag); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSTENCILCLEARTAGEXTPROC) (GLsizei stencilTagBits, GLuint stencilClearTag); +#endif + +#ifndef GL_EXT_texture_sRGB +#define GL_EXT_texture_sRGB 1 +#endif + +#ifndef GL_EXT_framebuffer_blit +#define GL_EXT_framebuffer_blit 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlitFramebufferEXT (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLITFRAMEBUFFEREXTPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#endif + +#ifndef GL_EXT_framebuffer_multisample +#define GL_EXT_framebuffer_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glRenderbufferStorageMultisampleEXT (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +#endif + +#ifndef GL_MESAX_texture_stack +#define GL_MESAX_texture_stack 1 +#endif + +#ifndef GL_EXT_timer_query +#define GL_EXT_timer_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetQueryObjecti64vEXT (GLuint id, GLenum pname, GLint64EXT *params); +GLAPI void APIENTRY glGetQueryObjectui64vEXT (GLuint id, GLenum pname, GLuint64EXT *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VEXTPROC) (GLuint id, GLenum pname, GLint64EXT *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VEXTPROC) (GLuint id, GLenum pname, GLuint64EXT *params); +#endif + +#ifndef GL_EXT_gpu_program_parameters +#define GL_EXT_gpu_program_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramEnvParameters4fvEXT (GLenum target, GLuint index, GLsizei count, const GLfloat *params); +GLAPI void APIENTRY glProgramLocalParameters4fvEXT (GLenum target, GLuint index, GLsizei count, const GLfloat *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERS4FVEXTPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *params); +#endif + +#ifndef GL_APPLE_flush_buffer_range +#define GL_APPLE_flush_buffer_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBufferParameteriAPPLE (GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glFlushMappedBufferRangeAPPLE (GLenum target, GLintptr offset, GLsizeiptr size); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBUFFERPARAMETERIAPPLEPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEAPPLEPROC) (GLenum target, GLintptr offset, GLsizeiptr size); +#endif + +#ifndef GL_NV_gpu_program4 +#define GL_NV_gpu_program4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramLocalParameterI4iNV (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glProgramLocalParameterI4ivNV (GLenum target, GLuint index, const GLint *params); +GLAPI void APIENTRY glProgramLocalParametersI4ivNV (GLenum target, GLuint index, GLsizei count, const GLint *params); +GLAPI void APIENTRY glProgramLocalParameterI4uiNV (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glProgramLocalParameterI4uivNV (GLenum target, GLuint index, const GLuint *params); +GLAPI void APIENTRY glProgramLocalParametersI4uivNV (GLenum target, GLuint index, GLsizei count, const GLuint *params); +GLAPI void APIENTRY glProgramEnvParameterI4iNV (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glProgramEnvParameterI4ivNV (GLenum target, GLuint index, const GLint *params); +GLAPI void APIENTRY glProgramEnvParametersI4ivNV (GLenum target, GLuint index, GLsizei count, const GLint *params); +GLAPI void APIENTRY glProgramEnvParameterI4uiNV (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glProgramEnvParameterI4uivNV (GLenum target, GLuint index, const GLuint *params); +GLAPI void APIENTRY glProgramEnvParametersI4uivNV (GLenum target, GLuint index, GLsizei count, const GLuint *params); +GLAPI void APIENTRY glGetProgramLocalParameterIivNV (GLenum target, GLuint index, GLint *params); +GLAPI void APIENTRY glGetProgramLocalParameterIuivNV (GLenum target, GLuint index, GLuint *params); +GLAPI void APIENTRY glGetProgramEnvParameterIivNV (GLenum target, GLuint index, GLint *params); +GLAPI void APIENTRY glGetProgramEnvParameterIuivNV (GLenum target, GLuint index, GLuint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4INVPROC) (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4IVNVPROC) (GLenum target, GLuint index, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERSI4IVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4UINVPROC) (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4UIVNVPROC) (GLenum target, GLuint index, const GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERSI4UIVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4INVPROC) (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4IVNVPROC) (GLenum target, GLuint index, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERSI4IVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4UINVPROC) (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4UIVNVPROC) (GLenum target, GLuint index, const GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERSI4UIVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERIIVNVPROC) (GLenum target, GLuint index, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERIUIVNVPROC) (GLenum target, GLuint index, GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERIIVNVPROC) (GLenum target, GLuint index, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERIUIVNVPROC) (GLenum target, GLuint index, GLuint *params); +#endif + +#ifndef GL_NV_geometry_program4 +#define GL_NV_geometry_program4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramVertexLimitNV (GLenum target, GLint limit); +GLAPI void APIENTRY glFramebufferTextureEXT (GLenum target, GLenum attachment, GLuint texture, GLint level); +GLAPI void APIENTRY glFramebufferTextureLayerEXT (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +GLAPI void APIENTRY glFramebufferTextureFaceEXT (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMVERTEXLIMITNVPROC) (GLenum target, GLint limit); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYEREXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); +#endif + +#ifndef GL_EXT_geometry_shader4 +#define GL_EXT_geometry_shader4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramParameteriEXT (GLuint program, GLenum pname, GLint value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIEXTPROC) (GLuint program, GLenum pname, GLint value); +#endif + +#ifndef GL_NV_vertex_program4 +#define GL_NV_vertex_program4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribI1iEXT (GLuint index, GLint x); +GLAPI void APIENTRY glVertexAttribI2iEXT (GLuint index, GLint x, GLint y); +GLAPI void APIENTRY glVertexAttribI3iEXT (GLuint index, GLint x, GLint y, GLint z); +GLAPI void APIENTRY glVertexAttribI4iEXT (GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glVertexAttribI1uiEXT (GLuint index, GLuint x); +GLAPI void APIENTRY glVertexAttribI2uiEXT (GLuint index, GLuint x, GLuint y); +GLAPI void APIENTRY glVertexAttribI3uiEXT (GLuint index, GLuint x, GLuint y, GLuint z); +GLAPI void APIENTRY glVertexAttribI4uiEXT (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glVertexAttribI1ivEXT (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI2ivEXT (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI3ivEXT (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI4ivEXT (GLuint index, const GLint *v); +GLAPI void APIENTRY glVertexAttribI1uivEXT (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI2uivEXT (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI3uivEXT (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4uivEXT (GLuint index, const GLuint *v); +GLAPI void APIENTRY glVertexAttribI4bvEXT (GLuint index, const GLbyte *v); +GLAPI void APIENTRY glVertexAttribI4svEXT (GLuint index, const GLshort *v); +GLAPI void APIENTRY glVertexAttribI4ubvEXT (GLuint index, const GLubyte *v); +GLAPI void APIENTRY glVertexAttribI4usvEXT (GLuint index, const GLushort *v); +GLAPI void APIENTRY glVertexAttribIPointerEXT (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glGetVertexAttribIivEXT (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribIuivEXT (GLuint index, GLenum pname, GLuint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IEXTPROC) (GLuint index, GLint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IEXTPROC) (GLuint index, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IEXTPROC) (GLuint index, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IEXTPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIEXTPROC) (GLuint index, GLuint x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIEXTPROC) (GLuint index, GLuint x, GLuint y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIEXTPROC) (GLuint index, GLuint x, GLuint y, GLuint z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIEXTPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVEXTPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVEXTPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVEXTPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVEXTPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVEXTPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVEXTPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTEREXTPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVEXTPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVEXTPROC) (GLuint index, GLenum pname, GLuint *params); +#endif + +#ifndef GL_EXT_gpu_shader4 +#define GL_EXT_gpu_shader4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetUniformuivEXT (GLuint program, GLint location, GLuint *params); +GLAPI void APIENTRY glBindFragDataLocationEXT (GLuint program, GLuint color, const GLchar *name); +GLAPI GLint APIENTRY glGetFragDataLocationEXT (GLuint program, const GLchar *name); +GLAPI void APIENTRY glUniform1uiEXT (GLint location, GLuint v0); +GLAPI void APIENTRY glUniform2uiEXT (GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glUniform3uiEXT (GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glUniform4uiEXT (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glUniform1uivEXT (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform2uivEXT (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform3uivEXT (GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glUniform4uivEXT (GLint location, GLsizei count, const GLuint *value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETUNIFORMUIVEXTPROC) (GLuint program, GLint location, GLuint *params); +typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONEXTPROC) (GLuint program, GLuint color, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONEXTPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLUNIFORM1UIEXTPROC) (GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLUNIFORM2UIEXTPROC) (GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLUNIFORM3UIEXTPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLUNIFORM4UIEXTPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLUNIFORM1UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM2UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM3UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLUNIFORM4UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value); +#endif + +#ifndef GL_EXT_draw_instanced +#define GL_EXT_draw_instanced 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawArraysInstancedEXT (GLenum mode, GLint start, GLsizei count, GLsizei primcount); +GLAPI void APIENTRY glDrawElementsInstancedEXT (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDEXTPROC) (GLenum mode, GLint start, GLsizei count, GLsizei primcount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDEXTPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); +#endif + +#ifndef GL_EXT_packed_float +#define GL_EXT_packed_float 1 +#endif + +#ifndef GL_EXT_texture_array +#define GL_EXT_texture_array 1 +#endif + +#ifndef GL_EXT_texture_buffer_object +#define GL_EXT_texture_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBufferEXT (GLenum target, GLenum internalformat, GLuint buffer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUFFEREXTPROC) (GLenum target, GLenum internalformat, GLuint buffer); +#endif + +#ifndef GL_EXT_texture_compression_latc +#define GL_EXT_texture_compression_latc 1 +#endif + +#ifndef GL_EXT_texture_compression_rgtc +#define GL_EXT_texture_compression_rgtc 1 +#endif + +#ifndef GL_EXT_texture_shared_exponent +#define GL_EXT_texture_shared_exponent 1 +#endif + +#ifndef GL_NV_depth_buffer_float +#define GL_NV_depth_buffer_float 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDepthRangedNV (GLdouble zNear, GLdouble zFar); +GLAPI void APIENTRY glClearDepthdNV (GLdouble depth); +GLAPI void APIENTRY glDepthBoundsdNV (GLdouble zmin, GLdouble zmax); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEPTHRANGEDNVPROC) (GLdouble zNear, GLdouble zFar); +typedef void (APIENTRYP PFNGLCLEARDEPTHDNVPROC) (GLdouble depth); +typedef void (APIENTRYP PFNGLDEPTHBOUNDSDNVPROC) (GLdouble zmin, GLdouble zmax); +#endif + +#ifndef GL_NV_fragment_program4 +#define GL_NV_fragment_program4 1 +#endif + +#ifndef GL_NV_framebuffer_multisample_coverage +#define GL_NV_framebuffer_multisample_coverage 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glRenderbufferStorageMultisampleCoverageNV (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); +#endif + +#ifndef GL_EXT_framebuffer_sRGB +#define GL_EXT_framebuffer_sRGB 1 +#endif + +#ifndef GL_NV_geometry_shader4 +#define GL_NV_geometry_shader4 1 +#endif + +#ifndef GL_NV_parameter_buffer_object +#define GL_NV_parameter_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramBufferParametersfvNV (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLfloat *params); +GLAPI void APIENTRY glProgramBufferParametersIivNV (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLint *params); +GLAPI void APIENTRY glProgramBufferParametersIuivNV (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLuint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSFVNVPROC) (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLfloat *params); +typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSIIVNVPROC) (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSIUIVNVPROC) (GLenum target, GLuint buffer, GLuint index, GLsizei count, const GLuint *params); +#endif + +#ifndef GL_EXT_draw_buffers2 +#define GL_EXT_draw_buffers2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorMaskIndexedEXT (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +GLAPI void APIENTRY glGetBooleanIndexedvEXT (GLenum target, GLuint index, GLboolean *data); +GLAPI void APIENTRY glGetIntegerIndexedvEXT (GLenum target, GLuint index, GLint *data); +GLAPI void APIENTRY glEnableIndexedEXT (GLenum target, GLuint index); +GLAPI void APIENTRY glDisableIndexedEXT (GLenum target, GLuint index); +GLAPI GLboolean APIENTRY glIsEnabledIndexedEXT (GLenum target, GLuint index); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORMASKINDEXEDEXTPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a); +typedef void (APIENTRYP PFNGLGETBOOLEANINDEXEDVEXTPROC) (GLenum target, GLuint index, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINTEGERINDEXEDVEXTPROC) (GLenum target, GLuint index, GLint *data); +typedef void (APIENTRYP PFNGLENABLEINDEXEDEXTPROC) (GLenum target, GLuint index); +typedef void (APIENTRYP PFNGLDISABLEINDEXEDEXTPROC) (GLenum target, GLuint index); +typedef GLboolean (APIENTRYP PFNGLISENABLEDINDEXEDEXTPROC) (GLenum target, GLuint index); +#endif + +#ifndef GL_NV_transform_feedback +#define GL_NV_transform_feedback 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginTransformFeedbackNV (GLenum primitiveMode); +GLAPI void APIENTRY glEndTransformFeedbackNV (void); +GLAPI void APIENTRY glTransformFeedbackAttribsNV (GLuint count, const GLint *attribs, GLenum bufferMode); +GLAPI void APIENTRY glBindBufferRangeNV (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glBindBufferOffsetNV (GLenum target, GLuint index, GLuint buffer, GLintptr offset); +GLAPI void APIENTRY glBindBufferBaseNV (GLenum target, GLuint index, GLuint buffer); +GLAPI void APIENTRY glTransformFeedbackVaryingsNV (GLuint program, GLsizei count, const GLint *locations, GLenum bufferMode); +GLAPI void APIENTRY glActiveVaryingNV (GLuint program, const GLchar *name); +GLAPI GLint APIENTRY glGetVaryingLocationNV (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGetActiveVaryingNV (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +GLAPI void APIENTRY glGetTransformFeedbackVaryingNV (GLuint program, GLuint index, GLint *location); +GLAPI void APIENTRY glTransformFeedbackStreamAttribsNV (GLsizei count, const GLint *attribs, GLsizei nbuffers, const GLint *bufstreams, GLenum bufferMode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKNVPROC) (GLenum primitiveMode); +typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKNVPROC) (void); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKATTRIBSNVPROC) (GLuint count, const GLint *attribs, GLenum bufferMode); +typedef void (APIENTRYP PFNGLBINDBUFFERRANGENVPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLBINDBUFFEROFFSETNVPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset); +typedef void (APIENTRYP PFNGLBINDBUFFERBASENVPROC) (GLenum target, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSNVPROC) (GLuint program, GLsizei count, const GLint *locations, GLenum bufferMode); +typedef void (APIENTRYP PFNGLACTIVEVARYINGNVPROC) (GLuint program, const GLchar *name); +typedef GLint (APIENTRYP PFNGLGETVARYINGLOCATIONNVPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVEVARYINGNVPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGNVPROC) (GLuint program, GLuint index, GLint *location); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKSTREAMATTRIBSNVPROC) (GLsizei count, const GLint *attribs, GLsizei nbuffers, const GLint *bufstreams, GLenum bufferMode); +#endif + +#ifndef GL_EXT_bindable_uniform +#define GL_EXT_bindable_uniform 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUniformBufferEXT (GLuint program, GLint location, GLuint buffer); +GLAPI GLint APIENTRY glGetUniformBufferSizeEXT (GLuint program, GLint location); +GLAPI GLintptr APIENTRY glGetUniformOffsetEXT (GLuint program, GLint location); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUNIFORMBUFFEREXTPROC) (GLuint program, GLint location, GLuint buffer); +typedef GLint (APIENTRYP PFNGLGETUNIFORMBUFFERSIZEEXTPROC) (GLuint program, GLint location); +typedef GLintptr (APIENTRYP PFNGLGETUNIFORMOFFSETEXTPROC) (GLuint program, GLint location); +#endif + +#ifndef GL_EXT_texture_integer +#define GL_EXT_texture_integer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexParameterIivEXT (GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTexParameterIuivEXT (GLenum target, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glGetTexParameterIivEXT (GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTexParameterIuivEXT (GLenum target, GLenum pname, GLuint *params); +GLAPI void APIENTRY glClearColorIiEXT (GLint red, GLint green, GLint blue, GLint alpha); +GLAPI void APIENTRY glClearColorIuiEXT (GLuint red, GLuint green, GLuint blue, GLuint alpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLCLEARCOLORIIEXTPROC) (GLint red, GLint green, GLint blue, GLint alpha); +typedef void (APIENTRYP PFNGLCLEARCOLORIUIEXTPROC) (GLuint red, GLuint green, GLuint blue, GLuint alpha); +#endif + +#ifndef GL_GREMEDY_frame_terminator +#define GL_GREMEDY_frame_terminator 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFrameTerminatorGREMEDY (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAMETERMINATORGREMEDYPROC) (void); +#endif + +#ifndef GL_NV_conditional_render +#define GL_NV_conditional_render 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginConditionalRenderNV (GLuint id, GLenum mode); +GLAPI void APIENTRY glEndConditionalRenderNV (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERNVPROC) (GLuint id, GLenum mode); +typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERNVPROC) (void); +#endif + +#ifndef GL_NV_present_video +#define GL_NV_present_video 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPresentFrameKeyedNV (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLuint key0, GLenum target1, GLuint fill1, GLuint key1); +GLAPI void APIENTRY glPresentFrameDualFillNV (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLenum target1, GLuint fill1, GLenum target2, GLuint fill2, GLenum target3, GLuint fill3); +GLAPI void APIENTRY glGetVideoivNV (GLuint video_slot, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVideouivNV (GLuint video_slot, GLenum pname, GLuint *params); +GLAPI void APIENTRY glGetVideoi64vNV (GLuint video_slot, GLenum pname, GLint64EXT *params); +GLAPI void APIENTRY glGetVideoui64vNV (GLuint video_slot, GLenum pname, GLuint64EXT *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPRESENTFRAMEKEYEDNVPROC) (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLuint key0, GLenum target1, GLuint fill1, GLuint key1); +typedef void (APIENTRYP PFNGLPRESENTFRAMEDUALFILLNVPROC) (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLenum target1, GLuint fill1, GLenum target2, GLuint fill2, GLenum target3, GLuint fill3); +typedef void (APIENTRYP PFNGLGETVIDEOIVNVPROC) (GLuint video_slot, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVIDEOUIVNVPROC) (GLuint video_slot, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLGETVIDEOI64VNVPROC) (GLuint video_slot, GLenum pname, GLint64EXT *params); +typedef void (APIENTRYP PFNGLGETVIDEOUI64VNVPROC) (GLuint video_slot, GLenum pname, GLuint64EXT *params); +#endif + +#ifndef GL_EXT_transform_feedback +#define GL_EXT_transform_feedback 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginTransformFeedbackEXT (GLenum primitiveMode); +GLAPI void APIENTRY glEndTransformFeedbackEXT (void); +GLAPI void APIENTRY glBindBufferRangeEXT (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +GLAPI void APIENTRY glBindBufferOffsetEXT (GLenum target, GLuint index, GLuint buffer, GLintptr offset); +GLAPI void APIENTRY glBindBufferBaseEXT (GLenum target, GLuint index, GLuint buffer); +GLAPI void APIENTRY glTransformFeedbackVaryingsEXT (GLuint program, GLsizei count, const GLchar* *varyings, GLenum bufferMode); +GLAPI void APIENTRY glGetTransformFeedbackVaryingEXT (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKEXTPROC) (GLenum primitiveMode); +typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKEXTPROC) (void); +typedef void (APIENTRYP PFNGLBINDBUFFERRANGEEXTPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLBINDBUFFEROFFSETEXTPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset); +typedef void (APIENTRYP PFNGLBINDBUFFERBASEEXTPROC) (GLenum target, GLuint index, GLuint buffer); +typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSEXTPROC) (GLuint program, GLsizei count, const GLchar* *varyings, GLenum bufferMode); +typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGEXTPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name); +#endif + +#ifndef GL_EXT_direct_state_access +#define GL_EXT_direct_state_access 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClientAttribDefaultEXT (GLbitfield mask); +GLAPI void APIENTRY glPushClientAttribDefaultEXT (GLbitfield mask); +GLAPI void APIENTRY glMatrixLoadfEXT (GLenum mode, const GLfloat *m); +GLAPI void APIENTRY glMatrixLoaddEXT (GLenum mode, const GLdouble *m); +GLAPI void APIENTRY glMatrixMultfEXT (GLenum mode, const GLfloat *m); +GLAPI void APIENTRY glMatrixMultdEXT (GLenum mode, const GLdouble *m); +GLAPI void APIENTRY glMatrixLoadIdentityEXT (GLenum mode); +GLAPI void APIENTRY glMatrixRotatefEXT (GLenum mode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glMatrixRotatedEXT (GLenum mode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glMatrixScalefEXT (GLenum mode, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glMatrixScaledEXT (GLenum mode, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glMatrixTranslatefEXT (GLenum mode, GLfloat x, GLfloat y, GLfloat z); +GLAPI void APIENTRY glMatrixTranslatedEXT (GLenum mode, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glMatrixFrustumEXT (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +GLAPI void APIENTRY glMatrixOrthoEXT (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +GLAPI void APIENTRY glMatrixPopEXT (GLenum mode); +GLAPI void APIENTRY glMatrixPushEXT (GLenum mode); +GLAPI void APIENTRY glMatrixLoadTransposefEXT (GLenum mode, const GLfloat *m); +GLAPI void APIENTRY glMatrixLoadTransposedEXT (GLenum mode, const GLdouble *m); +GLAPI void APIENTRY glMatrixMultTransposefEXT (GLenum mode, const GLfloat *m); +GLAPI void APIENTRY glMatrixMultTransposedEXT (GLenum mode, const GLdouble *m); +GLAPI void APIENTRY glTextureParameterfEXT (GLuint texture, GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glTextureParameterfvEXT (GLuint texture, GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glTextureParameteriEXT (GLuint texture, GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glTextureParameterivEXT (GLuint texture, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glCopyTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +GLAPI void APIENTRY glCopyTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GLAPI void APIENTRY glCopyTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetTextureImageEXT (GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +GLAPI void APIENTRY glGetTextureParameterfvEXT (GLuint texture, GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetTextureParameterivEXT (GLuint texture, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTextureLevelParameterfvEXT (GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetTextureLevelParameterivEXT (GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params); +GLAPI void APIENTRY glTextureImage3DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glCopyTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glMultiTexParameterfEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glMultiTexParameterfvEXT (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glMultiTexParameteriEXT (GLenum texunit, GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glMultiTexParameterivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glCopyMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +GLAPI void APIENTRY glCopyMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GLAPI void APIENTRY glCopyMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +GLAPI void APIENTRY glCopyMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetMultiTexImageEXT (GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +GLAPI void APIENTRY glGetMultiTexParameterfvEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMultiTexParameterivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMultiTexLevelParameterfvEXT (GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMultiTexLevelParameterivEXT (GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params); +GLAPI void APIENTRY glMultiTexImage3DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +GLAPI void APIENTRY glCopyMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GLAPI void APIENTRY glBindMultiTextureEXT (GLenum texunit, GLenum target, GLuint texture); +GLAPI void APIENTRY glEnableClientStateIndexedEXT (GLenum array, GLuint index); +GLAPI void APIENTRY glDisableClientStateIndexedEXT (GLenum array, GLuint index); +GLAPI void APIENTRY glMultiTexCoordPointerEXT (GLenum texunit, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glMultiTexEnvfEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat param); +GLAPI void APIENTRY glMultiTexEnvfvEXT (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glMultiTexEnviEXT (GLenum texunit, GLenum target, GLenum pname, GLint param); +GLAPI void APIENTRY glMultiTexEnvivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glMultiTexGendEXT (GLenum texunit, GLenum coord, GLenum pname, GLdouble param); +GLAPI void APIENTRY glMultiTexGendvEXT (GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params); +GLAPI void APIENTRY glMultiTexGenfEXT (GLenum texunit, GLenum coord, GLenum pname, GLfloat param); +GLAPI void APIENTRY glMultiTexGenfvEXT (GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glMultiTexGeniEXT (GLenum texunit, GLenum coord, GLenum pname, GLint param); +GLAPI void APIENTRY glMultiTexGenivEXT (GLenum texunit, GLenum coord, GLenum pname, const GLint *params); +GLAPI void APIENTRY glGetMultiTexEnvfvEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMultiTexEnvivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMultiTexGendvEXT (GLenum texunit, GLenum coord, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glGetMultiTexGenfvEXT (GLenum texunit, GLenum coord, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetMultiTexGenivEXT (GLenum texunit, GLenum coord, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetFloatIndexedvEXT (GLenum target, GLuint index, GLfloat *data); +GLAPI void APIENTRY glGetDoubleIndexedvEXT (GLenum target, GLuint index, GLdouble *data); +GLAPI void APIENTRY glGetPointerIndexedvEXT (GLenum target, GLuint index, GLvoid* *data); +GLAPI void APIENTRY glCompressedTextureImage3DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glGetCompressedTextureImageEXT (GLuint texture, GLenum target, GLint lod, GLvoid *img); +GLAPI void APIENTRY glCompressedMultiTexImage3DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glCompressedMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits); +GLAPI void APIENTRY glGetCompressedMultiTexImageEXT (GLenum texunit, GLenum target, GLint lod, GLvoid *img); +GLAPI void APIENTRY glNamedProgramStringEXT (GLuint program, GLenum target, GLenum format, GLsizei len, const GLvoid *string); +GLAPI void APIENTRY glNamedProgramLocalParameter4dEXT (GLuint program, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glNamedProgramLocalParameter4dvEXT (GLuint program, GLenum target, GLuint index, const GLdouble *params); +GLAPI void APIENTRY glNamedProgramLocalParameter4fEXT (GLuint program, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GLAPI void APIENTRY glNamedProgramLocalParameter4fvEXT (GLuint program, GLenum target, GLuint index, const GLfloat *params); +GLAPI void APIENTRY glGetNamedProgramLocalParameterdvEXT (GLuint program, GLenum target, GLuint index, GLdouble *params); +GLAPI void APIENTRY glGetNamedProgramLocalParameterfvEXT (GLuint program, GLenum target, GLuint index, GLfloat *params); +GLAPI void APIENTRY glGetNamedProgramivEXT (GLuint program, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetNamedProgramStringEXT (GLuint program, GLenum target, GLenum pname, GLvoid *string); +GLAPI void APIENTRY glNamedProgramLocalParameters4fvEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLfloat *params); +GLAPI void APIENTRY glNamedProgramLocalParameterI4iEXT (GLuint program, GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +GLAPI void APIENTRY glNamedProgramLocalParameterI4ivEXT (GLuint program, GLenum target, GLuint index, const GLint *params); +GLAPI void APIENTRY glNamedProgramLocalParametersI4ivEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLint *params); +GLAPI void APIENTRY glNamedProgramLocalParameterI4uiEXT (GLuint program, GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +GLAPI void APIENTRY glNamedProgramLocalParameterI4uivEXT (GLuint program, GLenum target, GLuint index, const GLuint *params); +GLAPI void APIENTRY glNamedProgramLocalParametersI4uivEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLuint *params); +GLAPI void APIENTRY glGetNamedProgramLocalParameterIivEXT (GLuint program, GLenum target, GLuint index, GLint *params); +GLAPI void APIENTRY glGetNamedProgramLocalParameterIuivEXT (GLuint program, GLenum target, GLuint index, GLuint *params); +GLAPI void APIENTRY glTextureParameterIivEXT (GLuint texture, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glTextureParameterIuivEXT (GLuint texture, GLenum target, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glGetTextureParameterIivEXT (GLuint texture, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetTextureParameterIuivEXT (GLuint texture, GLenum target, GLenum pname, GLuint *params); +GLAPI void APIENTRY glMultiTexParameterIivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +GLAPI void APIENTRY glMultiTexParameterIuivEXT (GLenum texunit, GLenum target, GLenum pname, const GLuint *params); +GLAPI void APIENTRY glGetMultiTexParameterIivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetMultiTexParameterIuivEXT (GLenum texunit, GLenum target, GLenum pname, GLuint *params); +GLAPI void APIENTRY glProgramUniform1fEXT (GLuint program, GLint location, GLfloat v0); +GLAPI void APIENTRY glProgramUniform2fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1); +GLAPI void APIENTRY glProgramUniform3fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +GLAPI void APIENTRY glProgramUniform4fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +GLAPI void APIENTRY glProgramUniform1iEXT (GLuint program, GLint location, GLint v0); +GLAPI void APIENTRY glProgramUniform2iEXT (GLuint program, GLint location, GLint v0, GLint v1); +GLAPI void APIENTRY glProgramUniform3iEXT (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +GLAPI void APIENTRY glProgramUniform4iEXT (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +GLAPI void APIENTRY glProgramUniform1fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform2fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform3fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform4fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform1ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform2ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform3ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniform4ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value); +GLAPI void APIENTRY glProgramUniformMatrix2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +GLAPI void APIENTRY glProgramUniform1uiEXT (GLuint program, GLint location, GLuint v0); +GLAPI void APIENTRY glProgramUniform2uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1); +GLAPI void APIENTRY glProgramUniform3uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +GLAPI void APIENTRY glProgramUniform4uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +GLAPI void APIENTRY glProgramUniform1uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform2uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform3uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glProgramUniform4uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value); +GLAPI void APIENTRY glNamedBufferDataEXT (GLuint buffer, GLsizeiptr size, const GLvoid *data, GLenum usage); +GLAPI void APIENTRY glNamedBufferSubDataEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, const GLvoid *data); +GLAPI GLvoid* APIENTRY glMapNamedBufferEXT (GLuint buffer, GLenum access); +GLAPI GLboolean APIENTRY glUnmapNamedBufferEXT (GLuint buffer); +GLAPI GLvoid* APIENTRY glMapNamedBufferRangeEXT (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access); +GLAPI void APIENTRY glFlushMappedNamedBufferRangeEXT (GLuint buffer, GLintptr offset, GLsizeiptr length); +GLAPI void APIENTRY glNamedCopyBufferSubDataEXT (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +GLAPI void APIENTRY glGetNamedBufferParameterivEXT (GLuint buffer, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetNamedBufferPointervEXT (GLuint buffer, GLenum pname, GLvoid* *params); +GLAPI void APIENTRY glGetNamedBufferSubDataEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, GLvoid *data); +GLAPI void APIENTRY glTextureBufferEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer); +GLAPI void APIENTRY glMultiTexBufferEXT (GLenum texunit, GLenum target, GLenum internalformat, GLuint buffer); +GLAPI void APIENTRY glNamedRenderbufferStorageEXT (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetNamedRenderbufferParameterivEXT (GLuint renderbuffer, GLenum pname, GLint *params); +GLAPI GLenum APIENTRY glCheckNamedFramebufferStatusEXT (GLuint framebuffer, GLenum target); +GLAPI void APIENTRY glNamedFramebufferTexture1DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glNamedFramebufferTexture2DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GLAPI void APIENTRY glNamedFramebufferTexture3DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +GLAPI void APIENTRY glNamedFramebufferRenderbufferEXT (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GLAPI void APIENTRY glGetNamedFramebufferAttachmentParameterivEXT (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params); +GLAPI void APIENTRY glGenerateTextureMipmapEXT (GLuint texture, GLenum target); +GLAPI void APIENTRY glGenerateMultiTexMipmapEXT (GLenum texunit, GLenum target); +GLAPI void APIENTRY glFramebufferDrawBufferEXT (GLuint framebuffer, GLenum mode); +GLAPI void APIENTRY glFramebufferDrawBuffersEXT (GLuint framebuffer, GLsizei n, const GLenum *bufs); +GLAPI void APIENTRY glFramebufferReadBufferEXT (GLuint framebuffer, GLenum mode); +GLAPI void APIENTRY glGetFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params); +GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleEXT (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleCoverageEXT (GLuint renderbuffer, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glNamedFramebufferTextureEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level); +GLAPI void APIENTRY glNamedFramebufferTextureLayerEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer); +GLAPI void APIENTRY glNamedFramebufferTextureFaceEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLenum face); +GLAPI void APIENTRY glTextureRenderbufferEXT (GLuint texture, GLenum target, GLuint renderbuffer); +GLAPI void APIENTRY glMultiTexRenderbufferEXT (GLenum texunit, GLenum target, GLuint renderbuffer); +GLAPI void APIENTRY glProgramUniform1dEXT (GLuint program, GLint location, GLdouble x); +GLAPI void APIENTRY glProgramUniform2dEXT (GLuint program, GLint location, GLdouble x, GLdouble y); +GLAPI void APIENTRY glProgramUniform3dEXT (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glProgramUniform4dEXT (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glProgramUniform1dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform2dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform3dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniform4dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix2x4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix3x4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +GLAPI void APIENTRY glProgramUniformMatrix4x3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLIENTATTRIBDEFAULTEXTPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLPUSHCLIENTATTRIBDEFAULTEXTPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLMATRIXLOADFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXLOADDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLMATRIXMULTFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXMULTDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLMATRIXLOADIDENTITYEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLMATRIXROTATEFEXTPROC) (GLenum mode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLMATRIXROTATEDEXTPROC) (GLenum mode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLMATRIXSCALEFEXTPROC) (GLenum mode, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLMATRIXSCALEDEXTPROC) (GLenum mode, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLMATRIXTRANSLATEFEXTPROC) (GLenum mode, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLMATRIXTRANSLATEDEXTPROC) (GLenum mode, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLMATRIXFRUSTUMEXTPROC) (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +typedef void (APIENTRYP PFNGLMATRIXORTHOEXTPROC) (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +typedef void (APIENTRYP PFNGLMATRIXPOPEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLMATRIXPUSHEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSEFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSEDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSEFEXTPROC) (GLenum mode, const GLfloat *m); +typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSEDEXTPROC) (GLenum mode, const GLdouble *m); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETTEXTUREIMAGEEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERFEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETMULTITEXIMAGEEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXLEVELPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXLEVELPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLBINDMULTITEXTUREEXTPROC) (GLenum texunit, GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLENABLECLIENTSTATEINDEXEDEXTPROC) (GLenum array, GLuint index); +typedef void (APIENTRYP PFNGLDISABLECLIENTSTATEINDEXEDEXTPROC) (GLenum array, GLuint index); +typedef void (APIENTRYP PFNGLMULTITEXCOORDPOINTEREXTPROC) (GLenum texunit, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLMULTITEXENVFEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLMULTITEXENVFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLMULTITEXENVIEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLMULTITEXENVIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXGENDEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLdouble param); +typedef void (APIENTRYP PFNGLMULTITEXGENDVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params); +typedef void (APIENTRYP PFNGLMULTITEXGENFEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLMULTITEXGENFVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLMULTITEXGENIEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLMULTITEXGENIVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXENVFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXENVIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXGENDVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETMULTITEXGENFVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMULTITEXGENIVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFLOATINDEXEDVEXTPROC) (GLenum target, GLuint index, GLfloat *data); +typedef void (APIENTRYP PFNGLGETDOUBLEINDEXEDVEXTPROC) (GLenum target, GLuint index, GLdouble *data); +typedef void (APIENTRYP PFNGLGETPOINTERINDEXEDVEXTPROC) (GLenum target, GLuint index, GLvoid* *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXTUREIMAGEEXTPROC) (GLuint texture, GLenum target, GLint lod, GLvoid *img); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *bits); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDMULTITEXIMAGEEXTPROC) (GLenum texunit, GLenum target, GLint lod, GLvoid *img); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMSTRINGEXTPROC) (GLuint program, GLenum target, GLenum format, GLsizei len, const GLvoid *string); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4DEXTPROC) (GLuint program, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4DVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4FEXTPROC) (GLuint program, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4FVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERDVEXTPROC) (GLuint program, GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERFVEXTPROC) (GLuint program, GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMIVEXTPROC) (GLuint program, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMSTRINGEXTPROC) (GLuint program, GLenum target, GLenum pname, GLvoid *string); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERS4FVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLfloat *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4IEXTPROC) (GLuint program, GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4IVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLint *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERSI4IVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLint *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4UIEXTPROC) (GLuint program, GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4UIVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLuint *params); +typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERSI4UIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERIIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLint *params); +typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERIUIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLuint *params); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIUIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIUIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIUIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLuint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIUIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FEXTPROC) (GLuint program, GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IEXTPROC) (GLuint program, GLint location, GLint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIEXTPROC) (GLuint program, GLint location, GLuint v0); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value); +typedef void (APIENTRYP PFNGLNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLsizeiptr size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, const GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPNAMEDBUFFEREXTPROC) (GLuint buffer, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPNAMEDBUFFEREXTPROC) (GLuint buffer); +typedef GLvoid* (APIENTRYP PFNGLMAPNAMEDBUFFERRANGEEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDNAMEDBUFFERRANGEEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length); +typedef void (APIENTRYP PFNGLNAMEDCOPYBUFFERSUBDATAEXTPROC) (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERIVEXTPROC) (GLuint buffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPOINTERVEXTPROC) (GLuint buffer, GLenum pname, GLvoid* *params); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, GLvoid *data); +typedef void (APIENTRYP PFNGLTEXTUREBUFFEREXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLMULTITEXBUFFEREXTPROC) (GLenum texunit, GLenum target, GLenum internalformat, GLuint buffer); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEEXTPROC) (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETNAMEDRENDERBUFFERPARAMETERIVEXTPROC) (GLuint renderbuffer, GLenum pname, GLint *params); +typedef GLenum (APIENTRYP PFNGLCHECKNAMEDFRAMEBUFFERSTATUSEXTPROC) (GLuint framebuffer, GLenum target); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE1DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE2DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE3DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERRENDERBUFFEREXTPROC) (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATETEXTUREMIPMAPEXTPROC) (GLuint texture, GLenum target); +typedef void (APIENTRYP PFNGLGENERATEMULTITEXMIPMAPEXTPROC) (GLenum texunit, GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERDRAWBUFFEREXTPROC) (GLuint framebuffer, GLenum mode); +typedef void (APIENTRYP PFNGLFRAMEBUFFERDRAWBUFFERSEXTPROC) (GLuint framebuffer, GLsizei n, const GLenum *bufs); +typedef void (APIENTRYP PFNGLFRAMEBUFFERREADBUFFEREXTPROC) (GLuint framebuffer, GLenum mode); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLECOVERAGEEXTPROC) (GLuint renderbuffer, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREEXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURELAYEREXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer); +typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREFACEEXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLenum face); +typedef void (APIENTRYP PFNGLTEXTURERENDERBUFFEREXTPROC) (GLuint texture, GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLMULTITEXRENDERBUFFEREXTPROC) (GLenum texunit, GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DEXTPROC) (GLuint program, GLint location, GLdouble x); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value); +#endif + +#ifndef GL_EXT_vertex_array_bgra +#define GL_EXT_vertex_array_bgra 1 +#endif + +#ifndef GL_EXT_texture_swizzle +#define GL_EXT_texture_swizzle 1 +#endif + +#ifndef GL_NV_explicit_multisample +#define GL_NV_explicit_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetMultisamplefvNV (GLenum pname, GLuint index, GLfloat *val); +GLAPI void APIENTRY glSampleMaskIndexedNV (GLuint index, GLbitfield mask); +GLAPI void APIENTRY glTexRenderbufferNV (GLenum target, GLuint renderbuffer); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVNVPROC) (GLenum pname, GLuint index, GLfloat *val); +typedef void (APIENTRYP PFNGLSAMPLEMASKINDEXEDNVPROC) (GLuint index, GLbitfield mask); +typedef void (APIENTRYP PFNGLTEXRENDERBUFFERNVPROC) (GLenum target, GLuint renderbuffer); +#endif + +#ifndef GL_NV_transform_feedback2 +#define GL_NV_transform_feedback2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindTransformFeedbackNV (GLenum target, GLuint id); +GLAPI void APIENTRY glDeleteTransformFeedbacksNV (GLsizei n, const GLuint *ids); +GLAPI void APIENTRY glGenTransformFeedbacksNV (GLsizei n, GLuint *ids); +GLAPI GLboolean APIENTRY glIsTransformFeedbackNV (GLuint id); +GLAPI void APIENTRY glPauseTransformFeedbackNV (void); +GLAPI void APIENTRY glResumeTransformFeedbackNV (void); +GLAPI void APIENTRY glDrawTransformFeedbackNV (GLenum mode, GLuint id); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKNVPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSNVPROC) (GLsizei n, const GLuint *ids); +typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSNVPROC) (GLsizei n, GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKNVPROC) (void); +typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKNVPROC) (void); +typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKNVPROC) (GLenum mode, GLuint id); +#endif + +#ifndef GL_ATI_meminfo +#define GL_ATI_meminfo 1 +#endif + +#ifndef GL_AMD_performance_monitor +#define GL_AMD_performance_monitor 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetPerfMonitorGroupsAMD (GLint *numGroups, GLsizei groupsSize, GLuint *groups); +GLAPI void APIENTRY glGetPerfMonitorCountersAMD (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); +GLAPI void APIENTRY glGetPerfMonitorGroupStringAMD (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); +GLAPI void APIENTRY glGetPerfMonitorCounterStringAMD (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); +GLAPI void APIENTRY glGetPerfMonitorCounterInfoAMD (GLuint group, GLuint counter, GLenum pname, GLvoid *data); +GLAPI void APIENTRY glGenPerfMonitorsAMD (GLsizei n, GLuint *monitors); +GLAPI void APIENTRY glDeletePerfMonitorsAMD (GLsizei n, GLuint *monitors); +GLAPI void APIENTRY glSelectPerfMonitorCountersAMD (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList); +GLAPI void APIENTRY glBeginPerfMonitorAMD (GLuint monitor); +GLAPI void APIENTRY glEndPerfMonitorAMD (GLuint monitor); +GLAPI void APIENTRY glGetPerfMonitorCounterDataAMD (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETPERFMONITORGROUPSAMDPROC) (GLint *numGroups, GLsizei groupsSize, GLuint *groups); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERSAMDPROC) (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); +typedef void (APIENTRYP PFNGLGETPERFMONITORGROUPSTRINGAMDPROC) (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERSTRINGAMDPROC) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERINFOAMDPROC) (GLuint group, GLuint counter, GLenum pname, GLvoid *data); +typedef void (APIENTRYP PFNGLGENPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); +typedef void (APIENTRYP PFNGLDELETEPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); +typedef void (APIENTRYP PFNGLSELECTPERFMONITORCOUNTERSAMDPROC) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList); +typedef void (APIENTRYP PFNGLBEGINPERFMONITORAMDPROC) (GLuint monitor); +typedef void (APIENTRYP PFNGLENDPERFMONITORAMDPROC) (GLuint monitor); +typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERDATAAMDPROC) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); +#endif + +#ifndef GL_AMD_texture_texture4 +#define GL_AMD_texture_texture4 1 +#endif + +#ifndef GL_AMD_vertex_shader_tesselator +#define GL_AMD_vertex_shader_tesselator 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTessellationFactorAMD (GLfloat factor); +GLAPI void APIENTRY glTessellationModeAMD (GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTESSELLATIONFACTORAMDPROC) (GLfloat factor); +typedef void (APIENTRYP PFNGLTESSELLATIONMODEAMDPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_provoking_vertex +#define GL_EXT_provoking_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProvokingVertexEXT (GLenum mode); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROVOKINGVERTEXEXTPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_texture_snorm +#define GL_EXT_texture_snorm 1 +#endif + +#ifndef GL_AMD_draw_buffers_blend +#define GL_AMD_draw_buffers_blend 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncIndexedAMD (GLuint buf, GLenum src, GLenum dst); +GLAPI void APIENTRY glBlendFuncSeparateIndexedAMD (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +GLAPI void APIENTRY glBlendEquationIndexedAMD (GLuint buf, GLenum mode); +GLAPI void APIENTRY glBlendEquationSeparateIndexedAMD (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCINDEXEDAMDPROC) (GLuint buf, GLenum src, GLenum dst); +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINDEXEDAMDPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +typedef void (APIENTRYP PFNGLBLENDEQUATIONINDEXEDAMDPROC) (GLuint buf, GLenum mode); +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEINDEXEDAMDPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha); +#endif + +#ifndef GL_APPLE_texture_range +#define GL_APPLE_texture_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureRangeAPPLE (GLenum target, GLsizei length, const GLvoid *pointer); +GLAPI void APIENTRY glGetTexParameterPointervAPPLE (GLenum target, GLenum pname, GLvoid* *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTURERANGEAPPLEPROC) (GLenum target, GLsizei length, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETTEXPARAMETERPOINTERVAPPLEPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_APPLE_float_pixels +#define GL_APPLE_float_pixels 1 +#endif + +#ifndef GL_APPLE_vertex_program_evaluators +#define GL_APPLE_vertex_program_evaluators 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glEnableVertexAttribAPPLE (GLuint index, GLenum pname); +GLAPI void APIENTRY glDisableVertexAttribAPPLE (GLuint index, GLenum pname); +GLAPI GLboolean APIENTRY glIsVertexAttribEnabledAPPLE (GLuint index, GLenum pname); +GLAPI void APIENTRY glMapVertexAttrib1dAPPLE (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); +GLAPI void APIENTRY glMapVertexAttrib1fAPPLE (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); +GLAPI void APIENTRY glMapVertexAttrib2dAPPLE (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); +GLAPI void APIENTRY glMapVertexAttrib2fAPPLE (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBAPPLEPROC) (GLuint index, GLenum pname); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBAPPLEPROC) (GLuint index, GLenum pname); +typedef GLboolean (APIENTRYP PFNGLISVERTEXATTRIBENABLEDAPPLEPROC) (GLuint index, GLenum pname); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB1DAPPLEPROC) (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB1FAPPLEPROC) (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB2DAPPLEPROC) (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); +typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB2FAPPLEPROC) (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); +#endif + +#ifndef GL_APPLE_aux_depth_stencil +#define GL_APPLE_aux_depth_stencil 1 +#endif + +#ifndef GL_APPLE_object_purgeable +#define GL_APPLE_object_purgeable 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLenum APIENTRY glObjectPurgeableAPPLE (GLenum objectType, GLuint name, GLenum option); +GLAPI GLenum APIENTRY glObjectUnpurgeableAPPLE (GLenum objectType, GLuint name, GLenum option); +GLAPI void APIENTRY glGetObjectParameterivAPPLE (GLenum objectType, GLuint name, GLenum pname, GLint *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLenum (APIENTRYP PFNGLOBJECTPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option); +typedef GLenum (APIENTRYP PFNGLOBJECTUNPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVAPPLEPROC) (GLenum objectType, GLuint name, GLenum pname, GLint *params); +#endif + +#ifndef GL_APPLE_row_bytes +#define GL_APPLE_row_bytes 1 +#endif + +#ifndef GL_APPLE_rgb_422 +#define GL_APPLE_rgb_422 1 +#endif + +#ifndef GL_NV_video_capture +#define GL_NV_video_capture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginVideoCaptureNV (GLuint video_capture_slot); +GLAPI void APIENTRY glBindVideoCaptureStreamBufferNV (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLintptrARB offset); +GLAPI void APIENTRY glBindVideoCaptureStreamTextureNV (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLenum target, GLuint texture); +GLAPI void APIENTRY glEndVideoCaptureNV (GLuint video_capture_slot); +GLAPI void APIENTRY glGetVideoCaptureivNV (GLuint video_capture_slot, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVideoCaptureStreamivNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVideoCaptureStreamfvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLfloat *params); +GLAPI void APIENTRY glGetVideoCaptureStreamdvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLdouble *params); +GLAPI GLenum APIENTRY glVideoCaptureNV (GLuint video_capture_slot, GLuint *sequence_num, GLuint64EXT *capture_time); +GLAPI void APIENTRY glVideoCaptureStreamParameterivNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLint *params); +GLAPI void APIENTRY glVideoCaptureStreamParameterfvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLfloat *params); +GLAPI void APIENTRY glVideoCaptureStreamParameterdvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLdouble *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINVIDEOCAPTURENVPROC) (GLuint video_capture_slot); +typedef void (APIENTRYP PFNGLBINDVIDEOCAPTURESTREAMBUFFERNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLintptrARB offset); +typedef void (APIENTRYP PFNGLBINDVIDEOCAPTURESTREAMTEXTURENVPROC) (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLENDVIDEOCAPTURENVPROC) (GLuint video_capture_slot); +typedef void (APIENTRYP PFNGLGETVIDEOCAPTUREIVNVPROC) (GLuint video_capture_slot, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMIVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMFVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMDVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLdouble *params); +typedef GLenum (APIENTRYP PFNGLVIDEOCAPTURENVPROC) (GLuint video_capture_slot, GLuint *sequence_num, GLuint64EXT *capture_time); +typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERIVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERFVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERDVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLdouble *params); +#endif + +#ifndef GL_NV_copy_image +#define GL_NV_copy_image 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCopyImageSubDataNV (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATANVPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +#endif + +#ifndef GL_EXT_separate_shader_objects +#define GL_EXT_separate_shader_objects 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUseShaderProgramEXT (GLenum type, GLuint program); +GLAPI void APIENTRY glActiveProgramEXT (GLuint program); +GLAPI GLuint APIENTRY glCreateShaderProgramEXT (GLenum type, const GLchar *string); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUSESHADERPROGRAMEXTPROC) (GLenum type, GLuint program); +typedef void (APIENTRYP PFNGLACTIVEPROGRAMEXTPROC) (GLuint program); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMEXTPROC) (GLenum type, const GLchar *string); +#endif + +#ifndef GL_NV_parameter_buffer_object2 +#define GL_NV_parameter_buffer_object2 1 +#endif + +#ifndef GL_NV_shader_buffer_load +#define GL_NV_shader_buffer_load 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMakeBufferResidentNV (GLenum target, GLenum access); +GLAPI void APIENTRY glMakeBufferNonResidentNV (GLenum target); +GLAPI GLboolean APIENTRY glIsBufferResidentNV (GLenum target); +GLAPI void APIENTRY glMakeNamedBufferResidentNV (GLuint buffer, GLenum access); +GLAPI void APIENTRY glMakeNamedBufferNonResidentNV (GLuint buffer); +GLAPI GLboolean APIENTRY glIsNamedBufferResidentNV (GLuint buffer); +GLAPI void APIENTRY glGetBufferParameterui64vNV (GLenum target, GLenum pname, GLuint64EXT *params); +GLAPI void APIENTRY glGetNamedBufferParameterui64vNV (GLuint buffer, GLenum pname, GLuint64EXT *params); +GLAPI void APIENTRY glGetIntegerui64vNV (GLenum value, GLuint64EXT *result); +GLAPI void APIENTRY glUniformui64NV (GLint location, GLuint64EXT value); +GLAPI void APIENTRY glUniformui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glGetUniformui64vNV (GLuint program, GLint location, GLuint64EXT *params); +GLAPI void APIENTRY glProgramUniformui64NV (GLuint program, GLint location, GLuint64EXT value); +GLAPI void APIENTRY glProgramUniformui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMAKEBUFFERRESIDENTNVPROC) (GLenum target, GLenum access); +typedef void (APIENTRYP PFNGLMAKEBUFFERNONRESIDENTNVPROC) (GLenum target); +typedef GLboolean (APIENTRYP PFNGLISBUFFERRESIDENTNVPROC) (GLenum target); +typedef void (APIENTRYP PFNGLMAKENAMEDBUFFERRESIDENTNVPROC) (GLuint buffer, GLenum access); +typedef void (APIENTRYP PFNGLMAKENAMEDBUFFERNONRESIDENTNVPROC) (GLuint buffer); +typedef GLboolean (APIENTRYP PFNGLISNAMEDBUFFERRESIDENTNVPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERUI64VNVPROC) (GLenum target, GLenum pname, GLuint64EXT *params); +typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERUI64VNVPROC) (GLuint buffer, GLenum pname, GLuint64EXT *params); +typedef void (APIENTRYP PFNGLGETINTEGERUI64VNVPROC) (GLenum value, GLuint64EXT *result); +typedef void (APIENTRYP PFNGLUNIFORMUI64NVPROC) (GLint location, GLuint64EXT value); +typedef void (APIENTRYP PFNGLUNIFORMUI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLGETUNIFORMUI64VNVPROC) (GLuint program, GLint location, GLuint64EXT *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMUI64NVPROC) (GLuint program, GLint location, GLuint64EXT value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORMUI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +#endif + +#ifndef GL_NV_vertex_buffer_unified_memory +#define GL_NV_vertex_buffer_unified_memory 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBufferAddressRangeNV (GLenum pname, GLuint index, GLuint64EXT address, GLsizeiptr length); +GLAPI void APIENTRY glVertexFormatNV (GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glNormalFormatNV (GLenum type, GLsizei stride); +GLAPI void APIENTRY glColorFormatNV (GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glIndexFormatNV (GLenum type, GLsizei stride); +GLAPI void APIENTRY glTexCoordFormatNV (GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glEdgeFlagFormatNV (GLsizei stride); +GLAPI void APIENTRY glSecondaryColorFormatNV (GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glFogCoordFormatNV (GLenum type, GLsizei stride); +GLAPI void APIENTRY glVertexAttribFormatNV (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride); +GLAPI void APIENTRY glVertexAttribIFormatNV (GLuint index, GLint size, GLenum type, GLsizei stride); +GLAPI void APIENTRY glGetIntegerui64i_vNV (GLenum value, GLuint index, GLuint64EXT *result); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBUFFERADDRESSRANGENVPROC) (GLenum pname, GLuint index, GLuint64EXT address, GLsizeiptr length); +typedef void (APIENTRYP PFNGLVERTEXFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLNORMALFORMATNVPROC) (GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLCOLORFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLINDEXFORMATNVPROC) (GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLTEXCOORDFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLEDGEFLAGFORMATNVPROC) (GLsizei stride); +typedef void (APIENTRYP PFNGLSECONDARYCOLORFORMATNVPROC) (GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLFOGCOORDFORMATNVPROC) (GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride); +typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLsizei stride); +typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result); +#endif + +#ifndef GL_NV_texture_barrier +#define GL_NV_texture_barrier 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureBarrierNV (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTUREBARRIERNVPROC) (void); +#endif + +#ifndef GL_AMD_shader_stencil_export +#define GL_AMD_shader_stencil_export 1 +#endif + +#ifndef GL_AMD_seamless_cubemap_per_texture +#define GL_AMD_seamless_cubemap_per_texture 1 +#endif + +#ifndef GL_AMD_conservative_depth +#define GL_AMD_conservative_depth 1 +#endif + +#ifndef GL_EXT_shader_image_load_store +#define GL_EXT_shader_image_load_store 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindImageTextureEXT (GLuint index, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLint format); +GLAPI void APIENTRY glMemoryBarrierEXT (GLbitfield barriers); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREEXTPROC) (GLuint index, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLint format); +typedef void (APIENTRYP PFNGLMEMORYBARRIEREXTPROC) (GLbitfield barriers); +#endif + +#ifndef GL_EXT_vertex_attrib_64bit +#define GL_EXT_vertex_attrib_64bit 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribL1dEXT (GLuint index, GLdouble x); +GLAPI void APIENTRY glVertexAttribL2dEXT (GLuint index, GLdouble x, GLdouble y); +GLAPI void APIENTRY glVertexAttribL3dEXT (GLuint index, GLdouble x, GLdouble y, GLdouble z); +GLAPI void APIENTRY glVertexAttribL4dEXT (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +GLAPI void APIENTRY glVertexAttribL1dvEXT (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL2dvEXT (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL3dvEXT (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribL4dvEXT (GLuint index, const GLdouble *v); +GLAPI void APIENTRY glVertexAttribLPointerEXT (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GLAPI void APIENTRY glGetVertexAttribLdvEXT (GLuint index, GLenum pname, GLdouble *params); +GLAPI void APIENTRY glVertexArrayVertexAttribLOffsetEXT (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DEXTPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DEXTPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DEXTPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DEXTPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVEXTPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVEXTPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVEXTPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVEXTPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTEREXTPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVEXTPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset); +#endif + +#ifndef GL_NV_gpu_program5 +#define GL_NV_gpu_program5 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramSubroutineParametersuivNV (GLenum target, GLsizei count, const GLuint *params); +GLAPI void APIENTRY glGetProgramSubroutineParameteruivNV (GLenum target, GLuint index, GLuint *param); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMSUBROUTINEPARAMETERSUIVNVPROC) (GLenum target, GLsizei count, const GLuint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSUBROUTINEPARAMETERUIVNVPROC) (GLenum target, GLuint index, GLuint *param); +#endif + +#ifndef GL_NV_gpu_shader5 +#define GL_NV_gpu_shader5 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glUniform1i64NV (GLint location, GLint64EXT x); +GLAPI void APIENTRY glUniform2i64NV (GLint location, GLint64EXT x, GLint64EXT y); +GLAPI void APIENTRY glUniform3i64NV (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); +GLAPI void APIENTRY glUniform4i64NV (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +GLAPI void APIENTRY glUniform1i64vNV (GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glUniform2i64vNV (GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glUniform3i64vNV (GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glUniform4i64vNV (GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glUniform1ui64NV (GLint location, GLuint64EXT x); +GLAPI void APIENTRY glUniform2ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y); +GLAPI void APIENTRY glUniform3ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +GLAPI void APIENTRY glUniform4ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +GLAPI void APIENTRY glUniform1ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glUniform2ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glUniform3ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glUniform4ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glGetUniformi64vNV (GLuint program, GLint location, GLint64EXT *params); +GLAPI void APIENTRY glProgramUniform1i64NV (GLuint program, GLint location, GLint64EXT x); +GLAPI void APIENTRY glProgramUniform2i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y); +GLAPI void APIENTRY glProgramUniform3i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); +GLAPI void APIENTRY glProgramUniform4i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +GLAPI void APIENTRY glProgramUniform1i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glProgramUniform2i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glProgramUniform3i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glProgramUniform4i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +GLAPI void APIENTRY glProgramUniform1ui64NV (GLuint program, GLint location, GLuint64EXT x); +GLAPI void APIENTRY glProgramUniform2ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y); +GLAPI void APIENTRY glProgramUniform3ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +GLAPI void APIENTRY glProgramUniform4ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +GLAPI void APIENTRY glProgramUniform1ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glProgramUniform2ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glProgramUniform3ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +GLAPI void APIENTRY glProgramUniform4ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLUNIFORM1I64NVPROC) (GLint location, GLint64EXT x); +typedef void (APIENTRYP PFNGLUNIFORM2I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y); +typedef void (APIENTRYP PFNGLUNIFORM3I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); +typedef void (APIENTRYP PFNGLUNIFORM4I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +typedef void (APIENTRYP PFNGLUNIFORM1I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM2I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM3I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM4I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM1UI64NVPROC) (GLint location, GLuint64EXT x); +typedef void (APIENTRYP PFNGLUNIFORM2UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y); +typedef void (APIENTRYP PFNGLUNIFORM3UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +typedef void (APIENTRYP PFNGLUNIFORM4UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +typedef void (APIENTRYP PFNGLUNIFORM1UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM2UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM3UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLUNIFORM4UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLGETUNIFORMI64VNVPROC) (GLuint program, GLint location, GLint64EXT *params); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64NVPROC) (GLuint program, GLint location, GLint64EXT x); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value); +#endif + +#ifndef GL_NV_shader_buffer_store +#define GL_NV_shader_buffer_store 1 +#endif + +#ifndef GL_NV_tessellation_program5 +#define GL_NV_tessellation_program5 1 +#endif + +#ifndef GL_NV_vertex_attrib_integer_64bit +#define GL_NV_vertex_attrib_integer_64bit 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribL1i64NV (GLuint index, GLint64EXT x); +GLAPI void APIENTRY glVertexAttribL2i64NV (GLuint index, GLint64EXT x, GLint64EXT y); +GLAPI void APIENTRY glVertexAttribL3i64NV (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z); +GLAPI void APIENTRY glVertexAttribL4i64NV (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +GLAPI void APIENTRY glVertexAttribL1i64vNV (GLuint index, const GLint64EXT *v); +GLAPI void APIENTRY glVertexAttribL2i64vNV (GLuint index, const GLint64EXT *v); +GLAPI void APIENTRY glVertexAttribL3i64vNV (GLuint index, const GLint64EXT *v); +GLAPI void APIENTRY glVertexAttribL4i64vNV (GLuint index, const GLint64EXT *v); +GLAPI void APIENTRY glVertexAttribL1ui64NV (GLuint index, GLuint64EXT x); +GLAPI void APIENTRY glVertexAttribL2ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y); +GLAPI void APIENTRY glVertexAttribL3ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +GLAPI void APIENTRY glVertexAttribL4ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +GLAPI void APIENTRY glVertexAttribL1ui64vNV (GLuint index, const GLuint64EXT *v); +GLAPI void APIENTRY glVertexAttribL2ui64vNV (GLuint index, const GLuint64EXT *v); +GLAPI void APIENTRY glVertexAttribL3ui64vNV (GLuint index, const GLuint64EXT *v); +GLAPI void APIENTRY glVertexAttribL4ui64vNV (GLuint index, const GLuint64EXT *v); +GLAPI void APIENTRY glGetVertexAttribLi64vNV (GLuint index, GLenum pname, GLint64EXT *params); +GLAPI void APIENTRY glGetVertexAttribLui64vNV (GLuint index, GLenum pname, GLuint64EXT *params); +GLAPI void APIENTRY glVertexAttribLFormatNV (GLuint index, GLint size, GLenum type, GLsizei stride); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1I64NVPROC) (GLuint index, GLint64EXT x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1I64VNVPROC) (GLuint index, const GLint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2I64VNVPROC) (GLuint index, const GLint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3I64VNVPROC) (GLuint index, const GLint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4I64VNVPROC) (GLuint index, const GLint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64NVPROC) (GLuint index, GLuint64EXT x); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64VNVPROC) (GLuint index, const GLuint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL2UI64VNVPROC) (GLuint index, const GLuint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL3UI64VNVPROC) (GLuint index, const GLuint64EXT *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBL4UI64VNVPROC) (GLuint index, const GLuint64EXT *v); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLI64VNVPROC) (GLuint index, GLenum pname, GLint64EXT *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLUI64VNVPROC) (GLuint index, GLenum pname, GLuint64EXT *params); +typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLsizei stride); +#endif + +#ifndef GL_NV_multisample_coverage +#define GL_NV_multisample_coverage 1 +#endif + +#ifndef GL_AMD_name_gen_delete +#define GL_AMD_name_gen_delete 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenNamesAMD (GLenum identifier, GLuint num, GLuint *names); +GLAPI void APIENTRY glDeleteNamesAMD (GLenum identifier, GLuint num, const GLuint *names); +GLAPI GLboolean APIENTRY glIsNameAMD (GLenum identifier, GLuint name); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENNAMESAMDPROC) (GLenum identifier, GLuint num, GLuint *names); +typedef void (APIENTRYP PFNGLDELETENAMESAMDPROC) (GLenum identifier, GLuint num, const GLuint *names); +typedef GLboolean (APIENTRYP PFNGLISNAMEAMDPROC) (GLenum identifier, GLuint name); +#endif + +#ifndef GL_AMD_debug_output +#define GL_AMD_debug_output 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDebugMessageEnableAMD (GLenum category, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +GLAPI void APIENTRY glDebugMessageInsertAMD (GLenum category, GLenum severity, GLuint id, GLsizei length, const GLchar *buf); +GLAPI void APIENTRY glDebugMessageCallbackAMD (GLDEBUGPROCAMD callback, GLvoid *userParam); +GLAPI GLuint APIENTRY glGetDebugMessageLogAMD (GLuint count, GLsizei bufsize, GLenum *categories, GLuint *severities, GLuint *ids, GLsizei *lengths, GLchar *message); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEBUGMESSAGEENABLEAMDPROC) (GLenum category, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); +typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTAMDPROC) (GLenum category, GLenum severity, GLuint id, GLsizei length, const GLchar *buf); +typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKAMDPROC) (GLDEBUGPROCAMD callback, GLvoid *userParam); +typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGAMDPROC) (GLuint count, GLsizei bufsize, GLenum *categories, GLuint *severities, GLuint *ids, GLsizei *lengths, GLchar *message); +#endif + +#ifndef GL_NV_vdpau_interop +#define GL_NV_vdpau_interop 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVDPAUInitNV (const GLvoid *vdpDevice, const GLvoid *getProcAddress); +GLAPI void APIENTRY glVDPAUFiniNV (void); +GLAPI GLvdpauSurfaceNV APIENTRY glVDPAURegisterVideoSurfaceNV (GLvoid *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); +GLAPI GLvdpauSurfaceNV APIENTRY glVDPAURegisterOutputSurfaceNV (GLvoid *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); +GLAPI void APIENTRY glVDPAUIsSurfaceNV (GLvdpauSurfaceNV surface); +GLAPI void APIENTRY glVDPAUUnregisterSurfaceNV (GLvdpauSurfaceNV surface); +GLAPI void APIENTRY glVDPAUGetSurfaceivNV (GLvdpauSurfaceNV surface, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +GLAPI void APIENTRY glVDPAUSurfaceAccessNV (GLvdpauSurfaceNV surface, GLenum access); +GLAPI void APIENTRY glVDPAUMapSurfacesNV (GLsizei numSurfaces, const GLvdpauSurfaceNV *surfaces); +GLAPI void APIENTRY glVDPAUUnmapSurfacesNV (GLsizei numSurface, const GLvdpauSurfaceNV *surfaces); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVDPAUINITNVPROC) (const GLvoid *vdpDevice, const GLvoid *getProcAddress); +typedef void (APIENTRYP PFNGLVDPAUFININVPROC) (void); +typedef GLvdpauSurfaceNV (APIENTRYP PFNGLVDPAUREGISTERVIDEOSURFACENVPROC) (GLvoid *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); +typedef GLvdpauSurfaceNV (APIENTRYP PFNGLVDPAUREGISTEROUTPUTSURFACENVPROC) (GLvoid *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames); +typedef void (APIENTRYP PFNGLVDPAUISSURFACENVPROC) (GLvdpauSurfaceNV surface); +typedef void (APIENTRYP PFNGLVDPAUUNREGISTERSURFACENVPROC) (GLvdpauSurfaceNV surface); +typedef void (APIENTRYP PFNGLVDPAUGETSURFACEIVNVPROC) (GLvdpauSurfaceNV surface, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +typedef void (APIENTRYP PFNGLVDPAUSURFACEACCESSNVPROC) (GLvdpauSurfaceNV surface, GLenum access); +typedef void (APIENTRYP PFNGLVDPAUMAPSURFACESNVPROC) (GLsizei numSurfaces, const GLvdpauSurfaceNV *surfaces); +typedef void (APIENTRYP PFNGLVDPAUUNMAPSURFACESNVPROC) (GLsizei numSurface, const GLvdpauSurfaceNV *surfaces); +#endif + +#ifndef GL_AMD_transform_feedback3_lines_triangles +#define GL_AMD_transform_feedback3_lines_triangles 1 +#endif + +#ifndef GL_AMD_depth_clamp_separate +#define GL_AMD_depth_clamp_separate 1 +#endif + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/GL/glfbdev.h b/include/GL/glfbdev.h new file mode 100644 index 0000000..452a643 --- /dev/null +++ b/include/GL/glfbdev.h @@ -0,0 +1,152 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 1999-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. + */ + + +#ifndef GLFBDEV_H +#define GLFBDEV_H + + +/* for size_t */ +#include + +/* avoid including linux/fb.h */ +struct fb_fix_screeninfo; +struct fb_var_screeninfo; + + +/* public types */ +typedef struct GLFBDevVisualRec *GLFBDevVisualPtr; +typedef struct GLFBDevBufferRec *GLFBDevBufferPtr; +typedef struct GLFBDevContextRec *GLFBDevContextPtr; + + +/* API version */ +#define GLFBDEV_VERSION_1_0 1 + + +/* For glFBDevCreateVisual */ +#define GLFBDEV_DOUBLE_BUFFER 100 +#define GLFBDEV_COLOR_INDEX 101 +#define GLFBDEV_DEPTH_SIZE 102 +#define GLFBDEV_STENCIL_SIZE 103 +#define GLFBDEV_ACCUM_SIZE 104 +#define GLFBDEV_LEVEL 105 +#define GLFBDEV_MULTISAMPLE 106 +#define GLFBDEV_NONE 0 + +/* For glFBDevGetString */ +#define GLFBDEV_VERSION 200 +#define GLFBDEV_VENDOR 201 + + +/* Misc functions */ + +extern const char * +glFBDevGetString( int str ); + + +typedef void (*GLFBDevProc)(); + + +extern GLFBDevProc +glFBDevGetProcAddress( const char *procName ); + + + +/** + * Create a GLFBDevVisual. + * \param fixInfo - needed to get the visual types, etc. + * \param varInfo - needed to get the bits_per_pixel, etc. + * \param attribs - for requesting depth, stencil, accum buffers, etc. + */ +extern GLFBDevVisualPtr +glFBDevCreateVisual( const struct fb_fix_screeninfo *fixInfo, + const struct fb_var_screeninfo *varInfo, + const int *attribs ); + +extern void +glFBDevDestroyVisual( GLFBDevVisualPtr visual ); + +extern int +glFBDevGetVisualAttrib( const GLFBDevVisualPtr visual, int attrib); + + + +/** + * Create a GLFBDevBuffer. + * \param fixInfo, varInfo - needed in order to get the screen size + * (resolution), etc. + * \param visual - as returned by glFBDevCreateVisual() + * \param frontBuffer - address of front color buffer + * \param backBuffer - address of back color buffer (may be NULL) + * \param size - size of the color buffer(s) in bytes. + */ +extern GLFBDevBufferPtr +glFBDevCreateBuffer( const struct fb_fix_screeninfo *fixInfo, + const struct fb_var_screeninfo *varInfo, + const GLFBDevVisualPtr visual, + void *frontBuffer, void *backBuffer, size_t size ); + +extern void +glFBDevDestroyBuffer( GLFBDevBufferPtr buffer ); + +extern int +glFBDevGetBufferAttrib( const GLFBDevBufferPtr buffer, int attrib); + +extern GLFBDevBufferPtr +glFBDevGetCurrentDrawBuffer( void ); + +extern GLFBDevBufferPtr +glFBDevGetCurrentReadBuffer( void ); + +extern void +glFBDevSwapBuffers( GLFBDevBufferPtr buffer ); + + + +/** + * Create a GLFBDevContext. + * \param visual - as created by glFBDevCreateVisual. + * \param share - specifies another context with which to share textures, + * display lists, etc. (may be NULL). + */ +extern GLFBDevContextPtr +glFBDevCreateContext( const GLFBDevVisualPtr visual, GLFBDevContextPtr share ); + +extern void +glFBDevDestroyContext( GLFBDevContextPtr context ); + +extern int +glFBDevGetContextAttrib( const GLFBDevContextPtr context, int attrib); + +extern GLFBDevContextPtr +glFBDevGetCurrentContext( void ); + +extern int +glFBDevMakeCurrent( GLFBDevContextPtr context, + GLFBDevBufferPtr drawBuffer, + GLFBDevBufferPtr readBuffer ); + + +#endif /* GLFBDEV_H */ diff --git a/include/GL/glu.h b/include/GL/glu.h new file mode 100644 index 0000000..cd967ac --- /dev/null +++ b/include/GL/glu.h @@ -0,0 +1,353 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#ifndef __glu_h__ +#define __glu_h__ + +#if defined(USE_MGL_NAMESPACE) +#include "glu_mangle.h" +#endif + +#include + +#ifndef GLAPIENTRY +#if defined(_MSC_VER) || defined(__MINGW32__) +#define GLAPIENTRY __stdcall +#else +#define GLAPIENTRY +#endif +#endif + +#ifndef GLAPIENTRYP +#define GLAPIENTRYP GLAPIENTRY * +#endif + +#if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(BUILD_GLU32) +# undef GLAPI +# define GLAPI __declspec(dllexport) +#elif (defined(_MSC_VER) || defined(__MINGW32__)) && defined(_DLL) +/* tag specifying we're building for DLL runtime support */ +# undef GLAPI +# define GLAPI __declspec(dllimport) +#elif !defined(GLAPI) +/* for use with static link lib build of Win32 edition only */ +# define GLAPI extern +#endif /* _STATIC_MESA support */ + +#ifdef __cplusplus +extern "C" { +#endif + +/*************************************************************/ + +/* Extensions */ +#define GLU_EXT_object_space_tess 1 +#define GLU_EXT_nurbs_tessellator 1 + +/* Boolean */ +#define GLU_FALSE 0 +#define GLU_TRUE 1 + +/* Version */ +#define GLU_VERSION_1_1 1 +#define GLU_VERSION_1_2 1 +#define GLU_VERSION_1_3 1 + +/* StringName */ +#define GLU_VERSION 100800 +#define GLU_EXTENSIONS 100801 + +/* ErrorCode */ +#define GLU_INVALID_ENUM 100900 +#define GLU_INVALID_VALUE 100901 +#define GLU_OUT_OF_MEMORY 100902 +#define GLU_INCOMPATIBLE_GL_VERSION 100903 +#define GLU_INVALID_OPERATION 100904 + +/* NurbsDisplay */ +/* GLU_FILL */ +#define GLU_OUTLINE_POLYGON 100240 +#define GLU_OUTLINE_PATCH 100241 + +/* NurbsCallback */ +#define GLU_NURBS_ERROR 100103 +#define GLU_ERROR 100103 +#define GLU_NURBS_BEGIN 100164 +#define GLU_NURBS_BEGIN_EXT 100164 +#define GLU_NURBS_VERTEX 100165 +#define GLU_NURBS_VERTEX_EXT 100165 +#define GLU_NURBS_NORMAL 100166 +#define GLU_NURBS_NORMAL_EXT 100166 +#define GLU_NURBS_COLOR 100167 +#define GLU_NURBS_COLOR_EXT 100167 +#define GLU_NURBS_TEXTURE_COORD 100168 +#define GLU_NURBS_TEX_COORD_EXT 100168 +#define GLU_NURBS_END 100169 +#define GLU_NURBS_END_EXT 100169 +#define GLU_NURBS_BEGIN_DATA 100170 +#define GLU_NURBS_BEGIN_DATA_EXT 100170 +#define GLU_NURBS_VERTEX_DATA 100171 +#define GLU_NURBS_VERTEX_DATA_EXT 100171 +#define GLU_NURBS_NORMAL_DATA 100172 +#define GLU_NURBS_NORMAL_DATA_EXT 100172 +#define GLU_NURBS_COLOR_DATA 100173 +#define GLU_NURBS_COLOR_DATA_EXT 100173 +#define GLU_NURBS_TEXTURE_COORD_DATA 100174 +#define GLU_NURBS_TEX_COORD_DATA_EXT 100174 +#define GLU_NURBS_END_DATA 100175 +#define GLU_NURBS_END_DATA_EXT 100175 + +/* NurbsError */ +#define GLU_NURBS_ERROR1 100251 +#define GLU_NURBS_ERROR2 100252 +#define GLU_NURBS_ERROR3 100253 +#define GLU_NURBS_ERROR4 100254 +#define GLU_NURBS_ERROR5 100255 +#define GLU_NURBS_ERROR6 100256 +#define GLU_NURBS_ERROR7 100257 +#define GLU_NURBS_ERROR8 100258 +#define GLU_NURBS_ERROR9 100259 +#define GLU_NURBS_ERROR10 100260 +#define GLU_NURBS_ERROR11 100261 +#define GLU_NURBS_ERROR12 100262 +#define GLU_NURBS_ERROR13 100263 +#define GLU_NURBS_ERROR14 100264 +#define GLU_NURBS_ERROR15 100265 +#define GLU_NURBS_ERROR16 100266 +#define GLU_NURBS_ERROR17 100267 +#define GLU_NURBS_ERROR18 100268 +#define GLU_NURBS_ERROR19 100269 +#define GLU_NURBS_ERROR20 100270 +#define GLU_NURBS_ERROR21 100271 +#define GLU_NURBS_ERROR22 100272 +#define GLU_NURBS_ERROR23 100273 +#define GLU_NURBS_ERROR24 100274 +#define GLU_NURBS_ERROR25 100275 +#define GLU_NURBS_ERROR26 100276 +#define GLU_NURBS_ERROR27 100277 +#define GLU_NURBS_ERROR28 100278 +#define GLU_NURBS_ERROR29 100279 +#define GLU_NURBS_ERROR30 100280 +#define GLU_NURBS_ERROR31 100281 +#define GLU_NURBS_ERROR32 100282 +#define GLU_NURBS_ERROR33 100283 +#define GLU_NURBS_ERROR34 100284 +#define GLU_NURBS_ERROR35 100285 +#define GLU_NURBS_ERROR36 100286 +#define GLU_NURBS_ERROR37 100287 + +/* NurbsProperty */ +#define GLU_AUTO_LOAD_MATRIX 100200 +#define GLU_CULLING 100201 +#define GLU_SAMPLING_TOLERANCE 100203 +#define GLU_DISPLAY_MODE 100204 +#define GLU_PARAMETRIC_TOLERANCE 100202 +#define GLU_SAMPLING_METHOD 100205 +#define GLU_U_STEP 100206 +#define GLU_V_STEP 100207 +#define GLU_NURBS_MODE 100160 +#define GLU_NURBS_MODE_EXT 100160 +#define GLU_NURBS_TESSELLATOR 100161 +#define GLU_NURBS_TESSELLATOR_EXT 100161 +#define GLU_NURBS_RENDERER 100162 +#define GLU_NURBS_RENDERER_EXT 100162 + +/* NurbsSampling */ +#define GLU_OBJECT_PARAMETRIC_ERROR 100208 +#define GLU_OBJECT_PARAMETRIC_ERROR_EXT 100208 +#define GLU_OBJECT_PATH_LENGTH 100209 +#define GLU_OBJECT_PATH_LENGTH_EXT 100209 +#define GLU_PATH_LENGTH 100215 +#define GLU_PARAMETRIC_ERROR 100216 +#define GLU_DOMAIN_DISTANCE 100217 + +/* NurbsTrim */ +#define GLU_MAP1_TRIM_2 100210 +#define GLU_MAP1_TRIM_3 100211 + +/* QuadricDrawStyle */ +#define GLU_POINT 100010 +#define GLU_LINE 100011 +#define GLU_FILL 100012 +#define GLU_SILHOUETTE 100013 + +/* QuadricCallback */ +/* GLU_ERROR */ + +/* QuadricNormal */ +#define GLU_SMOOTH 100000 +#define GLU_FLAT 100001 +#define GLU_NONE 100002 + +/* QuadricOrientation */ +#define GLU_OUTSIDE 100020 +#define GLU_INSIDE 100021 + +/* TessCallback */ +#define GLU_TESS_BEGIN 100100 +#define GLU_BEGIN 100100 +#define GLU_TESS_VERTEX 100101 +#define GLU_VERTEX 100101 +#define GLU_TESS_END 100102 +#define GLU_END 100102 +#define GLU_TESS_ERROR 100103 +#define GLU_TESS_EDGE_FLAG 100104 +#define GLU_EDGE_FLAG 100104 +#define GLU_TESS_COMBINE 100105 +#define GLU_TESS_BEGIN_DATA 100106 +#define GLU_TESS_VERTEX_DATA 100107 +#define GLU_TESS_END_DATA 100108 +#define GLU_TESS_ERROR_DATA 100109 +#define GLU_TESS_EDGE_FLAG_DATA 100110 +#define GLU_TESS_COMBINE_DATA 100111 + +/* TessContour */ +#define GLU_CW 100120 +#define GLU_CCW 100121 +#define GLU_INTERIOR 100122 +#define GLU_EXTERIOR 100123 +#define GLU_UNKNOWN 100124 + +/* TessProperty */ +#define GLU_TESS_WINDING_RULE 100140 +#define GLU_TESS_BOUNDARY_ONLY 100141 +#define GLU_TESS_TOLERANCE 100142 + +/* TessError */ +#define GLU_TESS_ERROR1 100151 +#define GLU_TESS_ERROR2 100152 +#define GLU_TESS_ERROR3 100153 +#define GLU_TESS_ERROR4 100154 +#define GLU_TESS_ERROR5 100155 +#define GLU_TESS_ERROR6 100156 +#define GLU_TESS_ERROR7 100157 +#define GLU_TESS_ERROR8 100158 +#define GLU_TESS_MISSING_BEGIN_POLYGON 100151 +#define GLU_TESS_MISSING_BEGIN_CONTOUR 100152 +#define GLU_TESS_MISSING_END_POLYGON 100153 +#define GLU_TESS_MISSING_END_CONTOUR 100154 +#define GLU_TESS_COORD_TOO_LARGE 100155 +#define GLU_TESS_NEED_COMBINE_CALLBACK 100156 + +/* TessWinding */ +#define GLU_TESS_WINDING_ODD 100130 +#define GLU_TESS_WINDING_NONZERO 100131 +#define GLU_TESS_WINDING_POSITIVE 100132 +#define GLU_TESS_WINDING_NEGATIVE 100133 +#define GLU_TESS_WINDING_ABS_GEQ_TWO 100134 + +/*************************************************************/ + + +#ifdef __cplusplus +class GLUnurbs; +class GLUquadric; +class GLUtesselator; +#else +typedef struct GLUnurbs GLUnurbs; +typedef struct GLUquadric GLUquadric; +typedef struct GLUtesselator GLUtesselator; +#endif + +typedef GLUnurbs GLUnurbsObj; +typedef GLUquadric GLUquadricObj; +typedef GLUtesselator GLUtesselatorObj; +typedef GLUtesselator GLUtriangulatorObj; + +#define GLU_TESS_MAX_COORD 1.0e150 + +/* Internal convenience typedefs */ +typedef void (GLAPIENTRYP _GLUfuncptr)(); + +GLAPI void GLAPIENTRY gluBeginCurve (GLUnurbs* nurb); +GLAPI void GLAPIENTRY gluBeginPolygon (GLUtesselator* tess); +GLAPI void GLAPIENTRY gluBeginSurface (GLUnurbs* nurb); +GLAPI void GLAPIENTRY gluBeginTrim (GLUnurbs* nurb); +GLAPI GLint GLAPIENTRY gluBuild1DMipmapLevels (GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void *data); +GLAPI GLint GLAPIENTRY gluBuild1DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void *data); +GLAPI GLint GLAPIENTRY gluBuild2DMipmapLevels (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void *data); +GLAPI GLint GLAPIENTRY gluBuild2DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *data); +GLAPI GLint GLAPIENTRY gluBuild3DMipmapLevels (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void *data); +GLAPI GLint GLAPIENTRY gluBuild3DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *data); +GLAPI GLboolean GLAPIENTRY gluCheckExtension (const GLubyte *extName, const GLubyte *extString); +GLAPI void GLAPIENTRY gluCylinder (GLUquadric* quad, GLdouble base, GLdouble top, GLdouble height, GLint slices, GLint stacks); +GLAPI void GLAPIENTRY gluDeleteNurbsRenderer (GLUnurbs* nurb); +GLAPI void GLAPIENTRY gluDeleteQuadric (GLUquadric* quad); +GLAPI void GLAPIENTRY gluDeleteTess (GLUtesselator* tess); +GLAPI void GLAPIENTRY gluDisk (GLUquadric* quad, GLdouble inner, GLdouble outer, GLint slices, GLint loops); +GLAPI void GLAPIENTRY gluEndCurve (GLUnurbs* nurb); +GLAPI void GLAPIENTRY gluEndPolygon (GLUtesselator* tess); +GLAPI void GLAPIENTRY gluEndSurface (GLUnurbs* nurb); +GLAPI void GLAPIENTRY gluEndTrim (GLUnurbs* nurb); +GLAPI const GLubyte * GLAPIENTRY gluErrorString (GLenum error); +GLAPI void GLAPIENTRY gluGetNurbsProperty (GLUnurbs* nurb, GLenum property, GLfloat* data); +GLAPI const GLubyte * GLAPIENTRY gluGetString (GLenum name); +GLAPI void GLAPIENTRY gluGetTessProperty (GLUtesselator* tess, GLenum which, GLdouble* data); +GLAPI void GLAPIENTRY gluLoadSamplingMatrices (GLUnurbs* nurb, const GLfloat *model, const GLfloat *perspective, const GLint *view); +GLAPI void GLAPIENTRY gluLookAt (GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLdouble centerZ, GLdouble upX, GLdouble upY, GLdouble upZ); +GLAPI GLUnurbs* GLAPIENTRY gluNewNurbsRenderer (void); +GLAPI GLUquadric* GLAPIENTRY gluNewQuadric (void); +GLAPI GLUtesselator* GLAPIENTRY gluNewTess (void); +GLAPI void GLAPIENTRY gluNextContour (GLUtesselator* tess, GLenum type); +GLAPI void GLAPIENTRY gluNurbsCallback (GLUnurbs* nurb, GLenum which, _GLUfuncptr CallBackFunc); +GLAPI void GLAPIENTRY gluNurbsCallbackData (GLUnurbs* nurb, GLvoid* userData); +GLAPI void GLAPIENTRY gluNurbsCallbackDataEXT (GLUnurbs* nurb, GLvoid* userData); +GLAPI void GLAPIENTRY gluNurbsCurve (GLUnurbs* nurb, GLint knotCount, GLfloat *knots, GLint stride, GLfloat *control, GLint order, GLenum type); +GLAPI void GLAPIENTRY gluNurbsProperty (GLUnurbs* nurb, GLenum property, GLfloat value); +GLAPI void GLAPIENTRY gluNurbsSurface (GLUnurbs* nurb, GLint sKnotCount, GLfloat* sKnots, GLint tKnotCount, GLfloat* tKnots, GLint sStride, GLint tStride, GLfloat* control, GLint sOrder, GLint tOrder, GLenum type); +GLAPI void GLAPIENTRY gluOrtho2D (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top); +GLAPI void GLAPIENTRY gluPartialDisk (GLUquadric* quad, GLdouble inner, GLdouble outer, GLint slices, GLint loops, GLdouble start, GLdouble sweep); +GLAPI void GLAPIENTRY gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); +GLAPI void GLAPIENTRY gluPickMatrix (GLdouble x, GLdouble y, GLdouble delX, GLdouble delY, GLint *viewport); +GLAPI GLint GLAPIENTRY gluProject (GLdouble objX, GLdouble objY, GLdouble objZ, const GLdouble *model, const GLdouble *proj, const GLint *view, GLdouble* winX, GLdouble* winY, GLdouble* winZ); +GLAPI void GLAPIENTRY gluPwlCurve (GLUnurbs* nurb, GLint count, GLfloat* data, GLint stride, GLenum type); +GLAPI void GLAPIENTRY gluQuadricCallback (GLUquadric* quad, GLenum which, _GLUfuncptr CallBackFunc); +GLAPI void GLAPIENTRY gluQuadricDrawStyle (GLUquadric* quad, GLenum draw); +GLAPI void GLAPIENTRY gluQuadricNormals (GLUquadric* quad, GLenum normal); +GLAPI void GLAPIENTRY gluQuadricOrientation (GLUquadric* quad, GLenum orientation); +GLAPI void GLAPIENTRY gluQuadricTexture (GLUquadric* quad, GLboolean texture); +GLAPI GLint GLAPIENTRY gluScaleImage (GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void *dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid* dataOut); +GLAPI void GLAPIENTRY gluSphere (GLUquadric* quad, GLdouble radius, GLint slices, GLint stacks); +GLAPI void GLAPIENTRY gluTessBeginContour (GLUtesselator* tess); +GLAPI void GLAPIENTRY gluTessBeginPolygon (GLUtesselator* tess, GLvoid* data); +GLAPI void GLAPIENTRY gluTessCallback (GLUtesselator* tess, GLenum which, _GLUfuncptr CallBackFunc); +GLAPI void GLAPIENTRY gluTessEndContour (GLUtesselator* tess); +GLAPI void GLAPIENTRY gluTessEndPolygon (GLUtesselator* tess); +GLAPI void GLAPIENTRY gluTessNormal (GLUtesselator* tess, GLdouble valueX, GLdouble valueY, GLdouble valueZ); +GLAPI void GLAPIENTRY gluTessProperty (GLUtesselator* tess, GLenum which, GLdouble data); +GLAPI void GLAPIENTRY gluTessVertex (GLUtesselator* tess, GLdouble *location, GLvoid* data); +GLAPI GLint GLAPIENTRY gluUnProject (GLdouble winX, GLdouble winY, GLdouble winZ, const GLdouble *model, const GLdouble *proj, const GLint *view, GLdouble* objX, GLdouble* objY, GLdouble* objZ); +GLAPI GLint GLAPIENTRY gluUnProject4 (GLdouble winX, GLdouble winY, GLdouble winZ, GLdouble clipW, const GLdouble *model, const GLdouble *proj, const GLint *view, GLdouble nearVal, GLdouble farVal, GLdouble* objX, GLdouble* objY, GLdouble* objZ, GLdouble* objW); + +#ifdef __cplusplus +} +#endif + +#endif /* __glu_h__ */ diff --git a/include/GL/glu_mangle.h b/include/GL/glu_mangle.h new file mode 100644 index 0000000..9c25aa8 --- /dev/null +++ b/include/GL/glu_mangle.h @@ -0,0 +1,86 @@ +/* + * Mesa 3-D graphics library + * Version: 3.0 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#ifndef GLU_MANGLE_H +#define GLU_MANGLE_H + + +#define gluLookAt mgluLookAt +#define gluOrtho2D mgluOrtho2D +#define gluPerspective mgluPerspective +#define gluPickMatrix mgluPickMatrix +#define gluProject mgluProject +#define gluUnProject mgluUnProject +#define gluErrorString mgluErrorString +#define gluScaleImage mgluScaleImage +#define gluBuild1DMipmaps mgluBuild1DMipmaps +#define gluBuild2DMipmaps mgluBuild2DMipmaps +#define gluNewQuadric mgluNewQuadric +#define gluDeleteQuadric mgluDeleteQuadric +#define gluQuadricDrawStyle mgluQuadricDrawStyle +#define gluQuadricOrientation mgluQuadricOrientation +#define gluQuadricNormals mgluQuadricNormals +#define gluQuadricTexture mgluQuadricTexture +#define gluQuadricCallback mgluQuadricCallback +#define gluCylinder mgluCylinder +#define gluSphere mgluSphere +#define gluDisk mgluDisk +#define gluPartialDisk mgluPartialDisk +#define gluNewNurbsRenderer mgluNewNurbsRenderer +#define gluDeleteNurbsRenderer mgluDeleteNurbsRenderer +#define gluLoadSamplingMatrices mgluLoadSamplingMatrices +#define gluNurbsProperty mgluNurbsProperty +#define gluGetNurbsProperty mgluGetNurbsProperty +#define gluBeginCurve mgluBeginCurve +#define gluEndCurve mgluEndCurve +#define gluNurbsCurve mgluNurbsCurve +#define gluBeginSurface mgluBeginSurface +#define gluEndSurface mgluEndSurface +#define gluNurbsSurface mgluNurbsSurface +#define gluBeginTrim mgluBeginTrim +#define gluEndTrim mgluEndTrim +#define gluPwlCurve mgluPwlCurve +#define gluNurbsCallback mgluNurbsCallback +#define gluNewTess mgluNewTess +#define gluDeleteTess mgluDeleteTess +#define gluTessBeginPolygon mgluTessBeginPolygon +#define gluTessBeginContour mgluTessBeginContour +#define gluTessVertex mgluTessVertex +#define gluTessEndPolygon mgluTessEndPolygon +#define gluTessEndContour mgluTessEndContour +#define gluTessProperty mgluTessProperty +#define gluTessNormal mgluTessNormal +#define gluTessCallback mgluTessCallback +#define gluGetTessProperty mgluGetTessProperty +#define gluBeginPolygon mgluBeginPolygon +#define gluNextContour mgluNextContour +#define gluEndPolygon mgluEndPolygon +#define gluGetString mgluGetString +#define gluBuild1DMipmapLevels mgluBuild1DMipmapLevels +#define gluBuild2DMipmapLevels mgluBuild2DMipmapLevels +#define gluBuild3DMipmapLevels mgluBuild3DMipmapLevels +#define gluBuild3DMipmaps mgluBuild3DMipmaps +#define gluCheckExtension mgluCheckExtension +#define gluUnProject4 mgluUnProject4 +#define gluNurbsCallbackData mgluNurbsCallbackData +#define gluNurbsCallbackDataEXT mgluNurbsCallbackDataEXT + +#endif diff --git a/include/GL/glx.h b/include/GL/glx.h new file mode 100644 index 0000000..a3a7d97 --- /dev/null +++ b/include/GL/glx.h @@ -0,0 +1,526 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 1999-2006 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. + */ + + +#ifndef GLX_H +#define GLX_H + + +#ifdef __VMS +#include +# ifdef __cplusplus +/* VMS Xlib.h gives problems with C++. + * this avoids a bunch of trivial warnings */ +#pragma message disable nosimpint +#endif +#endif +#include +#include +#ifdef __VMS +# ifdef __cplusplus +#pragma message enable nosimpint +#endif +#endif +#include + + +#if defined(USE_MGL_NAMESPACE) +#include "glx_mangle.h" +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define GLX_VERSION_1_1 1 +#define GLX_VERSION_1_2 1 +#define GLX_VERSION_1_3 1 +#define GLX_VERSION_1_4 1 + +#define GLX_EXTENSION_NAME "GLX" + + + +/* + * Tokens for glXChooseVisual and glXGetConfig: + */ +#define GLX_USE_GL 1 +#define GLX_BUFFER_SIZE 2 +#define GLX_LEVEL 3 +#define GLX_RGBA 4 +#define GLX_DOUBLEBUFFER 5 +#define GLX_STEREO 6 +#define GLX_AUX_BUFFERS 7 +#define GLX_RED_SIZE 8 +#define GLX_GREEN_SIZE 9 +#define GLX_BLUE_SIZE 10 +#define GLX_ALPHA_SIZE 11 +#define GLX_DEPTH_SIZE 12 +#define GLX_STENCIL_SIZE 13 +#define GLX_ACCUM_RED_SIZE 14 +#define GLX_ACCUM_GREEN_SIZE 15 +#define GLX_ACCUM_BLUE_SIZE 16 +#define GLX_ACCUM_ALPHA_SIZE 17 + + +/* + * Error codes returned by glXGetConfig: + */ +#define GLX_BAD_SCREEN 1 +#define GLX_BAD_ATTRIBUTE 2 +#define GLX_NO_EXTENSION 3 +#define GLX_BAD_VISUAL 4 +#define GLX_BAD_CONTEXT 5 +#define GLX_BAD_VALUE 6 +#define GLX_BAD_ENUM 7 + + +/* + * GLX 1.1 and later: + */ +#define GLX_VENDOR 1 +#define GLX_VERSION 2 +#define GLX_EXTENSIONS 3 + + +/* + * GLX 1.3 and later: + */ +#define GLX_CONFIG_CAVEAT 0x20 +#define GLX_DONT_CARE 0xFFFFFFFF +#define GLX_X_VISUAL_TYPE 0x22 +#define GLX_TRANSPARENT_TYPE 0x23 +#define GLX_TRANSPARENT_INDEX_VALUE 0x24 +#define GLX_TRANSPARENT_RED_VALUE 0x25 +#define GLX_TRANSPARENT_GREEN_VALUE 0x26 +#define GLX_TRANSPARENT_BLUE_VALUE 0x27 +#define GLX_TRANSPARENT_ALPHA_VALUE 0x28 +#define GLX_WINDOW_BIT 0x00000001 +#define GLX_PIXMAP_BIT 0x00000002 +#define GLX_PBUFFER_BIT 0x00000004 +#define GLX_AUX_BUFFERS_BIT 0x00000010 +#define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001 +#define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002 +#define GLX_BACK_LEFT_BUFFER_BIT 0x00000004 +#define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008 +#define GLX_DEPTH_BUFFER_BIT 0x00000020 +#define GLX_STENCIL_BUFFER_BIT 0x00000040 +#define GLX_ACCUM_BUFFER_BIT 0x00000080 +#define GLX_NONE 0x8000 +#define GLX_SLOW_CONFIG 0x8001 +#define GLX_TRUE_COLOR 0x8002 +#define GLX_DIRECT_COLOR 0x8003 +#define GLX_PSEUDO_COLOR 0x8004 +#define GLX_STATIC_COLOR 0x8005 +#define GLX_GRAY_SCALE 0x8006 +#define GLX_STATIC_GRAY 0x8007 +#define GLX_TRANSPARENT_RGB 0x8008 +#define GLX_TRANSPARENT_INDEX 0x8009 +#define GLX_VISUAL_ID 0x800B +#define GLX_SCREEN 0x800C +#define GLX_NON_CONFORMANT_CONFIG 0x800D +#define GLX_DRAWABLE_TYPE 0x8010 +#define GLX_RENDER_TYPE 0x8011 +#define GLX_X_RENDERABLE 0x8012 +#define GLX_FBCONFIG_ID 0x8013 +#define GLX_RGBA_TYPE 0x8014 +#define GLX_COLOR_INDEX_TYPE 0x8015 +#define GLX_MAX_PBUFFER_WIDTH 0x8016 +#define GLX_MAX_PBUFFER_HEIGHT 0x8017 +#define GLX_MAX_PBUFFER_PIXELS 0x8018 +#define GLX_PRESERVED_CONTENTS 0x801B +#define GLX_LARGEST_PBUFFER 0x801C +#define GLX_WIDTH 0x801D +#define GLX_HEIGHT 0x801E +#define GLX_EVENT_MASK 0x801F +#define GLX_DAMAGED 0x8020 +#define GLX_SAVED 0x8021 +#define GLX_WINDOW 0x8022 +#define GLX_PBUFFER 0x8023 +#define GLX_PBUFFER_HEIGHT 0x8040 +#define GLX_PBUFFER_WIDTH 0x8041 +#define GLX_RGBA_BIT 0x00000001 +#define GLX_COLOR_INDEX_BIT 0x00000002 +#define GLX_PBUFFER_CLOBBER_MASK 0x08000000 + + +/* + * GLX 1.4 and later: + */ +#define GLX_SAMPLE_BUFFERS 0x186a0 /*100000*/ +#define GLX_SAMPLES 0x186a1 /*100001*/ + + + +typedef struct __GLXcontextRec *GLXContext; +typedef XID GLXPixmap; +typedef XID GLXDrawable; +/* GLX 1.3 and later */ +typedef struct __GLXFBConfigRec *GLXFBConfig; +typedef XID GLXFBConfigID; +typedef XID GLXContextID; +typedef XID GLXWindow; +typedef XID GLXPbuffer; + + +/* +** Events. +** __GLX_NUMBER_EVENTS is set to 17 to account for the BufferClobberSGIX +** event - this helps initialization if the server supports the pbuffer +** extension and the client doesn't. +*/ +#define GLX_PbufferClobber 0 +#define GLX_BufferSwapComplete 1 + +#define __GLX_NUMBER_EVENTS 17 + +extern XVisualInfo* glXChooseVisual( Display *dpy, int screen, + int *attribList ); + +extern GLXContext glXCreateContext( Display *dpy, XVisualInfo *vis, + GLXContext shareList, Bool direct ); + +extern void glXDestroyContext( Display *dpy, GLXContext ctx ); + +extern Bool glXMakeCurrent( Display *dpy, GLXDrawable drawable, + GLXContext ctx); + +extern void glXCopyContext( Display *dpy, GLXContext src, GLXContext dst, + unsigned long mask ); + +extern void glXSwapBuffers( Display *dpy, GLXDrawable drawable ); + +extern GLXPixmap glXCreateGLXPixmap( Display *dpy, XVisualInfo *visual, + Pixmap pixmap ); + +extern void glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap ); + +extern Bool glXQueryExtension( Display *dpy, int *errorb, int *event ); + +extern Bool glXQueryVersion( Display *dpy, int *maj, int *min ); + +extern Bool glXIsDirect( Display *dpy, GLXContext ctx ); + +extern int glXGetConfig( Display *dpy, XVisualInfo *visual, + int attrib, int *value ); + +extern GLXContext glXGetCurrentContext( void ); + +extern GLXDrawable glXGetCurrentDrawable( void ); + +extern void glXWaitGL( void ); + +extern void glXWaitX( void ); + +extern void glXUseXFont( Font font, int first, int count, int list ); + + + +/* GLX 1.1 and later */ +extern const char *glXQueryExtensionsString( Display *dpy, int screen ); + +extern const char *glXQueryServerString( Display *dpy, int screen, int name ); + +extern const char *glXGetClientString( Display *dpy, int name ); + + +/* GLX 1.2 and later */ +extern Display *glXGetCurrentDisplay( void ); + + +/* GLX 1.3 and later */ +extern GLXFBConfig *glXChooseFBConfig( Display *dpy, int screen, + const int *attribList, int *nitems ); + +extern int glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config, + int attribute, int *value ); + +extern GLXFBConfig *glXGetFBConfigs( Display *dpy, int screen, + int *nelements ); + +extern XVisualInfo *glXGetVisualFromFBConfig( Display *dpy, + GLXFBConfig config ); + +extern GLXWindow glXCreateWindow( Display *dpy, GLXFBConfig config, + Window win, const int *attribList ); + +extern void glXDestroyWindow( Display *dpy, GLXWindow window ); + +extern GLXPixmap glXCreatePixmap( Display *dpy, GLXFBConfig config, + Pixmap pixmap, const int *attribList ); + +extern void glXDestroyPixmap( Display *dpy, GLXPixmap pixmap ); + +extern GLXPbuffer glXCreatePbuffer( Display *dpy, GLXFBConfig config, + const int *attribList ); + +extern void glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf ); + +extern void glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute, + unsigned int *value ); + +extern GLXContext glXCreateNewContext( Display *dpy, GLXFBConfig config, + int renderType, GLXContext shareList, + Bool direct ); + +extern Bool glXMakeContextCurrent( Display *dpy, GLXDrawable draw, + GLXDrawable read, GLXContext ctx ); + +extern GLXDrawable glXGetCurrentReadDrawable( void ); + +extern int glXQueryContext( Display *dpy, GLXContext ctx, int attribute, + int *value ); + +extern void glXSelectEvent( Display *dpy, GLXDrawable drawable, + unsigned long mask ); + +extern void glXGetSelectedEvent( Display *dpy, GLXDrawable drawable, + unsigned long *mask ); + +/* GLX 1.3 function pointer typedefs */ +typedef GLXFBConfig * (* PFNGLXGETFBCONFIGSPROC) (Display *dpy, int screen, int *nelements); +typedef GLXFBConfig * (* PFNGLXCHOOSEFBCONFIGPROC) (Display *dpy, int screen, const int *attrib_list, int *nelements); +typedef int (* PFNGLXGETFBCONFIGATTRIBPROC) (Display *dpy, GLXFBConfig config, int attribute, int *value); +typedef XVisualInfo * (* PFNGLXGETVISUALFROMFBCONFIGPROC) (Display *dpy, GLXFBConfig config); +typedef GLXWindow (* PFNGLXCREATEWINDOWPROC) (Display *dpy, GLXFBConfig config, Window win, const int *attrib_list); +typedef void (* PFNGLXDESTROYWINDOWPROC) (Display *dpy, GLXWindow win); +typedef GLXPixmap (* PFNGLXCREATEPIXMAPPROC) (Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list); +typedef void (* PFNGLXDESTROYPIXMAPPROC) (Display *dpy, GLXPixmap pixmap); +typedef GLXPbuffer (* PFNGLXCREATEPBUFFERPROC) (Display *dpy, GLXFBConfig config, const int *attrib_list); +typedef void (* PFNGLXDESTROYPBUFFERPROC) (Display *dpy, GLXPbuffer pbuf); +typedef void (* PFNGLXQUERYDRAWABLEPROC) (Display *dpy, GLXDrawable draw, int attribute, unsigned int *value); +typedef GLXContext (* PFNGLXCREATENEWCONTEXTPROC) (Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct); +typedef Bool (* PFNGLXMAKECONTEXTCURRENTPROC) (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); +typedef GLXDrawable (* PFNGLXGETCURRENTREADDRAWABLEPROC) (void); +typedef Display * (* PFNGLXGETCURRENTDISPLAYPROC) (void); +typedef int (* PFNGLXQUERYCONTEXTPROC) (Display *dpy, GLXContext ctx, int attribute, int *value); +typedef void (* PFNGLXSELECTEVENTPROC) (Display *dpy, GLXDrawable draw, unsigned long event_mask); +typedef void (* PFNGLXGETSELECTEDEVENTPROC) (Display *dpy, GLXDrawable draw, unsigned long *event_mask); + + +/* + * ARB 2. GLX_ARB_get_proc_address + */ +#ifndef GLX_ARB_get_proc_address +#define GLX_ARB_get_proc_address 1 + +typedef void (*__GLXextFuncPtr)(void); +extern __GLXextFuncPtr glXGetProcAddressARB (const GLubyte *); + +#endif /* GLX_ARB_get_proc_address */ + + + +/* GLX 1.4 and later */ +extern void (*glXGetProcAddress(const GLubyte *procname))( void ); + +/* GLX 1.4 function pointer typedefs */ +typedef __GLXextFuncPtr (* PFNGLXGETPROCADDRESSPROC) (const GLubyte *procName); + + +#ifndef GLX_GLXEXT_LEGACY + +#include + +#endif /* GLX_GLXEXT_LEGACY */ + + +/** + ** The following aren't in glxext.h yet. + **/ + + +/* + * ???. GLX_NV_vertex_array_range + */ +#ifndef GLX_NV_vertex_array_range +#define GLX_NV_vertex_array_range + +extern void *glXAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority); +extern void glXFreeMemoryNV(GLvoid *pointer); +typedef void * ( * PFNGLXALLOCATEMEMORYNVPROC) (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority); +typedef void ( * PFNGLXFREEMEMORYNVPROC) (GLvoid *pointer); + +#endif /* GLX_NV_vertex_array_range */ + + +/* + * ARB ?. GLX_ARB_render_texture + * XXX This was never finalized! + */ +#ifndef GLX_ARB_render_texture +#define GLX_ARB_render_texture 1 + +extern Bool glXBindTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer); +extern Bool glXReleaseTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer); +extern Bool glXDrawableAttribARB(Display *dpy, GLXDrawable draw, const int *attribList); + +#endif /* GLX_ARB_render_texture */ + + +/* + * Remove this when glxext.h is updated. + */ +#ifndef GLX_NV_float_buffer +#define GLX_NV_float_buffer 1 + +#define GLX_FLOAT_COMPONENTS_NV 0x20B0 + +#endif /* GLX_NV_float_buffer */ + + + +/* + * #?. GLX_MESA_swap_frame_usage + */ +#ifndef GLX_MESA_swap_frame_usage +#define GLX_MESA_swap_frame_usage 1 + +extern int glXGetFrameUsageMESA(Display *dpy, GLXDrawable drawable, float *usage); +extern int glXBeginFrameTrackingMESA(Display *dpy, GLXDrawable drawable); +extern int glXEndFrameTrackingMESA(Display *dpy, GLXDrawable drawable); +extern int glXQueryFrameTrackingMESA(Display *dpy, GLXDrawable drawable, int64_t *swapCount, int64_t *missedFrames, float *lastMissedUsage); + +typedef int (*PFNGLXGETFRAMEUSAGEMESAPROC) (Display *dpy, GLXDrawable drawable, float *usage); +typedef int (*PFNGLXBEGINFRAMETRACKINGMESAPROC)(Display *dpy, GLXDrawable drawable); +typedef int (*PFNGLXENDFRAMETRACKINGMESAPROC)(Display *dpy, GLXDrawable drawable); +typedef int (*PFNGLXQUERYFRAMETRACKINGMESAPROC)(Display *dpy, GLXDrawable drawable, int64_t *swapCount, int64_t *missedFrames, float *lastMissedUsage); + +#endif /* GLX_MESA_swap_frame_usage */ + + + +/* + * #?. GLX_MESA_swap_control + */ +#ifndef GLX_MESA_swap_control +#define GLX_MESA_swap_control 1 + +extern int glXSwapIntervalMESA(unsigned int interval); +extern int glXGetSwapIntervalMESA(void); + +typedef int (*PFNGLXSWAPINTERVALMESAPROC)(unsigned int interval); +typedef int (*PFNGLXGETSWAPINTERVALMESAPROC)(void); + +#endif /* GLX_MESA_swap_control */ + + + +/* + * #?. GLX_EXT_texture_from_pixmap + * XXX not finished? + */ +#ifndef GLX_EXT_texture_from_pixmap +#define GLX_EXT_texture_from_pixmap 1 + +#define GLX_BIND_TO_TEXTURE_RGB_EXT 0x20D0 +#define GLX_BIND_TO_TEXTURE_RGBA_EXT 0x20D1 +#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT 0x20D2 +#define GLX_BIND_TO_TEXTURE_TARGETS_EXT 0x20D3 +#define GLX_Y_INVERTED_EXT 0x20D4 + +#define GLX_TEXTURE_FORMAT_EXT 0x20D5 +#define GLX_TEXTURE_TARGET_EXT 0x20D6 +#define GLX_MIPMAP_TEXTURE_EXT 0x20D7 + +#define GLX_TEXTURE_FORMAT_NONE_EXT 0x20D8 +#define GLX_TEXTURE_FORMAT_RGB_EXT 0x20D9 +#define GLX_TEXTURE_FORMAT_RGBA_EXT 0x20DA + +#define GLX_TEXTURE_1D_BIT_EXT 0x00000001 +#define GLX_TEXTURE_2D_BIT_EXT 0x00000002 +#define GLX_TEXTURE_RECTANGLE_BIT_EXT 0x00000004 + +#define GLX_TEXTURE_1D_EXT 0x20DB +#define GLX_TEXTURE_2D_EXT 0x20DC +#define GLX_TEXTURE_RECTANGLE_EXT 0x20DD + +#define GLX_FRONT_LEFT_EXT 0x20DE +#define GLX_FRONT_RIGHT_EXT 0x20DF +#define GLX_BACK_LEFT_EXT 0x20E0 +#define GLX_BACK_RIGHT_EXT 0x20E1 +#define GLX_FRONT_EXT GLX_FRONT_LEFT_EXT +#define GLX_BACK_EXT GLX_BACK_LEFT_EXT +#define GLX_AUX0_EXT 0x20E2 +#define GLX_AUX1_EXT 0x20E3 +#define GLX_AUX2_EXT 0x20E4 +#define GLX_AUX3_EXT 0x20E5 +#define GLX_AUX4_EXT 0x20E6 +#define GLX_AUX5_EXT 0x20E7 +#define GLX_AUX6_EXT 0x20E8 +#define GLX_AUX7_EXT 0x20E9 +#define GLX_AUX8_EXT 0x20EA +#define GLX_AUX9_EXT 0x20EB + +extern void glXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer, const int *attrib_list); +extern void glXReleaseTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer); + +#endif /* GLX_EXT_texture_from_pixmap */ + + + + +/*** Should these go here, or in another header? */ +/* +** GLX Events +*/ +typedef struct { + int event_type; /* GLX_DAMAGED or GLX_SAVED */ + int draw_type; /* GLX_WINDOW or GLX_PBUFFER */ + unsigned long serial; /* # of last request processed by server */ + Bool send_event; /* true if this came for SendEvent request */ + Display *display; /* display the event was read from */ + GLXDrawable drawable; /* XID of Drawable */ + unsigned int buffer_mask; /* mask indicating which buffers are affected */ + unsigned int aux_buffer; /* which aux buffer was affected */ + int x, y; + int width, height; + int count; /* if nonzero, at least this many more */ +} GLXPbufferClobberEvent; + +typedef struct { + int type; + unsigned long serial; /* # of last request processed by server */ + Bool send_event; /* true if this came from a SendEvent request */ + Display *display; /* Display the event was read from */ + GLXDrawable drawable; /* drawable on which event was requested in event mask */ + int event_type; + int64_t ust; + int64_t msc; + int64_t sbc; +} GLXBufferSwapComplete; + +typedef union __GLXEvent { + GLXPbufferClobberEvent glxpbufferclobber; + GLXBufferSwapComplete glxbufferswapcomplete; + long pad[24]; +} GLXEvent; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/GL/glx_mangle.h b/include/GL/glx_mangle.h new file mode 100644 index 0000000..fa664a7 --- /dev/null +++ b/include/GL/glx_mangle.h @@ -0,0 +1,82 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 1999-2006 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. + */ + + +#ifndef GLX_MANGLE_H +#define GLX_MANGLE_H + +#define glXChooseVisual mglXChooseVisual +#define glXCreateContext mglXCreateContext +#define glXDestroyContext mglXDestroyContext +#define glXMakeCurrent mglXMakeCurrent +#define glXCopyContext mglXCopyContext +#define glXSwapBuffers mglXSwapBuffers +#define glXCreateGLXPixmap mglXCreateGLXPixmap +#define glXDestroyGLXPixmap mglXDestroyGLXPixmap +#define glXQueryExtension mglXQueryExtension +#define glXQueryVersion mglXQueryVersion +#define glXIsDirect mglXIsDirect +#define glXGetConfig mglXGetConfig +#define glXGetCurrentContext mglXGetCurrentContext +#define glXGetCurrentDrawable mglXGetCurrentDrawable +#define glXWaitGL mglXWaitGL +#define glXWaitX mglXWaitX +#define glXUseXFont mglXUseXFont +#define glXQueryExtensionsString mglXQueryExtensionsString +#define glXQueryServerString mglXQueryServerString +#define glXGetClientString mglXGetClientString +#define glXCreateGLXPixmapMESA mglXCreateGLXPixmapMESA +#define glXReleaseBuffersMESA mglXReleaseBuffersMESA +#define glXCopySubBufferMESA mglXCopySubBufferMESA +#define glXGetVideoSyncSGI mglXGetVideoSyncSGI +#define glXWaitVideoSyncSGI mglXWaitVideoSyncSGI + +/* GLX 1.2 */ +#define glXGetCurrentDisplay mglXGetCurrentDisplay + +/* GLX 1.3 */ +#define glXChooseFBConfig mglXChooseFBConfig +#define glXGetFBConfigAttrib mglXGetFBConfigAttrib +#define glXGetFBConfigs mglXGetFBConfigs +#define glXGetVisualFromFBConfig mglXGetVisualFromFBConfig +#define glXCreateWindow mglXCreateWindow +#define glXDestroyWindow mglXDestroyWindow +#define glXCreatePixmap mglXCreatePixmap +#define glXDestroyPixmap mglXDestroyPixmap +#define glXCreatePbuffer mglXCreatePbuffer +#define glXDestroyPbuffer mglXDestroyPbuffer +#define glXQueryDrawable mglXQueryDrawable +#define glXCreateNewContext mglXCreateNewContext +#define glXMakeContextCurrent mglXMakeContextCurrent +#define glXGetCurrentReadDrawable mglXGetCurrentReadDrawable +#define glXQueryContext mglXQueryContext +#define glXSelectEvent mglXSelectEvent +#define glXGetSelectedEvent mglXGetSelectedEvent + +/* GLX 1.4 */ +#define glXGetProcAddress mglXGetProcAddress +#define glXGetProcAddressARB mglXGetProcAddressARB + + +#endif diff --git a/include/GL/glxext.h b/include/GL/glxext.h new file mode 100644 index 0000000..3c47dc3 --- /dev/null +++ b/include/GL/glxext.h @@ -0,0 +1,993 @@ +#ifndef __glxext_h_ +#define __glxext_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2010 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are 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 Materials. +** +** THE MATERIALS ARE 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 +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Function declaration macros - to move into glplatform.h */ + +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif +#ifndef GLAPI +#define GLAPI extern +#endif + +/*************************************************************/ + +/* Header file version number, required by OpenGL ABI for Linux */ +/* glxext.h last updated 2010/08/06 */ +/* Current version at http://www.opengl.org/registry/ */ +#define GLX_GLXEXT_VERSION 32 + +#ifndef GLX_VERSION_1_3 +#define GLX_WINDOW_BIT 0x00000001 +#define GLX_PIXMAP_BIT 0x00000002 +#define GLX_PBUFFER_BIT 0x00000004 +#define GLX_RGBA_BIT 0x00000001 +#define GLX_COLOR_INDEX_BIT 0x00000002 +#define GLX_PBUFFER_CLOBBER_MASK 0x08000000 +#define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001 +#define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002 +#define GLX_BACK_LEFT_BUFFER_BIT 0x00000004 +#define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008 +#define GLX_AUX_BUFFERS_BIT 0x00000010 +#define GLX_DEPTH_BUFFER_BIT 0x00000020 +#define GLX_STENCIL_BUFFER_BIT 0x00000040 +#define GLX_ACCUM_BUFFER_BIT 0x00000080 +#define GLX_CONFIG_CAVEAT 0x20 +#define GLX_X_VISUAL_TYPE 0x22 +#define GLX_TRANSPARENT_TYPE 0x23 +#define GLX_TRANSPARENT_INDEX_VALUE 0x24 +#define GLX_TRANSPARENT_RED_VALUE 0x25 +#define GLX_TRANSPARENT_GREEN_VALUE 0x26 +#define GLX_TRANSPARENT_BLUE_VALUE 0x27 +#define GLX_TRANSPARENT_ALPHA_VALUE 0x28 +#define GLX_DONT_CARE 0xFFFFFFFF +#define GLX_NONE 0x8000 +#define GLX_SLOW_CONFIG 0x8001 +#define GLX_TRUE_COLOR 0x8002 +#define GLX_DIRECT_COLOR 0x8003 +#define GLX_PSEUDO_COLOR 0x8004 +#define GLX_STATIC_COLOR 0x8005 +#define GLX_GRAY_SCALE 0x8006 +#define GLX_STATIC_GRAY 0x8007 +#define GLX_TRANSPARENT_RGB 0x8008 +#define GLX_TRANSPARENT_INDEX 0x8009 +#define GLX_VISUAL_ID 0x800B +#define GLX_SCREEN 0x800C +#define GLX_NON_CONFORMANT_CONFIG 0x800D +#define GLX_DRAWABLE_TYPE 0x8010 +#define GLX_RENDER_TYPE 0x8011 +#define GLX_X_RENDERABLE 0x8012 +#define GLX_FBCONFIG_ID 0x8013 +#define GLX_RGBA_TYPE 0x8014 +#define GLX_COLOR_INDEX_TYPE 0x8015 +#define GLX_MAX_PBUFFER_WIDTH 0x8016 +#define GLX_MAX_PBUFFER_HEIGHT 0x8017 +#define GLX_MAX_PBUFFER_PIXELS 0x8018 +#define GLX_PRESERVED_CONTENTS 0x801B +#define GLX_LARGEST_PBUFFER 0x801C +#define GLX_WIDTH 0x801D +#define GLX_HEIGHT 0x801E +#define GLX_EVENT_MASK 0x801F +#define GLX_DAMAGED 0x8020 +#define GLX_SAVED 0x8021 +#define GLX_WINDOW 0x8022 +#define GLX_PBUFFER 0x8023 +#define GLX_PBUFFER_HEIGHT 0x8040 +#define GLX_PBUFFER_WIDTH 0x8041 +#endif + +#ifndef GLX_VERSION_1_4 +#define GLX_SAMPLE_BUFFERS 100000 +#define GLX_SAMPLES 100001 +#endif + +#ifndef GLX_ARB_get_proc_address +#endif + +#ifndef GLX_ARB_multisample +#define GLX_SAMPLE_BUFFERS_ARB 100000 +#define GLX_SAMPLES_ARB 100001 +#endif + +#ifndef GLX_ARB_vertex_buffer_object +#define GLX_CONTEXT_ALLOW_BUFFER_BYTE_ORDER_MISMATCH_ARB 0x2095 +#endif + +#ifndef GLX_ARB_fbconfig_float +#define GLX_RGBA_FLOAT_TYPE_ARB 0x20B9 +#define GLX_RGBA_FLOAT_BIT_ARB 0x00000004 +#endif + +#ifndef GLX_ARB_framebuffer_sRGB +#define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20B2 +#endif + +#ifndef GLX_ARB_create_context +#define GLX_CONTEXT_DEBUG_BIT_ARB 0x00000001 +#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 +#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 +#define GLX_CONTEXT_FLAGS_ARB 0x2094 +#endif + +#ifndef GLX_ARB_create_context_profile +#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 +#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 +#define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 +#endif + +#ifndef GLX_ARB_create_context_robustness +#define GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 +#define GLX_LOSE_CONTEXT_ON_RESET_ARB 0x8252 +#define GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 +#define GLX_NO_RESET_NOTIFICATION_ARB 0x8261 +#endif + +#ifndef GLX_SGIS_multisample +#define GLX_SAMPLE_BUFFERS_SGIS 100000 +#define GLX_SAMPLES_SGIS 100001 +#endif + +#ifndef GLX_EXT_visual_info +#define GLX_X_VISUAL_TYPE_EXT 0x22 +#define GLX_TRANSPARENT_TYPE_EXT 0x23 +#define GLX_TRANSPARENT_INDEX_VALUE_EXT 0x24 +#define GLX_TRANSPARENT_RED_VALUE_EXT 0x25 +#define GLX_TRANSPARENT_GREEN_VALUE_EXT 0x26 +#define GLX_TRANSPARENT_BLUE_VALUE_EXT 0x27 +#define GLX_TRANSPARENT_ALPHA_VALUE_EXT 0x28 +#define GLX_NONE_EXT 0x8000 +#define GLX_TRUE_COLOR_EXT 0x8002 +#define GLX_DIRECT_COLOR_EXT 0x8003 +#define GLX_PSEUDO_COLOR_EXT 0x8004 +#define GLX_STATIC_COLOR_EXT 0x8005 +#define GLX_GRAY_SCALE_EXT 0x8006 +#define GLX_STATIC_GRAY_EXT 0x8007 +#define GLX_TRANSPARENT_RGB_EXT 0x8008 +#define GLX_TRANSPARENT_INDEX_EXT 0x8009 +#endif + +#ifndef GLX_SGI_swap_control +#endif + +#ifndef GLX_SGI_video_sync +#endif + +#ifndef GLX_SGI_make_current_read +#endif + +#ifndef GLX_SGIX_video_source +#endif + +#ifndef GLX_EXT_visual_rating +#define GLX_VISUAL_CAVEAT_EXT 0x20 +#define GLX_SLOW_VISUAL_EXT 0x8001 +#define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D +/* reuse GLX_NONE_EXT */ +#endif + +#ifndef GLX_EXT_import_context +#define GLX_SHARE_CONTEXT_EXT 0x800A +#define GLX_VISUAL_ID_EXT 0x800B +#define GLX_SCREEN_EXT 0x800C +#endif + +#ifndef GLX_SGIX_fbconfig +#define GLX_WINDOW_BIT_SGIX 0x00000001 +#define GLX_PIXMAP_BIT_SGIX 0x00000002 +#define GLX_RGBA_BIT_SGIX 0x00000001 +#define GLX_COLOR_INDEX_BIT_SGIX 0x00000002 +#define GLX_DRAWABLE_TYPE_SGIX 0x8010 +#define GLX_RENDER_TYPE_SGIX 0x8011 +#define GLX_X_RENDERABLE_SGIX 0x8012 +#define GLX_FBCONFIG_ID_SGIX 0x8013 +#define GLX_RGBA_TYPE_SGIX 0x8014 +#define GLX_COLOR_INDEX_TYPE_SGIX 0x8015 +/* reuse GLX_SCREEN_EXT */ +#endif + +#ifndef GLX_SGIX_pbuffer +#define GLX_PBUFFER_BIT_SGIX 0x00000004 +#define GLX_BUFFER_CLOBBER_MASK_SGIX 0x08000000 +#define GLX_FRONT_LEFT_BUFFER_BIT_SGIX 0x00000001 +#define GLX_FRONT_RIGHT_BUFFER_BIT_SGIX 0x00000002 +#define GLX_BACK_LEFT_BUFFER_BIT_SGIX 0x00000004 +#define GLX_BACK_RIGHT_BUFFER_BIT_SGIX 0x00000008 +#define GLX_AUX_BUFFERS_BIT_SGIX 0x00000010 +#define GLX_DEPTH_BUFFER_BIT_SGIX 0x00000020 +#define GLX_STENCIL_BUFFER_BIT_SGIX 0x00000040 +#define GLX_ACCUM_BUFFER_BIT_SGIX 0x00000080 +#define GLX_SAMPLE_BUFFERS_BIT_SGIX 0x00000100 +#define GLX_MAX_PBUFFER_WIDTH_SGIX 0x8016 +#define GLX_MAX_PBUFFER_HEIGHT_SGIX 0x8017 +#define GLX_MAX_PBUFFER_PIXELS_SGIX 0x8018 +#define GLX_OPTIMAL_PBUFFER_WIDTH_SGIX 0x8019 +#define GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX 0x801A +#define GLX_PRESERVED_CONTENTS_SGIX 0x801B +#define GLX_LARGEST_PBUFFER_SGIX 0x801C +#define GLX_WIDTH_SGIX 0x801D +#define GLX_HEIGHT_SGIX 0x801E +#define GLX_EVENT_MASK_SGIX 0x801F +#define GLX_DAMAGED_SGIX 0x8020 +#define GLX_SAVED_SGIX 0x8021 +#define GLX_WINDOW_SGIX 0x8022 +#define GLX_PBUFFER_SGIX 0x8023 +#endif + +#ifndef GLX_SGI_cushion +#endif + +#ifndef GLX_SGIX_video_resize +#define GLX_SYNC_FRAME_SGIX 0x00000000 +#define GLX_SYNC_SWAP_SGIX 0x00000001 +#endif + +#ifndef GLX_SGIX_dmbuffer +#define GLX_DIGITAL_MEDIA_PBUFFER_SGIX 0x8024 +#endif + +#ifndef GLX_SGIX_swap_group +#endif + +#ifndef GLX_SGIX_swap_barrier +#endif + +#ifndef GLX_SGIS_blended_overlay +#define GLX_BLENDED_RGBA_SGIS 0x8025 +#endif + +#ifndef GLX_SGIS_shared_multisample +#define GLX_MULTISAMPLE_SUB_RECT_WIDTH_SGIS 0x8026 +#define GLX_MULTISAMPLE_SUB_RECT_HEIGHT_SGIS 0x8027 +#endif + +#ifndef GLX_SUN_get_transparent_index +#endif + +#ifndef GLX_3DFX_multisample +#define GLX_SAMPLE_BUFFERS_3DFX 0x8050 +#define GLX_SAMPLES_3DFX 0x8051 +#endif + +#ifndef GLX_MESA_copy_sub_buffer +#endif + +#ifndef GLX_MESA_pixmap_colormap +#endif + +#ifndef GLX_MESA_release_buffers +#endif + +#ifndef GLX_MESA_set_3dfx_mode +#define GLX_3DFX_WINDOW_MODE_MESA 0x1 +#define GLX_3DFX_FULLSCREEN_MODE_MESA 0x2 +#endif + +#ifndef GLX_SGIX_visual_select_group +#define GLX_VISUAL_SELECT_GROUP_SGIX 0x8028 +#endif + +#ifndef GLX_OML_swap_method +#define GLX_SWAP_METHOD_OML 0x8060 +#define GLX_SWAP_EXCHANGE_OML 0x8061 +#define GLX_SWAP_COPY_OML 0x8062 +#define GLX_SWAP_UNDEFINED_OML 0x8063 +#endif + +#ifndef GLX_OML_sync_control +#endif + +#ifndef GLX_NV_float_buffer +#define GLX_FLOAT_COMPONENTS_NV 0x20B0 +#endif + +#ifndef GLX_SGIX_hyperpipe +#define GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX 80 +#define GLX_BAD_HYPERPIPE_CONFIG_SGIX 91 +#define GLX_BAD_HYPERPIPE_SGIX 92 +#define GLX_HYPERPIPE_DISPLAY_PIPE_SGIX 0x00000001 +#define GLX_HYPERPIPE_RENDER_PIPE_SGIX 0x00000002 +#define GLX_PIPE_RECT_SGIX 0x00000001 +#define GLX_PIPE_RECT_LIMITS_SGIX 0x00000002 +#define GLX_HYPERPIPE_STEREO_SGIX 0x00000003 +#define GLX_HYPERPIPE_PIXEL_AVERAGE_SGIX 0x00000004 +#define GLX_HYPERPIPE_ID_SGIX 0x8030 +#endif + +#ifndef GLX_MESA_agp_offset +#endif + +#ifndef GLX_EXT_fbconfig_packed_float +#define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1 +#define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008 +#endif + +#ifndef GLX_EXT_framebuffer_sRGB +#define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2 +#endif + +#ifndef GLX_EXT_texture_from_pixmap +#define GLX_TEXTURE_1D_BIT_EXT 0x00000001 +#define GLX_TEXTURE_2D_BIT_EXT 0x00000002 +#define GLX_TEXTURE_RECTANGLE_BIT_EXT 0x00000004 +#define GLX_BIND_TO_TEXTURE_RGB_EXT 0x20D0 +#define GLX_BIND_TO_TEXTURE_RGBA_EXT 0x20D1 +#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT 0x20D2 +#define GLX_BIND_TO_TEXTURE_TARGETS_EXT 0x20D3 +#define GLX_Y_INVERTED_EXT 0x20D4 +#define GLX_TEXTURE_FORMAT_EXT 0x20D5 +#define GLX_TEXTURE_TARGET_EXT 0x20D6 +#define GLX_MIPMAP_TEXTURE_EXT 0x20D7 +#define GLX_TEXTURE_FORMAT_NONE_EXT 0x20D8 +#define GLX_TEXTURE_FORMAT_RGB_EXT 0x20D9 +#define GLX_TEXTURE_FORMAT_RGBA_EXT 0x20DA +#define GLX_TEXTURE_1D_EXT 0x20DB +#define GLX_TEXTURE_2D_EXT 0x20DC +#define GLX_TEXTURE_RECTANGLE_EXT 0x20DD +#define GLX_FRONT_LEFT_EXT 0x20DE +#define GLX_FRONT_RIGHT_EXT 0x20DF +#define GLX_BACK_LEFT_EXT 0x20E0 +#define GLX_BACK_RIGHT_EXT 0x20E1 +#define GLX_FRONT_EXT GLX_FRONT_LEFT_EXT +#define GLX_BACK_EXT GLX_BACK_LEFT_EXT +#define GLX_AUX0_EXT 0x20E2 +#define GLX_AUX1_EXT 0x20E3 +#define GLX_AUX2_EXT 0x20E4 +#define GLX_AUX3_EXT 0x20E5 +#define GLX_AUX4_EXT 0x20E6 +#define GLX_AUX5_EXT 0x20E7 +#define GLX_AUX6_EXT 0x20E8 +#define GLX_AUX7_EXT 0x20E9 +#define GLX_AUX8_EXT 0x20EA +#define GLX_AUX9_EXT 0x20EB +#endif + +#ifndef GLX_NV_present_video +#define GLX_NUM_VIDEO_SLOTS_NV 0x20F0 +#endif + +#ifndef GLX_NV_video_out +#define GLX_VIDEO_OUT_COLOR_NV 0x20C3 +#define GLX_VIDEO_OUT_ALPHA_NV 0x20C4 +#define GLX_VIDEO_OUT_DEPTH_NV 0x20C5 +#define GLX_VIDEO_OUT_COLOR_AND_ALPHA_NV 0x20C6 +#define GLX_VIDEO_OUT_COLOR_AND_DEPTH_NV 0x20C7 +#define GLX_VIDEO_OUT_FRAME_NV 0x20C8 +#define GLX_VIDEO_OUT_FIELD_1_NV 0x20C9 +#define GLX_VIDEO_OUT_FIELD_2_NV 0x20CA +#define GLX_VIDEO_OUT_STACKED_FIELDS_1_2_NV 0x20CB +#define GLX_VIDEO_OUT_STACKED_FIELDS_2_1_NV 0x20CC +#endif + +#ifndef GLX_NV_swap_group +#endif + +#ifndef GLX_NV_video_capture +#define GLX_DEVICE_ID_NV 0x20CD +#define GLX_UNIQUE_ID_NV 0x20CE +#define GLX_NUM_VIDEO_CAPTURE_SLOTS_NV 0x20CF +#endif + +#ifndef GLX_EXT_swap_control +#define GLX_SWAP_INTERVAL_EXT 0x20F1 +#define GLX_MAX_SWAP_INTERVAL_EXT 0x20F2 +#endif + +#ifndef GLX_NV_copy_image +#endif + +#ifndef GLX_INTEL_swap_event +#define GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK 0x04000000 +#define GLX_EXCHANGE_COMPLETE_INTEL 0x8180 +#define GLX_COPY_COMPLETE_INTEL 0x8181 +#define GLX_FLIP_COMPLETE_INTEL 0x8182 +#endif + +#ifndef GLX_NV_multisample_coverage +#define GLX_COVERAGE_SAMPLES_NV 100001 +#define GLX_COLOR_SAMPLES_NV 0x20B3 +#endif + +#ifndef GLX_AMD_gpu_association +#define GLX_GPU_VENDOR_AMD 0x1F00 +#define GLX_GPU_RENDERER_STRING_AMD 0x1F01 +#define GLX_GPU_OPENGL_VERSION_STRING_AMD 0x1F02 +#define GLX_GPU_FASTEST_TARGET_GPUS_AMD 0x21A2 +#define GLX_GPU_RAM_AMD 0x21A3 +#define GLX_GPU_CLOCK_AMD 0x21A4 +#define GLX_GPU_NUM_PIPES_AMD 0x21A5 +#define GLX_GPU_NUM_SIMD_AMD 0x21A6 +#define GLX_GPU_NUM_RB_AMD 0x21A7 +#define GLX_GPU_NUM_SPI_AMD 0x21A8 +#endif + +#ifndef GLX_EXT_create_context_es2_profile +#define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 +#endif + + +/*************************************************************/ + +#ifndef GLX_ARB_get_proc_address +typedef void (*__GLXextFuncPtr)(void); +#endif + +#ifndef GLX_SGIX_video_source +typedef XID GLXVideoSourceSGIX; +#endif + +#ifndef GLX_SGIX_fbconfig +typedef XID GLXFBConfigIDSGIX; +typedef struct __GLXFBConfigRec *GLXFBConfigSGIX; +#endif + +#ifndef GLX_SGIX_pbuffer +typedef XID GLXPbufferSGIX; +typedef struct { + int type; + unsigned long serial; /* # of last request processed by server */ + Bool send_event; /* true if this came for SendEvent request */ + Display *display; /* display the event was read from */ + GLXDrawable drawable; /* i.d. of Drawable */ + int event_type; /* GLX_DAMAGED_SGIX or GLX_SAVED_SGIX */ + int draw_type; /* GLX_WINDOW_SGIX or GLX_PBUFFER_SGIX */ + unsigned int mask; /* mask indicating which buffers are affected*/ + int x, y; + int width, height; + int count; /* if nonzero, at least this many more */ +} GLXBufferClobberEventSGIX; +#endif + +#ifndef GLX_NV_video_output +typedef unsigned int GLXVideoDeviceNV; +#endif + +#ifndef GLX_NV_video_capture +typedef XID GLXVideoCaptureDeviceNV; +#endif + +#ifndef GLEXT_64_TYPES_DEFINED +/* This code block is duplicated in glext.h, so must be protected */ +#define GLEXT_64_TYPES_DEFINED +/* Define int32_t, int64_t, and uint64_t types for UST/MSC */ +/* (as used in the GLX_OML_sync_control extension). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#include +#elif defined(__sun__) || defined(__digital__) +#include +#if defined(__STDC__) +#if defined(__arch64__) || defined(_LP64) +typedef long int int64_t; +typedef unsigned long int uint64_t; +#else +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#endif /* __arch64__ */ +#endif /* __STDC__ */ +#elif defined( __VMS ) || defined(__sgi) +#include +#elif defined(__SCO__) || defined(__USLC__) +#include +#elif defined(__UNIXOS2__) || defined(__SOL64__) +typedef long int int32_t; +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#elif defined(_WIN32) && defined(__GNUC__) +#include +#elif defined(_WIN32) +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +#else +#include /* Fallback option */ +#endif +#endif + +#ifndef GLX_VERSION_1_3 +#define GLX_VERSION_1_3 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern GLXFBConfig * glXGetFBConfigs (Display *dpy, int screen, int *nelements); +extern GLXFBConfig * glXChooseFBConfig (Display *dpy, int screen, const int *attrib_list, int *nelements); +extern int glXGetFBConfigAttrib (Display *dpy, GLXFBConfig config, int attribute, int *value); +extern XVisualInfo * glXGetVisualFromFBConfig (Display *dpy, GLXFBConfig config); +extern GLXWindow glXCreateWindow (Display *dpy, GLXFBConfig config, Window win, const int *attrib_list); +extern void glXDestroyWindow (Display *dpy, GLXWindow win); +extern GLXPixmap glXCreatePixmap (Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list); +extern void glXDestroyPixmap (Display *dpy, GLXPixmap pixmap); +extern GLXPbuffer glXCreatePbuffer (Display *dpy, GLXFBConfig config, const int *attrib_list); +extern void glXDestroyPbuffer (Display *dpy, GLXPbuffer pbuf); +extern void glXQueryDrawable (Display *dpy, GLXDrawable draw, int attribute, unsigned int *value); +extern GLXContext glXCreateNewContext (Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct); +extern Bool glXMakeContextCurrent (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); +extern GLXDrawable glXGetCurrentReadDrawable (void); +extern Display * glXGetCurrentDisplay (void); +extern int glXQueryContext (Display *dpy, GLXContext ctx, int attribute, int *value); +extern void glXSelectEvent (Display *dpy, GLXDrawable draw, unsigned long event_mask); +extern void glXGetSelectedEvent (Display *dpy, GLXDrawable draw, unsigned long *event_mask); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef GLXFBConfig * ( * PFNGLXGETFBCONFIGSPROC) (Display *dpy, int screen, int *nelements); +typedef GLXFBConfig * ( * PFNGLXCHOOSEFBCONFIGPROC) (Display *dpy, int screen, const int *attrib_list, int *nelements); +typedef int ( * PFNGLXGETFBCONFIGATTRIBPROC) (Display *dpy, GLXFBConfig config, int attribute, int *value); +typedef XVisualInfo * ( * PFNGLXGETVISUALFROMFBCONFIGPROC) (Display *dpy, GLXFBConfig config); +typedef GLXWindow ( * PFNGLXCREATEWINDOWPROC) (Display *dpy, GLXFBConfig config, Window win, const int *attrib_list); +typedef void ( * PFNGLXDESTROYWINDOWPROC) (Display *dpy, GLXWindow win); +typedef GLXPixmap ( * PFNGLXCREATEPIXMAPPROC) (Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list); +typedef void ( * PFNGLXDESTROYPIXMAPPROC) (Display *dpy, GLXPixmap pixmap); +typedef GLXPbuffer ( * PFNGLXCREATEPBUFFERPROC) (Display *dpy, GLXFBConfig config, const int *attrib_list); +typedef void ( * PFNGLXDESTROYPBUFFERPROC) (Display *dpy, GLXPbuffer pbuf); +typedef void ( * PFNGLXQUERYDRAWABLEPROC) (Display *dpy, GLXDrawable draw, int attribute, unsigned int *value); +typedef GLXContext ( * PFNGLXCREATENEWCONTEXTPROC) (Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct); +typedef Bool ( * PFNGLXMAKECONTEXTCURRENTPROC) (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); +typedef GLXDrawable ( * PFNGLXGETCURRENTREADDRAWABLEPROC) (void); +typedef Display * ( * PFNGLXGETCURRENTDISPLAYPROC) (void); +typedef int ( * PFNGLXQUERYCONTEXTPROC) (Display *dpy, GLXContext ctx, int attribute, int *value); +typedef void ( * PFNGLXSELECTEVENTPROC) (Display *dpy, GLXDrawable draw, unsigned long event_mask); +typedef void ( * PFNGLXGETSELECTEDEVENTPROC) (Display *dpy, GLXDrawable draw, unsigned long *event_mask); +#endif + +#ifndef GLX_VERSION_1_4 +#define GLX_VERSION_1_4 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern __GLXextFuncPtr glXGetProcAddress (const GLubyte *procName); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef __GLXextFuncPtr ( * PFNGLXGETPROCADDRESSPROC) (const GLubyte *procName); +#endif + +#ifndef GLX_ARB_get_proc_address +#define GLX_ARB_get_proc_address 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern __GLXextFuncPtr glXGetProcAddressARB (const GLubyte *procName); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef __GLXextFuncPtr ( * PFNGLXGETPROCADDRESSARBPROC) (const GLubyte *procName); +#endif + +#ifndef GLX_ARB_multisample +#define GLX_ARB_multisample 1 +#endif + +#ifndef GLX_ARB_fbconfig_float +#define GLX_ARB_fbconfig_float 1 +#endif + +#ifndef GLX_ARB_framebuffer_sRGB +#define GLX_ARB_framebuffer_sRGB 1 +#endif + +#ifndef GLX_ARB_create_context +#define GLX_ARB_create_context 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern GLXContext glXCreateContextAttribsARB (Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef GLXContext ( * PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list); +#endif + +#ifndef GLX_ARB_create_context_profile +#define GLX_ARB_create_context_profile 1 +#endif + +#ifndef GLX_ARB_create_context_robustness +#define GLX_ARB_create_context_robustness 1 +#endif + +#ifndef GLX_SGIS_multisample +#define GLX_SGIS_multisample 1 +#endif + +#ifndef GLX_EXT_visual_info +#define GLX_EXT_visual_info 1 +#endif + +#ifndef GLX_SGI_swap_control +#define GLX_SGI_swap_control 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern int glXSwapIntervalSGI (int interval); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef int ( * PFNGLXSWAPINTERVALSGIPROC) (int interval); +#endif + +#ifndef GLX_SGI_video_sync +#define GLX_SGI_video_sync 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern int glXGetVideoSyncSGI (unsigned int *count); +extern int glXWaitVideoSyncSGI (int divisor, int remainder, unsigned int *count); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef int ( * PFNGLXGETVIDEOSYNCSGIPROC) (unsigned int *count); +typedef int ( * PFNGLXWAITVIDEOSYNCSGIPROC) (int divisor, int remainder, unsigned int *count); +#endif + +#ifndef GLX_SGI_make_current_read +#define GLX_SGI_make_current_read 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern Bool glXMakeCurrentReadSGI (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); +extern GLXDrawable glXGetCurrentReadDrawableSGI (void); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Bool ( * PFNGLXMAKECURRENTREADSGIPROC) (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); +typedef GLXDrawable ( * PFNGLXGETCURRENTREADDRAWABLESGIPROC) (void); +#endif + +#ifndef GLX_SGIX_video_source +#define GLX_SGIX_video_source 1 +#ifdef _VL_H +#ifdef GLX_GLXEXT_PROTOTYPES +extern GLXVideoSourceSGIX glXCreateGLXVideoSourceSGIX (Display *display, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode); +extern void glXDestroyGLXVideoSourceSGIX (Display *dpy, GLXVideoSourceSGIX glxvideosource); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef GLXVideoSourceSGIX ( * PFNGLXCREATEGLXVIDEOSOURCESGIXPROC) (Display *display, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode); +typedef void ( * PFNGLXDESTROYGLXVIDEOSOURCESGIXPROC) (Display *dpy, GLXVideoSourceSGIX glxvideosource); +#endif /* _VL_H */ +#endif + +#ifndef GLX_EXT_visual_rating +#define GLX_EXT_visual_rating 1 +#endif + +#ifndef GLX_EXT_import_context +#define GLX_EXT_import_context 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern Display * glXGetCurrentDisplayEXT (void); +extern int glXQueryContextInfoEXT (Display *dpy, GLXContext context, int attribute, int *value); +extern GLXContextID glXGetContextIDEXT (const GLXContext context); +extern GLXContext glXImportContextEXT (Display *dpy, GLXContextID contextID); +extern void glXFreeContextEXT (Display *dpy, GLXContext context); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Display * ( * PFNGLXGETCURRENTDISPLAYEXTPROC) (void); +typedef int ( * PFNGLXQUERYCONTEXTINFOEXTPROC) (Display *dpy, GLXContext context, int attribute, int *value); +typedef GLXContextID ( * PFNGLXGETCONTEXTIDEXTPROC) (const GLXContext context); +typedef GLXContext ( * PFNGLXIMPORTCONTEXTEXTPROC) (Display *dpy, GLXContextID contextID); +typedef void ( * PFNGLXFREECONTEXTEXTPROC) (Display *dpy, GLXContext context); +#endif + +#ifndef GLX_SGIX_fbconfig +#define GLX_SGIX_fbconfig 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern int glXGetFBConfigAttribSGIX (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value); +extern GLXFBConfigSGIX * glXChooseFBConfigSGIX (Display *dpy, int screen, int *attrib_list, int *nelements); +extern GLXPixmap glXCreateGLXPixmapWithConfigSGIX (Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap); +extern GLXContext glXCreateContextWithConfigSGIX (Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct); +extern XVisualInfo * glXGetVisualFromFBConfigSGIX (Display *dpy, GLXFBConfigSGIX config); +extern GLXFBConfigSGIX glXGetFBConfigFromVisualSGIX (Display *dpy, XVisualInfo *vis); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef int ( * PFNGLXGETFBCONFIGATTRIBSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value); +typedef GLXFBConfigSGIX * ( * PFNGLXCHOOSEFBCONFIGSGIXPROC) (Display *dpy, int screen, int *attrib_list, int *nelements); +typedef GLXPixmap ( * PFNGLXCREATEGLXPIXMAPWITHCONFIGSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap); +typedef GLXContext ( * PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct); +typedef XVisualInfo * ( * PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) (Display *dpy, GLXFBConfigSGIX config); +typedef GLXFBConfigSGIX ( * PFNGLXGETFBCONFIGFROMVISUALSGIXPROC) (Display *dpy, XVisualInfo *vis); +#endif + +#ifndef GLX_SGIX_pbuffer +#define GLX_SGIX_pbuffer 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern GLXPbufferSGIX glXCreateGLXPbufferSGIX (Display *dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list); +extern void glXDestroyGLXPbufferSGIX (Display *dpy, GLXPbufferSGIX pbuf); +extern int glXQueryGLXPbufferSGIX (Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value); +extern void glXSelectEventSGIX (Display *dpy, GLXDrawable drawable, unsigned long mask); +extern void glXGetSelectedEventSGIX (Display *dpy, GLXDrawable drawable, unsigned long *mask); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef GLXPbufferSGIX ( * PFNGLXCREATEGLXPBUFFERSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list); +typedef void ( * PFNGLXDESTROYGLXPBUFFERSGIXPROC) (Display *dpy, GLXPbufferSGIX pbuf); +typedef int ( * PFNGLXQUERYGLXPBUFFERSGIXPROC) (Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value); +typedef void ( * PFNGLXSELECTEVENTSGIXPROC) (Display *dpy, GLXDrawable drawable, unsigned long mask); +typedef void ( * PFNGLXGETSELECTEDEVENTSGIXPROC) (Display *dpy, GLXDrawable drawable, unsigned long *mask); +#endif + +#ifndef GLX_SGI_cushion +#define GLX_SGI_cushion 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern void glXCushionSGI (Display *dpy, Window window, float cushion); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef void ( * PFNGLXCUSHIONSGIPROC) (Display *dpy, Window window, float cushion); +#endif + +#ifndef GLX_SGIX_video_resize +#define GLX_SGIX_video_resize 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern int glXBindChannelToWindowSGIX (Display *display, int screen, int channel, Window window); +extern int glXChannelRectSGIX (Display *display, int screen, int channel, int x, int y, int w, int h); +extern int glXQueryChannelRectSGIX (Display *display, int screen, int channel, int *dx, int *dy, int *dw, int *dh); +extern int glXQueryChannelDeltasSGIX (Display *display, int screen, int channel, int *x, int *y, int *w, int *h); +extern int glXChannelRectSyncSGIX (Display *display, int screen, int channel, GLenum synctype); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef int ( * PFNGLXBINDCHANNELTOWINDOWSGIXPROC) (Display *display, int screen, int channel, Window window); +typedef int ( * PFNGLXCHANNELRECTSGIXPROC) (Display *display, int screen, int channel, int x, int y, int w, int h); +typedef int ( * PFNGLXQUERYCHANNELRECTSGIXPROC) (Display *display, int screen, int channel, int *dx, int *dy, int *dw, int *dh); +typedef int ( * PFNGLXQUERYCHANNELDELTASSGIXPROC) (Display *display, int screen, int channel, int *x, int *y, int *w, int *h); +typedef int ( * PFNGLXCHANNELRECTSYNCSGIXPROC) (Display *display, int screen, int channel, GLenum synctype); +#endif + +#ifndef GLX_SGIX_dmbuffer +#define GLX_SGIX_dmbuffer 1 +#ifdef _DM_BUFFER_H_ +#ifdef GLX_GLXEXT_PROTOTYPES +extern Bool glXAssociateDMPbufferSGIX (Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Bool ( * PFNGLXASSOCIATEDMPBUFFERSGIXPROC) (Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer); +#endif /* _DM_BUFFER_H_ */ +#endif + +#ifndef GLX_SGIX_swap_group +#define GLX_SGIX_swap_group 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern void glXJoinSwapGroupSGIX (Display *dpy, GLXDrawable drawable, GLXDrawable member); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef void ( * PFNGLXJOINSWAPGROUPSGIXPROC) (Display *dpy, GLXDrawable drawable, GLXDrawable member); +#endif + +#ifndef GLX_SGIX_swap_barrier +#define GLX_SGIX_swap_barrier 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern void glXBindSwapBarrierSGIX (Display *dpy, GLXDrawable drawable, int barrier); +extern Bool glXQueryMaxSwapBarriersSGIX (Display *dpy, int screen, int *max); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef void ( * PFNGLXBINDSWAPBARRIERSGIXPROC) (Display *dpy, GLXDrawable drawable, int barrier); +typedef Bool ( * PFNGLXQUERYMAXSWAPBARRIERSSGIXPROC) (Display *dpy, int screen, int *max); +#endif + +#ifndef GLX_SUN_get_transparent_index +#define GLX_SUN_get_transparent_index 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern Status glXGetTransparentIndexSUN (Display *dpy, Window overlay, Window underlay, long *pTransparentIndex); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Status ( * PFNGLXGETTRANSPARENTINDEXSUNPROC) (Display *dpy, Window overlay, Window underlay, long *pTransparentIndex); +#endif + +#ifndef GLX_MESA_copy_sub_buffer +#define GLX_MESA_copy_sub_buffer 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern void glXCopySubBufferMESA (Display *dpy, GLXDrawable drawable, int x, int y, int width, int height); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef void ( * PFNGLXCOPYSUBBUFFERMESAPROC) (Display *dpy, GLXDrawable drawable, int x, int y, int width, int height); +#endif + +#ifndef GLX_MESA_pixmap_colormap +#define GLX_MESA_pixmap_colormap 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern GLXPixmap glXCreateGLXPixmapMESA (Display *dpy, XVisualInfo *visual, Pixmap pixmap, Colormap cmap); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef GLXPixmap ( * PFNGLXCREATEGLXPIXMAPMESAPROC) (Display *dpy, XVisualInfo *visual, Pixmap pixmap, Colormap cmap); +#endif + +#ifndef GLX_MESA_release_buffers +#define GLX_MESA_release_buffers 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern Bool glXReleaseBuffersMESA (Display *dpy, GLXDrawable drawable); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Bool ( * PFNGLXRELEASEBUFFERSMESAPROC) (Display *dpy, GLXDrawable drawable); +#endif + +#ifndef GLX_MESA_set_3dfx_mode +#define GLX_MESA_set_3dfx_mode 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern Bool glXSet3DfxModeMESA (int mode); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Bool ( * PFNGLXSET3DFXMODEMESAPROC) (int mode); +#endif + +#ifndef GLX_SGIX_visual_select_group +#define GLX_SGIX_visual_select_group 1 +#endif + +#ifndef GLX_OML_swap_method +#define GLX_OML_swap_method 1 +#endif + +#ifndef GLX_OML_sync_control +#define GLX_OML_sync_control 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern Bool glXGetSyncValuesOML (Display *dpy, GLXDrawable drawable, int64_t *ust, int64_t *msc, int64_t *sbc); +extern Bool glXGetMscRateOML (Display *dpy, GLXDrawable drawable, int32_t *numerator, int32_t *denominator); +extern int64_t glXSwapBuffersMscOML (Display *dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder); +extern Bool glXWaitForMscOML (Display *dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc); +extern Bool glXWaitForSbcOML (Display *dpy, GLXDrawable drawable, int64_t target_sbc, int64_t *ust, int64_t *msc, int64_t *sbc); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Bool ( * PFNGLXGETSYNCVALUESOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t *ust, int64_t *msc, int64_t *sbc); +typedef Bool ( * PFNGLXGETMSCRATEOMLPROC) (Display *dpy, GLXDrawable drawable, int32_t *numerator, int32_t *denominator); +typedef int64_t ( * PFNGLXSWAPBUFFERSMSCOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder); +typedef Bool ( * PFNGLXWAITFORMSCOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc); +typedef Bool ( * PFNGLXWAITFORSBCOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t target_sbc, int64_t *ust, int64_t *msc, int64_t *sbc); +#endif + +#ifndef GLX_NV_float_buffer +#define GLX_NV_float_buffer 1 +#endif + +#ifndef GLX_SGIX_hyperpipe +#define GLX_SGIX_hyperpipe 1 + +typedef struct { + char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]; + int networkId; +} GLXHyperpipeNetworkSGIX; + +typedef struct { + char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]; + int channel; + unsigned int + participationType; + int timeSlice; +} GLXHyperpipeConfigSGIX; + +typedef struct { + char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]; + int srcXOrigin, srcYOrigin, srcWidth, srcHeight; + int destXOrigin, destYOrigin, destWidth, destHeight; +} GLXPipeRect; + +typedef struct { + char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]; + int XOrigin, YOrigin, maxHeight, maxWidth; +} GLXPipeRectLimits; + +#ifdef GLX_GLXEXT_PROTOTYPES +extern GLXHyperpipeNetworkSGIX * glXQueryHyperpipeNetworkSGIX (Display *dpy, int *npipes); +extern int glXHyperpipeConfigSGIX (Display *dpy, int networkId, int npipes, GLXHyperpipeConfigSGIX *cfg, int *hpId); +extern GLXHyperpipeConfigSGIX * glXQueryHyperpipeConfigSGIX (Display *dpy, int hpId, int *npipes); +extern int glXDestroyHyperpipeConfigSGIX (Display *dpy, int hpId); +extern int glXBindHyperpipeSGIX (Display *dpy, int hpId); +extern int glXQueryHyperpipeBestAttribSGIX (Display *dpy, int timeSlice, int attrib, int size, void *attribList, void *returnAttribList); +extern int glXHyperpipeAttribSGIX (Display *dpy, int timeSlice, int attrib, int size, void *attribList); +extern int glXQueryHyperpipeAttribSGIX (Display *dpy, int timeSlice, int attrib, int size, void *returnAttribList); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef GLXHyperpipeNetworkSGIX * ( * PFNGLXQUERYHYPERPIPENETWORKSGIXPROC) (Display *dpy, int *npipes); +typedef int ( * PFNGLXHYPERPIPECONFIGSGIXPROC) (Display *dpy, int networkId, int npipes, GLXHyperpipeConfigSGIX *cfg, int *hpId); +typedef GLXHyperpipeConfigSGIX * ( * PFNGLXQUERYHYPERPIPECONFIGSGIXPROC) (Display *dpy, int hpId, int *npipes); +typedef int ( * PFNGLXDESTROYHYPERPIPECONFIGSGIXPROC) (Display *dpy, int hpId); +typedef int ( * PFNGLXBINDHYPERPIPESGIXPROC) (Display *dpy, int hpId); +typedef int ( * PFNGLXQUERYHYPERPIPEBESTATTRIBSGIXPROC) (Display *dpy, int timeSlice, int attrib, int size, void *attribList, void *returnAttribList); +typedef int ( * PFNGLXHYPERPIPEATTRIBSGIXPROC) (Display *dpy, int timeSlice, int attrib, int size, void *attribList); +typedef int ( * PFNGLXQUERYHYPERPIPEATTRIBSGIXPROC) (Display *dpy, int timeSlice, int attrib, int size, void *returnAttribList); +#endif + +#ifndef GLX_MESA_agp_offset +#define GLX_MESA_agp_offset 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern unsigned int glXGetAGPOffsetMESA (const void *pointer); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef unsigned int ( * PFNGLXGETAGPOFFSETMESAPROC) (const void *pointer); +#endif + +#ifndef GLX_EXT_fbconfig_packed_float +#define GLX_EXT_fbconfig_packed_float 1 +#endif + +#ifndef GLX_EXT_framebuffer_sRGB +#define GLX_EXT_framebuffer_sRGB 1 +#endif + +#ifndef GLX_EXT_texture_from_pixmap +#define GLX_EXT_texture_from_pixmap 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern void glXBindTexImageEXT (Display *dpy, GLXDrawable drawable, int buffer, const int *attrib_list); +extern void glXReleaseTexImageEXT (Display *dpy, GLXDrawable drawable, int buffer); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef void ( * PFNGLXBINDTEXIMAGEEXTPROC) (Display *dpy, GLXDrawable drawable, int buffer, const int *attrib_list); +typedef void ( * PFNGLXRELEASETEXIMAGEEXTPROC) (Display *dpy, GLXDrawable drawable, int buffer); +#endif + +#ifndef GLX_NV_present_video +#define GLX_NV_present_video 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern unsigned int * glXEnumerateVideoDevicesNV (Display *dpy, int screen, int *nelements); +extern int glXBindVideoDeviceNV (Display *dpy, unsigned int video_slot, unsigned int video_device, const int *attrib_list); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef unsigned int * ( * PFNGLXENUMERATEVIDEODEVICESNVPROC) (Display *dpy, int screen, int *nelements); +typedef int ( * PFNGLXBINDVIDEODEVICENVPROC) (Display *dpy, unsigned int video_slot, unsigned int video_device, const int *attrib_list); +#endif + +#ifndef GLX_NV_video_output +#define GLX_NV_video_output 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern int glXGetVideoDeviceNV (Display *dpy, int screen, int numVideoDevices, GLXVideoDeviceNV *pVideoDevice); +extern int glXReleaseVideoDeviceNV (Display *dpy, int screen, GLXVideoDeviceNV VideoDevice); +extern int glXBindVideoImageNV (Display *dpy, GLXVideoDeviceNV VideoDevice, GLXPbuffer pbuf, int iVideoBuffer); +extern int glXReleaseVideoImageNV (Display *dpy, GLXPbuffer pbuf); +extern int glXSendPbufferToVideoNV (Display *dpy, GLXPbuffer pbuf, int iBufferType, unsigned long *pulCounterPbuffer, GLboolean bBlock); +extern int glXGetVideoInfoNV (Display *dpy, int screen, GLXVideoDeviceNV VideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef int ( * PFNGLXGETVIDEODEVICENVPROC) (Display *dpy, int screen, int numVideoDevices, GLXVideoDeviceNV *pVideoDevice); +typedef int ( * PFNGLXRELEASEVIDEODEVICENVPROC) (Display *dpy, int screen, GLXVideoDeviceNV VideoDevice); +typedef int ( * PFNGLXBINDVIDEOIMAGENVPROC) (Display *dpy, GLXVideoDeviceNV VideoDevice, GLXPbuffer pbuf, int iVideoBuffer); +typedef int ( * PFNGLXRELEASEVIDEOIMAGENVPROC) (Display *dpy, GLXPbuffer pbuf); +typedef int ( * PFNGLXSENDPBUFFERTOVIDEONVPROC) (Display *dpy, GLXPbuffer pbuf, int iBufferType, unsigned long *pulCounterPbuffer, GLboolean bBlock); +typedef int ( * PFNGLXGETVIDEOINFONVPROC) (Display *dpy, int screen, GLXVideoDeviceNV VideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); +#endif + +#ifndef GLX_NV_swap_group +#define GLX_NV_swap_group 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern Bool glXJoinSwapGroupNV (Display *dpy, GLXDrawable drawable, GLuint group); +extern Bool glXBindSwapBarrierNV (Display *dpy, GLuint group, GLuint barrier); +extern Bool glXQuerySwapGroupNV (Display *dpy, GLXDrawable drawable, GLuint *group, GLuint *barrier); +extern Bool glXQueryMaxSwapGroupsNV (Display *dpy, int screen, GLuint *maxGroups, GLuint *maxBarriers); +extern Bool glXQueryFrameCountNV (Display *dpy, int screen, GLuint *count); +extern Bool glXResetFrameCountNV (Display *dpy, int screen); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef Bool ( * PFNGLXJOINSWAPGROUPNVPROC) (Display *dpy, GLXDrawable drawable, GLuint group); +typedef Bool ( * PFNGLXBINDSWAPBARRIERNVPROC) (Display *dpy, GLuint group, GLuint barrier); +typedef Bool ( * PFNGLXQUERYSWAPGROUPNVPROC) (Display *dpy, GLXDrawable drawable, GLuint *group, GLuint *barrier); +typedef Bool ( * PFNGLXQUERYMAXSWAPGROUPSNVPROC) (Display *dpy, int screen, GLuint *maxGroups, GLuint *maxBarriers); +typedef Bool ( * PFNGLXQUERYFRAMECOUNTNVPROC) (Display *dpy, int screen, GLuint *count); +typedef Bool ( * PFNGLXRESETFRAMECOUNTNVPROC) (Display *dpy, int screen); +#endif + +#ifndef GLX_NV_video_capture +#define GLX_NV_video_capture 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern int glXBindVideoCaptureDeviceNV (Display *dpy, unsigned int video_capture_slot, GLXVideoCaptureDeviceNV device); +extern GLXVideoCaptureDeviceNV * glXEnumerateVideoCaptureDevicesNV (Display *dpy, int screen, int *nelements); +extern void glXLockVideoCaptureDeviceNV (Display *dpy, GLXVideoCaptureDeviceNV device); +extern int glXQueryVideoCaptureDeviceNV (Display *dpy, GLXVideoCaptureDeviceNV device, int attribute, int *value); +extern void glXReleaseVideoCaptureDeviceNV (Display *dpy, GLXVideoCaptureDeviceNV device); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef int ( * PFNGLXBINDVIDEOCAPTUREDEVICENVPROC) (Display *dpy, unsigned int video_capture_slot, GLXVideoCaptureDeviceNV device); +typedef GLXVideoCaptureDeviceNV * ( * PFNGLXENUMERATEVIDEOCAPTUREDEVICESNVPROC) (Display *dpy, int screen, int *nelements); +typedef void ( * PFNGLXLOCKVIDEOCAPTUREDEVICENVPROC) (Display *dpy, GLXVideoCaptureDeviceNV device); +typedef int ( * PFNGLXQUERYVIDEOCAPTUREDEVICENVPROC) (Display *dpy, GLXVideoCaptureDeviceNV device, int attribute, int *value); +typedef void ( * PFNGLXRELEASEVIDEOCAPTUREDEVICENVPROC) (Display *dpy, GLXVideoCaptureDeviceNV device); +#endif + +#ifndef GLX_EXT_swap_control +#define GLX_EXT_swap_control 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern int glXSwapIntervalEXT (Display *dpy, GLXDrawable drawable, int interval); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef int ( * PFNGLXSWAPINTERVALEXTPROC) (Display *dpy, GLXDrawable drawable, int interval); +#endif + +#ifndef GLX_NV_copy_image +#define GLX_NV_copy_image 1 +#ifdef GLX_GLXEXT_PROTOTYPES +extern void glXCopyImageSubDataNV (Display *dpy, GLXContext srcCtx, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLXContext dstCtx, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +#endif /* GLX_GLXEXT_PROTOTYPES */ +typedef void ( * PFNGLXCOPYIMAGESUBDATANVPROC) (Display *dpy, GLXContext srcCtx, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLXContext dstCtx, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +#endif + +#ifndef GLX_INTEL_swap_event +#define GLX_INTEL_swap_event 1 +#endif + +#ifndef GLX_NV_multisample_coverage +#define GLX_NV_multisample_coverage 1 +#endif + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h new file mode 100644 index 0000000..9ee039b --- /dev/null +++ b/include/GL/internal/dri_interface.h @@ -0,0 +1,862 @@ +/* + * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. + * Copyright 2007-2008 Red Hat, Inc. + * (C) Copyright IBM Corporation 2004 + * 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 + * 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 COPYRIGHT HOLDERS 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. + */ + +/** + * \file dri_interface.h + * + * This file contains all the types and functions that define the interface + * between a DRI driver and driver loader. Currently, the most common driver + * loader is the XFree86 libGL.so. However, other loaders do exist, and in + * the future the server-side libglx.a will also be a loader. + * + * \author Kevin E. Martin + * \author Ian Romanick + * \author Kristian Høgsberg + */ + +#ifndef DRI_INTERFACE_H +#define DRI_INTERFACE_H + +/* For archs with no drm.h */ +#if defined(__APPLE__) || defined(__CYGWIN__) || defined(__GNU__) +#ifndef __NOT_HAVE_DRM_H +#define __NOT_HAVE_DRM_H +#endif +#endif + +#ifndef __NOT_HAVE_DRM_H +#include +#else +typedef unsigned int drm_context_t; +typedef unsigned int drm_drawable_t; +typedef struct drm_clip_rect drm_clip_rect_t; +#endif + +/** + * \name DRI interface structures + * + * The following structures define the interface between the GLX client + * side library and the DRI (direct rendering infrastructure). + */ +/*@{*/ +typedef struct __DRIdisplayRec __DRIdisplay; +typedef struct __DRIscreenRec __DRIscreen; +typedef struct __DRIcontextRec __DRIcontext; +typedef struct __DRIdrawableRec __DRIdrawable; +typedef struct __DRIconfigRec __DRIconfig; +typedef struct __DRIframebufferRec __DRIframebuffer; +typedef struct __DRIversionRec __DRIversion; + +typedef struct __DRIcoreExtensionRec __DRIcoreExtension; +typedef struct __DRIextensionRec __DRIextension; +typedef struct __DRIcopySubBufferExtensionRec __DRIcopySubBufferExtension; +typedef struct __DRIswapControlExtensionRec __DRIswapControlExtension; +typedef struct __DRIframeTrackingExtensionRec __DRIframeTrackingExtension; +typedef struct __DRImediaStreamCounterExtensionRec __DRImediaStreamCounterExtension; +typedef struct __DRItexOffsetExtensionRec __DRItexOffsetExtension; +typedef struct __DRItexBufferExtensionRec __DRItexBufferExtension; +typedef struct __DRIlegacyExtensionRec __DRIlegacyExtension; +typedef struct __DRIswrastExtensionRec __DRIswrastExtension; +typedef struct __DRIbufferRec __DRIbuffer; +typedef struct __DRIdri2ExtensionRec __DRIdri2Extension; +typedef struct __DRIdri2LoaderExtensionRec __DRIdri2LoaderExtension; +typedef struct __DRI2flushExtensionRec __DRI2flushExtension; + +/*@}*/ + + +/** + * Extension struct. Drivers 'inherit' from this struct by embedding + * it as the first element in the extension struct. + * + * We never break API in for a DRI extension. If we need to change + * the way things work in a non-backwards compatible manner, we + * introduce a new extension. During a transition period, we can + * leave both the old and the new extension in the driver, which + * allows us to move to the new interface without having to update the + * loader(s) in lock step. + * + * However, we can add entry points to an extension over time as long + * as we don't break the old ones. As we add entry points to an + * extension, we increase the version number. The corresponding + * #define can be used to guard code that accesses the new entry + * points at compile time and the version field in the extension + * struct can be used at run-time to determine how to use the + * extension. + */ +struct __DRIextensionRec { + const char *name; + int version; +}; + +/** + * The first set of extension are the screen extensions, returned by + * __DRIcore::getExtensions(). This entry point will return a list of + * extensions and the loader can use the ones it knows about by + * casting them to more specific extensions and advertising any GLX + * extensions the DRI extensions enables. + */ + +/** + * Used by drivers to indicate support for setting the read drawable. + */ +#define __DRI_READ_DRAWABLE "DRI_ReadDrawable" +#define __DRI_READ_DRAWABLE_VERSION 1 + +/** + * Used by drivers that implement the GLX_MESA_copy_sub_buffer extension. + */ +#define __DRI_COPY_SUB_BUFFER "DRI_CopySubBuffer" +#define __DRI_COPY_SUB_BUFFER_VERSION 1 +struct __DRIcopySubBufferExtensionRec { + __DRIextension base; + void (*copySubBuffer)(__DRIdrawable *drawable, int x, int y, int w, int h); +}; + +/** + * Used by drivers that implement the GLX_SGI_swap_control or + * GLX_MESA_swap_control extension. + */ +#define __DRI_SWAP_CONTROL "DRI_SwapControl" +#define __DRI_SWAP_CONTROL_VERSION 1 +struct __DRIswapControlExtensionRec { + __DRIextension base; + void (*setSwapInterval)(__DRIdrawable *drawable, unsigned int inteval); + unsigned int (*getSwapInterval)(__DRIdrawable *drawable); +}; + +/** + * Used by drivers that implement the GLX_MESA_swap_frame_usage extension. + */ +#define __DRI_FRAME_TRACKING "DRI_FrameTracking" +#define __DRI_FRAME_TRACKING_VERSION 1 +struct __DRIframeTrackingExtensionRec { + __DRIextension base; + + /** + * Enable or disable frame usage tracking. + * + * \since Internal API version 20030317. + */ + int (*frameTracking)(__DRIdrawable *drawable, GLboolean enable); + + /** + * Retrieve frame usage information. + * + * \since Internal API version 20030317. + */ + int (*queryFrameTracking)(__DRIdrawable *drawable, + int64_t * sbc, int64_t * missedFrames, + float * lastMissedUsage, float * usage); +}; + + +/** + * Used by drivers that implement the GLX_SGI_video_sync extension. + */ +#define __DRI_MEDIA_STREAM_COUNTER "DRI_MediaStreamCounter" +#define __DRI_MEDIA_STREAM_COUNTER_VERSION 1 +struct __DRImediaStreamCounterExtensionRec { + __DRIextension base; + + /** + * Wait for the MSC to equal target_msc, or, if that has already passed, + * the next time (MSC % divisor) is equal to remainder. If divisor is + * zero, the function will return as soon as MSC is greater than or equal + * to target_msc. + */ + int (*waitForMSC)(__DRIdrawable *drawable, + int64_t target_msc, int64_t divisor, int64_t remainder, + int64_t * msc, int64_t * sbc); + + /** + * Get the number of vertical refreshes since some point in time before + * this function was first called (i.e., system start up). + */ + int (*getDrawableMSC)(__DRIscreen *screen, __DRIdrawable *drawable, + int64_t *msc); +}; + + +#define __DRI_TEX_OFFSET "DRI_TexOffset" +#define __DRI_TEX_OFFSET_VERSION 1 +struct __DRItexOffsetExtensionRec { + __DRIextension base; + + /** + * Method to override base texture image with a driver specific 'offset'. + * The depth passed in allows e.g. to ignore the alpha channel of texture + * images where the non-alpha components don't occupy a whole texel. + * + * For GLX_EXT_texture_from_pixmap with AIGLX. + */ + void (*setTexOffset)(__DRIcontext *pDRICtx, GLint texname, + unsigned long long offset, GLint depth, GLuint pitch); +}; + + +/* Valid values for format in the setTexBuffer2 function below. These + * values match the GLX tokens for compatibility reasons, but we + * define them here since the DRI interface can't depend on GLX. */ +#define __DRI_TEXTURE_FORMAT_NONE 0x20D8 +#define __DRI_TEXTURE_FORMAT_RGB 0x20D9 +#define __DRI_TEXTURE_FORMAT_RGBA 0x20DA + +#define __DRI_TEX_BUFFER "DRI_TexBuffer" +#define __DRI_TEX_BUFFER_VERSION 2 +struct __DRItexBufferExtensionRec { + __DRIextension base; + + /** + * Method to override base texture image with the contents of a + * __DRIdrawable. + * + * For GLX_EXT_texture_from_pixmap with AIGLX. Deprecated in favor of + * setTexBuffer2 in version 2 of this interface + */ + void (*setTexBuffer)(__DRIcontext *pDRICtx, + GLint target, + __DRIdrawable *pDraw); + + /** + * Method to override base texture image with the contents of a + * __DRIdrawable, including the required texture format attribute. + * + * For GLX_EXT_texture_from_pixmap with AIGLX. + */ + void (*setTexBuffer2)(__DRIcontext *pDRICtx, + GLint target, + GLint format, + __DRIdrawable *pDraw); +}; + +/** + * Used by drivers that implement DRI2 + */ +#define __DRI2_FLUSH "DRI2_Flush" +#define __DRI2_FLUSH_VERSION 3 +struct __DRI2flushExtensionRec { + __DRIextension base; + void (*flush)(__DRIdrawable *drawable); + + /** + * Ask the driver to call getBuffers/getBuffersWithFormat before + * it starts rendering again. + * + * \param drawable the drawable to invalidate + * + * \since 3 + */ + void (*invalidate)(__DRIdrawable *drawable); +}; + + +/** + * XML document describing the configuration options supported by the + * driver. + */ +extern const char __driConfigOptions[]; + +/*@}*/ + +/** + * The following extensions describe loader features that the DRI + * driver can make use of. Some of these are mandatory, such as the + * getDrawableInfo extension for DRI and the DRI Loader extensions for + * DRI2, while others are optional, and if present allow the driver to + * expose certain features. The loader pass in a NULL terminated + * array of these extensions to the driver in the createNewScreen + * constructor. + */ + +typedef struct __DRIgetDrawableInfoExtensionRec __DRIgetDrawableInfoExtension; +typedef struct __DRIsystemTimeExtensionRec __DRIsystemTimeExtension; +typedef struct __DRIdamageExtensionRec __DRIdamageExtension; +typedef struct __DRIloaderExtensionRec __DRIloaderExtension; +typedef struct __DRIswrastLoaderExtensionRec __DRIswrastLoaderExtension; + + +/** + * Callback to getDrawableInfo protocol + */ +#define __DRI_GET_DRAWABLE_INFO "DRI_GetDrawableInfo" +#define __DRI_GET_DRAWABLE_INFO_VERSION 1 +struct __DRIgetDrawableInfoExtensionRec { + __DRIextension base; + + /** + * This function is used to get information about the position, size, and + * clip rects of a drawable. + */ + GLboolean (* getDrawableInfo) ( __DRIdrawable *drawable, + unsigned int * index, unsigned int * stamp, + int * x, int * y, int * width, int * height, + int * numClipRects, drm_clip_rect_t ** pClipRects, + int * backX, int * backY, + int * numBackClipRects, drm_clip_rect_t ** pBackClipRects, + void *loaderPrivate); +}; + +/** + * Callback to get system time for media stream counter extensions. + */ +#define __DRI_SYSTEM_TIME "DRI_SystemTime" +#define __DRI_SYSTEM_TIME_VERSION 1 +struct __DRIsystemTimeExtensionRec { + __DRIextension base; + + /** + * Get the 64-bit unadjusted system time (UST). + */ + int (*getUST)(int64_t * ust); + + /** + * Get the media stream counter (MSC) rate. + * + * Matching the definition in GLX_OML_sync_control, this function returns + * the rate of the "media stream counter". In practical terms, this is + * the frame refresh rate of the display. + */ + GLboolean (*getMSCRate)(__DRIdrawable *draw, + int32_t * numerator, int32_t * denominator, + void *loaderPrivate); +}; + +/** + * Damage reporting + */ +#define __DRI_DAMAGE "DRI_Damage" +#define __DRI_DAMAGE_VERSION 1 +struct __DRIdamageExtensionRec { + __DRIextension base; + + /** + * Reports areas of the given drawable which have been modified by the + * driver. + * + * \param drawable which the drawing was done to. + * \param rects rectangles affected, with the drawable origin as the + * origin. + * \param x X offset of the drawable within the screen (used in the + * front_buffer case) + * \param y Y offset of the drawable within the screen. + * \param front_buffer boolean flag for whether the drawing to the + * drawable was actually done directly to the front buffer (instead + * of backing storage, for example) + * \param loaderPrivate the data passed in at createNewDrawable time + */ + void (*reportDamage)(__DRIdrawable *draw, + int x, int y, + drm_clip_rect_t *rects, int num_rects, + GLboolean front_buffer, + void *loaderPrivate); +}; + +#define __DRI_SWRAST_IMAGE_OP_DRAW 1 +#define __DRI_SWRAST_IMAGE_OP_CLEAR 2 +#define __DRI_SWRAST_IMAGE_OP_SWAP 3 + +/** + * SWRast Loader extension. + */ +#define __DRI_SWRAST_LOADER "DRI_SWRastLoader" +#define __DRI_SWRAST_LOADER_VERSION 1 +struct __DRIswrastLoaderExtensionRec { + __DRIextension base; + + /* + * Drawable position and size + */ + void (*getDrawableInfo)(__DRIdrawable *drawable, + int *x, int *y, int *width, int *height, + void *loaderPrivate); + + /** + * Put image to drawable + */ + void (*putImage)(__DRIdrawable *drawable, int op, + int x, int y, int width, int height, + char *data, void *loaderPrivate); + + /** + * Get image from readable + */ + void (*getImage)(__DRIdrawable *readable, + int x, int y, int width, int height, + char *data, void *loaderPrivate); +}; + +/** + * Invalidate loader extension. The presence of this extension + * indicates to the DRI driver that the loader will call invalidate in + * the __DRI2_FLUSH extension, whenever the needs to query for new + * buffers. This means that the DRI driver can drop the polling in + * glViewport(). + * + * The extension doesn't provide any functionality, it's only use to + * indicate to the driver that it can use the new semantics. A DRI + * driver can use this to switch between the different semantics or + * just refuse to initialize if this extension isn't present. + */ +#define __DRI_USE_INVALIDATE "DRI_UseInvalidate" +#define __DRI_USE_INVALIDATE_VERSION 1 + +typedef struct __DRIuseInvalidateExtensionRec __DRIuseInvalidateExtension; +struct __DRIuseInvalidateExtensionRec { + __DRIextension base; +}; + +/** + * The remaining extensions describe driver extensions, immediately + * available interfaces provided by the driver. To start using the + * driver, dlsym() for the __DRI_DRIVER_EXTENSIONS symbol and look for + * the extension you need in the array. + */ +#define __DRI_DRIVER_EXTENSIONS "__driDriverExtensions" + +/** + * Tokens for __DRIconfig attribs. A number of attributes defined by + * GLX or EGL standards are not in the table, as they must be provided + * by the loader. For example, FBConfig ID or visual ID, drawable type. + */ + +#define __DRI_ATTRIB_BUFFER_SIZE 1 +#define __DRI_ATTRIB_LEVEL 2 +#define __DRI_ATTRIB_RED_SIZE 3 +#define __DRI_ATTRIB_GREEN_SIZE 4 +#define __DRI_ATTRIB_BLUE_SIZE 5 +#define __DRI_ATTRIB_LUMINANCE_SIZE 6 +#define __DRI_ATTRIB_ALPHA_SIZE 7 +#define __DRI_ATTRIB_ALPHA_MASK_SIZE 8 +#define __DRI_ATTRIB_DEPTH_SIZE 9 +#define __DRI_ATTRIB_STENCIL_SIZE 10 +#define __DRI_ATTRIB_ACCUM_RED_SIZE 11 +#define __DRI_ATTRIB_ACCUM_GREEN_SIZE 12 +#define __DRI_ATTRIB_ACCUM_BLUE_SIZE 13 +#define __DRI_ATTRIB_ACCUM_ALPHA_SIZE 14 +#define __DRI_ATTRIB_SAMPLE_BUFFERS 15 +#define __DRI_ATTRIB_SAMPLES 16 +#define __DRI_ATTRIB_RENDER_TYPE 17 +#define __DRI_ATTRIB_CONFIG_CAVEAT 18 +#define __DRI_ATTRIB_CONFORMANT 19 +#define __DRI_ATTRIB_DOUBLE_BUFFER 20 +#define __DRI_ATTRIB_STEREO 21 +#define __DRI_ATTRIB_AUX_BUFFERS 22 +#define __DRI_ATTRIB_TRANSPARENT_TYPE 23 +#define __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE 24 +#define __DRI_ATTRIB_TRANSPARENT_RED_VALUE 25 +#define __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE 26 +#define __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE 27 +#define __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE 28 +#define __DRI_ATTRIB_FLOAT_MODE 29 +#define __DRI_ATTRIB_RED_MASK 30 +#define __DRI_ATTRIB_GREEN_MASK 31 +#define __DRI_ATTRIB_BLUE_MASK 32 +#define __DRI_ATTRIB_ALPHA_MASK 33 +#define __DRI_ATTRIB_MAX_PBUFFER_WIDTH 34 +#define __DRI_ATTRIB_MAX_PBUFFER_HEIGHT 35 +#define __DRI_ATTRIB_MAX_PBUFFER_PIXELS 36 +#define __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH 37 +#define __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT 38 +#define __DRI_ATTRIB_VISUAL_SELECT_GROUP 39 +#define __DRI_ATTRIB_SWAP_METHOD 40 +#define __DRI_ATTRIB_MAX_SWAP_INTERVAL 41 +#define __DRI_ATTRIB_MIN_SWAP_INTERVAL 42 +#define __DRI_ATTRIB_BIND_TO_TEXTURE_RGB 43 +#define __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA 44 +#define __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE 45 +#define __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS 46 +#define __DRI_ATTRIB_YINVERTED 47 + +/* __DRI_ATTRIB_RENDER_TYPE */ +#define __DRI_ATTRIB_RGBA_BIT 0x01 +#define __DRI_ATTRIB_COLOR_INDEX_BIT 0x02 +#define __DRI_ATTRIB_LUMINANCE_BIT 0x04 + +/* __DRI_ATTRIB_CONFIG_CAVEAT */ +#define __DRI_ATTRIB_SLOW_BIT 0x01 +#define __DRI_ATTRIB_NON_CONFORMANT_CONFIG 0x02 + +/* __DRI_ATTRIB_TRANSPARENT_TYPE */ +#define __DRI_ATTRIB_TRANSPARENT_RGB 0x00 +#define __DRI_ATTRIB_TRANSPARENT_INDEX 0x01 + +/* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */ +#define __DRI_ATTRIB_TEXTURE_1D_BIT 0x01 +#define __DRI_ATTRIB_TEXTURE_2D_BIT 0x02 +#define __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT 0x04 + +/** + * This extension defines the core DRI functionality. + */ +#define __DRI_CORE "DRI_Core" +#define __DRI_CORE_VERSION 1 + +struct __DRIcoreExtensionRec { + __DRIextension base; + + __DRIscreen *(*createNewScreen)(int screen, int fd, + unsigned int sarea_handle, + const __DRIextension **extensions, + const __DRIconfig ***driverConfigs, + void *loaderPrivate); + + void (*destroyScreen)(__DRIscreen *screen); + + const __DRIextension **(*getExtensions)(__DRIscreen *screen); + + int (*getConfigAttrib)(const __DRIconfig *config, + unsigned int attrib, + unsigned int *value); + + int (*indexConfigAttrib)(const __DRIconfig *config, int index, + unsigned int *attrib, unsigned int *value); + + __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen, + const __DRIconfig *config, + unsigned int drawable_id, + unsigned int head, + void *loaderPrivate); + + void (*destroyDrawable)(__DRIdrawable *drawable); + + void (*swapBuffers)(__DRIdrawable *drawable); + + __DRIcontext *(*createNewContext)(__DRIscreen *screen, + const __DRIconfig *config, + __DRIcontext *shared, + void *loaderPrivate); + + int (*copyContext)(__DRIcontext *dest, + __DRIcontext *src, + unsigned long mask); + + void (*destroyContext)(__DRIcontext *context); + + int (*bindContext)(__DRIcontext *ctx, + __DRIdrawable *pdraw, + __DRIdrawable *pread); + + int (*unbindContext)(__DRIcontext *ctx); +}; + +/** + * Stored version of some component (i.e., server-side DRI module, kernel-side + * DRM, etc.). + * + * \todo + * There are several data structures that explicitly store a major version, + * minor version, and patch level. These structures should be modified to + * have a \c __DRIversionRec instead. + */ +struct __DRIversionRec { + int major; /**< Major version number. */ + int minor; /**< Minor version number. */ + int patch; /**< Patch-level. */ +}; + +/** + * Framebuffer information record. Used by libGL to communicate information + * about the framebuffer to the driver's \c __driCreateNewScreen function. + * + * In XFree86, most of this information is derrived from data returned by + * calling \c XF86DRIGetDeviceInfo. + * + * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen + * __driUtilCreateNewScreen CallCreateNewScreen + * + * \bug This structure could be better named. + */ +struct __DRIframebufferRec { + unsigned char *base; /**< Framebuffer base address in the CPU's + * address space. This value is calculated by + * calling \c drmMap on the framebuffer handle + * returned by \c XF86DRIGetDeviceInfo (or a + * similar function). + */ + int size; /**< Framebuffer size, in bytes. */ + int stride; /**< Number of bytes from one line to the next. */ + int width; /**< Pixel width of the framebuffer. */ + int height; /**< Pixel height of the framebuffer. */ + int dev_priv_size; /**< Size of the driver's dev-priv structure. */ + void *dev_priv; /**< Pointer to the driver's dev-priv structure. */ +}; + + +/** + * This extension provides alternative screen, drawable and context + * constructors for legacy DRI functionality. This is used in + * conjunction with the core extension. + */ +#define __DRI_LEGACY "DRI_Legacy" +#define __DRI_LEGACY_VERSION 1 + +struct __DRIlegacyExtensionRec { + __DRIextension base; + + __DRIscreen *(*createNewScreen)(int screen, + const __DRIversion *ddx_version, + const __DRIversion *dri_version, + const __DRIversion *drm_version, + const __DRIframebuffer *frame_buffer, + void *pSAREA, int fd, + const __DRIextension **extensions, + const __DRIconfig ***driver_configs, + void *loaderPrivate); + + __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen, + const __DRIconfig *config, + drm_drawable_t hwDrawable, + int renderType, const int *attrs, + void *loaderPrivate); + + __DRIcontext *(*createNewContext)(__DRIscreen *screen, + const __DRIconfig *config, + int render_type, + __DRIcontext *shared, + drm_context_t hwContext, + void *loaderPrivate); +}; + +/** + * This extension provides alternative screen, drawable and context + * constructors for swrast DRI functionality. This is used in + * conjunction with the core extension. + */ +#define __DRI_SWRAST "DRI_SWRast" +#define __DRI_SWRAST_VERSION 1 + +struct __DRIswrastExtensionRec { + __DRIextension base; + + __DRIscreen *(*createNewScreen)(int screen, + const __DRIextension **extensions, + const __DRIconfig ***driver_configs, + void *loaderPrivate); + + __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen, + const __DRIconfig *config, + void *loaderPrivate); +}; + +/** + * DRI2 Loader extension. + */ +#define __DRI_BUFFER_FRONT_LEFT 0 +#define __DRI_BUFFER_BACK_LEFT 1 +#define __DRI_BUFFER_FRONT_RIGHT 2 +#define __DRI_BUFFER_BACK_RIGHT 3 +#define __DRI_BUFFER_DEPTH 4 +#define __DRI_BUFFER_STENCIL 5 +#define __DRI_BUFFER_ACCUM 6 +#define __DRI_BUFFER_FAKE_FRONT_LEFT 7 +#define __DRI_BUFFER_FAKE_FRONT_RIGHT 8 +#define __DRI_BUFFER_DEPTH_STENCIL 9 /**< Only available with DRI2 1.1 */ + +struct __DRIbufferRec { + unsigned int attachment; + unsigned int name; + unsigned int pitch; + unsigned int cpp; + unsigned int flags; +}; + +#define __DRI_DRI2_LOADER "DRI_DRI2Loader" +#define __DRI_DRI2_LOADER_VERSION 3 +struct __DRIdri2LoaderExtensionRec { + __DRIextension base; + + __DRIbuffer *(*getBuffers)(__DRIdrawable *driDrawable, + int *width, int *height, + unsigned int *attachments, int count, + int *out_count, void *loaderPrivate); + + /** + * Flush pending front-buffer rendering + * + * Any rendering that has been performed to the + * \c __DRI_BUFFER_FAKE_FRONT_LEFT will be flushed to the + * \c __DRI_BUFFER_FRONT_LEFT. + * + * \param driDrawable Drawable whose front-buffer is to be flushed + * \param loaderPrivate Loader's private data that was previously passed + * into __DRIdri2ExtensionRec::createNewDrawable + */ + void (*flushFrontBuffer)(__DRIdrawable *driDrawable, void *loaderPrivate); + + + /** + * Get list of buffers from the server + * + * Gets a list of buffer for the specified set of attachments. Unlike + * \c ::getBuffers, this function takes a list of attachments paired with + * opaque \c unsigned \c int value describing the format of the buffer. + * It is the responsibility of the caller to know what the service that + * allocates the buffers will expect to receive for the format. + * + * \param driDrawable Drawable whose buffers are being queried. + * \param width Output where the width of the buffers is stored. + * \param height Output where the height of the buffers is stored. + * \param attachments List of pairs of attachment ID and opaque format + * requested for the drawable. + * \param count Number of attachment / format pairs stored in + * \c attachments. + * \param loaderPrivate Loader's private data that was previously passed + * into __DRIdri2ExtensionRec::createNewDrawable. + */ + __DRIbuffer *(*getBuffersWithFormat)(__DRIdrawable *driDrawable, + int *width, int *height, + unsigned int *attachments, int count, + int *out_count, void *loaderPrivate); +}; + +/** + * This extension provides alternative screen, drawable and context + * constructors for DRI2. + */ +#define __DRI_DRI2 "DRI_DRI2" +#define __DRI_DRI2_VERSION 2 + +#define __DRI_API_OPENGL 0 +#define __DRI_API_GLES 1 +#define __DRI_API_GLES2 2 + +struct __DRIdri2ExtensionRec { + __DRIextension base; + + __DRIscreen *(*createNewScreen)(int screen, int fd, + const __DRIextension **extensions, + const __DRIconfig ***driver_configs, + void *loaderPrivate); + + __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen, + const __DRIconfig *config, + void *loaderPrivate); + + __DRIcontext *(*createNewContext)(__DRIscreen *screen, + const __DRIconfig *config, + __DRIcontext *shared, + void *loaderPrivate); + + /* Since version 2 */ + unsigned int (*getAPIMask)(__DRIscreen *screen); + + __DRIcontext *(*createNewContextForAPI)(__DRIscreen *screen, + int api, + const __DRIconfig *config, + __DRIcontext *shared, + void *data); +}; + + +/** + * This extension provides functionality to enable various EGLImage + * extensions. + */ +#define __DRI_IMAGE "DRI_IMAGE" +#define __DRI_IMAGE_VERSION 1 + +/** + * These formats correspond to the similarly named MESA_FORMAT_* + * tokens, except in the native endian of the CPU. For example, on + * little endian __DRI_IMAGE_FORMAT_XRGB8888 corresponds to + * MESA_FORMAT_XRGB8888, but MESA_FORMAT_XRGB8888_REV on big endian. + */ +#define __DRI_IMAGE_FORMAT_RGB565 0x1001 +#define __DRI_IMAGE_FORMAT_XRGB8888 0x1002 +#define __DRI_IMAGE_FORMAT_ARGB8888 0x1003 + +#define __DRI_IMAGE_USE_SHARE 0x0001 +#define __DRI_IMAGE_USE_SCANOUT 0x0002 + +/** + * queryImage attributes + */ + +#define __DRI_IMAGE_ATTRIB_STRIDE 0x2000 +#define __DRI_IMAGE_ATTRIB_HANDLE 0x2001 +#define __DRI_IMAGE_ATTRIB_NAME 0x2002 + +typedef struct __DRIimageRec __DRIimage; +typedef struct __DRIimageExtensionRec __DRIimageExtension; +struct __DRIimageExtensionRec { + __DRIextension base; + + __DRIimage *(*createImageFromName)(__DRIscreen *screen, + int width, int height, int format, + int name, int pitch, + void *loaderPrivate); + + __DRIimage *(*createImageFromRenderbuffer)(__DRIcontext *context, + int renderbuffer, + void *loaderPrivate); + + void (*destroyImage)(__DRIimage *image); + + __DRIimage *(*createImage)(__DRIscreen *screen, + int width, int height, int format, + unsigned int use, + void *loaderPrivate); + + GLboolean (*queryImage)(__DRIimage *image, int attrib, int *value); +}; + + +/** + * This extension must be implemented by the loader and passed to the + * driver at screen creation time. The EGLImage entry points in the + * various client APIs take opaque EGLImage handles and use this + * extension to map them to a __DRIimage. At version 1, this + * extensions allows mapping EGLImage pointers to __DRIimage pointers, + * but future versions could support other EGLImage-like, opaque types + * with new lookup functions. + */ +#define __DRI_IMAGE_LOOKUP "DRI_IMAGE_LOOKUP" +#define __DRI_IMAGE_LOOKUP_VERSION 1 + +typedef struct __DRIimageLookupExtensionRec __DRIimageLookupExtension; +struct __DRIimageLookupExtensionRec { + __DRIextension base; + + __DRIimage *(*lookupEGLImage)(__DRIscreen *screen, void *image, + void *loaderPrivate); +}; + +/** + * This extension allows for common DRI2 options + */ +#define __DRI2_CONFIG_QUERY "DRI_CONFIG_QUERY" +#define __DRI2_CONFIG_QUERY_VERSION 1 + +typedef struct __DRI2configQueryExtensionRec __DRI2configQueryExtension; +struct __DRI2configQueryExtensionRec { + __DRIextension base; + + int (*configQueryb)(__DRIscreen *screen, const char *var, GLboolean *val); + int (*configQueryi)(__DRIscreen *screen, const char *var, GLint *val); + int (*configQueryf)(__DRIscreen *screen, const char *var, GLfloat *val); +}; +#endif diff --git a/include/GL/internal/sarea.h b/include/GL/internal/sarea.h new file mode 100644 index 0000000..a0d6084 --- /dev/null +++ b/include/GL/internal/sarea.h @@ -0,0 +1,92 @@ +/** + * \file sarea.h + * SAREA definitions. + * + * \author Kevin E. Martin + * \author Jens Owen + * \author Rickard E. (Rik) Faith + */ + +/* + * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. + * Copyright 2000 VA Linux Systems, 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 PRECISION INSIGHT 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 _SAREA_H_ +#define _SAREA_H_ + +#include "xf86drm.h" + +/* SAREA area needs to be at least a page */ +#if defined(__alpha__) +#define SAREA_MAX 0x2000 +#elif defined(__ia64__) +#define SAREA_MAX 0x10000 /* 64kB */ +#else +/* Intel 830M driver needs at least 8k SAREA */ +#define SAREA_MAX 0x2000 +#endif + +#define SAREA_MAX_DRAWABLES 256 + +#define SAREA_DRAWABLE_CLAIMED_ENTRY 0x80000000 + +/** + * SAREA per drawable information. + * + * \sa _XF86DRISAREA. + */ +typedef struct _XF86DRISAREADrawable { + unsigned int stamp; + unsigned int flags; +} XF86DRISAREADrawableRec, *XF86DRISAREADrawablePtr; + +/** + * SAREA frame information. + * + * \sa _XF86DRISAREA. + */ +typedef struct _XF86DRISAREAFrame { + unsigned int x; + unsigned int y; + unsigned int width; + unsigned int height; + unsigned int fullscreen; +} XF86DRISAREAFrameRec, *XF86DRISAREAFramePtr; + +/** + * SAREA definition. + */ +typedef struct _XF86DRISAREA { + /** first thing is always the DRM locking structure */ + drmLock lock; + /** \todo Use readers/writer lock for drawable_lock */ + drmLock drawable_lock; + XF86DRISAREADrawableRec drawableTable[SAREA_MAX_DRAWABLES]; + XF86DRISAREAFrameRec frame; + drm_context_t dummy_context; +} XF86DRISAREARec, *XF86DRISAREAPtr; + +#endif diff --git a/include/GL/mesa_wgl.h b/include/GL/mesa_wgl.h new file mode 100644 index 0000000..ca2e1b8 --- /dev/null +++ b/include/GL/mesa_wgl.h @@ -0,0 +1,121 @@ +/* + * Mesa 3-D graphics library + * Version: 3.1 + * + * Copyright (C) 1999 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. + */ + + +/* prototypes for the Mesa WGL functions */ +/* relocated here so that I could make GLUT get them properly */ + +#ifndef _mesa_wgl_h_ +#define _mesa_wgl_h_ + +#if defined(__MINGW32__) +# define __W32API_USE_DLLIMPORT__ +#endif + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifndef WGLAPI +#define WGLAPI GLAPI +#endif + +#if defined(__MINGW32__) +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN 1 +# endif +# include +#endif + + +#if defined(_WIN32) && !defined(_WINGDI_) && !defined(_GNU_H_WINDOWS32_DEFINES) && !defined(OPENSTEP) +#ifndef _GNU_H_WINDOWS32_FUNCTIONS +# ifdef UNICODE +# define wglUseFontBitmaps wglUseFontBitmapsW +# define wglUseFontOutlines wglUseFontOutlinesW +# else +# define wglUseFontBitmaps wglUseFontBitmapsA +# define wglUseFontOutlines wglUseFontOutlinesA +# endif /* !UNICODE */ +#endif /* _GNU_H_WINDOWS32_FUNCTIONS */ +typedef struct tagLAYERPLANEDESCRIPTOR LAYERPLANEDESCRIPTOR, *PLAYERPLANEDESCRIPTOR, *LPLAYERPLANEDESCRIPTOR; +typedef struct _GLYPHMETRICSFLOAT GLYPHMETRICSFLOAT, *PGLYPHMETRICSFLOAT, *LPGLYPHMETRICSFLOAT; +typedef struct tagPIXELFORMATDESCRIPTOR PIXELFORMATDESCRIPTOR, *PPIXELFORMATDESCRIPTOR, *LPPIXELFORMATDESCRIPTOR; +#endif + + +#ifdef _MSC_VER +# pragma warning( disable : 4615 ) /* pragma warning : unknown user warning type*/ +# pragma warning( push ) +# pragma warning( disable : 4273 ) /* 'function' : inconsistent DLL linkage. dllexport assumed. */ +#endif + + +WGLAPI int GLAPIENTRY wglSetPixelFormat(HDC, int, const PIXELFORMATDESCRIPTOR *); +WGLAPI int GLAPIENTRY wglSwapBuffers(HDC hdc); +WGLAPI int GLAPIENTRY wglChoosePixelFormat(HDC, const PIXELFORMATDESCRIPTOR *); +WGLAPI int GLAPIENTRY wglDescribePixelFormat(HDC,int, unsigned int, LPPIXELFORMATDESCRIPTOR); +WGLAPI int GLAPIENTRY wglGetPixelFormat(HDC hdc); + +WGLAPI int GLAPIENTRY wglCopyContext(HGLRC, HGLRC, unsigned int); +WGLAPI HGLRC GLAPIENTRY wglCreateContext(HDC); +WGLAPI HGLRC GLAPIENTRY wglCreateLayerContext(HDC,int); +WGLAPI int GLAPIENTRY wglDeleteContext(HGLRC); +WGLAPI int GLAPIENTRY wglDescribeLayerPlane(HDC, int, int, unsigned int,LPLAYERPLANEDESCRIPTOR); +WGLAPI HGLRC GLAPIENTRY wglGetCurrentContext(void); +WGLAPI HDC GLAPIENTRY wglGetCurrentDC(void); +WGLAPI int GLAPIENTRY wglGetLayerPaletteEntries(HDC, int, int, int,COLORREF *); +WGLAPI PROC GLAPIENTRY wglGetProcAddress(const char*); +WGLAPI int GLAPIENTRY wglMakeCurrent(HDC,HGLRC); +WGLAPI int GLAPIENTRY wglRealizeLayerPalette(HDC, int, int); +WGLAPI int GLAPIENTRY wglSetLayerPaletteEntries(HDC, int, int, int,const COLORREF *); +WGLAPI int GLAPIENTRY wglShareLists(HGLRC, HGLRC); +WGLAPI int GLAPIENTRY wglSwapLayerBuffers(HDC, unsigned int); +WGLAPI int GLAPIENTRY wglUseFontBitmapsA(HDC, unsigned long, unsigned long, unsigned long); +WGLAPI int GLAPIENTRY wglUseFontBitmapsW(HDC, unsigned long, unsigned long, unsigned long); +WGLAPI int GLAPIENTRY wglUseFontOutlinesA(HDC, unsigned long, unsigned long, unsigned long, float,float, int, LPGLYPHMETRICSFLOAT); +WGLAPI int GLAPIENTRY wglUseFontOutlinesW(HDC, unsigned long, unsigned long, unsigned long, float,float, int, LPGLYPHMETRICSFLOAT); + +#ifndef __MINGW32__ +WGLAPI int GLAPIENTRY SwapBuffers(HDC); +WGLAPI int GLAPIENTRY ChoosePixelFormat(HDC,const PIXELFORMATDESCRIPTOR *); +WGLAPI int GLAPIENTRY DescribePixelFormat(HDC,int,unsigned int,LPPIXELFORMATDESCRIPTOR); +WGLAPI int GLAPIENTRY GetPixelFormat(HDC); +WGLAPI int GLAPIENTRY SetPixelFormat(HDC,int,const PIXELFORMATDESCRIPTOR *); +#endif + + +#ifdef _MSC_VER +# pragma warning( pop ) +#endif + +#ifdef __cplusplus +} +#endif + + +#endif /* _mesa_wgl_h_ */ diff --git a/include/GL/osmesa.h b/include/GL/osmesa.h new file mode 100644 index 0000000..56fa23c --- /dev/null +++ b/include/GL/osmesa.h @@ -0,0 +1,289 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 1999-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. + */ + + +/* + * Mesa Off-Screen rendering interface. + * + * This is an operating system and window system independent interface to + * Mesa which allows one to render images into a client-supplied buffer in + * main memory. Such images may manipulated or saved in whatever way the + * client wants. + * + * These are the API functions: + * OSMesaCreateContext - create a new Off-Screen Mesa rendering context + * OSMesaMakeCurrent - bind an OSMesaContext to a client's image buffer + * and make the specified context the current one. + * OSMesaDestroyContext - destroy an OSMesaContext + * OSMesaGetCurrentContext - return thread's current context ID + * OSMesaPixelStore - controls how pixels are stored in image buffer + * OSMesaGetIntegerv - return OSMesa state parameters + * + * + * The limits on the width and height of an image buffer are MAX_WIDTH and + * MAX_HEIGHT as defined in Mesa/src/config.h. Defaults are 1280 and 1024. + * You can increase them as needed but beware that many temporary arrays in + * Mesa are dimensioned by MAX_WIDTH or MAX_HEIGHT. + */ + + +#ifndef OSMESA_H +#define OSMESA_H + + +#ifdef __cplusplus +extern "C" { +#endif + + +#include + + +#define OSMESA_MAJOR_VERSION 6 +#define OSMESA_MINOR_VERSION 5 +#define OSMESA_PATCH_VERSION 0 + + + +/* + * Values for the format parameter of OSMesaCreateContext() + * New in version 2.0. + */ +#define OSMESA_COLOR_INDEX GL_COLOR_INDEX +#define OSMESA_RGBA GL_RGBA +#define OSMESA_BGRA 0x1 +#define OSMESA_ARGB 0x2 +#define OSMESA_RGB GL_RGB +#define OSMESA_BGR 0x4 +#define OSMESA_RGB_565 0x5 + + +/* + * OSMesaPixelStore() parameters: + * New in version 2.0. + */ +#define OSMESA_ROW_LENGTH 0x10 +#define OSMESA_Y_UP 0x11 + + +/* + * Accepted by OSMesaGetIntegerv: + */ +#define OSMESA_WIDTH 0x20 +#define OSMESA_HEIGHT 0x21 +#define OSMESA_FORMAT 0x22 +#define OSMESA_TYPE 0x23 +#define OSMESA_MAX_WIDTH 0x24 /* new in 4.0 */ +#define OSMESA_MAX_HEIGHT 0x25 /* new in 4.0 */ + + +typedef struct osmesa_context *OSMesaContext; + + +#if defined(__BEOS__) || defined(__QUICKDRAW__) +#pragma export on +#endif + + +/* + * Create an Off-Screen Mesa rendering context. The only attribute needed is + * an RGBA vs Color-Index mode flag. + * + * Input: format - one of OSMESA_COLOR_INDEX, OSMESA_RGBA, OSMESA_BGRA, + * OSMESA_ARGB, OSMESA_RGB, or OSMESA_BGR. + * sharelist - specifies another OSMesaContext with which to share + * display lists. NULL indicates no sharing. + * Return: an OSMesaContext or 0 if error + */ +GLAPI OSMesaContext GLAPIENTRY +OSMesaCreateContext( GLenum format, OSMesaContext sharelist ); + + + +/* + * Create an Off-Screen Mesa rendering context and specify desired + * size of depth buffer, stencil buffer and accumulation buffer. + * If you specify zero for depthBits, stencilBits, accumBits you + * can save some memory. + * + * New in Mesa 3.5 + */ +GLAPI OSMesaContext GLAPIENTRY +OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits, + GLint accumBits, OSMesaContext sharelist); + + +/* + * Destroy an Off-Screen Mesa rendering context. + * + * Input: ctx - the context to destroy + */ +GLAPI void GLAPIENTRY +OSMesaDestroyContext( OSMesaContext ctx ); + + + +/* + * Bind an OSMesaContext to an image buffer. The image buffer is just a + * block of memory which the client provides. Its size must be at least + * as large as width*height*sizeof(type). Its address should be a multiple + * of 4 if using RGBA mode. + * + * Image data is stored in the order of glDrawPixels: row-major order + * with the lower-left image pixel stored in the first array position + * (ie. bottom-to-top). + * + * Since the only type initially supported is GL_UNSIGNED_BYTE, if the + * context is in RGBA mode, each pixel will be stored as a 4-byte RGBA + * value. If the context is in color indexed mode, each pixel will be + * stored as a 1-byte value. + * + * If the context's viewport hasn't been initialized yet, it will now be + * initialized to (0,0,width,height). + * + * Input: ctx - the rendering context + * buffer - the image buffer memory + * type - data type for pixel components, only GL_UNSIGNED_BYTE + * supported now + * width, height - size of image buffer in pixels, at least 1 + * Return: GL_TRUE if success, GL_FALSE if error because of invalid ctx, + * invalid buffer address, type!=GL_UNSIGNED_BYTE, width<1, height<1, + * width>internal limit or height>internal limit. + */ +GLAPI GLboolean GLAPIENTRY +OSMesaMakeCurrent( OSMesaContext ctx, void *buffer, GLenum type, + GLsizei width, GLsizei height ); + + + + +/* + * Return the current Off-Screen Mesa rendering context handle. + */ +GLAPI OSMesaContext GLAPIENTRY +OSMesaGetCurrentContext( void ); + + + +/* + * Set pixel store/packing parameters for the current context. + * This is similar to glPixelStore. + * Input: pname - OSMESA_ROW_LENGTH + * specify actual pixels per row in image buffer + * 0 = same as image width (default) + * OSMESA_Y_UP + * zero = Y coordinates increase downward + * non-zero = Y coordinates increase upward (default) + * value - the value for the parameter pname + * + * New in version 2.0. + */ +GLAPI void GLAPIENTRY +OSMesaPixelStore( GLint pname, GLint value ); + + + +/* + * Return an integer value like glGetIntegerv. + * Input: pname - + * OSMESA_WIDTH return current image width + * OSMESA_HEIGHT return current image height + * OSMESA_FORMAT return image format + * OSMESA_TYPE return color component data type + * OSMESA_ROW_LENGTH return row length in pixels + * OSMESA_Y_UP returns 1 or 0 to indicate Y axis direction + * value - pointer to integer in which to return result. + */ +GLAPI void GLAPIENTRY +OSMesaGetIntegerv( GLint pname, GLint *value ); + + + +/* + * Return the depth buffer associated with an OSMesa context. + * Input: c - the OSMesa context + * Output: width, height - size of buffer in pixels + * bytesPerValue - bytes per depth value (2 or 4) + * buffer - pointer to depth buffer values + * Return: GL_TRUE or GL_FALSE to indicate success or failure. + * + * New in Mesa 2.4. + */ +GLAPI GLboolean GLAPIENTRY +OSMesaGetDepthBuffer( OSMesaContext c, GLint *width, GLint *height, + GLint *bytesPerValue, void **buffer ); + + + +/* + * Return the color buffer associated with an OSMesa context. + * Input: c - the OSMesa context + * Output: width, height - size of buffer in pixels + * format - buffer format (OSMESA_FORMAT) + * buffer - pointer to depth buffer values + * Return: GL_TRUE or GL_FALSE to indicate success or failure. + * + * New in Mesa 3.3. + */ +GLAPI GLboolean GLAPIENTRY +OSMesaGetColorBuffer( OSMesaContext c, GLint *width, GLint *height, + GLint *format, void **buffer ); + + + +/** + * This typedef is new in Mesa 6.3. + */ +typedef void (*OSMESAproc)(); + + +/* + * Return pointer to the named function. + * New in Mesa 4.1 + * Return OSMESAproc in 6.3. + */ +GLAPI OSMESAproc GLAPIENTRY +OSMesaGetProcAddress( const char *funcName ); + + + +/** + * Enable/disable color clamping, off by default. + * New in Mesa 6.4.2 + */ +GLAPI void GLAPIENTRY +OSMesaColorClamp(GLboolean enable); + + +#if defined(__BEOS__) || defined(__QUICKDRAW__) +#pragma export off +#endif + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/include/GL/vms_x_fix.h b/include/GL/vms_x_fix.h new file mode 100644 index 0000000..24cba47 --- /dev/null +++ b/include/GL/vms_x_fix.h @@ -0,0 +1,1224 @@ +/*************************************************************************** + * * + * Author : Jouk Jansen (joukj@hrem.nano.tudelft.nl) * + * * + * Last revision : 31 August 2006 * + * * + * Repair definitions of Runtime library functions when compiling with * + * /name=(as_is) on OpenVMS * + * * + ***************************************************************************/ + +#ifndef VMS_X_FIX +#define VMS_X_FIX + +#define decw$_select DECW$_SELECT +#define DtSaverGetWindows DTSAVERGETWINDOWS +#define MrmFetchWidget MRMFETCHWIDGET +#define MrmInitialize MRMINITIALIZE +#define MrmOpenHierarchy MRMOPENHIERARCHY +#define MrmRegisterNames MRMREGISTERNAMES +#define XAddExtension XADDEXTENSION +#define XAddHosts XADDHOSTS +#define XAllocClassHint XALLOCCLASSHINT +#define XAllocColor XALLOCCOLOR +#define XAllocColorCells XALLOCCOLORCELLS +#define XAllocIconSize XALLOCICONSIZE +#define XAllocNamedColor XALLOCNAMEDCOLOR +#define XAllocSizeHints XALLOCSIZEHINTS +#define XAllocStandardColormap XALLOCSTANDARDCOLORMAP +#define XAllocWMHints XALLOCWMHINTS +#define XAllowEvents XALLOWEVENTS +#define XAutoRepeatOff XAUTOREPEATOFF +#define XAutoRepeatOn XAUTOREPEATON +#define XBaseFontNameListOfFontSet XBASEFONTNAMELISTOFFONTSET +#define XBell XBELL +#define XBitmapPad XBITMAPPAD +#define XBlackPixel XBLACKPIXEL +#define XBlackPixelOfScreen XBLACKPIXELOFSCREEN +#define XCellsOfScreen XCELLSOFSCREEN +#define XChangeActivePointerGrab XCHANGEACTIVEPOINTERGRAB +#define XChangeGC XCHANGEGC +#define XChangeKeyboardControl XCHANGEKEYBOARDCONTROL +#define XChangePointerControl XCHANGEPOINTERCONTROL +#define XChangeProperty XCHANGEPROPERTY +#define XChangeWindowAttributes XCHANGEWINDOWATTRIBUTES +#define XCheckIfEvent XCHECKIFEVENT +#define XCheckMaskEvent XCHECKMASKEVENT +#define XCheckTypedEvent XCHECKTYPEDEVENT +#define XCheckTypedWindowEvent XCHECKTYPEDWINDOWEVENT +#define XCheckWindowEvent XCHECKWINDOWEVENT +#define XClearArea XCLEARAREA +#define XClearWindow XCLEARWINDOW +#define XClipBox XCLIPBOX +#define XCloseDisplay XCLOSEDISPLAY +#define XCloseIM XCLOSEIM +#define XConfigureWindow XCONFIGUREWINDOW +#define XConvertSelection XCONVERTSELECTION +#define XCopyArea XCOPYAREA +#define XCopyColormapAndFree XCOPYCOLORMAPANDFREE +#define XCopyGC XCOPYGC +#define XCopyPlane XCOPYPLANE +#define XCreateBitmapFromData XCREATEBITMAPFROMDATA +#define XCreateColormap XCREATECOLORMAP +#define XCreateFontCursor XCREATEFONTCURSOR +#define XCreateFontSet XCREATEFONTSET +#define XCreateGC XCREATEGC +#define XCreateGlyphCursor XCREATEGLYPHCURSOR +#define XCreateIC XCREATEIC +#define XCreateImage XCREATEIMAGE +#define XCreatePixmap XCREATEPIXMAP +#define XCreatePixmapCursor XCREATEPIXMAPCURSOR +#define XCreatePixmapFromBitmapData XCREATEPIXMAPFROMBITMAPDATA +#define XCreateRegion XCREATEREGION +#define XCreateSimpleWindow XCREATESIMPLEWINDOW +#define XCreateWindow XCREATEWINDOW +#define XDefaultColormap XDEFAULTCOLORMAP +#define XDefaultColormapOfScreen XDEFAULTCOLORMAPOFSCREEN +#define XDefaultDepth XDEFAULTDEPTH +#define XDefaultDepthOfScreen XDEFAULTDEPTHOFSCREEN +#define XDefaultGC XDEFAULTGC +#define XDefaultRootWindow XDEFAULTROOTWINDOW +#define XDefaultScreen XDEFAULTSCREEN +#define XDefaultScreenOfDisplay XDEFAULTSCREENOFDISPLAY +#define XDefaultVisual XDEFAULTVISUAL +#define XDefaultVisualOfScreen XDEFAULTVISUALOFSCREEN +#define XDefineCursor XDEFINECURSOR +#define XDeleteContext XDELETECONTEXT +#define XDeleteProperty XDELETEPROPERTY +#define XDestroyIC XDESTROYIC +#define XDestroyRegion XDESTROYREGION +#define XDestroySubwindows XDESTROYSUBWINDOWS +#define XDestroyWindow XDESTROYWINDOW +#define XDisableAccessControl XDISABLEACCESSCONTROL +#define XDisplayCells XDISPLAYCELLS +#define XDisplayHeight XDISPLAYHEIGHT +#define XDisplayKeycodes XDISPLAYKEYCODES +#define XDisplayName XDISPLAYNAME +#define XDisplayOfIM XDISPLAYOFIM +#define XDisplayOfScreen XDISPLAYOFSCREEN +#define XDisplayString XDISPLAYSTRING +#define XDisplayWidth XDISPLAYWIDTH +#define XDoesBackingStore XDOESBACKINGSTORE +#define XDrawArc XDRAWARC +#define XDrawArcs XDRAWARCS +#define XDrawImageString XDRAWIMAGESTRING +#define XDrawImageString16 XDRAWIMAGESTRING16 +#define XDrawLine XDRAWLINE +#define XDrawLines XDRAWLINES +#define XDrawPoint XDRAWPOINT +#define XDrawPoints XDRAWPOINTS +#define XDrawRectangle XDRAWRECTANGLE +#define XDrawRectangles XDRAWRECTANGLES +#define XDrawSegments XDRAWSEGMENTS +#define XDrawString XDRAWSTRING +#define XDrawString16 XDRAWSTRING16 +#define XDrawText XDRAWTEXT +#define XDrawText16 XDRAWTEXT16 +#define XESetCloseDisplay XESETCLOSEDISPLAY +#define XEmptyRegion XEMPTYREGION +#define XEnableAccessControl XENABLEACCESSCONTROL +#define XEqualRegion XEQUALREGION +#define XEventsQueued XEVENTSQUEUED +#define XExtendedMaxRequestSize XEXTENDEDMAXREQUESTSIZE +#define XExtentsOfFontSet XEXTENTSOFFONTSET +#define XFetchBuffer XFETCHBUFFER +#define XFetchBytes XFETCHBYTES +#define XFetchName XFETCHNAME +#define XFillArc XFILLARC +#define XFillArcs XFILLARCS +#define XFillPolygon XFILLPOLYGON +#define XFillRectangle XFILLRECTANGLE +#define XFillRectangles XFILLRECTANGLES +#define XFilterEvent XFILTEREVENT +#define XFindContext XFINDCONTEXT +#define XFlush XFLUSH +#define XFontsOfFontSet XFONTSOFFONTSET +#define XForceScreenSaver XFORCESCREENSAVER +#define XFree XFREE +#define XFreeColormap XFREECOLORMAP +#define XFreeColors XFREECOLORS +#define XFreeCursor XFREECURSOR +#define XFreeDeviceList XFREEDEVICELIST +#define XFreeDeviceState XFREEDEVICESTATE +#define XFreeFont XFREEFONT +#define XFreeFontInfo XFREEFONTINFO +#define XFreeFontNames XFREEFONTNAMES +#define XFreeFontSet XFREEFONTSET +#define XFreeGC XFREEGC +#define XFreeModifiermap XFREEMODIFIERMAP +#define XFreePixmap XFREEPIXMAP +#define XFreeStringList XFREESTRINGLIST +#define XGContextFromGC XGCONTEXTFROMGC +#define XGeometry XGEOMETRY +#define XGetAtomName XGETATOMNAME +#define XGetClassHint XGETCLASSHINT +#define XGetCommand XGETCOMMAND +#define XGetDefault XGETDEFAULT +#define XGetErrorDatabaseText XGETERRORDATABASETEXT +#define XGetErrorText XGETERRORTEXT +#define XGetExtensionVersion XGETEXTENSIONVERSION +#define XGetFontProperty XGETFONTPROPERTY +#define XGetGCValues XGETGCVALUES +#define XGetGeometry XGETGEOMETRY +#define XGetICValues XGETICVALUES +#define XGetIMValues XGETIMVALUES +#define XGetIconName XGETICONNAME +#define XGetIconSizes XGETICONSIZES +#define XGetImage XGETIMAGE +#define XGetInputFocus XGETINPUTFOCUS +#define XGetKeyboardControl XGETKEYBOARDCONTROL +#define XGetKeyboardMapping XGETKEYBOARDMAPPING +#define XGetModifierMapping XGETMODIFIERMAPPING +#define XGetMotionEvents XGETMOTIONEVENTS +#define XGetNormalHints XGETNORMALHINTS +#define XGetPointerControl XGETPOINTERCONTROL +#define XGetPointerMapping XGETPOINTERMAPPING +#define XGetRGBColormaps XGETRGBCOLORMAPS +#define XGetScreenSaver XGETSCREENSAVER +#define XGetSelectionOwner XGETSELECTIONOWNER +#define XGetStandardColormap XGETSTANDARDCOLORMAP +#define XGetSubImage XGETSUBIMAGE +#define XGetTextProperty XGETTEXTPROPERTY +#define XGetVisualInfo XGETVISUALINFO +#define XGetWMColormapWindows XGETWMCOLORMAPWINDOWS +#define XGetWMHints XGETWMHINTS +#define XGetWMIconName XGETWMICONNAME +#define XGetWMName XGETWMNAME +#define XGetWMNormalHints XGETWMNORMALHINTS +#define XGetWindowAttributes XGETWINDOWATTRIBUTES +#define XGetWindowProperty XGETWINDOWPROPERTY +#define XGrabButton XGRABBUTTON +#define XGrabKeyboard XGRABKEYBOARD +#define XGrabPointer XGRABPOINTER +#define XGrabServer XGRABSERVER +#define XHeightMMOfScreen XHEIGHTMMOFSCREEN +#define XHeightOfScreen XHEIGHTOFSCREEN +#define XIconifyWindow XICONIFYWINDOW +#define XIfEvent XIFEVENT +#define XInitExtension XINITEXTENSION +#define XInitImage XINITIMAGE +#define XInstallColormap XINSTALLCOLORMAP +#define XInternAtom XINTERNATOM +#define XInternAtoms XINTERNATOMS +#define XIntersectRegion XINTERSECTREGION +#define XKeycodeToKeysym XKEYCODETOKEYSYM +#define XKeysymToKeycode XKEYSYMTOKEYCODE +#define XKeysymToString XKEYSYMTOSTRING +#define XKillClient XKILLCLIENT +#define XListDepths XLISTDEPTHS +#define XListFonts XLISTFONTS +#define XListFontsWithInfo XLISTFONTSWITHINFO +#define XListHosts XLISTHOSTS +#define XListInputDevices XLISTINPUTDEVICES +#define XListInstalledColormaps XLISTINSTALLEDCOLORMAPS +#define XListPixmapFormats XLISTPIXMAPFORMATS +#define XListProperties XLISTPROPERTIES +#define XLoadFont XLOADFONT +#define XLoadQueryFont XLOADQUERYFONT +#define XLookupColor XLOOKUPCOLOR +#define XLookupKeysym XLOOKUPKEYSYM +#define XLookupString XLOOKUPSTRING +#define XLowerWindow XLOWERWINDOW +#define XMapRaised XMAPRAISED +#define XMapSubwindows XMAPSUBWINDOWS +#define XMapWindow XMAPWINDOW +#define XMaskEvent XMASKEVENT +#define XMatchVisualInfo XMATCHVISUALINFO +#define XMaxRequestSize XMAXREQUESTSIZE +#define XMissingExtension XMISSINGEXTENSION +#define XMoveResizeWindow XMOVERESIZEWINDOW +#define XMoveWindow XMOVEWINDOW +#define XNextEvent XNEXTEVENT +#define XNextRequest XNEXTREQUEST +#define XNoOp XNOOP +#define XOffsetRegion XOFFSETREGION +#define XOpenDevice XOPENDEVICE +#define XOpenDisplay XOPENDISPLAY +#define XOpenIM XOPENIM +#define XParseColor XPARSECOLOR +#define XParseGeometry XPARSEGEOMETRY +#define XPeekEvent XPEEKEVENT +#define XPeekIfEvent XPEEKIFEVENT +#define XPending XPENDING +#define XPointInRegion XPOINTINREGION +#define XPolygonRegion XPOLYGONREGION +#define XPutBackEvent XPUTBACKEVENT +#define XPutImage XPUTIMAGE +#define XQLength XQLENGTH +#define XQueryBestCursor XQUERYBESTCURSOR +#define XQueryBestStipple XQUERYBESTSTIPPLE +#define XQueryColor XQUERYCOLOR +#define XQueryColors XQUERYCOLORS +#define XQueryDeviceState XQUERYDEVICESTATE +#define XQueryExtension XQUERYEXTENSION +#define XQueryFont XQUERYFONT +#define XQueryKeymap XQUERYKEYMAP +#define XQueryPointer XQUERYPOINTER +#define XQueryTree XQUERYTREE +#define XRaiseWindow XRAISEWINDOW +#define XReadBitmapFile XREADBITMAPFILE +#define XRecolorCursor XRECOLORCURSOR +#define XReconfigureWMWindow XRECONFIGUREWMWINDOW +#define XRectInRegion XRECTINREGION +#define XRefreshKeyboardMapping XREFRESHKEYBOARDMAPPING +#define XRemoveHosts XREMOVEHOSTS +#define XReparentWindow XREPARENTWINDOW +#define XResetScreenSaver XRESETSCREENSAVER +#define XResizeWindow XRESIZEWINDOW +#define XResourceManagerString XRESOURCEMANAGERSTRING +#define XRestackWindows XRESTACKWINDOWS +#define XRotateBuffers XROTATEBUFFERS +#define XRootWindow XROOTWINDOW +#define XRootWindowOfScreen XROOTWINDOWOFSCREEN +#define XSaveContext XSAVECONTEXT +#define XScreenNumberOfScreen XSCREENNUMBEROFSCREEN +#define XScreenOfDisplay XSCREENOFDISPLAY +#define XSelectAsyncEvent XSELECTASYNCEVENT +#define XSelectAsyncInput XSELECTASYNCINPUT +#define XSelectExtensionEvent XSELECTEXTENSIONEVENT +#define XSelectInput XSELECTINPUT +#define XSendEvent XSENDEVENT +#define XServerVendor XSERVERVENDOR +#define XSetArcMode XSETARCMODE +#define XSetBackground XSETBACKGROUND +#define XSetClassHint XSETCLASSHINT +#define XSetClipMask XSETCLIPMASK +#define XSetClipOrigin XSETCLIPORIGIN +#define XSetClipRectangles XSETCLIPRECTANGLES +#define XSetCloseDownMode XSETCLOSEDOWNMODE +#define XSetCommand XSETCOMMAND +#define XSetDashes XSETDASHES +#define XSetErrorHandler XSETERRORHANDLER +#define XSetExtensionErrorHandler XSETEXTENSIONERRORHANDLER +#define XSetFillRule XSETFILLRULE +#define XSetFillStyle XSETFILLSTYLE +#define XSetFont XSETFONT +#define XSetForeground XSETFOREGROUND +#define XSetFunction XSETFUNCTION +#define XSetGraphicsExposures XSETGRAPHICSEXPOSURES +#define XSetICFocus XSETICFOCUS +#define XSetICValues XSETICVALUES +#define XSetIOErrorHandler XSETIOERRORHANDLER +#define XSetIconName XSETICONNAME +#define XSetInputFocus XSETINPUTFOCUS +#define XSetLineAttributes XSETLINEATTRIBUTES +#define XSetLocaleModifiers XSETLOCALEMODIFIERS +#define XSetNormalHints XSETNORMALHINTS +#define XSetPlaneMask XSETPLANEMASK +#define XSetRegion XSETREGION +#define XSetRGBColormaps XSETRGBCOLORMAPS +#define XSetScreenSaver XSETSCREENSAVER +#define XSetSelectionOwner XSETSELECTIONOWNER +#define XSetStandardProperties XSETSTANDARDPROPERTIES +#define XSetState XSETSTATE +#define XSetStipple XSETSTIPPLE +#define XSetSubwindowMode XSETSUBWINDOWMODE +#define XSetTSOrigin XSETTSORIGIN +#define XSetTextProperty XSETTEXTPROPERTY +#define XSetTile XSETTILE +#define XSetTransientForHint XSETTRANSIENTFORHINT +#define XSetWMClientMachine XSETWMCLIENTMACHINE +#define XSetWMColormapWindows XSETWMCOLORMAPWINDOWS +#define XSetWMHints XSETWMHINTS +#define XSetWMIconName XSETWMICONNAME +#define XSetWMName XSETWMNAME +#define XSetWMNormalHints XSETWMNORMALHINTS +#define XSetWMProperties XSETWMPROPERTIES +#define XSetWMProtocols XSETWMPROTOCOLS +#define XSetWMSizeHints XSETWMSIZEHINTS +#define XSetWindowBackground XSETWINDOWBACKGROUND +#define XSetWindowBackgroundPixmap XSETWINDOWBACKGROUNDPIXMAP +#define XSetWindowBorder XSETWINDOWBORDER +#define XSetWindowBorderPixmap XSETWINDOWBORDERPIXMAP +#define XSetWindowBorderWidth XSETWINDOWBORDERWIDTH +#define XSetWindowColormap XSETWINDOWCOLORMAP +#define XShapeCombineMask XSHAPECOMBINEMASK +#define XShapeCombineRectangles XSHAPECOMBINERECTANGLES +#define XShapeGetRectangles XSHAPEGETRECTANGLES +#define XShapeQueryExtension XSHAPEQUERYEXTENSION +#define XShmAttach XSHMATTACH +#define XShmCreateImage XSHMCREATEIMAGE +#define XShmCreatePixmap XSHMCREATEPIXMAP +#define XShmDetach XSHMDETACH +#define XShmGetEventBase XSHMGETEVENTBASE +#define XShmPutImage XSHMPUTIMAGE +#define XShmQueryExtension XSHMQUERYEXTENSION +#define XShmQueryVersion XSHMQUERYVERSION +#define XShrinkRegion XSHRINKREGION +#define XStoreBuffer XSTOREBUFFER +#define XStoreBytes XSTOREBYTES +#define XStoreColor XSTORECOLOR +#define XStoreColors XSTORECOLORS +#define XStoreName XSTORENAME +#define XStringListToTextProperty XSTRINGLISTTOTEXTPROPERTY +#define XStringToKeysym XSTRINGTOKEYSYM +#define XSubtractRegion XSUBTRACTREGION +#define XSupportsLocale XSUPPORTSLOCALE +#define XSync XSYNC +#define XSynchronize XSYNCHRONIZE +#define XTextExtents XTEXTEXTENTS +#define XTextExtents16 XTEXTEXTENTS16 +#define XTextPropertyToStringList XTEXTPROPERTYTOSTRINGLIST +#define XTextWidth XTEXTWIDTH +#define XTextWidth16 XTEXTWIDTH16 +#define XTranslateCoordinates XTRANSLATECOORDINATES +#define XUndefineCursor XUNDEFINECURSOR +#define XUngrabButton XUNGRABBUTTON +#define XUngrabKeyboard XUNGRABKEYBOARD +#define XUngrabPointer XUNGRABPOINTER +#define XUngrabServer XUNGRABSERVER +#define XUninstallColormap XUNINSTALLCOLORMAP +#define XUnionRectWithRegion XUNIONRECTWITHREGION +#define XUnionRegion XUNIONREGION +#define XUniqueContext XUNIQUECONTEXT +#define XUnloadFont XUNLOADFONT +#define XUnmapWindow XUNMAPWINDOW +#define XUnsetICFocus XUNSETICFOCUS +#define XVaCreateNestedList XVACREATENESTEDLIST +#define XVisualIDFromVisual XVISUALIDFROMVISUAL +#define XWMGeometry XWMGEOMETRY +#define XWarpPointer XWARPPOINTER +#define XWhitePixel XWHITEPIXEL +#define XWhitePixelOfScreen XWHITEPIXELOFSCREEN +#define XWidthMMOfScreen XWIDTHMMOFSCREEN +#define XWidthOfScreen XWIDTHOFSCREEN +#define XWindowEvent XWINDOWEVENT +#define XWithdrawWindow XWITHDRAWWINDOW +#define XXorRegion XXORREGION +#define XcmsQueryColor XCMSQUERYCOLOR +#define XdbeAllocateBackBufferName XDBEALLOCATEBACKBUFFERNAME +#define XdbeFreeVisualInfo XDBEFREEVISUALINFO +#define XdbeGetVisualInfo XDBEGETVISUALINFO +#define XdbeQueryExtension XDBEQUERYEXTENSION +#define XdbeSwapBuffers XDBESWAPBUFFERS +#define XextAddDisplay XEXTADDDISPLAY +#define XextFindDisplay XEXTFINDDISPLAY +#define XextRemoveDisplay XEXTREMOVEDISPLAY +#define XkbSetDetectableAutoRepeat XKBSETDETECTABLEAUTOREPEAT +#define XmActivateProtocol XMACTIVATEPROTOCOL +#define XmAddProtocolCallback XMADDPROTOCOLCALLBACK +#define XmAddProtocols XMADDPROTOCOLS +#define XmChangeColor XMCHANGECOLOR +#define XmClipboardCopy XMCLIPBOARDCOPY +#define XmClipboardCopyByName XMCLIPBOARDCOPYBYNAME +#define XmClipboardEndCopy XMCLIPBOARDENDCOPY +#define XmClipboardEndRetrieve XMCLIPBOARDENDRETRIEVE +#define XmClipboardInquireCount XMCLIPBOARDINQUIRECOUNT +#define XmClipboardInquireFormat XMCLIPBOARDINQUIREFORMAT +#define XmClipboardInquireLength XMCLIPBOARDINQUIRELENGTH +#define XmClipboardLock XMCLIPBOARDLOCK +#define XmClipboardRetrieve XMCLIPBOARDRETRIEVE +#define XmClipboardStartCopy XMCLIPBOARDSTARTCOPY +#define XmClipboardStartRetrieve XMCLIPBOARDSTARTRETRIEVE +#define XmClipboardUnlock XMCLIPBOARDUNLOCK +#define XmCommandError XMCOMMANDERROR +#define XmCommandGetChild XMCOMMANDGETCHILD +#define XmCommandSetValue XMCOMMANDSETVALUE +#define XmCreateArrowButton XMCREATEARROWBUTTON +#define XmCreateArrowButtonGadget XMCREATEARROWBUTTONGADGET +#define XmCreateBulletinBoardDialog XMCREATEBULLETINBOARDDIALOG +#define XmCreateCascadeButton XMCREATECASCADEBUTTON +#define XmCreateCascadeButtonGadget XMCREATECASCADEBUTTONGADGET +#define XmCreateDialogShell XMCREATEDIALOGSHELL +#define XmCreateDragIcon XMCREATEDRAGICON +#define XmCreateDrawingArea XMCREATEDRAWINGAREA +#define XmCreateDrawnButton XMCREATEDRAWNBUTTON +#define XmCreateErrorDialog XMCREATEERRORDIALOG +#define XmCreateFileSelectionBox XMCREATEFILESELECTIONBOX +#define XmCreateFileSelectionDialog XMCREATEFILESELECTIONDIALOG +#define XmCreateForm XMCREATEFORM +#define XmCreateFormDialog XMCREATEFORMDIALOG +#define XmCreateFrame XMCREATEFRAME +#define XmCreateInformationDialog XMCREATEINFORMATIONDIALOG +#define XmCreateLabel XMCREATELABEL +#define XmCreateLabelGadget XMCREATELABELGADGET +#define XmCreateList XMCREATELIST +#define XmCreateMainWindow XMCREATEMAINWINDOW +#define XmCreateMenuBar XMCREATEMENUBAR +#define XmCreateMessageBox XMCREATEMESSAGEBOX +#define XmCreateMessageDialog XMCREATEMESSAGEDIALOG +#define XmCreateOptionMenu XMCREATEOPTIONMENU +#define XmCreatePanedWindow XMCREATEPANEDWINDOW +#define XmCreatePopupMenu XMCREATEPOPUPMENU +#define XmCreatePromptDialog XMCREATEPROMPTDIALOG +#define XmCreatePulldownMenu XMCREATEPULLDOWNMENU +#define XmCreatePushButton XMCREATEPUSHBUTTON +#define XmCreatePushButtonGadget XMCREATEPUSHBUTTONGADGET +#define XmCreateQuestionDialog XMCREATEQUESTIONDIALOG +#define XmCreateRadioBox XMCREATERADIOBOX +#define XmCreateRowColumn XMCREATEROWCOLUMN +#define XmCreateScale XMCREATESCALE +#define XmCreateScrollBar XMCREATESCROLLBAR +#define XmCreateScrolledList XMCREATESCROLLEDLIST +#define XmCreateScrolledText XMCREATESCROLLEDTEXT +#define XmCreateScrolledWindow XMCREATESCROLLEDWINDOW +#define XmCreateSelectionDialog XMCREATESELECTIONDIALOG +#define XmCreateSeparator XMCREATESEPARATOR +#define XmCreateSeparatorGadget XMCREATESEPARATORGADGET +#define XmCreateSimpleMenuBar XMCREATESIMPLEMENUBAR +#define XmCreateTemplateDialog XMCREATETEMPLATEDIALOG +#define XmCreateText XMCREATETEXT +#define XmCreateTextField XMCREATETEXTFIELD +#define XmCreateToggleButton XMCREATETOGGLEBUTTON +#define XmCreateToggleButtonGadget XMCREATETOGGLEBUTTONGADGET +#define XmCreateWarningDialog XMCREATEWARNINGDIALOG +#define XmCvtCTToXmString XMCVTCTTOXMSTRING +#define XmDestroyPixmap XMDESTROYPIXMAP +#define XmDragStart XMDRAGSTART +#define XmDropSiteRegister XMDROPSITEREGISTER +#define XmDropSiteUnregister XMDROPSITEUNREGISTER +#define XmDropSiteUpdate XMDROPSITEUPDATE +#define XmDropTransferStart XMDROPTRANSFERSTART +#define XmFileSelectionBoxGetChild XMFILESELECTIONBOXGETCHILD +#define XmFileSelectionDoSearch XMFILESELECTIONDOSEARCH +#define XmFontListAppendEntry XMFONTLISTAPPENDENTRY +#define XmFontListCopy XMFONTLISTCOPY +#define XmFontListCreate XMFONTLISTCREATE +#define XmFontListEntryCreate XMFONTLISTENTRYCREATE +#define XmFontListEntryFree XMFONTLISTENTRYFREE +#define XmFontListEntryGetFont XMFONTLISTENTRYGETFONT +#define XmFontListEntryGetTag XMFONTLISTENTRYGETTAG +#define XmFontListEntryLoad XMFONTLISTENTRYLOAD +#define XmFontListFree XMFONTLISTFREE +#define XmFontListFreeFontContext XMFONTLISTFREEFONTCONTEXT +#define XmFontListGetNextFont XMFONTLISTGETNEXTFONT +#define XmFontListInitFontContext XMFONTLISTINITFONTCONTEXT +#define XmFontListNextEntry XMFONTLISTNEXTENTRY +#define XmGetColors XMGETCOLORS +#define XmGetColorCalculation XMGETCOLORCALCULATION +#define XmGetFocusWidget XMGETFOCUSWIDGET +#define XmGetMenuCursor XMGETMENUCURSOR +#define XmGetPixmap XMGETPIXMAP +#define XmGetPixmapByDepth XMGETPIXMAPBYDEPTH +#define XmGetTearOffControl XMGETTEAROFFCONTROL +#define XmGetXmDisplay XMGETXMDISPLAY +#define XmImMbLookupString XMIMMBLOOKUPSTRING +#define XmImRegister XMIMREGISTER +#define XmImSetFocusValues XMIMSETFOCUSVALUES +#define XmImSetValues XMIMSETVALUES +#define XmImUnregister XMIMUNREGISTER +#define XmImUnsetFocus XMIMUNSETFOCUS +#define XmInstallImage XMINSTALLIMAGE +#define XmInternAtom XMINTERNATOM +#define XmIsMotifWMRunning XMISMOTIFWMRUNNING +#define XmListAddItem XMLISTADDITEM +#define XmListAddItemUnselected XMLISTADDITEMUNSELECTED +#define XmListAddItems XMLISTADDITEMS +#define XmListAddItemsUnselected XMLISTADDITEMSUNSELECTED +#define XmListDeleteAllItems XMLISTDELETEALLITEMS +#define XmListDeleteItem XMLISTDELETEITEM +#define XmListDeleteItemsPos XMLISTDELETEITEMSPOS +#define XmListDeletePos XMLISTDELETEPOS +#define XmListDeselectAllItems XMLISTDESELECTALLITEMS +#define XmListDeselectPos XMLISTDESELECTPOS +#define XmListGetKbdItemPos XMLISTGETKBDITEMPOS +#define XmListGetMatchPos XMLISTGETMATCHPOS +#define XmListGetSelectedPos XMLISTGETSELECTEDPOS +#define XmListItemExists XMLISTITEMEXISTS +#define XmListItemPos XMLISTITEMPOS +#define XmListPosSelected XMLISTPOSSELECTED +#define XmListReplaceItems XMLISTREPLACEITEMS +#define XmListReplaceItemsPos XMLISTREPLACEITEMSPOS +#define XmListSelectItem XMLISTSELECTITEM +#define XmListSelectPos XMLISTSELECTPOS +#define XmListSetBottomPos XMLISTSETBOTTOMPOS +#define XmListSetItem XMLISTSETITEM +#define XmListSetKbdItemPos XMLISTSETKBDITEMPOS +#define XmListSetPos XMLISTSETPOS +#define XmMainWindowSetAreas XMMAINWINDOWSETAREAS +#define XmMenuPosition XMMENUPOSITION +#define XmMessageBoxGetChild XMMESSAGEBOXGETCHILD +#define XmOptionButtonGadget XMOPTIONBUTTONGADGET +#define XmOptionLabelGadget XMOPTIONLABELGADGET +#define XmProcessTraversal XMPROCESSTRAVERSAL +#define XmQmotif XMQMOTIF +#define XmRemoveProtocolCallback XMREMOVEPROTOCOLCALLBACK +#define XmRemoveProtocols XMREMOVEPROTOCOLS +#define XmRemoveTabGroup XMREMOVETABGROUP +#define XmRepTypeGetId XMREPTYPEGETID +#define XmRepTypeGetRecord XMREPTYPEGETRECORD +#define XmRepTypeInstallTearOffModelCon XMREPTYPEINSTALLTEAROFFMODELCON +#define XmRepTypeRegister XMREPTYPEREGISTER +#define XmRepTypeValidValue XMREPTYPEVALIDVALUE +#define XmScrollBarGetValues XMSCROLLBARGETVALUES +#define XmScrollBarSetValues XMSCROLLBARSETVALUES +#define XmScrolledWindowSetAreas XMSCROLLEDWINDOWSETAREAS +#define XmSelectionBoxGetChild XMSELECTIONBOXGETCHILD +#define XmSetColorCalculation XMSETCOLORCALCULATION +#define XmStringByteCompare XMSTRINGBYTECOMPARE +#define XmStringCompare XMSTRINGCOMPARE +#define XmStringConcat XMSTRINGCONCAT +#define XmStringCopy XMSTRINGCOPY +#define XmStringCreate XMSTRINGCREATE +#define XmStringCreateLocalized XMSTRINGCREATELOCALIZED +#define XmStringCreateLtoR XMSTRINGCREATELTOR +#define XmStringCreateSimple XMSTRINGCREATESIMPLE +#define XmStringDraw XMSTRINGDRAW +#define XmStringDrawUnderline XMSTRINGDRAWUNDERLINE +#define XmStringExtent XMSTRINGEXTENT +#define XmStringFree XMSTRINGFREE +#define XmStringFreeContext XMSTRINGFREECONTEXT +#define XmStringGetLtoR XMSTRINGGETLTOR +#define XmStringGetNextComponent XMSTRINGGETNEXTCOMPONENT +#define XmStringGetNextSegment XMSTRINGGETNEXTSEGMENT +#define XmStringInitContext XMSTRINGINITCONTEXT +#define XmStringLength XMSTRINGLENGTH +#define XmStringLtoRCreate XMSTRINGLTORCREATE +#define XmStringNConcat XMSTRINGNCONCAT +#define XmStringSegmentCreate XMSTRINGSEGMENTCREATE +#define XmStringSeparatorCreate XMSTRINGSEPARATORCREATE +#define XmStringWidth XMSTRINGWIDTH +#define XmTextClearSelection XMTEXTCLEARSELECTION +#define XmTextCopy XMTEXTCOPY +#define XmTextCut XMTEXTCUT +#define XmTextFieldClearSelection XMTEXTFIELDCLEARSELECTION +#define XmTextFieldCopy XMTEXTFIELDCOPY +#define XmTextFieldCut XMTEXTFIELDCUT +#define XmTextFieldGetEditable XMTEXTFIELDGETEDITABLE +#define XmTextFieldGetInsertionPosition XMTEXTFIELDGETINSERTIONPOSITION +#define XmTextFieldGetLastPosition XMTEXTFIELDGETLASTPOSITION +#define XmTextFieldGetMaxLength XMTEXTFIELDGETMAXLENGTH +#define XmTextFieldGetSelection XMTEXTFIELDGETSELECTION +#define XmTextFieldGetSelectionPosition XMTEXTFIELDGETSELECTIONPOSITION +#define XmTextFieldGetString XMTEXTFIELDGETSTRING +#define XmTextFieldInsert XMTEXTFIELDINSERT +#define XmTextFieldPaste XMTEXTFIELDPASTE +#define XmTextFieldRemove XMTEXTFIELDREMOVE +#define XmTextFieldReplace XMTEXTFIELDREPLACE +#define XmTextFieldSetAddMode XMTEXTFIELDSETADDMODE +#define XmTextFieldSetHighlight XMTEXTFIELDSETHIGHLIGHT +#define XmTextFieldSetInsertionPosition XMTEXTFIELDSETINSERTIONPOSITION +#define XmTextFieldSetMaxLength XMTEXTFIELDSETMAXLENGTH +#define XmTextFieldSetSelection XMTEXTFIELDSETSELECTION +#define XmTextFieldSetString XMTEXTFIELDSETSTRING +#define XmTextFieldShowPosition XMTEXTFIELDSHOWPOSITION +#define XmTextGetCursorPosition XMTEXTGETCURSORPOSITION +#define XmTextGetEditable XMTEXTGETEDITABLE +#define XmTextGetInsertionPosition XMTEXTGETINSERTIONPOSITION +#define XmTextGetLastPosition XMTEXTGETLASTPOSITION +#define XmTextGetMaxLength XMTEXTGETMAXLENGTH +#define XmTextGetSelection XMTEXTGETSELECTION +#define XmTextGetSelectionPosition XMTEXTGETSELECTIONPOSITION +#define XmTextGetString XMTEXTGETSTRING +#define XmTextInsert XMTEXTINSERT +#define XmTextPaste XMTEXTPASTE +#define XmTextPosToXY XMTEXTPOSTOXY +#define XmTextRemove XMTEXTREMOVE +#define XmTextReplace XMTEXTREPLACE +#define XmTextSetCursorPosition XMTEXTSETCURSORPOSITION +#define XmTextSetEditable XMTEXTSETEDITABLE +#define XmTextSetHighlight XMTEXTSETHIGHLIGHT +#define XmTextSetInsertionPosition XMTEXTSETINSERTIONPOSITION +#define XmTextSetSelection XMTEXTSETSELECTION +#define XmTextSetString XMTEXTSETSTRING +#define XmTextSetTopCharacter XMTEXTSETTOPCHARACTER +#define XmTextShowPosition XMTEXTSHOWPOSITION +#define XmToggleButtonGadgetGetState XMTOGGLEBUTTONGADGETGETSTATE +#define XmToggleButtonGadgetSetState XMTOGGLEBUTTONGADGETSETSTATE +#define XmToggleButtonGetState XMTOGGLEBUTTONGETSTATE +#define XmToggleButtonSetState XMTOGGLEBUTTONSETSTATE +#define XmUninstallImage XMUNINSTALLIMAGE +#define XmUpdateDisplay XMUPDATEDISPLAY +#define XmVaCreateSimpleRadioBox XMVACREATESIMPLERADIOBOX +#define XmbDrawString XMBDRAWSTRING +#define XmbLookupString XMBLOOKUPSTRING +#define XmbResetIC XMBRESETIC +#define XmbSetWMProperties XMBSETWMPROPERTIES +#define XmbTextEscapement XMBTEXTESCAPEMENT +#define XmbTextExtents XMBTEXTEXTENTS +#define XmbTextListToTextProperty XMBTEXTLISTTOTEXTPROPERTY +#define XmbTextPropertyToTextList XMBTEXTPROPERTYTOTEXTLIST +#define XmbufCreateBuffers XMBUFCREATEBUFFERS +#define XmbufDestroyBuffers XMBUFDESTROYBUFFERS +#define XmbufDisplayBuffers XMBUFDISPLAYBUFFERS +#define XmbufQueryExtension XMBUFQUERYEXTENSION +#define Xmemory_free XMEMORY_FREE +#define Xmemory_malloc XMEMORY_MALLOC +#define XmuClientWindow XMUCLIENTWINDOW +#define XmuConvertStandardSelection XMUCONVERTSTANDARDSELECTION +#define XmuCvtStringToBitmap XMUCVTSTRINGTOBITMAP +#define XmuInternAtom XMUINTERNATOM +#define XmuInternStrings XMUINTERNSTRINGS +#define XmuLookupStandardColormap XMULOOKUPSTANDARDCOLORMAP +#define XmuPrintDefaultErrorMessage XMUPRINTDEFAULTERRORMESSAGE +#define XrmCombineDatabase XRMCOMBINEDATABASE +#define XrmCombineFileDatabase XRMCOMBINEFILEDATABASE +#define XrmDestroyDatabase XRMDESTROYDATABASE +#define XrmGetDatabase XRMGETDATABASE +#define XrmGetFileDatabase XRMGETFILEDATABASE +#define XrmGetResource XRMGETRESOURCE +#define XrmGetStringDatabase XRMGETSTRINGDATABASE +#define XrmInitialize XRMINITIALIZE +#define XrmMergeDatabases XRMMERGEDATABASES +#define XrmParseCommand XRMPARSECOMMAND +#define XrmPermStringToQuark XRMPERMSTRINGTOQUARK +#define XrmPutFileDatabase XRMPUTFILEDATABASE +#define XrmPutLineResource XRMPUTLINERESOURCE +#define XrmPutStringResource XRMPUTSTRINGRESOURCE +#define XrmQGetResource XRMQGETRESOURCE +#define XrmQPutStringResource XRMQPUTSTRINGRESOURCE +#define XrmQuarkToString XRMQUARKTOSTRING +#define XrmSetDatabase XRMSETDATABASE +#define XrmStringToBindingQuarkList XRMSTRINGTOBINDINGQUARKLIST +#define XrmStringToQuark XRMSTRINGTOQUARK +#define XtAddCallback XTADDCALLBACK +#define XtAddCallbacks XTADDCALLBACKS +#define XtAddConverter XTADDCONVERTER +#define XtAddEventHandler XTADDEVENTHANDLER +#define XtAddExposureToRegion XTADDEXPOSURETOREGION +#define XtAddGrab XTADDGRAB +#define XtAddRawEventHandler XTADDRAWEVENTHANDLER +#define XtAllocateGC XTALLOCATEGC +#define XtAppAddActions XTAPPADDACTIONS +#define XtAppAddInput XTAPPADDINPUT +#define XtAppAddTimeOut XTAPPADDTIMEOUT +#define XtAppAddWorkProc XTAPPADDWORKPROC +#define XtAppCreateShell XTAPPCREATESHELL +#define XtAppError XTAPPERROR +#define XtAppErrorMsg XTAPPERRORMSG +#define XtAppGetErrorDatabase XTAPPGETERRORDATABASE +#define XtAppGetErrorDatabaseText XTAPPGETERRORDATABASETEXT +#define XtAppSetErrorMsgHandler XTAPPSETERRORMSGHANDLER +#define XtAppInitialize XTAPPINITIALIZE +#define XtAppMainLoop XTAPPMAINLOOP +#define XtAppNextEvent XTAPPNEXTEVENT +#define XtAppPeekEvent XTAPPPEEKEVENT +#define XtAppPending XTAPPPENDING +#define XtAppProcessEvent XTAPPPROCESSEVENT +#define XtAppSetErrorHandler XTAPPSETERRORHANDLER +#define XtAppSetFallbackResources XTAPPSETFALLBACKRESOURCES +#define XtAppSetTypeConverter XTAPPSETTYPECONVERTER +#define XtAppSetWarningHandler XTAPPSETWARNINGHANDLER +#define XtAppWarningMsg XTAPPWARNINGMSG +#define XtAppSetWarningMsgHandler XTAPPSETWARNINGMSGHANDLER +#define XtAppWarning XTAPPWARNING +#define XtAugmentTranslations XTAUGMENTTRANSLATIONS +#define XtCallActionProc XTCALLACTIONPROC +#define XtCallCallbackList XTCALLCALLBACKLIST +#define XtCallCallbacks XTCALLCALLBACKS +#define XtCallConverter XTCALLCONVERTER +#define XtCalloc XTCALLOC +#ifndef NOXTDISPLAY +#define XtClass XTCLASS +#endif +#define XtCloseDisplay XTCLOSEDISPLAY +#define XtConfigureWidget XTCONFIGUREWIDGET +#define XtConvert XTCONVERT +#define XtConvertAndStore XTCONVERTANDSTORE +#define XtCreateApplicationContext XTCREATEAPPLICATIONCONTEXT +#define XtCreateManagedWidget XTCREATEMANAGEDWIDGET +#define XtCreatePopupShell XTCREATEPOPUPSHELL +#define XtCreateWidget XTCREATEWIDGET +#define XtCreateWindow XTCREATEWINDOW +#define XtCvtStringToFont XTCVTSTRINGTOFONT +#define XtDatabase XTDATABASE +#define XtDestroyApplicationContext XTDESTROYAPPLICATIONCONTEXT +#define XtDestroyWidget XTDESTROYWIDGET +#define XtDisownSelection XTDISOWNSELECTION +#define XtDispatchEvent XTDISPATCHEVENT +#ifndef NOXTDISPLAY +#define XtDisplay XTDISPLAY +#endif +#define XtDisplayInitialize XTDISPLAYINITIALIZE +#define XtDisplayOfObject XTDISPLAYOFOBJECT +#define XtDisplayStringConvWarning XTDISPLAYSTRINGCONVWARNING +#define XtDisplayToApplicationContext XTDISPLAYTOAPPLICATIONCONTEXT +#define XtError XTERROR +#define XtErrorMsg XTERRORMSG +#define XtFree XTFREE +#define XtGetActionKeysym XTGETACTIONKEYSYM +#define XtGetActionList XTGETACTIONLIST +#define XtGetApplicationNameAndClass XTGETAPPLICATIONNAMEANDCLASS +#define XtGetApplicationResources XTGETAPPLICATIONRESOURCES +#define XtGetClassExtension XTGETCLASSEXTENSION +#define XtGetConstraintResourceList XTGETCONSTRAINTRESOURCELIST +#define XtGetGC XTGETGC +#define XtGetMultiClickTime XTGETMULTICLICKTIME +#define XtGetResourceList XTGETRESOURCELIST +#define XtGetSelectionValue XTGETSELECTIONVALUE +#define XtGetSelectionValues XTGETSELECTIONVALUES +#define XtGetSubresources XTGETSUBRESOURCES +#define XtGetValues XTGETVALUES +#define XtGrabButton XTGRABBUTTON +#define XtGrabKeyboard XTGRABKEYBOARD +#define XtGrabPointer XTGRABPOINTER +#define XtHasCallbacks XTHASCALLBACKS +#define XtInitialize XTINITIALIZE +#define XtInitializeWidgetClass XTINITIALIZEWIDGETCLASS +#define XtInsertEventHandler XTINSERTEVENTHANDLER +#define XtInsertRawEventHandler XTINSERTRAWEVENTHANDLER +#define XtInstallAccelerators XTINSTALLACCELERATORS +#define XtIsManaged XTISMANAGED +#define XtIsObject XTISOBJECT +#ifndef NOXTDISPLAY +#define XtIsRealized XTISREALIZED +#endif +#define XtIsSensitive XTISSENSITIVE +#define XtIsSubclass XTISSUBCLASS +#define XtLastTimestampProcessed XTLASTTIMESTAMPPROCESSED +#define XtMainLoop XTMAINLOOP +#define XtMakeGeometryRequest XTMAKEGEOMETRYREQUEST +#define XtMakeResizeRequest XTMAKERESIZEREQUEST +#define XtMalloc XTMALLOC +#define XtManageChild XTMANAGECHILD +#define XtManageChildren XTMANAGECHILDREN +#define XtMergeArgLists XTMERGEARGLISTS +#define XtMoveWidget XTMOVEWIDGET +#define XtName XTNAME +#define XtNameToWidget XTNAMETOWIDGET +#define XtOpenApplication XTOPENAPPLICATION +#define XtOpenDisplay XTOPENDISPLAY +#define XtOverrideTranslations XTOVERRIDETRANSLATIONS +#define XtOwnSelection XTOWNSELECTION +#ifndef NOXTDISPLAY +#define XtParent XTPARENT +#endif +#define XtParseAcceleratorTable XTPARSEACCELERATORTABLE +#define XtParseTranslationTable XTPARSETRANSLATIONTABLE +#define XtPopdown XTPOPDOWN +#define XtPopup XTPOPUP +#define XtPopupSpringLoaded XTPOPUPSPRINGLOADED +#define XtQueryGeometry XTQUERYGEOMETRY +#define XtRealizeWidget XTREALIZEWIDGET +#define XtRealloc XTREALLOC +#define XtRegisterDrawable _XTREGISTERWINDOW +#define XtRegisterGrabAction XTREGISTERGRABACTION +#define XtReleaseGC XTRELEASEGC +#define XtRemoveAllCallbacks XTREMOVEALLCALLBACKS +#define XtRemoveCallback XTREMOVECALLBACK +#define XtRemoveEventHandler XTREMOVEEVENTHANDLER +#define XtRemoveGrab XTREMOVEGRAB +#define XtRemoveInput XTREMOVEINPUT +#define XtRemoveTimeOut XTREMOVETIMEOUT +#define XtRemoveWorkProc XTREMOVEWORKPROC +#define XtResizeWidget XTRESIZEWIDGET +#define XtResolvePathname XTRESOLVEPATHNAME +#ifndef NOXTDISPLAY +#define XtScreen XTSCREEN +#endif +#define XtScreenDatabase XTSCREENDATABASE +#define XtScreenOfObject XTSCREENOFOBJECT +#define XtSessionReturnToken XTSESSIONRETURNTOKEN +#define XtSetErrorHandler XTSETERRORHANDLER +#define XtSetKeyboardFocus XTSETKEYBOARDFOCUS +#define XtSetLanguageProc XTSETLANGUAGEPROC +#define XtSetMappedWhenManaged XTSETMAPPEDWHENMANAGED +#define XtSetSensitive XTSETSENSITIVE +#define XtSetTypeConverter XTSETTYPECONVERTER +#define XtSetValues XTSETVALUES +#define XtShellStrings XTSHELLSTRINGS +#define XtStringConversionWarning XTSTRINGCONVERSIONWARNING +#define XtStrings XTSTRINGS +#define XtToolkitInitialize XTTOOLKITINITIALIZE +#define XtTranslateCoords XTTRANSLATECOORDS +#define XtTranslateKeycode XTTRANSLATEKEYCODE +#define XtUngrabButton XTUNGRABBUTTON +#define XtUngrabKeyboard XTUNGRABKEYBOARD +#define XtUngrabPointer XTUNGRABPOINTER +#define XtUnmanageChild XTUNMANAGECHILD +#define XtUnmanageChildren XTUNMANAGECHILDREN +#define XtUnrealizeWidget XTUNREALIZEWIDGET +#define XtUnregisterDrawable _XTUNREGISTERWINDOW +#define XtVaAppCreateShell XTVAAPPCREATESHELL +#define XtVaCreateManagedWidget XTVACREATEMANAGEDWIDGET +#define XtVaCreatePopupShell XTVACREATEPOPUPSHELL +#define XtVaCreateWidget XTVACREATEWIDGET +#define XtVaGetApplicationResources XTVAGETAPPLICATIONRESOURCES +#define XtVaGetValues XTVAGETVALUES +#define XtVaSetValues XTVASETVALUES +#define XtWarning XTWARNING +#define XtWarningMsg XTWARNINGMSG +#define XtWidgetToApplicationContext XTWIDGETTOAPPLICATIONCONTEXT +#ifndef NOXTDISPLAY +#define XtWindow XTWINDOW +#endif +#define XtWindowOfObject XTWINDOWOFOBJECT +#define XtWindowToWidget XTWINDOWTOWIDGET +#define XwcDrawImageString XWCDRAWIMAGESTRING +#define XwcDrawString XWCDRAWSTRING +#define XwcFreeStringList XWCFREESTRINGLIST +#define XwcTextEscapement XWCTEXTESCAPEMENT +#define XwcTextExtents XWCTEXTEXTENTS +#define XwcTextListToTextProperty XWCTEXTLISTTOTEXTPROPERTY +#define XwcLookupString XWCLOOKUPSTRING +#define XwcTextPropertyToTextList XWCTEXTPROPERTYTOTEXTLIST +#define _XAllocTemp _XALLOCTEMP +#define _XDeqAsyncHandler _XDEQASYNCHANDLER +#define _XEatData _XEATDATA +#define _XFlush _XFLUSH +#define _XFreeTemp _XFREETEMP +#define _XGetAsyncReply _XGETASYNCREPLY +#define _XInitImageFuncPtrs _XINITIMAGEFUNCPTRS +#define _XRead _XREAD +#define _XReadPad _XREADPAD +#define _XRegisterFilterByType _XREGISTERFILTERBYTYPE +#define _XReply _XREPLY +#define _XSend _XSEND +#define _XUnregisterFilter _XUNREGISTERFILTER +#define _XVIDtoVisual _XVIDTOVISUAL +#define _XmBottomShadowColorDefault _XMBOTTOMSHADOWCOLORDEFAULT +#define _XmClearBorder _XMCLEARBORDER +#define _XmConfigureObject _XMCONFIGUREOBJECT +#define _XmDestroyParentCallback _XMDESTROYPARENTCALLBACK +#define _XmDrawArrow _XMDRAWARROW +#define _XmDrawShadows _XMDRAWSHADOWS +#define _XmFontListGetDefaultFont _XMFONTLISTGETDEFAULTFONT +#define _XmFromHorizontalPixels _XMFROMHORIZONTALPIXELS +#define _XmFromVerticalPixels _XMFROMVERTICALPIXELS +#define _XmGetClassExtensionPtr _XMGETCLASSEXTENSIONPTR +#define _XmGetDefaultFontList _XMGETDEFAULTFONTLIST +#define _XmGetTextualDragIcon _XMGETTEXTUALDRAGICON +#define _XmGetWidgetExtData _XMGETWIDGETEXTDATA +#define _XmGrabKeyboard _XMGRABKEYBOARD +#define _XmGrabPointer _XMGRABPOINTER +#define _XmInheritClass _XMINHERITCLASS +#define _XmInputForGadget _XMINPUTFORGADGET +#define _XmInputInGadget _XMINPUTINGADGET +#define _XmMakeGeometryRequest _XMMAKEGEOMETRYREQUEST +#define _XmMenuPopDown _XMMENUPOPDOWN +#define _XmMoveObject _XMMOVEOBJECT +#define _XmNavigChangeManaged _XMNAVIGCHANGEMANAGED +#define _XmOSBuildFileList _XMOSBUILDFILELIST +#define _XmOSFileCompare _XMOSFILECOMPARE +#define _XmOSFindPatternPart _XMOSFINDPATTERNPART +#define _XmOSQualifyFileSpec _XMOSQUALIFYFILESPEC +#define _XmPostPopupMenu _XMPOSTPOPUPMENU +#define _XmPrimitiveEnter _XMPRIMITIVEENTER +#define _XmPrimitiveLeave _XMPRIMITIVELEAVE +#define _XmRedisplayGadgets _XMREDISPLAYGADGETS +#define _XmShellIsExclusive _XMSHELLISEXCLUSIVE +#define _XmStringDraw _XMSTRINGDRAW +#define _XmStringGetTextConcat _XMSTRINGGETTEXTCONCAT +#define _XmStrings _XMSTRINGS +#define _XmToHorizontalPixels _XMTOHORIZONTALPIXELS +#define _XmToVerticalPixels _XMTOVERTICALPIXELS +#define _XmTopShadowColorDefault _XMTOPSHADOWCOLORDEFAULT +#define _Xm_fastPtr _XM_FASTPTR +#define _XtCheckSubclassFlag _XTCHECKSUBCLASSFLAG +#define _XtCopyFromArg _XTCOPYFROMARG +#define _XtCountVaList _XTCOUNTVALIST +#define _XtInherit _XTINHERIT +#define _XtInheritTranslations _XTINHERITTRANSLATIONS +#define _XtIsSubclassOf _XTISSUBCLASSOF +#define _XtVaToArgList _XTVATOARGLIST +#define applicationShellWidgetClass APPLICATIONSHELLWIDGETCLASS +#define cli$dcl_parse CLI$DCL_PARSE +#define cli$get_value CLI$GET_VALUE +#define cli$present CLI$PRESENT +#define compositeClassRec COMPOSITECLASSREC +#define compositeWidgetClass COMPOSITEWIDGETCLASS +#define constraintClassRec CONSTRAINTCLASSREC +#define constraintWidgetClass CONSTRAINTWIDGETCLASS +#define coreWidgetClass COREWIDGETCLASS +#define exe$getspi EXE$GETSPI +#define lbr$close LBR$CLOSE +#define lbr$get_header LBR$GET_HEADER +#define lbr$get_index LBR$GET_INDEX +#define lbr$get_record LBR$GET_RECORD +#define lbr$ini_control LBR$INI_CONTROL +#define lbr$lookup_key LBR$LOOKUP_KEY +#define lbr$open LBR$OPEN +#define lbr$output_help LBR$OUTPUT_HELP +#define lib$add_times LIB$ADD_TIMES +#define lib$addx LIB$ADDX +#define lib$create_dir LIB$CREATE_DIR +#define lib$create_vm_zone LIB$CREATE_VM_ZONE +#define lib$cvt_from_internal_time LIB$CVT_FROM_INTERNAL_TIME +#define lib$cvt_htb LIB$CVT_HTB +#define lib$cvt_vectim LIB$CVT_VECTIM +#define lib$day LIB$DAY +#define lib$day_of_week LIB$DAY_OF_WEEK +#define lib$delete_symbol LIB$DELETE_SYMBOL +#define lib$delete_vm_zone LIB$DELETE_VM_ZONE +#define lib$disable_ctrl LIB$DISABLE_CTRL +#define lib$ediv LIB$EDIV +#define lib$emul LIB$EMUL +#define lib$enable_ctrl LIB$ENABLE_CTRL +#define lib$find_vm_zone LIB$FIND_VM_ZONE +#define lib$format_date_time LIB$FORMAT_DATE_TIME +#define lib$free_timer LIB$FREE_TIMER +#define lib$free_vm LIB$FREE_VM +#define lib$get_ef LIB$GET_EF +#define lib$get_foreign LIB$GET_FOREIGN +#define lib$get_input LIB$GET_INPUT +#define lib$get_users_language LIB$GET_USERS_LANGUAGE +#define lib$get_vm LIB$GET_VM +#define lib$get_symbol LIB$GET_SYMBOL +#define lib$getdvi LIB$GETDVI +#define lib$init_date_time_context LIB$INIT_DATE_TIME_CONTEXT +#define lib$init_timer LIB$INIT_TIMER +#define lib$find_file LIB$FIND_FILE +#define lib$find_file_end LIB$FIND_FILE_END +#define lib$find_image_symbol LIB$FIND_IMAGE_SYMBOL +#define lib$mult_delta_time LIB$MULT_DELTA_TIME +#define lib$put_output LIB$PUT_OUTPUT +#define lib$rename_file LIB$RENAME_FILE +#define lib$reset_vm_zone LIB$RESET_VM_ZONE +#define lib$set_symbol LIB$SET_SYMBOL +#define lib$sfree1_dd LIB$SFREE1_DD +#define lib$show_vm LIB$SHOW_VM +#define lib$show_vm_zone LIB$SHOW_VM_ZONE +#define lib$spawn LIB$SPAWN +#define lib$stat_timer LIB$STAT_TIMER +#define lib$subx LIB$SUBX +#define lib$sub_times LIB$SUB_TIMES +#define lib$wait LIB$WAIT +#define mail$send_add_address MAIL$SEND_ADD_ADDRESS +#define mail$send_add_attribute MAIL$SEND_ADD_ATTRIBUTE +#define mail$send_add_bodypart MAIL$SEND_ADD_BODYPART +#define mail$send_begin MAIL$SEND_BEGIN +#define mail$send_end MAIL$SEND_END +#define mail$send_message MAIL$SEND_MESSAGE +#define ncs$convert NCS$CONVERT +#define ncs$get_cf NCS$GET_CF +#define objectClass OBJECTCLASS +#define objectClassRec OBJECTCLASSREC +#define overrideShellClassRec OVERRIDESHELLCLASSREC +#define overrideShellWidgetClass OVERRIDESHELLWIDGETCLASS +#define pthread_attr_create PTHREAD_ATTR_CREATE +#define pthread_attr_delete PTHREAD_ATTR_DELETE +#define pthread_attr_destroy PTHREAD_ATTR_DESTROY +#define pthread_attr_getdetach_np PTHREAD_ATTR_GETDETACH_NP +#define pthread_attr_getguardsize_np PTHREAD_ATTR_GETGUARDSIZE_NP +#define pthread_attr_getinheritsched PTHREAD_ATTR_GETINHERITSCHED +#define pthread_attr_getprio PTHREAD_ATTR_GETPRIO +#define pthread_attr_getsched PTHREAD_ATTR_GETSCHED +#define pthread_attr_getschedparam PTHREAD_ATTR_GETSCHEDPARAM +#define pthread_attr_getschedpolicy PTHREAD_ATTR_GETSCHEDPOLICY +#define pthread_attr_getstacksize PTHREAD_ATTR_GETSTACKSIZE +#define pthread_attr_init PTHREAD_ATTR_INIT +#define pthread_attr_setdetach_np PTHREAD_ATTR_SETDETACH_NP +#define pthread_attr_setdetachstate PTHREAD_ATTR_SETDETACHSTATE +#define pthread_attr_setguardsize_np PTHREAD_ATTR_SETGUARDSIZE_NP +#define pthread_attr_setinheritsched PTHREAD_ATTR_SETINHERITSCHED +#define pthread_attr_setprio PTHREAD_ATTR_SETPRIO +#define pthread_attr_setsched PTHREAD_ATTR_SETSCHED +#define pthread_attr_setschedparam PTHREAD_ATTR_SETSCHEDPARAM +#define pthread_attr_setschedpolicy PTHREAD_ATTR_SETSCHEDPOLICY +#ifndef pthread_attr_setscope +# define pthread_attr_setscope PTHREAD_ATTR_SETSCOPE +#endif +#define pthread_attr_setstacksize PTHREAD_ATTR_SETSTACKSIZE +#define pthread_cancel PTHREAD_CANCEL +#define pthread_cancel_e PTHREAD_CANCEL_E +#define pthread_cond_broadcast PTHREAD_COND_BROADCAST +#define pthread_cond_destroy PTHREAD_COND_DESTROY +#define pthread_cond_init PTHREAD_COND_INIT +#define pthread_cond_sig_preempt_int_np PTHREAD_COND_SIG_PREEMPT_INT_NP +#define pthread_cond_signal PTHREAD_COND_SIGNAL +#define pthread_cond_signal_int_np PTHREAD_COND_SIGNAL_INT_NP +#define pthread_cond_timedwait PTHREAD_COND_TIMEDWAIT +#define pthread_cond_wait PTHREAD_COND_WAIT +#define pthread_condattr_create PTHREAD_CONDATTR_CREATE +#define pthread_condattr_delete PTHREAD_CONDATTR_DELETE +#define pthread_condattr_init PTHREAD_CONDATTR_INIT +#define pthread_create PTHREAD_CREATE +#define pthread_delay_np PTHREAD_DELAY_NP +#define pthread_detach PTHREAD_DETACH +#define pthread_equal PTHREAD_EQUAL +#define pthread_exc_fetch_fp_np PTHREAD_EXC_FETCH_FP_NP +#define pthread_exc_handler_np PTHREAD_EXC_HANDLER_NP +#define pthread_exc_matches_np PTHREAD_EXC_MATCHES_NP +#define pthread_exc_pop_ctx_np PTHREAD_EXC_POP_CTX_NP +#define pthread_exc_push_ctx_np PTHREAD_EXC_PUSH_CTX_NP +#define pthread_exc_raise_np PTHREAD_EXC_RAISE_NP +#define pthread_exc_savecontext_np PTHREAD_EXC_SAVECONTEXT_NP +#define pthread_exit PTHREAD_EXIT +#define pthread_get_expiration_np PTHREAD_GET_EXPIRATION_NP +#define pthread_getprio PTHREAD_GETPRIO +#define pthread_getschedparam PTHREAD_GETSCHEDPARAM +#define pthread_getscheduler PTHREAD_GETSCHEDULER +#define pthread_getspecific PTHREAD_GETSPECIFIC +#define pthread_getunique_np PTHREAD_GETUNIQUE_NP +#define pthread_join PTHREAD_JOIN +#define pthread_join32 PTHREAD_JOIN32 +#define pthread_key_create PTHREAD_KEY_CREATE +#define pthread_key_delete PTHREAD_KEY_DELETE +#define pthread_keycreate PTHREAD_KEYCREATE +#define pthread_kill PTHREAD_KILL +#define pthread_lock_global_np PTHREAD_LOCK_GLOBAL_NP +#define pthread_mutex_destroy PTHREAD_MUTEX_DESTROY +#define pthread_mutex_init PTHREAD_MUTEX_INIT +#define pthread_mutex_lock PTHREAD_MUTEX_LOCK +#define pthread_mutex_trylock PTHREAD_MUTEX_TRYLOCK +#define pthread_mutex_unlock PTHREAD_MUTEX_UNLOCK +#define pthread_mutexattr_create PTHREAD_MUTEXATTR_CREATE +#define pthread_mutexattr_delete PTHREAD_MUTEXATTR_DELETE +#define pthread_mutexattr_destroy PTHREAD_MUTEXATTR_DESTROY +#define pthread_mutexattr_getkind_np PTHREAD_MUTEXATTR_GETKIND_NP +#define pthread_mutexattr_init PTHREAD_MUTEXATTR_INIT +#define pthread_mutexattr_setkind_np PTHREAD_MUTEXATTR_SETKIND_NP +#define pthread_mutexattr_settype_np PTHREAD_MUTEXATTR_SETTYPE_NP +#define pthread_once PTHREAD_ONCE +#define pthread_resume_np PTHREAD_RESUME_NP +#define pthread_self PTHREAD_SELF +#define pthread_setasynccancel PTHREAD_SETASYNCCANCEL +#define pthread_setcancel PTHREAD_SETCANCEL +#define pthread_setcancelstate PTHREAD_SETCANCELSTATE +#define pthread_setcanceltype PTHREAD_SETCANCELTYPE +#define pthread_setprio PTHREAD_SETPRIO +#define pthread_setschedparam PTHREAD_SETSCHEDPARAM +#define pthread_setscheduler PTHREAD_SETSCHEDULER +#define pthread_setspecific PTHREAD_SETSPECIFIC +#define pthread_suspend_np PTHREAD_SUSPEND_NP +#define pthread_testcancel PTHREAD_TESTCANCEL +#define pthread_unlock_global_np PTHREAD_UNLOCK_GLOBAL_NP +#define pthread_yield PTHREAD_YIELD +#define pthread_yield_np PTHREAD_YIELD_NP +#define rectObjClass RECTOBJCLASS +#define rectObjClassRec RECTOBJCLASSREC +#define sessionShellWidgetClass SESSIONSHELLWIDGETCLASS +#define shellWidgetClass SHELLWIDGETCLASS +#define shmat SHMAT +#define shmctl SHMCTL +#define shmdt SHMDT +#define shmget SHMGET +#define smg$create_key_table SMG$CREATE_KEY_TABLE +#define smg$create_virtual_keyboard SMG$CREATE_VIRTUAL_KEYBOARD +#define smg$read_composed_line SMG$READ_COMPOSED_LINE +#define sys$add_ident SYS$ADD_IDENT +#define sys$asctoid SYS$ASCTOID +#define sys$assign SYS$ASSIGN +#define sys$bintim SYS$BINTIM +#define sys$cancel SYS$CANCEL +#define sys$cantim SYS$CANTIM +#define sys$check_access SYS$CHECK_ACCESS +#define sys$close SYS$CLOSE +#define sys$connect SYS$CONNECT +#define sys$create SYS$CREATE +#define sys$create_user_profile SYS$CREATE_USER_PROFILE +#define sys$crembx SYS$CREMBX +#define sys$creprc SYS$CREPRC +#define sys$crmpsc SYS$CRMPSC +#define sys$dassgn SYS$DASSGN +#define sys$dclast SYS$DCLAST +#define sys$dclexh SYS$DCLEXH +#define sys$delprc SYS$DELPRC +#define sys$deq SYS$DEQ +#define sys$dgblsc SYS$DGBLSC +#define sys$display SYS$DISPLAY +#define sys$enq SYS$ENQ +#define sys$enqw SYS$ENQW +#define sys$erase SYS$ERASE +#define sys$fao SYS$FAO +#define sys$faol SYS$FAOL +#define sys$find_held SYS$FIND_HELD +#define sys$finish_rdb SYS$FINISH_RDB +#define sys$flush SYS$FLUSH +#define sys$forcex SYS$FORCEX +#define sys$get SYS$GET +#define sys$get_security SYS$GET_SECURITY +#define sys$getdviw SYS$GETDVIW +#define sys$getjpi SYS$GETJPI +#define sys$getjpiw SYS$GETJPIW +#define sys$getlkiw SYS$GETLKIW +#define sys$getmsg SYS$GETMSG +#define sys$getsyi SYS$GETSYI +#define sys$getsyiw SYS$GETSYIW +#define sys$gettim SYS$GETTIM +#define sys$getuai SYS$GETUAI +#define sys$grantid SYS$GRANTID +#define sys$hash_password SYS$HASH_PASSWORD +#define sys$hiber SYS$HIBER +#define sys$mgblsc SYS$MGBLSC +#define sys$numtim SYS$NUMTIM +#define sys$open SYS$OPEN +#define sys$parse SYS$PARSE +#define sys$parse_acl SYS$PARSE_ACL +#define sys$parse_acl SYS$PARSE_ACL +#define sys$persona_assume SYS$PERSONA_ASSUME +#define sys$persona_create SYS$PERSONA_CREATE +#define sys$persona_delete SYS$PERSONA_DELETE +#define sys$process_scan SYS$PROCESS_SCAN +#define sys$put SYS$PUT +#define sys$qio SYS$QIO +#define sys$qiow SYS$QIOW +#define sys$read SYS$READ +#define sys$resched SYS$RESCHED +#define sys$rewind SYS$REWIND +#define sys$search SYS$SEARCH +#define sys$set_security SYS$SET_SECURITY +#define sys$setast SYS$SETAST +#define sys$setef SYS$SETEF +#define sys$setimr SYS$SETIMR +#define sys$setpri SYS$SETPRI +#define sys$setprn SYS$SETPRN +#define sys$setprv SYS$SETPRV +#define sys$setswm SYS$SETSWM +#define sys$setuai SYS$SETUAI +#define sys$sndopr SYS$SNDOPR +#define sys$synch SYS$SYNCH +#define sys$trnlnm SYS$TRNLNM +#define sys$update SYS$UPDATE +#define sys$wake SYS$WAKE +#define sys$write SYS$WRITE +#define topLevelShellClassRec TOPLEVELSHELLCLASSREC +#define topLevelShellWidgetClass TOPLEVELSHELLWIDGETCLASS +#define transientShellWidgetClass TRANSIENTSHELLWIDGETCLASS +#define vendorShellClassRec VENDORSHELLCLASSREC +#define vendorShellWidgetClass VENDORSHELLWIDGETCLASS +#define widgetClass WIDGETCLASS +#define widgetClassRec WIDGETCLASSREC +#define wmShellClassRec WMSHELLCLASSREC +#define wmShellWidgetClass WMSHELLWIDGETCLASS +#define x$soft_ast_lib_lock X$SOFT_AST_LIB_LOCK +#define x$soft_ast_lock_depth X$SOFT_AST_LOCK_DEPTH +#define x$soft_reenable_asts X$SOFT_REENABLE_ASTS +#define xmArrowButtonWidgetClass XMARROWBUTTONWIDGETCLASS +#define xmBulletinBoardWidgetClass XMBULLETINBOARDWIDGETCLASS +#define xmCascadeButtonClassRec XMCASCADEBUTTONCLASSREC +#define xmCascadeButtonGadgetClass XMCASCADEBUTTONGADGETCLASS +#define xmCascadeButtonWidgetClass XMCASCADEBUTTONWIDGETCLASS +#define xmCommandWidgetClass XMCOMMANDWIDGETCLASS +#define xmDialogShellWidgetClass XMDIALOGSHELLWIDGETCLASS +#define xmDrawingAreaWidgetClass XMDRAWINGAREAWIDGETCLASS +#define xmDrawnButtonWidgetClass XMDRAWNBUTTONWIDGETCLASS +#define xmFileSelectionBoxWidgetClass XMFILESELECTIONBOXWIDGETCLASS +#define xmFormWidgetClass XMFORMWIDGETCLASS +#define xmFrameWidgetClass XMFRAMEWIDGETCLASS +#define xmGadgetClass XMGADGETCLASS +#define xmLabelGadgetClass XMLABELGADGETCLASS +#define xmLabelWidgetClass XMLABELWIDGETCLASS +#define xmListWidgetClass XMLISTWIDGETCLASS +#define xmMainWindowWidgetClass XMMAINWINDOWWIDGETCLASS +#define xmManagerClassRec XMMANAGERCLASSREC +#define xmManagerWidgetClass XMMANAGERWIDGETCLASS +#define xmMenuShellWidgetClass XMMENUSHELLWIDGETCLASS +#define xmMessageBoxWidgetClass XMMESSAGEBOXWIDGETCLASS +#define xmPrimitiveClassRec XMPRIMITIVECLASSREC +#define xmPrimitiveWidgetClass XMPRIMITIVEWIDGETCLASS +#define xmPushButtonClassRec XMPUSHBUTTONCLASSREC +#define xmPushButtonGadgetClass XMPUSHBUTTONGADGETCLASS +#define xmPushButtonWidgetClass XMPUSHBUTTONWIDGETCLASS +#define xmRowColumnWidgetClass XMROWCOLUMNWIDGETCLASS +#define xmSashWidgetClass XMSASHWIDGETCLASS +#define xmScaleWidgetClass XMSCALEWIDGETCLASS +#define xmScrollBarWidgetClass XMSCROLLBARWIDGETCLASS +#define xmScrolledWindowClassRec XMSCROLLEDWINDOWCLASSREC +#define xmScrolledWindowWidgetClass XMSCROLLEDWINDOWWIDGETCLASS +#define xmSeparatorGadgetClass XMSEPARATORGADGETCLASS +#define xmSeparatorWidgetClass XMSEPARATORWIDGETCLASS +#define xmTextFieldWidgetClass XMTEXTFIELDWIDGETCLASS +#define xmTextWidgetClass XMTEXTWIDGETCLASS +#define xmToggleButtonGadgetClass XMTOGGLEBUTTONGADGETCLASS +#define xmToggleButtonWidgetClass XMTOGGLEBUTTONWIDGETCLASS + +#if (__VMS_VER < 80200000) +# define SetReqLen(req,n,badlen) \ + if ((req->length + n) > (unsigned)65535) { \ + n = badlen; \ + req->length += n; \ + } else \ + req->length += n +#endif + +#ifdef __cplusplus +extern "C" { +#endif +extern void XtFree(char*); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/GL/wglext.h b/include/GL/wglext.h new file mode 100644 index 0000000..e60c652 --- /dev/null +++ b/include/GL/wglext.h @@ -0,0 +1,901 @@ +#ifndef __wglext_h_ +#define __wglext_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2010 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are 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 Materials. +** +** THE MATERIALS ARE 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 +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Function declaration macros - to move into glplatform.h */ + +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif +#ifndef GLAPI +#define GLAPI extern +#endif + +/*************************************************************/ + +/* Header file version number */ +/* wglext.h last updated 2010/08/06 */ +/* Current version at http://www.opengl.org/registry/ */ +#define WGL_WGLEXT_VERSION 22 + +#ifndef WGL_ARB_buffer_region +#define WGL_FRONT_COLOR_BUFFER_BIT_ARB 0x00000001 +#define WGL_BACK_COLOR_BUFFER_BIT_ARB 0x00000002 +#define WGL_DEPTH_BUFFER_BIT_ARB 0x00000004 +#define WGL_STENCIL_BUFFER_BIT_ARB 0x00000008 +#endif + +#ifndef WGL_ARB_multisample +#define WGL_SAMPLE_BUFFERS_ARB 0x2041 +#define WGL_SAMPLES_ARB 0x2042 +#endif + +#ifndef WGL_ARB_extensions_string +#endif + +#ifndef WGL_ARB_pixel_format +#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 +#define WGL_DRAW_TO_WINDOW_ARB 0x2001 +#define WGL_DRAW_TO_BITMAP_ARB 0x2002 +#define WGL_ACCELERATION_ARB 0x2003 +#define WGL_NEED_PALETTE_ARB 0x2004 +#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 +#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 +#define WGL_SWAP_METHOD_ARB 0x2007 +#define WGL_NUMBER_OVERLAYS_ARB 0x2008 +#define WGL_NUMBER_UNDERLAYS_ARB 0x2009 +#define WGL_TRANSPARENT_ARB 0x200A +#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 +#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038 +#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 +#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A +#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B +#define WGL_SHARE_DEPTH_ARB 0x200C +#define WGL_SHARE_STENCIL_ARB 0x200D +#define WGL_SHARE_ACCUM_ARB 0x200E +#define WGL_SUPPORT_GDI_ARB 0x200F +#define WGL_SUPPORT_OPENGL_ARB 0x2010 +#define WGL_DOUBLE_BUFFER_ARB 0x2011 +#define WGL_STEREO_ARB 0x2012 +#define WGL_PIXEL_TYPE_ARB 0x2013 +#define WGL_COLOR_BITS_ARB 0x2014 +#define WGL_RED_BITS_ARB 0x2015 +#define WGL_RED_SHIFT_ARB 0x2016 +#define WGL_GREEN_BITS_ARB 0x2017 +#define WGL_GREEN_SHIFT_ARB 0x2018 +#define WGL_BLUE_BITS_ARB 0x2019 +#define WGL_BLUE_SHIFT_ARB 0x201A +#define WGL_ALPHA_BITS_ARB 0x201B +#define WGL_ALPHA_SHIFT_ARB 0x201C +#define WGL_ACCUM_BITS_ARB 0x201D +#define WGL_ACCUM_RED_BITS_ARB 0x201E +#define WGL_ACCUM_GREEN_BITS_ARB 0x201F +#define WGL_ACCUM_BLUE_BITS_ARB 0x2020 +#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 +#define WGL_DEPTH_BITS_ARB 0x2022 +#define WGL_STENCIL_BITS_ARB 0x2023 +#define WGL_AUX_BUFFERS_ARB 0x2024 +#define WGL_NO_ACCELERATION_ARB 0x2025 +#define WGL_GENERIC_ACCELERATION_ARB 0x2026 +#define WGL_FULL_ACCELERATION_ARB 0x2027 +#define WGL_SWAP_EXCHANGE_ARB 0x2028 +#define WGL_SWAP_COPY_ARB 0x2029 +#define WGL_SWAP_UNDEFINED_ARB 0x202A +#define WGL_TYPE_RGBA_ARB 0x202B +#define WGL_TYPE_COLORINDEX_ARB 0x202C +#endif + +#ifndef WGL_ARB_make_current_read +#define ERROR_INVALID_PIXEL_TYPE_ARB 0x2043 +#define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054 +#endif + +#ifndef WGL_ARB_pbuffer +#define WGL_DRAW_TO_PBUFFER_ARB 0x202D +#define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E +#define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F +#define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030 +#define WGL_PBUFFER_LARGEST_ARB 0x2033 +#define WGL_PBUFFER_WIDTH_ARB 0x2034 +#define WGL_PBUFFER_HEIGHT_ARB 0x2035 +#define WGL_PBUFFER_LOST_ARB 0x2036 +#endif + +#ifndef WGL_ARB_render_texture +#define WGL_BIND_TO_TEXTURE_RGB_ARB 0x2070 +#define WGL_BIND_TO_TEXTURE_RGBA_ARB 0x2071 +#define WGL_TEXTURE_FORMAT_ARB 0x2072 +#define WGL_TEXTURE_TARGET_ARB 0x2073 +#define WGL_MIPMAP_TEXTURE_ARB 0x2074 +#define WGL_TEXTURE_RGB_ARB 0x2075 +#define WGL_TEXTURE_RGBA_ARB 0x2076 +#define WGL_NO_TEXTURE_ARB 0x2077 +#define WGL_TEXTURE_CUBE_MAP_ARB 0x2078 +#define WGL_TEXTURE_1D_ARB 0x2079 +#define WGL_TEXTURE_2D_ARB 0x207A +#define WGL_MIPMAP_LEVEL_ARB 0x207B +#define WGL_CUBE_MAP_FACE_ARB 0x207C +#define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x207D +#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x207E +#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x207F +#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x2080 +#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x2081 +#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x2082 +#define WGL_FRONT_LEFT_ARB 0x2083 +#define WGL_FRONT_RIGHT_ARB 0x2084 +#define WGL_BACK_LEFT_ARB 0x2085 +#define WGL_BACK_RIGHT_ARB 0x2086 +#define WGL_AUX0_ARB 0x2087 +#define WGL_AUX1_ARB 0x2088 +#define WGL_AUX2_ARB 0x2089 +#define WGL_AUX3_ARB 0x208A +#define WGL_AUX4_ARB 0x208B +#define WGL_AUX5_ARB 0x208C +#define WGL_AUX6_ARB 0x208D +#define WGL_AUX7_ARB 0x208E +#define WGL_AUX8_ARB 0x208F +#define WGL_AUX9_ARB 0x2090 +#endif + +#ifndef WGL_ARB_pixel_format_float +#define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0 +#endif + +#ifndef WGL_ARB_framebuffer_sRGB +#define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9 +#endif + +#ifndef WGL_ARB_create_context +#define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001 +#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 +#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 +#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093 +#define WGL_CONTEXT_FLAGS_ARB 0x2094 +#define ERROR_INVALID_VERSION_ARB 0x2095 +#endif + +#ifndef WGL_ARB_create_context_profile +#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 +#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 +#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 +#define ERROR_INVALID_PROFILE_ARB 0x2096 +#endif + +#ifndef WGL_ARB_create_context_robustness +#define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 +#define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 +#define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 +#define WGL_NO_RESET_NOTIFICATION_ARB 0x8261 +#endif + +#ifndef WGL_EXT_make_current_read +#define ERROR_INVALID_PIXEL_TYPE_EXT 0x2043 +#endif + +#ifndef WGL_EXT_pixel_format +#define WGL_NUMBER_PIXEL_FORMATS_EXT 0x2000 +#define WGL_DRAW_TO_WINDOW_EXT 0x2001 +#define WGL_DRAW_TO_BITMAP_EXT 0x2002 +#define WGL_ACCELERATION_EXT 0x2003 +#define WGL_NEED_PALETTE_EXT 0x2004 +#define WGL_NEED_SYSTEM_PALETTE_EXT 0x2005 +#define WGL_SWAP_LAYER_BUFFERS_EXT 0x2006 +#define WGL_SWAP_METHOD_EXT 0x2007 +#define WGL_NUMBER_OVERLAYS_EXT 0x2008 +#define WGL_NUMBER_UNDERLAYS_EXT 0x2009 +#define WGL_TRANSPARENT_EXT 0x200A +#define WGL_TRANSPARENT_VALUE_EXT 0x200B +#define WGL_SHARE_DEPTH_EXT 0x200C +#define WGL_SHARE_STENCIL_EXT 0x200D +#define WGL_SHARE_ACCUM_EXT 0x200E +#define WGL_SUPPORT_GDI_EXT 0x200F +#define WGL_SUPPORT_OPENGL_EXT 0x2010 +#define WGL_DOUBLE_BUFFER_EXT 0x2011 +#define WGL_STEREO_EXT 0x2012 +#define WGL_PIXEL_TYPE_EXT 0x2013 +#define WGL_COLOR_BITS_EXT 0x2014 +#define WGL_RED_BITS_EXT 0x2015 +#define WGL_RED_SHIFT_EXT 0x2016 +#define WGL_GREEN_BITS_EXT 0x2017 +#define WGL_GREEN_SHIFT_EXT 0x2018 +#define WGL_BLUE_BITS_EXT 0x2019 +#define WGL_BLUE_SHIFT_EXT 0x201A +#define WGL_ALPHA_BITS_EXT 0x201B +#define WGL_ALPHA_SHIFT_EXT 0x201C +#define WGL_ACCUM_BITS_EXT 0x201D +#define WGL_ACCUM_RED_BITS_EXT 0x201E +#define WGL_ACCUM_GREEN_BITS_EXT 0x201F +#define WGL_ACCUM_BLUE_BITS_EXT 0x2020 +#define WGL_ACCUM_ALPHA_BITS_EXT 0x2021 +#define WGL_DEPTH_BITS_EXT 0x2022 +#define WGL_STENCIL_BITS_EXT 0x2023 +#define WGL_AUX_BUFFERS_EXT 0x2024 +#define WGL_NO_ACCELERATION_EXT 0x2025 +#define WGL_GENERIC_ACCELERATION_EXT 0x2026 +#define WGL_FULL_ACCELERATION_EXT 0x2027 +#define WGL_SWAP_EXCHANGE_EXT 0x2028 +#define WGL_SWAP_COPY_EXT 0x2029 +#define WGL_SWAP_UNDEFINED_EXT 0x202A +#define WGL_TYPE_RGBA_EXT 0x202B +#define WGL_TYPE_COLORINDEX_EXT 0x202C +#endif + +#ifndef WGL_EXT_pbuffer +#define WGL_DRAW_TO_PBUFFER_EXT 0x202D +#define WGL_MAX_PBUFFER_PIXELS_EXT 0x202E +#define WGL_MAX_PBUFFER_WIDTH_EXT 0x202F +#define WGL_MAX_PBUFFER_HEIGHT_EXT 0x2030 +#define WGL_OPTIMAL_PBUFFER_WIDTH_EXT 0x2031 +#define WGL_OPTIMAL_PBUFFER_HEIGHT_EXT 0x2032 +#define WGL_PBUFFER_LARGEST_EXT 0x2033 +#define WGL_PBUFFER_WIDTH_EXT 0x2034 +#define WGL_PBUFFER_HEIGHT_EXT 0x2035 +#endif + +#ifndef WGL_EXT_depth_float +#define WGL_DEPTH_FLOAT_EXT 0x2040 +#endif + +#ifndef WGL_3DFX_multisample +#define WGL_SAMPLE_BUFFERS_3DFX 0x2060 +#define WGL_SAMPLES_3DFX 0x2061 +#endif + +#ifndef WGL_EXT_multisample +#define WGL_SAMPLE_BUFFERS_EXT 0x2041 +#define WGL_SAMPLES_EXT 0x2042 +#endif + +#ifndef WGL_I3D_digital_video_control +#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D 0x2050 +#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D 0x2051 +#define WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D 0x2052 +#define WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D 0x2053 +#endif + +#ifndef WGL_I3D_gamma +#define WGL_GAMMA_TABLE_SIZE_I3D 0x204E +#define WGL_GAMMA_EXCLUDE_DESKTOP_I3D 0x204F +#endif + +#ifndef WGL_I3D_genlock +#define WGL_GENLOCK_SOURCE_MULTIVIEW_I3D 0x2044 +#define WGL_GENLOCK_SOURCE_EXTENAL_SYNC_I3D 0x2045 +#define WGL_GENLOCK_SOURCE_EXTENAL_FIELD_I3D 0x2046 +#define WGL_GENLOCK_SOURCE_EXTENAL_TTL_I3D 0x2047 +#define WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D 0x2048 +#define WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D 0x2049 +#define WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D 0x204A +#define WGL_GENLOCK_SOURCE_EDGE_RISING_I3D 0x204B +#define WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D 0x204C +#endif + +#ifndef WGL_I3D_image_buffer +#define WGL_IMAGE_BUFFER_MIN_ACCESS_I3D 0x00000001 +#define WGL_IMAGE_BUFFER_LOCK_I3D 0x00000002 +#endif + +#ifndef WGL_I3D_swap_frame_lock +#endif + +#ifndef WGL_NV_render_depth_texture +#define WGL_BIND_TO_TEXTURE_DEPTH_NV 0x20A3 +#define WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV 0x20A4 +#define WGL_DEPTH_TEXTURE_FORMAT_NV 0x20A5 +#define WGL_TEXTURE_DEPTH_COMPONENT_NV 0x20A6 +#define WGL_DEPTH_COMPONENT_NV 0x20A7 +#endif + +#ifndef WGL_NV_render_texture_rectangle +#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV 0x20A0 +#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV 0x20A1 +#define WGL_TEXTURE_RECTANGLE_NV 0x20A2 +#endif + +#ifndef WGL_ATI_pixel_format_float +#define WGL_TYPE_RGBA_FLOAT_ATI 0x21A0 +#endif + +#ifndef WGL_NV_float_buffer +#define WGL_FLOAT_COMPONENTS_NV 0x20B0 +#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1 +#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2 +#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3 +#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4 +#define WGL_TEXTURE_FLOAT_R_NV 0x20B5 +#define WGL_TEXTURE_FLOAT_RG_NV 0x20B6 +#define WGL_TEXTURE_FLOAT_RGB_NV 0x20B7 +#define WGL_TEXTURE_FLOAT_RGBA_NV 0x20B8 +#endif + +#ifndef WGL_3DL_stereo_control +#define WGL_STEREO_EMITTER_ENABLE_3DL 0x2055 +#define WGL_STEREO_EMITTER_DISABLE_3DL 0x2056 +#define WGL_STEREO_POLARITY_NORMAL_3DL 0x2057 +#define WGL_STEREO_POLARITY_INVERT_3DL 0x2058 +#endif + +#ifndef WGL_EXT_pixel_format_packed_float +#define WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT 0x20A8 +#endif + +#ifndef WGL_EXT_framebuffer_sRGB +#define WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20A9 +#endif + +#ifndef WGL_NV_present_video +#define WGL_NUM_VIDEO_SLOTS_NV 0x20F0 +#endif + +#ifndef WGL_NV_video_out +#define WGL_BIND_TO_VIDEO_RGB_NV 0x20C0 +#define WGL_BIND_TO_VIDEO_RGBA_NV 0x20C1 +#define WGL_BIND_TO_VIDEO_RGB_AND_DEPTH_NV 0x20C2 +#define WGL_VIDEO_OUT_COLOR_NV 0x20C3 +#define WGL_VIDEO_OUT_ALPHA_NV 0x20C4 +#define WGL_VIDEO_OUT_DEPTH_NV 0x20C5 +#define WGL_VIDEO_OUT_COLOR_AND_ALPHA_NV 0x20C6 +#define WGL_VIDEO_OUT_COLOR_AND_DEPTH_NV 0x20C7 +#define WGL_VIDEO_OUT_FRAME 0x20C8 +#define WGL_VIDEO_OUT_FIELD_1 0x20C9 +#define WGL_VIDEO_OUT_FIELD_2 0x20CA +#define WGL_VIDEO_OUT_STACKED_FIELDS_1_2 0x20CB +#define WGL_VIDEO_OUT_STACKED_FIELDS_2_1 0x20CC +#endif + +#ifndef WGL_NV_swap_group +#endif + +#ifndef WGL_NV_gpu_affinity +#define WGL_ERROR_INCOMPATIBLE_AFFINITY_MASKS_NV 0x20D0 +#define WGL_ERROR_MISSING_AFFINITY_MASK_NV 0x20D1 +#endif + +#ifndef WGL_AMD_gpu_association +#define WGL_GPU_VENDOR_AMD 0x1F00 +#define WGL_GPU_RENDERER_STRING_AMD 0x1F01 +#define WGL_GPU_OPENGL_VERSION_STRING_AMD 0x1F02 +#define WGL_GPU_FASTEST_TARGET_GPUS_AMD 0x21A2 +#define WGL_GPU_RAM_AMD 0x21A3 +#define WGL_GPU_CLOCK_AMD 0x21A4 +#define WGL_GPU_NUM_PIPES_AMD 0x21A5 +#define WGL_GPU_NUM_SIMD_AMD 0x21A6 +#define WGL_GPU_NUM_RB_AMD 0x21A7 +#define WGL_GPU_NUM_SPI_AMD 0x21A8 +#endif + +#ifndef WGL_NV_video_capture +#define WGL_UNIQUE_ID_NV 0x20CE +#define WGL_NUM_VIDEO_CAPTURE_SLOTS_NV 0x20CF +#endif + +#ifndef WGL_NV_copy_image +#endif + +#ifndef WGL_NV_multisample_coverage +#define WGL_COVERAGE_SAMPLES_NV 0x2042 +#define WGL_COLOR_SAMPLES_NV 0x20B9 +#endif + +#ifndef WGL_EXT_create_context_es2_profile +#define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 +#endif + + +/*************************************************************/ + +#ifndef WGL_ARB_pbuffer +DECLARE_HANDLE(HPBUFFERARB); +#endif +#ifndef WGL_EXT_pbuffer +DECLARE_HANDLE(HPBUFFEREXT); +#endif +#ifndef WGL_NV_present_video +DECLARE_HANDLE(HVIDEOOUTPUTDEVICENV); +#endif +#ifndef WGL_NV_video_output +DECLARE_HANDLE(HPVIDEODEV); +#endif +#ifndef WGL_NV_gpu_affinity +DECLARE_HANDLE(HPGPUNV); +DECLARE_HANDLE(HGPUNV); + +typedef struct _GPU_DEVICE { + DWORD cb; + CHAR DeviceName[32]; + CHAR DeviceString[128]; + DWORD Flags; + RECT rcVirtualScreen; +} GPU_DEVICE, *PGPU_DEVICE; +#endif +#ifndef WGL_NV_video_capture +DECLARE_HANDLE(HVIDEOINPUTDEVICENV); +#endif + +#ifndef WGL_ARB_buffer_region +#define WGL_ARB_buffer_region 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern HANDLE WINAPI wglCreateBufferRegionARB (HDC hDC, int iLayerPlane, UINT uType); +extern VOID WINAPI wglDeleteBufferRegionARB (HANDLE hRegion); +extern BOOL WINAPI wglSaveBufferRegionARB (HANDLE hRegion, int x, int y, int width, int height); +extern BOOL WINAPI wglRestoreBufferRegionARB (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef HANDLE (WINAPI * PFNWGLCREATEBUFFERREGIONARBPROC) (HDC hDC, int iLayerPlane, UINT uType); +typedef VOID (WINAPI * PFNWGLDELETEBUFFERREGIONARBPROC) (HANDLE hRegion); +typedef BOOL (WINAPI * PFNWGLSAVEBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height); +typedef BOOL (WINAPI * PFNWGLRESTOREBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc); +#endif + +#ifndef WGL_ARB_multisample +#define WGL_ARB_multisample 1 +#endif + +#ifndef WGL_ARB_extensions_string +#define WGL_ARB_extensions_string 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern const char * WINAPI wglGetExtensionsStringARB (HDC hdc); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc); +#endif + +#ifndef WGL_ARB_pixel_format +#define WGL_ARB_pixel_format 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglGetPixelFormatAttribivARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues); +extern BOOL WINAPI wglGetPixelFormatAttribfvARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues); +extern BOOL WINAPI wglChoosePixelFormatARB (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues); +typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues); +typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); +#endif + +#ifndef WGL_ARB_make_current_read +#define WGL_ARB_make_current_read 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglMakeContextCurrentARB (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); +extern HDC WINAPI wglGetCurrentReadDCARB (void); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTARBPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); +typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCARBPROC) (void); +#endif + +#ifndef WGL_ARB_pbuffer +#define WGL_ARB_pbuffer 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern HPBUFFERARB WINAPI wglCreatePbufferARB (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); +extern HDC WINAPI wglGetPbufferDCARB (HPBUFFERARB hPbuffer); +extern int WINAPI wglReleasePbufferDCARB (HPBUFFERARB hPbuffer, HDC hDC); +extern BOOL WINAPI wglDestroyPbufferARB (HPBUFFERARB hPbuffer); +extern BOOL WINAPI wglQueryPbufferARB (HPBUFFERARB hPbuffer, int iAttribute, int *piValue); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef HPBUFFERARB (WINAPI * PFNWGLCREATEPBUFFERARBPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); +typedef HDC (WINAPI * PFNWGLGETPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer); +typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer, HDC hDC); +typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFERARBPROC) (HPBUFFERARB hPbuffer); +typedef BOOL (WINAPI * PFNWGLQUERYPBUFFERARBPROC) (HPBUFFERARB hPbuffer, int iAttribute, int *piValue); +#endif + +#ifndef WGL_ARB_render_texture +#define WGL_ARB_render_texture 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglBindTexImageARB (HPBUFFERARB hPbuffer, int iBuffer); +extern BOOL WINAPI wglReleaseTexImageARB (HPBUFFERARB hPbuffer, int iBuffer); +extern BOOL WINAPI wglSetPbufferAttribARB (HPBUFFERARB hPbuffer, const int *piAttribList); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLBINDTEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer); +typedef BOOL (WINAPI * PFNWGLRELEASETEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer); +typedef BOOL (WINAPI * PFNWGLSETPBUFFERATTRIBARBPROC) (HPBUFFERARB hPbuffer, const int *piAttribList); +#endif + +#ifndef WGL_ARB_pixel_format_float +#define WGL_ARB_pixel_format_float 1 +#endif + +#ifndef WGL_ARB_framebuffer_sRGB +#define WGL_ARB_framebuffer_sRGB 1 +#endif + +#ifndef WGL_ARB_create_context +#define WGL_ARB_create_context 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern HGLRC WINAPI wglCreateContextAttribsARB (HDC hDC, HGLRC hShareContext, const int *attribList); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList); +#endif + +#ifndef WGL_ARB_create_context_profile +#define WGL_ARB_create_context_profile 1 +#endif + +#ifndef WGL_ARB_create_context_robustness +#define WGL_ARB_create_context_robustness 1 +#endif + +#ifndef WGL_EXT_display_color_table +#define WGL_EXT_display_color_table 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern GLboolean WINAPI wglCreateDisplayColorTableEXT (GLushort id); +extern GLboolean WINAPI wglLoadDisplayColorTableEXT (const GLushort *table, GLuint length); +extern GLboolean WINAPI wglBindDisplayColorTableEXT (GLushort id); +extern VOID WINAPI wglDestroyDisplayColorTableEXT (GLushort id); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef GLboolean (WINAPI * PFNWGLCREATEDISPLAYCOLORTABLEEXTPROC) (GLushort id); +typedef GLboolean (WINAPI * PFNWGLLOADDISPLAYCOLORTABLEEXTPROC) (const GLushort *table, GLuint length); +typedef GLboolean (WINAPI * PFNWGLBINDDISPLAYCOLORTABLEEXTPROC) (GLushort id); +typedef VOID (WINAPI * PFNWGLDESTROYDISPLAYCOLORTABLEEXTPROC) (GLushort id); +#endif + +#ifndef WGL_EXT_extensions_string +#define WGL_EXT_extensions_string 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern const char * WINAPI wglGetExtensionsStringEXT (void); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC) (void); +#endif + +#ifndef WGL_EXT_make_current_read +#define WGL_EXT_make_current_read 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglMakeContextCurrentEXT (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); +extern HDC WINAPI wglGetCurrentReadDCEXT (void); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTEXTPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); +typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCEXTPROC) (void); +#endif + +#ifndef WGL_EXT_pbuffer +#define WGL_EXT_pbuffer 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern HPBUFFEREXT WINAPI wglCreatePbufferEXT (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); +extern HDC WINAPI wglGetPbufferDCEXT (HPBUFFEREXT hPbuffer); +extern int WINAPI wglReleasePbufferDCEXT (HPBUFFEREXT hPbuffer, HDC hDC); +extern BOOL WINAPI wglDestroyPbufferEXT (HPBUFFEREXT hPbuffer); +extern BOOL WINAPI wglQueryPbufferEXT (HPBUFFEREXT hPbuffer, int iAttribute, int *piValue); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef HPBUFFEREXT (WINAPI * PFNWGLCREATEPBUFFEREXTPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); +typedef HDC (WINAPI * PFNWGLGETPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer); +typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer, HDC hDC); +typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer); +typedef BOOL (WINAPI * PFNWGLQUERYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer, int iAttribute, int *piValue); +#endif + +#ifndef WGL_EXT_pixel_format +#define WGL_EXT_pixel_format 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglGetPixelFormatAttribivEXT (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues); +extern BOOL WINAPI wglGetPixelFormatAttribfvEXT (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues); +extern BOOL WINAPI wglChoosePixelFormatEXT (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues); +typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues); +typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATEXTPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); +#endif + +#ifndef WGL_EXT_swap_control +#define WGL_EXT_swap_control 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglSwapIntervalEXT (int interval); +extern int WINAPI wglGetSwapIntervalEXT (void); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval); +typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void); +#endif + +#ifndef WGL_EXT_depth_float +#define WGL_EXT_depth_float 1 +#endif + +#ifndef WGL_NV_vertex_array_range +#define WGL_NV_vertex_array_range 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern void* WINAPI wglAllocateMemoryNV (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority); +extern void WINAPI wglFreeMemoryNV (void *pointer); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef void* (WINAPI * PFNWGLALLOCATEMEMORYNVPROC) (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority); +typedef void (WINAPI * PFNWGLFREEMEMORYNVPROC) (void *pointer); +#endif + +#ifndef WGL_3DFX_multisample +#define WGL_3DFX_multisample 1 +#endif + +#ifndef WGL_EXT_multisample +#define WGL_EXT_multisample 1 +#endif + +#ifndef WGL_OML_sync_control +#define WGL_OML_sync_control 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglGetSyncValuesOML (HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc); +extern BOOL WINAPI wglGetMscRateOML (HDC hdc, INT32 *numerator, INT32 *denominator); +extern INT64 WINAPI wglSwapBuffersMscOML (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder); +extern INT64 WINAPI wglSwapLayerBuffersMscOML (HDC hdc, int fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder); +extern BOOL WINAPI wglWaitForMscOML (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64 *ust, INT64 *msc, INT64 *sbc); +extern BOOL WINAPI wglWaitForSbcOML (HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLGETSYNCVALUESOMLPROC) (HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc); +typedef BOOL (WINAPI * PFNWGLGETMSCRATEOMLPROC) (HDC hdc, INT32 *numerator, INT32 *denominator); +typedef INT64 (WINAPI * PFNWGLSWAPBUFFERSMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder); +typedef INT64 (WINAPI * PFNWGLSWAPLAYERBUFFERSMSCOMLPROC) (HDC hdc, int fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder); +typedef BOOL (WINAPI * PFNWGLWAITFORMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64 *ust, INT64 *msc, INT64 *sbc); +typedef BOOL (WINAPI * PFNWGLWAITFORSBCOMLPROC) (HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc); +#endif + +#ifndef WGL_I3D_digital_video_control +#define WGL_I3D_digital_video_control 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglGetDigitalVideoParametersI3D (HDC hDC, int iAttribute, int *piValue); +extern BOOL WINAPI wglSetDigitalVideoParametersI3D (HDC hDC, int iAttribute, const int *piValue); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLGETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int *piValue); +typedef BOOL (WINAPI * PFNWGLSETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int *piValue); +#endif + +#ifndef WGL_I3D_gamma +#define WGL_I3D_gamma 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglGetGammaTableParametersI3D (HDC hDC, int iAttribute, int *piValue); +extern BOOL WINAPI wglSetGammaTableParametersI3D (HDC hDC, int iAttribute, const int *piValue); +extern BOOL WINAPI wglGetGammaTableI3D (HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, USHORT *puBlue); +extern BOOL WINAPI wglSetGammaTableI3D (HDC hDC, int iEntries, const USHORT *puRed, const USHORT *puGreen, const USHORT *puBlue); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int *piValue); +typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int *piValue); +typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, USHORT *puBlue); +typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, const USHORT *puRed, const USHORT *puGreen, const USHORT *puBlue); +#endif + +#ifndef WGL_I3D_genlock +#define WGL_I3D_genlock 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglEnableGenlockI3D (HDC hDC); +extern BOOL WINAPI wglDisableGenlockI3D (HDC hDC); +extern BOOL WINAPI wglIsEnabledGenlockI3D (HDC hDC, BOOL *pFlag); +extern BOOL WINAPI wglGenlockSourceI3D (HDC hDC, UINT uSource); +extern BOOL WINAPI wglGetGenlockSourceI3D (HDC hDC, UINT *uSource); +extern BOOL WINAPI wglGenlockSourceEdgeI3D (HDC hDC, UINT uEdge); +extern BOOL WINAPI wglGetGenlockSourceEdgeI3D (HDC hDC, UINT *uEdge); +extern BOOL WINAPI wglGenlockSampleRateI3D (HDC hDC, UINT uRate); +extern BOOL WINAPI wglGetGenlockSampleRateI3D (HDC hDC, UINT *uRate); +extern BOOL WINAPI wglGenlockSourceDelayI3D (HDC hDC, UINT uDelay); +extern BOOL WINAPI wglGetGenlockSourceDelayI3D (HDC hDC, UINT *uDelay); +extern BOOL WINAPI wglQueryGenlockMaxSourceDelayI3D (HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLENABLEGENLOCKI3DPROC) (HDC hDC); +typedef BOOL (WINAPI * PFNWGLDISABLEGENLOCKI3DPROC) (HDC hDC); +typedef BOOL (WINAPI * PFNWGLISENABLEDGENLOCKI3DPROC) (HDC hDC, BOOL *pFlag); +typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEI3DPROC) (HDC hDC, UINT uSource); +typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEI3DPROC) (HDC hDC, UINT *uSource); +typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT uEdge); +typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT *uEdge); +typedef BOOL (WINAPI * PFNWGLGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT uRate); +typedef BOOL (WINAPI * PFNWGLGETGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT *uRate); +typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT uDelay); +typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT *uDelay); +typedef BOOL (WINAPI * PFNWGLQUERYGENLOCKMAXSOURCEDELAYI3DPROC) (HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay); +#endif + +#ifndef WGL_I3D_image_buffer +#define WGL_I3D_image_buffer 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern LPVOID WINAPI wglCreateImageBufferI3D (HDC hDC, DWORD dwSize, UINT uFlags); +extern BOOL WINAPI wglDestroyImageBufferI3D (HDC hDC, LPVOID pAddress); +extern BOOL WINAPI wglAssociateImageBufferEventsI3D (HDC hDC, const HANDLE *pEvent, const LPVOID *pAddress, const DWORD *pSize, UINT count); +extern BOOL WINAPI wglReleaseImageBufferEventsI3D (HDC hDC, const LPVOID *pAddress, UINT count); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef LPVOID (WINAPI * PFNWGLCREATEIMAGEBUFFERI3DPROC) (HDC hDC, DWORD dwSize, UINT uFlags); +typedef BOOL (WINAPI * PFNWGLDESTROYIMAGEBUFFERI3DPROC) (HDC hDC, LPVOID pAddress); +typedef BOOL (WINAPI * PFNWGLASSOCIATEIMAGEBUFFEREVENTSI3DPROC) (HDC hDC, const HANDLE *pEvent, const LPVOID *pAddress, const DWORD *pSize, UINT count); +typedef BOOL (WINAPI * PFNWGLRELEASEIMAGEBUFFEREVENTSI3DPROC) (HDC hDC, const LPVOID *pAddress, UINT count); +#endif + +#ifndef WGL_I3D_swap_frame_lock +#define WGL_I3D_swap_frame_lock 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglEnableFrameLockI3D (void); +extern BOOL WINAPI wglDisableFrameLockI3D (void); +extern BOOL WINAPI wglIsEnabledFrameLockI3D (BOOL *pFlag); +extern BOOL WINAPI wglQueryFrameLockMasterI3D (BOOL *pFlag); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLENABLEFRAMELOCKI3DPROC) (void); +typedef BOOL (WINAPI * PFNWGLDISABLEFRAMELOCKI3DPROC) (void); +typedef BOOL (WINAPI * PFNWGLISENABLEDFRAMELOCKI3DPROC) (BOOL *pFlag); +typedef BOOL (WINAPI * PFNWGLQUERYFRAMELOCKMASTERI3DPROC) (BOOL *pFlag); +#endif + +#ifndef WGL_I3D_swap_frame_usage +#define WGL_I3D_swap_frame_usage 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglGetFrameUsageI3D (float *pUsage); +extern BOOL WINAPI wglBeginFrameTrackingI3D (void); +extern BOOL WINAPI wglEndFrameTrackingI3D (void); +extern BOOL WINAPI wglQueryFrameTrackingI3D (DWORD *pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLGETFRAMEUSAGEI3DPROC) (float *pUsage); +typedef BOOL (WINAPI * PFNWGLBEGINFRAMETRACKINGI3DPROC) (void); +typedef BOOL (WINAPI * PFNWGLENDFRAMETRACKINGI3DPROC) (void); +typedef BOOL (WINAPI * PFNWGLQUERYFRAMETRACKINGI3DPROC) (DWORD *pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage); +#endif + +#ifndef WGL_ATI_pixel_format_float +#define WGL_ATI_pixel_format_float 1 +#endif + +#ifndef WGL_NV_float_buffer +#define WGL_NV_float_buffer 1 +#endif + +#ifndef WGL_3DL_stereo_control +#define WGL_3DL_stereo_control 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglSetStereoEmitterState3DL (HDC hDC, UINT uState); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLSETSTEREOEMITTERSTATE3DLPROC) (HDC hDC, UINT uState); +#endif + +#ifndef WGL_EXT_pixel_format_packed_float +#define WGL_EXT_pixel_format_packed_float 1 +#endif + +#ifndef WGL_EXT_framebuffer_sRGB +#define WGL_EXT_framebuffer_sRGB 1 +#endif + +#ifndef WGL_NV_present_video +#define WGL_NV_present_video 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern int WINAPI wglEnumerateVideoDevicesNV (HDC hDC, HVIDEOOUTPUTDEVICENV *phDeviceList); +extern BOOL WINAPI wglBindVideoDeviceNV (HDC hDC, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int *piAttribList); +extern BOOL WINAPI wglQueryCurrentContextNV (int iAttribute, int *piValue); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef int (WINAPI * PFNWGLENUMERATEVIDEODEVICESNVPROC) (HDC hDC, HVIDEOOUTPUTDEVICENV *phDeviceList); +typedef BOOL (WINAPI * PFNWGLBINDVIDEODEVICENVPROC) (HDC hDC, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int *piAttribList); +typedef BOOL (WINAPI * PFNWGLQUERYCURRENTCONTEXTNVPROC) (int iAttribute, int *piValue); +#endif + +#ifndef WGL_NV_video_output +#define WGL_NV_video_output 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglGetVideoDeviceNV (HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice); +extern BOOL WINAPI wglReleaseVideoDeviceNV (HPVIDEODEV hVideoDevice); +extern BOOL WINAPI wglBindVideoImageNV (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer); +extern BOOL WINAPI wglReleaseVideoImageNV (HPBUFFERARB hPbuffer, int iVideoBuffer); +extern BOOL WINAPI wglSendPbufferToVideoNV (HPBUFFERARB hPbuffer, int iBufferType, unsigned long *pulCounterPbuffer, BOOL bBlock); +extern BOOL WINAPI wglGetVideoInfoNV (HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLGETVIDEODEVICENVPROC) (HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice); +typedef BOOL (WINAPI * PFNWGLRELEASEVIDEODEVICENVPROC) (HPVIDEODEV hVideoDevice); +typedef BOOL (WINAPI * PFNWGLBINDVIDEOIMAGENVPROC) (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer); +typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOIMAGENVPROC) (HPBUFFERARB hPbuffer, int iVideoBuffer); +typedef BOOL (WINAPI * PFNWGLSENDPBUFFERTOVIDEONVPROC) (HPBUFFERARB hPbuffer, int iBufferType, unsigned long *pulCounterPbuffer, BOOL bBlock); +typedef BOOL (WINAPI * PFNWGLGETVIDEOINFONVPROC) (HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); +#endif + +#ifndef WGL_NV_swap_group +#define WGL_NV_swap_group 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglJoinSwapGroupNV (HDC hDC, GLuint group); +extern BOOL WINAPI wglBindSwapBarrierNV (GLuint group, GLuint barrier); +extern BOOL WINAPI wglQuerySwapGroupNV (HDC hDC, GLuint *group, GLuint *barrier); +extern BOOL WINAPI wglQueryMaxSwapGroupsNV (HDC hDC, GLuint *maxGroups, GLuint *maxBarriers); +extern BOOL WINAPI wglQueryFrameCountNV (HDC hDC, GLuint *count); +extern BOOL WINAPI wglResetFrameCountNV (HDC hDC); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLJOINSWAPGROUPNVPROC) (HDC hDC, GLuint group); +typedef BOOL (WINAPI * PFNWGLBINDSWAPBARRIERNVPROC) (GLuint group, GLuint barrier); +typedef BOOL (WINAPI * PFNWGLQUERYSWAPGROUPNVPROC) (HDC hDC, GLuint *group, GLuint *barrier); +typedef BOOL (WINAPI * PFNWGLQUERYMAXSWAPGROUPSNVPROC) (HDC hDC, GLuint *maxGroups, GLuint *maxBarriers); +typedef BOOL (WINAPI * PFNWGLQUERYFRAMECOUNTNVPROC) (HDC hDC, GLuint *count); +typedef BOOL (WINAPI * PFNWGLRESETFRAMECOUNTNVPROC) (HDC hDC); +#endif + +#ifndef WGL_NV_gpu_affinity +#define WGL_NV_gpu_affinity 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglEnumGpusNV (UINT iGpuIndex, HGPUNV *phGpu); +extern BOOL WINAPI wglEnumGpuDevicesNV (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice); +extern HDC WINAPI wglCreateAffinityDCNV (const HGPUNV *phGpuList); +extern BOOL WINAPI wglEnumGpusFromAffinityDCNV (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu); +extern BOOL WINAPI wglDeleteDCNV (HDC hdc); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLENUMGPUSNVPROC) (UINT iGpuIndex, HGPUNV *phGpu); +typedef BOOL (WINAPI * PFNWGLENUMGPUDEVICESNVPROC) (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice); +typedef HDC (WINAPI * PFNWGLCREATEAFFINITYDCNVPROC) (const HGPUNV *phGpuList); +typedef BOOL (WINAPI * PFNWGLENUMGPUSFROMAFFINITYDCNVPROC) (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu); +typedef BOOL (WINAPI * PFNWGLDELETEDCNVPROC) (HDC hdc); +#endif + +#ifndef WGL_AMD_gpu_association +#define WGL_AMD_gpu_association 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern UINT WINAPI wglGetGPUIDsAMD (UINT maxCount, UINT *ids); +extern INT WINAPI wglGetGPUInfoAMD (UINT id, int property, GLenum dataType, UINT size, void *data); +extern UINT WINAPI wglGetContextGPUIDAMD (HGLRC hglrc); +extern HGLRC WINAPI wglCreateAssociatedContextAMD (UINT id); +extern HGLRC WINAPI wglCreateAssociatedContextAttribsAMD (UINT id, HGLRC hShareContext, const int *attribList); +extern BOOL WINAPI wglDeleteAssociatedContextAMD (HGLRC hglrc); +extern BOOL WINAPI wglMakeAssociatedContextCurrentAMD (HGLRC hglrc); +extern HGLRC WINAPI wglGetCurrentAssociatedContextAMD (void); +extern VOID WINAPI wglBlitContextFramebufferAMD (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef UINT (WINAPI * PFNWGLGETGPUIDSAMDPROC) (UINT maxCount, UINT *ids); +typedef INT (WINAPI * PFNWGLGETGPUINFOAMDPROC) (UINT id, int property, GLenum dataType, UINT size, void *data); +typedef UINT (WINAPI * PFNWGLGETCONTEXTGPUIDAMDPROC) (HGLRC hglrc); +typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTAMDPROC) (UINT id); +typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTATTRIBSAMDPROC) (UINT id, HGLRC hShareContext, const int *attribList); +typedef BOOL (WINAPI * PFNWGLDELETEASSOCIATEDCONTEXTAMDPROC) (HGLRC hglrc); +typedef BOOL (WINAPI * PFNWGLMAKEASSOCIATEDCONTEXTCURRENTAMDPROC) (HGLRC hglrc); +typedef HGLRC (WINAPI * PFNWGLGETCURRENTASSOCIATEDCONTEXTAMDPROC) (void); +typedef VOID (WINAPI * PFNWGLBLITCONTEXTFRAMEBUFFERAMDPROC) (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#endif + +#ifndef WGL_NV_video_capture +#define WGL_NV_video_capture 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglBindVideoCaptureDeviceNV (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice); +extern UINT WINAPI wglEnumerateVideoCaptureDevicesNV (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList); +extern BOOL WINAPI wglLockVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice); +extern BOOL WINAPI wglQueryVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue); +extern BOOL WINAPI wglReleaseVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLBINDVIDEOCAPTUREDEVICENVPROC) (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice); +typedef UINT (WINAPI * PFNWGLENUMERATEVIDEOCAPTUREDEVICESNVPROC) (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList); +typedef BOOL (WINAPI * PFNWGLLOCKVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice); +typedef BOOL (WINAPI * PFNWGLQUERYVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue); +typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice); +#endif + +#ifndef WGL_NV_copy_image +#define WGL_NV_copy_image 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglCopyImageSubDataNV (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLCOPYIMAGESUBDATANVPROC) (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +#endif + +#ifndef WGL_NV_multisample_coverage +#define WGL_NV_multisample_coverage 1 +#endif + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/GL/wmesa.h b/include/GL/wmesa.h new file mode 100644 index 0000000..f5f4f27 --- /dev/null +++ b/include/GL/wmesa.h @@ -0,0 +1,141 @@ +/* + * Mesa 3-D graphics library + * Version: 3.0 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + + +/* + * Windows driver by: Mark E. Peterson (markp@ic.mankato.mn.us) + * Updated by Li Wei (liwei@aiar.xjtu.edu.cn) + * + * + *************************************************************** + * WMesa * + * version 2.3 * + * * + * By * + * Li Wei * + * Institute of Artificial Intelligence & Robotics * + * Xi'an Jiaotong University * + * Email: liwei@aiar.xjtu.edu.cn * + * Web page: http://sun.aiar.xjtu.edu.cn * + * * + * July 7th, 1997 * + *************************************************************** + */ + + +#ifndef WMESA_H +#define WMESA_H + + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "GL/gl.h" + +#if defined(_MSV_VER) && !defined(__GNUC__) +# pragma warning (disable:4273) +# pragma warning( disable : 4244 ) /* '=' : conversion from 'const double ' to 'float ', possible loss of data */ +# pragma warning( disable : 4018 ) /* '<' : signed/unsigned mismatch */ +# pragma warning( disable : 4305 ) /* '=' : truncation from 'const double ' to 'float ' */ +# pragma warning( disable : 4013 ) /* 'function' undefined; assuming extern returning int */ +# pragma warning( disable : 4761 ) /* integral size mismatch in argument; conversion supplied */ +# pragma warning( disable : 4273 ) /* 'identifier' : inconsistent DLL linkage. dllexport assumed */ +# if (MESA_WARNQUIET>1) +# pragma warning( disable : 4146 ) /* unary minus operator applied to unsigned type, result still unsigned */ +# endif +#endif + +/* + * This is the WMesa context 'handle': + */ +typedef struct wmesa_context *WMesaContext; + + + +/* + * Create a new WMesaContext for rendering into a window. You must + * have already created the window of correct visual type and with an + * appropriate colormap. + * + * Input: + * hDC - Windows device or memory context + * Pal - Palette to use + * rgb_flag - GL_TRUE = RGB mode, + * GL_FALSE = color index mode + * db_flag - GL_TRUE = double-buffered, + * GL_FALSE = single buffered + * alpha_flag - GL_TRUE = create software alpha buffer, + * GL_FALSE = no software alpha buffer + * + * Note: Indexed mode requires double buffering under Windows. + * + * Return: a WMesa_context or NULL if error. + */ +extern WMesaContext WMesaCreateContext(HDC hDC,HPALETTE* pPal, + GLboolean rgb_flag, + GLboolean db_flag, + GLboolean alpha_flag); + + +/* + * Destroy a rendering context as returned by WMesaCreateContext() + */ +extern void WMesaDestroyContext( WMesaContext ctx ); + + + +/* + * Make the specified context the current one. + */ +extern void WMesaMakeCurrent( WMesaContext ctx, HDC hdc ); + + +/* + * Return a handle to the current context. + */ +extern WMesaContext WMesaGetCurrentContext( void ); + + +/* + * Swap the front and back buffers for the current context. No action + * taken if the context is not double buffered. + */ +extern void WMesaSwapBuffers(HDC hdc); + + +/* + * In indexed color mode we need to know when the palette changes. + */ +extern void WMesaPaletteChange(HPALETTE Pal); + +extern void WMesaMove(void); + +void WMesaShareLists(WMesaContext ctx_to_share, WMesaContext ctx); + +#ifdef __cplusplus +} +#endif + + +#endif + diff --git a/include/GLES/egl.h b/include/GLES/egl.h new file mode 100644 index 0000000..5778e00 --- /dev/null +++ b/include/GLES/egl.h @@ -0,0 +1,15 @@ +/* + * Skeleton egl.h to provide compatibility for early GLES 1.0 + * applications. Several early implementations included gl.h + * in egl.h leading applications to include only egl.h + * + * $Revision: 6252 $ on $Date:: 2008-08-06 16:35:08 -0700 #$ + */ + +#ifndef __legacy_egl_h_ +#define __legacy_egl_h_ + +#include +#include + +#endif /* __legacy_egl_h_ */ diff --git a/include/GLES/gl.h b/include/GLES/gl.h new file mode 100644 index 0000000..5b8d85a --- /dev/null +++ b/include/GLES/gl.h @@ -0,0 +1,770 @@ +#ifndef __gl_h_ +#define __gl_h_ + +/* $Revision: 10601 $ on $Date:: 2010-03-04 22:15:27 -0800 #$ */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +typedef void GLvoid; +typedef char GLchar; +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef khronos_int8_t GLbyte; +typedef short GLshort; +typedef int GLint; +typedef int GLsizei; +typedef khronos_uint8_t GLubyte; +typedef unsigned short GLushort; +typedef unsigned int GLuint; +typedef khronos_float_t GLfloat; +typedef khronos_float_t GLclampf; +typedef khronos_int32_t GLfixed; +typedef khronos_int32_t GLclampx; + +typedef khronos_intptr_t GLintptr; +typedef khronos_ssize_t GLsizeiptr; + + +/*************************************************************/ + +/* OpenGL ES core versions */ +#define GL_VERSION_ES_CM_1_0 1 +#define GL_VERSION_ES_CL_1_0 1 +#define GL_VERSION_ES_CM_1_1 1 +#define GL_VERSION_ES_CL_1_1 1 + +/* ClearBufferMask */ +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_COLOR_BUFFER_BIT 0x00004000 + +/* Boolean */ +#define GL_FALSE 0 +#define GL_TRUE 1 + +/* BeginMode */ +#define GL_POINTS 0x0000 +#define GL_LINES 0x0001 +#define GL_LINE_LOOP 0x0002 +#define GL_LINE_STRIP 0x0003 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_TRIANGLE_FAN 0x0006 + +/* AlphaFunction */ +#define GL_NEVER 0x0200 +#define GL_LESS 0x0201 +#define GL_EQUAL 0x0202 +#define GL_LEQUAL 0x0203 +#define GL_GREATER 0x0204 +#define GL_NOTEQUAL 0x0205 +#define GL_GEQUAL 0x0206 +#define GL_ALWAYS 0x0207 + +/* BlendingFactorDest */ +#define GL_ZERO 0 +#define GL_ONE 1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 + +/* BlendingFactorSrc */ +/* GL_ZERO */ +/* GL_ONE */ +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 +/* GL_SRC_ALPHA */ +/* GL_ONE_MINUS_SRC_ALPHA */ +/* GL_DST_ALPHA */ +/* GL_ONE_MINUS_DST_ALPHA */ + +/* ClipPlaneName */ +#define GL_CLIP_PLANE0 0x3000 +#define GL_CLIP_PLANE1 0x3001 +#define GL_CLIP_PLANE2 0x3002 +#define GL_CLIP_PLANE3 0x3003 +#define GL_CLIP_PLANE4 0x3004 +#define GL_CLIP_PLANE5 0x3005 + +/* ColorMaterialFace */ +/* GL_FRONT_AND_BACK */ + +/* ColorMaterialParameter */ +/* GL_AMBIENT_AND_DIFFUSE */ + +/* ColorPointerType */ +/* GL_UNSIGNED_BYTE */ +/* GL_FLOAT */ +/* GL_FIXED */ + +/* CullFaceMode */ +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_FRONT_AND_BACK 0x0408 + +/* DepthFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* EnableCap */ +#define GL_FOG 0x0B60 +#define GL_LIGHTING 0x0B50 +#define GL_TEXTURE_2D 0x0DE1 +#define GL_CULL_FACE 0x0B44 +#define GL_ALPHA_TEST 0x0BC0 +#define GL_BLEND 0x0BE2 +#define GL_COLOR_LOGIC_OP 0x0BF2 +#define GL_DITHER 0x0BD0 +#define GL_STENCIL_TEST 0x0B90 +#define GL_DEPTH_TEST 0x0B71 +/* GL_LIGHT0 */ +/* GL_LIGHT1 */ +/* GL_LIGHT2 */ +/* GL_LIGHT3 */ +/* GL_LIGHT4 */ +/* GL_LIGHT5 */ +/* GL_LIGHT6 */ +/* GL_LIGHT7 */ +#define GL_POINT_SMOOTH 0x0B10 +#define GL_LINE_SMOOTH 0x0B20 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_COLOR_MATERIAL 0x0B57 +#define GL_NORMALIZE 0x0BA1 +#define GL_RESCALE_NORMAL 0x803A +#define GL_POLYGON_OFFSET_FILL 0x8037 +#define GL_VERTEX_ARRAY 0x8074 +#define GL_NORMAL_ARRAY 0x8075 +#define GL_COLOR_ARRAY 0x8076 +#define GL_TEXTURE_COORD_ARRAY 0x8078 +#define GL_MULTISAMPLE 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE 0x809F +#define GL_SAMPLE_COVERAGE 0x80A0 + +/* ErrorCode */ +#define GL_NO_ERROR 0 +#define GL_INVALID_ENUM 0x0500 +#define GL_INVALID_VALUE 0x0501 +#define GL_INVALID_OPERATION 0x0502 +#define GL_STACK_OVERFLOW 0x0503 +#define GL_STACK_UNDERFLOW 0x0504 +#define GL_OUT_OF_MEMORY 0x0505 + +/* FogMode */ +/* GL_LINEAR */ +#define GL_EXP 0x0800 +#define GL_EXP2 0x0801 + +/* FogParameter */ +#define GL_FOG_DENSITY 0x0B62 +#define GL_FOG_START 0x0B63 +#define GL_FOG_END 0x0B64 +#define GL_FOG_MODE 0x0B65 +#define GL_FOG_COLOR 0x0B66 + +/* FrontFaceDirection */ +#define GL_CW 0x0900 +#define GL_CCW 0x0901 + +/* GetPName */ +#define GL_CURRENT_COLOR 0x0B00 +#define GL_CURRENT_NORMAL 0x0B02 +#define GL_CURRENT_TEXTURE_COORDS 0x0B03 +#define GL_POINT_SIZE 0x0B11 +#define GL_POINT_SIZE_MIN 0x8126 +#define GL_POINT_SIZE_MAX 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 +#define GL_POINT_DISTANCE_ATTENUATION 0x8129 +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_LINE_WIDTH 0x0B21 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_SHADE_MODEL 0x0B54 +#define GL_DEPTH_RANGE 0x0B70 +#define GL_DEPTH_WRITEMASK 0x0B72 +#define GL_DEPTH_CLEAR_VALUE 0x0B73 +#define GL_DEPTH_FUNC 0x0B74 +#define GL_STENCIL_CLEAR_VALUE 0x0B91 +#define GL_STENCIL_FUNC 0x0B92 +#define GL_STENCIL_VALUE_MASK 0x0B93 +#define GL_STENCIL_FAIL 0x0B94 +#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 +#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 +#define GL_STENCIL_REF 0x0B97 +#define GL_STENCIL_WRITEMASK 0x0B98 +#define GL_MATRIX_MODE 0x0BA0 +#define GL_VIEWPORT 0x0BA2 +#define GL_MODELVIEW_STACK_DEPTH 0x0BA3 +#define GL_PROJECTION_STACK_DEPTH 0x0BA4 +#define GL_TEXTURE_STACK_DEPTH 0x0BA5 +#define GL_MODELVIEW_MATRIX 0x0BA6 +#define GL_PROJECTION_MATRIX 0x0BA7 +#define GL_TEXTURE_MATRIX 0x0BA8 +#define GL_ALPHA_TEST_FUNC 0x0BC1 +#define GL_ALPHA_TEST_REF 0x0BC2 +#define GL_BLEND_DST 0x0BE0 +#define GL_BLEND_SRC 0x0BE1 +#define GL_LOGIC_OP_MODE 0x0BF0 +#define GL_SCISSOR_BOX 0x0C10 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_COLOR_CLEAR_VALUE 0x0C22 +#define GL_COLOR_WRITEMASK 0x0C23 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_MAX_LIGHTS 0x0D31 +#define GL_MAX_CLIP_PLANES 0x0D32 +#define GL_MAX_TEXTURE_SIZE 0x0D33 +#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36 +#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38 +#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39 +#define GL_MAX_VIEWPORT_DIMS 0x0D3A +#define GL_MAX_TEXTURE_UNITS 0x84E2 +#define GL_SUBPIXEL_BITS 0x0D50 +#define GL_RED_BITS 0x0D52 +#define GL_GREEN_BITS 0x0D53 +#define GL_BLUE_BITS 0x0D54 +#define GL_ALPHA_BITS 0x0D55 +#define GL_DEPTH_BITS 0x0D56 +#define GL_STENCIL_BITS 0x0D57 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +#define GL_POLYGON_OFFSET_FILL 0x8037 +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_TEXTURE_BINDING_2D 0x8069 +#define GL_VERTEX_ARRAY_SIZE 0x807A +#define GL_VERTEX_ARRAY_TYPE 0x807B +#define GL_VERTEX_ARRAY_STRIDE 0x807C +#define GL_NORMAL_ARRAY_TYPE 0x807E +#define GL_NORMAL_ARRAY_STRIDE 0x807F +#define GL_COLOR_ARRAY_SIZE 0x8081 +#define GL_COLOR_ARRAY_TYPE 0x8082 +#define GL_COLOR_ARRAY_STRIDE 0x8083 +#define GL_TEXTURE_COORD_ARRAY_SIZE 0x8088 +#define GL_TEXTURE_COORD_ARRAY_TYPE 0x8089 +#define GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A +#define GL_VERTEX_ARRAY_POINTER 0x808E +#define GL_NORMAL_ARRAY_POINTER 0x808F +#define GL_COLOR_ARRAY_POINTER 0x8090 +#define GL_TEXTURE_COORD_ARRAY_POINTER 0x8092 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB + +/* GetTextureParameter */ +/* GL_TEXTURE_MAG_FILTER */ +/* GL_TEXTURE_MIN_FILTER */ +/* GL_TEXTURE_WRAP_S */ +/* GL_TEXTURE_WRAP_T */ + +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 + +/* HintMode */ +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 + +/* HintTarget */ +#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50 +#define GL_POINT_SMOOTH_HINT 0x0C51 +#define GL_LINE_SMOOTH_HINT 0x0C52 +#define GL_FOG_HINT 0x0C54 +#define GL_GENERATE_MIPMAP_HINT 0x8192 + +/* LightModelParameter */ +#define GL_LIGHT_MODEL_AMBIENT 0x0B53 +#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52 + +/* LightParameter */ +#define GL_AMBIENT 0x1200 +#define GL_DIFFUSE 0x1201 +#define GL_SPECULAR 0x1202 +#define GL_POSITION 0x1203 +#define GL_SPOT_DIRECTION 0x1204 +#define GL_SPOT_EXPONENT 0x1205 +#define GL_SPOT_CUTOFF 0x1206 +#define GL_CONSTANT_ATTENUATION 0x1207 +#define GL_LINEAR_ATTENUATION 0x1208 +#define GL_QUADRATIC_ATTENUATION 0x1209 + +/* DataType */ +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_FLOAT 0x1406 +#define GL_FIXED 0x140C + +/* LogicOp */ +#define GL_CLEAR 0x1500 +#define GL_AND 0x1501 +#define GL_AND_REVERSE 0x1502 +#define GL_COPY 0x1503 +#define GL_AND_INVERTED 0x1504 +#define GL_NOOP 0x1505 +#define GL_XOR 0x1506 +#define GL_OR 0x1507 +#define GL_NOR 0x1508 +#define GL_EQUIV 0x1509 +#define GL_INVERT 0x150A +#define GL_OR_REVERSE 0x150B +#define GL_COPY_INVERTED 0x150C +#define GL_OR_INVERTED 0x150D +#define GL_NAND 0x150E +#define GL_SET 0x150F + +/* MaterialFace */ +/* GL_FRONT_AND_BACK */ + +/* MaterialParameter */ +#define GL_EMISSION 0x1600 +#define GL_SHININESS 0x1601 +#define GL_AMBIENT_AND_DIFFUSE 0x1602 +/* GL_AMBIENT */ +/* GL_DIFFUSE */ +/* GL_SPECULAR */ + +/* MatrixMode */ +#define GL_MODELVIEW 0x1700 +#define GL_PROJECTION 0x1701 +#define GL_TEXTURE 0x1702 + +/* NormalPointerType */ +/* GL_BYTE */ +/* GL_SHORT */ +/* GL_FLOAT */ +/* GL_FIXED */ + +/* PixelFormat */ +#define GL_ALPHA 0x1906 +#define GL_RGB 0x1907 +#define GL_RGBA 0x1908 +#define GL_LUMINANCE 0x1909 +#define GL_LUMINANCE_ALPHA 0x190A + +/* PixelStoreParameter */ +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_ALIGNMENT 0x0D05 + +/* PixelType */ +/* GL_UNSIGNED_BYTE */ +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 + +/* ShadingModel */ +#define GL_FLAT 0x1D00 +#define GL_SMOOTH 0x1D01 + +/* StencilFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* StencilOp */ +/* GL_ZERO */ +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 +/* GL_INVERT */ + +/* StringName */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 + +/* TexCoordPointerType */ +/* GL_SHORT */ +/* GL_FLOAT */ +/* GL_FIXED */ +/* GL_BYTE */ + +/* TextureEnvMode */ +#define GL_MODULATE 0x2100 +#define GL_DECAL 0x2101 +/* GL_BLEND */ +#define GL_ADD 0x0104 +/* GL_REPLACE */ + +/* TextureEnvParameter */ +#define GL_TEXTURE_ENV_MODE 0x2200 +#define GL_TEXTURE_ENV_COLOR 0x2201 + +/* TextureEnvTarget */ +#define GL_TEXTURE_ENV 0x2300 + +/* TextureMagFilter */ +#define GL_NEAREST 0x2600 +#define GL_LINEAR 0x2601 + +/* TextureMinFilter */ +/* GL_NEAREST */ +/* GL_LINEAR */ +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 + +/* TextureParameterName */ +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 +#define GL_GENERATE_MIPMAP 0x8191 + +/* TextureTarget */ +/* GL_TEXTURE_2D */ + +/* TextureUnit */ +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 + +/* TextureWrapMode */ +#define GL_REPEAT 0x2901 +#define GL_CLAMP_TO_EDGE 0x812F + +/* VertexPointerType */ +/* GL_SHORT */ +/* GL_FLOAT */ +/* GL_FIXED */ +/* GL_BYTE */ + +/* LightName */ +#define GL_LIGHT0 0x4000 +#define GL_LIGHT1 0x4001 +#define GL_LIGHT2 0x4002 +#define GL_LIGHT3 0x4003 +#define GL_LIGHT4 0x4004 +#define GL_LIGHT5 0x4005 +#define GL_LIGHT6 0x4006 +#define GL_LIGHT7 0x4007 + +/* Buffer Objects */ +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 + +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 +#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A + +#define GL_STATIC_DRAW 0x88E4 +#define GL_DYNAMIC_DRAW 0x88E8 + +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 + +/* Texture combine + dot3 */ +#define GL_SUBTRACT 0x84E7 +#define GL_COMBINE 0x8570 +#define GL_COMBINE_RGB 0x8571 +#define GL_COMBINE_ALPHA 0x8572 +#define GL_RGB_SCALE 0x8573 +#define GL_ADD_SIGNED 0x8574 +#define GL_INTERPOLATE 0x8575 +#define GL_CONSTANT 0x8576 +#define GL_PRIMARY_COLOR 0x8577 +#define GL_PREVIOUS 0x8578 +#define GL_OPERAND0_RGB 0x8590 +#define GL_OPERAND1_RGB 0x8591 +#define GL_OPERAND2_RGB 0x8592 +#define GL_OPERAND0_ALPHA 0x8598 +#define GL_OPERAND1_ALPHA 0x8599 +#define GL_OPERAND2_ALPHA 0x859A + +#define GL_ALPHA_SCALE 0x0D1C + +#define GL_SRC0_RGB 0x8580 +#define GL_SRC1_RGB 0x8581 +#define GL_SRC2_RGB 0x8582 +#define GL_SRC0_ALPHA 0x8588 +#define GL_SRC1_ALPHA 0x8589 +#define GL_SRC2_ALPHA 0x858A + +#define GL_DOT3_RGB 0x86AE +#define GL_DOT3_RGBA 0x86AF + +/*------------------------------------------------------------------------* + * required OES extension tokens + *------------------------------------------------------------------------*/ + +/* OES_read_format */ +#ifndef GL_OES_read_format +#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B +#endif + +/* GL_OES_compressed_paletted_texture */ +#ifndef GL_OES_compressed_paletted_texture +#define GL_PALETTE4_RGB8_OES 0x8B90 +#define GL_PALETTE4_RGBA8_OES 0x8B91 +#define GL_PALETTE4_R5_G6_B5_OES 0x8B92 +#define GL_PALETTE4_RGBA4_OES 0x8B93 +#define GL_PALETTE4_RGB5_A1_OES 0x8B94 +#define GL_PALETTE8_RGB8_OES 0x8B95 +#define GL_PALETTE8_RGBA8_OES 0x8B96 +#define GL_PALETTE8_R5_G6_B5_OES 0x8B97 +#define GL_PALETTE8_RGBA4_OES 0x8B98 +#define GL_PALETTE8_RGB5_A1_OES 0x8B99 +#endif + +/* OES_point_size_array */ +#ifndef GL_OES_point_size_array +#define GL_POINT_SIZE_ARRAY_OES 0x8B9C +#define GL_POINT_SIZE_ARRAY_TYPE_OES 0x898A +#define GL_POINT_SIZE_ARRAY_STRIDE_OES 0x898B +#define GL_POINT_SIZE_ARRAY_POINTER_OES 0x898C +#define GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES 0x8B9F +#endif + +/* GL_OES_point_sprite */ +#ifndef GL_OES_point_sprite +#define GL_POINT_SPRITE_OES 0x8861 +#define GL_COORD_REPLACE_OES 0x8862 +#endif + +/*************************************************************/ + +/* Available only in Common profile */ +GL_API void GL_APIENTRY glAlphaFunc (GLenum func, GLclampf ref); +GL_API void GL_APIENTRY glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +GL_API void GL_APIENTRY glClearDepthf (GLclampf depth); +GL_API void GL_APIENTRY glClipPlanef (GLenum plane, const GLfloat *equation); +GL_API void GL_APIENTRY glColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +GL_API void GL_APIENTRY glDepthRangef (GLclampf zNear, GLclampf zFar); +GL_API void GL_APIENTRY glFogf (GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glFogfv (GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glFrustumf (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +GL_API void GL_APIENTRY glGetClipPlanef (GLenum pname, GLfloat eqn[4]); +GL_API void GL_APIENTRY glGetFloatv (GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetLightfv (GLenum light, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetMaterialfv (GLenum face, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetTexEnvfv (GLenum env, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glLightModelf (GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glLightModelfv (GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glLightf (GLenum light, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glLightfv (GLenum light, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glLineWidth (GLfloat width); +GL_API void GL_APIENTRY glLoadMatrixf (const GLfloat *m); +GL_API void GL_APIENTRY glMaterialf (GLenum face, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glMaterialfv (GLenum face, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glMultMatrixf (const GLfloat *m); +GL_API void GL_APIENTRY glMultiTexCoord4f (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +GL_API void GL_APIENTRY glNormal3f (GLfloat nx, GLfloat ny, GLfloat nz); +GL_API void GL_APIENTRY glOrthof (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +GL_API void GL_APIENTRY glPointParameterf (GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glPointSize (GLfloat size); +GL_API void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units); +GL_API void GL_APIENTRY glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +GL_API void GL_APIENTRY glScalef (GLfloat x, GLfloat y, GLfloat z); +GL_API void GL_APIENTRY glTexEnvf (GLenum target, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glTexEnvfv (GLenum target, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glTranslatef (GLfloat x, GLfloat y, GLfloat z); + +/* Available in both Common and Common-Lite profiles */ +GL_API void GL_APIENTRY glActiveTexture (GLenum texture); +GL_API void GL_APIENTRY glAlphaFuncx (GLenum func, GLclampx ref); +GL_API void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer); +GL_API void GL_APIENTRY glBindTexture (GLenum target, GLuint texture); +GL_API void GL_APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor); +GL_API void GL_APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); +GL_API void GL_APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); +GL_API void GL_APIENTRY glClear (GLbitfield mask); +GL_API void GL_APIENTRY glClearColorx (GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha); +GL_API void GL_APIENTRY glClearDepthx (GLclampx depth); +GL_API void GL_APIENTRY glClearStencil (GLint s); +GL_API void GL_APIENTRY glClientActiveTexture (GLenum texture); +GL_API void GL_APIENTRY glClipPlanex (GLenum plane, const GLfixed *equation); +GL_API void GL_APIENTRY glColor4ub (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); +GL_API void GL_APIENTRY glColor4x (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +GL_API void GL_APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +GL_API void GL_APIENTRY glColorPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +GL_API void GL_APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +GL_API void GL_APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GL_API void GL_APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GL_API void GL_APIENTRY glCullFace (GLenum mode); +GL_API void GL_APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers); +GL_API void GL_APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures); +GL_API void GL_APIENTRY glDepthFunc (GLenum func); +GL_API void GL_APIENTRY glDepthMask (GLboolean flag); +GL_API void GL_APIENTRY glDepthRangex (GLclampx zNear, GLclampx zFar); +GL_API void GL_APIENTRY glDisable (GLenum cap); +GL_API void GL_APIENTRY glDisableClientState (GLenum array); +GL_API void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count); +GL_API void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); +GL_API void GL_APIENTRY glEnable (GLenum cap); +GL_API void GL_APIENTRY glEnableClientState (GLenum array); +GL_API void GL_APIENTRY glFinish (void); +GL_API void GL_APIENTRY glFlush (void); +GL_API void GL_APIENTRY glFogx (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glFogxv (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glFrontFace (GLenum mode); +GL_API void GL_APIENTRY glFrustumx (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +GL_API void GL_APIENTRY glGetBooleanv (GLenum pname, GLboolean *params); +GL_API void GL_APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetClipPlanex (GLenum pname, GLfixed eqn[4]); +GL_API void GL_APIENTRY glGenBuffers (GLsizei n, GLuint *buffers); +GL_API void GL_APIENTRY glGenTextures (GLsizei n, GLuint *textures); +GL_API GLenum GL_APIENTRY glGetError (void); +GL_API void GL_APIENTRY glGetFixedv (GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetIntegerv (GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetLightxv (GLenum light, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetMaterialxv (GLenum face, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetPointerv (GLenum pname, GLvoid **params); +GL_API const GLubyte * GL_APIENTRY glGetString (GLenum name); +GL_API void GL_APIENTRY glGetTexEnviv (GLenum env, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetTexEnvxv (GLenum env, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetTexParameterxv (GLenum target, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glHint (GLenum target, GLenum mode); +GL_API GLboolean GL_APIENTRY glIsBuffer (GLuint buffer); +GL_API GLboolean GL_APIENTRY glIsEnabled (GLenum cap); +GL_API GLboolean GL_APIENTRY glIsTexture (GLuint texture); +GL_API void GL_APIENTRY glLightModelx (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glLightModelxv (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glLightx (GLenum light, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glLightxv (GLenum light, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glLineWidthx (GLfixed width); +GL_API void GL_APIENTRY glLoadIdentity (void); +GL_API void GL_APIENTRY glLoadMatrixx (const GLfixed *m); +GL_API void GL_APIENTRY glLogicOp (GLenum opcode); +GL_API void GL_APIENTRY glMaterialx (GLenum face, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glMaterialxv (GLenum face, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glMatrixMode (GLenum mode); +GL_API void GL_APIENTRY glMultMatrixx (const GLfixed *m); +GL_API void GL_APIENTRY glMultiTexCoord4x (GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q); +GL_API void GL_APIENTRY glNormal3x (GLfixed nx, GLfixed ny, GLfixed nz); +GL_API void GL_APIENTRY glNormalPointer (GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glOrthox (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +GL_API void GL_APIENTRY glPixelStorei (GLenum pname, GLint param); +GL_API void GL_APIENTRY glPointParameterx (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glPointParameterxv (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glPointSizex (GLfixed size); +GL_API void GL_APIENTRY glPolygonOffsetx (GLfixed factor, GLfixed units); +GL_API void GL_APIENTRY glPopMatrix (void); +GL_API void GL_APIENTRY glPushMatrix (void); +GL_API void GL_APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); +GL_API void GL_APIENTRY glRotatex (GLfixed angle, GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glSampleCoverage (GLclampf value, GLboolean invert); +GL_API void GL_APIENTRY glSampleCoveragex (GLclampx value, GLboolean invert); +GL_API void GL_APIENTRY glScalex (GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); +GL_API void GL_APIENTRY glShadeModel (GLenum mode); +GL_API void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask); +GL_API void GL_APIENTRY glStencilMask (GLuint mask); +GL_API void GL_APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); +GL_API void GL_APIENTRY glTexCoordPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glTexEnvi (GLenum target, GLenum pname, GLint param); +GL_API void GL_APIENTRY glTexEnvx (GLenum target, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexEnviv (GLenum target, GLenum pname, const GLint *params); +GL_API void GL_APIENTRY glTexEnvxv (GLenum target, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GL_API void GL_APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); +GL_API void GL_APIENTRY glTexParameterx (GLenum target, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint *params); +GL_API void GL_APIENTRY glTexParameterxv (GLenum target, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +GL_API void GL_APIENTRY glTranslatex (GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glVertexPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); + +/*------------------------------------------------------------------------* + * Required OES extension functions + *------------------------------------------------------------------------*/ + +/* GL_OES_read_format */ +#ifndef GL_OES_read_format +#define GL_OES_read_format 1 +#endif + +/* GL_OES_compressed_paletted_texture */ +#ifndef GL_OES_compressed_paletted_texture +#define GL_OES_compressed_paletted_texture 1 +#endif + +/* GL_OES_point_size_array */ +#ifndef GL_OES_point_size_array +#define GL_OES_point_size_array 1 +GL_API void GL_APIENTRY glPointSizePointerOES (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +/* GL_OES_point_sprite */ +#ifndef GL_OES_point_sprite +#define GL_OES_point_sprite 1 +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __gl_h_ */ + diff --git a/include/GLES/glext.h b/include/GLES/glext.h new file mode 100644 index 0000000..162909a --- /dev/null +++ b/include/GLES/glext.h @@ -0,0 +1,1001 @@ +#ifndef __glext_h_ +#define __glext_h_ + +/* $Revision: 10965 $ on $Date:: 2010-04-09 02:11:29 -0700 #$ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +#ifndef GL_APIENTRYP +# define GL_APIENTRYP GL_APIENTRY* +#endif + +/*------------------------------------------------------------------------* + * OES extension tokens + *------------------------------------------------------------------------*/ + +/* GL_OES_blend_equation_separate */ +#ifndef GL_OES_blend_equation_separate +/* BLEND_EQUATION_RGB_OES same as BLEND_EQUATION_OES */ +#define GL_BLEND_EQUATION_RGB_OES 0x8009 +#define GL_BLEND_EQUATION_ALPHA_OES 0x883D +#endif + +/* GL_OES_blend_func_separate */ +#ifndef GL_OES_blend_func_separate +#define GL_BLEND_DST_RGB_OES 0x80C8 +#define GL_BLEND_SRC_RGB_OES 0x80C9 +#define GL_BLEND_DST_ALPHA_OES 0x80CA +#define GL_BLEND_SRC_ALPHA_OES 0x80CB +#endif + +/* GL_OES_blend_subtract */ +#ifndef GL_OES_blend_subtract +#define GL_BLEND_EQUATION_OES 0x8009 +#define GL_FUNC_ADD_OES 0x8006 +#define GL_FUNC_SUBTRACT_OES 0x800A +#define GL_FUNC_REVERSE_SUBTRACT_OES 0x800B +#endif + +/* GL_OES_compressed_ETC1_RGB8_texture */ +#ifndef GL_OES_compressed_ETC1_RGB8_texture +#define GL_ETC1_RGB8_OES 0x8D64 +#endif + +/* GL_OES_depth24 */ +#ifndef GL_OES_depth24 +#define GL_DEPTH_COMPONENT24_OES 0x81A6 +#endif + +/* GL_OES_depth32 */ +#ifndef GL_OES_depth32 +#define GL_DEPTH_COMPONENT32_OES 0x81A7 +#endif + +/* GL_OES_draw_texture */ +#ifndef GL_OES_draw_texture +#define GL_TEXTURE_CROP_RECT_OES 0x8B9D +#endif + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +typedef void* GLeglImageOES; +#endif + +/* GL_OES_element_index_uint */ +#ifndef GL_OES_element_index_uint +#define GL_UNSIGNED_INT 0x1405 +#endif + +/* GL_OES_fixed_point */ +#ifndef GL_OES_fixed_point +#define GL_FIXED_OES 0x140C +#endif + +/* GL_OES_framebuffer_object */ +#ifndef GL_OES_framebuffer_object +#define GL_NONE_OES 0 +#define GL_FRAMEBUFFER_OES 0x8D40 +#define GL_RENDERBUFFER_OES 0x8D41 +#define GL_RGBA4_OES 0x8056 +#define GL_RGB5_A1_OES 0x8057 +#define GL_RGB565_OES 0x8D62 +#define GL_DEPTH_COMPONENT16_OES 0x81A5 +#define GL_RENDERBUFFER_WIDTH_OES 0x8D42 +#define GL_RENDERBUFFER_HEIGHT_OES 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT_OES 0x8D44 +#define GL_RENDERBUFFER_RED_SIZE_OES 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE_OES 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE_OES 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE_OES 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE_OES 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE_OES 0x8D55 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_OES 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_OES 0x8CD3 +#define GL_COLOR_ATTACHMENT0_OES 0x8CE0 +#define GL_DEPTH_ATTACHMENT_OES 0x8D00 +#define GL_STENCIL_ATTACHMENT_OES 0x8D20 +#define GL_FRAMEBUFFER_COMPLETE_OES 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES 0x8CD9 +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES 0x8CDA +#define GL_FRAMEBUFFER_UNSUPPORTED_OES 0x8CDD +#define GL_FRAMEBUFFER_BINDING_OES 0x8CA6 +#define GL_RENDERBUFFER_BINDING_OES 0x8CA7 +#define GL_MAX_RENDERBUFFER_SIZE_OES 0x84E8 +#define GL_INVALID_FRAMEBUFFER_OPERATION_OES 0x0506 +#endif + +/* GL_OES_mapbuffer */ +#ifndef GL_OES_mapbuffer +#define GL_WRITE_ONLY_OES 0x88B9 +#define GL_BUFFER_ACCESS_OES 0x88BB +#define GL_BUFFER_MAPPED_OES 0x88BC +#define GL_BUFFER_MAP_POINTER_OES 0x88BD +#endif + +/* GL_OES_matrix_get */ +#ifndef GL_OES_matrix_get +#define GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES 0x898D +#define GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES 0x898E +#define GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES 0x898F +#endif + +/* GL_OES_matrix_palette */ +#ifndef GL_OES_matrix_palette +#define GL_MAX_VERTEX_UNITS_OES 0x86A4 +#define GL_MAX_PALETTE_MATRICES_OES 0x8842 +#define GL_MATRIX_PALETTE_OES 0x8840 +#define GL_MATRIX_INDEX_ARRAY_OES 0x8844 +#define GL_WEIGHT_ARRAY_OES 0x86AD +#define GL_CURRENT_PALETTE_MATRIX_OES 0x8843 +#define GL_MATRIX_INDEX_ARRAY_SIZE_OES 0x8846 +#define GL_MATRIX_INDEX_ARRAY_TYPE_OES 0x8847 +#define GL_MATRIX_INDEX_ARRAY_STRIDE_OES 0x8848 +#define GL_MATRIX_INDEX_ARRAY_POINTER_OES 0x8849 +#define GL_MATRIX_INDEX_ARRAY_BUFFER_BINDING_OES 0x8B9E +#define GL_WEIGHT_ARRAY_SIZE_OES 0x86AB +#define GL_WEIGHT_ARRAY_TYPE_OES 0x86A9 +#define GL_WEIGHT_ARRAY_STRIDE_OES 0x86AA +#define GL_WEIGHT_ARRAY_POINTER_OES 0x86AC +#define GL_WEIGHT_ARRAY_BUFFER_BINDING_OES 0x889E +#endif + +/* GL_OES_packed_depth_stencil */ +#ifndef GL_OES_packed_depth_stencil +#define GL_DEPTH_STENCIL_OES 0x84F9 +#define GL_UNSIGNED_INT_24_8_OES 0x84FA +#define GL_DEPTH24_STENCIL8_OES 0x88F0 +#endif + +/* GL_OES_rgb8_rgba8 */ +#ifndef GL_OES_rgb8_rgba8 +#define GL_RGB8_OES 0x8051 +#define GL_RGBA8_OES 0x8058 +#endif + +/* GL_OES_stencil1 */ +#ifndef GL_OES_stencil1 +#define GL_STENCIL_INDEX1_OES 0x8D46 +#endif + +/* GL_OES_stencil4 */ +#ifndef GL_OES_stencil4 +#define GL_STENCIL_INDEX4_OES 0x8D47 +#endif + +/* GL_OES_stencil8 */ +#ifndef GL_OES_stencil8 +#define GL_STENCIL_INDEX8_OES 0x8D48 +#endif + +/* GL_OES_stencil_wrap */ +#ifndef GL_OES_stencil_wrap +#define GL_INCR_WRAP_OES 0x8507 +#define GL_DECR_WRAP_OES 0x8508 +#endif + +/* GL_OES_texture_cube_map */ +#ifndef GL_OES_texture_cube_map +#define GL_NORMAL_MAP_OES 0x8511 +#define GL_REFLECTION_MAP_OES 0x8512 +#define GL_TEXTURE_CUBE_MAP_OES 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_OES 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_OES 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_OES 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_OES 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_OES 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_OES 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_OES 0x851A +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_OES 0x851C +#define GL_TEXTURE_GEN_MODE_OES 0x2500 +#define GL_TEXTURE_GEN_STR_OES 0x8D60 +#endif + +/* GL_OES_texture_mirrored_repeat */ +#ifndef GL_OES_texture_mirrored_repeat +#define GL_MIRRORED_REPEAT_OES 0x8370 +#endif + +/* GL_OES_vertex_array_object */ +#ifndef GL_OES_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING_OES 0x85B5 +#endif + +/*------------------------------------------------------------------------* + * AMD extension tokens + *------------------------------------------------------------------------*/ + +/* GL_AMD_compressed_3DC_texture */ +#ifndef GL_AMD_compressed_3DC_texture +#define GL_3DC_X_AMD 0x87F9 +#define GL_3DC_XY_AMD 0x87FA +#endif + +/* GL_AMD_compressed_ATC_texture */ +#ifndef GL_AMD_compressed_ATC_texture +#define GL_ATC_RGB_AMD 0x8C92 +#define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93 +#define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE +#endif + +/*------------------------------------------------------------------------* + * APPLE extension tokens + *------------------------------------------------------------------------*/ + +/* GL_APPLE_texture_2D_limited_npot */ +/* No new tokens introduced by this extension. */ + +/*------------------------------------------------------------------------* + * EXT extension tokens + *------------------------------------------------------------------------*/ + +/* GL_EXT_blend_minmax */ +#ifndef GL_EXT_blend_minmax +#define GL_MIN_EXT 0x8007 +#define GL_MAX_EXT 0x8008 +#endif + +/* GL_EXT_discard_framebuffer */ +#ifndef GL_EXT_discard_framebuffer +#define GL_COLOR_EXT 0x1800 +#define GL_DEPTH_EXT 0x1801 +#define GL_STENCIL_EXT 0x1802 +#endif + +/* GL_EXT_multi_draw_arrays */ +/* No new tokens introduced by this extension. */ + +/* GL_EXT_read_format_bgra */ +#ifndef GL_EXT_read_format_bgra +#define GL_BGRA_EXT 0x80E1 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT 0x8366 +#endif + +/* GL_EXT_texture_filter_anisotropic */ +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF +#endif + +/* GL_EXT_texture_format_BGRA8888 */ +#ifndef GL_EXT_texture_format_BGRA8888 +#define GL_BGRA_EXT 0x80E1 +#endif + +/* GL_EXT_texture_lod_bias */ +#ifndef GL_EXT_texture_lod_bias +#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD +#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500 +#define GL_TEXTURE_LOD_BIAS_EXT 0x8501 +#endif + +/*------------------------------------------------------------------------* + * IMG extension tokens + *------------------------------------------------------------------------*/ + +/* GL_IMG_read_format */ +#ifndef GL_IMG_read_format +#define GL_BGRA_IMG 0x80E1 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV_IMG 0x8365 +#endif + +/* GL_IMG_texture_compression_pvrtc */ +#ifndef GL_IMG_texture_compression_pvrtc +#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 +#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 +#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 +#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 +#endif + +/* GL_IMG_texture_env_enhanced_fixed_function */ +#ifndef GL_IMG_texture_env_enhanced_fixed_function +#define GL_MODULATE_COLOR_IMG 0x8C04 +#define GL_RECIP_ADD_SIGNED_ALPHA_IMG 0x8C05 +#define GL_TEXTURE_ALPHA_MODULATE_IMG 0x8C06 +#define GL_FACTOR_ALPHA_MODULATE_IMG 0x8C07 +#define GL_FRAGMENT_ALPHA_MODULATE_IMG 0x8C08 +#define GL_ADD_BLEND_IMG 0x8C09 +#define GL_DOT3_RGBA_IMG 0x86AF +#endif + +/* GL_IMG_user_clip_plane */ +#ifndef GL_IMG_user_clip_plane +#define GL_CLIP_PLANE0_IMG 0x3000 +#define GL_CLIP_PLANE1_IMG 0x3001 +#define GL_CLIP_PLANE2_IMG 0x3002 +#define GL_CLIP_PLANE3_IMG 0x3003 +#define GL_CLIP_PLANE4_IMG 0x3004 +#define GL_CLIP_PLANE5_IMG 0x3005 +#define GL_MAX_CLIP_PLANES_IMG 0x0D32 +#endif + +/* GL_IMG_multisampled_render_to_texture */ +#ifndef GL_IMG_multisampled_render_to_texture +#define GL_RENDERBUFFER_SAMPLES_IMG 0x9133 +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_IMG 0x9134 +#define GL_MAX_SAMPLES_IMG 0x9135 +#define GL_TEXTURE_SAMPLES_IMG 0x9136 +#endif + +/*------------------------------------------------------------------------* + * NV extension tokens + *------------------------------------------------------------------------*/ + +/* GL_NV_fence */ +#ifndef GL_NV_fence +#define GL_ALL_COMPLETED_NV 0x84F2 +#define GL_FENCE_STATUS_NV 0x84F3 +#define GL_FENCE_CONDITION_NV 0x84F4 +#endif + +/*------------------------------------------------------------------------* + * QCOM extension tokens + *------------------------------------------------------------------------*/ + +/* GL_QCOM_driver_control */ +/* No new tokens introduced by this extension. */ + +/* GL_QCOM_extended_get */ +#ifndef GL_QCOM_extended_get +#define GL_TEXTURE_WIDTH_QCOM 0x8BD2 +#define GL_TEXTURE_HEIGHT_QCOM 0x8BD3 +#define GL_TEXTURE_DEPTH_QCOM 0x8BD4 +#define GL_TEXTURE_INTERNAL_FORMAT_QCOM 0x8BD5 +#define GL_TEXTURE_FORMAT_QCOM 0x8BD6 +#define GL_TEXTURE_TYPE_QCOM 0x8BD7 +#define GL_TEXTURE_IMAGE_VALID_QCOM 0x8BD8 +#define GL_TEXTURE_NUM_LEVELS_QCOM 0x8BD9 +#define GL_TEXTURE_TARGET_QCOM 0x8BDA +#define GL_TEXTURE_OBJECT_VALID_QCOM 0x8BDB +#define GL_STATE_RESTORE 0x8BDC +#endif + +/* GL_QCOM_extended_get2 */ +/* No new tokens introduced by this extension. */ + +/* GL_QCOM_perfmon_global_mode */ +#ifndef GL_QCOM_perfmon_global_mode +#define GL_PERFMON_GLOBAL_MODE_QCOM 0x8FA0 +#endif + +/* GL_QCOM_writeonly_rendering */ +#ifndef GL_QCOM_writeonly_rendering +#define GL_WRITEONLY_RENDERING_QCOM 0x8823 +#endif + +/* GL_QCOM_tiled_rendering */ +#ifndef GL_QCOM_tiled_rendering +#define GL_COLOR_BUFFER_BIT0_QCOM 0x00000001 +#define GL_COLOR_BUFFER_BIT1_QCOM 0x00000002 +#define GL_COLOR_BUFFER_BIT2_QCOM 0x00000004 +#define GL_COLOR_BUFFER_BIT3_QCOM 0x00000008 +#define GL_COLOR_BUFFER_BIT4_QCOM 0x00000010 +#define GL_COLOR_BUFFER_BIT5_QCOM 0x00000020 +#define GL_COLOR_BUFFER_BIT6_QCOM 0x00000040 +#define GL_COLOR_BUFFER_BIT7_QCOM 0x00000080 +#define GL_DEPTH_BUFFER_BIT0_QCOM 0x00000100 +#define GL_DEPTH_BUFFER_BIT1_QCOM 0x00000200 +#define GL_DEPTH_BUFFER_BIT2_QCOM 0x00000400 +#define GL_DEPTH_BUFFER_BIT3_QCOM 0x00000800 +#define GL_DEPTH_BUFFER_BIT4_QCOM 0x00001000 +#define GL_DEPTH_BUFFER_BIT5_QCOM 0x00002000 +#define GL_DEPTH_BUFFER_BIT6_QCOM 0x00004000 +#define GL_DEPTH_BUFFER_BIT7_QCOM 0x00008000 +#define GL_STENCIL_BUFFER_BIT0_QCOM 0x00010000 +#define GL_STENCIL_BUFFER_BIT1_QCOM 0x00020000 +#define GL_STENCIL_BUFFER_BIT2_QCOM 0x00040000 +#define GL_STENCIL_BUFFER_BIT3_QCOM 0x00080000 +#define GL_STENCIL_BUFFER_BIT4_QCOM 0x00100000 +#define GL_STENCIL_BUFFER_BIT5_QCOM 0x00200000 +#define GL_STENCIL_BUFFER_BIT6_QCOM 0x00400000 +#define GL_STENCIL_BUFFER_BIT7_QCOM 0x00800000 +#define GL_MULTISAMPLE_BUFFER_BIT0_QCOM 0x01000000 +#define GL_MULTISAMPLE_BUFFER_BIT1_QCOM 0x02000000 +#define GL_MULTISAMPLE_BUFFER_BIT2_QCOM 0x04000000 +#define GL_MULTISAMPLE_BUFFER_BIT3_QCOM 0x08000000 +#define GL_MULTISAMPLE_BUFFER_BIT4_QCOM 0x10000000 +#define GL_MULTISAMPLE_BUFFER_BIT5_QCOM 0x20000000 +#define GL_MULTISAMPLE_BUFFER_BIT6_QCOM 0x40000000 +#define GL_MULTISAMPLE_BUFFER_BIT7_QCOM 0x80000000 +#endif + +/*------------------------------------------------------------------------* + * End of extension tokens, start of corresponding extension functions + *------------------------------------------------------------------------*/ + +/*------------------------------------------------------------------------* + * OES extension functions + *------------------------------------------------------------------------*/ + +/* GL_OES_blend_equation_separate */ +#ifndef GL_OES_blend_equation_separate +#define GL_OES_blend_equation_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glBlendEquationSeparateOES (GLenum modeRGB, GLenum modeAlpha); +#endif +typedef void (GL_APIENTRYP PFNGLBLENDEQUATIONSEPARATEOESPROC) (GLenum modeRGB, GLenum modeAlpha); +#endif + +/* GL_OES_blend_func_separate */ +#ifndef GL_OES_blend_func_separate +#define GL_OES_blend_func_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glBlendFuncSeparateOES (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif +typedef void (GL_APIENTRYP PFNGLBLENDFUNCSEPARATEOESPROC) (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif + +/* GL_OES_blend_subtract */ +#ifndef GL_OES_blend_subtract +#define GL_OES_blend_subtract 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glBlendEquationOES (GLenum mode); +#endif +typedef void (GL_APIENTRYP PFNGLBLENDEQUATIONOESPROC) (GLenum mode); +#endif + +/* GL_OES_byte_coordinates */ +#ifndef GL_OES_byte_coordinates +#define GL_OES_byte_coordinates 1 +#endif + +/* GL_OES_compressed_ETC1_RGB8_texture */ +#ifndef GL_OES_compressed_ETC1_RGB8_texture +#define GL_OES_compressed_ETC1_RGB8_texture 1 +#endif + +/* GL_OES_depth24 */ +#ifndef GL_OES_depth24 +#define GL_OES_depth24 1 +#endif + +/* GL_OES_depth32 */ +#ifndef GL_OES_depth32 +#define GL_OES_depth32 1 +#endif + +/* GL_OES_draw_texture */ +#ifndef GL_OES_draw_texture +#define GL_OES_draw_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glDrawTexsOES (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height); +GL_API void GL_APIENTRY glDrawTexiOES (GLint x, GLint y, GLint z, GLint width, GLint height); +GL_API void GL_APIENTRY glDrawTexxOES (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height); +GL_API void GL_APIENTRY glDrawTexsvOES (const GLshort *coords); +GL_API void GL_APIENTRY glDrawTexivOES (const GLint *coords); +GL_API void GL_APIENTRY glDrawTexxvOES (const GLfixed *coords); +GL_API void GL_APIENTRY glDrawTexfOES (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height); +GL_API void GL_APIENTRY glDrawTexfvOES (const GLfloat *coords); +#endif +typedef void (GL_APIENTRYP PFNGLDRAWTEXSOESPROC) (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height); +typedef void (GL_APIENTRYP PFNGLDRAWTEXIOESPROC) (GLint x, GLint y, GLint z, GLint width, GLint height); +typedef void (GL_APIENTRYP PFNGLDRAWTEXXOESPROC) (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height); +typedef void (GL_APIENTRYP PFNGLDRAWTEXSVOESPROC) (const GLshort *coords); +typedef void (GL_APIENTRYP PFNGLDRAWTEXIVOESPROC) (const GLint *coords); +typedef void (GL_APIENTRYP PFNGLDRAWTEXXVOESPROC) (const GLfixed *coords); +typedef void (GL_APIENTRYP PFNGLDRAWTEXFOESPROC) (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height); +typedef void (GL_APIENTRYP PFNGLDRAWTEXFVOESPROC) (const GLfloat *coords); +#endif + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +#define GL_OES_EGL_image 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image); +GL_API void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image); +#endif +typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); +typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image); +#endif + +/* GL_OES_element_index_uint */ +#ifndef GL_OES_element_index_uint +#define GL_OES_element_index_uint 1 +#endif + +/* GL_OES_extended_matrix_palette */ +#ifndef GL_OES_extended_matrix_palette +#define GL_OES_extended_matrix_palette 1 +#endif + +/* GL_OES_fbo_render_mipmap */ +#ifndef GL_OES_fbo_render_mipmap +#define GL_OES_fbo_render_mipmap 1 +#endif + +/* GL_OES_fixed_point */ +#ifndef GL_OES_fixed_point +#define GL_OES_fixed_point 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glAlphaFuncxOES (GLenum func, GLclampx ref); +GL_API void GL_APIENTRY glClearColorxOES (GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha); +GL_API void GL_APIENTRY glClearDepthxOES (GLclampx depth); +GL_API void GL_APIENTRY glClipPlanexOES (GLenum plane, const GLfixed *equation); +GL_API void GL_APIENTRY glColor4xOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +GL_API void GL_APIENTRY glDepthRangexOES (GLclampx zNear, GLclampx zFar); +GL_API void GL_APIENTRY glFogxOES (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glFogxvOES (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glFrustumxOES (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +GL_API void GL_APIENTRY glGetClipPlanexOES (GLenum pname, GLfixed eqn[4]); +GL_API void GL_APIENTRY glGetFixedvOES (GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetLightxvOES (GLenum light, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetMaterialxvOES (GLenum face, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetTexEnvxvOES (GLenum env, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetTexParameterxvOES (GLenum target, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glLightModelxOES (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glLightModelxvOES (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glLightxOES (GLenum light, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glLightxvOES (GLenum light, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glLineWidthxOES (GLfixed width); +GL_API void GL_APIENTRY glLoadMatrixxOES (const GLfixed *m); +GL_API void GL_APIENTRY glMaterialxOES (GLenum face, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glMaterialxvOES (GLenum face, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glMultMatrixxOES (const GLfixed *m); +GL_API void GL_APIENTRY glMultiTexCoord4xOES (GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q); +GL_API void GL_APIENTRY glNormal3xOES (GLfixed nx, GLfixed ny, GLfixed nz); +GL_API void GL_APIENTRY glOrthoxOES (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +GL_API void GL_APIENTRY glPointParameterxOES (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glPointParameterxvOES (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glPointSizexOES (GLfixed size); +GL_API void GL_APIENTRY glPolygonOffsetxOES (GLfixed factor, GLfixed units); +GL_API void GL_APIENTRY glRotatexOES (GLfixed angle, GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glSampleCoveragexOES (GLclampx value, GLboolean invert); +GL_API void GL_APIENTRY glScalexOES (GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glTexEnvxOES (GLenum target, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexEnvxvOES (GLenum target, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glTexParameterxOES (GLenum target, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexParameterxvOES (GLenum target, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glTranslatexOES (GLfixed x, GLfixed y, GLfixed z); +#endif +typedef void (GL_APIENTRYP PFNGLALPHAFUNCXOESPROC) (GLenum func, GLclampx ref); +typedef void (GL_APIENTRYP PFNGLCLEARCOLORXOESPROC) (GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha); +typedef void (GL_APIENTRYP PFNGLCLEARDEPTHXOESPROC) (GLclampx depth); +typedef void (GL_APIENTRYP PFNGLCLIPPLANEXOESPROC) (GLenum plane, const GLfixed *equation); +typedef void (GL_APIENTRYP PFNGLCOLOR4XOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +typedef void (GL_APIENTRYP PFNGLDEPTHRANGEXOESPROC) (GLclampx zNear, GLclampx zFar); +typedef void (GL_APIENTRYP PFNGLFOGXOESPROC) (GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLFOGXVOESPROC) (GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLFRUSTUMXOESPROC) (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +typedef void (GL_APIENTRYP PFNGLGETCLIPPLANEXOESPROC) (GLenum pname, GLfixed eqn[4]); +typedef void (GL_APIENTRYP PFNGLGETFIXEDVOESPROC) (GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETLIGHTXVOESPROC) (GLenum light, GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETMATERIALXVOESPROC) (GLenum face, GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETTEXENVXVOESPROC) (GLenum env, GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETTEXPARAMETERXVOESPROC) (GLenum target, GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLLIGHTMODELXOESPROC) (GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLLIGHTMODELXVOESPROC) (GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLLIGHTXOESPROC) (GLenum light, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLLIGHTXVOESPROC) (GLenum light, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLLINEWIDTHXOESPROC) (GLfixed width); +typedef void (GL_APIENTRYP PFNGLLOADMATRIXXOESPROC) (const GLfixed *m); +typedef void (GL_APIENTRYP PFNGLMATERIALXOESPROC) (GLenum face, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLMATERIALXVOESPROC) (GLenum face, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLMULTMATRIXXOESPROC) (const GLfixed *m); +typedef void (GL_APIENTRYP PFNGLMULTITEXCOORD4XOESPROC) (GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q); +typedef void (GL_APIENTRYP PFNGLNORMAL3XOESPROC) (GLfixed nx, GLfixed ny, GLfixed nz); +typedef void (GL_APIENTRYP PFNGLORTHOXOESPROC) (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +typedef void (GL_APIENTRYP PFNGLPOINTPARAMETERXOESPROC) (GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLPOINTPARAMETERXVOESPROC) (GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLPOINTSIZEXOESPROC) (GLfixed size); +typedef void (GL_APIENTRYP PFNGLPOLYGONOFFSETXOESPROC) (GLfixed factor, GLfixed units); +typedef void (GL_APIENTRYP PFNGLROTATEXOESPROC) (GLfixed angle, GLfixed x, GLfixed y, GLfixed z); +typedef void (GL_APIENTRYP PFNGLSAMPLECOVERAGEXOESPROC) (GLclampx value, GLboolean invert); +typedef void (GL_APIENTRYP PFNGLSCALEXOESPROC) (GLfixed x, GLfixed y, GLfixed z); +typedef void (GL_APIENTRYP PFNGLTEXENVXOESPROC) (GLenum target, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLTEXENVXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLTEXPARAMETERXOESPROC) (GLenum target, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLTEXPARAMETERXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLTRANSLATEXOESPROC) (GLfixed x, GLfixed y, GLfixed z); +#endif + +/* GL_OES_framebuffer_object */ +#ifndef GL_OES_framebuffer_object +#define GL_OES_framebuffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API GLboolean GL_APIENTRY glIsRenderbufferOES (GLuint renderbuffer); +GL_API void GL_APIENTRY glBindRenderbufferOES (GLenum target, GLuint renderbuffer); +GL_API void GL_APIENTRY glDeleteRenderbuffersOES (GLsizei n, const GLuint* renderbuffers); +GL_API void GL_APIENTRY glGenRenderbuffersOES (GLsizei n, GLuint* renderbuffers); +GL_API void GL_APIENTRY glRenderbufferStorageOES (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GL_API void GL_APIENTRY glGetRenderbufferParameterivOES (GLenum target, GLenum pname, GLint* params); +GL_API GLboolean GL_APIENTRY glIsFramebufferOES (GLuint framebuffer); +GL_API void GL_APIENTRY glBindFramebufferOES (GLenum target, GLuint framebuffer); +GL_API void GL_APIENTRY glDeleteFramebuffersOES (GLsizei n, const GLuint* framebuffers); +GL_API void GL_APIENTRY glGenFramebuffersOES (GLsizei n, GLuint* framebuffers); +GL_API GLenum GL_APIENTRY glCheckFramebufferStatusOES (GLenum target); +GL_API void GL_APIENTRY glFramebufferRenderbufferOES (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GL_API void GL_APIENTRY glFramebufferTexture2DOES (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GL_API void GL_APIENTRY glGetFramebufferAttachmentParameterivOES (GLenum target, GLenum attachment, GLenum pname, GLint* params); +GL_API void GL_APIENTRY glGenerateMipmapOES (GLenum target); +#endif +typedef GLboolean (GL_APIENTRYP PFNGLISRENDERBUFFEROESPROC) (GLuint renderbuffer); +typedef void (GL_APIENTRYP PFNGLBINDRENDERBUFFEROESPROC) (GLenum target, GLuint renderbuffer); +typedef void (GL_APIENTRYP PFNGLDELETERENDERBUFFERSOESPROC) (GLsizei n, const GLuint* renderbuffers); +typedef void (GL_APIENTRYP PFNGLGENRENDERBUFFERSOESPROC) (GLsizei n, GLuint* renderbuffers); +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVOESPROC) (GLenum target, GLenum pname, GLint* params); +typedef GLboolean (GL_APIENTRYP PFNGLISFRAMEBUFFEROESPROC) (GLuint framebuffer); +typedef void (GL_APIENTRYP PFNGLBINDFRAMEBUFFEROESPROC) (GLenum target, GLuint framebuffer); +typedef void (GL_APIENTRYP PFNGLDELETEFRAMEBUFFERSOESPROC) (GLsizei n, const GLuint* framebuffers); +typedef void (GL_APIENTRYP PFNGLGENFRAMEBUFFERSOESPROC) (GLsizei n, GLuint* framebuffers); +typedef GLenum (GL_APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSOESPROC) (GLenum target); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEROESPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DOESPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (GL_APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVOESPROC) (GLenum target, GLenum attachment, GLenum pname, GLint* params); +typedef void (GL_APIENTRYP PFNGLGENERATEMIPMAPOESPROC) (GLenum target); +#endif + +/* GL_OES_mapbuffer */ +#ifndef GL_OES_mapbuffer +#define GL_OES_mapbuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void* GL_APIENTRY glMapBufferOES (GLenum target, GLenum access); +GL_API GLboolean GL_APIENTRY glUnmapBufferOES (GLenum target); +GL_API void GL_APIENTRY glGetBufferPointervOES (GLenum target, GLenum pname, GLvoid ** params); +#endif +typedef void* (GL_APIENTRYP PFNGLMAPBUFFEROESPROC) (GLenum target, GLenum access); +typedef GLboolean (GL_APIENTRYP PFNGLUNMAPBUFFEROESPROC) (GLenum target); +typedef void (GL_APIENTRYP PFNGLGETBUFFERPOINTERVOESPROC) (GLenum target, GLenum pname, GLvoid ** params); +#endif + +/* GL_OES_matrix_get */ +#ifndef GL_OES_matrix_get +#define GL_OES_matrix_get 1 +#endif + +/* GL_OES_matrix_palette */ +#ifndef GL_OES_matrix_palette +#define GL_OES_matrix_palette 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glCurrentPaletteMatrixOES (GLuint matrixpaletteindex); +GL_API void GL_APIENTRY glLoadPaletteFromModelViewMatrixOES (void); +GL_API void GL_APIENTRY glMatrixIndexPointerOES (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glWeightPointerOES (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif +typedef void (GL_APIENTRYP PFNGLCURRENTPALETTEMATRIXOESPROC) (GLuint matrixpaletteindex); +typedef void (GL_APIENTRYP PFNGLLOADPALETTEFROMMODELVIEWMATRIXOESPROC) (void); +typedef void (GL_APIENTRYP PFNGLMATRIXINDEXPOINTEROESPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (GL_APIENTRYP PFNGLWEIGHTPOINTEROESPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +/* GL_OES_packed_depth_stencil */ +#ifndef GL_OES_packed_depth_stencil +#define GL_OES_packed_depth_stencil 1 +#endif + +/* GL_OES_query_matrix */ +#ifndef GL_OES_query_matrix +#define GL_OES_query_matrix 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API GLbitfield GL_APIENTRY glQueryMatrixxOES (GLfixed mantissa[16], GLint exponent[16]); +#endif +typedef GLbitfield (GL_APIENTRYP PFNGLQUERYMATRIXXOESPROC) (GLfixed mantissa[16], GLint exponent[16]); +#endif + +/* GL_OES_rgb8_rgba8 */ +#ifndef GL_OES_rgb8_rgba8 +#define GL_OES_rgb8_rgba8 1 +#endif + +/* GL_OES_single_precision */ +#ifndef GL_OES_single_precision +#define GL_OES_single_precision 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glDepthRangefOES (GLclampf zNear, GLclampf zFar); +GL_API void GL_APIENTRY glFrustumfOES (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +GL_API void GL_APIENTRY glOrthofOES (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +GL_API void GL_APIENTRY glClipPlanefOES (GLenum plane, const GLfloat *equation); +GL_API void GL_APIENTRY glGetClipPlanefOES (GLenum pname, GLfloat eqn[4]); +GL_API void GL_APIENTRY glClearDepthfOES (GLclampf depth); +#endif +typedef void (GL_APIENTRYP PFNGLDEPTHRANGEFOESPROC) (GLclampf zNear, GLclampf zFar); +typedef void (GL_APIENTRYP PFNGLFRUSTUMFOESPROC) (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +typedef void (GL_APIENTRYP PFNGLORTHOFOESPROC) (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +typedef void (GL_APIENTRYP PFNGLCLIPPLANEFOESPROC) (GLenum plane, const GLfloat *equation); +typedef void (GL_APIENTRYP PFNGLGETCLIPPLANEFOESPROC) (GLenum pname, GLfloat eqn[4]); +typedef void (GL_APIENTRYP PFNGLCLEARDEPTHFOESPROC) (GLclampf depth); +#endif + +/* GL_OES_stencil1 */ +#ifndef GL_OES_stencil1 +#define GL_OES_stencil1 1 +#endif + +/* GL_OES_stencil4 */ +#ifndef GL_OES_stencil4 +#define GL_OES_stencil4 1 +#endif + +/* GL_OES_stencil8 */ +#ifndef GL_OES_stencil8 +#define GL_OES_stencil8 1 +#endif + +/* GL_OES_stencil_wrap */ +#ifndef GL_OES_stencil_wrap +#define GL_OES_stencil_wrap 1 +#endif + +/* GL_OES_texture_cube_map */ +#ifndef GL_OES_texture_cube_map +#define GL_OES_texture_cube_map 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glTexGenfOES (GLenum coord, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glTexGenfvOES (GLenum coord, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glTexGeniOES (GLenum coord, GLenum pname, GLint param); +GL_API void GL_APIENTRY glTexGenivOES (GLenum coord, GLenum pname, const GLint *params); +GL_API void GL_APIENTRY glTexGenxOES (GLenum coord, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexGenxvOES (GLenum coord, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glGetTexGenfvOES (GLenum coord, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetTexGenivOES (GLenum coord, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetTexGenxvOES (GLenum coord, GLenum pname, GLfixed *params); +#endif +typedef void (GL_APIENTRYP PFNGLTEXGENFOESPROC) (GLenum coord, GLenum pname, GLfloat param); +typedef void (GL_APIENTRYP PFNGLTEXGENFVOESPROC) (GLenum coord, GLenum pname, const GLfloat *params); +typedef void (GL_APIENTRYP PFNGLTEXGENIOESPROC) (GLenum coord, GLenum pname, GLint param); +typedef void (GL_APIENTRYP PFNGLTEXGENIVOESPROC) (GLenum coord, GLenum pname, const GLint *params); +typedef void (GL_APIENTRYP PFNGLTEXGENXOESPROC) (GLenum coord, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLTEXGENXVOESPROC) (GLenum coord, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETTEXGENFVOESPROC) (GLenum coord, GLenum pname, GLfloat *params); +typedef void (GL_APIENTRYP PFNGLGETTEXGENIVOESPROC) (GLenum coord, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLGETTEXGENXVOESPROC) (GLenum coord, GLenum pname, GLfixed *params); +#endif + +/* GL_OES_texture_env_crossbar */ +#ifndef GL_OES_texture_env_crossbar +#define GL_OES_texture_env_crossbar 1 +#endif + +/* GL_OES_texture_mirrored_repeat */ +#ifndef GL_OES_texture_mirrored_repeat +#define GL_OES_texture_mirrored_repeat 1 +#endif + +/* GL_OES_vertex_array_object */ +#ifndef GL_OES_vertex_array_object +#define GL_OES_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glBindVertexArrayOES (GLuint array); +GL_API void GL_APIENTRY glDeleteVertexArraysOES (GLsizei n, const GLuint *arrays); +GL_API void GL_APIENTRY glGenVertexArraysOES (GLsizei n, GLuint *arrays); +GL_API GLboolean GL_APIENTRY glIsVertexArrayOES (GLuint array); +#endif +typedef void (GL_APIENTRYP PFNGLBINDVERTEXARRAYOESPROC) (GLuint array); +typedef void (GL_APIENTRYP PFNGLDELETEVERTEXARRAYSOESPROC) (GLsizei n, const GLuint *arrays); +typedef void (GL_APIENTRYP PFNGLGENVERTEXARRAYSOESPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (GL_APIENTRYP PFNGLISVERTEXARRAYOESPROC) (GLuint array); +#endif + +/*------------------------------------------------------------------------* + * AMD extension functions + *------------------------------------------------------------------------*/ + +/* GL_AMD_compressed_3DC_texture */ +#ifndef GL_AMD_compressed_3DC_texture +#define GL_AMD_compressed_3DC_texture 1 +#endif + +/* GL_AMD_compressed_ATC_texture */ +#ifndef GL_AMD_compressed_ATC_texture +#define GL_AMD_compressed_ATC_texture 1 +#endif + +/*------------------------------------------------------------------------* + * APPLE extension functions + *------------------------------------------------------------------------*/ + +/* GL_APPLE_texture_2D_limited_npot */ +#ifndef GL_APPLE_texture_2D_limited_npot +#define GL_APPLE_texture_2D_limited_npot 1 +#endif + +/*------------------------------------------------------------------------* + * EXT extension functions + *------------------------------------------------------------------------*/ + +/* GL_EXT_blend_minmax */ +#ifndef GL_EXT_blend_minmax +#define GL_EXT_blend_minmax 1 +#endif + +/* GL_EXT_discard_framebuffer */ +#ifndef GL_EXT_discard_framebuffer +#define GL_EXT_discard_framebuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glDiscardFramebufferEXT (GLenum target, GLsizei numAttachments, const GLenum *attachments); +#endif +typedef void (GL_APIENTRYP PFNGLDISCARDFRAMEBUFFEREXTPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); +#endif + +/* GL_EXT_multi_draw_arrays */ +#ifndef GL_EXT_multi_draw_arrays +#define GL_EXT_multi_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glMultiDrawArraysEXT (GLenum, GLint *, GLsizei *, GLsizei); +GL_API void GL_APIENTRY glMultiDrawElementsEXT (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (GL_APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); +typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +#endif + +/* GL_EXT_read_format_bgra */ +#ifndef GL_EXT_read_format_bgra +#define GL_EXT_read_format_bgra 1 +#endif + +/* GL_EXT_texture_filter_anisotropic */ +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_EXT_texture_filter_anisotropic 1 +#endif + +/* GL_EXT_texture_format_BGRA8888 */ +#ifndef GL_EXT_texture_format_BGRA8888 +#define GL_EXT_texture_format_BGRA8888 1 +#endif + +/* GL_EXT_texture_lod_bias */ +#ifndef GL_EXT_texture_lod_bias +#define GL_EXT_texture_lod_bias 1 +#endif + +/*------------------------------------------------------------------------* + * IMG extension functions + *------------------------------------------------------------------------*/ + +/* GL_IMG_read_format */ +#ifndef GL_IMG_read_format +#define GL_IMG_read_format 1 +#endif + +/* GL_IMG_texture_compression_pvrtc */ +#ifndef GL_IMG_texture_compression_pvrtc +#define GL_IMG_texture_compression_pvrtc 1 +#endif + +/* GL_IMG_texture_env_enhanced_fixed_function */ +#ifndef GL_IMG_texture_env_enhanced_fixed_function +#define GL_IMG_texture_env_enhanced_fixed_function 1 +#endif + +/* GL_IMG_user_clip_plane */ +#ifndef GL_IMG_user_clip_plane +#define GL_IMG_user_clip_plane 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glClipPlanefIMG (GLenum, const GLfloat *); +GL_API void GL_APIENTRY glClipPlanexIMG (GLenum, const GLfixed *); +#endif +typedef void (GL_APIENTRYP PFNGLCLIPPLANEFIMGPROC) (GLenum p, const GLfloat *eqn); +typedef void (GL_APIENTRYP PFNGLCLIPPLANEXIMGPROC) (GLenum p, const GLfixed *eqn); +#endif + +/* GL_IMG_multisampled_render_to_texture */ +#ifndef GL_IMG_multisampled_render_to_texture +#define GL_IMG_multisampled_render_to_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glRenderbufferStorageMultisampleIMG (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +GL_API void GL_APIENTRY glFramebufferTexture2DMultisampleIMG (GLenum, GLenum, GLenum, GLuint, GLint, GLsizei); +#endif +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMG) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLCLIPPLANEXIMG) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples); +#endif + +/*------------------------------------------------------------------------* + * NV extension functions + *------------------------------------------------------------------------*/ + +/* NV_fence */ +#ifndef GL_NV_fence +#define GL_NV_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glDeleteFencesNV (GLsizei, const GLuint *); +GL_API void GL_APIENTRY glGenFencesNV (GLsizei, GLuint *); +GL_API GLboolean GL_APIENTRY glIsFenceNV (GLuint); +GL_API GLboolean GL_APIENTRY glTestFenceNV (GLuint); +GL_API void GL_APIENTRY glGetFenceivNV (GLuint, GLenum, GLint *); +GL_API void GL_APIENTRY glFinishFenceNV (GLuint); +GL_API void GL_APIENTRY glSetFenceNV (GLuint, GLenum); +#endif +typedef void (GL_APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences); +typedef void (GL_APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences); +typedef GLboolean (GL_APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); +typedef GLboolean (GL_APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); +typedef void (GL_APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); +typedef void (GL_APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition); +#endif + +/*------------------------------------------------------------------------* + * QCOM extension functions + *------------------------------------------------------------------------*/ + +/* GL_QCOM_driver_control */ +#ifndef GL_QCOM_driver_control +#define GL_QCOM_driver_control 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glGetDriverControlsQCOM (GLint *num, GLsizei size, GLuint *driverControls); +GL_API void GL_APIENTRY glGetDriverControlStringQCOM (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString); +GL_API void GL_APIENTRY glEnableDriverControlQCOM (GLuint driverControl); +GL_API void GL_APIENTRY glDisableDriverControlQCOM (GLuint driverControl); +#endif +typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSQCOMPROC) (GLint *num, GLsizei size, GLuint *driverControls); +typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSTRINGQCOMPROC) (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString); +typedef void (GL_APIENTRYP PFNGLENABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl); +typedef void (GL_APIENTRYP PFNGLDISABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl); +#endif + +/* GL_QCOM_extended_get */ +#ifndef GL_QCOM_extended_get +#define GL_QCOM_extended_get 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glExtGetTexturesQCOM (GLuint *textures, GLint maxTextures, GLint *numTextures); +GL_API void GL_APIENTRY glExtGetBuffersQCOM (GLuint *buffers, GLint maxBuffers, GLint *numBuffers); +GL_API void GL_APIENTRY glExtGetRenderbuffersQCOM (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers); +GL_API void GL_APIENTRY glExtGetFramebuffersQCOM (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers); +GL_API void GL_APIENTRY glExtGetTexLevelParameterivQCOM (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glExtTexObjectStateOverrideiQCOM (GLenum target, GLenum pname, GLint param); +GL_API void GL_APIENTRY glExtGetTexSubImageQCOM (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels); +GL_API void GL_APIENTRY glExtGetBufferPointervQCOM (GLenum target, GLvoid **params); +#endif +typedef void (GL_APIENTRYP PFNGLEXTGETTEXTURESQCOMPROC) (GLuint *textures, GLint maxTextures, GLint *numTextures); +typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERSQCOMPROC) (GLuint *buffers, GLint maxBuffers, GLint *numBuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETRENDERBUFFERSQCOMPROC) (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETFRAMEBUFFERSQCOMPROC) (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETTEXLEVELPARAMETERIVQCOMPROC) (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLEXTTEXOBJECTSTATEOVERRIDEIQCOMPROC) (GLenum target, GLenum pname, GLint param); +typedef void (GL_APIENTRYP PFNGLEXTGETTEXSUBIMAGEQCOMPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels); +typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERPOINTERVQCOMPROC) (GLenum target, GLvoid **params); +#endif + +/* GL_QCOM_extended_get2 */ +#ifndef GL_QCOM_extended_get2 +#define GL_QCOM_extended_get2 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glExtGetShadersQCOM (GLuint *shaders, GLint maxShaders, GLint *numShaders); +GL_API void GL_APIENTRY glExtGetProgramsQCOM (GLuint *programs, GLint maxPrograms, GLint *numPrograms); +GL_API GLboolean GL_APIENTRY glExtIsProgramBinaryQCOM (GLuint program); +GL_API void GL_APIENTRY glExtGetProgramBinarySourceQCOM (GLuint program, GLenum shadertype, GLchar *source, GLint *length); +#endif +typedef void (GL_APIENTRYP PFNGLEXTGETSHADERSQCOMPROC) (GLuint *shaders, GLint maxShaders, GLint *numShaders); +typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMSQCOMPROC) (GLuint *programs, GLint maxPrograms, GLint *numPrograms); +typedef GLboolean (GL_APIENTRYP PFNGLEXTISPROGRAMBINARYQCOMPROC) (GLuint program); +typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMBINARYSOURCEQCOMPROC) (GLuint program, GLenum shadertype, GLchar *source, GLint *length); +#endif + +/* GL_QCOM_perfmon_global_mode */ +#ifndef GL_QCOM_perfmon_global_mode +#define GL_QCOM_perfmon_global_mode 1 +#endif + +/* GL_QCOM_writeonly_rendering */ +#ifndef GL_QCOM_writeonly_rendering +#define GL_QCOM_writeonly_rendering 1 +#endif + +/* GL_QCOM_tiled_rendering */ +#ifndef GL_QCOM_tiled_rendering +#define GL_QCOM_tiled_rendering 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glStartTilingQCOM (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask); +GL_API void GL_APIENTRY glEndTilingQCOM (GLbitfield preserveMask); +#endif +typedef void (GL_APIENTRYP PFNGLSTARTTILINGQCOMPROC) (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask); +typedef void (GL_APIENTRYP PFNGLENDTILINGQCOMPROC) (GLbitfield preserveMask); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __glext_h_ */ + diff --git a/include/GLES/glplatform.h b/include/GLES/glplatform.h new file mode 100644 index 0000000..2db6ee2 --- /dev/null +++ b/include/GLES/glplatform.h @@ -0,0 +1,30 @@ +#ifndef __glplatform_h_ +#define __glplatform_h_ + +/* $Revision: 10601 $ on $Date:: 2010-03-04 22:15:27 -0800 #$ */ + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +/* Platform-specific types and definitions for OpenGL ES 1.X gl.h + * + * Adopters may modify khrplatform.h and this file to suit their platform. + * You are encouraged to submit all modifications to the Khronos group so that + * they can be included in future versions of this file. Please submit changes + * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) + * by filing a bug against product "OpenGL-ES" component "Registry". + */ + +#include + +#ifndef GL_API +#define GL_API KHRONOS_APICALL +#endif + +#ifndef GL_APIENTRY +#define GL_APIENTRY KHRONOS_APIENTRY +#endif + +#endif /* __glplatform_h_ */ diff --git a/include/GLES2/gl2.h b/include/GLES2/gl2.h new file mode 100644 index 0000000..e1d3b87 --- /dev/null +++ b/include/GLES2/gl2.h @@ -0,0 +1,621 @@ +#ifndef __gl2_h_ +#define __gl2_h_ + +/* $Revision: 10602 $ on $Date:: 2010-03-04 22:35:34 -0800 #$ */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +/*------------------------------------------------------------------------- + * Data type definitions + *-----------------------------------------------------------------------*/ + +typedef void GLvoid; +typedef char GLchar; +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef khronos_int8_t GLbyte; +typedef short GLshort; +typedef int GLint; +typedef int GLsizei; +typedef khronos_uint8_t GLubyte; +typedef unsigned short GLushort; +typedef unsigned int GLuint; +typedef khronos_float_t GLfloat; +typedef khronos_float_t GLclampf; +typedef khronos_int32_t GLfixed; + +/* GL types for handling large vertex buffer objects */ +typedef khronos_intptr_t GLintptr; +typedef khronos_ssize_t GLsizeiptr; + +/* OpenGL ES core versions */ +#define GL_ES_VERSION_2_0 1 + +/* ClearBufferMask */ +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_COLOR_BUFFER_BIT 0x00004000 + +/* Boolean */ +#define GL_FALSE 0 +#define GL_TRUE 1 + +/* BeginMode */ +#define GL_POINTS 0x0000 +#define GL_LINES 0x0001 +#define GL_LINE_LOOP 0x0002 +#define GL_LINE_STRIP 0x0003 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_TRIANGLE_FAN 0x0006 + +/* AlphaFunction (not supported in ES20) */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* BlendingFactorDest */ +#define GL_ZERO 0 +#define GL_ONE 1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 + +/* BlendingFactorSrc */ +/* GL_ZERO */ +/* GL_ONE */ +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 +/* GL_SRC_ALPHA */ +/* GL_ONE_MINUS_SRC_ALPHA */ +/* GL_DST_ALPHA */ +/* GL_ONE_MINUS_DST_ALPHA */ + +/* BlendEquationSeparate */ +#define GL_FUNC_ADD 0x8006 +#define GL_BLEND_EQUATION 0x8009 +#define GL_BLEND_EQUATION_RGB 0x8009 /* same as BLEND_EQUATION */ +#define GL_BLEND_EQUATION_ALPHA 0x883D + +/* BlendSubtract */ +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B + +/* Separate Blend Functions */ +#define GL_BLEND_DST_RGB 0x80C8 +#define GL_BLEND_SRC_RGB 0x80C9 +#define GL_BLEND_DST_ALPHA 0x80CA +#define GL_BLEND_SRC_ALPHA 0x80CB +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_BLEND_COLOR 0x8005 + +/* Buffer Objects */ +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 + +#define GL_STREAM_DRAW 0x88E0 +#define GL_STATIC_DRAW 0x88E4 +#define GL_DYNAMIC_DRAW 0x88E8 + +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 + +#define GL_CURRENT_VERTEX_ATTRIB 0x8626 + +/* CullFaceMode */ +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_FRONT_AND_BACK 0x0408 + +/* DepthFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* EnableCap */ +#define GL_TEXTURE_2D 0x0DE1 +#define GL_CULL_FACE 0x0B44 +#define GL_BLEND 0x0BE2 +#define GL_DITHER 0x0BD0 +#define GL_STENCIL_TEST 0x0B90 +#define GL_DEPTH_TEST 0x0B71 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_POLYGON_OFFSET_FILL 0x8037 +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_COVERAGE 0x80A0 + +/* ErrorCode */ +#define GL_NO_ERROR 0 +#define GL_INVALID_ENUM 0x0500 +#define GL_INVALID_VALUE 0x0501 +#define GL_INVALID_OPERATION 0x0502 +#define GL_OUT_OF_MEMORY 0x0505 + +/* FrontFaceDirection */ +#define GL_CW 0x0900 +#define GL_CCW 0x0901 + +/* GetPName */ +#define GL_LINE_WIDTH 0x0B21 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_DEPTH_RANGE 0x0B70 +#define GL_DEPTH_WRITEMASK 0x0B72 +#define GL_DEPTH_CLEAR_VALUE 0x0B73 +#define GL_DEPTH_FUNC 0x0B74 +#define GL_STENCIL_CLEAR_VALUE 0x0B91 +#define GL_STENCIL_FUNC 0x0B92 +#define GL_STENCIL_FAIL 0x0B94 +#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 +#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 +#define GL_STENCIL_REF 0x0B97 +#define GL_STENCIL_VALUE_MASK 0x0B93 +#define GL_STENCIL_WRITEMASK 0x0B98 +#define GL_STENCIL_BACK_FUNC 0x8800 +#define GL_STENCIL_BACK_FAIL 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 +#define GL_STENCIL_BACK_REF 0x8CA3 +#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 +#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 +#define GL_VIEWPORT 0x0BA2 +#define GL_SCISSOR_BOX 0x0C10 +/* GL_SCISSOR_TEST */ +#define GL_COLOR_CLEAR_VALUE 0x0C22 +#define GL_COLOR_WRITEMASK 0x0C23 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_MAX_TEXTURE_SIZE 0x0D33 +#define GL_MAX_VIEWPORT_DIMS 0x0D3A +#define GL_SUBPIXEL_BITS 0x0D50 +#define GL_RED_BITS 0x0D52 +#define GL_GREEN_BITS 0x0D53 +#define GL_BLUE_BITS 0x0D54 +#define GL_ALPHA_BITS 0x0D55 +#define GL_DEPTH_BITS 0x0D56 +#define GL_STENCIL_BITS 0x0D57 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +/* GL_POLYGON_OFFSET_FILL */ +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_TEXTURE_BINDING_2D 0x8069 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB + +/* GetTextureParameter */ +/* GL_TEXTURE_MAG_FILTER */ +/* GL_TEXTURE_MIN_FILTER */ +/* GL_TEXTURE_WRAP_S */ +/* GL_TEXTURE_WRAP_T */ + +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 + +/* HintMode */ +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 + +/* HintTarget */ +#define GL_GENERATE_MIPMAP_HINT 0x8192 + +/* DataType */ +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_INT 0x1404 +#define GL_UNSIGNED_INT 0x1405 +#define GL_FLOAT 0x1406 +#define GL_FIXED 0x140C + +/* PixelFormat */ +#define GL_DEPTH_COMPONENT 0x1902 +#define GL_ALPHA 0x1906 +#define GL_RGB 0x1907 +#define GL_RGBA 0x1908 +#define GL_LUMINANCE 0x1909 +#define GL_LUMINANCE_ALPHA 0x190A + +/* PixelType */ +/* GL_UNSIGNED_BYTE */ +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 + +/* Shaders */ +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 +#define GL_MAX_VERTEX_ATTRIBS 0x8869 +#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB +#define GL_MAX_VARYING_VECTORS 0x8DFC +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C +#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 +#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD +#define GL_SHADER_TYPE 0x8B4F +#define GL_DELETE_STATUS 0x8B80 +#define GL_LINK_STATUS 0x8B82 +#define GL_VALIDATE_STATUS 0x8B83 +#define GL_ATTACHED_SHADERS 0x8B85 +#define GL_ACTIVE_UNIFORMS 0x8B86 +#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 +#define GL_ACTIVE_ATTRIBUTES 0x8B89 +#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A +#define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#define GL_CURRENT_PROGRAM 0x8B8D + +/* StencilFunction */ +#define GL_NEVER 0x0200 +#define GL_LESS 0x0201 +#define GL_EQUAL 0x0202 +#define GL_LEQUAL 0x0203 +#define GL_GREATER 0x0204 +#define GL_NOTEQUAL 0x0205 +#define GL_GEQUAL 0x0206 +#define GL_ALWAYS 0x0207 + +/* StencilOp */ +/* GL_ZERO */ +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 +#define GL_INVERT 0x150A +#define GL_INCR_WRAP 0x8507 +#define GL_DECR_WRAP 0x8508 + +/* StringName */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 + +/* TextureMagFilter */ +#define GL_NEAREST 0x2600 +#define GL_LINEAR 0x2601 + +/* TextureMinFilter */ +/* GL_NEAREST */ +/* GL_LINEAR */ +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 + +/* TextureParameterName */ +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 + +/* TextureTarget */ +/* GL_TEXTURE_2D */ +#define GL_TEXTURE 0x1702 + +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C + +/* TextureUnit */ +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 + +/* TextureWrapMode */ +#define GL_REPEAT 0x2901 +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_MIRRORED_REPEAT 0x8370 + +/* Uniform Types */ +#define GL_FLOAT_VEC2 0x8B50 +#define GL_FLOAT_VEC3 0x8B51 +#define GL_FLOAT_VEC4 0x8B52 +#define GL_INT_VEC2 0x8B53 +#define GL_INT_VEC3 0x8B54 +#define GL_INT_VEC4 0x8B55 +#define GL_BOOL 0x8B56 +#define GL_BOOL_VEC2 0x8B57 +#define GL_BOOL_VEC3 0x8B58 +#define GL_BOOL_VEC4 0x8B59 +#define GL_FLOAT_MAT2 0x8B5A +#define GL_FLOAT_MAT3 0x8B5B +#define GL_FLOAT_MAT4 0x8B5C +#define GL_SAMPLER_2D 0x8B5E +#define GL_SAMPLER_CUBE 0x8B60 + +/* Vertex Arrays */ +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A +#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F + +/* Read Format */ +#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B + +/* Shader Source */ +#define GL_COMPILE_STATUS 0x8B81 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_SHADER_SOURCE_LENGTH 0x8B88 +#define GL_SHADER_COMPILER 0x8DFA + +/* Shader Binary */ +#define GL_SHADER_BINARY_FORMATS 0x8DF8 +#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 + +/* Shader Precision-Specified Types */ +#define GL_LOW_FLOAT 0x8DF0 +#define GL_MEDIUM_FLOAT 0x8DF1 +#define GL_HIGH_FLOAT 0x8DF2 +#define GL_LOW_INT 0x8DF3 +#define GL_MEDIUM_INT 0x8DF4 +#define GL_HIGH_INT 0x8DF5 + +/* Framebuffer Object. */ +#define GL_FRAMEBUFFER 0x8D40 +#define GL_RENDERBUFFER 0x8D41 + +#define GL_RGBA4 0x8056 +#define GL_RGB5_A1 0x8057 +#define GL_RGB565 0x8D62 +#define GL_DEPTH_COMPONENT16 0x81A5 +#define GL_STENCIL_INDEX 0x1901 +#define GL_STENCIL_INDEX8 0x8D48 + +#define GL_RENDERBUFFER_WIDTH 0x8D42 +#define GL_RENDERBUFFER_HEIGHT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 +#define GL_RENDERBUFFER_RED_SIZE 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 + +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 + +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#define GL_DEPTH_ATTACHMENT 0x8D00 +#define GL_STENCIL_ATTACHMENT 0x8D20 + +#define GL_NONE 0 + +#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9 +#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD + +#define GL_FRAMEBUFFER_BINDING 0x8CA6 +#define GL_RENDERBUFFER_BINDING 0x8CA7 +#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 + +#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 + +/*------------------------------------------------------------------------- + * GL core functions. + *-----------------------------------------------------------------------*/ + +GL_APICALL void GL_APIENTRY glActiveTexture (GLenum texture); +GL_APICALL void GL_APIENTRY glAttachShader (GLuint program, GLuint shader); +GL_APICALL void GL_APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar* name); +GL_APICALL void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer); +GL_APICALL void GL_APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer); +GL_APICALL void GL_APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer); +GL_APICALL void GL_APIENTRY glBindTexture (GLenum target, GLuint texture); +GL_APICALL void GL_APIENTRY glBlendColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +GL_APICALL void GL_APIENTRY glBlendEquation ( GLenum mode ); +GL_APICALL void GL_APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); +GL_APICALL void GL_APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor); +GL_APICALL void GL_APIENTRY glBlendFuncSeparate (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +GL_APICALL void GL_APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage); +GL_APICALL void GL_APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data); +GL_APICALL GLenum GL_APIENTRY glCheckFramebufferStatus (GLenum target); +GL_APICALL void GL_APIENTRY glClear (GLbitfield mask); +GL_APICALL void GL_APIENTRY glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +GL_APICALL void GL_APIENTRY glClearDepthf (GLclampf depth); +GL_APICALL void GL_APIENTRY glClearStencil (GLint s); +GL_APICALL void GL_APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +GL_APICALL void GL_APIENTRY glCompileShader (GLuint shader); +GL_APICALL void GL_APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GL_APICALL void GL_APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL GLuint GL_APIENTRY glCreateProgram (void); +GL_APICALL GLuint GL_APIENTRY glCreateShader (GLenum type); +GL_APICALL void GL_APIENTRY glCullFace (GLenum mode); +GL_APICALL void GL_APIENTRY glDeleteBuffers (GLsizei n, const GLuint* buffers); +GL_APICALL void GL_APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint* framebuffers); +GL_APICALL void GL_APIENTRY glDeleteProgram (GLuint program); +GL_APICALL void GL_APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint* renderbuffers); +GL_APICALL void GL_APIENTRY glDeleteShader (GLuint shader); +GL_APICALL void GL_APIENTRY glDeleteTextures (GLsizei n, const GLuint* textures); +GL_APICALL void GL_APIENTRY glDepthFunc (GLenum func); +GL_APICALL void GL_APIENTRY glDepthMask (GLboolean flag); +GL_APICALL void GL_APIENTRY glDepthRangef (GLclampf zNear, GLclampf zFar); +GL_APICALL void GL_APIENTRY glDetachShader (GLuint program, GLuint shader); +GL_APICALL void GL_APIENTRY glDisable (GLenum cap); +GL_APICALL void GL_APIENTRY glDisableVertexAttribArray (GLuint index); +GL_APICALL void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count); +GL_APICALL void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices); +GL_APICALL void GL_APIENTRY glEnable (GLenum cap); +GL_APICALL void GL_APIENTRY glEnableVertexAttribArray (GLuint index); +GL_APICALL void GL_APIENTRY glFinish (void); +GL_APICALL void GL_APIENTRY glFlush (void); +GL_APICALL void GL_APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GL_APICALL void GL_APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GL_APICALL void GL_APIENTRY glFrontFace (GLenum mode); +GL_APICALL void GL_APIENTRY glGenBuffers (GLsizei n, GLuint* buffers); +GL_APICALL void GL_APIENTRY glGenerateMipmap (GLenum target); +GL_APICALL void GL_APIENTRY glGenFramebuffers (GLsizei n, GLuint* framebuffers); +GL_APICALL void GL_APIENTRY glGenRenderbuffers (GLsizei n, GLuint* renderbuffers); +GL_APICALL void GL_APIENTRY glGenTextures (GLsizei n, GLuint* textures); +GL_APICALL void GL_APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); +GL_APICALL void GL_APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); +GL_APICALL void GL_APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders); +GL_APICALL int GL_APIENTRY glGetAttribLocation (GLuint program, const GLchar* name); +GL_APICALL void GL_APIENTRY glGetBooleanv (GLenum pname, GLboolean* params); +GL_APICALL void GL_APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL GLenum GL_APIENTRY glGetError (void); +GL_APICALL void GL_APIENTRY glGetFloatv (GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetIntegerv (GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog); +GL_APICALL void GL_APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog); +GL_APICALL void GL_APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); +GL_APICALL void GL_APIENTRY glGetShaderSource (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source); +GL_APICALL const GLubyte* GL_APIENTRY glGetString (GLenum name); +GL_APICALL void GL_APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetUniformiv (GLuint program, GLint location, GLint* params); +GL_APICALL int GL_APIENTRY glGetUniformLocation (GLuint program, const GLchar* name); +GL_APICALL void GL_APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid** pointer); +GL_APICALL void GL_APIENTRY glHint (GLenum target, GLenum mode); +GL_APICALL GLboolean GL_APIENTRY glIsBuffer (GLuint buffer); +GL_APICALL GLboolean GL_APIENTRY glIsEnabled (GLenum cap); +GL_APICALL GLboolean GL_APIENTRY glIsFramebuffer (GLuint framebuffer); +GL_APICALL GLboolean GL_APIENTRY glIsProgram (GLuint program); +GL_APICALL GLboolean GL_APIENTRY glIsRenderbuffer (GLuint renderbuffer); +GL_APICALL GLboolean GL_APIENTRY glIsShader (GLuint shader); +GL_APICALL GLboolean GL_APIENTRY glIsTexture (GLuint texture); +GL_APICALL void GL_APIENTRY glLineWidth (GLfloat width); +GL_APICALL void GL_APIENTRY glLinkProgram (GLuint program); +GL_APICALL void GL_APIENTRY glPixelStorei (GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units); +GL_APICALL void GL_APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels); +GL_APICALL void GL_APIENTRY glReleaseShaderCompiler (void); +GL_APICALL void GL_APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glSampleCoverage (GLclampf value, GLboolean invert); +GL_APICALL void GL_APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glShaderBinary (GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length); +GL_APICALL void GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar** string, const GLint* length); +GL_APICALL void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilMask (GLuint mask); +GL_APICALL void GL_APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); +GL_APICALL void GL_APIENTRY glStencilOpSeparate (GLenum face, GLenum fail, GLenum zfail, GLenum zpass); +GL_APICALL void GL_APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param); +GL_APICALL void GL_APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat* params); +GL_APICALL void GL_APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint* params); +GL_APICALL void GL_APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glUniform1f (GLint location, GLfloat x); +GL_APICALL void GL_APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform1i (GLint location, GLint x); +GL_APICALL void GL_APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform2f (GLint location, GLfloat x, GLfloat y); +GL_APICALL void GL_APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform2i (GLint location, GLint x, GLint y); +GL_APICALL void GL_APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform3f (GLint location, GLfloat x, GLfloat y, GLfloat z); +GL_APICALL void GL_APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform3i (GLint location, GLint x, GLint y, GLint z); +GL_APICALL void GL_APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform4f (GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GL_APICALL void GL_APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform4i (GLint location, GLint x, GLint y, GLint z, GLint w); +GL_APICALL void GL_APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUseProgram (GLuint program); +GL_APICALL void GL_APIENTRY glValidateProgram (GLuint program); +GL_APICALL void GL_APIENTRY glVertexAttrib1f (GLuint indx, GLfloat x); +GL_APICALL void GL_APIENTRY glVertexAttrib1fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib2f (GLuint indx, GLfloat x, GLfloat y); +GL_APICALL void GL_APIENTRY glVertexAttrib2fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib3f (GLuint indx, GLfloat x, GLfloat y, GLfloat z); +GL_APICALL void GL_APIENTRY glVertexAttrib3fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib4f (GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GL_APICALL void GL_APIENTRY glVertexAttrib4fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttribPointer (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr); +GL_APICALL void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); + +#ifdef __cplusplus +} +#endif + +#endif /* __gl2_h_ */ diff --git a/include/GLES2/gl2ext.h b/include/GLES2/gl2ext.h new file mode 100644 index 0000000..334e9ce --- /dev/null +++ b/include/GLES2/gl2ext.h @@ -0,0 +1,803 @@ +#ifndef __gl2ext_h_ +#define __gl2ext_h_ + +/* $Revision: 10969 $ on $Date:: 2010-04-09 02:27:15 -0700 #$ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +#ifndef GL_APIENTRYP +# define GL_APIENTRYP GL_APIENTRY* +#endif + +/*------------------------------------------------------------------------* + * OES extension tokens + *------------------------------------------------------------------------*/ + +/* GL_OES_compressed_ETC1_RGB8_texture */ +#ifndef GL_OES_compressed_ETC1_RGB8_texture +#define GL_ETC1_RGB8_OES 0x8D64 +#endif + +/* GL_OES_compressed_paletted_texture */ +#ifndef GL_OES_compressed_paletted_texture +#define GL_PALETTE4_RGB8_OES 0x8B90 +#define GL_PALETTE4_RGBA8_OES 0x8B91 +#define GL_PALETTE4_R5_G6_B5_OES 0x8B92 +#define GL_PALETTE4_RGBA4_OES 0x8B93 +#define GL_PALETTE4_RGB5_A1_OES 0x8B94 +#define GL_PALETTE8_RGB8_OES 0x8B95 +#define GL_PALETTE8_RGBA8_OES 0x8B96 +#define GL_PALETTE8_R5_G6_B5_OES 0x8B97 +#define GL_PALETTE8_RGBA4_OES 0x8B98 +#define GL_PALETTE8_RGB5_A1_OES 0x8B99 +#endif + +/* GL_OES_depth24 */ +#ifndef GL_OES_depth24 +#define GL_DEPTH_COMPONENT24_OES 0x81A6 +#endif + +/* GL_OES_depth32 */ +#ifndef GL_OES_depth32 +#define GL_DEPTH_COMPONENT32_OES 0x81A7 +#endif + +/* GL_OES_depth_texture */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +typedef void* GLeglImageOES; +#endif + +/* GL_OES_element_index_uint */ +#ifndef GL_OES_element_index_uint +#define GL_UNSIGNED_INT 0x1405 +#endif + +/* GL_OES_get_program_binary */ +#ifndef GL_OES_get_program_binary +#define GL_PROGRAM_BINARY_LENGTH_OES 0x8741 +#define GL_NUM_PROGRAM_BINARY_FORMATS_OES 0x87FE +#define GL_PROGRAM_BINARY_FORMATS_OES 0x87FF +#endif + +/* GL_OES_mapbuffer */ +#ifndef GL_OES_mapbuffer +#define GL_WRITE_ONLY_OES 0x88B9 +#define GL_BUFFER_ACCESS_OES 0x88BB +#define GL_BUFFER_MAPPED_OES 0x88BC +#define GL_BUFFER_MAP_POINTER_OES 0x88BD +#endif + +/* GL_OES_packed_depth_stencil */ +#ifndef GL_OES_packed_depth_stencil +#define GL_DEPTH_STENCIL_OES 0x84F9 +#define GL_UNSIGNED_INT_24_8_OES 0x84FA +#define GL_DEPTH24_STENCIL8_OES 0x88F0 +#endif + +/* GL_OES_rgb8_rgba8 */ +#ifndef GL_OES_rgb8_rgba8 +#define GL_RGB8_OES 0x8051 +#define GL_RGBA8_OES 0x8058 +#endif + +/* GL_OES_standard_derivatives */ +#ifndef GL_OES_standard_derivatives +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES 0x8B8B +#endif + +/* GL_OES_stencil1 */ +#ifndef GL_OES_stencil1 +#define GL_STENCIL_INDEX1_OES 0x8D46 +#endif + +/* GL_OES_stencil4 */ +#ifndef GL_OES_stencil4 +#define GL_STENCIL_INDEX4_OES 0x8D47 +#endif + +/* GL_OES_texture_3D */ +#ifndef GL_OES_texture_3D +#define GL_TEXTURE_WRAP_R_OES 0x8072 +#define GL_TEXTURE_3D_OES 0x806F +#define GL_TEXTURE_BINDING_3D_OES 0x806A +#define GL_MAX_3D_TEXTURE_SIZE_OES 0x8073 +#define GL_SAMPLER_3D_OES 0x8B5F +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_OES 0x8CD4 +#endif + +/* GL_OES_texture_float */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_texture_float_linear */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_texture_half_float */ +#ifndef GL_OES_texture_half_float +#define GL_HALF_FLOAT_OES 0x8D61 +#endif + +/* GL_OES_texture_half_float_linear */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_texture_npot */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_vertex_array_object */ +#ifndef GL_OES_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING_OES 0x85B5 +#endif + +/* GL_OES_vertex_half_float */ +/* GL_HALF_FLOAT_OES defined in GL_OES_texture_half_float already. */ + +/* GL_OES_vertex_type_10_10_10_2 */ +#ifndef GL_OES_vertex_type_10_10_10_2 +#define GL_UNSIGNED_INT_10_10_10_2_OES 0x8DF6 +#define GL_INT_10_10_10_2_OES 0x8DF7 +#endif + +/*------------------------------------------------------------------------* + * AMD extension tokens + *------------------------------------------------------------------------*/ + +/* GL_AMD_compressed_3DC_texture */ +#ifndef GL_AMD_compressed_3DC_texture +#define GL_3DC_X_AMD 0x87F9 +#define GL_3DC_XY_AMD 0x87FA +#endif + +/* GL_AMD_compressed_ATC_texture */ +#ifndef GL_AMD_compressed_ATC_texture +#define GL_ATC_RGB_AMD 0x8C92 +#define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93 +#define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE +#endif + +/* GL_AMD_performance_monitor */ +#ifndef GL_AMD_performance_monitor +#define GL_COUNTER_TYPE_AMD 0x8BC0 +#define GL_COUNTER_RANGE_AMD 0x8BC1 +#define GL_UNSIGNED_INT64_AMD 0x8BC2 +#define GL_PERCENTAGE_AMD 0x8BC3 +#define GL_PERFMON_RESULT_AVAILABLE_AMD 0x8BC4 +#define GL_PERFMON_RESULT_SIZE_AMD 0x8BC5 +#define GL_PERFMON_RESULT_AMD 0x8BC6 +#endif + +/* GL_AMD_program_binary_Z400 */ +#ifndef GL_AMD_program_binary_Z400 +#define GL_Z400_BINARY_AMD 0x8740 +#endif + +/*------------------------------------------------------------------------* + * EXT extension tokens + *------------------------------------------------------------------------*/ + +/* GL_EXT_blend_minmax */ +#ifndef GL_EXT_blend_minmax +#define GL_MIN_EXT 0x8007 +#define GL_MAX_EXT 0x8008 +#endif + +/* GL_EXT_discard_framebuffer */ +#ifndef GL_EXT_discard_framebuffer +#define GL_COLOR_EXT 0x1800 +#define GL_DEPTH_EXT 0x1801 +#define GL_STENCIL_EXT 0x1802 +#endif + +/* GL_EXT_multi_draw_arrays */ +/* No new tokens introduced by this extension. */ + +/* GL_EXT_read_format_bgra */ +#ifndef GL_EXT_read_format_bgra +#define GL_BGRA_EXT 0x80E1 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT 0x8366 +#endif + +/* GL_EXT_texture_filter_anisotropic */ +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF +#endif + +/* GL_EXT_texture_format_BGRA8888 */ +#ifndef GL_EXT_texture_format_BGRA8888 +#define GL_BGRA_EXT 0x80E1 +#endif + +/* GL_EXT_texture_type_2_10_10_10_REV */ +#ifndef GL_EXT_texture_type_2_10_10_10_REV +#define GL_UNSIGNED_INT_2_10_10_10_REV_EXT 0x8368 +#endif + +/* GL_EXT_texture_compression_dxt1 */ +#ifndef GL_EXT_texture_compression_dxt1 +#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 +#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 +#endif + +/*------------------------------------------------------------------------* + * IMG extension tokens + *------------------------------------------------------------------------*/ + +/* GL_IMG_program_binary */ +#ifndef GL_IMG_program_binary +#define GL_SGX_PROGRAM_BINARY_IMG 0x9130 +#endif + +/* GL_IMG_read_format */ +#ifndef GL_IMG_read_format +#define GL_BGRA_IMG 0x80E1 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV_IMG 0x8365 +#endif + +/* GL_IMG_shader_binary */ +#ifndef GL_IMG_shader_binary +#define GL_SGX_BINARY_IMG 0x8C0A +#endif + +/* GL_IMG_texture_compression_pvrtc */ +#ifndef GL_IMG_texture_compression_pvrtc +#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 +#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 +#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 +#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 +#endif + +/* GL_IMG_multisampled_render_to_texture */ +#ifndef GL_IMG_multisampled_render_to_texture +#define GL_RENDERBUFFER_SAMPLES_IMG 0x9133 +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_IMG 0x9134 +#define GL_MAX_SAMPLES_IMG 0x9135 +#define GL_TEXTURE_SAMPLES_IMG 0x9136 +#endif + +/*------------------------------------------------------------------------* + * NV extension tokens + *------------------------------------------------------------------------*/ + +/* GL_NV_fence */ +#ifndef GL_NV_fence +#define GL_ALL_COMPLETED_NV 0x84F2 +#define GL_FENCE_STATUS_NV 0x84F3 +#define GL_FENCE_CONDITION_NV 0x84F4 +#endif + +/* GL_NV_coverage_sample */ +#ifndef GL_NV_coverage_sample +#define GL_COVERAGE_COMPONENT_NV 0x8ED0 +#define GL_COVERAGE_COMPONENT4_NV 0x8ED1 +#define GL_COVERAGE_ATTACHMENT_NV 0x8ED2 +#define GL_COVERAGE_BUFFERS_NV 0x8ED3 +#define GL_COVERAGE_SAMPLES_NV 0x8ED4 +#define GL_COVERAGE_ALL_FRAGMENTS_NV 0x8ED5 +#define GL_COVERAGE_EDGE_FRAGMENTS_NV 0x8ED6 +#define GL_COVERAGE_AUTOMATIC_NV 0x8ED7 +#define GL_COVERAGE_BUFFER_BIT_NV 0x8000 +#endif + +/* GL_NV_depth_nonlinear */ +#ifndef GL_NV_depth_nonlinear +#define GL_DEPTH_COMPONENT16_NONLINEAR_NV 0x8E2C +#endif + +/*------------------------------------------------------------------------* + * QCOM extension tokens + *------------------------------------------------------------------------*/ + +/* GL_QCOM_driver_control */ +/* No new tokens introduced by this extension. */ + +/* GL_QCOM_extended_get */ +#ifndef GL_QCOM_extended_get +#define GL_TEXTURE_WIDTH_QCOM 0x8BD2 +#define GL_TEXTURE_HEIGHT_QCOM 0x8BD3 +#define GL_TEXTURE_DEPTH_QCOM 0x8BD4 +#define GL_TEXTURE_INTERNAL_FORMAT_QCOM 0x8BD5 +#define GL_TEXTURE_FORMAT_QCOM 0x8BD6 +#define GL_TEXTURE_TYPE_QCOM 0x8BD7 +#define GL_TEXTURE_IMAGE_VALID_QCOM 0x8BD8 +#define GL_TEXTURE_NUM_LEVELS_QCOM 0x8BD9 +#define GL_TEXTURE_TARGET_QCOM 0x8BDA +#define GL_TEXTURE_OBJECT_VALID_QCOM 0x8BDB +#define GL_STATE_RESTORE 0x8BDC +#endif + +/* GL_QCOM_extended_get2 */ +/* No new tokens introduced by this extension. */ + +/* GL_QCOM_perfmon_global_mode */ +#ifndef GL_QCOM_perfmon_global_mode +#define GL_PERFMON_GLOBAL_MODE_QCOM 0x8FA0 +#endif + +/* GL_QCOM_writeonly_rendering */ +#ifndef GL_QCOM_writeonly_rendering +#define GL_WRITEONLY_RENDERING_QCOM 0x8823 +#endif + +/* GL_QCOM_tiled_rendering */ +#ifndef GL_QCOM_tiled_rendering +#define GL_COLOR_BUFFER_BIT0_QCOM 0x00000001 +#define GL_COLOR_BUFFER_BIT1_QCOM 0x00000002 +#define GL_COLOR_BUFFER_BIT2_QCOM 0x00000004 +#define GL_COLOR_BUFFER_BIT3_QCOM 0x00000008 +#define GL_COLOR_BUFFER_BIT4_QCOM 0x00000010 +#define GL_COLOR_BUFFER_BIT5_QCOM 0x00000020 +#define GL_COLOR_BUFFER_BIT6_QCOM 0x00000040 +#define GL_COLOR_BUFFER_BIT7_QCOM 0x00000080 +#define GL_DEPTH_BUFFER_BIT0_QCOM 0x00000100 +#define GL_DEPTH_BUFFER_BIT1_QCOM 0x00000200 +#define GL_DEPTH_BUFFER_BIT2_QCOM 0x00000400 +#define GL_DEPTH_BUFFER_BIT3_QCOM 0x00000800 +#define GL_DEPTH_BUFFER_BIT4_QCOM 0x00001000 +#define GL_DEPTH_BUFFER_BIT5_QCOM 0x00002000 +#define GL_DEPTH_BUFFER_BIT6_QCOM 0x00004000 +#define GL_DEPTH_BUFFER_BIT7_QCOM 0x00008000 +#define GL_STENCIL_BUFFER_BIT0_QCOM 0x00010000 +#define GL_STENCIL_BUFFER_BIT1_QCOM 0x00020000 +#define GL_STENCIL_BUFFER_BIT2_QCOM 0x00040000 +#define GL_STENCIL_BUFFER_BIT3_QCOM 0x00080000 +#define GL_STENCIL_BUFFER_BIT4_QCOM 0x00100000 +#define GL_STENCIL_BUFFER_BIT5_QCOM 0x00200000 +#define GL_STENCIL_BUFFER_BIT6_QCOM 0x00400000 +#define GL_STENCIL_BUFFER_BIT7_QCOM 0x00800000 +#define GL_MULTISAMPLE_BUFFER_BIT0_QCOM 0x01000000 +#define GL_MULTISAMPLE_BUFFER_BIT1_QCOM 0x02000000 +#define GL_MULTISAMPLE_BUFFER_BIT2_QCOM 0x04000000 +#define GL_MULTISAMPLE_BUFFER_BIT3_QCOM 0x08000000 +#define GL_MULTISAMPLE_BUFFER_BIT4_QCOM 0x10000000 +#define GL_MULTISAMPLE_BUFFER_BIT5_QCOM 0x20000000 +#define GL_MULTISAMPLE_BUFFER_BIT6_QCOM 0x40000000 +#define GL_MULTISAMPLE_BUFFER_BIT7_QCOM 0x80000000 +#endif + +/*------------------------------------------------------------------------* + * End of extension tokens, start of corresponding extension functions + *------------------------------------------------------------------------*/ + +/*------------------------------------------------------------------------* + * OES extension functions + *------------------------------------------------------------------------*/ + +/* GL_OES_compressed_ETC1_RGB8_texture */ +#ifndef GL_OES_compressed_ETC1_RGB8_texture +#define GL_OES_compressed_ETC1_RGB8_texture 1 +#endif + +/* GL_OES_compressed_paletted_texture */ +#ifndef GL_OES_compressed_paletted_texture +#define GL_OES_compressed_paletted_texture 1 +#endif + +/* GL_OES_depth24 */ +#ifndef GL_OES_depth24 +#define GL_OES_depth24 1 +#endif + +/* GL_OES_depth32 */ +#ifndef GL_OES_depth32 +#define GL_OES_depth32 1 +#endif + +/* GL_OES_depth_texture */ +#ifndef GL_OES_depth_texture +#define GL_OES_depth_texture 1 +#endif + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +#define GL_OES_EGL_image 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image); +GL_APICALL void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image); +#endif +typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); +typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image); +#endif + +/* GL_OES_element_index_uint */ +#ifndef GL_OES_element_index_uint +#define GL_OES_element_index_uint 1 +#endif + +/* GL_OES_fbo_render_mipmap */ +#ifndef GL_OES_fbo_render_mipmap +#define GL_OES_fbo_render_mipmap 1 +#endif + +/* GL_OES_fragment_precision_high */ +#ifndef GL_OES_fragment_precision_high +#define GL_OES_fragment_precision_high 1 +#endif + +/* GL_OES_get_program_binary */ +#ifndef GL_OES_get_program_binary +#define GL_OES_get_program_binary 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glGetProgramBinaryOES (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +GL_APICALL void GL_APIENTRY glProgramBinaryOES (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length); +#endif +typedef void (GL_APIENTRYP PFNGLGETPROGRAMBINARYOESPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +typedef void (GL_APIENTRYP PFNGLPROGRAMBINARYOESPROC) (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length); +#endif + +/* GL_OES_mapbuffer */ +#ifndef GL_OES_mapbuffer +#define GL_OES_mapbuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void* GL_APIENTRY glMapBufferOES (GLenum target, GLenum access); +GL_APICALL GLboolean GL_APIENTRY glUnmapBufferOES (GLenum target); +GL_APICALL void GL_APIENTRY glGetBufferPointervOES (GLenum target, GLenum pname, GLvoid** params); +#endif +typedef void* (GL_APIENTRYP PFNGLMAPBUFFEROESPROC) (GLenum target, GLenum access); +typedef GLboolean (GL_APIENTRYP PFNGLUNMAPBUFFEROESPROC) (GLenum target); +typedef void (GL_APIENTRYP PFNGLGETBUFFERPOINTERVOESPROC) (GLenum target, GLenum pname, GLvoid** params); +#endif + +/* GL_OES_packed_depth_stencil */ +#ifndef GL_OES_packed_depth_stencil +#define GL_OES_packed_depth_stencil 1 +#endif + +/* GL_OES_rgb8_rgba8 */ +#ifndef GL_OES_rgb8_rgba8 +#define GL_OES_rgb8_rgba8 1 +#endif + +/* GL_OES_standard_derivatives */ +#ifndef GL_OES_standard_derivatives +#define GL_OES_standard_derivatives 1 +#endif + +/* GL_OES_stencil1 */ +#ifndef GL_OES_stencil1 +#define GL_OES_stencil1 1 +#endif + +/* GL_OES_stencil4 */ +#ifndef GL_OES_stencil4 +#define GL_OES_stencil4 1 +#endif + +/* GL_OES_texture_3D */ +#ifndef GL_OES_texture_3D +#define GL_OES_texture_3D 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glTexImage3DOES (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glCopyTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glCompressedTexImage3DOES (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCompressedTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glFramebufferTexture3DOES (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +#endif +typedef void (GL_APIENTRYP PFNGLTEXIMAGE3DOESPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels); +typedef void (GL_APIENTRYP PFNGLTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels); +typedef void (GL_APIENTRYP PFNGLCOPYTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DOESPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data); +typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DOES) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +#endif + +/* GL_OES_texture_float */ +#ifndef GL_OES_texture_float +#define GL_OES_texture_float 1 +#endif + +/* GL_OES_texture_float_linear */ +#ifndef GL_OES_texture_float_linear +#define GL_OES_texture_float_linear 1 +#endif + +/* GL_OES_texture_half_float */ +#ifndef GL_OES_texture_half_float +#define GL_OES_texture_half_float 1 +#endif + +/* GL_OES_texture_half_float_linear */ +#ifndef GL_OES_texture_half_float_linear +#define GL_OES_texture_half_float_linear 1 +#endif + +/* GL_OES_texture_npot */ +#ifndef GL_OES_texture_npot +#define GL_OES_texture_npot 1 +#endif + +/* GL_OES_vertex_array_object */ +#ifndef GL_OES_vertex_array_object +#define GL_OES_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glBindVertexArrayOES (GLuint array); +GL_APICALL void GL_APIENTRY glDeleteVertexArraysOES (GLsizei n, const GLuint *arrays); +GL_APICALL void GL_APIENTRY glGenVertexArraysOES (GLsizei n, GLuint *arrays); +GL_APICALL GLboolean GL_APIENTRY glIsVertexArrayOES (GLuint array); +#endif +typedef void (GL_APIENTRYP PFNGLBINDVERTEXARRAYOESPROC) (GLuint array); +typedef void (GL_APIENTRYP PFNGLDELETEVERTEXARRAYSOESPROC) (GLsizei n, const GLuint *arrays); +typedef void (GL_APIENTRYP PFNGLGENVERTEXARRAYSOESPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (GL_APIENTRYP PFNGLISVERTEXARRAYOESPROC) (GLuint array); +#endif + +/* GL_OES_vertex_half_float */ +#ifndef GL_OES_vertex_half_float +#define GL_OES_vertex_half_float 1 +#endif + +/* GL_OES_vertex_type_10_10_10_2 */ +#ifndef GL_OES_vertex_type_10_10_10_2 +#define GL_OES_vertex_type_10_10_10_2 1 +#endif + +/*------------------------------------------------------------------------* + * AMD extension functions + *------------------------------------------------------------------------*/ + +/* GL_AMD_compressed_3DC_texture */ +#ifndef GL_AMD_compressed_3DC_texture +#define GL_AMD_compressed_3DC_texture 1 +#endif + +/* GL_AMD_compressed_ATC_texture */ +#ifndef GL_AMD_compressed_ATC_texture +#define GL_AMD_compressed_ATC_texture 1 +#endif + +/* AMD_performance_monitor */ +#ifndef GL_AMD_performance_monitor +#define GL_AMD_performance_monitor 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glGetPerfMonitorGroupsAMD (GLint *numGroups, GLsizei groupsSize, GLuint *groups); +GL_APICALL void GL_APIENTRY glGetPerfMonitorCountersAMD (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); +GL_APICALL void GL_APIENTRY glGetPerfMonitorGroupStringAMD (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); +GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterStringAMD (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); +GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterInfoAMD (GLuint group, GLuint counter, GLenum pname, GLvoid *data); +GL_APICALL void GL_APIENTRY glGenPerfMonitorsAMD (GLsizei n, GLuint *monitors); +GL_APICALL void GL_APIENTRY glDeletePerfMonitorsAMD (GLsizei n, GLuint *monitors); +GL_APICALL void GL_APIENTRY glSelectPerfMonitorCountersAMD (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *countersList); +GL_APICALL void GL_APIENTRY glBeginPerfMonitorAMD (GLuint monitor); +GL_APICALL void GL_APIENTRY glEndPerfMonitorAMD (GLuint monitor); +GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterDataAMD (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); +#endif +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORGROUPSAMDPROC) (GLint *numGroups, GLsizei groupsSize, GLuint *groups); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERSAMDPROC) (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORGROUPSTRINGAMDPROC) (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERSTRINGAMDPROC) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERINFOAMDPROC) (GLuint group, GLuint counter, GLenum pname, GLvoid *data); +typedef void (GL_APIENTRYP PFNGLGENPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); +typedef void (GL_APIENTRYP PFNGLDELETEPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); +typedef void (GL_APIENTRYP PFNGLSELECTPERFMONITORCOUNTERSAMDPROC) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *countersList); +typedef void (GL_APIENTRYP PFNGLBEGINPERFMONITORAMDPROC) (GLuint monitor); +typedef void (GL_APIENTRYP PFNGLENDPERFMONITORAMDPROC) (GLuint monitor); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERDATAAMDPROC) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); +#endif + +/* GL_AMD_program_binary_Z400 */ +#ifndef GL_AMD_program_binary_Z400 +#define GL_AMD_program_binary_Z400 1 +#endif + +/*------------------------------------------------------------------------* + * EXT extension functions + *------------------------------------------------------------------------*/ + +/* GL_EXT_blend_minmax */ +#ifndef GL_EXT_blend_minmax +#define GL_EXT_blend_minmax 1 +#endif + +/* GL_EXT_discard_framebuffer */ +#ifndef GL_EXT_discard_framebuffer +#define GL_EXT_discard_framebuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glDiscardFramebufferEXT (GLenum target, GLsizei numAttachments, const GLenum *attachments); +#endif +typedef void (GL_APIENTRYP PFNGLDISCARDFRAMEBUFFEREXTPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); +#endif + +#ifndef GL_EXT_multi_draw_arrays +#define GL_EXT_multi_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glMultiDrawArraysEXT (GLenum, GLint *, GLsizei *, GLsizei); +GL_APICALL void GL_APIENTRY glMultiDrawElementsEXT (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (GL_APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); +typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +#endif + +/* GL_EXT_read_format_bgra */ +#ifndef GL_EXT_read_format_bgra +#define GL_EXT_read_format_bgra 1 +#endif + +/* GL_EXT_texture_filter_anisotropic */ +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_EXT_texture_filter_anisotropic 1 +#endif + +/* GL_EXT_texture_format_BGRA8888 */ +#ifndef GL_EXT_texture_format_BGRA8888 +#define GL_EXT_texture_format_BGRA8888 1 +#endif + +/* GL_EXT_texture_type_2_10_10_10_REV */ +#ifndef GL_EXT_texture_type_2_10_10_10_REV +#define GL_EXT_texture_type_2_10_10_10_REV 1 +#endif + +/* GL_EXT_texture_compression_dxt1 */ +#ifndef GL_EXT_texture_compression_dxt1 +#define GL_EXT_texture_compression_dxt1 1 +#endif + +/*------------------------------------------------------------------------* + * IMG extension functions + *------------------------------------------------------------------------*/ + +/* GL_IMG_program_binary */ +#ifndef GL_IMG_program_binary +#define GL_IMG_program_binary 1 +#endif + +/* GL_IMG_read_format */ +#ifndef GL_IMG_read_format +#define GL_IMG_read_format 1 +#endif + +/* GL_IMG_shader_binary */ +#ifndef GL_IMG_shader_binary +#define GL_IMG_shader_binary 1 +#endif + +/* GL_IMG_texture_compression_pvrtc */ +#ifndef GL_IMG_texture_compression_pvrtc +#define GL_IMG_texture_compression_pvrtc 1 +#endif + +/* GL_IMG_multisampled_render_to_texture */ +#ifndef GL_IMG_multisampled_render_to_texture +#define GL_IMG_multisampled_render_to_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleIMG (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +GL_APICALL void GL_APIENTRY glFramebufferTexture2DMultisampleIMG (GLenum, GLenum, GLenum, GLuint, GLint, GLsizei); +#endif +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMG) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLCLIPPLANEXIMG) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples); +#endif + +/*------------------------------------------------------------------------* + * NV extension functions + *------------------------------------------------------------------------*/ + +/* GL_NV_fence */ +#ifndef GL_NV_fence +#define GL_NV_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glDeleteFencesNV (GLsizei, const GLuint *); +GL_APICALL void GL_APIENTRY glGenFencesNV (GLsizei, GLuint *); +GL_APICALL GLboolean GL_APIENTRY glIsFenceNV (GLuint); +GL_APICALL GLboolean GL_APIENTRY glTestFenceNV (GLuint); +GL_APICALL void GL_APIENTRY glGetFenceivNV (GLuint, GLenum, GLint *); +GL_APICALL void GL_APIENTRY glFinishFenceNV (GLuint); +GL_APICALL void GL_APIENTRY glSetFenceNV (GLuint, GLenum); +#endif +typedef void (GL_APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences); +typedef void (GL_APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences); +typedef GLboolean (GL_APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); +typedef GLboolean (GL_APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); +typedef void (GL_APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); +typedef void (GL_APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition); +#endif + +/* GL_NV_coverage_sample */ +#ifndef GL_NV_coverage_sample +#define GL_NV_coverage_sample 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glCoverageMaskNV (GLboolean mask); +GL_APICALL void GL_APIENTRY glCoverageOperationNV (GLenum operation); +#endif +typedef void (GL_APIENTRYP PFNGLCOVERAGEMASKNVPROC) (GLboolean mask); +typedef void (GL_APIENTRYP PFNGLCOVERAGEOPERATIONNVPROC) (GLenum operation); +#endif + +/* GL_NV_depth_nonlinear */ +#ifndef GL_NV_depth_nonlinear +#define GL_NV_depth_nonlinear 1 +#endif + +/*------------------------------------------------------------------------* + * QCOM extension functions + *------------------------------------------------------------------------*/ + +/* GL_QCOM_driver_control */ +#ifndef GL_QCOM_driver_control +#define GL_QCOM_driver_control 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glGetDriverControlsQCOM (GLint *num, GLsizei size, GLuint *driverControls); +GL_APICALL void GL_APIENTRY glGetDriverControlStringQCOM (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString); +GL_APICALL void GL_APIENTRY glEnableDriverControlQCOM (GLuint driverControl); +GL_APICALL void GL_APIENTRY glDisableDriverControlQCOM (GLuint driverControl); +#endif +typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSQCOMPROC) (GLint *num, GLsizei size, GLuint *driverControls); +typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSTRINGQCOMPROC) (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString); +typedef void (GL_APIENTRYP PFNGLENABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl); +typedef void (GL_APIENTRYP PFNGLDISABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl); +#endif + +/* GL_QCOM_extended_get */ +#ifndef GL_QCOM_extended_get +#define GL_QCOM_extended_get 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glExtGetTexturesQCOM (GLuint *textures, GLint maxTextures, GLint *numTextures); +GL_APICALL void GL_APIENTRY glExtGetBuffersQCOM (GLuint *buffers, GLint maxBuffers, GLint *numBuffers); +GL_APICALL void GL_APIENTRY glExtGetRenderbuffersQCOM (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers); +GL_APICALL void GL_APIENTRY glExtGetFramebuffersQCOM (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers); +GL_APICALL void GL_APIENTRY glExtGetTexLevelParameterivQCOM (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params); +GL_APICALL void GL_APIENTRY glExtTexObjectStateOverrideiQCOM (GLenum target, GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glExtGetTexSubImageQCOM (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels); +GL_APICALL void GL_APIENTRY glExtGetBufferPointervQCOM (GLenum target, GLvoid **params); +#endif +typedef void (GL_APIENTRYP PFNGLEXTGETTEXTURESQCOMPROC) (GLuint *textures, GLint maxTextures, GLint *numTextures); +typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERSQCOMPROC) (GLuint *buffers, GLint maxBuffers, GLint *numBuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETRENDERBUFFERSQCOMPROC) (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETFRAMEBUFFERSQCOMPROC) (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETTEXLEVELPARAMETERIVQCOMPROC) (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLEXTTEXOBJECTSTATEOVERRIDEIQCOMPROC) (GLenum target, GLenum pname, GLint param); +typedef void (GL_APIENTRYP PFNGLEXTGETTEXSUBIMAGEQCOMPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels); +typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERPOINTERVQCOMPROC) (GLenum target, GLvoid **params); +#endif + +/* GL_QCOM_extended_get2 */ +#ifndef GL_QCOM_extended_get2 +#define GL_QCOM_extended_get2 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glExtGetShadersQCOM (GLuint *shaders, GLint maxShaders, GLint *numShaders); +GL_APICALL void GL_APIENTRY glExtGetProgramsQCOM (GLuint *programs, GLint maxPrograms, GLint *numPrograms); +GL_APICALL GLboolean GL_APIENTRY glExtIsProgramBinaryQCOM (GLuint program); +GL_APICALL void GL_APIENTRY glExtGetProgramBinarySourceQCOM (GLuint program, GLenum shadertype, GLchar *source, GLint *length); +#endif +typedef void (GL_APIENTRYP PFNGLEXTGETSHADERSQCOMPROC) (GLuint *shaders, GLint maxShaders, GLint *numShaders); +typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMSQCOMPROC) (GLuint *programs, GLint maxPrograms, GLint *numPrograms); +typedef GLboolean (GL_APIENTRYP PFNGLEXTISPROGRAMBINARYQCOMPROC) (GLuint program); +typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMBINARYSOURCEQCOMPROC) (GLuint program, GLenum shadertype, GLchar *source, GLint *length); +#endif + +/* GL_QCOM_perfmon_global_mode */ +#ifndef GL_QCOM_perfmon_global_mode +#define GL_QCOM_perfmon_global_mode 1 +#endif + +/* GL_QCOM_writeonly_rendering */ +#ifndef GL_QCOM_writeonly_rendering +#define GL_QCOM_writeonly_rendering 1 +#endif + +/* GL_QCOM_tiled_rendering */ +#ifndef GL_QCOM_tiled_rendering +#define GL_QCOM_tiled_rendering 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glStartTilingQCOM (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask); +GL_APICALL void GL_APIENTRY glEndTilingQCOM (GLbitfield preserveMask); +#endif +typedef void (GL_APIENTRYP PFNGLSTARTTILINGQCOMPROC) (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask); +typedef void (GL_APIENTRYP PFNGLENDTILINGQCOMPROC) (GLbitfield preserveMask); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __gl2ext_h_ */ diff --git a/include/GLES2/gl2platform.h b/include/GLES2/gl2platform.h new file mode 100644 index 0000000..c9fa3c4 --- /dev/null +++ b/include/GLES2/gl2platform.h @@ -0,0 +1,30 @@ +#ifndef __gl2platform_h_ +#define __gl2platform_h_ + +/* $Revision: 10602 $ on $Date:: 2010-03-04 22:35:34 -0800 #$ */ + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +/* Platform-specific types and definitions for OpenGL ES 2.X gl2.h + * + * Adopters may modify khrplatform.h and this file to suit their platform. + * You are encouraged to submit all modifications to the Khronos group so that + * they can be included in future versions of this file. Please submit changes + * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) + * by filing a bug against product "OpenGL-ES" component "Registry". + */ + +#include + +#ifndef GL_APICALL +#define GL_APICALL KHRONOS_APICALL +#endif + +#ifndef GL_APIENTRY +#define GL_APIENTRY KHRONOS_APIENTRY +#endif + +#endif /* __gl2platform_h_ */ diff --git a/include/KHR/khrplatform.h b/include/KHR/khrplatform.h new file mode 100644 index 0000000..4479539 --- /dev/null +++ b/include/KHR/khrplatform.h @@ -0,0 +1,277 @@ +#ifndef __khrplatform_h_ +#define __khrplatform_h_ + +/* +** Copyright (c) 2008-2009 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are 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 Materials. +** +** THE MATERIALS ARE 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 +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Khronos platform-specific types and definitions. + * + * $Revision: 9356 $ on $Date: 2009-10-21 02:52:25 -0700 (Wed, 21 Oct 2009) $ + * + * Adopters may modify this file to suit their platform. Adopters are + * encouraged to submit platform specific modifications to the Khronos + * group so that they can be included in future versions of this file. + * Please submit changes by sending them to the public Khronos Bugzilla + * (http://khronos.org/bugzilla) by filing a bug against product + * "Khronos (general)" component "Registry". + * + * A predefined template which fills in some of the bug fields can be + * reached using http://tinyurl.com/khrplatform-h-bugreport, but you + * must create a Bugzilla login first. + * + * + * See the Implementer's Guidelines for information about where this file + * should be located on your system and for more details of its use: + * http://www.khronos.org/registry/implementers_guide.pdf + * + * This file should be included as + * #include + * by Khronos client API header files that use its types and defines. + * + * The types in khrplatform.h should only be used to define API-specific types. + * + * Types defined in khrplatform.h: + * khronos_int8_t signed 8 bit + * khronos_uint8_t unsigned 8 bit + * khronos_int16_t signed 16 bit + * khronos_uint16_t unsigned 16 bit + * khronos_int32_t signed 32 bit + * khronos_uint32_t unsigned 32 bit + * khronos_int64_t signed 64 bit + * khronos_uint64_t unsigned 64 bit + * khronos_intptr_t signed same number of bits as a pointer + * khronos_uintptr_t unsigned same number of bits as a pointer + * khronos_ssize_t signed size + * khronos_usize_t unsigned size + * khronos_float_t signed 32 bit floating point + * khronos_time_ns_t unsigned 64 bit time in nanoseconds + * khronos_utime_nanoseconds_t unsigned time interval or absolute time in + * nanoseconds + * khronos_stime_nanoseconds_t signed time interval in nanoseconds + * khronos_boolean_enum_t enumerated boolean type. This should + * only be used as a base type when a client API's boolean type is + * an enum. Client APIs which use an integer or other type for + * booleans cannot use this as the base type for their boolean. + * + * Tokens defined in khrplatform.h: + * + * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values. + * + * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0. + * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0. + * + * Calling convention macros defined in this file: + * KHRONOS_APICALL + * KHRONOS_APIENTRY + * KHRONOS_APIATTRIBUTES + * + * These may be used in function prototypes as: + * + * KHRONOS_APICALL void KHRONOS_APIENTRY funcname( + * int arg1, + * int arg2) KHRONOS_APIATTRIBUTES; + */ + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APICALL + *------------------------------------------------------------------------- + * This precedes the return type of the function in the function prototype. + */ +#if defined(_WIN32) && !defined(__SCITECH_SNAP__) +# if defined(KHRONOS_DLL_EXPORTS) +# define KHRONOS_APICALL __declspec(dllexport) +# else +# define KHRONOS_APICALL __declspec(dllimport) +# endif +#elif defined (__SYMBIAN32__) +# define KHRONOS_APICALL IMPORT_C +#elif (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303) \ + || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +/* KHRONOS_APIATTRIBUTES is not used by the client API headers yet */ +# define KHRONOS_APICALL __attribute__((visibility("default"))) +#else +# define KHRONOS_APICALL +#endif + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APIENTRY + *------------------------------------------------------------------------- + * This follows the return type of the function and precedes the function + * name in the function prototype. + */ +#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) + /* Win32 but not WinCE */ +# define KHRONOS_APIENTRY __stdcall +#else +# define KHRONOS_APIENTRY +#endif + +/*------------------------------------------------------------------------- + * Definition of KHRONOS_APIATTRIBUTES + *------------------------------------------------------------------------- + * This follows the closing parenthesis of the function prototype arguments. + */ +#if defined (__ARMCC_2__) +#define KHRONOS_APIATTRIBUTES __softfp +#else +#define KHRONOS_APIATTRIBUTES +#endif + +/*------------------------------------------------------------------------- + * basic type definitions + *-----------------------------------------------------------------------*/ +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__) + + +/* + * Using + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(__VMS ) || defined(__sgi) + +/* + * Using + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(_WIN32) && !defined(__SCITECH_SNAP__) + +/* + * Win32 + */ +typedef __int32 khronos_int32_t; +typedef unsigned __int32 khronos_uint32_t; +typedef __int64 khronos_int64_t; +typedef unsigned __int64 khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif defined(__sun__) || defined(__digital__) + +/* + * Sun or Digital + */ +typedef int khronos_int32_t; +typedef unsigned int khronos_uint32_t; +#if defined(__arch64__) || defined(_LP64) +typedef long int khronos_int64_t; +typedef unsigned long int khronos_uint64_t; +#else +typedef long long int khronos_int64_t; +typedef unsigned long long int khronos_uint64_t; +#endif /* __arch64__ */ +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#elif 0 + +/* + * Hypothetical platform with no float or int64 support + */ +typedef int khronos_int32_t; +typedef unsigned int khronos_uint32_t; +#define KHRONOS_SUPPORT_INT64 0 +#define KHRONOS_SUPPORT_FLOAT 0 + +#else + +/* + * Generic fallback + */ +#include +typedef int32_t khronos_int32_t; +typedef uint32_t khronos_uint32_t; +typedef int64_t khronos_int64_t; +typedef uint64_t khronos_uint64_t; +#define KHRONOS_SUPPORT_INT64 1 +#define KHRONOS_SUPPORT_FLOAT 1 + +#endif + + +/* + * Types that are (so far) the same on all platforms + */ +typedef signed char khronos_int8_t; +typedef unsigned char khronos_uint8_t; +typedef signed short int khronos_int16_t; +typedef unsigned short int khronos_uint16_t; +typedef signed long int khronos_intptr_t; +typedef unsigned long int khronos_uintptr_t; +typedef signed long int khronos_ssize_t; +typedef unsigned long int khronos_usize_t; + +#if KHRONOS_SUPPORT_FLOAT +/* + * Float type + */ +typedef float khronos_float_t; +#endif + +#if KHRONOS_SUPPORT_INT64 +/* Time types + * + * These types can be used to represent a time interval in nanoseconds or + * an absolute Unadjusted System Time. Unadjusted System Time is the number + * of nanoseconds since some arbitrary system event (e.g. since the last + * time the system booted). The Unadjusted System Time is an unsigned + * 64 bit value that wraps back to 0 every 584 years. Time intervals + * may be either signed or unsigned. + */ +typedef khronos_uint64_t khronos_utime_nanoseconds_t; +typedef khronos_int64_t khronos_stime_nanoseconds_t; +#endif + +/* + * Dummy value used to pad enum types to 32 bits. + */ +#ifndef KHRONOS_MAX_ENUM +#define KHRONOS_MAX_ENUM 0x7FFFFFFF +#endif + +/* + * Enumerated boolean type + * + * Values other than zero should be considered to be true. Therefore + * comparisons should not be made against KHRONOS_TRUE. + */ +typedef enum { + KHRONOS_FALSE = 0, + KHRONOS_TRUE = 1, + KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM +} khronos_boolean_enum_t; + +#endif /* __khrplatform_h_ */ diff --git a/include/VG/openvg.h b/include/VG/openvg.h new file mode 100644 index 0000000..86d54d6 --- /dev/null +++ b/include/VG/openvg.h @@ -0,0 +1,746 @@ +/* $Revision: 9203 $ on $Date:: 2009-10-07 02:21:52 -0700 #$ */ + +/*------------------------------------------------------------------------ + * + * OpenVG 1.1 Reference Implementation + * ------------------------------------- + * + * Copyright (c) 2008 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and /or associated documentation files + * (the "Materials "), to deal in the Materials without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Materials, + * and to permit persons to whom the Materials are 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 Materials. + * + * THE MATERIALS ARE 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 MATERIALS OR + * THE USE OR OTHER DEALINGS IN THE MATERIALS. + * + *//** + * \file + * \brief OpenVG 1.1 API. + *//*-------------------------------------------------------------------*/ + +#ifndef _OPENVG_H +#define _OPENVG_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define OPENVG_VERSION_1_0 1 +#define OPENVG_VERSION_1_0_1 1 +#define OPENVG_VERSION_1_1 2 + +#ifndef VG_MAXSHORT +#define VG_MAXSHORT 0x7FFF +#endif + +#ifndef VG_MAXINT +#define VG_MAXINT 0x7FFFFFFF +#endif + +#ifndef VG_MAX_ENUM +#define VG_MAX_ENUM 0x7FFFFFFF +#endif + +typedef VGuint VGHandle; + +typedef VGHandle VGPath; +typedef VGHandle VGImage; +typedef VGHandle VGMaskLayer; +typedef VGHandle VGFont; +typedef VGHandle VGPaint; + +#define VG_INVALID_HANDLE ((VGHandle)0) + +typedef enum { + VG_FALSE = 0, + VG_TRUE = 1, + + VG_BOOLEAN_FORCE_SIZE = VG_MAX_ENUM +} VGboolean; + +typedef enum { + VG_NO_ERROR = 0, + VG_BAD_HANDLE_ERROR = 0x1000, + VG_ILLEGAL_ARGUMENT_ERROR = 0x1001, + VG_OUT_OF_MEMORY_ERROR = 0x1002, + VG_PATH_CAPABILITY_ERROR = 0x1003, + VG_UNSUPPORTED_IMAGE_FORMAT_ERROR = 0x1004, + VG_UNSUPPORTED_PATH_FORMAT_ERROR = 0x1005, + VG_IMAGE_IN_USE_ERROR = 0x1006, + VG_NO_CONTEXT_ERROR = 0x1007, + + VG_ERROR_CODE_FORCE_SIZE = VG_MAX_ENUM +} VGErrorCode; + +typedef enum { + /* Mode settings */ + VG_MATRIX_MODE = 0x1100, + VG_FILL_RULE = 0x1101, + VG_IMAGE_QUALITY = 0x1102, + VG_RENDERING_QUALITY = 0x1103, + VG_BLEND_MODE = 0x1104, + VG_IMAGE_MODE = 0x1105, + + /* Scissoring rectangles */ + VG_SCISSOR_RECTS = 0x1106, + + /* Color Transformation */ + VG_COLOR_TRANSFORM = 0x1170, + VG_COLOR_TRANSFORM_VALUES = 0x1171, + + /* Stroke parameters */ + VG_STROKE_LINE_WIDTH = 0x1110, + VG_STROKE_CAP_STYLE = 0x1111, + VG_STROKE_JOIN_STYLE = 0x1112, + VG_STROKE_MITER_LIMIT = 0x1113, + VG_STROKE_DASH_PATTERN = 0x1114, + VG_STROKE_DASH_PHASE = 0x1115, + VG_STROKE_DASH_PHASE_RESET = 0x1116, + + /* Edge fill color for VG_TILE_FILL tiling mode */ + VG_TILE_FILL_COLOR = 0x1120, + + /* Color for vgClear */ + VG_CLEAR_COLOR = 0x1121, + + /* Glyph origin */ + VG_GLYPH_ORIGIN = 0x1122, + + /* Enable/disable alpha masking and scissoring */ + VG_MASKING = 0x1130, + VG_SCISSORING = 0x1131, + + /* Pixel layout information */ + VG_PIXEL_LAYOUT = 0x1140, + VG_SCREEN_LAYOUT = 0x1141, + + /* Source format selection for image filters */ + VG_FILTER_FORMAT_LINEAR = 0x1150, + VG_FILTER_FORMAT_PREMULTIPLIED = 0x1151, + + /* Destination write enable mask for image filters */ + VG_FILTER_CHANNEL_MASK = 0x1152, + + /* Implementation limits (read-only) */ + VG_MAX_SCISSOR_RECTS = 0x1160, + VG_MAX_DASH_COUNT = 0x1161, + VG_MAX_KERNEL_SIZE = 0x1162, + VG_MAX_SEPARABLE_KERNEL_SIZE = 0x1163, + VG_MAX_COLOR_RAMP_STOPS = 0x1164, + VG_MAX_IMAGE_WIDTH = 0x1165, + VG_MAX_IMAGE_HEIGHT = 0x1166, + VG_MAX_IMAGE_PIXELS = 0x1167, + VG_MAX_IMAGE_BYTES = 0x1168, + VG_MAX_FLOAT = 0x1169, + VG_MAX_GAUSSIAN_STD_DEVIATION = 0x116A, + + VG_PARAM_TYPE_FORCE_SIZE = VG_MAX_ENUM +} VGParamType; + +typedef enum { + VG_RENDERING_QUALITY_NONANTIALIASED = 0x1200, + VG_RENDERING_QUALITY_FASTER = 0x1201, + VG_RENDERING_QUALITY_BETTER = 0x1202, /* Default */ + + VG_RENDERING_QUALITY_FORCE_SIZE = VG_MAX_ENUM +} VGRenderingQuality; + +typedef enum { + VG_PIXEL_LAYOUT_UNKNOWN = 0x1300, + VG_PIXEL_LAYOUT_RGB_VERTICAL = 0x1301, + VG_PIXEL_LAYOUT_BGR_VERTICAL = 0x1302, + VG_PIXEL_LAYOUT_RGB_HORIZONTAL = 0x1303, + VG_PIXEL_LAYOUT_BGR_HORIZONTAL = 0x1304, + + VG_PIXEL_LAYOUT_FORCE_SIZE = VG_MAX_ENUM +} VGPixelLayout; + +typedef enum { + VG_MATRIX_PATH_USER_TO_SURFACE = 0x1400, + VG_MATRIX_IMAGE_USER_TO_SURFACE = 0x1401, + VG_MATRIX_FILL_PAINT_TO_USER = 0x1402, + VG_MATRIX_STROKE_PAINT_TO_USER = 0x1403, + VG_MATRIX_GLYPH_USER_TO_SURFACE = 0x1404, + + VG_MATRIX_MODE_FORCE_SIZE = VG_MAX_ENUM +} VGMatrixMode; + +typedef enum { + VG_CLEAR_MASK = 0x1500, + VG_FILL_MASK = 0x1501, + VG_SET_MASK = 0x1502, + VG_UNION_MASK = 0x1503, + VG_INTERSECT_MASK = 0x1504, + VG_SUBTRACT_MASK = 0x1505, + + VG_MASK_OPERATION_FORCE_SIZE = VG_MAX_ENUM +} VGMaskOperation; + +#define VG_PATH_FORMAT_STANDARD 0 + +typedef enum { + VG_PATH_DATATYPE_S_8 = 0, + VG_PATH_DATATYPE_S_16 = 1, + VG_PATH_DATATYPE_S_32 = 2, + VG_PATH_DATATYPE_F = 3, + + VG_PATH_DATATYPE_FORCE_SIZE = VG_MAX_ENUM +} VGPathDatatype; + +typedef enum { + VG_ABSOLUTE = 0, + VG_RELATIVE = 1, + + VG_PATH_ABS_REL_FORCE_SIZE = VG_MAX_ENUM +} VGPathAbsRel; + +typedef enum { + VG_CLOSE_PATH = ( 0 << 1), + VG_MOVE_TO = ( 1 << 1), + VG_LINE_TO = ( 2 << 1), + VG_HLINE_TO = ( 3 << 1), + VG_VLINE_TO = ( 4 << 1), + VG_QUAD_TO = ( 5 << 1), + VG_CUBIC_TO = ( 6 << 1), + VG_SQUAD_TO = ( 7 << 1), + VG_SCUBIC_TO = ( 8 << 1), + VG_SCCWARC_TO = ( 9 << 1), + VG_SCWARC_TO = (10 << 1), + VG_LCCWARC_TO = (11 << 1), + VG_LCWARC_TO = (12 << 1), + + VG_PATH_SEGMENT_FORCE_SIZE = VG_MAX_ENUM +} VGPathSegment; + +typedef enum { + VG_MOVE_TO_ABS = VG_MOVE_TO | VG_ABSOLUTE, + VG_MOVE_TO_REL = VG_MOVE_TO | VG_RELATIVE, + VG_LINE_TO_ABS = VG_LINE_TO | VG_ABSOLUTE, + VG_LINE_TO_REL = VG_LINE_TO | VG_RELATIVE, + VG_HLINE_TO_ABS = VG_HLINE_TO | VG_ABSOLUTE, + VG_HLINE_TO_REL = VG_HLINE_TO | VG_RELATIVE, + VG_VLINE_TO_ABS = VG_VLINE_TO | VG_ABSOLUTE, + VG_VLINE_TO_REL = VG_VLINE_TO | VG_RELATIVE, + VG_QUAD_TO_ABS = VG_QUAD_TO | VG_ABSOLUTE, + VG_QUAD_TO_REL = VG_QUAD_TO | VG_RELATIVE, + VG_CUBIC_TO_ABS = VG_CUBIC_TO | VG_ABSOLUTE, + VG_CUBIC_TO_REL = VG_CUBIC_TO | VG_RELATIVE, + VG_SQUAD_TO_ABS = VG_SQUAD_TO | VG_ABSOLUTE, + VG_SQUAD_TO_REL = VG_SQUAD_TO | VG_RELATIVE, + VG_SCUBIC_TO_ABS = VG_SCUBIC_TO | VG_ABSOLUTE, + VG_SCUBIC_TO_REL = VG_SCUBIC_TO | VG_RELATIVE, + VG_SCCWARC_TO_ABS = VG_SCCWARC_TO | VG_ABSOLUTE, + VG_SCCWARC_TO_REL = VG_SCCWARC_TO | VG_RELATIVE, + VG_SCWARC_TO_ABS = VG_SCWARC_TO | VG_ABSOLUTE, + VG_SCWARC_TO_REL = VG_SCWARC_TO | VG_RELATIVE, + VG_LCCWARC_TO_ABS = VG_LCCWARC_TO | VG_ABSOLUTE, + VG_LCCWARC_TO_REL = VG_LCCWARC_TO | VG_RELATIVE, + VG_LCWARC_TO_ABS = VG_LCWARC_TO | VG_ABSOLUTE, + VG_LCWARC_TO_REL = VG_LCWARC_TO | VG_RELATIVE, + + VG_PATH_COMMAND_FORCE_SIZE = VG_MAX_ENUM +} VGPathCommand; + +typedef enum { + VG_PATH_CAPABILITY_APPEND_FROM = (1 << 0), + VG_PATH_CAPABILITY_APPEND_TO = (1 << 1), + VG_PATH_CAPABILITY_MODIFY = (1 << 2), + VG_PATH_CAPABILITY_TRANSFORM_FROM = (1 << 3), + VG_PATH_CAPABILITY_TRANSFORM_TO = (1 << 4), + VG_PATH_CAPABILITY_INTERPOLATE_FROM = (1 << 5), + VG_PATH_CAPABILITY_INTERPOLATE_TO = (1 << 6), + VG_PATH_CAPABILITY_PATH_LENGTH = (1 << 7), + VG_PATH_CAPABILITY_POINT_ALONG_PATH = (1 << 8), + VG_PATH_CAPABILITY_TANGENT_ALONG_PATH = (1 << 9), + VG_PATH_CAPABILITY_PATH_BOUNDS = (1 << 10), + VG_PATH_CAPABILITY_PATH_TRANSFORMED_BOUNDS = (1 << 11), + VG_PATH_CAPABILITY_ALL = (1 << 12) - 1, + + VG_PATH_CAPABILITIES_FORCE_SIZE = VG_MAX_ENUM +} VGPathCapabilities; + +typedef enum { + VG_PATH_FORMAT = 0x1600, + VG_PATH_DATATYPE = 0x1601, + VG_PATH_SCALE = 0x1602, + VG_PATH_BIAS = 0x1603, + VG_PATH_NUM_SEGMENTS = 0x1604, + VG_PATH_NUM_COORDS = 0x1605, + + VG_PATH_PARAM_TYPE_FORCE_SIZE = VG_MAX_ENUM +} VGPathParamType; + +typedef enum { + VG_CAP_BUTT = 0x1700, + VG_CAP_ROUND = 0x1701, + VG_CAP_SQUARE = 0x1702, + + VG_CAP_STYLE_FORCE_SIZE = VG_MAX_ENUM +} VGCapStyle; + +typedef enum { + VG_JOIN_MITER = 0x1800, + VG_JOIN_ROUND = 0x1801, + VG_JOIN_BEVEL = 0x1802, + + VG_JOIN_STYLE_FORCE_SIZE = VG_MAX_ENUM +} VGJoinStyle; + +typedef enum { + VG_EVEN_ODD = 0x1900, + VG_NON_ZERO = 0x1901, + + VG_FILL_RULE_FORCE_SIZE = VG_MAX_ENUM +} VGFillRule; + +typedef enum { + VG_STROKE_PATH = (1 << 0), + VG_FILL_PATH = (1 << 1), + + VG_PAINT_MODE_FORCE_SIZE = VG_MAX_ENUM +} VGPaintMode; + +typedef enum { + /* Color paint parameters */ + VG_PAINT_TYPE = 0x1A00, + VG_PAINT_COLOR = 0x1A01, + VG_PAINT_COLOR_RAMP_SPREAD_MODE = 0x1A02, + VG_PAINT_COLOR_RAMP_PREMULTIPLIED = 0x1A07, + VG_PAINT_COLOR_RAMP_STOPS = 0x1A03, + + /* Linear gradient paint parameters */ + VG_PAINT_LINEAR_GRADIENT = 0x1A04, + + /* Radial gradient paint parameters */ + VG_PAINT_RADIAL_GRADIENT = 0x1A05, + + /* Pattern paint parameters */ + VG_PAINT_PATTERN_TILING_MODE = 0x1A06, + + VG_PAINT_PARAM_TYPE_FORCE_SIZE = VG_MAX_ENUM +} VGPaintParamType; + +typedef enum { + VG_PAINT_TYPE_COLOR = 0x1B00, + VG_PAINT_TYPE_LINEAR_GRADIENT = 0x1B01, + VG_PAINT_TYPE_RADIAL_GRADIENT = 0x1B02, + VG_PAINT_TYPE_PATTERN = 0x1B03, + + VG_PAINT_TYPE_FORCE_SIZE = VG_MAX_ENUM +} VGPaintType; + +typedef enum { + VG_COLOR_RAMP_SPREAD_PAD = 0x1C00, + VG_COLOR_RAMP_SPREAD_REPEAT = 0x1C01, + VG_COLOR_RAMP_SPREAD_REFLECT = 0x1C02, + + VG_COLOR_RAMP_SPREAD_MODE_FORCE_SIZE = VG_MAX_ENUM +} VGColorRampSpreadMode; + +typedef enum { + VG_TILE_FILL = 0x1D00, + VG_TILE_PAD = 0x1D01, + VG_TILE_REPEAT = 0x1D02, + VG_TILE_REFLECT = 0x1D03, + + VG_TILING_MODE_FORCE_SIZE = VG_MAX_ENUM +} VGTilingMode; + +typedef enum { + /* RGB{A,X} channel ordering */ + VG_sRGBX_8888 = 0, + VG_sRGBA_8888 = 1, + VG_sRGBA_8888_PRE = 2, + VG_sRGB_565 = 3, + VG_sRGBA_5551 = 4, + VG_sRGBA_4444 = 5, + VG_sL_8 = 6, + VG_lRGBX_8888 = 7, + VG_lRGBA_8888 = 8, + VG_lRGBA_8888_PRE = 9, + VG_lL_8 = 10, + VG_A_8 = 11, + VG_BW_1 = 12, + VG_A_1 = 13, + VG_A_4 = 14, + + /* {A,X}RGB channel ordering */ + VG_sXRGB_8888 = 0 | (1 << 6), + VG_sARGB_8888 = 1 | (1 << 6), + VG_sARGB_8888_PRE = 2 | (1 << 6), + VG_sARGB_1555 = 4 | (1 << 6), + VG_sARGB_4444 = 5 | (1 << 6), + VG_lXRGB_8888 = 7 | (1 << 6), + VG_lARGB_8888 = 8 | (1 << 6), + VG_lARGB_8888_PRE = 9 | (1 << 6), + + /* BGR{A,X} channel ordering */ + VG_sBGRX_8888 = 0 | (1 << 7), + VG_sBGRA_8888 = 1 | (1 << 7), + VG_sBGRA_8888_PRE = 2 | (1 << 7), + VG_sBGR_565 = 3 | (1 << 7), + VG_sBGRA_5551 = 4 | (1 << 7), + VG_sBGRA_4444 = 5 | (1 << 7), + VG_lBGRX_8888 = 7 | (1 << 7), + VG_lBGRA_8888 = 8 | (1 << 7), + VG_lBGRA_8888_PRE = 9 | (1 << 7), + + /* {A,X}BGR channel ordering */ + VG_sXBGR_8888 = 0 | (1 << 6) | (1 << 7), + VG_sABGR_8888 = 1 | (1 << 6) | (1 << 7), + VG_sABGR_8888_PRE = 2 | (1 << 6) | (1 << 7), + VG_sABGR_1555 = 4 | (1 << 6) | (1 << 7), + VG_sABGR_4444 = 5 | (1 << 6) | (1 << 7), + VG_lXBGR_8888 = 7 | (1 << 6) | (1 << 7), + VG_lABGR_8888 = 8 | (1 << 6) | (1 << 7), + VG_lABGR_8888_PRE = 9 | (1 << 6) | (1 << 7), + + VG_IMAGE_FORMAT_FORCE_SIZE = VG_MAX_ENUM +} VGImageFormat; + +typedef enum { + VG_IMAGE_QUALITY_NONANTIALIASED = (1 << 0), + VG_IMAGE_QUALITY_FASTER = (1 << 1), + VG_IMAGE_QUALITY_BETTER = (1 << 2), + + VG_IMAGE_QUALITY_FORCE_SIZE = VG_MAX_ENUM +} VGImageQuality; + +typedef enum { + VG_IMAGE_FORMAT = 0x1E00, + VG_IMAGE_WIDTH = 0x1E01, + VG_IMAGE_HEIGHT = 0x1E02, + + VG_IMAGE_PARAM_TYPE_FORCE_SIZE = VG_MAX_ENUM +} VGImageParamType; + +typedef enum { + VG_DRAW_IMAGE_NORMAL = 0x1F00, + VG_DRAW_IMAGE_MULTIPLY = 0x1F01, + VG_DRAW_IMAGE_STENCIL = 0x1F02, + + VG_IMAGE_MODE_FORCE_SIZE = VG_MAX_ENUM +} VGImageMode; + +typedef enum { + VG_RED = (1 << 3), + VG_GREEN = (1 << 2), + VG_BLUE = (1 << 1), + VG_ALPHA = (1 << 0), + + VG_IMAGE_CHANNEL_FORCE_SIZE = VG_MAX_ENUM +} VGImageChannel; + +typedef enum { + VG_BLEND_SRC = 0x2000, + VG_BLEND_SRC_OVER = 0x2001, + VG_BLEND_DST_OVER = 0x2002, + VG_BLEND_SRC_IN = 0x2003, + VG_BLEND_DST_IN = 0x2004, + VG_BLEND_MULTIPLY = 0x2005, + VG_BLEND_SCREEN = 0x2006, + VG_BLEND_DARKEN = 0x2007, + VG_BLEND_LIGHTEN = 0x2008, + VG_BLEND_ADDITIVE = 0x2009, + + VG_BLEND_MODE_FORCE_SIZE = VG_MAX_ENUM +} VGBlendMode; + +typedef enum { + VG_FONT_NUM_GLYPHS = 0x2F00, + + VG_FONT_PARAM_TYPE_FORCE_SIZE = VG_MAX_ENUM +} VGFontParamType; + +typedef enum { + VG_IMAGE_FORMAT_QUERY = 0x2100, + VG_PATH_DATATYPE_QUERY = 0x2101, + + VG_HARDWARE_QUERY_TYPE_FORCE_SIZE = VG_MAX_ENUM +} VGHardwareQueryType; + +typedef enum { + VG_HARDWARE_ACCELERATED = 0x2200, + VG_HARDWARE_UNACCELERATED = 0x2201, + + VG_HARDWARE_QUERY_RESULT_FORCE_SIZE = VG_MAX_ENUM +} VGHardwareQueryResult; + +typedef enum { + VG_VENDOR = 0x2300, + VG_RENDERER = 0x2301, + VG_VERSION = 0x2302, + VG_EXTENSIONS = 0x2303, + + VG_STRING_ID_FORCE_SIZE = VG_MAX_ENUM +} VGStringID; + +/* Function Prototypes */ + +#ifndef VG_API_CALL +# error VG_API_CALL must be defined +#endif + +#ifndef VG_API_ENTRY +# error VG_API_ENTRY must be defined +#endif + +#ifndef VG_API_EXIT +# error VG_API_EXIT must be defined +#endif + +VG_API_CALL VGErrorCode VG_API_ENTRY vgGetError(void) VG_API_EXIT; + +VG_API_CALL void VG_API_ENTRY vgFlush(void) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgFinish(void) VG_API_EXIT; + +/* Getters and Setters */ +VG_API_CALL void VG_API_ENTRY vgSetf (VGParamType type, VGfloat value) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgSeti (VGParamType type, VGint value) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgSetfv(VGParamType type, VGint count, + const VGfloat * values) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgSetiv(VGParamType type, VGint count, + const VGint * values) VG_API_EXIT; + +VG_API_CALL VGfloat VG_API_ENTRY vgGetf(VGParamType type) VG_API_EXIT; +VG_API_CALL VGint VG_API_ENTRY vgGeti(VGParamType type) VG_API_EXIT; +VG_API_CALL VGint VG_API_ENTRY vgGetVectorSize(VGParamType type) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgGetfv(VGParamType type, VGint count, VGfloat * values) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgGetiv(VGParamType type, VGint count, VGint * values) VG_API_EXIT; + +VG_API_CALL void VG_API_ENTRY vgSetParameterf(VGHandle object, + VGint paramType, + VGfloat value) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgSetParameteri(VGHandle object, + VGint paramType, + VGint value) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgSetParameterfv(VGHandle object, + VGint paramType, + VGint count, const VGfloat * values) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgSetParameteriv(VGHandle object, + VGint paramType, + VGint count, const VGint * values) VG_API_EXIT; + +VG_API_CALL VGfloat VG_API_ENTRY vgGetParameterf(VGHandle object, + VGint paramType) VG_API_EXIT; +VG_API_CALL VGint VG_API_ENTRY vgGetParameteri(VGHandle object, + VGint paramType); +VG_API_CALL VGint VG_API_ENTRY vgGetParameterVectorSize(VGHandle object, + VGint paramType) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgGetParameterfv(VGHandle object, + VGint paramType, + VGint count, VGfloat * values) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgGetParameteriv(VGHandle object, + VGint paramType, + VGint count, VGint * values) VG_API_EXIT; + +/* Matrix Manipulation */ +VG_API_CALL void VG_API_ENTRY vgLoadIdentity(void) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgLoadMatrix(const VGfloat * m) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgGetMatrix(VGfloat * m) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgMultMatrix(const VGfloat * m) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgTranslate(VGfloat tx, VGfloat ty) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgScale(VGfloat sx, VGfloat sy) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgShear(VGfloat shx, VGfloat shy) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgRotate(VGfloat angle) VG_API_EXIT; + +/* Masking and Clearing */ +VG_API_CALL void VG_API_ENTRY vgMask(VGHandle mask, VGMaskOperation operation, + VGint x, VGint y, + VGint width, VGint height) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgRenderToMask(VGPath path, + VGbitfield paintModes, + VGMaskOperation operation) VG_API_EXIT; +VG_API_CALL VGMaskLayer VG_API_ENTRY vgCreateMaskLayer(VGint width, VGint height) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgDestroyMaskLayer(VGMaskLayer maskLayer) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgFillMaskLayer(VGMaskLayer maskLayer, + VGint x, VGint y, + VGint width, VGint height, + VGfloat value) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgCopyMask(VGMaskLayer maskLayer, + VGint dx, VGint dy, + VGint sx, VGint sy, + VGint width, VGint height) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgClear(VGint x, VGint y, VGint width, VGint height) VG_API_EXIT; + +/* Paths */ +VG_API_CALL VGPath VG_API_ENTRY vgCreatePath(VGint pathFormat, + VGPathDatatype datatype, + VGfloat scale, VGfloat bias, + VGint segmentCapacityHint, + VGint coordCapacityHint, + VGbitfield capabilities) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgClearPath(VGPath path, VGbitfield capabilities) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgDestroyPath(VGPath path) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgRemovePathCapabilities(VGPath path, + VGbitfield capabilities) VG_API_EXIT; +VG_API_CALL VGbitfield VG_API_ENTRY vgGetPathCapabilities(VGPath path) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgAppendPath(VGPath dstPath, VGPath srcPath) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgAppendPathData(VGPath dstPath, + VGint numSegments, + const VGubyte * pathSegments, + const void * pathData) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgModifyPathCoords(VGPath dstPath, VGint startIndex, + VGint numSegments, + const void * pathData) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgTransformPath(VGPath dstPath, VGPath srcPath) VG_API_EXIT; +VG_API_CALL VGboolean VG_API_ENTRY vgInterpolatePath(VGPath dstPath, + VGPath startPath, + VGPath endPath, + VGfloat amount) VG_API_EXIT; +VG_API_CALL VGfloat VG_API_ENTRY vgPathLength(VGPath path, + VGint startSegment, VGint numSegments) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgPointAlongPath(VGPath path, + VGint startSegment, VGint numSegments, + VGfloat distance, + VGfloat * x, VGfloat * y, + VGfloat * tangentX, VGfloat * tangentY) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgPathBounds(VGPath path, + VGfloat * minX, VGfloat * minY, + VGfloat * width, VGfloat * height) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgPathTransformedBounds(VGPath path, + VGfloat * minX, VGfloat * minY, + VGfloat * width, VGfloat * height) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgDrawPath(VGPath path, VGbitfield paintModes) VG_API_EXIT; + +/* Paint */ +VG_API_CALL VGPaint VG_API_ENTRY vgCreatePaint(void) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgDestroyPaint(VGPaint paint) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgSetPaint(VGPaint paint, VGbitfield paintModes) VG_API_EXIT; +VG_API_CALL VGPaint VG_API_ENTRY vgGetPaint(VGPaintMode paintMode) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgSetColor(VGPaint paint, VGuint rgba) VG_API_EXIT; +VG_API_CALL VGuint VG_API_ENTRY vgGetColor(VGPaint paint) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgPaintPattern(VGPaint paint, VGImage pattern) VG_API_EXIT; + +/* Images */ +VG_API_CALL VGImage VG_API_ENTRY vgCreateImage(VGImageFormat format, + VGint width, VGint height, + VGbitfield allowedQuality) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgDestroyImage(VGImage image) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgClearImage(VGImage image, + VGint x, VGint y, VGint width, VGint height) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgImageSubData(VGImage image, + const void * data, VGint dataStride, + VGImageFormat dataFormat, + VGint x, VGint y, VGint width, VGint height) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgGetImageSubData(VGImage image, + void * data, VGint dataStride, + VGImageFormat dataFormat, + VGint x, VGint y, + VGint width, VGint height) VG_API_EXIT; +VG_API_CALL VGImage VG_API_ENTRY vgChildImage(VGImage parent, + VGint x, VGint y, VGint width, VGint height) VG_API_EXIT; +VG_API_CALL VGImage VG_API_ENTRY vgGetParent(VGImage image) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgCopyImage(VGImage dst, VGint dx, VGint dy, + VGImage src, VGint sx, VGint sy, + VGint width, VGint height, + VGboolean dither) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgDrawImage(VGImage image) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgSetPixels(VGint dx, VGint dy, + VGImage src, VGint sx, VGint sy, + VGint width, VGint height) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgWritePixels(const void * data, VGint dataStride, + VGImageFormat dataFormat, + VGint dx, VGint dy, + VGint width, VGint height) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgGetPixels(VGImage dst, VGint dx, VGint dy, + VGint sx, VGint sy, + VGint width, VGint height) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgReadPixels(void * data, VGint dataStride, + VGImageFormat dataFormat, + VGint sx, VGint sy, + VGint width, VGint height) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgCopyPixels(VGint dx, VGint dy, + VGint sx, VGint sy, + VGint width, VGint height) VG_API_EXIT; + +/* Text */ +VG_API_CALL VGFont VG_API_ENTRY vgCreateFont(VGint glyphCapacityHint) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgDestroyFont(VGFont font) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgSetGlyphToPath(VGFont font, + VGuint glyphIndex, + VGPath path, + VGboolean isHinted, + const VGfloat glyphOrigin [2], + const VGfloat escapement[2]) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgSetGlyphToImage(VGFont font, + VGuint glyphIndex, + VGImage image, + const VGfloat glyphOrigin [2], + const VGfloat escapement[2]) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgClearGlyph(VGFont font,VGuint glyphIndex) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgDrawGlyph(VGFont font, + VGuint glyphIndex, + VGbitfield paintModes, + VGboolean allowAutoHinting) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgDrawGlyphs(VGFont font, + VGint glyphCount, + const VGuint *glyphIndices, + const VGfloat *adjustments_x, + const VGfloat *adjustments_y, + VGbitfield paintModes, + VGboolean allowAutoHinting) VG_API_EXIT; + +/* Image Filters */ +VG_API_CALL void VG_API_ENTRY vgColorMatrix(VGImage dst, VGImage src, + const VGfloat * matrix) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgConvolve(VGImage dst, VGImage src, + VGint kernelWidth, VGint kernelHeight, + VGint shiftX, VGint shiftY, + const VGshort * kernel, + VGfloat scale, + VGfloat bias, + VGTilingMode tilingMode) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgSeparableConvolve(VGImage dst, VGImage src, + VGint kernelWidth, + VGint kernelHeight, + VGint shiftX, VGint shiftY, + const VGshort * kernelX, + const VGshort * kernelY, + VGfloat scale, + VGfloat bias, + VGTilingMode tilingMode) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgGaussianBlur(VGImage dst, VGImage src, + VGfloat stdDeviationX, + VGfloat stdDeviationY, + VGTilingMode tilingMode) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgLookup(VGImage dst, VGImage src, + const VGubyte * redLUT, + const VGubyte * greenLUT, + const VGubyte * blueLUT, + const VGubyte * alphaLUT, + VGboolean outputLinear, + VGboolean outputPremultiplied) VG_API_EXIT; +VG_API_CALL void VG_API_ENTRY vgLookupSingle(VGImage dst, VGImage src, + const VGuint * lookupTable, + VGImageChannel sourceChannel, + VGboolean outputLinear, + VGboolean outputPremultiplied) VG_API_EXIT; + +/* Hardware Queries */ +VG_API_CALL VGHardwareQueryResult VG_API_ENTRY vgHardwareQuery(VGHardwareQueryType key, + VGint setting) VG_API_EXIT; + +/* Renderer and Extension Information */ +VG_API_CALL const VGubyte * VG_API_ENTRY vgGetString(VGStringID name) VG_API_EXIT; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* _OPENVG_H */ diff --git a/include/VG/vgext.h b/include/VG/vgext.h new file mode 100644 index 0000000..9ff3234 --- /dev/null +++ b/include/VG/vgext.h @@ -0,0 +1,233 @@ +/* $Revision: 6810 $ on $Date:: 2008-10-29 07:31:37 -0700 #$ */ + +/*------------------------------------------------------------------------ + * + * VG extensions Reference Implementation + * ------------------------------------- + * + * Copyright (c) 2008 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and /or associated documentation files + * (the "Materials "), to deal in the Materials without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Materials, + * and to permit persons to whom the Materials are 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 Materials. + * + * THE MATERIALS ARE 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 MATERIALS OR + * THE USE OR OTHER DEALINGS IN THE MATERIALS. + * + *//** + * \file + * \brief VG extensions + *//*-------------------------------------------------------------------*/ + + + +#ifndef _VGEXT_H +#define _VGEXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifndef VG_API_ENTRYP +# define VG_API_ENTRYP VG_API_ENTRY* +#endif + +#ifndef VGU_API_ENTRYP +# define VGU_API_ENTRYP VGU_API_ENTRY* +#endif + +/*------------------------------------------------------------------------------- + * KHR extensions + *------------------------------------------------------------------------------*/ + +typedef enum { + +#ifndef VG_KHR_iterative_average_blur + VG_MAX_AVERAGE_BLUR_DIMENSION_KHR = 0x116B, + VG_AVERAGE_BLUR_DIMENSION_RESOLUTION_KHR = 0x116C, + VG_MAX_AVERAGE_BLUR_ITERATIONS_KHR = 0x116D, +#endif + + VG_PARAM_TYPE_KHR_FORCE_SIZE = VG_MAX_ENUM +} VGParamTypeKHR; + +#ifndef VG_KHR_EGL_image +#define VG_KHR_EGL_image 1 +/* VGEGLImageKHR is an opaque handle to an EGLImage */ +typedef void* VGeglImageKHR; + +#ifdef VG_VGEXT_PROTOTYPES +VG_API_CALL VGImage VG_API_ENTRY vgCreateEGLImageTargetKHR(VGeglImageKHR image); +#endif +typedef VGImage (VG_API_ENTRYP PFNVGCREATEEGLIMAGETARGETKHRPROC) (VGeglImageKHR image); + +#endif + + +#ifndef VG_KHR_iterative_average_blur +#define VG_KHR_iterative_average_blur 1 + +#ifdef VG_VGEXT_PROTOTYPES +VG_API_CALL void vgIterativeAverageBlurKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGTilingMode tilingMode); +#endif +typedef void (VG_API_ENTRYP PFNVGITERATIVEAVERAGEBLURKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGTilingMode tilingMode); + +#endif + + +#ifndef VG_KHR_advanced_blending +#define VG_KHR_advanced_blending 1 + +typedef enum { + VG_BLEND_OVERLAY_KHR = 0x2010, + VG_BLEND_HARDLIGHT_KHR = 0x2011, + VG_BLEND_SOFTLIGHT_SVG_KHR = 0x2012, + VG_BLEND_SOFTLIGHT_KHR = 0x2013, + VG_BLEND_COLORDODGE_KHR = 0x2014, + VG_BLEND_COLORBURN_KHR = 0x2015, + VG_BLEND_DIFFERENCE_KHR = 0x2016, + VG_BLEND_SUBTRACT_KHR = 0x2017, + VG_BLEND_INVERT_KHR = 0x2018, + VG_BLEND_EXCLUSION_KHR = 0x2019, + VG_BLEND_LINEARDODGE_KHR = 0x201a, + VG_BLEND_LINEARBURN_KHR = 0x201b, + VG_BLEND_VIVIDLIGHT_KHR = 0x201c, + VG_BLEND_LINEARLIGHT_KHR = 0x201d, + VG_BLEND_PINLIGHT_KHR = 0x201e, + VG_BLEND_HARDMIX_KHR = 0x201f, + VG_BLEND_CLEAR_KHR = 0x2020, + VG_BLEND_DST_KHR = 0x2021, + VG_BLEND_SRC_OUT_KHR = 0x2022, + VG_BLEND_DST_OUT_KHR = 0x2023, + VG_BLEND_SRC_ATOP_KHR = 0x2024, + VG_BLEND_DST_ATOP_KHR = 0x2025, + VG_BLEND_XOR_KHR = 0x2026, + + VG_BLEND_MODE_KHR_FORCE_SIZE= VG_MAX_ENUM +} VGBlendModeKHR; +#endif + +#ifndef VG_KHR_parametric_filter +#define VG_KHR_parametric_filter 1 + +typedef enum { + VG_PF_OBJECT_VISIBLE_FLAG_KHR = (1 << 0), + VG_PF_KNOCKOUT_FLAG_KHR = (1 << 1), + VG_PF_OUTER_FLAG_KHR = (1 << 2), + VG_PF_INNER_FLAG_KHR = (1 << 3), + + VG_PF_TYPE_KHR_FORCE_SIZE = VG_MAX_ENUM +} VGPfTypeKHR; + +typedef enum { + VGU_IMAGE_IN_USE_ERROR = 0xF010, + + VGU_ERROR_CODE_KHR_FORCE_SIZE = VG_MAX_ENUM +} VGUErrorCodeKHR; + +#ifdef VG_VGEXT_PROTOTYPES +VG_API_CALL void VG_API_ENTRY vgParametricFilterKHR(VGImage dst,VGImage src,VGImage blur,VGfloat strength,VGfloat offsetX,VGfloat offsetY,VGbitfield filterFlags,VGPaint highlightPaint,VGPaint shadowPaint); +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguDropShadowKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint shadowColorRGBA); +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguGlowKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint glowColorRGBA) ; +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguBevelKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint highlightColorRGBA,VGuint shadowColorRGBA); +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguGradientGlowKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* glowColorRampStops); +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguGradientBevelKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* bevelColorRampStops); +#endif +typedef void (VG_API_ENTRYP PFNVGPARAMETRICFILTERKHRPROC) (VGImage dst,VGImage src,VGImage blur,VGfloat strength,VGfloat offsetX,VGfloat offsetY,VGbitfield filterFlags,VGPaint highlightPaint,VGPaint shadowPaint); +typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUDROPSHADOWKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint shadowColorRGBA); +typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUGLOWKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint glowColorRGBA); +typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUBEVELKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint highlightColorRGBA,VGuint shadowColorRGBA); +typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUGRADIENTGLOWKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* glowColorRampStops); +typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUGRADIENTBEVELKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* bevelColorRampStops); + +#endif + + +/*------------------------------------------------------------------------------- + * NDS extensions + *------------------------------------------------------------------------------*/ + +#ifndef VG_NDS_paint_generation +#define VG_NDS_paint_generation 1 + +typedef enum { + VG_PAINT_COLOR_RAMP_LINEAR_NDS = 0x1A10, + VG_COLOR_MATRIX_NDS = 0x1A11, + VG_PAINT_COLOR_TRANSFORM_LINEAR_NDS = 0x1A12, + + VG_PAINT_PARAM_TYPE_NDS_FORCE_SIZE = VG_MAX_ENUM +} VGPaintParamTypeNds; + +typedef enum { + VG_DRAW_IMAGE_COLOR_MATRIX_NDS = 0x1F10, + + VG_IMAGE_MODE_NDS_FORCE_SIZE = VG_MAX_ENUM +} VGImageModeNds; +#endif + + +#ifndef VG_NDS_projective_geometry +#define VG_NDS_projective_geometry 1 + +typedef enum { + VG_CLIP_MODE_NDS = 0x1180, + VG_CLIP_LINES_NDS = 0x1181, + VG_MAX_CLIP_LINES_NDS = 0x1182, + + VG_PARAM_TYPE_NDS_FORCE_SIZE = VG_MAX_ENUM +} VGParamTypeNds; + +typedef enum { + VG_CLIPMODE_NONE_NDS = 0x3000, + VG_CLIPMODE_CLIP_CLOSED_NDS = 0x3001, + VG_CLIPMODE_CLIP_OPEN_NDS = 0x3002, + VG_CLIPMODE_CULL_NDS = 0x3003, + + VG_CLIPMODE_NDS_FORCE_SIZE = VG_MAX_ENUM +} VGClipModeNds; + +typedef enum { + VG_RQUAD_TO_NDS = ( 13 << 1 ), + VG_RCUBIC_TO_NDS = ( 14 << 1 ), + + VG_PATH_SEGMENT_NDS_FORCE_SIZE = VG_MAX_ENUM +} VGPathSegmentNds; + +typedef enum { + VG_RQUAD_TO_ABS_NDS = (VG_RQUAD_TO_NDS | VG_ABSOLUTE), + VG_RQUAD_TO_REL_NDS = (VG_RQUAD_TO_NDS | VG_RELATIVE), + VG_RCUBIC_TO_ABS_NDS = (VG_RCUBIC_TO_NDS | VG_ABSOLUTE), + VG_RCUBIC_TO_REL_NDS = (VG_RCUBIC_TO_NDS | VG_RELATIVE), + + VG_PATH_COMMAND_NDS_FORCE_SIZE = VG_MAX_ENUM +} VGPathCommandNds; + +#ifdef VG_VGEXT_PROTOTYPES +VG_API_CALL void VG_API_ENTRY vgProjectiveMatrixNDS(VGboolean enable) ; +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguTransformClipLineNDS(const VGfloat Ain,const VGfloat Bin,const VGfloat Cin,const VGfloat* matrix,const VGboolean inverse,VGfloat* Aout,VGfloat* Bout,VGfloat* Cout); +#endif +typedef void (VG_API_ENTRYP PFNVGPROJECTIVEMATRIXNDSPROC) (VGboolean enable) ; +typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUTRANSFORMCLIPLINENDSPROC) (const VGfloat Ain,const VGfloat Bin,const VGfloat Cin,const VGfloat* matrix,const VGboolean inverse,VGfloat* Aout,VGfloat* Bout,VGfloat* Cout); + +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* _VGEXT_H */ diff --git a/include/VG/vgplatform.h b/include/VG/vgplatform.h new file mode 100644 index 0000000..aa1829f --- /dev/null +++ b/include/VG/vgplatform.h @@ -0,0 +1,92 @@ +/* $Revision: 6810 $ on $Date:: 2008-10-29 07:31:37 -0700 #$ */ + +/*------------------------------------------------------------------------ + * + * VG platform specific header Reference Implementation + * ---------------------------------------------------- + * + * Copyright (c) 2008 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and /or associated documentation files + * (the "Materials "), to deal in the Materials without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Materials, + * and to permit persons to whom the Materials are 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 Materials. + * + * THE MATERIALS ARE 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 MATERIALS OR + * THE USE OR OTHER DEALINGS IN THE MATERIALS. + * + *//** + * \file + * \brief VG platform specific header + *//*-------------------------------------------------------------------*/ + +#ifndef _VGPLATFORM_H +#define _VGPLATFORM_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef VG_API_CALL +#if defined(OPENVG_STATIC_LIBRARY) +# define VG_API_CALL +#else +# define VG_API_CALL KHRONOS_APICALL +#endif /* defined OPENVG_STATIC_LIBRARY */ +#endif /* ifndef VG_API_CALL */ + +#ifndef VGU_API_CALL +#if defined(OPENVG_STATIC_LIBRARY) +# define VGU_API_CALL +#else +# define VGU_API_CALL KHRONOS_APICALL +#endif /* defined OPENVG_STATIC_LIBRARY */ +#endif /* ifndef VGU_API_CALL */ + + +#ifndef VG_API_ENTRY +#define VG_API_ENTRY +#endif + +#ifndef VG_API_EXIT +#define VG_API_EXIT +#endif + +#ifndef VGU_API_ENTRY +#define VGU_API_ENTRY +#endif + +#ifndef VGU_API_EXIT +#define VGU_API_EXIT +#endif + +typedef float VGfloat; +typedef signed char VGbyte; +typedef unsigned char VGubyte; +typedef signed short VGshort; +typedef signed int VGint; +typedef unsigned int VGuint; +typedef unsigned int VGbitfield; + +#ifndef VG_VGEXT_PROTOTYPES +#define VG_VGEXT_PROTOTYPES +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* _VGPLATFORM_H */ diff --git a/include/VG/vgu.h b/include/VG/vgu.h new file mode 100644 index 0000000..da81da9 --- /dev/null +++ b/include/VG/vgu.h @@ -0,0 +1,131 @@ +/* $Revision: 6810 $ on $Date:: 2008-10-29 07:31:37 -0700 #$ */ + +/*------------------------------------------------------------------------ + * + * VGU 1.1 Reference Implementation + * ------------------------------------- + * + * Copyright (c) 2008 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and /or associated documentation files + * (the "Materials "), to deal in the Materials without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Materials, + * and to permit persons to whom the Materials are 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 Materials. + * + * THE MATERIALS ARE 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 MATERIALS OR + * THE USE OR OTHER DEALINGS IN THE MATERIALS. + * + *//** + * \file + * \brief VGU 1.1 API. + *//*-------------------------------------------------------------------*/ + +#ifndef _VGU_H +#define _VGU_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define VGU_VERSION_1_0 1 +#define VGU_VERSION_1_1 2 + +#ifndef VGU_API_CALL +# error VGU_API_CALL must be defined +#endif + +#ifndef VGU_API_ENTRY +# error VGU_API_ENTRY must be defined +#endif + +#ifndef VGU_API_EXIT +# error VGU_API_EXIT must be defined +#endif + + +typedef enum { + VGU_NO_ERROR = 0, + VGU_BAD_HANDLE_ERROR = 0xF000, + VGU_ILLEGAL_ARGUMENT_ERROR = 0xF001, + VGU_OUT_OF_MEMORY_ERROR = 0xF002, + VGU_PATH_CAPABILITY_ERROR = 0xF003, + VGU_BAD_WARP_ERROR = 0xF004, + + VGU_ERROR_CODE_FORCE_SIZE = VG_MAX_ENUM +} VGUErrorCode; + +typedef enum { + VGU_ARC_OPEN = 0xF100, + VGU_ARC_CHORD = 0xF101, + VGU_ARC_PIE = 0xF102, + + VGU_ARC_TYPE_FORCE_SIZE = VG_MAX_ENUM +} VGUArcType; + +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguLine(VGPath path, + VGfloat x0, VGfloat y0, + VGfloat x1, VGfloat y1) VGU_API_EXIT; + +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguPolygon(VGPath path, + const VGfloat * points, VGint count, + VGboolean closed) VGU_API_EXIT; + +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguRect(VGPath path, + VGfloat x, VGfloat y, + VGfloat width, VGfloat height) VGU_API_EXIT; + +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguRoundRect(VGPath path, + VGfloat x, VGfloat y, + VGfloat width, VGfloat height, + VGfloat arcWidth, VGfloat arcHeight) VGU_API_EXIT; + +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguEllipse(VGPath path, + VGfloat cx, VGfloat cy, + VGfloat width, VGfloat height) VGU_API_EXIT; + +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguArc(VGPath path, + VGfloat x, VGfloat y, + VGfloat width, VGfloat height, + VGfloat startAngle, VGfloat angleExtent, + VGUArcType arcType) VGU_API_EXIT; + +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguComputeWarpQuadToSquare(VGfloat sx0, VGfloat sy0, + VGfloat sx1, VGfloat sy1, + VGfloat sx2, VGfloat sy2, + VGfloat sx3, VGfloat sy3, + VGfloat * matrix) VGU_API_EXIT; + +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguComputeWarpSquareToQuad(VGfloat dx0, VGfloat dy0, + VGfloat dx1, VGfloat dy1, + VGfloat dx2, VGfloat dy2, + VGfloat dx3, VGfloat dy3, + VGfloat * matrix) VGU_API_EXIT; + +VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguComputeWarpQuadToQuad(VGfloat dx0, VGfloat dy0, + VGfloat dx1, VGfloat dy1, + VGfloat dx2, VGfloat dy2, + VGfloat dx3, VGfloat dy3, + VGfloat sx0, VGfloat sy0, + VGfloat sx1, VGfloat sy1, + VGfloat sx2, VGfloat sy2, + VGfloat sx3, VGfloat sy3, + VGfloat * matrix) VGU_API_EXIT; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* #ifndef _VGU_H */ diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..4f65da0 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,40 @@ +# src/Makefile + +TOP = .. + +include $(TOP)/configs/current + +SUBDIRS = $(SRC_DIRS) + + +default: message $(TOP)/$(LIB_DIR) subdirs + + +message: + @echo "Making sources for" $(CONFIG_NAME) + + +subdirs: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE)) || exit 1; \ + fi \ + done + +install: $(TOP)/$(LIB_DIR) + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) install) || exit 1 ; \ + fi \ + done + +$(TOP)/$(LIB_DIR): + -@test -d $(TOP)/$(LIB_DIR) || mkdir -p $(TOP)/$(LIB_DIR) + + +clean: + -@for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) clean) ; \ + fi \ + done diff --git a/src/egl/Makefile b/src/egl/Makefile new file mode 100644 index 0000000..5b09e17 --- /dev/null +++ b/src/egl/Makefile @@ -0,0 +1,31 @@ +# src/egl/Makefile + +TOP = ../.. +include $(TOP)/configs/current + +SUBDIRS = main drivers + + +default: subdirs + + +subdirs: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE)) || exit 1 ; \ + fi \ + done + +install: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) install) || exit 1 ; \ + fi \ + done + +clean: + -@for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) clean) ; \ + fi \ + done diff --git a/src/egl/drivers/Makefile b/src/egl/drivers/Makefile new file mode 100644 index 0000000..dde4ee2 --- /dev/null +++ b/src/egl/drivers/Makefile @@ -0,0 +1,31 @@ +# src/egl/drivers/Makefile + +TOP = ../../.. +include $(TOP)/configs/current + +SUBDIRS = $(EGL_DRIVERS_DIRS) + + +default: subdirs + + +subdirs: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir ; $(MAKE)) || exit 1 ; \ + fi \ + done + +install: + @ for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir ; $(MAKE) install) || exit 1 ; \ + fi \ + done + +clean: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir ; $(MAKE) clean) ; \ + fi \ + done diff --git a/src/egl/drivers/Makefile.template b/src/egl/drivers/Makefile.template new file mode 100644 index 0000000..47709e3 --- /dev/null +++ b/src/egl/drivers/Makefile.template @@ -0,0 +1,52 @@ +# src/egl/drivers/Makefile.template +# +# Drivers should define +# +# EGL_DRIVER, the driver name +# EGL_SOURCES, the driver sources +# EGL_INCLUDES, the include pathes +# EGL_CFLAGS, additional CFLAGS +# EGL_LIBS, additional LIBS +# +# before including this template. +# + + +EGL_DRIVER_PATH = $(TOP)/$(LIB_DIR)/egl/$(EGL_DRIVER) +EGL_OBJECTS = $(EGL_SOURCES:.c=.o) + + +default: depend $(EGL_DRIVER_PATH) + +$(EGL_DRIVER_PATH): $(EGL_DRIVER) + @$(INSTALL) -d $(TOP)/$(LIB_DIR)/egl + $(INSTALL) $< $(TOP)/$(LIB_DIR)/egl + +$(EGL_DRIVER): $(EGL_OBJECTS) Makefile $(TOP)/src/egl/drivers/Makefile.template + @$(MKLIB) -o $(EGL_DRIVER) -noprefix \ + -linker '$(CC)' -ldflags '-L$(TOP)/$(LIB_DIR) $(LDFLAGS)' \ + $(MKLIB_OPTIONS) \ + $(EGL_OBJECTS) $(EGL_LIBS) -l$(EGL_LIB) + +.c.o: + $(CC) -c $(EGL_INCLUDES) $(CFLAGS) $(EGL_CFLAGS) $< -o $@ + + +install: $(EGL_DRIVER_PATH) + $(INSTALL) -d $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR) + $(MINSTALL) $(EGL_DRIVER_PATH) $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR) + +clean: + rm -f $(EGL_DRIVER) + rm -f $(EGL_OBJECTS) + rm -f depend depend.bak + +depend: $(EGL_SOURCES) + @ echo "running $(MKDEP)" + @ rm -f depend + @ touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(EGL_INCLUDES) $(EGL_SOURCES) \ + >/dev/null 2>/dev/null + +sinclude depend +# DO NOT DELETE diff --git a/src/egl/drivers/dri2/Makefile b/src/egl/drivers/dri2/Makefile new file mode 100644 index 0000000..8a3c9b6 --- /dev/null +++ b/src/egl/drivers/dri2/Makefile @@ -0,0 +1,20 @@ +# src/egl/drivers/dri2/Makefile + +TOP = ../../../.. +include $(TOP)/configs/current + +EGL_DRIVER = egl_dri2.so +EGL_SOURCES = egl_dri2.c + +EGL_INCLUDES = \ + -I$(TOP)/include \ + -I$(TOP)/src/egl/main \ + -I$(TOP)/src/mapi \ + -DDEFAULT_DRIVER_DIR=\"$(DRI_DRIVER_SEARCH_DIR)\" \ + $(XCB_DRI2_CFLAGS) \ + $(LIBUDEV_CFLAGS) \ + $(LIBDRM_CFLAGS) + +EGL_LIBS = $(XCB_DRI2_LIBS) $(LIBUDEV_LIBS) $(LIBDRM_LIBS) + +include ../Makefile.template diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c new file mode 100644 index 0000000..6f40ab9 --- /dev/null +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -0,0 +1,2364 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Kristian Høgsberg + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_LIBUDEV +#include +#endif + +#include +#include "eglconfig.h" +#include "eglcontext.h" +#include "egldisplay.h" +#include "egldriver.h" +#include "eglcurrent.h" +#include "egllog.h" +#include "eglsurface.h" +#include "eglimage.h" + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) + +struct dri2_egl_driver +{ + _EGLDriver base; + + void (*glFlush)(void); +}; + +struct dri2_egl_display +{ + xcb_connection_t *conn; + int dri2_major; + int dri2_minor; + __DRIscreen *dri_screen; + const __DRIconfig **driver_configs; + void *driver; + __DRIcoreExtension *core; + __DRIdri2Extension *dri2; + __DRI2flushExtension *flush; + __DRItexBufferExtension *tex_buffer; + __DRIimageExtension *image; + int fd; + + char *device_name; + char *driver_name; + + __DRIdri2LoaderExtension loader_extension; + const __DRIextension *extensions[3]; +}; + +struct dri2_egl_context +{ + _EGLContext base; + __DRIcontext *dri_context; +}; + +struct dri2_egl_surface +{ + _EGLSurface base; + __DRIdrawable *dri_drawable; + xcb_drawable_t drawable; + __DRIbuffer buffers[5]; + int buffer_count; + xcb_xfixes_region_t region; + int have_fake_front; + int swap_interval; +}; + +struct dri2_egl_config +{ + _EGLConfig base; + const __DRIconfig *dri_config; +}; + +struct dri2_egl_image +{ + _EGLImage base; + __DRIimage *dri_image; +}; + +/* standard typecasts */ +_EGL_DRIVER_STANDARD_TYPECASTS(dri2_egl) +_EGL_DRIVER_TYPECAST(dri2_egl_image, _EGLImage, obj) + +static const __DRIuseInvalidateExtension use_invalidate = { + { __DRI_USE_INVALIDATE, 1 } +}; + +EGLint dri2_to_egl_attribute_map[] = { + 0, + EGL_BUFFER_SIZE, /* __DRI_ATTRIB_BUFFER_SIZE */ + EGL_LEVEL, /* __DRI_ATTRIB_LEVEL */ + EGL_RED_SIZE, /* __DRI_ATTRIB_RED_SIZE */ + EGL_GREEN_SIZE, /* __DRI_ATTRIB_GREEN_SIZE */ + EGL_BLUE_SIZE, /* __DRI_ATTRIB_BLUE_SIZE */ + EGL_LUMINANCE_SIZE, /* __DRI_ATTRIB_LUMINANCE_SIZE */ + EGL_ALPHA_SIZE, /* __DRI_ATTRIB_ALPHA_SIZE */ + 0, /* __DRI_ATTRIB_ALPHA_MASK_SIZE */ + EGL_DEPTH_SIZE, /* __DRI_ATTRIB_DEPTH_SIZE */ + EGL_STENCIL_SIZE, /* __DRI_ATTRIB_STENCIL_SIZE */ + 0, /* __DRI_ATTRIB_ACCUM_RED_SIZE */ + 0, /* __DRI_ATTRIB_ACCUM_GREEN_SIZE */ + 0, /* __DRI_ATTRIB_ACCUM_BLUE_SIZE */ + 0, /* __DRI_ATTRIB_ACCUM_ALPHA_SIZE */ + EGL_SAMPLE_BUFFERS, /* __DRI_ATTRIB_SAMPLE_BUFFERS */ + EGL_SAMPLES, /* __DRI_ATTRIB_SAMPLES */ + 0, /* __DRI_ATTRIB_RENDER_TYPE, */ + 0, /* __DRI_ATTRIB_CONFIG_CAVEAT */ + 0, /* __DRI_ATTRIB_CONFORMANT */ + 0, /* __DRI_ATTRIB_DOUBLE_BUFFER */ + 0, /* __DRI_ATTRIB_STEREO */ + 0, /* __DRI_ATTRIB_AUX_BUFFERS */ + 0, /* __DRI_ATTRIB_TRANSPARENT_TYPE */ + 0, /* __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE */ + 0, /* __DRI_ATTRIB_TRANSPARENT_RED_VALUE */ + 0, /* __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE */ + 0, /* __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE */ + 0, /* __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE */ + 0, /* __DRI_ATTRIB_FLOAT_MODE */ + 0, /* __DRI_ATTRIB_RED_MASK */ + 0, /* __DRI_ATTRIB_GREEN_MASK */ + 0, /* __DRI_ATTRIB_BLUE_MASK */ + 0, /* __DRI_ATTRIB_ALPHA_MASK */ + EGL_MAX_PBUFFER_WIDTH, /* __DRI_ATTRIB_MAX_PBUFFER_WIDTH */ + EGL_MAX_PBUFFER_HEIGHT, /* __DRI_ATTRIB_MAX_PBUFFER_HEIGHT */ + EGL_MAX_PBUFFER_PIXELS, /* __DRI_ATTRIB_MAX_PBUFFER_PIXELS */ + 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH */ + 0, /* __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT */ + 0, /* __DRI_ATTRIB_VISUAL_SELECT_GROUP */ + 0, /* __DRI_ATTRIB_SWAP_METHOD */ + EGL_MAX_SWAP_INTERVAL, /* __DRI_ATTRIB_MAX_SWAP_INTERVAL */ + EGL_MIN_SWAP_INTERVAL, /* __DRI_ATTRIB_MIN_SWAP_INTERVAL */ + 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGB */ + 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA */ + 0, /* __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE */ + 0, /* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */ + EGL_Y_INVERTED_NOK, /* __DRI_ATTRIB_YINVERTED */ +}; + +static struct dri2_egl_config * +dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, + int depth, EGLint surface_type) +{ + struct dri2_egl_config *conf; + struct dri2_egl_display *dri2_dpy; + _EGLConfig base; + unsigned int attrib, value, double_buffer; + EGLint key, bind_to_texture_rgb, bind_to_texture_rgba; + int i; + + dri2_dpy = disp->DriverData; + _eglInitConfig(&base, disp, id); + + i = 0; + double_buffer = 0; + bind_to_texture_rgb = 0; + bind_to_texture_rgba = 0; + + while (dri2_dpy->core->indexConfigAttrib(dri_config, i++, &attrib, &value)) { + switch (attrib) { + case __DRI_ATTRIB_RENDER_TYPE: + if (value & __DRI_ATTRIB_RGBA_BIT) + value = EGL_RGB_BUFFER; + else if (value & __DRI_ATTRIB_LUMINANCE_BIT) + value = EGL_LUMINANCE_BUFFER; + else + /* not valid */; + _eglSetConfigKey(&base, EGL_COLOR_BUFFER_TYPE, value); + break; + + case __DRI_ATTRIB_CONFIG_CAVEAT: + if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) + value = EGL_NON_CONFORMANT_CONFIG; + else if (value & __DRI_ATTRIB_SLOW_BIT) + value = EGL_SLOW_CONFIG; + else + value = EGL_NONE; + _eglSetConfigKey(&base, EGL_CONFIG_CAVEAT, value); + break; + + case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB: + bind_to_texture_rgb = value; + break; + + case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA: + bind_to_texture_rgba = value; + break; + + case __DRI_ATTRIB_DOUBLE_BUFFER: + double_buffer = value; + break; + + default: + key = dri2_to_egl_attribute_map[attrib]; + if (key != 0) + _eglSetConfigKey(&base, key, value); + break; + } + } + + /* In EGL, double buffer or not isn't a config attribute. Pixmaps + * surfaces are always single buffered, pbuffer surfaces are always + * back buffers and windows can be either, selected by passing an + * attribute at window surface construction time. To support this + * we ignore all double buffer configs and manipulate the buffer we + * return in the getBuffer callback to get the behaviour we want. */ + + if (double_buffer) + return NULL; + + if (depth > 0 && depth != base.BufferSize) + return NULL; + + base.NativeRenderable = EGL_TRUE; + + base.SurfaceType = surface_type; + if (surface_type & (EGL_PIXMAP_BIT | EGL_PBUFFER_BIT)) { + base.BindToTextureRGB = bind_to_texture_rgb; + if (base.AlphaSize > 0) + base.BindToTextureRGBA = bind_to_texture_rgba; + } + + base.RenderableType = disp->ClientAPIsMask; + base.Conformant = disp->ClientAPIsMask; + + if (!_eglValidateConfig(&base, EGL_FALSE)) { + _eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id); + return NULL; + } + + conf = malloc(sizeof *conf); + if (conf != NULL) { + memcpy(&conf->base, &base, sizeof base); + conf->dri_config = dri_config; + _eglLinkConfig(&conf->base); + } + + return conf; +} + +/** + * Process list of buffer received from the server + * + * Processes the list of buffers received in a reply from the server to either + * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat. + */ +static void +dri2_process_buffers(struct dri2_egl_surface *dri2_surf, + xcb_dri2_dri2_buffer_t *buffers, unsigned count) +{ + struct dri2_egl_display *dri2_dpy = + dri2_egl_display(dri2_surf->base.Resource.Display); + xcb_rectangle_t rectangle; + unsigned i; + + dri2_surf->buffer_count = count; + dri2_surf->have_fake_front = 0; + + /* This assumes the DRI2 buffer attachment tokens matches the + * __DRIbuffer tokens. */ + for (i = 0; i < count; i++) { + dri2_surf->buffers[i].attachment = buffers[i].attachment; + dri2_surf->buffers[i].name = buffers[i].name; + dri2_surf->buffers[i].pitch = buffers[i].pitch; + dri2_surf->buffers[i].cpp = buffers[i].cpp; + dri2_surf->buffers[i].flags = buffers[i].flags; + + /* We only use the DRI drivers single buffer configs. This + * means that if we try to render to a window, DRI2 will give us + * the fake front buffer, which we'll use as a back buffer. + * Note that EGL doesn't require that several clients rendering + * to the same window must see the same aux buffers. */ + if (dri2_surf->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT) + dri2_surf->have_fake_front = 1; + } + + if (dri2_surf->region != XCB_NONE) + xcb_xfixes_destroy_region(dri2_dpy->conn, dri2_surf->region); + + rectangle.x = 0; + rectangle.y = 0; + rectangle.width = dri2_surf->base.Width; + rectangle.height = dri2_surf->base.Height; + dri2_surf->region = xcb_generate_id(dri2_dpy->conn); + xcb_xfixes_create_region(dri2_dpy->conn, dri2_surf->region, 1, &rectangle); +} + +static __DRIbuffer * +dri2_get_buffers(__DRIdrawable * driDrawable, + int *width, int *height, + unsigned int *attachments, int count, + int *out_count, void *loaderPrivate) +{ + struct dri2_egl_surface *dri2_surf = loaderPrivate; + struct dri2_egl_display *dri2_dpy = + dri2_egl_display(dri2_surf->base.Resource.Display); + xcb_dri2_dri2_buffer_t *buffers; + xcb_dri2_get_buffers_reply_t *reply; + xcb_dri2_get_buffers_cookie_t cookie; + + (void) driDrawable; + + cookie = xcb_dri2_get_buffers_unchecked (dri2_dpy->conn, + dri2_surf->drawable, + count, count, attachments); + reply = xcb_dri2_get_buffers_reply (dri2_dpy->conn, cookie, NULL); + buffers = xcb_dri2_get_buffers_buffers (reply); + if (buffers == NULL) + return NULL; + + *out_count = reply->count; + dri2_surf->base.Width = *width = reply->width; + dri2_surf->base.Height = *height = reply->height; + dri2_process_buffers(dri2_surf, buffers, *out_count); + + free(reply); + + return dri2_surf->buffers; +} + +static void +dri2_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate) +{ + (void) driDrawable; + + /* FIXME: Does EGL support front buffer rendering at all? */ + +#if 0 + struct dri2_egl_surface *dri2_surf = loaderPrivate; + + dri2WaitGL(dri2_surf); +#else + (void) loaderPrivate; +#endif +} + +static __DRIimage * +dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data) +{ + _EGLDisplay *disp = data; + struct dri2_egl_image *dri2_img; + _EGLImage *img; + + (void) screen; + + img = _eglLookupImage(image, disp); + if (img == NULL) { + _eglError(EGL_BAD_PARAMETER, "dri2_lookup_egl_image"); + return NULL; + } + + dri2_img = dri2_egl_image(image); + + return dri2_img->dri_image; +} + +static const __DRIimageLookupExtension image_lookup_extension = { + { __DRI_IMAGE_LOOKUP, 1 }, + dri2_lookup_egl_image +}; + +static __DRIbuffer * +dri2_get_buffers_with_format(__DRIdrawable * driDrawable, + int *width, int *height, + unsigned int *attachments, int count, + int *out_count, void *loaderPrivate) +{ + struct dri2_egl_surface *dri2_surf = loaderPrivate; + struct dri2_egl_display *dri2_dpy = + dri2_egl_display(dri2_surf->base.Resource.Display); + xcb_dri2_dri2_buffer_t *buffers; + xcb_dri2_get_buffers_with_format_reply_t *reply; + xcb_dri2_get_buffers_with_format_cookie_t cookie; + xcb_dri2_attach_format_t *format_attachments; + + (void) driDrawable; + + format_attachments = (xcb_dri2_attach_format_t *) attachments; + cookie = xcb_dri2_get_buffers_with_format_unchecked (dri2_dpy->conn, + dri2_surf->drawable, + count, count, + format_attachments); + + reply = xcb_dri2_get_buffers_with_format_reply (dri2_dpy->conn, + cookie, NULL); + if (reply == NULL) + return NULL; + + buffers = xcb_dri2_get_buffers_with_format_buffers (reply); + dri2_surf->base.Width = *width = reply->width; + dri2_surf->base.Height = *height = reply->height; + *out_count = reply->count; + dri2_process_buffers(dri2_surf, buffers, *out_count); + + free(reply); + + return dri2_surf->buffers; +} + +static const char dri_driver_path[] = DEFAULT_DRIVER_DIR; + +struct dri2_extension_match { + const char *name; + int version; + int offset; +}; + +static struct dri2_extension_match dri2_driver_extensions[] = { + { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core) }, + { __DRI_DRI2, 1, offsetof(struct dri2_egl_display, dri2) }, + { NULL, 0, 0 } +}; + +static struct dri2_extension_match dri2_core_extensions[] = { + { __DRI2_FLUSH, 1, offsetof(struct dri2_egl_display, flush) }, + { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer) }, + { __DRI_IMAGE, 1, offsetof(struct dri2_egl_display, image) }, + { NULL, 0, 0 } +}; + +static EGLBoolean +dri2_bind_extensions(struct dri2_egl_display *dri2_dpy, + struct dri2_extension_match *matches, + const __DRIextension **extensions) +{ + int i, j, ret = EGL_TRUE; + void *field; + + for (i = 0; extensions[i]; i++) { + _eglLog(_EGL_DEBUG, "DRI2: found extension `%s'", extensions[i]->name); + for (j = 0; matches[j].name; j++) { + if (strcmp(extensions[i]->name, matches[j].name) == 0 && + extensions[i]->version >= matches[j].version) { + field = ((char *) dri2_dpy + matches[j].offset); + *(const __DRIextension **) field = extensions[i]; + _eglLog(_EGL_INFO, "DRI2: found extension %s version %d", + extensions[i]->name, extensions[i]->version); + } + } + } + + for (j = 0; matches[j].name; j++) { + field = ((char *) dri2_dpy + matches[j].offset); + if (*(const __DRIextension **) field == NULL) { + _eglLog(_EGL_FATAL, "DRI2: did not find extension %s version %d", + matches[j].name, matches[j].version); + ret = EGL_FALSE; + } + } + + return ret; +} + +static char * +dri2_strndup(const char *s, int length) +{ + char *d; + + d = malloc(length + 1); + if (d == NULL) + return NULL; + + memcpy(d, s, length); + d[length] = '\0'; + + return d; +} + +static EGLBoolean +dri2_connect(struct dri2_egl_display *dri2_dpy) +{ + xcb_xfixes_query_version_reply_t *xfixes_query; + xcb_xfixes_query_version_cookie_t xfixes_query_cookie; + xcb_dri2_query_version_reply_t *dri2_query; + xcb_dri2_query_version_cookie_t dri2_query_cookie; + xcb_dri2_connect_reply_t *connect; + xcb_dri2_connect_cookie_t connect_cookie; + xcb_generic_error_t *error; + xcb_screen_iterator_t s; + + xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_xfixes_id); + xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_dri2_id); + + xfixes_query_cookie = xcb_xfixes_query_version(dri2_dpy->conn, + XCB_XFIXES_MAJOR_VERSION, + XCB_XFIXES_MINOR_VERSION); + + dri2_query_cookie = xcb_dri2_query_version (dri2_dpy->conn, + XCB_DRI2_MAJOR_VERSION, + XCB_DRI2_MINOR_VERSION); + + s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); + connect_cookie = xcb_dri2_connect_unchecked (dri2_dpy->conn, + s.data->root, + XCB_DRI2_DRIVER_TYPE_DRI); + + xfixes_query = + xcb_xfixes_query_version_reply (dri2_dpy->conn, + xfixes_query_cookie, &error); + if (xfixes_query == NULL || + error != NULL || xfixes_query->major_version < 2) { + _eglLog(_EGL_FATAL, "DRI2: failed to query xfixes version"); + free(error); + return EGL_FALSE; + } + free(xfixes_query); + + dri2_query = + xcb_dri2_query_version_reply (dri2_dpy->conn, dri2_query_cookie, &error); + if (dri2_query == NULL || error != NULL) { + _eglLog(_EGL_FATAL, "DRI2: failed to query version"); + free(error); + return EGL_FALSE; + } + dri2_dpy->dri2_major = dri2_query->major_version; + dri2_dpy->dri2_minor = dri2_query->minor_version; + free(dri2_query); + + connect = xcb_dri2_connect_reply (dri2_dpy->conn, connect_cookie, NULL); + if (connect == NULL || + connect->driver_name_length + connect->device_name_length == 0) { + _eglLog(_EGL_FATAL, "DRI2: failed to authenticate"); + return EGL_FALSE; + } + + dri2_dpy->device_name = + dri2_strndup(xcb_dri2_connect_device_name (connect), + xcb_dri2_connect_device_name_length (connect)); + + dri2_dpy->driver_name = + dri2_strndup(xcb_dri2_connect_driver_name (connect), + xcb_dri2_connect_driver_name_length (connect)); + + if (dri2_dpy->device_name == NULL || dri2_dpy->driver_name == NULL) { + free(dri2_dpy->device_name); + free(dri2_dpy->driver_name); + free(connect); + return EGL_FALSE; + } + free(connect); + + return EGL_TRUE; +} + +static EGLBoolean +dri2_authenticate(struct dri2_egl_display *dri2_dpy) +{ + xcb_dri2_authenticate_reply_t *authenticate; + xcb_dri2_authenticate_cookie_t authenticate_cookie; + xcb_screen_iterator_t s; + drm_magic_t magic; + + if (drmGetMagic(dri2_dpy->fd, &magic)) { + _eglLog(_EGL_FATAL, "DRI2: failed to get drm magic"); + return EGL_FALSE; + } + + s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); + authenticate_cookie = + xcb_dri2_authenticate_unchecked(dri2_dpy->conn, s.data->root, magic); + authenticate = + xcb_dri2_authenticate_reply(dri2_dpy->conn, authenticate_cookie, NULL); + if (authenticate == NULL || !authenticate->authenticated) { + _eglLog(_EGL_FATAL, "DRI2: failed to authenticate"); + free(authenticate); + return EGL_FALSE; + } + + free(authenticate); + + return EGL_TRUE; +} + +static EGLBoolean +dri2_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy, + _EGLDisplay *disp) +{ + xcb_screen_iterator_t s; + xcb_depth_iterator_t d; + xcb_visualtype_t *visuals; + int i, j, id; + struct dri2_egl_config *conf; + EGLint surface_type; + + s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); + d = xcb_screen_allowed_depths_iterator(s.data); + id = 1; + + surface_type = + EGL_WINDOW_BIT | + EGL_PIXMAP_BIT | + EGL_PBUFFER_BIT | + EGL_SWAP_BEHAVIOR_PRESERVED_BIT; + + while (d.rem > 0) { + EGLBoolean class_added[6] = { 0, }; + + visuals = xcb_depth_visuals(d.data); + for (i = 0; i < xcb_depth_visuals_length(d.data); i++) { + if (class_added[visuals[i]._class]) + continue; + + class_added[visuals[i]._class] = EGL_TRUE; + for (j = 0; dri2_dpy->driver_configs[j]; j++) { + conf = dri2_add_config(disp, dri2_dpy->driver_configs[j], + id++, d.data->depth, surface_type); + if (conf == NULL) + continue; + _eglSetConfigKey(&conf->base, + EGL_NATIVE_VISUAL_ID, visuals[i].visual_id); + _eglSetConfigKey(&conf->base, + EGL_NATIVE_VISUAL_TYPE, visuals[i]._class); + } + } + + xcb_depth_next(&d); + } + + if (!_eglGetArraySize(disp->Configs)) { + _eglLog(_EGL_WARNING, "DRI2: failed to create any config"); + return EGL_FALSE; + } + + return EGL_TRUE; +} + +static EGLBoolean +dri2_load_driver(_EGLDisplay *disp) +{ + struct dri2_egl_display *dri2_dpy = disp->DriverData; + const __DRIextension **extensions; + char path[PATH_MAX], *search_paths, *p, *next, *end; + + search_paths = NULL; + if (geteuid() == getuid()) { + /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */ + search_paths = getenv("LIBGL_DRIVERS_PATH"); + } + if (search_paths == NULL) + search_paths = DEFAULT_DRIVER_DIR; + + dri2_dpy->driver = NULL; + end = search_paths + strlen(search_paths); + for (p = search_paths; p < end && dri2_dpy->driver == NULL; p = next + 1) { + int len; + next = strchr(p, ':'); + if (next == NULL) + next = end; + + len = next - p; +#if GLX_USE_TLS + snprintf(path, sizeof path, + "%.*s/tls/%s_dri.so", len, p, dri2_dpy->driver_name); + dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL); +#endif + if (dri2_dpy->driver == NULL) { + snprintf(path, sizeof path, + "%.*s/%s_dri.so", len, p, dri2_dpy->driver_name); + dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL); + if (dri2_dpy->driver == NULL) + _eglLog(_EGL_DEBUG, "failed to open %s: %s\n", path, dlerror()); + } + } + + if (dri2_dpy->driver == NULL) { + _eglLog(_EGL_WARNING, + "DRI2: failed to open any driver (search paths %s)", + search_paths); + return EGL_FALSE; + } + + _eglLog(_EGL_DEBUG, "DRI2: dlopen(%s)", path); + extensions = dlsym(dri2_dpy->driver, __DRI_DRIVER_EXTENSIONS); + if (extensions == NULL) { + _eglLog(_EGL_WARNING, + "DRI2: driver exports no extensions (%s)", dlerror()); + dlclose(dri2_dpy->driver); + return EGL_FALSE; + } + + if (!dri2_bind_extensions(dri2_dpy, dri2_driver_extensions, extensions)) { + dlclose(dri2_dpy->driver); + return EGL_FALSE; + } + + return EGL_TRUE; +} + +static EGLBoolean +dri2_create_screen(_EGLDisplay *disp) +{ + const __DRIextension **extensions; + struct dri2_egl_display *dri2_dpy; + unsigned int api_mask; + + dri2_dpy = disp->DriverData; + dri2_dpy->dri_screen = + dri2_dpy->dri2->createNewScreen(0, dri2_dpy->fd, dri2_dpy->extensions, + &dri2_dpy->driver_configs, disp); + + if (dri2_dpy->dri_screen == NULL) { + _eglLog(_EGL_WARNING, "DRI2: failed to create dri screen"); + return EGL_FALSE; + } + + extensions = dri2_dpy->core->getExtensions(dri2_dpy->dri_screen); + if (!dri2_bind_extensions(dri2_dpy, dri2_core_extensions, extensions)) + goto cleanup_dri_screen; + + if (dri2_dpy->dri2->base.version >= 2) + api_mask = dri2_dpy->dri2->getAPIMask(dri2_dpy->dri_screen); + else + api_mask = 1 << __DRI_API_OPENGL; + + disp->ClientAPIsMask = 0; + if (api_mask & (1 <<__DRI_API_OPENGL)) + disp->ClientAPIsMask |= EGL_OPENGL_BIT; + if (api_mask & (1 <<__DRI_API_GLES)) + disp->ClientAPIsMask |= EGL_OPENGL_ES_BIT; + if (api_mask & (1 << __DRI_API_GLES2)) + disp->ClientAPIsMask |= EGL_OPENGL_ES2_BIT; + + if (dri2_dpy->dri2->base.version >= 2) { + disp->Extensions.KHR_surfaceless_gles1 = EGL_TRUE; + disp->Extensions.KHR_surfaceless_gles2 = EGL_TRUE; + disp->Extensions.KHR_surfaceless_opengl = EGL_TRUE; + } + + return EGL_TRUE; + + cleanup_dri_screen: + dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); + + return EGL_FALSE; +} + +static EGLBoolean +dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp, + EGLint *major, EGLint *minor) +{ + struct dri2_egl_display *dri2_dpy; + + (void) drv; + + dri2_dpy = malloc(sizeof *dri2_dpy); + if (!dri2_dpy) + return _eglError(EGL_BAD_ALLOC, "eglInitialize"); + + disp->DriverData = (void *) dri2_dpy; + if (disp->PlatformDisplay == NULL) { + dri2_dpy->conn = xcb_connect(0, 0); + } else { + dri2_dpy->conn = XGetXCBConnection((Display *) disp->PlatformDisplay); + } + + if (xcb_connection_has_error(dri2_dpy->conn)) { + _eglLog(_EGL_WARNING, "DRI2: xcb_connect failed"); + goto cleanup_dpy; + } + + if (dri2_dpy->conn) { + if (!dri2_connect(dri2_dpy)) + goto cleanup_conn; + } + + if (!dri2_load_driver(disp)) + goto cleanup_conn; + + dri2_dpy->fd = open(dri2_dpy->device_name, O_RDWR); + if (dri2_dpy->fd == -1) { + _eglLog(_EGL_WARNING, + "DRI2: could not open %s (%s)", dri2_dpy->device_name, + strerror(errno)); + goto cleanup_driver; + } + + if (dri2_dpy->conn) { + if (!dri2_authenticate(dri2_dpy)) + goto cleanup_fd; + } + + if (dri2_dpy->dri2_minor >= 1) { + dri2_dpy->loader_extension.base.name = __DRI_DRI2_LOADER; + dri2_dpy->loader_extension.base.version = 3; + dri2_dpy->loader_extension.getBuffers = dri2_get_buffers; + dri2_dpy->loader_extension.flushFrontBuffer = dri2_flush_front_buffer; + dri2_dpy->loader_extension.getBuffersWithFormat = + dri2_get_buffers_with_format; + } else { + dri2_dpy->loader_extension.base.name = __DRI_DRI2_LOADER; + dri2_dpy->loader_extension.base.version = 2; + dri2_dpy->loader_extension.getBuffers = dri2_get_buffers; + dri2_dpy->loader_extension.flushFrontBuffer = dri2_flush_front_buffer; + dri2_dpy->loader_extension.getBuffersWithFormat = NULL; + } + + dri2_dpy->extensions[0] = &dri2_dpy->loader_extension.base; + dri2_dpy->extensions[1] = &image_lookup_extension.base; + dri2_dpy->extensions[2] = NULL; + + if (!dri2_create_screen(disp)) + goto cleanup_fd; + + if (dri2_dpy->conn) { + if (!dri2_add_configs_for_visuals(dri2_dpy, disp)) + goto cleanup_configs; + } + + disp->Extensions.MESA_drm_image = EGL_TRUE; + disp->Extensions.KHR_image_base = EGL_TRUE; + disp->Extensions.KHR_image_pixmap = EGL_TRUE; + disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE; + disp->Extensions.KHR_gl_texture_2D_image = EGL_TRUE; + disp->Extensions.NOK_swap_region = EGL_TRUE; + disp->Extensions.NOK_texture_from_pixmap = EGL_TRUE; + + /* we're supporting EGL 1.4 */ + *major = 1; + *minor = 4; + + return EGL_TRUE; + + cleanup_configs: + _eglCleanupDisplay(disp); + dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); + cleanup_fd: + close(dri2_dpy->fd); + cleanup_driver: + dlclose(dri2_dpy->driver); + cleanup_conn: + if (disp->PlatformDisplay == NULL) + xcb_disconnect(dri2_dpy->conn); + cleanup_dpy: + free(dri2_dpy); + + return EGL_FALSE; +} + +#ifdef HAVE_LIBUDEV + +struct dri2_driver_map { + int vendor_id; + const char *driver; + const int *chip_ids; + int num_chips_ids; +}; + +const int i915_chip_ids[] = { + 0x3577, /* PCI_CHIP_I830_M */ + 0x2562, /* PCI_CHIP_845_G */ + 0x3582, /* PCI_CHIP_I855_GM */ + 0x2572, /* PCI_CHIP_I865_G */ + 0x2582, /* PCI_CHIP_I915_G */ + 0x258a, /* PCI_CHIP_E7221_G */ + 0x2592, /* PCI_CHIP_I915_GM */ + 0x2772, /* PCI_CHIP_I945_G */ + 0x27a2, /* PCI_CHIP_I945_GM */ + 0x27ae, /* PCI_CHIP_I945_GME */ + 0x29b2, /* PCI_CHIP_Q35_G */ + 0x29c2, /* PCI_CHIP_G33_G */ + 0x29d2, /* PCI_CHIP_Q33_G */ + 0xa001, /* PCI_CHIP_IGD_G */ + 0xa011, /* Pineview */ +}; + +const int i965_chip_ids[] = { + 0x0042, /* PCI_CHIP_ILD_G */ + 0x0046, /* PCI_CHIP_ILM_G */ + 0x0102, /* PCI_CHIP_SANDYBRIDGE_GT1 */ + 0x0106, /* PCI_CHIP_SANDYBRIDGE_M_GT1 */ + 0x010a, /* PCI_CHIP_SANDYBRIDGE_S */ + 0x0112, /* PCI_CHIP_SANDYBRIDGE_GT2 */ + 0x0116, /* PCI_CHIP_SANDYBRIDGE_M_GT2 */ + 0x0122, /* PCI_CHIP_SANDYBRIDGE_GT2_PLUS */ + 0x0126, /* PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS */ + 0x29a2, /* PCI_CHIP_I965_G */ + 0x2992, /* PCI_CHIP_I965_Q */ + 0x2982, /* PCI_CHIP_I965_G_1 */ + 0x2972, /* PCI_CHIP_I946_GZ */ + 0x2a02, /* PCI_CHIP_I965_GM */ + 0x2a12, /* PCI_CHIP_I965_GME */ + 0x2a42, /* PCI_CHIP_GM45_GM */ + 0x2e02, /* PCI_CHIP_IGD_E_G */ + 0x2e12, /* PCI_CHIP_Q45_G */ + 0x2e22, /* PCI_CHIP_G45_G */ + 0x2e32, /* PCI_CHIP_G41_G */ + 0x2e42, /* PCI_CHIP_B43_G */ + 0x2e92, /* PCI_CHIP_B43_G1 */ +}; + +const int r100_chip_ids[] = { + 0x4C57, /* PCI_CHIP_RADEON_LW */ + 0x4C58, /* PCI_CHIP_RADEON_LX */ + 0x4C59, /* PCI_CHIP_RADEON_LY */ + 0x4C5A, /* PCI_CHIP_RADEON_LZ */ + 0x5144, /* PCI_CHIP_RADEON_QD */ + 0x5145, /* PCI_CHIP_RADEON_QE */ + 0x5146, /* PCI_CHIP_RADEON_QF */ + 0x5147, /* PCI_CHIP_RADEON_QG */ + 0x5159, /* PCI_CHIP_RADEON_QY */ + 0x515A, /* PCI_CHIP_RADEON_QZ */ + 0x5157, /* PCI_CHIP_RV200_QW */ + 0x5158, /* PCI_CHIP_RV200_QX */ + 0x515E, /* PCI_CHIP_RN50_515E */ + 0x5969, /* PCI_CHIP_RN50_5969 */ + 0x4136, /* PCI_CHIP_RS100_4136 */ + 0x4336, /* PCI_CHIP_RS100_4336 */ + 0x4137, /* PCI_CHIP_RS200_4137 */ + 0x4337, /* PCI_CHIP_RS200_4337 */ + 0x4237, /* PCI_CHIP_RS250_4237 */ + 0x4437, /* PCI_CHIP_RS250_4437 */ +}; + +const int r200_chip_ids[] = { + 0x5148, /* PCI_CHIP_R200_QH */ + 0x514C, /* PCI_CHIP_R200_QL */ + 0x514D, /* PCI_CHIP_R200_QM */ + 0x4242, /* PCI_CHIP_R200_BB */ + 0x4243, /* PCI_CHIP_R200_BC */ + 0x4966, /* PCI_CHIP_RV250_If */ + 0x4967, /* PCI_CHIP_RV250_Ig */ + 0x4C64, /* PCI_CHIP_RV250_Ld */ + 0x4C66, /* PCI_CHIP_RV250_Lf */ + 0x4C67, /* PCI_CHIP_RV250_Lg */ + 0x5960, /* PCI_CHIP_RV280_5960 */ + 0x5961, /* PCI_CHIP_RV280_5961 */ + 0x5962, /* PCI_CHIP_RV280_5962 */ + 0x5964, /* PCI_CHIP_RV280_5964 */ + 0x5965, /* PCI_CHIP_RV280_5965 */ + 0x5C61, /* PCI_CHIP_RV280_5C61 */ + 0x5C63, /* PCI_CHIP_RV280_5C63 */ + 0x5834, /* PCI_CHIP_RS300_5834 */ + 0x5835, /* PCI_CHIP_RS300_5835 */ + 0x7834, /* PCI_CHIP_RS350_7834 */ + 0x7835, /* PCI_CHIP_RS350_7835 */ +}; + +const int r300_chip_ids[] = { + 0x4144, /* PCI_CHIP_R300_AD */ + 0x4145, /* PCI_CHIP_R300_AE */ + 0x4146, /* PCI_CHIP_R300_AF */ + 0x4147, /* PCI_CHIP_R300_AG */ + 0x4E44, /* PCI_CHIP_R300_ND */ + 0x4E45, /* PCI_CHIP_R300_NE */ + 0x4E46, /* PCI_CHIP_R300_NF */ + 0x4E47, /* PCI_CHIP_R300_NG */ + 0x4E48, /* PCI_CHIP_R350_NH */ + 0x4E49, /* PCI_CHIP_R350_NI */ + 0x4E4B, /* PCI_CHIP_R350_NK */ + 0x4148, /* PCI_CHIP_R350_AH */ + 0x4149, /* PCI_CHIP_R350_AI */ + 0x414A, /* PCI_CHIP_R350_AJ */ + 0x414B, /* PCI_CHIP_R350_AK */ + 0x4E4A, /* PCI_CHIP_R360_NJ */ + 0x4150, /* PCI_CHIP_RV350_AP */ + 0x4151, /* PCI_CHIP_RV350_AQ */ + 0x4152, /* PCI_CHIP_RV350_AR */ + 0x4153, /* PCI_CHIP_RV350_AS */ + 0x4154, /* PCI_CHIP_RV350_AT */ + 0x4155, /* PCI_CHIP_RV350_AU */ + 0x4156, /* PCI_CHIP_RV350_AV */ + 0x4E50, /* PCI_CHIP_RV350_NP */ + 0x4E51, /* PCI_CHIP_RV350_NQ */ + 0x4E52, /* PCI_CHIP_RV350_NR */ + 0x4E53, /* PCI_CHIP_RV350_NS */ + 0x4E54, /* PCI_CHIP_RV350_NT */ + 0x4E56, /* PCI_CHIP_RV350_NV */ + 0x5460, /* PCI_CHIP_RV370_5460 */ + 0x5462, /* PCI_CHIP_RV370_5462 */ + 0x5464, /* PCI_CHIP_RV370_5464 */ + 0x5B60, /* PCI_CHIP_RV370_5B60 */ + 0x5B62, /* PCI_CHIP_RV370_5B62 */ + 0x5B63, /* PCI_CHIP_RV370_5B63 */ + 0x5B64, /* PCI_CHIP_RV370_5B64 */ + 0x5B65, /* PCI_CHIP_RV370_5B65 */ + 0x3150, /* PCI_CHIP_RV380_3150 */ + 0x3152, /* PCI_CHIP_RV380_3152 */ + 0x3154, /* PCI_CHIP_RV380_3154 */ + 0x3155, /* PCI_CHIP_RV380_3155 */ + 0x3E50, /* PCI_CHIP_RV380_3E50 */ + 0x3E54, /* PCI_CHIP_RV380_3E54 */ + 0x4A48, /* PCI_CHIP_R420_JH */ + 0x4A49, /* PCI_CHIP_R420_JI */ + 0x4A4A, /* PCI_CHIP_R420_JJ */ + 0x4A4B, /* PCI_CHIP_R420_JK */ + 0x4A4C, /* PCI_CHIP_R420_JL */ + 0x4A4D, /* PCI_CHIP_R420_JM */ + 0x4A4E, /* PCI_CHIP_R420_JN */ + 0x4A4F, /* PCI_CHIP_R420_JO */ + 0x4A50, /* PCI_CHIP_R420_JP */ + 0x4A54, /* PCI_CHIP_R420_JT */ + 0x5548, /* PCI_CHIP_R423_UH */ + 0x5549, /* PCI_CHIP_R423_UI */ + 0x554A, /* PCI_CHIP_R423_UJ */ + 0x554B, /* PCI_CHIP_R423_UK */ + 0x5550, /* PCI_CHIP_R423_5550 */ + 0x5551, /* PCI_CHIP_R423_UQ */ + 0x5552, /* PCI_CHIP_R423_UR */ + 0x5554, /* PCI_CHIP_R423_UT */ + 0x5D57, /* PCI_CHIP_R423_5D57 */ + 0x554C, /* PCI_CHIP_R430_554C */ + 0x554D, /* PCI_CHIP_R430_554D */ + 0x554E, /* PCI_CHIP_R430_554E */ + 0x554F, /* PCI_CHIP_R430_554F */ + 0x5D48, /* PCI_CHIP_R430_5D48 */ + 0x5D49, /* PCI_CHIP_R430_5D49 */ + 0x5D4A, /* PCI_CHIP_R430_5D4A */ + 0x5D4C, /* PCI_CHIP_R480_5D4C */ + 0x5D4D, /* PCI_CHIP_R480_5D4D */ + 0x5D4E, /* PCI_CHIP_R480_5D4E */ + 0x5D4F, /* PCI_CHIP_R480_5D4F */ + 0x5D50, /* PCI_CHIP_R480_5D50 */ + 0x5D52, /* PCI_CHIP_R480_5D52 */ + 0x4B49, /* PCI_CHIP_R481_4B49 */ + 0x4B4A, /* PCI_CHIP_R481_4B4A */ + 0x4B4B, /* PCI_CHIP_R481_4B4B */ + 0x4B4C, /* PCI_CHIP_R481_4B4C */ + 0x564A, /* PCI_CHIP_RV410_564A */ + 0x564B, /* PCI_CHIP_RV410_564B */ + 0x564F, /* PCI_CHIP_RV410_564F */ + 0x5652, /* PCI_CHIP_RV410_5652 */ + 0x5653, /* PCI_CHIP_RV410_5653 */ + 0x5657, /* PCI_CHIP_RV410_5657 */ + 0x5E48, /* PCI_CHIP_RV410_5E48 */ + 0x5E4A, /* PCI_CHIP_RV410_5E4A */ + 0x5E4B, /* PCI_CHIP_RV410_5E4B */ + 0x5E4C, /* PCI_CHIP_RV410_5E4C */ + 0x5E4D, /* PCI_CHIP_RV410_5E4D */ + 0x5E4F, /* PCI_CHIP_RV410_5E4F */ + 0x5A41, /* PCI_CHIP_RS400_5A41 */ + 0x5A42, /* PCI_CHIP_RS400_5A42 */ + 0x5A61, /* PCI_CHIP_RC410_5A61 */ + 0x5A62, /* PCI_CHIP_RC410_5A62 */ + 0x5954, /* PCI_CHIP_RS480_5954 */ + 0x5955, /* PCI_CHIP_RS480_5955 */ + 0x5974, /* PCI_CHIP_RS482_5974 */ + 0x5975, /* PCI_CHIP_RS482_5975 */ + 0x7100, /* PCI_CHIP_R520_7100 */ + 0x7101, /* PCI_CHIP_R520_7101 */ + 0x7102, /* PCI_CHIP_R520_7102 */ + 0x7103, /* PCI_CHIP_R520_7103 */ + 0x7104, /* PCI_CHIP_R520_7104 */ + 0x7105, /* PCI_CHIP_R520_7105 */ + 0x7106, /* PCI_CHIP_R520_7106 */ + 0x7108, /* PCI_CHIP_R520_7108 */ + 0x7109, /* PCI_CHIP_R520_7109 */ + 0x710A, /* PCI_CHIP_R520_710A */ + 0x710B, /* PCI_CHIP_R520_710B */ + 0x710C, /* PCI_CHIP_R520_710C */ + 0x710E, /* PCI_CHIP_R520_710E */ + 0x710F, /* PCI_CHIP_R520_710F */ + 0x7140, /* PCI_CHIP_RV515_7140 */ + 0x7141, /* PCI_CHIP_RV515_7141 */ + 0x7142, /* PCI_CHIP_RV515_7142 */ + 0x7143, /* PCI_CHIP_RV515_7143 */ + 0x7144, /* PCI_CHIP_RV515_7144 */ + 0x7145, /* PCI_CHIP_RV515_7145 */ + 0x7146, /* PCI_CHIP_RV515_7146 */ + 0x7147, /* PCI_CHIP_RV515_7147 */ + 0x7149, /* PCI_CHIP_RV515_7149 */ + 0x714A, /* PCI_CHIP_RV515_714A */ + 0x714B, /* PCI_CHIP_RV515_714B */ + 0x714C, /* PCI_CHIP_RV515_714C */ + 0x714D, /* PCI_CHIP_RV515_714D */ + 0x714E, /* PCI_CHIP_RV515_714E */ + 0x714F, /* PCI_CHIP_RV515_714F */ + 0x7151, /* PCI_CHIP_RV515_7151 */ + 0x7152, /* PCI_CHIP_RV515_7152 */ + 0x7153, /* PCI_CHIP_RV515_7153 */ + 0x715E, /* PCI_CHIP_RV515_715E */ + 0x715F, /* PCI_CHIP_RV515_715F */ + 0x7180, /* PCI_CHIP_RV515_7180 */ + 0x7181, /* PCI_CHIP_RV515_7181 */ + 0x7183, /* PCI_CHIP_RV515_7183 */ + 0x7186, /* PCI_CHIP_RV515_7186 */ + 0x7187, /* PCI_CHIP_RV515_7187 */ + 0x7188, /* PCI_CHIP_RV515_7188 */ + 0x718A, /* PCI_CHIP_RV515_718A */ + 0x718B, /* PCI_CHIP_RV515_718B */ + 0x718C, /* PCI_CHIP_RV515_718C */ + 0x718D, /* PCI_CHIP_RV515_718D */ + 0x718F, /* PCI_CHIP_RV515_718F */ + 0x7193, /* PCI_CHIP_RV515_7193 */ + 0x7196, /* PCI_CHIP_RV515_7196 */ + 0x719B, /* PCI_CHIP_RV515_719B */ + 0x719F, /* PCI_CHIP_RV515_719F */ + 0x7200, /* PCI_CHIP_RV515_7200 */ + 0x7210, /* PCI_CHIP_RV515_7210 */ + 0x7211, /* PCI_CHIP_RV515_7211 */ + 0x71C0, /* PCI_CHIP_RV530_71C0 */ + 0x71C1, /* PCI_CHIP_RV530_71C1 */ + 0x71C2, /* PCI_CHIP_RV530_71C2 */ + 0x71C3, /* PCI_CHIP_RV530_71C3 */ + 0x71C4, /* PCI_CHIP_RV530_71C4 */ + 0x71C5, /* PCI_CHIP_RV530_71C5 */ + 0x71C6, /* PCI_CHIP_RV530_71C6 */ + 0x71C7, /* PCI_CHIP_RV530_71C7 */ + 0x71CD, /* PCI_CHIP_RV530_71CD */ + 0x71CE, /* PCI_CHIP_RV530_71CE */ + 0x71D2, /* PCI_CHIP_RV530_71D2 */ + 0x71D4, /* PCI_CHIP_RV530_71D4 */ + 0x71D5, /* PCI_CHIP_RV530_71D5 */ + 0x71D6, /* PCI_CHIP_RV530_71D6 */ + 0x71DA, /* PCI_CHIP_RV530_71DA */ + 0x71DE, /* PCI_CHIP_RV530_71DE */ + 0x7281, /* PCI_CHIP_RV560_7281 */ + 0x7283, /* PCI_CHIP_RV560_7283 */ + 0x7287, /* PCI_CHIP_RV560_7287 */ + 0x7290, /* PCI_CHIP_RV560_7290 */ + 0x7291, /* PCI_CHIP_RV560_7291 */ + 0x7293, /* PCI_CHIP_RV560_7293 */ + 0x7297, /* PCI_CHIP_RV560_7297 */ + 0x7280, /* PCI_CHIP_RV570_7280 */ + 0x7288, /* PCI_CHIP_RV570_7288 */ + 0x7289, /* PCI_CHIP_RV570_7289 */ + 0x728B, /* PCI_CHIP_RV570_728B */ + 0x728C, /* PCI_CHIP_RV570_728C */ + 0x7240, /* PCI_CHIP_R580_7240 */ + 0x7243, /* PCI_CHIP_R580_7243 */ + 0x7244, /* PCI_CHIP_R580_7244 */ + 0x7245, /* PCI_CHIP_R580_7245 */ + 0x7246, /* PCI_CHIP_R580_7246 */ + 0x7247, /* PCI_CHIP_R580_7247 */ + 0x7248, /* PCI_CHIP_R580_7248 */ + 0x7249, /* PCI_CHIP_R580_7249 */ + 0x724A, /* PCI_CHIP_R580_724A */ + 0x724B, /* PCI_CHIP_R580_724B */ + 0x724C, /* PCI_CHIP_R580_724C */ + 0x724D, /* PCI_CHIP_R580_724D */ + 0x724E, /* PCI_CHIP_R580_724E */ + 0x724F, /* PCI_CHIP_R580_724F */ + 0x7284, /* PCI_CHIP_R580_7284 */ + 0x793F, /* PCI_CHIP_RS600_793F */ + 0x7941, /* PCI_CHIP_RS600_7941 */ + 0x7942, /* PCI_CHIP_RS600_7942 */ + 0x791E, /* PCI_CHIP_RS690_791E */ + 0x791F, /* PCI_CHIP_RS690_791F */ + 0x796C, /* PCI_CHIP_RS740_796C */ + 0x796D, /* PCI_CHIP_RS740_796D */ + 0x796E, /* PCI_CHIP_RS740_796E */ + 0x796F, /* PCI_CHIP_RS740_796F */ +}; + +const int r600_chip_ids[] = { + 0x9400, /* PCI_CHIP_R600_9400 */ + 0x9401, /* PCI_CHIP_R600_9401 */ + 0x9402, /* PCI_CHIP_R600_9402 */ + 0x9403, /* PCI_CHIP_R600_9403 */ + 0x9405, /* PCI_CHIP_R600_9405 */ + 0x940A, /* PCI_CHIP_R600_940A */ + 0x940B, /* PCI_CHIP_R600_940B */ + 0x940F, /* PCI_CHIP_R600_940F */ + 0x94C0, /* PCI_CHIP_RV610_94C0 */ + 0x94C1, /* PCI_CHIP_RV610_94C1 */ + 0x94C3, /* PCI_CHIP_RV610_94C3 */ + 0x94C4, /* PCI_CHIP_RV610_94C4 */ + 0x94C5, /* PCI_CHIP_RV610_94C5 */ + 0x94C6, /* PCI_CHIP_RV610_94C6 */ + 0x94C7, /* PCI_CHIP_RV610_94C7 */ + 0x94C8, /* PCI_CHIP_RV610_94C8 */ + 0x94C9, /* PCI_CHIP_RV610_94C9 */ + 0x94CB, /* PCI_CHIP_RV610_94CB */ + 0x94CC, /* PCI_CHIP_RV610_94CC */ + 0x94CD, /* PCI_CHIP_RV610_94CD */ + 0x9580, /* PCI_CHIP_RV630_9580 */ + 0x9581, /* PCI_CHIP_RV630_9581 */ + 0x9583, /* PCI_CHIP_RV630_9583 */ + 0x9586, /* PCI_CHIP_RV630_9586 */ + 0x9587, /* PCI_CHIP_RV630_9587 */ + 0x9588, /* PCI_CHIP_RV630_9588 */ + 0x9589, /* PCI_CHIP_RV630_9589 */ + 0x958A, /* PCI_CHIP_RV630_958A */ + 0x958B, /* PCI_CHIP_RV630_958B */ + 0x958C, /* PCI_CHIP_RV630_958C */ + 0x958D, /* PCI_CHIP_RV630_958D */ + 0x958E, /* PCI_CHIP_RV630_958E */ + 0x958F, /* PCI_CHIP_RV630_958F */ + 0x9500, /* PCI_CHIP_RV670_9500 */ + 0x9501, /* PCI_CHIP_RV670_9501 */ + 0x9504, /* PCI_CHIP_RV670_9504 */ + 0x9505, /* PCI_CHIP_RV670_9505 */ + 0x9506, /* PCI_CHIP_RV670_9506 */ + 0x9507, /* PCI_CHIP_RV670_9507 */ + 0x9508, /* PCI_CHIP_RV670_9508 */ + 0x9509, /* PCI_CHIP_RV670_9509 */ + 0x950F, /* PCI_CHIP_RV670_950F */ + 0x9511, /* PCI_CHIP_RV670_9511 */ + 0x9515, /* PCI_CHIP_RV670_9515 */ + 0x9517, /* PCI_CHIP_RV670_9517 */ + 0x9519, /* PCI_CHIP_RV670_9519 */ + 0x95C0, /* PCI_CHIP_RV620_95C0 */ + 0x95C2, /* PCI_CHIP_RV620_95C2 */ + 0x95C4, /* PCI_CHIP_RV620_95C4 */ + 0x95C5, /* PCI_CHIP_RV620_95C5 */ + 0x95C6, /* PCI_CHIP_RV620_95C6 */ + 0x95C7, /* PCI_CHIP_RV620_95C7 */ + 0x95C9, /* PCI_CHIP_RV620_95C9 */ + 0x95CC, /* PCI_CHIP_RV620_95CC */ + 0x95CD, /* PCI_CHIP_RV620_95CD */ + 0x95CE, /* PCI_CHIP_RV620_95CE */ + 0x95CF, /* PCI_CHIP_RV620_95CF */ + 0x9590, /* PCI_CHIP_RV635_9590 */ + 0x9591, /* PCI_CHIP_RV635_9591 */ + 0x9593, /* PCI_CHIP_RV635_9593 */ + 0x9595, /* PCI_CHIP_RV635_9595 */ + 0x9596, /* PCI_CHIP_RV635_9596 */ + 0x9597, /* PCI_CHIP_RV635_9597 */ + 0x9598, /* PCI_CHIP_RV635_9598 */ + 0x9599, /* PCI_CHIP_RV635_9599 */ + 0x959B, /* PCI_CHIP_RV635_959B */ + 0x9610, /* PCI_CHIP_RS780_9610 */ + 0x9611, /* PCI_CHIP_RS780_9611 */ + 0x9612, /* PCI_CHIP_RS780_9612 */ + 0x9613, /* PCI_CHIP_RS780_9613 */ + 0x9614, /* PCI_CHIP_RS780_9614 */ + 0x9615, /* PCI_CHIP_RS780_9615 */ + 0x9616, /* PCI_CHIP_RS780_9616 */ + 0x9710, /* PCI_CHIP_RS880_9710 */ + 0x9711, /* PCI_CHIP_RS880_9711 */ + 0x9712, /* PCI_CHIP_RS880_9712 */ + 0x9713, /* PCI_CHIP_RS880_9713 */ + 0x9714, /* PCI_CHIP_RS880_9714 */ + 0x9715, /* PCI_CHIP_RS880_9715 */ + 0x9440, /* PCI_CHIP_RV770_9440 */ + 0x9441, /* PCI_CHIP_RV770_9441 */ + 0x9442, /* PCI_CHIP_RV770_9442 */ + 0x9443, /* PCI_CHIP_RV770_9443 */ + 0x9444, /* PCI_CHIP_RV770_9444 */ + 0x9446, /* PCI_CHIP_RV770_9446 */ + 0x944A, /* PCI_CHIP_RV770_944A */ + 0x944B, /* PCI_CHIP_RV770_944B */ + 0x944C, /* PCI_CHIP_RV770_944C */ + 0x944E, /* PCI_CHIP_RV770_944E */ + 0x9450, /* PCI_CHIP_RV770_9450 */ + 0x9452, /* PCI_CHIP_RV770_9452 */ + 0x9456, /* PCI_CHIP_RV770_9456 */ + 0x945A, /* PCI_CHIP_RV770_945A */ + 0x945B, /* PCI_CHIP_RV770_945B */ + 0x945E, /* PCI_CHIP_RV770_945E */ + 0x9460, /* PCI_CHIP_RV790_9460 */ + 0x9462, /* PCI_CHIP_RV790_9462 */ + 0x946A, /* PCI_CHIP_RV770_946A */ + 0x946B, /* PCI_CHIP_RV770_946B */ + 0x947A, /* PCI_CHIP_RV770_947A */ + 0x947B, /* PCI_CHIP_RV770_947B */ + 0x9480, /* PCI_CHIP_RV730_9480 */ + 0x9487, /* PCI_CHIP_RV730_9487 */ + 0x9488, /* PCI_CHIP_RV730_9488 */ + 0x9489, /* PCI_CHIP_RV730_9489 */ + 0x948A, /* PCI_CHIP_RV730_948A */ + 0x948F, /* PCI_CHIP_RV730_948F */ + 0x9490, /* PCI_CHIP_RV730_9490 */ + 0x9491, /* PCI_CHIP_RV730_9491 */ + 0x9495, /* PCI_CHIP_RV730_9495 */ + 0x9498, /* PCI_CHIP_RV730_9498 */ + 0x949C, /* PCI_CHIP_RV730_949C */ + 0x949E, /* PCI_CHIP_RV730_949E */ + 0x949F, /* PCI_CHIP_RV730_949F */ + 0x9540, /* PCI_CHIP_RV710_9540 */ + 0x9541, /* PCI_CHIP_RV710_9541 */ + 0x9542, /* PCI_CHIP_RV710_9542 */ + 0x954E, /* PCI_CHIP_RV710_954E */ + 0x954F, /* PCI_CHIP_RV710_954F */ + 0x9552, /* PCI_CHIP_RV710_9552 */ + 0x9553, /* PCI_CHIP_RV710_9553 */ + 0x9555, /* PCI_CHIP_RV710_9555 */ + 0x9557, /* PCI_CHIP_RV710_9557 */ + 0x955F, /* PCI_CHIP_RV710_955F */ + 0x94A0, /* PCI_CHIP_RV740_94A0 */ + 0x94A1, /* PCI_CHIP_RV740_94A1 */ + 0x94A3, /* PCI_CHIP_RV740_94A3 */ + 0x94B1, /* PCI_CHIP_RV740_94B1 */ + 0x94B3, /* PCI_CHIP_RV740_94B3 */ + 0x94B4, /* PCI_CHIP_RV740_94B4 */ + 0x94B5, /* PCI_CHIP_RV740_94B5 */ + 0x94B9, /* PCI_CHIP_RV740_94B9 */ + 0x68E0, /* PCI_CHIP_CEDAR_68E0 */ + 0x68E1, /* PCI_CHIP_CEDAR_68E1 */ + 0x68E4, /* PCI_CHIP_CEDAR_68E4 */ + 0x68E5, /* PCI_CHIP_CEDAR_68E5 */ + 0x68E8, /* PCI_CHIP_CEDAR_68E8 */ + 0x68E9, /* PCI_CHIP_CEDAR_68E9 */ + 0x68F1, /* PCI_CHIP_CEDAR_68F1 */ + 0x68F8, /* PCI_CHIP_CEDAR_68F8 */ + 0x68F9, /* PCI_CHIP_CEDAR_68F9 */ + 0x68FE, /* PCI_CHIP_CEDAR_68FE */ + 0x68C0, /* PCI_CHIP_REDWOOD_68C0 */ + 0x68C1, /* PCI_CHIP_REDWOOD_68C1 */ + 0x68C8, /* PCI_CHIP_REDWOOD_68C8 */ + 0x68C9, /* PCI_CHIP_REDWOOD_68C9 */ + 0x68D8, /* PCI_CHIP_REDWOOD_68D8 */ + 0x68D9, /* PCI_CHIP_REDWOOD_68D9 */ + 0x68DA, /* PCI_CHIP_REDWOOD_68DA */ + 0x68DE, /* PCI_CHIP_REDWOOD_68DE */ + 0x68A0, /* PCI_CHIP_JUNIPER_68A0 */ + 0x68A1, /* PCI_CHIP_JUNIPER_68A1 */ + 0x68A8, /* PCI_CHIP_JUNIPER_68A8 */ + 0x68A9, /* PCI_CHIP_JUNIPER_68A9 */ + 0x68B0, /* PCI_CHIP_JUNIPER_68B0 */ + 0x68B8, /* PCI_CHIP_JUNIPER_68B8 */ + 0x68B9, /* PCI_CHIP_JUNIPER_68B9 */ + 0x68BE, /* PCI_CHIP_JUNIPER_68BE */ + 0x6880, /* PCI_CHIP_CYPRESS_6880 */ + 0x6888, /* PCI_CHIP_CYPRESS_6888 */ + 0x6889, /* PCI_CHIP_CYPRESS_6889 */ + 0x688A, /* PCI_CHIP_CYPRESS_688A */ + 0x6898, /* PCI_CHIP_CYPRESS_6898 */ + 0x6899, /* PCI_CHIP_CYPRESS_6899 */ + 0x689E, /* PCI_CHIP_CYPRESS_689E */ + 0x689C, /* PCI_CHIP_HEMLOCK_689C */ + 0x689D, /* PCI_CHIP_HEMLOCK_689D */ +}; + +const struct dri2_driver_map driver_map[] = { + { 0x8086, "i915", i915_chip_ids, ARRAY_SIZE(i915_chip_ids) }, + { 0x8086, "i965", i965_chip_ids, ARRAY_SIZE(i965_chip_ids) }, + { 0x1002, "radeon", r100_chip_ids, ARRAY_SIZE(r100_chip_ids) }, + { 0x1002, "r200", r200_chip_ids, ARRAY_SIZE(r200_chip_ids) }, + { 0x1002, "r300", r300_chip_ids, ARRAY_SIZE(r300_chip_ids) }, + { 0x1002, "r600", r600_chip_ids, ARRAY_SIZE(r600_chip_ids) }, +}; + +static char * +dri2_get_driver_for_fd(int fd) +{ + struct udev *udev; + struct udev_device *device, *parent; + struct stat buf; + const char *pci_id; + char *driver = NULL; + int vendor_id, chip_id, i, j; + + udev = udev_new(); + if (fstat(fd, &buf) < 0) { + _eglLog(_EGL_WARNING, "EGL-DRI2: failed to stat fd %d", fd); + goto out; + } + + device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev); + if (device == NULL) { + _eglLog(_EGL_WARNING, + "EGL-DRI2: could not create udev device for fd %d", fd); + goto out; + } + + parent = udev_device_get_parent(device); + if (parent == NULL) { + _eglLog(_EGL_WARNING, "DRI2: could not get parent device"); + goto out; + } + + pci_id = udev_device_get_property_value(parent, "PCI_ID"); + if (pci_id == NULL || sscanf(pci_id, "%x:%x", &vendor_id, &chip_id) != 2) { + _eglLog(_EGL_WARNING, "EGL-DRI2: malformed or no PCI ID"); + goto out; + } + + for (i = 0; i < ARRAY_SIZE(driver_map); i++) { + if (vendor_id != driver_map[i].vendor_id) + continue; + for (j = 0; j < driver_map[i].num_chips_ids; j++) + if (driver_map[i].chip_ids[j] == chip_id) { + driver = strdup(driver_map[i].driver); + _eglLog(_EGL_DEBUG, "pci id for %d: %04x:%04x, driver %s", + fd, vendor_id, chip_id, driver); + goto out; + } + } + + out: + udev_device_unref(device); + udev_unref(udev); + + return driver; +} + +static EGLBoolean +dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp, + EGLint *major, EGLint *minor) +{ + struct dri2_egl_display *dri2_dpy; + int i; + + dri2_dpy = malloc(sizeof *dri2_dpy); + if (!dri2_dpy) + return _eglError(EGL_BAD_ALLOC, "eglInitialize"); + + disp->DriverData = (void *) dri2_dpy; + dri2_dpy->fd = (int) disp->PlatformDisplay; + + dri2_dpy->driver_name = dri2_get_driver_for_fd(dri2_dpy->fd); + if (dri2_dpy->driver_name == NULL) + return _eglError(EGL_BAD_ALLOC, "DRI2: failed to get driver name"); + + if (!dri2_load_driver(disp)) + goto cleanup_driver_name; + + dri2_dpy->extensions[0] = &image_lookup_extension.base; + dri2_dpy->extensions[1] = &use_invalidate.base; + dri2_dpy->extensions[2] = NULL; + + if (!dri2_create_screen(disp)) + goto cleanup_driver; + + for (i = 0; dri2_dpy->driver_configs[i]; i++) + dri2_add_config(disp, dri2_dpy->driver_configs[i], i + 1, 0, 0); + + disp->Extensions.MESA_drm_image = EGL_TRUE; + disp->Extensions.KHR_image_base = EGL_TRUE; + disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE; + disp->Extensions.KHR_gl_texture_2D_image = EGL_TRUE; + + /* we're supporting EGL 1.4 */ + *major = 1; + *minor = 4; + + return EGL_TRUE; + + cleanup_driver: + dlclose(dri2_dpy->driver); + cleanup_driver_name: + free(dri2_dpy->driver_name); + + return EGL_FALSE; +} + +#endif + +/** + * Called via eglInitialize(), GLX_drv->API.Initialize(). + */ +static EGLBoolean +dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp, + EGLint *major, EGLint *minor) +{ + switch (disp->Platform) { + case _EGL_PLATFORM_X11: + return dri2_initialize_x11(drv, disp, major, minor); + +#ifdef HAVE_LIBUDEV + case _EGL_PLATFORM_DRM: + return dri2_initialize_drm(drv, disp, major, minor); +#endif + + default: + return EGL_FALSE; + } +} + +/** + * Called via eglTerminate(), drv->API.Terminate(). + */ +static EGLBoolean +dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + + _eglReleaseDisplayResources(drv, disp); + _eglCleanupDisplay(disp); + + dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen); + close(dri2_dpy->fd); + dlclose(dri2_dpy->driver); + if (disp->PlatformDisplay == NULL) + xcb_disconnect(dri2_dpy->conn); + free(dri2_dpy); + disp->DriverData = NULL; + + return EGL_TRUE; +} + + +/** + * Called via eglCreateContext(), drv->API.CreateContext(). + */ +static _EGLContext * +dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, + _EGLContext *share_list, const EGLint *attrib_list) +{ + struct dri2_egl_context *dri2_ctx; + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_context *dri2_ctx_shared = dri2_egl_context(share_list); + struct dri2_egl_config *dri2_config = dri2_egl_config(conf); + const __DRIconfig *dri_config; + int api; + + (void) drv; + + dri2_ctx = malloc(sizeof *dri2_ctx); + if (!dri2_ctx) { + _eglError(EGL_BAD_ALLOC, "eglCreateContext"); + return NULL; + } + + if (!_eglInitContext(&dri2_ctx->base, disp, conf, attrib_list)) + goto cleanup; + + switch (dri2_ctx->base.ClientAPI) { + case EGL_OPENGL_ES_API: + switch (dri2_ctx->base.ClientVersion) { + case 1: + api = __DRI_API_GLES; + break; + case 2: + api = __DRI_API_GLES2; + break; + default: + _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); + return NULL; + } + break; + case EGL_OPENGL_API: + api = __DRI_API_OPENGL; + break; + default: + _eglError(EGL_BAD_PARAMETER, "eglCreateContext"); + return NULL; + } + + if (conf != NULL) + dri_config = dri2_config->dri_config; + else + dri_config = NULL; + + if (dri2_dpy->dri2->base.version >= 2) { + dri2_ctx->dri_context = + dri2_dpy->dri2->createNewContextForAPI(dri2_dpy->dri_screen, + api, + dri_config, + dri2_ctx_shared ? + dri2_ctx_shared->dri_context : NULL, + dri2_ctx); + } else if (api == __DRI_API_OPENGL) { + dri2_ctx->dri_context = + dri2_dpy->dri2->createNewContext(dri2_dpy->dri_screen, + dri2_config->dri_config, + dri2_ctx_shared ? + dri2_ctx_shared->dri_context : NULL, + dri2_ctx); + } else { + /* fail */ + } + + if (!dri2_ctx->dri_context) + goto cleanup; + + return &dri2_ctx->base; + + cleanup: + free(dri2_ctx); + return NULL; +} + +static EGLBoolean +dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); + + (void) drv; + + if (!_eglPutSurface(surf)) + return EGL_TRUE; + + (*dri2_dpy->core->destroyDrawable)(dri2_surf->dri_drawable); + + xcb_dri2_destroy_drawable (dri2_dpy->conn, dri2_surf->drawable); + + if (surf->Type == EGL_PBUFFER_BIT) + xcb_free_pixmap (dri2_dpy->conn, dri2_surf->drawable); + + free(surf); + + return EGL_TRUE; +} + +/** + * Called via eglMakeCurrent(), drv->API.MakeCurrent(). + */ +static EGLBoolean +dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, + _EGLSurface *rsurf, _EGLContext *ctx) +{ + struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_surface *dri2_dsurf = dri2_egl_surface(dsurf); + struct dri2_egl_surface *dri2_rsurf = dri2_egl_surface(rsurf); + struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); + _EGLContext *old_ctx; + _EGLSurface *old_dsurf, *old_rsurf; + __DRIdrawable *ddraw, *rdraw; + __DRIcontext *cctx; + + /* make new bindings */ + if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) + return EGL_FALSE; + + /* flush before context switch */ + if (old_ctx && dri2_drv->glFlush) + dri2_drv->glFlush(); + + ddraw = (dri2_dsurf) ? dri2_dsurf->dri_drawable : NULL; + rdraw = (dri2_rsurf) ? dri2_rsurf->dri_drawable : NULL; + cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL; + + if ((cctx == NULL && ddraw == NULL && rdraw == NULL) || + dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { + dri2_destroy_surface(drv, disp, old_dsurf); + dri2_destroy_surface(drv, disp, old_rsurf); + if (old_ctx) { + /* unbind the old context only when there is no new context bound */ + if (!ctx) { + __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context; + dri2_dpy->core->unbindContext(old_cctx); + } + /* no destroy? */ + _eglPutContext(old_ctx); + } + + return EGL_TRUE; + } else { + /* undo the previous _eglBindContext */ + _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &dsurf, &rsurf); + assert(&dri2_ctx->base == ctx && + &dri2_dsurf->base == dsurf && + &dri2_rsurf->base == rsurf); + + _eglPutSurface(dsurf); + _eglPutSurface(rsurf); + _eglPutContext(ctx); + + _eglPutSurface(old_dsurf); + _eglPutSurface(old_rsurf); + _eglPutContext(old_ctx); + + return EGL_FALSE; + } +} + +/** + * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). + */ +static _EGLSurface * +dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type, + _EGLConfig *conf, EGLNativeWindowType window, + const EGLint *attrib_list) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_config *dri2_conf = dri2_egl_config(conf); + struct dri2_egl_surface *dri2_surf; + xcb_get_geometry_cookie_t cookie; + xcb_get_geometry_reply_t *reply; + xcb_screen_iterator_t s; + xcb_generic_error_t *error; + + (void) drv; + + dri2_surf = malloc(sizeof *dri2_surf); + if (!dri2_surf) { + _eglError(EGL_BAD_ALLOC, "dri2_create_surface"); + return NULL; + } + + if (!_eglInitSurface(&dri2_surf->base, disp, type, conf, attrib_list)) + goto cleanup_surf; + + dri2_surf->region = XCB_NONE; + if (type == EGL_PBUFFER_BIT) { + dri2_surf->drawable = xcb_generate_id(dri2_dpy->conn); + s = xcb_setup_roots_iterator(xcb_get_setup(dri2_dpy->conn)); + xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize, + dri2_surf->drawable, s.data->root, + dri2_surf->base.Width, dri2_surf->base.Height); + } else { + dri2_surf->drawable = window; + } + + dri2_surf->dri_drawable = + (*dri2_dpy->dri2->createNewDrawable) (dri2_dpy->dri_screen, + dri2_conf->dri_config, dri2_surf); + if (dri2_surf->dri_drawable == NULL) { + _eglError(EGL_BAD_ALLOC, "dri2->createNewDrawable"); + goto cleanup_pixmap; + } + + xcb_dri2_create_drawable (dri2_dpy->conn, dri2_surf->drawable); + + if (type != EGL_PBUFFER_BIT) { + cookie = xcb_get_geometry (dri2_dpy->conn, dri2_surf->drawable); + reply = xcb_get_geometry_reply (dri2_dpy->conn, cookie, &error); + if (reply == NULL || error != NULL) { + _eglError(EGL_BAD_ALLOC, "xcb_get_geometry"); + free(error); + goto cleanup_dri_drawable; + } + + dri2_surf->base.Width = reply->width; + dri2_surf->base.Height = reply->height; + free(reply); + } + + return &dri2_surf->base; + + cleanup_dri_drawable: + dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable); + cleanup_pixmap: + if (type == EGL_PBUFFER_BIT) + xcb_free_pixmap(dri2_dpy->conn, dri2_surf->drawable); + cleanup_surf: + free(dri2_surf); + + return NULL; +} + +/** + * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). + */ +static _EGLSurface * +dri2_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp, + _EGLConfig *conf, EGLNativeWindowType window, + const EGLint *attrib_list) +{ + return dri2_create_surface(drv, disp, EGL_WINDOW_BIT, conf, + window, attrib_list); +} + +static _EGLSurface * +dri2_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *disp, + _EGLConfig *conf, EGLNativePixmapType pixmap, + const EGLint *attrib_list) +{ + return dri2_create_surface(drv, disp, EGL_PIXMAP_BIT, conf, + pixmap, attrib_list); +} + +static _EGLSurface * +dri2_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp, + _EGLConfig *conf, const EGLint *attrib_list) +{ + return dri2_create_surface(drv, disp, EGL_PBUFFER_BIT, conf, + XCB_WINDOW_NONE, attrib_list); +} + +static EGLBoolean +dri2_copy_region(_EGLDriver *drv, _EGLDisplay *disp, + _EGLSurface *draw, xcb_xfixes_region_t region) +{ + struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); + _EGLContext *ctx; + xcb_dri2_copy_region_cookie_t cookie; + + if (dri2_drv->glFlush) { + ctx = _eglGetCurrentContext(); + if (ctx && ctx->DrawSurface == &dri2_surf->base) + dri2_drv->glFlush(); + } + + (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); + +#if 0 + /* FIXME: Add support for dri swapbuffers, that'll give us swap + * interval and page flipping (at least for fullscreen windows) as + * well as the page flip event. Unless surface->SwapBehavior is + * EGL_BUFFER_PRESERVED. */ +#if __DRI2_FLUSH_VERSION >= 2 + if (pdraw->psc->f) + (*pdraw->psc->f->flushInvalidate)(pdraw->driDrawable); +#endif +#endif + + if (!dri2_surf->have_fake_front) + return EGL_TRUE; + + cookie = xcb_dri2_copy_region_unchecked(dri2_dpy->conn, + dri2_surf->drawable, + region, + XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT, + XCB_DRI2_ATTACHMENT_BUFFER_FAKE_FRONT_LEFT); + free(xcb_dri2_copy_region_reply(dri2_dpy->conn, cookie, NULL)); + + return EGL_TRUE; +} + +static EGLBoolean +dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) +{ + struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); + + return dri2_copy_region(drv, disp, draw, dri2_surf->region); +} + +static EGLBoolean +dri2_swap_buffers_region(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw, + EGLint numRects, const EGLint *rects) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); + EGLBoolean ret; + xcb_xfixes_region_t region; + xcb_rectangle_t rectangles[16]; + int i; + + if (numRects > (int)ARRAY_SIZE(rectangles)) + return dri2_copy_region(drv, disp, draw, dri2_surf->region); + + /* FIXME: Invert y here? */ + for (i = 0; i < numRects; i++) { + rectangles[i].x = rects[i * 4]; + rectangles[i].y = rects[i * 4 + 1]; + rectangles[i].width = rects[i * 4 + 2]; + rectangles[i].height = rects[i * 4 + 3]; + } + + region = xcb_generate_id(dri2_dpy->conn); + xcb_xfixes_create_region(dri2_dpy->conn, region, numRects, rectangles); + ret = dri2_copy_region(drv, disp, draw, region); + xcb_xfixes_destroy_region(dri2_dpy->conn, region); + + return ret; +} + +/* + * Called from eglGetProcAddress() via drv->API.GetProcAddress(). + */ +static _EGLProc +dri2_get_proc_address(_EGLDriver *drv, const char *procname) +{ + (void) drv; + + /* FIXME: Do we need to support lookup of EGL symbols too? */ + + return (_EGLProc) _glapi_get_proc_address(procname); +} + +static EGLBoolean +dri2_wait_client(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_surface *dri2_surf = dri2_egl_surface(ctx->DrawSurface); + + (void) drv; + + /* FIXME: If EGL allows frontbuffer rendering for window surfaces, + * we need to copy fake to real here.*/ + + (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); + + return EGL_TRUE; +} + +static EGLBoolean +dri2_wait_native(_EGLDriver *drv, _EGLDisplay *disp, EGLint engine) +{ + (void) drv; + (void) disp; + + if (engine != EGL_CORE_NATIVE_ENGINE) + return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); + /* glXWaitX(); */ + + return EGL_TRUE; +} + +static void +dri2_unload(_EGLDriver *drv) +{ + struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv); + free(dri2_drv); +} + +static EGLBoolean +dri2_copy_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, + EGLNativePixmapType target) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); + xcb_gcontext_t gc; + + (void) drv; + + (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); + + gc = xcb_generate_id(dri2_dpy->conn); + xcb_create_gc(dri2_dpy->conn, gc, target, 0, NULL); + xcb_copy_area(dri2_dpy->conn, + dri2_surf->drawable, + target, + gc, + 0, 0, + 0, 0, + dri2_surf->base.Width, + dri2_surf->base.Height); + xcb_free_gc(dri2_dpy->conn, gc); + + return EGL_TRUE; +} + +static EGLBoolean +dri2_bind_tex_image(_EGLDriver *drv, + _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); + struct dri2_egl_context *dri2_ctx; + _EGLContext *ctx; + GLint format, target; + + ctx = _eglGetCurrentContext(); + dri2_ctx = dri2_egl_context(ctx); + + if (!_eglBindTexImage(drv, disp, surf, buffer)) + return EGL_FALSE; + + switch (dri2_surf->base.TextureFormat) { + case EGL_TEXTURE_RGB: + format = __DRI_TEXTURE_FORMAT_RGB; + break; + case EGL_TEXTURE_RGBA: + format = __DRI_TEXTURE_FORMAT_RGBA; + break; + default: + assert(0); + } + + switch (dri2_surf->base.TextureTarget) { + case EGL_TEXTURE_2D: + target = GL_TEXTURE_2D; + break; + default: + assert(0); + } + + (*dri2_dpy->tex_buffer->setTexBuffer2)(dri2_ctx->dri_context, + target, format, + dri2_surf->dri_drawable); + + return EGL_TRUE; +} + +static EGLBoolean +dri2_release_tex_image(_EGLDriver *drv, + _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) +{ + (void) drv; + (void) disp; + (void) surf; + (void) buffer; + + return EGL_TRUE; +} + +static _EGLImage * +dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, + EGLClientBuffer buffer, const EGLint *attr_list) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_image *dri2_img; + unsigned int attachments[1]; + xcb_drawable_t drawable; + xcb_dri2_get_buffers_cookie_t buffers_cookie; + xcb_dri2_get_buffers_reply_t *buffers_reply; + xcb_dri2_dri2_buffer_t *buffers; + xcb_get_geometry_cookie_t geometry_cookie; + xcb_get_geometry_reply_t *geometry_reply; + xcb_generic_error_t *error; + int stride, format; + + (void) ctx; + + drawable = (xcb_drawable_t) buffer; + xcb_dri2_create_drawable (dri2_dpy->conn, drawable); + attachments[0] = XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT; + buffers_cookie = + xcb_dri2_get_buffers_unchecked (dri2_dpy->conn, + drawable, 1, 1, attachments); + geometry_cookie = xcb_get_geometry (dri2_dpy->conn, drawable); + buffers_reply = xcb_dri2_get_buffers_reply (dri2_dpy->conn, + buffers_cookie, NULL); + buffers = xcb_dri2_get_buffers_buffers (buffers_reply); + if (buffers == NULL) { + return NULL; + } + + geometry_reply = xcb_get_geometry_reply (dri2_dpy->conn, + geometry_cookie, &error); + if (geometry_reply == NULL || error != NULL) { + _eglError(EGL_BAD_ALLOC, "xcb_get_geometry"); + free(error); + free(buffers_reply); + } + + switch (geometry_reply->depth) { + case 16: + format = __DRI_IMAGE_FORMAT_RGB565; + break; + case 24: + format = __DRI_IMAGE_FORMAT_XRGB8888; + break; + case 32: + format = __DRI_IMAGE_FORMAT_ARGB8888; + break; + default: + _eglError(EGL_BAD_PARAMETER, + "dri2_create_image_khr: unsupported pixmap depth"); + free(buffers_reply); + free(geometry_reply); + return NULL; + } + + dri2_img = malloc(sizeof *dri2_img); + if (!dri2_img) { + free(buffers_reply); + free(geometry_reply); + _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); + return EGL_NO_IMAGE_KHR; + } + + if (!_eglInitImage(&dri2_img->base, disp)) { + free(buffers_reply); + free(geometry_reply); + return EGL_NO_IMAGE_KHR; + } + + stride = buffers[0].pitch / buffers[0].cpp; + dri2_img->dri_image = + dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, + buffers_reply->width, + buffers_reply->height, + format, + buffers[0].name, + stride, + dri2_img); + + free(buffers_reply); + free(geometry_reply); + + return &dri2_img->base; +} + +static _EGLImage * +dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, + EGLClientBuffer buffer, + const EGLint *attr_list) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); + struct dri2_egl_image *dri2_img; + GLuint renderbuffer = (GLuint) buffer; + + if (renderbuffer == 0) { + _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); + return EGL_NO_IMAGE_KHR; + } + + dri2_img = malloc(sizeof *dri2_img); + if (!dri2_img) { + _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); + return EGL_NO_IMAGE_KHR; + } + + if (!_eglInitImage(&dri2_img->base, disp)) + return EGL_NO_IMAGE_KHR; + + dri2_img->dri_image = + dri2_dpy->image->createImageFromRenderbuffer(dri2_ctx->dri_context, + renderbuffer, + dri2_img); + + return &dri2_img->base; +} + +static _EGLImage * +dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx, + EGLClientBuffer buffer, const EGLint *attr_list) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_image *dri2_img; + EGLint format, name, pitch, err; + _EGLImageAttribs attrs; + + (void) ctx; + + name = (EGLint) buffer; + + err = _eglParseImageAttribList(&attrs, disp, attr_list); + if (err != EGL_SUCCESS) + return NULL; + + if (attrs.Width <= 0 || attrs.Height <= 0 || + attrs.DRMBufferStrideMESA <= 0) { + _eglError(EGL_BAD_PARAMETER, + "bad width, height or stride"); + return NULL; + } + + switch (attrs.DRMBufferFormatMESA) { + case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: + format = __DRI_IMAGE_FORMAT_ARGB8888; + pitch = attrs.DRMBufferStrideMESA; + break; + default: + _eglError(EGL_BAD_PARAMETER, + "dri2_create_image_khr: unsupported pixmap depth"); + return NULL; + } + + dri2_img = malloc(sizeof *dri2_img); + if (!dri2_img) { + _eglError(EGL_BAD_ALLOC, "dri2_create_image_mesa_drm"); + return NULL; + } + + if (!_eglInitImage(&dri2_img->base, disp)) { + free(dri2_img); + return NULL; + } + + dri2_img->dri_image = + dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen, + attrs.Width, + attrs.Height, + format, + name, + pitch, + dri2_img); + if (dri2_img->dri_image == NULL) { + free(dri2_img); + _eglError(EGL_BAD_ALLOC, "dri2_create_image_mesa_drm"); + return NULL; + } + + return &dri2_img->base; +} + +static _EGLImage * +dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, + _EGLContext *ctx, EGLenum target, + EGLClientBuffer buffer, const EGLint *attr_list) +{ + (void) drv; + + switch (target) { + case EGL_NATIVE_PIXMAP_KHR: + return dri2_create_image_khr_pixmap(disp, ctx, buffer, attr_list); + case EGL_GL_RENDERBUFFER_KHR: + return dri2_create_image_khr_renderbuffer(disp, ctx, buffer, attr_list); + case EGL_DRM_BUFFER_MESA: + return dri2_create_image_mesa_drm_buffer(disp, ctx, buffer, attr_list); + default: + _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr"); + return EGL_NO_IMAGE_KHR; + } +} + +static EGLBoolean +dri2_destroy_image_khr(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *image) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_image *dri2_img = dri2_egl_image(image); + + (void) drv; + + dri2_dpy->image->destroyImage(dri2_img->dri_image); + free(dri2_img); + + return EGL_TRUE; +} + +static _EGLImage * +dri2_create_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, + const EGLint *attr_list) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_image *dri2_img; + _EGLImageAttribs attrs; + unsigned int dri_use, valid_mask; + int format; + EGLint err = EGL_SUCCESS; + + (void) drv; + + dri2_img = malloc(sizeof *dri2_img); + if (!dri2_img) { + _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); + return EGL_NO_IMAGE_KHR; + } + + if (!attr_list) { + err = EGL_BAD_PARAMETER; + goto cleanup_img; + } + + if (!_eglInitImage(&dri2_img->base, disp)) { + err = EGL_BAD_PARAMETER; + goto cleanup_img; + } + + err = _eglParseImageAttribList(&attrs, disp, attr_list); + if (err != EGL_SUCCESS) + goto cleanup_img; + + if (attrs.Width <= 0 || attrs.Height <= 0) { + _eglLog(_EGL_WARNING, "bad width or height (%dx%d)", + attrs.Width, attrs.Height); + goto cleanup_img; + } + + switch (attrs.DRMBufferFormatMESA) { + case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: + format = __DRI_IMAGE_FORMAT_ARGB8888; + break; + default: + _eglLog(_EGL_WARNING, "bad image format value 0x%04x", + attrs.DRMBufferFormatMESA); + goto cleanup_img; + } + + valid_mask = + EGL_DRM_BUFFER_USE_SCANOUT_MESA | + EGL_DRM_BUFFER_USE_SHARE_MESA; + if (attrs.DRMBufferUseMESA & ~valid_mask) { + _eglLog(_EGL_WARNING, "bad image use bit 0x%04x", + attrs.DRMBufferUseMESA & ~valid_mask); + goto cleanup_img; + } + + dri_use = 0; + if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SHARE_MESA) + dri_use |= __DRI_IMAGE_USE_SHARE; + if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SCANOUT_MESA) + dri_use |= __DRI_IMAGE_USE_SCANOUT; + + dri2_img->dri_image = + dri2_dpy->image->createImage(dri2_dpy->dri_screen, + attrs.Width, attrs.Height, + format, dri_use, dri2_img); + if (dri2_img->dri_image == NULL) { + err = EGL_BAD_ALLOC; + goto cleanup_img; + } + + return &dri2_img->base; + + cleanup_img: + free(dri2_img); + _eglError(err, "dri2_create_drm_image_mesa"); + + return EGL_NO_IMAGE_KHR; +} + +static EGLBoolean +dri2_export_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img, + EGLint *name, EGLint *handle, EGLint *stride) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_image *dri2_img = dri2_egl_image(img); + + (void) drv; + + if (name && !dri2_dpy->image->queryImage(dri2_img->dri_image, + __DRI_IMAGE_ATTRIB_NAME, name)) { + _eglError(EGL_BAD_ALLOC, "dri2_export_drm_image_mesa"); + return EGL_FALSE; + } + + if (handle) + dri2_dpy->image->queryImage(dri2_img->dri_image, + __DRI_IMAGE_ATTRIB_HANDLE, handle); + + if (stride) + dri2_dpy->image->queryImage(dri2_img->dri_image, + __DRI_IMAGE_ATTRIB_STRIDE, stride); + + return EGL_TRUE; +} + +/** + * This is the main entrypoint into the driver, called by libEGL. + * Create a new _EGLDriver object and init its dispatch table. + */ +_EGLDriver * +_eglMain(const char *args) +{ + struct dri2_egl_driver *dri2_drv; + + (void) args; + + dri2_drv = malloc(sizeof *dri2_drv); + if (!dri2_drv) + return NULL; + + memset(dri2_drv, 0, sizeof *dri2_drv); + _eglInitDriverFallbacks(&dri2_drv->base); + dri2_drv->base.API.Initialize = dri2_initialize; + dri2_drv->base.API.Terminate = dri2_terminate; + dri2_drv->base.API.CreateContext = dri2_create_context; + dri2_drv->base.API.MakeCurrent = dri2_make_current; + dri2_drv->base.API.CreateWindowSurface = dri2_create_window_surface; + dri2_drv->base.API.CreatePixmapSurface = dri2_create_pixmap_surface; + dri2_drv->base.API.CreatePbufferSurface = dri2_create_pbuffer_surface; + dri2_drv->base.API.DestroySurface = dri2_destroy_surface; + dri2_drv->base.API.SwapBuffers = dri2_swap_buffers; + dri2_drv->base.API.GetProcAddress = dri2_get_proc_address; + dri2_drv->base.API.WaitClient = dri2_wait_client; + dri2_drv->base.API.WaitNative = dri2_wait_native; + dri2_drv->base.API.CopyBuffers = dri2_copy_buffers; + dri2_drv->base.API.BindTexImage = dri2_bind_tex_image; + dri2_drv->base.API.ReleaseTexImage = dri2_release_tex_image; + dri2_drv->base.API.CreateImageKHR = dri2_create_image_khr; + dri2_drv->base.API.DestroyImageKHR = dri2_destroy_image_khr; + dri2_drv->base.API.SwapBuffersRegionNOK = dri2_swap_buffers_region; + dri2_drv->base.API.CreateDRMImageMESA = dri2_create_drm_image_mesa; + dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa; + + dri2_drv->base.Name = "DRI2"; + dri2_drv->base.Unload = dri2_unload; + + dri2_drv->glFlush = + (void (*)(void)) dri2_get_proc_address(&dri2_drv->base, "glFlush"); + + return &dri2_drv->base; +} diff --git a/src/egl/drivers/glx/Makefile b/src/egl/drivers/glx/Makefile new file mode 100644 index 0000000..d976b91 --- /dev/null +++ b/src/egl/drivers/glx/Makefile @@ -0,0 +1,16 @@ +# src/egl/drivers/glx/Makefile + +TOP = ../../../.. +include $(TOP)/configs/current + +EGL_DRIVER = egl_glx.so +EGL_SOURCES = egl_glx.c + +EGL_INCLUDES = \ + -I$(TOP)/include \ + -I$(TOP)/src/egl/main + +EGL_CFLAGS = $(X11_CFLAGS) +EGL_LIBS = $(X11_LIBS) -lGL + +include ../Makefile.template diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c new file mode 100644 index 0000000..8ec7c48 --- /dev/null +++ b/src/egl/drivers/glx/egl_glx.c @@ -0,0 +1,1020 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * This is an EGL driver that wraps GLX. This gives the benefit of being + * completely agnostic of the direct rendering implementation. + * + * Authors: Alan Hourihane + */ + +#include +#include +#include +#include +#include + +#include "eglconfig.h" +#include "eglcontext.h" +#include "egldefines.h" +#include "egldisplay.h" +#include "egldriver.h" +#include "eglcurrent.h" +#include "egllog.h" +#include "eglsurface.h" + +#define CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T)) + +#ifndef GLX_VERSION_1_4 +#error "GL/glx.h must be equal to or greater than GLX 1.4" +#endif + +/** subclass of _EGLDriver */ +struct GLX_egl_driver +{ + _EGLDriver Base; /**< base class */ +}; + + +/** driver data of _EGLDisplay */ +struct GLX_egl_display +{ + Display *dpy; + XVisualInfo *visuals; + GLXFBConfig *fbconfigs; + + int glx_maj, glx_min; + + const char *extensions; + EGLBoolean have_1_3; + EGLBoolean have_make_current_read; + EGLBoolean have_fbconfig; + EGLBoolean have_pbuffer; + + /* GLX_SGIX_pbuffer */ + PFNGLXCREATEGLXPBUFFERSGIXPROC glXCreateGLXPbufferSGIX; + PFNGLXDESTROYGLXPBUFFERSGIXPROC glXDestroyGLXPbufferSGIX; + + /* workaround quirks of different GLX implementations */ + EGLBoolean single_buffered_quirk; + EGLBoolean glx_window_quirk; + +}; + + +/** subclass of _EGLContext */ +struct GLX_egl_context +{ + _EGLContext Base; /**< base class */ + + GLXContext context; +}; + + +/** subclass of _EGLSurface */ +struct GLX_egl_surface +{ + _EGLSurface Base; /**< base class */ + + Drawable drawable; + GLXDrawable glx_drawable; + + void (*destroy)(Display *, GLXDrawable); +}; + + +/** subclass of _EGLConfig */ +struct GLX_egl_config +{ + _EGLConfig Base; /**< base class */ + EGLBoolean double_buffered; + int index; +}; + +/* standard typecasts */ +_EGL_DRIVER_STANDARD_TYPECASTS(GLX_egl) + +static int +GLX_egl_config_index(_EGLConfig *conf) +{ + struct GLX_egl_config *GLX_conf = GLX_egl_config(conf); + return GLX_conf->index; +} + + +static const struct { + int attr; + int egl_attr; +} fbconfig_attributes[] = { + /* table 3.1 of GLX 1.4 */ + { GLX_FBCONFIG_ID, 0 }, + { GLX_BUFFER_SIZE, EGL_BUFFER_SIZE }, + { GLX_LEVEL, EGL_LEVEL }, + { GLX_DOUBLEBUFFER, 0 }, + { GLX_STEREO, 0 }, + { GLX_AUX_BUFFERS, 0 }, + { GLX_RED_SIZE, EGL_RED_SIZE }, + { GLX_GREEN_SIZE, EGL_GREEN_SIZE }, + { GLX_BLUE_SIZE, EGL_BLUE_SIZE }, + { GLX_ALPHA_SIZE, EGL_ALPHA_SIZE }, + { GLX_DEPTH_SIZE, EGL_DEPTH_SIZE }, + { GLX_STENCIL_SIZE, EGL_STENCIL_SIZE }, + { GLX_ACCUM_RED_SIZE, 0 }, + { GLX_ACCUM_GREEN_SIZE, 0 }, + { GLX_ACCUM_BLUE_SIZE, 0 }, + { GLX_ACCUM_ALPHA_SIZE, 0 }, + { GLX_SAMPLE_BUFFERS, EGL_SAMPLE_BUFFERS }, + { GLX_SAMPLES, EGL_SAMPLES }, + { GLX_RENDER_TYPE, 0 }, + { GLX_DRAWABLE_TYPE, EGL_SURFACE_TYPE }, + { GLX_X_RENDERABLE, EGL_NATIVE_RENDERABLE }, + { GLX_X_VISUAL_TYPE, EGL_NATIVE_VISUAL_TYPE }, + { GLX_CONFIG_CAVEAT, EGL_CONFIG_CAVEAT }, + { GLX_TRANSPARENT_TYPE, EGL_TRANSPARENT_TYPE }, + { GLX_TRANSPARENT_INDEX_VALUE, 0 }, + { GLX_TRANSPARENT_RED_VALUE, EGL_TRANSPARENT_RED_VALUE }, + { GLX_TRANSPARENT_GREEN_VALUE, EGL_TRANSPARENT_GREEN_VALUE }, + { GLX_TRANSPARENT_BLUE_VALUE, EGL_TRANSPARENT_BLUE_VALUE }, + { GLX_MAX_PBUFFER_WIDTH, EGL_MAX_PBUFFER_WIDTH }, + { GLX_MAX_PBUFFER_HEIGHT, EGL_MAX_PBUFFER_HEIGHT }, + { GLX_MAX_PBUFFER_PIXELS, EGL_MAX_PBUFFER_PIXELS }, + { GLX_VISUAL_ID, EGL_NATIVE_VISUAL_ID } +}; + + +static EGLBoolean +convert_fbconfig(Display *dpy, GLXFBConfig fbconfig, + struct GLX_egl_config *GLX_conf) +{ + int err, attr, val; + unsigned i; + + /* must have rgba bit */ + err = glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &val); + if (err || !(val & GLX_RGBA_BIT)) + return EGL_FALSE; + + /* must know whether it is double-buffered */ + err = glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &val); + if (err) + return EGL_FALSE; + GLX_conf->double_buffered = val; + + GLX_conf->Base.RenderableType = EGL_OPENGL_BIT; + GLX_conf->Base.Conformant = EGL_OPENGL_BIT; + + for (i = 0; i < ARRAY_SIZE(fbconfig_attributes); i++) { + EGLint egl_attr, egl_val; + + attr = fbconfig_attributes[i].attr; + egl_attr = fbconfig_attributes[i].egl_attr; + if (!egl_attr) + continue; + + err = glXGetFBConfigAttrib(dpy, fbconfig, attr, &val); + if (err) { + if (err == GLX_BAD_ATTRIBUTE) { + err = 0; + continue; + } + break; + } + + switch (egl_attr) { + case EGL_SURFACE_TYPE: + egl_val = 0; + if (val & GLX_WINDOW_BIT) + egl_val |= EGL_WINDOW_BIT; + /* pixmap and pbuffer surfaces must be single-buffered in EGL */ + if (!GLX_conf->double_buffered) { + if (val & GLX_PIXMAP_BIT) + egl_val |= EGL_PIXMAP_BIT; + if (val & GLX_PBUFFER_BIT) + egl_val |= EGL_PBUFFER_BIT; + } + break; + case EGL_NATIVE_VISUAL_TYPE: + switch (val) { + case GLX_TRUE_COLOR: + egl_val = TrueColor; + break; + case GLX_DIRECT_COLOR: + egl_val = DirectColor; + break; + case GLX_PSEUDO_COLOR: + egl_val = PseudoColor; + break; + case GLX_STATIC_COLOR: + egl_val = StaticColor; + break; + case GLX_GRAY_SCALE: + egl_val = GrayScale; + break; + case GLX_STATIC_GRAY: + egl_val = StaticGray; + break; + default: + egl_val = EGL_NONE; + break; + } + break; + case EGL_CONFIG_CAVEAT: + egl_val = EGL_NONE; + if (val == GLX_SLOW_CONFIG) { + egl_val = EGL_SLOW_CONFIG; + } + else if (val == GLX_NON_CONFORMANT_CONFIG) { + GLX_conf->Base.Conformant &= ~EGL_OPENGL_BIT; + egl_val = EGL_NONE; + } + break; + case EGL_TRANSPARENT_TYPE: + egl_val = (val == GLX_TRANSPARENT_RGB) ? + EGL_TRANSPARENT_RGB : EGL_NONE; + break; + default: + egl_val = val; + break; + } + + _eglSetConfigKey(&GLX_conf->Base, egl_attr, egl_val); + } + if (err) + return EGL_FALSE; + + if (!GLX_conf->Base.SurfaceType) + return EGL_FALSE; + + return EGL_TRUE; +} + +static const struct { + int attr; + int egl_attr; +} visual_attributes[] = { + /* table 3.7 of GLX 1.4 */ + { GLX_USE_GL, 0 }, + { GLX_BUFFER_SIZE, EGL_BUFFER_SIZE }, + { GLX_LEVEL, EGL_LEVEL }, + { GLX_RGBA, 0 }, + { GLX_DOUBLEBUFFER, 0 }, + { GLX_STEREO, 0 }, + { GLX_AUX_BUFFERS, 0 }, + { GLX_RED_SIZE, EGL_RED_SIZE }, + { GLX_GREEN_SIZE, EGL_GREEN_SIZE }, + { GLX_BLUE_SIZE, EGL_BLUE_SIZE }, + { GLX_ALPHA_SIZE, EGL_ALPHA_SIZE }, + { GLX_DEPTH_SIZE, EGL_DEPTH_SIZE }, + { GLX_STENCIL_SIZE, EGL_STENCIL_SIZE }, + { GLX_ACCUM_RED_SIZE, 0 }, + { GLX_ACCUM_GREEN_SIZE, 0 }, + { GLX_ACCUM_BLUE_SIZE, 0 }, + { GLX_ACCUM_ALPHA_SIZE, 0 }, + { GLX_SAMPLE_BUFFERS, EGL_SAMPLE_BUFFERS }, + { GLX_SAMPLES, EGL_SAMPLES }, + { GLX_FBCONFIG_ID, 0 }, + /* GLX_EXT_visual_rating */ + { GLX_VISUAL_CAVEAT_EXT, EGL_CONFIG_CAVEAT } +}; + +static EGLBoolean +convert_visual(Display *dpy, XVisualInfo *vinfo, + struct GLX_egl_config *GLX_conf) +{ + int err, attr, val; + unsigned i; + + /* the visual must support OpenGL and RGBA buffer */ + err = glXGetConfig(dpy, vinfo, GLX_USE_GL, &val); + if (!err && val) + err = glXGetConfig(dpy, vinfo, GLX_RGBA, &val); + if (err || !val) + return EGL_FALSE; + + /* must know whether it is double-buffered */ + err = glXGetConfig(dpy, vinfo, GLX_DOUBLEBUFFER, &val); + if (err) + return EGL_FALSE; + GLX_conf->double_buffered = val; + + GLX_conf->Base.RenderableType = EGL_OPENGL_BIT; + GLX_conf->Base.Conformant = EGL_OPENGL_BIT; + GLX_conf->Base.SurfaceType = EGL_WINDOW_BIT; + /* pixmap surfaces must be single-buffered in EGL */ + if (!GLX_conf->double_buffered) + GLX_conf->Base.SurfaceType |= EGL_PIXMAP_BIT; + + GLX_conf->Base.NativeVisualID = vinfo->visualid; + GLX_conf->Base.NativeVisualType = vinfo->class; + GLX_conf->Base.NativeRenderable = EGL_TRUE; + + for (i = 0; i < ARRAY_SIZE(visual_attributes); i++) { + EGLint egl_attr, egl_val; + + attr = visual_attributes[i].attr; + egl_attr = visual_attributes[i].egl_attr; + if (!egl_attr) + continue; + + err = glXGetConfig(dpy, vinfo, attr, &val); + if (err) { + if (err == GLX_BAD_ATTRIBUTE) { + err = 0; + continue; + } + break; + } + + switch (egl_attr) { + case EGL_CONFIG_CAVEAT: + egl_val = EGL_NONE; + if (val == GLX_SLOW_VISUAL_EXT) { + egl_val = EGL_SLOW_CONFIG; + } + else if (val == GLX_NON_CONFORMANT_VISUAL_EXT) { + GLX_conf->Base.Conformant &= ~EGL_OPENGL_BIT; + egl_val = EGL_NONE; + } + break; + break; + default: + egl_val = val; + break; + } + _eglSetConfigKey(&GLX_conf->Base, egl_attr, egl_val); + } + + return (err) ? EGL_FALSE : EGL_TRUE; +} + + +static void +fix_config(struct GLX_egl_display *GLX_dpy, struct GLX_egl_config *GLX_conf) +{ + _EGLConfig *conf = &GLX_conf->Base; + + if (!GLX_conf->double_buffered && GLX_dpy->single_buffered_quirk) { + /* some GLX impls do not like single-buffered window surface */ + conf->SurfaceType &= ~EGL_WINDOW_BIT; + /* pbuffer bit is usually not set */ + if (GLX_dpy->have_pbuffer) + conf->SurfaceType |= EGL_PBUFFER_BIT; + } + + /* no visual attribs unless window bit is set */ + if (!(conf->SurfaceType & EGL_WINDOW_BIT)) { + conf->NativeVisualID = 0; + conf->NativeVisualType = EGL_NONE; + } + + if (conf->TransparentType != EGL_TRANSPARENT_RGB) { + /* some impls set them to -1 (GLX_DONT_CARE) */ + conf->TransparentRedValue = 0; + conf->TransparentGreenValue = 0; + conf->TransparentBlueValue = 0; + } + + /* make sure buffer size is set correctly */ + conf->BufferSize = + conf->RedSize + conf->GreenSize + conf->BlueSize + conf->AlphaSize; +} + + +static EGLBoolean +create_configs(_EGLDisplay *dpy, struct GLX_egl_display *GLX_dpy, + EGLint screen) +{ + EGLint num_configs = 0, i; + EGLint id = 1; + + if (GLX_dpy->have_fbconfig) { + GLX_dpy->fbconfigs = glXGetFBConfigs(GLX_dpy->dpy, screen, &num_configs); + } + else { + XVisualInfo vinfo_template; + long mask; + + vinfo_template.screen = screen; + mask = VisualScreenMask; + GLX_dpy->visuals = XGetVisualInfo(GLX_dpy->dpy, mask, &vinfo_template, + &num_configs); + } + + if (!num_configs) + return EGL_FALSE; + + for (i = 0; i < num_configs; i++) { + struct GLX_egl_config *GLX_conf, template; + EGLBoolean ok; + + memset(&template, 0, sizeof(template)); + _eglInitConfig(&template.Base, dpy, id); + if (GLX_dpy->have_fbconfig) + ok = convert_fbconfig(GLX_dpy->dpy, GLX_dpy->fbconfigs[i], &template); + else + ok = convert_visual(GLX_dpy->dpy, &GLX_dpy->visuals[i], &template); + if (!ok) + continue; + + fix_config(GLX_dpy, &template); + if (!_eglValidateConfig(&template.Base, EGL_FALSE)) { + _eglLog(_EGL_DEBUG, "GLX: failed to validate config %d", i); + continue; + } + + GLX_conf = CALLOC_STRUCT(GLX_egl_config); + if (GLX_conf) { + memcpy(GLX_conf, &template, sizeof(template)); + GLX_conf->index = i; + + _eglLinkConfig(&GLX_conf->Base); + id++; + } + } + + return EGL_TRUE; +} + + +static void +check_extensions(struct GLX_egl_display *GLX_dpy, EGLint screen) +{ + GLX_dpy->extensions = + glXQueryExtensionsString(GLX_dpy->dpy, screen); + if (GLX_dpy->extensions) { + /* glXGetProcAddress is assumed */ + + if (strstr(GLX_dpy->extensions, "GLX_SGI_make_current_read")) { + /* GLX 1.3 entry points are used */ + GLX_dpy->have_make_current_read = EGL_TRUE; + } + + if (strstr(GLX_dpy->extensions, "GLX_SGIX_fbconfig")) { + /* GLX 1.3 entry points are used */ + GLX_dpy->have_fbconfig = EGL_TRUE; + } + + if (strstr(GLX_dpy->extensions, "GLX_SGIX_pbuffer")) { + GLX_dpy->glXCreateGLXPbufferSGIX = (PFNGLXCREATEGLXPBUFFERSGIXPROC) + glXGetProcAddress((const GLubyte *) "glXCreateGLXPbufferSGIX"); + GLX_dpy->glXDestroyGLXPbufferSGIX = (PFNGLXDESTROYGLXPBUFFERSGIXPROC) + glXGetProcAddress((const GLubyte *) "glXDestroyGLXPbufferSGIX"); + + if (GLX_dpy->glXCreateGLXPbufferSGIX && + GLX_dpy->glXDestroyGLXPbufferSGIX && + GLX_dpy->have_fbconfig) + GLX_dpy->have_pbuffer = EGL_TRUE; + } + } + + if (GLX_dpy->glx_maj == 1 && GLX_dpy->glx_min >= 3) { + GLX_dpy->have_1_3 = EGL_TRUE; + GLX_dpy->have_make_current_read = EGL_TRUE; + GLX_dpy->have_fbconfig = EGL_TRUE; + GLX_dpy->have_pbuffer = EGL_TRUE; + } +} + + +static void +check_quirks(struct GLX_egl_display *GLX_dpy, EGLint screen) +{ + const char *vendor; + + GLX_dpy->single_buffered_quirk = EGL_TRUE; + GLX_dpy->glx_window_quirk = EGL_TRUE; + + vendor = glXGetClientString(GLX_dpy->dpy, GLX_VENDOR); + if (vendor && strstr(vendor, "NVIDIA")) { + vendor = glXQueryServerString(GLX_dpy->dpy, screen, GLX_VENDOR); + if (vendor && strstr(vendor, "NVIDIA")) { + _eglLog(_EGL_DEBUG, "disable quirks"); + GLX_dpy->single_buffered_quirk = EGL_FALSE; + GLX_dpy->glx_window_quirk = EGL_FALSE; + } + } +} + + +/** + * Called via eglInitialize(), GLX_drv->API.Initialize(). + */ +static EGLBoolean +GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp, + EGLint *major, EGLint *minor) +{ + struct GLX_egl_display *GLX_dpy; + + (void) drv; + + if (disp->Platform != _EGL_PLATFORM_X11) + return EGL_FALSE; + + GLX_dpy = CALLOC_STRUCT(GLX_egl_display); + if (!GLX_dpy) + return _eglError(EGL_BAD_ALLOC, "eglInitialize"); + + GLX_dpy->dpy = (Display *) disp->PlatformDisplay; + if (!GLX_dpy->dpy) { + GLX_dpy->dpy = XOpenDisplay(NULL); + if (!GLX_dpy->dpy) { + _eglLog(_EGL_WARNING, "GLX: XOpenDisplay failed"); + free(GLX_dpy); + return EGL_FALSE; + } + } + + if (!glXQueryVersion(GLX_dpy->dpy, &GLX_dpy->glx_maj, &GLX_dpy->glx_min)) { + _eglLog(_EGL_WARNING, "GLX: glXQueryVersion failed"); + if (!disp->PlatformDisplay) + XCloseDisplay(GLX_dpy->dpy); + free(GLX_dpy); + return EGL_FALSE; + } + + check_extensions(GLX_dpy, DefaultScreen(GLX_dpy->dpy)); + check_quirks(GLX_dpy, DefaultScreen(GLX_dpy->dpy)); + + create_configs(disp, GLX_dpy, DefaultScreen(GLX_dpy->dpy)); + if (!_eglGetArraySize(disp->Configs)) { + _eglLog(_EGL_WARNING, "GLX: failed to create any config"); + if (!disp->PlatformDisplay) + XCloseDisplay(GLX_dpy->dpy); + free(GLX_dpy); + return EGL_FALSE; + } + + disp->DriverData = (void *) GLX_dpy; + disp->ClientAPIsMask = EGL_OPENGL_BIT; + + /* we're supporting EGL 1.4 */ + *major = 1; + *minor = 4; + + return EGL_TRUE; +} + +/** + * Called via eglTerminate(), drv->API.Terminate(). + */ +static EGLBoolean +GLX_eglTerminate(_EGLDriver *drv, _EGLDisplay *disp) +{ + struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp); + + _eglReleaseDisplayResources(drv, disp); + _eglCleanupDisplay(disp); + + if (GLX_dpy->visuals) + XFree(GLX_dpy->visuals); + if (GLX_dpy->fbconfigs) + XFree(GLX_dpy->fbconfigs); + + if (!disp->PlatformDisplay) + XCloseDisplay(GLX_dpy->dpy); + free(GLX_dpy); + + disp->DriverData = NULL; + + return EGL_TRUE; +} + + +/** + * Called via eglCreateContext(), drv->API.CreateContext(). + */ +static _EGLContext * +GLX_eglCreateContext(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, + _EGLContext *share_list, const EGLint *attrib_list) +{ + struct GLX_egl_context *GLX_ctx = CALLOC_STRUCT(GLX_egl_context); + struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp); + struct GLX_egl_context *GLX_ctx_shared = GLX_egl_context(share_list); + + (void) drv; + + if (!GLX_ctx) { + _eglError(EGL_BAD_ALLOC, "eglCreateContext"); + return NULL; + } + + if (!_eglInitContext(&GLX_ctx->Base, disp, conf, attrib_list)) { + free(GLX_ctx); + return NULL; + } + + if (GLX_dpy->have_fbconfig) + GLX_ctx->context = + glXCreateNewContext(GLX_dpy->dpy, + GLX_dpy->fbconfigs[GLX_egl_config_index(conf)], + GLX_RGBA_TYPE, + GLX_ctx_shared ? GLX_ctx_shared->context : NULL, + GL_TRUE); + else + GLX_ctx->context = + glXCreateContext(GLX_dpy->dpy, + &GLX_dpy->visuals[GLX_egl_config_index(conf)], + GLX_ctx_shared ? GLX_ctx_shared->context : NULL, + GL_TRUE); + if (!GLX_ctx->context) { + free(GLX_ctx); + return NULL; + } + + return &GLX_ctx->Base; +} + + +/** + * Destroy a surface. The display is allowed to be uninitialized. + */ +static void +destroy_surface(_EGLDisplay *disp, _EGLSurface *surf) +{ + struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp); + struct GLX_egl_surface *GLX_surf = GLX_egl_surface(surf); + + if (GLX_surf->destroy) + GLX_surf->destroy(GLX_dpy->dpy, GLX_surf->glx_drawable); + + free(GLX_surf); +} + + +/** + * Called via eglMakeCurrent(), drv->API.MakeCurrent(). + */ +static EGLBoolean +GLX_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, + _EGLSurface *rsurf, _EGLContext *ctx) +{ + struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp); + struct GLX_egl_surface *GLX_dsurf = GLX_egl_surface(dsurf); + struct GLX_egl_surface *GLX_rsurf = GLX_egl_surface(rsurf); + struct GLX_egl_context *GLX_ctx = GLX_egl_context(ctx); + _EGLContext *old_ctx; + _EGLSurface *old_dsurf, *old_rsurf; + GLXDrawable ddraw, rdraw; + GLXContext cctx; + EGLBoolean ret = EGL_FALSE; + + (void) drv; + + /* make new bindings */ + if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) + return EGL_FALSE; + + ddraw = (GLX_dsurf) ? GLX_dsurf->glx_drawable : None; + rdraw = (GLX_rsurf) ? GLX_rsurf->glx_drawable : None; + cctx = (GLX_ctx) ? GLX_ctx->context : NULL; + + if (GLX_dpy->have_make_current_read) + ret = glXMakeContextCurrent(GLX_dpy->dpy, ddraw, rdraw, cctx); + else if (ddraw == rdraw) + ret = glXMakeCurrent(GLX_dpy->dpy, ddraw, cctx); + + if (ret) { + if (_eglPutSurface(old_dsurf)) + destroy_surface(disp, old_dsurf); + if (_eglPutSurface(old_rsurf)) + destroy_surface(disp, old_rsurf); + /* no destroy? */ + _eglPutContext(old_ctx); + } + else { + /* undo the previous _eglBindContext */ + _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &dsurf, &rsurf); + assert(&GLX_ctx->Base == ctx && + &GLX_dsurf->Base == dsurf && + &GLX_rsurf->Base == rsurf); + + _eglPutSurface(dsurf); + _eglPutSurface(rsurf); + _eglPutContext(ctx); + + _eglPutSurface(old_dsurf); + _eglPutSurface(old_rsurf); + _eglPutContext(old_ctx); + } + + return ret; +} + +/** Get size of given window */ +static Status +get_drawable_size(Display *dpy, Drawable d, uint *width, uint *height) +{ + Window root; + Status stat; + int xpos, ypos; + unsigned int w, h, bw, depth; + stat = XGetGeometry(dpy, d, &root, &xpos, &ypos, &w, &h, &bw, &depth); + *width = w; + *height = h; + return stat; +} + +/** + * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface(). + */ +static _EGLSurface * +GLX_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp, + _EGLConfig *conf, EGLNativeWindowType window, + const EGLint *attrib_list) +{ + struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp); + struct GLX_egl_surface *GLX_surf; + uint width, height; + + (void) drv; + + GLX_surf = CALLOC_STRUCT(GLX_egl_surface); + if (!GLX_surf) { + _eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface"); + return NULL; + } + + if (!_eglInitSurface(&GLX_surf->Base, disp, EGL_WINDOW_BIT, + conf, attrib_list)) { + free(GLX_surf); + return NULL; + } + + GLX_surf->drawable = window; + + if (GLX_dpy->have_1_3 && !GLX_dpy->glx_window_quirk) + GLX_surf->glx_drawable = + glXCreateWindow(GLX_dpy->dpy, + GLX_dpy->fbconfigs[GLX_egl_config_index(conf)], + GLX_surf->drawable, NULL); + else + GLX_surf->glx_drawable = GLX_surf->drawable; + + if (!GLX_surf->glx_drawable) { + free(GLX_surf); + return NULL; + } + + if (GLX_dpy->have_1_3 && !GLX_dpy->glx_window_quirk) + GLX_surf->destroy = glXDestroyWindow; + + get_drawable_size(GLX_dpy->dpy, window, &width, &height); + GLX_surf->Base.Width = width; + GLX_surf->Base.Height = height; + + return &GLX_surf->Base; +} + +static _EGLSurface * +GLX_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *disp, + _EGLConfig *conf, EGLNativePixmapType pixmap, + const EGLint *attrib_list) +{ + struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp); + struct GLX_egl_surface *GLX_surf; + uint width, height; + + (void) drv; + + GLX_surf = CALLOC_STRUCT(GLX_egl_surface); + if (!GLX_surf) { + _eglError(EGL_BAD_ALLOC, "eglCreatePixmapSurface"); + return NULL; + } + + if (!_eglInitSurface(&GLX_surf->Base, disp, EGL_PIXMAP_BIT, + conf, attrib_list)) { + free(GLX_surf); + return NULL; + } + + GLX_surf->drawable = pixmap; + + if (GLX_dpy->have_1_3) { + GLX_surf->glx_drawable = + glXCreatePixmap(GLX_dpy->dpy, + GLX_dpy->fbconfigs[GLX_egl_config_index(conf)], + GLX_surf->drawable, NULL); + } + else if (GLX_dpy->have_fbconfig) { + GLXFBConfig fbconfig = GLX_dpy->fbconfigs[GLX_egl_config_index(conf)]; + XVisualInfo *vinfo = glXGetVisualFromFBConfig(GLX_dpy->dpy, fbconfig); + if (vinfo) { + GLX_surf->glx_drawable = + glXCreateGLXPixmap(GLX_dpy->dpy, vinfo, GLX_surf->drawable); + XFree(vinfo); + } + } + else { + GLX_surf->glx_drawable = + glXCreateGLXPixmap(GLX_dpy->dpy, + &GLX_dpy->visuals[GLX_egl_config_index(conf)], + GLX_surf->drawable); + } + + if (!GLX_surf->glx_drawable) { + free(GLX_surf); + return NULL; + } + + GLX_surf->destroy = (GLX_dpy->have_1_3) ? + glXDestroyPixmap : glXDestroyGLXPixmap; + + get_drawable_size(GLX_dpy->dpy, pixmap, &width, &height); + GLX_surf->Base.Width = width; + GLX_surf->Base.Height = height; + + return &GLX_surf->Base; +} + +static _EGLSurface * +GLX_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp, + _EGLConfig *conf, const EGLint *attrib_list) +{ + struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp); + struct GLX_egl_surface *GLX_surf; + int attribs[5]; + int i; + + (void) drv; + + GLX_surf = CALLOC_STRUCT(GLX_egl_surface); + if (!GLX_surf) { + _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface"); + return NULL; + } + + if (!_eglInitSurface(&GLX_surf->Base, disp, EGL_PBUFFER_BIT, + conf, attrib_list)) { + free(GLX_surf); + return NULL; + } + + i = 0; + attribs[i] = None; + + GLX_surf->drawable = None; + + if (GLX_dpy->have_1_3) { + /* put geometry in attribs */ + if (GLX_surf->Base.Width) { + attribs[i++] = GLX_PBUFFER_WIDTH; + attribs[i++] = GLX_surf->Base.Width; + } + if (GLX_surf->Base.Height) { + attribs[i++] = GLX_PBUFFER_HEIGHT; + attribs[i++] = GLX_surf->Base.Height; + } + attribs[i] = None; + + GLX_surf->glx_drawable = + glXCreatePbuffer(GLX_dpy->dpy, + GLX_dpy->fbconfigs[GLX_egl_config_index(conf)], + attribs); + } + else if (GLX_dpy->have_pbuffer) { + GLX_surf->glx_drawable = GLX_dpy->glXCreateGLXPbufferSGIX( + GLX_dpy->dpy, + GLX_dpy->fbconfigs[GLX_egl_config_index(conf)], + GLX_surf->Base.Width, + GLX_surf->Base.Height, + attribs); + } + + if (!GLX_surf->glx_drawable) { + free(GLX_surf); + return NULL; + } + + GLX_surf->destroy = (GLX_dpy->have_1_3) ? + glXDestroyPbuffer : GLX_dpy->glXDestroyGLXPbufferSGIX; + + return &GLX_surf->Base; +} + + +static EGLBoolean +GLX_eglDestroySurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) +{ + (void) drv; + + if (_eglPutSurface(surf)) + destroy_surface(disp, surf); + + return EGL_TRUE; +} + + +static EGLBoolean +GLX_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) +{ + struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp); + struct GLX_egl_surface *GLX_surf = GLX_egl_surface(draw); + + (void) drv; + + glXSwapBuffers(GLX_dpy->dpy, GLX_surf->glx_drawable); + + return EGL_TRUE; +} + +/* + * Called from eglGetProcAddress() via drv->API.GetProcAddress(). + */ +static _EGLProc +GLX_eglGetProcAddress(_EGLDriver *drv, const char *procname) +{ + (void) drv; + + return (_EGLProc) glXGetProcAddress((const GLubyte *) procname); +} + +static EGLBoolean +GLX_eglWaitClient(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx) +{ + (void) drv; + (void) dpy; + (void) ctx; + + glXWaitGL(); + return EGL_TRUE; +} + +static EGLBoolean +GLX_eglWaitNative(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine) +{ + (void) drv; + (void) dpy; + + if (engine != EGL_CORE_NATIVE_ENGINE) + return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); + glXWaitX(); + return EGL_TRUE; +} + +static void +GLX_Unload(_EGLDriver *drv) +{ + struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv); + free(GLX_drv); +} + + +/** + * This is the main entrypoint into the driver, called by libEGL. + * Create a new _EGLDriver object and init its dispatch table. + */ +_EGLDriver * +_eglMain(const char *args) +{ + struct GLX_egl_driver *GLX_drv = CALLOC_STRUCT(GLX_egl_driver); + + (void) args; + + if (!GLX_drv) + return NULL; + + _eglInitDriverFallbacks(&GLX_drv->Base); + GLX_drv->Base.API.Initialize = GLX_eglInitialize; + GLX_drv->Base.API.Terminate = GLX_eglTerminate; + GLX_drv->Base.API.CreateContext = GLX_eglCreateContext; + GLX_drv->Base.API.MakeCurrent = GLX_eglMakeCurrent; + GLX_drv->Base.API.CreateWindowSurface = GLX_eglCreateWindowSurface; + GLX_drv->Base.API.CreatePixmapSurface = GLX_eglCreatePixmapSurface; + GLX_drv->Base.API.CreatePbufferSurface = GLX_eglCreatePbufferSurface; + GLX_drv->Base.API.DestroySurface = GLX_eglDestroySurface; + GLX_drv->Base.API.SwapBuffers = GLX_eglSwapBuffers; + GLX_drv->Base.API.GetProcAddress = GLX_eglGetProcAddress; + GLX_drv->Base.API.WaitClient = GLX_eglWaitClient; + GLX_drv->Base.API.WaitNative = GLX_eglWaitNative; + + GLX_drv->Base.Name = "GLX"; + GLX_drv->Base.Unload = GLX_Unload; + + return &GLX_drv->Base; +} diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile new file mode 100644 index 0000000..b4ca20c --- /dev/null +++ b/src/egl/main/Makefile @@ -0,0 +1,133 @@ +# src/egl/main/Makefile + +TOP = ../../.. +include $(TOP)/configs/current + + +EGL_MAJOR = 1 +EGL_MINOR = 0 + +INCLUDE_DIRS = -I$(TOP)/include + +HEADERS = \ + eglcompiler.h \ + eglconfig.h \ + eglcontext.h \ + eglcurrent.h \ + egldefines.h \ + egldisplay.h \ + egldriver.h \ + eglglobals.h \ + eglimage.h \ + egllog.h \ + eglmisc.h \ + eglmode.h \ + eglmutex.h \ + eglscreen.h \ + eglstring.h \ + eglsurface.h \ + eglsync.h + +SOURCES = \ + eglapi.c \ + eglarray.c \ + eglconfig.c \ + eglcontext.c \ + eglcurrent.c \ + egldisplay.c \ + egldriver.c \ + eglfallbacks.c \ + eglglobals.c \ + eglimage.c \ + egllog.c \ + eglmisc.c \ + eglmode.c \ + eglscreen.c \ + eglstring.c \ + eglsurface.c \ + eglsync.c + +OBJECTS = $(SOURCES:.c=.o) + + +# use dl*() to load drivers +LOCAL_CFLAGS = -D_EGL_OS_UNIX=1 + +# translate --with-egl-platforms to _EGLPlatformType +EGL_NATIVE_PLATFORM=_EGL_INVALID_PLATFORM +ifeq ($(firstword $(EGL_PLATFORMS)),x11) +EGL_NATIVE_PLATFORM=_EGL_PLATFORM_X11 +endif +ifeq ($(firstword $(EGL_PLATFORMS)),drm) +EGL_NATIVE_PLATFORM=_EGL_PLATFORM_DRM +endif +ifeq ($(firstword $(EGL_PLATFORMS)),fbdev) +EGL_NATIVE_PLATFORM=_EGL_PLATFORM_FBDEV +endif + +LOCAL_CFLAGS += \ + -D_EGL_NATIVE_PLATFORM=$(EGL_NATIVE_PLATFORM) \ + -D_EGL_DRIVER_SEARCH_DIR=\"$(EGL_DRIVER_INSTALL_DIR)\" + +.c.o: + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $(LOCAL_CFLAGS) $< -o $@ + + + +default: depend library + + +# EGL Library +library: $(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME) + +$(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME): $(OBJECTS) + $(MKLIB) -o $(EGL_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + -major $(EGL_MAJOR) -minor $(EGL_MINOR) \ + -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \ + $(EGL_LIB_DEPS) $(OBJECTS) + +install-headers: + $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/KHR + $(INSTALL) -m 644 $(TOP)/include/KHR/*.h \ + $(DESTDIR)$(INSTALL_INC_DIR)/KHR + $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/EGL + $(INSTALL) -m 644 $(TOP)/include/EGL/*.h \ + $(DESTDIR)$(INSTALL_INC_DIR)/EGL + +PKG_CONFIG_DIR = $(INSTALL_LIB_DIR)/pkgconfig + +gl_pcedit = sed \ + -e 's,@INSTALL_DIR@,$(INSTALL_DIR),' \ + -e 's,@INSTALL_LIB_DIR@,$(INSTALL_LIB_DIR),' \ + -e 's,@INSTALL_INC_DIR@,$(INSTALL_INC_DIR),' \ + -e 's,@VERSION@,$(MESA_MAJOR).$(MESA_MINOR).$(MESA_TINY),' \ + -e 's,@EGL_PC_REQ_PRIV@,$(EGL_PC_REQ_PRIV),' \ + -e 's,@EGL_PC_LIB_PRIV@,$(EGL_PC_LIB_PRIV),' \ + -e 's,@EGL_PC_CFLAGS@,$(EGL_PC_CFLAGS),' \ + -e 's,@EGL_LIB@,$(EGL_LIB),' + +egl.pc: egl.pc.in + $(gl_pcedit) $< > $@ + +install: default install-headers egl.pc + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR) + $(MINSTALL) $(TOP)/$(LIB_DIR)/$(EGL_LIB_GLOB) \ + $(DESTDIR)$(INSTALL_LIB_DIR) + $(INSTALL) -d $(DESTDIR)$(PKG_CONFIG_DIR) + $(INSTALL) -m 644 egl.pc $(DESTDIR)$(PKG_CONFIG_DIR) + +clean: + -rm -f *.o + -rm -f depend depend.bak + + +depend: $(SOURCES) $(HEADERS) + @ echo "running $(MKDEP)" + @ rm -f depend + @ touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) \ + $(SOURCES) $(HEADERS) > /dev/null 2>/dev/null + + +-include depend +# DO NOT DELETE diff --git a/src/egl/main/egl.def b/src/egl/main/egl.def new file mode 100644 index 0000000..0cfe920 --- /dev/null +++ b/src/egl/main/egl.def @@ -0,0 +1,35 @@ +EXPORTS + eglBindAPI + eglBindTexImage + eglChooseConfig + eglCopyBuffers + eglCreateContext + eglCreatePbufferFromClientBuffer + eglCreatePbufferSurface + eglCreatePixmapSurface + eglCreateWindowSurface + eglDestroyContext + eglDestroySurface + eglGetConfigAttrib + eglGetConfigs + eglGetCurrentContext + eglGetCurrentDisplay + eglGetCurrentSurface + eglGetDisplay + eglGetError + eglGetProcAddress + eglInitialize + eglMakeCurrent + eglQueryAPI + eglQueryContext + eglQueryString + eglQuerySurface + eglReleaseTexImage + eglReleaseThread + eglSurfaceAttrib + eglSwapBuffers + eglSwapInterval + eglTerminate + eglWaitClient + eglWaitGL + eglWaitNative diff --git a/src/egl/main/egl.pc.in b/src/egl/main/egl.pc.in new file mode 100644 index 0000000..2855a49 --- /dev/null +++ b/src/egl/main/egl.pc.in @@ -0,0 +1,12 @@ +prefix=@INSTALL_DIR@ +exec_prefix=${prefix} +libdir=@INSTALL_LIB_DIR@ +includedir=@INSTALL_INC_DIR@ + +Name: egl +Description: Mesa EGL library +Requires.private: @EGL_PC_REQ_PRIV@ +Version: @VERSION@ +Libs: -L${libdir} -l@EGL_LIB@ +Libs.private: @EGL_PC_LIB_PRIV@ +Cflags: -I${includedir} @EGL_PC_CFLAGS@ diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c new file mode 100644 index 0000000..efa9e97 --- /dev/null +++ b/src/egl/main/eglapi.c @@ -0,0 +1,1496 @@ +/** + * Public EGL API entrypoints + * + * Generally, we use the EGLDisplay parameter as a key to lookup the + * appropriate device driver handle, then jump though the driver's + * dispatch table to handle the function. + * + * That allows us the option of supporting multiple, simultaneous, + * heterogeneous hardware devices in the future. + * + * The EGLDisplay, EGLConfig, EGLContext and EGLSurface types are + * opaque handles. Internal objects are linked to a display to + * create the handles. + * + * For each public API entry point, the opaque handles are looked up + * before being dispatched to the drivers. When it fails to look up + * a handle, one of + * + * EGL_BAD_DISPLAY + * EGL_BAD_CONFIG + * EGL_BAD_CONTEXT + * EGL_BAD_SURFACE + * EGL_BAD_SCREEN_MESA + * EGL_BAD_MODE_MESA + * + * is generated and the driver function is not called. An + * uninitialized EGLDisplay has no driver associated with it. When + * such display is detected, + * + * EGL_NOT_INITIALIZED + * + * is generated. + * + * Some of the entry points use current display, context, or surface + * implicitly. For such entry points, the implicit objects are also + * checked before calling the driver function. Other than the + * errors listed above, + * + * EGL_BAD_CURRENT_SURFACE + * + * may also be generated. + * + * Notes on naming conventions: + * + * eglFooBar - public EGL function + * EGL_FOO_BAR - public EGL token + * EGLDatatype - public EGL datatype + * + * _eglFooBar - private EGL function + * _EGLDatatype - private EGL datatype, typedef'd struct + * _egl_struct - private EGL struct, non-typedef'd + * + */ + + +#include +#include +#include + +#include "eglstring.h" +#include "eglcontext.h" +#include "egldisplay.h" +#include "egltypedefs.h" +#include "eglcurrent.h" +#include "egldriver.h" +#include "eglsurface.h" +#include "eglconfig.h" +#include "eglscreen.h" +#include "eglmode.h" +#include "eglimage.h" +#include "eglsync.h" + + +/** + * Macros to help return an API entrypoint. + * + * These macros will unlock the display and record the error code. + */ +#define RETURN_EGL_ERROR(disp, err, ret) \ + do { \ + if (disp) \ + _eglUnlockDisplay(disp); \ + /* EGL error codes are non-zero */ \ + if (err) \ + _eglError(err, __FUNCTION__); \ + return ret; \ + } while (0) + +#define RETURN_EGL_SUCCESS(disp, ret) \ + RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret) + +/* record EGL_SUCCESS only when ret evaluates to true */ +#define RETURN_EGL_EVAL(disp, ret) \ + RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret) + + +/* + * A bunch of macros and checks to simplify error checking. + */ + +#define _EGL_CHECK_DISPLAY(disp, ret, drv) \ + do { \ + drv = _eglCheckDisplay(disp, __FUNCTION__); \ + if (!drv) \ + RETURN_EGL_ERROR(disp, 0, ret); \ + } while (0) + +#define _EGL_CHECK_OBJECT(disp, type, obj, ret, drv) \ + do { \ + drv = _eglCheck ## type(disp, obj, __FUNCTION__); \ + if (!drv) \ + RETURN_EGL_ERROR(disp, 0, ret); \ + } while (0) + +#define _EGL_CHECK_SURFACE(disp, surf, ret, drv) \ + _EGL_CHECK_OBJECT(disp, Surface, surf, ret, drv) + +#define _EGL_CHECK_CONTEXT(disp, context, ret, drv) \ + _EGL_CHECK_OBJECT(disp, Context, context, ret, drv) + +#define _EGL_CHECK_CONFIG(disp, conf, ret, drv) \ + _EGL_CHECK_OBJECT(disp, Config, conf, ret, drv) + +#define _EGL_CHECK_SCREEN(disp, scrn, ret, drv) \ + _EGL_CHECK_OBJECT(disp, Screen, scrn, ret, drv) + +#define _EGL_CHECK_MODE(disp, m, ret, drv) \ + _EGL_CHECK_OBJECT(disp, Mode, m, ret, drv) + +#define _EGL_CHECK_SYNC(disp, s, ret, drv) \ + _EGL_CHECK_OBJECT(disp, Sync, s, ret, drv) + + +static INLINE _EGLDriver * +_eglCheckDisplay(_EGLDisplay *disp, const char *msg) +{ + if (!disp) { + _eglError(EGL_BAD_DISPLAY, msg); + return NULL; + } + if (!disp->Initialized) { + _eglError(EGL_NOT_INITIALIZED, msg); + return NULL; + } + return disp->Driver; +} + + +static INLINE _EGLDriver * +_eglCheckSurface(_EGLDisplay *disp, _EGLSurface *surf, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!surf) { + _eglError(EGL_BAD_SURFACE, msg); + return NULL; + } + return drv; +} + + +static INLINE _EGLDriver * +_eglCheckContext(_EGLDisplay *disp, _EGLContext *context, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!context) { + _eglError(EGL_BAD_CONTEXT, msg); + return NULL; + } + return drv; +} + + +static INLINE _EGLDriver * +_eglCheckConfig(_EGLDisplay *disp, _EGLConfig *conf, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!conf) { + _eglError(EGL_BAD_CONFIG, msg); + return NULL; + } + return drv; +} + + +#ifdef EGL_KHR_reusable_sync + + +static INLINE _EGLDriver * +_eglCheckSync(_EGLDisplay *disp, _EGLSync *s, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!s) { + _eglError(EGL_BAD_PARAMETER, msg); + return NULL; + } + return drv; +} + + +#endif /* EGL_KHR_reusable_sync */ + + +#ifdef EGL_MESA_screen_surface + + +static INLINE _EGLDriver * +_eglCheckScreen(_EGLDisplay *disp, _EGLScreen *scrn, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!scrn) { + _eglError(EGL_BAD_SCREEN_MESA, msg); + return NULL; + } + return drv; +} + + +static INLINE _EGLDriver * +_eglCheckMode(_EGLDisplay *disp, _EGLMode *m, const char *msg) +{ + _EGLDriver *drv = _eglCheckDisplay(disp, msg); + if (!drv) + return NULL; + if (!m) { + _eglError(EGL_BAD_MODE_MESA, msg); + return NULL; + } + return drv; +} + + +#endif /* EGL_MESA_screen_surface */ + + +/** + * Lookup and lock a display. + */ +static INLINE _EGLDisplay * +_eglLockDisplay(EGLDisplay display) +{ + _EGLDisplay *dpy = _eglLookupDisplay(display); + if (dpy) + _eglLockMutex(&dpy->Mutex); + return dpy; +} + + +/** + * Unlock a display. + */ +static INLINE void +_eglUnlockDisplay(_EGLDisplay *dpy) +{ + _eglUnlockMutex(&dpy->Mutex); +} + + +/** + * This is typically the first EGL function that an application calls. + * It associates a private _EGLDisplay object to the native display. + */ +EGLDisplay EGLAPIENTRY +eglGetDisplay(EGLNativeDisplayType nativeDisplay) +{ + _EGLPlatformType plat = _eglGetNativePlatform(); + _EGLDisplay *dpy = _eglFindDisplay(plat, (void *) nativeDisplay); + return _eglGetDisplayHandle(dpy); +} + + +/** + * This is typically the second EGL function that an application calls. + * Here we load/initialize the actual hardware driver. + */ +EGLBoolean EGLAPIENTRY +eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + + if (!disp) + RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE); + + if (!disp->Initialized) { + if (!_eglMatchDriver(disp, EGL_FALSE)) + RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE); + + _eglsnprintf(disp->Version, sizeof(disp->Version), "%d.%d (%s)", + disp->APImajor, disp->APIminor, disp->Driver->Name); + /* limit to APIs supported by core */ + disp->ClientAPIsMask &= _EGL_API_ALL_BITS; + } + + /* Update applications version of major and minor if not NULL */ + if ((major != NULL) && (minor != NULL)) { + *major = disp->APImajor; + *minor = disp->APIminor; + } + + RETURN_EGL_SUCCESS(disp, EGL_TRUE); +} + + +EGLBoolean EGLAPIENTRY +eglTerminate(EGLDisplay dpy) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + + if (!disp) + RETURN_EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE); + + if (disp->Initialized) { + _EGLDriver *drv = disp->Driver; + + drv->API.Terminate(drv, disp); + /* do not reset disp->Driver */ + disp->Initialized = EGL_FALSE; + } + + RETURN_EGL_SUCCESS(disp, EGL_TRUE); +} + + +const char * EGLAPIENTRY +eglQueryString(EGLDisplay dpy, EGLint name) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLDriver *drv; + const char *ret; + + _EGL_CHECK_DISPLAY(disp, NULL, drv); + ret = drv->API.QueryString(drv, disp, name); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, + EGLint config_size, EGLint *num_config) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); + ret = drv->API.GetConfigs(drv, disp, configs, config_size, num_config); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, + EGLint config_size, EGLint *num_config) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); + ret = drv->API.ChooseConfig(drv, disp, attrib_list, configs, + config_size, num_config); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, + EGLint attribute, EGLint *value) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLConfig *conf = _eglLookupConfig(config, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_CONFIG(disp, conf, EGL_FALSE, drv); + ret = drv->API.GetConfigAttrib(drv, disp, conf, attribute, value); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLContext EGLAPIENTRY +eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list, + const EGLint *attrib_list) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLConfig *conf = _eglLookupConfig(config, disp); + _EGLContext *share = _eglLookupContext(share_list, disp); + _EGLDriver *drv; + _EGLContext *context; + EGLContext ret; + + _EGL_CHECK_DISPLAY(disp, EGL_NO_CONTEXT, drv); + + if (!config) { + /* config may be NULL if surfaceless */ + if (!disp->Extensions.KHR_surfaceless_gles1 && + !disp->Extensions.KHR_surfaceless_gles2 && + !disp->Extensions.KHR_surfaceless_opengl) + RETURN_EGL_ERROR(disp, EGL_BAD_CONFIG, EGL_NO_CONTEXT); + } + + if (!share && share_list != EGL_NO_CONTEXT) + RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_CONTEXT); + + context = drv->API.CreateContext(drv, disp, conf, share, attrib_list); + ret = (context) ? _eglLinkContext(context) : EGL_NO_CONTEXT; + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglDestroyContext(EGLDisplay dpy, EGLContext ctx) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLContext *context = _eglLookupContext(ctx, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv); + _eglUnlinkContext(context); + ret = drv->API.DestroyContext(drv, disp, context); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, + EGLContext ctx) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLContext *context = _eglLookupContext(ctx, disp); + _EGLSurface *draw_surf = _eglLookupSurface(draw, disp); + _EGLSurface *read_surf = _eglLookupSurface(read, disp); + _EGLDriver *drv; + EGLBoolean ret; + + if (!disp) + RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE); + drv = disp->Driver; + + /* display is allowed to be uninitialized under certain condition */ + if (!disp->Initialized) { + if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE || + ctx != EGL_NO_CONTEXT) + RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_FALSE); + } + if (!drv) + RETURN_EGL_SUCCESS(disp, EGL_TRUE); + + if (!context && ctx != EGL_NO_CONTEXT) + RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE); + if (!draw_surf || !read_surf) { + /* surfaces may be NULL if surfaceless */ + if (!disp->Extensions.KHR_surfaceless_gles1 && + !disp->Extensions.KHR_surfaceless_gles2 && + !disp->Extensions.KHR_surfaceless_opengl) + RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); + + if ((!draw_surf && draw != EGL_NO_SURFACE) || + (!read_surf && read != EGL_NO_SURFACE)) + RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); + if (draw_surf || read_surf) + RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE); + } + + ret = drv->API.MakeCurrent(drv, disp, draw_surf, read_surf, context); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglQueryContext(EGLDisplay dpy, EGLContext ctx, + EGLint attribute, EGLint *value) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLContext *context = _eglLookupContext(ctx, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_CONTEXT(disp, context, EGL_FALSE, drv); + ret = drv->API.QueryContext(drv, disp, context, attribute, value); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLSurface EGLAPIENTRY +eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, + EGLNativeWindowType window, const EGLint *attrib_list) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLConfig *conf = _eglLookupConfig(config, disp); + _EGLDriver *drv; + _EGLSurface *surf; + EGLSurface ret; + + _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv); + if (disp->Platform != _eglGetNativePlatform()) + RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); + + surf = drv->API.CreateWindowSurface(drv, disp, conf, window, attrib_list); + ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLSurface EGLAPIENTRY +eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, + EGLNativePixmapType pixmap, const EGLint *attrib_list) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLConfig *conf = _eglLookupConfig(config, disp); + _EGLDriver *drv; + _EGLSurface *surf; + EGLSurface ret; + + _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv); + if (disp->Platform != _eglGetNativePlatform()) + RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE); + + surf = drv->API.CreatePixmapSurface(drv, disp, conf, pixmap, attrib_list); + ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLSurface EGLAPIENTRY +eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLConfig *conf = _eglLookupConfig(config, disp); + _EGLDriver *drv; + _EGLSurface *surf; + EGLSurface ret; + + _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv); + + surf = drv->API.CreatePbufferSurface(drv, disp, conf, attrib_list); + ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglDestroySurface(EGLDisplay dpy, EGLSurface surface) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSurface *surf = _eglLookupSurface(surface, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); + _eglUnlinkSurface(surf); + ret = drv->API.DestroySurface(drv, disp, surf); + + RETURN_EGL_EVAL(disp, ret); +} + +EGLBoolean EGLAPIENTRY +eglQuerySurface(EGLDisplay dpy, EGLSurface surface, + EGLint attribute, EGLint *value) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSurface *surf = _eglLookupSurface(surface, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); + ret = drv->API.QuerySurface(drv, disp, surf, attribute, value); + + RETURN_EGL_EVAL(disp, ret); +} + +EGLBoolean EGLAPIENTRY +eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, + EGLint attribute, EGLint value) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSurface *surf = _eglLookupSurface(surface, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); + ret = drv->API.SurfaceAttrib(drv, disp, surf, attribute, value); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSurface *surf = _eglLookupSurface(surface, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); + ret = drv->API.BindTexImage(drv, disp, surf, buffer); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSurface *surf = _eglLookupSurface(surface, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); + ret = drv->API.ReleaseTexImage(drv, disp, surf, buffer); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglSwapInterval(EGLDisplay dpy, EGLint interval) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLContext *ctx = _eglGetCurrentContext(); + _EGLSurface *surf; + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); + + if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || + ctx->Resource.Display != disp) + RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE); + + surf = ctx->DrawSurface; + if (_eglGetSurfaceHandle(surf) == EGL_NO_SURFACE) + RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); + + ret = drv->API.SwapInterval(drv, disp, surf, interval); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSurface *surf = _eglLookupSurface(surface, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); + + /* surface must be bound to current context in EGL 1.4 */ + if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || + surf != ctx->DrawSurface) + RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); + + ret = drv->API.SwapBuffers(drv, disp, surf); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSurface *surf = _eglLookupSurface(surface, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); + if (disp->Platform != _eglGetNativePlatform()) + RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_FALSE); + ret = drv->API.CopyBuffers(drv, disp, surf, target); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglWaitClient(void) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + _EGLDisplay *disp; + _EGLDriver *drv; + EGLBoolean ret; + + if (!ctx) + RETURN_EGL_SUCCESS(NULL, EGL_TRUE); + + disp = ctx->Resource.Display; + _eglLockMutex(&disp->Mutex); + + /* let bad current context imply bad current surface */ + if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || + _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE) + RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE); + + /* a valid current context implies an initialized current display */ + assert(disp->Initialized); + drv = disp->Driver; + ret = drv->API.WaitClient(drv, disp, ctx); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglWaitGL(void) +{ +#ifdef EGL_VERSION_1_2 + _EGLThreadInfo *t = _eglGetCurrentThread(); + EGLint api_index = t->CurrentAPIIndex; + EGLint es_index = _eglConvertApiToIndex(EGL_OPENGL_ES_API); + EGLBoolean ret; + + if (api_index != es_index && _eglIsCurrentThreadDummy()) + RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE); + + t->CurrentAPIIndex = es_index; + ret = eglWaitClient(); + t->CurrentAPIIndex = api_index; + return ret; +#else + return eglWaitClient(); +#endif +} + + +EGLBoolean EGLAPIENTRY +eglWaitNative(EGLint engine) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + _EGLDisplay *disp; + _EGLDriver *drv; + EGLBoolean ret; + + if (!ctx) + RETURN_EGL_SUCCESS(NULL, EGL_TRUE); + + disp = ctx->Resource.Display; + _eglLockMutex(&disp->Mutex); + + /* let bad current context imply bad current surface */ + if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || + _eglGetSurfaceHandle(ctx->DrawSurface) == EGL_NO_SURFACE) + RETURN_EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE); + + /* a valid current context implies an initialized current display */ + assert(disp->Initialized); + drv = disp->Driver; + ret = drv->API.WaitNative(drv, disp, engine); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLDisplay EGLAPIENTRY +eglGetCurrentDisplay(void) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + EGLDisplay ret; + + ret = (ctx) ? _eglGetDisplayHandle(ctx->Resource.Display) : EGL_NO_DISPLAY; + + RETURN_EGL_SUCCESS(NULL, ret); +} + + +EGLContext EGLAPIENTRY +eglGetCurrentContext(void) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + EGLContext ret; + + ret = _eglGetContextHandle(ctx); + + RETURN_EGL_SUCCESS(NULL, ret); +} + + +EGLSurface EGLAPIENTRY +eglGetCurrentSurface(EGLint readdraw) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + EGLint err = EGL_SUCCESS; + _EGLSurface *surf; + EGLSurface ret; + + if (!ctx) + RETURN_EGL_SUCCESS(NULL, EGL_NO_SURFACE); + + switch (readdraw) { + case EGL_DRAW: + surf = ctx->DrawSurface; + break; + case EGL_READ: + surf = ctx->ReadSurface; + break; + default: + surf = NULL; + err = EGL_BAD_PARAMETER; + break; + } + + ret = _eglGetSurfaceHandle(surf); + + RETURN_EGL_ERROR(NULL, err, ret); +} + + +EGLint EGLAPIENTRY +eglGetError(void) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + EGLint e = t->LastError; + if (!_eglIsCurrentThreadDummy()) + t->LastError = EGL_SUCCESS; + return e; +} + + +__eglMustCastToProperFunctionPointerType EGLAPIENTRY +eglGetProcAddress(const char *procname) +{ + static const struct { + const char *name; + _EGLProc function; + } egl_functions[] = { + /* core functions should not be queryable, but, well... */ +#ifdef _EGL_GET_CORE_ADDRESSES + /* alphabetical order */ + { "eglBindAPI", (_EGLProc) eglBindAPI }, + { "eglBindTexImage", (_EGLProc) eglBindTexImage }, + { "eglChooseConfig", (_EGLProc) eglChooseConfig }, + { "eglCopyBuffers", (_EGLProc) eglCopyBuffers }, + { "eglCreateContext", (_EGLProc) eglCreateContext }, + { "eglCreatePbufferFromClientBuffer", (_EGLProc) eglCreatePbufferFromClientBuffer }, + { "eglCreatePbufferSurface", (_EGLProc) eglCreatePbufferSurface }, + { "eglCreatePixmapSurface", (_EGLProc) eglCreatePixmapSurface }, + { "eglCreateWindowSurface", (_EGLProc) eglCreateWindowSurface }, + { "eglDestroyContext", (_EGLProc) eglDestroyContext }, + { "eglDestroySurface", (_EGLProc) eglDestroySurface }, + { "eglGetConfigAttrib", (_EGLProc) eglGetConfigAttrib }, + { "eglGetConfigs", (_EGLProc) eglGetConfigs }, + { "eglGetCurrentContext", (_EGLProc) eglGetCurrentContext }, + { "eglGetCurrentDisplay", (_EGLProc) eglGetCurrentDisplay }, + { "eglGetCurrentSurface", (_EGLProc) eglGetCurrentSurface }, + { "eglGetDisplay", (_EGLProc) eglGetDisplay }, + { "eglGetError", (_EGLProc) eglGetError }, + { "eglGetProcAddress", (_EGLProc) eglGetProcAddress }, + { "eglInitialize", (_EGLProc) eglInitialize }, + { "eglMakeCurrent", (_EGLProc) eglMakeCurrent }, + { "eglQueryAPI", (_EGLProc) eglQueryAPI }, + { "eglQueryContext", (_EGLProc) eglQueryContext }, + { "eglQueryString", (_EGLProc) eglQueryString }, + { "eglQuerySurface", (_EGLProc) eglQuerySurface }, + { "eglReleaseTexImage", (_EGLProc) eglReleaseTexImage }, + { "eglReleaseThread", (_EGLProc) eglReleaseThread }, + { "eglSurfaceAttrib", (_EGLProc) eglSurfaceAttrib }, + { "eglSwapBuffers", (_EGLProc) eglSwapBuffers }, + { "eglSwapInterval", (_EGLProc) eglSwapInterval }, + { "eglTerminate", (_EGLProc) eglTerminate }, + { "eglWaitClient", (_EGLProc) eglWaitClient }, + { "eglWaitGL", (_EGLProc) eglWaitGL }, + { "eglWaitNative", (_EGLProc) eglWaitNative }, +#endif /* _EGL_GET_CORE_ADDRESSES */ +#ifdef EGL_MESA_screen_surface + { "eglChooseModeMESA", (_EGLProc) eglChooseModeMESA }, + { "eglGetModesMESA", (_EGLProc) eglGetModesMESA }, + { "eglGetModeAttribMESA", (_EGLProc) eglGetModeAttribMESA }, + { "eglCopyContextMESA", (_EGLProc) eglCopyContextMESA }, + { "eglGetScreensMESA", (_EGLProc) eglGetScreensMESA }, + { "eglCreateScreenSurfaceMESA", (_EGLProc) eglCreateScreenSurfaceMESA }, + { "eglShowScreenSurfaceMESA", (_EGLProc) eglShowScreenSurfaceMESA }, + { "eglScreenPositionMESA", (_EGLProc) eglScreenPositionMESA }, + { "eglQueryScreenMESA", (_EGLProc) eglQueryScreenMESA }, + { "eglQueryScreenSurfaceMESA", (_EGLProc) eglQueryScreenSurfaceMESA }, + { "eglQueryScreenModeMESA", (_EGLProc) eglQueryScreenModeMESA }, + { "eglQueryModeStringMESA", (_EGLProc) eglQueryModeStringMESA }, +#endif /* EGL_MESA_screen_surface */ +#ifdef EGL_MESA_drm_display + { "eglGetDRMDisplayMESA", (_EGLProc) eglGetDRMDisplayMESA }, +#endif +#ifdef EGL_KHR_image_base + { "eglCreateImageKHR", (_EGLProc) eglCreateImageKHR }, + { "eglDestroyImageKHR", (_EGLProc) eglDestroyImageKHR }, +#endif /* EGL_KHR_image_base */ +#ifdef EGL_NOK_swap_region + { "eglSwapBuffersRegionNOK", (_EGLProc) eglSwapBuffersRegionNOK }, +#endif +#ifdef EGL_MESA_drm_image + { "eglCreateDRMImageMESA", (_EGLProc) eglCreateDRMImageMESA }, + { "eglExportDRMImageMESA", (_EGLProc) eglExportDRMImageMESA }, +#endif + { NULL, NULL } + }; + EGLint i; + _EGLProc ret; + + if (!procname) + RETURN_EGL_SUCCESS(NULL, NULL); + + ret = NULL; + if (strncmp(procname, "egl", 3) == 0) { + for (i = 0; egl_functions[i].name; i++) { + if (strcmp(egl_functions[i].name, procname) == 0) { + ret = egl_functions[i].function; + break; + } + } + } + if (!ret) + ret = _eglGetDriverProc(procname); + + RETURN_EGL_SUCCESS(NULL, ret); +} + + +#ifdef EGL_MESA_screen_surface + + +/* + * EGL_MESA_screen extension + */ + +EGLBoolean EGLAPIENTRY +eglChooseModeMESA(EGLDisplay dpy, EGLScreenMESA screen, + const EGLint *attrib_list, EGLModeMESA *modes, + EGLint modes_size, EGLint *num_modes) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLScreen *scrn = _eglLookupScreen(screen, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SCREEN(disp, scrn, EGL_FALSE, drv); + ret = drv->API.ChooseModeMESA(drv, disp, scrn, attrib_list, + modes, modes_size, num_modes); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglGetModesMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *modes, + EGLint mode_size, EGLint *num_mode) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLScreen *scrn = _eglLookupScreen(screen, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SCREEN(disp, scrn, EGL_FALSE, drv); + ret = drv->API.GetModesMESA(drv, disp, scrn, modes, mode_size, num_mode); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglGetModeAttribMESA(EGLDisplay dpy, EGLModeMESA mode, + EGLint attribute, EGLint *value) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLMode *m = _eglLookupMode(mode, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_MODE(disp, m, EGL_FALSE, drv); + ret = drv->API.GetModeAttribMESA(drv, disp, m, attribute, value); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglCopyContextMESA(EGLDisplay dpy, EGLContext source, EGLContext dest, + EGLint mask) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLContext *source_context = _eglLookupContext(source, disp); + _EGLContext *dest_context = _eglLookupContext(dest, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_CONTEXT(disp, source_context, EGL_FALSE, drv); + if (!dest_context) + RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_FALSE); + + ret = drv->API.CopyContextMESA(drv, disp, + source_context, dest_context, mask); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglGetScreensMESA(EGLDisplay dpy, EGLScreenMESA *screens, + EGLint max_screens, EGLint *num_screens) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); + ret = drv->API.GetScreensMESA(drv, disp, screens, max_screens, num_screens); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLSurface EGLAPIENTRY +eglCreateScreenSurfaceMESA(EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLConfig *conf = _eglLookupConfig(config, disp); + _EGLDriver *drv; + _EGLSurface *surf; + EGLSurface ret; + + _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv); + + surf = drv->API.CreateScreenSurfaceMESA(drv, disp, conf, attrib_list); + ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglShowScreenSurfaceMESA(EGLDisplay dpy, EGLint screen, + EGLSurface surface, EGLModeMESA mode) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLScreen *scrn = _eglLookupScreen((EGLScreenMESA) screen, disp); + _EGLSurface *surf = _eglLookupSurface(surface, disp); + _EGLMode *m = _eglLookupMode(mode, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SCREEN(disp, scrn, EGL_FALSE, drv); + if (!surf && surface != EGL_NO_SURFACE) + RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); + if (!m && mode != EGL_NO_MODE_MESA) + RETURN_EGL_ERROR(disp, EGL_BAD_MODE_MESA, EGL_FALSE); + + ret = drv->API.ShowScreenSurfaceMESA(drv, disp, scrn, surf, m); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglScreenPositionMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLScreen *scrn = _eglLookupScreen(screen, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SCREEN(disp, scrn, EGL_FALSE, drv); + ret = drv->API.ScreenPositionMESA(drv, disp, scrn, x, y); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglQueryScreenMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLint attribute, EGLint *value) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLScreen *scrn = _eglLookupScreen(screen, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SCREEN(disp, scrn, EGL_FALSE, drv); + ret = drv->API.QueryScreenMESA(drv, disp, scrn, attribute, value); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglQueryScreenSurfaceMESA(EGLDisplay dpy, EGLScreenMESA screen, + EGLSurface *surface) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLScreen *scrn = _eglLookupScreen((EGLScreenMESA) screen, disp); + _EGLDriver *drv; + _EGLSurface *surf; + EGLBoolean ret; + + _EGL_CHECK_SCREEN(disp, scrn, EGL_FALSE, drv); + ret = drv->API.QueryScreenSurfaceMESA(drv, disp, scrn, &surf); + if (ret && surface) + *surface = _eglGetSurfaceHandle(surf); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglQueryScreenModeMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLScreen *scrn = _eglLookupScreen((EGLScreenMESA) screen, disp); + _EGLDriver *drv; + _EGLMode *m; + EGLBoolean ret; + + _EGL_CHECK_SCREEN(disp, scrn, EGL_FALSE, drv); + ret = drv->API.QueryScreenModeMESA(drv, disp, scrn, &m); + if (ret && mode) + *mode = m->Handle; + + RETURN_EGL_EVAL(disp, ret); +} + + +const char * EGLAPIENTRY +eglQueryModeStringMESA(EGLDisplay dpy, EGLModeMESA mode) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLMode *m = _eglLookupMode(mode, disp); + _EGLDriver *drv; + const char *ret; + + _EGL_CHECK_MODE(disp, m, NULL, drv); + ret = drv->API.QueryModeStringMESA(drv, disp, m); + + RETURN_EGL_EVAL(disp, ret); +} + + +#endif /* EGL_MESA_screen_surface */ + + +#ifdef EGL_MESA_drm_display + +EGLDisplay EGLAPIENTRY +eglGetDRMDisplayMESA(int fd) +{ + _EGLDisplay *dpy = _eglFindDisplay(_EGL_PLATFORM_DRM, (void *) fd); + return _eglGetDisplayHandle(dpy); +} + +#endif /* EGL_MESA_drm_display */ + +/** + ** EGL 1.2 + **/ + +#ifdef EGL_VERSION_1_2 + + +/** + * Specify the client API to use for subsequent calls including: + * eglCreateContext() + * eglGetCurrentContext() + * eglGetCurrentDisplay() + * eglGetCurrentSurface() + * eglMakeCurrent(when the ctx parameter is EGL NO CONTEXT) + * eglWaitClient() + * eglWaitNative() + * See section 3.7 "Rendering Context" in the EGL specification for details. + */ +EGLBoolean EGLAPIENTRY +eglBindAPI(EGLenum api) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + + if (_eglIsCurrentThreadDummy()) + RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_FALSE); + + if (!_eglIsApiValid(api)) + RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE); + + t->CurrentAPIIndex = _eglConvertApiToIndex(api); + + RETURN_EGL_SUCCESS(NULL, EGL_TRUE); +} + + +/** + * Return the last value set with eglBindAPI(). + */ +EGLenum EGLAPIENTRY +eglQueryAPI(void) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + EGLenum ret; + + /* returns one of EGL_OPENGL_API, EGL_OPENGL_ES_API or EGL_OPENVG_API */ + ret = _eglConvertApiFromIndex(t->CurrentAPIIndex); + + RETURN_EGL_SUCCESS(NULL, ret); +} + + +EGLSurface EGLAPIENTRY +eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, + EGLClientBuffer buffer, EGLConfig config, + const EGLint *attrib_list) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLConfig *conf = _eglLookupConfig(config, disp); + _EGLDriver *drv; + _EGLSurface *surf; + EGLSurface ret; + + _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv); + + surf = drv->API.CreatePbufferFromClientBuffer(drv, disp, buftype, buffer, + conf, attrib_list); + ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglReleaseThread(void) +{ + /* unbind current contexts */ + if (!_eglIsCurrentThreadDummy()) { + _EGLThreadInfo *t = _eglGetCurrentThread(); + EGLint api_index = t->CurrentAPIIndex; + EGLint i; + + for (i = 0; i < _EGL_API_NUM_APIS; i++) { + _EGLContext *ctx = t->CurrentContexts[i]; + if (ctx) { + _EGLDisplay *disp = ctx->Resource.Display; + _EGLDriver *drv; + + t->CurrentAPIIndex = i; + + _eglLockMutex(&disp->Mutex); + drv = disp->Driver; + (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL); + _eglUnlockMutex(&disp->Mutex); + } + } + + t->CurrentAPIIndex = api_index; + } + + _eglDestroyCurrentThread(); + + RETURN_EGL_SUCCESS(NULL, EGL_TRUE); +} + + +#endif /* EGL_VERSION_1_2 */ + + +#ifdef EGL_KHR_image_base + + +EGLImageKHR EGLAPIENTRY +eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, + EGLClientBuffer buffer, const EGLint *attr_list) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLContext *context = _eglLookupContext(ctx, disp); + _EGLDriver *drv; + _EGLImage *img; + EGLImageKHR ret; + + _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv); + if (!disp->Extensions.KHR_image_base) + RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR); + if (!context && ctx != EGL_NO_CONTEXT) + RETURN_EGL_ERROR(disp, EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR); + + img = drv->API.CreateImageKHR(drv, + disp, context, target, buffer, attr_list); + ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR; + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLImage *img = _eglLookupImage(image, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); + if (!disp->Extensions.KHR_image_base) + RETURN_EGL_EVAL(disp, EGL_FALSE); + if (!img) + RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); + + _eglUnlinkImage(img); + ret = drv->API.DestroyImageKHR(drv, disp, img); + + RETURN_EGL_EVAL(disp, ret); +} + + +#endif /* EGL_KHR_image_base */ + + +#ifdef EGL_KHR_reusable_sync + + +EGLSyncKHR EGLAPIENTRY +eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLDriver *drv; + _EGLSync *sync; + EGLSyncKHR ret; + + _EGL_CHECK_DISPLAY(disp, EGL_NO_SYNC_KHR, drv); + if (!disp->Extensions.KHR_reusable_sync) + RETURN_EGL_EVAL(disp, EGL_NO_SYNC_KHR); + + sync = drv->API.CreateSyncKHR(drv, disp, type, attrib_list); + ret = (sync) ? _eglLinkSync(sync) : EGL_NO_SYNC_KHR; + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSync *s = _eglLookupSync(sync, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv); + assert(disp->Extensions.KHR_reusable_sync); + + _eglUnlinkSync(s); + ret = drv->API.DestroySyncKHR(drv, disp, s); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLint EGLAPIENTRY +eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSync *s = _eglLookupSync(sync, disp); + _EGLDriver *drv; + EGLint ret; + + _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv); + assert(disp->Extensions.KHR_reusable_sync); + ret = drv->API.ClientWaitSyncKHR(drv, disp, s, flags, timeout); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSync *s = _eglLookupSync(sync, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv); + assert(disp->Extensions.KHR_reusable_sync); + ret = drv->API.SignalSyncKHR(drv, disp, s, mode); + + RETURN_EGL_EVAL(disp, ret); +} + + +EGLBoolean EGLAPIENTRY +eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSync *s = _eglLookupSync(sync, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SYNC(disp, s, EGL_FALSE, drv); + assert(disp->Extensions.KHR_reusable_sync); + ret = drv->API.GetSyncAttribKHR(drv, disp, s, attribute, value); + + RETURN_EGL_EVAL(disp, ret); +} + + +#endif /* EGL_KHR_reusable_sync */ + + +#ifdef EGL_NOK_swap_region + +EGLBoolean EGLAPIENTRY +eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface, + EGLint numRects, const EGLint *rects) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLSurface *surf = _eglLookupSurface(surface, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE, drv); + + if (!disp->Extensions.NOK_swap_region) + RETURN_EGL_EVAL(disp, EGL_FALSE); + + /* surface must be bound to current context in EGL 1.4 */ + if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || + surf != ctx->DrawSurface) + RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); + + ret = drv->API.SwapBuffersRegionNOK(drv, disp, surf, numRects, rects); + + RETURN_EGL_EVAL(disp, ret); +} + +#endif /* EGL_NOK_swap_region */ + + +#ifdef EGL_MESA_drm_image + +EGLImageKHR EGLAPIENTRY +eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLDriver *drv; + _EGLImage *img; + EGLImageKHR ret; + + _EGL_CHECK_DISPLAY(disp, EGL_NO_IMAGE_KHR, drv); + if (!disp->Extensions.MESA_drm_image) + RETURN_EGL_EVAL(disp, EGL_NO_IMAGE_KHR); + + img = drv->API.CreateDRMImageMESA(drv, disp, attr_list); + ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR; + + RETURN_EGL_EVAL(disp, ret); +} + +EGLBoolean EGLAPIENTRY +eglExportDRMImageMESA(EGLDisplay dpy, EGLImageKHR image, + EGLint *name, EGLint *handle, EGLint *stride) +{ + _EGLDisplay *disp = _eglLockDisplay(dpy); + _EGLImage *img = _eglLookupImage(image, disp); + _EGLDriver *drv; + EGLBoolean ret; + + _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv); + assert(disp->Extensions.MESA_drm_image); + + if (!img) + RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); + + ret = drv->API.ExportDRMImageMESA(drv, disp, img, name, handle, stride); + + RETURN_EGL_EVAL(disp, ret); +} + +#endif diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h new file mode 100644 index 0000000..127becc --- /dev/null +++ b/src/egl/main/eglapi.h @@ -0,0 +1,174 @@ +#ifndef EGLAPI_INCLUDED +#define EGLAPI_INCLUDED + +/** + * A generic function ptr type + */ +typedef void (*_EGLProc)(void); + + +/** + * Typedefs for all EGL API entrypoint functions. + */ + +/* driver funcs */ +typedef EGLBoolean (*Initialize_t)(_EGLDriver *, _EGLDisplay *dpy, EGLint *major, EGLint *minor); +typedef EGLBoolean (*Terminate_t)(_EGLDriver *, _EGLDisplay *dpy); + +/* config funcs */ +typedef EGLBoolean (*GetConfigs_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config); +typedef EGLBoolean (*ChooseConfig_t)(_EGLDriver *drv, _EGLDisplay *dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); +typedef EGLBoolean (*GetConfigAttrib_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, EGLint attribute, EGLint *value); + +/* context funcs */ +typedef _EGLContext *(*CreateContext_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, _EGLContext *share_list, const EGLint *attrib_list); +typedef EGLBoolean (*DestroyContext_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx); +/* this is the only function (other than Initialize) that may be called with an uninitialized display */ +typedef EGLBoolean (*MakeCurrent_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx); +typedef EGLBoolean (*QueryContext_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value); + +/* surface funcs */ +typedef _EGLSurface *(*CreateWindowSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, EGLNativeWindowType window, const EGLint *attrib_list); +typedef _EGLSurface *(*CreatePixmapSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, EGLNativePixmapType pixmap, const EGLint *attrib_list); +typedef _EGLSurface *(*CreatePbufferSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, const EGLint *attrib_list); +typedef EGLBoolean (*DestroySurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface); +typedef EGLBoolean (*QuerySurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint attribute, EGLint *value); +typedef EGLBoolean (*SurfaceAttrib_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint attribute, EGLint value); +typedef EGLBoolean (*BindTexImage_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint buffer); +typedef EGLBoolean (*ReleaseTexImage_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint buffer); +typedef EGLBoolean (*SwapInterval_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval); +typedef EGLBoolean (*SwapBuffers_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw); +typedef EGLBoolean (*CopyBuffers_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLNativePixmapType target); + +/* misc funcs */ +typedef const char *(*QueryString_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLint name); +typedef EGLBoolean (*WaitClient_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx); +typedef EGLBoolean (*WaitNative_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine); + +/* this function may be called from multiple threads at the same time */ +typedef _EGLProc (*GetProcAddress_t)(_EGLDriver *drv, const char *procname); + + + +#ifdef EGL_MESA_screen_surface +typedef EGLBoolean (*ChooseModeMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, const EGLint *attrib_list, EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes); +typedef EGLBoolean (*GetModesMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, EGLModeMESA *modes, EGLint mode_size, EGLint *num_mode); +typedef EGLBoolean (*GetModeAttribMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLMode *mode, EGLint attribute, EGLint *value); +typedef EGLBoolean (*CopyContextMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *source, _EGLContext *dest, EGLint mask); +typedef EGLBoolean (*GetScreensMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens); +typedef _EGLSurface *(*CreateScreenSurfaceMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, const EGLint *attrib_list); +typedef EGLBoolean (*ShowScreenSurfaceMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, _EGLSurface *surface, _EGLMode *mode); +typedef EGLBoolean (*ScreenPositionMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, EGLint x, EGLint y); +typedef EGLBoolean (*QueryScreenMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, EGLint attribute, EGLint *value); +typedef EGLBoolean (*QueryScreenSurfaceMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, _EGLSurface **surface); +typedef EGLBoolean (*QueryScreenModeMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *screen, _EGLMode **mode); +typedef const char * (*QueryModeStringMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLMode *mode); +#endif /* EGL_MESA_screen_surface */ + + +#ifdef EGL_VERSION_1_2 +typedef _EGLSurface *(*CreatePbufferFromClientBuffer_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLenum buftype, EGLClientBuffer buffer, _EGLConfig *config, const EGLint *attrib_list); +#endif /* EGL_VERSION_1_2 */ + + +#ifdef EGL_KHR_image_base +typedef _EGLImage *(*CreateImageKHR_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attr_list); +typedef EGLBoolean (*DestroyImageKHR_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *image); +#endif /* EGL_KHR_image_base */ + + +#ifdef EGL_KHR_reusable_sync +typedef _EGLSync *(*CreateSyncKHR_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLenum type, const EGLint *attrib_list); +typedef EGLBoolean (*DestroySyncKHR_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync); +typedef EGLint (*ClientWaitSyncKHR_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, EGLint flags, EGLTimeKHR timeout); +typedef EGLBoolean (*SignalSyncKHR_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, EGLenum mode); +typedef EGLBoolean (*GetSyncAttribKHR_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, EGLint attribute, EGLint *value); +#endif /* EGL_KHR_reusable_sync */ + + +#ifdef EGL_NOK_swap_region +typedef EGLBoolean (*SwapBuffersRegionNOK_t)(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint numRects, const EGLint *rects); +#endif + +#ifdef EGL_MESA_drm_image +typedef _EGLImage *(*CreateDRMImageMESA_t)(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attr_list); +typedef EGLBoolean (*ExportDRMImageMESA_t)(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img, EGLint *name, EGLint *handle, EGLint *stride); +#endif + +/** + * The API dispatcher jumps through these functions + */ +struct _egl_api +{ + Initialize_t Initialize; + Terminate_t Terminate; + + GetConfigs_t GetConfigs; + ChooseConfig_t ChooseConfig; + GetConfigAttrib_t GetConfigAttrib; + + CreateContext_t CreateContext; + DestroyContext_t DestroyContext; + MakeCurrent_t MakeCurrent; + QueryContext_t QueryContext; + + CreateWindowSurface_t CreateWindowSurface; + CreatePixmapSurface_t CreatePixmapSurface; + CreatePbufferSurface_t CreatePbufferSurface; + DestroySurface_t DestroySurface; + QuerySurface_t QuerySurface; + SurfaceAttrib_t SurfaceAttrib; + BindTexImage_t BindTexImage; + ReleaseTexImage_t ReleaseTexImage; + SwapInterval_t SwapInterval; + SwapBuffers_t SwapBuffers; + CopyBuffers_t CopyBuffers; + + QueryString_t QueryString; + WaitClient_t WaitClient; + WaitNative_t WaitNative; + GetProcAddress_t GetProcAddress; + +#ifdef EGL_MESA_screen_surface + ChooseModeMESA_t ChooseModeMESA; + GetModesMESA_t GetModesMESA; + GetModeAttribMESA_t GetModeAttribMESA; + CopyContextMESA_t CopyContextMESA; + GetScreensMESA_t GetScreensMESA; + CreateScreenSurfaceMESA_t CreateScreenSurfaceMESA; + ShowScreenSurfaceMESA_t ShowScreenSurfaceMESA; + ScreenPositionMESA_t ScreenPositionMESA; + QueryScreenMESA_t QueryScreenMESA; + QueryScreenSurfaceMESA_t QueryScreenSurfaceMESA; + QueryScreenModeMESA_t QueryScreenModeMESA; + QueryModeStringMESA_t QueryModeStringMESA; +#endif /* EGL_MESA_screen_surface */ + +#ifdef EGL_VERSION_1_2 + CreatePbufferFromClientBuffer_t CreatePbufferFromClientBuffer; +#endif + +#ifdef EGL_KHR_image_base + CreateImageKHR_t CreateImageKHR; + DestroyImageKHR_t DestroyImageKHR; +#endif /* EGL_KHR_image_base */ + +#ifdef EGL_KHR_reusable_sync + CreateSyncKHR_t CreateSyncKHR; + DestroySyncKHR_t DestroySyncKHR; + ClientWaitSyncKHR_t ClientWaitSyncKHR; + SignalSyncKHR_t SignalSyncKHR; + GetSyncAttribKHR_t GetSyncAttribKHR; +#endif /* EGL_KHR_reusable_sync */ + +#ifdef EGL_NOK_swap_region + SwapBuffersRegionNOK_t SwapBuffersRegionNOK; +#endif + +#ifdef EGL_MESA_drm_image + CreateDRMImageMESA_t CreateDRMImageMESA; + ExportDRMImageMESA_t ExportDRMImageMESA; +#endif +}; + +#endif /* EGLAPI_INCLUDED */ diff --git a/src/egl/main/eglarray.c b/src/egl/main/eglarray.c new file mode 100644 index 0000000..fe2f1a7 --- /dev/null +++ b/src/egl/main/eglarray.c @@ -0,0 +1,181 @@ +#include +#include + +#include "egllog.h" +#include "eglarray.h" + + +/** + * Grow the size of the array. + */ +static EGLBoolean +_eglGrowArray(_EGLArray *array) +{ + EGLint new_size; + void **elems; + + new_size = array->MaxSize; + while (new_size <= array->Size) + new_size *= 2; + + elems = realloc(array->Elements, new_size * sizeof(array->Elements[0])); + if (!elems) { + _eglLog(_EGL_DEBUG, "failed to grow %s array to %d", + array->Name, new_size); + return EGL_FALSE; + } + + array->Elements = elems; + array->MaxSize = new_size; + + return EGL_TRUE; +} + + +/** + * Create an array. + */ +_EGLArray * +_eglCreateArray(const char *name, EGLint init_size) +{ + _EGLArray *array; + + array = calloc(1, sizeof(*array)); + if (array) { + array->Name = name; + array->MaxSize = (init_size > 0) ? init_size : 1; + if (!_eglGrowArray(array)) { + free(array); + array = NULL; + } + } + + return array; +} + + +/** + * Destroy an array, optionally free the data. + */ +void +_eglDestroyArray(_EGLArray *array, void (*free_cb)(void *)) +{ + if (free_cb) { + EGLint i; + for (i = 0; i < array->Size; i++) + free_cb(array->Elements[i]); + } + free(array->Elements); + free(array); +} + + +/** + * Append a element to an array. + */ +void +_eglAppendArray(_EGLArray *array, void *elem) +{ + if (array->Size >= array->MaxSize && !_eglGrowArray(array)) + return; + + array->Elements[array->Size++] = elem; +} + + +/** + * Erase an element from an array. + */ +void +_eglEraseArray(_EGLArray *array, EGLint i, void (*free_cb)(void *)) +{ + if (free_cb) + free_cb(array->Elements[i]); + if (i < array->Size - 1) { + memmove(&array->Elements[i], &array->Elements[i + 1], + (array->Size - i - 1) * sizeof(array->Elements[0])); + } + array->Size--; +} + + +/** + * Find in an array for the given element. + */ +void * +_eglFindArray(_EGLArray *array, void *elem) +{ + EGLint i; + + if (!array) + return NULL; + + for (i = 0; i < array->Size; i++) + if (array->Elements[i] == elem) + return elem; + return NULL; +} + + +/** + * Filter an array and return the number of filtered elements. + */ +EGLint +_eglFilterArray(_EGLArray *array, void **data, EGLint size, + _EGLArrayForEach filter, void *filter_data) +{ + EGLint count = 0, i; + + if (!array) + return 0; + + if (filter) { + for (i = 0; i < array->Size; i++) { + if (filter(array->Elements[i], filter_data)) { + if (data && count < size) + data[count] = array->Elements[i]; + count++; + } + if (data && count >= size) + break; + } + } + else { + if (data) { + count = (size < array->Size) ? size : array->Size; + memcpy(data, array->Elements, count * sizeof(array->Elements[0])); + } + else { + count = array->Size; + } + } + + return count; +} + + +/** + * Flatten an array by converting array elements into another form and store + * them in a buffer. + */ +EGLint +_eglFlattenArray(_EGLArray *array, void *buffer, EGLint elem_size, EGLint size, + _EGLArrayForEach flatten) +{ + EGLint i, count; + + if (!array) + return 0; + + count = array->Size; + if (buffer) { + /* do not exceed buffer size */ + if (count > size) + count = size; + for (i = 0; i < count; i++) + flatten(array->Elements[i], + (void *) ((char *) buffer + elem_size * i)); + } + + return count; +} diff --git a/src/egl/main/eglarray.h b/src/egl/main/eglarray.h new file mode 100644 index 0000000..a88189a --- /dev/null +++ b/src/egl/main/eglarray.h @@ -0,0 +1,57 @@ +#ifndef EGLARRAY_INCLUDED +#define EGLARRAY_INCLUDED + + +#include "egltypedefs.h" + + +typedef EGLBoolean (*_EGLArrayForEach)(void *elem, void *foreach_data); + + +struct _egl_array { + const char *Name; + EGLint MaxSize; + + void **Elements; + EGLint Size; +}; + + +extern _EGLArray * +_eglCreateArray(const char *name, EGLint init_size); + + +PUBLIC void +_eglDestroyArray(_EGLArray *array, void (*free_cb)(void *)); + + +extern void +_eglAppendArray(_EGLArray *array, void *elem); + + +extern void +_eglEraseArray(_EGLArray *array, EGLint i, void (*free_cb)(void *)); + + +void * +_eglFindArray(_EGLArray *array, void *elem); + + +PUBLIC EGLint +_eglFilterArray(_EGLArray *array, void **data, EGLint size, + _EGLArrayForEach filter, void *filter_data); + + +EGLint +_eglFlattenArray(_EGLArray *array, void *buffer, EGLint elem_size, EGLint size, + _EGLArrayForEach flatten); + + +static INLINE EGLint +_eglGetArraySize(_EGLArray *array) +{ + return (array) ? array->Size : 0; +} + + +#endif /* EGLARRAY_INCLUDED */ diff --git a/src/egl/main/eglcompiler.h b/src/egl/main/eglcompiler.h new file mode 100644 index 0000000..90c75e8 --- /dev/null +++ b/src/egl/main/eglcompiler.h @@ -0,0 +1,94 @@ +#ifndef EGLCOMPILER_INCLUDED +#define EGLCOMPILER_INCLUDED + + +/** + * Get standard integer types + */ +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) +# include +#elif defined(_MSC_VER) + typedef __int8 int8_t; + typedef unsigned __int8 uint8_t; + typedef __int16 int16_t; + typedef unsigned __int16 uint16_t; + typedef __int32 int32_t; + typedef unsigned __int32 uint32_t; + typedef __int64 int64_t; + typedef unsigned __int64 uint64_t; + +# if defined(_WIN64) + typedef __int64 intptr_t; + typedef unsigned __int64 uintptr_t; +# else + typedef __int32 intptr_t; + typedef unsigned __int32 uintptr_t; +# endif + +# define INT64_C(__val) __val##i64 +# define UINT64_C(__val) __val##ui64 +#else +/* hope the best instead of adding a bunch of ifdef's */ +# include +#endif + + +/** + * Function inlining + */ +#if defined(__GNUC__) +# define INLINE __inline__ +#elif defined(__MSC__) +# define INLINE __inline +#elif defined(_MSC_VER) +# define INLINE __inline +#elif defined(__ICL) +# define INLINE __inline +#elif defined(__INTEL_COMPILER) +# define INLINE inline +#elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100) +# define INLINE __inline +#elif defined(__SUNPRO_C) && defined(__C99FEATURES__) +# define INLINE inline +# define __inline inline +# define __inline__ inline +#elif (__STDC_VERSION__ >= 199901L) /* C99 */ +# define INLINE inline +#else +# define INLINE +#endif + + +/** + * Function visibility + */ +#ifndef PUBLIC +# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define PUBLIC __attribute__((visibility("default"))) +# elif defined(_MSC_VER) +# define PUBLIC __declspec(dllexport) +# else +# define PUBLIC +# endif +#endif + +/** + * The __FUNCTION__ gcc variable is generally only used for debugging. + * If we're not using gcc, define __FUNCTION__ as a cpp symbol here. + * Don't define it if using a newer Windows compiler. + */ +#ifndef __FUNCTION__ +# if defined(__VMS) +# define __FUNCTION__ "VMS$NL:" +# elif (!defined __GNUC__) && (!defined __xlC__) && \ + (!defined(_MSC_VER) || _MSC_VER < 1300) +# if (__STDC_VERSION__ >= 199901L) /* C99 */ || \ + (defined(__SUNPRO_C) && defined(__C99FEATURES__)) +# define __FUNCTION__ __func__ +# else +# define __FUNCTION__ "" +# endif +# endif +#endif + +#endif /* EGLCOMPILER_INCLUDED */ diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c new file mode 100644 index 0000000..5b377b7 --- /dev/null +++ b/src/egl/main/eglconfig.c @@ -0,0 +1,773 @@ +/** + * EGL Configuration (pixel format) functions. + */ + + +#include +#include +#include +#include "eglconfig.h" +#include "egldisplay.h" +#include "eglcurrent.h" +#include "egllog.h" + + +#define MIN2(A, B) (((A) < (B)) ? (A) : (B)) + + +/** + * Init the given _EGLconfig to default values. + * \param id the configuration's ID. + * + * Note that id must be positive for the config to be valid. + * It is also recommended that when there are N configs, their + * IDs are from 1 to N respectively. + */ +void +_eglInitConfig(_EGLConfig *conf, _EGLDisplay *dpy, EGLint id) +{ + memset(conf, 0, sizeof(*conf)); + + conf->Display = dpy; + + /* some attributes take non-zero default values */ + conf->ConfigID = id; + conf->ConfigCaveat = EGL_NONE; + conf->TransparentType = EGL_NONE; + conf->NativeVisualType = EGL_NONE; + conf->ColorBufferType = EGL_RGB_BUFFER; +} + + +/** + * Link a config to its display and return the handle of the link. + * The handle can be passed to client directly. + * + * Note that we just save the ptr to the config (we don't copy the config). + */ +PUBLIC EGLConfig +_eglLinkConfig(_EGLConfig *conf) +{ + _EGLDisplay *dpy = conf->Display; + + /* sanity check */ + assert(dpy && conf->ConfigID > 0); + + if (!dpy->Configs) { + dpy->Configs = _eglCreateArray("Config", 16); + if (!dpy->Configs) + return (EGLConfig) NULL; + } + + _eglAppendArray(dpy->Configs, (void *) conf); + + return (EGLConfig) conf; +} + + +/** + * Lookup a handle to find the linked config. + * Return NULL if the handle has no corresponding linked config. + */ +_EGLConfig * +_eglLookupConfig(EGLConfig config, _EGLDisplay *dpy) +{ + _EGLConfig *conf; + + if (!dpy) + return NULL; + + conf = (_EGLConfig *) _eglFindArray(dpy->Configs, (void *) config); + if (conf) + assert(conf->Display == dpy); + + return conf; +} + + +enum { + /* types */ + ATTRIB_TYPE_INTEGER, + ATTRIB_TYPE_BOOLEAN, + ATTRIB_TYPE_BITMASK, + ATTRIB_TYPE_ENUM, + ATTRIB_TYPE_PSEUDO, /* non-queryable */ + ATTRIB_TYPE_PLATFORM, /* platform-dependent */ + /* criteria */ + ATTRIB_CRITERION_EXACT, + ATTRIB_CRITERION_ATLEAST, + ATTRIB_CRITERION_MASK, + ATTRIB_CRITERION_SPECIAL, + ATTRIB_CRITERION_IGNORE +}; + + +/* EGL spec Table 3.1 and 3.4 */ +static const struct { + EGLint attr; + EGLint type; + EGLint criterion; + EGLint default_value; +} _eglValidationTable[] = +{ + /* core */ + { EGL_BUFFER_SIZE, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_ATLEAST, + 0 }, + { EGL_RED_SIZE, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_ATLEAST, + 0 }, + { EGL_GREEN_SIZE, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_ATLEAST, + 0 }, + { EGL_BLUE_SIZE, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_ATLEAST, + 0 }, + { EGL_LUMINANCE_SIZE, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_ATLEAST, + 0 }, + { EGL_ALPHA_SIZE, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_ATLEAST, + 0 }, + { EGL_ALPHA_MASK_SIZE, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_ATLEAST, + 0 }, + { EGL_BIND_TO_TEXTURE_RGB, ATTRIB_TYPE_BOOLEAN, + ATTRIB_CRITERION_EXACT, + EGL_DONT_CARE }, + { EGL_BIND_TO_TEXTURE_RGBA, ATTRIB_TYPE_BOOLEAN, + ATTRIB_CRITERION_EXACT, + EGL_DONT_CARE }, + { EGL_COLOR_BUFFER_TYPE, ATTRIB_TYPE_ENUM, + ATTRIB_CRITERION_EXACT, + EGL_RGB_BUFFER }, + { EGL_CONFIG_CAVEAT, ATTRIB_TYPE_ENUM, + ATTRIB_CRITERION_EXACT, + EGL_DONT_CARE }, + { EGL_CONFIG_ID, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_EXACT, + EGL_DONT_CARE }, + { EGL_CONFORMANT, ATTRIB_TYPE_BITMASK, + ATTRIB_CRITERION_MASK, + 0 }, + { EGL_DEPTH_SIZE, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_ATLEAST, + 0 }, + { EGL_LEVEL, ATTRIB_TYPE_PLATFORM, + ATTRIB_CRITERION_EXACT, + 0 }, + { EGL_MAX_PBUFFER_WIDTH, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_IGNORE, + 0 }, + { EGL_MAX_PBUFFER_HEIGHT, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_IGNORE, + 0 }, + { EGL_MAX_PBUFFER_PIXELS, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_IGNORE, + 0 }, + { EGL_MAX_SWAP_INTERVAL, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_EXACT, + EGL_DONT_CARE }, + { EGL_MIN_SWAP_INTERVAL, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_EXACT, + EGL_DONT_CARE }, + { EGL_NATIVE_RENDERABLE, ATTRIB_TYPE_BOOLEAN, + ATTRIB_CRITERION_EXACT, + EGL_DONT_CARE }, + { EGL_NATIVE_VISUAL_ID, ATTRIB_TYPE_PLATFORM, + ATTRIB_CRITERION_IGNORE, + 0 }, + { EGL_NATIVE_VISUAL_TYPE, ATTRIB_TYPE_PLATFORM, + ATTRIB_CRITERION_EXACT, + EGL_DONT_CARE }, + { EGL_RENDERABLE_TYPE, ATTRIB_TYPE_BITMASK, + ATTRIB_CRITERION_MASK, + EGL_OPENGL_ES_BIT }, + { EGL_SAMPLE_BUFFERS, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_ATLEAST, + 0 }, + { EGL_SAMPLES, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_ATLEAST, + 0 }, + { EGL_STENCIL_SIZE, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_ATLEAST, + 0 }, + { EGL_SURFACE_TYPE, ATTRIB_TYPE_BITMASK, + ATTRIB_CRITERION_MASK, + EGL_WINDOW_BIT }, + { EGL_TRANSPARENT_TYPE, ATTRIB_TYPE_ENUM, + ATTRIB_CRITERION_EXACT, + EGL_NONE }, + { EGL_TRANSPARENT_RED_VALUE, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_EXACT, + EGL_DONT_CARE }, + { EGL_TRANSPARENT_GREEN_VALUE, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_EXACT, + EGL_DONT_CARE }, + { EGL_TRANSPARENT_BLUE_VALUE, ATTRIB_TYPE_INTEGER, + ATTRIB_CRITERION_EXACT, + EGL_DONT_CARE }, + { EGL_MATCH_NATIVE_PIXMAP, ATTRIB_TYPE_PSEUDO, + ATTRIB_CRITERION_SPECIAL, + EGL_NONE }, + /* extensions */ + { EGL_Y_INVERTED_NOK, ATTRIB_TYPE_BOOLEAN, + ATTRIB_CRITERION_EXACT, + EGL_DONT_CARE } +}; + + +/** + * Return true if a config is valid. When for_matching is true, + * EGL_DONT_CARE is accepted as a valid attribute value, and checks + * for conflicting attribute values are skipped. + * + * Note that some attributes are platform-dependent and are not + * checked. + */ +EGLBoolean +_eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching) +{ + EGLint i, attr, val; + EGLBoolean valid = EGL_TRUE; + + /* check attributes by their types */ + for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) { + EGLint mask; + + attr = _eglValidationTable[i].attr; + val = _eglGetConfigKey(conf, attr); + + switch (_eglValidationTable[i].type) { + case ATTRIB_TYPE_INTEGER: + switch (attr) { + case EGL_CONFIG_ID: + /* config id must be positive */ + if (val <= 0) + valid = EGL_FALSE; + break; + case EGL_SAMPLE_BUFFERS: + /* there can be at most 1 sample buffer */ + if (val > 1 || val < 0) + valid = EGL_FALSE; + break; + default: + if (val < 0) + valid = EGL_FALSE; + break; + } + break; + case ATTRIB_TYPE_BOOLEAN: + if (val != EGL_TRUE && val != EGL_FALSE) + valid = EGL_FALSE; + break; + case ATTRIB_TYPE_ENUM: + switch (attr) { + case EGL_CONFIG_CAVEAT: + if (val != EGL_NONE && val != EGL_SLOW_CONFIG && + val != EGL_NON_CONFORMANT_CONFIG) + valid = EGL_FALSE; + break; + case EGL_TRANSPARENT_TYPE: + if (val != EGL_NONE && val != EGL_TRANSPARENT_RGB) + valid = EGL_FALSE; + break; + case EGL_COLOR_BUFFER_TYPE: + if (val != EGL_RGB_BUFFER && val != EGL_LUMINANCE_BUFFER) + valid = EGL_FALSE; + break; + default: + assert(0); + break; + } + break; + case ATTRIB_TYPE_BITMASK: + switch (attr) { + case EGL_SURFACE_TYPE: + mask = EGL_PBUFFER_BIT | + EGL_PIXMAP_BIT | + EGL_WINDOW_BIT | + EGL_VG_COLORSPACE_LINEAR_BIT | + EGL_VG_ALPHA_FORMAT_PRE_BIT | + EGL_MULTISAMPLE_RESOLVE_BOX_BIT | + EGL_SWAP_BEHAVIOR_PRESERVED_BIT; +#ifdef EGL_MESA_screen_surface + if (conf->Display->Extensions.MESA_screen_surface) + mask |= EGL_SCREEN_BIT_MESA; +#endif + break; + case EGL_RENDERABLE_TYPE: + case EGL_CONFORMANT: + mask = EGL_OPENGL_ES_BIT | + EGL_OPENVG_BIT | + EGL_OPENGL_ES2_BIT | + EGL_OPENGL_BIT; + break; + default: + assert(0); + break; + } + if (val & ~mask) + valid = EGL_FALSE; + break; + case ATTRIB_TYPE_PLATFORM: + /* unable to check platform-dependent attributes here */ + break; + case ATTRIB_TYPE_PSEUDO: + /* pseudo attributes should not be set */ + if (val != 0) + valid = EGL_FALSE; + break; + default: + assert(0); + break; + } + + if (!valid && for_matching) { + /* accept EGL_DONT_CARE as a valid value */ + if (val == EGL_DONT_CARE) + valid = EGL_TRUE; + if (_eglValidationTable[i].criterion == ATTRIB_CRITERION_SPECIAL) + valid = EGL_TRUE; + } + if (!valid) { + _eglLog(_EGL_DEBUG, + "attribute 0x%04x has an invalid value 0x%x", attr, val); + break; + } + } + + /* any invalid attribute value should have been catched */ + if (!valid || for_matching) + return valid; + + /* now check for conflicting attribute values */ + + switch (conf->ColorBufferType) { + case EGL_RGB_BUFFER: + if (conf->LuminanceSize) + valid = EGL_FALSE; + if (conf->RedSize + conf->GreenSize + + conf->BlueSize + conf->AlphaSize != conf->BufferSize) + valid = EGL_FALSE; + break; + case EGL_LUMINANCE_BUFFER: + if (conf->RedSize || conf->GreenSize || conf->BlueSize) + valid = EGL_FALSE; + if (conf->LuminanceSize + conf->AlphaSize != conf->BufferSize) + valid = EGL_FALSE; + break; + } + if (!valid) { + _eglLog(_EGL_DEBUG, "conflicting color buffer type and channel sizes"); + return EGL_FALSE; + } + + if (!conf->SampleBuffers && conf->Samples) + valid = EGL_FALSE; + if (!valid) { + _eglLog(_EGL_DEBUG, "conflicting samples and sample buffers"); + return EGL_FALSE; + } + + if (!(conf->SurfaceType & EGL_WINDOW_BIT)) { + if (conf->NativeVisualID != 0 || conf->NativeVisualType != EGL_NONE) + valid = EGL_FALSE; + } + if (!(conf->SurfaceType & EGL_PBUFFER_BIT)) { + if (conf->BindToTextureRGB || conf->BindToTextureRGBA) + valid = EGL_FALSE; + } + if (!valid) { + _eglLog(_EGL_DEBUG, "conflicting surface type and native visual/texture binding"); + return EGL_FALSE; + } + + return valid; +} + + +/** + * Return true if a config matches the criteria. This and + * _eglParseConfigAttribList together implement the algorithm + * described in "Selection of EGLConfigs". + * + * Note that attributes that are special (currently, only + * EGL_MATCH_NATIVE_PIXMAP) are ignored. + */ +EGLBoolean +_eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria) +{ + EGLint attr, val, i; + EGLBoolean matched = EGL_TRUE; + + for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) { + EGLint cmp; + if (_eglValidationTable[i].criterion == ATTRIB_CRITERION_IGNORE) + continue; + + attr = _eglValidationTable[i].attr; + cmp = _eglGetConfigKey(criteria, attr); + if (cmp == EGL_DONT_CARE) + continue; + + val = _eglGetConfigKey(conf, attr); + switch (_eglValidationTable[i].criterion) { + case ATTRIB_CRITERION_EXACT: + if (val != cmp) + matched = EGL_FALSE; + break; + case ATTRIB_CRITERION_ATLEAST: + if (val < cmp) + matched = EGL_FALSE; + break; + case ATTRIB_CRITERION_MASK: + if ((val & cmp) != cmp) + matched = EGL_FALSE; + break; + case ATTRIB_CRITERION_SPECIAL: + /* ignored here */ + break; + default: + assert(0); + break; + } + + if (!matched) { +#ifndef DEBUG + /* only print the common errors when DEBUG is not defined */ + if (attr != EGL_RENDERABLE_TYPE) + break; +#endif + _eglLog(_EGL_DEBUG, + "the value (0x%x) of attribute 0x%04x did not meet the criteria (0x%x)", + val, attr, cmp); + break; + } + } + + return matched; +} + +static INLINE EGLBoolean +_eglIsConfigAttribValid(_EGLConfig *conf, EGLint attr) +{ + if (_eglOffsetOfConfig(attr) < 0) + return EGL_FALSE; + + switch (attr) { + case EGL_MATCH_NATIVE_PIXMAP: + return EGL_FALSE; + case EGL_Y_INVERTED_NOK: + return conf->Display->Extensions.NOK_texture_from_pixmap; + default: + break; + } + + return EGL_TRUE; +} + +/** + * Initialize a criteria config from the given attribute list. + * Return EGL_FALSE if any of the attribute is invalid. + */ +EGLBoolean +_eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *dpy, + const EGLint *attrib_list) +{ + EGLint attr, val, i; + + _eglInitConfig(conf, dpy, EGL_DONT_CARE); + + /* reset to default values */ + for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) { + attr = _eglValidationTable[i].attr; + val = _eglValidationTable[i].default_value; + _eglSetConfigKey(conf, attr, val); + } + + /* parse the list */ + for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i += 2) { + attr = attrib_list[i]; + val = attrib_list[i + 1]; + + if (!_eglIsConfigAttribValid(conf, attr)) + return EGL_FALSE; + + _eglSetConfigKey(conf, attr, val); + } + + if (!_eglValidateConfig(conf, EGL_TRUE)) + return EGL_FALSE; + + /* the spec says that EGL_LEVEL cannot be EGL_DONT_CARE */ + if (conf->Level == EGL_DONT_CARE) + return EGL_FALSE; + + /* ignore other attributes when EGL_CONFIG_ID is given */ + if (conf->ConfigID != EGL_DONT_CARE) { + for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) { + attr = _eglValidationTable[i].attr; + if (attr != EGL_CONFIG_ID) + _eglSetConfigKey(conf, attr, EGL_DONT_CARE); + } + } + else { + if (!(conf->SurfaceType & EGL_WINDOW_BIT)) + conf->NativeVisualType = EGL_DONT_CARE; + + if (conf->TransparentType == EGL_NONE) { + conf->TransparentRedValue = EGL_DONT_CARE; + conf->TransparentGreenValue = EGL_DONT_CARE; + conf->TransparentBlueValue = EGL_DONT_CARE; + } + } + + return EGL_TRUE; +} + + +/** + * Decide the ordering of conf1 and conf2, under the given criteria. + * When compare_id is true, this implements the algorithm described + * in "Sorting of EGLConfigs". When compare_id is false, + * EGL_CONFIG_ID is not compared. + * + * It returns a negative integer if conf1 is considered to come + * before conf2; a positive integer if conf2 is considered to come + * before conf1; zero if the ordering cannot be decided. + * + * Note that EGL_NATIVE_VISUAL_TYPE is platform-dependent and is + * ignored here. + */ +EGLint +_eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2, + const _EGLConfig *criteria, EGLBoolean compare_id) +{ + const EGLint compare_attribs[] = { + EGL_BUFFER_SIZE, + EGL_SAMPLE_BUFFERS, + EGL_SAMPLES, + EGL_DEPTH_SIZE, + EGL_STENCIL_SIZE, + EGL_ALPHA_MASK_SIZE, + }; + EGLint val1, val2; + EGLint i; + + if (conf1 == conf2) + return 0; + + /* the enum values have the desired ordering */ + assert(EGL_NONE < EGL_SLOW_CONFIG); + assert(EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG); + val1 = conf1->ConfigCaveat - conf2->ConfigCaveat; + if (val1) + return val1; + + /* the enum values have the desired ordering */ + assert(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER); + val1 = conf1->ColorBufferType - conf2->ColorBufferType; + if (val1) + return val1; + + if (criteria) { + val1 = val2 = 0; + if (conf1->ColorBufferType == EGL_RGB_BUFFER) { + if (criteria->RedSize > 0) { + val1 += conf1->RedSize; + val2 += conf2->RedSize; + } + if (criteria->GreenSize > 0) { + val1 += conf1->GreenSize; + val2 += conf2->GreenSize; + } + if (criteria->BlueSize > 0) { + val1 += conf1->BlueSize; + val2 += conf2->BlueSize; + } + } + else { + if (criteria->LuminanceSize > 0) { + val1 += conf1->LuminanceSize; + val2 += conf2->LuminanceSize; + } + } + if (criteria->AlphaSize > 0) { + val1 += conf1->AlphaSize; + val2 += conf2->AlphaSize; + } + } + else { + /* assume the default criteria, which gives no specific ordering */ + val1 = val2 = 0; + } + + /* for color bits, larger one is preferred */ + if (val1 != val2) + return (val2 - val1); + + for (i = 0; i < ARRAY_SIZE(compare_attribs); i++) { + val1 = _eglGetConfigKey(conf1, compare_attribs[i]); + val2 = _eglGetConfigKey(conf2, compare_attribs[i]); + if (val1 != val2) + return (val1 - val2); + } + + /* EGL_NATIVE_VISUAL_TYPE cannot be compared here */ + + return (compare_id) ? (conf1->ConfigID - conf2->ConfigID) : 0; +} + + +static INLINE +void _eglSwapConfigs(const _EGLConfig **conf1, const _EGLConfig **conf2) +{ + const _EGLConfig *tmp = *conf1; + *conf1 = *conf2; + *conf2 = tmp; +} + + +/** + * Quick sort an array of configs. This differs from the standard + * qsort() in that the compare function accepts an additional + * argument. + */ +void +_eglSortConfigs(const _EGLConfig **configs, EGLint count, + EGLint (*compare)(const _EGLConfig *, const _EGLConfig *, + void *), + void *priv_data) +{ + const EGLint pivot = 0; + EGLint i, j; + + if (count <= 1) + return; + + _eglSwapConfigs(&configs[pivot], &configs[count / 2]); + i = 1; + j = count - 1; + do { + while (i < count && compare(configs[i], configs[pivot], priv_data) < 0) + i++; + while (compare(configs[j], configs[pivot], priv_data) > 0) + j--; + if (i < j) { + _eglSwapConfigs(&configs[i], &configs[j]); + i++; + j--; + } + else if (i == j) { + i++; + j--; + break; + } + } while (i <= j); + _eglSwapConfigs(&configs[pivot], &configs[j]); + + _eglSortConfigs(configs, j, compare, priv_data); + _eglSortConfigs(configs + i, count - i, compare, priv_data); +} + + +static int +_eglFallbackCompare(const _EGLConfig *conf1, const _EGLConfig *conf2, + void *priv_data) +{ + const _EGLConfig *criteria = (const _EGLConfig *) priv_data; + return _eglCompareConfigs(conf1, conf2, criteria, EGL_TRUE); +} + + +/** + * Typical fallback routine for eglChooseConfig + */ +EGLBoolean +_eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list, + EGLConfig *configs, EGLint config_size, EGLint *num_configs) +{ + _EGLConfig **configList, criteria; + EGLint i, count; + + if (!num_configs) + return _eglError(EGL_BAD_PARAMETER, "eglChooseConfigs"); + + if (!_eglParseConfigAttribList(&criteria, disp, attrib_list)) + return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig"); + + /* get the number of matched configs */ + count = _eglFilterArray(disp->Configs, NULL, 0, + (_EGLArrayForEach) _eglMatchConfig, (void *) &criteria); + if (!count) { + *num_configs = count; + return EGL_TRUE; + } + + configList = malloc(sizeof(*configList) * count); + if (!configList) + return _eglError(EGL_BAD_ALLOC, "eglChooseConfig(out of memory)"); + + /* get the matched configs */ + _eglFilterArray(disp->Configs, (void **) configList, count, + (_EGLArrayForEach) _eglMatchConfig, (void *) &criteria); + + /* perform sorting of configs */ + if (configs && count) { + _eglSortConfigs((const _EGLConfig **) configList, count, + _eglFallbackCompare, (void *) &criteria); + count = MIN2(count, config_size); + for (i = 0; i < count; i++) + configs[i] = _eglGetConfigHandle(configList[i]); + } + + free(configList); + + *num_configs = count; + + return EGL_TRUE; +} + + +/** + * Fallback for eglGetConfigAttrib. + */ +EGLBoolean +_eglGetConfigAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, + EGLint attribute, EGLint *value) +{ + if (!_eglIsConfigAttribValid(conf, attribute)) + return _eglError(EGL_BAD_ATTRIBUTE, "eglGetConfigAttrib"); + if (!value) + return _eglError(EGL_BAD_PARAMETER, "eglGetConfigAttrib"); + + *value = _eglGetConfigKey(conf, attribute); + return EGL_TRUE; +} + + +static EGLBoolean +_eglFlattenConfig(void *elem, void *buffer) +{ + _EGLConfig *conf = (_EGLConfig *) elem; + EGLConfig *handle = (EGLConfig *) buffer; + *handle = _eglGetConfigHandle(conf); + return EGL_TRUE; +} + +/** + * Fallback for eglGetConfigs. + */ +EGLBoolean +_eglGetConfigs(_EGLDriver *drv, _EGLDisplay *disp, EGLConfig *configs, + EGLint config_size, EGLint *num_config) +{ + if (!num_config) + return _eglError(EGL_BAD_PARAMETER, "eglGetConfigs"); + + *num_config = _eglFlattenArray(disp->Configs, (void *) configs, + sizeof(configs[0]), config_size, _eglFlattenConfig); + + return EGL_TRUE; +} diff --git a/src/egl/main/eglconfig.h b/src/egl/main/eglconfig.h new file mode 100644 index 0000000..2169960 --- /dev/null +++ b/src/egl/main/eglconfig.h @@ -0,0 +1,194 @@ +#ifndef EGLCONFIG_INCLUDED +#define EGLCONFIG_INCLUDED + + +#include +#include +#include "egltypedefs.h" + + +/* update _eglValidationTable and _eglOffsetOfConfig before updating this + * struct */ +struct _egl_config +{ + _EGLDisplay *Display; + + /* core */ + EGLint BufferSize; + EGLint AlphaSize; + EGLint BlueSize; + EGLint GreenSize; + EGLint RedSize; + EGLint DepthSize; + EGLint StencilSize; + EGLint ConfigCaveat; + EGLint ConfigID; + EGLint Level; + EGLint MaxPbufferHeight; + EGLint MaxPbufferPixels; + EGLint MaxPbufferWidth; + EGLint NativeRenderable; + EGLint NativeVisualID; + EGLint NativeVisualType; + EGLint Samples; + EGLint SampleBuffers; + EGLint SurfaceType; + EGLint TransparentType; + EGLint TransparentBlueValue; + EGLint TransparentGreenValue; + EGLint TransparentRedValue; + EGLint BindToTextureRGB; + EGLint BindToTextureRGBA; + EGLint MinSwapInterval; + EGLint MaxSwapInterval; + EGLint LuminanceSize; + EGLint AlphaMaskSize; + EGLint ColorBufferType; + EGLint RenderableType; + EGLint MatchNativePixmap; + EGLint Conformant; + + /* extensions */ + EGLint YInvertedNOK; +}; + + +/** + * Map an EGL attribute enum to the offset of the member in _EGLConfig. + */ +static INLINE EGLint +_eglOffsetOfConfig(EGLint attr) +{ + switch (attr) { +#define ATTRIB_MAP(attr, memb) case attr: return offsetof(_EGLConfig, memb) + /* core */ + ATTRIB_MAP(EGL_BUFFER_SIZE, BufferSize); + ATTRIB_MAP(EGL_ALPHA_SIZE, AlphaSize); + ATTRIB_MAP(EGL_BLUE_SIZE, BlueSize); + ATTRIB_MAP(EGL_GREEN_SIZE, GreenSize); + ATTRIB_MAP(EGL_RED_SIZE, RedSize); + ATTRIB_MAP(EGL_DEPTH_SIZE, DepthSize); + ATTRIB_MAP(EGL_STENCIL_SIZE, StencilSize); + ATTRIB_MAP(EGL_CONFIG_CAVEAT, ConfigCaveat); + ATTRIB_MAP(EGL_CONFIG_ID, ConfigID); + ATTRIB_MAP(EGL_LEVEL, Level); + ATTRIB_MAP(EGL_MAX_PBUFFER_HEIGHT, MaxPbufferHeight); + ATTRIB_MAP(EGL_MAX_PBUFFER_PIXELS, MaxPbufferPixels); + ATTRIB_MAP(EGL_MAX_PBUFFER_WIDTH, MaxPbufferWidth); + ATTRIB_MAP(EGL_NATIVE_RENDERABLE, NativeRenderable); + ATTRIB_MAP(EGL_NATIVE_VISUAL_ID, NativeVisualID); + ATTRIB_MAP(EGL_NATIVE_VISUAL_TYPE, NativeVisualType); + ATTRIB_MAP(EGL_SAMPLES, Samples); + ATTRIB_MAP(EGL_SAMPLE_BUFFERS, SampleBuffers); + ATTRIB_MAP(EGL_SURFACE_TYPE, SurfaceType); + ATTRIB_MAP(EGL_TRANSPARENT_TYPE, TransparentType); + ATTRIB_MAP(EGL_TRANSPARENT_BLUE_VALUE, TransparentBlueValue); + ATTRIB_MAP(EGL_TRANSPARENT_GREEN_VALUE, TransparentGreenValue); + ATTRIB_MAP(EGL_TRANSPARENT_RED_VALUE, TransparentRedValue); + ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGB, BindToTextureRGB); + ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGBA, BindToTextureRGBA); + ATTRIB_MAP(EGL_MIN_SWAP_INTERVAL, MinSwapInterval); + ATTRIB_MAP(EGL_MAX_SWAP_INTERVAL, MaxSwapInterval); + ATTRIB_MAP(EGL_LUMINANCE_SIZE, LuminanceSize); + ATTRIB_MAP(EGL_ALPHA_MASK_SIZE, AlphaMaskSize); + ATTRIB_MAP(EGL_COLOR_BUFFER_TYPE, ColorBufferType); + ATTRIB_MAP(EGL_RENDERABLE_TYPE, RenderableType); + ATTRIB_MAP(EGL_MATCH_NATIVE_PIXMAP, MatchNativePixmap); + ATTRIB_MAP(EGL_CONFORMANT, Conformant); + /* extensions */ + ATTRIB_MAP(EGL_Y_INVERTED_NOK, YInvertedNOK); +#undef ATTRIB_MAP + default: + return -1; + } +} + + +/** + * Update a config for a given key. + * + * Note that a valid key is not necessarily a valid attribute. There are gaps + * in the attribute enums. The separation is to catch application errors. + * Drivers should never set a key that is an invalid attribute. + */ +static INLINE void +_eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val) +{ + EGLint offset = _eglOffsetOfConfig(key); + assert(offset >= 0); + *((EGLint *) ((char *) conf + offset)) = val; +} + + +/** + * Return the value for a given key. + */ +static INLINE EGLint +_eglGetConfigKey(const _EGLConfig *conf, EGLint key) +{ + EGLint offset = _eglOffsetOfConfig(key); + assert(offset >= 0); + return *((EGLint *) ((char *) conf + offset)); +} + + +PUBLIC void +_eglInitConfig(_EGLConfig *config, _EGLDisplay *dpy, EGLint id); + + +PUBLIC EGLConfig +_eglLinkConfig(_EGLConfig *conf); + + +extern _EGLConfig * +_eglLookupConfig(EGLConfig config, _EGLDisplay *dpy); + + +/** + * Return the handle of a linked config. + */ +static INLINE EGLConfig +_eglGetConfigHandle(_EGLConfig *conf) +{ + return (EGLConfig) conf; +} + + +PUBLIC EGLBoolean +_eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching); + + +PUBLIC EGLBoolean +_eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria); + + +PUBLIC EGLBoolean +_eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *dpy, + const EGLint *attrib_list); + + +PUBLIC EGLint +_eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2, + const _EGLConfig *criteria, EGLBoolean compare_id); + + +PUBLIC void +_eglSortConfigs(const _EGLConfig **configs, EGLint count, + EGLint (*compare)(const _EGLConfig *, const _EGLConfig *, + void *), + void *priv_data); + + +extern EGLBoolean +_eglChooseConfig(_EGLDriver *drv, _EGLDisplay *dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); + + +extern EGLBoolean +_eglGetConfigAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, EGLint attribute, EGLint *value); + + +extern EGLBoolean +_eglGetConfigs(_EGLDriver *drv, _EGLDisplay *dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config); + + +#endif /* EGLCONFIG_INCLUDED */ diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c new file mode 100644 index 0000000..33dcfa6 --- /dev/null +++ b/src/egl/main/eglcontext.c @@ -0,0 +1,367 @@ +#include +#include +#include +#include "eglconfig.h" +#include "eglcontext.h" +#include "egldisplay.h" +#include "eglcurrent.h" +#include "eglsurface.h" +#include "egllog.h" + + +/** + * Return the API bit (one of EGL_xxx_BIT) of the context. + */ +static EGLint +_eglGetContextAPIBit(_EGLContext *ctx) +{ + EGLint bit = 0; + + switch (ctx->ClientAPI) { + case EGL_OPENGL_ES_API: + switch (ctx->ClientVersion) { + case 1: + bit = EGL_OPENGL_ES_BIT; + break; + case 2: + bit = EGL_OPENGL_ES2_BIT; + break; + default: + break; + } + break; + case EGL_OPENVG_API: + bit = EGL_OPENVG_BIT; + break; + case EGL_OPENGL_API: + bit = EGL_OPENGL_BIT; + break; + default: + break; + } + + return bit; +} + + +/** + * Parse the list of context attributes and return the proper error code. + */ +static EGLint +_eglParseContextAttribList(_EGLContext *ctx, const EGLint *attrib_list) +{ + EGLenum api = ctx->ClientAPI; + EGLint i, err = EGL_SUCCESS; + + if (!attrib_list) + return EGL_SUCCESS; + + for (i = 0; attrib_list[i] != EGL_NONE; i++) { + EGLint attr = attrib_list[i++]; + EGLint val = attrib_list[i]; + + switch (attr) { + case EGL_CONTEXT_CLIENT_VERSION: + if (api != EGL_OPENGL_ES_API) { + err = EGL_BAD_ATTRIBUTE; + break; + } + if (val != 1 && val != 2) { + err = EGL_BAD_ATTRIBUTE; + break; + } + ctx->ClientVersion = val; + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + + if (err != EGL_SUCCESS) { + _eglLog(_EGL_DEBUG, "bad context attribute 0x%04x", attr); + break; + } + } + + return err; +} + + +/** + * Initialize the given _EGLContext object to defaults and/or the values + * in the attrib_list. + */ +EGLBoolean +_eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy, _EGLConfig *conf, + const EGLint *attrib_list) +{ + const EGLenum api = eglQueryAPI(); + EGLint err; + + if (api == EGL_NONE) { + _eglError(EGL_BAD_MATCH, "eglCreateContext(no client API)"); + return EGL_FALSE; + } + + _eglInitResource(&ctx->Resource, sizeof(*ctx), dpy); + ctx->ClientAPI = api; + ctx->Config = conf; + ctx->WindowRenderBuffer = EGL_NONE; + + ctx->ClientVersion = 1; /* the default, per EGL spec */ + + err = _eglParseContextAttribList(ctx, attrib_list); + if (err == EGL_SUCCESS && ctx->Config) { + EGLint api_bit; + + api_bit = _eglGetContextAPIBit(ctx); + if (!(ctx->Config->RenderableType & api_bit)) { + _eglLog(_EGL_DEBUG, "context api is 0x%x while config supports 0x%x", + api_bit, ctx->Config->RenderableType); + err = EGL_BAD_CONFIG; + } + } + if (err != EGL_SUCCESS) + return _eglError(err, "eglCreateContext"); + + return EGL_TRUE; +} + + +#ifdef EGL_VERSION_1_2 +static EGLint +_eglQueryContextRenderBuffer(_EGLContext *ctx) +{ + _EGLSurface *surf = ctx->DrawSurface; + EGLint rb; + + if (!surf) + return EGL_NONE; + if (surf->Type == EGL_WINDOW_BIT && ctx->WindowRenderBuffer != EGL_NONE) + rb = ctx->WindowRenderBuffer; + else + rb = surf->RenderBuffer; + return rb; +} +#endif /* EGL_VERSION_1_2 */ + + +EGLBoolean +_eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *c, + EGLint attribute, EGLint *value) +{ + (void) drv; + (void) dpy; + + if (!value) + return _eglError(EGL_BAD_PARAMETER, "eglQueryContext"); + + switch (attribute) { + case EGL_CONFIG_ID: + if (!c->Config) + return _eglError(EGL_BAD_ATTRIBUTE, "eglQueryContext"); + *value = c->Config->ConfigID; + break; + case EGL_CONTEXT_CLIENT_VERSION: + *value = c->ClientVersion; + break; +#ifdef EGL_VERSION_1_2 + case EGL_CONTEXT_CLIENT_TYPE: + *value = c->ClientAPI; + break; + case EGL_RENDER_BUFFER: + *value = _eglQueryContextRenderBuffer(c); + break; +#endif /* EGL_VERSION_1_2 */ + default: + return _eglError(EGL_BAD_ATTRIBUTE, "eglQueryContext"); + } + + return EGL_TRUE; +} + + +/** + * Bind the context to the thread and return the previous context. + * + * Note that the context may be NULL. + */ +static _EGLContext * +_eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t) +{ + EGLint apiIndex; + _EGLContext *oldCtx; + + apiIndex = (ctx) ? + _eglConvertApiToIndex(ctx->ClientAPI) : t->CurrentAPIIndex; + + oldCtx = t->CurrentContexts[apiIndex]; + if (ctx != oldCtx) { + if (oldCtx) + oldCtx->Binding = NULL; + if (ctx) + ctx->Binding = t; + + t->CurrentContexts[apiIndex] = ctx; + } + + return oldCtx; +} + + +/** + * Return true if the given context and surfaces can be made current. + */ +static EGLBoolean +_eglCheckMakeCurrent(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + _EGLDisplay *dpy; + EGLint conflict_api; + EGLBoolean surfaceless; + + if (_eglIsCurrentThreadDummy()) + return _eglError(EGL_BAD_ALLOC, "eglMakeCurrent"); + + /* this is easy */ + if (!ctx) { + if (draw || read) + return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); + return EGL_TRUE; + } + + dpy = ctx->Resource.Display; + switch (_eglGetContextAPIBit(ctx)) { + case EGL_OPENGL_ES_BIT: + surfaceless = dpy->Extensions.KHR_surfaceless_gles1; + break; + case EGL_OPENGL_ES2_BIT: + surfaceless = dpy->Extensions.KHR_surfaceless_gles2; + break; + case EGL_OPENGL_BIT: + surfaceless = dpy->Extensions.KHR_surfaceless_opengl; + break; + default: + surfaceless = EGL_FALSE; + break; + } + + if (!surfaceless && (draw == NULL || read == NULL)) + return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); + + /* + * The spec says + * + * "If ctx is current to some other thread, or if either draw or read are + * bound to contexts in another thread, an EGL_BAD_ACCESS error is + * generated." + * + * and + * + * "at most one context may be bound to a particular surface at a given + * time" + */ + if (ctx->Binding && ctx->Binding != t) + return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); + if (draw && draw->CurrentContext && draw->CurrentContext != ctx) { + if (draw->CurrentContext->Binding != t || + draw->CurrentContext->ClientAPI != ctx->ClientAPI) + return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); + } + if (read && read->CurrentContext && read->CurrentContext != ctx) { + if (read->CurrentContext->Binding != t || + read->CurrentContext->ClientAPI != ctx->ClientAPI) + return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); + } + + /* simply require the configs to be equal */ + if ((draw && draw->Config != ctx->Config) || + (read && read->Config != ctx->Config)) + return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); + + switch (ctx->ClientAPI) { +#ifdef EGL_VERSION_1_4 + /* OpenGL and OpenGL ES are conflicting */ + case EGL_OPENGL_ES_API: + conflict_api = EGL_OPENGL_API; + break; + case EGL_OPENGL_API: + conflict_api = EGL_OPENGL_ES_API; + break; +#endif + default: + conflict_api = -1; + break; + } + + if (conflict_api >= 0 && _eglGetAPIContext(conflict_api)) + return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent"); + + return EGL_TRUE; +} + + +/** + * Bind the context to the current thread and given surfaces. Return the + * previous bound context and surfaces. The caller should unreference the + * returned context and surfaces. + * + * Making a second call with the resources returned by the first call + * unsurprisingly undoes the first call, except for the resouce reference + * counts. + */ +EGLBoolean +_eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read, + _EGLContext **old_ctx, + _EGLSurface **old_draw, _EGLSurface **old_read) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + _EGLContext *prev_ctx; + _EGLSurface *prev_draw, *prev_read; + + if (!_eglCheckMakeCurrent(ctx, draw, read)) + return EGL_FALSE; + + /* increment refcounts before binding */ + _eglGetContext(ctx); + _eglGetSurface(draw); + _eglGetSurface(read); + + /* bind the new context */ + prev_ctx = _eglBindContextToThread(ctx, t); + + /* break previous bindings */ + if (prev_ctx) { + prev_draw = prev_ctx->DrawSurface; + prev_read = prev_ctx->ReadSurface; + + if (prev_draw) + prev_draw->CurrentContext = NULL; + if (prev_read) + prev_read->CurrentContext = NULL; + + prev_ctx->DrawSurface = NULL; + prev_ctx->ReadSurface = NULL; + } + else { + prev_draw = prev_read = NULL; + } + + /* establish new bindings */ + if (ctx) { + if (draw) + draw->CurrentContext = ctx; + if (read) + read->CurrentContext = ctx; + + ctx->DrawSurface = draw; + ctx->ReadSurface = read; + } + + assert(old_ctx && old_draw && old_read); + *old_ctx = prev_ctx; + *old_draw = prev_draw; + *old_read = prev_read; + + return EGL_TRUE; +} diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h new file mode 100644 index 0000000..8cd0df1 --- /dev/null +++ b/src/egl/main/eglcontext.h @@ -0,0 +1,118 @@ +#ifndef EGLCONTEXT_INCLUDED +#define EGLCONTEXT_INCLUDED + + +#include "egltypedefs.h" +#include "egldisplay.h" + + +/** + * "Base" class for device driver contexts. + */ +struct _egl_context +{ + /* A context is a display resource */ + _EGLResource Resource; + + /* The bound status of the context */ + _EGLThreadInfo *Binding; + _EGLSurface *DrawSurface; + _EGLSurface *ReadSurface; + + _EGLConfig *Config; + + EGLint ClientAPI; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API, EGL_OPENVG_API */ + EGLint ClientVersion; /**< 1 = OpenGLES 1.x, 2 = OpenGLES 2.x */ + + /* The real render buffer when a window surface is bound */ + EGLint WindowRenderBuffer; +}; + + +PUBLIC EGLBoolean +_eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy, + _EGLConfig *config, const EGLint *attrib_list); + + +extern EGLBoolean +_eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value); + + +PUBLIC EGLBoolean +_eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read, + _EGLContext **old_ctx, + _EGLSurface **old_draw, _EGLSurface **old_read); + + +/** + * Increment reference count for the context. + */ +static INLINE _EGLContext * +_eglGetContext(_EGLContext *ctx) +{ + if (ctx) + _eglGetResource(&ctx->Resource); + return ctx; +} + + +/** + * Decrement reference count for the context. + */ +static INLINE EGLBoolean +_eglPutContext(_EGLContext *ctx) +{ + return (ctx) ? _eglPutResource(&ctx->Resource) : EGL_FALSE; +} + + +/** + * Link a context to its display and return the handle of the link. + * The handle can be passed to client directly. + */ +static INLINE EGLContext +_eglLinkContext(_EGLContext *ctx) +{ + _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT); + return (EGLContext) ctx; +} + + +/** + * Unlink a linked context from its display. + * Accessing an unlinked context should generate EGL_BAD_CONTEXT error. + */ +static INLINE void +_eglUnlinkContext(_EGLContext *ctx) +{ + _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT); +} + + +/** + * Lookup a handle to find the linked context. + * Return NULL if the handle has no corresponding linked context. + */ +static INLINE _EGLContext * +_eglLookupContext(EGLContext context, _EGLDisplay *dpy) +{ + _EGLContext *ctx = (_EGLContext *) context; + if (!dpy || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, dpy)) + ctx = NULL; + return ctx; +} + + +/** + * Return the handle of a linked context, or EGL_NO_CONTEXT. + */ +static INLINE EGLContext +_eglGetContextHandle(_EGLContext *ctx) +{ + _EGLResource *res = (_EGLResource *) ctx; + return (res && _eglIsResourceLinked(res)) ? + (EGLContext) ctx : EGL_NO_CONTEXT; +} + + +#endif /* EGLCONTEXT_INCLUDED */ diff --git a/src/egl/main/eglcurrent.c b/src/egl/main/eglcurrent.c new file mode 100644 index 0000000..cbca9ff --- /dev/null +++ b/src/egl/main/eglcurrent.c @@ -0,0 +1,304 @@ +#include +#include +#include "egllog.h" +#include "eglmutex.h" +#include "eglcurrent.h" +#include "eglglobals.h" + + +/* This should be kept in sync with _eglInitThreadInfo() */ +#define _EGL_THREAD_INFO_INITIALIZER \ + { EGL_SUCCESS, { NULL }, 0 } + +/* a fallback thread info to guarantee that every thread always has one */ +static _EGLThreadInfo dummy_thread = _EGL_THREAD_INFO_INITIALIZER; + + +#if PTHREADS +#include + +static _EGL_DECLARE_MUTEX(_egl_TSDMutex); +static EGLBoolean _egl_TSDInitialized; +static pthread_key_t _egl_TSD; +static void (*_egl_FreeTSD)(_EGLThreadInfo *); + +#ifdef GLX_USE_TLS +static __thread const _EGLThreadInfo *_egl_TLS + __attribute__ ((tls_model("initial-exec"))); +#endif + +static INLINE void _eglSetTSD(const _EGLThreadInfo *t) +{ + pthread_setspecific(_egl_TSD, (const void *) t); +#ifdef GLX_USE_TLS + _egl_TLS = t; +#endif +} + +static INLINE _EGLThreadInfo *_eglGetTSD(void) +{ +#ifdef GLX_USE_TLS + return (_EGLThreadInfo *) _egl_TLS; +#else + return (_EGLThreadInfo *) pthread_getspecific(_egl_TSD); +#endif +} + +static INLINE void _eglFiniTSD(void) +{ + _eglLockMutex(&_egl_TSDMutex); + if (_egl_TSDInitialized) { + _EGLThreadInfo *t = _eglGetTSD(); + + _egl_TSDInitialized = EGL_FALSE; + if (t && _egl_FreeTSD) + _egl_FreeTSD((void *) t); + pthread_key_delete(_egl_TSD); + } + _eglUnlockMutex(&_egl_TSDMutex); +} + +static INLINE EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *)) +{ + if (!_egl_TSDInitialized) { + _eglLockMutex(&_egl_TSDMutex); + + /* check again after acquiring lock */ + if (!_egl_TSDInitialized) { + if (pthread_key_create(&_egl_TSD, (void (*)(void *)) dtor) != 0) { + _eglUnlockMutex(&_egl_TSDMutex); + return EGL_FALSE; + } + _egl_FreeTSD = dtor; + _eglAddAtExitCall(_eglFiniTSD); + _egl_TSDInitialized = EGL_TRUE; + } + + _eglUnlockMutex(&_egl_TSDMutex); + } + + return EGL_TRUE; +} + +#else /* PTHREADS */ +static const _EGLThreadInfo *_egl_TSD; +static void (*_egl_FreeTSD)(_EGLThreadInfo *); + +static INLINE void _eglSetTSD(const _EGLThreadInfo *t) +{ + _egl_TSD = t; +} + +static INLINE _EGLThreadInfo *_eglGetTSD(void) +{ + return (_EGLThreadInfo *) _egl_TSD; +} + +static INLINE void _eglFiniTSD(void) +{ + if (_egl_FreeTSD && _egl_TSD) + _egl_FreeTSD((_EGLThreadInfo *) _egl_TSD); +} + +static INLINE EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *)) +{ + if (!_egl_FreeTSD && dtor) { + _egl_FreeTSD = dtor; + _eglAddAtExitCall(_eglFiniTSD); + } + return EGL_TRUE; +} + +#endif /* !PTHREADS */ + + +static void +_eglInitThreadInfo(_EGLThreadInfo *t) +{ + memset(t, 0, sizeof(*t)); + t->LastError = EGL_SUCCESS; + /* default, per EGL spec */ + t->CurrentAPIIndex = _eglConvertApiToIndex(EGL_OPENGL_ES_API); +} + + +/** + * Allocate and init a new _EGLThreadInfo object. + */ +static _EGLThreadInfo * +_eglCreateThreadInfo(void) +{ + _EGLThreadInfo *t = (_EGLThreadInfo *) calloc(1, sizeof(_EGLThreadInfo)); + if (t) + _eglInitThreadInfo(t); + else + t = &dummy_thread; + return t; +} + + +/** + * Delete/free a _EGLThreadInfo object. + */ +static void +_eglDestroyThreadInfo(_EGLThreadInfo *t) +{ + if (t != &dummy_thread) + free(t); +} + + +/** + * Make sure TSD is initialized and return current value. + */ +static INLINE _EGLThreadInfo * +_eglCheckedGetTSD(void) +{ + if (_eglInitTSD(&_eglDestroyThreadInfo) != EGL_TRUE) { + _eglLog(_EGL_FATAL, "failed to initialize \"current\" system"); + return NULL; + } + + return _eglGetTSD(); +} + + +/** + * Return the calling thread's thread info. + * If the calling thread nevers calls this function before, or if its thread + * info was destroyed, a new one is created. This function never returns NULL. + * In the case allocation fails, a dummy one is returned. See also + * _eglIsCurrentThreadDummy. + */ +_EGLThreadInfo * +_eglGetCurrentThread(void) +{ + _EGLThreadInfo *t = _eglCheckedGetTSD(); + if (!t) { + t = _eglCreateThreadInfo(); + _eglSetTSD(t); + } + + return t; +} + + +/** + * Destroy the calling thread's thread info. + */ +void +_eglDestroyCurrentThread(void) +{ + _EGLThreadInfo *t = _eglCheckedGetTSD(); + if (t) { + _eglDestroyThreadInfo(t); + _eglSetTSD(NULL); + } +} + + +/** + * Return true if the calling thread's thread info is dummy. + * A dummy thread info is shared by all threads and should not be modified. + * Functions like eglBindAPI or eglMakeCurrent should check for dummy-ness + * before updating the thread info. + */ +EGLBoolean +_eglIsCurrentThreadDummy(void) +{ + _EGLThreadInfo *t = _eglCheckedGetTSD(); + return (!t || t == &dummy_thread); +} + + +/** + * Return the currently bound context of the given API, or NULL. + */ +PUBLIC _EGLContext * +_eglGetAPIContext(EGLenum api) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + return t->CurrentContexts[_eglConvertApiToIndex(api)]; +} + + +/** + * Return the currently bound context of the current API, or NULL. + */ +_EGLContext * +_eglGetCurrentContext(void) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + return t->CurrentContexts[t->CurrentAPIIndex]; +} + + +/** + * Record EGL error code and return EGL_FALSE. + */ +EGLBoolean +_eglError(EGLint errCode, const char *msg) +{ + _EGLThreadInfo *t = _eglGetCurrentThread(); + + if (t == &dummy_thread) + return EGL_FALSE; + + t->LastError = errCode; + + if (errCode != EGL_SUCCESS) { + const char *s; + + switch (errCode) { + case EGL_BAD_ACCESS: + s = "EGL_BAD_ACCESS"; + break; + case EGL_BAD_ALLOC: + s = "EGL_BAD_ALLOC"; + break; + case EGL_BAD_ATTRIBUTE: + s = "EGL_BAD_ATTRIBUTE"; + break; + case EGL_BAD_CONFIG: + s = "EGL_BAD_CONFIG"; + break; + case EGL_BAD_CONTEXT: + s = "EGL_BAD_CONTEXT"; + break; + case EGL_BAD_CURRENT_SURFACE: + s = "EGL_BAD_CURRENT_SURFACE"; + break; + case EGL_BAD_DISPLAY: + s = "EGL_BAD_DISPLAY"; + break; + case EGL_BAD_MATCH: + s = "EGL_BAD_MATCH"; + break; + case EGL_BAD_NATIVE_PIXMAP: + s = "EGL_BAD_NATIVE_PIXMAP"; + break; + case EGL_BAD_NATIVE_WINDOW: + s = "EGL_BAD_NATIVE_WINDOW"; + break; + case EGL_BAD_PARAMETER: + s = "EGL_BAD_PARAMETER"; + break; + case EGL_BAD_SURFACE: + s = "EGL_BAD_SURFACE"; + break; +#ifdef EGL_MESA_screen_surface + case EGL_BAD_SCREEN_MESA: + s = "EGL_BAD_SCREEN_MESA"; + break; + case EGL_BAD_MODE_MESA: + s = "EGL_BAD_MODE_MESA"; + break; +#endif + default: + s = "other"; + } + _eglLog(_EGL_DEBUG, "EGL user error 0x%x (%s) in %s\n", errCode, s, msg); + } + + return EGL_FALSE; +} diff --git a/src/egl/main/eglcurrent.h b/src/egl/main/eglcurrent.h new file mode 100644 index 0000000..e5c94ce --- /dev/null +++ b/src/egl/main/eglcurrent.h @@ -0,0 +1,88 @@ +#ifndef EGLCURRENT_INCLUDED +#define EGLCURRENT_INCLUDED + + +#include "egltypedefs.h" + + +#define _EGL_API_ALL_BITS \ + (EGL_OPENGL_ES_BIT | \ + EGL_OPENVG_BIT | \ + EGL_OPENGL_ES2_BIT | \ + EGL_OPENGL_BIT) + + +#define _EGL_API_FIRST_API EGL_OPENGL_ES_API +#define _EGL_API_LAST_API EGL_OPENGL_API +#define _EGL_API_NUM_APIS (_EGL_API_LAST_API - _EGL_API_FIRST_API + 1) + + +/** + * Per-thread info + */ +struct _egl_thread_info +{ + EGLint LastError; + _EGLContext *CurrentContexts[_EGL_API_NUM_APIS]; + /* use index for fast access to current context */ + EGLint CurrentAPIIndex; +}; + + +/** + * Return true if a client API enum is recognized. + */ +static INLINE EGLBoolean +_eglIsApiValid(EGLenum api) +{ + return (api >= _EGL_API_FIRST_API && api <= _EGL_API_LAST_API); +} + + +/** + * Convert a client API enum to an index, for use by thread info. + * The client API enum is assumed to be valid. + */ +static INLINE EGLint +_eglConvertApiToIndex(EGLenum api) +{ + return api - _EGL_API_FIRST_API; +} + + +/** + * Convert an index, used by thread info, to a client API enum. + * The index is assumed to be valid. + */ +static INLINE EGLenum +_eglConvertApiFromIndex(EGLint idx) +{ + return _EGL_API_FIRST_API + idx; +} + + +PUBLIC _EGLThreadInfo * +_eglGetCurrentThread(void); + + +extern void +_eglDestroyCurrentThread(void); + + +extern EGLBoolean +_eglIsCurrentThreadDummy(void); + + +PUBLIC _EGLContext * +_eglGetAPIContext(EGLenum api); + + +PUBLIC _EGLContext * +_eglGetCurrentContext(void); + + +PUBLIC EGLBoolean +_eglError(EGLint errCode, const char *msg); + + +#endif /* EGLCURRENT_INCLUDED */ diff --git a/src/egl/main/egldefines.h b/src/egl/main/egldefines.h new file mode 100644 index 0000000..4ecd4c1 --- /dev/null +++ b/src/egl/main/egldefines.h @@ -0,0 +1,46 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + + +/** + * Internal EGL defines + */ + + +#ifndef EGLDEFINES_INCLUDED +#define EGLDEFINES_INCLUDED + + +#define _EGL_MAX_EXTENSIONS_LEN 1000 + +#define _EGL_VENDOR_STRING "Mesa Project" + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) + + +#endif /* EGLDEFINES_INCLUDED */ diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c new file mode 100644 index 0000000..565e44d --- /dev/null +++ b/src/egl/main/egldisplay.c @@ -0,0 +1,314 @@ +/** + * Functions related to EGLDisplay. + */ + +#include +#include +#include +#include "eglcontext.h" +#include "eglsurface.h" +#include "egldisplay.h" +#include "egldriver.h" +#include "eglglobals.h" +#include "eglmutex.h" +#include "egllog.h" + + +/** + * Return the native platform by parsing EGL_PLATFORM. + */ +static _EGLPlatformType +_eglGetNativePlatformFromEnv(void) +{ + /* map --with-egl-platforms names to platform types */ + static const struct { + _EGLPlatformType platform; + const char *name; + } egl_platforms[_EGL_NUM_PLATFORMS] = { + { _EGL_PLATFORM_WINDOWS, "gdi" }, + { _EGL_PLATFORM_X11, "x11" }, + { _EGL_PLATFORM_DRM, "drm" }, + { _EGL_PLATFORM_FBDEV, "fbdev" } + }; + _EGLPlatformType plat = _EGL_INVALID_PLATFORM; + const char *plat_name; + EGLint i; + + plat_name = getenv("EGL_PLATFORM"); + /* try deprecated env variable */ + if (!plat_name || !plat_name[0]) + plat_name = getenv("EGL_DISPLAY"); + if (!plat_name || !plat_name[0]) + return _EGL_INVALID_PLATFORM; + + for (i = 0; i < _EGL_NUM_PLATFORMS; i++) { + if (strcmp(egl_platforms[i].name, plat_name) == 0) { + plat = egl_platforms[i].platform; + break; + } + } + + return plat; +} + + +/** + * Return the native platform. It is the platform of the EGL native types. + */ +_EGLPlatformType +_eglGetNativePlatform(void) +{ + static _EGLPlatformType native_platform = _EGL_INVALID_PLATFORM; + + if (native_platform == _EGL_INVALID_PLATFORM) { + native_platform = _eglGetNativePlatformFromEnv(); + if (native_platform == _EGL_INVALID_PLATFORM) + native_platform = _EGL_NATIVE_PLATFORM; + } + + return native_platform; +} + + +/** + * Finish display management. + */ +void +_eglFiniDisplay(void) +{ + _EGLDisplay *dpyList, *dpy; + + /* atexit function is called with global mutex locked */ + dpyList = _eglGlobal.DisplayList; + while (dpyList) { + EGLint i; + + /* pop list head */ + dpy = dpyList; + dpyList = dpyList->Next; + + for (i = 0; i < _EGL_NUM_RESOURCES; i++) { + if (dpy->ResourceLists[i]) { + _eglLog(_EGL_DEBUG, "Display %p is destroyed with resources", dpy); + break; + } + } + + free(dpy); + } + _eglGlobal.DisplayList = NULL; +} + + +/** + * Find the display corresponding to the specified native display, or create a + * new one. + */ +_EGLDisplay * +_eglFindDisplay(_EGLPlatformType plat, void *plat_dpy) +{ + _EGLDisplay *dpy; + + if (plat == _EGL_INVALID_PLATFORM) + return NULL; + + _eglLockMutex(_eglGlobal.Mutex); + + /* search the display list first */ + dpy = _eglGlobal.DisplayList; + while (dpy) { + if (dpy->Platform == plat && dpy->PlatformDisplay == plat_dpy) + break; + dpy = dpy->Next; + } + + /* create a new display */ + if (!dpy) { + dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay)); + if (dpy) { + _eglInitMutex(&dpy->Mutex); + dpy->Platform = plat; + dpy->PlatformDisplay = plat_dpy; + + /* add to the display list */ + dpy->Next = _eglGlobal.DisplayList; + _eglGlobal.DisplayList = dpy; + } + } + + _eglUnlockMutex(_eglGlobal.Mutex); + + return dpy; +} + + +/** + * Destroy the contexts and surfaces that are linked to the display. + */ +void +_eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *display) +{ + _EGLResource *list; + + list = display->ResourceLists[_EGL_RESOURCE_CONTEXT]; + while (list) { + _EGLContext *ctx = (_EGLContext *) list; + list = list->Next; + + _eglUnlinkContext(ctx); + drv->API.DestroyContext(drv, display, ctx); + } + assert(!display->ResourceLists[_EGL_RESOURCE_CONTEXT]); + + list = display->ResourceLists[_EGL_RESOURCE_SURFACE]; + while (list) { + _EGLSurface *surf = (_EGLSurface *) list; + list = list->Next; + + _eglUnlinkSurface(surf); + drv->API.DestroySurface(drv, display, surf); + } + assert(!display->ResourceLists[_EGL_RESOURCE_SURFACE]); +} + + +/** + * Free all the data hanging of an _EGLDisplay object, but not + * the object itself. + */ +void +_eglCleanupDisplay(_EGLDisplay *disp) +{ + if (disp->Configs) { + _eglDestroyArray(disp->Configs, free); + disp->Configs = NULL; + } + + /* XXX incomplete */ +} + + +/** + * Return EGL_TRUE if the given handle is a valid handle to a display. + */ +EGLBoolean +_eglCheckDisplayHandle(EGLDisplay dpy) +{ + _EGLDisplay *cur; + + _eglLockMutex(_eglGlobal.Mutex); + cur = _eglGlobal.DisplayList; + while (cur) { + if (cur == (_EGLDisplay *) dpy) + break; + cur = cur->Next; + } + _eglUnlockMutex(_eglGlobal.Mutex); + return (cur != NULL); +} + + +/** + * Return EGL_TRUE if the given resource is valid. That is, the display does + * own the resource. + */ +EGLBoolean +_eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy) +{ + _EGLResource *list = dpy->ResourceLists[type]; + + if (!res) + return EGL_FALSE; + + while (list) { + if (res == (void *) list) { + assert(list->Display == dpy); + break; + } + list = list->Next; + } + + return (list != NULL); +} + + +/** + * Initialize a display resource. + */ +void +_eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *dpy) +{ + memset(res, 0, size); + res->Display = dpy; + res->RefCount = 1; +} + + +/** + * Increment reference count for the resource. + */ +void +_eglGetResource(_EGLResource *res) +{ + assert(res && res->RefCount > 0); + /* hopefully a resource is always manipulated with its display locked */ + res->RefCount++; +} + + +/** + * Decrement reference count for the resource. + */ +EGLBoolean +_eglPutResource(_EGLResource *res) +{ + assert(res && res->RefCount > 0); + res->RefCount--; + return (!res->RefCount); +} + + +/** + * Link a resource to its display. + */ +void +_eglLinkResource(_EGLResource *res, _EGLResourceType type) +{ + assert(res->Display); + + res->IsLinked = EGL_TRUE; + res->Next = res->Display->ResourceLists[type]; + res->Display->ResourceLists[type] = res; + _eglGetResource(res); +} + + +/** + * Unlink a linked resource from its display. + */ +void +_eglUnlinkResource(_EGLResource *res, _EGLResourceType type) +{ + _EGLResource *prev; + + prev = res->Display->ResourceLists[type]; + if (prev != res) { + while (prev) { + if (prev->Next == res) + break; + prev = prev->Next; + } + assert(prev); + prev->Next = res->Next; + } + else { + res->Display->ResourceLists[type] = res->Next; + } + + res->Next = NULL; + res->IsLinked = EGL_FALSE; + _eglPutResource(res); + + /* We always unlink before destroy. The driver still owns a reference */ + assert(res->RefCount); +} diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h new file mode 100644 index 0000000..bcba054 --- /dev/null +++ b/src/egl/main/egldisplay.h @@ -0,0 +1,195 @@ +#ifndef EGLDISPLAY_INCLUDED +#define EGLDISPLAY_INCLUDED + + +#include "egltypedefs.h" +#include "egldefines.h" +#include "eglmutex.h" +#include "eglarray.h" + + +enum _egl_platform_type { + _EGL_PLATFORM_WINDOWS, + _EGL_PLATFORM_X11, + _EGL_PLATFORM_DRM, + _EGL_PLATFORM_FBDEV, + + _EGL_NUM_PLATFORMS, + _EGL_INVALID_PLATFORM = -1 +}; +typedef enum _egl_platform_type _EGLPlatformType; + + +enum _egl_resource_type { + _EGL_RESOURCE_CONTEXT, + _EGL_RESOURCE_SURFACE, + _EGL_RESOURCE_IMAGE, + _EGL_RESOURCE_SYNC, + + _EGL_NUM_RESOURCES +}; +/* this cannot and need not go into egltypedefs.h */ +typedef enum _egl_resource_type _EGLResourceType; + + +/** + * A resource of a display. + */ +struct _egl_resource +{ + /* which display the resource belongs to */ + _EGLDisplay *Display; + EGLBoolean IsLinked; + EGLint RefCount; + + /* used to link resources of the same type */ + _EGLResource *Next; +}; + + +/** + * Optional EGL extensions info. + */ +struct _egl_extensions +{ + EGLBoolean MESA_screen_surface; + EGLBoolean MESA_copy_context; + EGLBoolean MESA_drm_display; + EGLBoolean MESA_drm_image; + + EGLBoolean KHR_image_base; + EGLBoolean KHR_image_pixmap; + EGLBoolean KHR_vg_parent_image; + EGLBoolean KHR_gl_texture_2D_image; + EGLBoolean KHR_gl_texture_cubemap_image; + EGLBoolean KHR_gl_texture_3D_image; + EGLBoolean KHR_gl_renderbuffer_image; + + EGLBoolean KHR_reusable_sync; + EGLBoolean KHR_fence_sync; + + EGLBoolean KHR_surfaceless_gles1; + EGLBoolean KHR_surfaceless_gles2; + EGLBoolean KHR_surfaceless_opengl; + + EGLBoolean NOK_swap_region; + EGLBoolean NOK_texture_from_pixmap; + + char String[_EGL_MAX_EXTENSIONS_LEN]; +}; + + +struct _egl_display +{ + /* used to link displays */ + _EGLDisplay *Next; + + _EGLMutex Mutex; + + _EGLPlatformType Platform; + void *PlatformDisplay; + + EGLBoolean Initialized; /**< True if the display is initialized */ + _EGLDriver *Driver; + void *DriverData; /* private to driver */ + + int APImajor, APIminor; /**< as returned by eglInitialize() */ + char Version[1000]; /**< initialized from APImajor/minor, DriverName */ + + /** Bitmask of supported APIs (EGL_xx_BIT) set by the driver during init */ + EGLint ClientAPIsMask; + char ClientAPIs[1000]; /**< updated by eglQueryString */ + + _EGLExtensions Extensions; + + _EGLArray *Screens; + _EGLArray *Configs; + + /* lists of resources */ + _EGLResource *ResourceLists[_EGL_NUM_RESOURCES]; +}; + + +extern _EGLPlatformType +_eglGetNativePlatform(void); + + +extern void +_eglFiniDisplay(void); + + +extern _EGLDisplay * +_eglFindDisplay(_EGLPlatformType plat, void *plat_dpy); + + +PUBLIC void +_eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *dpy); + + +PUBLIC void +_eglCleanupDisplay(_EGLDisplay *disp); + + +extern EGLBoolean +_eglCheckDisplayHandle(EGLDisplay dpy); + + +PUBLIC EGLBoolean +_eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy); + + +/** + * Lookup a handle to find the linked display. + * Return NULL if the handle has no corresponding linked display. + */ +static INLINE _EGLDisplay * +_eglLookupDisplay(EGLDisplay display) +{ + _EGLDisplay *dpy = (_EGLDisplay *) display; + if (!_eglCheckDisplayHandle(display)) + dpy = NULL; + return dpy; +} + + +/** + * Return the handle of a linked display, or EGL_NO_DISPLAY. + */ +static INLINE EGLDisplay +_eglGetDisplayHandle(_EGLDisplay *dpy) +{ + return (EGLDisplay) ((dpy) ? dpy : EGL_NO_DISPLAY); +} + + +extern void +_eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *dpy); + + +PUBLIC void +_eglGetResource(_EGLResource *res); + + +PUBLIC EGLBoolean +_eglPutResource(_EGLResource *res); + + +extern void +_eglLinkResource(_EGLResource *res, _EGLResourceType type); + + +extern void +_eglUnlinkResource(_EGLResource *res, _EGLResourceType type); + + +/** + * Return true if the resource is linked. + */ +static INLINE EGLBoolean +_eglIsResourceLinked(_EGLResource *res) +{ + return res->IsLinked; +} + + +#endif /* EGLDISPLAY_INCLUDED */ diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c new file mode 100644 index 0000000..ff0011c --- /dev/null +++ b/src/egl/main/egldriver.c @@ -0,0 +1,696 @@ +/** + * Functions for choosing and opening/loading device drivers. + */ + + +#include +#include +#include +#include + +#include "eglstring.h" +#include "egldefines.h" +#include "egldisplay.h" +#include "egldriver.h" +#include "egllog.h" +#include "eglmutex.h" + +#if defined(_EGL_OS_UNIX) +#include +#include +#include +#include +#endif + + +typedef struct _egl_module { + char *Path; + void *Handle; + _EGLDriver *Driver; +} _EGLModule; + +static _EGL_DECLARE_MUTEX(_eglModuleMutex); +static _EGLArray *_eglModules; + + +/** + * Wrappers for dlopen/dlclose() + */ +#if defined(_EGL_OS_WINDOWS) + + +typedef HMODULE lib_handle; + +static HMODULE +open_library(const char *filename) +{ + return LoadLibrary(filename); +} + +static void +close_library(HMODULE lib) +{ + FreeLibrary(lib); +} + + +static const char * +library_suffix(void) +{ + return ".dll"; +} + + +#elif defined(_EGL_OS_UNIX) + + +typedef void * lib_handle; + +static void * +open_library(const char *filename) +{ + return dlopen(filename, RTLD_LAZY); +} + +static void +close_library(void *lib) +{ + dlclose(lib); +} + + +static const char * +library_suffix(void) +{ + return ".so"; +} + + +#endif + + +/** + * Open the named driver and find its bootstrap function: _eglMain(). + */ +static _EGLMain_t +_eglOpenLibrary(const char *driverPath, lib_handle *handle) +{ + lib_handle lib; + _EGLMain_t mainFunc = NULL; + const char *error = "unknown error"; + + assert(driverPath); + + _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath); + lib = open_library(driverPath); + +#if defined(_EGL_OS_WINDOWS) + /* XXX untested */ + if (lib) + mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain"); +#elif defined(_EGL_OS_UNIX) + if (lib) { + union { + _EGLMain_t func; + void *ptr; + } tmp = { NULL }; + /* direct cast gives a warning when compiled with -pedantic */ + tmp.ptr = dlsym(lib, "_eglMain"); + mainFunc = tmp.func; + if (!mainFunc) + error = dlerror(); + } + else { + error = dlerror(); + } +#endif + + if (!lib) { + _eglLog(_EGL_WARNING, "Could not open driver %s (%s)", + driverPath, error); + if (!getenv("EGL_DRIVER")) + _eglLog(_EGL_WARNING, + "The driver can be overridden by setting EGL_DRIVER"); + return NULL; + } + + if (!mainFunc) { + _eglLog(_EGL_WARNING, "_eglMain not found in %s (%s)", + driverPath, error); + if (lib) + close_library(lib); + return NULL; + } + + *handle = lib; + return mainFunc; +} + + +/** + * Load a module and create the driver object. + */ +static EGLBoolean +_eglLoadModule(_EGLModule *mod) +{ + _EGLMain_t mainFunc; + lib_handle lib; + _EGLDriver *drv; + + mainFunc = _eglOpenLibrary(mod->Path, &lib); + if (!mainFunc) + return EGL_FALSE; + + drv = mainFunc(NULL); + if (!drv) { + if (lib) + close_library(lib); + return EGL_FALSE; + } + + if (!drv->Name) { + _eglLog(_EGL_WARNING, "Driver loaded from %s has no name", mod->Path); + drv->Name = "UNNAMED"; + } + + mod->Handle = (void *) lib; + mod->Driver = drv; + + return EGL_TRUE; +} + + +/** + * Unload a module. + */ +static void +_eglUnloadModule(_EGLModule *mod) +{ + /* destroy the driver */ + if (mod->Driver && mod->Driver->Unload) + mod->Driver->Unload(mod->Driver); + if (mod->Handle) + close_library(mod->Handle); + + mod->Driver = NULL; + mod->Handle = NULL; +} + + +/** + * Add a module to the module array. + */ +static _EGLModule * +_eglAddModule(const char *path) +{ + _EGLModule *mod; + EGLint i; + + if (!_eglModules) { + _eglModules = _eglCreateArray("Module", 8); + if (!_eglModules) + return NULL; + } + + /* find duplicates */ + for (i = 0; i < _eglModules->Size; i++) { + mod = _eglModules->Elements[i]; + if (strcmp(mod->Path, path) == 0) + return mod; + } + + /* allocate a new one */ + mod = calloc(1, sizeof(*mod)); + if (mod) { + mod->Path = _eglstrdup(path); + if (!mod->Path) { + free(mod); + mod = NULL; + } + } + if (mod) { + _eglAppendArray(_eglModules, (void *) mod); + _eglLog(_EGL_DEBUG, "added %s to module array", mod->Path); + } + + return mod; +} + + +/** + * Free a module. + */ +static void +_eglFreeModule(void *module) +{ + _EGLModule *mod = (_EGLModule *) module; + + _eglUnloadModule(mod); + free(mod->Path); + free(mod); +} + + +/** + * A loader function for use with _eglPreloadForEach. The loader data is the + * filename of the driver. This function stops on the first valid driver. + */ +static EGLBoolean +_eglLoaderFile(const char *dir, size_t len, void *loader_data) +{ + char path[1024]; + const char *filename = (const char *) loader_data; + size_t flen = strlen(filename); + + /* make a full path */ + if (len + flen + 2 > sizeof(path)) + return EGL_TRUE; + if (len) { + memcpy(path, dir, len); + path[len++] = '/'; + } + memcpy(path + len, filename, flen); + len += flen; + path[len] = '\0'; + + if (library_suffix()) { + const char *suffix = library_suffix(); + size_t slen = strlen(suffix); + const char *p; + EGLBoolean need_suffix; + + p = filename + flen - slen; + need_suffix = (p < filename || strcmp(p, suffix) != 0); + if (need_suffix) { + /* overflow */ + if (len + slen + 1 > sizeof(path)) + return EGL_TRUE; + strcpy(path + len, suffix); + } + } + +#if defined(_EGL_OS_UNIX) + /* check if the file exists */ + if (access(path, F_OK)) + return EGL_TRUE; +#endif + + _eglAddModule(path); + + return EGL_TRUE; +} + + +/** + * A loader function for use with _eglPreloadForEach. The loader data is the + * pattern (prefix) of the files to look for. + */ +static EGLBoolean +_eglLoaderPattern(const char *dir, size_t len, void *loader_data) +{ +#if defined(_EGL_OS_UNIX) + const char *prefix, *suffix; + size_t prefix_len, suffix_len; + DIR *dirp; + struct dirent *dirent; + char path[1024]; + + if (len + 2 > sizeof(path)) + return EGL_TRUE; + if (len) { + memcpy(path, dir, len); + path[len++] = '/'; + } + path[len] = '\0'; + + dirp = opendir(path); + if (!dirp) + return EGL_TRUE; + + prefix = (const char *) loader_data; + prefix_len = strlen(prefix); + suffix = library_suffix(); + suffix_len = (suffix) ? strlen(suffix) : 0; + + while ((dirent = readdir(dirp))) { + size_t dirent_len = strlen(dirent->d_name); + const char *p; + + /* match the prefix */ + if (strncmp(dirent->d_name, prefix, prefix_len) != 0) + continue; + /* match the suffix */ + if (suffix) { + p = dirent->d_name + dirent_len - suffix_len; + if (p < dirent->d_name || strcmp(p, suffix) != 0) + continue; + } + + /* make a full path and add it to the module array */ + if (len + dirent_len + 1 <= sizeof(path)) { + strcpy(path + len, dirent->d_name); + _eglAddModule(path); + } + } + + closedir(dirp); + + return EGL_TRUE; +#else /* _EGL_OS_UNIX */ + /* stop immediately */ + return EGL_FALSE; +#endif +} + + +/** + * Run the callback function on each driver directory. + * + * The process may end prematurely if the callback function returns false. + */ +static void +_eglPreloadForEach(const char *search_path, + EGLBoolean (*loader)(const char *, size_t, void *), + void *loader_data) +{ + const char *cur, *next; + size_t len; + + cur = search_path; + while (cur) { + next = strchr(cur, ':'); + len = (next) ? next - cur : strlen(cur); + + if (!loader(cur, len, loader_data)) + break; + + cur = (next) ? next + 1 : NULL; + } +} + + +/** + * Return a list of colon-separated driver directories. + */ +static const char * +_eglGetSearchPath(void) +{ + static char search_path[1024]; + +#if defined(_EGL_OS_UNIX) || defined(_EGL_OS_WINDOWS) + if (search_path[0] == '\0') { + char *buf = search_path; + size_t len = sizeof(search_path); + EGLBoolean use_env; + char dir_sep; + int ret; + +#if defined(_EGL_OS_UNIX) + use_env = (geteuid() == getuid() && getegid() == getgid()); + dir_sep = '/'; +#else + use_env = EGL_TRUE; + dir_sep = '\\'; +#endif + + if (use_env) { + char *p; + + /* extract the dirname from EGL_DRIVER */ + p = getenv("EGL_DRIVER"); + if (p && strchr(p, dir_sep)) { + ret = _eglsnprintf(buf, len, "%s", p); + if (ret > 0 && ret < len) { + p = strrchr(buf, dir_sep); + *p++ = ':'; + + len -= p - buf; + buf = p; + } + } + + /* append EGL_DRIVERS_PATH */ + p = getenv("EGL_DRIVERS_PATH"); + if (p) { + ret = _eglsnprintf(buf, len, "%s:", p); + if (ret > 0 && ret < len) { + buf += ret; + len -= ret; + } + } + } + else { + _eglLog(_EGL_DEBUG, + "ignore EGL_DRIVERS_PATH for setuid/setgid binaries"); + } + + ret = _eglsnprintf(buf, len, "%s", _EGL_DRIVER_SEARCH_DIR); + if (ret < 0 || ret >= len) + search_path[0] = '\0'; + + _eglLog(_EGL_DEBUG, "EGL search path is %s", search_path); + } +#endif /* defined(_EGL_OS_UNIX) || defined(_EGL_OS_WINDOWS) */ + + return search_path; +} + + +/** + * Add the user driver to the module array. + * + * The user driver is specified by EGL_DRIVER. + */ +static void +_eglAddUserDriver(void) +{ + const char *search_path = _eglGetSearchPath(); + char *env; + + env = getenv("EGL_DRIVER"); +#if defined(_EGL_OS_UNIX) + if (env && strchr(env, '/')) { + search_path = ""; + if ((geteuid() != getuid() || getegid() != getgid())) { + _eglLog(_EGL_DEBUG, + "ignore EGL_DRIVER for setuid/setgid binaries"); + env = NULL; + } + } +#endif /* _EGL_OS_UNIX */ + if (env) + _eglPreloadForEach(search_path, _eglLoaderFile, (void *) env); +} + + +/** + * Add default drivers to the module array. + */ +static void +_eglAddDefaultDrivers(void) +{ + const char *search_path = _eglGetSearchPath(); + EGLint i; +#if defined(_EGL_OS_WINDOWS) + const char *DefaultDriverNames[] = { + "egl_gallium" + }; +#elif defined(_EGL_OS_UNIX) + const char *DefaultDriverNames[] = { + "egl_gallium", + "egl_dri2", + "egl_glx" + }; +#endif + + for (i = 0; i < ARRAY_SIZE(DefaultDriverNames); i++) { + void *name = (void *) DefaultDriverNames[i]; + _eglPreloadForEach(search_path, _eglLoaderFile, name); + } +} + + +/** + * Add drivers to the module array. Drivers will be loaded as they are matched + * to displays. + */ +static EGLBoolean +_eglAddDrivers(void) +{ + if (_eglModules) + return EGL_TRUE; + + /* the order here decides the priorities of the drivers */ + _eglAddUserDriver(); + _eglAddDefaultDrivers(); + _eglPreloadForEach(_eglGetSearchPath(), _eglLoaderPattern, (void *) "egl_"); + + return (_eglModules != NULL); +} + + +/** + * Match a display to a driver. The display is initialized unless use_probe is + * true. + * + * The matching is done by finding the first driver that can initialize the + * display, or when use_probe is true, the driver with highest score. + */ +_EGLDriver * +_eglMatchDriver(_EGLDisplay *dpy, EGLBoolean use_probe) +{ + _EGLModule *mod; + _EGLDriver *best_drv = NULL; + EGLint best_score = 0; + EGLint major, minor, i; + + _eglLockMutex(&_eglModuleMutex); + + if (!_eglAddDrivers()) { + _eglUnlockMutex(&_eglModuleMutex); + return EGL_FALSE; + } + + /* match the loaded modules */ + for (i = 0; i < _eglModules->Size; i++) { + mod = (_EGLModule *) _eglModules->Elements[i]; + if (!mod->Driver) + break; + + if (use_probe) { + EGLint score = (mod->Driver->Probe) ? + mod->Driver->Probe(mod->Driver, dpy) : 1; + if (score > best_score) { + best_drv = mod->Driver; + best_score = score; + } + } + else { + if (mod->Driver->API.Initialize(mod->Driver, dpy, &major, &minor)) { + best_drv = mod->Driver; + best_score = 100; + } + } + /* perfect match */ + if (best_score >= 100) + break; + } + + /* load more modules */ + if (!best_drv) { + EGLint first_unloaded = i; + + while (i < _eglModules->Size) { + mod = (_EGLModule *) _eglModules->Elements[i]; + assert(!mod->Driver); + + if (!_eglLoadModule(mod)) { + /* remove invalid modules */ + _eglEraseArray(_eglModules, i, _eglFreeModule); + continue; + } + + if (use_probe) { + best_score = (mod->Driver->Probe) ? + mod->Driver->Probe(mod->Driver, dpy) : 1; + } + else { + if (mod->Driver->API.Initialize(mod->Driver, dpy, &major, &minor)) + best_score = 100; + } + + if (best_score > 0) { + best_drv = mod->Driver; + /* loaded modules come before unloaded ones */ + if (first_unloaded != i) { + void *tmp = _eglModules->Elements[i]; + _eglModules->Elements[i] = + _eglModules->Elements[first_unloaded]; + _eglModules->Elements[first_unloaded] = tmp; + } + break; + } + else { + _eglUnloadModule(mod); + i++; + } + } + } + + _eglUnlockMutex(&_eglModuleMutex); + + if (best_drv) { + _eglLog(_EGL_DEBUG, "the best driver is %s (score %d)", + best_drv->Name, best_score); + if (!use_probe) { + dpy->Driver = best_drv; + dpy->Initialized = EGL_TRUE; + dpy->APImajor = major; + dpy->APIminor = minor; + } + } + + return best_drv; +} + + +__eglMustCastToProperFunctionPointerType +_eglGetDriverProc(const char *procname) +{ + EGLint i; + _EGLProc proc = NULL; + + if (!_eglModules) { + /* load the driver for the default display */ + EGLDisplay egldpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); + _EGLDisplay *dpy = _eglLookupDisplay(egldpy); + if (!dpy || !_eglMatchDriver(dpy, EGL_TRUE)) + return NULL; + } + + for (i = 0; i < _eglModules->Size; i++) { + _EGLModule *mod = (_EGLModule *) _eglModules->Elements[i]; + + if (!mod->Driver) + break; + proc = mod->Driver->API.GetProcAddress(mod->Driver, procname); + if (proc) + break; + } + + return proc; +} + + +/** + * Unload all drivers. + */ +void +_eglUnloadDrivers(void) +{ + /* this is called at atexit time */ + if (_eglModules) { +#if defined(_EGL_OS_UNIX) + _eglDestroyArray(_eglModules, _eglFreeModule); +#elif defined(_EGL_OS_WINDOWS) + /* XXX Windows unloads DLLs before atexit */ + _eglDestroyArray(_eglModules, NULL); +#endif + _eglModules = NULL; + } +} + + +/** + * Invoke a callback function on each EGL search path. + * + * The first argument of the callback function is the name of the search path. + * The second argument is the length of the name. + */ +void +_eglSearchPathForEach(EGLBoolean (*callback)(const char *, size_t, void *), + void *callback_data) +{ + const char *search_path = _eglGetSearchPath(); + _eglPreloadForEach(search_path, callback, callback_data); +} diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h new file mode 100644 index 0000000..1a0aaad --- /dev/null +++ b/src/egl/main/egldriver.h @@ -0,0 +1,93 @@ +#ifndef EGLDRIVER_INCLUDED +#define EGLDRIVER_INCLUDED + + +#include "egltypedefs.h" +#include "eglapi.h" +#include + +/** + * Define an inline driver typecast function. + * + * Note that this macro defines a function and should not be ended with a + * semicolon when used. + */ +#define _EGL_DRIVER_TYPECAST(drvtype, egltype, code) \ + static INLINE struct drvtype *drvtype(const egltype *obj) \ + { return (struct drvtype *) code; } + + +/** + * Define the driver typecast functions for _EGLDriver, _EGLDisplay, + * _EGLContext, _EGLSurface, and _EGLConfig. + * + * Note that this macro defines several functions and should not be ended with + * a semicolon when used. + */ +#define _EGL_DRIVER_STANDARD_TYPECASTS(drvname) \ + _EGL_DRIVER_TYPECAST(drvname ## _driver, _EGLDriver, obj) \ + /* note that this is not a direct cast */ \ + _EGL_DRIVER_TYPECAST(drvname ## _display, _EGLDisplay, obj->DriverData) \ + _EGL_DRIVER_TYPECAST(drvname ## _context, _EGLContext, obj) \ + _EGL_DRIVER_TYPECAST(drvname ## _surface, _EGLSurface, obj) \ + _EGL_DRIVER_TYPECAST(drvname ## _config, _EGLConfig, obj) + + +typedef _EGLDriver *(*_EGLMain_t)(const char *args); + + +/** + * Base class for device drivers. + */ +struct _egl_driver +{ + const char *Name; /**< name of this driver */ + + /** + * Probe a display and return a score. + * + * Roughly, + * 50 means the driver supports the display; + * 90 means the driver can accelerate the display; + * 100 means a perfect match. + */ + EGLint (*Probe)(_EGLDriver *drv, _EGLDisplay *dpy); + + /** + * Release the driver resource. + * + * It is called before dlclose(). + */ + void (*Unload)(_EGLDriver *drv); + + _EGLAPI API; /**< EGL API dispatch table */ +}; + + +PUBLIC _EGLDriver * +_eglMain(const char *args); + + +extern _EGLDriver * +_eglMatchDriver(_EGLDisplay *dpy, EGLBoolean probe_only); + + +extern __eglMustCastToProperFunctionPointerType +_eglGetDriverProc(const char *procname); + + +extern void +_eglUnloadDrivers(void); + + +/* defined in eglfallbacks.c */ +PUBLIC void +_eglInitDriverFallbacks(_EGLDriver *drv); + + +PUBLIC void +_eglSearchPathForEach(EGLBoolean (*callback)(const char *, size_t, void *), + void *callback_data); + + +#endif /* EGLDRIVER_INCLUDED */ diff --git a/src/egl/main/eglfallbacks.c b/src/egl/main/eglfallbacks.c new file mode 100644 index 0000000..7c93adb --- /dev/null +++ b/src/egl/main/eglfallbacks.c @@ -0,0 +1,99 @@ +#include +#include "egltypedefs.h" +#include "egldriver.h" +#include "eglconfig.h" +#include "eglcontext.h" +#include "eglsurface.h" +#include "eglmisc.h" +#include "eglscreen.h" +#include "eglmode.h" +#include "eglsync.h" + + +static EGLBoolean +_eglReturnFalse(void) +{ + return EGL_FALSE; +} + + +/** + * Plug all the available fallback routines into the given driver's + * dispatch table. + */ +void +_eglInitDriverFallbacks(_EGLDriver *drv) +{ + memset(&drv->API, 0, sizeof(drv->API)); + + /* the driver has to implement these */ + drv->API.Initialize = NULL; + drv->API.Terminate = NULL; + + drv->API.GetConfigs = _eglGetConfigs; + drv->API.ChooseConfig = _eglChooseConfig; + drv->API.GetConfigAttrib = _eglGetConfigAttrib; + + drv->API.CreateContext = (CreateContext_t) _eglReturnFalse; + drv->API.DestroyContext = (DestroyContext_t) _eglReturnFalse; + drv->API.MakeCurrent = (MakeCurrent_t) _eglReturnFalse; + drv->API.QueryContext = _eglQueryContext; + + drv->API.CreateWindowSurface = (CreateWindowSurface_t) _eglReturnFalse; + drv->API.CreatePixmapSurface = (CreatePixmapSurface_t) _eglReturnFalse; + drv->API.CreatePbufferSurface = (CreatePbufferSurface_t) _eglReturnFalse; + drv->API.CreatePbufferFromClientBuffer = + (CreatePbufferFromClientBuffer_t) _eglReturnFalse; + drv->API.DestroySurface = (DestroySurface_t) _eglReturnFalse; + drv->API.QuerySurface = _eglQuerySurface; + drv->API.SurfaceAttrib = _eglSurfaceAttrib; + + drv->API.BindTexImage = (BindTexImage_t) _eglReturnFalse; + drv->API.ReleaseTexImage = (ReleaseTexImage_t) _eglReturnFalse; + drv->API.CopyBuffers = (CopyBuffers_t) _eglReturnFalse; + drv->API.SwapBuffers = (SwapBuffers_t) _eglReturnFalse; + drv->API.SwapInterval = _eglSwapInterval; + + drv->API.WaitClient = (WaitClient_t) _eglReturnFalse; + drv->API.WaitNative = (WaitNative_t) _eglReturnFalse; + drv->API.GetProcAddress = (GetProcAddress_t) _eglReturnFalse; + drv->API.QueryString = _eglQueryString; + +#ifdef EGL_MESA_screen_surface + drv->API.CopyContextMESA = (CopyContextMESA_t) _eglReturnFalse; + drv->API.CreateScreenSurfaceMESA = + (CreateScreenSurfaceMESA_t) _eglReturnFalse; + drv->API.ShowScreenSurfaceMESA = (ShowScreenSurfaceMESA_t) _eglReturnFalse; + drv->API.ChooseModeMESA = _eglChooseModeMESA; + drv->API.GetModesMESA = _eglGetModesMESA; + drv->API.GetModeAttribMESA = _eglGetModeAttribMESA; + drv->API.GetScreensMESA = _eglGetScreensMESA; + drv->API.ScreenPositionMESA = _eglScreenPositionMESA; + drv->API.QueryScreenMESA = _eglQueryScreenMESA; + drv->API.QueryScreenSurfaceMESA = _eglQueryScreenSurfaceMESA; + drv->API.QueryScreenModeMESA = _eglQueryScreenModeMESA; + drv->API.QueryModeStringMESA = _eglQueryModeStringMESA; +#endif /* EGL_MESA_screen_surface */ + +#ifdef EGL_KHR_image_base + drv->API.CreateImageKHR = NULL; + drv->API.DestroyImageKHR = NULL; +#endif /* EGL_KHR_image_base */ + +#ifdef EGL_KHR_reusable_sync + drv->API.CreateSyncKHR = NULL; + drv->API.DestroySyncKHR = NULL; + drv->API.ClientWaitSyncKHR = NULL; + drv->API.SignalSyncKHR = NULL; + drv->API.GetSyncAttribKHR = _eglGetSyncAttribKHR; +#endif /* EGL_KHR_reusable_sync */ + +#ifdef EGL_MESA_drm_image + drv->API.CreateDRMImageMESA = NULL; + drv->API.ExportDRMImageMESA = NULL; +#endif + +#ifdef EGL_NOK_swap_region + drv->API.SwapBuffersRegionNOK = NULL; +#endif +} diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c new file mode 100644 index 0000000..52eebb0 --- /dev/null +++ b/src/egl/main/eglglobals.c @@ -0,0 +1,50 @@ +#include +#include +#include "eglglobals.h" +#include "egldisplay.h" +#include "egldriver.h" +#include "eglmutex.h" + + +static _EGL_DECLARE_MUTEX(_eglGlobalMutex); +struct _egl_global _eglGlobal = +{ + &_eglGlobalMutex, /* Mutex */ + NULL, /* DisplayList */ + 2, /* NumAtExitCalls */ + { + /* default AtExitCalls, called in reverse order */ + _eglUnloadDrivers, /* always called last */ + _eglFiniDisplay + }, +}; + + +static void +_eglAtExit(void) +{ + EGLint i; + for (i = _eglGlobal.NumAtExitCalls - 1; i >= 0; i--) + _eglGlobal.AtExitCalls[i](); +} + + +void +_eglAddAtExitCall(void (*func)(void)) +{ + if (func) { + static EGLBoolean registered = EGL_FALSE; + + _eglLockMutex(_eglGlobal.Mutex); + + if (!registered) { + atexit(_eglAtExit); + registered = EGL_TRUE; + } + + assert(_eglGlobal.NumAtExitCalls < ARRAY_SIZE(_eglGlobal.AtExitCalls)); + _eglGlobal.AtExitCalls[_eglGlobal.NumAtExitCalls++] = func; + + _eglUnlockMutex(_eglGlobal.Mutex); + } +} diff --git a/src/egl/main/eglglobals.h b/src/egl/main/eglglobals.h new file mode 100644 index 0000000..c3771a8 --- /dev/null +++ b/src/egl/main/eglglobals.h @@ -0,0 +1,31 @@ +#ifndef EGLGLOBALS_INCLUDED +#define EGLGLOBALS_INCLUDED + + +#include "egltypedefs.h" +#include "eglmutex.h" + + +/** + * Global library data + */ +struct _egl_global +{ + _EGLMutex *Mutex; + + /* the list of all displays */ + _EGLDisplay *DisplayList; + + EGLint NumAtExitCalls; + void (*AtExitCalls[10])(void); +}; + + +extern struct _egl_global _eglGlobal; + + +extern void +_eglAddAtExitCall(void (*func)(void)); + + +#endif /* EGLGLOBALS_INCLUDED */ diff --git a/src/egl/main/eglimage.c b/src/egl/main/eglimage.c new file mode 100644 index 0000000..6d4ee4e --- /dev/null +++ b/src/egl/main/eglimage.c @@ -0,0 +1,89 @@ +#include +#include + +#include "eglimage.h" +#include "egllog.h" + + +#ifdef EGL_KHR_image_base + + +/** + * Parse the list of image attributes and return the proper error code. + */ +EGLint +_eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *dpy, + const EGLint *attrib_list) +{ + EGLint i, err = EGL_SUCCESS; + + (void) dpy; + + memset(attrs, 0, sizeof(attrs)); + attrs->ImagePreserved = EGL_FALSE; + attrs->GLTextureLevel = 0; + attrs->GLTextureZOffset = 0; + + if (!attrib_list) + return err; + + for (i = 0; attrib_list[i] != EGL_NONE; i++) { + EGLint attr = attrib_list[i++]; + EGLint val = attrib_list[i]; + + switch (attr) { + /* EGL_KHR_image_base */ + case EGL_IMAGE_PRESERVED_KHR: + attrs->ImagePreserved = val; + break; + + /* EGL_KHR_gl_image */ + case EGL_GL_TEXTURE_LEVEL_KHR: + attrs->GLTextureLevel = val; + break; + case EGL_GL_TEXTURE_ZOFFSET_KHR: + attrs->GLTextureZOffset = val; + break; + + /* EGL_MESA_drm_image */ + case EGL_WIDTH: + attrs->Width = val; + break; + case EGL_HEIGHT: + attrs->Height = val; + break; + case EGL_DRM_BUFFER_FORMAT_MESA: + attrs->DRMBufferFormatMESA = val; + break; + case EGL_DRM_BUFFER_USE_MESA: + attrs->DRMBufferUseMESA = val; + break; + case EGL_DRM_BUFFER_STRIDE_MESA: + attrs->DRMBufferStrideMESA = val; + break; + + default: + /* unknown attrs are ignored */ + break; + } + + if (err != EGL_SUCCESS) { + _eglLog(_EGL_DEBUG, "bad image attribute 0x%04x", attr); + break; + } + } + + return err; +} + + +EGLBoolean +_eglInitImage(_EGLImage *img, _EGLDisplay *dpy) +{ + _eglInitResource(&img->Resource, sizeof(*img), dpy); + + return EGL_TRUE; +} + + +#endif /* EGL_KHR_image_base */ diff --git a/src/egl/main/eglimage.h b/src/egl/main/eglimage.h new file mode 100644 index 0000000..adb939a --- /dev/null +++ b/src/egl/main/eglimage.h @@ -0,0 +1,116 @@ +#ifndef EGLIMAGE_INCLUDED +#define EGLIMAGE_INCLUDED + + +#include "egltypedefs.h" +#include "egldisplay.h" + + +struct _egl_image_attribs +{ + /* EGL_KHR_image_base */ + EGLBoolean ImagePreserved; + + /* EGL_KHR_gl_image */ + EGLint GLTextureLevel; + EGLint GLTextureZOffset; + + /* EGL_MESA_drm_image */ + EGLint Width; + EGLint Height; + EGLint DRMBufferFormatMESA; + EGLint DRMBufferUseMESA; + EGLint DRMBufferStrideMESA; +}; + +/** + * "Base" class for device driver images. + */ +struct _egl_image +{ + /* An image is a display resource */ + _EGLResource Resource; +}; + + +PUBLIC EGLint +_eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *dpy, + const EGLint *attrib_list); + + +PUBLIC EGLBoolean +_eglInitImage(_EGLImage *img, _EGLDisplay *dpy); + + +/** + * Increment reference count for the image. + */ +static INLINE _EGLImage * +_eglGetImage(_EGLImage *img) +{ + if (img) + _eglGetResource(&img->Resource); + return img; +} + + +/** + * Decrement reference count for the image. + */ +static INLINE EGLBoolean +_eglPutImage(_EGLImage *img) +{ + return (img) ? _eglPutResource(&img->Resource) : EGL_FALSE; +} + + +/** + * Link an image to its display and return the handle of the link. + * The handle can be passed to client directly. + */ +static INLINE EGLImageKHR +_eglLinkImage(_EGLImage *img) +{ + _eglLinkResource(&img->Resource, _EGL_RESOURCE_IMAGE); + return (EGLImageKHR) img; +} + + +/** + * Unlink a linked image from its display. + * Accessing an unlinked image should generate EGL_BAD_PARAMETER error. + */ +static INLINE void +_eglUnlinkImage(_EGLImage *img) +{ + _eglUnlinkResource(&img->Resource, _EGL_RESOURCE_IMAGE); +} + + +/** + * Lookup a handle to find the linked image. + * Return NULL if the handle has no corresponding linked image. + */ +static INLINE _EGLImage * +_eglLookupImage(EGLImageKHR image, _EGLDisplay *dpy) +{ + _EGLImage *img = (_EGLImage *) image; + if (!dpy || !_eglCheckResource((void *) img, _EGL_RESOURCE_IMAGE, dpy)) + img = NULL; + return img; +} + + +/** + * Return the handle of a linked image, or EGL_NO_IMAGE_KHR. + */ +static INLINE EGLImageKHR +_eglGetImageHandle(_EGLImage *img) +{ + _EGLResource *res = (_EGLResource *) img; + return (res && _eglIsResourceLinked(res)) ? + (EGLImageKHR) img : EGL_NO_IMAGE_KHR; +} + + +#endif /* EGLIMAGE_INCLUDED */ diff --git a/src/egl/main/egllog.c b/src/egl/main/egllog.c new file mode 100644 index 0000000..12c55f9 --- /dev/null +++ b/src/egl/main/egllog.c @@ -0,0 +1,179 @@ +/** + * Logging facility for debug/info messages. + * _EGL_FATAL messages are printed to stderr + * The EGL_LOG_LEVEL var controls the output of other warning/info/debug msgs. + */ + + +#include +#include +#include +#include + +#include "egllog.h" +#include "eglstring.h" +#include "eglmutex.h" + +#define MAXSTRING 1000 +#define FALLBACK_LOG_LEVEL _EGL_WARNING + + +static struct { + _EGLMutex mutex; + + EGLBoolean initialized; + EGLint level; + _EGLLogProc logger; + EGLint num_messages; +} logging = { + _EGL_MUTEX_INITIALIZER, + EGL_FALSE, + FALLBACK_LOG_LEVEL, + NULL, + 0 +}; + +static const char *level_strings[] = { + /* the order is important */ + "fatal", + "warning", + "info", + "debug", + NULL +}; + + +/** + * Set the function to be called when there is a message to log. + * Note that the function will be called with an internal lock held. + * Recursive logging is not allowed. + */ +void +_eglSetLogProc(_EGLLogProc logger) +{ + EGLint num_messages = 0; + + _eglLockMutex(&logging.mutex); + + if (logging.logger != logger) { + logging.logger = logger; + + num_messages = logging.num_messages; + logging.num_messages = 0; + } + + _eglUnlockMutex(&logging.mutex); + + if (num_messages) + _eglLog(_EGL_DEBUG, + "New logger installed. " + "Messages before the new logger might not be available."); +} + + +/** + * Set the log reporting level. + */ +void +_eglSetLogLevel(EGLint level) +{ + switch (level) { + case _EGL_FATAL: + case _EGL_WARNING: + case _EGL_INFO: + case _EGL_DEBUG: + _eglLockMutex(&logging.mutex); + logging.level = level; + _eglUnlockMutex(&logging.mutex); + break; + default: + break; + } +} + + +/** + * The default logger. It prints the message to stderr. + */ +static void +_eglDefaultLogger(EGLint level, const char *msg) +{ + fprintf(stderr, "libEGL %s: %s\n", level_strings[level], msg); +} + + +/** + * Initialize the logging facility. + */ +static void +_eglInitLogger(void) +{ + const char *log_env; + EGLint i, level = -1; + + if (logging.initialized) + return; + + log_env = getenv("EGL_LOG_LEVEL"); + if (log_env) { + for (i = 0; level_strings[i]; i++) { + if (_eglstrcasecmp(log_env, level_strings[i]) == 0) { + level = i; + break; + } + } + } + else { + level = FALLBACK_LOG_LEVEL; + } + + logging.logger = _eglDefaultLogger; + logging.level = (level >= 0) ? level : FALLBACK_LOG_LEVEL; + logging.initialized = EGL_TRUE; + + /* it is fine to call _eglLog now */ + if (log_env && level < 0) { + _eglLog(_EGL_WARNING, + "Unrecognized EGL_LOG_LEVEL environment variable value. " + "Expected one of \"fatal\", \"warning\", \"info\", \"debug\". " + "Got \"%s\". Falling back to \"%s\".", + log_env, level_strings[FALLBACK_LOG_LEVEL]); + } +} + + +/** + * Log a message with message logger. + * \param level one of _EGL_FATAL, _EGL_WARNING, _EGL_INFO, _EGL_DEBUG. + */ +void +_eglLog(EGLint level, const char *fmtStr, ...) +{ + va_list args; + char msg[MAXSTRING]; + int ret; + + /* one-time initialization; a little race here is fine */ + if (!logging.initialized) + _eglInitLogger(); + if (level > logging.level || level < 0) + return; + + _eglLockMutex(&logging.mutex); + + if (logging.logger) { + va_start(args, fmtStr); + ret = vsnprintf(msg, MAXSTRING, fmtStr, args); + if (ret < 0 || ret >= MAXSTRING) + strcpy(msg, ""); + va_end(args); + + logging.logger(level, msg); + logging.num_messages++; + } + + _eglUnlockMutex(&logging.mutex); + + if (level == _EGL_FATAL) + exit(1); /* or abort()? */ +} diff --git a/src/egl/main/egllog.h b/src/egl/main/egllog.h new file mode 100644 index 0000000..03bef26 --- /dev/null +++ b/src/egl/main/egllog.h @@ -0,0 +1,29 @@ +#ifndef EGLLOG_INCLUDED +#define EGLLOG_INCLUDED + + +#include "egltypedefs.h" + + +#define _EGL_FATAL 0 /* unrecoverable error */ +#define _EGL_WARNING 1 /* recoverable error/problem */ +#define _EGL_INFO 2 /* just useful info */ +#define _EGL_DEBUG 3 /* useful info for debugging */ + + +typedef void (*_EGLLogProc)(EGLint level, const char *msg); + + +PUBLIC void +_eglSetLogProc(_EGLLogProc logger); + + +PUBLIC void +_eglSetLogLevel(EGLint level); + + +PUBLIC void +_eglLog(EGLint level, const char *fmtStr, ...); + + +#endif /* EGLLOG_INCLUDED */ diff --git a/src/egl/main/eglmisc.c b/src/egl/main/eglmisc.c new file mode 100644 index 0000000..bbb96a9 --- /dev/null +++ b/src/egl/main/eglmisc.c @@ -0,0 +1,160 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * Small/misc EGL functions + */ + + +#include +#include +#include "eglcurrent.h" +#include "eglmisc.h" +#include "egldisplay.h" + + +/** + * Copy the extension into the string and update the string pointer. + */ +static EGLint +_eglAppendExtension(char **str, const char *ext) +{ + char *s = *str; + size_t len = strlen(ext); + + if (s) { + memcpy(s, ext, len); + s[len++] = ' '; + s[len] = '\0'; + + *str += len; + } + else { + len++; + } + + return (EGLint) len; +} + + +/** + * Examine the individual extension enable/disable flags and recompute + * the driver's Extensions string. + */ +static void +_eglUpdateExtensionsString(_EGLDisplay *dpy) +{ +#define _EGL_CHECK_EXTENSION(ext) \ + do { \ + if (dpy->Extensions.ext) { \ + _eglAppendExtension(&exts, "EGL_" #ext); \ + assert(exts <= dpy->Extensions.String + _EGL_MAX_EXTENSIONS_LEN); \ + } \ + } while (0) + + char *exts = dpy->Extensions.String; + + if (exts[0]) + return; + + _EGL_CHECK_EXTENSION(MESA_screen_surface); + _EGL_CHECK_EXTENSION(MESA_copy_context); + _EGL_CHECK_EXTENSION(MESA_drm_display); + _EGL_CHECK_EXTENSION(MESA_drm_image); + + _EGL_CHECK_EXTENSION(KHR_image_base); + _EGL_CHECK_EXTENSION(KHR_image_pixmap); + if (dpy->Extensions.KHR_image_base && dpy->Extensions.KHR_image_pixmap) + _eglAppendExtension(&exts, "EGL_KHR_image"); + + _EGL_CHECK_EXTENSION(KHR_vg_parent_image); + _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image); + _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image); + _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image); + _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image); + + _EGL_CHECK_EXTENSION(KHR_reusable_sync); + _EGL_CHECK_EXTENSION(KHR_fence_sync); + + _EGL_CHECK_EXTENSION(KHR_surfaceless_gles1); + _EGL_CHECK_EXTENSION(KHR_surfaceless_gles2); + _EGL_CHECK_EXTENSION(KHR_surfaceless_opengl); + + _EGL_CHECK_EXTENSION(NOK_swap_region); + _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap); +#undef _EGL_CHECK_EXTENSION +} + + +static void +_eglUpdateAPIsString(_EGLDisplay *dpy) +{ + char *apis = dpy->ClientAPIs; + + if (apis[0] || !dpy->ClientAPIsMask) + return; + + if (dpy->ClientAPIsMask & EGL_OPENGL_BIT) + strcat(apis, "OpenGL "); + + if (dpy->ClientAPIsMask & EGL_OPENGL_ES_BIT) + strcat(apis, "OpenGL_ES "); + + if (dpy->ClientAPIsMask & EGL_OPENGL_ES2_BIT) + strcat(apis, "OpenGL_ES2 "); + + if (dpy->ClientAPIsMask & EGL_OPENVG_BIT) + strcat(apis, "OpenVG "); + + assert(strlen(apis) < sizeof(dpy->ClientAPIs)); +} + + +const char * +_eglQueryString(_EGLDriver *drv, _EGLDisplay *dpy, EGLint name) +{ + (void) drv; + (void) dpy; + switch (name) { + case EGL_VENDOR: + return _EGL_VENDOR_STRING; + case EGL_VERSION: + return dpy->Version; + case EGL_EXTENSIONS: + _eglUpdateExtensionsString(dpy); + return dpy->Extensions.String; +#ifdef EGL_VERSION_1_2 + case EGL_CLIENT_APIS: + _eglUpdateAPIsString(dpy); + return dpy->ClientAPIs; +#endif + default: + _eglError(EGL_BAD_PARAMETER, "eglQueryString"); + return NULL; + } +} diff --git a/src/egl/main/eglmisc.h b/src/egl/main/eglmisc.h new file mode 100644 index 0000000..a753307 --- /dev/null +++ b/src/egl/main/eglmisc.h @@ -0,0 +1,40 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef EGLMISC_INCLUDED +#define EGLMISC_INCLUDED + + +#include "egltypedefs.h" + + +extern const char * +_eglQueryString(_EGLDriver *drv, _EGLDisplay *dpy, EGLint name); + + +#endif /* EGLMISC_INCLUDED */ diff --git a/src/egl/main/eglmode.c b/src/egl/main/eglmode.c new file mode 100644 index 0000000..a965349 --- /dev/null +++ b/src/egl/main/eglmode.c @@ -0,0 +1,327 @@ +#include +#include +#include + +#include "egldisplay.h" +#include "eglmode.h" +#include "eglcurrent.h" +#include "eglscreen.h" + + +#ifdef EGL_MESA_screen_surface + + +#define MIN2(A, B) (((A) < (B)) ? (A) : (B)) + + +/** + * Given an EGLModeMESA handle, return the corresponding _EGLMode object + * or null if non-existant. + */ +_EGLMode * +_eglLookupMode(EGLModeMESA mode, _EGLDisplay *disp) +{ + EGLint scrnum; + + if (!disp || !disp->Screens) + return NULL; + + /* loop over all screens on the display */ + for (scrnum = 0; scrnum < disp->Screens->Size; scrnum++) { + const _EGLScreen *scrn = disp->Screens->Elements[scrnum]; + EGLint idx; + + /* + * the mode ids of a screen ranges from scrn->Handle to scrn->Handle + + * scrn->NumModes + */ + if (mode >= scrn->Handle && + mode < scrn->Handle + _EGL_SCREEN_MAX_MODES) { + idx = mode - scrn->Handle; + + assert(idx < scrn->NumModes && scrn->Modes[idx].Handle == mode); + + return &scrn->Modes[idx]; + } + } + + return NULL; +} + + +/** + * Parse the attrib_list to fill in the fields of the given _eglMode + * Return EGL_FALSE if any errors, EGL_TRUE otherwise. + */ +static EGLBoolean +_eglParseModeAttribs(_EGLMode *mode, const EGLint *attrib_list) +{ + EGLint i; + + /* init all attribs to EGL_DONT_CARE */ + mode->Handle = EGL_DONT_CARE; + mode->Width = EGL_DONT_CARE; + mode->Height = EGL_DONT_CARE; + mode->RefreshRate = EGL_DONT_CARE; + mode->Optimal = EGL_DONT_CARE; + mode->Interlaced = EGL_DONT_CARE; + mode->Name = NULL; + + for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) { + switch (attrib_list[i]) { + case EGL_MODE_ID_MESA: + mode->Handle = attrib_list[++i]; + if (mode->Handle <= 0) { + _eglError(EGL_BAD_PARAMETER, "eglChooseModeMESA(handle)"); + return EGL_FALSE; + } + break; + case EGL_WIDTH: + mode->Width = attrib_list[++i]; + if (mode->Width <= 0) { + _eglError(EGL_BAD_PARAMETER, "eglChooseModeMESA(width)"); + return EGL_FALSE; + } + break; + case EGL_HEIGHT: + mode->Height = attrib_list[++i]; + if (mode->Height <= 0) { + _eglError(EGL_BAD_PARAMETER, "eglChooseModeMESA(height)"); + return EGL_FALSE; + } + break; + case EGL_REFRESH_RATE_MESA: + mode->RefreshRate = attrib_list[++i]; + if (mode->RefreshRate <= 0) { + _eglError(EGL_BAD_PARAMETER, "eglChooseModeMESA(refresh rate)"); + return EGL_FALSE; + } + break; + case EGL_INTERLACED_MESA: + mode->Interlaced = attrib_list[++i]; + if (mode->Interlaced != EGL_TRUE && mode->Interlaced != EGL_FALSE) { + _eglError(EGL_BAD_PARAMETER, "eglChooseModeMESA(interlaced)"); + return EGL_FALSE; + } + break; + case EGL_OPTIMAL_MESA: + mode->Optimal = attrib_list[++i]; + if (mode->Optimal != EGL_TRUE && mode->Optimal != EGL_FALSE) { + _eglError(EGL_BAD_PARAMETER, "eglChooseModeMESA(optimal)"); + return EGL_FALSE; + } + break; + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglChooseModeMESA"); + return EGL_FALSE; + } + } + return EGL_TRUE; +} + + +/** + * Determine if the candidate mode's attributes are at least as good + * as the minimal mode's. + * \return EGL_TRUE if qualifies, EGL_FALSE otherwise + */ +static EGLBoolean +_eglModeQualifies(const _EGLMode *c, const _EGLMode *min) +{ + if (min->Handle != EGL_DONT_CARE && c->Handle != min->Handle) + return EGL_FALSE; + if (min->Width != EGL_DONT_CARE && c->Width < min->Width) + return EGL_FALSE; + if (min->Height != EGL_DONT_CARE && c->Height < min->Height) + return EGL_FALSE; + if (min->RefreshRate != EGL_DONT_CARE && c->RefreshRate < min->RefreshRate) + return EGL_FALSE; + if (min->Optimal != EGL_DONT_CARE && c->Optimal != min->Optimal) + return EGL_FALSE; + if (min->Interlaced != EGL_DONT_CARE && c->Interlaced != min->Interlaced) + return EGL_FALSE; + + return EGL_TRUE; +} + + +/** + * Return value of given mode attribute, or -1 if bad attrib. + */ +static EGLint +getModeAttrib(const _EGLMode *m, EGLint attrib) +{ + switch (attrib) { + case EGL_MODE_ID_MESA: + return m->Handle; + case EGL_WIDTH: + return m->Width; + case EGL_HEIGHT: + return m->Height; + case EGL_REFRESH_RATE_MESA: + return m->RefreshRate; + case EGL_OPTIMAL_MESA: + return m->Optimal; + case EGL_INTERLACED_MESA: + return m->Interlaced; + default: + return -1; + } +} + + +#define SMALLER 1 +#define LARGER 2 + +struct sort_info { + EGLint Attrib; + EGLint Order; /* SMALLER or LARGER */ +}; + +/* the order of these entries is the priority */ +static struct sort_info SortInfo[] = { + { EGL_OPTIMAL_MESA, LARGER }, + { EGL_INTERLACED_MESA, SMALLER }, + { EGL_WIDTH, LARGER }, + { EGL_HEIGHT, LARGER }, + { EGL_REFRESH_RATE_MESA, LARGER }, + { EGL_MODE_ID_MESA, SMALLER }, + { 0, 0 } +}; + + +/** + * Compare modes 'a' and 'b' and return -1 if a belongs before b, or 1 if a + * belongs after b, or 0 if they're equal. + * Used by qsort(). + */ +static int +_eglCompareModes(const void *a, const void *b) +{ + const _EGLMode *aMode = *((const _EGLMode **) a); + const _EGLMode *bMode = *((const _EGLMode **) b); + EGLint i; + + for (i = 0; SortInfo[i].Attrib; i++) { + const EGLint aVal = getModeAttrib(aMode, SortInfo[i].Attrib); + const EGLint bVal = getModeAttrib(bMode, SortInfo[i].Attrib); + if (aVal == bVal) { + /* a tie */ + continue; + } + else if (SortInfo[i].Order == SMALLER) { + return (aVal < bVal) ? -1 : 1; + } + else if (SortInfo[i].Order == LARGER) { + return (aVal > bVal) ? -1 : 1; + } + } + + /* all attributes identical */ + return 0; +} + + +/** + * Search for EGLModes which match the given attribute list. + * Called via eglChooseModeMESA API function. + */ +EGLBoolean +_eglChooseModeMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, + const EGLint *attrib_list, EGLModeMESA *modes, + EGLint modes_size, EGLint *num_modes) +{ + _EGLMode **modeList, min; + EGLint i, count; + + if (!_eglParseModeAttribs(&min, attrib_list)) { + /* error code will have been recorded */ + return EGL_FALSE; + } + + /* allocate array of mode pointers */ + modeList = (_EGLMode **) malloc(modes_size * sizeof(_EGLMode *)); + if (!modeList) { + _eglError(EGL_BAD_MODE_MESA, "eglChooseModeMESA(out of memory)"); + return EGL_FALSE; + } + + /* make array of pointers to qualifying modes */ + for (i = count = 0; i < scrn->NumModes && count < modes_size; i++) { + if (_eglModeQualifies(scrn->Modes + i, &min)) { + modeList[count++] = scrn->Modes + i; + } + } + + /* sort array of pointers */ + qsort(modeList, count, sizeof(_EGLMode *), _eglCompareModes); + + /* copy mode handles to output array */ + for (i = 0; i < count; i++) { + modes[i] = modeList[i]->Handle; + } + + free(modeList); + + *num_modes = count; + + return EGL_TRUE; +} + + + +/** + * Return all possible modes for the given screen. No sorting of results. + * Called via eglGetModesMESA() API function. + */ +EGLBoolean +_eglGetModesMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, + EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes) +{ + if (modes) { + EGLint i; + *num_modes = MIN2(scrn->NumModes, modes_size); + for (i = 0; i < *num_modes; i++) { + modes[i] = scrn->Modes[i].Handle; + } + } + else { + /* just return total number of supported modes */ + *num_modes = scrn->NumModes; + } + + return EGL_TRUE; +} + + +/** + * Query an attribute of a mode. + */ +EGLBoolean +_eglGetModeAttribMESA(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLMode *m, EGLint attribute, EGLint *value) +{ + EGLint v; + + v = getModeAttrib(m, attribute); + if (v < 0) { + _eglError(EGL_BAD_ATTRIBUTE, "eglGetModeAttribMESA"); + return EGL_FALSE; + } + *value = v; + return EGL_TRUE; +} + + +/** + * Return human-readable string for given mode. + * This is the default function called by eglQueryModeStringMESA(). + */ +const char * +_eglQueryModeStringMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLMode *m) +{ + return m->Name; +} + + +#endif /* EGL_MESA_screen_surface */ diff --git a/src/egl/main/eglmode.h b/src/egl/main/eglmode.h new file mode 100644 index 0000000..ed4eb2c --- /dev/null +++ b/src/egl/main/eglmode.h @@ -0,0 +1,58 @@ +#ifndef EGLMODE_INCLUDED +#define EGLMODE_INCLUDED + +#include "egltypedefs.h" + + +#ifdef EGL_MESA_screen_surface + + +#define EGL_NO_MODE_MESA 0 + + +/** + * Data structure which corresponds to an EGLModeMESA. + */ +struct _egl_mode +{ + EGLModeMESA Handle; /* the public/opaque handle which names this mode */ + EGLint Width, Height; /* size in pixels */ + EGLint RefreshRate; /* rate * 1000.0 */ + EGLint Optimal; + EGLint Interlaced; + const char *Name; + + /* Other possible attributes */ + /* interlaced */ + /* external sync */ +}; + + +extern _EGLMode * +_eglLookupMode(EGLModeMESA mode, _EGLDisplay *dpy); + + +extern EGLBoolean +_eglChooseModeMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, + const EGLint *attrib_list, EGLModeMESA *modes, + EGLint modes_size, EGLint *num_modes); + + +extern EGLBoolean +_eglGetModesMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, + EGLModeMESA *modes, EGLint modes_size, EGLint *num_modes); + + +extern EGLBoolean +_eglGetModeAttribMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLMode *m, + EGLint attribute, EGLint *value); + + +extern const char * +_eglQueryModeStringMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLMode *m); + + +#endif /* EGL_MESA_screen_surface */ + + +#endif /* EGLMODE_INCLUDED */ diff --git a/src/egl/main/eglmutex.h b/src/egl/main/eglmutex.h new file mode 100644 index 0000000..29faba0 --- /dev/null +++ b/src/egl/main/eglmutex.h @@ -0,0 +1,52 @@ +#ifndef EGLMUTEX_INCLUDED +#define EGLMUTEX_INCLUDED + +#include "eglcompiler.h" + +#ifdef PTHREADS +#include + +typedef pthread_mutex_t _EGLMutex; + +static INLINE void _eglInitMutex(_EGLMutex *m) +{ + pthread_mutex_init(m, NULL); +} + +static INLINE void +_eglDestroyMutex(_EGLMutex *m) +{ + pthread_mutex_destroy(m); +} + +static INLINE void +_eglLockMutex(_EGLMutex *m) +{ + pthread_mutex_lock(m); +} + +static INLINE void +_eglUnlockMutex(_EGLMutex *m) +{ + pthread_mutex_unlock(m); +} + +#define _EGL_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER +#define _EGL_DECLARE_MUTEX(m) \ + _EGLMutex m = _EGL_MUTEX_INITIALIZER + +#else + +typedef int _EGLMutex; +static INLINE void _eglInitMutex(_EGLMutex *m) { (void) m; } +static INLINE void _eglDestroyMutex(_EGLMutex *m) { (void) m; } +static INLINE void _eglLockMutex(_EGLMutex *m) { (void) m; } +static INLINE void _eglUnlockMutex(_EGLMutex *m) { (void) m; } + +#define _EGL_MUTEX_INITIALIZER 0 +#define _EGL_DECLARE_MUTEX(m) \ + _EGLMutex m = _EGL_MUTEX_INITIALIZER + +#endif + +#endif /* EGLMUTEX_INCLUDED */ diff --git a/src/egl/main/eglscreen.c b/src/egl/main/eglscreen.c new file mode 100644 index 0000000..3abe85f --- /dev/null +++ b/src/egl/main/eglscreen.c @@ -0,0 +1,205 @@ +/* + * Ideas for screen management extension to EGL. + * + * Each EGLDisplay has one or more screens (CRTs, Flat Panels, etc). + * The screens' handles can be obtained with eglGetScreensMESA(). + * + * A new kind of EGLSurface is possible- one which can be directly scanned + * out on a screen. Such a surface is created with eglCreateScreenSurface(). + * + * To actually display a screen surface on a screen, the eglShowSurface() + * function is called. + */ + +#include +#include +#include + +#include "egldisplay.h" +#include "eglcurrent.h" +#include "eglmode.h" +#include "eglsurface.h" +#include "eglscreen.h" +#include "eglmutex.h" + + +#ifdef EGL_MESA_screen_surface + + +/* ugh, no atomic op? */ +static _EGL_DECLARE_MUTEX(_eglNextScreenHandleMutex); +static EGLScreenMESA _eglNextScreenHandle = 1; + + +/** + * Return a new screen handle/ID. + * NOTE: we never reuse these! + */ +static EGLScreenMESA +_eglAllocScreenHandle(void) +{ + EGLScreenMESA s; + + _eglLockMutex(&_eglNextScreenHandleMutex); + s = _eglNextScreenHandle; + _eglNextScreenHandle += _EGL_SCREEN_MAX_MODES; + _eglUnlockMutex(&_eglNextScreenHandleMutex); + + return s; +} + + +/** + * Initialize an _EGLScreen object to default values. + */ +void +_eglInitScreen(_EGLScreen *screen, _EGLDisplay *dpy, EGLint num_modes) +{ + memset(screen, 0, sizeof(_EGLScreen)); + + screen->Display = dpy; + screen->NumModes = num_modes; + screen->StepX = 1; + screen->StepY = 1; + + if (num_modes > _EGL_SCREEN_MAX_MODES) + num_modes = _EGL_SCREEN_MAX_MODES; + screen->Modes = (_EGLMode *) calloc(num_modes, sizeof(*screen->Modes)); + screen->NumModes = (screen->Modes) ? num_modes : 0; +} + + +/** + * Link a screen to its display and return the handle of the link. + * The handle can be passed to client directly. + */ +EGLScreenMESA +_eglLinkScreen(_EGLScreen *screen) +{ + _EGLDisplay *display; + EGLint i; + + assert(screen && screen->Display); + display = screen->Display; + + if (!display->Screens) { + display->Screens = _eglCreateArray("Screen", 4); + if (!display->Screens) + return (EGLScreenMESA) 0; + } + + screen->Handle = _eglAllocScreenHandle(); + for (i = 0; i < screen->NumModes; i++) + screen->Modes[i].Handle = screen->Handle + i; + + _eglAppendArray(display->Screens, (void *) screen); + + return screen->Handle; +} + + +/** + * Lookup a handle to find the linked config. + * Return NULL if the handle has no corresponding linked config. + */ +_EGLScreen * +_eglLookupScreen(EGLScreenMESA screen, _EGLDisplay *display) +{ + EGLint i; + + if (!display || !display->Screens) + return NULL; + + for (i = 0; i < display->Screens->Size; i++) { + _EGLScreen *scr = (_EGLScreen *) display->Screens->Elements[i]; + if (scr->Handle == screen) { + assert(scr->Display == display); + return scr; + } + } + return NULL; +} + + +static EGLBoolean +_eglFlattenScreen(void *elem, void *buffer) +{ + _EGLScreen *scr = (_EGLScreen *) elem; + EGLScreenMESA *handle = (EGLScreenMESA *) buffer; + *handle = _eglGetScreenHandle(scr); + return EGL_TRUE; +} + + +EGLBoolean +_eglGetScreensMESA(_EGLDriver *drv, _EGLDisplay *display, EGLScreenMESA *screens, + EGLint max_screens, EGLint *num_screens) +{ + *num_screens = _eglFlattenArray(display->Screens, (void *) screens, + sizeof(screens[0]), max_screens, _eglFlattenScreen); + + return EGL_TRUE; +} + + +/** + * Set a screen's surface origin. + */ +EGLBoolean +_eglScreenPositionMESA(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLScreen *scrn, EGLint x, EGLint y) +{ + scrn->OriginX = x; + scrn->OriginY = y; + + return EGL_TRUE; +} + + +/** + * Query a screen's current surface. + */ +EGLBoolean +_eglQueryScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLScreen *scrn, _EGLSurface **surf) +{ + *surf = scrn->CurrentSurface; + return EGL_TRUE; +} + + +/** + * Query a screen's current mode. + */ +EGLBoolean +_eglQueryScreenModeMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, + _EGLMode **m) +{ + *m = scrn->CurrentMode; + return EGL_TRUE; +} + + +EGLBoolean +_eglQueryScreenMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, + EGLint attribute, EGLint *value) +{ + switch (attribute) { + case EGL_SCREEN_POSITION_MESA: + value[0] = scrn->OriginX; + value[1] = scrn->OriginY; + break; + case EGL_SCREEN_POSITION_GRANULARITY_MESA: + value[0] = scrn->StepX; + value[1] = scrn->StepY; + break; + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglQueryScreenMESA"); + return EGL_FALSE; + } + + return EGL_TRUE; +} + + +#endif /* EGL_MESA_screen_surface */ diff --git a/src/egl/main/eglscreen.h b/src/egl/main/eglscreen.h new file mode 100644 index 0000000..2a99f23 --- /dev/null +++ b/src/egl/main/eglscreen.h @@ -0,0 +1,86 @@ +#ifndef EGLSCREEN_INCLUDED +#define EGLSCREEN_INCLUDED + + +#include "egltypedefs.h" + + +#ifdef EGL_MESA_screen_surface + + +#define _EGL_SCREEN_MAX_MODES 16 + + +/** + * Per-screen information. + * Note that an EGL screen doesn't have a size. A screen may be set to + * one of several display modes (width/height/scanrate). The screen + * then displays a drawing surface. The drawing surface must be at least + * as large as the display mode's resolution. If it's larger, the + * OriginX and OriginY fields control what part of the surface is visible + * on the screen. + */ +struct _egl_screen +{ + _EGLDisplay *Display; + + EGLScreenMESA Handle; /* The public/opaque handle which names this object */ + + _EGLMode *CurrentMode; + _EGLSurface *CurrentSurface; + + EGLint OriginX, OriginY; /**< Origin of scan-out region w.r.t. surface */ + EGLint StepX, StepY; /**< Screen position/origin granularity */ + + EGLint NumModes; + _EGLMode *Modes; /**< array [NumModes] */ +}; + + +PUBLIC void +_eglInitScreen(_EGLScreen *screen, _EGLDisplay *dpy, EGLint num_modes); + + +PUBLIC EGLScreenMESA +_eglLinkScreen(_EGLScreen *screen); + + +extern _EGLScreen * +_eglLookupScreen(EGLScreenMESA screen, _EGLDisplay *dpy); + + +/** + * Return the handle of a linked screen. + */ +static INLINE EGLScreenMESA +_eglGetScreenHandle(_EGLScreen *screen) +{ + return (screen) ? screen->Handle : (EGLScreenMESA) 0; +} + + +extern EGLBoolean +_eglGetScreensMESA(_EGLDriver *drv, _EGLDisplay *dpy, EGLScreenMESA *screens, EGLint max_screens, EGLint *num_screens); + + +extern EGLBoolean +_eglScreenPositionMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, EGLint x, EGLint y); + + +extern EGLBoolean +_eglQueryScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLScreen *scrn, _EGLSurface **surface); + + +extern EGLBoolean +_eglQueryScreenModeMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, _EGLMode **m); + + +extern EGLBoolean +_eglQueryScreenMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn, EGLint attribute, EGLint *value); + + +#endif /* EGL_MESA_screen_surface */ + + +#endif /* EGLSCREEN_INCLUDED */ diff --git a/src/egl/main/eglstring.c b/src/egl/main/eglstring.c new file mode 100644 index 0000000..e4ab191 --- /dev/null +++ b/src/egl/main/eglstring.c @@ -0,0 +1,24 @@ +/** + * String utils. + */ + +#include +#include +#include "eglstring.h" + + +char * +_eglstrdup(const char *s) +{ + if (s) { + size_t l = strlen(s); + char *s2 = malloc(l + 1); + if (s2) + strcpy(s2, s); + return s2; + } + return NULL; +} + + + diff --git a/src/egl/main/eglstring.h b/src/egl/main/eglstring.h new file mode 100644 index 0000000..f1d559b --- /dev/null +++ b/src/egl/main/eglstring.h @@ -0,0 +1,18 @@ +#ifndef EGLSTRING_INCLUDED +#define EGLSTRING_INCLUDED + +#include + +#ifdef _EGL_OS_WINDOWS +#define _eglstrcasecmp _stricmp +#define _eglsnprintf _snprintf +#else +#define _eglstrcasecmp strcasecmp +#define _eglsnprintf snprintf +#endif + +extern char * +_eglstrdup(const char *s); + + +#endif /* EGLSTRING_INCLUDED */ diff --git a/src/egl/main/eglsurface.c b/src/egl/main/eglsurface.c new file mode 100644 index 0000000..cc50504 --- /dev/null +++ b/src/egl/main/eglsurface.c @@ -0,0 +1,481 @@ +/** + * Surface-related functions. + */ + + +#include +#include +#include +#include "egldisplay.h" +#include "eglcontext.h" +#include "eglconfig.h" +#include "eglcurrent.h" +#include "egllog.h" +#include "eglsurface.h" + + +static void +_eglClampSwapInterval(_EGLSurface *surf, EGLint interval) +{ + EGLint bound = surf->Config->MaxSwapInterval; + if (interval >= bound) { + interval = bound; + } + else { + bound = surf->Config->MinSwapInterval; + if (interval < bound) + interval = bound; + } + surf->SwapInterval = interval; +} + + +#ifdef EGL_MESA_screen_surface +static EGLint +_eglParseScreenSurfaceAttribList(_EGLSurface *surf, const EGLint *attrib_list) +{ + EGLint i, err = EGL_SUCCESS; + + if (!attrib_list) + return EGL_SUCCESS; + + for (i = 0; attrib_list[i] != EGL_NONE; i++) { + EGLint attr = attrib_list[i++]; + EGLint val = attrib_list[i]; + + switch (attr) { + case EGL_WIDTH: + if (val < 0) { + err = EGL_BAD_PARAMETER; + break; + } + surf->Width = val; + break; + case EGL_HEIGHT: + if (val < 0) { + err = EGL_BAD_PARAMETER; + break; + } + surf->Height = val; + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + + if (err != EGL_SUCCESS) { + _eglLog(_EGL_WARNING, "bad surface attribute 0x%04x", attr); + break; + } + } + + return err; +} +#endif /* EGL_MESA_screen_surface */ + + +/** + * Parse the list of surface attributes and return the proper error code. + */ +static EGLint +_eglParseSurfaceAttribList(_EGLSurface *surf, const EGLint *attrib_list) +{ + _EGLDisplay *dpy = surf->Resource.Display; + EGLint type = surf->Type; + EGLint texture_type = EGL_PBUFFER_BIT; + EGLint i, err = EGL_SUCCESS; + + if (!attrib_list) + return EGL_SUCCESS; + +#ifdef EGL_MESA_screen_surface + if (type == EGL_SCREEN_BIT_MESA) + return _eglParseScreenSurfaceAttribList(surf, attrib_list); +#endif + + if (dpy->Extensions.NOK_texture_from_pixmap) + texture_type |= EGL_PIXMAP_BIT; + + for (i = 0; attrib_list[i] != EGL_NONE; i++) { + EGLint attr = attrib_list[i++]; + EGLint val = attrib_list[i]; + + switch (attr) { + /* common attributes */ + case EGL_VG_COLORSPACE: + switch (val) { + case EGL_VG_COLORSPACE_sRGB: + case EGL_VG_COLORSPACE_LINEAR: + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + if (err != EGL_SUCCESS) + break; + surf->VGColorspace = val; + break; + case EGL_VG_ALPHA_FORMAT: + switch (val) { + case EGL_VG_ALPHA_FORMAT_NONPRE: + case EGL_VG_ALPHA_FORMAT_PRE: + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + if (err != EGL_SUCCESS) + break; + surf->VGAlphaFormat = val; + break; + /* window surface attributes */ + case EGL_RENDER_BUFFER: + if (type != EGL_WINDOW_BIT) { + err = EGL_BAD_ATTRIBUTE; + break; + } + if (val != EGL_BACK_BUFFER && val != EGL_SINGLE_BUFFER) { + err = EGL_BAD_ATTRIBUTE; + break; + } + surf->RenderBuffer = val; + break; + /* pbuffer surface attributes */ + case EGL_WIDTH: + if (type != EGL_PBUFFER_BIT) { + err = EGL_BAD_ATTRIBUTE; + break; + } + if (val < 0) { + err = EGL_BAD_PARAMETER; + break; + } + surf->Width = val; + break; + case EGL_HEIGHT: + if (type != EGL_PBUFFER_BIT) { + err = EGL_BAD_ATTRIBUTE; + break; + } + if (val < 0) { + err = EGL_BAD_PARAMETER; + break; + } + surf->Height = val; + break; + case EGL_LARGEST_PBUFFER: + if (type != EGL_PBUFFER_BIT) { + err = EGL_BAD_ATTRIBUTE; + break; + } + surf->LargestPbuffer = !!val; + break; + /* for eglBindTexImage */ + case EGL_TEXTURE_FORMAT: + if (!(type & texture_type)) { + err = EGL_BAD_ATTRIBUTE; + break; + } + switch (val) { + case EGL_TEXTURE_RGB: + case EGL_TEXTURE_RGBA: + case EGL_NO_TEXTURE: + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + if (err != EGL_SUCCESS) + break; + surf->TextureFormat = val; + break; + case EGL_TEXTURE_TARGET: + if (!(type & texture_type)) { + err = EGL_BAD_ATTRIBUTE; + break; + } + switch (val) { + case EGL_TEXTURE_2D: + case EGL_NO_TEXTURE: + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + if (err != EGL_SUCCESS) + break; + surf->TextureTarget = val; + break; + case EGL_MIPMAP_TEXTURE: + if (!(type & texture_type)) { + err = EGL_BAD_ATTRIBUTE; + break; + } + surf->MipmapTexture = !!val; + break; + /* no pixmap surface specific attributes */ + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + + if (err != EGL_SUCCESS) { + _eglLog(_EGL_WARNING, "bad surface attribute 0x%04x", attr); + break; + } + } + + return err; +} + + +/** + * Do error check on parameters and initialize the given _EGLSurface object. + * \return EGL_TRUE if no errors, EGL_FALSE otherwise. + */ +EGLBoolean +_eglInitSurface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type, + _EGLConfig *conf, const EGLint *attrib_list) +{ + const char *func; + EGLint renderBuffer = EGL_BACK_BUFFER; + EGLint err; + + switch (type) { + case EGL_WINDOW_BIT: + func = "eglCreateWindowSurface"; + break; + case EGL_PIXMAP_BIT: + func = "eglCreatePixmapSurface"; + renderBuffer = EGL_SINGLE_BUFFER; + break; + case EGL_PBUFFER_BIT: + func = "eglCreatePBufferSurface"; + break; +#ifdef EGL_MESA_screen_surface + case EGL_SCREEN_BIT_MESA: + func = "eglCreateScreenSurface"; + renderBuffer = EGL_SINGLE_BUFFER; /* XXX correct? */ + break; +#endif + default: + _eglLog(_EGL_WARNING, "Bad type in _eglInitSurface"); + return EGL_FALSE; + } + + if ((conf->SurfaceType & type) == 0) { + /* The config can't be used to create a surface of this type */ + _eglError(EGL_BAD_CONFIG, func); + return EGL_FALSE; + } + + _eglInitResource(&surf->Resource, sizeof(*surf), dpy); + surf->Type = type; + surf->Config = conf; + + surf->Width = 0; + surf->Height = 0; + surf->TextureFormat = EGL_NO_TEXTURE; + surf->TextureTarget = EGL_NO_TEXTURE; + surf->MipmapTexture = EGL_FALSE; + surf->LargestPbuffer = EGL_FALSE; + surf->RenderBuffer = renderBuffer; + surf->VGAlphaFormat = EGL_VG_ALPHA_FORMAT_NONPRE; + surf->VGColorspace = EGL_VG_COLORSPACE_sRGB; + + surf->MipmapLevel = 0; + surf->MultisampleResolve = EGL_MULTISAMPLE_RESOLVE_DEFAULT; + surf->SwapBehavior = EGL_BUFFER_DESTROYED; + + surf->HorizontalResolution = EGL_UNKNOWN; + surf->VerticalResolution = EGL_UNKNOWN; + surf->AspectRatio = EGL_UNKNOWN; + + /* the default swap interval is 1 */ + _eglClampSwapInterval(surf, 1); + + err = _eglParseSurfaceAttribList(surf, attrib_list); + if (err != EGL_SUCCESS) + return _eglError(err, func); + + return EGL_TRUE; +} + + +EGLBoolean +_eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, + EGLint attribute, EGLint *value) +{ + switch (attribute) { + case EGL_WIDTH: + *value = surface->Width; + break; + case EGL_HEIGHT: + *value = surface->Height; + break; + case EGL_CONFIG_ID: + *value = surface->Config->ConfigID; + break; + case EGL_LARGEST_PBUFFER: + *value = surface->LargestPbuffer; + break; + case EGL_TEXTURE_FORMAT: + /* texture attributes: only for pbuffers, no error otherwise */ + if (surface->Type == EGL_PBUFFER_BIT) + *value = surface->TextureFormat; + break; + case EGL_TEXTURE_TARGET: + if (surface->Type == EGL_PBUFFER_BIT) + *value = surface->TextureTarget; + break; + case EGL_MIPMAP_TEXTURE: + if (surface->Type == EGL_PBUFFER_BIT) + *value = surface->MipmapTexture; + break; + case EGL_MIPMAP_LEVEL: + if (surface->Type == EGL_PBUFFER_BIT) + *value = surface->MipmapLevel; + break; + case EGL_SWAP_BEHAVIOR: + *value = surface->SwapBehavior; + break; + case EGL_RENDER_BUFFER: + *value = surface->RenderBuffer; + break; + case EGL_PIXEL_ASPECT_RATIO: + *value = surface->AspectRatio; + break; + case EGL_HORIZONTAL_RESOLUTION: + *value = surface->HorizontalResolution; + break; + case EGL_VERTICAL_RESOLUTION: + *value = surface->VerticalResolution; + break; + case EGL_MULTISAMPLE_RESOLVE: + *value = surface->MultisampleResolve; + break; + case EGL_VG_ALPHA_FORMAT: + *value = surface->VGAlphaFormat; + break; + case EGL_VG_COLORSPACE: + *value = surface->VGColorspace; + break; + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface"); + return EGL_FALSE; + } + + return EGL_TRUE; +} + + +/** + * Default fallback routine - drivers might override this. + */ +EGLBoolean +_eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, + EGLint attribute, EGLint value) +{ + EGLint confval; + EGLint err = EGL_SUCCESS; + + switch (attribute) { + case EGL_MIPMAP_LEVEL: + confval = surface->Config->RenderableType; + if (!(confval & (EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT))) { + err = EGL_BAD_PARAMETER; + break; + } + surface->MipmapLevel = value; + break; + case EGL_MULTISAMPLE_RESOLVE: + switch (value) { + case EGL_MULTISAMPLE_RESOLVE_DEFAULT: + break; + case EGL_MULTISAMPLE_RESOLVE_BOX: + confval = surface->Config->SurfaceType; + if (!(confval & EGL_MULTISAMPLE_RESOLVE_BOX_BIT)) + err = EGL_BAD_MATCH; + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + if (err != EGL_SUCCESS) + break; + surface->MultisampleResolve = value; + break; + case EGL_SWAP_BEHAVIOR: + switch (value) { + case EGL_BUFFER_DESTROYED: + break; + case EGL_BUFFER_PRESERVED: + confval = surface->Config->SurfaceType; + if (!(confval & EGL_SWAP_BEHAVIOR_PRESERVED_BIT)) + err = EGL_BAD_MATCH; + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + if (err != EGL_SUCCESS) + break; + surface->SwapBehavior = value; + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + + if (err != EGL_SUCCESS) + return _eglError(err, "eglSurfaceAttrib"); + return EGL_TRUE; +} + + +EGLBoolean +_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, + EGLint buffer) +{ + EGLint texture_type = EGL_PBUFFER_BIT; + + /* Just do basic error checking and return success/fail. + * Drivers must implement the real stuff. + */ + + if (dpy->Extensions.NOK_texture_from_pixmap) + texture_type |= EGL_PIXMAP_BIT; + + if (!(surface->Type & texture_type)) { + _eglError(EGL_BAD_SURFACE, "eglBindTexImage"); + return EGL_FALSE; + } + + if (surface->TextureFormat == EGL_NO_TEXTURE) { + _eglError(EGL_BAD_MATCH, "eglBindTexImage"); + return EGL_FALSE; + } + + if (surface->TextureTarget == EGL_NO_TEXTURE) { + _eglError(EGL_BAD_MATCH, "eglBindTexImage"); + return EGL_FALSE; + } + + if (buffer != EGL_BACK_BUFFER) { + _eglError(EGL_BAD_PARAMETER, "eglBindTexImage"); + return EGL_FALSE; + } + + surface->BoundToTexture = EGL_TRUE; + + return EGL_TRUE; +} + + +EGLBoolean +_eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, + EGLint interval) +{ + _eglClampSwapInterval(surf, interval); + return EGL_TRUE; +} diff --git a/src/egl/main/eglsurface.h b/src/egl/main/eglsurface.h new file mode 100644 index 0000000..ef01b32 --- /dev/null +++ b/src/egl/main/eglsurface.h @@ -0,0 +1,141 @@ +#ifndef EGLSURFACE_INCLUDED +#define EGLSURFACE_INCLUDED + + +#include "egltypedefs.h" +#include "egldisplay.h" + + +/** + * "Base" class for device driver surfaces. + */ +struct _egl_surface +{ + /* A surface is a display resource */ + _EGLResource Resource; + + /* The context that is currently bound to the surface */ + _EGLContext *CurrentContext; + + _EGLConfig *Config; + + EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */ + + /* attributes set by attribute list */ + EGLint Width, Height; + EGLenum TextureFormat; + EGLenum TextureTarget; + EGLBoolean MipmapTexture; + EGLBoolean LargestPbuffer; + EGLenum RenderBuffer; + EGLenum VGAlphaFormat; + EGLenum VGColorspace; + + /* attributes set by eglSurfaceAttrib */ + EGLint MipmapLevel; + EGLenum MultisampleResolve; + EGLenum SwapBehavior; + + EGLint HorizontalResolution, VerticalResolution; + EGLint AspectRatio; + + EGLint SwapInterval; + + /* True if the surface is bound to an OpenGL ES texture */ + EGLBoolean BoundToTexture; +}; + + +PUBLIC EGLBoolean +_eglInitSurface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type, + _EGLConfig *config, const EGLint *attrib_list); + + +extern EGLBoolean +_eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint *value); + + +extern EGLBoolean +_eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint value); + + +PUBLIC extern EGLBoolean +_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer); + + +extern EGLBoolean +_eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval); + + +/** + * Increment reference count for the surface. + */ +static INLINE _EGLSurface * +_eglGetSurface(_EGLSurface *surf) +{ + if (surf) + _eglGetResource(&surf->Resource); + return surf; +} + + +/** + * Decrement reference count for the surface. + */ +static INLINE EGLBoolean +_eglPutSurface(_EGLSurface *surf) +{ + return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE; +} + + +/** + * Link a surface to its display and return the handle of the link. + * The handle can be passed to client directly. + */ +static INLINE EGLSurface +_eglLinkSurface(_EGLSurface *surf) +{ + _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE); + return (EGLSurface) surf; +} + + +/** + * Unlink a linked surface from its display. + * Accessing an unlinked surface should generate EGL_BAD_SURFACE error. + */ +static INLINE void +_eglUnlinkSurface(_EGLSurface *surf) +{ + _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE); +} + + +/** + * Lookup a handle to find the linked surface. + * Return NULL if the handle has no corresponding linked surface. + */ +static INLINE _EGLSurface * +_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy) +{ + _EGLSurface *surf = (_EGLSurface *) surface; + if (!dpy || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, dpy)) + surf = NULL; + return surf; +} + + +/** + * Return the handle of a linked surface, or EGL_NO_SURFACE. + */ +static INLINE EGLSurface +_eglGetSurfaceHandle(_EGLSurface *surf) +{ + _EGLResource *res = (_EGLResource *) surf; + return (res && _eglIsResourceLinked(res)) ? + (EGLSurface) surf : EGL_NO_SURFACE; +} + + +#endif /* EGLSURFACE_INCLUDED */ diff --git a/src/egl/main/eglsync.c b/src/egl/main/eglsync.c new file mode 100644 index 0000000..95e97c7 --- /dev/null +++ b/src/egl/main/eglsync.c @@ -0,0 +1,94 @@ +#include + +#include "eglsync.h" +#include "eglcurrent.h" +#include "egllog.h" + + +#ifdef EGL_KHR_reusable_sync + + +/** + * Parse the list of sync attributes and return the proper error code. + */ +static EGLint +_eglParseSyncAttribList(_EGLSync *sync, const EGLint *attrib_list) +{ + EGLint i, err = EGL_SUCCESS; + + if (!attrib_list) + return EGL_SUCCESS; + + for (i = 0; attrib_list[i] != EGL_NONE; i++) { + EGLint attr = attrib_list[i++]; + EGLint val = attrib_list[i]; + + switch (attr) { + default: + (void) val; + err = EGL_BAD_ATTRIBUTE; + break; + } + + if (err != EGL_SUCCESS) { + _eglLog(_EGL_DEBUG, "bad sync attribute 0x%04x", attr); + break; + } + } + + return err; +} + + +EGLBoolean +_eglInitSync(_EGLSync *sync, _EGLDisplay *dpy, EGLenum type, + const EGLint *attrib_list) +{ + EGLint err; + + if (!(type == EGL_SYNC_REUSABLE_KHR && dpy->Extensions.KHR_reusable_sync) && + !(type == EGL_SYNC_FENCE_KHR && dpy->Extensions.KHR_fence_sync)) + return _eglError(EGL_BAD_ATTRIBUTE, "eglCreateSyncKHR"); + + _eglInitResource(&sync->Resource, sizeof(*sync), dpy); + sync->Type = type; + sync->SyncStatus = EGL_UNSIGNALED_KHR; + sync->SyncCondition = EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR; + + err = _eglParseSyncAttribList(sync, attrib_list); + if (err != EGL_SUCCESS) + return _eglError(err, "eglCreateSyncKHR"); + + return EGL_TRUE; +} + + +EGLBoolean +_eglGetSyncAttribKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, + EGLint attribute, EGLint *value) +{ + if (!value) + return _eglError(EGL_BAD_PARAMETER, "eglGetConfigs"); + + switch (attribute) { + case EGL_SYNC_TYPE_KHR: + *value = sync->Type; + break; + case EGL_SYNC_STATUS_KHR: + *value = sync->SyncStatus; + break; + case EGL_SYNC_CONDITION_KHR: + if (sync->Type != EGL_SYNC_FENCE_KHR) + return _eglError(EGL_BAD_ATTRIBUTE, "eglGetSyncAttribKHR"); + *value = sync->SyncCondition; + break; + default: + return _eglError(EGL_BAD_ATTRIBUTE, "eglGetSyncAttribKHR"); + break; + } + + return EGL_TRUE; +} + + +#endif /* EGL_KHR_reusable_sync */ diff --git a/src/egl/main/eglsync.h b/src/egl/main/eglsync.h new file mode 100644 index 0000000..a002523 --- /dev/null +++ b/src/egl/main/eglsync.h @@ -0,0 +1,109 @@ +#ifndef EGLSYNC_INCLUDED +#define EGLSYNC_INCLUDED + + +#include "egltypedefs.h" +#include "egldisplay.h" + + +#ifdef EGL_KHR_reusable_sync + + +/** + * "Base" class for device driver syncs. + */ +struct _egl_sync +{ + /* A sync is a display resource */ + _EGLResource Resource; + + EGLenum Type; + EGLenum SyncStatus; + EGLenum SyncCondition; +}; + + +PUBLIC EGLBoolean +_eglInitSync(_EGLSync *sync, _EGLDisplay *dpy, EGLenum type, + const EGLint *attrib_list); + + +extern EGLBoolean +_eglGetSyncAttribKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, + EGLint attribute, EGLint *value); + + +/** + * Increment reference count for the sync. + */ +static INLINE _EGLSync * +_eglGetSync(_EGLSync *sync) +{ + if (sync) + _eglGetResource(&sync->Resource); + return sync; +} + + +/** + * Decrement reference count for the sync. + */ +static INLINE EGLBoolean +_eglPutSync(_EGLSync *sync) +{ + return (sync) ? _eglPutResource(&sync->Resource) : EGL_FALSE; +} + + +/** + * Link a sync to its display and return the handle of the link. + * The handle can be passed to client directly. + */ +static INLINE EGLSyncKHR +_eglLinkSync(_EGLSync *sync) +{ + _eglLinkResource(&sync->Resource, _EGL_RESOURCE_SYNC); + return (EGLSyncKHR) sync; +} + + +/** + * Unlink a linked sync from its display. + */ +static INLINE void +_eglUnlinkSync(_EGLSync *sync) +{ + _eglUnlinkResource(&sync->Resource, _EGL_RESOURCE_SYNC); +} + + +/** + * Lookup a handle to find the linked sync. + * Return NULL if the handle has no corresponding linked sync. + */ +static INLINE _EGLSync * +_eglLookupSync(EGLSyncKHR handle, _EGLDisplay *dpy) +{ + _EGLSync *sync = (_EGLSync *) handle; + if (!dpy || !_eglCheckResource((void *) sync, _EGL_RESOURCE_SYNC, dpy)) + sync = NULL; + return sync; +} + + +/** + * Return the handle of a linked sync, or EGL_NO_SYNC_KHR. + */ +static INLINE EGLSyncKHR +_eglGetSyncHandle(_EGLSync *sync) +{ + _EGLResource *res = (_EGLResource *) sync; + return (res && _eglIsResourceLinked(res)) ? + (EGLSyncKHR) sync : EGL_NO_SYNC_KHR; +} + + +#endif /* EGL_KHR_reusable_sync */ + + +#endif /* EGLSYNC_INCLUDED */ diff --git a/src/egl/main/egltypedefs.h b/src/egl/main/egltypedefs.h new file mode 100644 index 0000000..20b67b2 --- /dev/null +++ b/src/egl/main/egltypedefs.h @@ -0,0 +1,41 @@ +#ifndef EGLTYPEDEFS_INCLUDED +#define EGLTYPEDEFS_INCLUDED + +#define EGL_EGLEXT_PROTOTYPES + +#include +#include + +#include "eglcompiler.h" + +typedef struct _egl_api _EGLAPI; + +typedef struct _egl_array _EGLArray; + +typedef struct _egl_config _EGLConfig; + +typedef struct _egl_context _EGLContext; + +typedef struct _egl_display _EGLDisplay; + +typedef struct _egl_driver _EGLDriver; + +typedef struct _egl_extensions _EGLExtensions; + +typedef struct _egl_image _EGLImage; + +typedef struct _egl_image_attribs _EGLImageAttribs; + +typedef struct _egl_mode _EGLMode; + +typedef struct _egl_resource _EGLResource; + +typedef struct _egl_screen _EGLScreen; + +typedef struct _egl_surface _EGLSurface; + +typedef struct _egl_sync _EGLSync; + +typedef struct _egl_thread_info _EGLThreadInfo; + +#endif /* EGLTYPEDEFS_INCLUDED */ diff --git a/src/gallium/Makefile b/src/gallium/Makefile new file mode 100644 index 0000000..79ca767 --- /dev/null +++ b/src/gallium/Makefile @@ -0,0 +1,12 @@ +# src/gallium/Makefile +TOP = ../.. +include $(TOP)/configs/current + +SUBDIRS = $(GALLIUM_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/Makefile.template b/src/gallium/Makefile.template new file mode 100644 index 0000000..036c119 --- /dev/null +++ b/src/gallium/Makefile.template @@ -0,0 +1,73 @@ +# src/gallium/Makefile.template + +# Template makefile for gallium libraries. +# +# Usage: +# The minimum that the including makefile needs to define +# is TOP, LIBNAME and one of of the *_SOURCES. +# +# Optional defines: +# LIBRARY_INCLUDES are appended to the list of includes directories. +# LIBRARY_DEFINES is not used for makedepend, but for compilation. + +### Basic defines ### + +OBJECTS = $(C_SOURCES:.c=.o) \ + $(CPP_SOURCES:.cpp=.o) \ + $(ASM_SOURCES:.S=.o) + +INCLUDES = \ + -I. \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers \ + $(LIBRARY_INCLUDES) + +ifeq ($(MESA_LLVM),1) +LIBRARY_DEFINES += $(LLVM_CFLAGS) +endif + + +##### TARGETS ##### + +default: depend lib$(LIBNAME).a $(PROGS) + +lib$(LIBNAME).a: $(OBJECTS) $(EXTRA_OBJECTS) Makefile $(TOP)/src/gallium/Makefile.template + $(MKLIB) -o $(LIBNAME) -static $(OBJECTS) $(EXTRA_OBJECTS) + +depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURCES) + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(GENERATED_SOURCES) 2> /dev/null + +$(PROGS): % : %.o $(PROGS_DEPS) + $(LD) $(LDFLAGS) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS) -Wl,--end-group + +# Emacs tags +tags: + etags `find . -name \*.[ch]` `find $(TOP)/src/gallium/include -name \*.h` + +# Remove .o and backup files +clean: + rm -f $(OBJECTS) $(GENERATED_SOURCES) $(PROGS) lib$(LIBNAME).a depend depend.bak $(CLEAN_EXTRA) + +# Dummy target +install: + @echo -n "" + +##### RULES ##### + +%.s: %.c + $(CC) -S $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@ + +%.o: %.c + $(CC) -c $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@ + +%.o: %.cpp + $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(LIBRARY_DEFINES) $< -o $@ + +%.o: %.S + $(CC) -c $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@ + + +sinclude depend diff --git a/src/gallium/SConscript b/src/gallium/SConscript new file mode 100644 index 0000000..0efab83 --- /dev/null +++ b/src/gallium/SConscript @@ -0,0 +1,135 @@ +Import('env') + +# +# Auxiliary modules +# + +SConscript('auxiliary/SConscript') + +# +# Drivers +# + +SConscript([ + 'drivers/failover/SConscript', + 'drivers/galahad/SConscript', + 'drivers/identity/SConscript', + 'drivers/llvmpipe/SConscript', + 'drivers/rbug/SConscript', + 'drivers/softpipe/SConscript', + 'drivers/svga/SConscript', + 'drivers/trace/SConscript', +]) + +if not env['msvc']: + # These drivers do not build on MSVC compilers + SConscript([ + 'drivers/i915/SConscript', + 'drivers/i965/SConscript', + 'drivers/r300/SConscript', + ]) + +if env['drm']: + # These drivers depend on drm headers + if env['drm_radeon']: + SConscript([ + 'drivers/r600/SConscript', + ]) + # XXX: nouveau drivers have a tight dependency on libdrm, so to enable + # we need some version logic before we enable them. Also, ATM there is + # no nouveau target in scons + # if env['drm_nouveau']: + # SConscript([ + # 'drivers/nouveau/SConscript', + # 'drivers/nv50/SConscript', + # 'drivers/nvfx/SConscript', + # ]) + +# +# State trackers +# + +# Needed by some state trackers +SConscript('winsys/sw/null/SConscript') + +SConscript('state_trackers/python/SConscript') +if env['platform'] != 'embedded': + SConscript('state_trackers/vega/SConscript') + + if env['x11']: + SConscript('state_trackers/glx/xlib/SConscript') + + if env['dri']: + SConscript('state_trackers/dri/SConscript') + + if env['dri'] and env['xorg']: + SConscript('state_trackers/xorg/SConscript') + +if env['platform'] == 'windows': + SConscript([ + 'state_trackers/egl/SConscript', + 'state_trackers/wgl/SConscript', + ]) + +# +# Winsys +# + +SConscript('winsys/SConscript') + +# +# Targets +# + +SConscript([ + 'targets/graw-null/SConscript', +]) + +if env['x11']: + SConscript([ + 'targets/graw-xlib/SConscript', + 'targets/libgl-xlib/SConscript', + ]) + +if env['platform'] == 'windows': + SConscript([ + 'targets/graw-gdi/SConscript', + 'targets/libgl-gdi/SConscript', + #'egl-gdi/SConscript', + ]) + +if env['dri']: + SConscript([ + 'targets/SConscript.dri', + 'targets/dri-swrast/SConscript', + 'targets/dri-vmwgfx/SConscript', + #'targets/dri-nouveau/SConscript', + ]) + if env['drm_intel']: + SConscript([ + 'targets/dri-i915/SConscript', + 'targets/dri-i965/SConscript', + ]) + if env['drm_radeon']: + SConscript([ + 'targets/dri-r300/SConscript', + 'targets/dri-r600/SConscript', + ]) + +if env['xorg'] and env['drm']: + SConscript([ + #'targets/xorg-i915/SConscript', + #'targets/xorg-i965/SConscript', + #'targets/xorg-nouveau/SConscript', + #'targets/xorg-radeon/SConscript', + 'targets/xorg-vmwgfx/SConscript', + ]) + + +# +# Unit tests & tools +# + +if env['platform'] != 'embedded': + SConscript('tests/unit/SConscript') + SConscript('tests/graw/SConscript') diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile new file mode 100644 index 0000000..ff355c4 --- /dev/null +++ b/src/gallium/auxiliary/Makefile @@ -0,0 +1,222 @@ +TOP = ../../.. +include $(TOP)/configs/current + +LIBNAME = gallium + +C_SOURCES = \ + cso_cache/cso_cache.c \ + cso_cache/cso_context.c \ + cso_cache/cso_hash.c \ + draw/draw_context.c \ + draw/draw_fs.c \ + draw/draw_gs.c \ + draw/draw_pipe.c \ + draw/draw_pipe_aaline.c \ + draw/draw_pipe_aapoint.c \ + draw/draw_pipe_clip.c \ + draw/draw_pipe_cull.c \ + draw/draw_pipe_flatshade.c \ + draw/draw_pipe_offset.c \ + draw/draw_pipe_pstipple.c \ + draw/draw_pipe_stipple.c \ + draw/draw_pipe_twoside.c \ + draw/draw_pipe_unfilled.c \ + draw/draw_pipe_util.c \ + draw/draw_pipe_validate.c \ + draw/draw_pipe_vbuf.c \ + draw/draw_pipe_wide_line.c \ + draw/draw_pipe_wide_point.c \ + draw/draw_pt.c \ + draw/draw_pt_emit.c \ + draw/draw_pt_fetch.c \ + draw/draw_pt_fetch_emit.c \ + draw/draw_pt_fetch_shade_emit.c \ + draw/draw_pt_fetch_shade_pipeline.c \ + draw/draw_pt_post_vs.c \ + draw/draw_pt_so_emit.c \ + draw/draw_pt_util.c \ + draw/draw_pt_vsplit.c \ + draw/draw_vertex.c \ + draw/draw_vs.c \ + draw/draw_vs_aos.c \ + draw/draw_vs_aos_io.c \ + draw/draw_vs_aos_machine.c \ + draw/draw_vs_exec.c \ + draw/draw_vs_ppc.c \ + draw/draw_vs_sse.c \ + draw/draw_vs_varient.c \ + indices/u_indices_gen.c \ + indices/u_unfilled_gen.c \ + os/os_misc.c \ + os/os_stream.c \ + os/os_stream_log.c \ + os/os_stream_null.c \ + os/os_stream_stdc.c \ + os/os_stream_str.c \ + os/os_time.c \ + pipebuffer/pb_buffer_fenced.c \ + pipebuffer/pb_buffer_malloc.c \ + pipebuffer/pb_bufmgr_alt.c \ + pipebuffer/pb_bufmgr_cache.c \ + pipebuffer/pb_bufmgr_debug.c \ + pipebuffer/pb_bufmgr_mm.c \ + pipebuffer/pb_bufmgr_ondemand.c \ + pipebuffer/pb_bufmgr_pool.c \ + pipebuffer/pb_bufmgr_slab.c \ + pipebuffer/pb_validate.c \ + rbug/rbug_connection.c \ + rbug/rbug_context.c \ + rbug/rbug_core.c \ + rbug/rbug_demarshal.c \ + rbug/rbug_texture.c \ + rbug/rbug_shader.c \ + rtasm/rtasm_cpu.c \ + rtasm/rtasm_execmem.c \ + rtasm/rtasm_ppc.c \ + rtasm/rtasm_ppc_spe.c \ + rtasm/rtasm_x86sse.c \ + tgsi/tgsi_build.c \ + tgsi/tgsi_dump.c \ + tgsi/tgsi_exec.c \ + tgsi/tgsi_info.c \ + tgsi/tgsi_iterate.c \ + tgsi/tgsi_parse.c \ + tgsi/tgsi_ppc.c \ + tgsi/tgsi_sanity.c \ + tgsi/tgsi_scan.c \ + tgsi/tgsi_sse2.c \ + tgsi/tgsi_text.c \ + tgsi/tgsi_transform.c \ + tgsi/tgsi_ureg.c \ + tgsi/tgsi_util.c \ + translate/translate.c \ + translate/translate_cache.c \ + translate/translate_generic.c \ + translate/translate_sse.c \ + util/u_debug.c \ + util/u_debug_describe.c \ + util/u_debug_refcnt.c \ + util/u_debug_stack.c \ + util/u_debug_symbol.c \ + util/u_dump_defines.c \ + util/u_dump_state.c \ + util/u_bitmask.c \ + util/u_blit.c \ + util/u_blitter.c \ + util/u_cache.c \ + util/u_caps.c \ + util/u_cpu_detect.c \ + util/u_dl.c \ + util/u_draw_quad.c \ + util/u_format.c \ + util/u_format_other.c \ + util/u_format_s3tc.c \ + util/u_format_srgb.c \ + util/u_format_table.c \ + util/u_format_tests.c \ + util/u_format_yuv.c \ + util/u_format_zs.c \ + util/u_framebuffer.c \ + util/u_gen_mipmap.c \ + util/u_half.c \ + util/u_handle_table.c \ + util/u_hash.c \ + util/u_hash_table.c \ + util/u_index_modify.c \ + util/u_keymap.c \ + util/u_linear.c \ + util/u_linkage.c \ + util/u_network.c \ + util/u_math.c \ + util/u_mm.c \ + util/u_rect.c \ + util/u_ringbuffer.c \ + util/u_sampler.c \ + util/u_simple_shaders.c \ + util/u_slab.c \ + util/u_snprintf.c \ + util/u_staging.c \ + util/u_surface.c \ + util/u_surfaces.c \ + util/u_texture.c \ + util/u_tile.c \ + util/u_transfer.c \ + util/u_resource.c \ + util/u_upload_mgr.c + + # Disabling until pipe-video branch gets merged in + #vl/vl_bitstream_parser.c \ + #vl/vl_mpeg12_mc_renderer.c \ + #vl/vl_compositor.c \ + #vl/vl_csc.c \ + #vl/vl_shader_build.c \ + +GALLIVM_SOURCES = \ + gallivm/lp_bld_arit.c \ + gallivm/lp_bld_assert.c \ + gallivm/lp_bld_bitarit.c \ + gallivm/lp_bld_const.c \ + gallivm/lp_bld_conv.c \ + gallivm/lp_bld_debug.c \ + gallivm/lp_bld_flow.c \ + gallivm/lp_bld_format_aos.c \ + gallivm/lp_bld_format_soa.c \ + gallivm/lp_bld_format_yuv.c \ + gallivm/lp_bld_gather.c \ + gallivm/lp_bld_init.c \ + gallivm/lp_bld_intr.c \ + gallivm/lp_bld_logic.c \ + gallivm/lp_bld_pack.c \ + gallivm/lp_bld_printf.c \ + gallivm/lp_bld_quad.c \ + gallivm/lp_bld_sample.c \ + gallivm/lp_bld_sample_aos.c \ + gallivm/lp_bld_sample_soa.c \ + gallivm/lp_bld_struct.c \ + gallivm/lp_bld_swizzle.c \ + gallivm/lp_bld_tgsi_aos.c \ + gallivm/lp_bld_tgsi_info.c \ + gallivm/lp_bld_tgsi_soa.c \ + gallivm/lp_bld_type.c \ + draw/draw_llvm.c \ + draw/draw_llvm_sample.c \ + draw/draw_llvm_translate.c \ + draw/draw_vs_llvm.c \ + draw/draw_pt_fetch_shade_pipeline_llvm.c + +GALLIVM_CPP_SOURCES = \ + gallivm/lp_bld_misc.cpp + +GENERATED_SOURCES = \ + indices/u_indices_gen.c \ + indices/u_unfilled_gen.c \ + util/u_format_srgb.c \ + util/u_format_table.c \ + util/u_half.c + + +ifeq ($(MESA_LLVM),1) +C_SOURCES += \ + $(GALLIVM_SOURCES) +CPP_SOURCES += \ + $(GALLIVM_CPP_SOURCES) +endif + + +include ../Makefile.template + + +indices/u_indices_gen.c: indices/u_indices_gen.py + $(PYTHON2) $< > $@ + +indices/u_unfilled_gen.c: indices/u_unfilled_gen.py + $(PYTHON2) $< > $@ + +util/u_format_srgb.c: util/u_format_srgb.py + $(PYTHON2) $< > $@ + +util/u_format_table.c: util/u_format_table.py util/u_format_pack.py util/u_format_parse.py util/u_format.csv + $(PYTHON2) util/u_format_table.py util/u_format.csv > $@ + +util/u_half.c: util/u_half.py + $(PYTHON2) util/u_half.py > $@ diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript new file mode 100644 index 0000000..fca7e5f --- /dev/null +++ b/src/gallium/auxiliary/SConscript @@ -0,0 +1,247 @@ +Import('*') + +from sys import executable as python_cmd + +env.Append(CPPPATH = [ + 'indices', + 'util', +]) + +env.CodeGenerate( + target = 'indices/u_indices_gen.c', + script = 'indices/u_indices_gen.py', + source = [], + command = python_cmd + ' $SCRIPT > $TARGET' +) + +env.CodeGenerate( + target = 'indices/u_unfilled_gen.c', + script = 'indices/u_unfilled_gen.py', + source = [], + command = python_cmd + ' $SCRIPT > $TARGET' +) + +env.CodeGenerate( + target = 'util/u_format_srgb.c', + script = 'util/u_format_srgb.py', + source = [], + command = python_cmd + ' $SCRIPT > $TARGET' +) + +env.CodeGenerate( + target = 'util/u_format_table.c', + script = '#src/gallium/auxiliary/util/u_format_table.py', + source = ['#src/gallium/auxiliary/util/u_format.csv'], + command = python_cmd + ' $SCRIPT $SOURCE > $TARGET' +) + +env.CodeGenerate( + target = 'util/u_half.c', + script = 'util/u_half.py', + source = [], + command = python_cmd + ' $SCRIPT > $TARGET' +) + +env.Depends('util/u_format_table.c', [ + '#src/gallium/auxiliary/util/u_format_parse.py', + 'util/u_format_pack.py', +]) + +source = [ + 'cso_cache/cso_cache.c', + 'cso_cache/cso_context.c', + 'cso_cache/cso_hash.c', + 'draw/draw_context.c', + 'draw/draw_fs.c', + 'draw/draw_gs.c', + 'draw/draw_pipe.c', + 'draw/draw_pipe_aaline.c', + 'draw/draw_pipe_aapoint.c', + 'draw/draw_pipe_clip.c', + 'draw/draw_pipe_cull.c', + 'draw/draw_pipe_flatshade.c', + 'draw/draw_pipe_offset.c', + 'draw/draw_pipe_pstipple.c', + 'draw/draw_pipe_stipple.c', + 'draw/draw_pipe_twoside.c', + 'draw/draw_pipe_unfilled.c', + 'draw/draw_pipe_util.c', + 'draw/draw_pipe_validate.c', + 'draw/draw_pipe_vbuf.c', + 'draw/draw_pipe_wide_line.c', + 'draw/draw_pipe_wide_point.c', + 'draw/draw_pt.c', + 'draw/draw_pt_emit.c', + 'draw/draw_pt_fetch.c', + 'draw/draw_pt_fetch_emit.c', + 'draw/draw_pt_fetch_shade_emit.c', + 'draw/draw_pt_fetch_shade_pipeline.c', + 'draw/draw_pt_post_vs.c', + 'draw/draw_pt_so_emit.c', + 'draw/draw_pt_util.c', + 'draw/draw_pt_vsplit.c', + 'draw/draw_vertex.c', + 'draw/draw_vs.c', + 'draw/draw_vs_aos.c', + 'draw/draw_vs_aos_io.c', + 'draw/draw_vs_aos_machine.c', + 'draw/draw_vs_exec.c', + 'draw/draw_vs_ppc.c', + 'draw/draw_vs_sse.c', + 'draw/draw_vs_varient.c', + #'indices/u_indices.c', + #'indices/u_unfilled_indices.c', + 'indices/u_indices_gen.c', + 'indices/u_unfilled_gen.c', + 'os/os_misc.c', + 'os/os_stream.c', + 'os/os_stream_log.c', + 'os/os_stream_null.c', + 'os/os_stream_stdc.c', + 'os/os_stream_str.c', + 'os/os_time.c', + 'pipebuffer/pb_buffer_fenced.c', + 'pipebuffer/pb_buffer_malloc.c', + 'pipebuffer/pb_bufmgr_alt.c', + 'pipebuffer/pb_bufmgr_cache.c', + 'pipebuffer/pb_bufmgr_debug.c', + 'pipebuffer/pb_bufmgr_mm.c', + 'pipebuffer/pb_bufmgr_ondemand.c', + 'pipebuffer/pb_bufmgr_pool.c', + 'pipebuffer/pb_bufmgr_slab.c', + 'pipebuffer/pb_validate.c', + 'rbug/rbug_connection.c', + 'rbug/rbug_context.c', + 'rbug/rbug_core.c', + 'rbug/rbug_demarshal.c', + 'rbug/rbug_shader.c', + 'rbug/rbug_texture.c', + 'rtasm/rtasm_cpu.c', + 'rtasm/rtasm_execmem.c', + 'rtasm/rtasm_ppc.c', + 'rtasm/rtasm_ppc_spe.c', + 'rtasm/rtasm_x86sse.c', + 'tgsi/tgsi_build.c', + 'tgsi/tgsi_dump.c', + 'tgsi/tgsi_exec.c', + 'tgsi/tgsi_info.c', + 'tgsi/tgsi_iterate.c', + 'tgsi/tgsi_parse.c', + 'tgsi/tgsi_ppc.c', + 'tgsi/tgsi_sanity.c', + 'tgsi/tgsi_scan.c', + 'tgsi/tgsi_sse2.c', + 'tgsi/tgsi_text.c', + 'tgsi/tgsi_transform.c', + 'tgsi/tgsi_ureg.c', + 'tgsi/tgsi_util.c', + 'translate/translate.c', + 'translate/translate_cache.c', + 'translate/translate_generic.c', + 'translate/translate_sse.c', + 'util/u_bitmask.c', + 'util/u_blit.c', + 'util/u_blitter.c', + 'util/u_cache.c', + 'util/u_caps.c', + 'util/u_cpu_detect.c', + 'util/u_debug.c', + 'util/u_debug_describe.c', + 'util/u_debug_memory.c', + 'util/u_debug_refcnt.c', + 'util/u_debug_stack.c', + 'util/u_debug_symbol.c', + 'util/u_dump_defines.c', + 'util/u_dump_state.c', + 'util/u_dl.c', + 'util/u_draw_quad.c', + 'util/u_format.c', + 'util/u_format_other.c', + 'util/u_format_s3tc.c', + 'util/u_format_srgb.c', + 'util/u_format_table.c', + 'util/u_format_tests.c', + 'util/u_format_yuv.c', + 'util/u_format_zs.c', + 'util/u_framebuffer.c', + 'util/u_gen_mipmap.c', + 'util/u_half.c', + 'util/u_handle_table.c', + 'util/u_hash.c', + 'util/u_hash_table.c', + 'util/u_index_modify.c', + 'util/u_keymap.c', + 'util/u_linear.c', + 'util/u_linkage.c', + 'util/u_network.c', + 'util/u_math.c', + 'util/u_mm.c', + 'util/u_rect.c', + 'util/u_resource.c', + 'util/u_ringbuffer.c', + 'util/u_sampler.c', + 'util/u_simple_shaders.c', + 'util/u_slab.c', + 'util/u_snprintf.c', + 'util/u_staging.c', + 'util/u_surface.c', + 'util/u_surfaces.c', + 'util/u_texture.c', + 'util/u_tile.c', + 'util/u_transfer.c', + 'util/u_upload_mgr.c', + # Disabling until pipe-video branch gets merged in + #'vl/vl_bitstream_parser.c', + #'vl/vl_mpeg12_mc_renderer.c', + #'vl/vl_compositor.c', + #'vl/vl_csc.c', + #'vl/vl_shader_build.c', +] + +if env['llvm']: + if env['UDIS86']: + env.Append(CPPDEFINES = [('HAVE_UDIS86', '1')]) + + source += [ + 'gallivm/lp_bld_arit.c', + 'gallivm/lp_bld_assert.c', + 'gallivm/lp_bld_bitarit.c', + 'gallivm/lp_bld_const.c', + 'gallivm/lp_bld_conv.c', + 'gallivm/lp_bld_debug.c', + 'gallivm/lp_bld_flow.c', + 'gallivm/lp_bld_format_aos.c', + 'gallivm/lp_bld_format_soa.c', + 'gallivm/lp_bld_format_yuv.c', + 'gallivm/lp_bld_gather.c', + 'gallivm/lp_bld_init.c', + 'gallivm/lp_bld_intr.c', + 'gallivm/lp_bld_logic.c', + 'gallivm/lp_bld_misc.cpp', + 'gallivm/lp_bld_pack.c', + 'gallivm/lp_bld_printf.c', + 'gallivm/lp_bld_quad.c', + 'gallivm/lp_bld_sample.c', + 'gallivm/lp_bld_sample_aos.c', + 'gallivm/lp_bld_sample_soa.c', + 'gallivm/lp_bld_struct.c', + 'gallivm/lp_bld_swizzle.c', + 'gallivm/lp_bld_tgsi_aos.c', + 'gallivm/lp_bld_tgsi_info.c', + 'gallivm/lp_bld_tgsi_soa.c', + 'gallivm/lp_bld_type.c', + 'draw/draw_llvm.c', + 'draw/draw_llvm_sample.c', + 'draw/draw_llvm_translate.c', + 'draw/draw_pt_fetch_shade_pipeline_llvm.c', + 'draw/draw_vs_llvm.c' + ] + +gallium = env.ConvenienceLibrary( + target = 'gallium', + source = source, +) + +env.Alias('gallium', gallium) + +Export('gallium') diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.c b/src/gallium/auxiliary/cso_cache/cso_cache.c new file mode 100644 index 0000000..900c64d --- /dev/null +++ b/src/gallium/auxiliary/cso_cache/cso_cache.c @@ -0,0 +1,410 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Zack Rusin + */ + +#include "util/u_debug.h" + +#include "util/u_memory.h" + +#include "cso_cache.h" +#include "cso_hash.h" + + +struct cso_cache { + struct cso_hash *blend_hash; + struct cso_hash *depth_stencil_hash; + struct cso_hash *fs_hash; + struct cso_hash *vs_hash; + struct cso_hash *rasterizer_hash; + struct cso_hash *sampler_hash; + struct cso_hash *velements_hash; + int max_size; + + cso_sanitize_callback sanitize_cb; + void *sanitize_data; +}; + +#if 1 +static unsigned hash_key(const void *key, unsigned key_size) +{ + unsigned *ikey = (unsigned *)key; + unsigned hash = 0, i; + + assert(key_size % 4 == 0); + + /* I'm sure this can be improved on: + */ + for (i = 0; i < key_size/4; i++) + hash ^= ikey[i]; + + return hash; +} +#else +static unsigned hash_key(const unsigned char *p, int n) +{ + unsigned h = 0; + unsigned g; + + while (n--) { + h = (h << 4) + *p++; + if ((g = (h & 0xf0000000)) != 0) + h ^= g >> 23; + h &= ~g; + } + return h; +} +#endif + +unsigned cso_construct_key(void *item, int item_size) +{ + return hash_key((item), item_size); +} + +static struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_type type) +{ + struct cso_hash *hash = 0; + + switch(type) { + case CSO_BLEND: + hash = sc->blend_hash; + break; + case CSO_SAMPLER: + hash = sc->sampler_hash; + break; + case CSO_DEPTH_STENCIL_ALPHA: + hash = sc->depth_stencil_hash; + break; + case CSO_RASTERIZER: + hash = sc->rasterizer_hash; + break; + case CSO_FRAGMENT_SHADER: + hash = sc->fs_hash; + break; + case CSO_VERTEX_SHADER: + hash = sc->vs_hash; + break; + case CSO_VELEMENTS: + hash = sc->velements_hash; + break; + } + + return hash; +} + +static void delete_blend_state(void *state, void *data) +{ + struct cso_blend *cso = (struct cso_blend *)state; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); +} + +static void delete_depth_stencil_state(void *state, void *data) +{ + struct cso_depth_stencil_alpha *cso = (struct cso_depth_stencil_alpha *)state; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); +} + +static void delete_sampler_state(void *state, void *data) +{ + struct cso_sampler *cso = (struct cso_sampler *)state; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); +} + +static void delete_rasterizer_state(void *state, void *data) +{ + struct cso_rasterizer *cso = (struct cso_rasterizer *)state; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); +} + +static void delete_fs_state(void *state, void *data) +{ + struct cso_fragment_shader *cso = (struct cso_fragment_shader *)state; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); +} + +static void delete_vs_state(void *state, void *data) +{ + struct cso_vertex_shader *cso = (struct cso_vertex_shader *)state; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); +} + +static void delete_velements(void *state, void *data) +{ + struct cso_velements *cso = (struct cso_velements *)state; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); +} + +static INLINE void delete_cso(void *state, enum cso_cache_type type) +{ + switch (type) { + case CSO_BLEND: + delete_blend_state(state, 0); + break; + case CSO_SAMPLER: + delete_sampler_state(state, 0); + break; + case CSO_DEPTH_STENCIL_ALPHA: + delete_depth_stencil_state(state, 0); + break; + case CSO_RASTERIZER: + delete_rasterizer_state(state, 0); + break; + case CSO_FRAGMENT_SHADER: + delete_fs_state(state, 0); + break; + case CSO_VERTEX_SHADER: + delete_vs_state(state, 0); + break; + case CSO_VELEMENTS: + delete_velements(state, 0); + break; + default: + assert(0); + FREE(state); + } +} + + +static INLINE void sanitize_hash(struct cso_cache *sc, + struct cso_hash *hash, + enum cso_cache_type type, + int max_size) +{ + if (sc->sanitize_cb) + sc->sanitize_cb(hash, type, max_size, sc->sanitize_data); +} + + +static INLINE void sanitize_cb(struct cso_hash *hash, enum cso_cache_type type, + int max_size, void *user_data) +{ + /* if we're approach the maximum size, remove fourth of the entries + * otherwise every subsequent call will go through the same */ + int hash_size = cso_hash_size(hash); + int max_entries = (max_size > hash_size) ? max_size : hash_size; + int to_remove = (max_size < max_entries) * max_entries/4; + if (hash_size > max_size) + to_remove += hash_size - max_size; + while (to_remove) { + /*remove elements until we're good */ + /*fixme: currently we pick the nodes to remove at random*/ + struct cso_hash_iter iter = cso_hash_first_node(hash); + void *cso = cso_hash_take(hash, cso_hash_iter_key(iter)); + delete_cso(cso, type); + --to_remove; + } +} + +struct cso_hash_iter +cso_insert_state(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type, + void *state) +{ + struct cso_hash *hash = _cso_hash_for_type(sc, type); + sanitize_hash(sc, hash, type, sc->max_size); + + return cso_hash_insert(hash, hash_key, state); +} + +struct cso_hash_iter +cso_find_state(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type) +{ + struct cso_hash *hash = _cso_hash_for_type(sc, type); + + return cso_hash_find(hash, hash_key); +} + + +void *cso_hash_find_data_from_template( struct cso_hash *hash, + unsigned hash_key, + void *templ, + int size ) +{ + struct cso_hash_iter iter = cso_hash_find(hash, hash_key); + while (!cso_hash_iter_is_null(iter)) { + void *iter_data = cso_hash_iter_data(iter); + if (!memcmp(iter_data, templ, size)) { + /* We found a match + */ + return iter_data; + } + iter = cso_hash_iter_next(iter); + } + return NULL; +} + + +struct cso_hash_iter cso_find_state_template(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type, + void *templ, unsigned size) +{ + struct cso_hash_iter iter = cso_find_state(sc, hash_key, type); + while (!cso_hash_iter_is_null(iter)) { + void *iter_data = cso_hash_iter_data(iter); + if (!memcmp(iter_data, templ, size)) + return iter; + iter = cso_hash_iter_next(iter); + } + return iter; +} + +void * cso_take_state(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type) +{ + struct cso_hash *hash = _cso_hash_for_type(sc, type); + return cso_hash_take(hash, hash_key); +} + +struct cso_cache *cso_cache_create(void) +{ + struct cso_cache *sc = MALLOC_STRUCT(cso_cache); + if (sc == NULL) + return NULL; + + sc->max_size = 4096; + sc->blend_hash = cso_hash_create(); + sc->sampler_hash = cso_hash_create(); + sc->depth_stencil_hash = cso_hash_create(); + sc->rasterizer_hash = cso_hash_create(); + sc->fs_hash = cso_hash_create(); + sc->vs_hash = cso_hash_create(); + sc->velements_hash = cso_hash_create(); + sc->sanitize_cb = sanitize_cb; + sc->sanitize_data = 0; + + return sc; +} + +void cso_for_each_state(struct cso_cache *sc, enum cso_cache_type type, + cso_state_callback func, void *user_data) +{ + struct cso_hash *hash = 0; + struct cso_hash_iter iter; + + switch (type) { + case CSO_BLEND: + hash = sc->blend_hash; + break; + case CSO_SAMPLER: + hash = sc->sampler_hash; + break; + case CSO_DEPTH_STENCIL_ALPHA: + hash = sc->depth_stencil_hash; + break; + case CSO_RASTERIZER: + hash = sc->rasterizer_hash; + break; + case CSO_FRAGMENT_SHADER: + hash = sc->fs_hash; + break; + case CSO_VERTEX_SHADER: + hash = sc->vs_hash; + break; + case CSO_VELEMENTS: + hash = sc->velements_hash; + break; + } + + iter = cso_hash_first_node(hash); + while (!cso_hash_iter_is_null(iter)) { + void *state = cso_hash_iter_data(iter); + iter = cso_hash_iter_next(iter); + if (state) { + func(state, user_data); + } + } +} + +void cso_cache_delete(struct cso_cache *sc) +{ + assert(sc); + + if (!sc) + return; + + /* delete driver data */ + cso_for_each_state(sc, CSO_BLEND, delete_blend_state, 0); + cso_for_each_state(sc, CSO_DEPTH_STENCIL_ALPHA, delete_depth_stencil_state, 0); + cso_for_each_state(sc, CSO_FRAGMENT_SHADER, delete_fs_state, 0); + cso_for_each_state(sc, CSO_VERTEX_SHADER, delete_vs_state, 0); + cso_for_each_state(sc, CSO_RASTERIZER, delete_rasterizer_state, 0); + cso_for_each_state(sc, CSO_SAMPLER, delete_sampler_state, 0); + cso_for_each_state(sc, CSO_VELEMENTS, delete_velements, 0); + + cso_hash_delete(sc->blend_hash); + cso_hash_delete(sc->sampler_hash); + cso_hash_delete(sc->depth_stencil_hash); + cso_hash_delete(sc->rasterizer_hash); + cso_hash_delete(sc->fs_hash); + cso_hash_delete(sc->vs_hash); + cso_hash_delete(sc->velements_hash); + FREE(sc); +} + +void cso_set_maximum_cache_size(struct cso_cache *sc, int number) +{ + sc->max_size = number; + + sanitize_hash(sc, sc->blend_hash, CSO_BLEND, sc->max_size); + sanitize_hash(sc, sc->depth_stencil_hash, CSO_DEPTH_STENCIL_ALPHA, + sc->max_size); + sanitize_hash(sc, sc->fs_hash, CSO_FRAGMENT_SHADER, sc->max_size); + sanitize_hash(sc, sc->vs_hash, CSO_VERTEX_SHADER, sc->max_size); + sanitize_hash(sc, sc->rasterizer_hash, CSO_RASTERIZER, sc->max_size); + sanitize_hash(sc, sc->sampler_hash, CSO_SAMPLER, sc->max_size); + sanitize_hash(sc, sc->velements_hash, CSO_VELEMENTS, sc->max_size); +} + +int cso_maximum_cache_size(const struct cso_cache *sc) +{ + return sc->max_size; +} + +void cso_cache_set_sanitize_callback(struct cso_cache *sc, + cso_sanitize_callback cb, + void *user_data) +{ + sc->sanitize_cb = cb; + sc->sanitize_data = user_data; +} + diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.h b/src/gallium/auxiliary/cso_cache/cso_cache.h new file mode 100644 index 0000000..fb09b83 --- /dev/null +++ b/src/gallium/auxiliary/cso_cache/cso_cache.h @@ -0,0 +1,190 @@ +/************************************************************************** + * + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /** + * @file + * Constant State Object (CSO) cache. + * + * The basic idea is that the states are created via the + * create_state/bind_state/delete_state semantics. The driver is expected to + * perform as much of the Gallium state translation to whatever its internal + * representation is during the create call. Gallium then has a caching + * mechanism where it stores the created states. When the pipeline needs an + * actual state change, a bind call is issued. In the bind call the driver + * gets its already translated representation. + * + * Those semantics mean that the driver doesn't do the repeated translations + * of states on every frame, but only once, when a new state is actually + * created. + * + * Even on hardware that doesn't do any kind of state cache, it makes the + * driver look a lot neater, plus it avoids all the redundant state + * translations on every frame. + * + * Currently our constant state objects are: + * - alpha test + * - blend + * - depth stencil + * - fragment shader + * - rasterizer (old setup) + * - sampler + * - vertex shader + * - vertex elements + * + * Things that are not constant state objects include: + * - blend_color + * - clip_state + * - clear_color_state + * - constant_buffer + * - feedback_state + * - framebuffer_state + * - polygon_stipple + * - scissor_state + * - texture_state + * - viewport_state + * + * @author Zack Rusin + */ + +#ifndef CSO_CACHE_H +#define CSO_CACHE_H + +#include "pipe/p_context.h" +#include "pipe/p_state.h" + +/* cso_hash.h is necessary for cso_hash_iter, as MSVC requires structures + * returned by value to be fully defined */ +#include "cso_hash.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +enum cso_cache_type { + CSO_BLEND, + CSO_SAMPLER, + CSO_DEPTH_STENCIL_ALPHA, + CSO_RASTERIZER, + CSO_FRAGMENT_SHADER, + CSO_VERTEX_SHADER, + CSO_VELEMENTS +}; + +typedef void (*cso_state_callback)(void *ctx, void *obj); + +typedef void (*cso_sanitize_callback)(struct cso_hash *hash, + enum cso_cache_type type, + int max_size, + void *user_data); + +struct cso_cache; + +struct cso_blend { + struct pipe_blend_state state; + void *data; + cso_state_callback delete_state; + struct pipe_context *context; +}; + +struct cso_depth_stencil_alpha { + struct pipe_depth_stencil_alpha_state state; + void *data; + cso_state_callback delete_state; + struct pipe_context *context; +}; + +struct cso_rasterizer { + struct pipe_rasterizer_state state; + void *data; + cso_state_callback delete_state; + struct pipe_context *context; +}; + +struct cso_fragment_shader { + struct pipe_shader_state state; + void *data; + cso_state_callback delete_state; + struct pipe_context *context; +}; + +struct cso_vertex_shader { + struct pipe_shader_state state; + void *data; + cso_state_callback delete_state; + struct pipe_context *context; +}; + +struct cso_sampler { + struct pipe_sampler_state state; + void *data; + cso_state_callback delete_state; + struct pipe_context *context; +}; + +struct cso_velems_state { + unsigned count; + struct pipe_vertex_element velems[PIPE_MAX_ATTRIBS]; +}; + +struct cso_velements { + struct cso_velems_state state; + void *data; + cso_state_callback delete_state; + struct pipe_context *context; +}; + +unsigned cso_construct_key(void *item, int item_size); + +struct cso_cache *cso_cache_create(void); +void cso_cache_delete(struct cso_cache *sc); + +void cso_cache_set_sanitize_callback(struct cso_cache *sc, + cso_sanitize_callback cb, + void *user_data); + +struct cso_hash_iter cso_insert_state(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type, + void *state); +struct cso_hash_iter cso_find_state(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type); +struct cso_hash_iter cso_find_state_template(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type, + void *templ, unsigned size); +void cso_for_each_state(struct cso_cache *sc, enum cso_cache_type type, + cso_state_callback func, void *user_data); +void * cso_take_state(struct cso_cache *sc, unsigned hash_key, + enum cso_cache_type type); + +void cso_set_maximum_cache_size(struct cso_cache *sc, int number); +int cso_maximum_cache_size(const struct cso_cache *sc); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c new file mode 100644 index 0000000..b983fa6 --- /dev/null +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -0,0 +1,1263 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /** + * @file + * + * Wrap the cso cache & hash mechanisms in a simplified + * pipe-driver-specific interface. + * + * @author Zack Rusin + * @author Keith Whitwell + */ + +#include "pipe/p_state.h" +#include "util/u_framebuffer.h" +#include "util/u_inlines.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "tgsi/tgsi_parse.h" + +#include "cso_cache/cso_context.h" +#include "cso_cache/cso_cache.h" +#include "cso_cache/cso_hash.h" +#include "cso_context.h" + +struct cso_context { + struct pipe_context *pipe; + struct cso_cache *cache; + + struct { + void *samplers[PIPE_MAX_SAMPLERS]; + unsigned nr_samplers; + + void *vertex_samplers[PIPE_MAX_VERTEX_SAMPLERS]; + unsigned nr_vertex_samplers; + } hw; + + void *samplers[PIPE_MAX_SAMPLERS]; + unsigned nr_samplers; + + void *vertex_samplers[PIPE_MAX_VERTEX_SAMPLERS]; + unsigned nr_vertex_samplers; + + unsigned nr_samplers_saved; + void *samplers_saved[PIPE_MAX_SAMPLERS]; + + unsigned nr_vertex_samplers_saved; + void *vertex_samplers_saved[PIPE_MAX_VERTEX_SAMPLERS]; + + uint nr_fragment_sampler_views; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; + + uint nr_vertex_sampler_views; + struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; + + uint nr_fragment_sampler_views_saved; + struct pipe_sampler_view *fragment_sampler_views_saved[PIPE_MAX_SAMPLERS]; + + uint nr_vertex_sampler_views_saved; + struct pipe_sampler_view *vertex_sampler_views_saved[PIPE_MAX_VERTEX_SAMPLERS]; + + /** Current and saved state. + * The saved state is used as a 1-deep stack. + */ + void *blend, *blend_saved; + void *depth_stencil, *depth_stencil_saved; + void *rasterizer, *rasterizer_saved; + void *fragment_shader, *fragment_shader_saved, *geometry_shader; + void *vertex_shader, *vertex_shader_saved, *geometry_shader_saved; + void *velements, *velements_saved; + + struct pipe_clip_state clip; + struct pipe_clip_state clip_saved; + + struct pipe_framebuffer_state fb, fb_saved; + struct pipe_viewport_state vp, vp_saved; + struct pipe_blend_color blend_color; + unsigned sample_mask; + struct pipe_stencil_ref stencil_ref, stencil_ref_saved; +}; + + +static boolean delete_blend_state(struct cso_context *ctx, void *state) +{ + struct cso_blend *cso = (struct cso_blend *)state; + + if (ctx->blend == cso->data) + return FALSE; + + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); + return TRUE; +} + +static boolean delete_depth_stencil_state(struct cso_context *ctx, void *state) +{ + struct cso_depth_stencil_alpha *cso = (struct cso_depth_stencil_alpha *)state; + + if (ctx->depth_stencil == cso->data) + return FALSE; + + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); + + return TRUE; +} + +static boolean delete_sampler_state(struct cso_context *ctx, void *state) +{ + struct cso_sampler *cso = (struct cso_sampler *)state; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); + return TRUE; +} + +static boolean delete_rasterizer_state(struct cso_context *ctx, void *state) +{ + struct cso_rasterizer *cso = (struct cso_rasterizer *)state; + + if (ctx->rasterizer == cso->data) + return FALSE; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); + return TRUE; +} + +static boolean delete_fs_state(struct cso_context *ctx, void *state) +{ + struct cso_fragment_shader *cso = (struct cso_fragment_shader *)state; + if (ctx->fragment_shader == cso->data) + return FALSE; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); + return TRUE; +} + +static boolean delete_vs_state(struct cso_context *ctx, void *state) +{ + struct cso_vertex_shader *cso = (struct cso_vertex_shader *)state; + if (ctx->vertex_shader == cso->data) + return TRUE; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); + return FALSE; +} + +static boolean delete_vertex_elements(struct cso_context *ctx, + void *state) +{ + struct cso_velements *cso = (struct cso_velements *)state; + + if (ctx->velements == cso->data) + return FALSE; + + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); + return TRUE; +} + + +static INLINE boolean delete_cso(struct cso_context *ctx, + void *state, enum cso_cache_type type) +{ + switch (type) { + case CSO_BLEND: + return delete_blend_state(ctx, state); + break; + case CSO_SAMPLER: + return delete_sampler_state(ctx, state); + break; + case CSO_DEPTH_STENCIL_ALPHA: + return delete_depth_stencil_state(ctx, state); + break; + case CSO_RASTERIZER: + return delete_rasterizer_state(ctx, state); + break; + case CSO_FRAGMENT_SHADER: + return delete_fs_state(ctx, state); + break; + case CSO_VERTEX_SHADER: + return delete_vs_state(ctx, state); + break; + case CSO_VELEMENTS: + return delete_vertex_elements(ctx, state); + break; + default: + assert(0); + FREE(state); + } + return FALSE; +} + +static INLINE void sanitize_hash(struct cso_hash *hash, enum cso_cache_type type, + int max_size, void *user_data) +{ + struct cso_context *ctx = (struct cso_context *)user_data; + /* if we're approach the maximum size, remove fourth of the entries + * otherwise every subsequent call will go through the same */ + int hash_size = cso_hash_size(hash); + int max_entries = (max_size > hash_size) ? max_size : hash_size; + int to_remove = (max_size < max_entries) * max_entries/4; + struct cso_hash_iter iter = cso_hash_first_node(hash); + if (hash_size > max_size) + to_remove += hash_size - max_size; + while (to_remove) { + /*remove elements until we're good */ + /*fixme: currently we pick the nodes to remove at random*/ + void *cso = cso_hash_iter_data(iter); + if (delete_cso(ctx, cso, type)) { + iter = cso_hash_erase(hash, iter); + --to_remove; + } else + iter = cso_hash_iter_next(iter); + } +} + + +struct cso_context *cso_create_context( struct pipe_context *pipe ) +{ + struct cso_context *ctx = CALLOC_STRUCT(cso_context); + if (ctx == NULL) + goto out; + + ctx->cache = cso_cache_create(); + if (ctx->cache == NULL) + goto out; + cso_cache_set_sanitize_callback(ctx->cache, + sanitize_hash, + ctx); + + ctx->pipe = pipe; + + /* Enable for testing: */ + if (0) cso_set_maximum_cache_size( ctx->cache, 4 ); + + return ctx; + +out: + cso_destroy_context( ctx ); + return NULL; +} + + +/** + * Prior to context destruction, this function unbinds all state objects. + */ +void cso_release_all( struct cso_context *ctx ) +{ + unsigned i; + + if (ctx->pipe) { + ctx->pipe->bind_blend_state( ctx->pipe, NULL ); + ctx->pipe->bind_rasterizer_state( ctx->pipe, NULL ); + ctx->pipe->bind_fragment_sampler_states( ctx->pipe, 0, NULL ); + if (ctx->pipe->bind_vertex_sampler_states) + ctx->pipe->bind_vertex_sampler_states(ctx->pipe, 0, NULL); + ctx->pipe->bind_depth_stencil_alpha_state( ctx->pipe, NULL ); + ctx->pipe->bind_fs_state( ctx->pipe, NULL ); + ctx->pipe->bind_vs_state( ctx->pipe, NULL ); + ctx->pipe->bind_vertex_elements_state( ctx->pipe, NULL ); + ctx->pipe->set_fragment_sampler_views(ctx->pipe, 0, NULL); + if (ctx->pipe->set_vertex_sampler_views) + ctx->pipe->set_vertex_sampler_views(ctx->pipe, 0, NULL); + } + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL); + pipe_sampler_view_reference(&ctx->fragment_sampler_views_saved[i], NULL); + } + + for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { + pipe_sampler_view_reference(&ctx->vertex_sampler_views[i], NULL); + pipe_sampler_view_reference(&ctx->vertex_sampler_views_saved[i], NULL); + } + + util_unreference_framebuffer_state(&ctx->fb); + util_unreference_framebuffer_state(&ctx->fb_saved); + + if (ctx->cache) { + cso_cache_delete( ctx->cache ); + ctx->cache = NULL; + } +} + + +/** + * Free the CSO context. NOTE: the state tracker should have previously called + * cso_release_all(). + */ +void cso_destroy_context( struct cso_context *ctx ) +{ + if (ctx) { + FREE( ctx ); + } +} + + +/* Those function will either find the state of the given template + * in the cache or they will create a new state from the given + * template, insert it in the cache and return it. + */ + +/* + * If the driver returns 0 from the create method then they will assign + * the data member of the cso to be the template itself. + */ + +enum pipe_error cso_set_blend(struct cso_context *ctx, + const struct pipe_blend_state *templ) +{ + unsigned key_size, hash_key; + struct cso_hash_iter iter; + void *handle; + + key_size = templ->independent_blend_enable ? sizeof(struct pipe_blend_state) : + (char *)&(templ->rt[1]) - (char *)templ; + hash_key = cso_construct_key((void*)templ, key_size); + iter = cso_find_state_template(ctx->cache, hash_key, CSO_BLEND, (void*)templ, key_size); + + if (cso_hash_iter_is_null(iter)) { + struct cso_blend *cso = MALLOC(sizeof(struct cso_blend)); + if (!cso) + return PIPE_ERROR_OUT_OF_MEMORY; + + memset(&cso->state, 0, sizeof cso->state); + memcpy(&cso->state, templ, key_size); + cso->data = ctx->pipe->create_blend_state(ctx->pipe, &cso->state); + cso->delete_state = (cso_state_callback)ctx->pipe->delete_blend_state; + cso->context = ctx->pipe; + + iter = cso_insert_state(ctx->cache, hash_key, CSO_BLEND, cso); + if (cso_hash_iter_is_null(iter)) { + FREE(cso); + return PIPE_ERROR_OUT_OF_MEMORY; + } + + handle = cso->data; + } + else { + handle = ((struct cso_blend *)cso_hash_iter_data(iter))->data; + } + + if (ctx->blend != handle) { + ctx->blend = handle; + ctx->pipe->bind_blend_state(ctx->pipe, handle); + } + return PIPE_OK; +} + +void cso_save_blend(struct cso_context *ctx) +{ + assert(!ctx->blend_saved); + ctx->blend_saved = ctx->blend; +} + +void cso_restore_blend(struct cso_context *ctx) +{ + if (ctx->blend != ctx->blend_saved) { + ctx->blend = ctx->blend_saved; + ctx->pipe->bind_blend_state(ctx->pipe, ctx->blend_saved); + } + ctx->blend_saved = NULL; +} + + + +enum pipe_error cso_single_sampler(struct cso_context *ctx, + unsigned idx, + const struct pipe_sampler_state *templ) +{ + void *handle = NULL; + + if (templ != NULL) { + unsigned key_size = sizeof(struct pipe_sampler_state); + unsigned hash_key = cso_construct_key((void*)templ, key_size); + struct cso_hash_iter iter = cso_find_state_template(ctx->cache, + hash_key, CSO_SAMPLER, + (void*)templ, key_size); + + if (cso_hash_iter_is_null(iter)) { + struct cso_sampler *cso = MALLOC(sizeof(struct cso_sampler)); + if (!cso) + return PIPE_ERROR_OUT_OF_MEMORY; + + memcpy(&cso->state, templ, sizeof(*templ)); + cso->data = ctx->pipe->create_sampler_state(ctx->pipe, &cso->state); + cso->delete_state = (cso_state_callback)ctx->pipe->delete_sampler_state; + cso->context = ctx->pipe; + + iter = cso_insert_state(ctx->cache, hash_key, CSO_SAMPLER, cso); + if (cso_hash_iter_is_null(iter)) { + FREE(cso); + return PIPE_ERROR_OUT_OF_MEMORY; + } + + handle = cso->data; + } + else { + handle = ((struct cso_sampler *)cso_hash_iter_data(iter))->data; + } + } + + ctx->samplers[idx] = handle; + return PIPE_OK; +} + +enum pipe_error +cso_single_vertex_sampler(struct cso_context *ctx, + unsigned idx, + const struct pipe_sampler_state *templ) +{ + void *handle = NULL; + + if (templ != NULL) { + unsigned key_size = sizeof(struct pipe_sampler_state); + unsigned hash_key = cso_construct_key((void*)templ, key_size); + struct cso_hash_iter iter = cso_find_state_template(ctx->cache, + hash_key, CSO_SAMPLER, + (void*)templ, key_size); + + if (cso_hash_iter_is_null(iter)) { + struct cso_sampler *cso = MALLOC(sizeof(struct cso_sampler)); + if (!cso) + return PIPE_ERROR_OUT_OF_MEMORY; + + memcpy(&cso->state, templ, sizeof(*templ)); + cso->data = ctx->pipe->create_sampler_state(ctx->pipe, &cso->state); + cso->delete_state = (cso_state_callback)ctx->pipe->delete_sampler_state; + cso->context = ctx->pipe; + + iter = cso_insert_state(ctx->cache, hash_key, CSO_SAMPLER, cso); + if (cso_hash_iter_is_null(iter)) { + FREE(cso); + return PIPE_ERROR_OUT_OF_MEMORY; + } + + handle = cso->data; + } + else { + handle = ((struct cso_sampler *)cso_hash_iter_data(iter))->data; + } + } + + ctx->vertex_samplers[idx] = handle; + return PIPE_OK; +} + +void cso_single_sampler_done( struct cso_context *ctx ) +{ + unsigned i; + + /* find highest non-null sampler */ + for (i = PIPE_MAX_SAMPLERS; i > 0; i--) { + if (ctx->samplers[i - 1] != NULL) + break; + } + + ctx->nr_samplers = i; + + if (ctx->hw.nr_samplers != ctx->nr_samplers || + memcmp(ctx->hw.samplers, + ctx->samplers, + ctx->nr_samplers * sizeof(void *)) != 0) + { + memcpy(ctx->hw.samplers, ctx->samplers, ctx->nr_samplers * sizeof(void *)); + ctx->hw.nr_samplers = ctx->nr_samplers; + + ctx->pipe->bind_fragment_sampler_states(ctx->pipe, ctx->nr_samplers, ctx->samplers); + } +} + +void +cso_single_vertex_sampler_done(struct cso_context *ctx) +{ + unsigned i; + + /* find highest non-null sampler */ + for (i = PIPE_MAX_VERTEX_SAMPLERS; i > 0; i--) { + if (ctx->vertex_samplers[i - 1] != NULL) + break; + } + + ctx->nr_vertex_samplers = i; + + if (ctx->hw.nr_vertex_samplers != ctx->nr_vertex_samplers || + memcmp(ctx->hw.vertex_samplers, + ctx->vertex_samplers, + ctx->nr_vertex_samplers * sizeof(void *)) != 0) + { + memcpy(ctx->hw.vertex_samplers, + ctx->vertex_samplers, + ctx->nr_vertex_samplers * sizeof(void *)); + ctx->hw.nr_vertex_samplers = ctx->nr_vertex_samplers; + + ctx->pipe->bind_vertex_sampler_states(ctx->pipe, + ctx->nr_vertex_samplers, + ctx->vertex_samplers); + } +} + +/* + * If the function encouters any errors it will return the + * last one. Done to always try to set as many samplers + * as possible. + */ +enum pipe_error cso_set_samplers( struct cso_context *ctx, + unsigned nr, + const struct pipe_sampler_state **templates ) +{ + unsigned i; + enum pipe_error temp, error = PIPE_OK; + + /* TODO: fastpath + */ + + for (i = 0; i < nr; i++) { + temp = cso_single_sampler( ctx, i, templates[i] ); + if (temp != PIPE_OK) + error = temp; + } + + for ( ; i < ctx->nr_samplers; i++) { + temp = cso_single_sampler( ctx, i, NULL ); + if (temp != PIPE_OK) + error = temp; + } + + cso_single_sampler_done( ctx ); + + return error; +} + +void cso_save_samplers(struct cso_context *ctx) +{ + ctx->nr_samplers_saved = ctx->nr_samplers; + memcpy(ctx->samplers_saved, ctx->samplers, sizeof(ctx->samplers)); +} + +void cso_restore_samplers(struct cso_context *ctx) +{ + ctx->nr_samplers = ctx->nr_samplers_saved; + memcpy(ctx->samplers, ctx->samplers_saved, sizeof(ctx->samplers)); + cso_single_sampler_done( ctx ); +} + +/* + * If the function encouters any errors it will return the + * last one. Done to always try to set as many samplers + * as possible. + */ +enum pipe_error cso_set_vertex_samplers(struct cso_context *ctx, + unsigned nr, + const struct pipe_sampler_state **templates) +{ + unsigned i; + enum pipe_error temp, error = PIPE_OK; + + /* TODO: fastpath + */ + + for (i = 0; i < nr; i++) { + temp = cso_single_vertex_sampler( ctx, i, templates[i] ); + if (temp != PIPE_OK) + error = temp; + } + + for ( ; i < ctx->nr_vertex_samplers; i++) { + temp = cso_single_vertex_sampler( ctx, i, NULL ); + if (temp != PIPE_OK) + error = temp; + } + + cso_single_vertex_sampler_done( ctx ); + + return error; +} + +void +cso_save_vertex_samplers(struct cso_context *ctx) +{ + ctx->nr_vertex_samplers_saved = ctx->nr_vertex_samplers; + memcpy(ctx->vertex_samplers_saved, ctx->vertex_samplers, sizeof(ctx->vertex_samplers)); +} + +void +cso_restore_vertex_samplers(struct cso_context *ctx) +{ + ctx->nr_vertex_samplers = ctx->nr_vertex_samplers_saved; + memcpy(ctx->vertex_samplers, ctx->vertex_samplers_saved, sizeof(ctx->vertex_samplers)); + cso_single_vertex_sampler_done(ctx); +} + + +enum pipe_error cso_set_depth_stencil_alpha(struct cso_context *ctx, + const struct pipe_depth_stencil_alpha_state *templ) +{ + unsigned key_size = sizeof(struct pipe_depth_stencil_alpha_state); + unsigned hash_key = cso_construct_key((void*)templ, key_size); + struct cso_hash_iter iter = cso_find_state_template(ctx->cache, + hash_key, + CSO_DEPTH_STENCIL_ALPHA, + (void*)templ, key_size); + void *handle; + + if (cso_hash_iter_is_null(iter)) { + struct cso_depth_stencil_alpha *cso = MALLOC(sizeof(struct cso_depth_stencil_alpha)); + if (!cso) + return PIPE_ERROR_OUT_OF_MEMORY; + + memcpy(&cso->state, templ, sizeof(*templ)); + cso->data = ctx->pipe->create_depth_stencil_alpha_state(ctx->pipe, &cso->state); + cso->delete_state = (cso_state_callback)ctx->pipe->delete_depth_stencil_alpha_state; + cso->context = ctx->pipe; + + iter = cso_insert_state(ctx->cache, hash_key, CSO_DEPTH_STENCIL_ALPHA, cso); + if (cso_hash_iter_is_null(iter)) { + FREE(cso); + return PIPE_ERROR_OUT_OF_MEMORY; + } + + handle = cso->data; + } + else { + handle = ((struct cso_depth_stencil_alpha *)cso_hash_iter_data(iter))->data; + } + + if (ctx->depth_stencil != handle) { + ctx->depth_stencil = handle; + ctx->pipe->bind_depth_stencil_alpha_state(ctx->pipe, handle); + } + return PIPE_OK; +} + +void cso_save_depth_stencil_alpha(struct cso_context *ctx) +{ + assert(!ctx->depth_stencil_saved); + ctx->depth_stencil_saved = ctx->depth_stencil; +} + +void cso_restore_depth_stencil_alpha(struct cso_context *ctx) +{ + if (ctx->depth_stencil != ctx->depth_stencil_saved) { + ctx->depth_stencil = ctx->depth_stencil_saved; + ctx->pipe->bind_depth_stencil_alpha_state(ctx->pipe, ctx->depth_stencil_saved); + } + ctx->depth_stencil_saved = NULL; +} + + + +enum pipe_error cso_set_rasterizer(struct cso_context *ctx, + const struct pipe_rasterizer_state *templ) +{ + unsigned key_size = sizeof(struct pipe_rasterizer_state); + unsigned hash_key = cso_construct_key((void*)templ, key_size); + struct cso_hash_iter iter = cso_find_state_template(ctx->cache, + hash_key, CSO_RASTERIZER, + (void*)templ, key_size); + void *handle = NULL; + + if (cso_hash_iter_is_null(iter)) { + struct cso_rasterizer *cso = MALLOC(sizeof(struct cso_rasterizer)); + if (!cso) + return PIPE_ERROR_OUT_OF_MEMORY; + + memcpy(&cso->state, templ, sizeof(*templ)); + cso->data = ctx->pipe->create_rasterizer_state(ctx->pipe, &cso->state); + cso->delete_state = (cso_state_callback)ctx->pipe->delete_rasterizer_state; + cso->context = ctx->pipe; + + iter = cso_insert_state(ctx->cache, hash_key, CSO_RASTERIZER, cso); + if (cso_hash_iter_is_null(iter)) { + FREE(cso); + return PIPE_ERROR_OUT_OF_MEMORY; + } + + handle = cso->data; + } + else { + handle = ((struct cso_rasterizer *)cso_hash_iter_data(iter))->data; + } + + if (ctx->rasterizer != handle) { + ctx->rasterizer = handle; + ctx->pipe->bind_rasterizer_state(ctx->pipe, handle); + } + return PIPE_OK; +} + +void cso_save_rasterizer(struct cso_context *ctx) +{ + assert(!ctx->rasterizer_saved); + ctx->rasterizer_saved = ctx->rasterizer; +} + +void cso_restore_rasterizer(struct cso_context *ctx) +{ + if (ctx->rasterizer != ctx->rasterizer_saved) { + ctx->rasterizer = ctx->rasterizer_saved; + ctx->pipe->bind_rasterizer_state(ctx->pipe, ctx->rasterizer_saved); + } + ctx->rasterizer_saved = NULL; +} + + + +enum pipe_error cso_set_fragment_shader_handle(struct cso_context *ctx, + void *handle ) +{ + if (ctx->fragment_shader != handle) { + ctx->fragment_shader = handle; + ctx->pipe->bind_fs_state(ctx->pipe, handle); + } + return PIPE_OK; +} + +void cso_delete_fragment_shader(struct cso_context *ctx, void *handle ) +{ + if (handle == ctx->fragment_shader) { + /* unbind before deleting */ + ctx->pipe->bind_fs_state(ctx->pipe, NULL); + ctx->fragment_shader = NULL; + } + ctx->pipe->delete_fs_state(ctx->pipe, handle); +} + +/* Not really working: + */ +#if 0 +enum pipe_error cso_set_fragment_shader(struct cso_context *ctx, + const struct pipe_shader_state *templ) +{ + const struct tgsi_token *tokens = templ->tokens; + unsigned num_tokens = tgsi_num_tokens(tokens); + size_t tokens_size = num_tokens*sizeof(struct tgsi_token); + unsigned hash_key = cso_construct_key((void*)tokens, tokens_size); + struct cso_hash_iter iter = cso_find_state_template(ctx->cache, + hash_key, + CSO_FRAGMENT_SHADER, + (void*)tokens, + sizeof(*templ)); /* XXX correct? tokens_size? */ + void *handle = NULL; + + if (cso_hash_iter_is_null(iter)) { + struct cso_fragment_shader *cso = MALLOC(sizeof(struct cso_fragment_shader) + tokens_size); + struct tgsi_token *cso_tokens = (struct tgsi_token *)((char *)cso + sizeof(*cso)); + + if (!cso) + return PIPE_ERROR_OUT_OF_MEMORY; + + memcpy(cso_tokens, tokens, tokens_size); + cso->state.tokens = cso_tokens; + cso->data = ctx->pipe->create_fs_state(ctx->pipe, &cso->state); + cso->delete_state = (cso_state_callback)ctx->pipe->delete_fs_state; + cso->context = ctx->pipe; + + iter = cso_insert_state(ctx->cache, hash_key, CSO_FRAGMENT_SHADER, cso); + if (cso_hash_iter_is_null(iter)) { + FREE(cso); + return PIPE_ERROR_OUT_OF_MEMORY; + } + + handle = cso->data; + } + else { + handle = ((struct cso_fragment_shader *)cso_hash_iter_data(iter))->data; + } + + return cso_set_fragment_shader_handle( ctx, handle ); +} +#endif + +void cso_save_fragment_shader(struct cso_context *ctx) +{ + assert(!ctx->fragment_shader_saved); + ctx->fragment_shader_saved = ctx->fragment_shader; +} + +void cso_restore_fragment_shader(struct cso_context *ctx) +{ + if (ctx->fragment_shader_saved != ctx->fragment_shader) { + ctx->pipe->bind_fs_state(ctx->pipe, ctx->fragment_shader_saved); + ctx->fragment_shader = ctx->fragment_shader_saved; + } + ctx->fragment_shader_saved = NULL; +} + + +enum pipe_error cso_set_vertex_shader_handle(struct cso_context *ctx, + void *handle ) +{ + if (ctx->vertex_shader != handle) { + ctx->vertex_shader = handle; + ctx->pipe->bind_vs_state(ctx->pipe, handle); + } + return PIPE_OK; +} + +void cso_delete_vertex_shader(struct cso_context *ctx, void *handle ) +{ + if (handle == ctx->vertex_shader) { + /* unbind before deleting */ + ctx->pipe->bind_vs_state(ctx->pipe, NULL); + ctx->vertex_shader = NULL; + } + ctx->pipe->delete_vs_state(ctx->pipe, handle); +} + + +/* Not really working: + */ +#if 0 +enum pipe_error cso_set_vertex_shader(struct cso_context *ctx, + const struct pipe_shader_state *templ) +{ + unsigned hash_key = cso_construct_key((void*)templ, + sizeof(struct pipe_shader_state)); + struct cso_hash_iter iter = cso_find_state_template(ctx->cache, + hash_key, CSO_VERTEX_SHADER, + (void*)templ, + sizeof(*templ)); + void *handle = NULL; + + if (cso_hash_iter_is_null(iter)) { + struct cso_vertex_shader *cso = MALLOC(sizeof(struct cso_vertex_shader)); + + if (!cso) + return PIPE_ERROR_OUT_OF_MEMORY; + + memcpy(cso->state, templ, sizeof(*templ)); + cso->data = ctx->pipe->create_vs_state(ctx->pipe, &cso->state); + cso->delete_state = (cso_state_callback)ctx->pipe->delete_vs_state; + cso->context = ctx->pipe; + + iter = cso_insert_state(ctx->cache, hash_key, CSO_VERTEX_SHADER, cso); + if (cso_hash_iter_is_null(iter)) { + FREE(cso); + return PIPE_ERROR_OUT_OF_MEMORY; + } + + handle = cso->data; + } + else { + handle = ((struct cso_vertex_shader *)cso_hash_iter_data(iter))->data; + } + + return cso_set_vertex_shader_handle( ctx, handle ); +} +#endif + + + +void cso_save_vertex_shader(struct cso_context *ctx) +{ + assert(!ctx->vertex_shader_saved); + ctx->vertex_shader_saved = ctx->vertex_shader; +} + +void cso_restore_vertex_shader(struct cso_context *ctx) +{ + if (ctx->vertex_shader_saved != ctx->vertex_shader) { + ctx->pipe->bind_vs_state(ctx->pipe, ctx->vertex_shader_saved); + ctx->vertex_shader = ctx->vertex_shader_saved; + } + ctx->vertex_shader_saved = NULL; +} + + +enum pipe_error cso_set_framebuffer(struct cso_context *ctx, + const struct pipe_framebuffer_state *fb) +{ + if (memcmp(&ctx->fb, fb, sizeof(*fb)) != 0) { + util_copy_framebuffer_state(&ctx->fb, fb); + ctx->pipe->set_framebuffer_state(ctx->pipe, fb); + } + return PIPE_OK; +} + +void cso_save_framebuffer(struct cso_context *ctx) +{ + util_copy_framebuffer_state(&ctx->fb_saved, &ctx->fb); +} + +void cso_restore_framebuffer(struct cso_context *ctx) +{ + if (memcmp(&ctx->fb, &ctx->fb_saved, sizeof(ctx->fb))) { + util_copy_framebuffer_state(&ctx->fb, &ctx->fb_saved); + ctx->pipe->set_framebuffer_state(ctx->pipe, &ctx->fb); + util_unreference_framebuffer_state(&ctx->fb_saved); + } +} + + +enum pipe_error cso_set_viewport(struct cso_context *ctx, + const struct pipe_viewport_state *vp) +{ + if (memcmp(&ctx->vp, vp, sizeof(*vp))) { + ctx->vp = *vp; + ctx->pipe->set_viewport_state(ctx->pipe, vp); + } + return PIPE_OK; +} + +void cso_save_viewport(struct cso_context *ctx) +{ + ctx->vp_saved = ctx->vp; +} + + +void cso_restore_viewport(struct cso_context *ctx) +{ + if (memcmp(&ctx->vp, &ctx->vp_saved, sizeof(ctx->vp))) { + ctx->vp = ctx->vp_saved; + ctx->pipe->set_viewport_state(ctx->pipe, &ctx->vp); + } +} + + +enum pipe_error cso_set_blend_color(struct cso_context *ctx, + const struct pipe_blend_color *bc) +{ + if (memcmp(&ctx->blend_color, bc, sizeof(ctx->blend_color))) { + ctx->blend_color = *bc; + ctx->pipe->set_blend_color(ctx->pipe, bc); + } + return PIPE_OK; +} + +enum pipe_error cso_set_sample_mask(struct cso_context *ctx, + unsigned sample_mask) +{ + if (ctx->sample_mask != sample_mask) { + ctx->sample_mask = sample_mask; + ctx->pipe->set_sample_mask(ctx->pipe, sample_mask); + } + return PIPE_OK; +} + +enum pipe_error cso_set_stencil_ref(struct cso_context *ctx, + const struct pipe_stencil_ref *sr) +{ + if (memcmp(&ctx->stencil_ref, sr, sizeof(ctx->stencil_ref))) { + ctx->stencil_ref = *sr; + ctx->pipe->set_stencil_ref(ctx->pipe, sr); + } + return PIPE_OK; +} + +void cso_save_stencil_ref(struct cso_context *ctx) +{ + ctx->stencil_ref_saved = ctx->stencil_ref; +} + + +void cso_restore_stencil_ref(struct cso_context *ctx) +{ + if (memcmp(&ctx->stencil_ref, &ctx->stencil_ref_saved, sizeof(ctx->stencil_ref))) { + ctx->stencil_ref = ctx->stencil_ref_saved; + ctx->pipe->set_stencil_ref(ctx->pipe, &ctx->stencil_ref); + } +} + +enum pipe_error cso_set_geometry_shader_handle(struct cso_context *ctx, + void *handle) +{ + if (ctx->geometry_shader != handle) { + ctx->geometry_shader = handle; + ctx->pipe->bind_gs_state(ctx->pipe, handle); + } + return PIPE_OK; +} + +void cso_delete_geometry_shader(struct cso_context *ctx, void *handle) +{ + if (handle == ctx->geometry_shader) { + /* unbind before deleting */ + ctx->pipe->bind_gs_state(ctx->pipe, NULL); + ctx->geometry_shader = NULL; + } + ctx->pipe->delete_gs_state(ctx->pipe, handle); +} + +void cso_save_geometry_shader(struct cso_context *ctx) +{ + assert(!ctx->geometry_shader_saved); + ctx->geometry_shader_saved = ctx->geometry_shader; +} + +void cso_restore_geometry_shader(struct cso_context *ctx) +{ + if (ctx->geometry_shader_saved != ctx->geometry_shader) { + ctx->pipe->bind_gs_state(ctx->pipe, ctx->geometry_shader_saved); + ctx->geometry_shader = ctx->geometry_shader_saved; + } + ctx->geometry_shader_saved = NULL; +} + +/* clip state */ + +static INLINE void +clip_state_cpy(struct pipe_clip_state *dst, + const struct pipe_clip_state *src) +{ + dst->depth_clamp = src->depth_clamp; + dst->nr = src->nr; + if (src->nr) { + memcpy(dst->ucp, src->ucp, src->nr * sizeof(src->ucp[0])); + } +} + +static INLINE int +clip_state_cmp(const struct pipe_clip_state *a, + const struct pipe_clip_state *b) +{ + if (a->depth_clamp != b->depth_clamp) { + return 1; + } + if (a->nr != b->nr) { + return 1; + } + if (a->nr) { + return memcmp(a->ucp, b->ucp, a->nr * sizeof(a->ucp[0])); + } + return 0; +} + +void +cso_set_clip(struct cso_context *ctx, + const struct pipe_clip_state *clip) +{ + if (clip_state_cmp(&ctx->clip, clip)) { + clip_state_cpy(&ctx->clip, clip); + ctx->pipe->set_clip_state(ctx->pipe, clip); + } +} + +void +cso_save_clip(struct cso_context *ctx) +{ + clip_state_cpy(&ctx->clip_saved, &ctx->clip); +} + +void +cso_restore_clip(struct cso_context *ctx) +{ + if (clip_state_cmp(&ctx->clip, &ctx->clip_saved)) { + clip_state_cpy(&ctx->clip, &ctx->clip_saved); + ctx->pipe->set_clip_state(ctx->pipe, &ctx->clip_saved); + } +} + +enum pipe_error cso_set_vertex_elements(struct cso_context *ctx, + unsigned count, + const struct pipe_vertex_element *states) +{ + unsigned key_size, hash_key; + struct cso_hash_iter iter; + void *handle; + struct cso_velems_state velems_state; + + /* need to include the count into the stored state data too. + Otherwise first few count pipe_vertex_elements could be identical even if count + is different, and there's no guarantee the hash would be different in that + case neither */ + key_size = sizeof(struct pipe_vertex_element) * count + sizeof(unsigned); + velems_state.count = count; + memcpy(velems_state.velems, states, sizeof(struct pipe_vertex_element) * count); + hash_key = cso_construct_key((void*)&velems_state, key_size); + iter = cso_find_state_template(ctx->cache, hash_key, CSO_VELEMENTS, (void*)&velems_state, key_size); + + if (cso_hash_iter_is_null(iter)) { + struct cso_velements *cso = MALLOC(sizeof(struct cso_velements)); + if (!cso) + return PIPE_ERROR_OUT_OF_MEMORY; + + memcpy(&cso->state, &velems_state, key_size); + cso->data = ctx->pipe->create_vertex_elements_state(ctx->pipe, count, &cso->state.velems[0]); + cso->delete_state = (cso_state_callback)ctx->pipe->delete_vertex_elements_state; + cso->context = ctx->pipe; + + iter = cso_insert_state(ctx->cache, hash_key, CSO_VELEMENTS, cso); + if (cso_hash_iter_is_null(iter)) { + FREE(cso); + return PIPE_ERROR_OUT_OF_MEMORY; + } + + handle = cso->data; + } + else { + handle = ((struct cso_velements *)cso_hash_iter_data(iter))->data; + } + + if (ctx->velements != handle) { + ctx->velements = handle; + ctx->pipe->bind_vertex_elements_state(ctx->pipe, handle); + } + return PIPE_OK; +} + +void cso_save_vertex_elements(struct cso_context *ctx) +{ + assert(!ctx->velements_saved); + ctx->velements_saved = ctx->velements; +} + +void cso_restore_vertex_elements(struct cso_context *ctx) +{ + if (ctx->velements != ctx->velements_saved) { + ctx->velements = ctx->velements_saved; + ctx->pipe->bind_vertex_elements_state(ctx->pipe, ctx->velements_saved); + } + ctx->velements_saved = NULL; +} + +/* fragment sampler view state */ + +void +cso_set_fragment_sampler_views(struct cso_context *cso, + uint count, + struct pipe_sampler_view **views) +{ + uint i; + + for (i = 0; i < count; i++) { + pipe_sampler_view_reference(&cso->fragment_sampler_views[i], views[i]); + } + for (; i < cso->nr_fragment_sampler_views; i++) { + pipe_sampler_view_reference(&cso->fragment_sampler_views[i], NULL); + } + + cso->pipe->set_fragment_sampler_views(cso->pipe, + MAX2(count, cso->nr_fragment_sampler_views), + cso->fragment_sampler_views); + + cso->nr_fragment_sampler_views = count; +} + +void +cso_save_fragment_sampler_views(struct cso_context *cso) +{ + uint i; + + cso->nr_fragment_sampler_views_saved = cso->nr_fragment_sampler_views; + + for (i = 0; i < cso->nr_fragment_sampler_views; i++) { + assert(!cso->fragment_sampler_views_saved[i]); + + pipe_sampler_view_reference(&cso->fragment_sampler_views_saved[i], + cso->fragment_sampler_views[i]); + } +} + +void +cso_restore_fragment_sampler_views(struct cso_context *cso) +{ + uint i; + + for (i = 0; i < cso->nr_fragment_sampler_views_saved; i++) { + pipe_sampler_view_reference(&cso->fragment_sampler_views[i], cso->fragment_sampler_views_saved[i]); + pipe_sampler_view_reference(&cso->fragment_sampler_views_saved[i], NULL); + } + for (; i < cso->nr_fragment_sampler_views; i++) { + pipe_sampler_view_reference(&cso->fragment_sampler_views[i], NULL); + } + + cso->pipe->set_fragment_sampler_views(cso->pipe, + MAX2(cso->nr_fragment_sampler_views, cso->nr_fragment_sampler_views_saved), + cso->fragment_sampler_views); + + cso->nr_fragment_sampler_views = cso->nr_fragment_sampler_views_saved; + cso->nr_fragment_sampler_views_saved = 0; +} + + +/* vertex sampler view state */ + +void +cso_set_vertex_sampler_views(struct cso_context *cso, + uint count, + struct pipe_sampler_view **views) +{ + uint i; + + for (i = 0; i < count; i++) { + pipe_sampler_view_reference(&cso->vertex_sampler_views[i], views[i]); + } + for (; i < cso->nr_vertex_sampler_views; i++) { + pipe_sampler_view_reference(&cso->vertex_sampler_views[i], NULL); + } + + cso->pipe->set_vertex_sampler_views(cso->pipe, + MAX2(count, cso->nr_vertex_sampler_views), + cso->vertex_sampler_views); + + cso->nr_vertex_sampler_views = count; +} + +void +cso_save_vertex_sampler_views(struct cso_context *cso) +{ + uint i; + + cso->nr_vertex_sampler_views_saved = cso->nr_vertex_sampler_views; + + for (i = 0; i < cso->nr_vertex_sampler_views; i++) { + assert(!cso->vertex_sampler_views_saved[i]); + + pipe_sampler_view_reference(&cso->vertex_sampler_views_saved[i], + cso->vertex_sampler_views[i]); + } +} + +void +cso_restore_vertex_sampler_views(struct cso_context *cso) +{ + uint i; + + for (i = 0; i < cso->nr_vertex_sampler_views_saved; i++) { + pipe_sampler_view_reference(&cso->vertex_sampler_views[i], cso->vertex_sampler_views_saved[i]); + pipe_sampler_view_reference(&cso->vertex_sampler_views_saved[i], NULL); + } + for (; i < cso->nr_vertex_sampler_views; i++) { + pipe_sampler_view_reference(&cso->vertex_sampler_views[i], NULL); + } + + cso->pipe->set_vertex_sampler_views(cso->pipe, + MAX2(cso->nr_vertex_sampler_views, cso->nr_vertex_sampler_views_saved), + cso->vertex_sampler_views); + + cso->nr_vertex_sampler_views = cso->nr_vertex_sampler_views_saved; + cso->nr_vertex_sampler_views_saved = 0; +} diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h new file mode 100644 index 0000000..f0b07f7 --- /dev/null +++ b/src/gallium/auxiliary/cso_cache/cso_context.h @@ -0,0 +1,216 @@ +/************************************************************************** + * + * Copyright 2007-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. + * + **************************************************************************/ + + +#ifndef CSO_CONTEXT_H +#define CSO_CONTEXT_H + +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +struct cso_context; + +struct cso_context *cso_create_context( struct pipe_context *pipe ); + +void cso_release_all( struct cso_context *ctx ); + +void cso_destroy_context( struct cso_context *cso ); + + + +enum pipe_error cso_set_blend( struct cso_context *cso, + const struct pipe_blend_state *blend ); +void cso_save_blend(struct cso_context *cso); +void cso_restore_blend(struct cso_context *cso); + + + +enum pipe_error cso_set_depth_stencil_alpha( struct cso_context *cso, + const struct pipe_depth_stencil_alpha_state *dsa ); +void cso_save_depth_stencil_alpha(struct cso_context *cso); +void cso_restore_depth_stencil_alpha(struct cso_context *cso); + + + +enum pipe_error cso_set_rasterizer( struct cso_context *cso, + const struct pipe_rasterizer_state *rasterizer ); +void cso_save_rasterizer(struct cso_context *cso); +void cso_restore_rasterizer(struct cso_context *cso); + + + +enum pipe_error cso_set_samplers( struct cso_context *cso, + unsigned count, + const struct pipe_sampler_state **states ); +void cso_save_samplers(struct cso_context *cso); +void cso_restore_samplers(struct cso_context *cso); + +/* Alternate interface to support state trackers that like to modify + * samplers one at a time: + */ +enum pipe_error cso_single_sampler( struct cso_context *cso, + unsigned nr, + const struct pipe_sampler_state *states ); + +void cso_single_sampler_done( struct cso_context *cso ); + +enum pipe_error cso_set_vertex_samplers(struct cso_context *cso, + unsigned count, + const struct pipe_sampler_state **states); + +void +cso_save_vertex_samplers(struct cso_context *cso); + +void +cso_restore_vertex_samplers(struct cso_context *cso); + +enum pipe_error +cso_single_vertex_sampler(struct cso_context *cso, + unsigned nr, + const struct pipe_sampler_state *states); + +void +cso_single_vertex_sampler_done(struct cso_context *cso); + + +enum pipe_error cso_set_vertex_elements(struct cso_context *ctx, + unsigned count, + const struct pipe_vertex_element *states); +void cso_save_vertex_elements(struct cso_context *ctx); +void cso_restore_vertex_elements(struct cso_context *ctx); + + +/* These aren't really sensible -- most of the time the api provides + * object semantics for shaders anyway, and the cases where it doesn't + * (eg mesa's internall-generated texenv programs), it will be up to + * the state tracker to implement their own specialized caching. + */ +enum pipe_error cso_set_fragment_shader_handle(struct cso_context *ctx, + void *handle ); +void cso_delete_fragment_shader(struct cso_context *ctx, void *handle ); +/* +enum pipe_error cso_set_fragment_shader( struct cso_context *cso, + const struct pipe_shader_state *shader ); +*/ +void cso_save_fragment_shader(struct cso_context *cso); +void cso_restore_fragment_shader(struct cso_context *cso); + + +enum pipe_error cso_set_vertex_shader_handle(struct cso_context *ctx, + void *handle ); +void cso_delete_vertex_shader(struct cso_context *ctx, void *handle ); +/* +enum pipe_error cso_set_vertex_shader( struct cso_context *cso, + const struct pipe_shader_state *shader ); +*/ +void cso_save_vertex_shader(struct cso_context *cso); +void cso_restore_vertex_shader(struct cso_context *cso); + + +enum pipe_error cso_set_geometry_shader_handle(struct cso_context *ctx, + void *handle); +void cso_delete_geometry_shader(struct cso_context *ctx, void *handle); +void cso_save_geometry_shader(struct cso_context *cso); +void cso_restore_geometry_shader(struct cso_context *cso); + + +enum pipe_error cso_set_framebuffer(struct cso_context *cso, + const struct pipe_framebuffer_state *fb); +void cso_save_framebuffer(struct cso_context *cso); +void cso_restore_framebuffer(struct cso_context *cso); + + +enum pipe_error cso_set_viewport(struct cso_context *cso, + const struct pipe_viewport_state *vp); +void cso_save_viewport(struct cso_context *cso); +void cso_restore_viewport(struct cso_context *cso); + + +enum pipe_error cso_set_blend_color(struct cso_context *cso, + const struct pipe_blend_color *bc); + +enum pipe_error cso_set_sample_mask(struct cso_context *cso, + unsigned stencil_mask); + +enum pipe_error cso_set_stencil_ref(struct cso_context *cso, + const struct pipe_stencil_ref *sr); +void cso_save_stencil_ref(struct cso_context *cso); +void cso_restore_stencil_ref(struct cso_context *cso); + + +/* clip state */ + +void +cso_set_clip(struct cso_context *cso, + const struct pipe_clip_state *clip); + +void +cso_save_clip(struct cso_context *cso); + +void +cso_restore_clip(struct cso_context *cso); + + +/* fragment sampler view state */ + +void +cso_set_fragment_sampler_views(struct cso_context *cso, + uint count, + struct pipe_sampler_view **views); + +void +cso_save_fragment_sampler_views(struct cso_context *cso); + +void +cso_restore_fragment_sampler_views(struct cso_context *cso); + + +/* vertex sampler view state */ + +void +cso_set_vertex_sampler_views(struct cso_context *cso, + uint count, + struct pipe_sampler_view **views); + +void +cso_save_vertex_sampler_views(struct cso_context *cso); + +void +cso_restore_vertex_sampler_views(struct cso_context *cso); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/auxiliary/cso_cache/cso_hash.c b/src/gallium/auxiliary/cso_cache/cso_hash.c new file mode 100644 index 0000000..288cef7 --- /dev/null +++ b/src/gallium/auxiliary/cso_cache/cso_hash.c @@ -0,0 +1,439 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Zack Rusin + */ + +#include "util/u_debug.h" +#include "util/u_memory.h" + +#include "cso_hash.h" + +#define MAX(a, b) ((a > b) ? (a) : (b)) + +static const int MinNumBits = 4; + +static const unsigned char prime_deltas[] = { + 0, 0, 1, 3, 1, 5, 3, 3, 1, 9, 7, 5, 3, 9, 25, 3, + 1, 21, 3, 21, 7, 15, 9, 5, 3, 29, 15, 0, 0, 0, 0, 0 +}; + +static int primeForNumBits(int numBits) +{ + return (1 << numBits) + prime_deltas[numBits]; +} + +/* + Returns the smallest integer n such that + primeForNumBits(n) >= hint. +*/ +static int countBits(int hint) +{ + int numBits = 0; + int bits = hint; + + while (bits > 1) { + bits >>= 1; + numBits++; + } + + if (numBits >= (int)sizeof(prime_deltas)) { + numBits = sizeof(prime_deltas) - 1; + } else if (primeForNumBits(numBits) < hint) { + ++numBits; + } + return numBits; +} + +struct cso_node { + struct cso_node *next; + unsigned key; + void *value; +}; + +struct cso_hash_data { + struct cso_node *fakeNext; + struct cso_node **buckets; + int size; + int nodeSize; + short userNumBits; + short numBits; + int numBuckets; +}; + +struct cso_hash { + union { + struct cso_hash_data *d; + struct cso_node *e; + } data; +}; + +static void *cso_data_allocate_node(struct cso_hash_data *hash) +{ + return MALLOC(hash->nodeSize); +} + +static void cso_free_node(struct cso_node *node) +{ + FREE(node); +} + +static struct cso_node * +cso_hash_create_node(struct cso_hash *hash, + unsigned akey, void *avalue, + struct cso_node **anextNode) +{ + struct cso_node *node = cso_data_allocate_node(hash->data.d); + + if (!node) + return NULL; + + node->key = akey; + node->value = avalue; + + node->next = (struct cso_node*)(*anextNode); + *anextNode = node; + ++hash->data.d->size; + return node; +} + +static void cso_data_rehash(struct cso_hash_data *hash, int hint) +{ + if (hint < 0) { + hint = countBits(-hint); + if (hint < MinNumBits) + hint = MinNumBits; + hash->userNumBits = (short)hint; + while (primeForNumBits(hint) < (hash->size >> 1)) + ++hint; + } else if (hint < MinNumBits) { + hint = MinNumBits; + } + + if (hash->numBits != hint) { + struct cso_node *e = (struct cso_node *)(hash); + struct cso_node **oldBuckets = hash->buckets; + int oldNumBuckets = hash->numBuckets; + int i = 0; + + hash->numBits = (short)hint; + hash->numBuckets = primeForNumBits(hint); + hash->buckets = MALLOC(sizeof(struct cso_node*) * hash->numBuckets); + for (i = 0; i < hash->numBuckets; ++i) + hash->buckets[i] = e; + + for (i = 0; i < oldNumBuckets; ++i) { + struct cso_node *firstNode = oldBuckets[i]; + while (firstNode != e) { + unsigned h = firstNode->key; + struct cso_node *lastNode = firstNode; + struct cso_node *afterLastNode; + struct cso_node **beforeFirstNode; + + while (lastNode->next != e && lastNode->next->key == h) + lastNode = lastNode->next; + + afterLastNode = lastNode->next; + beforeFirstNode = &hash->buckets[h % hash->numBuckets]; + while (*beforeFirstNode != e) + beforeFirstNode = &(*beforeFirstNode)->next; + lastNode->next = *beforeFirstNode; + *beforeFirstNode = firstNode; + firstNode = afterLastNode; + } + } + FREE(oldBuckets); + } +} + +static void cso_data_might_grow(struct cso_hash_data *hash) +{ + if (hash->size >= hash->numBuckets) + cso_data_rehash(hash, hash->numBits + 1); +} + +static void cso_data_has_shrunk(struct cso_hash_data *hash) +{ + if (hash->size <= (hash->numBuckets >> 3) && + hash->numBits > hash->userNumBits) { + int max = MAX(hash->numBits-2, hash->userNumBits); + cso_data_rehash(hash, max); + } +} + +static struct cso_node *cso_data_first_node(struct cso_hash_data *hash) +{ + struct cso_node *e = (struct cso_node *)(hash); + struct cso_node **bucket = hash->buckets; + int n = hash->numBuckets; + while (n--) { + if (*bucket != e) + return *bucket; + ++bucket; + } + return e; +} + +static struct cso_node **cso_hash_find_node(struct cso_hash *hash, unsigned akey) +{ + struct cso_node **node; + + if (hash->data.d->numBuckets) { + node = (struct cso_node **)(&hash->data.d->buckets[akey % hash->data.d->numBuckets]); + assert(*node == hash->data.e || (*node)->next); + while (*node != hash->data.e && (*node)->key != akey) + node = &(*node)->next; + } else { + node = (struct cso_node **)((const struct cso_node * const *)(&hash->data.e)); + } + return node; +} + +struct cso_hash_iter cso_hash_insert(struct cso_hash *hash, + unsigned key, void *data) +{ + cso_data_might_grow(hash->data.d); + + { + struct cso_node **nextNode = cso_hash_find_node(hash, key); + struct cso_node *node = cso_hash_create_node(hash, key, data, nextNode); + if (!node) { + struct cso_hash_iter null_iter = {hash, 0}; + return null_iter; + } + + { + struct cso_hash_iter iter = {hash, node}; + return iter; + } + } +} + +struct cso_hash * cso_hash_create(void) +{ + struct cso_hash *hash = MALLOC_STRUCT(cso_hash); + if (!hash) + return NULL; + + hash->data.d = MALLOC_STRUCT(cso_hash_data); + if (!hash->data.d) { + FREE(hash); + return NULL; + } + + hash->data.d->fakeNext = 0; + hash->data.d->buckets = 0; + hash->data.d->size = 0; + hash->data.d->nodeSize = sizeof(struct cso_node); + hash->data.d->userNumBits = (short)MinNumBits; + hash->data.d->numBits = 0; + hash->data.d->numBuckets = 0; + + return hash; +} + +void cso_hash_delete(struct cso_hash *hash) +{ + struct cso_node *e_for_x = (struct cso_node *)(hash->data.d); + struct cso_node **bucket = (struct cso_node **)(hash->data.d->buckets); + int n = hash->data.d->numBuckets; + while (n--) { + struct cso_node *cur = *bucket++; + while (cur != e_for_x) { + struct cso_node *next = cur->next; + cso_free_node(cur); + cur = next; + } + } + FREE(hash->data.d->buckets); + FREE(hash->data.d); + FREE(hash); +} + +struct cso_hash_iter cso_hash_find(struct cso_hash *hash, + unsigned key) +{ + struct cso_node **nextNode = cso_hash_find_node(hash, key); + struct cso_hash_iter iter = {hash, *nextNode}; + return iter; +} + +unsigned cso_hash_iter_key(struct cso_hash_iter iter) +{ + if (!iter.node || iter.hash->data.e == iter.node) + return 0; + return iter.node->key; +} + +void * cso_hash_iter_data(struct cso_hash_iter iter) +{ + if (!iter.node || iter.hash->data.e == iter.node) + return 0; + return iter.node->value; +} + +static struct cso_node *cso_hash_data_next(struct cso_node *node) +{ + union { + struct cso_node *next; + struct cso_node *e; + struct cso_hash_data *d; + } a; + int start; + struct cso_node **bucket; + int n; + + a.next = node->next; + if (!a.next) { + debug_printf("iterating beyond the last element\n"); + return 0; + } + if (a.next->next) + return a.next; + + start = (node->key % a.d->numBuckets) + 1; + bucket = a.d->buckets + start; + n = a.d->numBuckets - start; + while (n--) { + if (*bucket != a.e) + return *bucket; + ++bucket; + } + return a.e; +} + + +static struct cso_node *cso_hash_data_prev(struct cso_node *node) +{ + union { + struct cso_node *e; + struct cso_hash_data *d; + } a; + int start; + struct cso_node *sentinel; + struct cso_node **bucket; + + a.e = node; + while (a.e->next) + a.e = a.e->next; + + if (node == a.e) + start = a.d->numBuckets - 1; + else + start = node->key % a.d->numBuckets; + + sentinel = node; + bucket = a.d->buckets + start; + while (start >= 0) { + if (*bucket != sentinel) { + struct cso_node *prev = *bucket; + while (prev->next != sentinel) + prev = prev->next; + return prev; + } + + sentinel = a.e; + --bucket; + --start; + } + debug_printf("iterating backward beyond first element\n"); + return a.e; +} + +struct cso_hash_iter cso_hash_iter_next(struct cso_hash_iter iter) +{ + struct cso_hash_iter next = {iter.hash, cso_hash_data_next(iter.node)}; + return next; +} + +int cso_hash_iter_is_null(struct cso_hash_iter iter) +{ + if (!iter.node || iter.node == iter.hash->data.e) + return 1; + return 0; +} + +void * cso_hash_take(struct cso_hash *hash, + unsigned akey) +{ + struct cso_node **node = cso_hash_find_node(hash, akey); + if (*node != hash->data.e) { + void *t = (*node)->value; + struct cso_node *next = (*node)->next; + cso_free_node(*node); + *node = next; + --hash->data.d->size; + cso_data_has_shrunk(hash->data.d); + return t; + } + return 0; +} + +struct cso_hash_iter cso_hash_iter_prev(struct cso_hash_iter iter) +{ + struct cso_hash_iter prev = {iter.hash, + cso_hash_data_prev(iter.node)}; + return prev; +} + +struct cso_hash_iter cso_hash_first_node(struct cso_hash *hash) +{ + struct cso_hash_iter iter = {hash, cso_data_first_node(hash->data.d)}; + return iter; +} + +int cso_hash_size(struct cso_hash *hash) +{ + return hash->data.d->size; +} + +struct cso_hash_iter cso_hash_erase(struct cso_hash *hash, struct cso_hash_iter iter) +{ + struct cso_hash_iter ret = iter; + struct cso_node *node = iter.node; + struct cso_node **node_ptr; + + if (node == hash->data.e) + return iter; + + ret = cso_hash_iter_next(ret); + node_ptr = (struct cso_node**)(&hash->data.d->buckets[node->key % hash->data.d->numBuckets]); + while (*node_ptr != node) + node_ptr = &(*node_ptr)->next; + *node_ptr = node->next; + cso_free_node(node); + --hash->data.d->size; + return ret; +} + +boolean cso_hash_contains(struct cso_hash *hash, unsigned key) +{ + struct cso_node **node = cso_hash_find_node(hash, key); + return (*node != hash->data.e); +} diff --git a/src/gallium/auxiliary/cso_cache/cso_hash.h b/src/gallium/auxiliary/cso_cache/cso_hash.h new file mode 100644 index 0000000..5891c32 --- /dev/null +++ b/src/gallium/auxiliary/cso_cache/cso_hash.h @@ -0,0 +1,129 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Hash table implementation. + * + * This file provides a hash implementation that is capable of dealing + * with collisions. It stores colliding entries in linked list. All + * functions operating on the hash return an iterator. The iterator + * itself points to the collision list. If there wasn't any collision + * the list will have just one entry, otherwise client code should + * iterate over the entries to find the exact entry among ones that + * had the same key (e.g. memcmp could be used on the data to check + * that) + * + * @author Zack Rusin + */ + +#ifndef CSO_HASH_H +#define CSO_HASH_H + +#include "pipe/p_compiler.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +struct cso_hash; +struct cso_node; + + +struct cso_hash_iter { + struct cso_hash *hash; + struct cso_node *node; +}; + + +struct cso_hash *cso_hash_create(void); +void cso_hash_delete(struct cso_hash *hash); + + +int cso_hash_size(struct cso_hash *hash); + + +/** + * Adds a data with the given key to the hash. If entry with the given + * key is already in the hash, this current entry is instered before it + * in the collision list. + * Function returns iterator pointing to the inserted item in the hash. + */ +struct cso_hash_iter cso_hash_insert(struct cso_hash *hash, unsigned key, + void *data); +/** + * Removes the item pointed to by the current iterator from the hash. + * Note that the data itself is not erased and if it was a malloc'ed pointer + * it will have to be freed after calling this function by the callee. + * Function returns iterator pointing to the item after the removed one in + * the hash. + */ +struct cso_hash_iter cso_hash_erase(struct cso_hash *hash, struct cso_hash_iter iter); + +void *cso_hash_take(struct cso_hash *hash, unsigned key); + + + +struct cso_hash_iter cso_hash_first_node(struct cso_hash *hash); + +/** + * Return an iterator pointing to the first entry in the collision list. + */ +struct cso_hash_iter cso_hash_find(struct cso_hash *hash, unsigned key); + +/** + * Returns true if a value with the given key exists in the hash + */ +boolean cso_hash_contains(struct cso_hash *hash, unsigned key); + + +int cso_hash_iter_is_null(struct cso_hash_iter iter); +unsigned cso_hash_iter_key(struct cso_hash_iter iter); +void *cso_hash_iter_data(struct cso_hash_iter iter); + + +struct cso_hash_iter cso_hash_iter_next(struct cso_hash_iter iter); +struct cso_hash_iter cso_hash_iter_prev(struct cso_hash_iter iter); + + +/** + * Convenience routine to iterate over the collision list while doing a memory + * comparison to see which entry in the list is a direct copy of our template + * and returns that entry. + */ +void *cso_hash_find_data_from_template( struct cso_hash *hash, + unsigned hash_key, + void *templ, + int size ); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/auxiliary/draw/draw_cliptest_tmp.h b/src/gallium/auxiliary/draw/draw_cliptest_tmp.h new file mode 100644 index 0000000..958ed20 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_cliptest_tmp.h @@ -0,0 +1,114 @@ +/************************************************************************** + * + * Copyright 2010, VMware, inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + + +static boolean TAG(do_cliptest)( struct pt_post_vs *pvs, + struct draw_vertex_info *info ) +{ + struct vertex_header *out = info->verts; + const float *scale = pvs->draw->viewport.scale; + const float *trans = pvs->draw->viewport.translate; + /* const */ float (*plane)[4] = pvs->draw->plane; + const unsigned pos = draw_current_shader_position_output(pvs->draw); + const unsigned ef = pvs->draw->vs.edgeflag_output; + const unsigned nr = pvs->draw->nr_planes; + const unsigned flags = (FLAGS); + unsigned need_pipeline = 0; + unsigned j; + + for (j = 0; j < info->count; j++) { + float *position = out->data[pos]; + unsigned mask = 0x0; + + initialize_vertex_header(out); + + if (flags & (DO_CLIP_XY | DO_CLIP_FULL_Z | DO_CLIP_HALF_Z | DO_CLIP_USER)) { + out->clip[0] = position[0]; + out->clip[1] = position[1]; + out->clip[2] = position[2]; + out->clip[3] = position[3]; + + /* Do the hardwired planes first: + */ + if (flags & DO_CLIP_XY) { + if (-position[0] + position[3] < 0) mask |= (1<<0); + if ( position[0] + position[3] < 0) mask |= (1<<1); + if (-position[1] + position[3] < 0) mask |= (1<<2); + if ( position[1] + position[3] < 0) mask |= (1<<3); + } + + /* Clip Z planes according to full cube, half cube or none. + */ + if (flags & DO_CLIP_FULL_Z) { + if ( position[2] + position[3] < 0) mask |= (1<<4); + if (-position[2] + position[3] < 0) mask |= (1<<5); + } + else if (flags & DO_CLIP_HALF_Z) { + if ( position[2] < 0) mask |= (1<<4); + if (-position[2] + position[3] < 0) mask |= (1<<5); + } + + if (flags & DO_CLIP_USER) { + unsigned i; + for (i = 6; i < nr; i++) { + if (dot4(position, plane[i]) < 0) + mask |= (1<clipmask = mask; + need_pipeline |= out->clipmask; + } + + if ((flags & DO_VIEWPORT) && mask == 0) + { + /* divide by w */ + float w = 1.0f / position[3]; + + /* Viewport mapping */ + position[0] = position[0] * w * scale[0] + trans[0]; + position[1] = position[1] * w * scale[1] + trans[1]; + position[2] = position[2] * w * scale[2] + trans[2]; + position[3] = w; + } + + if ((flags & DO_EDGEFLAG) && ef) { + const float *edgeflag = out->data[ef]; + out->edgeflag = !(edgeflag[0] != 1.0f); + need_pipeline |= !out->edgeflag; + } + + out = (struct vertex_header *)( (char *)out + info->stride ); + } + + return need_pipeline != 0; +} + + +#undef FLAGS +#undef TAG diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c new file mode 100644 index 0000000..73d5b6e --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_context.c @@ -0,0 +1,751 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + + +#include "pipe/p_context.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_cpu_detect.h" +#include "draw_context.h" +#include "draw_vs.h" +#include "draw_gs.h" + +#if HAVE_LLVM +#include "gallivm/lp_bld_init.h" +#include "draw_llvm.h" + +static boolean +draw_get_option_use_llvm(void) +{ + static boolean first = TRUE; + static boolean value; + if (first) { + first = FALSE; + value = debug_get_bool_option("DRAW_USE_LLVM", TRUE); + +#ifdef PIPE_ARCH_X86 + util_cpu_detect(); + /* require SSE2 due to LLVM PR6960. */ + if (!util_cpu_caps.has_sse2) + value = FALSE; +#endif + } + return value; +} +#endif + + + +/** + * Create new draw module context. + */ +struct draw_context * +draw_create(struct pipe_context *pipe) +{ + return draw_create_gallivm(pipe, NULL); +} + + + +/** + * Create new draw module context with gallivm state for LLVM JIT. + */ +struct draw_context * +draw_create_gallivm(struct pipe_context *pipe, struct gallivm_state *gallivm) +{ + struct draw_context *draw = CALLOC_STRUCT( draw_context ); + if (draw == NULL) + goto fail; + +#if HAVE_LLVM + if (draw_get_option_use_llvm() && gallivm) { + draw->llvm = draw_llvm_create(draw, gallivm); + } +#endif + + if (!draw_init(draw)) + goto fail; + + draw->pipe = pipe; + + return draw; + +fail: + draw_destroy( draw ); + return NULL; +} + + + +boolean draw_init(struct draw_context *draw) +{ + /* + * Note that several functions compute the clipmask of the predefined + * formats with hardcoded formulas instead of using these. So modifications + * here must be reflected there too. + */ + + ASSIGN_4V( draw->plane[0], -1, 0, 0, 1 ); + ASSIGN_4V( draw->plane[1], 1, 0, 0, 1 ); + ASSIGN_4V( draw->plane[2], 0, -1, 0, 1 ); + ASSIGN_4V( draw->plane[3], 0, 1, 0, 1 ); + ASSIGN_4V( draw->plane[4], 0, 0, 1, 1 ); /* yes these are correct */ + ASSIGN_4V( draw->plane[5], 0, 0, -1, 1 ); /* mesa's a bit wonky */ + draw->nr_planes = 6; + draw->clip_xy = 1; + draw->clip_z = 1; + + + draw->reduced_prim = ~0; /* != any of PIPE_PRIM_x */ + + + if (!draw_pipeline_init( draw )) + return FALSE; + + if (!draw_pt_init( draw )) + return FALSE; + + if (!draw_vs_init( draw )) + return FALSE; + + if (!draw_gs_init( draw )) + return FALSE; + + return TRUE; +} + + +void draw_destroy( struct draw_context *draw ) +{ + struct pipe_context *pipe; + int i, j; + + if (!draw) + return; + + pipe = draw->pipe; + + /* free any rasterizer CSOs that we may have created. + */ + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + if (draw->rasterizer_no_cull[i][j]) { + pipe->delete_rasterizer_state(pipe, draw->rasterizer_no_cull[i][j]); + } + } + } + + /* Not so fast -- we're just borrowing this at the moment. + * + if (draw->render) + draw->render->destroy( draw->render ); + */ + + draw_pipeline_destroy( draw ); + draw_pt_destroy( draw ); + draw_vs_destroy( draw ); + draw_gs_destroy( draw ); +#ifdef HAVE_LLVM + if(draw->llvm) + draw_llvm_destroy( draw->llvm ); +#endif + + FREE( draw ); +} + + + +void draw_flush( struct draw_context *draw ) +{ + draw_do_flush( draw, DRAW_FLUSH_BACKEND ); +} + + +/** + * Specify the Minimum Resolvable Depth factor for polygon offset. + * This factor potentially depends on the number of Z buffer bits, + * the rasterization algorithm and the arithmetic performed on Z + * values between vertex shading and rasterization. It will vary + * from one driver to another. + */ +void draw_set_mrd(struct draw_context *draw, double mrd) +{ + draw->mrd = mrd; +} + + +static void update_clip_flags( struct draw_context *draw ) +{ + draw->clip_xy = !draw->driver.bypass_clip_xy; + draw->clip_z = (!draw->driver.bypass_clip_z && + !draw->depth_clamp); + draw->clip_user = (draw->nr_planes > 6); +} + +/** + * Register new primitive rasterization/rendering state. + * This causes the drawing pipeline to be rebuilt. + */ +void draw_set_rasterizer_state( struct draw_context *draw, + const struct pipe_rasterizer_state *raster, + void *rast_handle ) +{ + if (!draw->suspend_flushing) { + draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE ); + + draw->rasterizer = raster; + draw->rast_handle = rast_handle; + + } +} + +/* With a little more work, llvmpipe will be able to turn this off and + * do its own x/y clipping. + * + * Some hardware can turn off clipping altogether - in particular any + * hardware with a TNL unit can do its own clipping, even if it is + * relying on the draw module for some other reason. + */ +void draw_set_driver_clipping( struct draw_context *draw, + boolean bypass_clip_xy, + boolean bypass_clip_z ) +{ + draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE ); + + draw->driver.bypass_clip_xy = bypass_clip_xy; + draw->driver.bypass_clip_z = bypass_clip_z; + update_clip_flags(draw); +} + + +/** + * Plug in the primitive rendering/rasterization stage (which is the last + * stage in the drawing pipeline). + * This is provided by the device driver. + */ +void draw_set_rasterize_stage( struct draw_context *draw, + struct draw_stage *stage ) +{ + draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE ); + + draw->pipeline.rasterize = stage; +} + + +/** + * Set the draw module's clipping state. + */ +void draw_set_clip_state( struct draw_context *draw, + const struct pipe_clip_state *clip ) +{ + draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE ); + + assert(clip->nr <= PIPE_MAX_CLIP_PLANES); + memcpy(&draw->plane[6], clip->ucp, clip->nr * sizeof(clip->ucp[0])); + draw->nr_planes = 6 + clip->nr; + draw->depth_clamp = clip->depth_clamp; + + update_clip_flags(draw); +} + + +/** + * Set the draw module's viewport state. + */ +void draw_set_viewport_state( struct draw_context *draw, + const struct pipe_viewport_state *viewport ) +{ + draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE ); + draw->viewport = *viewport; /* struct copy */ + draw->identity_viewport = (viewport->scale[0] == 1.0f && + viewport->scale[1] == 1.0f && + viewport->scale[2] == 1.0f && + viewport->scale[3] == 1.0f && + viewport->translate[0] == 0.0f && + viewport->translate[1] == 0.0f && + viewport->translate[2] == 0.0f && + viewport->translate[3] == 0.0f); + + draw_vs_set_viewport( draw, viewport ); +} + + + +void +draw_set_vertex_buffers(struct draw_context *draw, + unsigned count, + const struct pipe_vertex_buffer *buffers) +{ + assert(count <= PIPE_MAX_ATTRIBS); + + memcpy(draw->pt.vertex_buffer, buffers, count * sizeof(buffers[0])); + draw->pt.nr_vertex_buffers = count; +} + + +void +draw_set_vertex_elements(struct draw_context *draw, + unsigned count, + const struct pipe_vertex_element *elements) +{ + assert(count <= PIPE_MAX_ATTRIBS); + + memcpy(draw->pt.vertex_element, elements, count * sizeof(elements[0])); + draw->pt.nr_vertex_elements = count; +} + + +/** + * Tell drawing context where to find mapped vertex buffers. + */ +void +draw_set_mapped_vertex_buffer(struct draw_context *draw, + unsigned attr, const void *buffer) +{ + draw->pt.user.vbuffer[attr] = buffer; +} + + +void +draw_set_mapped_constant_buffer(struct draw_context *draw, + unsigned shader_type, + unsigned slot, + const void *buffer, + unsigned size ) +{ + debug_assert(shader_type == PIPE_SHADER_VERTEX || + shader_type == PIPE_SHADER_GEOMETRY); + debug_assert(slot < PIPE_MAX_CONSTANT_BUFFERS); + + switch (shader_type) { + case PIPE_SHADER_VERTEX: + draw->pt.user.vs_constants[slot] = buffer; + draw->pt.user.vs_constants_size[slot] = size; + draw->pt.user.planes = (float (*) [12][4]) &(draw->plane[0]); + draw_vs_set_constants(draw, slot, buffer, size); + break; + case PIPE_SHADER_GEOMETRY: + draw->pt.user.gs_constants[slot] = buffer; + draw->pt.user.gs_constants_size[slot] = size; + draw_gs_set_constants(draw, slot, buffer, size); + break; + default: + assert(0 && "invalid shader type in draw_set_mapped_constant_buffer"); + } +} + + +/** + * Tells the draw module to draw points with triangles if their size + * is greater than this threshold. + */ +void +draw_wide_point_threshold(struct draw_context *draw, float threshold) +{ + draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE ); + draw->pipeline.wide_point_threshold = threshold; +} + + +/** + * Should the draw module handle point->quad conversion for drawing sprites? + */ +void +draw_wide_point_sprites(struct draw_context *draw, boolean draw_sprite) +{ + draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE ); + draw->pipeline.wide_point_sprites = draw_sprite; +} + + +/** + * Tells the draw module to draw lines with triangles if their width + * is greater than this threshold. + */ +void +draw_wide_line_threshold(struct draw_context *draw, float threshold) +{ + draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE ); + draw->pipeline.wide_line_threshold = threshold; +} + + +/** + * Tells the draw module whether or not to implement line stipple. + */ +void +draw_enable_line_stipple(struct draw_context *draw, boolean enable) +{ + draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE ); + draw->pipeline.line_stipple = enable; +} + + +/** + * Tells draw module whether to convert points to quads for sprite mode. + */ +void +draw_enable_point_sprites(struct draw_context *draw, boolean enable) +{ + draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE ); + draw->pipeline.point_sprite = enable; +} + + +void +draw_set_force_passthrough( struct draw_context *draw, boolean enable ) +{ + draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE ); + draw->force_passthrough = enable; +} + + + +/** + * Allocate an extra vertex/geometry shader vertex attribute. + * This is used by some of the optional draw module stages such + * as wide_point which may need to allocate additional generic/texcoord + * attributes. + */ +int +draw_alloc_extra_vertex_attrib(struct draw_context *draw, + uint semantic_name, uint semantic_index) +{ + const int num_outputs = draw_current_shader_outputs(draw); + const int n = draw->extra_shader_outputs.num; + + assert(n < Elements(draw->extra_shader_outputs.semantic_name)); + + draw->extra_shader_outputs.semantic_name[n] = semantic_name; + draw->extra_shader_outputs.semantic_index[n] = semantic_index; + draw->extra_shader_outputs.slot[n] = num_outputs + n; + draw->extra_shader_outputs.num++; + + return draw->extra_shader_outputs.slot[n]; +} + + +/** + * Remove all extra vertex attributes that were allocated with + * draw_alloc_extra_vertex_attrib(). + */ +void +draw_remove_extra_vertex_attribs(struct draw_context *draw) +{ + draw->extra_shader_outputs.num = 0; +} + + +/** + * Ask the draw module for the location/slot of the given vertex attribute in + * a post-transformed vertex. + * + * With this function, drivers that use the draw module should have no reason + * to track the current vertex/geometry shader. + * + * Note that the draw module may sometimes generate vertices with extra + * attributes (such as texcoords for AA lines). The driver can call this + * function to find those attributes. + * + * Zero is returned if the attribute is not found since this is + * a don't care / undefined situtation. Returning -1 would be a bit more + * work for the drivers. + */ +int +draw_find_shader_output(const struct draw_context *draw, + uint semantic_name, uint semantic_index) +{ + const struct draw_vertex_shader *vs = draw->vs.vertex_shader; + const struct draw_geometry_shader *gs = draw->gs.geometry_shader; + uint i; + const struct tgsi_shader_info *info = &vs->info; + + if (gs) + info = &gs->info; + + for (i = 0; i < info->num_outputs; i++) { + if (info->output_semantic_name[i] == semantic_name && + info->output_semantic_index[i] == semantic_index) + return i; + } + + /* Search the extra vertex attributes */ + for (i = 0; i < draw->extra_shader_outputs.num; i++) { + if (draw->extra_shader_outputs.semantic_name[i] == semantic_name && + draw->extra_shader_outputs.semantic_index[i] == semantic_index) { + return draw->extra_shader_outputs.slot[i]; + } + } + + return 0; +} + + +/** + * Return total number of the shader outputs. This function is similar to + * draw_current_shader_outputs() but this function also counts any extra + * vertex/geometry output attributes that may be filled in by some draw + * stages (such as AA point, AA line). + * + * If geometry shader is present, its output will be returned, + * if not vertex shader is used. + */ +uint +draw_num_shader_outputs(const struct draw_context *draw) +{ + uint count; + + /* If a geometry shader is present, its outputs go to the + * driver, else the vertex shader's outputs. + */ + if (draw->gs.geometry_shader) + count = draw->gs.geometry_shader->info.num_outputs; + else + count = draw->vs.vertex_shader->info.num_outputs; + + count += draw->extra_shader_outputs.num; + + return count; +} + + +/** + * Provide TGSI sampler objects for vertex/geometry shaders that use + * texture fetches. + * This might only be used by software drivers for the time being. + */ +void +draw_texture_samplers(struct draw_context *draw, + uint shader, + uint num_samplers, + struct tgsi_sampler **samplers) +{ + if (shader == PIPE_SHADER_VERTEX) { + draw->vs.num_samplers = num_samplers; + draw->vs.samplers = samplers; + } else { + debug_assert(shader == PIPE_SHADER_GEOMETRY); + draw->gs.num_samplers = num_samplers; + draw->gs.samplers = samplers; + } +} + + + + +void draw_set_render( struct draw_context *draw, + struct vbuf_render *render ) +{ + draw->render = render; +} + + +void +draw_set_index_buffer(struct draw_context *draw, + const struct pipe_index_buffer *ib) +{ + if (ib) + memcpy(&draw->pt.index_buffer, ib, sizeof(draw->pt.index_buffer)); + else + memset(&draw->pt.index_buffer, 0, sizeof(draw->pt.index_buffer)); +} + + +/** + * Tell drawing context where to find mapped index/element buffer. + */ +void +draw_set_mapped_index_buffer(struct draw_context *draw, + const void *elements) +{ + draw->pt.user.elts = elements; +} + + +/* Revamp me please: + */ +void draw_do_flush( struct draw_context *draw, unsigned flags ) +{ + if (!draw->suspend_flushing) + { + assert(!draw->flushing); /* catch inadvertant recursion */ + + draw->flushing = TRUE; + + draw_pipeline_flush( draw, flags ); + + draw->reduced_prim = ~0; /* is reduced_prim needed any more? */ + + draw->flushing = FALSE; + } +} + + +/** + * Return the number of output attributes produced by the geometry + * shader, if present. If no geometry shader, return the number of + * outputs from the vertex shader. + * \sa draw_num_shader_outputs + */ +uint +draw_current_shader_outputs(const struct draw_context *draw) +{ + if (draw->gs.geometry_shader) + return draw->gs.num_gs_outputs; + return draw->vs.num_vs_outputs; +} + + +/** + * Return the index of the shader output which will contain the + * vertex position. + */ +uint +draw_current_shader_position_output(const struct draw_context *draw) +{ + if (draw->gs.geometry_shader) + return draw->gs.position_output; + return draw->vs.position_output; +} + + +/** + * Return a pointer/handle for a driver/CSO rasterizer object which + * disabled culling, stippling, unfilled tris, etc. + * This is used by some pipeline stages (such as wide_point, aa_line + * and aa_point) which convert points/lines into triangles. In those + * cases we don't want to accidentally cull the triangles. + * + * \param scissor should the rasterizer state enable scissoring? + * \param flatshade should the rasterizer state use flat shading? + * \return rasterizer CSO handle + */ +void * +draw_get_rasterizer_no_cull( struct draw_context *draw, + boolean scissor, + boolean flatshade ) +{ + if (!draw->rasterizer_no_cull[scissor][flatshade]) { + /* create now */ + struct pipe_context *pipe = draw->pipe; + struct pipe_rasterizer_state rast; + + memset(&rast, 0, sizeof(rast)); + rast.scissor = scissor; + rast.flatshade = flatshade; + rast.front_ccw = 1; + rast.gl_rasterization_rules = draw->rasterizer->gl_rasterization_rules; + + draw->rasterizer_no_cull[scissor][flatshade] = + pipe->create_rasterizer_state(pipe, &rast); + } + return draw->rasterizer_no_cull[scissor][flatshade]; +} + +void +draw_set_mapped_so_buffers(struct draw_context *draw, + void *buffers[PIPE_MAX_SO_BUFFERS], + unsigned num_buffers) +{ + int i; + + for (i = 0; i < num_buffers; ++i) { + draw->so.buffers[i] = buffers[i]; + } + draw->so.num_buffers = num_buffers; +} + +void +draw_set_so_state(struct draw_context *draw, + struct pipe_stream_output_state *state) +{ + memcpy(&draw->so.state, + state, + sizeof(struct pipe_stream_output_state)); +} + +void +draw_set_sampler_views(struct draw_context *draw, + struct pipe_sampler_view **views, + unsigned num) +{ + unsigned i; + + debug_assert(num <= PIPE_MAX_VERTEX_SAMPLERS); + + for (i = 0; i < num; ++i) + draw->sampler_views[i] = views[i]; + for (i = num; i < PIPE_MAX_VERTEX_SAMPLERS; ++i) + draw->sampler_views[i] = NULL; + + draw->num_sampler_views = num; +} + +void +draw_set_samplers(struct draw_context *draw, + struct pipe_sampler_state **samplers, + unsigned num) +{ + unsigned i; + + debug_assert(num <= PIPE_MAX_VERTEX_SAMPLERS); + + for (i = 0; i < num; ++i) + draw->samplers[i] = samplers[i]; + for (i = num; i < PIPE_MAX_VERTEX_SAMPLERS; ++i) + draw->samplers[i] = NULL; + + draw->num_samplers = num; + +#ifdef HAVE_LLVM + if (draw->llvm) + draw_llvm_set_sampler_state(draw); +#endif +} + +void +draw_set_mapped_texture(struct draw_context *draw, + unsigned sampler_idx, + uint32_t width, uint32_t height, uint32_t depth, + uint32_t last_level, + uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS], + uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS], + const void *data[PIPE_MAX_TEXTURE_LEVELS]) +{ +#ifdef HAVE_LLVM + if(draw->llvm) + draw_llvm_set_mapped_texture(draw, + sampler_idx, + width, height, depth, last_level, + row_stride, img_stride, data); +#endif +} diff --git a/src/gallium/auxiliary/draw/draw_context.h b/src/gallium/auxiliary/draw/draw_context.h new file mode 100644 index 0000000..a0b217e --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_context.h @@ -0,0 +1,257 @@ + +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \brief Public interface into the drawing module. + */ + +/* Authors: Keith Whitwell + */ + + +#ifndef DRAW_CONTEXT_H +#define DRAW_CONTEXT_H + + +#include "pipe/p_state.h" +#include "tgsi/tgsi_exec.h" + +struct pipe_context; +struct draw_context; +struct draw_stage; +struct draw_vertex_shader; +struct draw_geometry_shader; +struct draw_fragment_shader; +struct tgsi_sampler; +struct gallivm_state; + + + +struct draw_context *draw_create( struct pipe_context *pipe ); + +struct draw_context * +draw_create_gallivm(struct pipe_context *pipe, struct gallivm_state *gallivm); + +void draw_destroy( struct draw_context *draw ); + +void draw_flush(struct draw_context *draw); + +void draw_set_viewport_state( struct draw_context *draw, + const struct pipe_viewport_state *viewport ); + +void draw_set_clip_state( struct draw_context *pipe, + const struct pipe_clip_state *clip ); + +void draw_set_rasterizer_state( struct draw_context *draw, + const struct pipe_rasterizer_state *raster, + void *rast_handle ); + +void draw_set_rasterize_stage( struct draw_context *draw, + struct draw_stage *stage ); + +void draw_wide_point_threshold(struct draw_context *draw, float threshold); + +void draw_wide_point_sprites(struct draw_context *draw, boolean draw_sprite); + +void draw_wide_line_threshold(struct draw_context *draw, float threshold); + +void draw_enable_line_stipple(struct draw_context *draw, boolean enable); + +void draw_enable_point_sprites(struct draw_context *draw, boolean enable); + +void draw_set_mrd(struct draw_context *draw, double mrd); + +boolean +draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe); + +boolean +draw_install_aapoint_stage(struct draw_context *draw, struct pipe_context *pipe); + +boolean +draw_install_pstipple_stage(struct draw_context *draw, struct pipe_context *pipe); + + +int +draw_find_shader_output(const struct draw_context *draw, + uint semantic_name, uint semantic_index); + +uint +draw_num_shader_outputs(const struct draw_context *draw); + + +void +draw_texture_samplers(struct draw_context *draw, + uint shader_type, + uint num_samplers, + struct tgsi_sampler **samplers); + +void +draw_set_sampler_views(struct draw_context *draw, + struct pipe_sampler_view **views, + unsigned num); +void +draw_set_samplers(struct draw_context *draw, + struct pipe_sampler_state **samplers, + unsigned num); + +void +draw_set_mapped_texture(struct draw_context *draw, + unsigned sampler_idx, + uint32_t width, uint32_t height, uint32_t depth, + uint32_t last_level, + uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS], + uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS], + const void *data[PIPE_MAX_TEXTURE_LEVELS]); + + +/* + * Vertex shader functions + */ + +struct draw_vertex_shader * +draw_create_vertex_shader(struct draw_context *draw, + const struct pipe_shader_state *shader); +void draw_bind_vertex_shader(struct draw_context *draw, + struct draw_vertex_shader *dvs); +void draw_delete_vertex_shader(struct draw_context *draw, + struct draw_vertex_shader *dvs); + + +/* + * Fragment shader functions + */ +struct draw_fragment_shader * +draw_create_fragment_shader(struct draw_context *draw, + const struct pipe_shader_state *shader); +void draw_bind_fragment_shader(struct draw_context *draw, + struct draw_fragment_shader *dvs); +void draw_delete_fragment_shader(struct draw_context *draw, + struct draw_fragment_shader *dvs); + +/* + * Geometry shader functions + */ +struct draw_geometry_shader * +draw_create_geometry_shader(struct draw_context *draw, + const struct pipe_shader_state *shader); +void draw_bind_geometry_shader(struct draw_context *draw, + struct draw_geometry_shader *dvs); +void draw_delete_geometry_shader(struct draw_context *draw, + struct draw_geometry_shader *dvs); + + +/* + * Vertex data functions + */ + +void draw_set_vertex_buffers(struct draw_context *draw, + unsigned count, + const struct pipe_vertex_buffer *buffers); + +void draw_set_vertex_elements(struct draw_context *draw, + unsigned count, + const struct pipe_vertex_element *elements); + +void draw_set_index_buffer(struct draw_context *draw, + const struct pipe_index_buffer *ib); + +void draw_set_mapped_index_buffer(struct draw_context *draw, + const void *elements); + +void draw_set_mapped_vertex_buffer(struct draw_context *draw, + unsigned attr, const void *buffer); + +void +draw_set_mapped_constant_buffer(struct draw_context *draw, + unsigned shader_type, + unsigned slot, + const void *buffer, + unsigned size); + +void +draw_set_mapped_so_buffers(struct draw_context *draw, + void *buffers[PIPE_MAX_SO_BUFFERS], + unsigned num_buffers); +void +draw_set_so_state(struct draw_context *draw, + struct pipe_stream_output_state *state); + + +/*********************************************************************** + * draw_pt.c + */ + +void draw_vbo(struct draw_context *draw, + const struct pipe_draw_info *info); + +void draw_arrays(struct draw_context *draw, unsigned prim, + unsigned start, unsigned count); + +void +draw_arrays_instanced(struct draw_context *draw, + unsigned mode, + unsigned start, + unsigned count, + unsigned startInstance, + unsigned instanceCount); + + +/******************************************************************************* + * Driver backend interface + */ +struct vbuf_render; +void draw_set_render( struct draw_context *draw, + struct vbuf_render *render ); + +void draw_set_driver_clipping( struct draw_context *draw, + boolean bypass_clip_xy, + boolean bypass_clip_z ); + +void draw_set_force_passthrough( struct draw_context *draw, + boolean enable ); + +/******************************************************************************* + * Draw pipeline + */ +boolean draw_need_pipeline(const struct draw_context *draw, + const struct pipe_rasterizer_state *rasterizer, + unsigned prim ); + +static INLINE int +draw_get_shader_param(unsigned shader, enum pipe_cap param) +{ + switch(shader) { + case PIPE_SHADER_VERTEX: + case PIPE_SHADER_GEOMETRY: + return tgsi_exec_get_shader_param(param); + default: + return 0; + } +} + +#endif /* DRAW_CONTEXT_H */ diff --git a/src/gallium/auxiliary/draw/draw_decompose_tmp.h b/src/gallium/auxiliary/draw/draw_decompose_tmp.h new file mode 100644 index 0000000..a142563 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_decompose_tmp.h @@ -0,0 +1,431 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Keith Whitwell + * Chia-I Wu + */ + +/* these macros are optional */ +#ifndef LOCAL_VARS +#define LOCAL_VARS +#endif +#ifndef FUNC_ENTER +#define FUNC_ENTER do {} while (0) +#endif +#ifndef FUNC_EXIT +#define FUNC_EXIT do {} while (0) +#endif +#ifndef LINE_ADJ +#define LINE_ADJ(flags, a0, i0, i1, a1) LINE(flags, i0, i1) +#endif +#ifndef TRIANGLE_ADJ +#define TRIANGLE_ADJ(flags, i0, a0, i1, a1, i2, a2) TRIANGLE(flags, i0, i1, i2) +#endif + +static void +FUNC(FUNC_VARS) +{ + unsigned idx[6], i; + ushort flags; + LOCAL_VARS + + FUNC_ENTER; + + /* prim, prim_flags, count, and last_vertex_last should have been defined */ + if (0) { + debug_printf("%s: prim 0x%x, prim_flags 0x%x, count %d, last_vertex_last %d\n", + __FUNCTION__, prim, prim_flags, count, last_vertex_last); + } + + switch (prim) { + case PIPE_PRIM_POINTS: + for (i = 0; i < count; i++) { + idx[0] = GET_ELT(i); + POINT(idx[0]); + } + break; + + case PIPE_PRIM_LINES: + flags = DRAW_PIPE_RESET_STIPPLE; + for (i = 0; i + 1 < count; i += 2) { + idx[0] = GET_ELT(i); + idx[1] = GET_ELT(i + 1); + LINE(flags, idx[0], idx[1]); + } + break; + + case PIPE_PRIM_LINE_LOOP: + case PIPE_PRIM_LINE_STRIP: + if (count >= 2) { + flags = (prim_flags & DRAW_SPLIT_BEFORE) ? 0 : DRAW_PIPE_RESET_STIPPLE; + idx[1] = GET_ELT(0); + idx[2] = idx[1]; + + for (i = 1; i < count; i++, flags = 0) { + idx[0] = idx[1]; + idx[1] = GET_ELT(i); + LINE(flags, idx[0], idx[1]); + } + /* close the loop */ + if (prim == PIPE_PRIM_LINE_LOOP && !prim_flags) + LINE(flags, idx[1], idx[2]); + } + break; + + case PIPE_PRIM_TRIANGLES: + flags = DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL; + for (i = 0; i + 2 < count; i += 3) { + idx[0] = GET_ELT(i); + idx[1] = GET_ELT(i + 1); + idx[2] = GET_ELT(i + 2); + TRIANGLE(flags, idx[0], idx[1], idx[2]); + } + break; + + case PIPE_PRIM_TRIANGLE_STRIP: + if (count >= 3) { + flags = DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL; + idx[1] = GET_ELT(0); + idx[2] = GET_ELT(1); + + if (last_vertex_last) { + for (i = 0; i + 2 < count; i++) { + idx[0] = idx[1]; + idx[1] = idx[2]; + idx[2] = GET_ELT(i + 2); + /* always emit idx[2] last */ + if (i & 1) + TRIANGLE(flags, idx[1], idx[0], idx[2]); + else + TRIANGLE(flags, idx[0], idx[1], idx[2]); + } + } + else { + for (i = 0; i + 2 < count; i++) { + idx[0] = idx[1]; + idx[1] = idx[2]; + idx[2] = GET_ELT(i + 2); + /* always emit idx[0] first */ + if (i & 1) + TRIANGLE(flags, idx[0], idx[2], idx[1]); + else + TRIANGLE(flags, idx[0], idx[1], idx[2]); + } + } + } + break; + + case PIPE_PRIM_TRIANGLE_FAN: + if (count >= 3) { + flags = DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL; + idx[0] = GET_ELT(0); + idx[2] = GET_ELT(1); + + /* idx[0] is neither the first nor the last vertex */ + if (last_vertex_last) { + for (i = 0; i + 2 < count; i++) { + idx[1] = idx[2]; + idx[2] = GET_ELT(i + 2); + /* always emit idx[2] last */ + TRIANGLE(flags, idx[0], idx[1], idx[2]); + } + } + else { + for (i = 0; i + 2 < count; i++) { + idx[1] = idx[2]; + idx[2] = GET_ELT(i + 2); + /* always emit idx[1] first */ + TRIANGLE(flags, idx[1], idx[2], idx[0]); + } + } + } + break; + + case PIPE_PRIM_QUADS: + if (last_vertex_last) { + for (i = 0; i + 3 < count; i += 4) { + idx[0] = GET_ELT(i); + idx[1] = GET_ELT(i + 1); + idx[2] = GET_ELT(i + 2); + idx[3] = GET_ELT(i + 3); + + flags = DRAW_PIPE_RESET_STIPPLE | + DRAW_PIPE_EDGE_FLAG_0 | + DRAW_PIPE_EDGE_FLAG_2; + /* always emit idx[3] last */ + TRIANGLE(flags, idx[0], idx[1], idx[3]); + + flags = DRAW_PIPE_EDGE_FLAG_0 | + DRAW_PIPE_EDGE_FLAG_1; + TRIANGLE(flags, idx[1], idx[2], idx[3]); + } + } + else { + for (i = 0; i + 3 < count; i += 4) { + idx[0] = GET_ELT(i); + idx[1] = GET_ELT(i + 1); + idx[2] = GET_ELT(i + 2); + idx[3] = GET_ELT(i + 3); + + flags = DRAW_PIPE_RESET_STIPPLE | + DRAW_PIPE_EDGE_FLAG_0 | + DRAW_PIPE_EDGE_FLAG_1; + /* XXX should always emit idx[0] first */ + /* always emit idx[3] first */ + TRIANGLE(flags, idx[3], idx[0], idx[1]); + + flags = DRAW_PIPE_EDGE_FLAG_1 | + DRAW_PIPE_EDGE_FLAG_2; + TRIANGLE(flags, idx[3], idx[1], idx[2]); + } + } + break; + + case PIPE_PRIM_QUAD_STRIP: + if (count >= 4) { + idx[2] = GET_ELT(0); + idx[3] = GET_ELT(1); + + if (last_vertex_last) { + for (i = 0; i + 3 < count; i += 2) { + idx[0] = idx[2]; + idx[1] = idx[3]; + idx[2] = GET_ELT(i + 2); + idx[3] = GET_ELT(i + 3); + + /* always emit idx[3] last */ + flags = DRAW_PIPE_RESET_STIPPLE | + DRAW_PIPE_EDGE_FLAG_0 | + DRAW_PIPE_EDGE_FLAG_2; + TRIANGLE(flags, idx[2], idx[0], idx[3]); + + flags = DRAW_PIPE_EDGE_FLAG_0 | + DRAW_PIPE_EDGE_FLAG_1; + TRIANGLE(flags, idx[0], idx[1], idx[3]); + } + } + else { + for (i = 0; i + 3 < count; i += 2) { + idx[0] = idx[2]; + idx[1] = idx[3]; + idx[2] = GET_ELT(i + 2); + idx[3] = GET_ELT(i + 3); + + flags = DRAW_PIPE_RESET_STIPPLE | + DRAW_PIPE_EDGE_FLAG_0 | + DRAW_PIPE_EDGE_FLAG_1; + /* XXX should always emit idx[0] first */ + /* always emit idx[3] first */ + TRIANGLE(flags, idx[3], idx[2], idx[0]); + + flags = DRAW_PIPE_EDGE_FLAG_1 | + DRAW_PIPE_EDGE_FLAG_2; + TRIANGLE(flags, idx[3], idx[0], idx[1]); + } + } + } + break; + + case PIPE_PRIM_POLYGON: + if (count >= 3) { + ushort edge_next, edge_finish; + + if (last_vertex_last) { + flags = (DRAW_PIPE_RESET_STIPPLE | + DRAW_PIPE_EDGE_FLAG_0); + if (!(prim_flags & DRAW_SPLIT_BEFORE)) + flags |= DRAW_PIPE_EDGE_FLAG_2; + + edge_next = DRAW_PIPE_EDGE_FLAG_0; + edge_finish = + (prim_flags & DRAW_SPLIT_AFTER) ? 0 : DRAW_PIPE_EDGE_FLAG_1; + } + else { + flags = (DRAW_PIPE_RESET_STIPPLE | + DRAW_PIPE_EDGE_FLAG_1); + if (!(prim_flags & DRAW_SPLIT_BEFORE)) + flags |= DRAW_PIPE_EDGE_FLAG_0; + + edge_next = DRAW_PIPE_EDGE_FLAG_1; + edge_finish = + (prim_flags & DRAW_SPLIT_AFTER) ? 0 : DRAW_PIPE_EDGE_FLAG_2; + } + + idx[0] = GET_ELT(0); + idx[2] = GET_ELT(1); + + for (i = 0; i + 2 < count; i++, flags = edge_next) { + idx[1] = idx[2]; + idx[2] = GET_ELT(i + 2); + + if (i + 3 == count) + flags |= edge_finish; + + /* idx[0] is both the first and the last vertex */ + if (last_vertex_last) + TRIANGLE(flags, idx[1], idx[2], idx[0]); + else + TRIANGLE(flags, idx[0], idx[1], idx[2]); + } + } + break; + + case PIPE_PRIM_LINES_ADJACENCY: + flags = DRAW_PIPE_RESET_STIPPLE; + for (i = 0; i + 3 < count; i += 4) { + idx[0] = GET_ELT(i); + idx[1] = GET_ELT(i + 1); + idx[2] = GET_ELT(i + 2); + idx[3] = GET_ELT(i + 3); + LINE_ADJ(flags, idx[0], idx[1], idx[2], idx[3]); + } + break; + + case PIPE_PRIM_LINE_STRIP_ADJACENCY: + if (count >= 4) { + flags = (prim_flags & DRAW_SPLIT_BEFORE) ? 0 : DRAW_PIPE_RESET_STIPPLE; + idx[1] = GET_ELT(0); + idx[2] = GET_ELT(1); + idx[3] = GET_ELT(2); + + for (i = 1; i + 2 < count; i++, flags = 0) { + idx[0] = idx[1]; + idx[1] = idx[2]; + idx[2] = idx[3]; + idx[3] = GET_ELT(i + 2); + LINE_ADJ(flags, idx[0], idx[1], idx[2], idx[3]); + } + } + break; + + case PIPE_PRIM_TRIANGLES_ADJACENCY: + flags = DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL; + for (i = 0; i + 5 < count; i += 6) { + idx[0] = GET_ELT(i); + idx[1] = GET_ELT(i + 1); + idx[2] = GET_ELT(i + 2); + idx[3] = GET_ELT(i + 3); + idx[4] = GET_ELT(i + 4); + idx[5] = GET_ELT(i + 5); + TRIANGLE_ADJ(flags, idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]); + } + break; + + case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY: + if (count >= 6) { + flags = DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL; + idx[0] = GET_ELT(1); + idx[2] = GET_ELT(0); + idx[4] = GET_ELT(2); + idx[3] = GET_ELT(4); + + /* + * The vertices of the i-th triangle are stored in + * idx[0,2,4] = { 2*i, 2*i+2, 2*i+4 }; + * + * The adjacent vertices are stored in + * idx[1,3,5] = { 2*i-2, 2*i+6, 2*i+3 }. + * + * However, there are two exceptions: + * + * For the first triangle, idx[1] = 1; + * For the last triangle, idx[3] = 2*i+5. + */ + if (last_vertex_last) { + for (i = 0; i + 5 < count; i += 2) { + idx[1] = idx[0]; + + idx[0] = idx[2]; + idx[2] = idx[4]; + idx[4] = idx[3]; + + idx[3] = GET_ELT(i + ((i + 7 < count) ? 6 : 5)); + idx[5] = GET_ELT(i + 3); + + /* + * alternate the first two vertices (idx[0] and idx[2]) and the + * corresponding adjacent vertices (idx[3] and idx[5]) to have + * the correct orientation + */ + if (i & 2) { + TRIANGLE_ADJ(flags, + idx[2], idx[1], idx[0], idx[5], idx[4], idx[3]); + } + else { + TRIANGLE_ADJ(flags, + idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]); + } + } + } + else { + for (i = 0; i + 5 < count; i += 2) { + idx[1] = idx[0]; + + idx[0] = idx[2]; + idx[2] = idx[4]; + idx[4] = idx[3]; + + idx[3] = GET_ELT(i + ((i + 7 < count) ? 6 : 5)); + idx[5] = GET_ELT(i + 3); + + /* + * alternate the last two vertices (idx[2] and idx[4]) and the + * corresponding adjacent vertices (idx[1] and idx[5]) to have + * the correct orientation + */ + if (i & 2) { + TRIANGLE_ADJ(flags, + idx[0], idx[5], idx[4], idx[3], idx[2], idx[1]); + } + else { + TRIANGLE_ADJ(flags, + idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]); + } + } + } + } + break; + + default: + assert(0); + break; + } + + FUNC_EXIT; +} + +#undef LOCAL_VARS +#undef FUNC_ENTER +#undef FUNC_EXIT +#undef LINE_ADJ +#undef TRIANGLE_ADJ + +#undef FUNC +#undef FUNC_VARS +#undef GET_ELT +#undef POINT +#undef LINE +#undef TRIANGLE diff --git a/src/gallium/auxiliary/draw/draw_fs.c b/src/gallium/auxiliary/draw/draw_fs.c new file mode 100644 index 0000000..1543bd8 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_fs.c @@ -0,0 +1,73 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "pipe/p_shader_tokens.h" + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_prim.h" + +#include "tgsi/tgsi_parse.h" + +#include "draw_fs.h" +#include "draw_private.h" +#include "draw_context.h" + + +struct draw_fragment_shader * +draw_create_fragment_shader(struct draw_context *draw, + const struct pipe_shader_state *shader) +{ + struct draw_fragment_shader *dfs; + + dfs = CALLOC_STRUCT(draw_fragment_shader); + if (dfs) { + dfs->base = *shader; + tgsi_scan_shader(shader->tokens, &dfs->info); + } + + return dfs; +} + + +void +draw_bind_fragment_shader(struct draw_context *draw, + struct draw_fragment_shader *dfs) +{ + draw_do_flush(draw, DRAW_FLUSH_STATE_CHANGE); + + draw->fs.fragment_shader = dfs; +} + + +void +draw_delete_fragment_shader(struct draw_context *draw, + struct draw_fragment_shader *dfs) +{ + FREE(dfs); +} + diff --git a/src/gallium/auxiliary/draw/draw_fs.h b/src/gallium/auxiliary/draw/draw_fs.h new file mode 100644 index 0000000..44995b8 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_fs.h @@ -0,0 +1,42 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef DRAW_FS_H +#define DRAW_FS_H + + +#include "tgsi/tgsi_scan.h" + + +struct draw_fragment_shader +{ + struct pipe_shader_state base; + struct tgsi_shader_info info; +}; + + +#endif /* DRAW_FS_H */ diff --git a/src/gallium/auxiliary/draw/draw_gs.c b/src/gallium/auxiliary/draw/draw_gs.c new file mode 100644 index 0000000..50a03ac --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_gs.c @@ -0,0 +1,489 @@ +/************************************************************************** + * + * 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 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. + * + **************************************************************************/ + +#include "draw_gs.h" + +#include "draw_private.h" +#include "draw_context.h" + +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_exec.h" + +#include "pipe/p_shader_tokens.h" + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_prim.h" + +/* fixme: move it from here */ +#define MAX_PRIMITIVES 64 + +boolean +draw_gs_init( struct draw_context *draw ) +{ + draw->gs.machine = tgsi_exec_machine_create(); + if (!draw->gs.machine) + return FALSE; + + draw->gs.machine->Primitives = align_malloc( + MAX_PRIMITIVES * sizeof(struct tgsi_exec_vector), 16); + if (!draw->gs.machine->Primitives) + return FALSE; + memset(draw->gs.machine->Primitives, 0, + MAX_PRIMITIVES * sizeof(struct tgsi_exec_vector)); + + return TRUE; +} + +void draw_gs_destroy( struct draw_context *draw ) +{ + if (!draw->gs.machine) + return; + + align_free(draw->gs.machine->Primitives); + + tgsi_exec_machine_destroy(draw->gs.machine); +} + +void +draw_gs_set_constants(struct draw_context *draw, + unsigned slot, + const void *constants, + unsigned size) +{ + /* noop. added here for symmetry with the VS + * code and in case we'll ever want to allign + * the constants, e.g. when we'll change to a + * different interpreter */ +} + + +struct draw_geometry_shader * +draw_create_geometry_shader(struct draw_context *draw, + const struct pipe_shader_state *state) +{ + struct draw_geometry_shader *gs; + int i; + + gs = CALLOC_STRUCT(draw_geometry_shader); + + if (!gs) + return NULL; + + gs->draw = draw; + gs->state = *state; + gs->state.tokens = tgsi_dup_tokens(state->tokens); + if (!gs->state.tokens) { + FREE(gs); + return NULL; + } + + tgsi_scan_shader(state->tokens, &gs->info); + + /* setup the defaults */ + gs->input_primitive = PIPE_PRIM_TRIANGLES; + gs->output_primitive = PIPE_PRIM_TRIANGLE_STRIP; + gs->max_output_vertices = 32; + + for (i = 0; i < gs->info.num_properties; ++i) { + if (gs->info.properties[i].name == + TGSI_PROPERTY_GS_INPUT_PRIM) + gs->input_primitive = gs->info.properties[i].data[0]; + else if (gs->info.properties[i].name == + TGSI_PROPERTY_GS_OUTPUT_PRIM) + gs->output_primitive = gs->info.properties[i].data[0]; + else if (gs->info.properties[i].name == + TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES) + gs->max_output_vertices = gs->info.properties[i].data[0]; + } + + gs->machine = draw->gs.machine; + + if (gs) + { + uint i; + for (i = 0; i < gs->info.num_outputs; i++) { + if (gs->info.output_semantic_name[i] == TGSI_SEMANTIC_POSITION && + gs->info.output_semantic_index[i] == 0) + gs->position_output = i; + } + } + + return gs; +} + +void draw_bind_geometry_shader(struct draw_context *draw, + struct draw_geometry_shader *dgs) +{ + draw_do_flush(draw, DRAW_FLUSH_STATE_CHANGE); + + if (dgs) { + draw->gs.geometry_shader = dgs; + draw->gs.num_gs_outputs = dgs->info.num_outputs; + draw->gs.position_output = dgs->position_output; + draw_geometry_shader_prepare(dgs, draw); + } + else { + draw->gs.geometry_shader = NULL; + draw->gs.num_gs_outputs = 0; + } +} + +void draw_delete_geometry_shader(struct draw_context *draw, + struct draw_geometry_shader *dgs) +{ + FREE(dgs); +} + +/*#define DEBUG_OUTPUTS 1*/ +static INLINE void +draw_geometry_fetch_outputs(struct draw_geometry_shader *shader, + int num_primitives, + float (**p_output)[4]) +{ + struct tgsi_exec_machine *machine = shader->machine; + unsigned prim_idx, j, slot; + float (*output)[4]; + + output = *p_output; + + /* Unswizzle all output results. + */ + + for (prim_idx = 0; prim_idx < num_primitives; ++prim_idx) { + unsigned num_verts_per_prim = machine->Primitives[prim_idx]; + shader->primitive_lengths[prim_idx + shader->emitted_primitives] = + machine->Primitives[prim_idx]; + shader->emitted_vertices += num_verts_per_prim; + for (j = 0; j < num_verts_per_prim; j++) { + int idx = (prim_idx * num_verts_per_prim + j) * + shader->info.num_outputs; +#ifdef DEBUG_OUTPUTS + debug_printf("%d) Output vert:\n", idx / shader->info.num_outputs); +#endif + for (slot = 0; slot < shader->info.num_outputs; slot++) { + output[slot][0] = machine->Outputs[idx + slot].xyzw[0].f[0]; + output[slot][1] = machine->Outputs[idx + slot].xyzw[1].f[0]; + output[slot][2] = machine->Outputs[idx + slot].xyzw[2].f[0]; + output[slot][3] = machine->Outputs[idx + slot].xyzw[3].f[0]; +#ifdef DEBUG_OUTPUTS + debug_printf("\t%d: %f %f %f %f\n", slot, + output[slot][0], + output[slot][1], + output[slot][2], + output[slot][3]); +#endif + debug_assert(!util_is_inf_or_nan(output[slot][0])); + } + output = (float (*)[4])((char *)output + shader->vertex_size); + } + } + *p_output = output; + shader->emitted_primitives += num_primitives; +} + +/*#define DEBUG_INPUTS 1*/ +static void draw_fetch_gs_input(struct draw_geometry_shader *shader, + unsigned *indices, + unsigned num_vertices, + unsigned prim_idx) +{ + struct tgsi_exec_machine *machine = shader->machine; + unsigned slot, vs_slot, i; + unsigned input_vertex_stride = shader->input_vertex_stride; + const float (*input_ptr)[4]; + + input_ptr = shader->input; + + for (i = 0; i < num_vertices; ++i) { + const float (*input)[4]; +#if DEBUG_INPUTS + debug_printf("%d) vertex index = %d (prim idx = %d)\n", + i, indices[i], prim_idx); +#endif + input = (const float (*)[4])( + (const char *)input_ptr + (indices[i] * input_vertex_stride)); + for (slot = 0, vs_slot = 0; slot < shader->info.num_inputs; ++slot) { + unsigned idx = i * TGSI_EXEC_MAX_INPUT_ATTRIBS + slot; + if (shader->info.input_semantic_name[slot] == TGSI_SEMANTIC_PRIMID) { + machine->Inputs[idx].xyzw[0].f[prim_idx] = + (float)shader->in_prim_idx; + machine->Inputs[idx].xyzw[1].f[prim_idx] = + (float)shader->in_prim_idx; + machine->Inputs[idx].xyzw[2].f[prim_idx] = + (float)shader->in_prim_idx; + machine->Inputs[idx].xyzw[3].f[prim_idx] = + (float)shader->in_prim_idx; + } else { +#if DEBUG_INPUTS + debug_printf("\tSlot = %d, vs_slot = %d, idx = %d:\n", + slot, vs_slot, idx); +#endif +#if 1 + assert(!util_is_inf_or_nan(input[vs_slot][0])); + assert(!util_is_inf_or_nan(input[vs_slot][1])); + assert(!util_is_inf_or_nan(input[vs_slot][2])); + assert(!util_is_inf_or_nan(input[vs_slot][3])); +#endif + machine->Inputs[idx].xyzw[0].f[prim_idx] = input[vs_slot][0]; + machine->Inputs[idx].xyzw[1].f[prim_idx] = input[vs_slot][1]; + machine->Inputs[idx].xyzw[2].f[prim_idx] = input[vs_slot][2]; + machine->Inputs[idx].xyzw[3].f[prim_idx] = input[vs_slot][3]; +#if DEBUG_INPUTS + debug_printf("\t\t%f %f %f %f\n", + machine->Inputs[idx].xyzw[0].f[prim_idx], + machine->Inputs[idx].xyzw[1].f[prim_idx], + machine->Inputs[idx].xyzw[2].f[prim_idx], + machine->Inputs[idx].xyzw[3].f[prim_idx]); +#endif + ++vs_slot; + } + } + } +} + +static void gs_flush(struct draw_geometry_shader *shader, + unsigned input_primitives) +{ + unsigned out_prim_count; + struct tgsi_exec_machine *machine = shader->machine; + + debug_assert(input_primitives > 0 && + input_primitives < 4); + + tgsi_set_exec_mask(machine, + 1, + input_primitives > 1, + input_primitives > 2, + input_primitives > 3); + + /* run interpreter */ + tgsi_exec_machine_run(machine); + + out_prim_count = + machine->Temps[TGSI_EXEC_TEMP_PRIMITIVE_I].xyzw[TGSI_EXEC_TEMP_PRIMITIVE_C].u[0]; + +#if 0 + debug_printf("PRIM emitted prims = %d (verts=%d), cur prim count = %d\n", + shader->emitted_primitives, shader->emitted_vertices, + out_prim_count); +#endif + draw_geometry_fetch_outputs(shader, out_prim_count, + &shader->tmp_output); +} + +static void gs_point(struct draw_geometry_shader *shader, + int idx) +{ + unsigned indices[1]; + + indices[0] = idx; + + draw_fetch_gs_input(shader, indices, 1, 0); + ++shader->in_prim_idx; + + gs_flush(shader, 1); +} + +static void gs_line(struct draw_geometry_shader *shader, + int i0, int i1) +{ + unsigned indices[2]; + + indices[0] = i0; + indices[1] = i1; + + draw_fetch_gs_input(shader, indices, 2, 0); + ++shader->in_prim_idx; + + gs_flush(shader, 1); +} + +static void gs_line_adj(struct draw_geometry_shader *shader, + int i0, int i1, int i2, int i3) +{ + unsigned indices[4]; + + indices[0] = i0; + indices[1] = i1; + indices[2] = i2; + indices[3] = i3; + + draw_fetch_gs_input(shader, indices, 4, 0); + ++shader->in_prim_idx; + + gs_flush(shader, 1); +} + +static void gs_tri(struct draw_geometry_shader *shader, + int i0, int i1, int i2) +{ + unsigned indices[3]; + + indices[0] = i0; + indices[1] = i1; + indices[2] = i2; + + draw_fetch_gs_input(shader, indices, 3, 0); + ++shader->in_prim_idx; + + gs_flush(shader, 1); +} + +static void gs_tri_adj(struct draw_geometry_shader *shader, + int i0, int i1, int i2, + int i3, int i4, int i5) +{ + unsigned indices[6]; + + indices[0] = i0; + indices[1] = i1; + indices[2] = i2; + indices[3] = i3; + indices[4] = i4; + indices[5] = i5; + + draw_fetch_gs_input(shader, indices, 6, 0); + ++shader->in_prim_idx; + + gs_flush(shader, 1); +} + +#define FUNC gs_run +#define GET_ELT(idx) (idx) +#include "draw_gs_tmp.h" + + +#define FUNC gs_run_elts +#define LOCAL_VARS const ushort *elts = input_prims->elts; +#define GET_ELT(idx) (elts[idx]) +#include "draw_gs_tmp.h" + + +/** + * Execute geometry shader using TGSI interpreter. + */ +int draw_geometry_shader_run(struct draw_geometry_shader *shader, + const void *constants[PIPE_MAX_CONSTANT_BUFFERS], + const unsigned constants_size[PIPE_MAX_CONSTANT_BUFFERS], + const struct draw_vertex_info *input_verts, + const struct draw_prim_info *input_prim, + struct draw_vertex_info *output_verts, + struct draw_prim_info *output_prims ) +{ + const float (*input)[4] = (const float (*)[4])input_verts->verts->data; + unsigned input_stride = input_verts->vertex_size; + unsigned vertex_size = input_verts->vertex_size; + struct tgsi_exec_machine *machine = shader->machine; + unsigned num_input_verts = input_prim->linear ? + input_verts->count : + input_prim->count; + unsigned num_in_primitives = + MAX2(u_gs_prims_for_vertices(input_prim->prim, num_input_verts), + u_gs_prims_for_vertices(shader->input_primitive, num_input_verts)); + unsigned max_out_prims = u_gs_prims_for_vertices(shader->output_primitive, + shader->max_output_vertices) + * num_in_primitives; + + output_verts->vertex_size = input_verts->vertex_size; + output_verts->stride = input_verts->vertex_size; + output_verts->verts = + (struct vertex_header *)MALLOC(input_verts->vertex_size * + num_in_primitives * + shader->max_output_vertices); + + +#if 0 + debug_printf("%s count = %d (in prims # = %d)\n", + __FUNCTION__, num_input_verts, num_in_primitives); + debug_printf("\tlinear = %d, prim_info->count = %d\n", + input_prim->linear, input_prim->count); + debug_printf("\tprimt pipe = %d, shader in = %d, shader out = %d, max out = %d\n", + input_prim->prim, shader->input_primitive, + shader->output_primitive, + shader->max_output_vertices); +#endif + + shader->emitted_vertices = 0; + shader->emitted_primitives = 0; + shader->vertex_size = vertex_size; + shader->tmp_output = (float (*)[4])output_verts->verts->data; + shader->in_prim_idx = 0; + shader->input_vertex_stride = input_stride; + shader->input = input; + if (shader->primitive_lengths) { + FREE(shader->primitive_lengths); + } + shader->primitive_lengths = MALLOC(max_out_prims * sizeof(unsigned)); + + tgsi_exec_set_constant_buffers(machine, PIPE_MAX_CONSTANT_BUFFERS, + constants, constants_size); + + if (input_prim->linear) + gs_run(shader, input_prim, input_verts, + output_prims, output_verts); + else + gs_run_elts(shader, input_prim, input_verts, + output_prims, output_verts); + + /* Update prim_info: + */ + output_prims->linear = TRUE; + output_prims->elts = NULL; + output_prims->start = 0; + output_prims->count = shader->emitted_vertices; + output_prims->prim = shader->output_primitive; + output_prims->flags = 0x0; + output_prims->primitive_lengths = shader->primitive_lengths; + output_prims->primitive_count = shader->emitted_primitives; + output_verts->count = shader->emitted_vertices; + +#if 0 + debug_printf("GS finished, prims = %d, verts = %d\n", + output_prims->primitive_count, + output_verts->count); +#endif + + return shader->emitted_vertices; +} + +void draw_geometry_shader_delete(struct draw_geometry_shader *shader) +{ + FREE((void*) shader->state.tokens); + FREE(shader); +} + +void draw_geometry_shader_prepare(struct draw_geometry_shader *shader, + struct draw_context *draw) +{ + if (shader && shader->machine->Tokens != shader->state.tokens) { + tgsi_exec_machine_bind_shader(shader->machine, + shader->state.tokens, + draw->gs.num_samplers, + draw->gs.samplers); + } +} diff --git a/src/gallium/auxiliary/draw/draw_gs.h b/src/gallium/auxiliary/draw/draw_gs.h new file mode 100644 index 0000000..67bc1aa --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_gs.h @@ -0,0 +1,90 @@ +/************************************************************************** + * + * 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 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. + * + **************************************************************************/ + +#ifndef DRAW_GS_H +#define DRAW_GS_H + +#include "draw_context.h" +#include "draw_private.h" + + +#define MAX_TGSI_PRIMITIVES 4 + +struct draw_context; + +/** + * Private version of the compiled geometry shader + */ +struct draw_geometry_shader { + struct draw_context *draw; + + struct tgsi_exec_machine *machine; + + /* This member will disappear shortly:*/ + struct pipe_shader_state state; + + struct tgsi_shader_info info; + unsigned position_output; + + unsigned max_output_vertices; + unsigned input_primitive; + unsigned output_primitive; + + unsigned *primitive_lengths; + unsigned emitted_vertices; + unsigned emitted_primitives; + + float (*tmp_output)[4]; + unsigned vertex_size; + + unsigned in_prim_idx; + unsigned input_vertex_stride; + const float (*input)[4]; +}; + +/* + * Returns the number of vertices emitted. + * The vertex shader can emit any number of vertices as long as it's + * smaller than the GS_MAX_OUTPUT_VERTICES shader property. + */ +int draw_geometry_shader_run(struct draw_geometry_shader *shader, + const void *constants[PIPE_MAX_CONSTANT_BUFFERS], + const unsigned constants_size[PIPE_MAX_CONSTANT_BUFFERS], + const struct draw_vertex_info *input_verts, + const struct draw_prim_info *input_prim, + struct draw_vertex_info *output_verts, + struct draw_prim_info *output_prims ); + +void draw_geometry_shader_prepare(struct draw_geometry_shader *shader, + struct draw_context *draw); + +void draw_geometry_shader_delete(struct draw_geometry_shader *shader); + +int draw_gs_max_output_vertices(struct draw_geometry_shader *shader, + unsigned pipe_prim); + +#endif diff --git a/src/gallium/auxiliary/draw/draw_gs_tmp.h b/src/gallium/auxiliary/draw/draw_gs_tmp.h new file mode 100644 index 0000000..de7b026 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_gs_tmp.h @@ -0,0 +1,32 @@ +#define FUNC_VARS struct draw_geometry_shader *gs, \ + const struct draw_prim_info *input_prims, \ + const struct draw_vertex_info *input_verts, \ + struct draw_prim_info *output_prims, \ + struct draw_vertex_info *output_verts + +#define FUNC_ENTER \ + /* declare more local vars */ \ + const unsigned prim = input_prims->prim; \ + const unsigned prim_flags = input_prims->flags; \ + const unsigned count = input_prims->count; \ + const boolean last_vertex_last = TRUE; \ + do { \ + debug_assert(input_prims->primitive_count == 1); \ + switch (prim) { \ + case PIPE_PRIM_QUADS: \ + case PIPE_PRIM_QUAD_STRIP: \ + case PIPE_PRIM_POLYGON: \ + debug_assert(!"unexpected primitive type in GS"); \ + return; \ + default: \ + break; \ + } \ + } while (0) \ + +#define POINT(i0) gs_point(gs,i0) +#define LINE(flags,i0,i1) gs_line(gs,i0,i1) +#define TRIANGLE(flags,i0,i1,i2) gs_tri(gs,i0,i1,i2) +#define LINE_ADJ(flags,i0,i1,i2,i3) gs_line_adj(gs,i0,i1,i2,i3) +#define TRIANGLE_ADJ(flags,i0,i1,i2,i3,i4,i5) gs_tri_adj(gs,i0,i1,i2,i3,i4,i5) + +#include "draw_decompose_tmp.h" diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c new file mode 100644 index 0000000..3b8286f --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_llvm.c @@ -0,0 +1,1631 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "draw_llvm.h" + +#include "draw_context.h" +#include "draw_vs.h" + +#include "gallivm/lp_bld_arit.h" +#include "gallivm/lp_bld_logic.h" +#include "gallivm/lp_bld_const.h" +#include "gallivm/lp_bld_swizzle.h" +#include "gallivm/lp_bld_struct.h" +#include "gallivm/lp_bld_type.h" +#include "gallivm/lp_bld_flow.h" +#include "gallivm/lp_bld_debug.h" +#include "gallivm/lp_bld_tgsi.h" +#include "gallivm/lp_bld_printf.h" +#include "gallivm/lp_bld_intr.h" +#include "gallivm/lp_bld_init.h" +#include "gallivm/lp_bld_type.h" + +#include "tgsi/tgsi_exec.h" +#include "tgsi/tgsi_dump.h" + +#include "util/u_math.h" +#include "util/u_pointer.h" +#include "util/u_string.h" +#include "util/u_simple_list.h" + + +#define DEBUG_STORE 0 + + +/** + * This function is called by the gallivm "garbage collector" when + * the LLVM global data structures are freed. We must free all LLVM-related + * data. Specifically, all JIT'd shader variants. + */ +static void +draw_llvm_garbage_collect_callback(void *cb_data) +{ + struct draw_llvm *llvm = (struct draw_llvm *) cb_data; + struct draw_llvm_variant_list_item *li; + + /* free all shader variants */ + li = first_elem(&llvm->vs_variants_list); + while (!at_end(&llvm->vs_variants_list, li)) { + struct draw_llvm_variant_list_item *next = next_elem(li); + draw_llvm_destroy_variant(li->base); + li = next; + } + + /* Null-out these pointers so they get remade next time they're needed. + * See the accessor functions below. + */ + llvm->context_ptr_type = NULL; + llvm->buffer_ptr_type = NULL; + llvm->vb_ptr_type = NULL; + llvm->vertex_header_ptr_type = NULL; +} + + +static void +draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *var); + +static void +draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *var); + + +/** + * Create LLVM type for struct draw_jit_texture + */ +static LLVMTypeRef +create_jit_texture_type(struct gallivm_state *gallivm) +{ + LLVMTargetDataRef target = gallivm->target; + LLVMTypeRef texture_type; + LLVMTypeRef elem_types[DRAW_JIT_TEXTURE_NUM_FIELDS]; + LLVMTypeRef int32_type = LLVMInt32TypeInContext(gallivm->context); + + elem_types[DRAW_JIT_TEXTURE_WIDTH] = + elem_types[DRAW_JIT_TEXTURE_HEIGHT] = + elem_types[DRAW_JIT_TEXTURE_DEPTH] = + elem_types[DRAW_JIT_TEXTURE_LAST_LEVEL] = int32_type; + elem_types[DRAW_JIT_TEXTURE_ROW_STRIDE] = + elem_types[DRAW_JIT_TEXTURE_IMG_STRIDE] = + LLVMArrayType(int32_type, PIPE_MAX_TEXTURE_LEVELS); + elem_types[DRAW_JIT_TEXTURE_DATA] = + LLVMArrayType(LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0), + PIPE_MAX_TEXTURE_LEVELS); + elem_types[DRAW_JIT_TEXTURE_MIN_LOD] = + elem_types[DRAW_JIT_TEXTURE_MAX_LOD] = + elem_types[DRAW_JIT_TEXTURE_LOD_BIAS] = LLVMFloatTypeInContext(gallivm->context); + elem_types[DRAW_JIT_TEXTURE_BORDER_COLOR] = + LLVMArrayType(LLVMFloatTypeInContext(gallivm->context), 4); + + texture_type = LLVMStructTypeInContext(gallivm->context, elem_types, + Elements(elem_types), 0); + + /* Make sure the target's struct layout cache doesn't return + * stale/invalid data. + */ + LLVMInvalidateStructLayout(gallivm->target, texture_type); + + LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, width, + target, texture_type, + DRAW_JIT_TEXTURE_WIDTH); + LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, height, + target, texture_type, + DRAW_JIT_TEXTURE_HEIGHT); + LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, depth, + target, texture_type, + DRAW_JIT_TEXTURE_DEPTH); + LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, last_level, + target, texture_type, + DRAW_JIT_TEXTURE_LAST_LEVEL); + LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, row_stride, + target, texture_type, + DRAW_JIT_TEXTURE_ROW_STRIDE); + LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, img_stride, + target, texture_type, + DRAW_JIT_TEXTURE_IMG_STRIDE); + LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, data, + target, texture_type, + DRAW_JIT_TEXTURE_DATA); + LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, min_lod, + target, texture_type, + DRAW_JIT_TEXTURE_MIN_LOD); + LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, max_lod, + target, texture_type, + DRAW_JIT_TEXTURE_MAX_LOD); + LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, lod_bias, + target, texture_type, + DRAW_JIT_TEXTURE_LOD_BIAS); + LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, border_color, + target, texture_type, + DRAW_JIT_TEXTURE_BORDER_COLOR); + + LP_CHECK_STRUCT_SIZE(struct draw_jit_texture, target, texture_type); + + return texture_type; +} + + +/** + * Create LLVM type for struct draw_jit_texture + */ +static LLVMTypeRef +create_jit_context_type(struct gallivm_state *gallivm, + LLVMTypeRef texture_type) +{ + LLVMTargetDataRef target = gallivm->target; + LLVMTypeRef float_type = LLVMFloatTypeInContext(gallivm->context); + LLVMTypeRef elem_types[5]; + LLVMTypeRef context_type; + + elem_types[0] = LLVMPointerType(float_type, 0); /* vs_constants */ + elem_types[1] = LLVMPointerType(float_type, 0); /* gs_constants */ + elem_types[2] = LLVMPointerType(LLVMArrayType(LLVMArrayType(float_type, 4), 12), 0); /* planes */ + elem_types[3] = LLVMPointerType(float_type, 0); /* viewport */ + elem_types[4] = LLVMArrayType(texture_type, + PIPE_MAX_VERTEX_SAMPLERS); /* textures */ + + context_type = LLVMStructTypeInContext(gallivm->context, elem_types, + Elements(elem_types), 0); + + LLVMInvalidateStructLayout(gallivm->target, context_type); + + LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, vs_constants, + target, context_type, 0); + LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, gs_constants, + target, context_type, 1); + LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, planes, + target, context_type, 2); + LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, textures, + target, context_type, + DRAW_JIT_CTX_TEXTURES); + LP_CHECK_STRUCT_SIZE(struct draw_jit_context, + target, context_type); + + return context_type; +} + + +/** + * Create LLVM type for struct pipe_vertex_buffer + */ +static LLVMTypeRef +create_jit_vertex_buffer_type(struct gallivm_state *gallivm) +{ + LLVMTargetDataRef target = gallivm->target; + LLVMTypeRef elem_types[4]; + LLVMTypeRef vb_type; + + elem_types[0] = + elem_types[1] = + elem_types[2] = LLVMInt32TypeInContext(gallivm->context); + elem_types[3] = LLVMPointerType(LLVMOpaqueTypeInContext(gallivm->context), 0); /* vs_constants */ + + vb_type = LLVMStructTypeInContext(gallivm->context, elem_types, + Elements(elem_types), 0); + + LLVMInvalidateStructLayout(gallivm->target, vb_type); + + LP_CHECK_MEMBER_OFFSET(struct pipe_vertex_buffer, stride, + target, vb_type, 0); + LP_CHECK_MEMBER_OFFSET(struct pipe_vertex_buffer, buffer_offset, + target, vb_type, 2); + + LP_CHECK_STRUCT_SIZE(struct pipe_vertex_buffer, target, vb_type); + + return vb_type; +} + + +/** + * Create LLVM type for struct vertex_header; + */ +static LLVMTypeRef +create_jit_vertex_header(struct gallivm_state *gallivm, int data_elems) +{ + LLVMTargetDataRef target = gallivm->target; + LLVMTypeRef elem_types[3]; + LLVMTypeRef vertex_header; + char struct_name[24]; + + util_snprintf(struct_name, 23, "vertex_header%d", data_elems); + + elem_types[0] = LLVMIntTypeInContext(gallivm->context, 32); + elem_types[1] = LLVMArrayType(LLVMFloatTypeInContext(gallivm->context), 4); + elem_types[2] = LLVMArrayType(elem_types[1], data_elems); + + vertex_header = LLVMStructTypeInContext(gallivm->context, elem_types, + Elements(elem_types), 0); + + LLVMInvalidateStructLayout(gallivm->target, vertex_header); + + /* these are bit-fields and we can't take address of them + LP_CHECK_MEMBER_OFFSET(struct vertex_header, clipmask, + target, vertex_header, + DRAW_JIT_VERTEX_CLIPMASK); + LP_CHECK_MEMBER_OFFSET(struct vertex_header, edgeflag, + target, vertex_header, + DRAW_JIT_VERTEX_EDGEFLAG); + LP_CHECK_MEMBER_OFFSET(struct vertex_header, pad, + target, vertex_header, + DRAW_JIT_VERTEX_PAD); + LP_CHECK_MEMBER_OFFSET(struct vertex_header, vertex_id, + target, vertex_header, + DRAW_JIT_VERTEX_VERTEX_ID); + */ + LP_CHECK_MEMBER_OFFSET(struct vertex_header, clip, + target, vertex_header, + DRAW_JIT_VERTEX_CLIP); + LP_CHECK_MEMBER_OFFSET(struct vertex_header, data, + target, vertex_header, + DRAW_JIT_VERTEX_DATA); + + LLVMAddTypeName(gallivm->module, struct_name, vertex_header); + + return vertex_header; +} + + +/** + * Create LLVM types for various structures. + */ +static void +create_jit_types(struct draw_llvm *llvm) +{ + struct gallivm_state *gallivm = llvm->gallivm; + LLVMTypeRef texture_type, context_type, buffer_type, vb_type; + + texture_type = create_jit_texture_type(gallivm); + LLVMAddTypeName(gallivm->module, "texture", texture_type); + + context_type = create_jit_context_type(gallivm, texture_type); + LLVMAddTypeName(gallivm->module, "draw_jit_context", context_type); + llvm->context_ptr_type = LLVMPointerType(context_type, 0); + + buffer_type = LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 8), 0); + LLVMAddTypeName(gallivm->module, "buffer", buffer_type); + llvm->buffer_ptr_type = LLVMPointerType(buffer_type, 0); + + vb_type = create_jit_vertex_buffer_type(gallivm); + LLVMAddTypeName(gallivm->module, "pipe_vertex_buffer", vb_type); + llvm->vb_ptr_type = LLVMPointerType(vb_type, 0); +} + + +static LLVMTypeRef +get_context_ptr_type(struct draw_llvm *llvm) +{ + if (!llvm->context_ptr_type) + create_jit_types(llvm); + return llvm->context_ptr_type; +} + + +static LLVMTypeRef +get_buffer_ptr_type(struct draw_llvm *llvm) +{ + if (!llvm->buffer_ptr_type) + create_jit_types(llvm); + return llvm->buffer_ptr_type; +} + + +static LLVMTypeRef +get_vb_ptr_type(struct draw_llvm *llvm) +{ + if (!llvm->vb_ptr_type) + create_jit_types(llvm); + return llvm->vb_ptr_type; +} + +static LLVMTypeRef +get_vertex_header_ptr_type(struct draw_llvm *llvm) +{ + if (!llvm->vertex_header_ptr_type) + create_jit_types(llvm); + return llvm->vertex_header_ptr_type; +} + + +/** + * Create per-context LLVM info. + */ +struct draw_llvm * +draw_llvm_create(struct draw_context *draw, struct gallivm_state *gallivm) +{ + struct draw_llvm *llvm; + + llvm = CALLOC_STRUCT( draw_llvm ); + if (!llvm) + return NULL; + + lp_build_init(); + + llvm->draw = draw; + llvm->gallivm = gallivm; + + if (gallivm_debug & GALLIVM_DEBUG_IR) { + LLVMDumpModule(llvm->gallivm->module); + } + + llvm->nr_variants = 0; + make_empty_list(&llvm->vs_variants_list); + + gallivm_register_garbage_collector_callback( + draw_llvm_garbage_collect_callback, llvm); + + return llvm; +} + + +/** + * Free per-context LLVM info. + */ +void +draw_llvm_destroy(struct draw_llvm *llvm) +{ + gallivm_remove_garbage_collector_callback( + draw_llvm_garbage_collect_callback, llvm); + + /* XXX free other draw_llvm data? */ + FREE(llvm); +} + + +/** + * Create LLVM-generated code for a vertex shader. + */ +struct draw_llvm_variant * +draw_llvm_create_variant(struct draw_llvm *llvm, + unsigned num_inputs, + const struct draw_llvm_variant_key *key) +{ + struct draw_llvm_variant *variant; + struct llvm_vertex_shader *shader = + llvm_vertex_shader(llvm->draw->vs.vertex_shader); + LLVMTypeRef vertex_header; + + variant = MALLOC(sizeof *variant + + shader->variant_key_size - + sizeof variant->key); + if (variant == NULL) + return NULL; + + variant->llvm = llvm; + + memcpy(&variant->key, key, shader->variant_key_size); + + vertex_header = create_jit_vertex_header(llvm->gallivm, num_inputs); + + llvm->vertex_header_ptr_type = LLVMPointerType(vertex_header, 0); + + draw_llvm_generate(llvm, variant); + draw_llvm_generate_elts(llvm, variant); + + variant->shader = shader; + variant->list_item_global.base = variant; + variant->list_item_local.base = variant; + /*variant->no = */shader->variants_created++; + variant->list_item_global.base = variant; + + return variant; +} + +static void +generate_vs(struct draw_llvm *llvm, + LLVMBuilderRef builder, + LLVMValueRef (*outputs)[NUM_CHANNELS], + const LLVMValueRef (*inputs)[NUM_CHANNELS], + LLVMValueRef context_ptr, + struct lp_build_sampler_soa *draw_sampler) +{ + const struct tgsi_token *tokens = llvm->draw->vs.vertex_shader->state.tokens; + struct lp_type vs_type; + LLVMValueRef consts_ptr = draw_jit_context_vs_constants(llvm->gallivm, context_ptr); + struct lp_build_sampler_soa *sampler = 0; + + memset(&vs_type, 0, sizeof vs_type); + vs_type.floating = TRUE; /* floating point values */ + vs_type.sign = TRUE; /* values are signed */ + vs_type.norm = FALSE; /* values are not limited to [0,1] or [-1,1] */ + vs_type.width = 32; /* 32-bit float */ + vs_type.length = 4; /* 4 elements per vector */ +#if 0 + num_vs = 4; /* number of vertices per block */ +#endif + + if (gallivm_debug & GALLIVM_DEBUG_IR) { + tgsi_dump(tokens, 0); + } + + if (llvm->draw->num_sampler_views && + llvm->draw->num_samplers) + sampler = draw_sampler; + + lp_build_tgsi_soa(llvm->gallivm, + tokens, + vs_type, + NULL /*struct lp_build_mask_context *mask*/, + consts_ptr, + NULL /*pos*/, + inputs, + outputs, + sampler, + &llvm->draw->vs.vertex_shader->info); +} + +#if DEBUG_STORE +static void print_vectorf(LLVMBuilderRef builder, + LLVMValueRef vec) +{ + LLVMValueRef val[4]; + val[0] = LLVMBuildExtractElement(builder, vec, + lp_build_const_int32(gallivm, 0), ""); + val[1] = LLVMBuildExtractElement(builder, vec, + lp_build_const_int32(gallivm, 1), ""); + val[2] = LLVMBuildExtractElement(builder, vec, + lp_build_const_int32(gallivm, 2), ""); + val[3] = LLVMBuildExtractElement(builder, vec, + lp_build_const_int32(gallivm, 3), ""); + lp_build_printf(builder, "vector = [%f, %f, %f, %f]\n", + val[0], val[1], val[2], val[3]); +} +#endif + +static void +generate_fetch(struct gallivm_state *gallivm, + LLVMValueRef vbuffers_ptr, + LLVMValueRef *res, + struct pipe_vertex_element *velem, + LLVMValueRef vbuf, + LLVMValueRef index, + LLVMValueRef instance_id) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef indices = + LLVMConstInt(LLVMInt64TypeInContext(gallivm->context), + velem->vertex_buffer_index, 0); + LLVMValueRef vbuffer_ptr = LLVMBuildGEP(builder, vbuffers_ptr, + &indices, 1, ""); + LLVMValueRef vb_stride = draw_jit_vbuffer_stride(gallivm, vbuf); + LLVMValueRef vb_max_index = draw_jit_vbuffer_max_index(gallivm, vbuf); + LLVMValueRef vb_buffer_offset = draw_jit_vbuffer_offset(gallivm, vbuf); + LLVMValueRef cond; + LLVMValueRef stride; + + if (velem->instance_divisor) { + /* array index = instance_id / instance_divisor */ + index = LLVMBuildUDiv(builder, instance_id, + lp_build_const_int32(gallivm, velem->instance_divisor), + "instance_divisor"); + } + + /* limit index to min(index, vb_max_index) */ + cond = LLVMBuildICmp(builder, LLVMIntULE, index, vb_max_index, ""); + index = LLVMBuildSelect(builder, cond, index, vb_max_index, ""); + + stride = LLVMBuildMul(builder, vb_stride, index, ""); + + vbuffer_ptr = LLVMBuildLoad(builder, vbuffer_ptr, "vbuffer"); + + stride = LLVMBuildAdd(builder, stride, + vb_buffer_offset, + ""); + stride = LLVMBuildAdd(builder, stride, + lp_build_const_int32(gallivm, velem->src_offset), + ""); + + /*lp_build_printf(builder, "vbuf index = %d, stride is %d\n", indices, stride);*/ + vbuffer_ptr = LLVMBuildGEP(builder, vbuffer_ptr, &stride, 1, ""); + + *res = draw_llvm_translate_from(gallivm, vbuffer_ptr, velem->src_format); +} + +static LLVMValueRef +aos_to_soa(struct gallivm_state *gallivm, + LLVMValueRef val0, + LLVMValueRef val1, + LLVMValueRef val2, + LLVMValueRef val3, + LLVMValueRef channel) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef ex, res; + + ex = LLVMBuildExtractElement(builder, val0, + channel, ""); + res = LLVMBuildInsertElement(builder, + LLVMConstNull(LLVMTypeOf(val0)), + ex, + lp_build_const_int32(gallivm, 0), + ""); + + ex = LLVMBuildExtractElement(builder, val1, + channel, ""); + res = LLVMBuildInsertElement(builder, + res, ex, + lp_build_const_int32(gallivm, 1), + ""); + + ex = LLVMBuildExtractElement(builder, val2, + channel, ""); + res = LLVMBuildInsertElement(builder, + res, ex, + lp_build_const_int32(gallivm, 2), + ""); + + ex = LLVMBuildExtractElement(builder, val3, + channel, ""); + res = LLVMBuildInsertElement(builder, + res, ex, + lp_build_const_int32(gallivm, 3), + ""); + + return res; +} + +static void +soa_to_aos(struct gallivm_state *gallivm, + LLVMValueRef soa[NUM_CHANNELS], + LLVMValueRef aos[NUM_CHANNELS]) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef comp; + int i = 0; + + debug_assert(NUM_CHANNELS == 4); + + aos[0] = LLVMConstNull(LLVMTypeOf(soa[0])); + aos[1] = aos[2] = aos[3] = aos[0]; + + for (i = 0; i < NUM_CHANNELS; ++i) { + LLVMValueRef channel = lp_build_const_int32(gallivm, i); + + comp = LLVMBuildExtractElement(builder, soa[i], + lp_build_const_int32(gallivm, 0), ""); + aos[0] = LLVMBuildInsertElement(builder, aos[0], comp, channel, ""); + + comp = LLVMBuildExtractElement(builder, soa[i], + lp_build_const_int32(gallivm, 1), ""); + aos[1] = LLVMBuildInsertElement(builder, aos[1], comp, channel, ""); + + comp = LLVMBuildExtractElement(builder, soa[i], + lp_build_const_int32(gallivm, 2), ""); + aos[2] = LLVMBuildInsertElement(builder, aos[2], comp, channel, ""); + + comp = LLVMBuildExtractElement(builder, soa[i], + lp_build_const_int32(gallivm, 3), ""); + aos[3] = LLVMBuildInsertElement(builder, aos[3], comp, channel, ""); + + } +} + +static void +convert_to_soa(struct gallivm_state *gallivm, + LLVMValueRef (*aos)[NUM_CHANNELS], + LLVMValueRef (*soa)[NUM_CHANNELS], + int num_attribs) +{ + int i; + + debug_assert(NUM_CHANNELS == 4); + + for (i = 0; i < num_attribs; ++i) { + LLVMValueRef val0 = aos[i][0]; + LLVMValueRef val1 = aos[i][1]; + LLVMValueRef val2 = aos[i][2]; + LLVMValueRef val3 = aos[i][3]; + + soa[i][0] = aos_to_soa(gallivm, val0, val1, val2, val3, + lp_build_const_int32(gallivm, 0)); + soa[i][1] = aos_to_soa(gallivm, val0, val1, val2, val3, + lp_build_const_int32(gallivm, 1)); + soa[i][2] = aos_to_soa(gallivm, val0, val1, val2, val3, + lp_build_const_int32(gallivm, 2)); + soa[i][3] = aos_to_soa(gallivm, val0, val1, val2, val3, + lp_build_const_int32(gallivm, 3)); + } +} + +static void +store_aos(struct gallivm_state *gallivm, + LLVMValueRef io_ptr, + LLVMValueRef index, + LLVMValueRef value, + LLVMValueRef clipmask) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef id_ptr = draw_jit_header_id(gallivm, io_ptr); + LLVMValueRef data_ptr = draw_jit_header_data(gallivm, io_ptr); + LLVMValueRef indices[3]; + LLVMValueRef val, shift; + + indices[0] = lp_build_const_int32(gallivm, 0); + indices[1] = index; + indices[2] = lp_build_const_int32(gallivm, 0); + + /* initialize vertex id:16 = 0xffff, pad:3 = 0, edgeflag:1 = 1 */ + val = lp_build_const_int32(gallivm, 0xffff1); + shift = lp_build_const_int32(gallivm, 12); + val = LLVMBuildShl(builder, val, shift, ""); + /* add clipmask:12 */ + val = LLVMBuildOr(builder, val, clipmask, ""); + + /* store vertex header */ + LLVMBuildStore(builder, val, id_ptr); + + +#if DEBUG_STORE + lp_build_printf(builder, " ---- %p storing attribute %d (io = %p)\n", data_ptr, index, io_ptr); +#endif +#if 0 + /*lp_build_printf(builder, " ---- %p storing at %d (%p) ", io_ptr, index, data_ptr); + print_vectorf(builder, value);*/ + data_ptr = LLVMBuildBitCast(builder, data_ptr, + LLVMPointerType(LLVMArrayType(LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4), 0), 0), + "datavec"); + data_ptr = LLVMBuildGEP(builder, data_ptr, indices, 2, ""); + + LLVMBuildStore(builder, value, data_ptr); +#else + { + LLVMValueRef x, y, z, w; + LLVMValueRef idx0, idx1, idx2, idx3; + LLVMValueRef gep0, gep1, gep2, gep3; + data_ptr = LLVMBuildGEP(builder, data_ptr, indices, 3, ""); + + idx0 = lp_build_const_int32(gallivm, 0); + idx1 = lp_build_const_int32(gallivm, 1); + idx2 = lp_build_const_int32(gallivm, 2); + idx3 = lp_build_const_int32(gallivm, 3); + + x = LLVMBuildExtractElement(builder, value, + idx0, ""); + y = LLVMBuildExtractElement(builder, value, + idx1, ""); + z = LLVMBuildExtractElement(builder, value, + idx2, ""); + w = LLVMBuildExtractElement(builder, value, + idx3, ""); + + gep0 = LLVMBuildGEP(builder, data_ptr, &idx0, 1, ""); + gep1 = LLVMBuildGEP(builder, data_ptr, &idx1, 1, ""); + gep2 = LLVMBuildGEP(builder, data_ptr, &idx2, 1, ""); + gep3 = LLVMBuildGEP(builder, data_ptr, &idx3, 1, ""); + + /*lp_build_printf(builder, "##### x = %f (%p), y = %f (%p), z = %f (%p), w = %f (%p)\n", + x, gep0, y, gep1, z, gep2, w, gep3);*/ + LLVMBuildStore(builder, x, gep0); + LLVMBuildStore(builder, y, gep1); + LLVMBuildStore(builder, z, gep2); + LLVMBuildStore(builder, w, gep3); + } +#endif +} + +static void +store_aos_array(struct gallivm_state *gallivm, + LLVMValueRef io_ptr, + LLVMValueRef aos[NUM_CHANNELS], + int attrib, + int num_outputs, + LLVMValueRef clipmask) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef attr_index = lp_build_const_int32(gallivm, attrib); + LLVMValueRef ind0 = lp_build_const_int32(gallivm, 0); + LLVMValueRef ind1 = lp_build_const_int32(gallivm, 1); + LLVMValueRef ind2 = lp_build_const_int32(gallivm, 2); + LLVMValueRef ind3 = lp_build_const_int32(gallivm, 3); + LLVMValueRef io0_ptr, io1_ptr, io2_ptr, io3_ptr; + LLVMValueRef clipmask0, clipmask1, clipmask2, clipmask3; + + debug_assert(NUM_CHANNELS == 4); + + io0_ptr = LLVMBuildGEP(builder, io_ptr, + &ind0, 1, ""); + io1_ptr = LLVMBuildGEP(builder, io_ptr, + &ind1, 1, ""); + io2_ptr = LLVMBuildGEP(builder, io_ptr, + &ind2, 1, ""); + io3_ptr = LLVMBuildGEP(builder, io_ptr, + &ind3, 1, ""); + + clipmask0 = LLVMBuildExtractElement(builder, clipmask, + ind0, ""); + clipmask1 = LLVMBuildExtractElement(builder, clipmask, + ind1, ""); + clipmask2 = LLVMBuildExtractElement(builder, clipmask, + ind2, ""); + clipmask3 = LLVMBuildExtractElement(builder, clipmask, + ind3, ""); + +#if DEBUG_STORE + lp_build_printf(builder, "io = %p, indexes[%d, %d, %d, %d]\n, clipmask0 = %x, clipmask1 = %x, clipmask2 = %x, clipmask3 = %x\n", + io_ptr, ind0, ind1, ind2, ind3, clipmask0, clipmask1, clipmask2, clipmask3); +#endif + /* store for each of the 4 vertices */ + store_aos(gallivm, io0_ptr, attr_index, aos[0], clipmask0); + store_aos(gallivm, io1_ptr, attr_index, aos[1], clipmask1); + store_aos(gallivm, io2_ptr, attr_index, aos[2], clipmask2); + store_aos(gallivm, io3_ptr, attr_index, aos[3], clipmask3); +} + +static void +convert_to_aos(struct gallivm_state *gallivm, + LLVMValueRef io, + LLVMValueRef (*outputs)[NUM_CHANNELS], + LLVMValueRef clipmask, + int num_outputs, + int max_vertices) +{ + LLVMBuilderRef builder = gallivm->builder; + unsigned chan, attrib; + +#if DEBUG_STORE + lp_build_printf(builder, " # storing begin\n"); +#endif + for (attrib = 0; attrib < num_outputs; ++attrib) { + LLVMValueRef soa[4]; + LLVMValueRef aos[4]; + for(chan = 0; chan < NUM_CHANNELS; ++chan) { + if(outputs[attrib][chan]) { + LLVMValueRef out = LLVMBuildLoad(builder, outputs[attrib][chan], ""); + lp_build_name(out, "output%u.%c", attrib, "xyzw"[chan]); + /*lp_build_printf(builder, "output %d : %d ", + LLVMConstInt(LLVMInt32Type(), attrib, 0), + LLVMConstInt(LLVMInt32Type(), chan, 0)); + print_vectorf(builder, out);*/ + soa[chan] = out; + } else + soa[chan] = 0; + } + soa_to_aos(gallivm, soa, aos); + store_aos_array(gallivm, + io, + aos, + attrib, + num_outputs, + clipmask); + } +#if DEBUG_STORE + lp_build_printf(builder, " # storing end\n"); +#endif +} + +/* + * Stores original vertex positions in clip coordinates + * There is probably a more efficient way to do this, 4 floats at once + * rather than extracting each element one by one. + */ +static void +store_clip(struct gallivm_state *gallivm, + LLVMValueRef io_ptr, + LLVMValueRef (*outputs)[NUM_CHANNELS]) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef out[4]; + LLVMValueRef indices[2]; + LLVMValueRef io0_ptr, io1_ptr, io2_ptr, io3_ptr; + LLVMValueRef clip_ptr0, clip_ptr1, clip_ptr2, clip_ptr3; + LLVMValueRef clip0_ptr, clip1_ptr, clip2_ptr, clip3_ptr; + LLVMValueRef out0elem, out1elem, out2elem, out3elem; + int i; + + LLVMValueRef ind0 = lp_build_const_int32(gallivm, 0); + LLVMValueRef ind1 = lp_build_const_int32(gallivm, 1); + LLVMValueRef ind2 = lp_build_const_int32(gallivm, 2); + LLVMValueRef ind3 = lp_build_const_int32(gallivm, 3); + + indices[0] = + indices[1] = lp_build_const_int32(gallivm, 0); + + out[0] = LLVMBuildLoad(builder, outputs[0][0], ""); /*x0 x1 x2 x3*/ + out[1] = LLVMBuildLoad(builder, outputs[0][1], ""); /*y0 y1 y2 y3*/ + out[2] = LLVMBuildLoad(builder, outputs[0][2], ""); /*z0 z1 z2 z3*/ + out[3] = LLVMBuildLoad(builder, outputs[0][3], ""); /*w0 w1 w2 w3*/ + + io0_ptr = LLVMBuildGEP(builder, io_ptr, &ind0, 1, ""); + io1_ptr = LLVMBuildGEP(builder, io_ptr, &ind1, 1, ""); + io2_ptr = LLVMBuildGEP(builder, io_ptr, &ind2, 1, ""); + io3_ptr = LLVMBuildGEP(builder, io_ptr, &ind3, 1, ""); + + clip_ptr0 = draw_jit_header_clip(gallivm, io0_ptr); + clip_ptr1 = draw_jit_header_clip(gallivm, io1_ptr); + clip_ptr2 = draw_jit_header_clip(gallivm, io2_ptr); + clip_ptr3 = draw_jit_header_clip(gallivm, io3_ptr); + + for (i = 0; i<4; i++){ + clip0_ptr = LLVMBuildGEP(builder, clip_ptr0, indices, 2, ""); /* x0 */ + clip1_ptr = LLVMBuildGEP(builder, clip_ptr1, indices, 2, ""); /* x1 */ + clip2_ptr = LLVMBuildGEP(builder, clip_ptr2, indices, 2, ""); /* x2 */ + clip3_ptr = LLVMBuildGEP(builder, clip_ptr3, indices, 2, ""); /* x3 */ + + out0elem = LLVMBuildExtractElement(builder, out[i], ind0, ""); /* x0 */ + out1elem = LLVMBuildExtractElement(builder, out[i], ind1, ""); /* x1 */ + out2elem = LLVMBuildExtractElement(builder, out[i], ind2, ""); /* x2 */ + out3elem = LLVMBuildExtractElement(builder, out[i], ind3, ""); /* x3 */ + + LLVMBuildStore(builder, out0elem, clip0_ptr); + LLVMBuildStore(builder, out1elem, clip1_ptr); + LLVMBuildStore(builder, out2elem, clip2_ptr); + LLVMBuildStore(builder, out3elem, clip3_ptr); + + indices[1]= LLVMBuildAdd(builder, indices[1], ind1, ""); + } + +} + +/* Equivalent of _mm_set1_ps(a) + */ +static LLVMValueRef +vec4f_from_scalar(struct gallivm_state *gallivm, + LLVMValueRef a, + const char *name) +{ + LLVMTypeRef float_type = LLVMFloatTypeInContext(gallivm->context); + LLVMValueRef res = LLVMGetUndef(LLVMVectorType(float_type, 4)); + int i; + + for(i = 0; i < 4; ++i) { + LLVMValueRef index = lp_build_const_int32(gallivm, i); + res = LLVMBuildInsertElement(gallivm->builder, res, a, + index, i == 3 ? name : ""); + } + + return res; +} + +/* + * Transforms the outputs for viewport mapping + */ +static void +generate_viewport(struct draw_llvm *llvm, + LLVMBuilderRef builder, + LLVMValueRef (*outputs)[NUM_CHANNELS], + LLVMValueRef context_ptr) +{ + int i; + struct gallivm_state *gallivm = llvm->gallivm; + struct lp_type f32_type = lp_type_float_vec(32); + LLVMValueRef out3 = LLVMBuildLoad(builder, outputs[0][3], ""); /*w0 w1 w2 w3*/ + LLVMValueRef const1 = lp_build_const_vec(gallivm, f32_type, 1.0); /*1.0 1.0 1.0 1.0*/ + LLVMValueRef vp_ptr = draw_jit_context_viewport(gallivm, context_ptr); + + /* for 1/w convention*/ + out3 = LLVMBuildFDiv(builder, const1, out3, ""); + LLVMBuildStore(builder, out3, outputs[0][3]); + + /* Viewport Mapping */ + for (i=0; i<3; i++){ + LLVMValueRef out = LLVMBuildLoad(builder, outputs[0][i], ""); /*x0 x1 x2 x3*/ + LLVMValueRef scale; + LLVMValueRef trans; + LLVMValueRef scale_i; + LLVMValueRef trans_i; + LLVMValueRef index; + + index = lp_build_const_int32(gallivm, i); + scale_i = LLVMBuildGEP(builder, vp_ptr, &index, 1, ""); + + index = lp_build_const_int32(gallivm, i+4); + trans_i = LLVMBuildGEP(builder, vp_ptr, &index, 1, ""); + + scale = vec4f_from_scalar(gallivm, LLVMBuildLoad(builder, scale_i, ""), "scale"); + trans = vec4f_from_scalar(gallivm, LLVMBuildLoad(builder, trans_i, ""), "trans"); + + /* divide by w */ + out = LLVMBuildFMul(builder, out, out3, ""); + /* mult by scale */ + out = LLVMBuildFMul(builder, out, scale, ""); + /* add translation */ + out = LLVMBuildFAdd(builder, out, trans, ""); + + /* store transformed outputs */ + LLVMBuildStore(builder, out, outputs[0][i]); + } + +} + + +/* + * Returns clipmask as 4xi32 bitmask for the 4 vertices + */ +static LLVMValueRef +generate_clipmask(struct gallivm_state *gallivm, + LLVMValueRef (*outputs)[NUM_CHANNELS], + boolean clip_xy, + boolean clip_z, + boolean clip_user, + boolean clip_halfz, + unsigned nr, + LLVMValueRef context_ptr) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef mask; /* stores the <4xi32> clipmasks */ + LLVMValueRef test, temp; + LLVMValueRef zero, shift; + LLVMValueRef pos_x, pos_y, pos_z, pos_w; + LLVMValueRef plane1, planes, plane_ptr, sum; + + unsigned i; + + struct lp_type f32_type = lp_type_float_vec(32); + + mask = lp_build_const_int_vec(gallivm, lp_type_int_vec(32), 0); + temp = lp_build_const_int_vec(gallivm, lp_type_int_vec(32), 0); + zero = lp_build_const_vec(gallivm, f32_type, 0); /* 0.0f 0.0f 0.0f 0.0f */ + shift = lp_build_const_int_vec(gallivm, lp_type_int_vec(32), 1); /* 1 1 1 1 */ + + /* Assuming position stored at output[0] */ + pos_x = LLVMBuildLoad(builder, outputs[0][0], ""); /*x0 x1 x2 x3*/ + pos_y = LLVMBuildLoad(builder, outputs[0][1], ""); /*y0 y1 y2 y3*/ + pos_z = LLVMBuildLoad(builder, outputs[0][2], ""); /*z0 z1 z2 z3*/ + pos_w = LLVMBuildLoad(builder, outputs[0][3], ""); /*w0 w1 w2 w3*/ + + /* Cliptest, for hardwired planes */ + if (clip_xy){ + /* plane 1 */ + test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, pos_x , pos_w); + temp = shift; + test = LLVMBuildAnd(builder, test, temp, ""); + mask = test; + + /* plane 2 */ + test = LLVMBuildFAdd(builder, pos_x, pos_w, ""); + test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, zero, test); + temp = LLVMBuildShl(builder, temp, shift, ""); + test = LLVMBuildAnd(builder, test, temp, ""); + mask = LLVMBuildOr(builder, mask, test, ""); + + /* plane 3 */ + test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, pos_y, pos_w); + temp = LLVMBuildShl(builder, temp, shift, ""); + test = LLVMBuildAnd(builder, test, temp, ""); + mask = LLVMBuildOr(builder, mask, test, ""); + + /* plane 4 */ + test = LLVMBuildFAdd(builder, pos_y, pos_w, ""); + test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, zero, test); + temp = LLVMBuildShl(builder, temp, shift, ""); + test = LLVMBuildAnd(builder, test, temp, ""); + mask = LLVMBuildOr(builder, mask, test, ""); + } + + if (clip_z){ + temp = lp_build_const_int_vec(gallivm, lp_type_int_vec(32), 16); + if (clip_halfz){ + /* plane 5 */ + test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, zero, pos_z); + test = LLVMBuildAnd(builder, test, temp, ""); + mask = LLVMBuildOr(builder, mask, test, ""); + } + else{ + /* plane 5 */ + test = LLVMBuildFAdd(builder, pos_z, pos_w, ""); + test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, zero, test); + test = LLVMBuildAnd(builder, test, temp, ""); + mask = LLVMBuildOr(builder, mask, test, ""); + } + /* plane 6 */ + test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, pos_z, pos_w); + temp = LLVMBuildShl(builder, temp, shift, ""); + test = LLVMBuildAnd(builder, test, temp, ""); + mask = LLVMBuildOr(builder, mask, test, ""); + } + + if (clip_user){ + LLVMValueRef planes_ptr = draw_jit_context_planes(gallivm, context_ptr); + LLVMValueRef indices[3]; + temp = lp_build_const_int_vec(gallivm, lp_type_int_vec(32), 32); + + /* userclip planes */ + for (i = 6; i < nr; i++) { + indices[0] = lp_build_const_int32(gallivm, 0); + indices[1] = lp_build_const_int32(gallivm, i); + + indices[2] = lp_build_const_int32(gallivm, 0); + plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, ""); + plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_x"); + planes = vec4f_from_scalar(gallivm, plane1, "plane4_x"); + sum = LLVMBuildFMul(builder, planes, pos_x, ""); + + indices[2] = lp_build_const_int32(gallivm, 1); + plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, ""); + plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_y"); + planes = vec4f_from_scalar(gallivm, plane1, "plane4_y"); + test = LLVMBuildFMul(builder, planes, pos_y, ""); + sum = LLVMBuildFAdd(builder, sum, test, ""); + + indices[2] = lp_build_const_int32(gallivm, 2); + plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, ""); + plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_z"); + planes = vec4f_from_scalar(gallivm, plane1, "plane4_z"); + test = LLVMBuildFMul(builder, planes, pos_z, ""); + sum = LLVMBuildFAdd(builder, sum, test, ""); + + indices[2] = lp_build_const_int32(gallivm, 3); + plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, ""); + plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_w"); + planes = vec4f_from_scalar(gallivm, plane1, "plane4_w"); + test = LLVMBuildFMul(builder, planes, pos_w, ""); + sum = LLVMBuildFAdd(builder, sum, test, ""); + + test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, zero, sum); + temp = LLVMBuildShl(builder, temp, shift, ""); + test = LLVMBuildAnd(builder, test, temp, ""); + mask = LLVMBuildOr(builder, mask, test, ""); + } + } + return mask; +} + +/* + * Returns boolean if any clipping has occurred + * Used zero/non-zero i32 value to represent boolean + */ +static void +clipmask_bool(struct gallivm_state *gallivm, + LLVMValueRef clipmask, + LLVMValueRef ret_ptr) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef ret = LLVMBuildLoad(builder, ret_ptr, ""); + LLVMValueRef temp; + int i; + + for (i=0; i<4; i++){ + temp = LLVMBuildExtractElement(builder, clipmask, + lp_build_const_int32(gallivm, i) , ""); + ret = LLVMBuildOr(builder, ret, temp, ""); + } + + LLVMBuildStore(builder, ret, ret_ptr); +} + +static void +draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) +{ + struct gallivm_state *gallivm = llvm->gallivm; + LLVMContextRef context = gallivm->context; + LLVMTypeRef int32_type = LLVMInt32TypeInContext(context); + LLVMTypeRef arg_types[8]; + LLVMTypeRef func_type; + LLVMValueRef context_ptr; + LLVMBasicBlockRef block; + LLVMBuilderRef builder; + LLVMValueRef start, end, count, stride, step, io_itr; + LLVMValueRef io_ptr, vbuffers_ptr, vb_ptr; + LLVMValueRef instance_id; + struct draw_context *draw = llvm->draw; + unsigned i, j; + struct lp_build_context bld; + struct lp_build_loop_state lp_loop; + const int max_vertices = 4; + LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][NUM_CHANNELS]; + void *code; + struct lp_build_sampler_soa *sampler = 0; + LLVMValueRef ret, ret_ptr; + boolean bypass_viewport = variant->key.bypass_viewport; + boolean enable_cliptest = variant->key.clip_xy || + variant->key.clip_z || + variant->key.clip_user; + + arg_types[0] = get_context_ptr_type(llvm); /* context */ + arg_types[1] = get_vertex_header_ptr_type(llvm); /* vertex_header */ + arg_types[2] = get_buffer_ptr_type(llvm); /* vbuffers */ + arg_types[3] = int32_type; /* start */ + arg_types[4] = int32_type; /* count */ + arg_types[5] = int32_type; /* stride */ + arg_types[6] = get_vb_ptr_type(llvm); /* pipe_vertex_buffer's */ + arg_types[7] = int32_type; /* instance_id */ + + func_type = LLVMFunctionType(int32_type, arg_types, Elements(arg_types), 0); + + variant->function = LLVMAddFunction(gallivm->module, "draw_llvm_shader", + func_type); + LLVMSetFunctionCallConv(variant->function, LLVMCCallConv); + for(i = 0; i < Elements(arg_types); ++i) + if(LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind) + LLVMAddAttribute(LLVMGetParam(variant->function, i), LLVMNoAliasAttribute); + + context_ptr = LLVMGetParam(variant->function, 0); + io_ptr = LLVMGetParam(variant->function, 1); + vbuffers_ptr = LLVMGetParam(variant->function, 2); + start = LLVMGetParam(variant->function, 3); + count = LLVMGetParam(variant->function, 4); + stride = LLVMGetParam(variant->function, 5); + vb_ptr = LLVMGetParam(variant->function, 6); + instance_id = LLVMGetParam(variant->function, 7); + + lp_build_name(context_ptr, "context"); + lp_build_name(io_ptr, "io"); + lp_build_name(vbuffers_ptr, "vbuffers"); + lp_build_name(start, "start"); + lp_build_name(count, "count"); + lp_build_name(stride, "stride"); + lp_build_name(vb_ptr, "vb"); + lp_build_name(instance_id, "instance_id"); + + /* + * Function body + */ + + block = LLVMAppendBasicBlockInContext(gallivm->context, variant->function, "entry"); + builder = gallivm->builder; + assert(builder); + LLVMPositionBuilderAtEnd(builder, block); + + lp_build_context_init(&bld, llvm->gallivm, lp_type_int(32)); + + end = lp_build_add(&bld, start, count); + + step = lp_build_const_int32(gallivm, max_vertices); + + /* function will return non-zero i32 value if any clipped vertices */ + ret_ptr = lp_build_alloca(gallivm, int32_type, ""); + LLVMBuildStore(builder, lp_build_const_int32(gallivm, 0), ret_ptr); + + /* code generated texture sampling */ + sampler = draw_llvm_sampler_soa_create( + draw_llvm_variant_key_samplers(&variant->key), + context_ptr); + +#if DEBUG_STORE + lp_build_printf(builder, "start = %d, end = %d, step = %d\n", + start, end, step); +#endif + lp_build_loop_begin(&lp_loop, llvm->gallivm, start); + { + LLVMValueRef inputs[PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS]; + LLVMValueRef aos_attribs[PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS] = { { 0 } }; + LLVMValueRef io; + LLVMValueRef clipmask; /* holds the clipmask value */ + const LLVMValueRef (*ptr_aos)[NUM_CHANNELS]; + + io_itr = LLVMBuildSub(builder, lp_loop.counter, start, ""); + io = LLVMBuildGEP(builder, io_ptr, &io_itr, 1, ""); +#if DEBUG_STORE + lp_build_printf(builder, " --- io %d = %p, loop counter %d\n", + io_itr, io, lp_loop.counter); +#endif + for (i = 0; i < NUM_CHANNELS; ++i) { + LLVMValueRef true_index = LLVMBuildAdd( + builder, + lp_loop.counter, + lp_build_const_int32(gallivm, i), ""); + for (j = 0; j < draw->pt.nr_vertex_elements; ++j) { + struct pipe_vertex_element *velem = &draw->pt.vertex_element[j]; + LLVMValueRef vb_index = lp_build_const_int32(gallivm, velem->vertex_buffer_index); + LLVMValueRef vb = LLVMBuildGEP(builder, vb_ptr, + &vb_index, 1, ""); + generate_fetch(llvm->gallivm, vbuffers_ptr, + &aos_attribs[j][i], velem, vb, true_index, + instance_id); + } + } + convert_to_soa(gallivm, aos_attribs, inputs, + draw->pt.nr_vertex_elements); + + ptr_aos = (const LLVMValueRef (*)[NUM_CHANNELS]) inputs; + generate_vs(llvm, + builder, + outputs, + ptr_aos, + context_ptr, + sampler); + + /* store original positions in clip before further manipulation */ + store_clip(gallivm, io, outputs); + + /* do cliptest */ + if (enable_cliptest){ + /* allocate clipmask, assign it integer type */ + clipmask = generate_clipmask(gallivm, outputs, + variant->key.clip_xy, + variant->key.clip_z, + variant->key.clip_user, + variant->key.clip_halfz, + variant->key.nr_planes, + context_ptr); + /* return clipping boolean value for function */ + clipmask_bool(gallivm, clipmask, ret_ptr); + } + else{ + clipmask = lp_build_const_int_vec(gallivm, lp_type_int_vec(32), 0); + } + + /* do viewport mapping */ + if (!bypass_viewport){ + generate_viewport(llvm, builder, outputs, context_ptr); + } + + /* store clipmask in vertex header and positions in data */ + convert_to_aos(gallivm, io, outputs, clipmask, + draw->vs.vertex_shader->info.num_outputs, + max_vertices); + } + + lp_build_loop_end_cond(&lp_loop, end, step, LLVMIntUGE); + + sampler->destroy(sampler); + + ret = LLVMBuildLoad(builder, ret_ptr,""); + LLVMBuildRet(builder, ret); + + /* + * Translate the LLVM IR into machine code. + */ +#ifdef DEBUG + if(LLVMVerifyFunction(variant->function, LLVMPrintMessageAction)) { + lp_debug_dump_value(variant->function); + assert(0); + } +#endif + + LLVMRunFunctionPassManager(gallivm->passmgr, variant->function); + + if (gallivm_debug & GALLIVM_DEBUG_IR) { + lp_debug_dump_value(variant->function); + debug_printf("\n"); + } + + code = LLVMGetPointerToGlobal(gallivm->engine, variant->function); + variant->jit_func = (draw_jit_vert_func)pointer_to_func(code); + + if (gallivm_debug & GALLIVM_DEBUG_ASM) { + lp_disassemble(code); + } + lp_func_delete_body(variant->function); +} + + +static void +draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *variant) +{ + struct gallivm_state *gallivm = llvm->gallivm; + LLVMContextRef context = gallivm->context; + LLVMTypeRef int32_type = LLVMInt32TypeInContext(context); + LLVMTypeRef arg_types[8]; + LLVMTypeRef func_type; + LLVMValueRef context_ptr; + LLVMBasicBlockRef block; + LLVMBuilderRef builder; + LLVMValueRef fetch_elts, fetch_count, stride, step, io_itr; + LLVMValueRef io_ptr, vbuffers_ptr, vb_ptr; + LLVMValueRef instance_id; + struct draw_context *draw = llvm->draw; + unsigned i, j; + struct lp_build_context bld; + struct lp_build_loop_state lp_loop; + const int max_vertices = 4; + LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][NUM_CHANNELS]; + LLVMValueRef fetch_max; + void *code; + struct lp_build_sampler_soa *sampler = 0; + LLVMValueRef ret, ret_ptr; + boolean bypass_viewport = variant->key.bypass_viewport; + boolean enable_cliptest = variant->key.clip_xy || + variant->key.clip_z || + variant->key.clip_user; + + arg_types[0] = get_context_ptr_type(llvm); /* context */ + arg_types[1] = get_vertex_header_ptr_type(llvm); /* vertex_header */ + arg_types[2] = get_buffer_ptr_type(llvm); /* vbuffers */ + arg_types[3] = LLVMPointerType(int32_type, 0); /* fetch_elts * */ + arg_types[4] = int32_type; /* fetch_count */ + arg_types[5] = int32_type; /* stride */ + arg_types[6] = get_vb_ptr_type(llvm); /* pipe_vertex_buffer's */ + arg_types[7] = int32_type; /* instance_id */ + + func_type = LLVMFunctionType(int32_type, arg_types, Elements(arg_types), 0); + + variant->function_elts = LLVMAddFunction(gallivm->module, "draw_llvm_shader_elts", func_type); + LLVMSetFunctionCallConv(variant->function_elts, LLVMCCallConv); + for(i = 0; i < Elements(arg_types); ++i) + if(LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind) + LLVMAddAttribute(LLVMGetParam(variant->function_elts, i), + LLVMNoAliasAttribute); + + context_ptr = LLVMGetParam(variant->function_elts, 0); + io_ptr = LLVMGetParam(variant->function_elts, 1); + vbuffers_ptr = LLVMGetParam(variant->function_elts, 2); + fetch_elts = LLVMGetParam(variant->function_elts, 3); + fetch_count = LLVMGetParam(variant->function_elts, 4); + stride = LLVMGetParam(variant->function_elts, 5); + vb_ptr = LLVMGetParam(variant->function_elts, 6); + instance_id = LLVMGetParam(variant->function_elts, 7); + + lp_build_name(context_ptr, "context"); + lp_build_name(io_ptr, "io"); + lp_build_name(vbuffers_ptr, "vbuffers"); + lp_build_name(fetch_elts, "fetch_elts"); + lp_build_name(fetch_count, "fetch_count"); + lp_build_name(stride, "stride"); + lp_build_name(vb_ptr, "vb"); + lp_build_name(instance_id, "instance_id"); + + /* + * Function body + */ + + block = LLVMAppendBasicBlockInContext(gallivm->context, variant->function_elts, "entry"); + builder = gallivm->builder; + LLVMPositionBuilderAtEnd(builder, block); + + lp_build_context_init(&bld, gallivm, lp_type_int(32)); + + step = lp_build_const_int32(gallivm, max_vertices); + + /* code generated texture sampling */ + sampler = draw_llvm_sampler_soa_create( + draw_llvm_variant_key_samplers(&variant->key), + context_ptr); + + fetch_max = LLVMBuildSub(builder, fetch_count, + lp_build_const_int32(gallivm, 1), + "fetch_max"); + + /* function returns non-zero i32 value if any clipped vertices */ + ret_ptr = lp_build_alloca(gallivm, int32_type, ""); + LLVMBuildStore(builder, lp_build_const_int32(gallivm, 0), ret_ptr); + + lp_build_loop_begin(&lp_loop, gallivm, lp_build_const_int32(gallivm, 0)); + { + LLVMValueRef inputs[PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS]; + LLVMValueRef aos_attribs[PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS] = { { 0 } }; + LLVMValueRef io; + LLVMValueRef clipmask; /* holds the clipmask value */ + const LLVMValueRef (*ptr_aos)[NUM_CHANNELS]; + + io_itr = lp_loop.counter; + io = LLVMBuildGEP(builder, io_ptr, &io_itr, 1, ""); +#if DEBUG_STORE + lp_build_printf(builder, " --- io %d = %p, loop counter %d\n", + io_itr, io, lp_loop.counter); +#endif + for (i = 0; i < NUM_CHANNELS; ++i) { + LLVMValueRef true_index = LLVMBuildAdd( + builder, + lp_loop.counter, + lp_build_const_int32(gallivm, i), ""); + LLVMValueRef fetch_ptr; + + /* make sure we're not out of bounds which can happen + * if fetch_count % 4 != 0, because on the last iteration + * a few of the 4 vertex fetches will be out of bounds */ + true_index = lp_build_min(&bld, true_index, fetch_max); + + fetch_ptr = LLVMBuildGEP(builder, fetch_elts, + &true_index, 1, ""); + true_index = LLVMBuildLoad(builder, fetch_ptr, "fetch_elt"); + for (j = 0; j < draw->pt.nr_vertex_elements; ++j) { + struct pipe_vertex_element *velem = &draw->pt.vertex_element[j]; + LLVMValueRef vb_index = lp_build_const_int32(gallivm, velem->vertex_buffer_index); + LLVMValueRef vb = LLVMBuildGEP(builder, vb_ptr, + &vb_index, 1, ""); + generate_fetch(gallivm, vbuffers_ptr, + &aos_attribs[j][i], velem, vb, true_index, + instance_id); + } + } + convert_to_soa(gallivm, aos_attribs, inputs, + draw->pt.nr_vertex_elements); + + ptr_aos = (const LLVMValueRef (*)[NUM_CHANNELS]) inputs; + generate_vs(llvm, + builder, + outputs, + ptr_aos, + context_ptr, + sampler); + + /* store original positions in clip before further manipulation */ + store_clip(gallivm, io, outputs); + + /* do cliptest */ + if (enable_cliptest){ + /* allocate clipmask, assign it integer type */ + clipmask = generate_clipmask(gallivm, outputs, + variant->key.clip_xy, + variant->key.clip_z, + variant->key.clip_user, + variant->key.clip_halfz, + variant->key.nr_planes, + context_ptr); + /* return clipping boolean value for function */ + clipmask_bool(gallivm, clipmask, ret_ptr); + } + else{ + clipmask = lp_build_const_int_vec(gallivm, lp_type_int_vec(32), 0); + } + + /* do viewport mapping */ + if (!bypass_viewport){ + generate_viewport(llvm, builder, outputs, context_ptr); + } + + /* store clipmask in vertex header, + * original positions in clip + * and transformed positions in data + */ + convert_to_aos(gallivm, io, outputs, clipmask, + draw->vs.vertex_shader->info.num_outputs, + max_vertices); + } + + lp_build_loop_end_cond(&lp_loop, fetch_count, step, LLVMIntUGE); + + sampler->destroy(sampler); + + ret = LLVMBuildLoad(builder, ret_ptr,""); + LLVMBuildRet(builder, ret); + + /* + * Translate the LLVM IR into machine code. + */ +#ifdef DEBUG + if(LLVMVerifyFunction(variant->function_elts, LLVMPrintMessageAction)) { + lp_debug_dump_value(variant->function_elts); + assert(0); + } +#endif + + LLVMRunFunctionPassManager(gallivm->passmgr, variant->function_elts); + + if (gallivm_debug & GALLIVM_DEBUG_IR) { + lp_debug_dump_value(variant->function_elts); + debug_printf("\n"); + } + + code = LLVMGetPointerToGlobal(gallivm->engine, variant->function_elts); + variant->jit_func_elts = (draw_jit_vert_func_elts)pointer_to_func(code); + + if (gallivm_debug & GALLIVM_DEBUG_ASM) { + lp_disassemble(code); + } + lp_func_delete_body(variant->function_elts); +} + + +struct draw_llvm_variant_key * +draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store) +{ + unsigned i; + struct draw_llvm_variant_key *key; + struct lp_sampler_static_state *sampler; + + key = (struct draw_llvm_variant_key *)store; + + /* Presumably all variants of the shader should have the same + * number of vertex elements - ie the number of shader inputs. + */ + key->nr_vertex_elements = llvm->draw->pt.nr_vertex_elements; + + /* will have to rig this up properly later */ + key->clip_xy = llvm->draw->clip_xy; + key->clip_z = llvm->draw->clip_z; + key->clip_user = llvm->draw->clip_user; + key->bypass_viewport = llvm->draw->identity_viewport; + key->clip_halfz = !llvm->draw->rasterizer->gl_rasterization_rules; + key->need_edgeflags = (llvm->draw->vs.edgeflag_output ? TRUE : FALSE); + key->nr_planes = llvm->draw->nr_planes; + key->pad = 0; + + /* All variants of this shader will have the same value for + * nr_samplers. Not yet trying to compact away holes in the + * sampler array. + */ + key->nr_samplers = llvm->draw->vs.vertex_shader->info.file_max[TGSI_FILE_SAMPLER] + 1; + + sampler = draw_llvm_variant_key_samplers(key); + + memcpy(key->vertex_element, + llvm->draw->pt.vertex_element, + sizeof(struct pipe_vertex_element) * key->nr_vertex_elements); + + memset(sampler, 0, key->nr_samplers * sizeof *sampler); + + for (i = 0 ; i < key->nr_samplers; i++) { + lp_sampler_static_state(&sampler[i], + llvm->draw->sampler_views[i], + llvm->draw->samplers[i]); + } + + return key; +} + +void +draw_llvm_set_mapped_texture(struct draw_context *draw, + unsigned sampler_idx, + uint32_t width, uint32_t height, uint32_t depth, + uint32_t last_level, + uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS], + uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS], + const void *data[PIPE_MAX_TEXTURE_LEVELS]) +{ + unsigned j; + struct draw_jit_texture *jit_tex; + + assert(sampler_idx < PIPE_MAX_VERTEX_SAMPLERS); + + + jit_tex = &draw->llvm->jit_context.textures[sampler_idx]; + + jit_tex->width = width; + jit_tex->height = height; + jit_tex->depth = depth; + jit_tex->last_level = last_level; + + for (j = 0; j <= last_level; j++) { + jit_tex->data[j] = data[j]; + jit_tex->row_stride[j] = row_stride[j]; + jit_tex->img_stride[j] = img_stride[j]; + } +} + + +void +draw_llvm_set_sampler_state(struct draw_context *draw) +{ + unsigned i; + + for (i = 0; i < draw->num_samplers; i++) { + struct draw_jit_texture *jit_tex = &draw->llvm->jit_context.textures[i]; + + if (draw->samplers[i]) { + jit_tex->min_lod = draw->samplers[i]->min_lod; + jit_tex->max_lod = draw->samplers[i]->max_lod; + jit_tex->lod_bias = draw->samplers[i]->lod_bias; + COPY_4V(jit_tex->border_color, draw->samplers[i]->border_color); + } + } +} + + +void +draw_llvm_destroy_variant(struct draw_llvm_variant *variant) +{ + struct draw_llvm *llvm = variant->llvm; + + if (variant->function_elts) { + if (variant->function_elts) + LLVMFreeMachineCodeForFunction(llvm->gallivm->engine, + variant->function_elts); + LLVMDeleteFunction(variant->function_elts); + } + + if (variant->function) { + if (variant->function) + LLVMFreeMachineCodeForFunction(llvm->gallivm->engine, + variant->function); + LLVMDeleteFunction(variant->function); + } + + remove_from_list(&variant->list_item_local); + variant->shader->variants_cached--; + remove_from_list(&variant->list_item_global); + llvm->nr_variants--; + FREE(variant); +} diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h new file mode 100644 index 0000000..73c1d92 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_llvm.h @@ -0,0 +1,307 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef DRAW_LLVM_H +#define DRAW_LLVM_H + +#include "draw/draw_private.h" + +#include "draw/draw_vs.h" +#include "gallivm/lp_bld_sample.h" + +#include "pipe/p_context.h" +#include "util/u_simple_list.h" + +#include +#include +#include +#include + + +struct draw_llvm; +struct llvm_vertex_shader; + +struct draw_jit_texture +{ + uint32_t width; + uint32_t height; + uint32_t depth; + uint32_t last_level; + uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS]; + uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS]; + const void *data[PIPE_MAX_TEXTURE_LEVELS]; + float min_lod; + float max_lod; + float lod_bias; + float border_color[4]; +}; + +enum { + DRAW_JIT_TEXTURE_WIDTH = 0, + DRAW_JIT_TEXTURE_HEIGHT, + DRAW_JIT_TEXTURE_DEPTH, + DRAW_JIT_TEXTURE_LAST_LEVEL, + DRAW_JIT_TEXTURE_ROW_STRIDE, + DRAW_JIT_TEXTURE_IMG_STRIDE, + DRAW_JIT_TEXTURE_DATA, + DRAW_JIT_TEXTURE_MIN_LOD, + DRAW_JIT_TEXTURE_MAX_LOD, + DRAW_JIT_TEXTURE_LOD_BIAS, + DRAW_JIT_TEXTURE_BORDER_COLOR, + DRAW_JIT_TEXTURE_NUM_FIELDS /* number of fields above */ +}; + +enum { + DRAW_JIT_VERTEX_VERTEX_ID = 0, + DRAW_JIT_VERTEX_CLIP, + DRAW_JIT_VERTEX_DATA +}; + +/** + * This structure is passed directly to the generated vertex shader. + * + * It contains the derived state. + * + * Changes here must be reflected in the draw_jit_context_* macros. + * Changes to the ordering should be avoided. + * + * Only use types with a clear size and padding here, in particular prefer the + * stdint.h types to the basic integer types. + */ +struct draw_jit_context +{ + const float *vs_constants; + const float *gs_constants; + float (*planes) [12][4]; + float *viewport; + + struct draw_jit_texture textures[PIPE_MAX_VERTEX_SAMPLERS]; +}; + + +#define draw_jit_context_vs_constants(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, 0, "vs_constants") + +#define draw_jit_context_gs_constants(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, 1, "gs_constants") + +#define draw_jit_context_planes(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, 2, "planes") + +#define draw_jit_context_viewport(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, 3, "viewport") + +#define DRAW_JIT_CTX_TEXTURES 4 + +#define draw_jit_context_textures(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_TEXTURES, "textures") + +#define draw_jit_header_id(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, 0, "id") + +#define draw_jit_header_clip(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, 1, "clip") + +#define draw_jit_header_data(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, 2, "data") + + +#define draw_jit_vbuffer_stride(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, 0, "stride") + +#define draw_jit_vbuffer_max_index(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, 1, "max_index") + +#define draw_jit_vbuffer_offset(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, 2, "buffer_offset") + + +typedef int +(*draw_jit_vert_func)(struct draw_jit_context *context, + struct vertex_header *io, + const char *vbuffers[PIPE_MAX_ATTRIBS], + unsigned start, + unsigned count, + unsigned stride, + struct pipe_vertex_buffer *vertex_buffers, + unsigned instance_id); + + +typedef int +(*draw_jit_vert_func_elts)(struct draw_jit_context *context, + struct vertex_header *io, + const char *vbuffers[PIPE_MAX_ATTRIBS], + const unsigned *fetch_elts, + unsigned fetch_count, + unsigned stride, + struct pipe_vertex_buffer *vertex_buffers, + unsigned instance_id); + +struct draw_llvm_variant_key +{ + unsigned nr_vertex_elements:8; + unsigned nr_samplers:8; + unsigned clip_xy:1; + unsigned clip_z:1; + unsigned clip_user:1; + unsigned clip_halfz:1; + unsigned bypass_viewport:1; + unsigned need_edgeflags:1; + unsigned nr_planes:4; + unsigned pad:6; + + /* Variable number of vertex elements: + */ + struct pipe_vertex_element vertex_element[1]; + + /* Followed by variable number of samplers: + */ +/* struct lp_sampler_static_state sampler; */ +}; + +#define DRAW_LLVM_MAX_VARIANT_KEY_SIZE \ + (sizeof(struct draw_llvm_variant_key) + \ + PIPE_MAX_VERTEX_SAMPLERS * sizeof(struct lp_sampler_static_state) + \ + (PIPE_MAX_ATTRIBS-1) * sizeof(struct pipe_vertex_element)) + + +static INLINE size_t +draw_llvm_variant_key_size(unsigned nr_vertex_elements, + unsigned nr_samplers) +{ + return (sizeof(struct draw_llvm_variant_key) + + nr_samplers * sizeof(struct lp_sampler_static_state) + + (nr_vertex_elements - 1) * sizeof(struct pipe_vertex_element)); +} + + +static INLINE struct lp_sampler_static_state * +draw_llvm_variant_key_samplers(struct draw_llvm_variant_key *key) +{ + return (struct lp_sampler_static_state *) + &key->vertex_element[key->nr_vertex_elements]; +} + + + +struct draw_llvm_variant_list_item +{ + struct draw_llvm_variant *base; + struct draw_llvm_variant_list_item *next, *prev; +}; + +struct draw_llvm_variant +{ + LLVMValueRef function; + LLVMValueRef function_elts; + draw_jit_vert_func jit_func; + draw_jit_vert_func_elts jit_func_elts; + + struct llvm_vertex_shader *shader; + + struct draw_llvm *llvm; + struct draw_llvm_variant_list_item list_item_global; + struct draw_llvm_variant_list_item list_item_local; + + /* key is variable-sized, must be last */ + struct draw_llvm_variant_key key; + /* key is variable-sized, must be last */ +}; + +struct llvm_vertex_shader { + struct draw_vertex_shader base; + + unsigned variant_key_size; + struct draw_llvm_variant_list_item variants; + unsigned variants_created; + unsigned variants_cached; +}; + +struct draw_llvm { + struct draw_context *draw; + + struct draw_jit_context jit_context; + + struct gallivm_state *gallivm; + + struct draw_llvm_variant_list_item vs_variants_list; + int nr_variants; + + /* LLVM JIT builder types */ + LLVMTypeRef context_ptr_type; + LLVMTypeRef buffer_ptr_type; + LLVMTypeRef vb_ptr_type; + LLVMTypeRef vertex_header_ptr_type; +}; + + +static INLINE struct llvm_vertex_shader * +llvm_vertex_shader(struct draw_vertex_shader *vs) +{ + return (struct llvm_vertex_shader *)vs; +} + + +struct draw_llvm * +draw_llvm_create(struct draw_context *draw, struct gallivm_state *gallivm); + +void +draw_llvm_destroy(struct draw_llvm *llvm); + +struct draw_llvm_variant * +draw_llvm_create_variant(struct draw_llvm *llvm, + unsigned num_vertex_header_attribs, + const struct draw_llvm_variant_key *key); + +void +draw_llvm_destroy_variant(struct draw_llvm_variant *variant); + +struct draw_llvm_variant_key * +draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store); + +LLVMValueRef +draw_llvm_translate_from(struct gallivm_state *gallivm, + LLVMValueRef vbuffer, + enum pipe_format from_format); + +struct lp_build_sampler_soa * +draw_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state, + LLVMValueRef context_ptr); + +void +draw_llvm_set_sampler_state(struct draw_context *draw); + +void +draw_llvm_set_mapped_texture(struct draw_context *draw, + unsigned sampler_idx, + uint32_t width, uint32_t height, uint32_t depth, + uint32_t last_level, + uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS], + uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS], + const void *data[PIPE_MAX_TEXTURE_LEVELS]); + +#endif diff --git a/src/gallium/auxiliary/draw/draw_llvm_sample.c b/src/gallium/auxiliary/draw/draw_llvm_sample.c new file mode 100644 index 0000000..574c7cc --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_llvm_sample.c @@ -0,0 +1,225 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Texture sampling code generation + * @author Jose Fonseca + */ + +#include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" +#include "gallivm/lp_bld_const.h" +#include "gallivm/lp_bld_debug.h" +#include "gallivm/lp_bld_type.h" +#include "gallivm/lp_bld_sample.h" +#include "gallivm/lp_bld_tgsi.h" + + +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "util/u_pointer.h" +#include "util/u_string.h" + +#include "draw_llvm.h" + + +/** + * This provides the bridge between the sampler state store in + * lp_jit_context and lp_jit_texture and the sampler code + * generator. It provides the texture layout information required by + * the texture sampler code generator in terms of the state stored in + * lp_jit_context and lp_jit_texture in runtime. + */ +struct draw_llvm_sampler_dynamic_state +{ + struct lp_sampler_dynamic_state base; + + const struct lp_sampler_static_state *static_state; + + LLVMValueRef context_ptr; +}; + + +/** + * This is the bridge between our sampler and the TGSI translator. + */ +struct draw_llvm_sampler_soa +{ + struct lp_build_sampler_soa base; + + struct draw_llvm_sampler_dynamic_state dynamic_state; +}; + + +/** + * Fetch the specified member of the lp_jit_texture structure. + * \param emit_load if TRUE, emit the LLVM load instruction to actually + * fetch the field's value. Otherwise, just emit the + * GEP code to address the field. + * + * @sa http://llvm.org/docs/GetElementPtr.html + */ +static LLVMValueRef +draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base, + struct gallivm_state *gallivm, + unsigned unit, + unsigned member_index, + const char *member_name, + boolean emit_load) +{ + LLVMBuilderRef builder = gallivm->builder; + struct draw_llvm_sampler_dynamic_state *state = + (struct draw_llvm_sampler_dynamic_state *)base; + LLVMValueRef indices[4]; + LLVMValueRef ptr; + LLVMValueRef res; + + debug_assert(unit < PIPE_MAX_VERTEX_SAMPLERS); + + /* context[0] */ + indices[0] = lp_build_const_int32(gallivm, 0); + /* context[0].textures */ + indices[1] = lp_build_const_int32(gallivm, DRAW_JIT_CTX_TEXTURES); + /* context[0].textures[unit] */ + indices[2] = lp_build_const_int32(gallivm, unit); + /* context[0].textures[unit].member */ + indices[3] = lp_build_const_int32(gallivm, member_index); + + ptr = LLVMBuildGEP(builder, state->context_ptr, indices, Elements(indices), ""); + + if (emit_load) + res = LLVMBuildLoad(builder, ptr, ""); + else + res = ptr; + + lp_build_name(res, "context.texture%u.%s", unit, member_name); + + return res; +} + + +/** + * Helper macro to instantiate the functions that generate the code to + * fetch the members of lp_jit_texture to fulfill the sampler code + * generator requests. + * + * This complexity is the price we have to pay to keep the texture + * sampler code generator a reusable module without dependencies to + * llvmpipe internals. + */ +#define DRAW_LLVM_TEXTURE_MEMBER(_name, _index, _emit_load) \ + static LLVMValueRef \ + draw_llvm_texture_##_name( const struct lp_sampler_dynamic_state *base, \ + struct gallivm_state *gallivm, \ + unsigned unit) \ + { \ + return draw_llvm_texture_member(base, gallivm, unit, _index, #_name, _emit_load ); \ + } + + +DRAW_LLVM_TEXTURE_MEMBER(width, DRAW_JIT_TEXTURE_WIDTH, TRUE) +DRAW_LLVM_TEXTURE_MEMBER(height, DRAW_JIT_TEXTURE_HEIGHT, TRUE) +DRAW_LLVM_TEXTURE_MEMBER(depth, DRAW_JIT_TEXTURE_DEPTH, TRUE) +DRAW_LLVM_TEXTURE_MEMBER(last_level, DRAW_JIT_TEXTURE_LAST_LEVEL, TRUE) +DRAW_LLVM_TEXTURE_MEMBER(row_stride, DRAW_JIT_TEXTURE_ROW_STRIDE, FALSE) +DRAW_LLVM_TEXTURE_MEMBER(img_stride, DRAW_JIT_TEXTURE_IMG_STRIDE, FALSE) +DRAW_LLVM_TEXTURE_MEMBER(data_ptr, DRAW_JIT_TEXTURE_DATA, FALSE) +DRAW_LLVM_TEXTURE_MEMBER(min_lod, DRAW_JIT_TEXTURE_MIN_LOD, TRUE) +DRAW_LLVM_TEXTURE_MEMBER(max_lod, DRAW_JIT_TEXTURE_MAX_LOD, TRUE) +DRAW_LLVM_TEXTURE_MEMBER(lod_bias, DRAW_JIT_TEXTURE_LOD_BIAS, TRUE) +DRAW_LLVM_TEXTURE_MEMBER(border_color, DRAW_JIT_TEXTURE_BORDER_COLOR, FALSE) + + +static void +draw_llvm_sampler_soa_destroy(struct lp_build_sampler_soa *sampler) +{ + FREE(sampler); +} + + +/** + * Fetch filtered values from texture. + * The 'texel' parameter returns four vectors corresponding to R, G, B, A. + */ +static void +draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base, + struct gallivm_state *gallivm, + struct lp_type type, + unsigned unit, + unsigned num_coords, + const LLVMValueRef *coords, + const LLVMValueRef *ddx, + const LLVMValueRef *ddy, + LLVMValueRef lod_bias, /* optional */ + LLVMValueRef explicit_lod, /* optional */ + LLVMValueRef *texel) +{ + struct draw_llvm_sampler_soa *sampler = (struct draw_llvm_sampler_soa *)base; + + assert(unit < PIPE_MAX_VERTEX_SAMPLERS); + + lp_build_sample_soa(gallivm, + &sampler->dynamic_state.static_state[unit], + &sampler->dynamic_state.base, + type, + unit, + num_coords, coords, + ddx, ddy, + lod_bias, explicit_lod, + texel); +} + + +struct lp_build_sampler_soa * +draw_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state, + LLVMValueRef context_ptr) +{ + struct draw_llvm_sampler_soa *sampler; + + sampler = CALLOC_STRUCT(draw_llvm_sampler_soa); + if(!sampler) + return NULL; + + sampler->base.destroy = draw_llvm_sampler_soa_destroy; + sampler->base.emit_fetch_texel = draw_llvm_sampler_soa_emit_fetch_texel; + sampler->dynamic_state.base.width = draw_llvm_texture_width; + sampler->dynamic_state.base.height = draw_llvm_texture_height; + sampler->dynamic_state.base.depth = draw_llvm_texture_depth; + sampler->dynamic_state.base.last_level = draw_llvm_texture_last_level; + sampler->dynamic_state.base.row_stride = draw_llvm_texture_row_stride; + sampler->dynamic_state.base.img_stride = draw_llvm_texture_img_stride; + sampler->dynamic_state.base.data_ptr = draw_llvm_texture_data_ptr; + sampler->dynamic_state.base.min_lod = draw_llvm_texture_min_lod; + sampler->dynamic_state.base.max_lod = draw_llvm_texture_max_lod; + sampler->dynamic_state.base.lod_bias = draw_llvm_texture_lod_bias; + sampler->dynamic_state.base.border_color = draw_llvm_texture_border_color; + sampler->dynamic_state.static_state = static_state; + sampler->dynamic_state.context_ptr = context_ptr; + + return &sampler->base; +} + diff --git a/src/gallium/auxiliary/draw/draw_llvm_translate.c b/src/gallium/auxiliary/draw/draw_llvm_translate.c new file mode 100644 index 0000000..77d0af7 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_llvm_translate.c @@ -0,0 +1,506 @@ +#include "draw_private.h" +#include "draw_context.h" + +#include "draw_llvm.h" + +#include "gallivm/lp_bld_const.h" +#include "gallivm/lp_bld_struct.h" +#include "gallivm/lp_bld_format.h" +#include "gallivm/lp_bld_debug.h" +#include "gallivm/lp_bld_type.h" + +#include "util/u_memory.h" +#include "util/u_format.h" +#include "pipe/p_state.h" + + +#define DRAW_DBG 0 + +static LLVMValueRef +from_64_float(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val, + LLVMPointerType(LLVMDoubleTypeInContext(gallivm->context), 0) , ""); + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, ""); + return LLVMBuildFPTrunc(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), ""); +} + +static LLVMValueRef +from_32_float(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val, + LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0) , ""); + return LLVMBuildLoad(gallivm->builder, bc, ""); +} + +static INLINE LLVMValueRef +from_8_uscaled(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, ""); + return LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), ""); +} + +static INLINE LLVMValueRef +from_16_uscaled(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val, + LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 16), 0) , ""); + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, ""); + return LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), ""); +} + +static INLINE LLVMValueRef +from_32_uscaled(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val, + LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , ""); + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, ""); + return LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), ""); +} + +static INLINE LLVMValueRef +from_8_sscaled(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, ""); + return LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), ""); +} + +static INLINE LLVMValueRef +from_16_sscaled(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val, + LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 16), 0) , ""); + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, ""); + return LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), ""); +} + +static INLINE LLVMValueRef +from_32_sscaled(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val, + LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , ""); + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, ""); + return LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), ""); +} + + +static INLINE LLVMValueRef +from_8_unorm(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, ""); + LLVMValueRef uscaled = LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), ""); + return LLVMBuildFDiv(gallivm->builder, uscaled, + lp_build_const_float(gallivm, 255.), ""); +} + +static INLINE LLVMValueRef +from_16_unorm(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val, + LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 16), 0) , ""); + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, ""); + LLVMValueRef uscaled = LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), ""); + return LLVMBuildFDiv(gallivm->builder, uscaled, + lp_build_const_float(gallivm, 65535.), ""); +} + +static INLINE LLVMValueRef +from_32_unorm(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val, + LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , ""); + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, ""); + LLVMValueRef uscaled = LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), ""); + + return LLVMBuildFDiv(gallivm->builder, uscaled, + lp_build_const_float(gallivm, 4294967295.), ""); +} + +static INLINE LLVMValueRef +from_8_snorm(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, ""); + LLVMValueRef uscaled = LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), ""); + return LLVMBuildFDiv(gallivm->builder, uscaled, + lp_build_const_float(gallivm, 127.0), ""); +} + +static INLINE LLVMValueRef +from_16_snorm(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val, + LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 16), 0) , ""); + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, ""); + LLVMValueRef uscaled = LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), ""); + return LLVMBuildFDiv(gallivm->builder, uscaled, + lp_build_const_float(gallivm, 32767.0f), ""); +} + +static INLINE LLVMValueRef +from_32_snorm(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val, + LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , ""); + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, ""); + LLVMValueRef uscaled = LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), ""); + + return LLVMBuildFDiv(gallivm->builder, uscaled, + lp_build_const_float(gallivm, 2147483647.0), ""); +} + +static INLINE LLVMValueRef +from_32_fixed(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val, + LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , ""); + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, ""); + LLVMValueRef uscaled = LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), ""); + + return LLVMBuildFDiv(gallivm->builder, uscaled, + lp_build_const_float(gallivm, 65536.0), ""); +} + +static LLVMValueRef +to_64_float(struct gallivm_state *gallivm, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, ""); + return LLVMBuildFPExt(gallivm->builder, l, LLVMDoubleTypeInContext(gallivm->context), ""); +} + +static LLVMValueRef +to_32_float(struct gallivm_state *gallivm, LLVMValueRef fp) +{ + return LLVMBuildLoad(gallivm->builder, fp, ""); +} + +static INLINE LLVMValueRef +to_8_uscaled(struct gallivm_state *gallivm, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, ""); + return LLVMBuildFPToUI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 8), ""); +} + +static INLINE LLVMValueRef +to_16_uscaled(struct gallivm_state *gallivm, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, ""); + return LLVMBuildFPToUI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 16), ""); +} + +static INLINE LLVMValueRef +to_32_uscaled(struct gallivm_state *gallivm, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, ""); + return LLVMBuildFPToUI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 32), ""); +} + +static INLINE LLVMValueRef +to_8_sscaled(struct gallivm_state *gallivm, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, ""); + return LLVMBuildFPToSI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 8), ""); +} + +static INLINE LLVMValueRef +to_16_sscaled(struct gallivm_state *gallivm, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, ""); + return LLVMBuildFPToSI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 16), ""); +} + +static INLINE LLVMValueRef +to_32_sscaled(struct gallivm_state *gallivm, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, ""); + return LLVMBuildFPToSI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 32), ""); +} + +static INLINE LLVMValueRef +to_8_unorm(struct gallivm_state *gallivm, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, ""); + LLVMValueRef uscaled = LLVMBuildFPToUI(gallivm->builder, l, + LLVMIntTypeInContext(gallivm->context, 8), ""); + return LLVMBuildFMul(gallivm->builder, uscaled, + lp_build_const_float(gallivm, 255.), ""); +} + +static INLINE LLVMValueRef +to_16_unorm(struct gallivm_state *gallivm, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, ""); + LLVMValueRef uscaled = LLVMBuildFPToUI(gallivm->builder, l, + LLVMIntTypeInContext(gallivm->context, 32), ""); + return LLVMBuildFMul(gallivm->builder, uscaled, + lp_build_const_float(gallivm, 65535.), ""); +} + +static INLINE LLVMValueRef +to_32_unorm(struct gallivm_state *gallivm, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, ""); + LLVMValueRef uscaled = LLVMBuildFPToUI(gallivm->builder, l, + LLVMIntTypeInContext(gallivm->context, 32), ""); + + return LLVMBuildFMul(gallivm->builder, uscaled, + lp_build_const_float(gallivm, 4294967295.), ""); +} + +static INLINE LLVMValueRef +to_8_snorm(struct gallivm_state *gallivm, LLVMValueRef val) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, ""); + LLVMValueRef uscaled = LLVMBuildFPToSI(gallivm->builder, l, + LLVMIntTypeInContext(gallivm->context, 8), ""); + return LLVMBuildFMul(gallivm->builder, uscaled, + lp_build_const_float(gallivm, 127.0), ""); +} + +static INLINE LLVMValueRef +to_16_snorm(struct gallivm_state *gallivm, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, ""); + LLVMValueRef uscaled = LLVMBuildFPToSI(gallivm->builder, l, + LLVMIntTypeInContext(gallivm->context, 16), ""); + return LLVMBuildFMul(gallivm->builder, uscaled, + lp_build_const_float(gallivm, 32767.0f), ""); +} + +static INLINE LLVMValueRef +to_32_snorm(struct gallivm_state *gallivm, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, ""); + LLVMValueRef uscaled = LLVMBuildFPToSI(gallivm->builder, l, + LLVMIntTypeInContext(gallivm->context, 32), ""); + + return LLVMBuildFMul(gallivm->builder, uscaled, + lp_build_const_float(gallivm, 2147483647.0), ""); +} + +static INLINE LLVMValueRef +to_32_fixed(struct gallivm_state *gallivm, LLVMValueRef fp) +{ + LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, ""); + LLVMValueRef uscaled = LLVMBuildFPToSI(gallivm->builder, l, + LLVMIntTypeInContext(gallivm->context, 32), ""); + + return LLVMBuildFMul(gallivm->builder, uscaled, + lp_build_const_float(gallivm, 65536.0), ""); +} + +typedef LLVMValueRef (*from_func)(struct gallivm_state *, LLVMValueRef); +typedef LLVMValueRef (*to_func)(struct gallivm_state *, LLVMValueRef); + +/* so that underneath can avoid function calls which are prohibited + * for static initialization we need this conversion */ +enum ll_type { + LL_Double, + LL_Float, + LL_Int32, + LL_Int16, + LL_Int8 +}; + +static INLINE LLVMTypeRef +ll_type_to_llvm(struct gallivm_state *gallivm, enum ll_type type) +{ + switch (type) { + case LL_Double: + return LLVMDoubleTypeInContext(gallivm->context); + case LL_Float: + return LLVMFloatTypeInContext(gallivm->context); + case LL_Int32: + return LLVMInt32TypeInContext(gallivm->context); + case LL_Int16: + return LLVMIntTypeInContext(gallivm->context, 16); + case LL_Int8: + return LLVMIntTypeInContext(gallivm->context, 8); + } + return LLVMIntTypeInContext(gallivm->context, 8); +} + +static INLINE int +ll_type_size(enum ll_type type) +{ + switch (type) { + case LL_Double: + return 8; + case LL_Float: + return 4; + case LL_Int32: + return 4; + case LL_Int16: + return 2; + case LL_Int8: + return 1; + } + return 1; +} + +struct draw_llvm_translate { + int format; + from_func from; + to_func to; + enum ll_type type; + int num_components; +} translates[] = +{ + {PIPE_FORMAT_R64_FLOAT, from_64_float, to_64_float, LL_Double, 1}, + {PIPE_FORMAT_R64G64_FLOAT, from_64_float, to_64_float, LL_Double, 2}, + {PIPE_FORMAT_R64G64B64_FLOAT, from_64_float, to_64_float, LL_Double, 3}, + {PIPE_FORMAT_R64G64B64A64_FLOAT, from_64_float, to_64_float, LL_Double, 4}, + {PIPE_FORMAT_R32_FLOAT, from_32_float, to_32_float, LL_Float, 1}, + {PIPE_FORMAT_R32G32_FLOAT, from_32_float, to_32_float, LL_Float, 2}, + {PIPE_FORMAT_R32G32B32_FLOAT, from_32_float, to_32_float, LL_Float, 3}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, from_32_float, to_32_float, LL_Float, 4}, + + {PIPE_FORMAT_R32_UNORM, from_32_unorm, to_32_unorm, LL_Int32, 1}, + {PIPE_FORMAT_R32G32_UNORM, from_32_unorm, to_32_unorm, LL_Int32, 2}, + {PIPE_FORMAT_R32G32B32_UNORM, from_32_unorm, to_32_unorm, LL_Int32, 3}, + {PIPE_FORMAT_R32G32B32A32_UNORM, from_32_unorm, to_32_unorm, LL_Int32, 4}, + + {PIPE_FORMAT_R32_USCALED, from_32_uscaled, to_32_uscaled, LL_Int32, 1}, + {PIPE_FORMAT_R32G32_USCALED, from_32_uscaled, to_32_uscaled, LL_Int32, 2}, + {PIPE_FORMAT_R32G32B32_USCALED, from_32_uscaled, to_32_uscaled, LL_Int32, 3}, + {PIPE_FORMAT_R32G32B32A32_USCALED, from_32_uscaled, to_32_uscaled, LL_Int32, 4}, + + {PIPE_FORMAT_R32_SNORM, from_32_snorm, to_32_snorm, LL_Int32, 1}, + {PIPE_FORMAT_R32G32_SNORM, from_32_snorm, to_32_snorm, LL_Int32, 2}, + {PIPE_FORMAT_R32G32B32_SNORM, from_32_snorm, to_32_snorm, LL_Int32, 3}, + {PIPE_FORMAT_R32G32B32A32_SNORM, from_32_snorm, to_32_snorm, LL_Int32, 4}, + + {PIPE_FORMAT_R32_SSCALED, from_32_sscaled, to_32_sscaled, LL_Int32, 1}, + {PIPE_FORMAT_R32G32_SSCALED, from_32_sscaled, to_32_sscaled, LL_Int32, 2}, + {PIPE_FORMAT_R32G32B32_SSCALED, from_32_sscaled, to_32_sscaled, LL_Int32, 3}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, from_32_sscaled, to_32_sscaled, LL_Int32, 4}, + + {PIPE_FORMAT_R16_UNORM, from_16_unorm, to_16_unorm, LL_Int16, 1}, + {PIPE_FORMAT_R16G16_UNORM, from_16_unorm, to_16_unorm, LL_Int16, 2}, + {PIPE_FORMAT_R16G16B16_UNORM, from_16_unorm, to_16_unorm, LL_Int16, 3}, + {PIPE_FORMAT_R16G16B16A16_UNORM, from_16_unorm, to_16_unorm, LL_Int16, 4}, + + {PIPE_FORMAT_R16_USCALED, from_16_uscaled, to_16_uscaled, LL_Int16, 1}, + {PIPE_FORMAT_R16G16_USCALED, from_16_uscaled, to_16_uscaled, LL_Int16, 2}, + {PIPE_FORMAT_R16G16B16_USCALED, from_16_uscaled, to_16_uscaled, LL_Int16, 3}, + {PIPE_FORMAT_R16G16B16A16_USCALED, from_16_uscaled, to_16_uscaled, LL_Int16, 4}, + + {PIPE_FORMAT_R16_SNORM, from_16_snorm, to_16_snorm, LL_Int16, 1}, + {PIPE_FORMAT_R16G16_SNORM, from_16_snorm, to_16_snorm, LL_Int16, 2}, + {PIPE_FORMAT_R16G16B16_SNORM, from_16_snorm, to_16_snorm, LL_Int16, 3}, + {PIPE_FORMAT_R16G16B16A16_SNORM, from_16_snorm, to_16_snorm, LL_Int16, 4}, + + {PIPE_FORMAT_R16_SSCALED, from_16_sscaled, to_16_sscaled, LL_Int16, 1}, + {PIPE_FORMAT_R16G16_SSCALED, from_16_sscaled, to_16_sscaled, LL_Int16, 2}, + {PIPE_FORMAT_R16G16B16_SSCALED, from_16_sscaled, to_16_sscaled, LL_Int16, 3}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, from_16_sscaled, to_16_sscaled, LL_Int16, 4}, + + {PIPE_FORMAT_R8_UNORM, from_8_unorm, to_8_unorm, LL_Int8, 1}, + {PIPE_FORMAT_R8G8_UNORM, from_8_unorm, to_8_unorm, LL_Int8, 2}, + {PIPE_FORMAT_R8G8B8_UNORM, from_8_unorm, to_8_unorm, LL_Int8, 3}, + {PIPE_FORMAT_R8G8B8A8_UNORM, from_8_unorm, to_8_unorm, LL_Int8, 4}, + + {PIPE_FORMAT_R8_USCALED, from_8_uscaled, to_8_uscaled, LL_Int8, 1}, + {PIPE_FORMAT_R8G8_USCALED, from_8_uscaled, to_8_uscaled, LL_Int8, 2}, + {PIPE_FORMAT_R8G8B8_USCALED, from_8_uscaled, to_8_uscaled, LL_Int8, 3}, + {PIPE_FORMAT_R8G8B8A8_USCALED, from_8_uscaled, to_8_uscaled, LL_Int8, 4}, + + {PIPE_FORMAT_R8_SNORM, from_8_snorm, to_8_snorm, LL_Int8, 1}, + {PIPE_FORMAT_R8G8_SNORM, from_8_snorm, to_8_snorm, LL_Int8, 2}, + {PIPE_FORMAT_R8G8B8_SNORM, from_8_snorm, to_8_snorm, LL_Int8, 3}, + {PIPE_FORMAT_R8G8B8A8_SNORM, from_8_snorm, to_8_snorm, LL_Int8, 4}, + + {PIPE_FORMAT_R8_SSCALED, from_8_sscaled, to_8_sscaled, LL_Int8, 1}, + {PIPE_FORMAT_R8G8_SSCALED, from_8_sscaled, to_8_sscaled, LL_Int8, 2}, + {PIPE_FORMAT_R8G8B8_SSCALED, from_8_sscaled, to_8_sscaled, LL_Int8, 3}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, from_8_sscaled, to_8_sscaled, LL_Int8, 4}, + + {PIPE_FORMAT_R32_FIXED, from_32_fixed, to_32_fixed, LL_Int32, 1}, + {PIPE_FORMAT_R32G32_FIXED, from_32_fixed, to_32_fixed, LL_Int32, 2}, + {PIPE_FORMAT_R32G32B32_FIXED, from_32_fixed, to_32_fixed, LL_Int32, 3}, + {PIPE_FORMAT_R32G32B32A32_FIXED, from_32_fixed, to_32_fixed, LL_Int32, 4}, +}; + + +static LLVMValueRef +fetch(struct gallivm_state *gallivm, + LLVMValueRef ptr, int val_size, int nr_components, + from_func func) +{ + int i; + int offset = 0; + LLVMValueRef res = + LLVMConstNull(LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4)); + LLVMValueRef defaults[4]; + + defaults[0] = + defaults[1] = + defaults[2] = lp_build_const_float(gallivm, 0.0); + defaults[3] = lp_build_const_float(gallivm, 1.0); + + for (i = 0; i < nr_components; ++i) { + LLVMValueRef src_index = lp_build_const_int32(gallivm, offset); + LLVMValueRef dst_index = lp_build_const_int32(gallivm, i); + LLVMValueRef src_tmp; + LLVMValueRef component; + + src_tmp = LLVMBuildGEP(gallivm->builder, ptr, &src_index, 1, "src_tmp"); + + /* convert src_tmp to float */ + component = func(gallivm, src_tmp); + + /* vec.comp = component */ + res = LLVMBuildInsertElement(gallivm->builder, + res, + component, + dst_index, ""); + offset += val_size; + } + for (; i < 4; ++i) { + LLVMValueRef dst_index = lp_build_const_int32(gallivm, i); + res = LLVMBuildInsertElement(gallivm->builder, + res, + defaults[i], + dst_index, ""); + } + return res; +} + + +LLVMValueRef +draw_llvm_translate_from(struct gallivm_state *gallivm, + LLVMValueRef vbuffer, + enum pipe_format from_format) +{ + const struct util_format_description *format_desc; + LLVMValueRef zero; + int i; + struct lp_type type = lp_float32_vec4_type(); + + /* + * The above can only cope with straight arrays: no bitfields, + * swizzles, or half floats. + */ + + for (i = 0; i < Elements(translates); ++i) { + if (translates[i].format == from_format) { + /*LLVMTypeRef type = ll_type_to_llvm(translates[i].type);*/ + return fetch(gallivm, + vbuffer, + ll_type_size(translates[i].type), + translates[i].num_components, + translates[i].from); + } + } + + + /* + * This doesn't handle anything bigger than 32bits, or half floats + * yet. + * + * TODO: unify all this code into lp_build_fetch_rgba_aos(). + */ + + format_desc = util_format_description(from_format); + zero = LLVMConstNull(LLVMInt32TypeInContext(gallivm->context)); + return lp_build_fetch_rgba_aos(gallivm, format_desc, type, vbuffer, zero, zero, zero); +} diff --git a/src/gallium/auxiliary/draw/draw_pipe.c b/src/gallium/auxiliary/draw/draw_pipe.c new file mode 100644 index 0000000..6206197 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe.c @@ -0,0 +1,348 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + +#include "draw/draw_private.h" +#include "draw/draw_pipe.h" +#include "util/u_debug.h" + + + +boolean draw_pipeline_init( struct draw_context *draw ) +{ + /* create pipeline stages */ + draw->pipeline.wide_line = draw_wide_line_stage( draw ); + draw->pipeline.wide_point = draw_wide_point_stage( draw ); + draw->pipeline.stipple = draw_stipple_stage( draw ); + draw->pipeline.unfilled = draw_unfilled_stage( draw ); + draw->pipeline.twoside = draw_twoside_stage( draw ); + draw->pipeline.offset = draw_offset_stage( draw ); + draw->pipeline.clip = draw_clip_stage( draw ); + draw->pipeline.flatshade = draw_flatshade_stage( draw ); + draw->pipeline.cull = draw_cull_stage( draw ); + draw->pipeline.validate = draw_validate_stage( draw ); + draw->pipeline.first = draw->pipeline.validate; + + if (!draw->pipeline.wide_line || + !draw->pipeline.wide_point || + !draw->pipeline.stipple || + !draw->pipeline.unfilled || + !draw->pipeline.twoside || + !draw->pipeline.offset || + !draw->pipeline.clip || + !draw->pipeline.flatshade || + !draw->pipeline.cull || + !draw->pipeline.validate) + return FALSE; + + /* these defaults are oriented toward the needs of softpipe */ + draw->pipeline.wide_point_threshold = 1000000.0; /* infinity */ + draw->pipeline.wide_line_threshold = 1.0; + draw->pipeline.wide_point_sprites = FALSE; + draw->pipeline.line_stipple = TRUE; + draw->pipeline.point_sprite = TRUE; + + return TRUE; +} + + +void draw_pipeline_destroy( struct draw_context *draw ) +{ + if (draw->pipeline.wide_line) + draw->pipeline.wide_line->destroy( draw->pipeline.wide_line ); + if (draw->pipeline.wide_point) + draw->pipeline.wide_point->destroy( draw->pipeline.wide_point ); + if (draw->pipeline.stipple) + draw->pipeline.stipple->destroy( draw->pipeline.stipple ); + if (draw->pipeline.unfilled) + draw->pipeline.unfilled->destroy( draw->pipeline.unfilled ); + if (draw->pipeline.twoside) + draw->pipeline.twoside->destroy( draw->pipeline.twoside ); + if (draw->pipeline.offset) + draw->pipeline.offset->destroy( draw->pipeline.offset ); + if (draw->pipeline.clip) + draw->pipeline.clip->destroy( draw->pipeline.clip ); + if (draw->pipeline.flatshade) + draw->pipeline.flatshade->destroy( draw->pipeline.flatshade ); + if (draw->pipeline.cull) + draw->pipeline.cull->destroy( draw->pipeline.cull ); + if (draw->pipeline.validate) + draw->pipeline.validate->destroy( draw->pipeline.validate ); + if (draw->pipeline.aaline) + draw->pipeline.aaline->destroy( draw->pipeline.aaline ); + if (draw->pipeline.aapoint) + draw->pipeline.aapoint->destroy( draw->pipeline.aapoint ); + if (draw->pipeline.pstipple) + draw->pipeline.pstipple->destroy( draw->pipeline.pstipple ); + if (draw->pipeline.rasterize) + draw->pipeline.rasterize->destroy( draw->pipeline.rasterize ); +} + + + +/** + * Build primitive to render a point with vertex at v0. + */ +static void do_point( struct draw_context *draw, + const char *v0 ) +{ + struct prim_header prim; + + prim.flags = 0; + prim.pad = 0; + prim.v[0] = (struct vertex_header *)v0; + + draw->pipeline.first->point( draw->pipeline.first, &prim ); +} + + +/** + * Build primitive to render a line with vertices at v0, v1. + * \param flags bitmask of DRAW_PIPE_EDGE_x, DRAW_PIPE_RESET_STIPPLE + */ +static void do_line( struct draw_context *draw, + ushort flags, + const char *v0, + const char *v1 ) +{ + struct prim_header prim; + + prim.flags = flags; + prim.pad = 0; + prim.v[0] = (struct vertex_header *)v0; + prim.v[1] = (struct vertex_header *)v1; + + draw->pipeline.first->line( draw->pipeline.first, &prim ); +} + + +/** + * Build primitive to render a triangle with vertices at v0, v1, v2. + * \param flags bitmask of DRAW_PIPE_EDGE_x, DRAW_PIPE_RESET_STIPPLE + */ +static void do_triangle( struct draw_context *draw, + ushort flags, + char *v0, + char *v1, + char *v2 ) +{ + struct prim_header prim; + + prim.v[0] = (struct vertex_header *)v0; + prim.v[1] = (struct vertex_header *)v1; + prim.v[2] = (struct vertex_header *)v2; + prim.flags = flags; + prim.pad = 0; + + draw->pipeline.first->tri( draw->pipeline.first, &prim ); +} + + +/* + * Set up macros for draw_pt_decompose.h template code. + * This code uses vertex indexes / elements. + */ + +#define TRIANGLE(flags,i0,i1,i2) \ + do { \ + do_triangle( draw, \ + flags, \ + verts + stride * (i0), \ + verts + stride * (i1), \ + verts + stride * (i2) ); \ + } while (0) + +#define LINE(flags,i0,i1) \ + do { \ + do_line( draw, \ + flags, \ + verts + stride * (i0), \ + verts + stride * (i1) ); \ + } while (0) + +#define POINT(i0) \ + do { \ + do_point( draw, verts + stride * (i0) ); \ + } while (0) + +#define GET_ELT(idx) (elts[idx]) + +#define FUNC pipe_run_elts +#define FUNC_VARS \ + struct draw_context *draw, \ + unsigned prim, \ + unsigned prim_flags, \ + struct vertex_header *vertices, \ + unsigned stride, \ + const ushort *elts, \ + unsigned count + +#include "draw_pt_decompose.h" + + + +/** + * Code to run the pipeline on a fairly arbitrary collection of vertices. + * For drawing indexed primitives. + * + * Vertex headers must be pre-initialized with the + * UNDEFINED_VERTEX_ID, this code will cause that id to become + * overwritten, so it may have to be reset if there is the intention + * to reuse the vertices. + * + * This code provides a callback to reset the vertex id's which the + * draw_vbuf.c code uses when it has to perform a flush. + */ +void draw_pipeline_run( struct draw_context *draw, + const struct draw_vertex_info *vert_info, + const struct draw_prim_info *prim_info) +{ + unsigned i, start; + + draw->pipeline.verts = (char *)vert_info->verts; + draw->pipeline.vertex_stride = vert_info->stride; + draw->pipeline.vertex_count = vert_info->count; + + for (start = i = 0; + i < prim_info->primitive_count; + start += prim_info->primitive_lengths[i], i++) + { + const unsigned count = prim_info->primitive_lengths[i]; + +#if DEBUG + /* Warn if one of the element indexes go outside the vertex buffer */ + { + unsigned max_index = 0x0, i; + /* find the largest element index */ + for (i = 0; i < count; i++) { + unsigned int index = prim_info->elts[start + i]; + if (index > max_index) + max_index = index; + } + if (max_index >= vert_info->count) { + debug_printf("%s: max_index (%u) outside vertex buffer (%u)\n", + __FUNCTION__, + max_index, + vert_info->count); + } + } +#endif + + pipe_run_elts(draw, + prim_info->prim, + prim_info->flags, + vert_info->verts, + vert_info->stride, + prim_info->elts + start, + count); + } + + draw->pipeline.verts = NULL; + draw->pipeline.vertex_count = 0; +} + + +/* + * Set up macros for draw_pt_decompose.h template code. + * This code is for non-indexed (aka linear) rendering (no elts). + */ + +#define TRIANGLE(flags,i0,i1,i2) \ + do_triangle( draw, flags, \ + verts + stride * (i0), \ + verts + stride * (i1), \ + verts + stride * (i2) ) + +#define LINE(flags,i0,i1) \ + do_line( draw, flags, \ + verts + stride * (i0), \ + verts + stride * (i1) ) + +#define POINT(i0) \ + do_point( draw, verts + stride * (i0) ) + + +#define GET_ELT(idx) (idx) + +#define FUNC pipe_run_linear +#define FUNC_VARS \ + struct draw_context *draw, \ + unsigned prim, \ + unsigned prim_flags, \ + struct vertex_header *vertices, \ + unsigned stride, \ + unsigned count + +#include "draw_pt_decompose.h" + + +/* + * For drawing non-indexed primitives. + */ +void draw_pipeline_run_linear( struct draw_context *draw, + const struct draw_vertex_info *vert_info, + const struct draw_prim_info *prim_info) +{ + unsigned i, start; + + for (start = i = 0; + i < prim_info->primitive_count; + start += prim_info->primitive_lengths[i], i++) + { + unsigned count = prim_info->primitive_lengths[i]; + char *verts = ((char*)vert_info->verts) + + (start * vert_info->stride); + + draw->pipeline.verts = verts; + draw->pipeline.vertex_stride = vert_info->stride; + draw->pipeline.vertex_count = count; + + assert(count <= vert_info->count); + + pipe_run_linear(draw, + prim_info->prim, + prim_info->flags, + (struct vertex_header*)verts, + vert_info->stride, + count); + } + + draw->pipeline.verts = NULL; + draw->pipeline.vertex_count = 0; +} + + +void draw_pipeline_flush( struct draw_context *draw, + unsigned flags ) +{ + draw->pipeline.first->flush( draw->pipeline.first, flags ); + draw->pipeline.first = draw->pipeline.validate; +} diff --git a/src/gallium/auxiliary/draw/draw_pipe.h b/src/gallium/auxiliary/draw/draw_pipe.h new file mode 100644 index 0000000..4792507 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe.h @@ -0,0 +1,126 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + +#ifndef DRAW_PIPE_H +#define DRAW_PIPE_H + +#include "pipe/p_compiler.h" +#include "draw_private.h" /* for sizeof(vertex_header) */ + + +/** + * Basic info for a point/line/triangle primitive. + */ +struct prim_header { + float det; /**< front/back face determinant */ + ushort flags; + ushort pad; + struct vertex_header *v[3]; /**< 1 to 3 vertex pointers */ +}; + + + +/** + * Base class for all primitive drawing stages. + */ +struct draw_stage +{ + struct draw_context *draw; /**< parent context */ + + struct draw_stage *next; /**< next stage in pipeline */ + const char *name; /**< for debugging */ + + struct vertex_header **tmp; /**< temp vert storage, such as for clipping */ + unsigned nr_tmps; + + void (*point)( struct draw_stage *, + struct prim_header * ); + + void (*line)( struct draw_stage *, + struct prim_header * ); + + void (*tri)( struct draw_stage *, + struct prim_header * ); + + void (*flush)( struct draw_stage *, + unsigned flags ); + + void (*reset_stipple_counter)( struct draw_stage * ); + + void (*destroy)( struct draw_stage * ); +}; + + +extern struct draw_stage *draw_unfilled_stage( struct draw_context *context ); +extern struct draw_stage *draw_twoside_stage( struct draw_context *context ); +extern struct draw_stage *draw_offset_stage( struct draw_context *context ); +extern struct draw_stage *draw_clip_stage( struct draw_context *context ); +extern struct draw_stage *draw_flatshade_stage( struct draw_context *context ); +extern struct draw_stage *draw_cull_stage( struct draw_context *context ); +extern struct draw_stage *draw_stipple_stage( struct draw_context *context ); +extern struct draw_stage *draw_wide_line_stage( struct draw_context *context ); +extern struct draw_stage *draw_wide_point_stage( struct draw_context *context ); +extern struct draw_stage *draw_validate_stage( struct draw_context *context ); + + +extern void draw_free_temp_verts( struct draw_stage *stage ); +extern boolean draw_alloc_temp_verts( struct draw_stage *stage, unsigned nr ); + +extern void draw_reset_vertex_ids( struct draw_context *draw ); + +void draw_pipe_passthrough_tri(struct draw_stage *stage, struct prim_header *header); +void draw_pipe_passthrough_line(struct draw_stage *stage, struct prim_header *header); +void draw_pipe_passthrough_point(struct draw_stage *stage, struct prim_header *header); + + + +/** + * Get a writeable copy of a vertex. + * \param stage drawing stage info + * \param vert the vertex to copy (source) + * \param idx index into stage's tmp[] array to put the copy (dest) + * \return pointer to the copied vertex + */ +static INLINE struct vertex_header * +dup_vert( struct draw_stage *stage, + const struct vertex_header *vert, + unsigned idx ) +{ + struct vertex_header *tmp = stage->tmp[idx]; + const uint vsize = sizeof(struct vertex_header) + + stage->draw->vs.num_vs_outputs * 4 * sizeof(float); + memcpy(tmp, vert, vsize); + tmp->vertex_id = UNDEFINED_VERTEX_ID; + return tmp; +} + +#endif diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c new file mode 100644 index 0000000..0851b9a --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c @@ -0,0 +1,965 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * AA line stage: AA lines are converted to texture mapped triangles. + * + * Authors: Brian Paul + */ + + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_inlines.h" + +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_sampler.h" + +#include "tgsi/tgsi_transform.h" +#include "tgsi/tgsi_dump.h" + +#include "draw_context.h" +#include "draw_private.h" +#include "draw_pipe.h" + + +/** Approx number of new tokens for instructions in aa_transform_inst() */ +#define NUM_NEW_TOKENS 50 + + +/** + * Max texture level for the alpha texture used for antialiasing + */ +#define MAX_TEXTURE_LEVEL 5 /* 32 x 32 */ + + +/** + * Subclass of pipe_shader_state to carry extra fragment shader info. + */ +struct aaline_fragment_shader +{ + struct pipe_shader_state state; + void *driver_fs; + void *aaline_fs; + uint sampler_unit; + int generic_attrib; /**< texcoord/generic used for texture */ +}; + + +/** + * Subclass of draw_stage + */ +struct aaline_stage +{ + struct draw_stage stage; + + float half_line_width; + + /** For AA lines, this is the vertex attrib slot for the new texcoords */ + uint tex_slot; + /** position, not necessarily output zero */ + uint pos_slot; + + void *sampler_cso; + struct pipe_resource *texture; + struct pipe_sampler_view *sampler_view; + uint num_samplers; + uint num_sampler_views; + + + /* + * Currently bound state + */ + struct aaline_fragment_shader *fs; + struct { + void *sampler[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; + } state; + + /* + * Driver interface/override functions + */ + void * (*driver_create_fs_state)(struct pipe_context *, + const struct pipe_shader_state *); + void (*driver_bind_fs_state)(struct pipe_context *, void *); + void (*driver_delete_fs_state)(struct pipe_context *, void *); + + void (*driver_bind_sampler_states)(struct pipe_context *, unsigned, + void **); + + void (*driver_set_sampler_views)(struct pipe_context *, + unsigned, + struct pipe_sampler_view **); +}; + + + +/** + * Subclass of tgsi_transform_context, used for transforming the + * user's fragment shader to add the special AA instructions. + */ +struct aa_transform_context { + struct tgsi_transform_context base; + uint tempsUsed; /**< bitmask */ + int colorOutput; /**< which output is the primary color */ + uint samplersUsed; /**< bitfield of samplers used */ + int freeSampler; /** an available sampler for the pstipple */ + int maxInput, maxGeneric; /**< max input index found */ + int colorTemp, texTemp; /**< temp registers */ + boolean firstInstruction; +}; + + +/** + * TGSI declaration transform callback. + * Look for a free sampler, a free input attrib, and two free temp regs. + */ +static void +aa_transform_decl(struct tgsi_transform_context *ctx, + struct tgsi_full_declaration *decl) +{ + struct aa_transform_context *aactx = (struct aa_transform_context *) ctx; + + if (decl->Declaration.File == TGSI_FILE_OUTPUT && + decl->Semantic.Name == TGSI_SEMANTIC_COLOR && + decl->Semantic.Index == 0) { + aactx->colorOutput = decl->Range.First; + } + else if (decl->Declaration.File == TGSI_FILE_SAMPLER) { + uint i; + for (i = decl->Range.First; + i <= decl->Range.Last; i++) { + aactx->samplersUsed |= 1 << i; + } + } + else if (decl->Declaration.File == TGSI_FILE_INPUT) { + if ((int) decl->Range.Last > aactx->maxInput) + aactx->maxInput = decl->Range.Last; + if (decl->Semantic.Name == TGSI_SEMANTIC_GENERIC && + (int) decl->Semantic.Index > aactx->maxGeneric) { + aactx->maxGeneric = decl->Semantic.Index; + } + } + else if (decl->Declaration.File == TGSI_FILE_TEMPORARY) { + uint i; + for (i = decl->Range.First; + i <= decl->Range.Last; i++) { + aactx->tempsUsed |= (1 << i); + } + } + + ctx->emit_declaration(ctx, decl); +} + + +/** + * Find the lowest zero bit in the given word, or -1 if bitfield is all ones. + */ +static int +free_bit(uint bitfield) +{ + return ffs(~bitfield) - 1; +} + + +/** + * TGSI instruction transform callback. + * Replace writes to result.color w/ a temp reg. + * Upon END instruction, insert texture sampling code for antialiasing. + */ +static void +aa_transform_inst(struct tgsi_transform_context *ctx, + struct tgsi_full_instruction *inst) +{ + struct aa_transform_context *aactx = (struct aa_transform_context *) ctx; + + if (aactx->firstInstruction) { + /* emit our new declarations before the first instruction */ + + struct tgsi_full_declaration decl; + uint i; + + /* find free sampler */ + aactx->freeSampler = free_bit(aactx->samplersUsed); + if (aactx->freeSampler >= PIPE_MAX_SAMPLERS) + aactx->freeSampler = PIPE_MAX_SAMPLERS - 1; + + /* find two free temp regs */ + for (i = 0; i < 32; i++) { + if ((aactx->tempsUsed & (1 << i)) == 0) { + /* found a free temp */ + if (aactx->colorTemp < 0) + aactx->colorTemp = i; + else if (aactx->texTemp < 0) + aactx->texTemp = i; + else + break; + } + } + assert(aactx->colorTemp >= 0); + assert(aactx->texTemp >= 0); + + /* declare new generic input/texcoord */ + decl = tgsi_default_full_declaration(); + decl.Declaration.File = TGSI_FILE_INPUT; + /* XXX this could be linear... */ + decl.Declaration.Interpolate = TGSI_INTERPOLATE_PERSPECTIVE; + decl.Declaration.Semantic = 1; + decl.Semantic.Name = TGSI_SEMANTIC_GENERIC; + decl.Semantic.Index = aactx->maxGeneric + 1; + decl.Range.First = + decl.Range.Last = aactx->maxInput + 1; + ctx->emit_declaration(ctx, &decl); + + /* declare new sampler */ + decl = tgsi_default_full_declaration(); + decl.Declaration.File = TGSI_FILE_SAMPLER; + decl.Range.First = + decl.Range.Last = aactx->freeSampler; + ctx->emit_declaration(ctx, &decl); + + /* declare new temp regs */ + decl = tgsi_default_full_declaration(); + decl.Declaration.File = TGSI_FILE_TEMPORARY; + decl.Range.First = + decl.Range.Last = aactx->texTemp; + ctx->emit_declaration(ctx, &decl); + + decl = tgsi_default_full_declaration(); + decl.Declaration.File = TGSI_FILE_TEMPORARY; + decl.Range.First = + decl.Range.Last = aactx->colorTemp; + ctx->emit_declaration(ctx, &decl); + + aactx->firstInstruction = FALSE; + } + + if (inst->Instruction.Opcode == TGSI_OPCODE_END && + aactx->colorOutput != -1) { + struct tgsi_full_instruction newInst; + + /* TEX */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_TEX; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Dst[0].Register.Index = aactx->texTemp; + newInst.Instruction.NumSrcRegs = 2; + newInst.Instruction.Texture = TRUE; + newInst.Texture.Texture = TGSI_TEXTURE_2D; + newInst.Src[0].Register.File = TGSI_FILE_INPUT; + newInst.Src[0].Register.Index = aactx->maxInput + 1; + newInst.Src[1].Register.File = TGSI_FILE_SAMPLER; + newInst.Src[1].Register.Index = aactx->freeSampler; + + ctx->emit_instruction(ctx, &newInst); + + /* MOV rgb */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_MOV; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_OUTPUT; + newInst.Dst[0].Register.Index = aactx->colorOutput; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_XYZ; + newInst.Instruction.NumSrcRegs = 1; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = aactx->colorTemp; + ctx->emit_instruction(ctx, &newInst); + + /* MUL alpha */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_MUL; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_OUTPUT; + newInst.Dst[0].Register.Index = aactx->colorOutput; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_W; + newInst.Instruction.NumSrcRegs = 2; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = aactx->colorTemp; + newInst.Src[1].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[1].Register.Index = aactx->texTemp; + ctx->emit_instruction(ctx, &newInst); + + /* END */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_END; + newInst.Instruction.NumDstRegs = 0; + newInst.Instruction.NumSrcRegs = 0; + ctx->emit_instruction(ctx, &newInst); + } + else { + /* Not an END instruction. + * Look for writes to result.color and replace with colorTemp reg. + */ + uint i; + + for (i = 0; i < inst->Instruction.NumDstRegs; i++) { + struct tgsi_full_dst_register *dst = &inst->Dst[i]; + if (dst->Register.File == TGSI_FILE_OUTPUT && + dst->Register.Index == aactx->colorOutput) { + dst->Register.File = TGSI_FILE_TEMPORARY; + dst->Register.Index = aactx->colorTemp; + } + } + + ctx->emit_instruction(ctx, inst); + } +} + + +/** + * Generate the frag shader we'll use for drawing AA lines. + * This will be the user's shader plus some texture/modulate instructions. + */ +static boolean +generate_aaline_fs(struct aaline_stage *aaline) +{ + struct pipe_context *pipe = aaline->stage.draw->pipe; + const struct pipe_shader_state *orig_fs = &aaline->fs->state; + struct pipe_shader_state aaline_fs; + struct aa_transform_context transform; + const uint newLen = tgsi_num_tokens(orig_fs->tokens) + NUM_NEW_TOKENS; + + aaline_fs = *orig_fs; /* copy to init */ + aaline_fs.tokens = tgsi_alloc_tokens(newLen); + if (aaline_fs.tokens == NULL) + return FALSE; + + memset(&transform, 0, sizeof(transform)); + transform.colorOutput = -1; + transform.maxInput = -1; + transform.maxGeneric = -1; + transform.colorTemp = -1; + transform.texTemp = -1; + transform.firstInstruction = TRUE; + transform.base.transform_instruction = aa_transform_inst; + transform.base.transform_declaration = aa_transform_decl; + + tgsi_transform_shader(orig_fs->tokens, + (struct tgsi_token *) aaline_fs.tokens, + newLen, &transform.base); + +#if 0 /* DEBUG */ + tgsi_dump(orig_fs->tokens, 0); + tgsi_dump(aaline_fs.tokens, 0); +#endif + + aaline->fs->sampler_unit = transform.freeSampler; + + aaline->fs->aaline_fs = aaline->driver_create_fs_state(pipe, &aaline_fs); + if (aaline->fs->aaline_fs == NULL) + goto fail; + + aaline->fs->generic_attrib = transform.maxGeneric + 1; + FREE((void *)aaline_fs.tokens); + return TRUE; + +fail: + FREE((void *)aaline_fs.tokens); + return FALSE; +} + + +/** + * Create the texture map we'll use for antialiasing the lines. + */ +static boolean +aaline_create_texture(struct aaline_stage *aaline) +{ + struct pipe_context *pipe = aaline->stage.draw->pipe; + struct pipe_screen *screen = pipe->screen; + struct pipe_resource texTemp; + struct pipe_sampler_view viewTempl; + uint level; + + memset(&texTemp, 0, sizeof(texTemp)); + texTemp.target = PIPE_TEXTURE_2D; + texTemp.format = PIPE_FORMAT_A8_UNORM; /* XXX verify supported by driver! */ + texTemp.last_level = MAX_TEXTURE_LEVEL; + texTemp.width0 = 1 << MAX_TEXTURE_LEVEL; + texTemp.height0 = 1 << MAX_TEXTURE_LEVEL; + texTemp.depth0 = 1; + texTemp.array_size = 1; + texTemp.bind = PIPE_BIND_SAMPLER_VIEW; + + aaline->texture = screen->resource_create(screen, &texTemp); + if (!aaline->texture) + return FALSE; + + u_sampler_view_default_template(&viewTempl, + aaline->texture, + aaline->texture->format); + aaline->sampler_view = pipe->create_sampler_view(pipe, + aaline->texture, + &viewTempl); + if (!aaline->sampler_view) { + return FALSE; + } + + /* Fill in mipmap images. + * Basically each level is solid opaque, except for the outermost + * texels which are zero. Special case the 1x1 and 2x2 levels + * (though, those levels shouldn't be used - see the max_lod setting). + */ + for (level = 0; level <= MAX_TEXTURE_LEVEL; level++) { + struct pipe_transfer *transfer; + struct pipe_box box; + const uint size = u_minify(aaline->texture->width0, level); + ubyte *data; + uint i, j; + + assert(aaline->texture->width0 == aaline->texture->height0); + + u_box_origin_2d( size, size, &box ); + + /* This texture is new, no need to flush. + */ + transfer = pipe->get_transfer(pipe, + aaline->texture, + level, + PIPE_TRANSFER_WRITE, + &box); + + data = pipe->transfer_map(pipe, transfer); + if (data == NULL) + return FALSE; + + for (i = 0; i < size; i++) { + for (j = 0; j < size; j++) { + ubyte d; + if (size == 1) { + d = 255; + } + else if (size == 2) { + d = 200; /* tuneable */ + } + else if (i == 0 || j == 0 || i == size - 1 || j == size - 1) { + d = 0; + } + else { + d = 255; + } + data[i * transfer->stride + j] = d; + } + } + + /* unmap */ + pipe->transfer_unmap(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); + } + return TRUE; +} + + +/** + * Create the sampler CSO that'll be used for antialiasing. + * By using a mipmapped texture, we don't have to generate a different + * texture image for each line size. + */ +static boolean +aaline_create_sampler(struct aaline_stage *aaline) +{ + struct pipe_sampler_state sampler; + struct pipe_context *pipe = aaline->stage.draw->pipe; + + memset(&sampler, 0, sizeof(sampler)); + sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_LINEAR; + sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR; + sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR; + sampler.normalized_coords = 1; + sampler.min_lod = 0.0f; + /* avoid using the 1x1 and 2x2 mipmap levels */ + sampler.max_lod = MAX_TEXTURE_LEVEL - 2; + + aaline->sampler_cso = pipe->create_sampler_state(pipe, &sampler); + if (aaline->sampler_cso == NULL) + return FALSE; + + return TRUE; +} + + +/** + * When we're about to draw our first AA line in a batch, this function is + * called to tell the driver to bind our modified fragment shader. + */ +static boolean +bind_aaline_fragment_shader(struct aaline_stage *aaline) +{ + struct draw_context *draw = aaline->stage.draw; + struct pipe_context *pipe = draw->pipe; + + if (!aaline->fs->aaline_fs && + !generate_aaline_fs(aaline)) + return FALSE; + + draw->suspend_flushing = TRUE; + aaline->driver_bind_fs_state(pipe, aaline->fs->aaline_fs); + draw->suspend_flushing = FALSE; + + return TRUE; +} + + + +static INLINE struct aaline_stage * +aaline_stage( struct draw_stage *stage ) +{ + return (struct aaline_stage *) stage; +} + + +/** + * Draw a wide line by drawing a quad, using geometry which will + * fullfill GL's antialiased line requirements. + */ +static void +aaline_line(struct draw_stage *stage, struct prim_header *header) +{ + const struct aaline_stage *aaline = aaline_stage(stage); + const float half_width = aaline->half_line_width; + struct prim_header tri; + struct vertex_header *v[8]; + uint texPos = aaline->tex_slot; + uint posPos = aaline->pos_slot; + float *pos, *tex; + float dx = header->v[1]->data[posPos][0] - header->v[0]->data[posPos][0]; + float dy = header->v[1]->data[posPos][1] - header->v[0]->data[posPos][1]; + double a = atan2(dy, dx); + float c_a = (float) cos(a), s_a = (float) sin(a); + uint i; + + /* XXX the ends of lines aren't quite perfect yet, but probably passable */ + dx = 0.5F * half_width; + dy = half_width; + + /* allocate/dup new verts */ + for (i = 0; i < 8; i++) { + v[i] = dup_vert(stage, header->v[i/4], i); + } + + /* + * Quad strip for line from v0 to v1 (*=endpoints): + * + * 1 3 5 7 + * +---+---------------------+---+ + * | | + * | *v0 v1* | + * | | + * +---+---------------------+---+ + * 0 2 4 6 + */ + + /* new verts */ + pos = v[0]->data[posPos]; + pos[0] += (-dx * c_a - dy * s_a); + pos[1] += (-dx * s_a + dy * c_a); + + pos = v[1]->data[posPos]; + pos[0] += (-dx * c_a - -dy * s_a); + pos[1] += (-dx * s_a + -dy * c_a); + + pos = v[2]->data[posPos]; + pos[0] += ( dx * c_a - dy * s_a); + pos[1] += ( dx * s_a + dy * c_a); + + pos = v[3]->data[posPos]; + pos[0] += ( dx * c_a - -dy * s_a); + pos[1] += ( dx * s_a + -dy * c_a); + + pos = v[4]->data[posPos]; + pos[0] += (-dx * c_a - dy * s_a); + pos[1] += (-dx * s_a + dy * c_a); + + pos = v[5]->data[posPos]; + pos[0] += (-dx * c_a - -dy * s_a); + pos[1] += (-dx * s_a + -dy * c_a); + + pos = v[6]->data[posPos]; + pos[0] += ( dx * c_a - dy * s_a); + pos[1] += ( dx * s_a + dy * c_a); + + pos = v[7]->data[posPos]; + pos[0] += ( dx * c_a - -dy * s_a); + pos[1] += ( dx * s_a + -dy * c_a); + + /* new texcoords */ + tex = v[0]->data[texPos]; + ASSIGN_4V(tex, 0, 0, 0, 1); + + tex = v[1]->data[texPos]; + ASSIGN_4V(tex, 0, 1, 0, 1); + + tex = v[2]->data[texPos]; + ASSIGN_4V(tex, .5, 0, 0, 1); + + tex = v[3]->data[texPos]; + ASSIGN_4V(tex, .5, 1, 0, 1); + + tex = v[4]->data[texPos]; + ASSIGN_4V(tex, .5, 0, 0, 1); + + tex = v[5]->data[texPos]; + ASSIGN_4V(tex, .5, 1, 0, 1); + + tex = v[6]->data[texPos]; + ASSIGN_4V(tex, 1, 0, 0, 1); + + tex = v[7]->data[texPos]; + ASSIGN_4V(tex, 1, 1, 0, 1); + + /* emit 6 tris for the quad strip */ + tri.v[0] = v[2]; tri.v[1] = v[1]; tri.v[2] = v[0]; + stage->next->tri( stage->next, &tri ); + + tri.v[0] = v[3]; tri.v[1] = v[1]; tri.v[2] = v[2]; + stage->next->tri( stage->next, &tri ); + + tri.v[0] = v[4]; tri.v[1] = v[3]; tri.v[2] = v[2]; + stage->next->tri( stage->next, &tri ); + + tri.v[0] = v[5]; tri.v[1] = v[3]; tri.v[2] = v[4]; + stage->next->tri( stage->next, &tri ); + + tri.v[0] = v[6]; tri.v[1] = v[5]; tri.v[2] = v[4]; + stage->next->tri( stage->next, &tri ); + + tri.v[0] = v[7]; tri.v[1] = v[5]; tri.v[2] = v[6]; + stage->next->tri( stage->next, &tri ); +} + + +static void +aaline_first_line(struct draw_stage *stage, struct prim_header *header) +{ + auto struct aaline_stage *aaline = aaline_stage(stage); + struct draw_context *draw = stage->draw; + struct pipe_context *pipe = draw->pipe; + const struct pipe_rasterizer_state *rast = draw->rasterizer; + uint num_samplers; + void *r; + + assert(draw->rasterizer->line_smooth); + + if (draw->rasterizer->line_width <= 2.2) + aaline->half_line_width = 1.1f; + else + aaline->half_line_width = 0.5f * draw->rasterizer->line_width; + + /* + * Bind (generate) our fragprog, sampler and texture + */ + if (!bind_aaline_fragment_shader(aaline)) { + stage->line = draw_pipe_passthrough_line; + stage->line(stage, header); + return; + } + + /* update vertex attrib info */ + aaline->tex_slot = draw_current_shader_outputs(draw); + aaline->pos_slot = draw_current_shader_position_output(draw);; + + /* allocate the extra post-transformed vertex attribute */ + (void) draw_alloc_extra_vertex_attrib(draw, TGSI_SEMANTIC_GENERIC, + aaline->fs->generic_attrib); + + /* how many samplers? */ + /* we'll use sampler/texture[pstip->sampler_unit] for the stipple */ + num_samplers = MAX2(aaline->num_sampler_views, aaline->num_samplers); + num_samplers = MAX2(num_samplers, aaline->fs->sampler_unit + 1); + + aaline->state.sampler[aaline->fs->sampler_unit] = aaline->sampler_cso; + pipe_sampler_view_reference(&aaline->state.sampler_views[aaline->fs->sampler_unit], + aaline->sampler_view); + + draw->suspend_flushing = TRUE; + aaline->driver_bind_sampler_states(pipe, num_samplers, aaline->state.sampler); + aaline->driver_set_sampler_views(pipe, num_samplers, aaline->state.sampler_views); + + /* Disable triangle culling, stippling, unfilled mode etc. */ + r = draw_get_rasterizer_no_cull(draw, rast->scissor, rast->flatshade); + pipe->bind_rasterizer_state(pipe, r); + + draw->suspend_flushing = FALSE; + + /* now really draw first line */ + stage->line = aaline_line; + stage->line(stage, header); +} + + +static void +aaline_flush(struct draw_stage *stage, unsigned flags) +{ + struct draw_context *draw = stage->draw; + struct aaline_stage *aaline = aaline_stage(stage); + struct pipe_context *pipe = draw->pipe; + + stage->line = aaline_first_line; + stage->next->flush( stage->next, flags ); + + /* restore original frag shader, texture, sampler state */ + draw->suspend_flushing = TRUE; + aaline->driver_bind_fs_state(pipe, aaline->fs->driver_fs); + aaline->driver_bind_sampler_states(pipe, aaline->num_samplers, + aaline->state.sampler); + aaline->driver_set_sampler_views(pipe, + aaline->num_sampler_views, + aaline->state.sampler_views); + + /* restore original rasterizer state */ + if (draw->rast_handle) { + pipe->bind_rasterizer_state(pipe, draw->rast_handle); + } + + draw->suspend_flushing = FALSE; + + draw_remove_extra_vertex_attribs(draw); +} + + +static void +aaline_reset_stipple_counter(struct draw_stage *stage) +{ + stage->next->reset_stipple_counter( stage->next ); +} + + +static void +aaline_destroy(struct draw_stage *stage) +{ + struct aaline_stage *aaline = aaline_stage(stage); + struct pipe_context *pipe = stage->draw->pipe; + uint i; + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + pipe_sampler_view_reference(&aaline->state.sampler_views[i], NULL); + } + + if (aaline->sampler_cso) + pipe->delete_sampler_state(pipe, aaline->sampler_cso); + + if (aaline->texture) + pipe_resource_reference(&aaline->texture, NULL); + + if (aaline->sampler_view) { + pipe_sampler_view_reference(&aaline->sampler_view, NULL); + } + + draw_free_temp_verts( stage ); + + FREE( stage ); +} + + +static struct aaline_stage * +draw_aaline_stage(struct draw_context *draw) +{ + struct aaline_stage *aaline = CALLOC_STRUCT(aaline_stage); + if (aaline == NULL) + return NULL; + + aaline->stage.draw = draw; + aaline->stage.name = "aaline"; + aaline->stage.next = NULL; + aaline->stage.point = draw_pipe_passthrough_point; + aaline->stage.line = aaline_first_line; + aaline->stage.tri = draw_pipe_passthrough_tri; + aaline->stage.flush = aaline_flush; + aaline->stage.reset_stipple_counter = aaline_reset_stipple_counter; + aaline->stage.destroy = aaline_destroy; + + if (!draw_alloc_temp_verts( &aaline->stage, 8 )) + goto fail; + + return aaline; + + fail: + if (aaline) + aaline->stage.destroy(&aaline->stage); + + return NULL; +} + + +static struct aaline_stage * +aaline_stage_from_pipe(struct pipe_context *pipe) +{ + struct draw_context *draw = (struct draw_context *) pipe->draw; + return aaline_stage(draw->pipeline.aaline); +} + + +/** + * This function overrides the driver's create_fs_state() function and + * will typically be called by the state tracker. + */ +static void * +aaline_create_fs_state(struct pipe_context *pipe, + const struct pipe_shader_state *fs) +{ + struct aaline_stage *aaline = aaline_stage_from_pipe(pipe); + struct aaline_fragment_shader *aafs = CALLOC_STRUCT(aaline_fragment_shader); + + if (aafs == NULL) + return NULL; + + aafs->state = *fs; + + /* pass-through */ + aafs->driver_fs = aaline->driver_create_fs_state(pipe, fs); + + return aafs; +} + + +static void +aaline_bind_fs_state(struct pipe_context *pipe, void *fs) +{ + struct aaline_stage *aaline = aaline_stage_from_pipe(pipe); + struct aaline_fragment_shader *aafs = (struct aaline_fragment_shader *) fs; + + /* save current */ + aaline->fs = aafs; + /* pass-through */ + aaline->driver_bind_fs_state(pipe, (aafs ? aafs->driver_fs : NULL)); +} + + +static void +aaline_delete_fs_state(struct pipe_context *pipe, void *fs) +{ + struct aaline_stage *aaline = aaline_stage_from_pipe(pipe); + struct aaline_fragment_shader *aafs = (struct aaline_fragment_shader *) fs; + + /* pass-through */ + aaline->driver_delete_fs_state(pipe, aafs->driver_fs); + + if (aafs->aaline_fs) + aaline->driver_delete_fs_state(pipe, aafs->aaline_fs); + + FREE(aafs); +} + + +static void +aaline_bind_sampler_states(struct pipe_context *pipe, + unsigned num, void **sampler) +{ + struct aaline_stage *aaline = aaline_stage_from_pipe(pipe); + + /* save current */ + memcpy(aaline->state.sampler, sampler, num * sizeof(void *)); + aaline->num_samplers = num; + + /* pass-through */ + aaline->driver_bind_sampler_states(pipe, num, sampler); +} + + +static void +aaline_set_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct aaline_stage *aaline = aaline_stage_from_pipe(pipe); + uint i; + + /* save current */ + for (i = 0; i < num; i++) { + pipe_sampler_view_reference(&aaline->state.sampler_views[i], views[i]); + } + for ( ; i < PIPE_MAX_SAMPLERS; i++) { + pipe_sampler_view_reference(&aaline->state.sampler_views[i], NULL); + } + aaline->num_sampler_views = num; + + /* pass-through */ + aaline->driver_set_sampler_views(pipe, num, views); +} + + +/** + * Called by drivers that want to install this AA line prim stage + * into the draw module's pipeline. This will not be used if the + * hardware has native support for AA lines. + */ +boolean +draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe) +{ + struct aaline_stage *aaline; + + pipe->draw = (void *) draw; + + /* + * Create / install AA line drawing / prim stage + */ + aaline = draw_aaline_stage( draw ); + if (!aaline) + goto fail; + + /* create special texture, sampler state */ + if (!aaline_create_texture(aaline)) + goto fail; + + if (!aaline_create_sampler(aaline)) + goto fail; + + /* save original driver functions */ + aaline->driver_create_fs_state = pipe->create_fs_state; + aaline->driver_bind_fs_state = pipe->bind_fs_state; + aaline->driver_delete_fs_state = pipe->delete_fs_state; + + aaline->driver_bind_sampler_states = pipe->bind_fragment_sampler_states; + aaline->driver_set_sampler_views = pipe->set_fragment_sampler_views; + + /* override the driver's functions */ + pipe->create_fs_state = aaline_create_fs_state; + pipe->bind_fs_state = aaline_bind_fs_state; + pipe->delete_fs_state = aaline_delete_fs_state; + + pipe->bind_fragment_sampler_states = aaline_bind_sampler_states; + pipe->set_fragment_sampler_views = aaline_set_sampler_views; + + /* Install once everything is known to be OK: + */ + draw->pipeline.aaline = &aaline->stage; + + return TRUE; + + fail: + if (aaline) + aaline->stage.destroy( &aaline->stage ); + + return FALSE; +} diff --git a/src/gallium/auxiliary/draw/draw_pipe_aapoint.c b/src/gallium/auxiliary/draw/draw_pipe_aapoint.c new file mode 100644 index 0000000..5ea552f --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_aapoint.c @@ -0,0 +1,897 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * AA point stage: AA points are converted to quads and rendered with a + * special fragment shader. Another approach would be to use a texture + * map image of a point, but experiments indicate the quality isn't nearly + * as good as this approach. + * + * Note: this looks a lot like draw_aaline.c but there's actually little + * if any code that can be shared. + * + * Authors: Brian Paul + */ + + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" + +#include "tgsi/tgsi_transform.h" +#include "tgsi/tgsi_dump.h" + +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "draw_context.h" +#include "draw_vs.h" +#include "draw_pipe.h" + + +/** Approx number of new tokens for instructions in aa_transform_inst() */ +#define NUM_NEW_TOKENS 200 + + +/* + * Enabling NORMALIZE might give _slightly_ better results. + * Basically, it controls whether we compute distance as d=sqrt(x*x+y*y) or + * d=x*x+y*y. Since we're working with a unit circle, the later seems + * close enough and saves some costly instructions. + */ +#define NORMALIZE 0 + + +/** + * Subclass of pipe_shader_state to carry extra fragment shader info. + */ +struct aapoint_fragment_shader +{ + struct pipe_shader_state state; + void *driver_fs; /**< the regular shader */ + void *aapoint_fs; /**< the aa point-augmented shader */ + int generic_attrib; /**< The generic input attrib/texcoord we'll use */ +}; + + +/** + * Subclass of draw_stage + */ +struct aapoint_stage +{ + struct draw_stage stage; + + /** half of pipe_rasterizer_state::point_size */ + float radius; + + /** vertex attrib slot containing point size */ + int psize_slot; + + /** this is the vertex attrib slot for the new texcoords */ + uint tex_slot; + + /** vertex attrib slot containing position */ + uint pos_slot; + + /** Currently bound fragment shader */ + struct aapoint_fragment_shader *fs; + + /* + * Driver interface/override functions + */ + void * (*driver_create_fs_state)(struct pipe_context *, + const struct pipe_shader_state *); + void (*driver_bind_fs_state)(struct pipe_context *, void *); + void (*driver_delete_fs_state)(struct pipe_context *, void *); +}; + + + +/** + * Subclass of tgsi_transform_context, used for transforming the + * user's fragment shader to add the special AA instructions. + */ +struct aa_transform_context { + struct tgsi_transform_context base; + uint tempsUsed; /**< bitmask */ + int colorOutput; /**< which output is the primary color */ + int maxInput, maxGeneric; /**< max input index found */ + int tmp0, colorTemp; /**< temp registers */ + boolean firstInstruction; +}; + + +/** + * TGSI declaration transform callback. + * Look for two free temp regs and available input reg for new texcoords. + */ +static void +aa_transform_decl(struct tgsi_transform_context *ctx, + struct tgsi_full_declaration *decl) +{ + struct aa_transform_context *aactx = (struct aa_transform_context *) ctx; + + if (decl->Declaration.File == TGSI_FILE_OUTPUT && + decl->Semantic.Name == TGSI_SEMANTIC_COLOR && + decl->Semantic.Index == 0) { + aactx->colorOutput = decl->Range.First; + } + else if (decl->Declaration.File == TGSI_FILE_INPUT) { + if ((int) decl->Range.Last > aactx->maxInput) + aactx->maxInput = decl->Range.Last; + if (decl->Semantic.Name == TGSI_SEMANTIC_GENERIC && + (int) decl->Semantic.Index > aactx->maxGeneric) { + aactx->maxGeneric = decl->Semantic.Index; + } + } + else if (decl->Declaration.File == TGSI_FILE_TEMPORARY) { + uint i; + for (i = decl->Range.First; + i <= decl->Range.Last; i++) { + aactx->tempsUsed |= (1 << i); + } + } + + ctx->emit_declaration(ctx, decl); +} + + +/** + * TGSI instruction transform callback. + * Replace writes to result.color w/ a temp reg. + * Upon END instruction, insert texture sampling code for antialiasing. + */ +static void +aa_transform_inst(struct tgsi_transform_context *ctx, + struct tgsi_full_instruction *inst) +{ + struct aa_transform_context *aactx = (struct aa_transform_context *) ctx; + struct tgsi_full_instruction newInst; + + if (aactx->firstInstruction) { + /* emit our new declarations before the first instruction */ + + struct tgsi_full_declaration decl; + const int texInput = aactx->maxInput + 1; + int tmp0; + uint i; + + /* find two free temp regs */ + for (i = 0; i < 32; i++) { + if ((aactx->tempsUsed & (1 << i)) == 0) { + /* found a free temp */ + if (aactx->tmp0 < 0) + aactx->tmp0 = i; + else if (aactx->colorTemp < 0) + aactx->colorTemp = i; + else + break; + } + } + + assert(aactx->colorTemp != aactx->tmp0); + + tmp0 = aactx->tmp0; + + /* declare new generic input/texcoord */ + decl = tgsi_default_full_declaration(); + decl.Declaration.File = TGSI_FILE_INPUT; + /* XXX this could be linear... */ + decl.Declaration.Interpolate = TGSI_INTERPOLATE_PERSPECTIVE; + decl.Declaration.Semantic = 1; + decl.Semantic.Name = TGSI_SEMANTIC_GENERIC; + decl.Semantic.Index = aactx->maxGeneric + 1; + decl.Range.First = + decl.Range.Last = texInput; + ctx->emit_declaration(ctx, &decl); + + /* declare new temp regs */ + decl = tgsi_default_full_declaration(); + decl.Declaration.File = TGSI_FILE_TEMPORARY; + decl.Range.First = + decl.Range.Last = tmp0; + ctx->emit_declaration(ctx, &decl); + + decl = tgsi_default_full_declaration(); + decl.Declaration.File = TGSI_FILE_TEMPORARY; + decl.Range.First = + decl.Range.Last = aactx->colorTemp; + ctx->emit_declaration(ctx, &decl); + + aactx->firstInstruction = FALSE; + + + /* + * Emit code to compute fragment coverage, kill if outside point radius + * + * Temp reg0 usage: + * t0.x = distance of fragment from center point + * t0.y = boolean, is t0.x > 1.0, also misc temp usage + * t0.z = temporary for computing 1/(1-k) value + * t0.w = final coverage value + */ + + /* MUL t0.xy, tex, tex; # compute x^2, y^2 */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_MUL; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Dst[0].Register.Index = tmp0; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_XY; + newInst.Instruction.NumSrcRegs = 2; + newInst.Src[0].Register.File = TGSI_FILE_INPUT; + newInst.Src[0].Register.Index = texInput; + newInst.Src[1].Register.File = TGSI_FILE_INPUT; + newInst.Src[1].Register.Index = texInput; + ctx->emit_instruction(ctx, &newInst); + + /* ADD t0.x, t0.x, t0.y; # x^2 + y^2 */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_ADD; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Dst[0].Register.Index = tmp0; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_X; + newInst.Instruction.NumSrcRegs = 2; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = tmp0; + newInst.Src[0].Register.SwizzleX = TGSI_SWIZZLE_X; + newInst.Src[1].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[1].Register.Index = tmp0; + newInst.Src[1].Register.SwizzleX = TGSI_SWIZZLE_Y; + ctx->emit_instruction(ctx, &newInst); + +#if NORMALIZE /* OPTIONAL normalization of length */ + /* RSQ t0.x, t0.x; */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_RSQ; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Dst[0].Register.Index = tmp0; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_X; + newInst.Instruction.NumSrcRegs = 1; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = tmp0; + ctx->emit_instruction(ctx, &newInst); + + /* RCP t0.x, t0.x; */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_RCP; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Dst[0].Register.Index = tmp0; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_X; + newInst.Instruction.NumSrcRegs = 1; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = tmp0; + ctx->emit_instruction(ctx, &newInst); +#endif + + /* SGT t0.y, t0.xxxx, tex.wwww; # bool b = d > 1 (NOTE tex.w == 1) */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_SGT; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Dst[0].Register.Index = tmp0; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_Y; + newInst.Instruction.NumSrcRegs = 2; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = tmp0; + newInst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_X; + newInst.Src[1].Register.File = TGSI_FILE_INPUT; + newInst.Src[1].Register.Index = texInput; + newInst.Src[1].Register.SwizzleY = TGSI_SWIZZLE_W; + ctx->emit_instruction(ctx, &newInst); + + /* KIL -tmp0.yyyy; # if -tmp0.y < 0, KILL */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_KIL; + newInst.Instruction.NumDstRegs = 0; + newInst.Instruction.NumSrcRegs = 1; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = tmp0; + newInst.Src[0].Register.SwizzleX = TGSI_SWIZZLE_Y; + newInst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_Y; + newInst.Src[0].Register.SwizzleZ = TGSI_SWIZZLE_Y; + newInst.Src[0].Register.SwizzleW = TGSI_SWIZZLE_Y; + newInst.Src[0].Register.Negate = 1; + ctx->emit_instruction(ctx, &newInst); + + + /* compute coverage factor = (1-d)/(1-k) */ + + /* SUB t0.z, tex.w, tex.z; # m = 1 - k */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_SUB; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Dst[0].Register.Index = tmp0; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_Z; + newInst.Instruction.NumSrcRegs = 2; + newInst.Src[0].Register.File = TGSI_FILE_INPUT; + newInst.Src[0].Register.Index = texInput; + newInst.Src[0].Register.SwizzleZ = TGSI_SWIZZLE_W; + newInst.Src[1].Register.File = TGSI_FILE_INPUT; + newInst.Src[1].Register.Index = texInput; + newInst.Src[1].Register.SwizzleZ = TGSI_SWIZZLE_Z; + ctx->emit_instruction(ctx, &newInst); + + /* RCP t0.z, t0.z; # t0.z = 1 / m */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_RCP; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Dst[0].Register.Index = tmp0; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_Z; + newInst.Instruction.NumSrcRegs = 1; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = tmp0; + newInst.Src[0].Register.SwizzleX = TGSI_SWIZZLE_Z; + ctx->emit_instruction(ctx, &newInst); + + /* SUB t0.y, 1, t0.x; # d = 1 - d */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_SUB; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Dst[0].Register.Index = tmp0; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_Y; + newInst.Instruction.NumSrcRegs = 2; + newInst.Src[0].Register.File = TGSI_FILE_INPUT; + newInst.Src[0].Register.Index = texInput; + newInst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_W; + newInst.Src[1].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[1].Register.Index = tmp0; + newInst.Src[1].Register.SwizzleY = TGSI_SWIZZLE_X; + ctx->emit_instruction(ctx, &newInst); + + /* MUL t0.w, t0.y, t0.z; # coverage = d * m */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_MUL; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Dst[0].Register.Index = tmp0; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_W; + newInst.Instruction.NumSrcRegs = 2; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = tmp0; + newInst.Src[0].Register.SwizzleW = TGSI_SWIZZLE_Y; + newInst.Src[1].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[1].Register.Index = tmp0; + newInst.Src[1].Register.SwizzleW = TGSI_SWIZZLE_Z; + ctx->emit_instruction(ctx, &newInst); + + /* SLE t0.y, t0.x, tex.z; # bool b = distance <= k */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_SLE; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Dst[0].Register.Index = tmp0; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_Y; + newInst.Instruction.NumSrcRegs = 2; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = tmp0; + newInst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_X; + newInst.Src[1].Register.File = TGSI_FILE_INPUT; + newInst.Src[1].Register.Index = texInput; + newInst.Src[1].Register.SwizzleY = TGSI_SWIZZLE_Z; + ctx->emit_instruction(ctx, &newInst); + + /* CMP t0.w, -t0.y, tex.w, t0.w; + * # if -t0.y < 0 then + * t0.w = 1 + * else + * t0.w = t0.w + */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_CMP; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Dst[0].Register.Index = tmp0; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_W; + newInst.Instruction.NumSrcRegs = 3; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = tmp0; + newInst.Src[0].Register.SwizzleX = TGSI_SWIZZLE_Y; + newInst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_Y; + newInst.Src[0].Register.SwizzleZ = TGSI_SWIZZLE_Y; + newInst.Src[0].Register.SwizzleW = TGSI_SWIZZLE_Y; + newInst.Src[0].Register.Negate = 1; + newInst.Src[1].Register.File = TGSI_FILE_INPUT; + newInst.Src[1].Register.Index = texInput; + newInst.Src[1].Register.SwizzleX = TGSI_SWIZZLE_W; + newInst.Src[1].Register.SwizzleY = TGSI_SWIZZLE_W; + newInst.Src[1].Register.SwizzleZ = TGSI_SWIZZLE_W; + newInst.Src[1].Register.SwizzleW = TGSI_SWIZZLE_W; + newInst.Src[2].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[2].Register.Index = tmp0; + newInst.Src[2].Register.SwizzleX = TGSI_SWIZZLE_W; + newInst.Src[2].Register.SwizzleY = TGSI_SWIZZLE_W; + newInst.Src[2].Register.SwizzleZ = TGSI_SWIZZLE_W; + newInst.Src[2].Register.SwizzleW = TGSI_SWIZZLE_W; + ctx->emit_instruction(ctx, &newInst); + + } + + if (inst->Instruction.Opcode == TGSI_OPCODE_END) { + /* add alpha modulation code at tail of program */ + + /* MOV result.color.xyz, colorTemp; */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_MOV; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_OUTPUT; + newInst.Dst[0].Register.Index = aactx->colorOutput; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_XYZ; + newInst.Instruction.NumSrcRegs = 1; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = aactx->colorTemp; + ctx->emit_instruction(ctx, &newInst); + + /* MUL result.color.w, colorTemp, tmp0.w; */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_MUL; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_OUTPUT; + newInst.Dst[0].Register.Index = aactx->colorOutput; + newInst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_W; + newInst.Instruction.NumSrcRegs = 2; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = aactx->colorTemp; + newInst.Src[1].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[1].Register.Index = aactx->tmp0; + ctx->emit_instruction(ctx, &newInst); + } + else { + /* Not an END instruction. + * Look for writes to result.color and replace with colorTemp reg. + */ + uint i; + + for (i = 0; i < inst->Instruction.NumDstRegs; i++) { + struct tgsi_full_dst_register *dst = &inst->Dst[i]; + if (dst->Register.File == TGSI_FILE_OUTPUT && + dst->Register.Index == aactx->colorOutput) { + dst->Register.File = TGSI_FILE_TEMPORARY; + dst->Register.Index = aactx->colorTemp; + } + } + } + + ctx->emit_instruction(ctx, inst); +} + + +/** + * Generate the frag shader we'll use for drawing AA points. + * This will be the user's shader plus some texture/modulate instructions. + */ +static boolean +generate_aapoint_fs(struct aapoint_stage *aapoint) +{ + const struct pipe_shader_state *orig_fs = &aapoint->fs->state; + struct pipe_shader_state aapoint_fs; + struct aa_transform_context transform; + const uint newLen = tgsi_num_tokens(orig_fs->tokens) + NUM_NEW_TOKENS; + struct pipe_context *pipe = aapoint->stage.draw->pipe; + + aapoint_fs = *orig_fs; /* copy to init */ + aapoint_fs.tokens = tgsi_alloc_tokens(newLen); + if (aapoint_fs.tokens == NULL) + return FALSE; + + memset(&transform, 0, sizeof(transform)); + transform.colorOutput = -1; + transform.maxInput = -1; + transform.maxGeneric = -1; + transform.colorTemp = -1; + transform.tmp0 = -1; + transform.firstInstruction = TRUE; + transform.base.transform_instruction = aa_transform_inst; + transform.base.transform_declaration = aa_transform_decl; + + tgsi_transform_shader(orig_fs->tokens, + (struct tgsi_token *) aapoint_fs.tokens, + newLen, &transform.base); + +#if 0 /* DEBUG */ + printf("draw_aapoint, orig shader:\n"); + tgsi_dump(orig_fs->tokens, 0); + printf("draw_aapoint, new shader:\n"); + tgsi_dump(aapoint_fs.tokens, 0); +#endif + + aapoint->fs->aapoint_fs + = aapoint->driver_create_fs_state(pipe, &aapoint_fs); + if (aapoint->fs->aapoint_fs == NULL) + goto fail; + + aapoint->fs->generic_attrib = transform.maxGeneric + 1; + FREE((void *)aapoint_fs.tokens); + return TRUE; + +fail: + FREE((void *)aapoint_fs.tokens); + return FALSE; +} + + +/** + * When we're about to draw our first AA point in a batch, this function is + * called to tell the driver to bind our modified fragment shader. + */ +static boolean +bind_aapoint_fragment_shader(struct aapoint_stage *aapoint) +{ + struct draw_context *draw = aapoint->stage.draw; + struct pipe_context *pipe = draw->pipe; + + if (!aapoint->fs->aapoint_fs && + !generate_aapoint_fs(aapoint)) + return FALSE; + + draw->suspend_flushing = TRUE; + aapoint->driver_bind_fs_state(pipe, aapoint->fs->aapoint_fs); + draw->suspend_flushing = FALSE; + + return TRUE; +} + + + +static INLINE struct aapoint_stage * +aapoint_stage( struct draw_stage *stage ) +{ + return (struct aapoint_stage *) stage; +} + + + + +/** + * Draw an AA point by drawing a quad. + */ +static void +aapoint_point(struct draw_stage *stage, struct prim_header *header) +{ + const struct aapoint_stage *aapoint = aapoint_stage(stage); + struct prim_header tri; + struct vertex_header *v[4]; + const uint tex_slot = aapoint->tex_slot; + const uint pos_slot = aapoint->pos_slot; + float radius, *pos, *tex; + uint i; + float k; + + if (aapoint->psize_slot >= 0) { + radius = 0.5f * header->v[0]->data[aapoint->psize_slot][0]; + } + else { + radius = aapoint->radius; + } + + /* + * Note: the texcoords (generic attrib, really) we use are special: + * The S and T components simply vary from -1 to +1. + * The R component is k, below. + * The Q component is 1.0 and will used as a handy constant in the + * fragment shader. + */ + + /* + * k is the threshold distance from the point's center at which + * we begin alpha attenuation (the coverage value). + * Operating within a unit circle, we'll compute the fragment's + * distance 'd' from the center point using the texcoords. + * IF d > 1.0 THEN + * KILL fragment + * ELSE IF d > k THEN + * compute coverage in [0,1] proportional to d in [k, 1]. + * ELSE + * coverage = 1.0; // full coverage + * ENDIF + * + * Note: the ELSEIF and ELSE clauses are actually implemented with CMP to + * avoid using IF/ELSE/ENDIF TGSI opcodes. + */ + +#if !NORMALIZE + k = 1.0f / radius; + k = 1.0f - 2.0f * k + k * k; +#else + k = 1.0f - 1.0f / radius; +#endif + + /* allocate/dup new verts */ + for (i = 0; i < 4; i++) { + v[i] = dup_vert(stage, header->v[0], i); + } + + /* new verts */ + pos = v[0]->data[pos_slot]; + pos[0] -= radius; + pos[1] -= radius; + + pos = v[1]->data[pos_slot]; + pos[0] += radius; + pos[1] -= radius; + + pos = v[2]->data[pos_slot]; + pos[0] += radius; + pos[1] += radius; + + pos = v[3]->data[pos_slot]; + pos[0] -= radius; + pos[1] += radius; + + /* new texcoords */ + tex = v[0]->data[tex_slot]; + ASSIGN_4V(tex, -1, -1, k, 1); + + tex = v[1]->data[tex_slot]; + ASSIGN_4V(tex, 1, -1, k, 1); + + tex = v[2]->data[tex_slot]; + ASSIGN_4V(tex, 1, 1, k, 1); + + tex = v[3]->data[tex_slot]; + ASSIGN_4V(tex, -1, 1, k, 1); + + /* emit 2 tris for the quad strip */ + tri.v[0] = v[0]; + tri.v[1] = v[1]; + tri.v[2] = v[2]; + stage->next->tri( stage->next, &tri ); + + tri.v[0] = v[0]; + tri.v[1] = v[2]; + tri.v[2] = v[3]; + stage->next->tri( stage->next, &tri ); +} + + +static void +aapoint_first_point(struct draw_stage *stage, struct prim_header *header) +{ + auto struct aapoint_stage *aapoint = aapoint_stage(stage); + struct draw_context *draw = stage->draw; + struct pipe_context *pipe = draw->pipe; + const struct pipe_rasterizer_state *rast = draw->rasterizer; + void *r; + + assert(draw->rasterizer->point_smooth); + + if (draw->rasterizer->point_size <= 2.0) + aapoint->radius = 1.0; + else + aapoint->radius = 0.5f * draw->rasterizer->point_size; + + /* + * Bind (generate) our fragprog. + */ + bind_aapoint_fragment_shader(aapoint); + + /* update vertex attrib info */ + aapoint->tex_slot = draw_current_shader_outputs(draw); + assert(aapoint->tex_slot > 0); /* output[0] is vertex pos */ + + aapoint->pos_slot = draw_current_shader_position_output(draw); + + /* allocate the extra post-transformed vertex attribute */ + (void) draw_alloc_extra_vertex_attrib(draw, TGSI_SEMANTIC_GENERIC, + aapoint->fs->generic_attrib); + + /* find psize slot in post-transform vertex */ + aapoint->psize_slot = -1; + if (draw->rasterizer->point_size_per_vertex) { + /* find PSIZ vertex output */ + const struct draw_vertex_shader *vs = draw->vs.vertex_shader; + uint i; + for (i = 0; i < vs->info.num_outputs; i++) { + if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_PSIZE) { + aapoint->psize_slot = i; + break; + } + } + } + + draw->suspend_flushing = TRUE; + + /* Disable triangle culling, stippling, unfilled mode etc. */ + r = draw_get_rasterizer_no_cull(draw, rast->scissor, rast->flatshade); + pipe->bind_rasterizer_state(pipe, r); + + draw->suspend_flushing = FALSE; + + /* now really draw first point */ + stage->point = aapoint_point; + stage->point(stage, header); +} + + +static void +aapoint_flush(struct draw_stage *stage, unsigned flags) +{ + struct draw_context *draw = stage->draw; + struct aapoint_stage *aapoint = aapoint_stage(stage); + struct pipe_context *pipe = draw->pipe; + + stage->point = aapoint_first_point; + stage->next->flush( stage->next, flags ); + + /* restore original frag shader */ + draw->suspend_flushing = TRUE; + aapoint->driver_bind_fs_state(pipe, aapoint->fs->driver_fs); + + /* restore original rasterizer state */ + if (draw->rast_handle) { + pipe->bind_rasterizer_state(pipe, draw->rast_handle); + } + + draw->suspend_flushing = FALSE; + + draw_remove_extra_vertex_attribs(draw); +} + + +static void +aapoint_reset_stipple_counter(struct draw_stage *stage) +{ + stage->next->reset_stipple_counter( stage->next ); +} + + +static void +aapoint_destroy(struct draw_stage *stage) +{ + draw_free_temp_verts( stage ); + FREE( stage ); +} + + +static struct aapoint_stage * +draw_aapoint_stage(struct draw_context *draw) +{ + struct aapoint_stage *aapoint = CALLOC_STRUCT(aapoint_stage); + if (aapoint == NULL) + goto fail; + + aapoint->stage.draw = draw; + aapoint->stage.name = "aapoint"; + aapoint->stage.next = NULL; + aapoint->stage.point = aapoint_first_point; + aapoint->stage.line = draw_pipe_passthrough_line; + aapoint->stage.tri = draw_pipe_passthrough_tri; + aapoint->stage.flush = aapoint_flush; + aapoint->stage.reset_stipple_counter = aapoint_reset_stipple_counter; + aapoint->stage.destroy = aapoint_destroy; + + if (!draw_alloc_temp_verts( &aapoint->stage, 4 )) + goto fail; + + return aapoint; + + fail: + if (aapoint) + aapoint->stage.destroy(&aapoint->stage); + + return NULL; + +} + + +static struct aapoint_stage * +aapoint_stage_from_pipe(struct pipe_context *pipe) +{ + struct draw_context *draw = (struct draw_context *) pipe->draw; + return aapoint_stage(draw->pipeline.aapoint); +} + + +/** + * This function overrides the driver's create_fs_state() function and + * will typically be called by the state tracker. + */ +static void * +aapoint_create_fs_state(struct pipe_context *pipe, + const struct pipe_shader_state *fs) +{ + struct aapoint_stage *aapoint = aapoint_stage_from_pipe(pipe); + struct aapoint_fragment_shader *aafs = CALLOC_STRUCT(aapoint_fragment_shader); + if (aafs == NULL) + return NULL; + + aafs->state = *fs; + + /* pass-through */ + aafs->driver_fs = aapoint->driver_create_fs_state(pipe, fs); + + return aafs; +} + + +static void +aapoint_bind_fs_state(struct pipe_context *pipe, void *fs) +{ + struct aapoint_stage *aapoint = aapoint_stage_from_pipe(pipe); + struct aapoint_fragment_shader *aafs = (struct aapoint_fragment_shader *) fs; + /* save current */ + aapoint->fs = aafs; + /* pass-through */ + aapoint->driver_bind_fs_state(pipe, + (aafs ? aafs->driver_fs : NULL)); +} + + +static void +aapoint_delete_fs_state(struct pipe_context *pipe, void *fs) +{ + struct aapoint_stage *aapoint = aapoint_stage_from_pipe(pipe); + struct aapoint_fragment_shader *aafs = (struct aapoint_fragment_shader *) fs; + + /* pass-through */ + aapoint->driver_delete_fs_state(pipe, aafs->driver_fs); + + if (aafs->aapoint_fs) + aapoint->driver_delete_fs_state(pipe, aafs->aapoint_fs); + + FREE(aafs); +} + + +/** + * Called by drivers that want to install this AA point prim stage + * into the draw module's pipeline. This will not be used if the + * hardware has native support for AA points. + */ +boolean +draw_install_aapoint_stage(struct draw_context *draw, + struct pipe_context *pipe) +{ + struct aapoint_stage *aapoint; + + /* + * Create / install AA point drawing / prim stage + */ + aapoint = draw_aapoint_stage( draw ); + if (aapoint == NULL) + return FALSE; + + /* save original driver functions */ + aapoint->driver_create_fs_state = pipe->create_fs_state; + aapoint->driver_bind_fs_state = pipe->bind_fs_state; + aapoint->driver_delete_fs_state = pipe->delete_fs_state; + + /* override the driver's functions */ + pipe->create_fs_state = aapoint_create_fs_state; + pipe->bind_fs_state = aapoint_bind_fs_state; + pipe->delete_fs_state = aapoint_delete_fs_state; + + draw->pipeline.aapoint = &aapoint->stage; + + return TRUE; +} diff --git a/src/gallium/auxiliary/draw/draw_pipe_clip.c b/src/gallium/auxiliary/draw/draw_pipe_clip.c new file mode 100644 index 0000000..a10d8e9 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_clip.c @@ -0,0 +1,568 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \brief Clipping stage + * + * \author Keith Whitwell + */ + + +#include "util/u_memory.h" +#include "util/u_math.h" + +#include "pipe/p_shader_tokens.h" + +#include "draw_vs.h" +#include "draw_pipe.h" + + +#ifndef IS_NEGATIVE +#define IS_NEGATIVE(X) ((X) < 0.0) +#endif + +#ifndef DIFFERENT_SIGNS +#define DIFFERENT_SIGNS(x, y) ((x) * (y) <= 0.0F && (x) - (y) != 0.0F) +#endif + +#ifndef MAX_CLIPPED_VERTICES +#define MAX_CLIPPED_VERTICES ((2 * (6 + PIPE_MAX_CLIP_PLANES))+1) +#endif + + + +struct clip_stage { + struct draw_stage stage; /**< base class */ + + /* Basically duplicate some of the flatshading logic here: + */ + boolean flat; + uint num_color_attribs; + uint color_attribs[4]; /* front/back primary/secondary colors */ + + float (*plane)[4]; +}; + + +/** Cast wrapper */ +static INLINE struct clip_stage *clip_stage( struct draw_stage *stage ) +{ + return (struct clip_stage *)stage; +} + + +#define LINTERP(T, OUT, IN) ((OUT) + (T) * ((IN) - (OUT))) + + +/* All attributes are float[4], so this is easy: + */ +static void interp_attr( float dst[4], + float t, + const float in[4], + const float out[4] ) +{ + dst[0] = LINTERP( t, out[0], in[0] ); + dst[1] = LINTERP( t, out[1], in[1] ); + dst[2] = LINTERP( t, out[2], in[2] ); + dst[3] = LINTERP( t, out[3], in[3] ); +} + + +/** + * Copy front/back, primary/secondary colors from src vertex to dst vertex. + * Used when flat shading. + */ +static void copy_colors( struct draw_stage *stage, + struct vertex_header *dst, + const struct vertex_header *src ) +{ + const struct clip_stage *clipper = clip_stage(stage); + uint i; + for (i = 0; i < clipper->num_color_attribs; i++) { + const uint attr = clipper->color_attribs[i]; + COPY_4FV(dst->data[attr], src->data[attr]); + } +} + + + +/* Interpolate between two vertices to produce a third. + */ +static void interp( const struct clip_stage *clip, + struct vertex_header *dst, + float t, + const struct vertex_header *out, + const struct vertex_header *in ) +{ + const unsigned nr_attrs = draw_current_shader_outputs(clip->stage.draw); + const unsigned pos_attr = draw_current_shader_position_output(clip->stage.draw); + unsigned j; + + /* Vertex header. + */ + dst->clipmask = 0; + dst->edgeflag = 0; /* will get overwritten later */ + dst->pad = 0; + dst->vertex_id = UNDEFINED_VERTEX_ID; + + /* Interpolate the clip-space coords. + */ + interp_attr(dst->clip, t, in->clip, out->clip); + + /* Do the projective divide and viewport transformation to get + * new window coordinates: + */ + { + const float *pos = dst->clip; + const float *scale = clip->stage.draw->viewport.scale; + const float *trans = clip->stage.draw->viewport.translate; + const float oow = 1.0f / pos[3]; + + dst->data[pos_attr][0] = pos[0] * oow * scale[0] + trans[0]; + dst->data[pos_attr][1] = pos[1] * oow * scale[1] + trans[1]; + dst->data[pos_attr][2] = pos[2] * oow * scale[2] + trans[2]; + dst->data[pos_attr][3] = oow; + } + + /* Other attributes + */ + for (j = 0; j < nr_attrs; j++) { + if (j != pos_attr) + interp_attr(dst->data[j], t, in->data[j], out->data[j]); + } +} + + +/** + * Emit a post-clip polygon to the next pipeline stage. The polygon + * will be convex and the provoking vertex will always be vertex[0]. + */ +static void emit_poly( struct draw_stage *stage, + struct vertex_header **inlist, + unsigned n, + const struct prim_header *origPrim) +{ + struct prim_header header; + unsigned i; + ushort edge_first, edge_middle, edge_last; + + if (stage->draw->rasterizer->flatshade_first) { + edge_first = DRAW_PIPE_EDGE_FLAG_0; + edge_middle = DRAW_PIPE_EDGE_FLAG_1; + edge_last = DRAW_PIPE_EDGE_FLAG_2; + } + else { + edge_first = DRAW_PIPE_EDGE_FLAG_2; + edge_middle = DRAW_PIPE_EDGE_FLAG_0; + edge_last = DRAW_PIPE_EDGE_FLAG_1; + } + + /* later stages may need the determinant, but only the sign matters */ + header.det = origPrim->det; + header.flags = DRAW_PIPE_RESET_STIPPLE | edge_first | edge_middle; + header.pad = 0; + + for (i = 2; i < n; i++, header.flags = edge_middle) { + /* order the triangle verts to respect the provoking vertex mode */ + if (stage->draw->rasterizer->flatshade_first) { + header.v[0] = inlist[0]; /* the provoking vertex */ + header.v[1] = inlist[i-1]; + header.v[2] = inlist[i]; + } + else { + header.v[0] = inlist[i-1]; + header.v[1] = inlist[i]; + header.v[2] = inlist[0]; /* the provoking vertex */ + } + + if (i == n-1) + header.flags |= edge_last; + + if (0) { + const struct draw_vertex_shader *vs = stage->draw->vs.vertex_shader; + uint j, k; + debug_printf("Clipped tri: (flat-shade-first = %d)\n", + stage->draw->rasterizer->flatshade_first); + for (j = 0; j < 3; j++) { + for (k = 0; k < vs->info.num_outputs; k++) { + debug_printf(" Vert %d: Attr %d: %f %f %f %f\n", j, k, + header.v[j]->data[k][0], + header.v[j]->data[k][1], + header.v[j]->data[k][2], + header.v[j]->data[k][3]); + } + } + } + + stage->next->tri( stage->next, &header ); + } +} + + +static INLINE float +dot4(const float *a, const float *b) +{ + return (a[0] * b[0] + + a[1] * b[1] + + a[2] * b[2] + + a[3] * b[3]); +} + + +/* Clip a triangle against the viewport and user clip planes. + */ +static void +do_clip_tri( struct draw_stage *stage, + struct prim_header *header, + unsigned clipmask ) +{ + struct clip_stage *clipper = clip_stage( stage ); + struct vertex_header *a[MAX_CLIPPED_VERTICES]; + struct vertex_header *b[MAX_CLIPPED_VERTICES]; + struct vertex_header **inlist = a; + struct vertex_header **outlist = b; + unsigned tmpnr = 0; + unsigned n = 3; + unsigned i; + + inlist[0] = header->v[0]; + inlist[1] = header->v[1]; + inlist[2] = header->v[2]; + + while (clipmask && n >= 3) { + const unsigned plane_idx = ffs(clipmask)-1; + const float *plane = clipper->plane[plane_idx]; + struct vertex_header *vert_prev = inlist[0]; + float dp_prev = dot4( vert_prev->clip, plane ); + unsigned outcount = 0; + + clipmask &= ~(1<= MAX_CLIPPED_VERTICES) + return; + inlist[n] = inlist[0]; /* prevent rotation of vertices */ + + for (i = 1; i <= n; i++) { + struct vertex_header *vert = inlist[i]; + + float dp = dot4( vert->clip, plane ); + + if (!IS_NEGATIVE(dp_prev)) { + assert(outcount < MAX_CLIPPED_VERTICES); + if (outcount >= MAX_CLIPPED_VERTICES) + return; + outlist[outcount++] = vert_prev; + } + + if (DIFFERENT_SIGNS(dp, dp_prev)) { + struct vertex_header *new_vert; + + assert(tmpnr < MAX_CLIPPED_VERTICES + 1); + if (tmpnr >= MAX_CLIPPED_VERTICES + 1) + return; + new_vert = clipper->stage.tmp[tmpnr++]; + + assert(outcount < MAX_CLIPPED_VERTICES); + if (outcount >= MAX_CLIPPED_VERTICES) + return; + outlist[outcount++] = new_vert; + + if (IS_NEGATIVE(dp)) { + /* Going out of bounds. Avoid division by zero as we + * know dp != dp_prev from DIFFERENT_SIGNS, above. + */ + float t = dp / (dp - dp_prev); + interp( clipper, new_vert, t, vert, vert_prev ); + + /* Force edgeflag true in this case: + */ + new_vert->edgeflag = 1; + } else { + /* Coming back in. + */ + float t = dp_prev / (dp_prev - dp); + interp( clipper, new_vert, t, vert_prev, vert ); + + /* Copy starting vert's edgeflag: + */ + new_vert->edgeflag = vert_prev->edgeflag; + } + } + + vert_prev = vert; + dp_prev = dp; + } + + /* swap in/out lists */ + { + struct vertex_header **tmp = inlist; + inlist = outlist; + outlist = tmp; + n = outcount; + } + } + + /* If flat-shading, copy provoking vertex color to polygon vertex[0] + */ + if (n >= 3) { + if (clipper->flat) { + if (stage->draw->rasterizer->flatshade_first) { + if (inlist[0] != header->v[0]) { + assert(tmpnr < MAX_CLIPPED_VERTICES + 1); + if (tmpnr >= MAX_CLIPPED_VERTICES + 1) + return; + inlist[0] = dup_vert(stage, inlist[0], tmpnr++); + copy_colors(stage, inlist[0], header->v[0]); + } + } + else { + if (inlist[0] != header->v[2]) { + assert(tmpnr < MAX_CLIPPED_VERTICES + 1); + if (tmpnr >= MAX_CLIPPED_VERTICES + 1) + return; + inlist[0] = dup_vert(stage, inlist[0], tmpnr++); + copy_colors(stage, inlist[0], header->v[2]); + } + } + } + + /* Emit the polygon as triangles to the setup stage: + */ + emit_poly( stage, inlist, n, header ); + } +} + + +/* Clip a line against the viewport and user clip planes. + */ +static void +do_clip_line( struct draw_stage *stage, + struct prim_header *header, + unsigned clipmask ) +{ + const struct clip_stage *clipper = clip_stage( stage ); + struct vertex_header *v0 = header->v[0]; + struct vertex_header *v1 = header->v[1]; + const float *pos0 = v0->clip; + const float *pos1 = v1->clip; + float t0 = 0.0F; + float t1 = 0.0F; + struct prim_header newprim; + + while (clipmask) { + const unsigned plane_idx = ffs(clipmask)-1; + const float *plane = clipper->plane[plane_idx]; + const float dp0 = dot4( pos0, plane ); + const float dp1 = dot4( pos1, plane ); + + if (dp1 < 0.0F) { + float t = dp1 / (dp1 - dp0); + t1 = MAX2(t1, t); + } + + if (dp0 < 0.0F) { + float t = dp0 / (dp0 - dp1); + t0 = MAX2(t0, t); + } + + if (t0 + t1 >= 1.0F) + return; /* discard */ + + clipmask &= ~(1 << plane_idx); /* turn off this plane's bit */ + } + + if (v0->clipmask) { + interp( clipper, stage->tmp[0], t0, v0, v1 ); + + if (clipper->flat) + copy_colors(stage, stage->tmp[0], v0); + + newprim.v[0] = stage->tmp[0]; + } + else { + newprim.v[0] = v0; + } + + if (v1->clipmask) { + interp( clipper, stage->tmp[1], t1, v1, v0 ); + newprim.v[1] = stage->tmp[1]; + } + else { + newprim.v[1] = v1; + } + + stage->next->line( stage->next, &newprim ); +} + + +static void +clip_point( struct draw_stage *stage, + struct prim_header *header ) +{ + if (header->v[0]->clipmask == 0) + stage->next->point( stage->next, header ); +} + + +static void +clip_line( struct draw_stage *stage, + struct prim_header *header ) +{ + unsigned clipmask = (header->v[0]->clipmask | + header->v[1]->clipmask); + + if (clipmask == 0) { + /* no clipping needed */ + stage->next->line( stage->next, header ); + } + else if ((header->v[0]->clipmask & + header->v[1]->clipmask) == 0) { + do_clip_line(stage, header, clipmask); + } + /* else, totally clipped */ +} + + +static void +clip_tri( struct draw_stage *stage, + struct prim_header *header ) +{ + unsigned clipmask = (header->v[0]->clipmask | + header->v[1]->clipmask | + header->v[2]->clipmask); + + if (clipmask == 0) { + /* no clipping needed */ + stage->next->tri( stage->next, header ); + } + else if ((header->v[0]->clipmask & + header->v[1]->clipmask & + header->v[2]->clipmask) == 0) { + do_clip_tri(stage, header, clipmask); + } +} + + +/* Update state. Could further delay this until we hit the first + * primitive that really requires clipping. + */ +static void +clip_init_state( struct draw_stage *stage ) +{ + struct clip_stage *clipper = clip_stage( stage ); + + clipper->flat = stage->draw->rasterizer->flatshade ? TRUE : FALSE; + + if (clipper->flat) { + const struct draw_vertex_shader *vs = stage->draw->vs.vertex_shader; + uint i; + + clipper->num_color_attribs = 0; + for (i = 0; i < vs->info.num_outputs; i++) { + if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_COLOR || + vs->info.output_semantic_name[i] == TGSI_SEMANTIC_BCOLOR) { + clipper->color_attribs[clipper->num_color_attribs++] = i; + } + } + } + + stage->tri = clip_tri; + stage->line = clip_line; +} + + + +static void clip_first_tri( struct draw_stage *stage, + struct prim_header *header ) +{ + clip_init_state( stage ); + stage->tri( stage, header ); +} + +static void clip_first_line( struct draw_stage *stage, + struct prim_header *header ) +{ + clip_init_state( stage ); + stage->line( stage, header ); +} + + +static void clip_flush( struct draw_stage *stage, + unsigned flags ) +{ + stage->tri = clip_first_tri; + stage->line = clip_first_line; + stage->next->flush( stage->next, flags ); +} + + +static void clip_reset_stipple_counter( struct draw_stage *stage ) +{ + stage->next->reset_stipple_counter( stage->next ); +} + + +static void clip_destroy( struct draw_stage *stage ) +{ + draw_free_temp_verts( stage ); + FREE( stage ); +} + + +/** + * Allocate a new clipper stage. + * \return pointer to new stage object + */ +struct draw_stage *draw_clip_stage( struct draw_context *draw ) +{ + struct clip_stage *clipper = CALLOC_STRUCT(clip_stage); + if (clipper == NULL) + goto fail; + + clipper->stage.draw = draw; + clipper->stage.name = "clipper"; + clipper->stage.point = clip_point; + clipper->stage.line = clip_first_line; + clipper->stage.tri = clip_first_tri; + clipper->stage.flush = clip_flush; + clipper->stage.reset_stipple_counter = clip_reset_stipple_counter; + clipper->stage.destroy = clip_destroy; + + clipper->plane = draw->plane; + + if (!draw_alloc_temp_verts( &clipper->stage, MAX_CLIPPED_VERTICES+1 )) + goto fail; + + return &clipper->stage; + + fail: + if (clipper) + clipper->stage.destroy( &clipper->stage ); + + return NULL; +} diff --git a/src/gallium/auxiliary/draw/draw_pipe_cull.c b/src/gallium/auxiliary/draw/draw_pipe_cull.c new file mode 100644 index 0000000..2f4d01d --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_cull.c @@ -0,0 +1,152 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \brief Drawing stage for polygon culling + */ + +/* Authors: Keith Whitwell + */ + + +#include "util/u_memory.h" +#include "pipe/p_defines.h" +#include "draw_pipe.h" + + +struct cull_stage { + struct draw_stage stage; + unsigned cull_face; /**< which face(s) to cull (one of PIPE_FACE_x) */ + unsigned front_ccw; +}; + + +static INLINE struct cull_stage *cull_stage( struct draw_stage *stage ) +{ + return (struct cull_stage *)stage; +} + + +static void cull_tri( struct draw_stage *stage, + struct prim_header *header ) +{ + const unsigned pos = draw_current_shader_position_output(stage->draw); + + /* Window coords: */ + const float *v0 = header->v[0]->data[pos]; + const float *v1 = header->v[1]->data[pos]; + const float *v2 = header->v[2]->data[pos]; + + /* edge vectors: e = v0 - v2, f = v1 - v2 */ + const float ex = v0[0] - v2[0]; + const float ey = v0[1] - v2[1]; + const float fx = v1[0] - v2[0]; + const float fy = v1[1] - v2[1]; + + /* det = cross(e,f).z */ + header->det = ex * fy - ey * fx; + + if (header->det != 0) { + /* if det < 0 then Z points toward the camera and the triangle is + * counter-clockwise winding. + */ + unsigned ccw = (header->det < 0); + unsigned face = ((ccw == cull_stage(stage)->front_ccw) ? + PIPE_FACE_FRONT : + PIPE_FACE_BACK); + + if ((face & cull_stage(stage)->cull_face) == 0) { + /* triangle is not culled, pass to next stage */ + stage->next->tri( stage->next, header ); + } + } +} + + +static void cull_first_tri( struct draw_stage *stage, + struct prim_header *header ) +{ + struct cull_stage *cull = cull_stage(stage); + + cull->cull_face = stage->draw->rasterizer->cull_face; + cull->front_ccw = stage->draw->rasterizer->front_ccw; + + stage->tri = cull_tri; + stage->tri( stage, header ); +} + + +static void cull_flush( struct draw_stage *stage, unsigned flags ) +{ + stage->tri = cull_first_tri; + stage->next->flush( stage->next, flags ); +} + + +static void cull_reset_stipple_counter( struct draw_stage *stage ) +{ + stage->next->reset_stipple_counter( stage->next ); +} + + +static void cull_destroy( struct draw_stage *stage ) +{ + draw_free_temp_verts( stage ); + FREE( stage ); +} + + +/** + * Create a new polygon culling stage. + */ +struct draw_stage *draw_cull_stage( struct draw_context *draw ) +{ + struct cull_stage *cull = CALLOC_STRUCT(cull_stage); + if (cull == NULL) + goto fail; + + cull->stage.draw = draw; + cull->stage.name = "cull"; + cull->stage.next = NULL; + cull->stage.point = draw_pipe_passthrough_point; + cull->stage.line = draw_pipe_passthrough_line; + cull->stage.tri = cull_first_tri; + cull->stage.flush = cull_flush; + cull->stage.reset_stipple_counter = cull_reset_stipple_counter; + cull->stage.destroy = cull_destroy; + + if (!draw_alloc_temp_verts( &cull->stage, 0 )) + goto fail; + + return &cull->stage; + +fail: + if (cull) + cull->stage.destroy( &cull->stage ); + + return NULL; +} diff --git a/src/gallium/auxiliary/draw/draw_pipe_flatshade.c b/src/gallium/auxiliary/draw/draw_pipe_flatshade.c new file mode 100644 index 0000000..693f289 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_flatshade.c @@ -0,0 +1,282 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "pipe/p_shader_tokens.h" +#include "draw_vs.h" +#include "draw_pipe.h" + + +/** subclass of draw_stage */ +struct flat_stage +{ + struct draw_stage stage; + + uint num_color_attribs; + uint color_attribs[2]; /* front/back primary colors */ + + uint num_spec_attribs; + uint spec_attribs[2]; /* front/back secondary colors */ +}; + +#define COPY_3FV( DST, SRC ) \ +do { \ + (DST)[0] = (SRC)[0]; \ + (DST)[1] = (SRC)[1]; \ + (DST)[2] = (SRC)[2]; \ +} while (0) + + +static INLINE struct flat_stage * +flat_stage(struct draw_stage *stage) +{ + return (struct flat_stage *) stage; +} + + +/** Copy all the color attributes from 'src' vertex to 'dst' vertex */ +static INLINE void copy_colors( struct draw_stage *stage, + struct vertex_header *dst, + const struct vertex_header *src ) +{ + const struct flat_stage *flat = flat_stage(stage); + uint i; + + for (i = 0; i < flat->num_color_attribs; i++) { + const uint attr = flat->color_attribs[i]; + COPY_4FV(dst->data[attr], src->data[attr]); + } + + for (i = 0; i < flat->num_spec_attribs; i++) { + const uint attr = flat->spec_attribs[i]; + COPY_3FV(dst->data[attr], src->data[attr]); + } +} + + +/** Copy all the color attributes from src vertex to dst0 & dst1 vertices */ +static INLINE void copy_colors2( struct draw_stage *stage, + struct vertex_header *dst0, + struct vertex_header *dst1, + const struct vertex_header *src ) +{ + const struct flat_stage *flat = flat_stage(stage); + uint i; + for (i = 0; i < flat->num_color_attribs; i++) { + const uint attr = flat->color_attribs[i]; + COPY_4FV(dst0->data[attr], src->data[attr]); + COPY_4FV(dst1->data[attr], src->data[attr]); + } + + for (i = 0; i < flat->num_spec_attribs; i++) { + const uint attr = flat->spec_attribs[i]; + COPY_3FV(dst0->data[attr], src->data[attr]); + COPY_3FV(dst1->data[attr], src->data[attr]); + } +} + + +/** + * Flatshade tri. Required for clipping and when unfilled tris are + * active, otherwise handled by hardware. + */ +static void flatshade_tri_0( struct draw_stage *stage, + struct prim_header *header ) +{ + struct prim_header tmp; + + tmp.det = header->det; + tmp.flags = header->flags; + tmp.pad = header->pad; + tmp.v[0] = header->v[0]; + tmp.v[1] = dup_vert(stage, header->v[1], 0); + tmp.v[2] = dup_vert(stage, header->v[2], 1); + + copy_colors2(stage, tmp.v[1], tmp.v[2], tmp.v[0]); + + stage->next->tri( stage->next, &tmp ); +} + + +static void flatshade_tri_2( struct draw_stage *stage, + struct prim_header *header ) +{ + struct prim_header tmp; + + tmp.det = header->det; + tmp.flags = header->flags; + tmp.pad = header->pad; + tmp.v[0] = dup_vert(stage, header->v[0], 0); + tmp.v[1] = dup_vert(stage, header->v[1], 1); + tmp.v[2] = header->v[2]; + + copy_colors2(stage, tmp.v[0], tmp.v[1], tmp.v[2]); + + stage->next->tri( stage->next, &tmp ); +} + + + + + +/** + * Flatshade line. Required for clipping. + */ +static void flatshade_line_0( struct draw_stage *stage, + struct prim_header *header ) +{ + struct prim_header tmp; + + tmp.v[0] = header->v[0]; + tmp.v[1] = dup_vert(stage, header->v[1], 0); + + copy_colors(stage, tmp.v[1], tmp.v[0]); + + stage->next->line( stage->next, &tmp ); +} + +static void flatshade_line_1( struct draw_stage *stage, + struct prim_header *header ) +{ + struct prim_header tmp; + + tmp.v[0] = dup_vert(stage, header->v[0], 0); + tmp.v[1] = header->v[1]; + + copy_colors(stage, tmp.v[0], tmp.v[1]); + + stage->next->line( stage->next, &tmp ); +} + + + + +static void flatshade_init_state( struct draw_stage *stage ) +{ + struct flat_stage *flat = flat_stage(stage); + const struct draw_vertex_shader *vs = stage->draw->vs.vertex_shader; + uint i; + + /* Find which vertex shader outputs are colors, make a list */ + flat->num_color_attribs = 0; + flat->num_spec_attribs = 0; + for (i = 0; i < vs->info.num_outputs; i++) { + if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_COLOR || + vs->info.output_semantic_name[i] == TGSI_SEMANTIC_BCOLOR) { + if (vs->info.output_semantic_index[i] == 0) + flat->color_attribs[flat->num_color_attribs++] = i; + else + flat->spec_attribs[flat->num_spec_attribs++] = i; + } + } + + /* Choose flatshade routine according to provoking vertex: + */ + if (stage->draw->rasterizer->flatshade_first) { + stage->line = flatshade_line_0; + stage->tri = flatshade_tri_0; + } + else { + stage->line = flatshade_line_1; + stage->tri = flatshade_tri_2; + } +} + +static void flatshade_first_tri( struct draw_stage *stage, + struct prim_header *header ) +{ + flatshade_init_state( stage ); + stage->tri( stage, header ); +} + +static void flatshade_first_line( struct draw_stage *stage, + struct prim_header *header ) +{ + flatshade_init_state( stage ); + stage->line( stage, header ); +} + + +static void flatshade_flush( struct draw_stage *stage, + unsigned flags ) +{ + stage->tri = flatshade_first_tri; + stage->line = flatshade_first_line; + stage->next->flush( stage->next, flags ); +} + + +static void flatshade_reset_stipple_counter( struct draw_stage *stage ) +{ + stage->next->reset_stipple_counter( stage->next ); +} + + +static void flatshade_destroy( struct draw_stage *stage ) +{ + draw_free_temp_verts( stage ); + FREE( stage ); +} + + +/** + * Create flatshading drawing stage. + */ +struct draw_stage *draw_flatshade_stage( struct draw_context *draw ) +{ + struct flat_stage *flatshade = CALLOC_STRUCT(flat_stage); + if (flatshade == NULL) + goto fail; + + flatshade->stage.draw = draw; + flatshade->stage.name = "flatshade"; + flatshade->stage.next = NULL; + flatshade->stage.point = draw_pipe_passthrough_point; + flatshade->stage.line = flatshade_first_line; + flatshade->stage.tri = flatshade_first_tri; + flatshade->stage.flush = flatshade_flush; + flatshade->stage.reset_stipple_counter = flatshade_reset_stipple_counter; + flatshade->stage.destroy = flatshade_destroy; + + if (!draw_alloc_temp_verts( &flatshade->stage, 2 )) + goto fail; + + return &flatshade->stage; + + fail: + if (flatshade) + flatshade->stage.destroy( &flatshade->stage ); + + return NULL; +} + + diff --git a/src/gallium/auxiliary/draw/draw_pipe_offset.c b/src/gallium/auxiliary/draw/draw_pipe_offset.c new file mode 100644 index 0000000..8afbbfa --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_offset.c @@ -0,0 +1,186 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \brief polygon offset state + * + * \author Keith Whitwell + * \author Brian Paul + */ + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "draw_pipe.h" + + + +struct offset_stage { + struct draw_stage stage; + + float scale; + float units; +}; + + + +static INLINE struct offset_stage *offset_stage( struct draw_stage *stage ) +{ + return (struct offset_stage *) stage; +} + + + + + +/** + * Offset tri Z. Some hardware can handle this, but not usually when + * doing unfilled rendering. + */ +static void do_offset_tri( struct draw_stage *stage, + struct prim_header *header ) +{ + const unsigned pos = draw_current_shader_position_output(stage->draw); + struct offset_stage *offset = offset_stage(stage); + float inv_det = 1.0f / header->det; + + /* Window coords: + */ + float *v0 = header->v[0]->data[pos]; + float *v1 = header->v[1]->data[pos]; + float *v2 = header->v[2]->data[pos]; + + /* edge vectors e = v0 - v2, f = v1 - v2 */ + float ex = v0[0] - v2[0]; + float ey = v0[1] - v2[1]; + float ez = v0[2] - v2[2]; + float fx = v1[0] - v2[0]; + float fy = v1[1] - v2[1]; + float fz = v1[2] - v2[2]; + + /* (a,b) = cross(e,f).xy */ + float a = ey*fz - ez*fy; + float b = ez*fx - ex*fz; + + float dzdx = fabsf(a * inv_det); + float dzdy = fabsf(b * inv_det); + + float zoffset = offset->units + MAX2(dzdx, dzdy) * offset->scale; + + /* + * Note: we're applying the offset and clamping per-vertex. + * Ideally, the offset is applied per-fragment prior to fragment shading. + */ + v0[2] = CLAMP(v0[2] + zoffset, 0.0f, 1.0f); + v1[2] = CLAMP(v1[2] + zoffset, 0.0f, 1.0f); + v2[2] = CLAMP(v2[2] + zoffset, 0.0f, 1.0f); + + stage->next->tri( stage->next, header ); +} + + +static void offset_tri( struct draw_stage *stage, + struct prim_header *header ) +{ + struct prim_header tmp; + + tmp.det = header->det; + tmp.flags = header->flags; + tmp.pad = header->pad; + tmp.v[0] = dup_vert(stage, header->v[0], 0); + tmp.v[1] = dup_vert(stage, header->v[1], 1); + tmp.v[2] = dup_vert(stage, header->v[2], 2); + + do_offset_tri( stage, &tmp ); +} + + +static void offset_first_tri( struct draw_stage *stage, + struct prim_header *header ) +{ + struct offset_stage *offset = offset_stage(stage); + + offset->units = (float) (stage->draw->rasterizer->offset_units * stage->draw->mrd); + offset->scale = stage->draw->rasterizer->offset_scale; + + stage->tri = offset_tri; + stage->tri( stage, header ); +} + + + + +static void offset_flush( struct draw_stage *stage, + unsigned flags ) +{ + stage->tri = offset_first_tri; + stage->next->flush( stage->next, flags ); +} + + +static void offset_reset_stipple_counter( struct draw_stage *stage ) +{ + stage->next->reset_stipple_counter( stage->next ); +} + + +static void offset_destroy( struct draw_stage *stage ) +{ + draw_free_temp_verts( stage ); + FREE( stage ); +} + + +/** + * Create polygon offset drawing stage. + */ +struct draw_stage *draw_offset_stage( struct draw_context *draw ) +{ + struct offset_stage *offset = CALLOC_STRUCT(offset_stage); + if (offset == NULL) + goto fail; + + offset->stage.draw = draw; + offset->stage.name = "offset"; + offset->stage.next = NULL; + offset->stage.point = draw_pipe_passthrough_point; + offset->stage.line = draw_pipe_passthrough_line; + offset->stage.tri = offset_first_tri; + offset->stage.flush = offset_flush; + offset->stage.reset_stipple_counter = offset_reset_stipple_counter; + offset->stage.destroy = offset_destroy; + + if (!draw_alloc_temp_verts( &offset->stage, 3 )) + goto fail; + + return &offset->stage; + +fail: + if (offset) + offset->stage.destroy( &offset->stage ); + + return NULL; +} diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c new file mode 100644 index 0000000..f5515c1 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -0,0 +1,814 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * Polygon stipple stage: implement polygon stipple with texture map and + * fragment program. The fragment program samples the texture and does + * a fragment kill for the stipple-failing fragments. + * + * Authors: Brian Paul + */ + + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_inlines.h" + +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_sampler.h" + +#include "tgsi/tgsi_transform.h" +#include "tgsi/tgsi_dump.h" + +#include "draw_context.h" +#include "draw_pipe.h" + + +/** Approx number of new tokens for instructions in pstip_transform_inst() */ +#define NUM_NEW_TOKENS 50 + + +/** + * Subclass of pipe_shader_state to carry extra fragment shader info. + */ +struct pstip_fragment_shader +{ + struct pipe_shader_state state; + void *driver_fs; + void *pstip_fs; + uint sampler_unit; +}; + + +/** + * Subclass of draw_stage + */ +struct pstip_stage +{ + struct draw_stage stage; + + void *sampler_cso; + struct pipe_resource *texture; + struct pipe_sampler_view *sampler_view; + uint num_samplers; + uint num_sampler_views; + + /* + * Currently bound state + */ + struct pstip_fragment_shader *fs; + struct { + void *samplers[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; + const struct pipe_poly_stipple *stipple; + } state; + + /* + * Driver interface/override functions + */ + void * (*driver_create_fs_state)(struct pipe_context *, + const struct pipe_shader_state *); + void (*driver_bind_fs_state)(struct pipe_context *, void *); + void (*driver_delete_fs_state)(struct pipe_context *, void *); + + void (*driver_bind_sampler_states)(struct pipe_context *, unsigned, void **); + + void (*driver_set_sampler_views)(struct pipe_context *, + unsigned, + struct pipe_sampler_view **); + + void (*driver_set_polygon_stipple)(struct pipe_context *, + const struct pipe_poly_stipple *); + + struct pipe_context *pipe; +}; + + + +/** + * Subclass of tgsi_transform_context, used for transforming the + * user's fragment shader to add the special AA instructions. + */ +struct pstip_transform_context { + struct tgsi_transform_context base; + uint tempsUsed; /**< bitmask */ + int wincoordInput; + int maxInput; + uint samplersUsed; /**< bitfield of samplers used */ + int freeSampler; /** an available sampler for the pstipple */ + int texTemp; /**< temp registers */ + int numImmed; + boolean firstInstruction; +}; + + +/** + * TGSI declaration transform callback. + * Look for a free sampler, a free input attrib, and two free temp regs. + */ +static void +pstip_transform_decl(struct tgsi_transform_context *ctx, + struct tgsi_full_declaration *decl) +{ + struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; + + if (decl->Declaration.File == TGSI_FILE_SAMPLER) { + uint i; + for (i = decl->Range.First; + i <= decl->Range.Last; i++) { + pctx->samplersUsed |= 1 << i; + } + } + else if (decl->Declaration.File == TGSI_FILE_INPUT) { + pctx->maxInput = MAX2(pctx->maxInput, (int) decl->Range.Last); + if (decl->Semantic.Name == TGSI_SEMANTIC_POSITION) + pctx->wincoordInput = (int) decl->Range.First; + } + else if (decl->Declaration.File == TGSI_FILE_TEMPORARY) { + uint i; + for (i = decl->Range.First; + i <= decl->Range.Last; i++) { + pctx->tempsUsed |= (1 << i); + } + } + + ctx->emit_declaration(ctx, decl); +} + + +static void +pstip_transform_immed(struct tgsi_transform_context *ctx, + struct tgsi_full_immediate *immed) +{ + struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; + pctx->numImmed++; +} + + +/** + * Find the lowest zero bit in the given word, or -1 if bitfield is all ones. + */ +static int +free_bit(uint bitfield) +{ + return ffs(~bitfield) - 1; +} + + +/** + * TGSI instruction transform callback. + * Replace writes to result.color w/ a temp reg. + * Upon END instruction, insert texture sampling code for antialiasing. + */ +static void +pstip_transform_inst(struct tgsi_transform_context *ctx, + struct tgsi_full_instruction *inst) +{ + struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; + + if (pctx->firstInstruction) { + /* emit our new declarations before the first instruction */ + + struct tgsi_full_declaration decl; + struct tgsi_full_instruction newInst; + uint i; + int wincoordInput; + + /* find free sampler */ + pctx->freeSampler = free_bit(pctx->samplersUsed); + if (pctx->freeSampler >= PIPE_MAX_SAMPLERS) + pctx->freeSampler = PIPE_MAX_SAMPLERS - 1; + + if (pctx->wincoordInput < 0) + wincoordInput = pctx->maxInput + 1; + else + wincoordInput = pctx->wincoordInput; + + /* find one free temp reg */ + for (i = 0; i < 32; i++) { + if ((pctx->tempsUsed & (1 << i)) == 0) { + /* found a free temp */ + if (pctx->texTemp < 0) + pctx->texTemp = i; + else + break; + } + } + assert(pctx->texTemp >= 0); + + if (pctx->wincoordInput < 0) { + /* declare new position input reg */ + decl = tgsi_default_full_declaration(); + decl.Declaration.File = TGSI_FILE_INPUT; + decl.Declaration.Interpolate = TGSI_INTERPOLATE_LINEAR; /* XXX? */ + decl.Declaration.Semantic = 1; + decl.Semantic.Name = TGSI_SEMANTIC_POSITION; + decl.Semantic.Index = 0; + decl.Range.First = + decl.Range.Last = wincoordInput; + ctx->emit_declaration(ctx, &decl); + } + + /* declare new sampler */ + decl = tgsi_default_full_declaration(); + decl.Declaration.File = TGSI_FILE_SAMPLER; + decl.Range.First = + decl.Range.Last = pctx->freeSampler; + ctx->emit_declaration(ctx, &decl); + + /* declare new temp regs */ + decl = tgsi_default_full_declaration(); + decl.Declaration.File = TGSI_FILE_TEMPORARY; + decl.Range.First = + decl.Range.Last = pctx->texTemp; + ctx->emit_declaration(ctx, &decl); + + /* emit immediate = {1/32, 1/32, 1, 1} + * The index/position of this immediate will be pctx->numImmed + */ + { + static const float value[4] = { 1.0/32, 1.0/32, 1.0, 1.0 }; + struct tgsi_full_immediate immed; + uint size = 4; + immed = tgsi_default_full_immediate(); + immed.Immediate.NrTokens = 1 + size; /* one for the token itself */ + immed.u[0].Float = value[0]; + immed.u[1].Float = value[1]; + immed.u[2].Float = value[2]; + immed.u[3].Float = value[3]; + ctx->emit_immediate(ctx, &immed); + } + + pctx->firstInstruction = FALSE; + + + /* + * Insert new MUL/TEX/KILP instructions at start of program + * Take gl_FragCoord, divide by 32 (stipple size), sample the + * texture and kill fragment if needed. + * + * We'd like to use non-normalized texcoords to index into a RECT + * texture, but we can only use GL_REPEAT wrap mode with normalized + * texcoords. Darn. + */ + + /* MUL texTemp, INPUT[wincoord], 1/32; */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_MUL; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Dst[0].Register.Index = pctx->texTemp; + newInst.Instruction.NumSrcRegs = 2; + newInst.Src[0].Register.File = TGSI_FILE_INPUT; + newInst.Src[0].Register.Index = wincoordInput; + newInst.Src[1].Register.File = TGSI_FILE_IMMEDIATE; + newInst.Src[1].Register.Index = pctx->numImmed; + ctx->emit_instruction(ctx, &newInst); + + /* TEX texTemp, texTemp, sampler; */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_TEX; + newInst.Instruction.NumDstRegs = 1; + newInst.Dst[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Dst[0].Register.Index = pctx->texTemp; + newInst.Instruction.NumSrcRegs = 2; + newInst.Instruction.Texture = TRUE; + newInst.Texture.Texture = TGSI_TEXTURE_2D; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = pctx->texTemp; + newInst.Src[1].Register.File = TGSI_FILE_SAMPLER; + newInst.Src[1].Register.Index = pctx->freeSampler; + ctx->emit_instruction(ctx, &newInst); + + /* KIL -texTemp; # if -texTemp < 0, KILL fragment */ + newInst = tgsi_default_full_instruction(); + newInst.Instruction.Opcode = TGSI_OPCODE_KIL; + newInst.Instruction.NumDstRegs = 0; + newInst.Instruction.NumSrcRegs = 1; + newInst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + newInst.Src[0].Register.Index = pctx->texTemp; + newInst.Src[0].Register.Negate = 1; + ctx->emit_instruction(ctx, &newInst); + } + + /* emit this instruction */ + ctx->emit_instruction(ctx, inst); +} + + +/** + * Generate the frag shader we'll use for doing polygon stipple. + * This will be the user's shader prefixed with a TEX and KIL instruction. + */ +static boolean +generate_pstip_fs(struct pstip_stage *pstip) +{ + const struct pipe_shader_state *orig_fs = &pstip->fs->state; + /*struct draw_context *draw = pstip->stage.draw;*/ + struct pipe_shader_state pstip_fs; + struct pstip_transform_context transform; + const uint newLen = tgsi_num_tokens(orig_fs->tokens) + NUM_NEW_TOKENS; + + pstip_fs = *orig_fs; /* copy to init */ + pstip_fs.tokens = tgsi_alloc_tokens(newLen); + if (pstip_fs.tokens == NULL) + return FALSE; + + memset(&transform, 0, sizeof(transform)); + transform.wincoordInput = -1; + transform.maxInput = -1; + transform.texTemp = -1; + transform.firstInstruction = TRUE; + transform.base.transform_instruction = pstip_transform_inst; + transform.base.transform_declaration = pstip_transform_decl; + transform.base.transform_immediate = pstip_transform_immed; + + tgsi_transform_shader(orig_fs->tokens, + (struct tgsi_token *) pstip_fs.tokens, + newLen, &transform.base); + +#if 0 /* DEBUG */ + tgsi_dump(orig_fs->tokens, 0); + tgsi_dump(pstip_fs.tokens, 0); +#endif + + pstip->fs->sampler_unit = transform.freeSampler; + assert(pstip->fs->sampler_unit < PIPE_MAX_SAMPLERS); + + pstip->fs->pstip_fs = pstip->driver_create_fs_state(pstip->pipe, &pstip_fs); + + FREE((void *)pstip_fs.tokens); + + if (!pstip->fs->pstip_fs) + return FALSE; + + return TRUE; +} + + +/** + * Load texture image with current stipple pattern. + */ +static void +pstip_update_texture(struct pstip_stage *pstip) +{ + static const uint bit31 = 1 << 31; + struct pipe_context *pipe = pstip->pipe; + struct pipe_transfer *transfer; + const uint *stipple = pstip->state.stipple->stipple; + uint i, j; + ubyte *data; + + /* XXX: want to avoid flushing just because we use stipple: + * + * Flush should no longer be necessary if driver is properly + * interleaving drawing and transfers on a given context: + */ + pipe->flush( pipe, PIPE_FLUSH_TEXTURE_CACHE, NULL ); + + transfer = pipe_get_transfer(pipe, pstip->texture, 0, 0, + PIPE_TRANSFER_WRITE, 0, 0, 32, 32); + data = pipe->transfer_map(pipe, transfer); + + /* + * Load alpha texture. + * Note: 0 means keep the fragment, 255 means kill it. + * We'll negate the texel value and use KILP which kills if value + * is negative. + */ + for (i = 0; i < 32; i++) { + for (j = 0; j < 32; j++) { + if (stipple[i] & (bit31 >> j)) { + /* fragment "on" */ + data[i * transfer->stride + j] = 0; + } + else { + /* fragment "off" */ + data[i * transfer->stride + j] = 255; + } + } + } + + /* unmap */ + pipe->transfer_unmap(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); +} + + +/** + * Create the texture map we'll use for stippling. + */ +static boolean +pstip_create_texture(struct pstip_stage *pstip) +{ + struct pipe_context *pipe = pstip->pipe; + struct pipe_screen *screen = pipe->screen; + struct pipe_resource texTemp; + struct pipe_sampler_view viewTempl; + + memset(&texTemp, 0, sizeof(texTemp)); + texTemp.target = PIPE_TEXTURE_2D; + texTemp.format = PIPE_FORMAT_A8_UNORM; /* XXX verify supported by driver! */ + texTemp.last_level = 0; + texTemp.width0 = 32; + texTemp.height0 = 32; + texTemp.depth0 = 1; + texTemp.array_size = 1; + texTemp.bind = PIPE_BIND_SAMPLER_VIEW; + + pstip->texture = screen->resource_create(screen, &texTemp); + if (pstip->texture == NULL) + return FALSE; + + u_sampler_view_default_template(&viewTempl, + pstip->texture, + pstip->texture->format); + pstip->sampler_view = pipe->create_sampler_view(pipe, + pstip->texture, + &viewTempl); + if (!pstip->sampler_view) { + return FALSE; + } + + return TRUE; +} + + +/** + * Create the sampler CSO that'll be used for stippling. + */ +static boolean +pstip_create_sampler(struct pstip_stage *pstip) +{ + struct pipe_sampler_state sampler; + struct pipe_context *pipe = pstip->pipe; + + memset(&sampler, 0, sizeof(sampler)); + sampler.wrap_s = PIPE_TEX_WRAP_REPEAT; + sampler.wrap_t = PIPE_TEX_WRAP_REPEAT; + sampler.wrap_r = PIPE_TEX_WRAP_REPEAT; + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler.normalized_coords = 1; + sampler.min_lod = 0.0f; + sampler.max_lod = 0.0f; + + pstip->sampler_cso = pipe->create_sampler_state(pipe, &sampler); + if (pstip->sampler_cso == NULL) + return FALSE; + + return TRUE; +} + + +/** + * When we're about to draw our first stipple polygon in a batch, this function + * is called to tell the driver to bind our modified fragment shader. + */ +static boolean +bind_pstip_fragment_shader(struct pstip_stage *pstip) +{ + struct draw_context *draw = pstip->stage.draw; + if (!pstip->fs->pstip_fs && + !generate_pstip_fs(pstip)) + return FALSE; + + draw->suspend_flushing = TRUE; + pstip->driver_bind_fs_state(pstip->pipe, pstip->fs->pstip_fs); + draw->suspend_flushing = FALSE; + return TRUE; +} + + +static INLINE struct pstip_stage * +pstip_stage( struct draw_stage *stage ) +{ + return (struct pstip_stage *) stage; +} + + +static void +pstip_first_tri(struct draw_stage *stage, struct prim_header *header) +{ + struct pstip_stage *pstip = pstip_stage(stage); + struct pipe_context *pipe = pstip->pipe; + struct draw_context *draw = stage->draw; + uint num_samplers; + + assert(stage->draw->rasterizer->poly_stipple_enable); + + /* bind our fragprog */ + if (!bind_pstip_fragment_shader(pstip)) { + stage->tri = draw_pipe_passthrough_tri; + stage->tri(stage, header); + return; + } + + + /* how many samplers? */ + /* we'll use sampler/texture[pstip->sampler_unit] for the stipple */ + num_samplers = MAX2(pstip->num_sampler_views, pstip->num_samplers); + num_samplers = MAX2(num_samplers, pstip->fs->sampler_unit + 1); + + /* plug in our sampler, texture */ + pstip->state.samplers[pstip->fs->sampler_unit] = pstip->sampler_cso; + pipe_sampler_view_reference(&pstip->state.sampler_views[pstip->fs->sampler_unit], + pstip->sampler_view); + + assert(num_samplers <= PIPE_MAX_SAMPLERS); + + draw->suspend_flushing = TRUE; + pstip->driver_bind_sampler_states(pipe, num_samplers, pstip->state.samplers); + pstip->driver_set_sampler_views(pipe, num_samplers, pstip->state.sampler_views); + draw->suspend_flushing = FALSE; + + /* now really draw first triangle */ + stage->tri = draw_pipe_passthrough_tri; + stage->tri(stage, header); +} + + +static void +pstip_flush(struct draw_stage *stage, unsigned flags) +{ + struct draw_context *draw = stage->draw; + struct pstip_stage *pstip = pstip_stage(stage); + struct pipe_context *pipe = pstip->pipe; + + stage->tri = pstip_first_tri; + stage->next->flush( stage->next, flags ); + + /* restore original frag shader, texture, sampler state */ + draw->suspend_flushing = TRUE; + pstip->driver_bind_fs_state(pipe, pstip->fs->driver_fs); + pstip->driver_bind_sampler_states(pipe, pstip->num_samplers, + pstip->state.samplers); + pstip->driver_set_sampler_views(pipe, + pstip->num_sampler_views, + pstip->state.sampler_views); + draw->suspend_flushing = FALSE; +} + + +static void +pstip_reset_stipple_counter(struct draw_stage *stage) +{ + stage->next->reset_stipple_counter( stage->next ); +} + + +static void +pstip_destroy(struct draw_stage *stage) +{ + struct pstip_stage *pstip = pstip_stage(stage); + uint i; + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + pipe_sampler_view_reference(&pstip->state.sampler_views[i], NULL); + } + + pstip->pipe->delete_sampler_state(pstip->pipe, pstip->sampler_cso); + + pipe_resource_reference(&pstip->texture, NULL); + + if (pstip->sampler_view) { + pipe_sampler_view_reference(&pstip->sampler_view, NULL); + } + + draw_free_temp_verts( stage ); + FREE( stage ); +} + + +/** Create a new polygon stipple drawing stage object */ +static struct pstip_stage * +draw_pstip_stage(struct draw_context *draw, struct pipe_context *pipe) +{ + struct pstip_stage *pstip = CALLOC_STRUCT(pstip_stage); + if (pstip == NULL) + goto fail; + + pstip->pipe = pipe; + + pstip->stage.draw = draw; + pstip->stage.name = "pstip"; + pstip->stage.next = NULL; + pstip->stage.point = draw_pipe_passthrough_point; + pstip->stage.line = draw_pipe_passthrough_line; + pstip->stage.tri = pstip_first_tri; + pstip->stage.flush = pstip_flush; + pstip->stage.reset_stipple_counter = pstip_reset_stipple_counter; + pstip->stage.destroy = pstip_destroy; + + if (!draw_alloc_temp_verts( &pstip->stage, 8 )) + goto fail; + + return pstip; + +fail: + if (pstip) + pstip->stage.destroy( &pstip->stage ); + + return NULL; +} + + +static struct pstip_stage * +pstip_stage_from_pipe(struct pipe_context *pipe) +{ + struct draw_context *draw = (struct draw_context *) pipe->draw; + return pstip_stage(draw->pipeline.pstipple); +} + + +/** + * This function overrides the driver's create_fs_state() function and + * will typically be called by the state tracker. + */ +static void * +pstip_create_fs_state(struct pipe_context *pipe, + const struct pipe_shader_state *fs) +{ + struct pstip_stage *pstip = pstip_stage_from_pipe(pipe); + struct pstip_fragment_shader *aafs = CALLOC_STRUCT(pstip_fragment_shader); + + if (aafs) { + aafs->state = *fs; + + /* pass-through */ + aafs->driver_fs = pstip->driver_create_fs_state(pstip->pipe, fs); + } + + return aafs; +} + + +static void +pstip_bind_fs_state(struct pipe_context *pipe, void *fs) +{ + struct pstip_stage *pstip = pstip_stage_from_pipe(pipe); + struct pstip_fragment_shader *aafs = (struct pstip_fragment_shader *) fs; + /* save current */ + pstip->fs = aafs; + /* pass-through */ + pstip->driver_bind_fs_state(pstip->pipe, + (aafs ? aafs->driver_fs : NULL)); +} + + +static void +pstip_delete_fs_state(struct pipe_context *pipe, void *fs) +{ + struct pstip_stage *pstip = pstip_stage_from_pipe(pipe); + struct pstip_fragment_shader *aafs = (struct pstip_fragment_shader *) fs; + /* pass-through */ + pstip->driver_delete_fs_state(pstip->pipe, aafs->driver_fs); + + if (aafs->pstip_fs) + pstip->driver_delete_fs_state(pstip->pipe, aafs->pstip_fs); + + FREE(aafs); +} + + +static void +pstip_bind_sampler_states(struct pipe_context *pipe, + unsigned num, void **sampler) +{ + struct pstip_stage *pstip = pstip_stage_from_pipe(pipe); + uint i; + + /* save current */ + memcpy(pstip->state.samplers, sampler, num * sizeof(void *)); + for (i = num; i < PIPE_MAX_SAMPLERS; i++) { + pstip->state.samplers[i] = NULL; + } + + pstip->num_samplers = num; + /* pass-through */ + pstip->driver_bind_sampler_states(pstip->pipe, num, sampler); +} + + +static void +pstip_set_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct pstip_stage *pstip = pstip_stage_from_pipe(pipe); + uint i; + + /* save current */ + for (i = 0; i < num; i++) { + pipe_sampler_view_reference(&pstip->state.sampler_views[i], views[i]); + } + for (; i < PIPE_MAX_SAMPLERS; i++) { + pipe_sampler_view_reference(&pstip->state.sampler_views[i], NULL); + } + + pstip->num_sampler_views = num; + + /* pass-through */ + pstip->driver_set_sampler_views(pstip->pipe, num, views); +} + + +static void +pstip_set_polygon_stipple(struct pipe_context *pipe, + const struct pipe_poly_stipple *stipple) +{ + struct pstip_stage *pstip = pstip_stage_from_pipe(pipe); + + /* save current */ + pstip->state.stipple = stipple; + + /* pass-through */ + pstip->driver_set_polygon_stipple(pstip->pipe, stipple); + + pstip_update_texture(pstip); +} + + +/** + * Called by drivers that want to install this polygon stipple stage + * into the draw module's pipeline. This will not be used if the + * hardware has native support for polygon stipple. + */ +boolean +draw_install_pstipple_stage(struct draw_context *draw, + struct pipe_context *pipe) +{ + struct pstip_stage *pstip; + + pipe->draw = (void *) draw; + + /* + * Create / install pgon stipple drawing / prim stage + */ + pstip = draw_pstip_stage( draw, pipe ); + if (pstip == NULL) + goto fail; + + draw->pipeline.pstipple = &pstip->stage; + + /* create special texture, sampler state */ + if (!pstip_create_texture(pstip)) + goto fail; + + if (!pstip_create_sampler(pstip)) + goto fail; + + /* save original driver functions */ + pstip->driver_create_fs_state = pipe->create_fs_state; + pstip->driver_bind_fs_state = pipe->bind_fs_state; + pstip->driver_delete_fs_state = pipe->delete_fs_state; + + pstip->driver_bind_sampler_states = pipe->bind_fragment_sampler_states; + pstip->driver_set_sampler_views = pipe->set_fragment_sampler_views; + pstip->driver_set_polygon_stipple = pipe->set_polygon_stipple; + + /* override the driver's functions */ + pipe->create_fs_state = pstip_create_fs_state; + pipe->bind_fs_state = pstip_bind_fs_state; + pipe->delete_fs_state = pstip_delete_fs_state; + + pipe->bind_fragment_sampler_states = pstip_bind_sampler_states; + pipe->set_fragment_sampler_views = pstip_set_sampler_views; + pipe->set_polygon_stipple = pstip_set_polygon_stipple; + + return TRUE; + + fail: + if (pstip) + pstip->stage.destroy( &pstip->stage ); + + return FALSE; +} diff --git a/src/gallium/auxiliary/draw/draw_pipe_stipple.c b/src/gallium/auxiliary/draw/draw_pipe_stipple.c new file mode 100644 index 0000000..4b3f4e7 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_stipple.c @@ -0,0 +1,261 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +/* Implement line stipple by cutting lines up into smaller lines. + * There are hundreds of ways to implement line stipple, this is one + * choice that should work in all situations, requires no state + * manipulations, but with a penalty in terms of large amounts of + * generated geometry. + */ + + +#include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "draw/draw_pipe.h" + + +/** Subclass of draw_stage */ +struct stipple_stage { + struct draw_stage stage; + float counter; + uint pattern; + uint factor; +}; + + +static INLINE struct stipple_stage * +stipple_stage(struct draw_stage *stage) +{ + return (struct stipple_stage *) stage; +} + + +/** + * Compute interpolated vertex attributes for 'dst' at position 't' + * between 'v0' and 'v1'. + * XXX using linear interpolation for all attribs at this time. + */ +static void +screen_interp( struct draw_context *draw, + struct vertex_header *dst, + float t, + const struct vertex_header *v0, + const struct vertex_header *v1 ) +{ + uint attr; + int num_outputs = draw_current_shader_outputs(draw); + for (attr = 0; attr < num_outputs; attr++) { + const float *val0 = v0->data[attr]; + const float *val1 = v1->data[attr]; + float *newv = dst->data[attr]; + uint i; + for (i = 0; i < 4; i++) { + newv[i] = val0[i] + t * (val1[i] - val0[i]); + } + } +} + + +static void +emit_segment(struct draw_stage *stage, struct prim_header *header, + float t0, float t1) +{ + struct vertex_header *v0new = dup_vert(stage, header->v[0], 0); + struct vertex_header *v1new = dup_vert(stage, header->v[1], 1); + struct prim_header newprim = *header; + + if (t0 > 0.0) { + screen_interp( stage->draw, v0new, t0, header->v[0], header->v[1] ); + newprim.v[0] = v0new; + } + + if (t1 < 1.0) { + screen_interp( stage->draw, v1new, t1, header->v[0], header->v[1] ); + newprim.v[1] = v1new; + } + + stage->next->line( stage->next, &newprim ); +} + + +static INLINE unsigned +stipple_test(int counter, ushort pattern, int factor) +{ + int b = (counter / factor) & 0xf; + return (1 << b) & pattern; +} + + +static void +stipple_line(struct draw_stage *stage, struct prim_header *header) +{ + struct stipple_stage *stipple = stipple_stage(stage); + struct vertex_header *v0 = header->v[0]; + struct vertex_header *v1 = header->v[1]; + const unsigned pos = draw_current_shader_position_output(stage->draw); + const float *pos0 = v0->data[pos]; + const float *pos1 = v1->data[pos]; + float start = 0; + int state = 0; + + float x0 = pos0[0]; + float x1 = pos1[0]; + float y0 = pos0[1]; + float y1 = pos1[1]; + + float dx = x0 > x1 ? x0 - x1 : x1 - x0; + float dy = y0 > y1 ? y0 - y1 : y1 - y0; + + float length = MAX2(dx, dy); + int i; + + if (header->flags & DRAW_PIPE_RESET_STIPPLE) + stipple->counter = 0; + + + /* XXX ToDo: intead of iterating pixel-by-pixel, use a look-up table. + */ + for (i = 0; i < length; i++) { + int result = stipple_test( (int) stipple->counter+i, + (ushort) stipple->pattern, stipple->factor ); + if (result != state) { + /* changing from "off" to "on" or vice versa */ + if (state) { + if (start != i) { + /* finishing an "on" segment */ + emit_segment( stage, header, start / length, i / length ); + } + } + else { + /* starting an "on" segment */ + start = (float) i; + } + state = result; + } + } + + if (state && start < length) + emit_segment( stage, header, start / length, 1.0 ); + + stipple->counter += length; +} + + +static void +reset_stipple_counter(struct draw_stage *stage) +{ + struct stipple_stage *stipple = stipple_stage(stage); + stipple->counter = 0; + stage->next->reset_stipple_counter( stage->next ); +} + +static void +stipple_reset_point(struct draw_stage *stage, struct prim_header *header) +{ + struct stipple_stage *stipple = stipple_stage(stage); + stipple->counter = 0; + stage->next->point(stage->next, header); +} + +static void +stipple_reset_tri(struct draw_stage *stage, struct prim_header *header) +{ + struct stipple_stage *stipple = stipple_stage(stage); + stipple->counter = 0; + stage->next->tri(stage->next, header); +} + + +static void +stipple_first_line(struct draw_stage *stage, + struct prim_header *header) +{ + struct stipple_stage *stipple = stipple_stage(stage); + struct draw_context *draw = stage->draw; + + stipple->pattern = draw->rasterizer->line_stipple_pattern; + stipple->factor = draw->rasterizer->line_stipple_factor + 1; + + stage->line = stipple_line; + stage->line( stage, header ); +} + + +static void +stipple_flush(struct draw_stage *stage, unsigned flags) +{ + stage->line = stipple_first_line; + stage->next->flush( stage->next, flags ); +} + + + + +static void +stipple_destroy( struct draw_stage *stage ) +{ + draw_free_temp_verts( stage ); + FREE( stage ); +} + + +/** + * Create line stippler stage + */ +struct draw_stage *draw_stipple_stage( struct draw_context *draw ) +{ + struct stipple_stage *stipple = CALLOC_STRUCT(stipple_stage); + if (stipple == NULL) + goto fail; + + stipple->stage.draw = draw; + stipple->stage.name = "stipple"; + stipple->stage.next = NULL; + stipple->stage.point = stipple_reset_point; + stipple->stage.line = stipple_first_line; + stipple->stage.tri = stipple_reset_tri; + stipple->stage.reset_stipple_counter = reset_stipple_counter; + stipple->stage.flush = stipple_flush; + stipple->stage.destroy = stipple_destroy; + + if (!draw_alloc_temp_verts( &stipple->stage, 2 )) + goto fail; + + return &stipple->stage; + +fail: + if (stipple) + stipple->stage.destroy( &stipple->stage ); + + return NULL; +} diff --git a/src/gallium/auxiliary/draw/draw_pipe_twoside.c b/src/gallium/auxiliary/draw/draw_pipe_twoside.c new file mode 100644 index 0000000..9a3f3fe --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_twoside.c @@ -0,0 +1,200 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" +#include "draw_vs.h" +#include "draw_pipe.h" + +struct twoside_stage { + struct draw_stage stage; + float sign; /**< +1 or -1 */ + uint attrib_front0, attrib_back0; + uint attrib_front1, attrib_back1; +}; + + +static INLINE struct twoside_stage *twoside_stage( struct draw_stage *stage ) +{ + return (struct twoside_stage *)stage; +} + + + + +/** + * Copy back color(s) to front color(s). + */ +static INLINE struct vertex_header * +copy_bfc( struct twoside_stage *twoside, + const struct vertex_header *v, + unsigned idx ) +{ + struct vertex_header *tmp = dup_vert( &twoside->stage, v, idx ); + + if (twoside->attrib_back0) { + COPY_4FV(tmp->data[twoside->attrib_front0], + tmp->data[twoside->attrib_back0]); + } + if (twoside->attrib_back1) { + COPY_4FV(tmp->data[twoside->attrib_front1], + tmp->data[twoside->attrib_back1]); + } + + return tmp; +} + + +/* Twoside tri: + */ +static void twoside_tri( struct draw_stage *stage, + struct prim_header *header ) +{ + struct twoside_stage *twoside = twoside_stage(stage); + + if (header->det * twoside->sign < 0.0) { + /* this is a back-facing triangle */ + struct prim_header tmp; + + tmp.det = header->det; + tmp.flags = header->flags; + tmp.pad = header->pad; + /* copy back attribs to front attribs */ + tmp.v[0] = copy_bfc(twoside, header->v[0], 0); + tmp.v[1] = copy_bfc(twoside, header->v[1], 1); + tmp.v[2] = copy_bfc(twoside, header->v[2], 2); + + stage->next->tri( stage->next, &tmp ); + } + else { + stage->next->tri( stage->next, header ); + } +} + + + +static void twoside_first_tri( struct draw_stage *stage, + struct prim_header *header ) +{ + struct twoside_stage *twoside = twoside_stage(stage); + const struct draw_vertex_shader *vs = stage->draw->vs.vertex_shader; + uint i; + + twoside->attrib_front0 = 0; + twoside->attrib_front1 = 0; + twoside->attrib_back0 = 0; + twoside->attrib_back1 = 0; + + /* Find which vertex shader outputs are front/back colors */ + for (i = 0; i < vs->info.num_outputs; i++) { + if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_COLOR) { + if (vs->info.output_semantic_index[i] == 0) + twoside->attrib_front0 = i; + else + twoside->attrib_front1 = i; + } + if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_BCOLOR) { + if (vs->info.output_semantic_index[i] == 0) + twoside->attrib_back0 = i; + else + twoside->attrib_back1 = i; + } + } + + if (!twoside->attrib_back0) + twoside->attrib_front0 = 0; + + if (!twoside->attrib_back1) + twoside->attrib_front1 = 0; + + /* + * We'll multiply the primitive's determinant by this sign to determine + * if the triangle is back-facing (negative). + * sign = -1 for CCW, +1 for CW + */ + twoside->sign = stage->draw->rasterizer->front_ccw ? -1.0f : 1.0f; + + stage->tri = twoside_tri; + stage->tri( stage, header ); +} + + +static void twoside_flush( struct draw_stage *stage, unsigned flags ) +{ + stage->tri = twoside_first_tri; + stage->next->flush( stage->next, flags ); +} + + +static void twoside_reset_stipple_counter( struct draw_stage *stage ) +{ + stage->next->reset_stipple_counter( stage->next ); +} + + +static void twoside_destroy( struct draw_stage *stage ) +{ + draw_free_temp_verts( stage ); + FREE( stage ); +} + + +/** + * Create twoside pipeline stage. + */ +struct draw_stage *draw_twoside_stage( struct draw_context *draw ) +{ + struct twoside_stage *twoside = CALLOC_STRUCT(twoside_stage); + if (twoside == NULL) + goto fail; + + twoside->stage.draw = draw; + twoside->stage.name = "twoside"; + twoside->stage.next = NULL; + twoside->stage.point = draw_pipe_passthrough_point; + twoside->stage.line = draw_pipe_passthrough_line; + twoside->stage.tri = twoside_first_tri; + twoside->stage.flush = twoside_flush; + twoside->stage.reset_stipple_counter = twoside_reset_stipple_counter; + twoside->stage.destroy = twoside_destroy; + + if (!draw_alloc_temp_verts( &twoside->stage, 3 )) + goto fail; + + return &twoside->stage; + + fail: + if (twoside) + twoside->stage.destroy( &twoside->stage ); + + return NULL; +} diff --git a/src/gallium/auxiliary/draw/draw_pipe_unfilled.c b/src/gallium/auxiliary/draw/draw_pipe_unfilled.c new file mode 100644 index 0000000..d87741b --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_unfilled.c @@ -0,0 +1,226 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \brief Drawing stage for handling glPolygonMode(line/point). + * Convert triangles to points or lines as needed. + */ + +/* Authors: Keith Whitwell + */ + +#include "util/u_memory.h" +#include "pipe/p_defines.h" +#include "draw_private.h" +#include "draw_pipe.h" + + +struct unfilled_stage { + struct draw_stage stage; + + /** [0] = front face, [1] = back face. + * legal values: PIPE_POLYGON_MODE_FILL, PIPE_POLYGON_MODE_LINE, + * and PIPE_POLYGON_MODE_POINT, + */ + unsigned mode[2]; +}; + + +static INLINE struct unfilled_stage *unfilled_stage( struct draw_stage *stage ) +{ + return (struct unfilled_stage *)stage; +} + + + +static void point( struct draw_stage *stage, + struct vertex_header *v0 ) +{ + struct prim_header tmp; + tmp.v[0] = v0; + stage->next->point( stage->next, &tmp ); +} + +static void line( struct draw_stage *stage, + struct vertex_header *v0, + struct vertex_header *v1 ) +{ + struct prim_header tmp; + tmp.v[0] = v0; + tmp.v[1] = v1; + stage->next->line( stage->next, &tmp ); +} + + +static void points( struct draw_stage *stage, + struct prim_header *header ) +{ + struct vertex_header *v0 = header->v[0]; + struct vertex_header *v1 = header->v[1]; + struct vertex_header *v2 = header->v[2]; + + if ((header->flags & DRAW_PIPE_EDGE_FLAG_0) && v0->edgeflag) point( stage, v0 ); + if ((header->flags & DRAW_PIPE_EDGE_FLAG_1) && v1->edgeflag) point( stage, v1 ); + if ((header->flags & DRAW_PIPE_EDGE_FLAG_2) && v2->edgeflag) point( stage, v2 ); +} + + +static void lines( struct draw_stage *stage, + struct prim_header *header ) +{ + struct vertex_header *v0 = header->v[0]; + struct vertex_header *v1 = header->v[1]; + struct vertex_header *v2 = header->v[2]; + + if (header->flags & DRAW_PIPE_RESET_STIPPLE) + stage->next->reset_stipple_counter( stage->next ); + + if ((header->flags & DRAW_PIPE_EDGE_FLAG_2) && v2->edgeflag) line( stage, v2, v0 ); + if ((header->flags & DRAW_PIPE_EDGE_FLAG_0) && v0->edgeflag) line( stage, v0, v1 ); + if ((header->flags & DRAW_PIPE_EDGE_FLAG_1) && v1->edgeflag) line( stage, v1, v2 ); +} + + +/** For debugging */ +static void +print_header_flags(unsigned flags) +{ + debug_printf("header->flags = "); + if (flags & DRAW_PIPE_RESET_STIPPLE) + debug_printf("RESET_STIPPLE "); + if (flags & DRAW_PIPE_EDGE_FLAG_0) + debug_printf("EDGE_FLAG_0 "); + if (flags & DRAW_PIPE_EDGE_FLAG_1) + debug_printf("EDGE_FLAG_1 "); + if (flags & DRAW_PIPE_EDGE_FLAG_2) + debug_printf("EDGE_FLAG_2 "); + debug_printf("\n"); +} + + +/* Unfilled tri: + * + * Note edgeflags in the vertex struct is not sufficient as we will + * need to manipulate them when decomposing primitives. + * + * We currently keep the vertex edgeflag and primitive edgeflag mask + * separate until the last possible moment. + */ +static void unfilled_tri( struct draw_stage *stage, + struct prim_header *header ) +{ + struct unfilled_stage *unfilled = unfilled_stage(stage); + unsigned cw = header->det >= 0.0; + unsigned mode = unfilled->mode[cw]; + + if (0) + print_header_flags(header->flags); + + switch (mode) { + case PIPE_POLYGON_MODE_FILL: + stage->next->tri( stage->next, header ); + break; + case PIPE_POLYGON_MODE_LINE: + lines( stage, header ); + break; + case PIPE_POLYGON_MODE_POINT: + points( stage, header ); + break; + default: + assert(0); + } +} + + +static void unfilled_first_tri( struct draw_stage *stage, + struct prim_header *header ) +{ + struct unfilled_stage *unfilled = unfilled_stage(stage); + const struct pipe_rasterizer_state *rast = stage->draw->rasterizer; + + unfilled->mode[0] = rast->front_ccw ? rast->fill_front : rast->fill_back; + unfilled->mode[1] = rast->front_ccw ? rast->fill_back : rast->fill_front; + + stage->tri = unfilled_tri; + stage->tri( stage, header ); +} + + + +static void unfilled_flush( struct draw_stage *stage, + unsigned flags ) +{ + stage->next->flush( stage->next, flags ); + + stage->tri = unfilled_first_tri; +} + + +static void unfilled_reset_stipple_counter( struct draw_stage *stage ) +{ + stage->next->reset_stipple_counter( stage->next ); +} + + +static void unfilled_destroy( struct draw_stage *stage ) +{ + draw_free_temp_verts( stage ); + FREE( stage ); +} + + +/** + * Create unfilled triangle stage. + */ +struct draw_stage *draw_unfilled_stage( struct draw_context *draw ) +{ + struct unfilled_stage *unfilled = CALLOC_STRUCT(unfilled_stage); + if (unfilled == NULL) + goto fail; + + unfilled->stage.draw = draw; + unfilled->stage.name = "unfilled"; + unfilled->stage.next = NULL; + unfilled->stage.tmp = NULL; + unfilled->stage.point = draw_pipe_passthrough_point; + unfilled->stage.line = draw_pipe_passthrough_line; + unfilled->stage.tri = unfilled_first_tri; + unfilled->stage.flush = unfilled_flush; + unfilled->stage.reset_stipple_counter = unfilled_reset_stipple_counter; + unfilled->stage.destroy = unfilled_destroy; + + if (!draw_alloc_temp_verts( &unfilled->stage, 0 )) + goto fail; + + return &unfilled->stage; + + fail: + if (unfilled) + unfilled->stage.destroy( &unfilled->stage ); + + return NULL; +} diff --git a/src/gallium/auxiliary/draw/draw_pipe_util.c b/src/gallium/auxiliary/draw/draw_pipe_util.c new file mode 100644 index 0000000..e22e5fe --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_util.c @@ -0,0 +1,137 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_memory.h" +#include "draw/draw_private.h" +#include "draw/draw_pipe.h" + + + +void +draw_pipe_passthrough_point(struct draw_stage *stage, struct prim_header *header) +{ + stage->next->point(stage->next, header); +} + +void +draw_pipe_passthrough_line(struct draw_stage *stage, struct prim_header *header) +{ + stage->next->line(stage->next, header); +} + +void +draw_pipe_passthrough_tri(struct draw_stage *stage, struct prim_header *header) +{ + stage->next->tri(stage->next, header); +} + + + + + +/* This is only used for temporary verts. + */ +#define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float)) + + +/** + * Allocate space for temporary post-transform vertices, such as for clipping. + */ +boolean draw_alloc_temp_verts( struct draw_stage *stage, unsigned nr ) +{ + assert(!stage->tmp); + + stage->tmp = NULL; + stage->nr_tmps = nr; + + if (nr != 0) + { + unsigned i; + ubyte *store = (ubyte *) MALLOC( MAX_VERTEX_SIZE * nr ); + + if (store == NULL) + return FALSE; + + stage->tmp = (struct vertex_header **) MALLOC( sizeof(struct vertex_header *) * nr ); + if (stage->tmp == NULL) { + FREE(store); + return FALSE; + } + + for (i = 0; i < nr; i++) + stage->tmp[i] = (struct vertex_header *)(store + i * MAX_VERTEX_SIZE); + } + + return TRUE; +} + + +void draw_free_temp_verts( struct draw_stage *stage ) +{ + if (stage->tmp) { + FREE( stage->tmp[0] ); + FREE( stage->tmp ); + stage->tmp = NULL; + } +} + + +/* Reset vertex ids. This is basically a type of flush. + * + * Called only from draw_pipe_vbuf.c + */ +void draw_reset_vertex_ids(struct draw_context *draw) +{ + struct draw_stage *stage = draw->pipeline.first; + + while (stage) { + unsigned i; + + for (i = 0; i < stage->nr_tmps; i++) + stage->tmp[i]->vertex_id = UNDEFINED_VERTEX_ID; + + stage = stage->next; + } + + if (draw->pipeline.verts) + { + unsigned i; + char *verts = draw->pipeline.verts; + unsigned stride = draw->pipeline.vertex_stride; + + for (i = 0; i < draw->pipeline.vertex_count; i++) { + ((struct vertex_header *)verts)->vertex_id = UNDEFINED_VERTEX_ID; + verts += stride; + } + } +} + diff --git a/src/gallium/auxiliary/draw/draw_pipe_validate.c b/src/gallium/auxiliary/draw/draw_pipe_validate.c new file mode 100644 index 0000000..c575a8a --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_validate.c @@ -0,0 +1,350 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#include "util/u_memory.h" +#include "pipe/p_defines.h" +#include "draw_private.h" +#include "draw_pipe.h" +#include "draw_context.h" +#include "draw_vbuf.h" + +static boolean points( unsigned prim ) +{ + return (prim == PIPE_PRIM_POINTS); +} + +static boolean lines( unsigned prim ) +{ + return (prim == PIPE_PRIM_LINES || + prim == PIPE_PRIM_LINE_STRIP || + prim == PIPE_PRIM_LINE_LOOP); +} + +static boolean triangles( unsigned prim ) +{ + return prim >= PIPE_PRIM_TRIANGLES; +} + +/** + * Default version of a function to check if we need any special + * pipeline stages, or whether prims/verts can go through untouched. + * Don't test for bypass clipping or vs modes, this function is just + * about the primitive pipeline stages. + * + * This can be overridden by the driver. + */ +boolean +draw_need_pipeline(const struct draw_context *draw, + const struct pipe_rasterizer_state *rasterizer, + unsigned int prim ) +{ + /* If the driver has overridden this, use that version: + */ + if (draw->render && + draw->render->need_pipeline) + { + return draw->render->need_pipeline( draw->render, + rasterizer, + prim ); + } + + /* Don't have to worry about triangles turning into lines/points + * and triggering the pipeline, because we have to trigger the + * pipeline *anyway* if unfilled mode is active. + */ + if (lines(prim)) + { + /* line stipple */ + if (rasterizer->line_stipple_enable && draw->pipeline.line_stipple) + return TRUE; + + /* wide lines */ + if (rasterizer->line_width > draw->pipeline.wide_line_threshold) + return TRUE; + + /* AA lines */ + if (rasterizer->line_smooth && draw->pipeline.aaline) + return TRUE; + } + + if (points(prim)) + { + /* large points */ + if (rasterizer->point_size > draw->pipeline.wide_point_threshold) + return TRUE; + + /* sprite points */ + if (rasterizer->point_quad_rasterization + && draw->pipeline.wide_point_sprites) + return TRUE; + + /* AA points */ + if (rasterizer->point_smooth && draw->pipeline.aapoint) + return TRUE; + + /* point sprites */ + if (rasterizer->sprite_coord_enable && draw->pipeline.point_sprite) + return TRUE; + } + + + if (triangles(prim)) + { + /* polygon stipple */ + if (rasterizer->poly_stipple_enable && draw->pipeline.pstipple) + return TRUE; + + /* unfilled polygons */ + if (rasterizer->fill_front != PIPE_POLYGON_MODE_FILL || + rasterizer->fill_back != PIPE_POLYGON_MODE_FILL) + return TRUE; + + /* polygon offset */ + if (rasterizer->offset_point || + rasterizer->offset_line || + rasterizer->offset_tri) + return TRUE; + + /* two-side lighting */ + if (rasterizer->light_twoside) + return TRUE; + } + + /* polygon cull - this is difficult - hardware can cull just fine + * most of the time (though sometimes CULL_NEITHER is unsupported. + * + * Generally this isn't a reason to require the pipeline, though. + * + if (rasterizer->cull_mode) + return TRUE; + */ + + return FALSE; +} + + + +/** + * Rebuild the rendering pipeline. + */ +static struct draw_stage *validate_pipeline( struct draw_stage *stage ) +{ + struct draw_context *draw = stage->draw; + struct draw_stage *next = draw->pipeline.rasterize; + boolean need_det = FALSE; + boolean precalc_flat = FALSE; + boolean wide_lines, wide_points; + const struct pipe_rasterizer_state *rast = draw->rasterizer; + + /* Set the validate's next stage to the rasterize stage, so that it + * can be found later if needed for flushing. + */ + stage->next = next; + + /* drawing wide lines? */ + wide_lines = (rast->line_width > draw->pipeline.wide_line_threshold + && !rast->line_smooth); + + /* drawing large/sprite points (but not AA points)? */ + if (rast->sprite_coord_enable && draw->pipeline.point_sprite) + wide_points = TRUE; + else if (rast->point_smooth && draw->pipeline.aapoint) + wide_points = FALSE; + else if (rast->point_size > draw->pipeline.wide_point_threshold) + wide_points = TRUE; + else if (rast->point_quad_rasterization && draw->pipeline.wide_point_sprites) + wide_points = TRUE; + else + wide_points = FALSE; + + /* + * NOTE: we build up the pipeline in end-to-start order. + * + * TODO: make the current primitive part of the state and build + * shorter pipelines for lines & points. + */ + + if (rast->line_smooth && draw->pipeline.aaline) { + draw->pipeline.aaline->next = next; + next = draw->pipeline.aaline; + } + + if (rast->point_smooth && draw->pipeline.aapoint) { + draw->pipeline.aapoint->next = next; + next = draw->pipeline.aapoint; + } + + if (wide_lines) { + draw->pipeline.wide_line->next = next; + next = draw->pipeline.wide_line; + precalc_flat = TRUE; + } + + if (wide_points) { + draw->pipeline.wide_point->next = next; + next = draw->pipeline.wide_point; + } + + if (rast->line_stipple_enable && draw->pipeline.line_stipple) { + draw->pipeline.stipple->next = next; + next = draw->pipeline.stipple; + precalc_flat = TRUE; /* only needed for lines really */ + } + + if (rast->poly_stipple_enable + && draw->pipeline.pstipple) { + draw->pipeline.pstipple->next = next; + next = draw->pipeline.pstipple; + } + + if (rast->fill_front != PIPE_POLYGON_MODE_FILL || + rast->fill_back != PIPE_POLYGON_MODE_FILL) { + draw->pipeline.unfilled->next = next; + next = draw->pipeline.unfilled; + precalc_flat = TRUE; /* only needed for triangles really */ + need_det = TRUE; + } + + if (rast->flatshade && precalc_flat) { + draw->pipeline.flatshade->next = next; + next = draw->pipeline.flatshade; + } + + if (rast->offset_point || + rast->offset_line || + rast->offset_tri) { + draw->pipeline.offset->next = next; + next = draw->pipeline.offset; + need_det = TRUE; + } + + if (rast->light_twoside) { + draw->pipeline.twoside->next = next; + next = draw->pipeline.twoside; + need_det = TRUE; + } + + /* Always run the cull stage as we calculate determinant there + * also. + * + * This can actually be a win as culling out the triangles can lead + * to less work emitting vertices, smaller vertex buffers, etc. + * It's difficult to say whether this will be true in general. + */ + if (need_det || rast->cull_face != PIPE_FACE_NONE) { + draw->pipeline.cull->next = next; + next = draw->pipeline.cull; + } + + /* Clip stage + */ + if (draw->clip_xy || draw->clip_z || draw->clip_user) + { + draw->pipeline.clip->next = next; + next = draw->pipeline.clip; + } + + + draw->pipeline.first = next; + + if (0) { + debug_printf("draw pipeline:\n"); + for (next = draw->pipeline.first; next ; next = next->next ) + debug_printf(" %s\n", next->name); + debug_printf("\n"); + } + + return draw->pipeline.first; +} + +static void validate_tri( struct draw_stage *stage, + struct prim_header *header ) +{ + struct draw_stage *pipeline = validate_pipeline( stage ); + pipeline->tri( pipeline, header ); +} + +static void validate_line( struct draw_stage *stage, + struct prim_header *header ) +{ + struct draw_stage *pipeline = validate_pipeline( stage ); + pipeline->line( pipeline, header ); +} + +static void validate_point( struct draw_stage *stage, + struct prim_header *header ) +{ + struct draw_stage *pipeline = validate_pipeline( stage ); + pipeline->point( pipeline, header ); +} + +static void validate_reset_stipple_counter( struct draw_stage *stage ) +{ + struct draw_stage *pipeline = validate_pipeline( stage ); + pipeline->reset_stipple_counter( pipeline ); +} + +static void validate_flush( struct draw_stage *stage, + unsigned flags ) +{ + /* May need to pass a backend flush on to the rasterize stage. + */ + if (stage->next) + stage->next->flush( stage->next, flags ); +} + + +static void validate_destroy( struct draw_stage *stage ) +{ + FREE( stage ); +} + + +/** + * Create validate pipeline stage. + */ +struct draw_stage *draw_validate_stage( struct draw_context *draw ) +{ + struct draw_stage *stage = CALLOC_STRUCT(draw_stage); + if (stage == NULL) + return NULL; + + stage->draw = draw; + stage->name = "validate"; + stage->next = NULL; + stage->point = validate_point; + stage->line = validate_line; + stage->tri = validate_tri; + stage->flush = validate_flush; + stage->reset_stipple_counter = validate_reset_stipple_counter; + stage->destroy = validate_destroy; + + return stage; +} diff --git a/src/gallium/auxiliary/draw/draw_pipe_vbuf.c b/src/gallium/auxiliary/draw/draw_pipe_vbuf.c new file mode 100644 index 0000000..58c5858 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_vbuf.c @@ -0,0 +1,457 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \file + * Vertex buffer drawing stage. + * + * \author Jose Fonseca + * \author Keith Whitwell + */ + + +#include "util/u_debug.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "draw_vbuf.h" +#include "draw_private.h" +#include "draw_vertex.h" +#include "draw_pipe.h" +#include "translate/translate.h" +#include "translate/translate_cache.h" + + +/** + * Vertex buffer emit stage. + */ +struct vbuf_stage { + struct draw_stage stage; /**< This must be first (base class) */ + + struct vbuf_render *render; + + const struct vertex_info *vinfo; + + /** Vertex size in bytes */ + unsigned vertex_size; + + struct translate *translate; + + /* FIXME: we have no guarantee that 'unsigned' is 32bit */ + + /** Vertices in hardware format */ + unsigned *vertices; + unsigned *vertex_ptr; + unsigned max_vertices; + unsigned nr_vertices; + + /** Indices */ + ushort *indices; + unsigned max_indices; + unsigned nr_indices; + + /* Cache point size somewhere it's address won't change: + */ + float point_size; + + struct translate_cache *cache; +}; + + +/** + * Basically a cast wrapper. + */ +static INLINE struct vbuf_stage * +vbuf_stage( struct draw_stage *stage ) +{ + assert(stage); + return (struct vbuf_stage *)stage; +} + + +static void vbuf_flush_vertices( struct vbuf_stage *vbuf ); +static void vbuf_alloc_vertices( struct vbuf_stage *vbuf ); + + +static INLINE boolean +overflow( void *map, void *ptr, unsigned bytes, unsigned bufsz ) +{ + unsigned long used = (unsigned long) ((char *)ptr - (char *)map); + return (used + bytes) > bufsz; +} + + +static INLINE void +check_space( struct vbuf_stage *vbuf, unsigned nr ) +{ + if (vbuf->nr_vertices + nr > vbuf->max_vertices || + vbuf->nr_indices + nr > vbuf->max_indices) + { + vbuf_flush_vertices( vbuf ); + vbuf_alloc_vertices( vbuf ); + } +} + + + + +/** + * Extract the needed fields from post-transformed vertex and emit + * a hardware(driver) vertex. + * Recall that the vertices are constructed by the 'draw' module and + * have a couple of slots at the beginning (1-dword header, 4-dword + * clip pos) that we ignore here. We only use the vertex->data[] fields. + */ +static INLINE ushort +emit_vertex( struct vbuf_stage *vbuf, + struct vertex_header *vertex ) +{ + if(vertex->vertex_id == UNDEFINED_VERTEX_ID) { + /* Hmm - vertices are emitted one at a time - better make sure + * set_buffer is efficient. Consider a special one-shot mode for + * translate. + */ + /* Note: we really do want data[0] here, not data[pos]: + */ + vbuf->translate->set_buffer(vbuf->translate, 0, vertex->data[0], 0, ~0); + vbuf->translate->run(vbuf->translate, 0, 1, 0, vbuf->vertex_ptr); + + if (0) draw_dump_emitted_vertex(vbuf->vinfo, (uint8_t *)vbuf->vertex_ptr); + + vbuf->vertex_ptr += vbuf->vertex_size/4; + vertex->vertex_id = vbuf->nr_vertices++; + } + + return (ushort)vertex->vertex_id; +} + + +static void +vbuf_tri( struct draw_stage *stage, + struct prim_header *prim ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + unsigned i; + + check_space( vbuf, 3 ); + + for (i = 0; i < 3; i++) { + vbuf->indices[vbuf->nr_indices++] = emit_vertex( vbuf, prim->v[i] ); + } +} + + +static void +vbuf_line( struct draw_stage *stage, + struct prim_header *prim ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + unsigned i; + + check_space( vbuf, 2 ); + + for (i = 0; i < 2; i++) { + vbuf->indices[vbuf->nr_indices++] = emit_vertex( vbuf, prim->v[i] ); + } +} + + +static void +vbuf_point( struct draw_stage *stage, + struct prim_header *prim ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + check_space( vbuf, 1 ); + + vbuf->indices[vbuf->nr_indices++] = emit_vertex( vbuf, prim->v[0] ); +} + + + + +/** + * Set the prim type for subsequent vertices. + * This may result in a new vertex size. The existing vbuffer (if any) + * will be flushed if needed and a new one allocated. + */ +static void +vbuf_start_prim( struct vbuf_stage *vbuf, uint prim ) +{ + struct translate_key hw_key; + unsigned dst_offset; + unsigned i; + + vbuf->render->set_primitive(vbuf->render, prim); + + /* Must do this after set_primitive() above: + * + * XXX: need some state managment to track when this needs to be + * recalculated. The driver should tell us whether there was a + * state change. + */ + vbuf->vinfo = vbuf->render->get_vertex_info(vbuf->render); + vbuf->vertex_size = vbuf->vinfo->size * sizeof(float); + + /* Translate from pipeline vertices to hw vertices. + */ + dst_offset = 0; + + for (i = 0; i < vbuf->vinfo->num_attribs; i++) { + unsigned emit_sz = 0; + unsigned src_buffer = 0; + enum pipe_format output_format; + unsigned src_offset = (vbuf->vinfo->attrib[i].src_index * 4 * sizeof(float) ); + + output_format = draw_translate_vinfo_format(vbuf->vinfo->attrib[i].emit); + emit_sz = draw_translate_vinfo_size(vbuf->vinfo->attrib[i].emit); + + /* doesn't handle EMIT_OMIT */ + assert(emit_sz != 0); + + if (vbuf->vinfo->attrib[i].emit == EMIT_1F_PSIZE) { + src_buffer = 1; + src_offset = 0; + } + + hw_key.element[i].type = TRANSLATE_ELEMENT_NORMAL; + hw_key.element[i].input_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + hw_key.element[i].input_buffer = src_buffer; + hw_key.element[i].input_offset = src_offset; + hw_key.element[i].instance_divisor = 0; + hw_key.element[i].output_format = output_format; + hw_key.element[i].output_offset = dst_offset; + + dst_offset += emit_sz; + } + + hw_key.nr_elements = vbuf->vinfo->num_attribs; + hw_key.output_stride = vbuf->vinfo->size * 4; + + /* Don't bother with caching at this stage: + */ + if (!vbuf->translate || + translate_key_compare(&vbuf->translate->key, &hw_key) != 0) + { + translate_key_sanitize(&hw_key); + vbuf->translate = translate_cache_find(vbuf->cache, &hw_key); + + vbuf->translate->set_buffer(vbuf->translate, 1, &vbuf->point_size, 0, ~0); + } + + vbuf->point_size = vbuf->stage.draw->rasterizer->point_size; + + /* Allocate new buffer? + */ + assert(vbuf->vertices == NULL); + vbuf_alloc_vertices(vbuf); +} + + +static void +vbuf_first_tri( struct draw_stage *stage, + struct prim_header *prim ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + vbuf_flush_vertices( vbuf ); + vbuf_start_prim(vbuf, PIPE_PRIM_TRIANGLES); + stage->tri = vbuf_tri; + stage->tri( stage, prim ); +} + + +static void +vbuf_first_line( struct draw_stage *stage, + struct prim_header *prim ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + vbuf_flush_vertices( vbuf ); + vbuf_start_prim(vbuf, PIPE_PRIM_LINES); + stage->line = vbuf_line; + stage->line( stage, prim ); +} + + +static void +vbuf_first_point( struct draw_stage *stage, + struct prim_header *prim ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + vbuf_flush_vertices(vbuf); + vbuf_start_prim(vbuf, PIPE_PRIM_POINTS); + stage->point = vbuf_point; + stage->point( stage, prim ); +} + + + +/** + * Flush existing vertex buffer and allocate a new one. + */ +static void +vbuf_flush_vertices( struct vbuf_stage *vbuf ) +{ + if(vbuf->vertices) { + + vbuf->render->unmap_vertices( vbuf->render, 0, vbuf->nr_vertices - 1 ); + + if (vbuf->nr_indices) + { + vbuf->render->draw_elements(vbuf->render, + vbuf->indices, + vbuf->nr_indices ); + + vbuf->nr_indices = 0; + } + + /* Reset temporary vertices ids */ + if(vbuf->nr_vertices) + draw_reset_vertex_ids( vbuf->stage.draw ); + + /* Free the vertex buffer */ + vbuf->render->release_vertices( vbuf->render ); + + vbuf->max_vertices = vbuf->nr_vertices = 0; + vbuf->vertex_ptr = vbuf->vertices = NULL; + } +} + + +static void +vbuf_alloc_vertices( struct vbuf_stage *vbuf ) +{ + assert(!vbuf->nr_indices); + assert(!vbuf->vertices); + + /* Allocate a new vertex buffer */ + vbuf->max_vertices = vbuf->render->max_vertex_buffer_bytes / vbuf->vertex_size; + + if(vbuf->max_vertices >= UNDEFINED_VERTEX_ID) + vbuf->max_vertices = UNDEFINED_VERTEX_ID - 1; + + /* Must always succeed -- driver gives us a + * 'max_vertex_buffer_bytes' which it guarantees it can allocate, + * and it will flush itself if necessary to do so. If this does + * fail, we are basically without usable hardware. + */ + vbuf->render->allocate_vertices(vbuf->render, + (ushort) vbuf->vertex_size, + (ushort) vbuf->max_vertices); + + vbuf->vertices = (uint *) vbuf->render->map_vertices( vbuf->render ); + + vbuf->vertex_ptr = vbuf->vertices; +} + + + +static void +vbuf_flush( struct draw_stage *stage, unsigned flags ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + vbuf_flush_vertices( vbuf ); + + stage->point = vbuf_first_point; + stage->line = vbuf_first_line; + stage->tri = vbuf_first_tri; +} + + +static void +vbuf_reset_stipple_counter( struct draw_stage *stage ) +{ + /* XXX: Need to do something here for hardware with linestipple. + */ + (void) stage; +} + + +static void vbuf_destroy( struct draw_stage *stage ) +{ + struct vbuf_stage *vbuf = vbuf_stage( stage ); + + if(vbuf->indices) + align_free( vbuf->indices ); + + if (vbuf->render) + vbuf->render->destroy( vbuf->render ); + + if (vbuf->cache) + translate_cache_destroy(vbuf->cache); + + FREE( stage ); +} + + +/** + * Create a new primitive vbuf/render stage. + */ +struct draw_stage *draw_vbuf_stage( struct draw_context *draw, + struct vbuf_render *render ) +{ + struct vbuf_stage *vbuf = CALLOC_STRUCT(vbuf_stage); + if (vbuf == NULL) + goto fail; + + vbuf->stage.draw = draw; + vbuf->stage.name = "vbuf"; + vbuf->stage.point = vbuf_first_point; + vbuf->stage.line = vbuf_first_line; + vbuf->stage.tri = vbuf_first_tri; + vbuf->stage.flush = vbuf_flush; + vbuf->stage.reset_stipple_counter = vbuf_reset_stipple_counter; + vbuf->stage.destroy = vbuf_destroy; + + vbuf->render = render; + vbuf->max_indices = MAX2(render->max_indices, UNDEFINED_VERTEX_ID-1); + + vbuf->indices = (ushort *) align_malloc( vbuf->max_indices * + sizeof(vbuf->indices[0]), + 16 ); + if (!vbuf->indices) + goto fail; + + vbuf->cache = translate_cache_create(); + if (!vbuf->cache) + goto fail; + + + vbuf->vertices = NULL; + vbuf->vertex_ptr = vbuf->vertices; + + return &vbuf->stage; + + fail: + if (vbuf) + vbuf_destroy(&vbuf->stage); + + return NULL; +} diff --git a/src/gallium/auxiliary/draw/draw_pipe_wide_line.c b/src/gallium/auxiliary/draw/draw_pipe_wide_line.c new file mode 100644 index 0000000..98da9cf --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_wide_line.c @@ -0,0 +1,228 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "draw_private.h" +#include "draw_pipe.h" + + +struct wideline_stage { + struct draw_stage stage; + + float half_line_width; +}; + + + +static INLINE struct wideline_stage *wideline_stage( struct draw_stage *stage ) +{ + return (struct wideline_stage *)stage; +} + + + +/** + * Draw a wide line by drawing a quad (two triangles). + */ +static void wideline_line( struct draw_stage *stage, + struct prim_header *header ) +{ + /*const struct wideline_stage *wide = wideline_stage(stage);*/ + const unsigned pos = draw_current_shader_position_output(stage->draw); + const float half_width = 0.5f * stage->draw->rasterizer->line_width; + + struct prim_header tri; + + struct vertex_header *v0 = dup_vert(stage, header->v[0], 0); + struct vertex_header *v1 = dup_vert(stage, header->v[0], 1); + struct vertex_header *v2 = dup_vert(stage, header->v[1], 2); + struct vertex_header *v3 = dup_vert(stage, header->v[1], 3); + + float *pos0 = v0->data[pos]; + float *pos1 = v1->data[pos]; + float *pos2 = v2->data[pos]; + float *pos3 = v3->data[pos]; + + const float dx = fabsf(pos0[0] - pos2[0]); + const float dy = fabsf(pos0[1] - pos2[1]); + + const boolean gl_rasterization_rules = + stage->draw->rasterizer->gl_rasterization_rules; + + /* small tweak to meet GL specification */ + const float bias = gl_rasterization_rules ? 0.125f : 0.0f; + + /* + * Draw wide line as a quad (two tris) by "stretching" the line along + * X or Y. + * We need to tweak coords in several ways to be conformant here. + */ + + if (dx > dy) { + /* x-major line */ + pos0[1] = pos0[1] - half_width - bias; + pos1[1] = pos1[1] + half_width - bias; + pos2[1] = pos2[1] - half_width - bias; + pos3[1] = pos3[1] + half_width - bias; + if (gl_rasterization_rules) { + if (pos0[0] < pos2[0]) { + /* left to right line */ + pos0[0] -= 0.5f; + pos1[0] -= 0.5f; + pos2[0] -= 0.5f; + pos3[0] -= 0.5f; + } + else { + /* right to left line */ + pos0[0] += 0.5f; + pos1[0] += 0.5f; + pos2[0] += 0.5f; + pos3[0] += 0.5f; + } + } + } + else { + /* y-major line */ + pos0[0] = pos0[0] - half_width + bias; + pos1[0] = pos1[0] + half_width + bias; + pos2[0] = pos2[0] - half_width + bias; + pos3[0] = pos3[0] + half_width + bias; + if (gl_rasterization_rules) { + if (pos0[1] < pos2[1]) { + /* top to bottom line */ + pos0[1] -= 0.5f; + pos1[1] -= 0.5f; + pos2[1] -= 0.5f; + pos3[1] -= 0.5f; + } + else { + /* bottom to top line */ + pos0[1] += 0.5f; + pos1[1] += 0.5f; + pos2[1] += 0.5f; + pos3[1] += 0.5f; + } + } + } + + tri.det = header->det; /* only the sign matters */ + tri.v[0] = v0; + tri.v[1] = v2; + tri.v[2] = v3; + stage->next->tri( stage->next, &tri ); + + tri.v[0] = v0; + tri.v[1] = v3; + tri.v[2] = v1; + stage->next->tri( stage->next, &tri ); +} + + +static void wideline_first_line( struct draw_stage *stage, + struct prim_header *header ) +{ + struct draw_context *draw = stage->draw; + struct pipe_context *pipe = draw->pipe; + const struct pipe_rasterizer_state *rast = draw->rasterizer; + void *r; + + /* Disable triangle culling, stippling, unfilled mode etc. */ + r = draw_get_rasterizer_no_cull(draw, rast->scissor, rast->flatshade); + draw->suspend_flushing = TRUE; + pipe->bind_rasterizer_state(pipe, r); + draw->suspend_flushing = FALSE; + + stage->line = wideline_line; + + wideline_line(stage, header); +} + + +static void wideline_flush( struct draw_stage *stage, unsigned flags ) +{ + struct draw_context *draw = stage->draw; + struct pipe_context *pipe = draw->pipe; + + stage->line = wideline_first_line; + stage->next->flush( stage->next, flags ); + + /* restore original rasterizer state */ + if (draw->rast_handle) { + draw->suspend_flushing = TRUE; + pipe->bind_rasterizer_state(pipe, draw->rast_handle); + draw->suspend_flushing = FALSE; + } +} + + +static void wideline_reset_stipple_counter( struct draw_stage *stage ) +{ + stage->next->reset_stipple_counter( stage->next ); +} + + +static void wideline_destroy( struct draw_stage *stage ) +{ + draw_free_temp_verts( stage ); + FREE( stage ); +} + + +struct draw_stage *draw_wide_line_stage( struct draw_context *draw ) +{ + struct wideline_stage *wide = CALLOC_STRUCT(wideline_stage); + if (wide == NULL) + goto fail; + + wide->stage.draw = draw; + wide->stage.name = "wide-line"; + wide->stage.next = NULL; + wide->stage.point = draw_pipe_passthrough_point; + wide->stage.line = wideline_first_line; + wide->stage.tri = draw_pipe_passthrough_tri; + wide->stage.flush = wideline_flush; + wide->stage.reset_stipple_counter = wideline_reset_stipple_counter; + wide->stage.destroy = wideline_destroy; + + if (!draw_alloc_temp_verts( &wide->stage, 4 )) + goto fail; + + return &wide->stage; + +fail: + if (wide) + wide->stage.destroy( &wide->stage ); + + return NULL; +} diff --git a/src/gallium/auxiliary/draw/draw_pipe_wide_point.c b/src/gallium/auxiliary/draw/draw_pipe_wide_point.c new file mode 100644 index 0000000..3646c6a --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pipe_wide_point.c @@ -0,0 +1,346 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +/** + * Notes on wide points and sprite mode: + * + * In wide point/sprite mode we effectively need to convert each incoming + * vertex into four outgoing vertices specifying the corners of a quad. + * Since we don't (yet) have geometry shaders, we have to handle this here + * in the draw module. + * + * For sprites, it also means that this is where we have to handle texcoords + * for the vertices of the quad. OpenGL's GL_COORD_REPLACE state specifies + * if/how enabled texcoords are automatically generated for sprites. We pass + * that info through gallium in the pipe_rasterizer_state::sprite_coord_mode + * array. + * + * Additionally, GLSL's gl_PointCoord fragment attribute has to be handled + * here as well. This is basically an additional texture/generic attribute + * that varies .x from 0 to 1 horizontally across the point and varies .y + * vertically from 0 to 1 down the sprite. + * + * With geometry shaders, the state tracker could create a GS to do + * most/all of this. + */ + + +#include "pipe/p_context.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" +#include "draw_fs.h" +#include "draw_vs.h" +#include "draw_pipe.h" + + +struct widepoint_stage { + struct draw_stage stage; /**< base class */ + + float half_point_size; + + float xbias; + float ybias; + + /** for automatic texcoord generation/replacement */ + uint num_texcoord_gen; + uint texcoord_gen_slot[PIPE_MAX_SHADER_OUTPUTS]; + + int psize_slot; +}; + + + +static INLINE struct widepoint_stage * +widepoint_stage( struct draw_stage *stage ) +{ + return (struct widepoint_stage *)stage; +} + + +/** + * Set the vertex texcoords for sprite mode. + * Coords may be left untouched or set to a right-side-up or upside-down + * orientation. + */ +static void set_texcoords(const struct widepoint_stage *wide, + struct vertex_header *v, const float tc[4]) +{ + const struct draw_context *draw = wide->stage.draw; + const struct pipe_rasterizer_state *rast = draw->rasterizer; + const uint texcoord_mode = rast->sprite_coord_mode; + uint i; + + for (i = 0; i < wide->num_texcoord_gen; i++) { + const uint slot = wide->texcoord_gen_slot[i]; + v->data[slot][0] = tc[0]; + if (texcoord_mode == PIPE_SPRITE_COORD_LOWER_LEFT) + v->data[slot][1] = 1.0f - tc[1]; + else + v->data[slot][1] = tc[1]; + v->data[slot][2] = tc[2]; + v->data[slot][3] = tc[3]; + } +} + + +/* If there are lots of sprite points (and why wouldn't there be?) it + * would probably be more sensible to change hardware setup to + * optimize this rather than doing the whole thing in software like + * this. + */ +static void widepoint_point( struct draw_stage *stage, + struct prim_header *header ) +{ + const struct widepoint_stage *wide = widepoint_stage(stage); + const unsigned pos = draw_current_shader_position_output(stage->draw); + const boolean sprite = (boolean) stage->draw->rasterizer->point_quad_rasterization; + float half_size; + float left_adj, right_adj, bot_adj, top_adj; + + struct prim_header tri; + + /* four dups of original vertex */ + struct vertex_header *v0 = dup_vert(stage, header->v[0], 0); + struct vertex_header *v1 = dup_vert(stage, header->v[0], 1); + struct vertex_header *v2 = dup_vert(stage, header->v[0], 2); + struct vertex_header *v3 = dup_vert(stage, header->v[0], 3); + + float *pos0 = v0->data[pos]; + float *pos1 = v1->data[pos]; + float *pos2 = v2->data[pos]; + float *pos3 = v3->data[pos]; + + /* point size is either per-vertex or fixed size */ + if (wide->psize_slot >= 0) { + half_size = header->v[0]->data[wide->psize_slot][0]; + half_size *= 0.5f; + } + else { + half_size = wide->half_point_size; + } + + left_adj = -half_size + wide->xbias; + right_adj = half_size + wide->xbias; + bot_adj = half_size + wide->ybias; + top_adj = -half_size + wide->ybias; + + pos0[0] += left_adj; + pos0[1] += top_adj; + + pos1[0] += left_adj; + pos1[1] += bot_adj; + + pos2[0] += right_adj; + pos2[1] += top_adj; + + pos3[0] += right_adj; + pos3[1] += bot_adj; + + if (sprite) { + static const float tex00[4] = { 0, 0, 0, 1 }; + static const float tex01[4] = { 0, 1, 0, 1 }; + static const float tex11[4] = { 1, 1, 0, 1 }; + static const float tex10[4] = { 1, 0, 0, 1 }; + set_texcoords( wide, v0, tex00 ); + set_texcoords( wide, v1, tex01 ); + set_texcoords( wide, v2, tex10 ); + set_texcoords( wide, v3, tex11 ); + } + + tri.det = header->det; /* only the sign matters */ + tri.v[0] = v0; + tri.v[1] = v2; + tri.v[2] = v3; + stage->next->tri( stage->next, &tri ); + + tri.v[0] = v0; + tri.v[1] = v3; + tri.v[2] = v1; + stage->next->tri( stage->next, &tri ); +} + + +static void +widepoint_first_point(struct draw_stage *stage, + struct prim_header *header) +{ + struct widepoint_stage *wide = widepoint_stage(stage); + struct draw_context *draw = stage->draw; + struct pipe_context *pipe = draw->pipe; + const struct pipe_rasterizer_state *rast = draw->rasterizer; + void *r; + + wide->half_point_size = 0.5f * rast->point_size; + wide->xbias = 0.0; + wide->ybias = 0.0; + + if (rast->gl_rasterization_rules) { + wide->xbias = 0.125; + wide->ybias = -0.125; + } + + /* Disable triangle culling, stippling, unfilled mode etc. */ + r = draw_get_rasterizer_no_cull(draw, rast->scissor, rast->flatshade); + draw->suspend_flushing = TRUE; + pipe->bind_rasterizer_state(pipe, r); + draw->suspend_flushing = FALSE; + + /* XXX we won't know the real size if it's computed by the vertex shader! */ + if ((rast->point_size > draw->pipeline.wide_point_threshold) || + (rast->point_quad_rasterization && draw->pipeline.point_sprite)) { + stage->point = widepoint_point; + } + else { + stage->point = draw_pipe_passthrough_point; + } + + draw_remove_extra_vertex_attribs(draw); + + if (rast->point_quad_rasterization) { + const struct draw_fragment_shader *fs = draw->fs.fragment_shader; + uint i; + + wide->num_texcoord_gen = 0; + + /* Loop over fragment shader inputs looking for generic inputs + * for which bit 'k' in sprite_coord_enable is set. + */ + for (i = 0; i < fs->info.num_inputs; i++) { + if (fs->info.input_semantic_name[i] == TGSI_SEMANTIC_GENERIC) { + const int generic_index = fs->info.input_semantic_index[i]; + /* Note that sprite_coord enable is a bitfield of + * PIPE_MAX_SHADER_OUTPUTS bits. + */ + if (generic_index < PIPE_MAX_SHADER_OUTPUTS && + (rast->sprite_coord_enable & (1 << generic_index))) { + /* OK, this generic attribute needs to be replaced with a + * texcoord (see above). + */ + int slot = draw_find_shader_output(draw, + TGSI_SEMANTIC_GENERIC, + generic_index); + + if (slot > 0) { + /* there's already a post-vertex shader attribute + * for this fragment shader input attribute. + */ + } + else { + /* need to allocate a new post-vertex shader attribute */ + slot = draw_alloc_extra_vertex_attrib(draw, + TGSI_SEMANTIC_GENERIC, + generic_index); + } + + /* add this slot to the texcoord-gen list */ + wide->texcoord_gen_slot[wide->num_texcoord_gen++] = slot; + } + } + } + } + + wide->psize_slot = -1; + if (rast->point_size_per_vertex) { + /* find PSIZ vertex output */ + const struct draw_vertex_shader *vs = draw->vs.vertex_shader; + uint i; + for (i = 0; i < vs->info.num_outputs; i++) { + if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_PSIZE) { + wide->psize_slot = i; + break; + } + } + } + + stage->point( stage, header ); +} + + +static void widepoint_flush( struct draw_stage *stage, unsigned flags ) +{ + struct draw_context *draw = stage->draw; + struct pipe_context *pipe = draw->pipe; + + stage->point = widepoint_first_point; + stage->next->flush( stage->next, flags ); + + draw_remove_extra_vertex_attribs(draw); + + /* restore original rasterizer state */ + if (draw->rast_handle) { + draw->suspend_flushing = TRUE; + pipe->bind_rasterizer_state(pipe, draw->rast_handle); + draw->suspend_flushing = FALSE; + } +} + + +static void widepoint_reset_stipple_counter( struct draw_stage *stage ) +{ + stage->next->reset_stipple_counter( stage->next ); +} + + +static void widepoint_destroy( struct draw_stage *stage ) +{ + draw_free_temp_verts( stage ); + FREE( stage ); +} + + +struct draw_stage *draw_wide_point_stage( struct draw_context *draw ) +{ + struct widepoint_stage *wide = CALLOC_STRUCT(widepoint_stage); + if (wide == NULL) + goto fail; + + wide->stage.draw = draw; + wide->stage.name = "wide-point"; + wide->stage.next = NULL; + wide->stage.point = widepoint_first_point; + wide->stage.line = draw_pipe_passthrough_line; + wide->stage.tri = draw_pipe_passthrough_tri; + wide->stage.flush = widepoint_flush; + wide->stage.reset_stipple_counter = widepoint_reset_stipple_counter; + wide->stage.destroy = widepoint_destroy; + + if (!draw_alloc_temp_verts( &wide->stage, 4 )) + goto fail; + + return &wide->stage; + + fail: + if (wide) + wide->stage.destroy( &wide->stage ); + + return NULL; +} diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h new file mode 100644 index 0000000..06ed4d6 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_private.h @@ -0,0 +1,441 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Private data structures, etc for the draw module. + */ + + +/** + * Authors: + * Keith Whitwell + * Brian Paul + */ + + +#ifndef DRAW_PRIVATE_H +#define DRAW_PRIVATE_H + + +#include "pipe/p_state.h" +#include "pipe/p_defines.h" + +#include "tgsi/tgsi_scan.h" + +#ifdef HAVE_LLVM +#include +struct draw_llvm; +#endif + + +struct pipe_context; +struct draw_vertex_shader; +struct draw_context; +struct draw_stage; +struct vbuf_render; +struct tgsi_exec_machine; +struct tgsi_sampler; + + +/** + * Basic vertex info. + * Carry some useful information around with the vertices in the prim pipe. + */ +struct vertex_header { + unsigned clipmask:12; + unsigned edgeflag:1; + unsigned pad:3; + unsigned vertex_id:16; + + float clip[4]; + + /* This will probably become float (*data)[4] soon: + */ + float data[][4]; +}; + +/* NOTE: It should match vertex_id size above */ +#define UNDEFINED_VERTEX_ID 0xffff + + +/* maximum number of shader variants we can cache */ +#define DRAW_MAX_SHADER_VARIANTS 1024 + +/** + * Private context for the drawing module. + */ +struct draw_context +{ + struct pipe_context *pipe; + + /** Drawing/primitive pipeline stages */ + struct { + struct draw_stage *first; /**< one of the following */ + + struct draw_stage *validate; + + /* stages (in logical order) */ + struct draw_stage *flatshade; + struct draw_stage *clip; + struct draw_stage *cull; + struct draw_stage *twoside; + struct draw_stage *offset; + struct draw_stage *unfilled; + struct draw_stage *stipple; + struct draw_stage *aapoint; + struct draw_stage *aaline; + struct draw_stage *pstipple; + struct draw_stage *wide_line; + struct draw_stage *wide_point; + struct draw_stage *rasterize; + + float wide_point_threshold; /**< convert pnts to tris if larger than this */ + float wide_line_threshold; /**< convert lines to tris if wider than this */ + boolean wide_point_sprites; /**< convert points to tris for sprite mode */ + boolean line_stipple; /**< do line stipple? */ + boolean point_sprite; /**< convert points to quads for sprites? */ + + /* Temporary storage while the pipeline is being run: + */ + char *verts; + unsigned vertex_stride; + unsigned vertex_count; + } pipeline; + + + struct vbuf_render *render; + + /* Support prototype passthrough path: + */ + struct { + struct { + struct draw_pt_middle_end *fetch_emit; + struct draw_pt_middle_end *fetch_shade_emit; + struct draw_pt_middle_end *general; + struct draw_pt_middle_end *llvm; + } middle; + + struct { + struct draw_pt_front_end *vsplit; + } front; + + struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; + unsigned nr_vertex_buffers; + + struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS]; + unsigned nr_vertex_elements; + + struct pipe_index_buffer index_buffer; + + /* user-space vertex data, buffers */ + struct { + /** vertex element/index buffer (ex: glDrawElements) */ + const void *elts; + /** bytes per index (0, 1, 2 or 4) */ + unsigned eltSize; + int eltBias; + unsigned min_index; + unsigned max_index; + + /** vertex arrays */ + const void *vbuffer[PIPE_MAX_ATTRIBS]; + + /** constant buffers (for vertex/geometry shader) */ + const void *vs_constants[PIPE_MAX_CONSTANT_BUFFERS]; + unsigned vs_constants_size[PIPE_MAX_CONSTANT_BUFFERS]; + const void *gs_constants[PIPE_MAX_CONSTANT_BUFFERS]; + unsigned gs_constants_size[PIPE_MAX_CONSTANT_BUFFERS]; + + /* pointer to planes */ + float (*planes)[12][4]; + } user; + + boolean test_fse; /* enable FSE even though its not correct (eg for softpipe) */ + boolean no_fse; /* disable FSE even when it is correct */ + } pt; + + struct { + boolean bypass_clip_xy; + boolean bypass_clip_z; + } driver; + + boolean flushing; /**< debugging/sanity */ + boolean suspend_flushing; /**< internally set */ + + /* Flags set if API requires clipping in these planes and the + * driver doesn't indicate that it can do it for us. + */ + boolean clip_xy; + boolean clip_z; + boolean clip_user; + + boolean force_passthrough; /**< never clip or shade */ + + boolean dump_vs; + + double mrd; /**< minimum resolvable depth value, for polygon offset */ + + /** Current rasterizer state given to us by the driver */ + const struct pipe_rasterizer_state *rasterizer; + /** Driver CSO handle for the current rasterizer state */ + void *rast_handle; + + /** Rasterizer CSOs without culling/stipple/etc */ + void *rasterizer_no_cull[2][2]; + + struct pipe_viewport_state viewport; + boolean identity_viewport; + + /** Vertex shader state */ + struct { + struct draw_vertex_shader *vertex_shader; + uint num_vs_outputs; /**< convenience, from vertex_shader */ + uint position_output; + uint edgeflag_output; + + /** TGSI program interpreter runtime state */ + struct tgsi_exec_machine *machine; + + uint num_samplers; + struct tgsi_sampler **samplers; + + /* Here's another one: + */ + struct aos_machine *aos_machine; + + + const void *aligned_constants[PIPE_MAX_CONSTANT_BUFFERS]; + + const void *aligned_constant_storage[PIPE_MAX_CONSTANT_BUFFERS]; + unsigned const_storage_size[PIPE_MAX_CONSTANT_BUFFERS]; + + + struct translate *fetch; + struct translate_cache *fetch_cache; + struct translate *emit; + struct translate_cache *emit_cache; + } vs; + + /** Geometry shader state */ + struct { + struct draw_geometry_shader *geometry_shader; + uint num_gs_outputs; /**< convenience, from geometry_shader */ + uint position_output; + + /** TGSI program interpreter runtime state */ + struct tgsi_exec_machine *machine; + + uint num_samplers; + struct tgsi_sampler **samplers; + } gs; + + /** Fragment shader state */ + struct { + struct draw_fragment_shader *fragment_shader; + } fs; + + /** Stream output (vertex feedback) state */ + struct { + struct pipe_stream_output_state state; + void *buffers[PIPE_MAX_SO_BUFFERS]; + uint num_buffers; + } so; + + /* Clip derived state: + */ + float plane[12][4]; + unsigned nr_planes; + boolean depth_clamp; + + /* If a prim stage introduces new vertex attributes, they'll be stored here + */ + struct { + uint num; + uint semantic_name[10]; + uint semantic_index[10]; + uint slot[10]; + } extra_shader_outputs; + + unsigned reduced_prim; + + unsigned instance_id; + +#ifdef HAVE_LLVM + struct draw_llvm *llvm; +#endif + + struct pipe_sampler_view *sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; + unsigned num_sampler_views; + const struct pipe_sampler_state *samplers[PIPE_MAX_VERTEX_SAMPLERS]; + unsigned num_samplers; + + void *driver_private; +}; + + +struct draw_fetch_info { + boolean linear; + unsigned start; + const unsigned *elts; + unsigned count; +}; + +struct draw_vertex_info { + struct vertex_header *verts; + unsigned vertex_size; + unsigned stride; + unsigned count; +}; + +/* these flags are set if the primitive is a segment of a larger one */ +#define DRAW_SPLIT_BEFORE 0x1 +#define DRAW_SPLIT_AFTER 0x2 + +struct draw_prim_info { + boolean linear; + unsigned start; + + const ushort *elts; + unsigned count; + + unsigned prim; + unsigned flags; + unsigned *primitive_lengths; + unsigned primitive_count; +}; + + +/******************************************************************************* + * Draw common initialization code + */ +boolean draw_init(struct draw_context *draw); + +/******************************************************************************* + * Vertex shader code: + */ +boolean draw_vs_init( struct draw_context *draw ); +void draw_vs_destroy( struct draw_context *draw ); + +void draw_vs_set_viewport( struct draw_context *, + const struct pipe_viewport_state * ); + +void +draw_vs_set_constants(struct draw_context *, + unsigned slot, + const void *constants, + unsigned size); + + + +/******************************************************************************* + * Geometry shading code: + */ +boolean draw_gs_init( struct draw_context *draw ); + +void +draw_gs_set_constants(struct draw_context *, + unsigned slot, + const void *constants, + unsigned size); + +void draw_gs_destroy( struct draw_context *draw ); + +/******************************************************************************* + * Common shading code: + */ +uint draw_current_shader_outputs(const struct draw_context *draw); +uint draw_current_shader_position_output(const struct draw_context *draw); + +int draw_alloc_extra_vertex_attrib(struct draw_context *draw, + uint semantic_name, uint semantic_index); +void draw_remove_extra_vertex_attribs(struct draw_context *draw); + + +/******************************************************************************* + * Vertex processing (was passthrough) code: + */ +boolean draw_pt_init( struct draw_context *draw ); +void draw_pt_destroy( struct draw_context *draw ); +void draw_pt_reset_vertex_ids( struct draw_context *draw ); + + +/******************************************************************************* + * Primitive processing (pipeline) code: + */ + +boolean draw_pipeline_init( struct draw_context *draw ); +void draw_pipeline_destroy( struct draw_context *draw ); + + + + + +/* + * These flags are used by the pipeline when unfilled and/or line stipple modes + * are operational. + */ +#define DRAW_PIPE_EDGE_FLAG_0 0x1 +#define DRAW_PIPE_EDGE_FLAG_1 0x2 +#define DRAW_PIPE_EDGE_FLAG_2 0x4 +#define DRAW_PIPE_EDGE_FLAG_ALL 0x7 +#define DRAW_PIPE_RESET_STIPPLE 0x8 + +void draw_pipeline_run( struct draw_context *draw, + const struct draw_vertex_info *vert, + const struct draw_prim_info *prim); + +void draw_pipeline_run_linear( struct draw_context *draw, + const struct draw_vertex_info *vert, + const struct draw_prim_info *prim); + + + + +void draw_pipeline_flush( struct draw_context *draw, + unsigned flags ); + + + +/******************************************************************************* + * Flushing + */ + +#define DRAW_FLUSH_STATE_CHANGE 0x8 +#define DRAW_FLUSH_BACKEND 0x10 + + +void draw_do_flush( struct draw_context *draw, unsigned flags ); + + + +void * +draw_get_rasterizer_no_cull( struct draw_context *draw, + boolean scissor, + boolean flatshade ); + + +#endif /* DRAW_PRIVATE_H */ diff --git a/src/gallium/auxiliary/draw/draw_pt.c b/src/gallium/auxiliary/draw/draw_pt.c new file mode 100644 index 0000000..4078b2a --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pt.c @@ -0,0 +1,484 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + +#include "draw/draw_context.h" +#include "draw/draw_gs.h" +#include "draw/draw_private.h" +#include "draw/draw_pt.h" +#include "draw/draw_vs.h" +#include "tgsi/tgsi_dump.h" +#include "util/u_math.h" +#include "util/u_prim.h" +#include "util/u_format.h" +#include "util/u_draw.h" + + +DEBUG_GET_ONCE_BOOL_OPTION(draw_fse, "DRAW_FSE", FALSE) +DEBUG_GET_ONCE_BOOL_OPTION(draw_no_fse, "DRAW_NO_FSE", FALSE) + +/* Overall we split things into: + * - frontend -- prepare fetch_elts, draw_elts - eg vsplit + * - middle -- fetch, shade, cliptest, viewport + * - pipeline -- the prim pipeline: clipping, wide lines, etc + * - backend -- the vbuf_render provided by the driver. + */ +static boolean +draw_pt_arrays(struct draw_context *draw, + unsigned prim, + unsigned start, + unsigned count) +{ + struct draw_pt_front_end *frontend = NULL; + struct draw_pt_middle_end *middle = NULL; + unsigned opt = 0; + + /* Sanitize primitive length: + */ + { + unsigned first, incr; + draw_pt_split_prim(prim, &first, &incr); + count = draw_pt_trim_count(count, first, incr); + if (count < first) + return TRUE; + } + + if (!draw->force_passthrough) { + unsigned gs_out_prim = (draw->gs.geometry_shader ? + draw->gs.geometry_shader->output_primitive : + prim); + + if (!draw->render) { + opt |= PT_PIPELINE; + } + + if (draw_need_pipeline(draw, + draw->rasterizer, + gs_out_prim)) { + opt |= PT_PIPELINE; + } + + if ((draw->clip_xy || + draw->clip_z || + draw->clip_user) && !draw->pt.test_fse) { + opt |= PT_CLIPTEST; + } + + opt |= PT_SHADE; + } + + if (draw->pt.middle.llvm) { + middle = draw->pt.middle.llvm; + } else { + if (opt == 0) + middle = draw->pt.middle.fetch_emit; + else if (opt == PT_SHADE && !draw->pt.no_fse) + middle = draw->pt.middle.fetch_shade_emit; + else + middle = draw->pt.middle.general; + } + + frontend = draw->pt.front.vsplit; + + frontend->prepare( frontend, prim, middle, opt ); + + frontend->run(frontend, start, count); + + frontend->finish( frontend ); + + return TRUE; +} + + +boolean draw_pt_init( struct draw_context *draw ) +{ + draw->pt.test_fse = debug_get_option_draw_fse(); + draw->pt.no_fse = debug_get_option_draw_no_fse(); + + draw->pt.front.vsplit = draw_pt_vsplit(draw); + if (!draw->pt.front.vsplit) + return FALSE; + + draw->pt.middle.fetch_emit = draw_pt_fetch_emit( draw ); + if (!draw->pt.middle.fetch_emit) + return FALSE; + + draw->pt.middle.fetch_shade_emit = draw_pt_middle_fse( draw ); + if (!draw->pt.middle.fetch_shade_emit) + return FALSE; + + draw->pt.middle.general = draw_pt_fetch_pipeline_or_emit( draw ); + if (!draw->pt.middle.general) + return FALSE; + +#if HAVE_LLVM + if (draw->llvm) + draw->pt.middle.llvm = draw_pt_fetch_pipeline_or_emit_llvm( draw ); +#endif + + return TRUE; +} + + +void draw_pt_destroy( struct draw_context *draw ) +{ + if (draw->pt.middle.llvm) { + draw->pt.middle.llvm->destroy( draw->pt.middle.llvm ); + draw->pt.middle.llvm = NULL; + } + + if (draw->pt.middle.general) { + draw->pt.middle.general->destroy( draw->pt.middle.general ); + draw->pt.middle.general = NULL; + } + + if (draw->pt.middle.fetch_emit) { + draw->pt.middle.fetch_emit->destroy( draw->pt.middle.fetch_emit ); + draw->pt.middle.fetch_emit = NULL; + } + + if (draw->pt.middle.fetch_shade_emit) { + draw->pt.middle.fetch_shade_emit->destroy( draw->pt.middle.fetch_shade_emit ); + draw->pt.middle.fetch_shade_emit = NULL; + } + + if (draw->pt.front.vsplit) { + draw->pt.front.vsplit->destroy( draw->pt.front.vsplit ); + draw->pt.front.vsplit = NULL; + } +} + + +/** + * Debug- print the first 'count' vertices. + */ +static void +draw_print_arrays(struct draw_context *draw, uint prim, int start, uint count) +{ + uint i; + + debug_printf("Draw arrays(prim = %u, start = %u, count = %u)\n", + prim, start, count); + + for (i = 0; i < count; i++) { + uint ii = 0; + uint j; + + if (draw->pt.user.eltSize) { + const char *elts; + + /* indexed arrays */ + elts = (const char *) draw->pt.user.elts; + elts += draw->pt.index_buffer.offset; + + switch (draw->pt.user.eltSize) { + case 1: + { + const ubyte *elem = (const ubyte *) elts; + ii = elem[start + i]; + } + break; + case 2: + { + const ushort *elem = (const ushort *) elts; + ii = elem[start + i]; + } + break; + case 4: + { + const uint *elem = (const uint *) elts; + ii = elem[start + i]; + } + break; + default: + assert(0); + return; + } + ii += draw->pt.user.eltBias; + debug_printf("Element[%u + %u] + %i -> Vertex %u:\n", start, i, + draw->pt.user.eltBias, ii); + } + else { + /* non-indexed arrays */ + ii = start + i; + debug_printf("Vertex %u:\n", ii); + } + + for (j = 0; j < draw->pt.nr_vertex_elements; j++) { + uint buf = draw->pt.vertex_element[j].vertex_buffer_index; + ubyte *ptr = (ubyte *) draw->pt.user.vbuffer[buf]; + + if (draw->pt.vertex_element[j].instance_divisor) { + ii = draw->instance_id / draw->pt.vertex_element[j].instance_divisor; + } + + ptr += draw->pt.vertex_buffer[buf].buffer_offset; + ptr += draw->pt.vertex_buffer[buf].stride * ii; + ptr += draw->pt.vertex_element[j].src_offset; + + debug_printf(" Attr %u: ", j); + switch (draw->pt.vertex_element[j].src_format) { + case PIPE_FORMAT_R32_FLOAT: + { + float *v = (float *) ptr; + debug_printf("R %f @ %p\n", v[0], (void *) v); + } + break; + case PIPE_FORMAT_R32G32_FLOAT: + { + float *v = (float *) ptr; + debug_printf("RG %f %f @ %p\n", v[0], v[1], (void *) v); + } + break; + case PIPE_FORMAT_R32G32B32_FLOAT: + { + float *v = (float *) ptr; + debug_printf("RGB %f %f %f @ %p\n", v[0], v[1], v[2], (void *) v); + } + break; + case PIPE_FORMAT_R32G32B32A32_FLOAT: + { + float *v = (float *) ptr; + debug_printf("RGBA %f %f %f %f @ %p\n", v[0], v[1], v[2], v[3], + (void *) v); + } + break; + case PIPE_FORMAT_B8G8R8A8_UNORM: + { + ubyte *u = (ubyte *) ptr; + debug_printf("BGRA %d %d %d %d @ %p\n", u[0], u[1], u[2], u[3], + (void *) u); + } + break; + default: + debug_printf("other format %s (fix me)\n", + util_format_name(draw->pt.vertex_element[j].src_format)); + } + } + } +} + + +/** Helper code for below */ +#define PRIM_RESTART_LOOP(elements) \ + do { \ + for (i = start; i < end; i++) { \ + if (elements[i] == info->restart_index) { \ + if (cur_count > 0) { \ + /* draw elts up to prev pos */ \ + draw_pt_arrays(draw, prim, cur_start, cur_count); \ + } \ + /* begin new prim at next elt */ \ + cur_start = i + 1; \ + cur_count = 0; \ + } \ + else { \ + cur_count++; \ + } \ + } \ + if (cur_count > 0) { \ + draw_pt_arrays(draw, prim, cur_start, cur_count); \ + } \ + } while (0) + + +/** + * For drawing prims with primitive restart enabled. + * Scan for restart indexes and draw the runs of elements/vertices between + * the restarts. + */ +static void +draw_pt_arrays_restart(struct draw_context *draw, + const struct pipe_draw_info *info) +{ + const unsigned prim = info->mode; + const unsigned start = info->start; + const unsigned count = info->count; + const unsigned end = start + count; + unsigned i, cur_start, cur_count; + + assert(info->primitive_restart); + + if (draw->pt.user.elts) { + /* indexed prims (draw_elements) */ + cur_start = start; + cur_count = 0; + + switch (draw->pt.user.eltSize) { + case 1: + { + const ubyte *elt_ub = (const ubyte *) draw->pt.user.elts; + PRIM_RESTART_LOOP(elt_ub); + } + break; + case 2: + { + const ushort *elt_us = (const ushort *) draw->pt.user.elts; + PRIM_RESTART_LOOP(elt_us); + } + break; + case 4: + { + const uint *elt_ui = (const uint *) draw->pt.user.elts; + PRIM_RESTART_LOOP(elt_ui); + } + break; + default: + assert(0 && "bad eltSize in draw_arrays()"); + } + } + else { + /* Non-indexed prims (draw_arrays). + * Primitive restart should have been handled in the state tracker. + */ + draw_pt_arrays(draw, prim, start, count); + } +} + + + +/** + * Non-instanced drawing. + * \sa draw_arrays_instanced + */ +void +draw_arrays(struct draw_context *draw, unsigned prim, + unsigned start, unsigned count) +{ + draw_arrays_instanced(draw, prim, start, count, 0, 1); +} + + +/** + * Instanced drawing. + * \sa draw_vbo + */ +void +draw_arrays_instanced(struct draw_context *draw, + unsigned mode, + unsigned start, + unsigned count, + unsigned startInstance, + unsigned instanceCount) +{ + struct pipe_draw_info info; + + util_draw_init_info(&info); + + info.mode = mode; + info.start = start; + info.count = count; + info.start_instance = startInstance; + info.instance_count = instanceCount; + + info.indexed = (draw->pt.user.elts != NULL); + if (!info.indexed) { + info.min_index = start; + info.max_index = start + count - 1; + } + + draw_vbo(draw, &info); +} + + +/** + * Draw vertex arrays. + * This is the main entrypoint into the drawing module. If drawing an indexed + * primitive, the draw_set_index_buffer() and draw_set_mapped_index_buffer() + * functions should have already been called to specify the element/index + * buffer information. + */ +void +draw_vbo(struct draw_context *draw, + const struct pipe_draw_info *info) +{ + unsigned reduced_prim = u_reduced_prim(info->mode); + unsigned instance; + + assert(info->instance_count > 0); + if (info->indexed) + assert(draw->pt.user.elts); + + draw->pt.user.eltSize = + (info->indexed) ? draw->pt.index_buffer.index_size : 0; + + draw->pt.user.eltBias = info->index_bias; + draw->pt.user.min_index = info->min_index; + draw->pt.user.max_index = info->max_index; + + if (reduced_prim != draw->reduced_prim) { + draw_do_flush(draw, DRAW_FLUSH_STATE_CHANGE); + draw->reduced_prim = reduced_prim; + } + + if (0) + debug_printf("draw_vbo(mode=%u start=%u count=%u):\n", + info->mode, info->start, info->count); + + if (0) + tgsi_dump(draw->vs.vertex_shader->state.tokens, 0); + + if (0) { + unsigned int i; + debug_printf("Elements:\n"); + for (i = 0; i < draw->pt.nr_vertex_elements; i++) { + debug_printf(" %u: src_offset=%u inst_div=%u vbuf=%u format=%s\n", + i, + draw->pt.vertex_element[i].src_offset, + draw->pt.vertex_element[i].instance_divisor, + draw->pt.vertex_element[i].vertex_buffer_index, + util_format_name(draw->pt.vertex_element[i].src_format)); + } + debug_printf("Buffers:\n"); + for (i = 0; i < draw->pt.nr_vertex_buffers; i++) { + debug_printf(" %u: stride=%u maxindex=%u offset=%u ptr=%p\n", + i, + draw->pt.vertex_buffer[i].stride, + draw->pt.vertex_buffer[i].max_index, + draw->pt.vertex_buffer[i].buffer_offset, + draw->pt.user.vbuffer[i]); + } + } + + if (0) + draw_print_arrays(draw, info->mode, info->start, MIN2(info->count, 20)); + + for (instance = 0; instance < info->instance_count; instance++) { + draw->instance_id = instance + info->start_instance; + + if (info->primitive_restart) { + draw_pt_arrays_restart(draw, info); + } + else { + draw_pt_arrays(draw, info->mode, info->start, info->count); + } + } +} diff --git a/src/gallium/auxiliary/draw/draw_pt.h b/src/gallium/auxiliary/draw/draw_pt.h new file mode 100644 index 0000000..5fbb424 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pt.h @@ -0,0 +1,243 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + +#ifndef DRAW_PT_H +#define DRAW_PT_H + +#include "pipe/p_compiler.h" + +struct draw_pt_middle_end; +struct draw_context; +struct draw_prim_info; +struct draw_vertex_info; + + +#define PT_SHADE 0x1 +#define PT_CLIPTEST 0x2 +#define PT_PIPELINE 0x4 +#define PT_MAX_MIDDLE 0x8 + + +/* The "front end" - prepare sets of fetch, draw elements for the + * middle end. + * + * The fetch elements are indices to the vertices. The draw elements are + * indices to the fetched vertices. When both arrays of elements are both + * linear, middle->run_linear is called; When only the fetch elements are + * linear, middle->run_linear_elts is called; Otherwise, middle->run is + * called. + * + * When the number of the draw elements exceeds max_vertex of the middle end, + * the draw elements (as well as the fetch elements) are splitted and the + * middle end is called multiple times. + * + * Currenly there is: + * - vsplit - catchall implementation, splits big prims + */ +struct draw_pt_front_end { + void (*prepare)( struct draw_pt_front_end *, + unsigned prim, + struct draw_pt_middle_end *, + unsigned opt ); + + void (*run)( struct draw_pt_front_end *, + unsigned start, + unsigned count ); + + void (*finish)( struct draw_pt_front_end * ); + void (*destroy)( struct draw_pt_front_end * ); +}; + + +/* The "middle end" - prepares actual hardware vertices for the + * hardware backend. + * + * prim_flags is as defined by pipe_draw_info::flags. + * + * Currently two versions of this: + * - fetch, vertex shade, cliptest, prim-pipeline + * - fetch, emit (ie passthrough) + */ +struct draw_pt_middle_end { + void (*prepare)( struct draw_pt_middle_end *, + unsigned prim, + unsigned opt, + unsigned *max_vertices ); + + void (*run)( struct draw_pt_middle_end *, + const unsigned *fetch_elts, + unsigned fetch_count, + const ushort *draw_elts, + unsigned draw_count, + unsigned prim_flags ); + + void (*run_linear)(struct draw_pt_middle_end *, + unsigned start, + unsigned count, + unsigned prim_flags ); + + /* Transform all vertices in a linear range and then draw them with + * the supplied element list. May fail and return FALSE. + */ + boolean (*run_linear_elts)( struct draw_pt_middle_end *, + unsigned fetch_start, + unsigned fetch_count, + const ushort *draw_elts, + unsigned draw_count, + unsigned prim_flags ); + + int (*get_max_vertex_count)( struct draw_pt_middle_end * ); + + void (*finish)( struct draw_pt_middle_end * ); + void (*destroy)( struct draw_pt_middle_end * ); +}; + + +/* The "back end" - supplied by the driver, defined in draw_vbuf.h. + */ +struct vbuf_render; +struct vertex_header; + + +/* Frontends: + * + * Currently only the general-purpose vsplit implementation. + */ +struct draw_pt_front_end *draw_pt_vsplit(struct draw_context *draw); + + +/* Middle-ends: + * + * Currently one general-purpose case which can do all possibilities, + * at the slight expense of creating a vertex_header in some cases + * unecessarily. + * + * The special case fetch_emit code avoids pipeline vertices + * altogether and builds hardware vertices directly from API + * vertex_elements. + */ +struct draw_pt_middle_end *draw_pt_fetch_emit( struct draw_context *draw ); +struct draw_pt_middle_end *draw_pt_middle_fse( struct draw_context *draw ); +struct draw_pt_middle_end *draw_pt_fetch_pipeline_or_emit(struct draw_context *draw); +struct draw_pt_middle_end *draw_pt_fetch_pipeline_or_emit_llvm(struct draw_context *draw); + + + +/******************************************************************************* + * HW vertex emit: + */ +struct pt_emit; + +void draw_pt_emit_prepare( struct pt_emit *emit, + unsigned prim, + unsigned *max_vertices ); + +void draw_pt_emit( struct pt_emit *emit, + const struct draw_vertex_info *vert_info, + const struct draw_prim_info *prim_info); + +void draw_pt_emit_linear( struct pt_emit *emit, + const struct draw_vertex_info *vert_info, + const struct draw_prim_info *prim_info); + +void draw_pt_emit_destroy( struct pt_emit *emit ); + +struct pt_emit *draw_pt_emit_create( struct draw_context *draw ); + +/******************************************************************************* + * HW stream output emit: + */ +struct pt_so_emit; + +void draw_pt_so_emit_prepare( struct pt_so_emit *emit ); + +void draw_pt_so_emit( struct pt_so_emit *emit, + const struct draw_vertex_info *vert_info, + const struct draw_prim_info *prim_info ); + +void draw_pt_so_emit_destroy( struct pt_so_emit *emit ); + +struct pt_so_emit *draw_pt_so_emit_create( struct draw_context *draw ); + +/******************************************************************************* + * API vertex fetch: + */ + +struct pt_fetch; +void draw_pt_fetch_prepare( struct pt_fetch *fetch, + unsigned vertex_input_count, + unsigned vertex_size, + unsigned instance_id_index ); + +void draw_pt_fetch_run( struct pt_fetch *fetch, + const unsigned *elts, + unsigned count, + char *verts ); + +void draw_pt_fetch_run_linear( struct pt_fetch *fetch, + unsigned start, + unsigned count, + char *verts ); + +void draw_pt_fetch_destroy( struct pt_fetch *fetch ); + +struct pt_fetch *draw_pt_fetch_create( struct draw_context *draw ); + +/******************************************************************************* + * Post-VS: cliptest, rhw, viewport + */ +struct pt_post_vs; + +boolean draw_pt_post_vs_run( struct pt_post_vs *pvs, + struct draw_vertex_info *info ); + +void draw_pt_post_vs_prepare( struct pt_post_vs *pvs, + boolean clip_xy, + boolean clip_z, + boolean clip_user, + boolean bypass_viewport, + boolean opengl, + boolean need_edgeflags ); + +struct pt_post_vs *draw_pt_post_vs_create( struct draw_context *draw ); + +void draw_pt_post_vs_destroy( struct pt_post_vs *pvs ); + + +/******************************************************************************* + * Utils: + */ +void draw_pt_split_prim(unsigned prim, unsigned *first, unsigned *incr); +unsigned draw_pt_trim_count(unsigned count, unsigned first, unsigned incr); + + +#endif diff --git a/src/gallium/auxiliary/draw/draw_pt_decompose.h b/src/gallium/auxiliary/draw/draw_pt_decompose.h new file mode 100644 index 0000000..3127aad --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pt_decompose.h @@ -0,0 +1,7 @@ +#define LOCAL_VARS \ + char *verts = (char *) vertices; \ + const boolean last_vertex_last = \ + !(draw->rasterizer->flatshade && \ + draw->rasterizer->flatshade_first); + +#include "draw_decompose_tmp.h" diff --git a/src/gallium/auxiliary/draw/draw_pt_emit.c b/src/gallium/auxiliary/draw/draw_pt_emit.c new file mode 100644 index 0000000..c8dfc16 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pt_emit.c @@ -0,0 +1,301 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_memory.h" +#include "draw/draw_context.h" +#include "draw/draw_private.h" +#include "draw/draw_vbuf.h" +#include "draw/draw_vertex.h" +#include "draw/draw_pt.h" +#include "translate/translate.h" +#include "translate/translate_cache.h" + +struct pt_emit { + struct draw_context *draw; + + struct translate *translate; + + struct translate_cache *cache; + unsigned prim; + + const struct vertex_info *vinfo; +}; + +void draw_pt_emit_prepare( struct pt_emit *emit, + unsigned prim, + unsigned *max_vertices ) +{ + struct draw_context *draw = emit->draw; + const struct vertex_info *vinfo; + unsigned dst_offset; + struct translate_key hw_key; + unsigned i; + boolean ok; + + /* XXX: need to flush to get prim_vbuf.c to release its allocation?? + */ + draw_do_flush( draw, DRAW_FLUSH_BACKEND ); + + + /* XXX: may need to defensively reset this later on as clipping can + * clobber this state in the render backend. + */ + emit->prim = prim; + + ok = draw->render->set_primitive(draw->render, emit->prim); + if (!ok) { + assert(0); + return; + } + + /* Must do this after set_primitive() above: + */ + emit->vinfo = vinfo = draw->render->get_vertex_info(draw->render); + + + /* Translate from pipeline vertices to hw vertices. + */ + dst_offset = 0; + for (i = 0; i < vinfo->num_attribs; i++) { + unsigned emit_sz = 0; + unsigned src_buffer = 0; + unsigned output_format; + unsigned src_offset = (vinfo->attrib[i].src_index * 4 * sizeof(float) ); + + output_format = draw_translate_vinfo_format(vinfo->attrib[i].emit); + emit_sz = draw_translate_vinfo_size(vinfo->attrib[i].emit); + + /* doesn't handle EMIT_OMIT */ + assert(emit_sz != 0); + + if (vinfo->attrib[i].emit == EMIT_1F_PSIZE) { + src_buffer = 1; + src_offset = 0; + } + + hw_key.element[i].type = TRANSLATE_ELEMENT_NORMAL; + hw_key.element[i].input_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + hw_key.element[i].input_buffer = src_buffer; + hw_key.element[i].input_offset = src_offset; + hw_key.element[i].instance_divisor = 0; + hw_key.element[i].output_format = output_format; + hw_key.element[i].output_offset = dst_offset; + + dst_offset += emit_sz; + } + + hw_key.nr_elements = vinfo->num_attribs; + hw_key.output_stride = vinfo->size * 4; + + if (!emit->translate || + translate_key_compare(&emit->translate->key, &hw_key) != 0) + { + translate_key_sanitize(&hw_key); + emit->translate = translate_cache_find(emit->cache, &hw_key); + } + + *max_vertices = (draw->render->max_vertex_buffer_bytes / + (vinfo->size * 4)); +} + + +void draw_pt_emit( struct pt_emit *emit, + const struct draw_vertex_info *vert_info, + const struct draw_prim_info *prim_info) +{ + const float (*vertex_data)[4] = (const float (*)[4])vert_info->verts->data; + unsigned vertex_count = vert_info->count; + unsigned stride = vert_info->stride; + const ushort *elts = prim_info->elts; + struct draw_context *draw = emit->draw; + struct translate *translate = emit->translate; + struct vbuf_render *render = draw->render; + unsigned start, i; + void *hw_verts; + + /* XXX: need to flush to get prim_vbuf.c to release its allocation?? + */ + draw_do_flush( draw, DRAW_FLUSH_BACKEND ); + + if (vertex_count == 0) + return; + + /* XXX: and work out some way to coordinate the render primitive + * between vbuf.c and here... + */ + if (!draw->render->set_primitive(draw->render, emit->prim)) { + assert(0); + return; + } + + render->allocate_vertices(render, + (ushort)translate->key.output_stride, + (ushort)vertex_count); + + hw_verts = render->map_vertices( render ); + if (!hw_verts) { + assert(0); + return; + } + + translate->set_buffer(translate, + 0, + vertex_data, + stride, + ~0); + + translate->set_buffer(translate, + 1, + &draw->rasterizer->point_size, + 0, + ~0); + + /* fetch/translate vertex attribs to fill hw_verts[] */ + translate->run( translate, + 0, + vertex_count, + draw->instance_id, + hw_verts ); + + render->unmap_vertices( render, + 0, + vertex_count - 1 ); + + for (start = i = 0; + i < prim_info->primitive_count; + start += prim_info->primitive_lengths[i], i++) + { + render->draw_elements(render, + elts + start, + prim_info->primitive_lengths[i]); + } + + render->release_vertices(render); +} + + +void draw_pt_emit_linear(struct pt_emit *emit, + const struct draw_vertex_info *vert_info, + const struct draw_prim_info *prim_info) +{ + const float (*vertex_data)[4] = (const float (*)[4])vert_info->verts->data; + unsigned stride = vert_info->stride; + unsigned count = vert_info->count; + struct draw_context *draw = emit->draw; + struct translate *translate = emit->translate; + struct vbuf_render *render = draw->render; + void *hw_verts; + unsigned start, i; + +#if 0 + debug_printf("Linear emit\n"); +#endif + /* XXX: need to flush to get prim_vbuf.c to release its allocation?? + */ + draw_do_flush( draw, DRAW_FLUSH_BACKEND ); + + /* XXX: and work out some way to coordinate the render primitive + * between vbuf.c and here... + */ + if (!draw->render->set_primitive(draw->render, emit->prim)) + goto fail; + + if (!render->allocate_vertices(render, + (ushort)translate->key.output_stride, + (ushort)count)) + goto fail; + + hw_verts = render->map_vertices( render ); + if (!hw_verts) + goto fail; + + translate->set_buffer(translate, 0, + vertex_data, stride, count - 1); + + translate->set_buffer(translate, 1, + &draw->rasterizer->point_size, + 0, ~0); + + translate->run(translate, + 0, + count, + draw->instance_id, + hw_verts); + + if (0) { + unsigned i; + for (i = 0; i < count; i++) { + debug_printf("\n\n%s vertex %d:\n", __FUNCTION__, i); + draw_dump_emitted_vertex( emit->vinfo, + (const uint8_t *)hw_verts + + translate->key.output_stride * i ); + } + } + + render->unmap_vertices( render, 0, count - 1 ); + + for (start = i = 0; + i < prim_info->primitive_count; + start += prim_info->primitive_lengths[i], i++) + { + render->draw_arrays(render, + start, + prim_info->primitive_lengths[i]); + } + + render->release_vertices(render); + + return; + +fail: + assert(0); + return; +} + +struct pt_emit *draw_pt_emit_create( struct draw_context *draw ) +{ + struct pt_emit *emit = CALLOC_STRUCT(pt_emit); + if (!emit) + return NULL; + + emit->draw = draw; + emit->cache = translate_cache_create(); + if (!emit->cache) { + FREE(emit); + return NULL; + } + + return emit; +} + +void draw_pt_emit_destroy( struct pt_emit *emit ) +{ + if (emit->cache) + translate_cache_destroy(emit->cache); + + FREE(emit); +} diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch.c b/src/gallium/auxiliary/draw/draw_pt_fetch.c new file mode 100644 index 0000000..ae12ee2 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pt_fetch.c @@ -0,0 +1,203 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_memory.h" +#include "util/u_math.h" +#include "draw/draw_context.h" +#include "draw/draw_private.h" +#include "draw/draw_pt.h" +#include "translate/translate.h" +#include "translate/translate_cache.h" + + +struct pt_fetch { + struct draw_context *draw; + + struct translate *translate; + + unsigned vertex_size; + + struct translate_cache *cache; +}; + + +/* Perform the fetch from API vertex elements & vertex buffers, to a + * contiguous set of float[4] attributes as required for the + * vertex_shader->run_linear() method. + * + * This is used in all cases except pure passthrough + * (draw_pt_fetch_emit.c) which has its own version to translate + * directly to hw vertices. + * + */ +void draw_pt_fetch_prepare( struct pt_fetch *fetch, + unsigned vs_input_count, + unsigned vertex_size, + unsigned instance_id_index ) +{ + struct draw_context *draw = fetch->draw; + unsigned nr_inputs; + unsigned i, nr = 0, ei = 0; + unsigned dst_offset = 0; + unsigned num_extra_inputs = 0; + struct translate_key key; + + fetch->vertex_size = vertex_size; + + /* Leave the clipmask/edgeflags/pad/vertex_id untouched + */ + dst_offset += 1 * sizeof(float); + /* Just leave the clip[] array untouched. + */ + dst_offset += 4 * sizeof(float); + + if (instance_id_index != ~0) { + num_extra_inputs++; + } + + assert(draw->pt.nr_vertex_elements + num_extra_inputs >= vs_input_count); + + nr_inputs = MIN2(vs_input_count, draw->pt.nr_vertex_elements + num_extra_inputs); + + for (i = 0; i < nr_inputs; i++) { + if (i == instance_id_index) { + key.element[nr].type = TRANSLATE_ELEMENT_INSTANCE_ID; + key.element[nr].input_format = PIPE_FORMAT_R32_USCALED; + key.element[nr].output_format = PIPE_FORMAT_R32_USCALED; + key.element[nr].output_offset = dst_offset; + + dst_offset += sizeof(uint); + } else { + key.element[nr].type = TRANSLATE_ELEMENT_NORMAL; + key.element[nr].input_format = draw->pt.vertex_element[ei].src_format; + key.element[nr].input_buffer = draw->pt.vertex_element[ei].vertex_buffer_index; + key.element[nr].input_offset = draw->pt.vertex_element[ei].src_offset; + key.element[nr].instance_divisor = draw->pt.vertex_element[ei].instance_divisor; + key.element[nr].output_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + key.element[nr].output_offset = dst_offset; + + ei++; + dst_offset += 4 * sizeof(float); + } + + nr++; + } + + assert(dst_offset <= vertex_size); + + key.nr_elements = nr; + key.output_stride = vertex_size; + + if (!fetch->translate || + translate_key_compare(&fetch->translate->key, &key) != 0) + { + translate_key_sanitize(&key); + fetch->translate = translate_cache_find(fetch->cache, &key); + } + +} + + + + +void draw_pt_fetch_run( struct pt_fetch *fetch, + const unsigned *elts, + unsigned count, + char *verts ) +{ + struct draw_context *draw = fetch->draw; + struct translate *translate = fetch->translate; + unsigned i; + + for (i = 0; i < draw->pt.nr_vertex_buffers; i++) { + translate->set_buffer(translate, + i, + ((char *)draw->pt.user.vbuffer[i] + + draw->pt.vertex_buffer[i].buffer_offset), + draw->pt.vertex_buffer[i].stride, + draw->pt.vertex_buffer[i].max_index); + } + + translate->run_elts( translate, + elts, + count, + draw->instance_id, + verts ); + +} + + +void draw_pt_fetch_run_linear( struct pt_fetch *fetch, + unsigned start, + unsigned count, + char *verts ) +{ + struct draw_context *draw = fetch->draw; + struct translate *translate = fetch->translate; + unsigned i; + + for (i = 0; i < draw->pt.nr_vertex_buffers; i++) { + translate->set_buffer(translate, + i, + ((char *)draw->pt.user.vbuffer[i] + + draw->pt.vertex_buffer[i].buffer_offset), + draw->pt.vertex_buffer[i].stride, + draw->pt.vertex_buffer[i].max_index); + } + + translate->run( translate, + start, + count, + draw->instance_id, + verts ); +} + + +struct pt_fetch *draw_pt_fetch_create( struct draw_context *draw ) +{ + struct pt_fetch *fetch = CALLOC_STRUCT(pt_fetch); + if (!fetch) + return NULL; + + fetch->draw = draw; + fetch->cache = translate_cache_create(); + if (!fetch->cache) { + FREE(fetch); + return NULL; + } + + return fetch; +} + +void draw_pt_fetch_destroy( struct pt_fetch *fetch ) +{ + if (fetch->cache) + translate_cache_destroy(fetch->cache); + + FREE(fetch); +} + diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c b/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c new file mode 100644 index 0000000..e706b77 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c @@ -0,0 +1,408 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_memory.h" +#include "draw/draw_context.h" +#include "draw/draw_private.h" +#include "draw/draw_vbuf.h" +#include "draw/draw_vertex.h" +#include "draw/draw_pt.h" +#include "draw/draw_gs.h" +#include "translate/translate.h" +#include "translate/translate_cache.h" + +/* The simplest 'middle end' in the new vertex code. + * + * The responsibilities of a middle end are to: + * - perform vertex fetch using + * - draw vertex element/buffer state + * - a list of fetch indices we received as an input + * - run the vertex shader + * - cliptest, + * - clip coord calculation + * - viewport transformation + * - if necessary, run the primitive pipeline, passing it: + * - a linear array of vertex_header vertices constructed here + * - a set of draw indices we received as an input + * - otherwise, drive the hw backend, + * - allocate space for hardware format vertices + * - translate the vertex-shader output vertices to hw format + * - calling the backend draw functions. + * + * For convenience, we provide a helper function to drive the hardware + * backend given similar inputs to those required to run the pipeline. + * + * In the case of passthrough mode, many of these actions are disabled + * or noops, so we end up doing: + * + * - perform vertex fetch + * - drive the hw backend + * + * IE, basically just vertex fetch to post-vs-format vertices, + * followed by a call to the backend helper function. + */ + + +struct fetch_emit_middle_end { + struct draw_pt_middle_end base; + struct draw_context *draw; + + struct translate *translate; + const struct vertex_info *vinfo; + + /* Cache point size somewhere it's address won't change: + */ + float point_size; + + struct translate_cache *cache; +}; + + + + +static void fetch_emit_prepare( struct draw_pt_middle_end *middle, + unsigned prim, + unsigned opt, + unsigned *max_vertices ) +{ + struct fetch_emit_middle_end *feme = (struct fetch_emit_middle_end *)middle; + struct draw_context *draw = feme->draw; + const struct vertex_info *vinfo; + unsigned i, dst_offset; + boolean ok; + struct translate_key key; + + unsigned gs_out_prim = (draw->gs.geometry_shader ? + draw->gs.geometry_shader->output_primitive : + prim); + + + + ok = draw->render->set_primitive( draw->render, + gs_out_prim ); + if (!ok) { + assert(0); + return; + } + + /* Must do this after set_primitive() above: + */ + vinfo = feme->vinfo = draw->render->get_vertex_info(draw->render); + + + + /* Transform from API vertices to HW vertices, skipping the + * pipeline_vertex intermediate step. + */ + dst_offset = 0; + memset(&key, 0, sizeof(key)); + + for (i = 0; i < vinfo->num_attribs; i++) { + const struct pipe_vertex_element *src = &draw->pt.vertex_element[vinfo->attrib[i].src_index]; + + unsigned emit_sz = 0; + unsigned input_format = src->src_format; + unsigned input_buffer = src->vertex_buffer_index; + unsigned input_offset = src->src_offset; + unsigned output_format; + + output_format = draw_translate_vinfo_format(vinfo->attrib[i].emit); + emit_sz = draw_translate_vinfo_size(vinfo->attrib[i].emit); + + if (vinfo->attrib[i].emit == EMIT_OMIT) + continue; + + if (vinfo->attrib[i].emit == EMIT_1F_PSIZE) { + input_format = PIPE_FORMAT_R32_FLOAT; + input_buffer = draw->pt.nr_vertex_buffers; + input_offset = 0; + } + + key.element[i].type = TRANSLATE_ELEMENT_NORMAL; + key.element[i].input_format = input_format; + key.element[i].input_buffer = input_buffer; + key.element[i].input_offset = input_offset; + key.element[i].instance_divisor = src->instance_divisor; + key.element[i].output_format = output_format; + key.element[i].output_offset = dst_offset; + + dst_offset += emit_sz; + } + + key.nr_elements = vinfo->num_attribs; + key.output_stride = vinfo->size * 4; + + /* Don't bother with caching at this stage: + */ + if (!feme->translate || + translate_key_compare(&feme->translate->key, &key) != 0) + { + translate_key_sanitize(&key); + feme->translate = translate_cache_find(feme->cache, + &key); + + + feme->translate->set_buffer(feme->translate, + draw->pt.nr_vertex_buffers, + &feme->point_size, + 0, + ~0); + } + + feme->point_size = draw->rasterizer->point_size; + + for (i = 0; i < draw->pt.nr_vertex_buffers; i++) { + feme->translate->set_buffer(feme->translate, + i, + ((char *)draw->pt.user.vbuffer[i] + + draw->pt.vertex_buffer[i].buffer_offset), + draw->pt.vertex_buffer[i].stride, + draw->pt.vertex_buffer[i].max_index); + } + + *max_vertices = (draw->render->max_vertex_buffer_bytes / + (vinfo->size * 4)); +} + + + + + +static void fetch_emit_run( struct draw_pt_middle_end *middle, + const unsigned *fetch_elts, + unsigned fetch_count, + const ushort *draw_elts, + unsigned draw_count, + unsigned prim_flags ) +{ + struct fetch_emit_middle_end *feme = (struct fetch_emit_middle_end *)middle; + struct draw_context *draw = feme->draw; + void *hw_verts; + + /* XXX: need to flush to get prim_vbuf.c to release its allocation?? + */ + draw_do_flush( draw, DRAW_FLUSH_BACKEND ); + + draw->render->allocate_vertices( draw->render, + (ushort)feme->translate->key.output_stride, + (ushort)fetch_count ); + + hw_verts = draw->render->map_vertices( draw->render ); + if (!hw_verts) { + assert(0); + return; + } + + + /* Single routine to fetch vertices and emit HW verts. + */ + feme->translate->run_elts( feme->translate, + fetch_elts, + fetch_count, + draw->instance_id, + hw_verts ); + + if (0) { + unsigned i; + for (i = 0; i < fetch_count; i++) { + debug_printf("\n\nvertex %d:\n", i); + draw_dump_emitted_vertex( feme->vinfo, + (const uint8_t *)hw_verts + feme->vinfo->size * 4 * i ); + } + } + + draw->render->unmap_vertices( draw->render, + 0, + (ushort)(fetch_count - 1) ); + + /* XXX: Draw arrays path to avoid re-emitting index list again and + * again. + */ + draw->render->draw_elements( draw->render, + draw_elts, + draw_count ); + + /* Done -- that was easy, wasn't it: + */ + draw->render->release_vertices( draw->render ); + +} + + +static void fetch_emit_run_linear( struct draw_pt_middle_end *middle, + unsigned start, + unsigned count, + unsigned prim_flags ) +{ + struct fetch_emit_middle_end *feme = (struct fetch_emit_middle_end *)middle; + struct draw_context *draw = feme->draw; + void *hw_verts; + + /* XXX: need to flush to get prim_vbuf.c to release its allocation?? + */ + draw_do_flush( draw, DRAW_FLUSH_BACKEND ); + + if (!draw->render->allocate_vertices( draw->render, + (ushort)feme->translate->key.output_stride, + (ushort)count )) + goto fail; + + hw_verts = draw->render->map_vertices( draw->render ); + if (!hw_verts) + goto fail; + + /* Single routine to fetch vertices and emit HW verts. + */ + feme->translate->run( feme->translate, + start, + count, + draw->instance_id, + hw_verts ); + + if (0) { + unsigned i; + for (i = 0; i < count; i++) { + debug_printf("\n\nvertex %d:\n", i); + draw_dump_emitted_vertex( feme->vinfo, + (const uint8_t *)hw_verts + feme->vinfo->size * 4 * i ); + } + } + + draw->render->unmap_vertices( draw->render, 0, count - 1 ); + + /* XXX: Draw arrays path to avoid re-emitting index list again and + * again. + */ + draw->render->draw_arrays( draw->render, 0, count ); + + /* Done -- that was easy, wasn't it: + */ + draw->render->release_vertices( draw->render ); + return; + +fail: + assert(0); + return; +} + + +static boolean fetch_emit_run_linear_elts( struct draw_pt_middle_end *middle, + unsigned start, + unsigned count, + const ushort *draw_elts, + unsigned draw_count, + unsigned prim_flags ) +{ + struct fetch_emit_middle_end *feme = (struct fetch_emit_middle_end *)middle; + struct draw_context *draw = feme->draw; + void *hw_verts; + + /* XXX: need to flush to get prim_vbuf.c to release its allocation?? + */ + draw_do_flush( draw, DRAW_FLUSH_BACKEND ); + + if (!draw->render->allocate_vertices( draw->render, + (ushort)feme->translate->key.output_stride, + (ushort)count )) + return FALSE; + + hw_verts = draw->render->map_vertices( draw->render ); + if (!hw_verts) + return FALSE; + + /* Single routine to fetch vertices and emit HW verts. + */ + feme->translate->run( feme->translate, + start, + count, + draw->instance_id, + hw_verts ); + + draw->render->unmap_vertices( draw->render, 0, (ushort)(count - 1) ); + + /* XXX: Draw arrays path to avoid re-emitting index list again and + * again. + */ + draw->render->draw_elements( draw->render, + draw_elts, + draw_count ); + + /* Done -- that was easy, wasn't it: + */ + draw->render->release_vertices( draw->render ); + + return TRUE; +} + + + + +static void fetch_emit_finish( struct draw_pt_middle_end *middle ) +{ + /* nothing to do */ +} + +static void fetch_emit_destroy( struct draw_pt_middle_end *middle ) +{ + struct fetch_emit_middle_end *feme = (struct fetch_emit_middle_end *)middle; + + if (feme->cache) + translate_cache_destroy(feme->cache); + + FREE(middle); +} + + +struct draw_pt_middle_end *draw_pt_fetch_emit( struct draw_context *draw ) +{ + struct fetch_emit_middle_end *fetch_emit = CALLOC_STRUCT( fetch_emit_middle_end ); + if (fetch_emit == NULL) + return NULL; + + fetch_emit->cache = translate_cache_create(); + if (!fetch_emit->cache) { + FREE(fetch_emit); + return NULL; + } + + fetch_emit->base.prepare = fetch_emit_prepare; + fetch_emit->base.run = fetch_emit_run; + fetch_emit->base.run_linear = fetch_emit_run_linear; + fetch_emit->base.run_linear_elts = fetch_emit_run_linear_elts; + fetch_emit->base.finish = fetch_emit_finish; + fetch_emit->base.destroy = fetch_emit_destroy; + + fetch_emit->draw = draw; + + return &fetch_emit->base; +} + diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c new file mode 100644 index 0000000..7c198c6 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c @@ -0,0 +1,386 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "draw/draw_context.h" +#include "draw/draw_private.h" +#include "draw/draw_vbuf.h" +#include "draw/draw_vertex.h" +#include "draw/draw_pt.h" +#include "draw/draw_vs.h" + + +struct fetch_shade_emit; + + +/* Prototype fetch, shade, emit-hw-verts all in one go. + */ +struct fetch_shade_emit { + struct draw_pt_middle_end base; + struct draw_context *draw; + + + /* Temporaries: + */ + const float *constants; + unsigned pitch[PIPE_MAX_ATTRIBS]; + const ubyte *src[PIPE_MAX_ATTRIBS]; + unsigned prim; + + struct draw_vs_varient_key key; + struct draw_vs_varient *active; + + + const struct vertex_info *vinfo; +}; + + + +static void fse_prepare( struct draw_pt_middle_end *middle, + unsigned prim, + unsigned opt, + unsigned *max_vertices ) +{ + struct fetch_shade_emit *fse = (struct fetch_shade_emit *)middle; + struct draw_context *draw = fse->draw; + unsigned num_vs_inputs = draw->vs.vertex_shader->info.num_inputs; + const struct vertex_info *vinfo; + unsigned i; + unsigned nr_vbs = 0; + + /* Can't support geometry shader on this path. + */ + assert(!draw->gs.geometry_shader); + + if (!draw->render->set_primitive( draw->render, + prim )) { + assert(0); + return; + } + + /* Must do this after set_primitive() above: + */ + fse->vinfo = vinfo = draw->render->get_vertex_info(draw->render); + + + fse->key.output_stride = vinfo->size * 4; + fse->key.nr_outputs = vinfo->num_attribs; + fse->key.nr_inputs = num_vs_inputs; + + fse->key.nr_elements = MAX2(fse->key.nr_outputs, /* outputs - translate to hw format */ + fse->key.nr_inputs); /* inputs - fetch from api format */ + + fse->key.viewport = !draw->identity_viewport; + fse->key.clip = draw->clip_xy || draw->clip_z || draw->clip_user; + fse->key.const_vbuffers = 0; + + memset(fse->key.element, 0, + fse->key.nr_elements * sizeof(fse->key.element[0])); + + for (i = 0; i < num_vs_inputs; i++) { + const struct pipe_vertex_element *src = &draw->pt.vertex_element[i]; + fse->key.element[i].in.format = src->src_format; + + /* Consider ignoring these, ie make generated programs + * independent of this state: + */ + fse->key.element[i].in.buffer = src->vertex_buffer_index; + fse->key.element[i].in.offset = src->src_offset; + nr_vbs = MAX2(nr_vbs, src->vertex_buffer_index + 1); + } + + for (i = 0; i < 5 && i < nr_vbs; i++) { + if (draw->pt.vertex_buffer[i].stride == 0) + fse->key.const_vbuffers |= (1<key.const_vbuffers); + + { + unsigned dst_offset = 0; + + for (i = 0; i < vinfo->num_attribs; i++) { + unsigned emit_sz = draw_translate_vinfo_size(vinfo->attrib[i].emit); + + /* doesn't handle EMIT_OMIT */ + assert(emit_sz != 0); + + /* The elements in the key correspond to vertex shader output + * numbers, not to positions in the hw vertex description -- + * that's handled by the output_offset field. + */ + fse->key.element[i].out.format = vinfo->attrib[i].emit; + fse->key.element[i].out.vs_output = vinfo->attrib[i].src_index; + fse->key.element[i].out.offset = dst_offset; + + dst_offset += emit_sz; + assert(fse->key.output_stride >= dst_offset); + } + } + + + fse->active = draw_vs_lookup_varient( draw->vs.vertex_shader, + &fse->key ); + + if (!fse->active) { + assert(0); + return ; + } + + if (0) debug_printf("%s: found const_vbuffers: %x\n", __FUNCTION__, + fse->active->key.const_vbuffers); + + /* Now set buffer pointers: + */ + for (i = 0; i < draw->pt.nr_vertex_buffers; i++) { + fse->active->set_buffer( fse->active, + i, + ((const ubyte *) draw->pt.user.vbuffer[i] + + draw->pt.vertex_buffer[i].buffer_offset), + draw->pt.vertex_buffer[i].stride, + draw->pt.vertex_buffer[i].max_index ); + } + + *max_vertices = (draw->render->max_vertex_buffer_bytes / + (vinfo->size * 4)); + + /* Probably need to do this somewhere (or fix exec shader not to + * need it): + */ + if (1) { + struct draw_vertex_shader *vs = draw->vs.vertex_shader; + vs->prepare(vs, draw); + } +} + + + +static void fse_run_linear( struct draw_pt_middle_end *middle, + unsigned start, + unsigned count, + unsigned prim_flags ) +{ + struct fetch_shade_emit *fse = (struct fetch_shade_emit *)middle; + struct draw_context *draw = fse->draw; + char *hw_verts; + + /* XXX: need to flush to get prim_vbuf.c to release its allocation?? + */ + draw_do_flush( draw, DRAW_FLUSH_BACKEND ); + + if (!draw->render->allocate_vertices( draw->render, + (ushort)fse->key.output_stride, + (ushort)count )) + goto fail; + + hw_verts = draw->render->map_vertices( draw->render ); + if (!hw_verts) + goto fail; + + /* Single routine to fetch vertices, run shader and emit HW verts. + * Clipping is done elsewhere -- either by the API or on hardware, + * or for some other reason not required... + */ + fse->active->run_linear( fse->active, + start, count, + hw_verts ); + + + if (0) { + unsigned i; + for (i = 0; i < count; i++) { + debug_printf("\n\n%s vertex %d: (stride %d, offset %d)\n", __FUNCTION__, i, + fse->key.output_stride, + fse->key.output_stride * i); + + draw_dump_emitted_vertex( fse->vinfo, + (const uint8_t *)hw_verts + fse->key.output_stride * i ); + } + } + + draw->render->unmap_vertices( draw->render, 0, (ushort)(count - 1) ); + + /* Draw arrays path to avoid re-emitting index list again and + * again. + */ + draw->render->draw_arrays( draw->render, + 0, + count ); + + + draw->render->release_vertices( draw->render ); + + return; + +fail: + assert(0); + return; +} + + +static void +fse_run(struct draw_pt_middle_end *middle, + const unsigned *fetch_elts, + unsigned fetch_count, + const ushort *draw_elts, + unsigned draw_count, + unsigned prim_flags ) +{ + struct fetch_shade_emit *fse = (struct fetch_shade_emit *)middle; + struct draw_context *draw = fse->draw; + void *hw_verts; + + /* XXX: need to flush to get prim_vbuf.c to release its allocation?? + */ + draw_do_flush( draw, DRAW_FLUSH_BACKEND ); + + if (!draw->render->allocate_vertices( draw->render, + (ushort)fse->key.output_stride, + (ushort)fetch_count )) + goto fail; + + hw_verts = draw->render->map_vertices( draw->render ); + if (!hw_verts) + goto fail; + + + /* Single routine to fetch vertices, run shader and emit HW verts. + */ + fse->active->run_elts( fse->active, + fetch_elts, + fetch_count, + hw_verts ); + + + if (0) { + unsigned i; + for (i = 0; i < fetch_count; i++) { + debug_printf("\n\n%s vertex %d:\n", __FUNCTION__, i); + draw_dump_emitted_vertex( fse->vinfo, + (const uint8_t *)hw_verts + + fse->key.output_stride * i ); + } + } + + draw->render->unmap_vertices( draw->render, 0, (ushort)(fetch_count - 1) ); + + draw->render->draw_elements( draw->render, + draw_elts, + draw_count ); + + + draw->render->release_vertices( draw->render ); + return; + +fail: + assert(0); + return; +} + + + +static boolean fse_run_linear_elts( struct draw_pt_middle_end *middle, + unsigned start, + unsigned count, + const ushort *draw_elts, + unsigned draw_count, + unsigned prim_flags ) +{ + struct fetch_shade_emit *fse = (struct fetch_shade_emit *)middle; + struct draw_context *draw = fse->draw; + char *hw_verts; + + /* XXX: need to flush to get prim_vbuf.c to release its allocation?? + */ + draw_do_flush( draw, DRAW_FLUSH_BACKEND ); + + if (!draw->render->allocate_vertices( draw->render, + (ushort)fse->key.output_stride, + (ushort)count )) + return FALSE; + + hw_verts = draw->render->map_vertices( draw->render ); + if (!hw_verts) + return FALSE; + + /* Single routine to fetch vertices, run shader and emit HW verts. + * Clipping is done elsewhere -- either by the API or on hardware, + * or for some other reason not required... + */ + fse->active->run_linear( fse->active, + start, count, + hw_verts ); + + + draw->render->draw_elements( draw->render, + draw_elts, + draw_count ); + + + draw->render->unmap_vertices( draw->render, 0, (ushort)(count - 1) ); + + draw->render->release_vertices( draw->render ); + + return TRUE; +} + + + +static void fse_finish( struct draw_pt_middle_end *middle ) +{ +} + + +static void +fse_destroy( struct draw_pt_middle_end *middle ) +{ + FREE(middle); +} + +struct draw_pt_middle_end *draw_pt_middle_fse( struct draw_context *draw ) +{ + struct fetch_shade_emit *fse = CALLOC_STRUCT(fetch_shade_emit); + if (!fse) + return NULL; + + fse->base.prepare = fse_prepare; + fse->base.run = fse_run; + fse->base.run_linear = fse_run_linear; + fse->base.run_linear_elts = fse_run_linear_elts; + fse->base.finish = fse_finish; + fse->base.destroy = fse_destroy; + fse->draw = draw; + + return &fse->base; +} diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c new file mode 100644 index 0000000..b72fd61 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c @@ -0,0 +1,445 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_prim.h" +#include "draw/draw_context.h" +#include "draw/draw_vbuf.h" +#include "draw/draw_vertex.h" +#include "draw/draw_pt.h" +#include "draw/draw_vs.h" +#include "draw/draw_gs.h" + + +struct fetch_pipeline_middle_end { + struct draw_pt_middle_end base; + struct draw_context *draw; + + struct pt_emit *emit; + struct pt_so_emit *so_emit; + struct pt_fetch *fetch; + struct pt_post_vs *post_vs; + + unsigned vertex_data_offset; + unsigned vertex_size; + unsigned input_prim; + unsigned opt; +}; + +static void fetch_pipeline_prepare( struct draw_pt_middle_end *middle, + unsigned prim, + unsigned opt, + unsigned *max_vertices ) +{ + struct fetch_pipeline_middle_end *fpme = (struct fetch_pipeline_middle_end *)middle; + struct draw_context *draw = fpme->draw; + struct draw_vertex_shader *vs = draw->vs.vertex_shader; + unsigned i; + unsigned instance_id_index = ~0; + + unsigned gs_out_prim = (draw->gs.geometry_shader ? + draw->gs.geometry_shader->output_primitive : + prim); + + /* Add one to num_outputs because the pipeline occasionally tags on + * an additional texcoord, eg for AA lines. + */ + unsigned nr = MAX2( vs->info.num_inputs, + vs->info.num_outputs + 1 ); + + /* Scan for instanceID system value. + */ + for (i = 0; i < vs->info.num_inputs; i++) { + if (vs->info.input_semantic_name[i] == TGSI_SEMANTIC_INSTANCEID) { + instance_id_index = i; + break; + } + } + + fpme->input_prim = prim; + fpme->opt = opt; + + /* Always leave room for the vertex header whether we need it or + * not. It's hard to get rid of it in particular because of the + * viewport code in draw_pt_post_vs.c. + */ + fpme->vertex_size = sizeof(struct vertex_header) + nr * 4 * sizeof(float); + + + + draw_pt_fetch_prepare( fpme->fetch, + vs->info.num_inputs, + fpme->vertex_size, + instance_id_index ); + /* XXX: it's not really gl rasterization rules we care about here, + * but gl vs dx9 clip spaces. + */ + draw_pt_post_vs_prepare( fpme->post_vs, + draw->clip_xy, + draw->clip_z, + draw->clip_user, + draw->identity_viewport, + (boolean)draw->rasterizer->gl_rasterization_rules, + (draw->vs.edgeflag_output ? TRUE : FALSE) ); + + draw_pt_so_emit_prepare( fpme->so_emit ); + + if (!(opt & PT_PIPELINE)) { + draw_pt_emit_prepare( fpme->emit, + gs_out_prim, + max_vertices ); + + *max_vertices = MAX2( *max_vertices, 4096 ); + } + else { + /* limit max fetches by limiting max_vertices */ + *max_vertices = 4096; + } + + /* No need to prepare the shader. + */ + vs->prepare(vs, draw); +} + + +static void fetch( struct pt_fetch *fetch, + const struct draw_fetch_info *fetch_info, + char *output) +{ + if (fetch_info->linear) { + draw_pt_fetch_run_linear( fetch, + fetch_info->start, + fetch_info->count, + output ); + } + else { + draw_pt_fetch_run( fetch, + fetch_info->elts, + fetch_info->count, + output ); + } +} + + +static void pipeline(struct fetch_pipeline_middle_end *fpme, + const struct draw_vertex_info *vert_info, + const struct draw_prim_info *prim_info) +{ + if (prim_info->linear) + draw_pipeline_run_linear( fpme->draw, + vert_info, + prim_info); + else + draw_pipeline_run( fpme->draw, + vert_info, + prim_info ); +} + +static void emit(struct pt_emit *emit, + const struct draw_vertex_info *vert_info, + const struct draw_prim_info *prim_info) +{ + if (prim_info->linear) { + draw_pt_emit_linear(emit, vert_info, prim_info); + } + else { + draw_pt_emit(emit, vert_info, prim_info); + } +} + + +static void draw_vertex_shader_run(struct draw_vertex_shader *vshader, + const void *constants[PIPE_MAX_CONSTANT_BUFFERS], + unsigned const_size[PIPE_MAX_CONSTANT_BUFFERS], + const struct draw_vertex_info *input_verts, + struct draw_vertex_info *output_verts ) +{ + output_verts->vertex_size = input_verts->vertex_size; + output_verts->stride = input_verts->vertex_size; + output_verts->count = input_verts->count; + output_verts->verts = + (struct vertex_header *)MALLOC(output_verts->vertex_size * + align(output_verts->count, 4)); + + vshader->run_linear(vshader, + (const float (*)[4])input_verts->verts->data, + ( float (*)[4])output_verts->verts->data, + constants, + const_size, + input_verts->count, + input_verts->vertex_size, + input_verts->vertex_size); +} + +static void fetch_pipeline_generic( struct draw_pt_middle_end *middle, + const struct draw_fetch_info *fetch_info, + const struct draw_prim_info *prim_info ) +{ + struct fetch_pipeline_middle_end *fpme = (struct fetch_pipeline_middle_end *)middle; + struct draw_context *draw = fpme->draw; + struct draw_vertex_shader *vshader = draw->vs.vertex_shader; + struct draw_geometry_shader *gshader = draw->gs.geometry_shader; + struct draw_prim_info gs_prim_info; + struct draw_vertex_info fetched_vert_info; + struct draw_vertex_info vs_vert_info; + struct draw_vertex_info gs_vert_info; + struct draw_vertex_info *vert_info; + unsigned opt = fpme->opt; + + fetched_vert_info.count = fetch_info->count; + fetched_vert_info.vertex_size = fpme->vertex_size; + fetched_vert_info.stride = fpme->vertex_size; + fetched_vert_info.verts = + (struct vertex_header *)MALLOC(fpme->vertex_size * + align(fetch_info->count, 4)); + if (!fetched_vert_info.verts) { + assert(0); + return; + } + + /* Fetch into our vertex buffer. + */ + fetch( fpme->fetch, fetch_info, (char *)fetched_vert_info.verts ); + + /* Finished with fetch: + */ + fetch_info = NULL; + vert_info = &fetched_vert_info; + + /* Run the shader, note that this overwrites the data[] parts of + * the pipeline verts. + */ + if (fpme->opt & PT_SHADE) { + draw_vertex_shader_run(vshader, + draw->pt.user.vs_constants, + draw->pt.user.vs_constants_size, + vert_info, + &vs_vert_info); + + FREE(vert_info->verts); + vert_info = &vs_vert_info; + } + + if ((fpme->opt & PT_SHADE) && gshader) { + draw_geometry_shader_run(gshader, + draw->pt.user.gs_constants, + draw->pt.user.gs_constants_size, + vert_info, + prim_info, + &gs_vert_info, + &gs_prim_info); + + FREE(vert_info->verts); + vert_info = &gs_vert_info; + prim_info = &gs_prim_info; + } + + + /* Stream output needs to be done before clipping. + * + * XXX: Stream output surely needs to respect the prim_info->elt + * lists. + */ + draw_pt_so_emit( fpme->so_emit, + vert_info, + prim_info ); + + if (draw_pt_post_vs_run( fpme->post_vs, + vert_info )) + { + opt |= PT_PIPELINE; + } + + /* Do we need to run the pipeline? + */ + if (opt & PT_PIPELINE) { + pipeline( fpme, + vert_info, + prim_info ); + } + else { + emit( fpme->emit, + vert_info, + prim_info ); + } + FREE(vert_info->verts); +} + +static void fetch_pipeline_run( struct draw_pt_middle_end *middle, + const unsigned *fetch_elts, + unsigned fetch_count, + const ushort *draw_elts, + unsigned draw_count, + unsigned prim_flags ) +{ + struct fetch_pipeline_middle_end *fpme = (struct fetch_pipeline_middle_end *)middle; + struct draw_fetch_info fetch_info; + struct draw_prim_info prim_info; + + fetch_info.linear = FALSE; + fetch_info.start = 0; + fetch_info.elts = fetch_elts; + fetch_info.count = fetch_count; + + prim_info.linear = FALSE; + prim_info.start = 0; + prim_info.count = draw_count; + prim_info.elts = draw_elts; + prim_info.prim = fpme->input_prim; + prim_info.flags = prim_flags; + prim_info.primitive_count = 1; + prim_info.primitive_lengths = &draw_count; + + fetch_pipeline_generic( middle, &fetch_info, &prim_info ); +} + + +static void fetch_pipeline_linear_run( struct draw_pt_middle_end *middle, + unsigned start, + unsigned count, + unsigned prim_flags) +{ + struct fetch_pipeline_middle_end *fpme = (struct fetch_pipeline_middle_end *)middle; + struct draw_fetch_info fetch_info; + struct draw_prim_info prim_info; + + fetch_info.linear = TRUE; + fetch_info.start = start; + fetch_info.count = count; + fetch_info.elts = NULL; + + prim_info.linear = TRUE; + prim_info.start = 0; + prim_info.count = count; + prim_info.elts = NULL; + prim_info.prim = fpme->input_prim; + prim_info.flags = prim_flags; + prim_info.primitive_count = 1; + prim_info.primitive_lengths = &count; + + fetch_pipeline_generic( middle, &fetch_info, &prim_info ); +} + + + +static boolean fetch_pipeline_linear_run_elts( struct draw_pt_middle_end *middle, + unsigned start, + unsigned count, + const ushort *draw_elts, + unsigned draw_count, + unsigned prim_flags ) +{ + struct fetch_pipeline_middle_end *fpme = (struct fetch_pipeline_middle_end *)middle; + struct draw_fetch_info fetch_info; + struct draw_prim_info prim_info; + + fetch_info.linear = TRUE; + fetch_info.start = start; + fetch_info.count = count; + fetch_info.elts = NULL; + + prim_info.linear = FALSE; + prim_info.start = 0; + prim_info.count = draw_count; + prim_info.elts = draw_elts; + prim_info.prim = fpme->input_prim; + prim_info.flags = prim_flags; + prim_info.primitive_count = 1; + prim_info.primitive_lengths = &draw_count; + + fetch_pipeline_generic( middle, &fetch_info, &prim_info ); + + return TRUE; +} + + + +static void fetch_pipeline_finish( struct draw_pt_middle_end *middle ) +{ + /* nothing to do */ +} + +static void fetch_pipeline_destroy( struct draw_pt_middle_end *middle ) +{ + struct fetch_pipeline_middle_end *fpme = (struct fetch_pipeline_middle_end *)middle; + + if (fpme->fetch) + draw_pt_fetch_destroy( fpme->fetch ); + + if (fpme->emit) + draw_pt_emit_destroy( fpme->emit ); + + if (fpme->so_emit) + draw_pt_so_emit_destroy( fpme->so_emit ); + + if (fpme->post_vs) + draw_pt_post_vs_destroy( fpme->post_vs ); + + FREE(middle); +} + + +struct draw_pt_middle_end *draw_pt_fetch_pipeline_or_emit( struct draw_context *draw ) +{ + struct fetch_pipeline_middle_end *fpme = CALLOC_STRUCT( fetch_pipeline_middle_end ); + if (!fpme) + goto fail; + + fpme->base.prepare = fetch_pipeline_prepare; + fpme->base.run = fetch_pipeline_run; + fpme->base.run_linear = fetch_pipeline_linear_run; + fpme->base.run_linear_elts = fetch_pipeline_linear_run_elts; + fpme->base.finish = fetch_pipeline_finish; + fpme->base.destroy = fetch_pipeline_destroy; + + fpme->draw = draw; + + fpme->fetch = draw_pt_fetch_create( draw ); + if (!fpme->fetch) + goto fail; + + fpme->post_vs = draw_pt_post_vs_create( draw ); + if (!fpme->post_vs) + goto fail; + + fpme->emit = draw_pt_emit_create( draw ); + if (!fpme->emit) + goto fail; + + fpme->so_emit = draw_pt_so_emit_create( draw ); + if (!fpme->so_emit) + goto fail; + + return &fpme->base; + + fail: + if (fpme) + fetch_pipeline_destroy( &fpme->base ); + + return NULL; +} diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c new file mode 100644 index 0000000..2e3afb2 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c @@ -0,0 +1,477 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL 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. + * + **************************************************************************/ + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "draw/draw_context.h" +#include "draw/draw_gs.h" +#include "draw/draw_vbuf.h" +#include "draw/draw_vertex.h" +#include "draw/draw_pt.h" +#include "draw/draw_vs.h" +#include "draw/draw_llvm.h" +#include "gallivm/lp_bld_init.h" + + +struct llvm_middle_end { + struct draw_pt_middle_end base; + struct draw_context *draw; + + struct pt_emit *emit; + struct pt_so_emit *so_emit; + struct pt_fetch *fetch; + struct pt_post_vs *post_vs; + + + unsigned vertex_data_offset; + unsigned vertex_size; + unsigned input_prim; + unsigned opt; + + struct draw_llvm *llvm; + struct draw_llvm_variant *current_variant; +}; + + +static void +llvm_middle_end_prepare( struct draw_pt_middle_end *middle, + unsigned in_prim, + unsigned opt, + unsigned *max_vertices ) +{ + struct llvm_middle_end *fpme = (struct llvm_middle_end *)middle; + struct draw_context *draw = fpme->draw; + struct llvm_vertex_shader *shader = + llvm_vertex_shader(draw->vs.vertex_shader); + char store[DRAW_LLVM_MAX_VARIANT_KEY_SIZE]; + struct draw_llvm_variant_key *key; + struct draw_llvm_variant *variant = NULL; + struct draw_llvm_variant_list_item *li; + unsigned i; + unsigned instance_id_index = ~0; + const unsigned out_prim = (draw->gs.geometry_shader ? + draw->gs.geometry_shader->output_primitive : + in_prim); + + /* Add one to num_outputs because the pipeline occasionally tags on + * an additional texcoord, eg for AA lines. + */ + const unsigned nr = MAX2( shader->base.info.num_inputs, + shader->base.info.num_outputs + 1 ); + + /* Scan for instanceID system value. + * XXX but we never use instance_id_index?! + */ + for (i = 0; i < shader->base.info.num_inputs; i++) { + if (shader->base.info.input_semantic_name[i] == TGSI_SEMANTIC_INSTANCEID) { + instance_id_index = i; + break; + } + } + + fpme->input_prim = in_prim; + fpme->opt = opt; + + /* Always leave room for the vertex header whether we need it or + * not. It's hard to get rid of it in particular because of the + * viewport code in draw_pt_post_vs.c. + */ + fpme->vertex_size = sizeof(struct vertex_header) + nr * 4 * sizeof(float); + + + /* XXX: it's not really gl rasterization rules we care about here, + * but gl vs dx9 clip spaces. + */ + draw_pt_post_vs_prepare( fpme->post_vs, + draw->clip_xy, + draw->clip_z, + draw->clip_user, + draw->identity_viewport, + (boolean)draw->rasterizer->gl_rasterization_rules, + (draw->vs.edgeflag_output ? TRUE : FALSE) ); + + draw_pt_so_emit_prepare( fpme->so_emit ); + + if (!(opt & PT_PIPELINE)) { + draw_pt_emit_prepare( fpme->emit, + out_prim, + max_vertices ); + + *max_vertices = MAX2( *max_vertices, 4096 ); + } + else { + /* limit max fetches by limiting max_vertices */ + *max_vertices = 4096; + } + + /* return even number */ + *max_vertices = *max_vertices & ~1; + + key = draw_llvm_make_variant_key(fpme->llvm, store); + + /* Search shader's list of variants for the key */ + li = first_elem(&shader->variants); + while (!at_end(&shader->variants, li)) { + if (memcmp(&li->base->key, key, shader->variant_key_size) == 0) { + variant = li->base; + break; + } + li = next_elem(li); + } + + if (variant) { + /* found the variant, move to head of global list (for LRU) */ + move_to_head(&fpme->llvm->vs_variants_list, &variant->list_item_global); + } + else { + /* Need to create new variant */ + unsigned i; + + /* First check if we've created too many variants. If so, free + * 25% of the LRU to avoid using too much memory. + */ + if (fpme->llvm->nr_variants >= DRAW_MAX_SHADER_VARIANTS) { + /* + * XXX: should we flush here ? + */ + for (i = 0; i < DRAW_MAX_SHADER_VARIANTS / 4; i++) { + struct draw_llvm_variant_list_item *item = + last_elem(&fpme->llvm->vs_variants_list); + draw_llvm_destroy_variant(item->base); + } + } + + variant = draw_llvm_create_variant(fpme->llvm, nr, key); + + if (variant) { + insert_at_head(&shader->variants, &variant->list_item_local); + insert_at_head(&fpme->llvm->vs_variants_list, &variant->list_item_global); + fpme->llvm->nr_variants++; + shader->variants_cached++; + } + } + + fpme->current_variant = variant; + + /*XXX we only support one constant buffer */ + fpme->llvm->jit_context.vs_constants = + draw->pt.user.vs_constants[0]; + fpme->llvm->jit_context.gs_constants = + draw->pt.user.gs_constants[0]; + fpme->llvm->jit_context.planes = + (float (*) [12][4]) draw->pt.user.planes[0]; + fpme->llvm->jit_context.viewport = + (float *)draw->viewport.scale; + +} + + +static void pipeline(struct llvm_middle_end *llvm, + const struct draw_vertex_info *vert_info, + const struct draw_prim_info *prim_info) +{ + if (prim_info->linear) + draw_pipeline_run_linear( llvm->draw, + vert_info, + prim_info); + else + draw_pipeline_run( llvm->draw, + vert_info, + prim_info ); +} + +static void emit(struct pt_emit *emit, + const struct draw_vertex_info *vert_info, + const struct draw_prim_info *prim_info) +{ + if (prim_info->linear) { + draw_pt_emit_linear(emit, vert_info, prim_info); + } + else { + draw_pt_emit(emit, vert_info, prim_info); + } +} + +static void +llvm_pipeline_generic( struct draw_pt_middle_end *middle, + const struct draw_fetch_info *fetch_info, + const struct draw_prim_info *prim_info ) +{ + struct llvm_middle_end *fpme = (struct llvm_middle_end *)middle; + struct draw_context *draw = fpme->draw; + struct draw_geometry_shader *gshader = draw->gs.geometry_shader; + struct draw_prim_info gs_prim_info; + struct draw_vertex_info llvm_vert_info; + struct draw_vertex_info gs_vert_info; + struct draw_vertex_info *vert_info; + unsigned opt = fpme->opt; + unsigned clipped = 0; + + llvm_vert_info.count = fetch_info->count; + llvm_vert_info.vertex_size = fpme->vertex_size; + llvm_vert_info.stride = fpme->vertex_size; + llvm_vert_info.verts = + (struct vertex_header *)MALLOC(fpme->vertex_size * + align(fetch_info->count, 4)); + if (!llvm_vert_info.verts) { + assert(0); + return; + } + + if (fetch_info->linear) + clipped = fpme->current_variant->jit_func( &fpme->llvm->jit_context, + llvm_vert_info.verts, + (const char **)draw->pt.user.vbuffer, + fetch_info->start, + fetch_info->count, + fpme->vertex_size, + draw->pt.vertex_buffer, + draw->instance_id); + else + clipped = fpme->current_variant->jit_func_elts( &fpme->llvm->jit_context, + llvm_vert_info.verts, + (const char **)draw->pt.user.vbuffer, + fetch_info->elts, + fetch_info->count, + fpme->vertex_size, + draw->pt.vertex_buffer, + draw->instance_id); + + /* Finished with fetch and vs: + */ + fetch_info = NULL; + vert_info = &llvm_vert_info; + + + if ((opt & PT_SHADE) && gshader) { + draw_geometry_shader_run(gshader, + draw->pt.user.gs_constants, + draw->pt.user.gs_constants_size, + vert_info, + prim_info, + &gs_vert_info, + &gs_prim_info); + + FREE(vert_info->verts); + vert_info = &gs_vert_info; + prim_info = &gs_prim_info; + + clipped = draw_pt_post_vs_run( fpme->post_vs, vert_info ); + + } + + /* stream output needs to be done before clipping */ + draw_pt_so_emit( fpme->so_emit, + vert_info, + prim_info ); + + if (clipped) { + opt |= PT_PIPELINE; + } + + /* Do we need to run the pipeline? Now will come here if clipped + */ + if (opt & PT_PIPELINE) { + pipeline( fpme, + vert_info, + prim_info ); + } + else { + emit( fpme->emit, + vert_info, + prim_info ); + } + FREE(vert_info->verts); +} + + +static void llvm_middle_end_run( struct draw_pt_middle_end *middle, + const unsigned *fetch_elts, + unsigned fetch_count, + const ushort *draw_elts, + unsigned draw_count, + unsigned prim_flags ) +{ + struct llvm_middle_end *fpme = (struct llvm_middle_end *)middle; + struct draw_fetch_info fetch_info; + struct draw_prim_info prim_info; + + fetch_info.linear = FALSE; + fetch_info.start = 0; + fetch_info.elts = fetch_elts; + fetch_info.count = fetch_count; + + prim_info.linear = FALSE; + prim_info.start = 0; + prim_info.count = draw_count; + prim_info.elts = draw_elts; + prim_info.prim = fpme->input_prim; + prim_info.flags = prim_flags; + prim_info.primitive_count = 1; + prim_info.primitive_lengths = &draw_count; + + llvm_pipeline_generic( middle, &fetch_info, &prim_info ); +} + + +static void llvm_middle_end_linear_run( struct draw_pt_middle_end *middle, + unsigned start, + unsigned count, + unsigned prim_flags) +{ + struct llvm_middle_end *fpme = (struct llvm_middle_end *)middle; + struct draw_fetch_info fetch_info; + struct draw_prim_info prim_info; + + fetch_info.linear = TRUE; + fetch_info.start = start; + fetch_info.count = count; + fetch_info.elts = NULL; + + prim_info.linear = TRUE; + prim_info.start = 0; + prim_info.count = count; + prim_info.elts = NULL; + prim_info.prim = fpme->input_prim; + prim_info.flags = prim_flags; + prim_info.primitive_count = 1; + prim_info.primitive_lengths = &count; + + llvm_pipeline_generic( middle, &fetch_info, &prim_info ); +} + + + +static boolean +llvm_middle_end_linear_run_elts( struct draw_pt_middle_end *middle, + unsigned start, + unsigned count, + const ushort *draw_elts, + unsigned draw_count, + unsigned prim_flags ) +{ + struct llvm_middle_end *fpme = (struct llvm_middle_end *)middle; + struct draw_fetch_info fetch_info; + struct draw_prim_info prim_info; + + fetch_info.linear = TRUE; + fetch_info.start = start; + fetch_info.count = count; + fetch_info.elts = NULL; + + prim_info.linear = FALSE; + prim_info.start = 0; + prim_info.count = draw_count; + prim_info.elts = draw_elts; + prim_info.prim = fpme->input_prim; + prim_info.flags = prim_flags; + prim_info.primitive_count = 1; + prim_info.primitive_lengths = &draw_count; + + llvm_pipeline_generic( middle, &fetch_info, &prim_info ); + + return TRUE; +} + + + +static void llvm_middle_end_finish( struct draw_pt_middle_end *middle ) +{ + /* nothing to do */ +} + +static void llvm_middle_end_destroy( struct draw_pt_middle_end *middle ) +{ + struct llvm_middle_end *fpme = (struct llvm_middle_end *)middle; + + if (fpme->fetch) + draw_pt_fetch_destroy( fpme->fetch ); + + if (fpme->emit) + draw_pt_emit_destroy( fpme->emit ); + + if (fpme->so_emit) + draw_pt_so_emit_destroy( fpme->so_emit ); + + if (fpme->post_vs) + draw_pt_post_vs_destroy( fpme->post_vs ); + + FREE(middle); +} + + +struct draw_pt_middle_end * +draw_pt_fetch_pipeline_or_emit_llvm(struct draw_context *draw) +{ + struct llvm_middle_end *fpme = 0; + + if (!draw->llvm->gallivm->engine) + return NULL; + + fpme = CALLOC_STRUCT( llvm_middle_end ); + if (!fpme) + goto fail; + + fpme->base.prepare = llvm_middle_end_prepare; + fpme->base.run = llvm_middle_end_run; + fpme->base.run_linear = llvm_middle_end_linear_run; + fpme->base.run_linear_elts = llvm_middle_end_linear_run_elts; + fpme->base.finish = llvm_middle_end_finish; + fpme->base.destroy = llvm_middle_end_destroy; + + fpme->draw = draw; + + fpme->fetch = draw_pt_fetch_create( draw ); + if (!fpme->fetch) + goto fail; + + fpme->post_vs = draw_pt_post_vs_create( draw ); + if (!fpme->post_vs) + goto fail; + + fpme->emit = draw_pt_emit_create( draw ); + if (!fpme->emit) + goto fail; + + fpme->so_emit = draw_pt_so_emit_create( draw ); + if (!fpme->so_emit) + goto fail; + + fpme->llvm = draw->llvm; + if (!fpme->llvm) + goto fail; + + fpme->current_variant = NULL; + + return &fpme->base; + + fail: + if (fpme) + llvm_middle_end_destroy( &fpme->base ); + + return NULL; +} diff --git a/src/gallium/auxiliary/draw/draw_pt_post_vs.c b/src/gallium/auxiliary/draw/draw_pt_post_vs.c new file mode 100644 index 0000000..769409c --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pt_post_vs.c @@ -0,0 +1,204 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_memory.h" +#include "util/u_math.h" +#include "pipe/p_context.h" +#include "draw/draw_context.h" +#include "draw/draw_private.h" +#include "draw/draw_pt.h" + + +#define DO_CLIP_XY 0x1 +#define DO_CLIP_FULL_Z 0x2 +#define DO_CLIP_HALF_Z 0x4 +#define DO_CLIP_USER 0x8 +#define DO_VIEWPORT 0x10 +#define DO_EDGEFLAG 0x20 + + +struct pt_post_vs { + struct draw_context *draw; + + unsigned flags; + + boolean (*run)( struct pt_post_vs *pvs, + struct draw_vertex_info *info ); +}; + +static INLINE void +initialize_vertex_header(struct vertex_header *header) +{ + header->clipmask = 0; + header->edgeflag = 1; + header->pad = 0; + header->vertex_id = UNDEFINED_VERTEX_ID; +} + +static INLINE float +dot4(const float *a, const float *b) +{ + return (a[0]*b[0] + + a[1]*b[1] + + a[2]*b[2] + + a[3]*b[3]); +} + +#define FLAGS (0) +#define TAG(x) x##_none +#include "draw_cliptest_tmp.h" + +#define FLAGS (DO_CLIP_XY | DO_CLIP_FULL_Z | DO_VIEWPORT) +#define TAG(x) x##_xy_fullz_viewport +#include "draw_cliptest_tmp.h" + +#define FLAGS (DO_CLIP_XY | DO_CLIP_HALF_Z | DO_VIEWPORT) +#define TAG(x) x##_xy_halfz_viewport +#include "draw_cliptest_tmp.h" + +#define FLAGS (DO_CLIP_FULL_Z | DO_VIEWPORT) +#define TAG(x) x##_fullz_viewport +#include "draw_cliptest_tmp.h" + +#define FLAGS (DO_CLIP_HALF_Z | DO_VIEWPORT) +#define TAG(x) x##_halfz_viewport +#include "draw_cliptest_tmp.h" + +#define FLAGS (DO_CLIP_XY | DO_CLIP_FULL_Z | DO_CLIP_USER | DO_VIEWPORT) +#define TAG(x) x##_xy_fullz_user_viewport +#include "draw_cliptest_tmp.h" + +#define FLAGS (DO_CLIP_XY | DO_CLIP_FULL_Z | DO_CLIP_USER | DO_VIEWPORT | DO_EDGEFLAG) +#define TAG(x) x##_xy_fullz_user_viewport_edgeflag +#include "draw_cliptest_tmp.h" + + + +/* Don't want to create 64 versions of this function, so catch the + * less common ones here. This is looking like something which should + * be code-generated, perhaps appended to the end of the vertex + * shader. + */ +#define FLAGS (pvs->flags) +#define TAG(x) x##_generic +#include "draw_cliptest_tmp.h" + + + +boolean draw_pt_post_vs_run( struct pt_post_vs *pvs, + struct draw_vertex_info *info ) +{ + return pvs->run( pvs, info ); +} + + +void draw_pt_post_vs_prepare( struct pt_post_vs *pvs, + boolean clip_xy, + boolean clip_z, + boolean clip_user, + boolean bypass_viewport, + boolean opengl, + boolean need_edgeflags ) +{ + pvs->flags = 0; + + if (clip_xy) + pvs->flags |= DO_CLIP_XY; + + if (clip_z && opengl) { + pvs->flags |= DO_CLIP_FULL_Z; + ASSIGN_4V( pvs->draw->plane[4], 0, 0, 1, 1 ); + } + + if (clip_z && !opengl) { + pvs->flags |= DO_CLIP_HALF_Z; + ASSIGN_4V( pvs->draw->plane[4], 0, 0, 1, 0 ); + } + + if (clip_user) + pvs->flags |= DO_CLIP_USER; + + if (!bypass_viewport) + pvs->flags |= DO_VIEWPORT; + + if (need_edgeflags) + pvs->flags |= DO_EDGEFLAG; + + /* Now select the relevant function: + */ + switch (pvs->flags) { + case 0: + pvs->run = do_cliptest_none; + break; + + case DO_CLIP_XY | DO_CLIP_FULL_Z | DO_VIEWPORT: + pvs->run = do_cliptest_xy_fullz_viewport; + break; + + case DO_CLIP_XY | DO_CLIP_HALF_Z | DO_VIEWPORT: + pvs->run = do_cliptest_xy_halfz_viewport; + break; + + case DO_CLIP_FULL_Z | DO_VIEWPORT: + pvs->run = do_cliptest_fullz_viewport; + break; + + case DO_CLIP_HALF_Z | DO_VIEWPORT: + pvs->run = do_cliptest_halfz_viewport; + break; + + case DO_CLIP_XY | DO_CLIP_FULL_Z | DO_CLIP_USER | DO_VIEWPORT: + pvs->run = do_cliptest_xy_fullz_user_viewport; + break; + + case (DO_CLIP_XY | DO_CLIP_FULL_Z | DO_CLIP_USER | + DO_VIEWPORT | DO_EDGEFLAG): + pvs->run = do_cliptest_xy_fullz_user_viewport_edgeflag; + break; + + default: + pvs->run = do_cliptest_generic; + break; + } +} + + +struct pt_post_vs *draw_pt_post_vs_create( struct draw_context *draw ) +{ + struct pt_post_vs *pvs = CALLOC_STRUCT( pt_post_vs ); + if (!pvs) + return NULL; + + pvs->draw = draw; + + return pvs; +} + +void draw_pt_post_vs_destroy( struct pt_post_vs *pvs ) +{ + FREE(pvs); +} diff --git a/src/gallium/auxiliary/draw/draw_pt_so_emit.c b/src/gallium/auxiliary/draw/draw_pt_so_emit.c new file mode 100644 index 0000000..c86bdd9 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pt_so_emit.c @@ -0,0 +1,293 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "draw/draw_context.h" +#include "draw/draw_private.h" +#include "draw/draw_vbuf.h" +#include "draw/draw_vertex.h" +#include "draw/draw_pt.h" + +#include "util/u_math.h" +#include "util/u_memory.h" + +struct pt_so_emit { + struct draw_context *draw; + + void *buffers[PIPE_MAX_SO_BUFFERS]; + + unsigned input_vertex_stride; + const float (*inputs)[4]; + + boolean has_so; + + boolean single_buffer; + + unsigned emitted_primitives; + unsigned emitted_vertices; +}; + + +void draw_pt_so_emit_prepare(struct pt_so_emit *emit) +{ + struct draw_context *draw = emit->draw; + + emit->has_so = (draw->so.state.num_outputs > 0); + + /* if we have a state with outputs make sure we have + * buffers to output to */ + if (emit->has_so) { + boolean has_valid_buffer = FALSE; + unsigned i; + for (i = 0; i < draw->so.num_buffers; ++i) { + if (draw->so.buffers[i]) { + has_valid_buffer = TRUE; + break; + } + } + emit->has_so = has_valid_buffer; + } + + if (!emit->has_so) + return; + + /* XXX: need to flush to get prim_vbuf.c to release its allocation?? + */ + draw_do_flush( draw, DRAW_FLUSH_BACKEND ); +} + +static boolean +is_component_writable(unsigned mask, + unsigned compo) +{ + switch (mask) { + case TGSI_WRITEMASK_NONE: + return FALSE; + case TGSI_WRITEMASK_X: + return compo == 0; + case TGSI_WRITEMASK_Y: + return compo == 1; + case TGSI_WRITEMASK_XY: + return compo == 0 || compo == 1; + case TGSI_WRITEMASK_Z: + return compo == 2; + case TGSI_WRITEMASK_XZ: + return compo == 0 || compo == 2; + case TGSI_WRITEMASK_YZ: + return compo == 1 || compo == 2; + case TGSI_WRITEMASK_XYZ: + return compo == 0 || compo == 1 || compo == 2; + case TGSI_WRITEMASK_W: + return compo == 3; + case TGSI_WRITEMASK_XW: + return compo == 0 || compo == 3; + case TGSI_WRITEMASK_YW: + return compo == 1 || compo == 3; + case TGSI_WRITEMASK_XYW: + return compo == 0 || compo == 1 || compo == 3; + case TGSI_WRITEMASK_ZW: + return compo == 2 || compo == 3; + case TGSI_WRITEMASK_XZW: + return compo == 0 || compo == 1 || compo == 3; + case TGSI_WRITEMASK_YZW: + return compo == 1 || compo == 2 || compo == 4; + case TGSI_WRITEMASK_XYZW: + return compo < 4; + default: + debug_assert(!"Unknown writemask in stream out"); + return compo < 4; + } +} + +static void so_emit_prim(struct pt_so_emit *so, + unsigned *indices, + unsigned num_vertices) +{ + unsigned slot, i; + unsigned input_vertex_stride = so->input_vertex_stride; + struct draw_context *draw = so->draw; + const float (*input_ptr)[4]; + const struct pipe_stream_output_state *state = + &draw->so.state; + float **buffer = 0; + + input_ptr = so->inputs; + + for (i = 0; i < num_vertices; ++i) { + const float (*input)[4]; + unsigned total_written_compos = 0; + /*debug_printf("%d) vertex index = %d (prim idx = %d)\n", i, indices[i], prim_idx);*/ + input = (const float (*)[4])( + (const char *)input_ptr + (indices[i] * input_vertex_stride)); + for (slot = 0; slot < state->num_outputs; ++slot) { + unsigned idx = state->register_index[slot]; + unsigned writemask = state->register_mask[slot]; + unsigned written_compos = 0; + unsigned compo; + + buffer = (float**)&so->buffers[state->output_buffer[slot]]; + + /*debug_printf("\tSlot = %d, vs_slot = %d, idx = %d:\n", + slot, vs_slot, idx);*/ +#if 1 + assert(!util_is_inf_or_nan(input[idx][0])); + assert(!util_is_inf_or_nan(input[idx][1])); + assert(!util_is_inf_or_nan(input[idx][2])); + assert(!util_is_inf_or_nan(input[idx][3])); +#endif + for (compo = 0; compo < 4; ++compo) { + if (is_component_writable(writemask, compo)) { + float *buf = *buffer; + buf[written_compos++] = input[idx][compo]; + } + } +#if 0 + debug_printf("\t\t(writemask = %d)%f %f %f %f\n", + writemask, + input[idx][0], + input[idx][1], + input[idx][2], + input[idx][3]); +#endif + *buffer += written_compos; + total_written_compos += written_compos; + } + if (so->single_buffer) { + int stride = (int)state->stride - + sizeof(float) * total_written_compos; + + debug_assert(stride >= 0); + *buffer = (float*) (((char*)*buffer) + stride); + } + } + so->emitted_vertices += num_vertices; + ++so->emitted_primitives; +} + +static void so_point(struct pt_so_emit *so, int idx) +{ + unsigned indices[1]; + + indices[0] = idx; + + so_emit_prim(so, indices, 1); +} + +static void so_line(struct pt_so_emit *so, int i0, int i1) +{ + unsigned indices[2]; + + indices[0] = i0; + indices[1] = i1; + + so_emit_prim(so, indices, 2); +} + +static void so_tri(struct pt_so_emit *so, int i0, int i1, int i2) +{ + unsigned indices[3]; + + indices[0] = i0; + indices[1] = i1; + indices[2] = i2; + + so_emit_prim(so, indices, 3); +} + + +#define FUNC so_run_linear +#define GET_ELT(idx) (start + (idx)) +#include "draw_so_emit_tmp.h" + + +#define FUNC so_run_elts +#define LOCAL_VARS const ushort *elts = input_prims->elts; +#define GET_ELT(idx) (elts[start + (idx)]) +#include "draw_so_emit_tmp.h" + + +void draw_pt_so_emit( struct pt_so_emit *emit, + const struct draw_vertex_info *input_verts, + const struct draw_prim_info *input_prims ) +{ + struct draw_context *draw = emit->draw; + struct vbuf_render *render = draw->render; + unsigned start, i; + + if (!emit->has_so) + return; + + emit->emitted_vertices = 0; + emit->emitted_primitives = 0; + emit->input_vertex_stride = input_verts->stride; + emit->inputs = (const float (*)[4])input_verts->verts->data; + for (i = 0; i < draw->so.num_buffers; ++i) { + emit->buffers[i] = draw->so.buffers[i]; + } + emit->single_buffer = TRUE; + for (i = 0; i < draw->so.state.num_outputs; ++i) { + if (draw->so.state.output_buffer[i] != 0) + emit->single_buffer = FALSE; + } + + /* XXX: need to flush to get prim_vbuf.c to release its allocation??*/ + draw_do_flush( draw, DRAW_FLUSH_BACKEND ); + + for (start = i = 0; i < input_prims->primitive_count; + start += input_prims->primitive_lengths[i], i++) + { + unsigned count = input_prims->primitive_lengths[i]; + + if (input_prims->linear) { + so_run_linear(emit, input_prims, input_verts, + start, count); + } else { + so_run_elts(emit, input_prims, input_verts, + start, count); + } + } + + render->set_stream_output_info(render, + emit->emitted_primitives, + emit->emitted_vertices); +} + + +struct pt_so_emit *draw_pt_so_emit_create( struct draw_context *draw ) +{ + struct pt_so_emit *emit = CALLOC_STRUCT(pt_so_emit); + if (!emit) + return NULL; + + emit->draw = draw; + + return emit; +} + +void draw_pt_so_emit_destroy( struct pt_so_emit *emit ) +{ + FREE(emit); +} diff --git a/src/gallium/auxiliary/draw/draw_pt_util.c b/src/gallium/auxiliary/draw/draw_pt_util.c new file mode 100644 index 0000000..513bbbe --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pt_util.c @@ -0,0 +1,101 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + +#include "draw/draw_context.h" +#include "draw/draw_private.h" +#include "draw/draw_pt.h" +#include "util/u_debug.h" + +void draw_pt_split_prim(unsigned prim, unsigned *first, unsigned *incr) +{ + switch (prim) { + case PIPE_PRIM_POINTS: + *first = 1; + *incr = 1; + break; + case PIPE_PRIM_LINES: + *first = 2; + *incr = 2; + break; + case PIPE_PRIM_LINE_STRIP: + case PIPE_PRIM_LINE_LOOP: + *first = 2; + *incr = 1; + break; + case PIPE_PRIM_LINES_ADJACENCY: + *first = 4; + *incr = 4; + break; + case PIPE_PRIM_LINE_STRIP_ADJACENCY: + *first = 4; + *incr = 1; + break; + case PIPE_PRIM_TRIANGLES: + *first = 3; + *incr = 3; + break; + case PIPE_PRIM_TRIANGLES_ADJACENCY: + *first = 6; + *incr = 6; + break; + case PIPE_PRIM_TRIANGLE_STRIP: + case PIPE_PRIM_TRIANGLE_FAN: + case PIPE_PRIM_POLYGON: + *first = 3; + *incr = 1; + break; + case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY: + *first = 6; + *incr = 2; + break; + case PIPE_PRIM_QUADS: + *first = 4; + *incr = 4; + break; + case PIPE_PRIM_QUAD_STRIP: + *first = 4; + *incr = 2; + break; + default: + assert(0); + *first = 0; + *incr = 1; /* set to one so that count % incr works */ + break; + } +} + +unsigned draw_pt_trim_count(unsigned count, unsigned first, unsigned incr) +{ + if (count < first) + return 0; + return count - (count - first) % incr; +} diff --git a/src/gallium/auxiliary/draw/draw_pt_vsplit.c b/src/gallium/auxiliary/draw/draw_pt_vsplit.c new file mode 100644 index 0000000..a687525 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pt_vsplit.c @@ -0,0 +1,208 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "draw/draw_context.h" +#include "draw/draw_private.h" +#include "draw/draw_pt.h" + +#define SEGMENT_SIZE 1024 +#define MAP_SIZE 256 + +struct vsplit_frontend { + struct draw_pt_front_end base; + struct draw_context *draw; + + unsigned prim; + + struct draw_pt_middle_end *middle; + + unsigned max_vertices; + ushort segment_size; + + /* buffers for splitting */ + unsigned fetch_elts[SEGMENT_SIZE]; + ushort draw_elts[SEGMENT_SIZE]; + ushort identity_draw_elts[SEGMENT_SIZE]; + + struct { + /* map a fetch element to a draw element */ + unsigned fetches[MAP_SIZE]; + ushort draws[MAP_SIZE]; + boolean has_max_fetch; + + ushort num_fetch_elts; + ushort num_draw_elts; + } cache; +}; + + +static void +vsplit_clear_cache(struct vsplit_frontend *vsplit) +{ + memset(vsplit->cache.fetches, 0xff, sizeof(vsplit->cache.fetches)); + vsplit->cache.has_max_fetch = FALSE; + vsplit->cache.num_fetch_elts = 0; + vsplit->cache.num_draw_elts = 0; +} + +static void +vsplit_flush_cache(struct vsplit_frontend *vsplit, unsigned flags) +{ + vsplit->middle->run(vsplit->middle, + vsplit->fetch_elts, vsplit->cache.num_fetch_elts, + vsplit->draw_elts, vsplit->cache.num_draw_elts, flags); +} + +/** + * Add a fetch element and add it to the draw elements. + */ +static INLINE void +vsplit_add_cache(struct vsplit_frontend *vsplit, unsigned fetch) +{ + unsigned hash = fetch % MAP_SIZE; + + if (vsplit->cache.fetches[hash] != fetch) { + /* update cache */ + vsplit->cache.fetches[hash] = fetch; + vsplit->cache.draws[hash] = vsplit->cache.num_fetch_elts; + + /* add fetch */ + assert(vsplit->cache.num_fetch_elts < vsplit->segment_size); + vsplit->fetch_elts[vsplit->cache.num_fetch_elts++] = fetch; + } + + vsplit->draw_elts[vsplit->cache.num_draw_elts++] = vsplit->cache.draws[hash]; +} + + +/** + * Add a fetch element and add it to the draw elements. The fetch element is + * in full range (uint). + */ +static INLINE void +vsplit_add_cache_uint(struct vsplit_frontend *vsplit, unsigned fetch) +{ + /* special care for 0xffffffff */ + if (fetch == 0xffffffff && !vsplit->cache.has_max_fetch) { + unsigned hash = fetch % MAP_SIZE; + vsplit->cache.fetches[hash] = fetch - 1; /* force update */ + vsplit->cache.has_max_fetch = TRUE; + } + + vsplit_add_cache(vsplit, fetch); +} + + +#define FUNC vsplit_run_linear +#include "draw_pt_vsplit_tmp.h" + +#define FUNC vsplit_run_ubyte +#define ELT_TYPE ubyte +#define ADD_CACHE(vsplit, fetch) vsplit_add_cache(vsplit, fetch) +#include "draw_pt_vsplit_tmp.h" + +#define FUNC vsplit_run_ushort +#define ELT_TYPE ushort +#define ADD_CACHE(vsplit, fetch) vsplit_add_cache(vsplit, fetch) +#include "draw_pt_vsplit_tmp.h" + +#define FUNC vsplit_run_uint +#define ELT_TYPE uint +#define ADD_CACHE(vsplit, fetch) vsplit_add_cache_uint(vsplit, fetch) +#include "draw_pt_vsplit_tmp.h" + + +static void vsplit_prepare(struct draw_pt_front_end *frontend, + unsigned in_prim, + struct draw_pt_middle_end *middle, + unsigned opt) +{ + struct vsplit_frontend *vsplit = (struct vsplit_frontend *) frontend; + + switch (vsplit->draw->pt.user.eltSize) { + case 0: + vsplit->base.run = vsplit_run_linear; + break; + case 1: + vsplit->base.run = vsplit_run_ubyte; + break; + case 2: + vsplit->base.run = vsplit_run_ushort; + break; + case 4: + vsplit->base.run = vsplit_run_uint; + break; + default: + assert(0); + break; + } + + /* split only */ + vsplit->prim = in_prim; + + vsplit->middle = middle; + middle->prepare(middle, vsplit->prim, opt, &vsplit->max_vertices); + + vsplit->segment_size = MIN2(SEGMENT_SIZE, vsplit->max_vertices); +} + + +static void vsplit_finish(struct draw_pt_front_end *frontend) +{ + struct vsplit_frontend *vsplit = (struct vsplit_frontend *) frontend; + vsplit->middle->finish(vsplit->middle); + vsplit->middle = NULL; +} + + +static void vsplit_destroy(struct draw_pt_front_end *frontend) +{ + FREE(frontend); +} + + +struct draw_pt_front_end *draw_pt_vsplit(struct draw_context *draw) +{ + struct vsplit_frontend *vsplit = CALLOC_STRUCT(vsplit_frontend); + ushort i; + + if (!vsplit) + return NULL; + + vsplit->base.prepare = vsplit_prepare; + vsplit->base.run = NULL; + vsplit->base.finish = vsplit_finish; + vsplit->base.destroy = vsplit_destroy; + vsplit->draw = draw; + + for (i = 0; i < SEGMENT_SIZE; i++) + vsplit->identity_draw_elts[i] = i; + + return &vsplit->base; +} diff --git a/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h b/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h new file mode 100644 index 0000000..75dba8c --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h @@ -0,0 +1,310 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#define CONCAT2(name, elt_type) name ## elt_type +#define CONCAT(name, elt_type) CONCAT2(name, elt_type) + +#ifdef ELT_TYPE + +/** + * Fetch all elements in [min_index, max_index] with bias, and use the + * (rebased) index buffer as the draw elements. + */ +static boolean +CONCAT(vsplit_primitive_, ELT_TYPE)(struct vsplit_frontend *vsplit, + unsigned istart, unsigned icount) +{ + struct draw_context *draw = vsplit->draw; + const ELT_TYPE *ib = (const ELT_TYPE *) + ((const char *) draw->pt.user.elts + draw->pt.index_buffer.offset); + const unsigned min_index = draw->pt.user.min_index; + const unsigned max_index = draw->pt.user.max_index; + const int elt_bias = draw->pt.user.eltBias; + unsigned fetch_start, fetch_count; + const ushort *draw_elts = NULL; + unsigned i; + + /* use the ib directly */ + if (min_index == 0 && sizeof(ib[0]) == sizeof(draw_elts[0])) { + if (icount > vsplit->max_vertices) + return FALSE; + + for (i = 0; i < icount; i++) { + ELT_TYPE idx = ib[istart + i]; + assert(idx >= min_index && idx <= max_index); + } + draw_elts = (const ushort *) ib; + } + else { + /* have to go through vsplit->draw_elts */ + if (icount > vsplit->segment_size) + return FALSE; + } + + /* this is faster only when we fetch less elements than the normal path */ + if (max_index - min_index > icount - 1) + return FALSE; + + if (elt_bias < 0 && min_index < -elt_bias) + return FALSE; + + /* why this check? */ + for (i = 0; i < draw->pt.nr_vertex_elements; i++) { + if (draw->pt.vertex_element[i].instance_divisor) + return FALSE; + } + + fetch_start = min_index + elt_bias; + fetch_count = max_index - min_index + 1; + + if (!draw_elts) { + if (min_index == 0) { + for (i = 0; i < icount; i++) { + ELT_TYPE idx = ib[istart + i]; + + assert(idx >= min_index && idx <= max_index); + vsplit->draw_elts[i] = (ushort) idx; + } + } + else { + for (i = 0; i < icount; i++) { + ELT_TYPE idx = ib[istart + i]; + + assert(idx >= min_index && idx <= max_index); + vsplit->draw_elts[i] = (ushort) (idx - min_index); + } + } + + draw_elts = vsplit->draw_elts; + } + + return vsplit->middle->run_linear_elts(vsplit->middle, + fetch_start, fetch_count, + draw_elts, icount, 0x0); +} + +/** + * Use the cache to prepare the fetch and draw elements, and flush. + * + * When spoken is TRUE, ispoken replaces istart; When close is TRUE, iclose is + * appended. + */ +static INLINE void +CONCAT(vsplit_segment_cache_, ELT_TYPE)(struct vsplit_frontend *vsplit, + unsigned flags, + unsigned istart, unsigned icount, + boolean spoken, unsigned ispoken, + boolean close, unsigned iclose) +{ + struct draw_context *draw = vsplit->draw; + const ELT_TYPE *ib = (const ELT_TYPE *) + ((const char *) draw->pt.user.elts + draw->pt.index_buffer.offset); + const int ibias = draw->pt.user.eltBias; + unsigned i; + + assert(icount + !!close <= vsplit->segment_size); + + vsplit_clear_cache(vsplit); + + spoken = !!spoken; + if (ibias == 0) { + if (spoken) + ADD_CACHE(vsplit, ib[ispoken]); + + for (i = spoken; i < icount; i++) + ADD_CACHE(vsplit, ib[istart + i]); + + if (close) + ADD_CACHE(vsplit, ib[iclose]); + } + else if (ibias > 0) { + if (spoken) + ADD_CACHE(vsplit, (uint) ib[ispoken] + ibias); + + for (i = spoken; i < icount; i++) + ADD_CACHE(vsplit, (uint) ib[istart + i] + ibias); + + if (close) + ADD_CACHE(vsplit, (uint) ib[iclose] + ibias); + } + else { + if (spoken) { + if (ib[ispoken] < -ibias) + return; + ADD_CACHE(vsplit, ib[ispoken] + ibias); + } + + for (i = spoken; i < icount; i++) { + if (ib[istart + i] < -ibias) + return; + ADD_CACHE(vsplit, ib[istart + i] + ibias); + } + + if (close) { + if (ib[iclose] < -ibias) + return; + ADD_CACHE(vsplit, ib[iclose] + ibias); + } + } + + vsplit_flush_cache(vsplit, flags); +} + +static void +CONCAT(vsplit_segment_simple_, ELT_TYPE)(struct vsplit_frontend *vsplit, + unsigned flags, + unsigned istart, + unsigned icount) +{ + CONCAT(vsplit_segment_cache_, ELT_TYPE)(vsplit, + flags, istart, icount, FALSE, 0, FALSE, 0); +} + +static void +CONCAT(vsplit_segment_loop_, ELT_TYPE)(struct vsplit_frontend *vsplit, + unsigned flags, + unsigned istart, + unsigned icount, + unsigned i0) +{ + const boolean close_loop = ((flags) == DRAW_SPLIT_BEFORE); + + CONCAT(vsplit_segment_cache_, ELT_TYPE)(vsplit, + flags, istart, icount, FALSE, 0, close_loop, i0); +} + +static void +CONCAT(vsplit_segment_fan_, ELT_TYPE)(struct vsplit_frontend *vsplit, + unsigned flags, + unsigned istart, + unsigned icount, + unsigned i0) +{ + const boolean use_spoken = (((flags) & DRAW_SPLIT_BEFORE) != 0); + + CONCAT(vsplit_segment_cache_, ELT_TYPE)(vsplit, + flags, istart, icount, use_spoken, i0, FALSE, 0); +} + +#define LOCAL_VARS \ + struct vsplit_frontend *vsplit = (struct vsplit_frontend *) frontend; \ + const unsigned prim = vsplit->prim; \ + const unsigned max_count_simple = vsplit->segment_size; \ + const unsigned max_count_loop = vsplit->segment_size - 1; \ + const unsigned max_count_fan = vsplit->segment_size; + +#define PRIMITIVE(istart, icount) \ + CONCAT(vsplit_primitive_, ELT_TYPE)(vsplit, istart, icount) + +#else /* ELT_TYPE */ + +static void +vsplit_segment_simple_linear(struct vsplit_frontend *vsplit, unsigned flags, + unsigned istart, unsigned icount) +{ + assert(icount <= vsplit->max_vertices); + vsplit->middle->run_linear(vsplit->middle, istart, icount, flags); +} + +static void +vsplit_segment_loop_linear(struct vsplit_frontend *vsplit, unsigned flags, + unsigned istart, unsigned icount, unsigned i0) +{ + boolean close_loop = (flags == DRAW_SPLIT_BEFORE); + unsigned nr; + + assert(icount + !!close_loop <= vsplit->segment_size); + + if (close_loop) { + for (nr = 0; nr < icount; nr++) + vsplit->fetch_elts[nr] = istart + nr; + vsplit->fetch_elts[nr++] = i0; + + vsplit->middle->run(vsplit->middle, vsplit->fetch_elts, nr, + vsplit->identity_draw_elts, nr, flags); + } + else { + vsplit->middle->run_linear(vsplit->middle, istart, icount, flags); + } +} + +static void +vsplit_segment_fan_linear(struct vsplit_frontend *vsplit, unsigned flags, + unsigned istart, unsigned icount, unsigned i0) +{ + boolean use_spoken = ((flags & DRAW_SPLIT_BEFORE) != 0); + unsigned nr = 0, i; + + assert(icount <= vsplit->segment_size); + + if (use_spoken) { + /* replace istart by i0 */ + vsplit->fetch_elts[nr++] = i0; + for (i = 1 ; i < icount; i++) + vsplit->fetch_elts[nr++] = istart + i; + + vsplit->middle->run(vsplit->middle, vsplit->fetch_elts, nr, + vsplit->identity_draw_elts, nr, flags); + } + else { + vsplit->middle->run_linear(vsplit->middle, istart, icount, flags); + } +} + +#define LOCAL_VARS \ + struct vsplit_frontend *vsplit = (struct vsplit_frontend *) frontend; \ + const unsigned prim = vsplit->prim; \ + const unsigned max_count_simple = vsplit->max_vertices; \ + const unsigned max_count_loop = vsplit->segment_size - 1; \ + const unsigned max_count_fan = vsplit->segment_size; + +#define PRIMITIVE(istart, icount) FALSE + +#define ELT_TYPE linear + +#endif /* ELT_TYPE */ + +#define FUNC_VARS \ + struct draw_pt_front_end *frontend, \ + unsigned start, \ + unsigned count + +#define SEGMENT_SIMPLE(flags, istart, icount) \ + CONCAT(vsplit_segment_simple_, ELT_TYPE)(vsplit, flags, istart, icount) + +#define SEGMENT_LOOP(flags, istart, icount, i0) \ + CONCAT(vsplit_segment_loop_, ELT_TYPE)(vsplit, flags, istart, icount, i0) + +#define SEGMENT_FAN(flags, istart, icount, i0) \ + CONCAT(vsplit_segment_fan_, ELT_TYPE)(vsplit, flags, istart, icount, i0) + +#include "draw_split_tmp.h" + +#undef CONCAT2 +#undef CONCAT + +#undef ELT_TYPE +#undef ADD_CACHE diff --git a/src/gallium/auxiliary/draw/draw_so_emit_tmp.h b/src/gallium/auxiliary/draw/draw_so_emit_tmp.h new file mode 100644 index 0000000..7fafde9 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_so_emit_tmp.h @@ -0,0 +1,31 @@ +#define FUNC_VARS \ + struct pt_so_emit *so, \ + const struct draw_prim_info *input_prims, \ + const struct draw_vertex_info *input_verts, \ + unsigned start, \ + unsigned count + +#define FUNC_ENTER \ + /* declare more local vars */ \ + const unsigned prim = input_prims->prim; \ + const unsigned prim_flags = input_prims->flags; \ + const boolean last_vertex_last = TRUE; \ + do { \ + debug_assert(input_prims->primitive_count == 1); \ + switch (prim) { \ + case PIPE_PRIM_LINES_ADJACENCY: \ + case PIPE_PRIM_LINE_STRIP_ADJACENCY: \ + case PIPE_PRIM_TRIANGLES_ADJACENCY: \ + case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY: \ + debug_assert(!"unexpected primitive type in stream output"); \ + return; \ + default: \ + break; \ + } \ + } while (0) \ + +#define POINT(i0) so_point(so,i0) +#define LINE(flags,i0,i1) so_line(so,i0,i1) +#define TRIANGLE(flags,i0,i1,i2) so_tri(so,i0,i1,i2) + +#include "draw_decompose_tmp.h" diff --git a/src/gallium/auxiliary/draw/draw_split_tmp.h b/src/gallium/auxiliary/draw/draw_split_tmp.h new file mode 100644 index 0000000..47defc6 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_split_tmp.h @@ -0,0 +1,176 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +static void +FUNC(FUNC_VARS) +{ + unsigned first, incr; + LOCAL_VARS + + /* + * prim, start, count, and max_count_{simple,loop,fan} should have been + * defined + */ + if (0) { + debug_printf("%s: prim 0x%x, start %d, count %d, max_count_simple %d, " + "max_count_loop %d, max_count_fan %d\n", + __FUNCTION__, prim, start, count, max_count_simple, + max_count_loop, max_count_fan); + } + + draw_pt_split_prim(prim, &first, &incr); + /* sanitize primitive length */ + count = draw_pt_trim_count(count, first, incr); + if (count < first) + return; + + /* try flushing the entire primitive */ + if (PRIMITIVE(start, count)) + return; + + /* must be able to at least flush two complete primitives */ + assert(max_count_simple >= first + incr && + max_count_loop >= first + incr && + max_count_fan >= first + incr); + + /* no splitting required */ + if (count <= max_count_simple) { + SEGMENT_SIMPLE(0x0, start, count); + } + else { + const unsigned rollback = first - incr; + unsigned flags = DRAW_SPLIT_AFTER, seg_start = 0, seg_max; + + /* + * Both count and seg_max below are explicitly trimmed. Because + * + * seg_start = N * (seg_max - rollback) = N' * incr, + * + * we have + * + * remaining = count - seg_start = first + N'' * incr. + * + * That is, remaining is implicitly trimmed. + */ + switch (prim) { + case PIPE_PRIM_POINTS: + case PIPE_PRIM_LINES: + case PIPE_PRIM_LINE_STRIP: + case PIPE_PRIM_TRIANGLES: + case PIPE_PRIM_TRIANGLE_STRIP: + case PIPE_PRIM_QUADS: + case PIPE_PRIM_QUAD_STRIP: + case PIPE_PRIM_LINES_ADJACENCY: + case PIPE_PRIM_LINE_STRIP_ADJACENCY: + case PIPE_PRIM_TRIANGLES_ADJACENCY: + case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY: + seg_max = + draw_pt_trim_count(MIN2(max_count_simple, count), first, incr); + if (prim == PIPE_PRIM_TRIANGLE_STRIP || + prim == PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY) { + /* make sure we flush even number of triangles at a time */ + if (seg_max < count && !(((seg_max - first) / incr) & 1)) + seg_max -= incr; + } + + do { + const unsigned remaining = count - seg_start; + + if (remaining > seg_max) { + SEGMENT_SIMPLE(flags, start + seg_start, seg_max); + seg_start += seg_max - rollback; + + flags |= DRAW_SPLIT_BEFORE; + } + else { + flags &= ~DRAW_SPLIT_AFTER; + + SEGMENT_SIMPLE(flags, start + seg_start, remaining); + seg_start += remaining; + } + } while (seg_start < count); + break; + + case PIPE_PRIM_LINE_LOOP: + seg_max = + draw_pt_trim_count(MIN2(max_count_loop, count), first, incr); + + do { + const unsigned remaining = count - seg_start; + + if (remaining > seg_max) { + SEGMENT_LOOP(flags, start + seg_start, seg_max, start); + seg_start += seg_max - rollback; + + flags |= DRAW_SPLIT_BEFORE; + } + else { + flags &= ~DRAW_SPLIT_AFTER; + + SEGMENT_LOOP(flags, start + seg_start, remaining, start); + seg_start += remaining; + } + } while (seg_start < count); + break; + + case PIPE_PRIM_TRIANGLE_FAN: + case PIPE_PRIM_POLYGON: + seg_max = + draw_pt_trim_count(MIN2(max_count_fan, count), first, incr); + + do { + const unsigned remaining = count - seg_start; + + if (remaining > seg_max) { + SEGMENT_FAN(flags, start + seg_start, seg_max, start); + seg_start += seg_max - rollback; + + flags |= DRAW_SPLIT_BEFORE; + } + else { + flags &= ~DRAW_SPLIT_AFTER; + + SEGMENT_FAN(flags, start + seg_start, remaining, start); + seg_start += remaining; + } + } while (seg_start < count); + break; + + default: + assert(0); + break; + } + } +} + +#undef FUNC +#undef FUNC_VARS +#undef LOCAL_VARS + +#undef PRIMITIVE +#undef SEGMENT_SIMPLE +#undef SEGMENT_LOOP +#undef SEGMENT_FAN diff --git a/src/gallium/auxiliary/draw/draw_vbuf.h b/src/gallium/auxiliary/draw/draw_vbuf.h new file mode 100644 index 0000000..e32803c --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_vbuf.h @@ -0,0 +1,137 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \file + * Vertex buffer drawing stage. + * + * \author Keith Whitwell + * \author Jose Fonseca + */ + +#ifndef DRAW_VBUF_H_ +#define DRAW_VBUF_H_ + + +#include "pipe/p_compiler.h" + + +struct pipe_rasterizer_state; +struct draw_context; +struct vertex_info; + + +/** + * Interface for hardware vertex buffer rendering. + */ +struct vbuf_render { + + /** + * Driver limits. May be tuned lower to improve cache hits on + * index list. + */ + unsigned max_indices; + unsigned max_vertex_buffer_bytes; + + /** + * Query if the hardware driver needs assistance for a particular + * combination of rasterizer state and primitive. + * + * Currently optional. + */ + boolean (*need_pipeline)(const struct vbuf_render *render, + const struct pipe_rasterizer_state *rasterizer, + unsigned int prim ); + + + /** + * Get the hardware vertex format. + * + * XXX: have this in draw_context instead? + */ + const struct vertex_info *(*get_vertex_info)( struct vbuf_render * ); + + /** + * Request a destination for vertices. + * Hardware renderers will use ttm memory, others will just malloc + * something. + */ + boolean (*allocate_vertices)( struct vbuf_render *, + ushort vertex_size, + ushort nr_vertices ); + + void *(*map_vertices)( struct vbuf_render * ); + void (*unmap_vertices)( struct vbuf_render *, + ushort min_index, + ushort max_index ); + + /** + * Notify the renderer of the current primitive when it changes. + * Must succeed for TRIANGLES, LINES and POINTS. Other prims at + * the discretion of the driver, for the benefit of the passthrough + * path. + */ + boolean (*set_primitive)( struct vbuf_render *, unsigned prim ); + + /** + * Draw indexed primitives. Note that indices are ushort. The driver + * must complete this call, if necessary splitting the index list itself. + */ + void (*draw_elements)( struct vbuf_render *, + const ushort *indices, + uint nr_indices ); + + /* Draw non-indexed primitives. + */ + void (*draw_arrays)( struct vbuf_render *, + unsigned start, + uint nr ); + + /** + * Called when vbuf is done with this set of vertices: + */ + void (*release_vertices)( struct vbuf_render * ); + + void (*destroy)( struct vbuf_render * ); + + + /** + * Called after writing data to the stream out buffers + */ + void (*set_stream_output_info)( struct vbuf_render *vbufr, + unsigned primitive_count, + unsigned vertices_count ); +}; + + + +struct draw_stage * +draw_vbuf_stage( struct draw_context *draw, + struct vbuf_render *render ); + + +#endif /*DRAW_VBUF_H_*/ diff --git a/src/gallium/auxiliary/draw/draw_vertex.c b/src/gallium/auxiliary/draw/draw_vertex.c new file mode 100644 index 0000000..a4f5e88 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_vertex.c @@ -0,0 +1,118 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* + * Functions for specifying the post-transformation vertex layout. + * + * Author: + * Brian Paul + * Keith Whitwell + */ + + +#include "draw/draw_private.h" +#include "draw/draw_vertex.h" + + +/** + * Compute the size of a vertex, in dwords/floats, to update the + * vinfo->size field. + */ +void +draw_compute_vertex_size(struct vertex_info *vinfo) +{ + uint i; + + vinfo->size = 0; + for (i = 0; i < vinfo->num_attribs; i++) + vinfo->size += draw_translate_vinfo_size(vinfo->attrib[i].emit); + + assert(vinfo->size % 4 == 0); + /* in dwords */ + vinfo->size /= 4; +} + + +void +draw_dump_emitted_vertex(const struct vertex_info *vinfo, const uint8_t *data) +{ + unsigned i, j; + + for (i = 0; i < vinfo->num_attribs; i++) { + j = vinfo->attrib[i].src_index; + switch (vinfo->attrib[i].emit) { + case EMIT_OMIT: + debug_printf("EMIT_OMIT:"); + break; + case EMIT_1F: + debug_printf("EMIT_1F:\t"); + debug_printf("%f ", *(float *)data); data += sizeof(float); + break; + case EMIT_1F_PSIZE: + debug_printf("EMIT_1F_PSIZE:\t"); + debug_printf("%f ", *(float *)data); data += sizeof(float); + break; + case EMIT_2F: + debug_printf("EMIT_2F:\t"); + debug_printf("%f ", *(float *)data); data += sizeof(float); + debug_printf("%f ", *(float *)data); data += sizeof(float); + break; + case EMIT_3F: + debug_printf("EMIT_3F:\t"); + debug_printf("%f ", *(float *)data); data += sizeof(float); + debug_printf("%f ", *(float *)data); data += sizeof(float); + debug_printf("%f ", *(float *)data); data += sizeof(float); + data += sizeof(float); + break; + case EMIT_4F: + debug_printf("EMIT_4F:\t"); + debug_printf("%f ", *(float *)data); data += sizeof(float); + debug_printf("%f ", *(float *)data); data += sizeof(float); + debug_printf("%f ", *(float *)data); data += sizeof(float); + debug_printf("%f ", *(float *)data); data += sizeof(float); + break; + case EMIT_4UB: + debug_printf("EMIT_4UB:\t"); + debug_printf("%u ", *data++); + debug_printf("%u ", *data++); + debug_printf("%u ", *data++); + debug_printf("%u ", *data++); + break; + case EMIT_4UB_BGRA: + debug_printf("EMIT_4UB_BGRA:\t"); + debug_printf("%u ", *data++); + debug_printf("%u ", *data++); + debug_printf("%u ", *data++); + debug_printf("%u ", *data++); + break; + default: + assert(0); + } + debug_printf("\n"); + } + debug_printf("\n"); +} diff --git a/src/gallium/auxiliary/draw/draw_vertex.h b/src/gallium/auxiliary/draw/draw_vertex.h new file mode 100644 index 0000000..e63cf5f --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_vertex.h @@ -0,0 +1,193 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Post-transform vertex format info. The vertex_info struct is used by + * the draw_vbuf code to emit hardware-specific vertex layouts into hw + * vertex buffers. + * + * Author: + * Brian Paul + */ + + +#ifndef DRAW_VERTEX_H +#define DRAW_VERTEX_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "util/u_debug.h" + + +/** + * Vertex attribute emit modes + */ +enum attrib_emit { + EMIT_OMIT, /**< don't emit the attribute */ + EMIT_1F, + EMIT_1F_PSIZE, /**< insert constant point size */ + EMIT_2F, + EMIT_3F, + EMIT_4F, + EMIT_4UB, /**< is RGBA like the rest */ + EMIT_4UB_BGRA +}; + + +/** + * Attribute interpolation mode + */ +enum interp_mode { + INTERP_NONE, /**< never interpolate vertex header info */ + INTERP_POS, /**< special case for frag position */ + INTERP_CONSTANT, + INTERP_LINEAR, + INTERP_PERSPECTIVE +}; + + +/** + * Information about hardware/rasterization vertex layout. + */ +struct vertex_info +{ + uint num_attribs; + uint hwfmt[4]; /**< hardware format info for this format */ + uint size; /**< total vertex size in dwords */ + + /* Keep this small and at the end of the struct to allow quick + * memcmp() comparisons. + */ + struct { + unsigned interp_mode:4; /**< INTERP_x */ + unsigned emit:4; /**< EMIT_x */ + unsigned src_index:8; /**< map to post-xform attribs */ + } attrib[PIPE_MAX_SHADER_INPUTS]; +}; + +static INLINE size_t +draw_vinfo_size( const struct vertex_info *a ) +{ + return offsetof(const struct vertex_info, attrib[a->num_attribs]); +} + +static INLINE int +draw_vinfo_compare( const struct vertex_info *a, + const struct vertex_info *b ) +{ + size_t sizea = draw_vinfo_size( a ); + return memcmp( a, b, sizea ); +} + +static INLINE void +draw_vinfo_copy( struct vertex_info *dst, + const struct vertex_info *src ) +{ + size_t size = draw_vinfo_size( src ); + memcpy( dst, src, size ); +} + + + +/** + * Add another attribute to the given vertex_info object. + * \param src_index indicates which post-transformed vertex attrib slot + * corresponds to this attribute. + * \return slot in which the attribute was added + */ +static INLINE uint +draw_emit_vertex_attr(struct vertex_info *vinfo, + enum attrib_emit emit, + enum interp_mode interp, /* only used by softpipe??? */ + uint src_index) +{ + const uint n = vinfo->num_attribs; + assert(n < PIPE_MAX_SHADER_INPUTS); + vinfo->attrib[n].emit = emit; + vinfo->attrib[n].interp_mode = interp; + vinfo->attrib[n].src_index = src_index; + vinfo->num_attribs++; + return n; +} + + +extern void draw_compute_vertex_size(struct vertex_info *vinfo); + +void draw_dump_emitted_vertex(const struct vertex_info *vinfo, + const uint8_t *data); + + +static INLINE enum pipe_format draw_translate_vinfo_format(enum attrib_emit emit) +{ + switch (emit) { + case EMIT_OMIT: + return PIPE_FORMAT_NONE; + case EMIT_1F: + case EMIT_1F_PSIZE: + return PIPE_FORMAT_R32_FLOAT; + case EMIT_2F: + return PIPE_FORMAT_R32G32_FLOAT; + case EMIT_3F: + return PIPE_FORMAT_R32G32B32_FLOAT; + case EMIT_4F: + return PIPE_FORMAT_R32G32B32A32_FLOAT; + case EMIT_4UB: + return PIPE_FORMAT_R8G8B8A8_UNORM; + case EMIT_4UB_BGRA: + return PIPE_FORMAT_B8G8R8A8_UNORM; + default: + assert(!"unexpected format"); + return PIPE_FORMAT_NONE; + } +} + +static INLINE unsigned draw_translate_vinfo_size(enum attrib_emit emit) +{ + switch (emit) { + case EMIT_OMIT: + return 0; + case EMIT_1F: + case EMIT_1F_PSIZE: + return 1 * sizeof(float); + case EMIT_2F: + return 2 * sizeof(float); + case EMIT_3F: + return 3 * sizeof(float); + case EMIT_4F: + return 4 * sizeof(float); + case EMIT_4UB: + return 4 * sizeof(unsigned char); + case EMIT_4UB_BGRA: + return 4 * sizeof(unsigned char); + default: + assert(!"unexpected format"); + return 0; + } +} + +#endif /* DRAW_VERTEX_H */ diff --git a/src/gallium/auxiliary/draw/draw_vs.c b/src/gallium/auxiliary/draw/draw_vs.c new file mode 100644 index 0000000..fb665b0 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_vs.c @@ -0,0 +1,291 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + * Brian Paul + */ + +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "pipe/p_shader_tokens.h" + +#include "draw_private.h" +#include "draw_context.h" +#include "draw_vs.h" + +#include "translate/translate.h" +#include "translate/translate_cache.h" + +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_exec.h" + +DEBUG_GET_ONCE_BOOL_OPTION(gallium_dump_vs, "GALLIUM_DUMP_VS", FALSE) + + +/** + * Set a vertex shader constant buffer. + * \param slot which constant buffer in [0, PIPE_MAX_CONSTANT_BUFFERS-1] + * \param constants the mapped buffer + * \param size size of buffer in bytes + */ +void +draw_vs_set_constants(struct draw_context *draw, + unsigned slot, + const void *constants, + unsigned size) +{ + const int alignment = 16; + + /* check if buffer is 16-byte aligned */ + if (((uintptr_t)constants) & (alignment - 1)) { + /* if not, copy the constants into a new, 16-byte aligned buffer */ + if (size > draw->vs.const_storage_size[slot]) { + if (draw->vs.aligned_constant_storage[slot]) { + align_free((void *)draw->vs.aligned_constant_storage[slot]); + } + draw->vs.aligned_constant_storage[slot] = + align_malloc(size, alignment); + } + assert(constants); + memcpy((void *)draw->vs.aligned_constant_storage[slot], + constants, + size); + constants = draw->vs.aligned_constant_storage[slot]; + } + + draw->vs.aligned_constants[slot] = constants; + draw_vs_aos_machine_constants(draw->vs.aos_machine, slot, constants); +} + + +void draw_vs_set_viewport( struct draw_context *draw, + const struct pipe_viewport_state *viewport ) +{ + draw_vs_aos_machine_viewport( draw->vs.aos_machine, viewport ); +} + + + +struct draw_vertex_shader * +draw_create_vertex_shader(struct draw_context *draw, + const struct pipe_shader_state *shader) +{ + struct draw_vertex_shader *vs = NULL; + + if (draw->dump_vs) { + tgsi_dump(shader->tokens, 0); + } + + if (!draw->pt.middle.llvm) { +#if defined(PIPE_ARCH_X86) + vs = draw_create_vs_sse( draw, shader ); +#elif defined(PIPE_ARCH_PPC) + vs = draw_create_vs_ppc( draw, shader ); +#endif + } +#if HAVE_LLVM + else { + vs = draw_create_vs_llvm(draw, shader); + } +#endif + + if (!vs) { + vs = draw_create_vs_exec( draw, shader ); + } + + if (vs) + { + uint i; + for (i = 0; i < vs->info.num_outputs; i++) { + if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_POSITION && + vs->info.output_semantic_index[i] == 0) + vs->position_output = i; + else if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_EDGEFLAG && + vs->info.output_semantic_index[i] == 0) + vs->edgeflag_output = i; + } + } + + assert(vs); + return vs; +} + + +void +draw_bind_vertex_shader(struct draw_context *draw, + struct draw_vertex_shader *dvs) +{ + draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE ); + + if (dvs) + { + draw->vs.vertex_shader = dvs; + draw->vs.num_vs_outputs = dvs->info.num_outputs; + draw->vs.position_output = dvs->position_output; + draw->vs.edgeflag_output = dvs->edgeflag_output; + dvs->prepare( dvs, draw ); + } + else { + draw->vs.vertex_shader = NULL; + draw->vs.num_vs_outputs = 0; + } +} + + +void +draw_delete_vertex_shader(struct draw_context *draw, + struct draw_vertex_shader *dvs) +{ + unsigned i; + + for (i = 0; i < dvs->nr_varients; i++) + dvs->varient[i]->destroy( dvs->varient[i] ); + + dvs->nr_varients = 0; + + dvs->delete( dvs ); +} + + + +boolean +draw_vs_init( struct draw_context *draw ) +{ + draw->dump_vs = debug_get_option_gallium_dump_vs(); + + draw->vs.machine = tgsi_exec_machine_create(); + if (!draw->vs.machine) + return FALSE; + + draw->vs.emit_cache = translate_cache_create(); + if (!draw->vs.emit_cache) + return FALSE; + + draw->vs.fetch_cache = translate_cache_create(); + if (!draw->vs.fetch_cache) + return FALSE; + + draw->vs.aos_machine = draw_vs_aos_machine(); +#ifdef PIPE_ARCH_X86 + if (!draw->vs.aos_machine) + return FALSE; +#endif + + return TRUE; +} + +void +draw_vs_destroy( struct draw_context *draw ) +{ + uint i; + + if (draw->vs.fetch_cache) + translate_cache_destroy(draw->vs.fetch_cache); + + if (draw->vs.emit_cache) + translate_cache_destroy(draw->vs.emit_cache); + + if (draw->vs.aos_machine) + draw_vs_aos_machine_destroy(draw->vs.aos_machine); + + for (i = 0; i < PIPE_MAX_CONSTANT_BUFFERS; i++) { + if (draw->vs.aligned_constant_storage[i]) { + align_free((void *)draw->vs.aligned_constant_storage[i]); + } + } + + tgsi_exec_machine_destroy(draw->vs.machine); +} + + +struct draw_vs_varient * +draw_vs_lookup_varient( struct draw_vertex_shader *vs, + const struct draw_vs_varient_key *key ) +{ + struct draw_vs_varient *varient; + unsigned i; + + /* Lookup existing varient: + */ + for (i = 0; i < vs->nr_varients; i++) + if (draw_vs_varient_key_compare(key, &vs->varient[i]->key) == 0) + return vs->varient[i]; + + /* Else have to create a new one: + */ + varient = vs->create_varient( vs, key ); + if (varient == NULL) + return NULL; + + /* Add it to our list, could be smarter: + */ + if (vs->nr_varients < Elements(vs->varient)) { + vs->varient[vs->nr_varients++] = varient; + } + else { + vs->last_varient++; + vs->last_varient %= Elements(vs->varient); + vs->varient[vs->last_varient]->destroy(vs->varient[vs->last_varient]); + vs->varient[vs->last_varient] = varient; + } + + /* Done + */ + return varient; +} + + +struct translate * +draw_vs_get_fetch( struct draw_context *draw, + struct translate_key *key ) +{ + if (!draw->vs.fetch || + translate_key_compare(&draw->vs.fetch->key, key) != 0) + { + translate_key_sanitize(key); + draw->vs.fetch = translate_cache_find(draw->vs.fetch_cache, key); + } + + return draw->vs.fetch; +} + +struct translate * +draw_vs_get_emit( struct draw_context *draw, + struct translate_key *key ) +{ + if (!draw->vs.emit || + translate_key_compare(&draw->vs.emit->key, key) != 0) + { + translate_key_sanitize(key); + draw->vs.emit = translate_cache_find(draw->vs.emit_cache, key); + } + + return draw->vs.emit; +} diff --git a/src/gallium/auxiliary/draw/draw_vs.h b/src/gallium/auxiliary/draw/draw_vs.h new file mode 100644 index 0000000..f9a0387 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_vs.h @@ -0,0 +1,232 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef DRAW_VS_H +#define DRAW_VS_H + +#include "draw_context.h" +#include "draw_private.h" + + +struct draw_context; +struct pipe_shader_state; + +struct draw_varient_input +{ + enum pipe_format format; + unsigned buffer; + unsigned offset; + unsigned instance_divisor; +}; + +struct draw_varient_output +{ + enum pipe_format format; /* output format */ + unsigned vs_output:8; /* which vertex shader output is this? */ + unsigned offset:24; /* offset into output vertex */ +}; + +struct draw_varient_element { + struct draw_varient_input in; + struct draw_varient_output out; +}; + +struct draw_vs_varient_key { + unsigned output_stride; + unsigned nr_elements:8; /* max2(nr_inputs, nr_outputs) */ + unsigned nr_inputs:8; + unsigned nr_outputs:8; + unsigned viewport:1; + unsigned clip:1; + unsigned const_vbuffers:5; + struct draw_varient_element element[PIPE_MAX_ATTRIBS]; +}; + +struct draw_vs_varient; + + +struct draw_vs_varient { + struct draw_vs_varient_key key; + + struct draw_vertex_shader *vs; + + void (*set_buffer)( struct draw_vs_varient *, + unsigned i, + const void *ptr, + unsigned stride, + unsigned max_stride ); + + void (PIPE_CDECL *run_linear)( struct draw_vs_varient *shader, + unsigned start, + unsigned count, + void *output_buffer ); + + void (PIPE_CDECL *run_elts)( struct draw_vs_varient *shader, + const unsigned *elts, + unsigned count, + void *output_buffer ); + + void (*destroy)( struct draw_vs_varient * ); +}; + + +/** + * Private version of the compiled vertex_shader + */ +struct draw_vertex_shader { + struct draw_context *draw; + + /* This member will disappear shortly: + */ + struct pipe_shader_state state; + + struct tgsi_shader_info info; + unsigned position_output; + unsigned edgeflag_output; + + /* Extracted from shader: + */ + const float (*immediates)[4]; + + /* + */ + struct draw_vs_varient *varient[16]; + unsigned nr_varients; + unsigned last_varient; + struct draw_vs_varient *(*create_varient)( struct draw_vertex_shader *shader, + const struct draw_vs_varient_key *key ); + + + void (*prepare)( struct draw_vertex_shader *shader, + struct draw_context *draw ); + + /* Run the shader - this interface will get cleaned up in the + * future: + */ + void (*run_linear)( struct draw_vertex_shader *shader, + const float (*input)[4], + float (*output)[4], + const void *constants[PIPE_MAX_CONSTANT_BUFFERS], + const unsigned const_size[PIPE_MAX_CONSTANT_BUFFERS], + unsigned count, + unsigned input_stride, + unsigned output_stride ); + + + void (*delete)( struct draw_vertex_shader * ); +}; + + +struct draw_vs_varient * +draw_vs_lookup_varient( struct draw_vertex_shader *base, + const struct draw_vs_varient_key *key ); + + +/******************************************************************************** + * Internal functions: + */ + +struct draw_vertex_shader * +draw_create_vs_exec(struct draw_context *draw, + const struct pipe_shader_state *templ); + +struct draw_vertex_shader * +draw_create_vs_sse(struct draw_context *draw, + const struct pipe_shader_state *templ); + +struct draw_vertex_shader * +draw_create_vs_ppc(struct draw_context *draw, + const struct pipe_shader_state *templ); + + +struct draw_vs_varient_key; +struct draw_vertex_shader; + +struct draw_vs_varient * +draw_vs_create_varient_aos_sse( struct draw_vertex_shader *vs, + const struct draw_vs_varient_key *key ); + +#if HAVE_LLVM +struct draw_vertex_shader * +draw_create_vs_llvm(struct draw_context *draw, + const struct pipe_shader_state *state); +#endif + + +/******************************************************************************** + * Helpers for vs implementations that don't do their own fetch/emit varients. + * Means these can be shared between shaders. + */ +struct translate; +struct translate_key; + +struct translate *draw_vs_get_fetch( struct draw_context *draw, + struct translate_key *key ); + + +struct translate *draw_vs_get_emit( struct draw_context *draw, + struct translate_key *key ); + +struct draw_vs_varient * +draw_vs_create_varient_generic( struct draw_vertex_shader *vs, + const struct draw_vs_varient_key *key ); + + + +static INLINE int draw_vs_varient_keysize( const struct draw_vs_varient_key *key ) +{ + return 2 * sizeof(int) + key->nr_elements * sizeof(struct draw_varient_element); +} + +static INLINE int draw_vs_varient_key_compare( const struct draw_vs_varient_key *a, + const struct draw_vs_varient_key *b ) +{ + int keysize = draw_vs_varient_keysize(a); + return memcmp(a, b, keysize); +} + + +struct aos_machine *draw_vs_aos_machine( void ); +void draw_vs_aos_machine_destroy( struct aos_machine *machine ); + +void +draw_vs_aos_machine_constants(struct aos_machine *machine, + unsigned slot, + const void *constants); + +void draw_vs_aos_machine_viewport( struct aos_machine *machine, + const struct pipe_viewport_state *viewport ); + + +#define MAX_TGSI_VERTICES 4 + + + +#endif diff --git a/src/gallium/auxiliary/draw/draw_vs_aos.c b/src/gallium/auxiliary/draw/draw_vs_aos.c new file mode 100644 index 0000000..19f49e3 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_vs_aos.c @@ -0,0 +1,2267 @@ +/* + * Mesa 3-D graphics library + * Version: 6.3 + * + * Copyright (C) 1999-2004 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. + */ + +/** + * Translate tgsi vertex programs to x86/x87/SSE/SSE2 machine code + * using the rtasm runtime assembler. Based on the old + * t_vb_arb_program_sse.c + */ + + +#include "util/u_memory.h" +#include "util/u_math.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_debug.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "tgsi/tgsi_exec.h" +#include "tgsi/tgsi_dump.h" + +#include "draw_vs.h" +#include "draw_vs_aos.h" + +#include "rtasm/rtasm_x86sse.h" + +#ifdef PIPE_ARCH_X86 +#define DISASSEM 0 +#define FAST_MATH 1 + +static const char *files[] = +{ + "NULL", + "CONST", + "IN", + "OUT", + "TEMP", + "SAMP", + "ADDR", + "IMM", + "INTERNAL", +}; + +static INLINE boolean eq( struct x86_reg a, + struct x86_reg b ) +{ + return (a.file == b.file && + a.idx == b.idx && + a.mod == b.mod && + a.disp == b.disp); +} + +struct x86_reg aos_get_x86( struct aos_compilation *cp, + unsigned which_reg, /* quick hack */ + unsigned value ) +{ + struct x86_reg reg; + + if (which_reg == 0) + reg = cp->temp_EBP; + else + reg = cp->tmp_EAX; + + if (cp->x86_reg[which_reg] != value) { + unsigned offset; + + switch (value) { + case X86_IMMEDIATES: + assert(which_reg == 0); + offset = Offset(struct aos_machine, immediates); + break; + case X86_CONSTANTS: + assert(which_reg == 1); + offset = Offset(struct aos_machine, constants); + break; + case X86_BUFFERS: + assert(which_reg == 0); + offset = Offset(struct aos_machine, buffer); + break; + default: + assert(0); + offset = 0; + } + + + x86_mov(cp->func, reg, + x86_make_disp(cp->machine_EDX, offset)); + + cp->x86_reg[which_reg] = value; + } + + return reg; +} + + +static struct x86_reg get_reg_ptr(struct aos_compilation *cp, + unsigned file, + unsigned idx ) +{ + struct x86_reg ptr = cp->machine_EDX; + + switch (file) { + case TGSI_FILE_INPUT: + assert(idx < MAX_INPUTS); + return x86_make_disp(ptr, Offset(struct aos_machine, input[idx])); + + case TGSI_FILE_OUTPUT: + return x86_make_disp(ptr, Offset(struct aos_machine, output[idx])); + + case TGSI_FILE_TEMPORARY: + assert(idx < MAX_TEMPS); + return x86_make_disp(ptr, Offset(struct aos_machine, temp[idx])); + + case AOS_FILE_INTERNAL: + assert(idx < MAX_INTERNALS); + return x86_make_disp(ptr, Offset(struct aos_machine, internal[idx])); + + case TGSI_FILE_IMMEDIATE: + assert(idx < MAX_IMMEDIATES); /* just a sanity check */ + return x86_make_disp(aos_get_x86(cp, 0, X86_IMMEDIATES), idx * 4 * sizeof(float)); + + case TGSI_FILE_CONSTANT: + assert(idx < MAX_CONSTANTS); /* just a sanity check */ + return x86_make_disp(aos_get_x86(cp, 1, X86_CONSTANTS), idx * 4 * sizeof(float)); + + default: + AOS_ERROR(cp, "unknown reg file"); + return x86_make_reg(0,0); + } +} + + + +#define X87_CW_EXCEPTION_INV_OP (1<<0) +#define X87_CW_EXCEPTION_DENORM_OP (1<<1) +#define X87_CW_EXCEPTION_ZERO_DIVIDE (1<<2) +#define X87_CW_EXCEPTION_OVERFLOW (1<<3) +#define X87_CW_EXCEPTION_UNDERFLOW (1<<4) +#define X87_CW_EXCEPTION_PRECISION (1<<5) +#define X87_CW_PRECISION_SINGLE (0<<8) +#define X87_CW_PRECISION_RESERVED (1<<8) +#define X87_CW_PRECISION_DOUBLE (2<<8) +#define X87_CW_PRECISION_DOUBLE_EXT (3<<8) +#define X87_CW_PRECISION_MASK (3<<8) +#define X87_CW_ROUND_NEAREST (0<<10) +#define X87_CW_ROUND_DOWN (1<<10) +#define X87_CW_ROUND_UP (2<<10) +#define X87_CW_ROUND_ZERO (3<<10) +#define X87_CW_ROUND_MASK (3<<10) +#define X87_CW_INFINITY (1<<12) + + + + +static void spill( struct aos_compilation *cp, unsigned idx ) +{ + if (!cp->xmm[idx].dirty || + (cp->xmm[idx].file != TGSI_FILE_INPUT && /* inputs are fetched into xmm & set dirty */ + cp->xmm[idx].file != TGSI_FILE_OUTPUT && + cp->xmm[idx].file != TGSI_FILE_TEMPORARY)) { + AOS_ERROR(cp, "invalid spill"); + return; + } + else { + struct x86_reg oldval = get_reg_ptr(cp, + cp->xmm[idx].file, + cp->xmm[idx].idx); + + if (0) debug_printf("\nspill %s[%d]", + files[cp->xmm[idx].file], + cp->xmm[idx].idx); + + assert(cp->xmm[idx].dirty); + sse_movaps(cp->func, oldval, x86_make_reg(file_XMM, idx)); + cp->xmm[idx].dirty = 0; + } +} + + +void aos_spill_all( struct aos_compilation *cp ) +{ + unsigned i; + + for (i = 0; i < 8; i++) { + if (cp->xmm[i].dirty) + spill(cp, i); + aos_release_xmm_reg(cp, i); + } +} + + +static struct x86_reg get_xmm_writable( struct aos_compilation *cp, + struct x86_reg reg ) +{ + if (reg.file != file_XMM || + cp->xmm[reg.idx].file != TGSI_FILE_NULL) + { + struct x86_reg tmp = aos_get_xmm_reg(cp); + sse_movaps(cp->func, tmp, reg); + reg = tmp; + } + + cp->xmm[reg.idx].last_used = cp->insn_counter; + return reg; +} + +static struct x86_reg get_xmm( struct aos_compilation *cp, + struct x86_reg reg ) +{ + if (reg.file != file_XMM) + { + struct x86_reg tmp = aos_get_xmm_reg(cp); + sse_movaps(cp->func, tmp, reg); + reg = tmp; + } + + cp->xmm[reg.idx].last_used = cp->insn_counter; + return reg; +} + + +/* Allocate an empty xmm register, either as a temporary or later to + * "adopt" as a shader reg. + */ +struct x86_reg aos_get_xmm_reg( struct aos_compilation *cp ) +{ + unsigned i; + unsigned oldest = 0; + boolean found = FALSE; + + for (i = 0; i < 8; i++) + if (cp->xmm[i].last_used != cp->insn_counter && + cp->xmm[i].file == TGSI_FILE_NULL) { + oldest = i; + found = TRUE; + } + + if (!found) { + for (i = 0; i < 8; i++) + if (cp->xmm[i].last_used < cp->xmm[oldest].last_used) + oldest = i; + } + + /* Need to write out the old value? + */ + if (cp->xmm[oldest].dirty) + spill(cp, oldest); + + assert(cp->xmm[oldest].last_used != cp->insn_counter); + + cp->xmm[oldest].file = TGSI_FILE_NULL; + cp->xmm[oldest].idx = 0; + cp->xmm[oldest].dirty = 0; + cp->xmm[oldest].last_used = cp->insn_counter; + return x86_make_reg(file_XMM, oldest); +} + +void aos_release_xmm_reg( struct aos_compilation *cp, + unsigned idx ) +{ + cp->xmm[idx].file = TGSI_FILE_NULL; + cp->xmm[idx].idx = 0; + cp->xmm[idx].dirty = 0; + cp->xmm[idx].last_used = 0; +} + + +static void aos_soft_release_xmm( struct aos_compilation *cp, + struct x86_reg reg ) +{ + if (reg.file == file_XMM) { + assert(cp->xmm[reg.idx].last_used == cp->insn_counter); + cp->xmm[reg.idx].last_used = cp->insn_counter - 1; + } +} + + + +/* Mark an xmm reg as holding the current copy of a shader reg. + */ +void aos_adopt_xmm_reg( struct aos_compilation *cp, + struct x86_reg reg, + unsigned file, + unsigned idx, + unsigned dirty ) +{ + unsigned i; + + if (reg.file != file_XMM) { + assert(0); + return; + } + + + /* If any xmm reg thinks it holds this shader reg, break the + * illusion. + */ + for (i = 0; i < 8; i++) { + if (cp->xmm[i].file == file && + cp->xmm[i].idx == idx) + { + /* If an xmm reg is already holding this shader reg, take into account its + * dirty flag... + */ + dirty |= cp->xmm[i].dirty; + aos_release_xmm_reg(cp, i); + } + } + + cp->xmm[reg.idx].file = file; + cp->xmm[reg.idx].idx = idx; + cp->xmm[reg.idx].dirty = dirty; + cp->xmm[reg.idx].last_used = cp->insn_counter; +} + + +/* Return a pointer to the in-memory copy of the reg, making sure it is uptodate. + */ +static struct x86_reg aos_get_shader_reg_ptr( struct aos_compilation *cp, + unsigned file, + unsigned idx ) +{ + unsigned i; + + /* Ensure the in-memory copy of this reg is up-to-date + */ + for (i = 0; i < 8; i++) { + if (cp->xmm[i].file == file && + cp->xmm[i].idx == idx && + cp->xmm[i].dirty) { + spill(cp, i); + } + } + + return get_reg_ptr( cp, file, idx ); +} + + +/* As above, but return a pointer. Note - this pointer may alias + * those returned by get_arg_ptr(). + */ +static struct x86_reg get_dst_ptr( struct aos_compilation *cp, + const struct tgsi_full_dst_register *dst ) +{ + unsigned file = dst->Register.File; + unsigned idx = dst->Register.Index; + unsigned i; + + + /* Ensure in-memory copy of this reg is up-to-date and invalidate + * any xmm copies. + */ + for (i = 0; i < 8; i++) { + if (cp->xmm[i].file == file && + cp->xmm[i].idx == idx) + { + if (cp->xmm[i].dirty) + spill(cp, i); + + aos_release_xmm_reg(cp, i); + } + } + + return get_reg_ptr( cp, file, idx ); +} + + + + + +/* Return an XMM reg if the argument is resident, otherwise return a + * base+offset pointer to the saved value. + */ +struct x86_reg aos_get_shader_reg( struct aos_compilation *cp, + unsigned file, + unsigned idx ) +{ + unsigned i; + + for (i = 0; i < 8; i++) { + if (cp->xmm[i].file == file && + cp->xmm[i].idx == idx) + { + cp->xmm[i].last_used = cp->insn_counter; + return x86_make_reg(file_XMM, i); + } + } + + /* If not found in the XMM register file, return an indirect + * reference to the in-memory copy: + */ + return get_reg_ptr( cp, file, idx ); +} + + + +static struct x86_reg aos_get_shader_reg_xmm( struct aos_compilation *cp, + unsigned file, + unsigned idx ) +{ + struct x86_reg reg = get_xmm( cp, + aos_get_shader_reg( cp, file, idx ) ); + + aos_adopt_xmm_reg( cp, + reg, + file, + idx, + FALSE ); + + return reg; +} + + + +struct x86_reg aos_get_internal_xmm( struct aos_compilation *cp, + unsigned imm ) +{ + return aos_get_shader_reg_xmm( cp, AOS_FILE_INTERNAL, imm ); +} + + +struct x86_reg aos_get_internal( struct aos_compilation *cp, + unsigned imm ) +{ + return aos_get_shader_reg( cp, AOS_FILE_INTERNAL, imm ); +} + + + + + +/* Emulate pshufd insn in regular SSE, if necessary: + */ +static void emit_pshufd( struct aos_compilation *cp, + struct x86_reg dst, + struct x86_reg arg0, + ubyte shuf ) +{ + if (cp->have_sse2) { + sse2_pshufd(cp->func, dst, arg0, shuf); + } + else { + if (!eq(dst, arg0)) + sse_movaps(cp->func, dst, arg0); + + sse_shufps(cp->func, dst, dst, shuf); + } +} + +/* load masks (pack into negs??) + * pshufd - shuffle according to writemask + * and - result, mask + * nand - dest, mask + * or - dest, result + */ +static boolean mask_write( struct aos_compilation *cp, + struct x86_reg dst, + struct x86_reg result, + unsigned mask ) +{ + struct x86_reg imm_swz = aos_get_internal_xmm(cp, IMM_SWZ); + struct x86_reg tmp = aos_get_xmm_reg(cp); + + emit_pshufd(cp, tmp, imm_swz, + SHUF((mask & 1) ? 2 : 3, + (mask & 2) ? 2 : 3, + (mask & 4) ? 2 : 3, + (mask & 8) ? 2 : 3)); + + sse_andps(cp->func, dst, tmp); + sse_andnps(cp->func, tmp, result); + sse_orps(cp->func, dst, tmp); + + aos_release_xmm_reg(cp, tmp.idx); + return TRUE; +} + + + + +/* Helper for writemask: + */ +static boolean emit_shuf_copy2( struct aos_compilation *cp, + struct x86_reg dst, + struct x86_reg arg0, + struct x86_reg arg1, + ubyte shuf ) +{ + struct x86_reg tmp = aos_get_xmm_reg(cp); + + emit_pshufd(cp, dst, arg1, shuf); + emit_pshufd(cp, tmp, arg0, shuf); + sse_shufps(cp->func, dst, tmp, SHUF(X, Y, Z, W)); + emit_pshufd(cp, dst, dst, shuf); + + aos_release_xmm_reg(cp, tmp.idx); + return TRUE; +} + + + +#define SSE_SWIZZLE_NOOP ((0<<0) | (1<<2) | (2<<4) | (3<<6)) + + +/* Locate a source register and perform any required (simple) swizzle. + * + * Just fail on complex swizzles at this point. + */ +static struct x86_reg fetch_src( struct aos_compilation *cp, + const struct tgsi_full_src_register *src ) +{ + struct x86_reg arg0 = aos_get_shader_reg(cp, + src->Register.File, + src->Register.Index); + unsigned i; + ubyte swz = 0; + unsigned negs = 0; + unsigned abs = 0; + + for (i = 0; i < 4; i++) { + unsigned swizzle = tgsi_util_get_full_src_register_swizzle( src, i ); + unsigned neg = tgsi_util_get_full_src_register_sign_mode( src, i ); + + swz |= (swizzle & 0x3) << (i * 2); + + switch (neg) { + case TGSI_UTIL_SIGN_TOGGLE: + negs |= (1<func, dst, arg0); + + if (negs && negs != 0xf) { + struct x86_reg imm_swz = aos_get_internal_xmm(cp, IMM_SWZ); + struct x86_reg tmp = aos_get_xmm_reg(cp); + + /* Load 1,-1,0,0 + * Use neg as arg to pshufd + * Multiply + */ + emit_pshufd(cp, tmp, imm_swz, + SHUF((negs & 1) ? 1 : 0, + (negs & 2) ? 1 : 0, + (negs & 4) ? 1 : 0, + (negs & 8) ? 1 : 0)); + sse_mulps(cp->func, dst, tmp); + + aos_release_xmm_reg(cp, tmp.idx); + aos_soft_release_xmm(cp, imm_swz); + } + else if (negs) { + struct x86_reg imm_negs = aos_get_internal_xmm(cp, IMM_NEGS); + sse_mulps(cp->func, dst, imm_negs); + aos_soft_release_xmm(cp, imm_negs); + } + + + if (abs && abs != 0xf) { + AOS_ERROR(cp, "unsupported partial abs"); + } + else if (abs) { + struct x86_reg neg = aos_get_internal(cp, IMM_NEGS); + struct x86_reg tmp = aos_get_xmm_reg(cp); + + sse_movaps(cp->func, tmp, dst); + sse_mulps(cp->func, tmp, neg); + sse_maxps(cp->func, dst, tmp); + + aos_release_xmm_reg(cp, tmp.idx); + aos_soft_release_xmm(cp, neg); + } + + aos_soft_release_xmm(cp, arg0); + return dst; + } + + return arg0; +} + +static void x87_fld_src( struct aos_compilation *cp, + const struct tgsi_full_src_register *src, + unsigned channel ) +{ + struct x86_reg arg0 = aos_get_shader_reg_ptr(cp, + src->Register.File, + src->Register.Index); + + unsigned swizzle = tgsi_util_get_full_src_register_swizzle( src, channel ); + unsigned neg = tgsi_util_get_full_src_register_sign_mode( src, channel ); + + x87_fld( cp->func, x86_make_disp(arg0, (swizzle & 3) * sizeof(float)) ); + + switch (neg) { + case TGSI_UTIL_SIGN_TOGGLE: + /* Flip the sign: + */ + x87_fchs( cp->func ); + break; + + case TGSI_UTIL_SIGN_KEEP: + break; + + case TGSI_UTIL_SIGN_CLEAR: + x87_fabs( cp->func ); + break; + + case TGSI_UTIL_SIGN_SET: + x87_fabs( cp->func ); + x87_fchs( cp->func ); + break; + + default: + AOS_ERROR(cp, "unsupported sign-mode"); + break; + } +} + + + + + + +/* Used to implement write masking. This and most of the other instructions + * here would be easier to implement if there had been a translation + * to a 2 argument format (dst/arg0, arg1) at the shader level before + * attempting to translate to x86/sse code. + */ +static void store_dest( struct aos_compilation *cp, + const struct tgsi_full_dst_register *reg, + struct x86_reg result ) +{ + struct x86_reg dst; + + switch (reg->Register.WriteMask) { + case 0: + return; + + case TGSI_WRITEMASK_XYZW: + aos_adopt_xmm_reg(cp, + get_xmm_writable(cp, result), + reg->Register.File, + reg->Register.Index, + TRUE); + return; + default: + break; + } + + dst = aos_get_shader_reg_xmm(cp, + reg->Register.File, + reg->Register.Index); + + switch (reg->Register.WriteMask) { + case TGSI_WRITEMASK_X: + sse_movss(cp->func, dst, get_xmm(cp, result)); + break; + + case TGSI_WRITEMASK_ZW: + sse_shufps(cp->func, dst, get_xmm(cp, result), SHUF(X, Y, Z, W)); + break; + + case TGSI_WRITEMASK_XY: + result = get_xmm_writable(cp, result); + sse_shufps(cp->func, result, dst, SHUF(X, Y, Z, W)); + dst = result; + break; + + case TGSI_WRITEMASK_YZW: + result = get_xmm_writable(cp, result); + sse_movss(cp->func, result, dst); + dst = result; + break; + + default: + mask_write(cp, dst, result, reg->Register.WriteMask); + break; + } + + aos_adopt_xmm_reg(cp, + dst, + reg->Register.File, + reg->Register.Index, + TRUE); + +} + +static void inject_scalar( struct aos_compilation *cp, + struct x86_reg dst, + struct x86_reg result, + ubyte swizzle ) +{ + sse_shufps(cp->func, dst, dst, swizzle); + sse_movss(cp->func, dst, result); + sse_shufps(cp->func, dst, dst, swizzle); +} + + +static void store_scalar_dest( struct aos_compilation *cp, + const struct tgsi_full_dst_register *reg, + struct x86_reg result ) +{ + unsigned writemask = reg->Register.WriteMask; + struct x86_reg dst; + + if (writemask != TGSI_WRITEMASK_X && + writemask != TGSI_WRITEMASK_Y && + writemask != TGSI_WRITEMASK_Z && + writemask != TGSI_WRITEMASK_W && + writemask != 0) + { + result = get_xmm_writable(cp, result); /* already true, right? */ + sse_shufps(cp->func, result, result, SHUF(X,X,X,X)); + store_dest(cp, reg, result); + return; + } + + result = get_xmm(cp, result); + dst = aos_get_shader_reg_xmm(cp, + reg->Register.File, + reg->Register.Index); + + + + switch (reg->Register.WriteMask) { + case TGSI_WRITEMASK_X: + sse_movss(cp->func, dst, result); + break; + + case TGSI_WRITEMASK_Y: + inject_scalar(cp, dst, result, SHUF(Y, X, Z, W)); + break; + + case TGSI_WRITEMASK_Z: + inject_scalar(cp, dst, result, SHUF(Z, Y, X, W)); + break; + + case TGSI_WRITEMASK_W: + inject_scalar(cp, dst, result, SHUF(W, Y, Z, X)); + break; + + default: + break; + } + + aos_adopt_xmm_reg(cp, + dst, + reg->Register.File, + reg->Register.Index, + TRUE); +} + + + +static void x87_fst_or_nop( struct x86_function *func, + unsigned writemask, + unsigned channel, + struct x86_reg ptr ) +{ + assert(ptr.file == file_REG32); + if (writemask & (1<Register.WriteMask; + + x87_fst_or_nop(cp->func, writemask, 0, ptr); + x87_fst_or_nop(cp->func, writemask, 1, ptr); + x87_fst_or_nop(cp->func, writemask, 2, ptr); + x87_fstp_or_pop(cp->func, writemask, 3, ptr); +} + +/* Save current x87 state and put it into single precision mode. + */ +static void save_fpu_state( struct aos_compilation *cp ) +{ + x87_fnstcw( cp->func, x86_make_disp(cp->machine_EDX, + Offset(struct aos_machine, fpu_restore))); +} + +static void restore_fpu_state( struct aos_compilation *cp ) +{ + x87_fnclex(cp->func); + x87_fldcw( cp->func, x86_make_disp(cp->machine_EDX, + Offset(struct aos_machine, fpu_restore))); +} + +static void set_fpu_round_neg_inf( struct aos_compilation *cp ) +{ + if (cp->fpucntl != FPU_RND_NEG) { + cp->fpucntl = FPU_RND_NEG; + x87_fnclex(cp->func); + x87_fldcw( cp->func, x86_make_disp(cp->machine_EDX, + Offset(struct aos_machine, fpu_rnd_neg_inf))); + } +} + +static void set_fpu_round_nearest( struct aos_compilation *cp ) +{ + if (cp->fpucntl != FPU_RND_NEAREST) { + cp->fpucntl = FPU_RND_NEAREST; + x87_fnclex(cp->func); + x87_fldcw( cp->func, x86_make_disp(cp->machine_EDX, + Offset(struct aos_machine, fpu_rnd_nearest))); + } +} + +#if 0 +static void x87_emit_ex2( struct aos_compilation *cp ) +{ + struct x86_reg st0 = x86_make_reg(file_x87, 0); + struct x86_reg st1 = x86_make_reg(file_x87, 1); + int stack = cp->func->x87_stack; + + /* set_fpu_round_neg_inf( cp ); */ + + x87_fld(cp->func, st0); /* a a */ + x87_fprndint( cp->func ); /* int(a) a*/ + x87_fsubr(cp->func, st1, st0); /* int(a) frc(a) */ + x87_fxch(cp->func, st1); /* frc(a) int(a) */ + x87_f2xm1(cp->func); /* (2^frc(a))-1 int(a) */ + x87_fld1(cp->func); /* 1 (2^frc(a))-1 int(a) */ + x87_faddp(cp->func, st1); /* 2^frac(a) int(a) */ + x87_fscale(cp->func); /* (2^frac(a)*2^int(int(a))) int(a) */ + /* 2^a int(a) */ + x87_fstp(cp->func, st1); /* 2^a */ + + assert( stack == cp->func->x87_stack); + +} +#endif + +#if 0 +static void PIPE_CDECL print_reg( const char *msg, + const float *reg ) +{ + debug_printf("%s: %f %f %f %f\n", msg, reg[0], reg[1], reg[2], reg[3]); +} +#endif + +#if 0 +static void emit_print( struct aos_compilation *cp, + const char *message, /* must point to a static string! */ + unsigned file, + unsigned idx ) +{ + struct x86_reg ecx = x86_make_reg( file_REG32, reg_CX ); + struct x86_reg arg = aos_get_shader_reg_ptr( cp, file, idx ); + unsigned i; + + /* There shouldn't be anything on the x87 stack. Can add this + * capacity later if need be. + */ + assert(cp->func->x87_stack == 0); + + /* For absolute correctness, need to spill/invalidate all XMM regs + * too. We're obviously not concerned about performance on this + * debug path, so here goes: + */ + for (i = 0; i < 8; i++) { + if (cp->xmm[i].dirty) + spill(cp, i); + + aos_release_xmm_reg(cp, i); + } + + /* Push caller-save (ie scratch) regs. + */ + x86_cdecl_caller_push_regs( cp->func ); + + + /* Push the arguments: + */ + x86_lea( cp->func, ecx, arg ); + x86_push( cp->func, ecx ); + x86_push_imm32( cp->func, (int)message ); + + /* Call the helper. Could call debug_printf directly, but + * print_reg is a nice place to put a breakpoint if need be. + */ + x86_mov_reg_imm( cp->func, ecx, (int)print_reg ); + x86_call( cp->func, ecx ); + x86_pop( cp->func, ecx ); + x86_pop( cp->func, ecx ); + + /* Pop caller-save regs + */ + x86_cdecl_caller_pop_regs( cp->func ); + + /* Done... + */ +} +#endif + +/** + * The traditional instructions. All operate on internal registers + * and ignore write masks and swizzling issues. + */ + +static boolean emit_ABS( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg neg = aos_get_internal(cp, IMM_NEGS); + struct x86_reg tmp = aos_get_xmm_reg(cp); + + sse_movaps(cp->func, tmp, arg0); + sse_mulps(cp->func, tmp, neg); + sse_maxps(cp->func, tmp, arg0); + + store_dest(cp, &op->Dst[0], tmp); + return TRUE; +} + +static boolean emit_ADD( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg arg1 = fetch_src(cp, &op->Src[1]); + struct x86_reg dst = get_xmm_writable(cp, arg0); + + sse_addps(cp->func, dst, arg1); + + store_dest(cp, &op->Dst[0], dst); + return TRUE; +} + +static boolean emit_COS( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + x87_fld_src(cp, &op->Src[0], 0); + x87_fcos(cp->func); + x87_fstp_dest4(cp, &op->Dst[0]); + return TRUE; +} + +/* The dotproduct instructions don't really do that well in sse: + * XXX: produces wrong results -- disabled. + */ +static boolean emit_DP3( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg arg1 = fetch_src(cp, &op->Src[1]); + struct x86_reg tmp = aos_get_xmm_reg(cp); + struct x86_reg dst = get_xmm_writable(cp, arg0); + + sse_mulps(cp->func, dst, arg1); + /* Now the hard bit: sum the first 3 values: + */ + sse_movhlps(cp->func, tmp, dst); + sse_addss(cp->func, dst, tmp); /* a*x+c*z, b*y, ?, ? */ + emit_pshufd(cp, tmp, dst, SHUF(Y,X,W,Z)); + sse_addss(cp->func, dst, tmp); + + aos_release_xmm_reg(cp, tmp.idx); + store_scalar_dest(cp, &op->Dst[0], dst); + return TRUE; +} + +static boolean emit_DP4( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg arg1 = fetch_src(cp, &op->Src[1]); + struct x86_reg tmp = aos_get_xmm_reg(cp); + struct x86_reg dst = get_xmm_writable(cp, arg0); + + sse_mulps(cp->func, dst, arg1); + + /* Now the hard bit: sum the values: + */ + sse_movhlps(cp->func, tmp, dst); + sse_addps(cp->func, dst, tmp); /* a*x+c*z, b*y+d*w, a*x+c*z, b*y+d*w */ + emit_pshufd(cp, tmp, dst, SHUF(Y,X,W,Z)); + sse_addss(cp->func, dst, tmp); + + aos_release_xmm_reg(cp, tmp.idx); + store_scalar_dest(cp, &op->Dst[0], dst); + return TRUE; +} + +static boolean emit_DPH( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg arg1 = fetch_src(cp, &op->Src[1]); + struct x86_reg tmp = aos_get_xmm_reg(cp); + struct x86_reg dst = get_xmm_writable(cp, arg0); + + sse_mulps(cp->func, dst, arg1); + + /* Now the hard bit: sum the values (from DP3): + */ + sse_movhlps(cp->func, tmp, dst); + sse_addss(cp->func, dst, tmp); /* a*x+c*z, b*y, ?, ? */ + emit_pshufd(cp, tmp, dst, SHUF(Y,X,W,Z)); + sse_addss(cp->func, dst, tmp); + emit_pshufd(cp, tmp, arg1, SHUF(W,W,W,W)); + sse_addss(cp->func, dst, tmp); + + aos_release_xmm_reg(cp, tmp.idx); + store_scalar_dest(cp, &op->Dst[0], dst); + return TRUE; +} + +static boolean emit_DST( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg arg1 = fetch_src(cp, &op->Src[1]); + struct x86_reg dst = aos_get_xmm_reg(cp); + struct x86_reg tmp = aos_get_xmm_reg(cp); + struct x86_reg ones = aos_get_internal(cp, IMM_ONES); + +/* dst[0] = 1.0 * 1.0F; */ +/* dst[1] = arg0[1] * arg1[1]; */ +/* dst[2] = arg0[2] * 1.0; */ +/* dst[3] = 1.0 * arg1[3]; */ + + emit_shuf_copy2(cp, dst, arg0, ones, SHUF(X,W,Z,Y)); + emit_shuf_copy2(cp, tmp, arg1, ones, SHUF(X,Z,Y,W)); + sse_mulps(cp->func, dst, tmp); + + aos_release_xmm_reg(cp, tmp.idx); + store_dest(cp, &op->Dst[0], dst); + return TRUE; +} + +static boolean emit_LG2( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + x87_fld1(cp->func); /* 1 */ + x87_fld_src(cp, &op->Src[0], 0); /* a0 1 */ + x87_fyl2x(cp->func); /* log2(a0) */ + x87_fstp_dest4(cp, &op->Dst[0]); + return TRUE; +} + +#if 0 +static boolean emit_EX2( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + x87_fld_src(cp, &op->Src[0], 0); + x87_emit_ex2(cp); + x87_fstp_dest4(cp, &op->Dst[0]); + return TRUE; +} +#endif + + +static boolean emit_FLR( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg dst = get_dst_ptr(cp, &op->Dst[0]); + unsigned writemask = op->Dst[0].Register.WriteMask; + int i; + + set_fpu_round_neg_inf( cp ); + + /* Load all sources first to avoid aliasing + */ + for (i = 3; i >= 0; i--) { + if (writemask & (1<Src[0], i); + } + } + + for (i = 0; i < 4; i++) { + if (writemask & (1<func ); + x87_fstp(cp->func, x86_make_disp(dst, i*4)); + } + } + + return TRUE; +} + + +static boolean emit_RND( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg dst = get_dst_ptr(cp, &op->Dst[0]); + unsigned writemask = op->Dst[0].Register.WriteMask; + int i; + + set_fpu_round_nearest( cp ); + + /* Load all sources first to avoid aliasing + */ + for (i = 3; i >= 0; i--) { + if (writemask & (1<Src[0], i); + } + } + + for (i = 0; i < 4; i++) { + if (writemask & (1<func ); + x87_fstp(cp->func, x86_make_disp(dst, i*4)); + } + } + + return TRUE; +} + + +static boolean emit_FRC( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg dst = get_dst_ptr(cp, &op->Dst[0]); + struct x86_reg st0 = x86_make_reg(file_x87, 0); + struct x86_reg st1 = x86_make_reg(file_x87, 1); + unsigned writemask = op->Dst[0].Register.WriteMask; + int i; + + set_fpu_round_neg_inf( cp ); + + /* suck all the source values onto the stack before writing out any + * dst, which may alias... + */ + for (i = 3; i >= 0; i--) { + if (writemask & (1<Src[0], i); + } + } + + for (i = 0; i < 4; i++) { + if (writemask & (1<func, st0); /* a a */ + x87_fprndint( cp->func ); /* flr(a) a */ + x87_fsubp(cp->func, st1); /* frc(a) */ + x87_fstp(cp->func, x86_make_disp(dst, i*4)); + } + } + + return TRUE; +} + + + + + + +static boolean emit_LIT( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg ecx = x86_make_reg( file_REG32, reg_CX ); + unsigned writemask = op->Dst[0].Register.WriteMask; + unsigned lit_count = cp->lit_count++; + struct x86_reg result, arg0; + unsigned i; + +#if 1 + /* For absolute correctness, need to spill/invalidate all XMM regs + * too. + */ + for (i = 0; i < 8; i++) { + if (cp->xmm[i].dirty) + spill(cp, i); + aos_release_xmm_reg(cp, i); + } +#endif + + if (writemask != TGSI_WRITEMASK_XYZW) + result = x86_make_disp(cp->machine_EDX, Offset(struct aos_machine, tmp[0])); + else + result = get_dst_ptr(cp, &op->Dst[0]); + + + arg0 = fetch_src( cp, &op->Src[0] ); + if (arg0.file == file_XMM) { + struct x86_reg tmp = x86_make_disp(cp->machine_EDX, + Offset(struct aos_machine, tmp[1])); + sse_movaps( cp->func, tmp, arg0 ); + arg0 = tmp; + } + + + + /* Push caller-save (ie scratch) regs. + */ + x86_cdecl_caller_push_regs( cp->func ); + + /* Push the arguments: + */ + x86_push_imm32( cp->func, lit_count ); + + x86_lea( cp->func, ecx, arg0 ); + x86_push( cp->func, ecx ); + + x86_lea( cp->func, ecx, result ); + x86_push( cp->func, ecx ); + + x86_push( cp->func, cp->machine_EDX ); + + if (lit_count < MAX_LIT_INFO) { + x86_mov( cp->func, ecx, x86_make_disp( cp->machine_EDX, + Offset(struct aos_machine, lit_info) + + lit_count * sizeof(struct lit_info) + + Offset(struct lit_info, func))); + } + else { + x86_mov_reg_imm( cp->func, ecx, (int)aos_do_lit ); + } + + x86_call( cp->func, ecx ); + + x86_pop( cp->func, ecx ); /* fixme... */ + x86_pop( cp->func, ecx ); + x86_pop( cp->func, ecx ); + x86_pop( cp->func, ecx ); + + x86_cdecl_caller_pop_regs( cp->func ); + + if (writemask != TGSI_WRITEMASK_XYZW) { + store_dest( cp, + &op->Dst[0], + get_xmm_writable( cp, result ) ); + } + + return TRUE; +} + +#if 0 +static boolean emit_inline_LIT( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg dst = get_dst_ptr(cp, &op->Dst[0]); + unsigned writemask = op->Dst[0].Register.WriteMask; + + if (writemask & TGSI_WRITEMASK_YZ) { + struct x86_reg st1 = x86_make_reg(file_x87, 1); + struct x86_reg st2 = x86_make_reg(file_x87, 2); + + /* a1' = a1 <= 0 ? 1 : a1; + */ + x87_fldz(cp->func); /* 1 0 */ +#if 1 + x87_fld1(cp->func); /* 1 0 */ +#else + /* Correct but slow due to fp exceptions generated in fyl2x - fix me. + */ + x87_fldz(cp->func); /* 1 0 */ +#endif + x87_fld_src(cp, &op->Src[0], 1); /* a1 1 0 */ + x87_fcomi(cp->func, st2); /* a1 1 0 */ + x87_fcmovb(cp->func, st1); /* a1' 1 0 */ + x87_fstp(cp->func, st1); /* a1' 0 */ + x87_fstp(cp->func, st1); /* a1' */ + + x87_fld_src(cp, &op->Src[0], 3); /* a3 a1' */ + x87_fxch(cp->func, st1); /* a1' a3 */ + + + /* Compute pow(a1, a3) + */ + x87_fyl2x(cp->func); /* a3*log2(a1) */ + x87_emit_ex2( cp ); /* 2^(a3*log2(a1)) */ + + + /* a0' = max2(a0, 0): + */ + x87_fldz(cp->func); /* 0 r2 */ + x87_fld_src(cp, &op->Src[0], 0); /* a0 0 r2 */ + x87_fcomi(cp->func, st1); + x87_fcmovb(cp->func, st1); /* a0' 0 r2 */ + + x87_fst_or_nop(cp->func, writemask, 1, dst); /* result[1] = a0' */ + + x87_fcomi(cp->func, st1); /* a0' 0 r2 */ + x87_fcmovnbe(cp->func, st2); /* r2' 0' r2 */ + + x87_fstp_or_pop(cp->func, writemask, 2, dst); /* 0 r2 */ + x87_fpop(cp->func); /* r2 */ + x87_fpop(cp->func); + } + + if (writemask & TGSI_WRITEMASK_XW) { + x87_fld1(cp->func); + x87_fst_or_nop(cp->func, writemask, 0, dst); + x87_fstp_or_pop(cp->func, writemask, 3, dst); + } + + return TRUE; +} +#endif + + + +static boolean emit_MAX( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg arg1 = fetch_src(cp, &op->Src[1]); + struct x86_reg dst = get_xmm_writable(cp, arg0); + + sse_maxps(cp->func, dst, arg1); + + store_dest(cp, &op->Dst[0], dst); + return TRUE; +} + + +static boolean emit_MIN( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg arg1 = fetch_src(cp, &op->Src[1]); + struct x86_reg dst = get_xmm_writable(cp, arg0); + + sse_minps(cp->func, dst, arg1); + + store_dest(cp, &op->Dst[0], dst); + return TRUE; +} + +static boolean emit_MOV( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg dst = get_xmm_writable(cp, arg0); + + /* potentially nothing to do */ + + store_dest(cp, &op->Dst[0], dst); + return TRUE; +} + +static boolean emit_MUL( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg arg1 = fetch_src(cp, &op->Src[1]); + struct x86_reg dst = get_xmm_writable(cp, arg0); + + sse_mulps(cp->func, dst, arg1); + + store_dest(cp, &op->Dst[0], dst); + return TRUE; +} + + +static boolean emit_MAD( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg arg1 = fetch_src(cp, &op->Src[1]); + struct x86_reg arg2 = fetch_src(cp, &op->Src[2]); + + /* If we can't clobber old contents of arg0, get a temporary & copy + * it there, then clobber it... + */ + arg0 = get_xmm_writable(cp, arg0); + + sse_mulps(cp->func, arg0, arg1); + sse_addps(cp->func, arg0, arg2); + store_dest(cp, &op->Dst[0], arg0); + return TRUE; +} + + + +/* A wrapper for powf(). + * Makes sure it is cdecl and operates on floats. + */ +static float PIPE_CDECL _powerf( float x, float y ) +{ +#if FAST_MATH + return util_fast_pow(x, y); +#else + return powf( x, y ); +#endif +} + +#if FAST_MATH +static float PIPE_CDECL _exp2(float x) +{ + return util_fast_exp2(x); +} +#endif + + +/* Really not sufficient -- need to check for conditions that could + * generate inf/nan values, which will slow things down hugely. + */ +static boolean emit_POW( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ +#if 0 + x87_fld_src(cp, &op->Src[1], 0); /* a1.x */ + x87_fld_src(cp, &op->Src[0], 0); /* a0.x a1.x */ + x87_fyl2x(cp->func); /* a1*log2(a0) */ + + x87_emit_ex2( cp ); /* 2^(a1*log2(a0)) */ + + x87_fstp_dest4(cp, &op->Dst[0]); +#else + uint i; + + /* For absolute correctness, need to spill/invalidate all XMM regs + * too. + */ + for (i = 0; i < 8; i++) { + if (cp->xmm[i].dirty) + spill(cp, i); + aos_release_xmm_reg(cp, i); + } + + /* Push caller-save (ie scratch) regs. + */ + x86_cdecl_caller_push_regs( cp->func ); + + x86_lea( cp->func, cp->stack_ESP, x86_make_disp(cp->stack_ESP, -8) ); + + x87_fld_src( cp, &op->Src[1], 0 ); + x87_fstp( cp->func, x86_make_disp( cp->stack_ESP, 4 ) ); + x87_fld_src( cp, &op->Src[0], 0 ); + x87_fstp( cp->func, x86_make_disp( cp->stack_ESP, 0 ) ); + + /* tmp_EAX has been pushed & will be restored below */ + x86_mov_reg_imm( cp->func, cp->tmp_EAX, (unsigned long) _powerf ); + x86_call( cp->func, cp->tmp_EAX ); + + x86_lea( cp->func, cp->stack_ESP, x86_make_disp(cp->stack_ESP, 8) ); + + x86_cdecl_caller_pop_regs( cp->func ); + + /* Note retval on x87 stack: + */ + cp->func->x87_stack++; + + x87_fstp_dest4( cp, &op->Dst[0] ); +#endif + return TRUE; +} + + +#if FAST_MATH +static boolean emit_EXPBASE2( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + uint i; + + /* For absolute correctness, need to spill/invalidate all XMM regs + * too. + */ + for (i = 0; i < 8; i++) { + if (cp->xmm[i].dirty) + spill(cp, i); + aos_release_xmm_reg(cp, i); + } + + /* Push caller-save (ie scratch) regs. + */ + x86_cdecl_caller_push_regs( cp->func ); + + x86_lea( cp->func, cp->stack_ESP, x86_make_disp(cp->stack_ESP, -4) ); + + x87_fld_src( cp, &op->Src[0], 0 ); + x87_fstp( cp->func, x86_make_disp( cp->stack_ESP, 0 ) ); + + /* tmp_EAX has been pushed & will be restored below */ + x86_mov_reg_imm( cp->func, cp->tmp_EAX, (unsigned long) _exp2 ); + x86_call( cp->func, cp->tmp_EAX ); + + x86_lea( cp->func, cp->stack_ESP, x86_make_disp(cp->stack_ESP, 4) ); + + x86_cdecl_caller_pop_regs( cp->func ); + + /* Note retval on x87 stack: + */ + cp->func->x87_stack++; + + x87_fstp_dest4( cp, &op->Dst[0] ); + + return TRUE; +} +#endif + + +static boolean emit_RCP( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg dst = aos_get_xmm_reg(cp); + + if (cp->have_sse2) { + sse2_rcpss(cp->func, dst, arg0); + /* extend precision here... + */ + } + else { + struct x86_reg ones = aos_get_internal(cp, IMM_ONES); + sse_movss(cp->func, dst, ones); + sse_divss(cp->func, dst, arg0); + } + + store_scalar_dest(cp, &op->Dst[0], dst); + return TRUE; +} + + +/* Although rsqrtps() and rcpps() are low precision on some/all SSE + * implementations, it is possible to improve its precision at + * fairly low cost, using a newton/raphson step, as below: + * + * x1 = 2 * rcpps(a) - a * rcpps(a) * rcpps(a) + * x1 = 0.5 * rsqrtps(a) * [3.0 - (a * rsqrtps(a))* rsqrtps(a)] + * or: + * x1 = rsqrtps(a) * [1.5 - .5 * a * rsqrtps(a) * rsqrtps(a)] + * + * + * See: http://softwarecommunity.intel.com/articles/eng/1818.htm + */ +static boolean emit_RSQ( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + if (0) { + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg r = aos_get_xmm_reg(cp); + sse_rsqrtss(cp->func, r, arg0); + store_scalar_dest(cp, &op->Dst[0], r); + return TRUE; + } + else { + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg r = aos_get_xmm_reg(cp); + + struct x86_reg neg_half = get_reg_ptr( cp, AOS_FILE_INTERNAL, IMM_RSQ ); + struct x86_reg one_point_five = x86_make_disp( neg_half, 4 ); + struct x86_reg src = get_xmm_writable( cp, arg0 ); + struct x86_reg neg = aos_get_internal(cp, IMM_NEGS); + struct x86_reg tmp = aos_get_xmm_reg(cp); + + sse_movaps(cp->func, tmp, src); + sse_mulps(cp->func, tmp, neg); + sse_maxps(cp->func, tmp, src); + + sse_rsqrtss( cp->func, r, tmp ); /* rsqrtss(a) */ + sse_mulss( cp->func, tmp, neg_half ); /* -.5 * a */ + sse_mulss( cp->func, tmp, r ); /* -.5 * a * r */ + sse_mulss( cp->func, tmp, r ); /* -.5 * a * r * r */ + sse_addss( cp->func, tmp, one_point_five ); /* 1.5 - .5 * a * r * r */ + sse_mulss( cp->func, r, tmp ); /* r * (1.5 - .5 * a * r * r) */ + + store_scalar_dest(cp, &op->Dst[0], r); + + aos_release_xmm_reg(cp, tmp.idx); + + return TRUE; + } +} + + +static boolean emit_SGE( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg arg1 = fetch_src(cp, &op->Src[1]); + struct x86_reg ones = aos_get_internal(cp, IMM_ONES); + struct x86_reg dst = get_xmm_writable(cp, arg0); + + sse_cmpps(cp->func, dst, arg1, cc_NotLessThan); + sse_andps(cp->func, dst, ones); + + store_dest(cp, &op->Dst[0], dst); + return TRUE; +} + +static boolean emit_SIN( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + x87_fld_src(cp, &op->Src[0], 0); + x87_fsin(cp->func); + x87_fstp_dest4(cp, &op->Dst[0]); + return TRUE; +} + + + +static boolean emit_SLT( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg arg1 = fetch_src(cp, &op->Src[1]); + struct x86_reg ones = aos_get_internal(cp, IMM_ONES); + struct x86_reg dst = get_xmm_writable(cp, arg0); + + sse_cmpps(cp->func, dst, arg1, cc_LessThan); + sse_andps(cp->func, dst, ones); + + store_dest(cp, &op->Dst[0], dst); + return TRUE; +} + +static boolean emit_SUB( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg arg1 = fetch_src(cp, &op->Src[1]); + struct x86_reg dst = get_xmm_writable(cp, arg0); + + sse_subps(cp->func, dst, arg1); + + store_dest(cp, &op->Dst[0], dst); + return TRUE; +} + +static boolean emit_TRUNC( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg tmp0 = aos_get_xmm_reg(cp); + + sse2_cvttps2dq(cp->func, tmp0, arg0); + sse2_cvtdq2ps(cp->func, tmp0, tmp0); + + store_dest(cp, &op->Dst[0], tmp0); + return TRUE; +} + +static boolean emit_XPD( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) +{ + struct x86_reg arg0 = fetch_src(cp, &op->Src[0]); + struct x86_reg arg1 = fetch_src(cp, &op->Src[1]); + struct x86_reg tmp0 = aos_get_xmm_reg(cp); + struct x86_reg tmp1 = aos_get_xmm_reg(cp); + + emit_pshufd(cp, tmp1, arg1, SHUF(Y, Z, X, W)); + sse_mulps(cp->func, tmp1, arg0); + emit_pshufd(cp, tmp0, arg0, SHUF(Y, Z, X, W)); + sse_mulps(cp->func, tmp0, arg1); + sse_subps(cp->func, tmp1, tmp0); + sse_shufps(cp->func, tmp1, tmp1, SHUF(Y, Z, X, W)); + +/* dst[2] = arg0[0] * arg1[1] - arg0[1] * arg1[0]; */ +/* dst[0] = arg0[1] * arg1[2] - arg0[2] * arg1[1]; */ +/* dst[1] = arg0[2] * arg1[0] - arg0[0] * arg1[2]; */ +/* dst[3] is undef */ + + + aos_release_xmm_reg(cp, tmp0.idx); + store_dest(cp, &op->Dst[0], tmp1); + return TRUE; +} + + + +static boolean +emit_instruction( struct aos_compilation *cp, + struct tgsi_full_instruction *inst ) +{ + x87_assert_stack_empty(cp->func); + + switch( inst->Instruction.Opcode ) { + case TGSI_OPCODE_MOV: + return emit_MOV( cp, inst ); + + case TGSI_OPCODE_LIT: + return emit_LIT(cp, inst); + + case TGSI_OPCODE_RCP: + return emit_RCP(cp, inst); + + case TGSI_OPCODE_RSQ: + return emit_RSQ(cp, inst); + + case TGSI_OPCODE_EXP: + /*return emit_EXP(cp, inst);*/ + return FALSE; + + case TGSI_OPCODE_LOG: + /*return emit_LOG(cp, inst);*/ + return FALSE; + + case TGSI_OPCODE_MUL: + return emit_MUL(cp, inst); + + case TGSI_OPCODE_ADD: + return emit_ADD(cp, inst); + + case TGSI_OPCODE_DP3: + return emit_DP3(cp, inst); + + case TGSI_OPCODE_DP4: + return emit_DP4(cp, inst); + + case TGSI_OPCODE_DST: + return emit_DST(cp, inst); + + case TGSI_OPCODE_MIN: + return emit_MIN(cp, inst); + + case TGSI_OPCODE_MAX: + return emit_MAX(cp, inst); + + case TGSI_OPCODE_SLT: + return emit_SLT(cp, inst); + + case TGSI_OPCODE_SGE: + return emit_SGE(cp, inst); + + case TGSI_OPCODE_MAD: + return emit_MAD(cp, inst); + + case TGSI_OPCODE_SUB: + return emit_SUB(cp, inst); + + case TGSI_OPCODE_LRP: + /*return emit_LERP(cp, inst);*/ + return FALSE; + + case TGSI_OPCODE_FRC: + return emit_FRC(cp, inst); + + case TGSI_OPCODE_CLAMP: + /*return emit_CLAMP(cp, inst);*/ + return FALSE; + + case TGSI_OPCODE_FLR: + return emit_FLR(cp, inst); + + case TGSI_OPCODE_ROUND: + return emit_RND(cp, inst); + + case TGSI_OPCODE_EX2: +#if FAST_MATH + return emit_EXPBASE2(cp, inst); +#elif 0 + /* this seems to fail for "larger" exponents. + * See glean tvertProg1's EX2 test. + */ + return emit_EX2(cp, inst); +#else + return FALSE; +#endif + + case TGSI_OPCODE_LG2: + return emit_LG2(cp, inst); + + case TGSI_OPCODE_POW: + return emit_POW(cp, inst); + + case TGSI_OPCODE_XPD: + return emit_XPD(cp, inst); + + case TGSI_OPCODE_ABS: + return emit_ABS(cp, inst); + + case TGSI_OPCODE_DPH: + return emit_DPH(cp, inst); + + case TGSI_OPCODE_COS: + return emit_COS(cp, inst); + + case TGSI_OPCODE_SIN: + return emit_SIN(cp, inst); + + case TGSI_OPCODE_TRUNC: + return emit_TRUNC(cp, inst); + + case TGSI_OPCODE_END: + return TRUE; + + default: + return FALSE; + } +} + + +static boolean emit_viewport( struct aos_compilation *cp ) +{ + struct x86_reg pos = aos_get_shader_reg_xmm(cp, + TGSI_FILE_OUTPUT, + cp->vaos->draw->vs.position_output ); + + struct x86_reg scale = x86_make_disp(cp->machine_EDX, + Offset(struct aos_machine, scale)); + + struct x86_reg translate = x86_make_disp(cp->machine_EDX, + Offset(struct aos_machine, translate)); + + sse_mulps(cp->func, pos, scale); + sse_addps(cp->func, pos, translate); + + aos_adopt_xmm_reg( cp, + pos, + TGSI_FILE_OUTPUT, + cp->vaos->draw->vs.position_output, + TRUE ); + return TRUE; +} + + +/* This is useful to be able to see the results on softpipe. Doesn't + * do proper clipping, just assumes the backend can do it during + * rasterization -- for debug only... + */ +static boolean emit_rhw_viewport( struct aos_compilation *cp ) +{ + struct x86_reg tmp = aos_get_xmm_reg(cp); + struct x86_reg pos = aos_get_shader_reg_xmm(cp, + TGSI_FILE_OUTPUT, + cp->vaos->draw->vs.position_output); + + struct x86_reg scale = x86_make_disp(cp->machine_EDX, + Offset(struct aos_machine, scale)); + + struct x86_reg translate = x86_make_disp(cp->machine_EDX, + Offset(struct aos_machine, translate)); + + + + emit_pshufd(cp, tmp, pos, SHUF(W, W, W, W)); + sse2_rcpss(cp->func, tmp, tmp); + sse_shufps(cp->func, tmp, tmp, SHUF(X, X, X, X)); + + sse_mulps(cp->func, pos, scale); + sse_mulps(cp->func, pos, tmp); + sse_addps(cp->func, pos, translate); + + /* Set pos[3] = w + */ + mask_write(cp, pos, tmp, TGSI_WRITEMASK_W); + + aos_adopt_xmm_reg( cp, + pos, + TGSI_FILE_OUTPUT, + cp->vaos->draw->vs.position_output, + TRUE ); + return TRUE; +} + + +#if 0 +static boolean note_immediate( struct aos_compilation *cp, + struct tgsi_full_immediate *imm ) +{ + unsigned pos = cp->num_immediates++; + unsigned j; + + assert( imm->Immediate.NrTokens <= 4 + 1 ); + for (j = 0; j < imm->Immediate.NrTokens - 1; j++) { + cp->vaos->machine->immediate[pos][j] = imm->u[j].Float; + } + + return TRUE; +} +#endif + + + + +static void find_last_write_outputs( struct aos_compilation *cp ) +{ + struct tgsi_parse_context parse; + unsigned this_instruction = 0; + unsigned i; + + tgsi_parse_init( &parse, cp->vaos->base.vs->state.tokens ); + + while (!tgsi_parse_end_of_tokens( &parse )) { + + tgsi_parse_token( &parse ); + + if (parse.FullToken.Token.Type != TGSI_TOKEN_TYPE_INSTRUCTION) + continue; + + for (i = 0; i < TGSI_FULL_MAX_DST_REGISTERS; i++) { + if (parse.FullToken.FullInstruction.Dst[i].Register.File == + TGSI_FILE_OUTPUT) + { + unsigned idx = parse.FullToken.FullInstruction.Dst[i].Register.Index; + cp->output_last_write[idx] = this_instruction; + } + } + + this_instruction++; + } + + tgsi_parse_free( &parse ); +} + + +#define ARG_MACHINE 1 +#define ARG_START_ELTS 2 +#define ARG_COUNT 3 +#define ARG_OUTBUF 4 + + +static boolean build_vertex_program( struct draw_vs_varient_aos_sse *varient, + boolean linear ) +{ + struct tgsi_parse_context parse; + struct aos_compilation cp; + unsigned fixup, label; + + util_init_math(); + + tgsi_parse_init( &parse, varient->base.vs->state.tokens ); + + memset(&cp, 0, sizeof(cp)); + + cp.insn_counter = 1; + cp.vaos = varient; + cp.have_sse2 = 1; + cp.func = &varient->func[ linear ? 0 : 1 ]; + + cp.tmp_EAX = x86_make_reg(file_REG32, reg_AX); + cp.idx_EBX = x86_make_reg(file_REG32, reg_BX); + cp.outbuf_ECX = x86_make_reg(file_REG32, reg_CX); + cp.machine_EDX = x86_make_reg(file_REG32, reg_DX); + cp.count_ESI = x86_make_reg(file_REG32, reg_SI); + cp.temp_EBP = x86_make_reg(file_REG32, reg_BP); + cp.stack_ESP = x86_make_reg( file_REG32, reg_SP ); + + x86_init_func(cp.func); + + find_last_write_outputs(&cp); + + x86_push(cp.func, cp.idx_EBX); + x86_push(cp.func, cp.count_ESI); + x86_push(cp.func, cp.temp_EBP); + + + /* Load arguments into regs: + */ + x86_mov(cp.func, cp.machine_EDX, x86_fn_arg(cp.func, ARG_MACHINE)); + x86_mov(cp.func, cp.idx_EBX, x86_fn_arg(cp.func, ARG_START_ELTS)); + x86_mov(cp.func, cp.count_ESI, x86_fn_arg(cp.func, ARG_COUNT)); + x86_mov(cp.func, cp.outbuf_ECX, x86_fn_arg(cp.func, ARG_OUTBUF)); + + + /* Compare count to zero and possibly bail. + */ + x86_xor(cp.func, cp.tmp_EAX, cp.tmp_EAX); + x86_cmp(cp.func, cp.count_ESI, cp.tmp_EAX); + fixup = x86_jcc_forward(cp.func, cc_E); + + + save_fpu_state( &cp ); + set_fpu_round_nearest( &cp ); + + aos_init_inputs( &cp, linear ); + + cp.x86_reg[0] = 0; + cp.x86_reg[1] = 0; + + /* Note address for loop jump + */ + label = x86_get_label(cp.func); + { + /* Fetch inputs... TODO: fetch lazily... + */ + if (!aos_fetch_inputs( &cp, linear )) + goto fail; + + /* Emit the shader: + */ + while( !tgsi_parse_end_of_tokens( &parse ) && !cp.error ) + { + tgsi_parse_token( &parse ); + + switch (parse.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_IMMEDIATE: +#if 0 + if (!note_immediate( &cp, &parse.FullToken.FullImmediate )) + goto fail; +#endif + break; + + case TGSI_TOKEN_TYPE_INSTRUCTION: + if (DISASSEM) + tgsi_dump_instruction( &parse.FullToken.FullInstruction, cp.insn_counter ); + + if (!emit_instruction( &cp, &parse.FullToken.FullInstruction )) + goto fail; + break; + } + + x87_assert_stack_empty(cp.func); + cp.insn_counter++; + + if (DISASSEM) + debug_printf("\n"); + } + + + { + unsigned i; + for (i = 0; i < 8; i++) { + if (cp.xmm[i].file != TGSI_FILE_OUTPUT) { + cp.xmm[i].file = TGSI_FILE_NULL; + cp.xmm[i].dirty = 0; + } + } + } + + if (cp.error) + goto fail; + + if (cp.vaos->base.key.clip) { + /* not really handling clipping, just do the rhw so we can + * see the results... + */ + emit_rhw_viewport(&cp); + } + else if (cp.vaos->base.key.viewport) { + emit_viewport(&cp); + } + + /* Emit output... TODO: do this eagerly after the last write to a + * given output. + */ + if (!aos_emit_outputs( &cp )) + goto fail; + + + /* Next vertex: + */ + x86_lea(cp.func, + cp.outbuf_ECX, + x86_make_disp(cp.outbuf_ECX, + cp.vaos->base.key.output_stride)); + + /* Incr index + */ + aos_incr_inputs( &cp, linear ); + } + /* decr count, loop if not zero + */ + x86_dec(cp.func, cp.count_ESI); + x86_jcc(cp.func, cc_NZ, label); + + restore_fpu_state(&cp); + + /* Land forward jump here: + */ + x86_fixup_fwd_jump(cp.func, fixup); + + /* Exit mmx state? + */ + if (cp.func->need_emms) + mmx_emms(cp.func); + + x86_pop(cp.func, cp.temp_EBP); + x86_pop(cp.func, cp.count_ESI); + x86_pop(cp.func, cp.idx_EBX); + + x87_assert_stack_empty(cp.func); + x86_ret(cp.func); + + tgsi_parse_free( &parse ); + return !cp.error; + + fail: + tgsi_parse_free( &parse ); + return FALSE; +} + + +/** cast wrapper */ +static INLINE struct draw_vs_varient_aos_sse * +draw_vs_varient_aos_sse(struct draw_vs_varient *varient) +{ + return (struct draw_vs_varient_aos_sse *) varient; +} + + +static void vaos_set_buffer( struct draw_vs_varient *varient, + unsigned buf, + const void *ptr, + unsigned stride, + unsigned max_stride) +{ + struct draw_vs_varient_aos_sse *vaos = draw_vs_varient_aos_sse(varient); + + if (buf < vaos->nr_vb) { + vaos->buffer[buf].base_ptr = (char *)ptr; + vaos->buffer[buf].stride = stride; + } + + if (0) debug_printf("%s %d/%d: %p %d\n", __FUNCTION__, buf, vaos->nr_vb, ptr, stride); +} + + + +static void PIPE_CDECL vaos_run_elts( struct draw_vs_varient *varient, + const unsigned *elts, + unsigned count, + void *output_buffer ) +{ + struct draw_vs_varient_aos_sse *vaos = draw_vs_varient_aos_sse(varient); + struct aos_machine *machine = vaos->draw->vs.aos_machine; + unsigned i; + + if (0) debug_printf("%s %d\n", __FUNCTION__, count); + + machine->internal[IMM_PSIZE][0] = vaos->draw->rasterizer->point_size; + for (i = 0; i < PIPE_MAX_CONSTANT_BUFFERS; i++) { + machine->constants[i] = vaos->draw->vs.aligned_constants[i]; + } + machine->immediates = vaos->base.vs->immediates; + machine->buffer = vaos->buffer; + + vaos->gen_run_elts( machine, + elts, + count, + output_buffer ); +} + +static void PIPE_CDECL vaos_run_linear( struct draw_vs_varient *varient, + unsigned start, + unsigned count, + void *output_buffer ) +{ + struct draw_vs_varient_aos_sse *vaos = draw_vs_varient_aos_sse(varient); + struct aos_machine *machine = vaos->draw->vs.aos_machine; + unsigned i; + + if (0) debug_printf("%s %d %d const: %x\n", __FUNCTION__, start, count, + vaos->base.key.const_vbuffers); + + machine->internal[IMM_PSIZE][0] = vaos->draw->rasterizer->point_size; + for (i = 0; i < PIPE_MAX_CONSTANT_BUFFERS; i++) { + machine->constants[i] = vaos->draw->vs.aligned_constants[i]; + } + machine->immediates = vaos->base.vs->immediates; + machine->buffer = vaos->buffer; + + vaos->gen_run_linear( machine, + start, + count, + output_buffer ); + + /* Sanity spot checks to make sure we didn't trash our constants */ + assert(machine->internal[IMM_ONES][0] == 1.0f); + assert(machine->internal[IMM_IDENTITY][0] == 0.0f); + assert(machine->internal[IMM_NEGS][0] == -1.0f); +} + + + +static void vaos_destroy( struct draw_vs_varient *varient ) +{ + struct draw_vs_varient_aos_sse *vaos = draw_vs_varient_aos_sse(varient); + + FREE( vaos->buffer ); + + x86_release_func( &vaos->func[0] ); + x86_release_func( &vaos->func[1] ); + + FREE(vaos); +} + + + +static struct draw_vs_varient *varient_aos_sse( struct draw_vertex_shader *vs, + const struct draw_vs_varient_key *key ) +{ + unsigned i; + struct draw_vs_varient_aos_sse *vaos = CALLOC_STRUCT(draw_vs_varient_aos_sse); + + if (!vaos) + goto fail; + + vaos->base.key = *key; + vaos->base.vs = vs; + vaos->base.set_buffer = vaos_set_buffer; + vaos->base.destroy = vaos_destroy; + vaos->base.run_linear = vaos_run_linear; + vaos->base.run_elts = vaos_run_elts; + + vaos->draw = vs->draw; + + for (i = 0; i < key->nr_inputs; i++) + vaos->nr_vb = MAX2( vaos->nr_vb, key->element[i].in.buffer + 1 ); + + vaos->buffer = MALLOC( vaos->nr_vb * sizeof(vaos->buffer[0]) ); + if (!vaos->buffer) + goto fail; + + if (0) + debug_printf("nr_vb: %d const: %x\n", vaos->nr_vb, vaos->base.key.const_vbuffers); + +#if 0 + tgsi_dump(vs->state.tokens, 0); +#endif + + if (!build_vertex_program( vaos, TRUE )) + goto fail; + + if (!build_vertex_program( vaos, FALSE )) + goto fail; + + vaos->gen_run_linear = (vaos_run_linear_func)x86_get_func(&vaos->func[0]); + if (!vaos->gen_run_linear) + goto fail; + + vaos->gen_run_elts = (vaos_run_elts_func)x86_get_func(&vaos->func[1]); + if (!vaos->gen_run_elts) + goto fail; + + return &vaos->base; + + fail: + if (vaos && vaos->buffer) + FREE(vaos->buffer); + + if (vaos) + x86_release_func( &vaos->func[0] ); + + if (vaos) + x86_release_func( &vaos->func[1] ); + + FREE(vaos); + + return NULL; +} + + +struct draw_vs_varient * +draw_vs_create_varient_aos_sse( struct draw_vertex_shader *vs, + const struct draw_vs_varient_key *key ) +{ + struct draw_vs_varient *varient = varient_aos_sse( vs, key ); + + if (varient == NULL) { + varient = draw_vs_create_varient_generic( vs, key ); + } + + return varient; +} + + + +#endif /* PIPE_ARCH_X86 */ diff --git a/src/gallium/auxiliary/draw/draw_vs_aos.h b/src/gallium/auxiliary/draw/draw_vs_aos.h new file mode 100644 index 0000000..68e8295 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_vs_aos.h @@ -0,0 +1,255 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef DRAW_VS_AOS_H +#define DRAW_VS_AOS_H + +#include "pipe/p_config.h" +#include "tgsi/tgsi_exec.h" +#include "draw_vs.h" + +#ifdef PIPE_ARCH_X86 + +struct tgsi_token; +struct x86_function; + +#include "pipe/p_state.h" +#include "rtasm/rtasm_x86sse.h" + + + + + +#define X 0 +#define Y 1 +#define Z 2 +#define W 3 + +#define MAX_INPUTS PIPE_MAX_ATTRIBS +#define MAX_OUTPUTS PIPE_MAX_SHADER_OUTPUTS +#define MAX_TEMPS TGSI_EXEC_NUM_TEMPS +#define MAX_CONSTANTS 1024 /** only used for sanity checking */ +#define MAX_IMMEDIATES 1024 /** only used for sanity checking */ +#define MAX_INTERNALS 8 /** see IMM_x values below */ + +#define AOS_FILE_INTERNAL TGSI_FILE_COUNT + +#define FPU_RND_NEG 1 +#define FPU_RND_NEAREST 2 + +struct aos_machine; +typedef void (PIPE_CDECL *lit_func)( struct aos_machine *, + float *result, + const float *in, + unsigned count ); + +void PIPE_CDECL aos_do_lit( struct aos_machine *machine, + float *result, + const float *in, + unsigned count ); + +struct shine_tab { + float exponent; + float values[258]; + unsigned last_used; +}; + +struct lit_info { + lit_func func; + struct shine_tab *shine_tab; +}; + +#define MAX_SHINE_TAB 4 +#define MAX_LIT_INFO 16 + +struct aos_buffer { + const void *base_ptr; + unsigned stride; + void *ptr; /* updated per vertex */ +}; + + + + +/* This is the temporary storage used by all the aos_sse vs varients. + * Create one per context and reuse by passing a pointer in at + * vs_varient creation?? + */ +struct aos_machine { + float input [MAX_INPUTS ][4]; + float output [MAX_OUTPUTS ][4]; + float temp [MAX_TEMPS ][4]; + float internal [MAX_INTERNALS ][4]; + + float scale[4]; /* viewport */ + float translate[4]; /* viewport */ + + float tmp[2][4]; /* scratch space for LIT */ + + struct shine_tab shine_tab[MAX_SHINE_TAB]; + struct lit_info lit_info[MAX_LIT_INFO]; + unsigned now; + + + ushort fpu_rnd_nearest; + ushort fpu_rnd_neg_inf; + ushort fpu_restore; + ushort fpucntl; /* one of FPU_* above */ + + const float (*immediates)[4]; /* points to shader data */ + const void *constants[PIPE_MAX_CONSTANT_BUFFERS]; /* points to draw data */ + + const struct aos_buffer *buffer; /* points to ? */ +}; + + + + +struct aos_compilation { + struct x86_function *func; + struct draw_vs_varient_aos_sse *vaos; + + unsigned insn_counter; + unsigned num_immediates; + unsigned count; + unsigned lit_count; + + struct { + unsigned idx:16; + unsigned file:8; + unsigned dirty:8; + unsigned last_used; + } xmm[8]; + + unsigned x86_reg[2]; /* one of X86_* */ + + boolean input_fetched[PIPE_MAX_ATTRIBS]; + unsigned output_last_write[PIPE_MAX_ATTRIBS]; + + boolean have_sse2; + boolean error; + short fpucntl; + + /* these are actually known values, but putting them in a struct + * like this is helpful to keep them in sync across the file. + */ + struct x86_reg tmp_EAX; + struct x86_reg idx_EBX; /* either start+i or &elt[i] */ + struct x86_reg outbuf_ECX; + struct x86_reg machine_EDX; + struct x86_reg count_ESI; /* decrements to zero */ + struct x86_reg temp_EBP; + struct x86_reg stack_ESP; +}; + +struct x86_reg aos_get_xmm_reg( struct aos_compilation *cp ); +void aos_release_xmm_reg( struct aos_compilation *cp, unsigned idx ); + +void aos_adopt_xmm_reg( struct aos_compilation *cp, + struct x86_reg reg, + unsigned file, + unsigned idx, + unsigned dirty ); + +void aos_spill_all( struct aos_compilation *cp ); + +struct x86_reg aos_get_shader_reg( struct aos_compilation *cp, + unsigned file, + unsigned idx ); + +boolean aos_init_inputs( struct aos_compilation *cp, boolean linear ); +boolean aos_fetch_inputs( struct aos_compilation *cp, boolean linear ); +boolean aos_incr_inputs( struct aos_compilation *cp, boolean linear ); + +boolean aos_emit_outputs( struct aos_compilation *cp ); + + +#define IMM_ONES 0 /* 1, 1,1,1 */ +#define IMM_SWZ 1 /* 1,-1,0, 0xffffffff */ +#define IMM_IDENTITY 2 /* 0, 0,0,1 */ +#define IMM_INV_255 3 /* 1/255, 1/255, 1/255, 1/255 */ +#define IMM_255 4 /* 255, 255, 255, 255 */ +#define IMM_NEGS 5 /* -1,-1,-1,-1 */ +#define IMM_RSQ 6 /* -.5,1.5,_,_ */ +#define IMM_PSIZE 7 /* not really an immediate - updated each run */ + +struct x86_reg aos_get_internal( struct aos_compilation *cp, + unsigned imm ); +struct x86_reg aos_get_internal_xmm( struct aos_compilation *cp, + unsigned imm ); + + +#define AOS_ERROR(cp, msg) \ +do { \ + if (0) debug_printf("%s: x86 translation failed: %s\n", __FUNCTION__, msg); \ + cp->error = 1; \ +} while (0) + + +#define X86_NULL 0 +#define X86_IMMEDIATES 1 +#define X86_CONSTANTS 2 +#define X86_BUFFERS 3 + +struct x86_reg aos_get_x86( struct aos_compilation *cp, + unsigned which_reg, + unsigned value ); + + +typedef void (PIPE_CDECL *vaos_run_elts_func)( struct aos_machine *, + const unsigned *elts, + unsigned count, + void *output_buffer); + +typedef void (PIPE_CDECL *vaos_run_linear_func)( struct aos_machine *, + unsigned start, + unsigned count, + void *output_buffer); + + +struct draw_vs_varient_aos_sse { + struct draw_vs_varient base; + struct draw_context *draw; + + struct aos_buffer *buffer; + unsigned nr_vb; + + vaos_run_linear_func gen_run_linear; + vaos_run_elts_func gen_run_elts; + + + struct x86_function func[2]; +}; + + +#endif + +#endif + diff --git a/src/gallium/auxiliary/draw/draw_vs_aos_io.c b/src/gallium/auxiliary/draw/draw_vs_aos_io.c new file mode 100644 index 0000000..8f8bbe7 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_vs_aos_io.c @@ -0,0 +1,460 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "util/u_memory.h" +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "tgsi/tgsi_exec.h" +#include "draw_vs.h" +#include "draw_vs_aos.h" +#include "draw_vertex.h" + +#include "rtasm/rtasm_x86sse.h" + +#ifdef PIPE_ARCH_X86 + +/* Note - don't yet have to worry about interacting with the code in + * draw_vs_aos.c as there is no intermingling of generated code... + * That may have to change, we'll see. + */ +static void emit_load_R32G32B32A32( struct aos_compilation *cp, + struct x86_reg data, + struct x86_reg src_ptr ) +{ + sse_movups(cp->func, data, src_ptr); +} + +static void emit_load_R32G32B32( struct aos_compilation *cp, + struct x86_reg data, + struct x86_reg src_ptr ) +{ +#if 1 + sse_movss(cp->func, data, x86_make_disp(src_ptr, 8)); + /* data = z ? ? ? */ + sse_shufps(cp->func, data, aos_get_internal_xmm( cp, IMM_IDENTITY ), SHUF(X,Y,Z,W) ); + /* data = z ? 0 1 */ + sse_shufps(cp->func, data, data, SHUF(Y,Z,X,W) ); + /* data = ? 0 z 1 */ + sse_movlps(cp->func, data, src_ptr); + /* data = x y z 1 */ +#else + sse_movups(cp->func, data, src_ptr); + /* data = x y z ? */ + sse2_pshufd(cp->func, data, data, SHUF(W,X,Y,Z) ); + /* data = ? x y z */ + sse_movss(cp->func, data, aos_get_internal_xmm( cp, IMM_ONES ) ); + /* data = 1 x y z */ + sse2_pshufd(cp->func, data, data, SHUF(Y,Z,W,X) ); + /* data = x y z 1 */ +#endif +} + +static void emit_load_R32G32( struct aos_compilation *cp, + struct x86_reg data, + struct x86_reg src_ptr ) +{ + sse_movups(cp->func, data, aos_get_internal_xmm( cp, IMM_IDENTITY ) ); + sse_movlps(cp->func, data, src_ptr); +} + + +static void emit_load_R32( struct aos_compilation *cp, + struct x86_reg data, + struct x86_reg src_ptr ) +{ + sse_movss(cp->func, data, src_ptr); + sse_orps(cp->func, data, aos_get_internal_xmm( cp, IMM_IDENTITY ) ); +} + + +static void emit_load_R8G8B8A8_UNORM( struct aos_compilation *cp, + struct x86_reg data, + struct x86_reg src_ptr ) +{ + sse_movss(cp->func, data, src_ptr); + sse2_punpcklbw(cp->func, data, aos_get_internal_xmm( cp, IMM_IDENTITY )); + sse2_punpcklbw(cp->func, data, aos_get_internal_xmm( cp, IMM_IDENTITY )); + sse2_cvtdq2ps(cp->func, data, data); + sse_mulps(cp->func, data, aos_get_internal(cp, IMM_INV_255)); +} + + + +/* Extended swizzles? Maybe later. + */ +static void emit_swizzle( struct aos_compilation *cp, + struct x86_reg dest, + struct x86_reg src, + ubyte shuffle ) +{ + sse_shufps(cp->func, dest, src, shuffle); +} + + + +static boolean get_buffer_ptr( struct aos_compilation *cp, + boolean linear, + unsigned buf_idx, + struct x86_reg elt, + struct x86_reg ptr) +{ + struct x86_reg buf = x86_make_disp(aos_get_x86( cp, 0, X86_BUFFERS ), + buf_idx * sizeof(struct aos_buffer)); + + struct x86_reg buf_stride = x86_make_disp(buf, + Offset(struct aos_buffer, stride)); + if (linear) { + struct x86_reg buf_ptr = x86_make_disp(buf, + Offset(struct aos_buffer, ptr)); + + + /* Calculate pointer to current attrib: + */ + x86_mov(cp->func, ptr, buf_ptr); + x86_mov(cp->func, elt, buf_stride); + x86_add(cp->func, elt, ptr); + if (buf_idx == 0) sse_prefetchnta(cp->func, x86_make_disp(elt, 192)); + x86_mov(cp->func, buf_ptr, elt); + } + else { + struct x86_reg buf_base_ptr = x86_make_disp(buf, + Offset(struct aos_buffer, base_ptr)); + + + /* Calculate pointer to current attrib: + */ + x86_mov(cp->func, ptr, buf_stride); + x86_imul(cp->func, ptr, elt); + x86_add(cp->func, ptr, buf_base_ptr); + } + + cp->insn_counter++; + + return TRUE; +} + + +static boolean load_input( struct aos_compilation *cp, + unsigned idx, + struct x86_reg bufptr ) +{ + unsigned format = cp->vaos->base.key.element[idx].in.format; + unsigned offset = cp->vaos->base.key.element[idx].in.offset; + struct x86_reg dataXMM = aos_get_xmm_reg(cp); + + /* Figure out source pointer address: + */ + struct x86_reg src = x86_make_disp(bufptr, offset); + + aos_adopt_xmm_reg( cp, + dataXMM, + TGSI_FILE_INPUT, + idx, + TRUE ); + + switch (format) { + case PIPE_FORMAT_R32_FLOAT: + emit_load_R32(cp, dataXMM, src); + break; + case PIPE_FORMAT_R32G32_FLOAT: + emit_load_R32G32(cp, dataXMM, src); + break; + case PIPE_FORMAT_R32G32B32_FLOAT: + emit_load_R32G32B32(cp, dataXMM, src); + break; + case PIPE_FORMAT_R32G32B32A32_FLOAT: + emit_load_R32G32B32A32(cp, dataXMM, src); + break; + case PIPE_FORMAT_A8R8G8B8_UNORM: + emit_load_R8G8B8A8_UNORM(cp, dataXMM, src); + emit_swizzle(cp, dataXMM, dataXMM, SHUF(Z,Y,X,W)); + break; + case PIPE_FORMAT_R8G8B8A8_UNORM: + emit_load_R8G8B8A8_UNORM(cp, dataXMM, src); + break; + default: + AOS_ERROR(cp, "unhandled input format"); + return FALSE; + } + + return TRUE; +} + +static boolean load_inputs( struct aos_compilation *cp, + unsigned buffer, + struct x86_reg ptr ) +{ + unsigned i; + + for (i = 0; i < cp->vaos->base.key.nr_inputs; i++) { + if (cp->vaos->base.key.element[i].in.buffer == buffer) { + + if (!load_input( cp, i, ptr )) + return FALSE; + + cp->insn_counter++; + } + } + + return TRUE; +} + +boolean aos_init_inputs( struct aos_compilation *cp, boolean linear ) +{ + unsigned i; + for (i = 0; i < cp->vaos->nr_vb; i++) { + struct x86_reg buf = x86_make_disp(aos_get_x86( cp, 0, X86_BUFFERS ), + i * sizeof(struct aos_buffer)); + + struct x86_reg buf_base_ptr = x86_make_disp(buf, + Offset(struct aos_buffer, base_ptr)); + + if (cp->vaos->base.key.const_vbuffers & (1<tmp_EAX; + + x86_mov(cp->func, ptr, buf_base_ptr); + + /* Load all inputs for this constant vertex buffer + */ + load_inputs( cp, i, x86_deref(ptr) ); + + /* Then just force them out to aos_machine.input[] + */ + aos_spill_all( cp ); + + } + else if (linear) { + + struct x86_reg elt = cp->idx_EBX; + struct x86_reg ptr = cp->tmp_EAX; + + struct x86_reg buf_stride = x86_make_disp(buf, + Offset(struct aos_buffer, stride)); + + struct x86_reg buf_ptr = x86_make_disp(buf, + Offset(struct aos_buffer, ptr)); + + + /* Calculate pointer to current attrib: + */ + x86_mov(cp->func, ptr, buf_stride); + x86_imul(cp->func, ptr, elt); + x86_add(cp->func, ptr, buf_base_ptr); + + + /* In the linear case, keep the buffer pointer instead of the + * index number. + */ + if (cp->vaos->nr_vb == 1) + x86_mov( cp->func, elt, ptr ); + else + x86_mov( cp->func, buf_ptr, ptr ); + + cp->insn_counter++; + } + } + + return TRUE; +} + +boolean aos_fetch_inputs( struct aos_compilation *cp, boolean linear ) +{ + unsigned j; + + for (j = 0; j < cp->vaos->nr_vb; j++) { + if (cp->vaos->base.key.const_vbuffers & (1<vaos->nr_vb == 1) { + load_inputs( cp, 0, cp->idx_EBX ); + } + else { + struct x86_reg elt = linear ? cp->idx_EBX : x86_deref(cp->idx_EBX); + struct x86_reg ptr = cp->tmp_EAX; + + if (!get_buffer_ptr( cp, linear, j, elt, ptr )) + return FALSE; + + if (!load_inputs( cp, j, ptr )) + return FALSE; + } + } + + return TRUE; +} + +boolean aos_incr_inputs( struct aos_compilation *cp, boolean linear ) +{ + if (linear && cp->vaos->nr_vb == 1) { + struct x86_reg stride = x86_make_disp(aos_get_x86( cp, 0, X86_BUFFERS ), + (0 * sizeof(struct aos_buffer) + + Offset(struct aos_buffer, stride))); + + x86_add(cp->func, cp->idx_EBX, stride); + sse_prefetchnta(cp->func, x86_make_disp(cp->idx_EBX, 192)); + } + else if (linear) { + /* Nothing to do */ + } + else { + x86_lea(cp->func, cp->idx_EBX, x86_make_disp(cp->idx_EBX, 4)); + } + + return TRUE; +} + + + + + + +static void emit_store_R32G32B32A32( struct aos_compilation *cp, + struct x86_reg dst_ptr, + struct x86_reg dataXMM ) +{ + sse_movups(cp->func, dst_ptr, dataXMM); +} + +static void emit_store_R32G32B32( struct aos_compilation *cp, + struct x86_reg dst_ptr, + struct x86_reg dataXMM ) +{ + sse_movlps(cp->func, dst_ptr, dataXMM); + sse_shufps(cp->func, dataXMM, dataXMM, SHUF(Z,Z,Z,Z) ); /* NOTE! destructive */ + sse_movss(cp->func, x86_make_disp(dst_ptr,8), dataXMM); +} + +static void emit_store_R32G32( struct aos_compilation *cp, + struct x86_reg dst_ptr, + struct x86_reg dataXMM ) +{ + sse_movlps(cp->func, dst_ptr, dataXMM); +} + +static void emit_store_R32( struct aos_compilation *cp, + struct x86_reg dst_ptr, + struct x86_reg dataXMM ) +{ + sse_movss(cp->func, dst_ptr, dataXMM); +} + + + +static void emit_store_R8G8B8A8_UNORM( struct aos_compilation *cp, + struct x86_reg dst_ptr, + struct x86_reg dataXMM ) +{ + sse_mulps(cp->func, dataXMM, aos_get_internal(cp, IMM_255)); + sse2_cvtps2dq(cp->func, dataXMM, dataXMM); + sse2_packssdw(cp->func, dataXMM, dataXMM); + sse2_packuswb(cp->func, dataXMM, dataXMM); + sse_movss(cp->func, dst_ptr, dataXMM); +} + + + + + +static boolean emit_output( struct aos_compilation *cp, + struct x86_reg ptr, + struct x86_reg dataXMM, + unsigned format ) +{ + switch (format) { + case EMIT_1F: + case EMIT_1F_PSIZE: + emit_store_R32(cp, ptr, dataXMM); + break; + case EMIT_2F: + emit_store_R32G32(cp, ptr, dataXMM); + break; + case EMIT_3F: + emit_store_R32G32B32(cp, ptr, dataXMM); + break; + case EMIT_4F: + emit_store_R32G32B32A32(cp, ptr, dataXMM); + break; + case EMIT_4UB: + emit_store_R8G8B8A8_UNORM(cp, ptr, dataXMM); + break; + case EMIT_4UB_BGRA: + emit_swizzle(cp, dataXMM, dataXMM, SHUF(Z,Y,X,W)); + emit_store_R8G8B8A8_UNORM(cp, ptr, dataXMM); + break; + default: + AOS_ERROR(cp, "unhandled output format"); + return FALSE; + } + + return TRUE; +} + + + +boolean aos_emit_outputs( struct aos_compilation *cp ) +{ + unsigned i; + + for (i = 0; i < cp->vaos->base.key.nr_outputs; i++) { + unsigned format = cp->vaos->base.key.element[i].out.format; + unsigned offset = cp->vaos->base.key.element[i].out.offset; + unsigned vs_output = cp->vaos->base.key.element[i].out.vs_output; + + struct x86_reg data; + + if (format == EMIT_1F_PSIZE) { + data = aos_get_internal_xmm( cp, IMM_PSIZE ); + } + else { + data = aos_get_shader_reg( cp, + TGSI_FILE_OUTPUT, + vs_output ); + } + + if (data.file != file_XMM) { + struct x86_reg tmp = aos_get_xmm_reg( cp ); + sse_movaps(cp->func, tmp, data); + data = tmp; + } + + if (!emit_output( cp, + x86_make_disp( cp->outbuf_ECX, offset ), + data, + format )) + return FALSE; + + aos_release_xmm_reg( cp, data.idx ); + + cp->insn_counter++; + } + + return TRUE; +} + +#endif diff --git a/src/gallium/auxiliary/draw/draw_vs_aos_machine.c b/src/gallium/auxiliary/draw/draw_vs_aos_machine.c new file mode 100644 index 0000000..0eda414 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_vs_aos_machine.c @@ -0,0 +1,328 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "pipe/p_config.h" + + +#include "pipe/p_shader_tokens.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "tgsi/tgsi_exec.h" +#include "draw_vs.h" +#include "draw_vs_aos.h" +#include "draw_vertex.h" + +#ifdef PIPE_ARCH_X86 + +#include "rtasm/rtasm_x86sse.h" + + +#define X87_CW_EXCEPTION_INV_OP (1<<0) +#define X87_CW_EXCEPTION_DENORM_OP (1<<1) +#define X87_CW_EXCEPTION_ZERO_DIVIDE (1<<2) +#define X87_CW_EXCEPTION_OVERFLOW (1<<3) +#define X87_CW_EXCEPTION_UNDERFLOW (1<<4) +#define X87_CW_EXCEPTION_PRECISION (1<<5) +#define X87_CW_PRECISION_SINGLE (0<<8) +#define X87_CW_PRECISION_RESERVED (1<<8) +#define X87_CW_PRECISION_DOUBLE (2<<8) +#define X87_CW_PRECISION_DOUBLE_EXT (3<<8) +#define X87_CW_PRECISION_MASK (3<<8) +#define X87_CW_ROUND_NEAREST (0<<10) +#define X87_CW_ROUND_DOWN (1<<10) +#define X87_CW_ROUND_UP (2<<10) +#define X87_CW_ROUND_ZERO (3<<10) +#define X87_CW_ROUND_MASK (3<<10) +#define X87_CW_INFINITY (1<<12) + + +void PIPE_CDECL aos_do_lit( struct aos_machine *machine, + float *result, + const float *in, + unsigned count ) +{ + if (in[0] > 0) + { + if (in[1] <= 0.0) + { + result[0] = 1.0F; + result[1] = in[0]; + result[2] = 0.0F; + result[3] = 1.0F; + } + else + { + const float epsilon = 1.0F / 256.0F; + float exponent = CLAMP(in[3], -(128.0F - epsilon), (128.0F - epsilon)); + result[0] = 1.0F; + result[1] = in[0]; + result[2] = powf(in[1], exponent); + result[3] = 1.0; + } + } + else + { + result[0] = 1.0F; + result[1] = 0.0; + result[2] = 0.0; + result[3] = 1.0F; + } +} + + +static void PIPE_CDECL do_lit_lut( struct aos_machine *machine, + float *result, + const float *in, + unsigned count ) +{ + if (in[0] > 0) + { + if (in[1] <= 0.0) + { + result[0] = 1.0F; + result[1] = in[0]; + result[2] = 0.0F; + result[3] = 1.0F; + return; + } + + if (machine->lit_info[count].shine_tab->exponent != in[3]) { + machine->lit_info[count].func = aos_do_lit; + goto no_luck; + } + + if (in[1] <= 1.0) + { + const float *tab = machine->lit_info[count].shine_tab->values; + float f = in[1] * 256; + int k = (int)f; + float frac = f - (float)k; + + result[0] = 1.0F; + result[1] = in[0]; + result[2] = tab[k] + frac*(tab[k+1]-tab[k]); + result[3] = 1.0; + return; + } + + no_luck: + { + const float epsilon = 1.0F / 256.0F; + float exponent = CLAMP(in[3], -(128.0F - epsilon), (128.0F - epsilon)); + result[0] = 1.0F; + result[1] = in[0]; + result[2] = powf(in[1], exponent); + result[3] = 1.0; + } + } + else + { + result[0] = 1.0F; + result[1] = 0.0; + result[2] = 0.0; + result[3] = 1.0F; + } +} + + +static void do_populate_lut( struct shine_tab *tab, + float unclamped_exponent ) +{ + const float epsilon = 1.0F / 256.0F; + float exponent = CLAMP(unclamped_exponent, -(128.0F - epsilon), (128.0F - epsilon)); + unsigned i; + + tab->exponent = unclamped_exponent; /* for later comparison */ + + tab->values[0] = 0; + if (exponent == 0) { + for (i = 1; i < 258; i++) { + tab->values[i] = 1.0; + } + } + else { + for (i = 1; i < 258; i++) { + tab->values[i] = powf((float)i * epsilon, exponent); + } + } +} + + + + +static void PIPE_CDECL populate_lut( struct aos_machine *machine, + float *result, + const float *in, + unsigned count ) +{ + unsigned i, tab; + + /* Search for an existing table for this value. Note that without + * static analysis we don't really know if in[3] will be constant, + * but it usually is... + */ + for (tab = 0; tab < 4; tab++) { + if (machine->shine_tab[tab].exponent == in[3]) { + goto found; + } + } + + for (tab = 0, i = 1; i < 4; i++) { + if (machine->shine_tab[i].last_used < machine->shine_tab[tab].last_used) + tab = i; + } + + if (machine->shine_tab[tab].last_used == machine->now) { + /* No unused tables (this is not a ffvertex program...). Just + * call pow each time: + */ + machine->lit_info[count].func = aos_do_lit; + machine->lit_info[count].func( machine, result, in, count ); + return; + } + else { + do_populate_lut( &machine->shine_tab[tab], in[3] ); + } + + found: + machine->shine_tab[tab].last_used = machine->now; + machine->lit_info[count].shine_tab = &machine->shine_tab[tab]; + machine->lit_info[count].func = do_lit_lut; + machine->lit_info[count].func( machine, result, in, count ); +} + + +void +draw_vs_aos_machine_constants(struct aos_machine *machine, + unsigned slot, + const void *constants) +{ + machine->constants[slot] = constants; + + { + unsigned i; + for (i = 0; i < MAX_LIT_INFO; i++) { + machine->lit_info[i].func = populate_lut; + machine->now++; + } + } +} + + +void draw_vs_aos_machine_viewport( struct aos_machine *machine, + const struct pipe_viewport_state *viewport ) +{ + memcpy(machine->scale, viewport->scale, 4 * sizeof(float)); + memcpy(machine->translate, viewport->translate, 4 * sizeof(float)); +} + + + +void draw_vs_aos_machine_destroy( struct aos_machine *machine ) +{ + align_free(machine); +} + +struct aos_machine *draw_vs_aos_machine( void ) +{ + struct aos_machine *machine; + unsigned i; + float inv = 1.0f/255.0f; + float f255 = 255.0f; + + machine = align_malloc(sizeof(struct aos_machine), 16); + if (!machine) + return NULL; + + memset(machine, 0, sizeof(*machine)); + + ASSIGN_4V(machine->internal[IMM_SWZ], 1.0f, -1.0f, 0.0f, 1.0f); + *(unsigned *)&machine->internal[IMM_SWZ][3] = 0xffffffff; + + ASSIGN_4V(machine->internal[IMM_ONES], 1.0f, 1.0f, 1.0f, 1.0f); + ASSIGN_4V(machine->internal[IMM_NEGS], -1.0f, -1.0f, -1.0f, -1.0f); + ASSIGN_4V(machine->internal[IMM_IDENTITY], 0.0f, 0.0f, 0.0f, 1.0f); + ASSIGN_4V(machine->internal[IMM_INV_255], inv, inv, inv, inv); + ASSIGN_4V(machine->internal[IMM_255], f255, f255, f255, f255); + ASSIGN_4V(machine->internal[IMM_RSQ], -.5f, 1.5f, 0.0f, 0.0f); + + + machine->fpu_rnd_nearest = (X87_CW_EXCEPTION_INV_OP | + X87_CW_EXCEPTION_DENORM_OP | + X87_CW_EXCEPTION_ZERO_DIVIDE | + X87_CW_EXCEPTION_OVERFLOW | + X87_CW_EXCEPTION_UNDERFLOW | + X87_CW_EXCEPTION_PRECISION | + (1<<6) | + X87_CW_ROUND_NEAREST | + X87_CW_PRECISION_DOUBLE_EXT); + + assert(machine->fpu_rnd_nearest == 0x37f); + + machine->fpu_rnd_neg_inf = (X87_CW_EXCEPTION_INV_OP | + X87_CW_EXCEPTION_DENORM_OP | + X87_CW_EXCEPTION_ZERO_DIVIDE | + X87_CW_EXCEPTION_OVERFLOW | + X87_CW_EXCEPTION_UNDERFLOW | + X87_CW_EXCEPTION_PRECISION | + (1<<6) | + X87_CW_ROUND_DOWN | + X87_CW_PRECISION_DOUBLE_EXT); + + for (i = 0; i < MAX_SHINE_TAB; i++) + do_populate_lut( &machine->shine_tab[i], 1.0f ); + + return machine; +} + +#else + +void draw_vs_aos_machine_viewport( struct aos_machine *machine, + const struct pipe_viewport_state *viewport ) +{ +} + +void +draw_vs_aos_machine_constants(struct aos_machine *machine, + unsigned slot, + const void *constants) +{ +} + +void draw_vs_aos_machine_destroy( struct aos_machine *machine ) +{ +} + +struct aos_machine *draw_vs_aos_machine( void ) +{ + return NULL; +} +#endif + diff --git a/src/gallium/auxiliary/draw/draw_vs_exec.c b/src/gallium/auxiliary/draw/draw_vs_exec.c new file mode 100644 index 0000000..dab3eb1 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_vs_exec.c @@ -0,0 +1,210 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + * Brian Paul + */ + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "pipe/p_shader_tokens.h" + +#include "draw_private.h" +#include "draw_context.h" +#include "draw_vs.h" + +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_scan.h" +#include "tgsi/tgsi_exec.h" + + +struct exec_vertex_shader { + struct draw_vertex_shader base; + struct tgsi_exec_machine *machine; +}; + +static struct exec_vertex_shader *exec_vertex_shader( struct draw_vertex_shader *vs ) +{ + return (struct exec_vertex_shader *)vs; +} + + +/* Not required for run_linear. + */ +static void +vs_exec_prepare( struct draw_vertex_shader *shader, + struct draw_context *draw ) +{ + struct exec_vertex_shader *evs = exec_vertex_shader(shader); + + /* Specify the vertex program to interpret/execute. + * Avoid rebinding when possible. + */ + if (evs->machine->Tokens != shader->state.tokens) { + tgsi_exec_machine_bind_shader(evs->machine, + shader->state.tokens, + draw->vs.num_samplers, + draw->vs.samplers); + } +} + + + + +/* Simplified vertex shader interface for the pt paths. Given the + * complexity of code-generating all the above operations together, + * it's time to try doing all the other stuff separately. + */ +static void +vs_exec_run_linear( struct draw_vertex_shader *shader, + const float (*input)[4], + float (*output)[4], + const void *constants[PIPE_MAX_CONSTANT_BUFFERS], + const unsigned const_size[PIPE_MAX_CONSTANT_BUFFERS], + unsigned count, + unsigned input_stride, + unsigned output_stride ) +{ + struct exec_vertex_shader *evs = exec_vertex_shader(shader); + struct tgsi_exec_machine *machine = evs->machine; + unsigned int i, j; + unsigned slot; + + tgsi_exec_set_constant_buffers(machine, PIPE_MAX_CONSTANT_BUFFERS, + constants, const_size); + + for (i = 0; i < count; i += MAX_TGSI_VERTICES) { + unsigned int max_vertices = MIN2(MAX_TGSI_VERTICES, count - i); + + /* Swizzle inputs. + */ + for (j = 0; j < max_vertices; j++) { +#if 0 + debug_printf("%d) Input vert:\n", i + j); + for (slot = 0; slot < shader->info.num_inputs; slot++) { + debug_printf("\t%d: %f %f %f %f\n", slot, + input[slot][0], + input[slot][1], + input[slot][2], + input[slot][3]); + } +#endif + + for (slot = 0; slot < shader->info.num_inputs; slot++) { +#if 0 + assert(!util_is_inf_or_nan(input[slot][0])); + assert(!util_is_inf_or_nan(input[slot][1])); + assert(!util_is_inf_or_nan(input[slot][2])); + assert(!util_is_inf_or_nan(input[slot][3])); +#endif + machine->Inputs[slot].xyzw[0].f[j] = input[slot][0]; + machine->Inputs[slot].xyzw[1].f[j] = input[slot][1]; + machine->Inputs[slot].xyzw[2].f[j] = input[slot][2]; + machine->Inputs[slot].xyzw[3].f[j] = input[slot][3]; + } + + input = (const float (*)[4])((const char *)input + input_stride); + } + + tgsi_set_exec_mask(machine, + 1, + max_vertices > 1, + max_vertices > 2, + max_vertices > 3); + + /* run interpreter */ + tgsi_exec_machine_run( machine ); + + /* Unswizzle all output results. + */ + for (j = 0; j < max_vertices; j++) { + for (slot = 0; slot < shader->info.num_outputs; slot++) { + output[slot][0] = machine->Outputs[slot].xyzw[0].f[j]; + output[slot][1] = machine->Outputs[slot].xyzw[1].f[j]; + output[slot][2] = machine->Outputs[slot].xyzw[2].f[j]; + output[slot][3] = machine->Outputs[slot].xyzw[3].f[j]; + + } + +#if 0 + debug_printf("%d) Post xform vert:\n", i + j); + for (slot = 0; slot < shader->info.num_outputs; slot++) { + debug_printf("\t%d: %f %f %f %f\n", slot, + output[slot][0], + output[slot][1], + output[slot][2], + output[slot][3]); + assert(!util_is_inf_or_nan(output[slot][0])); + } +#endif + + output = (float (*)[4])((char *)output + output_stride); + } + + } +} + + + + +static void +vs_exec_delete( struct draw_vertex_shader *dvs ) +{ + FREE((void*) dvs->state.tokens); + FREE( dvs ); +} + + +struct draw_vertex_shader * +draw_create_vs_exec(struct draw_context *draw, + const struct pipe_shader_state *state) +{ + struct exec_vertex_shader *vs = CALLOC_STRUCT( exec_vertex_shader ); + + if (vs == NULL) + return NULL; + + /* we make a private copy of the tokens */ + vs->base.state.tokens = tgsi_dup_tokens(state->tokens); + if (!vs->base.state.tokens) { + FREE(vs); + return NULL; + } + + tgsi_scan_shader(state->tokens, &vs->base.info); + + vs->base.draw = draw; + vs->base.prepare = vs_exec_prepare; + vs->base.run_linear = vs_exec_run_linear; + vs->base.delete = vs_exec_delete; + vs->base.create_varient = draw_vs_create_varient_generic; + vs->machine = draw->vs.machine; + + return &vs->base; +} diff --git a/src/gallium/auxiliary/draw/draw_vs_llvm.c b/src/gallium/auxiliary/draw/draw_vs_llvm.c new file mode 100644 index 0000000..de074be --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_vs_llvm.c @@ -0,0 +1,115 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/p_screen.h" + +#include "draw_private.h" +#include "draw_context.h" +#include "draw_vs.h" +#include "draw_llvm.h" + +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_scan.h" + +static void +vs_llvm_prepare(struct draw_vertex_shader *shader, + struct draw_context *draw) +{ + /*struct llvm_vertex_shader *evs = llvm_vertex_shader(shader);*/ +} + +static void +vs_llvm_run_linear( struct draw_vertex_shader *shader, + const float (*input)[4], + float (*output)[4], + const void *constants[PIPE_MAX_CONSTANT_BUFFERS], + const unsigned constants_size[PIPE_MAX_CONSTANT_BUFFERS], + unsigned count, + unsigned input_stride, + unsigned output_stride ) +{ + /* we should never get here since the entire pipeline is + * generated in draw_pt_fetch_shade_pipeline_llvm.c */ + debug_assert(0); +} + + +static void +vs_llvm_delete( struct draw_vertex_shader *dvs ) +{ + struct llvm_vertex_shader *shader = llvm_vertex_shader(dvs); + struct draw_llvm_variant_list_item *li; + + li = first_elem(&shader->variants); + while(!at_end(&shader->variants, li)) { + struct draw_llvm_variant_list_item *next = next_elem(li); + draw_llvm_destroy_variant(li->base); + li = next; + } + + assert(shader->variants_cached == 0); + FREE((void*) dvs->state.tokens); + FREE( dvs ); +} + + +struct draw_vertex_shader * +draw_create_vs_llvm(struct draw_context *draw, + const struct pipe_shader_state *state) +{ + struct llvm_vertex_shader *vs = CALLOC_STRUCT( llvm_vertex_shader ); + + if (vs == NULL) + return NULL; + + /* we make a private copy of the tokens */ + vs->base.state.tokens = tgsi_dup_tokens(state->tokens); + if (!vs->base.state.tokens) { + FREE(vs); + return NULL; + } + + tgsi_scan_shader(state->tokens, &vs->base.info); + + vs->variant_key_size = + draw_llvm_variant_key_size( + vs->base.info.file_max[TGSI_FILE_INPUT]+1, + vs->base.info.file_max[TGSI_FILE_SAMPLER]+1); + + vs->base.draw = draw; + vs->base.prepare = vs_llvm_prepare; + vs->base.run_linear = vs_llvm_run_linear; + vs->base.delete = vs_llvm_delete; + vs->base.create_varient = draw_vs_create_varient_generic; + + make_empty_list(&vs->variants); + + return &vs->base; +} diff --git a/src/gallium/auxiliary/draw/draw_vs_ppc.c b/src/gallium/auxiliary/draw/draw_vs_ppc.c new file mode 100644 index 0000000..5df8491 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_vs_ppc.c @@ -0,0 +1,245 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + * Brian Paul + */ + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "pipe/p_config.h" + +#include "draw_vs.h" + +#if defined(PIPE_ARCH_PPC) + +#include "pipe/p_shader_tokens.h" + +#include "draw_private.h" +#include "draw_context.h" + +#include "rtasm/rtasm_cpu.h" +#include "rtasm/rtasm_ppc.h" +#include "tgsi/tgsi_ppc.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_exec.h" + + + +typedef void (PIPE_CDECL *codegen_function) (float (*inputs)[4][4], + float (*outputs)[4][4], + float (*temps)[4][4], + float (*immeds)[4], + float (*consts)[4], + const float *builtins); + + +struct draw_ppc_vertex_shader { + struct draw_vertex_shader base; + struct ppc_function ppc_program; + + codegen_function func; +}; + + +static void +vs_ppc_prepare( struct draw_vertex_shader *base, + struct draw_context *draw ) +{ + /* nothing */ +} + + +/** + * Simplified vertex shader interface for the pt paths. Given the + * complexity of code-generating all the above operations together, + * it's time to try doing all the other stuff separately. + */ +static void +vs_ppc_run_linear( struct draw_vertex_shader *base, + const float (*input)[4], + float (*output)[4], + const void *constants[PIPE_MAX_CONSTANT_BUFFERS], + unsigned count, + unsigned input_stride, + unsigned output_stride ) +{ + struct draw_ppc_vertex_shader *shader = (struct draw_ppc_vertex_shader *)base; + unsigned int i; + +#define MAX_VERTICES 4 + + /* loop over verts */ + for (i = 0; i < count; i += MAX_VERTICES) { + const uint max_vertices = MIN2(MAX_VERTICES, count - i); + PIPE_ALIGN_VAR(16) float inputs_soa[PIPE_MAX_SHADER_INPUTS][4][4]; + PIPE_ALIGN_VAR(16) float outputs_soa[PIPE_MAX_SHADER_OUTPUTS][4][4]; + PIPE_ALIGN_VAR(16) float temps_soa[TGSI_EXEC_NUM_TEMPS][4][4]; + uint attr; + + /* convert (up to) four input verts to SoA format */ + for (attr = 0; attr < base->info.num_inputs; attr++) { + const float *vIn = (const float *) input; + uint vert; + for (vert = 0; vert < max_vertices; vert++) { +#if 0 + if (attr==0) + printf("Input v%d a%d: %f %f %f %f\n", + vert, attr, vIn[0], vIn[1], vIn[2], vIn[3]); +#endif + inputs_soa[attr][0][vert] = vIn[attr * 4 + 0]; + inputs_soa[attr][1][vert] = vIn[attr * 4 + 1]; + inputs_soa[attr][2][vert] = vIn[attr * 4 + 2]; + inputs_soa[attr][3][vert] = vIn[attr * 4 + 3]; + vIn += input_stride / 4; + } + } + + /* run compiled shader + */ + shader->func(inputs_soa, outputs_soa, temps_soa, + (float (*)[4]) shader->base.immediates, + (float (*)[4])constants[0], + ppc_builtin_constants); + + /* convert (up to) four output verts from SoA back to AoS format */ + for (attr = 0; attr < base->info.num_outputs; attr++) { + float *vOut = (float *) output; + uint vert; + for (vert = 0; vert < max_vertices; vert++) { + vOut[attr * 4 + 0] = outputs_soa[attr][0][vert]; + vOut[attr * 4 + 1] = outputs_soa[attr][1][vert]; + vOut[attr * 4 + 2] = outputs_soa[attr][2][vert]; + vOut[attr * 4 + 3] = outputs_soa[attr][3][vert]; +#if 0 + if (attr==0) + printf("Output v%d a%d: %f %f %f %f\n", + vert, attr, vOut[0], vOut[1], vOut[2], vOut[3]); +#endif + vOut += output_stride / 4; + } + } + + /* advance to next group of four input/output verts */ + input = (const float (*)[4])((const char *)input + input_stride * max_vertices); + output = (float (*)[4])((char *)output + output_stride * max_vertices); + } +} + + +static void +vs_ppc_delete( struct draw_vertex_shader *base ) +{ + struct draw_ppc_vertex_shader *shader = (struct draw_ppc_vertex_shader *)base; + + ppc_release_func( &shader->ppc_program ); + + align_free( (void *) shader->base.immediates ); + + FREE( (void*) shader->base.state.tokens ); + FREE( shader ); +} + + +struct draw_vertex_shader * +draw_create_vs_ppc(struct draw_context *draw, + const struct pipe_shader_state *templ) +{ + struct draw_ppc_vertex_shader *vs; + + vs = CALLOC_STRUCT( draw_ppc_vertex_shader ); + if (vs == NULL) + return NULL; + + /* we make a private copy of the tokens */ + vs->base.state.tokens = tgsi_dup_tokens(templ->tokens); + if (!vs->base.state.tokens) + goto fail; + + tgsi_scan_shader(templ->tokens, &vs->base.info); + + vs->base.draw = draw; +#if 0 + if (1) + vs->base.create_varient = draw_vs_varient_aos_ppc; + else +#endif + vs->base.create_varient = draw_vs_create_varient_generic; + vs->base.prepare = vs_ppc_prepare; + vs->base.run_linear = vs_ppc_run_linear; + vs->base.delete = vs_ppc_delete; + + vs->base.immediates = align_malloc(TGSI_EXEC_NUM_IMMEDIATES * 4 * + sizeof(float), 16); + + ppc_init_func( &vs->ppc_program ); + +#if 0 + ppc_print_code(&vs->ppc_program, TRUE); + ppc_indent(&vs->ppc_program, 8); +#endif + + if (!tgsi_emit_ppc( (struct tgsi_token *) vs->base.state.tokens, + &vs->ppc_program, + (float (*)[4]) vs->base.immediates, + TRUE )) + goto fail; + + vs->func = (codegen_function) ppc_get_func( &vs->ppc_program ); + if (!vs->func) { + goto fail; + } + + return &vs->base; + +fail: + /* + debug_error("tgsi_emit_ppc() failed, falling back to interpreter\n"); + */ + + ppc_release_func( &vs->ppc_program ); + + FREE(vs); + return NULL; +} + + + +#else /* PIPE_ARCH_PPC */ + + +struct draw_vertex_shader * +draw_create_vs_ppc( struct draw_context *draw, + const struct pipe_shader_state *templ ) +{ + return (void *) 0; +} + + +#endif /* PIPE_ARCH_PPC */ diff --git a/src/gallium/auxiliary/draw/draw_vs_sse.c b/src/gallium/auxiliary/draw/draw_vs_sse.c new file mode 100644 index 0000000..0b0c607 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_vs_sse.c @@ -0,0 +1,218 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + * Brian Paul + */ + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "pipe/p_config.h" + +#include "draw_vs.h" + +#if defined(PIPE_ARCH_X86) + +#include "pipe/p_shader_tokens.h" + +#include "draw_private.h" +#include "draw_context.h" + +#include "rtasm/rtasm_cpu.h" +#include "rtasm/rtasm_x86sse.h" +#include "tgsi/tgsi_sse2.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_exec.h" + +#define SSE_MAX_VERTICES 4 + + +struct draw_sse_vertex_shader { + struct draw_vertex_shader base; + struct x86_function sse2_program; + + tgsi_sse2_vs_func func; + + struct tgsi_exec_machine *machine; +}; + + +static void +vs_sse_prepare( struct draw_vertex_shader *base, + struct draw_context *draw ) +{ + struct draw_sse_vertex_shader *shader = (struct draw_sse_vertex_shader *)base; + struct tgsi_exec_machine *machine = shader->machine; + + machine->Samplers = draw->vs.samplers; +} + + + +/* Simplified vertex shader interface for the pt paths. Given the + * complexity of code-generating all the above operations together, + * it's time to try doing all the other stuff separately. + */ +static void +vs_sse_run_linear( struct draw_vertex_shader *base, + const float (*input)[4], + float (*output)[4], + const void *constants[PIPE_MAX_CONSTANT_BUFFERS], + const unsigned const_size[PIPE_MAX_CONSTANT_BUFFERS], + unsigned count, + unsigned input_stride, + unsigned output_stride ) +{ + struct draw_sse_vertex_shader *shader = (struct draw_sse_vertex_shader *)base; + struct tgsi_exec_machine *machine = shader->machine; + unsigned int i; + + /* By default, execute all channels. XXX move this inside the loop + * below when we support shader conditionals/loops. + */ + tgsi_set_exec_mask(machine, 1, 1, 1, 1); + + for (i = 0; i < count; i += MAX_TGSI_VERTICES) { + unsigned int max_vertices = MIN2(MAX_TGSI_VERTICES, count - i); + + if (max_vertices < 4) { + /* disable the unused execution channels */ + tgsi_set_exec_mask(machine, + 1, + max_vertices > 1, + max_vertices > 2, + 0); + } + + /* run compiled shader + */ + shader->func(machine, + (const float (*)[4])constants[0], + shader->base.immediates, + input, + base->info.num_inputs, + input_stride, + output, + base->info.num_outputs, + output_stride ); + + input = (const float (*)[4])((const char *)input + input_stride * max_vertices); + output = (float (*)[4])((char *)output + output_stride * max_vertices); + } +} + + + + +static void +vs_sse_delete( struct draw_vertex_shader *base ) +{ + struct draw_sse_vertex_shader *shader = (struct draw_sse_vertex_shader *)base; + + x86_release_func( &shader->sse2_program ); + + align_free( (void *) shader->base.immediates ); + + FREE( (void*) shader->base.state.tokens ); + FREE( shader ); +} + + +struct draw_vertex_shader * +draw_create_vs_sse(struct draw_context *draw, + const struct pipe_shader_state *templ) +{ + struct draw_sse_vertex_shader *vs; + + if (!rtasm_cpu_has_sse2()) + return NULL; + + vs = CALLOC_STRUCT( draw_sse_vertex_shader ); + if (vs == NULL) + return NULL; + + /* we make a private copy of the tokens */ + vs->base.state.tokens = tgsi_dup_tokens(templ->tokens); + if (!vs->base.state.tokens) + goto fail; + + tgsi_scan_shader(templ->tokens, &vs->base.info); + + vs->base.draw = draw; + if (1) + vs->base.create_varient = draw_vs_create_varient_aos_sse; + else + vs->base.create_varient = draw_vs_create_varient_generic; + vs->base.prepare = vs_sse_prepare; + vs->base.run_linear = vs_sse_run_linear; + vs->base.delete = vs_sse_delete; + + vs->base.immediates = align_malloc(TGSI_EXEC_NUM_IMMEDIATES * 4 * + sizeof(float), 16); + + vs->machine = draw->vs.machine; + + x86_init_func( &vs->sse2_program ); + + if (!tgsi_emit_sse2( (struct tgsi_token *) vs->base.state.tokens, + &vs->sse2_program, + (float (*)[4])vs->base.immediates, + TRUE )) + goto fail; + + vs->func = (tgsi_sse2_vs_func) x86_get_func( &vs->sse2_program ); + if (!vs->func) { + goto fail; + } + + return &vs->base; + +fail: + debug_error("tgsi_emit_sse2() failed, falling back to interpreter\n"); + + x86_release_func( &vs->sse2_program ); + + FREE(vs); + return NULL; +} + + + +#else + +struct draw_vertex_shader * +draw_create_vs_sse( struct draw_context *draw, + const struct pipe_shader_state *templ ) +{ + return (void *) 0; +} + + +#endif + diff --git a/src/gallium/auxiliary/draw/draw_vs_varient.c b/src/gallium/auxiliary/draw/draw_vs_varient.c new file mode 100644 index 0000000..eacd160 --- /dev/null +++ b/src/gallium/auxiliary/draw/draw_vs_varient.c @@ -0,0 +1,341 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_memory.h" +#include "util/u_math.h" +#include "draw/draw_context.h" +#include "draw/draw_private.h" +#include "draw/draw_vbuf.h" +#include "draw/draw_vertex.h" +#include "draw/draw_vs.h" +#include "translate/translate.h" + +/* A first pass at incorporating vertex fetch/emit functionality into + */ +struct draw_vs_varient_generic { + struct draw_vs_varient base; + + struct draw_vertex_shader *shader; + struct draw_context *draw; + + /* Basic plan is to run these two translate functions before/after + * the vertex shader's existing run_linear() routine to simulate + * the inclusion of this functionality into the shader... + * + * Next will look at actually including it. + */ + struct translate *fetch; + struct translate *emit; + + unsigned temp_vertex_stride; +}; + + + + + +static void vsvg_set_buffer( struct draw_vs_varient *varient, + unsigned buffer, + const void *ptr, + unsigned stride, + unsigned max_index ) +{ + struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient; + + vsvg->fetch->set_buffer(vsvg->fetch, + buffer, + ptr, + stride, + max_index ); +} + + +/* Mainly for debug at this stage: + */ +static void do_rhw_viewport( struct draw_vs_varient_generic *vsvg, + unsigned count, + void *output_buffer ) +{ + char *ptr = (char *)output_buffer; + const float *scale = vsvg->base.vs->draw->viewport.scale; + const float *trans = vsvg->base.vs->draw->viewport.translate; + unsigned stride = vsvg->temp_vertex_stride; + unsigned j; + + ptr += vsvg->base.vs->position_output * 4 * sizeof(float); + + for (j = 0; j < count; j++, ptr += stride) { + float *data = (float *)ptr; + float w = 1.0f / data[3]; + + data[0] = data[0] * w * scale[0] + trans[0]; + data[1] = data[1] * w * scale[1] + trans[1]; + data[2] = data[2] * w * scale[2] + trans[2]; + data[3] = w; + } +} + +static void do_viewport( struct draw_vs_varient_generic *vsvg, + unsigned count, + void *output_buffer ) +{ + char *ptr = (char *)output_buffer; + const float *scale = vsvg->base.vs->draw->viewport.scale; + const float *trans = vsvg->base.vs->draw->viewport.translate; + unsigned stride = vsvg->temp_vertex_stride; + unsigned j; + + ptr += vsvg->base.vs->position_output * 4 * sizeof(float); + + for (j = 0; j < count; j++, ptr += stride) { + float *data = (float *)ptr; + + data[0] = data[0] * scale[0] + trans[0]; + data[1] = data[1] * scale[1] + trans[1]; + data[2] = data[2] * scale[2] + trans[2]; + } +} + + +static void PIPE_CDECL vsvg_run_elts( struct draw_vs_varient *varient, + const unsigned *elts, + unsigned count, + void *output_buffer) +{ + struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient; + unsigned temp_vertex_stride = vsvg->temp_vertex_stride; + void *temp_buffer = MALLOC( align(count,4) * temp_vertex_stride ); + + if (0) debug_printf("%s %d \n", __FUNCTION__, count); + + /* Want to do this in small batches for cache locality? + */ + + vsvg->fetch->run_elts( vsvg->fetch, + elts, + count, + vsvg->draw->instance_id, + temp_buffer ); + + vsvg->base.vs->run_linear( vsvg->base.vs, + temp_buffer, + temp_buffer, + vsvg->base.vs->draw->pt.user.vs_constants, + vsvg->base.vs->draw->pt.user.vs_constants_size, + count, + temp_vertex_stride, + temp_vertex_stride); + + /* FIXME: geometry shading? */ + + if (vsvg->base.key.clip) { + /* not really handling clipping, just do the rhw so we can + * see the results... + */ + do_rhw_viewport( vsvg, + count, + temp_buffer ); + } + else if (vsvg->base.key.viewport) { + do_viewport( vsvg, + count, + temp_buffer ); + } + + + vsvg->emit->set_buffer( vsvg->emit, + 0, + temp_buffer, + temp_vertex_stride, + ~0 ); + + vsvg->emit->set_buffer( vsvg->emit, + 1, + &vsvg->draw->rasterizer->point_size, + 0, + ~0 ); + + vsvg->emit->run( vsvg->emit, + 0, count, + vsvg->draw->instance_id, + output_buffer ); + + FREE(temp_buffer); +} + + +static void PIPE_CDECL vsvg_run_linear( struct draw_vs_varient *varient, + unsigned start, + unsigned count, + void *output_buffer ) +{ + struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient; + unsigned temp_vertex_stride = vsvg->temp_vertex_stride; + void *temp_buffer = MALLOC( align(count,4) * temp_vertex_stride ); + + if (0) debug_printf("%s %d %d (sz %d, %d)\n", __FUNCTION__, start, count, + vsvg->base.key.output_stride, + temp_vertex_stride); + + vsvg->fetch->run( vsvg->fetch, + start, + count, + vsvg->draw->instance_id, + temp_buffer ); + + vsvg->base.vs->run_linear( vsvg->base.vs, + temp_buffer, + temp_buffer, + vsvg->base.vs->draw->pt.user.vs_constants, + vsvg->base.vs->draw->pt.user.vs_constants_size, + count, + temp_vertex_stride, + temp_vertex_stride); + + if (vsvg->base.key.clip) { + /* not really handling clipping, just do the rhw so we can + * see the results... + */ + do_rhw_viewport( vsvg, + count, + temp_buffer ); + } + else if (vsvg->base.key.viewport) { + do_viewport( vsvg, + count, + temp_buffer ); + } + + vsvg->emit->set_buffer( vsvg->emit, + 0, + temp_buffer, + temp_vertex_stride, + ~0 ); + + vsvg->emit->set_buffer( vsvg->emit, + 1, + &vsvg->draw->rasterizer->point_size, + 0, + ~0 ); + + vsvg->emit->run( vsvg->emit, + 0, count, + vsvg->draw->instance_id, + output_buffer ); + + FREE(temp_buffer); +} + + + + + +static void vsvg_destroy( struct draw_vs_varient *varient ) +{ + FREE(varient); +} + + +struct draw_vs_varient * +draw_vs_create_varient_generic( struct draw_vertex_shader *vs, + const struct draw_vs_varient_key *key ) +{ + unsigned i; + struct translate_key fetch, emit; + + struct draw_vs_varient_generic *vsvg = CALLOC_STRUCT( draw_vs_varient_generic ); + if (vsvg == NULL) + return NULL; + + vsvg->base.key = *key; + vsvg->base.vs = vs; + vsvg->base.set_buffer = vsvg_set_buffer; + vsvg->base.run_elts = vsvg_run_elts; + vsvg->base.run_linear = vsvg_run_linear; + vsvg->base.destroy = vsvg_destroy; + + vsvg->draw = vs->draw; + + vsvg->temp_vertex_stride = MAX2(key->nr_inputs, + vsvg->base.vs->info.num_outputs) * 4 * sizeof(float); + + /* Build free-standing fetch and emit functions: + */ + fetch.nr_elements = key->nr_inputs; + fetch.output_stride = vsvg->temp_vertex_stride; + for (i = 0; i < key->nr_inputs; i++) { + fetch.element[i].type = TRANSLATE_ELEMENT_NORMAL; + fetch.element[i].input_format = key->element[i].in.format; + fetch.element[i].input_buffer = key->element[i].in.buffer; + fetch.element[i].input_offset = key->element[i].in.offset; + fetch.element[i].instance_divisor = 0; + fetch.element[i].output_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + fetch.element[i].output_offset = i * 4 * sizeof(float); + assert(fetch.element[i].output_offset < fetch.output_stride); + } + + + emit.nr_elements = key->nr_outputs; + emit.output_stride = key->output_stride; + for (i = 0; i < key->nr_outputs; i++) { + if (key->element[i].out.format != EMIT_1F_PSIZE) + { + emit.element[i].type = TRANSLATE_ELEMENT_NORMAL; + emit.element[i].input_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + emit.element[i].input_buffer = 0; + emit.element[i].input_offset = key->element[i].out.vs_output * 4 * sizeof(float); + emit.element[i].instance_divisor = 0; + emit.element[i].output_format = draw_translate_vinfo_format(key->element[i].out.format); + emit.element[i].output_offset = key->element[i].out.offset; + assert(emit.element[i].input_offset <= fetch.output_stride); + } + else { + emit.element[i].type = TRANSLATE_ELEMENT_NORMAL; + emit.element[i].input_format = PIPE_FORMAT_R32_FLOAT; + emit.element[i].input_buffer = 1; + emit.element[i].input_offset = 0; + emit.element[i].instance_divisor = 0; + emit.element[i].output_format = PIPE_FORMAT_R32_FLOAT; + emit.element[i].output_offset = key->element[i].out.offset; + } + } + + vsvg->fetch = draw_vs_get_fetch( vs->draw, &fetch ); + vsvg->emit = draw_vs_get_emit( vs->draw, &emit ); + + return &vsvg->base; +} + + + + + diff --git a/src/gallium/auxiliary/gallivm/f.cpp b/src/gallium/auxiliary/gallivm/f.cpp new file mode 100644 index 0000000..5eb09c0 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/f.cpp @@ -0,0 +1,85 @@ +/************************************************************************** + * + * (C) Copyright VMware, Inc 2010. + * (C) Copyright John Maddock 2006. + * Use, modification and distribution are subject to the + * Boost Software License, Version 1.0. (See accompanying file + * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + * + **************************************************************************/ + + +/* + * This file allows to compute the minimax polynomial coefficients we use + * for fast exp2/log2. + * + * How to use this source: + * + * - Download and abuild the NTL library from + * http://shoup.net/ntl/download.html + * + * - Download boost source code matching to your distro. + * + * - Goto libs/math/minimax and replace f.cpp with this file. + * + * - Build as + * + * g++ -o minimax -I /path/to/ntl/include main.cpp f.cpp /path/to/ntl/src/ntl.a -lboost_math_tr1 + * + * - Run as + * + * ./minimax + * + * - For example, to compute exp2 5th order polynomial between [0, 1] do: + * + * variant 1 + * range 0 1 + * order 5 0 + * steps 200 + * info + * + * - For more info see + * http://www.boost.org/doc/libs/1_36_0/libs/math/doc/sf_and_dist/html/math_toolkit/toolkit/internals2/minimax.html + */ + +#define L22 +#include +#include + +#include + + +boost::math::ntl::RR f(const boost::math::ntl::RR& x, int variant) +{ + static const boost::math::ntl::RR tiny = boost::math::tools::min_value() * 64; + + switch(variant) + { + case 0: + // log2(x)/(x - 1) + return log(x)/log(2.0)/(x - 1.0); + + case 1: + // exp2(x) + return exp(x*log(2.0)); + } + + return 0; +} + + +void show_extra( + const boost::math::tools::polynomial& n, + const boost::math::tools::polynomial& d, + const boost::math::ntl::RR& x_offset, + const boost::math::ntl::RR& y_offset, + int variant) +{ + switch(variant) + { + default: + // do nothing here... + ; + } +} + diff --git a/src/gallium/auxiliary/gallivm/lp_bld.h b/src/gallium/auxiliary/gallivm/lp_bld.h new file mode 100644 index 0000000..ee05c6b --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld.h @@ -0,0 +1,87 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Wrapper for LLVM header file #includes. + */ + + +#ifndef LP_BLD_H +#define LP_BLD_H + + +/** + * @file + * LLVM IR building helpers interfaces. + * + * We use LLVM-C bindings for now. They are not documented, but follow the C++ + * interfaces very closely, and appear to be complete enough for code + * genration. See + * http://npcontemplation.blogspot.com/2008/06/secret-of-llvm-c-bindings.html + * for a standalone example. + */ + +#include + + +/** Ensure HAVE_LLVM is set to avoid #ifdef HAVE_LLVM everywhere */ +#ifndef HAVE_LLVM +#error "HAVE_LLVM should be set with LLVM's version number, e.g. (0x0207 for 2.7)" +#endif + + +/** + * Redefine these LLVM entrypoints as invalid macros to make sure we + * don't accidentally use them. We need to use the functions which + * take an explicit LLVMContextRef parameter. + */ +#define LLVMInt1Type ILLEGAL_LLVM_FUNCTION +#define LLVMInt8Type ILLEGAL_LLVM_FUNCTION +#define LLVMInt16Type ILLEGAL_LLVM_FUNCTION +#define LLVMInt32Type ILLEGAL_LLVM_FUNCTION +#define LLVMInt64Type ILLEGAL_LLVM_FUNCTION +#define LLVMIntType ILLEGAL_LLVM_FUNCTION +#define LLVMFloatType ILLEGAL_LLVM_FUNCTION +#define LLVMDoubleType ILLEGAL_LLVM_FUNCTION +#define LLVMX86FP80Type ILLEGAL_LLVM_FUNCTION +#define LLVMFP128Type ILLEGAL_LLVM_FUNCTION +#define LLVMPPCFP128Type ILLEGAL_LLVM_FUNCTION +#define LLVMStructType ILLEGAL_LLVM_FUNCTION +#define LLVMVoidType ILLEGAL_LLVM_FUNCTION +#define LLVMLabelType ILLEGAL_LLVM_FUNCTION +#define LLVMOpaqueType ILLEGAL_LLVM_FUNCTION +#define LLVMUnionType ILLEGAL_LLVM_FUNCTION +#define LLVMMDString ILLEGAL_LLVM_FUNCTION +#define LLVMMDNode ILLEGAL_LLVM_FUNCTION +#define LLVMConstString ILLEGAL_LLVM_FUNCTION +#define LLVMConstStruct ILLEGAL_LLVM_FUNCTION +#define LLVMAppendBasicBlock ILLEGAL_LLVM_FUNCTION +#define LLVMInsertBasicBlock ILLEGAL_LLVM_FUNCTION +#define LLVMCreateBuilder ILLEGAL_LLVM_FUNCTION + +#endif /* LP_BLD_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c new file mode 100644 index 0000000..02b3bde --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c @@ -0,0 +1,2576 @@ +/************************************************************************** + * + * Copyright 2009-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/** + * @file + * Helper + * + * LLVM IR doesn't support all basic arithmetic operations we care about (most + * notably min/max and saturated operations), and it is often necessary to + * resort machine-specific intrinsics directly. The functions here hide all + * these implementation details from the other modules. + * + * We also do simple expressions simplification here. Reasons are: + * - it is very easy given we have all necessary information readily available + * - LLVM optimization passes fail to simplify several vector expressions + * - We often know value constraints which the optimization passes have no way + * of knowing, such as when source arguments are known to be in [0, 1] range. + * + * @author Jose Fonseca + */ + + +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_math.h" +#include "util/u_string.h" +#include "util/u_cpu_detect.h" + +#include "lp_bld_type.h" +#include "lp_bld_const.h" +#include "lp_bld_init.h" +#include "lp_bld_intr.h" +#include "lp_bld_logic.h" +#include "lp_bld_pack.h" +#include "lp_bld_debug.h" +#include "lp_bld_arit.h" + + +#define EXP_POLY_DEGREE 3 + +#define LOG_POLY_DEGREE 5 + + +/** + * Generate min(a, b) + * No checks for special case values of a or b = 1 or 0 are done. + */ +static LLVMValueRef +lp_build_min_simple(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + const char *intrinsic = NULL; + LLVMValueRef cond; + + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + /* TODO: optimize the constant case */ + + if(type.width * type.length == 128) { + if(type.floating) { + if(type.width == 32 && util_cpu_caps.has_sse) + intrinsic = "llvm.x86.sse.min.ps"; + if(type.width == 64 && util_cpu_caps.has_sse2) + intrinsic = "llvm.x86.sse2.min.pd"; + } + else { + if(type.width == 8 && !type.sign && util_cpu_caps.has_sse2) + intrinsic = "llvm.x86.sse2.pminu.b"; + if(type.width == 8 && type.sign && util_cpu_caps.has_sse4_1) + intrinsic = "llvm.x86.sse41.pminsb"; + if(type.width == 16 && !type.sign && util_cpu_caps.has_sse4_1) + intrinsic = "llvm.x86.sse41.pminuw"; + if(type.width == 16 && type.sign && util_cpu_caps.has_sse2) + intrinsic = "llvm.x86.sse2.pmins.w"; + if(type.width == 32 && !type.sign && util_cpu_caps.has_sse4_1) + intrinsic = "llvm.x86.sse41.pminud"; + if(type.width == 32 && type.sign && util_cpu_caps.has_sse4_1) + intrinsic = "llvm.x86.sse41.pminsd"; + } + } + + if(intrinsic) + return lp_build_intrinsic_binary(builder, intrinsic, lp_build_vec_type(bld->gallivm, bld->type), a, b); + + cond = lp_build_cmp(bld, PIPE_FUNC_LESS, a, b); + return lp_build_select(bld, cond, a, b); +} + + +/** + * Generate max(a, b) + * No checks for special case values of a or b = 1 or 0 are done. + */ +static LLVMValueRef +lp_build_max_simple(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + const char *intrinsic = NULL; + LLVMValueRef cond; + + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + /* TODO: optimize the constant case */ + + if(type.width * type.length == 128) { + if(type.floating) { + if(type.width == 32 && util_cpu_caps.has_sse) + intrinsic = "llvm.x86.sse.max.ps"; + if(type.width == 64 && util_cpu_caps.has_sse2) + intrinsic = "llvm.x86.sse2.max.pd"; + } + else { + if(type.width == 8 && !type.sign && util_cpu_caps.has_sse2) + intrinsic = "llvm.x86.sse2.pmaxu.b"; + if(type.width == 8 && type.sign && util_cpu_caps.has_sse4_1) + intrinsic = "llvm.x86.sse41.pmaxsb"; + if(type.width == 16 && !type.sign && util_cpu_caps.has_sse4_1) + intrinsic = "llvm.x86.sse41.pmaxuw"; + if(type.width == 16 && type.sign && util_cpu_caps.has_sse2) + intrinsic = "llvm.x86.sse2.pmaxs.w"; + if(type.width == 32 && !type.sign && util_cpu_caps.has_sse4_1) + intrinsic = "llvm.x86.sse41.pmaxud"; + if(type.width == 32 && type.sign && util_cpu_caps.has_sse4_1) + intrinsic = "llvm.x86.sse41.pmaxsd"; + } + } + + if(intrinsic) + return lp_build_intrinsic_binary(builder, intrinsic, lp_build_vec_type(bld->gallivm, bld->type), a, b); + + cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, a, b); + return lp_build_select(bld, cond, a, b); +} + + +/** + * Generate 1 - a, or ~a depending on bld->type. + */ +LLVMValueRef +lp_build_comp(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + + assert(lp_check_value(type, a)); + + if(a == bld->one) + return bld->zero; + if(a == bld->zero) + return bld->one; + + if(type.norm && !type.floating && !type.fixed && !type.sign) { + if(LLVMIsConstant(a)) + return LLVMConstNot(a); + else + return LLVMBuildNot(builder, a, ""); + } + + if(LLVMIsConstant(a)) + if (type.floating) + return LLVMConstFSub(bld->one, a); + else + return LLVMConstSub(bld->one, a); + else + if (type.floating) + return LLVMBuildFSub(builder, bld->one, a, ""); + else + return LLVMBuildSub(builder, bld->one, a, ""); +} + + +/** + * Generate a + b + */ +LLVMValueRef +lp_build_add(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMValueRef res; + + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + if(a == bld->zero) + return b; + if(b == bld->zero) + return a; + if(a == bld->undef || b == bld->undef) + return bld->undef; + + if(bld->type.norm) { + const char *intrinsic = NULL; + + if(a == bld->one || b == bld->one) + return bld->one; + + if(util_cpu_caps.has_sse2 && + type.width * type.length == 128 && + !type.floating && !type.fixed) { + if(type.width == 8) + intrinsic = type.sign ? "llvm.x86.sse2.padds.b" : "llvm.x86.sse2.paddus.b"; + if(type.width == 16) + intrinsic = type.sign ? "llvm.x86.sse2.padds.w" : "llvm.x86.sse2.paddus.w"; + } + + if(intrinsic) + return lp_build_intrinsic_binary(builder, intrinsic, lp_build_vec_type(bld->gallivm, bld->type), a, b); + } + + if(LLVMIsConstant(a) && LLVMIsConstant(b)) + if (type.floating) + res = LLVMConstFAdd(a, b); + else + res = LLVMConstAdd(a, b); + else + if (type.floating) + res = LLVMBuildFAdd(builder, a, b, ""); + else + res = LLVMBuildAdd(builder, a, b, ""); + + /* clamp to ceiling of 1.0 */ + if(bld->type.norm && (bld->type.floating || bld->type.fixed)) + res = lp_build_min_simple(bld, res, bld->one); + + /* XXX clamp to floor of -1 or 0??? */ + + return res; +} + + +/** Return the scalar sum of the elements of a */ +LLVMValueRef +lp_build_sum_vector(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMValueRef index, res; + unsigned i; + + assert(lp_check_value(type, a)); + + if (type.length == 1) { + return a; + } + + assert(!bld->type.norm); + + index = lp_build_const_int32(bld->gallivm, 0); + res = LLVMBuildExtractElement(builder, a, index, ""); + + for (i = 1; i < type.length; i++) { + index = lp_build_const_int32(bld->gallivm, i); + if (type.floating) + res = LLVMBuildFAdd(builder, res, + LLVMBuildExtractElement(builder, + a, index, ""), + ""); + else + res = LLVMBuildAdd(builder, res, + LLVMBuildExtractElement(builder, + a, index, ""), + ""); + } + + return res; +} + + +/** + * Generate a - b + */ +LLVMValueRef +lp_build_sub(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMValueRef res; + + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + if(b == bld->zero) + return a; + if(a == bld->undef || b == bld->undef) + return bld->undef; + if(a == b) + return bld->zero; + + if(bld->type.norm) { + const char *intrinsic = NULL; + + if(b == bld->one) + return bld->zero; + + if(util_cpu_caps.has_sse2 && + type.width * type.length == 128 && + !type.floating && !type.fixed) { + if(type.width == 8) + intrinsic = type.sign ? "llvm.x86.sse2.psubs.b" : "llvm.x86.sse2.psubus.b"; + if(type.width == 16) + intrinsic = type.sign ? "llvm.x86.sse2.psubs.w" : "llvm.x86.sse2.psubus.w"; + } + + if(intrinsic) + return lp_build_intrinsic_binary(builder, intrinsic, lp_build_vec_type(bld->gallivm, bld->type), a, b); + } + + if(LLVMIsConstant(a) && LLVMIsConstant(b)) + if (type.floating) + res = LLVMConstFSub(a, b); + else + res = LLVMConstSub(a, b); + else + if (type.floating) + res = LLVMBuildFSub(builder, a, b, ""); + else + res = LLVMBuildSub(builder, a, b, ""); + + if(bld->type.norm && (bld->type.floating || bld->type.fixed)) + res = lp_build_max_simple(bld, res, bld->zero); + + return res; +} + + +/** + * Normalized 8bit multiplication. + * + * - alpha plus one + * + * makes the following approximation to the division (Sree) + * + * a*b/255 ~= (a*(b + 1)) >> 256 + * + * which is the fastest method that satisfies the following OpenGL criteria + * + * 0*0 = 0 and 255*255 = 255 + * + * - geometric series + * + * takes the geometric series approximation to the division + * + * t/255 = (t >> 8) + (t >> 16) + (t >> 24) .. + * + * in this case just the first two terms to fit in 16bit arithmetic + * + * t/255 ~= (t + (t >> 8)) >> 8 + * + * note that just by itself it doesn't satisfies the OpenGL criteria, as + * 255*255 = 254, so the special case b = 255 must be accounted or roundoff + * must be used + * + * - geometric series plus rounding + * + * when using a geometric series division instead of truncating the result + * use roundoff in the approximation (Jim Blinn) + * + * t/255 ~= (t + (t >> 8) + 0x80) >> 8 + * + * achieving the exact results + * + * @sa Alvy Ray Smith, Image Compositing Fundamentals, Tech Memo 4, Aug 15, 1995, + * ftp://ftp.alvyray.com/Acrobat/4_Comp.pdf + * @sa Michael Herf, The "double blend trick", May 2000, + * http://www.stereopsis.com/doubleblend.html + */ +static LLVMValueRef +lp_build_mul_u8n(struct gallivm_state *gallivm, + struct lp_type i16_type, + LLVMValueRef a, LLVMValueRef b) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef c8; + LLVMValueRef ab; + + assert(!i16_type.floating); + assert(lp_check_value(i16_type, a)); + assert(lp_check_value(i16_type, b)); + + c8 = lp_build_const_int_vec(gallivm, i16_type, 8); + +#if 0 + + /* a*b/255 ~= (a*(b + 1)) >> 256 */ + b = LLVMBuildAdd(builder, b, lp_build_const_int_vec(gallium, i16_type, 1), ""); + ab = LLVMBuildMul(builder, a, b, ""); + +#else + + /* ab/255 ~= (ab + (ab >> 8) + 0x80) >> 8 */ + ab = LLVMBuildMul(builder, a, b, ""); + ab = LLVMBuildAdd(builder, ab, LLVMBuildLShr(builder, ab, c8, ""), ""); + ab = LLVMBuildAdd(builder, ab, lp_build_const_int_vec(gallivm, i16_type, 0x80), ""); + +#endif + + ab = LLVMBuildLShr(builder, ab, c8, ""); + + return ab; +} + + +/** + * Generate a * b + */ +LLVMValueRef +lp_build_mul(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMValueRef shift; + LLVMValueRef res; + + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + if(a == bld->zero) + return bld->zero; + if(a == bld->one) + return b; + if(b == bld->zero) + return bld->zero; + if(b == bld->one) + return a; + if(a == bld->undef || b == bld->undef) + return bld->undef; + + if(!type.floating && !type.fixed && type.norm) { + if(type.width == 8) { + struct lp_type i16_type = lp_wider_type(type); + LLVMValueRef al, ah, bl, bh, abl, abh, ab; + + lp_build_unpack2(bld->gallivm, type, i16_type, a, &al, &ah); + lp_build_unpack2(bld->gallivm, type, i16_type, b, &bl, &bh); + + /* PMULLW, PSRLW, PADDW */ + abl = lp_build_mul_u8n(bld->gallivm, i16_type, al, bl); + abh = lp_build_mul_u8n(bld->gallivm, i16_type, ah, bh); + + ab = lp_build_pack2(bld->gallivm, i16_type, type, abl, abh); + + return ab; + } + + /* FIXME */ + assert(0); + } + + if(type.fixed) + shift = lp_build_const_int_vec(bld->gallivm, type, type.width/2); + else + shift = NULL; + + if(LLVMIsConstant(a) && LLVMIsConstant(b)) { + if (type.floating) + res = LLVMConstFMul(a, b); + else + res = LLVMConstMul(a, b); + if(shift) { + if(type.sign) + res = LLVMConstAShr(res, shift); + else + res = LLVMConstLShr(res, shift); + } + } + else { + if (type.floating) + res = LLVMBuildFMul(builder, a, b, ""); + else + res = LLVMBuildMul(builder, a, b, ""); + if(shift) { + if(type.sign) + res = LLVMBuildAShr(builder, res, shift, ""); + else + res = LLVMBuildLShr(builder, res, shift, ""); + } + } + + return res; +} + + +/** + * Small vector x scale multiplication optimization. + */ +LLVMValueRef +lp_build_mul_imm(struct lp_build_context *bld, + LLVMValueRef a, + int b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef factor; + + assert(lp_check_value(bld->type, a)); + + if(b == 0) + return bld->zero; + + if(b == 1) + return a; + + if(b == -1) + return lp_build_negate(bld, a); + + if(b == 2 && bld->type.floating) + return lp_build_add(bld, a, a); + + if(util_is_power_of_two(b)) { + unsigned shift = ffs(b) - 1; + + if(bld->type.floating) { +#if 0 + /* + * Power of two multiplication by directly manipulating the mantissa. + * + * XXX: This might not be always faster, it will introduce a small error + * for multiplication by zero, and it will produce wrong results + * for Inf and NaN. + */ + unsigned mantissa = lp_mantissa(bld->type); + factor = lp_build_const_int_vec(bld->gallivm, bld->type, (unsigned long long)shift << mantissa); + a = LLVMBuildBitCast(builder, a, lp_build_int_vec_type(bld->type), ""); + a = LLVMBuildAdd(builder, a, factor, ""); + a = LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, bld->type), ""); + return a; +#endif + } + else { + factor = lp_build_const_vec(bld->gallivm, bld->type, shift); + return LLVMBuildShl(builder, a, factor, ""); + } + } + + factor = lp_build_const_vec(bld->gallivm, bld->type, (double)b); + return lp_build_mul(bld, a, factor); +} + + +/** + * Generate a / b + */ +LLVMValueRef +lp_build_div(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + if(a == bld->zero) + return bld->zero; + if(a == bld->one) + return lp_build_rcp(bld, b); + if(b == bld->zero) + return bld->undef; + if(b == bld->one) + return a; + if(a == bld->undef || b == bld->undef) + return bld->undef; + + if(LLVMIsConstant(a) && LLVMIsConstant(b)) { + if (type.floating) + return LLVMConstFDiv(a, b); + else if (type.sign) + return LLVMConstSDiv(a, b); + else + return LLVMConstUDiv(a, b); + } + + if(util_cpu_caps.has_sse && type.width == 32 && type.length == 4) + return lp_build_mul(bld, a, lp_build_rcp(bld, b)); + + if (type.floating) + return LLVMBuildFDiv(builder, a, b, ""); + else if (type.sign) + return LLVMBuildSDiv(builder, a, b, ""); + else + return LLVMBuildUDiv(builder, a, b, ""); +} + + +/** + * Linear interpolation -- without any checks. + * + * @sa http://www.stereopsis.com/doubleblend.html + */ +static INLINE LLVMValueRef +lp_build_lerp_simple(struct lp_build_context *bld, + LLVMValueRef x, + LLVMValueRef v0, + LLVMValueRef v1) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef delta; + LLVMValueRef res; + + assert(lp_check_value(bld->type, x)); + assert(lp_check_value(bld->type, v0)); + assert(lp_check_value(bld->type, v1)); + + delta = lp_build_sub(bld, v1, v0); + + res = lp_build_mul(bld, x, delta); + + res = lp_build_add(bld, v0, res); + + if (bld->type.fixed) { + /* XXX: This step is necessary for lerping 8bit colors stored on 16bits, + * but it will be wrong for other uses. Basically we need a more + * powerful lp_type, capable of further distinguishing the values + * interpretation from the value storage. */ + res = LLVMBuildAnd(builder, res, lp_build_const_int_vec(bld->gallivm, bld->type, (1 << bld->type.width/2) - 1), ""); + } + + return res; +} + + +/** + * Linear interpolation. + */ +LLVMValueRef +lp_build_lerp(struct lp_build_context *bld, + LLVMValueRef x, + LLVMValueRef v0, + LLVMValueRef v1) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMValueRef res; + + assert(lp_check_value(type, x)); + assert(lp_check_value(type, v0)); + assert(lp_check_value(type, v1)); + + if (type.norm) { + struct lp_type wide_type; + struct lp_build_context wide_bld; + LLVMValueRef xl, xh, v0l, v0h, v1l, v1h, resl, resh; + LLVMValueRef shift; + + assert(type.length >= 2); + assert(!type.sign); + + /* + * Create a wider type, enough to hold the intermediate result of the + * multiplication. + */ + memset(&wide_type, 0, sizeof wide_type); + wide_type.fixed = TRUE; + wide_type.width = type.width*2; + wide_type.length = type.length/2; + + lp_build_context_init(&wide_bld, bld->gallivm, wide_type); + + lp_build_unpack2(bld->gallivm, type, wide_type, x, &xl, &xh); + lp_build_unpack2(bld->gallivm, type, wide_type, v0, &v0l, &v0h); + lp_build_unpack2(bld->gallivm, type, wide_type, v1, &v1l, &v1h); + + /* + * Scale x from [0, 255] to [0, 256] + */ + + shift = lp_build_const_int_vec(bld->gallivm, wide_type, type.width - 1); + + xl = lp_build_add(&wide_bld, xl, + LLVMBuildAShr(builder, xl, shift, "")); + xh = lp_build_add(&wide_bld, xh, + LLVMBuildAShr(builder, xh, shift, "")); + + /* + * Lerp both halves. + */ + + resl = lp_build_lerp_simple(&wide_bld, xl, v0l, v1l); + resh = lp_build_lerp_simple(&wide_bld, xh, v0h, v1h); + + res = lp_build_pack2(bld->gallivm, wide_type, type, resl, resh); + } else { + res = lp_build_lerp_simple(bld, x, v0, v1); + } + + return res; +} + + +LLVMValueRef +lp_build_lerp_2d(struct lp_build_context *bld, + LLVMValueRef x, + LLVMValueRef y, + LLVMValueRef v00, + LLVMValueRef v01, + LLVMValueRef v10, + LLVMValueRef v11) +{ + LLVMValueRef v0 = lp_build_lerp(bld, x, v00, v01); + LLVMValueRef v1 = lp_build_lerp(bld, x, v10, v11); + return lp_build_lerp(bld, y, v0, v1); +} + + +/** + * Generate min(a, b) + * Do checks for special cases. + */ +LLVMValueRef +lp_build_min(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b) +{ + assert(lp_check_value(bld->type, a)); + assert(lp_check_value(bld->type, b)); + + if(a == bld->undef || b == bld->undef) + return bld->undef; + + if(a == b) + return a; + + if(bld->type.norm) { + if(a == bld->zero || b == bld->zero) + return bld->zero; + if(a == bld->one) + return b; + if(b == bld->one) + return a; + } + + return lp_build_min_simple(bld, a, b); +} + + +/** + * Generate max(a, b) + * Do checks for special cases. + */ +LLVMValueRef +lp_build_max(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b) +{ + assert(lp_check_value(bld->type, a)); + assert(lp_check_value(bld->type, b)); + + if(a == bld->undef || b == bld->undef) + return bld->undef; + + if(a == b) + return a; + + if(bld->type.norm) { + if(a == bld->one || b == bld->one) + return bld->one; + if(a == bld->zero) + return b; + if(b == bld->zero) + return a; + } + + return lp_build_max_simple(bld, a, b); +} + + +/** + * Generate clamp(a, min, max) + * Do checks for special cases. + */ +LLVMValueRef +lp_build_clamp(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef min, + LLVMValueRef max) +{ + assert(lp_check_value(bld->type, a)); + assert(lp_check_value(bld->type, min)); + assert(lp_check_value(bld->type, max)); + + a = lp_build_min(bld, a, max); + a = lp_build_max(bld, a, min); + return a; +} + + +/** + * Generate abs(a) + */ +LLVMValueRef +lp_build_abs(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type); + + assert(lp_check_value(type, a)); + + if(!type.sign) + return a; + + if(type.floating) { + /* Mask out the sign bit */ + LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type); + unsigned long long absMask = ~(1ULL << (type.width - 1)); + LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type, ((unsigned long long) absMask)); + a = LLVMBuildBitCast(builder, a, int_vec_type, ""); + a = LLVMBuildAnd(builder, a, mask, ""); + a = LLVMBuildBitCast(builder, a, vec_type, ""); + return a; + } + + if(type.width*type.length == 128 && util_cpu_caps.has_ssse3) { + switch(type.width) { + case 8: + return lp_build_intrinsic_unary(builder, "llvm.x86.ssse3.pabs.b.128", vec_type, a); + case 16: + return lp_build_intrinsic_unary(builder, "llvm.x86.ssse3.pabs.w.128", vec_type, a); + case 32: + return lp_build_intrinsic_unary(builder, "llvm.x86.ssse3.pabs.d.128", vec_type, a); + } + } + + return lp_build_max(bld, a, LLVMBuildNeg(builder, a, "")); +} + + +LLVMValueRef +lp_build_negate(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + + assert(lp_check_value(bld->type, a)); + +#if HAVE_LLVM >= 0x0207 + if (bld->type.floating) + a = LLVMBuildFNeg(builder, a, ""); + else +#endif + a = LLVMBuildNeg(builder, a, ""); + + return a; +} + + +/** Return -1, 0 or +1 depending on the sign of a */ +LLVMValueRef +lp_build_sgn(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMValueRef cond; + LLVMValueRef res; + + assert(lp_check_value(type, a)); + + /* Handle non-zero case */ + if(!type.sign) { + /* if not zero then sign must be positive */ + res = bld->one; + } + else if(type.floating) { + LLVMTypeRef vec_type; + LLVMTypeRef int_type; + LLVMValueRef mask; + LLVMValueRef sign; + LLVMValueRef one; + unsigned long long maskBit = (unsigned long long)1 << (type.width - 1); + + int_type = lp_build_int_vec_type(bld->gallivm, type); + vec_type = lp_build_vec_type(bld->gallivm, type); + mask = lp_build_const_int_vec(bld->gallivm, type, maskBit); + + /* Take the sign bit and add it to 1 constant */ + sign = LLVMBuildBitCast(builder, a, int_type, ""); + sign = LLVMBuildAnd(builder, sign, mask, ""); + one = LLVMConstBitCast(bld->one, int_type); + res = LLVMBuildOr(builder, sign, one, ""); + res = LLVMBuildBitCast(builder, res, vec_type, ""); + } + else + { + LLVMValueRef minus_one = lp_build_const_vec(bld->gallivm, type, -1.0); + cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, a, bld->zero); + res = lp_build_select(bld, cond, bld->one, minus_one); + } + + /* Handle zero */ + cond = lp_build_cmp(bld, PIPE_FUNC_EQUAL, a, bld->zero); + res = lp_build_select(bld, cond, bld->zero, res); + + return res; +} + + +/** + * Set the sign of float vector 'a' according to 'sign'. + * If sign==0, return abs(a). + * If sign==1, return -abs(a); + * Other values for sign produce undefined results. + */ +LLVMValueRef +lp_build_set_sign(struct lp_build_context *bld, + LLVMValueRef a, LLVMValueRef sign) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type); + LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type); + LLVMValueRef shift = lp_build_const_int_vec(bld->gallivm, type, type.width - 1); + LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type, + ~((unsigned long long) 1 << (type.width - 1))); + LLVMValueRef val, res; + + assert(type.floating); + assert(lp_check_value(type, a)); + + /* val = reinterpret_cast(a) */ + val = LLVMBuildBitCast(builder, a, int_vec_type, ""); + /* val = val & mask */ + val = LLVMBuildAnd(builder, val, mask, ""); + /* sign = sign << shift */ + sign = LLVMBuildShl(builder, sign, shift, ""); + /* res = val | sign */ + res = LLVMBuildOr(builder, val, sign, ""); + /* res = reinterpret_cast(res) */ + res = LLVMBuildBitCast(builder, res, vec_type, ""); + + return res; +} + + +/** + * Convert vector of (or scalar) int to vector of (or scalar) float. + */ +LLVMValueRef +lp_build_int_to_float(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type); + + assert(type.floating); + + return LLVMBuildSIToFP(builder, a, vec_type, ""); +} + + + +enum lp_build_round_sse41_mode +{ + LP_BUILD_ROUND_SSE41_NEAREST = 0, + LP_BUILD_ROUND_SSE41_FLOOR = 1, + LP_BUILD_ROUND_SSE41_CEIL = 2, + LP_BUILD_ROUND_SSE41_TRUNCATE = 3 +}; + + +/** + * Helper for SSE4.1's ROUNDxx instructions. + * + * NOTE: In the SSE4.1's nearest mode, if two values are equally close, the + * result is the even value. That is, rounding 2.5 will be 2.0, and not 3.0. + */ +static INLINE LLVMValueRef +lp_build_round_sse41(struct lp_build_context *bld, + LLVMValueRef a, + enum lp_build_round_sse41_mode mode) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context); + const char *intrinsic; + LLVMValueRef res; + + assert(type.floating); + + assert(lp_check_value(type, a)); + assert(util_cpu_caps.has_sse4_1); + + if (type.length == 1) { + LLVMTypeRef vec_type; + LLVMValueRef undef; + LLVMValueRef args[3]; + LLVMValueRef index0 = LLVMConstInt(i32t, 0, 0); + + switch(type.width) { + case 32: + intrinsic = "llvm.x86.sse41.round.ss"; + break; + case 64: + intrinsic = "llvm.x86.sse41.round.sd"; + break; + default: + assert(0); + return bld->undef; + } + + vec_type = LLVMVectorType(bld->elem_type, 4); + + undef = LLVMGetUndef(vec_type); + + args[0] = undef; + args[1] = LLVMBuildInsertElement(builder, undef, a, index0, ""); + args[2] = LLVMConstInt(i32t, mode, 0); + + res = lp_build_intrinsic(builder, intrinsic, + vec_type, args, Elements(args)); + + res = LLVMBuildExtractElement(builder, res, index0, ""); + } + else { + assert(type.width*type.length == 128); + + switch(type.width) { + case 32: + intrinsic = "llvm.x86.sse41.round.ps"; + break; + case 64: + intrinsic = "llvm.x86.sse41.round.pd"; + break; + default: + assert(0); + return bld->undef; + } + + res = lp_build_intrinsic_binary(builder, intrinsic, + bld->vec_type, a, + LLVMConstInt(i32t, mode, 0)); + } + + return res; +} + + +static INLINE LLVMValueRef +lp_build_iround_nearest_sse2(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context); + LLVMTypeRef ret_type = lp_build_int_vec_type(bld->gallivm, type); + const char *intrinsic; + LLVMValueRef res; + + assert(type.floating); + /* using the double precision conversions is a bit more complicated */ + assert(type.width == 32); + + assert(lp_check_value(type, a)); + assert(util_cpu_caps.has_sse2); + + /* This is relying on MXCSR rounding mode, which should always be nearest. */ + if (type.length == 1) { + LLVMTypeRef vec_type; + LLVMValueRef undef; + LLVMValueRef arg; + LLVMValueRef index0 = LLVMConstInt(i32t, 0, 0); + + vec_type = LLVMVectorType(bld->elem_type, 4); + + intrinsic = "llvm.x86.sse.cvtss2si"; + + undef = LLVMGetUndef(vec_type); + + arg = LLVMBuildInsertElement(builder, undef, a, index0, ""); + + res = lp_build_intrinsic_unary(builder, intrinsic, + ret_type, arg); + } + else { + assert(type.width*type.length == 128); + + intrinsic = "llvm.x86.sse2.cvtps2dq"; + + res = lp_build_intrinsic_unary(builder, intrinsic, + ret_type, a); + } + + return res; +} + + +/** + * Return the integer part of a float (vector) value (== round toward zero). + * The returned value is a float (vector). + * Ex: trunc(-1.5) = -1.0 + */ +LLVMValueRef +lp_build_trunc(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + + assert(type.floating); + assert(lp_check_value(type, a)); + + if (util_cpu_caps.has_sse4_1 && + (type.length == 1 || type.width*type.length == 128)) { + return lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_TRUNCATE); + } + else { + LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type); + LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type); + LLVMValueRef res; + res = LLVMBuildFPToSI(builder, a, int_vec_type, ""); + res = LLVMBuildSIToFP(builder, res, vec_type, ""); + return res; + } +} + + +/** + * Return float (vector) rounded to nearest integer (vector). The returned + * value is a float (vector). + * Ex: round(0.9) = 1.0 + * Ex: round(-1.5) = -2.0 + */ +LLVMValueRef +lp_build_round(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + + assert(type.floating); + assert(lp_check_value(type, a)); + + if (util_cpu_caps.has_sse4_1 && + (type.length == 1 || type.width*type.length == 128)) { + return lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_NEAREST); + } + else { + LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type); + LLVMValueRef res; + res = lp_build_iround(bld, a); + res = LLVMBuildSIToFP(builder, res, vec_type, ""); + return res; + } +} + + +/** + * Return floor of float (vector), result is a float (vector) + * Ex: floor(1.1) = 1.0 + * Ex: floor(-1.1) = -2.0 + */ +LLVMValueRef +lp_build_floor(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + + assert(type.floating); + assert(lp_check_value(type, a)); + + if (util_cpu_caps.has_sse4_1 && + (type.length == 1 || type.width*type.length == 128)) { + return lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_FLOOR); + } + else { + LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type); + LLVMValueRef res; + res = lp_build_ifloor(bld, a); + res = LLVMBuildSIToFP(builder, res, vec_type, ""); + return res; + } +} + + +/** + * Return ceiling of float (vector), returning float (vector). + * Ex: ceil( 1.1) = 2.0 + * Ex: ceil(-1.1) = -1.0 + */ +LLVMValueRef +lp_build_ceil(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + + assert(type.floating); + assert(lp_check_value(type, a)); + + if (util_cpu_caps.has_sse4_1 && + (type.length == 1 || type.width*type.length == 128)) { + return lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_CEIL); + } + else { + LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type); + LLVMValueRef res; + res = lp_build_iceil(bld, a); + res = LLVMBuildSIToFP(builder, res, vec_type, ""); + return res; + } +} + + +/** + * Return fractional part of 'a' computed as a - floor(a) + * Typically used in texture coord arithmetic. + */ +LLVMValueRef +lp_build_fract(struct lp_build_context *bld, + LLVMValueRef a) +{ + assert(bld->type.floating); + return lp_build_sub(bld, a, lp_build_floor(bld, a)); +} + + +/** + * Return the integer part of a float (vector) value (== round toward zero). + * The returned value is an integer (vector). + * Ex: itrunc(-1.5) = -1 + */ +LLVMValueRef +lp_build_itrunc(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type); + + assert(type.floating); + assert(lp_check_value(type, a)); + + return LLVMBuildFPToSI(builder, a, int_vec_type, ""); +} + + +/** + * Return float (vector) rounded to nearest integer (vector). The returned + * value is an integer (vector). + * Ex: iround(0.9) = 1 + * Ex: iround(-1.5) = -2 + */ +LLVMValueRef +lp_build_iround(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMTypeRef int_vec_type = bld->int_vec_type; + LLVMValueRef res; + + assert(type.floating); + + assert(lp_check_value(type, a)); + + if (util_cpu_caps.has_sse2 && + ((type.width == 32) && (type.length == 1 || type.length == 4))) { + return lp_build_iround_nearest_sse2(bld, a); + } + else if (util_cpu_caps.has_sse4_1 && + (type.length == 1 || type.width*type.length == 128)) { + res = lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_NEAREST); + } + else { + LLVMValueRef half; + + half = lp_build_const_vec(bld->gallivm, type, 0.5); + + if (type.sign) { + LLVMTypeRef vec_type = bld->vec_type; + LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type, + (unsigned long long)1 << (type.width - 1)); + LLVMValueRef sign; + + /* get sign bit */ + sign = LLVMBuildBitCast(builder, a, int_vec_type, ""); + sign = LLVMBuildAnd(builder, sign, mask, ""); + + /* sign * 0.5 */ + half = LLVMBuildBitCast(builder, half, int_vec_type, ""); + half = LLVMBuildOr(builder, sign, half, ""); + half = LLVMBuildBitCast(builder, half, vec_type, ""); + } + + res = LLVMBuildFAdd(builder, a, half, ""); + } + + res = LLVMBuildFPToSI(builder, res, int_vec_type, ""); + + return res; +} + + +/** + * Return floor of float (vector), result is an int (vector) + * Ex: ifloor(1.1) = 1.0 + * Ex: ifloor(-1.1) = -2.0 + */ +LLVMValueRef +lp_build_ifloor(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMTypeRef int_vec_type = bld->int_vec_type; + LLVMValueRef res; + + assert(type.floating); + assert(lp_check_value(type, a)); + + if (util_cpu_caps.has_sse4_1 && + (type.length == 1 || type.width*type.length == 128)) { + res = lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_FLOOR); + } + else { + res = a; + + if (type.sign) { + /* Take the sign bit and add it to 1 constant */ + LLVMTypeRef vec_type = bld->vec_type; + unsigned mantissa = lp_mantissa(type); + LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type, + (unsigned long long)1 << (type.width - 1)); + LLVMValueRef sign; + LLVMValueRef offset; + + /* sign = a < 0 ? ~0 : 0 */ + sign = LLVMBuildBitCast(builder, a, int_vec_type, ""); + sign = LLVMBuildAnd(builder, sign, mask, ""); + sign = LLVMBuildAShr(builder, sign, + lp_build_const_int_vec(bld->gallivm, type, + type.width - 1), + "ifloor.sign"); + + /* offset = -0.99999(9)f */ + offset = lp_build_const_vec(bld->gallivm, type, + -(double)(((unsigned long long)1 << mantissa) - 10)/((unsigned long long)1 << mantissa)); + offset = LLVMConstBitCast(offset, int_vec_type); + + /* offset = a < 0 ? offset : 0.0f */ + offset = LLVMBuildAnd(builder, offset, sign, ""); + offset = LLVMBuildBitCast(builder, offset, vec_type, "ifloor.offset"); + + res = LLVMBuildFAdd(builder, res, offset, "ifloor.res"); + } + } + + /* round to nearest (toward zero) */ + res = LLVMBuildFPToSI(builder, res, int_vec_type, "ifloor.res"); + + return res; +} + + +/** + * Return ceiling of float (vector), returning int (vector). + * Ex: iceil( 1.1) = 2 + * Ex: iceil(-1.1) = -1 + */ +LLVMValueRef +lp_build_iceil(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMTypeRef int_vec_type = bld->int_vec_type; + LLVMValueRef res; + + assert(type.floating); + assert(lp_check_value(type, a)); + + if (util_cpu_caps.has_sse4_1 && + (type.length == 1 || type.width*type.length == 128)) { + res = lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_CEIL); + } + else { + LLVMTypeRef vec_type = bld->vec_type; + unsigned mantissa = lp_mantissa(type); + LLVMValueRef offset; + + /* offset = 0.99999(9)f */ + offset = lp_build_const_vec(bld->gallivm, type, + (double)(((unsigned long long)1 << mantissa) - 10)/((unsigned long long)1 << mantissa)); + + if (type.sign) { + LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type, + (unsigned long long)1 << (type.width - 1)); + LLVMValueRef sign; + + /* sign = a < 0 ? 0 : ~0 */ + sign = LLVMBuildBitCast(builder, a, int_vec_type, ""); + sign = LLVMBuildAnd(builder, sign, mask, ""); + sign = LLVMBuildAShr(builder, sign, + lp_build_const_int_vec(bld->gallivm, type, + type.width - 1), + "iceil.sign"); + sign = LLVMBuildNot(builder, sign, "iceil.not"); + + /* offset = a < 0 ? 0.0 : offset */ + offset = LLVMConstBitCast(offset, int_vec_type); + offset = LLVMBuildAnd(builder, offset, sign, ""); + offset = LLVMBuildBitCast(builder, offset, vec_type, "iceil.offset"); + } + + res = LLVMBuildFAdd(builder, a, offset, "iceil.res"); + } + + /* round to nearest (toward zero) */ + res = LLVMBuildFPToSI(builder, res, int_vec_type, "iceil.res"); + + return res; +} + + +/** + * Combined ifloor() & fract(). + * + * Preferred to calling the functions separately, as it will ensure that the + * stratergy (floor() vs ifloor()) that results in less redundant work is used. + */ +void +lp_build_ifloor_fract(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef *out_ipart, + LLVMValueRef *out_fpart) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMValueRef ipart; + + assert(type.floating); + assert(lp_check_value(type, a)); + + if (util_cpu_caps.has_sse4_1 && + (type.length == 1 || type.width*type.length == 128)) { + /* + * floor() is easier. + */ + + ipart = lp_build_floor(bld, a); + *out_fpart = LLVMBuildFSub(builder, a, ipart, "fpart"); + *out_ipart = LLVMBuildFPToSI(builder, ipart, bld->int_vec_type, "ipart"); + } + else { + /* + * ifloor() is easier. + */ + + *out_ipart = lp_build_ifloor(bld, a); + ipart = LLVMBuildSIToFP(builder, *out_ipart, bld->vec_type, "ipart"); + *out_fpart = LLVMBuildFSub(builder, a, ipart, "fpart"); + } +} + + +LLVMValueRef +lp_build_sqrt(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type); + char intrinsic[32]; + + assert(lp_check_value(type, a)); + + /* TODO: optimize the constant case */ + /* TODO: optimize the constant case */ + + assert(type.floating); + util_snprintf(intrinsic, sizeof intrinsic, "llvm.sqrt.v%uf%u", type.length, type.width); + + return lp_build_intrinsic_unary(builder, intrinsic, vec_type, a); +} + + +/** + * Do one Newton-Raphson step to improve reciprocate precision: + * + * x_{i+1} = x_i * (2 - a * x_i) + * + * XXX: Unfortunately this won't give IEEE-754 conformant results for 0 or + * +/-Inf, giving NaN instead. Certain applications rely on this behavior, + * such as Google Earth, which does RCP(RSQRT(0.0) when drawing the Earth's + * halo. It would be necessary to clamp the argument to prevent this. + * + * See also: + * - http://en.wikipedia.org/wiki/Division_(digital)#Newton.E2.80.93Raphson_division + * - http://softwarecommunity.intel.com/articles/eng/1818.htm + */ +static INLINE LLVMValueRef +lp_build_rcp_refine(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef rcp_a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef two = lp_build_const_vec(bld->gallivm, bld->type, 2.0); + LLVMValueRef res; + + res = LLVMBuildFMul(builder, a, rcp_a, ""); + res = LLVMBuildFSub(builder, two, res, ""); + res = LLVMBuildFMul(builder, rcp_a, res, ""); + + return res; +} + + +LLVMValueRef +lp_build_rcp(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + + assert(lp_check_value(type, a)); + + if(a == bld->zero) + return bld->undef; + if(a == bld->one) + return bld->one; + if(a == bld->undef) + return bld->undef; + + assert(type.floating); + + if(LLVMIsConstant(a)) + return LLVMConstFDiv(bld->one, a); + + /* + * We don't use RCPPS because: + * - it only has 10bits of precision + * - it doesn't even get the reciprocate of 1.0 exactly + * - doing Newton-Rapshon steps yields wrong (NaN) values for 0.0 or Inf + * - for recent processors the benefit over DIVPS is marginal, a case + * depedent + * + * We could still use it on certain processors if benchmarks show that the + * RCPPS plus necessary workarounds are still preferrable to DIVPS; or for + * particular uses that require less workarounds. + */ + + if (FALSE && util_cpu_caps.has_sse && type.width == 32 && type.length == 4) { + const unsigned num_iterations = 0; + LLVMValueRef res; + unsigned i; + + res = lp_build_intrinsic_unary(builder, "llvm.x86.sse.rcp.ps", bld->vec_type, a); + + for (i = 0; i < num_iterations; ++i) { + res = lp_build_rcp_refine(bld, a, res); + } + + return res; + } + + return LLVMBuildFDiv(builder, bld->one, a, ""); +} + + +/** + * Do one Newton-Raphson step to improve rsqrt precision: + * + * x_{i+1} = 0.5 * x_i * (3.0 - a * x_i * x_i) + * + * See also: + * - http://softwarecommunity.intel.com/articles/eng/1818.htm + */ +static INLINE LLVMValueRef +lp_build_rsqrt_refine(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef rsqrt_a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef half = lp_build_const_vec(bld->gallivm, bld->type, 0.5); + LLVMValueRef three = lp_build_const_vec(bld->gallivm, bld->type, 3.0); + LLVMValueRef res; + + res = LLVMBuildFMul(builder, rsqrt_a, rsqrt_a, ""); + res = LLVMBuildFMul(builder, a, res, ""); + res = LLVMBuildFSub(builder, three, res, ""); + res = LLVMBuildFMul(builder, rsqrt_a, res, ""); + res = LLVMBuildFMul(builder, half, res, ""); + + return res; +} + + +/** + * Generate 1/sqrt(a) + */ +LLVMValueRef +lp_build_rsqrt(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + + assert(lp_check_value(type, a)); + + assert(type.floating); + + if (util_cpu_caps.has_sse && type.width == 32 && type.length == 4) { + const unsigned num_iterations = 0; + LLVMValueRef res; + unsigned i; + + res = lp_build_intrinsic_unary(builder, "llvm.x86.sse.rsqrt.ps", bld->vec_type, a); + + for (i = 0; i < num_iterations; ++i) { + res = lp_build_rsqrt_refine(bld, a, res); + } + + return res; + } + + return lp_build_rcp(bld, lp_build_sqrt(bld, a)); +} + + +static inline LLVMValueRef +lp_build_const_v4si(struct gallivm_state *gallivm, unsigned long value) +{ + LLVMValueRef element = lp_build_const_int32(gallivm, value); + LLVMValueRef elements[4] = { element, element, element, element }; + return LLVMConstVector(elements, 4); +} + +static inline LLVMValueRef +lp_build_const_v4sf(struct gallivm_state *gallivm, float value) +{ + LLVMValueRef element = lp_build_const_float(gallivm, value); + LLVMValueRef elements[4] = { element, element, element, element }; + return LLVMConstVector(elements, 4); +} + + +/** + * Generate sin(a) using SSE2 + */ +LLVMValueRef +lp_build_sin(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + struct gallivm_state *gallivm = bld->gallivm; + struct lp_type int_type = lp_int_type(bld->type); + LLVMBuilderRef b = builder; + LLVMTypeRef v4sf = LLVMVectorType(LLVMFloatTypeInContext(bld->gallivm->context), 4); + LLVMTypeRef v4si = LLVMVectorType(LLVMInt32TypeInContext(bld->gallivm->context), 4); + + /* + * take the absolute value, + * x = _mm_and_ps(x, *(v4sf*)_ps_inv_sign_mask); + */ + + LLVMValueRef inv_sig_mask = lp_build_const_v4si(bld->gallivm, ~0x80000000); + LLVMValueRef a_v4si = LLVMBuildBitCast(b, a, v4si, "a_v4si"); + + LLVMValueRef absi = LLVMBuildAnd(b, a_v4si, inv_sig_mask, "absi"); + LLVMValueRef x_abs = LLVMBuildBitCast(b, absi, v4sf, "x_abs"); + + /* + * extract the sign bit (upper one) + * sign_bit = _mm_and_ps(sign_bit, *(v4sf*)_ps_sign_mask); + */ + LLVMValueRef sig_mask = lp_build_const_v4si(bld->gallivm, 0x80000000); + LLVMValueRef sign_bit_i = LLVMBuildAnd(b, a_v4si, sig_mask, "sign_bit_i"); + + /* + * scale by 4/Pi + * y = _mm_mul_ps(x, *(v4sf*)_ps_cephes_FOPI); + */ + + LLVMValueRef FOPi = lp_build_const_v4sf(gallivm, 1.27323954473516); + LLVMValueRef scale_y = LLVMBuildFMul(b, x_abs, FOPi, "scale_y"); + + /* + * store the integer part of y in mm0 + * emm2 = _mm_cvttps_epi32(y); + */ + + LLVMValueRef emm2_i = LLVMBuildFPToSI(b, scale_y, v4si, "emm2_i"); + + /* + * j=(j+1) & (~1) (see the cephes sources) + * emm2 = _mm_add_epi32(emm2, *(v4si*)_pi32_1); + */ + + LLVMValueRef all_one = lp_build_const_v4si(bld->gallivm, 1); + LLVMValueRef emm2_add = LLVMBuildAdd(b, emm2_i, all_one, "emm2_add"); + /* + * emm2 = _mm_and_si128(emm2, *(v4si*)_pi32_inv1); + */ + LLVMValueRef inv_one = lp_build_const_v4si(bld->gallivm, ~1); + LLVMValueRef emm2_and = LLVMBuildAnd(b, emm2_add, inv_one, "emm2_and"); + + /* + * y = _mm_cvtepi32_ps(emm2); + */ + LLVMValueRef y_2 = LLVMBuildSIToFP(b, emm2_and, v4sf, "y_2"); + + /* get the swap sign flag + * emm0 = _mm_and_si128(emm2, *(v4si*)_pi32_4); + */ + LLVMValueRef pi32_4 = lp_build_const_v4si(bld->gallivm, 4); + LLVMValueRef emm0_and = LLVMBuildAnd(b, emm2_add, pi32_4, "emm0_and"); + + /* + * emm2 = _mm_slli_epi32(emm0, 29); + */ + LLVMValueRef const_29 = lp_build_const_v4si(bld->gallivm, 29); + LLVMValueRef swap_sign_bit = LLVMBuildShl(b, emm0_and, const_29, "swap_sign_bit"); + + /* + * get the polynom selection mask + * there is one polynom for 0 <= x <= Pi/4 + * and another one for Pi/4gallivm, 2); + LLVMValueRef emm2_3 = LLVMBuildAnd(b, emm2_and, pi32_2, "emm2_3"); + LLVMValueRef poly_mask = lp_build_compare(bld->gallivm, + int_type, PIPE_FUNC_EQUAL, + emm2_3, lp_build_const_v4si(bld->gallivm, 0)); + /* + * sign_bit = _mm_xor_ps(sign_bit, swap_sign_bit); + */ + LLVMValueRef sign_bit_1 = LLVMBuildXor(b, sign_bit_i, swap_sign_bit, "sign_bit"); + + /* + * _PS_CONST(minus_cephes_DP1, -0.78515625); + * _PS_CONST(minus_cephes_DP2, -2.4187564849853515625e-4); + * _PS_CONST(minus_cephes_DP3, -3.77489497744594108e-8); + */ + LLVMValueRef DP1 = lp_build_const_v4sf(gallivm, -0.78515625); + LLVMValueRef DP2 = lp_build_const_v4sf(gallivm, -2.4187564849853515625e-4); + LLVMValueRef DP3 = lp_build_const_v4sf(gallivm, -3.77489497744594108e-8); + + /* + * The magic pass: "Extended precision modular arithmetic" + * x = ((x - y * DP1) - y * DP2) - y * DP3; + * xmm1 = _mm_mul_ps(y, xmm1); + * xmm2 = _mm_mul_ps(y, xmm2); + * xmm3 = _mm_mul_ps(y, xmm3); + */ + LLVMValueRef xmm1 = LLVMBuildFMul(b, y_2, DP1, "xmm1"); + LLVMValueRef xmm2 = LLVMBuildFMul(b, y_2, DP2, "xmm2"); + LLVMValueRef xmm3 = LLVMBuildFMul(b, y_2, DP3, "xmm3"); + + /* + * x = _mm_add_ps(x, xmm1); + * x = _mm_add_ps(x, xmm2); + * x = _mm_add_ps(x, xmm3); + */ + + LLVMValueRef x_1 = LLVMBuildFAdd(b, x_abs, xmm1, "x_1"); + LLVMValueRef x_2 = LLVMBuildFAdd(b, x_1, xmm2, "x_2"); + LLVMValueRef x_3 = LLVMBuildFAdd(b, x_2, xmm3, "x_3"); + + /* + * Evaluate the first polynom (0 <= x <= Pi/4) + * + * z = _mm_mul_ps(x,x); + */ + LLVMValueRef z = LLVMBuildFMul(b, x_3, x_3, "z"); + + /* + * _PS_CONST(coscof_p0, 2.443315711809948E-005); + * _PS_CONST(coscof_p1, -1.388731625493765E-003); + * _PS_CONST(coscof_p2, 4.166664568298827E-002); + */ + LLVMValueRef coscof_p0 = lp_build_const_v4sf(gallivm, 2.443315711809948E-005); + LLVMValueRef coscof_p1 = lp_build_const_v4sf(gallivm, -1.388731625493765E-003); + LLVMValueRef coscof_p2 = lp_build_const_v4sf(gallivm, 4.166664568298827E-002); + + /* + * y = *(v4sf*)_ps_coscof_p0; + * y = _mm_mul_ps(y, z); + */ + LLVMValueRef y_3 = LLVMBuildFMul(b, z, coscof_p0, "y_3"); + LLVMValueRef y_4 = LLVMBuildFAdd(b, y_3, coscof_p1, "y_4"); + LLVMValueRef y_5 = LLVMBuildFMul(b, y_4, z, "y_5"); + LLVMValueRef y_6 = LLVMBuildFAdd(b, y_5, coscof_p2, "y_6"); + LLVMValueRef y_7 = LLVMBuildFMul(b, y_6, z, "y_7"); + LLVMValueRef y_8 = LLVMBuildFMul(b, y_7, z, "y_8"); + + + /* + * tmp = _mm_mul_ps(z, *(v4sf*)_ps_0p5); + * y = _mm_sub_ps(y, tmp); + * y = _mm_add_ps(y, *(v4sf*)_ps_1); + */ + LLVMValueRef half = lp_build_const_v4sf(gallivm, 0.5); + LLVMValueRef tmp = LLVMBuildFMul(b, z, half, "tmp"); + LLVMValueRef y_9 = LLVMBuildFSub(b, y_8, tmp, "y_8"); + LLVMValueRef one = lp_build_const_v4sf(gallivm, 1.0); + LLVMValueRef y_10 = LLVMBuildFAdd(b, y_9, one, "y_9"); + + /* + * _PS_CONST(sincof_p0, -1.9515295891E-4); + * _PS_CONST(sincof_p1, 8.3321608736E-3); + * _PS_CONST(sincof_p2, -1.6666654611E-1); + */ + LLVMValueRef sincof_p0 = lp_build_const_v4sf(gallivm, -1.9515295891E-4); + LLVMValueRef sincof_p1 = lp_build_const_v4sf(gallivm, 8.3321608736E-3); + LLVMValueRef sincof_p2 = lp_build_const_v4sf(gallivm, -1.6666654611E-1); + + /* + * Evaluate the second polynom (Pi/4 <= x <= 0) + * + * y2 = *(v4sf*)_ps_sincof_p0; + * y2 = _mm_mul_ps(y2, z); + * y2 = _mm_add_ps(y2, *(v4sf*)_ps_sincof_p1); + * y2 = _mm_mul_ps(y2, z); + * y2 = _mm_add_ps(y2, *(v4sf*)_ps_sincof_p2); + * y2 = _mm_mul_ps(y2, z); + * y2 = _mm_mul_ps(y2, x); + * y2 = _mm_add_ps(y2, x); + */ + + LLVMValueRef y2_3 = LLVMBuildFMul(b, z, sincof_p0, "y2_3"); + LLVMValueRef y2_4 = LLVMBuildFAdd(b, y2_3, sincof_p1, "y2_4"); + LLVMValueRef y2_5 = LLVMBuildFMul(b, y2_4, z, "y2_5"); + LLVMValueRef y2_6 = LLVMBuildFAdd(b, y2_5, sincof_p2, "y2_6"); + LLVMValueRef y2_7 = LLVMBuildFMul(b, y2_6, z, "y2_7"); + LLVMValueRef y2_8 = LLVMBuildFMul(b, y2_7, x_3, "y2_8"); + LLVMValueRef y2_9 = LLVMBuildFAdd(b, y2_8, x_3, "y2_9"); + + /* + * select the correct result from the two polynoms + * xmm3 = poly_mask; + * y2 = _mm_and_ps(xmm3, y2); //, xmm3); + * y = _mm_andnot_ps(xmm3, y); + * y = _mm_add_ps(y,y2); + */ + LLVMValueRef y2_i = LLVMBuildBitCast(b, y2_9, v4si, "y2_i"); + LLVMValueRef y_i = LLVMBuildBitCast(b, y_10, v4si, "y_i"); + LLVMValueRef y2_and = LLVMBuildAnd(b, y2_i, poly_mask, "y2_and"); + LLVMValueRef inv = lp_build_const_v4si(bld->gallivm, ~0); + LLVMValueRef poly_mask_inv = LLVMBuildXor(b, poly_mask, inv, "poly_mask_inv"); + LLVMValueRef y_and = LLVMBuildAnd(b, y_i, poly_mask_inv, "y_and"); + LLVMValueRef y_combine = LLVMBuildAdd(b, y_and, y2_and, "y_combine"); + + /* + * update the sign + * y = _mm_xor_ps(y, sign_bit); + */ + LLVMValueRef y_sign = LLVMBuildXor(b, y_combine, sign_bit_1, "y_sin"); + LLVMValueRef y_result = LLVMBuildBitCast(b, y_sign, v4sf, "y_result"); + return y_result; +} + + +/** + * Generate cos(a) using SSE2 + */ +LLVMValueRef +lp_build_cos(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + struct gallivm_state *gallivm = bld->gallivm; + struct lp_type int_type = lp_int_type(bld->type); + LLVMBuilderRef b = builder; + LLVMTypeRef v4sf = LLVMVectorType(LLVMFloatTypeInContext(bld->gallivm->context), 4); + LLVMTypeRef v4si = LLVMVectorType(LLVMInt32TypeInContext(bld->gallivm->context), 4); + + /* + * take the absolute value, + * x = _mm_and_ps(x, *(v4sf*)_ps_inv_sign_mask); + */ + + LLVMValueRef inv_sig_mask = lp_build_const_v4si(bld->gallivm, ~0x80000000); + LLVMValueRef a_v4si = LLVMBuildBitCast(b, a, v4si, "a_v4si"); + + LLVMValueRef absi = LLVMBuildAnd(b, a_v4si, inv_sig_mask, "absi"); + LLVMValueRef x_abs = LLVMBuildBitCast(b, absi, v4sf, "x_abs"); + + /* + * scale by 4/Pi + * y = _mm_mul_ps(x, *(v4sf*)_ps_cephes_FOPI); + */ + + LLVMValueRef FOPi = lp_build_const_v4sf(gallivm, 1.27323954473516); + LLVMValueRef scale_y = LLVMBuildFMul(b, x_abs, FOPi, "scale_y"); + + /* + * store the integer part of y in mm0 + * emm2 = _mm_cvttps_epi32(y); + */ + + LLVMValueRef emm2_i = LLVMBuildFPToSI(b, scale_y, v4si, "emm2_i"); + + /* + * j=(j+1) & (~1) (see the cephes sources) + * emm2 = _mm_add_epi32(emm2, *(v4si*)_pi32_1); + */ + + LLVMValueRef all_one = lp_build_const_v4si(bld->gallivm, 1); + LLVMValueRef emm2_add = LLVMBuildAdd(b, emm2_i, all_one, "emm2_add"); + /* + * emm2 = _mm_and_si128(emm2, *(v4si*)_pi32_inv1); + */ + LLVMValueRef inv_one = lp_build_const_v4si(bld->gallivm, ~1); + LLVMValueRef emm2_and = LLVMBuildAnd(b, emm2_add, inv_one, "emm2_and"); + + /* + * y = _mm_cvtepi32_ps(emm2); + */ + LLVMValueRef y_2 = LLVMBuildSIToFP(b, emm2_and, v4sf, "y_2"); + + + /* + * emm2 = _mm_sub_epi32(emm2, *(v4si*)_pi32_2); + */ + LLVMValueRef const_2 = lp_build_const_v4si(bld->gallivm, 2); + LLVMValueRef emm2_2 = LLVMBuildSub(b, emm2_and, const_2, "emm2_2"); + + + /* get the swap sign flag + * emm0 = _mm_andnot_si128(emm2, *(v4si*)_pi32_4); + */ + LLVMValueRef inv = lp_build_const_v4si(bld->gallivm, ~0); + LLVMValueRef emm0_not = LLVMBuildXor(b, emm2_2, inv, "emm0_not"); + LLVMValueRef pi32_4 = lp_build_const_v4si(bld->gallivm, 4); + LLVMValueRef emm0_and = LLVMBuildAnd(b, emm0_not, pi32_4, "emm0_and"); + + /* + * emm2 = _mm_slli_epi32(emm0, 29); + */ + LLVMValueRef const_29 = lp_build_const_v4si(bld->gallivm, 29); + LLVMValueRef sign_bit = LLVMBuildShl(b, emm0_and, const_29, "sign_bit"); + + /* + * get the polynom selection mask + * there is one polynom for 0 <= x <= Pi/4 + * and another one for Pi/4gallivm, 2); + LLVMValueRef emm2_3 = LLVMBuildAnd(b, emm2_2, pi32_2, "emm2_3"); + LLVMValueRef poly_mask = lp_build_compare(bld->gallivm, + int_type, PIPE_FUNC_EQUAL, + emm2_3, lp_build_const_v4si(bld->gallivm, 0)); + + /* + * _PS_CONST(minus_cephes_DP1, -0.78515625); + * _PS_CONST(minus_cephes_DP2, -2.4187564849853515625e-4); + * _PS_CONST(minus_cephes_DP3, -3.77489497744594108e-8); + */ + LLVMValueRef DP1 = lp_build_const_v4sf(gallivm, -0.78515625); + LLVMValueRef DP2 = lp_build_const_v4sf(gallivm, -2.4187564849853515625e-4); + LLVMValueRef DP3 = lp_build_const_v4sf(gallivm, -3.77489497744594108e-8); + + /* + * The magic pass: "Extended precision modular arithmetic" + * x = ((x - y * DP1) - y * DP2) - y * DP3; + * xmm1 = _mm_mul_ps(y, xmm1); + * xmm2 = _mm_mul_ps(y, xmm2); + * xmm3 = _mm_mul_ps(y, xmm3); + */ + LLVMValueRef xmm1 = LLVMBuildFMul(b, y_2, DP1, "xmm1"); + LLVMValueRef xmm2 = LLVMBuildFMul(b, y_2, DP2, "xmm2"); + LLVMValueRef xmm3 = LLVMBuildFMul(b, y_2, DP3, "xmm3"); + + /* + * x = _mm_add_ps(x, xmm1); + * x = _mm_add_ps(x, xmm2); + * x = _mm_add_ps(x, xmm3); + */ + + LLVMValueRef x_1 = LLVMBuildFAdd(b, x_abs, xmm1, "x_1"); + LLVMValueRef x_2 = LLVMBuildFAdd(b, x_1, xmm2, "x_2"); + LLVMValueRef x_3 = LLVMBuildFAdd(b, x_2, xmm3, "x_3"); + + /* + * Evaluate the first polynom (0 <= x <= Pi/4) + * + * z = _mm_mul_ps(x,x); + */ + LLVMValueRef z = LLVMBuildFMul(b, x_3, x_3, "z"); + + /* + * _PS_CONST(coscof_p0, 2.443315711809948E-005); + * _PS_CONST(coscof_p1, -1.388731625493765E-003); + * _PS_CONST(coscof_p2, 4.166664568298827E-002); + */ + LLVMValueRef coscof_p0 = lp_build_const_v4sf(gallivm, 2.443315711809948E-005); + LLVMValueRef coscof_p1 = lp_build_const_v4sf(gallivm, -1.388731625493765E-003); + LLVMValueRef coscof_p2 = lp_build_const_v4sf(gallivm, 4.166664568298827E-002); + + /* + * y = *(v4sf*)_ps_coscof_p0; + * y = _mm_mul_ps(y, z); + */ + LLVMValueRef y_3 = LLVMBuildFMul(b, z, coscof_p0, "y_3"); + LLVMValueRef y_4 = LLVMBuildFAdd(b, y_3, coscof_p1, "y_4"); + LLVMValueRef y_5 = LLVMBuildFMul(b, y_4, z, "y_5"); + LLVMValueRef y_6 = LLVMBuildFAdd(b, y_5, coscof_p2, "y_6"); + LLVMValueRef y_7 = LLVMBuildFMul(b, y_6, z, "y_7"); + LLVMValueRef y_8 = LLVMBuildFMul(b, y_7, z, "y_8"); + + + /* + * tmp = _mm_mul_ps(z, *(v4sf*)_ps_0p5); + * y = _mm_sub_ps(y, tmp); + * y = _mm_add_ps(y, *(v4sf*)_ps_1); + */ + LLVMValueRef half = lp_build_const_v4sf(gallivm, 0.5); + LLVMValueRef tmp = LLVMBuildFMul(b, z, half, "tmp"); + LLVMValueRef y_9 = LLVMBuildFSub(b, y_8, tmp, "y_8"); + LLVMValueRef one = lp_build_const_v4sf(gallivm, 1.0); + LLVMValueRef y_10 = LLVMBuildFAdd(b, y_9, one, "y_9"); + + /* + * _PS_CONST(sincof_p0, -1.9515295891E-4); + * _PS_CONST(sincof_p1, 8.3321608736E-3); + * _PS_CONST(sincof_p2, -1.6666654611E-1); + */ + LLVMValueRef sincof_p0 = lp_build_const_v4sf(gallivm, -1.9515295891E-4); + LLVMValueRef sincof_p1 = lp_build_const_v4sf(gallivm, 8.3321608736E-3); + LLVMValueRef sincof_p2 = lp_build_const_v4sf(gallivm, -1.6666654611E-1); + + /* + * Evaluate the second polynom (Pi/4 <= x <= 0) + * + * y2 = *(v4sf*)_ps_sincof_p0; + * y2 = _mm_mul_ps(y2, z); + * y2 = _mm_add_ps(y2, *(v4sf*)_ps_sincof_p1); + * y2 = _mm_mul_ps(y2, z); + * y2 = _mm_add_ps(y2, *(v4sf*)_ps_sincof_p2); + * y2 = _mm_mul_ps(y2, z); + * y2 = _mm_mul_ps(y2, x); + * y2 = _mm_add_ps(y2, x); + */ + + LLVMValueRef y2_3 = LLVMBuildFMul(b, z, sincof_p0, "y2_3"); + LLVMValueRef y2_4 = LLVMBuildFAdd(b, y2_3, sincof_p1, "y2_4"); + LLVMValueRef y2_5 = LLVMBuildFMul(b, y2_4, z, "y2_5"); + LLVMValueRef y2_6 = LLVMBuildFAdd(b, y2_5, sincof_p2, "y2_6"); + LLVMValueRef y2_7 = LLVMBuildFMul(b, y2_6, z, "y2_7"); + LLVMValueRef y2_8 = LLVMBuildFMul(b, y2_7, x_3, "y2_8"); + LLVMValueRef y2_9 = LLVMBuildFAdd(b, y2_8, x_3, "y2_9"); + + /* + * select the correct result from the two polynoms + * xmm3 = poly_mask; + * y2 = _mm_and_ps(xmm3, y2); //, xmm3); + * y = _mm_andnot_ps(xmm3, y); + * y = _mm_add_ps(y,y2); + */ + LLVMValueRef y2_i = LLVMBuildBitCast(b, y2_9, v4si, "y2_i"); + LLVMValueRef y_i = LLVMBuildBitCast(b, y_10, v4si, "y_i"); + LLVMValueRef y2_and = LLVMBuildAnd(b, y2_i, poly_mask, "y2_and"); + LLVMValueRef poly_mask_inv = LLVMBuildXor(b, poly_mask, inv, "poly_mask_inv"); + LLVMValueRef y_and = LLVMBuildAnd(b, y_i, poly_mask_inv, "y_and"); + LLVMValueRef y_combine = LLVMBuildAdd(b, y_and, y2_and, "y_combine"); + + /* + * update the sign + * y = _mm_xor_ps(y, sign_bit); + */ + LLVMValueRef y_sign = LLVMBuildXor(b, y_combine, sign_bit, "y_sin"); + LLVMValueRef y_result = LLVMBuildBitCast(b, y_sign, v4sf, "y_result"); + return y_result; +} + + +/** + * Generate pow(x, y) + */ +LLVMValueRef +lp_build_pow(struct lp_build_context *bld, + LLVMValueRef x, + LLVMValueRef y) +{ + /* TODO: optimize the constant case */ + if (gallivm_debug & GALLIVM_DEBUG_PERF && + LLVMIsConstant(x) && LLVMIsConstant(y)) { + debug_printf("%s: inefficient/imprecise constant arithmetic\n", + __FUNCTION__); + } + + return lp_build_exp2(bld, lp_build_mul(bld, lp_build_log2(bld, x), y)); +} + + +/** + * Generate exp(x) + */ +LLVMValueRef +lp_build_exp(struct lp_build_context *bld, + LLVMValueRef x) +{ + /* log2(e) = 1/log(2) */ + LLVMValueRef log2e = lp_build_const_vec(bld->gallivm, bld->type, + 1.4426950408889634); + + assert(lp_check_value(bld->type, x)); + + return lp_build_mul(bld, log2e, lp_build_exp2(bld, x)); +} + + +/** + * Generate log(x) + */ +LLVMValueRef +lp_build_log(struct lp_build_context *bld, + LLVMValueRef x) +{ + /* log(2) */ + LLVMValueRef log2 = lp_build_const_vec(bld->gallivm, bld->type, + 0.69314718055994529); + + assert(lp_check_value(bld->type, x)); + + return lp_build_mul(bld, log2, lp_build_exp2(bld, x)); +} + + +/** + * Generate polynomial. + * Ex: coeffs[0] + x * coeffs[1] + x^2 * coeffs[2]. + */ +static LLVMValueRef +lp_build_polynomial(struct lp_build_context *bld, + LLVMValueRef x, + const double *coeffs, + unsigned num_coeffs) +{ + const struct lp_type type = bld->type; + LLVMValueRef res = NULL; + unsigned i; + + assert(lp_check_value(bld->type, x)); + + /* TODO: optimize the constant case */ + if (gallivm_debug & GALLIVM_DEBUG_PERF && + LLVMIsConstant(x)) { + debug_printf("%s: inefficient/imprecise constant arithmetic\n", + __FUNCTION__); + } + + for (i = num_coeffs; i--; ) { + LLVMValueRef coeff; + + coeff = lp_build_const_vec(bld->gallivm, type, coeffs[i]); + + if(res) + res = lp_build_add(bld, coeff, lp_build_mul(bld, x, res)); + else + res = coeff; + } + + if(res) + return res; + else + return bld->undef; +} + + +/** + * Minimax polynomial fit of 2**x, in range [0, 1[ + */ +const double lp_build_exp2_polynomial[] = { +#if EXP_POLY_DEGREE == 5 + 0.999999999690134838155, + 0.583974334321735217258, + 0.164553105719676828492, + 0.0292811063701710962255, + 0.00354944426657875141846, + 0.000296253726543423377365 +#elif EXP_POLY_DEGREE == 4 + 1.00000001502262084505, + 0.563586057338685991394, + 0.150436017652442413623, + 0.0243220604213317927308, + 0.0025359088446580436489 +#elif EXP_POLY_DEGREE == 3 + 0.999925218562710312959, + 0.695833540494823811697, + 0.226067155427249155588, + 0.0780245226406372992967 +#elif EXP_POLY_DEGREE == 2 + 1.00172476321474503578, + 0.657636275736077639316, + 0.33718943461968720704 +#else +#error +#endif +}; + + +void +lp_build_exp2_approx(struct lp_build_context *bld, + LLVMValueRef x, + LLVMValueRef *p_exp2_int_part, + LLVMValueRef *p_frac_part, + LLVMValueRef *p_exp2) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type); + LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type); + LLVMValueRef ipart = NULL; + LLVMValueRef fpart = NULL; + LLVMValueRef expipart = NULL; + LLVMValueRef expfpart = NULL; + LLVMValueRef res = NULL; + + assert(lp_check_value(bld->type, x)); + + if(p_exp2_int_part || p_frac_part || p_exp2) { + /* TODO: optimize the constant case */ + if (gallivm_debug & GALLIVM_DEBUG_PERF && + LLVMIsConstant(x)) { + debug_printf("%s: inefficient/imprecise constant arithmetic\n", + __FUNCTION__); + } + + assert(type.floating && type.width == 32); + + x = lp_build_min(bld, x, lp_build_const_vec(bld->gallivm, type, 129.0)); + x = lp_build_max(bld, x, lp_build_const_vec(bld->gallivm, type, -126.99999)); + + /* ipart = floor(x) */ + ipart = lp_build_floor(bld, x); + + /* fpart = x - ipart */ + fpart = LLVMBuildFSub(builder, x, ipart, ""); + } + + if(p_exp2_int_part || p_exp2) { + /* expipart = (float) (1 << ipart) */ + ipart = LLVMBuildFPToSI(builder, ipart, int_vec_type, ""); + expipart = LLVMBuildAdd(builder, ipart, + lp_build_const_int_vec(bld->gallivm, type, 127), ""); + expipart = LLVMBuildShl(builder, expipart, + lp_build_const_int_vec(bld->gallivm, type, 23), ""); + expipart = LLVMBuildBitCast(builder, expipart, vec_type, ""); + } + + if(p_exp2) { + expfpart = lp_build_polynomial(bld, fpart, lp_build_exp2_polynomial, + Elements(lp_build_exp2_polynomial)); + + res = LLVMBuildFMul(builder, expipart, expfpart, ""); + } + + if(p_exp2_int_part) + *p_exp2_int_part = expipart; + + if(p_frac_part) + *p_frac_part = fpart; + + if(p_exp2) + *p_exp2 = res; +} + + +LLVMValueRef +lp_build_exp2(struct lp_build_context *bld, + LLVMValueRef x) +{ + LLVMValueRef res; + lp_build_exp2_approx(bld, x, NULL, NULL, &res); + return res; +} + + +/** + * Extract the exponent of a IEEE-754 floating point value. + * + * Optionally apply an integer bias. + * + * Result is an integer value with + * + * ifloor(log2(x)) + bias + */ +LLVMValueRef +lp_build_extract_exponent(struct lp_build_context *bld, + LLVMValueRef x, + int bias) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + unsigned mantissa = lp_mantissa(type); + LLVMValueRef res; + + assert(type.floating); + + assert(lp_check_value(bld->type, x)); + + x = LLVMBuildBitCast(builder, x, bld->int_vec_type, ""); + + res = LLVMBuildLShr(builder, x, + lp_build_const_int_vec(bld->gallivm, type, mantissa), ""); + res = LLVMBuildAnd(builder, res, + lp_build_const_int_vec(bld->gallivm, type, 255), ""); + res = LLVMBuildSub(builder, res, + lp_build_const_int_vec(bld->gallivm, type, 127 - bias), ""); + + return res; +} + + +/** + * Extract the mantissa of the a floating. + * + * Result is a floating point value with + * + * x / floor(log2(x)) + */ +LLVMValueRef +lp_build_extract_mantissa(struct lp_build_context *bld, + LLVMValueRef x) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + unsigned mantissa = lp_mantissa(type); + LLVMValueRef mantmask = lp_build_const_int_vec(bld->gallivm, type, + (1ULL << mantissa) - 1); + LLVMValueRef one = LLVMConstBitCast(bld->one, bld->int_vec_type); + LLVMValueRef res; + + assert(lp_check_value(bld->type, x)); + + assert(type.floating); + + x = LLVMBuildBitCast(builder, x, bld->int_vec_type, ""); + + /* res = x / 2**ipart */ + res = LLVMBuildAnd(builder, x, mantmask, ""); + res = LLVMBuildOr(builder, res, one, ""); + res = LLVMBuildBitCast(builder, res, bld->vec_type, ""); + + return res; +} + + + +/** + * Minimax polynomial fit of log2(x)/(x - 1), for x in range [1, 2[ + * These coefficients can be generate with + * http://www.boost.org/doc/libs/1_36_0/libs/math/doc/sf_and_dist/html/math_toolkit/toolkit/internals2/minimax.html + */ +const double lp_build_log2_polynomial[] = { +#if LOG_POLY_DEGREE == 6 + 3.11578814719469302614, + -3.32419399085241980044, + 2.59883907202499966007, + -1.23152682416275988241, + 0.318212422185251071475, + -0.0344359067839062357313 +#elif LOG_POLY_DEGREE == 5 + 2.8882704548164776201, + -2.52074962577807006663, + 1.48116647521213171641, + -0.465725644288844778798, + 0.0596515482674574969533 +#elif LOG_POLY_DEGREE == 4 + 2.61761038894603480148, + -1.75647175389045657003, + 0.688243882994381274313, + -0.107254423828329604454 +#elif LOG_POLY_DEGREE == 3 + 2.28330284476918490682, + -1.04913055217340124191, + 0.204446009836232697516 +#else +#error +#endif +}; + + +/** + * See http://www.devmaster.net/forums/showthread.php?p=43580 + */ +void +lp_build_log2_approx(struct lp_build_context *bld, + LLVMValueRef x, + LLVMValueRef *p_exp, + LLVMValueRef *p_floor_log2, + LLVMValueRef *p_log2) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type); + LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type); + + LLVMValueRef expmask = lp_build_const_int_vec(bld->gallivm, type, 0x7f800000); + LLVMValueRef mantmask = lp_build_const_int_vec(bld->gallivm, type, 0x007fffff); + LLVMValueRef one = LLVMConstBitCast(bld->one, int_vec_type); + + LLVMValueRef i = NULL; + LLVMValueRef exp = NULL; + LLVMValueRef mant = NULL; + LLVMValueRef logexp = NULL; + LLVMValueRef logmant = NULL; + LLVMValueRef res = NULL; + + assert(lp_check_value(bld->type, x)); + + if(p_exp || p_floor_log2 || p_log2) { + /* TODO: optimize the constant case */ + if (gallivm_debug & GALLIVM_DEBUG_PERF && + LLVMIsConstant(x)) { + debug_printf("%s: inefficient/imprecise constant arithmetic\n", + __FUNCTION__); + } + + assert(type.floating && type.width == 32); + + i = LLVMBuildBitCast(builder, x, int_vec_type, ""); + + /* exp = (float) exponent(x) */ + exp = LLVMBuildAnd(builder, i, expmask, ""); + } + + if(p_floor_log2 || p_log2) { + logexp = LLVMBuildLShr(builder, exp, lp_build_const_int_vec(bld->gallivm, type, 23), ""); + logexp = LLVMBuildSub(builder, logexp, lp_build_const_int_vec(bld->gallivm, type, 127), ""); + logexp = LLVMBuildSIToFP(builder, logexp, vec_type, ""); + } + + if(p_log2) { + /* mant = (float) mantissa(x) */ + mant = LLVMBuildAnd(builder, i, mantmask, ""); + mant = LLVMBuildOr(builder, mant, one, ""); + mant = LLVMBuildBitCast(builder, mant, vec_type, ""); + + logmant = lp_build_polynomial(bld, mant, lp_build_log2_polynomial, + Elements(lp_build_log2_polynomial)); + + /* This effectively increases the polynomial degree by one, but ensures that log2(1) == 0*/ + logmant = LLVMBuildFMul(builder, logmant, LLVMBuildFSub(builder, mant, bld->one, ""), ""); + + res = LLVMBuildFAdd(builder, logmant, logexp, ""); + } + + if(p_exp) { + exp = LLVMBuildBitCast(builder, exp, vec_type, ""); + *p_exp = exp; + } + + if(p_floor_log2) + *p_floor_log2 = logexp; + + if(p_log2) + *p_log2 = res; +} + + +LLVMValueRef +lp_build_log2(struct lp_build_context *bld, + LLVMValueRef x) +{ + LLVMValueRef res; + lp_build_log2_approx(bld, x, NULL, NULL, &res); + return res; +} + + +/** + * Faster (and less accurate) log2. + * + * log2(x) = floor(log2(x)) - 1 + x / 2**floor(log2(x)) + * + * Piece-wise linear approximation, with exact results when x is a + * power of two. + * + * See http://www.flipcode.com/archives/Fast_log_Function.shtml + */ +LLVMValueRef +lp_build_fast_log2(struct lp_build_context *bld, + LLVMValueRef x) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef ipart; + LLVMValueRef fpart; + + assert(lp_check_value(bld->type, x)); + + assert(bld->type.floating); + + /* ipart = floor(log2(x)) - 1 */ + ipart = lp_build_extract_exponent(bld, x, -1); + ipart = LLVMBuildSIToFP(builder, ipart, bld->vec_type, ""); + + /* fpart = x / 2**ipart */ + fpart = lp_build_extract_mantissa(bld, x); + + /* ipart + fpart */ + return LLVMBuildFAdd(builder, ipart, fpart, ""); +} + + +/** + * Fast implementation of iround(log2(x)). + * + * Not an approximation -- it should give accurate results all the time. + */ +LLVMValueRef +lp_build_ilog2(struct lp_build_context *bld, + LLVMValueRef x) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef sqrt2 = lp_build_const_vec(bld->gallivm, bld->type, M_SQRT2); + LLVMValueRef ipart; + + assert(bld->type.floating); + + assert(lp_check_value(bld->type, x)); + + /* x * 2^(0.5) i.e., add 0.5 to the log2(x) */ + x = LLVMBuildFMul(builder, x, sqrt2, ""); + + /* ipart = floor(log2(x) + 0.5) */ + ipart = lp_build_extract_exponent(bld, x, 0); + + return ipart; +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.h b/src/gallium/auxiliary/gallivm/lp_bld_arit.h new file mode 100644 index 0000000..c78b61d --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.h @@ -0,0 +1,252 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Helper arithmetic functions. + * + * @author Jose Fonseca + */ + + +#ifndef LP_BLD_ARIT_H +#define LP_BLD_ARIT_H + + +#include "gallivm/lp_bld.h" + + +struct lp_type; +struct lp_build_context; + + +/** + * Complement, i.e., 1 - a. + */ +LLVMValueRef +lp_build_comp(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_add(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b); + +LLVMValueRef +lp_build_sum_vector(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_sub(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b); + +LLVMValueRef +lp_build_mul(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b); + +LLVMValueRef +lp_build_mul_imm(struct lp_build_context *bld, + LLVMValueRef a, + int b); + +LLVMValueRef +lp_build_div(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b); + +LLVMValueRef +lp_build_lerp(struct lp_build_context *bld, + LLVMValueRef x, + LLVMValueRef v0, + LLVMValueRef v1); + +/** + * Bilinear interpolation. + * + * Values indices are in v_{yx}. + */ +LLVMValueRef +lp_build_lerp_2d(struct lp_build_context *bld, + LLVMValueRef x, + LLVMValueRef y, + LLVMValueRef v00, + LLVMValueRef v01, + LLVMValueRef v10, + LLVMValueRef v11); + +LLVMValueRef +lp_build_min(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b); + +LLVMValueRef +lp_build_max(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b); + +LLVMValueRef +lp_build_clamp(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef min, + LLVMValueRef max); + +LLVMValueRef +lp_build_abs(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_negate(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_sgn(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_set_sign(struct lp_build_context *bld, + LLVMValueRef a, LLVMValueRef sign); + +LLVMValueRef +lp_build_int_to_float(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_round(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_floor(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_ceil(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_trunc(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_fract(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_ifloor(struct lp_build_context *bld, + LLVMValueRef a); +LLVMValueRef +lp_build_iceil(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_iround(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_itrunc(struct lp_build_context *bld, + LLVMValueRef a); + +void +lp_build_ifloor_fract(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef *out_ipart, + LLVMValueRef *out_fpart); + +LLVMValueRef +lp_build_sqrt(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_rcp(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_rsqrt(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_cos(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_sin(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_pow(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef b); + +LLVMValueRef +lp_build_exp(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_log(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_exp2(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_extract_exponent(struct lp_build_context *bld, + LLVMValueRef x, + int bias); + +LLVMValueRef +lp_build_extract_mantissa(struct lp_build_context *bld, + LLVMValueRef x); + +LLVMValueRef +lp_build_log2(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_fast_log2(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef +lp_build_ilog2(struct lp_build_context *bld, + LLVMValueRef x); + +void +lp_build_exp2_approx(struct lp_build_context *bld, + LLVMValueRef x, + LLVMValueRef *p_exp2_int_part, + LLVMValueRef *p_frac_part, + LLVMValueRef *p_exp2); + +void +lp_build_log2_approx(struct lp_build_context *bld, + LLVMValueRef x, + LLVMValueRef *p_exp, + LLVMValueRef *p_floor_log2, + LLVMValueRef *p_log2); + +#endif /* !LP_BLD_ARIT_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_assert.c b/src/gallium/auxiliary/gallivm/lp_bld_assert.c new file mode 100644 index 0000000..9de5e8e --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_assert.c @@ -0,0 +1,102 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "lp_bld_assert.h" +#include "lp_bld_init.h" +#include "lp_bld_printf.h" + + +/** + * A call to lp_build_assert() will build a function call to this function. + */ +static void +lp_assert(int condition, const char *msg) +{ + if (!condition) { + debug_printf("LLVM assertion '%s' failed!\n", msg); + assert(condition); + } +} + + + +/** + * lp_build_assert. + * + * Build an assertion in LLVM IR by building a function call to the + * lp_assert() function above. + * + * \param condition should be an 'i1' or 'i32' value + * \param msg a string to print if the assertion fails. + */ +LLVMValueRef +lp_build_assert(struct gallivm_state *gallivm, + LLVMValueRef condition, + const char *msg) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMContextRef context = gallivm->context; + LLVMModuleRef module = gallivm->module; + LLVMTypeRef arg_types[2]; + LLVMValueRef msg_string, assert_func, params[2], r; + + msg_string = lp_build_const_string_variable(module, context, + msg, strlen(msg) + 1); + + arg_types[0] = LLVMInt32TypeInContext(context); + arg_types[1] = LLVMPointerType(LLVMInt8TypeInContext(context), 0); + + /* lookup the lp_assert function */ + assert_func = LLVMGetNamedFunction(module, "lp_assert"); + + /* Create the assertion function if not found */ + if (!assert_func) { + LLVMTypeRef func_type = + LLVMFunctionType(LLVMVoidTypeInContext(context), arg_types, 2, 0); + + assert_func = LLVMAddFunction(module, "lp_assert", func_type); + LLVMSetFunctionCallConv(assert_func, LLVMCCallConv); + LLVMSetLinkage(assert_func, LLVMExternalLinkage); + LLVMAddGlobalMapping(gallivm->engine, assert_func, + func_to_pointer((func_pointer)lp_assert)); + } + assert(assert_func); + + /* build function call param list */ + params[0] = LLVMBuildZExt(builder, condition, arg_types[0], ""); + params[1] = LLVMBuildBitCast(builder, msg_string, arg_types[1], ""); + + /* check arg types */ + assert(LLVMTypeOf(params[0]) == arg_types[0]); + assert(LLVMTypeOf(params[1]) == arg_types[1]); + + r = LLVMBuildCall(builder, assert_func, params, 2, ""); + + return r; +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_assert.h b/src/gallium/auxiliary/gallivm/lp_bld_assert.h new file mode 100644 index 0000000..1d2baab --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_assert.h @@ -0,0 +1,43 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef LP_BLD_ASSERT_H +#define LP_BLD_ASSERT_H + + +#include "lp_bld.h" +#include "lp_bld_init.h" + + +LLVMValueRef +lp_build_assert(struct gallivm_state *gallivm, + LLVMValueRef condition, + const char *msg); + + +#endif + diff --git a/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c b/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c new file mode 100644 index 0000000..a9c57d6 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c @@ -0,0 +1,192 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "util/u_debug.h" + +#include "lp_bld_type.h" +#include "lp_bld_debug.h" +#include "lp_bld_const.h" +#include "lp_bld_bitarit.h" + + +/** + * Return (a | b) + */ +LLVMValueRef +lp_build_or(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMValueRef res; + + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + /* can't do bitwise ops on floating-point values */ + if (type.floating) { + a = LLVMBuildBitCast(builder, a, bld->int_vec_type, ""); + b = LLVMBuildBitCast(builder, b, bld->int_vec_type, ""); + } + + res = LLVMBuildOr(builder, a, b, ""); + + if (type.floating) { + res = LLVMBuildBitCast(builder, res, bld->vec_type, ""); + } + + return res; +} + + +/** + * Return (a & b) + */ +LLVMValueRef +lp_build_and(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMValueRef res; + + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + /* can't do bitwise ops on floating-point values */ + if (type.floating) { + a = LLVMBuildBitCast(builder, a, bld->int_vec_type, ""); + b = LLVMBuildBitCast(builder, b, bld->int_vec_type, ""); + } + + res = LLVMBuildAnd(builder, a, b, ""); + + if (type.floating) { + res = LLVMBuildBitCast(builder, res, bld->vec_type, ""); + } + + return res; +} + + +/** + * Return (a & ~b) + */ +LLVMValueRef +lp_build_andnot(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMValueRef res; + + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + /* can't do bitwise ops on floating-point values */ + if (type.floating) { + a = LLVMBuildBitCast(builder, a, bld->int_vec_type, ""); + b = LLVMBuildBitCast(builder, b, bld->int_vec_type, ""); + } + + res = LLVMBuildNot(builder, b, ""); + res = LLVMBuildAnd(builder, a, res, ""); + + if (type.floating) { + res = LLVMBuildBitCast(builder, res, bld->vec_type, ""); + } + + return res; +} + + +/** + * Shift left. + */ +LLVMValueRef +lp_build_shl(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMValueRef res; + + assert(!type.floating); + + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + res = LLVMBuildShl(builder, a, b, ""); + + return res; +} + + +/** + * Shift right. + */ +LLVMValueRef +lp_build_shr(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + LLVMValueRef res; + + assert(!type.floating); + + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + if (type.sign) { + res = LLVMBuildAShr(builder, a, b, ""); + } else { + res = LLVMBuildLShr(builder, a, b, ""); + } + + return res; +} + + +/** + * Shift left with immediate. + */ +LLVMValueRef +lp_build_shl_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm) +{ + LLVMValueRef b = lp_build_const_int_vec(bld->gallivm, bld->type, imm); + assert(imm <= bld->type.width); + return lp_build_shl(bld, a, b); +} + + +/** + * Shift right with immediate. + */ +LLVMValueRef +lp_build_shr_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm) +{ + LLVMValueRef b = lp_build_const_int_vec(bld->gallivm, bld->type, imm); + assert(imm <= bld->type.width); + return lp_build_shr(bld, a, b); +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_bitarit.h b/src/gallium/auxiliary/gallivm/lp_bld_bitarit.h new file mode 100644 index 0000000..5c5b981 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_bitarit.h @@ -0,0 +1,69 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Helper bitwise arithmetic functions. + * + * @author Jose Fonseca + */ + + +#ifndef LP_BLD_BITARIT_H +#define LP_BLD_BITARIT_H + + +#include "gallivm/lp_bld.h" + + +struct lp_type; +struct lp_build_context; + + +LLVMValueRef +lp_build_or(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b); + +LLVMValueRef +lp_build_and(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b); + +LLVMValueRef +lp_build_andnot(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b); + +LLVMValueRef +lp_build_shl(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b); + +LLVMValueRef +lp_build_shr(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b); + +LLVMValueRef +lp_build_shl_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm); + +LLVMValueRef +lp_build_shr_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm); + + +#endif /* !LP_BLD_ARIT_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.c b/src/gallium/auxiliary/gallivm/lp_bld_const.c new file mode 100644 index 0000000..6d8b7c2 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_const.c @@ -0,0 +1,411 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * @file + * Helper functions for constant building. + * + * @author Jose Fonseca + */ + +#include + +#include "util/u_debug.h" + +#include "lp_bld_type.h" +#include "lp_bld_const.h" +#include "lp_bld_init.h" + + +unsigned +lp_mantissa(struct lp_type type) +{ + assert(type.floating); + + if(type.floating) { + switch(type.width) { + case 32: + return 23; + case 64: + return 53; + default: + assert(0); + return 0; + } + } + else { + if(type.sign) + return type.width - 1; + else + return type.width; + } +} + + +/** + * Shift of the unity. + * + * Same as lp_const_scale(), but in terms of shifts. + */ +unsigned +lp_const_shift(struct lp_type type) +{ + if(type.floating) + return 0; + else if(type.fixed) + return type.width/2; + else if(type.norm) + return type.sign ? type.width - 1 : type.width; + else + return 0; +} + + +unsigned +lp_const_offset(struct lp_type type) +{ + if(type.floating || type.fixed) + return 0; + else if(type.norm) + return 1; + else + return 0; +} + + +/** + * Scaling factor between the LLVM native value and its interpretation. + * + * This is 1.0 for all floating types and unnormalized integers, and something + * else for the fixed points types and normalized integers. + */ +double +lp_const_scale(struct lp_type type) +{ + unsigned long long llscale; + double dscale; + + llscale = (unsigned long long)1 << lp_const_shift(type); + llscale -= lp_const_offset(type); + dscale = (double)llscale; + assert((unsigned long long)dscale == llscale); + + return dscale; +} + + +/** + * Minimum value representable by the type. + */ +double +lp_const_min(struct lp_type type) +{ + unsigned bits; + + if(!type.sign) + return 0.0; + + if(type.norm) + return -1.0; + + if (type.floating) { + switch(type.width) { + case 32: + return -FLT_MAX; + case 64: + return -DBL_MAX; + default: + assert(0); + return 0.0; + } + } + + if(type.fixed) + /* FIXME: consider the fractional bits? */ + bits = type.width / 2 - 1; + else + bits = type.width - 1; + + return (double)-((long long)1 << bits); +} + + +/** + * Maximum value representable by the type. + */ +double +lp_const_max(struct lp_type type) +{ + unsigned bits; + + if(type.norm) + return 1.0; + + if (type.floating) { + switch(type.width) { + case 32: + return FLT_MAX; + case 64: + return DBL_MAX; + default: + assert(0); + return 0.0; + } + } + + if(type.fixed) + bits = type.width / 2; + else + bits = type.width; + + if(type.sign) + bits -= 1; + + return (double)(((unsigned long long)1 << bits) - 1); +} + + +double +lp_const_eps(struct lp_type type) +{ + if (type.floating) { + switch(type.width) { + case 32: + return FLT_EPSILON; + case 64: + return DBL_EPSILON; + default: + assert(0); + return 0.0; + } + } + else { + double scale = lp_const_scale(type); + return 1.0/scale; + } +} + + +LLVMValueRef +lp_build_undef(struct gallivm_state *gallivm, struct lp_type type) +{ + LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type); + return LLVMGetUndef(vec_type); +} + + +LLVMValueRef +lp_build_zero(struct gallivm_state *gallivm, struct lp_type type) +{ + if (type.length == 1) { + if (type.floating) + return lp_build_const_float(gallivm, 0.0); + else + return LLVMConstInt(LLVMIntTypeInContext(gallivm->context, type.width), 0, 0); + } + else { + LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type); + return LLVMConstNull(vec_type); + } +} + + +LLVMValueRef +lp_build_one(struct gallivm_state *gallivm, struct lp_type type) +{ + LLVMTypeRef elem_type; + LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; + unsigned i; + + assert(type.length <= LP_MAX_VECTOR_LENGTH); + + elem_type = lp_build_elem_type(gallivm, type); + + if(type.floating) + elems[0] = LLVMConstReal(elem_type, 1.0); + else if(type.fixed) + elems[0] = LLVMConstInt(elem_type, 1LL << (type.width/2), 0); + else if(!type.norm) + elems[0] = LLVMConstInt(elem_type, 1, 0); + else if(type.sign) + elems[0] = LLVMConstInt(elem_type, (1LL << (type.width - 1)) - 1, 0); + else { + /* special case' -- 1.0 for normalized types is more easily attained if + * we start with a vector consisting of all bits set */ + LLVMTypeRef vec_type = LLVMVectorType(elem_type, type.length); + LLVMValueRef vec = LLVMConstAllOnes(vec_type); + +#if 0 + if(type.sign) + /* TODO: Unfortunately this caused "Tried to create a shift operation + * on a non-integer type!" */ + vec = LLVMConstLShr(vec, lp_build_const_int_vec(type, 1)); +#endif + + return vec; + } + + for(i = 1; i < type.length; ++i) + elems[i] = elems[0]; + + if (type.length == 1) + return elems[0]; + else + return LLVMConstVector(elems, type.length); +} + + +/** + * Build constant-valued element from a scalar value. + */ +LLVMValueRef +lp_build_const_elem(struct gallivm_state *gallivm, + struct lp_type type, + double val) +{ + LLVMTypeRef elem_type = lp_build_elem_type(gallivm, type); + LLVMValueRef elem; + + if(type.floating) { + elem = LLVMConstReal(elem_type, val); + } + else { + double dscale = lp_const_scale(type); + + elem = LLVMConstInt(elem_type, val*dscale + 0.5, 0); + } + + return elem; +} + + +/** + * Build constant-valued vector from a scalar value. + */ +LLVMValueRef +lp_build_const_vec(struct gallivm_state *gallivm, struct lp_type type, + double val) +{ + if (type.length == 1) { + return lp_build_const_elem(gallivm, type, val); + } else { + LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; + unsigned i; + elems[0] = lp_build_const_elem(gallivm, type, val); + for(i = 1; i < type.length; ++i) + elems[i] = elems[0]; + return LLVMConstVector(elems, type.length); + } +} + + +LLVMValueRef +lp_build_const_int_vec(struct gallivm_state *gallivm, struct lp_type type, + long long val) +{ + LLVMTypeRef elem_type = lp_build_int_elem_type(gallivm, type); + LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; + unsigned i; + + assert(type.length <= LP_MAX_VECTOR_LENGTH); + + for(i = 0; i < type.length; ++i) + elems[i] = LLVMConstInt(elem_type, val, type.sign ? 1 : 0); + + if (type.length == 1) + return elems[0]; + + return LLVMConstVector(elems, type.length); +} + + +LLVMValueRef +lp_build_const_aos(struct gallivm_state *gallivm, + struct lp_type type, + double r, double g, double b, double a, + const unsigned char *swizzle) +{ + const unsigned char default_swizzle[4] = {0, 1, 2, 3}; + LLVMTypeRef elem_type; + LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; + unsigned i; + + assert(type.length % 4 == 0); + assert(type.length <= LP_MAX_VECTOR_LENGTH); + + elem_type = lp_build_elem_type(gallivm, type); + + if(swizzle == NULL) + swizzle = default_swizzle; + + if(type.floating) { + elems[swizzle[0]] = LLVMConstReal(elem_type, r); + elems[swizzle[1]] = LLVMConstReal(elem_type, g); + elems[swizzle[2]] = LLVMConstReal(elem_type, b); + elems[swizzle[3]] = LLVMConstReal(elem_type, a); + } + else { + double dscale = lp_const_scale(type); + + elems[swizzle[0]] = LLVMConstInt(elem_type, r*dscale + 0.5, 0); + elems[swizzle[1]] = LLVMConstInt(elem_type, g*dscale + 0.5, 0); + elems[swizzle[2]] = LLVMConstInt(elem_type, b*dscale + 0.5, 0); + elems[swizzle[3]] = LLVMConstInt(elem_type, a*dscale + 0.5, 0); + } + + for(i = 4; i < type.length; ++i) + elems[i] = elems[i % 4]; + + return LLVMConstVector(elems, type.length); +} + + +/** + * @param mask TGSI_WRITEMASK_xxx + */ +LLVMValueRef +lp_build_const_mask_aos(struct gallivm_state *gallivm, + struct lp_type type, + unsigned mask) +{ + LLVMTypeRef elem_type = LLVMIntTypeInContext(gallivm->context, type.width); + LLVMValueRef masks[LP_MAX_VECTOR_LENGTH]; + unsigned i, j; + + assert(type.length <= LP_MAX_VECTOR_LENGTH); + + for (j = 0; j < type.length; j += 4) { + for( i = 0; i < 4; ++i) { + masks[j + i] = LLVMConstInt(elem_type, + mask & (1 << i) ? ~0ULL : 0, + 1); + } + } + + return LLVMConstVector(masks, type.length); +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.h b/src/gallium/auxiliary/gallivm/lp_bld_const.h new file mode 100644 index 0000000..680211f --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_const.h @@ -0,0 +1,146 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Helper functions for constant building. + * + * @author Jose Fonseca + */ + + +#ifndef LP_BLD_CONST_H +#define LP_BLD_CONST_H + + +#include "pipe/p_compiler.h" +#include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_init.h" + + + +struct lp_type; + + +unsigned +lp_mantissa(struct lp_type type); + + +unsigned +lp_const_shift(struct lp_type type); + + +unsigned +lp_const_offset(struct lp_type type); + + +double +lp_const_scale(struct lp_type type); + +double +lp_const_min(struct lp_type type); + + +double +lp_const_max(struct lp_type type); + + +double +lp_const_eps(struct lp_type type); + + +LLVMValueRef +lp_build_undef(struct gallivm_state *gallivm, struct lp_type type); + + +LLVMValueRef +lp_build_zero(struct gallivm_state *gallivm, struct lp_type type); + + +LLVMValueRef +lp_build_one(struct gallivm_state *gallivm, struct lp_type type); + + +LLVMValueRef +lp_build_const_elem(struct gallivm_state *gallivm, struct lp_type type, + double val); + +LLVMValueRef +lp_build_const_vec(struct gallivm_state *gallivm, struct lp_type type, + double val); + + +LLVMValueRef +lp_build_const_int_vec(struct gallivm_state *gallivm, + struct lp_type type, long long val); + + +LLVMValueRef +lp_build_const_aos(struct gallivm_state *gallivm, struct lp_type type, + double r, double g, double b, double a, + const unsigned char *swizzle); + + +LLVMValueRef +lp_build_const_mask_aos(struct gallivm_state *gallivm, + struct lp_type type, + unsigned mask); + + +static INLINE LLVMValueRef +lp_build_const_int32(struct gallivm_state *gallivm, int i) +{ + return LLVMConstInt(LLVMInt32TypeInContext(gallivm->context), i, 0); +} + + +static INLINE LLVMValueRef +lp_build_const_float(struct gallivm_state *gallivm, float x) +{ + return LLVMConstReal(LLVMFloatTypeInContext(gallivm->context), x); +} + + +/** Return constant-valued pointer to int */ +static INLINE LLVMValueRef +lp_build_const_int_pointer(struct gallivm_state *gallivm, const void *ptr) +{ + LLVMTypeRef int_type; + LLVMValueRef v; + + /* int type large enough to hold a pointer */ + int_type = LLVMIntTypeInContext(gallivm->context, 8 * sizeof(void *)); + v = LLVMConstInt(int_type, (unsigned long long) ptr, 0); + v = LLVMBuildIntToPtr(gallivm->builder, v, + LLVMPointerType(int_type, 0), + "cast int to ptr"); + return v; +} + + + +#endif /* !LP_BLD_CONST_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_conv.c b/src/gallium/auxiliary/gallivm/lp_bld_conv.c new file mode 100644 index 0000000..c43ee8a --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_conv.c @@ -0,0 +1,623 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * @file + * Helper functions for type conversions. + * + * We want to use the fastest type for a given computation whenever feasible. + * The other side of this is that we need to be able convert between several + * types accurately and efficiently. + * + * Conversion between types of different bit width is quite complex since a + * + * To remember there are a few invariants in type conversions: + * + * - register width must remain constant: + * + * src_type.width * src_type.length == dst_type.width * dst_type.length + * + * - total number of elements must remain constant: + * + * src_type.length * num_srcs == dst_type.length * num_dsts + * + * It is not always possible to do the conversion both accurately and + * efficiently, usually due to lack of adequate machine instructions. In these + * cases it is important not to cut shortcuts here and sacrifice accuracy, as + * there this functions can be used anywhere. In the future we might have a + * precision parameter which can gauge the accuracy vs efficiency compromise, + * but for now if the data conversion between two stages happens to be the + * bottleneck, then most likely should just avoid converting at all and run + * both stages with the same type. + * + * Make sure to run lp_test_conv unit test after any change to this file. + * + * @author Jose Fonseca + */ + + +#include "util/u_debug.h" +#include "util/u_math.h" +#include "util/u_cpu_detect.h" + +#include "lp_bld_type.h" +#include "lp_bld_const.h" +#include "lp_bld_arit.h" +#include "lp_bld_pack.h" +#include "lp_bld_conv.h" + + +/** + * Special case for converting clamped IEEE-754 floats to unsigned norms. + * + * The mathematical voodoo below may seem excessive but it is actually + * paramount we do it this way for several reasons. First, there is no single + * precision FP to unsigned integer conversion Intel SSE instruction. Second, + * secondly, even if there was, since the FP's mantissa takes only a fraction + * of register bits the typically scale and cast approach would require double + * precision for accurate results, and therefore half the throughput + * + * Although the result values can be scaled to an arbitrary bit width specified + * by dst_width, the actual result type will have the same width. + * + * Ex: src = { float, float, float, float } + * return { i32, i32, i32, i32 } where each value is in [0, 2^dst_width-1]. + */ +LLVMValueRef +lp_build_clamped_float_to_unsigned_norm(struct gallivm_state *gallivm, + struct lp_type src_type, + unsigned dst_width, + LLVMValueRef src) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMTypeRef int_vec_type = lp_build_int_vec_type(gallivm, src_type); + LLVMValueRef res; + unsigned mantissa; + + assert(src_type.floating); + assert(dst_width <= src_type.width); + src_type.sign = FALSE; + + mantissa = lp_mantissa(src_type); + + if (dst_width <= mantissa) { + /* + * Apply magic coefficients that will make the desired result to appear + * in the lowest significant bits of the mantissa, with correct rounding. + * + * This only works if the destination width fits in the mantissa. + */ + + unsigned long long ubound; + unsigned long long mask; + double scale; + double bias; + + ubound = (1ULL << dst_width); + mask = ubound - 1; + scale = (double)mask/ubound; + bias = (double)(1ULL << (mantissa - dst_width)); + + res = LLVMBuildFMul(builder, src, lp_build_const_vec(gallivm, src_type, scale), ""); + res = LLVMBuildFAdd(builder, res, lp_build_const_vec(gallivm, src_type, bias), ""); + res = LLVMBuildBitCast(builder, res, int_vec_type, ""); + res = LLVMBuildAnd(builder, res, + lp_build_const_int_vec(gallivm, src_type, mask), ""); + } + else if (dst_width == (mantissa + 1)) { + /* + * The destination width matches exactly what can be represented in + * floating point (i.e., mantissa + 1 bits). So do a straight + * multiplication followed by casting. No further rounding is necessary. + */ + + double scale; + + scale = (double)((1ULL << dst_width) - 1); + + res = LLVMBuildFMul(builder, src, + lp_build_const_vec(gallivm, src_type, scale), ""); + res = LLVMBuildFPToSI(builder, res, int_vec_type, ""); + } + else { + /* + * The destination exceeds what can be represented in the floating point. + * So multiply by the largest power two we get away with, and when + * subtract the most significant bit to rescale to normalized values. + * + * The largest power of two factor we can get away is + * (1 << (src_type.width - 1)), because we need to use signed . In theory it + * should be (1 << (src_type.width - 2)), but IEEE 754 rules states + * INT_MIN should be returned in FPToSI, which is the correct result for + * values near 1.0! + * + * This means we get (src_type.width - 1) correct bits for values near 0.0, + * and (mantissa + 1) correct bits for values near 1.0. Equally or more + * important, we also get exact results for 0.0 and 1.0. + */ + + unsigned n = MIN2(src_type.width - 1, dst_width); + + double scale = (double)(1ULL << n); + unsigned lshift = dst_width - n; + unsigned rshift = n; + LLVMValueRef lshifted; + LLVMValueRef rshifted; + + res = LLVMBuildFMul(builder, src, + lp_build_const_vec(gallivm, src_type, scale), ""); + res = LLVMBuildFPToSI(builder, res, int_vec_type, ""); + + /* + * Align the most significant bit to its final place. + * + * This will cause 1.0 to overflow to 0, but the later adjustment will + * get it right. + */ + if (lshift) { + lshifted = LLVMBuildShl(builder, res, + lp_build_const_int_vec(gallivm, src_type, + lshift), ""); + } else { + lshifted = res; + } + + /* + * Align the most significant bit to the right. + */ + rshifted = LLVMBuildAShr(builder, res, + lp_build_const_int_vec(gallivm, src_type, rshift), + ""); + + /* + * Subtract the MSB to the LSB, therefore re-scaling from + * (1 << dst_width) to ((1 << dst_width) - 1). + */ + + res = LLVMBuildSub(builder, lshifted, rshifted, ""); + } + + return res; +} + + +/** + * Inverse of lp_build_clamped_float_to_unsigned_norm above. + * Ex: src = { i32, i32, i32, i32 } with values in range [0, 2^src_width-1] + * return {float, float, float, float} with values in range [0, 1]. + */ +LLVMValueRef +lp_build_unsigned_norm_to_float(struct gallivm_state *gallivm, + unsigned src_width, + struct lp_type dst_type, + LLVMValueRef src) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMTypeRef vec_type = lp_build_vec_type(gallivm, dst_type); + LLVMTypeRef int_vec_type = lp_build_int_vec_type(gallivm, dst_type); + LLVMValueRef bias_; + LLVMValueRef res; + unsigned mantissa; + unsigned n; + unsigned long long ubound; + unsigned long long mask; + double scale; + double bias; + + assert(dst_type.floating); + + /* Special-case int8->float, though most cases could be handled + * this way: + */ + if (src_width == 8) { + scale = 1.0/255.0; + res = LLVMBuildSIToFP(builder, src, vec_type, ""); + res = LLVMBuildFMul(builder, res, + lp_build_const_vec(gallivm, dst_type, scale), ""); + return res; + } + + mantissa = lp_mantissa(dst_type); + + n = MIN2(mantissa, src_width); + + ubound = ((unsigned long long)1 << n); + mask = ubound - 1; + scale = (double)ubound/mask; + bias = (double)((unsigned long long)1 << (mantissa - n)); + + res = src; + + if(src_width > mantissa) { + int shift = src_width - mantissa; + res = LLVMBuildLShr(builder, res, + lp_build_const_int_vec(gallivm, dst_type, shift), ""); + } + + bias_ = lp_build_const_vec(gallivm, dst_type, bias); + + res = LLVMBuildOr(builder, + res, + LLVMBuildBitCast(builder, bias_, int_vec_type, ""), ""); + + res = LLVMBuildBitCast(builder, res, vec_type, ""); + + res = LLVMBuildFSub(builder, res, bias_, ""); + res = LLVMBuildFMul(builder, res, lp_build_const_vec(gallivm, dst_type, scale), ""); + + return res; +} + + +/** + * Generic type conversion. + * + * TODO: Take a precision argument, or even better, add a new precision member + * to the lp_type union. + */ +void +lp_build_conv(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + const LLVMValueRef *src, unsigned num_srcs, + LLVMValueRef *dst, unsigned num_dsts) +{ + LLVMBuilderRef builder = gallivm->builder; + struct lp_type tmp_type; + LLVMValueRef tmp[LP_MAX_VECTOR_LENGTH]; + unsigned num_tmps; + unsigned i; + + /* We must not loose or gain channels. Only precision */ + assert(src_type.length * num_srcs == dst_type.length * num_dsts); + + assert(src_type.length <= LP_MAX_VECTOR_LENGTH); + assert(dst_type.length <= LP_MAX_VECTOR_LENGTH); + assert(num_srcs <= LP_MAX_VECTOR_LENGTH); + assert(num_dsts <= LP_MAX_VECTOR_LENGTH); + + tmp_type = src_type; + for(i = 0; i < num_srcs; ++i) { + assert(lp_check_value(src_type, src[i])); + tmp[i] = src[i]; + } + num_tmps = num_srcs; + + + /* Special case 4x4f --> 1x16ub + */ + if (src_type.floating == 1 && + src_type.fixed == 0 && + src_type.sign == 1 && + src_type.norm == 0 && + src_type.width == 32 && + src_type.length == 4 && + + dst_type.floating == 0 && + dst_type.fixed == 0 && + dst_type.sign == 0 && + dst_type.norm == 1 && + dst_type.width == 8 && + dst_type.length == 16 && + + util_cpu_caps.has_sse2) + { + int i; + + for (i = 0; i < num_dsts; i++, src += 4) { + struct lp_type int16_type = dst_type; + struct lp_type int32_type = dst_type; + LLVMValueRef lo, hi; + LLVMValueRef src_int0; + LLVMValueRef src_int1; + LLVMValueRef src_int2; + LLVMValueRef src_int3; + LLVMTypeRef int16_vec_type; + LLVMTypeRef int32_vec_type; + LLVMTypeRef src_vec_type; + LLVMTypeRef dst_vec_type; + LLVMValueRef const_255f; + LLVMValueRef a, b, c, d; + + int16_type.width *= 2; + int16_type.length /= 2; + int16_type.sign = 1; + + int32_type.width *= 4; + int32_type.length /= 4; + int32_type.sign = 1; + + src_vec_type = lp_build_vec_type(gallivm, src_type); + dst_vec_type = lp_build_vec_type(gallivm, dst_type); + int16_vec_type = lp_build_vec_type(gallivm, int16_type); + int32_vec_type = lp_build_vec_type(gallivm, int32_type); + + const_255f = lp_build_const_vec(gallivm, src_type, 255.0f); + + a = LLVMBuildFMul(builder, src[0], const_255f, ""); + b = LLVMBuildFMul(builder, src[1], const_255f, ""); + c = LLVMBuildFMul(builder, src[2], const_255f, ""); + d = LLVMBuildFMul(builder, src[3], const_255f, ""); + + { + struct lp_build_context bld; + + bld.gallivm = gallivm; + bld.type = src_type; + bld.vec_type = src_vec_type; + bld.int_elem_type = lp_build_elem_type(gallivm, int32_type); + bld.int_vec_type = int32_vec_type; + bld.undef = lp_build_undef(gallivm, src_type); + bld.zero = lp_build_zero(gallivm, src_type); + bld.one = lp_build_one(gallivm, src_type); + + src_int0 = lp_build_iround(&bld, a); + src_int1 = lp_build_iround(&bld, b); + src_int2 = lp_build_iround(&bld, c); + src_int3 = lp_build_iround(&bld, d); + } + /* relying on clamping behavior of sse2 intrinsics here */ + lo = lp_build_pack2(gallivm, int32_type, int16_type, src_int0, src_int1); + hi = lp_build_pack2(gallivm, int32_type, int16_type, src_int2, src_int3); + dst[i] = lp_build_pack2(gallivm, int16_type, dst_type, lo, hi); + } + return; + } + + /* + * Clamp if necessary + */ + + if(memcmp(&src_type, &dst_type, sizeof src_type) != 0) { + struct lp_build_context bld; + double src_min = lp_const_min(src_type); + double dst_min = lp_const_min(dst_type); + double src_max = lp_const_max(src_type); + double dst_max = lp_const_max(dst_type); + LLVMValueRef thres; + + lp_build_context_init(&bld, gallivm, tmp_type); + + if(src_min < dst_min) { + if(dst_min == 0.0) + thres = bld.zero; + else + thres = lp_build_const_vec(gallivm, src_type, dst_min); + for(i = 0; i < num_tmps; ++i) + tmp[i] = lp_build_max(&bld, tmp[i], thres); + } + + if(src_max > dst_max) { + if(dst_max == 1.0) + thres = bld.one; + else + thres = lp_build_const_vec(gallivm, src_type, dst_max); + for(i = 0; i < num_tmps; ++i) + tmp[i] = lp_build_min(&bld, tmp[i], thres); + } + } + + /* + * Scale to the narrowest range + */ + + if(dst_type.floating) { + /* Nothing to do */ + } + else if(tmp_type.floating) { + if(!dst_type.fixed && !dst_type.sign && dst_type.norm) { + for(i = 0; i < num_tmps; ++i) { + tmp[i] = lp_build_clamped_float_to_unsigned_norm(gallivm, + tmp_type, + dst_type.width, + tmp[i]); + } + tmp_type.floating = FALSE; + } + else { + double dst_scale = lp_const_scale(dst_type); + LLVMTypeRef tmp_vec_type; + + if (dst_scale != 1.0) { + LLVMValueRef scale = lp_build_const_vec(gallivm, tmp_type, dst_scale); + for(i = 0; i < num_tmps; ++i) + tmp[i] = LLVMBuildFMul(builder, tmp[i], scale, ""); + } + + /* Use an equally sized integer for intermediate computations */ + tmp_type.floating = FALSE; + tmp_vec_type = lp_build_vec_type(gallivm, tmp_type); + for(i = 0; i < num_tmps; ++i) { +#if 0 + if(dst_type.sign) + tmp[i] = LLVMBuildFPToSI(builder, tmp[i], tmp_vec_type, ""); + else + tmp[i] = LLVMBuildFPToUI(builder, tmp[i], tmp_vec_type, ""); +#else + /* FIXME: there is no SSE counterpart for LLVMBuildFPToUI */ + tmp[i] = LLVMBuildFPToSI(builder, tmp[i], tmp_vec_type, ""); +#endif + } + } + } + else { + unsigned src_shift = lp_const_shift(src_type); + unsigned dst_shift = lp_const_shift(dst_type); + + /* FIXME: compensate different offsets too */ + if(src_shift > dst_shift) { + LLVMValueRef shift = lp_build_const_int_vec(gallivm, tmp_type, + src_shift - dst_shift); + for(i = 0; i < num_tmps; ++i) + if(src_type.sign) + tmp[i] = LLVMBuildAShr(builder, tmp[i], shift, ""); + else + tmp[i] = LLVMBuildLShr(builder, tmp[i], shift, ""); + } + } + + /* + * Truncate or expand bit width + * + * No data conversion should happen here, although the sign bits are + * crucial to avoid bad clamping. + */ + + { + struct lp_type new_type; + + new_type = tmp_type; + new_type.sign = dst_type.sign; + new_type.width = dst_type.width; + new_type.length = dst_type.length; + + lp_build_resize(gallivm, tmp_type, new_type, tmp, num_srcs, tmp, num_dsts); + + tmp_type = new_type; + num_tmps = num_dsts; + } + + /* + * Scale to the widest range + */ + + if(src_type.floating) { + /* Nothing to do */ + } + else if(!src_type.floating && dst_type.floating) { + if(!src_type.fixed && !src_type.sign && src_type.norm) { + for(i = 0; i < num_tmps; ++i) { + tmp[i] = lp_build_unsigned_norm_to_float(gallivm, + src_type.width, + dst_type, + tmp[i]); + } + tmp_type.floating = TRUE; + } + else { + double src_scale = lp_const_scale(src_type); + LLVMTypeRef tmp_vec_type; + + /* Use an equally sized integer for intermediate computations */ + tmp_type.floating = TRUE; + tmp_type.sign = TRUE; + tmp_vec_type = lp_build_vec_type(gallivm, tmp_type); + for(i = 0; i < num_tmps; ++i) { +#if 0 + if(dst_type.sign) + tmp[i] = LLVMBuildSIToFP(builder, tmp[i], tmp_vec_type, ""); + else + tmp[i] = LLVMBuildUIToFP(builder, tmp[i], tmp_vec_type, ""); +#else + /* FIXME: there is no SSE counterpart for LLVMBuildUIToFP */ + tmp[i] = LLVMBuildSIToFP(builder, tmp[i], tmp_vec_type, ""); +#endif + } + + if (src_scale != 1.0) { + LLVMValueRef scale = lp_build_const_vec(gallivm, tmp_type, 1.0/src_scale); + for(i = 0; i < num_tmps; ++i) + tmp[i] = LLVMBuildFMul(builder, tmp[i], scale, ""); + } + } + } + else { + unsigned src_shift = lp_const_shift(src_type); + unsigned dst_shift = lp_const_shift(dst_type); + + /* FIXME: compensate different offsets too */ + if(src_shift < dst_shift) { + LLVMValueRef shift = lp_build_const_int_vec(gallivm, tmp_type, dst_shift - src_shift); + for(i = 0; i < num_tmps; ++i) + tmp[i] = LLVMBuildShl(builder, tmp[i], shift, ""); + } + } + + for(i = 0; i < num_dsts; ++i) { + dst[i] = tmp[i]; + assert(lp_check_value(dst_type, dst[i])); + } +} + + +/** + * Bit mask conversion. + * + * This will convert the integer masks that match the given types. + * + * The mask values should 0 or -1, i.e., all bits either set to zero or one. + * Any other value will likely cause in unpredictable results. + * + * This is basically a very trimmed down version of lp_build_conv. + */ +void +lp_build_conv_mask(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + const LLVMValueRef *src, unsigned num_srcs, + LLVMValueRef *dst, unsigned num_dsts) +{ + /* Register width must remain constant */ + assert(src_type.width * src_type.length == dst_type.width * dst_type.length); + + /* We must not loose or gain channels. Only precision */ + assert(src_type.length * num_srcs == dst_type.length * num_dsts); + + /* + * Drop + * + * We assume all values are 0 or -1 + */ + + src_type.floating = FALSE; + src_type.fixed = FALSE; + src_type.sign = TRUE; + src_type.norm = FALSE; + + dst_type.floating = FALSE; + dst_type.fixed = FALSE; + dst_type.sign = TRUE; + dst_type.norm = FALSE; + + /* + * Truncate or expand bit width + */ + + if(src_type.width > dst_type.width) { + assert(num_dsts == 1); + dst[0] = lp_build_pack(gallivm, src_type, dst_type, TRUE, src, num_srcs); + } + else if(src_type.width < dst_type.width) { + assert(num_srcs == 1); + lp_build_unpack(gallivm, src_type, dst_type, src[0], dst, num_dsts); + } + else { + assert(num_srcs == num_dsts); + memcpy(dst, src, num_dsts * sizeof *dst); + } +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_conv.h b/src/gallium/auxiliary/gallivm/lp_bld_conv.h new file mode 100644 index 0000000..cec6559 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_conv.h @@ -0,0 +1,73 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Helper functions for type conversions. + * + * @author Jose Fonseca + */ + + +#ifndef LP_BLD_CONV_H +#define LP_BLD_CONV_H + + +#include "gallivm/lp_bld.h" + + +struct lp_type; + + +LLVMValueRef +lp_build_clamped_float_to_unsigned_norm(struct gallivm_state *gallivm, + struct lp_type src_type, + unsigned dst_width, + LLVMValueRef src); + +LLVMValueRef +lp_build_unsigned_norm_to_float(struct gallivm_state *gallivm, + unsigned src_width, + struct lp_type dst_type, + LLVMValueRef src); + + +void +lp_build_conv(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + const LLVMValueRef *srcs, unsigned num_srcs, + LLVMValueRef *dsts, unsigned num_dsts); + +void +lp_build_conv_mask(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + const LLVMValueRef *src, unsigned num_srcs, + LLVMValueRef *dst, unsigned num_dsts); + +#endif /* !LP_BLD_CONV_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_debug.c b/src/gallium/auxiliary/gallivm/lp_bld_debug.c new file mode 100644 index 0000000..93e5655 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.c @@ -0,0 +1,141 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifdef HAVE_UDIS86 +#include +#endif + +#include "util/u_math.h" +#include "util/u_debug.h" +#include "lp_bld_debug.h" + + +/** + * Check alignment. + * + * It is important that this check is not implemented as a macro or inlined + * function, as the compiler assumptions in respect to alignment of global + * and stack variables would often make the check a no op, defeating the + * whole purpose of the exercise. + */ +boolean +lp_check_alignment(const void *ptr, unsigned alignment) +{ + assert(util_is_power_of_two(alignment)); + return ((uintptr_t)ptr & (alignment - 1)) == 0; +} + + +void +lp_disassemble(const void* func) +{ +#ifdef HAVE_UDIS86 + ud_t ud_obj; + uint64_t max_jmp_pc; + uint inst_no; + boolean emit_addrs = TRUE, emit_line_nos = FALSE; + + ud_init(&ud_obj); + + ud_set_input_buffer(&ud_obj, (void*)func, 0xffff); + + max_jmp_pc = (uint64_t) (uintptr_t) func; + ud_set_pc(&ud_obj, max_jmp_pc); + +#ifdef PIPE_ARCH_X86 + ud_set_mode(&ud_obj, 32); +#endif +#ifdef PIPE_ARCH_X86_64 + ud_set_mode(&ud_obj, 64); +#endif + + ud_set_syntax(&ud_obj, UD_SYN_ATT); + + while (ud_disassemble(&ud_obj)) { + + if (emit_addrs) { +#ifdef PIPE_ARCH_X86 + debug_printf("0x%08lx:\t", (unsigned long)ud_insn_off(&ud_obj)); +#endif +#ifdef PIPE_ARCH_X86_64 + debug_printf("0x%016llx:\t", (unsigned long long)ud_insn_off(&ud_obj)); +#endif + } + else if (emit_line_nos) { + debug_printf("%6d:\t", inst_no); + inst_no++; + } +#if 0 + debug_printf("%-16s ", ud_insn_hex(&ud_obj)); +#endif + + debug_printf("%s\n", ud_insn_asm(&ud_obj)); + + if(ud_obj.mnemonic != UD_Icall) { + unsigned i; + for(i = 0; i < 3; ++i) { + const struct ud_operand *op = &ud_obj.operand[i]; + if (op->type == UD_OP_JIMM){ + uint64_t pc = ud_obj.pc; + + switch (op->size) { + case 8: + pc += op->lval.sbyte; + break; + case 16: + pc += op->lval.sword; + break; + case 32: + pc += op->lval.sdword; + break; + default: + break; + } + if(pc > max_jmp_pc) + max_jmp_pc = pc; + } + } + } + + if (ud_obj.mnemonic == UD_Iinvalid || + (ud_insn_off(&ud_obj) >= max_jmp_pc && + (ud_obj.mnemonic == UD_Iret || + ud_obj.mnemonic == UD_Ijmp))) + break; + } + +#if 0 + /* Print GDB command, useful to verify udis86 output */ + debug_printf("disassemble %p %p\n", func, (void*)(uintptr_t)ud_obj.pc); +#endif + + debug_printf("\n"); +#else + (void)func; +#endif +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_debug.h b/src/gallium/auxiliary/gallivm/lp_bld_debug.h new file mode 100644 index 0000000..8a58f95 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.h @@ -0,0 +1,84 @@ +/************************************************************************** + * + * 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 LP_BLD_DEBUG_H +#define LP_BLD_DEBUG_H + + +#include "gallivm/lp_bld.h" + +#include "pipe/p_compiler.h" +#include "util/u_string.h" + + +#define GALLIVM_DEBUG_TGSI (1 << 0) +#define GALLIVM_DEBUG_IR (1 << 1) +#define GALLIVM_DEBUG_ASM (1 << 2) +#define GALLIVM_DEBUG_NO_OPT (1 << 3) +#define GALLIVM_DEBUG_PERF (1 << 4) +#define GALLIVM_DEBUG_NO_BRILINEAR (1 << 5) +#define GALLIVM_DEBUG_GC (1 << 6) + + +#ifdef DEBUG +extern unsigned gallivm_debug; +#else +#define gallivm_debug 0 +#endif + + +static INLINE void +lp_build_name(LLVMValueRef val, const char *format, ...) +{ +#ifdef DEBUG + char name[32]; + va_list ap; + va_start(ap, format); + util_vsnprintf(name, sizeof name, format, ap); + va_end(ap); + LLVMSetValueName(val, name); +#else + (void)val; + (void)format; +#endif +} + + +void +lp_debug_dump_value(LLVMValueRef value); + + +boolean +lp_check_alignment(const void *ptr, unsigned alignment); + + +void +lp_disassemble(const void* func); + + +#endif /* !LP_BLD_DEBUG_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_flow.c b/src/gallium/auxiliary/gallivm/lp_bld_flow.c new file mode 100644 index 0000000..a9c9c7a --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_flow.c @@ -0,0 +1,463 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * LLVM control flow build helpers. + * + * @author Jose Fonseca + */ + +#include "util/u_debug.h" +#include "util/u_memory.h" + +#include "lp_bld_init.h" +#include "lp_bld_type.h" +#include "lp_bld_flow.h" + + +/** + * Insert a new block, right where builder is pointing to. + * + * This is useful important not only for aesthetic reasons, but also for + * performance reasons, as frequently run blocks should be laid out next to + * each other and fall-throughs maximized. + * + * See also llvm/lib/Transforms/Scalar/BasicBlockPlacement.cpp. + * + * Note: this function has no dependencies on the flow code and could + * be used elsewhere. + */ +LLVMBasicBlockRef +lp_build_insert_new_block(struct gallivm_state *gallivm, const char *name) +{ + LLVMBasicBlockRef current_block; + LLVMBasicBlockRef next_block; + LLVMBasicBlockRef new_block; + + /* get current basic block */ + current_block = LLVMGetInsertBlock(gallivm->builder); + + /* check if there's another block after this one */ + next_block = LLVMGetNextBasicBlock(current_block); + if (next_block) { + /* insert the new block before the next block */ + new_block = LLVMInsertBasicBlockInContext(gallivm->context, next_block, name); + } + else { + /* append new block after current block */ + LLVMValueRef function = LLVMGetBasicBlockParent(current_block); + new_block = LLVMAppendBasicBlockInContext(gallivm->context, function, name); + } + + return new_block; +} + + +/** + * Begin a "skip" block. Inside this block we can test a condition and + * skip to the end of the block if the condition is false. + */ +void +lp_build_flow_skip_begin(struct lp_build_skip_context *skip, + struct gallivm_state *gallivm) +{ + skip->gallivm = gallivm; + /* create new basic block */ + skip->block = lp_build_insert_new_block(gallivm, "skip"); +} + + +/** + * Insert code to test a condition and branch to the end of the current + * skip block if the condition is true. + */ +void +lp_build_flow_skip_cond_break(struct lp_build_skip_context *skip, + LLVMValueRef cond) +{ + LLVMBasicBlockRef new_block; + + new_block = lp_build_insert_new_block(skip->gallivm, ""); + + /* if cond is true, goto skip->block, else goto new_block */ + LLVMBuildCondBr(skip->gallivm->builder, cond, skip->block, new_block); + + LLVMPositionBuilderAtEnd(skip->gallivm->builder, new_block); +} + + +void +lp_build_flow_skip_end(struct lp_build_skip_context *skip) +{ + /* goto block */ + LLVMBuildBr(skip->gallivm->builder, skip->block); + LLVMPositionBuilderAtEnd(skip->gallivm->builder, skip->block); +} + + +/** + * Check if the mask predicate is zero. If so, jump to the end of the block. + */ +void +lp_build_mask_check(struct lp_build_mask_context *mask) +{ + LLVMBuilderRef builder = mask->skip.gallivm->builder; + LLVMValueRef value; + LLVMValueRef cond; + + value = lp_build_mask_value(mask); + + /* cond = (mask == 0) */ + cond = LLVMBuildICmp(builder, + LLVMIntEQ, + LLVMBuildBitCast(builder, value, mask->reg_type, ""), + LLVMConstNull(mask->reg_type), + ""); + + /* if cond, goto end of block */ + lp_build_flow_skip_cond_break(&mask->skip, cond); +} + + +/** + * Begin a section of code which is predicated on a mask. + * \param mask the mask context, initialized here + * \param flow the flow context + * \param type the type of the mask + * \param value storage for the mask + */ +void +lp_build_mask_begin(struct lp_build_mask_context *mask, + struct gallivm_state *gallivm, + struct lp_type type, + LLVMValueRef value) +{ + memset(mask, 0, sizeof *mask); + + mask->reg_type = LLVMIntTypeInContext(gallivm->context, type.width * type.length); + mask->var = lp_build_alloca(gallivm, + lp_build_int_vec_type(gallivm, type), + "execution_mask"); + + LLVMBuildStore(gallivm->builder, value, mask->var); + + lp_build_flow_skip_begin(&mask->skip, gallivm); +} + + +LLVMValueRef +lp_build_mask_value(struct lp_build_mask_context *mask) +{ + return LLVMBuildLoad(mask->skip.gallivm->builder, mask->var, ""); +} + + +/** + * Update boolean mask with given value (bitwise AND). + * Typically used to update the quad's pixel alive/killed mask + * after depth testing, alpha testing, TGSI_OPCODE_KIL, etc. + */ +void +lp_build_mask_update(struct lp_build_mask_context *mask, + LLVMValueRef value) +{ + value = LLVMBuildAnd(mask->skip.gallivm->builder, + lp_build_mask_value(mask), + value, ""); + LLVMBuildStore(mask->skip.gallivm->builder, value, mask->var); +} + + +/** + * End section of code which is predicated on a mask. + */ +LLVMValueRef +lp_build_mask_end(struct lp_build_mask_context *mask) +{ + lp_build_flow_skip_end(&mask->skip); + return lp_build_mask_value(mask); +} + + + +void +lp_build_loop_begin(struct lp_build_loop_state *state, + struct gallivm_state *gallivm, + LLVMValueRef start) + +{ + LLVMBuilderRef builder = gallivm->builder; + + state->block = lp_build_insert_new_block(gallivm, "loop_begin"); + + state->counter_var = lp_build_alloca(gallivm, LLVMTypeOf(start), "loop_counter"); + state->gallivm = gallivm; + + LLVMBuildStore(builder, start, state->counter_var); + + LLVMBuildBr(builder, state->block); + + LLVMPositionBuilderAtEnd(builder, state->block); + + state->counter = LLVMBuildLoad(builder, state->counter_var, ""); +} + + +void +lp_build_loop_end_cond(struct lp_build_loop_state *state, + LLVMValueRef end, + LLVMValueRef step, + LLVMIntPredicate llvm_cond) +{ + LLVMBuilderRef builder = state->gallivm->builder; + LLVMValueRef next; + LLVMValueRef cond; + LLVMBasicBlockRef after_block; + + if (!step) + step = LLVMConstInt(LLVMTypeOf(end), 1, 0); + + next = LLVMBuildAdd(builder, state->counter, step, ""); + + LLVMBuildStore(builder, next, state->counter_var); + + cond = LLVMBuildICmp(builder, llvm_cond, next, end, ""); + + after_block = lp_build_insert_new_block(state->gallivm, "loop_end"); + + LLVMBuildCondBr(builder, cond, after_block, state->block); + + LLVMPositionBuilderAtEnd(builder, after_block); + + state->counter = LLVMBuildLoad(builder, state->counter_var, ""); +} + + +void +lp_build_loop_end(struct lp_build_loop_state *state, + LLVMValueRef end, + LLVMValueRef step) +{ + lp_build_loop_end_cond(state, end, step, LLVMIntNE); +} + + + +/* + Example of if/then/else building: + + int x; + if (cond) { + x = 1 + 2; + } + else { + x = 2 + 3; + } + + Is built with: + + // x needs an alloca variable + x = lp_build_alloca(builder, type, "x"); + + + lp_build_if(ctx, builder, cond); + LLVMBuildStore(LLVMBuildAdd(1, 2), x); + lp_build_else(ctx); + LLVMBuildStore(LLVMBuildAdd(2, 3). x); + lp_build_endif(ctx); + + */ + + + +/** + * Begin an if/else/endif construct. + */ +void +lp_build_if(struct lp_build_if_state *ifthen, + struct gallivm_state *gallivm, + LLVMValueRef condition) +{ + LLVMBasicBlockRef block = LLVMGetInsertBlock(gallivm->builder); + + memset(ifthen, 0, sizeof *ifthen); + ifthen->gallivm = gallivm; + ifthen->condition = condition; + ifthen->entry_block = block; + + /* create endif/merge basic block for the phi functions */ + ifthen->merge_block = lp_build_insert_new_block(gallivm, "endif-block"); + + /* create/insert true_block before merge_block */ + ifthen->true_block = + LLVMInsertBasicBlockInContext(gallivm->context, + ifthen->merge_block, + "if-true-block"); + + /* successive code goes into the true block */ + LLVMPositionBuilderAtEnd(gallivm->builder, ifthen->true_block); +} + + +/** + * Begin else-part of a conditional + */ +void +lp_build_else(struct lp_build_if_state *ifthen) +{ + LLVMBuilderRef builder = ifthen->gallivm->builder; + + /* Append an unconditional Br(anch) instruction on the true_block */ + LLVMBuildBr(builder, ifthen->merge_block); + + /* create/insert false_block before the merge block */ + ifthen->false_block = + LLVMInsertBasicBlockInContext(ifthen->gallivm->context, + ifthen->merge_block, + "if-false-block"); + + /* successive code goes into the else block */ + LLVMPositionBuilderAtEnd(builder, ifthen->false_block); +} + + +/** + * End a conditional. + */ +void +lp_build_endif(struct lp_build_if_state *ifthen) +{ + LLVMBuilderRef builder = ifthen->gallivm->builder; + + /* Insert branch to the merge block from current block */ + LLVMBuildBr(builder, ifthen->merge_block); + + /* + * Now patch in the various branch instructions. + */ + + /* Insert the conditional branch instruction at the end of entry_block */ + LLVMPositionBuilderAtEnd(builder, ifthen->entry_block); + if (ifthen->false_block) { + /* we have an else clause */ + LLVMBuildCondBr(builder, ifthen->condition, + ifthen->true_block, ifthen->false_block); + } + else { + /* no else clause */ + LLVMBuildCondBr(builder, ifthen->condition, + ifthen->true_block, ifthen->merge_block); + } + + /* Resume building code at end of the ifthen->merge_block */ + LLVMPositionBuilderAtEnd(builder, ifthen->merge_block); +} + + +/** + * Allocate a scalar (or vector) variable. + * + * Although not strictly part of control flow, control flow has deep impact in + * how variables should be allocated. + * + * The mem2reg optimization pass is the recommended way to dealing with mutable + * variables, and SSA. It looks for allocas and if it can handle them, it + * promotes them, but only looks for alloca instructions in the entry block of + * the function. Being in the entry block guarantees that the alloca is only + * executed once, which makes analysis simpler. + * + * See also: + * - http://www.llvm.org/docs/tutorial/OCamlLangImpl7.html#memory + */ +LLVMValueRef +lp_build_alloca(struct gallivm_state *gallivm, + LLVMTypeRef type, + const char *name) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMBasicBlockRef current_block = LLVMGetInsertBlock(builder); + LLVMValueRef function = LLVMGetBasicBlockParent(current_block); + LLVMBasicBlockRef first_block = LLVMGetEntryBasicBlock(function); + LLVMValueRef first_instr = LLVMGetFirstInstruction(first_block); + LLVMBuilderRef first_builder = LLVMCreateBuilderInContext(gallivm->context); + LLVMValueRef res; + + if (first_instr) { + LLVMPositionBuilderBefore(first_builder, first_instr); + } else { + LLVMPositionBuilderAtEnd(first_builder, first_block); + } + + res = LLVMBuildAlloca(first_builder, type, name); + LLVMBuildStore(builder, LLVMConstNull(type), res); + + LLVMDisposeBuilder(first_builder); + + return res; +} + + +/** + * Allocate an array of scalars/vectors. + * + * mem2reg pass is not capable of promoting structs or arrays to registers, but + * we still put it in the first block anyway as failure to put allocas in the + * first block may prevent the X86 backend from successfully align the stack as + * required. + * + * Also the scalarrepl pass is supposedly more powerful and can promote + * arrays in many cases. + * + * See also: + * - http://www.llvm.org/docs/tutorial/OCamlLangImpl7.html#memory + */ +LLVMValueRef +lp_build_array_alloca(struct gallivm_state *gallivm, + LLVMTypeRef type, + LLVMValueRef count, + const char *name) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMBasicBlockRef current_block = LLVMGetInsertBlock(builder); + LLVMValueRef function = LLVMGetBasicBlockParent(current_block); + LLVMBasicBlockRef first_block = LLVMGetEntryBasicBlock(function); + LLVMValueRef first_instr = LLVMGetFirstInstruction(first_block); + LLVMBuilderRef first_builder = LLVMCreateBuilderInContext(gallivm->context); + LLVMValueRef res; + + if (first_instr) { + LLVMPositionBuilderBefore(first_builder, first_instr); + } else { + LLVMPositionBuilderAtEnd(first_builder, first_block); + } + + res = LLVMBuildArrayAlloca(first_builder, type, count, name); + + LLVMDisposeBuilder(first_builder); + + return res; +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_flow.h b/src/gallium/auxiliary/gallivm/lp_bld_flow.h new file mode 100644 index 0000000..3cd5a9f --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_flow.h @@ -0,0 +1,174 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * LLVM control flow build helpers. + * + * @author Jose Fonseca + */ + +#ifndef LP_BLD_FLOW_H +#define LP_BLD_FLOW_H + + +#include "gallivm/lp_bld.h" + + +struct lp_type; + + +/** + * Early exit. Useful to skip to the end of a function or block when + * the execution mask becomes zero or when there is an error condition. + */ +struct lp_build_skip_context +{ + struct gallivm_state *gallivm; + + /** Block to skip to */ + LLVMBasicBlockRef block; +}; + +void +lp_build_flow_skip_begin(struct lp_build_skip_context *ctx, + struct gallivm_state *gallivm); + +void +lp_build_flow_skip_cond_break(struct lp_build_skip_context *ctx, + LLVMValueRef cond); + +void +lp_build_flow_skip_end(struct lp_build_skip_context *ctx); + + +struct lp_build_mask_context +{ + struct lp_build_skip_context skip; + + LLVMTypeRef reg_type; + + LLVMValueRef var; +}; + + +void +lp_build_mask_begin(struct lp_build_mask_context *mask, + struct gallivm_state *gallivm, + struct lp_type type, + LLVMValueRef value); + +LLVMValueRef +lp_build_mask_value(struct lp_build_mask_context *mask); + +/** + * Bitwise AND the mask with the given value, if a previous mask was set. + */ +void +lp_build_mask_update(struct lp_build_mask_context *mask, + LLVMValueRef value); + +void +lp_build_mask_check(struct lp_build_mask_context *mask); + +LLVMValueRef +lp_build_mask_end(struct lp_build_mask_context *mask); + + +/** + * LLVM's IR doesn't represent for-loops directly. Furthermore it + * it requires creating code blocks, branches, phi variables, so it + * requires a fair amount of code. + * + * @sa http://www.llvm.org/docs/tutorial/LangImpl5.html#for + */ +struct lp_build_loop_state +{ + LLVMBasicBlockRef block; + LLVMValueRef counter_var; + LLVMValueRef counter; + struct gallivm_state *gallivm; +}; + + +void +lp_build_loop_begin(struct lp_build_loop_state *state, + struct gallivm_state *gallivm, + LLVMValueRef start); + +void +lp_build_loop_end(struct lp_build_loop_state *state, + LLVMValueRef end, + LLVMValueRef step); + +void +lp_build_loop_end_cond(struct lp_build_loop_state *state, + LLVMValueRef end, + LLVMValueRef step, + LLVMIntPredicate cond); + + + +/** + * if/else/endif. + */ +struct lp_build_if_state +{ + struct gallivm_state *gallivm; + LLVMValueRef condition; + LLVMBasicBlockRef entry_block; + LLVMBasicBlockRef true_block; + LLVMBasicBlockRef false_block; + LLVMBasicBlockRef merge_block; +}; + + +void +lp_build_if(struct lp_build_if_state *ctx, + struct gallivm_state *gallivm, + LLVMValueRef condition); + +void +lp_build_else(struct lp_build_if_state *ctx); + +void +lp_build_endif(struct lp_build_if_state *ctx); + +LLVMBasicBlockRef +lp_build_insert_new_block(struct gallivm_state *gallivm, const char *name); + +LLVMValueRef +lp_build_alloca(struct gallivm_state *gallivm, + LLVMTypeRef type, + const char *name); + +LLVMValueRef +lp_build_array_alloca(struct gallivm_state *gallivm, + LLVMTypeRef type, + LLVMValueRef count, + const char *name); + +#endif /* !LP_BLD_FLOW_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format.h b/src/gallium/auxiliary/gallivm/lp_bld_format.h new file mode 100644 index 0000000..04142d9 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_format.h @@ -0,0 +1,118 @@ +/************************************************************************** + * + * 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 LP_BLD_FORMAT_H +#define LP_BLD_FORMAT_H + + +/** + * @file + * Pixel format helpers. + */ + +#include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_init.h" + +#include "pipe/p_format.h" + +struct util_format_description; +struct lp_type; +struct lp_build_context; + + +/* + * AoS + */ + +LLVMValueRef +lp_build_format_swizzle_aos(const struct util_format_description *desc, + struct lp_build_context *bld, + LLVMValueRef unswizzled); + +LLVMValueRef +lp_build_pack_rgba_aos(struct gallivm_state *gallivm, + const struct util_format_description *desc, + LLVMValueRef rgba); + +LLVMValueRef +lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, + const struct util_format_description *format_desc, + struct lp_type type, + LLVMValueRef base_ptr, + LLVMValueRef offset, + LLVMValueRef i, + LLVMValueRef j); + + +/* + * SoA + */ + +void +lp_build_format_swizzle_soa(const struct util_format_description *format_desc, + struct lp_build_context *bld, + const LLVMValueRef unswizzled[4], + LLVMValueRef swizzled_out[4]); + +void +lp_build_unpack_rgba_soa(struct gallivm_state *gallivm, + const struct util_format_description *format_desc, + struct lp_type type, + LLVMValueRef packed, + LLVMValueRef rgba_out[4]); + +void +lp_build_rgba8_to_f32_soa(struct gallivm_state *gallivm, + struct lp_type dst_type, + LLVMValueRef packed, + LLVMValueRef *rgba); + +void +lp_build_fetch_rgba_soa(struct gallivm_state *gallivm, + const struct util_format_description *format_desc, + struct lp_type type, + LLVMValueRef base_ptr, + LLVMValueRef offsets, + LLVMValueRef i, + LLVMValueRef j, + LLVMValueRef rgba_out[4]); + +/* + * YUV + */ + + +LLVMValueRef +lp_build_fetch_subsampled_rgba_aos(struct gallivm_state *gallivm, + const struct util_format_description *format_desc, + unsigned n, + LLVMValueRef base_ptr, + LLVMValueRef offset, + LLVMValueRef i, + LLVMValueRef j); + +#endif /* !LP_BLD_FORMAT_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c new file mode 100644 index 0000000..8a4261f --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c @@ -0,0 +1,732 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * AoS pixel format manipulation. + * + * @author Jose Fonseca + */ + + +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_pointer.h" +#include "util/u_string.h" + +#include "lp_bld_arit.h" +#include "lp_bld_init.h" +#include "lp_bld_type.h" +#include "lp_bld_flow.h" +#include "lp_bld_const.h" +#include "lp_bld_conv.h" +#include "lp_bld_swizzle.h" +#include "lp_bld_gather.h" +#include "lp_bld_debug.h" +#include "lp_bld_format.h" + + +/** + * Basic swizzling. Rearrange the order of the unswizzled array elements + * according to the format description. PIPE_SWIZZLE_ZERO/ONE are supported + * too. + * Ex: if unswizzled[4] = {B, G, R, x}, then swizzled_out[4] = {R, G, B, 1}. + */ +LLVMValueRef +lp_build_format_swizzle_aos(const struct util_format_description *desc, + struct lp_build_context *bld, + LLVMValueRef unswizzled) +{ + unsigned char swizzles[4]; + unsigned chan; + + assert(bld->type.length % 4 == 0); + + for (chan = 0; chan < 4; ++chan) { + enum util_format_swizzle swizzle; + + if (desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) { + /* + * For ZS formats do RGBA = ZZZ1 + */ + if (chan == 3) { + swizzle = UTIL_FORMAT_SWIZZLE_1; + } else if (desc->swizzle[0] == UTIL_FORMAT_SWIZZLE_NONE) { + swizzle = UTIL_FORMAT_SWIZZLE_0; + } else { + swizzle = desc->swizzle[0]; + } + } else { + swizzle = desc->swizzle[chan]; + } + swizzles[chan] = swizzle; + } + + return lp_build_swizzle_aos(bld, unswizzled, swizzles); +} + + +/** + * Whether the format matches the vector type, apart of swizzles. + */ +static INLINE boolean +format_matches_type(const struct util_format_description *desc, + struct lp_type type) +{ + enum util_format_type chan_type; + unsigned chan; + + assert(type.length % 4 == 0); + + if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN || + desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB || + desc->block.width != 1 || + desc->block.height != 1) { + return FALSE; + } + + if (type.floating) { + chan_type = UTIL_FORMAT_TYPE_FLOAT; + } else if (type.fixed) { + chan_type = UTIL_FORMAT_TYPE_FIXED; + } else if (type.sign) { + chan_type = UTIL_FORMAT_TYPE_SIGNED; + } else { + chan_type = UTIL_FORMAT_TYPE_UNSIGNED; + } + + for (chan = 0; chan < desc->nr_channels; ++chan) { + if (desc->channel[chan].size != type.width) { + return FALSE; + } + + if (desc->channel[chan].type != UTIL_FORMAT_TYPE_VOID) { + if (desc->channel[chan].type != chan_type || + desc->channel[chan].normalized != type.norm) { + return FALSE; + } + } + } + + return TRUE; +} + + +/** + * Unpack a single pixel into its RGBA components. + * + * @param desc the pixel format for the packed pixel value + * @param packed integer pixel in a format such as PIPE_FORMAT_B8G8R8A8_UNORM + * + * @return RGBA in a float[4] or ubyte[4] or ushort[4] vector. + */ +static INLINE LLVMValueRef +lp_build_unpack_arith_rgba_aos(struct gallivm_state *gallivm, + const struct util_format_description *desc, + LLVMValueRef packed) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef shifted, casted, scaled, masked; + LLVMValueRef shifts[4]; + LLVMValueRef masks[4]; + LLVMValueRef scales[4]; + + boolean normalized; + boolean needs_uitofp; + unsigned shift; + unsigned i; + + /* TODO: Support more formats */ + assert(desc->layout == UTIL_FORMAT_LAYOUT_PLAIN); + assert(desc->block.width == 1); + assert(desc->block.height == 1); + assert(desc->block.bits <= 32); + + /* Do the intermediate integer computations with 32bit integers since it + * matches floating point size */ + assert (LLVMTypeOf(packed) == LLVMInt32TypeInContext(gallivm->context)); + + /* Broadcast the packed value to all four channels + * before: packed = BGRA + * after: packed = {BGRA, BGRA, BGRA, BGRA} + */ + packed = LLVMBuildInsertElement(builder, + LLVMGetUndef(LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4)), + packed, + LLVMConstNull(LLVMInt32TypeInContext(gallivm->context)), + ""); + packed = LLVMBuildShuffleVector(builder, + packed, + LLVMGetUndef(LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4)), + LLVMConstNull(LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4)), + ""); + + /* Initialize vector constants */ + normalized = FALSE; + needs_uitofp = FALSE; + shift = 0; + + /* Loop over 4 color components */ + for (i = 0; i < 4; ++i) { + unsigned bits = desc->channel[i].size; + + if (desc->channel[i].type == UTIL_FORMAT_TYPE_VOID) { + shifts[i] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context)); + masks[i] = LLVMConstNull(LLVMInt32TypeInContext(gallivm->context)); + scales[i] = LLVMConstNull(LLVMFloatTypeInContext(gallivm->context)); + } + else { + unsigned long long mask = (1ULL << bits) - 1; + + assert(desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED); + + if (bits == 32) { + needs_uitofp = TRUE; + } + + shifts[i] = lp_build_const_int32(gallivm, shift); + masks[i] = lp_build_const_int32(gallivm, mask); + + if (desc->channel[i].normalized) { + scales[i] = lp_build_const_float(gallivm, 1.0 / mask); + normalized = TRUE; + } + else + scales[i] = lp_build_const_float(gallivm, 1.0); + } + + shift += bits; + } + + /* Ex: convert packed = {BGRA, BGRA, BGRA, BGRA} + * into masked = {B, G, R, A} + */ + shifted = LLVMBuildLShr(builder, packed, LLVMConstVector(shifts, 4), ""); + masked = LLVMBuildAnd(builder, shifted, LLVMConstVector(masks, 4), ""); + + + if (!needs_uitofp) { + /* UIToFP can't be expressed in SSE2 */ + casted = LLVMBuildSIToFP(builder, masked, LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4), ""); + } else { + casted = LLVMBuildUIToFP(builder, masked, LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4), ""); + } + + /* At this point 'casted' may be a vector of floats such as + * {255.0, 255.0, 255.0, 255.0}. Next, if the pixel values are normalized + * we'll scale this to {1.0, 1.0, 1.0, 1.0}. + */ + + if (normalized) + scaled = LLVMBuildFMul(builder, casted, LLVMConstVector(scales, 4), ""); + else + scaled = casted; + + return scaled; +} + + +/** + * Pack a single pixel. + * + * @param rgba 4 float vector with the unpacked components. + * + * XXX: This is mostly for reference and testing -- operating a single pixel at + * a time is rarely if ever needed. + */ +LLVMValueRef +lp_build_pack_rgba_aos(struct gallivm_state *gallivm, + const struct util_format_description *desc, + LLVMValueRef rgba) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMTypeRef type; + LLVMValueRef packed = NULL; + LLVMValueRef swizzles[4]; + LLVMValueRef shifted, casted, scaled, unswizzled; + LLVMValueRef shifts[4]; + LLVMValueRef scales[4]; + boolean normalized; + unsigned shift; + unsigned i, j; + + assert(desc->layout == UTIL_FORMAT_LAYOUT_PLAIN); + assert(desc->block.width == 1); + assert(desc->block.height == 1); + + type = LLVMIntTypeInContext(gallivm->context, desc->block.bits); + + /* Unswizzle the color components into the source vector. */ + for (i = 0; i < 4; ++i) { + for (j = 0; j < 4; ++j) { + if (desc->swizzle[j] == i) + break; + } + if (j < 4) + swizzles[i] = lp_build_const_int32(gallivm, j); + else + swizzles[i] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context)); + } + + unswizzled = LLVMBuildShuffleVector(builder, rgba, + LLVMGetUndef(LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4)), + LLVMConstVector(swizzles, 4), ""); + + normalized = FALSE; + shift = 0; + for (i = 0; i < 4; ++i) { + unsigned bits = desc->channel[i].size; + + if (desc->channel[i].type == UTIL_FORMAT_TYPE_VOID) { + shifts[i] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context)); + scales[i] = LLVMGetUndef(LLVMFloatTypeInContext(gallivm->context)); + } + else { + unsigned mask = (1 << bits) - 1; + + assert(desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED); + assert(bits < 32); + + shifts[i] = lp_build_const_int32(gallivm, shift); + + if (desc->channel[i].normalized) { + scales[i] = lp_build_const_float(gallivm, mask); + normalized = TRUE; + } + else + scales[i] = lp_build_const_float(gallivm, 1.0); + } + + shift += bits; + } + + if (normalized) + scaled = LLVMBuildFMul(builder, unswizzled, LLVMConstVector(scales, 4), ""); + else + scaled = unswizzled; + + casted = LLVMBuildFPToSI(builder, scaled, LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4), ""); + + shifted = LLVMBuildShl(builder, casted, LLVMConstVector(shifts, 4), ""); + + /* Bitwise or all components */ + for (i = 0; i < 4; ++i) { + if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED) { + LLVMValueRef component = LLVMBuildExtractElement(builder, shifted, + lp_build_const_int32(gallivm, i), ""); + if (packed) + packed = LLVMBuildOr(builder, packed, component, ""); + else + packed = component; + } + } + + if (!packed) + packed = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context)); + + if (desc->block.bits < 32) + packed = LLVMBuildTrunc(builder, packed, type, ""); + + return packed; +} + + + + +/** + * Fetch a pixel into a 4 float AoS. + * + * \param format_desc describes format of the image we're fetching from + * \param ptr address of the pixel block (or the texel if uncompressed) + * \param i, j the sub-block pixel coordinates. For non-compressed formats + * these will always be (0, 0). + * \return a 4 element vector with the pixel's RGBA values. + */ +LLVMValueRef +lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, + const struct util_format_description *format_desc, + struct lp_type type, + LLVMValueRef base_ptr, + LLVMValueRef offset, + LLVMValueRef i, + LLVMValueRef j) +{ + LLVMBuilderRef builder = gallivm->builder; + unsigned num_pixels = type.length / 4; + struct lp_build_context bld; + + assert(type.length <= LP_MAX_VECTOR_LENGTH); + assert(type.length % 4 == 0); + + lp_build_context_init(&bld, gallivm, type); + + /* + * Trivial case + * + * The format matches the type (apart of a swizzle) so no need for + * scaling or converting. + */ + + if (format_matches_type(format_desc, type) && + format_desc->block.bits <= type.width * 4 && + util_is_power_of_two(format_desc->block.bits)) { + LLVMValueRef packed; + + /* + * The format matches the type (apart of a swizzle) so no need for + * scaling or converting. + */ + + packed = lp_build_gather(gallivm, type.length/4, + format_desc->block.bits, type.width*4, + base_ptr, offset); + + assert(format_desc->block.bits <= type.width * type.length); + + packed = LLVMBuildBitCast(gallivm->builder, packed, + lp_build_vec_type(gallivm, type), ""); + + return lp_build_format_swizzle_aos(format_desc, &bld, packed); + } + + /* + * Bit arithmetic + */ + + if (format_desc->layout == UTIL_FORMAT_LAYOUT_PLAIN && + (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB || + format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) && + format_desc->block.width == 1 && + format_desc->block.height == 1 && + util_is_power_of_two(format_desc->block.bits) && + format_desc->block.bits <= 32 && + format_desc->is_bitmask && + !format_desc->is_mixed && + (format_desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED || + format_desc->channel[1].type == UTIL_FORMAT_TYPE_UNSIGNED)) { + + LLVMValueRef tmps[LP_MAX_VECTOR_LENGTH/4]; + LLVMValueRef res; + unsigned k; + + /* + * Unpack a pixel at a time into a <4 x float> RGBA vector + */ + + for (k = 0; k < num_pixels; ++k) { + LLVMValueRef packed; + + packed = lp_build_gather_elem(gallivm, num_pixels, + format_desc->block.bits, 32, + base_ptr, offset, k); + + tmps[k] = lp_build_unpack_arith_rgba_aos(gallivm, + format_desc, + packed); + } + + /* + * Type conversion. + * + * TODO: We could avoid floating conversion for integer to + * integer conversions. + */ + + if (gallivm_debug & GALLIVM_DEBUG_PERF && !type.floating) { + debug_printf("%s: unpacking %s with floating point\n", + __FUNCTION__, format_desc->short_name); + } + + lp_build_conv(gallivm, + lp_float32_vec4_type(), + type, + tmps, num_pixels, &res, 1); + + return lp_build_format_swizzle_aos(format_desc, &bld, res); + } + + /* + * YUV / subsampled formats + */ + + if (format_desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED) { + struct lp_type tmp_type; + LLVMValueRef tmp; + + memset(&tmp_type, 0, sizeof tmp_type); + tmp_type.width = 8; + tmp_type.length = num_pixels * 4; + tmp_type.norm = TRUE; + + tmp = lp_build_fetch_subsampled_rgba_aos(gallivm, + format_desc, + num_pixels, + base_ptr, + offset, + i, j); + + lp_build_conv(gallivm, + tmp_type, type, + &tmp, 1, &tmp, 1); + + return tmp; + } + + /* + * Fallback to util_format_description::fetch_rgba_8unorm(). + */ + + if (format_desc->fetch_rgba_8unorm && + !type.floating && type.width == 8 && !type.sign && type.norm) { + /* + * Fallback to calling util_format_description::fetch_rgba_8unorm. + * + * This is definitely not the most efficient way of fetching pixels, as + * we miss the opportunity to do vectorization, but this it is a + * convenient for formats or scenarios for which there was no opportunity + * or incentive to optimize. + */ + + LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(gallivm->builder))); + char name[256]; + LLVMTypeRef i8t = LLVMInt8TypeInContext(gallivm->context); + LLVMTypeRef pi8t = LLVMPointerType(i8t, 0); + LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context); + LLVMValueRef function; + LLVMValueRef tmp_ptr; + LLVMValueRef tmp; + LLVMValueRef res; + LLVMValueRef callee; + unsigned k; + + util_snprintf(name, sizeof name, "util_format_%s_fetch_rgba_8unorm", + format_desc->short_name); + + if (gallivm_debug & GALLIVM_DEBUG_PERF) { + debug_printf("%s: falling back to %s\n", __FUNCTION__, name); + } + + /* + * Declare and bind format_desc->fetch_rgba_8unorm(). + */ + + function = LLVMGetNamedFunction(module, name); + if (!function) { + /* + * Function to call looks like: + * fetch(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) + */ + LLVMTypeRef ret_type; + LLVMTypeRef arg_types[4]; + LLVMTypeRef function_type; + + ret_type = LLVMVoidTypeInContext(gallivm->context); + arg_types[0] = pi8t; + arg_types[1] = pi8t; + arg_types[2] = i32t; + arg_types[3] = i32t; + function_type = LLVMFunctionType(ret_type, arg_types, + Elements(arg_types), 0); + function = LLVMAddFunction(module, name, function_type); + + LLVMSetFunctionCallConv(function, LLVMCCallConv); + LLVMSetLinkage(function, LLVMExternalLinkage); + + assert(LLVMIsDeclaration(function)); + } + + /* make const pointer for the C fetch_rgba_float function */ + callee = lp_build_const_int_pointer(gallivm, + func_to_pointer((func_pointer) format_desc->fetch_rgba_8unorm)); + + /* cast the callee pointer to the function's type */ + function = LLVMBuildBitCast(builder, callee, + LLVMTypeOf(function), "cast callee"); + + tmp_ptr = lp_build_alloca(gallivm, i32t, ""); + + res = LLVMGetUndef(LLVMVectorType(i32t, num_pixels)); + + /* + * Invoke format_desc->fetch_rgba_8unorm() for each pixel and insert the result + * in the SoA vectors. + */ + + for (k = 0; k < num_pixels; ++k) { + LLVMValueRef index = lp_build_const_int32(gallivm, k); + LLVMValueRef args[4]; + + args[0] = LLVMBuildBitCast(builder, tmp_ptr, pi8t, ""); + args[1] = lp_build_gather_elem_ptr(gallivm, num_pixels, + base_ptr, offset, k); + + if (num_pixels == 1) { + args[2] = i; + args[3] = j; + } + else { + args[2] = LLVMBuildExtractElement(builder, i, index, ""); + args[3] = LLVMBuildExtractElement(builder, j, index, ""); + } + + LLVMBuildCall(builder, function, args, Elements(args), ""); + + tmp = LLVMBuildLoad(builder, tmp_ptr, ""); + + if (num_pixels == 1) { + res = tmp; + } + else { + res = LLVMBuildInsertElement(builder, res, tmp, index, ""); + } + } + + /* Bitcast from to <4n x i8> */ + res = LLVMBuildBitCast(builder, res, bld.vec_type, ""); + + return res; + } + + + /* + * Fallback to util_format_description::fetch_rgba_float(). + */ + + if (format_desc->fetch_rgba_float) { + /* + * Fallback to calling util_format_description::fetch_rgba_float. + * + * This is definitely not the most efficient way of fetching pixels, as + * we miss the opportunity to do vectorization, but this it is a + * convenient for formats or scenarios for which there was no opportunity + * or incentive to optimize. + */ + + LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder))); + char name[256]; + LLVMTypeRef f32t = LLVMFloatTypeInContext(gallivm->context); + LLVMTypeRef f32x4t = LLVMVectorType(f32t, 4); + LLVMTypeRef pf32t = LLVMPointerType(f32t, 0); + LLVMTypeRef pi8t = LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0); + LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context); + LLVMValueRef function; + LLVMValueRef tmp_ptr; + LLVMValueRef tmps[LP_MAX_VECTOR_LENGTH/4]; + LLVMValueRef res; + LLVMValueRef callee; + unsigned k; + + util_snprintf(name, sizeof name, "util_format_%s_fetch_rgba_float", + format_desc->short_name); + + if (gallivm_debug & GALLIVM_DEBUG_PERF) { + debug_printf("%s: falling back to %s\n", __FUNCTION__, name); + } + + /* + * Declare and bind format_desc->fetch_rgba_float(). + */ + + function = LLVMGetNamedFunction(module, name); + if (!function) { + /* + * Function to call looks like: + * fetch(float *dst, const uint8_t *src, unsigned i, unsigned j) + */ + LLVMTypeRef ret_type; + LLVMTypeRef arg_types[4]; + LLVMTypeRef function_type; + + ret_type = LLVMVoidTypeInContext(gallivm->context); + arg_types[0] = pf32t; + arg_types[1] = pi8t; + arg_types[2] = i32t; + arg_types[3] = i32t; + function_type = LLVMFunctionType(ret_type, arg_types, + Elements(arg_types), 0); + function = LLVMAddFunction(module, name, function_type); + + LLVMSetFunctionCallConv(function, LLVMCCallConv); + LLVMSetLinkage(function, LLVMExternalLinkage); + + assert(LLVMIsDeclaration(function)); + } + + /* Note: we're using this casting here instead of LLVMAddGlobalMapping() + * to work around a bug in LLVM 2.6. + */ + + /* make const pointer for the C fetch_rgba_float function */ + callee = lp_build_const_int_pointer(gallivm, + func_to_pointer((func_pointer) format_desc->fetch_rgba_float)); + + /* cast the callee pointer to the function's type */ + function = LLVMBuildBitCast(builder, callee, + LLVMTypeOf(function), "cast callee"); + + + tmp_ptr = lp_build_alloca(gallivm, f32x4t, ""); + + /* + * Invoke format_desc->fetch_rgba_float() for each pixel and insert the result + * in the SoA vectors. + */ + + for (k = 0; k < num_pixels; ++k) { + LLVMValueRef args[4]; + + args[0] = LLVMBuildBitCast(builder, tmp_ptr, pf32t, ""); + args[1] = lp_build_gather_elem_ptr(gallivm, num_pixels, + base_ptr, offset, k); + + if (num_pixels == 1) { + args[2] = i; + args[3] = j; + } + else { + LLVMValueRef index = lp_build_const_int32(gallivm, k); + args[2] = LLVMBuildExtractElement(builder, i, index, ""); + args[3] = LLVMBuildExtractElement(builder, j, index, ""); + } + + LLVMBuildCall(builder, function, args, Elements(args), ""); + + tmps[k] = LLVMBuildLoad(builder, tmp_ptr, ""); + } + + lp_build_conv(gallivm, + lp_float32_vec4_type(), + type, + tmps, num_pixels, &res, 1); + + return res; + } + + assert(0); + return lp_build_undef(gallivm, type); +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c new file mode 100644 index 0000000..0a57b3c --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c @@ -0,0 +1,437 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "pipe/p_defines.h" + +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_string.h" + +#include "lp_bld_type.h" +#include "lp_bld_const.h" +#include "lp_bld_conv.h" +#include "lp_bld_swizzle.h" +#include "lp_bld_gather.h" +#include "lp_bld_debug.h" +#include "lp_bld_format.h" + + +void +lp_build_format_swizzle_soa(const struct util_format_description *format_desc, + struct lp_build_context *bld, + const LLVMValueRef *unswizzled, + LLVMValueRef swizzled_out[4]) +{ + assert(UTIL_FORMAT_SWIZZLE_0 == PIPE_SWIZZLE_ZERO); + assert(UTIL_FORMAT_SWIZZLE_1 == PIPE_SWIZZLE_ONE); + + if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) { + /* + * Return zzz1 for depth-stencil formats. + * + * XXX: Allow to control the depth swizzle with an additional parameter, + * as the caller may wish another depth swizzle, or retain the stencil + * value. + */ + enum util_format_swizzle swizzle = format_desc->swizzle[0]; + LLVMValueRef depth = lp_build_swizzle_soa_channel(bld, unswizzled, swizzle); + swizzled_out[2] = swizzled_out[1] = swizzled_out[0] = depth; + swizzled_out[3] = bld->one; + } + else { + unsigned chan; + for (chan = 0; chan < 4; ++chan) { + enum util_format_swizzle swizzle = format_desc->swizzle[chan]; + swizzled_out[chan] = lp_build_swizzle_soa_channel(bld, unswizzled, swizzle); + } + } +} + + +/** + * Unpack several pixels in SoA. + * + * It takes a vector of packed pixels: + * + * packed = {P0, P1, P2, P3, ..., Pn} + * + * And will produce four vectors: + * + * red = {R0, R1, R2, R3, ..., Rn} + * green = {G0, G1, G2, G3, ..., Gn} + * blue = {B0, B1, B2, B3, ..., Bn} + * alpha = {A0, A1, A2, A3, ..., An} + * + * It requires that a packed pixel fits into an element of the output + * channels. The common case is when converting pixel with a depth of 32 bit or + * less into floats. + * + * \param format_desc the format of the 'packed' incoming pixel vector + * \param type the desired type for rgba_out (type.length = n, above) + * \param packed the incoming vector of packed pixels + * \param rgba_out returns the SoA R,G,B,A vectors + */ +void +lp_build_unpack_rgba_soa(struct gallivm_state *gallivm, + const struct util_format_description *format_desc, + struct lp_type type, + LLVMValueRef packed, + LLVMValueRef rgba_out[4]) +{ + LLVMBuilderRef builder = gallivm->builder; + struct lp_build_context bld; + LLVMValueRef inputs[4]; + unsigned start; + unsigned chan; + + assert(format_desc->layout == UTIL_FORMAT_LAYOUT_PLAIN); + assert(format_desc->block.width == 1); + assert(format_desc->block.height == 1); + assert(format_desc->block.bits <= type.width); + /* FIXME: Support more output types */ + assert(type.floating); + assert(type.width == 32); + + lp_build_context_init(&bld, gallivm, type); + + /* Decode the input vector components */ + start = 0; + for (chan = 0; chan < format_desc->nr_channels; ++chan) { + const unsigned width = format_desc->channel[chan].size; + const unsigned stop = start + width; + LLVMValueRef input; + + input = packed; + + switch(format_desc->channel[chan].type) { + case UTIL_FORMAT_TYPE_VOID: + input = lp_build_undef(gallivm, type); + break; + + case UTIL_FORMAT_TYPE_UNSIGNED: + /* + * Align the LSB + */ + + if (start) { + input = LLVMBuildLShr(builder, input, lp_build_const_int_vec(gallivm, type, start), ""); + } + + /* + * Zero the MSBs + */ + + if (stop < format_desc->block.bits) { + unsigned mask = ((unsigned long long)1 << width) - 1; + input = LLVMBuildAnd(builder, input, lp_build_const_int_vec(gallivm, type, mask), ""); + } + + /* + * Type conversion + */ + + if (type.floating) { + if(format_desc->channel[chan].normalized) + input = lp_build_unsigned_norm_to_float(gallivm, width, type, input); + else + input = LLVMBuildSIToFP(builder, input, + lp_build_vec_type(gallivm, type), ""); + } + else { + /* FIXME */ + assert(0); + input = lp_build_undef(gallivm, type); + } + + break; + + case UTIL_FORMAT_TYPE_SIGNED: + /* + * Align the sign bit first. + */ + + if (stop < type.width) { + unsigned bits = type.width - stop; + LLVMValueRef bits_val = lp_build_const_int_vec(gallivm, type, bits); + input = LLVMBuildShl(builder, input, bits_val, ""); + } + + /* + * Align the LSB (with an arithmetic shift to preserve the sign) + */ + + if (format_desc->channel[chan].size < type.width) { + unsigned bits = type.width - format_desc->channel[chan].size; + LLVMValueRef bits_val = lp_build_const_int_vec(gallivm, type, bits); + input = LLVMBuildAShr(builder, input, bits_val, ""); + } + + /* + * Type conversion + */ + + if (type.floating) { + input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(gallivm, type), ""); + if (format_desc->channel[chan].normalized) { + double scale = 1.0 / ((1 << (format_desc->channel[chan].size - 1)) - 1); + LLVMValueRef scale_val = lp_build_const_vec(gallivm, type, scale); + input = LLVMBuildFMul(builder, input, scale_val, ""); + } + } + else { + /* FIXME */ + assert(0); + input = lp_build_undef(gallivm, type); + } + + break; + + case UTIL_FORMAT_TYPE_FLOAT: + if (type.floating) { + assert(start == 0); + assert(stop == 32); + assert(type.width == 32); + input = LLVMBuildBitCast(builder, input, lp_build_vec_type(gallivm, type), ""); + } + else { + /* FIXME */ + assert(0); + input = lp_build_undef(gallivm, type); + } + break; + + case UTIL_FORMAT_TYPE_FIXED: + if (type.floating) { + double scale = 1.0 / ((1 << (format_desc->channel[chan].size/2)) - 1); + LLVMValueRef scale_val = lp_build_const_vec(gallivm, type, scale); + input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(gallivm, type), ""); + input = LLVMBuildFMul(builder, input, scale_val, ""); + } + else { + /* FIXME */ + assert(0); + input = lp_build_undef(gallivm, type); + } + break; + + default: + assert(0); + input = lp_build_undef(gallivm, type); + break; + } + + inputs[chan] = input; + + start = stop; + } + + lp_build_format_swizzle_soa(format_desc, &bld, inputs, rgba_out); +} + + +void +lp_build_rgba8_to_f32_soa(struct gallivm_state *gallivm, + struct lp_type dst_type, + LLVMValueRef packed, + LLVMValueRef *rgba) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef mask = lp_build_const_int_vec(gallivm, dst_type, 0xff); + unsigned chan; + + packed = LLVMBuildBitCast(builder, packed, + lp_build_int_vec_type(gallivm, dst_type), ""); + + /* Decode the input vector components */ + for (chan = 0; chan < 4; ++chan) { + unsigned start = chan*8; + unsigned stop = start + 8; + LLVMValueRef input; + + input = packed; + + if (start) + input = LLVMBuildLShr(builder, input, + lp_build_const_int_vec(gallivm, dst_type, start), ""); + + if (stop < 32) + input = LLVMBuildAnd(builder, input, mask, ""); + + input = lp_build_unsigned_norm_to_float(gallivm, 8, dst_type, input); + + rgba[chan] = input; + } +} + + + +/** + * Fetch a texels from a texture, returning them in SoA layout. + * + * \param type the desired return type for 'rgba'. The vector length + * is the number of texels to fetch + * + * \param base_ptr points to start of the texture image block. For non- + * compressed formats, this simply points to the texel. + * For compressed formats, it points to the start of the + * compressed data block. + * + * \param i, j the sub-block pixel coordinates. For non-compressed formats + * these will always be (0,0). For compressed formats, i will + * be in [0, block_width-1] and j will be in [0, block_height-1]. + */ +void +lp_build_fetch_rgba_soa(struct gallivm_state *gallivm, + const struct util_format_description *format_desc, + struct lp_type type, + LLVMValueRef base_ptr, + LLVMValueRef offset, + LLVMValueRef i, + LLVMValueRef j, + LLVMValueRef rgba_out[4]) +{ + LLVMBuilderRef builder = gallivm->builder; + + if (format_desc->layout == UTIL_FORMAT_LAYOUT_PLAIN && + (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB || + format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) && + format_desc->block.width == 1 && + format_desc->block.height == 1 && + format_desc->block.bits <= type.width && + (format_desc->channel[0].type != UTIL_FORMAT_TYPE_FLOAT || + format_desc->channel[0].size == 32)) + { + /* + * The packed pixel fits into an element of the destination format. Put + * the packed pixels into a vector and extract each component for all + * vector elements in parallel. + */ + + LLVMValueRef packed; + + /* + * gather the texels from the texture + * Ex: packed = {BGRA, BGRA, BGRA, BGRA}. + */ + packed = lp_build_gather(gallivm, + type.length, + format_desc->block.bits, + type.width, + base_ptr, offset); + + /* + * convert texels to float rgba + */ + lp_build_unpack_rgba_soa(gallivm, + format_desc, + type, + packed, rgba_out); + return; + } + + /* + * Try calling lp_build_fetch_rgba_aos for all pixels. + */ + + if (util_format_fits_8unorm(format_desc) && + type.floating && type.width == 32 && type.length == 4) { + struct lp_type tmp_type; + LLVMValueRef tmp; + + memset(&tmp_type, 0, sizeof tmp_type); + tmp_type.width = 8; + tmp_type.length = type.length * 4; + tmp_type.norm = TRUE; + + tmp = lp_build_fetch_rgba_aos(gallivm, format_desc, tmp_type, + base_ptr, offset, i, j); + + lp_build_rgba8_to_f32_soa(gallivm, + type, + tmp, + rgba_out); + + return; + } + + /* + * Fallback to calling lp_build_fetch_rgba_aos for each pixel. + * + * This is not the most efficient way of fetching pixels, as we + * miss some opportunities to do vectorization, but this is + * convenient for formats or scenarios for which there was no + * opportunity or incentive to optimize. + */ + + { + unsigned k, chan; + struct lp_type tmp_type; + + if (gallivm_debug & GALLIVM_DEBUG_PERF) { + debug_printf("%s: scalar unpacking of %s\n", + __FUNCTION__, format_desc->short_name); + } + + tmp_type = type; + tmp_type.length = 4; + + for (chan = 0; chan < 4; ++chan) { + rgba_out[chan] = lp_build_undef(gallivm, type); + } + + /* loop over number of pixels */ + for(k = 0; k < type.length; ++k) { + LLVMValueRef index = lp_build_const_int32(gallivm, k); + LLVMValueRef offset_elem; + LLVMValueRef i_elem, j_elem; + LLVMValueRef tmp; + + offset_elem = LLVMBuildExtractElement(builder, offset, + index, ""); + + i_elem = LLVMBuildExtractElement(builder, i, index, ""); + j_elem = LLVMBuildExtractElement(builder, j, index, ""); + + /* Get a single float[4]={R,G,B,A} pixel */ + tmp = lp_build_fetch_rgba_aos(gallivm, format_desc, tmp_type, + base_ptr, offset_elem, + i_elem, j_elem); + + /* + * Insert the AoS tmp value channels into the SoA result vectors at + * position = 'index'. + */ + for (chan = 0; chan < 4; ++chan) { + LLVMValueRef chan_val = lp_build_const_int32(gallivm, chan), + tmp_chan = LLVMBuildExtractElement(builder, tmp, chan_val, ""); + rgba_out[chan] = LLVMBuildInsertElement(builder, rgba_out[chan], + tmp_chan, index, ""); + } + } + } +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_yuv.c b/src/gallium/auxiliary/gallivm/lp_bld_format_yuv.c new file mode 100644 index 0000000..cdf1956 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_format_yuv.c @@ -0,0 +1,450 @@ +/************************************************************************** + * + * 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 + * YUV pixel format manipulation. + * + * @author Jose Fonseca + */ + + +#include "util/u_format.h" +#include "util/u_cpu_detect.h" + +#include "lp_bld_arit.h" +#include "lp_bld_type.h" +#include "lp_bld_const.h" +#include "lp_bld_conv.h" +#include "lp_bld_gather.h" +#include "lp_bld_format.h" +#include "lp_bld_init.h" +#include "lp_bld_logic.h" + +/** + * Extract Y, U, V channels from packed UYVY. + * @param packed is a vector with the packed UYVY blocks + * @param i is a vector with the x pixel coordinate (0 or 1) + */ +static void +uyvy_to_yuv_soa(struct gallivm_state *gallivm, + unsigned n, + LLVMValueRef packed, + LLVMValueRef i, + LLVMValueRef *y, + LLVMValueRef *u, + LLVMValueRef *v) +{ + LLVMBuilderRef builder = gallivm->builder; + struct lp_type type; + LLVMValueRef mask; + + memset(&type, 0, sizeof type); + type.width = 32; + type.length = n; + + assert(lp_check_value(type, packed)); + assert(lp_check_value(type, i)); + + /* + * y = (uyvy >> (16*i + 8)) & 0xff + * u = (uyvy ) & 0xff + * v = (uyvy >> 16 ) & 0xff + */ + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) + /* + * Avoid shift with per-element count. + * No support on x86, gets translated to roughly 5 instructions + * per element. Didn't measure performance but cuts shader size + * by quite a bit (less difference if cpu has no sse4.1 support). + */ + if (util_cpu_caps.has_sse2 && n == 4) { + LLVMValueRef sel, tmp, tmp2; + struct lp_build_context bld32; + + lp_build_context_init(&bld32, gallivm, type); + + tmp = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 8), ""); + tmp2 = LLVMBuildLShr(builder, tmp, lp_build_const_int_vec(gallivm, type, 16), ""); + sel = lp_build_compare(gallivm, type, PIPE_FUNC_EQUAL, i, lp_build_const_int_vec(gallivm, type, 0)); + *y = lp_build_select(&bld32, sel, tmp, tmp2); + } else +#endif + { + LLVMValueRef shift; + shift = LLVMBuildMul(builder, i, lp_build_const_int_vec(gallivm, type, 16), ""); + shift = LLVMBuildAdd(builder, shift, lp_build_const_int_vec(gallivm, type, 8), ""); + *y = LLVMBuildLShr(builder, packed, shift, ""); + } + + *u = packed; + *v = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 16), ""); + + mask = lp_build_const_int_vec(gallivm, type, 0xff); + + *y = LLVMBuildAnd(builder, *y, mask, "y"); + *u = LLVMBuildAnd(builder, *u, mask, "u"); + *v = LLVMBuildAnd(builder, *v, mask, "v"); +} + + +/** + * Extract Y, U, V channels from packed YUYV. + * @param packed is a vector with the packed YUYV blocks + * @param i is a vector with the x pixel coordinate (0 or 1) + */ +static void +yuyv_to_yuv_soa(struct gallivm_state *gallivm, + unsigned n, + LLVMValueRef packed, + LLVMValueRef i, + LLVMValueRef *y, + LLVMValueRef *u, + LLVMValueRef *v) +{ + LLVMBuilderRef builder = gallivm->builder; + struct lp_type type; + LLVMValueRef mask; + + memset(&type, 0, sizeof type); + type.width = 32; + type.length = n; + + assert(lp_check_value(type, packed)); + assert(lp_check_value(type, i)); + + /* + * y = (yuyv >> 16*i) & 0xff + * u = (yuyv >> 8 ) & 0xff + * v = (yuyv >> 24 ) & 0xff + */ + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) + /* + * Avoid shift with per-element count. + * No support on x86, gets translated to roughly 5 instructions + * per element. Didn't measure performance but cuts shader size + * by quite a bit (less difference if cpu has no sse4.1 support). + */ + if (util_cpu_caps.has_sse2 && n == 4) { + LLVMValueRef sel, tmp; + struct lp_build_context bld32; + + lp_build_context_init(&bld32, gallivm, type); + + tmp = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 16), ""); + sel = lp_build_compare(gallivm, type, PIPE_FUNC_EQUAL, i, lp_build_const_int_vec(gallivm, type, 0)); + *y = lp_build_select(&bld32, sel, packed, tmp); + } else +#endif + { + LLVMValueRef shift; + shift = LLVMBuildMul(builder, i, lp_build_const_int_vec(gallivm, type, 16), ""); + *y = LLVMBuildLShr(builder, packed, shift, ""); + } + + *u = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 8), ""); + *v = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 24), ""); + + mask = lp_build_const_int_vec(gallivm, type, 0xff); + + *y = LLVMBuildAnd(builder, *y, mask, "y"); + *u = LLVMBuildAnd(builder, *u, mask, "u"); + *v = LLVMBuildAnd(builder, *v, mask, "v"); +} + + +static INLINE void +yuv_to_rgb_soa(struct gallivm_state *gallivm, + unsigned n, + LLVMValueRef y, LLVMValueRef u, LLVMValueRef v, + LLVMValueRef *r, LLVMValueRef *g, LLVMValueRef *b) +{ + LLVMBuilderRef builder = gallivm->builder; + struct lp_type type; + struct lp_build_context bld; + + LLVMValueRef c0; + LLVMValueRef c8; + LLVMValueRef c16; + LLVMValueRef c128; + LLVMValueRef c255; + + LLVMValueRef cy; + LLVMValueRef cug; + LLVMValueRef cub; + LLVMValueRef cvr; + LLVMValueRef cvg; + + memset(&type, 0, sizeof type); + type.sign = TRUE; + type.width = 32; + type.length = n; + + lp_build_context_init(&bld, gallivm, type); + + assert(lp_check_value(type, y)); + assert(lp_check_value(type, u)); + assert(lp_check_value(type, v)); + + /* + * Constants + */ + + c0 = lp_build_const_int_vec(gallivm, type, 0); + c8 = lp_build_const_int_vec(gallivm, type, 8); + c16 = lp_build_const_int_vec(gallivm, type, 16); + c128 = lp_build_const_int_vec(gallivm, type, 128); + c255 = lp_build_const_int_vec(gallivm, type, 255); + + cy = lp_build_const_int_vec(gallivm, type, 298); + cug = lp_build_const_int_vec(gallivm, type, -100); + cub = lp_build_const_int_vec(gallivm, type, 516); + cvr = lp_build_const_int_vec(gallivm, type, 409); + cvg = lp_build_const_int_vec(gallivm, type, -208); + + /* + * y -= 16; + * u -= 128; + * v -= 128; + */ + + y = LLVMBuildSub(builder, y, c16, ""); + u = LLVMBuildSub(builder, u, c128, ""); + v = LLVMBuildSub(builder, v, c128, ""); + + /* + * r = 298 * _y + 409 * _v + 128; + * g = 298 * _y - 100 * _u - 208 * _v + 128; + * b = 298 * _y + 516 * _u + 128; + */ + + y = LLVMBuildMul(builder, y, cy, ""); + y = LLVMBuildAdd(builder, y, c128, ""); + + *r = LLVMBuildMul(builder, v, cvr, ""); + *g = LLVMBuildAdd(builder, + LLVMBuildMul(builder, u, cug, ""), + LLVMBuildMul(builder, v, cvg, ""), + ""); + *b = LLVMBuildMul(builder, u, cub, ""); + + *r = LLVMBuildAdd(builder, *r, y, ""); + *g = LLVMBuildAdd(builder, *g, y, ""); + *b = LLVMBuildAdd(builder, *b, y, ""); + + /* + * r >>= 8; + * g >>= 8; + * b >>= 8; + */ + + *r = LLVMBuildAShr(builder, *r, c8, "r"); + *g = LLVMBuildAShr(builder, *g, c8, "g"); + *b = LLVMBuildAShr(builder, *b, c8, "b"); + + /* + * Clamp + */ + + *r = lp_build_clamp(&bld, *r, c0, c255); + *g = lp_build_clamp(&bld, *g, c0, c255); + *b = lp_build_clamp(&bld, *b, c0, c255); +} + + +static LLVMValueRef +rgb_to_rgba_aos(struct gallivm_state *gallivm, + unsigned n, + LLVMValueRef r, LLVMValueRef g, LLVMValueRef b) +{ + LLVMBuilderRef builder = gallivm->builder; + struct lp_type type; + LLVMValueRef a; + LLVMValueRef rgba; + + memset(&type, 0, sizeof type); + type.sign = TRUE; + type.width = 32; + type.length = n; + + assert(lp_check_value(type, r)); + assert(lp_check_value(type, g)); + assert(lp_check_value(type, b)); + + /* + * Make a 4 x unorm8 vector + */ + + r = r; + g = LLVMBuildShl(builder, g, lp_build_const_int_vec(gallivm, type, 8), ""); + b = LLVMBuildShl(builder, b, lp_build_const_int_vec(gallivm, type, 16), ""); + a = lp_build_const_int_vec(gallivm, type, 0xff000000); + + rgba = r; + rgba = LLVMBuildOr(builder, rgba, g, ""); + rgba = LLVMBuildOr(builder, rgba, b, ""); + rgba = LLVMBuildOr(builder, rgba, a, ""); + + rgba = LLVMBuildBitCast(builder, rgba, + LLVMVectorType(LLVMInt8TypeInContext(gallivm->context), 4*n), ""); + + return rgba; +} + + +/** + * Convert from packed UYVY to <4n x i8> RGBA AoS + */ +static LLVMValueRef +uyvy_to_rgba_aos(struct gallivm_state *gallivm, + unsigned n, + LLVMValueRef packed, + LLVMValueRef i) +{ + LLVMValueRef y, u, v; + LLVMValueRef r, g, b; + LLVMValueRef rgba; + + uyvy_to_yuv_soa(gallivm, n, packed, i, &y, &u, &v); + yuv_to_rgb_soa(gallivm, n, y, u, v, &r, &g, &b); + rgba = rgb_to_rgba_aos(gallivm, n, r, g, b); + + return rgba; +} + + +/** + * Convert from packed YUYV to <4n x i8> RGBA AoS + */ +static LLVMValueRef +yuyv_to_rgba_aos(struct gallivm_state *gallivm, + unsigned n, + LLVMValueRef packed, + LLVMValueRef i) +{ + LLVMValueRef y, u, v; + LLVMValueRef r, g, b; + LLVMValueRef rgba; + + yuyv_to_yuv_soa(gallivm, n, packed, i, &y, &u, &v); + yuv_to_rgb_soa(gallivm, n, y, u, v, &r, &g, &b); + rgba = rgb_to_rgba_aos(gallivm, n, r, g, b); + + return rgba; +} + + +/** + * Convert from packed RG_BG to <4n x i8> RGBA AoS + */ +static LLVMValueRef +rgbg_to_rgba_aos(struct gallivm_state *gallivm, + unsigned n, + LLVMValueRef packed, + LLVMValueRef i) +{ + LLVMValueRef r, g, b; + LLVMValueRef rgba; + + uyvy_to_yuv_soa(gallivm, n, packed, i, &g, &r, &b); + rgba = rgb_to_rgba_aos(gallivm, n, r, g, b); + + return rgba; +} + + +/** + * Convert from packed GR_GB to <4n x i8> RGBA AoS + */ +static LLVMValueRef +grgb_to_rgba_aos(struct gallivm_state *gallivm, + unsigned n, + LLVMValueRef packed, + LLVMValueRef i) +{ + LLVMValueRef r, g, b; + LLVMValueRef rgba; + + yuyv_to_yuv_soa(gallivm, n, packed, i, &g, &r, &b); + rgba = rgb_to_rgba_aos(gallivm, n, r, g, b); + + return rgba; +} + + +/** + * @param n is the number of pixels processed + * @param packed is a vector with the packed YUYV blocks + * @param i is a vector with the x pixel coordinate (0 or 1) + * @return a <4*n x i8> vector with the pixel RGBA values in AoS + */ +LLVMValueRef +lp_build_fetch_subsampled_rgba_aos(struct gallivm_state *gallivm, + const struct util_format_description *format_desc, + unsigned n, + LLVMValueRef base_ptr, + LLVMValueRef offset, + LLVMValueRef i, + LLVMValueRef j) +{ + LLVMValueRef packed; + LLVMValueRef rgba; + + assert(format_desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED); + assert(format_desc->block.bits == 32); + assert(format_desc->block.width == 2); + assert(format_desc->block.height == 1); + + packed = lp_build_gather(gallivm, n, 32, 32, base_ptr, offset); + + (void)j; + + switch (format_desc->format) { + case PIPE_FORMAT_UYVY: + rgba = uyvy_to_rgba_aos(gallivm, n, packed, i); + break; + case PIPE_FORMAT_YUYV: + rgba = yuyv_to_rgba_aos(gallivm, n, packed, i); + break; + case PIPE_FORMAT_R8G8_B8G8_UNORM: + rgba = rgbg_to_rgba_aos(gallivm, n, packed, i); + break; + case PIPE_FORMAT_G8R8_G8B8_UNORM: + rgba = grgb_to_rgba_aos(gallivm, n, packed, i); + break; + default: + assert(0); + rgba = LLVMGetUndef(LLVMVectorType(LLVMInt8TypeInContext(gallivm->context), 4*n)); + break; + } + + return rgba; +} + diff --git a/src/gallium/auxiliary/gallivm/lp_bld_gather.c b/src/gallium/auxiliary/gallivm/lp_bld_gather.c new file mode 100644 index 0000000..0dc81b1 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_gather.c @@ -0,0 +1,149 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "util/u_debug.h" +#include "lp_bld_debug.h" +#include "lp_bld_const.h" +#include "lp_bld_format.h" +#include "lp_bld_gather.h" +#include "lp_bld_init.h" + + +/** + * Get the pointer to one element from scatter positions in memory. + * + * @sa lp_build_gather() + */ +LLVMValueRef +lp_build_gather_elem_ptr(struct gallivm_state *gallivm, + unsigned length, + LLVMValueRef base_ptr, + LLVMValueRef offsets, + unsigned i) +{ + LLVMValueRef offset; + LLVMValueRef ptr; + + assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0)); + + if (length == 1) { + assert(i == 0); + offset = offsets; + } else { + LLVMValueRef index = lp_build_const_int32(gallivm, i); + offset = LLVMBuildExtractElement(gallivm->builder, offsets, index, ""); + } + + ptr = LLVMBuildGEP(gallivm->builder, base_ptr, &offset, 1, ""); + + return ptr; +} + + +/** + * Gather one element from scatter positions in memory. + * + * @sa lp_build_gather() + */ +LLVMValueRef +lp_build_gather_elem(struct gallivm_state *gallivm, + unsigned length, + unsigned src_width, + unsigned dst_width, + LLVMValueRef base_ptr, + LLVMValueRef offsets, + unsigned i) +{ + LLVMTypeRef src_type = LLVMIntTypeInContext(gallivm->context, src_width); + LLVMTypeRef src_ptr_type = LLVMPointerType(src_type, 0); + LLVMTypeRef dst_elem_type = LLVMIntTypeInContext(gallivm->context, dst_width); + LLVMValueRef ptr; + LLVMValueRef res; + + assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0)); + + ptr = lp_build_gather_elem_ptr(gallivm, length, base_ptr, offsets, i); + ptr = LLVMBuildBitCast(gallivm->builder, ptr, src_ptr_type, ""); + res = LLVMBuildLoad(gallivm->builder, ptr, ""); + + assert(src_width <= dst_width); + if (src_width > dst_width) + res = LLVMBuildTrunc(gallivm->builder, res, dst_elem_type, ""); + if (src_width < dst_width) + res = LLVMBuildZExt(gallivm->builder, res, dst_elem_type, ""); + + return res; +} + + +/** + * Gather elements from scatter positions in memory into a single vector. + * Use for fetching texels from a texture. + * For SSE, typical values are length=4, src_width=32, dst_width=32. + * + * @param length length of the offsets + * @param src_width src element width in bits + * @param dst_width result element width in bits (src will be expanded to fit) + * @param base_ptr base pointer, should be a i8 pointer type. + * @param offsets vector with offsets + */ +LLVMValueRef +lp_build_gather(struct gallivm_state *gallivm, + unsigned length, + unsigned src_width, + unsigned dst_width, + LLVMValueRef base_ptr, + LLVMValueRef offsets) +{ + LLVMValueRef res; + + if (length == 1) { + /* Scalar */ + return lp_build_gather_elem(gallivm, length, + src_width, dst_width, + base_ptr, offsets, 0); + } else { + /* Vector */ + + LLVMTypeRef dst_elem_type = LLVMIntTypeInContext(gallivm->context, dst_width); + LLVMTypeRef dst_vec_type = LLVMVectorType(dst_elem_type, length); + unsigned i; + + res = LLVMGetUndef(dst_vec_type); + for (i = 0; i < length; ++i) { + LLVMValueRef index = lp_build_const_int32(gallivm, i); + LLVMValueRef elem; + elem = lp_build_gather_elem(gallivm, length, + src_width, dst_width, + base_ptr, offsets, i); + res = LLVMBuildInsertElement(gallivm->builder, res, elem, index, ""); + } + } + + return res; +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_gather.h b/src/gallium/auxiliary/gallivm/lp_bld_gather.h new file mode 100644 index 0000000..5b04131 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_gather.h @@ -0,0 +1,61 @@ +/************************************************************************** + * + * 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 LP_BLD_GATHER_H_ +#define LP_BLD_GATHER_H_ + + +#include "gallivm/lp_bld.h" + + +LLVMValueRef +lp_build_gather_elem_ptr(struct gallivm_state *gallivm, + unsigned length, + LLVMValueRef base_ptr, + LLVMValueRef offsets, + unsigned i); + +LLVMValueRef +lp_build_gather_elem(struct gallivm_state *gallivm, + unsigned length, + unsigned src_width, + unsigned dst_width, + LLVMValueRef base_ptr, + LLVMValueRef offsets, + unsigned i); + +LLVMValueRef +lp_build_gather(struct gallivm_state *gallivm, + unsigned length, + unsigned src_width, + unsigned dst_width, + LLVMValueRef base_ptr, + LLVMValueRef offsets); + + +#endif /* LP_BLD_GATHER_H_ */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c new file mode 100644 index 0000000..efe8d38 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c @@ -0,0 +1,454 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "pipe/p_compiler.h" +#include "util/u_cpu_detect.h" +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "lp_bld_debug.h" +#include "lp_bld_init.h" + +#include + + +#ifdef DEBUG +unsigned gallivm_debug = 0; + +static const struct debug_named_value lp_bld_debug_flags[] = { + { "tgsi", GALLIVM_DEBUG_TGSI, NULL }, + { "ir", GALLIVM_DEBUG_IR, NULL }, + { "asm", GALLIVM_DEBUG_ASM, NULL }, + { "nopt", GALLIVM_DEBUG_NO_OPT, NULL }, + { "perf", GALLIVM_DEBUG_PERF, NULL }, + { "no_brilinear", GALLIVM_DEBUG_NO_BRILINEAR, NULL }, + { "gc", GALLIVM_DEBUG_GC, NULL }, + DEBUG_NAMED_VALUE_END +}; + +DEBUG_GET_ONCE_FLAGS_OPTION(gallivm_debug, "GALLIVM_DEBUG", lp_bld_debug_flags, 0) +#endif + + +static boolean gallivm_initialized = FALSE; + + +/* + * Optimization values are: + * - 0: None (-O0) + * - 1: Less (-O1) + * - 2: Default (-O2, -Os) + * - 3: Aggressive (-O3) + * + * See also CodeGenOpt::Level in llvm/Target/TargetMachine.h + */ +enum LLVM_CodeGenOpt_Level { +#if HAVE_LLVM >= 0x207 + None, // -O0 + Less, // -O1 + Default, // -O2, -Os + Aggressive // -O3 +#else + Default, + None, + Aggressive +#endif +}; + + +/** + * LLVM 2.6 permits only one ExecutionEngine to be created. This is it. + */ +static LLVMExecutionEngineRef GlobalEngine = NULL; + +/** + * Same gallivm state shared by all contexts. + */ +static struct gallivm_state *GlobalGallivm = NULL; + + + + +extern void +lp_register_oprofile_jit_event_listener(LLVMExecutionEngineRef EE); + +extern void +lp_set_target_options(void); + + + +/** + * Create the LLVM (optimization) pass manager and install + * relevant optimization passes. + * \return TRUE for success, FALSE for failure + */ +static boolean +create_pass_manager(struct gallivm_state *gallivm) +{ + assert(!gallivm->passmgr); + + gallivm->passmgr = LLVMCreateFunctionPassManager(gallivm->provider); + if (!gallivm->passmgr) + return FALSE; + + LLVMAddTargetData(gallivm->target, gallivm->passmgr); + + if ((gallivm_debug & GALLIVM_DEBUG_NO_OPT) == 0) { + /* These are the passes currently listed in llvm-c/Transforms/Scalar.h, + * but there are more on SVN. + * TODO: Add more passes. + */ + LLVMAddCFGSimplificationPass(gallivm->passmgr); + + if (HAVE_LLVM >= 0x207 && sizeof(void*) == 4) { + /* For LLVM >= 2.7 and 32-bit build, use this order of passes to + * avoid generating bad code. + * Test with piglit glsl-vs-sqrt-zero test. + */ + LLVMAddConstantPropagationPass(gallivm->passmgr); + LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr); + } + else { + LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr); + LLVMAddConstantPropagationPass(gallivm->passmgr); + } + + if (util_cpu_caps.has_sse4_1) { + /* FIXME: There is a bug in this pass, whereby the combination + * of fptosi and sitofp (necessary for trunc/floor/ceil/round + * implementation) somehow becomes invalid code. + */ + LLVMAddInstructionCombiningPass(gallivm->passmgr); + } + LLVMAddGVNPass(gallivm->passmgr); + } + else { + /* We need at least this pass to prevent the backends to fail in + * unexpected ways. + */ + LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr); + } + + return TRUE; +} + + +/** + * Free gallivm object's LLVM allocations, but not the gallivm object itself. + */ +static void +free_gallivm_state(struct gallivm_state *gallivm) +{ +#if HAVE_LLVM >= 0x207 /* XXX or 0x208? */ + /* This leads to crashes w/ some versions of LLVM */ + LLVMModuleRef mod; + char *error; + + if (gallivm->engine && gallivm->provider) + LLVMRemoveModuleProvider(gallivm->engine, gallivm->provider, + &mod, &error); +#endif + +#if 0 + /* XXX this seems to crash with all versions of LLVM */ + if (gallivm->provider) + LLVMDisposeModuleProvider(gallivm->provider); +#endif + + if (gallivm->passmgr) + LLVMDisposePassManager(gallivm->passmgr); + +#if HAVE_LLVM >= 0x207 + if (gallivm->module) + LLVMDisposeModule(gallivm->module); +#endif + +#if 0 + /* Don't free the exec engine, it's a global/singleton */ + if (gallivm->engine) + LLVMDisposeExecutionEngine(gallivm->engine); +#endif + +#if 0 + /* Don't free the TargetData, it's owned by the exec engine */ + LLVMDisposeTargetData(gallivm->target); +#endif + + if (gallivm->context) + LLVMContextDispose(gallivm->context); + + if (gallivm->builder) + LLVMDisposeBuilder(gallivm->builder); + + gallivm->engine = NULL; + gallivm->target = NULL; + gallivm->module = NULL; + gallivm->provider = NULL; + gallivm->passmgr = NULL; + gallivm->context = NULL; + gallivm->builder = NULL; +} + + +/** + * Allocate gallivm LLVM objects. + * \return TRUE for success, FALSE for failure + */ +static boolean +init_gallivm_state(struct gallivm_state *gallivm) +{ + assert(gallivm_initialized); + assert(!gallivm->context); + assert(!gallivm->module); + assert(!gallivm->provider); + + gallivm->context = LLVMContextCreate(); + if (!gallivm->context) + goto fail; + + gallivm->module = LLVMModuleCreateWithNameInContext("gallivm", + gallivm->context); + if (!gallivm->module) + goto fail; + + gallivm->provider = + LLVMCreateModuleProviderForExistingModule(gallivm->module); + if (!gallivm->provider) + goto fail; + + if (!GlobalEngine) { + /* We can only create one LLVMExecutionEngine (w/ LLVM 2.6 anyway) */ + enum LLVM_CodeGenOpt_Level optlevel; + char *error = NULL; + + if (gallivm_debug & GALLIVM_DEBUG_NO_OPT) { + optlevel = None; + } + else { + optlevel = Default; + } + + if (LLVMCreateJITCompiler(&GlobalEngine, gallivm->provider, + (unsigned) optlevel, &error)) { + _debug_printf("%s\n", error); + LLVMDisposeMessage(error); + goto fail; + } + +#if defined(DEBUG) || defined(PROFILE) + lp_register_oprofile_jit_event_listener(GlobalEngine); +#endif + } + + gallivm->engine = GlobalEngine; + + LLVMAddModuleProvider(gallivm->engine, gallivm->provider);//new + + gallivm->target = LLVMGetExecutionEngineTargetData(gallivm->engine); + if (!gallivm->target) + goto fail; + + if (!create_pass_manager(gallivm)) + goto fail; + + gallivm->builder = LLVMCreateBuilderInContext(gallivm->context); + if (!gallivm->builder) + goto fail; + + return TRUE; + +fail: + free_gallivm_state(gallivm); + return FALSE; +} + + +struct callback +{ + garbage_collect_callback_func func; + void *cb_data; +}; + + +#define MAX_CALLBACKS 32 +static struct callback Callbacks[MAX_CALLBACKS]; +static unsigned NumCallbacks = 0; + + +/** + * Register a function with gallivm which will be called when we + * do garbage collection. + */ +void +gallivm_register_garbage_collector_callback(garbage_collect_callback_func func, + void *cb_data) +{ + unsigned i; + + for (i = 0; i < NumCallbacks; i++) { + if (Callbacks[i].func == func && Callbacks[i].cb_data == cb_data) { + /* already in list: no-op */ + return; + } + } + + assert(NumCallbacks < MAX_CALLBACKS); + if (NumCallbacks < MAX_CALLBACKS) { + Callbacks[NumCallbacks].func = func; + Callbacks[NumCallbacks].cb_data = cb_data; + NumCallbacks++; + } +} + + +/** + * Remove a callback. + */ +void +gallivm_remove_garbage_collector_callback(garbage_collect_callback_func func, + void *cb_data) +{ + unsigned i; + + for (i = 0; i < NumCallbacks; i++) { + if (Callbacks[i].func == func && Callbacks[i].cb_data == cb_data) { + /* found, now remove it */ + NumCallbacks--; + for ( ; i < NumCallbacks; i++) { + Callbacks[i] = Callbacks[i + 1]; + } + return; + } + } +} + + +/** + * Call the callback functions (which are typically in the + * draw module and llvmpipe driver. + */ +static void +call_garbage_collector_callbacks(void) +{ + unsigned i; + + for (i = 0; i < NumCallbacks; i++) { + Callbacks[i].func(Callbacks[i].cb_data); + } +} + + + +/** + * Other gallium components using gallivm should call this periodically + * to let us do garbage collection (or at least try to free memory + * accumulated by the LLVM libraries). + */ +void +gallivm_garbage_collect(struct gallivm_state *gallivm) +{ + if (gallivm->context) { + if (gallivm_debug & GALLIVM_DEBUG_GC) + debug_printf("***** Doing LLVM garbage collection\n"); + + call_garbage_collector_callbacks(); + free_gallivm_state(gallivm); + init_gallivm_state(gallivm); + } +} + + +void +lp_build_init(void) +{ +#ifdef DEBUG + gallivm_debug = debug_get_option_gallivm_debug(); +#endif + + lp_set_target_options(); + + LLVMInitializeNativeTarget(); + + LLVMLinkInJIT(); + + util_cpu_detect(); + + gallivm_initialized = TRUE; + +#if 0 + /* For simulating less capable machines */ + util_cpu_caps.has_sse3 = 0; + util_cpu_caps.has_ssse3 = 0; + util_cpu_caps.has_sse4_1 = 0; +#endif +} + + + +/** + * Create a new gallivm_state object. + * Note that we return a singleton. + */ +struct gallivm_state * +gallivm_create(void) +{ + if (!GlobalGallivm) { + GlobalGallivm = CALLOC_STRUCT(gallivm_state); + if (GlobalGallivm) { + if (!init_gallivm_state(GlobalGallivm)) { + FREE(GlobalGallivm); + GlobalGallivm = NULL; + } + } + } + return GlobalGallivm; +} + + +/** + * Destroy a gallivm_state object. + */ +void +gallivm_destroy(struct gallivm_state *gallivm) +{ + /* No-op: don't destroy the singleton */ + (void) gallivm; +} + + + +/* + * Hack to allow the linking of release LLVM static libraries on a debug build. + * + * See also: + * - http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/7234ea2b-0042-42ed-b4e2-5d8644dfb57d + */ +#if defined(_MSC_VER) && defined(_DEBUG) +#include +_CRTIMP void __cdecl +_invalid_parameter_noinfo(void) {} +#endif diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h b/src/gallium/auxiliary/gallivm/lp_bld_init.h new file mode 100644 index 0000000..f68bf75 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h @@ -0,0 +1,85 @@ +/************************************************************************** + * + * 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 LP_BLD_INIT_H +#define LP_BLD_INIT_H + + +#include "pipe/p_compiler.h" +#include "lp_bld.h" +#include + + +struct gallivm_state +{ + LLVMModuleRef module; + LLVMExecutionEngineRef engine; + LLVMModuleProviderRef provider; + LLVMTargetDataRef target; + LLVMPassManagerRef passmgr; + LLVMContextRef context; + LLVMBuilderRef builder; +}; + + +void +lp_build_init(void); + + +extern void +lp_func_delete_body(LLVMValueRef func); + + +void +gallivm_garbage_collect(struct gallivm_state *gallivm); + + +typedef void (*garbage_collect_callback_func)(void *cb_data); + +void +gallivm_register_garbage_collector_callback(garbage_collect_callback_func func, + void *cb_data); + +void +gallivm_remove_garbage_collector_callback(garbage_collect_callback_func func, + void *cb_data); + + +struct gallivm_state * +gallivm_create(void); + +void +gallivm_destroy(struct gallivm_state *gallivm); + + +extern LLVMValueRef +lp_build_load_volatile(LLVMBuilderRef B, LLVMValueRef PointerVal, + const char *Name); + + +#endif /* !LP_BLD_INIT_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.c b/src/gallium/auxiliary/gallivm/lp_bld_intr.c new file mode 100644 index 0000000..518a01f --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.c @@ -0,0 +1,194 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * @file + * Helpers for emiting intrinsic calls. + * + * LLVM vanilla IR doesn't represent all basic arithmetic operations we care + * about, and it is often necessary to resort target-specific intrinsics for + * performance, convenience. + * + * Ideally we would like to stay away from target specific intrinsics and + * move all the instruction selection logic into upstream LLVM where it belongs. + * + * These functions are also used for calling C functions provided by us from + * generated LLVM code. + * + * @author Jose Fonseca + */ + + +#include "util/u_debug.h" + +#include "lp_bld_const.h" +#include "lp_bld_intr.h" + + +LLVMValueRef +lp_declare_intrinsic(LLVMModuleRef module, + const char *name, + LLVMTypeRef ret_type, + LLVMTypeRef *arg_types, + unsigned num_args) +{ + LLVMTypeRef function_type; + LLVMValueRef function; + + assert(!LLVMGetNamedFunction(module, name)); + + function_type = LLVMFunctionType(ret_type, arg_types, num_args, 0); + function = LLVMAddFunction(module, name, function_type); + + LLVMSetFunctionCallConv(function, LLVMCCallConv); + LLVMSetLinkage(function, LLVMExternalLinkage); + + assert(LLVMIsDeclaration(function)); + + if(name[0] == 'l' && + name[1] == 'l' && + name[2] == 'v' && + name[3] == 'm' && + name[4] == '.') + assert(LLVMGetIntrinsicID(function)); + + return function; +} + + +LLVMValueRef +lp_build_intrinsic(LLVMBuilderRef builder, + const char *name, + LLVMTypeRef ret_type, + LLVMValueRef *args, + unsigned num_args) +{ + LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder))); + LLVMValueRef function; + + function = LLVMGetNamedFunction(module, name); + if(!function) { + LLVMTypeRef arg_types[LP_MAX_FUNC_ARGS]; + unsigned i; + + assert(num_args <= LP_MAX_FUNC_ARGS); + + for(i = 0; i < num_args; ++i) { + assert(args[i]); + arg_types[i] = LLVMTypeOf(args[i]); + } + + function = lp_declare_intrinsic(module, name, ret_type, arg_types, num_args); + } + + return LLVMBuildCall(builder, function, args, num_args, ""); +} + + +LLVMValueRef +lp_build_intrinsic_unary(LLVMBuilderRef builder, + const char *name, + LLVMTypeRef ret_type, + LLVMValueRef a) +{ + return lp_build_intrinsic(builder, name, ret_type, &a, 1); +} + + +LLVMValueRef +lp_build_intrinsic_binary(LLVMBuilderRef builder, + const char *name, + LLVMTypeRef ret_type, + LLVMValueRef a, + LLVMValueRef b) +{ + LLVMValueRef args[2]; + + args[0] = a; + args[1] = b; + + return lp_build_intrinsic(builder, name, ret_type, args, 2); +} + + +LLVMValueRef +lp_build_intrinsic_map(struct gallivm_state *gallivm, + const char *name, + LLVMTypeRef ret_type, + LLVMValueRef *args, + unsigned num_args) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMTypeRef ret_elem_type = LLVMGetElementType(ret_type); + unsigned n = LLVMGetVectorSize(ret_type); + unsigned i, j; + LLVMValueRef res; + + assert(num_args <= LP_MAX_FUNC_ARGS); + + res = LLVMGetUndef(ret_type); + for(i = 0; i < n; ++i) { + LLVMValueRef index = lp_build_const_int32(gallivm, i); + LLVMValueRef arg_elems[LP_MAX_FUNC_ARGS]; + LLVMValueRef res_elem; + for(j = 0; j < num_args; ++j) + arg_elems[j] = LLVMBuildExtractElement(builder, args[j], index, ""); + res_elem = lp_build_intrinsic(builder, name, ret_elem_type, arg_elems, num_args); + res = LLVMBuildInsertElement(builder, res, res_elem, index, ""); + } + + return res; +} + + +LLVMValueRef +lp_build_intrinsic_map_unary(struct gallivm_state *gallivm, + const char *name, + LLVMTypeRef ret_type, + LLVMValueRef a) +{ + return lp_build_intrinsic_map(gallivm, name, ret_type, &a, 1); +} + + +LLVMValueRef +lp_build_intrinsic_map_binary(struct gallivm_state *gallivm, + const char *name, + LLVMTypeRef ret_type, + LLVMValueRef a, + LLVMValueRef b) +{ + LLVMValueRef args[2]; + + args[0] = a; + args[1] = b; + + return lp_build_intrinsic_map(gallivm, name, ret_type, args, 2); +} + + diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.h b/src/gallium/auxiliary/gallivm/lp_bld_intr.h new file mode 100644 index 0000000..b73dd70 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.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, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Helper functions for calling intrinsics. + * + * @author Jose Fonseca + */ + + +#ifndef LP_BLD_INTR_H +#define LP_BLD_INTR_H + + +#include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_init.h" + + +/** + * Max number of arguments in an intrinsic. + */ +#define LP_MAX_FUNC_ARGS 32 + + +LLVMValueRef +lp_declare_intrinsic(LLVMModuleRef module, + const char *name, + LLVMTypeRef ret_type, + LLVMTypeRef *arg_types, + unsigned num_args); + +LLVMValueRef +lp_build_intrinsic(LLVMBuilderRef builder, + const char *name, + LLVMTypeRef ret_type, + LLVMValueRef *args, + unsigned num_args); + + +LLVMValueRef +lp_build_intrinsic_unary(LLVMBuilderRef builder, + const char *name, + LLVMTypeRef ret_type, + LLVMValueRef a); + + +LLVMValueRef +lp_build_intrinsic_binary(LLVMBuilderRef builder, + const char *name, + LLVMTypeRef ret_type, + LLVMValueRef a, + LLVMValueRef b); + + +LLVMValueRef +lp_build_intrinsic_map(struct gallivm_state *gallivm, + const char *name, + LLVMTypeRef ret_type, + LLVMValueRef *args, + unsigned num_args); + + +LLVMValueRef +lp_build_intrinsic_map_unary(struct gallivm_state *gallivm, + const char *name, + LLVMTypeRef ret_type, + LLVMValueRef a); + + +LLVMValueRef +lp_build_intrinsic_map_binary(struct gallivm_state *gallivm, + const char *name, + LLVMTypeRef ret_type, + LLVMValueRef a, + LLVMValueRef b); + + +#endif /* !LP_BLD_INTR_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_limits.h b/src/gallium/auxiliary/gallivm/lp_bld_limits.h new file mode 100644 index 0000000..369c812 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_limits.h @@ -0,0 +1,55 @@ +/************************************************************************** + * + * 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 LP_BLD_LIMITS_H_ +#define LP_BLD_LIMITS_H_ + +/* + * TGSI translation limits. + * + * Some are slightly above SM 3.0 requirements to give some wiggle room to + * the state trackers. + */ + +#define LP_MAX_TGSI_TEMPS 256 + +#define LP_MAX_TGSI_ADDRS 16 + +#define LP_MAX_TGSI_IMMEDIATES 256 + +#define LP_MAX_TGSI_PREDS 16 + +/** + * Maximum control flow nesting + * + * SM3.0 requires 24 + */ +#define LP_MAX_TGSI_NESTING 32 + + +#endif /* LP_BLD_LIMITS_H_ */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.c b/src/gallium/auxiliary/gallivm/lp_bld_logic.c new file mode 100644 index 0000000..f7e6fba --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.c @@ -0,0 +1,582 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Helper functions for logical operations. + * + * @author Jose Fonseca + */ + + +#include "util/u_cpu_detect.h" +#include "util/u_memory.h" +#include "util/u_debug.h" + +#include "lp_bld_type.h" +#include "lp_bld_const.h" +#include "lp_bld_init.h" +#include "lp_bld_intr.h" +#include "lp_bld_debug.h" +#include "lp_bld_logic.h" + + +/* + * XXX + * + * Selection with vector conditional like + * + * select <4 x i1> %C, %A, %B + * + * is valid IR (e.g. llvm/test/Assembler/vector-select.ll), but it is not + * supported on any backend. + * + * Expanding the boolean vector to full SIMD register width, as in + * + * sext <4 x i1> %C to <4 x i32> + * + * is valid and supported (e.g., llvm/test/CodeGen/X86/vec_compare.ll), but + * it causes assertion failures in LLVM 2.6. It appears to work correctly on + * LLVM 2.7. + */ + + +/** + * Build code to compare two values 'a' and 'b' of 'type' using the given func. + * \param func one of PIPE_FUNC_x + * The result values will be 0 for false or ~0 for true. + */ +LLVMValueRef +lp_build_compare(struct gallivm_state *gallivm, + const struct lp_type type, + unsigned func, + LLVMValueRef a, + LLVMValueRef b) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMTypeRef int_vec_type = lp_build_int_vec_type(gallivm, type); + LLVMValueRef zeros = LLVMConstNull(int_vec_type); + LLVMValueRef ones = LLVMConstAllOnes(int_vec_type); + LLVMValueRef cond; + LLVMValueRef res; + + assert(func >= PIPE_FUNC_NEVER); + assert(func <= PIPE_FUNC_ALWAYS); + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + if(func == PIPE_FUNC_NEVER) + return zeros; + if(func == PIPE_FUNC_ALWAYS) + return ones; + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) + /* + * There are no unsigned integer comparison instructions in SSE. + */ + + if (!type.floating && !type.sign && + type.width * type.length == 128 && + util_cpu_caps.has_sse2 && + (func == PIPE_FUNC_LESS || + func == PIPE_FUNC_LEQUAL || + func == PIPE_FUNC_GREATER || + func == PIPE_FUNC_GEQUAL) && + (gallivm_debug & GALLIVM_DEBUG_PERF)) { + debug_printf("%s: inefficient <%u x i%u> unsigned comparison\n", + __FUNCTION__, type.length, type.width); + } +#endif + +#if HAVE_LLVM < 0x0207 +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) + if(type.width * type.length == 128) { + if(type.floating && util_cpu_caps.has_sse) { + /* float[4] comparison */ + LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type); + LLVMValueRef args[3]; + unsigned cc; + boolean swap; + + swap = FALSE; + switch(func) { + case PIPE_FUNC_EQUAL: + cc = 0; + break; + case PIPE_FUNC_NOTEQUAL: + cc = 4; + break; + case PIPE_FUNC_LESS: + cc = 1; + break; + case PIPE_FUNC_LEQUAL: + cc = 2; + break; + case PIPE_FUNC_GREATER: + cc = 1; + swap = TRUE; + break; + case PIPE_FUNC_GEQUAL: + cc = 2; + swap = TRUE; + break; + default: + assert(0); + return lp_build_undef(gallivm, type); + } + + if(swap) { + args[0] = b; + args[1] = a; + } + else { + args[0] = a; + args[1] = b; + } + + args[2] = LLVMConstInt(LLVMInt8TypeInContext(gallivm->context), cc, 0); + res = lp_build_intrinsic(builder, + "llvm.x86.sse.cmp.ps", + vec_type, + args, 3); + res = LLVMBuildBitCast(builder, res, int_vec_type, ""); + return res; + } + else if(util_cpu_caps.has_sse2) { + /* int[4] comparison */ + static const struct { + unsigned swap:1; + unsigned eq:1; + unsigned gt:1; + unsigned not:1; + } table[] = { + {0, 0, 0, 1}, /* PIPE_FUNC_NEVER */ + {1, 0, 1, 0}, /* PIPE_FUNC_LESS */ + {0, 1, 0, 0}, /* PIPE_FUNC_EQUAL */ + {0, 0, 1, 1}, /* PIPE_FUNC_LEQUAL */ + {0, 0, 1, 0}, /* PIPE_FUNC_GREATER */ + {0, 1, 0, 1}, /* PIPE_FUNC_NOTEQUAL */ + {1, 0, 1, 1}, /* PIPE_FUNC_GEQUAL */ + {0, 0, 0, 0} /* PIPE_FUNC_ALWAYS */ + }; + const char *pcmpeq; + const char *pcmpgt; + LLVMValueRef args[2]; + LLVMValueRef res; + LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type); + + switch (type.width) { + case 8: + pcmpeq = "llvm.x86.sse2.pcmpeq.b"; + pcmpgt = "llvm.x86.sse2.pcmpgt.b"; + break; + case 16: + pcmpeq = "llvm.x86.sse2.pcmpeq.w"; + pcmpgt = "llvm.x86.sse2.pcmpgt.w"; + break; + case 32: + pcmpeq = "llvm.x86.sse2.pcmpeq.d"; + pcmpgt = "llvm.x86.sse2.pcmpgt.d"; + break; + default: + assert(0); + return lp_build_undef(gallivm, type); + } + + /* There are no unsigned comparison instructions. So flip the sign bit + * so that the results match. + */ + if (table[func].gt && !type.sign) { + LLVMValueRef msb = lp_build_const_int_vec(gallivm, type, (unsigned long long)1 << (type.width - 1)); + a = LLVMBuildXor(builder, a, msb, ""); + b = LLVMBuildXor(builder, b, msb, ""); + } + + if(table[func].swap) { + args[0] = b; + args[1] = a; + } + else { + args[0] = a; + args[1] = b; + } + + if(table[func].eq) + res = lp_build_intrinsic(builder, pcmpeq, vec_type, args, 2); + else if (table[func].gt) + res = lp_build_intrinsic(builder, pcmpgt, vec_type, args, 2); + else + res = LLVMConstNull(vec_type); + + if(table[func].not) + res = LLVMBuildNot(builder, res, ""); + + return res; + } + } /* if (type.width * type.length == 128) */ +#endif +#endif /* HAVE_LLVM < 0x0207 */ + + /* XXX: It is not clear if we should use the ordered or unordered operators */ + + if(type.floating) { + LLVMRealPredicate op; + switch(func) { + case PIPE_FUNC_NEVER: + op = LLVMRealPredicateFalse; + break; + case PIPE_FUNC_ALWAYS: + op = LLVMRealPredicateTrue; + break; + case PIPE_FUNC_EQUAL: + op = LLVMRealUEQ; + break; + case PIPE_FUNC_NOTEQUAL: + op = LLVMRealUNE; + break; + case PIPE_FUNC_LESS: + op = LLVMRealULT; + break; + case PIPE_FUNC_LEQUAL: + op = LLVMRealULE; + break; + case PIPE_FUNC_GREATER: + op = LLVMRealUGT; + break; + case PIPE_FUNC_GEQUAL: + op = LLVMRealUGE; + break; + default: + assert(0); + return lp_build_undef(gallivm, type); + } + +#if HAVE_LLVM >= 0x0207 + cond = LLVMBuildFCmp(builder, op, a, b, ""); + res = LLVMBuildSExt(builder, cond, int_vec_type, ""); +#else + if (type.length == 1) { + cond = LLVMBuildFCmp(builder, op, a, b, ""); + res = LLVMBuildSExt(builder, cond, int_vec_type, ""); + } + else { + unsigned i; + + res = LLVMGetUndef(int_vec_type); + + debug_printf("%s: warning: using slow element-wise float" + " vector comparison\n", __FUNCTION__); + for (i = 0; i < type.length; ++i) { + LLVMValueRef index = lp_build_const_int32(gallivm, i); + cond = LLVMBuildFCmp(builder, op, + LLVMBuildExtractElement(builder, a, index, ""), + LLVMBuildExtractElement(builder, b, index, ""), + ""); + cond = LLVMBuildSelect(builder, cond, + LLVMConstExtractElement(ones, index), + LLVMConstExtractElement(zeros, index), + ""); + res = LLVMBuildInsertElement(builder, res, cond, index, ""); + } + } +#endif + } + else { + LLVMIntPredicate op; + switch(func) { + case PIPE_FUNC_EQUAL: + op = LLVMIntEQ; + break; + case PIPE_FUNC_NOTEQUAL: + op = LLVMIntNE; + break; + case PIPE_FUNC_LESS: + op = type.sign ? LLVMIntSLT : LLVMIntULT; + break; + case PIPE_FUNC_LEQUAL: + op = type.sign ? LLVMIntSLE : LLVMIntULE; + break; + case PIPE_FUNC_GREATER: + op = type.sign ? LLVMIntSGT : LLVMIntUGT; + break; + case PIPE_FUNC_GEQUAL: + op = type.sign ? LLVMIntSGE : LLVMIntUGE; + break; + default: + assert(0); + return lp_build_undef(gallivm, type); + } + +#if HAVE_LLVM >= 0x0207 + cond = LLVMBuildICmp(builder, op, a, b, ""); + res = LLVMBuildSExt(builder, cond, int_vec_type, ""); +#else + if (type.length == 1) { + cond = LLVMBuildICmp(builder, op, a, b, ""); + res = LLVMBuildSExt(builder, cond, int_vec_type, ""); + } + else { + unsigned i; + + res = LLVMGetUndef(int_vec_type); + + if (gallivm_debug & GALLIVM_DEBUG_PERF) { + debug_printf("%s: using slow element-wise int" + " vector comparison\n", __FUNCTION__); + } + + for(i = 0; i < type.length; ++i) { + LLVMValueRef index = lp_build_const_int32(gallivm, i); + cond = LLVMBuildICmp(builder, op, + LLVMBuildExtractElement(builder, a, index, ""), + LLVMBuildExtractElement(builder, b, index, ""), + ""); + cond = LLVMBuildSelect(builder, cond, + LLVMConstExtractElement(ones, index), + LLVMConstExtractElement(zeros, index), + ""); + res = LLVMBuildInsertElement(builder, res, cond, index, ""); + } + } +#endif + } + + return res; +} + + + +/** + * Build code to compare two values 'a' and 'b' using the given func. + * \param func one of PIPE_FUNC_x + * The result values will be 0 for false or ~0 for true. + */ +LLVMValueRef +lp_build_cmp(struct lp_build_context *bld, + unsigned func, + LLVMValueRef a, + LLVMValueRef b) +{ + return lp_build_compare(bld->gallivm, bld->type, func, a, b); +} + + +/** + * Return (mask & a) | (~mask & b); + */ +LLVMValueRef +lp_build_select_bitwise(struct lp_build_context *bld, + LLVMValueRef mask, + LLVMValueRef a, + LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + struct lp_type type = bld->type; + LLVMValueRef res; + + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + if (a == b) { + return a; + } + + if(type.floating) { + LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type); + a = LLVMBuildBitCast(builder, a, int_vec_type, ""); + b = LLVMBuildBitCast(builder, b, int_vec_type, ""); + } + + a = LLVMBuildAnd(builder, a, mask, ""); + + /* This often gets translated to PANDN, but sometimes the NOT is + * pre-computed and stored in another constant. The best strategy depends + * on available registers, so it is not a big deal -- hopefully LLVM does + * the right decision attending the rest of the program. + */ + b = LLVMBuildAnd(builder, b, LLVMBuildNot(builder, mask, ""), ""); + + res = LLVMBuildOr(builder, a, b, ""); + + if(type.floating) { + LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type); + res = LLVMBuildBitCast(builder, res, vec_type, ""); + } + + return res; +} + + +/** + * Return mask ? a : b; + * + * mask is a bitwise mask, composed of 0 or ~0 for each element. Any other value + * will yield unpredictable results. + */ +LLVMValueRef +lp_build_select(struct lp_build_context *bld, + LLVMValueRef mask, + LLVMValueRef a, + LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMContextRef lc = bld->gallivm->context; + struct lp_type type = bld->type; + LLVMValueRef res; + + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + if(a == b) + return a; + + if (type.length == 1) { + mask = LLVMBuildTrunc(builder, mask, LLVMInt1TypeInContext(lc), ""); + res = LLVMBuildSelect(builder, mask, a, b, ""); + } + else if (util_cpu_caps.has_sse4_1 && + type.width * type.length == 128 && + !LLVMIsConstant(a) && + !LLVMIsConstant(b) && + !LLVMIsConstant(mask)) { + const char *intrinsic; + LLVMTypeRef arg_type; + LLVMValueRef args[3]; + + if (type.floating && + type.width == 64) { + intrinsic = "llvm.x86.sse41.blendvpd"; + arg_type = LLVMVectorType(LLVMDoubleTypeInContext(lc), 2); + } else if (type.floating && + type.width == 32) { + intrinsic = "llvm.x86.sse41.blendvps"; + arg_type = LLVMVectorType(LLVMFloatTypeInContext(lc), 4); + } else { + intrinsic = "llvm.x86.sse41.pblendvb"; + arg_type = LLVMVectorType(LLVMInt8TypeInContext(lc), 16); + } + + if (arg_type != bld->int_vec_type) { + mask = LLVMBuildBitCast(builder, mask, arg_type, ""); + } + + if (arg_type != bld->vec_type) { + a = LLVMBuildBitCast(builder, a, arg_type, ""); + b = LLVMBuildBitCast(builder, b, arg_type, ""); + } + + args[0] = b; + args[1] = a; + args[2] = mask; + + res = lp_build_intrinsic(builder, intrinsic, + arg_type, args, Elements(args)); + + if (arg_type != bld->vec_type) { + res = LLVMBuildBitCast(builder, res, bld->vec_type, ""); + } + } + else { + res = lp_build_select_bitwise(bld, mask, a, b); + } + + return res; +} + + +/** + * Return mask ? a : b; + * + * mask is a TGSI_WRITEMASK_xxx. + */ +LLVMValueRef +lp_build_select_aos(struct lp_build_context *bld, + unsigned mask, + LLVMValueRef a, + LLVMValueRef b) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + const unsigned n = type.length; + unsigned i, j; + + assert((mask & ~0xf) == 0); + assert(lp_check_value(type, a)); + assert(lp_check_value(type, b)); + + if(a == b) + return a; + if((mask & 0xf) == 0xf) + return a; + if((mask & 0xf) == 0x0) + return b; + if(a == bld->undef || b == bld->undef) + return bld->undef; + + /* + * There are three major ways of accomplishing this: + * - with a shuffle, + * - with a select, + * - or with a bit mask. + * + * Select isn't supported for vector types yet. + * The flip between these is empirical and might need to be. + */ + if (n <= 4) { + /* + * Shuffle. + */ + LLVMTypeRef elem_type = LLVMInt32TypeInContext(bld->gallivm->context); + LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH]; + + for(j = 0; j < n; j += 4) + for(i = 0; i < 4; ++i) + shuffles[j + i] = LLVMConstInt(elem_type, + (mask & (1 << i) ? 0 : n) + j + i, + 0); + + return LLVMBuildShuffleVector(builder, a, b, LLVMConstVector(shuffles, n), ""); + } + else { +#if 0 + /* XXX: Unfortunately select of vectors do not work */ + /* Use a select */ + LLVMTypeRef elem_type = LLVMInt1Type(); + LLVMValueRef cond_vec[LP_MAX_VECTOR_LENGTH]; + + for(j = 0; j < n; j += 4) + for(i = 0; i < 4; ++i) + cond_vec[j + i] = LLVMConstInt(elem_type, + mask & (1 << i) ? 1 : 0, 0); + + return LLVMBuildSelect(builder, LLVMConstVector(cond_vec, n), a, b, ""); +#else + LLVMValueRef mask_vec = lp_build_const_mask_aos(bld->gallivm, type, mask); + return lp_build_select(bld, mask_vec, a, b); +#endif + } +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.h b/src/gallium/auxiliary/gallivm/lp_bld_logic.h new file mode 100644 index 0000000..ef33a65 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.h @@ -0,0 +1,85 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Helper functions for logical operations. + * + * @author Jose Fonseca + */ + + +#ifndef LP_BLD_LOGIC_H +#define LP_BLD_LOGIC_H + + +#include "gallivm/lp_bld.h" + +#include "pipe/p_defines.h" /* For PIPE_FUNC_xxx */ + + +struct lp_type; +struct lp_build_context; + + +LLVMValueRef +lp_build_compare(struct gallivm_state *gallivm, + const struct lp_type type, + unsigned func, + LLVMValueRef a, + LLVMValueRef b); + + +/** + * @param func is one of PIPE_FUNC_xxx + */ +LLVMValueRef +lp_build_cmp(struct lp_build_context *bld, + unsigned func, + LLVMValueRef a, + LLVMValueRef b); + +LLVMValueRef +lp_build_select_bitwise(struct lp_build_context *bld, + LLVMValueRef mask, + LLVMValueRef a, + LLVMValueRef b); + +LLVMValueRef +lp_build_select(struct lp_build_context *bld, + LLVMValueRef mask, + LLVMValueRef a, + LLVMValueRef b); + +LLVMValueRef +lp_build_select_aos(struct lp_build_context *bld, + unsigned mask, + LLVMValueRef a, + LLVMValueRef b); + + +#endif /* !LP_BLD_LOGIC_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp new file mode 100644 index 0000000..f56ddee --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp @@ -0,0 +1,190 @@ +/************************************************************************** + * + * 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 __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS +#endif + +#ifndef __STDC_CONSTANT_MACROS +#define __STDC_CONSTANT_MACROS +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include "pipe/p_config.h" +#include "util/u_debug.h" + + +#if (defined(PIPE_OS_WINDOWS) && !defined(PIPE_CC_MSVC)) || defined(PIPE_OS_EMBDDED) + +#include "llvm/Support/raw_ostream.h" + +class raw_debug_ostream : + public llvm::raw_ostream +{ + uint64_t pos; + + void write_impl(const char *Ptr, size_t Size); + uint64_t current_pos() { return pos; } + uint64_t current_pos() const { return pos; } + +#if HAVE_LLVM >= 0x207 + uint64_t preferred_buffer_size() { return 512; } +#else + size_t preferred_buffer_size() { return 512; } +#endif +}; + + +void +raw_debug_ostream::write_impl(const char *Ptr, size_t Size) +{ + if (Size > 0) { + char *lastPtr = (char *)&Ptr[Size]; + char last = *lastPtr; + *lastPtr = 0; + _debug_printf("%*s", Size, Ptr); + *lastPtr = last; + pos += Size; + } +} + + +/** + * Same as LLVMDumpValue, but through our debugging channels. + */ +extern "C" void +lp_debug_dump_value(LLVMValueRef value) +{ + raw_debug_ostream os; + llvm::unwrap(value)->print(os); + os.flush(); +} + + +#else + + +extern "C" void +lp_debug_dump_value(LLVMValueRef value) +{ + LLVMDumpValue(value); +} + + +#endif + + +/** + * Register the engine with oprofile. + * + * This allows to see the LLVM IR function names in oprofile output. + * + * To actually work LLVM needs to be built with the --with-oprofile configure + * option. + * + * Also a oprofile:oprofile user:group is necessary. Which is not created by + * default on some distributions. + */ +extern "C" void +lp_register_oprofile_jit_event_listener(LLVMExecutionEngineRef EE) +{ + llvm::unwrap(EE)->RegisterJITEventListener(llvm::createOProfileJITEventListener()); +} + + +extern "C" void +lp_set_target_options(void) +{ +#if defined(DEBUG) +#if HAVE_LLVM >= 0x0207 + llvm::JITEmitDebugInfo = true; +#endif +#endif + +#if defined(DEBUG) || defined(PROFILE) + llvm::NoFramePointerElim = true; +#endif + + llvm::NoExcessFPPrecision = false; + + /* XXX: Investigate this */ +#if 0 + llvm::UnsafeFPMath = true; +#endif + + /* + * LLVM will generate MMX instructions for vectors <= 64 bits, leading to + * innefficient code, and in 32bit systems, to the corruption of the FPU + * stack given that it expects the user to generate the EMMS instructions. + * + * See also: + * - http://llvm.org/bugs/show_bug.cgi?id=3287 + * - http://l4.me.uk/post/2009/06/07/llvm-wrinkle-3-configuration-what-configuration/ + */ + static boolean first = TRUE; + if (first) { + static const char* options[] = { + "prog", + "-disable-mmx" + }; + llvm::cl::ParseCommandLineOptions(2, const_cast(options)); + first = FALSE; + } + + /* + * By default LLVM adds a signal handler to output a pretty stack trace. + * This signal handler is never removed, causing problems when unloading the + * shared object where the gallium driver resides. + */ + llvm::DisablePrettyStackTrace = true; +} + + +extern "C" void +lp_func_delete_body(LLVMValueRef FF) +{ + llvm::Function *func = llvm::unwrap(FF); + func->deleteBody(); +} + + +extern "C" +LLVMValueRef +lp_build_load_volatile(LLVMBuilderRef B, LLVMValueRef PointerVal, + const char *Name) +{ + return llvm::wrap(llvm::unwrap(B)->CreateLoad(llvm::unwrap(PointerVal), true, Name)); +} + diff --git a/src/gallium/auxiliary/gallivm/lp_bld_pack.c b/src/gallium/auxiliary/gallivm/lp_bld_pack.c new file mode 100644 index 0000000..fde6bb5 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_pack.c @@ -0,0 +1,556 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * @file + * Helper functions for packing/unpacking. + * + * Pack/unpacking is necessary for conversion between types of different + * bit width. + * + * They are also commonly used when an computation needs higher + * precision for the intermediate values. For example, if one needs the + * function: + * + * c = compute(a, b); + * + * to use more precision for intermediate results then one should implement it + * as: + * + * LLVMValueRef + * compute(LLVMBuilderRef builder struct lp_type type, LLVMValueRef a, LLVMValueRef b) + * { + * struct lp_type wide_type = lp_wider_type(type); + * LLVMValueRef al, ah, bl, bh, cl, ch, c; + * + * lp_build_unpack2(builder, type, wide_type, a, &al, &ah); + * lp_build_unpack2(builder, type, wide_type, b, &bl, &bh); + * + * cl = compute_half(al, bl); + * ch = compute_half(ah, bh); + * + * c = lp_build_pack2(bld->builder, wide_type, type, cl, ch); + * + * return c; + * } + * + * where compute_half() would do the computation for half the elements with + * twice the precision. + * + * @author Jose Fonseca + */ + + +#include "util/u_debug.h" +#include "util/u_math.h" +#include "util/u_cpu_detect.h" + +#include "lp_bld_type.h" +#include "lp_bld_const.h" +#include "lp_bld_init.h" +#include "lp_bld_intr.h" +#include "lp_bld_arit.h" +#include "lp_bld_pack.h" + + +/** + * Build shuffle vectors that match PUNPCKLxx and PUNPCKHxx instructions. + */ +static LLVMValueRef +lp_build_const_unpack_shuffle(struct gallivm_state *gallivm, + unsigned n, unsigned lo_hi) +{ + LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; + unsigned i, j; + + assert(n <= LP_MAX_VECTOR_LENGTH); + assert(lo_hi < 2); + + /* TODO: cache results in a static table */ + + for(i = 0, j = lo_hi*n/2; i < n; i += 2, ++j) { + elems[i + 0] = lp_build_const_int32(gallivm, 0 + j); + elems[i + 1] = lp_build_const_int32(gallivm, n + j); + } + + return LLVMConstVector(elems, n); +} + + +/** + * Build shuffle vectors that match PACKxx instructions. + */ +static LLVMValueRef +lp_build_const_pack_shuffle(struct gallivm_state *gallivm, unsigned n) +{ + LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; + unsigned i; + + assert(n <= LP_MAX_VECTOR_LENGTH); + + for(i = 0; i < n; ++i) + elems[i] = lp_build_const_int32(gallivm, 2*i); + + return LLVMConstVector(elems, n); +} + + +/** + * Interleave vector elements. + * + * Matches the PUNPCKLxx and PUNPCKHxx SSE instructions. + */ +LLVMValueRef +lp_build_interleave2(struct gallivm_state *gallivm, + struct lp_type type, + LLVMValueRef a, + LLVMValueRef b, + unsigned lo_hi) +{ + LLVMValueRef shuffle; + + shuffle = lp_build_const_unpack_shuffle(gallivm, type.length, lo_hi); + + return LLVMBuildShuffleVector(gallivm->builder, a, b, shuffle, ""); +} + + +/** + * Double the bit width. + * + * This will only change the number of bits the values are represented, not the + * values themselves. + */ +void +lp_build_unpack2(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + LLVMValueRef src, + LLVMValueRef *dst_lo, + LLVMValueRef *dst_hi) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef msb; + LLVMTypeRef dst_vec_type; + + assert(!src_type.floating); + assert(!dst_type.floating); + assert(dst_type.width == src_type.width * 2); + assert(dst_type.length * 2 == src_type.length); + + if(dst_type.sign && src_type.sign) { + /* Replicate the sign bit in the most significant bits */ + msb = LLVMBuildAShr(builder, src, lp_build_const_int_vec(gallivm, src_type, src_type.width - 1), ""); + } + else + /* Most significant bits always zero */ + msb = lp_build_zero(gallivm, src_type); + + /* Interleave bits */ +#ifdef PIPE_ARCH_LITTLE_ENDIAN + *dst_lo = lp_build_interleave2(gallivm, src_type, src, msb, 0); + *dst_hi = lp_build_interleave2(gallivm, src_type, src, msb, 1); +#else + *dst_lo = lp_build_interleave2(gallivm, src_type, msb, src, 0); + *dst_hi = lp_build_interleave2(gallivm, src_type, msb, src, 1); +#endif + + /* Cast the result into the new type (twice as wide) */ + + dst_vec_type = lp_build_vec_type(gallivm, dst_type); + + *dst_lo = LLVMBuildBitCast(builder, *dst_lo, dst_vec_type, ""); + *dst_hi = LLVMBuildBitCast(builder, *dst_hi, dst_vec_type, ""); +} + + +/** + * Expand the bit width. + * + * This will only change the number of bits the values are represented, not the + * values themselves. + */ +void +lp_build_unpack(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + LLVMValueRef src, + LLVMValueRef *dst, unsigned num_dsts) +{ + unsigned num_tmps; + unsigned i; + + /* Register width must remain constant */ + assert(src_type.width * src_type.length == dst_type.width * dst_type.length); + + /* We must not loose or gain channels. Only precision */ + assert(src_type.length == dst_type.length * num_dsts); + + num_tmps = 1; + dst[0] = src; + + while(src_type.width < dst_type.width) { + struct lp_type tmp_type = src_type; + + tmp_type.width *= 2; + tmp_type.length /= 2; + + for(i = num_tmps; i--; ) { + lp_build_unpack2(gallivm, src_type, tmp_type, dst[i], &dst[2*i + 0], &dst[2*i + 1]); + } + + src_type = tmp_type; + + num_tmps *= 2; + } + + assert(num_tmps == num_dsts); +} + + +/** + * Non-interleaved pack. + * + * This will move values as + * + * lo = __ l0 __ l1 __ l2 __.. __ ln + * hi = __ h0 __ h1 __ h2 __.. __ hn + * res = l0 l1 l2 .. ln h0 h1 h2 .. hn + * + * This will only change the number of bits the values are represented, not the + * values themselves. + * + * It is assumed the values are already clamped into the destination type range. + * Values outside that range will produce undefined results. Use + * lp_build_packs2 instead. + */ +LLVMValueRef +lp_build_pack2(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + LLVMValueRef lo, + LLVMValueRef hi) +{ + LLVMBuilderRef builder = gallivm->builder; +#if HAVE_LLVM < 0x0207 + LLVMTypeRef src_vec_type = lp_build_vec_type(gallivm, src_type); +#endif + LLVMTypeRef dst_vec_type = lp_build_vec_type(gallivm, dst_type); + LLVMValueRef shuffle; + LLVMValueRef res = NULL; + + assert(!src_type.floating); + assert(!dst_type.floating); + assert(src_type.width == dst_type.width * 2); + assert(src_type.length * 2 == dst_type.length); + + /* Check for special cases first */ + if(util_cpu_caps.has_sse2 && src_type.width * src_type.length == 128) { + switch(src_type.width) { + case 32: + if(dst_type.sign) { +#if HAVE_LLVM >= 0x0207 + res = lp_build_intrinsic_binary(builder, "llvm.x86.sse2.packssdw.128", dst_vec_type, lo, hi); +#else + res = lp_build_intrinsic_binary(builder, "llvm.x86.sse2.packssdw.128", src_vec_type, lo, hi); +#endif + } + else { + if (util_cpu_caps.has_sse4_1) { + return lp_build_intrinsic_binary(builder, "llvm.x86.sse41.packusdw", dst_vec_type, lo, hi); + } + else { + /* use generic shuffle below */ + res = NULL; + } + } + break; + + case 16: + if(dst_type.sign) +#if HAVE_LLVM >= 0x0207 + res = lp_build_intrinsic_binary(builder, "llvm.x86.sse2.packsswb.128", dst_vec_type, lo, hi); +#else + res = lp_build_intrinsic_binary(builder, "llvm.x86.sse2.packsswb.128", src_vec_type, lo, hi); +#endif + else +#if HAVE_LLVM >= 0x0207 + res = lp_build_intrinsic_binary(builder, "llvm.x86.sse2.packuswb.128", dst_vec_type, lo, hi); +#else + res = lp_build_intrinsic_binary(builder, "llvm.x86.sse2.packuswb.128", src_vec_type, lo, hi); +#endif + break; + + default: + assert(0); + return LLVMGetUndef(dst_vec_type); + break; + } + + if (res) { + res = LLVMBuildBitCast(builder, res, dst_vec_type, ""); + return res; + } + } + + /* generic shuffle */ + lo = LLVMBuildBitCast(builder, lo, dst_vec_type, ""); + hi = LLVMBuildBitCast(builder, hi, dst_vec_type, ""); + + shuffle = lp_build_const_pack_shuffle(gallivm, dst_type.length); + + res = LLVMBuildShuffleVector(builder, lo, hi, shuffle, ""); + + return res; +} + + + +/** + * Non-interleaved pack and saturate. + * + * Same as lp_build_pack2 but will saturate values so that they fit into the + * destination type. + */ +LLVMValueRef +lp_build_packs2(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + LLVMValueRef lo, + LLVMValueRef hi) +{ + boolean clamp; + + assert(!src_type.floating); + assert(!dst_type.floating); + assert(src_type.sign == dst_type.sign); + assert(src_type.width == dst_type.width * 2); + assert(src_type.length * 2 == dst_type.length); + + clamp = TRUE; + + /* All X86 SSE non-interleaved pack instructions take signed inputs and + * saturate them, so no need to clamp for those cases. */ + if(util_cpu_caps.has_sse2 && + src_type.width * src_type.length == 128 && + src_type.sign) + clamp = FALSE; + + if(clamp) { + struct lp_build_context bld; + unsigned dst_bits = dst_type.sign ? dst_type.width - 1 : dst_type.width; + LLVMValueRef dst_max = lp_build_const_int_vec(gallivm, src_type, ((unsigned long long)1 << dst_bits) - 1); + lp_build_context_init(&bld, gallivm, src_type); + lo = lp_build_min(&bld, lo, dst_max); + hi = lp_build_min(&bld, hi, dst_max); + /* FIXME: What about lower bound? */ + } + + return lp_build_pack2(gallivm, src_type, dst_type, lo, hi); +} + + +/** + * Truncate the bit width. + * + * TODO: Handle saturation consistently. + */ +LLVMValueRef +lp_build_pack(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + boolean clamped, + const LLVMValueRef *src, unsigned num_srcs) +{ + LLVMValueRef (*pack2)(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + LLVMValueRef lo, + LLVMValueRef hi); + LLVMValueRef tmp[LP_MAX_VECTOR_LENGTH]; + unsigned i; + + + /* Register width must remain constant */ + assert(src_type.width * src_type.length == dst_type.width * dst_type.length); + + /* We must not loose or gain channels. Only precision */ + assert(src_type.length * num_srcs == dst_type.length); + + if(clamped) + pack2 = &lp_build_pack2; + else + pack2 = &lp_build_packs2; + + for(i = 0; i < num_srcs; ++i) + tmp[i] = src[i]; + + while(src_type.width > dst_type.width) { + struct lp_type tmp_type = src_type; + + tmp_type.width /= 2; + tmp_type.length *= 2; + + /* Take in consideration the sign changes only in the last step */ + if(tmp_type.width == dst_type.width) + tmp_type.sign = dst_type.sign; + + num_srcs /= 2; + + for(i = 0; i < num_srcs; ++i) + tmp[i] = pack2(gallivm, src_type, tmp_type, + tmp[2*i + 0], tmp[2*i + 1]); + + src_type = tmp_type; + } + + assert(num_srcs == 1); + + return tmp[0]; +} + + +/** + * Truncate or expand the bitwidth. + * + * NOTE: Getting the right sign flags is crucial here, as we employ some + * intrinsics that do saturation. + */ +void +lp_build_resize(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + const LLVMValueRef *src, unsigned num_srcs, + LLVMValueRef *dst, unsigned num_dsts) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef tmp[LP_MAX_VECTOR_LENGTH]; + unsigned i; + + /* + * We don't support float <-> int conversion here. That must be done + * before/after calling this function. + */ + assert(src_type.floating == dst_type.floating); + + /* + * We don't support double <-> float conversion yet, although it could be + * added with little effort. + */ + assert((!src_type.floating && !dst_type.floating) || + src_type.width == dst_type.width); + + /* We must not loose or gain channels. Only precision */ + assert(src_type.length * num_srcs == dst_type.length * num_dsts); + + /* We don't support M:N conversion, only 1:N, M:1, or 1:1 */ + assert(num_srcs == 1 || num_dsts == 1); + + assert(src_type.length <= LP_MAX_VECTOR_LENGTH); + assert(dst_type.length <= LP_MAX_VECTOR_LENGTH); + assert(num_srcs <= LP_MAX_VECTOR_LENGTH); + assert(num_dsts <= LP_MAX_VECTOR_LENGTH); + + if (src_type.width > dst_type.width) { + /* + * Truncate bit width. + */ + + assert(num_dsts == 1); + + if (src_type.width * src_type.length == dst_type.width * dst_type.length) { + /* + * Register width remains constant -- use vector packing intrinsics + */ + + tmp[0] = lp_build_pack(gallivm, src_type, dst_type, TRUE, src, num_srcs); + } + else { + /* + * Do it element-wise. + */ + + assert(src_type.length == dst_type.length); + tmp[0] = lp_build_undef(gallivm, dst_type); + for (i = 0; i < dst_type.length; ++i) { + LLVMValueRef index = lp_build_const_int32(gallivm, i); + LLVMValueRef val = LLVMBuildExtractElement(builder, src[0], index, ""); + val = LLVMBuildTrunc(builder, val, lp_build_elem_type(gallivm, dst_type), ""); + tmp[0] = LLVMBuildInsertElement(builder, tmp[0], val, index, ""); + } + } + } + else if (src_type.width < dst_type.width) { + /* + * Expand bit width. + */ + + assert(num_srcs == 1); + + if (src_type.width * src_type.length == dst_type.width * dst_type.length) { + /* + * Register width remains constant -- use vector unpack intrinsics + */ + lp_build_unpack(gallivm, src_type, dst_type, src[0], tmp, num_dsts); + } + else { + /* + * Do it element-wise. + */ + + assert(src_type.length == dst_type.length); + tmp[0] = lp_build_undef(gallivm, dst_type); + for (i = 0; i < dst_type.length; ++i) { + LLVMValueRef index = lp_build_const_int32(gallivm, i); + LLVMValueRef val = LLVMBuildExtractElement(builder, src[0], index, ""); + + if (src_type.sign && dst_type.sign) { + val = LLVMBuildSExt(builder, val, lp_build_elem_type(gallivm, dst_type), ""); + } else { + val = LLVMBuildZExt(builder, val, lp_build_elem_type(gallivm, dst_type), ""); + } + tmp[0] = LLVMBuildInsertElement(builder, tmp[0], val, index, ""); + } + } + } + else { + /* + * No-op + */ + + assert(num_srcs == 1); + assert(num_dsts == 1); + + tmp[0] = src[0]; + } + + for(i = 0; i < num_dsts; ++i) + dst[i] = tmp[i]; +} + + diff --git a/src/gallium/auxiliary/gallivm/lp_bld_pack.h b/src/gallium/auxiliary/gallivm/lp_bld_pack.h new file mode 100644 index 0000000..d58da4f --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_pack.h @@ -0,0 +1,105 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Helper functions for packing/unpacking conversions. + * + * @author Jose Fonseca + */ + + +#ifndef LP_BLD_PACK_H +#define LP_BLD_PACK_H + + +#include "pipe/p_compiler.h" + +#include "gallivm/lp_bld.h" + + +struct lp_type; + + +LLVMValueRef +lp_build_interleave2(struct gallivm_state *gallivm, + struct lp_type type, + LLVMValueRef a, + LLVMValueRef b, + unsigned lo_hi); + + +void +lp_build_unpack2(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + LLVMValueRef src, + LLVMValueRef *dst_lo, + LLVMValueRef *dst_hi); + + +void +lp_build_unpack(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + LLVMValueRef src, + LLVMValueRef *dst, unsigned num_dsts); + + +LLVMValueRef +lp_build_packs2(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + LLVMValueRef lo, + LLVMValueRef hi); + + +LLVMValueRef +lp_build_pack2(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + LLVMValueRef lo, + LLVMValueRef hi); + + +LLVMValueRef +lp_build_pack(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + boolean clamped, + const LLVMValueRef *src, unsigned num_srcs); + + +void +lp_build_resize(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + const LLVMValueRef *src, unsigned num_srcs, + LLVMValueRef *dst, unsigned num_dsts); + + +#endif /* !LP_BLD_PACK_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.c b/src/gallium/auxiliary/gallivm/lp_bld_printf.c new file mode 100644 index 0000000..60cc609 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.c @@ -0,0 +1,151 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include + +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "util/u_string.h" +#include "lp_bld_const.h" +#include "lp_bld_init.h" +#include "lp_bld_const.h" +#include "lp_bld_printf.h" + + +static int +lp_get_printf_arg_count(const char *fmt) +{ + int count =0; + const char *p = fmt; + int c; + + while ((c = *p++)) { + if (c != '%') + continue; + switch (*p) { + case '\0': + continue; + case '%': + p++; + continue; + case '.': + if (p[1] == '*' && p[2] == 's') { + count += 2; + p += 3; + continue; + } + /* fallthrough */ + default: + count ++; + } + } + return count; +} + +LLVMValueRef +lp_build_const_string_variable(LLVMModuleRef module, + LLVMContextRef context, + const char *str, int len) +{ + LLVMValueRef string = LLVMAddGlobal(module, LLVMArrayType(LLVMInt8TypeInContext(context), len + 1), ""); + LLVMSetGlobalConstant(string, TRUE); + LLVMSetLinkage(string, LLVMInternalLinkage); + LLVMSetInitializer(string, LLVMConstStringInContext(context, str, len + 1, TRUE)); + return string; +} + + +/** + * lp_build_printf. + * + * Build printf call in LLVM IR. The output goes to stdout. + * The additional variable arguments need to have type + * LLVMValueRef. + */ +LLVMValueRef +lp_build_printf(struct gallivm_state *gallivm, const char *fmt, ...) +{ + va_list arglist; + int i = 0; + int argcount = lp_get_printf_arg_count(fmt); + LLVMBuilderRef builder = gallivm->builder; + LLVMContextRef context = gallivm->context; + LLVMModuleRef module = gallivm->module; + LLVMValueRef params[50]; + LLVMValueRef fmtarg = lp_build_const_string_variable(module, context, + fmt, strlen(fmt) + 1); + LLVMValueRef int0 = lp_build_const_int32(gallivm, 0); + LLVMValueRef index[2]; + LLVMValueRef func_printf = LLVMGetNamedFunction(module, "printf"); + + assert(Elements(params) >= argcount + 1); + + index[0] = index[1] = int0; + + if (!func_printf) { + LLVMTypeRef printf_type = LLVMFunctionType(LLVMIntTypeInContext(context, 32), NULL, 0, 1); + func_printf = LLVMAddFunction(module, "printf", printf_type); + } + + params[0] = LLVMBuildGEP(builder, fmtarg, index, 2, ""); + + va_start(arglist, fmt); + for (i = 1; i <= argcount; i++) { + LLVMValueRef val = va_arg(arglist, LLVMValueRef); + LLVMTypeRef type = LLVMTypeOf(val); + /* printf wants doubles, so lets convert so that + * we can actually print them */ + if (LLVMGetTypeKind(type) == LLVMFloatTypeKind) + val = LLVMBuildFPExt(builder, val, LLVMDoubleTypeInContext(context), ""); + params[i] = val; + } + va_end(arglist); + + return LLVMBuildCall(builder, func_printf, params, argcount + 1, ""); +} + + + +/** + * Print a float[4] vector. + */ +LLVMValueRef +lp_build_print_vec4(struct gallivm_state *gallivm, + const char *msg, LLVMValueRef vec) +{ + LLVMBuilderRef builder = gallivm->builder; + char format[1000]; + LLVMValueRef x, y, z, w; + + x = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 0), ""); + y = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 1), ""); + z = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 2), ""); + w = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 3), ""); + + util_snprintf(format, sizeof(format), "%s %%f %%f %%f %%f\n", msg); + return lp_build_printf(gallivm, format, x, y, z, w); +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.h b/src/gallium/auxiliary/gallivm/lp_bld_printf.h new file mode 100644 index 0000000..f6bb834 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.h @@ -0,0 +1,50 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef LP_BLD_PRINTF_H +#define LP_BLD_PRINTF_H + + +#include "pipe/p_compiler.h" +#include "lp_bld.h" +#include "lp_bld_init.h" + + +LLVMValueRef lp_build_const_string_variable(LLVMModuleRef module, + LLVMContextRef context, + const char *str, int len); + +LLVMValueRef lp_build_printf(struct gallivm_state *gallivm, + const char *fmt, ...); + +LLVMValueRef +lp_build_print_vec4(struct gallivm_state *gallivm, + const char *msg, LLVMValueRef vec); + + +#endif + diff --git a/src/gallium/auxiliary/gallivm/lp_bld_quad.c b/src/gallium/auxiliary/gallivm/lp_bld_quad.c new file mode 100644 index 0000000..b0a5bc0 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_quad.c @@ -0,0 +1,110 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "lp_bld_type.h" +#include "lp_bld_arit.h" +#include "lp_bld_const.h" +#include "lp_bld_swizzle.h" +#include "lp_bld_quad.h" + + +static const unsigned char +swizzle_left[4] = { + LP_BLD_QUAD_TOP_LEFT, LP_BLD_QUAD_TOP_LEFT, + LP_BLD_QUAD_BOTTOM_LEFT, LP_BLD_QUAD_BOTTOM_LEFT +}; + +static const unsigned char +swizzle_right[4] = { + LP_BLD_QUAD_TOP_RIGHT, LP_BLD_QUAD_TOP_RIGHT, + LP_BLD_QUAD_BOTTOM_RIGHT, LP_BLD_QUAD_BOTTOM_RIGHT +}; + +static const unsigned char +swizzle_top[4] = { + LP_BLD_QUAD_TOP_LEFT, LP_BLD_QUAD_TOP_RIGHT, + LP_BLD_QUAD_TOP_LEFT, LP_BLD_QUAD_TOP_RIGHT +}; + +static const unsigned char +swizzle_bottom[4] = { + LP_BLD_QUAD_BOTTOM_LEFT, LP_BLD_QUAD_BOTTOM_RIGHT, + LP_BLD_QUAD_BOTTOM_LEFT, LP_BLD_QUAD_BOTTOM_RIGHT +}; + + +LLVMValueRef +lp_build_ddx(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMValueRef a_left = lp_build_swizzle_aos(bld, a, swizzle_left); + LLVMValueRef a_right = lp_build_swizzle_aos(bld, a, swizzle_right); + return lp_build_sub(bld, a_right, a_left); +} + + +LLVMValueRef +lp_build_ddy(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMValueRef a_top = lp_build_swizzle_aos(bld, a, swizzle_top); + LLVMValueRef a_bottom = lp_build_swizzle_aos(bld, a, swizzle_bottom); + return lp_build_sub(bld, a_bottom, a_top); +} + + +LLVMValueRef +lp_build_scalar_ddx(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef idx_left = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_TOP_LEFT); + LLVMValueRef idx_right = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_TOP_RIGHT); + LLVMValueRef a_left = LLVMBuildExtractElement(builder, a, idx_left, "left"); + LLVMValueRef a_right = LLVMBuildExtractElement(builder, a, idx_right, "right"); + if (bld->type.floating) + return LLVMBuildFSub(builder, a_right, a_left, "ddx"); + else + return LLVMBuildSub(builder, a_right, a_left, "ddx"); +} + + +LLVMValueRef +lp_build_scalar_ddy(struct lp_build_context *bld, + LLVMValueRef a) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef idx_top = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_TOP_LEFT); + LLVMValueRef idx_bottom = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_BOTTOM_LEFT); + LLVMValueRef a_top = LLVMBuildExtractElement(builder, a, idx_top, "top"); + LLVMValueRef a_bottom = LLVMBuildExtractElement(builder, a, idx_bottom, "bottom"); + if (bld->type.floating) + return LLVMBuildFSub(builder, a_bottom, a_top, "ddy"); + else + return LLVMBuildSub(builder, a_bottom, a_top, "ddy"); +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_quad.h b/src/gallium/auxiliary/gallivm/lp_bld_quad.h new file mode 100644 index 0000000..b799291 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_quad.h @@ -0,0 +1,96 @@ +/************************************************************************** + * + * 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 LP_BLD_QUAD_H_ +#define LP_BLD_QUAD_H_ + + +#include "gallivm/lp_bld.h" + + +struct lp_build_context; + + +/* + * Each quad is composed of four elements. + * + * ######### + * # 0 | 1 # + * #---+---# + * # 2 | 3 # + * ######### + */ + +enum lp_bld_quad { + LP_BLD_QUAD_TOP_LEFT = 0, + LP_BLD_QUAD_TOP_RIGHT = 1, + LP_BLD_QUAD_BOTTOM_LEFT = 2, + LP_BLD_QUAD_BOTTOM_RIGHT = 3 +}; + + +/* + * (Vector) derivates. + * + * More than one quad is supported. The only requirement is that the vector + * contains a whole number of quads: + * + * ######### ######### ... + * # 0 | 1 # # 4 | 5 # + * #---+---# #---+---# ... + * # 2 | 3 # # 6 | 7 # + * ######### ######### ... + */ + +LLVMValueRef +lp_build_ddx(struct lp_build_context *bld, + LLVMValueRef a); + + +LLVMValueRef +lp_build_ddy(struct lp_build_context *bld, + LLVMValueRef a); + + +/* + * Scalar derivatives. + * + * Same as getting the first value of above. + */ + +LLVMValueRef +lp_build_scalar_ddx(struct lp_build_context *bld, + LLVMValueRef a); + + +LLVMValueRef +lp_build_scalar_ddy(struct lp_build_context *bld, + LLVMValueRef a); + + +#endif /* LP_BLD_QUAD_H_ */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c new file mode 100644 index 0000000..8ad3459 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c @@ -0,0 +1,1115 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Texture sampling -- common code. + * + * @author Jose Fonseca + */ + +#include "pipe/p_defines.h" +#include "pipe/p_state.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "lp_bld_arit.h" +#include "lp_bld_const.h" +#include "lp_bld_debug.h" +#include "lp_bld_printf.h" +#include "lp_bld_flow.h" +#include "lp_bld_sample.h" +#include "lp_bld_swizzle.h" +#include "lp_bld_type.h" + + +/* + * Bri-linear factor. Should be greater than one. + */ +#define BRILINEAR_FACTOR 2 + + +/** + * Does the given texture wrap mode allow sampling the texture border color? + * XXX maybe move this into gallium util code. + */ +boolean +lp_sampler_wrap_mode_uses_border_color(unsigned mode, + unsigned min_img_filter, + unsigned mag_img_filter) +{ + switch (mode) { + case PIPE_TEX_WRAP_REPEAT: + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + case PIPE_TEX_WRAP_MIRROR_REPEAT: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + return FALSE; + case PIPE_TEX_WRAP_CLAMP: + case PIPE_TEX_WRAP_MIRROR_CLAMP: + if (min_img_filter == PIPE_TEX_FILTER_NEAREST && + mag_img_filter == PIPE_TEX_FILTER_NEAREST) { + return FALSE; + } else { + return TRUE; + } + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + return TRUE; + default: + assert(0 && "unexpected wrap mode"); + return FALSE; + } +} + + +/** + * Initialize lp_sampler_static_state object with the gallium sampler + * and texture state. + * The former is considered to be static and the later dynamic. + */ +void +lp_sampler_static_state(struct lp_sampler_static_state *state, + const struct pipe_sampler_view *view, + const struct pipe_sampler_state *sampler) +{ + const struct pipe_resource *texture = view->texture; + + memset(state, 0, sizeof *state); + + if(!texture) + return; + + if(!sampler) + return; + + /* + * We don't copy sampler state over unless it is actually enabled, to avoid + * spurious recompiles, as the sampler static state is part of the shader + * key. + * + * Ideally the state tracker or cso_cache module would make all state + * canonical, but until that happens it's better to be safe than sorry here. + * + * XXX: Actually there's much more than can be done here, especially + * regarding 1D/2D/3D/CUBE textures, wrap modes, etc. + */ + + state->format = view->format; + state->swizzle_r = view->swizzle_r; + state->swizzle_g = view->swizzle_g; + state->swizzle_b = view->swizzle_b; + state->swizzle_a = view->swizzle_a; + + state->target = texture->target; + state->pot_width = util_is_power_of_two(texture->width0); + state->pot_height = util_is_power_of_two(texture->height0); + state->pot_depth = util_is_power_of_two(texture->depth0); + + state->wrap_s = sampler->wrap_s; + state->wrap_t = sampler->wrap_t; + state->wrap_r = sampler->wrap_r; + state->min_img_filter = sampler->min_img_filter; + state->mag_img_filter = sampler->mag_img_filter; + + if (view->u.tex.last_level && sampler->max_lod > 0.0f) { + state->min_mip_filter = sampler->min_mip_filter; + } else { + state->min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + } + + if (state->min_mip_filter != PIPE_TEX_MIPFILTER_NONE) { + if (sampler->lod_bias != 0.0f) { + state->lod_bias_non_zero = 1; + } + + /* If min_lod == max_lod we can greatly simplify mipmap selection. + * This is a case that occurs during automatic mipmap generation. + */ + if (sampler->min_lod == sampler->max_lod) { + state->min_max_lod_equal = 1; + } else { + if (sampler->min_lod > 0.0f) { + state->apply_min_lod = 1; + } + + if (sampler->max_lod < (float)view->u.tex.last_level) { + state->apply_max_lod = 1; + } + } + } + + state->compare_mode = sampler->compare_mode; + if (sampler->compare_mode != PIPE_TEX_COMPARE_NONE) { + state->compare_func = sampler->compare_func; + } + + state->normalized_coords = sampler->normalized_coords; + + /* + * FIXME: Handle the remainder of pipe_sampler_view. + */ +} + + +/** + * Generate code to compute coordinate gradient (rho). + * \param ddx partial derivatives of (s, t, r, q) with respect to X + * \param ddy partial derivatives of (s, t, r, q) with respect to Y + * + * XXX: The resulting rho is scalar, so we ignore all but the first element of + * derivatives that are passed by the shader. + */ +static LLVMValueRef +lp_build_rho(struct lp_build_sample_context *bld, + const LLVMValueRef ddx[4], + const LLVMValueRef ddy[4]) +{ + struct lp_build_context *float_size_bld = &bld->float_size_bld; + struct lp_build_context *float_bld = &bld->float_bld; + const unsigned dims = bld->dims; + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context); + LLVMValueRef index0 = LLVMConstInt(i32t, 0, 0); + LLVMValueRef index1 = LLVMConstInt(i32t, 1, 0); + LLVMValueRef index2 = LLVMConstInt(i32t, 2, 0); + LLVMValueRef dsdx, dsdy, dtdx, dtdy, drdx, drdy; + LLVMValueRef rho_x, rho_y; + LLVMValueRef rho_vec; + LLVMValueRef float_size; + LLVMValueRef rho; + + dsdx = ddx[0]; + dsdy = ddy[0]; + + if (dims <= 1) { + rho_x = dsdx; + rho_y = dsdy; + } + else { + rho_x = float_size_bld->undef; + rho_y = float_size_bld->undef; + + rho_x = LLVMBuildInsertElement(builder, rho_x, dsdx, index0, ""); + rho_y = LLVMBuildInsertElement(builder, rho_y, dsdy, index0, ""); + + dtdx = ddx[1]; + dtdy = ddy[1]; + + rho_x = LLVMBuildInsertElement(builder, rho_x, dtdx, index1, ""); + rho_y = LLVMBuildInsertElement(builder, rho_y, dtdy, index1, ""); + + if (dims >= 3) { + drdx = ddx[2]; + drdy = ddy[2]; + + rho_x = LLVMBuildInsertElement(builder, rho_x, drdx, index2, ""); + rho_y = LLVMBuildInsertElement(builder, rho_y, drdy, index2, ""); + } + } + + rho_x = lp_build_abs(float_size_bld, rho_x); + rho_y = lp_build_abs(float_size_bld, rho_y); + + rho_vec = lp_build_max(float_size_bld, rho_x, rho_y); + + float_size = lp_build_int_to_float(float_size_bld, bld->int_size); + + rho_vec = lp_build_mul(float_size_bld, rho_vec, float_size); + + if (dims <= 1) { + rho = rho_vec; + } + else { + if (dims >= 2) { + LLVMValueRef rho_s, rho_t, rho_r; + + rho_s = LLVMBuildExtractElement(builder, rho_vec, index0, ""); + rho_t = LLVMBuildExtractElement(builder, rho_vec, index1, ""); + + rho = lp_build_max(float_bld, rho_s, rho_t); + + if (dims >= 3) { + rho_r = LLVMBuildExtractElement(builder, rho_vec, index0, ""); + rho = lp_build_max(float_bld, rho, rho_r); + } + } + } + + return rho; +} + + +/* + * Bri-linear lod computation + * + * Use a piece-wise linear approximation of log2 such that: + * - round to nearest, for values in the neighborhood of -1, 0, 1, 2, etc. + * - linear approximation for values in the neighborhood of 0.5, 1.5., etc, + * with the steepness specified in 'factor' + * - exact result for 0.5, 1.5, etc. + * + * + * 1.0 - /----* + * / + * / + * / + * 0.5 - * + * / + * / + * / + * 0.0 - *----/ + * + * | | + * 2^0 2^1 + * + * This is a technique also commonly used in hardware: + * - http://ixbtlabs.com/articles2/gffx/nv40-rx800-3.html + * + * TODO: For correctness, this should only be applied when texture is known to + * have regular mipmaps, i.e., mipmaps derived from the base level. + * + * TODO: This could be done in fixed point, where applicable. + */ +static void +lp_build_brilinear_lod(struct lp_build_context *bld, + LLVMValueRef lod, + double factor, + LLVMValueRef *out_lod_ipart, + LLVMValueRef *out_lod_fpart) +{ + LLVMValueRef lod_fpart; + double pre_offset = (factor - 0.5)/factor - 0.5; + double post_offset = 1 - factor; + + if (0) { + lp_build_printf(bld->gallivm, "lod = %f\n", lod); + } + + lod = lp_build_add(bld, lod, + lp_build_const_vec(bld->gallivm, bld->type, pre_offset)); + + lp_build_ifloor_fract(bld, lod, out_lod_ipart, &lod_fpart); + + lod_fpart = lp_build_mul(bld, lod_fpart, + lp_build_const_vec(bld->gallivm, bld->type, factor)); + + lod_fpart = lp_build_add(bld, lod_fpart, + lp_build_const_vec(bld->gallivm, bld->type, post_offset)); + + /* + * It's not necessary to clamp lod_fpart since: + * - the above expression will never produce numbers greater than one. + * - the mip filtering branch is only taken if lod_fpart is positive + */ + + *out_lod_fpart = lod_fpart; + + if (0) { + lp_build_printf(bld->gallivm, "lod_ipart = %i\n", *out_lod_ipart); + lp_build_printf(bld->gallivm, "lod_fpart = %f\n\n", *out_lod_fpart); + } +} + + +/* + * Combined log2 and brilinear lod computation. + * + * It's in all identical to calling lp_build_fast_log2() and + * lp_build_brilinear_lod() above, but by combining we can compute the interger + * and fractional part independently. + */ +static void +lp_build_brilinear_rho(struct lp_build_context *bld, + LLVMValueRef rho, + double factor, + LLVMValueRef *out_lod_ipart, + LLVMValueRef *out_lod_fpart) +{ + LLVMValueRef lod_ipart; + LLVMValueRef lod_fpart; + + const double pre_factor = (2*factor - 0.5)/(M_SQRT2*factor); + const double post_offset = 1 - 2*factor; + + assert(bld->type.floating); + + assert(lp_check_value(bld->type, rho)); + + /* + * The pre factor will make the intersections with the exact powers of two + * happen precisely where we want then to be, which means that the integer + * part will not need any post adjustments. + */ + rho = lp_build_mul(bld, rho, + lp_build_const_vec(bld->gallivm, bld->type, pre_factor)); + + /* ipart = ifloor(log2(rho)) */ + lod_ipart = lp_build_extract_exponent(bld, rho, 0); + + /* fpart = rho / 2**ipart */ + lod_fpart = lp_build_extract_mantissa(bld, rho); + + lod_fpart = lp_build_mul(bld, lod_fpart, + lp_build_const_vec(bld->gallivm, bld->type, factor)); + + lod_fpart = lp_build_add(bld, lod_fpart, + lp_build_const_vec(bld->gallivm, bld->type, post_offset)); + + /* + * Like lp_build_brilinear_lod, it's not necessary to clamp lod_fpart since: + * - the above expression will never produce numbers greater than one. + * - the mip filtering branch is only taken if lod_fpart is positive + */ + + *out_lod_ipart = lod_ipart; + *out_lod_fpart = lod_fpart; +} + + +/** + * Generate code to compute texture level of detail (lambda). + * \param ddx partial derivatives of (s, t, r, q) with respect to X + * \param ddy partial derivatives of (s, t, r, q) with respect to Y + * \param lod_bias optional float vector with the shader lod bias + * \param explicit_lod optional float vector with the explicit lod + * \param width scalar int texture width + * \param height scalar int texture height + * \param depth scalar int texture depth + * + * XXX: The resulting lod is scalar, so ignore all but the first element of + * derivatives, lod_bias, etc that are passed by the shader. + */ +void +lp_build_lod_selector(struct lp_build_sample_context *bld, + unsigned unit, + const LLVMValueRef ddx[4], + const LLVMValueRef ddy[4], + LLVMValueRef lod_bias, /* optional */ + LLVMValueRef explicit_lod, /* optional */ + unsigned mip_filter, + LLVMValueRef *out_lod_ipart, + LLVMValueRef *out_lod_fpart) + +{ + LLVMBuilderRef builder = bld->gallivm->builder; + struct lp_build_context *float_bld = &bld->float_bld; + LLVMValueRef lod; + + *out_lod_ipart = bld->int_bld.zero; + *out_lod_fpart = bld->float_bld.zero; + + if (bld->static_state->min_max_lod_equal) { + /* User is forcing sampling from a particular mipmap level. + * This is hit during mipmap generation. + */ + LLVMValueRef min_lod = + bld->dynamic_state->min_lod(bld->dynamic_state, bld->gallivm, unit); + + lod = min_lod; + } + else { + LLVMValueRef sampler_lod_bias = + bld->dynamic_state->lod_bias(bld->dynamic_state, bld->gallivm, unit); + LLVMValueRef index0 = lp_build_const_int32(bld->gallivm, 0); + + if (explicit_lod) { + lod = LLVMBuildExtractElement(builder, explicit_lod, + index0, ""); + } + else { + LLVMValueRef rho; + + rho = lp_build_rho(bld, ddx, ddy); + + /* + * Compute lod = log2(rho) + */ + + if (!lod_bias && + !bld->static_state->lod_bias_non_zero && + !bld->static_state->apply_max_lod && + !bld->static_state->apply_min_lod) { + /* + * Special case when there are no post-log2 adjustments, which + * saves instructions but keeping the integer and fractional lod + * computations separate from the start. + */ + + if (mip_filter == PIPE_TEX_MIPFILTER_NONE || + mip_filter == PIPE_TEX_MIPFILTER_NEAREST) { + *out_lod_ipart = lp_build_ilog2(float_bld, rho); + *out_lod_fpart = bld->float_bld.zero; + return; + } + if (mip_filter == PIPE_TEX_MIPFILTER_LINEAR && + !(gallivm_debug & GALLIVM_DEBUG_NO_BRILINEAR)) { + lp_build_brilinear_rho(float_bld, rho, BRILINEAR_FACTOR, + out_lod_ipart, out_lod_fpart); + return; + } + } + + if (0) { + lod = lp_build_log2(float_bld, rho); + } + else { + lod = lp_build_fast_log2(float_bld, rho); + } + + /* add shader lod bias */ + if (lod_bias) { + lod_bias = LLVMBuildExtractElement(builder, lod_bias, + index0, ""); + lod = LLVMBuildFAdd(builder, lod, lod_bias, "shader_lod_bias"); + } + } + + /* add sampler lod bias */ + if (bld->static_state->lod_bias_non_zero) + lod = LLVMBuildFAdd(builder, lod, sampler_lod_bias, "sampler_lod_bias"); + + + /* clamp lod */ + if (bld->static_state->apply_max_lod) { + LLVMValueRef max_lod = + bld->dynamic_state->max_lod(bld->dynamic_state, bld->gallivm, unit); + + lod = lp_build_min(float_bld, lod, max_lod); + } + if (bld->static_state->apply_min_lod) { + LLVMValueRef min_lod = + bld->dynamic_state->min_lod(bld->dynamic_state, bld->gallivm, unit); + + lod = lp_build_max(float_bld, lod, min_lod); + } + } + + if (mip_filter == PIPE_TEX_MIPFILTER_LINEAR) { + if (!(gallivm_debug & GALLIVM_DEBUG_NO_BRILINEAR)) { + lp_build_brilinear_lod(float_bld, lod, BRILINEAR_FACTOR, + out_lod_ipart, out_lod_fpart); + } + else { + lp_build_ifloor_fract(float_bld, lod, out_lod_ipart, out_lod_fpart); + } + + lp_build_name(*out_lod_fpart, "lod_fpart"); + } + else { + *out_lod_ipart = lp_build_iround(float_bld, lod); + } + + lp_build_name(*out_lod_ipart, "lod_ipart"); + + return; +} + + +/** + * For PIPE_TEX_MIPFILTER_NEAREST, convert float LOD to integer + * mipmap level index. + * Note: this is all scalar code. + * \param lod scalar float texture level of detail + * \param level_out returns integer + */ +void +lp_build_nearest_mip_level(struct lp_build_sample_context *bld, + unsigned unit, + LLVMValueRef lod_ipart, + LLVMValueRef *level_out) +{ + struct lp_build_context *int_bld = &bld->int_bld; + LLVMValueRef last_level, level; + + LLVMValueRef zero = lp_build_const_int32(bld->gallivm, 0); + + last_level = bld->dynamic_state->last_level(bld->dynamic_state, + bld->gallivm, unit); + + /* convert float lod to integer */ + level = lod_ipart; + + /* clamp level to legal range of levels */ + *level_out = lp_build_clamp(int_bld, level, zero, last_level); +} + + +/** + * For PIPE_TEX_MIPFILTER_LINEAR, convert float LOD to integer to + * two (adjacent) mipmap level indexes. Later, we'll sample from those + * two mipmap levels and interpolate between them. + */ +void +lp_build_linear_mip_levels(struct lp_build_sample_context *bld, + unsigned unit, + LLVMValueRef lod_ipart, + LLVMValueRef *lod_fpart_inout, + LLVMValueRef *level0_out, + LLVMValueRef *level1_out) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + struct lp_build_context *int_bld = &bld->int_bld; + struct lp_build_context *float_bld = &bld->float_bld; + LLVMValueRef last_level; + LLVMValueRef clamp_min; + LLVMValueRef clamp_max; + + *level0_out = lod_ipart; + *level1_out = lp_build_add(int_bld, lod_ipart, int_bld->one); + + last_level = bld->dynamic_state->last_level(bld->dynamic_state, + bld->gallivm, unit); + + /* + * Clamp both lod_ipart and lod_ipart + 1 to [0, last_level], with the + * minimum number of comparisons, and zeroing lod_fpart in the extreme + * ends in the process. + */ + + /* lod_ipart < 0 */ + clamp_min = LLVMBuildICmp(builder, LLVMIntSLT, + lod_ipart, int_bld->zero, + "clamp_lod_to_zero"); + + *level0_out = LLVMBuildSelect(builder, clamp_min, + int_bld->zero, *level0_out, ""); + + *level1_out = LLVMBuildSelect(builder, clamp_min, + int_bld->zero, *level1_out, ""); + + *lod_fpart_inout = LLVMBuildSelect(builder, clamp_min, + float_bld->zero, *lod_fpart_inout, ""); + + /* lod_ipart >= last_level */ + clamp_max = LLVMBuildICmp(builder, LLVMIntSGE, + lod_ipart, last_level, + "clamp_lod_to_last"); + + *level0_out = LLVMBuildSelect(builder, clamp_max, + last_level, *level0_out, ""); + + *level1_out = LLVMBuildSelect(builder, clamp_max, + last_level, *level1_out, ""); + + *lod_fpart_inout = LLVMBuildSelect(builder, clamp_max, + float_bld->zero, *lod_fpart_inout, ""); + + lp_build_name(*level0_out, "sampler%u_miplevel0", unit); + lp_build_name(*level1_out, "sampler%u_miplevel1", unit); + lp_build_name(*lod_fpart_inout, "sampler%u_mipweight", unit); +} + + +/** + * Return pointer to a single mipmap level. + * \param data_array array of pointers to mipmap levels + * \param level integer mipmap level + */ +LLVMValueRef +lp_build_get_mipmap_level(struct lp_build_sample_context *bld, + LLVMValueRef level) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef indexes[2], data_ptr; + + indexes[0] = lp_build_const_int32(bld->gallivm, 0); + indexes[1] = level; + data_ptr = LLVMBuildGEP(builder, bld->data_array, indexes, 2, ""); + data_ptr = LLVMBuildLoad(builder, data_ptr, ""); + return data_ptr; +} + + +LLVMValueRef +lp_build_get_const_mipmap_level(struct lp_build_sample_context *bld, + int level) +{ + LLVMValueRef lvl = lp_build_const_int32(bld->gallivm, level); + return lp_build_get_mipmap_level(bld, lvl); +} + + +/** + * Codegen equivalent for u_minify(). + * Return max(1, base_size >> level); + */ +static LLVMValueRef +lp_build_minify(struct lp_build_context *bld, + LLVMValueRef base_size, + LLVMValueRef level) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + assert(lp_check_value(bld->type, base_size)); + assert(lp_check_value(bld->type, level)); + + if (level == bld->zero) { + /* if we're using mipmap level zero, no minification is needed */ + return base_size; + } + else { + LLVMValueRef size = + LLVMBuildLShr(builder, base_size, level, "minify"); + assert(bld->type.sign); + size = lp_build_max(bld, size, bld->one); + return size; + } +} + + +/** + * Dereference stride_array[mipmap_level] array to get a stride. + * Return stride as a vector. + */ +static LLVMValueRef +lp_build_get_level_stride_vec(struct lp_build_sample_context *bld, + LLVMValueRef stride_array, LLVMValueRef level) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef indexes[2], stride; + indexes[0] = lp_build_const_int32(bld->gallivm, 0); + indexes[1] = level; + stride = LLVMBuildGEP(builder, stride_array, indexes, 2, ""); + stride = LLVMBuildLoad(builder, stride, ""); + stride = lp_build_broadcast_scalar(&bld->int_coord_bld, stride); + return stride; +} + + +/** + * When sampling a mipmap, we need to compute the width, height, depth + * of the source levels from the level indexes. This helper function + * does that. + */ +void +lp_build_mipmap_level_sizes(struct lp_build_sample_context *bld, + LLVMValueRef ilevel, + LLVMValueRef *out_size, + LLVMValueRef *row_stride_vec, + LLVMValueRef *img_stride_vec) +{ + const unsigned dims = bld->dims; + LLVMValueRef ilevel_vec; + + ilevel_vec = lp_build_broadcast_scalar(&bld->int_size_bld, ilevel); + + /* + * Compute width, height, depth at mipmap level 'ilevel' + */ + *out_size = lp_build_minify(&bld->int_size_bld, bld->int_size, ilevel_vec); + + if (dims >= 2) { + *row_stride_vec = lp_build_get_level_stride_vec(bld, + bld->row_stride_array, + ilevel); + if (dims == 3 || bld->static_state->target == PIPE_TEXTURE_CUBE) { + *img_stride_vec = lp_build_get_level_stride_vec(bld, + bld->img_stride_array, + ilevel); + } + } +} + + +/** + * Extract and broadcast texture size. + * + * @param size_type type of the texture size vector (either + * bld->int_size_type or bld->float_size_type) + * @param coord_type type of the texture size vector (either + * bld->int_coord_type or bld->coord_type) + * @param int_size vector with the integer texture size (width, height, + * depth) + */ +void +lp_build_extract_image_sizes(struct lp_build_sample_context *bld, + struct lp_type size_type, + struct lp_type coord_type, + LLVMValueRef size, + LLVMValueRef *out_width, + LLVMValueRef *out_height, + LLVMValueRef *out_depth) +{ + const unsigned dims = bld->dims; + LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context); + + *out_width = lp_build_extract_broadcast(bld->gallivm, + size_type, + coord_type, + size, + LLVMConstInt(i32t, 0, 0)); + if (dims >= 2) { + *out_height = lp_build_extract_broadcast(bld->gallivm, + size_type, + coord_type, + size, + LLVMConstInt(i32t, 1, 0)); + if (dims == 3) { + *out_depth = lp_build_extract_broadcast(bld->gallivm, + size_type, + coord_type, + size, + LLVMConstInt(i32t, 2, 0)); + } + } +} + + +/** + * Unnormalize coords. + * + * @param int_size vector with the integer texture size (width, height, depth) + */ +void +lp_build_unnormalized_coords(struct lp_build_sample_context *bld, + LLVMValueRef flt_size, + LLVMValueRef *s, + LLVMValueRef *t, + LLVMValueRef *r) +{ + const unsigned dims = bld->dims; + LLVMValueRef width; + LLVMValueRef height; + LLVMValueRef depth; + + lp_build_extract_image_sizes(bld, + bld->float_size_type, + bld->coord_type, + flt_size, + &width, + &height, + &depth); + + /* s = s * width, t = t * height */ + *s = lp_build_mul(&bld->coord_bld, *s, width); + if (dims >= 2) { + *t = lp_build_mul(&bld->coord_bld, *t, height); + if (dims >= 3) { + *r = lp_build_mul(&bld->coord_bld, *r, depth); + } + } +} + + +/** Helper used by lp_build_cube_lookup() */ +static LLVMValueRef +lp_build_cube_ima(struct lp_build_context *coord_bld, LLVMValueRef coord) +{ + /* ima = -0.5 / abs(coord); */ + LLVMValueRef negHalf = lp_build_const_vec(coord_bld->gallivm, coord_bld->type, -0.5); + LLVMValueRef absCoord = lp_build_abs(coord_bld, coord); + LLVMValueRef ima = lp_build_div(coord_bld, negHalf, absCoord); + return ima; +} + + +/** + * Helper used by lp_build_cube_lookup() + * \param sign scalar +1 or -1 + * \param coord float vector + * \param ima float vector + */ +static LLVMValueRef +lp_build_cube_coord(struct lp_build_context *coord_bld, + LLVMValueRef sign, int negate_coord, + LLVMValueRef coord, LLVMValueRef ima) +{ + /* return negate(coord) * ima * sign + 0.5; */ + LLVMValueRef half = lp_build_const_vec(coord_bld->gallivm, coord_bld->type, 0.5); + LLVMValueRef res; + + assert(negate_coord == +1 || negate_coord == -1); + + if (negate_coord == -1) { + coord = lp_build_negate(coord_bld, coord); + } + + res = lp_build_mul(coord_bld, coord, ima); + if (sign) { + sign = lp_build_broadcast_scalar(coord_bld, sign); + res = lp_build_mul(coord_bld, res, sign); + } + res = lp_build_add(coord_bld, res, half); + + return res; +} + + +/** Helper used by lp_build_cube_lookup() + * Return (major_coord >= 0) ? pos_face : neg_face; + */ +static LLVMValueRef +lp_build_cube_face(struct lp_build_sample_context *bld, + LLVMValueRef major_coord, + unsigned pos_face, unsigned neg_face) +{ + struct gallivm_state *gallivm = bld->gallivm; + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef cmp = LLVMBuildFCmp(builder, LLVMRealUGE, + major_coord, + bld->float_bld.zero, ""); + LLVMValueRef pos = lp_build_const_int32(gallivm, pos_face); + LLVMValueRef neg = lp_build_const_int32(gallivm, neg_face); + LLVMValueRef res = LLVMBuildSelect(builder, cmp, pos, neg, ""); + return res; +} + + + +/** + * Generate code to do cube face selection and compute per-face texcoords. + */ +void +lp_build_cube_lookup(struct lp_build_sample_context *bld, + LLVMValueRef s, + LLVMValueRef t, + LLVMValueRef r, + LLVMValueRef *face, + LLVMValueRef *face_s, + LLVMValueRef *face_t) +{ + struct lp_build_context *float_bld = &bld->float_bld; + struct lp_build_context *coord_bld = &bld->coord_bld; + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef rx, ry, rz; + LLVMValueRef arx, ary, arz; + LLVMValueRef c25 = lp_build_const_float(bld->gallivm, 0.25); + LLVMValueRef arx_ge_ary, arx_ge_arz; + LLVMValueRef ary_ge_arx, ary_ge_arz; + LLVMValueRef arx_ge_ary_arz, ary_ge_arx_arz; + LLVMValueRef rx_pos, ry_pos, rz_pos; + + assert(bld->coord_bld.type.length == 4); + + /* + * Use the average of the four pixel's texcoords to choose the face. + */ + rx = lp_build_mul(float_bld, c25, + lp_build_sum_vector(&bld->coord_bld, s)); + ry = lp_build_mul(float_bld, c25, + lp_build_sum_vector(&bld->coord_bld, t)); + rz = lp_build_mul(float_bld, c25, + lp_build_sum_vector(&bld->coord_bld, r)); + + arx = lp_build_abs(float_bld, rx); + ary = lp_build_abs(float_bld, ry); + arz = lp_build_abs(float_bld, rz); + + /* + * Compare sign/magnitude of rx,ry,rz to determine face + */ + arx_ge_ary = LLVMBuildFCmp(builder, LLVMRealUGE, arx, ary, ""); + arx_ge_arz = LLVMBuildFCmp(builder, LLVMRealUGE, arx, arz, ""); + ary_ge_arx = LLVMBuildFCmp(builder, LLVMRealUGE, ary, arx, ""); + ary_ge_arz = LLVMBuildFCmp(builder, LLVMRealUGE, ary, arz, ""); + + arx_ge_ary_arz = LLVMBuildAnd(builder, arx_ge_ary, arx_ge_arz, ""); + ary_ge_arx_arz = LLVMBuildAnd(builder, ary_ge_arx, ary_ge_arz, ""); + + rx_pos = LLVMBuildFCmp(builder, LLVMRealUGE, rx, float_bld->zero, ""); + ry_pos = LLVMBuildFCmp(builder, LLVMRealUGE, ry, float_bld->zero, ""); + rz_pos = LLVMBuildFCmp(builder, LLVMRealUGE, rz, float_bld->zero, ""); + + { + struct lp_build_if_state if_ctx; + LLVMValueRef face_s_var; + LLVMValueRef face_t_var; + LLVMValueRef face_var; + + face_s_var = lp_build_alloca(bld->gallivm, bld->coord_bld.vec_type, "face_s_var"); + face_t_var = lp_build_alloca(bld->gallivm, bld->coord_bld.vec_type, "face_t_var"); + face_var = lp_build_alloca(bld->gallivm, bld->int_bld.vec_type, "face_var"); + + lp_build_if(&if_ctx, bld->gallivm, arx_ge_ary_arz); + { + /* +/- X face */ + LLVMValueRef sign = lp_build_sgn(float_bld, rx); + LLVMValueRef ima = lp_build_cube_ima(coord_bld, s); + *face_s = lp_build_cube_coord(coord_bld, sign, +1, r, ima); + *face_t = lp_build_cube_coord(coord_bld, NULL, +1, t, ima); + *face = lp_build_cube_face(bld, rx, + PIPE_TEX_FACE_POS_X, + PIPE_TEX_FACE_NEG_X); + LLVMBuildStore(builder, *face_s, face_s_var); + LLVMBuildStore(builder, *face_t, face_t_var); + LLVMBuildStore(builder, *face, face_var); + } + lp_build_else(&if_ctx); + { + struct lp_build_if_state if_ctx2; + + ary_ge_arx_arz = LLVMBuildAnd(builder, ary_ge_arx, ary_ge_arz, ""); + + lp_build_if(&if_ctx2, bld->gallivm, ary_ge_arx_arz); + { + /* +/- Y face */ + LLVMValueRef sign = lp_build_sgn(float_bld, ry); + LLVMValueRef ima = lp_build_cube_ima(coord_bld, t); + *face_s = lp_build_cube_coord(coord_bld, NULL, -1, s, ima); + *face_t = lp_build_cube_coord(coord_bld, sign, -1, r, ima); + *face = lp_build_cube_face(bld, ry, + PIPE_TEX_FACE_POS_Y, + PIPE_TEX_FACE_NEG_Y); + LLVMBuildStore(builder, *face_s, face_s_var); + LLVMBuildStore(builder, *face_t, face_t_var); + LLVMBuildStore(builder, *face, face_var); + } + lp_build_else(&if_ctx2); + { + /* +/- Z face */ + LLVMValueRef sign = lp_build_sgn(float_bld, rz); + LLVMValueRef ima = lp_build_cube_ima(coord_bld, r); + *face_s = lp_build_cube_coord(coord_bld, sign, -1, s, ima); + *face_t = lp_build_cube_coord(coord_bld, NULL, +1, t, ima); + *face = lp_build_cube_face(bld, rz, + PIPE_TEX_FACE_POS_Z, + PIPE_TEX_FACE_NEG_Z); + LLVMBuildStore(builder, *face_s, face_s_var); + LLVMBuildStore(builder, *face_t, face_t_var); + LLVMBuildStore(builder, *face, face_var); + } + lp_build_endif(&if_ctx2); + } + + lp_build_endif(&if_ctx); + + *face_s = LLVMBuildLoad(builder, face_s_var, "face_s"); + *face_t = LLVMBuildLoad(builder, face_t_var, "face_t"); + *face = LLVMBuildLoad(builder, face_var, "face"); + } +} + + +/** + * Compute the partial offset of a pixel block along an arbitrary axis. + * + * @param coord coordinate in pixels + * @param stride number of bytes between rows of successive pixel blocks + * @param block_length number of pixels in a pixels block along the coordinate + * axis + * @param out_offset resulting relative offset of the pixel block in bytes + * @param out_subcoord resulting sub-block pixel coordinate + */ +void +lp_build_sample_partial_offset(struct lp_build_context *bld, + unsigned block_length, + LLVMValueRef coord, + LLVMValueRef stride, + LLVMValueRef *out_offset, + LLVMValueRef *out_subcoord) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef offset; + LLVMValueRef subcoord; + + if (block_length == 1) { + subcoord = bld->zero; + } + else { + /* + * Pixel blocks have power of two dimensions. LLVM should convert the + * rem/div to bit arithmetic. + * TODO: Verify this. + * It does indeed BUT it does transform it to scalar (and back) when doing so + * (using roughly extract, shift/and, mov, unpack) (llvm 2.7). + * The generated code looks seriously unfunny and is quite expensive. + */ +#if 0 + LLVMValueRef block_width = lp_build_const_int_vec(bld->type, block_length); + subcoord = LLVMBuildURem(builder, coord, block_width, ""); + coord = LLVMBuildUDiv(builder, coord, block_width, ""); +#else + unsigned logbase2 = util_unsigned_logbase2(block_length); + LLVMValueRef block_shift = lp_build_const_int_vec(bld->gallivm, bld->type, logbase2); + LLVMValueRef block_mask = lp_build_const_int_vec(bld->gallivm, bld->type, block_length - 1); + subcoord = LLVMBuildAnd(builder, coord, block_mask, ""); + coord = LLVMBuildLShr(builder, coord, block_shift, ""); +#endif + } + + offset = lp_build_mul(bld, coord, stride); + + assert(out_offset); + assert(out_subcoord); + + *out_offset = offset; + *out_subcoord = subcoord; +} + + +/** + * Compute the offset of a pixel block. + * + * x, y, z, y_stride, z_stride are vectors, and they refer to pixels. + * + * Returns the relative offset and i,j sub-block coordinates + */ +void +lp_build_sample_offset(struct lp_build_context *bld, + const struct util_format_description *format_desc, + LLVMValueRef x, + LLVMValueRef y, + LLVMValueRef z, + LLVMValueRef y_stride, + LLVMValueRef z_stride, + LLVMValueRef *out_offset, + LLVMValueRef *out_i, + LLVMValueRef *out_j) +{ + LLVMValueRef x_stride; + LLVMValueRef offset; + + x_stride = lp_build_const_vec(bld->gallivm, bld->type, + format_desc->block.bits/8); + + lp_build_sample_partial_offset(bld, + format_desc->block.width, + x, x_stride, + &offset, out_i); + + if (y && y_stride) { + LLVMValueRef y_offset; + lp_build_sample_partial_offset(bld, + format_desc->block.height, + y, y_stride, + &y_offset, out_j); + offset = lp_build_add(bld, offset, y_offset); + } + else { + *out_j = bld->zero; + } + + if (z && z_stride) { + LLVMValueRef z_offset; + LLVMValueRef k; + lp_build_sample_partial_offset(bld, + 1, /* pixel blocks are always 2D */ + z, z_stride, + &z_offset, &k); + offset = lp_build_add(bld, offset, z_offset); + } + + *out_offset = offset; +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h new file mode 100644 index 0000000..8c9d5df --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h @@ -0,0 +1,406 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Texture sampling. + * + * @author Jose Fonseca + */ + +#ifndef LP_BLD_SAMPLE_H +#define LP_BLD_SAMPLE_H + + +#include "pipe/p_format.h" +#include "util/u_debug.h" +#include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_type.h" +#include "gallivm/lp_bld_swizzle.h" + + +struct pipe_resource; +struct pipe_sampler_view; +struct pipe_sampler_state; +struct util_format_description; +struct lp_type; +struct lp_build_context; + + +/** + * Sampler static state. + * + * These are the bits of state from pipe_resource and pipe_sampler_state that + * are embedded in the generated code. + */ +struct lp_sampler_static_state +{ + /* pipe_sampler_view's state */ + enum pipe_format format; + unsigned swizzle_r:3; /**< PIPE_SWIZZLE_* */ + unsigned swizzle_g:3; + unsigned swizzle_b:3; + unsigned swizzle_a:3; + + /* pipe_texture's state */ + unsigned target:3; /**< PIPE_TEXTURE_* */ + unsigned pot_width:1; /**< is the width a power of two? */ + unsigned pot_height:1; + unsigned pot_depth:1; + + /* pipe_sampler_state's state */ + unsigned wrap_s:3; + unsigned wrap_t:3; + unsigned wrap_r:3; + unsigned min_img_filter:2; + unsigned min_mip_filter:2; + unsigned mag_img_filter:2; + unsigned compare_mode:1; + unsigned compare_func:3; + unsigned normalized_coords:1; + unsigned min_max_lod_equal:1; /**< min_lod == max_lod ? */ + unsigned lod_bias_non_zero:1; + unsigned apply_min_lod:1; /**< min_lod > 0 ? */ + unsigned apply_max_lod:1; /**< max_lod < last_level ? */ +}; + + +/** + * Sampler dynamic state. + * + * These are the bits of state from pipe_resource and pipe_sampler_state that + * are computed in runtime. + * + * There are obtained through callbacks, as we don't want to tie the texture + * sampling code generation logic to any particular texture layout or pipe + * driver. + */ +struct lp_sampler_dynamic_state +{ + + /** Obtain the base texture width (returns int32) */ + LLVMValueRef + (*width)( const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + unsigned unit); + + /** Obtain the base texture height (returns int32) */ + LLVMValueRef + (*height)( const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + unsigned unit); + + /** Obtain the base texture depth (returns int32) */ + LLVMValueRef + (*depth)( const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + unsigned unit); + + /** Obtain the number of mipmap levels minus one (returns int32) */ + LLVMValueRef + (*last_level)( const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + unsigned unit); + + /** Obtain stride in bytes between image rows/blocks (returns int32) */ + LLVMValueRef + (*row_stride)( const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + unsigned unit); + + /** Obtain stride in bytes between image slices (returns int32) */ + LLVMValueRef + (*img_stride)( const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + unsigned unit); + + /** Obtain pointer to array of pointers to mimpap levels */ + LLVMValueRef + (*data_ptr)( const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + unsigned unit); + + /** Obtain texture min lod (returns float) */ + LLVMValueRef + (*min_lod)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, unsigned unit); + + /** Obtain texture max lod (returns float) */ + LLVMValueRef + (*max_lod)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, unsigned unit); + + /** Obtain texture lod bias (returns float) */ + LLVMValueRef + (*lod_bias)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, unsigned unit); + + /** Obtain texture border color (returns ptr to float[4]) */ + LLVMValueRef + (*border_color)(const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, unsigned unit); +}; + + +/** + * Keep all information for sampling code generation in a single place. + */ +struct lp_build_sample_context +{ + struct gallivm_state *gallivm; + + const struct lp_sampler_static_state *static_state; + + struct lp_sampler_dynamic_state *dynamic_state; + + const struct util_format_description *format_desc; + + /* See texture_dims() */ + unsigned dims; + + /** regular scalar float type */ + struct lp_type float_type; + struct lp_build_context float_bld; + + /** float vector type */ + struct lp_build_context float_vec_bld; + + /** regular scalar float type */ + struct lp_type int_type; + struct lp_build_context int_bld; + + /** Incoming coordinates type and build context */ + struct lp_type coord_type; + struct lp_build_context coord_bld; + + /** Signed integer coordinates */ + struct lp_type int_coord_type; + struct lp_build_context int_coord_bld; + + /** Unsigned integer texture size */ + struct lp_type int_size_type; + struct lp_build_context int_size_bld; + + /** Unsigned integer texture size */ + struct lp_type float_size_type; + struct lp_build_context float_size_bld; + + /** Output texels type and build context */ + struct lp_type texel_type; + struct lp_build_context texel_bld; + + /* Common dynamic state values */ + LLVMValueRef width; + LLVMValueRef height; + LLVMValueRef depth; + LLVMValueRef row_stride_array; + LLVMValueRef img_stride_array; + LLVMValueRef data_array; + + /** Integer vector with texture width, height, depth */ + LLVMValueRef int_size; +}; + + + +/** + * We only support a few wrap modes in lp_build_sample_wrap_linear_int() at + * this time. Return whether the given mode is supported by that function. + */ +static INLINE boolean +lp_is_simple_wrap_mode(unsigned mode) +{ + switch (mode) { + case PIPE_TEX_WRAP_REPEAT: + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return TRUE; + default: + return FALSE; + } +} + + +static INLINE void +apply_sampler_swizzle(struct lp_build_sample_context *bld, + LLVMValueRef *texel) +{ + unsigned char swizzles[4]; + + swizzles[0] = bld->static_state->swizzle_r; + swizzles[1] = bld->static_state->swizzle_g; + swizzles[2] = bld->static_state->swizzle_b; + swizzles[3] = bld->static_state->swizzle_a; + + lp_build_swizzle_soa_inplace(&bld->texel_bld, texel, swizzles); +} + + +static INLINE unsigned +texture_dims(enum pipe_texture_target tex) +{ + switch (tex) { + case PIPE_TEXTURE_1D: + return 1; + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + case PIPE_TEXTURE_CUBE: + return 2; + case PIPE_TEXTURE_3D: + return 3; + default: + assert(0 && "bad texture target in texture_dims()"); + return 2; + } +} + + +boolean +lp_sampler_wrap_mode_uses_border_color(unsigned mode, + unsigned min_img_filter, + unsigned mag_img_filter); + +/** + * Derive the sampler static state. + */ +void +lp_sampler_static_state(struct lp_sampler_static_state *state, + const struct pipe_sampler_view *view, + const struct pipe_sampler_state *sampler); + + +void +lp_build_lod_selector(struct lp_build_sample_context *bld, + unsigned unit, + const LLVMValueRef ddx[4], + const LLVMValueRef ddy[4], + LLVMValueRef lod_bias, /* optional */ + LLVMValueRef explicit_lod, /* optional */ + unsigned mip_filter, + LLVMValueRef *out_lod_ipart, + LLVMValueRef *out_lod_fpart); + +void +lp_build_nearest_mip_level(struct lp_build_sample_context *bld, + unsigned unit, + LLVMValueRef lod, + LLVMValueRef *level_out); + +void +lp_build_linear_mip_levels(struct lp_build_sample_context *bld, + unsigned unit, + LLVMValueRef lod_ipart, + LLVMValueRef *lod_fpart_inout, + LLVMValueRef *level0_out, + LLVMValueRef *level1_out); + +LLVMValueRef +lp_build_get_mipmap_level(struct lp_build_sample_context *bld, + LLVMValueRef level); + +LLVMValueRef +lp_build_get_const_mipmap_level(struct lp_build_sample_context *bld, + int level); + + +void +lp_build_mipmap_level_sizes(struct lp_build_sample_context *bld, + LLVMValueRef ilevel, + LLVMValueRef *out_size_vec, + LLVMValueRef *row_stride_vec, + LLVMValueRef *img_stride_vec); + + +void +lp_build_extract_image_sizes(struct lp_build_sample_context *bld, + struct lp_type size_type, + struct lp_type coord_type, + LLVMValueRef size, + LLVMValueRef *out_width, + LLVMValueRef *out_height, + LLVMValueRef *out_depth); + + +void +lp_build_unnormalized_coords(struct lp_build_sample_context *bld, + LLVMValueRef flt_size, + LLVMValueRef *s, + LLVMValueRef *t, + LLVMValueRef *r); + + +void +lp_build_cube_lookup(struct lp_build_sample_context *bld, + LLVMValueRef s, + LLVMValueRef t, + LLVMValueRef r, + LLVMValueRef *face, + LLVMValueRef *face_s, + LLVMValueRef *face_t); + + +void +lp_build_sample_partial_offset(struct lp_build_context *bld, + unsigned block_length, + LLVMValueRef coord, + LLVMValueRef stride, + LLVMValueRef *out_offset, + LLVMValueRef *out_i); + + +void +lp_build_sample_offset(struct lp_build_context *bld, + const struct util_format_description *format_desc, + LLVMValueRef x, + LLVMValueRef y, + LLVMValueRef z, + LLVMValueRef y_stride, + LLVMValueRef z_stride, + LLVMValueRef *out_offset, + LLVMValueRef *out_i, + LLVMValueRef *out_j); + + +void +lp_build_sample_soa(struct gallivm_state *gallivm, + const struct lp_sampler_static_state *static_state, + struct lp_sampler_dynamic_state *dynamic_state, + struct lp_type fp_type, + unsigned unit, + unsigned num_coords, + const LLVMValueRef *coords, + const LLVMValueRef *ddx, + const LLVMValueRef *ddy, + LLVMValueRef lod_bias, + LLVMValueRef explicit_lod, + LLVMValueRef texel_out[4]); + +void +lp_build_sample_nop(struct gallivm_state *gallivm, struct lp_type type, + LLVMValueRef texel_out[4]); + + +#endif /* LP_BLD_SAMPLE_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c new file mode 100644 index 0000000..991f6fa --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c @@ -0,0 +1,1103 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Texture sampling -- SoA. + * + * @author Jose Fonseca + * @author Brian Paul + */ + +#include "pipe/p_defines.h" +#include "pipe/p_state.h" +#include "util/u_debug.h" +#include "util/u_dump.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_format.h" +#include "lp_bld_debug.h" +#include "lp_bld_type.h" +#include "lp_bld_const.h" +#include "lp_bld_conv.h" +#include "lp_bld_arit.h" +#include "lp_bld_bitarit.h" +#include "lp_bld_logic.h" +#include "lp_bld_swizzle.h" +#include "lp_bld_pack.h" +#include "lp_bld_flow.h" +#include "lp_bld_gather.h" +#include "lp_bld_format.h" +#include "lp_bld_init.h" +#include "lp_bld_sample.h" +#include "lp_bld_sample_aos.h" +#include "lp_bld_quad.h" + + +/** + * Build LLVM code for texture coord wrapping, for nearest filtering, + * for scaled integer texcoords. + * \param block_length is the length of the pixel block along the + * coordinate axis + * \param coord the incoming texcoord (s,t,r or q) scaled to the texture size + * \param length the texture size along one dimension + * \param stride pixel stride along the coordinate axis (in bytes) + * \param is_pot if TRUE, length is a power of two + * \param wrap_mode one of PIPE_TEX_WRAP_x + * \param out_offset byte offset for the wrapped coordinate + * \param out_i resulting sub-block pixel coordinate for coord0 + */ +static void +lp_build_sample_wrap_nearest_int(struct lp_build_sample_context *bld, + unsigned block_length, + LLVMValueRef coord, + LLVMValueRef length, + LLVMValueRef stride, + boolean is_pot, + unsigned wrap_mode, + LLVMValueRef *out_offset, + LLVMValueRef *out_i) +{ + struct lp_build_context *int_coord_bld = &bld->int_coord_bld; + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef length_minus_one; + + length_minus_one = lp_build_sub(int_coord_bld, length, int_coord_bld->one); + + switch(wrap_mode) { + case PIPE_TEX_WRAP_REPEAT: + if(is_pot) + coord = LLVMBuildAnd(builder, coord, length_minus_one, ""); + else { + /* Add a bias to the texcoord to handle negative coords */ + LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024); + coord = LLVMBuildAdd(builder, coord, bias, ""); + coord = LLVMBuildURem(builder, coord, length, ""); + } + break; + + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + coord = lp_build_max(int_coord_bld, coord, int_coord_bld->zero); + coord = lp_build_min(int_coord_bld, coord, length_minus_one); + break; + + case PIPE_TEX_WRAP_CLAMP: + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + case PIPE_TEX_WRAP_MIRROR_REPEAT: + case PIPE_TEX_WRAP_MIRROR_CLAMP: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + default: + assert(0); + } + + lp_build_sample_partial_offset(int_coord_bld, block_length, coord, stride, + out_offset, out_i); +} + + +/** + * Build LLVM code for texture coord wrapping, for linear filtering, + * for scaled integer texcoords. + * \param block_length is the length of the pixel block along the + * coordinate axis + * \param coord0 the incoming texcoord (s,t,r or q) scaled to the texture size + * \param length the texture size along one dimension + * \param stride pixel stride along the coordinate axis (in bytes) + * \param is_pot if TRUE, length is a power of two + * \param wrap_mode one of PIPE_TEX_WRAP_x + * \param offset0 resulting relative offset for coord0 + * \param offset1 resulting relative offset for coord0 + 1 + * \param i0 resulting sub-block pixel coordinate for coord0 + * \param i1 resulting sub-block pixel coordinate for coord0 + 1 + */ +static void +lp_build_sample_wrap_linear_int(struct lp_build_sample_context *bld, + unsigned block_length, + LLVMValueRef coord0, + LLVMValueRef length, + LLVMValueRef stride, + boolean is_pot, + unsigned wrap_mode, + LLVMValueRef *offset0, + LLVMValueRef *offset1, + LLVMValueRef *i0, + LLVMValueRef *i1) +{ + struct lp_build_context *int_coord_bld = &bld->int_coord_bld; + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef length_minus_one; + LLVMValueRef lmask, umask, mask; + + if (block_length != 1) { + /* + * If the pixel block covers more than one pixel then there is no easy + * way to calculate offset1 relative to offset0. Instead, compute them + * independently. + */ + + LLVMValueRef coord1; + + lp_build_sample_wrap_nearest_int(bld, + block_length, + coord0, + length, + stride, + is_pot, + wrap_mode, + offset0, i0); + + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + + lp_build_sample_wrap_nearest_int(bld, + block_length, + coord1, + length, + stride, + is_pot, + wrap_mode, + offset1, i1); + + return; + } + + /* + * Scalar pixels -- try to compute offset0 and offset1 with a single stride + * multiplication. + */ + + *i0 = int_coord_bld->zero; + *i1 = int_coord_bld->zero; + + length_minus_one = lp_build_sub(int_coord_bld, length, int_coord_bld->one); + + switch(wrap_mode) { + case PIPE_TEX_WRAP_REPEAT: + if (is_pot) { + coord0 = LLVMBuildAnd(builder, coord0, length_minus_one, ""); + } + else { + /* Add a bias to the texcoord to handle negative coords */ + LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024); + coord0 = LLVMBuildAdd(builder, coord0, bias, ""); + coord0 = LLVMBuildURem(builder, coord0, length, ""); + } + + mask = lp_build_compare(bld->gallivm, int_coord_bld->type, + PIPE_FUNC_NOTEQUAL, coord0, length_minus_one); + + *offset0 = lp_build_mul(int_coord_bld, coord0, stride); + *offset1 = LLVMBuildAnd(builder, + lp_build_add(int_coord_bld, *offset0, stride), + mask, ""); + break; + + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + lmask = lp_build_compare(int_coord_bld->gallivm, int_coord_bld->type, + PIPE_FUNC_GEQUAL, coord0, int_coord_bld->zero); + umask = lp_build_compare(int_coord_bld->gallivm, int_coord_bld->type, + PIPE_FUNC_LESS, coord0, length_minus_one); + + coord0 = lp_build_select(int_coord_bld, lmask, coord0, int_coord_bld->zero); + coord0 = lp_build_select(int_coord_bld, umask, coord0, length_minus_one); + + mask = LLVMBuildAnd(builder, lmask, umask, ""); + + *offset0 = lp_build_mul(int_coord_bld, coord0, stride); + *offset1 = lp_build_add(int_coord_bld, + *offset0, + LLVMBuildAnd(builder, stride, mask, "")); + break; + + case PIPE_TEX_WRAP_CLAMP: + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + case PIPE_TEX_WRAP_MIRROR_REPEAT: + case PIPE_TEX_WRAP_MIRROR_CLAMP: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + default: + assert(0); + *offset0 = int_coord_bld->zero; + *offset1 = int_coord_bld->zero; + break; + } +} + + +/** + * Sample a single texture image with nearest sampling. + * If sampling a cube texture, r = cube face in [0,5]. + * Return filtered color as two vectors of 16-bit fixed point values. + */ +static void +lp_build_sample_image_nearest(struct lp_build_sample_context *bld, + LLVMValueRef int_size, + LLVMValueRef row_stride_vec, + LLVMValueRef img_stride_vec, + LLVMValueRef data_ptr, + LLVMValueRef s, + LLVMValueRef t, + LLVMValueRef r, + LLVMValueRef *colors_lo, + LLVMValueRef *colors_hi) +{ + const unsigned dims = bld->dims; + LLVMBuilderRef builder = bld->gallivm->builder; + struct lp_build_context i32, h16, u8n; + LLVMTypeRef i32_vec_type, h16_vec_type, u8n_vec_type; + LLVMValueRef i32_c8; + LLVMValueRef width_vec, height_vec, depth_vec; + LLVMValueRef s_ipart, t_ipart = NULL, r_ipart = NULL; + LLVMValueRef x_stride; + LLVMValueRef x_offset, offset; + LLVMValueRef x_subcoord, y_subcoord, z_subcoord; + + lp_build_context_init(&i32, bld->gallivm, lp_type_int_vec(32)); + lp_build_context_init(&h16, bld->gallivm, lp_type_ufixed(16)); + lp_build_context_init(&u8n, bld->gallivm, lp_type_unorm(8)); + + i32_vec_type = lp_build_vec_type(bld->gallivm, i32.type); + h16_vec_type = lp_build_vec_type(bld->gallivm, h16.type); + u8n_vec_type = lp_build_vec_type(bld->gallivm, u8n.type); + + lp_build_extract_image_sizes(bld, + bld->int_size_type, + bld->int_coord_type, + int_size, + &width_vec, + &height_vec, + &depth_vec); + + if (bld->static_state->normalized_coords) { + LLVMValueRef scaled_size; + LLVMValueRef flt_size; + + /* scale size by 256 (8 fractional bits) */ + scaled_size = lp_build_shl_imm(&bld->int_size_bld, int_size, 8); + + flt_size = lp_build_int_to_float(&bld->float_size_bld, scaled_size); + + lp_build_unnormalized_coords(bld, flt_size, &s, &t, &r); + } + else { + /* scale coords by 256 (8 fractional bits) */ + s = lp_build_mul_imm(&bld->coord_bld, s, 256); + if (dims >= 2) + t = lp_build_mul_imm(&bld->coord_bld, t, 256); + if (dims >= 3) + r = lp_build_mul_imm(&bld->coord_bld, r, 256); + } + + /* convert float to int */ + s = LLVMBuildFPToSI(builder, s, i32_vec_type, ""); + if (dims >= 2) + t = LLVMBuildFPToSI(builder, t, i32_vec_type, ""); + if (dims >= 3) + r = LLVMBuildFPToSI(builder, r, i32_vec_type, ""); + + /* compute floor (shift right 8) */ + i32_c8 = lp_build_const_int_vec(bld->gallivm, i32.type, 8); + s_ipart = LLVMBuildAShr(builder, s, i32_c8, ""); + if (dims >= 2) + t_ipart = LLVMBuildAShr(builder, t, i32_c8, ""); + if (dims >= 3) + r_ipart = LLVMBuildAShr(builder, r, i32_c8, ""); + + /* get pixel, row, image strides */ + x_stride = lp_build_const_vec(bld->gallivm, + bld->int_coord_bld.type, + bld->format_desc->block.bits/8); + + /* Do texcoord wrapping, compute texel offset */ + lp_build_sample_wrap_nearest_int(bld, + bld->format_desc->block.width, + s_ipart, width_vec, x_stride, + bld->static_state->pot_width, + bld->static_state->wrap_s, + &x_offset, &x_subcoord); + offset = x_offset; + if (dims >= 2) { + LLVMValueRef y_offset; + lp_build_sample_wrap_nearest_int(bld, + bld->format_desc->block.height, + t_ipart, height_vec, row_stride_vec, + bld->static_state->pot_height, + bld->static_state->wrap_t, + &y_offset, &y_subcoord); + offset = lp_build_add(&bld->int_coord_bld, offset, y_offset); + if (dims >= 3) { + LLVMValueRef z_offset; + lp_build_sample_wrap_nearest_int(bld, + 1, /* block length (depth) */ + r_ipart, depth_vec, img_stride_vec, + bld->static_state->pot_height, + bld->static_state->wrap_r, + &z_offset, &z_subcoord); + offset = lp_build_add(&bld->int_coord_bld, offset, z_offset); + } + else if (bld->static_state->target == PIPE_TEXTURE_CUBE) { + LLVMValueRef z_offset; + /* The r coord is the cube face in [0,5] */ + z_offset = lp_build_mul(&bld->int_coord_bld, r, img_stride_vec); + offset = lp_build_add(&bld->int_coord_bld, offset, z_offset); + } + } + + /* + * Fetch the pixels as 4 x 32bit (rgba order might differ): + * + * rgba0 rgba1 rgba2 rgba3 + * + * bit cast them into 16 x u8 + * + * r0 g0 b0 a0 r1 g1 b1 a1 r2 g2 b2 a2 r3 g3 b3 a3 + * + * unpack them into two 8 x i16: + * + * r0 g0 b0 a0 r1 g1 b1 a1 + * r2 g2 b2 a2 r3 g3 b3 a3 + * + * The higher 8 bits of the resulting elements will be zero. + */ + { + LLVMValueRef rgba8; + + if (util_format_is_rgba8_variant(bld->format_desc)) { + /* + * Given the format is a rgba8, just read the pixels as is, + * without any swizzling. Swizzling will be done later. + */ + rgba8 = lp_build_gather(bld->gallivm, + bld->texel_type.length, + bld->format_desc->block.bits, + bld->texel_type.width, + data_ptr, offset); + + rgba8 = LLVMBuildBitCast(builder, rgba8, u8n_vec_type, ""); + } + else { + rgba8 = lp_build_fetch_rgba_aos(bld->gallivm, + bld->format_desc, + u8n.type, + data_ptr, offset, + x_subcoord, + y_subcoord); + } + + /* Expand one 4*rgba8 to two 2*rgba16 */ + lp_build_unpack2(bld->gallivm, u8n.type, h16.type, + rgba8, + colors_lo, colors_hi); + } +} + + +/** + * Sample a single texture image with (bi-)(tri-)linear sampling. + * Return filtered color as two vectors of 16-bit fixed point values. + */ +static void +lp_build_sample_image_linear(struct lp_build_sample_context *bld, + LLVMValueRef int_size, + LLVMValueRef row_stride_vec, + LLVMValueRef img_stride_vec, + LLVMValueRef data_ptr, + LLVMValueRef s, + LLVMValueRef t, + LLVMValueRef r, + LLVMValueRef *colors_lo, + LLVMValueRef *colors_hi) +{ + const unsigned dims = bld->dims; + LLVMBuilderRef builder = bld->gallivm->builder; + struct lp_build_context i32, h16, u8n; + LLVMTypeRef i32_vec_type, h16_vec_type, u8n_vec_type; + LLVMValueRef i32_c8, i32_c128, i32_c255; + LLVMValueRef width_vec, height_vec, depth_vec; + LLVMValueRef s_ipart, s_fpart, s_fpart_lo, s_fpart_hi; + LLVMValueRef t_ipart = NULL, t_fpart = NULL, t_fpart_lo = NULL, t_fpart_hi = NULL; + LLVMValueRef r_ipart = NULL, r_fpart = NULL, r_fpart_lo = NULL, r_fpart_hi = NULL; + LLVMValueRef x_stride, y_stride, z_stride; + LLVMValueRef x_offset0, x_offset1; + LLVMValueRef y_offset0, y_offset1; + LLVMValueRef z_offset0, z_offset1; + LLVMValueRef offset[2][2][2]; /* [z][y][x] */ + LLVMValueRef x_subcoord[2], y_subcoord[2], z_subcoord[2]; + LLVMValueRef neighbors_lo[2][2][2]; /* [z][y][x] */ + LLVMValueRef neighbors_hi[2][2][2]; /* [z][y][x] */ + LLVMValueRef packed_lo, packed_hi; + unsigned x, y, z; + unsigned i, j, k; + unsigned numj, numk; + + lp_build_context_init(&i32, bld->gallivm, lp_type_int_vec(32)); + lp_build_context_init(&h16, bld->gallivm, lp_type_ufixed(16)); + lp_build_context_init(&u8n, bld->gallivm, lp_type_unorm(8)); + + i32_vec_type = lp_build_vec_type(bld->gallivm, i32.type); + h16_vec_type = lp_build_vec_type(bld->gallivm, h16.type); + u8n_vec_type = lp_build_vec_type(bld->gallivm, u8n.type); + + lp_build_extract_image_sizes(bld, + bld->int_size_type, + bld->int_coord_type, + int_size, + &width_vec, + &height_vec, + &depth_vec); + + if (bld->static_state->normalized_coords) { + LLVMValueRef scaled_size; + LLVMValueRef flt_size; + + /* scale size by 256 (8 fractional bits) */ + scaled_size = lp_build_shl_imm(&bld->int_size_bld, int_size, 8); + + flt_size = lp_build_int_to_float(&bld->float_size_bld, scaled_size); + + lp_build_unnormalized_coords(bld, flt_size, &s, &t, &r); + } + else { + /* scale coords by 256 (8 fractional bits) */ + s = lp_build_mul_imm(&bld->coord_bld, s, 256); + if (dims >= 2) + t = lp_build_mul_imm(&bld->coord_bld, t, 256); + if (dims >= 3) + r = lp_build_mul_imm(&bld->coord_bld, r, 256); + } + + /* convert float to int */ + s = LLVMBuildFPToSI(builder, s, i32_vec_type, ""); + if (dims >= 2) + t = LLVMBuildFPToSI(builder, t, i32_vec_type, ""); + if (dims >= 3) + r = LLVMBuildFPToSI(builder, r, i32_vec_type, ""); + + /* subtract 0.5 (add -128) */ + i32_c128 = lp_build_const_int_vec(bld->gallivm, i32.type, -128); + s = LLVMBuildAdd(builder, s, i32_c128, ""); + if (dims >= 2) { + t = LLVMBuildAdd(builder, t, i32_c128, ""); + } + if (dims >= 3) { + r = LLVMBuildAdd(builder, r, i32_c128, ""); + } + + /* compute floor (shift right 8) */ + i32_c8 = lp_build_const_int_vec(bld->gallivm, i32.type, 8); + s_ipart = LLVMBuildAShr(builder, s, i32_c8, ""); + if (dims >= 2) + t_ipart = LLVMBuildAShr(builder, t, i32_c8, ""); + if (dims >= 3) + r_ipart = LLVMBuildAShr(builder, r, i32_c8, ""); + + /* compute fractional part (AND with 0xff) */ + i32_c255 = lp_build_const_int_vec(bld->gallivm, i32.type, 255); + s_fpart = LLVMBuildAnd(builder, s, i32_c255, ""); + if (dims >= 2) + t_fpart = LLVMBuildAnd(builder, t, i32_c255, ""); + if (dims >= 3) + r_fpart = LLVMBuildAnd(builder, r, i32_c255, ""); + + /* get pixel, row and image strides */ + x_stride = lp_build_const_vec(bld->gallivm, bld->int_coord_bld.type, + bld->format_desc->block.bits/8); + y_stride = row_stride_vec; + z_stride = img_stride_vec; + + /* do texcoord wrapping and compute texel offsets */ + lp_build_sample_wrap_linear_int(bld, + bld->format_desc->block.width, + s_ipart, width_vec, x_stride, + bld->static_state->pot_width, + bld->static_state->wrap_s, + &x_offset0, &x_offset1, + &x_subcoord[0], &x_subcoord[1]); + for (z = 0; z < 2; z++) { + for (y = 0; y < 2; y++) { + offset[z][y][0] = x_offset0; + offset[z][y][1] = x_offset1; + } + } + + if (dims >= 2) { + lp_build_sample_wrap_linear_int(bld, + bld->format_desc->block.height, + t_ipart, height_vec, y_stride, + bld->static_state->pot_height, + bld->static_state->wrap_t, + &y_offset0, &y_offset1, + &y_subcoord[0], &y_subcoord[1]); + + for (z = 0; z < 2; z++) { + for (x = 0; x < 2; x++) { + offset[z][0][x] = lp_build_add(&bld->int_coord_bld, + offset[z][0][x], y_offset0); + offset[z][1][x] = lp_build_add(&bld->int_coord_bld, + offset[z][1][x], y_offset1); + } + } + } + + if (dims >= 3) { + lp_build_sample_wrap_linear_int(bld, + bld->format_desc->block.height, + r_ipart, depth_vec, z_stride, + bld->static_state->pot_depth, + bld->static_state->wrap_r, + &z_offset0, &z_offset1, + &z_subcoord[0], &z_subcoord[1]); + for (y = 0; y < 2; y++) { + for (x = 0; x < 2; x++) { + offset[0][y][x] = lp_build_add(&bld->int_coord_bld, + offset[0][y][x], z_offset0); + offset[1][y][x] = lp_build_add(&bld->int_coord_bld, + offset[1][y][x], z_offset1); + } + } + } + else if (bld->static_state->target == PIPE_TEXTURE_CUBE) { + LLVMValueRef z_offset; + z_offset = lp_build_mul(&bld->int_coord_bld, r, img_stride_vec); + for (y = 0; y < 2; y++) { + for (x = 0; x < 2; x++) { + /* The r coord is the cube face in [0,5] */ + offset[0][y][x] = lp_build_add(&bld->int_coord_bld, + offset[0][y][x], z_offset); + } + } + } + + /* + * Transform 4 x i32 in + * + * s_fpart = {s0, s1, s2, s3} + * + * into 8 x i16 + * + * s_fpart = {00, s0, 00, s1, 00, s2, 00, s3} + * + * into two 8 x i16 + * + * s_fpart_lo = {s0, s0, s0, s0, s1, s1, s1, s1} + * s_fpart_hi = {s2, s2, s2, s2, s3, s3, s3, s3} + * + * and likewise for t_fpart. There is no risk of loosing precision here + * since the fractional parts only use the lower 8bits. + */ + s_fpart = LLVMBuildBitCast(builder, s_fpart, h16_vec_type, ""); + if (dims >= 2) + t_fpart = LLVMBuildBitCast(builder, t_fpart, h16_vec_type, ""); + if (dims >= 3) + r_fpart = LLVMBuildBitCast(builder, r_fpart, h16_vec_type, ""); + + { + LLVMTypeRef elem_type = LLVMInt32TypeInContext(bld->gallivm->context); + LLVMValueRef shuffles_lo[LP_MAX_VECTOR_LENGTH]; + LLVMValueRef shuffles_hi[LP_MAX_VECTOR_LENGTH]; + LLVMValueRef shuffle_lo; + LLVMValueRef shuffle_hi; + + for (j = 0; j < h16.type.length; j += 4) { +#ifdef PIPE_ARCH_LITTLE_ENDIAN + unsigned subindex = 0; +#else + unsigned subindex = 1; +#endif + LLVMValueRef index; + + index = LLVMConstInt(elem_type, j/2 + subindex, 0); + for (i = 0; i < 4; ++i) + shuffles_lo[j + i] = index; + + index = LLVMConstInt(elem_type, h16.type.length/2 + j/2 + subindex, 0); + for (i = 0; i < 4; ++i) + shuffles_hi[j + i] = index; + } + + shuffle_lo = LLVMConstVector(shuffles_lo, h16.type.length); + shuffle_hi = LLVMConstVector(shuffles_hi, h16.type.length); + + s_fpart_lo = LLVMBuildShuffleVector(builder, s_fpart, h16.undef, + shuffle_lo, ""); + s_fpart_hi = LLVMBuildShuffleVector(builder, s_fpart, h16.undef, + shuffle_hi, ""); + if (dims >= 2) { + t_fpart_lo = LLVMBuildShuffleVector(builder, t_fpart, h16.undef, + shuffle_lo, ""); + t_fpart_hi = LLVMBuildShuffleVector(builder, t_fpart, h16.undef, + shuffle_hi, ""); + } + if (dims >= 3) { + r_fpart_lo = LLVMBuildShuffleVector(builder, r_fpart, h16.undef, + shuffle_lo, ""); + r_fpart_hi = LLVMBuildShuffleVector(builder, r_fpart, h16.undef, + shuffle_hi, ""); + } + } + + /* + * Fetch the pixels as 4 x 32bit (rgba order might differ): + * + * rgba0 rgba1 rgba2 rgba3 + * + * bit cast them into 16 x u8 + * + * r0 g0 b0 a0 r1 g1 b1 a1 r2 g2 b2 a2 r3 g3 b3 a3 + * + * unpack them into two 8 x i16: + * + * r0 g0 b0 a0 r1 g1 b1 a1 + * r2 g2 b2 a2 r3 g3 b3 a3 + * + * The higher 8 bits of the resulting elements will be zero. + */ + numj = 1 + (dims >= 2); + numk = 1 + (dims >= 3); + + for (k = 0; k < numk; k++) { + for (j = 0; j < numj; j++) { + for (i = 0; i < 2; i++) { + LLVMValueRef rgba8; + + if (util_format_is_rgba8_variant(bld->format_desc)) { + /* + * Given the format is a rgba8, just read the pixels as is, + * without any swizzling. Swizzling will be done later. + */ + rgba8 = lp_build_gather(bld->gallivm, + bld->texel_type.length, + bld->format_desc->block.bits, + bld->texel_type.width, + data_ptr, offset[k][j][i]); + + rgba8 = LLVMBuildBitCast(builder, rgba8, u8n_vec_type, ""); + } + else { + rgba8 = lp_build_fetch_rgba_aos(bld->gallivm, + bld->format_desc, + u8n.type, + data_ptr, offset[k][j][i], + x_subcoord[i], + y_subcoord[j]); + } + + /* Expand one 4*rgba8 to two 2*rgba16 */ + lp_build_unpack2(bld->gallivm, u8n.type, h16.type, + rgba8, + &neighbors_lo[k][j][i], &neighbors_hi[k][j][i]); + } + } + } + + /* + * Linear interpolation with 8.8 fixed point. + */ + if (dims == 1) { + /* 1-D lerp */ + packed_lo = lp_build_lerp(&h16, + s_fpart_lo, + neighbors_lo[0][0][0], + neighbors_lo[0][0][1]); + + packed_hi = lp_build_lerp(&h16, + s_fpart_hi, + neighbors_hi[0][0][0], + neighbors_hi[0][0][1]); + } + else { + /* 2-D lerp */ + packed_lo = lp_build_lerp_2d(&h16, + s_fpart_lo, t_fpart_lo, + neighbors_lo[0][0][0], + neighbors_lo[0][0][1], + neighbors_lo[0][1][0], + neighbors_lo[0][1][1]); + + packed_hi = lp_build_lerp_2d(&h16, + s_fpart_hi, t_fpart_hi, + neighbors_hi[0][0][0], + neighbors_hi[0][0][1], + neighbors_hi[0][1][0], + neighbors_hi[0][1][1]); + + if (dims >= 3) { + LLVMValueRef packed_lo2, packed_hi2; + + /* lerp in the second z slice */ + packed_lo2 = lp_build_lerp_2d(&h16, + s_fpart_lo, t_fpart_lo, + neighbors_lo[1][0][0], + neighbors_lo[1][0][1], + neighbors_lo[1][1][0], + neighbors_lo[1][1][1]); + + packed_hi2 = lp_build_lerp_2d(&h16, + s_fpart_hi, t_fpart_hi, + neighbors_hi[1][0][0], + neighbors_hi[1][0][1], + neighbors_hi[1][1][0], + neighbors_hi[1][1][1]); + /* interp between two z slices */ + packed_lo = lp_build_lerp(&h16, r_fpart_lo, + packed_lo, packed_lo2); + packed_hi = lp_build_lerp(&h16, r_fpart_hi, + packed_hi, packed_hi2); + } + } + + *colors_lo = packed_lo; + *colors_hi = packed_hi; +} + + +/** + * Sample the texture/mipmap using given image filter and mip filter. + * data0_ptr and data1_ptr point to the two mipmap levels to sample + * from. width0/1_vec, height0/1_vec, depth0/1_vec indicate their sizes. + * If we're using nearest miplevel sampling the '1' values will be null/unused. + */ +static void +lp_build_sample_mipmap(struct lp_build_sample_context *bld, + unsigned img_filter, + unsigned mip_filter, + LLVMValueRef s, + LLVMValueRef t, + LLVMValueRef r, + LLVMValueRef ilevel0, + LLVMValueRef ilevel1, + LLVMValueRef lod_fpart, + LLVMValueRef colors_lo_var, + LLVMValueRef colors_hi_var) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef size0; + LLVMValueRef size1; + LLVMValueRef row_stride0_vec; + LLVMValueRef row_stride1_vec; + LLVMValueRef img_stride0_vec; + LLVMValueRef img_stride1_vec; + LLVMValueRef data_ptr0; + LLVMValueRef data_ptr1; + LLVMValueRef colors0_lo, colors0_hi; + LLVMValueRef colors1_lo, colors1_hi; + + /* sample the first mipmap level */ + lp_build_mipmap_level_sizes(bld, ilevel0, + &size0, + &row_stride0_vec, &img_stride0_vec); + data_ptr0 = lp_build_get_mipmap_level(bld, ilevel0); + if (img_filter == PIPE_TEX_FILTER_NEAREST) { + lp_build_sample_image_nearest(bld, + size0, + row_stride0_vec, img_stride0_vec, + data_ptr0, s, t, r, + &colors0_lo, &colors0_hi); + } + else { + assert(img_filter == PIPE_TEX_FILTER_LINEAR); + lp_build_sample_image_linear(bld, + size0, + row_stride0_vec, img_stride0_vec, + data_ptr0, s, t, r, + &colors0_lo, &colors0_hi); + } + + /* Store the first level's colors in the output variables */ + LLVMBuildStore(builder, colors0_lo, colors_lo_var); + LLVMBuildStore(builder, colors0_hi, colors_hi_var); + + if (mip_filter == PIPE_TEX_MIPFILTER_LINEAR) { + LLVMValueRef h16_scale = lp_build_const_float(bld->gallivm, 256.0); + LLVMTypeRef i32_type = LLVMIntTypeInContext(bld->gallivm->context, 32); + struct lp_build_if_state if_ctx; + LLVMValueRef need_lerp; + + lod_fpart = LLVMBuildFMul(builder, lod_fpart, h16_scale, ""); + lod_fpart = LLVMBuildFPToSI(builder, lod_fpart, i32_type, "lod_fpart.fixed16"); + + /* need_lerp = lod_fpart > 0 */ + need_lerp = LLVMBuildICmp(builder, LLVMIntSGT, + lod_fpart, LLVMConstNull(i32_type), + "need_lerp"); + + lp_build_if(&if_ctx, bld->gallivm, need_lerp); + { + struct lp_build_context h16_bld; + + lp_build_context_init(&h16_bld, bld->gallivm, lp_type_ufixed(16)); + + /* sample the second mipmap level */ + lp_build_mipmap_level_sizes(bld, ilevel1, + &size1, + &row_stride1_vec, &img_stride1_vec); + data_ptr1 = lp_build_get_mipmap_level(bld, ilevel1); + if (img_filter == PIPE_TEX_FILTER_NEAREST) { + lp_build_sample_image_nearest(bld, + size1, + row_stride1_vec, img_stride1_vec, + data_ptr1, s, t, r, + &colors1_lo, &colors1_hi); + } + else { + lp_build_sample_image_linear(bld, + size1, + row_stride1_vec, img_stride1_vec, + data_ptr1, s, t, r, + &colors1_lo, &colors1_hi); + } + + /* interpolate samples from the two mipmap levels */ + + lod_fpart = LLVMBuildTrunc(builder, lod_fpart, h16_bld.elem_type, ""); + lod_fpart = lp_build_broadcast_scalar(&h16_bld, lod_fpart); + +#if HAVE_LLVM == 0x208 + /* This is a work-around for a bug in LLVM 2.8. + * Evidently, something goes wrong in the construction of the + * lod_fpart short[8] vector. Adding this no-effect shuffle seems + * to force the vector to be properly constructed. + * Tested with mesa-demos/src/tests/mipmap_limits.c (press t, f). + */ + { + LLVMValueRef shuffles[8], shuffle; + int i; + assert(h16_bld.type.length <= Elements(shuffles)); + for (i = 0; i < h16_bld.type.length; i++) + shuffles[i] = lp_build_const_int32(bld->gallivm, 2 * (i & 1)); + shuffle = LLVMConstVector(shuffles, h16_bld.type.length); + lod_fpart = LLVMBuildShuffleVector(builder, + lod_fpart, lod_fpart, + shuffle, ""); + } +#endif + + colors0_lo = lp_build_lerp(&h16_bld, lod_fpart, + colors0_lo, colors1_lo); + colors0_hi = lp_build_lerp(&h16_bld, lod_fpart, + colors0_hi, colors1_hi); + + LLVMBuildStore(builder, colors0_lo, colors_lo_var); + LLVMBuildStore(builder, colors0_hi, colors_hi_var); + } + lp_build_endif(&if_ctx); + } +} + + + +/** + * Texture sampling in AoS format. Used when sampling common 32-bit/texel + * formats. 1D/2D/3D/cube texture supported. All mipmap sampling modes + * but only limited texture coord wrap modes. + */ +void +lp_build_sample_aos(struct lp_build_sample_context *bld, + unsigned unit, + LLVMValueRef s, + LLVMValueRef t, + LLVMValueRef r, + const LLVMValueRef *ddx, + const LLVMValueRef *ddy, + LLVMValueRef lod_bias, /* optional */ + LLVMValueRef explicit_lod, /* optional */ + LLVMValueRef texel_out[4]) +{ + struct lp_build_context *int_bld = &bld->int_bld; + LLVMBuilderRef builder = bld->gallivm->builder; + const unsigned mip_filter = bld->static_state->min_mip_filter; + const unsigned min_filter = bld->static_state->min_img_filter; + const unsigned mag_filter = bld->static_state->mag_img_filter; + const unsigned dims = bld->dims; + LLVMValueRef lod_ipart = NULL, lod_fpart = NULL; + LLVMValueRef ilevel0, ilevel1 = NULL; + LLVMValueRef packed, packed_lo, packed_hi; + LLVMValueRef unswizzled[4]; + LLVMValueRef face_ddx[4], face_ddy[4]; + struct lp_build_context h16_bld; + LLVMValueRef i32t_zero = lp_build_const_int32(bld->gallivm, 0); + + /* we only support the common/simple wrap modes at this time */ + assert(lp_is_simple_wrap_mode(bld->static_state->wrap_s)); + if (dims >= 2) + assert(lp_is_simple_wrap_mode(bld->static_state->wrap_t)); + if (dims >= 3) + assert(lp_is_simple_wrap_mode(bld->static_state->wrap_r)); + + + /* make 16-bit fixed-pt builder context */ + lp_build_context_init(&h16_bld, bld->gallivm, lp_type_ufixed(16)); + + /* cube face selection, compute pre-face coords, etc. */ + if (bld->static_state->target == PIPE_TEXTURE_CUBE) { + LLVMValueRef face, face_s, face_t; + lp_build_cube_lookup(bld, s, t, r, &face, &face_s, &face_t); + s = face_s; /* vec */ + t = face_t; /* vec */ + /* use 'r' to indicate cube face */ + r = lp_build_broadcast_scalar(&bld->int_coord_bld, face); /* vec */ + + /* recompute ddx, ddy using the new (s,t) face texcoords */ + face_ddx[0] = lp_build_scalar_ddx(&bld->coord_bld, s); + face_ddx[1] = lp_build_scalar_ddx(&bld->coord_bld, t); + face_ddx[2] = NULL; + face_ddx[3] = NULL; + face_ddy[0] = lp_build_scalar_ddy(&bld->coord_bld, s); + face_ddy[1] = lp_build_scalar_ddy(&bld->coord_bld, t); + face_ddy[2] = NULL; + face_ddy[3] = NULL; + ddx = face_ddx; + ddy = face_ddy; + } + + /* + * Compute the level of detail (float). + */ + if (min_filter != mag_filter || + mip_filter != PIPE_TEX_MIPFILTER_NONE) { + /* Need to compute lod either to choose mipmap levels or to + * distinguish between minification/magnification with one mipmap level. + */ + lp_build_lod_selector(bld, unit, ddx, ddy, + lod_bias, explicit_lod, + mip_filter, + &lod_ipart, &lod_fpart); + } else { + lod_ipart = i32t_zero; + } + + /* + * Compute integer mipmap level(s) to fetch texels from: ilevel0, ilevel1 + */ + switch (mip_filter) { + default: + assert(0 && "bad mip_filter value in lp_build_sample_aos()"); + /* fall-through */ + case PIPE_TEX_MIPFILTER_NONE: + /* always use mip level 0 */ + if (bld->static_state->target == PIPE_TEXTURE_CUBE) { + /* XXX this is a work-around for an apparent bug in LLVM 2.7. + * We should be able to set ilevel0 = const(0) but that causes + * bad x86 code to be emitted. + */ + assert(lod_ipart); + lp_build_nearest_mip_level(bld, unit, lod_ipart, &ilevel0); + } + else { + ilevel0 = i32t_zero; + } + break; + case PIPE_TEX_MIPFILTER_NEAREST: + assert(lod_ipart); + lp_build_nearest_mip_level(bld, unit, lod_ipart, &ilevel0); + break; + case PIPE_TEX_MIPFILTER_LINEAR: + assert(lod_ipart); + assert(lod_fpart); + lp_build_linear_mip_levels(bld, unit, + lod_ipart, &lod_fpart, + &ilevel0, &ilevel1); + break; + } + + /* + * Get/interpolate texture colors. + */ + + packed_lo = lp_build_alloca(bld->gallivm, h16_bld.vec_type, "packed_lo"); + packed_hi = lp_build_alloca(bld->gallivm, h16_bld.vec_type, "packed_hi"); + + if (min_filter == mag_filter) { + /* no need to distinquish between minification and magnification */ + lp_build_sample_mipmap(bld, + min_filter, mip_filter, + s, t, r, + ilevel0, ilevel1, lod_fpart, + packed_lo, packed_hi); + } + else { + /* Emit conditional to choose min image filter or mag image filter + * depending on the lod being > 0 or <= 0, respectively. + */ + struct lp_build_if_state if_ctx; + LLVMValueRef minify; + + /* minify = lod >= 0.0 */ + minify = LLVMBuildICmp(builder, LLVMIntSGE, + lod_ipart, int_bld->zero, ""); + + lp_build_if(&if_ctx, bld->gallivm, minify); + { + /* Use the minification filter */ + lp_build_sample_mipmap(bld, + min_filter, mip_filter, + s, t, r, + ilevel0, ilevel1, lod_fpart, + packed_lo, packed_hi); + } + lp_build_else(&if_ctx); + { + /* Use the magnification filter */ + lp_build_sample_mipmap(bld, + mag_filter, PIPE_TEX_MIPFILTER_NONE, + s, t, r, + i32t_zero, NULL, NULL, + packed_lo, packed_hi); + } + lp_build_endif(&if_ctx); + } + + /* + * combine the values stored in 'packed_lo' and 'packed_hi' variables + * into 'packed' + */ + packed = lp_build_pack2(bld->gallivm, + h16_bld.type, lp_type_unorm(8), + LLVMBuildLoad(builder, packed_lo, ""), + LLVMBuildLoad(builder, packed_hi, "")); + + /* + * Convert to SoA and swizzle. + */ + lp_build_rgba8_to_f32_soa(bld->gallivm, + bld->texel_type, + packed, unswizzled); + + if (util_format_is_rgba8_variant(bld->format_desc)) { + lp_build_format_swizzle_soa(bld->format_desc, + &bld->texel_bld, + unswizzled, texel_out); + } + else { + texel_out[0] = unswizzled[0]; + texel_out[1] = unswizzled[1]; + texel_out[2] = unswizzled[2]; + texel_out[3] = unswizzled[3]; + } + + apply_sampler_swizzle(bld, texel_out); +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.h b/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.h new file mode 100644 index 0000000..5d9ecac --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.h @@ -0,0 +1,56 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Texture sampling -- SoA. + * + * @author Jose Fonseca + * @author Brian Paul + */ + +#ifndef LP_BLD_SAMPLE_AOS_H +#define LP_BLD_SAMPLE_AOS_H + + +#include "lp_bld_sample.h" + + +void +lp_build_sample_aos(struct lp_build_sample_context *bld, + unsigned unit, + LLVMValueRef s, + LLVMValueRef t, + LLVMValueRef r, + const LLVMValueRef *ddx, + const LLVMValueRef *ddy, + LLVMValueRef lod_bias, /* optional */ + LLVMValueRef explicit_lod, /* optional */ + LLVMValueRef texel_out[4]); + + +#endif /* LP_BLD_SAMPLE_AOS_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c new file mode 100644 index 0000000..cf46e2b --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c @@ -0,0 +1,1271 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Texture sampling -- SoA. + * + * @author Jose Fonseca + * @author Brian Paul + */ + +#include "pipe/p_defines.h" +#include "pipe/p_state.h" +#include "util/u_debug.h" +#include "util/u_dump.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_format.h" +#include "lp_bld_debug.h" +#include "lp_bld_type.h" +#include "lp_bld_const.h" +#include "lp_bld_conv.h" +#include "lp_bld_arit.h" +#include "lp_bld_bitarit.h" +#include "lp_bld_logic.h" +#include "lp_bld_printf.h" +#include "lp_bld_swizzle.h" +#include "lp_bld_flow.h" +#include "lp_bld_gather.h" +#include "lp_bld_format.h" +#include "lp_bld_sample.h" +#include "lp_bld_sample_aos.h" +#include "lp_bld_struct.h" +#include "lp_bld_quad.h" + + +/** + * Generate code to fetch a texel from a texture at int coords (x, y, z). + * The computation depends on whether the texture is 1D, 2D or 3D. + * The result, texel, will be float vectors: + * texel[0] = red values + * texel[1] = green values + * texel[2] = blue values + * texel[3] = alpha values + */ +static void +lp_build_sample_texel_soa(struct lp_build_sample_context *bld, + unsigned unit, + LLVMValueRef width, + LLVMValueRef height, + LLVMValueRef depth, + LLVMValueRef x, + LLVMValueRef y, + LLVMValueRef z, + LLVMValueRef y_stride, + LLVMValueRef z_stride, + LLVMValueRef data_ptr, + LLVMValueRef texel_out[4]) +{ + const struct lp_sampler_static_state *static_state = bld->static_state; + const unsigned dims = bld->dims; + struct lp_build_context *int_coord_bld = &bld->int_coord_bld; + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef offset; + LLVMValueRef i, j; + LLVMValueRef use_border = NULL; + + /* use_border = x < 0 || x >= width || y < 0 || y >= height */ + if (lp_sampler_wrap_mode_uses_border_color(static_state->wrap_s, + static_state->min_img_filter, + static_state->mag_img_filter)) { + LLVMValueRef b1, b2; + b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, x, int_coord_bld->zero); + b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, x, width); + use_border = LLVMBuildOr(builder, b1, b2, "b1_or_b2"); + } + + if (dims >= 2 && + lp_sampler_wrap_mode_uses_border_color(static_state->wrap_t, + static_state->min_img_filter, + static_state->mag_img_filter)) { + LLVMValueRef b1, b2; + b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, y, int_coord_bld->zero); + b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, y, height); + if (use_border) { + use_border = LLVMBuildOr(builder, use_border, b1, "ub_or_b1"); + use_border = LLVMBuildOr(builder, use_border, b2, "ub_or_b2"); + } + else { + use_border = LLVMBuildOr(builder, b1, b2, "b1_or_b2"); + } + } + + if (dims == 3 && + lp_sampler_wrap_mode_uses_border_color(static_state->wrap_r, + static_state->min_img_filter, + static_state->mag_img_filter)) { + LLVMValueRef b1, b2; + b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, z, int_coord_bld->zero); + b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, z, depth); + if (use_border) { + use_border = LLVMBuildOr(builder, use_border, b1, "ub_or_b1"); + use_border = LLVMBuildOr(builder, use_border, b2, "ub_or_b2"); + } + else { + use_border = LLVMBuildOr(builder, b1, b2, "b1_or_b2"); + } + } + + /* convert x,y,z coords to linear offset from start of texture, in bytes */ + lp_build_sample_offset(&bld->int_coord_bld, + bld->format_desc, + x, y, z, y_stride, z_stride, + &offset, &i, &j); + + if (use_border) { + /* If we can sample the border color, it means that texcoords may + * lie outside the bounds of the texture image. We need to do + * something to prevent reading out of bounds and causing a segfault. + * + * Simply AND the texture coords with !use_border. This will cause + * coords which are out of bounds to become zero. Zero's guaranteed + * to be inside the texture image. + */ + offset = lp_build_andnot(&bld->int_coord_bld, offset, use_border); + } + + lp_build_fetch_rgba_soa(bld->gallivm, + bld->format_desc, + bld->texel_type, + data_ptr, offset, + i, j, + texel_out); + + /* + * Note: if we find an app which frequently samples the texture border + * we might want to implement a true conditional here to avoid sampling + * the texture whenever possible (since that's quite a bit of code). + * Ex: + * if (use_border) { + * texel = border_color; + * } + * else { + * texel = sample_texture(coord); + * } + * As it is now, we always sample the texture, then selectively replace + * the texel color results with the border color. + */ + + if (use_border) { + /* select texel color or border color depending on use_border */ + LLVMValueRef border_color_ptr = + bld->dynamic_state->border_color(bld->dynamic_state, + bld->gallivm, unit); + int chan; + for (chan = 0; chan < 4; chan++) { + LLVMValueRef border_chan = + lp_build_array_get(bld->gallivm, border_color_ptr, + lp_build_const_int32(bld->gallivm, chan)); + LLVMValueRef border_chan_vec = + lp_build_broadcast_scalar(&bld->float_vec_bld, border_chan); + texel_out[chan] = lp_build_select(&bld->texel_bld, use_border, + border_chan_vec, texel_out[chan]); + } + } + + apply_sampler_swizzle(bld, texel_out); +} + + +/** + * Helper to compute the mirror function for the PIPE_WRAP_MIRROR modes. + */ +static LLVMValueRef +lp_build_coord_mirror(struct lp_build_sample_context *bld, + LLVMValueRef coord) +{ + struct lp_build_context *coord_bld = &bld->coord_bld; + struct lp_build_context *int_coord_bld = &bld->int_coord_bld; + LLVMValueRef fract, flr, isOdd; + + lp_build_ifloor_fract(coord_bld, coord, &flr, &fract); + + /* isOdd = flr & 1 */ + isOdd = LLVMBuildAnd(bld->gallivm->builder, flr, int_coord_bld->one, ""); + + /* make coord positive or negative depending on isOdd */ + coord = lp_build_set_sign(coord_bld, fract, isOdd); + + /* convert isOdd to float */ + isOdd = lp_build_int_to_float(coord_bld, isOdd); + + /* add isOdd to coord */ + coord = lp_build_add(coord_bld, coord, isOdd); + + return coord; +} + + +/** + * Build LLVM code for texture wrap mode for linear filtering. + * \param x0_out returns first integer texcoord + * \param x1_out returns second integer texcoord + * \param weight_out returns linear interpolation weight + */ +static void +lp_build_sample_wrap_linear(struct lp_build_sample_context *bld, + LLVMValueRef coord, + LLVMValueRef length, + LLVMValueRef length_f, + boolean is_pot, + unsigned wrap_mode, + LLVMValueRef *x0_out, + LLVMValueRef *x1_out, + LLVMValueRef *weight_out) +{ + struct lp_build_context *coord_bld = &bld->coord_bld; + struct lp_build_context *int_coord_bld = &bld->int_coord_bld; + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef half = lp_build_const_vec(bld->gallivm, coord_bld->type, 0.5); + LLVMValueRef length_minus_one = lp_build_sub(int_coord_bld, length, int_coord_bld->one); + LLVMValueRef coord0, coord1, weight; + + switch(wrap_mode) { + case PIPE_TEX_WRAP_REPEAT: + /* mul by size and subtract 0.5 */ + coord = lp_build_mul(coord_bld, coord, length_f); + coord = lp_build_sub(coord_bld, coord, half); + /* convert to int, compute lerp weight */ + lp_build_ifloor_fract(coord_bld, coord, &coord0, &weight); + /* repeat wrap */ + if (is_pot) { + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + coord0 = LLVMBuildAnd(builder, coord0, length_minus_one, ""); + coord1 = LLVMBuildAnd(builder, coord1, length_minus_one, ""); + } + else { + /* Add a bias to the texcoord to handle negative coords */ + LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024); + LLVMValueRef mask; + coord0 = LLVMBuildAdd(builder, coord0, bias, ""); + coord0 = LLVMBuildURem(builder, coord0, length, ""); + mask = lp_build_compare(bld->gallivm, int_coord_bld->type, + PIPE_FUNC_NOTEQUAL, coord0, length_minus_one); + coord1 = LLVMBuildAnd(builder, + lp_build_add(int_coord_bld, coord0, int_coord_bld->one), + mask, ""); + } + break; + + case PIPE_TEX_WRAP_CLAMP: + if (bld->static_state->normalized_coords) { + /* scale coord to length */ + coord = lp_build_mul(coord_bld, coord, length_f); + } + + /* clamp to [0, length] */ + coord = lp_build_clamp(coord_bld, coord, coord_bld->zero, length_f); + + coord = lp_build_sub(coord_bld, coord, half); + + /* convert to int, compute lerp weight */ + lp_build_ifloor_fract(coord_bld, coord, &coord0, &weight); + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + break; + + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + { + struct lp_build_context abs_coord_bld = bld->coord_bld; + abs_coord_bld.type.sign = FALSE; + + if (bld->static_state->normalized_coords) { + /* mul by tex size */ + coord = lp_build_mul(coord_bld, coord, length_f); + } + /* clamp to length max */ + coord = lp_build_min(coord_bld, coord, length_f); + /* subtract 0.5 */ + coord = lp_build_sub(coord_bld, coord, half); + /* clamp to [0, length - 0.5] */ + coord = lp_build_max(coord_bld, coord, coord_bld->zero); + /* convert to int, compute lerp weight */ + lp_build_ifloor_fract(&abs_coord_bld, coord, &coord0, &weight); + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + /* coord1 = min(coord1, length-1) */ + coord1 = lp_build_min(int_coord_bld, coord1, length_minus_one); + break; + } + + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + { + LLVMValueRef min; + if (bld->static_state->normalized_coords) { + /* scale coord to length */ + coord = lp_build_mul(coord_bld, coord, length_f); + } + /* was: clamp to [-0.5, length + 0.5], then sub 0.5 */ + coord = lp_build_sub(coord_bld, coord, half); + min = lp_build_const_vec(bld->gallivm, coord_bld->type, -1.0F); + coord = lp_build_clamp(coord_bld, coord, min, length_f); + /* convert to int, compute lerp weight */ + lp_build_ifloor_fract(coord_bld, coord, &coord0, &weight); + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + } + break; + + case PIPE_TEX_WRAP_MIRROR_REPEAT: + /* compute mirror function */ + coord = lp_build_coord_mirror(bld, coord); + + /* scale coord to length */ + coord = lp_build_mul(coord_bld, coord, length_f); + coord = lp_build_sub(coord_bld, coord, half); + + /* convert to int, compute lerp weight */ + lp_build_ifloor_fract(coord_bld, coord, &coord0, &weight); + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + + /* coord0 = max(coord0, 0) */ + coord0 = lp_build_max(int_coord_bld, coord0, int_coord_bld->zero); + /* coord1 = min(coord1, length-1) */ + coord1 = lp_build_min(int_coord_bld, coord1, length_minus_one); + break; + + case PIPE_TEX_WRAP_MIRROR_CLAMP: + coord = lp_build_abs(coord_bld, coord); + + if (bld->static_state->normalized_coords) { + /* scale coord to length */ + coord = lp_build_mul(coord_bld, coord, length_f); + } + + /* clamp to [0, length] */ + coord = lp_build_min(coord_bld, coord, length_f); + + coord = lp_build_sub(coord_bld, coord, half); + + /* convert to int, compute lerp weight */ + lp_build_ifloor_fract(coord_bld, coord, &coord0, &weight); + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + break; + + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + { + LLVMValueRef min, max; + struct lp_build_context abs_coord_bld = bld->coord_bld; + abs_coord_bld.type.sign = FALSE; + coord = lp_build_abs(coord_bld, coord); + + if (bld->static_state->normalized_coords) { + /* scale coord to length */ + coord = lp_build_mul(coord_bld, coord, length_f); + } + + /* clamp to [0.5, length - 0.5] */ + min = half; + max = lp_build_sub(coord_bld, length_f, min); + coord = lp_build_clamp(coord_bld, coord, min, max); + + coord = lp_build_sub(coord_bld, coord, half); + + /* convert to int, compute lerp weight */ + lp_build_ifloor_fract(&abs_coord_bld, coord, &coord0, &weight); + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + } + break; + + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + { + coord = lp_build_abs(coord_bld, coord); + + if (bld->static_state->normalized_coords) { + /* scale coord to length */ + coord = lp_build_mul(coord_bld, coord, length_f); + } + + /* was: clamp to [-0.5, length + 0.5] then sub 0.5 */ + /* skip -0.5 clamp (always positive), do sub first */ + coord = lp_build_sub(coord_bld, coord, half); + coord = lp_build_min(coord_bld, coord, length_f); + + /* convert to int, compute lerp weight */ + lp_build_ifloor_fract(coord_bld, coord, &coord0, &weight); + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + } + break; + + default: + assert(0); + coord0 = NULL; + coord1 = NULL; + weight = NULL; + } + + *x0_out = coord0; + *x1_out = coord1; + *weight_out = weight; +} + + +/** + * Build LLVM code for texture wrap mode for nearest filtering. + * \param coord the incoming texcoord (nominally in [0,1]) + * \param length the texture size along one dimension, as int vector + * \param is_pot if TRUE, length is a power of two + * \param wrap_mode one of PIPE_TEX_WRAP_x + */ +static LLVMValueRef +lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld, + LLVMValueRef coord, + LLVMValueRef length, + LLVMValueRef length_f, + boolean is_pot, + unsigned wrap_mode) +{ + struct lp_build_context *coord_bld = &bld->coord_bld; + struct lp_build_context *int_coord_bld = &bld->int_coord_bld; + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef length_minus_one = lp_build_sub(int_coord_bld, length, int_coord_bld->one); + LLVMValueRef icoord; + + switch(wrap_mode) { + case PIPE_TEX_WRAP_REPEAT: + coord = lp_build_mul(coord_bld, coord, length_f); + icoord = lp_build_ifloor(coord_bld, coord); + if (is_pot) + icoord = LLVMBuildAnd(builder, icoord, length_minus_one, ""); + else { + /* Add a bias to the texcoord to handle negative coords */ + LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024); + icoord = LLVMBuildAdd(builder, icoord, bias, ""); + icoord = LLVMBuildURem(builder, icoord, length, ""); + } + break; + + case PIPE_TEX_WRAP_CLAMP: + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + if (bld->static_state->normalized_coords) { + /* scale coord to length */ + coord = lp_build_mul(coord_bld, coord, length_f); + } + + /* floor */ + /* use itrunc instead since we clamp to 0 anyway */ + icoord = lp_build_itrunc(coord_bld, coord); + + /* clamp to [0, length - 1]. */ + icoord = lp_build_clamp(int_coord_bld, icoord, int_coord_bld->zero, + length_minus_one); + break; + + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + /* Note: this is the same as CLAMP_TO_EDGE, except min = -min */ + { + LLVMValueRef min, max; + + if (bld->static_state->normalized_coords) { + /* scale coord to length */ + coord = lp_build_mul(coord_bld, coord, length_f); + } + + icoord = lp_build_ifloor(coord_bld, coord); + + /* clamp to [-1, length] */ + min = lp_build_negate(int_coord_bld, int_coord_bld->one); + max = length; + icoord = lp_build_clamp(int_coord_bld, icoord, min, max); + } + break; + + case PIPE_TEX_WRAP_MIRROR_REPEAT: + /* compute mirror function */ + coord = lp_build_coord_mirror(bld, coord); + + /* scale coord to length */ + assert(bld->static_state->normalized_coords); + coord = lp_build_mul(coord_bld, coord, length_f); + + /* itrunc == ifloor here */ + icoord = lp_build_itrunc(coord_bld, coord); + + /* clamp to [0, length - 1] */ + icoord = lp_build_min(int_coord_bld, icoord, length_minus_one); + break; + + case PIPE_TEX_WRAP_MIRROR_CLAMP: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + coord = lp_build_abs(coord_bld, coord); + + if (bld->static_state->normalized_coords) { + /* scale coord to length */ + coord = lp_build_mul(coord_bld, coord, length_f); + } + + /* itrunc == ifloor here */ + icoord = lp_build_itrunc(coord_bld, coord); + + /* clamp to [0, length - 1] */ + icoord = lp_build_min(int_coord_bld, icoord, length_minus_one); + break; + + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + coord = lp_build_abs(coord_bld, coord); + + if (bld->static_state->normalized_coords) { + /* scale coord to length */ + coord = lp_build_mul(coord_bld, coord, length_f); + } + + /* itrunc == ifloor here */ + icoord = lp_build_itrunc(coord_bld, coord); + + /* clamp to [0, length] */ + icoord = lp_build_min(int_coord_bld, icoord, length); + break; + + default: + assert(0); + icoord = NULL; + } + + return icoord; +} + + +/** + * Generate code to sample a mipmap level with nearest filtering. + * If sampling a cube texture, r = cube face in [0,5]. + */ +static void +lp_build_sample_image_nearest(struct lp_build_sample_context *bld, + unsigned unit, + LLVMValueRef size, + LLVMValueRef row_stride_vec, + LLVMValueRef img_stride_vec, + LLVMValueRef data_ptr, + LLVMValueRef s, + LLVMValueRef t, + LLVMValueRef r, + LLVMValueRef colors_out[4]) +{ + const unsigned dims = bld->dims; + LLVMValueRef width_vec; + LLVMValueRef height_vec; + LLVMValueRef depth_vec; + LLVMValueRef flt_size; + LLVMValueRef flt_width_vec; + LLVMValueRef flt_height_vec; + LLVMValueRef flt_depth_vec; + LLVMValueRef x, y, z; + + lp_build_extract_image_sizes(bld, + bld->int_size_type, + bld->int_coord_type, + size, + &width_vec, &height_vec, &depth_vec); + + flt_size = lp_build_int_to_float(&bld->float_size_bld, size); + + lp_build_extract_image_sizes(bld, + bld->float_size_type, + bld->coord_type, + flt_size, + &flt_width_vec, &flt_height_vec, &flt_depth_vec); + + /* + * Compute integer texcoords. + */ + x = lp_build_sample_wrap_nearest(bld, s, width_vec, flt_width_vec, + bld->static_state->pot_width, + bld->static_state->wrap_s); + lp_build_name(x, "tex.x.wrapped"); + + if (dims >= 2) { + y = lp_build_sample_wrap_nearest(bld, t, height_vec, flt_height_vec, + bld->static_state->pot_height, + bld->static_state->wrap_t); + lp_build_name(y, "tex.y.wrapped"); + + if (dims == 3) { + z = lp_build_sample_wrap_nearest(bld, r, depth_vec, flt_depth_vec, + bld->static_state->pot_depth, + bld->static_state->wrap_r); + lp_build_name(z, "tex.z.wrapped"); + } + else if (bld->static_state->target == PIPE_TEXTURE_CUBE) { + z = r; + } + else { + z = NULL; + } + } + else { + y = z = NULL; + } + + /* + * Get texture colors. + */ + lp_build_sample_texel_soa(bld, unit, + width_vec, height_vec, depth_vec, + x, y, z, + row_stride_vec, img_stride_vec, + data_ptr, colors_out); +} + + +/** + * Generate code to sample a mipmap level with linear filtering. + * If sampling a cube texture, r = cube face in [0,5]. + */ +static void +lp_build_sample_image_linear(struct lp_build_sample_context *bld, + unsigned unit, + LLVMValueRef size, + LLVMValueRef row_stride_vec, + LLVMValueRef img_stride_vec, + LLVMValueRef data_ptr, + LLVMValueRef s, + LLVMValueRef t, + LLVMValueRef r, + LLVMValueRef colors_out[4]) +{ + const unsigned dims = bld->dims; + LLVMValueRef width_vec; + LLVMValueRef height_vec; + LLVMValueRef depth_vec; + LLVMValueRef flt_size; + LLVMValueRef flt_width_vec; + LLVMValueRef flt_height_vec; + LLVMValueRef flt_depth_vec; + LLVMValueRef x0, y0, z0, x1, y1, z1; + LLVMValueRef s_fpart, t_fpart, r_fpart; + LLVMValueRef neighbors[2][2][4]; + int chan; + + lp_build_extract_image_sizes(bld, + bld->int_size_type, + bld->int_coord_type, + size, + &width_vec, &height_vec, &depth_vec); + + flt_size = lp_build_int_to_float(&bld->float_size_bld, size); + + lp_build_extract_image_sizes(bld, + bld->float_size_type, + bld->coord_type, + flt_size, + &flt_width_vec, &flt_height_vec, &flt_depth_vec); + + /* + * Compute integer texcoords. + */ + lp_build_sample_wrap_linear(bld, s, width_vec, flt_width_vec, + bld->static_state->pot_width, + bld->static_state->wrap_s, + &x0, &x1, &s_fpart); + lp_build_name(x0, "tex.x0.wrapped"); + lp_build_name(x1, "tex.x1.wrapped"); + + if (dims >= 2) { + lp_build_sample_wrap_linear(bld, t, height_vec, flt_height_vec, + bld->static_state->pot_height, + bld->static_state->wrap_t, + &y0, &y1, &t_fpart); + lp_build_name(y0, "tex.y0.wrapped"); + lp_build_name(y1, "tex.y1.wrapped"); + + if (dims == 3) { + lp_build_sample_wrap_linear(bld, r, depth_vec, flt_depth_vec, + bld->static_state->pot_depth, + bld->static_state->wrap_r, + &z0, &z1, &r_fpart); + lp_build_name(z0, "tex.z0.wrapped"); + lp_build_name(z1, "tex.z1.wrapped"); + } + else if (bld->static_state->target == PIPE_TEXTURE_CUBE) { + z0 = z1 = r; /* cube face */ + r_fpart = NULL; + } + else { + z0 = z1 = NULL; + r_fpart = NULL; + } + } + else { + y0 = y1 = t_fpart = NULL; + z0 = z1 = r_fpart = NULL; + } + + /* + * Get texture colors. + */ + /* get x0/x1 texels */ + lp_build_sample_texel_soa(bld, unit, + width_vec, height_vec, depth_vec, + x0, y0, z0, + row_stride_vec, img_stride_vec, + data_ptr, neighbors[0][0]); + lp_build_sample_texel_soa(bld, unit, + width_vec, height_vec, depth_vec, + x1, y0, z0, + row_stride_vec, img_stride_vec, + data_ptr, neighbors[0][1]); + + if (dims == 1) { + /* Interpolate two samples from 1D image to produce one color */ + for (chan = 0; chan < 4; chan++) { + colors_out[chan] = lp_build_lerp(&bld->texel_bld, s_fpart, + neighbors[0][0][chan], + neighbors[0][1][chan]); + } + } + else { + /* 2D/3D texture */ + LLVMValueRef colors0[4]; + + /* get x0/x1 texels at y1 */ + lp_build_sample_texel_soa(bld, unit, + width_vec, height_vec, depth_vec, + x0, y1, z0, + row_stride_vec, img_stride_vec, + data_ptr, neighbors[1][0]); + lp_build_sample_texel_soa(bld, unit, + width_vec, height_vec, depth_vec, + x1, y1, z0, + row_stride_vec, img_stride_vec, + data_ptr, neighbors[1][1]); + + /* Bilinear interpolate the four samples from the 2D image / 3D slice */ + for (chan = 0; chan < 4; chan++) { + colors0[chan] = lp_build_lerp_2d(&bld->texel_bld, + s_fpart, t_fpart, + neighbors[0][0][chan], + neighbors[0][1][chan], + neighbors[1][0][chan], + neighbors[1][1][chan]); + } + + if (dims == 3) { + LLVMValueRef neighbors1[2][2][4]; + LLVMValueRef colors1[4]; + + /* get x0/x1/y0/y1 texels at z1 */ + lp_build_sample_texel_soa(bld, unit, + width_vec, height_vec, depth_vec, + x0, y0, z1, + row_stride_vec, img_stride_vec, + data_ptr, neighbors1[0][0]); + lp_build_sample_texel_soa(bld, unit, + width_vec, height_vec, depth_vec, + x1, y0, z1, + row_stride_vec, img_stride_vec, + data_ptr, neighbors1[0][1]); + lp_build_sample_texel_soa(bld, unit, + width_vec, height_vec, depth_vec, + x0, y1, z1, + row_stride_vec, img_stride_vec, + data_ptr, neighbors1[1][0]); + lp_build_sample_texel_soa(bld, unit, + width_vec, height_vec, depth_vec, + x1, y1, z1, + row_stride_vec, img_stride_vec, + data_ptr, neighbors1[1][1]); + + /* Bilinear interpolate the four samples from the second Z slice */ + for (chan = 0; chan < 4; chan++) { + colors1[chan] = lp_build_lerp_2d(&bld->texel_bld, + s_fpart, t_fpart, + neighbors1[0][0][chan], + neighbors1[0][1][chan], + neighbors1[1][0][chan], + neighbors1[1][1][chan]); + } + + /* Linearly interpolate the two samples from the two 3D slices */ + for (chan = 0; chan < 4; chan++) { + colors_out[chan] = lp_build_lerp(&bld->texel_bld, + r_fpart, + colors0[chan], colors1[chan]); + } + } + else { + /* 2D tex */ + for (chan = 0; chan < 4; chan++) { + colors_out[chan] = colors0[chan]; + } + } + } +} + + +/** + * Sample the texture/mipmap using given image filter and mip filter. + * data0_ptr and data1_ptr point to the two mipmap levels to sample + * from. width0/1_vec, height0/1_vec, depth0/1_vec indicate their sizes. + * If we're using nearest miplevel sampling the '1' values will be null/unused. + */ +static void +lp_build_sample_mipmap(struct lp_build_sample_context *bld, + unsigned unit, + unsigned img_filter, + unsigned mip_filter, + LLVMValueRef s, + LLVMValueRef t, + LLVMValueRef r, + LLVMValueRef ilevel0, + LLVMValueRef ilevel1, + LLVMValueRef lod_fpart, + LLVMValueRef *colors_out) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef size0; + LLVMValueRef size1; + LLVMValueRef row_stride0_vec; + LLVMValueRef row_stride1_vec; + LLVMValueRef img_stride0_vec; + LLVMValueRef img_stride1_vec; + LLVMValueRef data_ptr0; + LLVMValueRef data_ptr1; + LLVMValueRef colors0[4], colors1[4]; + unsigned chan; + + /* sample the first mipmap level */ + lp_build_mipmap_level_sizes(bld, ilevel0, + &size0, + &row_stride0_vec, &img_stride0_vec); + data_ptr0 = lp_build_get_mipmap_level(bld, ilevel0); + if (img_filter == PIPE_TEX_FILTER_NEAREST) { + lp_build_sample_image_nearest(bld, unit, + size0, + row_stride0_vec, img_stride0_vec, + data_ptr0, s, t, r, + colors0); + } + else { + assert(img_filter == PIPE_TEX_FILTER_LINEAR); + lp_build_sample_image_linear(bld, unit, + size0, + row_stride0_vec, img_stride0_vec, + data_ptr0, s, t, r, + colors0); + } + + /* Store the first level's colors in the output variables */ + for (chan = 0; chan < 4; chan++) { + LLVMBuildStore(builder, colors0[chan], colors_out[chan]); + } + + if (mip_filter == PIPE_TEX_MIPFILTER_LINEAR) { + struct lp_build_if_state if_ctx; + LLVMValueRef need_lerp; + + /* need_lerp = lod_fpart > 0 */ + need_lerp = LLVMBuildFCmp(builder, LLVMRealUGT, + lod_fpart, + bld->float_bld.zero, + "need_lerp"); + + lp_build_if(&if_ctx, bld->gallivm, need_lerp); + { + /* sample the second mipmap level */ + lp_build_mipmap_level_sizes(bld, ilevel1, + &size1, + &row_stride1_vec, &img_stride1_vec); + data_ptr1 = lp_build_get_mipmap_level(bld, ilevel1); + if (img_filter == PIPE_TEX_FILTER_NEAREST) { + lp_build_sample_image_nearest(bld, unit, + size1, + row_stride1_vec, img_stride1_vec, + data_ptr1, s, t, r, + colors1); + } + else { + lp_build_sample_image_linear(bld, unit, + size1, + row_stride1_vec, img_stride1_vec, + data_ptr1, s, t, r, + colors1); + } + + /* interpolate samples from the two mipmap levels */ + + lod_fpart = lp_build_broadcast_scalar(&bld->texel_bld, lod_fpart); + + for (chan = 0; chan < 4; chan++) { + colors0[chan] = lp_build_lerp(&bld->texel_bld, lod_fpart, + colors0[chan], colors1[chan]); + LLVMBuildStore(builder, colors0[chan], colors_out[chan]); + } + } + lp_build_endif(&if_ctx); + } +} + + + +/** + * General texture sampling codegen. + * This function handles texture sampling for all texture targets (1D, + * 2D, 3D, cube) and all filtering modes. + */ +static void +lp_build_sample_general(struct lp_build_sample_context *bld, + unsigned unit, + LLVMValueRef s, + LLVMValueRef t, + LLVMValueRef r, + const LLVMValueRef *ddx, + const LLVMValueRef *ddy, + LLVMValueRef lod_bias, /* optional */ + LLVMValueRef explicit_lod, /* optional */ + LLVMValueRef *colors_out) +{ + struct lp_build_context *int_bld = &bld->int_bld; + LLVMBuilderRef builder = bld->gallivm->builder; + const unsigned mip_filter = bld->static_state->min_mip_filter; + const unsigned min_filter = bld->static_state->min_img_filter; + const unsigned mag_filter = bld->static_state->mag_img_filter; + LLVMValueRef lod_ipart = NULL, lod_fpart = NULL; + LLVMValueRef ilevel0, ilevel1 = NULL; + LLVMValueRef face_ddx[4], face_ddy[4]; + LLVMValueRef texels[4]; + LLVMValueRef i32t_zero = lp_build_const_int32(bld->gallivm, 0); + unsigned chan; + + /* + printf("%s mip %d min %d mag %d\n", __FUNCTION__, + mip_filter, min_filter, mag_filter); + */ + + /* + * Choose cube face, recompute texcoords and derivatives for the chosen face. + */ + if (bld->static_state->target == PIPE_TEXTURE_CUBE) { + LLVMValueRef face, face_s, face_t; + lp_build_cube_lookup(bld, s, t, r, &face, &face_s, &face_t); + s = face_s; /* vec */ + t = face_t; /* vec */ + /* use 'r' to indicate cube face */ + r = lp_build_broadcast_scalar(&bld->int_coord_bld, face); /* vec */ + + /* recompute ddx, ddy using the new (s,t) face texcoords */ + face_ddx[0] = lp_build_scalar_ddx(&bld->coord_bld, s); + face_ddx[1] = lp_build_scalar_ddx(&bld->coord_bld, t); + face_ddx[2] = NULL; + face_ddx[3] = NULL; + face_ddy[0] = lp_build_scalar_ddy(&bld->coord_bld, s); + face_ddy[1] = lp_build_scalar_ddy(&bld->coord_bld, t); + face_ddy[2] = NULL; + face_ddy[3] = NULL; + ddx = face_ddx; + ddy = face_ddy; + } + + /* + * Compute the level of detail (float). + */ + if (min_filter != mag_filter || + mip_filter != PIPE_TEX_MIPFILTER_NONE) { + /* Need to compute lod either to choose mipmap levels or to + * distinguish between minification/magnification with one mipmap level. + */ + lp_build_lod_selector(bld, unit, ddx, ddy, + lod_bias, explicit_lod, + mip_filter, + &lod_ipart, &lod_fpart); + } else { + lod_ipart = i32t_zero; + } + + /* + * Compute integer mipmap level(s) to fetch texels from: ilevel0, ilevel1 + */ + switch (mip_filter) { + default: + assert(0 && "bad mip_filter value in lp_build_sample_soa()"); + /* fall-through */ + case PIPE_TEX_MIPFILTER_NONE: + /* always use mip level 0 */ + if (bld->static_state->target == PIPE_TEXTURE_CUBE) { + /* XXX this is a work-around for an apparent bug in LLVM 2.7. + * We should be able to set ilevel0 = const(0) but that causes + * bad x86 code to be emitted. + */ + assert(lod_ipart); + lp_build_nearest_mip_level(bld, unit, lod_ipart, &ilevel0); + } + else { + ilevel0 = i32t_zero; + } + break; + case PIPE_TEX_MIPFILTER_NEAREST: + assert(lod_ipart); + lp_build_nearest_mip_level(bld, unit, lod_ipart, &ilevel0); + break; + case PIPE_TEX_MIPFILTER_LINEAR: + assert(lod_ipart); + assert(lod_fpart); + lp_build_linear_mip_levels(bld, unit, + lod_ipart, &lod_fpart, + &ilevel0, &ilevel1); + break; + } + + /* + * Get/interpolate texture colors. + */ + + for (chan = 0; chan < 4; ++chan) { + texels[chan] = lp_build_alloca(bld->gallivm, bld->texel_bld.vec_type, ""); + lp_build_name(texels[chan], "sampler%u_texel_%c_var", unit, "xyzw"[chan]); + } + + if (min_filter == mag_filter) { + /* no need to distinquish between minification and magnification */ + lp_build_sample_mipmap(bld, unit, + min_filter, mip_filter, + s, t, r, + ilevel0, ilevel1, lod_fpart, + texels); + } + else { + /* Emit conditional to choose min image filter or mag image filter + * depending on the lod being > 0 or <= 0, respectively. + */ + struct lp_build_if_state if_ctx; + LLVMValueRef minify; + + /* minify = lod >= 0.0 */ + minify = LLVMBuildICmp(builder, LLVMIntSGE, + lod_ipart, int_bld->zero, ""); + + lp_build_if(&if_ctx, bld->gallivm, minify); + { + /* Use the minification filter */ + lp_build_sample_mipmap(bld, unit, + min_filter, mip_filter, + s, t, r, + ilevel0, ilevel1, lod_fpart, + texels); + } + lp_build_else(&if_ctx); + { + /* Use the magnification filter */ + lp_build_sample_mipmap(bld, unit, + mag_filter, PIPE_TEX_MIPFILTER_NONE, + s, t, r, + i32t_zero, NULL, NULL, + texels); + } + lp_build_endif(&if_ctx); + } + + for (chan = 0; chan < 4; ++chan) { + colors_out[chan] = LLVMBuildLoad(builder, texels[chan], ""); + lp_build_name(colors_out[chan], "sampler%u_texel_%c", unit, "xyzw"[chan]); + } +} + + +/** + * Do shadow test/comparison. + * \param p the texcoord Z (aka R, aka P) component + * \param texel the texel to compare against (use the X channel) + */ +static void +lp_build_sample_compare(struct lp_build_sample_context *bld, + LLVMValueRef p, + LLVMValueRef texel[4]) +{ + struct lp_build_context *texel_bld = &bld->texel_bld; + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef res; + const unsigned chan = 0; + + if (bld->static_state->compare_mode == PIPE_TEX_COMPARE_NONE) + return; + + /* debug code */ + if (0) { + LLVMValueRef indx = lp_build_const_int32(bld->gallivm, 0); + LLVMValueRef coord = LLVMBuildExtractElement(builder, p, indx, ""); + LLVMValueRef tex = LLVMBuildExtractElement(builder, texel[chan], indx, ""); + lp_build_printf(bld->gallivm, "shadow compare coord %f to texture %f\n", + coord, tex); + } + + /* result = (p FUNC texel) ? 1 : 0 */ + res = lp_build_cmp(texel_bld, bld->static_state->compare_func, + p, texel[chan]); + res = lp_build_select(texel_bld, res, texel_bld->one, texel_bld->zero); + + /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */ + texel[0] = + texel[1] = + texel[2] = res; + texel[3] = texel_bld->one; +} + + +/** + * Just set texels to white instead of actually sampling the texture. + * For debugging. + */ +void +lp_build_sample_nop(struct gallivm_state *gallivm, struct lp_type type, + LLVMValueRef texel_out[4]) +{ + LLVMValueRef one = lp_build_one(gallivm, type); + unsigned chan; + + for (chan = 0; chan < 4; chan++) { + texel_out[chan] = one; + } +} + + +/** + * Build texture sampling code. + * 'texel' will return a vector of four LLVMValueRefs corresponding to + * R, G, B, A. + * \param type vector float type to use for coords, etc. + * \param ddx partial derivatives of (s,t,r,q) with respect to x + * \param ddy partial derivatives of (s,t,r,q) with respect to y + */ +void +lp_build_sample_soa(struct gallivm_state *gallivm, + const struct lp_sampler_static_state *static_state, + struct lp_sampler_dynamic_state *dynamic_state, + struct lp_type type, + unsigned unit, + unsigned num_coords, + const LLVMValueRef *coords, + const LLVMValueRef ddx[4], + const LLVMValueRef ddy[4], + LLVMValueRef lod_bias, /* optional */ + LLVMValueRef explicit_lod, /* optional */ + LLVMValueRef texel_out[4]) +{ + unsigned dims = texture_dims(static_state->target); + struct lp_build_sample_context bld; + LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context); + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef s; + LLVMValueRef t; + LLVMValueRef r; + struct lp_type float_vec_type; + + if (0) { + enum pipe_format fmt = static_state->format; + debug_printf("Sample from %s\n", util_format_name(fmt)); + } + + assert(type.floating); + + /* Setup our build context */ + memset(&bld, 0, sizeof bld); + bld.gallivm = gallivm; + bld.static_state = static_state; + bld.dynamic_state = dynamic_state; + bld.format_desc = util_format_description(static_state->format); + bld.dims = dims; + + bld.float_type = lp_type_float(32); + bld.int_type = lp_type_int(32); + bld.coord_type = type; + bld.int_coord_type = lp_int_type(type); + bld.float_size_type = lp_type_float(32); + bld.float_size_type.length = dims > 1 ? 4 : 1; + bld.int_size_type = lp_int_type(bld.float_size_type); + bld.texel_type = type; + + float_vec_type = lp_type_float_vec(32); + + lp_build_context_init(&bld.float_bld, gallivm, bld.float_type); + lp_build_context_init(&bld.float_vec_bld, gallivm, float_vec_type); + lp_build_context_init(&bld.int_bld, gallivm, bld.int_type); + lp_build_context_init(&bld.coord_bld, gallivm, bld.coord_type); + lp_build_context_init(&bld.int_coord_bld, gallivm, bld.int_coord_type); + lp_build_context_init(&bld.int_size_bld, gallivm, bld.int_size_type); + lp_build_context_init(&bld.float_size_bld, gallivm, bld.float_size_type); + lp_build_context_init(&bld.texel_bld, gallivm, bld.texel_type); + + /* Get the dynamic state */ + bld.width = dynamic_state->width(dynamic_state, gallivm, unit); + bld.height = dynamic_state->height(dynamic_state, gallivm, unit); + bld.depth = dynamic_state->depth(dynamic_state, gallivm, unit); + bld.row_stride_array = dynamic_state->row_stride(dynamic_state, gallivm, unit); + bld.img_stride_array = dynamic_state->img_stride(dynamic_state, gallivm, unit); + bld.data_array = dynamic_state->data_ptr(dynamic_state, gallivm, unit); + /* Note that data_array is an array[level] of pointers to texture images */ + + s = coords[0]; + t = coords[1]; + r = coords[2]; + + /* width, height, depth as single int vector */ + if (dims <= 1) { + bld.int_size = bld.width; + } + else { + bld.int_size = LLVMBuildInsertElement(builder, bld.int_size_bld.undef, + bld.width, LLVMConstInt(i32t, 0, 0), ""); + if (dims >= 2) { + bld.int_size = LLVMBuildInsertElement(builder, bld.int_size, + bld.height, LLVMConstInt(i32t, 1, 0), ""); + if (dims >= 3) { + bld.int_size = LLVMBuildInsertElement(builder, bld.int_size, + bld.depth, LLVMConstInt(i32t, 2, 0), ""); + } + } + } + + if (0) { + /* For debug: no-op texture sampling */ + lp_build_sample_nop(gallivm, bld.texel_type, texel_out); + } + else if (util_format_fits_8unorm(bld.format_desc) && + lp_is_simple_wrap_mode(static_state->wrap_s) && + lp_is_simple_wrap_mode(static_state->wrap_t)) { + /* do sampling/filtering with fixed pt arithmetic */ + lp_build_sample_aos(&bld, unit, s, t, r, ddx, ddy, + lod_bias, explicit_lod, + texel_out); + } + + else { + if ((gallivm_debug & GALLIVM_DEBUG_PERF) && + util_format_fits_8unorm(bld.format_desc)) { + debug_printf("%s: using floating point linear filtering for %s\n", + __FUNCTION__, bld.format_desc->short_name); + debug_printf(" min_img %d mag_img %d mip %d wraps %d wrapt %d\n", + static_state->min_img_filter, + static_state->mag_img_filter, + static_state->min_mip_filter, + static_state->wrap_s, + static_state->wrap_t); + } + + lp_build_sample_general(&bld, unit, s, t, r, ddx, ddy, + lod_bias, explicit_lod, + texel_out); + } + + lp_build_sample_compare(&bld, r, texel_out); +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c new file mode 100644 index 0000000..0dc2f24 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c @@ -0,0 +1,158 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * @file + * Helper functions for manipulation structures. + * + * @author Jose Fonseca + */ + + +#include "util/u_debug.h" +#include "util/u_memory.h" + +#include "lp_bld_const.h" +#include "lp_bld_debug.h" +#include "lp_bld_struct.h" + + +LLVMValueRef +lp_build_struct_get_ptr(struct gallivm_state *gallivm, + LLVMValueRef ptr, + unsigned member, + const char *name) +{ + LLVMValueRef indices[2]; + LLVMValueRef member_ptr; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); + assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); + indices[0] = lp_build_const_int32(gallivm, 0); + indices[1] = lp_build_const_int32(gallivm, member); + member_ptr = LLVMBuildGEP(gallivm->builder, ptr, indices, Elements(indices), ""); + lp_build_name(member_ptr, "%s.%s_ptr", LLVMGetValueName(ptr), name); + return member_ptr; +} + + +LLVMValueRef +lp_build_struct_get(struct gallivm_state *gallivm, + LLVMValueRef ptr, + unsigned member, + const char *name) +{ + LLVMValueRef member_ptr; + LLVMValueRef res; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); + assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind); + member_ptr = lp_build_struct_get_ptr(gallivm, ptr, member, name); + res = LLVMBuildLoad(gallivm->builder, member_ptr, ""); + lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name); + return res; +} + + +LLVMValueRef +lp_build_array_get_ptr(struct gallivm_state *gallivm, + LLVMValueRef ptr, + LLVMValueRef index) +{ + LLVMValueRef indices[2]; + LLVMValueRef element_ptr; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); + assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind); + indices[0] = lp_build_const_int32(gallivm, 0); + indices[1] = index; + element_ptr = LLVMBuildGEP(gallivm->builder, ptr, indices, Elements(indices), ""); +#ifdef DEBUG + lp_build_name(element_ptr, "&%s[%s]", + LLVMGetValueName(ptr), LLVMGetValueName(index)); +#endif + return element_ptr; +} + + +LLVMValueRef +lp_build_array_get(struct gallivm_state *gallivm, + LLVMValueRef ptr, + LLVMValueRef index) +{ + LLVMValueRef element_ptr; + LLVMValueRef res; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); + assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind); + element_ptr = lp_build_array_get_ptr(gallivm, ptr, index); + res = LLVMBuildLoad(gallivm->builder, element_ptr, ""); +#ifdef DEBUG + lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index)); +#endif + return res; +} + + +void +lp_build_array_set(struct gallivm_state *gallivm, + LLVMValueRef ptr, + LLVMValueRef index, + LLVMValueRef value) +{ + LLVMValueRef element_ptr; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); + assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind); + element_ptr = lp_build_array_get_ptr(gallivm, ptr, index); + LLVMBuildStore(gallivm->builder, value, element_ptr); +} + + +LLVMValueRef +lp_build_pointer_get(LLVMBuilderRef builder, + LLVMValueRef ptr, + LLVMValueRef index) +{ + LLVMValueRef element_ptr; + LLVMValueRef res; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); + element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, ""); + res = LLVMBuildLoad(builder, element_ptr, ""); +#ifdef DEBUG + lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index)); +#endif + return res; +} + + +void +lp_build_pointer_set(LLVMBuilderRef builder, + LLVMValueRef ptr, + LLVMValueRef index, + LLVMValueRef value) +{ + LLVMValueRef element_ptr; + element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, ""); + LLVMBuildStore(builder, value, element_ptr); +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.h b/src/gallium/auxiliary/gallivm/lp_bld_struct.h new file mode 100644 index 0000000..11605c6 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.h @@ -0,0 +1,116 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Helper functions for type conversions. + * + * @author Jose Fonseca + */ + + +#ifndef LP_BLD_STRUCT_H +#define LP_BLD_STRUCT_H + + +#include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_init.h" + +#include "util/u_debug.h" +#include "util/u_memory.h" + + +#define LP_CHECK_STRUCT_SIZE(_ctype, _ltarget, _ltype) \ + assert(LLVMABISizeOfType(_ltarget, _ltype) == \ + sizeof(_ctype)) + +#define LP_CHECK_MEMBER_OFFSET(_ctype, _cmember, _ltarget, _ltype, _lindex) \ + assert(LLVMOffsetOfElement(_ltarget, _ltype, _lindex) == \ + offsetof(_ctype, _cmember)) + + +/** + * Get value pointer to a structure member. + */ +LLVMValueRef +lp_build_struct_get_ptr(struct gallivm_state *gallivm, + LLVMValueRef ptr, + unsigned member, + const char *name); + +/** + * Get the value of a structure member. + */ +LLVMValueRef +lp_build_struct_get(struct gallivm_state *gallivm, + LLVMValueRef ptr, + unsigned member, + const char *name); + +/** + * Get value pointer to an array element. + */ +LLVMValueRef +lp_build_array_get_ptr(struct gallivm_state *gallivm, + LLVMValueRef ptr, + LLVMValueRef index); + +/** + * Get the value of an array element. + */ +LLVMValueRef +lp_build_array_get(struct gallivm_state *gallivm, + LLVMValueRef ptr, + LLVMValueRef index); + +/** + * Set the value of an array element. + */ +void +lp_build_array_set(struct gallivm_state *gallivm, + LLVMValueRef ptr, + LLVMValueRef index, + LLVMValueRef value); + +/** + * Get the value of an array element. + */ +LLVMValueRef +lp_build_pointer_get(LLVMBuilderRef builder, + LLVMValueRef ptr, + LLVMValueRef index); + +/** + * Set the value of an array element. + */ +void +lp_build_pointer_set(LLVMBuilderRef builder, + LLVMValueRef ptr, + LLVMValueRef index, + LLVMValueRef value); + +#endif /* !LP_BLD_STRUCT_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c new file mode 100644 index 0000000..7169360 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c @@ -0,0 +1,518 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Helper functions for swizzling/shuffling. + * + * @author Jose Fonseca + */ + + +#include "util/u_debug.h" + +#include "lp_bld_type.h" +#include "lp_bld_const.h" +#include "lp_bld_init.h" +#include "lp_bld_logic.h" +#include "lp_bld_swizzle.h" + + +LLVMValueRef +lp_build_broadcast(struct gallivm_state *gallivm, + LLVMTypeRef vec_type, + LLVMValueRef scalar) +{ + const unsigned n = LLVMGetVectorSize(vec_type); + LLVMValueRef res; + unsigned i; + + res = LLVMGetUndef(vec_type); + for(i = 0; i < n; ++i) { + LLVMValueRef index = lp_build_const_int32(gallivm, i); + res = LLVMBuildInsertElement(gallivm->builder, res, scalar, index, ""); + } + + return res; +} + + +/** + * Broadcast + */ +LLVMValueRef +lp_build_broadcast_scalar(struct lp_build_context *bld, + LLVMValueRef scalar) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + + assert(lp_check_elem_type(type, LLVMTypeOf(scalar))); + + if (type.length == 1) { + return scalar; + } + else { + LLVMValueRef res; + +#if HAVE_LLVM >= 0x207 + /* The shuffle vector is always made of int32 elements */ + struct lp_type i32_vec_type = lp_type_int_vec(32); + i32_vec_type.length = type.length; + + res = LLVMBuildInsertElement(builder, bld->undef, scalar, + lp_build_const_int32(bld->gallivm, 0), ""); + res = LLVMBuildShuffleVector(builder, res, bld->undef, + lp_build_const_int_vec(bld->gallivm, i32_vec_type, 0), ""); +#else + /* XXX: The above path provokes a bug in LLVM 2.6 */ + unsigned i; + res = bld->undef; + for(i = 0; i < type.length; ++i) { + LLVMValueRef index = lp_build_const_int32(bld->gallivm, i); + res = LLVMBuildInsertElement(builder, res, scalar, index, ""); + } +#endif + return res; + } +} + + +/** + * Combined extract and broadcast (or a mere shuffle when the two types match) + */ +LLVMValueRef +lp_build_extract_broadcast(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + LLVMValueRef vector, + LLVMValueRef index) +{ + LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context); + LLVMValueRef res; + + assert(src_type.floating == dst_type.floating); + assert(src_type.width == dst_type.width); + + assert(lp_check_value(src_type, vector)); + assert(LLVMTypeOf(index) == i32t); + + if (src_type.length == 1) { + if (dst_type.length == 1) { + /* + * Trivial scalar -> scalar. + */ + + res = vector; + } + else { + /* + * Broadcast scalar -> vector. + */ + + res = lp_build_broadcast(gallivm, + lp_build_vec_type(gallivm, dst_type), + vector); + } + } + else { + if (dst_type.length == src_type.length) { + /* + * Special shuffle of the same size. + */ + + LLVMValueRef shuffle; + shuffle = lp_build_broadcast(gallivm, + LLVMVectorType(i32t, dst_type.length), + index); + res = LLVMBuildShuffleVector(gallivm->builder, vector, + LLVMGetUndef(lp_build_vec_type(gallivm, dst_type)), + shuffle, ""); + } + else { + LLVMValueRef scalar; + scalar = LLVMBuildExtractElement(gallivm->builder, vector, index, ""); + if (dst_type.length == 1) { + /* + * Trivial extract scalar from vector. + */ + + res = scalar; + } + else { + /* + * General case of different sized vectors. + */ + + res = lp_build_broadcast(gallivm, + lp_build_vec_type(gallivm, dst_type), + vector); + } + } + } + + return res; +} + + +/** + * Swizzle one channel into all other three channels. + */ +LLVMValueRef +lp_build_swizzle_scalar_aos(struct lp_build_context *bld, + LLVMValueRef a, + unsigned channel) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + const unsigned n = type.length; + unsigned i, j; + + if(a == bld->undef || a == bld->zero || a == bld->one) + return a; + + /* XXX: SSE3 has PSHUFB which should be better than bitmasks, but forcing + * using shuffles here actually causes worst results. More investigation is + * needed. */ + if (type.width >= 16) { + /* + * Shuffle. + */ + LLVMTypeRef elem_type = LLVMInt32TypeInContext(bld->gallivm->context); + LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH]; + + for(j = 0; j < n; j += 4) + for(i = 0; i < 4; ++i) + shuffles[j + i] = LLVMConstInt(elem_type, j + channel, 0); + + return LLVMBuildShuffleVector(builder, a, bld->undef, LLVMConstVector(shuffles, n), ""); + } + else { + /* + * Bit mask and recursive shifts + * + * XYZW XYZW .... XYZW <= input + * 0Y00 0Y00 .... 0Y00 + * YY00 YY00 .... YY00 + * YYYY YYYY .... YYYY <= output + */ + struct lp_type type4; + const char shifts[4][2] = { + { 1, 2}, + {-1, 2}, + { 1, -2}, + {-1, -2} + }; + unsigned i; + + a = LLVMBuildAnd(builder, a, + lp_build_const_mask_aos(bld->gallivm, + type, 1 << channel), ""); + + /* + * Build a type where each element is an integer that cover the four + * channels. + */ + + type4 = type; + type4.floating = FALSE; + type4.width *= 4; + type4.length /= 4; + + a = LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, type4), ""); + + for(i = 0; i < 2; ++i) { + LLVMValueRef tmp = NULL; + int shift = shifts[channel][i]; + +#ifdef PIPE_ARCH_LITTLE_ENDIAN + shift = -shift; +#endif + + if(shift > 0) + tmp = LLVMBuildLShr(builder, a, lp_build_const_int_vec(bld->gallivm, type4, shift*type.width), ""); + if(shift < 0) + tmp = LLVMBuildShl(builder, a, lp_build_const_int_vec(bld->gallivm, type4, -shift*type.width), ""); + + assert(tmp); + if(tmp) + a = LLVMBuildOr(builder, a, tmp, ""); + } + + return LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, type), ""); + } +} + + +LLVMValueRef +lp_build_swizzle_aos(struct lp_build_context *bld, + LLVMValueRef a, + const unsigned char swizzles[4]) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const struct lp_type type = bld->type; + const unsigned n = type.length; + unsigned i, j; + + if (swizzles[0] == PIPE_SWIZZLE_RED && + swizzles[1] == PIPE_SWIZZLE_GREEN && + swizzles[2] == PIPE_SWIZZLE_BLUE && + swizzles[3] == PIPE_SWIZZLE_ALPHA) { + return a; + } + + if (swizzles[0] == swizzles[1] && + swizzles[1] == swizzles[2] && + swizzles[2] == swizzles[3]) { + switch (swizzles[0]) { + case PIPE_SWIZZLE_RED: + case PIPE_SWIZZLE_GREEN: + case PIPE_SWIZZLE_BLUE: + case PIPE_SWIZZLE_ALPHA: + return lp_build_swizzle_scalar_aos(bld, a, swizzles[0]); + case PIPE_SWIZZLE_ZERO: + return bld->zero; + case PIPE_SWIZZLE_ONE: + return bld->one; + default: + assert(0); + return bld->undef; + } + } + + if (type.width >= 16) { + /* + * Shuffle. + */ + LLVMValueRef undef = LLVMGetUndef(lp_build_elem_type(bld->gallivm, type)); + LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context); + LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH]; + LLVMValueRef aux[LP_MAX_VECTOR_LENGTH]; + + memset(aux, 0, sizeof aux); + + for(j = 0; j < n; j += 4) { + for(i = 0; i < 4; ++i) { + unsigned shuffle; + switch (swizzles[i]) { + default: + assert(0); + /* fall through */ + case PIPE_SWIZZLE_RED: + case PIPE_SWIZZLE_GREEN: + case PIPE_SWIZZLE_BLUE: + case PIPE_SWIZZLE_ALPHA: + shuffle = j + swizzles[i]; + break; + case PIPE_SWIZZLE_ZERO: + shuffle = type.length + 0; + if (!aux[0]) { + aux[0] = lp_build_const_elem(bld->gallivm, type, 0.0); + } + break; + case PIPE_SWIZZLE_ONE: + shuffle = type.length + 1; + if (!aux[1]) { + aux[1] = lp_build_const_elem(bld->gallivm, type, 1.0); + } + break; + } + shuffles[j + i] = LLVMConstInt(i32t, shuffle, 0); + } + } + + for (i = 0; i < n; ++i) { + if (!aux[i]) { + aux[i] = undef; + } + } + + return LLVMBuildShuffleVector(builder, a, + LLVMConstVector(aux, n), + LLVMConstVector(shuffles, n), ""); + } else { + /* + * Bit mask and shifts. + * + * For example, this will convert BGRA to RGBA by doing + * + * rgba = (bgra & 0x00ff0000) >> 16 + * | (bgra & 0xff00ff00) + * | (bgra & 0x000000ff) << 16 + * + * This is necessary not only for faster cause, but because X86 backend + * will refuse shuffles of <4 x i8> vectors + */ + LLVMValueRef res; + struct lp_type type4; + unsigned cond = 0; + unsigned chan; + int shift; + + /* + * Start with a mixture of 1 and 0. + */ + for (chan = 0; chan < 4; ++chan) { + if (swizzles[chan] == PIPE_SWIZZLE_ONE) { + cond |= 1 << chan; + } + } + res = lp_build_select_aos(bld, cond, bld->one, bld->zero); + + /* + * Build a type where each element is an integer that cover the four + * channels. + */ + type4 = type; + type4.floating = FALSE; + type4.width *= 4; + type4.length /= 4; + + a = LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, type4), ""); + res = LLVMBuildBitCast(builder, res, lp_build_vec_type(bld->gallivm, type4), ""); + + /* + * Mask and shift the channels, trying to group as many channels in the + * same shift as possible + */ + for (shift = -3; shift <= 3; ++shift) { + unsigned long long mask = 0; + + assert(type4.width <= sizeof(mask)*8); + + for (chan = 0; chan < 4; ++chan) { + /* FIXME: big endian */ + if (swizzles[chan] < 4 && + chan - swizzles[chan] == shift) { + mask |= ((1ULL << type.width) - 1) << (swizzles[chan] * type.width); + } + } + + if (mask) { + LLVMValueRef masked; + LLVMValueRef shifted; + + if (0) + debug_printf("shift = %i, mask = 0x%08llx\n", shift, mask); + + masked = LLVMBuildAnd(builder, a, + lp_build_const_int_vec(bld->gallivm, type4, mask), ""); + if (shift > 0) { + shifted = LLVMBuildShl(builder, masked, + lp_build_const_int_vec(bld->gallivm, type4, shift*type.width), ""); + } else if (shift < 0) { + shifted = LLVMBuildLShr(builder, masked, + lp_build_const_int_vec(bld->gallivm, type4, -shift*type.width), ""); + } else { + shifted = masked; + } + + res = LLVMBuildOr(builder, res, shifted, ""); + } + } + + return LLVMBuildBitCast(builder, res, + lp_build_vec_type(bld->gallivm, type), ""); + } +} + + +/** + * Extended swizzle of a single channel of a SoA vector. + * + * @param bld building context + * @param unswizzled array with the 4 unswizzled values + * @param swizzle one of the PIPE_SWIZZLE_* + * + * @return the swizzled value. + */ +LLVMValueRef +lp_build_swizzle_soa_channel(struct lp_build_context *bld, + const LLVMValueRef *unswizzled, + unsigned swizzle) +{ + switch (swizzle) { + case PIPE_SWIZZLE_RED: + case PIPE_SWIZZLE_GREEN: + case PIPE_SWIZZLE_BLUE: + case PIPE_SWIZZLE_ALPHA: + return unswizzled[swizzle]; + case PIPE_SWIZZLE_ZERO: + return bld->zero; + case PIPE_SWIZZLE_ONE: + return bld->one; + default: + assert(0); + return bld->undef; + } +} + + +/** + * Extended swizzle of a SoA vector. + * + * @param bld building context + * @param unswizzled array with the 4 unswizzled values + * @param swizzles array of PIPE_SWIZZLE_* + * @param swizzled output swizzled values + */ +void +lp_build_swizzle_soa(struct lp_build_context *bld, + const LLVMValueRef *unswizzled, + const unsigned char swizzles[4], + LLVMValueRef *swizzled) +{ + unsigned chan; + + for (chan = 0; chan < 4; ++chan) { + swizzled[chan] = lp_build_swizzle_soa_channel(bld, unswizzled, + swizzles[chan]); + } +} + + +/** + * Do an extended swizzle of a SoA vector inplace. + * + * @param bld building context + * @param values intput/output array with the 4 values + * @param swizzles array of PIPE_SWIZZLE_* + */ +void +lp_build_swizzle_soa_inplace(struct lp_build_context *bld, + LLVMValueRef *values, + const unsigned char swizzles[4]) +{ + LLVMValueRef unswizzled[4]; + unsigned chan; + + for (chan = 0; chan < 4; ++chan) { + unswizzled[chan] = values[chan]; + } + + lp_build_swizzle_soa(bld, unswizzled, swizzles, values); +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h new file mode 100644 index 0000000..c366a65 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h @@ -0,0 +1,106 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Helper functions for swizzling/shuffling. + * + * @author Jose Fonseca + */ + + +#ifndef LP_BLD_SWIZZLE_H +#define LP_BLD_SWIZZLE_H + + +#include "gallivm/lp_bld.h" + + +struct lp_type; +struct lp_build_context; + + +LLVMValueRef +lp_build_broadcast(struct gallivm_state *gallivm, + LLVMTypeRef vec_type, + LLVMValueRef scalar); + + +LLVMValueRef +lp_build_broadcast_scalar(struct lp_build_context *bld, + LLVMValueRef scalar); + + +LLVMValueRef +lp_build_extract_broadcast(struct gallivm_state *gallivm, + struct lp_type src_type, + struct lp_type dst_type, + LLVMValueRef vector, + LLVMValueRef index); + + +/** + * Broadcast one channel of a vector composed of arrays of XYZW structures into + * all four channel. + */ +LLVMValueRef +lp_build_swizzle_scalar_aos(struct lp_build_context *bld, + LLVMValueRef a, + unsigned channel); + + +/** + * Swizzle a vector consisting of an array of XYZW structs. + * + * @param swizzles is the in [0,4[ range. + */ +LLVMValueRef +lp_build_swizzle_aos(struct lp_build_context *bld, + LLVMValueRef a, + const unsigned char swizzles[4]); + + +LLVMValueRef +lp_build_swizzle_soa_channel(struct lp_build_context *bld, + const LLVMValueRef *unswizzled, + unsigned swizzle); + + +void +lp_build_swizzle_soa(struct lp_build_context *bld, + const LLVMValueRef *unswizzled, + const unsigned char swizzles[4], + LLVMValueRef *swizzled); + + +void +lp_build_swizzle_soa_inplace(struct lp_build_context *bld, + LLVMValueRef *values, + const unsigned char swizzles[4]); + + +#endif /* !LP_BLD_SWIZZLE_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h new file mode 100644 index 0000000..40186be --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h @@ -0,0 +1,202 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * TGSI to LLVM IR translation. + * + * @author Jose Fonseca + */ + +#ifndef LP_BLD_TGSI_H +#define LP_BLD_TGSI_H + +#include "gallivm/lp_bld.h" +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "tgsi/tgsi_scan.h" + + +struct tgsi_token; +struct tgsi_shader_info; +struct lp_type; +struct lp_build_context; +struct lp_build_mask_context; +struct gallivm_state; + + +enum lp_build_tex_modifier { + LP_BLD_TEX_MODIFIER_NONE = 0, + LP_BLD_TEX_MODIFIER_PROJECTED, + LP_BLD_TEX_MODIFIER_LOD_BIAS, + LP_BLD_TEX_MODIFIER_EXPLICIT_LOD, + LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV +}; + + +/** + * Describe a channel of a register. + * + * The value can be a: + * - immediate value (i.e. derived from a IMM register) + * - CONST[n].x/y/z/w + * - IN[n].x/y/z/w + * - undetermined (when .file == TGSI_FILE_NULL) + * + * This is one of the analysis results, and is used to described + * the output color in terms of inputs. + */ +struct lp_tgsi_channel_info +{ + unsigned file:4; /* TGSI_FILE_* */ + unsigned swizzle:3; /* PIPE_SWIZZLE_x */ + union { + uint32_t index; + float value; /* for TGSI_FILE_IMMEDIATE */ + } u; +}; + + +/** + * Describe a texture sampler interpolator. + * + * The interpolation is described in terms of regular inputs. + */ +struct lp_tgsi_texture_info +{ + struct lp_tgsi_channel_info coord[4]; + unsigned target:8; /* TGSI_TEXTURE_* */ + unsigned unit:8; /* Sampler unit */ + unsigned modifier:8; /* LP_BLD_TEX_MODIFIER_* */ +}; + + +struct lp_tgsi_info +{ + struct tgsi_shader_info base; + + /* + * Whether any of the texture opcodes access a register file other than + * TGSI_FILE_INPUT. + * + * We could also handle TGSI_FILE_CONST/IMMEDIATE here, but there is little + * benefit. + */ + unsigned indirect_textures:1; + + /* + * Texture opcode description. Aimed at detecting and described direct + * texture opcodes. + */ + unsigned num_texs; + struct lp_tgsi_texture_info tex[PIPE_MAX_SAMPLERS]; + + /* + * Output description. Aimed at detecting and describing simple blit + * shaders. + */ + struct lp_tgsi_channel_info output[PIPE_MAX_SHADER_OUTPUTS][4]; + + /* + * Shortcut pointers into the above (for fragment shaders). + */ + const struct lp_tgsi_channel_info *cbuf[PIPE_MAX_COLOR_BUFS]; +}; + +/** + * Sampler code generation interface. + * + * Although texture sampling is a requirement for TGSI translation, it is + * a very different problem with several different approaches to it. This + * structure establishes an interface for texture sampling code generation, so + * that we can easily use different texture sampling strategies. + */ +struct lp_build_sampler_soa +{ + void + (*destroy)( struct lp_build_sampler_soa *sampler ); + + void + (*emit_fetch_texel)( const struct lp_build_sampler_soa *sampler, + struct gallivm_state *gallivm, + struct lp_type type, + unsigned unit, + unsigned num_coords, + const LLVMValueRef *coords, + const LLVMValueRef *ddx, + const LLVMValueRef *ddy, + LLVMValueRef lod_bias, /* optional */ + LLVMValueRef explicit_lod, /* optional */ + LLVMValueRef *texel); +}; + + +struct lp_build_sampler_aos +{ + LLVMValueRef + (*emit_fetch_texel)( struct lp_build_sampler_aos *sampler, + struct lp_build_context *bld, + unsigned target, /* TGSI_TEXTURE_* */ + unsigned unit, + LLVMValueRef coords, + LLVMValueRef ddx, + LLVMValueRef ddy, + enum lp_build_tex_modifier modifier); +}; + + +void +lp_build_tgsi_info(const struct tgsi_token *tokens, + struct lp_tgsi_info *info); + + +void +lp_build_tgsi_soa(struct gallivm_state *gallivm, + const struct tgsi_token *tokens, + struct lp_type type, + struct lp_build_mask_context *mask, + LLVMValueRef consts_ptr, + const LLVMValueRef *pos, + const LLVMValueRef (*inputs)[4], + LLVMValueRef (*outputs)[4], + struct lp_build_sampler_soa *sampler, + const struct tgsi_shader_info *info); + + +void +lp_build_tgsi_aos(struct gallivm_state *gallivm, + const struct tgsi_token *tokens, + struct lp_type type, + const unsigned char swizzles[4], + LLVMValueRef consts_ptr, + const LLVMValueRef *inputs, + LLVMValueRef *outputs, + struct lp_build_sampler_aos *sampler, + const struct tgsi_shader_info *info); + + +#endif /* LP_BLD_TGSI_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c new file mode 100644 index 0000000..a021efd --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c @@ -0,0 +1,1173 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * TGSI to LLVM IR translation -- AoS. + * + * FIXME: + * - No control flow support: the existing control flow code should be factored + * out into from the SoA code into a common module and shared. + * - No derivatives. Derivate logic should be pluggable, just like the samplers. + * + * @author Jose Fonseca + */ + +#include "pipe/p_config.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_debug.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_info.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "tgsi/tgsi_scan.h" +#include "lp_bld_type.h" +#include "lp_bld_const.h" +#include "lp_bld_arit.h" +#include "lp_bld_logic.h" +#include "lp_bld_swizzle.h" +#include "lp_bld_flow.h" +#include "lp_bld_quad.h" +#include "lp_bld_tgsi.h" +#include "lp_bld_limits.h" +#include "lp_bld_debug.h" + + +#define LP_MAX_INSTRUCTIONS 256 + + +struct lp_build_tgsi_aos_context +{ + struct lp_build_context base; + + /* Builder for integer masks and indices */ + struct lp_build_context int_bld; + + /* + * AoS swizzle used: + * - swizzles[0] = red index + * - swizzles[1] = green index + * - swizzles[2] = blue index + * - swizzles[3] = alpha index + */ + unsigned char swizzles[4]; + unsigned char inv_swizzles[4]; + + LLVMValueRef consts_ptr; + const LLVMValueRef *inputs; + LLVMValueRef *outputs; + + struct lp_build_sampler_aos *sampler; + + LLVMValueRef immediates[LP_MAX_TGSI_IMMEDIATES]; + LLVMValueRef temps[LP_MAX_TGSI_TEMPS]; + LLVMValueRef addr[LP_MAX_TGSI_ADDRS]; + LLVMValueRef preds[LP_MAX_TGSI_PREDS]; + + /* We allocate/use this array of temps if (1 << TGSI_FILE_TEMPORARY) is + * set in the indirect_files field. + * The temps[] array above is unused then. + */ + LLVMValueRef temps_array; + + /** bitmask indicating which register files are accessed indirectly */ + unsigned indirect_files; + + struct tgsi_full_instruction *instructions; + uint max_instructions; +}; + + +/** + * Wrapper around lp_build_swizzle_aos which translates swizzles to another + * ordering. + */ +static LLVMValueRef +swizzle_aos(struct lp_build_tgsi_aos_context *bld, + LLVMValueRef a, + unsigned swizzle_x, + unsigned swizzle_y, + unsigned swizzle_z, + unsigned swizzle_w) +{ + unsigned char swizzles[4]; + + assert(swizzle_x < 4); + assert(swizzle_y < 4); + assert(swizzle_z < 4); + assert(swizzle_w < 4); + + swizzles[bld->inv_swizzles[0]] = bld->swizzles[swizzle_x]; + swizzles[bld->inv_swizzles[1]] = bld->swizzles[swizzle_y]; + swizzles[bld->inv_swizzles[2]] = bld->swizzles[swizzle_z]; + swizzles[bld->inv_swizzles[3]] = bld->swizzles[swizzle_w]; + + return lp_build_swizzle_aos(&bld->base, a, swizzles); +} + + +static LLVMValueRef +swizzle_scalar_aos(struct lp_build_tgsi_aos_context *bld, + LLVMValueRef a, + unsigned chan) +{ + chan = bld->swizzles[chan]; + return lp_build_swizzle_scalar_aos(&bld->base, a, chan); +} + + +/** + * Register fetch. + */ +static LLVMValueRef +emit_fetch( + struct lp_build_tgsi_aos_context *bld, + const struct tgsi_full_instruction *inst, + unsigned src_op) +{ + LLVMBuilderRef builder = bld->base.gallivm->builder; + struct lp_type type = bld->base.type; + const struct tgsi_full_src_register *reg = &inst->Src[src_op]; + LLVMValueRef res; + unsigned chan; + + assert(!reg->Register.Indirect); + + /* + * Fetch the from the register file. + */ + + switch (reg->Register.File) { + case TGSI_FILE_CONSTANT: + /* + * Get the constants components + */ + + res = bld->base.undef; + for (chan = 0; chan < 4; ++chan) { + LLVMValueRef index; + LLVMValueRef scalar_ptr; + LLVMValueRef scalar; + LLVMValueRef swizzle; + + index = lp_build_const_int32(bld->base.gallivm, reg->Register.Index * 4 + chan); + + scalar_ptr = LLVMBuildGEP(builder, bld->consts_ptr, + &index, 1, ""); + + scalar = LLVMBuildLoad(builder, scalar_ptr, ""); + + lp_build_name(scalar, "const[%u].%c", reg->Register.Index, "xyzw"[chan]); + + /* + * NOTE: constants array is always assumed to be RGBA + */ + + swizzle = lp_build_const_int32(bld->base.gallivm, chan); + + res = LLVMBuildInsertElement(builder, res, scalar, swizzle, ""); + } + + /* + * Broadcast the first quaternion to all others. + * + * XXX: could be factored into a reusable function. + */ + + if (type.length > 4) { + LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH]; + unsigned i; + + for (chan = 0; chan < 4; ++chan) { + shuffles[chan] = lp_build_const_int32(bld->base.gallivm, chan); + } + + for (i = 4; i < type.length; ++i) { + shuffles[i] = shuffles[i % 4]; + } + + res = LLVMBuildShuffleVector(builder, + res, bld->base.undef, + LLVMConstVector(shuffles, type.length), + ""); + } + break; + + case TGSI_FILE_IMMEDIATE: + res = bld->immediates[reg->Register.Index]; + assert(res); + break; + + case TGSI_FILE_INPUT: + res = bld->inputs[reg->Register.Index]; + assert(res); + break; + + case TGSI_FILE_TEMPORARY: + { + LLVMValueRef temp_ptr; + temp_ptr = bld->temps[reg->Register.Index]; + res = LLVMBuildLoad(builder, temp_ptr, ""); + if (!res) + return bld->base.undef; + } + break; + + default: + assert(0 && "invalid src register in emit_fetch()"); + return bld->base.undef; + } + + /* + * Apply sign modifier. + */ + + if (reg->Register.Absolute) { + res = lp_build_abs(&bld->base, res); + } + + if(reg->Register.Negate) { + res = lp_build_negate(&bld->base, res); + } + + /* + * Swizzle the argument + */ + + res = swizzle_aos(bld, res, + reg->Register.SwizzleX, + reg->Register.SwizzleY, + reg->Register.SwizzleZ, + reg->Register.SwizzleW); + + return res; +} + + +/** + * Register store. + */ +static void +emit_store( + struct lp_build_tgsi_aos_context *bld, + const struct tgsi_full_instruction *inst, + unsigned index, + LLVMValueRef value) +{ + LLVMBuilderRef builder = bld->base.gallivm->builder; + const struct tgsi_full_dst_register *reg = &inst->Dst[index]; + LLVMValueRef mask = NULL; + LLVMValueRef ptr; + + /* + * Saturate the value + */ + + switch (inst->Instruction.Saturate) { + case TGSI_SAT_NONE: + break; + + case TGSI_SAT_ZERO_ONE: + value = lp_build_max(&bld->base, value, bld->base.zero); + value = lp_build_min(&bld->base, value, bld->base.one); + break; + + case TGSI_SAT_MINUS_PLUS_ONE: + value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.gallivm, bld->base.type, -1.0)); + value = lp_build_min(&bld->base, value, bld->base.one); + break; + + default: + assert(0); + } + + /* + * Translate the register file + */ + + assert(!reg->Register.Indirect); + + switch (reg->Register.File) { + case TGSI_FILE_OUTPUT: + ptr = bld->outputs[reg->Register.Index]; + break; + + case TGSI_FILE_TEMPORARY: + ptr = bld->temps[reg->Register.Index]; + break; + + case TGSI_FILE_ADDRESS: + ptr = bld->addr[reg->Indirect.Index]; + break; + + case TGSI_FILE_PREDICATE: + ptr = bld->preds[reg->Register.Index]; + break; + + default: + assert(0); + return; + } + + /* + * Predicate + */ + + if (inst->Instruction.Predicate) { + LLVMValueRef pred; + + assert(inst->Predicate.Index < LP_MAX_TGSI_PREDS); + + pred = LLVMBuildLoad(builder, + bld->preds[inst->Predicate.Index], ""); + + /* + * Convert the value to an integer mask. + */ + pred = lp_build_compare(bld->base.gallivm, + bld->base.type, + PIPE_FUNC_NOTEQUAL, + pred, + bld->base.zero); + + if (inst->Predicate.Negate) { + pred = LLVMBuildNot(builder, pred, ""); + } + + pred = swizzle_aos(bld, pred, + inst->Predicate.SwizzleX, + inst->Predicate.SwizzleY, + inst->Predicate.SwizzleZ, + inst->Predicate.SwizzleW); + + if (mask) { + mask = LLVMBuildAnd(builder, mask, pred, ""); + } else { + mask = pred; + } + } + + /* + * Writemask + */ + + if (reg->Register.WriteMask != TGSI_WRITEMASK_XYZW) { + LLVMValueRef writemask; + + writemask = lp_build_const_mask_aos(bld->base.gallivm, bld->base.type, + reg->Register.WriteMask); + + if (mask) { + mask = LLVMBuildAnd(builder, mask, writemask, ""); + } else { + mask = writemask; + } + } + + if (mask) { + LLVMValueRef orig_value; + + orig_value = LLVMBuildLoad(builder, ptr, ""); + value = lp_build_select(&bld->base, + mask, value, orig_value); + } + + LLVMBuildStore(builder, value, ptr); +} + + +/** + * High-level instruction translators. + */ + +static LLVMValueRef +emit_tex(struct lp_build_tgsi_aos_context *bld, + const struct tgsi_full_instruction *inst, + enum lp_build_tex_modifier modifier) +{ + unsigned target; + unsigned unit; + LLVMValueRef coords; + LLVMValueRef ddx; + LLVMValueRef ddy; + + if (!bld->sampler) { + _debug_printf("warning: found texture instruction but no sampler generator supplied\n"); + return bld->base.undef; + } + + target = inst->Texture.Texture; + + coords = emit_fetch( bld, inst, 0 ); + + if (modifier == LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV) { + ddx = emit_fetch( bld, inst, 1 ); + ddy = emit_fetch( bld, inst, 2 ); + unit = inst->Src[3].Register.Index; + } else { +#if 0 + ddx = lp_build_ddx( &bld->base, coords ); + ddy = lp_build_ddy( &bld->base, coords ); +#else + /* TODO */ + ddx = bld->base.one; + ddy = bld->base.one; +#endif + unit = inst->Src[1].Register.Index; + } + + return bld->sampler->emit_fetch_texel(bld->sampler, + &bld->base, + target, unit, + coords, ddx, ddy, + modifier); +} + + +static void +emit_declaration( + struct lp_build_tgsi_aos_context *bld, + const struct tgsi_full_declaration *decl) +{ + struct gallivm_state *gallivm = bld->base.gallivm; + LLVMTypeRef vec_type = lp_build_vec_type(bld->base.gallivm, bld->base.type); + + unsigned first = decl->Range.First; + unsigned last = decl->Range.Last; + unsigned idx; + + for (idx = first; idx <= last; ++idx) { + switch (decl->Declaration.File) { + case TGSI_FILE_TEMPORARY: + assert(idx < LP_MAX_TGSI_TEMPS); + if (bld->indirect_files & (1 << TGSI_FILE_TEMPORARY)) { + LLVMValueRef array_size = lp_build_const_int32(gallivm, last + 1); + bld->temps_array = lp_build_array_alloca(bld->base.gallivm, + vec_type, array_size, ""); + } else { + bld->temps[idx] = lp_build_alloca(gallivm, vec_type, ""); + } + break; + + case TGSI_FILE_OUTPUT: + bld->outputs[idx] = lp_build_alloca(gallivm, vec_type, ""); + break; + + case TGSI_FILE_ADDRESS: + assert(idx < LP_MAX_TGSI_ADDRS); + bld->addr[idx] = lp_build_alloca(gallivm, vec_type, ""); + break; + + case TGSI_FILE_PREDICATE: + assert(idx < LP_MAX_TGSI_PREDS); + bld->preds[idx] = lp_build_alloca(gallivm, vec_type, ""); + break; + + default: + /* don't need to declare other vars */ + break; + } + } +} + + +/** + * Emit LLVM for one TGSI instruction. + * \param return TRUE for success, FALSE otherwise + */ +static boolean +emit_instruction( + struct lp_build_tgsi_aos_context *bld, + const struct tgsi_full_instruction *inst, + const struct tgsi_opcode_info *info, + int *pc) +{ + LLVMValueRef src0, src1, src2; + LLVMValueRef tmp0, tmp1; + LLVMValueRef dst0 = NULL; + + /* + * Stores and write masks are handled in a general fashion after the long + * instruction opcode switch statement. + * + * Although not stricitly necessary, we avoid generating instructions for + * channels which won't be stored, in cases where's that easy. For some + * complex instructions, like texture sampling, it is more convenient to + * assume a full writemask and then let LLVM optimization passes eliminate + * redundant code. + */ + + (*pc)++; + + assert(info->num_dst <= 1); + if (info->num_dst) { + dst0 = bld->base.undef; + } + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_ARL: + src0 = emit_fetch(bld, inst, 0); + dst0 = lp_build_floor(&bld->base, src0); + break; + + case TGSI_OPCODE_MOV: + dst0 = emit_fetch(bld, inst, 0); + break; + + case TGSI_OPCODE_LIT: + return FALSE; + + case TGSI_OPCODE_RCP: + /* TGSI_OPCODE_RECIP */ + src0 = emit_fetch(bld, inst, 0); + dst0 = lp_build_rcp(&bld->base, src0); + break; + + case TGSI_OPCODE_RSQ: + /* TGSI_OPCODE_RECIPSQRT */ + src0 = emit_fetch(bld, inst, 0); + tmp0 = lp_build_abs(&bld->base, src0); + dst0 = lp_build_rsqrt(&bld->base, tmp0); + break; + + case TGSI_OPCODE_EXP: + return FALSE; + + case TGSI_OPCODE_LOG: + return FALSE; + + case TGSI_OPCODE_MUL: + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + dst0 = lp_build_mul(&bld->base, src0, src1); + break; + + case TGSI_OPCODE_ADD: + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + dst0 = lp_build_add(&bld->base, src0, src1); + break; + + case TGSI_OPCODE_DP3: + /* TGSI_OPCODE_DOT3 */ + return FALSE; + + case TGSI_OPCODE_DP4: + /* TGSI_OPCODE_DOT4 */ + return FALSE; + + case TGSI_OPCODE_DST: + return FALSE; + + case TGSI_OPCODE_MIN: + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + dst0 = lp_build_max(&bld->base, src0, src1); + break; + + case TGSI_OPCODE_MAX: + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + dst0 = lp_build_max(&bld->base, src0, src1); + break; + + case TGSI_OPCODE_SLT: + /* TGSI_OPCODE_SETLT */ + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + tmp0 = lp_build_cmp(&bld->base, PIPE_FUNC_LESS, src0, src1); + dst0 = lp_build_select(&bld->base, tmp0, bld->base.one, bld->base.zero); + break; + + case TGSI_OPCODE_SGE: + /* TGSI_OPCODE_SETGE */ + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + tmp0 = lp_build_cmp(&bld->base, PIPE_FUNC_GEQUAL, src0, src1); + dst0 = lp_build_select(&bld->base, tmp0, bld->base.one, bld->base.zero); + break; + + case TGSI_OPCODE_MAD: + /* TGSI_OPCODE_MADD */ + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + src2 = emit_fetch(bld, inst, 2); + tmp0 = lp_build_mul(&bld->base, src0, src1); + dst0 = lp_build_add(&bld->base, tmp0, src2); + break; + + case TGSI_OPCODE_SUB: + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + dst0 = lp_build_sub(&bld->base, src0, src1); + break; + + case TGSI_OPCODE_LRP: + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + src2 = emit_fetch(bld, inst, 2); + tmp0 = lp_build_sub(&bld->base, src1, src2); + tmp0 = lp_build_mul(&bld->base, src0, tmp0); + dst0 = lp_build_add(&bld->base, tmp0, src2); + break; + + case TGSI_OPCODE_CND: + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + src2 = emit_fetch(bld, inst, 2); + tmp1 = lp_build_const_vec(bld->base.gallivm, bld->base.type, 0.5); + tmp0 = lp_build_cmp(&bld->base, PIPE_FUNC_GREATER, src2, tmp1); + dst0 = lp_build_select(&bld->base, tmp0, src0, src1); + break; + + case TGSI_OPCODE_DP2A: + return FALSE; + + case TGSI_OPCODE_FRC: + src0 = emit_fetch(bld, inst, 0); + tmp0 = lp_build_floor(&bld->base, src0); + dst0 = lp_build_sub(&bld->base, src0, tmp0); + break; + + case TGSI_OPCODE_CLAMP: + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + src2 = emit_fetch(bld, inst, 2); + tmp0 = lp_build_max(&bld->base, src0, src1); + dst0 = lp_build_min(&bld->base, tmp0, src2); + break; + + case TGSI_OPCODE_FLR: + src0 = emit_fetch(bld, inst, 0); + dst0 = lp_build_floor(&bld->base, src0); + break; + + case TGSI_OPCODE_ROUND: + src0 = emit_fetch(bld, inst, 0); + dst0 = lp_build_round(&bld->base, src0); + break; + + case TGSI_OPCODE_EX2: + src0 = emit_fetch(bld, inst, 0); + tmp0 = lp_build_swizzle_scalar_aos(&bld->base, src0, TGSI_SWIZZLE_X); + dst0 = lp_build_exp2(&bld->base, tmp0); + break; + + case TGSI_OPCODE_LG2: + src0 = emit_fetch(bld, inst, 0); + tmp0 = swizzle_scalar_aos(bld, src0, TGSI_SWIZZLE_X); + dst0 = lp_build_log2(&bld->base, tmp0); + break; + + case TGSI_OPCODE_POW: + src0 = emit_fetch(bld, inst, 0); + src0 = swizzle_scalar_aos(bld, src0, TGSI_SWIZZLE_X); + src1 = emit_fetch(bld, inst, 1); + src1 = swizzle_scalar_aos(bld, src1, TGSI_SWIZZLE_X); + dst0 = lp_build_pow(&bld->base, src0, src1); + break; + + case TGSI_OPCODE_XPD: + return FALSE; + + case TGSI_OPCODE_ABS: + src0 = emit_fetch(bld, inst, 0); + dst0 = lp_build_abs(&bld->base, src0); + break; + + case TGSI_OPCODE_RCC: + /* deprecated? */ + assert(0); + return FALSE; + + case TGSI_OPCODE_DPH: + return FALSE; + + case TGSI_OPCODE_COS: + src0 = emit_fetch(bld, inst, 0); + tmp0 = swizzle_scalar_aos(bld, src0, TGSI_SWIZZLE_X); + dst0 = lp_build_cos(&bld->base, tmp0); + break; + + case TGSI_OPCODE_DDX: + return FALSE; + + case TGSI_OPCODE_DDY: + return FALSE; + + case TGSI_OPCODE_KILP: + /* predicated kill */ + return FALSE; + + case TGSI_OPCODE_KIL: + /* conditional kill */ + return FALSE; + + case TGSI_OPCODE_PK2H: + return FALSE; + break; + + case TGSI_OPCODE_PK2US: + return FALSE; + break; + + case TGSI_OPCODE_PK4B: + return FALSE; + break; + + case TGSI_OPCODE_PK4UB: + return FALSE; + + case TGSI_OPCODE_RFL: + return FALSE; + + case TGSI_OPCODE_SEQ: + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + tmp0 = lp_build_cmp(&bld->base, PIPE_FUNC_EQUAL, src0, src1); + dst0 = lp_build_select(&bld->base, tmp0, bld->base.one, bld->base.zero); + break; + + case TGSI_OPCODE_SFL: + dst0 = bld->base.zero; + break; + + case TGSI_OPCODE_SGT: + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + tmp0 = lp_build_cmp(&bld->base, PIPE_FUNC_GREATER, src0, src1); + dst0 = lp_build_select(&bld->base, tmp0, bld->base.one, bld->base.zero); + break; + + case TGSI_OPCODE_SIN: + src0 = emit_fetch(bld, inst, 0); + tmp0 = swizzle_scalar_aos(bld, src0, TGSI_SWIZZLE_X); + dst0 = lp_build_sin(&bld->base, tmp0); + break; + + case TGSI_OPCODE_SLE: + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + tmp0 = lp_build_cmp(&bld->base, PIPE_FUNC_LEQUAL, src0, src1); + dst0 = lp_build_select(&bld->base, tmp0, bld->base.one, bld->base.zero); + break; + + case TGSI_OPCODE_SNE: + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + tmp0 = lp_build_cmp(&bld->base, PIPE_FUNC_NOTEQUAL, src0, src1); + dst0 = lp_build_select(&bld->base, tmp0, bld->base.one, bld->base.zero); + break; + + case TGSI_OPCODE_STR: + dst0 = bld->base.one; + break; + + case TGSI_OPCODE_TEX: + dst0 = emit_tex(bld, inst, LP_BLD_TEX_MODIFIER_NONE); + break; + + case TGSI_OPCODE_TXD: + dst0 = emit_tex(bld, inst, LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV); + break; + + case TGSI_OPCODE_UP2H: + /* deprecated */ + assert (0); + return FALSE; + break; + + case TGSI_OPCODE_UP2US: + /* deprecated */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_UP4B: + /* deprecated */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_UP4UB: + /* deprecated */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_X2D: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_ARA: + /* deprecated */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_ARR: + src0 = emit_fetch(bld, inst, 0); + dst0 = lp_build_round(&bld->base, src0); + break; + + case TGSI_OPCODE_BRA: + /* deprecated */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_CAL: + return FALSE; + + case TGSI_OPCODE_RET: + return FALSE; + + case TGSI_OPCODE_END: + *pc = -1; + break; + + case TGSI_OPCODE_SSG: + /* TGSI_OPCODE_SGN */ + tmp0 = emit_fetch(bld, inst, 0); + dst0 = lp_build_sgn(&bld->base, tmp0); + break; + + case TGSI_OPCODE_CMP: + src0 = emit_fetch(bld, inst, 0); + src1 = emit_fetch(bld, inst, 1); + src2 = emit_fetch(bld, inst, 2); + tmp0 = lp_build_cmp(&bld->base, PIPE_FUNC_LESS, src0, bld->base.zero); + dst0 = lp_build_select(&bld->base, tmp0, src1, src2); + break; + + case TGSI_OPCODE_SCS: + return FALSE; + + case TGSI_OPCODE_TXB: + dst0 = emit_tex(bld, inst, LP_BLD_TEX_MODIFIER_LOD_BIAS); + break; + + case TGSI_OPCODE_NRM: + /* fall-through */ + case TGSI_OPCODE_NRM4: + return FALSE; + + case TGSI_OPCODE_DIV: + /* deprecated */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_DP2: + return FALSE; + + case TGSI_OPCODE_TXL: + dst0 = emit_tex(bld, inst, LP_BLD_TEX_MODIFIER_EXPLICIT_LOD); + break; + + case TGSI_OPCODE_TXP: + dst0 = emit_tex(bld, inst, LP_BLD_TEX_MODIFIER_PROJECTED); + break; + + case TGSI_OPCODE_BRK: + return FALSE; + + case TGSI_OPCODE_IF: + return FALSE; + + case TGSI_OPCODE_BGNLOOP: + return FALSE; + + case TGSI_OPCODE_BGNSUB: + return FALSE; + + case TGSI_OPCODE_ELSE: + return FALSE; + + case TGSI_OPCODE_ENDIF: + return FALSE; + + case TGSI_OPCODE_ENDLOOP: + return FALSE; + + case TGSI_OPCODE_ENDSUB: + return FALSE; + + case TGSI_OPCODE_PUSHA: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_POPA: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_CEIL: + src0 = emit_fetch(bld, inst, 0); + dst0 = lp_build_ceil(&bld->base, src0); + break; + + case TGSI_OPCODE_I2F: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_NOT: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_TRUNC: + src0 = emit_fetch(bld, inst, 0); + dst0 = lp_build_trunc(&bld->base, src0); + break; + + case TGSI_OPCODE_SHL: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_ISHR: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_AND: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_OR: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_MOD: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_XOR: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_SAD: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_TXF: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_TXQ: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_CONT: + return FALSE; + + case TGSI_OPCODE_EMIT: + return FALSE; + break; + + case TGSI_OPCODE_ENDPRIM: + return FALSE; + break; + + case TGSI_OPCODE_NOP: + break; + + default: + return FALSE; + } + + if (info->num_dst) { + emit_store(bld, inst, 0, dst0); + } + + return TRUE; +} + + +void +lp_build_tgsi_aos(struct gallivm_state *gallivm, + const struct tgsi_token *tokens, + struct lp_type type, + const unsigned char swizzles[4], + LLVMValueRef consts_ptr, + const LLVMValueRef *inputs, + LLVMValueRef *outputs, + struct lp_build_sampler_aos *sampler, + const struct tgsi_shader_info *info) +{ + struct lp_build_tgsi_aos_context bld; + struct tgsi_parse_context parse; + uint num_immediates = 0; + uint num_instructions = 0; + unsigned chan; + int pc = 0; + + /* Setup build context */ + memset(&bld, 0, sizeof bld); + lp_build_context_init(&bld.base, gallivm, type); + lp_build_context_init(&bld.int_bld, gallivm, lp_int_type(type)); + + for (chan = 0; chan < 4; ++chan) { + bld.swizzles[chan] = swizzles[chan]; + bld.inv_swizzles[swizzles[chan]] = chan; + } + + bld.inputs = inputs; + bld.outputs = outputs; + bld.consts_ptr = consts_ptr; + bld.sampler = sampler; + bld.indirect_files = info->indirect_files; + bld.instructions = (struct tgsi_full_instruction *) + MALLOC(LP_MAX_INSTRUCTIONS * sizeof(struct tgsi_full_instruction)); + bld.max_instructions = LP_MAX_INSTRUCTIONS; + + if (!bld.instructions) { + return; + } + + tgsi_parse_init(&parse, tokens); + + while (!tgsi_parse_end_of_tokens(&parse)) { + tgsi_parse_token(&parse); + + switch(parse.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_DECLARATION: + /* Inputs already interpolated */ + emit_declaration(&bld, &parse.FullToken.FullDeclaration); + break; + + case TGSI_TOKEN_TYPE_INSTRUCTION: + { + /* save expanded instruction */ + if (num_instructions == bld.max_instructions) { + struct tgsi_full_instruction *instructions; + instructions = REALLOC(bld.instructions, + bld.max_instructions + * sizeof(struct tgsi_full_instruction), + (bld.max_instructions + LP_MAX_INSTRUCTIONS) + * sizeof(struct tgsi_full_instruction)); + if (!instructions) { + break; + } + bld.instructions = instructions; + bld.max_instructions += LP_MAX_INSTRUCTIONS; + } + + memcpy(bld.instructions + num_instructions, + &parse.FullToken.FullInstruction, + sizeof(bld.instructions[0])); + + num_instructions++; + } + + break; + + case TGSI_TOKEN_TYPE_IMMEDIATE: + /* simply copy the immediate values into the next immediates[] slot */ + { + const uint size = parse.FullToken.FullImmediate.Immediate.NrTokens - 1; + float imm[4]; + assert(size <= 4); + assert(num_immediates < LP_MAX_TGSI_IMMEDIATES); + for (chan = 0; chan < 4; ++chan) { + imm[chan] = 0.0f; + } + for (chan = 0; chan < size; ++chan) { + unsigned swizzle = bld.swizzles[chan]; + imm[swizzle] = parse.FullToken.FullImmediate.u[chan].Float; + } + bld.immediates[num_immediates] = + lp_build_const_aos(gallivm, type, + imm[0], imm[1], imm[2], imm[3], + NULL); + num_immediates++; + } + break; + + case TGSI_TOKEN_TYPE_PROPERTY: + break; + + default: + assert(0); + } + } + + while (pc != -1) { + struct tgsi_full_instruction *instr = bld.instructions + pc; + const struct tgsi_opcode_info *opcode_info = + tgsi_get_opcode_info(instr->Instruction.Opcode); + if (!emit_instruction(&bld, instr, opcode_info, &pc)) + _debug_printf("warning: failed to translate tgsi opcode %s to LLVM\n", + opcode_info->mnemonic); + } + + if (0) { + LLVMBasicBlockRef block = LLVMGetInsertBlock(gallivm->builder); + LLVMValueRef function = LLVMGetBasicBlockParent(block); + debug_printf("11111111111111111111111111111 \n"); + tgsi_dump(tokens, 0); + lp_debug_dump_value(function); + debug_printf("2222222222222222222222222222 \n"); + } + tgsi_parse_free(&parse); + + if (0) { + LLVMModuleRef module = LLVMGetGlobalParent( + LLVMGetBasicBlockParent(LLVMGetInsertBlock(gallivm->builder))); + LLVMDumpModule(module); + } + + FREE(bld.instructions); +} + diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c new file mode 100644 index 0000000..ad51446 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c @@ -0,0 +1,479 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "util/u_memory.h" +#include "util/u_math.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "tgsi/tgsi_dump.h" +#include "lp_bld_debug.h" +#include "lp_bld_tgsi.h" + + +/** + * Analysis context. + * + * This is where we keep store the value of each channel of the IMM/TEMP/OUT + * register values, as we walk the shader. + */ +struct analysis_context +{ + struct lp_tgsi_info *info; + + unsigned num_imms; + float imm[32][4]; + + struct lp_tgsi_channel_info temp[32][4]; +}; + + +/** + * Describe the specified channel of the src register. + */ +static void +analyse_src(struct analysis_context *ctx, + struct lp_tgsi_channel_info *chan_info, + const struct tgsi_src_register *src, + unsigned chan) +{ + chan_info->file = TGSI_FILE_NULL; + if (!src->Indirect && !src->Absolute && !src->Negate) { + unsigned swizzle = tgsi_util_get_src_register_swizzle(src, chan); + if (src->File == TGSI_FILE_TEMPORARY) { + if (src->Index < Elements(ctx->temp)) { + *chan_info = ctx->temp[src->Index][swizzle]; + } + } else { + chan_info->file = src->File; + if (src->File == TGSI_FILE_IMMEDIATE) { + assert(src->Index < Elements(ctx->imm)); + if (src->Index < Elements(ctx->imm)) { + chan_info->u.value = ctx->imm[src->Index][swizzle]; + } + } else { + chan_info->u.index = src->Index; + chan_info->swizzle = swizzle; + } + } + } +} + + +/** + * Whether this register channel refers to a specific immediate value. + */ +static boolean +is_immediate(const struct lp_tgsi_channel_info *chan_info, float value) +{ + return chan_info->file == TGSI_FILE_IMMEDIATE && + chan_info->u.value == value; +} + + +static void +analyse_tex(struct analysis_context *ctx, + const struct tgsi_full_instruction *inst, + enum lp_build_tex_modifier modifier) +{ + struct lp_tgsi_info *info = ctx->info; + unsigned chan; + + if (info->num_texs < Elements(info->tex)) { + struct lp_tgsi_texture_info *tex_info = &info->tex[info->num_texs]; + bool indirect = FALSE; + unsigned readmask = 0; + + tex_info->target = inst->Texture.Texture; + switch (inst->Texture.Texture) { + case TGSI_TEXTURE_1D: + readmask = TGSI_WRITEMASK_X; + break; + case TGSI_TEXTURE_2D: + case TGSI_TEXTURE_RECT: + readmask = TGSI_WRITEMASK_XY; + break; + case TGSI_TEXTURE_SHADOW1D: + case TGSI_TEXTURE_SHADOW2D: + case TGSI_TEXTURE_SHADOWRECT: + case TGSI_TEXTURE_3D: + case TGSI_TEXTURE_CUBE: + readmask = TGSI_WRITEMASK_XYZ; + break; + default: + assert(0); + return; + } + + if (modifier == LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV) { + /* We don't track explicit derivatives, although we could */ + indirect = TRUE; + tex_info->unit = inst->Src[3].Register.Index; + } else { + if (modifier == LP_BLD_TEX_MODIFIER_PROJECTED || + modifier == LP_BLD_TEX_MODIFIER_LOD_BIAS || + modifier == LP_BLD_TEX_MODIFIER_EXPLICIT_LOD) { + readmask |= TGSI_WRITEMASK_W; + } + tex_info->unit = inst->Src[1].Register.Index; + } + + for (chan = 0; chan < 4; ++chan) { + struct lp_tgsi_channel_info *chan_info = &tex_info->coord[chan]; + if (readmask & (1 << chan)) { + analyse_src(ctx, chan_info, &inst->Src[0].Register, chan); + if (chan_info->file != TGSI_FILE_INPUT) { + indirect = TRUE; + } + } else { + memset(chan_info, 0, sizeof *chan_info); + } + } + + if (indirect) { + info->indirect_textures = TRUE; + } + + ++info->num_texs; + } else { + info->indirect_textures = TRUE; + } +} + + +/** + * Process an instruction, and update the register values accordingly. + */ +static void +analyse_instruction(struct analysis_context *ctx, + struct tgsi_full_instruction *inst) +{ + struct lp_tgsi_info *info = ctx->info; + struct lp_tgsi_channel_info (*regs)[4]; + unsigned max_regs; + unsigned i; + unsigned index; + unsigned chan; + + for (i = 0; i < inst->Instruction.NumDstRegs; ++i) { + const struct tgsi_dst_register *dst = &inst->Dst[i].Register; + + /* + * Get the lp_tgsi_channel_info array corresponding to the destination + * register file. + */ + + if (dst->File == TGSI_FILE_TEMPORARY) { + regs = ctx->temp; + max_regs = Elements(ctx->temp); + } else if (dst->File == TGSI_FILE_OUTPUT) { + regs = info->output; + max_regs = Elements(info->output); + } else if (dst->File == TGSI_FILE_ADDRESS || + dst->File == TGSI_FILE_PREDICATE) { + continue; + } else { + assert(0); + continue; + } + + /* + * Detect direct TEX instructions + */ + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_TEX: + analyse_tex(ctx, inst, LP_BLD_TEX_MODIFIER_NONE); + break; + case TGSI_OPCODE_TXD: + analyse_tex(ctx, inst, LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV); + break; + case TGSI_OPCODE_TXB: + analyse_tex(ctx, inst, LP_BLD_TEX_MODIFIER_LOD_BIAS); + break; + case TGSI_OPCODE_TXL: + analyse_tex(ctx, inst, LP_BLD_TEX_MODIFIER_EXPLICIT_LOD); + break; + case TGSI_OPCODE_TXP: + analyse_tex(ctx, inst, LP_BLD_TEX_MODIFIER_PROJECTED); + break; + default: + break; + } + + /* + * Keep track of assignments and writes + */ + + if (dst->Indirect) { + /* + * It could be any register index so clear all register indices. + */ + + for (chan = 0; chan < 4; ++chan) { + if (dst->WriteMask & (1 << chan)) { + for (index = 0; index < max_regs; ++index) { + regs[index][chan].file = TGSI_FILE_NULL; + } + } + } + } else if (dst->Index < max_regs) { + /* + * Update this destination register value. + */ + + struct lp_tgsi_channel_info res[4]; + + memset(res, 0, sizeof res); + + if (!inst->Instruction.Predicate && + !inst->Instruction.Saturate) { + for (chan = 0; chan < 4; ++chan) { + if (dst->WriteMask & (1 << chan)) { + if (inst->Instruction.Opcode == TGSI_OPCODE_MOV) { + analyse_src(ctx, &res[chan], + &inst->Src[0].Register, chan); + } else if (inst->Instruction.Opcode == TGSI_OPCODE_MUL) { + /* + * Propagate values across 1.0 and 0.0 multiplications. + */ + + struct lp_tgsi_channel_info src0; + struct lp_tgsi_channel_info src1; + + analyse_src(ctx, &src0, &inst->Src[0].Register, chan); + analyse_src(ctx, &src1, &inst->Src[1].Register, chan); + + if (is_immediate(&src0, 0.0f)) { + res[chan] = src0; + } else if (is_immediate(&src1, 0.0f)) { + res[chan] = src1; + } else if (is_immediate(&src0, 1.0f)) { + res[chan] = src1; + } else if (is_immediate(&src1, 1.0f)) { + res[chan] = src0; + } + } + } + } + } + + for (chan = 0; chan < 4; ++chan) { + if (dst->WriteMask & (1 << chan)) { + regs[dst->Index][chan] = res[chan]; + } + } + } + } + + /* + * Clear all temporaries information in presence of a control flow opcode. + */ + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_IF: + case TGSI_OPCODE_IFC: + case TGSI_OPCODE_ELSE: + case TGSI_OPCODE_ENDIF: + case TGSI_OPCODE_BGNLOOP: + case TGSI_OPCODE_BRK: + case TGSI_OPCODE_BREAKC: + case TGSI_OPCODE_CONT: + case TGSI_OPCODE_ENDLOOP: + case TGSI_OPCODE_CALLNZ: + case TGSI_OPCODE_CAL: + case TGSI_OPCODE_BGNSUB: + case TGSI_OPCODE_ENDSUB: + case TGSI_OPCODE_SWITCH: + case TGSI_OPCODE_CASE: + case TGSI_OPCODE_DEFAULT: + case TGSI_OPCODE_ENDSWITCH: + case TGSI_OPCODE_RET: + case TGSI_OPCODE_END: + /* XXX: Are there more cases? */ + memset(&ctx->temp, 0, sizeof ctx->temp); + memset(&info->output, 0, sizeof info->output); + default: + break; + } +} + + +static INLINE void +dump_info(const struct tgsi_token *tokens, + struct lp_tgsi_info *info) +{ + unsigned index; + unsigned chan; + + tgsi_dump(tokens, 0); + + for (index = 0; index < info->num_texs; ++index) { + const struct lp_tgsi_texture_info *tex_info = &info->tex[index]; + debug_printf("TEX[%u] =", index); + for (chan = 0; chan < 4; ++chan) { + const struct lp_tgsi_channel_info *chan_info = + &tex_info->coord[chan]; + if (chan_info->file != TGSI_FILE_NULL) { + debug_printf(" %s[%u].%c", + tgsi_file_names[chan_info->file], + chan_info->u.index, + "xyzw01"[chan_info->swizzle]); + } else { + debug_printf(" _"); + } + } + debug_printf(", SAMP[%u], %s\n", + tex_info->unit, + tgsi_texture_names[tex_info->target]); + } + + for (index = 0; index < PIPE_MAX_SHADER_OUTPUTS; ++index) { + for (chan = 0; chan < 4; ++chan) { + const struct lp_tgsi_channel_info *chan_info = + &info->output[index][chan]; + if (chan_info->file != TGSI_FILE_NULL) { + debug_printf("OUT[%u].%c = ", index, "xyzw"[chan]); + if (chan_info->file == TGSI_FILE_IMMEDIATE) { + debug_printf("%f", chan_info->u.value); + } else { + const char *file_name; + switch (chan_info->file) { + case TGSI_FILE_CONSTANT: + file_name = "CONST"; + break; + case TGSI_FILE_INPUT: + file_name = "IN"; + break; + default: + file_name = "???"; + break; + } + debug_printf("%s[%u].%c", + file_name, + chan_info->u.index, + "xyzw01"[chan_info->swizzle]); + } + debug_printf("\n"); + } + } + } +} + + +/** + * Detect any direct relationship between the output color + */ +void +lp_build_tgsi_info(const struct tgsi_token *tokens, + struct lp_tgsi_info *info) +{ + struct tgsi_parse_context parse; + struct analysis_context ctx; + unsigned index; + unsigned chan; + + memset(info, 0, sizeof *info); + + tgsi_scan_shader(tokens, &info->base); + + memset(&ctx, 0, sizeof ctx); + ctx.info = info; + + tgsi_parse_init(&parse, tokens); + + while (!tgsi_parse_end_of_tokens(&parse)) { + tgsi_parse_token(&parse); + + switch (parse.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_DECLARATION: + break; + + case TGSI_TOKEN_TYPE_INSTRUCTION: + { + struct tgsi_full_instruction *inst = + &parse.FullToken.FullInstruction; + + if (inst->Instruction.Opcode == TGSI_OPCODE_END || + inst->Instruction.Opcode == TGSI_OPCODE_BGNSUB) { + /* We reached the end of main function body. */ + goto finished; + } + + analyse_instruction(&ctx, inst); + } + break; + + case TGSI_TOKEN_TYPE_IMMEDIATE: + { + const unsigned size = + parse.FullToken.FullImmediate.Immediate.NrTokens - 1; + assert(size <= 4); + if (ctx.num_imms < Elements(ctx.imm)) { + for (chan = 0; chan < size; ++chan) { + ctx.imm[ctx.num_imms][chan] = + parse.FullToken.FullImmediate.u[chan].Float; + } + ++ctx.num_imms; + } + } + break; + + case TGSI_TOKEN_TYPE_PROPERTY: + break; + + default: + assert(0); + } + } +finished: + + tgsi_parse_free(&parse); + + + /* + * Link the output color values. + */ + + for (index = 0; index < PIPE_MAX_COLOR_BUFS; ++index) { + const struct lp_tgsi_channel_info null_output[4]; + info->cbuf[index] = null_output; + } + + for (index = 0; index < info->base.num_outputs; ++index) { + unsigned semantic_name = info->base.output_semantic_name[index]; + unsigned semantic_index = info->base.output_semantic_index[index]; + if (semantic_name == TGSI_SEMANTIC_COLOR && + semantic_index < PIPE_MAX_COLOR_BUFS) { + info->cbuf[semantic_index] = info->output[index]; + } + } + + if (gallivm_debug & GALLIVM_DEBUG_TGSI) { + dump_info(tokens, info); + } +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c new file mode 100644 index 0000000..1b5a8a5 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c @@ -0,0 +1,2514 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * TGSI to LLVM IR translation -- SoA. + * + * @author Jose Fonseca + * + * Based on tgsi_sse2.c code written by Michal Krol, Keith Whitwell, + * Brian Paul, and others. + */ + +#include "pipe/p_config.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_debug.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_info.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "tgsi/tgsi_scan.h" +#include "lp_bld_type.h" +#include "lp_bld_const.h" +#include "lp_bld_arit.h" +#include "lp_bld_bitarit.h" +#include "lp_bld_gather.h" +#include "lp_bld_init.h" +#include "lp_bld_logic.h" +#include "lp_bld_swizzle.h" +#include "lp_bld_flow.h" +#include "lp_bld_quad.h" +#include "lp_bld_tgsi.h" +#include "lp_bld_limits.h" +#include "lp_bld_debug.h" +#include "lp_bld_printf.h" + + +#define FOR_EACH_CHANNEL( CHAN )\ + for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++) + +#define IS_DST0_CHANNEL_ENABLED( INST, CHAN )\ + ((INST)->Dst[0].Register.WriteMask & (1 << (CHAN))) + +#define IF_IS_DST0_CHANNEL_ENABLED( INST, CHAN )\ + if (IS_DST0_CHANNEL_ENABLED( INST, CHAN )) + +#define FOR_EACH_DST0_ENABLED_CHANNEL( INST, CHAN )\ + FOR_EACH_CHANNEL( CHAN )\ + IF_IS_DST0_CHANNEL_ENABLED( INST, CHAN ) + +#define CHAN_X 0 +#define CHAN_Y 1 +#define CHAN_Z 2 +#define CHAN_W 3 +#define NUM_CHANNELS 4 + +#define LP_MAX_INSTRUCTIONS 256 + + +struct lp_exec_mask { + struct lp_build_context *bld; + + boolean has_mask; + + LLVMTypeRef int_vec_type; + + LLVMValueRef cond_stack[LP_MAX_TGSI_NESTING]; + int cond_stack_size; + LLVMValueRef cond_mask; + + LLVMBasicBlockRef loop_block; + LLVMValueRef cont_mask; + LLVMValueRef break_mask; + LLVMValueRef break_var; + struct { + LLVMBasicBlockRef loop_block; + LLVMValueRef cont_mask; + LLVMValueRef break_mask; + LLVMValueRef break_var; + } loop_stack[LP_MAX_TGSI_NESTING]; + int loop_stack_size; + + LLVMValueRef ret_mask; + struct { + int pc; + LLVMValueRef ret_mask; + } call_stack[LP_MAX_TGSI_NESTING]; + int call_stack_size; + + LLVMValueRef exec_mask; +}; + +struct lp_build_tgsi_soa_context +{ + struct lp_build_context base; + + /* Builder for vector integer masks and indices */ + struct lp_build_context uint_bld; + + /* Builder for scalar elements of shader's data type (float) */ + struct lp_build_context elem_bld; + + LLVMValueRef consts_ptr; + const LLVMValueRef *pos; + const LLVMValueRef (*inputs)[NUM_CHANNELS]; + LLVMValueRef (*outputs)[NUM_CHANNELS]; + + const struct lp_build_sampler_soa *sampler; + + LLVMValueRef immediates[LP_MAX_TGSI_IMMEDIATES][NUM_CHANNELS]; + LLVMValueRef temps[LP_MAX_TGSI_TEMPS][NUM_CHANNELS]; + LLVMValueRef addr[LP_MAX_TGSI_ADDRS][NUM_CHANNELS]; + LLVMValueRef preds[LP_MAX_TGSI_PREDS][NUM_CHANNELS]; + + /* We allocate/use this array of temps if (1 << TGSI_FILE_TEMPORARY) is + * set in the indirect_files field. + * The temps[] array above is unused then. + */ + LLVMValueRef temps_array; + + /* We allocate/use this array of output if (1 << TGSI_FILE_OUTPUT) is + * set in the indirect_files field. + * The outputs[] array above is unused then. + */ + LLVMValueRef outputs_array; + + /* We allocate/use this array of inputs if (1 << TGSI_FILE_INPUT) is + * set in the indirect_files field. + * The inputs[] array above is unused then. + */ + LLVMValueRef inputs_array; + + const struct tgsi_shader_info *info; + /** bitmask indicating which register files are accessed indirectly */ + unsigned indirect_files; + + struct lp_build_mask_context *mask; + struct lp_exec_mask exec_mask; + + struct tgsi_full_instruction *instructions; + uint max_instructions; +}; + +static void lp_exec_mask_init(struct lp_exec_mask *mask, struct lp_build_context *bld) +{ + mask->bld = bld; + mask->has_mask = FALSE; + mask->cond_stack_size = 0; + mask->loop_stack_size = 0; + mask->call_stack_size = 0; + + mask->int_vec_type = lp_build_int_vec_type(bld->gallivm, mask->bld->type); + mask->exec_mask = mask->ret_mask = mask->break_mask = mask->cont_mask = mask->cond_mask = + LLVMConstAllOnes(mask->int_vec_type); +} + +static void lp_exec_mask_update(struct lp_exec_mask *mask) +{ + LLVMBuilderRef builder = mask->bld->gallivm->builder; + + if (mask->loop_stack_size) { + /*for loops we need to update the entire mask at runtime */ + LLVMValueRef tmp; + assert(mask->break_mask); + tmp = LLVMBuildAnd(builder, + mask->cont_mask, + mask->break_mask, + "maskcb"); + mask->exec_mask = LLVMBuildAnd(builder, + mask->cond_mask, + tmp, + "maskfull"); + } else + mask->exec_mask = mask->cond_mask; + + if (mask->call_stack_size) { + mask->exec_mask = LLVMBuildAnd(builder, + mask->exec_mask, + mask->ret_mask, + "callmask"); + } + + mask->has_mask = (mask->cond_stack_size > 0 || + mask->loop_stack_size > 0 || + mask->call_stack_size > 0); +} + +static void lp_exec_mask_cond_push(struct lp_exec_mask *mask, + LLVMValueRef val) +{ + LLVMBuilderRef builder = mask->bld->gallivm->builder; + + assert(mask->cond_stack_size < LP_MAX_TGSI_NESTING); + if (mask->cond_stack_size == 0) { + assert(mask->cond_mask == LLVMConstAllOnes(mask->int_vec_type)); + } + mask->cond_stack[mask->cond_stack_size++] = mask->cond_mask; + assert(LLVMTypeOf(val) == mask->int_vec_type); + mask->cond_mask = LLVMBuildAnd(builder, + mask->cond_mask, + val, + ""); + lp_exec_mask_update(mask); +} + +static void lp_exec_mask_cond_invert(struct lp_exec_mask *mask) +{ + LLVMBuilderRef builder = mask->bld->gallivm->builder; + LLVMValueRef prev_mask; + LLVMValueRef inv_mask; + + assert(mask->cond_stack_size); + prev_mask = mask->cond_stack[mask->cond_stack_size - 1]; + if (mask->cond_stack_size == 1) { + assert(prev_mask == LLVMConstAllOnes(mask->int_vec_type)); + } + + inv_mask = LLVMBuildNot(builder, mask->cond_mask, ""); + + mask->cond_mask = LLVMBuildAnd(builder, + inv_mask, + prev_mask, ""); + lp_exec_mask_update(mask); +} + +static void lp_exec_mask_cond_pop(struct lp_exec_mask *mask) +{ + assert(mask->cond_stack_size); + mask->cond_mask = mask->cond_stack[--mask->cond_stack_size]; + lp_exec_mask_update(mask); +} + +static void lp_exec_bgnloop(struct lp_exec_mask *mask) +{ + LLVMBuilderRef builder = mask->bld->gallivm->builder; + + if (mask->loop_stack_size == 0) { + assert(mask->loop_block == NULL); + assert(mask->cont_mask == LLVMConstAllOnes(mask->int_vec_type)); + assert(mask->break_mask == LLVMConstAllOnes(mask->int_vec_type)); + assert(mask->break_var == NULL); + } + + assert(mask->loop_stack_size < LP_MAX_TGSI_NESTING); + + mask->loop_stack[mask->loop_stack_size].loop_block = mask->loop_block; + mask->loop_stack[mask->loop_stack_size].cont_mask = mask->cont_mask; + mask->loop_stack[mask->loop_stack_size].break_mask = mask->break_mask; + mask->loop_stack[mask->loop_stack_size].break_var = mask->break_var; + ++mask->loop_stack_size; + + mask->break_var = lp_build_alloca(mask->bld->gallivm, mask->int_vec_type, ""); + LLVMBuildStore(builder, mask->break_mask, mask->break_var); + + mask->loop_block = lp_build_insert_new_block(mask->bld->gallivm, "bgnloop"); + LLVMBuildBr(builder, mask->loop_block); + LLVMPositionBuilderAtEnd(builder, mask->loop_block); + + mask->break_mask = LLVMBuildLoad(builder, mask->break_var, ""); + + lp_exec_mask_update(mask); +} + +static void lp_exec_break(struct lp_exec_mask *mask) +{ + LLVMBuilderRef builder = mask->bld->gallivm->builder; + LLVMValueRef exec_mask = LLVMBuildNot(builder, + mask->exec_mask, + "break"); + + mask->break_mask = LLVMBuildAnd(builder, + mask->break_mask, + exec_mask, "break_full"); + + lp_exec_mask_update(mask); +} + +static void lp_exec_continue(struct lp_exec_mask *mask) +{ + LLVMBuilderRef builder = mask->bld->gallivm->builder; + LLVMValueRef exec_mask = LLVMBuildNot(builder, + mask->exec_mask, + ""); + + mask->cont_mask = LLVMBuildAnd(builder, + mask->cont_mask, + exec_mask, ""); + + lp_exec_mask_update(mask); +} + + +static void lp_exec_endloop(struct gallivm_state *gallivm, + struct lp_exec_mask *mask) +{ + LLVMBuilderRef builder = mask->bld->gallivm->builder; + LLVMBasicBlockRef endloop; + LLVMTypeRef reg_type = LLVMIntTypeInContext(gallivm->context, + mask->bld->type.width * + mask->bld->type.length); + LLVMValueRef i1cond; + + assert(mask->break_mask); + + /* + * Restore the cont_mask, but don't pop + */ + assert(mask->loop_stack_size); + mask->cont_mask = mask->loop_stack[mask->loop_stack_size - 1].cont_mask; + lp_exec_mask_update(mask); + + /* + * Unlike the continue mask, the break_mask must be preserved across loop + * iterations + */ + LLVMBuildStore(builder, mask->break_mask, mask->break_var); + + /* i1cond = (mask == 0) */ + i1cond = LLVMBuildICmp( + builder, + LLVMIntNE, + LLVMBuildBitCast(builder, mask->exec_mask, reg_type, ""), + LLVMConstNull(reg_type), ""); + + endloop = lp_build_insert_new_block(mask->bld->gallivm, "endloop"); + + LLVMBuildCondBr(builder, + i1cond, mask->loop_block, endloop); + + LLVMPositionBuilderAtEnd(builder, endloop); + + assert(mask->loop_stack_size); + --mask->loop_stack_size; + mask->loop_block = mask->loop_stack[mask->loop_stack_size].loop_block; + mask->cont_mask = mask->loop_stack[mask->loop_stack_size].cont_mask; + mask->break_mask = mask->loop_stack[mask->loop_stack_size].break_mask; + mask->break_var = mask->loop_stack[mask->loop_stack_size].break_var; + + lp_exec_mask_update(mask); +} + +/* stores val into an address pointed to by dst. + * mask->exec_mask is used to figure out which bits of val + * should be stored into the address + * (0 means don't store this bit, 1 means do store). + */ +static void lp_exec_mask_store(struct lp_exec_mask *mask, + LLVMValueRef pred, + LLVMValueRef val, + LLVMValueRef dst) +{ + LLVMBuilderRef builder = mask->bld->gallivm->builder; + + /* Mix the predicate and execution mask */ + if (mask->has_mask) { + if (pred) { + pred = LLVMBuildAnd(builder, pred, mask->exec_mask, ""); + } else { + pred = mask->exec_mask; + } + } + + if (pred) { + LLVMValueRef real_val, dst_val; + + dst_val = LLVMBuildLoad(builder, dst, ""); + real_val = lp_build_select(mask->bld, + pred, + val, dst_val); + + LLVMBuildStore(builder, real_val, dst); + } else + LLVMBuildStore(builder, val, dst); +} + +static void lp_exec_mask_call(struct lp_exec_mask *mask, + int func, + int *pc) +{ + assert(mask->call_stack_size < LP_MAX_TGSI_NESTING); + mask->call_stack[mask->call_stack_size].pc = *pc; + mask->call_stack[mask->call_stack_size].ret_mask = mask->ret_mask; + mask->call_stack_size++; + *pc = func; +} + +static void lp_exec_mask_ret(struct lp_exec_mask *mask, int *pc) +{ + LLVMBuilderRef builder = mask->bld->gallivm->builder; + LLVMValueRef exec_mask; + + if (mask->call_stack_size == 0) { + /* returning from main() */ + *pc = -1; + return; + } + exec_mask = LLVMBuildNot(builder, + mask->exec_mask, + "ret"); + + mask->ret_mask = LLVMBuildAnd(builder, + mask->ret_mask, + exec_mask, "ret_full"); + + lp_exec_mask_update(mask); +} + +static void lp_exec_mask_bgnsub(struct lp_exec_mask *mask) +{ +} + +static void lp_exec_mask_endsub(struct lp_exec_mask *mask, int *pc) +{ + assert(mask->call_stack_size); + mask->call_stack_size--; + *pc = mask->call_stack[mask->call_stack_size].pc; + mask->ret_mask = mask->call_stack[mask->call_stack_size].ret_mask; + lp_exec_mask_update(mask); +} + + +/** + * Return pointer to a temporary register channel (src or dest). + * Note that indirect addressing cannot be handled here. + * \param index which temporary register + * \param chan which channel of the temp register. + */ +static LLVMValueRef +get_temp_ptr(struct lp_build_tgsi_soa_context *bld, + unsigned index, + unsigned chan) +{ + LLVMBuilderRef builder = bld->base.gallivm->builder; + assert(chan < 4); + if (bld->indirect_files & (1 << TGSI_FILE_TEMPORARY)) { + LLVMValueRef lindex = lp_build_const_int32(bld->base.gallivm, index * 4 + chan); + return LLVMBuildGEP(builder, bld->temps_array, &lindex, 1, ""); + } + else { + return bld->temps[index][chan]; + } +} + +/** + * Return pointer to a output register channel (src or dest). + * Note that indirect addressing cannot be handled here. + * \param index which output register + * \param chan which channel of the output register. + */ +static LLVMValueRef +get_output_ptr(struct lp_build_tgsi_soa_context *bld, + unsigned index, + unsigned chan) +{ + LLVMBuilderRef builder = bld->base.gallivm->builder; + assert(chan < 4); + if (bld->indirect_files & (1 << TGSI_FILE_OUTPUT)) { + LLVMValueRef lindex = lp_build_const_int32(bld->base.gallivm, + index * 4 + chan); + return LLVMBuildGEP(builder, bld->outputs_array, &lindex, 1, ""); + } + else { + return bld->outputs[index][chan]; + } +} + +/** + * Gather vector. + * XXX the lp_build_gather() function should be capable of doing this + * with a little work. + */ +static LLVMValueRef +build_gather(struct lp_build_tgsi_soa_context *bld, + LLVMValueRef base_ptr, + LLVMValueRef indexes) +{ + LLVMBuilderRef builder = bld->base.gallivm->builder; + LLVMValueRef res = bld->base.undef; + unsigned i; + + /* + * Loop over elements of index_vec, load scalar value, insert it into 'res'. + */ + for (i = 0; i < bld->base.type.length; i++) { + LLVMValueRef ii = lp_build_const_int32(bld->base.gallivm, i); + LLVMValueRef index = LLVMBuildExtractElement(builder, + indexes, ii, ""); + LLVMValueRef scalar_ptr = LLVMBuildGEP(builder, base_ptr, + &index, 1, "gather_ptr"); + LLVMValueRef scalar = LLVMBuildLoad(builder, scalar_ptr, ""); + + res = LLVMBuildInsertElement(builder, res, scalar, ii, ""); + } + + return res; +} + + +/** + * Scatter/store vector. + */ +static void +emit_mask_scatter(struct lp_build_tgsi_soa_context *bld, + LLVMValueRef base_ptr, + LLVMValueRef indexes, + LLVMValueRef values, + struct lp_exec_mask *mask, + LLVMValueRef pred) +{ + struct gallivm_state *gallivm = bld->base.gallivm; + LLVMBuilderRef builder = gallivm->builder; + unsigned i; + + /* Mix the predicate and execution mask */ + if (mask->has_mask) { + if (pred) { + pred = LLVMBuildAnd(builder, pred, mask->exec_mask, ""); + } + else { + pred = mask->exec_mask; + } + } + + /* + * Loop over elements of index_vec, store scalar value. + */ + for (i = 0; i < bld->base.type.length; i++) { + LLVMValueRef ii = lp_build_const_int32(gallivm, i); + LLVMValueRef index = LLVMBuildExtractElement(builder, indexes, ii, ""); + LLVMValueRef scalar_ptr = LLVMBuildGEP(builder, base_ptr, &index, 1, "scatter_ptr"); + LLVMValueRef val = LLVMBuildExtractElement(builder, values, ii, "scatter_val"); + LLVMValueRef scalar_pred = pred ? + LLVMBuildExtractElement(builder, pred, ii, "scatter_pred") : NULL; + + if (0) + lp_build_printf(gallivm, "scatter %d: val %f at %d %p\n", + ii, val, index, scalar_ptr); + + if (scalar_pred) { + LLVMValueRef real_val, dst_val; + dst_val = LLVMBuildLoad(builder, scalar_ptr, ""); + real_val = lp_build_select(&bld->elem_bld, scalar_pred, val, dst_val); + LLVMBuildStore(builder, real_val, scalar_ptr); + } + else { + LLVMBuildStore(builder, val, scalar_ptr); + } + } +} + + +/** + * Read the current value of the ADDR register, convert the floats to + * ints, add the base index and return the vector of offsets. + * The offsets will be used to index into the constant buffer or + * temporary register file. + */ +static LLVMValueRef +get_indirect_index(struct lp_build_tgsi_soa_context *bld, + unsigned reg_file, unsigned reg_index, + const struct tgsi_src_register *indirect_reg) +{ + LLVMBuilderRef builder = bld->base.gallivm->builder; + struct lp_build_context *uint_bld = &bld->uint_bld; + /* always use X component of address register */ + unsigned swizzle = indirect_reg->SwizzleX; + LLVMValueRef base; + LLVMValueRef rel; + LLVMValueRef max_index; + LLVMValueRef index; + + assert(bld->indirect_files & (1 << reg_file)); + + base = lp_build_const_int_vec(bld->base.gallivm, uint_bld->type, reg_index); + + assert(swizzle < 4); + rel = LLVMBuildLoad(builder, + bld->addr[indirect_reg->Index][swizzle], + "load addr reg"); + + /* for indexing we want integers */ + rel = LLVMBuildFPToSI(builder, + rel, + uint_bld->vec_type, ""); + + index = lp_build_add(uint_bld, base, rel); + + max_index = lp_build_const_int_vec(bld->base.gallivm, + uint_bld->type, + bld->info->file_max[reg_file]); + + assert(!uint_bld->type.sign); + index = lp_build_min(uint_bld, index, max_index); + + return index; +} + + +/** + * Register fetch. + */ +static LLVMValueRef +emit_fetch( + struct lp_build_tgsi_soa_context *bld, + const struct tgsi_full_instruction *inst, + unsigned src_op, + const unsigned chan_index ) +{ + struct gallivm_state *gallivm = bld->base.gallivm; + LLVMBuilderRef builder = gallivm->builder; + struct lp_build_context *uint_bld = &bld->uint_bld; + const struct tgsi_full_src_register *reg = &inst->Src[src_op]; + const unsigned swizzle = + tgsi_util_get_full_src_register_swizzle(reg, chan_index); + LLVMValueRef res; + LLVMValueRef indirect_index = NULL; + + if (swizzle > 3) { + assert(0 && "invalid swizzle in emit_fetch()"); + return bld->base.undef; + } + + if (reg->Register.Indirect) { + indirect_index = get_indirect_index(bld, + reg->Register.File, + reg->Register.Index, + ®->Indirect); + } else { + assert(reg->Register.Index <= bld->info->file_max[reg->Register.File]); + } + + switch (reg->Register.File) { + case TGSI_FILE_CONSTANT: + if (reg->Register.Indirect) { + LLVMValueRef swizzle_vec = + lp_build_const_int_vec(bld->base.gallivm, uint_bld->type, swizzle); + LLVMValueRef index_vec; /* index into the const buffer */ + + /* index_vec = indirect_index * 4 + swizzle */ + index_vec = lp_build_shl_imm(uint_bld, indirect_index, 2); + index_vec = lp_build_add(uint_bld, index_vec, swizzle_vec); + + /* Gather values from the constant buffer */ + res = build_gather(bld, bld->consts_ptr, index_vec); + } + else { + LLVMValueRef index; /* index into the const buffer */ + LLVMValueRef scalar, scalar_ptr; + + index = lp_build_const_int32(gallivm, reg->Register.Index*4 + swizzle); + + scalar_ptr = LLVMBuildGEP(builder, bld->consts_ptr, + &index, 1, ""); + scalar = LLVMBuildLoad(builder, scalar_ptr, ""); + + res = lp_build_broadcast_scalar(&bld->base, scalar); + } + break; + + case TGSI_FILE_IMMEDIATE: + res = bld->immediates[reg->Register.Index][swizzle]; + assert(res); + break; + + case TGSI_FILE_INPUT: + if (reg->Register.Indirect) { + LLVMValueRef swizzle_vec = + lp_build_const_int_vec(gallivm, uint_bld->type, swizzle); + LLVMValueRef length_vec = + lp_build_const_int_vec(gallivm, uint_bld->type, bld->base.type.length); + LLVMValueRef index_vec; /* index into the const buffer */ + LLVMValueRef inputs_array; + LLVMTypeRef float4_ptr_type; + + /* index_vec = (indirect_index * 4 + swizzle) * length */ + index_vec = lp_build_shl_imm(uint_bld, indirect_index, 2); + index_vec = lp_build_add(uint_bld, index_vec, swizzle_vec); + index_vec = lp_build_mul(uint_bld, index_vec, length_vec); + + /* cast inputs_array pointer to float* */ + float4_ptr_type = LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0); + inputs_array = LLVMBuildBitCast(builder, bld->inputs_array, + float4_ptr_type, ""); + + /* Gather values from the temporary register array */ + res = build_gather(bld, inputs_array, index_vec); + } else { + if (bld->indirect_files & (1 << TGSI_FILE_INPUT)) { + LLVMValueRef lindex = lp_build_const_int32(gallivm, + reg->Register.Index * 4 + swizzle); + LLVMValueRef input_ptr = LLVMBuildGEP(builder, + bld->inputs_array, &lindex, 1, ""); + res = LLVMBuildLoad(builder, input_ptr, ""); + } + else { + res = bld->inputs[reg->Register.Index][swizzle]; + } + } + assert(res); + break; + + case TGSI_FILE_TEMPORARY: + if (reg->Register.Indirect) { + LLVMValueRef swizzle_vec = + lp_build_const_int_vec(bld->base.gallivm, uint_bld->type, swizzle); + LLVMValueRef length_vec = + lp_build_const_int_vec(bld->base.gallivm, uint_bld->type, + bld->base.type.length); + LLVMValueRef index_vec; /* index into the const buffer */ + LLVMValueRef temps_array; + LLVMTypeRef float4_ptr_type; + + /* index_vec = (indirect_index * 4 + swizzle) * length */ + index_vec = lp_build_shl_imm(uint_bld, indirect_index, 2); + index_vec = lp_build_add(uint_bld, index_vec, swizzle_vec); + index_vec = lp_build_mul(uint_bld, index_vec, length_vec); + + /* cast temps_array pointer to float* */ + float4_ptr_type = LLVMPointerType(LLVMFloatTypeInContext(bld->base.gallivm->context), 0); + temps_array = LLVMBuildBitCast(builder, bld->temps_array, + float4_ptr_type, ""); + + /* Gather values from the temporary register array */ + res = build_gather(bld, temps_array, index_vec); + } + else { + LLVMValueRef temp_ptr; + temp_ptr = get_temp_ptr(bld, reg->Register.Index, swizzle); + res = LLVMBuildLoad(builder, temp_ptr, ""); + if (!res) + return bld->base.undef; + } + break; + + default: + assert(0 && "invalid src register in emit_fetch()"); + return bld->base.undef; + } + + switch( tgsi_util_get_full_src_register_sign_mode( reg, chan_index ) ) { + case TGSI_UTIL_SIGN_CLEAR: + res = lp_build_abs( &bld->base, res ); + break; + + case TGSI_UTIL_SIGN_SET: + res = lp_build_abs( &bld->base, res ); + /* fall through */ + case TGSI_UTIL_SIGN_TOGGLE: + res = lp_build_negate( &bld->base, res ); + break; + + case TGSI_UTIL_SIGN_KEEP: + break; + } + + return res; +} + + +/** + * Register fetch with derivatives. + */ +static void +emit_fetch_deriv( + struct lp_build_tgsi_soa_context *bld, + const struct tgsi_full_instruction *inst, + unsigned index, + const unsigned chan_index, + LLVMValueRef *res, + LLVMValueRef *ddx, + LLVMValueRef *ddy) +{ + LLVMValueRef src; + + src = emit_fetch(bld, inst, index, chan_index); + + if(res) + *res = src; + + /* TODO: use interpolation coeffs for inputs */ + + if(ddx) + *ddx = lp_build_ddx(&bld->base, src); + + if(ddy) + *ddy = lp_build_ddy(&bld->base, src); +} + + +/** + * Predicate. + */ +static void +emit_fetch_predicate( + struct lp_build_tgsi_soa_context *bld, + const struct tgsi_full_instruction *inst, + LLVMValueRef *pred) +{ + LLVMBuilderRef builder = bld->base.gallivm->builder; + unsigned index; + unsigned char swizzles[4]; + LLVMValueRef unswizzled[4] = {NULL, NULL, NULL, NULL}; + LLVMValueRef value; + unsigned chan; + + if (!inst->Instruction.Predicate) { + FOR_EACH_CHANNEL( chan ) { + pred[chan] = NULL; + } + return; + } + + swizzles[0] = inst->Predicate.SwizzleX; + swizzles[1] = inst->Predicate.SwizzleY; + swizzles[2] = inst->Predicate.SwizzleZ; + swizzles[3] = inst->Predicate.SwizzleW; + + index = inst->Predicate.Index; + assert(index < LP_MAX_TGSI_PREDS); + + FOR_EACH_CHANNEL( chan ) { + unsigned swizzle = swizzles[chan]; + + /* + * Only fetch the predicate register channels that are actually listed + * in the swizzles + */ + if (!unswizzled[swizzle]) { + value = LLVMBuildLoad(builder, + bld->preds[index][swizzle], ""); + + /* + * Convert the value to an integer mask. + * + * TODO: Short-circuit this comparison -- a D3D setp_xx instructions + * is needlessly causing two comparisons due to storing the intermediate + * result as float vector instead of an integer mask vector. + */ + value = lp_build_compare(bld->base.gallivm, + bld->base.type, + PIPE_FUNC_NOTEQUAL, + value, + bld->base.zero); + if (inst->Predicate.Negate) { + value = LLVMBuildNot(builder, value, ""); + } + + unswizzled[swizzle] = value; + } else { + value = unswizzled[swizzle]; + } + + pred[chan] = value; + } +} + + +/** + * Register store. + */ +static void +emit_store( + struct lp_build_tgsi_soa_context *bld, + const struct tgsi_full_instruction *inst, + unsigned index, + unsigned chan_index, + LLVMValueRef pred, + LLVMValueRef value) +{ + struct gallivm_state *gallivm = bld->base.gallivm; + LLVMBuilderRef builder = gallivm->builder; + const struct tgsi_full_dst_register *reg = &inst->Dst[index]; + struct lp_build_context *uint_bld = &bld->uint_bld; + LLVMValueRef indirect_index = NULL; + + switch( inst->Instruction.Saturate ) { + case TGSI_SAT_NONE: + break; + + case TGSI_SAT_ZERO_ONE: + value = lp_build_max(&bld->base, value, bld->base.zero); + value = lp_build_min(&bld->base, value, bld->base.one); + break; + + case TGSI_SAT_MINUS_PLUS_ONE: + value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.gallivm, bld->base.type, -1.0)); + value = lp_build_min(&bld->base, value, bld->base.one); + break; + + default: + assert(0); + } + + if (reg->Register.Indirect) { + indirect_index = get_indirect_index(bld, + reg->Register.File, + reg->Register.Index, + ®->Indirect); + } else { + assert(reg->Register.Index <= bld->info->file_max[reg->Register.File]); + } + + switch( reg->Register.File ) { + case TGSI_FILE_OUTPUT: + if (reg->Register.Indirect) { + LLVMValueRef chan_vec = + lp_build_const_int_vec(gallivm, uint_bld->type, chan_index); + LLVMValueRef length_vec = + lp_build_const_int_vec(gallivm, uint_bld->type, bld->base.type.length); + LLVMValueRef index_vec; /* indexes into the temp registers */ + LLVMValueRef outputs_array; + LLVMValueRef pixel_offsets; + LLVMTypeRef float_ptr_type; + int i; + + /* build pixel offset vector: {0, 1, 2, 3, ...} */ + pixel_offsets = uint_bld->undef; + for (i = 0; i < bld->base.type.length; i++) { + LLVMValueRef ii = lp_build_const_int32(gallivm, i); + pixel_offsets = LLVMBuildInsertElement(builder, pixel_offsets, + ii, ii, ""); + } + + /* index_vec = (indirect_index * 4 + chan_index) * length + offsets */ + index_vec = lp_build_shl_imm(uint_bld, indirect_index, 2); + index_vec = lp_build_add(uint_bld, index_vec, chan_vec); + index_vec = lp_build_mul(uint_bld, index_vec, length_vec); + index_vec = lp_build_add(uint_bld, index_vec, pixel_offsets); + + float_ptr_type = + LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0); + outputs_array = LLVMBuildBitCast(builder, bld->outputs_array, + float_ptr_type, ""); + + /* Scatter store values into temp registers */ + emit_mask_scatter(bld, outputs_array, index_vec, value, + &bld->exec_mask, pred); + } + else { + LLVMValueRef out_ptr = get_output_ptr(bld, reg->Register.Index, + chan_index); + lp_exec_mask_store(&bld->exec_mask, pred, value, out_ptr); + } + break; + + case TGSI_FILE_TEMPORARY: + if (reg->Register.Indirect) { + LLVMValueRef chan_vec = + lp_build_const_int_vec(gallivm, uint_bld->type, chan_index); + LLVMValueRef length_vec = + lp_build_const_int_vec(gallivm, uint_bld->type, + bld->base.type.length); + LLVMValueRef index_vec; /* indexes into the temp registers */ + LLVMValueRef temps_array; + LLVMValueRef pixel_offsets; + LLVMTypeRef float_ptr_type; + int i; + + /* build pixel offset vector: {0, 1, 2, 3, ...} */ + pixel_offsets = uint_bld->undef; + for (i = 0; i < bld->base.type.length; i++) { + LLVMValueRef ii = lp_build_const_int32(gallivm, i); + pixel_offsets = LLVMBuildInsertElement(builder, pixel_offsets, + ii, ii, ""); + } + + /* index_vec = (indirect_index * 4 + chan_index) * length + offsets */ + index_vec = lp_build_shl_imm(uint_bld, indirect_index, 2); + index_vec = lp_build_add(uint_bld, index_vec, chan_vec); + index_vec = lp_build_mul(uint_bld, index_vec, length_vec); + index_vec = lp_build_add(uint_bld, index_vec, pixel_offsets); + + float_ptr_type = + LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0); + temps_array = LLVMBuildBitCast(builder, bld->temps_array, + float_ptr_type, ""); + + /* Scatter store values into temp registers */ + emit_mask_scatter(bld, temps_array, index_vec, value, + &bld->exec_mask, pred); + } + else { + LLVMValueRef temp_ptr = get_temp_ptr(bld, reg->Register.Index, + chan_index); + lp_exec_mask_store(&bld->exec_mask, pred, value, temp_ptr); + } + break; + + case TGSI_FILE_ADDRESS: + lp_exec_mask_store(&bld->exec_mask, pred, value, + bld->addr[reg->Register.Index][chan_index]); + break; + + case TGSI_FILE_PREDICATE: + lp_exec_mask_store(&bld->exec_mask, pred, value, + bld->preds[reg->Register.Index][chan_index]); + break; + + default: + assert( 0 ); + } +} + + +/** + * High-level instruction translators. + */ + +static void +emit_tex( struct lp_build_tgsi_soa_context *bld, + const struct tgsi_full_instruction *inst, + enum lp_build_tex_modifier modifier, + LLVMValueRef *texel) +{ + LLVMBuilderRef builder = bld->base.gallivm->builder; + unsigned unit; + LLVMValueRef lod_bias, explicit_lod; + LLVMValueRef oow = NULL; + LLVMValueRef coords[3]; + LLVMValueRef ddx[3]; + LLVMValueRef ddy[3]; + unsigned num_coords; + unsigned i; + + if (!bld->sampler) { + _debug_printf("warning: found texture instruction but no sampler generator supplied\n"); + for (i = 0; i < 4; i++) { + texel[i] = bld->base.undef; + } + return; + } + + switch (inst->Texture.Texture) { + case TGSI_TEXTURE_1D: + num_coords = 1; + break; + case TGSI_TEXTURE_2D: + case TGSI_TEXTURE_RECT: + num_coords = 2; + break; + case TGSI_TEXTURE_SHADOW1D: + case TGSI_TEXTURE_SHADOW2D: + case TGSI_TEXTURE_SHADOWRECT: + case TGSI_TEXTURE_3D: + case TGSI_TEXTURE_CUBE: + num_coords = 3; + break; + default: + assert(0); + return; + } + + if (modifier == LP_BLD_TEX_MODIFIER_LOD_BIAS) { + lod_bias = emit_fetch( bld, inst, 0, 3 ); + explicit_lod = NULL; + } + else if (modifier == LP_BLD_TEX_MODIFIER_EXPLICIT_LOD) { + lod_bias = NULL; + explicit_lod = emit_fetch( bld, inst, 0, 3 ); + } + else { + lod_bias = NULL; + explicit_lod = NULL; + } + + if (modifier == LP_BLD_TEX_MODIFIER_PROJECTED) { + oow = emit_fetch( bld, inst, 0, 3 ); + oow = lp_build_rcp(&bld->base, oow); + } + + for (i = 0; i < num_coords; i++) { + coords[i] = emit_fetch( bld, inst, 0, i ); + if (modifier == LP_BLD_TEX_MODIFIER_PROJECTED) + coords[i] = lp_build_mul(&bld->base, coords[i], oow); + } + for (i = num_coords; i < 3; i++) { + coords[i] = bld->base.undef; + } + + if (modifier == LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV) { + LLVMValueRef index0 = lp_build_const_int32(bld->base.gallivm, 0); + for (i = 0; i < num_coords; i++) { + LLVMValueRef src1 = emit_fetch( bld, inst, 1, i ); + LLVMValueRef src2 = emit_fetch( bld, inst, 2, i ); + ddx[i] = LLVMBuildExtractElement(builder, src1, index0, ""); + ddy[i] = LLVMBuildExtractElement(builder, src2, index0, ""); + } + unit = inst->Src[3].Register.Index; + } else { + for (i = 0; i < num_coords; i++) { + ddx[i] = lp_build_scalar_ddx( &bld->base, coords[i] ); + ddy[i] = lp_build_scalar_ddy( &bld->base, coords[i] ); + } + unit = inst->Src[1].Register.Index; + } + for (i = num_coords; i < 3; i++) { + ddx[i] = LLVMGetUndef(bld->base.elem_type); + ddy[i] = LLVMGetUndef(bld->base.elem_type); + } + + bld->sampler->emit_fetch_texel(bld->sampler, + bld->base.gallivm, + bld->base.type, + unit, num_coords, coords, + ddx, ddy, + lod_bias, explicit_lod, + texel); +} + +static boolean +near_end_of_shader(struct lp_build_tgsi_soa_context *bld, + int pc) +{ + int i; + + for (i = 0; i < 5; i++) { + unsigned opcode; + + if (pc + i >= bld->info->num_instructions) + return TRUE; + + opcode = bld->instructions[pc + i].Instruction.Opcode; + + if (opcode == TGSI_OPCODE_END) + return TRUE; + + if (opcode == TGSI_OPCODE_TEX || + opcode == TGSI_OPCODE_TXP || + opcode == TGSI_OPCODE_TXD || + opcode == TGSI_OPCODE_TXB || + opcode == TGSI_OPCODE_TXL || + opcode == TGSI_OPCODE_TXF || + opcode == TGSI_OPCODE_TXQ || + opcode == TGSI_OPCODE_CAL || + opcode == TGSI_OPCODE_CALLNZ || + opcode == TGSI_OPCODE_IF || + opcode == TGSI_OPCODE_IFC || + opcode == TGSI_OPCODE_BGNLOOP || + opcode == TGSI_OPCODE_SWITCH) + return FALSE; + } + + return TRUE; +} + + + +/** + * Kill fragment if any of the src register values are negative. + */ +static void +emit_kil( + struct lp_build_tgsi_soa_context *bld, + const struct tgsi_full_instruction *inst, + int pc) +{ + LLVMBuilderRef builder = bld->base.gallivm->builder; + const struct tgsi_full_src_register *reg = &inst->Src[0]; + LLVMValueRef terms[NUM_CHANNELS]; + LLVMValueRef mask; + unsigned chan_index; + + memset(&terms, 0, sizeof terms); + + FOR_EACH_CHANNEL( chan_index ) { + unsigned swizzle; + + /* Unswizzle channel */ + swizzle = tgsi_util_get_full_src_register_swizzle( reg, chan_index ); + + /* Check if the component has not been already tested. */ + assert(swizzle < NUM_CHANNELS); + if( !terms[swizzle] ) + /* TODO: change the comparison operator instead of setting the sign */ + terms[swizzle] = emit_fetch(bld, inst, 0, chan_index ); + } + + mask = NULL; + FOR_EACH_CHANNEL( chan_index ) { + if(terms[chan_index]) { + LLVMValueRef chan_mask; + + /* + * If term < 0 then mask = 0 else mask = ~0. + */ + chan_mask = lp_build_cmp(&bld->base, PIPE_FUNC_GEQUAL, terms[chan_index], bld->base.zero); + + if(mask) + mask = LLVMBuildAnd(builder, mask, chan_mask, ""); + else + mask = chan_mask; + } + } + + if(mask) { + lp_build_mask_update(bld->mask, mask); + + if (!near_end_of_shader(bld, pc)) + lp_build_mask_check(bld->mask); + } +} + + +/** + * Predicated fragment kill. + * XXX Actually, we do an unconditional kill (as in tgsi_exec.c). + * The only predication is the execution mask which will apply if + * we're inside a loop or conditional. + */ +static void +emit_kilp(struct lp_build_tgsi_soa_context *bld, + const struct tgsi_full_instruction *inst, + int pc) +{ + LLVMBuilderRef builder = bld->base.gallivm->builder; + LLVMValueRef mask; + + /* For those channels which are "alive", disable fragment shader + * execution. + */ + if (bld->exec_mask.has_mask) { + mask = LLVMBuildNot(builder, bld->exec_mask.exec_mask, "kilp"); + } + else { + LLVMValueRef zero = LLVMConstNull(bld->base.int_vec_type); + mask = zero; + } + + lp_build_mask_update(bld->mask, mask); + + if (!near_end_of_shader(bld, pc)) + lp_build_mask_check(bld->mask); +} + + +/** + * Emit code which will dump the value of all the temporary registers + * to stdout. + */ +static void +emit_dump_temps(struct lp_build_tgsi_soa_context *bld) +{ + struct gallivm_state *gallivm = bld->base.gallivm; + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef temp_ptr; + LLVMValueRef i0 = lp_build_const_int32(gallivm, 0); + LLVMValueRef i1 = lp_build_const_int32(gallivm, 1); + LLVMValueRef i2 = lp_build_const_int32(gallivm, 2); + LLVMValueRef i3 = lp_build_const_int32(gallivm, 3); + int index; + int n = bld->info->file_max[TGSI_FILE_TEMPORARY]; + + for (index = 0; index < n; index++) { + LLVMValueRef idx = lp_build_const_int32(gallivm, index); + LLVMValueRef v[4][4], res; + int chan; + + lp_build_printf(gallivm, "TEMP[%d]:\n", idx); + + for (chan = 0; chan < 4; chan++) { + temp_ptr = get_temp_ptr(bld, index, chan); + res = LLVMBuildLoad(builder, temp_ptr, ""); + v[chan][0] = LLVMBuildExtractElement(builder, res, i0, ""); + v[chan][1] = LLVMBuildExtractElement(builder, res, i1, ""); + v[chan][2] = LLVMBuildExtractElement(builder, res, i2, ""); + v[chan][3] = LLVMBuildExtractElement(builder, res, i3, ""); + } + + lp_build_printf(gallivm, " X: %f %f %f %f\n", + v[0][0], v[0][1], v[0][2], v[0][3]); + lp_build_printf(gallivm, " Y: %f %f %f %f\n", + v[1][0], v[1][1], v[1][2], v[1][3]); + lp_build_printf(gallivm, " Z: %f %f %f %f\n", + v[2][0], v[2][1], v[2][2], v[2][3]); + lp_build_printf(gallivm, " W: %f %f %f %f\n", + v[3][0], v[3][1], v[3][2], v[3][3]); + } +} + + + +static void +emit_declaration( + struct lp_build_tgsi_soa_context *bld, + const struct tgsi_full_declaration *decl) +{ + struct gallivm_state *gallivm = bld->base.gallivm; + LLVMTypeRef vec_type = bld->base.vec_type; + const unsigned first = decl->Range.First; + const unsigned last = decl->Range.Last; + unsigned idx, i; + + for (idx = first; idx <= last; ++idx) { + assert(last <= bld->info->file_max[decl->Declaration.File]); + switch (decl->Declaration.File) { + case TGSI_FILE_TEMPORARY: + assert(idx < LP_MAX_TGSI_TEMPS); + if (!(bld->indirect_files & (1 << TGSI_FILE_TEMPORARY))) { + for (i = 0; i < NUM_CHANNELS; i++) + bld->temps[idx][i] = lp_build_alloca(gallivm, vec_type, "temp"); + } + break; + + case TGSI_FILE_OUTPUT: + if (!(bld->indirect_files & (1 << TGSI_FILE_OUTPUT))) { + for (i = 0; i < NUM_CHANNELS; i++) + bld->outputs[idx][i] = lp_build_alloca(gallivm, + vec_type, "output"); + } + break; + + case TGSI_FILE_ADDRESS: + assert(idx < LP_MAX_TGSI_ADDRS); + for (i = 0; i < NUM_CHANNELS; i++) + bld->addr[idx][i] = lp_build_alloca(gallivm, vec_type, "addr"); + break; + + case TGSI_FILE_PREDICATE: + assert(idx < LP_MAX_TGSI_PREDS); + for (i = 0; i < NUM_CHANNELS; i++) + bld->preds[idx][i] = lp_build_alloca(gallivm, vec_type, + "predicate"); + break; + + default: + /* don't need to declare other vars */ + break; + } + } +} + + +/** + * Emit LLVM for one TGSI instruction. + * \param return TRUE for success, FALSE otherwise + */ +static boolean +emit_instruction( + struct lp_build_tgsi_soa_context *bld, + const struct tgsi_full_instruction *inst, + const struct tgsi_opcode_info *info, + int *pc) +{ + unsigned chan_index; + LLVMValueRef src0, src1, src2; + LLVMValueRef tmp0, tmp1, tmp2; + LLVMValueRef tmp3 = NULL; + LLVMValueRef tmp4 = NULL; + LLVMValueRef tmp5 = NULL; + LLVMValueRef tmp6 = NULL; + LLVMValueRef tmp7 = NULL; + LLVMValueRef res; + LLVMValueRef dst0[NUM_CHANNELS]; + + /* + * Stores and write masks are handled in a general fashion after the long + * instruction opcode switch statement. + * + * Although not stricitly necessary, we avoid generating instructions for + * channels which won't be stored, in cases where's that easy. For some + * complex instructions, like texture sampling, it is more convenient to + * assume a full writemask and then let LLVM optimization passes eliminate + * redundant code. + */ + + (*pc)++; + + assert(info->num_dst <= 1); + if (info->num_dst) { + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = bld->base.undef; + } + } + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_ARL: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + tmp0 = emit_fetch( bld, inst, 0, chan_index ); + tmp0 = lp_build_floor(&bld->base, tmp0); + dst0[chan_index] = tmp0; + } + break; + + case TGSI_OPCODE_MOV: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = emit_fetch( bld, inst, 0, chan_index ); + } + break; + + case TGSI_OPCODE_LIT: + if( IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) ) { + dst0[CHAN_X] = bld->base.one; + } + if( IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) ) { + src0 = emit_fetch( bld, inst, 0, CHAN_X ); + dst0[CHAN_Y] = lp_build_max( &bld->base, src0, bld->base.zero); + } + if( IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ) ) { + /* XMM[1] = SrcReg[0].yyyy */ + tmp1 = emit_fetch( bld, inst, 0, CHAN_Y ); + /* XMM[1] = max(XMM[1], 0) */ + tmp1 = lp_build_max( &bld->base, tmp1, bld->base.zero); + /* XMM[2] = SrcReg[0].wwww */ + tmp2 = emit_fetch( bld, inst, 0, CHAN_W ); + tmp1 = lp_build_pow( &bld->base, tmp1, tmp2); + tmp0 = emit_fetch( bld, inst, 0, CHAN_X ); + tmp2 = lp_build_cmp(&bld->base, PIPE_FUNC_GREATER, tmp0, bld->base.zero); + dst0[CHAN_Z] = lp_build_select(&bld->base, tmp2, tmp1, bld->base.zero); + } + if( IS_DST0_CHANNEL_ENABLED( inst, CHAN_W ) ) { + dst0[CHAN_W] = bld->base.one; + } + break; + + case TGSI_OPCODE_RCP: + /* TGSI_OPCODE_RECIP */ + src0 = emit_fetch( bld, inst, 0, CHAN_X ); + res = lp_build_rcp(&bld->base, src0); + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = res; + } + break; + + case TGSI_OPCODE_RSQ: + /* TGSI_OPCODE_RECIPSQRT */ + src0 = emit_fetch( bld, inst, 0, CHAN_X ); + src0 = lp_build_abs(&bld->base, src0); + res = lp_build_rsqrt(&bld->base, src0); + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = res; + } + break; + + case TGSI_OPCODE_EXP: + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) || + IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) || + IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z )) { + LLVMValueRef *p_exp2_int_part = NULL; + LLVMValueRef *p_frac_part = NULL; + LLVMValueRef *p_exp2 = NULL; + + src0 = emit_fetch( bld, inst, 0, CHAN_X ); + + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_X )) + p_exp2_int_part = &tmp0; + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y )) + p_frac_part = &tmp1; + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z )) + p_exp2 = &tmp2; + + lp_build_exp2_approx(&bld->base, src0, p_exp2_int_part, p_frac_part, p_exp2); + + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_X )) + dst0[CHAN_X] = tmp0; + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y )) + dst0[CHAN_Y] = tmp1; + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z )) + dst0[CHAN_Z] = tmp2; + } + /* dst.w = 1.0 */ + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_W )) { + dst0[CHAN_W] = bld->base.one; + } + break; + + case TGSI_OPCODE_LOG: + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) || + IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) || + IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z )) { + LLVMValueRef *p_floor_log2 = NULL; + LLVMValueRef *p_exp = NULL; + LLVMValueRef *p_log2 = NULL; + + src0 = emit_fetch( bld, inst, 0, CHAN_X ); + src0 = lp_build_abs( &bld->base, src0 ); + + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_X )) + p_floor_log2 = &tmp0; + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y )) + p_exp = &tmp1; + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z )) + p_log2 = &tmp2; + + lp_build_log2_approx(&bld->base, src0, p_exp, p_floor_log2, p_log2); + + /* dst.x = floor(lg2(abs(src.x))) */ + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_X )) + dst0[CHAN_X] = tmp0; + /* dst.y = abs(src)/ex2(floor(lg2(abs(src.x)))) */ + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y )) { + dst0[CHAN_Y] = lp_build_div( &bld->base, src0, tmp1); + } + /* dst.z = lg2(abs(src.x)) */ + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z )) + dst0[CHAN_Z] = tmp2; + } + /* dst.w = 1.0 */ + if (IS_DST0_CHANNEL_ENABLED( inst, CHAN_W )) { + dst0[CHAN_W] = bld->base.one; + } + break; + + case TGSI_OPCODE_MUL: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + src0 = emit_fetch( bld, inst, 0, chan_index ); + src1 = emit_fetch( bld, inst, 1, chan_index ); + dst0[chan_index] = lp_build_mul(&bld->base, src0, src1); + } + break; + + case TGSI_OPCODE_ADD: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + src0 = emit_fetch( bld, inst, 0, chan_index ); + src1 = emit_fetch( bld, inst, 1, chan_index ); + dst0[chan_index] = lp_build_add(&bld->base, src0, src1); + } + break; + + case TGSI_OPCODE_DP3: + /* TGSI_OPCODE_DOT3 */ + tmp0 = emit_fetch( bld, inst, 0, CHAN_X ); + tmp1 = emit_fetch( bld, inst, 1, CHAN_X ); + tmp0 = lp_build_mul( &bld->base, tmp0, tmp1); + tmp1 = emit_fetch( bld, inst, 0, CHAN_Y ); + tmp2 = emit_fetch( bld, inst, 1, CHAN_Y ); + tmp1 = lp_build_mul( &bld->base, tmp1, tmp2); + tmp0 = lp_build_add( &bld->base, tmp0, tmp1); + tmp1 = emit_fetch( bld, inst, 0, CHAN_Z ); + tmp2 = emit_fetch( bld, inst, 1, CHAN_Z ); + tmp1 = lp_build_mul( &bld->base, tmp1, tmp2); + tmp0 = lp_build_add( &bld->base, tmp0, tmp1); + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = tmp0; + } + break; + + case TGSI_OPCODE_DP4: + /* TGSI_OPCODE_DOT4 */ + tmp0 = emit_fetch( bld, inst, 0, CHAN_X ); + tmp1 = emit_fetch( bld, inst, 1, CHAN_X ); + tmp0 = lp_build_mul( &bld->base, tmp0, tmp1); + tmp1 = emit_fetch( bld, inst, 0, CHAN_Y ); + tmp2 = emit_fetch( bld, inst, 1, CHAN_Y ); + tmp1 = lp_build_mul( &bld->base, tmp1, tmp2); + tmp0 = lp_build_add( &bld->base, tmp0, tmp1); + tmp1 = emit_fetch( bld, inst, 0, CHAN_Z ); + tmp2 = emit_fetch( bld, inst, 1, CHAN_Z ); + tmp1 = lp_build_mul( &bld->base, tmp1, tmp2); + tmp0 = lp_build_add( &bld->base, tmp0, tmp1); + tmp1 = emit_fetch( bld, inst, 0, CHAN_W ); + tmp2 = emit_fetch( bld, inst, 1, CHAN_W ); + tmp1 = lp_build_mul( &bld->base, tmp1, tmp2); + tmp0 = lp_build_add( &bld->base, tmp0, tmp1); + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = tmp0; + } + break; + + case TGSI_OPCODE_DST: + IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) { + dst0[CHAN_X] = bld->base.one; + } + IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) { + tmp0 = emit_fetch( bld, inst, 0, CHAN_Y ); + tmp1 = emit_fetch( bld, inst, 1, CHAN_Y ); + dst0[CHAN_Y] = lp_build_mul( &bld->base, tmp0, tmp1); + } + IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ) { + dst0[CHAN_Z] = emit_fetch( bld, inst, 0, CHAN_Z ); + } + IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_W ) { + dst0[CHAN_W] = emit_fetch( bld, inst, 1, CHAN_W ); + } + break; + + case TGSI_OPCODE_MIN: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + src0 = emit_fetch( bld, inst, 0, chan_index ); + src1 = emit_fetch( bld, inst, 1, chan_index ); + dst0[chan_index] = lp_build_min( &bld->base, src0, src1 ); + } + break; + + case TGSI_OPCODE_MAX: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + src0 = emit_fetch( bld, inst, 0, chan_index ); + src1 = emit_fetch( bld, inst, 1, chan_index ); + dst0[chan_index] = lp_build_max( &bld->base, src0, src1 ); + } + break; + + case TGSI_OPCODE_SLT: + /* TGSI_OPCODE_SETLT */ + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + src0 = emit_fetch( bld, inst, 0, chan_index ); + src1 = emit_fetch( bld, inst, 1, chan_index ); + tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_LESS, src0, src1 ); + dst0[chan_index] = lp_build_select( &bld->base, tmp0, bld->base.one, bld->base.zero ); + } + break; + + case TGSI_OPCODE_SGE: + /* TGSI_OPCODE_SETGE */ + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + src0 = emit_fetch( bld, inst, 0, chan_index ); + src1 = emit_fetch( bld, inst, 1, chan_index ); + tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_GEQUAL, src0, src1 ); + dst0[chan_index] = lp_build_select( &bld->base, tmp0, bld->base.one, bld->base.zero ); + } + break; + + case TGSI_OPCODE_MAD: + /* TGSI_OPCODE_MADD */ + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + tmp0 = emit_fetch( bld, inst, 0, chan_index ); + tmp1 = emit_fetch( bld, inst, 1, chan_index ); + tmp2 = emit_fetch( bld, inst, 2, chan_index ); + tmp0 = lp_build_mul( &bld->base, tmp0, tmp1); + tmp0 = lp_build_add( &bld->base, tmp0, tmp2); + dst0[chan_index] = tmp0; + } + break; + + case TGSI_OPCODE_SUB: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + tmp0 = emit_fetch( bld, inst, 0, chan_index ); + tmp1 = emit_fetch( bld, inst, 1, chan_index ); + dst0[chan_index] = lp_build_sub( &bld->base, tmp0, tmp1); + } + break; + + case TGSI_OPCODE_LRP: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + src0 = emit_fetch( bld, inst, 0, chan_index ); + src1 = emit_fetch( bld, inst, 1, chan_index ); + src2 = emit_fetch( bld, inst, 2, chan_index ); + tmp0 = lp_build_sub( &bld->base, src1, src2 ); + tmp0 = lp_build_mul( &bld->base, src0, tmp0 ); + dst0[chan_index] = lp_build_add( &bld->base, tmp0, src2 ); + } + break; + + case TGSI_OPCODE_CND: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + src0 = emit_fetch( bld, inst, 0, chan_index ); + src1 = emit_fetch( bld, inst, 1, chan_index ); + src2 = emit_fetch( bld, inst, 2, chan_index ); + tmp1 = lp_build_const_vec(bld->base.gallivm, bld->base.type, 0.5); + tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_GREATER, src2, tmp1); + dst0[chan_index] = lp_build_select( &bld->base, tmp0, src0, src1 ); + } + break; + + case TGSI_OPCODE_DP2A: + tmp0 = emit_fetch( bld, inst, 0, CHAN_X ); /* xmm0 = src[0].x */ + tmp1 = emit_fetch( bld, inst, 1, CHAN_X ); /* xmm1 = src[1].x */ + tmp0 = lp_build_mul( &bld->base, tmp0, tmp1); /* xmm0 = xmm0 * xmm1 */ + tmp1 = emit_fetch( bld, inst, 0, CHAN_Y ); /* xmm1 = src[0].y */ + tmp2 = emit_fetch( bld, inst, 1, CHAN_Y ); /* xmm2 = src[1].y */ + tmp1 = lp_build_mul( &bld->base, tmp1, tmp2); /* xmm1 = xmm1 * xmm2 */ + tmp0 = lp_build_add( &bld->base, tmp0, tmp1); /* xmm0 = xmm0 + xmm1 */ + tmp1 = emit_fetch( bld, inst, 2, CHAN_X ); /* xmm1 = src[2].x */ + tmp0 = lp_build_add( &bld->base, tmp0, tmp1); /* xmm0 = xmm0 + xmm1 */ + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = tmp0; /* dest[ch] = xmm0 */ + } + break; + + case TGSI_OPCODE_FRC: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + src0 = emit_fetch( bld, inst, 0, chan_index ); + tmp0 = lp_build_floor(&bld->base, src0); + tmp0 = lp_build_sub(&bld->base, src0, tmp0); + dst0[chan_index] = tmp0; + } + break; + + case TGSI_OPCODE_CLAMP: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + tmp0 = emit_fetch( bld, inst, 0, chan_index ); + src1 = emit_fetch( bld, inst, 1, chan_index ); + src2 = emit_fetch( bld, inst, 2, chan_index ); + tmp0 = lp_build_max(&bld->base, tmp0, src1); + tmp0 = lp_build_min(&bld->base, tmp0, src2); + dst0[chan_index] = tmp0; + } + break; + + case TGSI_OPCODE_FLR: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + tmp0 = emit_fetch( bld, inst, 0, chan_index ); + dst0[chan_index] = lp_build_floor(&bld->base, tmp0); + } + break; + + case TGSI_OPCODE_ROUND: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + tmp0 = emit_fetch( bld, inst, 0, chan_index ); + dst0[chan_index] = lp_build_round(&bld->base, tmp0); + } + break; + + case TGSI_OPCODE_EX2: { + tmp0 = emit_fetch( bld, inst, 0, CHAN_X ); + tmp0 = lp_build_exp2( &bld->base, tmp0); + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = tmp0; + } + break; + } + + case TGSI_OPCODE_LG2: + tmp0 = emit_fetch( bld, inst, 0, CHAN_X ); + tmp0 = lp_build_log2( &bld->base, tmp0); + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = tmp0; + } + break; + + case TGSI_OPCODE_POW: + src0 = emit_fetch( bld, inst, 0, CHAN_X ); + src1 = emit_fetch( bld, inst, 1, CHAN_X ); + res = lp_build_pow( &bld->base, src0, src1 ); + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = res; + } + break; + + case TGSI_OPCODE_XPD: + if( IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) || + IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) ) { + tmp1 = emit_fetch( bld, inst, 1, CHAN_Z ); + tmp3 = emit_fetch( bld, inst, 0, CHAN_Z ); + } + if( IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) || + IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ) ) { + tmp0 = emit_fetch( bld, inst, 0, CHAN_Y ); + tmp4 = emit_fetch( bld, inst, 1, CHAN_Y ); + } + IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) { + tmp2 = tmp0; + tmp2 = lp_build_mul( &bld->base, tmp2, tmp1); + tmp5 = tmp3; + tmp5 = lp_build_mul( &bld->base, tmp5, tmp4); + tmp2 = lp_build_sub( &bld->base, tmp2, tmp5); + dst0[CHAN_X] = tmp2; + } + if( IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) || + IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ) ) { + tmp2 = emit_fetch( bld, inst, 1, CHAN_X ); + tmp5 = emit_fetch( bld, inst, 0, CHAN_X ); + } + IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) { + tmp3 = lp_build_mul( &bld->base, tmp3, tmp2); + tmp1 = lp_build_mul( &bld->base, tmp1, tmp5); + tmp3 = lp_build_sub( &bld->base, tmp3, tmp1); + dst0[CHAN_Y] = tmp3; + } + IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ) { + tmp5 = lp_build_mul( &bld->base, tmp5, tmp4); + tmp0 = lp_build_mul( &bld->base, tmp0, tmp2); + tmp5 = lp_build_sub( &bld->base, tmp5, tmp0); + dst0[CHAN_Z] = tmp5; + } + IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_W ) { + dst0[CHAN_W] = bld->base.one; + } + break; + + case TGSI_OPCODE_ABS: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + tmp0 = emit_fetch( bld, inst, 0, chan_index ); + dst0[chan_index] = lp_build_abs( &bld->base, tmp0 ); + } + break; + + case TGSI_OPCODE_RCC: + /* deprecated? */ + assert(0); + return FALSE; + + case TGSI_OPCODE_DPH: + tmp0 = emit_fetch( bld, inst, 0, CHAN_X ); + tmp1 = emit_fetch( bld, inst, 1, CHAN_X ); + tmp0 = lp_build_mul( &bld->base, tmp0, tmp1); + tmp1 = emit_fetch( bld, inst, 0, CHAN_Y ); + tmp2 = emit_fetch( bld, inst, 1, CHAN_Y ); + tmp1 = lp_build_mul( &bld->base, tmp1, tmp2); + tmp0 = lp_build_add( &bld->base, tmp0, tmp1); + tmp1 = emit_fetch( bld, inst, 0, CHAN_Z ); + tmp2 = emit_fetch( bld, inst, 1, CHAN_Z ); + tmp1 = lp_build_mul( &bld->base, tmp1, tmp2); + tmp0 = lp_build_add( &bld->base, tmp0, tmp1); + tmp1 = emit_fetch( bld, inst, 1, CHAN_W ); + tmp0 = lp_build_add( &bld->base, tmp0, tmp1); + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = tmp0; + } + break; + + case TGSI_OPCODE_COS: + tmp0 = emit_fetch( bld, inst, 0, CHAN_X ); + tmp0 = lp_build_cos( &bld->base, tmp0 ); + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = tmp0; + } + break; + + case TGSI_OPCODE_DDX: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + emit_fetch_deriv( bld, inst, 0, chan_index, NULL, &dst0[chan_index], NULL); + } + break; + + case TGSI_OPCODE_DDY: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + emit_fetch_deriv( bld, inst, 0, chan_index, NULL, NULL, &dst0[chan_index]); + } + break; + + case TGSI_OPCODE_KILP: + /* predicated kill */ + emit_kilp( bld, inst, (*pc)-1 ); + break; + + case TGSI_OPCODE_KIL: + /* conditional kill */ + emit_kil( bld, inst, (*pc)-1 ); + break; + + case TGSI_OPCODE_PK2H: + return FALSE; + break; + + case TGSI_OPCODE_PK2US: + return FALSE; + break; + + case TGSI_OPCODE_PK4B: + return FALSE; + break; + + case TGSI_OPCODE_PK4UB: + return FALSE; + break; + + case TGSI_OPCODE_RFL: + return FALSE; + break; + + case TGSI_OPCODE_SEQ: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + src0 = emit_fetch( bld, inst, 0, chan_index ); + src1 = emit_fetch( bld, inst, 1, chan_index ); + tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_EQUAL, src0, src1 ); + dst0[chan_index] = lp_build_select( &bld->base, tmp0, bld->base.one, bld->base.zero ); + } + break; + + case TGSI_OPCODE_SFL: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = bld->base.zero; + } + break; + + case TGSI_OPCODE_SGT: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + src0 = emit_fetch( bld, inst, 0, chan_index ); + src1 = emit_fetch( bld, inst, 1, chan_index ); + tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_GREATER, src0, src1 ); + dst0[chan_index] = lp_build_select( &bld->base, tmp0, bld->base.one, bld->base.zero ); + } + break; + + case TGSI_OPCODE_SIN: + tmp0 = emit_fetch( bld, inst, 0, CHAN_X ); + tmp0 = lp_build_sin( &bld->base, tmp0 ); + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = tmp0; + } + break; + + case TGSI_OPCODE_SLE: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + src0 = emit_fetch( bld, inst, 0, chan_index ); + src1 = emit_fetch( bld, inst, 1, chan_index ); + tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_LEQUAL, src0, src1 ); + dst0[chan_index] = lp_build_select( &bld->base, tmp0, bld->base.one, bld->base.zero ); + } + break; + + case TGSI_OPCODE_SNE: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + src0 = emit_fetch( bld, inst, 0, chan_index ); + src1 = emit_fetch( bld, inst, 1, chan_index ); + tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_NOTEQUAL, src0, src1 ); + dst0[chan_index] = lp_build_select( &bld->base, tmp0, bld->base.one, bld->base.zero ); + } + break; + + case TGSI_OPCODE_STR: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = bld->base.one; + } + break; + + case TGSI_OPCODE_TEX: + emit_tex( bld, inst, LP_BLD_TEX_MODIFIER_NONE, dst0 ); + break; + + case TGSI_OPCODE_TXD: + emit_tex( bld, inst, LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV, dst0 ); + break; + + case TGSI_OPCODE_UP2H: + /* deprecated */ + assert (0); + return FALSE; + break; + + case TGSI_OPCODE_UP2US: + /* deprecated */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_UP4B: + /* deprecated */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_UP4UB: + /* deprecated */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_X2D: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_ARA: + /* deprecated */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_ARR: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + tmp0 = emit_fetch( bld, inst, 0, chan_index ); + tmp0 = lp_build_round(&bld->base, tmp0); + dst0[chan_index] = tmp0; + } + break; + + case TGSI_OPCODE_BRA: + /* deprecated */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_CAL: + lp_exec_mask_call(&bld->exec_mask, + inst->Label.Label, + pc); + + break; + + case TGSI_OPCODE_RET: + lp_exec_mask_ret(&bld->exec_mask, pc); + break; + + case TGSI_OPCODE_END: + if (0) { + /* for debugging */ + emit_dump_temps(bld); + } + *pc = -1; + break; + + case TGSI_OPCODE_SSG: + /* TGSI_OPCODE_SGN */ + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + tmp0 = emit_fetch( bld, inst, 0, chan_index ); + dst0[chan_index] = lp_build_sgn( &bld->base, tmp0 ); + } + break; + + case TGSI_OPCODE_CMP: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + src0 = emit_fetch( bld, inst, 0, chan_index ); + src1 = emit_fetch( bld, inst, 1, chan_index ); + src2 = emit_fetch( bld, inst, 2, chan_index ); + tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_LESS, src0, bld->base.zero ); + dst0[chan_index] = lp_build_select( &bld->base, tmp0, src1, src2); + } + break; + + case TGSI_OPCODE_SCS: + IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_X ) { + tmp0 = emit_fetch( bld, inst, 0, CHAN_X ); + dst0[CHAN_X] = lp_build_cos( &bld->base, tmp0 ); + } + IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_Y ) { + tmp0 = emit_fetch( bld, inst, 0, CHAN_X ); + dst0[CHAN_Y] = lp_build_sin( &bld->base, tmp0 ); + } + IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_Z ) { + dst0[CHAN_Z] = bld->base.zero; + } + IF_IS_DST0_CHANNEL_ENABLED( inst, CHAN_W ) { + dst0[CHAN_W] = bld->base.one; + } + break; + + case TGSI_OPCODE_TXB: + emit_tex( bld, inst, LP_BLD_TEX_MODIFIER_LOD_BIAS, dst0 ); + break; + + case TGSI_OPCODE_NRM: + /* fall-through */ + case TGSI_OPCODE_NRM4: + /* 3 or 4-component normalization */ + { + uint dims = (inst->Instruction.Opcode == TGSI_OPCODE_NRM) ? 3 : 4; + + if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_X) || + IS_DST0_CHANNEL_ENABLED(inst, CHAN_Y) || + IS_DST0_CHANNEL_ENABLED(inst, CHAN_Z) || + (IS_DST0_CHANNEL_ENABLED(inst, CHAN_W) && dims == 4)) { + + /* NOTE: Cannot use xmm regs 2/3 here (see emit_rsqrt() above). */ + + /* xmm4 = src.x */ + /* xmm0 = src.x * src.x */ + tmp0 = emit_fetch(bld, inst, 0, CHAN_X); + if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_X)) { + tmp4 = tmp0; + } + tmp0 = lp_build_mul( &bld->base, tmp0, tmp0); + + /* xmm5 = src.y */ + /* xmm0 = xmm0 + src.y * src.y */ + tmp1 = emit_fetch(bld, inst, 0, CHAN_Y); + if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_Y)) { + tmp5 = tmp1; + } + tmp1 = lp_build_mul( &bld->base, tmp1, tmp1); + tmp0 = lp_build_add( &bld->base, tmp0, tmp1); + + /* xmm6 = src.z */ + /* xmm0 = xmm0 + src.z * src.z */ + tmp1 = emit_fetch(bld, inst, 0, CHAN_Z); + if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_Z)) { + tmp6 = tmp1; + } + tmp1 = lp_build_mul( &bld->base, tmp1, tmp1); + tmp0 = lp_build_add( &bld->base, tmp0, tmp1); + + if (dims == 4) { + /* xmm7 = src.w */ + /* xmm0 = xmm0 + src.w * src.w */ + tmp1 = emit_fetch(bld, inst, 0, CHAN_W); + if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_W)) { + tmp7 = tmp1; + } + tmp1 = lp_build_mul( &bld->base, tmp1, tmp1); + tmp0 = lp_build_add( &bld->base, tmp0, tmp1); + } + + /* xmm1 = 1 / sqrt(xmm0) */ + tmp1 = lp_build_rsqrt( &bld->base, tmp0); + + /* dst.x = xmm1 * src.x */ + if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_X)) { + dst0[CHAN_X] = lp_build_mul( &bld->base, tmp4, tmp1); + } + + /* dst.y = xmm1 * src.y */ + if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_Y)) { + dst0[CHAN_Y] = lp_build_mul( &bld->base, tmp5, tmp1); + } + + /* dst.z = xmm1 * src.z */ + if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_Z)) { + dst0[CHAN_Z] = lp_build_mul( &bld->base, tmp6, tmp1); + } + + /* dst.w = xmm1 * src.w */ + if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_X) && dims == 4) { + dst0[CHAN_W] = lp_build_mul( &bld->base, tmp7, tmp1); + } + } + + /* dst.w = 1.0 */ + if (IS_DST0_CHANNEL_ENABLED(inst, CHAN_W) && dims == 3) { + dst0[CHAN_W] = bld->base.one; + } + } + break; + + case TGSI_OPCODE_DIV: + /* deprecated */ + assert( 0 ); + return FALSE; + break; + + case TGSI_OPCODE_DP2: + tmp0 = emit_fetch( bld, inst, 0, CHAN_X ); /* xmm0 = src[0].x */ + tmp1 = emit_fetch( bld, inst, 1, CHAN_X ); /* xmm1 = src[1].x */ + tmp0 = lp_build_mul( &bld->base, tmp0, tmp1); /* xmm0 = xmm0 * xmm1 */ + tmp1 = emit_fetch( bld, inst, 0, CHAN_Y ); /* xmm1 = src[0].y */ + tmp2 = emit_fetch( bld, inst, 1, CHAN_Y ); /* xmm2 = src[1].y */ + tmp1 = lp_build_mul( &bld->base, tmp1, tmp2); /* xmm1 = xmm1 * xmm2 */ + tmp0 = lp_build_add( &bld->base, tmp0, tmp1); /* xmm0 = xmm0 + xmm1 */ + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + dst0[chan_index] = tmp0; /* dest[ch] = xmm0 */ + } + break; + + case TGSI_OPCODE_TXL: + emit_tex( bld, inst, LP_BLD_TEX_MODIFIER_EXPLICIT_LOD, dst0 ); + break; + + case TGSI_OPCODE_TXP: + emit_tex( bld, inst, LP_BLD_TEX_MODIFIER_PROJECTED, dst0 ); + break; + + case TGSI_OPCODE_BRK: + lp_exec_break(&bld->exec_mask); + break; + + case TGSI_OPCODE_IF: + tmp0 = emit_fetch(bld, inst, 0, CHAN_X); + tmp0 = lp_build_cmp(&bld->base, PIPE_FUNC_NOTEQUAL, + tmp0, bld->base.zero); + lp_exec_mask_cond_push(&bld->exec_mask, tmp0); + break; + + case TGSI_OPCODE_BGNLOOP: + lp_exec_bgnloop(&bld->exec_mask); + break; + + case TGSI_OPCODE_BGNSUB: + lp_exec_mask_bgnsub(&bld->exec_mask); + break; + + case TGSI_OPCODE_ELSE: + lp_exec_mask_cond_invert(&bld->exec_mask); + break; + + case TGSI_OPCODE_ENDIF: + lp_exec_mask_cond_pop(&bld->exec_mask); + break; + + case TGSI_OPCODE_ENDLOOP: + lp_exec_endloop(bld->base.gallivm, &bld->exec_mask); + break; + + case TGSI_OPCODE_ENDSUB: + lp_exec_mask_endsub(&bld->exec_mask, pc); + break; + + case TGSI_OPCODE_PUSHA: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_POPA: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_CEIL: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + tmp0 = emit_fetch( bld, inst, 0, chan_index ); + dst0[chan_index] = lp_build_ceil(&bld->base, tmp0); + } + break; + + case TGSI_OPCODE_I2F: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_NOT: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_TRUNC: + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + tmp0 = emit_fetch( bld, inst, 0, chan_index ); + dst0[chan_index] = lp_build_trunc(&bld->base, tmp0); + } + break; + + case TGSI_OPCODE_SHL: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_ISHR: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_AND: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_OR: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_MOD: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_XOR: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_SAD: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_TXF: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_TXQ: + /* deprecated? */ + assert(0); + return FALSE; + break; + + case TGSI_OPCODE_CONT: + lp_exec_continue(&bld->exec_mask); + break; + + case TGSI_OPCODE_EMIT: + return FALSE; + break; + + case TGSI_OPCODE_ENDPRIM: + return FALSE; + break; + + case TGSI_OPCODE_NOP: + break; + + default: + return FALSE; + } + + if(info->num_dst) { + LLVMValueRef pred[NUM_CHANNELS]; + + emit_fetch_predicate( bld, inst, pred ); + + FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { + emit_store( bld, inst, 0, chan_index, pred[chan_index], dst0[chan_index]); + } + } + + return TRUE; +} + + +void +lp_build_tgsi_soa(struct gallivm_state *gallivm, + const struct tgsi_token *tokens, + struct lp_type type, + struct lp_build_mask_context *mask, + LLVMValueRef consts_ptr, + const LLVMValueRef *pos, + const LLVMValueRef (*inputs)[NUM_CHANNELS], + LLVMValueRef (*outputs)[NUM_CHANNELS], + struct lp_build_sampler_soa *sampler, + const struct tgsi_shader_info *info) +{ + struct lp_build_tgsi_soa_context bld; + struct tgsi_parse_context parse; + uint num_immediates = 0; + uint num_instructions = 0; + unsigned i; + int pc = 0; + + struct lp_type res_type; + + assert(type.length <= LP_MAX_VECTOR_LENGTH); + memset(&res_type, 0, sizeof res_type); + res_type.width = type.width; + res_type.length = type.length; + res_type.sign = 1; + + /* Setup build context */ + memset(&bld, 0, sizeof bld); + lp_build_context_init(&bld.base, gallivm, type); + lp_build_context_init(&bld.uint_bld, gallivm, lp_uint_type(type)); + lp_build_context_init(&bld.elem_bld, gallivm, lp_elem_type(type)); + bld.mask = mask; + bld.pos = pos; + bld.inputs = inputs; + bld.outputs = outputs; + bld.consts_ptr = consts_ptr; + bld.sampler = sampler; + bld.info = info; + bld.indirect_files = info->indirect_files; + bld.instructions = (struct tgsi_full_instruction *) + MALLOC( LP_MAX_INSTRUCTIONS * sizeof(struct tgsi_full_instruction) ); + bld.max_instructions = LP_MAX_INSTRUCTIONS; + + if (!bld.instructions) { + return; + } + + lp_exec_mask_init(&bld.exec_mask, &bld.base); + + if (bld.indirect_files & (1 << TGSI_FILE_TEMPORARY)) { + LLVMValueRef array_size = + lp_build_const_int32(gallivm, + info->file_max[TGSI_FILE_TEMPORARY] * 4 + 4); + bld.temps_array = lp_build_array_alloca(gallivm, + bld.base.vec_type, array_size, + "temp_array"); + } + + if (bld.indirect_files & (1 << TGSI_FILE_OUTPUT)) { + LLVMValueRef array_size = + lp_build_const_int32(gallivm, + info->file_max[TGSI_FILE_OUTPUT] * 4 + 4); + bld.outputs_array = lp_build_array_alloca(gallivm, + bld.base.vec_type, array_size, + "output_array"); + } + + /* If we have indirect addressing in inputs we need to copy them into + * our alloca array to be able to iterate over them */ + if (bld.indirect_files & (1 << TGSI_FILE_INPUT)) { + unsigned index, chan; + LLVMTypeRef vec_type = bld.base.vec_type; + LLVMValueRef array_size = + lp_build_const_int32(gallivm, info->file_max[TGSI_FILE_INPUT]*4 + 4); + bld.inputs_array = lp_build_array_alloca(gallivm, + vec_type, array_size, + "input_array"); + + assert(info->num_inputs <= info->file_max[TGSI_FILE_INPUT] + 1); + + for (index = 0; index < info->num_inputs; ++index) { + for (chan = 0; chan < NUM_CHANNELS; ++chan) { + LLVMValueRef lindex = + lp_build_const_int32(gallivm, index * 4 + chan); + LLVMValueRef input_ptr = + LLVMBuildGEP(gallivm->builder, bld.inputs_array, + &lindex, 1, ""); + LLVMValueRef value = bld.inputs[index][chan]; + if (value) + LLVMBuildStore(gallivm->builder, value, input_ptr); + } + } + } + + tgsi_parse_init( &parse, tokens ); + + while( !tgsi_parse_end_of_tokens( &parse ) ) { + tgsi_parse_token( &parse ); + + switch( parse.FullToken.Token.Type ) { + case TGSI_TOKEN_TYPE_DECLARATION: + /* Inputs already interpolated */ + emit_declaration( &bld, &parse.FullToken.FullDeclaration ); + break; + + case TGSI_TOKEN_TYPE_INSTRUCTION: + { + /* save expanded instruction */ + if (num_instructions == bld.max_instructions) { + struct tgsi_full_instruction *instructions; + instructions = REALLOC(bld.instructions, + bld.max_instructions + * sizeof(struct tgsi_full_instruction), + (bld.max_instructions + LP_MAX_INSTRUCTIONS) + * sizeof(struct tgsi_full_instruction)); + if (!instructions) { + break; + } + bld.instructions = instructions; + bld.max_instructions += LP_MAX_INSTRUCTIONS; + } + + memcpy(bld.instructions + num_instructions, + &parse.FullToken.FullInstruction, + sizeof(bld.instructions[0])); + + num_instructions++; + } + + break; + + case TGSI_TOKEN_TYPE_IMMEDIATE: + /* simply copy the immediate values into the next immediates[] slot */ + { + const uint size = parse.FullToken.FullImmediate.Immediate.NrTokens - 1; + assert(size <= 4); + assert(num_immediates < LP_MAX_TGSI_IMMEDIATES); + for( i = 0; i < size; ++i ) + bld.immediates[num_immediates][i] = + lp_build_const_vec(gallivm, type, parse.FullToken.FullImmediate.u[i].Float); + for( i = size; i < 4; ++i ) + bld.immediates[num_immediates][i] = bld.base.undef; + num_immediates++; + } + break; + + case TGSI_TOKEN_TYPE_PROPERTY: + break; + + default: + assert( 0 ); + } + } + + while (pc != -1) { + struct tgsi_full_instruction *instr = bld.instructions + pc; + const struct tgsi_opcode_info *opcode_info = + tgsi_get_opcode_info(instr->Instruction.Opcode); + if (!emit_instruction( &bld, instr, opcode_info, &pc )) + _debug_printf("warning: failed to translate tgsi opcode %s to LLVM\n", + opcode_info->mnemonic); + } + + /* If we have indirect addressing in outputs we need to copy our alloca array + * to the outputs slots specified by the called */ + if (bld.indirect_files & (1 << TGSI_FILE_OUTPUT)) { + unsigned index, chan; + assert(info->num_outputs <= info->file_max[TGSI_FILE_OUTPUT] + 1); + for (index = 0; index < info->num_outputs; ++index) { + for (chan = 0; chan < NUM_CHANNELS; ++chan) { + bld.outputs[index][chan] = get_output_ptr(&bld, index, chan); + } + } + } + + if (0) { + LLVMBasicBlockRef block = LLVMGetInsertBlock(gallivm->builder); + LLVMValueRef function = LLVMGetBasicBlockParent(block); + debug_printf("11111111111111111111111111111 \n"); + tgsi_dump(tokens, 0); + lp_debug_dump_value(function); + debug_printf("2222222222222222222222222222 \n"); + } + tgsi_parse_free( &parse ); + + if (0) { + LLVMModuleRef module = LLVMGetGlobalParent( + LLVMGetBasicBlockParent(LLVMGetInsertBlock(gallivm->builder))); + LLVMDumpModule(module); + + } + + FREE( bld.instructions ); +} + diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.c b/src/gallium/auxiliary/gallivm/lp_bld_type.c new file mode 100644 index 0000000..c5cf6d4 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_type.c @@ -0,0 +1,411 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "util/u_debug.h" + +#include "lp_bld_type.h" +#include "lp_bld_const.h" +#include "lp_bld_init.h" + + +LLVMTypeRef +lp_build_elem_type(struct gallivm_state *gallivm, struct lp_type type) +{ + if (type.floating) { + switch(type.width) { + case 32: + return LLVMFloatTypeInContext(gallivm->context); + break; + case 64: + return LLVMDoubleTypeInContext(gallivm->context); + break; + default: + assert(0); + return LLVMFloatTypeInContext(gallivm->context); + } + } + else { + return LLVMIntTypeInContext(gallivm->context, type.width); + } +} + + +LLVMTypeRef +lp_build_vec_type(struct gallivm_state *gallivm,struct lp_type type) +{ + LLVMTypeRef elem_type = lp_build_elem_type(gallivm, type); + if (type.length == 1) + return elem_type; + else + return LLVMVectorType(elem_type, type.length); +} + + +/** + * This function is a mirror of lp_build_elem_type() above. + * + * XXX: I'm not sure if it wouldn't be easier/efficient to just recreate the + * type and check for identity. + */ +boolean +lp_check_elem_type(struct lp_type type, LLVMTypeRef elem_type) +{ + LLVMTypeKind elem_kind; + + assert(elem_type); + if(!elem_type) + return FALSE; + + elem_kind = LLVMGetTypeKind(elem_type); + + if (type.floating) { + switch(type.width) { + case 32: + if(elem_kind != LLVMFloatTypeKind) + return FALSE; + break; + case 64: + if(elem_kind != LLVMDoubleTypeKind) + return FALSE; + break; + default: + assert(0); + return FALSE; + } + } + else { + if(elem_kind != LLVMIntegerTypeKind) + return FALSE; + + if(LLVMGetIntTypeWidth(elem_type) != type.width) + return FALSE; + } + + return TRUE; +} + + +boolean +lp_check_vec_type(struct lp_type type, LLVMTypeRef vec_type) +{ + LLVMTypeRef elem_type; + + assert(vec_type); + if(!vec_type) + return FALSE; + + if (type.length == 1) + return lp_check_elem_type(type, vec_type); + + if(LLVMGetTypeKind(vec_type) != LLVMVectorTypeKind) + return FALSE; + + if(LLVMGetVectorSize(vec_type) != type.length) + return FALSE; + + elem_type = LLVMGetElementType(vec_type); + + return lp_check_elem_type(type, elem_type); +} + + +boolean +lp_check_value(struct lp_type type, LLVMValueRef val) +{ + LLVMTypeRef vec_type; + + assert(val); + if(!val) + return FALSE; + + vec_type = LLVMTypeOf(val); + + return lp_check_vec_type(type, vec_type); +} + + +LLVMTypeRef +lp_build_int_elem_type(struct gallivm_state *gallivm, struct lp_type type) +{ + return LLVMIntTypeInContext(gallivm->context, type.width); +} + + +LLVMTypeRef +lp_build_int_vec_type(struct gallivm_state *gallivm, struct lp_type type) +{ + LLVMTypeRef elem_type = lp_build_int_elem_type(gallivm, type); + if (type.length == 1) + return elem_type; + else + return LLVMVectorType(elem_type, type.length); +} + + +/** + * Build int32[4] vector type + */ +LLVMTypeRef +lp_build_int32_vec4_type(struct gallivm_state *gallivm) +{ + struct lp_type t; + LLVMTypeRef type; + + memset(&t, 0, sizeof(t)); + t.floating = FALSE; /* floating point values */ + t.sign = TRUE; /* values are signed */ + t.norm = FALSE; /* values are not limited to [0,1] or [-1,1] */ + t.width = 32; /* 32-bit int */ + t.length = 4; /* 4 elements per vector */ + + type = lp_build_int_elem_type(gallivm, t); + return LLVMVectorType(type, t.length); +} + + +/** + * Create element of vector type + */ +struct lp_type +lp_elem_type(struct lp_type type) +{ + struct lp_type res_type; + + assert(type.length > 1); + res_type = type; + res_type.length = 1; + + return res_type; +} + + +/** + * Create unsigned integer type variation of given type. + */ +struct lp_type +lp_uint_type(struct lp_type type) +{ + struct lp_type res_type; + + assert(type.length <= LP_MAX_VECTOR_LENGTH); + memset(&res_type, 0, sizeof res_type); + res_type.width = type.width; + res_type.length = type.length; + + return res_type; +} + + +/** + * Create signed integer type variation of given type. + */ +struct lp_type +lp_int_type(struct lp_type type) +{ + struct lp_type res_type; + + assert(type.length <= LP_MAX_VECTOR_LENGTH); + memset(&res_type, 0, sizeof res_type); + res_type.width = type.width; + res_type.length = type.length; + res_type.sign = 1; + + return res_type; +} + + +/** + * Return the type with twice the bit width (hence half the number of elements). + */ +struct lp_type +lp_wider_type(struct lp_type type) +{ + struct lp_type res_type; + + memcpy(&res_type, &type, sizeof res_type); + res_type.width *= 2; + res_type.length /= 2; + + assert(res_type.length); + + return res_type; +} + + +/** + * Return the size of the LLVMType in bits. + * XXX this function doesn't necessarily handle all LLVM types. + */ +unsigned +lp_sizeof_llvm_type(LLVMTypeRef t) +{ + LLVMTypeKind k = LLVMGetTypeKind(t); + + switch (k) { + case LLVMIntegerTypeKind: + return LLVMGetIntTypeWidth(t); + case LLVMFloatTypeKind: + return 8 * sizeof(float); + case LLVMDoubleTypeKind: + return 8 * sizeof(double); + case LLVMVectorTypeKind: + { + LLVMTypeRef elem = LLVMGetElementType(t); + unsigned len = LLVMGetVectorSize(t); + return len * lp_sizeof_llvm_type(elem); + } + break; + case LLVMArrayTypeKind: + { + LLVMTypeRef elem = LLVMGetElementType(t); + unsigned len = LLVMGetArrayLength(t); + return len * lp_sizeof_llvm_type(elem); + } + break; + default: + assert(0 && "Unexpected type in lp_get_llvm_type_size()"); + return 0; + } +} + + +/** + * Return string name for a LLVMTypeKind. Useful for debugging. + */ +const char * +lp_typekind_name(LLVMTypeKind t) +{ + switch (t) { + case LLVMVoidTypeKind: + return "LLVMVoidTypeKind"; + case LLVMFloatTypeKind: + return "LLVMFloatTypeKind"; + case LLVMDoubleTypeKind: + return "LLVMDoubleTypeKind"; + case LLVMX86_FP80TypeKind: + return "LLVMX86_FP80TypeKind"; + case LLVMFP128TypeKind: + return "LLVMFP128TypeKind"; + case LLVMPPC_FP128TypeKind: + return "LLVMPPC_FP128TypeKind"; + case LLVMLabelTypeKind: + return "LLVMLabelTypeKind"; + case LLVMIntegerTypeKind: + return "LLVMIntegerTypeKind"; + case LLVMFunctionTypeKind: + return "LLVMFunctionTypeKind"; + case LLVMStructTypeKind: + return "LLVMStructTypeKind"; + case LLVMArrayTypeKind: + return "LLVMArrayTypeKind"; + case LLVMPointerTypeKind: + return "LLVMPointerTypeKind"; + case LLVMOpaqueTypeKind: + return "LLVMOpaqueTypeKind"; + case LLVMVectorTypeKind: + return "LLVMVectorTypeKind"; + case LLVMMetadataTypeKind: + return "LLVMMetadataTypeKind"; + /* Only in LLVM 2.7 and later??? + case LLVMUnionTypeKind: + return "LLVMUnionTypeKind"; + */ + default: + return "unknown LLVMTypeKind"; + } +} + + +/** + * Print an LLVMTypeRef. Like LLVMDumpValue(). For debugging. + */ +void +lp_dump_llvmtype(LLVMTypeRef t) +{ + LLVMTypeKind k = LLVMGetTypeKind(t); + + if (k == LLVMVectorTypeKind) { + LLVMTypeRef te = LLVMGetElementType(t); + LLVMTypeKind ke = LLVMGetTypeKind(te); + unsigned len = LLVMGetVectorSize(t); + if (ke == LLVMIntegerTypeKind) { + unsigned b = LLVMGetIntTypeWidth(te); + debug_printf("Vector [%u] of %u-bit Integer\n", len, b); + } + else { + debug_printf("Vector [%u] of %s\n", len, lp_typekind_name(ke)); + } + } + else if (k == LLVMArrayTypeKind) { + LLVMTypeRef te = LLVMGetElementType(t); + LLVMTypeKind ke = LLVMGetTypeKind(te); + unsigned len = LLVMGetArrayLength(t); + debug_printf("Array [%u] of %s\n", len, lp_typekind_name(ke)); + } + else if (k == LLVMIntegerTypeKind) { + unsigned b = LLVMGetIntTypeWidth(t); + debug_printf("%u-bit Integer\n", b); + } + else if (k == LLVMPointerTypeKind) { + LLVMTypeRef te = LLVMGetElementType(t); + debug_printf("Pointer to "); + lp_dump_llvmtype(te); + } + else { + debug_printf("%s\n", lp_typekind_name(k)); + } +} + + +void +lp_build_context_init(struct lp_build_context *bld, + struct gallivm_state *gallivm, + struct lp_type type) +{ + bld->gallivm = gallivm; + bld->type = type; + + bld->int_elem_type = lp_build_int_elem_type(gallivm, type); + if (type.floating) + bld->elem_type = lp_build_elem_type(gallivm, type); + else + bld->elem_type = bld->int_elem_type; + + if (type.length == 1) { + bld->int_vec_type = bld->int_elem_type; + bld->vec_type = bld->elem_type; + } + else { + bld->int_vec_type = LLVMVectorType(bld->int_elem_type, type.length); + bld->vec_type = LLVMVectorType(bld->elem_type, type.length); + } + + bld->undef = LLVMGetUndef(bld->vec_type); + bld->zero = LLVMConstNull(bld->vec_type); + bld->one = lp_build_one(gallivm, type); +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.h b/src/gallium/auxiliary/gallivm/lp_bld_type.h new file mode 100644 index 0000000..5007e83 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_type.h @@ -0,0 +1,401 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Convenient representation of SIMD types. + * + * @author Jose Fonseca + */ + + +#ifndef LP_BLD_TYPE_H +#define LP_BLD_TYPE_H + + +#include "pipe/p_compiler.h" +#include "gallivm/lp_bld.h" + + + +/** + * Native SIMD register width. + * + * 128 for all architectures we care about. + */ +#define LP_NATIVE_VECTOR_WIDTH 128 + +/** + * Several functions can only cope with vectors of length up to this value. + * You may need to increase that value if you want to represent bigger vectors. + */ +#define LP_MAX_VECTOR_LENGTH 16 + + +/** + * The LLVM type system can't conveniently express all the things we care about + * on the types used for intermediate computations, such as signed vs unsigned, + * normalized values, or fixed point. + */ +struct lp_type { + /** + * Floating-point. Cannot be used with fixed. Integer numbers are + * represented by this zero. + */ + unsigned floating:1; + + /** + * Fixed-point. Cannot be used with floating. Integer numbers are + * represented by this zero. + */ + unsigned fixed:1; + + /** + * Whether it can represent negative values or not. + * + * If this is not set for floating point, it means that all values are + * assumed to be positive. + */ + unsigned sign:1; + + /** + * Whether values are normalized to fit [0, 1] interval, or [-1, 1] + * interval for signed types. + * + * For integer types it means the representable integer range should be + * interpreted as the interval above. + * + * For floating and fixed point formats it means the values should be + * clamped to the interval above. + */ + unsigned norm:1; + + /** + * Element width. + * + * For fixed point values, the fixed point is assumed to be at half the + * width. + */ + unsigned width:14; + + /** + * Vector length. If length==1, this is a scalar (float/int) type. + * + * width*length should be a power of two greater or equal to eight. + * + * @sa LP_MAX_VECTOR_LENGTH + */ + unsigned length:14; +}; + + +/** + * We need most of the information here in order to correctly and efficiently + * translate an arithmetic operation into LLVM IR. Putting it here avoids the + * trouble of passing it as parameters. + */ +struct lp_build_context +{ + struct gallivm_state *gallivm; + + /** + * This not only describes the input/output LLVM types, but also whether + * to normalize/clamp the results. + */ + struct lp_type type; + + /** Same as lp_build_elem_type(type) */ + LLVMTypeRef elem_type; + + /** Same as lp_build_vec_type(type) */ + LLVMTypeRef vec_type; + + /** Same as lp_build_int_elem_type(type) */ + LLVMTypeRef int_elem_type; + + /** Same as lp_build_int_vec_type(type) */ + LLVMTypeRef int_vec_type; + + /** Same as lp_build_undef(type) */ + LLVMValueRef undef; + + /** Same as lp_build_zero(type) */ + LLVMValueRef zero; + + /** Same as lp_build_one(type) */ + LLVMValueRef one; +}; + + +/** Create scalar float type */ +static INLINE struct lp_type +lp_type_float(unsigned width) +{ + struct lp_type res_type; + + memset(&res_type, 0, sizeof res_type); + res_type.floating = TRUE; + res_type.sign = TRUE; + res_type.width = width; + res_type.length = 1; + + return res_type; +} + + +/** Create vector of float type */ +static INLINE struct lp_type +lp_type_float_vec(unsigned width) +{ + struct lp_type res_type; + + memset(&res_type, 0, sizeof res_type); + res_type.floating = TRUE; + res_type.sign = TRUE; + res_type.width = width; + res_type.length = LP_NATIVE_VECTOR_WIDTH / width; + + return res_type; +} + + +/** Create scalar int type */ +static INLINE struct lp_type +lp_type_int(unsigned width) +{ + struct lp_type res_type; + + memset(&res_type, 0, sizeof res_type); + res_type.sign = TRUE; + res_type.width = width; + res_type.length = 1; + + return res_type; +} + + +/** Create vector int type */ +static INLINE struct lp_type +lp_type_int_vec(unsigned width) +{ + struct lp_type res_type; + + memset(&res_type, 0, sizeof res_type); + res_type.sign = TRUE; + res_type.width = width; + res_type.length = LP_NATIVE_VECTOR_WIDTH / width; + + return res_type; +} + + +/** Create scalar uint type */ +static INLINE struct lp_type +lp_type_uint(unsigned width) +{ + struct lp_type res_type; + + memset(&res_type, 0, sizeof res_type); + res_type.width = width; + res_type.length = 1; + + return res_type; +} + + +/** Create vector uint type */ +static INLINE struct lp_type +lp_type_uint_vec(unsigned width) +{ + struct lp_type res_type; + + memset(&res_type, 0, sizeof res_type); + res_type.width = width; + res_type.length = LP_NATIVE_VECTOR_WIDTH / width; + + return res_type; +} + + +static INLINE struct lp_type +lp_type_unorm(unsigned width) +{ + struct lp_type res_type; + + memset(&res_type, 0, sizeof res_type); + res_type.norm = TRUE; + res_type.width = width; + res_type.length = LP_NATIVE_VECTOR_WIDTH / width; + + return res_type; +} + + +static INLINE struct lp_type +lp_type_fixed(unsigned width) +{ + struct lp_type res_type; + + memset(&res_type, 0, sizeof res_type); + res_type.sign = TRUE; + res_type.fixed = TRUE; + res_type.width = width; + res_type.length = LP_NATIVE_VECTOR_WIDTH / width; + + return res_type; +} + + +static INLINE struct lp_type +lp_type_ufixed(unsigned width) +{ + struct lp_type res_type; + + memset(&res_type, 0, sizeof res_type); + res_type.fixed = TRUE; + res_type.width = width; + res_type.length = LP_NATIVE_VECTOR_WIDTH / width; + + return res_type; +} + + +LLVMTypeRef +lp_build_elem_type(struct gallivm_state *gallivm, struct lp_type type); + + +LLVMTypeRef +lp_build_vec_type(struct gallivm_state *gallivm, struct lp_type type); + + +boolean +lp_check_elem_type(struct lp_type type, LLVMTypeRef elem_type); + + +boolean +lp_check_vec_type(struct lp_type type, LLVMTypeRef vec_type); + + +boolean +lp_check_value(struct lp_type type, LLVMValueRef val); + + +LLVMTypeRef +lp_build_int_elem_type(struct gallivm_state *gallivm, struct lp_type type); + + +LLVMTypeRef +lp_build_int_vec_type(struct gallivm_state *gallivm, struct lp_type type); + + +LLVMTypeRef +lp_build_int32_vec4_type(struct gallivm_state *gallivm); + + +static INLINE struct lp_type +lp_float32_vec4_type(void) +{ + struct lp_type type; + + memset(&type, 0, sizeof(type)); + type.floating = TRUE; + type.sign = TRUE; + type.norm = FALSE; + type.width = 32; + type.length = 4; + + return type; +} + + +static INLINE struct lp_type +lp_int32_vec4_type(void) +{ + struct lp_type type; + + memset(&type, 0, sizeof(type)); + type.floating = FALSE; + type.sign = TRUE; + type.norm = FALSE; + type.width = 32; + type.length = 4; + + return type; +} + + +static INLINE struct lp_type +lp_unorm8_vec4_type(void) +{ + struct lp_type type; + + memset(&type, 0, sizeof(type)); + type.floating = FALSE; + type.sign = FALSE; + type.norm = TRUE; + type.width = 8; + type.length = 4; + + return type; +} + + +struct lp_type +lp_elem_type(struct lp_type type); + + +struct lp_type +lp_uint_type(struct lp_type type); + + +struct lp_type +lp_int_type(struct lp_type type); + + +struct lp_type +lp_wider_type(struct lp_type type); + + +unsigned +lp_sizeof_llvm_type(LLVMTypeRef t); + + +const char * +lp_typekind_name(LLVMTypeKind t); + + +void +lp_dump_llvmtype(LLVMTypeRef t); + + +void +lp_build_context_init(struct lp_build_context *bld, + struct gallivm_state *gallivm, + struct lp_type type); + + +#endif /* !LP_BLD_TYPE_H */ diff --git a/src/gallium/auxiliary/indices/u_indices.c b/src/gallium/auxiliary/indices/u_indices.c new file mode 100644 index 0000000..03d7453 --- /dev/null +++ b/src/gallium/auxiliary/indices/u_indices.c @@ -0,0 +1,253 @@ +/* + * 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 + * 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 + * VMWARE 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 "u_indices.h" +#include "u_indices_priv.h" + +static void translate_memcpy_ushort( const void *in, + unsigned nr, + void *out ) +{ + memcpy(out, in, nr*sizeof(short)); +} + +static void translate_memcpy_uint( const void *in, + unsigned nr, + void *out ) +{ + memcpy(out, in, nr*sizeof(int)); +} + + +int u_index_translator( unsigned hw_mask, + unsigned prim, + unsigned in_index_size, + unsigned nr, + unsigned in_pv, + unsigned out_pv, + unsigned *out_prim, + unsigned *out_index_size, + unsigned *out_nr, + u_translate_func *out_translate ) +{ + unsigned in_idx; + unsigned out_idx; + int ret = U_TRANSLATE_NORMAL; + + u_index_init(); + + in_idx = in_size_idx(in_index_size); + *out_index_size = (in_index_size == 4) ? 4 : 2; + out_idx = out_size_idx(*out_index_size); + + if ((hw_mask & (1< 0xfffe) ? 4 : 2; + out_idx = out_size_idx(*out_index_size); + + if ((hw_mask & (1< 0xfffe) ? 4 : 2; + out_idx = out_size_idx(*out_index_size); + + if (unfilled_mode == PIPE_POLYGON_MODE_POINT) { + + if (*out_index_size == 4) + *out_generate = generate_linear_uint; + else + *out_generate = generate_linear_ushort; + + *out_prim = PIPE_PRIM_POINTS; + *out_nr = nr; + return U_GENERATE_LINEAR; + } + else { + assert(unfilled_mode == PIPE_POLYGON_MODE_LINE); + *out_prim = PIPE_PRIM_LINES; + *out_generate = generate_line[out_idx][prim]; + *out_nr = nr_lines( prim, nr ); + + return U_GENERATE_REUSABLE; + } +} + diff --git a/src/gallium/auxiliary/os/os_memory.h b/src/gallium/auxiliary/os/os_memory.h new file mode 100644 index 0000000..556662d --- /dev/null +++ b/src/gallium/auxiliary/os/os_memory.h @@ -0,0 +1,84 @@ +/************************************************************************** + * + * Copyright 2010 Vmware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/* + * OS memory management abstractions + */ + + +#ifndef _OS_MEMORY_H_ +#define _OS_MEMORY_H_ + + +#include "pipe/p_config.h" +#include "pipe/p_compiler.h" + + +#if defined(PIPE_OS_EMBEDDED) + +#ifdef __cplusplus +extern "C" { +#endif + +void * +os_malloc(size_t size); + +void * +os_calloc(size_t count, size_t size); + +void +os_free(void *ptr); + +void * +os_realloc(void *ptr, size_t old_size, size_t new_size); + +void * +os_malloc_aligned(size_t size, size_t alignment); + +void +os_free_aligned(void *ptr); + +#ifdef __cplusplus +} +#endif + +#elif defined(PIPE_OS_WINDOWS) && defined(DEBUG) && !defined(DEBUG_MEMORY_IMPLEMENTATION) + +# include "os_memory_debug.h" + +#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) + +# include "os_memory_win32k.h" + +#else + +# include "os_memory_stdc.h" + +#endif + +#endif /* _OS_MEMORY_H_ */ diff --git a/src/gallium/auxiliary/os/os_memory_aligned.h b/src/gallium/auxiliary/os/os_memory_aligned.h new file mode 100644 index 0000000..72c5cf6 --- /dev/null +++ b/src/gallium/auxiliary/os/os_memory_aligned.h @@ -0,0 +1,72 @@ +/************************************************************************** + * + * Copyright 2008-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/* + * Memory alignment wrappers. + */ + + +#ifndef _OS_MEMORY_H_ +#error "Must not be included directly. Include os_memory.h instead" +#endif + + +#include "pipe/p_compiler.h" + + +/** + * Return memory on given byte alignment + */ +static INLINE void * +os_malloc_aligned(size_t size, size_t alignment) +{ + char *ptr, *buf; + + ptr = (char *) os_malloc(size + alignment + sizeof(void *)); + if (!ptr) + return NULL; + + buf = (char *)(((uintptr_t)ptr + sizeof(void *) + alignment - 1) & ~((uintptr_t)(alignment - 1))); + *(char **)(buf - sizeof(void *)) = ptr; + + return buf; +} + + +/** + * Free memory returned by align_malloc(). + */ +static INLINE void +os_free_aligned(void *ptr) +{ + if (ptr) { + void **cubbyHole = (void **) ((char *) ptr - sizeof(void *)); + void *realAddr = *cubbyHole; + os_free(realAddr); + } +} diff --git a/src/gallium/auxiliary/os/os_memory_debug.h b/src/gallium/auxiliary/os/os_memory_debug.h new file mode 100644 index 0000000..c664be9 --- /dev/null +++ b/src/gallium/auxiliary/os/os_memory_debug.h @@ -0,0 +1,83 @@ +/************************************************************************** + * + * Copyright 2008-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/* + * Debugging wrappers for OS memory management abstractions. + */ + + +#ifndef _OS_MEMORY_H_ +#error "Must not be included directly. Include os_memory.h instead" +#endif + + +#include "pipe/p_compiler.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +void * +debug_malloc(const char *file, unsigned line, const char *function, + size_t size); + +void * +debug_calloc(const char *file, unsigned line, const char *function, + size_t count, size_t size ); + +void +debug_free(const char *file, unsigned line, const char *function, + void *ptr); + +void * +debug_realloc(const char *file, unsigned line, const char *function, + void *old_ptr, size_t old_size, size_t new_size ); + + +#ifdef __cplusplus +} +#endif + + +#ifndef DEBUG_MEMORY_IMPLEMENTATION + +#define os_malloc( _size ) \ + debug_malloc( __FILE__, __LINE__, __FUNCTION__, _size ) +#define os_calloc( _count, _size ) \ + debug_calloc(__FILE__, __LINE__, __FUNCTION__, _count, _size ) +#define os_free( _ptr ) \ + debug_free( __FILE__, __LINE__, __FUNCTION__, _ptr ) +#define os_realloc( _ptr, _old_size, _new_size ) \ + debug_realloc( __FILE__, __LINE__, __FUNCTION__, _ptr, _old_size, _new_size ) + +/* TODO: wrap os_malloc_aligned() and os_free_aligned() too */ +#include "os_memory_aligned.h" + +#endif /* !DEBUG_MEMORY_IMPLEMENTATION */ diff --git a/src/gallium/auxiliary/os/os_memory_stdc.h b/src/gallium/auxiliary/os/os_memory_stdc.h new file mode 100644 index 0000000..806e536 --- /dev/null +++ b/src/gallium/auxiliary/os/os_memory_stdc.h @@ -0,0 +1,76 @@ +/************************************************************************** + * + * Copyright 2008-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/* + * OS memory management abstractions for the standard C library. + */ + + +#ifndef _OS_MEMORY_H_ +#error "Must not be included directly. Include os_memory.h instead" +#endif + +#include + +#include "pipe/p_compiler.h" + + +#define os_malloc(_size) malloc(_size) +#define os_calloc(_count, _size ) calloc(_count, _size ) +#define os_free(_ptr) free(_ptr) + +#define os_realloc( _old_ptr, _old_size, _new_size) \ + realloc(_old_ptr, _new_size + 0*(_old_size)) + + +#if defined(HAVE_POSIX_MEMALIGN) + +static INLINE void * +os_malloc_aligned(size_t size, size_t alignment) +{ + void *ptr; + alignment = (alignment + sizeof(void*) - 1) & ~(sizeof(void*) - 1); + if(posix_memalign(&ptr, alignment, size) != 0) + return NULL; + return ptr; +} + +#define os_free_aligned(_ptr) free(_ptr) + +#elif defined(PIPE_OS_WINDOWS) + +#include + +#define os_malloc_aligned(_size, _align) _aligned_malloc(_size, _align) +#define os_free_aligned(_ptr) _aligned_free(_ptr) + +#else + +#include "os_memory_aligned.h" + +#endif diff --git a/src/gallium/auxiliary/os/os_memory_win32k.h b/src/gallium/auxiliary/os/os_memory_win32k.h new file mode 100644 index 0000000..d56d690 --- /dev/null +++ b/src/gallium/auxiliary/os/os_memory_win32k.h @@ -0,0 +1,123 @@ +/************************************************************************** + * + * Copyright 2008-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/* + * OS memory management abstractions for Windows kernel. + */ + + +#ifndef _OS_MEMORY_H_ +#error "Must not be included directly. Include os_memory.h instead" +#endif + + +#include "pipe/p_compiler.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) + +void * __stdcall +EngAllocMem(unsigned long Flags, + unsigned long MemSize, + unsigned long Tag); + +void __stdcall +EngFreeMem(void *Mem); + +#define os_malloc(_size) EngAllocMem(0, _size, 'D3AG') +#define os_calloc(_count, _size) EngAllocMem(1, (_count)*(_size), 'D3AG') +#define _os_free(_ptr) EngFreeMem(_ptr) + +#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) + +void * +ExAllocatePool(unsigned long PoolType, + size_t NumberOfBytes); + +void +ExFreePool(void *P); + +#define os_malloc(_size) ExAllocatePool(0, _size) +#define _os_free(_ptr) ExFreePool(_ptr) + +static INLINE void * +os_calloc(unsigned count, unsigned size) +{ + void *ptr = os_malloc(count * size); + if (ptr) { + memset(ptr, 0, count * size); + } + return ptr; +} + +#else + +#error "Unsupported subsystem" + +#endif + + +static INLINE void +os_free( void *ptr ) +{ + if (ptr) { + _os_free(ptr); + } +} + + +static INLINE void * +os_realloc(void *old_ptr, unsigned old_size, unsigned new_size) +{ + void *new_ptr = NULL; + + if (new_size != 0) { + unsigned copy_size = old_size < new_size ? old_size : new_size; + new_ptr = os_malloc( new_size ); + if (new_ptr && old_ptr && copy_size) { + memcpy(new_ptr, old_ptr, copy_size); + } + } + + os_free(old_ptr); + + return new_ptr; +} + + +#ifdef __cplusplus +} +#endif + + +#include "os_memory_aligned.h" diff --git a/src/gallium/auxiliary/os/os_misc.c b/src/gallium/auxiliary/os/os_misc.c new file mode 100644 index 0000000..3849880 --- /dev/null +++ b/src/gallium/auxiliary/os/os_misc.c @@ -0,0 +1,188 @@ +/************************************************************************** + * + * Copyright 2008-2010 Vmware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "os_misc.h" + +#include + + +#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY + +#include +#include + +#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE) + +#include +#include +#include +#include + +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#endif +#include +#include + +#else + +#include +#include + +#endif + + +#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY +static INLINE void +_EngDebugPrint(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + EngDebugPrint("", (PCHAR)format, ap); + va_end(ap); +} +#endif + + +void +os_log_message(const char *message) +{ +#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) + _EngDebugPrint("%s", message); +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) + OutputDebugStringA(message); + if(GetConsoleWindow() && !IsDebuggerPresent()) { + fflush(stdout); + fputs(message, stderr); + fflush(stderr); + } +#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE) + wchar_t *wide_format; + long wide_str_len; + /* Format is ascii - needs to be converted to wchar_t for printing */ + wide_str_len = MultiByteToWideChar(CP_ACP, 0, message, -1, NULL, 0); + wide_format = (wchar_t *) malloc((wide_str_len+1) * sizeof(wchar_t)); + if (wide_format) { + MultiByteToWideChar(CP_ACP, 0, message, -1, + wide_format, wide_str_len); + NKDbgPrintfW(wide_format, wide_format); + free(wide_format); + } +#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) + /* TODO */ +#else /* !PIPE_SUBSYSTEM_WINDOWS */ + fflush(stdout); + fputs(message, stderr); +#endif +} + + +#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY +static const char * +find(const char *start, const char *end, char c) +{ + const char *p; + for(p = start; !end || p != end; ++p) { + if(*p == c) + return p; + if(*p < 32) + break; + } + return NULL; +} + +static int +compare(const char *start, const char *end, const char *s) +{ + const char *p, *q; + for(p = start, q = s; p != end && *q != '\0'; ++p, ++q) { + if(*p != *q) + return 0; + } + return p == end && *q == '\0'; +} + +static void +copy(char *dst, const char *start, const char *end, size_t n) +{ + const char *p; + char *q; + for(p = start, q = dst, n = n - 1; p != end && n; ++p, ++q, --n) + *q = *p; + *q = '\0'; +} +#endif + + +const char * +os_get_option(const char *name) +{ +#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) + /* EngMapFile creates the file if it does not exists, so it must either be + * disabled on release versions (or put in a less conspicuous place). */ +#ifdef DEBUG + const char *result = NULL; + ULONG_PTR iFile = 0; + const void *pMap = NULL; + const char *sol, *eol, *sep; + static char output[1024]; + + pMap = EngMapFile(L"\\??\\c:\\gallium.cfg", 0, &iFile); + if(pMap) { + sol = (const char *)pMap; + while(1) { + /* TODO: handle LF line endings */ + eol = find(sol, NULL, '\r'); + if(!eol || eol == sol) + break; + sep = find(sol, eol, '='); + if(!sep) + break; + if(compare(sol, sep, name)) { + copy(output, sep + 1, eol, sizeof(output)); + result = output; + break; + } + sol = eol + 2; + } + EngUnmapFile(iFile); + } + return result; +#else + return NULL; +#endif +#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) + /* TODO: implement */ + return NULL; +#else + return getenv(name); +#endif +} + diff --git a/src/gallium/auxiliary/os/os_misc.h b/src/gallium/auxiliary/os/os_misc.h new file mode 100644 index 0000000..d59f981 --- /dev/null +++ b/src/gallium/auxiliary/os/os_misc.h @@ -0,0 +1,99 @@ +/************************************************************************** + * + * Copyright 2010 Vmware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/* + * Miscellaneous OS services. + */ + + +#ifndef _OS_MISC_H_ +#define _OS_MISC_H_ + + +#include "pipe/p_compiler.h" + + +#if defined(PIPE_OS_UNIX) +# include /* for kill() */ +# include /* getpid() */ +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* + * Trap into the debugger. + */ +#if (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)) && defined(PIPE_CC_GCC) +# define os_break() __asm("int3") +#elif defined(PIPE_CC_MSVC) +# define os_break() __debugbreak() +#elif defined(PIPE_OS_UNIX) +# define os_break() kill(getpid(), SIGTRAP) +#elif defined(PIPE_OS_EMBEDDED) +void os_break(void); +#else +# define os_break() abort() +#endif + + +/* + * Abort the program. + */ +#if defined(DEBUG) || defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) +# define os_abort() os_break() +#elif defined(PIPE_OS_EMBEDDED) +void os_abort(void); +#else +# define os_abort() abort() +#endif + + +/* + * Output a message. Message should preferably end in a newline. + */ +void +os_log_message(const char *message); + + +/* + * Get an option. Should return NULL if specified option is not set. + */ +const char * +os_get_option(const char *name); + + +#ifdef __cplusplus +} +#endif + + +#endif /* _OS_MISC_H_ */ diff --git a/src/gallium/auxiliary/os/os_stream.c b/src/gallium/auxiliary/os/os_stream.c new file mode 100644 index 0000000..3c55fc0 --- /dev/null +++ b/src/gallium/auxiliary/os/os_stream.c @@ -0,0 +1,58 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "pipe/p_config.h" + +#include "os_stream.h" +#include "util/u_memory.h" +#include "util/u_string.h" + +int +os_default_stream_vprintf (struct os_stream* stream, const char *format, va_list ap) +{ + char buf[1024]; + int retval; + va_list ap2; + va_copy(ap2, ap); + retval = util_vsnprintf(buf, sizeof(buf), format, ap2); + va_end(ap2); + if(retval <= 0) + {} + else if(retval < sizeof(buf)) + stream->write(stream, buf, retval); + else + { + char* str = MALLOC(retval + 1); + if(!str) + return -1; + retval = util_vsnprintf(str, retval + 1, format, ap); + if(retval > 0) + stream->write(stream, str, retval); + FREE(str); + } + + return retval; +} diff --git a/src/gallium/auxiliary/os/os_stream.h b/src/gallium/auxiliary/os/os_stream.h new file mode 100644 index 0000000..6c6050b --- /dev/null +++ b/src/gallium/auxiliary/os/os_stream.h @@ -0,0 +1,145 @@ +/************************************************************************** + * + * Copyright 2008-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Cross-platform sequential access stream abstraction. + */ + +#ifndef _OS_STREAM_H_ +#define _OS_STREAM_H_ + + +#include "pipe/p_compiler.h" + + +/** + * OS stream (FILE, socket, etc) abstraction. + */ +struct os_stream +{ + void + (*close)(struct os_stream *stream); + + boolean + (*write)(struct os_stream *stream, const void *data, size_t size); + + void + (*flush)(struct os_stream *stream); + + int + (*vprintf)(struct os_stream *stream, const char* format, va_list ap); +}; + + +static INLINE void +os_stream_close(struct os_stream *stream) +{ + if (!stream) + return; + + stream->close(stream); +} + + +static INLINE boolean +os_stream_write(struct os_stream *stream, const void *data, size_t size) +{ + if (!stream) + return FALSE; + return stream->write(stream, data, size); +} + + +static INLINE boolean +os_stream_write_str(struct os_stream *stream, const char *str) +{ + size_t size; + if (!stream) + return FALSE; + for(size = 0; str[size]; ++size) + ; + return stream->write(stream, str, size); +} + + +static INLINE void +os_stream_flush(struct os_stream *stream) +{ + stream->flush(stream); +} + +int +os_default_stream_vprintf (struct os_stream* stream, const char *format, va_list ap); + +static INLINE int +os_stream_vprintf (struct os_stream* stream, const char *format, va_list ap) +{ + return stream->vprintf(stream, format, ap); +} + +static INLINE int +os_stream_printf (struct os_stream* stream, const char *format, ...) +{ + int retval; + va_list args; + + va_start (args, format); + retval = stream->vprintf(stream, format, args); + va_end (args); + + return retval; +} + +struct os_stream * +os_file_stream_create(const char *filename); + + +struct os_stream * +os_null_stream_create(void); + + +extern struct os_stream * +os_log_stream; + + +struct os_stream * +os_str_stream_create(size_t initial_size); + + +const char * +os_str_stream_get(struct os_stream *stream); + +char * +os_str_stream_get_and_close(struct os_stream *stream); + + +#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) +#define os_file_stream_create(_filename) os_null_stream_create() +#endif + +#endif /* _OS_STREAM_H_ */ diff --git a/src/gallium/auxiliary/os/os_stream_log.c b/src/gallium/auxiliary/os/os_stream_log.c new file mode 100644 index 0000000..b01377c --- /dev/null +++ b/src/gallium/auxiliary/os/os_stream_log.c @@ -0,0 +1,82 @@ +/************************************************************************** + * + * Copyright 2008-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Debug logging stream implementation. + */ + +#include "os_memory.h" +#include "os_misc.h" +#include "os_stream.h" + + +static void +os_log_stream_close(struct os_stream *stream) +{ + (void)stream; +} + + +static boolean +os_log_stream_write(struct os_stream *stream, const void *data, size_t size) +{ + char *str; + + str = os_malloc(size + 1); + if (!str) + return FALSE; + + memcpy(str, data, size); + str[size] = 0; + + os_log_message(str); + + os_free(str); + + return TRUE; +} + + +static void +os_log_stream_flush(struct os_stream *stream) +{ + (void)stream; +} + + +static struct os_stream +os_log_stream_struct = { + &os_log_stream_close, + &os_log_stream_write, + &os_log_stream_flush, + &os_default_stream_vprintf, +}; + + +struct os_stream * +os_log_stream = &os_log_stream_struct; diff --git a/src/gallium/auxiliary/os/os_stream_null.c b/src/gallium/auxiliary/os/os_stream_null.c new file mode 100644 index 0000000..a549a78 --- /dev/null +++ b/src/gallium/auxiliary/os/os_stream_null.c @@ -0,0 +1,78 @@ +/************************************************************************** + * + * Copyright 2008-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Null stream implementation. + */ + +#include "os_memory.h" +#include "os_stream.h" + + +static void +os_null_stream_close(struct os_stream *stream) +{ + (void)stream; +} + + +static boolean +os_null_stream_write(struct os_stream *stream, const void *data, size_t size) +{ + (void)data; + (void)size; + return TRUE; +} + + +static void +os_null_stream_flush(struct os_stream *stream) +{ + (void)stream; +} + +static int +os_null_stream_vprintf (struct os_stream* stream, const char *format, va_list ap) +{ + return 0; +} + +static struct os_stream +os_null_stream = { + &os_null_stream_close, + &os_null_stream_write, + &os_null_stream_flush, + &os_null_stream_vprintf +}; + + +struct os_stream * +os_null_stream_create() +{ + return &os_null_stream; +} diff --git a/src/gallium/auxiliary/os/os_stream_stdc.c b/src/gallium/auxiliary/os/os_stream_stdc.c new file mode 100644 index 0000000..afd3ff6 --- /dev/null +++ b/src/gallium/auxiliary/os/os_stream_stdc.c @@ -0,0 +1,122 @@ +/************************************************************************** + * + * Copyright 2008-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Stream implementation based on the Standard C Library. + */ + +#include "pipe/p_config.h" + +#if defined(PIPE_OS_UNIX) || defined(PIPE_SUBSYSTEM_WINDOWS_USER) + +#include +#include + +#include "os_stream.h" + + +struct os_stdc_stream +{ + struct os_stream base; + + FILE *file; +}; + + +static INLINE struct os_stdc_stream * +os_stdc_stream(struct os_stream *stream) +{ + return (struct os_stdc_stream *)stream; +} + + +static void +os_stdc_stream_close(struct os_stream *_stream) +{ + struct os_stdc_stream *stream = os_stdc_stream(_stream); + + fclose(stream->file); + + free(stream); +} + + +static boolean +os_stdc_stream_write(struct os_stream *_stream, const void *data, size_t size) +{ + struct os_stdc_stream *stream = os_stdc_stream(_stream); + + return fwrite(data, size, 1, stream->file) == size ? TRUE : FALSE; +} + + +static void +os_stdc_stream_flush(struct os_stream *_stream) +{ + struct os_stdc_stream *stream = os_stdc_stream(_stream); + + fflush(stream->file); +} + +static int +os_stdc_stream_vprintf (struct os_stream* _stream, const char *format, va_list ap) +{ + struct os_stdc_stream *stream = os_stdc_stream(_stream); + + return vfprintf(stream->file, format, ap); +} + + +struct os_stream * +os_file_stream_create(const char *filename) +{ + struct os_stdc_stream *stream; + + stream = (struct os_stdc_stream *)calloc(1, sizeof(*stream)); + if(!stream) + goto no_stream; + + stream->base.close = &os_stdc_stream_close; + stream->base.write = &os_stdc_stream_write; + stream->base.flush = &os_stdc_stream_flush; + stream->base.vprintf = &os_stdc_stream_vprintf; + + stream->file = fopen(filename, "wb"); + if(!stream->file) + goto no_file; + + return &stream->base; + +no_file: + free(stream); +no_stream: + return NULL; +} + + +#endif diff --git a/src/gallium/auxiliary/os/os_stream_str.c b/src/gallium/auxiliary/os/os_stream_str.c new file mode 100644 index 0000000..be9478b --- /dev/null +++ b/src/gallium/auxiliary/os/os_stream_str.c @@ -0,0 +1,167 @@ +/************************************************************************** + * + * Copyright 2008-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Malloc string stream implementation. + */ + +#include "pipe/p_config.h" + +#include "os_memory.h" +#include "os_stream.h" + + +struct os_str_stream +{ + struct os_stream base; + + char *str; + + size_t size; + size_t written; +}; + + +static INLINE struct os_str_stream * +os_str_stream(struct os_stream *stream) +{ + return (struct os_str_stream *)stream; +} + + +static void +os_str_stream_close(struct os_stream *_stream) +{ + struct os_str_stream *stream = os_str_stream(_stream); + + os_free(stream->str); + + os_free(stream); +} + + +static boolean +os_str_stream_write(struct os_stream *_stream, const void *data, size_t size) +{ + struct os_str_stream *stream = os_str_stream(_stream); + size_t minimum_size; + boolean ret = TRUE; + + minimum_size = stream->written + size + 1; + if (stream->size < minimum_size) { + size_t new_size = stream->size; + char * new_str; + + do { + new_size *= 2; + } while (new_size < minimum_size); + + new_str = os_realloc(stream->str, stream->size, new_size); + if (new_str) { + stream->str = new_str; + stream->size = new_size; + } + else { + size = stream->size - stream->written - 1; + ret = FALSE; + } + } + + memcpy(stream->str + stream->written, data, size); + stream->written += size; + + return ret; +} + + +static void +os_str_stream_flush(struct os_stream *stream) +{ + (void)stream; +} + + +struct os_stream * +os_str_stream_create(size_t size) +{ + struct os_str_stream *stream; + + stream = (struct os_str_stream *)os_calloc(1, sizeof(*stream)); + if(!stream) + goto no_stream; + + stream->base.close = &os_str_stream_close; + stream->base.write = &os_str_stream_write; + stream->base.flush = &os_str_stream_flush; + stream->base.vprintf = &os_default_stream_vprintf; + + stream->str = os_malloc(size); + if(!stream->str) + goto no_str; + + stream->size = size; + + return &stream->base; + +no_str: + os_free(stream); +no_stream: + return NULL; +} + + +const char * +os_str_stream_get(struct os_stream *_stream) +{ + struct os_str_stream *stream = os_str_stream(_stream); + + if (!stream) + return NULL; + + stream->str[stream->written] = 0; + return stream->str; +} + + +char * +os_str_stream_get_and_close(struct os_stream *_stream) +{ + struct os_str_stream *stream = os_str_stream(_stream); + char *str; + + if (!stream) + return NULL; + + str = stream->str; + + str[stream->written] = 0; + + os_free(stream); + + return str; +} diff --git a/src/gallium/auxiliary/os/os_thread.h b/src/gallium/auxiliary/os/os_thread.h new file mode 100644 index 0000000..a084310 --- /dev/null +++ b/src/gallium/auxiliary/os/os_thread.h @@ -0,0 +1,500 @@ +/************************************************************************** + * + * Copyright 1999-2006 Brian Paul + * 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, 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. + * + **************************************************************************/ + + +/** + * @file + * + * Thread, mutex, condition variable, barrier, semaphore and + * thread-specific data functions. + */ + + +#ifndef OS_THREAD_H_ +#define OS_THREAD_H_ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" /* for assert */ + + +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED) || defined(PIPE_OS_CYGWIN) + +#include /* POSIX threads headers */ +#include /* for perror() */ + + +/* pipe_thread + */ +typedef pthread_t pipe_thread; + +#define PIPE_THREAD_ROUTINE( name, param ) \ + void *name( void *param ) + +static INLINE pipe_thread pipe_thread_create( void *(* routine)( void *), void *param ) +{ + pipe_thread thread; + if (pthread_create( &thread, NULL, routine, param )) + return 0; + return thread; +} + +static INLINE int pipe_thread_wait( pipe_thread thread ) +{ + return pthread_join( thread, NULL ); +} + +static INLINE int pipe_thread_destroy( pipe_thread thread ) +{ + return pthread_detach( thread ); +} + + +/* pipe_mutex + */ +typedef pthread_mutex_t pipe_mutex; + +#define pipe_static_mutex(mutex) \ + static pipe_mutex mutex = PTHREAD_MUTEX_INITIALIZER + +#define pipe_mutex_init(mutex) \ + (void) pthread_mutex_init(&(mutex), NULL) + +#define pipe_mutex_destroy(mutex) \ + pthread_mutex_destroy(&(mutex)) + +#define pipe_mutex_lock(mutex) \ + (void) pthread_mutex_lock(&(mutex)) + +#define pipe_mutex_unlock(mutex) \ + (void) pthread_mutex_unlock(&(mutex)) + + +/* pipe_condvar + */ +typedef pthread_cond_t pipe_condvar; + +#define pipe_static_condvar(mutex) \ + static pipe_condvar mutex = PTHREAD_COND_INITIALIZER + +#define pipe_condvar_init(cond) \ + pthread_cond_init(&(cond), NULL) + +#define pipe_condvar_destroy(cond) \ + pthread_cond_destroy(&(cond)) + +#define pipe_condvar_wait(cond, mutex) \ + pthread_cond_wait(&(cond), &(mutex)) + +#define pipe_condvar_signal(cond) \ + pthread_cond_signal(&(cond)) + +#define pipe_condvar_broadcast(cond) \ + pthread_cond_broadcast(&(cond)) + + + +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) + +#include + +/* pipe_thread + */ +typedef HANDLE pipe_thread; + +#define PIPE_THREAD_ROUTINE( name, param ) \ + void * WINAPI name( void *param ) + +static INLINE pipe_thread pipe_thread_create( void *(WINAPI * routine)( void *), void *param ) +{ + DWORD id; + return CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE) routine, param, 0, &id ); +} + +static INLINE int pipe_thread_wait( pipe_thread thread ) +{ + if (WaitForSingleObject( thread, INFINITE ) == WAIT_OBJECT_0) + return 0; + return -1; +} + +static INLINE int pipe_thread_destroy( pipe_thread thread ) +{ + if (CloseHandle( thread )) + return 0; + return -1; +} + + +/* pipe_mutex + */ +typedef CRITICAL_SECTION pipe_mutex; + +#define pipe_static_mutex(mutex) \ + /*static*/ pipe_mutex mutex = {0,0,0,0,0,0} + +#define pipe_mutex_init(mutex) \ + InitializeCriticalSection(&mutex) + +#define pipe_mutex_destroy(mutex) \ + DeleteCriticalSection(&mutex) + +#define pipe_mutex_lock(mutex) \ + EnterCriticalSection(&mutex) + +#define pipe_mutex_unlock(mutex) \ + LeaveCriticalSection(&mutex) + +/* TODO: Need a macro to declare "I don't care about WinXP compatibilty" */ +#if 0 && defined (_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600) +/* CONDITION_VARIABLE is only available on newer versions of Windows + * (Server 2008/Vista or later). + * http://msdn.microsoft.com/en-us/library/ms682052(VS.85).aspx + * + * pipe_condvar + */ +typedef CONDITION_VARIABLE pipe_condvar; + +#define pipe_static_condvar(cond) \ + /*static*/ pipe_condvar cond = CONDITION_VARIABLE_INIT + +#define pipe_condvar_init(cond) \ + InitializeConditionVariable(&(cond)) + +#define pipe_condvar_destroy(cond) \ + (void) cond /* nothing to do */ + +#define pipe_condvar_wait(cond, mutex) \ + SleepConditionVariableCS(&(cond), &(mutex), INFINITE) + +#define pipe_condvar_signal(cond) \ + WakeConditionVariable(&(cond)) + +#define pipe_condvar_broadcast(cond) \ + WakeAllConditionVariable(&(cond)) + +#else /* need compatibility with pre-Vista Win32 */ + +/* pipe_condvar (XXX FIX THIS) + * See http://www.cs.wustl.edu/~schmidt/win32-cv-1.html + * for potential pitfalls in implementation. + */ +typedef DWORD pipe_condvar; + +#define pipe_static_condvar(cond) \ + /*static*/ pipe_condvar cond = 1 + +#define pipe_condvar_init(cond) \ + (void) (cond = 1) + +#define pipe_condvar_destroy(cond) \ + (void) cond + +/* Poor man's pthread_cond_wait(): + Just release the mutex and sleep for one millisecond. + The caller's while() loop does all the work. */ +#define pipe_condvar_wait(cond, mutex) \ + do { pipe_mutex_unlock(mutex); \ + Sleep(cond); \ + pipe_mutex_lock(mutex); \ + } while (0) + +#define pipe_condvar_signal(cond) \ + (void) cond + +#define pipe_condvar_broadcast(cond) \ + (void) cond + +#endif /* pre-Vista win32 */ + +#else + +#include "os/os_time.h" + +/** Dummy definitions */ + +typedef unsigned pipe_thread; + +#define PIPE_THREAD_ROUTINE( name, param ) \ + void * name( void *param ) + +static INLINE pipe_thread pipe_thread_create( void *(* routine)( void *), void *param ) +{ + return 0; +} + +static INLINE int pipe_thread_wait( pipe_thread thread ) +{ + return -1; +} + +static INLINE int pipe_thread_destroy( pipe_thread thread ) +{ + return -1; +} + +typedef unsigned pipe_mutex; + +#define pipe_static_mutex(mutex) \ + static pipe_mutex mutex = 0 + +#define pipe_mutex_init(mutex) \ + (void) mutex + +#define pipe_mutex_destroy(mutex) \ + (void) mutex + +#define pipe_mutex_lock(mutex) \ + (void) mutex + +#define pipe_mutex_unlock(mutex) \ + (void) mutex + +typedef int64_t pipe_condvar; + +#define pipe_static_condvar(condvar) \ + static pipe_condvar condvar = 1000 + +#define pipe_condvar_init(condvar) \ + (void) (condvar = 1000) + +#define pipe_condvar_destroy(condvar) \ + (void) condvar + +/* Poor man's pthread_cond_wait(): + Just release the mutex and sleep for one millisecond. + The caller's while() loop does all the work. */ +#define pipe_condvar_wait(condvar, mutex) \ + do { pipe_mutex_unlock(mutex); \ + os_time_sleep(condvar); \ + pipe_mutex_lock(mutex); \ + } while (0) + +#define pipe_condvar_signal(condvar) \ + (void) condvar + +#define pipe_condvar_broadcast(condvar) \ + (void) condvar + + +#endif /* PIPE_OS_? */ + + +/* + * pipe_barrier + */ + +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED) + +typedef pthread_barrier_t pipe_barrier; + +static INLINE void pipe_barrier_init(pipe_barrier *barrier, unsigned count) +{ + pthread_barrier_init(barrier, NULL, count); +} + +static INLINE void pipe_barrier_destroy(pipe_barrier *barrier) +{ + pthread_barrier_destroy(barrier); +} + +static INLINE void pipe_barrier_wait(pipe_barrier *barrier) +{ + pthread_barrier_wait(barrier); +} + + +#else /* If the OS doesn't have its own, implement barriers using a mutex and a condvar */ + +typedef struct { + unsigned count; + unsigned waiters; + uint64_t sequence; + pipe_mutex mutex; + pipe_condvar condvar; +} pipe_barrier; + +static INLINE void pipe_barrier_init(pipe_barrier *barrier, unsigned count) +{ + barrier->count = count; + barrier->waiters = 0; + barrier->sequence = 0; + pipe_mutex_init(barrier->mutex); + pipe_condvar_init(barrier->condvar); +} + +static INLINE void pipe_barrier_destroy(pipe_barrier *barrier) +{ + assert(barrier->waiters == 0); + pipe_mutex_destroy(barrier->mutex); + pipe_condvar_destroy(barrier->condvar); +} + +static INLINE void pipe_barrier_wait(pipe_barrier *barrier) +{ + pipe_mutex_lock(barrier->mutex); + + assert(barrier->waiters < barrier->count); + barrier->waiters++; + + if (barrier->waiters < barrier->count) { + uint64_t sequence = barrier->sequence; + + do { + pipe_condvar_wait(barrier->condvar, barrier->mutex); + } while (sequence == barrier->sequence); + } else { + barrier->waiters = 0; + barrier->sequence++; + pipe_condvar_broadcast(barrier->condvar); + } + + pipe_mutex_unlock(barrier->mutex); +} + + +#endif + + +/* + * Semaphores + */ + +typedef struct +{ + pipe_mutex mutex; + pipe_condvar cond; + int counter; +} pipe_semaphore; + + +static INLINE void +pipe_semaphore_init(pipe_semaphore *sema, int init_val) +{ + pipe_mutex_init(sema->mutex); + pipe_condvar_init(sema->cond); + sema->counter = init_val; +} + +static INLINE void +pipe_semaphore_destroy(pipe_semaphore *sema) +{ + pipe_mutex_destroy(sema->mutex); + pipe_condvar_destroy(sema->cond); +} + +/** Signal/increment semaphore counter */ +static INLINE void +pipe_semaphore_signal(pipe_semaphore *sema) +{ + pipe_mutex_lock(sema->mutex); + sema->counter++; + pipe_condvar_signal(sema->cond); + pipe_mutex_unlock(sema->mutex); +} + +/** Wait for semaphore counter to be greater than zero */ +static INLINE void +pipe_semaphore_wait(pipe_semaphore *sema) +{ + pipe_mutex_lock(sema->mutex); + while (sema->counter <= 0) { + pipe_condvar_wait(sema->cond, sema->mutex); + } + sema->counter--; + pipe_mutex_unlock(sema->mutex); +} + + + +/* + * Thread-specific data. + */ + +typedef struct { +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED) || defined(PIPE_OS_CYGWIN) + pthread_key_t key; +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) + DWORD key; +#endif + int initMagic; +} pipe_tsd; + + +#define PIPE_TSD_INIT_MAGIC 0xff8adc98 + + +static INLINE void +pipe_tsd_init(pipe_tsd *tsd) +{ +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED) || defined(PIPE_OS_CYGWIN) + if (pthread_key_create(&tsd->key, NULL/*free*/) != 0) { + perror("pthread_key_create(): failed to allocate key for thread specific data"); + exit(-1); + } +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) + assert(0); +#endif + tsd->initMagic = PIPE_TSD_INIT_MAGIC; +} + +static INLINE void * +pipe_tsd_get(pipe_tsd *tsd) +{ + if (tsd->initMagic != (int) PIPE_TSD_INIT_MAGIC) { + pipe_tsd_init(tsd); + } +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED) || defined(PIPE_OS_CYGWIN) + return pthread_getspecific(tsd->key); +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) + assert(0); + return NULL; +#else + assert(0); + return NULL; +#endif +} + +static INLINE void +pipe_tsd_set(pipe_tsd *tsd, void *value) +{ + if (tsd->initMagic != (int) PIPE_TSD_INIT_MAGIC) { + pipe_tsd_init(tsd); + } +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED) || defined(PIPE_OS_CYGWIN) + if (pthread_setspecific(tsd->key, value) != 0) { + perror("pthread_set_specific() failed"); + exit(-1); + } +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) + assert(0); +#else + assert(0); +#endif +} + + + +#endif /* OS_THREAD_H_ */ diff --git a/src/gallium/auxiliary/os/os_time.c b/src/gallium/auxiliary/os/os_time.c new file mode 100644 index 0000000..8490721 --- /dev/null +++ b/src/gallium/auxiliary/os/os_time.c @@ -0,0 +1,128 @@ +/************************************************************************** + * + * Copyright 2008-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * OS independent time-manipulation functions. + * + * @author Jose Fonseca + */ + + +#include "pipe/p_config.h" + +#if !defined(PIPE_OS_EMBEDDED) + +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_CYGWIN) +# include /* timeval */ +#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) +# include +# include +#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) +# include +extern VOID KeQuerySystemTime(PLARGE_INTEGER); +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE) +# include +#else +# error Unsupported OS +#endif + +#include "os_time.h" + + +int64_t +os_time_get(void) +{ +#if defined(PIPE_OS_UNIX) + + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_usec + tv.tv_sec*1000000LL; + +#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) + + static LONGLONG frequency; + LONGLONG counter; + if(!frequency) + EngQueryPerformanceFrequency(&frequency); + EngQueryPerformanceCounter(&counter); + return counter*INT64_C(1000000)/frequency; + +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE) + + static LARGE_INTEGER frequency; + LARGE_INTEGER counter; + if(!frequency.QuadPart) + QueryPerformanceFrequency(&frequency); + QueryPerformanceCounter(&counter); + return counter.QuadPart*INT64_C(1000000)/frequency.QuadPart; + +#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) + + /* Updated every 10 miliseconds, measured in units of 100 nanoseconds. + * http://msdn.microsoft.com/en-us/library/ms801642.aspx */ + LARGE_INTEGER counter; + KeQuerySystemTime(&counter); + return counter.QuadPart/10; + +#endif +} + + +#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) + +void +os_time_sleep(int64_t usecs) +{ + static LONGLONG frequency; + LONGLONG start, curr, end; + + EngQueryPerformanceCounter(&start); + + if(!frequency) + EngQueryPerformanceFrequency(&frequency); + + end = start + (usecs * frequency + 999999LL)/1000000LL; + + do { + EngQueryPerformanceCounter(&curr); + } while(start <= curr && curr < end || + end < start && (curr < end || start <= curr)); +} + +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) + +void +os_time_sleep(int64_t usecs) +{ + Sleep((usecs + 999) / 1000); +} + +#endif + + +#endif /* !PIPE_OS_EMBEDDED */ diff --git a/src/gallium/auxiliary/os/os_time.h b/src/gallium/auxiliary/os/os_time.h new file mode 100644 index 0000000..7e0f67a --- /dev/null +++ b/src/gallium/auxiliary/os/os_time.h @@ -0,0 +1,92 @@ +/************************************************************************** + * + * Copyright 2008-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * OS independent time-manipulation functions. + * + * @author Jose Fonseca + */ + +#ifndef _OS_TIME_H_ +#define _OS_TIME_H_ + + +#include "pipe/p_config.h" + +#if defined(PIPE_OS_UNIX) +# include /* usleep */ +#endif + +#include "pipe/p_compiler.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* + * Get the current time in microseconds from an unknown base. + */ +int64_t +os_time_get(void); + + +/* + * Sleep. + */ +#if defined(PIPE_OS_UNIX) +#define os_time_sleep(_usecs) usleep(_usecs) +#else +void +os_time_sleep(int64_t usecs); +#endif + + +/* + * Helper function for detecting time outs, taking in account overflow. + * + * Returns true if the current time has elapsed beyond the specified interval. + */ +static INLINE boolean +os_time_timeout(int64_t start, + int64_t end, + int64_t curr) +{ + if(start <= end) + return !(start <= curr && curr < end); + else + return !((start <= curr) || (curr < end)); +} + + +#ifdef __cplusplus +} +#endif + +#endif /* _OS_TIME_H_ */ diff --git a/src/gallium/auxiliary/pipebuffer/Makefile b/src/gallium/auxiliary/pipebuffer/Makefile new file mode 100644 index 0000000..21d25d2 --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = pipebuffer + +C_SOURCES = \ + pb_buffer_fenced.c \ + pb_buffer_malloc.c \ + pb_bufmgr_alt.c \ + pb_bufmgr_cache.c \ + pb_bufmgr_debug.c \ + pb_bufmgr_mm.c \ + pb_bufmgr_ondemand.c \ + pb_bufmgr_pool.c \ + pb_bufmgr_slab.c \ + pb_validate.c + +include ../../Makefile.template diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer.h b/src/gallium/auxiliary/pipebuffer/pb_buffer.h new file mode 100644 index 0000000..5a13f39 --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer.h @@ -0,0 +1,292 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \file + * Generic code for buffers. + * + * Behind a pipe buffle handle there can be DMA buffers, client (or user) + * buffers, regular malloced buffers, etc. This file provides an abstract base + * buffer handle that allows the driver to cope with all those kinds of buffers + * in a more flexible way. + * + * There is no obligation of a winsys driver to use this library. And a pipe + * driver should be completly agnostic about it. + * + * \author Jose Fonseca + */ + +#ifndef PB_BUFFER_H_ +#define PB_BUFFER_H_ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" +#include "util/u_inlines.h" +#include "pipe/p_defines.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct pb_vtbl; +struct pb_validate; +struct pipe_fence_handle; + + +#define PB_USAGE_CPU_READ (1 << 0) +#define PB_USAGE_CPU_WRITE (1 << 1) +#define PB_USAGE_GPU_READ (1 << 2) +#define PB_USAGE_GPU_WRITE (1 << 3) +#define PB_USAGE_UNSYNCHRONIZED (1 << 10) +#define PB_USAGE_DONTBLOCK (1 << 9) + +#define PB_USAGE_CPU_READ_WRITE \ + ( PB_USAGE_CPU_READ | PB_USAGE_CPU_WRITE ) +#define PB_USAGE_GPU_READ_WRITE \ + ( PB_USAGE_GPU_READ | PB_USAGE_GPU_WRITE ) +#define PB_USAGE_WRITE \ + ( PB_USAGE_CPU_WRITE | PB_USAGE_GPU_WRITE ) + +/** + * Buffer description. + * + * Used when allocating the buffer. + */ +struct pb_desc +{ + unsigned alignment; + unsigned usage; +}; + + +/** + * Size. Regular (32bit) unsigned for now. + */ +typedef unsigned pb_size; + + +/** + * Base class for all pb_* buffers. + */ +struct pb_buffer +{ + /* This used to be a pipe_buffer struct: + */ + struct { + struct pipe_reference reference; + unsigned size; + unsigned alignment; + unsigned usage; + } base; + + /** + * Pointer to the virtual function table. + * + * Avoid accessing this table directly. Use the inline functions below + * instead to avoid mistakes. + */ + const struct pb_vtbl *vtbl; +}; + + +/** + * Virtual function table for the buffer storage operations. + * + * Note that creation is not done through this table. + */ +struct pb_vtbl +{ + void (*destroy)( struct pb_buffer *buf ); + + /** + * Map the entire data store of a buffer object into the client's address. + * flags is bitmask of PB_USAGE_CPU_READ/WRITE. + */ + void *(*map)( struct pb_buffer *buf, + unsigned flags, void *flush_ctx ); + + void (*unmap)( struct pb_buffer *buf ); + + enum pipe_error (*validate)( struct pb_buffer *buf, + struct pb_validate *vl, + unsigned flags ); + + void (*fence)( struct pb_buffer *buf, + struct pipe_fence_handle *fence ); + + /** + * Get the base buffer and the offset. + * + * A buffer can be subdivided in smaller buffers. This method should return + * the underlaying buffer, and the relative offset. + * + * Buffers without an underlaying base buffer should return themselves, with + * a zero offset. + * + * Note that this will increase the reference count of the base buffer. + */ + void (*get_base_buffer)( struct pb_buffer *buf, + struct pb_buffer **base_buf, + pb_size *offset ); + +}; + + + +/* Accessor functions for pb->vtbl: + */ +static INLINE void * +pb_map(struct pb_buffer *buf, + unsigned flags, void *flush_ctx) +{ + assert(buf); + if(!buf) + return NULL; + assert(pipe_is_referenced(&buf->base.reference)); + return buf->vtbl->map(buf, flags, flush_ctx); +} + + +static INLINE void +pb_unmap(struct pb_buffer *buf) +{ + assert(buf); + if(!buf) + return; + assert(pipe_is_referenced(&buf->base.reference)); + buf->vtbl->unmap(buf); +} + + +static INLINE void +pb_get_base_buffer( struct pb_buffer *buf, + struct pb_buffer **base_buf, + pb_size *offset ) +{ + assert(buf); + if(!buf) { + base_buf = NULL; + offset = 0; + return; + } + assert(pipe_is_referenced(&buf->base.reference)); + assert(buf->vtbl->get_base_buffer); + buf->vtbl->get_base_buffer(buf, base_buf, offset); + assert(*base_buf); + assert(*offset < (*base_buf)->base.size); +} + + +static INLINE enum pipe_error +pb_validate(struct pb_buffer *buf, struct pb_validate *vl, unsigned flags) +{ + assert(buf); + if(!buf) + return PIPE_ERROR; + assert(buf->vtbl->validate); + return buf->vtbl->validate(buf, vl, flags); +} + + +static INLINE void +pb_fence(struct pb_buffer *buf, struct pipe_fence_handle *fence) +{ + assert(buf); + if(!buf) + return; + assert(buf->vtbl->fence); + buf->vtbl->fence(buf, fence); +} + + +static INLINE void +pb_destroy(struct pb_buffer *buf) +{ + assert(buf); + if(!buf) + return; + assert(!pipe_is_referenced(&buf->base.reference)); + buf->vtbl->destroy(buf); +} + +static INLINE void +pb_reference(struct pb_buffer **dst, + struct pb_buffer *src) +{ + struct pb_buffer *old = *dst; + + if (pipe_reference(&(*dst)->base.reference, &src->base.reference)) + pb_destroy( old ); + *dst = src; +} + + +/** + * Utility function to check whether the provided alignment is consistent with + * the requested or not. + */ +static INLINE boolean +pb_check_alignment(pb_size requested, pb_size provided) +{ + if(!requested) + return TRUE; + if(requested > provided) + return FALSE; + if(provided % requested != 0) + return FALSE; + return TRUE; +} + + +/** + * Utility function to check whether the provided alignment is consistent with + * the requested or not. + */ +static INLINE boolean +pb_check_usage(unsigned requested, unsigned provided) +{ + return (requested & provided) == requested ? TRUE : FALSE; +} + + +/** + * Malloc-based buffer to store data that can't be used by the graphics + * hardware. + */ +struct pb_buffer * +pb_malloc_buffer_create(pb_size size, + const struct pb_desc *desc); + + +#ifdef __cplusplus +} +#endif + +#endif /*PB_BUFFER_H_*/ diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c new file mode 100644 index 0000000..c310f28 --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c @@ -0,0 +1,1069 @@ +/************************************************************************** + * + * Copyright 2007-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \file + * Implementation of fenced buffers. + * + * \author Jose Fonseca + * \author Thomas Hellström + */ + + +#include "pipe/p_config.h" + +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) +#include +#include +#endif + +#include "pipe/p_compiler.h" +#include "pipe/p_defines.h" +#include "util/u_debug.h" +#include "os/os_thread.h" +#include "util/u_memory.h" +#include "util/u_double_list.h" + +#include "pb_buffer.h" +#include "pb_buffer_fenced.h" +#include "pb_bufmgr.h" + + + +/** + * Convenience macro (type safe). + */ +#define SUPER(__derived) (&(__derived)->base) + + +struct fenced_manager +{ + struct pb_manager base; + struct pb_manager *provider; + struct pb_fence_ops *ops; + + /** + * Maximum buffer size that can be safely allocated. + */ + pb_size max_buffer_size; + + /** + * Maximum cpu memory we can allocate before we start waiting for the + * GPU to idle. + */ + pb_size max_cpu_total_size; + + /** + * Following members are mutable and protected by this mutex. + */ + pipe_mutex mutex; + + /** + * Fenced buffer list. + * + * All fenced buffers are placed in this listed, ordered from the oldest + * fence to the newest fence. + */ + struct list_head fenced; + pb_size num_fenced; + + struct list_head unfenced; + pb_size num_unfenced; + + /** + * How much temporary CPU memory is being used to hold unvalidated buffers. + */ + pb_size cpu_total_size; +}; + + +/** + * Fenced buffer. + * + * Wrapper around a pipe buffer which adds fencing and reference counting. + */ +struct fenced_buffer +{ + /* + * Immutable members. + */ + + struct pb_buffer base; + struct fenced_manager *mgr; + + /* + * Following members are mutable and protected by fenced_manager::mutex. + */ + + struct list_head head; + + /** + * Buffer with storage. + */ + struct pb_buffer *buffer; + pb_size size; + struct pb_desc desc; + + /** + * Temporary CPU storage data. Used when there isn't enough GPU memory to + * store the buffer. + */ + void *data; + + /** + * A bitmask of PB_USAGE_CPU/GPU_READ/WRITE describing the current + * buffer usage. + */ + unsigned flags; + + unsigned mapcount; + + struct pb_validate *vl; + unsigned validation_flags; + + struct pipe_fence_handle *fence; +}; + + +static INLINE struct fenced_manager * +fenced_manager(struct pb_manager *mgr) +{ + assert(mgr); + return (struct fenced_manager *)mgr; +} + + +static INLINE struct fenced_buffer * +fenced_buffer(struct pb_buffer *buf) +{ + assert(buf); + return (struct fenced_buffer *)buf; +} + + +static void +fenced_buffer_destroy_cpu_storage_locked(struct fenced_buffer *fenced_buf); + +static enum pipe_error +fenced_buffer_create_cpu_storage_locked(struct fenced_manager *fenced_mgr, + struct fenced_buffer *fenced_buf); + +static void +fenced_buffer_destroy_gpu_storage_locked(struct fenced_buffer *fenced_buf); + +static enum pipe_error +fenced_buffer_create_gpu_storage_locked(struct fenced_manager *fenced_mgr, + struct fenced_buffer *fenced_buf, + boolean wait); + +static enum pipe_error +fenced_buffer_copy_storage_to_gpu_locked(struct fenced_buffer *fenced_buf); + +static enum pipe_error +fenced_buffer_copy_storage_to_cpu_locked(struct fenced_buffer *fenced_buf); + + +/** + * Dump the fenced buffer list. + * + * Useful to understand failures to allocate buffers. + */ +static void +fenced_manager_dump_locked(struct fenced_manager *fenced_mgr) +{ +#ifdef DEBUG + struct pb_fence_ops *ops = fenced_mgr->ops; + struct list_head *curr, *next; + struct fenced_buffer *fenced_buf; + + debug_printf("%10s %7s %8s %7s %10s %s\n", + "buffer", "size", "refcount", "storage", "fence", "signalled"); + + curr = fenced_mgr->unfenced.next; + next = curr->next; + while(curr != &fenced_mgr->unfenced) { + fenced_buf = LIST_ENTRY(struct fenced_buffer, curr, head); + assert(!fenced_buf->fence); + debug_printf("%10p %7u %8u %7s\n", + (void *) fenced_buf, + fenced_buf->base.base.size, + p_atomic_read(&fenced_buf->base.base.reference.count), + fenced_buf->buffer ? "gpu" : (fenced_buf->data ? "cpu" : "none")); + curr = next; + next = curr->next; + } + + curr = fenced_mgr->fenced.next; + next = curr->next; + while(curr != &fenced_mgr->fenced) { + int signaled; + fenced_buf = LIST_ENTRY(struct fenced_buffer, curr, head); + assert(fenced_buf->buffer); + signaled = ops->fence_signalled(ops, fenced_buf->fence, 0); + debug_printf("%10p %7u %8u %7s %10p %s\n", + (void *) fenced_buf, + fenced_buf->base.base.size, + p_atomic_read(&fenced_buf->base.base.reference.count), + "gpu", + (void *) fenced_buf->fence, + signaled == 0 ? "y" : "n"); + curr = next; + next = curr->next; + } +#else + (void)fenced_mgr; +#endif +} + + +static INLINE void +fenced_buffer_destroy_locked(struct fenced_manager *fenced_mgr, + struct fenced_buffer *fenced_buf) +{ + assert(!pipe_is_referenced(&fenced_buf->base.base.reference)); + + assert(!fenced_buf->fence); + assert(fenced_buf->head.prev); + assert(fenced_buf->head.next); + LIST_DEL(&fenced_buf->head); + assert(fenced_mgr->num_unfenced); + --fenced_mgr->num_unfenced; + + fenced_buffer_destroy_gpu_storage_locked(fenced_buf); + fenced_buffer_destroy_cpu_storage_locked(fenced_buf); + + FREE(fenced_buf); +} + + +/** + * Add the buffer to the fenced list. + * + * Reference count should be incremented before calling this function. + */ +static INLINE void +fenced_buffer_add_locked(struct fenced_manager *fenced_mgr, + struct fenced_buffer *fenced_buf) +{ + assert(pipe_is_referenced(&fenced_buf->base.base.reference)); + assert(fenced_buf->flags & PB_USAGE_GPU_READ_WRITE); + assert(fenced_buf->fence); + + p_atomic_inc(&fenced_buf->base.base.reference.count); + + LIST_DEL(&fenced_buf->head); + assert(fenced_mgr->num_unfenced); + --fenced_mgr->num_unfenced; + LIST_ADDTAIL(&fenced_buf->head, &fenced_mgr->fenced); + ++fenced_mgr->num_fenced; +} + + +/** + * Remove the buffer from the fenced list, and potentially destroy the buffer + * if the reference count reaches zero. + * + * Returns TRUE if the buffer was detroyed. + */ +static INLINE boolean +fenced_buffer_remove_locked(struct fenced_manager *fenced_mgr, + struct fenced_buffer *fenced_buf) +{ + struct pb_fence_ops *ops = fenced_mgr->ops; + + assert(fenced_buf->fence); + assert(fenced_buf->mgr == fenced_mgr); + + ops->fence_reference(ops, &fenced_buf->fence, NULL); + fenced_buf->flags &= ~PB_USAGE_GPU_READ_WRITE; + + assert(fenced_buf->head.prev); + assert(fenced_buf->head.next); + + LIST_DEL(&fenced_buf->head); + assert(fenced_mgr->num_fenced); + --fenced_mgr->num_fenced; + + LIST_ADDTAIL(&fenced_buf->head, &fenced_mgr->unfenced); + ++fenced_mgr->num_unfenced; + + if (p_atomic_dec_zero(&fenced_buf->base.base.reference.count)) { + fenced_buffer_destroy_locked(fenced_mgr, fenced_buf); + return TRUE; + } + + return FALSE; +} + + +/** + * Wait for the fence to expire, and remove it from the fenced list. + * + * This function will release and re-aquire the mutex, so any copy of mutable + * state must be discarded after calling it. + */ +static INLINE enum pipe_error +fenced_buffer_finish_locked(struct fenced_manager *fenced_mgr, + struct fenced_buffer *fenced_buf) +{ + struct pb_fence_ops *ops = fenced_mgr->ops; + enum pipe_error ret = PIPE_ERROR; + +#if 0 + debug_warning("waiting for GPU"); +#endif + + assert(pipe_is_referenced(&fenced_buf->base.base.reference)); + assert(fenced_buf->fence); + + if(fenced_buf->fence) { + struct pipe_fence_handle *fence = NULL; + int finished; + boolean proceed; + + ops->fence_reference(ops, &fence, fenced_buf->fence); + + pipe_mutex_unlock(fenced_mgr->mutex); + + finished = ops->fence_finish(ops, fenced_buf->fence, 0); + + pipe_mutex_lock(fenced_mgr->mutex); + + assert(pipe_is_referenced(&fenced_buf->base.base.reference)); + + /* + * Only proceed if the fence object didn't change in the meanwhile. + * Otherwise assume the work has been already carried out by another + * thread that re-aquired the lock before us. + */ + proceed = fence == fenced_buf->fence ? TRUE : FALSE; + + ops->fence_reference(ops, &fence, NULL); + + if(proceed && finished == 0) { + /* + * Remove from the fenced list + */ + + boolean destroyed; + + destroyed = fenced_buffer_remove_locked(fenced_mgr, fenced_buf); + + /* TODO: remove consequents buffers with the same fence? */ + + assert(!destroyed); + + fenced_buf->flags &= ~PB_USAGE_GPU_READ_WRITE; + + ret = PIPE_OK; + } + } + + return ret; +} + + +/** + * Remove as many fenced buffers from the fenced list as possible. + * + * Returns TRUE if at least one buffer was removed. + */ +static boolean +fenced_manager_check_signalled_locked(struct fenced_manager *fenced_mgr, + boolean wait) +{ + struct pb_fence_ops *ops = fenced_mgr->ops; + struct list_head *curr, *next; + struct fenced_buffer *fenced_buf; + struct pipe_fence_handle *prev_fence = NULL; + boolean ret = FALSE; + + curr = fenced_mgr->fenced.next; + next = curr->next; + while(curr != &fenced_mgr->fenced) { + fenced_buf = LIST_ENTRY(struct fenced_buffer, curr, head); + + if(fenced_buf->fence != prev_fence) { + int signaled; + + if (wait) { + signaled = ops->fence_finish(ops, fenced_buf->fence, 0); + + /* + * Don't return just now. Instead preemptively check if the + * following buffers' fences already expired, without further waits. + */ + wait = FALSE; + } + else { + signaled = ops->fence_signalled(ops, fenced_buf->fence, 0); + } + + if (signaled != 0) { + return ret; + } + + prev_fence = fenced_buf->fence; + } + else { + /* This buffer's fence object is identical to the previous buffer's + * fence object, so no need to check the fence again. + */ + assert(ops->fence_signalled(ops, fenced_buf->fence, 0) == 0); + } + + fenced_buffer_remove_locked(fenced_mgr, fenced_buf); + + ret = TRUE; + + curr = next; + next = curr->next; + } + + return ret; +} + + +/** + * Try to free some GPU memory by backing it up into CPU memory. + * + * Returns TRUE if at least one buffer was freed. + */ +static boolean +fenced_manager_free_gpu_storage_locked(struct fenced_manager *fenced_mgr) +{ + struct list_head *curr, *next; + struct fenced_buffer *fenced_buf; + + curr = fenced_mgr->unfenced.next; + next = curr->next; + while(curr != &fenced_mgr->unfenced) { + fenced_buf = LIST_ENTRY(struct fenced_buffer, curr, head); + + /* + * We can only move storage if the buffer is not mapped and not + * validated. + */ + if(fenced_buf->buffer && + !fenced_buf->mapcount && + !fenced_buf->vl) { + enum pipe_error ret; + + ret = fenced_buffer_create_cpu_storage_locked(fenced_mgr, fenced_buf); + if(ret == PIPE_OK) { + ret = fenced_buffer_copy_storage_to_cpu_locked(fenced_buf); + if(ret == PIPE_OK) { + fenced_buffer_destroy_gpu_storage_locked(fenced_buf); + return TRUE; + } + fenced_buffer_destroy_cpu_storage_locked(fenced_buf); + } + } + + curr = next; + next = curr->next; + } + + return FALSE; +} + + +/** + * Destroy CPU storage for this buffer. + */ +static void +fenced_buffer_destroy_cpu_storage_locked(struct fenced_buffer *fenced_buf) +{ + if(fenced_buf->data) { + align_free(fenced_buf->data); + fenced_buf->data = NULL; + assert(fenced_buf->mgr->cpu_total_size >= fenced_buf->size); + fenced_buf->mgr->cpu_total_size -= fenced_buf->size; + } +} + + +/** + * Create CPU storage for this buffer. + */ +static enum pipe_error +fenced_buffer_create_cpu_storage_locked(struct fenced_manager *fenced_mgr, + struct fenced_buffer *fenced_buf) +{ + assert(!fenced_buf->data); + if(fenced_buf->data) + return PIPE_OK; + + if (fenced_mgr->cpu_total_size + fenced_buf->size > fenced_mgr->max_cpu_total_size) + return PIPE_ERROR_OUT_OF_MEMORY; + + fenced_buf->data = align_malloc(fenced_buf->size, fenced_buf->desc.alignment); + if(!fenced_buf->data) + return PIPE_ERROR_OUT_OF_MEMORY; + + fenced_mgr->cpu_total_size += fenced_buf->size; + + return PIPE_OK; +} + + +/** + * Destroy the GPU storage. + */ +static void +fenced_buffer_destroy_gpu_storage_locked(struct fenced_buffer *fenced_buf) +{ + if(fenced_buf->buffer) { + pb_reference(&fenced_buf->buffer, NULL); + } +} + + +/** + * Try to create GPU storage for this buffer. + * + * This function is a shorthand around pb_manager::create_buffer for + * fenced_buffer_create_gpu_storage_locked()'s benefit. + */ +static INLINE boolean +fenced_buffer_try_create_gpu_storage_locked(struct fenced_manager *fenced_mgr, + struct fenced_buffer *fenced_buf) +{ + struct pb_manager *provider = fenced_mgr->provider; + + assert(!fenced_buf->buffer); + + fenced_buf->buffer = provider->create_buffer(fenced_mgr->provider, + fenced_buf->size, + &fenced_buf->desc); + return fenced_buf->buffer ? TRUE : FALSE; +} + + +/** + * Create GPU storage for this buffer. + */ +static enum pipe_error +fenced_buffer_create_gpu_storage_locked(struct fenced_manager *fenced_mgr, + struct fenced_buffer *fenced_buf, + boolean wait) +{ + assert(!fenced_buf->buffer); + + /* + * Check for signaled buffers before trying to allocate. + */ + fenced_manager_check_signalled_locked(fenced_mgr, FALSE); + + fenced_buffer_try_create_gpu_storage_locked(fenced_mgr, fenced_buf); + + /* + * Keep trying while there is some sort of progress: + * - fences are expiring, + * - or buffers are being being swapped out from GPU memory into CPU memory. + */ + while(!fenced_buf->buffer && + (fenced_manager_check_signalled_locked(fenced_mgr, FALSE) || + fenced_manager_free_gpu_storage_locked(fenced_mgr))) { + fenced_buffer_try_create_gpu_storage_locked(fenced_mgr, fenced_buf); + } + + if(!fenced_buf->buffer && wait) { + /* + * Same as before, but this time around, wait to free buffers if + * necessary. + */ + while(!fenced_buf->buffer && + (fenced_manager_check_signalled_locked(fenced_mgr, TRUE) || + fenced_manager_free_gpu_storage_locked(fenced_mgr))) { + fenced_buffer_try_create_gpu_storage_locked(fenced_mgr, fenced_buf); + } + } + + if(!fenced_buf->buffer) { + if(0) + fenced_manager_dump_locked(fenced_mgr); + + /* give up */ + return PIPE_ERROR_OUT_OF_MEMORY; + } + + return PIPE_OK; +} + + +static enum pipe_error +fenced_buffer_copy_storage_to_gpu_locked(struct fenced_buffer *fenced_buf) +{ + uint8_t *map; + + assert(fenced_buf->data); + assert(fenced_buf->buffer); + + map = pb_map(fenced_buf->buffer, PB_USAGE_CPU_WRITE, NULL); + if(!map) + return PIPE_ERROR; + + memcpy(map, fenced_buf->data, fenced_buf->size); + + pb_unmap(fenced_buf->buffer); + + return PIPE_OK; +} + + +static enum pipe_error +fenced_buffer_copy_storage_to_cpu_locked(struct fenced_buffer *fenced_buf) +{ + const uint8_t *map; + + assert(fenced_buf->data); + assert(fenced_buf->buffer); + + map = pb_map(fenced_buf->buffer, PB_USAGE_CPU_READ, NULL); + if(!map) + return PIPE_ERROR; + + memcpy(fenced_buf->data, map, fenced_buf->size); + + pb_unmap(fenced_buf->buffer); + + return PIPE_OK; +} + + +static void +fenced_buffer_destroy(struct pb_buffer *buf) +{ + struct fenced_buffer *fenced_buf = fenced_buffer(buf); + struct fenced_manager *fenced_mgr = fenced_buf->mgr; + + assert(!pipe_is_referenced(&fenced_buf->base.base.reference)); + + pipe_mutex_lock(fenced_mgr->mutex); + + fenced_buffer_destroy_locked(fenced_mgr, fenced_buf); + + pipe_mutex_unlock(fenced_mgr->mutex); +} + + +static void * +fenced_buffer_map(struct pb_buffer *buf, + unsigned flags, void *flush_ctx) +{ + struct fenced_buffer *fenced_buf = fenced_buffer(buf); + struct fenced_manager *fenced_mgr = fenced_buf->mgr; + struct pb_fence_ops *ops = fenced_mgr->ops; + void *map = NULL; + + pipe_mutex_lock(fenced_mgr->mutex); + + assert(!(flags & PB_USAGE_GPU_READ_WRITE)); + + /* + * Serialize writes. + */ + while((fenced_buf->flags & PB_USAGE_GPU_WRITE) || + ((fenced_buf->flags & PB_USAGE_GPU_READ) && + (flags & PB_USAGE_CPU_WRITE))) { + + /* + * Don't wait for the GPU to finish accessing it, if blocking is forbidden. + */ + if((flags & PB_USAGE_DONTBLOCK) && + ops->fence_signalled(ops, fenced_buf->fence, 0) != 0) { + goto done; + } + + if (flags & PB_USAGE_UNSYNCHRONIZED) { + break; + } + + /* + * Wait for the GPU to finish accessing. This will release and re-acquire + * the mutex, so all copies of mutable state must be discarded. + */ + fenced_buffer_finish_locked(fenced_mgr, fenced_buf); + } + + if(fenced_buf->buffer) { + map = pb_map(fenced_buf->buffer, flags, flush_ctx); + } + else { + assert(fenced_buf->data); + map = fenced_buf->data; + } + + if(map) { + ++fenced_buf->mapcount; + fenced_buf->flags |= flags & PB_USAGE_CPU_READ_WRITE; + } + +done: + pipe_mutex_unlock(fenced_mgr->mutex); + + return map; +} + + +static void +fenced_buffer_unmap(struct pb_buffer *buf) +{ + struct fenced_buffer *fenced_buf = fenced_buffer(buf); + struct fenced_manager *fenced_mgr = fenced_buf->mgr; + + pipe_mutex_lock(fenced_mgr->mutex); + + assert(fenced_buf->mapcount); + if(fenced_buf->mapcount) { + if (fenced_buf->buffer) + pb_unmap(fenced_buf->buffer); + --fenced_buf->mapcount; + if(!fenced_buf->mapcount) + fenced_buf->flags &= ~PB_USAGE_CPU_READ_WRITE; + } + + pipe_mutex_unlock(fenced_mgr->mutex); +} + + +static enum pipe_error +fenced_buffer_validate(struct pb_buffer *buf, + struct pb_validate *vl, + unsigned flags) +{ + struct fenced_buffer *fenced_buf = fenced_buffer(buf); + struct fenced_manager *fenced_mgr = fenced_buf->mgr; + enum pipe_error ret; + + pipe_mutex_lock(fenced_mgr->mutex); + + if(!vl) { + /* invalidate */ + fenced_buf->vl = NULL; + fenced_buf->validation_flags = 0; + ret = PIPE_OK; + goto done; + } + + assert(flags & PB_USAGE_GPU_READ_WRITE); + assert(!(flags & ~PB_USAGE_GPU_READ_WRITE)); + flags &= PB_USAGE_GPU_READ_WRITE; + + /* Buffer cannot be validated in two different lists */ + if(fenced_buf->vl && fenced_buf->vl != vl) { + ret = PIPE_ERROR_RETRY; + goto done; + } + + if(fenced_buf->vl == vl && + (fenced_buf->validation_flags & flags) == flags) { + /* Nothing to do -- buffer already validated */ + ret = PIPE_OK; + goto done; + } + + /* + * Create and update GPU storage. + */ + if(!fenced_buf->buffer) { + assert(!fenced_buf->mapcount); + + ret = fenced_buffer_create_gpu_storage_locked(fenced_mgr, fenced_buf, TRUE); + if(ret != PIPE_OK) { + goto done; + } + + ret = fenced_buffer_copy_storage_to_gpu_locked(fenced_buf); + if(ret != PIPE_OK) { + fenced_buffer_destroy_gpu_storage_locked(fenced_buf); + goto done; + } + + if(fenced_buf->mapcount) { + debug_printf("warning: validating a buffer while it is still mapped\n"); + } + else { + fenced_buffer_destroy_cpu_storage_locked(fenced_buf); + } + } + + ret = pb_validate(fenced_buf->buffer, vl, flags); + if (ret != PIPE_OK) + goto done; + + fenced_buf->vl = vl; + fenced_buf->validation_flags |= flags; + +done: + pipe_mutex_unlock(fenced_mgr->mutex); + + return ret; +} + + +static void +fenced_buffer_fence(struct pb_buffer *buf, + struct pipe_fence_handle *fence) +{ + struct fenced_buffer *fenced_buf = fenced_buffer(buf); + struct fenced_manager *fenced_mgr = fenced_buf->mgr; + struct pb_fence_ops *ops = fenced_mgr->ops; + + pipe_mutex_lock(fenced_mgr->mutex); + + assert(pipe_is_referenced(&fenced_buf->base.base.reference)); + assert(fenced_buf->buffer); + + if(fence != fenced_buf->fence) { + assert(fenced_buf->vl); + assert(fenced_buf->validation_flags); + + if (fenced_buf->fence) { + boolean destroyed; + destroyed = fenced_buffer_remove_locked(fenced_mgr, fenced_buf); + assert(!destroyed); + } + if (fence) { + ops->fence_reference(ops, &fenced_buf->fence, fence); + fenced_buf->flags |= fenced_buf->validation_flags; + fenced_buffer_add_locked(fenced_mgr, fenced_buf); + } + + pb_fence(fenced_buf->buffer, fence); + + fenced_buf->vl = NULL; + fenced_buf->validation_flags = 0; + } + + pipe_mutex_unlock(fenced_mgr->mutex); +} + + +static void +fenced_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, + pb_size *offset) +{ + struct fenced_buffer *fenced_buf = fenced_buffer(buf); + struct fenced_manager *fenced_mgr = fenced_buf->mgr; + + pipe_mutex_lock(fenced_mgr->mutex); + + /* + * This should only be called when the buffer is validated. Typically + * when processing relocations. + */ + assert(fenced_buf->vl); + assert(fenced_buf->buffer); + + if(fenced_buf->buffer) + pb_get_base_buffer(fenced_buf->buffer, base_buf, offset); + else { + *base_buf = buf; + *offset = 0; + } + + pipe_mutex_unlock(fenced_mgr->mutex); +} + + +static const struct pb_vtbl +fenced_buffer_vtbl = { + fenced_buffer_destroy, + fenced_buffer_map, + fenced_buffer_unmap, + fenced_buffer_validate, + fenced_buffer_fence, + fenced_buffer_get_base_buffer +}; + + +/** + * Wrap a buffer in a fenced buffer. + */ +static struct pb_buffer * +fenced_bufmgr_create_buffer(struct pb_manager *mgr, + pb_size size, + const struct pb_desc *desc) +{ + struct fenced_manager *fenced_mgr = fenced_manager(mgr); + struct fenced_buffer *fenced_buf; + enum pipe_error ret; + + /* + * Don't stall the GPU, waste time evicting buffers, or waste memory + * trying to create a buffer that will most likely never fit into the + * graphics aperture. + */ + if(size > fenced_mgr->max_buffer_size) { + goto no_buffer; + } + + fenced_buf = CALLOC_STRUCT(fenced_buffer); + if(!fenced_buf) + goto no_buffer; + + pipe_reference_init(&fenced_buf->base.base.reference, 1); + fenced_buf->base.base.alignment = desc->alignment; + fenced_buf->base.base.usage = desc->usage; + fenced_buf->base.base.size = size; + fenced_buf->size = size; + fenced_buf->desc = *desc; + + fenced_buf->base.vtbl = &fenced_buffer_vtbl; + fenced_buf->mgr = fenced_mgr; + + pipe_mutex_lock(fenced_mgr->mutex); + + /* + * Try to create GPU storage without stalling, + */ + ret = fenced_buffer_create_gpu_storage_locked(fenced_mgr, fenced_buf, FALSE); + + /* + * Attempt to use CPU memory to avoid stalling the GPU. + */ + if(ret != PIPE_OK) { + ret = fenced_buffer_create_cpu_storage_locked(fenced_mgr, fenced_buf); + } + + /* + * Create GPU storage, waiting for some to be available. + */ + if(ret != PIPE_OK) { + ret = fenced_buffer_create_gpu_storage_locked(fenced_mgr, fenced_buf, TRUE); + } + + /* + * Give up. + */ + if(ret != PIPE_OK) { + goto no_storage; + } + + assert(fenced_buf->buffer || fenced_buf->data); + + LIST_ADDTAIL(&fenced_buf->head, &fenced_mgr->unfenced); + ++fenced_mgr->num_unfenced; + pipe_mutex_unlock(fenced_mgr->mutex); + + return &fenced_buf->base; + +no_storage: + pipe_mutex_unlock(fenced_mgr->mutex); + FREE(fenced_buf); +no_buffer: + return NULL; +} + + +static void +fenced_bufmgr_flush(struct pb_manager *mgr) +{ + struct fenced_manager *fenced_mgr = fenced_manager(mgr); + + pipe_mutex_lock(fenced_mgr->mutex); + while(fenced_manager_check_signalled_locked(fenced_mgr, TRUE)) + ; + pipe_mutex_unlock(fenced_mgr->mutex); + + assert(fenced_mgr->provider->flush); + if(fenced_mgr->provider->flush) + fenced_mgr->provider->flush(fenced_mgr->provider); +} + + +static void +fenced_bufmgr_destroy(struct pb_manager *mgr) +{ + struct fenced_manager *fenced_mgr = fenced_manager(mgr); + + pipe_mutex_lock(fenced_mgr->mutex); + + /* Wait on outstanding fences */ + while (fenced_mgr->num_fenced) { + pipe_mutex_unlock(fenced_mgr->mutex); +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) + sched_yield(); +#endif + pipe_mutex_lock(fenced_mgr->mutex); + while(fenced_manager_check_signalled_locked(fenced_mgr, TRUE)) + ; + } + +#ifdef DEBUG + /*assert(!fenced_mgr->num_unfenced);*/ +#endif + + pipe_mutex_unlock(fenced_mgr->mutex); + pipe_mutex_destroy(fenced_mgr->mutex); + + if(fenced_mgr->provider) + fenced_mgr->provider->destroy(fenced_mgr->provider); + + fenced_mgr->ops->destroy(fenced_mgr->ops); + + FREE(fenced_mgr); +} + + +struct pb_manager * +fenced_bufmgr_create(struct pb_manager *provider, + struct pb_fence_ops *ops, + pb_size max_buffer_size, + pb_size max_cpu_total_size) +{ + struct fenced_manager *fenced_mgr; + + if(!provider) + return NULL; + + fenced_mgr = CALLOC_STRUCT(fenced_manager); + if (!fenced_mgr) + return NULL; + + fenced_mgr->base.destroy = fenced_bufmgr_destroy; + fenced_mgr->base.create_buffer = fenced_bufmgr_create_buffer; + fenced_mgr->base.flush = fenced_bufmgr_flush; + + fenced_mgr->provider = provider; + fenced_mgr->ops = ops; + fenced_mgr->max_buffer_size = max_buffer_size; + fenced_mgr->max_cpu_total_size = max_cpu_total_size; + + LIST_INITHEAD(&fenced_mgr->fenced); + fenced_mgr->num_fenced = 0; + + LIST_INITHEAD(&fenced_mgr->unfenced); + fenced_mgr->num_unfenced = 0; + + pipe_mutex_init(fenced_mgr->mutex); + + return &fenced_mgr->base; +} diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h new file mode 100644 index 0000000..004c2b9 --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h @@ -0,0 +1,104 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \file + * Buffer fencing. + * + * "Fenced buffers" is actually a misnomer. They should be referred as + * "fenceable buffers", i.e, buffers that can be fenced, but I couldn't find + * the word "fenceable" in the dictionary. + * + * A "fenced buffer" is a decorator around a normal buffer, which adds two + * special properties: + * - the ability for the destruction to be delayed by a fence; + * - reference counting. + * + * Usually DMA buffers have a life-time that will extend the life-time of its + * handle. The end-of-life is dictated by the fence signalling. + * + * Between the handle's destruction, and the fence signalling, the buffer is + * stored in a fenced buffer list. + * + * \author Jose Fonseca + */ + +#ifndef PB_BUFFER_FENCED_H_ +#define PB_BUFFER_FENCED_H_ + + +#include "util/u_debug.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct pipe_fence_handle; + + +/** + * List of buffers which are awaiting fence signalling. + */ +struct fenced_buffer_list; + + +struct pb_fence_ops +{ + void (*destroy)( struct pb_fence_ops *ops ); + + /** Set ptr = fence, with reference counting */ + void (*fence_reference)( struct pb_fence_ops *ops, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence ); + + /** + * Checks whether the fence has been signalled. + * \param flags driver-specific meaning + * \return zero on success. + */ + int (*fence_signalled)( struct pb_fence_ops *ops, + struct pipe_fence_handle *fence, + unsigned flag ); + + /** + * Wait for the fence to finish. + * \param flags driver-specific meaning + * \return zero on success. + */ + int (*fence_finish)( struct pb_fence_ops *ops, + struct pipe_fence_handle *fence, + unsigned flag ); +}; + + +#ifdef __cplusplus +} +#endif + +#endif /*PB_BUFFER_FENCED_H_*/ diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c new file mode 100644 index 0000000..c2322ee --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c @@ -0,0 +1,189 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \file + * Implementation of malloc-based buffers to store data that can't be processed + * by the hardware. + * + * \author Jose Fonseca + */ + + +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "pb_buffer.h" +#include "pb_bufmgr.h" + + +struct malloc_buffer +{ + struct pb_buffer base; + void *data; +}; + + +extern const struct pb_vtbl malloc_buffer_vtbl; + +static INLINE struct malloc_buffer * +malloc_buffer(struct pb_buffer *buf) +{ + assert(buf); + if (!buf) + return NULL; + assert(buf->vtbl == &malloc_buffer_vtbl); + return (struct malloc_buffer *)buf; +} + + +static void +malloc_buffer_destroy(struct pb_buffer *buf) +{ + align_free(malloc_buffer(buf)->data); + FREE(buf); +} + + +static void * +malloc_buffer_map(struct pb_buffer *buf, + unsigned flags, + void *flush_ctx) +{ + return malloc_buffer(buf)->data; +} + + +static void +malloc_buffer_unmap(struct pb_buffer *buf) +{ + /* No-op */ +} + + +static enum pipe_error +malloc_buffer_validate(struct pb_buffer *buf, + struct pb_validate *vl, + unsigned flags) +{ + assert(0); + return PIPE_ERROR; +} + + +static void +malloc_buffer_fence(struct pb_buffer *buf, + struct pipe_fence_handle *fence) +{ + assert(0); +} + + +static void +malloc_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, + pb_size *offset) +{ + *base_buf = buf; + *offset = 0; +} + + +const struct pb_vtbl +malloc_buffer_vtbl = { + malloc_buffer_destroy, + malloc_buffer_map, + malloc_buffer_unmap, + malloc_buffer_validate, + malloc_buffer_fence, + malloc_buffer_get_base_buffer +}; + + +struct pb_buffer * +pb_malloc_buffer_create(pb_size size, + const struct pb_desc *desc) +{ + struct malloc_buffer *buf; + + /* TODO: do a single allocation */ + + buf = CALLOC_STRUCT(malloc_buffer); + if(!buf) + return NULL; + + pipe_reference_init(&buf->base.base.reference, 1); + buf->base.base.usage = desc->usage; + buf->base.base.size = size; + buf->base.base.alignment = desc->alignment; + buf->base.vtbl = &malloc_buffer_vtbl; + + buf->data = align_malloc(size, desc->alignment < sizeof(void*) ? sizeof(void*) : desc->alignment); + if(!buf->data) { + FREE(buf); + return NULL; + } + + return &buf->base; +} + + +static struct pb_buffer * +pb_malloc_bufmgr_create_buffer(struct pb_manager *mgr, + pb_size size, + const struct pb_desc *desc) +{ + return pb_malloc_buffer_create(size, desc); +} + + +static void +pb_malloc_bufmgr_flush(struct pb_manager *mgr) +{ + /* No-op */ +} + + +static void +pb_malloc_bufmgr_destroy(struct pb_manager *mgr) +{ + /* No-op */ +} + + +static struct pb_manager +pb_malloc_bufmgr = { + pb_malloc_bufmgr_destroy, + pb_malloc_bufmgr_create_buffer, + pb_malloc_bufmgr_flush +}; + + +struct pb_manager * +pb_malloc_bufmgr_create(void) +{ + return &pb_malloc_bufmgr; +} diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h b/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h new file mode 100644 index 0000000..2ef0216 --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h @@ -0,0 +1,214 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \file + * Buffer management. + * + * A buffer manager does only one basic thing: it creates buffers. Actually, + * "buffer factory" would probably a more accurate description. + * + * You can chain buffer managers so that you can have a finer grained memory + * management and pooling. + * + * For example, for a simple batch buffer manager you would chain: + * - the native buffer manager, which provides DMA memory from the graphics + * memory space; + * - the pool buffer manager, which keep around a pool of equally sized buffers + * to avoid latency associated with the native buffer manager; + * - the fenced buffer manager, which will delay buffer destruction until the + * the moment the card finishing processing it. + * + * \author Jose Fonseca + */ + +#ifndef PB_BUFMGR_H_ +#define PB_BUFMGR_H_ + + +#include "pb_buffer.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct pb_desc; + + +/** + * Abstract base class for all buffer managers. + */ +struct pb_manager +{ + void + (*destroy)( struct pb_manager *mgr ); + + struct pb_buffer * + (*create_buffer)( struct pb_manager *mgr, + pb_size size, + const struct pb_desc *desc); + + /** + * Flush all temporary-held buffers. + * + * Used mostly to aid debugging memory issues or to clean up resources when + * the drivers are long lived. + */ + void + (*flush)( struct pb_manager *mgr ); +}; + + +/** + * Malloc buffer provider. + * + * Simple wrapper around pb_malloc_buffer_create for convenience. + */ +struct pb_manager * +pb_malloc_bufmgr_create(void); + + +/** + * Static buffer pool sub-allocator. + * + * Manages the allocation of equally sized buffers. It does so by allocating + * a single big buffer and divide it equally sized buffers. + * + * It is meant to manage the allocation of batch buffer pools. + */ +struct pb_manager * +pool_bufmgr_create(struct pb_manager *provider, + pb_size n, pb_size size, + const struct pb_desc *desc); + + +/** + * Static sub-allocator based the old memory manager. + * + * It managers buffers of different sizes. It does so by allocating a buffer + * with the size of the heap, and then using the old mm memory manager to manage + * that heap. + */ +struct pb_manager * +mm_bufmgr_create(struct pb_manager *provider, + pb_size size, pb_size align2); + +/** + * Same as mm_bufmgr_create. + * + * Buffer will be release when the manager is destroyed. + */ +struct pb_manager * +mm_bufmgr_create_from_buffer(struct pb_buffer *buffer, + pb_size size, pb_size align2); + + +/** + * Slab sub-allocator. + */ +struct pb_manager * +pb_slab_manager_create(struct pb_manager *provider, + pb_size bufSize, + pb_size slabSize, + const struct pb_desc *desc); + +/** + * Allow a range of buffer size, by aggregating multiple slabs sub-allocators + * with different bucket sizes. + */ +struct pb_manager * +pb_slab_range_manager_create(struct pb_manager *provider, + pb_size minBufSize, + pb_size maxBufSize, + pb_size slabSize, + const struct pb_desc *desc); + + +/** + * Time-based buffer cache. + * + * This manager keeps a cache of destroyed buffers during a time interval. + */ +struct pb_manager * +pb_cache_manager_create(struct pb_manager *provider, + unsigned usecs); + + +struct pb_fence_ops; + +/** + * Fenced buffer manager. + * + * This manager is just meant for convenience. It wraps the buffers returned + * by another manager in fenced buffers, so that + * + * NOTE: the buffer manager that provides the buffers will be destroyed + * at the same time. + */ +struct pb_manager * +fenced_bufmgr_create(struct pb_manager *provider, + struct pb_fence_ops *ops, + pb_size max_buffer_size, + pb_size max_cpu_total_size); + + +struct pb_manager * +pb_alt_manager_create(struct pb_manager *provider1, + struct pb_manager *provider2); + + +/** + * Ondemand buffer manager. + * + * Buffers are created in malloc'ed memory (fast and cached), and the constents + * is transfered to a buffer from the provider (typically in slow uncached + * memory) when there is an attempt to validate the buffer. + * + * Ideal for situations where one does not know before hand whether a given + * buffer will effectively be used by the hardware or not. + */ +struct pb_manager * +pb_ondemand_manager_create(struct pb_manager *provider); + + +/** + * Debug buffer manager to detect buffer under- and overflows. + * + * Under/overflow sizes should be a multiple of the largest alignment + */ +struct pb_manager * +pb_debug_manager_create(struct pb_manager *provider, + pb_size underflow_size, pb_size overflow_size); + + +#ifdef __cplusplus +} +#endif + +#endif /*PB_BUFMGR_H_*/ diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_alt.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_alt.c new file mode 100644 index 0000000..f60c836 --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_alt.c @@ -0,0 +1,120 @@ +/************************************************************************** + * + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \file + * Allocate buffers from two alternative buffer providers. + * + * \author Jose Fonseca + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" +#include "util/u_memory.h" + +#include "pb_buffer.h" +#include "pb_bufmgr.h" + + +struct pb_alt_manager +{ + struct pb_manager base; + + struct pb_manager *provider1; + struct pb_manager *provider2; +}; + + +static INLINE struct pb_alt_manager * +pb_alt_manager(struct pb_manager *mgr) +{ + assert(mgr); + return (struct pb_alt_manager *)mgr; +} + + +static struct pb_buffer * +pb_alt_manager_create_buffer(struct pb_manager *_mgr, + pb_size size, + const struct pb_desc *desc) +{ + struct pb_alt_manager *mgr = pb_alt_manager(_mgr); + struct pb_buffer *buf; + + buf = mgr->provider1->create_buffer(mgr->provider1, size, desc); + if(buf) + return buf; + + buf = mgr->provider2->create_buffer(mgr->provider2, size, desc); + return buf; +} + + +static void +pb_alt_manager_flush(struct pb_manager *_mgr) +{ + struct pb_alt_manager *mgr = pb_alt_manager(_mgr); + + assert(mgr->provider1->flush); + if(mgr->provider1->flush) + mgr->provider1->flush(mgr->provider1); + + assert(mgr->provider2->flush); + if(mgr->provider2->flush) + mgr->provider2->flush(mgr->provider2); +} + + +static void +pb_alt_manager_destroy(struct pb_manager *mgr) +{ + FREE(mgr); +} + + +struct pb_manager * +pb_alt_manager_create(struct pb_manager *provider1, + struct pb_manager *provider2) +{ + struct pb_alt_manager *mgr; + + if(!provider1 || !provider2) + return NULL; + + mgr = CALLOC_STRUCT(pb_alt_manager); + if (!mgr) + return NULL; + + mgr->base.destroy = pb_alt_manager_destroy; + mgr->base.create_buffer = pb_alt_manager_create_buffer; + mgr->base.flush = pb_alt_manager_flush; + mgr->provider1 = provider1; + mgr->provider2 = provider2; + + return &mgr->base; +} diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c new file mode 100644 index 0000000..a6eb403 --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c @@ -0,0 +1,401 @@ +/************************************************************************** + * + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \file + * Buffer cache. + * + * \author Jose Fonseca + * \author Thomas Hellström + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" +#include "os/os_thread.h" +#include "util/u_memory.h" +#include "util/u_double_list.h" +#include "util/u_time.h" + +#include "pb_buffer.h" +#include "pb_bufmgr.h" + + +/** + * Convenience macro (type safe). + */ +#define SUPER(__derived) (&(__derived)->base) + + +struct pb_cache_manager; + + +/** + * Wrapper around a pipe buffer which adds delayed destruction. + */ +struct pb_cache_buffer +{ + struct pb_buffer base; + + struct pb_buffer *buffer; + struct pb_cache_manager *mgr; + + /** Caching time interval */ + int64_t start, end; + + struct list_head head; +}; + + +struct pb_cache_manager +{ + struct pb_manager base; + + struct pb_manager *provider; + unsigned usecs; + + pipe_mutex mutex; + + struct list_head delayed; + pb_size numDelayed; +}; + + +static INLINE struct pb_cache_buffer * +pb_cache_buffer(struct pb_buffer *buf) +{ + assert(buf); + return (struct pb_cache_buffer *)buf; +} + + +static INLINE struct pb_cache_manager * +pb_cache_manager(struct pb_manager *mgr) +{ + assert(mgr); + return (struct pb_cache_manager *)mgr; +} + + +/** + * Actually destroy the buffer. + */ +static INLINE void +_pb_cache_buffer_destroy(struct pb_cache_buffer *buf) +{ + struct pb_cache_manager *mgr = buf->mgr; + + LIST_DEL(&buf->head); + assert(mgr->numDelayed); + --mgr->numDelayed; + assert(!pipe_is_referenced(&buf->base.base.reference)); + pb_reference(&buf->buffer, NULL); + FREE(buf); +} + + +/** + * Free as many cache buffers from the list head as possible. + */ +static void +_pb_cache_buffer_list_check_free(struct pb_cache_manager *mgr) +{ + struct list_head *curr, *next; + struct pb_cache_buffer *buf; + int64_t now; + + now = os_time_get(); + + curr = mgr->delayed.next; + next = curr->next; + while(curr != &mgr->delayed) { + buf = LIST_ENTRY(struct pb_cache_buffer, curr, head); + + if(!os_time_timeout(buf->start, buf->end, now)) + break; + + _pb_cache_buffer_destroy(buf); + + curr = next; + next = curr->next; + } +} + + +static void +pb_cache_buffer_destroy(struct pb_buffer *_buf) +{ + struct pb_cache_buffer *buf = pb_cache_buffer(_buf); + struct pb_cache_manager *mgr = buf->mgr; + + pipe_mutex_lock(mgr->mutex); + assert(!pipe_is_referenced(&buf->base.base.reference)); + + _pb_cache_buffer_list_check_free(mgr); + + buf->start = os_time_get(); + buf->end = buf->start + mgr->usecs; + LIST_ADDTAIL(&buf->head, &mgr->delayed); + ++mgr->numDelayed; + pipe_mutex_unlock(mgr->mutex); +} + + +static void * +pb_cache_buffer_map(struct pb_buffer *_buf, + unsigned flags, void *flush_ctx) +{ + struct pb_cache_buffer *buf = pb_cache_buffer(_buf); + return pb_map(buf->buffer, flags, flush_ctx); +} + + +static void +pb_cache_buffer_unmap(struct pb_buffer *_buf) +{ + struct pb_cache_buffer *buf = pb_cache_buffer(_buf); + pb_unmap(buf->buffer); +} + + +static enum pipe_error +pb_cache_buffer_validate(struct pb_buffer *_buf, + struct pb_validate *vl, + unsigned flags) +{ + struct pb_cache_buffer *buf = pb_cache_buffer(_buf); + return pb_validate(buf->buffer, vl, flags); +} + + +static void +pb_cache_buffer_fence(struct pb_buffer *_buf, + struct pipe_fence_handle *fence) +{ + struct pb_cache_buffer *buf = pb_cache_buffer(_buf); + pb_fence(buf->buffer, fence); +} + + +static void +pb_cache_buffer_get_base_buffer(struct pb_buffer *_buf, + struct pb_buffer **base_buf, + pb_size *offset) +{ + struct pb_cache_buffer *buf = pb_cache_buffer(_buf); + pb_get_base_buffer(buf->buffer, base_buf, offset); +} + + +const struct pb_vtbl +pb_cache_buffer_vtbl = { + pb_cache_buffer_destroy, + pb_cache_buffer_map, + pb_cache_buffer_unmap, + pb_cache_buffer_validate, + pb_cache_buffer_fence, + pb_cache_buffer_get_base_buffer +}; + + +static INLINE int +pb_cache_is_buffer_compat(struct pb_cache_buffer *buf, + pb_size size, + const struct pb_desc *desc) +{ + void *map; + + if(buf->base.base.size < size) + return 0; + + /* be lenient with size */ + if(buf->base.base.size >= 2*size) + return 0; + + if(!pb_check_alignment(desc->alignment, buf->base.base.alignment)) + return 0; + + if(!pb_check_usage(desc->usage, buf->base.base.usage)) + return 0; + + map = pb_map(buf->buffer, PB_USAGE_DONTBLOCK, NULL); + if (!map) { + return -1; + } + + pb_unmap(buf->buffer); + + return 1; +} + + +static struct pb_buffer * +pb_cache_manager_create_buffer(struct pb_manager *_mgr, + pb_size size, + const struct pb_desc *desc) +{ + struct pb_cache_manager *mgr = pb_cache_manager(_mgr); + struct pb_cache_buffer *buf; + struct pb_cache_buffer *curr_buf; + struct list_head *curr, *next; + int64_t now; + int ret = 0; + + pipe_mutex_lock(mgr->mutex); + + buf = NULL; + curr = mgr->delayed.next; + next = curr->next; + + /* search in the expired buffers, freeing them in the process */ + now = os_time_get(); + while(curr != &mgr->delayed) { + curr_buf = LIST_ENTRY(struct pb_cache_buffer, curr, head); + if(!buf && (ret = pb_cache_is_buffer_compat(curr_buf, size, desc) > 0)) + buf = curr_buf; + else if(os_time_timeout(curr_buf->start, curr_buf->end, now)) + _pb_cache_buffer_destroy(curr_buf); + else + /* This buffer (and all hereafter) are still hot in cache */ + break; + if (ret == -1) + break; + curr = next; + next = curr->next; + } + + /* keep searching in the hot buffers */ + if(!buf && ret != -1) { + while(curr != &mgr->delayed) { + curr_buf = LIST_ENTRY(struct pb_cache_buffer, curr, head); + ret = pb_cache_is_buffer_compat(curr_buf, size, desc); + if (ret > 0) { + buf = curr_buf; + break; + } + if (ret == -1) + break; + /* no need to check the timeout here */ + curr = next; + next = curr->next; + } + } + + if(buf) { + LIST_DEL(&buf->head); + --mgr->numDelayed; + pipe_mutex_unlock(mgr->mutex); + /* Increase refcount */ + pipe_reference_init(&buf->base.base.reference, 1); + return &buf->base; + } + + pipe_mutex_unlock(mgr->mutex); + + buf = CALLOC_STRUCT(pb_cache_buffer); + if(!buf) + return NULL; + + buf->buffer = mgr->provider->create_buffer(mgr->provider, size, desc); + if(!buf->buffer) { + FREE(buf); + return NULL; + } + + assert(pipe_is_referenced(&buf->buffer->base.reference)); + assert(pb_check_alignment(desc->alignment, buf->buffer->base.alignment)); + assert(pb_check_usage(desc->usage, buf->buffer->base.usage)); + assert(buf->buffer->base.size >= size); + + pipe_reference_init(&buf->base.base.reference, 1); + buf->base.base.alignment = buf->buffer->base.alignment; + buf->base.base.usage = buf->buffer->base.usage; + buf->base.base.size = buf->buffer->base.size; + + buf->base.vtbl = &pb_cache_buffer_vtbl; + buf->mgr = mgr; + + return &buf->base; +} + + +static void +pb_cache_manager_flush(struct pb_manager *_mgr) +{ + struct pb_cache_manager *mgr = pb_cache_manager(_mgr); + struct list_head *curr, *next; + struct pb_cache_buffer *buf; + + pipe_mutex_lock(mgr->mutex); + curr = mgr->delayed.next; + next = curr->next; + while(curr != &mgr->delayed) { + buf = LIST_ENTRY(struct pb_cache_buffer, curr, head); + _pb_cache_buffer_destroy(buf); + curr = next; + next = curr->next; + } + pipe_mutex_unlock(mgr->mutex); + + assert(mgr->provider->flush); + if(mgr->provider->flush) + mgr->provider->flush(mgr->provider); +} + + +static void +pb_cache_manager_destroy(struct pb_manager *mgr) +{ + pb_cache_manager_flush(mgr); + FREE(mgr); +} + + +struct pb_manager * +pb_cache_manager_create(struct pb_manager *provider, + unsigned usecs) +{ + struct pb_cache_manager *mgr; + + if(!provider) + return NULL; + + mgr = CALLOC_STRUCT(pb_cache_manager); + if (!mgr) + return NULL; + + mgr->base.destroy = pb_cache_manager_destroy; + mgr->base.create_buffer = pb_cache_manager_create_buffer; + mgr->base.flush = pb_cache_manager_flush; + mgr->provider = provider; + mgr->usecs = usecs; + LIST_INITHEAD(&mgr->delayed); + mgr->numDelayed = 0; + pipe_mutex_init(mgr->mutex); + + return &mgr->base; +} diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c new file mode 100644 index 0000000..7604e75 --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c @@ -0,0 +1,499 @@ +/************************************************************************** + * + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \file + * Debug buffer manager to detect buffer under- and overflows. + * + * \author Jose Fonseca + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" +#include "os/os_thread.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_double_list.h" +#include "util/u_time.h" +#include "util/u_debug_stack.h" + +#include "pb_buffer.h" +#include "pb_bufmgr.h" + + +#ifdef DEBUG + + +#define PB_DEBUG_CREATE_BACKTRACE 8 +#define PB_DEBUG_MAP_BACKTRACE 8 + + +/** + * Convenience macro (type safe). + */ +#define SUPER(__derived) (&(__derived)->base) + + +struct pb_debug_manager; + + +/** + * Wrapper around a pipe buffer which adds delayed destruction. + */ +struct pb_debug_buffer +{ + struct pb_buffer base; + + struct pb_buffer *buffer; + struct pb_debug_manager *mgr; + + pb_size underflow_size; + pb_size overflow_size; + + struct debug_stack_frame create_backtrace[PB_DEBUG_CREATE_BACKTRACE]; + + pipe_mutex mutex; + unsigned map_count; + struct debug_stack_frame map_backtrace[PB_DEBUG_MAP_BACKTRACE]; + + struct list_head head; +}; + + +struct pb_debug_manager +{ + struct pb_manager base; + + struct pb_manager *provider; + + pb_size underflow_size; + pb_size overflow_size; + + pipe_mutex mutex; + struct list_head list; +}; + + +static INLINE struct pb_debug_buffer * +pb_debug_buffer(struct pb_buffer *buf) +{ + assert(buf); + return (struct pb_debug_buffer *)buf; +} + + +static INLINE struct pb_debug_manager * +pb_debug_manager(struct pb_manager *mgr) +{ + assert(mgr); + return (struct pb_debug_manager *)mgr; +} + + +static const uint8_t random_pattern[32] = { + 0xaf, 0xcf, 0xa5, 0xa2, 0xc2, 0x63, 0x15, 0x1a, + 0x7e, 0xe2, 0x7e, 0x84, 0x15, 0x49, 0xa2, 0x1e, + 0x49, 0x63, 0xf5, 0x52, 0x74, 0x66, 0x9e, 0xc4, + 0x6d, 0xcf, 0x2c, 0x4a, 0x74, 0xe6, 0xfd, 0x94 +}; + + +static INLINE void +fill_random_pattern(uint8_t *dst, pb_size size) +{ + pb_size i = 0; + while(size--) { + *dst++ = random_pattern[i++]; + i &= sizeof(random_pattern) - 1; + } +} + + +static INLINE boolean +check_random_pattern(const uint8_t *dst, pb_size size, + pb_size *min_ofs, pb_size *max_ofs) +{ + boolean result = TRUE; + pb_size i; + *min_ofs = size; + *max_ofs = 0; + for(i = 0; i < size; ++i) { + if(*dst++ != random_pattern[i % sizeof(random_pattern)]) { + *min_ofs = MIN2(*min_ofs, i); + *max_ofs = MAX2(*max_ofs, i); + result = FALSE; + } + } + return result; +} + + +static void +pb_debug_buffer_fill(struct pb_debug_buffer *buf) +{ + uint8_t *map; + + map = pb_map(buf->buffer, PB_USAGE_CPU_WRITE, NULL); + assert(map); + if(map) { + fill_random_pattern(map, buf->underflow_size); + fill_random_pattern(map + buf->underflow_size + buf->base.base.size, + buf->overflow_size); + pb_unmap(buf->buffer); + } +} + + +/** + * Check for under/over flows. + * + * Should be called with the buffer unmaped. + */ +static void +pb_debug_buffer_check(struct pb_debug_buffer *buf) +{ + uint8_t *map; + + map = pb_map(buf->buffer, + PB_USAGE_CPU_READ | + PB_USAGE_UNSYNCHRONIZED, NULL); + assert(map); + if(map) { + boolean underflow, overflow; + pb_size min_ofs, max_ofs; + + underflow = !check_random_pattern(map, buf->underflow_size, + &min_ofs, &max_ofs); + if(underflow) { + debug_printf("buffer underflow (offset -%u%s to -%u bytes) detected\n", + buf->underflow_size - min_ofs, + min_ofs == 0 ? "+" : "", + buf->underflow_size - max_ofs); + } + + overflow = !check_random_pattern(map + buf->underflow_size + buf->base.base.size, + buf->overflow_size, + &min_ofs, &max_ofs); + if(overflow) { + debug_printf("buffer overflow (size %u plus offset %u to %u%s bytes) detected\n", + buf->base.base.size, + min_ofs, + max_ofs, + max_ofs == buf->overflow_size - 1 ? "+" : ""); + } + + if(underflow || overflow) + debug_backtrace_dump(buf->create_backtrace, PB_DEBUG_CREATE_BACKTRACE); + + debug_assert(!underflow && !overflow); + + /* re-fill if not aborted */ + if(underflow) + fill_random_pattern(map, buf->underflow_size); + if(overflow) + fill_random_pattern(map + buf->underflow_size + buf->base.base.size, + buf->overflow_size); + + pb_unmap(buf->buffer); + } +} + + +static void +pb_debug_buffer_destroy(struct pb_buffer *_buf) +{ + struct pb_debug_buffer *buf = pb_debug_buffer(_buf); + struct pb_debug_manager *mgr = buf->mgr; + + assert(!pipe_is_referenced(&buf->base.base.reference)); + + pb_debug_buffer_check(buf); + + pipe_mutex_lock(mgr->mutex); + LIST_DEL(&buf->head); + pipe_mutex_unlock(mgr->mutex); + + pipe_mutex_destroy(buf->mutex); + + pb_reference(&buf->buffer, NULL); + FREE(buf); +} + + +static void * +pb_debug_buffer_map(struct pb_buffer *_buf, + unsigned flags, void *flush_ctx) +{ + struct pb_debug_buffer *buf = pb_debug_buffer(_buf); + void *map; + + pb_debug_buffer_check(buf); + + map = pb_map(buf->buffer, flags, flush_ctx); + if(!map) + return NULL; + + if(map) { + pipe_mutex_lock(buf->mutex); + ++buf->map_count; + debug_backtrace_capture(buf->map_backtrace, 1, PB_DEBUG_MAP_BACKTRACE); + pipe_mutex_unlock(buf->mutex); + } + + return (uint8_t *)map + buf->underflow_size; +} + + +static void +pb_debug_buffer_unmap(struct pb_buffer *_buf) +{ + struct pb_debug_buffer *buf = pb_debug_buffer(_buf); + + pipe_mutex_lock(buf->mutex); + assert(buf->map_count); + if(buf->map_count) + --buf->map_count; + pipe_mutex_unlock(buf->mutex); + + pb_unmap(buf->buffer); + + pb_debug_buffer_check(buf); +} + + +static void +pb_debug_buffer_get_base_buffer(struct pb_buffer *_buf, + struct pb_buffer **base_buf, + pb_size *offset) +{ + struct pb_debug_buffer *buf = pb_debug_buffer(_buf); + pb_get_base_buffer(buf->buffer, base_buf, offset); + *offset += buf->underflow_size; +} + + +static enum pipe_error +pb_debug_buffer_validate(struct pb_buffer *_buf, + struct pb_validate *vl, + unsigned flags) +{ + struct pb_debug_buffer *buf = pb_debug_buffer(_buf); + + pipe_mutex_lock(buf->mutex); + if(buf->map_count) { + debug_printf("%s: attempting to validate a mapped buffer\n", __FUNCTION__); + debug_printf("last map backtrace is\n"); + debug_backtrace_dump(buf->map_backtrace, PB_DEBUG_MAP_BACKTRACE); + } + pipe_mutex_unlock(buf->mutex); + + pb_debug_buffer_check(buf); + + return pb_validate(buf->buffer, vl, flags); +} + + +static void +pb_debug_buffer_fence(struct pb_buffer *_buf, + struct pipe_fence_handle *fence) +{ + struct pb_debug_buffer *buf = pb_debug_buffer(_buf); + pb_fence(buf->buffer, fence); +} + + +const struct pb_vtbl +pb_debug_buffer_vtbl = { + pb_debug_buffer_destroy, + pb_debug_buffer_map, + pb_debug_buffer_unmap, + pb_debug_buffer_validate, + pb_debug_buffer_fence, + pb_debug_buffer_get_base_buffer +}; + + +static void +pb_debug_manager_dump(struct pb_debug_manager *mgr) +{ + struct list_head *curr, *next; + struct pb_debug_buffer *buf; + + pipe_mutex_lock(mgr->mutex); + + curr = mgr->list.next; + next = curr->next; + while(curr != &mgr->list) { + buf = LIST_ENTRY(struct pb_debug_buffer, curr, head); + + debug_printf("buffer = %p\n", (void *) buf); + debug_printf(" .size = 0x%x\n", buf->base.base.size); + debug_backtrace_dump(buf->create_backtrace, PB_DEBUG_CREATE_BACKTRACE); + + curr = next; + next = curr->next; + } + + pipe_mutex_unlock(mgr->mutex); +} + + +static struct pb_buffer * +pb_debug_manager_create_buffer(struct pb_manager *_mgr, + pb_size size, + const struct pb_desc *desc) +{ + struct pb_debug_manager *mgr = pb_debug_manager(_mgr); + struct pb_debug_buffer *buf; + struct pb_desc real_desc; + pb_size real_size; + + assert(size); + assert(desc->alignment); + + buf = CALLOC_STRUCT(pb_debug_buffer); + if(!buf) + return NULL; + + real_size = mgr->underflow_size + size + mgr->overflow_size; + real_desc = *desc; + real_desc.usage |= PB_USAGE_CPU_WRITE; + real_desc.usage |= PB_USAGE_CPU_READ; + + buf->buffer = mgr->provider->create_buffer(mgr->provider, + real_size, + &real_desc); + if(!buf->buffer) { + FREE(buf); +#if 0 + pipe_mutex_lock(mgr->mutex); + debug_printf("%s: failed to create buffer\n", __FUNCTION__); + if(!LIST_IS_EMPTY(&mgr->list)) + pb_debug_manager_dump(mgr); + pipe_mutex_unlock(mgr->mutex); +#endif + return NULL; + } + + assert(pipe_is_referenced(&buf->buffer->base.reference)); + assert(pb_check_alignment(real_desc.alignment, buf->buffer->base.alignment)); + assert(pb_check_usage(real_desc.usage, buf->buffer->base.usage)); + assert(buf->buffer->base.size >= real_size); + + 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 = &pb_debug_buffer_vtbl; + buf->mgr = mgr; + + buf->underflow_size = mgr->underflow_size; + buf->overflow_size = buf->buffer->base.size - buf->underflow_size - size; + + debug_backtrace_capture(buf->create_backtrace, 1, PB_DEBUG_CREATE_BACKTRACE); + + pb_debug_buffer_fill(buf); + + pipe_mutex_init(buf->mutex); + + pipe_mutex_lock(mgr->mutex); + LIST_ADDTAIL(&buf->head, &mgr->list); + pipe_mutex_unlock(mgr->mutex); + + return &buf->base; +} + + +static void +pb_debug_manager_flush(struct pb_manager *_mgr) +{ + struct pb_debug_manager *mgr = pb_debug_manager(_mgr); + assert(mgr->provider->flush); + if(mgr->provider->flush) + mgr->provider->flush(mgr->provider); +} + + +static void +pb_debug_manager_destroy(struct pb_manager *_mgr) +{ + struct pb_debug_manager *mgr = pb_debug_manager(_mgr); + + pipe_mutex_lock(mgr->mutex); + if(!LIST_IS_EMPTY(&mgr->list)) { + debug_printf("%s: unfreed buffers\n", __FUNCTION__); + pb_debug_manager_dump(mgr); + } + pipe_mutex_unlock(mgr->mutex); + + pipe_mutex_destroy(mgr->mutex); + mgr->provider->destroy(mgr->provider); + FREE(mgr); +} + + +struct pb_manager * +pb_debug_manager_create(struct pb_manager *provider, + pb_size underflow_size, pb_size overflow_size) +{ + struct pb_debug_manager *mgr; + + if(!provider) + return NULL; + + mgr = CALLOC_STRUCT(pb_debug_manager); + if (!mgr) + return NULL; + + mgr->base.destroy = pb_debug_manager_destroy; + mgr->base.create_buffer = pb_debug_manager_create_buffer; + mgr->base.flush = pb_debug_manager_flush; + mgr->provider = provider; + mgr->underflow_size = underflow_size; + mgr->overflow_size = overflow_size; + + pipe_mutex_init(mgr->mutex); + LIST_INITHEAD(&mgr->list); + + return &mgr->base; +} + + +#else /* !DEBUG */ + + +struct pb_manager * +pb_debug_manager_create(struct pb_manager *provider, + pb_size underflow_size, pb_size overflow_size) +{ + return provider; +} + + +#endif /* !DEBUG */ diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c new file mode 100644 index 0000000..88da786 --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c @@ -0,0 +1,321 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \file + * Buffer manager using the old texture memory manager. + * + * \author Jose Fonseca + */ + + +#include "pipe/p_defines.h" +#include "util/u_debug.h" +#include "os/os_thread.h" +#include "util/u_memory.h" +#include "util/u_double_list.h" +#include "util/u_mm.h" +#include "pb_buffer.h" +#include "pb_bufmgr.h" + + +/** + * Convenience macro (type safe). + */ +#define SUPER(__derived) (&(__derived)->base) + + +struct mm_pb_manager +{ + struct pb_manager base; + + pipe_mutex mutex; + + pb_size size; + struct mem_block *heap; + + pb_size align2; + + struct pb_buffer *buffer; + void *map; +}; + + +static INLINE struct mm_pb_manager * +mm_pb_manager(struct pb_manager *mgr) +{ + assert(mgr); + return (struct mm_pb_manager *)mgr; +} + + +struct mm_buffer +{ + struct pb_buffer base; + + struct mm_pb_manager *mgr; + + struct mem_block *block; +}; + + +static INLINE struct mm_buffer * +mm_buffer(struct pb_buffer *buf) +{ + assert(buf); + return (struct mm_buffer *)buf; +} + + +static void +mm_buffer_destroy(struct pb_buffer *buf) +{ + struct mm_buffer *mm_buf = mm_buffer(buf); + struct mm_pb_manager *mm = mm_buf->mgr; + + assert(!pipe_is_referenced(&mm_buf->base.base.reference)); + + pipe_mutex_lock(mm->mutex); + u_mmFreeMem(mm_buf->block); + FREE(mm_buf); + pipe_mutex_unlock(mm->mutex); +} + + +static void * +mm_buffer_map(struct pb_buffer *buf, + unsigned flags, + void *flush_ctx) +{ + struct mm_buffer *mm_buf = mm_buffer(buf); + struct mm_pb_manager *mm = mm_buf->mgr; + + /* XXX: it will be necessary to remap here to propagate flush_ctx */ + + return (unsigned char *) mm->map + mm_buf->block->ofs; +} + + +static void +mm_buffer_unmap(struct pb_buffer *buf) +{ + /* No-op */ +} + + +static enum pipe_error +mm_buffer_validate(struct pb_buffer *buf, + struct pb_validate *vl, + unsigned flags) +{ + struct mm_buffer *mm_buf = mm_buffer(buf); + struct mm_pb_manager *mm = mm_buf->mgr; + return pb_validate(mm->buffer, vl, flags); +} + + +static void +mm_buffer_fence(struct pb_buffer *buf, + struct pipe_fence_handle *fence) +{ + struct mm_buffer *mm_buf = mm_buffer(buf); + struct mm_pb_manager *mm = mm_buf->mgr; + pb_fence(mm->buffer, fence); +} + + +static void +mm_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, + pb_size *offset) +{ + struct mm_buffer *mm_buf = mm_buffer(buf); + struct mm_pb_manager *mm = mm_buf->mgr; + pb_get_base_buffer(mm->buffer, base_buf, offset); + *offset += mm_buf->block->ofs; +} + + +static const struct pb_vtbl +mm_buffer_vtbl = { + mm_buffer_destroy, + mm_buffer_map, + mm_buffer_unmap, + mm_buffer_validate, + mm_buffer_fence, + mm_buffer_get_base_buffer +}; + + +static struct pb_buffer * +mm_bufmgr_create_buffer(struct pb_manager *mgr, + pb_size size, + const struct pb_desc *desc) +{ + struct mm_pb_manager *mm = mm_pb_manager(mgr); + struct mm_buffer *mm_buf; + + /* We don't handle alignments larger then the one initially setup */ + assert(pb_check_alignment(desc->alignment, (pb_size)1 << mm->align2)); + if(!pb_check_alignment(desc->alignment, (pb_size)1 << mm->align2)) + return NULL; + + pipe_mutex_lock(mm->mutex); + + mm_buf = CALLOC_STRUCT(mm_buffer); + if (!mm_buf) { + pipe_mutex_unlock(mm->mutex); + return NULL; + } + + pipe_reference_init(&mm_buf->base.base.reference, 1); + mm_buf->base.base.alignment = desc->alignment; + mm_buf->base.base.usage = desc->usage; + mm_buf->base.base.size = size; + + mm_buf->base.vtbl = &mm_buffer_vtbl; + + mm_buf->mgr = mm; + + mm_buf->block = u_mmAllocMem(mm->heap, (int)size, (int)mm->align2, 0); + if(!mm_buf->block) { +#if 0 + debug_printf("warning: heap full\n"); + mmDumpMemInfo(mm->heap); +#endif + FREE(mm_buf); + pipe_mutex_unlock(mm->mutex); + return NULL; + } + + /* Some sanity checks */ + assert(0 <= (pb_size)mm_buf->block->ofs && (pb_size)mm_buf->block->ofs < mm->size); + assert(size <= (pb_size)mm_buf->block->size && (pb_size)mm_buf->block->ofs + (pb_size)mm_buf->block->size <= mm->size); + + pipe_mutex_unlock(mm->mutex); + return SUPER(mm_buf); +} + + +static void +mm_bufmgr_flush(struct pb_manager *mgr) +{ + /* No-op */ +} + + +static void +mm_bufmgr_destroy(struct pb_manager *mgr) +{ + struct mm_pb_manager *mm = mm_pb_manager(mgr); + + pipe_mutex_lock(mm->mutex); + + u_mmDestroy(mm->heap); + + pb_unmap(mm->buffer); + pb_reference(&mm->buffer, NULL); + + pipe_mutex_unlock(mm->mutex); + + FREE(mgr); +} + + +struct pb_manager * +mm_bufmgr_create_from_buffer(struct pb_buffer *buffer, + pb_size size, pb_size align2) +{ + struct mm_pb_manager *mm; + + if(!buffer) + return NULL; + + mm = CALLOC_STRUCT(mm_pb_manager); + if (!mm) + return NULL; + + mm->base.destroy = mm_bufmgr_destroy; + mm->base.create_buffer = mm_bufmgr_create_buffer; + mm->base.flush = mm_bufmgr_flush; + + mm->size = size; + mm->align2 = align2; /* 64-byte alignment */ + + pipe_mutex_init(mm->mutex); + + mm->buffer = buffer; + + mm->map = pb_map(mm->buffer, + PB_USAGE_CPU_READ | + PB_USAGE_CPU_WRITE, NULL); + if(!mm->map) + goto failure; + + mm->heap = u_mmInit(0, (int)size); + if (!mm->heap) + goto failure; + + return SUPER(mm); + +failure: +if(mm->heap) + u_mmDestroy(mm->heap); + if(mm->map) + pb_unmap(mm->buffer); + if(mm) + FREE(mm); + return NULL; +} + + +struct pb_manager * +mm_bufmgr_create(struct pb_manager *provider, + pb_size size, pb_size align2) +{ + struct pb_buffer *buffer; + struct pb_manager *mgr; + struct pb_desc desc; + + if(!provider) + return NULL; + + memset(&desc, 0, sizeof(desc)); + desc.alignment = 1 << align2; + + buffer = provider->create_buffer(provider, size, &desc); + if (!buffer) + return NULL; + + mgr = mm_bufmgr_create_from_buffer(buffer, size, align2); + if (!mgr) { + pb_reference(&buffer, NULL); + return NULL; + } + + return mgr; +} diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c new file mode 100644 index 0000000..694a092 --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c @@ -0,0 +1,305 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * A variation of malloc buffers which get transferred to real graphics memory + * when there is an attempt to validate them. + * + * @author Jose Fonseca + */ + + +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "pb_buffer.h" +#include "pb_bufmgr.h" + + +struct pb_ondemand_manager; + + +struct pb_ondemand_buffer +{ + struct pb_buffer base; + + struct pb_ondemand_manager *mgr; + + /** Regular malloc'ed memory */ + void *data; + unsigned mapcount; + + /** Real buffer */ + struct pb_buffer *buffer; + pb_size size; + struct pb_desc desc; +}; + + +struct pb_ondemand_manager +{ + struct pb_manager base; + + struct pb_manager *provider; +}; + + +extern const struct pb_vtbl pb_ondemand_buffer_vtbl; + +static INLINE struct pb_ondemand_buffer * +pb_ondemand_buffer(struct pb_buffer *buf) +{ + assert(buf); + if (!buf) + return NULL; + assert(buf->vtbl == &pb_ondemand_buffer_vtbl); + return (struct pb_ondemand_buffer *)buf; +} + +static INLINE struct pb_ondemand_manager * +pb_ondemand_manager(struct pb_manager *mgr) +{ + assert(mgr); + return (struct pb_ondemand_manager *)mgr; +} + + +static void +pb_ondemand_buffer_destroy(struct pb_buffer *_buf) +{ + struct pb_ondemand_buffer *buf = pb_ondemand_buffer(_buf); + + pb_reference(&buf->buffer, NULL); + + align_free(buf->data); + + FREE(buf); +} + + +static void * +pb_ondemand_buffer_map(struct pb_buffer *_buf, + unsigned flags, void *flush_ctx) +{ + struct pb_ondemand_buffer *buf = pb_ondemand_buffer(_buf); + + if(buf->buffer) { + assert(!buf->data); + return pb_map(buf->buffer, flags, flush_ctx); + } + else { + assert(buf->data); + ++buf->mapcount; + return buf->data; + } +} + + +static void +pb_ondemand_buffer_unmap(struct pb_buffer *_buf) +{ + struct pb_ondemand_buffer *buf = pb_ondemand_buffer(_buf); + + if(buf->buffer) { + assert(!buf->data); + pb_unmap(buf->buffer); + } + else { + assert(buf->data); + assert(buf->mapcount); + if(buf->mapcount) + --buf->mapcount; + } +} + + +static enum pipe_error +pb_ondemand_buffer_instantiate(struct pb_ondemand_buffer *buf) +{ + if(!buf->buffer) { + struct pb_manager *provider = buf->mgr->provider; + uint8_t *map; + + assert(!buf->mapcount); + + buf->buffer = provider->create_buffer(provider, buf->size, &buf->desc); + if(!buf->buffer) + return PIPE_ERROR_OUT_OF_MEMORY; + + map = pb_map(buf->buffer, PB_USAGE_CPU_READ, NULL); + if(!map) { + pb_reference(&buf->buffer, NULL); + return PIPE_ERROR; + } + + memcpy(map, buf->data, buf->size); + + pb_unmap(buf->buffer); + + if(!buf->mapcount) { + FREE(buf->data); + buf->data = NULL; + } + } + + return PIPE_OK; +} + +static enum pipe_error +pb_ondemand_buffer_validate(struct pb_buffer *_buf, + struct pb_validate *vl, + unsigned flags) +{ + struct pb_ondemand_buffer *buf = pb_ondemand_buffer(_buf); + enum pipe_error ret; + + assert(!buf->mapcount); + if(buf->mapcount) + return PIPE_ERROR; + + ret = pb_ondemand_buffer_instantiate(buf); + if(ret != PIPE_OK) + return ret; + + return pb_validate(buf->buffer, vl, flags); +} + + +static void +pb_ondemand_buffer_fence(struct pb_buffer *_buf, + struct pipe_fence_handle *fence) +{ + struct pb_ondemand_buffer *buf = pb_ondemand_buffer(_buf); + + assert(buf->buffer); + if(!buf->buffer) + return; + + pb_fence(buf->buffer, fence); +} + + +static void +pb_ondemand_buffer_get_base_buffer(struct pb_buffer *_buf, + struct pb_buffer **base_buf, + pb_size *offset) +{ + struct pb_ondemand_buffer *buf = pb_ondemand_buffer(_buf); + + if(pb_ondemand_buffer_instantiate(buf) != PIPE_OK) { + assert(0); + *base_buf = &buf->base; + *offset = 0; + return; + } + + pb_get_base_buffer(buf->buffer, base_buf, offset); +} + + +const struct pb_vtbl +pb_ondemand_buffer_vtbl = { + pb_ondemand_buffer_destroy, + pb_ondemand_buffer_map, + pb_ondemand_buffer_unmap, + pb_ondemand_buffer_validate, + pb_ondemand_buffer_fence, + pb_ondemand_buffer_get_base_buffer +}; + + +static struct pb_buffer * +pb_ondemand_manager_create_buffer(struct pb_manager *_mgr, + pb_size size, + const struct pb_desc *desc) +{ + struct pb_ondemand_manager *mgr = pb_ondemand_manager(_mgr); + struct pb_ondemand_buffer *buf; + + buf = CALLOC_STRUCT(pb_ondemand_buffer); + if(!buf) + return NULL; + + 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 = &pb_ondemand_buffer_vtbl; + + buf->mgr = mgr; + + buf->data = align_malloc(size, desc->alignment < sizeof(void*) ? sizeof(void*) : desc->alignment); + if(!buf->data) { + FREE(buf); + return NULL; + } + + buf->size = size; + buf->desc = *desc; + + return &buf->base; +} + + +static void +pb_ondemand_manager_flush(struct pb_manager *_mgr) +{ + struct pb_ondemand_manager *mgr = pb_ondemand_manager(_mgr); + + mgr->provider->flush(mgr->provider); +} + + +static void +pb_ondemand_manager_destroy(struct pb_manager *_mgr) +{ + struct pb_ondemand_manager *mgr = pb_ondemand_manager(_mgr); + + FREE(mgr); +} + + +struct pb_manager * +pb_ondemand_manager_create(struct pb_manager *provider) +{ + struct pb_ondemand_manager *mgr; + + if(!provider) + return NULL; + + mgr = CALLOC_STRUCT(pb_ondemand_manager); + if(!mgr) + return NULL; + + mgr->base.destroy = pb_ondemand_manager_destroy; + mgr->base.create_buffer = pb_ondemand_manager_create_buffer; + mgr->base.flush = pb_ondemand_manager_flush; + + mgr->provider = provider; + + return &mgr->base; +} diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c new file mode 100644 index 0000000..2f7c738 --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c @@ -0,0 +1,323 @@ +/************************************************************************** + * + * Copyright 2006 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. + * + * + **************************************************************************/ + +/** + * \file + * Batch buffer pool management. + * + * \author Jose Fonseca + * \author Thomas Hellström + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" +#include "os/os_thread.h" +#include "pipe/p_defines.h" +#include "util/u_memory.h" +#include "util/u_double_list.h" + +#include "pb_buffer.h" +#include "pb_bufmgr.h" + + +/** + * Convenience macro (type safe). + */ +#define SUPER(__derived) (&(__derived)->base) + + +struct pool_pb_manager +{ + struct pb_manager base; + + pipe_mutex mutex; + + pb_size bufSize; + pb_size bufAlign; + + pb_size numFree; + pb_size numTot; + + struct list_head free; + + struct pb_buffer *buffer; + void *map; + + struct pool_buffer *bufs; +}; + + +static INLINE struct pool_pb_manager * +pool_pb_manager(struct pb_manager *mgr) +{ + assert(mgr); + return (struct pool_pb_manager *)mgr; +} + + +struct pool_buffer +{ + struct pb_buffer base; + + struct pool_pb_manager *mgr; + + struct list_head head; + + pb_size start; +}; + + +static INLINE struct pool_buffer * +pool_buffer(struct pb_buffer *buf) +{ + assert(buf); + return (struct pool_buffer *)buf; +} + + + +static void +pool_buffer_destroy(struct pb_buffer *buf) +{ + struct pool_buffer *pool_buf = pool_buffer(buf); + struct pool_pb_manager *pool = pool_buf->mgr; + + assert(!pipe_is_referenced(&pool_buf->base.base.reference)); + + pipe_mutex_lock(pool->mutex); + LIST_ADD(&pool_buf->head, &pool->free); + pool->numFree++; + pipe_mutex_unlock(pool->mutex); +} + + +static void * +pool_buffer_map(struct pb_buffer *buf, unsigned flags, void *flush_ctx) +{ + struct pool_buffer *pool_buf = pool_buffer(buf); + struct pool_pb_manager *pool = pool_buf->mgr; + void *map; + + /* XXX: it will be necessary to remap here to propagate flush_ctx */ + + pipe_mutex_lock(pool->mutex); + map = (unsigned char *) pool->map + pool_buf->start; + pipe_mutex_unlock(pool->mutex); + return map; +} + + +static void +pool_buffer_unmap(struct pb_buffer *buf) +{ + /* No-op */ +} + + +static enum pipe_error +pool_buffer_validate(struct pb_buffer *buf, + struct pb_validate *vl, + unsigned flags) +{ + struct pool_buffer *pool_buf = pool_buffer(buf); + struct pool_pb_manager *pool = pool_buf->mgr; + return pb_validate(pool->buffer, vl, flags); +} + + +static void +pool_buffer_fence(struct pb_buffer *buf, + struct pipe_fence_handle *fence) +{ + struct pool_buffer *pool_buf = pool_buffer(buf); + struct pool_pb_manager *pool = pool_buf->mgr; + pb_fence(pool->buffer, fence); +} + + +static void +pool_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, + pb_size *offset) +{ + struct pool_buffer *pool_buf = pool_buffer(buf); + struct pool_pb_manager *pool = pool_buf->mgr; + pb_get_base_buffer(pool->buffer, base_buf, offset); + *offset += pool_buf->start; +} + + +static const struct pb_vtbl +pool_buffer_vtbl = { + pool_buffer_destroy, + pool_buffer_map, + pool_buffer_unmap, + pool_buffer_validate, + pool_buffer_fence, + pool_buffer_get_base_buffer +}; + + +static struct pb_buffer * +pool_bufmgr_create_buffer(struct pb_manager *mgr, + pb_size size, + const struct pb_desc *desc) +{ + struct pool_pb_manager *pool = pool_pb_manager(mgr); + struct pool_buffer *pool_buf; + struct list_head *item; + + assert(size == pool->bufSize); + assert(pool->bufAlign % desc->alignment == 0); + + pipe_mutex_lock(pool->mutex); + + if (pool->numFree == 0) { + pipe_mutex_unlock(pool->mutex); + debug_printf("warning: out of fixed size buffer objects\n"); + return NULL; + } + + item = pool->free.next; + + if (item == &pool->free) { + pipe_mutex_unlock(pool->mutex); + debug_printf("error: fixed size buffer pool corruption\n"); + return NULL; + } + + LIST_DEL(item); + --pool->numFree; + + pipe_mutex_unlock(pool->mutex); + + pool_buf = LIST_ENTRY(struct pool_buffer, item, head); + assert(!pipe_is_referenced(&pool_buf->base.base.reference)); + pipe_reference_init(&pool_buf->base.base.reference, 1); + pool_buf->base.base.alignment = desc->alignment; + pool_buf->base.base.usage = desc->usage; + + return SUPER(pool_buf); +} + + +static void +pool_bufmgr_flush(struct pb_manager *mgr) +{ + /* No-op */ +} + + +static void +pool_bufmgr_destroy(struct pb_manager *mgr) +{ + struct pool_pb_manager *pool = pool_pb_manager(mgr); + pipe_mutex_lock(pool->mutex); + + FREE(pool->bufs); + + pb_unmap(pool->buffer); + pb_reference(&pool->buffer, NULL); + + pipe_mutex_unlock(pool->mutex); + + FREE(mgr); +} + + +struct pb_manager * +pool_bufmgr_create(struct pb_manager *provider, + pb_size numBufs, + pb_size bufSize, + const struct pb_desc *desc) +{ + struct pool_pb_manager *pool; + struct pool_buffer *pool_buf; + pb_size i; + + if(!provider) + return NULL; + + pool = CALLOC_STRUCT(pool_pb_manager); + if (!pool) + return NULL; + + pool->base.destroy = pool_bufmgr_destroy; + pool->base.create_buffer = pool_bufmgr_create_buffer; + pool->base.flush = pool_bufmgr_flush; + + LIST_INITHEAD(&pool->free); + + pool->numTot = numBufs; + pool->numFree = numBufs; + pool->bufSize = bufSize; + pool->bufAlign = desc->alignment; + + pipe_mutex_init(pool->mutex); + + pool->buffer = provider->create_buffer(provider, numBufs*bufSize, desc); + if (!pool->buffer) + goto failure; + + pool->map = pb_map(pool->buffer, + PB_USAGE_CPU_READ | + PB_USAGE_CPU_WRITE, NULL); + if(!pool->map) + goto failure; + + pool->bufs = (struct pool_buffer *)CALLOC(numBufs, sizeof(*pool->bufs)); + if (!pool->bufs) + goto failure; + + pool_buf = pool->bufs; + for (i = 0; i < numBufs; ++i) { + pipe_reference_init(&pool_buf->base.base.reference, 0); + pool_buf->base.base.alignment = 0; + pool_buf->base.base.usage = 0; + pool_buf->base.base.size = bufSize; + pool_buf->base.vtbl = &pool_buffer_vtbl; + pool_buf->mgr = pool; + pool_buf->start = i * bufSize; + LIST_ADDTAIL(&pool_buf->head, &pool->free); + pool_buf++; + } + + return SUPER(pool); + +failure: + if(pool->bufs) + FREE(pool->bufs); + if(pool->map) + pb_unmap(pool->buffer); + if(pool->buffer) + pb_reference(&pool->buffer, NULL); + if(pool) + FREE(pool); + return NULL; +} diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c new file mode 100644 index 0000000..176f9aa --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c @@ -0,0 +1,590 @@ +/************************************************************************** + * + * Copyright 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., 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. + * + * + **************************************************************************/ + +/** + * @file + * S-lab pool implementation. + * + * @sa http://en.wikipedia.org/wiki/Slab_allocation + * + * @author Thomas Hellstrom + * @author Jose Fonseca + */ + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" +#include "os/os_thread.h" +#include "pipe/p_defines.h" +#include "util/u_memory.h" +#include "util/u_double_list.h" +#include "util/u_time.h" + +#include "pb_buffer.h" +#include "pb_bufmgr.h" + + +struct pb_slab; + + +/** + * Buffer in a slab. + * + * Sub-allocation of a contiguous buffer. + */ +struct pb_slab_buffer +{ + struct pb_buffer base; + + struct pb_slab *slab; + + struct list_head head; + + unsigned mapCount; + + /** Offset relative to the start of the slab buffer. */ + pb_size start; + + /** Use when validating, to signal that all mappings are finished */ + /* TODO: Actually validation does not reach this stage yet */ + pipe_condvar event; +}; + + +/** + * Slab -- a contiguous piece of memory. + */ +struct pb_slab +{ + struct list_head head; + struct list_head freeBuffers; + pb_size numBuffers; + pb_size numFree; + + struct pb_slab_buffer *buffers; + struct pb_slab_manager *mgr; + + /** Buffer from the provider */ + struct pb_buffer *bo; + + void *virtual; +}; + + +/** + * It adds/removes slabs as needed in order to meet the allocation/destruction + * of individual buffers. + */ +struct pb_slab_manager +{ + struct pb_manager base; + + /** From where we get our buffers */ + struct pb_manager *provider; + + /** Size of the buffers we hand on downstream */ + pb_size bufSize; + + /** Size of the buffers we request upstream */ + pb_size slabSize; + + /** + * Alignment, usage to be used to allocate the slab buffers. + * + * We can only provide buffers which are consistent (in alignment, usage) + * with this description. + */ + struct pb_desc desc; + + /** + * Partial slabs + * + * Full slabs are not stored in any list. Empty slabs are destroyed + * immediatly. + */ + struct list_head slabs; + + pipe_mutex mutex; +}; + + +/** + * Wrapper around several slabs, therefore capable of handling buffers of + * multiple sizes. + * + * This buffer manager just dispatches buffer allocations to the appropriate slab + * manager, according to the requested buffer size, or by passes the slab + * managers altogether for even greater sizes. + * + * The data of this structure remains constant after + * initialization and thus needs no mutex protection. + */ +struct pb_slab_range_manager +{ + struct pb_manager base; + + struct pb_manager *provider; + + pb_size minBufSize; + pb_size maxBufSize; + + /** @sa pb_slab_manager::desc */ + struct pb_desc desc; + + unsigned numBuckets; + pb_size *bucketSizes; + + /** Array of pb_slab_manager, one for each bucket size */ + struct pb_manager **buckets; +}; + + +static INLINE struct pb_slab_buffer * +pb_slab_buffer(struct pb_buffer *buf) +{ + assert(buf); + return (struct pb_slab_buffer *)buf; +} + + +static INLINE struct pb_slab_manager * +pb_slab_manager(struct pb_manager *mgr) +{ + assert(mgr); + return (struct pb_slab_manager *)mgr; +} + + +static INLINE struct pb_slab_range_manager * +pb_slab_range_manager(struct pb_manager *mgr) +{ + assert(mgr); + return (struct pb_slab_range_manager *)mgr; +} + + +/** + * Delete a buffer from the slab delayed list and put + * it on the slab FREE list. + */ +static void +pb_slab_buffer_destroy(struct pb_buffer *_buf) +{ + struct pb_slab_buffer *buf = pb_slab_buffer(_buf); + struct pb_slab *slab = buf->slab; + struct pb_slab_manager *mgr = slab->mgr; + struct list_head *list = &buf->head; + + pipe_mutex_lock(mgr->mutex); + + assert(!pipe_is_referenced(&buf->base.base.reference)); + + buf->mapCount = 0; + + LIST_DEL(list); + LIST_ADDTAIL(list, &slab->freeBuffers); + slab->numFree++; + + if (slab->head.next == &slab->head) + LIST_ADDTAIL(&slab->head, &mgr->slabs); + + /* If the slab becomes totally empty, free it */ + if (slab->numFree == slab->numBuffers) { + list = &slab->head; + LIST_DELINIT(list); + pb_reference(&slab->bo, NULL); + FREE(slab->buffers); + FREE(slab); + } + + pipe_mutex_unlock(mgr->mutex); +} + + +static void * +pb_slab_buffer_map(struct pb_buffer *_buf, + unsigned flags, + void *flush_ctx) +{ + struct pb_slab_buffer *buf = pb_slab_buffer(_buf); + + /* XXX: it will be necessary to remap here to propagate flush_ctx */ + + ++buf->mapCount; + return (void *) ((uint8_t *) buf->slab->virtual + buf->start); +} + + +static void +pb_slab_buffer_unmap(struct pb_buffer *_buf) +{ + struct pb_slab_buffer *buf = pb_slab_buffer(_buf); + + --buf->mapCount; + if (buf->mapCount == 0) + pipe_condvar_broadcast(buf->event); +} + + +static enum pipe_error +pb_slab_buffer_validate(struct pb_buffer *_buf, + struct pb_validate *vl, + unsigned flags) +{ + struct pb_slab_buffer *buf = pb_slab_buffer(_buf); + return pb_validate(buf->slab->bo, vl, flags); +} + + +static void +pb_slab_buffer_fence(struct pb_buffer *_buf, + struct pipe_fence_handle *fence) +{ + struct pb_slab_buffer *buf = pb_slab_buffer(_buf); + pb_fence(buf->slab->bo, fence); +} + + +static void +pb_slab_buffer_get_base_buffer(struct pb_buffer *_buf, + struct pb_buffer **base_buf, + pb_size *offset) +{ + struct pb_slab_buffer *buf = pb_slab_buffer(_buf); + pb_get_base_buffer(buf->slab->bo, base_buf, offset); + *offset += buf->start; +} + + +static const struct pb_vtbl +pb_slab_buffer_vtbl = { + pb_slab_buffer_destroy, + pb_slab_buffer_map, + pb_slab_buffer_unmap, + pb_slab_buffer_validate, + pb_slab_buffer_fence, + pb_slab_buffer_get_base_buffer +}; + + +/** + * Create a new slab. + * + * Called when we ran out of free slabs. + */ +static enum pipe_error +pb_slab_create(struct pb_slab_manager *mgr) +{ + struct pb_slab *slab; + struct pb_slab_buffer *buf; + unsigned numBuffers; + unsigned i; + enum pipe_error ret; + + slab = CALLOC_STRUCT(pb_slab); + if (!slab) + return PIPE_ERROR_OUT_OF_MEMORY; + + slab->bo = mgr->provider->create_buffer(mgr->provider, mgr->slabSize, &mgr->desc); + if(!slab->bo) { + ret = PIPE_ERROR_OUT_OF_MEMORY; + goto out_err0; + } + + /* Note down the slab virtual address. All mappings are accessed directly + * through this address so it is required that the buffer is pinned. */ + slab->virtual = pb_map(slab->bo, + PB_USAGE_CPU_READ | + PB_USAGE_CPU_WRITE, NULL); + if(!slab->virtual) { + ret = PIPE_ERROR_OUT_OF_MEMORY; + goto out_err1; + } + pb_unmap(slab->bo); + + numBuffers = slab->bo->base.size / mgr->bufSize; + + slab->buffers = CALLOC(numBuffers, sizeof(*slab->buffers)); + if (!slab->buffers) { + ret = PIPE_ERROR_OUT_OF_MEMORY; + goto out_err1; + } + + LIST_INITHEAD(&slab->head); + LIST_INITHEAD(&slab->freeBuffers); + slab->numBuffers = numBuffers; + slab->numFree = 0; + slab->mgr = mgr; + + buf = slab->buffers; + for (i=0; i < numBuffers; ++i) { + pipe_reference_init(&buf->base.base.reference, 0); + buf->base.base.size = mgr->bufSize; + buf->base.base.alignment = 0; + buf->base.base.usage = 0; + buf->base.vtbl = &pb_slab_buffer_vtbl; + buf->slab = slab; + buf->start = i* mgr->bufSize; + buf->mapCount = 0; + pipe_condvar_init(buf->event); + LIST_ADDTAIL(&buf->head, &slab->freeBuffers); + slab->numFree++; + buf++; + } + + /* Add this slab to the list of partial slabs */ + LIST_ADDTAIL(&slab->head, &mgr->slabs); + + return PIPE_OK; + +out_err1: + pb_reference(&slab->bo, NULL); +out_err0: + FREE(slab); + return ret; +} + + +static struct pb_buffer * +pb_slab_manager_create_buffer(struct pb_manager *_mgr, + pb_size size, + const struct pb_desc *desc) +{ + struct pb_slab_manager *mgr = pb_slab_manager(_mgr); + static struct pb_slab_buffer *buf; + struct pb_slab *slab; + struct list_head *list; + + /* check size */ + assert(size <= mgr->bufSize); + if(size > mgr->bufSize) + return NULL; + + /* check if we can provide the requested alignment */ + assert(pb_check_alignment(desc->alignment, mgr->desc.alignment)); + if(!pb_check_alignment(desc->alignment, mgr->desc.alignment)) + return NULL; + assert(pb_check_alignment(desc->alignment, mgr->bufSize)); + if(!pb_check_alignment(desc->alignment, mgr->bufSize)) + return NULL; + + assert(pb_check_usage(desc->usage, mgr->desc.usage)); + if(!pb_check_usage(desc->usage, mgr->desc.usage)) + return NULL; + + pipe_mutex_lock(mgr->mutex); + + /* Create a new slab, if we run out of partial slabs */ + if (mgr->slabs.next == &mgr->slabs) { + (void) pb_slab_create(mgr); + if (mgr->slabs.next == &mgr->slabs) { + pipe_mutex_unlock(mgr->mutex); + return NULL; + } + } + + /* Allocate the buffer from a partial (or just created) slab */ + list = mgr->slabs.next; + slab = LIST_ENTRY(struct pb_slab, list, head); + + /* If totally full remove from the partial slab list */ + if (--slab->numFree == 0) + LIST_DELINIT(list); + + list = slab->freeBuffers.next; + LIST_DELINIT(list); + + pipe_mutex_unlock(mgr->mutex); + buf = LIST_ENTRY(struct pb_slab_buffer, list, head); + + pipe_reference_init(&buf->base.base.reference, 1); + buf->base.base.alignment = desc->alignment; + buf->base.base.usage = desc->usage; + + return &buf->base; +} + + +static void +pb_slab_manager_flush(struct pb_manager *_mgr) +{ + struct pb_slab_manager *mgr = pb_slab_manager(_mgr); + + assert(mgr->provider->flush); + if(mgr->provider->flush) + mgr->provider->flush(mgr->provider); +} + + +static void +pb_slab_manager_destroy(struct pb_manager *_mgr) +{ + struct pb_slab_manager *mgr = pb_slab_manager(_mgr); + + /* TODO: cleanup all allocated buffers */ + FREE(mgr); +} + + +struct pb_manager * +pb_slab_manager_create(struct pb_manager *provider, + pb_size bufSize, + pb_size slabSize, + const struct pb_desc *desc) +{ + struct pb_slab_manager *mgr; + + mgr = CALLOC_STRUCT(pb_slab_manager); + if (!mgr) + return NULL; + + mgr->base.destroy = pb_slab_manager_destroy; + mgr->base.create_buffer = pb_slab_manager_create_buffer; + mgr->base.flush = pb_slab_manager_flush; + + mgr->provider = provider; + mgr->bufSize = bufSize; + mgr->slabSize = slabSize; + mgr->desc = *desc; + + LIST_INITHEAD(&mgr->slabs); + + pipe_mutex_init(mgr->mutex); + + return &mgr->base; +} + + +static struct pb_buffer * +pb_slab_range_manager_create_buffer(struct pb_manager *_mgr, + pb_size size, + const struct pb_desc *desc) +{ + struct pb_slab_range_manager *mgr = pb_slab_range_manager(_mgr); + pb_size bufSize; + pb_size reqSize = size; + unsigned i; + + if(desc->alignment > reqSize) + reqSize = desc->alignment; + + bufSize = mgr->minBufSize; + for (i = 0; i < mgr->numBuckets; ++i) { + if(bufSize >= reqSize) + return mgr->buckets[i]->create_buffer(mgr->buckets[i], size, desc); + bufSize *= 2; + } + + /* Fall back to allocate a buffer object directly from the provider. */ + return mgr->provider->create_buffer(mgr->provider, size, desc); +} + + +static void +pb_slab_range_manager_flush(struct pb_manager *_mgr) +{ + struct pb_slab_range_manager *mgr = pb_slab_range_manager(_mgr); + + /* Individual slabs don't hold any temporary buffers so no need to call them */ + + assert(mgr->provider->flush); + if(mgr->provider->flush) + mgr->provider->flush(mgr->provider); +} + + +static void +pb_slab_range_manager_destroy(struct pb_manager *_mgr) +{ + struct pb_slab_range_manager *mgr = pb_slab_range_manager(_mgr); + unsigned i; + + for (i = 0; i < mgr->numBuckets; ++i) + mgr->buckets[i]->destroy(mgr->buckets[i]); + FREE(mgr->buckets); + FREE(mgr->bucketSizes); + FREE(mgr); +} + + +struct pb_manager * +pb_slab_range_manager_create(struct pb_manager *provider, + pb_size minBufSize, + pb_size maxBufSize, + pb_size slabSize, + const struct pb_desc *desc) +{ + struct pb_slab_range_manager *mgr; + pb_size bufSize; + unsigned i; + + if(!provider) + return NULL; + + mgr = CALLOC_STRUCT(pb_slab_range_manager); + if (!mgr) + goto out_err0; + + mgr->base.destroy = pb_slab_range_manager_destroy; + mgr->base.create_buffer = pb_slab_range_manager_create_buffer; + mgr->base.flush = pb_slab_range_manager_flush; + + mgr->provider = provider; + mgr->minBufSize = minBufSize; + mgr->maxBufSize = maxBufSize; + + mgr->numBuckets = 1; + bufSize = minBufSize; + while(bufSize < maxBufSize) { + bufSize *= 2; + ++mgr->numBuckets; + } + + mgr->buckets = CALLOC(mgr->numBuckets, sizeof(*mgr->buckets)); + if (!mgr->buckets) + goto out_err1; + + bufSize = minBufSize; + for (i = 0; i < mgr->numBuckets; ++i) { + mgr->buckets[i] = pb_slab_manager_create(provider, bufSize, slabSize, desc); + if(!mgr->buckets[i]) + goto out_err2; + bufSize *= 2; + } + + return &mgr->base; + +out_err2: + for (i = 0; i < mgr->numBuckets; ++i) + if(mgr->buckets[i]) + mgr->buckets[i]->destroy(mgr->buckets[i]); + FREE(mgr->buckets); +out_err1: + FREE(mgr); +out_err0: + return NULL; +} diff --git a/src/gallium/auxiliary/pipebuffer/pb_validate.c b/src/gallium/auxiliary/pipebuffer/pb_validate.c new file mode 100644 index 0000000..b585422 --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/pb_validate.c @@ -0,0 +1,192 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Buffer validation. + * + * @author Jose Fonseca + */ + + +#include "pipe/p_compiler.h" +#include "pipe/p_defines.h" +#include "util/u_memory.h" +#include "util/u_debug.h" + +#include "pb_buffer.h" +#include "pb_validate.h" + + +#define PB_VALIDATE_INITIAL_SIZE 1 /* 512 */ + + +struct pb_validate_entry +{ + struct pb_buffer *buf; + unsigned flags; +}; + + +struct pb_validate +{ + struct pb_validate_entry *entries; + unsigned used; + unsigned size; +}; + + +enum pipe_error +pb_validate_add_buffer(struct pb_validate *vl, + struct pb_buffer *buf, + unsigned flags) +{ + assert(buf); + if(!buf) + return PIPE_ERROR; + + assert(flags & PB_USAGE_GPU_READ_WRITE); + assert(!(flags & ~PB_USAGE_GPU_READ_WRITE)); + flags &= PB_USAGE_GPU_READ_WRITE; + + /* We only need to store one reference for each buffer, so avoid storing + * consecutive references for the same buffer. It might not be the most + * common pattern, but it is easy to implement. + */ + if(vl->used && vl->entries[vl->used - 1].buf == buf) { + vl->entries[vl->used - 1].flags |= flags; + return PIPE_OK; + } + + /* Grow the table */ + if(vl->used == vl->size) { + unsigned new_size; + struct pb_validate_entry *new_entries; + + new_size = vl->size * 2; + if(!new_size) + return PIPE_ERROR_OUT_OF_MEMORY; + + new_entries = (struct pb_validate_entry *)REALLOC(vl->entries, + vl->size*sizeof(struct pb_validate_entry), + new_size*sizeof(struct pb_validate_entry)); + if(!new_entries) + return PIPE_ERROR_OUT_OF_MEMORY; + + memset(new_entries + vl->size, 0, (new_size - vl->size)*sizeof(struct pb_validate_entry)); + + vl->size = new_size; + vl->entries = new_entries; + } + + assert(!vl->entries[vl->used].buf); + pb_reference(&vl->entries[vl->used].buf, buf); + vl->entries[vl->used].flags = flags; + ++vl->used; + + return PIPE_OK; +} + + +enum pipe_error +pb_validate_foreach(struct pb_validate *vl, + enum pipe_error (*callback)(struct pb_buffer *buf, void *data), + void *data) +{ + unsigned i; + for(i = 0; i < vl->used; ++i) { + enum pipe_error ret; + ret = callback(vl->entries[i].buf, data); + if(ret != PIPE_OK) + return ret; + } + return PIPE_OK; +} + + +enum pipe_error +pb_validate_validate(struct pb_validate *vl) +{ + unsigned i; + + for(i = 0; i < vl->used; ++i) { + enum pipe_error ret; + ret = pb_validate(vl->entries[i].buf, vl, vl->entries[i].flags); + if(ret != PIPE_OK) { + while(i--) + pb_validate(vl->entries[i].buf, NULL, 0); + return ret; + } + } + + return PIPE_OK; +} + + +void +pb_validate_fence(struct pb_validate *vl, + struct pipe_fence_handle *fence) +{ + unsigned i; + for(i = 0; i < vl->used; ++i) { + pb_fence(vl->entries[i].buf, fence); + pb_reference(&vl->entries[i].buf, NULL); + } + vl->used = 0; +} + + +void +pb_validate_destroy(struct pb_validate *vl) +{ + unsigned i; + for(i = 0; i < vl->used; ++i) + pb_reference(&vl->entries[i].buf, NULL); + FREE(vl->entries); + FREE(vl); +} + + +struct pb_validate * +pb_validate_create() +{ + struct pb_validate *vl; + + vl = CALLOC_STRUCT(pb_validate); + if(!vl) + return NULL; + + vl->size = PB_VALIDATE_INITIAL_SIZE; + vl->entries = (struct pb_validate_entry *)CALLOC(vl->size, sizeof(struct pb_validate_entry)); + if(!vl->entries) { + FREE(vl); + return NULL; + } + + return vl; +} + diff --git a/src/gallium/auxiliary/pipebuffer/pb_validate.h b/src/gallium/auxiliary/pipebuffer/pb_validate.h new file mode 100644 index 0000000..3c93f30 --- /dev/null +++ b/src/gallium/auxiliary/pipebuffer/pb_validate.h @@ -0,0 +1,97 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Buffer validation. + * + * @author Jose Fonseca + */ + +#ifndef PB_VALIDATE_H_ +#define PB_VALIDATE_H_ + + +#include "pipe/p_compiler.h" +#include "pipe/p_defines.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +struct pb_buffer; +struct pipe_fence_handle; + + +/** + * Buffer validation list. + * + * It holds a list of buffers to be validated and fenced when flushing. + */ +struct pb_validate; + + +enum pipe_error +pb_validate_add_buffer(struct pb_validate *vl, + struct pb_buffer *buf, + unsigned flags); + +enum pipe_error +pb_validate_foreach(struct pb_validate *vl, + enum pipe_error (*callback)(struct pb_buffer *buf, void *data), + void *data); + +/** + * Validate all buffers for hardware access. + * + * Should be called right before issuing commands to the hardware. + */ +enum pipe_error +pb_validate_validate(struct pb_validate *vl); + +/** + * Fence all buffers and clear the list. + * + * Should be called right after issuing commands to the hardware. + */ +void +pb_validate_fence(struct pb_validate *vl, + struct pipe_fence_handle *fence); + +struct pb_validate * +pb_validate_create(void); + +void +pb_validate_destroy(struct pb_validate *vl); + + +#ifdef __cplusplus +} +#endif + +#endif /*PB_VALIDATE_H_*/ diff --git a/src/gallium/auxiliary/rbug/rbug.h b/src/gallium/auxiliary/rbug/rbug.h new file mode 100644 index 0000000..259bfc6 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug.h @@ -0,0 +1,33 @@ +/* + * 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 + * 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 + * VMWARE 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 all for users the remote debugger protocol code. + */ + +#include "rbug/rbug_core.h" +#include "rbug/rbug_shader.h" +#include "rbug/rbug_context.h" +#include "rbug/rbug_texture.h" +#include "rbug/rbug_connection.h" diff --git a/src/gallium/auxiliary/rbug/rbug_connection.c b/src/gallium/auxiliary/rbug/rbug_connection.c new file mode 100644 index 0000000..ae4e27f --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_connection.c @@ -0,0 +1,168 @@ +/* + * 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 + * 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 + * VMWARE 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 "rbug/rbug.h" +#include "rbug/rbug_internal.h" + +#include "util/u_network.h" + +struct rbug_connection +{ + int socket; + uint32_t send_serial; + uint32_t recv_serial; + enum rbug_opcode opcode; +}; + +/** + * Create a rbug connection from a socket created with u_socket. + * + * Result: + * A new allocated connection using socket as communication path + */ +struct rbug_connection * +rbug_from_socket(int socket) +{ + struct rbug_connection *c = CALLOC_STRUCT(rbug_connection); + c->socket = socket; + return c; +} + +/** + * Free a connection, also closes socket. + */ +void +rbug_disconnect(struct rbug_connection *c) +{ + u_socket_close(c->socket); + FREE(c); +} + +/** + * Waits for a message to be fully received. + * Also returns the serial for the message, serial is not touched for replys. + * + * Result: + * demarshaled message on success, NULL on connection error + */ +struct rbug_header * +rbug_get_message(struct rbug_connection *c, uint32_t *serial) +{ + struct rbug_proto_header header; + struct rbug_header *out; + struct rbug_proto_header *data; + size_t length = 0; + size_t read = 0; + int ret; + + + ret = u_socket_peek(c->socket, &header, sizeof(header)); + if (ret <= 0) { + return NULL; + } + + length = (size_t)header.length * 4; + data = MALLOC(length); + if (!data) { + return NULL; + } + data->opcode = 0; + + do { + uint8_t *ptr = ((uint8_t*)data) + read; + ret = u_socket_recv(c->socket, ptr, length - read); + + if (ret <= 0) { + FREE(data); + return NULL; + } + + read += ret; + } while(read < length); + + out = rbug_demarshal(data); + if (!out) + FREE(data); + else if (serial) + *serial = c->recv_serial++; + else + c->recv_serial++; + + return out; +} + +/** + * Frees a message and associated data. + */ +void +rbug_free_header(struct rbug_header *header) +{ + if (!header) + return; + + FREE(header->__message); + FREE(header); +} + +/** + * Internal function used by rbug_send_* functions. + * + * Start sending a message. + */ +int +rbug_connection_send_start(struct rbug_connection *c, enum rbug_opcode opcode, uint32_t length) +{ + c->opcode = opcode; + return 0; +} + +/** + * Internal function used by rbug_send_* functions. + * + * Write data to the socket. + */ +int +rbug_connection_write(struct rbug_connection *c, void *to, uint32_t size) +{ + int ret = u_socket_send(c->socket, to, size); + return ret; +} + +/** + * Internal function used by rbug_send_* functions. + * + * Finish writeing data to the socket. + * Ups the send_serial and sets the serial argument if supplied. + */ +int rbug_connection_send_finish(struct rbug_connection *c, uint32_t *serial) +{ + if (c->opcode < 0) + return 0; + else if (serial) + *serial = c->send_serial++; + else + c->send_serial++; + + return 0; +} diff --git a/src/gallium/auxiliary/rbug/rbug_connection.h b/src/gallium/auxiliary/rbug/rbug_connection.h new file mode 100644 index 0000000..1f2c9ff --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_connection.h @@ -0,0 +1,45 @@ +/* + * 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 + * 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 + * VMWARE 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. + */ + +/* + * This file contains the function defentions for connection see c file for + * more comments covering function use. + */ + +#ifndef _RBUG_CONNECTION_H_ +#define _RBUG_CONNECTION_H_ + +#include "rbug/rbug_proto.h" + +struct rbug_connection * rbug_from_socket(int socket); + +void rbug_disconnect(struct rbug_connection *c); + +struct rbug_header * rbug_get_message(struct rbug_connection *c, uint32_t *serial); + +void rbug_free_header(struct rbug_header *header); + +struct rbug_header * rbug_demarshal(struct rbug_proto_header *header); + +#endif diff --git a/src/gallium/auxiliary/rbug/rbug_context.c b/src/gallium/auxiliary/rbug/rbug_context.c new file mode 100644 index 0000000..a3fd7e8 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_context.c @@ -0,0 +1,759 @@ +/* + * 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 + * 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 + * VMWARE 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. + */ + +/* + * This file holds the function implementation for one of the rbug extensions. + * Prototypes and declerations of functions and structs is in the same folder + * in the header file matching this file's name. + * + * The functions starting rbug_send_* encodes a call to the write format and + * sends that to the supplied connection, while functions starting with + * rbug_demarshal_* demarshal data in the wire protocol. + * + * Functions ending with _reply are replies to requests. + */ + +#include "rbug_internal.h" +#include "rbug/rbug_context.h" + +int rbug_send_context_list(struct rbug_connection *__con, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_LIST)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_CONTEXT_LIST, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_context_info(struct rbug_connection *__con, + rbug_context_t context, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(8); /* context */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_INFO)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(8, rbug_context_t, context); /* context */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_CONTEXT_INFO, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_context_draw_block(struct rbug_connection *__con, + rbug_context_t context, + rbug_block_t block, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(8); /* context */ + LEN(4); /* block */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_BLOCK)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(8, rbug_context_t, context); /* context */ + WRITE(4, rbug_block_t, block); /* block */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_BLOCK, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_context_draw_step(struct rbug_connection *__con, + rbug_context_t context, + rbug_block_t step, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(8); /* context */ + LEN(4); /* step */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_STEP)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(8, rbug_context_t, context); /* context */ + WRITE(4, rbug_block_t, step); /* step */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_STEP, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_context_draw_unblock(struct rbug_connection *__con, + rbug_context_t context, + rbug_block_t unblock, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(8); /* context */ + LEN(4); /* unblock */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_UNBLOCK)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(8, rbug_context_t, context); /* context */ + WRITE(4, rbug_block_t, unblock); /* unblock */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_UNBLOCK, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_context_draw_rule(struct rbug_connection *__con, + rbug_context_t context, + rbug_shader_t vertex, + rbug_shader_t fragment, + rbug_texture_t texture, + rbug_texture_t surface, + rbug_block_t block, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(8); /* context */ + LEN(8); /* vertex */ + LEN(8); /* fragment */ + LEN(8); /* texture */ + LEN(8); /* surface */ + LEN(4); /* block */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_RULE)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(8, rbug_context_t, context); /* context */ + WRITE(8, rbug_shader_t, vertex); /* vertex */ + WRITE(8, rbug_shader_t, fragment); /* fragment */ + WRITE(8, rbug_texture_t, texture); /* texture */ + WRITE(8, rbug_texture_t, surface); /* surface */ + WRITE(4, rbug_block_t, block); /* block */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_RULE, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_context_flush(struct rbug_connection *__con, + rbug_context_t context, + int32_t flags, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(8); /* context */ + LEN(4); /* flags */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_FLUSH)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(8, rbug_context_t, context); /* context */ + WRITE(4, int32_t, flags); /* flags */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_CONTEXT_FLUSH, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_context_list_reply(struct rbug_connection *__con, + uint32_t serial, + rbug_context_t *contexts, + uint32_t contexts_len, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(4); /* serial */ + LEN_ARRAY(8, contexts); /* contexts */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_LIST_REPLY)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(4, uint32_t, serial); /* serial */ + WRITE_ARRAY(8, rbug_context_t, contexts); /* contexts */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_CONTEXT_LIST_REPLY, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_context_info_reply(struct rbug_connection *__con, + uint32_t serial, + rbug_shader_t vertex, + rbug_shader_t fragment, + rbug_texture_t *texs, + uint32_t texs_len, + rbug_texture_t *cbufs, + uint32_t cbufs_len, + rbug_texture_t zsbuf, + rbug_block_t blocker, + rbug_block_t blocked, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(4); /* serial */ + LEN(8); /* vertex */ + LEN(8); /* fragment */ + LEN_ARRAY(8, texs); /* texs */ + LEN_ARRAY(8, cbufs); /* cbufs */ + LEN(8); /* zsbuf */ + LEN(4); /* blocker */ + LEN(4); /* blocked */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_INFO_REPLY)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(4, uint32_t, serial); /* serial */ + WRITE(8, rbug_shader_t, vertex); /* vertex */ + WRITE(8, rbug_shader_t, fragment); /* fragment */ + WRITE_ARRAY(8, rbug_texture_t, texs); /* texs */ + WRITE_ARRAY(8, rbug_texture_t, cbufs); /* cbufs */ + WRITE(8, rbug_texture_t, zsbuf); /* zsbuf */ + WRITE(4, rbug_block_t, blocker); /* blocker */ + WRITE(4, rbug_block_t, blocked); /* blocked */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_CONTEXT_INFO_REPLY, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_context_draw_blocked(struct rbug_connection *__con, + rbug_context_t context, + rbug_block_t block, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(8); /* context */ + LEN(4); /* block */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_BLOCKED)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(8, rbug_context_t, context); /* context */ + WRITE(4, rbug_block_t, block); /* block */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_BLOCKED, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +struct rbug_proto_context_list * rbug_demarshal_context_list(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_context_list *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_CONTEXT_LIST) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + + return ret; +} + +struct rbug_proto_context_info * rbug_demarshal_context_info(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_context_info *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_CONTEXT_INFO) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(8, rbug_context_t, context); /* context */ + + return ret; +} + +struct rbug_proto_context_draw_block * rbug_demarshal_context_draw_block(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_context_draw_block *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_BLOCK) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(8, rbug_context_t, context); /* context */ + READ(4, rbug_block_t, block); /* block */ + + return ret; +} + +struct rbug_proto_context_draw_step * rbug_demarshal_context_draw_step(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_context_draw_step *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_STEP) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(8, rbug_context_t, context); /* context */ + READ(4, rbug_block_t, step); /* step */ + + return ret; +} + +struct rbug_proto_context_draw_unblock * rbug_demarshal_context_draw_unblock(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_context_draw_unblock *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_UNBLOCK) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(8, rbug_context_t, context); /* context */ + READ(4, rbug_block_t, unblock); /* unblock */ + + return ret; +} + +struct rbug_proto_context_draw_rule * rbug_demarshal_context_draw_rule(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_context_draw_rule *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_RULE) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(8, rbug_context_t, context); /* context */ + READ(8, rbug_shader_t, vertex); /* vertex */ + READ(8, rbug_shader_t, fragment); /* fragment */ + READ(8, rbug_texture_t, texture); /* texture */ + READ(8, rbug_texture_t, surface); /* surface */ + READ(4, rbug_block_t, block); /* block */ + + return ret; +} + +struct rbug_proto_context_flush * rbug_demarshal_context_flush(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_context_flush *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_CONTEXT_FLUSH) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(8, rbug_context_t, context); /* context */ + READ(4, int32_t, flags); /* flags */ + + return ret; +} + +struct rbug_proto_context_list_reply * rbug_demarshal_context_list_reply(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_context_list_reply *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_CONTEXT_LIST_REPLY) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(4, uint32_t, serial); /* serial */ + READ_ARRAY(8, rbug_context_t, contexts); /* contexts */ + + return ret; +} + +struct rbug_proto_context_info_reply * rbug_demarshal_context_info_reply(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_context_info_reply *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_CONTEXT_INFO_REPLY) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(4, uint32_t, serial); /* serial */ + READ(8, rbug_shader_t, vertex); /* vertex */ + READ(8, rbug_shader_t, fragment); /* fragment */ + READ_ARRAY(8, rbug_texture_t, texs); /* texs */ + READ_ARRAY(8, rbug_texture_t, cbufs); /* cbufs */ + READ(8, rbug_texture_t, zsbuf); /* zsbuf */ + READ(4, rbug_block_t, blocker); /* blocker */ + READ(4, rbug_block_t, blocked); /* blocked */ + + return ret; +} + +struct rbug_proto_context_draw_blocked * rbug_demarshal_context_draw_blocked(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_context_draw_blocked *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_BLOCKED) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(8, rbug_context_t, context); /* context */ + READ(4, rbug_block_t, block); /* block */ + + return ret; +} diff --git a/src/gallium/auxiliary/rbug/rbug_context.h b/src/gallium/auxiliary/rbug/rbug_context.h new file mode 100644 index 0000000..03126d6 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_context.h @@ -0,0 +1,212 @@ +/* + * 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 + * 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 + * VMWARE 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. + */ + +/* + * This file holds structs decelerations and function prototypes for one of + * the rbug extensions. Implementation of the functions is in the same folder + * in the c file matching this file's name. + * + * The structs what is returned from the demarshal functions. The functions + * starting rbug_send_* encodes a call to the write format and sends that to + * the supplied connection, while functions starting with rbug_demarshal_* + * demarshal data from the wire protocol. + * + * Structs and functions ending with _reply are replies to requests. + */ + +#ifndef _RBUG_PROTO_CONTEXT_H_ +#define _RBUG_PROTO_CONTEXT_H_ + +#include "rbug/rbug_proto.h" +#include "rbug/rbug_core.h" + +typedef enum +{ + RBUG_BLOCK_BEFORE = 1, + RBUG_BLOCK_AFTER = 2, + RBUG_BLOCK_RULE = 4, + RBUG_BLOCK_MASK = 7 +} rbug_block_t; + +struct rbug_proto_context_list +{ + struct rbug_header header; +}; + +struct rbug_proto_context_info +{ + struct rbug_header header; + rbug_context_t context; +}; + +struct rbug_proto_context_draw_block +{ + struct rbug_header header; + rbug_context_t context; + rbug_block_t block; +}; + +struct rbug_proto_context_draw_step +{ + struct rbug_header header; + rbug_context_t context; + rbug_block_t step; +}; + +struct rbug_proto_context_draw_unblock +{ + struct rbug_header header; + rbug_context_t context; + rbug_block_t unblock; +}; + +struct rbug_proto_context_draw_rule +{ + struct rbug_header header; + rbug_context_t context; + rbug_shader_t vertex; + rbug_shader_t fragment; + rbug_texture_t texture; + rbug_texture_t surface; + rbug_block_t block; +}; + +struct rbug_proto_context_flush +{ + struct rbug_header header; + rbug_context_t context; + int32_t flags; +}; + +struct rbug_proto_context_list_reply +{ + struct rbug_header header; + uint32_t serial; + rbug_context_t *contexts; + uint32_t contexts_len; +}; + +struct rbug_proto_context_info_reply +{ + struct rbug_header header; + uint32_t serial; + rbug_shader_t vertex; + rbug_shader_t fragment; + rbug_texture_t *texs; + uint32_t texs_len; + rbug_texture_t *cbufs; + uint32_t cbufs_len; + rbug_texture_t zsbuf; + rbug_block_t blocker; + rbug_block_t blocked; +}; + +struct rbug_proto_context_draw_blocked +{ + struct rbug_header header; + rbug_context_t context; + rbug_block_t block; +}; + +int rbug_send_context_list(struct rbug_connection *__con, + uint32_t *__serial); + +int rbug_send_context_info(struct rbug_connection *__con, + rbug_context_t context, + uint32_t *__serial); + +int rbug_send_context_draw_block(struct rbug_connection *__con, + rbug_context_t context, + rbug_block_t block, + uint32_t *__serial); + +int rbug_send_context_draw_step(struct rbug_connection *__con, + rbug_context_t context, + rbug_block_t step, + uint32_t *__serial); + +int rbug_send_context_draw_unblock(struct rbug_connection *__con, + rbug_context_t context, + rbug_block_t unblock, + uint32_t *__serial); + +int rbug_send_context_draw_rule(struct rbug_connection *__con, + rbug_context_t context, + rbug_shader_t vertex, + rbug_shader_t fragment, + rbug_texture_t texture, + rbug_texture_t surface, + rbug_block_t block, + uint32_t *__serial); + +int rbug_send_context_flush(struct rbug_connection *__con, + rbug_context_t context, + int32_t flags, + uint32_t *__serial); + +int rbug_send_context_list_reply(struct rbug_connection *__con, + uint32_t serial, + rbug_context_t *contexts, + uint32_t contexts_len, + uint32_t *__serial); + +int rbug_send_context_info_reply(struct rbug_connection *__con, + uint32_t serial, + rbug_shader_t vertex, + rbug_shader_t fragment, + rbug_texture_t *texs, + uint32_t texs_len, + rbug_texture_t *cbufs, + uint32_t cbufs_len, + rbug_texture_t zsbuf, + rbug_block_t blocker, + rbug_block_t blocked, + uint32_t *__serial); + +int rbug_send_context_draw_blocked(struct rbug_connection *__con, + rbug_context_t context, + rbug_block_t block, + uint32_t *__serial); + +struct rbug_proto_context_list * rbug_demarshal_context_list(struct rbug_proto_header *header); + +struct rbug_proto_context_info * rbug_demarshal_context_info(struct rbug_proto_header *header); + +struct rbug_proto_context_draw_block * rbug_demarshal_context_draw_block(struct rbug_proto_header *header); + +struct rbug_proto_context_draw_step * rbug_demarshal_context_draw_step(struct rbug_proto_header *header); + +struct rbug_proto_context_draw_unblock * rbug_demarshal_context_draw_unblock(struct rbug_proto_header *header); + +struct rbug_proto_context_draw_rule * rbug_demarshal_context_draw_rule(struct rbug_proto_header *header); + +struct rbug_proto_context_flush * rbug_demarshal_context_flush(struct rbug_proto_header *header); + +struct rbug_proto_context_list_reply * rbug_demarshal_context_list_reply(struct rbug_proto_header *header); + +struct rbug_proto_context_info_reply * rbug_demarshal_context_info_reply(struct rbug_proto_header *header); + +struct rbug_proto_context_draw_blocked * rbug_demarshal_context_draw_blocked(struct rbug_proto_header *header); + +#endif diff --git a/src/gallium/auxiliary/rbug/rbug_core.c b/src/gallium/auxiliary/rbug/rbug_core.c new file mode 100644 index 0000000..1d47d13 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_core.c @@ -0,0 +1,359 @@ +/* + * 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 + * 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 + * VMWARE 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. + */ + +/* + * This file holds the function implementation for one of the rbug extensions. + * Prototypes and declerations of functions and structs is in the same folder + * in the header file matching this file's name. + * + * The functions starting rbug_send_* encodes a call to the write format and + * sends that to the supplied connection, while functions starting with + * rbug_demarshal_* demarshal data in the wire protocol. + * + * Functions ending with _reply are replies to requests. + */ + +#include "rbug_internal.h" +#include "rbug/rbug_core.h" + +int rbug_send_noop(struct rbug_connection *__con, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_NOOP)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_NOOP, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_ping(struct rbug_connection *__con, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_PING)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_PING, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_error(struct rbug_connection *__con, + uint32_t error, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(4); /* error */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_ERROR)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(4, uint32_t, error); /* error */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_ERROR, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_ping_reply(struct rbug_connection *__con, + uint32_t serial, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(4); /* serial */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_PING_REPLY)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(4, uint32_t, serial); /* serial */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_PING_REPLY, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_error_reply(struct rbug_connection *__con, + uint32_t serial, + uint32_t error, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(4); /* serial */ + LEN(4); /* error */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_ERROR_REPLY)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(4, uint32_t, serial); /* serial */ + WRITE(4, uint32_t, error); /* error */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_ERROR_REPLY, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +struct rbug_proto_noop * rbug_demarshal_noop(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_noop *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_NOOP) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + + return ret; +} + +struct rbug_proto_ping * rbug_demarshal_ping(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_ping *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_PING) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + + return ret; +} + +struct rbug_proto_error * rbug_demarshal_error(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_error *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_ERROR) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(4, uint32_t, error); /* error */ + + return ret; +} + +struct rbug_proto_ping_reply * rbug_demarshal_ping_reply(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_ping_reply *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_PING_REPLY) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(4, uint32_t, serial); /* serial */ + + return ret; +} + +struct rbug_proto_error_reply * rbug_demarshal_error_reply(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_error_reply *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_ERROR_REPLY) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(4, uint32_t, serial); /* serial */ + READ(4, uint32_t, error); /* error */ + + return ret; +} diff --git a/src/gallium/auxiliary/rbug/rbug_core.h b/src/gallium/auxiliary/rbug/rbug_core.h new file mode 100644 index 0000000..99a36a0 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_core.h @@ -0,0 +1,105 @@ +/* + * 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 + * 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 + * VMWARE 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. + */ + +/* + * This file holds structs decelerations and function prototypes for one of + * the rbug extensions. Implementation of the functions is in the same folder + * in the c file matching this file's name. + * + * The structs what is returned from the demarshal functions. The functions + * starting rbug_send_* encodes a call to the write format and sends that to + * the supplied connection, while functions starting with rbug_demarshal_* + * demarshal data from the wire protocol. + * + * Structs and functions ending with _reply are replies to requests. + */ + +#ifndef _RBUG_PROTO_CORE_H_ +#define _RBUG_PROTO_CORE_H_ + +#include "rbug/rbug_proto.h" + +typedef uint64_t rbug_shader_t; +typedef uint64_t rbug_context_t; +typedef uint64_t rbug_texture_t; + +struct rbug_proto_noop +{ + struct rbug_header header; +}; + +struct rbug_proto_ping +{ + struct rbug_header header; +}; + +struct rbug_proto_error +{ + struct rbug_header header; + uint32_t error; +}; + +struct rbug_proto_ping_reply +{ + struct rbug_header header; + uint32_t serial; +}; + +struct rbug_proto_error_reply +{ + struct rbug_header header; + uint32_t serial; + uint32_t error; +}; + +int rbug_send_noop(struct rbug_connection *__con, + uint32_t *__serial); + +int rbug_send_ping(struct rbug_connection *__con, + uint32_t *__serial); + +int rbug_send_error(struct rbug_connection *__con, + uint32_t error, + uint32_t *__serial); + +int rbug_send_ping_reply(struct rbug_connection *__con, + uint32_t serial, + uint32_t *__serial); + +int rbug_send_error_reply(struct rbug_connection *__con, + uint32_t serial, + uint32_t error, + uint32_t *__serial); + +struct rbug_proto_noop * rbug_demarshal_noop(struct rbug_proto_header *header); + +struct rbug_proto_ping * rbug_demarshal_ping(struct rbug_proto_header *header); + +struct rbug_proto_error * rbug_demarshal_error(struct rbug_proto_header *header); + +struct rbug_proto_ping_reply * rbug_demarshal_ping_reply(struct rbug_proto_header *header); + +struct rbug_proto_error_reply * rbug_demarshal_error_reply(struct rbug_proto_header *header); + +#endif diff --git a/src/gallium/auxiliary/rbug/rbug_demarshal.c b/src/gallium/auxiliary/rbug/rbug_demarshal.c new file mode 100644 index 0000000..06caa45 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_demarshal.c @@ -0,0 +1,157 @@ +/* + * 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 + * 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 + * VMWARE 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 "rbug.h" + +/** + * Small function that looks at the proto_header and selects the correct + * demarshal functions and return the result. + */ +struct rbug_header * rbug_demarshal(struct rbug_proto_header *header) +{ + switch(header->opcode) { + case RBUG_OP_NOOP: + return (struct rbug_header *)rbug_demarshal_noop(header); + case RBUG_OP_PING: + return (struct rbug_header *)rbug_demarshal_ping(header); + case RBUG_OP_ERROR: + return (struct rbug_header *)rbug_demarshal_error(header); + case RBUG_OP_PING_REPLY: + return (struct rbug_header *)rbug_demarshal_ping_reply(header); + case RBUG_OP_ERROR_REPLY: + return (struct rbug_header *)rbug_demarshal_error_reply(header); + case RBUG_OP_TEXTURE_LIST: + return (struct rbug_header *)rbug_demarshal_texture_list(header); + case RBUG_OP_TEXTURE_INFO: + return (struct rbug_header *)rbug_demarshal_texture_info(header); + case RBUG_OP_TEXTURE_WRITE: + return (struct rbug_header *)rbug_demarshal_texture_write(header); + case RBUG_OP_TEXTURE_READ: + return (struct rbug_header *)rbug_demarshal_texture_read(header); + case RBUG_OP_TEXTURE_LIST_REPLY: + return (struct rbug_header *)rbug_demarshal_texture_list_reply(header); + case RBUG_OP_TEXTURE_INFO_REPLY: + return (struct rbug_header *)rbug_demarshal_texture_info_reply(header); + case RBUG_OP_TEXTURE_READ_REPLY: + return (struct rbug_header *)rbug_demarshal_texture_read_reply(header); + case RBUG_OP_CONTEXT_LIST: + return (struct rbug_header *)rbug_demarshal_context_list(header); + case RBUG_OP_CONTEXT_INFO: + return (struct rbug_header *)rbug_demarshal_context_info(header); + case RBUG_OP_CONTEXT_DRAW_BLOCK: + return (struct rbug_header *)rbug_demarshal_context_draw_block(header); + case RBUG_OP_CONTEXT_DRAW_STEP: + return (struct rbug_header *)rbug_demarshal_context_draw_step(header); + case RBUG_OP_CONTEXT_DRAW_UNBLOCK: + return (struct rbug_header *)rbug_demarshal_context_draw_unblock(header); + case RBUG_OP_CONTEXT_DRAW_RULE: + return (struct rbug_header *)rbug_demarshal_context_draw_rule(header); + case RBUG_OP_CONTEXT_FLUSH: + return (struct rbug_header *)rbug_demarshal_context_flush(header); + case RBUG_OP_CONTEXT_LIST_REPLY: + return (struct rbug_header *)rbug_demarshal_context_list_reply(header); + case RBUG_OP_CONTEXT_INFO_REPLY: + return (struct rbug_header *)rbug_demarshal_context_info_reply(header); + case RBUG_OP_CONTEXT_DRAW_BLOCKED: + return (struct rbug_header *)rbug_demarshal_context_draw_blocked(header); + case RBUG_OP_SHADER_LIST: + return (struct rbug_header *)rbug_demarshal_shader_list(header); + case RBUG_OP_SHADER_INFO: + return (struct rbug_header *)rbug_demarshal_shader_info(header); + case RBUG_OP_SHADER_DISABLE: + return (struct rbug_header *)rbug_demarshal_shader_disable(header); + case RBUG_OP_SHADER_REPLACE: + return (struct rbug_header *)rbug_demarshal_shader_replace(header); + case RBUG_OP_SHADER_LIST_REPLY: + return (struct rbug_header *)rbug_demarshal_shader_list_reply(header); + case RBUG_OP_SHADER_INFO_REPLY: + return (struct rbug_header *)rbug_demarshal_shader_info_reply(header); + default: + return NULL; + } +} + +const char* rbug_proto_get_name(enum rbug_opcode opcode) +{ + switch(opcode) { + case RBUG_OP_NOOP: + return "RBUG_OP_NOOP"; + case RBUG_OP_PING: + return "RBUG_OP_PING"; + case RBUG_OP_ERROR: + return "RBUG_OP_ERROR"; + case RBUG_OP_PING_REPLY: + return "RBUG_OP_PING_REPLY"; + case RBUG_OP_ERROR_REPLY: + return "RBUG_OP_ERROR_REPLY"; + case RBUG_OP_TEXTURE_LIST: + return "RBUG_OP_TEXTURE_LIST"; + case RBUG_OP_TEXTURE_INFO: + return "RBUG_OP_TEXTURE_INFO"; + case RBUG_OP_TEXTURE_WRITE: + return "RBUG_OP_TEXTURE_WRITE"; + case RBUG_OP_TEXTURE_READ: + return "RBUG_OP_TEXTURE_READ"; + case RBUG_OP_TEXTURE_LIST_REPLY: + return "RBUG_OP_TEXTURE_LIST_REPLY"; + case RBUG_OP_TEXTURE_INFO_REPLY: + return "RBUG_OP_TEXTURE_INFO_REPLY"; + case RBUG_OP_TEXTURE_READ_REPLY: + return "RBUG_OP_TEXTURE_READ_REPLY"; + case RBUG_OP_CONTEXT_LIST: + return "RBUG_OP_CONTEXT_LIST"; + case RBUG_OP_CONTEXT_INFO: + return "RBUG_OP_CONTEXT_INFO"; + case RBUG_OP_CONTEXT_DRAW_BLOCK: + return "RBUG_OP_CONTEXT_DRAW_BLOCK"; + case RBUG_OP_CONTEXT_DRAW_STEP: + return "RBUG_OP_CONTEXT_DRAW_STEP"; + case RBUG_OP_CONTEXT_DRAW_UNBLOCK: + return "RBUG_OP_CONTEXT_DRAW_UNBLOCK"; + case RBUG_OP_CONTEXT_DRAW_RULE: + return "RBUG_OP_CONTEXT_DRAW_RULE"; + case RBUG_OP_CONTEXT_FLUSH: + return "RBUG_OP_CONTEXT_FLUSH"; + case RBUG_OP_CONTEXT_LIST_REPLY: + return "RBUG_OP_CONTEXT_LIST_REPLY"; + case RBUG_OP_CONTEXT_INFO_REPLY: + return "RBUG_OP_CONTEXT_INFO_REPLY"; + case RBUG_OP_CONTEXT_DRAW_BLOCKED: + return "RBUG_OP_CONTEXT_DRAW_BLOCKED"; + case RBUG_OP_SHADER_LIST: + return "RBUG_OP_SHADER_LIST"; + case RBUG_OP_SHADER_INFO: + return "RBUG_OP_SHADER_INFO"; + case RBUG_OP_SHADER_DISABLE: + return "RBUG_OP_SHADER_DISABLE"; + case RBUG_OP_SHADER_REPLACE: + return "RBUG_OP_SHADER_REPLACE"; + case RBUG_OP_SHADER_LIST_REPLY: + return "RBUG_OP_SHADER_LIST_REPLY"; + case RBUG_OP_SHADER_INFO_REPLY: + return "RBUG_OP_SHADER_INFO_REPLY"; + default: + return NULL; + } +} diff --git a/src/gallium/auxiliary/rbug/rbug_internal.h b/src/gallium/auxiliary/rbug/rbug_internal.h new file mode 100644 index 0000000..4aba1a8 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_internal.h @@ -0,0 +1,100 @@ +/* + * 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 + * 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 + * VMWARE 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. + */ + +/* + * This file is internal to the rbug protocol code, and contains asorted + * features needed by the code. + */ + +#ifndef _RBUG_INTERNAL_H_ +#define _RBUG_INTERNAL_H_ + +#include "rbug/rbug_proto.h" + +#include "util/u_memory.h" +#include "util/u_debug.h" +#include + +int rbug_connection_send_start(struct rbug_connection *con, enum rbug_opcode opcode, uint32_t length); +int rbug_connection_write(struct rbug_connection *con, void *data, uint32_t size); +int rbug_connection_send_finish(struct rbug_connection *con, uint32_t *c); + +/** + * Only works with multiples of 2 + */ +#define PAD(from, to) \ +do { \ + from = (from + to - 1) & ~(to - 1); \ +} while(0) + +#define LEN(size) \ +do { \ + PAD(__len, size); \ + __len += size; \ +} while(0) + +#define LEN_ARRAY(size, name) \ +do { \ + LEN(4); \ + PAD(__len, size); \ + __len += size * name##_len; \ +} while(0) + +#define WRITE(size, type, name) \ +do { \ + PAD(__pos, size); \ + *((type *)(&__data[__pos])) = name; \ + __pos += size; \ +} while(0) + +#define WRITE_ARRAY(size, type, name) \ +do { \ + WRITE(4, uint32_t, name##_len); \ + PAD(__pos, size); \ + memcpy(&__data[__pos], name, size * name##_len); \ + __pos += size * name##_len; \ +} while(0) + +#define READ(size, type, name) \ +do { \ + PAD(pos, size); \ + pos += size; \ + if (pos > len) \ + break; \ + ret->name = *((type *)(&data[pos - size])); \ +} while(0) + +#define READ_ARRAY(size, type, name) \ +do { \ + READ(4, uint32_t, name##_len); \ + if (pos > len) \ + break; \ + PAD(pos, size); \ + pos += size * ret->name##_len; \ + if (pos > len) \ + break; \ + ret->name = (type *)&data[pos - size * ret->name##_len]; \ +} while(0) + +#endif diff --git a/src/gallium/auxiliary/rbug/rbug_proto.h b/src/gallium/auxiliary/rbug/rbug_proto.h new file mode 100644 index 0000000..2fce725 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_proto.h @@ -0,0 +1,99 @@ +/* + * 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 + * 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 + * VMWARE 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. + */ + +/* + * This file holds common definitions of the gallium remote debugging protocol. + */ + +#ifndef _RBUG_PROTO_H_ +#define _RBUG_PROTO_H_ + +#include "pipe/p_compiler.h" + +/** + * Uniqe indentifier for each command. + * + * Replys are designated by negative. + */ +enum rbug_opcode +{ + RBUG_OP_NOOP = 0, + RBUG_OP_PING = 1, + RBUG_OP_ERROR = 2, + RBUG_OP_PING_REPLY = -1, + RBUG_OP_ERROR_REPLY = -2, + RBUG_OP_TEXTURE_LIST = 256, + RBUG_OP_TEXTURE_INFO = 257, + RBUG_OP_TEXTURE_WRITE = 258, + RBUG_OP_TEXTURE_READ = 259, + RBUG_OP_TEXTURE_LIST_REPLY = -256, + RBUG_OP_TEXTURE_INFO_REPLY = -257, + RBUG_OP_TEXTURE_READ_REPLY = -259, + RBUG_OP_CONTEXT_LIST = 512, + RBUG_OP_CONTEXT_INFO = 513, + RBUG_OP_CONTEXT_DRAW_BLOCK = 514, + RBUG_OP_CONTEXT_DRAW_STEP = 515, + RBUG_OP_CONTEXT_DRAW_UNBLOCK = 516, + RBUG_OP_CONTEXT_DRAW_RULE = 518, + RBUG_OP_CONTEXT_FLUSH = 519, + RBUG_OP_CONTEXT_LIST_REPLY = -512, + RBUG_OP_CONTEXT_INFO_REPLY = -513, + RBUG_OP_CONTEXT_DRAW_BLOCKED = 517, + RBUG_OP_SHADER_LIST = 768, + RBUG_OP_SHADER_INFO = 769, + RBUG_OP_SHADER_DISABLE = 770, + RBUG_OP_SHADER_REPLACE = 771, + RBUG_OP_SHADER_LIST_REPLY = -768, + RBUG_OP_SHADER_INFO_REPLY = -769 +}; + +/** + * Header for demarshaled message. + */ +struct rbug_header +{ + enum rbug_opcode opcode; + void *__message; +}; + +/** + * Header for a message in wire format. + */ +struct rbug_proto_header +{ + int32_t opcode; + uint32_t length; +}; + +/** + * Forward declare connection here, as this file is included by all users. + */ +struct rbug_connection; + +/** + * Get printable string for opcode. + */ +const char* rbug_proto_get_name(enum rbug_opcode opcode); + +#endif diff --git a/src/gallium/auxiliary/rbug/rbug_shader.c b/src/gallium/auxiliary/rbug/rbug_shader.c new file mode 100644 index 0000000..1742941 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_shader.c @@ -0,0 +1,468 @@ +/* + * 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 + * 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 + * VMWARE 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. + */ + +/* + * This file holds the function implementation for one of the rbug extensions. + * Prototypes and declerations of functions and structs is in the same folder + * in the header file matching this file's name. + * + * The functions starting rbug_send_* encodes a call to the write format and + * sends that to the supplied connection, while functions starting with + * rbug_demarshal_* demarshal data in the wire protocol. + * + * Functions ending with _reply are replies to requests. + */ + +#include "rbug_internal.h" +#include "rbug/rbug_shader.h" + +int rbug_send_shader_list(struct rbug_connection *__con, + rbug_context_t context, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(8); /* context */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(8, rbug_context_t, context); /* context */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_shader_info(struct rbug_connection *__con, + rbug_context_t context, + rbug_shader_t shader, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(8); /* context */ + LEN(8); /* shader */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(8, rbug_context_t, context); /* context */ + WRITE(8, rbug_shader_t, shader); /* shader */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_shader_disable(struct rbug_connection *__con, + rbug_context_t context, + rbug_shader_t shader, + uint8_t disable, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(8); /* context */ + LEN(8); /* shader */ + LEN(1); /* disable */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_DISABLE)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(8, rbug_context_t, context); /* context */ + WRITE(8, rbug_shader_t, shader); /* shader */ + WRITE(1, uint8_t, disable); /* disable */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_SHADER_DISABLE, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_shader_replace(struct rbug_connection *__con, + rbug_context_t context, + rbug_shader_t shader, + uint32_t *tokens, + uint32_t tokens_len, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(8); /* context */ + LEN(8); /* shader */ + LEN_ARRAY(4, tokens); /* tokens */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_REPLACE)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(8, rbug_context_t, context); /* context */ + WRITE(8, rbug_shader_t, shader); /* shader */ + WRITE_ARRAY(4, uint32_t, tokens); /* tokens */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_SHADER_REPLACE, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_shader_list_reply(struct rbug_connection *__con, + uint32_t serial, + rbug_shader_t *shaders, + uint32_t shaders_len, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(4); /* serial */ + LEN_ARRAY(8, shaders); /* shaders */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST_REPLY)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(4, uint32_t, serial); /* serial */ + WRITE_ARRAY(8, rbug_shader_t, shaders); /* shaders */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST_REPLY, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_shader_info_reply(struct rbug_connection *__con, + uint32_t serial, + uint32_t *original, + uint32_t original_len, + uint32_t *replaced, + uint32_t replaced_len, + uint8_t disabled, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(4); /* serial */ + LEN_ARRAY(4, original); /* original */ + LEN_ARRAY(4, replaced); /* replaced */ + LEN(1); /* disabled */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO_REPLY)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(4, uint32_t, serial); /* serial */ + WRITE_ARRAY(4, uint32_t, original); /* original */ + WRITE_ARRAY(4, uint32_t, replaced); /* replaced */ + WRITE(1, uint8_t, disabled); /* disabled */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO_REPLY, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +struct rbug_proto_shader_list * rbug_demarshal_shader_list(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_shader_list *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_SHADER_LIST) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(8, rbug_context_t, context); /* context */ + + return ret; +} + +struct rbug_proto_shader_info * rbug_demarshal_shader_info(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_shader_info *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_SHADER_INFO) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(8, rbug_context_t, context); /* context */ + READ(8, rbug_shader_t, shader); /* shader */ + + return ret; +} + +struct rbug_proto_shader_disable * rbug_demarshal_shader_disable(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_shader_disable *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_SHADER_DISABLE) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(8, rbug_context_t, context); /* context */ + READ(8, rbug_shader_t, shader); /* shader */ + READ(1, uint8_t, disable); /* disable */ + + return ret; +} + +struct rbug_proto_shader_replace * rbug_demarshal_shader_replace(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_shader_replace *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_SHADER_REPLACE) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(8, rbug_context_t, context); /* context */ + READ(8, rbug_shader_t, shader); /* shader */ + READ_ARRAY(4, uint32_t, tokens); /* tokens */ + + return ret; +} + +struct rbug_proto_shader_list_reply * rbug_demarshal_shader_list_reply(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_shader_list_reply *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_SHADER_LIST_REPLY) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(4, uint32_t, serial); /* serial */ + READ_ARRAY(8, rbug_shader_t, shaders); /* shaders */ + + return ret; +} + +struct rbug_proto_shader_info_reply * rbug_demarshal_shader_info_reply(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_shader_info_reply *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_SHADER_INFO_REPLY) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(4, uint32_t, serial); /* serial */ + READ_ARRAY(4, uint32_t, original); /* original */ + READ_ARRAY(4, uint32_t, replaced); /* replaced */ + READ(1, uint8_t, disabled); /* disabled */ + + return ret; +} diff --git a/src/gallium/auxiliary/rbug/rbug_shader.h b/src/gallium/auxiliary/rbug/rbug_shader.h new file mode 100644 index 0000000..b5d8867 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_shader.h @@ -0,0 +1,142 @@ +/* + * 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 + * 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 + * VMWARE 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. + */ + +/* + * This file holds structs decelerations and function prototypes for one of + * the rbug extensions. Implementation of the functions is in the same folder + * in the c file matching this file's name. + * + * The structs what is returned from the demarshal functions. The functions + * starting rbug_send_* encodes a call to the write format and sends that to + * the supplied connection, while functions starting with rbug_demarshal_* + * demarshal data from the wire protocol. + * + * Structs and functions ending with _reply are replies to requests. + */ + +#ifndef _RBUG_PROTO_SHADER_H_ +#define _RBUG_PROTO_SHADER_H_ + +#include "rbug/rbug_proto.h" +#include "rbug/rbug_core.h" + +struct rbug_proto_shader_list +{ + struct rbug_header header; + rbug_context_t context; +}; + +struct rbug_proto_shader_info +{ + struct rbug_header header; + rbug_context_t context; + rbug_shader_t shader; +}; + +struct rbug_proto_shader_disable +{ + struct rbug_header header; + rbug_context_t context; + rbug_shader_t shader; + uint8_t disable; +}; + +struct rbug_proto_shader_replace +{ + struct rbug_header header; + rbug_context_t context; + rbug_shader_t shader; + uint32_t *tokens; + uint32_t tokens_len; +}; + +struct rbug_proto_shader_list_reply +{ + struct rbug_header header; + uint32_t serial; + rbug_shader_t *shaders; + uint32_t shaders_len; +}; + +struct rbug_proto_shader_info_reply +{ + struct rbug_header header; + uint32_t serial; + uint32_t *original; + uint32_t original_len; + uint32_t *replaced; + uint32_t replaced_len; + uint8_t disabled; +}; + +int rbug_send_shader_list(struct rbug_connection *__con, + rbug_context_t context, + uint32_t *__serial); + +int rbug_send_shader_info(struct rbug_connection *__con, + rbug_context_t context, + rbug_shader_t shader, + uint32_t *__serial); + +int rbug_send_shader_disable(struct rbug_connection *__con, + rbug_context_t context, + rbug_shader_t shader, + uint8_t disable, + uint32_t *__serial); + +int rbug_send_shader_replace(struct rbug_connection *__con, + rbug_context_t context, + rbug_shader_t shader, + uint32_t *tokens, + uint32_t tokens_len, + uint32_t *__serial); + +int rbug_send_shader_list_reply(struct rbug_connection *__con, + uint32_t serial, + rbug_shader_t *shaders, + uint32_t shaders_len, + uint32_t *__serial); + +int rbug_send_shader_info_reply(struct rbug_connection *__con, + uint32_t serial, + uint32_t *original, + uint32_t original_len, + uint32_t *replaced, + uint32_t replaced_len, + uint8_t disabled, + uint32_t *__serial); + +struct rbug_proto_shader_list * rbug_demarshal_shader_list(struct rbug_proto_header *header); + +struct rbug_proto_shader_info * rbug_demarshal_shader_info(struct rbug_proto_header *header); + +struct rbug_proto_shader_disable * rbug_demarshal_shader_disable(struct rbug_proto_header *header); + +struct rbug_proto_shader_replace * rbug_demarshal_shader_replace(struct rbug_proto_header *header); + +struct rbug_proto_shader_list_reply * rbug_demarshal_shader_list_reply(struct rbug_proto_header *header); + +struct rbug_proto_shader_info_reply * rbug_demarshal_shader_info_reply(struct rbug_proto_header *header); + +#endif diff --git a/src/gallium/auxiliary/rbug/rbug_texture.c b/src/gallium/auxiliary/rbug/rbug_texture.c new file mode 100644 index 0000000..2ad5779 --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_texture.c @@ -0,0 +1,631 @@ +/* + * 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 + * 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 + * VMWARE 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. + */ + +/* + * This file holds the function implementation for one of the rbug extensions. + * Prototypes and declerations of functions and structs is in the same folder + * in the header file matching this file's name. + * + * The functions starting rbug_send_* encodes a call to the write format and + * sends that to the supplied connection, while functions starting with + * rbug_demarshal_* demarshal data in the wire protocol. + * + * Functions ending with _reply are replies to requests. + */ + +#include "rbug_internal.h" +#include "rbug/rbug_texture.h" + +int rbug_send_texture_list(struct rbug_connection *__con, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_TEXTURE_LIST, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_texture_info(struct rbug_connection *__con, + rbug_texture_t texture, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(8); /* texture */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(8, rbug_texture_t, texture); /* texture */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_TEXTURE_INFO, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_texture_write(struct rbug_connection *__con, + rbug_texture_t texture, + uint32_t face, + uint32_t level, + uint32_t zslice, + uint32_t x, + uint32_t y, + uint32_t w, + uint32_t h, + uint8_t *data, + uint32_t data_len, + uint32_t stride, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(8); /* texture */ + LEN(4); /* face */ + LEN(4); /* level */ + LEN(4); /* zslice */ + LEN(4); /* x */ + LEN(4); /* y */ + LEN(4); /* w */ + LEN(4); /* h */ + LEN_ARRAY(1, data); /* data */ + LEN(4); /* stride */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_WRITE)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(8, rbug_texture_t, texture); /* texture */ + WRITE(4, uint32_t, face); /* face */ + WRITE(4, uint32_t, level); /* level */ + WRITE(4, uint32_t, zslice); /* zslice */ + WRITE(4, uint32_t, x); /* x */ + WRITE(4, uint32_t, y); /* y */ + WRITE(4, uint32_t, w); /* w */ + WRITE(4, uint32_t, h); /* h */ + WRITE_ARRAY(1, uint8_t, data); /* data */ + WRITE(4, uint32_t, stride); /* stride */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_TEXTURE_WRITE, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_texture_read(struct rbug_connection *__con, + rbug_texture_t texture, + uint32_t face, + uint32_t level, + uint32_t zslice, + uint32_t x, + uint32_t y, + uint32_t w, + uint32_t h, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(8); /* texture */ + LEN(4); /* face */ + LEN(4); /* level */ + LEN(4); /* zslice */ + LEN(4); /* x */ + LEN(4); /* y */ + LEN(4); /* w */ + LEN(4); /* h */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(8, rbug_texture_t, texture); /* texture */ + WRITE(4, uint32_t, face); /* face */ + WRITE(4, uint32_t, level); /* level */ + WRITE(4, uint32_t, zslice); /* zslice */ + WRITE(4, uint32_t, x); /* x */ + WRITE(4, uint32_t, y); /* y */ + WRITE(4, uint32_t, w); /* w */ + WRITE(4, uint32_t, h); /* h */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_TEXTURE_READ, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_texture_list_reply(struct rbug_connection *__con, + uint32_t serial, + rbug_texture_t *textures, + uint32_t textures_len, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(4); /* serial */ + LEN_ARRAY(8, textures); /* textures */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_LIST_REPLY)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(4, uint32_t, serial); /* serial */ + WRITE_ARRAY(8, rbug_texture_t, textures); /* textures */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_TEXTURE_LIST_REPLY, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_texture_info_reply(struct rbug_connection *__con, + uint32_t serial, + uint32_t target, + uint32_t format, + uint32_t *width, + uint32_t width_len, + uint32_t *height, + uint32_t height_len, + uint32_t *depth, + uint32_t depth_len, + uint32_t blockw, + uint32_t blockh, + uint32_t blocksize, + uint32_t last_level, + uint32_t nr_samples, + uint32_t tex_usage, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(4); /* serial */ + LEN(4); /* target */ + LEN(4); /* format */ + LEN_ARRAY(4, width); /* width */ + LEN_ARRAY(4, height); /* height */ + LEN_ARRAY(4, depth); /* depth */ + LEN(4); /* blockw */ + LEN(4); /* blockh */ + LEN(4); /* blocksize */ + LEN(4); /* last_level */ + LEN(4); /* nr_samples */ + LEN(4); /* tex_usage */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_INFO_REPLY)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(4, uint32_t, serial); /* serial */ + WRITE(4, uint32_t, target); /* target */ + WRITE(4, uint32_t, format); /* format */ + WRITE_ARRAY(4, uint32_t, width); /* width */ + WRITE_ARRAY(4, uint32_t, height); /* height */ + WRITE_ARRAY(4, uint32_t, depth); /* depth */ + WRITE(4, uint32_t, blockw); /* blockw */ + WRITE(4, uint32_t, blockh); /* blockh */ + WRITE(4, uint32_t, blocksize); /* blocksize */ + WRITE(4, uint32_t, last_level); /* last_level */ + WRITE(4, uint32_t, nr_samples); /* nr_samples */ + WRITE(4, uint32_t, tex_usage); /* tex_usage */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_TEXTURE_INFO_REPLY, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +int rbug_send_texture_read_reply(struct rbug_connection *__con, + uint32_t serial, + uint32_t format, + uint32_t blockw, + uint32_t blockh, + uint32_t blocksize, + uint8_t *data, + uint32_t data_len, + uint32_t stride, + uint32_t *__serial) +{ + uint32_t __len = 0; + uint32_t __pos = 0; + uint8_t *__data = NULL; + int __ret = 0; + + LEN(8); /* header */ + LEN(4); /* serial */ + LEN(4); /* format */ + LEN(4); /* blockw */ + LEN(4); /* blockh */ + LEN(4); /* blocksize */ + LEN_ARRAY(1, data); /* data */ + LEN(4); /* stride */ + + /* align */ + PAD(__len, 8); + + __data = (uint8_t*)MALLOC(__len); + if (!__data) + return -ENOMEM; + + WRITE(4, int32_t, ((int32_t)RBUG_OP_TEXTURE_READ_REPLY)); + WRITE(4, uint32_t, ((uint32_t)(__len / 4))); + WRITE(4, uint32_t, serial); /* serial */ + WRITE(4, uint32_t, format); /* format */ + WRITE(4, uint32_t, blockw); /* blockw */ + WRITE(4, uint32_t, blockh); /* blockh */ + WRITE(4, uint32_t, blocksize); /* blocksize */ + WRITE_ARRAY(1, uint8_t, data); /* data */ + WRITE(4, uint32_t, stride); /* stride */ + + /* final pad */ + PAD(__pos, 8); + + if (__pos != __len) { + __ret = -EINVAL; + } else { + rbug_connection_send_start(__con, RBUG_OP_TEXTURE_READ_REPLY, __len); + rbug_connection_write(__con, __data, __len); + __ret = rbug_connection_send_finish(__con, __serial); + } + + FREE(__data); + return __ret; +} + +struct rbug_proto_texture_list * rbug_demarshal_texture_list(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_texture_list *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_TEXTURE_LIST) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + + return ret; +} + +struct rbug_proto_texture_info * rbug_demarshal_texture_info(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_texture_info *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_TEXTURE_INFO) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(8, rbug_texture_t, texture); /* texture */ + + return ret; +} + +struct rbug_proto_texture_write * rbug_demarshal_texture_write(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_texture_write *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_TEXTURE_WRITE) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(8, rbug_texture_t, texture); /* texture */ + READ(4, uint32_t, face); /* face */ + READ(4, uint32_t, level); /* level */ + READ(4, uint32_t, zslice); /* zslice */ + READ(4, uint32_t, x); /* x */ + READ(4, uint32_t, y); /* y */ + READ(4, uint32_t, w); /* w */ + READ(4, uint32_t, h); /* h */ + READ_ARRAY(1, uint8_t, data); /* data */ + READ(4, uint32_t, stride); /* stride */ + + return ret; +} + +struct rbug_proto_texture_read * rbug_demarshal_texture_read(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_texture_read *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_TEXTURE_READ) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(8, rbug_texture_t, texture); /* texture */ + READ(4, uint32_t, face); /* face */ + READ(4, uint32_t, level); /* level */ + READ(4, uint32_t, zslice); /* zslice */ + READ(4, uint32_t, x); /* x */ + READ(4, uint32_t, y); /* y */ + READ(4, uint32_t, w); /* w */ + READ(4, uint32_t, h); /* h */ + + return ret; +} + +struct rbug_proto_texture_list_reply * rbug_demarshal_texture_list_reply(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_texture_list_reply *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_TEXTURE_LIST_REPLY) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(4, uint32_t, serial); /* serial */ + READ_ARRAY(8, rbug_texture_t, textures); /* textures */ + + return ret; +} + +struct rbug_proto_texture_info_reply * rbug_demarshal_texture_info_reply(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_texture_info_reply *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_TEXTURE_INFO_REPLY) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(4, uint32_t, serial); /* serial */ + READ(4, uint32_t, target); /* target */ + READ(4, uint32_t, format); /* format */ + READ_ARRAY(4, uint32_t, width); /* width */ + READ_ARRAY(4, uint32_t, height); /* height */ + READ_ARRAY(4, uint32_t, depth); /* depth */ + READ(4, uint32_t, blockw); /* blockw */ + READ(4, uint32_t, blockh); /* blockh */ + READ(4, uint32_t, blocksize); /* blocksize */ + READ(4, uint32_t, last_level); /* last_level */ + READ(4, uint32_t, nr_samples); /* nr_samples */ + READ(4, uint32_t, tex_usage); /* tex_usage */ + + return ret; +} + +struct rbug_proto_texture_read_reply * rbug_demarshal_texture_read_reply(struct rbug_proto_header *header) +{ + uint32_t len = 0; + uint32_t pos = 0; + uint8_t *data = NULL; + struct rbug_proto_texture_read_reply *ret; + + if (!header) + return NULL; + if (header->opcode != (int32_t)RBUG_OP_TEXTURE_READ_REPLY) + return NULL; + + pos = 0; + len = header->length * 4; + data = (uint8_t*)&header[1]; + ret = MALLOC(sizeof(*ret)); + if (!ret) + return NULL; + + ret->header.__message = header; + ret->header.opcode = header->opcode; + + READ(4, uint32_t, serial); /* serial */ + READ(4, uint32_t, format); /* format */ + READ(4, uint32_t, blockw); /* blockw */ + READ(4, uint32_t, blockh); /* blockh */ + READ(4, uint32_t, blocksize); /* blocksize */ + READ_ARRAY(1, uint8_t, data); /* data */ + READ(4, uint32_t, stride); /* stride */ + + return ret; +} diff --git a/src/gallium/auxiliary/rbug/rbug_texture.h b/src/gallium/auxiliary/rbug/rbug_texture.h new file mode 100644 index 0000000..fbb247e --- /dev/null +++ b/src/gallium/auxiliary/rbug/rbug_texture.h @@ -0,0 +1,206 @@ +/* + * 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 + * 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 + * VMWARE 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. + */ + +/* + * This file holds structs decelerations and function prototypes for one of + * the rbug extensions. Implementation of the functions is in the same folder + * in the c file matching this file's name. + * + * The structs what is returned from the demarshal functions. The functions + * starting rbug_send_* encodes a call to the write format and sends that to + * the supplied connection, while functions starting with rbug_demarshal_* + * demarshal data from the wire protocol. + * + * Structs and functions ending with _reply are replies to requests. + */ + +#ifndef _RBUG_PROTO_TEXTURE_H_ +#define _RBUG_PROTO_TEXTURE_H_ + +#include "rbug/rbug_proto.h" +#include "rbug/rbug_core.h" + +struct rbug_proto_texture_list +{ + struct rbug_header header; +}; + +struct rbug_proto_texture_info +{ + struct rbug_header header; + rbug_texture_t texture; +}; + +struct rbug_proto_texture_write +{ + struct rbug_header header; + rbug_texture_t texture; + uint32_t face; + uint32_t level; + uint32_t zslice; + uint32_t x; + uint32_t y; + uint32_t w; + uint32_t h; + uint8_t *data; + uint32_t data_len; + uint32_t stride; +}; + +struct rbug_proto_texture_read +{ + struct rbug_header header; + rbug_texture_t texture; + uint32_t face; + uint32_t level; + uint32_t zslice; + uint32_t x; + uint32_t y; + uint32_t w; + uint32_t h; +}; + +struct rbug_proto_texture_list_reply +{ + struct rbug_header header; + uint32_t serial; + rbug_texture_t *textures; + uint32_t textures_len; +}; + +struct rbug_proto_texture_info_reply +{ + struct rbug_header header; + uint32_t serial; + uint32_t target; + uint32_t format; + uint32_t *width; + uint32_t width_len; + uint32_t *height; + uint32_t height_len; + uint32_t *depth; + uint32_t depth_len; + uint32_t blockw; + uint32_t blockh; + uint32_t blocksize; + uint32_t last_level; + uint32_t nr_samples; + uint32_t tex_usage; +}; + +struct rbug_proto_texture_read_reply +{ + struct rbug_header header; + uint32_t serial; + uint32_t format; + uint32_t blockw; + uint32_t blockh; + uint32_t blocksize; + uint8_t *data; + uint32_t data_len; + uint32_t stride; +}; + +int rbug_send_texture_list(struct rbug_connection *__con, + uint32_t *__serial); + +int rbug_send_texture_info(struct rbug_connection *__con, + rbug_texture_t texture, + uint32_t *__serial); + +int rbug_send_texture_write(struct rbug_connection *__con, + rbug_texture_t texture, + uint32_t face, + uint32_t level, + uint32_t zslice, + uint32_t x, + uint32_t y, + uint32_t w, + uint32_t h, + uint8_t *data, + uint32_t data_len, + uint32_t stride, + uint32_t *__serial); + +int rbug_send_texture_read(struct rbug_connection *__con, + rbug_texture_t texture, + uint32_t face, + uint32_t level, + uint32_t zslice, + uint32_t x, + uint32_t y, + uint32_t w, + uint32_t h, + uint32_t *__serial); + +int rbug_send_texture_list_reply(struct rbug_connection *__con, + uint32_t serial, + rbug_texture_t *textures, + uint32_t textures_len, + uint32_t *__serial); + +int rbug_send_texture_info_reply(struct rbug_connection *__con, + uint32_t serial, + uint32_t target, + uint32_t format, + uint32_t *width, + uint32_t width_len, + uint32_t *height, + uint32_t height_len, + uint32_t *depth, + uint32_t depth_len, + uint32_t blockw, + uint32_t blockh, + uint32_t blocksize, + uint32_t last_level, + uint32_t nr_samples, + uint32_t tex_usage, + uint32_t *__serial); + +int rbug_send_texture_read_reply(struct rbug_connection *__con, + uint32_t serial, + uint32_t format, + uint32_t blockw, + uint32_t blockh, + uint32_t blocksize, + uint8_t *data, + uint32_t data_len, + uint32_t stride, + uint32_t *__serial); + +struct rbug_proto_texture_list * rbug_demarshal_texture_list(struct rbug_proto_header *header); + +struct rbug_proto_texture_info * rbug_demarshal_texture_info(struct rbug_proto_header *header); + +struct rbug_proto_texture_write * rbug_demarshal_texture_write(struct rbug_proto_header *header); + +struct rbug_proto_texture_read * rbug_demarshal_texture_read(struct rbug_proto_header *header); + +struct rbug_proto_texture_list_reply * rbug_demarshal_texture_list_reply(struct rbug_proto_header *header); + +struct rbug_proto_texture_info_reply * rbug_demarshal_texture_info_reply(struct rbug_proto_header *header); + +struct rbug_proto_texture_read_reply * rbug_demarshal_texture_read_reply(struct rbug_proto_header *header); + +#endif diff --git a/src/gallium/auxiliary/rtasm/rtasm_cpu.c b/src/gallium/auxiliary/rtasm/rtasm_cpu.c new file mode 100644 index 0000000..0461c81 --- /dev/null +++ b/src/gallium/auxiliary/rtasm/rtasm_cpu.c @@ -0,0 +1,67 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "util/u_debug.h" +#include "rtasm_cpu.h" + + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) +static boolean rtasm_sse_enabled(void) +{ + static boolean firsttime = 1; + static boolean enabled; + + /* This gets called quite often at the moment: + */ + if (firsttime) { + enabled = !debug_get_bool_option("GALLIUM_NOSSE", FALSE); + firsttime = FALSE; + } + return enabled; +} +#endif + +int rtasm_cpu_has_sse(void) +{ + /* FIXME: actually detect this at run-time */ +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) + return rtasm_sse_enabled(); +#else + return 0; +#endif +} + +int rtasm_cpu_has_sse2(void) +{ + /* FIXME: actually detect this at run-time */ +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) + return rtasm_sse_enabled(); +#else + return 0; +#endif +} diff --git a/src/gallium/auxiliary/rtasm/rtasm_cpu.h b/src/gallium/auxiliary/rtasm/rtasm_cpu.h new file mode 100644 index 0000000..ebc7163 --- /dev/null +++ b/src/gallium/auxiliary/rtasm/rtasm_cpu.h @@ -0,0 +1,42 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Runtime detection of CPU capabilities. + */ + +#ifndef _RTASM_CPU_H_ +#define _RTASM_CPU_H_ + + +int rtasm_cpu_has_sse(void); + +int rtasm_cpu_has_sse2(void); + + +#endif /* _RTASM_CPU_H_ */ diff --git a/src/gallium/auxiliary/rtasm/rtasm_execmem.c b/src/gallium/auxiliary/rtasm/rtasm_execmem.c new file mode 100644 index 0000000..fbde1d1 --- /dev/null +++ b/src/gallium/auxiliary/rtasm/rtasm_execmem.c @@ -0,0 +1,168 @@ +/************************************************************************** + * + * Copyright (C) 1999-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. + * + **************************************************************************/ + + +/** + * \file exemem.c + * Functions for allocating executable memory. + * + * \author Keith Whitwell + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" +#include "os/os_thread.h" +#include "util/u_memory.h" + +#include "rtasm_execmem.h" + +#if defined(PIPE_OS_BSD) +#define MAP_ANONYMOUS MAP_ANON +#endif + +#if defined(PIPE_OS_WINDOWS) +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#include +#endif + +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) + + +/* + * Allocate a large block of memory which can hold code then dole it out + * in pieces by means of the generic memory manager code. + */ + +#include +#include +#include "util/u_mm.h" + +#define EXEC_HEAP_SIZE (10*1024*1024) + +pipe_static_mutex(exec_mutex); + +static struct mem_block *exec_heap = NULL; +static unsigned char *exec_mem = NULL; + + +static void +init_heap(void) +{ + if (!exec_heap) + exec_heap = u_mmInit( 0, EXEC_HEAP_SIZE ); + + if (!exec_mem) + exec_mem = (unsigned char *) mmap(0, EXEC_HEAP_SIZE, + PROT_EXEC | PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); +} + + +void * +rtasm_exec_malloc(size_t size) +{ + struct mem_block *block = NULL; + void *addr = NULL; + + pipe_mutex_lock(exec_mutex); + + init_heap(); + + if (exec_heap) { + size = (size + 31) & ~31; /* next multiple of 32 bytes */ + block = u_mmAllocMem( exec_heap, size, 5, 0 ); /* 5 -> 32-byte alignment */ + } + + if (block) + addr = exec_mem + block->ofs; + else + debug_printf("rtasm_exec_malloc failed\n"); + + pipe_mutex_unlock(exec_mutex); + + return addr; +} + + +void +rtasm_exec_free(void *addr) +{ + pipe_mutex_lock(exec_mutex); + + if (exec_heap) { + struct mem_block *block = u_mmFindBlock(exec_heap, (unsigned char *)addr - exec_mem); + + if (block) + u_mmFreeMem(block); + } + + pipe_mutex_unlock(exec_mutex); +} + + +#elif defined(PIPE_OS_WINDOWS) + + +/* + * Avoid Data Execution Prevention. + */ + +void * +rtasm_exec_malloc(size_t size) +{ + return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); +} + + +void +rtasm_exec_free(void *addr) +{ + VirtualFree(addr, 0, MEM_RELEASE); +} + + +#else + + +/* + * Just use regular memory. + */ + +void * +rtasm_exec_malloc(size_t size) +{ + return MALLOC( size ); +} + + +void +rtasm_exec_free(void *addr) +{ + FREE(addr); +} + + +#endif diff --git a/src/gallium/auxiliary/rtasm/rtasm_execmem.h b/src/gallium/auxiliary/rtasm/rtasm_execmem.h new file mode 100644 index 0000000..155c6d3 --- /dev/null +++ b/src/gallium/auxiliary/rtasm/rtasm_execmem.h @@ -0,0 +1,45 @@ +/************************************************************************** + * + * Copyright (C) 1999-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. + * + **************************************************************************/ + +/** + * \file exemem.c + * Functions for allocating executable memory. + * + * \author Keith Whitwell + */ + +#ifndef _RTASM_EXECMEM_H_ +#define _RTASM_EXECMEM_H_ + +#include "pipe/p_compiler.h" + + +extern void * +rtasm_exec_malloc( size_t size ); + + +extern void +rtasm_exec_free( void *addr ); + + +#endif diff --git a/src/gallium/auxiliary/rtasm/rtasm_ppc.c b/src/gallium/auxiliary/rtasm/rtasm_ppc.c new file mode 100644 index 0000000..330838d --- /dev/null +++ b/src/gallium/auxiliary/rtasm/rtasm_ppc.c @@ -0,0 +1,1077 @@ +/************************************************************************** + * + * Copyright (C) 2008 Tungsten Graphics, Inc. All Rights Reserved. + * Copyright (C) 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 + * 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. + * + **************************************************************************/ + +/** + * PPC code generation. + * For reference, see http://www.power.org/resources/reading/PowerISA_V2.05.pdf + * ABI info: http://www.cs.utsa.edu/~whaley/teach/cs6463FHPO/LEC/lec12_ho.pdf + * + * Other PPC refs: + * http://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/852569B20050FF778525699600719DF2 + * http://www.ibm.com/developerworks/eserver/library/es-archguide-v2.html + * http://www.freescale.com/files/product/doc/MPCFPE32B.pdf + * + * \author Brian Paul + */ + + +#include +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "rtasm_execmem.h" +#include "rtasm_ppc.h" + + +void +ppc_init_func(struct ppc_function *p) +{ + uint i; + + memset(p, 0, sizeof(*p)); + + p->num_inst = 0; + p->max_inst = 100; /* first guess at buffer size */ + p->store = rtasm_exec_malloc(p->max_inst * PPC_INST_SIZE); + p->reg_used = 0x0; + p->fp_used = 0x0; + p->vec_used = 0x0; + + p->print = FALSE; + p->indent = 0; + + /* only allow using gp registers 3..12 for now */ + for (i = 0; i < 3; i++) + ppc_reserve_register(p, i); + for (i = 12; i < PPC_NUM_REGS; i++) + ppc_reserve_register(p, i); +} + + +void +ppc_release_func(struct ppc_function *p) +{ + assert(p->num_inst <= p->max_inst); + if (p->store != NULL) { + rtasm_exec_free(p->store); + } + p->store = NULL; +} + + +uint +ppc_num_instructions(const struct ppc_function *p) +{ + return p->num_inst; +} + + +void (*ppc_get_func(struct ppc_function *p))(void) +{ +#if 0 + DUMP_END(); + if (DISASSEM && p->store) + debug_printf("disassemble %p %p\n", p->store, p->csr); + + if (p->store == p->error_overflow) + return (void (*)(void)) NULL; + else +#endif + return (void (*)(void)) pointer_to_func(p->store); +} + + +void +ppc_dump_func(const struct ppc_function *p) +{ + uint i; + for (i = 0; i < p->num_inst; i++) { + debug_printf("%3u: 0x%08x\n", i, p->store[i]); + } +} + + +void +ppc_print_code(struct ppc_function *p, boolean enable) +{ + p->print = enable; +} + + +void +ppc_indent(struct ppc_function *p, int spaces) +{ + p->indent += spaces; +} + + +static void +indent(const struct ppc_function *p) +{ + int i; + for (i = 0; i < p->indent; i++) { + putchar(' '); + } +} + + +void +ppc_comment(struct ppc_function *p, int rel_indent, const char *s) +{ + if (p->print) { + p->indent += rel_indent; + indent(p); + p->indent -= rel_indent; + printf("# %s\n", s); + } +} + + +/** + * Mark a register as being unavailable. + */ +int +ppc_reserve_register(struct ppc_function *p, int reg) +{ + assert(reg < PPC_NUM_REGS); + p->reg_used |= (1 << reg); + return reg; +} + + +/** + * Allocate a general purpose register. + * \return register index or -1 if none left. + */ +int +ppc_allocate_register(struct ppc_function *p) +{ + unsigned i; + for (i = 0; i < PPC_NUM_REGS; i++) { + const uint32_t mask = 1 << i; + if ((p->reg_used & mask) == 0) { + p->reg_used |= mask; + return i; + } + } + printf("OUT OF PPC registers!\n"); + return -1; +} + + +/** + * Mark the given general purpose register as "unallocated". + */ +void +ppc_release_register(struct ppc_function *p, int reg) +{ + assert(reg < PPC_NUM_REGS); + assert(p->reg_used & (1 << reg)); + p->reg_used &= ~(1 << reg); +} + + +/** + * Allocate a floating point register. + * \return register index or -1 if none left. + */ +int +ppc_allocate_fp_register(struct ppc_function *p) +{ + unsigned i; + for (i = 0; i < PPC_NUM_FP_REGS; i++) { + const uint32_t mask = 1 << i; + if ((p->fp_used & mask) == 0) { + p->fp_used |= mask; + return i; + } + } + printf("OUT OF PPC FP registers!\n"); + return -1; +} + + +/** + * Mark the given floating point register as "unallocated". + */ +void +ppc_release_fp_register(struct ppc_function *p, int reg) +{ + assert(reg < PPC_NUM_FP_REGS); + assert(p->fp_used & (1 << reg)); + p->fp_used &= ~(1 << reg); +} + + +/** + * Allocate a vector register. + * \return register index or -1 if none left. + */ +int +ppc_allocate_vec_register(struct ppc_function *p) +{ + unsigned i; + for (i = 0; i < PPC_NUM_VEC_REGS; i++) { + const uint32_t mask = 1 << i; + if ((p->vec_used & mask) == 0) { + p->vec_used |= mask; + return i; + } + } + printf("OUT OF PPC VEC registers!\n"); + return -1; +} + + +/** + * Mark the given vector register as "unallocated". + */ +void +ppc_release_vec_register(struct ppc_function *p, int reg) +{ + assert(reg < PPC_NUM_VEC_REGS); + assert(p->vec_used & (1 << reg)); + p->vec_used &= ~(1 << reg); +} + + +/** + * Append instruction to instruction buffer. Grow buffer if out of room. + */ +static void +emit_instruction(struct ppc_function *p, uint32_t inst_bits) +{ + if (!p->store) + return; /* out of memory, drop the instruction */ + + if (p->num_inst == p->max_inst) { + /* allocate larger buffer */ + uint32_t *newbuf; + p->max_inst *= 2; /* 2x larger */ + newbuf = rtasm_exec_malloc(p->max_inst * PPC_INST_SIZE); + if (newbuf) { + memcpy(newbuf, p->store, p->num_inst * PPC_INST_SIZE); + } + rtasm_exec_free(p->store); + p->store = newbuf; + if (!p->store) { + /* out of memory */ + p->num_inst = 0; + return; + } + } + + p->store[p->num_inst++] = inst_bits; +} + + +union vx_inst { + uint32_t bits; + struct { + unsigned op:6; + unsigned vD:5; + unsigned vA:5; + unsigned vB:5; + unsigned op2:11; + } inst; +}; + +static INLINE void +emit_vx(struct ppc_function *p, uint op2, uint vD, uint vA, uint vB, + const char *format, boolean transpose) +{ + union vx_inst inst; + inst.inst.op = 4; + inst.inst.vD = vD; + inst.inst.vA = vA; + inst.inst.vB = vB; + inst.inst.op2 = op2; + emit_instruction(p, inst.bits); + if (p->print) { + indent(p); + if (transpose) + printf(format, vD, vB, vA); + else + printf(format, vD, vA, vB); + } +} + + +union vxr_inst { + uint32_t bits; + struct { + unsigned op:6; + unsigned vD:5; + unsigned vA:5; + unsigned vB:5; + unsigned rC:1; + unsigned op2:10; + } inst; +}; + +static INLINE void +emit_vxr(struct ppc_function *p, uint op2, uint vD, uint vA, uint vB, + const char *format) +{ + union vxr_inst inst; + inst.inst.op = 4; + inst.inst.vD = vD; + inst.inst.vA = vA; + inst.inst.vB = vB; + inst.inst.rC = 0; + inst.inst.op2 = op2; + emit_instruction(p, inst.bits); + if (p->print) { + indent(p); + printf(format, vD, vA, vB); + } +} + + +union va_inst { + uint32_t bits; + struct { + unsigned op:6; + unsigned vD:5; + unsigned vA:5; + unsigned vB:5; + unsigned vC:5; + unsigned op2:6; + } inst; +}; + +static INLINE void +emit_va(struct ppc_function *p, uint op2, uint vD, uint vA, uint vB, uint vC, + const char *format) +{ + union va_inst inst; + inst.inst.op = 4; + inst.inst.vD = vD; + inst.inst.vA = vA; + inst.inst.vB = vB; + inst.inst.vC = vC; + inst.inst.op2 = op2; + emit_instruction(p, inst.bits); + if (p->print) { + indent(p); + printf(format, vD, vA, vB, vC); + } +} + + +union i_inst { + uint32_t bits; + struct { + unsigned op:6; + unsigned li:24; + unsigned aa:1; + unsigned lk:1; + } inst; +}; + +static INLINE void +emit_i(struct ppc_function *p, uint op, uint li, uint aa, uint lk) +{ + union i_inst inst; + inst.inst.op = op; + inst.inst.li = li; + inst.inst.aa = aa; + inst.inst.lk = lk; + emit_instruction(p, inst.bits); +} + + +union xl_inst { + uint32_t bits; + struct { + unsigned op:6; + unsigned bo:5; + unsigned bi:5; + unsigned unused:3; + unsigned bh:2; + unsigned op2:10; + unsigned lk:1; + } inst; +}; + +static INLINE void +emit_xl(struct ppc_function *p, uint op, uint bo, uint bi, uint bh, + uint op2, uint lk) +{ + union xl_inst inst; + inst.inst.op = op; + inst.inst.bo = bo; + inst.inst.bi = bi; + inst.inst.unused = 0x0; + inst.inst.bh = bh; + inst.inst.op2 = op2; + inst.inst.lk = lk; + emit_instruction(p, inst.bits); +} + +static INLINE void +dump_xl(const char *name, uint inst) +{ + union xl_inst i; + + i.bits = inst; + debug_printf("%s = 0x%08x\n", name, inst); + debug_printf(" op: %d 0x%x\n", i.inst.op, i.inst.op); + debug_printf(" bo: %d 0x%x\n", i.inst.bo, i.inst.bo); + debug_printf(" bi: %d 0x%x\n", i.inst.bi, i.inst.bi); + debug_printf(" unused: %d 0x%x\n", i.inst.unused, i.inst.unused); + debug_printf(" bh: %d 0x%x\n", i.inst.bh, i.inst.bh); + debug_printf(" op2: %d 0x%x\n", i.inst.op2, i.inst.op2); + debug_printf(" lk: %d 0x%x\n", i.inst.lk, i.inst.lk); +} + + +union x_inst { + uint32_t bits; + struct { + unsigned op:6; + unsigned vrs:5; + unsigned ra:5; + unsigned rb:5; + unsigned op2:10; + unsigned unused:1; + } inst; +}; + +static INLINE void +emit_x(struct ppc_function *p, uint op, uint vrs, uint ra, uint rb, uint op2, + const char *format) +{ + union x_inst inst; + inst.inst.op = op; + inst.inst.vrs = vrs; + inst.inst.ra = ra; + inst.inst.rb = rb; + inst.inst.op2 = op2; + inst.inst.unused = 0x0; + emit_instruction(p, inst.bits); + if (p->print) { + indent(p); + printf(format, vrs, ra, rb); + } +} + + +union d_inst { + uint32_t bits; + struct { + unsigned op:6; + unsigned rt:5; + unsigned ra:5; + unsigned si:16; + } inst; +}; + +static INLINE void +emit_d(struct ppc_function *p, uint op, uint rt, uint ra, int si, + const char *format, boolean transpose) +{ + union d_inst inst; + assert(si >= -32768); + assert(si <= 32767); + inst.inst.op = op; + inst.inst.rt = rt; + inst.inst.ra = ra; + inst.inst.si = (unsigned) (si & 0xffff); + emit_instruction(p, inst.bits); + if (p->print) { + indent(p); + if (transpose) + printf(format, rt, si, ra); + else + printf(format, rt, ra, si); + } +} + + +union a_inst { + uint32_t bits; + struct { + unsigned op:6; + unsigned frt:5; + unsigned fra:5; + unsigned frb:5; + unsigned unused:5; + unsigned op2:5; + unsigned rc:1; + } inst; +}; + +static INLINE void +emit_a(struct ppc_function *p, uint op, uint frt, uint fra, uint frb, uint op2, + uint rc, const char *format) +{ + union a_inst inst; + inst.inst.op = op; + inst.inst.frt = frt; + inst.inst.fra = fra; + inst.inst.frb = frb; + inst.inst.unused = 0x0; + inst.inst.op2 = op2; + inst.inst.rc = rc; + emit_instruction(p, inst.bits); + if (p->print) { + indent(p); + printf(format, frt, fra, frb); + } +} + + +union xo_inst { + uint32_t bits; + struct { + unsigned op:6; + unsigned rt:5; + unsigned ra:5; + unsigned rb:5; + unsigned oe:1; + unsigned op2:9; + unsigned rc:1; + } inst; +}; + +static INLINE void +emit_xo(struct ppc_function *p, uint op, uint rt, uint ra, uint rb, uint oe, + uint op2, uint rc, const char *format) +{ + union xo_inst inst; + inst.inst.op = op; + inst.inst.rt = rt; + inst.inst.ra = ra; + inst.inst.rb = rb; + inst.inst.oe = oe; + inst.inst.op2 = op2; + inst.inst.rc = rc; + emit_instruction(p, inst.bits); + if (p->print) { + indent(p); + printf(format, rt, ra, rb); + } +} + + + + + +/** + ** float vector arithmetic + **/ + +/** vector float add */ +void +ppc_vaddfp(struct ppc_function *p, uint vD, uint vA, uint vB) +{ + emit_vx(p, 10, vD, vA, vB, "vaddfp\t%u, v%u, v%u\n", FALSE); +} + +/** vector float substract */ +void +ppc_vsubfp(struct ppc_function *p, uint vD, uint vA, uint vB) +{ + emit_vx(p, 74, vD, vA, vB, "vsubfp\tv%u, v%u, v%u\n", FALSE); +} + +/** vector float min */ +void +ppc_vminfp(struct ppc_function *p, uint vD, uint vA, uint vB) +{ + emit_vx(p, 1098, vD, vA, vB, "vminfp\tv%u, v%u, v%u\n", FALSE); +} + +/** vector float max */ +void +ppc_vmaxfp(struct ppc_function *p, uint vD, uint vA, uint vB) +{ + emit_vx(p, 1034, vD, vA, vB, "vmaxfp\tv%u, v%u, v%u\n", FALSE); +} + +/** vector float mult add: vD = vA * vB + vC */ +void +ppc_vmaddfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC) +{ + /* note arg order */ + emit_va(p, 46, vD, vA, vC, vB, "vmaddfp\tv%u, v%u, v%u, v%u\n"); +} + +/** vector float negative mult subtract: vD = vA - vB * vC */ +void +ppc_vnmsubfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC) +{ + /* note arg order */ + emit_va(p, 47, vD, vB, vA, vC, "vnmsubfp\tv%u, v%u, v%u, v%u\n"); +} + +/** vector float compare greater than */ +void +ppc_vcmpgtfpx(struct ppc_function *p, uint vD, uint vA, uint vB) +{ + emit_vxr(p, 710, vD, vA, vB, "vcmpgtfpx\tv%u, v%u, v%u"); +} + +/** vector float compare greater than or equal to */ +void +ppc_vcmpgefpx(struct ppc_function *p, uint vD, uint vA, uint vB) +{ + emit_vxr(p, 454, vD, vA, vB, "vcmpgefpx\tv%u, v%u, v%u"); +} + +/** vector float compare equal */ +void +ppc_vcmpeqfpx(struct ppc_function *p, uint vD, uint vA, uint vB) +{ + emit_vxr(p, 198, vD, vA, vB, "vcmpeqfpx\tv%u, v%u, v%u"); +} + +/** vector float 2^x */ +void +ppc_vexptefp(struct ppc_function *p, uint vD, uint vB) +{ + emit_vx(p, 394, vD, 0, vB, "vexptefp\tv%u, 0%u, v%u\n", FALSE); +} + +/** vector float log2(x) */ +void +ppc_vlogefp(struct ppc_function *p, uint vD, uint vB) +{ + emit_vx(p, 458, vD, 0, vB, "vlogefp\tv%u, 0%u, v%u\n", FALSE); +} + +/** vector float reciprocol */ +void +ppc_vrefp(struct ppc_function *p, uint vD, uint vB) +{ + emit_vx(p, 266, vD, 0, vB, "vrefp\tv%u, 0%u, v%u\n", FALSE); +} + +/** vector float reciprocol sqrt estimate */ +void +ppc_vrsqrtefp(struct ppc_function *p, uint vD, uint vB) +{ + emit_vx(p, 330, vD, 0, vB, "vrsqrtefp\tv%u, 0%u, v%u\n", FALSE); +} + +/** vector float round to negative infinity */ +void +ppc_vrfim(struct ppc_function *p, uint vD, uint vB) +{ + emit_vx(p, 714, vD, 0, vB, "vrfim\tv%u, 0%u, v%u\n", FALSE); +} + +/** vector float round to positive infinity */ +void +ppc_vrfip(struct ppc_function *p, uint vD, uint vB) +{ + emit_vx(p, 650, vD, 0, vB, "vrfip\tv%u, 0%u, v%u\n", FALSE); +} + +/** vector float round to nearest int */ +void +ppc_vrfin(struct ppc_function *p, uint vD, uint vB) +{ + emit_vx(p, 522, vD, 0, vB, "vrfin\tv%u, 0%u, v%u\n", FALSE); +} + +/** vector float round to int toward zero */ +void +ppc_vrfiz(struct ppc_function *p, uint vD, uint vB) +{ + emit_vx(p, 586, vD, 0, vB, "vrfiz\tv%u, 0%u, v%u\n", FALSE); +} + +/** vector store: store vR at mem[rA+rB] */ +void +ppc_stvx(struct ppc_function *p, uint vR, uint rA, uint rB) +{ + emit_x(p, 31, vR, rA, rB, 231, "stvx\tv%u, r%u, r%u\n"); +} + +/** vector load: vR = mem[rA+rB] */ +void +ppc_lvx(struct ppc_function *p, uint vR, uint rA, uint rB) +{ + emit_x(p, 31, vR, rA, rB, 103, "lvx\tv%u, r%u, r%u\n"); +} + +/** load vector element word: vR = mem_word[ra+rb] */ +void +ppc_lvewx(struct ppc_function *p, uint vR, uint rA, uint rB) +{ + emit_x(p, 31, vR, rA, rB, 71, "lvewx\tv%u, r%u, r%u\n"); +} + + + + +/** + ** vector bitwise operations + **/ + +/** vector and */ +void +ppc_vand(struct ppc_function *p, uint vD, uint vA, uint vB) +{ + emit_vx(p, 1028, vD, vA, vB, "vand\tv%u, v%u, v%u\n", FALSE); +} + +/** vector and complement */ +void +ppc_vandc(struct ppc_function *p, uint vD, uint vA, uint vB) +{ + emit_vx(p, 1092, vD, vA, vB, "vandc\tv%u, v%u, v%u\n", FALSE); +} + +/** vector or */ +void +ppc_vor(struct ppc_function *p, uint vD, uint vA, uint vB) +{ + emit_vx(p, 1156, vD, vA, vB, "vor\tv%u, v%u, v%u\n", FALSE); +} + +/** vector nor */ +void +ppc_vnor(struct ppc_function *p, uint vD, uint vA, uint vB) +{ + emit_vx(p, 1284, vD, vA, vB, "vnor\tv%u, v%u, v%u\n", FALSE); +} + +/** vector xor */ +void +ppc_vxor(struct ppc_function *p, uint vD, uint vA, uint vB) +{ + emit_vx(p, 1220, vD, vA, vB, "vxor\tv%u, v%u, v%u\n", FALSE); +} + +/** Pseudo-instruction: vector move */ +void +ppc_vmove(struct ppc_function *p, uint vD, uint vA) +{ + boolean print = p->print; + p->print = FALSE; + ppc_vor(p, vD, vA, vA); + if (print) { + indent(p); + printf("vor\tv%u, v%u, v%u \t# v%u = v%u\n", vD, vA, vA, vD, vA); + } + p->print = print; +} + +/** Set vector register to {0,0,0,0} */ +void +ppc_vzero(struct ppc_function *p, uint vr) +{ + boolean print = p->print; + p->print = FALSE; + ppc_vxor(p, vr, vr, vr); + if (print) { + indent(p); + printf("vxor\tv%u, v%u, v%u \t# v%u = {0,0,0,0}\n", vr, vr, vr, vr); + } + p->print = print; +} + + + + +/** + ** Vector shuffle / select / splat / etc + **/ + +/** vector permute */ +void +ppc_vperm(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC) +{ + emit_va(p, 43, vD, vA, vB, vC, "vperm\tr%u, r%u, r%u, r%u"); +} + +/** vector select */ +void +ppc_vsel(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC) +{ + emit_va(p, 42, vD, vA, vB, vC, "vsel\tr%u, r%u, r%u, r%u"); +} + +/** vector splat byte */ +void +ppc_vspltb(struct ppc_function *p, uint vD, uint vB, uint imm) +{ + emit_vx(p, 42, vD, imm, vB, "vspltb\tv%u, v%u, %u\n", TRUE); +} + +/** vector splat half word */ +void +ppc_vsplthw(struct ppc_function *p, uint vD, uint vB, uint imm) +{ + emit_vx(p, 588, vD, imm, vB, "vsplthw\tv%u, v%u, %u\n", TRUE); +} + +/** vector splat word */ +void +ppc_vspltw(struct ppc_function *p, uint vD, uint vB, uint imm) +{ + emit_vx(p, 652, vD, imm, vB, "vspltw\tv%u, v%u, %u\n", TRUE); +} + +/** vector splat signed immediate word */ +void +ppc_vspltisw(struct ppc_function *p, uint vD, int imm) +{ + assert(imm >= -16); + assert(imm < 15); + emit_vx(p, 908, vD, imm, 0, "vspltisw\tv%u, %d, %u\n", FALSE); +} + +/** vector shift left word: vD[word] = vA[word] << (vB[word] & 0x1f) */ +void +ppc_vslw(struct ppc_function *p, uint vD, uint vA, uint vB) +{ + emit_vx(p, 388, vD, vA, vB, "vslw\tv%u, v%u, v%u\n", FALSE); +} + + + + +/** + ** integer arithmetic + **/ + +/** rt = ra + imm */ +void +ppc_addi(struct ppc_function *p, uint rt, uint ra, int imm) +{ + emit_d(p, 14, rt, ra, imm, "addi\tr%u, r%u, %d\n", FALSE); +} + +/** rt = ra + (imm << 16) */ +void +ppc_addis(struct ppc_function *p, uint rt, uint ra, int imm) +{ + emit_d(p, 15, rt, ra, imm, "addis\tr%u, r%u, %d\n", FALSE); +} + +/** rt = ra + rb */ +void +ppc_add(struct ppc_function *p, uint rt, uint ra, uint rb) +{ + emit_xo(p, 31, rt, ra, rb, 0, 266, 0, "add\tr%u, r%u, r%u\n"); +} + +/** rt = ra AND ra */ +void +ppc_and(struct ppc_function *p, uint rt, uint ra, uint rb) +{ + emit_x(p, 31, ra, rt, rb, 28, "and\tr%u, r%u, r%u\n"); /* note argument order */ +} + +/** rt = ra AND imm */ +void +ppc_andi(struct ppc_function *p, uint rt, uint ra, int imm) +{ + /* note argument order */ + emit_d(p, 28, ra, rt, imm, "andi\tr%u, r%u, %d\n", FALSE); +} + +/** rt = ra OR ra */ +void +ppc_or(struct ppc_function *p, uint rt, uint ra, uint rb) +{ + emit_x(p, 31, ra, rt, rb, 444, "or\tr%u, r%u, r%u\n"); /* note argument order */ +} + +/** rt = ra OR imm */ +void +ppc_ori(struct ppc_function *p, uint rt, uint ra, int imm) +{ + /* note argument order */ + emit_d(p, 24, ra, rt, imm, "ori\tr%u, r%u, %d\n", FALSE); +} + +/** rt = ra XOR ra */ +void +ppc_xor(struct ppc_function *p, uint rt, uint ra, uint rb) +{ + emit_x(p, 31, ra, rt, rb, 316, "xor\tr%u, r%u, r%u\n"); /* note argument order */ +} + +/** rt = ra XOR imm */ +void +ppc_xori(struct ppc_function *p, uint rt, uint ra, int imm) +{ + /* note argument order */ + emit_d(p, 26, ra, rt, imm, "xori\tr%u, r%u, %d\n", FALSE); +} + +/** pseudo instruction: move: rt = ra */ +void +ppc_mr(struct ppc_function *p, uint rt, uint ra) +{ + ppc_or(p, rt, ra, ra); +} + +/** pseudo instruction: load immediate: rt = imm */ +void +ppc_li(struct ppc_function *p, uint rt, int imm) +{ + boolean print = p->print; + p->print = FALSE; + ppc_addi(p, rt, 0, imm); + if (print) { + indent(p); + printf("addi\tr%u, r0, %d \t# r%u = %d\n", rt, imm, rt, imm); + } + p->print = print; +} + +/** rt = imm << 16 */ +void +ppc_lis(struct ppc_function *p, uint rt, int imm) +{ + ppc_addis(p, rt, 0, imm); +} + +/** rt = imm */ +void +ppc_load_int(struct ppc_function *p, uint rt, int imm) +{ + ppc_lis(p, rt, (imm >> 16)); /* rt = imm >> 16 */ + ppc_ori(p, rt, rt, (imm & 0xffff)); /* rt = rt | (imm & 0xffff) */ +} + + + + +/** + ** integer load/store + **/ + +/** store rs at memory[(ra)+d], + * then update ra = (ra)+d + */ +void +ppc_stwu(struct ppc_function *p, uint rs, uint ra, int d) +{ + emit_d(p, 37, rs, ra, d, "stwu\tr%u, %d(r%u)\n", TRUE); +} + +/** store rs at memory[(ra)+d] */ +void +ppc_stw(struct ppc_function *p, uint rs, uint ra, int d) +{ + emit_d(p, 36, rs, ra, d, "stw\tr%u, %d(r%u)\n", TRUE); +} + +/** Load rt = mem[(ra)+d]; then zero set high 32 bits to zero. */ +void +ppc_lwz(struct ppc_function *p, uint rt, uint ra, int d) +{ + emit_d(p, 32, rt, ra, d, "lwz\tr%u, %d(r%u)\n", TRUE); +} + + + +/** + ** Float (non-vector) arithmetic + **/ + +/** add: frt = fra + frb */ +void +ppc_fadd(struct ppc_function *p, uint frt, uint fra, uint frb) +{ + emit_a(p, 63, frt, fra, frb, 21, 0, "fadd\tf%u, f%u, f%u\n"); +} + +/** sub: frt = fra - frb */ +void +ppc_fsub(struct ppc_function *p, uint frt, uint fra, uint frb) +{ + emit_a(p, 63, frt, fra, frb, 20, 0, "fsub\tf%u, f%u, f%u\n"); +} + +/** convert to int: rt = (int) ra */ +void +ppc_fctiwz(struct ppc_function *p, uint rt, uint fra) +{ + emit_x(p, 63, rt, 0, fra, 15, "fctiwz\tr%u, r%u, r%u\n"); +} + +/** store frs at mem[(ra)+offset] */ +void +ppc_stfs(struct ppc_function *p, uint frs, uint ra, int offset) +{ + emit_d(p, 52, frs, ra, offset, "stfs\tr%u, %d(r%u)\n", TRUE); +} + +/** store frs at mem[(ra)+(rb)] */ +void +ppc_stfiwx(struct ppc_function *p, uint frs, uint ra, uint rb) +{ + emit_x(p, 31, frs, ra, rb, 983, "stfiwx\tr%u, r%u, r%u\n"); +} + +/** load frt = mem[(ra)+offset] */ +void +ppc_lfs(struct ppc_function *p, uint frt, uint ra, int offset) +{ + emit_d(p, 48, frt, ra, offset, "stfs\tr%u, %d(r%u)\n", TRUE); +} + + + + + +/** + ** branch instructions + **/ + +/** BLR: Branch to link register (p. 35) */ +void +ppc_blr(struct ppc_function *p) +{ + emit_i(p, 18, 0, 0, 1); + if (p->print) { + indent(p); + printf("blr\n"); + } +} + +/** Branch Conditional to Link Register (p. 36) */ +void +ppc_bclr(struct ppc_function *p, uint condOp, uint branchHint, uint condReg) +{ + emit_xl(p, 19, condOp, condReg, branchHint, 16, 0); + if (p->print) { + indent(p); + printf("bclr\t%u %u %u\n", condOp, branchHint, condReg); + } +} + +/** Pseudo instruction: return from subroutine */ +void +ppc_return(struct ppc_function *p) +{ + ppc_bclr(p, BRANCH_COND_ALWAYS, BRANCH_HINT_SUB_RETURN, 0); +} diff --git a/src/gallium/auxiliary/rtasm/rtasm_ppc.h b/src/gallium/auxiliary/rtasm/rtasm_ppc.h new file mode 100644 index 0000000..93e5f51 --- /dev/null +++ b/src/gallium/auxiliary/rtasm/rtasm_ppc.h @@ -0,0 +1,342 @@ +/************************************************************************** + * + * Copyright (C) 2008 Tungsten Graphics, Inc. All Rights Reserved. + * Copyright (C) 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 + * 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. + * + **************************************************************************/ + +/** + * PPC code generation. + * \author Brian Paul + */ + + +#ifndef RTASM_PPC_H +#define RTASM_PPC_H + + +#include "pipe/p_compiler.h" + + +#define PPC_INST_SIZE 4 /**< 4 bytes / instruction */ + +#define PPC_NUM_REGS 32 +#define PPC_NUM_FP_REGS 32 +#define PPC_NUM_VEC_REGS 32 + +/** Stack pointer register */ +#define PPC_REG_SP 1 + +/** Branch conditions */ +#define BRANCH_COND_ALWAYS 0x14 /* binary 1z1zz (z=ignored) */ + +/** Branch hints */ +#define BRANCH_HINT_SUB_RETURN 0x0 /* binary 00 */ + + +struct ppc_function +{ + uint32_t *store; /**< instruction buffer */ + uint num_inst; + uint max_inst; + uint32_t reg_used; /** used/free general-purpose registers bitmask */ + uint32_t fp_used; /** used/free floating point registers bitmask */ + uint32_t vec_used; /** used/free vector registers bitmask */ + int indent; + boolean print; +}; + + + +extern void ppc_init_func(struct ppc_function *p); +extern void ppc_release_func(struct ppc_function *p); +extern uint ppc_num_instructions(const struct ppc_function *p); +extern void (*ppc_get_func( struct ppc_function *p ))( void ); +extern void ppc_dump_func(const struct ppc_function *p); + +extern void ppc_print_code(struct ppc_function *p, boolean enable); +extern void ppc_indent(struct ppc_function *p, int spaces); +extern void ppc_comment(struct ppc_function *p, int rel_indent, const char *s); + +extern int ppc_reserve_register(struct ppc_function *p, int reg); +extern int ppc_allocate_register(struct ppc_function *p); +extern void ppc_release_register(struct ppc_function *p, int reg); +extern int ppc_allocate_fp_register(struct ppc_function *p); +extern void ppc_release_fp_register(struct ppc_function *p, int reg); +extern int ppc_allocate_vec_register(struct ppc_function *p); +extern void ppc_release_vec_register(struct ppc_function *p, int reg); + + + +/** + ** float vector arithmetic + **/ + +/** vector float add */ +extern void +ppc_vaddfp(struct ppc_function *p,uint vD, uint vA, uint vB); + +/** vector float substract */ +extern void +ppc_vsubfp(struct ppc_function *p, uint vD, uint vA, uint vB); + +/** vector float min */ +extern void +ppc_vminfp(struct ppc_function *p, uint vD, uint vA, uint vB); + +/** vector float max */ +extern void +ppc_vmaxfp(struct ppc_function *p, uint vD, uint vA, uint vB); + +/** vector float mult add: vD = vA * vB + vC */ +extern void +ppc_vmaddfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC); + +/** vector float negative mult subtract: vD = vA - vB * vC */ +extern void +ppc_vnmsubfp(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC); + +/** vector float compare greater than */ +extern void +ppc_vcmpgtfpx(struct ppc_function *p, uint vD, uint vA, uint vB); + +/** vector float compare greater than or equal to */ +extern void +ppc_vcmpgefpx(struct ppc_function *p, uint vD, uint vA, uint vB); + +/** vector float compare equal */ +extern void +ppc_vcmpeqfpx(struct ppc_function *p, uint vD, uint vA, uint vB); + +/** vector float 2^x */ +extern void +ppc_vexptefp(struct ppc_function *p, uint vD, uint vB); + +/** vector float log2(x) */ +extern void +ppc_vlogefp(struct ppc_function *p, uint vD, uint vB); + +/** vector float reciprocol */ +extern void +ppc_vrefp(struct ppc_function *p, uint vD, uint vB); + +/** vector float reciprocol sqrt estimate */ +extern void +ppc_vrsqrtefp(struct ppc_function *p, uint vD, uint vB); + +/** vector float round to negative infinity */ +extern void +ppc_vrfim(struct ppc_function *p, uint vD, uint vB); + +/** vector float round to positive infinity */ +extern void +ppc_vrfip(struct ppc_function *p, uint vD, uint vB); + +/** vector float round to nearest int */ +extern void +ppc_vrfin(struct ppc_function *p, uint vD, uint vB); + +/** vector float round to int toward zero */ +extern void +ppc_vrfiz(struct ppc_function *p, uint vD, uint vB); + + +/** vector store: store vR at mem[vA+vB] */ +extern void +ppc_stvx(struct ppc_function *p, uint vR, uint vA, uint vB); + +/** vector load: vR = mem[vA+vB] */ +extern void +ppc_lvx(struct ppc_function *p, uint vR, uint vA, uint vB); + +/** load vector element word: vR = mem_word[vA+vB] */ +extern void +ppc_lvewx(struct ppc_function *p, uint vR, uint vA, uint vB); + + + +/** + ** vector bitwise operations + **/ + + +/** vector and */ +extern void +ppc_vand(struct ppc_function *p, uint vD, uint vA, uint vB); + +/** vector and complement */ +extern void +ppc_vandc(struct ppc_function *p, uint vD, uint vA, uint vB); + +/** vector or */ +extern void +ppc_vor(struct ppc_function *p, uint vD, uint vA, uint vB); + +/** vector nor */ +extern void +ppc_vnor(struct ppc_function *p, uint vD, uint vA, uint vB); + +/** vector xor */ +extern void +ppc_vxor(struct ppc_function *p, uint vD, uint vA, uint vB); + +/** Pseudo-instruction: vector move */ +extern void +ppc_vmove(struct ppc_function *p, uint vD, uint vA); + +/** Set vector register to {0,0,0,0} */ +extern void +ppc_vzero(struct ppc_function *p, uint vr); + + + +/** + ** Vector shuffle / select / splat / etc + **/ + +/** vector permute */ +extern void +ppc_vperm(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC); + +/** vector select */ +extern void +ppc_vsel(struct ppc_function *p, uint vD, uint vA, uint vB, uint vC); + +/** vector splat byte */ +extern void +ppc_vspltb(struct ppc_function *p, uint vD, uint vB, uint imm); + +/** vector splat half word */ +extern void +ppc_vsplthw(struct ppc_function *p, uint vD, uint vB, uint imm); + +/** vector splat word */ +extern void +ppc_vspltw(struct ppc_function *p, uint vD, uint vB, uint imm); + +/** vector splat signed immediate word */ +extern void +ppc_vspltisw(struct ppc_function *p, uint vD, int imm); + +/** vector shift left word: vD[word] = vA[word] << (vB[word] & 0x1f) */ +extern void +ppc_vslw(struct ppc_function *p, uint vD, uint vA, uint vB); + + + +/** + ** scalar arithmetic + **/ + +extern void +ppc_add(struct ppc_function *p, uint rt, uint ra, uint rb); + +extern void +ppc_addi(struct ppc_function *p, uint rt, uint ra, int imm); + +extern void +ppc_addis(struct ppc_function *p, uint rt, uint ra, int imm); + +extern void +ppc_and(struct ppc_function *p, uint rt, uint ra, uint rb); + +extern void +ppc_andi(struct ppc_function *p, uint rt, uint ra, int imm); + +extern void +ppc_or(struct ppc_function *p, uint rt, uint ra, uint rb); + +extern void +ppc_ori(struct ppc_function *p, uint rt, uint ra, int imm); + +extern void +ppc_xor(struct ppc_function *p, uint rt, uint ra, uint rb); + +extern void +ppc_xori(struct ppc_function *p, uint rt, uint ra, int imm); + +extern void +ppc_mr(struct ppc_function *p, uint rt, uint ra); + +extern void +ppc_li(struct ppc_function *p, uint rt, int imm); + +extern void +ppc_lis(struct ppc_function *p, uint rt, int imm); + +extern void +ppc_load_int(struct ppc_function *p, uint rt, int imm); + + + +/** + ** scalar load/store + **/ + +extern void +ppc_stwu(struct ppc_function *p, uint rs, uint ra, int d); + +extern void +ppc_stw(struct ppc_function *p, uint rs, uint ra, int d); + +extern void +ppc_lwz(struct ppc_function *p, uint rs, uint ra, int d); + + + +/** + ** Float (non-vector) arithmetic + **/ + +extern void +ppc_fadd(struct ppc_function *p, uint frt, uint fra, uint frb); + +extern void +ppc_fsub(struct ppc_function *p, uint frt, uint fra, uint frb); + +extern void +ppc_fctiwz(struct ppc_function *p, uint rt, uint ra); + +extern void +ppc_stfs(struct ppc_function *p, uint frs, uint ra, int offset); + +extern void +ppc_stfiwx(struct ppc_function *p, uint frs, uint ra, uint rb); + +extern void +ppc_lfs(struct ppc_function *p, uint frt, uint ra, int offset); + + + +/** + ** branch instructions + **/ + +extern void +ppc_blr(struct ppc_function *p); + +void +ppc_bclr(struct ppc_function *p, uint condOp, uint branchHint, uint condReg); + +extern void +ppc_return(struct ppc_function *p); + + +#endif /* RTASM_PPC_H */ diff --git a/src/gallium/auxiliary/rtasm/rtasm_ppc_spe.c b/src/gallium/auxiliary/rtasm/rtasm_ppc_spe.c new file mode 100644 index 0000000..53a0e72 --- /dev/null +++ b/src/gallium/auxiliary/rtasm/rtasm_ppc_spe.c @@ -0,0 +1,1067 @@ +/* + * (C) Copyright IBM Corporation 2008 + * 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 + * 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 + * AUTHORS, COPYRIGHT HOLDERS, 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. + */ + +/** + * \file + * Real-time assembly generation interface for Cell B.E. SPEs. + * + * \author Ian Romanick + * \author Brian Paul + */ + + +#include +#include "pipe/p_compiler.h" +#include "util/u_memory.h" +#include "rtasm_ppc_spe.h" + + +#ifdef GALLIUM_CELL +/** + * SPE instruction types + * + * There are 6 primary instruction encodings used on the Cell's SPEs. Each of + * the following unions encodes one type. + * + * \bug + * If, at some point, we start generating SPE code from a little-endian host + * these unions will not work. + */ +/*@{*/ +/** + * Encode one output register with two input registers + */ +union spe_inst_RR { + uint32_t bits; + struct { + unsigned op:11; + unsigned rB:7; + unsigned rA:7; + unsigned rT:7; + } inst; +}; + + +/** + * Encode one output register with three input registers + */ +union spe_inst_RRR { + uint32_t bits; + struct { + unsigned op:4; + unsigned rT:7; + unsigned rB:7; + unsigned rA:7; + unsigned rC:7; + } inst; +}; + + +/** + * Encode one output register with one input reg. and a 7-bit signed immed + */ +union spe_inst_RI7 { + uint32_t bits; + struct { + unsigned op:11; + unsigned i7:7; + unsigned rA:7; + unsigned rT:7; + } inst; +}; + + +/** + * Encode one output register with one input reg. and an 8-bit signed immed + */ +union spe_inst_RI8 { + uint32_t bits; + struct { + unsigned op:10; + unsigned i8:8; + unsigned rA:7; + unsigned rT:7; + } inst; +}; + + +/** + * Encode one output register with one input reg. and a 10-bit signed immed + */ +union spe_inst_RI10 { + uint32_t bits; + struct { + unsigned op:8; + unsigned i10:10; + unsigned rA:7; + unsigned rT:7; + } inst; +}; + + +/** + * Encode one output register with a 16-bit signed immediate + */ +union spe_inst_RI16 { + uint32_t bits; + struct { + unsigned op:9; + unsigned i16:16; + unsigned rT:7; + } inst; +}; + + +/** + * Encode one output register with a 18-bit signed immediate + */ +union spe_inst_RI18 { + uint32_t bits; + struct { + unsigned op:7; + unsigned i18:18; + unsigned rT:7; + } inst; +}; +/*@}*/ + + +static void +indent(const struct spe_function *p) +{ + int i; + for (i = 0; i < p->indent; i++) { + putchar(' '); + } +} + + +static const char * +rem_prefix(const char *longname) +{ + return longname + 4; +} + + +static const char * +reg_name(int reg) +{ + switch (reg) { + case SPE_REG_SP: + return "$sp"; + case SPE_REG_RA: + return "$lr"; + default: + { + /* cycle through four buffers to handle multiple calls per printf */ + static char buf[4][10]; + static int b = 0; + b = (b + 1) % 4; + sprintf(buf[b], "$%d", reg); + return buf[b]; + } + } +} + + +static void +emit_instruction(struct spe_function *p, uint32_t inst_bits) +{ + if (!p->store) + return; /* out of memory, drop the instruction */ + + if (p->num_inst == p->max_inst) { + /* allocate larger buffer */ + uint32_t *newbuf; + p->max_inst *= 2; /* 2x larger */ + newbuf = align_malloc(p->max_inst * SPE_INST_SIZE, 16); + if (newbuf) { + memcpy(newbuf, p->store, p->num_inst * SPE_INST_SIZE); + } + align_free(p->store); + p->store = newbuf; + if (!p->store) { + /* out of memory */ + p->num_inst = 0; + return; + } + } + + p->store[p->num_inst++] = inst_bits; +} + + + +static void emit_RR(struct spe_function *p, unsigned op, int rT, + int rA, int rB, const char *name) +{ + union spe_inst_RR inst; + inst.inst.op = op; + inst.inst.rB = rB; + inst.inst.rA = rA; + inst.inst.rT = rT; + emit_instruction(p, inst.bits); + if (p->print) { + indent(p); + printf("%s\t%s, %s, %s\n", + rem_prefix(name), reg_name(rT), reg_name(rA), reg_name(rB)); + } +} + + +static void emit_RRR(struct spe_function *p, unsigned op, int rT, + int rA, int rB, int rC, const char *name) +{ + union spe_inst_RRR inst; + inst.inst.op = op; + inst.inst.rT = rT; + inst.inst.rB = rB; + inst.inst.rA = rA; + inst.inst.rC = rC; + emit_instruction(p, inst.bits); + if (p->print) { + indent(p); + printf("%s\t%s, %s, %s, %s\n", rem_prefix(name), reg_name(rT), + reg_name(rA), reg_name(rB), reg_name(rC)); + } +} + + +static void emit_RI7(struct spe_function *p, unsigned op, int rT, + int rA, int imm, const char *name) +{ + union spe_inst_RI7 inst; + inst.inst.op = op; + inst.inst.i7 = imm; + inst.inst.rA = rA; + inst.inst.rT = rT; + emit_instruction(p, inst.bits); + if (p->print) { + indent(p); + printf("%s\t%s, %s, 0x%x\n", + rem_prefix(name), reg_name(rT), reg_name(rA), imm); + } +} + + + +static void emit_RI8(struct spe_function *p, unsigned op, int rT, + int rA, int imm, const char *name) +{ + union spe_inst_RI8 inst; + inst.inst.op = op; + inst.inst.i8 = imm; + inst.inst.rA = rA; + inst.inst.rT = rT; + emit_instruction(p, inst.bits); + if (p->print) { + indent(p); + printf("%s\t%s, %s, 0x%x\n", + rem_prefix(name), reg_name(rT), reg_name(rA), imm); + } +} + + + +static void emit_RI10(struct spe_function *p, unsigned op, int rT, + int rA, int imm, const char *name) +{ + union spe_inst_RI10 inst; + inst.inst.op = op; + inst.inst.i10 = imm; + inst.inst.rA = rA; + inst.inst.rT = rT; + emit_instruction(p, inst.bits); + if (p->print) { + indent(p); + printf("%s\t%s, %s, 0x%x\n", + rem_prefix(name), reg_name(rT), reg_name(rA), imm); + } +} + + +/** As above, but do range checking on signed immediate value */ +static void emit_RI10s(struct spe_function *p, unsigned op, int rT, + int rA, int imm, const char *name) +{ + assert(imm <= 511); + assert(imm >= -512); + emit_RI10(p, op, rT, rA, imm, name); +} + + +static void emit_RI16(struct spe_function *p, unsigned op, int rT, + int imm, const char *name) +{ + union spe_inst_RI16 inst; + inst.inst.op = op; + inst.inst.i16 = imm; + inst.inst.rT = rT; + emit_instruction(p, inst.bits); + if (p->print) { + indent(p); + printf("%s\t%s, 0x%x\n", rem_prefix(name), reg_name(rT), imm); + } +} + + +static void emit_RI18(struct spe_function *p, unsigned op, int rT, + int imm, const char *name) +{ + union spe_inst_RI18 inst; + inst.inst.op = op; + inst.inst.i18 = imm; + inst.inst.rT = rT; + emit_instruction(p, inst.bits); + if (p->print) { + indent(p); + printf("%s\t%s, 0x%x\n", rem_prefix(name), reg_name(rT), imm); + } +} + + +#define EMIT(_name, _op) \ +void _name (struct spe_function *p) \ +{ \ + emit_RR(p, _op, 0, 0, 0, __FUNCTION__); \ +} + +#define EMIT_(_name, _op) \ +void _name (struct spe_function *p, int rT) \ +{ \ + emit_RR(p, _op, rT, 0, 0, __FUNCTION__); \ +} + +#define EMIT_R(_name, _op) \ +void _name (struct spe_function *p, int rT, int rA) \ +{ \ + emit_RR(p, _op, rT, rA, 0, __FUNCTION__); \ +} + +#define EMIT_RR(_name, _op) \ +void _name (struct spe_function *p, int rT, int rA, int rB) \ +{ \ + emit_RR(p, _op, rT, rA, rB, __FUNCTION__); \ +} + +#define EMIT_RRR(_name, _op) \ +void _name (struct spe_function *p, int rT, int rA, int rB, int rC) \ +{ \ + emit_RRR(p, _op, rT, rA, rB, rC, __FUNCTION__); \ +} + +#define EMIT_RI7(_name, _op) \ +void _name (struct spe_function *p, int rT, int rA, int imm) \ +{ \ + emit_RI7(p, _op, rT, rA, imm, __FUNCTION__); \ +} + +#define EMIT_RI8(_name, _op, bias) \ +void _name (struct spe_function *p, int rT, int rA, int imm) \ +{ \ + emit_RI8(p, _op, rT, rA, bias - imm, __FUNCTION__); \ +} + +#define EMIT_RI10(_name, _op) \ +void _name (struct spe_function *p, int rT, int rA, int imm) \ +{ \ + emit_RI10(p, _op, rT, rA, imm, __FUNCTION__); \ +} + +#define EMIT_RI10s(_name, _op) \ +void _name (struct spe_function *p, int rT, int rA, int imm) \ +{ \ + emit_RI10s(p, _op, rT, rA, imm, __FUNCTION__); \ +} + +#define EMIT_RI16(_name, _op) \ +void _name (struct spe_function *p, int rT, int imm) \ +{ \ + emit_RI16(p, _op, rT, imm, __FUNCTION__); \ +} + +#define EMIT_RI18(_name, _op) \ +void _name (struct spe_function *p, int rT, int imm) \ +{ \ + emit_RI18(p, _op, rT, imm, __FUNCTION__); \ +} + +#define EMIT_I16(_name, _op) \ +void _name (struct spe_function *p, int imm) \ +{ \ + emit_RI16(p, _op, 0, imm, __FUNCTION__); \ +} + +#include "rtasm_ppc_spe.h" + + + +/** + * Initialize an spe_function. + * \param code_size initial size of instruction buffer to allocate, in bytes. + * If zero, use a default. + */ +void spe_init_func(struct spe_function *p, unsigned code_size) +{ + uint i; + + if (!code_size) + code_size = 64; + + p->num_inst = 0; + p->max_inst = code_size / SPE_INST_SIZE; + p->store = align_malloc(code_size, 16); + + p->set_count = 0; + memset(p->regs, 0, SPE_NUM_REGS * sizeof(p->regs[0])); + + /* Conservatively treat R0 - R2 and R80 - R127 as non-volatile. + */ + p->regs[0] = p->regs[1] = p->regs[2] = 1; + for (i = 80; i <= 127; i++) { + p->regs[i] = 1; + } + + p->print = FALSE; + p->indent = 0; +} + + +void spe_release_func(struct spe_function *p) +{ + assert(p->num_inst <= p->max_inst); + if (p->store != NULL) { + align_free(p->store); + } + p->store = NULL; +} + + +/** Return current code size in bytes. */ +unsigned spe_code_size(const struct spe_function *p) +{ + return p->num_inst * SPE_INST_SIZE; +} + + +/** + * Allocate a SPE register. + * \return register index or -1 if none left. + */ +int spe_allocate_available_register(struct spe_function *p) +{ + unsigned i; + for (i = 0; i < SPE_NUM_REGS; i++) { + if (p->regs[i] == 0) { + p->regs[i] = 1; + return i; + } + } + + return -1; +} + + +/** + * Mark the given SPE register as "allocated". + */ +int spe_allocate_register(struct spe_function *p, int reg) +{ + assert(reg < SPE_NUM_REGS); + assert(p->regs[reg] == 0); + p->regs[reg] = 1; + return reg; +} + + +/** + * Mark the given SPE register as "unallocated". Note that this should + * only be used on registers allocated in the current register set; an + * assertion will fail if an attempt is made to deallocate a register + * allocated in an earlier register set. + */ +void spe_release_register(struct spe_function *p, int reg) +{ + assert(reg >= 0); + assert(reg < SPE_NUM_REGS); + assert(p->regs[reg] == 1); + + p->regs[reg] = 0; +} + +/** + * Start a new set of registers. This can be called if + * it will be difficult later to determine exactly what + * registers were actually allocated during a code generation + * sequence, and you really just want to deallocate all of them. + */ +void spe_allocate_register_set(struct spe_function *p) +{ + uint i; + + /* Keep track of the set count. If it ever wraps around to 0, + * we're in trouble. + */ + p->set_count++; + assert(p->set_count > 0); + + /* Increment the allocation count of all registers currently + * allocated. Then any registers that are allocated in this set + * will be the only ones with a count of 1; they'll all be released + * when the register set is released. + */ + for (i = 0; i < SPE_NUM_REGS; i++) { + if (p->regs[i] > 0) + p->regs[i]++; + } +} + +void spe_release_register_set(struct spe_function *p) +{ + uint i; + + /* If the set count drops below zero, we're in trouble. */ + assert(p->set_count > 0); + p->set_count--; + + /* Drop the allocation level of all registers. Any allocated + * during this register set will drop to 0 and then become + * available. + */ + for (i = 0; i < SPE_NUM_REGS; i++) { + if (p->regs[i] > 0) + p->regs[i]--; + } +} + + +unsigned +spe_get_registers_used(const struct spe_function *p, ubyte used[]) +{ + unsigned i, num = 0; + /* only count registers in the range available to callers */ + for (i = 2; i < 80; i++) { + if (p->regs[i]) { + used[num++] = i; + } + } + return num; +} + + +void +spe_print_code(struct spe_function *p, boolean enable) +{ + p->print = enable; +} + + +void +spe_indent(struct spe_function *p, int spaces) +{ + p->indent += spaces; +} + + +void +spe_comment(struct spe_function *p, int rel_indent, const char *s) +{ + if (p->print) { + p->indent += rel_indent; + indent(p); + p->indent -= rel_indent; + printf("# %s\n", s); + } +} + + +/** + * Load quad word. + * NOTE: offset is in bytes and the least significant 4 bits must be zero! + */ +void spe_lqd(struct spe_function *p, int rT, int rA, int offset) +{ + const boolean pSave = p->print; + + /* offset must be a multiple of 16 */ + assert(offset % 16 == 0); + /* offset must fit in 10-bit signed int field, after shifting */ + assert((offset >> 4) <= 511); + assert((offset >> 4) >= -512); + + p->print = FALSE; + emit_RI10(p, 0x034, rT, rA, offset >> 4, "spe_lqd"); + p->print = pSave; + + if (p->print) { + indent(p); + printf("lqd\t%s, %d(%s)\n", reg_name(rT), offset, reg_name(rA)); + } +} + + +/** + * Store quad word. + * NOTE: offset is in bytes and the least significant 4 bits must be zero! + */ +void spe_stqd(struct spe_function *p, int rT, int rA, int offset) +{ + const boolean pSave = p->print; + + /* offset must be a multiple of 16 */ + assert(offset % 16 == 0); + /* offset must fit in 10-bit signed int field, after shifting */ + assert((offset >> 4) <= 511); + assert((offset >> 4) >= -512); + + p->print = FALSE; + emit_RI10(p, 0x024, rT, rA, offset >> 4, "spe_stqd"); + p->print = pSave; + + if (p->print) { + indent(p); + printf("stqd\t%s, %d(%s)\n", reg_name(rT), offset, reg_name(rA)); + } +} + + +/** + * For branch instructions: + * \param d if 1, disable interupts if branch is taken + * \param e if 1, enable interupts if branch is taken + * If d and e are both zero, don't change interupt status (right?) + */ + +/** Branch Indirect to address in rA */ +void spe_bi(struct spe_function *p, int rA, int d, int e) +{ + emit_RI7(p, 0x1a8, 0, rA, (d << 5) | (e << 4), __FUNCTION__); +} + +/** Interupt Return */ +void spe_iret(struct spe_function *p, int rA, int d, int e) +{ + emit_RI7(p, 0x1aa, 0, rA, (d << 5) | (e << 4), __FUNCTION__); +} + +/** Branch indirect and set link on external data */ +void spe_bisled(struct spe_function *p, int rT, int rA, int d, + int e) +{ + emit_RI7(p, 0x1ab, rT, rA, (d << 5) | (e << 4), __FUNCTION__); +} + +/** Branch indirect and set link. Save PC in rT, jump to rA. */ +void spe_bisl(struct spe_function *p, int rT, int rA, int d, + int e) +{ + emit_RI7(p, 0x1a9, rT, rA, (d << 5) | (e << 4), __FUNCTION__); +} + +/** Branch indirect if zero word. If rT.word[0]==0, jump to rA. */ +void spe_biz(struct spe_function *p, int rT, int rA, int d, int e) +{ + emit_RI7(p, 0x128, rT, rA, (d << 5) | (e << 4), __FUNCTION__); +} + +/** Branch indirect if non-zero word. If rT.word[0]!=0, jump to rA. */ +void spe_binz(struct spe_function *p, int rT, int rA, int d, int e) +{ + emit_RI7(p, 0x129, rT, rA, (d << 5) | (e << 4), __FUNCTION__); +} + +/** Branch indirect if zero halfword. If rT.halfword[1]==0, jump to rA. */ +void spe_bihz(struct spe_function *p, int rT, int rA, int d, int e) +{ + emit_RI7(p, 0x12a, rT, rA, (d << 5) | (e << 4), __FUNCTION__); +} + +/** Branch indirect if non-zero halfword. If rT.halfword[1]!=0, jump to rA. */ +void spe_bihnz(struct spe_function *p, int rT, int rA, int d, int e) +{ + emit_RI7(p, 0x12b, rT, rA, (d << 5) | (e << 4), __FUNCTION__); +} + + +/* Hint-for-branch instructions + */ +#if 0 +hbr; +hbra; +hbrr; +#endif + + +/* Control instructions + */ +#if 0 +stop; +EMIT_RR (spe_stopd, 0x140); +EMIT_ (spe_nop, 0x201); +sync; +EMIT_ (spe_dsync, 0x003); +EMIT_R (spe_mfspr, 0x00c); +EMIT_R (spe_mtspr, 0x10c); +#endif + + +/** + ** Helper / "macro" instructions. + ** Use somewhat verbose names as a reminder that these aren't native + ** SPE instructions. + **/ + + +void +spe_load_float(struct spe_function *p, int rT, float x) +{ + if (x == 0.0f) { + spe_il(p, rT, 0x0); + } + else if (x == 0.5f) { + spe_ilhu(p, rT, 0x3f00); + } + else if (x == 1.0f) { + spe_ilhu(p, rT, 0x3f80); + } + else if (x == -1.0f) { + spe_ilhu(p, rT, 0xbf80); + } + else { + union { + float f; + unsigned u; + } bits; + bits.f = x; + spe_ilhu(p, rT, bits.u >> 16); + spe_iohl(p, rT, bits.u & 0xffff); + } +} + + +void +spe_load_int(struct spe_function *p, int rT, int i) +{ + if (-32768 <= i && i <= 32767) { + spe_il(p, rT, i); + } + else { + spe_ilhu(p, rT, i >> 16); + if (i & 0xffff) + spe_iohl(p, rT, i & 0xffff); + } +} + +void spe_load_uint(struct spe_function *p, int rT, uint ui) +{ + /* If the whole value is in the lower 18 bits, use ila, which + * doesn't sign-extend. Otherwise, if the two halfwords of + * the constant are identical, use ilh. Otherwise, if every byte of + * the desired value is 0x00 or 0xff, we can use Form Select Mask for + * Bytes Immediate (fsmbi) to load the value in a single instruction. + * Otherwise, in the general case, we have to use ilhu followed by iohl. + */ + if ((ui & 0x0003ffff) == ui) { + spe_ila(p, rT, ui); + } + else if ((ui >> 16) == (ui & 0xffff)) { + spe_ilh(p, rT, ui & 0xffff); + } + else if ( + ((ui & 0x000000ff) == 0 || (ui & 0x000000ff) == 0x000000ff) && + ((ui & 0x0000ff00) == 0 || (ui & 0x0000ff00) == 0x0000ff00) && + ((ui & 0x00ff0000) == 0 || (ui & 0x00ff0000) == 0x00ff0000) && + ((ui & 0xff000000) == 0 || (ui & 0xff000000) == 0xff000000) + ) { + uint mask = 0; + /* fsmbi duplicates each bit in the given mask eight times, + * using a 16-bit value to initialize a 16-byte quadword. + * Each 4-bit nybble of the mask corresponds to a full word + * of the result; look at the value and figure out the mask + * (replicated for each word in the quadword), and then + * form the "select mask" to get the value. + */ + if ((ui & 0x000000ff) == 0x000000ff) mask |= 0x1111; + if ((ui & 0x0000ff00) == 0x0000ff00) mask |= 0x2222; + if ((ui & 0x00ff0000) == 0x00ff0000) mask |= 0x4444; + if ((ui & 0xff000000) == 0xff000000) mask |= 0x8888; + spe_fsmbi(p, rT, mask); + } + else { + /* The general case: this usually uses two instructions, but + * may use only one if the low-order 16 bits of each word are 0. + */ + spe_ilhu(p, rT, ui >> 16); + if (ui & 0xffff) + spe_iohl(p, rT, ui & 0xffff); + } +} + +/** + * This function is constructed identically to spe_xor_uint() below. + * Changes to one should be made in the other. + */ +void +spe_and_uint(struct spe_function *p, int rT, int rA, uint ui) +{ + /* If we can, emit a single instruction, either And Byte Immediate + * (which uses the same constant across each byte), And Halfword Immediate + * (which sign-extends a 10-bit immediate to 16 bits and uses that + * across each halfword), or And Word Immediate (which sign-extends + * a 10-bit immediate to 32 bits). + * + * Otherwise, we'll need to use a temporary register. + */ + uint tmp; + + /* If the upper 23 bits are all 0s or all 1s, sign extension + * will work and we can use And Word Immediate + */ + tmp = ui & 0xfffffe00; + if (tmp == 0xfffffe00 || tmp == 0) { + spe_andi(p, rT, rA, ui & 0x000003ff); + return; + } + + /* If the ui field is symmetric along halfword boundaries and + * the upper 7 bits of each halfword are all 0s or 1s, we + * can use And Halfword Immediate + */ + tmp = ui & 0xfe00fe00; + if ((tmp == 0xfe00fe00 || tmp == 0) && ((ui >> 16) == (ui & 0x0000ffff))) { + spe_andhi(p, rT, rA, ui & 0x000003ff); + return; + } + + /* If the ui field is symmetric in each byte, then we can use + * the And Byte Immediate instruction. + */ + tmp = ui & 0x000000ff; + if ((ui >> 24) == tmp && ((ui >> 16) & 0xff) == tmp && ((ui >> 8) & 0xff) == tmp) { + spe_andbi(p, rT, rA, tmp); + return; + } + + /* Otherwise, we'll have to use a temporary register. */ + int tmp_reg = spe_allocate_available_register(p); + spe_load_uint(p, tmp_reg, ui); + spe_and(p, rT, rA, tmp_reg); + spe_release_register(p, tmp_reg); +} + + +/** + * This function is constructed identically to spe_and_uint() above. + * Changes to one should be made in the other. + */ +void +spe_xor_uint(struct spe_function *p, int rT, int rA, uint ui) +{ + /* If we can, emit a single instruction, either Exclusive Or Byte + * Immediate (which uses the same constant across each byte), Exclusive + * Or Halfword Immediate (which sign-extends a 10-bit immediate to + * 16 bits and uses that across each halfword), or Exclusive Or Word + * Immediate (which sign-extends a 10-bit immediate to 32 bits). + * + * Otherwise, we'll need to use a temporary register. + */ + uint tmp; + + /* If the upper 23 bits are all 0s or all 1s, sign extension + * will work and we can use Exclusive Or Word Immediate + */ + tmp = ui & 0xfffffe00; + if (tmp == 0xfffffe00 || tmp == 0) { + spe_xori(p, rT, rA, ui & 0x000003ff); + return; + } + + /* If the ui field is symmetric along halfword boundaries and + * the upper 7 bits of each halfword are all 0s or 1s, we + * can use Exclusive Or Halfword Immediate + */ + tmp = ui & 0xfe00fe00; + if ((tmp == 0xfe00fe00 || tmp == 0) && ((ui >> 16) == (ui & 0x0000ffff))) { + spe_xorhi(p, rT, rA, ui & 0x000003ff); + return; + } + + /* If the ui field is symmetric in each byte, then we can use + * the Exclusive Or Byte Immediate instruction. + */ + tmp = ui & 0x000000ff; + if ((ui >> 24) == tmp && ((ui >> 16) & 0xff) == tmp && ((ui >> 8) & 0xff) == tmp) { + spe_xorbi(p, rT, rA, tmp); + return; + } + + /* Otherwise, we'll have to use a temporary register. */ + int tmp_reg = spe_allocate_available_register(p); + spe_load_uint(p, tmp_reg, ui); + spe_xor(p, rT, rA, tmp_reg); + spe_release_register(p, tmp_reg); +} + +void +spe_compare_equal_uint(struct spe_function *p, int rT, int rA, uint ui) +{ + /* If the comparison value is 9 bits or less, it fits inside a + * Compare Equal Word Immediate instruction. + */ + if ((ui & 0x000001ff) == ui) { + spe_ceqi(p, rT, rA, ui); + } + /* Otherwise, we're going to have to load a word first. */ + else { + int tmp_reg = spe_allocate_available_register(p); + spe_load_uint(p, tmp_reg, ui); + spe_ceq(p, rT, rA, tmp_reg); + spe_release_register(p, tmp_reg); + } +} + +void +spe_compare_greater_uint(struct spe_function *p, int rT, int rA, uint ui) +{ + /* If the comparison value is 10 bits or less, it fits inside a + * Compare Logical Greater Than Word Immediate instruction. + */ + if ((ui & 0x000003ff) == ui) { + spe_clgti(p, rT, rA, ui); + } + /* Otherwise, we're going to have to load a word first. */ + else { + int tmp_reg = spe_allocate_available_register(p); + spe_load_uint(p, tmp_reg, ui); + spe_clgt(p, rT, rA, tmp_reg); + spe_release_register(p, tmp_reg); + } +} + +void +spe_splat(struct spe_function *p, int rT, int rA) +{ + /* Use a temporary, just in case rT == rA */ + int tmp_reg = spe_allocate_available_register(p); + /* Duplicate bytes 0, 1, 2, and 3 across the whole register */ + spe_ila(p, tmp_reg, 0x00010203); + spe_shufb(p, rT, rA, rA, tmp_reg); + spe_release_register(p, tmp_reg); +} + + +void +spe_complement(struct spe_function *p, int rT, int rA) +{ + spe_nor(p, rT, rA, rA); +} + + +void +spe_move(struct spe_function *p, int rT, int rA) +{ + /* Use different instructions depending on the instruction address + * to take advantage of the dual pipelines. + */ + if (p->num_inst & 1) + spe_shlqbyi(p, rT, rA, 0); /* odd pipe */ + else + spe_ori(p, rT, rA, 0); /* even pipe */ +} + + +void +spe_zero(struct spe_function *p, int rT) +{ + spe_xor(p, rT, rT, rT); +} + + +void +spe_splat_word(struct spe_function *p, int rT, int rA, int word) +{ + assert(word >= 0); + assert(word <= 3); + + if (word == 0) { + int tmp1 = rT; + spe_ila(p, tmp1, 66051); + spe_shufb(p, rT, rA, rA, tmp1); + } + else { + /* XXX review this, we may not need the rotqbyi instruction */ + int tmp1 = rT; + int tmp2 = spe_allocate_available_register(p); + + spe_ila(p, tmp1, 66051); + spe_rotqbyi(p, tmp2, rA, 4 * word); + spe_shufb(p, rT, tmp2, tmp2, tmp1); + + spe_release_register(p, tmp2); + } +} + +/** + * For each 32-bit float element of rA and rB, choose the smaller of the + * two, compositing them into the rT register. + * + * The Float Compare Greater Than (fcgt) instruction will put 1s into + * compare_reg where rA > rB, and 0s where rA <= rB. + * + * Then the Select Bits (selb) instruction will take bits from rA where + * compare_reg is 0, and from rB where compare_reg is 1; i.e., from rA + * where rA <= rB and from rB where rB > rA, which is exactly the + * "min" operation. + * + * The compare_reg could in many cases be the same as rT, unless + * rT == rA || rt == rB. But since this is common in constructions + * like "x = min(x, a)", we always allocate a new register to be safe. + */ +void +spe_float_min(struct spe_function *p, int rT, int rA, int rB) +{ + int compare_reg = spe_allocate_available_register(p); + spe_fcgt(p, compare_reg, rA, rB); + spe_selb(p, rT, rA, rB, compare_reg); + spe_release_register(p, compare_reg); +} + +/** + * For each 32-bit float element of rA and rB, choose the greater of the + * two, compositing them into the rT register. + * + * The logic is similar to that of spe_float_min() above; the only + * difference is that the registers on spe_selb() have been reversed, + * so that the larger of the two is selected instead of the smaller. + */ +void +spe_float_max(struct spe_function *p, int rT, int rA, int rB) +{ + int compare_reg = spe_allocate_available_register(p); + spe_fcgt(p, compare_reg, rA, rB); + spe_selb(p, rT, rB, rA, compare_reg); + spe_release_register(p, compare_reg); +} + +#endif /* GALLIUM_CELL */ diff --git a/src/gallium/auxiliary/rtasm/rtasm_ppc_spe.h b/src/gallium/auxiliary/rtasm/rtasm_ppc_spe.h new file mode 100644 index 0000000..65d9c77 --- /dev/null +++ b/src/gallium/auxiliary/rtasm/rtasm_ppc_spe.h @@ -0,0 +1,433 @@ +/* + * (C) Copyright IBM Corporation 2008 + * 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 + * 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 + * AUTHORS, COPYRIGHT HOLDERS, 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. + */ + +/** + * \file + * Real-time assembly generation interface for Cell B.E. SPEs. + * For details, see /opt/cell/sdk/docs/arch/SPU_ISA_v1.2_27Jan2007_pub.pdf + * + * \author Ian Romanick + * \author Brian Paul + */ + +#ifndef RTASM_PPC_SPE_H +#define RTASM_PPC_SPE_H + +/** 4 bytes per instruction */ +#define SPE_INST_SIZE 4 + +/** number of general-purpose SIMD registers */ +#define SPE_NUM_REGS 128 + +/** Return Address register (aka $lr / Link Register) */ +#define SPE_REG_RA 0 + +/** Stack Pointer register (aka $sp) */ +#define SPE_REG_SP 1 + + +struct spe_function +{ + uint32_t *store; /**< instruction buffer */ + uint num_inst; + uint max_inst; + + /** + * The "set count" reflects the number of nested register sets + * are allowed. In the unlikely case that we exceed the set count, + * register allocation will start to be confused, which is critical + * enough that we check for it. + */ + unsigned char set_count; + + /** + * Flags for used and unused registers. Each byte corresponds to a + * register; a 0 in that byte means that the register is available. + * A value of 1 means that the register was allocated in the current + * register set. Any other value N means that the register was allocated + * N register sets ago. + * + * \sa + * spe_allocate_register, spe_allocate_available_register, + * spe_allocate_register_set, spe_release_register_set, spe_release_register, + */ + unsigned char regs[SPE_NUM_REGS]; + + boolean print; /**< print/dump instructions as they're emitted? */ + int indent; /**< number of spaces to indent */ +}; + + +extern void spe_init_func(struct spe_function *p, uint code_size); +extern void spe_release_func(struct spe_function *p); +extern uint spe_code_size(const struct spe_function *p); + +extern int spe_allocate_available_register(struct spe_function *p); +extern int spe_allocate_register(struct spe_function *p, int reg); +extern void spe_release_register(struct spe_function *p, int reg); +extern void spe_allocate_register_set(struct spe_function *p); +extern void spe_release_register_set(struct spe_function *p); + +extern uint spe_get_registers_used(const struct spe_function *p, ubyte used[]); + +extern void spe_print_code(struct spe_function *p, boolean enable); +extern void spe_indent(struct spe_function *p, int spaces); +extern void spe_comment(struct spe_function *p, int rel_indent, const char *s); + + +#endif /* RTASM_PPC_SPE_H */ + +#ifndef EMIT +#define EMIT(_name, _op) \ + extern void _name (struct spe_function *p); +#define EMIT_(_name, _op) \ + extern void _name (struct spe_function *p, int rT); +#define EMIT_R(_name, _op) \ + extern void _name (struct spe_function *p, int rT, int rA); +#define EMIT_RR(_name, _op) \ + extern void _name (struct spe_function *p, int rT, int rA, int rB); +#define EMIT_RRR(_name, _op) \ + extern void _name (struct spe_function *p, int rT, int rA, int rB, int rC); +#define EMIT_RI7(_name, _op) \ + extern void _name (struct spe_function *p, int rT, int rA, int imm); +#define EMIT_RI8(_name, _op, bias) \ + extern void _name (struct spe_function *p, int rT, int rA, int imm); +#define EMIT_RI10(_name, _op) \ + extern void _name (struct spe_function *p, int rT, int rA, int imm); +#define EMIT_RI10s(_name, _op) \ + extern void _name (struct spe_function *p, int rT, int rA, int imm); +#define EMIT_RI16(_name, _op) \ + extern void _name (struct spe_function *p, int rT, int imm); +#define EMIT_RI18(_name, _op) \ + extern void _name (struct spe_function *p, int rT, int imm); +#define EMIT_I16(_name, _op) \ + extern void _name (struct spe_function *p, int imm); +#define UNDEF_EMIT_MACROS +#endif /* EMIT */ + + +/* Memory load / store instructions + */ +EMIT_RR (spe_lqx, 0x1c4) +EMIT_RI16(spe_lqa, 0x061) +EMIT_RI16(spe_lqr, 0x067) +EMIT_RR (spe_stqx, 0x144) +EMIT_RI16(spe_stqa, 0x041) +EMIT_RI16(spe_stqr, 0x047) +EMIT_RI7 (spe_cbd, 0x1f4) +EMIT_RR (spe_cbx, 0x1d4) +EMIT_RI7 (spe_chd, 0x1f5) +EMIT_RI7 (spe_chx, 0x1d5) +EMIT_RI7 (spe_cwd, 0x1f6) +EMIT_RI7 (spe_cwx, 0x1d6) +EMIT_RI7 (spe_cdd, 0x1f7) +EMIT_RI7 (spe_cdx, 0x1d7) + + +/* Constant formation instructions + */ +EMIT_RI16(spe_ilh, 0x083) +EMIT_RI16(spe_ilhu, 0x082) +EMIT_RI16(spe_il, 0x081) +EMIT_RI18(spe_ila, 0x021) +EMIT_RI16(spe_iohl, 0x0c1) +EMIT_RI16(spe_fsmbi, 0x065) + + + +/* Integer and logical instructions + */ +EMIT_RR (spe_ah, 0x0c8) +EMIT_RI10(spe_ahi, 0x01d) +EMIT_RR (spe_a, 0x0c0) +EMIT_RI10s(spe_ai, 0x01c) +EMIT_RR (spe_sfh, 0x048) +EMIT_RI10(spe_sfhi, 0x00d) +EMIT_RR (spe_sf, 0x040) +EMIT_RI10(spe_sfi, 0x00c) +EMIT_RR (spe_addx, 0x340) +EMIT_RR (spe_cg, 0x0c2) +EMIT_RR (spe_cgx, 0x342) +EMIT_RR (spe_sfx, 0x341) +EMIT_RR (spe_bg, 0x042) +EMIT_RR (spe_bgx, 0x343) +EMIT_RR (spe_mpy, 0x3c4) +EMIT_RR (spe_mpyu, 0x3cc) +EMIT_RI10(spe_mpyi, 0x074) +EMIT_RI10(spe_mpyui, 0x075) +EMIT_RRR (spe_mpya, 0x00c) +EMIT_RR (spe_mpyh, 0x3c5) +EMIT_RR (spe_mpys, 0x3c7) +EMIT_RR (spe_mpyhh, 0x3c6) +EMIT_RR (spe_mpyhha, 0x346) +EMIT_RR (spe_mpyhhu, 0x3ce) +EMIT_RR (spe_mpyhhau, 0x34e) +EMIT_R (spe_clz, 0x2a5) +EMIT_R (spe_cntb, 0x2b4) +EMIT_R (spe_fsmb, 0x1b6) +EMIT_R (spe_fsmh, 0x1b5) +EMIT_R (spe_fsm, 0x1b4) +EMIT_R (spe_gbb, 0x1b2) +EMIT_R (spe_gbh, 0x1b1) +EMIT_R (spe_gb, 0x1b0) +EMIT_RR (spe_avgb, 0x0d3) +EMIT_RR (spe_absdb, 0x053) +EMIT_RR (spe_sumb, 0x253) +EMIT_R (spe_xsbh, 0x2b6) +EMIT_R (spe_xshw, 0x2ae) +EMIT_R (spe_xswd, 0x2a6) +EMIT_RR (spe_and, 0x0c1) +EMIT_RR (spe_andc, 0x2c1) +EMIT_RI10s(spe_andbi, 0x016) +EMIT_RI10s(spe_andhi, 0x015) +EMIT_RI10s(spe_andi, 0x014) +EMIT_RR (spe_or, 0x041) +EMIT_RR (spe_orc, 0x2c9) +EMIT_RI10s(spe_orbi, 0x006) +EMIT_RI10s(spe_orhi, 0x005) +EMIT_RI10s(spe_ori, 0x004) +EMIT_R (spe_orx, 0x1f0) +EMIT_RR (spe_xor, 0x241) +EMIT_RI10s(spe_xorbi, 0x046) +EMIT_RI10s(spe_xorhi, 0x045) +EMIT_RI10s(spe_xori, 0x044) +EMIT_RR (spe_nand, 0x0c9) +EMIT_RR (spe_nor, 0x049) +EMIT_RR (spe_eqv, 0x249) +EMIT_RRR (spe_selb, 0x008) +EMIT_RRR (spe_shufb, 0x00b) + + +/* Shift and rotate instructions + */ +EMIT_RR (spe_shlh, 0x05f) +EMIT_RI7 (spe_shlhi, 0x07f) +EMIT_RR (spe_shl, 0x05b) +EMIT_RI7 (spe_shli, 0x07b) +EMIT_RR (spe_shlqbi, 0x1db) +EMIT_RI7 (spe_shlqbii, 0x1fb) +EMIT_RR (spe_shlqby, 0x1df) +EMIT_RI7 (spe_shlqbyi, 0x1ff) +EMIT_RR (spe_shlqbybi, 0x1cf) +EMIT_RR (spe_roth, 0x05c) +EMIT_RI7 (spe_rothi, 0x07c) +EMIT_RR (spe_rot, 0x058) +EMIT_RI7 (spe_roti, 0x078) +EMIT_RR (spe_rotqby, 0x1dc) +EMIT_RI7 (spe_rotqbyi, 0x1fc) +EMIT_RR (spe_rotqbybi, 0x1cc) +EMIT_RR (spe_rotqbi, 0x1d8) +EMIT_RI7 (spe_rotqbii, 0x1f8) +EMIT_RR (spe_rothm, 0x05d) +EMIT_RI7 (spe_rothmi, 0x07d) +EMIT_RR (spe_rotm, 0x059) +EMIT_RI7 (spe_rotmi, 0x079) +EMIT_RR (spe_rotqmby, 0x1dd) +EMIT_RI7 (spe_rotqmbyi, 0x1fd) +EMIT_RR (spe_rotqmbybi, 0x1cd) +EMIT_RR (spe_rotqmbi, 0x1c9) +EMIT_RI7 (spe_rotqmbii, 0x1f9) +EMIT_RR (spe_rotmah, 0x05e) +EMIT_RI7 (spe_rotmahi, 0x07e) +EMIT_RR (spe_rotma, 0x05a) +EMIT_RI7 (spe_rotmai, 0x07a) + + +/* Compare, branch, and halt instructions + */ +EMIT_RR (spe_heq, 0x3d8) +EMIT_RI10(spe_heqi, 0x07f) +EMIT_RR (spe_hgt, 0x258) +EMIT_RI10(spe_hgti, 0x04f) +EMIT_RR (spe_hlgt, 0x2d8) +EMIT_RI10(spe_hlgti, 0x05f) +EMIT_RR (spe_ceqb, 0x3d0) +EMIT_RI10(spe_ceqbi, 0x07e) +EMIT_RR (spe_ceqh, 0x3c8) +EMIT_RI10(spe_ceqhi, 0x07d) +EMIT_RR (spe_ceq, 0x3c0) +EMIT_RI10(spe_ceqi, 0x07c) +EMIT_RR (spe_cgtb, 0x250) +EMIT_RI10(spe_cgtbi, 0x04e) +EMIT_RR (spe_cgth, 0x248) +EMIT_RI10(spe_cgthi, 0x04d) +EMIT_RR (spe_cgt, 0x240) +EMIT_RI10(spe_cgti, 0x04c) +EMIT_RR (spe_clgtb, 0x2d0) +EMIT_RI10(spe_clgtbi, 0x05e) +EMIT_RR (spe_clgth, 0x2c8) +EMIT_RI10(spe_clgthi, 0x05d) +EMIT_RR (spe_clgt, 0x2c0) +EMIT_RI10(spe_clgti, 0x05c) +EMIT_I16 (spe_br, 0x064) +EMIT_I16 (spe_bra, 0x060) +EMIT_RI16(spe_brsl, 0x066) +EMIT_RI16(spe_brasl, 0x062) +EMIT_RI16(spe_brnz, 0x042) +EMIT_RI16(spe_brz, 0x040) +EMIT_RI16(spe_brhnz, 0x046) +EMIT_RI16(spe_brhz, 0x044) + +/* Control instructions + */ +EMIT (spe_lnop, 0x001) + +extern void +spe_lqd(struct spe_function *p, int rT, int rA, int offset); + +extern void +spe_stqd(struct spe_function *p, int rT, int rA, int offset); + +extern void spe_bi(struct spe_function *p, int rA, int d, int e); +extern void spe_iret(struct spe_function *p, int rA, int d, int e); +extern void spe_bisled(struct spe_function *p, int rT, int rA, + int d, int e); +extern void spe_bisl(struct spe_function *p, int rT, int rA, + int d, int e); +extern void spe_biz(struct spe_function *p, int rT, int rA, + int d, int e); +extern void spe_binz(struct spe_function *p, int rT, int rA, + int d, int e); +extern void spe_bihz(struct spe_function *p, int rT, int rA, + int d, int e); +extern void spe_bihnz(struct spe_function *p, int rT, int rA, + int d, int e); + + +/** Load/splat immediate float into rT. */ +extern void +spe_load_float(struct spe_function *p, int rT, float x); + +/** Load/splat immediate int into rT. */ +extern void +spe_load_int(struct spe_function *p, int rT, int i); + +/** Load/splat immediate unsigned int into rT. */ +extern void +spe_load_uint(struct spe_function *p, int rT, uint ui); + +/** And immediate value into rT. */ +extern void +spe_and_uint(struct spe_function *p, int rT, int rA, uint ui); + +/** Xor immediate value into rT. */ +extern void +spe_xor_uint(struct spe_function *p, int rT, int rA, uint ui); + +/** Compare equal with immediate value. */ +extern void +spe_compare_equal_uint(struct spe_function *p, int rT, int rA, uint ui); + +/** Compare greater with immediate value. */ +extern void +spe_compare_greater_uint(struct spe_function *p, int rT, int rA, uint ui); + +/** Replicate word 0 of rA across rT. */ +extern void +spe_splat(struct spe_function *p, int rT, int rA); + +/** rT = complement_all_bits(rA). */ +extern void +spe_complement(struct spe_function *p, int rT, int rA); + +/** rT = rA. */ +extern void +spe_move(struct spe_function *p, int rT, int rA); + +/** rT = {0,0,0,0}. */ +extern void +spe_zero(struct spe_function *p, int rT); + +/** rT = splat(rA, word) */ +extern void +spe_splat_word(struct spe_function *p, int rT, int rA, int word); + +/** rT = float min(rA, rB) */ +extern void +spe_float_min(struct spe_function *p, int rT, int rA, int rB); + +/** rT = float max(rA, rB) */ +extern void +spe_float_max(struct spe_function *p, int rT, int rA, int rB); + + +/* Floating-point instructions + */ +EMIT_RR (spe_fa, 0x2c4) +EMIT_RR (spe_dfa, 0x2cc) +EMIT_RR (spe_fs, 0x2c5) +EMIT_RR (spe_dfs, 0x2cd) +EMIT_RR (spe_fm, 0x2c6) +EMIT_RR (spe_dfm, 0x2ce) +EMIT_RRR (spe_fma, 0x00e) +EMIT_RR (spe_dfma, 0x35c) +EMIT_RRR (spe_fnms, 0x00d) +EMIT_RR (spe_dfnms, 0x35e) +EMIT_RRR (spe_fms, 0x00f) +EMIT_RR (spe_dfms, 0x35d) +EMIT_RR (spe_dfnma, 0x35f) +EMIT_R (spe_frest, 0x1b8) +EMIT_R (spe_frsqest, 0x1b9) +EMIT_RR (spe_fi, 0x3d4) +EMIT_RI8 (spe_csflt, 0x1da, 155) +EMIT_RI8 (spe_cflts, 0x1d8, 173) +EMIT_RI8 (spe_cuflt, 0x1db, 155) +EMIT_RI8 (spe_cfltu, 0x1d9, 173) +EMIT_R (spe_frds, 0x3b9) +EMIT_R (spe_fesd, 0x3b8) +EMIT_RR (spe_dfceq, 0x3c3) +EMIT_RR (spe_dfcmeq, 0x3cb) +EMIT_RR (spe_dfcgt, 0x2c3) +EMIT_RR (spe_dfcmgt, 0x2cb) +EMIT_RI7 (spe_dftsv, 0x3bf) +EMIT_RR (spe_fceq, 0x3c2) +EMIT_RR (spe_fcmeq, 0x3ca) +EMIT_RR (spe_fcgt, 0x2c2) +EMIT_RR (spe_fcmgt, 0x2ca) +EMIT_R (spe_fscrwr, 0x3ba) +EMIT_ (spe_fscrrd, 0x398) + + +/* Channel instructions + */ +EMIT_R (spe_rdch, 0x00d) +EMIT_R (spe_rdchcnt, 0x00f) +EMIT_R (spe_wrch, 0x10d) + + +#ifdef UNDEF_EMIT_MACROS +#undef EMIT +#undef EMIT_ +#undef EMIT_R +#undef EMIT_RR +#undef EMIT_RRR +#undef EMIT_RI7 +#undef EMIT_RI8 +#undef EMIT_RI10 +#undef EMIT_RI10s +#undef EMIT_RI16 +#undef EMIT_RI18 +#undef EMIT_I16 +#undef UNDEF_EMIT_MACROS +#endif /* EMIT_ */ diff --git a/src/gallium/auxiliary/rtasm/rtasm_x86sse.c b/src/gallium/auxiliary/rtasm/rtasm_x86sse.c new file mode 100644 index 0000000..75b0f6a --- /dev/null +++ b/src/gallium/auxiliary/rtasm/rtasm_x86sse.c @@ -0,0 +1,2220 @@ +/************************************************************************** + * + * Copyright (C) 1999-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. + * + **************************************************************************/ + +#include "pipe/p_config.h" +#include "util/u_cpu_detect.h" + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" +#include "util/u_pointer.h" + +#include "rtasm_execmem.h" +#include "rtasm_x86sse.h" + +#define DISASSEM 0 +#define X86_TWOB 0x0f + + +#define DUMP_SSE 0 + + +void x86_print_reg( struct x86_reg reg ) +{ + if (reg.mod != mod_REG) + debug_printf( "[" ); + + switch( reg.file ) { + case file_REG32: + switch( reg.idx ) { + case reg_AX: debug_printf( "EAX" ); break; + case reg_CX: debug_printf( "ECX" ); break; + case reg_DX: debug_printf( "EDX" ); break; + case reg_BX: debug_printf( "EBX" ); break; + case reg_SP: debug_printf( "ESP" ); break; + case reg_BP: debug_printf( "EBP" ); break; + case reg_SI: debug_printf( "ESI" ); break; + case reg_DI: debug_printf( "EDI" ); break; + } + break; + case file_MMX: + debug_printf( "MMX%u", reg.idx ); + break; + case file_XMM: + debug_printf( "XMM%u", reg.idx ); + break; + case file_x87: + debug_printf( "fp%u", reg.idx ); + break; + } + + if (reg.mod == mod_DISP8 || + reg.mod == mod_DISP32) + debug_printf("+%d", reg.disp); + + if (reg.mod != mod_REG) + debug_printf( "]" ); +} + +#if DUMP_SSE + +#define DUMP_START() debug_printf( "\n" ) +#define DUMP_END() debug_printf( "\n" ) + +#define DUMP() do { \ + const char *foo = __FUNCTION__; \ + while (*foo && *foo != '_') \ + foo++; \ + if (*foo) \ + foo++; \ + debug_printf( "\n%4x %14s ", p->csr - p->store, foo ); \ +} while (0) + +#define DUMP_I( I ) do { \ + DUMP(); \ + debug_printf( "%u", I ); \ +} while( 0 ) + +#define DUMP_R( R0 ) do { \ + DUMP(); \ + x86_print_reg( R0 ); \ +} while( 0 ) + +#define DUMP_RR( R0, R1 ) do { \ + DUMP(); \ + x86_print_reg( R0 ); \ + debug_printf( ", " ); \ + x86_print_reg( R1 ); \ +} while( 0 ) + +#define DUMP_RI( R0, I ) do { \ + DUMP(); \ + x86_print_reg( R0 ); \ + debug_printf( ", %u", I ); \ +} while( 0 ) + +#define DUMP_RRI( R0, R1, I ) do { \ + DUMP(); \ + x86_print_reg( R0 ); \ + debug_printf( ", " ); \ + x86_print_reg( R1 ); \ + debug_printf( ", %u", I ); \ +} while( 0 ) + +#else + +#define DUMP_START() +#define DUMP_END() +#define DUMP( ) +#define DUMP_I( I ) +#define DUMP_R( R0 ) +#define DUMP_RR( R0, R1 ) +#define DUMP_RI( R0, I ) +#define DUMP_RRI( R0, R1, I ) + +#endif + + +static void do_realloc( struct x86_function *p ) +{ + if (p->store == p->error_overflow) { + p->csr = p->store; + } + else if (p->size == 0) { + p->size = 1024; + p->store = rtasm_exec_malloc(p->size); + p->csr = p->store; + } + else { + uintptr_t used = pointer_to_uintptr( p->csr ) - pointer_to_uintptr( p->store ); + unsigned char *tmp = p->store; + p->size *= 2; + p->store = rtasm_exec_malloc(p->size); + + if (p->store) { + memcpy(p->store, tmp, used); + p->csr = p->store + used; + } + else { + p->csr = p->store; + } + + rtasm_exec_free(tmp); + } + + if (p->store == NULL) { + p->store = p->csr = p->error_overflow; + p->size = sizeof(p->error_overflow); + } +} + +/* Emit bytes to the instruction stream: + */ +static unsigned char *reserve( struct x86_function *p, int bytes ) +{ + if (p->csr + bytes - p->store > (int) p->size) + do_realloc(p); + + { + unsigned char *csr = p->csr; + p->csr += bytes; + return csr; + } +} + + + +static void emit_1b( struct x86_function *p, char b0 ) +{ + char *csr = (char *)reserve(p, 1); + *csr = b0; +} + +static void emit_1i( struct x86_function *p, int i0 ) +{ + int *icsr = (int *)reserve(p, sizeof(i0)); + *icsr = i0; +} + +static void emit_1ub( struct x86_function *p, unsigned char b0 ) +{ + unsigned char *csr = reserve(p, 1); + *csr++ = b0; +} + +static void emit_2ub( struct x86_function *p, unsigned char b0, unsigned char b1 ) +{ + unsigned char *csr = reserve(p, 2); + *csr++ = b0; + *csr++ = b1; +} + +static void emit_3ub( struct x86_function *p, unsigned char b0, unsigned char b1, unsigned char b2 ) +{ + unsigned char *csr = reserve(p, 3); + *csr++ = b0; + *csr++ = b1; + *csr++ = b2; +} + + +/* Build a modRM byte + possible displacement. No treatment of SIB + * indexing. BZZT - no way to encode an absolute address. + * + * This is the "/r" field in the x86 manuals... + */ +static void emit_modrm( struct x86_function *p, + struct x86_reg reg, + struct x86_reg regmem ) +{ + unsigned char val = 0; + + assert(reg.mod == mod_REG); + + /* TODO: support extended x86-64 registers */ + assert(reg.idx < 8); + assert(regmem.idx < 8); + + val |= regmem.mod << 6; /* mod field */ + val |= reg.idx << 3; /* reg field */ + val |= regmem.idx; /* r/m field */ + + emit_1ub(p, val); + + /* Oh-oh we've stumbled into the SIB thing. + */ + if (regmem.file == file_REG32 && + regmem.idx == reg_SP && + regmem.mod != mod_REG) { + emit_1ub(p, 0x24); /* simplistic! */ + } + + switch (regmem.mod) { + case mod_REG: + case mod_INDIRECT: + break; + case mod_DISP8: + emit_1b(p, (char) regmem.disp); + break; + case mod_DISP32: + emit_1i(p, regmem.disp); + break; + default: + assert(0); + break; + } +} + +/* Emits the "/0".."/7" specialized versions of the modrm ("/r") bytes. + */ +static void emit_modrm_noreg( struct x86_function *p, + unsigned op, + struct x86_reg regmem ) +{ + struct x86_reg dummy = x86_make_reg(file_REG32, op); + emit_modrm(p, dummy, regmem); +} + +/* Many x86 instructions have two opcodes to cope with the situations + * where the destination is a register or memory reference + * respectively. This function selects the correct opcode based on + * the arguments presented. + */ +static void emit_op_modrm( struct x86_function *p, + unsigned char op_dst_is_reg, + unsigned char op_dst_is_mem, + struct x86_reg dst, + struct x86_reg src ) +{ + switch (dst.mod) { + case mod_REG: + emit_1ub(p, op_dst_is_reg); + emit_modrm(p, dst, src); + break; + case mod_INDIRECT: + case mod_DISP32: + case mod_DISP8: + assert(src.mod == mod_REG); + emit_1ub(p, op_dst_is_mem); + emit_modrm(p, src, dst); + break; + default: + assert(0); + break; + } +} + + + + + + + +/* Create and manipulate registers and regmem values: + */ +struct x86_reg x86_make_reg( enum x86_reg_file file, + enum x86_reg_name idx ) +{ + struct x86_reg reg; + + reg.file = file; + reg.idx = idx; + reg.mod = mod_REG; + reg.disp = 0; + + return reg; +} + +struct x86_reg x86_make_disp( struct x86_reg reg, + int disp ) +{ + assert(reg.file == file_REG32); + + if (reg.mod == mod_REG) + reg.disp = disp; + else + reg.disp += disp; + + if (reg.disp == 0 && reg.idx != reg_BP) + reg.mod = mod_INDIRECT; + else if (reg.disp <= 127 && reg.disp >= -128) + reg.mod = mod_DISP8; + else + reg.mod = mod_DISP32; + + return reg; +} + +struct x86_reg x86_deref( struct x86_reg reg ) +{ + return x86_make_disp(reg, 0); +} + +struct x86_reg x86_get_base_reg( struct x86_reg reg ) +{ + return x86_make_reg( reg.file, reg.idx ); +} + +int x86_get_label( struct x86_function *p ) +{ + return p->csr - p->store; +} + + + +/*********************************************************************** + * x86 instructions + */ + + +void x64_rexw(struct x86_function *p) +{ + if(x86_target(p) != X86_32) + emit_1ub(p, 0x48); +} + +void x86_jcc( struct x86_function *p, + enum x86_cc cc, + int label ) +{ + int offset = label - (x86_get_label(p) + 2); + DUMP_I(cc); + + if (offset < 0) { + /*assert(p->csr - p->store > -offset);*/ + if (p->csr - p->store <= -offset) { + /* probably out of memory (using the error_overflow buffer) */ + return; + } + } + + if (offset <= 127 && offset >= -128) { + emit_1ub(p, 0x70 + cc); + emit_1b(p, (char) offset); + } + else { + offset = label - (x86_get_label(p) + 6); + emit_2ub(p, 0x0f, 0x80 + cc); + emit_1i(p, offset); + } +} + +/* Always use a 32bit offset for forward jumps: + */ +int x86_jcc_forward( struct x86_function *p, + enum x86_cc cc ) +{ + DUMP_I(cc); + emit_2ub(p, 0x0f, 0x80 + cc); + emit_1i(p, 0); + return x86_get_label(p); +} + +int x86_jmp_forward( struct x86_function *p) +{ + DUMP(); + emit_1ub(p, 0xe9); + emit_1i(p, 0); + return x86_get_label(p); +} + +int x86_call_forward( struct x86_function *p) +{ + DUMP(); + + emit_1ub(p, 0xe8); + emit_1i(p, 0); + return x86_get_label(p); +} + +/* Fixup offset from forward jump: + */ +void x86_fixup_fwd_jump( struct x86_function *p, + int fixup ) +{ + *(int *)(p->store + fixup - 4) = x86_get_label(p) - fixup; +} + +void x86_jmp( struct x86_function *p, int label) +{ + DUMP_I( label ); + emit_1ub(p, 0xe9); + emit_1i(p, label - x86_get_label(p) - 4); +} + +void x86_call( struct x86_function *p, struct x86_reg reg) +{ + DUMP_R( reg ); + emit_1ub(p, 0xff); + emit_modrm_noreg(p, 2, reg); +} + + +void x86_mov_reg_imm( struct x86_function *p, struct x86_reg dst, int imm ) +{ + DUMP_RI( dst, imm ); + assert(dst.file == file_REG32); + assert(dst.mod == mod_REG); + emit_1ub(p, 0xb8 + dst.idx); + emit_1i(p, imm); +} + +void x86_mov_imm( struct x86_function *p, struct x86_reg dst, int imm ) +{ + DUMP_RI( dst, imm ); + if(dst.mod == mod_REG) + x86_mov_reg_imm(p, dst, imm); + else + { + emit_1ub(p, 0xc7); + emit_modrm_noreg(p, 0, dst); + emit_1i(p, imm); + } +} + +void x86_mov16_imm( struct x86_function *p, struct x86_reg dst, uint16_t imm ) +{ + DUMP_RI( dst, imm ); + emit_1ub(p, 0x66); + if(dst.mod == mod_REG) + { + emit_1ub(p, 0xb8 + dst.idx); + emit_2ub(p, imm & 0xff, imm >> 8); + } + else + { + emit_1ub(p, 0xc7); + emit_modrm_noreg(p, 0, dst); + emit_2ub(p, imm & 0xff, imm >> 8); + } +} + +void x86_mov8_imm( struct x86_function *p, struct x86_reg dst, uint8_t imm ) +{ + DUMP_RI( dst, imm ); + if(dst.mod == mod_REG) + { + emit_1ub(p, 0xb0 + dst.idx); + emit_1ub(p, imm); + } + else + { + emit_1ub(p, 0xc6); + emit_modrm_noreg(p, 0, dst); + emit_1ub(p, imm); + } +} + +/** + * Immediate group 1 instructions. + */ +static INLINE void +x86_group1_imm( struct x86_function *p, + unsigned op, struct x86_reg dst, int imm ) +{ + assert(dst.file == file_REG32); + assert(dst.mod == mod_REG); + if(-0x80 <= imm && imm < 0x80) { + emit_1ub(p, 0x83); + emit_modrm_noreg(p, op, dst); + emit_1b(p, (char)imm); + } + else { + emit_1ub(p, 0x81); + emit_modrm_noreg(p, op, dst); + emit_1i(p, imm); + } +} + +void x86_add_imm( struct x86_function *p, struct x86_reg dst, int imm ) +{ + DUMP_RI( dst, imm ); + x86_group1_imm(p, 0, dst, imm); +} + +void x86_or_imm( struct x86_function *p, struct x86_reg dst, int imm ) +{ + DUMP_RI( dst, imm ); + x86_group1_imm(p, 1, dst, imm); +} + +void x86_and_imm( struct x86_function *p, struct x86_reg dst, int imm ) +{ + DUMP_RI( dst, imm ); + x86_group1_imm(p, 4, dst, imm); +} + +void x86_sub_imm( struct x86_function *p, struct x86_reg dst, int imm ) +{ + DUMP_RI( dst, imm ); + x86_group1_imm(p, 5, dst, imm); +} + +void x86_xor_imm( struct x86_function *p, struct x86_reg dst, int imm ) +{ + DUMP_RI( dst, imm ); + x86_group1_imm(p, 6, dst, imm); +} + +void x86_cmp_imm( struct x86_function *p, struct x86_reg dst, int imm ) +{ + DUMP_RI( dst, imm ); + x86_group1_imm(p, 7, dst, imm); +} + + +void x86_push( struct x86_function *p, + struct x86_reg reg ) +{ + DUMP_R( reg ); + if (reg.mod == mod_REG) + emit_1ub(p, 0x50 + reg.idx); + else + { + emit_1ub(p, 0xff); + emit_modrm_noreg(p, 6, reg); + } + + + p->stack_offset += sizeof(void*); +} + +void x86_push_imm32( struct x86_function *p, + int imm32 ) +{ + DUMP_I( imm32 ); + emit_1ub(p, 0x68); + emit_1i(p, imm32); + + p->stack_offset += sizeof(void*); +} + + +void x86_pop( struct x86_function *p, + struct x86_reg reg ) +{ + DUMP_R( reg ); + assert(reg.mod == mod_REG); + emit_1ub(p, 0x58 + reg.idx); + p->stack_offset -= sizeof(void*); +} + +void x86_inc( struct x86_function *p, + struct x86_reg reg ) +{ + DUMP_R( reg ); + if(x86_target(p) == X86_32 && reg.mod == mod_REG) + { + emit_1ub(p, 0x40 + reg.idx); + return; + } + emit_1ub(p, 0xff); + emit_modrm_noreg(p, 0, reg); +} + +void x86_dec( struct x86_function *p, + struct x86_reg reg ) +{ + DUMP_R( reg ); + if(x86_target(p) == X86_32 && reg.mod == mod_REG) + { + emit_1ub(p, 0x48 + reg.idx); + return; + } + emit_1ub(p, 0xff); + emit_modrm_noreg(p, 1, reg); +} + +void x86_ret( struct x86_function *p ) +{ + DUMP(); + assert(p->stack_offset == 0); + emit_1ub(p, 0xc3); +} + +void x86_retw( struct x86_function *p, unsigned short imm ) +{ + DUMP(); + emit_3ub(p, 0xc2, imm & 0xff, (imm >> 8) & 0xff); +} + +void x86_sahf( struct x86_function *p ) +{ + DUMP(); + emit_1ub(p, 0x9e); +} + +void x86_mov( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + /* special hack for reading arguments until we support x86-64 registers everywhere */ + if(src.mod == mod_REG && dst.mod == mod_REG && (src.idx >= 8 || dst.idx >= 8)) + { + uint8_t rex = 0x40; + if(dst.idx >= 8) + { + rex |= 4; + dst.idx -= 8; + } + if(src.idx >= 8) + { + rex |= 1; + src.idx -= 8; + } + emit_1ub(p, rex); + } + emit_op_modrm( p, 0x8b, 0x89, dst, src ); +} + +void x86_mov16( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_1ub(p, 0x66); + emit_op_modrm( p, 0x8b, 0x89, dst, src ); +} + +void x86_mov8( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_op_modrm( p, 0x8a, 0x88, dst, src ); +} + +void x64_mov64( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + uint8_t rex = 0x48; + DUMP_RR( dst, src ); + assert(x86_target(p) != X86_32); + + /* special hack for reading arguments until we support x86-64 registers everywhere */ + if(src.mod == mod_REG && dst.mod == mod_REG && (src.idx >= 8 || dst.idx >= 8)) + { + if(dst.idx >= 8) + { + rex |= 4; + dst.idx -= 8; + } + if(src.idx >= 8) + { + rex |= 1; + src.idx -= 8; + } + } + emit_1ub(p, rex); + emit_op_modrm( p, 0x8b, 0x89, dst, src ); +} + +void x86_movzx8(struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, 0x0f, 0xb6); + emit_modrm(p, dst, src); +} + +void x86_movzx16(struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, 0x0f, 0xb7); + emit_modrm(p, dst, src); +} + +void x86_xor( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_op_modrm( p, 0x33, 0x31, dst, src ); +} + +void x86_cmp( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_op_modrm( p, 0x3b, 0x39, dst, src ); +} + +void x86_lea( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_1ub(p, 0x8d); + emit_modrm( p, dst, src ); +} + +void x86_test( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_1ub(p, 0x85); + emit_modrm( p, dst, src ); +} + +void x86_add( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_op_modrm(p, 0x03, 0x01, dst, src ); +} + +/* Calculate EAX * src, results in EDX:EAX. + */ +void x86_mul( struct x86_function *p, + struct x86_reg src ) +{ + DUMP_R( src ); + emit_1ub(p, 0xf7); + emit_modrm_noreg(p, 4, src ); +} + + +void x86_imul( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, X86_TWOB, 0xAF); + emit_modrm(p, dst, src); +} + + +void x86_sub( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_op_modrm(p, 0x2b, 0x29, dst, src ); +} + +void x86_or( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_op_modrm( p, 0x0b, 0x09, dst, src ); +} + +void x86_and( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_op_modrm( p, 0x23, 0x21, dst, src ); +} + +void x86_div( struct x86_function *p, + struct x86_reg src ) +{ + assert(src.file == file_REG32 && src.mod == mod_REG); + emit_op_modrm(p, 0xf7, 0, x86_make_reg(file_REG32, 6), src); +} + +void x86_bswap( struct x86_function *p, struct x86_reg reg ) +{ + DUMP_R(reg); + assert(reg.file == file_REG32); + assert(reg.mod == mod_REG); + emit_2ub(p, 0x0f, 0xc8 + reg.idx); +} + +void x86_shr_imm( struct x86_function *p, struct x86_reg reg, unsigned imm ) +{ + DUMP_RI(reg, imm); + if(imm == 1) + { + emit_1ub(p, 0xd1); + emit_modrm_noreg(p, 5, reg); + } + else + { + emit_1ub(p, 0xc1); + emit_modrm_noreg(p, 5, reg); + emit_1ub(p, imm); + } +} + +void x86_sar_imm( struct x86_function *p, struct x86_reg reg, unsigned imm ) +{ + DUMP_RI(reg, imm); + if(imm == 1) + { + emit_1ub(p, 0xd1); + emit_modrm_noreg(p, 7, reg); + } + else + { + emit_1ub(p, 0xc1); + emit_modrm_noreg(p, 7, reg); + emit_1ub(p, imm); + } +} + +void x86_shl_imm( struct x86_function *p, struct x86_reg reg, unsigned imm ) +{ + DUMP_RI(reg, imm); + if(imm == 1) + { + emit_1ub(p, 0xd1); + emit_modrm_noreg(p, 4, reg); + } + else + { + emit_1ub(p, 0xc1); + emit_modrm_noreg(p, 4, reg); + emit_1ub(p, imm); + } +} + + +/*********************************************************************** + * SSE instructions + */ + +void sse_prefetchnta( struct x86_function *p, struct x86_reg ptr) +{ + DUMP_R( ptr ); + assert(ptr.mod != mod_REG); + emit_2ub(p, 0x0f, 0x18); + emit_modrm_noreg(p, 0, ptr); +} + +void sse_prefetch0( struct x86_function *p, struct x86_reg ptr) +{ + DUMP_R( ptr ); + assert(ptr.mod != mod_REG); + emit_2ub(p, 0x0f, 0x18); + emit_modrm_noreg(p, 1, ptr); +} + +void sse_prefetch1( struct x86_function *p, struct x86_reg ptr) +{ + DUMP_R( ptr ); + assert(ptr.mod != mod_REG); + emit_2ub(p, 0x0f, 0x18); + emit_modrm_noreg(p, 2, ptr); +} + +void sse_movntps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src) +{ + DUMP_RR( dst, src ); + + assert(dst.mod != mod_REG); + assert(src.mod == mod_REG); + emit_2ub(p, 0x0f, 0x2b); + emit_modrm(p, src, dst); +} + + + + +void sse_movss( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, 0xF3, X86_TWOB); + emit_op_modrm( p, 0x10, 0x11, dst, src ); +} + +void sse_movaps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_1ub(p, X86_TWOB); + emit_op_modrm( p, 0x28, 0x29, dst, src ); +} + +void sse_movups( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_1ub(p, X86_TWOB); + emit_op_modrm( p, 0x10, 0x11, dst, src ); +} + +void sse_movhps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + assert(dst.mod != mod_REG || src.mod != mod_REG); + emit_1ub(p, X86_TWOB); + emit_op_modrm( p, 0x16, 0x17, dst, src ); /* cf movlhps */ +} + +void sse_movlps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + assert(dst.mod != mod_REG || src.mod != mod_REG); + emit_1ub(p, X86_TWOB); + emit_op_modrm( p, 0x12, 0x13, dst, src ); /* cf movhlps */ +} + +void sse_maxps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, X86_TWOB, 0x5F); + emit_modrm( p, dst, src ); +} + +void sse_maxss( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0xF3, X86_TWOB, 0x5F); + emit_modrm( p, dst, src ); +} + +void sse_divss( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0xF3, X86_TWOB, 0x5E); + emit_modrm( p, dst, src ); +} + +void sse_minps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, X86_TWOB, 0x5D); + emit_modrm( p, dst, src ); +} + +void sse_subps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, X86_TWOB, 0x5C); + emit_modrm( p, dst, src ); +} + +void sse_mulps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, X86_TWOB, 0x59); + emit_modrm( p, dst, src ); +} + +void sse_mulss( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0xF3, X86_TWOB, 0x59); + emit_modrm( p, dst, src ); +} + +void sse_addps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, X86_TWOB, 0x58); + emit_modrm( p, dst, src ); +} + +void sse_addss( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0xF3, X86_TWOB, 0x58); + emit_modrm( p, dst, src ); +} + +void sse_andnps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, X86_TWOB, 0x55); + emit_modrm( p, dst, src ); +} + +void sse_andps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, X86_TWOB, 0x54); + emit_modrm( p, dst, src ); +} + +void sse_rsqrtps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, X86_TWOB, 0x52); + emit_modrm( p, dst, src ); +} + +void sse_rsqrtss( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0xF3, X86_TWOB, 0x52); + emit_modrm( p, dst, src ); + +} + +void sse_movhlps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + assert(dst.mod == mod_REG && src.mod == mod_REG); + emit_2ub(p, X86_TWOB, 0x12); + emit_modrm( p, dst, src ); +} + +void sse_movlhps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + assert(dst.mod == mod_REG && src.mod == mod_REG); + emit_2ub(p, X86_TWOB, 0x16); + emit_modrm( p, dst, src ); +} + +void sse_orps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, X86_TWOB, 0x56); + emit_modrm( p, dst, src ); +} + +void sse_xorps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, X86_TWOB, 0x57); + emit_modrm( p, dst, src ); +} + +void sse_cvtps2pi( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + assert(dst.file == file_MMX && + (src.file == file_XMM || src.mod != mod_REG)); + + p->need_emms = 1; + + emit_2ub(p, X86_TWOB, 0x2d); + emit_modrm( p, dst, src ); +} + +void sse2_cvtdq2ps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, X86_TWOB, 0x5b); + emit_modrm( p, dst, src ); +} + + +/* Shufps can also be used to implement a reduced swizzle when dest == + * arg0. + */ +void sse_shufps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src, + unsigned char shuf) +{ + DUMP_RRI( dst, src, shuf ); + emit_2ub(p, X86_TWOB, 0xC6); + emit_modrm(p, dst, src); + emit_1ub(p, shuf); +} + +void sse_unpckhps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub( p, X86_TWOB, 0x15 ); + emit_modrm( p, dst, src ); +} + +void sse_unpcklps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub( p, X86_TWOB, 0x14 ); + emit_modrm( p, dst, src ); +} + +void sse_cmpps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src, + enum sse_cc cc) +{ + DUMP_RRI( dst, src, cc ); + emit_2ub(p, X86_TWOB, 0xC2); + emit_modrm(p, dst, src); + emit_1ub(p, cc); +} + +void sse_pmovmskb( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0x66, X86_TWOB, 0xD7); + emit_modrm(p, dst, src); +} + +void sse_movmskps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src) +{ + DUMP_RR( dst, src ); + emit_2ub(p, X86_TWOB, 0x50); + emit_modrm(p, dst, src); +} + +/*********************************************************************** + * SSE2 instructions + */ + +void sse2_movd( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR(dst, src); + emit_2ub(p, 0x66, 0x0f); + if(dst.mod == mod_REG && dst.file == file_REG32) + { + emit_1ub(p, 0x7e); + emit_modrm(p, src, dst); + } + else + { + emit_op_modrm(p, 0x6e, 0x7e, dst, src); + } +} + +void sse2_movq( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR(dst, src); + switch (dst.mod) { + case mod_REG: + emit_3ub(p, 0xf3, 0x0f, 0x7e); + emit_modrm(p, dst, src); + break; + case mod_INDIRECT: + case mod_DISP32: + case mod_DISP8: + assert(src.mod == mod_REG); + emit_3ub(p, 0x66, 0x0f, 0xd6); + emit_modrm(p, src, dst); + break; + default: + assert(0); + break; + } +} + +void sse2_movdqu( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR(dst, src); + emit_2ub(p, 0xf3, 0x0f); + emit_op_modrm(p, 0x6f, 0x7f, dst, src); +} + +void sse2_movdqa( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR(dst, src); + emit_2ub(p, 0x66, 0x0f); + emit_op_modrm(p, 0x6f, 0x7f, dst, src); +} + +void sse2_movsd( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR(dst, src); + emit_2ub(p, 0xf2, 0x0f); + emit_op_modrm(p, 0x10, 0x11, dst, src); +} + +void sse2_movupd( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR(dst, src); + emit_2ub(p, 0x66, 0x0f); + emit_op_modrm(p, 0x10, 0x11, dst, src); +} + +void sse2_movapd( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR(dst, src); + emit_2ub(p, 0x66, 0x0f); + emit_op_modrm(p, 0x28, 0x29, dst, src); +} + +/** + * Perform a reduced swizzle: + */ +void sse2_pshufd( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src, + unsigned char shuf) +{ + DUMP_RRI( dst, src, shuf ); + emit_3ub(p, 0x66, X86_TWOB, 0x70); + emit_modrm(p, dst, src); + emit_1ub(p, shuf); +} + +void sse2_pshuflw( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src, + unsigned char shuf) +{ + DUMP_RRI( dst, src, shuf ); + emit_3ub(p, 0xf2, X86_TWOB, 0x70); + emit_modrm(p, dst, src); + emit_1ub(p, shuf); +} + +void sse2_pshufhw( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src, + unsigned char shuf) +{ + DUMP_RRI( dst, src, shuf ); + emit_3ub(p, 0xf3, X86_TWOB, 0x70); + emit_modrm(p, dst, src); + emit_1ub(p, shuf); +} + +void sse2_cvttps2dq( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub( p, 0xF3, X86_TWOB, 0x5B ); + emit_modrm( p, dst, src ); +} + +void sse2_cvtps2dq( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0x66, X86_TWOB, 0x5B); + emit_modrm( p, dst, src ); +} + +void sse2_cvtsd2ss( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0xf2, 0x0f, 0x5a); + emit_modrm( p, dst, src ); +} + +void sse2_cvtpd2ps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0x66, 0x0f, 0x5a); + emit_modrm( p, dst, src ); +} + +void sse2_packssdw( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0x66, X86_TWOB, 0x6B); + emit_modrm( p, dst, src ); +} + +void sse2_packsswb( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0x66, X86_TWOB, 0x63); + emit_modrm( p, dst, src ); +} + +void sse2_packuswb( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0x66, X86_TWOB, 0x67); + emit_modrm( p, dst, src ); +} + +void sse2_punpcklbw( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0x66, X86_TWOB, 0x60); + emit_modrm( p, dst, src ); +} + +void sse2_punpcklwd( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0x66, 0x0f, 0x61); + emit_modrm( p, dst, src ); +} + +void sse2_punpckldq( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0x66, 0x0f, 0x62); + emit_modrm( p, dst, src ); +} + +void sse2_punpcklqdq( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0x66, 0x0f, 0x6c); + emit_modrm( p, dst, src ); +} + +void sse2_psllw_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ) +{ + DUMP_RI(dst, imm); + emit_3ub(p, 0x66, 0x0f, 0x71); + emit_modrm_noreg(p, 6, dst); + emit_1ub(p, imm); +} + +void sse2_pslld_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ) +{ + DUMP_RI(dst, imm); + emit_3ub(p, 0x66, 0x0f, 0x72); + emit_modrm_noreg(p, 6, dst); + emit_1ub(p, imm); +} + +void sse2_psllq_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ) +{ + DUMP_RI(dst, imm); + emit_3ub(p, 0x66, 0x0f, 0x73); + emit_modrm_noreg(p, 6, dst); + emit_1ub(p, imm); +} + +void sse2_psrlw_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ) +{ + DUMP_RI(dst, imm); + emit_3ub(p, 0x66, 0x0f, 0x71); + emit_modrm_noreg(p, 2, dst); + emit_1ub(p, imm); +} + +void sse2_psrld_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ) +{ + DUMP_RI(dst, imm); + emit_3ub(p, 0x66, 0x0f, 0x72); + emit_modrm_noreg(p, 2, dst); + emit_1ub(p, imm); +} + +void sse2_psrlq_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ) +{ + DUMP_RI(dst, imm); + emit_3ub(p, 0x66, 0x0f, 0x73); + emit_modrm_noreg(p, 2, dst); + emit_1ub(p, imm); +} + +void sse2_psraw_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ) +{ + DUMP_RI(dst, imm); + emit_3ub(p, 0x66, 0x0f, 0x71); + emit_modrm_noreg(p, 4, dst); + emit_1ub(p, imm); +} + +void sse2_psrad_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ) +{ + DUMP_RI(dst, imm); + emit_3ub(p, 0x66, 0x0f, 0x72); + emit_modrm_noreg(p, 4, dst); + emit_1ub(p, imm); +} + +void sse2_por( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR(dst, src); + emit_3ub(p, 0x66, 0x0f, 0xeb); + emit_modrm(p, dst, src); +} + +void sse2_rcpps( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_2ub(p, X86_TWOB, 0x53); + emit_modrm( p, dst, src ); +} + +void sse2_rcpss( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + emit_3ub(p, 0xF3, X86_TWOB, 0x53); + emit_modrm( p, dst, src ); +} + +/*********************************************************************** + * x87 instructions + */ +static void note_x87_pop( struct x86_function *p ) +{ + p->x87_stack--; + assert(p->x87_stack >= 0); +} + +static void note_x87_push( struct x86_function *p ) +{ + p->x87_stack++; + assert(p->x87_stack <= 7); +} + +void x87_assert_stack_empty( struct x86_function *p ) +{ + assert (p->x87_stack == 0); +} + + +void x87_fist( struct x86_function *p, struct x86_reg dst ) +{ + DUMP_R( dst ); + emit_1ub(p, 0xdb); + emit_modrm_noreg(p, 2, dst); +} + +void x87_fistp( struct x86_function *p, struct x86_reg dst ) +{ + DUMP_R( dst ); + emit_1ub(p, 0xdb); + emit_modrm_noreg(p, 3, dst); + note_x87_pop(p); +} + +void x87_fild( struct x86_function *p, struct x86_reg arg ) +{ + DUMP_R( arg ); + emit_1ub(p, 0xdf); + emit_modrm_noreg(p, 0, arg); + note_x87_push(p); +} + +void x87_fldz( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xee); + note_x87_push(p); +} + + +void x87_fldcw( struct x86_function *p, struct x86_reg arg ) +{ + DUMP_R( arg ); + assert(arg.file == file_REG32); + assert(arg.mod != mod_REG); + emit_1ub(p, 0xd9); + emit_modrm_noreg(p, 5, arg); +} + +void x87_fld1( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xe8); + note_x87_push(p); +} + +void x87_fldl2e( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xea); + note_x87_push(p); +} + +void x87_fldln2( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xed); + note_x87_push(p); +} + +void x87_fwait( struct x86_function *p ) +{ + DUMP(); + emit_1ub(p, 0x9b); +} + +void x87_fnclex( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xdb, 0xe2); +} + +void x87_fclex( struct x86_function *p ) +{ + x87_fwait(p); + x87_fnclex(p); +} + +void x87_fcmovb( struct x86_function *p, struct x86_reg arg ) +{ + DUMP_R( arg ); + assert(arg.file == file_x87); + emit_2ub(p, 0xda, 0xc0+arg.idx); +} + +void x87_fcmove( struct x86_function *p, struct x86_reg arg ) +{ + DUMP_R( arg ); + assert(arg.file == file_x87); + emit_2ub(p, 0xda, 0xc8+arg.idx); +} + +void x87_fcmovbe( struct x86_function *p, struct x86_reg arg ) +{ + DUMP_R( arg ); + assert(arg.file == file_x87); + emit_2ub(p, 0xda, 0xd0+arg.idx); +} + +void x87_fcmovnb( struct x86_function *p, struct x86_reg arg ) +{ + DUMP_R( arg ); + assert(arg.file == file_x87); + emit_2ub(p, 0xdb, 0xc0+arg.idx); +} + +void x87_fcmovne( struct x86_function *p, struct x86_reg arg ) +{ + DUMP_R( arg ); + assert(arg.file == file_x87); + emit_2ub(p, 0xdb, 0xc8+arg.idx); +} + +void x87_fcmovnbe( struct x86_function *p, struct x86_reg arg ) +{ + DUMP_R( arg ); + assert(arg.file == file_x87); + emit_2ub(p, 0xdb, 0xd0+arg.idx); +} + + + +static void x87_arith_op( struct x86_function *p, struct x86_reg dst, struct x86_reg arg, + unsigned char dst0ub0, + unsigned char dst0ub1, + unsigned char arg0ub0, + unsigned char arg0ub1, + unsigned char argmem_noreg) +{ + assert(dst.file == file_x87); + + if (arg.file == file_x87) { + if (dst.idx == 0) + emit_2ub(p, dst0ub0, dst0ub1+arg.idx); + else if (arg.idx == 0) + emit_2ub(p, arg0ub0, arg0ub1+arg.idx); + else + assert(0); + } + else if (dst.idx == 0) { + assert(arg.file == file_REG32); + emit_1ub(p, 0xd8); + emit_modrm_noreg(p, argmem_noreg, arg); + } + else + assert(0); +} + +void x87_fmul( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR( dst, src ); + x87_arith_op(p, dst, src, + 0xd8, 0xc8, + 0xdc, 0xc8, + 4); +} + +void x87_fsub( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR( dst, src ); + x87_arith_op(p, dst, src, + 0xd8, 0xe0, + 0xdc, 0xe8, + 4); +} + +void x87_fsubr( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR( dst, src ); + x87_arith_op(p, dst, src, + 0xd8, 0xe8, + 0xdc, 0xe0, + 5); +} + +void x87_fadd( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR( dst, src ); + x87_arith_op(p, dst, src, + 0xd8, 0xc0, + 0xdc, 0xc0, + 0); +} + +void x87_fdiv( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR( dst, src ); + x87_arith_op(p, dst, src, + 0xd8, 0xf0, + 0xdc, 0xf8, + 6); +} + +void x87_fdivr( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) +{ + DUMP_RR( dst, src ); + x87_arith_op(p, dst, src, + 0xd8, 0xf8, + 0xdc, 0xf0, + 7); +} + +void x87_fmulp( struct x86_function *p, struct x86_reg dst ) +{ + DUMP_R( dst ); + assert(dst.file == file_x87); + assert(dst.idx >= 1); + emit_2ub(p, 0xde, 0xc8+dst.idx); + note_x87_pop(p); +} + +void x87_fsubp( struct x86_function *p, struct x86_reg dst ) +{ + DUMP_R( dst ); + assert(dst.file == file_x87); + assert(dst.idx >= 1); + emit_2ub(p, 0xde, 0xe8+dst.idx); + note_x87_pop(p); +} + +void x87_fsubrp( struct x86_function *p, struct x86_reg dst ) +{ + DUMP_R( dst ); + assert(dst.file == file_x87); + assert(dst.idx >= 1); + emit_2ub(p, 0xde, 0xe0+dst.idx); + note_x87_pop(p); +} + +void x87_faddp( struct x86_function *p, struct x86_reg dst ) +{ + DUMP_R( dst ); + assert(dst.file == file_x87); + assert(dst.idx >= 1); + emit_2ub(p, 0xde, 0xc0+dst.idx); + note_x87_pop(p); +} + +void x87_fdivp( struct x86_function *p, struct x86_reg dst ) +{ + DUMP_R( dst ); + assert(dst.file == file_x87); + assert(dst.idx >= 1); + emit_2ub(p, 0xde, 0xf8+dst.idx); + note_x87_pop(p); +} + +void x87_fdivrp( struct x86_function *p, struct x86_reg dst ) +{ + DUMP_R( dst ); + assert(dst.file == file_x87); + assert(dst.idx >= 1); + emit_2ub(p, 0xde, 0xf0+dst.idx); + note_x87_pop(p); +} + +void x87_ftst( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xe4); +} + +void x87_fucom( struct x86_function *p, struct x86_reg arg ) +{ + DUMP_R( arg ); + assert(arg.file == file_x87); + emit_2ub(p, 0xdd, 0xe0+arg.idx); +} + +void x87_fucomp( struct x86_function *p, struct x86_reg arg ) +{ + DUMP_R( arg ); + assert(arg.file == file_x87); + emit_2ub(p, 0xdd, 0xe8+arg.idx); + note_x87_pop(p); +} + +void x87_fucompp( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xda, 0xe9); + note_x87_pop(p); /* pop twice */ + note_x87_pop(p); /* pop twice */ +} + +void x87_fxch( struct x86_function *p, struct x86_reg arg ) +{ + DUMP_R( arg ); + assert(arg.file == file_x87); + emit_2ub(p, 0xd9, 0xc8+arg.idx); +} + +void x87_fabs( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xe1); +} + +void x87_fchs( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xe0); +} + +void x87_fcos( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xff); +} + + +void x87_fprndint( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xfc); +} + +void x87_fscale( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xfd); +} + +void x87_fsin( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xfe); +} + +void x87_fsincos( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xfb); +} + +void x87_fsqrt( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xfa); +} + +void x87_fxtract( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xf4); +} + +/* st0 = (2^st0)-1 + * + * Restrictions: -1.0 <= st0 <= 1.0 + */ +void x87_f2xm1( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xf0); +} + +/* st1 = st1 * log2(st0); + * pop_stack; + */ +void x87_fyl2x( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xf1); + note_x87_pop(p); +} + +/* st1 = st1 * log2(st0 + 1.0); + * pop_stack; + * + * A fast operation, with restrictions: -.29 < st0 < .29 + */ +void x87_fyl2xp1( struct x86_function *p ) +{ + DUMP(); + emit_2ub(p, 0xd9, 0xf9); + note_x87_pop(p); +} + + +void x87_fld( struct x86_function *p, struct x86_reg arg ) +{ + DUMP_R( arg ); + if (arg.file == file_x87) + emit_2ub(p, 0xd9, 0xc0 + arg.idx); + else { + emit_1ub(p, 0xd9); + emit_modrm_noreg(p, 0, arg); + } + note_x87_push(p); +} + +void x87_fst( struct x86_function *p, struct x86_reg dst ) +{ + DUMP_R( dst ); + if (dst.file == file_x87) + emit_2ub(p, 0xdd, 0xd0 + dst.idx); + else { + emit_1ub(p, 0xd9); + emit_modrm_noreg(p, 2, dst); + } +} + +void x87_fstp( struct x86_function *p, struct x86_reg dst ) +{ + DUMP_R( dst ); + if (dst.file == file_x87) + emit_2ub(p, 0xdd, 0xd8 + dst.idx); + else { + emit_1ub(p, 0xd9); + emit_modrm_noreg(p, 3, dst); + } + note_x87_pop(p); +} + +void x87_fpop( struct x86_function *p ) +{ + x87_fstp( p, x86_make_reg( file_x87, 0 )); +} + + +void x87_fcom( struct x86_function *p, struct x86_reg dst ) +{ + DUMP_R( dst ); + if (dst.file == file_x87) + emit_2ub(p, 0xd8, 0xd0 + dst.idx); + else { + emit_1ub(p, 0xd8); + emit_modrm_noreg(p, 2, dst); + } +} + + +void x87_fcomp( struct x86_function *p, struct x86_reg dst ) +{ + DUMP_R( dst ); + if (dst.file == file_x87) + emit_2ub(p, 0xd8, 0xd8 + dst.idx); + else { + emit_1ub(p, 0xd8); + emit_modrm_noreg(p, 3, dst); + } + note_x87_pop(p); +} + +void x87_fcomi( struct x86_function *p, struct x86_reg arg ) +{ + DUMP_R( arg ); + emit_2ub(p, 0xdb, 0xf0+arg.idx); +} + +void x87_fcomip( struct x86_function *p, struct x86_reg arg ) +{ + DUMP_R( arg ); + emit_2ub(p, 0xdb, 0xf0+arg.idx); + note_x87_pop(p); +} + + +void x87_fnstsw( struct x86_function *p, struct x86_reg dst ) +{ + DUMP_R( dst ); + assert(dst.file == file_REG32); + + if (dst.idx == reg_AX && + dst.mod == mod_REG) + emit_2ub(p, 0xdf, 0xe0); + else { + emit_1ub(p, 0xdd); + emit_modrm_noreg(p, 7, dst); + } +} + + +void x87_fnstcw( struct x86_function *p, struct x86_reg dst ) +{ + DUMP_R( dst ); + assert(dst.file == file_REG32); + + emit_1ub(p, 0x9b); /* WAIT -- needed? */ + emit_1ub(p, 0xd9); + emit_modrm_noreg(p, 7, dst); +} + + + + +/*********************************************************************** + * MMX instructions + */ + +void mmx_emms( struct x86_function *p ) +{ + DUMP(); + assert(p->need_emms); + emit_2ub(p, 0x0f, 0x77); + p->need_emms = 0; +} + +void mmx_packssdw( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + assert(dst.file == file_MMX && + (src.file == file_MMX || src.mod != mod_REG)); + + p->need_emms = 1; + + emit_2ub(p, X86_TWOB, 0x6b); + emit_modrm( p, dst, src ); +} + +void mmx_packuswb( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + assert(dst.file == file_MMX && + (src.file == file_MMX || src.mod != mod_REG)); + + p->need_emms = 1; + + emit_2ub(p, X86_TWOB, 0x67); + emit_modrm( p, dst, src ); +} + +void mmx_movd( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + p->need_emms = 1; + emit_1ub(p, X86_TWOB); + emit_op_modrm( p, 0x6e, 0x7e, dst, src ); +} + +void mmx_movq( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src ) +{ + DUMP_RR( dst, src ); + p->need_emms = 1; + emit_1ub(p, X86_TWOB); + emit_op_modrm( p, 0x6f, 0x7f, dst, src ); +} + + +/*********************************************************************** + * Helper functions + */ + + +void x86_cdecl_caller_push_regs( struct x86_function *p ) +{ + x86_push(p, x86_make_reg(file_REG32, reg_AX)); + x86_push(p, x86_make_reg(file_REG32, reg_CX)); + x86_push(p, x86_make_reg(file_REG32, reg_DX)); +} + +void x86_cdecl_caller_pop_regs( struct x86_function *p ) +{ + x86_pop(p, x86_make_reg(file_REG32, reg_DX)); + x86_pop(p, x86_make_reg(file_REG32, reg_CX)); + x86_pop(p, x86_make_reg(file_REG32, reg_AX)); +} + + +struct x86_reg x86_fn_arg( struct x86_function *p, + unsigned arg ) +{ + switch(x86_target(p)) + { + case X86_64_WIN64_ABI: + /* Microsoft uses a different calling convention than the rest of the world */ + switch(arg) + { + case 1: + return x86_make_reg(file_REG32, reg_CX); + case 2: + return x86_make_reg(file_REG32, reg_DX); + case 3: + return x86_make_reg(file_REG32, reg_R8); + case 4: + return x86_make_reg(file_REG32, reg_R9); + default: + /* Win64 allocates stack slots as if it pushed the first 4 arguments too */ + return x86_make_disp(x86_make_reg(file_REG32, reg_SP), + p->stack_offset + arg * 8); + } + case X86_64_STD_ABI: + switch(arg) + { + case 1: + return x86_make_reg(file_REG32, reg_DI); + case 2: + return x86_make_reg(file_REG32, reg_SI); + case 3: + return x86_make_reg(file_REG32, reg_DX); + case 4: + return x86_make_reg(file_REG32, reg_CX); + case 5: + return x86_make_reg(file_REG32, reg_R8); + case 6: + return x86_make_reg(file_REG32, reg_R9); + default: + return x86_make_disp(x86_make_reg(file_REG32, reg_SP), + p->stack_offset + (arg - 6) * 8); /* ??? */ + } + case X86_32: + return x86_make_disp(x86_make_reg(file_REG32, reg_SP), + p->stack_offset + arg * 4); /* ??? */ + default: + abort(); + } +} + +static void x86_init_func_common( struct x86_function *p ) +{ + util_cpu_detect(); + p->caps = 0; + if(util_cpu_caps.has_mmx) + p->caps |= X86_MMX; + if(util_cpu_caps.has_mmx2) + p->caps |= X86_MMX2; + if(util_cpu_caps.has_sse) + p->caps |= X86_SSE; + if(util_cpu_caps.has_sse2) + p->caps |= X86_SSE2; + if(util_cpu_caps.has_sse3) + p->caps |= X86_SSE3; + if(util_cpu_caps.has_sse4_1) + p->caps |= X86_SSE4_1; + p->csr = p->store; + DUMP_START(); +} + +void x86_init_func( struct x86_function *p ) +{ + p->size = 0; + p->store = NULL; + x86_init_func_common(p); +} + +void x86_init_func_size( struct x86_function *p, unsigned code_size ) +{ + p->size = code_size; + p->store = rtasm_exec_malloc(code_size); + if (p->store == NULL) { + p->store = p->error_overflow; + } + x86_init_func_common(p); +} + +void x86_release_func( struct x86_function *p ) +{ + if (p->store && p->store != p->error_overflow) + rtasm_exec_free(p->store); + + p->store = NULL; + p->csr = NULL; + p->size = 0; +} + + +static INLINE x86_func +voidptr_to_x86_func(void *v) +{ + union { + void *v; + x86_func f; + } u; + assert(sizeof(u.v) == sizeof(u.f)); + u.v = v; + return u.f; +} + + +x86_func x86_get_func( struct x86_function *p ) +{ + DUMP_END(); + if (DISASSEM && p->store) + debug_printf("disassemble %p %p\n", p->store, p->csr); + + if (p->store == p->error_overflow) + return voidptr_to_x86_func(NULL); + else + return voidptr_to_x86_func(p->store); +} + +#else + +void x86sse_dummy( void ); + +void x86sse_dummy( void ) +{ +} + +#endif diff --git a/src/gallium/auxiliary/rtasm/rtasm_x86sse.h b/src/gallium/auxiliary/rtasm/rtasm_x86sse.h new file mode 100644 index 0000000..2b9678b --- /dev/null +++ b/src/gallium/auxiliary/rtasm/rtasm_x86sse.h @@ -0,0 +1,414 @@ +/************************************************************************** + * + * Copyright (C) 1999-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. + * + **************************************************************************/ + +#ifndef _RTASM_X86SSE_H_ +#define _RTASM_X86SSE_H_ + +#include "pipe/p_compiler.h" +#include "pipe/p_config.h" + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) + +/* It is up to the caller to ensure that instructions issued are + * suitable for the host cpu. There are no checks made in this module + * for mmx/sse/sse2 support on the cpu. + */ +struct x86_reg { + unsigned file:2; + unsigned idx:4; + unsigned mod:2; /* mod_REG if this is just a register */ + int disp:24; /* only +/- 23bits of offset - should be enough... */ +}; + +#define X86_MMX 1 +#define X86_MMX2 2 +#define X86_SSE 4 +#define X86_SSE2 8 +#define X86_SSE3 0x10 +#define X86_SSE4_1 0x20 + +struct x86_function { + unsigned caps; + unsigned size; + unsigned char *store; + unsigned char *csr; + + unsigned stack_offset:16; + unsigned need_emms:8; + int x87_stack:8; + + unsigned char error_overflow[4]; +}; + +enum x86_reg_file { + file_REG32, + file_MMX, + file_XMM, + file_x87 +}; + +/* Values for mod field of modr/m byte + */ +enum x86_reg_mod { + mod_INDIRECT, + mod_DISP8, + mod_DISP32, + mod_REG +}; + +enum x86_reg_name { + reg_AX, + reg_CX, + reg_DX, + reg_BX, + reg_SP, + reg_BP, + reg_SI, + reg_DI, + reg_R8, + reg_R9, + reg_R10, + reg_R11, + reg_R12, + reg_R13, + reg_R14, + reg_R15 +}; + + +enum x86_cc { + cc_O, /* overflow */ + cc_NO, /* not overflow */ + cc_NAE, /* not above or equal / carry */ + cc_AE, /* above or equal / not carry */ + cc_E, /* equal / zero */ + cc_NE /* not equal / not zero */ +}; + +enum sse_cc { + cc_Equal, + cc_LessThan, + cc_LessThanEqual, + cc_Unordered, + cc_NotEqual, + cc_NotLessThan, + cc_NotLessThanEqual, + cc_Ordered +}; + +#define cc_Z cc_E +#define cc_NZ cc_NE + + +/** generic pointer to function */ +typedef void (*x86_func)(void); + + +/* Begin/end/retrieve function creation: + */ + +enum x86_target +{ + X86_32, + X86_64_STD_ABI, + X86_64_WIN64_ABI +}; + +/* make this read a member of x86_function if target != host is desired */ +static INLINE enum x86_target x86_target( struct x86_function* p ) +{ +#ifdef PIPE_ARCH_X86 + return X86_32; +#elif defined(_WIN64) + return X86_64_WIN64_ABI; +#elif defined(PIPE_ARCH_X86_64) + return X86_64_STD_ABI; +#endif +} + +static INLINE unsigned x86_target_caps( struct x86_function* p ) +{ + return p->caps; +} + +void x86_init_func( struct x86_function *p ); +void x86_init_func_size( struct x86_function *p, unsigned code_size ); +void x86_release_func( struct x86_function *p ); +x86_func x86_get_func( struct x86_function *p ); + +/* Debugging: + */ +void x86_print_reg( struct x86_reg reg ); + + +/* Create and manipulate registers and regmem values: + */ +struct x86_reg x86_make_reg( enum x86_reg_file file, + enum x86_reg_name idx ); + +struct x86_reg x86_make_disp( struct x86_reg reg, + int disp ); + +struct x86_reg x86_deref( struct x86_reg reg ); + +struct x86_reg x86_get_base_reg( struct x86_reg reg ); + + +/* Labels, jumps and fixup: + */ +int x86_get_label( struct x86_function *p ); + +void x64_rexw(struct x86_function *p); + +void x86_jcc( struct x86_function *p, + enum x86_cc cc, + int label ); + +int x86_jcc_forward( struct x86_function *p, + enum x86_cc cc ); + +int x86_jmp_forward( struct x86_function *p); + +int x86_call_forward( struct x86_function *p); + +void x86_fixup_fwd_jump( struct x86_function *p, + int fixup ); + +void x86_jmp( struct x86_function *p, int label ); + +/* void x86_call( struct x86_function *p, void (*label)() ); */ +void x86_call( struct x86_function *p, struct x86_reg reg); + +void x86_mov_reg_imm( struct x86_function *p, struct x86_reg dst, int imm ); +void x86_add_imm( struct x86_function *p, struct x86_reg dst, int imm ); +void x86_or_imm( struct x86_function *p, struct x86_reg dst, int imm ); +void x86_and_imm( struct x86_function *p, struct x86_reg dst, int imm ); +void x86_sub_imm( struct x86_function *p, struct x86_reg dst, int imm ); +void x86_xor_imm( struct x86_function *p, struct x86_reg dst, int imm ); +void x86_cmp_imm( struct x86_function *p, struct x86_reg dst, int imm ); + + +/* Macro for sse_shufps() and sse2_pshufd(): + */ +#define SHUF(_x,_y,_z,_w) (((_x)<<0) | ((_y)<<2) | ((_z)<<4) | ((_w)<<6)) +#define SHUF_NOOP RSW(0,1,2,3) +#define GET_SHUF(swz, idx) (((swz) >> ((idx)*2)) & 0x3) + +void mmx_emms( struct x86_function *p ); +void mmx_movd( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void mmx_movq( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void mmx_packssdw( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void mmx_packuswb( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); + +void sse2_movd( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_movq( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_movdqu( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_movdqa( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_movsd( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_movupd( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_movapd( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); + +void sse2_cvtps2dq( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_cvttps2dq( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_cvtdq2ps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_cvtsd2ss( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_cvtpd2ps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); + +void sse2_movd( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_packssdw( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_packsswb( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_packuswb( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_pshufd( struct x86_function *p, struct x86_reg dest, struct x86_reg arg0, + unsigned char shuf ); +void sse2_pshuflw( struct x86_function *p, struct x86_reg dest, struct x86_reg arg0, + unsigned char shuf ); +void sse2_pshufhw( struct x86_function *p, struct x86_reg dest, struct x86_reg arg0, + unsigned char shuf ); +void sse2_rcpps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_rcpss( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); + +void sse2_punpcklbw( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_punpcklwd( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_punpckldq( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse2_punpcklqdq( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); + +void sse2_psllw_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ); +void sse2_pslld_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ); +void sse2_psllq_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ); + +void sse2_psrlw_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ); +void sse2_psrld_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ); +void sse2_psrlq_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ); + +void sse2_psraw_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ); +void sse2_psrad_imm( struct x86_function *p, struct x86_reg dst, unsigned imm ); + +void sse2_por( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); + +void sse2_pshuflw( struct x86_function *p, struct x86_reg dst, struct x86_reg src, uint8_t imm ); +void sse2_pshufhw( struct x86_function *p, struct x86_reg dst, struct x86_reg src, uint8_t imm ); +void sse2_pshufd( struct x86_function *p, struct x86_reg dst, struct x86_reg src, uint8_t imm ); + +void sse_prefetchnta( struct x86_function *p, struct x86_reg ptr); +void sse_prefetch0( struct x86_function *p, struct x86_reg ptr); +void sse_prefetch1( struct x86_function *p, struct x86_reg ptr); + +void sse_movntps( struct x86_function *p, struct x86_reg dst, struct x86_reg src); + +void sse_addps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_addss( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_cvtps2pi( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_divss( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_andnps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_andps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_cmpps( struct x86_function *p, struct x86_reg dst, struct x86_reg src, + enum sse_cc cc ); +void sse_maxps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_maxss( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_minps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_movaps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_movhlps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_movhps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_movlhps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_movlps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_movss( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_movups( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_mulps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_mulss( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_orps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_xorps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_subps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_rsqrtps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_rsqrtss( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_shufps( struct x86_function *p, struct x86_reg dest, struct x86_reg arg0, + unsigned char shuf ); +void sse_unpckhps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_unpcklps( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void sse_pmovmskb( struct x86_function *p, struct x86_reg dest, struct x86_reg src ); +void sse_movmskps( struct x86_function *p, struct x86_reg dst, struct x86_reg src); + +void x86_add( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_and( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_cmp( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_dec( struct x86_function *p, struct x86_reg reg ); +void x86_inc( struct x86_function *p, struct x86_reg reg ); +void x86_lea( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_mov( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x64_mov64( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_mov8( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_mov16( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_movzx8(struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_movzx16(struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_mov_imm(struct x86_function *p, struct x86_reg dst, int imm ); +void x86_mov8_imm(struct x86_function *p, struct x86_reg dst, uint8_t imm ); +void x86_mov16_imm(struct x86_function *p, struct x86_reg dst, uint16_t imm ); +void x86_mul( struct x86_function *p, struct x86_reg src ); +void x86_imul( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_or( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_pop( struct x86_function *p, struct x86_reg reg ); +void x86_push( struct x86_function *p, struct x86_reg reg ); +void x86_push_imm32( struct x86_function *p, int imm ); +void x86_ret( struct x86_function *p ); +void x86_retw( struct x86_function *p, unsigned short imm ); +void x86_sub( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_test( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_xor( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_sahf( struct x86_function *p ); +void x86_div( struct x86_function *p, struct x86_reg src ); +void x86_bswap( struct x86_function *p, struct x86_reg src ); +void x86_shr_imm( struct x86_function *p, struct x86_reg reg, unsigned imm ); +void x86_sar_imm( struct x86_function *p, struct x86_reg reg, unsigned imm ); +void x86_shl_imm( struct x86_function *p, struct x86_reg reg, unsigned imm ); + +void x86_cdecl_caller_push_regs( struct x86_function *p ); +void x86_cdecl_caller_pop_regs( struct x86_function *p ); + +void x87_assert_stack_empty( struct x86_function *p ); + +void x87_f2xm1( struct x86_function *p ); +void x87_fabs( struct x86_function *p ); +void x87_fadd( struct x86_function *p, struct x86_reg dst, struct x86_reg arg ); +void x87_faddp( struct x86_function *p, struct x86_reg dst ); +void x87_fchs( struct x86_function *p ); +void x87_fclex( struct x86_function *p ); +void x87_fcmovb( struct x86_function *p, struct x86_reg src ); +void x87_fcmovbe( struct x86_function *p, struct x86_reg src ); +void x87_fcmove( struct x86_function *p, struct x86_reg src ); +void x87_fcmovnb( struct x86_function *p, struct x86_reg src ); +void x87_fcmovnbe( struct x86_function *p, struct x86_reg src ); +void x87_fcmovne( struct x86_function *p, struct x86_reg src ); +void x87_fcom( struct x86_function *p, struct x86_reg dst ); +void x87_fcomi( struct x86_function *p, struct x86_reg dst ); +void x87_fcomip( struct x86_function *p, struct x86_reg dst ); +void x87_fcomp( struct x86_function *p, struct x86_reg dst ); +void x87_fcos( struct x86_function *p ); +void x87_fdiv( struct x86_function *p, struct x86_reg dst, struct x86_reg arg ); +void x87_fdivp( struct x86_function *p, struct x86_reg dst ); +void x87_fdivr( struct x86_function *p, struct x86_reg dst, struct x86_reg arg ); +void x87_fdivrp( struct x86_function *p, struct x86_reg dst ); +void x87_fild( struct x86_function *p, struct x86_reg arg ); +void x87_fist( struct x86_function *p, struct x86_reg dst ); +void x87_fistp( struct x86_function *p, struct x86_reg dst ); +void x87_fld( struct x86_function *p, struct x86_reg arg ); +void x87_fld1( struct x86_function *p ); +void x87_fldcw( struct x86_function *p, struct x86_reg arg ); +void x87_fldl2e( struct x86_function *p ); +void x87_fldln2( struct x86_function *p ); +void x87_fldz( struct x86_function *p ); +void x87_fmul( struct x86_function *p, struct x86_reg dst, struct x86_reg arg ); +void x87_fmulp( struct x86_function *p, struct x86_reg dst ); +void x87_fnclex( struct x86_function *p ); +void x87_fprndint( struct x86_function *p ); +void x87_fpop( struct x86_function *p ); +void x87_fscale( struct x86_function *p ); +void x87_fsin( struct x86_function *p ); +void x87_fsincos( struct x86_function *p ); +void x87_fsqrt( struct x86_function *p ); +void x87_fst( struct x86_function *p, struct x86_reg dst ); +void x87_fstp( struct x86_function *p, struct x86_reg dst ); +void x87_fsub( struct x86_function *p, struct x86_reg dst, struct x86_reg arg ); +void x87_fsubp( struct x86_function *p, struct x86_reg dst ); +void x87_fsubr( struct x86_function *p, struct x86_reg dst, struct x86_reg arg ); +void x87_fsubrp( struct x86_function *p, struct x86_reg dst ); +void x87_ftst( struct x86_function *p ); +void x87_fxch( struct x86_function *p, struct x86_reg dst ); +void x87_fxtract( struct x86_function *p ); +void x87_fyl2x( struct x86_function *p ); +void x87_fyl2xp1( struct x86_function *p ); +void x87_fwait( struct x86_function *p ); +void x87_fnstcw( struct x86_function *p, struct x86_reg dst ); +void x87_fnstsw( struct x86_function *p, struct x86_reg dst ); +void x87_fucompp( struct x86_function *p ); +void x87_fucomp( struct x86_function *p, struct x86_reg arg ); +void x87_fucom( struct x86_function *p, struct x86_reg arg ); + + + +/* Retrieve a reference to one of the function arguments, taking into + * account any push/pop activity. Note - doesn't track explicit + * manipulation of ESP by other instructions. + */ +struct x86_reg x86_fn_arg( struct x86_function *p, unsigned arg ); + +#endif +#endif diff --git a/src/gallium/auxiliary/target-helpers/inline_debug_helper.h b/src/gallium/auxiliary/target-helpers/inline_debug_helper.h new file mode 100644 index 0000000..0433da6 --- /dev/null +++ b/src/gallium/auxiliary/target-helpers/inline_debug_helper.h @@ -0,0 +1,44 @@ + +#ifndef INLINE_DEBUG_HELPER_H +#define INLINE_DEBUG_HELPER_H + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" + + +/* Helper function to wrap a screen with + * one or more debug driver: rbug, trace. + */ + +#ifdef GALLIUM_TRACE +#include "trace/tr_public.h" +#endif + +#ifdef GALLIUM_RBUG +#include "rbug/rbug_public.h" +#endif + +#ifdef GALLIUM_GALAHAD +#include "galahad/glhd_public.h" +#endif + +static INLINE struct pipe_screen * +debug_screen_wrap(struct pipe_screen *screen) +{ + +#if defined(GALLIUM_RBUG) + screen = rbug_screen_create(screen); +#endif + +#if defined(GALLIUM_TRACE) + screen = trace_screen_create(screen); +#endif + +#if defined(GALLIUM_GALAHAD) + screen = galahad_screen_create(screen); +#endif + + return screen; +} + +#endif diff --git a/src/gallium/auxiliary/target-helpers/inline_sw_helper.h b/src/gallium/auxiliary/target-helpers/inline_sw_helper.h new file mode 100644 index 0000000..34bfa52 --- /dev/null +++ b/src/gallium/auxiliary/target-helpers/inline_sw_helper.h @@ -0,0 +1,72 @@ + +#ifndef INLINE_SW_HELPER_H +#define INLINE_SW_HELPER_H + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" +#include "state_tracker/sw_winsys.h" + + +/* Helper function to choose and instantiate one of the software rasterizers: + * cell, llvmpipe, softpipe. + */ + +#ifdef GALLIUM_SOFTPIPE +#include "softpipe/sp_public.h" +#endif + +#ifdef GALLIUM_LLVMPIPE +#include "llvmpipe/lp_public.h" +#endif + +#ifdef GALLIUM_CELL +#include "cell/ppu/cell_public.h" +#endif + + +static INLINE struct pipe_screen * +sw_screen_create_named(struct sw_winsys *winsys, const char *driver) +{ + struct pipe_screen *screen = NULL; + +#if defined(GALLIUM_CELL) + if (screen == NULL && strcmp(driver, "cell") == 0) + screen = cell_create_screen(winsys); +#endif + +#if defined(GALLIUM_LLVMPIPE) + if (screen == NULL && strcmp(driver, "llvmpipe") == 0) + screen = llvmpipe_create_screen(winsys); +#endif + +#if defined(GALLIUM_SOFTPIPE) + if (screen == NULL) + screen = softpipe_create_screen(winsys); +#endif + + return screen; +} + + +static INLINE struct pipe_screen * +sw_screen_create(struct sw_winsys *winsys) +{ + const char *default_driver; + const char *driver; + +#if defined(GALLIUM_CELL) + default_driver = "cell"; +#elif defined(GALLIUM_LLVMPIPE) + default_driver = "llvmpipe"; +#elif defined(GALLIUM_SOFTPIPE) + default_driver = "softpipe"; +#else + default_driver = ""; +#endif + + driver = debug_get_option("GALLIUM_DRIVER", default_driver); + return sw_screen_create_named(winsys, driver); +} + + +#endif diff --git a/src/gallium/auxiliary/target-helpers/inline_wrapper_sw_helper.h b/src/gallium/auxiliary/target-helpers/inline_wrapper_sw_helper.h new file mode 100644 index 0000000..e4effa7 --- /dev/null +++ b/src/gallium/auxiliary/target-helpers/inline_wrapper_sw_helper.h @@ -0,0 +1,40 @@ + +#ifndef INLINE_WRAPPER_SW_HELPER_H +#define INLINE_WRAPPER_SW_HELPER_H + +#include "target-helpers/inline_sw_helper.h" +#include "sw/wrapper/wrapper_sw_winsys.h" + +/** + * Try to wrap a hw screen with a software screen. + * On failure will return given screen. + */ +static INLINE struct pipe_screen * +sw_screen_wrap(struct pipe_screen *screen) +{ + struct sw_winsys *sws; + struct pipe_screen *sw_screen = NULL; + const char *driver; + + driver = debug_get_option("GALLIUM_DRIVER", "native"); + if (strcmp(driver, "native") == 0) + return screen; + + sws = wrapper_sw_winsys_wrap_pipe_screen(screen); + if (!sws) + goto err; + + sw_screen = sw_screen_create_named(sws, driver); + + if (!sw_screen) + goto err_winsys; + + return sw_screen; + +err_winsys: + return wrapper_sw_winsys_dewrap_pipe_screen(sws); +err: + return screen; +} + +#endif diff --git a/src/gallium/auxiliary/tgsi/tgsi_build.c b/src/gallium/auxiliary/tgsi/tgsi_build.c new file mode 100644 index 0000000..16a205f --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_build.c @@ -0,0 +1,1137 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_debug.h" +#include "pipe/p_shader_tokens.h" +#include "tgsi_build.h" +#include "tgsi_parse.h" + + +/* + * header + */ + +struct tgsi_header +tgsi_build_header( void ) +{ + struct tgsi_header header; + + header.HeaderSize = 1; + header.BodySize = 0; + + return header; +} + +static void +header_headersize_grow( struct tgsi_header *header ) +{ + assert( header->HeaderSize < 0xFF ); + assert( header->BodySize == 0 ); + + header->HeaderSize++; +} + +static void +header_bodysize_grow( struct tgsi_header *header ) +{ + assert( header->BodySize < 0xFFFFFF ); + + header->BodySize++; +} + +struct tgsi_processor +tgsi_build_processor( + unsigned type, + struct tgsi_header *header ) +{ + struct tgsi_processor processor; + + processor.Processor = type; + processor.Padding = 0; + + header_headersize_grow( header ); + + return processor; +} + +/* + * declaration + */ + +static void +declaration_grow( + struct tgsi_declaration *declaration, + struct tgsi_header *header ) +{ + assert( declaration->NrTokens < 0xFF ); + + declaration->NrTokens++; + + header_bodysize_grow( header ); +} + +static struct tgsi_declaration +tgsi_default_declaration( void ) +{ + struct tgsi_declaration declaration; + + declaration.Type = TGSI_TOKEN_TYPE_DECLARATION; + declaration.NrTokens = 1; + declaration.File = TGSI_FILE_NULL; + declaration.UsageMask = TGSI_WRITEMASK_XYZW; + declaration.Interpolate = TGSI_INTERPOLATE_CONSTANT; + declaration.Dimension = 0; + declaration.Semantic = 0; + declaration.Centroid = 0; + declaration.Invariant = 0; + declaration.CylindricalWrap = 0; + + return declaration; +} + +static struct tgsi_declaration +tgsi_build_declaration( + unsigned file, + unsigned usage_mask, + unsigned interpolate, + unsigned dimension, + unsigned semantic, + unsigned centroid, + unsigned invariant, + unsigned cylindrical_wrap, + struct tgsi_header *header ) +{ + struct tgsi_declaration declaration; + + assert( file < TGSI_FILE_COUNT ); + assert( interpolate < TGSI_INTERPOLATE_COUNT ); + + declaration = tgsi_default_declaration(); + declaration.File = file; + declaration.UsageMask = usage_mask; + declaration.Interpolate = interpolate; + declaration.Dimension = dimension; + declaration.Semantic = semantic; + declaration.Centroid = centroid; + declaration.Invariant = invariant; + declaration.CylindricalWrap = cylindrical_wrap; + + header_bodysize_grow( header ); + + return declaration; +} + +static struct tgsi_declaration_range +tgsi_default_declaration_range( void ) +{ + struct tgsi_declaration_range dr; + + dr.First = 0; + dr.Last = 0; + + return dr; +} + +static struct tgsi_declaration_range +tgsi_build_declaration_range( + unsigned first, + unsigned last, + struct tgsi_declaration *declaration, + struct tgsi_header *header ) +{ + struct tgsi_declaration_range declaration_range; + + assert( last >= first ); + assert( last <= 0xFFFF ); + + declaration_range.First = first; + declaration_range.Last = last; + + declaration_grow( declaration, header ); + + return declaration_range; +} + +static struct tgsi_declaration_dimension +tgsi_build_declaration_dimension(unsigned index_2d, + struct tgsi_declaration *declaration, + struct tgsi_header *header) +{ + struct tgsi_declaration_dimension dd; + + assert(index_2d <= 0xFFFF); + + dd.Index2D = index_2d; + dd.Padding = 0; + + declaration_grow(declaration, header); + + return dd; +} + +static struct tgsi_declaration_semantic +tgsi_default_declaration_semantic( void ) +{ + struct tgsi_declaration_semantic ds; + + ds.Name = TGSI_SEMANTIC_POSITION; + ds.Index = 0; + ds.Padding = 0; + + return ds; +} + +static struct tgsi_declaration_semantic +tgsi_build_declaration_semantic( + unsigned semantic_name, + unsigned semantic_index, + struct tgsi_declaration *declaration, + struct tgsi_header *header ) +{ + struct tgsi_declaration_semantic ds; + + assert( semantic_name <= TGSI_SEMANTIC_COUNT ); + assert( semantic_index <= 0xFFFF ); + + ds.Name = semantic_name; + ds.Index = semantic_index; + ds.Padding = 0; + + declaration_grow( declaration, header ); + + return ds; +} + +struct tgsi_full_declaration +tgsi_default_full_declaration( void ) +{ + struct tgsi_full_declaration full_declaration; + + full_declaration.Declaration = tgsi_default_declaration(); + full_declaration.Range = tgsi_default_declaration_range(); + full_declaration.Semantic = tgsi_default_declaration_semantic(); + full_declaration.ImmediateData.u = NULL; + + return full_declaration; +} + +unsigned +tgsi_build_full_declaration( + const struct tgsi_full_declaration *full_decl, + struct tgsi_token *tokens, + struct tgsi_header *header, + unsigned maxsize ) +{ + unsigned size = 0; + struct tgsi_declaration *declaration; + struct tgsi_declaration_range *dr; + + if( maxsize <= size ) + return 0; + declaration = (struct tgsi_declaration *) &tokens[size]; + size++; + + *declaration = tgsi_build_declaration( + full_decl->Declaration.File, + full_decl->Declaration.UsageMask, + full_decl->Declaration.Interpolate, + full_decl->Declaration.Dimension, + full_decl->Declaration.Semantic, + full_decl->Declaration.Centroid, + full_decl->Declaration.Invariant, + full_decl->Declaration.CylindricalWrap, + header ); + + if (maxsize <= size) + return 0; + dr = (struct tgsi_declaration_range *) &tokens[size]; + size++; + + *dr = tgsi_build_declaration_range( + full_decl->Range.First, + full_decl->Range.Last, + declaration, + header ); + + if (full_decl->Declaration.Dimension) { + struct tgsi_declaration_dimension *dd; + + if (maxsize <= size) { + return 0; + } + dd = (struct tgsi_declaration_dimension *)&tokens[size]; + size++; + + *dd = tgsi_build_declaration_dimension(full_decl->Dim.Index2D, + declaration, + header); + } + + if( full_decl->Declaration.Semantic ) { + struct tgsi_declaration_semantic *ds; + + if( maxsize <= size ) + return 0; + ds = (struct tgsi_declaration_semantic *) &tokens[size]; + size++; + + *ds = tgsi_build_declaration_semantic( + full_decl->Semantic.Name, + full_decl->Semantic.Index, + declaration, + header ); + } + + if (full_decl->Declaration.File == TGSI_FILE_IMMEDIATE_ARRAY) { + unsigned i, j; + union tgsi_immediate_data *data; + + for (i = 0; i <= dr->Last; ++i) { + for (j = 0; j < 4; ++j) { + unsigned idx = i*4 + j; + if (maxsize <= size) + return 0; + data = (union tgsi_immediate_data *) &tokens[size]; + ++size; + + *data = full_decl->ImmediateData.u[idx]; + declaration_grow( declaration, header ); + } + } + } + + return size; +} + +/* + * immediate + */ + +static struct tgsi_immediate +tgsi_default_immediate( void ) +{ + struct tgsi_immediate immediate; + + immediate.Type = TGSI_TOKEN_TYPE_IMMEDIATE; + immediate.NrTokens = 1; + immediate.DataType = TGSI_IMM_FLOAT32; + immediate.Padding = 0; + + return immediate; +} + +static struct tgsi_immediate +tgsi_build_immediate( + struct tgsi_header *header ) +{ + struct tgsi_immediate immediate; + + immediate = tgsi_default_immediate(); + + header_bodysize_grow( header ); + + return immediate; +} + +struct tgsi_full_immediate +tgsi_default_full_immediate( void ) +{ + struct tgsi_full_immediate fullimm; + + fullimm.Immediate = tgsi_default_immediate(); + fullimm.u[0].Float = 0.0f; + fullimm.u[1].Float = 0.0f; + fullimm.u[2].Float = 0.0f; + fullimm.u[3].Float = 0.0f; + + return fullimm; +} + +static void +immediate_grow( + struct tgsi_immediate *immediate, + struct tgsi_header *header ) +{ + assert( immediate->NrTokens < 0xFF ); + + immediate->NrTokens++; + + header_bodysize_grow( header ); +} + +static union tgsi_immediate_data +tgsi_build_immediate_float32( + float value, + struct tgsi_immediate *immediate, + struct tgsi_header *header ) +{ + union tgsi_immediate_data immediate_data; + + immediate_data.Float = value; + + immediate_grow( immediate, header ); + + return immediate_data; +} + +unsigned +tgsi_build_full_immediate( + const struct tgsi_full_immediate *full_imm, + struct tgsi_token *tokens, + struct tgsi_header *header, + unsigned maxsize ) +{ + unsigned size = 0, i; + struct tgsi_immediate *immediate; + + if( maxsize <= size ) + return 0; + immediate = (struct tgsi_immediate *) &tokens[size]; + size++; + + *immediate = tgsi_build_immediate( header ); + + assert( full_imm->Immediate.NrTokens <= 4 + 1 ); + + for( i = 0; i < full_imm->Immediate.NrTokens - 1; i++ ) { + union tgsi_immediate_data *data; + + if( maxsize <= size ) + return 0; + data = (union tgsi_immediate_data *) &tokens[size]; + size++; + + *data = tgsi_build_immediate_float32( + full_imm->u[i].Float, + immediate, + header ); + } + + return size; +} + +/* + * instruction + */ + +struct tgsi_instruction +tgsi_default_instruction( void ) +{ + struct tgsi_instruction instruction; + + instruction.Type = TGSI_TOKEN_TYPE_INSTRUCTION; + instruction.NrTokens = 0; + instruction.Opcode = TGSI_OPCODE_MOV; + instruction.Saturate = TGSI_SAT_NONE; + instruction.Predicate = 0; + instruction.NumDstRegs = 1; + instruction.NumSrcRegs = 1; + instruction.Label = 0; + instruction.Texture = 0; + instruction.Padding = 0; + + return instruction; +} + +static struct tgsi_instruction +tgsi_build_instruction(unsigned opcode, + unsigned saturate, + unsigned predicate, + unsigned num_dst_regs, + unsigned num_src_regs, + struct tgsi_header *header) +{ + struct tgsi_instruction instruction; + + assert (opcode <= TGSI_OPCODE_LAST); + assert (saturate <= TGSI_SAT_MINUS_PLUS_ONE); + assert (num_dst_regs <= 3); + assert (num_src_regs <= 15); + + instruction = tgsi_default_instruction(); + instruction.Opcode = opcode; + instruction.Saturate = saturate; + instruction.Predicate = predicate; + instruction.NumDstRegs = num_dst_regs; + instruction.NumSrcRegs = num_src_regs; + + header_bodysize_grow( header ); + + return instruction; +} + +static void +instruction_grow( + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + assert (instruction->NrTokens < 0xFF); + + instruction->NrTokens++; + + header_bodysize_grow( header ); +} + +struct tgsi_instruction_predicate +tgsi_default_instruction_predicate(void) +{ + struct tgsi_instruction_predicate instruction_predicate; + + instruction_predicate.SwizzleX = TGSI_SWIZZLE_X; + instruction_predicate.SwizzleY = TGSI_SWIZZLE_Y; + instruction_predicate.SwizzleZ = TGSI_SWIZZLE_Z; + instruction_predicate.SwizzleW = TGSI_SWIZZLE_W; + instruction_predicate.Negate = 0; + instruction_predicate.Index = 0; + instruction_predicate.Padding = 0; + + return instruction_predicate; +} + +static struct tgsi_instruction_predicate +tgsi_build_instruction_predicate(int index, + unsigned negate, + unsigned swizzleX, + unsigned swizzleY, + unsigned swizzleZ, + unsigned swizzleW, + struct tgsi_instruction *instruction, + struct tgsi_header *header) +{ + struct tgsi_instruction_predicate instruction_predicate; + + instruction_predicate = tgsi_default_instruction_predicate(); + instruction_predicate.SwizzleX = swizzleX; + instruction_predicate.SwizzleY = swizzleY; + instruction_predicate.SwizzleZ = swizzleZ; + instruction_predicate.SwizzleW = swizzleW; + instruction_predicate.Negate = negate; + instruction_predicate.Index = index; + + instruction_grow(instruction, header); + + return instruction_predicate; +} + +static struct tgsi_instruction_label +tgsi_default_instruction_label( void ) +{ + struct tgsi_instruction_label instruction_label; + + instruction_label.Label = 0; + instruction_label.Padding = 0; + + return instruction_label; +} + +static struct tgsi_instruction_label +tgsi_build_instruction_label( + unsigned label, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_instruction_label instruction_label; + + instruction_label.Label = label; + instruction_label.Padding = 0; + instruction->Label = 1; + + instruction_grow( instruction, header ); + + return instruction_label; +} + +static struct tgsi_instruction_texture +tgsi_default_instruction_texture( void ) +{ + struct tgsi_instruction_texture instruction_texture; + + instruction_texture.Texture = TGSI_TEXTURE_UNKNOWN; + instruction_texture.Padding = 0; + + return instruction_texture; +} + +static struct tgsi_instruction_texture +tgsi_build_instruction_texture( + unsigned texture, + struct tgsi_token *prev_token, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_instruction_texture instruction_texture; + + instruction_texture.Texture = texture; + instruction_texture.Padding = 0; + instruction->Texture = 1; + + instruction_grow( instruction, header ); + + return instruction_texture; +} + +static struct tgsi_src_register +tgsi_default_src_register( void ) +{ + struct tgsi_src_register src_register; + + src_register.File = TGSI_FILE_NULL; + src_register.SwizzleX = TGSI_SWIZZLE_X; + src_register.SwizzleY = TGSI_SWIZZLE_Y; + src_register.SwizzleZ = TGSI_SWIZZLE_Z; + src_register.SwizzleW = TGSI_SWIZZLE_W; + src_register.Negate = 0; + src_register.Absolute = 0; + src_register.Indirect = 0; + src_register.Dimension = 0; + src_register.Index = 0; + + return src_register; +} + +static struct tgsi_src_register +tgsi_build_src_register( + unsigned file, + unsigned swizzle_x, + unsigned swizzle_y, + unsigned swizzle_z, + unsigned swizzle_w, + unsigned negate, + unsigned absolute, + unsigned indirect, + unsigned dimension, + int index, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_src_register src_register; + + assert( file < TGSI_FILE_COUNT ); + assert( swizzle_x <= TGSI_SWIZZLE_W ); + assert( swizzle_y <= TGSI_SWIZZLE_W ); + assert( swizzle_z <= TGSI_SWIZZLE_W ); + assert( swizzle_w <= TGSI_SWIZZLE_W ); + assert( negate <= 1 ); + assert( index >= -0x8000 && index <= 0x7FFF ); + + src_register.File = file; + src_register.SwizzleX = swizzle_x; + src_register.SwizzleY = swizzle_y; + src_register.SwizzleZ = swizzle_z; + src_register.SwizzleW = swizzle_w; + src_register.Negate = negate; + src_register.Absolute = absolute; + src_register.Indirect = indirect; + src_register.Dimension = dimension; + src_register.Index = index; + + instruction_grow( instruction, header ); + + return src_register; +} + +static struct tgsi_dimension +tgsi_default_dimension( void ) +{ + struct tgsi_dimension dimension; + + dimension.Indirect = 0; + dimension.Dimension = 0; + dimension.Padding = 0; + dimension.Index = 0; + + return dimension; +} + +static struct tgsi_full_src_register +tgsi_default_full_src_register( void ) +{ + struct tgsi_full_src_register full_src_register; + + full_src_register.Register = tgsi_default_src_register(); + full_src_register.Indirect = tgsi_default_src_register(); + full_src_register.Dimension = tgsi_default_dimension(); + full_src_register.DimIndirect = tgsi_default_src_register(); + + return full_src_register; +} + +static struct tgsi_dimension +tgsi_build_dimension( + unsigned indirect, + unsigned index, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_dimension dimension; + + dimension.Indirect = indirect; + dimension.Dimension = 0; + dimension.Padding = 0; + dimension.Index = index; + + instruction_grow( instruction, header ); + + return dimension; +} + +static struct tgsi_dst_register +tgsi_default_dst_register( void ) +{ + struct tgsi_dst_register dst_register; + + dst_register.File = TGSI_FILE_NULL; + dst_register.WriteMask = TGSI_WRITEMASK_XYZW; + dst_register.Indirect = 0; + dst_register.Dimension = 0; + dst_register.Index = 0; + dst_register.Padding = 0; + + return dst_register; +} + +static struct tgsi_dst_register +tgsi_build_dst_register( + unsigned file, + unsigned mask, + unsigned indirect, + unsigned dimension, + int index, + struct tgsi_instruction *instruction, + struct tgsi_header *header ) +{ + struct tgsi_dst_register dst_register; + + assert( file < TGSI_FILE_COUNT ); + assert( mask <= TGSI_WRITEMASK_XYZW ); + assert( index >= -32768 && index <= 32767 ); + + dst_register.File = file; + dst_register.WriteMask = mask; + dst_register.Indirect = indirect; + dst_register.Dimension = dimension; + dst_register.Index = index; + dst_register.Padding = 0; + + instruction_grow( instruction, header ); + + return dst_register; +} + +static struct tgsi_full_dst_register +tgsi_default_full_dst_register( void ) +{ + struct tgsi_full_dst_register full_dst_register; + + full_dst_register.Register = tgsi_default_dst_register(); + full_dst_register.Indirect = tgsi_default_src_register(); + full_dst_register.Dimension = tgsi_default_dimension(); + full_dst_register.DimIndirect = tgsi_default_src_register(); + + return full_dst_register; +} + +struct tgsi_full_instruction +tgsi_default_full_instruction( void ) +{ + struct tgsi_full_instruction full_instruction; + unsigned i; + + full_instruction.Instruction = tgsi_default_instruction(); + full_instruction.Predicate = tgsi_default_instruction_predicate(); + full_instruction.Label = tgsi_default_instruction_label(); + full_instruction.Texture = tgsi_default_instruction_texture(); + for( i = 0; i < TGSI_FULL_MAX_DST_REGISTERS; i++ ) { + full_instruction.Dst[i] = tgsi_default_full_dst_register(); + } + for( i = 0; i < TGSI_FULL_MAX_SRC_REGISTERS; i++ ) { + full_instruction.Src[i] = tgsi_default_full_src_register(); + } + + return full_instruction; +} + +unsigned +tgsi_build_full_instruction( + const struct tgsi_full_instruction *full_inst, + struct tgsi_token *tokens, + struct tgsi_header *header, + unsigned maxsize ) +{ + unsigned size = 0; + unsigned i; + struct tgsi_instruction *instruction; + struct tgsi_token *prev_token; + + if( maxsize <= size ) + return 0; + instruction = (struct tgsi_instruction *) &tokens[size]; + size++; + + *instruction = tgsi_build_instruction(full_inst->Instruction.Opcode, + full_inst->Instruction.Saturate, + full_inst->Instruction.Predicate, + full_inst->Instruction.NumDstRegs, + full_inst->Instruction.NumSrcRegs, + header); + prev_token = (struct tgsi_token *) instruction; + + if (full_inst->Instruction.Predicate) { + struct tgsi_instruction_predicate *instruction_predicate; + + if (maxsize <= size) { + return 0; + } + instruction_predicate = (struct tgsi_instruction_predicate *)&tokens[size]; + size++; + + *instruction_predicate = + tgsi_build_instruction_predicate(full_inst->Predicate.Index, + full_inst->Predicate.Negate, + full_inst->Predicate.SwizzleX, + full_inst->Predicate.SwizzleY, + full_inst->Predicate.SwizzleZ, + full_inst->Predicate.SwizzleW, + instruction, + header); + } + + if (full_inst->Instruction.Label) { + struct tgsi_instruction_label *instruction_label; + + if( maxsize <= size ) + return 0; + instruction_label = + (struct tgsi_instruction_label *) &tokens[size]; + size++; + + *instruction_label = tgsi_build_instruction_label( + full_inst->Label.Label, + prev_token, + instruction, + header ); + prev_token = (struct tgsi_token *) instruction_label; + } + + if (full_inst->Instruction.Texture) { + struct tgsi_instruction_texture *instruction_texture; + + if( maxsize <= size ) + return 0; + instruction_texture = + (struct tgsi_instruction_texture *) &tokens[size]; + size++; + + *instruction_texture = tgsi_build_instruction_texture( + full_inst->Texture.Texture, + prev_token, + instruction, + header ); + prev_token = (struct tgsi_token *) instruction_texture; + } + + for( i = 0; i < full_inst->Instruction.NumDstRegs; i++ ) { + const struct tgsi_full_dst_register *reg = &full_inst->Dst[i]; + struct tgsi_dst_register *dst_register; + struct tgsi_token *prev_token; + + if( maxsize <= size ) + return 0; + dst_register = (struct tgsi_dst_register *) &tokens[size]; + size++; + + *dst_register = tgsi_build_dst_register( + reg->Register.File, + reg->Register.WriteMask, + reg->Register.Indirect, + reg->Register.Dimension, + reg->Register.Index, + instruction, + header ); + prev_token = (struct tgsi_token *) dst_register; + + if( reg->Register.Indirect ) { + struct tgsi_src_register *ind; + + if( maxsize <= size ) + return 0; + ind = (struct tgsi_src_register *) &tokens[size]; + size++; + + *ind = tgsi_build_src_register( + reg->Indirect.File, + reg->Indirect.SwizzleX, + reg->Indirect.SwizzleY, + reg->Indirect.SwizzleZ, + reg->Indirect.SwizzleW, + reg->Indirect.Negate, + reg->Indirect.Absolute, + reg->Indirect.Indirect, + reg->Indirect.Dimension, + reg->Indirect.Index, + instruction, + header ); + } + + if( reg->Register.Dimension ) { + struct tgsi_dimension *dim; + + assert( !reg->Dimension.Dimension ); + + if( maxsize <= size ) + return 0; + dim = (struct tgsi_dimension *) &tokens[size]; + size++; + + *dim = tgsi_build_dimension( + reg->Dimension.Indirect, + reg->Dimension.Index, + instruction, + header ); + + if( reg->Dimension.Indirect ) { + struct tgsi_src_register *ind; + + if( maxsize <= size ) + return 0; + ind = (struct tgsi_src_register *) &tokens[size]; + size++; + + *ind = tgsi_build_src_register( + reg->DimIndirect.File, + reg->DimIndirect.SwizzleX, + reg->DimIndirect.SwizzleY, + reg->DimIndirect.SwizzleZ, + reg->DimIndirect.SwizzleW, + reg->DimIndirect.Negate, + reg->DimIndirect.Absolute, + reg->DimIndirect.Indirect, + reg->DimIndirect.Dimension, + reg->DimIndirect.Index, + instruction, + header ); + } + } + } + + for( i = 0; i < full_inst->Instruction.NumSrcRegs; i++ ) { + const struct tgsi_full_src_register *reg = &full_inst->Src[i]; + struct tgsi_src_register *src_register; + struct tgsi_token *prev_token; + + if( maxsize <= size ) + return 0; + src_register = (struct tgsi_src_register *) &tokens[size]; + size++; + + *src_register = tgsi_build_src_register( + reg->Register.File, + reg->Register.SwizzleX, + reg->Register.SwizzleY, + reg->Register.SwizzleZ, + reg->Register.SwizzleW, + reg->Register.Negate, + reg->Register.Absolute, + reg->Register.Indirect, + reg->Register.Dimension, + reg->Register.Index, + instruction, + header ); + prev_token = (struct tgsi_token *) src_register; + + if( reg->Register.Indirect ) { + struct tgsi_src_register *ind; + + if( maxsize <= size ) + return 0; + ind = (struct tgsi_src_register *) &tokens[size]; + size++; + + *ind = tgsi_build_src_register( + reg->Indirect.File, + reg->Indirect.SwizzleX, + reg->Indirect.SwizzleY, + reg->Indirect.SwizzleZ, + reg->Indirect.SwizzleW, + reg->Indirect.Negate, + reg->Indirect.Absolute, + reg->Indirect.Indirect, + reg->Indirect.Dimension, + reg->Indirect.Index, + instruction, + header ); + } + + if( reg->Register.Dimension ) { + struct tgsi_dimension *dim; + + assert( !reg->Dimension.Dimension ); + + if( maxsize <= size ) + return 0; + dim = (struct tgsi_dimension *) &tokens[size]; + size++; + + *dim = tgsi_build_dimension( + reg->Dimension.Indirect, + reg->Dimension.Index, + instruction, + header ); + + if( reg->Dimension.Indirect ) { + struct tgsi_src_register *ind; + + if( maxsize <= size ) + return 0; + ind = (struct tgsi_src_register *) &tokens[size]; + size++; + + *ind = tgsi_build_src_register( + reg->DimIndirect.File, + reg->DimIndirect.SwizzleX, + reg->DimIndirect.SwizzleY, + reg->DimIndirect.SwizzleZ, + reg->DimIndirect.SwizzleW, + reg->DimIndirect.Negate, + reg->DimIndirect.Absolute, + reg->DimIndirect.Indirect, + reg->DimIndirect.Dimension, + reg->DimIndirect.Index, + instruction, + header ); + } + } + } + + return size; +} + +static struct tgsi_property +tgsi_default_property( void ) +{ + struct tgsi_property property; + + property.Type = TGSI_TOKEN_TYPE_PROPERTY; + property.NrTokens = 1; + property.PropertyName = TGSI_PROPERTY_GS_INPUT_PRIM; + property.Padding = 0; + + return property; +} + +static struct tgsi_property +tgsi_build_property(unsigned property_name, + struct tgsi_header *header) +{ + struct tgsi_property property; + + property = tgsi_default_property(); + property.PropertyName = property_name; + + header_bodysize_grow( header ); + + return property; +} + + +struct tgsi_full_property +tgsi_default_full_property( void ) +{ + struct tgsi_full_property full_property; + + full_property.Property = tgsi_default_property(); + memset(full_property.u, 0, + sizeof(struct tgsi_property_data) * 8); + + return full_property; +} + +static void +property_grow( + struct tgsi_property *property, + struct tgsi_header *header ) +{ + assert( property->NrTokens < 0xFF ); + + property->NrTokens++; + + header_bodysize_grow( header ); +} + +static struct tgsi_property_data +tgsi_build_property_data( + unsigned value, + struct tgsi_property *property, + struct tgsi_header *header ) +{ + struct tgsi_property_data property_data; + + property_data.Data = value; + + property_grow( property, header ); + + return property_data; +} + +unsigned +tgsi_build_full_property( + const struct tgsi_full_property *full_prop, + struct tgsi_token *tokens, + struct tgsi_header *header, + unsigned maxsize ) +{ + unsigned size = 0, i; + struct tgsi_property *property; + + if( maxsize <= size ) + return 0; + property = (struct tgsi_property *) &tokens[size]; + size++; + + *property = tgsi_build_property( + full_prop->Property.PropertyName, + header ); + + assert( full_prop->Property.NrTokens <= 8 + 1 ); + + for( i = 0; i < full_prop->Property.NrTokens - 1; i++ ) { + struct tgsi_property_data *data; + + if( maxsize <= size ) + return 0; + data = (struct tgsi_property_data *) &tokens[size]; + size++; + + *data = tgsi_build_property_data( + full_prop->u[i].Data, + property, + header ); + } + + return size; +} diff --git a/src/gallium/auxiliary/tgsi/tgsi_build.h b/src/gallium/auxiliary/tgsi/tgsi_build.h new file mode 100644 index 0000000..3f236a9 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_build.h @@ -0,0 +1,118 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef TGSI_BUILD_H +#define TGSI_BUILD_H + + +struct tgsi_token; + + +#if defined __cplusplus +extern "C" { +#endif + + +/* + * header + */ + +struct tgsi_header +tgsi_build_header( void ); + +struct tgsi_processor +tgsi_build_processor( + unsigned processor, + struct tgsi_header *header ); + +/* + * declaration + */ + +struct tgsi_full_declaration +tgsi_default_full_declaration( void ); + +unsigned +tgsi_build_full_declaration( + const struct tgsi_full_declaration *full_decl, + struct tgsi_token *tokens, + struct tgsi_header *header, + unsigned maxsize ); + +/* + * immediate + */ + +struct tgsi_full_immediate +tgsi_default_full_immediate( void ); + +unsigned +tgsi_build_full_immediate( + const struct tgsi_full_immediate *full_imm, + struct tgsi_token *tokens, + struct tgsi_header *header, + unsigned maxsize ); + +/* + * properties + */ + +struct tgsi_full_property +tgsi_default_full_property( void ); + +unsigned +tgsi_build_full_property( + const struct tgsi_full_property *full_prop, + struct tgsi_token *tokens, + struct tgsi_header *header, + unsigned maxsize ); + +/* + * instruction + */ + +struct tgsi_instruction +tgsi_default_instruction( void ); + +struct tgsi_full_instruction +tgsi_default_full_instruction( void ); + +unsigned +tgsi_build_full_instruction( + const struct tgsi_full_instruction *full_inst, + struct tgsi_token *tokens, + struct tgsi_header *header, + unsigned maxsize ); + +struct tgsi_instruction_predicate +tgsi_default_instruction_predicate(void); + +#if defined __cplusplus +} +#endif + +#endif /* TGSI_BUILD_H */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_dump.c b/src/gallium/auxiliary/tgsi/tgsi_dump.c new file mode 100644 index 0000000..77bde86 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_dump.c @@ -0,0 +1,793 @@ +/************************************************************************** + * + * Copyright 2007-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. + * + **************************************************************************/ + +#include "util/u_debug.h" +#include "util/u_string.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "tgsi_dump.h" +#include "tgsi_info.h" +#include "tgsi_iterate.h" + + +/** Number of spaces to indent for IF/LOOP/etc */ +static const int indent_spaces = 3; + + +struct dump_ctx +{ + struct tgsi_iterate_context iter; + + uint instno; + int indent; + + uint indentation; + + void (*printf)(struct dump_ctx *ctx, const char *format, ...); +}; + +static void +dump_ctx_printf(struct dump_ctx *ctx, const char *format, ...) +{ + va_list ap; + (void)ctx; + va_start(ap, format); + _debug_vprintf(format, ap); + va_end(ap); +} + +static void +dump_enum( + struct dump_ctx *ctx, + uint e, + const char **enums, + uint enum_count ) +{ + if (e >= enum_count) + ctx->printf( ctx, "%u", e ); + else + ctx->printf( ctx, "%s", enums[e] ); +} + +#define EOL() ctx->printf( ctx, "\n" ) +#define TXT(S) ctx->printf( ctx, "%s", S ) +#define CHR(C) ctx->printf( ctx, "%c", C ) +#define UIX(I) ctx->printf( ctx, "0x%x", I ) +#define UID(I) ctx->printf( ctx, "%u", I ) +#define INSTID(I) ctx->printf( ctx, "% 3u", I ) +#define SID(I) ctx->printf( ctx, "%d", I ) +#define FLT(F) ctx->printf( ctx, "%10.4f", F ) +#define ENM(E,ENUMS) dump_enum( ctx, E, ENUMS, sizeof( ENUMS ) / sizeof( *ENUMS ) ) + +static const char *processor_type_names[] = +{ + "FRAG", + "VERT", + "GEOM" +}; + +const char * +tgsi_file_names[TGSI_FILE_COUNT] = +{ + "NULL", + "CONST", + "IN", + "OUT", + "TEMP", + "SAMP", + "ADDR", + "IMM", + "PRED", + "SV", + "IMMX", + "TEMPX" +}; + +static const char *interpolate_names[] = +{ + "CONSTANT", + "LINEAR", + "PERSPECTIVE" +}; + +static const char *semantic_names[] = +{ + "POSITION", + "COLOR", + "BCOLOR", + "FOG", + "PSIZE", + "GENERIC", + "NORMAL", + "FACE", + "EDGEFLAG", + "PRIM_ID", + "INSTANCEID", + "STENCIL" +}; + +static const char *immediate_type_names[] = +{ + "FLT32", + "UINT32", + "INT32" +}; + +const char * +tgsi_swizzle_names[] = +{ + "x", + "y", + "z", + "w" +}; + +const char * +tgsi_texture_names[] = +{ + "UNKNOWN", + "1D", + "2D", + "3D", + "CUBE", + "RECT", + "SHADOW1D", + "SHADOW2D", + "SHADOWRECT" +}; + +static const char *property_names[] = +{ + "GS_INPUT_PRIMITIVE", + "GS_OUTPUT_PRIMITIVE", + "GS_MAX_OUTPUT_VERTICES", + "FS_COORD_ORIGIN", + "FS_COORD_PIXEL_CENTER" +}; + +static const char *primitive_names[] = +{ + "POINTS", + "LINES", + "LINE_LOOP", + "LINE_STRIP", + "TRIANGLES", + "TRIANGLE_STRIP", + "TRIANGLE_FAN", + "QUADS", + "QUAD_STRIP", + "POLYGON", + "LINES_ADJACENCY", + "LINE_STRIP_ADJACENCY", + "TRIANGLES_ADJACENCY", + "TRIANGLE_STRIP_ADJACENCY" +}; + +static const char *fs_coord_origin_names[] = +{ + "UPPER_LEFT", + "LOWER_LEFT" +}; + +static const char *fs_coord_pixel_center_names[] = +{ + "HALF_INTEGER", + "INTEGER" +}; + + +static void +_dump_register_src( + struct dump_ctx *ctx, + const struct tgsi_full_src_register *src ) +{ + ENM(src->Register.File, tgsi_file_names); + if (src->Register.Dimension) { + if (src->Dimension.Indirect) { + CHR( '[' ); + ENM( src->DimIndirect.File, tgsi_file_names ); + CHR( '[' ); + SID( src->DimIndirect.Index ); + TXT( "]." ); + ENM( src->DimIndirect.SwizzleX, tgsi_swizzle_names ); + if (src->Dimension.Index != 0) { + if (src->Dimension.Index > 0) + CHR( '+' ); + SID( src->Dimension.Index ); + } + CHR( ']' ); + } else { + CHR('['); + SID(src->Dimension.Index); + CHR(']'); + } + } + if (src->Register.Indirect) { + CHR( '[' ); + ENM( src->Indirect.File, tgsi_file_names ); + CHR( '[' ); + SID( src->Indirect.Index ); + TXT( "]." ); + ENM( src->Indirect.SwizzleX, tgsi_swizzle_names ); + if (src->Register.Index != 0) { + if (src->Register.Index > 0) + CHR( '+' ); + SID( src->Register.Index ); + } + CHR( ']' ); + } else { + CHR( '[' ); + SID( src->Register.Index ); + CHR( ']' ); + } +} + + +static void +_dump_register_dst( + struct dump_ctx *ctx, + const struct tgsi_full_dst_register *dst ) +{ + ENM(dst->Register.File, tgsi_file_names); + if (dst->Register.Dimension) { + if (dst->Dimension.Indirect) { + CHR( '[' ); + ENM( dst->DimIndirect.File, tgsi_file_names ); + CHR( '[' ); + SID( dst->DimIndirect.Index ); + TXT( "]." ); + ENM( dst->DimIndirect.SwizzleX, tgsi_swizzle_names ); + if (dst->Dimension.Index != 0) { + if (dst->Dimension.Index > 0) + CHR( '+' ); + SID( dst->Dimension.Index ); + } + CHR( ']' ); + } else { + CHR('['); + SID(dst->Dimension.Index); + CHR(']'); + } + } + if (dst->Register.Indirect) { + CHR( '[' ); + ENM( dst->Indirect.File, tgsi_file_names ); + CHR( '[' ); + SID( dst->Indirect.Index ); + TXT( "]." ); + ENM( dst->Indirect.SwizzleX, tgsi_swizzle_names ); + if (dst->Register.Index != 0) { + if (dst->Register.Index > 0) + CHR( '+' ); + SID( dst->Register.Index ); + } + CHR( ']' ); + } else { + CHR( '[' ); + SID( dst->Register.Index ); + CHR( ']' ); + } +} +static void +_dump_writemask( + struct dump_ctx *ctx, + uint writemask ) +{ + if (writemask != TGSI_WRITEMASK_XYZW) { + CHR( '.' ); + if (writemask & TGSI_WRITEMASK_X) + CHR( 'x' ); + if (writemask & TGSI_WRITEMASK_Y) + CHR( 'y' ); + if (writemask & TGSI_WRITEMASK_Z) + CHR( 'z' ); + if (writemask & TGSI_WRITEMASK_W) + CHR( 'w' ); + } +} + +static void +dump_imm_data(struct tgsi_iterate_context *iter, + union tgsi_immediate_data *data, + unsigned num_tokens, + unsigned data_type) +{ + struct dump_ctx *ctx = (struct dump_ctx *)iter; + unsigned i ; + + TXT( " {" ); + + assert( num_tokens <= 4 ); + for (i = 0; i < num_tokens; i++) { + switch (data_type) { + case TGSI_IMM_FLOAT32: + FLT( data[i].Float ); + break; + case TGSI_IMM_UINT32: + UID(data[i].Uint); + break; + case TGSI_IMM_INT32: + SID(data[i].Int); + break; + default: + assert( 0 ); + } + + if (i < num_tokens - 1) + TXT( ", " ); + } + TXT( "}" ); +} + +static boolean +iter_declaration( + struct tgsi_iterate_context *iter, + struct tgsi_full_declaration *decl ) +{ + struct dump_ctx *ctx = (struct dump_ctx *)iter; + + assert(Elements(semantic_names) == TGSI_SEMANTIC_COUNT); + assert(Elements(interpolate_names) == TGSI_INTERPOLATE_COUNT); + + TXT( "DCL " ); + + ENM(decl->Declaration.File, tgsi_file_names); + + /* all geometry shader inputs are two dimensional */ + if (decl->Declaration.File == TGSI_FILE_INPUT && + iter->processor.Processor == TGSI_PROCESSOR_GEOMETRY) { + TXT("[]"); + } + + if (decl->Declaration.Dimension) { + CHR('['); + SID(decl->Dim.Index2D); + CHR(']'); + } + + CHR('['); + SID(decl->Range.First); + if (decl->Range.First != decl->Range.Last) { + TXT(".."); + SID(decl->Range.Last); + } + CHR(']'); + + _dump_writemask( + ctx, + decl->Declaration.UsageMask ); + + if (decl->Declaration.Semantic) { + TXT( ", " ); + ENM( decl->Semantic.Name, semantic_names ); + if (decl->Semantic.Index != 0 || + decl->Semantic.Name == TGSI_SEMANTIC_GENERIC) { + CHR( '[' ); + UID( decl->Semantic.Index ); + CHR( ']' ); + } + } + + if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT && + decl->Declaration.File == TGSI_FILE_INPUT) + { + TXT( ", " ); + ENM( decl->Declaration.Interpolate, interpolate_names ); + } + + if (decl->Declaration.Centroid) { + TXT( ", CENTROID" ); + } + + if (decl->Declaration.Invariant) { + TXT( ", INVARIANT" ); + } + + if (decl->Declaration.CylindricalWrap) { + TXT(", CYLWRAP_"); + if (decl->Declaration.CylindricalWrap & TGSI_CYLINDRICAL_WRAP_X) { + CHR('X'); + } + if (decl->Declaration.CylindricalWrap & TGSI_CYLINDRICAL_WRAP_Y) { + CHR('Y'); + } + if (decl->Declaration.CylindricalWrap & TGSI_CYLINDRICAL_WRAP_Z) { + CHR('Z'); + } + if (decl->Declaration.CylindricalWrap & TGSI_CYLINDRICAL_WRAP_W) { + CHR('W'); + } + } + + if (decl->Declaration.File == TGSI_FILE_IMMEDIATE_ARRAY) { + unsigned i; + char range_indent[4]; + + TXT(" {"); + + if (decl->Range.Last < 10) + range_indent[0] = '\0'; + else if (decl->Range.Last < 100) { + range_indent[0] = ' '; + range_indent[1] = '\0'; + } else if (decl->Range.Last < 1000) { + range_indent[0] = ' '; + range_indent[1] = ' '; + range_indent[2] = '\0'; + } else { + range_indent[0] = ' '; + range_indent[1] = ' '; + range_indent[2] = ' '; + range_indent[3] = '\0'; + } + + dump_imm_data(iter, decl->ImmediateData.u, + 4, TGSI_IMM_FLOAT32); + for(i = 1; i <= decl->Range.Last; ++i) { + /* indent by strlen of: + * "DCL IMMX[0..1] {" */ + CHR('\n'); + TXT( " " ); + TXT( range_indent ); + dump_imm_data(iter, decl->ImmediateData.u + i, + 4, TGSI_IMM_FLOAT32); + } + + TXT(" }"); + } + + EOL(); + + return TRUE; +} + +void +tgsi_dump_declaration( + const struct tgsi_full_declaration *decl ) +{ + struct dump_ctx ctx; + + ctx.printf = dump_ctx_printf; + + iter_declaration( &ctx.iter, (struct tgsi_full_declaration *)decl ); +} + +static boolean +iter_property( + struct tgsi_iterate_context *iter, + struct tgsi_full_property *prop ) +{ + int i; + struct dump_ctx *ctx = (struct dump_ctx *)iter; + + assert(Elements(property_names) == TGSI_PROPERTY_COUNT); + + TXT( "PROPERTY " ); + ENM(prop->Property.PropertyName, property_names); + + if (prop->Property.NrTokens > 1) + TXT(" "); + + for (i = 0; i < prop->Property.NrTokens - 1; ++i) { + switch (prop->Property.PropertyName) { + case TGSI_PROPERTY_GS_INPUT_PRIM: + case TGSI_PROPERTY_GS_OUTPUT_PRIM: + ENM(prop->u[i].Data, primitive_names); + break; + case TGSI_PROPERTY_FS_COORD_ORIGIN: + ENM(prop->u[i].Data, fs_coord_origin_names); + break; + case TGSI_PROPERTY_FS_COORD_PIXEL_CENTER: + ENM(prop->u[i].Data, fs_coord_pixel_center_names); + break; + default: + SID( prop->u[i].Data ); + break; + } + if (i < prop->Property.NrTokens - 2) + TXT( ", " ); + } + EOL(); + + return TRUE; +} + +void tgsi_dump_property( + const struct tgsi_full_property *prop ) +{ + struct dump_ctx ctx; + + ctx.printf = dump_ctx_printf; + + iter_property( &ctx.iter, (struct tgsi_full_property *)prop ); +} + +static boolean +iter_immediate( + struct tgsi_iterate_context *iter, + struct tgsi_full_immediate *imm ) +{ + struct dump_ctx *ctx = (struct dump_ctx *) iter; + + TXT( "IMM " ); + ENM( imm->Immediate.DataType, immediate_type_names ); + + dump_imm_data(iter, imm->u, imm->Immediate.NrTokens - 1, + imm->Immediate.DataType); + + EOL(); + + return TRUE; +} + +void +tgsi_dump_immediate( + const struct tgsi_full_immediate *imm ) +{ + struct dump_ctx ctx; + + ctx.printf = dump_ctx_printf; + + iter_immediate( &ctx.iter, (struct tgsi_full_immediate *)imm ); +} + +static boolean +iter_instruction( + struct tgsi_iterate_context *iter, + struct tgsi_full_instruction *inst ) +{ + struct dump_ctx *ctx = (struct dump_ctx *) iter; + uint instno = ctx->instno++; + const struct tgsi_opcode_info *info = tgsi_get_opcode_info( inst->Instruction.Opcode ); + uint i; + boolean first_reg = TRUE; + + INSTID( instno ); + TXT( ": " ); + + ctx->indent -= info->pre_dedent; + for(i = 0; (int)i < ctx->indent; ++i) + TXT( " " ); + ctx->indent += info->post_indent; + + if (inst->Instruction.Predicate) { + CHR( '(' ); + + if (inst->Predicate.Negate) + CHR( '!' ); + + TXT( "PRED[" ); + SID( inst->Predicate.Index ); + CHR( ']' ); + + if (inst->Predicate.SwizzleX != TGSI_SWIZZLE_X || + inst->Predicate.SwizzleY != TGSI_SWIZZLE_Y || + inst->Predicate.SwizzleZ != TGSI_SWIZZLE_Z || + inst->Predicate.SwizzleW != TGSI_SWIZZLE_W) { + CHR( '.' ); + ENM( inst->Predicate.SwizzleX, tgsi_swizzle_names ); + ENM( inst->Predicate.SwizzleY, tgsi_swizzle_names ); + ENM( inst->Predicate.SwizzleZ, tgsi_swizzle_names ); + ENM( inst->Predicate.SwizzleW, tgsi_swizzle_names ); + } + + TXT( ") " ); + } + + TXT( info->mnemonic ); + + switch (inst->Instruction.Saturate) { + case TGSI_SAT_NONE: + break; + case TGSI_SAT_ZERO_ONE: + TXT( "_SAT" ); + break; + case TGSI_SAT_MINUS_PLUS_ONE: + TXT( "_SATNV" ); + break; + default: + assert( 0 ); + } + + for (i = 0; i < inst->Instruction.NumDstRegs; i++) { + const struct tgsi_full_dst_register *dst = &inst->Dst[i]; + + if (!first_reg) + CHR( ',' ); + CHR( ' ' ); + + _dump_register_dst( ctx, dst ); + _dump_writemask( ctx, dst->Register.WriteMask ); + + first_reg = FALSE; + } + + for (i = 0; i < inst->Instruction.NumSrcRegs; i++) { + const struct tgsi_full_src_register *src = &inst->Src[i]; + + if (!first_reg) + CHR( ',' ); + CHR( ' ' ); + + if (src->Register.Negate) + CHR( '-' ); + if (src->Register.Absolute) + CHR( '|' ); + + _dump_register_src(ctx, src); + + if (src->Register.SwizzleX != TGSI_SWIZZLE_X || + src->Register.SwizzleY != TGSI_SWIZZLE_Y || + src->Register.SwizzleZ != TGSI_SWIZZLE_Z || + src->Register.SwizzleW != TGSI_SWIZZLE_W) { + CHR( '.' ); + ENM( src->Register.SwizzleX, tgsi_swizzle_names ); + ENM( src->Register.SwizzleY, tgsi_swizzle_names ); + ENM( src->Register.SwizzleZ, tgsi_swizzle_names ); + ENM( src->Register.SwizzleW, tgsi_swizzle_names ); + } + + if (src->Register.Absolute) + CHR( '|' ); + + first_reg = FALSE; + } + + if (inst->Instruction.Texture) { + TXT( ", " ); + ENM( inst->Texture.Texture, tgsi_texture_names ); + } + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_IF: + case TGSI_OPCODE_ELSE: + case TGSI_OPCODE_BGNLOOP: + case TGSI_OPCODE_ENDLOOP: + case TGSI_OPCODE_CAL: + TXT( " :" ); + UID( inst->Label.Label ); + break; + } + + /* update indentation */ + if (inst->Instruction.Opcode == TGSI_OPCODE_IF || + inst->Instruction.Opcode == TGSI_OPCODE_ELSE || + inst->Instruction.Opcode == TGSI_OPCODE_BGNLOOP) { + ctx->indentation += indent_spaces; + } + + EOL(); + + return TRUE; +} + +void +tgsi_dump_instruction( + const struct tgsi_full_instruction *inst, + uint instno ) +{ + struct dump_ctx ctx; + + ctx.instno = instno; + ctx.indent = 0; + ctx.printf = dump_ctx_printf; + ctx.indentation = 0; + + iter_instruction( &ctx.iter, (struct tgsi_full_instruction *)inst ); +} + +static boolean +prolog( + struct tgsi_iterate_context *iter ) +{ + struct dump_ctx *ctx = (struct dump_ctx *) iter; + ENM( iter->processor.Processor, processor_type_names ); + EOL(); + return TRUE; +} + +void +tgsi_dump( + const struct tgsi_token *tokens, + uint flags ) +{ + struct dump_ctx ctx; + + ctx.iter.prolog = prolog; + ctx.iter.iterate_instruction = iter_instruction; + ctx.iter.iterate_declaration = iter_declaration; + ctx.iter.iterate_immediate = iter_immediate; + ctx.iter.iterate_property = iter_property; + ctx.iter.epilog = NULL; + + ctx.instno = 0; + ctx.indent = 0; + ctx.printf = dump_ctx_printf; + ctx.indentation = 0; + + tgsi_iterate_shader( tokens, &ctx.iter ); +} + +struct str_dump_ctx +{ + struct dump_ctx base; + char *str; + char *ptr; + int left; +}; + +static void +str_dump_ctx_printf(struct dump_ctx *ctx, const char *format, ...) +{ + struct str_dump_ctx *sctx = (struct str_dump_ctx *)ctx; + + if(sctx->left > 1) { + int written; + va_list ap; + va_start(ap, format); + written = util_vsnprintf(sctx->ptr, sctx->left, format, ap); + va_end(ap); + + /* Some complicated logic needed to handle the return value of + * vsnprintf: + */ + if (written > 0) { + written = MIN2(sctx->left, written); + sctx->ptr += written; + sctx->left -= written; + } + } +} + +void +tgsi_dump_str( + const struct tgsi_token *tokens, + uint flags, + char *str, + size_t size) +{ + struct str_dump_ctx ctx; + + ctx.base.iter.prolog = prolog; + ctx.base.iter.iterate_instruction = iter_instruction; + ctx.base.iter.iterate_declaration = iter_declaration; + ctx.base.iter.iterate_immediate = iter_immediate; + ctx.base.iter.iterate_property = iter_property; + ctx.base.iter.epilog = NULL; + + ctx.base.instno = 0; + ctx.base.indent = 0; + ctx.base.printf = &str_dump_ctx_printf; + ctx.base.indentation = 0; + + ctx.str = str; + ctx.str[0] = 0; + ctx.ptr = str; + ctx.left = (int)size; + + tgsi_iterate_shader( tokens, &ctx.base.iter ); +} diff --git a/src/gallium/auxiliary/tgsi/tgsi_dump.h b/src/gallium/auxiliary/tgsi/tgsi_dump.h new file mode 100644 index 0000000..fc0429a --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_dump.h @@ -0,0 +1,85 @@ +/************************************************************************** + * + * Copyright 2007-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. + * + **************************************************************************/ + +#ifndef TGSI_DUMP_H +#define TGSI_DUMP_H + +#include "pipe/p_compiler.h" +#include "pipe/p_shader_tokens.h" + +#if defined __cplusplus +extern "C" { +#endif + +extern const char * +tgsi_file_names[TGSI_FILE_COUNT]; + +extern const char * +tgsi_swizzle_names[]; + +extern const char * +tgsi_texture_names[]; + +void +tgsi_dump_str( + const struct tgsi_token *tokens, + uint flags, + char *str, + size_t size); + +void +tgsi_dump( + const struct tgsi_token *tokens, + uint flags ); + +struct tgsi_full_immediate; +struct tgsi_full_instruction; +struct tgsi_full_declaration; +struct tgsi_full_property; + +void +tgsi_dump_immediate( + const struct tgsi_full_immediate *imm ); + +void +tgsi_dump_instruction( + const struct tgsi_full_instruction *inst, + uint instno ); + +void +tgsi_dump_declaration( + const struct tgsi_full_declaration *decl ); + +void +tgsi_dump_property( + const struct tgsi_full_property *prop ); + +#if defined __cplusplus +} +#endif + +#endif /* TGSI_DUMP_H */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c new file mode 100644 index 0000000..7892a67 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c @@ -0,0 +1,3810 @@ +/************************************************************************** + * + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2009-2010 VMware, Inc. All rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL 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. + * + **************************************************************************/ + +/** + * TGSI interpreter/executor. + * + * Flow control information: + * + * Since we operate on 'quads' (4 pixels or 4 vertices in parallel) + * flow control statements (IF/ELSE/ENDIF, LOOP/ENDLOOP) require special + * care since a condition may be true for some quad components but false + * for other components. + * + * We basically execute all statements (even if they're in the part of + * an IF/ELSE clause that's "not taken") and use a special mask to + * control writing to destination registers. This is the ExecMask. + * See store_dest(). + * + * The ExecMask is computed from three other masks (CondMask, LoopMask and + * ContMask) which are controlled by the flow control instructions (namely: + * (IF/ELSE/ENDIF, LOOP/ENDLOOP and CONT). + * + * + * Authors: + * Michal Krol + * Brian Paul + */ + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "tgsi_exec.h" +#include "util/u_memory.h" +#include "util/u_math.h" + + +#define FAST_MATH 1 + +#define TILE_TOP_LEFT 0 +#define TILE_TOP_RIGHT 1 +#define TILE_BOTTOM_LEFT 2 +#define TILE_BOTTOM_RIGHT 3 + +static void +micro_abs(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->f[0] = fabsf(src->f[0]); + dst->f[1] = fabsf(src->f[1]); + dst->f[2] = fabsf(src->f[2]); + dst->f[3] = fabsf(src->f[3]); +} + +static void +micro_arl(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->i[0] = (int)floorf(src->f[0]); + dst->i[1] = (int)floorf(src->f[1]); + dst->i[2] = (int)floorf(src->f[2]); + dst->i[3] = (int)floorf(src->f[3]); +} + +static void +micro_arr(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->i[0] = (int)floorf(src->f[0] + 0.5f); + dst->i[1] = (int)floorf(src->f[1] + 0.5f); + dst->i[2] = (int)floorf(src->f[2] + 0.5f); + dst->i[3] = (int)floorf(src->f[3] + 0.5f); +} + +static void +micro_ceil(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->f[0] = ceilf(src->f[0]); + dst->f[1] = ceilf(src->f[1]); + dst->f[2] = ceilf(src->f[2]); + dst->f[3] = ceilf(src->f[3]); +} + +static void +micro_clamp(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) +{ + dst->f[0] = src0->f[0] < src1->f[0] ? src1->f[0] : src0->f[0] > src2->f[0] ? src2->f[0] : src0->f[0]; + dst->f[1] = src0->f[1] < src1->f[1] ? src1->f[1] : src0->f[1] > src2->f[1] ? src2->f[1] : src0->f[1]; + dst->f[2] = src0->f[2] < src1->f[2] ? src1->f[2] : src0->f[2] > src2->f[2] ? src2->f[2] : src0->f[2]; + dst->f[3] = src0->f[3] < src1->f[3] ? src1->f[3] : src0->f[3] > src2->f[3] ? src2->f[3] : src0->f[3]; +} + +static void +micro_cmp(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) +{ + dst->f[0] = src0->f[0] < 0.0f ? src1->f[0] : src2->f[0]; + dst->f[1] = src0->f[1] < 0.0f ? src1->f[1] : src2->f[1]; + dst->f[2] = src0->f[2] < 0.0f ? src1->f[2] : src2->f[2]; + dst->f[3] = src0->f[3] < 0.0f ? src1->f[3] : src2->f[3]; +} + +static void +micro_cnd(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) +{ + dst->f[0] = src2->f[0] > 0.5f ? src0->f[0] : src1->f[0]; + dst->f[1] = src2->f[1] > 0.5f ? src0->f[1] : src1->f[1]; + dst->f[2] = src2->f[2] > 0.5f ? src0->f[2] : src1->f[2]; + dst->f[3] = src2->f[3] > 0.5f ? src0->f[3] : src1->f[3]; +} + +static void +micro_cos(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->f[0] = cosf(src->f[0]); + dst->f[1] = cosf(src->f[1]); + dst->f[2] = cosf(src->f[2]); + dst->f[3] = cosf(src->f[3]); +} + +static void +micro_ddx(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->f[0] = + dst->f[1] = + dst->f[2] = + dst->f[3] = src->f[TILE_BOTTOM_RIGHT] - src->f[TILE_BOTTOM_LEFT]; +} + +static void +micro_ddy(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->f[0] = + dst->f[1] = + dst->f[2] = + dst->f[3] = src->f[TILE_BOTTOM_LEFT] - src->f[TILE_TOP_LEFT]; +} + +static void +micro_exp2(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ +#if FAST_MATH + dst->f[0] = util_fast_exp2(src->f[0]); + dst->f[1] = util_fast_exp2(src->f[1]); + dst->f[2] = util_fast_exp2(src->f[2]); + dst->f[3] = util_fast_exp2(src->f[3]); +#else +#if DEBUG + /* Inf is okay for this instruction, so clamp it to silence assertions. */ + uint i; + union tgsi_exec_channel clamped; + + for (i = 0; i < 4; i++) { + if (src->f[i] > 127.99999f) { + clamped.f[i] = 127.99999f; + } else if (src->f[i] < -126.99999f) { + clamped.f[i] = -126.99999f; + } else { + clamped.f[i] = src->f[i]; + } + } + src = &clamped; +#endif /* DEBUG */ + + dst->f[0] = powf(2.0f, src->f[0]); + dst->f[1] = powf(2.0f, src->f[1]); + dst->f[2] = powf(2.0f, src->f[2]); + dst->f[3] = powf(2.0f, src->f[3]); +#endif /* FAST_MATH */ +} + +static void +micro_flr(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->f[0] = floorf(src->f[0]); + dst->f[1] = floorf(src->f[1]); + dst->f[2] = floorf(src->f[2]); + dst->f[3] = floorf(src->f[3]); +} + +static void +micro_frc(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->f[0] = src->f[0] - floorf(src->f[0]); + dst->f[1] = src->f[1] - floorf(src->f[1]); + dst->f[2] = src->f[2] - floorf(src->f[2]); + dst->f[3] = src->f[3] - floorf(src->f[3]); +} + +static void +micro_iabs(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->i[0] = src->i[0] >= 0 ? src->i[0] : -src->i[0]; + dst->i[1] = src->i[1] >= 0 ? src->i[1] : -src->i[1]; + dst->i[2] = src->i[2] >= 0 ? src->i[2] : -src->i[2]; + dst->i[3] = src->i[3] >= 0 ? src->i[3] : -src->i[3]; +} + +static void +micro_ineg(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->i[0] = -src->i[0]; + dst->i[1] = -src->i[1]; + dst->i[2] = -src->i[2]; + dst->i[3] = -src->i[3]; +} + +static void +micro_lg2(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ +#if FAST_MATH + dst->f[0] = util_fast_log2(src->f[0]); + dst->f[1] = util_fast_log2(src->f[1]); + dst->f[2] = util_fast_log2(src->f[2]); + dst->f[3] = util_fast_log2(src->f[3]); +#else + dst->f[0] = logf(src->f[0]) * 1.442695f; + dst->f[1] = logf(src->f[1]) * 1.442695f; + dst->f[2] = logf(src->f[2]) * 1.442695f; + dst->f[3] = logf(src->f[3]) * 1.442695f; +#endif +} + +static void +micro_lrp(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) +{ + dst->f[0] = src0->f[0] * (src1->f[0] - src2->f[0]) + src2->f[0]; + dst->f[1] = src0->f[1] * (src1->f[1] - src2->f[1]) + src2->f[1]; + dst->f[2] = src0->f[2] * (src1->f[2] - src2->f[2]) + src2->f[2]; + dst->f[3] = src0->f[3] * (src1->f[3] - src2->f[3]) + src2->f[3]; +} + +static void +micro_mad(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) +{ + dst->f[0] = src0->f[0] * src1->f[0] + src2->f[0]; + dst->f[1] = src0->f[1] * src1->f[1] + src2->f[1]; + dst->f[2] = src0->f[2] * src1->f[2] + src2->f[2]; + dst->f[3] = src0->f[3] * src1->f[3] + src2->f[3]; +} + +static void +micro_mov(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->u[0] = src->u[0]; + dst->u[1] = src->u[1]; + dst->u[2] = src->u[2]; + dst->u[3] = src->u[3]; +} + +static void +micro_rcp(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ +#if 0 /* for debugging */ + assert(src->f[0] != 0.0f); + assert(src->f[1] != 0.0f); + assert(src->f[2] != 0.0f); + assert(src->f[3] != 0.0f); +#endif + dst->f[0] = 1.0f / src->f[0]; + dst->f[1] = 1.0f / src->f[1]; + dst->f[2] = 1.0f / src->f[2]; + dst->f[3] = 1.0f / src->f[3]; +} + +static void +micro_rnd(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->f[0] = floorf(src->f[0] + 0.5f); + dst->f[1] = floorf(src->f[1] + 0.5f); + dst->f[2] = floorf(src->f[2] + 0.5f); + dst->f[3] = floorf(src->f[3] + 0.5f); +} + +static void +micro_rsq(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ +#if 0 /* for debugging */ + assert(src->f[0] != 0.0f); + assert(src->f[1] != 0.0f); + assert(src->f[2] != 0.0f); + assert(src->f[3] != 0.0f); +#endif + dst->f[0] = 1.0f / sqrtf(fabsf(src->f[0])); + dst->f[1] = 1.0f / sqrtf(fabsf(src->f[1])); + dst->f[2] = 1.0f / sqrtf(fabsf(src->f[2])); + dst->f[3] = 1.0f / sqrtf(fabsf(src->f[3])); +} + +static void +micro_seq(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->f[0] = src0->f[0] == src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] == src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] == src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] == src1->f[3] ? 1.0f : 0.0f; +} + +static void +micro_sge(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->f[0] = src0->f[0] >= src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] >= src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] >= src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] >= src1->f[3] ? 1.0f : 0.0f; +} + +static void +micro_sgn(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->f[0] = src->f[0] < 0.0f ? -1.0f : src->f[0] > 0.0f ? 1.0f : 0.0f; + dst->f[1] = src->f[1] < 0.0f ? -1.0f : src->f[1] > 0.0f ? 1.0f : 0.0f; + dst->f[2] = src->f[2] < 0.0f ? -1.0f : src->f[2] > 0.0f ? 1.0f : 0.0f; + dst->f[3] = src->f[3] < 0.0f ? -1.0f : src->f[3] > 0.0f ? 1.0f : 0.0f; +} + +static void +micro_sgt(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->f[0] = src0->f[0] > src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] > src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] > src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] > src1->f[3] ? 1.0f : 0.0f; +} + +static void +micro_sin(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->f[0] = sinf(src->f[0]); + dst->f[1] = sinf(src->f[1]); + dst->f[2] = sinf(src->f[2]); + dst->f[3] = sinf(src->f[3]); +} + +static void +micro_sle(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->f[0] = src0->f[0] <= src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] <= src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] <= src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] <= src1->f[3] ? 1.0f : 0.0f; +} + +static void +micro_slt(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->f[0] = src0->f[0] < src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] < src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] < src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] < src1->f[3] ? 1.0f : 0.0f; +} + +static void +micro_sne(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->f[0] = src0->f[0] != src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] != src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] != src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] != src1->f[3] ? 1.0f : 0.0f; +} + +static void +micro_sfl(union tgsi_exec_channel *dst) +{ + dst->f[0] = 0.0f; + dst->f[1] = 0.0f; + dst->f[2] = 0.0f; + dst->f[3] = 0.0f; +} + +static void +micro_str(union tgsi_exec_channel *dst) +{ + dst->f[0] = 1.0f; + dst->f[1] = 1.0f; + dst->f[2] = 1.0f; + dst->f[3] = 1.0f; +} + +static void +micro_trunc(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->f[0] = (float)(int)src->f[0]; + dst->f[1] = (float)(int)src->f[1]; + dst->f[2] = (float)(int)src->f[2]; + dst->f[3] = (float)(int)src->f[3]; +} + + +#define CHAN_X 0 +#define CHAN_Y 1 +#define CHAN_Z 2 +#define CHAN_W 3 + +enum tgsi_exec_datatype { + TGSI_EXEC_DATA_FLOAT, + TGSI_EXEC_DATA_INT, + TGSI_EXEC_DATA_UINT +}; + +/* + * Shorthand locations of various utility registers (_I = Index, _C = Channel) + */ +#define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I +#define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C +#define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I +#define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C +#define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I +#define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C + + +/** The execution mask depends on the conditional mask and the loop mask */ +#define UPDATE_EXEC_MASK(MACH) \ + MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->Switch.mask & MACH->FuncMask + + +static const union tgsi_exec_channel ZeroVec = + { { 0.0, 0.0, 0.0, 0.0 } }; + +static const union tgsi_exec_channel OneVec = { + {1.0f, 1.0f, 1.0f, 1.0f} +}; + +static const union tgsi_exec_channel P128Vec = { + {128.0f, 128.0f, 128.0f, 128.0f} +}; + +static const union tgsi_exec_channel M128Vec = { + {-128.0f, -128.0f, -128.0f, -128.0f} +}; + + +/** + * Assert that none of the float values in 'chan' are infinite or NaN. + * NaN and Inf may occur normally during program execution and should + * not lead to crashes, etc. But when debugging, it's helpful to catch + * them. + */ +static INLINE void +check_inf_or_nan(const union tgsi_exec_channel *chan) +{ + assert(!util_is_inf_or_nan((chan)->f[0])); + assert(!util_is_inf_or_nan((chan)->f[1])); + assert(!util_is_inf_or_nan((chan)->f[2])); + assert(!util_is_inf_or_nan((chan)->f[3])); +} + + +#ifdef DEBUG +static void +print_chan(const char *msg, const union tgsi_exec_channel *chan) +{ + debug_printf("%s = {%f, %f, %f, %f}\n", + msg, chan->f[0], chan->f[1], chan->f[2], chan->f[3]); +} +#endif + + +#ifdef DEBUG +static void +print_temp(const struct tgsi_exec_machine *mach, uint index) +{ + const struct tgsi_exec_vector *tmp = &mach->Temps[index]; + int i; + debug_printf("Temp[%u] =\n", index); + for (i = 0; i < 4; i++) { + debug_printf(" %c: { %f, %f, %f, %f }\n", + "XYZW"[i], + tmp->xyzw[i].f[0], + tmp->xyzw[i].f[1], + tmp->xyzw[i].f[2], + tmp->xyzw[i].f[3]); + } +} +#endif + + +void +tgsi_exec_set_constant_buffers(struct tgsi_exec_machine *mach, + unsigned num_bufs, + const void **bufs, + const unsigned *buf_sizes) +{ + unsigned i; + + for (i = 0; i < num_bufs; i++) { + mach->Consts[i] = bufs[i]; + mach->ConstsSize[i] = buf_sizes[i]; + } +} + + +/** + * Check if there's a potential src/dst register data dependency when + * using SOA execution. + * Example: + * MOV T, T.yxwz; + * This would expand into: + * MOV t0, t1; + * MOV t1, t0; + * MOV t2, t3; + * MOV t3, t2; + * The second instruction will have the wrong value for t0 if executed as-is. + */ +boolean +tgsi_check_soa_dependencies(const struct tgsi_full_instruction *inst) +{ + uint i, chan; + + uint writemask = inst->Dst[0].Register.WriteMask; + if (writemask == TGSI_WRITEMASK_X || + writemask == TGSI_WRITEMASK_Y || + writemask == TGSI_WRITEMASK_Z || + writemask == TGSI_WRITEMASK_W || + writemask == TGSI_WRITEMASK_NONE) { + /* no chance of data dependency */ + return FALSE; + } + + /* loop over src regs */ + for (i = 0; i < inst->Instruction.NumSrcRegs; i++) { + if ((inst->Src[i].Register.File == + inst->Dst[0].Register.File) && + ((inst->Src[i].Register.Index == + inst->Dst[0].Register.Index) || + inst->Src[i].Register.Indirect || + inst->Dst[0].Register.Indirect)) { + /* loop over dest channels */ + uint channelsWritten = 0x0; + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + /* check if we're reading a channel that's been written */ + uint swizzle = tgsi_util_get_full_src_register_swizzle(&inst->Src[i], chan); + if (channelsWritten & (1 << swizzle)) { + return TRUE; + } + + channelsWritten |= (1 << chan); + } + } + } + } + return FALSE; +} + + +/** + * Initialize machine state by expanding tokens to full instructions, + * allocating temporary storage, setting up constants, etc. + * After this, we can call tgsi_exec_machine_run() many times. + */ +void +tgsi_exec_machine_bind_shader( + struct tgsi_exec_machine *mach, + const struct tgsi_token *tokens, + uint numSamplers, + struct tgsi_sampler **samplers) +{ + uint k; + struct tgsi_parse_context parse; + struct tgsi_full_instruction *instructions; + struct tgsi_full_declaration *declarations; + uint maxInstructions = 10, numInstructions = 0; + uint maxDeclarations = 10, numDeclarations = 0; + +#if 0 + tgsi_dump(tokens, 0); +#endif + + util_init_math(); + + if (numSamplers) { + assert(samplers); + } + + mach->Tokens = tokens; + mach->Samplers = samplers; + + if (!tokens) { + /* unbind and free all */ + if (mach->Declarations) { + FREE( mach->Declarations ); + } + mach->Declarations = NULL; + mach->NumDeclarations = 0; + + if (mach->Instructions) { + FREE( mach->Instructions ); + } + mach->Instructions = NULL; + mach->NumInstructions = 0; + + return; + } + + k = tgsi_parse_init (&parse, mach->Tokens); + if (k != TGSI_PARSE_OK) { + debug_printf( "Problem parsing!\n" ); + return; + } + + mach->Processor = parse.FullHeader.Processor.Processor; + mach->ImmLimit = 0; + + declarations = (struct tgsi_full_declaration *) + MALLOC( maxDeclarations * sizeof(struct tgsi_full_declaration) ); + + if (!declarations) { + return; + } + + instructions = (struct tgsi_full_instruction *) + MALLOC( maxInstructions * sizeof(struct tgsi_full_instruction) ); + + if (!instructions) { + FREE( declarations ); + return; + } + + while( !tgsi_parse_end_of_tokens( &parse ) ) { + uint i; + + tgsi_parse_token( &parse ); + switch( parse.FullToken.Token.Type ) { + case TGSI_TOKEN_TYPE_DECLARATION: + /* save expanded declaration */ + if (numDeclarations == maxDeclarations) { + declarations = REALLOC(declarations, + maxDeclarations + * sizeof(struct tgsi_full_declaration), + (maxDeclarations + 10) + * sizeof(struct tgsi_full_declaration)); + maxDeclarations += 10; + } + if (parse.FullToken.FullDeclaration.Declaration.File == TGSI_FILE_OUTPUT) { + unsigned reg; + for (reg = parse.FullToken.FullDeclaration.Range.First; + reg <= parse.FullToken.FullDeclaration.Range.Last; + ++reg) { + ++mach->NumOutputs; + } + } + if (parse.FullToken.FullDeclaration.Declaration.File == + TGSI_FILE_IMMEDIATE_ARRAY) { + unsigned reg; + struct tgsi_full_declaration *decl = + &parse.FullToken.FullDeclaration; + debug_assert(decl->Range.Last < TGSI_EXEC_NUM_IMMEDIATES); + for (reg = decl->Range.First; reg <= decl->Range.Last; ++reg) { + for( i = 0; i < 4; i++ ) { + int idx = reg * 4 + i; + mach->ImmArray[reg][i] = decl->ImmediateData.u[idx].Float; + } + } + } + memcpy(declarations + numDeclarations, + &parse.FullToken.FullDeclaration, + sizeof(declarations[0])); + numDeclarations++; + break; + + case TGSI_TOKEN_TYPE_IMMEDIATE: + { + uint size = parse.FullToken.FullImmediate.Immediate.NrTokens - 1; + assert( size <= 4 ); + assert( mach->ImmLimit + 1 <= TGSI_EXEC_NUM_IMMEDIATES ); + + for( i = 0; i < size; i++ ) { + mach->Imms[mach->ImmLimit][i] = + parse.FullToken.FullImmediate.u[i].Float; + } + mach->ImmLimit += 1; + } + break; + + case TGSI_TOKEN_TYPE_INSTRUCTION: + + /* save expanded instruction */ + if (numInstructions == maxInstructions) { + instructions = REALLOC(instructions, + maxInstructions + * sizeof(struct tgsi_full_instruction), + (maxInstructions + 10) + * sizeof(struct tgsi_full_instruction)); + maxInstructions += 10; + } + + memcpy(instructions + numInstructions, + &parse.FullToken.FullInstruction, + sizeof(instructions[0])); + + numInstructions++; + break; + + case TGSI_TOKEN_TYPE_PROPERTY: + break; + + default: + assert( 0 ); + } + } + tgsi_parse_free (&parse); + + if (mach->Declarations) { + FREE( mach->Declarations ); + } + mach->Declarations = declarations; + mach->NumDeclarations = numDeclarations; + + if (mach->Instructions) { + FREE( mach->Instructions ); + } + mach->Instructions = instructions; + mach->NumInstructions = numInstructions; +} + + +struct tgsi_exec_machine * +tgsi_exec_machine_create( void ) +{ + struct tgsi_exec_machine *mach; + uint i; + + mach = align_malloc( sizeof *mach, 16 ); + if (!mach) + goto fail; + + memset(mach, 0, sizeof(*mach)); + + mach->Addrs = &mach->Temps[TGSI_EXEC_TEMP_ADDR]; + mach->MaxGeometryShaderOutputs = TGSI_MAX_TOTAL_VERTICES; + mach->Predicates = &mach->Temps[TGSI_EXEC_TEMP_P0]; + + /* Setup constants needed by the SSE2 executor. */ + for( i = 0; i < 4; i++ ) { + mach->Temps[TGSI_EXEC_TEMP_00000000_I].xyzw[TGSI_EXEC_TEMP_00000000_C].u[i] = 0x00000000; + mach->Temps[TGSI_EXEC_TEMP_7FFFFFFF_I].xyzw[TGSI_EXEC_TEMP_7FFFFFFF_C].u[i] = 0x7FFFFFFF; + mach->Temps[TGSI_EXEC_TEMP_80000000_I].xyzw[TGSI_EXEC_TEMP_80000000_C].u[i] = 0x80000000; + mach->Temps[TGSI_EXEC_TEMP_FFFFFFFF_I].xyzw[TGSI_EXEC_TEMP_FFFFFFFF_C].u[i] = 0xFFFFFFFF; /* not used */ + mach->Temps[TGSI_EXEC_TEMP_ONE_I].xyzw[TGSI_EXEC_TEMP_ONE_C].f[i] = 1.0f; + mach->Temps[TGSI_EXEC_TEMP_TWO_I].xyzw[TGSI_EXEC_TEMP_TWO_C].f[i] = 2.0f; /* not used */ + mach->Temps[TGSI_EXEC_TEMP_128_I].xyzw[TGSI_EXEC_TEMP_128_C].f[i] = 128.0f; + mach->Temps[TGSI_EXEC_TEMP_MINUS_128_I].xyzw[TGSI_EXEC_TEMP_MINUS_128_C].f[i] = -128.0f; + mach->Temps[TGSI_EXEC_TEMP_THREE_I].xyzw[TGSI_EXEC_TEMP_THREE_C].f[i] = 3.0f; + mach->Temps[TGSI_EXEC_TEMP_HALF_I].xyzw[TGSI_EXEC_TEMP_HALF_C].f[i] = 0.5f; + } + +#ifdef DEBUG + /* silence warnings */ + (void) print_chan; + (void) print_temp; +#endif + + return mach; + +fail: + align_free(mach); + return NULL; +} + + +void +tgsi_exec_machine_destroy(struct tgsi_exec_machine *mach) +{ + if (mach) { + if (mach->Instructions) + FREE(mach->Instructions); + if (mach->Declarations) + FREE(mach->Declarations); + } + + align_free(mach); +} + +static void +micro_add(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->f[0] = src0->f[0] + src1->f[0]; + dst->f[1] = src0->f[1] + src1->f[1]; + dst->f[2] = src0->f[2] + src1->f[2]; + dst->f[3] = src0->f[3] + src1->f[3]; +} + +static void +micro_div( + union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1 ) +{ + if (src1->f[0] != 0) { + dst->f[0] = src0->f[0] / src1->f[0]; + } + if (src1->f[1] != 0) { + dst->f[1] = src0->f[1] / src1->f[1]; + } + if (src1->f[2] != 0) { + dst->f[2] = src0->f[2] / src1->f[2]; + } + if (src1->f[3] != 0) { + dst->f[3] = src0->f[3] / src1->f[3]; + } +} + +static void +micro_rcc(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + uint i; + + for (i = 0; i < 4; i++) { + float recip = 1.0f / src->f[i]; + + if (recip > 0.0f) { + if (recip > 1.884467e+019f) { + dst->f[i] = 1.884467e+019f; + } + else if (recip < 5.42101e-020f) { + dst->f[i] = 5.42101e-020f; + } + else { + dst->f[i] = recip; + } + } + else { + if (recip < -1.884467e+019f) { + dst->f[i] = -1.884467e+019f; + } + else if (recip > -5.42101e-020f) { + dst->f[i] = -5.42101e-020f; + } + else { + dst->f[i] = recip; + } + } + } +} + +static void +micro_lt( + union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2, + const union tgsi_exec_channel *src3 ) +{ + dst->f[0] = src0->f[0] < src1->f[0] ? src2->f[0] : src3->f[0]; + dst->f[1] = src0->f[1] < src1->f[1] ? src2->f[1] : src3->f[1]; + dst->f[2] = src0->f[2] < src1->f[2] ? src2->f[2] : src3->f[2]; + dst->f[3] = src0->f[3] < src1->f[3] ? src2->f[3] : src3->f[3]; +} + +static void +micro_max(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->f[0] = src0->f[0] > src1->f[0] ? src0->f[0] : src1->f[0]; + dst->f[1] = src0->f[1] > src1->f[1] ? src0->f[1] : src1->f[1]; + dst->f[2] = src0->f[2] > src1->f[2] ? src0->f[2] : src1->f[2]; + dst->f[3] = src0->f[3] > src1->f[3] ? src0->f[3] : src1->f[3]; +} + +static void +micro_min(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->f[0] = src0->f[0] < src1->f[0] ? src0->f[0] : src1->f[0]; + dst->f[1] = src0->f[1] < src1->f[1] ? src0->f[1] : src1->f[1]; + dst->f[2] = src0->f[2] < src1->f[2] ? src0->f[2] : src1->f[2]; + dst->f[3] = src0->f[3] < src1->f[3] ? src0->f[3] : src1->f[3]; +} + +static void +micro_mul(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->f[0] = src0->f[0] * src1->f[0]; + dst->f[1] = src0->f[1] * src1->f[1]; + dst->f[2] = src0->f[2] * src1->f[2]; + dst->f[3] = src0->f[3] * src1->f[3]; +} + +static void +micro_neg( + union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src ) +{ + dst->f[0] = -src->f[0]; + dst->f[1] = -src->f[1]; + dst->f[2] = -src->f[2]; + dst->f[3] = -src->f[3]; +} + +static void +micro_pow( + union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1 ) +{ +#if FAST_MATH + dst->f[0] = util_fast_pow( src0->f[0], src1->f[0] ); + dst->f[1] = util_fast_pow( src0->f[1], src1->f[1] ); + dst->f[2] = util_fast_pow( src0->f[2], src1->f[2] ); + dst->f[3] = util_fast_pow( src0->f[3], src1->f[3] ); +#else + dst->f[0] = powf( src0->f[0], src1->f[0] ); + dst->f[1] = powf( src0->f[1], src1->f[1] ); + dst->f[2] = powf( src0->f[2], src1->f[2] ); + dst->f[3] = powf( src0->f[3], src1->f[3] ); +#endif +} + +static void +micro_sub(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->f[0] = src0->f[0] - src1->f[0]; + dst->f[1] = src0->f[1] - src1->f[1]; + dst->f[2] = src0->f[2] - src1->f[2]; + dst->f[3] = src0->f[3] - src1->f[3]; +} + +static void +fetch_src_file_channel(const struct tgsi_exec_machine *mach, + const uint file, + const uint swizzle, + const union tgsi_exec_channel *index, + const union tgsi_exec_channel *index2D, + union tgsi_exec_channel *chan) +{ + uint i; + + assert(swizzle < 4); + + switch (file) { + case TGSI_FILE_CONSTANT: + for (i = 0; i < QUAD_SIZE; i++) { + assert(index2D->i[i] >= 0 && index2D->i[i] < PIPE_MAX_CONSTANT_BUFFERS); + assert(mach->Consts[index2D->i[i]]); + + if (index->i[i] < 0) { + chan->u[i] = 0; + } else { + /* NOTE: copying the const value as a uint instead of float */ + const uint constbuf = index2D->i[i]; + const uint *buf = (const uint *)mach->Consts[constbuf]; + const int pos = index->i[i] * 4 + swizzle; + /* const buffer bounds check */ + if (pos < 0 || pos >= mach->ConstsSize[constbuf]) { + if (0) { + /* Debug: print warning */ + static int count = 0; + if (count++ < 100) + debug_printf("TGSI Exec: const buffer index %d" + " out of bounds\n", pos); + } + chan->u[i] = 0; + } + else + chan->u[i] = buf[pos]; + } + } + break; + + case TGSI_FILE_INPUT: + case TGSI_FILE_SYSTEM_VALUE: + for (i = 0; i < QUAD_SIZE; i++) { + /* + if (TGSI_PROCESSOR_GEOMETRY == mach->Processor) { + debug_printf("Fetching Input[%d] (2d=%d, 1d=%d)\n", + index2D->i[i] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index->i[i], + index2D->i[i], index->i[i]); + }*/ + int pos = index2D->i[i] * TGSI_EXEC_MAX_INPUT_ATTRIBS + index->i[i]; + assert(pos >= 0); + assert(pos < Elements(mach->Inputs)); + chan->u[i] = mach->Inputs[pos].xyzw[swizzle].u[i]; + } + break; + + case TGSI_FILE_TEMPORARY: + for (i = 0; i < QUAD_SIZE; i++) { + assert(index->i[i] < TGSI_EXEC_NUM_TEMPS); + assert(index2D->i[i] == 0); + + chan->u[i] = mach->Temps[index->i[i]].xyzw[swizzle].u[i]; + } + break; + + case TGSI_FILE_TEMPORARY_ARRAY: + for (i = 0; i < QUAD_SIZE; i++) { + assert(index->i[i] < TGSI_EXEC_NUM_TEMPS); + assert(index2D->i[i] < TGSI_EXEC_NUM_TEMP_ARRAYS); + + chan->u[i] = + mach->TempArray[index2D->i[i]][index->i[i]].xyzw[swizzle].u[i]; + } + break; + + case TGSI_FILE_IMMEDIATE: + for (i = 0; i < QUAD_SIZE; i++) { + assert(index->i[i] >= 0 && index->i[i] < (int)mach->ImmLimit); + assert(index2D->i[i] == 0); + + chan->f[i] = mach->Imms[index->i[i]][swizzle]; + } + break; + + case TGSI_FILE_IMMEDIATE_ARRAY: + for (i = 0; i < QUAD_SIZE; i++) { + assert(index2D->i[i] == 0); + + chan->f[i] = mach->ImmArray[index->i[i]][swizzle]; + } + break; + + case TGSI_FILE_ADDRESS: + for (i = 0; i < QUAD_SIZE; i++) { + assert(index->i[i] >= 0); + assert(index2D->i[i] == 0); + + chan->u[i] = mach->Addrs[index->i[i]].xyzw[swizzle].u[i]; + } + break; + + case TGSI_FILE_PREDICATE: + for (i = 0; i < QUAD_SIZE; i++) { + assert(index->i[i] >= 0 && index->i[i] < TGSI_EXEC_NUM_PREDS); + assert(index2D->i[i] == 0); + + chan->u[i] = mach->Predicates[0].xyzw[swizzle].u[i]; + } + break; + + case TGSI_FILE_OUTPUT: + /* vertex/fragment output vars can be read too */ + for (i = 0; i < QUAD_SIZE; i++) { + assert(index->i[i] >= 0); + assert(index2D->i[i] == 0); + + chan->u[i] = mach->Outputs[index->i[i]].xyzw[swizzle].u[i]; + } + break; + + default: + assert(0); + for (i = 0; i < QUAD_SIZE; i++) { + chan->u[i] = 0; + } + } +} + +static void +fetch_source(const struct tgsi_exec_machine *mach, + union tgsi_exec_channel *chan, + const struct tgsi_full_src_register *reg, + const uint chan_index, + enum tgsi_exec_datatype src_datatype) +{ + union tgsi_exec_channel index; + union tgsi_exec_channel index2D; + uint swizzle; + + /* We start with a direct index into a register file. + * + * file[1], + * where: + * file = Register.File + * [1] = Register.Index + */ + index.i[0] = + index.i[1] = + index.i[2] = + index.i[3] = reg->Register.Index; + + /* There is an extra source register that indirectly subscripts + * a register file. The direct index now becomes an offset + * that is being added to the indirect register. + * + * file[ind[2].x+1], + * where: + * ind = Indirect.File + * [2] = Indirect.Index + * .x = Indirect.SwizzleX + */ + if (reg->Register.Indirect) { + union tgsi_exec_channel index2; + union tgsi_exec_channel indir_index; + const uint execmask = mach->ExecMask; + uint i; + + /* which address register (always zero now) */ + index2.i[0] = + index2.i[1] = + index2.i[2] = + index2.i[3] = reg->Indirect.Index; + assert(reg->Indirect.File == TGSI_FILE_ADDRESS); + /* get current value of address register[swizzle] */ + swizzle = tgsi_util_get_src_register_swizzle( ®->Indirect, CHAN_X ); + fetch_src_file_channel(mach, + reg->Indirect.File, + swizzle, + &index2, + &ZeroVec, + &indir_index); + + /* add value of address register to the offset */ + index.i[0] += indir_index.i[0]; + index.i[1] += indir_index.i[1]; + index.i[2] += indir_index.i[2]; + index.i[3] += indir_index.i[3]; + + /* for disabled execution channels, zero-out the index to + * avoid using a potential garbage value. + */ + for (i = 0; i < QUAD_SIZE; i++) { + if ((execmask & (1 << i)) == 0) + index.i[i] = 0; + } + } + + /* There is an extra source register that is a second + * subscript to a register file. Effectively it means that + * the register file is actually a 2D array of registers. + * + * file[3][1], + * where: + * [3] = Dimension.Index + */ + if (reg->Register.Dimension) { + index2D.i[0] = + index2D.i[1] = + index2D.i[2] = + index2D.i[3] = reg->Dimension.Index; + + /* Again, the second subscript index can be addressed indirectly + * identically to the first one. + * Nothing stops us from indirectly addressing the indirect register, + * but there is no need for that, so we won't exercise it. + * + * file[ind[4].y+3][1], + * where: + * ind = DimIndirect.File + * [4] = DimIndirect.Index + * .y = DimIndirect.SwizzleX + */ + if (reg->Dimension.Indirect) { + union tgsi_exec_channel index2; + union tgsi_exec_channel indir_index; + const uint execmask = mach->ExecMask; + uint i; + + index2.i[0] = + index2.i[1] = + index2.i[2] = + index2.i[3] = reg->DimIndirect.Index; + + swizzle = tgsi_util_get_src_register_swizzle( ®->DimIndirect, CHAN_X ); + fetch_src_file_channel(mach, + reg->DimIndirect.File, + swizzle, + &index2, + &ZeroVec, + &indir_index); + + index2D.i[0] += indir_index.i[0]; + index2D.i[1] += indir_index.i[1]; + index2D.i[2] += indir_index.i[2]; + index2D.i[3] += indir_index.i[3]; + + /* for disabled execution channels, zero-out the index to + * avoid using a potential garbage value. + */ + for (i = 0; i < QUAD_SIZE; i++) { + if ((execmask & (1 << i)) == 0) { + index2D.i[i] = 0; + } + } + } + + /* If by any chance there was a need for a 3D array of register + * files, we would have to check whether Dimension is followed + * by a dimension register and continue the saga. + */ + } else { + index2D.i[0] = + index2D.i[1] = + index2D.i[2] = + index2D.i[3] = 0; + } + + swizzle = tgsi_util_get_full_src_register_swizzle( reg, chan_index ); + fetch_src_file_channel(mach, + reg->Register.File, + swizzle, + &index, + &index2D, + chan); + + if (reg->Register.Absolute) { + if (src_datatype == TGSI_EXEC_DATA_FLOAT) { + micro_abs(chan, chan); + } else { + micro_iabs(chan, chan); + } + } + + if (reg->Register.Negate) { + if (src_datatype == TGSI_EXEC_DATA_FLOAT) { + micro_neg(chan, chan); + } else { + micro_ineg(chan, chan); + } + } +} + +static void +store_dest(struct tgsi_exec_machine *mach, + const union tgsi_exec_channel *chan, + const struct tgsi_full_dst_register *reg, + const struct tgsi_full_instruction *inst, + uint chan_index, + enum tgsi_exec_datatype dst_datatype) +{ + uint i; + union tgsi_exec_channel null; + union tgsi_exec_channel *dst; + union tgsi_exec_channel index2D; + uint execmask = mach->ExecMask; + int offset = 0; /* indirection offset */ + int index; + + /* for debugging */ + if (0 && dst_datatype == TGSI_EXEC_DATA_FLOAT) { + check_inf_or_nan(chan); + } + + /* There is an extra source register that indirectly subscripts + * a register file. The direct index now becomes an offset + * that is being added to the indirect register. + * + * file[ind[2].x+1], + * where: + * ind = Indirect.File + * [2] = Indirect.Index + * .x = Indirect.SwizzleX + */ + if (reg->Register.Indirect) { + union tgsi_exec_channel index; + union tgsi_exec_channel indir_index; + uint swizzle; + + /* which address register (always zero for now) */ + index.i[0] = + index.i[1] = + index.i[2] = + index.i[3] = reg->Indirect.Index; + + /* get current value of address register[swizzle] */ + swizzle = tgsi_util_get_src_register_swizzle( ®->Indirect, CHAN_X ); + + /* fetch values from the address/indirection register */ + fetch_src_file_channel(mach, + reg->Indirect.File, + swizzle, + &index, + &ZeroVec, + &indir_index); + + /* save indirection offset */ + offset = indir_index.i[0]; + } + + /* There is an extra source register that is a second + * subscript to a register file. Effectively it means that + * the register file is actually a 2D array of registers. + * + * file[3][1], + * where: + * [3] = Dimension.Index + */ + if (reg->Register.Dimension) { + index2D.i[0] = + index2D.i[1] = + index2D.i[2] = + index2D.i[3] = reg->Dimension.Index; + + /* Again, the second subscript index can be addressed indirectly + * identically to the first one. + * Nothing stops us from indirectly addressing the indirect register, + * but there is no need for that, so we won't exercise it. + * + * file[ind[4].y+3][1], + * where: + * ind = DimIndirect.File + * [4] = DimIndirect.Index + * .y = DimIndirect.SwizzleX + */ + if (reg->Dimension.Indirect) { + union tgsi_exec_channel index2; + union tgsi_exec_channel indir_index; + const uint execmask = mach->ExecMask; + unsigned swizzle; + uint i; + + index2.i[0] = + index2.i[1] = + index2.i[2] = + index2.i[3] = reg->DimIndirect.Index; + + swizzle = tgsi_util_get_src_register_swizzle( ®->DimIndirect, CHAN_X ); + fetch_src_file_channel(mach, + reg->DimIndirect.File, + swizzle, + &index2, + &ZeroVec, + &indir_index); + + index2D.i[0] += indir_index.i[0]; + index2D.i[1] += indir_index.i[1]; + index2D.i[2] += indir_index.i[2]; + index2D.i[3] += indir_index.i[3]; + + /* for disabled execution channels, zero-out the index to + * avoid using a potential garbage value. + */ + for (i = 0; i < QUAD_SIZE; i++) { + if ((execmask & (1 << i)) == 0) { + index2D.i[i] = 0; + } + } + } + + /* If by any chance there was a need for a 3D array of register + * files, we would have to check whether Dimension is followed + * by a dimension register and continue the saga. + */ + } else { + index2D.i[0] = + index2D.i[1] = + index2D.i[2] = + index2D.i[3] = 0; + } + + switch (reg->Register.File) { + case TGSI_FILE_NULL: + dst = &null; + break; + + case TGSI_FILE_OUTPUT: + index = mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0] + + reg->Register.Index; + dst = &mach->Outputs[offset + index].xyzw[chan_index]; +#if 0 + if (TGSI_PROCESSOR_GEOMETRY == mach->Processor) { + fprintf(stderr, "STORING OUT[%d] mask(%d), = (", offset + index, execmask); + for (i = 0; i < QUAD_SIZE; i++) + if (execmask & (1 << i)) + fprintf(stderr, "%f, ", chan->f[i]); + fprintf(stderr, ")\n"); + } +#endif + break; + + case TGSI_FILE_TEMPORARY: + index = reg->Register.Index; + assert( index < TGSI_EXEC_NUM_TEMPS ); + dst = &mach->Temps[offset + index].xyzw[chan_index]; + break; + + case TGSI_FILE_TEMPORARY_ARRAY: + index = reg->Register.Index; + assert( index < TGSI_EXEC_NUM_TEMPS ); + assert( index2D.i[0] < TGSI_EXEC_NUM_TEMP_ARRAYS ); + /* XXX we use index2D.i[0] here but somehow we might + * end up with someone trying to store indirectly in + * different buffers */ + dst = &mach->TempArray[index2D.i[0]][offset + index].xyzw[chan_index]; + break; + + case TGSI_FILE_ADDRESS: + index = reg->Register.Index; + dst = &mach->Addrs[index].xyzw[chan_index]; + break; + + case TGSI_FILE_PREDICATE: + index = reg->Register.Index; + assert(index < TGSI_EXEC_NUM_PREDS); + dst = &mach->Predicates[index].xyzw[chan_index]; + break; + + default: + assert( 0 ); + return; + } + + if (inst->Instruction.Predicate) { + uint swizzle; + union tgsi_exec_channel *pred; + + switch (chan_index) { + case CHAN_X: + swizzle = inst->Predicate.SwizzleX; + break; + case CHAN_Y: + swizzle = inst->Predicate.SwizzleY; + break; + case CHAN_Z: + swizzle = inst->Predicate.SwizzleZ; + break; + case CHAN_W: + swizzle = inst->Predicate.SwizzleW; + break; + default: + assert(0); + return; + } + + assert(inst->Predicate.Index == 0); + + pred = &mach->Predicates[inst->Predicate.Index].xyzw[swizzle]; + + if (inst->Predicate.Negate) { + for (i = 0; i < QUAD_SIZE; i++) { + if (pred->u[i]) { + execmask &= ~(1 << i); + } + } + } else { + for (i = 0; i < QUAD_SIZE; i++) { + if (!pred->u[i]) { + execmask &= ~(1 << i); + } + } + } + } + + switch (inst->Instruction.Saturate) { + case TGSI_SAT_NONE: + for (i = 0; i < QUAD_SIZE; i++) + if (execmask & (1 << i)) + dst->i[i] = chan->i[i]; + break; + + case TGSI_SAT_ZERO_ONE: + for (i = 0; i < QUAD_SIZE; i++) + if (execmask & (1 << i)) { + if (chan->f[i] < 0.0f) + dst->f[i] = 0.0f; + else if (chan->f[i] > 1.0f) + dst->f[i] = 1.0f; + else + dst->i[i] = chan->i[i]; + } + break; + + case TGSI_SAT_MINUS_PLUS_ONE: + for (i = 0; i < QUAD_SIZE; i++) + if (execmask & (1 << i)) { + if (chan->f[i] < -1.0f) + dst->f[i] = -1.0f; + else if (chan->f[i] > 1.0f) + dst->f[i] = 1.0f; + else + dst->i[i] = chan->i[i]; + } + break; + + default: + assert( 0 ); + } +} + +#define FETCH(VAL,INDEX,CHAN)\ + fetch_source(mach, VAL, &inst->Src[INDEX], CHAN, TGSI_EXEC_DATA_FLOAT) + + +/** + * Execute ARB-style KIL which is predicated by a src register. + * Kill fragment if any of the four values is less than zero. + */ +static void +exec_kil(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + uint uniquemask; + uint chan_index; + uint kilmask = 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */ + union tgsi_exec_channel r[1]; + + /* This mask stores component bits that were already tested. */ + uniquemask = 0; + + for (chan_index = 0; chan_index < 4; chan_index++) + { + uint swizzle; + uint i; + + /* unswizzle channel */ + swizzle = tgsi_util_get_full_src_register_swizzle ( + &inst->Src[0], + chan_index); + + /* check if the component has not been already tested */ + if (uniquemask & (1 << swizzle)) + continue; + uniquemask |= 1 << swizzle; + + FETCH(&r[0], 0, chan_index); + for (i = 0; i < 4; i++) + if (r[0].f[i] < 0.0f) + kilmask |= 1 << i; + } + + mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0] |= kilmask; +} + +/** + * Execute NVIDIA-style KIL which is predicated by a condition code. + * Kill fragment if the condition code is TRUE. + */ +static void +exec_kilp(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + uint kilmask; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */ + + /* "unconditional" kil */ + kilmask = mach->ExecMask; + mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0] |= kilmask; +} + +static void +emit_vertex(struct tgsi_exec_machine *mach) +{ + /* FIXME: check for exec mask correctly + unsigned i; + for (i = 0; i < QUAD_SIZE; ++i) { + if ((mach->ExecMask & (1 << i))) + */ + if (mach->ExecMask) { + mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0] += mach->NumOutputs; + mach->Primitives[mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0]]++; + } +} + +static void +emit_primitive(struct tgsi_exec_machine *mach) +{ + unsigned *prim_count = &mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0]; + /* FIXME: check for exec mask correctly + unsigned i; + for (i = 0; i < QUAD_SIZE; ++i) { + if ((mach->ExecMask & (1 << i))) + */ + if (mach->ExecMask) { + ++(*prim_count); + debug_assert((*prim_count * mach->NumOutputs) < mach->MaxGeometryShaderOutputs); + mach->Primitives[*prim_count] = 0; + } +} + +static void +conditional_emit_primitive(struct tgsi_exec_machine *mach) +{ + if (TGSI_PROCESSOR_GEOMETRY == mach->Processor) { + int emitted_verts = + mach->Primitives[mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0]]; + if (emitted_verts) { + emit_primitive(mach); + } + } +} + + +/* + * Fetch four texture samples using STR texture coordinates. + */ +static void +fetch_texel( struct tgsi_sampler *sampler, + const union tgsi_exec_channel *s, + const union tgsi_exec_channel *t, + const union tgsi_exec_channel *p, + const union tgsi_exec_channel *c0, + enum tgsi_sampler_control control, + union tgsi_exec_channel *r, + union tgsi_exec_channel *g, + union tgsi_exec_channel *b, + union tgsi_exec_channel *a ) +{ + uint j; + float rgba[NUM_CHANNELS][QUAD_SIZE]; + + sampler->get_samples(sampler, s->f, t->f, p->f, c0->f, control, rgba); + + for (j = 0; j < 4; j++) { + r->f[j] = rgba[0][j]; + g->f[j] = rgba[1][j]; + b->f[j] = rgba[2][j]; + a->f[j] = rgba[3][j]; + } +} + + +#define TEX_MODIFIER_NONE 0 +#define TEX_MODIFIER_PROJECTED 1 +#define TEX_MODIFIER_LOD_BIAS 2 +#define TEX_MODIFIER_EXPLICIT_LOD 3 + + +static void +exec_tex(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst, + uint modifier) +{ + const uint unit = inst->Src[1].Register.Index; + union tgsi_exec_channel r[4]; + const union tgsi_exec_channel *lod = &ZeroVec; + enum tgsi_sampler_control control; + uint chan; + + if (modifier != TEX_MODIFIER_NONE) { + FETCH(&r[3], 0, CHAN_W); + if (modifier != TEX_MODIFIER_PROJECTED) { + lod = &r[3]; + } + } + + if (modifier == TEX_MODIFIER_EXPLICIT_LOD) { + control = tgsi_sampler_lod_explicit; + } else { + control = tgsi_sampler_lod_bias; + } + + switch (inst->Texture.Texture) { + case TGSI_TEXTURE_1D: + case TGSI_TEXTURE_SHADOW1D: + FETCH(&r[0], 0, CHAN_X); + + if (modifier == TEX_MODIFIER_PROJECTED) { + micro_div(&r[0], &r[0], &r[3]); + } + + fetch_texel(mach->Samplers[unit], + &r[0], &ZeroVec, &ZeroVec, lod, /* S, T, P, LOD */ + control, + &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */ + break; + + case TGSI_TEXTURE_2D: + case TGSI_TEXTURE_RECT: + case TGSI_TEXTURE_SHADOW2D: + case TGSI_TEXTURE_SHADOWRECT: + FETCH(&r[0], 0, CHAN_X); + FETCH(&r[1], 0, CHAN_Y); + FETCH(&r[2], 0, CHAN_Z); + + if (modifier == TEX_MODIFIER_PROJECTED) { + micro_div(&r[0], &r[0], &r[3]); + micro_div(&r[1], &r[1], &r[3]); + micro_div(&r[2], &r[2], &r[3]); + } + + fetch_texel(mach->Samplers[unit], + &r[0], &r[1], &r[2], lod, /* S, T, P, LOD */ + control, + &r[0], &r[1], &r[2], &r[3]); /* outputs */ + break; + + case TGSI_TEXTURE_3D: + case TGSI_TEXTURE_CUBE: + FETCH(&r[0], 0, CHAN_X); + FETCH(&r[1], 0, CHAN_Y); + FETCH(&r[2], 0, CHAN_Z); + + if (modifier == TEX_MODIFIER_PROJECTED) { + micro_div(&r[0], &r[0], &r[3]); + micro_div(&r[1], &r[1], &r[3]); + micro_div(&r[2], &r[2], &r[3]); + } + + fetch_texel(mach->Samplers[unit], + &r[0], &r[1], &r[2], lod, + control, + &r[0], &r[1], &r[2], &r[3]); + break; + + default: + assert(0); + } + + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT); + } + } +} + +static void +exec_txd(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + const uint unit = inst->Src[3].Register.Index; + union tgsi_exec_channel r[4]; + uint chan; + + /* + * XXX: This is fake TXD -- the derivatives are not taken into account, yet. + */ + + switch (inst->Texture.Texture) { + case TGSI_TEXTURE_1D: + case TGSI_TEXTURE_SHADOW1D: + + FETCH(&r[0], 0, CHAN_X); + + fetch_texel(mach->Samplers[unit], + &r[0], &ZeroVec, &ZeroVec, &ZeroVec, /* S, T, P, BIAS */ + tgsi_sampler_lod_bias, + &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */ + break; + + case TGSI_TEXTURE_2D: + case TGSI_TEXTURE_RECT: + case TGSI_TEXTURE_SHADOW2D: + case TGSI_TEXTURE_SHADOWRECT: + + FETCH(&r[0], 0, CHAN_X); + FETCH(&r[1], 0, CHAN_Y); + FETCH(&r[2], 0, CHAN_Z); + + fetch_texel(mach->Samplers[unit], + &r[0], &r[1], &r[2], &ZeroVec, /* inputs */ + tgsi_sampler_lod_bias, + &r[0], &r[1], &r[2], &r[3]); /* outputs */ + break; + + case TGSI_TEXTURE_3D: + case TGSI_TEXTURE_CUBE: + + FETCH(&r[0], 0, CHAN_X); + FETCH(&r[1], 0, CHAN_Y); + FETCH(&r[2], 0, CHAN_Z); + + fetch_texel(mach->Samplers[unit], + &r[0], &r[1], &r[2], &ZeroVec, + tgsi_sampler_lod_bias, + &r[0], &r[1], &r[2], &r[3]); + break; + + default: + assert(0); + } + + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT); + } + } +} + + +/** + * Evaluate a constant-valued coefficient at the position of the + * current quad. + */ +static void +eval_constant_coef( + struct tgsi_exec_machine *mach, + unsigned attrib, + unsigned chan ) +{ + unsigned i; + + for( i = 0; i < QUAD_SIZE; i++ ) { + mach->Inputs[attrib].xyzw[chan].f[i] = mach->InterpCoefs[attrib].a0[chan]; + } +} + +/** + * Evaluate a linear-valued coefficient at the position of the + * current quad. + */ +static void +eval_linear_coef( + struct tgsi_exec_machine *mach, + unsigned attrib, + unsigned chan ) +{ + const float x = mach->QuadPos.xyzw[0].f[0]; + const float y = mach->QuadPos.xyzw[1].f[0]; + const float dadx = mach->InterpCoefs[attrib].dadx[chan]; + const float dady = mach->InterpCoefs[attrib].dady[chan]; + const float a0 = mach->InterpCoefs[attrib].a0[chan] + dadx * x + dady * y; + mach->Inputs[attrib].xyzw[chan].f[0] = a0; + mach->Inputs[attrib].xyzw[chan].f[1] = a0 + dadx; + mach->Inputs[attrib].xyzw[chan].f[2] = a0 + dady; + mach->Inputs[attrib].xyzw[chan].f[3] = a0 + dadx + dady; +} + +/** + * Evaluate a perspective-valued coefficient at the position of the + * current quad. + */ +static void +eval_perspective_coef( + struct tgsi_exec_machine *mach, + unsigned attrib, + unsigned chan ) +{ + const float x = mach->QuadPos.xyzw[0].f[0]; + const float y = mach->QuadPos.xyzw[1].f[0]; + const float dadx = mach->InterpCoefs[attrib].dadx[chan]; + const float dady = mach->InterpCoefs[attrib].dady[chan]; + const float a0 = mach->InterpCoefs[attrib].a0[chan] + dadx * x + dady * y; + const float *w = mach->QuadPos.xyzw[3].f; + /* divide by W here */ + mach->Inputs[attrib].xyzw[chan].f[0] = a0 / w[0]; + mach->Inputs[attrib].xyzw[chan].f[1] = (a0 + dadx) / w[1]; + mach->Inputs[attrib].xyzw[chan].f[2] = (a0 + dady) / w[2]; + mach->Inputs[attrib].xyzw[chan].f[3] = (a0 + dadx + dady) / w[3]; +} + + +typedef void (* eval_coef_func)( + struct tgsi_exec_machine *mach, + unsigned attrib, + unsigned chan ); + +static void +exec_declaration(struct tgsi_exec_machine *mach, + const struct tgsi_full_declaration *decl) +{ + if (mach->Processor == TGSI_PROCESSOR_FRAGMENT) { + if (decl->Declaration.File == TGSI_FILE_INPUT || + decl->Declaration.File == TGSI_FILE_SYSTEM_VALUE) { + uint first, last, mask; + + first = decl->Range.First; + last = decl->Range.Last; + mask = decl->Declaration.UsageMask; + + /* XXX we could remove this special-case code since + * mach->InterpCoefs[first].a0 should already have the + * front/back-face value. But we should first update the + * ureg code to emit the right UsageMask value (WRITEMASK_X). + * Then, we could remove the tgsi_exec_machine::Face field. + */ + if (decl->Semantic.Name == TGSI_SEMANTIC_FACE) { + uint i; + + assert(decl->Semantic.Index == 0); + assert(first == last); + + for (i = 0; i < QUAD_SIZE; i++) { + mach->Inputs[first].xyzw[0].f[i] = mach->Face; + } + } else { + eval_coef_func eval; + uint i, j; + + switch (decl->Declaration.Interpolate) { + case TGSI_INTERPOLATE_CONSTANT: + eval = eval_constant_coef; + break; + + case TGSI_INTERPOLATE_LINEAR: + eval = eval_linear_coef; + break; + + case TGSI_INTERPOLATE_PERSPECTIVE: + eval = eval_perspective_coef; + break; + + default: + assert(0); + return; + } + + for (j = 0; j < NUM_CHANNELS; j++) { + if (mask & (1 << j)) { + for (i = first; i <= last; i++) { + eval(mach, i, j); + } + } + } + } + } + } +} + +typedef void (* micro_op)(union tgsi_exec_channel *dst); + +static void +exec_vector(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst, + micro_op op, + enum tgsi_exec_datatype dst_datatype) +{ + unsigned int chan; + + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + union tgsi_exec_channel dst; + + op(&dst); + store_dest(mach, &dst, &inst->Dst[0], inst, chan, dst_datatype); + } + } +} + +typedef void (* micro_unary_op)(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src); + +static void +exec_scalar_unary(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst, + micro_unary_op op, + enum tgsi_exec_datatype dst_datatype, + enum tgsi_exec_datatype src_datatype) +{ + unsigned int chan; + union tgsi_exec_channel src; + union tgsi_exec_channel dst; + + fetch_source(mach, &src, &inst->Src[0], CHAN_X, src_datatype); + op(&dst, &src); + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + store_dest(mach, &dst, &inst->Dst[0], inst, chan, dst_datatype); + } + } +} + +static void +exec_vector_unary(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst, + micro_unary_op op, + enum tgsi_exec_datatype dst_datatype, + enum tgsi_exec_datatype src_datatype) +{ + unsigned int chan; + struct tgsi_exec_vector dst; + + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + union tgsi_exec_channel src; + + fetch_source(mach, &src, &inst->Src[0], chan, src_datatype); + op(&dst.xyzw[chan], &src); + } + } + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + store_dest(mach, &dst.xyzw[chan], &inst->Dst[0], inst, chan, dst_datatype); + } + } +} + +typedef void (* micro_binary_op)(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1); + +static void +exec_scalar_binary(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst, + micro_binary_op op, + enum tgsi_exec_datatype dst_datatype, + enum tgsi_exec_datatype src_datatype) +{ + unsigned int chan; + union tgsi_exec_channel src[2]; + union tgsi_exec_channel dst; + + fetch_source(mach, &src[0], &inst->Src[0], CHAN_X, src_datatype); + fetch_source(mach, &src[1], &inst->Src[1], CHAN_Y, src_datatype); + op(&dst, &src[0], &src[1]); + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + store_dest(mach, &dst, &inst->Dst[0], inst, chan, dst_datatype); + } + } +} + +static void +exec_vector_binary(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst, + micro_binary_op op, + enum tgsi_exec_datatype dst_datatype, + enum tgsi_exec_datatype src_datatype) +{ + unsigned int chan; + struct tgsi_exec_vector dst; + + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + union tgsi_exec_channel src[2]; + + fetch_source(mach, &src[0], &inst->Src[0], chan, src_datatype); + fetch_source(mach, &src[1], &inst->Src[1], chan, src_datatype); + op(&dst.xyzw[chan], &src[0], &src[1]); + } + } + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + store_dest(mach, &dst.xyzw[chan], &inst->Dst[0], inst, chan, dst_datatype); + } + } +} + +typedef void (* micro_trinary_op)(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2); + +static void +exec_vector_trinary(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst, + micro_trinary_op op, + enum tgsi_exec_datatype dst_datatype, + enum tgsi_exec_datatype src_datatype) +{ + unsigned int chan; + struct tgsi_exec_vector dst; + + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + union tgsi_exec_channel src[3]; + + fetch_source(mach, &src[0], &inst->Src[0], chan, src_datatype); + fetch_source(mach, &src[1], &inst->Src[1], chan, src_datatype); + fetch_source(mach, &src[2], &inst->Src[2], chan, src_datatype); + op(&dst.xyzw[chan], &src[0], &src[1], &src[2]); + } + } + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + store_dest(mach, &dst.xyzw[chan], &inst->Dst[0], inst, chan, dst_datatype); + } + } +} + +static void +exec_dp3(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + unsigned int chan; + union tgsi_exec_channel arg[3]; + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &arg[1], &inst->Src[1], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_mul(&arg[2], &arg[0], &arg[1]); + + for (chan = CHAN_Y; chan <= CHAN_Z; chan++) { + fetch_source(mach, &arg[0], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &arg[1], &inst->Src[1], chan, TGSI_EXEC_DATA_FLOAT); + micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]); + } + + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + store_dest(mach, &arg[2], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT); + } + } +} + +static void +exec_dp4(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + unsigned int chan; + union tgsi_exec_channel arg[3]; + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &arg[1], &inst->Src[1], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_mul(&arg[2], &arg[0], &arg[1]); + + for (chan = CHAN_Y; chan <= CHAN_W; chan++) { + fetch_source(mach, &arg[0], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &arg[1], &inst->Src[1], chan, TGSI_EXEC_DATA_FLOAT); + micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]); + } + + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + store_dest(mach, &arg[2], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT); + } + } +} + +static void +exec_dp2a(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + unsigned int chan; + union tgsi_exec_channel arg[3]; + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &arg[1], &inst->Src[1], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_mul(&arg[2], &arg[0], &arg[1]); + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &arg[1], &inst->Src[1], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + micro_mad(&arg[0], &arg[0], &arg[1], &arg[2]); + + fetch_source(mach, &arg[1], &inst->Src[2], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_add(&arg[0], &arg[0], &arg[1]); + + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + store_dest(mach, &arg[0], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT); + } + } +} + +static void +exec_dph(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + unsigned int chan; + union tgsi_exec_channel arg[3]; + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &arg[1], &inst->Src[1], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_mul(&arg[2], &arg[0], &arg[1]); + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &arg[1], &inst->Src[1], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]); + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_Z, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &arg[1], &inst->Src[1], CHAN_Z, TGSI_EXEC_DATA_FLOAT); + micro_mad(&arg[0], &arg[0], &arg[1], &arg[2]); + + fetch_source(mach, &arg[1], &inst->Src[1], CHAN_W, TGSI_EXEC_DATA_FLOAT); + micro_add(&arg[0], &arg[0], &arg[1]); + + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + store_dest(mach, &arg[0], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT); + } + } +} + +static void +exec_dp2(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + unsigned int chan; + union tgsi_exec_channel arg[3]; + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &arg[1], &inst->Src[1], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_mul(&arg[2], &arg[0], &arg[1]); + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &arg[1], &inst->Src[1], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]); + + for (chan = 0; chan < NUM_CHANNELS; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + store_dest(mach, &arg[2], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT); + } + } +} + +static void +exec_nrm4(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + unsigned int chan; + union tgsi_exec_channel arg[4]; + union tgsi_exec_channel scale; + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_mul(&scale, &arg[0], &arg[0]); + + for (chan = CHAN_Y; chan <= CHAN_W; chan++) { + union tgsi_exec_channel product; + + fetch_source(mach, &arg[chan], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT); + micro_mul(&product, &arg[chan], &arg[chan]); + micro_add(&scale, &scale, &product); + } + + micro_rsq(&scale, &scale); + + for (chan = CHAN_X; chan <= CHAN_W; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + micro_mul(&arg[chan], &arg[chan], &scale); + store_dest(mach, &arg[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT); + } + } +} + +static void +exec_nrm3(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XYZ) { + unsigned int chan; + union tgsi_exec_channel arg[3]; + union tgsi_exec_channel scale; + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_mul(&scale, &arg[0], &arg[0]); + + for (chan = CHAN_Y; chan <= CHAN_Z; chan++) { + union tgsi_exec_channel product; + + fetch_source(mach, &arg[chan], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT); + micro_mul(&product, &arg[chan], &arg[chan]); + micro_add(&scale, &scale, &product); + } + + micro_rsq(&scale, &scale); + + for (chan = CHAN_X; chan <= CHAN_Z; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + micro_mul(&arg[chan], &arg[chan], &scale); + store_dest(mach, &arg[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT); + } + } + } + + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) { + store_dest(mach, &OneVec, &inst->Dst[0], inst, CHAN_W, TGSI_EXEC_DATA_FLOAT); + } +} + +static void +exec_scs(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XY) { + union tgsi_exec_channel arg; + union tgsi_exec_channel result; + + fetch_source(mach, &arg, &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) { + micro_cos(&result, &arg); + store_dest(mach, &result, &inst->Dst[0], inst, CHAN_X, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) { + micro_sin(&result, &arg); + store_dest(mach, &result, &inst->Dst[0], inst, CHAN_Y, TGSI_EXEC_DATA_FLOAT); + } + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) { + store_dest(mach, &ZeroVec, &inst->Dst[0], inst, CHAN_Z, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) { + store_dest(mach, &OneVec, &inst->Dst[0], inst, CHAN_W, TGSI_EXEC_DATA_FLOAT); + } +} + +static void +exec_x2d(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + union tgsi_exec_channel r[4]; + union tgsi_exec_channel d[2]; + + fetch_source(mach, &r[0], &inst->Src[1], CHAN_X, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &r[1], &inst->Src[1], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XZ) { + fetch_source(mach, &r[2], &inst->Src[2], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_mul(&r[2], &r[2], &r[0]); + fetch_source(mach, &r[3], &inst->Src[2], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + micro_mul(&r[3], &r[3], &r[1]); + micro_add(&r[2], &r[2], &r[3]); + fetch_source(mach, &r[3], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_add(&d[0], &r[2], &r[3]); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_YW) { + fetch_source(mach, &r[2], &inst->Src[2], CHAN_Z, TGSI_EXEC_DATA_FLOAT); + micro_mul(&r[2], &r[2], &r[0]); + fetch_source(mach, &r[3], &inst->Src[2], CHAN_W, TGSI_EXEC_DATA_FLOAT); + micro_mul(&r[3], &r[3], &r[1]); + micro_add(&r[2], &r[2], &r[3]); + fetch_source(mach, &r[3], &inst->Src[0], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + micro_add(&d[1], &r[2], &r[3]); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) { + store_dest(mach, &d[0], &inst->Dst[0], inst, CHAN_X, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) { + store_dest(mach, &d[1], &inst->Dst[0], inst, CHAN_Y, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) { + store_dest(mach, &d[0], &inst->Dst[0], inst, CHAN_Z, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) { + store_dest(mach, &d[1], &inst->Dst[0], inst, CHAN_W, TGSI_EXEC_DATA_FLOAT); + } +} + +static void +exec_rfl(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + union tgsi_exec_channel r[9]; + + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XYZ) { + /* r0 = dp3(src0, src0) */ + fetch_source(mach, &r[2], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_mul(&r[0], &r[2], &r[2]); + fetch_source(mach, &r[4], &inst->Src[0], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + micro_mul(&r[8], &r[4], &r[4]); + micro_add(&r[0], &r[0], &r[8]); + fetch_source(mach, &r[6], &inst->Src[0], CHAN_Z, TGSI_EXEC_DATA_FLOAT); + micro_mul(&r[8], &r[6], &r[6]); + micro_add(&r[0], &r[0], &r[8]); + + /* r1 = dp3(src0, src1) */ + fetch_source(mach, &r[3], &inst->Src[1], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_mul(&r[1], &r[2], &r[3]); + fetch_source(mach, &r[5], &inst->Src[1], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + micro_mul(&r[8], &r[4], &r[5]); + micro_add(&r[1], &r[1], &r[8]); + fetch_source(mach, &r[7], &inst->Src[1], CHAN_Z, TGSI_EXEC_DATA_FLOAT); + micro_mul(&r[8], &r[6], &r[7]); + micro_add(&r[1], &r[1], &r[8]); + + /* r1 = 2 * r1 / r0 */ + micro_add(&r[1], &r[1], &r[1]); + micro_div(&r[1], &r[1], &r[0]); + + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) { + micro_mul(&r[2], &r[2], &r[1]); + micro_sub(&r[2], &r[2], &r[3]); + store_dest(mach, &r[2], &inst->Dst[0], inst, CHAN_X, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) { + micro_mul(&r[4], &r[4], &r[1]); + micro_sub(&r[4], &r[4], &r[5]); + store_dest(mach, &r[4], &inst->Dst[0], inst, CHAN_Y, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) { + micro_mul(&r[6], &r[6], &r[1]); + micro_sub(&r[6], &r[6], &r[7]); + store_dest(mach, &r[6], &inst->Dst[0], inst, CHAN_Z, TGSI_EXEC_DATA_FLOAT); + } + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) { + store_dest(mach, &OneVec, &inst->Dst[0], inst, CHAN_W, TGSI_EXEC_DATA_FLOAT); + } +} + +static void +exec_xpd(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + union tgsi_exec_channel r[6]; + union tgsi_exec_channel d[3]; + + fetch_source(mach, &r[0], &inst->Src[0], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &r[1], &inst->Src[1], CHAN_Z, TGSI_EXEC_DATA_FLOAT); + + micro_mul(&r[2], &r[0], &r[1]); + + fetch_source(mach, &r[3], &inst->Src[0], CHAN_Z, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &r[4], &inst->Src[1], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + + micro_mul(&r[5], &r[3], &r[4] ); + micro_sub(&d[CHAN_X], &r[2], &r[5]); + + fetch_source(mach, &r[2], &inst->Src[1], CHAN_X, TGSI_EXEC_DATA_FLOAT); + + micro_mul(&r[3], &r[3], &r[2]); + + fetch_source(mach, &r[5], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + + micro_mul(&r[1], &r[1], &r[5]); + micro_sub(&d[CHAN_Y], &r[3], &r[1]); + + micro_mul(&r[5], &r[5], &r[4]); + micro_mul(&r[0], &r[0], &r[2]); + micro_sub(&d[CHAN_Z], &r[5], &r[0]); + + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) { + store_dest(mach, &d[CHAN_X], &inst->Dst[0], inst, CHAN_X, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) { + store_dest(mach, &d[CHAN_Y], &inst->Dst[0], inst, CHAN_Y, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) { + store_dest(mach, &d[CHAN_Z], &inst->Dst[0], inst, CHAN_Z, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) { + store_dest(mach, &OneVec, &inst->Dst[0], inst, CHAN_W, TGSI_EXEC_DATA_FLOAT); + } +} + +static void +exec_dst(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + union tgsi_exec_channel r[2]; + union tgsi_exec_channel d[4]; + + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) { + fetch_source(mach, &r[0], &inst->Src[0], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + fetch_source(mach, &r[1], &inst->Src[1], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + micro_mul(&d[CHAN_Y], &r[0], &r[1]); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) { + fetch_source(mach, &d[CHAN_Z], &inst->Src[0], CHAN_Z, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) { + fetch_source(mach, &d[CHAN_W], &inst->Src[1], CHAN_W, TGSI_EXEC_DATA_FLOAT); + } + + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) { + store_dest(mach, &OneVec, &inst->Dst[0], inst, CHAN_X, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) { + store_dest(mach, &d[CHAN_Y], &inst->Dst[0], inst, CHAN_Y, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) { + store_dest(mach, &d[CHAN_Z], &inst->Dst[0], inst, CHAN_Z, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) { + store_dest(mach, &d[CHAN_W], &inst->Dst[0], inst, CHAN_W, TGSI_EXEC_DATA_FLOAT); + } +} + +static void +exec_log(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + union tgsi_exec_channel r[3]; + + fetch_source(mach, &r[0], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_abs(&r[2], &r[0]); /* r2 = abs(r0) */ + micro_lg2(&r[1], &r[2]); /* r1 = lg2(r2) */ + micro_flr(&r[0], &r[1]); /* r0 = floor(r1) */ + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) { + store_dest(mach, &r[0], &inst->Dst[0], inst, CHAN_X, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) { + micro_exp2(&r[0], &r[0]); /* r0 = 2 ^ r0 */ + micro_div(&r[0], &r[2], &r[0]); /* r0 = r2 / r0 */ + store_dest(mach, &r[0], &inst->Dst[0], inst, CHAN_Y, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) { + store_dest(mach, &r[1], &inst->Dst[0], inst, CHAN_Z, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) { + store_dest(mach, &OneVec, &inst->Dst[0], inst, CHAN_W, TGSI_EXEC_DATA_FLOAT); + } +} + +static void +exec_exp(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + union tgsi_exec_channel r[3]; + + fetch_source(mach, &r[0], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_flr(&r[1], &r[0]); /* r1 = floor(r0) */ + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) { + micro_exp2(&r[2], &r[1]); /* r2 = 2 ^ r1 */ + store_dest(mach, &r[2], &inst->Dst[0], inst, CHAN_X, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) { + micro_sub(&r[2], &r[0], &r[1]); /* r2 = r0 - r1 */ + store_dest(mach, &r[2], &inst->Dst[0], inst, CHAN_Y, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) { + micro_exp2(&r[2], &r[0]); /* r2 = 2 ^ r0 */ + store_dest(mach, &r[2], &inst->Dst[0], inst, CHAN_Z, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) { + store_dest(mach, &OneVec, &inst->Dst[0], inst, CHAN_W, TGSI_EXEC_DATA_FLOAT); + } +} + +static void +exec_lit(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + union tgsi_exec_channel r[3]; + union tgsi_exec_channel d[3]; + + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) { + store_dest(mach, &OneVec, &inst->Dst[0], inst, CHAN_X, TGSI_EXEC_DATA_FLOAT); + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_YZ) { + fetch_source(mach, &r[0], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) { + micro_max(&d[CHAN_Y], &r[0], &ZeroVec); + store_dest(mach, &d[CHAN_Y], &inst->Dst[0], inst, CHAN_Y, TGSI_EXEC_DATA_FLOAT); + } + + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) { + fetch_source(mach, &r[1], &inst->Src[0], CHAN_Y, TGSI_EXEC_DATA_FLOAT); + micro_max(&r[1], &r[1], &ZeroVec); + + fetch_source(mach, &r[2], &inst->Src[0], CHAN_W, TGSI_EXEC_DATA_FLOAT); + micro_min(&r[2], &r[2], &P128Vec); + micro_max(&r[2], &r[2], &M128Vec); + micro_pow(&r[1], &r[1], &r[2]); + micro_lt(&d[CHAN_Z], &ZeroVec, &r[0], &r[1], &ZeroVec); + store_dest(mach, &d[CHAN_Z], &inst->Dst[0], inst, CHAN_Z, TGSI_EXEC_DATA_FLOAT); + } + } + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) { + store_dest(mach, &OneVec, &inst->Dst[0], inst, CHAN_W, TGSI_EXEC_DATA_FLOAT); + } +} + +static void +exec_break(struct tgsi_exec_machine *mach) +{ + if (mach->BreakType == TGSI_EXEC_BREAK_INSIDE_LOOP) { + /* turn off loop channels for each enabled exec channel */ + mach->LoopMask &= ~mach->ExecMask; + /* Todo: if mach->LoopMask == 0, jump to end of loop */ + UPDATE_EXEC_MASK(mach); + } else { + assert(mach->BreakType == TGSI_EXEC_BREAK_INSIDE_SWITCH); + + mach->Switch.mask = 0x0; + + UPDATE_EXEC_MASK(mach); + } +} + +static void +exec_switch(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + assert(mach->SwitchStackTop < TGSI_EXEC_MAX_SWITCH_NESTING); + assert(mach->BreakStackTop < TGSI_EXEC_MAX_BREAK_STACK); + + mach->SwitchStack[mach->SwitchStackTop++] = mach->Switch; + fetch_source(mach, &mach->Switch.selector, &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_UINT); + mach->Switch.mask = 0x0; + mach->Switch.defaultMask = 0x0; + + mach->BreakStack[mach->BreakStackTop++] = mach->BreakType; + mach->BreakType = TGSI_EXEC_BREAK_INSIDE_SWITCH; + + UPDATE_EXEC_MASK(mach); +} + +static void +exec_case(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + uint prevMask = mach->SwitchStack[mach->SwitchStackTop - 1].mask; + union tgsi_exec_channel src; + uint mask = 0; + + fetch_source(mach, &src, &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_UINT); + + if (mach->Switch.selector.u[0] == src.u[0]) { + mask |= 0x1; + } + if (mach->Switch.selector.u[1] == src.u[1]) { + mask |= 0x2; + } + if (mach->Switch.selector.u[2] == src.u[2]) { + mask |= 0x4; + } + if (mach->Switch.selector.u[3] == src.u[3]) { + mask |= 0x8; + } + + mach->Switch.defaultMask |= mask; + + mach->Switch.mask |= mask & prevMask; + + UPDATE_EXEC_MASK(mach); +} + +static void +exec_default(struct tgsi_exec_machine *mach) +{ + uint prevMask = mach->SwitchStack[mach->SwitchStackTop - 1].mask; + + mach->Switch.mask |= ~mach->Switch.defaultMask & prevMask; + + UPDATE_EXEC_MASK(mach); +} + +static void +exec_endswitch(struct tgsi_exec_machine *mach) +{ + mach->Switch = mach->SwitchStack[--mach->SwitchStackTop]; + mach->BreakType = mach->BreakStack[--mach->BreakStackTop]; + + UPDATE_EXEC_MASK(mach); +} + +static void +micro_i2f(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->f[0] = (float)src->i[0]; + dst->f[1] = (float)src->i[1]; + dst->f[2] = (float)src->i[2]; + dst->f[3] = (float)src->i[3]; +} + +static void +micro_not(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->u[0] = ~src->u[0]; + dst->u[1] = ~src->u[1]; + dst->u[2] = ~src->u[2]; + dst->u[3] = ~src->u[3]; +} + +static void +micro_shl(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] << src1->u[0]; + dst->u[1] = src0->u[1] << src1->u[1]; + dst->u[2] = src0->u[2] << src1->u[2]; + dst->u[3] = src0->u[3] << src1->u[3]; +} + +static void +micro_and(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] & src1->u[0]; + dst->u[1] = src0->u[1] & src1->u[1]; + dst->u[2] = src0->u[2] & src1->u[2]; + dst->u[3] = src0->u[3] & src1->u[3]; +} + +static void +micro_or(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] | src1->u[0]; + dst->u[1] = src0->u[1] | src1->u[1]; + dst->u[2] = src0->u[2] | src1->u[2]; + dst->u[3] = src0->u[3] | src1->u[3]; +} + +static void +micro_xor(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] ^ src1->u[0]; + dst->u[1] = src0->u[1] ^ src1->u[1]; + dst->u[2] = src0->u[2] ^ src1->u[2]; + dst->u[3] = src0->u[3] ^ src1->u[3]; +} + +static void +micro_f2i(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->i[0] = (int)src->f[0]; + dst->i[1] = (int)src->f[1]; + dst->i[2] = (int)src->f[2]; + dst->i[3] = (int)src->f[3]; +} + +static void +micro_idiv(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->i[0] = src0->i[0] / src1->i[0]; + dst->i[1] = src0->i[1] / src1->i[1]; + dst->i[2] = src0->i[2] / src1->i[2]; + dst->i[3] = src0->i[3] / src1->i[3]; +} + +static void +micro_imax(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->i[0] = src0->i[0] > src1->i[0] ? src0->i[0] : src1->i[0]; + dst->i[1] = src0->i[1] > src1->i[1] ? src0->i[1] : src1->i[1]; + dst->i[2] = src0->i[2] > src1->i[2] ? src0->i[2] : src1->i[2]; + dst->i[3] = src0->i[3] > src1->i[3] ? src0->i[3] : src1->i[3]; +} + +static void +micro_imin(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->i[0] = src0->i[0] < src1->i[0] ? src0->i[0] : src1->i[0]; + dst->i[1] = src0->i[1] < src1->i[1] ? src0->i[1] : src1->i[1]; + dst->i[2] = src0->i[2] < src1->i[2] ? src0->i[2] : src1->i[2]; + dst->i[3] = src0->i[3] < src1->i[3] ? src0->i[3] : src1->i[3]; +} + +static void +micro_isge(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->i[0] = src0->i[0] >= src1->i[0] ? -1 : 0; + dst->i[1] = src0->i[1] >= src1->i[1] ? -1 : 0; + dst->i[2] = src0->i[2] >= src1->i[2] ? -1 : 0; + dst->i[3] = src0->i[3] >= src1->i[3] ? -1 : 0; +} + +static void +micro_ishr(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->i[0] = src0->i[0] >> src1->i[0]; + dst->i[1] = src0->i[1] >> src1->i[1]; + dst->i[2] = src0->i[2] >> src1->i[2]; + dst->i[3] = src0->i[3] >> src1->i[3]; +} + +static void +micro_islt(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->i[0] = src0->i[0] < src1->i[0] ? -1 : 0; + dst->i[1] = src0->i[1] < src1->i[1] ? -1 : 0; + dst->i[2] = src0->i[2] < src1->i[2] ? -1 : 0; + dst->i[3] = src0->i[3] < src1->i[3] ? -1 : 0; +} + +static void +micro_f2u(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->u[0] = (uint)src->f[0]; + dst->u[1] = (uint)src->f[1]; + dst->u[2] = (uint)src->f[2]; + dst->u[3] = (uint)src->f[3]; +} + +static void +micro_u2f(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src) +{ + dst->f[0] = (float)src->u[0]; + dst->f[1] = (float)src->u[1]; + dst->f[2] = (float)src->u[2]; + dst->f[3] = (float)src->u[3]; +} + +static void +micro_uadd(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] + src1->u[0]; + dst->u[1] = src0->u[1] + src1->u[1]; + dst->u[2] = src0->u[2] + src1->u[2]; + dst->u[3] = src0->u[3] + src1->u[3]; +} + +static void +micro_udiv(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] / src1->u[0]; + dst->u[1] = src0->u[1] / src1->u[1]; + dst->u[2] = src0->u[2] / src1->u[2]; + dst->u[3] = src0->u[3] / src1->u[3]; +} + +static void +micro_umad(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) +{ + dst->u[0] = src0->u[0] * src1->u[0] + src2->u[0]; + dst->u[1] = src0->u[1] * src1->u[1] + src2->u[1]; + dst->u[2] = src0->u[2] * src1->u[2] + src2->u[2]; + dst->u[3] = src0->u[3] * src1->u[3] + src2->u[3]; +} + +static void +micro_umax(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] > src1->u[0] ? src0->u[0] : src1->u[0]; + dst->u[1] = src0->u[1] > src1->u[1] ? src0->u[1] : src1->u[1]; + dst->u[2] = src0->u[2] > src1->u[2] ? src0->u[2] : src1->u[2]; + dst->u[3] = src0->u[3] > src1->u[3] ? src0->u[3] : src1->u[3]; +} + +static void +micro_umin(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] < src1->u[0] ? src0->u[0] : src1->u[0]; + dst->u[1] = src0->u[1] < src1->u[1] ? src0->u[1] : src1->u[1]; + dst->u[2] = src0->u[2] < src1->u[2] ? src0->u[2] : src1->u[2]; + dst->u[3] = src0->u[3] < src1->u[3] ? src0->u[3] : src1->u[3]; +} + +static void +micro_umod(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] % src1->u[0]; + dst->u[1] = src0->u[1] % src1->u[1]; + dst->u[2] = src0->u[2] % src1->u[2]; + dst->u[3] = src0->u[3] % src1->u[3]; +} + +static void +micro_umul(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] * src1->u[0]; + dst->u[1] = src0->u[1] * src1->u[1]; + dst->u[2] = src0->u[2] * src1->u[2]; + dst->u[3] = src0->u[3] * src1->u[3]; +} + +static void +micro_useq(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] == src1->u[0] ? ~0 : 0; + dst->u[1] = src0->u[1] == src1->u[1] ? ~0 : 0; + dst->u[2] = src0->u[2] == src1->u[2] ? ~0 : 0; + dst->u[3] = src0->u[3] == src1->u[3] ? ~0 : 0; +} + +static void +micro_usge(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] >= src1->u[0] ? ~0 : 0; + dst->u[1] = src0->u[1] >= src1->u[1] ? ~0 : 0; + dst->u[2] = src0->u[2] >= src1->u[2] ? ~0 : 0; + dst->u[3] = src0->u[3] >= src1->u[3] ? ~0 : 0; +} + +static void +micro_ushr(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] >> src1->u[0]; + dst->u[1] = src0->u[1] >> src1->u[1]; + dst->u[2] = src0->u[2] >> src1->u[2]; + dst->u[3] = src0->u[3] >> src1->u[3]; +} + +static void +micro_uslt(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] < src1->u[0] ? ~0 : 0; + dst->u[1] = src0->u[1] < src1->u[1] ? ~0 : 0; + dst->u[2] = src0->u[2] < src1->u[2] ? ~0 : 0; + dst->u[3] = src0->u[3] < src1->u[3] ? ~0 : 0; +} + +static void +micro_usne(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) +{ + dst->u[0] = src0->u[0] != src1->u[0] ? ~0 : 0; + dst->u[1] = src0->u[1] != src1->u[1] ? ~0 : 0; + dst->u[2] = src0->u[2] != src1->u[2] ? ~0 : 0; + dst->u[3] = src0->u[3] != src1->u[3] ? ~0 : 0; +} + +static void +exec_instruction( + struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst, + int *pc ) +{ + union tgsi_exec_channel r[10]; + + (*pc)++; + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_ARL: + exec_vector_unary(mach, inst, micro_arl, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_MOV: + exec_vector_unary(mach, inst, micro_mov, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_LIT: + exec_lit(mach, inst); + break; + + case TGSI_OPCODE_RCP: + exec_scalar_unary(mach, inst, micro_rcp, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_RSQ: + exec_scalar_unary(mach, inst, micro_rsq, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_EXP: + exec_exp(mach, inst); + break; + + case TGSI_OPCODE_LOG: + exec_log(mach, inst); + break; + + case TGSI_OPCODE_MUL: + exec_vector_binary(mach, inst, micro_mul, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_ADD: + exec_vector_binary(mach, inst, micro_add, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_DP3: + exec_dp3(mach, inst); + break; + + case TGSI_OPCODE_DP4: + exec_dp4(mach, inst); + break; + + case TGSI_OPCODE_DST: + exec_dst(mach, inst); + break; + + case TGSI_OPCODE_MIN: + exec_vector_binary(mach, inst, micro_min, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_MAX: + exec_vector_binary(mach, inst, micro_max, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_SLT: + exec_vector_binary(mach, inst, micro_slt, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_SGE: + exec_vector_binary(mach, inst, micro_sge, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_MAD: + exec_vector_trinary(mach, inst, micro_mad, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_SUB: + exec_vector_binary(mach, inst, micro_sub, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_LRP: + exec_vector_trinary(mach, inst, micro_lrp, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_CND: + exec_vector_trinary(mach, inst, micro_cnd, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_DP2A: + exec_dp2a(mach, inst); + break; + + case TGSI_OPCODE_FRC: + exec_vector_unary(mach, inst, micro_frc, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_CLAMP: + exec_vector_trinary(mach, inst, micro_clamp, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_FLR: + exec_vector_unary(mach, inst, micro_flr, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_ROUND: + exec_vector_unary(mach, inst, micro_rnd, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_EX2: + exec_scalar_unary(mach, inst, micro_exp2, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_LG2: + exec_scalar_unary(mach, inst, micro_lg2, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_POW: + exec_scalar_binary(mach, inst, micro_pow, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_XPD: + exec_xpd(mach, inst); + break; + + case TGSI_OPCODE_ABS: + exec_vector_unary(mach, inst, micro_abs, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_RCC: + exec_scalar_unary(mach, inst, micro_rcc, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_DPH: + exec_dph(mach, inst); + break; + + case TGSI_OPCODE_COS: + exec_scalar_unary(mach, inst, micro_cos, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_DDX: + exec_vector_unary(mach, inst, micro_ddx, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_DDY: + exec_vector_unary(mach, inst, micro_ddy, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_KILP: + exec_kilp (mach, inst); + break; + + case TGSI_OPCODE_KIL: + exec_kil (mach, inst); + break; + + case TGSI_OPCODE_PK2H: + assert (0); + break; + + case TGSI_OPCODE_PK2US: + assert (0); + break; + + case TGSI_OPCODE_PK4B: + assert (0); + break; + + case TGSI_OPCODE_PK4UB: + assert (0); + break; + + case TGSI_OPCODE_RFL: + exec_rfl(mach, inst); + break; + + case TGSI_OPCODE_SEQ: + exec_vector_binary(mach, inst, micro_seq, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_SFL: + exec_vector(mach, inst, micro_sfl, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_SGT: + exec_vector_binary(mach, inst, micro_sgt, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_SIN: + exec_scalar_unary(mach, inst, micro_sin, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_SLE: + exec_vector_binary(mach, inst, micro_sle, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_SNE: + exec_vector_binary(mach, inst, micro_sne, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_STR: + exec_vector(mach, inst, micro_str, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_TEX: + /* simple texture lookup */ + /* src[0] = texcoord */ + /* src[1] = sampler unit */ + exec_tex(mach, inst, TEX_MODIFIER_NONE); + break; + + case TGSI_OPCODE_TXB: + /* Texture lookup with lod bias */ + /* src[0] = texcoord (src[0].w = LOD bias) */ + /* src[1] = sampler unit */ + exec_tex(mach, inst, TEX_MODIFIER_LOD_BIAS); + break; + + case TGSI_OPCODE_TXD: + /* Texture lookup with explict partial derivatives */ + /* src[0] = texcoord */ + /* src[1] = d[strq]/dx */ + /* src[2] = d[strq]/dy */ + /* src[3] = sampler unit */ + exec_txd(mach, inst); + break; + + case TGSI_OPCODE_TXL: + /* Texture lookup with explit LOD */ + /* src[0] = texcoord (src[0].w = LOD) */ + /* src[1] = sampler unit */ + exec_tex(mach, inst, TEX_MODIFIER_EXPLICIT_LOD); + break; + + case TGSI_OPCODE_TXP: + /* Texture lookup with projection */ + /* src[0] = texcoord (src[0].w = projection) */ + /* src[1] = sampler unit */ + exec_tex(mach, inst, TEX_MODIFIER_PROJECTED); + break; + + case TGSI_OPCODE_UP2H: + assert (0); + break; + + case TGSI_OPCODE_UP2US: + assert (0); + break; + + case TGSI_OPCODE_UP4B: + assert (0); + break; + + case TGSI_OPCODE_UP4UB: + assert (0); + break; + + case TGSI_OPCODE_X2D: + exec_x2d(mach, inst); + break; + + case TGSI_OPCODE_ARA: + assert (0); + break; + + case TGSI_OPCODE_ARR: + exec_vector_unary(mach, inst, micro_arr, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_BRA: + assert (0); + break; + + case TGSI_OPCODE_CAL: + /* skip the call if no execution channels are enabled */ + if (mach->ExecMask) { + /* do the call */ + + /* First, record the depths of the execution stacks. + * This is important for deeply nested/looped return statements. + * We have to unwind the stacks by the correct amount. For a + * real code generator, we could determine the number of entries + * to pop off each stack with simple static analysis and avoid + * implementing this data structure at run time. + */ + mach->CallStack[mach->CallStackTop].CondStackTop = mach->CondStackTop; + mach->CallStack[mach->CallStackTop].LoopStackTop = mach->LoopStackTop; + mach->CallStack[mach->CallStackTop].ContStackTop = mach->ContStackTop; + mach->CallStack[mach->CallStackTop].SwitchStackTop = mach->SwitchStackTop; + mach->CallStack[mach->CallStackTop].BreakStackTop = mach->BreakStackTop; + /* note that PC was already incremented above */ + mach->CallStack[mach->CallStackTop].ReturnAddr = *pc; + + mach->CallStackTop++; + + /* Second, push the Cond, Loop, Cont, Func stacks */ + assert(mach->CondStackTop < TGSI_EXEC_MAX_COND_NESTING); + assert(mach->LoopStackTop < TGSI_EXEC_MAX_LOOP_NESTING); + assert(mach->ContStackTop < TGSI_EXEC_MAX_LOOP_NESTING); + assert(mach->SwitchStackTop < TGSI_EXEC_MAX_SWITCH_NESTING); + assert(mach->BreakStackTop < TGSI_EXEC_MAX_BREAK_STACK); + assert(mach->FuncStackTop < TGSI_EXEC_MAX_CALL_NESTING); + + mach->CondStack[mach->CondStackTop++] = mach->CondMask; + mach->LoopStack[mach->LoopStackTop++] = mach->LoopMask; + mach->ContStack[mach->ContStackTop++] = mach->ContMask; + mach->SwitchStack[mach->SwitchStackTop++] = mach->Switch; + mach->BreakStack[mach->BreakStackTop++] = mach->BreakType; + mach->FuncStack[mach->FuncStackTop++] = mach->FuncMask; + + /* Finally, jump to the subroutine */ + *pc = inst->Label.Label; + } + break; + + case TGSI_OPCODE_RET: + mach->FuncMask &= ~mach->ExecMask; + UPDATE_EXEC_MASK(mach); + + if (mach->FuncMask == 0x0) { + /* really return now (otherwise, keep executing */ + + if (mach->CallStackTop == 0) { + /* returning from main() */ + mach->CondStackTop = 0; + mach->LoopStackTop = 0; + *pc = -1; + return; + } + + assert(mach->CallStackTop > 0); + mach->CallStackTop--; + + mach->CondStackTop = mach->CallStack[mach->CallStackTop].CondStackTop; + mach->CondMask = mach->CondStack[mach->CondStackTop]; + + mach->LoopStackTop = mach->CallStack[mach->CallStackTop].LoopStackTop; + mach->LoopMask = mach->LoopStack[mach->LoopStackTop]; + + mach->ContStackTop = mach->CallStack[mach->CallStackTop].ContStackTop; + mach->ContMask = mach->ContStack[mach->ContStackTop]; + + mach->SwitchStackTop = mach->CallStack[mach->CallStackTop].SwitchStackTop; + mach->Switch = mach->SwitchStack[mach->SwitchStackTop]; + + mach->BreakStackTop = mach->CallStack[mach->CallStackTop].BreakStackTop; + mach->BreakType = mach->BreakStack[mach->BreakStackTop]; + + assert(mach->FuncStackTop > 0); + mach->FuncMask = mach->FuncStack[--mach->FuncStackTop]; + + *pc = mach->CallStack[mach->CallStackTop].ReturnAddr; + + UPDATE_EXEC_MASK(mach); + } + break; + + case TGSI_OPCODE_SSG: + exec_vector_unary(mach, inst, micro_sgn, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_CMP: + exec_vector_trinary(mach, inst, micro_cmp, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_SCS: + exec_scs(mach, inst); + break; + + case TGSI_OPCODE_NRM: + exec_nrm3(mach, inst); + break; + + case TGSI_OPCODE_NRM4: + exec_nrm4(mach, inst); + break; + + case TGSI_OPCODE_DIV: + exec_vector_binary(mach, inst, micro_div, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_DP2: + exec_dp2(mach, inst); + break; + + case TGSI_OPCODE_IF: + /* push CondMask */ + assert(mach->CondStackTop < TGSI_EXEC_MAX_COND_NESTING); + mach->CondStack[mach->CondStackTop++] = mach->CondMask; + FETCH( &r[0], 0, CHAN_X ); + /* update CondMask */ + if( ! r[0].u[0] ) { + mach->CondMask &= ~0x1; + } + if( ! r[0].u[1] ) { + mach->CondMask &= ~0x2; + } + if( ! r[0].u[2] ) { + mach->CondMask &= ~0x4; + } + if( ! r[0].u[3] ) { + mach->CondMask &= ~0x8; + } + UPDATE_EXEC_MASK(mach); + /* Todo: If CondMask==0, jump to ELSE */ + break; + + case TGSI_OPCODE_ELSE: + /* invert CondMask wrt previous mask */ + { + uint prevMask; + assert(mach->CondStackTop > 0); + prevMask = mach->CondStack[mach->CondStackTop - 1]; + mach->CondMask = ~mach->CondMask & prevMask; + UPDATE_EXEC_MASK(mach); + /* Todo: If CondMask==0, jump to ENDIF */ + } + break; + + case TGSI_OPCODE_ENDIF: + /* pop CondMask */ + assert(mach->CondStackTop > 0); + mach->CondMask = mach->CondStack[--mach->CondStackTop]; + UPDATE_EXEC_MASK(mach); + break; + + case TGSI_OPCODE_END: + /* make sure we end primitives which haven't + * been explicitly emitted */ + conditional_emit_primitive(mach); + /* halt execution */ + *pc = -1; + break; + + case TGSI_OPCODE_PUSHA: + assert (0); + break; + + case TGSI_OPCODE_POPA: + assert (0); + break; + + case TGSI_OPCODE_CEIL: + exec_vector_unary(mach, inst, micro_ceil, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_I2F: + exec_vector_unary(mach, inst, micro_i2f, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_INT); + break; + + case TGSI_OPCODE_NOT: + exec_vector_unary(mach, inst, micro_not, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_TRUNC: + exec_vector_unary(mach, inst, micro_trunc, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_SHL: + exec_vector_binary(mach, inst, micro_shl, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_AND: + exec_vector_binary(mach, inst, micro_and, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_OR: + exec_vector_binary(mach, inst, micro_or, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_MOD: + assert (0); + break; + + case TGSI_OPCODE_XOR: + exec_vector_binary(mach, inst, micro_xor, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_SAD: + assert (0); + break; + + case TGSI_OPCODE_TXF: + assert (0); + break; + + case TGSI_OPCODE_TXQ: + assert (0); + break; + + case TGSI_OPCODE_EMIT: + emit_vertex(mach); + break; + + case TGSI_OPCODE_ENDPRIM: + emit_primitive(mach); + break; + + case TGSI_OPCODE_BGNLOOP: + /* push LoopMask and ContMasks */ + assert(mach->LoopStackTop < TGSI_EXEC_MAX_LOOP_NESTING); + assert(mach->ContStackTop < TGSI_EXEC_MAX_LOOP_NESTING); + assert(mach->LoopLabelStackTop < TGSI_EXEC_MAX_LOOP_NESTING); + assert(mach->BreakStackTop < TGSI_EXEC_MAX_BREAK_STACK); + + mach->LoopStack[mach->LoopStackTop++] = mach->LoopMask; + mach->ContStack[mach->ContStackTop++] = mach->ContMask; + mach->LoopLabelStack[mach->LoopLabelStackTop++] = *pc - 1; + mach->BreakStack[mach->BreakStackTop++] = mach->BreakType; + mach->BreakType = TGSI_EXEC_BREAK_INSIDE_LOOP; + break; + + case TGSI_OPCODE_ENDLOOP: + /* Restore ContMask, but don't pop */ + assert(mach->ContStackTop > 0); + mach->ContMask = mach->ContStack[mach->ContStackTop - 1]; + UPDATE_EXEC_MASK(mach); + if (mach->ExecMask) { + /* repeat loop: jump to instruction just past BGNLOOP */ + assert(mach->LoopLabelStackTop > 0); + *pc = mach->LoopLabelStack[mach->LoopLabelStackTop - 1] + 1; + } + else { + /* exit loop: pop LoopMask */ + assert(mach->LoopStackTop > 0); + mach->LoopMask = mach->LoopStack[--mach->LoopStackTop]; + /* pop ContMask */ + assert(mach->ContStackTop > 0); + mach->ContMask = mach->ContStack[--mach->ContStackTop]; + assert(mach->LoopLabelStackTop > 0); + --mach->LoopLabelStackTop; + + mach->BreakType = mach->BreakStack[--mach->BreakStackTop]; + } + UPDATE_EXEC_MASK(mach); + break; + + case TGSI_OPCODE_BRK: + exec_break(mach); + break; + + case TGSI_OPCODE_CONT: + /* turn off cont channels for each enabled exec channel */ + mach->ContMask &= ~mach->ExecMask; + /* Todo: if mach->LoopMask == 0, jump to end of loop */ + UPDATE_EXEC_MASK(mach); + break; + + case TGSI_OPCODE_BGNSUB: + /* no-op */ + break; + + case TGSI_OPCODE_ENDSUB: + /* + * XXX: This really should be a no-op. We should never reach this opcode. + */ + + assert(mach->CallStackTop > 0); + mach->CallStackTop--; + + mach->CondStackTop = mach->CallStack[mach->CallStackTop].CondStackTop; + mach->CondMask = mach->CondStack[mach->CondStackTop]; + + mach->LoopStackTop = mach->CallStack[mach->CallStackTop].LoopStackTop; + mach->LoopMask = mach->LoopStack[mach->LoopStackTop]; + + mach->ContStackTop = mach->CallStack[mach->CallStackTop].ContStackTop; + mach->ContMask = mach->ContStack[mach->ContStackTop]; + + mach->SwitchStackTop = mach->CallStack[mach->CallStackTop].SwitchStackTop; + mach->Switch = mach->SwitchStack[mach->SwitchStackTop]; + + mach->BreakStackTop = mach->CallStack[mach->CallStackTop].BreakStackTop; + mach->BreakType = mach->BreakStack[mach->BreakStackTop]; + + assert(mach->FuncStackTop > 0); + mach->FuncMask = mach->FuncStack[--mach->FuncStackTop]; + + *pc = mach->CallStack[mach->CallStackTop].ReturnAddr; + + UPDATE_EXEC_MASK(mach); + break; + + case TGSI_OPCODE_NOP: + break; + + case TGSI_OPCODE_BREAKC: + FETCH(&r[0], 0, CHAN_X); + /* update CondMask */ + if (r[0].u[0] && (mach->ExecMask & 0x1)) { + mach->LoopMask &= ~0x1; + } + if (r[0].u[1] && (mach->ExecMask & 0x2)) { + mach->LoopMask &= ~0x2; + } + if (r[0].u[2] && (mach->ExecMask & 0x4)) { + mach->LoopMask &= ~0x4; + } + if (r[0].u[3] && (mach->ExecMask & 0x8)) { + mach->LoopMask &= ~0x8; + } + /* Todo: if mach->LoopMask == 0, jump to end of loop */ + UPDATE_EXEC_MASK(mach); + break; + + case TGSI_OPCODE_F2I: + exec_vector_unary(mach, inst, micro_f2i, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_IDIV: + exec_vector_binary(mach, inst, micro_idiv, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT); + break; + + case TGSI_OPCODE_IMAX: + exec_vector_binary(mach, inst, micro_imax, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT); + break; + + case TGSI_OPCODE_IMIN: + exec_vector_binary(mach, inst, micro_imin, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT); + break; + + case TGSI_OPCODE_INEG: + exec_vector_unary(mach, inst, micro_ineg, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT); + break; + + case TGSI_OPCODE_ISGE: + exec_vector_binary(mach, inst, micro_isge, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT); + break; + + case TGSI_OPCODE_ISHR: + exec_vector_binary(mach, inst, micro_ishr, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT); + break; + + case TGSI_OPCODE_ISLT: + exec_vector_binary(mach, inst, micro_islt, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT); + break; + + case TGSI_OPCODE_F2U: + exec_vector_unary(mach, inst, micro_f2u, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_FLOAT); + break; + + case TGSI_OPCODE_U2F: + exec_vector_unary(mach, inst, micro_u2f, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_UADD: + exec_vector_binary(mach, inst, micro_uadd, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_UDIV: + exec_vector_binary(mach, inst, micro_udiv, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_UMAD: + exec_vector_trinary(mach, inst, micro_umad, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_UMAX: + exec_vector_binary(mach, inst, micro_umax, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_UMIN: + exec_vector_binary(mach, inst, micro_umin, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_UMOD: + exec_vector_binary(mach, inst, micro_umod, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_UMUL: + exec_vector_binary(mach, inst, micro_umul, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_USEQ: + exec_vector_binary(mach, inst, micro_useq, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_USGE: + exec_vector_binary(mach, inst, micro_usge, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_USHR: + exec_vector_binary(mach, inst, micro_ushr, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_USLT: + exec_vector_binary(mach, inst, micro_uslt, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_USNE: + exec_vector_binary(mach, inst, micro_usne, TGSI_EXEC_DATA_UINT, TGSI_EXEC_DATA_UINT); + break; + + case TGSI_OPCODE_SWITCH: + exec_switch(mach, inst); + break; + + case TGSI_OPCODE_CASE: + exec_case(mach, inst); + break; + + case TGSI_OPCODE_DEFAULT: + exec_default(mach); + break; + + case TGSI_OPCODE_ENDSWITCH: + exec_endswitch(mach); + break; + + default: + assert( 0 ); + } +} + + +#define DEBUG_EXECUTION 0 + + +/** + * Run TGSI interpreter. + * \return bitmask of "alive" quad components + */ +uint +tgsi_exec_machine_run( struct tgsi_exec_machine *mach ) +{ + uint i; + int pc = 0; + + mach->CondMask = 0xf; + mach->LoopMask = 0xf; + mach->ContMask = 0xf; + mach->FuncMask = 0xf; + mach->ExecMask = 0xf; + + mach->Switch.mask = 0xf; + + assert(mach->CondStackTop == 0); + assert(mach->LoopStackTop == 0); + assert(mach->ContStackTop == 0); + assert(mach->SwitchStackTop == 0); + assert(mach->BreakStackTop == 0); + assert(mach->CallStackTop == 0); + + mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0] = 0; + mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0] = 0; + + if( mach->Processor == TGSI_PROCESSOR_GEOMETRY ) { + mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0] = 0; + mach->Primitives[0] = 0; + } + + /* execute declarations (interpolants) */ + for (i = 0; i < mach->NumDeclarations; i++) { + exec_declaration( mach, mach->Declarations+i ); + } + + { +#if DEBUG_EXECUTION + struct tgsi_exec_vector temps[TGSI_EXEC_NUM_TEMPS + TGSI_EXEC_NUM_TEMP_EXTRAS]; + struct tgsi_exec_vector outputs[PIPE_MAX_ATTRIBS]; + uint inst = 1; + + memcpy(temps, mach->Temps, sizeof(temps)); + memcpy(outputs, mach->Outputs, sizeof(outputs)); +#endif + + /* execute instructions, until pc is set to -1 */ + while (pc != -1) { + +#if DEBUG_EXECUTION + uint i; + + tgsi_dump_instruction(&mach->Instructions[pc], inst++); +#endif + + assert(pc < (int) mach->NumInstructions); + exec_instruction(mach, mach->Instructions + pc, &pc); + +#if DEBUG_EXECUTION + for (i = 0; i < TGSI_EXEC_NUM_TEMPS + TGSI_EXEC_NUM_TEMP_EXTRAS; i++) { + if (memcmp(&temps[i], &mach->Temps[i], sizeof(temps[i]))) { + uint j; + + memcpy(&temps[i], &mach->Temps[i], sizeof(temps[i])); + debug_printf("TEMP[%2u] = ", i); + for (j = 0; j < 4; j++) { + if (j > 0) { + debug_printf(" "); + } + debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n", + temps[i].xyzw[0].f[j], temps[i].xyzw[0].u[j], + temps[i].xyzw[1].f[j], temps[i].xyzw[1].u[j], + temps[i].xyzw[2].f[j], temps[i].xyzw[2].u[j], + temps[i].xyzw[3].f[j], temps[i].xyzw[3].u[j]); + } + } + } + for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { + if (memcmp(&outputs[i], &mach->Outputs[i], sizeof(outputs[i]))) { + uint j; + + memcpy(&outputs[i], &mach->Outputs[i], sizeof(outputs[i])); + debug_printf("OUT[%2u] = ", i); + for (j = 0; j < 4; j++) { + if (j > 0) { + debug_printf(" "); + } + debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n", + outputs[i].xyzw[0].f[j], outputs[i].xyzw[0].u[j], + outputs[i].xyzw[1].f[j], outputs[i].xyzw[1].u[j], + outputs[i].xyzw[2].f[j], outputs[i].xyzw[2].u[j], + outputs[i].xyzw[3].f[j], outputs[i].xyzw[3].u[j]); + } + } + } +#endif + } + } + +#if 0 + /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */ + if (mach->Processor == TGSI_PROCESSOR_FRAGMENT) { + /* + * Scale back depth component. + */ + for (i = 0; i < 4; i++) + mach->Outputs[0].xyzw[2].f[i] *= ctx->DrawBuffer->_DepthMaxF; + } +#endif + + /* Strictly speaking, these assertions aren't really needed but they + * can potentially catch some bugs in the control flow code. + */ + assert(mach->CondStackTop == 0); + assert(mach->LoopStackTop == 0); + assert(mach->ContStackTop == 0); + assert(mach->SwitchStackTop == 0); + assert(mach->BreakStackTop == 0); + assert(mach->CallStackTop == 0); + + return ~mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0]; +} diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.h b/src/gallium/auxiliary/tgsi/tgsi_exec.h new file mode 100644 index 0000000..b5ebbfb --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.h @@ -0,0 +1,402 @@ +/************************************************************************** + * + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2009-2010 VMware, Inc. All rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL 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. + * + **************************************************************************/ + +#ifndef TGSI_EXEC_H +#define TGSI_EXEC_H + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" + +#if defined __cplusplus +extern "C" { +#endif + + +#define NUM_CHANNELS 4 /* R,G,B,A */ +#define QUAD_SIZE 4 /* 4 pixel/quad */ + + +/** + * Registers may be treated as float, signed int or unsigned int. + */ +union tgsi_exec_channel +{ + float f[QUAD_SIZE]; + int i[QUAD_SIZE]; + unsigned u[QUAD_SIZE]; +}; + +/** + * A vector[RGBA] of channels[4 pixels] + */ +struct tgsi_exec_vector +{ + union tgsi_exec_channel xyzw[NUM_CHANNELS]; +}; + +/** + * For fragment programs, information for computing fragment input + * values from plane equation of the triangle/line. + */ +struct tgsi_interp_coef +{ + float a0[NUM_CHANNELS]; /* in an xyzw layout */ + float dadx[NUM_CHANNELS]; + float dady[NUM_CHANNELS]; +}; + +enum tgsi_sampler_control { + tgsi_sampler_lod_bias, + tgsi_sampler_lod_explicit +}; + +/** + * Information for sampling textures, which must be implemented + * by code outside the TGSI executor. + */ +struct tgsi_sampler +{ + /** Get samples for four fragments in a quad */ + void (*get_samples)(struct tgsi_sampler *sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]); +}; + +#define TGSI_EXEC_NUM_TEMPS 128 +#define TGSI_EXEC_NUM_IMMEDIATES 256 +#define TGSI_EXEC_NUM_TEMP_ARRAYS 8 + +/* + * Locations of various utility registers (_I = Index, _C = Channel) + */ +#define TGSI_EXEC_TEMP_00000000_I (TGSI_EXEC_NUM_TEMPS + 0) +#define TGSI_EXEC_TEMP_00000000_C 0 + +#define TGSI_EXEC_TEMP_7FFFFFFF_I (TGSI_EXEC_NUM_TEMPS + 0) +#define TGSI_EXEC_TEMP_7FFFFFFF_C 1 + +#define TGSI_EXEC_TEMP_80000000_I (TGSI_EXEC_NUM_TEMPS + 0) +#define TGSI_EXEC_TEMP_80000000_C 2 + +#define TGSI_EXEC_TEMP_FFFFFFFF_I (TGSI_EXEC_NUM_TEMPS + 0) +#define TGSI_EXEC_TEMP_FFFFFFFF_C 3 + +#define TGSI_EXEC_TEMP_ONE_I (TGSI_EXEC_NUM_TEMPS + 1) +#define TGSI_EXEC_TEMP_ONE_C 0 + +#define TGSI_EXEC_TEMP_TWO_I (TGSI_EXEC_NUM_TEMPS + 1) +#define TGSI_EXEC_TEMP_TWO_C 1 + +#define TGSI_EXEC_TEMP_128_I (TGSI_EXEC_NUM_TEMPS + 1) +#define TGSI_EXEC_TEMP_128_C 2 + +#define TGSI_EXEC_TEMP_MINUS_128_I (TGSI_EXEC_NUM_TEMPS + 1) +#define TGSI_EXEC_TEMP_MINUS_128_C 3 + +#define TGSI_EXEC_TEMP_KILMASK_I (TGSI_EXEC_NUM_TEMPS + 2) +#define TGSI_EXEC_TEMP_KILMASK_C 0 + +#define TGSI_EXEC_TEMP_OUTPUT_I (TGSI_EXEC_NUM_TEMPS + 2) +#define TGSI_EXEC_TEMP_OUTPUT_C 1 + +#define TGSI_EXEC_TEMP_PRIMITIVE_I (TGSI_EXEC_NUM_TEMPS + 2) +#define TGSI_EXEC_TEMP_PRIMITIVE_C 2 + +#define TGSI_EXEC_TEMP_THREE_I (TGSI_EXEC_NUM_TEMPS + 2) +#define TGSI_EXEC_TEMP_THREE_C 3 + +#define TGSI_EXEC_TEMP_HALF_I (TGSI_EXEC_NUM_TEMPS + 3) +#define TGSI_EXEC_TEMP_HALF_C 0 + +/* execution mask, each value is either 0 or ~0 */ +#define TGSI_EXEC_MASK_I (TGSI_EXEC_NUM_TEMPS + 3) +#define TGSI_EXEC_MASK_C 1 + +/* 4 register buffer for various purposes */ +#define TGSI_EXEC_TEMP_R0 (TGSI_EXEC_NUM_TEMPS + 4) +#define TGSI_EXEC_NUM_TEMP_R 4 + +#define TGSI_EXEC_TEMP_ADDR (TGSI_EXEC_NUM_TEMPS + 8) +#define TGSI_EXEC_NUM_ADDRS 1 + +/* predicate register */ +#define TGSI_EXEC_TEMP_P0 (TGSI_EXEC_NUM_TEMPS + 9) +#define TGSI_EXEC_NUM_PREDS 1 + +#define TGSI_EXEC_NUM_TEMP_EXTRAS 10 + + + +#define TGSI_EXEC_MAX_NESTING 32 +#define TGSI_EXEC_MAX_COND_NESTING TGSI_EXEC_MAX_NESTING +#define TGSI_EXEC_MAX_LOOP_NESTING TGSI_EXEC_MAX_NESTING +#define TGSI_EXEC_MAX_SWITCH_NESTING TGSI_EXEC_MAX_NESTING +#define TGSI_EXEC_MAX_CALL_NESTING TGSI_EXEC_MAX_NESTING + +/* The maximum number of input attributes per vertex. For 2D + * input register files, this is the stride between two 1D + * arrays. + */ +#define TGSI_EXEC_MAX_INPUT_ATTRIBS 17 + +/* The maximum number of constant vectors per constant buffer. + */ +#define TGSI_EXEC_MAX_CONST_BUFFER 4096 + +/* The maximum number of vertices per primitive */ +#define TGSI_MAX_PRIM_VERTICES 6 + +/* The maximum number of primitives to be generated */ +#define TGSI_MAX_PRIMITIVES 64 + +/* The maximum total number of vertices */ +#define TGSI_MAX_TOTAL_VERTICES (TGSI_MAX_PRIM_VERTICES * TGSI_MAX_PRIMITIVES * PIPE_MAX_ATTRIBS) + +/** function call/activation record */ +struct tgsi_call_record +{ + uint CondStackTop; + uint LoopStackTop; + uint ContStackTop; + int SwitchStackTop; + int BreakStackTop; + uint ReturnAddr; +}; + + +/* Switch-case block state. */ +struct tgsi_switch_record { + uint mask; /**< execution mask */ + union tgsi_exec_channel selector; /**< a value case statements are compared to */ + uint defaultMask; /**< non-execute mask for default case */ +}; + + +enum tgsi_break_type { + TGSI_EXEC_BREAK_INSIDE_LOOP, + TGSI_EXEC_BREAK_INSIDE_SWITCH +}; + + +#define TGSI_EXEC_MAX_BREAK_STACK (TGSI_EXEC_MAX_LOOP_NESTING + TGSI_EXEC_MAX_SWITCH_NESTING) + + +/** + * Run-time virtual machine state for executing TGSI shader. + */ +struct tgsi_exec_machine +{ + /* Total = program temporaries + internal temporaries + */ + struct tgsi_exec_vector Temps[TGSI_EXEC_NUM_TEMPS + + TGSI_EXEC_NUM_TEMP_EXTRAS]; + struct tgsi_exec_vector TempArray[TGSI_EXEC_NUM_TEMP_ARRAYS][TGSI_EXEC_NUM_TEMPS]; + + float Imms[TGSI_EXEC_NUM_IMMEDIATES][4]; + + float ImmArray[TGSI_EXEC_NUM_IMMEDIATES][4]; + + struct tgsi_exec_vector Inputs[TGSI_MAX_PRIM_VERTICES * PIPE_MAX_ATTRIBS]; + struct tgsi_exec_vector Outputs[TGSI_MAX_TOTAL_VERTICES]; + + struct tgsi_exec_vector *Addrs; + struct tgsi_exec_vector *Predicates; + + struct tgsi_sampler **Samplers; + + unsigned ImmLimit; + + const void *Consts[PIPE_MAX_CONSTANT_BUFFERS]; + unsigned ConstsSize[PIPE_MAX_CONSTANT_BUFFERS]; + + const struct tgsi_token *Tokens; /**< Declarations, instructions */ + unsigned Processor; /**< TGSI_PROCESSOR_x */ + + /* GEOMETRY processor only. */ + unsigned *Primitives; + unsigned NumOutputs; + unsigned MaxGeometryShaderOutputs; + + /* FRAGMENT processor only. */ + const struct tgsi_interp_coef *InterpCoefs; + struct tgsi_exec_vector QuadPos; + float Face; /**< +1 if front facing, -1 if back facing */ + + /* Conditional execution masks */ + uint CondMask; /**< For IF/ELSE/ENDIF */ + uint LoopMask; /**< For BGNLOOP/ENDLOOP */ + uint ContMask; /**< For loop CONT statements */ + uint FuncMask; /**< For function calls */ + uint ExecMask; /**< = CondMask & LoopMask */ + + /* Current switch-case state. */ + struct tgsi_switch_record Switch; + + /* Current break type. */ + enum tgsi_break_type BreakType; + + /** Condition mask stack (for nested conditionals) */ + uint CondStack[TGSI_EXEC_MAX_COND_NESTING]; + int CondStackTop; + + /** Loop mask stack (for nested loops) */ + uint LoopStack[TGSI_EXEC_MAX_LOOP_NESTING]; + int LoopStackTop; + + /** Loop label stack */ + uint LoopLabelStack[TGSI_EXEC_MAX_LOOP_NESTING]; + int LoopLabelStackTop; + + /** Loop continue mask stack (see comments in tgsi_exec.c) */ + uint ContStack[TGSI_EXEC_MAX_LOOP_NESTING]; + int ContStackTop; + + /** Switch case stack */ + struct tgsi_switch_record SwitchStack[TGSI_EXEC_MAX_SWITCH_NESTING]; + int SwitchStackTop; + + enum tgsi_break_type BreakStack[TGSI_EXEC_MAX_BREAK_STACK]; + int BreakStackTop; + + /** Function execution mask stack (for executing subroutine code) */ + uint FuncStack[TGSI_EXEC_MAX_CALL_NESTING]; + int FuncStackTop; + + /** Function call stack for saving/restoring the program counter */ + struct tgsi_call_record CallStack[TGSI_EXEC_MAX_CALL_NESTING]; + int CallStackTop; + + struct tgsi_full_instruction *Instructions; + uint NumInstructions; + + struct tgsi_full_declaration *Declarations; + uint NumDeclarations; + +}; + +struct tgsi_exec_machine * +tgsi_exec_machine_create( void ); + +void +tgsi_exec_machine_destroy(struct tgsi_exec_machine *mach); + + +void +tgsi_exec_machine_bind_shader( + struct tgsi_exec_machine *mach, + const struct tgsi_token *tokens, + uint numSamplers, + struct tgsi_sampler **samplers); + +uint +tgsi_exec_machine_run( + struct tgsi_exec_machine *mach ); + + +void +tgsi_exec_machine_free_data(struct tgsi_exec_machine *mach); + + +boolean +tgsi_check_soa_dependencies(const struct tgsi_full_instruction *inst); + + +static INLINE void +tgsi_set_kill_mask(struct tgsi_exec_machine *mach, unsigned mask) +{ + mach->Temps[TGSI_EXEC_TEMP_KILMASK_I].xyzw[TGSI_EXEC_TEMP_KILMASK_C].u[0] = + mask; +} + + +/** Set execution mask values prior to executing the shader */ +static INLINE void +tgsi_set_exec_mask(struct tgsi_exec_machine *mach, + boolean ch0, boolean ch1, boolean ch2, boolean ch3) +{ + int *mask = mach->Temps[TGSI_EXEC_MASK_I].xyzw[TGSI_EXEC_MASK_C].i; + mask[0] = ch0 ? ~0 : 0; + mask[1] = ch1 ? ~0 : 0; + mask[2] = ch2 ? ~0 : 0; + mask[3] = ch3 ? ~0 : 0; +} + + +extern void +tgsi_exec_set_constant_buffers(struct tgsi_exec_machine *mach, + unsigned num_bufs, + const void **bufs, + const unsigned *buf_sizes); + + +static INLINE int +tgsi_exec_get_shader_param(enum pipe_shader_cap param) +{ + switch(param) { + case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: + return INT_MAX; + case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: + return TGSI_EXEC_MAX_NESTING; + case PIPE_SHADER_CAP_MAX_INPUTS: + return TGSI_EXEC_MAX_INPUT_ATTRIBS; + case PIPE_SHADER_CAP_MAX_CONSTS: + return TGSI_EXEC_MAX_CONST_BUFFER; + case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: + return PIPE_MAX_CONSTANT_BUFFERS; + case PIPE_SHADER_CAP_MAX_TEMPS: + return TGSI_EXEC_NUM_TEMPS; + case PIPE_SHADER_CAP_MAX_ADDRS: + return TGSI_EXEC_NUM_ADDRS; + case PIPE_SHADER_CAP_MAX_PREDS: + return TGSI_EXEC_NUM_PREDS; + case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: + return 1; + case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: + case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: + return 1; + case PIPE_SHADER_CAP_SUBROUTINES: + return 1; + default: + return 0; + } +} + +#if defined __cplusplus +} /* extern "C" */ +#endif + +#endif /* TGSI_EXEC_H */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_info.c b/src/gallium/auxiliary/tgsi/tgsi_info.c new file mode 100644 index 0000000..e59e964 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_info.c @@ -0,0 +1,222 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "tgsi_info.h" + +static const struct tgsi_opcode_info opcode_info[TGSI_OPCODE_LAST] = +{ + { 1, 1, 0, 0, 0, 0, "ARL", TGSI_OPCODE_ARL }, + { 1, 1, 0, 0, 0, 0, "MOV", TGSI_OPCODE_MOV }, + { 1, 1, 0, 0, 0, 0, "LIT", TGSI_OPCODE_LIT }, + { 1, 1, 0, 0, 0, 0, "RCP", TGSI_OPCODE_RCP }, + { 1, 1, 0, 0, 0, 0, "RSQ", TGSI_OPCODE_RSQ }, + { 1, 1, 0, 0, 0, 0, "EXP", TGSI_OPCODE_EXP }, + { 1, 1, 0, 0, 0, 0, "LOG", TGSI_OPCODE_LOG }, + { 1, 2, 0, 0, 0, 0, "MUL", TGSI_OPCODE_MUL }, + { 1, 2, 0, 0, 0, 0, "ADD", TGSI_OPCODE_ADD }, + { 1, 2, 0, 0, 0, 0, "DP3", TGSI_OPCODE_DP3 }, + { 1, 2, 0, 0, 0, 0, "DP4", TGSI_OPCODE_DP4 }, + { 1, 2, 0, 0, 0, 0, "DST", TGSI_OPCODE_DST }, + { 1, 2, 0, 0, 0, 0, "MIN", TGSI_OPCODE_MIN }, + { 1, 2, 0, 0, 0, 0, "MAX", TGSI_OPCODE_MAX }, + { 1, 2, 0, 0, 0, 0, "SLT", TGSI_OPCODE_SLT }, + { 1, 2, 0, 0, 0, 0, "SGE", TGSI_OPCODE_SGE }, + { 1, 3, 0, 0, 0, 0, "MAD", TGSI_OPCODE_MAD }, + { 1, 2, 0, 0, 0, 0, "SUB", TGSI_OPCODE_SUB }, + { 1, 3, 0, 0, 0, 0, "LRP", TGSI_OPCODE_LRP }, + { 1, 3, 0, 0, 0, 0, "CND", TGSI_OPCODE_CND }, + { 0, 0, 0, 0, 0, 0, "", 20 }, /* removed */ + { 1, 3, 0, 0, 0, 0, "DP2A", TGSI_OPCODE_DP2A }, + { 0, 0, 0, 0, 0, 0, "", 22 }, /* removed */ + { 0, 0, 0, 0, 0, 0, "", 23 }, /* removed */ + { 1, 1, 0, 0, 0, 0, "FRC", TGSI_OPCODE_FRC }, + { 1, 3, 0, 0, 0, 0, "CLAMP", TGSI_OPCODE_CLAMP }, + { 1, 1, 0, 0, 0, 0, "FLR", TGSI_OPCODE_FLR }, + { 1, 1, 0, 0, 0, 0, "ROUND", TGSI_OPCODE_ROUND }, + { 1, 1, 0, 0, 0, 0, "EX2", TGSI_OPCODE_EX2 }, + { 1, 1, 0, 0, 0, 0, "LG2", TGSI_OPCODE_LG2 }, + { 1, 2, 0, 0, 0, 0, "POW", TGSI_OPCODE_POW }, + { 1, 2, 0, 0, 0, 0, "XPD", TGSI_OPCODE_XPD }, + { 0, 0, 0, 0, 0, 0, "", 32 }, /* removed */ + { 1, 1, 0, 0, 0, 0, "ABS", TGSI_OPCODE_ABS }, + { 1, 1, 0, 0, 0, 0, "RCC", TGSI_OPCODE_RCC }, + { 1, 2, 0, 0, 0, 0, "DPH", TGSI_OPCODE_DPH }, + { 1, 1, 0, 0, 0, 0, "COS", TGSI_OPCODE_COS }, + { 1, 1, 0, 0, 0, 0, "DDX", TGSI_OPCODE_DDX }, + { 1, 1, 0, 0, 0, 0, "DDY", TGSI_OPCODE_DDY }, + { 0, 0, 0, 0, 0, 0, "KILP", TGSI_OPCODE_KILP }, + { 1, 1, 0, 0, 0, 0, "PK2H", TGSI_OPCODE_PK2H }, + { 1, 1, 0, 0, 0, 0, "PK2US", TGSI_OPCODE_PK2US }, + { 1, 1, 0, 0, 0, 0, "PK4B", TGSI_OPCODE_PK4B }, + { 1, 1, 0, 0, 0, 0, "PK4UB", TGSI_OPCODE_PK4UB }, + { 1, 2, 0, 0, 0, 0, "RFL", TGSI_OPCODE_RFL }, + { 1, 2, 0, 0, 0, 0, "SEQ", TGSI_OPCODE_SEQ }, + { 1, 2, 0, 0, 0, 0, "SFL", TGSI_OPCODE_SFL }, + { 1, 2, 0, 0, 0, 0, "SGT", TGSI_OPCODE_SGT }, + { 1, 1, 0, 0, 0, 0, "SIN", TGSI_OPCODE_SIN }, + { 1, 2, 0, 0, 0, 0, "SLE", TGSI_OPCODE_SLE }, + { 1, 2, 0, 0, 0, 0, "SNE", TGSI_OPCODE_SNE }, + { 1, 2, 0, 0, 0, 0, "STR", TGSI_OPCODE_STR }, + { 1, 2, 1, 0, 0, 0, "TEX", TGSI_OPCODE_TEX }, + { 1, 4, 1, 0, 0, 0, "TXD", TGSI_OPCODE_TXD }, + { 1, 2, 1, 0, 0, 0, "TXP", TGSI_OPCODE_TXP }, + { 1, 1, 0, 0, 0, 0, "UP2H", TGSI_OPCODE_UP2H }, + { 1, 1, 0, 0, 0, 0, "UP2US", TGSI_OPCODE_UP2US }, + { 1, 1, 0, 0, 0, 0, "UP4B", TGSI_OPCODE_UP4B }, + { 1, 1, 0, 0, 0, 0, "UP4UB", TGSI_OPCODE_UP4UB }, + { 1, 3, 0, 0, 0, 0, "X2D", TGSI_OPCODE_X2D }, + { 1, 1, 0, 0, 0, 0, "ARA", TGSI_OPCODE_ARA }, + { 1, 1, 0, 0, 0, 0, "ARR", TGSI_OPCODE_ARR }, + { 0, 1, 0, 0, 0, 0, "BRA", TGSI_OPCODE_BRA }, + { 0, 0, 0, 1, 0, 0, "CAL", TGSI_OPCODE_CAL }, + { 0, 0, 0, 0, 0, 0, "RET", TGSI_OPCODE_RET }, + { 1, 1, 0, 0, 0, 0, "SSG", TGSI_OPCODE_SSG }, + { 1, 3, 0, 0, 0, 0, "CMP", TGSI_OPCODE_CMP }, + { 1, 1, 0, 0, 0, 0, "SCS", TGSI_OPCODE_SCS }, + { 1, 2, 1, 0, 0, 0, "TXB", TGSI_OPCODE_TXB }, + { 1, 1, 0, 0, 0, 0, "NRM", TGSI_OPCODE_NRM }, + { 1, 2, 0, 0, 0, 0, "DIV", TGSI_OPCODE_DIV }, + { 1, 2, 0, 0, 0, 0, "DP2", TGSI_OPCODE_DP2 }, + { 1, 2, 1, 0, 0, 0, "TXL", TGSI_OPCODE_TXL }, + { 0, 0, 0, 0, 0, 0, "BRK", TGSI_OPCODE_BRK }, + { 0, 1, 0, 1, 0, 1, "IF", TGSI_OPCODE_IF }, + { 1, 1, 0, 0, 0, 1, "", 75 }, /* removed */ + { 0, 1, 0, 0, 0, 1, "", 76 }, /* removed */ + { 0, 0, 0, 1, 1, 1, "ELSE", TGSI_OPCODE_ELSE }, + { 0, 0, 0, 0, 1, 0, "ENDIF", TGSI_OPCODE_ENDIF }, + { 1, 0, 0, 0, 1, 0, "", 79 }, /* removed */ + { 0, 0, 0, 0, 1, 0, "", 80 }, /* removed */ + { 0, 1, 0, 0, 0, 0, "PUSHA", TGSI_OPCODE_PUSHA }, + { 1, 0, 0, 0, 0, 0, "POPA", TGSI_OPCODE_POPA }, + { 1, 1, 0, 0, 0, 0, "CEIL", TGSI_OPCODE_CEIL }, + { 1, 1, 0, 0, 0, 0, "I2F", TGSI_OPCODE_I2F }, + { 1, 1, 0, 0, 0, 0, "NOT", TGSI_OPCODE_NOT }, + { 1, 1, 0, 0, 0, 0, "TRUNC", TGSI_OPCODE_TRUNC }, + { 1, 2, 0, 0, 0, 0, "SHL", TGSI_OPCODE_SHL }, + { 0, 0, 0, 0, 0, 0, "", 88 }, /* removed */ + { 1, 2, 0, 0, 0, 0, "AND", TGSI_OPCODE_AND }, + { 1, 2, 0, 0, 0, 0, "OR", TGSI_OPCODE_OR }, + { 1, 2, 0, 0, 0, 0, "MOD", TGSI_OPCODE_MOD }, + { 1, 2, 0, 0, 0, 0, "XOR", TGSI_OPCODE_XOR }, + { 1, 3, 0, 0, 0, 0, "SAD", TGSI_OPCODE_SAD }, + { 1, 2, 1, 0, 0, 0, "TXF", TGSI_OPCODE_TXF }, + { 1, 2, 1, 0, 0, 0, "TXQ", TGSI_OPCODE_TXQ }, + { 0, 0, 0, 0, 0, 0, "CONT", TGSI_OPCODE_CONT }, + { 0, 0, 0, 0, 0, 0, "EMIT", TGSI_OPCODE_EMIT }, + { 0, 0, 0, 0, 0, 0, "ENDPRIM", TGSI_OPCODE_ENDPRIM }, + { 0, 0, 0, 1, 0, 1, "BGNLOOP", TGSI_OPCODE_BGNLOOP }, + { 0, 0, 0, 0, 0, 1, "BGNSUB", TGSI_OPCODE_BGNSUB }, + { 0, 0, 0, 1, 1, 0, "ENDLOOP", TGSI_OPCODE_ENDLOOP }, + { 0, 0, 0, 0, 1, 0, "ENDSUB", TGSI_OPCODE_ENDSUB }, + { 0, 0, 0, 0, 0, 0, "", 103 }, /* removed */ + { 0, 0, 0, 0, 0, 0, "", 104 }, /* removed */ + { 0, 0, 0, 0, 0, 0, "", 105 }, /* removed */ + { 0, 0, 0, 0, 0, 0, "", 106 }, /* removed */ + { 0, 0, 0, 0, 0, 0, "NOP", TGSI_OPCODE_NOP }, + { 0, 0, 0, 0, 0, 0, "", 108 }, /* removed */ + { 0, 0, 0, 0, 0, 0, "", 109 }, /* removed */ + { 0, 0, 0, 0, 0, 0, "", 110 }, /* removed */ + { 0, 0, 0, 0, 0, 0, "", 111 }, /* removed */ + { 1, 1, 0, 0, 0, 0, "NRM4", TGSI_OPCODE_NRM4 }, + { 0, 1, 0, 0, 0, 0, "CALLNZ", TGSI_OPCODE_CALLNZ }, + { 0, 1, 0, 0, 0, 0, "IFC", TGSI_OPCODE_IFC }, + { 0, 1, 0, 0, 0, 0, "BREAKC", TGSI_OPCODE_BREAKC }, + { 0, 1, 0, 0, 0, 0, "KIL", TGSI_OPCODE_KIL }, + { 0, 0, 0, 0, 0, 0, "END", TGSI_OPCODE_END }, + { 0, 0, 0, 0, 0, 0, "", 118 }, /* removed */ + { 1, 1, 0, 0, 0, 0, "F2I", TGSI_OPCODE_F2I }, + { 1, 2, 0, 0, 0, 0, "IDIV", TGSI_OPCODE_IDIV }, + { 1, 2, 0, 0, 0, 0, "IMAX", TGSI_OPCODE_IMAX }, + { 1, 2, 0, 0, 0, 0, "IMIN", TGSI_OPCODE_IMIN }, + { 1, 1, 0, 0, 0, 0, "INEG", TGSI_OPCODE_INEG }, + { 1, 2, 0, 0, 0, 0, "ISGE", TGSI_OPCODE_ISGE }, + { 1, 2, 0, 0, 0, 0, "ISHR", TGSI_OPCODE_ISHR }, + { 1, 2, 0, 0, 0, 0, "ISLT", TGSI_OPCODE_ISLT }, + { 1, 1, 0, 0, 0, 0, "F2U", TGSI_OPCODE_F2U }, + { 1, 1, 0, 0, 0, 0, "U2F", TGSI_OPCODE_U2F }, + { 1, 2, 0, 0, 0, 0, "UADD", TGSI_OPCODE_UADD }, + { 1, 2, 0, 0, 0, 0, "UDIV", TGSI_OPCODE_UDIV }, + { 1, 3, 0, 0, 0, 0, "UMAD", TGSI_OPCODE_UMAD }, + { 1, 2, 0, 0, 0, 0, "UMAX", TGSI_OPCODE_UMAX }, + { 1, 2, 0, 0, 0, 0, "UMIN", TGSI_OPCODE_UMIN }, + { 1, 2, 0, 0, 0, 0, "UMOD", TGSI_OPCODE_UMOD }, + { 1, 2, 0, 0, 0, 0, "UMUL", TGSI_OPCODE_UMUL }, + { 1, 2, 0, 0, 0, 0, "USEQ", TGSI_OPCODE_USEQ }, + { 1, 2, 0, 0, 0, 0, "USGE", TGSI_OPCODE_USGE }, + { 1, 2, 0, 0, 0, 0, "USHR", TGSI_OPCODE_USHR }, + { 1, 2, 0, 0, 0, 0, "USLT", TGSI_OPCODE_USLT }, + { 1, 2, 0, 0, 0, 0, "USNE", TGSI_OPCODE_USNE }, + { 0, 1, 0, 0, 0, 0, "SWITCH", TGSI_OPCODE_SWITCH }, + { 0, 1, 0, 0, 0, 0, "CASE", TGSI_OPCODE_CASE }, + { 0, 0, 0, 0, 0, 0, "DEFAULT", TGSI_OPCODE_DEFAULT }, + { 0, 0, 0, 0, 0, 0, "ENDSWITCH", TGSI_OPCODE_ENDSWITCH } +}; + +const struct tgsi_opcode_info * +tgsi_get_opcode_info( uint opcode ) +{ + static boolean firsttime = 1; + + if (firsttime) { + unsigned i; + firsttime = 0; + for (i = 0; i < Elements(opcode_info); i++) + assert(opcode_info[i].opcode == i); + } + + if (opcode < TGSI_OPCODE_LAST) + return &opcode_info[opcode]; + + assert( 0 ); + return NULL; +} + + +const char * +tgsi_get_opcode_name( uint opcode ) +{ + const struct tgsi_opcode_info *info = tgsi_get_opcode_info(opcode); + return info->mnemonic; +} + + +const char * +tgsi_get_processor_name( uint processor ) +{ + switch (processor) { + case TGSI_PROCESSOR_VERTEX: + return "vertex shader"; + case TGSI_PROCESSOR_FRAGMENT: + return "fragment shader"; + case TGSI_PROCESSOR_GEOMETRY: + return "geometry shader"; + default: + return "unknown shader type!"; + } +} diff --git a/src/gallium/auxiliary/tgsi/tgsi_info.h b/src/gallium/auxiliary/tgsi/tgsi_info.h new file mode 100644 index 0000000..1992d11 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_info.h @@ -0,0 +1,64 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef TGSI_INFO_H +#define TGSI_INFO_H + +#include "pipe/p_compiler.h" +#include "pipe/p_shader_tokens.h" + +#if defined __cplusplus +extern "C" { +#endif + +struct tgsi_opcode_info +{ + unsigned num_dst:3; + unsigned num_src:3; + unsigned is_tex:1; + unsigned is_branch:1; + int pre_dedent:2; + int post_indent:2; + const char *mnemonic; + uint opcode; +}; + +const struct tgsi_opcode_info * +tgsi_get_opcode_info( uint opcode ); + +const char * +tgsi_get_opcode_name( uint opcode ); + +const char * +tgsi_get_processor_name( uint processor ); + + +#if defined __cplusplus +} +#endif + +#endif /* TGSI_INFO_H */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_iterate.c b/src/gallium/auxiliary/tgsi/tgsi_iterate.c new file mode 100644 index 0000000..0ba5fe4 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_iterate.c @@ -0,0 +1,90 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_debug.h" +#include "tgsi_iterate.h" + +boolean +tgsi_iterate_shader( + const struct tgsi_token *tokens, + struct tgsi_iterate_context *ctx ) +{ + struct tgsi_parse_context parse; + + if (tgsi_parse_init( &parse, tokens ) != TGSI_PARSE_OK) + return FALSE; + + ctx->processor = parse.FullHeader.Processor; + + if (ctx->prolog) + if (!ctx->prolog( ctx )) + goto fail; + + while (!tgsi_parse_end_of_tokens( &parse )) { + tgsi_parse_token( &parse ); + + switch (parse.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_INSTRUCTION: + if (ctx->iterate_instruction) + if (!ctx->iterate_instruction( ctx, &parse.FullToken.FullInstruction )) + goto fail; + break; + + case TGSI_TOKEN_TYPE_DECLARATION: + if (ctx->iterate_declaration) + if (!ctx->iterate_declaration( ctx, &parse.FullToken.FullDeclaration )) + goto fail; + break; + + case TGSI_TOKEN_TYPE_IMMEDIATE: + if (ctx->iterate_immediate) + if (!ctx->iterate_immediate( ctx, &parse.FullToken.FullImmediate )) + goto fail; + break; + + case TGSI_TOKEN_TYPE_PROPERTY: + if (ctx->iterate_property) + if (!ctx->iterate_property( ctx, &parse.FullToken.FullProperty )) + goto fail; + break; + + default: + assert( 0 ); + } + } + + if (ctx->epilog) + if (!ctx->epilog( ctx )) + goto fail; + + tgsi_parse_free( &parse ); + return TRUE; + +fail: + tgsi_parse_free( &parse ); + return FALSE; +} diff --git a/src/gallium/auxiliary/tgsi/tgsi_iterate.h b/src/gallium/auxiliary/tgsi/tgsi_iterate.h new file mode 100644 index 0000000..8d67f22 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_iterate.h @@ -0,0 +1,80 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef TGSI_ITERATE_H +#define TGSI_ITERATE_H + +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" + +#if defined __cplusplus +extern "C" { +#endif + +struct tgsi_iterate_context +{ + boolean + (* prolog)( + struct tgsi_iterate_context *ctx ); + + boolean + (* iterate_instruction)( + struct tgsi_iterate_context *ctx, + struct tgsi_full_instruction *inst ); + + boolean + (* iterate_declaration)( + struct tgsi_iterate_context *ctx, + struct tgsi_full_declaration *decl ); + + boolean + (* iterate_immediate)( + struct tgsi_iterate_context *ctx, + struct tgsi_full_immediate *imm ); + + boolean + (* iterate_property)( + struct tgsi_iterate_context *ctx, + struct tgsi_full_property *prop ); + + boolean + (* epilog)( + struct tgsi_iterate_context *ctx ); + + struct tgsi_processor processor; +}; + +boolean +tgsi_iterate_shader( + const struct tgsi_token *tokens, + struct tgsi_iterate_context *ctx ); + +#if defined __cplusplus +} +#endif + +#endif /* TGSI_ITERATE_H */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_opcode_tmp.h b/src/gallium/auxiliary/tgsi/tgsi_opcode_tmp.h new file mode 100644 index 0000000..b3123ed --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_opcode_tmp.h @@ -0,0 +1,188 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ +#ifndef OP12_TEX +#define OP12_TEX(a) OP12(a) +#endif + +#ifndef OP14_TEX +#define OP14_TEX(a) OP14(a) +#endif + +#ifndef OP00_LBL +#define OP00_LBL(a) OP00(a) +#endif + +#ifndef OP01_LBL +#define OP01_LBL(a) OP01(a) +#endif + +OP11(ARL) +OP11(MOV) +OP11(LIT) +OP11(RCP) +OP11(RSQ) +OP11(EXP) +OP11(LOG) +OP12(MUL) +OP12(ADD) +OP12(DP3) +OP12(DP4) +OP12(DST) +OP12(MIN) +OP12(MAX) +OP12(SLT) +OP12(SGE) +OP13(MAD) +OP12(SUB) +OP13(LRP) +OP13(CND) +OP13(DP2A) +OP11(FRC) +OP13(CLAMP) +OP11(FLR) +OP11(ROUND) +OP11(EX2) +OP11(LG2) +OP12(POW) +OP12(XPD) +OP11(ABS) +OP11(RCC) +OP12(DPH) +OP11(COS) +OP11(DDX) +OP11(DDY) +OP00(KILP) +OP11(PK2H) +OP11(PK2US) +OP11(PK4B) +OP11(PK4UB) +OP12(RFL) +OP12(SEQ) +OP12(SFL) +OP12(SGT) +OP11(SIN) +OP12(SLE) +OP12(SNE) +OP12(STR) +OP12_TEX(TEX) +OP14_TEX(TXD) +OP12_TEX(TXP) +OP11(UP2H) +OP11(UP2US) +OP11(UP4B) +OP11(UP4UB) +OP13(X2D) +OP11(ARA) +OP11(ARR) +OP01(BRA) +OP00_LBL(CAL) +OP00(RET) +OP11(SSG) +OP13(CMP) +OP11(SCS) +OP12_TEX(TXB) +OP11(NRM) +OP12(DIV) +OP12(DP2) +OP12_TEX(TXL) +OP00(BRK) +OP01_LBL(IF) +OP00_LBL(ELSE) +OP00(ENDIF) +OP01(PUSHA) +OP10(POPA) +OP11(CEIL) +OP11(I2F) +OP11(NOT) +OP11(TRUNC) +OP12(SHL) +OP12(AND) +OP12(OR) +OP12(MOD) +OP12(XOR) +OP13(SAD) +OP12_TEX(TXF) +OP12_TEX(TXQ) +OP00(CONT) +OP00(EMIT) +OP00(ENDPRIM) +OP00_LBL(BGNLOOP) +OP00(BGNSUB) +OP00_LBL(ENDLOOP) +OP00(ENDSUB) +OP00(NOP) +OP11(NRM4) +OP01(CALLNZ) +OP01(IFC) +OP01(BREAKC) +OP01(KIL) +OP00(END) +OP11(F2I) +OP12(IDIV) +OP12(IMAX) +OP12(IMIN) +OP11(INEG) +OP12(ISGE) +OP12(ISHR) +OP12(ISLT) +OP11(F2U) +OP11(U2F) +OP12(UADD) +OP12(UDIV) +OP13(UMAD) +OP12(UMAX) +OP12(UMIN) +OP12(UMOD) +OP12(UMUL) +OP12(USEQ) +OP12(USGE) +OP12(USHR) +OP12(USLT) +OP12(USNE) +OP01(SWITCH) +OP01(CASE) +OP00(DEFAULT) +OP00(ENDSWITCH) + + +#undef OP00 +#undef OP01 +#undef OP10 +#undef OP11 +#undef OP12 +#undef OP13 + +#ifdef OP14 +#undef OP14 +#endif + +#undef OP00_LBL +#undef OP01_LBL + +#undef OP12_TEX +#undef OP14_TEX + diff --git a/src/gallium/auxiliary/tgsi/tgsi_parse.c b/src/gallium/auxiliary/tgsi/tgsi_parse.c new file mode 100644 index 0000000..1891203 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_parse.c @@ -0,0 +1,326 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_debug.h" +#include "pipe/p_shader_tokens.h" +#include "tgsi_parse.h" +#include "util/u_memory.h" + +unsigned +tgsi_parse_init( + struct tgsi_parse_context *ctx, + const struct tgsi_token *tokens ) +{ + ctx->FullHeader.Header = *(struct tgsi_header *) &tokens[0]; + if( ctx->FullHeader.Header.HeaderSize >= 2 ) { + ctx->FullHeader.Processor = *(struct tgsi_processor *) &tokens[1]; + } + else { + return TGSI_PARSE_ERROR; + } + + ctx->Tokens = tokens; + ctx->Position = ctx->FullHeader.Header.HeaderSize; + + return TGSI_PARSE_OK; +} + +void +tgsi_parse_free( + struct tgsi_parse_context *ctx ) +{ +} + +boolean +tgsi_parse_end_of_tokens( + struct tgsi_parse_context *ctx ) +{ + return ctx->Position >= + ctx->FullHeader.Header.HeaderSize + ctx->FullHeader.Header.BodySize; +} + + +/** + * This function is used to avoid and work-around type punning/aliasing + * warnings. The warnings seem harmless on x86 but on PPC they cause + * real failures. + */ +static INLINE void +copy_token(void *dst, const void *src) +{ + memcpy(dst, src, 4); +} + + +/** + * Get next 4-byte token, return it at address specified by 'token' + */ +static void +next_token( + struct tgsi_parse_context *ctx, + void *token ) +{ + assert( !tgsi_parse_end_of_tokens( ctx ) ); + copy_token(token, &ctx->Tokens[ctx->Position]); + ctx->Position++; +} + + +void +tgsi_parse_token( + struct tgsi_parse_context *ctx ) +{ + struct tgsi_token token; + unsigned i; + + next_token( ctx, &token ); + + switch( token.Type ) { + case TGSI_TOKEN_TYPE_DECLARATION: + { + struct tgsi_full_declaration *decl = &ctx->FullToken.FullDeclaration; + + memset(decl, 0, sizeof *decl); + copy_token(&decl->Declaration, &token); + + next_token( ctx, &decl->Range ); + + if (decl->Declaration.Dimension) { + next_token(ctx, &decl->Dim); + } + + if( decl->Declaration.Semantic ) { + next_token( ctx, &decl->Semantic ); + } + + if (decl->Declaration.File == TGSI_FILE_IMMEDIATE_ARRAY) { + unsigned i, j; + decl->ImmediateData.u = (union tgsi_immediate_data*) + &ctx->Tokens[ctx->Position]; + for (i = 0; i <= decl->Range.Last; ++i) { + for (j = 0; j < 4; ++j) { + ctx->Position++; + } + } + } + + break; + } + + case TGSI_TOKEN_TYPE_IMMEDIATE: + { + struct tgsi_full_immediate *imm = &ctx->FullToken.FullImmediate; + uint imm_count; + + memset(imm, 0, sizeof *imm); + copy_token(&imm->Immediate, &token); + + imm_count = imm->Immediate.NrTokens - 1; + + switch (imm->Immediate.DataType) { + case TGSI_IMM_FLOAT32: + for (i = 0; i < imm_count; i++) { + next_token(ctx, &imm->u[i].Float); + } + break; + + case TGSI_IMM_UINT32: + for (i = 0; i < imm_count; i++) { + next_token(ctx, &imm->u[i].Uint); + } + break; + + case TGSI_IMM_INT32: + for (i = 0; i < imm_count; i++) { + next_token(ctx, &imm->u[i].Int); + } + break; + + default: + assert( 0 ); + } + + break; + } + + case TGSI_TOKEN_TYPE_INSTRUCTION: + { + struct tgsi_full_instruction *inst = &ctx->FullToken.FullInstruction; + + memset(inst, 0, sizeof *inst); + copy_token(&inst->Instruction, &token); + + if (inst->Instruction.Predicate) { + next_token(ctx, &inst->Predicate); + } + + if (inst->Instruction.Label) { + next_token( ctx, &inst->Label); + } + + if (inst->Instruction.Texture) { + next_token( ctx, &inst->Texture); + } + + assert( inst->Instruction.NumDstRegs <= TGSI_FULL_MAX_DST_REGISTERS ); + + for( i = 0; i < inst->Instruction.NumDstRegs; i++ ) { + + next_token( ctx, &inst->Dst[i].Register ); + + if( inst->Dst[i].Register.Indirect ) { + next_token( ctx, &inst->Dst[i].Indirect ); + + /* + * No support for indirect or multi-dimensional addressing. + */ + assert( !inst->Dst[i].Indirect.Dimension ); + assert( !inst->Dst[i].Indirect.Indirect ); + } + if( inst->Dst[i].Register.Dimension ) { + next_token( ctx, &inst->Dst[i].Dimension ); + + /* + * No support for multi-dimensional addressing. + */ + assert( !inst->Dst[i].Dimension.Dimension ); + + if( inst->Dst[i].Dimension.Indirect ) { + next_token( ctx, &inst->Dst[i].DimIndirect ); + + /* + * No support for indirect or multi-dimensional addressing. + */ + assert( !inst->Dst[i].Indirect.Indirect ); + assert( !inst->Dst[i].Indirect.Dimension ); + } + } + } + + assert( inst->Instruction.NumSrcRegs <= TGSI_FULL_MAX_SRC_REGISTERS ); + + for( i = 0; i < inst->Instruction.NumSrcRegs; i++ ) { + + next_token( ctx, &inst->Src[i].Register ); + + if( inst->Src[i].Register.Indirect ) { + next_token( ctx, &inst->Src[i].Indirect ); + + /* + * No support for indirect or multi-dimensional addressing. + */ + assert( !inst->Src[i].Indirect.Indirect ); + assert( !inst->Src[i].Indirect.Dimension ); + } + + if( inst->Src[i].Register.Dimension ) { + next_token( ctx, &inst->Src[i].Dimension ); + + /* + * No support for multi-dimensional addressing. + */ + assert( !inst->Src[i].Dimension.Dimension ); + + if( inst->Src[i].Dimension.Indirect ) { + next_token( ctx, &inst->Src[i].DimIndirect ); + + /* + * No support for indirect or multi-dimensional addressing. + */ + assert( !inst->Src[i].Indirect.Indirect ); + assert( !inst->Src[i].Indirect.Dimension ); + } + } + } + + break; + } + + case TGSI_TOKEN_TYPE_PROPERTY: + { + struct tgsi_full_property *prop = &ctx->FullToken.FullProperty; + uint prop_count; + + memset(prop, 0, sizeof *prop); + copy_token(&prop->Property, &token); + + prop_count = prop->Property.NrTokens - 1; + for (i = 0; i < prop_count; i++) { + next_token(ctx, &prop->u[i]); + } + + break; + } + + default: + assert( 0 ); + } +} + + + + +/** + * Make a new copy of a token array. + */ +struct tgsi_token * +tgsi_dup_tokens(const struct tgsi_token *tokens) +{ + unsigned n = tgsi_num_tokens(tokens); + unsigned bytes = n * sizeof(struct tgsi_token); + struct tgsi_token *new_tokens = (struct tgsi_token *) MALLOC(bytes); + if (new_tokens) + memcpy(new_tokens, tokens, bytes); + return new_tokens; +} + + +/** + * Allocate memory for num_tokens tokens. + */ +struct tgsi_token * +tgsi_alloc_tokens(unsigned num_tokens) +{ + unsigned bytes = num_tokens * sizeof(struct tgsi_token); + return (struct tgsi_token *) MALLOC(bytes); +} + + +void +tgsi_dump_tokens(const struct tgsi_token *tokens) +{ + const unsigned *dwords = (const unsigned *)tokens; + int nr = tgsi_num_tokens(tokens); + int i; + + assert(sizeof(*tokens) == sizeof(unsigned)); + + debug_printf("const unsigned tokens[%d] = {\n", nr); + for (i = 0; i < nr; i++) + debug_printf("0x%08x,\n", dwords[i]); + debug_printf("};\n"); +} diff --git a/src/gallium/auxiliary/tgsi/tgsi_parse.h b/src/gallium/auxiliary/tgsi/tgsi_parse.h new file mode 100644 index 0000000..d4df585 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_parse.h @@ -0,0 +1,158 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef TGSI_PARSE_H +#define TGSI_PARSE_H + +#include "pipe/p_compiler.h" +#include "pipe/p_shader_tokens.h" + +#if defined __cplusplus +extern "C" { +#endif + +struct tgsi_full_header +{ + struct tgsi_header Header; + struct tgsi_processor Processor; +}; + +struct tgsi_full_dst_register +{ + struct tgsi_dst_register Register; + struct tgsi_src_register Indirect; + struct tgsi_dimension Dimension; + struct tgsi_src_register DimIndirect; +}; + +struct tgsi_full_src_register +{ + struct tgsi_src_register Register; + struct tgsi_src_register Indirect; + struct tgsi_dimension Dimension; + struct tgsi_src_register DimIndirect; +}; + +struct tgsi_immediate_array_data +{ + union tgsi_immediate_data *u; +}; + +struct tgsi_full_declaration +{ + struct tgsi_declaration Declaration; + struct tgsi_declaration_range Range; + struct tgsi_declaration_dimension Dim; + struct tgsi_declaration_semantic Semantic; + struct tgsi_immediate_array_data ImmediateData; +}; + +struct tgsi_full_immediate +{ + struct tgsi_immediate Immediate; + union tgsi_immediate_data u[4]; +}; + +struct tgsi_full_property +{ + struct tgsi_property Property; + struct tgsi_property_data u[8]; +}; + +#define TGSI_FULL_MAX_DST_REGISTERS 2 +#define TGSI_FULL_MAX_SRC_REGISTERS 4 /* TXD has 4 */ + +struct tgsi_full_instruction +{ + struct tgsi_instruction Instruction; + struct tgsi_instruction_predicate Predicate; + struct tgsi_instruction_label Label; + struct tgsi_instruction_texture Texture; + struct tgsi_full_dst_register Dst[TGSI_FULL_MAX_DST_REGISTERS]; + struct tgsi_full_src_register Src[TGSI_FULL_MAX_SRC_REGISTERS]; +}; + +union tgsi_full_token +{ + struct tgsi_token Token; + struct tgsi_full_declaration FullDeclaration; + struct tgsi_full_immediate FullImmediate; + struct tgsi_full_instruction FullInstruction; + struct tgsi_full_property FullProperty; +}; + +struct tgsi_parse_context +{ + const struct tgsi_token *Tokens; + unsigned Position; + struct tgsi_full_header FullHeader; + union tgsi_full_token FullToken; +}; + +#define TGSI_PARSE_OK 0 +#define TGSI_PARSE_ERROR 1 + +unsigned +tgsi_parse_init( + struct tgsi_parse_context *ctx, + const struct tgsi_token *tokens ); + +void +tgsi_parse_free( + struct tgsi_parse_context *ctx ); + +boolean +tgsi_parse_end_of_tokens( + struct tgsi_parse_context *ctx ); + +void +tgsi_parse_token( + struct tgsi_parse_context *ctx ); + +static INLINE unsigned +tgsi_num_tokens(const struct tgsi_token *tokens) +{ + struct tgsi_header header = *(const struct tgsi_header *) tokens; + return header.HeaderSize + header.BodySize; +} + +void +tgsi_dump_tokens(const struct tgsi_token *tokens); + +struct tgsi_token * +tgsi_dup_tokens(const struct tgsi_token *tokens); + +struct tgsi_token * +tgsi_alloc_tokens(unsigned num_tokens); + + +#if defined __cplusplus +} +#endif + +#endif /* TGSI_PARSE_H */ + diff --git a/src/gallium/auxiliary/tgsi/tgsi_ppc.c b/src/gallium/auxiliary/tgsi/tgsi_ppc.c new file mode 100644 index 0000000..3521847 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_ppc.c @@ -0,0 +1,1377 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * TGSI to PowerPC code generation. + */ + +#include "pipe/p_config.h" + +#if defined(PIPE_ARCH_PPC) + +#include "util/u_debug.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_sse.h" +#include "tgsi/tgsi_info.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "tgsi_dump.h" +#include "tgsi_exec.h" +#include "tgsi_ppc.h" +#include "rtasm/rtasm_ppc.h" + + +/** + * Since it's pretty much impossible to form PPC vector immediates, load + * them from memory here: + */ +PIPE_ALIGN_VAR(16) const float +ppc_builtin_constants[] = { + 1.0f, -128.0f, 128.0, 0.0 +}; + + +#define FOR_EACH_CHANNEL( CHAN )\ + for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++) + +#define IS_DST0_CHANNEL_ENABLED( INST, CHAN )\ + ((INST).Dst[0].Register.WriteMask & (1 << (CHAN))) + +#define IF_IS_DST0_CHANNEL_ENABLED( INST, CHAN )\ + if (IS_DST0_CHANNEL_ENABLED( INST, CHAN )) + +#define FOR_EACH_DST0_ENABLED_CHANNEL( INST, CHAN )\ + FOR_EACH_CHANNEL( CHAN )\ + IF_IS_DST0_CHANNEL_ENABLED( INST, CHAN ) + +#define CHAN_X 0 +#define CHAN_Y 1 +#define CHAN_Z 2 +#define CHAN_W 3 + + +/** + * How many TGSI temps should be implemented with real PPC vector registers + * rather than memory. + */ +#define MAX_PPC_TEMPS 3 + + +/** + * Context/state used during code gen. + */ +struct gen_context +{ + struct ppc_function *f; + int inputs_reg; /**< GP register pointing to input params */ + int outputs_reg; /**< GP register pointing to output params */ + int temps_reg; /**< GP register pointing to temporary "registers" */ + int immed_reg; /**< GP register pointing to immediates buffer */ + int const_reg; /**< GP register pointing to constants buffer */ + int builtins_reg; /**< GP register pointint to built-in constants */ + + int offset_reg; /**< used to reduce redundant li instructions */ + int offset_value; + + int one_vec; /**< vector register with {1.0, 1.0, 1.0, 1.0} */ + int bit31_vec; /**< vector register with {1<<31, 1<<31, 1<<31, 1<<31} */ + + /** + * Map TGSI temps to PPC vector temps. + * We have 32 PPC vector regs. Use 16 of them for storing 4 TGSI temps. + * XXX currently only do this for TGSI temps [0..MAX_PPC_TEMPS-1]. + */ + int temps_map[MAX_PPC_TEMPS][4]; + + /** + * Cache of src registers. + * This is used to avoid redundant load instructions. + */ + struct { + struct tgsi_full_src_register src; + uint chan; + uint vec; + } regs[12]; /* 3 src regs, 4 channels */ + uint num_regs; +}; + + +/** + * Initialize code generation context. + */ +static void +init_gen_context(struct gen_context *gen, struct ppc_function *func) +{ + uint i; + + memset(gen, 0, sizeof(*gen)); + gen->f = func; + gen->inputs_reg = ppc_reserve_register(func, 3); /* first function param */ + gen->outputs_reg = ppc_reserve_register(func, 4); /* second function param */ + gen->temps_reg = ppc_reserve_register(func, 5); /* ... */ + gen->immed_reg = ppc_reserve_register(func, 6); + gen->const_reg = ppc_reserve_register(func, 7); + gen->builtins_reg = ppc_reserve_register(func, 8); + gen->one_vec = -1; + gen->bit31_vec = -1; + gen->offset_reg = -1; + gen->offset_value = -9999999; + for (i = 0; i < MAX_PPC_TEMPS; i++) { + gen->temps_map[i][0] = ppc_allocate_vec_register(gen->f); + gen->temps_map[i][1] = ppc_allocate_vec_register(gen->f); + gen->temps_map[i][2] = ppc_allocate_vec_register(gen->f); + gen->temps_map[i][3] = ppc_allocate_vec_register(gen->f); + } +} + + +/** + * Is the given TGSI register stored as a real PPC vector register? + */ +static boolean +is_ppc_vec_temporary(const struct tgsi_full_src_register *reg) +{ + return (reg->Register.File == TGSI_FILE_TEMPORARY && + reg->Register.Index < MAX_PPC_TEMPS); +} + + +/** + * Is the given TGSI register stored as a real PPC vector register? + */ +static boolean +is_ppc_vec_temporary_dst(const struct tgsi_full_dst_register *reg) +{ + return (reg->Register.File == TGSI_FILE_TEMPORARY && + reg->Register.Index < MAX_PPC_TEMPS); +} + + + +/** + * All PPC vector load/store instructions form an effective address + * by adding the contents of two registers. For example: + * lvx v2,r8,r9 # v2 = memory[r8 + r9] + * stvx v2,r8,r9 # memory[r8 + r9] = v2; + * So our lvx/stvx instructions are typically preceded by an 'li' instruction + * to load r9 (above) with an immediate (an offset). + * This code emits that 'li' instruction, but only if the offset value is + * different than the previous 'li'. + * This optimization seems to save about 10% in the instruction count. + * Note that we need to unconditionally emit an 'li' inside basic blocks + * (such as inside loops). + */ +static int +emit_li_offset(struct gen_context *gen, int offset) +{ + if (gen->offset_reg <= 0) { + /* allocate a GP register for storing load/store offset */ + gen->offset_reg = ppc_allocate_register(gen->f); + } + + /* emit new 'li' if offset is changing */ + if (gen->offset_value < 0 || gen->offset_value != offset) { + gen->offset_value = offset; + ppc_li(gen->f, gen->offset_reg, offset); + } + + return gen->offset_reg; +} + + +/** + * Forces subsequent emit_li_offset() calls to emit an 'li'. + * To be called at the top of basic blocks. + */ +static void +reset_li_offset(struct gen_context *gen) +{ + gen->offset_value = -9999999; +} + + + +/** + * Load the given vector register with {value, value, value, value}. + * The value must be in the ppu_builtin_constants[] array. + * We wouldn't need this if there was a simple way to load PPC vector + * registers with immediate values! + */ +static void +load_constant_vec(struct gen_context *gen, int dst_vec, float value) +{ + uint pos; + for (pos = 0; pos < Elements(ppc_builtin_constants); pos++) { + if (ppc_builtin_constants[pos] == value) { + int offset = pos * 4; + int offset_reg = emit_li_offset(gen, offset); + + /* Load 4-byte word into vector register. + * The vector slot depends on the effective address we load from. + * We know that our builtins start at a 16-byte boundary so we + * know that 'swizzle' tells us which vector slot will have the + * loaded word. The other vector slots will be undefined. + */ + ppc_lvewx(gen->f, dst_vec, gen->builtins_reg, offset_reg); + /* splat word[pos % 4] across the vector reg */ + ppc_vspltw(gen->f, dst_vec, dst_vec, pos % 4); + return; + } + } + assert(0 && "Need to add new constant to ppc_builtin_constants array"); +} + + +/** + * Return index of vector register containing {1.0, 1.0, 1.0, 1.0}. + */ +static int +gen_one_vec(struct gen_context *gen) +{ + if (gen->one_vec < 0) { + gen->one_vec = ppc_allocate_vec_register(gen->f); + load_constant_vec(gen, gen->one_vec, 1.0f); + } + return gen->one_vec; +} + +/** + * Return index of vector register containing {1<<31, 1<<31, 1<<31, 1<<31}. + */ +static int +gen_get_bit31_vec(struct gen_context *gen) +{ + if (gen->bit31_vec < 0) { + gen->bit31_vec = ppc_allocate_vec_register(gen->f); + ppc_vspltisw(gen->f, gen->bit31_vec, -1); + ppc_vslw(gen->f, gen->bit31_vec, gen->bit31_vec, gen->bit31_vec); + } + return gen->bit31_vec; +} + + +/** + * Register fetch. Return PPC vector register with result. + */ +static int +emit_fetch(struct gen_context *gen, + const struct tgsi_full_src_register *reg, + const unsigned chan_index) +{ + uint swizzle = tgsi_util_get_full_src_register_swizzle(reg, chan_index); + int dst_vec = -1; + + switch (swizzle) { + case TGSI_SWIZZLE_X: + case TGSI_SWIZZLE_Y: + case TGSI_SWIZZLE_Z: + case TGSI_SWIZZLE_W: + switch (reg->Register.File) { + case TGSI_FILE_INPUT: + case TGSI_FILE_SYSTEM_VALUE: + { + int offset = (reg->Register.Index * 4 + swizzle) * 16; + int offset_reg = emit_li_offset(gen, offset); + dst_vec = ppc_allocate_vec_register(gen->f); + ppc_lvx(gen->f, dst_vec, gen->inputs_reg, offset_reg); + } + break; + case TGSI_FILE_TEMPORARY: + if (is_ppc_vec_temporary(reg)) { + /* use PPC vec register */ + dst_vec = gen->temps_map[reg->Register.Index][swizzle]; + } + else { + /* use memory-based temp register "file" */ + int offset = (reg->Register.Index * 4 + swizzle) * 16; + int offset_reg = emit_li_offset(gen, offset); + dst_vec = ppc_allocate_vec_register(gen->f); + ppc_lvx(gen->f, dst_vec, gen->temps_reg, offset_reg); + } + break; + case TGSI_FILE_IMMEDIATE: + { + int offset = (reg->Register.Index * 4 + swizzle) * 4; + int offset_reg = emit_li_offset(gen, offset); + dst_vec = ppc_allocate_vec_register(gen->f); + /* Load 4-byte word into vector register. + * The vector slot depends on the effective address we load from. + * We know that our immediates start at a 16-byte boundary so we + * know that 'swizzle' tells us which vector slot will have the + * loaded word. The other vector slots will be undefined. + */ + ppc_lvewx(gen->f, dst_vec, gen->immed_reg, offset_reg); + /* splat word[swizzle] across the vector reg */ + ppc_vspltw(gen->f, dst_vec, dst_vec, swizzle); + } + break; + case TGSI_FILE_CONSTANT: + { + int offset = (reg->Register.Index * 4 + swizzle) * 4; + int offset_reg = emit_li_offset(gen, offset); + dst_vec = ppc_allocate_vec_register(gen->f); + /* Load 4-byte word into vector register. + * The vector slot depends on the effective address we load from. + * We know that our constants start at a 16-byte boundary so we + * know that 'swizzle' tells us which vector slot will have the + * loaded word. The other vector slots will be undefined. + */ + ppc_lvewx(gen->f, dst_vec, gen->const_reg, offset_reg); + /* splat word[swizzle] across the vector reg */ + ppc_vspltw(gen->f, dst_vec, dst_vec, swizzle); + } + break; + default: + assert( 0 ); + } + break; + default: + assert( 0 ); + } + + assert(dst_vec >= 0); + + { + uint sign_op = tgsi_util_get_full_src_register_sign_mode(reg, chan_index); + if (sign_op != TGSI_UTIL_SIGN_KEEP) { + int bit31_vec = gen_get_bit31_vec(gen); + int dst_vec2; + + if (is_ppc_vec_temporary(reg)) { + /* need to use a new temp */ + dst_vec2 = ppc_allocate_vec_register(gen->f); + } + else { + dst_vec2 = dst_vec; + } + + switch (sign_op) { + case TGSI_UTIL_SIGN_CLEAR: + /* vec = vec & ~bit31 */ + ppc_vandc(gen->f, dst_vec2, dst_vec, bit31_vec); + break; + case TGSI_UTIL_SIGN_SET: + /* vec = vec | bit31 */ + ppc_vor(gen->f, dst_vec2, dst_vec, bit31_vec); + break; + case TGSI_UTIL_SIGN_TOGGLE: + /* vec = vec ^ bit31 */ + ppc_vxor(gen->f, dst_vec2, dst_vec, bit31_vec); + break; + default: + assert(0); + } + return dst_vec2; + } + } + + return dst_vec; +} + + + +/** + * Test if two TGSI src registers refer to the same memory location. + * We use this to avoid redundant register loads. + */ +static boolean +equal_src_locs(const struct tgsi_full_src_register *a, uint chan_a, + const struct tgsi_full_src_register *b, uint chan_b) +{ + int swz_a, swz_b; + int sign_a, sign_b; + if (a->Register.File != b->Register.File) + return FALSE; + if (a->Register.Index != b->Register.Index) + return FALSE; + swz_a = tgsi_util_get_full_src_register_swizzle(a, chan_a); + swz_b = tgsi_util_get_full_src_register_swizzle(b, chan_b); + if (swz_a != swz_b) + return FALSE; + sign_a = tgsi_util_get_full_src_register_sign_mode(a, chan_a); + sign_b = tgsi_util_get_full_src_register_sign_mode(b, chan_b); + if (sign_a != sign_b) + return FALSE; + return TRUE; +} + + +/** + * Given a TGSI src register and channel index, return the PPC vector + * register containing the value. We use a cache to prevent re-loading + * the same register multiple times. + * \return index of PPC vector register with the desired src operand + */ +static int +get_src_vec(struct gen_context *gen, + struct tgsi_full_instruction *inst, int src_reg, uint chan) +{ + const const struct tgsi_full_src_register *src = + &inst->Src[src_reg]; + int vec; + uint i; + + /* check the cache */ + for (i = 0; i < gen->num_regs; i++) { + if (equal_src_locs(&gen->regs[i].src, gen->regs[i].chan, src, chan)) { + /* cache hit */ + assert(gen->regs[i].vec >= 0); + return gen->regs[i].vec; + } + } + + /* cache miss: allocate new vec reg and emit fetch/load code */ + vec = emit_fetch(gen, src, chan); + gen->regs[gen->num_regs].src = *src; + gen->regs[gen->num_regs].chan = chan; + gen->regs[gen->num_regs].vec = vec; + gen->num_regs++; + + assert(gen->num_regs <= Elements(gen->regs)); + + assert(vec >= 0); + + return vec; +} + + +/** + * Clear the src operand cache. To be called at the end of each emit function. + */ +static void +release_src_vecs(struct gen_context *gen) +{ + uint i; + for (i = 0; i < gen->num_regs; i++) { + const const struct tgsi_full_src_register src = gen->regs[i].src; + if (!is_ppc_vec_temporary(&src)) { + ppc_release_vec_register(gen->f, gen->regs[i].vec); + } + } + gen->num_regs = 0; +} + + + +static int +get_dst_vec(struct gen_context *gen, + const struct tgsi_full_instruction *inst, + unsigned chan_index) +{ + const struct tgsi_full_dst_register *reg = &inst->Dst[0]; + + if (is_ppc_vec_temporary_dst(reg)) { + int vec = gen->temps_map[reg->Register.Index][chan_index]; + return vec; + } + else { + return ppc_allocate_vec_register(gen->f); + } +} + + +/** + * Register store. Store 'src_vec' at location indicated by 'reg'. + * \param free_vec Should the src_vec be released when done? + */ +static void +emit_store(struct gen_context *gen, + int src_vec, + const struct tgsi_full_instruction *inst, + unsigned chan_index, + boolean free_vec) +{ + const struct tgsi_full_dst_register *reg = &inst->Dst[0]; + + switch (reg->Register.File) { + case TGSI_FILE_OUTPUT: + { + int offset = (reg->Register.Index * 4 + chan_index) * 16; + int offset_reg = emit_li_offset(gen, offset); + ppc_stvx(gen->f, src_vec, gen->outputs_reg, offset_reg); + } + break; + case TGSI_FILE_TEMPORARY: + if (is_ppc_vec_temporary_dst(reg)) { + if (!free_vec) { + int dst_vec = gen->temps_map[reg->Register.Index][chan_index]; + if (dst_vec != src_vec) + ppc_vmove(gen->f, dst_vec, src_vec); + } + free_vec = FALSE; + } + else { + int offset = (reg->Register.Index * 4 + chan_index) * 16; + int offset_reg = emit_li_offset(gen, offset); + ppc_stvx(gen->f, src_vec, gen->temps_reg, offset_reg); + } + break; +#if 0 + case TGSI_FILE_ADDRESS: + emit_addrs( + func, + xmm, + reg->Register.Index, + chan_index ); + break; +#endif + default: + assert( 0 ); + } + +#if 0 + switch( inst->Instruction.Saturate ) { + case TGSI_SAT_NONE: + break; + + case TGSI_SAT_ZERO_ONE: + /* assert( 0 ); */ + break; + + case TGSI_SAT_MINUS_PLUS_ONE: + assert( 0 ); + break; + } +#endif + + if (free_vec) + ppc_release_vec_register(gen->f, src_vec); +} + + +static void +emit_scalar_unaryop(struct gen_context *gen, struct tgsi_full_instruction *inst) +{ + int v0, v1; + uint chan_index; + + v0 = get_src_vec(gen, inst, 0, CHAN_X); + v1 = ppc_allocate_vec_register(gen->f); + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_RSQ: + /* v1 = 1.0 / sqrt(v0) */ + ppc_vrsqrtefp(gen->f, v1, v0); + break; + case TGSI_OPCODE_RCP: + /* v1 = 1.0 / v0 */ + ppc_vrefp(gen->f, v1, v0); + break; + default: + assert(0); + } + + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + emit_store(gen, v1, inst, chan_index, FALSE); + } + + release_src_vecs(gen); + ppc_release_vec_register(gen->f, v1); +} + + +static void +emit_unaryop(struct gen_context *gen, struct tgsi_full_instruction *inst) +{ + uint chan_index; + + FOR_EACH_DST0_ENABLED_CHANNEL(*inst, chan_index) { + int v0 = get_src_vec(gen, inst, 0, chan_index); /* v0 = srcreg[0] */ + int v1 = get_dst_vec(gen, inst, chan_index); + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_ABS: + /* turn off the most significant bit of each vector float word */ + { + int bit31_vec = gen_get_bit31_vec(gen); + ppc_vandc(gen->f, v1, v0, bit31_vec); /* v1 = v0 & ~bit31 */ + } + break; + case TGSI_OPCODE_FLR: + ppc_vrfim(gen->f, v1, v0); /* v1 = floor(v0) */ + break; + case TGSI_OPCODE_FRC: + ppc_vrfim(gen->f, v1, v0); /* tmp = floor(v0) */ + ppc_vsubfp(gen->f, v1, v0, v1); /* v1 = v0 - v1 */ + break; + case TGSI_OPCODE_EX2: + ppc_vexptefp(gen->f, v1, v0); /* v1 = 2^v0 */ + break; + case TGSI_OPCODE_LG2: + /* XXX this may be broken! */ + ppc_vlogefp(gen->f, v1, v0); /* v1 = log2(v0) */ + break; + case TGSI_OPCODE_MOV: + if (v0 != v1) + ppc_vmove(gen->f, v1, v0); + break; + default: + assert(0); + } + emit_store(gen, v1, inst, chan_index, TRUE); /* store v0 */ + } + + release_src_vecs(gen); +} + + +static void +emit_binop(struct gen_context *gen, struct tgsi_full_instruction *inst) +{ + int zero_vec = -1; + uint chan; + + if (inst->Instruction.Opcode == TGSI_OPCODE_MUL) { + zero_vec = ppc_allocate_vec_register(gen->f); + ppc_vzero(gen->f, zero_vec); + } + + FOR_EACH_DST0_ENABLED_CHANNEL(*inst, chan) { + /* fetch src operands */ + int v0 = get_src_vec(gen, inst, 0, chan); + int v1 = get_src_vec(gen, inst, 1, chan); + int v2 = get_dst_vec(gen, inst, chan); + + /* emit binop */ + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_ADD: + ppc_vaddfp(gen->f, v2, v0, v1); + break; + case TGSI_OPCODE_SUB: + ppc_vsubfp(gen->f, v2, v0, v1); + break; + case TGSI_OPCODE_MUL: + ppc_vmaddfp(gen->f, v2, v0, v1, zero_vec); + break; + case TGSI_OPCODE_MIN: + ppc_vminfp(gen->f, v2, v0, v1); + break; + case TGSI_OPCODE_MAX: + ppc_vmaxfp(gen->f, v2, v0, v1); + break; + default: + assert(0); + } + + /* store v2 */ + emit_store(gen, v2, inst, chan, TRUE); + } + + if (inst->Instruction.Opcode == TGSI_OPCODE_MUL) + ppc_release_vec_register(gen->f, zero_vec); + + release_src_vecs(gen); +} + + +static void +emit_triop(struct gen_context *gen, struct tgsi_full_instruction *inst) +{ + uint chan; + + FOR_EACH_DST0_ENABLED_CHANNEL(*inst, chan) { + /* fetch src operands */ + int v0 = get_src_vec(gen, inst, 0, chan); + int v1 = get_src_vec(gen, inst, 1, chan); + int v2 = get_src_vec(gen, inst, 2, chan); + int v3 = get_dst_vec(gen, inst, chan); + + /* emit ALU */ + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_MAD: + ppc_vmaddfp(gen->f, v3, v0, v1, v2); /* v3 = v0 * v1 + v2 */ + break; + case TGSI_OPCODE_LRP: + ppc_vsubfp(gen->f, v3, v1, v2); /* v3 = v1 - v2 */ + ppc_vmaddfp(gen->f, v3, v0, v3, v2); /* v3 = v0 * v3 + v2 */ + break; + default: + assert(0); + } + + /* store v3 */ + emit_store(gen, v3, inst, chan, TRUE); + } + + release_src_vecs(gen); +} + + +/** + * Vector comparisons, resulting in 1.0 or 0.0 values. + */ +static void +emit_inequality(struct gen_context *gen, struct tgsi_full_instruction *inst) +{ + uint chan; + int one_vec = gen_one_vec(gen); + + FOR_EACH_DST0_ENABLED_CHANNEL(*inst, chan) { + /* fetch src operands */ + int v0 = get_src_vec(gen, inst, 0, chan); + int v1 = get_src_vec(gen, inst, 1, chan); + int v2 = get_dst_vec(gen, inst, chan); + boolean complement = FALSE; + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_SNE: + complement = TRUE; + /* fall-through */ + case TGSI_OPCODE_SEQ: + ppc_vcmpeqfpx(gen->f, v2, v0, v1); /* v2 = v0 == v1 ? ~0 : 0 */ + break; + + case TGSI_OPCODE_SGE: + complement = TRUE; + /* fall-through */ + case TGSI_OPCODE_SLT: + ppc_vcmpgtfpx(gen->f, v2, v1, v0); /* v2 = v1 > v0 ? ~0 : 0 */ + break; + + case TGSI_OPCODE_SLE: + complement = TRUE; + /* fall-through */ + case TGSI_OPCODE_SGT: + ppc_vcmpgtfpx(gen->f, v2, v0, v1); /* v2 = v0 > v1 ? ~0 : 0 */ + break; + default: + assert(0); + } + + /* v2 is now {0,0,0,0} or {~0,~0,~0,~0} */ + + if (complement) + ppc_vandc(gen->f, v2, one_vec, v2); /* v2 = one_vec & ~v2 */ + else + ppc_vand(gen->f, v2, one_vec, v2); /* v2 = one_vec & v2 */ + + /* store v2 */ + emit_store(gen, v2, inst, chan, TRUE); + } + + release_src_vecs(gen); +} + + +static void +emit_dotprod(struct gen_context *gen, struct tgsi_full_instruction *inst) +{ + int v0, v1, v2; + uint chan_index; + + v2 = ppc_allocate_vec_register(gen->f); + + ppc_vzero(gen->f, v2); /* v2 = {0, 0, 0, 0} */ + + v0 = get_src_vec(gen, inst, 0, CHAN_X); /* v0 = src0.XXXX */ + v1 = get_src_vec(gen, inst, 1, CHAN_X); /* v1 = src1.XXXX */ + ppc_vmaddfp(gen->f, v2, v0, v1, v2); /* v2 = v0 * v1 + v2 */ + + v0 = get_src_vec(gen, inst, 0, CHAN_Y); /* v0 = src0.YYYY */ + v1 = get_src_vec(gen, inst, 1, CHAN_Y); /* v1 = src1.YYYY */ + ppc_vmaddfp(gen->f, v2, v0, v1, v2); /* v2 = v0 * v1 + v2 */ + + v0 = get_src_vec(gen, inst, 0, CHAN_Z); /* v0 = src0.ZZZZ */ + v1 = get_src_vec(gen, inst, 1, CHAN_Z); /* v1 = src1.ZZZZ */ + ppc_vmaddfp(gen->f, v2, v0, v1, v2); /* v2 = v0 * v1 + v2 */ + + if (inst->Instruction.Opcode == TGSI_OPCODE_DP4) { + v0 = get_src_vec(gen, inst, 0, CHAN_W); /* v0 = src0.WWWW */ + v1 = get_src_vec(gen, inst, 1, CHAN_W); /* v1 = src1.WWWW */ + ppc_vmaddfp(gen->f, v2, v0, v1, v2); /* v2 = v0 * v1 + v2 */ + } + else if (inst->Instruction.Opcode == TGSI_OPCODE_DPH) { + v1 = get_src_vec(gen, inst, 1, CHAN_W); /* v1 = src1.WWWW */ + ppc_vaddfp(gen->f, v2, v2, v1); /* v2 = v2 + v1 */ + } + + FOR_EACH_DST0_ENABLED_CHANNEL(*inst, chan_index) { + emit_store(gen, v2, inst, chan_index, FALSE); /* store v2, free v2 later */ + } + + release_src_vecs(gen); + + ppc_release_vec_register(gen->f, v2); +} + + +/** Approximation for vr = pow(va, vb) */ +static void +ppc_vec_pow(struct ppc_function *f, int vr, int va, int vb) +{ + /* pow(a,b) ~= exp2(log2(a) * b) */ + int t_vec = ppc_allocate_vec_register(f); + int zero_vec = ppc_allocate_vec_register(f); + + ppc_vzero(f, zero_vec); + + ppc_vlogefp(f, t_vec, va); /* t = log2(va) */ + ppc_vmaddfp(f, t_vec, t_vec, vb, zero_vec); /* t = t * vb + zero */ + ppc_vexptefp(f, vr, t_vec); /* vr = 2^t */ + + ppc_release_vec_register(f, t_vec); + ppc_release_vec_register(f, zero_vec); +} + + +static void +emit_lit(struct gen_context *gen, struct tgsi_full_instruction *inst) +{ + int one_vec = gen_one_vec(gen); + + /* Compute X */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X)) { + emit_store(gen, one_vec, inst, CHAN_X, FALSE); + } + + /* Compute Y, Z */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Y) || + IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Z)) { + int x_vec; + int zero_vec = ppc_allocate_vec_register(gen->f); + + x_vec = get_src_vec(gen, inst, 0, CHAN_X); /* x_vec = src[0].x */ + + ppc_vzero(gen->f, zero_vec); /* zero = {0,0,0,0} */ + ppc_vmaxfp(gen->f, x_vec, x_vec, zero_vec); /* x_vec = max(x_vec, 0) */ + + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Y)) { + emit_store(gen, x_vec, inst, CHAN_Y, FALSE); + } + + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Z)) { + int y_vec, w_vec; + int z_vec = ppc_allocate_vec_register(gen->f); + int pow_vec = ppc_allocate_vec_register(gen->f); + int pos_vec = ppc_allocate_vec_register(gen->f); + int p128_vec = ppc_allocate_vec_register(gen->f); + int n128_vec = ppc_allocate_vec_register(gen->f); + + y_vec = get_src_vec(gen, inst, 0, CHAN_Y); /* y_vec = src[0].y */ + ppc_vmaxfp(gen->f, y_vec, y_vec, zero_vec); /* y_vec = max(y_vec, 0) */ + + w_vec = get_src_vec(gen, inst, 0, CHAN_W); /* w_vec = src[0].w */ + + /* clamp W to [-128, 128] */ + load_constant_vec(gen, p128_vec, 128.0f); + load_constant_vec(gen, n128_vec, -128.0f); + ppc_vmaxfp(gen->f, w_vec, w_vec, n128_vec); /* w = max(w, -128) */ + ppc_vminfp(gen->f, w_vec, w_vec, p128_vec); /* w = min(w, 128) */ + + /* if temp.x > 0 + * z = pow(tmp.y, tmp.w) + * else + * z = 0.0 + */ + ppc_vec_pow(gen->f, pow_vec, y_vec, w_vec); /* pow = pow(y, w) */ + ppc_vcmpgtfpx(gen->f, pos_vec, x_vec, zero_vec); /* pos = x > 0 */ + ppc_vand(gen->f, z_vec, pow_vec, pos_vec); /* z = pow & pos */ + + emit_store(gen, z_vec, inst, CHAN_Z, FALSE); + + ppc_release_vec_register(gen->f, z_vec); + ppc_release_vec_register(gen->f, pow_vec); + ppc_release_vec_register(gen->f, pos_vec); + ppc_release_vec_register(gen->f, p128_vec); + ppc_release_vec_register(gen->f, n128_vec); + } + + ppc_release_vec_register(gen->f, zero_vec); + } + + /* Compute W */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_W)) { + emit_store(gen, one_vec, inst, CHAN_W, FALSE); + } + + release_src_vecs(gen); +} + + +static void +emit_exp(struct gen_context *gen, struct tgsi_full_instruction *inst) +{ + const int one_vec = gen_one_vec(gen); + int src_vec; + + /* get src arg */ + src_vec = get_src_vec(gen, inst, 0, CHAN_X); + + /* Compute X = 2^floor(src) */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X)) { + int dst_vec = get_dst_vec(gen, inst, CHAN_X); + int tmp_vec = ppc_allocate_vec_register(gen->f); + ppc_vrfim(gen->f, tmp_vec, src_vec); /* tmp = floor(src); */ + ppc_vexptefp(gen->f, dst_vec, tmp_vec); /* dst = 2 ^ tmp */ + emit_store(gen, dst_vec, inst, CHAN_X, TRUE); + ppc_release_vec_register(gen->f, tmp_vec); + } + + /* Compute Y = src - floor(src) */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Y)) { + int dst_vec = get_dst_vec(gen, inst, CHAN_Y); + int tmp_vec = ppc_allocate_vec_register(gen->f); + ppc_vrfim(gen->f, tmp_vec, src_vec); /* tmp = floor(src); */ + ppc_vsubfp(gen->f, dst_vec, src_vec, tmp_vec); /* dst = src - tmp */ + emit_store(gen, dst_vec, inst, CHAN_Y, TRUE); + ppc_release_vec_register(gen->f, tmp_vec); + } + + /* Compute Z = RoughApprox2ToX(src) */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Z)) { + int dst_vec = get_dst_vec(gen, inst, CHAN_Z); + ppc_vexptefp(gen->f, dst_vec, src_vec); /* dst = 2 ^ src */ + emit_store(gen, dst_vec, inst, CHAN_Z, TRUE); + } + + /* Compute W = 1.0 */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_W)) { + emit_store(gen, one_vec, inst, CHAN_W, FALSE); + } + + release_src_vecs(gen); +} + + +static void +emit_log(struct gen_context *gen, struct tgsi_full_instruction *inst) +{ + const int bit31_vec = gen_get_bit31_vec(gen); + const int one_vec = gen_one_vec(gen); + int src_vec, abs_vec; + + /* get src arg */ + src_vec = get_src_vec(gen, inst, 0, CHAN_X); + + /* compute abs(src) */ + abs_vec = ppc_allocate_vec_register(gen->f); + ppc_vandc(gen->f, abs_vec, src_vec, bit31_vec); /* abs = src & ~bit31 */ + + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X) && + IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Y)) { + + /* compute tmp = floor(log2(abs)) */ + int tmp_vec = ppc_allocate_vec_register(gen->f); + ppc_vlogefp(gen->f, tmp_vec, abs_vec); /* tmp = log2(abs) */ + ppc_vrfim(gen->f, tmp_vec, tmp_vec); /* tmp = floor(tmp); */ + + /* Compute X = tmp */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X)) { + emit_store(gen, tmp_vec, inst, CHAN_X, FALSE); + } + + /* Compute Y = abs / 2^tmp */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Y)) { + const int zero_vec = ppc_allocate_vec_register(gen->f); + ppc_vzero(gen->f, zero_vec); + ppc_vexptefp(gen->f, tmp_vec, tmp_vec); /* tmp = 2 ^ tmp */ + ppc_vrefp(gen->f, tmp_vec, tmp_vec); /* tmp = 1 / tmp */ + /* tmp = abs * tmp + zero */ + ppc_vmaddfp(gen->f, tmp_vec, abs_vec, tmp_vec, zero_vec); + emit_store(gen, tmp_vec, inst, CHAN_Y, FALSE); + ppc_release_vec_register(gen->f, zero_vec); + } + + ppc_release_vec_register(gen->f, tmp_vec); + } + + /* Compute Z = RoughApproxLog2(abs) */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Z)) { + int dst_vec = get_dst_vec(gen, inst, CHAN_Z); + ppc_vlogefp(gen->f, dst_vec, abs_vec); /* dst = log2(abs) */ + emit_store(gen, dst_vec, inst, CHAN_Z, TRUE); + } + + /* Compute W = 1.0 */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_W)) { + emit_store(gen, one_vec, inst, CHAN_W, FALSE); + } + + ppc_release_vec_register(gen->f, abs_vec); + release_src_vecs(gen); +} + + +static void +emit_pow(struct gen_context *gen, struct tgsi_full_instruction *inst) +{ + int s0_vec = get_src_vec(gen, inst, 0, CHAN_X); + int s1_vec = get_src_vec(gen, inst, 1, CHAN_X); + int pow_vec = ppc_allocate_vec_register(gen->f); + int chan; + + ppc_vec_pow(gen->f, pow_vec, s0_vec, s1_vec); + + FOR_EACH_DST0_ENABLED_CHANNEL(*inst, chan) { + emit_store(gen, pow_vec, inst, chan, FALSE); + } + + ppc_release_vec_register(gen->f, pow_vec); + + release_src_vecs(gen); +} + + +static void +emit_xpd(struct gen_context *gen, struct tgsi_full_instruction *inst) +{ + int x0_vec, y0_vec, z0_vec; + int x1_vec, y1_vec, z1_vec; + int zero_vec, tmp_vec; + int tmp2_vec; + + zero_vec = ppc_allocate_vec_register(gen->f); + ppc_vzero(gen->f, zero_vec); + + tmp_vec = ppc_allocate_vec_register(gen->f); + tmp2_vec = ppc_allocate_vec_register(gen->f); + + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Y) || + IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Z)) { + x0_vec = get_src_vec(gen, inst, 0, CHAN_X); + x1_vec = get_src_vec(gen, inst, 1, CHAN_X); + } + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X) || + IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Z)) { + y0_vec = get_src_vec(gen, inst, 0, CHAN_Y); + y1_vec = get_src_vec(gen, inst, 1, CHAN_Y); + } + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X) || + IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Y)) { + z0_vec = get_src_vec(gen, inst, 0, CHAN_Z); + z1_vec = get_src_vec(gen, inst, 1, CHAN_Z); + } + + IF_IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X) { + /* tmp = y0 * z1 */ + ppc_vmaddfp(gen->f, tmp_vec, y0_vec, z1_vec, zero_vec); + /* tmp = tmp - z0 * y1*/ + ppc_vnmsubfp(gen->f, tmp_vec, tmp_vec, z0_vec, y1_vec); + emit_store(gen, tmp_vec, inst, CHAN_X, FALSE); + } + IF_IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Y) { + /* tmp = z0 * x1 */ + ppc_vmaddfp(gen->f, tmp_vec, z0_vec, x1_vec, zero_vec); + /* tmp = tmp - x0 * z1 */ + ppc_vnmsubfp(gen->f, tmp_vec, tmp_vec, x0_vec, z1_vec); + emit_store(gen, tmp_vec, inst, CHAN_Y, FALSE); + } + IF_IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Z) { + /* tmp = x0 * y1 */ + ppc_vmaddfp(gen->f, tmp_vec, x0_vec, y1_vec, zero_vec); + /* tmp = tmp - y0 * x1 */ + ppc_vnmsubfp(gen->f, tmp_vec, tmp_vec, y0_vec, x1_vec); + emit_store(gen, tmp_vec, inst, CHAN_Z, FALSE); + } + /* W is undefined */ + + ppc_release_vec_register(gen->f, tmp_vec); + ppc_release_vec_register(gen->f, zero_vec); + release_src_vecs(gen); +} + +static int +emit_instruction(struct gen_context *gen, + struct tgsi_full_instruction *inst) +{ + + /* we don't handle saturation/clamping yet */ + if (inst->Instruction.Saturate != TGSI_SAT_NONE) + return 0; + + /* need to use extra temps to fix SOA dependencies : */ + if (tgsi_check_soa_dependencies(inst)) + return FALSE; + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_MOV: + case TGSI_OPCODE_ABS: + case TGSI_OPCODE_FLR: + case TGSI_OPCODE_FRC: + case TGSI_OPCODE_EX2: + case TGSI_OPCODE_LG2: + emit_unaryop(gen, inst); + break; + case TGSI_OPCODE_RSQ: + case TGSI_OPCODE_RCP: + emit_scalar_unaryop(gen, inst); + break; + case TGSI_OPCODE_ADD: + case TGSI_OPCODE_SUB: + case TGSI_OPCODE_MUL: + case TGSI_OPCODE_MIN: + case TGSI_OPCODE_MAX: + emit_binop(gen, inst); + break; + case TGSI_OPCODE_SEQ: + case TGSI_OPCODE_SNE: + case TGSI_OPCODE_SLT: + case TGSI_OPCODE_SGT: + case TGSI_OPCODE_SLE: + case TGSI_OPCODE_SGE: + emit_inequality(gen, inst); + break; + case TGSI_OPCODE_MAD: + case TGSI_OPCODE_LRP: + emit_triop(gen, inst); + break; + case TGSI_OPCODE_DP3: + case TGSI_OPCODE_DP4: + case TGSI_OPCODE_DPH: + emit_dotprod(gen, inst); + break; + case TGSI_OPCODE_LIT: + emit_lit(gen, inst); + break; + case TGSI_OPCODE_LOG: + emit_log(gen, inst); + break; + case TGSI_OPCODE_EXP: + emit_exp(gen, inst); + break; + case TGSI_OPCODE_POW: + emit_pow(gen, inst); + break; + case TGSI_OPCODE_XPD: + emit_xpd(gen, inst); + break; + case TGSI_OPCODE_END: + /* normal end */ + return 1; + default: + return 0; + } + return 1; +} + + +static void +emit_declaration( + struct ppc_function *func, + struct tgsi_full_declaration *decl ) +{ + if( decl->Declaration.File == TGSI_FILE_INPUT || + decl->Declaration.File == TGSI_FILE_SYSTEM_VALUE ) { +#if 0 + unsigned first, last, mask; + unsigned i, j; + + first = decl->Range.First; + last = decl->Range.Last; + mask = decl->Declaration.UsageMask; + + for( i = first; i <= last; i++ ) { + for( j = 0; j < NUM_CHANNELS; j++ ) { + if( mask & (1 << j) ) { + switch( decl->Declaration.Interpolate ) { + case TGSI_INTERPOLATE_CONSTANT: + emit_coef_a0( func, 0, i, j ); + emit_inputs( func, 0, i, j ); + break; + + case TGSI_INTERPOLATE_LINEAR: + emit_tempf( func, 0, 0, TGSI_SWIZZLE_X ); + emit_coef_dadx( func, 1, i, j ); + emit_tempf( func, 2, 0, TGSI_SWIZZLE_Y ); + emit_coef_dady( func, 3, i, j ); + emit_mul( func, 0, 1 ); /* x * dadx */ + emit_coef_a0( func, 4, i, j ); + emit_mul( func, 2, 3 ); /* y * dady */ + emit_add( func, 0, 4 ); /* x * dadx + a0 */ + emit_add( func, 0, 2 ); /* x * dadx + y * dady + a0 */ + emit_inputs( func, 0, i, j ); + break; + + case TGSI_INTERPOLATE_PERSPECTIVE: + emit_tempf( func, 0, 0, TGSI_SWIZZLE_X ); + emit_coef_dadx( func, 1, i, j ); + emit_tempf( func, 2, 0, TGSI_SWIZZLE_Y ); + emit_coef_dady( func, 3, i, j ); + emit_mul( func, 0, 1 ); /* x * dadx */ + emit_tempf( func, 4, 0, TGSI_SWIZZLE_W ); + emit_coef_a0( func, 5, i, j ); + emit_rcp( func, 4, 4 ); /* 1.0 / w */ + emit_mul( func, 2, 3 ); /* y * dady */ + emit_add( func, 0, 5 ); /* x * dadx + a0 */ + emit_add( func, 0, 2 ); /* x * dadx + y * dady + a0 */ + emit_mul( func, 0, 4 ); /* (x * dadx + y * dady + a0) / w */ + emit_inputs( func, 0, i, j ); + break; + + default: + assert( 0 ); + break; + } + } + } + } +#endif + } +} + + + +static void +emit_prologue(struct ppc_function *func) +{ + /* XXX set up stack frame */ +} + + +static void +emit_epilogue(struct ppc_function *func) +{ + ppc_comment(func, -4, "Epilogue:"); + ppc_return(func); + /* XXX restore prev stack frame */ +#if 0 + debug_printf("PPC: Emitted %u instructions\n", func->num_inst); +#endif +} + + + +/** + * Translate a TGSI vertex/fragment shader to PPC code. + * + * \param tokens the TGSI input shader + * \param func the output PPC code/function + * \param immediates buffer to place immediates, later passed to PPC func + * \return TRUE for success, FALSE if translation failed + */ +boolean +tgsi_emit_ppc(const struct tgsi_token *tokens, + struct ppc_function *func, + float (*immediates)[4], + boolean do_swizzles ) +{ + static int use_ppc_asm = -1; + struct tgsi_parse_context parse; + /*boolean instruction_phase = FALSE;*/ + unsigned ok = 1; + uint num_immediates = 0; + struct gen_context gen; + uint ic = 0; + + if (use_ppc_asm < 0) { + /* If GALLIUM_NOPPC is set, don't use PPC codegen */ + use_ppc_asm = !debug_get_bool_option("GALLIUM_NOPPC", FALSE); + } + if (!use_ppc_asm) + return FALSE; + + if (0) { + debug_printf("\n********* TGSI->PPC ********\n"); + tgsi_dump(tokens, 0); + } + + util_init_math(); + + init_gen_context(&gen, func); + + emit_prologue(func); + + tgsi_parse_init( &parse, tokens ); + + while (!tgsi_parse_end_of_tokens(&parse) && ok) { + tgsi_parse_token(&parse); + + switch (parse.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_DECLARATION: + if (parse.FullHeader.Processor.Processor == TGSI_PROCESSOR_FRAGMENT) { + emit_declaration(func, &parse.FullToken.FullDeclaration ); + } + break; + + case TGSI_TOKEN_TYPE_INSTRUCTION: + if (func->print) { + _debug_printf("# "); + ic++; + tgsi_dump_instruction(&parse.FullToken.FullInstruction, ic); + } + + ok = emit_instruction(&gen, &parse.FullToken.FullInstruction); + + if (!ok) { + uint opcode = parse.FullToken.FullInstruction.Instruction.Opcode; + debug_printf("failed to translate tgsi opcode %d (%s) to PPC (%s)\n", + opcode, + tgsi_get_opcode_name(opcode), + parse.FullHeader.Processor.Processor == TGSI_PROCESSOR_VERTEX ? + "vertex shader" : "fragment shader"); + } + break; + + case TGSI_TOKEN_TYPE_IMMEDIATE: + /* splat each immediate component into a float[4] vector for SoA */ + { + const uint size = parse.FullToken.FullImmediate.Immediate.NrTokens - 1; + uint i; + assert(size <= 4); + assert(num_immediates < TGSI_EXEC_NUM_IMMEDIATES); + for (i = 0; i < size; i++) { + immediates[num_immediates][i] = + parse.FullToken.FullImmediate.u[i].Float; + } + num_immediates++; + } + break; + + case TGSI_TOKEN_TYPE_PROPERTY: + break; + + default: + ok = 0; + assert( 0 ); + } + } + + emit_epilogue(func); + + tgsi_parse_free( &parse ); + + if (ppc_num_instructions(func) == 0) { + /* ran out of memory for instructions */ + ok = FALSE; + } + + if (!ok) + debug_printf("TGSI->PPC translation failed\n"); + + return ok; +} + +#else + +void ppc_dummy_func(void); + +void ppc_dummy_func(void) +{ +} + +#endif /* PIPE_ARCH_PPC */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_ppc.h b/src/gallium/auxiliary/tgsi/tgsi_ppc.h new file mode 100644 index 0000000..829ec07 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_ppc.h @@ -0,0 +1,51 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef TGSI_PPC_H +#define TGSI_PPC_H + +#if defined __cplusplus +extern "C" { +#endif + +struct tgsi_token; +struct ppc_function; + +extern const float ppc_builtin_constants[]; + + +boolean +tgsi_emit_ppc(const struct tgsi_token *tokens, + struct ppc_function *function, + float (*immediates)[4], + boolean do_swizzles); + +#if defined __cplusplus +} +#endif + +#endif /* TGSI_PPC_H */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_sanity.c b/src/gallium/auxiliary/tgsi/tgsi_sanity.c new file mode 100644 index 0000000..acbff10 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_sanity.c @@ -0,0 +1,563 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "util/u_prim.h" +#include "cso_cache/cso_hash.h" +#include "tgsi_sanity.h" +#include "tgsi_info.h" +#include "tgsi_iterate.h" + + +DEBUG_GET_ONCE_BOOL_OPTION(print_sanity, "TGSI_PRINT_SANITY", FALSE) + + +typedef struct { + uint file : 28; + /* max 2 dimensions */ + uint dimensions : 4; + uint indices[2]; +} scan_register; + +struct sanity_check_ctx +{ + struct tgsi_iterate_context iter; + struct cso_hash *regs_decl; + struct cso_hash *regs_used; + struct cso_hash *regs_ind_used; + + uint num_imms; + uint num_instructions; + uint index_of_END; + + uint errors; + uint warnings; + uint implied_array_size; + + boolean print; +}; + +static INLINE unsigned +scan_register_key(const scan_register *reg) +{ + unsigned key = reg->file; + key |= (reg->indices[0] << 4); + key |= (reg->indices[1] << 18); + + return key; +} + +static void +fill_scan_register1d(scan_register *reg, + uint file, uint index) +{ + reg->file = file; + reg->dimensions = 1; + reg->indices[0] = index; + reg->indices[1] = 0; +} + +static void +fill_scan_register2d(scan_register *reg, + uint file, uint index1, uint index2) +{ + reg->file = file; + reg->dimensions = 2; + reg->indices[0] = index1; + reg->indices[1] = index2; +} + +static void +scan_register_dst(scan_register *reg, + struct tgsi_full_dst_register *dst) +{ + if (dst->Register.Dimension) { + /*FIXME: right now we don't support indirect + * multidimensional addressing */ + fill_scan_register2d(reg, + dst->Register.File, + dst->Register.Index, + dst->Dimension.Index); + } else { + fill_scan_register1d(reg, + dst->Register.File, + dst->Register.Index); + } +} + +static void +scan_register_src(scan_register *reg, + struct tgsi_full_src_register *src) +{ + if (src->Register.Dimension) { + /*FIXME: right now we don't support indirect + * multidimensional addressing */ + fill_scan_register2d(reg, + src->Register.File, + src->Register.Index, + src->Dimension.Index); + } else { + fill_scan_register1d(reg, + src->Register.File, + src->Register.Index); + } +} + +static scan_register * +create_scan_register_src(struct tgsi_full_src_register *src) +{ + scan_register *reg = MALLOC(sizeof(scan_register)); + scan_register_src(reg, src); + + return reg; +} + +static scan_register * +create_scan_register_dst(struct tgsi_full_dst_register *dst) +{ + scan_register *reg = MALLOC(sizeof(scan_register)); + scan_register_dst(reg, dst); + + return reg; +} + +static void +report_error( + struct sanity_check_ctx *ctx, + const char *format, + ... ) +{ + va_list args; + + if (!ctx->print) + return; + + debug_printf( "Error : " ); + va_start( args, format ); + _debug_vprintf( format, args ); + va_end( args ); + debug_printf( "\n" ); + ctx->errors++; +} + +static void +report_warning( + struct sanity_check_ctx *ctx, + const char *format, + ... ) +{ + va_list args; + + if (!ctx->print) + return; + + debug_printf( "Warning: " ); + va_start( args, format ); + _debug_vprintf( format, args ); + va_end( args ); + debug_printf( "\n" ); + ctx->warnings++; +} + +static boolean +check_file_name( + struct sanity_check_ctx *ctx, + uint file ) +{ + if (file <= TGSI_FILE_NULL || file >= TGSI_FILE_COUNT) { + report_error( ctx, "(%u): Invalid register file name", file ); + return FALSE; + } + return TRUE; +} + +static boolean +is_register_declared( + struct sanity_check_ctx *ctx, + const scan_register *reg) +{ + void *data = cso_hash_find_data_from_template( + ctx->regs_decl, scan_register_key(reg), + (void*)reg, sizeof(scan_register)); + return data ? TRUE : FALSE; +} + +static boolean +is_any_register_declared( + struct sanity_check_ctx *ctx, + uint file ) +{ + struct cso_hash_iter iter = + cso_hash_first_node(ctx->regs_decl); + + while (!cso_hash_iter_is_null(iter)) { + scan_register *reg = (scan_register *)cso_hash_iter_data(iter); + if (reg->file == file) + return TRUE; + iter = cso_hash_iter_next(iter); + } + + return FALSE; +} + +static boolean +is_register_used( + struct sanity_check_ctx *ctx, + scan_register *reg) +{ + void *data = cso_hash_find_data_from_template( + ctx->regs_used, scan_register_key(reg), + reg, sizeof(scan_register)); + return data ? TRUE : FALSE; +} + + +static boolean +is_ind_register_used( + struct sanity_check_ctx *ctx, + scan_register *reg) +{ + return cso_hash_contains(ctx->regs_ind_used, reg->file); +} + +static const char *file_names[TGSI_FILE_COUNT] = +{ + "NULL", + "CONST", + "IN", + "OUT", + "TEMP", + "SAMP", + "ADDR", + "IMM", + "PRED", + "SV", + "IMMX", + "TEMPX" +}; + +static boolean +check_register_usage( + struct sanity_check_ctx *ctx, + scan_register *reg, + const char *name, + boolean indirect_access ) +{ + if (!check_file_name( ctx, reg->file )) { + FREE(reg); + return FALSE; + } + + if (indirect_access) { + /* Note that 'index' is an offset relative to the value of the + * address register. No range checking done here.*/ + reg->indices[0] = 0; + reg->indices[1] = 0; + if (!is_any_register_declared( ctx, reg->file )) + report_error( ctx, "%s: Undeclared %s register", file_names[reg->file], name ); + if (!is_ind_register_used(ctx, reg)) + cso_hash_insert(ctx->regs_ind_used, reg->file, reg); + else + FREE(reg); + } + else { + if (!is_register_declared( ctx, reg )) { + if (reg->dimensions == 2) { + report_error( ctx, "%s[%d][%d]: Undeclared %s register", file_names[reg->file], + reg->indices[0], reg->indices[1], name ); + } + else { + report_error( ctx, "%s[%d]: Undeclared %s register", file_names[reg->file], + reg->indices[0], name ); + } + } + if (!is_register_used( ctx, reg )) + cso_hash_insert(ctx->regs_used, scan_register_key(reg), reg); + else + FREE(reg); + } + return TRUE; +} + +static boolean +iter_instruction( + struct tgsi_iterate_context *iter, + struct tgsi_full_instruction *inst ) +{ + struct sanity_check_ctx *ctx = (struct sanity_check_ctx *) iter; + const struct tgsi_opcode_info *info; + uint i; + + if (inst->Instruction.Opcode == TGSI_OPCODE_END) { + if (ctx->index_of_END != ~0) { + report_error( ctx, "Too many END instructions" ); + } + ctx->index_of_END = ctx->num_instructions; + } + + info = tgsi_get_opcode_info( inst->Instruction.Opcode ); + if (info == NULL) { + report_error( ctx, "(%u): Invalid instruction opcode", inst->Instruction.Opcode ); + return TRUE; + } + + if (info->num_dst != inst->Instruction.NumDstRegs) { + report_error( ctx, "%s: Invalid number of destination operands, should be %u", info->mnemonic, info->num_dst ); + } + if (info->num_src != inst->Instruction.NumSrcRegs) { + report_error( ctx, "%s: Invalid number of source operands, should be %u", info->mnemonic, info->num_src ); + } + + /* Check destination and source registers' validity. + * Mark the registers as used. + */ + for (i = 0; i < inst->Instruction.NumDstRegs; i++) { + scan_register *reg = create_scan_register_dst(&inst->Dst[i]); + check_register_usage( + ctx, + reg, + "destination", + FALSE ); + if (!inst->Dst[i].Register.WriteMask) { + report_error(ctx, "Destination register has empty writemask"); + } + } + for (i = 0; i < inst->Instruction.NumSrcRegs; i++) { + scan_register *reg = create_scan_register_src(&inst->Src[i]); + check_register_usage( + ctx, + reg, + "source", + (boolean)inst->Src[i].Register.Indirect ); + if (inst->Src[i].Register.Indirect) { + scan_register *ind_reg = MALLOC(sizeof(scan_register)); + + fill_scan_register1d(ind_reg, + inst->Src[i].Indirect.File, + inst->Src[i].Indirect.Index); + check_register_usage( + ctx, + ind_reg, + "indirect", + FALSE ); + } + } + + ctx->num_instructions++; + + return TRUE; +} + +static void +check_and_declare(struct sanity_check_ctx *ctx, + scan_register *reg) +{ + if (is_register_declared( ctx, reg)) + report_error( ctx, "%s[%u]: The same register declared more than once", + file_names[reg->file], reg->indices[0] ); + cso_hash_insert(ctx->regs_decl, + scan_register_key(reg), + reg); +} + + +static boolean +iter_declaration( + struct tgsi_iterate_context *iter, + struct tgsi_full_declaration *decl ) +{ + struct sanity_check_ctx *ctx = (struct sanity_check_ctx *) iter; + uint file; + uint i; + + /* No declarations allowed after the first instruction. + */ + if (ctx->num_instructions > 0) + report_error( ctx, "Instruction expected but declaration found" ); + + /* Check registers' validity. + * Mark the registers as declared. + */ + file = decl->Declaration.File; + if (!check_file_name( ctx, file )) + return TRUE; + for (i = decl->Range.First; i <= decl->Range.Last; i++) { + /* declared TGSI_FILE_INPUT's for geometry processor + * have an implied second dimension */ + if (file == TGSI_FILE_INPUT && + ctx->iter.processor.Processor == TGSI_PROCESSOR_GEOMETRY) { + uint vert; + for (vert = 0; vert < ctx->implied_array_size; ++vert) { + scan_register *reg = MALLOC(sizeof(scan_register)); + fill_scan_register2d(reg, file, i, vert); + check_and_declare(ctx, reg); + } + } else { + scan_register *reg = MALLOC(sizeof(scan_register)); + if (decl->Declaration.Dimension) { + fill_scan_register2d(reg, file, i, decl->Dim.Index2D); + } else { + fill_scan_register1d(reg, file, i); + } + check_and_declare(ctx, reg); + } + } + + return TRUE; +} + +static boolean +iter_immediate( + struct tgsi_iterate_context *iter, + struct tgsi_full_immediate *imm ) +{ + struct sanity_check_ctx *ctx = (struct sanity_check_ctx *) iter; + scan_register *reg; + + /* No immediates allowed after the first instruction. + */ + if (ctx->num_instructions > 0) + report_error( ctx, "Instruction expected but immediate found" ); + + /* Mark the register as declared. + */ + reg = MALLOC(sizeof(scan_register)); + fill_scan_register1d(reg, TGSI_FILE_IMMEDIATE, ctx->num_imms); + cso_hash_insert(ctx->regs_decl, scan_register_key(reg), reg); + ctx->num_imms++; + + /* Check data type validity. + */ + if (imm->Immediate.DataType != TGSI_IMM_FLOAT32 && + imm->Immediate.DataType != TGSI_IMM_UINT32 && + imm->Immediate.DataType != TGSI_IMM_INT32) { + report_error( ctx, "(%u): Invalid immediate data type", imm->Immediate.DataType ); + return TRUE; + } + + return TRUE; +} + + +static boolean +iter_property( + struct tgsi_iterate_context *iter, + struct tgsi_full_property *prop ) +{ + struct sanity_check_ctx *ctx = (struct sanity_check_ctx *) iter; + + if (iter->processor.Processor == TGSI_PROCESSOR_GEOMETRY && + prop->Property.PropertyName == TGSI_PROPERTY_GS_INPUT_PRIM) { + ctx->implied_array_size = u_vertices_per_prim(prop->u[0].Data); + } + return TRUE; +} + +static boolean +epilog( + struct tgsi_iterate_context *iter ) +{ + struct sanity_check_ctx *ctx = (struct sanity_check_ctx *) iter; + + /* There must be an END instruction somewhere. + */ + if (ctx->index_of_END == ~0) { + report_error( ctx, "Missing END instruction" ); + } + + /* Check if all declared registers were used. + */ + { + struct cso_hash_iter iter = + cso_hash_first_node(ctx->regs_decl); + + while (!cso_hash_iter_is_null(iter)) { + scan_register *reg = (scan_register *)cso_hash_iter_data(iter); + if (!is_register_used(ctx, reg) && !is_ind_register_used(ctx, reg)) { + report_warning( ctx, "%s[%u]: Register never used", + file_names[reg->file], reg->indices[0] ); + } + iter = cso_hash_iter_next(iter); + } + } + + /* Print totals, if any. + */ + if (ctx->errors || ctx->warnings) + debug_printf( "%u errors, %u warnings\n", ctx->errors, ctx->warnings ); + + return TRUE; +} + +static void +regs_hash_destroy(struct cso_hash *hash) +{ + struct cso_hash_iter iter = cso_hash_first_node(hash); + while (!cso_hash_iter_is_null(iter)) { + scan_register *reg = (scan_register *)cso_hash_iter_data(iter); + iter = cso_hash_erase(hash, iter); + assert(reg->file < TGSI_FILE_COUNT); + FREE(reg); + } + cso_hash_delete(hash); +} + +boolean +tgsi_sanity_check( + const struct tgsi_token *tokens ) +{ + struct sanity_check_ctx ctx; + + ctx.iter.prolog = NULL; + ctx.iter.iterate_instruction = iter_instruction; + ctx.iter.iterate_declaration = iter_declaration; + ctx.iter.iterate_immediate = iter_immediate; + ctx.iter.iterate_property = iter_property; + ctx.iter.epilog = epilog; + + ctx.regs_decl = cso_hash_create(); + ctx.regs_used = cso_hash_create(); + ctx.regs_ind_used = cso_hash_create(); + + ctx.num_imms = 0; + ctx.num_instructions = 0; + ctx.index_of_END = ~0; + + ctx.errors = 0; + ctx.warnings = 0; + ctx.implied_array_size = 0; + ctx.print = debug_get_option_print_sanity(); + + if (!tgsi_iterate_shader( tokens, &ctx.iter )) + return FALSE; + + regs_hash_destroy(ctx.regs_decl); + regs_hash_destroy(ctx.regs_used); + regs_hash_destroy(ctx.regs_ind_used); + return ctx.errors == 0; +} diff --git a/src/gallium/auxiliary/tgsi/tgsi_sanity.h b/src/gallium/auxiliary/tgsi/tgsi_sanity.h new file mode 100644 index 0000000..73f0f41 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_sanity.h @@ -0,0 +1,50 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef TGSI_SANITY_H +#define TGSI_SANITY_H + +#include "pipe/p_shader_tokens.h" + +#if defined __cplusplus +extern "C" { +#endif + +/* Check the given token stream for errors and common mistakes. + * Diagnostic messages are printed out to the debug output, and is + * controlled by the debug option TGSI_PRINT_SANITY (default false). + * Returns TRUE if there are no errors, even though there could be some warnings. + */ +boolean +tgsi_sanity_check( + const struct tgsi_token *tokens ); + +#if defined __cplusplus +} +#endif + +#endif /* TGSI_SANITY_H */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_scan.c b/src/gallium/auxiliary/tgsi/tgsi_scan.c new file mode 100644 index 0000000..6585da3 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_scan.c @@ -0,0 +1,286 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2008 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 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. + * + **************************************************************************/ + +/** + * TGSI program scan utility. + * Used to determine which registers and instructions are used by a shader. + * + * Authors: Brian Paul + */ + + +#include "util/u_math.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "tgsi/tgsi_scan.h" + + + + +/** + * Scan the given TGSI shader to collect information such as number of + * registers used, special instructions used, etc. + * \return info the result of the scan + */ +void +tgsi_scan_shader(const struct tgsi_token *tokens, + struct tgsi_shader_info *info) +{ + uint procType, i; + struct tgsi_parse_context parse; + + memset(info, 0, sizeof(*info)); + for (i = 0; i < TGSI_FILE_COUNT; i++) + info->file_max[i] = -1; + + /** + ** Setup to begin parsing input shader + **/ + if (tgsi_parse_init( &parse, tokens ) != TGSI_PARSE_OK) { + debug_printf("tgsi_parse_init() failed in tgsi_scan_shader()!\n"); + return; + } + procType = parse.FullHeader.Processor.Processor; + assert(procType == TGSI_PROCESSOR_FRAGMENT || + procType == TGSI_PROCESSOR_VERTEX || + procType == TGSI_PROCESSOR_GEOMETRY); + + + /** + ** Loop over incoming program tokens/instructions + */ + while( !tgsi_parse_end_of_tokens( &parse ) ) { + + info->num_tokens++; + + tgsi_parse_token( &parse ); + + switch( parse.FullToken.Token.Type ) { + case TGSI_TOKEN_TYPE_INSTRUCTION: + { + const struct tgsi_full_instruction *fullinst + = &parse.FullToken.FullInstruction; + uint i; + + assert(fullinst->Instruction.Opcode < TGSI_OPCODE_LAST); + info->opcode_count[fullinst->Instruction.Opcode]++; + + for (i = 0; i < fullinst->Instruction.NumSrcRegs; i++) { + const struct tgsi_full_src_register *src = + &fullinst->Src[i]; + int ind = src->Register.Index; + + /* Mark which inputs are effectively used */ + if (src->Register.File == TGSI_FILE_INPUT) { + unsigned usage_mask; + usage_mask = tgsi_util_get_inst_usage_mask(fullinst, i); + if (src->Register.Indirect) { + for (ind = 0; ind < info->num_inputs; ++ind) { + info->input_usage_mask[ind] |= usage_mask; + } + } else { + assert(ind >= 0); + assert(ind < PIPE_MAX_SHADER_INPUTS); + info->input_usage_mask[ind] |= usage_mask; + } + } + + /* check for indirect register reads */ + if (src->Register.Indirect) { + info->indirect_files |= (1 << src->Register.File); + } + } + + /* check for indirect register writes */ + for (i = 0; i < fullinst->Instruction.NumDstRegs; i++) { + const struct tgsi_full_dst_register *dst = &fullinst->Dst[i]; + if (dst->Register.Indirect) { + info->indirect_files |= (1 << dst->Register.File); + } + } + + info->num_instructions++; + } + break; + + case TGSI_TOKEN_TYPE_DECLARATION: + { + const struct tgsi_full_declaration *fulldecl + = &parse.FullToken.FullDeclaration; + const uint file = fulldecl->Declaration.File; + uint reg; + for (reg = fulldecl->Range.First; + reg <= fulldecl->Range.Last; + reg++) { + + /* only first 32 regs will appear in this bitfield */ + info->file_mask[file] |= (1 << reg); + info->file_count[file]++; + info->file_max[file] = MAX2(info->file_max[file], (int)reg); + + if (file == TGSI_FILE_INPUT || file == TGSI_FILE_SYSTEM_VALUE) { + info->input_semantic_name[reg] = (ubyte)fulldecl->Semantic.Name; + info->input_semantic_index[reg] = (ubyte)fulldecl->Semantic.Index; + info->input_interpolate[reg] = (ubyte)fulldecl->Declaration.Interpolate; + info->input_centroid[reg] = (ubyte)fulldecl->Declaration.Centroid; + info->input_cylindrical_wrap[reg] = (ubyte)fulldecl->Declaration.CylindricalWrap; + info->num_inputs++; + } + else if (file == TGSI_FILE_OUTPUT) { + info->output_semantic_name[reg] = (ubyte)fulldecl->Semantic.Name; + info->output_semantic_index[reg] = (ubyte)fulldecl->Semantic.Index; + info->num_outputs++; + + /* extra info for special outputs */ + if (procType == TGSI_PROCESSOR_FRAGMENT && + fulldecl->Semantic.Name == TGSI_SEMANTIC_POSITION) + info->writes_z = TRUE; + if (procType == TGSI_PROCESSOR_FRAGMENT && + fulldecl->Semantic.Name == TGSI_SEMANTIC_STENCIL) + info->writes_stencil = TRUE; + if (procType == TGSI_PROCESSOR_VERTEX && + fulldecl->Semantic.Name == TGSI_SEMANTIC_EDGEFLAG) { + info->writes_edgeflag = TRUE; + } + } + + } + } + break; + + case TGSI_TOKEN_TYPE_IMMEDIATE: + { + uint reg = info->immediate_count++; + uint file = TGSI_FILE_IMMEDIATE; + + info->file_mask[file] |= (1 << reg); + info->file_count[file]++; + info->file_max[file] = MAX2(info->file_max[file], (int)reg); + } + break; + case TGSI_TOKEN_TYPE_PROPERTY: + { + const struct tgsi_full_property *fullprop + = &parse.FullToken.FullProperty; + + info->properties[info->num_properties].name = + fullprop->Property.PropertyName; + memcpy(info->properties[info->num_properties].data, + fullprop->u, 8 * sizeof(unsigned));; + + ++info->num_properties; + } + break; + + default: + assert( 0 ); + } + } + + info->uses_kill = (info->opcode_count[TGSI_OPCODE_KIL] || + info->opcode_count[TGSI_OPCODE_KILP]); + + tgsi_parse_free (&parse); +} + + + +/** + * Check if the given shader is a "passthrough" shader consisting of only + * MOV instructions of the form: MOV OUT[n], IN[n] + * + */ +boolean +tgsi_is_passthrough_shader(const struct tgsi_token *tokens) +{ + struct tgsi_parse_context parse; + + /** + ** Setup to begin parsing input shader + **/ + if (tgsi_parse_init(&parse, tokens) != TGSI_PARSE_OK) { + debug_printf("tgsi_parse_init() failed in tgsi_is_passthrough_shader()!\n"); + return FALSE; + } + + /** + ** Loop over incoming program tokens/instructions + */ + while (!tgsi_parse_end_of_tokens(&parse)) { + + tgsi_parse_token(&parse); + + switch (parse.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_INSTRUCTION: + { + struct tgsi_full_instruction *fullinst = + &parse.FullToken.FullInstruction; + const struct tgsi_full_src_register *src = + &fullinst->Src[0]; + const struct tgsi_full_dst_register *dst = + &fullinst->Dst[0]; + + /* Do a whole bunch of checks for a simple move */ + if (fullinst->Instruction.Opcode != TGSI_OPCODE_MOV || + (src->Register.File != TGSI_FILE_INPUT && + src->Register.File != TGSI_FILE_SYSTEM_VALUE) || + dst->Register.File != TGSI_FILE_OUTPUT || + src->Register.Index != dst->Register.Index || + + src->Register.Negate || + src->Register.Absolute || + + src->Register.SwizzleX != TGSI_SWIZZLE_X || + src->Register.SwizzleY != TGSI_SWIZZLE_Y || + src->Register.SwizzleZ != TGSI_SWIZZLE_Z || + src->Register.SwizzleW != TGSI_SWIZZLE_W || + + dst->Register.WriteMask != TGSI_WRITEMASK_XYZW) + { + tgsi_parse_free(&parse); + return FALSE; + } + } + break; + + case TGSI_TOKEN_TYPE_DECLARATION: + /* fall-through */ + case TGSI_TOKEN_TYPE_IMMEDIATE: + /* fall-through */ + case TGSI_TOKEN_TYPE_PROPERTY: + /* fall-through */ + default: + ; /* no-op */ + } + } + + tgsi_parse_free(&parse); + + /* if we get here, it's a pass-through shader */ + return TRUE; +} diff --git a/src/gallium/auxiliary/tgsi/tgsi_scan.h b/src/gallium/auxiliary/tgsi/tgsi_scan.h new file mode 100644 index 0000000..104097f --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_scan.h @@ -0,0 +1,90 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef TGSI_SCAN_H +#define TGSI_SCAN_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "pipe/p_shader_tokens.h" + +/** + * Shader summary info + */ +struct tgsi_shader_info +{ + uint num_tokens; + + ubyte num_inputs; + ubyte num_outputs; + ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; /**< TGSI_SEMANTIC_x */ + ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS]; + ubyte input_interpolate[PIPE_MAX_SHADER_INPUTS]; + ubyte input_centroid[PIPE_MAX_SHADER_INPUTS]; + ubyte input_usage_mask[PIPE_MAX_SHADER_INPUTS]; + ubyte input_cylindrical_wrap[PIPE_MAX_SHADER_INPUTS]; + ubyte output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; /**< TGSI_SEMANTIC_x */ + ubyte output_semantic_index[PIPE_MAX_SHADER_OUTPUTS]; + + uint file_mask[TGSI_FILE_COUNT]; /**< bitmask of declared registers */ + uint file_count[TGSI_FILE_COUNT]; /**< number of declared registers */ + int file_max[TGSI_FILE_COUNT]; /**< highest index of declared registers */ + + uint immediate_count; /**< number of immediates declared */ + uint num_instructions; + + uint opcode_count[TGSI_OPCODE_LAST]; /**< opcode histogram */ + + boolean writes_z; /**< does fragment shader write Z value? */ + boolean writes_stencil; /**< does fragment shader write stencil value? */ + boolean writes_edgeflag; /**< vertex shader outputs edgeflag */ + boolean uses_kill; /**< KIL or KILP instruction used? */ + + /** + * Bitmask indicating which register files are accessed with + * indirect addressing. The bits are (1 << TGSI_FILE_x), etc. + */ + unsigned indirect_files; + + struct { + unsigned name; + unsigned data[8]; + } properties[TGSI_PROPERTY_COUNT]; + uint num_properties; +}; + +extern void +tgsi_scan_shader(const struct tgsi_token *tokens, + struct tgsi_shader_info *info); + + +extern boolean +tgsi_is_passthrough_shader(const struct tgsi_token *tokens); + + +#endif /* TGSI_SCAN_H */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_sse2.c b/src/gallium/auxiliary/tgsi/tgsi_sse2.c new file mode 100644 index 0000000..086d983 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_sse2.c @@ -0,0 +1,3035 @@ +/************************************************************************** + * + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2009-2010 VMware, Inc. All rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL 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. + * + **************************************************************************/ + +#include "pipe/p_config.h" + +#if defined(PIPE_ARCH_X86) + +#include "util/u_debug.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#if defined(PIPE_ARCH_SSE) +#include "util/u_sse.h" +#endif +#include "tgsi/tgsi_info.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_exec.h" +#include "tgsi/tgsi_sse2.h" + +#include "rtasm/rtasm_x86sse.h" + +/* for 1/sqrt() + * + * This costs about 100fps (close to 10%) in gears: + */ +#define HIGH_PRECISION 1 + +#define FAST_MATH 1 + + +#define FOR_EACH_CHANNEL( CHAN )\ + for (CHAN = 0; CHAN < NUM_CHANNELS; CHAN++) + +#define IS_DST0_CHANNEL_ENABLED( INST, CHAN )\ + ((INST).Dst[0].Register.WriteMask & (1 << (CHAN))) + +#define IF_IS_DST0_CHANNEL_ENABLED( INST, CHAN )\ + if (IS_DST0_CHANNEL_ENABLED( INST, CHAN )) + +#define FOR_EACH_DST0_ENABLED_CHANNEL( INST, CHAN )\ + FOR_EACH_CHANNEL( CHAN )\ + IF_IS_DST0_CHANNEL_ENABLED( INST, CHAN ) + +#define CHAN_X 0 +#define CHAN_Y 1 +#define CHAN_Z 2 +#define CHAN_W 3 + +#define TEMP_ONE_I TGSI_EXEC_TEMP_ONE_I +#define TEMP_ONE_C TGSI_EXEC_TEMP_ONE_C + +#define TEMP_R0 TGSI_EXEC_TEMP_R0 +#define TEMP_ADDR TGSI_EXEC_TEMP_ADDR +#define TEMP_EXEC_MASK_I TGSI_EXEC_MASK_I +#define TEMP_EXEC_MASK_C TGSI_EXEC_MASK_C + + +/** + * X86 utility functions. + */ + +static struct x86_reg +make_xmm( + unsigned xmm ) +{ + return x86_make_reg( + file_XMM, + (enum x86_reg_name) xmm ); +} + +/** + * X86 register mapping helpers. + */ + +static struct x86_reg +get_const_base( void ) +{ + return x86_make_reg( + file_REG32, + reg_AX ); +} + +static struct x86_reg +get_machine_base( void ) +{ + return x86_make_reg( + file_REG32, + reg_CX ); +} + +static struct x86_reg +get_input_base( void ) +{ + return x86_make_disp( + get_machine_base(), + Offset(struct tgsi_exec_machine, Inputs) ); +} + +static struct x86_reg +get_output_base( void ) +{ + return x86_make_disp( + get_machine_base(), + Offset(struct tgsi_exec_machine, Outputs) ); +} + +static struct x86_reg +get_temp_base( void ) +{ + return x86_make_disp( + get_machine_base(), + Offset(struct tgsi_exec_machine, Temps) ); +} + +static struct x86_reg +get_coef_base( void ) +{ + return x86_make_reg( + file_REG32, + reg_BX ); +} + +static struct x86_reg +get_sampler_base( void ) +{ + return x86_make_reg( + file_REG32, + reg_DI ); +} + +static struct x86_reg +get_immediate_base( void ) +{ + return x86_make_reg( + file_REG32, + reg_DX ); +} + + +/** + * Data access helpers. + */ + + +static struct x86_reg +get_immediate( + unsigned vec, + unsigned chan ) +{ + return x86_make_disp( + get_immediate_base(), + (vec * 4 + chan) * 4 ); +} + +static struct x86_reg +get_const( + unsigned vec, + unsigned chan ) +{ + return x86_make_disp( + get_const_base(), + (vec * 4 + chan) * 4 ); +} + +static struct x86_reg +get_sampler_ptr( + unsigned unit ) +{ + return x86_make_disp( + get_sampler_base(), + unit * sizeof( struct tgsi_sampler * ) ); +} + +static struct x86_reg +get_input( + unsigned vec, + unsigned chan ) +{ + return x86_make_disp( + get_input_base(), + (vec * 4 + chan) * 16 ); +} + +static struct x86_reg +get_output( + unsigned vec, + unsigned chan ) +{ + return x86_make_disp( + get_output_base(), + (vec * 4 + chan) * 16 ); +} + +static struct x86_reg +get_temp( + unsigned vec, + unsigned chan ) +{ + return x86_make_disp( + get_temp_base(), + (vec * 4 + chan) * 16 ); +} + +static struct x86_reg +get_coef( + unsigned vec, + unsigned chan, + unsigned member ) +{ + return x86_make_disp( + get_coef_base(), + ((vec * 3 + member) * 4 + chan) * 4 ); +} + + +static void +emit_ret( + struct x86_function *func ) +{ + x86_ret( func ); +} + + +/** + * Data fetch helpers. + */ + +/** + * Copy a shader constant to xmm register + * \param xmm the destination xmm register + * \param vec the src const buffer index + * \param chan src channel to fetch (X, Y, Z or W) + */ +static void +emit_const( + struct x86_function *func, + uint xmm, + int vec, + uint chan, + uint indirect, + uint indirectFile, + int indirectIndex ) +{ + if (indirect) { + /* 'vec' is the offset from the address register's value. + * We're loading CONST[ADDR+vec] into an xmm register. + */ + struct x86_reg r0 = get_immediate_base(); + struct x86_reg r1 = get_coef_base(); + uint i; + + assert( indirectFile == TGSI_FILE_ADDRESS ); + assert( indirectIndex == 0 ); + assert( r0.mod == mod_REG ); + assert( r1.mod == mod_REG ); + + x86_push( func, r0 ); + x86_push( func, r1 ); + + /* + * Loop over the four pixels or vertices in the quad. + * Get the value of the address (offset) register for pixel/vertex[i], + * add it to the src offset and index into the constant buffer. + * Note that we're working on SOA data. + * If any of the pixel/vertex execution channels are unused their + * values will be garbage. It's very important that we don't use + * those garbage values as indexes into the constant buffer since + * that'll cause segfaults. + * The solution is to bitwise-AND the offset with the execution mask + * register whose values are either 0 or ~0. + * The caller must setup the execution mask register to indicate + * which channels are valid/alive before running the shader. + * The execution mask will also figure into loops and conditionals + * someday. + */ + for (i = 0; i < QUAD_SIZE; i++) { + /* r1 = address register[i] */ + x86_mov( func, r1, x86_make_disp( get_temp( TEMP_ADDR, CHAN_X ), i * 4 ) ); + /* r0 = execution mask[i] */ + x86_mov( func, r0, x86_make_disp( get_temp( TEMP_EXEC_MASK_I, TEMP_EXEC_MASK_C ), i * 4 ) ); + /* r1 = r1 & r0 */ + x86_and( func, r1, r0 ); + /* r0 = 'vec', the offset */ + x86_lea( func, r0, get_const( vec, chan ) ); + + /* Quick hack to multiply r1 by 16 -- need to add SHL to rtasm. + */ + x86_add( func, r1, r1 ); + x86_add( func, r1, r1 ); + x86_add( func, r1, r1 ); + x86_add( func, r1, r1 ); + + x86_add( func, r0, r1 ); /* r0 = r0 + r1 */ + x86_mov( func, r1, x86_deref( r0 ) ); + x86_mov( func, x86_make_disp( get_temp( TEMP_R0, CHAN_X ), i * 4 ), r1 ); + } + + x86_pop( func, r1 ); + x86_pop( func, r0 ); + + sse_movaps( + func, + make_xmm( xmm ), + get_temp( TEMP_R0, CHAN_X ) ); + } + else { + /* 'vec' is the index into the src register file, such as TEMP[vec] */ + assert( vec >= 0 ); + + sse_movss( + func, + make_xmm( xmm ), + get_const( vec, chan ) ); + sse_shufps( + func, + make_xmm( xmm ), + make_xmm( xmm ), + SHUF( 0, 0, 0, 0 ) ); + } +} + +static void +emit_immediate( + struct x86_function *func, + unsigned xmm, + unsigned vec, + unsigned chan ) +{ + sse_movss( + func, + make_xmm( xmm ), + get_immediate( vec, chan ) ); + sse_shufps( + func, + make_xmm( xmm ), + make_xmm( xmm ), + SHUF( 0, 0, 0, 0 ) ); +} + + +/** + * Copy a shader input to xmm register + * \param xmm the destination xmm register + * \param vec the src input attrib + * \param chan src channel to fetch (X, Y, Z or W) + */ +static void +emit_inputf( + struct x86_function *func, + unsigned xmm, + unsigned vec, + unsigned chan ) +{ + sse_movups( + func, + make_xmm( xmm ), + get_input( vec, chan ) ); +} + +/** + * Store an xmm register to a shader output + * \param xmm the source xmm register + * \param vec the dest output attrib + * \param chan src dest channel to store (X, Y, Z or W) + */ +static void +emit_output( + struct x86_function *func, + unsigned xmm, + unsigned vec, + unsigned chan ) +{ + sse_movups( + func, + get_output( vec, chan ), + make_xmm( xmm ) ); +} + +/** + * Copy a shader temporary to xmm register + * \param xmm the destination xmm register + * \param vec the src temp register + * \param chan src channel to fetch (X, Y, Z or W) + */ +static void +emit_tempf( + struct x86_function *func, + unsigned xmm, + unsigned vec, + unsigned chan ) +{ + sse_movaps( + func, + make_xmm( xmm ), + get_temp( vec, chan ) ); +} + +/** + * Load an xmm register with an input attrib coefficient (a0, dadx or dady) + * \param xmm the destination xmm register + * \param vec the src input/attribute coefficient index + * \param chan src channel to fetch (X, Y, Z or W) + * \param member 0=a0, 1=dadx, 2=dady + */ +static void +emit_coef( + struct x86_function *func, + unsigned xmm, + unsigned vec, + unsigned chan, + unsigned member ) +{ + sse_movss( + func, + make_xmm( xmm ), + get_coef( vec, chan, member ) ); + sse_shufps( + func, + make_xmm( xmm ), + make_xmm( xmm ), + SHUF( 0, 0, 0, 0 ) ); +} + +/** + * Data store helpers. + */ + +static void +emit_inputs( + struct x86_function *func, + unsigned xmm, + unsigned vec, + unsigned chan ) +{ + sse_movups( + func, + get_input( vec, chan ), + make_xmm( xmm ) ); +} + +static void +emit_temps( + struct x86_function *func, + unsigned xmm, + unsigned vec, + unsigned chan ) +{ + sse_movaps( + func, + get_temp( vec, chan ), + make_xmm( xmm ) ); +} + +static void +emit_addrs( + struct x86_function *func, + unsigned xmm, + unsigned vec, + unsigned chan ) +{ + assert( vec == 0 ); + + emit_temps( + func, + xmm, + vec + TGSI_EXEC_TEMP_ADDR, + chan ); +} + +/** + * Coefficent fetch helpers. + */ + +static void +emit_coef_a0( + struct x86_function *func, + unsigned xmm, + unsigned vec, + unsigned chan ) +{ + emit_coef( + func, + xmm, + vec, + chan, + 0 ); +} + +static void +emit_coef_dadx( + struct x86_function *func, + unsigned xmm, + unsigned vec, + unsigned chan ) +{ + emit_coef( + func, + xmm, + vec, + chan, + 1 ); +} + +static void +emit_coef_dady( + struct x86_function *func, + unsigned xmm, + unsigned vec, + unsigned chan ) +{ + emit_coef( + func, + xmm, + vec, + chan, + 2 ); +} + +/** + * Function call helpers. + */ + +/** + * NOTE: In gcc, if the destination uses the SSE intrinsics, then it must be + * defined with __attribute__((force_align_arg_pointer)), as we do not guarantee + * that the stack pointer is 16 byte aligned, as expected. + */ +static void +emit_func_call( + struct x86_function *func, + unsigned xmm_save_mask, + const struct x86_reg *arg, + unsigned nr_args, + void (PIPE_CDECL *code)() ) +{ + struct x86_reg ecx = x86_make_reg( file_REG32, reg_CX ); + unsigned i, n; + + x86_push( + func, + x86_make_reg( file_REG32, reg_AX) ); + x86_push( + func, + x86_make_reg( file_REG32, reg_CX) ); + x86_push( + func, + x86_make_reg( file_REG32, reg_DX) ); + + /* Store XMM regs to the stack + */ + for(i = 0, n = 0; i < 8; ++i) + if(xmm_save_mask & (1 << i)) + ++n; + + x86_sub_imm( + func, + x86_make_reg( file_REG32, reg_SP ), + n*16); + + for(i = 0, n = 0; i < 8; ++i) + if(xmm_save_mask & (1 << i)) { + sse_movups( + func, + x86_make_disp( x86_make_reg( file_REG32, reg_SP ), n*16 ), + make_xmm( i ) ); + ++n; + } + + for (i = 0; i < nr_args; i++) { + /* Load the address of the buffer we use for passing arguments and + * receiving results: + */ + x86_lea( + func, + ecx, + arg[i] ); + + /* Push actual function arguments (currently just the pointer to + * the buffer above), and call the function: + */ + x86_push( func, ecx ); + } + + x86_mov_reg_imm( func, ecx, (unsigned long) code ); + x86_call( func, ecx ); + + /* Pop the arguments (or just add an immediate to esp) + */ + for (i = 0; i < nr_args; i++) { + x86_pop(func, ecx ); + } + + /* Pop the saved XMM regs: + */ + for(i = 0, n = 0; i < 8; ++i) + if(xmm_save_mask & (1 << i)) { + sse_movups( + func, + make_xmm( i ), + x86_make_disp( x86_make_reg( file_REG32, reg_SP ), n*16 ) ); + ++n; + } + + x86_add_imm( + func, + x86_make_reg( file_REG32, reg_SP ), + n*16); + + /* Restore GP registers in a reverse order. + */ + x86_pop( + func, + x86_make_reg( file_REG32, reg_DX) ); + x86_pop( + func, + x86_make_reg( file_REG32, reg_CX) ); + x86_pop( + func, + x86_make_reg( file_REG32, reg_AX) ); +} + +static void +emit_func_call_dst_src1( + struct x86_function *func, + unsigned xmm_save, + unsigned xmm_dst, + unsigned xmm_src0, + void (PIPE_CDECL *code)() ) +{ + struct x86_reg store = get_temp( TEMP_R0, 0 ); + unsigned xmm_mask = ((1 << xmm_save) - 1) & ~(1 << xmm_dst); + + /* Store our input parameters (in xmm regs) to the buffer we use + * for passing arguments. We will pass a pointer to this buffer as + * the actual function argument. + */ + sse_movaps( + func, + store, + make_xmm( xmm_src0 ) ); + + emit_func_call( func, + xmm_mask, + &store, + 1, + code ); + + sse_movaps( + func, + make_xmm( xmm_dst ), + store ); +} + + +static void +emit_func_call_dst_src2( + struct x86_function *func, + unsigned xmm_save, + unsigned xmm_dst, + unsigned xmm_src0, + unsigned xmm_src1, + void (PIPE_CDECL *code)() ) +{ + struct x86_reg store = get_temp( TEMP_R0, 0 ); + unsigned xmm_mask = ((1 << xmm_save) - 1) & ~(1 << xmm_dst); + + /* Store two inputs to parameter buffer. + */ + sse_movaps( + func, + store, + make_xmm( xmm_src0 ) ); + + sse_movaps( + func, + x86_make_disp( store, 4 * sizeof(float) ), + make_xmm( xmm_src1 ) ); + + + /* Emit the call + */ + emit_func_call( func, + xmm_mask, + &store, + 1, + code ); + + /* Retrieve the results: + */ + sse_movaps( + func, + make_xmm( xmm_dst ), + store ); +} + + + + + +#if defined(PIPE_ARCH_SSE) + +/* + * Fast SSE2 implementation of special math functions. + */ + +#define POLY0(x, c0) _mm_set1_ps(c0) +#define POLY1(x, c0, c1) _mm_add_ps(_mm_mul_ps(POLY0(x, c1), x), _mm_set1_ps(c0)) +#define POLY2(x, c0, c1, c2) _mm_add_ps(_mm_mul_ps(POLY1(x, c1, c2), x), _mm_set1_ps(c0)) +#define POLY3(x, c0, c1, c2, c3) _mm_add_ps(_mm_mul_ps(POLY2(x, c1, c2, c3), x), _mm_set1_ps(c0)) +#define POLY4(x, c0, c1, c2, c3, c4) _mm_add_ps(_mm_mul_ps(POLY3(x, c1, c2, c3, c4), x), _mm_set1_ps(c0)) +#define POLY5(x, c0, c1, c2, c3, c4, c5) _mm_add_ps(_mm_mul_ps(POLY4(x, c1, c2, c3, c4, c5), x), _mm_set1_ps(c0)) + +#define EXP_POLY_DEGREE 3 +#define LOG_POLY_DEGREE 5 + +/** + * See http://www.devmaster.net/forums/showthread.php?p=43580 + */ +static INLINE __m128 +exp2f4(__m128 x) +{ + __m128i ipart; + __m128 fpart, expipart, expfpart; + + x = _mm_min_ps(x, _mm_set1_ps( 129.00000f)); + x = _mm_max_ps(x, _mm_set1_ps(-126.99999f)); + + /* ipart = int(x - 0.5) */ + ipart = _mm_cvtps_epi32(_mm_sub_ps(x, _mm_set1_ps(0.5f))); + + /* fpart = x - ipart */ + fpart = _mm_sub_ps(x, _mm_cvtepi32_ps(ipart)); + + /* expipart = (float) (1 << ipart) */ + expipart = _mm_castsi128_ps(_mm_slli_epi32(_mm_add_epi32(ipart, _mm_set1_epi32(127)), 23)); + + /* minimax polynomial fit of 2**x, in range [-0.5, 0.5[ */ +#if EXP_POLY_DEGREE == 5 + expfpart = POLY5(fpart, 9.9999994e-1f, 6.9315308e-1f, 2.4015361e-1f, 5.5826318e-2f, 8.9893397e-3f, 1.8775767e-3f); +#elif EXP_POLY_DEGREE == 4 + expfpart = POLY4(fpart, 1.0000026f, 6.9300383e-1f, 2.4144275e-1f, 5.2011464e-2f, 1.3534167e-2f); +#elif EXP_POLY_DEGREE == 3 + expfpart = POLY3(fpart, 9.9992520e-1f, 6.9583356e-1f, 2.2606716e-1f, 7.8024521e-2f); +#elif EXP_POLY_DEGREE == 2 + expfpart = POLY2(fpart, 1.0017247f, 6.5763628e-1f, 3.3718944e-1f); +#else +#error +#endif + + return _mm_mul_ps(expipart, expfpart); +} + + +/** + * See http://www.devmaster.net/forums/showthread.php?p=43580 + */ +static INLINE __m128 +log2f4(__m128 x) +{ + __m128i expmask = _mm_set1_epi32(0x7f800000); + __m128i mantmask = _mm_set1_epi32(0x007fffff); + __m128 one = _mm_set1_ps(1.0f); + + __m128i i = _mm_castps_si128(x); + + /* exp = (float) exponent(x) */ + __m128 exp = _mm_cvtepi32_ps(_mm_sub_epi32(_mm_srli_epi32(_mm_and_si128(i, expmask), 23), _mm_set1_epi32(127))); + + /* mant = (float) mantissa(x) */ + __m128 mant = _mm_or_ps(_mm_castsi128_ps(_mm_and_si128(i, mantmask)), one); + + __m128 logmant; + + /* Minimax polynomial fit of log2(x)/(x - 1), for x in range [1, 2[ + * These coefficients can be generate with + * http://www.boost.org/doc/libs/1_36_0/libs/math/doc/sf_and_dist/html/math_toolkit/toolkit/internals2/minimax.html + */ +#if LOG_POLY_DEGREE == 6 + logmant = POLY5(mant, 3.11578814719469302614f, -3.32419399085241980044f, 2.59883907202499966007f, -1.23152682416275988241f, 0.318212422185251071475f, -0.0344359067839062357313f); +#elif LOG_POLY_DEGREE == 5 + logmant = POLY4(mant, 2.8882704548164776201f, -2.52074962577807006663f, 1.48116647521213171641f, -0.465725644288844778798f, 0.0596515482674574969533f); +#elif LOG_POLY_DEGREE == 4 + logmant = POLY3(mant, 2.61761038894603480148f, -1.75647175389045657003f, 0.688243882994381274313f, -0.107254423828329604454f); +#elif LOG_POLY_DEGREE == 3 + logmant = POLY2(mant, 2.28330284476918490682f, -1.04913055217340124191f, 0.204446009836232697516f); +#else +#error +#endif + + /* This effectively increases the polynomial degree by one, but ensures that log2(1) == 0*/ + logmant = _mm_mul_ps(logmant, _mm_sub_ps(mant, one)); + + return _mm_add_ps(logmant, exp); +} + + +static INLINE __m128 +powf4(__m128 x, __m128 y) +{ + return exp2f4(_mm_mul_ps(log2f4(x), y)); +} + +#endif /* PIPE_ARCH_SSE */ + + + +/** + * Low-level instruction translators. + */ + +static void +emit_abs( + struct x86_function *func, + unsigned xmm ) +{ + sse_andps( + func, + make_xmm( xmm ), + get_temp( + TGSI_EXEC_TEMP_7FFFFFFF_I, + TGSI_EXEC_TEMP_7FFFFFFF_C ) ); +} + +static void +emit_add( + struct x86_function *func, + unsigned xmm_dst, + unsigned xmm_src ) +{ + sse_addps( + func, + make_xmm( xmm_dst ), + make_xmm( xmm_src ) ); +} + +static void PIPE_CDECL +cos4f( + float *store ) +{ + store[0] = cosf( store[0] ); + store[1] = cosf( store[1] ); + store[2] = cosf( store[2] ); + store[3] = cosf( store[3] ); +} + +static void +emit_cos( + struct x86_function *func, + unsigned xmm_save, + unsigned xmm_dst ) +{ + emit_func_call_dst_src1( + func, + xmm_save, + xmm_dst, + xmm_dst, + cos4f ); +} + +static void PIPE_CDECL +#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_SSE) +__attribute__((force_align_arg_pointer)) +#endif +ex24f( + float *store ) +{ +#if defined(PIPE_ARCH_SSE) + _mm_store_ps(&store[0], exp2f4( _mm_load_ps(&store[0]) )); +#else + store[0] = util_fast_exp2( store[0] ); + store[1] = util_fast_exp2( store[1] ); + store[2] = util_fast_exp2( store[2] ); + store[3] = util_fast_exp2( store[3] ); +#endif +} + +static void +emit_ex2( + struct x86_function *func, + unsigned xmm_save, + unsigned xmm_dst ) +{ + emit_func_call_dst_src1( + func, + xmm_save, + xmm_dst, + xmm_dst, + ex24f ); +} + +static void +emit_f2it( + struct x86_function *func, + unsigned xmm ) +{ + sse2_cvttps2dq( + func, + make_xmm( xmm ), + make_xmm( xmm ) ); +} + +static void +emit_i2f( + struct x86_function *func, + unsigned xmm ) +{ + sse2_cvtdq2ps( + func, + make_xmm( xmm ), + make_xmm( xmm ) ); +} + +static void PIPE_CDECL +flr4f( + float *store ) +{ + store[0] = floorf( store[0] ); + store[1] = floorf( store[1] ); + store[2] = floorf( store[2] ); + store[3] = floorf( store[3] ); +} + +static void +emit_flr( + struct x86_function *func, + unsigned xmm_save, + unsigned xmm_dst ) +{ + emit_func_call_dst_src1( + func, + xmm_save, + xmm_dst, + xmm_dst, + flr4f ); +} + +static void PIPE_CDECL +frc4f( + float *store ) +{ + store[0] -= floorf( store[0] ); + store[1] -= floorf( store[1] ); + store[2] -= floorf( store[2] ); + store[3] -= floorf( store[3] ); +} + +static void +emit_frc( + struct x86_function *func, + unsigned xmm_save, + unsigned xmm_dst ) +{ + emit_func_call_dst_src1( + func, + xmm_save, + xmm_dst, + xmm_dst, + frc4f ); +} + +static void PIPE_CDECL +#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_SSE) +__attribute__((force_align_arg_pointer)) +#endif +lg24f( + float *store ) +{ +#if defined(PIPE_ARCH_SSE) + _mm_store_ps(&store[0], log2f4( _mm_load_ps(&store[0]) )); +#else + store[0] = util_fast_log2( store[0] ); + store[1] = util_fast_log2( store[1] ); + store[2] = util_fast_log2( store[2] ); + store[3] = util_fast_log2( store[3] ); +#endif +} + +static void +emit_lg2( + struct x86_function *func, + unsigned xmm_save, + unsigned xmm_dst ) +{ + emit_func_call_dst_src1( + func, + xmm_save, + xmm_dst, + xmm_dst, + lg24f ); +} + +static void +emit_MOV( + struct x86_function *func, + unsigned xmm_dst, + unsigned xmm_src ) +{ + sse_movups( + func, + make_xmm( xmm_dst ), + make_xmm( xmm_src ) ); +} + +static void +emit_mul (struct x86_function *func, + unsigned xmm_dst, + unsigned xmm_src) +{ + sse_mulps( + func, + make_xmm( xmm_dst ), + make_xmm( xmm_src ) ); +} + +static void +emit_neg( + struct x86_function *func, + unsigned xmm ) +{ + sse_xorps( + func, + make_xmm( xmm ), + get_temp( + TGSI_EXEC_TEMP_80000000_I, + TGSI_EXEC_TEMP_80000000_C ) ); +} + +static void PIPE_CDECL +#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_SSE) +__attribute__((force_align_arg_pointer)) +#endif +pow4f( + float *store ) +{ +#if defined(PIPE_ARCH_SSE) + _mm_store_ps(&store[0], powf4( _mm_load_ps(&store[0]), _mm_load_ps(&store[4]) )); +#else + store[0] = util_fast_pow( store[0], store[4] ); + store[1] = util_fast_pow( store[1], store[5] ); + store[2] = util_fast_pow( store[2], store[6] ); + store[3] = util_fast_pow( store[3], store[7] ); +#endif +} + +static void +emit_pow( + struct x86_function *func, + unsigned xmm_save, + unsigned xmm_dst, + unsigned xmm_src0, + unsigned xmm_src1 ) +{ + emit_func_call_dst_src2( + func, + xmm_save, + xmm_dst, + xmm_src0, + xmm_src1, + pow4f ); +} + +static void +emit_rcp ( + struct x86_function *func, + unsigned xmm_dst, + unsigned xmm_src ) +{ + /* On Intel CPUs at least, this is only accurate to 12 bits -- not + * good enough. Need to either emit a proper divide or use the + * iterative technique described below in emit_rsqrt(). + */ + sse2_rcpps( + func, + make_xmm( xmm_dst ), + make_xmm( xmm_src ) ); +} + +static void PIPE_CDECL +rnd4f( + float *store ) +{ + store[0] = floorf( store[0] + 0.5f ); + store[1] = floorf( store[1] + 0.5f ); + store[2] = floorf( store[2] + 0.5f ); + store[3] = floorf( store[3] + 0.5f ); +} + +static void +emit_rnd( + struct x86_function *func, + unsigned xmm_save, + unsigned xmm_dst ) +{ + emit_func_call_dst_src1( + func, + xmm_save, + xmm_dst, + xmm_dst, + rnd4f ); +} + +static void +emit_rsqrt( + struct x86_function *func, + unsigned xmm_dst, + unsigned xmm_src ) +{ +#if HIGH_PRECISION + /* Although rsqrtps() and rcpps() are low precision on some/all SSE + * implementations, it is possible to improve its precision at + * fairly low cost, using a newton/raphson step, as below: + * + * x1 = 2 * rcpps(a) - a * rcpps(a) * rcpps(a) + * x1 = 0.5 * rsqrtps(a) * [3.0 - (a * rsqrtps(a))* rsqrtps(a)] + * + * See: http://softwarecommunity.intel.com/articles/eng/1818.htm + */ + { + struct x86_reg dst = make_xmm( xmm_dst ); + struct x86_reg src = make_xmm( xmm_src ); + struct x86_reg tmp0 = make_xmm( 2 ); + struct x86_reg tmp1 = make_xmm( 3 ); + + assert( xmm_dst != xmm_src ); + assert( xmm_dst != 2 && xmm_dst != 3 ); + assert( xmm_src != 2 && xmm_src != 3 ); + + sse_movaps( func, dst, get_temp( TGSI_EXEC_TEMP_HALF_I, TGSI_EXEC_TEMP_HALF_C ) ); + sse_movaps( func, tmp0, get_temp( TGSI_EXEC_TEMP_THREE_I, TGSI_EXEC_TEMP_THREE_C ) ); + sse_rsqrtps( func, tmp1, src ); + sse_mulps( func, src, tmp1 ); + sse_mulps( func, dst, tmp1 ); + sse_mulps( func, src, tmp1 ); + sse_subps( func, tmp0, src ); + sse_mulps( func, dst, tmp0 ); + } +#else + /* On Intel CPUs at least, this is only accurate to 12 bits -- not + * good enough. + */ + sse_rsqrtps( + func, + make_xmm( xmm_dst ), + make_xmm( xmm_src ) ); +#endif +} + +static void +emit_setsign( + struct x86_function *func, + unsigned xmm ) +{ + sse_orps( + func, + make_xmm( xmm ), + get_temp( + TGSI_EXEC_TEMP_80000000_I, + TGSI_EXEC_TEMP_80000000_C ) ); +} + +static void PIPE_CDECL +sgn4f( + float *store ) +{ + store[0] = store[0] < 0.0f ? -1.0f : store[0] > 0.0f ? 1.0f : 0.0f; + store[1] = store[1] < 0.0f ? -1.0f : store[1] > 0.0f ? 1.0f : 0.0f; + store[2] = store[2] < 0.0f ? -1.0f : store[2] > 0.0f ? 1.0f : 0.0f; + store[3] = store[3] < 0.0f ? -1.0f : store[3] > 0.0f ? 1.0f : 0.0f; +} + +static void +emit_sgn( + struct x86_function *func, + unsigned xmm_save, + unsigned xmm_dst ) +{ + emit_func_call_dst_src1( + func, + xmm_save, + xmm_dst, + xmm_dst, + sgn4f ); +} + +static void PIPE_CDECL +sin4f( + float *store ) +{ + store[0] = sinf( store[0] ); + store[1] = sinf( store[1] ); + store[2] = sinf( store[2] ); + store[3] = sinf( store[3] ); +} + +static void +emit_sin (struct x86_function *func, + unsigned xmm_save, + unsigned xmm_dst) +{ + emit_func_call_dst_src1( + func, + xmm_save, + xmm_dst, + xmm_dst, + sin4f ); +} + +static void +emit_sub( + struct x86_function *func, + unsigned xmm_dst, + unsigned xmm_src ) +{ + sse_subps( + func, + make_xmm( xmm_dst ), + make_xmm( xmm_src ) ); +} + +/** + * Register fetch. + */ +static void +emit_fetch( + struct x86_function *func, + unsigned xmm, + const struct tgsi_full_src_register *reg, + const unsigned chan_index ) +{ + unsigned swizzle = tgsi_util_get_full_src_register_swizzle( reg, chan_index ); + + switch (swizzle) { + case TGSI_SWIZZLE_X: + case TGSI_SWIZZLE_Y: + case TGSI_SWIZZLE_Z: + case TGSI_SWIZZLE_W: + switch (reg->Register.File) { + case TGSI_FILE_CONSTANT: + emit_const( + func, + xmm, + reg->Register.Index, + swizzle, + reg->Register.Indirect, + reg->Indirect.File, + reg->Indirect.Index ); + break; + + case TGSI_FILE_IMMEDIATE: + emit_immediate( + func, + xmm, + reg->Register.Index, + swizzle ); + break; + + case TGSI_FILE_INPUT: + case TGSI_FILE_SYSTEM_VALUE: + emit_inputf( + func, + xmm, + reg->Register.Index, + swizzle ); + break; + + case TGSI_FILE_TEMPORARY: + emit_tempf( + func, + xmm, + reg->Register.Index, + swizzle ); + break; + + default: + assert( 0 ); + } + break; + + default: + assert( 0 ); + } + + switch( tgsi_util_get_full_src_register_sign_mode( reg, chan_index ) ) { + case TGSI_UTIL_SIGN_CLEAR: + emit_abs( func, xmm ); + break; + + case TGSI_UTIL_SIGN_SET: + emit_setsign( func, xmm ); + break; + + case TGSI_UTIL_SIGN_TOGGLE: + emit_neg( func, xmm ); + break; + + case TGSI_UTIL_SIGN_KEEP: + break; + } +} + +#define FETCH( FUNC, INST, XMM, INDEX, CHAN )\ + emit_fetch( FUNC, XMM, &(INST).Src[INDEX], CHAN ) + +/** + * Register store. + */ +static void +emit_store( + struct x86_function *func, + unsigned xmm, + const struct tgsi_full_dst_register *reg, + const struct tgsi_full_instruction *inst, + unsigned chan_index ) +{ + switch( inst->Instruction.Saturate ) { + case TGSI_SAT_NONE: + break; + + case TGSI_SAT_ZERO_ONE: + sse_maxps( + func, + make_xmm( xmm ), + get_temp( + TGSI_EXEC_TEMP_00000000_I, + TGSI_EXEC_TEMP_00000000_C ) ); + + sse_minps( + func, + make_xmm( xmm ), + get_temp( + TGSI_EXEC_TEMP_ONE_I, + TGSI_EXEC_TEMP_ONE_C ) ); + break; + + case TGSI_SAT_MINUS_PLUS_ONE: + assert( 0 ); + break; + } + + + switch( reg->Register.File ) { + case TGSI_FILE_OUTPUT: + emit_output( + func, + xmm, + reg->Register.Index, + chan_index ); + break; + + case TGSI_FILE_TEMPORARY: + emit_temps( + func, + xmm, + reg->Register.Index, + chan_index ); + break; + + case TGSI_FILE_ADDRESS: + emit_addrs( + func, + xmm, + reg->Register.Index, + chan_index ); + break; + + default: + assert( 0 ); + } +} + +#define STORE( FUNC, INST, XMM, INDEX, CHAN )\ + emit_store( FUNC, XMM, &(INST).Dst[INDEX], &(INST), CHAN ) + + +static void PIPE_CDECL +fetch_texel( struct tgsi_sampler **sampler, + float *store ) +{ +#if 0 + uint j; + + debug_printf("%s sampler: %p (%p) store: %p\n", + __FUNCTION__, + sampler, *sampler, + store ); + + for (j = 0; j < 4; j++) + debug_printf("sample %d texcoord %f %f %f lodbias %f\n", + j, + store[0+j], + store[4+j], + store[8 + j], + store[12 + j]); +#endif + + { + float rgba[NUM_CHANNELS][QUAD_SIZE]; + (*sampler)->get_samples(*sampler, + &store[0], /* s */ + &store[4], /* t */ + &store[8], /* r */ + &store[12], /* lodbias */ + tgsi_sampler_lod_bias, + rgba); /* results */ + + memcpy( store, rgba, 16 * sizeof(float)); + } + +#if 0 + for (j = 0; j < 4; j++) + debug_printf("sample %d result %f %f %f %f\n", + j, + store[0+j], + store[4+j], + store[8+j], + store[12+j]); +#endif +} + +/** + * High-level instruction translators. + */ +static void +emit_tex( struct x86_function *func, + const struct tgsi_full_instruction *inst, + boolean lodbias, + boolean projected) +{ + const uint unit = inst->Src[1].Register.Index; + struct x86_reg args[2]; + unsigned count; + unsigned i; + + assert(inst->Instruction.Texture); + switch (inst->Texture.Texture) { + case TGSI_TEXTURE_1D: + count = 1; + break; + case TGSI_TEXTURE_2D: + case TGSI_TEXTURE_RECT: + count = 2; + break; + case TGSI_TEXTURE_SHADOW1D: + case TGSI_TEXTURE_SHADOW2D: + case TGSI_TEXTURE_SHADOWRECT: + case TGSI_TEXTURE_3D: + case TGSI_TEXTURE_CUBE: + count = 3; + break; + default: + assert(0); + return; + } + + if (lodbias) { + FETCH( func, *inst, 3, 0, 3 ); + } + else { + emit_tempf( + func, + 3, + TGSI_EXEC_TEMP_00000000_I, + TGSI_EXEC_TEMP_00000000_C ); + + } + + /* store lodbias whether enabled or not -- fetch_texel currently + * respects it always. + */ + sse_movaps( func, + get_temp( TEMP_R0, 3 ), + make_xmm( 3 ) ); + + if (projected) { + FETCH( func, *inst, 3, 0, 3 ); + + emit_rcp( func, 3, 3 ); + } + + for (i = 0; i < count; i++) { + FETCH( func, *inst, i, 0, i ); + + if (projected) { + sse_mulps( + func, + make_xmm( i ), + make_xmm( 3 ) ); + } + + /* Store in the argument buffer: + */ + sse_movaps( + func, + get_temp( TEMP_R0, i ), + make_xmm( i ) ); + } + + args[0] = get_temp( TEMP_R0, 0 ); + args[1] = get_sampler_ptr( unit ); + + emit_func_call( func, + 0, + args, + Elements(args), + fetch_texel ); + + /* If all four channels are enabled, could use a pointer to + * dst[0].x instead of TEMP_R0 for store? + */ + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, i ) { + + sse_movaps( + func, + make_xmm( 0 ), + get_temp( TEMP_R0, i ) ); + + STORE( func, *inst, 0, 0, i ); + } +} + + +static void +emit_kil( + struct x86_function *func, + const struct tgsi_full_src_register *reg ) +{ + unsigned uniquemask; + unsigned unique_count = 0; + unsigned chan_index; + unsigned i; + + /* This mask stores component bits that were already tested. Note that + * we test if the value is less than zero, so 1.0 and 0.0 need not to be + * tested. + */ + uniquemask = 0; + + FOR_EACH_CHANNEL( chan_index ) { + unsigned swizzle; + + /* unswizzle channel */ + swizzle = tgsi_util_get_full_src_register_swizzle( + reg, + chan_index ); + + /* check if the component has not been already tested */ + if( !(uniquemask & (1 << swizzle)) ) { + uniquemask |= 1 << swizzle; + + /* allocate register */ + emit_fetch( + func, + unique_count++, + reg, + chan_index ); + } + } + + x86_push( + func, + x86_make_reg( file_REG32, reg_AX ) ); + x86_push( + func, + x86_make_reg( file_REG32, reg_DX ) ); + + for (i = 0 ; i < unique_count; i++ ) { + struct x86_reg dataXMM = make_xmm(i); + + sse_cmpps( + func, + dataXMM, + get_temp( + TGSI_EXEC_TEMP_00000000_I, + TGSI_EXEC_TEMP_00000000_C ), + cc_LessThan ); + + if( i == 0 ) { + sse_movmskps( + func, + x86_make_reg( file_REG32, reg_AX ), + dataXMM ); + } + else { + sse_movmskps( + func, + x86_make_reg( file_REG32, reg_DX ), + dataXMM ); + x86_or( + func, + x86_make_reg( file_REG32, reg_AX ), + x86_make_reg( file_REG32, reg_DX ) ); + } + } + + x86_or( + func, + get_temp( + TGSI_EXEC_TEMP_KILMASK_I, + TGSI_EXEC_TEMP_KILMASK_C ), + x86_make_reg( file_REG32, reg_AX ) ); + + x86_pop( + func, + x86_make_reg( file_REG32, reg_DX ) ); + x86_pop( + func, + x86_make_reg( file_REG32, reg_AX ) ); +} + + +static void +emit_kilp( + struct x86_function *func ) +{ + /* XXX todo / fix me */ +} + + +static void +emit_setcc( + struct x86_function *func, + struct tgsi_full_instruction *inst, + enum sse_cc cc ) +{ + unsigned chan_index; + + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + FETCH( func, *inst, 1, 1, chan_index ); + sse_cmpps( + func, + make_xmm( 0 ), + make_xmm( 1 ), + cc ); + sse_andps( + func, + make_xmm( 0 ), + get_temp( + TEMP_ONE_I, + TEMP_ONE_C ) ); + STORE( func, *inst, 0, 0, chan_index ); + } +} + +static void +emit_cmp( + struct x86_function *func, + struct tgsi_full_instruction *inst ) +{ + unsigned chan_index; + + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + FETCH( func, *inst, 1, 1, chan_index ); + FETCH( func, *inst, 2, 2, chan_index ); + sse_cmpps( + func, + make_xmm( 0 ), + get_temp( + TGSI_EXEC_TEMP_00000000_I, + TGSI_EXEC_TEMP_00000000_C ), + cc_LessThan ); + sse_andps( + func, + make_xmm( 1 ), + make_xmm( 0 ) ); + sse_andnps( + func, + make_xmm( 0 ), + make_xmm( 2 ) ); + sse_orps( + func, + make_xmm( 0 ), + make_xmm( 1 ) ); + STORE( func, *inst, 0, 0, chan_index ); + } +} + + +/** + * Check if inst src/dest regs use indirect addressing into temporary, + * input or output register files. + */ +static boolean +indirect_reg_reference(const struct tgsi_full_instruction *inst) +{ + uint i; + for (i = 0; i < inst->Instruction.NumSrcRegs; i++) { + const struct tgsi_full_src_register *reg = &inst->Src[i]; + if ((reg->Register.File == TGSI_FILE_TEMPORARY || + reg->Register.File == TGSI_FILE_INPUT || + reg->Register.File == TGSI_FILE_OUTPUT) && + reg->Register.Indirect) + return TRUE; + } + for (i = 0; i < inst->Instruction.NumDstRegs; i++) { + const struct tgsi_full_dst_register *reg = &inst->Dst[i]; + if ((reg->Register.File == TGSI_FILE_TEMPORARY || + reg->Register.File == TGSI_FILE_INPUT || + reg->Register.File == TGSI_FILE_OUTPUT) && + reg->Register.Indirect) + return TRUE; + } + return FALSE; +} + + +static int +emit_instruction( + struct x86_function *func, + struct tgsi_full_instruction *inst ) +{ + unsigned chan_index; + + /* we can't handle indirect addressing into temp register file yet */ + if (indirect_reg_reference(inst)) + return FALSE; + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_ARL: + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + emit_flr(func, 0, 0); + emit_f2it( func, 0 ); + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_MOV: + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 4 + chan_index, 0, chan_index ); + } + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( func, *inst, 4 + chan_index, 0, chan_index ); + } + break; + + case TGSI_OPCODE_LIT: + if( IS_DST0_CHANNEL_ENABLED( *inst, CHAN_X ) || + IS_DST0_CHANNEL_ENABLED( *inst, CHAN_W ) ) { + emit_tempf( + func, + 0, + TEMP_ONE_I, + TEMP_ONE_C); + if( IS_DST0_CHANNEL_ENABLED( *inst, CHAN_X ) ) { + STORE( func, *inst, 0, 0, CHAN_X ); + } + if( IS_DST0_CHANNEL_ENABLED( *inst, CHAN_W ) ) { + STORE( func, *inst, 0, 0, CHAN_W ); + } + } + if( IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Y ) || + IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Z ) ) { + if( IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Y ) ) { + FETCH( func, *inst, 0, 0, CHAN_X ); + sse_maxps( + func, + make_xmm( 0 ), + get_temp( + TGSI_EXEC_TEMP_00000000_I, + TGSI_EXEC_TEMP_00000000_C ) ); + STORE( func, *inst, 0, 0, CHAN_Y ); + } + if( IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Z ) ) { + /* XMM[1] = SrcReg[0].yyyy */ + FETCH( func, *inst, 1, 0, CHAN_Y ); + /* XMM[1] = max(XMM[1], 0) */ + sse_maxps( + func, + make_xmm( 1 ), + get_temp( + TGSI_EXEC_TEMP_00000000_I, + TGSI_EXEC_TEMP_00000000_C ) ); + /* XMM[2] = SrcReg[0].wwww */ + FETCH( func, *inst, 2, 0, CHAN_W ); + /* XMM[2] = min(XMM[2], 128.0) */ + sse_minps( + func, + make_xmm( 2 ), + get_temp( + TGSI_EXEC_TEMP_128_I, + TGSI_EXEC_TEMP_128_C ) ); + /* XMM[2] = max(XMM[2], -128.0) */ + sse_maxps( + func, + make_xmm( 2 ), + get_temp( + TGSI_EXEC_TEMP_MINUS_128_I, + TGSI_EXEC_TEMP_MINUS_128_C ) ); + emit_pow( func, 3, 1, 1, 2 ); + FETCH( func, *inst, 0, 0, CHAN_X ); + sse_xorps( + func, + make_xmm( 2 ), + make_xmm( 2 ) ); + sse_cmpps( + func, + make_xmm( 2 ), + make_xmm( 0 ), + cc_LessThan ); + sse_andps( + func, + make_xmm( 2 ), + make_xmm( 1 ) ); + STORE( func, *inst, 2, 0, CHAN_Z ); + } + } + break; + + case TGSI_OPCODE_RCP: + FETCH( func, *inst, 0, 0, CHAN_X ); + emit_rcp( func, 0, 0 ); + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_RSQ: + FETCH( func, *inst, 0, 0, CHAN_X ); + emit_abs( func, 0 ); + emit_rsqrt( func, 1, 0 ); + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( func, *inst, 1, 0, chan_index ); + } + break; + + case TGSI_OPCODE_EXP: + if (IS_DST0_CHANNEL_ENABLED( *inst, CHAN_X ) || + IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Y ) || + IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Z )) { + FETCH( func, *inst, 0, 0, CHAN_X ); + if (IS_DST0_CHANNEL_ENABLED( *inst, CHAN_X ) || + IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Y )) { + emit_MOV( func, 1, 0 ); + emit_flr( func, 2, 1 ); + /* dst.x = ex2(floor(src.x)) */ + if (IS_DST0_CHANNEL_ENABLED( *inst, CHAN_X )) { + emit_MOV( func, 2, 1 ); + emit_ex2( func, 3, 2 ); + STORE( func, *inst, 2, 0, CHAN_X ); + } + /* dst.y = src.x - floor(src.x) */ + if (IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Y )) { + emit_MOV( func, 2, 0 ); + emit_sub( func, 2, 1 ); + STORE( func, *inst, 2, 0, CHAN_Y ); + } + } + /* dst.z = ex2(src.x) */ + if (IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Z )) { + emit_ex2( func, 3, 0 ); + STORE( func, *inst, 0, 0, CHAN_Z ); + } + } + /* dst.w = 1.0 */ + if (IS_DST0_CHANNEL_ENABLED( *inst, CHAN_W )) { + emit_tempf( func, 0, TEMP_ONE_I, TEMP_ONE_C ); + STORE( func, *inst, 0, 0, CHAN_W ); + } + break; + + case TGSI_OPCODE_LOG: + if (IS_DST0_CHANNEL_ENABLED( *inst, CHAN_X ) || + IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Y ) || + IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Z )) { + FETCH( func, *inst, 0, 0, CHAN_X ); + emit_abs( func, 0 ); + emit_MOV( func, 1, 0 ); + emit_lg2( func, 2, 1 ); + /* dst.z = lg2(abs(src.x)) */ + if (IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Z )) { + STORE( func, *inst, 1, 0, CHAN_Z ); + } + if (IS_DST0_CHANNEL_ENABLED( *inst, CHAN_X ) || + IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Y )) { + emit_flr( func, 2, 1 ); + /* dst.x = floor(lg2(abs(src.x))) */ + if (IS_DST0_CHANNEL_ENABLED( *inst, CHAN_X )) { + STORE( func, *inst, 1, 0, CHAN_X ); + } + /* dst.x = abs(src)/ex2(floor(lg2(abs(src.x)))) */ + if (IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Y )) { + emit_ex2( func, 2, 1 ); + emit_rcp( func, 1, 1 ); + emit_mul( func, 0, 1 ); + STORE( func, *inst, 0, 0, CHAN_Y ); + } + } + } + /* dst.w = 1.0 */ + if (IS_DST0_CHANNEL_ENABLED( *inst, CHAN_W )) { + emit_tempf( func, 0, TEMP_ONE_I, TEMP_ONE_C ); + STORE( func, *inst, 0, 0, CHAN_W ); + } + break; + + case TGSI_OPCODE_MUL: + /* do all fetches and adds, storing results in temp regs */ + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + int r = chan_index + 1; + FETCH( func, *inst, 0, 0, chan_index ); /* load xmm[0] */ + FETCH( func, *inst, r, 1, chan_index ); /* load xmm[r] */ + emit_mul( func, r, 0 ); /* xmm[r] = xmm[r] * xmm[0] */ + } + /* do all stores of the temp regs */ + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + int r = chan_index + 1; + STORE( func, *inst, r, 0, chan_index ); /* store xmm[r] */ + } + break; + + case TGSI_OPCODE_ADD: + /* do all fetches and adds, storing results in temp regs */ + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + int r = chan_index + 1; + FETCH( func, *inst, 0, 0, chan_index ); /* load xmm[0] */ + FETCH( func, *inst, r, 1, chan_index ); /* load xmm[r] */ + emit_add( func, r, 0 ); /* xmm[r] = xmm[r] + xmm[0] */ + } + /* do all stores of the temp regs */ + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + int r = chan_index + 1; + STORE( func, *inst, r, 0, chan_index ); /* store xmm[r] */ + } + break; + + case TGSI_OPCODE_DP3: + FETCH( func, *inst, 0, 0, CHAN_X ); + FETCH( func, *inst, 1, 1, CHAN_X ); + emit_mul( func, 0, 1 ); + FETCH( func, *inst, 1, 0, CHAN_Y ); + FETCH( func, *inst, 2, 1, CHAN_Y ); + emit_mul( func, 1, 2 ); + emit_add( func, 0, 1 ); + FETCH( func, *inst, 1, 0, CHAN_Z ); + FETCH( func, *inst, 2, 1, CHAN_Z ); + emit_mul( func, 1, 2 ); + emit_add( func, 0, 1 ); + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_DP4: + FETCH( func, *inst, 0, 0, CHAN_X ); + FETCH( func, *inst, 1, 1, CHAN_X ); + emit_mul( func, 0, 1 ); + FETCH( func, *inst, 1, 0, CHAN_Y ); + FETCH( func, *inst, 2, 1, CHAN_Y ); + emit_mul( func, 1, 2 ); + emit_add( func, 0, 1 ); + FETCH( func, *inst, 1, 0, CHAN_Z ); + FETCH( func, *inst, 2, 1, CHAN_Z ); + emit_mul(func, 1, 2 ); + emit_add(func, 0, 1 ); + FETCH( func, *inst, 1, 0, CHAN_W ); + FETCH( func, *inst, 2, 1, CHAN_W ); + emit_mul( func, 1, 2 ); + emit_add( func, 0, 1 ); + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_DST: + IF_IS_DST0_CHANNEL_ENABLED( *inst, CHAN_X ) { + emit_tempf( + func, + 0, + TEMP_ONE_I, + TEMP_ONE_C ); + STORE( func, *inst, 0, 0, CHAN_X ); + } + IF_IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Y ) { + FETCH( func, *inst, 0, 0, CHAN_Y ); + FETCH( func, *inst, 1, 1, CHAN_Y ); + emit_mul( func, 0, 1 ); + STORE( func, *inst, 0, 0, CHAN_Y ); + } + IF_IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Z ) { + FETCH( func, *inst, 0, 0, CHAN_Z ); + STORE( func, *inst, 0, 0, CHAN_Z ); + } + IF_IS_DST0_CHANNEL_ENABLED( *inst, CHAN_W ) { + FETCH( func, *inst, 0, 1, CHAN_W ); + STORE( func, *inst, 0, 0, CHAN_W ); + } + break; + + case TGSI_OPCODE_MIN: + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + FETCH( func, *inst, 1, 1, chan_index ); + sse_minps( + func, + make_xmm( 0 ), + make_xmm( 1 ) ); + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_MAX: + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + FETCH( func, *inst, 1, 1, chan_index ); + sse_maxps( + func, + make_xmm( 0 ), + make_xmm( 1 ) ); + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_SLT: + emit_setcc( func, inst, cc_LessThan ); + break; + + case TGSI_OPCODE_SGE: + emit_setcc( func, inst, cc_NotLessThan ); + break; + + case TGSI_OPCODE_MAD: + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + FETCH( func, *inst, 1, 1, chan_index ); + FETCH( func, *inst, 2, 2, chan_index ); + emit_mul( func, 0, 1 ); + emit_add( func, 0, 2 ); + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_SUB: + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + FETCH( func, *inst, 1, 1, chan_index ); + emit_sub( func, 0, 1 ); + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_LRP: + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + FETCH( func, *inst, 1, 1, chan_index ); + FETCH( func, *inst, 2, 2, chan_index ); + emit_sub( func, 1, 2 ); + emit_mul( func, 0, 1 ); + emit_add( func, 0, 2 ); + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_CND: + return 0; + break; + + case TGSI_OPCODE_DP2A: + FETCH( func, *inst, 0, 0, CHAN_X ); /* xmm0 = src[0].x */ + FETCH( func, *inst, 1, 1, CHAN_X ); /* xmm1 = src[1].x */ + emit_mul( func, 0, 1 ); /* xmm0 = xmm0 * xmm1 */ + FETCH( func, *inst, 1, 0, CHAN_Y ); /* xmm1 = src[0].y */ + FETCH( func, *inst, 2, 1, CHAN_Y ); /* xmm2 = src[1].y */ + emit_mul( func, 1, 2 ); /* xmm1 = xmm1 * xmm2 */ + emit_add( func, 0, 1 ); /* xmm0 = xmm0 + xmm1 */ + FETCH( func, *inst, 1, 2, CHAN_X ); /* xmm1 = src[2].x */ + emit_add( func, 0, 1 ); /* xmm0 = xmm0 + xmm1 */ + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( func, *inst, 0, 0, chan_index ); /* dest[ch] = xmm0 */ + } + break; + + case TGSI_OPCODE_FRC: + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + emit_frc( func, 0, 0 ); + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_CLAMP: + return 0; + break; + + case TGSI_OPCODE_FLR: + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + emit_flr( func, 0, 0 ); + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_ROUND: + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + emit_rnd( func, 0, 0 ); + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_EX2: + FETCH( func, *inst, 0, 0, CHAN_X ); + emit_ex2( func, 0, 0 ); + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_LG2: + FETCH( func, *inst, 0, 0, CHAN_X ); + emit_lg2( func, 0, 0 ); + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_POW: + FETCH( func, *inst, 0, 0, CHAN_X ); + FETCH( func, *inst, 1, 1, CHAN_X ); + emit_pow( func, 0, 0, 0, 1 ); + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_XPD: + /* Note: we do all stores after all operands have been fetched + * to avoid src/dst register aliasing issues for an instruction + * such as: XPD TEMP[2].xyz, TEMP[0], TEMP[2]; + */ + if( IS_DST0_CHANNEL_ENABLED( *inst, CHAN_X ) || + IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Y ) ) { + FETCH( func, *inst, 1, 1, CHAN_Z ); /* xmm[1] = src[1].z */ + FETCH( func, *inst, 3, 0, CHAN_Z ); /* xmm[3] = src[0].z */ + } + if( IS_DST0_CHANNEL_ENABLED( *inst, CHAN_X ) || + IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Z ) ) { + FETCH( func, *inst, 0, 0, CHAN_Y ); /* xmm[0] = src[0].y */ + FETCH( func, *inst, 4, 1, CHAN_Y ); /* xmm[4] = src[1].y */ + } + IF_IS_DST0_CHANNEL_ENABLED( *inst, CHAN_X ) { + emit_MOV( func, 7, 0 ); /* xmm[7] = xmm[0] */ + emit_mul( func, 7, 1 ); /* xmm[7] = xmm[2] * xmm[1] */ + emit_MOV( func, 5, 3 ); /* xmm[5] = xmm[3] */ + emit_mul( func, 5, 4 ); /* xmm[5] = xmm[5] * xmm[4] */ + emit_sub( func, 7, 5 ); /* xmm[7] = xmm[2] - xmm[5] */ + /* store xmm[7] in dst.x below */ + } + if( IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Y ) || + IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Z ) ) { + FETCH( func, *inst, 2, 1, CHAN_X ); /* xmm[2] = src[1].x */ + FETCH( func, *inst, 5, 0, CHAN_X ); /* xmm[5] = src[0].x */ + } + IF_IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Y ) { + emit_mul( func, 3, 2 ); /* xmm[3] = xmm[3] * xmm[2] */ + emit_mul( func, 1, 5 ); /* xmm[1] = xmm[1] * xmm[5] */ + emit_sub( func, 3, 1 ); /* xmm[3] = xmm[3] - xmm[1] */ + /* store xmm[3] in dst.y below */ + } + IF_IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Z ) { + emit_mul( func, 5, 4 ); /* xmm[5] = xmm[5] * xmm[4] */ + emit_mul( func, 0, 2 ); /* xmm[0] = xmm[0] * xmm[2] */ + emit_sub( func, 5, 0 ); /* xmm[5] = xmm[5] - xmm[0] */ + STORE( func, *inst, 5, 0, CHAN_Z ); /* dst.z = xmm[5] */ + } + IF_IS_DST0_CHANNEL_ENABLED( *inst, CHAN_X ) { + STORE( func, *inst, 7, 0, CHAN_X ); /* dst.x = xmm[7] */ + } + IF_IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Y ) { + STORE( func, *inst, 3, 0, CHAN_Y ); /* dst.y = xmm[3] */ + } + IF_IS_DST0_CHANNEL_ENABLED( *inst, CHAN_W ) { + emit_tempf( + func, + 0, + TEMP_ONE_I, + TEMP_ONE_C ); + STORE( func, *inst, 0, 0, CHAN_W ); + } + break; + + case TGSI_OPCODE_ABS: + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + emit_abs( func, 0) ; + + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_RCC: + return 0; + break; + + case TGSI_OPCODE_DPH: + FETCH( func, *inst, 0, 0, CHAN_X ); + FETCH( func, *inst, 1, 1, CHAN_X ); + emit_mul( func, 0, 1 ); + FETCH( func, *inst, 1, 0, CHAN_Y ); + FETCH( func, *inst, 2, 1, CHAN_Y ); + emit_mul( func, 1, 2 ); + emit_add( func, 0, 1 ); + FETCH( func, *inst, 1, 0, CHAN_Z ); + FETCH( func, *inst, 2, 1, CHAN_Z ); + emit_mul( func, 1, 2 ); + emit_add( func, 0, 1 ); + FETCH( func, *inst, 1, 1, CHAN_W ); + emit_add( func, 0, 1 ); + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_COS: + FETCH( func, *inst, 0, 0, CHAN_X ); + emit_cos( func, 0, 0 ); + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_DDX: + return 0; + break; + + case TGSI_OPCODE_DDY: + return 0; + break; + + case TGSI_OPCODE_KILP: + /* predicated kill */ + emit_kilp( func ); + return 0; /* XXX fix me */ + break; + + case TGSI_OPCODE_KIL: + /* conditional kill */ + emit_kil( func, &inst->Src[0] ); + break; + + case TGSI_OPCODE_PK2H: + return 0; + break; + + case TGSI_OPCODE_PK2US: + return 0; + break; + + case TGSI_OPCODE_PK4B: + return 0; + break; + + case TGSI_OPCODE_PK4UB: + return 0; + break; + + case TGSI_OPCODE_RFL: + return 0; + break; + + case TGSI_OPCODE_SEQ: + emit_setcc( func, inst, cc_Equal ); + break; + + case TGSI_OPCODE_SFL: + return 0; + break; + + case TGSI_OPCODE_SGT: + emit_setcc( func, inst, cc_NotLessThanEqual ); + break; + + case TGSI_OPCODE_SIN: + FETCH( func, *inst, 0, 0, CHAN_X ); + emit_sin( func, 0, 0 ); + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_SLE: + emit_setcc( func, inst, cc_LessThanEqual ); + break; + + case TGSI_OPCODE_SNE: + emit_setcc( func, inst, cc_NotEqual ); + break; + + case TGSI_OPCODE_STR: + return 0; + break; + + case TGSI_OPCODE_TEX: + emit_tex( func, inst, FALSE, FALSE ); + break; + + case TGSI_OPCODE_TXD: + return 0; + break; + + case TGSI_OPCODE_UP2H: + return 0; + break; + + case TGSI_OPCODE_UP2US: + return 0; + break; + + case TGSI_OPCODE_UP4B: + return 0; + break; + + case TGSI_OPCODE_UP4UB: + return 0; + break; + + case TGSI_OPCODE_X2D: + return 0; + break; + + case TGSI_OPCODE_ARA: + return 0; + break; + + case TGSI_OPCODE_ARR: + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + emit_rnd( func, 0, 0 ); + emit_f2it( func, 0 ); + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_BRA: + return 0; + break; + + case TGSI_OPCODE_CAL: + return 0; + break; + + case TGSI_OPCODE_RET: + emit_ret( func ); + break; + + case TGSI_OPCODE_END: + break; + + case TGSI_OPCODE_SSG: + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + emit_sgn( func, 0, 0 ); + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_CMP: + emit_cmp (func, inst); + break; + + case TGSI_OPCODE_SCS: + IF_IS_DST0_CHANNEL_ENABLED( *inst, CHAN_X ) { + FETCH( func, *inst, 0, 0, CHAN_X ); + emit_cos( func, 0, 0 ); + STORE( func, *inst, 0, 0, CHAN_X ); + } + IF_IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Y ) { + FETCH( func, *inst, 0, 0, CHAN_X ); + emit_sin( func, 0, 0 ); + STORE( func, *inst, 0, 0, CHAN_Y ); + } + IF_IS_DST0_CHANNEL_ENABLED( *inst, CHAN_Z ) { + emit_tempf( + func, + 0, + TGSI_EXEC_TEMP_00000000_I, + TGSI_EXEC_TEMP_00000000_C ); + STORE( func, *inst, 0, 0, CHAN_Z ); + } + IF_IS_DST0_CHANNEL_ENABLED( *inst, CHAN_W ) { + emit_tempf( + func, + 0, + TEMP_ONE_I, + TEMP_ONE_C ); + STORE( func, *inst, 0, 0, CHAN_W ); + } + break; + + case TGSI_OPCODE_TXB: + emit_tex( func, inst, TRUE, FALSE ); + break; + + case TGSI_OPCODE_NRM: + /* fall-through */ + case TGSI_OPCODE_NRM4: + /* 3 or 4-component normalization */ + { + uint dims = (inst->Instruction.Opcode == TGSI_OPCODE_NRM) ? 3 : 4; + + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X) || + IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Y) || + IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Z) || + (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_W) && dims == 4)) { + + /* NOTE: Cannot use xmm regs 2/3 here (see emit_rsqrt() above). */ + + /* xmm4 = src.x */ + /* xmm0 = src.x * src.x */ + FETCH(func, *inst, 0, 0, CHAN_X); + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X)) { + emit_MOV(func, 4, 0); + } + emit_mul(func, 0, 0); + + /* xmm5 = src.y */ + /* xmm0 = xmm0 + src.y * src.y */ + FETCH(func, *inst, 1, 0, CHAN_Y); + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Y)) { + emit_MOV(func, 5, 1); + } + emit_mul(func, 1, 1); + emit_add(func, 0, 1); + + /* xmm6 = src.z */ + /* xmm0 = xmm0 + src.z * src.z */ + FETCH(func, *inst, 1, 0, CHAN_Z); + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Z)) { + emit_MOV(func, 6, 1); + } + emit_mul(func, 1, 1); + emit_add(func, 0, 1); + + if (dims == 4) { + /* xmm7 = src.w */ + /* xmm0 = xmm0 + src.w * src.w */ + FETCH(func, *inst, 1, 0, CHAN_W); + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_W)) { + emit_MOV(func, 7, 1); + } + emit_mul(func, 1, 1); + emit_add(func, 0, 1); + } + + /* xmm1 = 1 / sqrt(xmm0) */ + emit_rsqrt(func, 1, 0); + + /* dst.x = xmm1 * src.x */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X)) { + emit_mul(func, 4, 1); + STORE(func, *inst, 4, 0, CHAN_X); + } + + /* dst.y = xmm1 * src.y */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Y)) { + emit_mul(func, 5, 1); + STORE(func, *inst, 5, 0, CHAN_Y); + } + + /* dst.z = xmm1 * src.z */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_Z)) { + emit_mul(func, 6, 1); + STORE(func, *inst, 6, 0, CHAN_Z); + } + + /* dst.w = xmm1 * src.w */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_X) && dims == 4) { + emit_mul(func, 7, 1); + STORE(func, *inst, 7, 0, CHAN_W); + } + } + + /* dst0.w = 1.0 */ + if (IS_DST0_CHANNEL_ENABLED(*inst, CHAN_W) && dims == 3) { + emit_tempf(func, 0, TEMP_ONE_I, TEMP_ONE_C); + STORE(func, *inst, 0, 0, CHAN_W); + } + } + break; + + case TGSI_OPCODE_DIV: + return 0; + break; + + case TGSI_OPCODE_DP2: + FETCH( func, *inst, 0, 0, CHAN_X ); /* xmm0 = src[0].x */ + FETCH( func, *inst, 1, 1, CHAN_X ); /* xmm1 = src[1].x */ + emit_mul( func, 0, 1 ); /* xmm0 = xmm0 * xmm1 */ + FETCH( func, *inst, 1, 0, CHAN_Y ); /* xmm1 = src[0].y */ + FETCH( func, *inst, 2, 1, CHAN_Y ); /* xmm2 = src[1].y */ + emit_mul( func, 1, 2 ); /* xmm1 = xmm1 * xmm2 */ + emit_add( func, 0, 1 ); /* xmm0 = xmm0 + xmm1 */ + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( func, *inst, 0, 0, chan_index ); /* dest[ch] = xmm0 */ + } + break; + + case TGSI_OPCODE_TXL: + return 0; + break; + + case TGSI_OPCODE_TXP: + emit_tex( func, inst, FALSE, TRUE ); + break; + + case TGSI_OPCODE_BRK: + return 0; + break; + + case TGSI_OPCODE_IF: + return 0; + break; + + case TGSI_OPCODE_ELSE: + return 0; + break; + + case TGSI_OPCODE_ENDIF: + return 0; + break; + + case TGSI_OPCODE_PUSHA: + return 0; + break; + + case TGSI_OPCODE_POPA: + return 0; + break; + + case TGSI_OPCODE_CEIL: + return 0; + break; + + case TGSI_OPCODE_I2F: + return 0; + break; + + case TGSI_OPCODE_NOT: + return 0; + break; + + case TGSI_OPCODE_TRUNC: + FOR_EACH_DST0_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( func, *inst, 0, 0, chan_index ); + emit_f2it( func, 0 ); + emit_i2f( func, 0 ); + STORE( func, *inst, 0, 0, chan_index ); + } + break; + + case TGSI_OPCODE_SHL: + return 0; + break; + + case TGSI_OPCODE_ISHR: + return 0; + break; + + case TGSI_OPCODE_AND: + return 0; + break; + + case TGSI_OPCODE_OR: + return 0; + break; + + case TGSI_OPCODE_MOD: + return 0; + break; + + case TGSI_OPCODE_XOR: + return 0; + break; + + case TGSI_OPCODE_SAD: + return 0; + break; + + case TGSI_OPCODE_TXF: + return 0; + break; + + case TGSI_OPCODE_TXQ: + return 0; + break; + + case TGSI_OPCODE_CONT: + return 0; + break; + + case TGSI_OPCODE_EMIT: + return 0; + break; + + case TGSI_OPCODE_ENDPRIM: + return 0; + break; + + default: + return 0; + } + + return 1; +} + +static void +emit_declaration( + struct x86_function *func, + struct tgsi_full_declaration *decl ) +{ + if( decl->Declaration.File == TGSI_FILE_INPUT || + decl->Declaration.File == TGSI_FILE_SYSTEM_VALUE ) { + unsigned first, last, mask; + unsigned i, j; + + first = decl->Range.First; + last = decl->Range.Last; + mask = decl->Declaration.UsageMask; + + for( i = first; i <= last; i++ ) { + for( j = 0; j < NUM_CHANNELS; j++ ) { + if( mask & (1 << j) ) { + switch( decl->Declaration.Interpolate ) { + case TGSI_INTERPOLATE_CONSTANT: + emit_coef_a0( func, 0, i, j ); + emit_inputs( func, 0, i, j ); + break; + + case TGSI_INTERPOLATE_LINEAR: + emit_tempf( func, 0, 0, TGSI_SWIZZLE_X ); + emit_coef_dadx( func, 1, i, j ); + emit_tempf( func, 2, 0, TGSI_SWIZZLE_Y ); + emit_coef_dady( func, 3, i, j ); + emit_mul( func, 0, 1 ); /* x * dadx */ + emit_coef_a0( func, 4, i, j ); + emit_mul( func, 2, 3 ); /* y * dady */ + emit_add( func, 0, 4 ); /* x * dadx + a0 */ + emit_add( func, 0, 2 ); /* x * dadx + y * dady + a0 */ + emit_inputs( func, 0, i, j ); + break; + + case TGSI_INTERPOLATE_PERSPECTIVE: + emit_tempf( func, 0, 0, TGSI_SWIZZLE_X ); + emit_coef_dadx( func, 1, i, j ); + emit_tempf( func, 2, 0, TGSI_SWIZZLE_Y ); + emit_coef_dady( func, 3, i, j ); + emit_mul( func, 0, 1 ); /* x * dadx */ + emit_tempf( func, 4, 0, TGSI_SWIZZLE_W ); + emit_coef_a0( func, 5, i, j ); + emit_rcp( func, 4, 4 ); /* 1.0 / w */ + emit_mul( func, 2, 3 ); /* y * dady */ + emit_add( func, 0, 5 ); /* x * dadx + a0 */ + emit_add( func, 0, 2 ); /* x * dadx + y * dady + a0 */ + emit_mul( func, 0, 4 ); /* (x * dadx + y * dady + a0) / w */ + emit_inputs( func, 0, i, j ); + break; + + default: + assert( 0 ); + break; + } + } + } + } + } +} + +static void aos_to_soa( struct x86_function *func, + uint arg_aos, + uint arg_machine, + uint arg_num, + uint arg_stride ) +{ + struct x86_reg soa_input = x86_make_reg( file_REG32, reg_AX ); + struct x86_reg aos_input = x86_make_reg( file_REG32, reg_BX ); + struct x86_reg num_inputs = x86_make_reg( file_REG32, reg_CX ); + struct x86_reg stride = x86_make_reg( file_REG32, reg_DX ); + int loop_top, loop_exit_fixup; + + /* Save EBX */ + x86_push( func, x86_make_reg( file_REG32, reg_BX ) ); + + x86_mov( func, aos_input, x86_fn_arg( func, arg_aos ) ); + x86_mov( func, soa_input, x86_fn_arg( func, arg_machine ) ); + x86_lea( func, soa_input, + x86_make_disp( soa_input, + Offset(struct tgsi_exec_machine, Inputs) ) ); + x86_mov( func, num_inputs, x86_fn_arg( func, arg_num ) ); + x86_mov( func, stride, x86_fn_arg( func, arg_stride ) ); + + /* while (num_inputs != 0) */ + loop_top = x86_get_label( func ); + x86_cmp_imm( func, num_inputs, 0 ); + loop_exit_fixup = x86_jcc_forward( func, cc_E ); + + { + x86_push( func, aos_input ); + sse_movlps( func, make_xmm( 0 ), x86_make_disp( aos_input, 0 ) ); + sse_movlps( func, make_xmm( 3 ), x86_make_disp( aos_input, 8 ) ); + x86_add( func, aos_input, stride ); + sse_movhps( func, make_xmm( 0 ), x86_make_disp( aos_input, 0 ) ); + sse_movhps( func, make_xmm( 3 ), x86_make_disp( aos_input, 8 ) ); + x86_add( func, aos_input, stride ); + sse_movlps( func, make_xmm( 1 ), x86_make_disp( aos_input, 0 ) ); + sse_movlps( func, make_xmm( 4 ), x86_make_disp( aos_input, 8 ) ); + x86_add( func, aos_input, stride ); + sse_movhps( func, make_xmm( 1 ), x86_make_disp( aos_input, 0 ) ); + sse_movhps( func, make_xmm( 4 ), x86_make_disp( aos_input, 8 ) ); + x86_pop( func, aos_input ); + + sse_movaps( func, make_xmm( 2 ), make_xmm( 0 ) ); + sse_movaps( func, make_xmm( 5 ), make_xmm( 3 ) ); + sse_shufps( func, make_xmm( 0 ), make_xmm( 1 ), 0x88 ); + sse_shufps( func, make_xmm( 2 ), make_xmm( 1 ), 0xdd ); + sse_shufps( func, make_xmm( 3 ), make_xmm( 4 ), 0x88 ); + sse_shufps( func, make_xmm( 5 ), make_xmm( 4 ), 0xdd ); + + sse_movups( func, x86_make_disp( soa_input, 0 ), make_xmm( 0 ) ); + sse_movups( func, x86_make_disp( soa_input, 16 ), make_xmm( 2 ) ); + sse_movups( func, x86_make_disp( soa_input, 32 ), make_xmm( 3 ) ); + sse_movups( func, x86_make_disp( soa_input, 48 ), make_xmm( 5 ) ); + + /* Advance to next input */ + x86_lea( func, aos_input, x86_make_disp(aos_input, 16) ); + x86_lea( func, soa_input, x86_make_disp(soa_input, 64) ); + } + /* --num_inputs */ + x86_dec( func, num_inputs ); + x86_jmp( func, loop_top ); + x86_fixup_fwd_jump( func, loop_exit_fixup ); + + /* Restore EBX */ + x86_pop( func, x86_make_reg( file_REG32, reg_BX ) ); +} + +static void soa_to_aos( struct x86_function *func, + uint arg_aos, + uint arg_machine, + uint arg_num, + uint arg_stride ) +{ + struct x86_reg soa_output = x86_make_reg( file_REG32, reg_AX ); + struct x86_reg aos_output = x86_make_reg( file_REG32, reg_BX ); + struct x86_reg num_outputs = x86_make_reg( file_REG32, reg_CX ); + struct x86_reg temp = x86_make_reg( file_REG32, reg_DX ); + int inner_loop; + + /* Save EBX */ + x86_push( func, x86_make_reg( file_REG32, reg_BX ) ); + + x86_mov( func, aos_output, x86_fn_arg( func, arg_aos ) ); + x86_mov( func, soa_output, x86_fn_arg( func, arg_machine ) ); + x86_lea( func, soa_output, + x86_make_disp( soa_output, + Offset(struct tgsi_exec_machine, Outputs) ) ); + x86_mov( func, num_outputs, x86_fn_arg( func, arg_num ) ); + + /* do */ + inner_loop = x86_get_label( func ); + { + sse_movups( func, make_xmm( 0 ), x86_make_disp( soa_output, 0 ) ); + sse_movups( func, make_xmm( 1 ), x86_make_disp( soa_output, 16 ) ); + sse_movups( func, make_xmm( 3 ), x86_make_disp( soa_output, 32 ) ); + sse_movups( func, make_xmm( 4 ), x86_make_disp( soa_output, 48 ) ); + + sse_movaps( func, make_xmm( 2 ), make_xmm( 0 ) ); + sse_movaps( func, make_xmm( 5 ), make_xmm( 3 ) ); + sse_unpcklps( func, make_xmm( 0 ), make_xmm( 1 ) ); + sse_unpckhps( func, make_xmm( 2 ), make_xmm( 1 ) ); + sse_unpcklps( func, make_xmm( 3 ), make_xmm( 4 ) ); + sse_unpckhps( func, make_xmm( 5 ), make_xmm( 4 ) ); + + x86_mov( func, temp, x86_fn_arg( func, arg_stride ) ); + x86_push( func, aos_output ); + sse_movlps( func, x86_make_disp( aos_output, 0 ), make_xmm( 0 ) ); + sse_movlps( func, x86_make_disp( aos_output, 8 ), make_xmm( 3 ) ); + x86_add( func, aos_output, temp ); + sse_movhps( func, x86_make_disp( aos_output, 0 ), make_xmm( 0 ) ); + sse_movhps( func, x86_make_disp( aos_output, 8 ), make_xmm( 3 ) ); + x86_add( func, aos_output, temp ); + sse_movlps( func, x86_make_disp( aos_output, 0 ), make_xmm( 2 ) ); + sse_movlps( func, x86_make_disp( aos_output, 8 ), make_xmm( 5 ) ); + x86_add( func, aos_output, temp ); + sse_movhps( func, x86_make_disp( aos_output, 0 ), make_xmm( 2 ) ); + sse_movhps( func, x86_make_disp( aos_output, 8 ), make_xmm( 5 ) ); + x86_pop( func, aos_output ); + + /* Advance to next output */ + x86_lea( func, aos_output, x86_make_disp(aos_output, 16) ); + x86_lea( func, soa_output, x86_make_disp(soa_output, 64) ); + } + /* while --num_outputs */ + x86_dec( func, num_outputs ); + x86_jcc( func, cc_NE, inner_loop ); + + /* Restore EBX */ + x86_pop( func, x86_make_reg( file_REG32, reg_BX ) ); +} + + +/** + * Check if the instructions dst register is the same as any src + * register and warn if there's a posible SOA dependency. + */ +static boolean +check_soa_dependencies(const struct tgsi_full_instruction *inst) +{ + uint opcode = inst->Instruction.Opcode; + + /* XXX: we only handle src/dst aliasing in a few opcodes currently. + * Need to use an additional temporay to hold the result in the + * cases where the code is too opaque to fix. + */ + + switch (opcode) { + case TGSI_OPCODE_ADD: + case TGSI_OPCODE_MOV: + case TGSI_OPCODE_MUL: + case TGSI_OPCODE_RCP: + case TGSI_OPCODE_RSQ: + case TGSI_OPCODE_EXP: + case TGSI_OPCODE_LOG: + case TGSI_OPCODE_DP3: + case TGSI_OPCODE_DP4: + case TGSI_OPCODE_DP2A: + case TGSI_OPCODE_EX2: + case TGSI_OPCODE_LG2: + case TGSI_OPCODE_POW: + case TGSI_OPCODE_XPD: + case TGSI_OPCODE_DPH: + case TGSI_OPCODE_COS: + case TGSI_OPCODE_SIN: + case TGSI_OPCODE_TEX: + case TGSI_OPCODE_TXB: + case TGSI_OPCODE_TXP: + case TGSI_OPCODE_NRM: + case TGSI_OPCODE_NRM4: + case TGSI_OPCODE_DP2: + /* OK - these opcodes correctly handle SOA dependencies */ + return TRUE; + default: + if (!tgsi_check_soa_dependencies(inst)) + return TRUE; + + debug_printf("Warning: src/dst aliasing in instruction" + " is not handled:\n"); + debug_printf("Warning: "); + tgsi_dump_instruction(inst, 1); + + return FALSE; + } +} + + +/** + * Translate a TGSI vertex/fragment shader to SSE2 code. + * Slightly different things are done for vertex vs. fragment shaders. + * + * \param tokens the TGSI input shader + * \param func the output SSE code/function + * \param immediates buffer to place immediates, later passed to SSE func + * \param return 1 for success, 0 if translation failed + */ +unsigned +tgsi_emit_sse2( + const struct tgsi_token *tokens, + struct x86_function *func, + float (*immediates)[4], + boolean do_swizzles ) +{ + struct tgsi_parse_context parse; + unsigned ok = 1; + uint num_immediates = 0; + + util_init_math(); + + func->csr = func->store; + + tgsi_parse_init( &parse, tokens ); + + /* Can't just use EDI, EBX without save/restoring them: + */ + x86_push( func, x86_make_reg( file_REG32, reg_BX ) ); + x86_push( func, x86_make_reg( file_REG32, reg_DI ) ); + + /* + * Different function args for vertex/fragment shaders: + */ + if (parse.FullHeader.Processor.Processor == TGSI_PROCESSOR_VERTEX) { + if (do_swizzles) + aos_to_soa( func, + 4, /* aos_input */ + 1, /* machine */ + 5, /* num_inputs */ + 6 ); /* input_stride */ + } + + x86_mov( + func, + get_machine_base(), + x86_fn_arg( func, 1 ) ); + x86_mov( + func, + get_const_base(), + x86_fn_arg( func, 2 ) ); + x86_mov( + func, + get_immediate_base(), + x86_fn_arg( func, 3 ) ); + + if (parse.FullHeader.Processor.Processor == TGSI_PROCESSOR_FRAGMENT) { + x86_mov( + func, + get_coef_base(), + x86_fn_arg( func, 4 ) ); + } + + x86_mov( + func, + get_sampler_base(), + x86_make_disp( get_machine_base(), + Offset( struct tgsi_exec_machine, Samplers ) ) ); + + while( !tgsi_parse_end_of_tokens( &parse ) && ok ) { + tgsi_parse_token( &parse ); + + switch( parse.FullToken.Token.Type ) { + case TGSI_TOKEN_TYPE_DECLARATION: + if (parse.FullHeader.Processor.Processor == TGSI_PROCESSOR_FRAGMENT) { + emit_declaration( + func, + &parse.FullToken.FullDeclaration ); + } + break; + + case TGSI_TOKEN_TYPE_INSTRUCTION: + ok = emit_instruction( + func, + &parse.FullToken.FullInstruction ); + + if (!ok) { + uint opcode = parse.FullToken.FullInstruction.Instruction.Opcode; + uint proc = parse.FullHeader.Processor.Processor; + debug_printf("failed to translate tgsi opcode %d (%s) to SSE (%s)\n", + opcode, + tgsi_get_opcode_name(opcode), + tgsi_get_processor_name(proc)); + } + + if (ok) + ok = check_soa_dependencies(&parse.FullToken.FullInstruction); + break; + + case TGSI_TOKEN_TYPE_IMMEDIATE: + /* simply copy the immediate values into the next immediates[] slot */ + { + const uint size = parse.FullToken.FullImmediate.Immediate.NrTokens - 1; + uint i; + assert(size <= 4); + assert(num_immediates < TGSI_EXEC_NUM_IMMEDIATES); + for( i = 0; i < size; i++ ) { + immediates[num_immediates][i] = + parse.FullToken.FullImmediate.u[i].Float; + } +#if 0 + debug_printf("SSE FS immediate[%d] = %f %f %f %f\n", + num_immediates, + immediates[num_immediates][0], + immediates[num_immediates][1], + immediates[num_immediates][2], + immediates[num_immediates][3]); +#endif + num_immediates++; + } + break; + case TGSI_TOKEN_TYPE_PROPERTY: + /* we just ignore them for now */ + break; + + default: + ok = 0; + assert( 0 ); + } + } + + if (parse.FullHeader.Processor.Processor == TGSI_PROCESSOR_VERTEX) { + if (do_swizzles) + soa_to_aos( func, + 7, /* aos_output */ + 1, /* machine */ + 8, /* num_outputs */ + 9 ); /* output_stride */ + } + + /* Can't just use EBX, EDI without save/restoring them: + */ + x86_pop( func, x86_make_reg( file_REG32, reg_DI ) ); + x86_pop( func, x86_make_reg( file_REG32, reg_BX ) ); + + emit_ret( func ); + + tgsi_parse_free( &parse ); + + return ok; +} + +#endif /* PIPE_ARCH_X86 */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_sse2.h b/src/gallium/auxiliary/tgsi/tgsi_sse2.h new file mode 100644 index 0000000..00aa8b8 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_sse2.h @@ -0,0 +1,80 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef TGSI_SSE2_H +#define TGSI_SSE2_H + +#if defined __cplusplus +extern "C" { +#endif + +#include "pipe/p_compiler.h" + +struct tgsi_exec_machine; +struct tgsi_interp_coef; +struct tgsi_token; +struct x86_function; + +unsigned +tgsi_emit_sse2( + const struct tgsi_token *tokens, + struct x86_function *function, + float (*immediates)[4], + boolean do_swizzles ); + + +/* This is the function prototype generated when do_swizzles is false + * -- effectively for fragment shaders. + */ +typedef void (PIPE_CDECL *tgsi_sse2_fs_function) ( + struct tgsi_exec_machine *machine, /* 1 */ + const float (*constant)[4], /* 2 */ + const float (*immediate)[4], /* 3 */ + const struct tgsi_interp_coef *coef /* 4 */ + ); + + +/* This is the function prototype generated when do_swizzles is true + * -- effectively for vertex shaders. + */ +typedef void (PIPE_CDECL *tgsi_sse2_vs_func) ( + struct tgsi_exec_machine *machine, /* 1 */ + const float (*constant)[4], /* 2 */ + const float (*immediate)[4], /* 3 */ + const float (*aos_input)[4], /* 4 */ + uint num_inputs, /* 5 */ + uint input_stride, /* 6 */ + float (*aos_output)[4], /* 7 */ + uint num_outputs, /* 8 */ + uint output_stride ); /* 9 */ + + +#if defined __cplusplus +} +#endif + +#endif /* TGSI_SSE2_H */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c new file mode 100644 index 0000000..9a38c37 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_text.c @@ -0,0 +1,1483 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "util/u_prim.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "tgsi_text.h" +#include "tgsi_build.h" +#include "tgsi_info.h" +#include "tgsi_parse.h" +#include "tgsi_sanity.h" +#include "tgsi_util.h" + +static boolean is_alpha_underscore( const char *cur ) +{ + return + (*cur >= 'a' && *cur <= 'z') || + (*cur >= 'A' && *cur <= 'Z') || + *cur == '_'; +} + +static boolean is_digit( const char *cur ) +{ + return *cur >= '0' && *cur <= '9'; +} + +static boolean is_digit_alpha_underscore( const char *cur ) +{ + return is_digit( cur ) || is_alpha_underscore( cur ); +} + +static char uprcase( char c ) +{ + if (c >= 'a' && c <= 'z') + return c + 'A' - 'a'; + return c; +} + +/* + * Ignore case of str1 and assume str1 is already uppercase. + * Return TRUE iff str1 and str2 are equal. + */ +static int +streq_nocase_uprcase(const char *str1, + const char *str2) +{ + while (*str1 && *str2) { + if (*str1 != uprcase(*str2)) + return FALSE; + str1++; + str2++; + } + return *str1 == 0 && *str2 == 0; +} + +static boolean str_match_no_case( const char **pcur, const char *str ) +{ + const char *cur = *pcur; + + while (*str != '\0' && *str == uprcase( *cur )) { + str++; + cur++; + } + if (*str == '\0') { + *pcur = cur; + return TRUE; + } + return FALSE; +} + +/* Eat zero or more whitespaces. + */ +static void eat_opt_white( const char **pcur ) +{ + while (**pcur == ' ' || **pcur == '\t' || **pcur == '\n') + (*pcur)++; +} + +/* Eat one or more whitespaces. + * Return TRUE if at least one whitespace eaten. + */ +static boolean eat_white( const char **pcur ) +{ + const char *cur = *pcur; + + eat_opt_white( pcur ); + return *pcur > cur; +} + +/* Parse unsigned integer. + * No checks for overflow. + */ +static boolean parse_uint( const char **pcur, uint *val ) +{ + const char *cur = *pcur; + + if (is_digit( cur )) { + *val = *cur++ - '0'; + while (is_digit( cur )) + *val = *val * 10 + *cur++ - '0'; + *pcur = cur; + return TRUE; + } + return FALSE; +} + +static boolean parse_identifier( const char **pcur, char *ret ) +{ + const char *cur = *pcur; + int i = 0; + if (is_alpha_underscore( cur )) { + ret[i++] = *cur++; + while (is_alpha_underscore( cur )) + ret[i++] = *cur++; + ret[i++] = '\0'; + *pcur = cur; + return TRUE; + } + return FALSE; +} + +/* Parse floating point. + */ +static boolean parse_float( const char **pcur, float *val ) +{ + const char *cur = *pcur; + boolean integral_part = FALSE; + boolean fractional_part = FALSE; + + *val = (float) atof( cur ); + + if (*cur == '-' || *cur == '+') + cur++; + if (is_digit( cur )) { + cur++; + integral_part = TRUE; + while (is_digit( cur )) + cur++; + } + if (*cur == '.') { + cur++; + if (is_digit( cur )) { + cur++; + fractional_part = TRUE; + while (is_digit( cur )) + cur++; + } + } + if (!integral_part && !fractional_part) + return FALSE; + if (uprcase( *cur ) == 'E') { + cur++; + if (*cur == '-' || *cur == '+') + cur++; + if (is_digit( cur )) { + cur++; + while (is_digit( cur )) + cur++; + } + else + return FALSE; + } + *pcur = cur; + return TRUE; +} + +struct translate_ctx +{ + const char *text; + const char *cur; + struct tgsi_token *tokens; + struct tgsi_token *tokens_cur; + struct tgsi_token *tokens_end; + struct tgsi_header *header; + unsigned processor : 4; + int implied_array_size : 5; +}; + +static void report_error( struct translate_ctx *ctx, const char *msg ) +{ + int line = 1; + int column = 1; + const char *itr = ctx->text; + + while (itr != ctx->cur) { + if (*itr == '\n') { + column = 1; + ++line; + } + ++column; + ++itr; + } + + debug_printf( "\nTGSI asm error: %s [%d : %d] \n", msg, line, column ); +} + +/* Parse shader header. + * Return TRUE for one of the following headers. + * FRAG + * GEOM + * VERT + */ +static boolean parse_header( struct translate_ctx *ctx ) +{ + uint processor; + + if (str_match_no_case( &ctx->cur, "FRAG" )) + processor = TGSI_PROCESSOR_FRAGMENT; + else if (str_match_no_case( &ctx->cur, "VERT" )) + processor = TGSI_PROCESSOR_VERTEX; + else if (str_match_no_case( &ctx->cur, "GEOM" )) + processor = TGSI_PROCESSOR_GEOMETRY; + else { + report_error( ctx, "Unknown header" ); + return FALSE; + } + + if (ctx->tokens_cur >= ctx->tokens_end) + return FALSE; + ctx->header = (struct tgsi_header *) ctx->tokens_cur++; + *ctx->header = tgsi_build_header(); + + if (ctx->tokens_cur >= ctx->tokens_end) + return FALSE; + *(struct tgsi_processor *) ctx->tokens_cur++ = tgsi_build_processor( processor, ctx->header ); + ctx->processor = processor; + + return TRUE; +} + +static boolean parse_label( struct translate_ctx *ctx, uint *val ) +{ + const char *cur = ctx->cur; + + if (parse_uint( &cur, val )) { + eat_opt_white( &cur ); + if (*cur == ':') { + cur++; + ctx->cur = cur; + return TRUE; + } + } + return FALSE; +} + +static const char *file_names[TGSI_FILE_COUNT] = +{ + "NULL", + "CONST", + "IN", + "OUT", + "TEMP", + "SAMP", + "ADDR", + "IMM", + "PRED", + "SV", + "IMMX", + "TEMPX" +}; + +static boolean +parse_file( const char **pcur, uint *file ) +{ + uint i; + + for (i = 0; i < TGSI_FILE_COUNT; i++) { + const char *cur = *pcur; + + if (str_match_no_case( &cur, file_names[i] )) { + if (!is_digit_alpha_underscore( cur )) { + *pcur = cur; + *file = i; + return TRUE; + } + } + } + return FALSE; +} + +static boolean +parse_opt_writemask( + struct translate_ctx *ctx, + uint *writemask ) +{ + const char *cur; + + cur = ctx->cur; + eat_opt_white( &cur ); + if (*cur == '.') { + cur++; + *writemask = TGSI_WRITEMASK_NONE; + eat_opt_white( &cur ); + if (uprcase( *cur ) == 'X') { + cur++; + *writemask |= TGSI_WRITEMASK_X; + } + if (uprcase( *cur ) == 'Y') { + cur++; + *writemask |= TGSI_WRITEMASK_Y; + } + if (uprcase( *cur ) == 'Z') { + cur++; + *writemask |= TGSI_WRITEMASK_Z; + } + if (uprcase( *cur ) == 'W') { + cur++; + *writemask |= TGSI_WRITEMASK_W; + } + + if (*writemask == TGSI_WRITEMASK_NONE) { + report_error( ctx, "Writemask expected" ); + return FALSE; + } + + ctx->cur = cur; + } + else { + *writemask = TGSI_WRITEMASK_XYZW; + } + return TRUE; +} + + +/* ::= `[' + */ +static boolean +parse_register_file_bracket( + struct translate_ctx *ctx, + uint *file ) +{ + if (!parse_file( &ctx->cur, file )) { + report_error( ctx, "Unknown register file" ); + return FALSE; + } + eat_opt_white( &ctx->cur ); + if (*ctx->cur != '[') { + report_error( ctx, "Expected `['" ); + return FALSE; + } + ctx->cur++; + return TRUE; +} + +/* ::= + */ +static boolean +parse_register_file_bracket_index( + struct translate_ctx *ctx, + uint *file, + int *index ) +{ + uint uindex; + + if (!parse_register_file_bracket( ctx, file )) + return FALSE; + eat_opt_white( &ctx->cur ); + if (!parse_uint( &ctx->cur, &uindex )) { + report_error( ctx, "Expected literal unsigned integer" ); + return FALSE; + } + *index = (int) uindex; + return TRUE; +} + +/* Parse simple 1d register operand. + * ::= `]' + */ +static boolean +parse_register_1d(struct translate_ctx *ctx, + uint *file, + int *index ) +{ + if (!parse_register_file_bracket_index( ctx, file, index )) + return FALSE; + eat_opt_white( &ctx->cur ); + if (*ctx->cur != ']') { + report_error( ctx, "Expected `]'" ); + return FALSE; + } + ctx->cur++; + return TRUE; +} + +struct parsed_bracket { + int index; + + uint ind_file; + int ind_index; + uint ind_comp; +}; + + +static boolean +parse_register_bracket( + struct translate_ctx *ctx, + struct parsed_bracket *brackets) +{ + const char *cur; + uint uindex; + + memset(brackets, 0, sizeof(struct parsed_bracket)); + + eat_opt_white( &ctx->cur ); + + cur = ctx->cur; + if (parse_file( &cur, &brackets->ind_file )) { + if (!parse_register_1d( ctx, &brackets->ind_file, + &brackets->ind_index )) + return FALSE; + eat_opt_white( &ctx->cur ); + + if (*ctx->cur == '.') { + ctx->cur++; + eat_opt_white(&ctx->cur); + + switch (uprcase(*ctx->cur)) { + case 'X': + brackets->ind_comp = TGSI_SWIZZLE_X; + break; + case 'Y': + brackets->ind_comp = TGSI_SWIZZLE_Y; + break; + case 'Z': + brackets->ind_comp = TGSI_SWIZZLE_Z; + break; + case 'W': + brackets->ind_comp = TGSI_SWIZZLE_W; + break; + default: + report_error(ctx, "Expected indirect register swizzle component `x', `y', `z' or `w'"); + return FALSE; + } + ctx->cur++; + eat_opt_white(&ctx->cur); + } + + if (*ctx->cur == '+' || *ctx->cur == '-') { + boolean negate; + + negate = *ctx->cur == '-'; + ctx->cur++; + eat_opt_white( &ctx->cur ); + if (!parse_uint( &ctx->cur, &uindex )) { + report_error( ctx, "Expected literal unsigned integer" ); + return FALSE; + } + if (negate) + brackets->index = -(int) uindex; + else + brackets->index = (int) uindex; + } + else { + brackets->index = 0; + } + } + else { + if (!parse_uint( &ctx->cur, &uindex )) { + report_error( ctx, "Expected literal unsigned integer" ); + return FALSE; + } + brackets->index = (int) uindex; + brackets->ind_file = TGSI_FILE_NULL; + brackets->ind_index = 0; + } + eat_opt_white( &ctx->cur ); + if (*ctx->cur != ']') { + report_error( ctx, "Expected `]'" ); + return FALSE; + } + ctx->cur++; + return TRUE; +} + +static boolean +parse_opt_register_src_bracket( + struct translate_ctx *ctx, + struct parsed_bracket *brackets, + int *parsed_brackets) +{ + const char *cur = ctx->cur; + + *parsed_brackets = 0; + + eat_opt_white( &cur ); + if (cur[0] == '[') { + ++cur; + ctx->cur = cur; + + if (!parse_register_bracket(ctx, brackets)) + return FALSE; + + *parsed_brackets = 1; + } + + return TRUE; +} + + +/* Parse source register operand. + * ::= `]' | + * [`.' (`x' | `y' | `z' | `w')] `]' | + * [`.' (`x' | `y' | `z' | `w')] `+' `]' | + * [`.' (`x' | `y' | `z' | `w')] `-' `]' + */ +static boolean +parse_register_src( + struct translate_ctx *ctx, + uint *file, + struct parsed_bracket *brackets) +{ + brackets->ind_comp = TGSI_SWIZZLE_X; + if (!parse_register_file_bracket( ctx, file )) + return FALSE; + if (!parse_register_bracket( ctx, brackets )) + return FALSE; + + return TRUE; +} + +struct parsed_dcl_bracket { + uint first; + uint last; +}; + +static boolean +parse_register_dcl_bracket( + struct translate_ctx *ctx, + struct parsed_dcl_bracket *bracket) +{ + uint uindex; + memset(bracket, 0, sizeof(struct parsed_dcl_bracket)); + + eat_opt_white( &ctx->cur ); + + if (!parse_uint( &ctx->cur, &uindex )) { + /* it can be an empty bracket [] which means its range + * is from 0 to some implied size */ + if (ctx->cur[0] == ']' && ctx->implied_array_size != 0) { + bracket->first = 0; + bracket->last = ctx->implied_array_size - 1; + goto cleanup; + } + report_error( ctx, "Expected literal unsigned integer" ); + return FALSE; + } + bracket->first = uindex; + + eat_opt_white( &ctx->cur ); + + if (ctx->cur[0] == '.' && ctx->cur[1] == '.') { + uint uindex; + + ctx->cur += 2; + eat_opt_white( &ctx->cur ); + if (!parse_uint( &ctx->cur, &uindex )) { + report_error( ctx, "Expected literal integer" ); + return FALSE; + } + bracket->last = (int) uindex; + eat_opt_white( &ctx->cur ); + } + else { + bracket->last = bracket->first; + } + +cleanup: + if (*ctx->cur != ']') { + report_error( ctx, "Expected `]' or `..'" ); + return FALSE; + } + ctx->cur++; + return TRUE; +} + +/* Parse register declaration. + * ::= `]' | + * `..' `]' + */ +static boolean +parse_register_dcl( + struct translate_ctx *ctx, + uint *file, + struct parsed_dcl_bracket *brackets, + int *num_brackets) +{ + const char *cur; + + *num_brackets = 0; + + if (!parse_register_file_bracket( ctx, file )) + return FALSE; + if (!parse_register_dcl_bracket( ctx, &brackets[0] )) + return FALSE; + + *num_brackets = 1; + + cur = ctx->cur; + eat_opt_white( &cur ); + + if (cur[0] == '[') { + ++cur; + ctx->cur = cur; + if (!parse_register_dcl_bracket( ctx, &brackets[1] )) + return FALSE; + /* for geometry shader we don't really care about + * the first brackets it's always the size of the + * input primitive. so we want to declare just + * the index relevant to the semantics which is in + * the second bracket */ + if (ctx->processor == TGSI_PROCESSOR_GEOMETRY && *file == TGSI_FILE_INPUT) { + brackets[0] = brackets[1]; + *num_brackets = 1; + } else { + *num_brackets = 2; + } + } + + return TRUE; +} + + +/* Parse destination register operand.*/ +static boolean +parse_register_dst( + struct translate_ctx *ctx, + uint *file, + struct parsed_bracket *brackets) +{ + brackets->ind_comp = TGSI_SWIZZLE_X; + if (!parse_register_file_bracket( ctx, file )) + return FALSE; + if (!parse_register_bracket( ctx, brackets )) + return FALSE; + + return TRUE; +} + +static boolean +parse_dst_operand( + struct translate_ctx *ctx, + struct tgsi_full_dst_register *dst ) +{ + uint file; + uint writemask; + const char *cur; + struct parsed_bracket bracket[2]; + int parsed_opt_brackets; + + if (!parse_register_dst( ctx, &file, &bracket[0] )) + return FALSE; + if (!parse_opt_register_src_bracket(ctx, &bracket[1], &parsed_opt_brackets)) + return FALSE; + + cur = ctx->cur; + eat_opt_white( &cur ); + + if (!parse_opt_writemask( ctx, &writemask )) + return FALSE; + + dst->Register.File = file; + if (parsed_opt_brackets) { + dst->Register.Dimension = 1; + dst->Dimension.Indirect = 0; + dst->Dimension.Dimension = 0; + dst->Dimension.Index = bracket[0].index; + bracket[0] = bracket[1]; + } + dst->Register.Index = bracket[0].index; + dst->Register.WriteMask = writemask; + if (bracket[0].ind_file != TGSI_FILE_NULL) { + dst->Register.Indirect = 1; + dst->Indirect.File = bracket[0].ind_file; + dst->Indirect.Index = bracket[0].ind_index; + dst->Indirect.SwizzleX = bracket[0].ind_comp; + dst->Indirect.SwizzleY = bracket[0].ind_comp; + dst->Indirect.SwizzleZ = bracket[0].ind_comp; + dst->Indirect.SwizzleW = bracket[0].ind_comp; + } + return TRUE; +} + +static boolean +parse_optional_swizzle( + struct translate_ctx *ctx, + uint swizzle[4], + boolean *parsed_swizzle ) +{ + const char *cur = ctx->cur; + + *parsed_swizzle = FALSE; + + eat_opt_white( &cur ); + if (*cur == '.') { + uint i; + + cur++; + eat_opt_white( &cur ); + for (i = 0; i < 4; i++) { + if (uprcase( *cur ) == 'X') + swizzle[i] = TGSI_SWIZZLE_X; + else if (uprcase( *cur ) == 'Y') + swizzle[i] = TGSI_SWIZZLE_Y; + else if (uprcase( *cur ) == 'Z') + swizzle[i] = TGSI_SWIZZLE_Z; + else if (uprcase( *cur ) == 'W') + swizzle[i] = TGSI_SWIZZLE_W; + else { + report_error( ctx, "Expected register swizzle component `x', `y', `z' or `w'" ); + return FALSE; + } + cur++; + } + *parsed_swizzle = TRUE; + ctx->cur = cur; + } + return TRUE; +} + +static boolean +parse_src_operand( + struct translate_ctx *ctx, + struct tgsi_full_src_register *src ) +{ + uint file; + uint swizzle[4]; + boolean parsed_swizzle; + struct parsed_bracket bracket[2]; + int parsed_opt_brackets; + + if (*ctx->cur == '-') { + ctx->cur++; + eat_opt_white( &ctx->cur ); + src->Register.Negate = 1; + } + + if (*ctx->cur == '|') { + ctx->cur++; + eat_opt_white( &ctx->cur ); + src->Register.Absolute = 1; + } + + if (!parse_register_src(ctx, &file, &bracket[0])) + return FALSE; + if (!parse_opt_register_src_bracket(ctx, &bracket[1], &parsed_opt_brackets)) + return FALSE; + + src->Register.File = file; + if (parsed_opt_brackets) { + src->Register.Dimension = 1; + src->Dimension.Indirect = 0; + src->Dimension.Dimension = 0; + src->Dimension.Index = bracket[0].index; + bracket[0] = bracket[1]; + } + src->Register.Index = bracket[0].index; + if (bracket[0].ind_file != TGSI_FILE_NULL) { + src->Register.Indirect = 1; + src->Indirect.File = bracket[0].ind_file; + src->Indirect.Index = bracket[0].ind_index; + src->Indirect.SwizzleX = bracket[0].ind_comp; + src->Indirect.SwizzleY = bracket[0].ind_comp; + src->Indirect.SwizzleZ = bracket[0].ind_comp; + src->Indirect.SwizzleW = bracket[0].ind_comp; + } + + /* Parse optional swizzle. + */ + if (parse_optional_swizzle( ctx, swizzle, &parsed_swizzle )) { + if (parsed_swizzle) { + src->Register.SwizzleX = swizzle[0]; + src->Register.SwizzleY = swizzle[1]; + src->Register.SwizzleZ = swizzle[2]; + src->Register.SwizzleW = swizzle[3]; + } + } + + if (src->Register.Absolute) { + eat_opt_white( &ctx->cur ); + if (*ctx->cur != '|') { + report_error( ctx, "Expected `|'" ); + return FALSE; + } + ctx->cur++; + } + + + return TRUE; +} + +static const char *texture_names[TGSI_TEXTURE_COUNT] = +{ + "UNKNOWN", + "1D", + "2D", + "3D", + "CUBE", + "RECT", + "SHADOW1D", + "SHADOW2D", + "SHADOWRECT" +}; + +static boolean +match_inst_mnemonic(const char **pcur, + const struct tgsi_opcode_info *info) +{ + if (str_match_no_case(pcur, info->mnemonic)) { + return TRUE; + } + return FALSE; +} + +static boolean +parse_instruction( + struct translate_ctx *ctx, + boolean has_label ) +{ + uint i; + uint saturate = TGSI_SAT_NONE; + const struct tgsi_opcode_info *info; + struct tgsi_full_instruction inst; + uint advance; + + inst = tgsi_default_full_instruction(); + + /* Parse predicate. + */ + eat_opt_white( &ctx->cur ); + if (*ctx->cur == '(') { + uint file; + int index; + uint swizzle[4]; + boolean parsed_swizzle; + + inst.Instruction.Predicate = 1; + + ctx->cur++; + if (*ctx->cur == '!') { + ctx->cur++; + inst.Predicate.Negate = 1; + } + + if (!parse_register_1d( ctx, &file, &index )) + return FALSE; + + if (parse_optional_swizzle( ctx, swizzle, &parsed_swizzle )) { + if (parsed_swizzle) { + inst.Predicate.SwizzleX = swizzle[0]; + inst.Predicate.SwizzleY = swizzle[1]; + inst.Predicate.SwizzleZ = swizzle[2]; + inst.Predicate.SwizzleW = swizzle[3]; + } + } + + if (*ctx->cur != ')') { + report_error( ctx, "Expected `)'" ); + return FALSE; + } + + ctx->cur++; + } + + /* Parse instruction name. + */ + eat_opt_white( &ctx->cur ); + for (i = 0; i < TGSI_OPCODE_LAST; i++) { + const char *cur = ctx->cur; + + info = tgsi_get_opcode_info( i ); + if (match_inst_mnemonic(&cur, info)) { + if (str_match_no_case( &cur, "_SATNV" )) + saturate = TGSI_SAT_MINUS_PLUS_ONE; + else if (str_match_no_case( &cur, "_SAT" )) + saturate = TGSI_SAT_ZERO_ONE; + + if (info->num_dst + info->num_src + info->is_tex == 0) { + if (!is_digit_alpha_underscore( cur )) { + ctx->cur = cur; + break; + } + } + else if (*cur == '\0' || eat_white( &cur )) { + ctx->cur = cur; + break; + } + } + } + if (i == TGSI_OPCODE_LAST) { + if (has_label) + report_error( ctx, "Unknown opcode" ); + else + report_error( ctx, "Expected `DCL', `IMM' or a label" ); + return FALSE; + } + + inst.Instruction.Opcode = i; + inst.Instruction.Saturate = saturate; + inst.Instruction.NumDstRegs = info->num_dst; + inst.Instruction.NumSrcRegs = info->num_src; + + /* Parse instruction operands. + */ + for (i = 0; i < info->num_dst + info->num_src + info->is_tex; i++) { + if (i > 0) { + eat_opt_white( &ctx->cur ); + if (*ctx->cur != ',') { + report_error( ctx, "Expected `,'" ); + return FALSE; + } + ctx->cur++; + eat_opt_white( &ctx->cur ); + } + + if (i < info->num_dst) { + if (!parse_dst_operand( ctx, &inst.Dst[i] )) + return FALSE; + } + else if (i < info->num_dst + info->num_src) { + if (!parse_src_operand( ctx, &inst.Src[i - info->num_dst] )) + return FALSE; + } + else { + uint j; + + for (j = 0; j < TGSI_TEXTURE_COUNT; j++) { + if (str_match_no_case( &ctx->cur, texture_names[j] )) { + if (!is_digit_alpha_underscore( ctx->cur )) { + inst.Instruction.Texture = 1; + inst.Texture.Texture = j; + break; + } + } + } + if (j == TGSI_TEXTURE_COUNT) { + report_error( ctx, "Expected texture target" ); + return FALSE; + } + } + } + + if (info->is_branch) { + uint target; + + eat_opt_white( &ctx->cur ); + if (*ctx->cur != ':') { + report_error( ctx, "Expected `:'" ); + return FALSE; + } + ctx->cur++; + eat_opt_white( &ctx->cur ); + if (!parse_uint( &ctx->cur, &target )) { + report_error( ctx, "Expected a label" ); + return FALSE; + } + inst.Instruction.Label = 1; + inst.Label.Label = target; + } + + advance = tgsi_build_full_instruction( + &inst, + ctx->tokens_cur, + ctx->header, + (uint) (ctx->tokens_end - ctx->tokens_cur) ); + if (advance == 0) + return FALSE; + ctx->tokens_cur += advance; + + return TRUE; +} + +static const char *semantic_names[TGSI_SEMANTIC_COUNT] = +{ + "POSITION", + "COLOR", + "BCOLOR", + "FOG", + "PSIZE", + "GENERIC", + "NORMAL", + "FACE", + "EDGEFLAG", + "PRIM_ID", + "INSTANCEID", + "STENCIL" +}; + +static const char *interpolate_names[TGSI_INTERPOLATE_COUNT] = +{ + "CONSTANT", + "LINEAR", + "PERSPECTIVE" +}; + + +/* parses a 4-touple of the form {x, y, z, w} + * where x, y, z, w are numbers */ +static boolean parse_immediate_data(struct translate_ctx *ctx, + float *values) +{ + unsigned i; + + eat_opt_white( &ctx->cur ); + if (*ctx->cur != '{') { + report_error( ctx, "Expected `{'" ); + return FALSE; + } + ctx->cur++; + for (i = 0; i < 4; i++) { + eat_opt_white( &ctx->cur ); + if (i > 0) { + if (*ctx->cur != ',') { + report_error( ctx, "Expected `,'" ); + return FALSE; + } + ctx->cur++; + eat_opt_white( &ctx->cur ); + } + if (!parse_float( &ctx->cur, &values[i] )) { + report_error( ctx, "Expected literal floating point" ); + return FALSE; + } + } + eat_opt_white( &ctx->cur ); + if (*ctx->cur != '}') { + report_error( ctx, "Expected `}'" ); + return FALSE; + } + ctx->cur++; + + return TRUE; +} + +static boolean parse_declaration( struct translate_ctx *ctx ) +{ + struct tgsi_full_declaration decl; + uint file; + struct parsed_dcl_bracket brackets[2]; + int num_brackets; + uint writemask; + const char *cur; + uint advance; + boolean is_vs_input; + boolean is_imm_array; + + assert(Elements(semantic_names) == TGSI_SEMANTIC_COUNT); + assert(Elements(interpolate_names) == TGSI_INTERPOLATE_COUNT); + + if (!eat_white( &ctx->cur )) { + report_error( ctx, "Syntax error" ); + return FALSE; + } + if (!parse_register_dcl( ctx, &file, brackets, &num_brackets)) + return FALSE; + if (!parse_opt_writemask( ctx, &writemask )) + return FALSE; + + decl = tgsi_default_full_declaration(); + decl.Declaration.File = file; + decl.Declaration.UsageMask = writemask; + + if (num_brackets == 1) { + decl.Range.First = brackets[0].first; + decl.Range.Last = brackets[0].last; + } else { + decl.Range.First = brackets[1].first; + decl.Range.Last = brackets[1].last; + + decl.Declaration.Dimension = 1; + decl.Dim.Index2D = brackets[0].first; + } + + is_vs_input = (file == TGSI_FILE_INPUT && + ctx->processor == TGSI_PROCESSOR_VERTEX); + is_imm_array = (file == TGSI_FILE_IMMEDIATE_ARRAY); + + cur = ctx->cur; + eat_opt_white( &cur ); + if (*cur == ',' && !is_vs_input) { + uint i; + + cur++; + eat_opt_white( &cur ); + for (i = 0; i < TGSI_SEMANTIC_COUNT; i++) { + if (str_match_no_case( &cur, semantic_names[i] )) { + const char *cur2 = cur; + uint index; + + if (is_digit_alpha_underscore( cur )) + continue; + eat_opt_white( &cur2 ); + if (*cur2 == '[') { + cur2++; + eat_opt_white( &cur2 ); + if (!parse_uint( &cur2, &index )) { + report_error( ctx, "Expected literal integer" ); + return FALSE; + } + eat_opt_white( &cur2 ); + if (*cur2 != ']') { + report_error( ctx, "Expected `]'" ); + return FALSE; + } + cur2++; + + decl.Semantic.Index = index; + + cur = cur2; + } + + decl.Declaration.Semantic = 1; + decl.Semantic.Name = i; + + ctx->cur = cur; + break; + } + } + } else if (is_imm_array) { + unsigned i; + float *vals_itr; + /* we have our immediate data */ + if (*cur != '{') { + report_error( ctx, "Immediate array without data" ); + return FALSE; + } + ++cur; + ctx->cur = cur; + + decl.ImmediateData.u = + MALLOC(sizeof(union tgsi_immediate_data) * 4 * + (decl.Range.Last + 1)); + vals_itr = (float*)decl.ImmediateData.u; + for (i = 0; i <= decl.Range.Last; ++i) { + if (!parse_immediate_data(ctx, vals_itr)) { + FREE(decl.ImmediateData.u); + return FALSE; + } + vals_itr += 4; + eat_opt_white( &ctx->cur ); + if (*ctx->cur != ',') { + if (i != decl.Range.Last) { + report_error( ctx, "Not enough data in immediate array!" ); + FREE(decl.ImmediateData.u); + return FALSE; + } + } else + ++ctx->cur; + } + eat_opt_white( &ctx->cur ); + if (*ctx->cur != '}') { + FREE(decl.ImmediateData.u); + report_error( ctx, "Immediate array data missing closing '}'" ); + return FALSE; + } + ++ctx->cur; + } + + cur = ctx->cur; + eat_opt_white( &cur ); + if (*cur == ',' && !is_vs_input) { + uint i; + + cur++; + eat_opt_white( &cur ); + for (i = 0; i < TGSI_INTERPOLATE_COUNT; i++) { + if (str_match_no_case( &cur, interpolate_names[i] )) { + if (is_digit_alpha_underscore( cur )) + continue; + decl.Declaration.Interpolate = i; + + ctx->cur = cur; + break; + } + } + if (i == TGSI_INTERPOLATE_COUNT) { + report_error( ctx, "Expected semantic or interpolate attribute" ); + return FALSE; + } + } + + advance = tgsi_build_full_declaration( + &decl, + ctx->tokens_cur, + ctx->header, + (uint) (ctx->tokens_end - ctx->tokens_cur) ); + + if (is_imm_array) + FREE(decl.ImmediateData.u); + + if (advance == 0) + return FALSE; + ctx->tokens_cur += advance; + + return TRUE; +} + +static boolean parse_immediate( struct translate_ctx *ctx ) +{ + struct tgsi_full_immediate imm; + float values[4]; + uint advance; + + if (!eat_white( &ctx->cur )) { + report_error( ctx, "Syntax error" ); + return FALSE; + } + if (!str_match_no_case( &ctx->cur, "FLT32" ) || + is_digit_alpha_underscore( ctx->cur )) { + report_error( ctx, "Expected `FLT32'" ); + return FALSE; + } + + parse_immediate_data(ctx, values); + + imm = tgsi_default_full_immediate(); + imm.Immediate.NrTokens += 4; + imm.Immediate.DataType = TGSI_IMM_FLOAT32; + imm.u[0].Float = values[0]; + imm.u[1].Float = values[1]; + imm.u[2].Float = values[2]; + imm.u[3].Float = values[3]; + + advance = tgsi_build_full_immediate( + &imm, + ctx->tokens_cur, + ctx->header, + (uint) (ctx->tokens_end - ctx->tokens_cur) ); + if (advance == 0) + return FALSE; + ctx->tokens_cur += advance; + + return TRUE; +} + +static const char *property_names[] = +{ + "GS_INPUT_PRIMITIVE", + "GS_OUTPUT_PRIMITIVE", + "GS_MAX_OUTPUT_VERTICES", + "FS_COORD_ORIGIN", + "FS_COORD_PIXEL_CENTER" +}; + +static const char *primitive_names[] = +{ + "POINTS", + "LINES", + "LINE_LOOP", + "LINE_STRIP", + "TRIANGLES", + "TRIANGLE_STRIP", + "TRIANGLE_FAN", + "QUADS", + "QUAD_STRIP", + "POLYGON" +}; + +static const char *fs_coord_origin_names[] = +{ + "UPPER_LEFT", + "LOWER_LEFT" +}; + +static const char *fs_coord_pixel_center_names[] = +{ + "HALF_INTEGER", + "INTEGER" +}; + + +static boolean +parse_primitive( const char **pcur, uint *primitive ) +{ + uint i; + + for (i = 0; i < PIPE_PRIM_MAX; i++) { + const char *cur = *pcur; + + if (str_match_no_case( &cur, primitive_names[i])) { + *primitive = i; + *pcur = cur; + return TRUE; + } + } + return FALSE; +} + +static boolean +parse_fs_coord_origin( const char **pcur, uint *fs_coord_origin ) +{ + uint i; + + for (i = 0; i < sizeof(fs_coord_origin_names) / sizeof(fs_coord_origin_names[0]); i++) { + const char *cur = *pcur; + + if (str_match_no_case( &cur, fs_coord_origin_names[i])) { + *fs_coord_origin = i; + *pcur = cur; + return TRUE; + } + } + return FALSE; +} + +static boolean +parse_fs_coord_pixel_center( const char **pcur, uint *fs_coord_pixel_center ) +{ + uint i; + + for (i = 0; i < sizeof(fs_coord_pixel_center_names) / sizeof(fs_coord_pixel_center_names[0]); i++) { + const char *cur = *pcur; + + if (str_match_no_case( &cur, fs_coord_pixel_center_names[i])) { + *fs_coord_pixel_center = i; + *pcur = cur; + return TRUE; + } + } + return FALSE; +} + + +static boolean parse_property( struct translate_ctx *ctx ) +{ + struct tgsi_full_property prop; + uint property_name; + uint values[8]; + uint advance; + char id[64]; + + if (!eat_white( &ctx->cur )) { + report_error( ctx, "Syntax error" ); + return FALSE; + } + if (!parse_identifier( &ctx->cur, id )) { + report_error( ctx, "Syntax error" ); + return FALSE; + } + for (property_name = 0; property_name < TGSI_PROPERTY_COUNT; + ++property_name) { + if (streq_nocase_uprcase(property_names[property_name], id)) { + break; + } + } + if (property_name >= TGSI_PROPERTY_COUNT) { + debug_printf( "\nError: Unknown property : '%s'", id ); + return FALSE; + } + + eat_opt_white( &ctx->cur ); + switch(property_name) { + case TGSI_PROPERTY_GS_INPUT_PRIM: + case TGSI_PROPERTY_GS_OUTPUT_PRIM: + if (!parse_primitive(&ctx->cur, &values[0] )) { + report_error( ctx, "Unknown primitive name as property!" ); + return FALSE; + } + if (property_name == TGSI_PROPERTY_GS_INPUT_PRIM && + ctx->processor == TGSI_PROCESSOR_GEOMETRY) { + ctx->implied_array_size = u_vertices_per_prim(values[0]); + } + break; + case TGSI_PROPERTY_FS_COORD_ORIGIN: + if (!parse_fs_coord_origin(&ctx->cur, &values[0] )) { + report_error( ctx, "Unknown coord origin as property: must be UPPER_LEFT or LOWER_LEFT!" ); + return FALSE; + } + break; + case TGSI_PROPERTY_FS_COORD_PIXEL_CENTER: + if (!parse_fs_coord_pixel_center(&ctx->cur, &values[0] )) { + report_error( ctx, "Unknown coord pixel center as property: must be HALF_INTEGER or INTEGER!" ); + return FALSE; + } + break; + default: + if (!parse_uint(&ctx->cur, &values[0] )) { + report_error( ctx, "Expected unsigned integer as property!" ); + return FALSE; + } + } + + prop = tgsi_default_full_property(); + prop.Property.PropertyName = property_name; + prop.Property.NrTokens += 1; + prop.u[0].Data = values[0]; + + advance = tgsi_build_full_property( + &prop, + ctx->tokens_cur, + ctx->header, + (uint) (ctx->tokens_end - ctx->tokens_cur) ); + if (advance == 0) + return FALSE; + ctx->tokens_cur += advance; + + return TRUE; +} + + +static boolean translate( struct translate_ctx *ctx ) +{ + eat_opt_white( &ctx->cur ); + if (!parse_header( ctx )) + return FALSE; + + while (*ctx->cur != '\0') { + uint label_val = 0; + if (!eat_white( &ctx->cur )) { + report_error( ctx, "Syntax error" ); + return FALSE; + } + + if (*ctx->cur == '\0') + break; + if (parse_label( ctx, &label_val )) { + if (!parse_instruction( ctx, TRUE )) + return FALSE; + } + else if (str_match_no_case( &ctx->cur, "DCL" )) { + if (!parse_declaration( ctx )) + return FALSE; + } + else if (str_match_no_case( &ctx->cur, "IMM" )) { + if (!parse_immediate( ctx )) + return FALSE; + } + else if (str_match_no_case( &ctx->cur, "PROPERTY" )) { + if (!parse_property( ctx )) + return FALSE; + } + else if (!parse_instruction( ctx, FALSE )) { + return FALSE; + } + } + + return TRUE; +} + +boolean +tgsi_text_translate( + const char *text, + struct tgsi_token *tokens, + uint num_tokens ) +{ + struct translate_ctx ctx; + + ctx.text = text; + ctx.cur = text; + ctx.tokens = tokens; + ctx.tokens_cur = tokens; + ctx.tokens_end = tokens + num_tokens; + + if (!translate( &ctx )) + return FALSE; + + return tgsi_sanity_check( tokens ); +} diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.h b/src/gallium/auxiliary/tgsi/tgsi_text.h new file mode 100644 index 0000000..8eeeeef --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_text.h @@ -0,0 +1,47 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef TGSI_TEXT_H +#define TGSI_TEXT_H + +#include "pipe/p_shader_tokens.h" + +#if defined __cplusplus +extern "C" { +#endif + +boolean +tgsi_text_translate( + const char *text, + struct tgsi_token *tokens, + uint num_tokens ); + +#if defined __cplusplus +} +#endif + +#endif /* TGSI_TEXT_H */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_transform.c b/src/gallium/auxiliary/tgsi/tgsi_transform.c new file mode 100644 index 0000000..ae875f2 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_transform.c @@ -0,0 +1,250 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * TGSI program transformation utility. + * + * Authors: Brian Paul + */ + +#include "util/u_debug.h" + +#include "tgsi_transform.h" + + + +static void +emit_instruction(struct tgsi_transform_context *ctx, + const struct tgsi_full_instruction *inst) +{ + uint ti = ctx->ti; + + ti += tgsi_build_full_instruction(inst, + ctx->tokens_out + ti, + ctx->header, + ctx->max_tokens_out - ti); + ctx->ti = ti; +} + + +static void +emit_declaration(struct tgsi_transform_context *ctx, + const struct tgsi_full_declaration *decl) +{ + uint ti = ctx->ti; + + ti += tgsi_build_full_declaration(decl, + ctx->tokens_out + ti, + ctx->header, + ctx->max_tokens_out - ti); + ctx->ti = ti; +} + + +static void +emit_immediate(struct tgsi_transform_context *ctx, + const struct tgsi_full_immediate *imm) +{ + uint ti = ctx->ti; + + ti += tgsi_build_full_immediate(imm, + ctx->tokens_out + ti, + ctx->header, + ctx->max_tokens_out - ti); + ctx->ti = ti; +} + + +static void +emit_property(struct tgsi_transform_context *ctx, + const struct tgsi_full_property *prop) +{ + uint ti = ctx->ti; + + ti += tgsi_build_full_property(prop, + ctx->tokens_out + ti, + ctx->header, + ctx->max_tokens_out - ti); + ctx->ti = ti; +} + + +/** + * Apply user-defined transformations to the input shader to produce + * the output shader. + * For example, a register search-and-replace operation could be applied + * by defining a transform_instruction() callback that examined and changed + * the instruction src/dest regs. + * + * \return number of tokens emitted + */ +int +tgsi_transform_shader(const struct tgsi_token *tokens_in, + struct tgsi_token *tokens_out, + uint max_tokens_out, + struct tgsi_transform_context *ctx) +{ + uint procType; + + /* input shader */ + struct tgsi_parse_context parse; + + /* output shader */ + struct tgsi_processor *processor; + + + /** + ** callback context init + **/ + ctx->emit_instruction = emit_instruction; + ctx->emit_declaration = emit_declaration; + ctx->emit_immediate = emit_immediate; + ctx->emit_property = emit_property; + ctx->tokens_out = tokens_out; + ctx->max_tokens_out = max_tokens_out; + + + /** + ** Setup to begin parsing input shader + **/ + if (tgsi_parse_init( &parse, tokens_in ) != TGSI_PARSE_OK) { + debug_printf("tgsi_parse_init() failed in tgsi_transform_shader()!\n"); + return -1; + } + procType = parse.FullHeader.Processor.Processor; + assert(procType == TGSI_PROCESSOR_FRAGMENT || + procType == TGSI_PROCESSOR_VERTEX || + procType == TGSI_PROCESSOR_GEOMETRY); + + + /** + ** Setup output shader + **/ + ctx->header = (struct tgsi_header *)tokens_out; + *ctx->header = tgsi_build_header(); + + processor = (struct tgsi_processor *) (tokens_out + 1); + *processor = tgsi_build_processor( procType, ctx->header ); + + ctx->ti = 2; + + + /** + ** Loop over incoming program tokens/instructions + */ + while( !tgsi_parse_end_of_tokens( &parse ) ) { + + tgsi_parse_token( &parse ); + + switch( parse.FullToken.Token.Type ) { + case TGSI_TOKEN_TYPE_INSTRUCTION: + { + struct tgsi_full_instruction *fullinst + = &parse.FullToken.FullInstruction; + + if (ctx->transform_instruction) + ctx->transform_instruction(ctx, fullinst); + else + ctx->emit_instruction(ctx, fullinst); + } + break; + + case TGSI_TOKEN_TYPE_DECLARATION: + { + struct tgsi_full_declaration *fulldecl + = &parse.FullToken.FullDeclaration; + + if (ctx->transform_declaration) + ctx->transform_declaration(ctx, fulldecl); + else + ctx->emit_declaration(ctx, fulldecl); + } + break; + + case TGSI_TOKEN_TYPE_IMMEDIATE: + { + struct tgsi_full_immediate *fullimm + = &parse.FullToken.FullImmediate; + + if (ctx->transform_immediate) + ctx->transform_immediate(ctx, fullimm); + else + ctx->emit_immediate(ctx, fullimm); + } + break; + case TGSI_TOKEN_TYPE_PROPERTY: + { + struct tgsi_full_property *fullprop + = &parse.FullToken.FullProperty; + + if (ctx->transform_property) + ctx->transform_property(ctx, fullprop); + else + ctx->emit_property(ctx, fullprop); + } + break; + + default: + assert( 0 ); + } + } + + if (ctx->epilog) { + ctx->epilog(ctx); + } + + tgsi_parse_free (&parse); + + return ctx->ti; +} + + +#include "tgsi_text.h" + +extern int tgsi_transform_foo( struct tgsi_token *tokens_out, + uint max_tokens_out ); + +/* This function exists only so that tgsi_text_translate() doesn't get + * magic-ed out of the libtgsi.a archive by the build system. Don't + * remove unless you know this has been fixed - check on mingw/scons + * builds as well. + */ +int +tgsi_transform_foo( struct tgsi_token *tokens_out, + uint max_tokens_out ) +{ + const char *text = + "FRAG\n" + "DCL IN[0], COLOR, CONSTANT\n" + "DCL OUT[0], COLOR\n" + " 0: MOV OUT[0], IN[0]\n" + " 1: END"; + + return tgsi_text_translate( text, + tokens_out, + max_tokens_out ); +} diff --git a/src/gallium/auxiliary/tgsi/tgsi_transform.h b/src/gallium/auxiliary/tgsi/tgsi_transform.h new file mode 100644 index 0000000..818478e --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_transform.h @@ -0,0 +1,96 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef TGSI_TRANSFORM_H +#define TGSI_TRANSFORM_H + + +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_build.h" + + + +/** + * Subclass this to add caller-specific data + */ +struct tgsi_transform_context +{ +/**** PUBLIC ***/ + + /** + * User-defined callbacks invoked per instruction. + */ + void (*transform_instruction)(struct tgsi_transform_context *ctx, + struct tgsi_full_instruction *inst); + + void (*transform_declaration)(struct tgsi_transform_context *ctx, + struct tgsi_full_declaration *decl); + + void (*transform_immediate)(struct tgsi_transform_context *ctx, + struct tgsi_full_immediate *imm); + void (*transform_property)(struct tgsi_transform_context *ctx, + struct tgsi_full_property *prop); + + /** + * Called at end of input program to allow caller to append extra + * instructions. Return number of tokens emitted. + */ + void (*epilog)(struct tgsi_transform_context *ctx); + + +/*** PRIVATE ***/ + + /** + * These are setup by tgsi_transform_shader() and cannot be overridden. + * Meant to be called from in the above user callback functions. + */ + void (*emit_instruction)(struct tgsi_transform_context *ctx, + const struct tgsi_full_instruction *inst); + void (*emit_declaration)(struct tgsi_transform_context *ctx, + const struct tgsi_full_declaration *decl); + void (*emit_immediate)(struct tgsi_transform_context *ctx, + const struct tgsi_full_immediate *imm); + void (*emit_property)(struct tgsi_transform_context *ctx, + const struct tgsi_full_property *prop); + + struct tgsi_header *header; + uint max_tokens_out; + struct tgsi_token *tokens_out; + uint ti; +}; + + + +extern int +tgsi_transform_shader(const struct tgsi_token *tokens_in, + struct tgsi_token *tokens_out, + uint max_tokens_out, + struct tgsi_transform_context *ctx); + + +#endif /* TGSI_TRANSFORM_H */ diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c b/src/gallium/auxiliary/tgsi/tgsi_ureg.c new file mode 100644 index 0000000..7d13a17 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c @@ -0,0 +1,1524 @@ +/************************************************************************** + * + * 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, INC AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "tgsi/tgsi_ureg.h" +#include "tgsi/tgsi_build.h" +#include "tgsi/tgsi_info.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_sanity.h" +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "util/u_math.h" + +union tgsi_any_token { + struct tgsi_header header; + struct tgsi_processor processor; + struct tgsi_token token; + struct tgsi_property prop; + struct tgsi_property_data prop_data; + struct tgsi_declaration decl; + struct tgsi_declaration_range decl_range; + struct tgsi_declaration_dimension decl_dim; + struct tgsi_declaration_semantic decl_semantic; + struct tgsi_immediate imm; + union tgsi_immediate_data imm_data; + struct tgsi_instruction insn; + struct tgsi_instruction_predicate insn_predicate; + struct tgsi_instruction_label insn_label; + struct tgsi_instruction_texture insn_texture; + struct tgsi_src_register src; + struct tgsi_dimension dim; + struct tgsi_dst_register dst; + unsigned value; +}; + + +struct ureg_tokens { + union tgsi_any_token *tokens; + unsigned size; + unsigned order; + unsigned count; +}; + +#define UREG_MAX_INPUT PIPE_MAX_ATTRIBS +#define UREG_MAX_SYSTEM_VALUE PIPE_MAX_ATTRIBS +#define UREG_MAX_OUTPUT PIPE_MAX_ATTRIBS +#define UREG_MAX_CONSTANT_RANGE 32 +#define UREG_MAX_IMMEDIATE 32 +#define UREG_MAX_TEMP 256 +#define UREG_MAX_ADDR 2 +#define UREG_MAX_PRED 1 + +struct const_decl { + struct { + unsigned first; + unsigned last; + } constant_range[UREG_MAX_CONSTANT_RANGE]; + unsigned nr_constant_ranges; +}; + +#define DOMAIN_DECL 0 +#define DOMAIN_INSN 1 + +struct ureg_program +{ + unsigned processor; + struct pipe_context *pipe; + + struct { + unsigned semantic_name; + unsigned semantic_index; + unsigned interp; + unsigned char cylindrical_wrap; + unsigned char centroid; + } fs_input[UREG_MAX_INPUT]; + unsigned nr_fs_inputs; + + unsigned vs_inputs[UREG_MAX_INPUT/32]; + + struct { + unsigned index; + unsigned semantic_name; + unsigned semantic_index; + } gs_input[UREG_MAX_INPUT]; + unsigned nr_gs_inputs; + + struct { + unsigned index; + unsigned semantic_name; + unsigned semantic_index; + } system_value[UREG_MAX_SYSTEM_VALUE]; + unsigned nr_system_values; + + struct { + unsigned semantic_name; + unsigned semantic_index; + } output[UREG_MAX_OUTPUT]; + unsigned nr_outputs; + + struct { + union { + float f[4]; + unsigned u[4]; + int i[4]; + } value; + unsigned nr; + unsigned type; + } immediate[UREG_MAX_IMMEDIATE]; + unsigned nr_immediates; + + struct ureg_src sampler[PIPE_MAX_SAMPLERS]; + unsigned nr_samplers; + + unsigned temps_active[UREG_MAX_TEMP / 32]; + unsigned nr_temps; + + struct const_decl const_decls; + struct const_decl const_decls2D[PIPE_MAX_CONSTANT_BUFFERS]; + + unsigned property_gs_input_prim; + unsigned property_gs_output_prim; + unsigned property_gs_max_vertices; + unsigned char property_fs_coord_origin; /* = TGSI_FS_COORD_ORIGIN_* */ + unsigned char property_fs_coord_pixel_center; /* = TGSI_FS_COORD_PIXEL_CENTER_* */ + + unsigned nr_addrs; + unsigned nr_preds; + unsigned nr_instructions; + + struct ureg_tokens domain[2]; +}; + +static union tgsi_any_token error_tokens[32]; + +static void tokens_error( struct ureg_tokens *tokens ) +{ + if (tokens->tokens && tokens->tokens != error_tokens) + FREE(tokens->tokens); + + tokens->tokens = error_tokens; + tokens->size = Elements(error_tokens); + tokens->count = 0; +} + + +static void tokens_expand( struct ureg_tokens *tokens, + unsigned count ) +{ + unsigned old_size = tokens->size * sizeof(unsigned); + + if (tokens->tokens == error_tokens) { + return; + } + + while (tokens->count + count > tokens->size) { + tokens->size = (1 << ++tokens->order); + } + + tokens->tokens = REALLOC(tokens->tokens, + old_size, + tokens->size * sizeof(unsigned)); + if (tokens->tokens == NULL) { + tokens_error(tokens); + } +} + +static void set_bad( struct ureg_program *ureg ) +{ + tokens_error(&ureg->domain[0]); +} + + + +static union tgsi_any_token *get_tokens( struct ureg_program *ureg, + unsigned domain, + unsigned count ) +{ + struct ureg_tokens *tokens = &ureg->domain[domain]; + union tgsi_any_token *result; + + if (tokens->count + count > tokens->size) + tokens_expand(tokens, count); + + result = &tokens->tokens[tokens->count]; + tokens->count += count; + return result; +} + + +static union tgsi_any_token *retrieve_token( struct ureg_program *ureg, + unsigned domain, + unsigned nr ) +{ + if (ureg->domain[domain].tokens == error_tokens) + return &error_tokens[0]; + + return &ureg->domain[domain].tokens[nr]; +} + + + +static INLINE struct ureg_dst +ureg_dst_register( unsigned file, + unsigned index ) +{ + struct ureg_dst dst; + + dst.File = file; + dst.WriteMask = TGSI_WRITEMASK_XYZW; + dst.Indirect = 0; + dst.IndirectIndex = 0; + dst.IndirectSwizzle = 0; + dst.Saturate = 0; + dst.Predicate = 0; + dst.PredNegate = 0; + dst.PredSwizzleX = TGSI_SWIZZLE_X; + dst.PredSwizzleY = TGSI_SWIZZLE_Y; + dst.PredSwizzleZ = TGSI_SWIZZLE_Z; + dst.PredSwizzleW = TGSI_SWIZZLE_W; + dst.Index = index; + + return dst; +} + + +void +ureg_property_gs_input_prim(struct ureg_program *ureg, + unsigned input_prim) +{ + ureg->property_gs_input_prim = input_prim; +} + +void +ureg_property_gs_output_prim(struct ureg_program *ureg, + unsigned output_prim) +{ + ureg->property_gs_output_prim = output_prim; +} + +void +ureg_property_gs_max_vertices(struct ureg_program *ureg, + unsigned max_vertices) +{ + ureg->property_gs_max_vertices = max_vertices; +} + +void +ureg_property_fs_coord_origin(struct ureg_program *ureg, + unsigned fs_coord_origin) +{ + ureg->property_fs_coord_origin = fs_coord_origin; +} + +void +ureg_property_fs_coord_pixel_center(struct ureg_program *ureg, + unsigned fs_coord_pixel_center) +{ + ureg->property_fs_coord_pixel_center = fs_coord_pixel_center; +} + + + +struct ureg_src +ureg_DECL_fs_input_cyl_centroid(struct ureg_program *ureg, + unsigned semantic_name, + unsigned semantic_index, + unsigned interp_mode, + unsigned cylindrical_wrap, + unsigned centroid) +{ + unsigned i; + + for (i = 0; i < ureg->nr_fs_inputs; i++) { + if (ureg->fs_input[i].semantic_name == semantic_name && + ureg->fs_input[i].semantic_index == semantic_index) { + goto out; + } + } + + if (ureg->nr_fs_inputs < UREG_MAX_INPUT) { + ureg->fs_input[i].semantic_name = semantic_name; + ureg->fs_input[i].semantic_index = semantic_index; + ureg->fs_input[i].interp = interp_mode; + ureg->fs_input[i].cylindrical_wrap = cylindrical_wrap; + ureg->fs_input[i].centroid = centroid; + ureg->nr_fs_inputs++; + } else { + set_bad(ureg); + } + +out: + return ureg_src_register(TGSI_FILE_INPUT, i); +} + + +struct ureg_src +ureg_DECL_vs_input( struct ureg_program *ureg, + unsigned index ) +{ + assert(ureg->processor == TGSI_PROCESSOR_VERTEX); + + ureg->vs_inputs[index/32] |= 1 << (index % 32); + return ureg_src_register( TGSI_FILE_INPUT, index ); +} + + +struct ureg_src +ureg_DECL_gs_input(struct ureg_program *ureg, + unsigned index, + unsigned semantic_name, + unsigned semantic_index) +{ + if (ureg->nr_gs_inputs < UREG_MAX_INPUT) { + ureg->gs_input[ureg->nr_gs_inputs].index = index; + ureg->gs_input[ureg->nr_gs_inputs].semantic_name = semantic_name; + ureg->gs_input[ureg->nr_gs_inputs].semantic_index = semantic_index; + ureg->nr_gs_inputs++; + } else { + set_bad(ureg); + } + + /* XXX: Add suport for true 2D input registers. */ + return ureg_src_register(TGSI_FILE_INPUT, index); +} + + +struct ureg_src +ureg_DECL_system_value(struct ureg_program *ureg, + unsigned index, + unsigned semantic_name, + unsigned semantic_index) +{ + if (ureg->nr_system_values < UREG_MAX_SYSTEM_VALUE) { + ureg->system_value[ureg->nr_system_values].index = index; + ureg->system_value[ureg->nr_system_values].semantic_name = semantic_name; + ureg->system_value[ureg->nr_system_values].semantic_index = semantic_index; + ureg->nr_system_values++; + } else { + set_bad(ureg); + } + + return ureg_src_register(TGSI_FILE_SYSTEM_VALUE, index); +} + + +struct ureg_dst +ureg_DECL_output( struct ureg_program *ureg, + unsigned name, + unsigned index ) +{ + unsigned i; + + for (i = 0; i < ureg->nr_outputs; i++) { + if (ureg->output[i].semantic_name == name && + ureg->output[i].semantic_index == index) + goto out; + } + + if (ureg->nr_outputs < UREG_MAX_OUTPUT) { + ureg->output[i].semantic_name = name; + ureg->output[i].semantic_index = index; + ureg->nr_outputs++; + } + else { + set_bad( ureg ); + } + +out: + return ureg_dst_register( TGSI_FILE_OUTPUT, i ); +} + + +/* Returns a new constant register. Keep track of which have been + * referred to so that we can emit decls later. + * + * Constant operands declared with this function must be addressed + * with a two-dimensional index. + * + * There is nothing in this code to bind this constant to any tracked + * value or manage any constant_buffer contents -- that's the + * resposibility of the calling code. + */ +void +ureg_DECL_constant2D(struct ureg_program *ureg, + unsigned first, + unsigned last, + unsigned index2D) +{ + struct const_decl *decl = &ureg->const_decls2D[index2D]; + + assert(index2D < PIPE_MAX_CONSTANT_BUFFERS); + + if (decl->nr_constant_ranges < UREG_MAX_CONSTANT_RANGE) { + uint i = decl->nr_constant_ranges++; + + decl->constant_range[i].first = first; + decl->constant_range[i].last = last; + } +} + + +/* A one-dimensional, depricated version of ureg_DECL_constant2D(). + * + * Constant operands declared with this function must be addressed + * with a one-dimensional index. + */ +struct ureg_src +ureg_DECL_constant(struct ureg_program *ureg, + unsigned index) +{ + struct const_decl *decl = &ureg->const_decls; + unsigned minconst = index, maxconst = index; + unsigned i; + + /* Inside existing range? + */ + for (i = 0; i < decl->nr_constant_ranges; i++) { + if (decl->constant_range[i].first <= index && + decl->constant_range[i].last >= index) { + goto out; + } + } + + /* Extend existing range? + */ + for (i = 0; i < decl->nr_constant_ranges; i++) { + if (decl->constant_range[i].last == index - 1) { + decl->constant_range[i].last = index; + goto out; + } + + if (decl->constant_range[i].first == index + 1) { + decl->constant_range[i].first = index; + goto out; + } + + minconst = MIN2(minconst, decl->constant_range[i].first); + maxconst = MAX2(maxconst, decl->constant_range[i].last); + } + + /* Create new range? + */ + if (decl->nr_constant_ranges < UREG_MAX_CONSTANT_RANGE) { + i = decl->nr_constant_ranges++; + decl->constant_range[i].first = index; + decl->constant_range[i].last = index; + goto out; + } + + /* Collapse all ranges down to one: + */ + i = 0; + decl->constant_range[0].first = minconst; + decl->constant_range[0].last = maxconst; + decl->nr_constant_ranges = 1; + +out: + assert(i < decl->nr_constant_ranges); + assert(decl->constant_range[i].first <= index); + assert(decl->constant_range[i].last >= index); + return ureg_src_register(TGSI_FILE_CONSTANT, index); +} + + +/* Allocate a new temporary. Temporaries greater than UREG_MAX_TEMP + * are legal, but will not be released. + */ +struct ureg_dst ureg_DECL_temporary( struct ureg_program *ureg ) +{ + unsigned i; + + for (i = 0; i < UREG_MAX_TEMP; i += 32) { + int bit = ffs(~ureg->temps_active[i/32]); + if (bit != 0) { + i += bit - 1; + goto out; + } + } + + /* No reusable temps, so allocate a new one: + */ + i = ureg->nr_temps++; + +out: + if (i < UREG_MAX_TEMP) + ureg->temps_active[i/32] |= 1 << (i % 32); + + if (i >= ureg->nr_temps) + ureg->nr_temps = i + 1; + + return ureg_dst_register( TGSI_FILE_TEMPORARY, i ); +} + + +void ureg_release_temporary( struct ureg_program *ureg, + struct ureg_dst tmp ) +{ + if(tmp.File == TGSI_FILE_TEMPORARY) + if (tmp.Index < UREG_MAX_TEMP) + ureg->temps_active[tmp.Index/32] &= ~(1 << (tmp.Index % 32)); +} + + +/* Allocate a new address register. + */ +struct ureg_dst ureg_DECL_address( struct ureg_program *ureg ) +{ + if (ureg->nr_addrs < UREG_MAX_ADDR) + return ureg_dst_register( TGSI_FILE_ADDRESS, ureg->nr_addrs++ ); + + assert( 0 ); + return ureg_dst_register( TGSI_FILE_ADDRESS, 0 ); +} + +/* Allocate a new predicate register. + */ +struct ureg_dst +ureg_DECL_predicate(struct ureg_program *ureg) +{ + if (ureg->nr_preds < UREG_MAX_PRED) { + return ureg_dst_register(TGSI_FILE_PREDICATE, ureg->nr_preds++); + } + + assert(0); + return ureg_dst_register(TGSI_FILE_PREDICATE, 0); +} + +/* Allocate a new sampler. + */ +struct ureg_src ureg_DECL_sampler( struct ureg_program *ureg, + unsigned nr ) +{ + unsigned i; + + for (i = 0; i < ureg->nr_samplers; i++) + if (ureg->sampler[i].Index == nr) + return ureg->sampler[i]; + + if (i < PIPE_MAX_SAMPLERS) { + ureg->sampler[i] = ureg_src_register( TGSI_FILE_SAMPLER, nr ); + ureg->nr_samplers++; + return ureg->sampler[i]; + } + + assert( 0 ); + return ureg->sampler[0]; +} + + +static int +match_or_expand_immediate( const unsigned *v, + unsigned nr, + unsigned *v2, + unsigned *pnr2, + unsigned *swizzle ) +{ + unsigned nr2 = *pnr2; + unsigned i, j; + + *swizzle = 0; + + for (i = 0; i < nr; i++) { + boolean found = FALSE; + + for (j = 0; j < nr2 && !found; j++) { + if (v[i] == v2[j]) { + *swizzle |= j << (i * 2); + found = TRUE; + } + } + + if (!found) { + if (nr2 >= 4) { + return FALSE; + } + + v2[nr2] = v[i]; + *swizzle |= nr2 << (i * 2); + nr2++; + } + } + + /* Actually expand immediate only when fully succeeded. + */ + *pnr2 = nr2; + return TRUE; +} + + +static struct ureg_src +decl_immediate( struct ureg_program *ureg, + const unsigned *v, + unsigned nr, + unsigned type ) +{ + unsigned i, j; + unsigned swizzle = 0; + + /* Could do a first pass where we examine all existing immediates + * without expanding. + */ + + for (i = 0; i < ureg->nr_immediates; i++) { + if (ureg->immediate[i].type != type) { + continue; + } + if (match_or_expand_immediate(v, + nr, + ureg->immediate[i].value.u, + &ureg->immediate[i].nr, + &swizzle)) { + goto out; + } + } + + if (ureg->nr_immediates < UREG_MAX_IMMEDIATE) { + i = ureg->nr_immediates++; + ureg->immediate[i].type = type; + if (match_or_expand_immediate(v, + nr, + ureg->immediate[i].value.u, + &ureg->immediate[i].nr, + &swizzle)) { + goto out; + } + } + + set_bad(ureg); + +out: + /* Make sure that all referenced elements are from this immediate. + * Has the effect of making size-one immediates into scalars. + */ + for (j = nr; j < 4; j++) { + swizzle |= (swizzle & 0x3) << (j * 2); + } + + return ureg_swizzle(ureg_src_register(TGSI_FILE_IMMEDIATE, i), + (swizzle >> 0) & 0x3, + (swizzle >> 2) & 0x3, + (swizzle >> 4) & 0x3, + (swizzle >> 6) & 0x3); +} + + +struct ureg_src +ureg_DECL_immediate( struct ureg_program *ureg, + const float *v, + unsigned nr ) +{ + union { + float f[4]; + unsigned u[4]; + } fu; + unsigned int i; + + for (i = 0; i < nr; i++) { + fu.f[i] = v[i]; + } + + return decl_immediate(ureg, fu.u, nr, TGSI_IMM_FLOAT32); +} + + +struct ureg_src +ureg_DECL_immediate_uint( struct ureg_program *ureg, + const unsigned *v, + unsigned nr ) +{ + return decl_immediate(ureg, v, nr, TGSI_IMM_UINT32); +} + + +struct ureg_src +ureg_DECL_immediate_block_uint( struct ureg_program *ureg, + const unsigned *v, + unsigned nr ) +{ + uint index; + uint i; + + if (ureg->nr_immediates + (nr + 3) / 4 > UREG_MAX_IMMEDIATE) { + set_bad(ureg); + return ureg_src_register(TGSI_FILE_IMMEDIATE, 0); + } + + index = ureg->nr_immediates; + ureg->nr_immediates += (nr + 3) / 4; + + for (i = index; i < ureg->nr_immediates; i++) { + ureg->immediate[i].type = TGSI_IMM_UINT32; + ureg->immediate[i].nr = nr > 4 ? 4 : nr; + memcpy(ureg->immediate[i].value.u, + &v[(i - index) * 4], + ureg->immediate[i].nr * sizeof(uint)); + nr -= 4; + } + + return ureg_src_register(TGSI_FILE_IMMEDIATE, index); +} + + +struct ureg_src +ureg_DECL_immediate_int( struct ureg_program *ureg, + const int *v, + unsigned nr ) +{ + return decl_immediate(ureg, (const unsigned *)v, nr, TGSI_IMM_INT32); +} + + +void +ureg_emit_src( struct ureg_program *ureg, + struct ureg_src src ) +{ + unsigned size = 1 + (src.Indirect ? 1 : 0) + + (src.Dimension ? (src.DimIndirect ? 2 : 1) : 0); + + union tgsi_any_token *out = get_tokens( ureg, DOMAIN_INSN, size ); + unsigned n = 0; + + assert(src.File != TGSI_FILE_NULL); + assert(src.File != TGSI_FILE_OUTPUT); + assert(src.File < TGSI_FILE_COUNT); + + out[n].value = 0; + out[n].src.File = src.File; + out[n].src.SwizzleX = src.SwizzleX; + out[n].src.SwizzleY = src.SwizzleY; + out[n].src.SwizzleZ = src.SwizzleZ; + out[n].src.SwizzleW = src.SwizzleW; + out[n].src.Index = src.Index; + out[n].src.Negate = src.Negate; + out[0].src.Absolute = src.Absolute; + n++; + + if (src.Indirect) { + out[0].src.Indirect = 1; + out[n].value = 0; + out[n].src.File = src.IndirectFile; + out[n].src.SwizzleX = src.IndirectSwizzle; + out[n].src.SwizzleY = src.IndirectSwizzle; + out[n].src.SwizzleZ = src.IndirectSwizzle; + out[n].src.SwizzleW = src.IndirectSwizzle; + out[n].src.Index = src.IndirectIndex; + n++; + } + + if (src.Dimension) { + if (src.DimIndirect) { + out[0].src.Dimension = 1; + out[n].dim.Indirect = 1; + out[n].dim.Dimension = 0; + out[n].dim.Padding = 0; + out[n].dim.Index = src.DimensionIndex; + n++; + out[n].value = 0; + out[n].src.File = src.DimIndFile; + out[n].src.SwizzleX = src.DimIndSwizzle; + out[n].src.SwizzleY = src.DimIndSwizzle; + out[n].src.SwizzleZ = src.DimIndSwizzle; + out[n].src.SwizzleW = src.DimIndSwizzle; + out[n].src.Index = src.DimIndIndex; + } else { + out[0].src.Dimension = 1; + out[n].dim.Indirect = 0; + out[n].dim.Dimension = 0; + out[n].dim.Padding = 0; + out[n].dim.Index = src.DimensionIndex; + } + n++; + } + + assert(n == size); +} + + +void +ureg_emit_dst( struct ureg_program *ureg, + struct ureg_dst dst ) +{ + unsigned size = (1 + + (dst.Indirect ? 1 : 0)); + + union tgsi_any_token *out = get_tokens( ureg, DOMAIN_INSN, size ); + unsigned n = 0; + + assert(dst.File != TGSI_FILE_NULL); + assert(dst.File != TGSI_FILE_CONSTANT); + assert(dst.File != TGSI_FILE_INPUT); + assert(dst.File != TGSI_FILE_SAMPLER); + assert(dst.File != TGSI_FILE_IMMEDIATE); + assert(dst.File < TGSI_FILE_COUNT); + + out[n].value = 0; + out[n].dst.File = dst.File; + out[n].dst.WriteMask = dst.WriteMask; + out[n].dst.Indirect = dst.Indirect; + out[n].dst.Index = dst.Index; + n++; + + if (dst.Indirect) { + out[n].value = 0; + out[n].src.File = TGSI_FILE_ADDRESS; + out[n].src.SwizzleX = dst.IndirectSwizzle; + out[n].src.SwizzleY = dst.IndirectSwizzle; + out[n].src.SwizzleZ = dst.IndirectSwizzle; + out[n].src.SwizzleW = dst.IndirectSwizzle; + out[n].src.Index = dst.IndirectIndex; + n++; + } + + assert(n == size); +} + + +static void validate( unsigned opcode, + unsigned nr_dst, + unsigned nr_src ) +{ +#ifdef DEBUG + const struct tgsi_opcode_info *info = tgsi_get_opcode_info( opcode ); + assert(info); + if(info) { + assert(nr_dst == info->num_dst); + assert(nr_src == info->num_src); + } +#endif +} + +struct ureg_emit_insn_result +ureg_emit_insn(struct ureg_program *ureg, + unsigned opcode, + boolean saturate, + boolean predicate, + boolean pred_negate, + unsigned pred_swizzle_x, + unsigned pred_swizzle_y, + unsigned pred_swizzle_z, + unsigned pred_swizzle_w, + unsigned num_dst, + unsigned num_src ) +{ + union tgsi_any_token *out; + uint count = predicate ? 2 : 1; + struct ureg_emit_insn_result result; + + validate( opcode, num_dst, num_src ); + + out = get_tokens( ureg, DOMAIN_INSN, count ); + out[0].insn = tgsi_default_instruction(); + out[0].insn.Opcode = opcode; + out[0].insn.Saturate = saturate; + out[0].insn.NumDstRegs = num_dst; + out[0].insn.NumSrcRegs = num_src; + + result.insn_token = ureg->domain[DOMAIN_INSN].count - count; + result.extended_token = result.insn_token; + + if (predicate) { + out[0].insn.Predicate = 1; + out[1].insn_predicate = tgsi_default_instruction_predicate(); + out[1].insn_predicate.Negate = pred_negate; + out[1].insn_predicate.SwizzleX = pred_swizzle_x; + out[1].insn_predicate.SwizzleY = pred_swizzle_y; + out[1].insn_predicate.SwizzleZ = pred_swizzle_z; + out[1].insn_predicate.SwizzleW = pred_swizzle_w; + } + + ureg->nr_instructions++; + + return result; +} + + +void +ureg_emit_label(struct ureg_program *ureg, + unsigned extended_token, + unsigned *label_token ) +{ + union tgsi_any_token *out, *insn; + + if(!label_token) + return; + + out = get_tokens( ureg, DOMAIN_INSN, 1 ); + out[0].value = 0; + + insn = retrieve_token( ureg, DOMAIN_INSN, extended_token ); + insn->insn.Label = 1; + + *label_token = ureg->domain[DOMAIN_INSN].count - 1; +} + +/* Will return a number which can be used in a label to point to the + * next instruction to be emitted. + */ +unsigned +ureg_get_instruction_number( struct ureg_program *ureg ) +{ + return ureg->nr_instructions; +} + +/* Patch a given label (expressed as a token number) to point to a + * given instruction (expressed as an instruction number). + */ +void +ureg_fixup_label(struct ureg_program *ureg, + unsigned label_token, + unsigned instruction_number ) +{ + union tgsi_any_token *out = retrieve_token( ureg, DOMAIN_INSN, label_token ); + + out->insn_label.Label = instruction_number; +} + + +void +ureg_emit_texture(struct ureg_program *ureg, + unsigned extended_token, + unsigned target ) +{ + union tgsi_any_token *out, *insn; + + out = get_tokens( ureg, DOMAIN_INSN, 1 ); + insn = retrieve_token( ureg, DOMAIN_INSN, extended_token ); + + insn->insn.Texture = 1; + + out[0].value = 0; + out[0].insn_texture.Texture = target; +} + + +void +ureg_fixup_insn_size(struct ureg_program *ureg, + unsigned insn ) +{ + union tgsi_any_token *out = retrieve_token( ureg, DOMAIN_INSN, insn ); + + assert(out->insn.Type == TGSI_TOKEN_TYPE_INSTRUCTION); + out->insn.NrTokens = ureg->domain[DOMAIN_INSN].count - insn - 1; +} + + +void +ureg_insn(struct ureg_program *ureg, + unsigned opcode, + const struct ureg_dst *dst, + unsigned nr_dst, + const struct ureg_src *src, + unsigned nr_src ) +{ + struct ureg_emit_insn_result insn; + unsigned i; + boolean saturate; + boolean predicate; + boolean negate = FALSE; + unsigned swizzle[4] = { 0 }; + + saturate = nr_dst ? dst[0].Saturate : FALSE; + predicate = nr_dst ? dst[0].Predicate : FALSE; + if (predicate) { + negate = dst[0].PredNegate; + swizzle[0] = dst[0].PredSwizzleX; + swizzle[1] = dst[0].PredSwizzleY; + swizzle[2] = dst[0].PredSwizzleZ; + swizzle[3] = dst[0].PredSwizzleW; + } + + insn = ureg_emit_insn(ureg, + opcode, + saturate, + predicate, + negate, + swizzle[0], + swizzle[1], + swizzle[2], + swizzle[3], + nr_dst, + nr_src); + + for (i = 0; i < nr_dst; i++) + ureg_emit_dst( ureg, dst[i] ); + + for (i = 0; i < nr_src; i++) + ureg_emit_src( ureg, src[i] ); + + ureg_fixup_insn_size( ureg, insn.insn_token ); +} + +void +ureg_tex_insn(struct ureg_program *ureg, + unsigned opcode, + const struct ureg_dst *dst, + unsigned nr_dst, + unsigned target, + const struct ureg_src *src, + unsigned nr_src ) +{ + struct ureg_emit_insn_result insn; + unsigned i; + boolean saturate; + boolean predicate; + boolean negate = FALSE; + unsigned swizzle[4] = { 0 }; + + saturate = nr_dst ? dst[0].Saturate : FALSE; + predicate = nr_dst ? dst[0].Predicate : FALSE; + if (predicate) { + negate = dst[0].PredNegate; + swizzle[0] = dst[0].PredSwizzleX; + swizzle[1] = dst[0].PredSwizzleY; + swizzle[2] = dst[0].PredSwizzleZ; + swizzle[3] = dst[0].PredSwizzleW; + } + + insn = ureg_emit_insn(ureg, + opcode, + saturate, + predicate, + negate, + swizzle[0], + swizzle[1], + swizzle[2], + swizzle[3], + nr_dst, + nr_src); + + ureg_emit_texture( ureg, insn.extended_token, target ); + + for (i = 0; i < nr_dst; i++) + ureg_emit_dst( ureg, dst[i] ); + + for (i = 0; i < nr_src; i++) + ureg_emit_src( ureg, src[i] ); + + ureg_fixup_insn_size( ureg, insn.insn_token ); +} + + +void +ureg_label_insn(struct ureg_program *ureg, + unsigned opcode, + const struct ureg_src *src, + unsigned nr_src, + unsigned *label_token ) +{ + struct ureg_emit_insn_result insn; + unsigned i; + + insn = ureg_emit_insn(ureg, + opcode, + FALSE, + FALSE, + FALSE, + TGSI_SWIZZLE_X, + TGSI_SWIZZLE_Y, + TGSI_SWIZZLE_Z, + TGSI_SWIZZLE_W, + 0, + nr_src); + + ureg_emit_label( ureg, insn.extended_token, label_token ); + + for (i = 0; i < nr_src; i++) + ureg_emit_src( ureg, src[i] ); + + ureg_fixup_insn_size( ureg, insn.insn_token ); +} + + +static void +emit_decl_semantic(struct ureg_program *ureg, + unsigned file, + unsigned index, + unsigned semantic_name, + unsigned semantic_index) +{ + union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 3); + + out[0].value = 0; + out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION; + out[0].decl.NrTokens = 3; + out[0].decl.File = file; + out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; /* FIXME! */ + out[0].decl.Semantic = 1; + + out[1].value = 0; + out[1].decl_range.First = index; + out[1].decl_range.Last = index; + + out[2].value = 0; + out[2].decl_semantic.Name = semantic_name; + out[2].decl_semantic.Index = semantic_index; +} + + +static void +emit_decl_fs(struct ureg_program *ureg, + unsigned file, + unsigned index, + unsigned semantic_name, + unsigned semantic_index, + unsigned interpolate, + unsigned cylindrical_wrap, + unsigned centroid) +{ + union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 3); + + out[0].value = 0; + out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION; + out[0].decl.NrTokens = 3; + out[0].decl.File = file; + out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; /* FIXME! */ + out[0].decl.Interpolate = interpolate; + out[0].decl.Semantic = 1; + out[0].decl.CylindricalWrap = cylindrical_wrap; + out[0].decl.Centroid = centroid; + + out[1].value = 0; + out[1].decl_range.First = index; + out[1].decl_range.Last = index; + + out[2].value = 0; + out[2].decl_semantic.Name = semantic_name; + out[2].decl_semantic.Index = semantic_index; +} + + +static void emit_decl_range( struct ureg_program *ureg, + unsigned file, + unsigned first, + unsigned count ) +{ + union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, 2 ); + + out[0].value = 0; + out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION; + out[0].decl.NrTokens = 2; + out[0].decl.File = file; + out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; + out[0].decl.Interpolate = TGSI_INTERPOLATE_CONSTANT; + out[0].decl.Semantic = 0; + + out[1].value = 0; + out[1].decl_range.First = first; + out[1].decl_range.Last = first + count - 1; +} + +static void +emit_decl_range2D(struct ureg_program *ureg, + unsigned file, + unsigned first, + unsigned last, + unsigned index2D) +{ + union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 3); + + out[0].value = 0; + out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION; + out[0].decl.NrTokens = 3; + out[0].decl.File = file; + out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; + out[0].decl.Interpolate = TGSI_INTERPOLATE_CONSTANT; + out[0].decl.Dimension = 1; + + out[1].value = 0; + out[1].decl_range.First = first; + out[1].decl_range.Last = last; + + out[2].value = 0; + out[2].decl_dim.Index2D = index2D; +} + +static void +emit_immediate( struct ureg_program *ureg, + const unsigned *v, + unsigned type ) +{ + union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, 5 ); + + out[0].value = 0; + out[0].imm.Type = TGSI_TOKEN_TYPE_IMMEDIATE; + out[0].imm.NrTokens = 5; + out[0].imm.DataType = type; + out[0].imm.Padding = 0; + + out[1].imm_data.Uint = v[0]; + out[2].imm_data.Uint = v[1]; + out[3].imm_data.Uint = v[2]; + out[4].imm_data.Uint = v[3]; +} + +static void +emit_property(struct ureg_program *ureg, + unsigned name, + unsigned data) +{ + union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 2); + + out[0].value = 0; + out[0].prop.Type = TGSI_TOKEN_TYPE_PROPERTY; + out[0].prop.NrTokens = 2; + out[0].prop.PropertyName = name; + + out[1].prop_data.Data = data; +} + + +static void emit_decls( struct ureg_program *ureg ) +{ + unsigned i; + + if (ureg->property_gs_input_prim != ~0) { + assert(ureg->processor == TGSI_PROCESSOR_GEOMETRY); + + emit_property(ureg, + TGSI_PROPERTY_GS_INPUT_PRIM, + ureg->property_gs_input_prim); + } + + if (ureg->property_gs_output_prim != ~0) { + assert(ureg->processor == TGSI_PROCESSOR_GEOMETRY); + + emit_property(ureg, + TGSI_PROPERTY_GS_OUTPUT_PRIM, + ureg->property_gs_output_prim); + } + + if (ureg->property_gs_max_vertices != ~0) { + assert(ureg->processor == TGSI_PROCESSOR_GEOMETRY); + + emit_property(ureg, + TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES, + ureg->property_gs_max_vertices); + } + + if (ureg->property_fs_coord_origin) { + assert(ureg->processor == TGSI_PROCESSOR_FRAGMENT); + + emit_property(ureg, + TGSI_PROPERTY_FS_COORD_ORIGIN, + ureg->property_fs_coord_origin); + } + + if (ureg->property_fs_coord_pixel_center) { + assert(ureg->processor == TGSI_PROCESSOR_FRAGMENT); + + emit_property(ureg, + TGSI_PROPERTY_FS_COORD_PIXEL_CENTER, + ureg->property_fs_coord_pixel_center); + } + + if (ureg->processor == TGSI_PROCESSOR_VERTEX) { + for (i = 0; i < UREG_MAX_INPUT; i++) { + if (ureg->vs_inputs[i/32] & (1 << (i%32))) { + emit_decl_range( ureg, TGSI_FILE_INPUT, i, 1 ); + } + } + } else if (ureg->processor == TGSI_PROCESSOR_FRAGMENT) { + for (i = 0; i < ureg->nr_fs_inputs; i++) { + emit_decl_fs(ureg, + TGSI_FILE_INPUT, + i, + ureg->fs_input[i].semantic_name, + ureg->fs_input[i].semantic_index, + ureg->fs_input[i].interp, + ureg->fs_input[i].cylindrical_wrap, + ureg->fs_input[i].centroid); + } + } else { + for (i = 0; i < ureg->nr_gs_inputs; i++) { + emit_decl_semantic(ureg, + TGSI_FILE_INPUT, + ureg->gs_input[i].index, + ureg->gs_input[i].semantic_name, + ureg->gs_input[i].semantic_index); + } + } + + for (i = 0; i < ureg->nr_system_values; i++) { + emit_decl_semantic(ureg, + TGSI_FILE_SYSTEM_VALUE, + ureg->system_value[i].index, + ureg->system_value[i].semantic_name, + ureg->system_value[i].semantic_index); + } + + for (i = 0; i < ureg->nr_outputs; i++) { + emit_decl_semantic(ureg, + TGSI_FILE_OUTPUT, + i, + ureg->output[i].semantic_name, + ureg->output[i].semantic_index); + } + + for (i = 0; i < ureg->nr_samplers; i++) { + emit_decl_range( ureg, + TGSI_FILE_SAMPLER, + ureg->sampler[i].Index, 1 ); + } + + if (ureg->const_decls.nr_constant_ranges) { + for (i = 0; i < ureg->const_decls.nr_constant_ranges; i++) { + emit_decl_range(ureg, + TGSI_FILE_CONSTANT, + ureg->const_decls.constant_range[i].first, + ureg->const_decls.constant_range[i].last - ureg->const_decls.constant_range[i].first + 1); + } + } + + for (i = 0; i < PIPE_MAX_CONSTANT_BUFFERS; i++) { + struct const_decl *decl = &ureg->const_decls2D[i]; + + if (decl->nr_constant_ranges) { + uint j; + + for (j = 0; j < decl->nr_constant_ranges; j++) { + emit_decl_range2D(ureg, + TGSI_FILE_CONSTANT, + decl->constant_range[j].first, + decl->constant_range[j].last, + i); + } + } + } + + if (ureg->nr_temps) { + emit_decl_range( ureg, + TGSI_FILE_TEMPORARY, + 0, ureg->nr_temps ); + } + + if (ureg->nr_addrs) { + emit_decl_range( ureg, + TGSI_FILE_ADDRESS, + 0, ureg->nr_addrs ); + } + + if (ureg->nr_preds) { + emit_decl_range(ureg, + TGSI_FILE_PREDICATE, + 0, + ureg->nr_preds); + } + + for (i = 0; i < ureg->nr_immediates; i++) { + emit_immediate( ureg, + ureg->immediate[i].value.u, + ureg->immediate[i].type ); + } +} + +/* Append the instruction tokens onto the declarations to build a + * contiguous stream suitable to send to the driver. + */ +static void copy_instructions( struct ureg_program *ureg ) +{ + unsigned nr_tokens = ureg->domain[DOMAIN_INSN].count; + union tgsi_any_token *out = get_tokens( ureg, + DOMAIN_DECL, + nr_tokens ); + + memcpy(out, + ureg->domain[DOMAIN_INSN].tokens, + nr_tokens * sizeof out[0] ); +} + + +static void +fixup_header_size(struct ureg_program *ureg) +{ + union tgsi_any_token *out = retrieve_token( ureg, DOMAIN_DECL, 0 ); + + out->header.BodySize = ureg->domain[DOMAIN_DECL].count - 2; +} + + +static void +emit_header( struct ureg_program *ureg ) +{ + union tgsi_any_token *out = get_tokens( ureg, DOMAIN_DECL, 2 ); + + out[0].header.HeaderSize = 2; + out[0].header.BodySize = 0; + + out[1].processor.Processor = ureg->processor; + out[1].processor.Padding = 0; +} + + +const struct tgsi_token *ureg_finalize( struct ureg_program *ureg ) +{ + const struct tgsi_token *tokens; + + emit_header( ureg ); + emit_decls( ureg ); + copy_instructions( ureg ); + fixup_header_size( ureg ); + + if (ureg->domain[0].tokens == error_tokens || + ureg->domain[1].tokens == error_tokens) { + debug_printf("%s: error in generated shader\n", __FUNCTION__); + assert(0); + return NULL; + } + + tokens = &ureg->domain[DOMAIN_DECL].tokens[0].token; + + if (0) { + debug_printf("%s: emitted shader %d tokens:\n", __FUNCTION__, + ureg->domain[DOMAIN_DECL].count); + tgsi_dump( tokens, 0 ); + } + +#if DEBUG + if (tokens && !tgsi_sanity_check(tokens)) { + debug_printf("tgsi_ureg.c, sanity check failed on generated tokens:\n"); + tgsi_dump(tokens, 0); + assert(0); + } +#endif + + + return tokens; +} + + +void *ureg_create_shader( struct ureg_program *ureg, + struct pipe_context *pipe ) +{ + struct pipe_shader_state state; + + state.tokens = ureg_finalize(ureg); + if(!state.tokens) + return NULL; + + if (ureg->processor == TGSI_PROCESSOR_VERTEX) + return pipe->create_vs_state( pipe, &state ); + else + return pipe->create_fs_state( pipe, &state ); +} + + +const struct tgsi_token *ureg_get_tokens( struct ureg_program *ureg, + unsigned *nr_tokens ) +{ + const struct tgsi_token *tokens; + + ureg_finalize(ureg); + + tokens = &ureg->domain[DOMAIN_DECL].tokens[0].token; + + if (nr_tokens) + *nr_tokens = ureg->domain[DOMAIN_DECL].size; + + ureg->domain[DOMAIN_DECL].tokens = 0; + ureg->domain[DOMAIN_DECL].size = 0; + ureg->domain[DOMAIN_DECL].order = 0; + ureg->domain[DOMAIN_DECL].count = 0; + + return tokens; +} + + +void ureg_free_tokens( const struct tgsi_token *tokens ) +{ + FREE((struct tgsi_token *)tokens); +} + + +struct ureg_program *ureg_create( unsigned processor ) +{ + struct ureg_program *ureg = CALLOC_STRUCT( ureg_program ); + if (ureg == NULL) + return NULL; + + ureg->processor = processor; + ureg->property_gs_input_prim = ~0; + ureg->property_gs_output_prim = ~0; + ureg->property_gs_max_vertices = ~0; + return ureg; +} + + +void ureg_destroy( struct ureg_program *ureg ) +{ + unsigned i; + + for (i = 0; i < Elements(ureg->domain); i++) { + if (ureg->domain[i].tokens && + ureg->domain[i].tokens != error_tokens) + FREE(ureg->domain[i].tokens); + } + + FREE(ureg); +} diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.h b/src/gallium/auxiliary/tgsi/tgsi_ureg.h new file mode 100644 index 0000000..acc4632 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.h @@ -0,0 +1,1016 @@ +/************************************************************************** + * + * 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, INC 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 TGSI_UREG_H +#define TGSI_UREG_H + +#include "pipe/p_compiler.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_debug.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct ureg_program; + +/* Almost a tgsi_src_register, but we need to pull in the Absolute + * flag from the _ext token. Indirect flag always implies ADDR[0]. + */ +struct ureg_src +{ + unsigned File : 4; /* TGSI_FILE_ */ + unsigned SwizzleX : 2; /* TGSI_SWIZZLE_ */ + unsigned SwizzleY : 2; /* TGSI_SWIZZLE_ */ + unsigned SwizzleZ : 2; /* TGSI_SWIZZLE_ */ + unsigned SwizzleW : 2; /* TGSI_SWIZZLE_ */ + unsigned Indirect : 1; /* BOOL */ + unsigned DimIndirect : 1; /* BOOL */ + unsigned Dimension : 1; /* BOOL */ + unsigned Absolute : 1; /* BOOL */ + unsigned Negate : 1; /* BOOL */ + int Index : 16; /* SINT */ + unsigned IndirectFile : 4; /* TGSI_FILE_ */ + int IndirectIndex : 16; /* SINT */ + unsigned IndirectSwizzle : 2; /* TGSI_SWIZZLE_ */ + int DimensionIndex : 16; /* SINT */ + unsigned DimIndFile : 4; /* TGSI_FILE_ */ + int DimIndIndex : 16; /* SINT */ + unsigned DimIndSwizzle : 2; /* TGSI_SWIZZLE_ */ +}; + +/* Very similar to a tgsi_dst_register, removing unsupported fields + * and adding a Saturate flag. It's easier to push saturate into the + * destination register than to try and create a _SAT varient of each + * instruction function. + */ +struct ureg_dst +{ + unsigned File : 4; /* TGSI_FILE_ */ + unsigned WriteMask : 4; /* TGSI_WRITEMASK_ */ + unsigned Indirect : 1; /* BOOL */ + unsigned Saturate : 1; /* BOOL */ + unsigned Predicate : 1; + unsigned PredNegate : 1; /* BOOL */ + unsigned PredSwizzleX: 2; /* TGSI_SWIZZLE_ */ + unsigned PredSwizzleY: 2; /* TGSI_SWIZZLE_ */ + unsigned PredSwizzleZ: 2; /* TGSI_SWIZZLE_ */ + unsigned PredSwizzleW: 2; /* TGSI_SWIZZLE_ */ + int Index : 16; /* SINT */ + int IndirectIndex : 16; /* SINT */ + int IndirectSwizzle : 2; /* TGSI_SWIZZLE_ */ +}; + +struct pipe_context; + +struct ureg_program * +ureg_create( unsigned processor ); + +const struct tgsi_token * +ureg_finalize( struct ureg_program * ); + +/* Create and return a shader: + */ +void * +ureg_create_shader( struct ureg_program *, + struct pipe_context *pipe ); + + +/* Alternately, return the built token stream and hand ownership of + * that memory to the caller: + */ +const struct tgsi_token * +ureg_get_tokens( struct ureg_program *ureg, + unsigned *nr_tokens ); + + +/* Free the tokens created by ureg_get_tokens() */ +void ureg_free_tokens( const struct tgsi_token *tokens ); + + +void +ureg_destroy( struct ureg_program * ); + + +/*********************************************************************** + * Convenience routine: + */ +static INLINE void * +ureg_create_shader_and_destroy( struct ureg_program *p, + struct pipe_context *pipe ) +{ + void *result = ureg_create_shader( p, pipe ); + ureg_destroy( p ); + return result; +} + + +/*********************************************************************** + * Build shader properties: + */ + +void +ureg_property_gs_input_prim(struct ureg_program *ureg, + unsigned input_prim); + +void +ureg_property_gs_output_prim(struct ureg_program *ureg, + unsigned output_prim); + +void +ureg_property_gs_max_vertices(struct ureg_program *ureg, + unsigned max_vertices); + +void +ureg_property_fs_coord_origin(struct ureg_program *ureg, + unsigned fs_coord_origin); + +void +ureg_property_fs_coord_pixel_center(struct ureg_program *ureg, + unsigned fs_coord_pixel_center); + +/*********************************************************************** + * Build shader declarations: + */ + +struct ureg_src +ureg_DECL_fs_input_cyl_centroid(struct ureg_program *, + unsigned semantic_name, + unsigned semantic_index, + unsigned interp_mode, + unsigned cylindrical_wrap, + unsigned centroid); + +static INLINE struct ureg_src +ureg_DECL_fs_input_cyl(struct ureg_program *ureg, + unsigned semantic_name, + unsigned semantic_index, + unsigned interp_mode, + unsigned cylindrical_wrap) +{ + return ureg_DECL_fs_input_cyl_centroid(ureg, + semantic_name, + semantic_index, + interp_mode, + cylindrical_wrap, + 0); +} + +static INLINE struct ureg_src +ureg_DECL_fs_input(struct ureg_program *ureg, + unsigned semantic_name, + unsigned semantic_index, + unsigned interp_mode) +{ + return ureg_DECL_fs_input_cyl_centroid(ureg, + semantic_name, + semantic_index, + interp_mode, + 0, 0); +} + +struct ureg_src +ureg_DECL_vs_input( struct ureg_program *, + unsigned index ); + +struct ureg_src +ureg_DECL_gs_input(struct ureg_program *, + unsigned index, + unsigned semantic_name, + unsigned semantic_index); + +struct ureg_src +ureg_DECL_system_value(struct ureg_program *, + unsigned index, + unsigned semantic_name, + unsigned semantic_index); + +struct ureg_dst +ureg_DECL_output( struct ureg_program *, + unsigned semantic_name, + unsigned semantic_index ); + +struct ureg_src +ureg_DECL_immediate( struct ureg_program *, + const float *v, + unsigned nr ); + +struct ureg_src +ureg_DECL_immediate_uint( struct ureg_program *, + const unsigned *v, + unsigned nr ); + +struct ureg_src +ureg_DECL_immediate_block_uint( struct ureg_program *, + const unsigned *v, + unsigned nr ); + +struct ureg_src +ureg_DECL_immediate_int( struct ureg_program *, + const int *v, + unsigned nr ); + +void +ureg_DECL_constant2D(struct ureg_program *ureg, + unsigned first, + unsigned last, + unsigned index2D); + +struct ureg_src +ureg_DECL_constant( struct ureg_program *, + unsigned index ); + +struct ureg_dst +ureg_DECL_temporary( struct ureg_program * ); + +void +ureg_release_temporary( struct ureg_program *ureg, + struct ureg_dst tmp ); + +struct ureg_dst +ureg_DECL_address( struct ureg_program * ); + +struct ureg_dst +ureg_DECL_predicate(struct ureg_program *); + +/* Supply an index to the sampler declaration as this is the hook to + * the external pipe_sampler state. Users of this function probably + * don't want just any sampler, but a specific one which they've set + * up state for in the context. + */ +struct ureg_src +ureg_DECL_sampler( struct ureg_program *, + unsigned index ); + + +static INLINE struct ureg_src +ureg_imm4f( struct ureg_program *ureg, + float a, float b, + float c, float d) +{ + float v[4]; + v[0] = a; + v[1] = b; + v[2] = c; + v[3] = d; + return ureg_DECL_immediate( ureg, v, 4 ); +} + +static INLINE struct ureg_src +ureg_imm3f( struct ureg_program *ureg, + float a, float b, + float c) +{ + float v[3]; + v[0] = a; + v[1] = b; + v[2] = c; + return ureg_DECL_immediate( ureg, v, 3 ); +} + +static INLINE struct ureg_src +ureg_imm2f( struct ureg_program *ureg, + float a, float b) +{ + float v[2]; + v[0] = a; + v[1] = b; + return ureg_DECL_immediate( ureg, v, 2 ); +} + +static INLINE struct ureg_src +ureg_imm1f( struct ureg_program *ureg, + float a) +{ + float v[1]; + v[0] = a; + return ureg_DECL_immediate( ureg, v, 1 ); +} + +static INLINE struct ureg_src +ureg_imm4u( struct ureg_program *ureg, + unsigned a, unsigned b, + unsigned c, unsigned d) +{ + unsigned v[4]; + v[0] = a; + v[1] = b; + v[2] = c; + v[3] = d; + return ureg_DECL_immediate_uint( ureg, v, 4 ); +} + +static INLINE struct ureg_src +ureg_imm3u( struct ureg_program *ureg, + unsigned a, unsigned b, + unsigned c) +{ + unsigned v[3]; + v[0] = a; + v[1] = b; + v[2] = c; + return ureg_DECL_immediate_uint( ureg, v, 3 ); +} + +static INLINE struct ureg_src +ureg_imm2u( struct ureg_program *ureg, + unsigned a, unsigned b) +{ + unsigned v[2]; + v[0] = a; + v[1] = b; + return ureg_DECL_immediate_uint( ureg, v, 2 ); +} + +static INLINE struct ureg_src +ureg_imm1u( struct ureg_program *ureg, + unsigned a) +{ + return ureg_DECL_immediate_uint( ureg, &a, 1 ); +} + +static INLINE struct ureg_src +ureg_imm4i( struct ureg_program *ureg, + int a, int b, + int c, int d) +{ + int v[4]; + v[0] = a; + v[1] = b; + v[2] = c; + v[3] = d; + return ureg_DECL_immediate_int( ureg, v, 4 ); +} + +static INLINE struct ureg_src +ureg_imm3i( struct ureg_program *ureg, + int a, int b, + int c) +{ + int v[3]; + v[0] = a; + v[1] = b; + v[2] = c; + return ureg_DECL_immediate_int( ureg, v, 3 ); +} + +static INLINE struct ureg_src +ureg_imm2i( struct ureg_program *ureg, + int a, int b) +{ + int v[2]; + v[0] = a; + v[1] = b; + return ureg_DECL_immediate_int( ureg, v, 2 ); +} + +static INLINE struct ureg_src +ureg_imm1i( struct ureg_program *ureg, + int a) +{ + return ureg_DECL_immediate_int( ureg, &a, 1 ); +} + +/*********************************************************************** + * Functions for patching up labels + */ + + +/* Will return a number which can be used in a label to point to the + * next instruction to be emitted. + */ +unsigned +ureg_get_instruction_number( struct ureg_program *ureg ); + + +/* Patch a given label (expressed as a token number) to point to a + * given instruction (expressed as an instruction number). + * + * Labels are obtained from instruction emitters, eg ureg_CAL(). + * Instruction numbers are obtained from ureg_get_instruction_number(), + * above. + */ +void +ureg_fixup_label(struct ureg_program *ureg, + unsigned label_token, + unsigned instruction_number ); + + +/* Generic instruction emitter. Use if you need to pass the opcode as + * a parameter, rather than using the emit_OP() varients below. + */ +void +ureg_insn(struct ureg_program *ureg, + unsigned opcode, + const struct ureg_dst *dst, + unsigned nr_dst, + const struct ureg_src *src, + unsigned nr_src ); + + +void +ureg_tex_insn(struct ureg_program *ureg, + unsigned opcode, + const struct ureg_dst *dst, + unsigned nr_dst, + unsigned target, + const struct ureg_src *src, + unsigned nr_src ); + + +void +ureg_label_insn(struct ureg_program *ureg, + unsigned opcode, + const struct ureg_src *src, + unsigned nr_src, + unsigned *label); + + +/*********************************************************************** + * Internal instruction helpers, don't call these directly: + */ + +struct ureg_emit_insn_result { + unsigned insn_token; /*< Used to fixup insn size. */ + unsigned extended_token; /*< Used to set the Extended bit, usually the same as insn_token. */ +}; + +struct ureg_emit_insn_result +ureg_emit_insn(struct ureg_program *ureg, + unsigned opcode, + boolean saturate, + boolean predicate, + boolean pred_negate, + unsigned pred_swizzle_x, + unsigned pred_swizzle_y, + unsigned pred_swizzle_z, + unsigned pred_swizzle_w, + unsigned num_dst, + unsigned num_src ); + +void +ureg_emit_label(struct ureg_program *ureg, + unsigned insn_token, + unsigned *label_token ); + +void +ureg_emit_texture(struct ureg_program *ureg, + unsigned insn_token, + unsigned target ); + +void +ureg_emit_dst( struct ureg_program *ureg, + struct ureg_dst dst ); + +void +ureg_emit_src( struct ureg_program *ureg, + struct ureg_src src ); + +void +ureg_fixup_insn_size(struct ureg_program *ureg, + unsigned insn ); + + +#define OP00( op ) \ +static INLINE void ureg_##op( struct ureg_program *ureg ) \ +{ \ + unsigned opcode = TGSI_OPCODE_##op; \ + unsigned insn = ureg_emit_insn(ureg, \ + opcode, \ + FALSE, \ + FALSE, \ + FALSE, \ + TGSI_SWIZZLE_X, \ + TGSI_SWIZZLE_Y, \ + TGSI_SWIZZLE_Z, \ + TGSI_SWIZZLE_W, \ + 0, \ + 0).insn_token; \ + ureg_fixup_insn_size( ureg, insn ); \ +} + +#define OP01( op ) \ +static INLINE void ureg_##op( struct ureg_program *ureg, \ + struct ureg_src src ) \ +{ \ + unsigned opcode = TGSI_OPCODE_##op; \ + unsigned insn = ureg_emit_insn(ureg, \ + opcode, \ + FALSE, \ + FALSE, \ + FALSE, \ + TGSI_SWIZZLE_X, \ + TGSI_SWIZZLE_Y, \ + TGSI_SWIZZLE_Z, \ + TGSI_SWIZZLE_W, \ + 0, \ + 1).insn_token; \ + ureg_emit_src( ureg, src ); \ + ureg_fixup_insn_size( ureg, insn ); \ +} + +#define OP00_LBL( op ) \ +static INLINE void ureg_##op( struct ureg_program *ureg, \ + unsigned *label_token ) \ +{ \ + unsigned opcode = TGSI_OPCODE_##op; \ + struct ureg_emit_insn_result insn; \ + insn = ureg_emit_insn(ureg, \ + opcode, \ + FALSE, \ + FALSE, \ + FALSE, \ + TGSI_SWIZZLE_X, \ + TGSI_SWIZZLE_Y, \ + TGSI_SWIZZLE_Z, \ + TGSI_SWIZZLE_W, \ + 0, \ + 0); \ + ureg_emit_label( ureg, insn.extended_token, label_token ); \ + ureg_fixup_insn_size( ureg, insn.insn_token ); \ +} + +#define OP01_LBL( op ) \ +static INLINE void ureg_##op( struct ureg_program *ureg, \ + struct ureg_src src, \ + unsigned *label_token ) \ +{ \ + unsigned opcode = TGSI_OPCODE_##op; \ + struct ureg_emit_insn_result insn; \ + insn = ureg_emit_insn(ureg, \ + opcode, \ + FALSE, \ + FALSE, \ + FALSE, \ + TGSI_SWIZZLE_X, \ + TGSI_SWIZZLE_Y, \ + TGSI_SWIZZLE_Z, \ + TGSI_SWIZZLE_W, \ + 0, \ + 1); \ + ureg_emit_label( ureg, insn.extended_token, label_token ); \ + ureg_emit_src( ureg, src ); \ + ureg_fixup_insn_size( ureg, insn.insn_token ); \ +} + +#define OP10( op ) \ +static INLINE void ureg_##op( struct ureg_program *ureg, \ + struct ureg_dst dst ) \ +{ \ + unsigned opcode = TGSI_OPCODE_##op; \ + unsigned insn = ureg_emit_insn(ureg, \ + opcode, \ + dst.Saturate, \ + dst.Predicate, \ + dst.PredNegate, \ + dst.PredSwizzleX, \ + dst.PredSwizzleY, \ + dst.PredSwizzleZ, \ + dst.PredSwizzleW, \ + 1, \ + 0).insn_token; \ + ureg_emit_dst( ureg, dst ); \ + ureg_fixup_insn_size( ureg, insn ); \ +} + + +#define OP11( op ) \ +static INLINE void ureg_##op( struct ureg_program *ureg, \ + struct ureg_dst dst, \ + struct ureg_src src ) \ +{ \ + unsigned opcode = TGSI_OPCODE_##op; \ + unsigned insn = ureg_emit_insn(ureg, \ + opcode, \ + dst.Saturate, \ + dst.Predicate, \ + dst.PredNegate, \ + dst.PredSwizzleX, \ + dst.PredSwizzleY, \ + dst.PredSwizzleZ, \ + dst.PredSwizzleW, \ + 1, \ + 1).insn_token; \ + ureg_emit_dst( ureg, dst ); \ + ureg_emit_src( ureg, src ); \ + ureg_fixup_insn_size( ureg, insn ); \ +} + +#define OP12( op ) \ +static INLINE void ureg_##op( struct ureg_program *ureg, \ + struct ureg_dst dst, \ + struct ureg_src src0, \ + struct ureg_src src1 ) \ +{ \ + unsigned opcode = TGSI_OPCODE_##op; \ + unsigned insn = ureg_emit_insn(ureg, \ + opcode, \ + dst.Saturate, \ + dst.Predicate, \ + dst.PredNegate, \ + dst.PredSwizzleX, \ + dst.PredSwizzleY, \ + dst.PredSwizzleZ, \ + dst.PredSwizzleW, \ + 1, \ + 2).insn_token; \ + ureg_emit_dst( ureg, dst ); \ + ureg_emit_src( ureg, src0 ); \ + ureg_emit_src( ureg, src1 ); \ + ureg_fixup_insn_size( ureg, insn ); \ +} + +#define OP12_TEX( op ) \ +static INLINE void ureg_##op( struct ureg_program *ureg, \ + struct ureg_dst dst, \ + unsigned target, \ + struct ureg_src src0, \ + struct ureg_src src1 ) \ +{ \ + unsigned opcode = TGSI_OPCODE_##op; \ + struct ureg_emit_insn_result insn; \ + insn = ureg_emit_insn(ureg, \ + opcode, \ + dst.Saturate, \ + dst.Predicate, \ + dst.PredNegate, \ + dst.PredSwizzleX, \ + dst.PredSwizzleY, \ + dst.PredSwizzleZ, \ + dst.PredSwizzleW, \ + 1, \ + 2); \ + ureg_emit_texture( ureg, insn.extended_token, target ); \ + ureg_emit_dst( ureg, dst ); \ + ureg_emit_src( ureg, src0 ); \ + ureg_emit_src( ureg, src1 ); \ + ureg_fixup_insn_size( ureg, insn.insn_token ); \ +} + +#define OP13( op ) \ +static INLINE void ureg_##op( struct ureg_program *ureg, \ + struct ureg_dst dst, \ + struct ureg_src src0, \ + struct ureg_src src1, \ + struct ureg_src src2 ) \ +{ \ + unsigned opcode = TGSI_OPCODE_##op; \ + unsigned insn = ureg_emit_insn(ureg, \ + opcode, \ + dst.Saturate, \ + dst.Predicate, \ + dst.PredNegate, \ + dst.PredSwizzleX, \ + dst.PredSwizzleY, \ + dst.PredSwizzleZ, \ + dst.PredSwizzleW, \ + 1, \ + 3).insn_token; \ + ureg_emit_dst( ureg, dst ); \ + ureg_emit_src( ureg, src0 ); \ + ureg_emit_src( ureg, src1 ); \ + ureg_emit_src( ureg, src2 ); \ + ureg_fixup_insn_size( ureg, insn ); \ +} + +#define OP14_TEX( op ) \ +static INLINE void ureg_##op( struct ureg_program *ureg, \ + struct ureg_dst dst, \ + unsigned target, \ + struct ureg_src src0, \ + struct ureg_src src1, \ + struct ureg_src src2, \ + struct ureg_src src3 ) \ +{ \ + unsigned opcode = TGSI_OPCODE_##op; \ + struct ureg_emit_insn_result insn; \ + insn = ureg_emit_insn(ureg, \ + opcode, \ + dst.Saturate, \ + dst.Predicate, \ + dst.PredNegate, \ + dst.PredSwizzleX, \ + dst.PredSwizzleY, \ + dst.PredSwizzleZ, \ + dst.PredSwizzleW, \ + 1, \ + 4); \ + ureg_emit_texture( ureg, insn.extended_token, target ); \ + ureg_emit_dst( ureg, dst ); \ + ureg_emit_src( ureg, src0 ); \ + ureg_emit_src( ureg, src1 ); \ + ureg_emit_src( ureg, src2 ); \ + ureg_emit_src( ureg, src3 ); \ + ureg_fixup_insn_size( ureg, insn.insn_token ); \ +} + + +/* Use a template include to generate a correctly-typed ureg_OP() + * function for each TGSI opcode: + */ +#include "tgsi_opcode_tmp.h" + + +/*********************************************************************** + * Inline helpers for manipulating register structs: + */ +static INLINE struct ureg_src +ureg_negate( struct ureg_src reg ) +{ + assert(reg.File != TGSI_FILE_NULL); + reg.Negate ^= 1; + return reg; +} + +static INLINE struct ureg_src +ureg_abs( struct ureg_src reg ) +{ + assert(reg.File != TGSI_FILE_NULL); + reg.Absolute = 1; + reg.Negate = 0; + return reg; +} + +static INLINE struct ureg_src +ureg_swizzle( struct ureg_src reg, + int x, int y, int z, int w ) +{ + unsigned swz = ( (reg.SwizzleX << 0) | + (reg.SwizzleY << 2) | + (reg.SwizzleZ << 4) | + (reg.SwizzleW << 6)); + + assert(reg.File != TGSI_FILE_NULL); + assert(x < 4); + assert(y < 4); + assert(z < 4); + assert(w < 4); + + reg.SwizzleX = (swz >> (x*2)) & 0x3; + reg.SwizzleY = (swz >> (y*2)) & 0x3; + reg.SwizzleZ = (swz >> (z*2)) & 0x3; + reg.SwizzleW = (swz >> (w*2)) & 0x3; + return reg; +} + +static INLINE struct ureg_src +ureg_scalar( struct ureg_src reg, int x ) +{ + return ureg_swizzle(reg, x, x, x, x); +} + +static INLINE struct ureg_dst +ureg_writemask( struct ureg_dst reg, + unsigned writemask ) +{ + assert(reg.File != TGSI_FILE_NULL); + reg.WriteMask &= writemask; + return reg; +} + +static INLINE struct ureg_dst +ureg_saturate( struct ureg_dst reg ) +{ + assert(reg.File != TGSI_FILE_NULL); + reg.Saturate = 1; + return reg; +} + +static INLINE struct ureg_dst +ureg_predicate(struct ureg_dst reg, + boolean negate, + unsigned swizzle_x, + unsigned swizzle_y, + unsigned swizzle_z, + unsigned swizzle_w) +{ + assert(reg.File != TGSI_FILE_NULL); + reg.Predicate = 1; + reg.PredNegate = negate; + reg.PredSwizzleX = swizzle_x; + reg.PredSwizzleY = swizzle_y; + reg.PredSwizzleZ = swizzle_z; + reg.PredSwizzleW = swizzle_w; + return reg; +} + +static INLINE struct ureg_dst +ureg_dst_indirect( struct ureg_dst reg, struct ureg_src addr ) +{ + assert(reg.File != TGSI_FILE_NULL); + assert(addr.File == TGSI_FILE_ADDRESS); + reg.Indirect = 1; + reg.IndirectIndex = addr.Index; + reg.IndirectSwizzle = addr.SwizzleX; + return reg; +} + +static INLINE struct ureg_src +ureg_src_indirect( struct ureg_src reg, struct ureg_src addr ) +{ + assert(reg.File != TGSI_FILE_NULL); + assert(addr.File == TGSI_FILE_ADDRESS || addr.File == TGSI_FILE_TEMPORARY); + reg.Indirect = 1; + reg.IndirectFile = addr.File; + reg.IndirectIndex = addr.Index; + reg.IndirectSwizzle = addr.SwizzleX; + return reg; +} + +static INLINE struct ureg_src +ureg_src_dimension( struct ureg_src reg, int index ) +{ + assert(reg.File != TGSI_FILE_NULL); + reg.Dimension = 1; + reg.DimIndirect = 0; + reg.DimensionIndex = index; + return reg; +} + + +static INLINE struct ureg_src +ureg_src_dimension_indirect( struct ureg_src reg, struct ureg_src addr, + int index ) +{ + assert(reg.File != TGSI_FILE_NULL); + reg.Dimension = 1; + reg.DimIndirect = 1; + reg.DimensionIndex = index; + reg.DimIndFile = addr.File; + reg.DimIndIndex = addr.Index; + reg.DimIndSwizzle = addr.SwizzleX; + return reg; +} + +static INLINE struct ureg_dst +ureg_dst( struct ureg_src src ) +{ + struct ureg_dst dst; + + assert(!src.Indirect || src.IndirectFile == TGSI_FILE_ADDRESS); + + dst.File = src.File; + dst.WriteMask = TGSI_WRITEMASK_XYZW; + dst.Indirect = src.Indirect; + dst.IndirectIndex = src.IndirectIndex; + dst.IndirectSwizzle = src.IndirectSwizzle; + dst.Saturate = 0; + dst.Predicate = 0; + dst.PredNegate = 0; + dst.PredSwizzleX = TGSI_SWIZZLE_X; + dst.PredSwizzleY = TGSI_SWIZZLE_Y; + dst.PredSwizzleZ = TGSI_SWIZZLE_Z; + dst.PredSwizzleW = TGSI_SWIZZLE_W; + dst.Index = src.Index; + + return dst; +} + +static INLINE struct ureg_src +ureg_src_register(unsigned file, + unsigned index) +{ + struct ureg_src src; + + src.File = file; + src.SwizzleX = TGSI_SWIZZLE_X; + src.SwizzleY = TGSI_SWIZZLE_Y; + src.SwizzleZ = TGSI_SWIZZLE_Z; + src.SwizzleW = TGSI_SWIZZLE_W; + src.Indirect = 0; + src.IndirectFile = TGSI_FILE_NULL; + src.IndirectIndex = 0; + src.IndirectSwizzle = 0; + src.Absolute = 0; + src.Index = index; + src.Negate = 0; + src.Dimension = 0; + src.DimensionIndex = 0; + src.DimIndirect = 0; + src.DimIndFile = TGSI_FILE_NULL; + src.DimIndIndex = 0; + src.DimIndSwizzle = 0; + + return src; +} + +static INLINE struct ureg_src +ureg_src( struct ureg_dst dst ) +{ + struct ureg_src src; + + src.File = dst.File; + src.SwizzleX = TGSI_SWIZZLE_X; + src.SwizzleY = TGSI_SWIZZLE_Y; + src.SwizzleZ = TGSI_SWIZZLE_Z; + src.SwizzleW = TGSI_SWIZZLE_W; + src.Indirect = dst.Indirect; + src.IndirectFile = TGSI_FILE_ADDRESS; + src.IndirectIndex = dst.IndirectIndex; + src.IndirectSwizzle = dst.IndirectSwizzle; + src.Absolute = 0; + src.Index = dst.Index; + src.Negate = 0; + src.Dimension = 0; + src.DimensionIndex = 0; + src.DimIndirect = 0; + src.DimIndFile = TGSI_FILE_NULL; + src.DimIndIndex = 0; + src.DimIndSwizzle = 0; + + return src; +} + + + +static INLINE struct ureg_dst +ureg_dst_undef( void ) +{ + struct ureg_dst dst; + + dst.File = TGSI_FILE_NULL; + dst.WriteMask = 0; + dst.Indirect = 0; + dst.IndirectIndex = 0; + dst.IndirectSwizzle = 0; + dst.Saturate = 0; + dst.Predicate = 0; + dst.PredNegate = 0; + dst.PredSwizzleX = TGSI_SWIZZLE_X; + dst.PredSwizzleY = TGSI_SWIZZLE_Y; + dst.PredSwizzleZ = TGSI_SWIZZLE_Z; + dst.PredSwizzleW = TGSI_SWIZZLE_W; + dst.Index = 0; + + return dst; +} + +static INLINE struct ureg_src +ureg_src_undef( void ) +{ + struct ureg_src src; + + src.File = TGSI_FILE_NULL; + src.SwizzleX = 0; + src.SwizzleY = 0; + src.SwizzleZ = 0; + src.SwizzleW = 0; + src.Indirect = 0; + src.IndirectFile = TGSI_FILE_NULL; + src.IndirectIndex = 0; + src.IndirectSwizzle = 0; + src.Absolute = 0; + src.Index = 0; + src.Negate = 0; + src.Dimension = 0; + src.DimensionIndex = 0; + src.DimIndirect = 0; + src.DimIndFile = TGSI_FILE_NULL; + src.DimIndIndex = 0; + src.DimIndSwizzle = 0; + + return src; +} + +static INLINE boolean +ureg_src_is_undef( struct ureg_src src ) +{ + return src.File == TGSI_FILE_NULL; +} + +static INLINE boolean +ureg_dst_is_undef( struct ureg_dst dst ) +{ + return dst.File == TGSI_FILE_NULL; +} + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/auxiliary/tgsi/tgsi_util.c b/src/gallium/auxiliary/tgsi/tgsi_util.c new file mode 100644 index 0000000..08e7e89 --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_util.c @@ -0,0 +1,312 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_debug.h" +#include "pipe/p_shader_tokens.h" +#include "tgsi_parse.h" +#include "tgsi_util.h" + +union pointer_hack +{ + void *pointer; + uint64_t uint64; +}; + +void * +tgsi_align_128bit( + void *unaligned ) +{ + union pointer_hack ph; + + ph.uint64 = 0; + ph.pointer = unaligned; + ph.uint64 = (ph.uint64 + 15) & ~15; + return ph.pointer; +} + +unsigned +tgsi_util_get_src_register_swizzle( + const struct tgsi_src_register *reg, + unsigned component ) +{ + switch( component ) { + case 0: + return reg->SwizzleX; + case 1: + return reg->SwizzleY; + case 2: + return reg->SwizzleZ; + case 3: + return reg->SwizzleW; + default: + assert( 0 ); + } + return 0; +} + + +unsigned +tgsi_util_get_full_src_register_swizzle( + const struct tgsi_full_src_register *reg, + unsigned component ) +{ + return tgsi_util_get_src_register_swizzle( + ®->Register, + component ); +} + +void +tgsi_util_set_src_register_swizzle( + struct tgsi_src_register *reg, + unsigned swizzle, + unsigned component ) +{ + switch( component ) { + case 0: + reg->SwizzleX = swizzle; + break; + case 1: + reg->SwizzleY = swizzle; + break; + case 2: + reg->SwizzleZ = swizzle; + break; + case 3: + reg->SwizzleW = swizzle; + break; + default: + assert( 0 ); + } +} + +unsigned +tgsi_util_get_full_src_register_sign_mode( + const struct tgsi_full_src_register *reg, + unsigned component ) +{ + unsigned sign_mode; + + if( reg->Register.Absolute ) { + /* Consider only the post-abs negation. */ + + if( reg->Register.Negate ) { + sign_mode = TGSI_UTIL_SIGN_SET; + } + else { + sign_mode = TGSI_UTIL_SIGN_CLEAR; + } + } + else { + if( reg->Register.Negate ) { + sign_mode = TGSI_UTIL_SIGN_TOGGLE; + } + else { + sign_mode = TGSI_UTIL_SIGN_KEEP; + } + } + + return sign_mode; +} + +void +tgsi_util_set_full_src_register_sign_mode( + struct tgsi_full_src_register *reg, + unsigned sign_mode ) +{ + switch (sign_mode) + { + case TGSI_UTIL_SIGN_CLEAR: + reg->Register.Negate = 0; + reg->Register.Absolute = 1; + break; + + case TGSI_UTIL_SIGN_SET: + reg->Register.Absolute = 1; + reg->Register.Negate = 1; + break; + + case TGSI_UTIL_SIGN_TOGGLE: + reg->Register.Negate = 1; + reg->Register.Absolute = 0; + break; + + case TGSI_UTIL_SIGN_KEEP: + reg->Register.Negate = 0; + reg->Register.Absolute = 0; + break; + + default: + assert( 0 ); + } +} + +/** + * Determine which channels of the specificed src register are effectively + * used by this instruction. + */ +unsigned +tgsi_util_get_inst_usage_mask(const struct tgsi_full_instruction *inst, + unsigned src_idx) +{ + const struct tgsi_full_src_register *src = &inst->Src[src_idx]; + unsigned write_mask = inst->Dst[0].Register.WriteMask; + unsigned read_mask; + unsigned usage_mask; + unsigned chan; + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_MOV: + case TGSI_OPCODE_ARL: + case TGSI_OPCODE_ARR: + case TGSI_OPCODE_RCP: + case TGSI_OPCODE_MUL: + case TGSI_OPCODE_DIV: + case TGSI_OPCODE_ADD: + case TGSI_OPCODE_MIN: + case TGSI_OPCODE_MAX: + case TGSI_OPCODE_SLT: + case TGSI_OPCODE_SGE: + case TGSI_OPCODE_MAD: + case TGSI_OPCODE_SUB: + case TGSI_OPCODE_LRP: + case TGSI_OPCODE_CND: + case TGSI_OPCODE_FRC: + case TGSI_OPCODE_CEIL: + case TGSI_OPCODE_CLAMP: + case TGSI_OPCODE_FLR: + case TGSI_OPCODE_ROUND: + case TGSI_OPCODE_POW: + case TGSI_OPCODE_ABS: + case TGSI_OPCODE_COS: + case TGSI_OPCODE_SIN: + case TGSI_OPCODE_DDX: + case TGSI_OPCODE_DDY: + case TGSI_OPCODE_SEQ: + case TGSI_OPCODE_SGT: + case TGSI_OPCODE_SLE: + case TGSI_OPCODE_SNE: + case TGSI_OPCODE_SSG: + case TGSI_OPCODE_CMP: + case TGSI_OPCODE_TRUNC: + case TGSI_OPCODE_NOT: + case TGSI_OPCODE_AND: + case TGSI_OPCODE_OR: + case TGSI_OPCODE_XOR: + case TGSI_OPCODE_SAD: + /* Channel-wise operations */ + read_mask = write_mask; + break; + + case TGSI_OPCODE_EX2: + case TGSI_OPCODE_LG2: + case TGSI_OPCODE_RCC: + read_mask = TGSI_WRITEMASK_X; + break; + + case TGSI_OPCODE_SCS: + read_mask = write_mask & TGSI_WRITEMASK_XY ? TGSI_WRITEMASK_X : 0; + break; + + case TGSI_OPCODE_EXP: + case TGSI_OPCODE_LOG: + read_mask = write_mask & TGSI_WRITEMASK_XYZ ? TGSI_WRITEMASK_X : 0; + break; + + case TGSI_OPCODE_DP2A: + read_mask = src_idx == 2 ? TGSI_WRITEMASK_X : TGSI_WRITEMASK_XY; + break; + + case TGSI_OPCODE_DP2: + read_mask = TGSI_WRITEMASK_XY; + break; + + case TGSI_OPCODE_DP3: + read_mask = TGSI_WRITEMASK_XYZ; + break; + + case TGSI_OPCODE_DP4: + read_mask = TGSI_WRITEMASK_XYZW; + break; + + case TGSI_OPCODE_DPH: + read_mask = src_idx == 0 ? TGSI_WRITEMASK_XYZ : TGSI_WRITEMASK_XYZW; + break; + + case TGSI_OPCODE_TEX: + case TGSI_OPCODE_TXD: + case TGSI_OPCODE_TXB: + case TGSI_OPCODE_TXL: + case TGSI_OPCODE_TXP: + if (src_idx == 0) { + /* Note that the SHADOW variants use the Z component too */ + switch (inst->Texture.Texture) { + case TGSI_TEXTURE_1D: + read_mask = TGSI_WRITEMASK_X; + break; + case TGSI_TEXTURE_SHADOW1D: + read_mask = TGSI_WRITEMASK_XZ; + break; + case TGSI_TEXTURE_2D: + case TGSI_TEXTURE_RECT: + read_mask = TGSI_WRITEMASK_XY; + break; + case TGSI_TEXTURE_SHADOW2D: + case TGSI_TEXTURE_SHADOWRECT: + case TGSI_TEXTURE_3D: + case TGSI_TEXTURE_CUBE: + read_mask = TGSI_WRITEMASK_XYZ; + break; + + default: + assert(0); + read_mask = 0; + } + + if (inst->Instruction.Opcode != TGSI_OPCODE_TEX) { + read_mask |= TGSI_WRITEMASK_W; + } + } else { + /* A safe approximation */ + read_mask = TGSI_WRITEMASK_XYZW; + } + break; + + default: + /* Assume all channels are read */ + read_mask = TGSI_WRITEMASK_XYZW; + break; + } + + usage_mask = 0; + for (chan = 0; chan < 4; ++chan) { + if (read_mask & (1 << chan)) { + usage_mask |= 1 << tgsi_util_get_full_src_register_swizzle(src, chan); + } + } + + return usage_mask; +} diff --git a/src/gallium/auxiliary/tgsi/tgsi_util.h b/src/gallium/auxiliary/tgsi/tgsi_util.h new file mode 100644 index 0000000..04702ba --- /dev/null +++ b/src/gallium/auxiliary/tgsi/tgsi_util.h @@ -0,0 +1,83 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef TGSI_UTIL_H +#define TGSI_UTIL_H + +#if defined __cplusplus +extern "C" { +#endif + +struct tgsi_src_register; +struct tgsi_full_src_register; +struct tgsi_full_instruction; + +void * +tgsi_align_128bit( + void *unaligned ); + +unsigned +tgsi_util_get_src_register_swizzle( + const struct tgsi_src_register *reg, + unsigned component ); + + +unsigned +tgsi_util_get_full_src_register_swizzle( + const struct tgsi_full_src_register *reg, + unsigned component ); + +void +tgsi_util_set_src_register_swizzle( + struct tgsi_src_register *reg, + unsigned swizzle, + unsigned component ); + +#define TGSI_UTIL_SIGN_CLEAR 0 /* Force positive */ +#define TGSI_UTIL_SIGN_SET 1 /* Force negative */ +#define TGSI_UTIL_SIGN_TOGGLE 2 /* Negate */ +#define TGSI_UTIL_SIGN_KEEP 3 /* No change */ + +unsigned +tgsi_util_get_full_src_register_sign_mode( + const struct tgsi_full_src_register *reg, + unsigned component ); + +void +tgsi_util_set_full_src_register_sign_mode( + struct tgsi_full_src_register *reg, + unsigned sign_mode ); + +unsigned +tgsi_util_get_inst_usage_mask(const struct tgsi_full_instruction *inst, + unsigned src_idx); + +#if defined __cplusplus +} +#endif + +#endif /* TGSI_UTIL_H */ diff --git a/src/gallium/auxiliary/translate/translate.c b/src/gallium/auxiliary/translate/translate.c new file mode 100644 index 0000000..73287b6 --- /dev/null +++ b/src/gallium/auxiliary/translate/translate.c @@ -0,0 +1,55 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + +#include "pipe/p_config.h" +#include "pipe/p_state.h" +#include "translate.h" + +struct translate *translate_create( const struct translate_key *key ) +{ + struct translate *translate = NULL; + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) + translate = translate_sse2_create( key ); + if (translate) + return translate; +#else + (void)translate; +#endif + + return translate_generic_create( key ); +} + +boolean translate_is_output_format_supported(enum pipe_format format) +{ + return translate_generic_is_output_format_supported(format); +} diff --git a/src/gallium/auxiliary/translate/translate.h b/src/gallium/auxiliary/translate/translate.h new file mode 100644 index 0000000..850ef39 --- /dev/null +++ b/src/gallium/auxiliary/translate/translate.h @@ -0,0 +1,156 @@ +/* + * Copyright 2008 Tungsten Graphics, 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 + * 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 + * TUNGSTEN GRAPHICS 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. + */ + + +/** + * Vertex fetch/store/convert code. This functionality is used in two places: + * 1. Vertex fetch/convert - to grab vertex data from incoming vertex + * arrays and convert to format needed by vertex shaders. + * 2. Vertex store/emit - to convert simple float[][4] vertex attributes + * (which is the organization used throughout the draw/prim pipeline) to + * hardware-specific formats and emit into hardware vertex buffers. + * + * + * Authors: + * Keith Whitwell + */ + +#ifndef _TRANSLATE_H +#define _TRANSLATE_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" + +enum translate_element_type { + TRANSLATE_ELEMENT_NORMAL, + TRANSLATE_ELEMENT_INSTANCE_ID +}; + +struct translate_element +{ + enum translate_element_type type; + enum pipe_format input_format; + enum pipe_format output_format; + unsigned input_buffer:8; + unsigned input_offset:24; + unsigned instance_divisor; + unsigned output_offset; +}; + + +struct translate_key { + unsigned output_stride; + unsigned nr_elements; + struct translate_element element[PIPE_MAX_ATTRIBS + 1]; +}; + + +struct translate; + + +typedef void (PIPE_CDECL *run_elts_func)(struct translate *, + const unsigned *elts, + unsigned count, + unsigned instance_id, + void *output_buffer); + +typedef void (PIPE_CDECL *run_elts16_func)(struct translate *, + const uint16_t *elts, + unsigned count, + unsigned instance_id, + void *output_buffer); + +typedef void (PIPE_CDECL *run_elts8_func)(struct translate *, + const uint8_t *elts, + unsigned count, + unsigned instance_id, + void *output_buffer); + +typedef void (PIPE_CDECL *run_func)(struct translate *, + unsigned start, + unsigned count, + unsigned instance_id, + void *output_buffer); + +struct translate { + struct translate_key key; + + void (*release)( struct translate * ); + + void (*set_buffer)( struct translate *, + unsigned i, + const void *ptr, + unsigned stride, + unsigned max_index ); + + run_elts_func run_elts; + run_elts16_func run_elts16; + run_elts8_func run_elts8; + run_func run; +}; + + + +struct translate *translate_create( const struct translate_key *key ); + +boolean translate_is_output_format_supported(enum pipe_format format); + +static INLINE int translate_keysize( const struct translate_key *key ) +{ + return 2 * sizeof(int) + key->nr_elements * sizeof(struct translate_element); +} + +static INLINE int translate_key_compare( const struct translate_key *a, + const struct translate_key *b ) +{ + int keysize_a = translate_keysize(a); + int keysize_b = translate_keysize(b); + + if (keysize_a != keysize_b) { + return keysize_a - keysize_b; + } + return memcmp(a, b, keysize_a); +} + + +static INLINE void translate_key_sanitize( struct translate_key *a ) +{ + int keysize = translate_keysize(a); + char *ptr = (char *)a; + memset(ptr + keysize, 0, sizeof(*a) - keysize); +} + + +/******************************************************************************* + * Private: + */ +struct translate *translate_sse2_create( const struct translate_key *key ); + +struct translate *translate_generic_create( const struct translate_key *key ); + +boolean translate_generic_is_output_format_supported(enum pipe_format format); + +#endif diff --git a/src/gallium/auxiliary/translate/translate_cache.c b/src/gallium/auxiliary/translate/translate_cache.c new file mode 100644 index 0000000..d8069a1 --- /dev/null +++ b/src/gallium/auxiliary/translate/translate_cache.c @@ -0,0 +1,102 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_memory.h" +#include "pipe/p_state.h" +#include "translate.h" +#include "translate_cache.h" + +#include "cso_cache/cso_cache.h" +#include "cso_cache/cso_hash.h" + +struct translate_cache { + struct cso_hash *hash; +}; + +struct translate_cache * translate_cache_create( void ) +{ + struct translate_cache *cache = MALLOC_STRUCT(translate_cache); + cache->hash = cso_hash_create(); + return cache; +} + + +static INLINE void delete_translates(struct translate_cache *cache) +{ + struct cso_hash *hash = cache->hash; + struct cso_hash_iter iter = cso_hash_first_node(hash); + while (!cso_hash_iter_is_null(iter)) { + struct translate *state = (struct translate*)cso_hash_iter_data(iter); + iter = cso_hash_iter_next(iter); + if (state) { + state->release(state); + } + } +} + +void translate_cache_destroy(struct translate_cache *cache) +{ + delete_translates(cache); + cso_hash_delete(cache->hash); + FREE(cache); +} + + +static INLINE unsigned translate_hash_key_size(struct translate_key *key) +{ + unsigned size = sizeof(struct translate_key) - + sizeof(struct translate_element) * (PIPE_MAX_ATTRIBS - key->nr_elements); + return size; +} + +static INLINE unsigned create_key(struct translate_key *key) +{ + unsigned hash_key; + unsigned size = translate_hash_key_size(key); + /*debug_printf("key size = %d, (els = %d)\n", + size, key->nr_elements);*/ + hash_key = cso_construct_key(key, size); + return hash_key; +} + +struct translate * translate_cache_find(struct translate_cache *cache, + struct translate_key *key) +{ + unsigned hash_key = create_key(key); + struct translate *translate = (struct translate*) + cso_hash_find_data_from_template(cache->hash, + hash_key, + key, sizeof(*key)); + + if (!translate) { + /* create/insert */ + translate = translate_create(key); + cso_hash_insert(cache->hash, hash_key, translate); + } + + return translate; +} diff --git a/src/gallium/auxiliary/translate/translate_cache.h b/src/gallium/auxiliary/translate/translate_cache.h new file mode 100644 index 0000000..7dba871 --- /dev/null +++ b/src/gallium/auxiliary/translate/translate_cache.h @@ -0,0 +1,54 @@ +/* + * Copyright 2008 Tungsten Graphics, 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 + * 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 + * TUNGSTEN GRAPHICS 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 _TRANSLATE_CACHE_H +#define _TRANSLATE_CACHE_H + + +/******************************************************************************* + * Translate cache. + * Simply used to cache created translates. Avoids unecessary creation of + * translate's if one suitable for a given translate_key has already been + * created. + * + * Note: this functionality depends and requires the CSO module. + */ +struct translate_cache; + +struct translate_key; +struct translate; + +struct translate_cache *translate_cache_create( void ); +void translate_cache_destroy(struct translate_cache *cache); + +/** + * Will try to find a translate structure matched by the given key. + * If such a structure doesn't exist in the cache the function + * will automatically create it, insert it in the cache and + * return the created version. + * + */ +struct translate *translate_cache_find(struct translate_cache *cache, + struct translate_key *key); + +#endif diff --git a/src/gallium/auxiliary/translate/translate_generic.c b/src/gallium/auxiliary/translate/translate_generic.c new file mode 100644 index 0000000..ad809db --- /dev/null +++ b/src/gallium/auxiliary/translate/translate_generic.c @@ -0,0 +1,659 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_memory.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "pipe/p_state.h" +#include "translate.h" + + +#define DRAW_DBG 0 + +typedef void (*fetch_func)(float *dst, + const uint8_t *src, + unsigned i, unsigned j); +typedef void (*emit_func)(const float *attrib, void *ptr); + + + +struct translate_generic { + struct translate translate; + + struct { + enum translate_element_type type; + + fetch_func fetch; + unsigned buffer; + unsigned input_offset; + unsigned instance_divisor; + + emit_func emit; + unsigned output_offset; + + const uint8_t *input_ptr; + unsigned input_stride; + unsigned max_index; + + /* this value is set to -1 if this is a normal element with output_format != input_format: + * in this case, u_format is used to do a full conversion + * + * this value is set to the format size in bytes if output_format == input_format or for 32-bit instance ids: + * in this case, memcpy is used to copy this amount of bytes + */ + int copy_size; + + } attrib[PIPE_MAX_ATTRIBS]; + + unsigned nr_attrib; +}; + + +static struct translate_generic *translate_generic( struct translate *translate ) +{ + return (struct translate_generic *)translate; +} + +/** + * Fetch a float[4] vertex attribute from memory, doing format/type + * conversion as needed. + * + * This is probably needed/dupliocated elsewhere, eg format + * conversion, texture sampling etc. + */ +#define ATTRIB( NAME, SZ, TYPE, TO ) \ +static void \ +emit_##NAME(const float *attrib, void *ptr) \ +{ \ + unsigned i; \ + TYPE *out = (TYPE *)ptr; \ + \ + for (i = 0; i < SZ; i++) { \ + out[i] = TO(attrib[i]); \ + } \ +} + + +#define TO_64_FLOAT(x) ((double) x) +#define TO_32_FLOAT(x) (x) + +#define TO_8_USCALED(x) ((unsigned char) x) +#define TO_16_USCALED(x) ((unsigned short) x) +#define TO_32_USCALED(x) ((unsigned int) x) + +#define TO_8_SSCALED(x) ((char) x) +#define TO_16_SSCALED(x) ((short) x) +#define TO_32_SSCALED(x) ((int) x) + +#define TO_8_UNORM(x) ((unsigned char) (x * 255.0f)) +#define TO_16_UNORM(x) ((unsigned short) (x * 65535.0f)) +#define TO_32_UNORM(x) ((unsigned int) (x * 4294967295.0f)) + +#define TO_8_SNORM(x) ((char) (x * 127.0f)) +#define TO_16_SNORM(x) ((short) (x * 32767.0f)) +#define TO_32_SNORM(x) ((int) (x * 2147483647.0f)) + +#define TO_32_FIXED(x) ((int) (x * 65536.0f)) + + +ATTRIB( R64G64B64A64_FLOAT, 4, double, TO_64_FLOAT ) +ATTRIB( R64G64B64_FLOAT, 3, double, TO_64_FLOAT ) +ATTRIB( R64G64_FLOAT, 2, double, TO_64_FLOAT ) +ATTRIB( R64_FLOAT, 1, double, TO_64_FLOAT ) + +ATTRIB( R32G32B32A32_FLOAT, 4, float, TO_32_FLOAT ) +ATTRIB( R32G32B32_FLOAT, 3, float, TO_32_FLOAT ) +ATTRIB( R32G32_FLOAT, 2, float, TO_32_FLOAT ) +ATTRIB( R32_FLOAT, 1, float, TO_32_FLOAT ) + +ATTRIB( R32G32B32A32_USCALED, 4, unsigned, TO_32_USCALED ) +ATTRIB( R32G32B32_USCALED, 3, unsigned, TO_32_USCALED ) +ATTRIB( R32G32_USCALED, 2, unsigned, TO_32_USCALED ) +ATTRIB( R32_USCALED, 1, unsigned, TO_32_USCALED ) + +ATTRIB( R32G32B32A32_SSCALED, 4, int, TO_32_SSCALED ) +ATTRIB( R32G32B32_SSCALED, 3, int, TO_32_SSCALED ) +ATTRIB( R32G32_SSCALED, 2, int, TO_32_SSCALED ) +ATTRIB( R32_SSCALED, 1, int, TO_32_SSCALED ) + +ATTRIB( R32G32B32A32_UNORM, 4, unsigned, TO_32_UNORM ) +ATTRIB( R32G32B32_UNORM, 3, unsigned, TO_32_UNORM ) +ATTRIB( R32G32_UNORM, 2, unsigned, TO_32_UNORM ) +ATTRIB( R32_UNORM, 1, unsigned, TO_32_UNORM ) + +ATTRIB( R32G32B32A32_SNORM, 4, int, TO_32_SNORM ) +ATTRIB( R32G32B32_SNORM, 3, int, TO_32_SNORM ) +ATTRIB( R32G32_SNORM, 2, int, TO_32_SNORM ) +ATTRIB( R32_SNORM, 1, int, TO_32_SNORM ) + +ATTRIB( R16G16B16A16_USCALED, 4, ushort, TO_16_USCALED ) +ATTRIB( R16G16B16_USCALED, 3, ushort, TO_16_USCALED ) +ATTRIB( R16G16_USCALED, 2, ushort, TO_16_USCALED ) +ATTRIB( R16_USCALED, 1, ushort, TO_16_USCALED ) + +ATTRIB( R16G16B16A16_SSCALED, 4, short, TO_16_SSCALED ) +ATTRIB( R16G16B16_SSCALED, 3, short, TO_16_SSCALED ) +ATTRIB( R16G16_SSCALED, 2, short, TO_16_SSCALED ) +ATTRIB( R16_SSCALED, 1, short, TO_16_SSCALED ) + +ATTRIB( R16G16B16A16_UNORM, 4, ushort, TO_16_UNORM ) +ATTRIB( R16G16B16_UNORM, 3, ushort, TO_16_UNORM ) +ATTRIB( R16G16_UNORM, 2, ushort, TO_16_UNORM ) +ATTRIB( R16_UNORM, 1, ushort, TO_16_UNORM ) + +ATTRIB( R16G16B16A16_SNORM, 4, short, TO_16_SNORM ) +ATTRIB( R16G16B16_SNORM, 3, short, TO_16_SNORM ) +ATTRIB( R16G16_SNORM, 2, short, TO_16_SNORM ) +ATTRIB( R16_SNORM, 1, short, TO_16_SNORM ) + +ATTRIB( R8G8B8A8_USCALED, 4, ubyte, TO_8_USCALED ) +ATTRIB( R8G8B8_USCALED, 3, ubyte, TO_8_USCALED ) +ATTRIB( R8G8_USCALED, 2, ubyte, TO_8_USCALED ) +ATTRIB( R8_USCALED, 1, ubyte, TO_8_USCALED ) + +ATTRIB( R8G8B8A8_SSCALED, 4, char, TO_8_SSCALED ) +ATTRIB( R8G8B8_SSCALED, 3, char, TO_8_SSCALED ) +ATTRIB( R8G8_SSCALED, 2, char, TO_8_SSCALED ) +ATTRIB( R8_SSCALED, 1, char, TO_8_SSCALED ) + +ATTRIB( R8G8B8A8_UNORM, 4, ubyte, TO_8_UNORM ) +ATTRIB( R8G8B8_UNORM, 3, ubyte, TO_8_UNORM ) +ATTRIB( R8G8_UNORM, 2, ubyte, TO_8_UNORM ) +ATTRIB( R8_UNORM, 1, ubyte, TO_8_UNORM ) + +ATTRIB( R8G8B8A8_SNORM, 4, char, TO_8_SNORM ) +ATTRIB( R8G8B8_SNORM, 3, char, TO_8_SNORM ) +ATTRIB( R8G8_SNORM, 2, char, TO_8_SNORM ) +ATTRIB( R8_SNORM, 1, char, TO_8_SNORM ) + +static void +emit_A8R8G8B8_UNORM( const float *attrib, void *ptr) +{ + ubyte *out = (ubyte *)ptr; + out[0] = TO_8_UNORM(attrib[3]); + out[1] = TO_8_UNORM(attrib[0]); + out[2] = TO_8_UNORM(attrib[1]); + out[3] = TO_8_UNORM(attrib[2]); +} + +static void +emit_B8G8R8A8_UNORM( const float *attrib, void *ptr) +{ + ubyte *out = (ubyte *)ptr; + out[2] = TO_8_UNORM(attrib[0]); + out[1] = TO_8_UNORM(attrib[1]); + out[0] = TO_8_UNORM(attrib[2]); + out[3] = TO_8_UNORM(attrib[3]); +} + +static void +emit_NULL( const float *attrib, void *ptr ) +{ + /* do nothing is the only sensible option */ +} + +static emit_func get_emit_func( enum pipe_format format ) +{ + switch (format) { + case PIPE_FORMAT_R64_FLOAT: + return &emit_R64_FLOAT; + case PIPE_FORMAT_R64G64_FLOAT: + return &emit_R64G64_FLOAT; + case PIPE_FORMAT_R64G64B64_FLOAT: + return &emit_R64G64B64_FLOAT; + case PIPE_FORMAT_R64G64B64A64_FLOAT: + return &emit_R64G64B64A64_FLOAT; + + case PIPE_FORMAT_R32_FLOAT: + return &emit_R32_FLOAT; + case PIPE_FORMAT_R32G32_FLOAT: + return &emit_R32G32_FLOAT; + case PIPE_FORMAT_R32G32B32_FLOAT: + return &emit_R32G32B32_FLOAT; + case PIPE_FORMAT_R32G32B32A32_FLOAT: + return &emit_R32G32B32A32_FLOAT; + + case PIPE_FORMAT_R32_UNORM: + return &emit_R32_UNORM; + case PIPE_FORMAT_R32G32_UNORM: + return &emit_R32G32_UNORM; + case PIPE_FORMAT_R32G32B32_UNORM: + return &emit_R32G32B32_UNORM; + case PIPE_FORMAT_R32G32B32A32_UNORM: + return &emit_R32G32B32A32_UNORM; + + case PIPE_FORMAT_R32_USCALED: + return &emit_R32_USCALED; + case PIPE_FORMAT_R32G32_USCALED: + return &emit_R32G32_USCALED; + case PIPE_FORMAT_R32G32B32_USCALED: + return &emit_R32G32B32_USCALED; + case PIPE_FORMAT_R32G32B32A32_USCALED: + return &emit_R32G32B32A32_USCALED; + + case PIPE_FORMAT_R32_SNORM: + return &emit_R32_SNORM; + case PIPE_FORMAT_R32G32_SNORM: + return &emit_R32G32_SNORM; + case PIPE_FORMAT_R32G32B32_SNORM: + return &emit_R32G32B32_SNORM; + case PIPE_FORMAT_R32G32B32A32_SNORM: + return &emit_R32G32B32A32_SNORM; + + case PIPE_FORMAT_R32_SSCALED: + return &emit_R32_SSCALED; + case PIPE_FORMAT_R32G32_SSCALED: + return &emit_R32G32_SSCALED; + case PIPE_FORMAT_R32G32B32_SSCALED: + return &emit_R32G32B32_SSCALED; + case PIPE_FORMAT_R32G32B32A32_SSCALED: + return &emit_R32G32B32A32_SSCALED; + + case PIPE_FORMAT_R16_UNORM: + return &emit_R16_UNORM; + case PIPE_FORMAT_R16G16_UNORM: + return &emit_R16G16_UNORM; + case PIPE_FORMAT_R16G16B16_UNORM: + return &emit_R16G16B16_UNORM; + case PIPE_FORMAT_R16G16B16A16_UNORM: + return &emit_R16G16B16A16_UNORM; + + case PIPE_FORMAT_R16_USCALED: + return &emit_R16_USCALED; + case PIPE_FORMAT_R16G16_USCALED: + return &emit_R16G16_USCALED; + case PIPE_FORMAT_R16G16B16_USCALED: + return &emit_R16G16B16_USCALED; + case PIPE_FORMAT_R16G16B16A16_USCALED: + return &emit_R16G16B16A16_USCALED; + + case PIPE_FORMAT_R16_SNORM: + return &emit_R16_SNORM; + case PIPE_FORMAT_R16G16_SNORM: + return &emit_R16G16_SNORM; + case PIPE_FORMAT_R16G16B16_SNORM: + return &emit_R16G16B16_SNORM; + case PIPE_FORMAT_R16G16B16A16_SNORM: + return &emit_R16G16B16A16_SNORM; + + case PIPE_FORMAT_R16_SSCALED: + return &emit_R16_SSCALED; + case PIPE_FORMAT_R16G16_SSCALED: + return &emit_R16G16_SSCALED; + case PIPE_FORMAT_R16G16B16_SSCALED: + return &emit_R16G16B16_SSCALED; + case PIPE_FORMAT_R16G16B16A16_SSCALED: + return &emit_R16G16B16A16_SSCALED; + + case PIPE_FORMAT_R8_UNORM: + return &emit_R8_UNORM; + case PIPE_FORMAT_R8G8_UNORM: + return &emit_R8G8_UNORM; + case PIPE_FORMAT_R8G8B8_UNORM: + return &emit_R8G8B8_UNORM; + case PIPE_FORMAT_R8G8B8A8_UNORM: + return &emit_R8G8B8A8_UNORM; + + case PIPE_FORMAT_R8_USCALED: + return &emit_R8_USCALED; + case PIPE_FORMAT_R8G8_USCALED: + return &emit_R8G8_USCALED; + case PIPE_FORMAT_R8G8B8_USCALED: + return &emit_R8G8B8_USCALED; + case PIPE_FORMAT_R8G8B8A8_USCALED: + return &emit_R8G8B8A8_USCALED; + + case PIPE_FORMAT_R8_SNORM: + return &emit_R8_SNORM; + case PIPE_FORMAT_R8G8_SNORM: + return &emit_R8G8_SNORM; + case PIPE_FORMAT_R8G8B8_SNORM: + return &emit_R8G8B8_SNORM; + case PIPE_FORMAT_R8G8B8A8_SNORM: + return &emit_R8G8B8A8_SNORM; + + case PIPE_FORMAT_R8_SSCALED: + return &emit_R8_SSCALED; + case PIPE_FORMAT_R8G8_SSCALED: + return &emit_R8G8_SSCALED; + case PIPE_FORMAT_R8G8B8_SSCALED: + return &emit_R8G8B8_SSCALED; + case PIPE_FORMAT_R8G8B8A8_SSCALED: + return &emit_R8G8B8A8_SSCALED; + + case PIPE_FORMAT_B8G8R8A8_UNORM: + return &emit_B8G8R8A8_UNORM; + + case PIPE_FORMAT_A8R8G8B8_UNORM: + return &emit_A8R8G8B8_UNORM; + + default: + assert(0); + return &emit_NULL; + } +} + +static ALWAYS_INLINE void PIPE_CDECL generic_run_one( struct translate_generic *tg, + unsigned elt, + unsigned instance_id, + void *vert ) +{ + unsigned nr_attrs = tg->nr_attrib; + unsigned attr; + + for (attr = 0; attr < nr_attrs; attr++) { + float data[4]; + uint8_t *dst = (uint8_t *)vert + tg->attrib[attr].output_offset; + + if (tg->attrib[attr].type == TRANSLATE_ELEMENT_NORMAL) { + const uint8_t *src; + unsigned index; + int copy_size; + + if (tg->attrib[attr].instance_divisor) { + index = instance_id / tg->attrib[attr].instance_divisor; + } + else { + index = elt; + } + + /* clamp to void going out of bounds */ + index = MIN2(index, tg->attrib[attr].max_index); + + src = tg->attrib[attr].input_ptr + + tg->attrib[attr].input_stride * index; + + copy_size = tg->attrib[attr].copy_size; + if(likely(copy_size >= 0)) + memcpy(dst, src, copy_size); + else + { + tg->attrib[attr].fetch( data, src, 0, 0 ); + + if (0) + debug_printf("Fetch linear attr %d from %p stride %d index %d: " + " %f, %f, %f, %f \n", + attr, + tg->attrib[attr].input_ptr, + tg->attrib[attr].input_stride, + index, + data[0], data[1],data[2], data[3]); + + tg->attrib[attr].emit( data, dst ); + } + } else { + if(likely(tg->attrib[attr].copy_size >= 0)) + memcpy(data, &instance_id, 4); + else + { + data[0] = (float)instance_id; + tg->attrib[attr].emit( data, dst ); + } + } + } +} + +/** + * Fetch vertex attributes for 'count' vertices. + */ +static void PIPE_CDECL generic_run_elts( struct translate *translate, + const unsigned *elts, + unsigned count, + unsigned instance_id, + void *output_buffer ) +{ + struct translate_generic *tg = translate_generic(translate); + char *vert = output_buffer; + unsigned i; + + for (i = 0; i < count; i++) { + generic_run_one(tg, *elts++, instance_id, vert); + vert += tg->translate.key.output_stride; + } +} + +static void PIPE_CDECL generic_run_elts16( struct translate *translate, + const uint16_t *elts, + unsigned count, + unsigned instance_id, + void *output_buffer ) +{ + struct translate_generic *tg = translate_generic(translate); + char *vert = output_buffer; + unsigned i; + + for (i = 0; i < count; i++) { + generic_run_one(tg, *elts++, instance_id, vert); + vert += tg->translate.key.output_stride; + } +} + +static void PIPE_CDECL generic_run_elts8( struct translate *translate, + const uint8_t *elts, + unsigned count, + unsigned instance_id, + void *output_buffer ) +{ + struct translate_generic *tg = translate_generic(translate); + char *vert = output_buffer; + unsigned i; + + for (i = 0; i < count; i++) { + generic_run_one(tg, *elts++, instance_id, vert); + vert += tg->translate.key.output_stride; + } +} + +static void PIPE_CDECL generic_run( struct translate *translate, + unsigned start, + unsigned count, + unsigned instance_id, + void *output_buffer ) +{ + struct translate_generic *tg = translate_generic(translate); + char *vert = output_buffer; + unsigned i; + + for (i = 0; i < count; i++) { + generic_run_one(tg, start + i, instance_id, vert); + vert += tg->translate.key.output_stride; + } +} + + + +static void generic_set_buffer( struct translate *translate, + unsigned buf, + const void *ptr, + unsigned stride, + unsigned max_index ) +{ + struct translate_generic *tg = translate_generic(translate); + unsigned i; + + for (i = 0; i < tg->nr_attrib; i++) { + if (tg->attrib[i].buffer == buf) { + tg->attrib[i].input_ptr = ((const uint8_t *)ptr + + tg->attrib[i].input_offset); + tg->attrib[i].input_stride = stride; + tg->attrib[i].max_index = max_index; + } + } +} + + +static void generic_release( struct translate *translate ) +{ + /* Refcount? + */ + FREE(translate); +} + +struct translate *translate_generic_create( const struct translate_key *key ) +{ + struct translate_generic *tg = CALLOC_STRUCT(translate_generic); + unsigned i; + + if (tg == NULL) + return NULL; + + tg->translate.key = *key; + tg->translate.release = generic_release; + tg->translate.set_buffer = generic_set_buffer; + tg->translate.run_elts = generic_run_elts; + tg->translate.run_elts16 = generic_run_elts16; + tg->translate.run_elts8 = generic_run_elts8; + tg->translate.run = generic_run; + + for (i = 0; i < key->nr_elements; i++) { + const struct util_format_description *format_desc = + util_format_description(key->element[i].input_format); + + assert(format_desc); + assert(format_desc->fetch_rgba_float); + + tg->attrib[i].type = key->element[i].type; + + tg->attrib[i].fetch = format_desc->fetch_rgba_float; + tg->attrib[i].buffer = key->element[i].input_buffer; + tg->attrib[i].input_offset = key->element[i].input_offset; + tg->attrib[i].instance_divisor = key->element[i].instance_divisor; + + tg->attrib[i].output_offset = key->element[i].output_offset; + + tg->attrib[i].copy_size = -1; + if (tg->attrib[i].type == TRANSLATE_ELEMENT_INSTANCE_ID) + { + if(key->element[i].output_format == PIPE_FORMAT_R32_USCALED + || key->element[i].output_format == PIPE_FORMAT_R32_SSCALED) + tg->attrib[i].copy_size = 4; + } + else + { + if(key->element[i].input_format == key->element[i].output_format + && format_desc->block.width == 1 + && format_desc->block.height == 1 + && !(format_desc->block.bits & 7)) + tg->attrib[i].copy_size = format_desc->block.bits >> 3; + } + + if(tg->attrib[i].copy_size < 0) + tg->attrib[i].emit = get_emit_func(key->element[i].output_format); + else + tg->attrib[i].emit = NULL; + } + + tg->nr_attrib = key->nr_elements; + + + return &tg->translate; +} + +boolean translate_generic_is_output_format_supported(enum pipe_format format) +{ + switch(format) + { + case PIPE_FORMAT_R64G64B64A64_FLOAT: return TRUE; + case PIPE_FORMAT_R64G64B64_FLOAT: return TRUE; + case PIPE_FORMAT_R64G64_FLOAT: return TRUE; + case PIPE_FORMAT_R64_FLOAT: return TRUE; + + case PIPE_FORMAT_R32G32B32A32_FLOAT: return TRUE; + case PIPE_FORMAT_R32G32B32_FLOAT: return TRUE; + case PIPE_FORMAT_R32G32_FLOAT: return TRUE; + case PIPE_FORMAT_R32_FLOAT: return TRUE; + + case PIPE_FORMAT_R32G32B32A32_USCALED: return TRUE; + case PIPE_FORMAT_R32G32B32_USCALED: return TRUE; + case PIPE_FORMAT_R32G32_USCALED: return TRUE; + case PIPE_FORMAT_R32_USCALED: return TRUE; + + case PIPE_FORMAT_R32G32B32A32_SSCALED: return TRUE; + case PIPE_FORMAT_R32G32B32_SSCALED: return TRUE; + case PIPE_FORMAT_R32G32_SSCALED: return TRUE; + case PIPE_FORMAT_R32_SSCALED: return TRUE; + + case PIPE_FORMAT_R32G32B32A32_UNORM: return TRUE; + case PIPE_FORMAT_R32G32B32_UNORM: return TRUE; + case PIPE_FORMAT_R32G32_UNORM: return TRUE; + case PIPE_FORMAT_R32_UNORM: return TRUE; + + case PIPE_FORMAT_R32G32B32A32_SNORM: return TRUE; + case PIPE_FORMAT_R32G32B32_SNORM: return TRUE; + case PIPE_FORMAT_R32G32_SNORM: return TRUE; + case PIPE_FORMAT_R32_SNORM: return TRUE; + + case PIPE_FORMAT_R16G16B16A16_USCALED: return TRUE; + case PIPE_FORMAT_R16G16B16_USCALED: return TRUE; + case PIPE_FORMAT_R16G16_USCALED: return TRUE; + case PIPE_FORMAT_R16_USCALED: return TRUE; + + case PIPE_FORMAT_R16G16B16A16_SSCALED: return TRUE; + case PIPE_FORMAT_R16G16B16_SSCALED: return TRUE; + case PIPE_FORMAT_R16G16_SSCALED: return TRUE; + case PIPE_FORMAT_R16_SSCALED: return TRUE; + + case PIPE_FORMAT_R16G16B16A16_UNORM: return TRUE; + case PIPE_FORMAT_R16G16B16_UNORM: return TRUE; + case PIPE_FORMAT_R16G16_UNORM: return TRUE; + case PIPE_FORMAT_R16_UNORM: return TRUE; + + case PIPE_FORMAT_R16G16B16A16_SNORM: return TRUE; + case PIPE_FORMAT_R16G16B16_SNORM: return TRUE; + case PIPE_FORMAT_R16G16_SNORM: return TRUE; + case PIPE_FORMAT_R16_SNORM: return TRUE; + + case PIPE_FORMAT_R8G8B8A8_USCALED: return TRUE; + case PIPE_FORMAT_R8G8B8_USCALED: return TRUE; + case PIPE_FORMAT_R8G8_USCALED: return TRUE; + case PIPE_FORMAT_R8_USCALED: return TRUE; + + case PIPE_FORMAT_R8G8B8A8_SSCALED: return TRUE; + case PIPE_FORMAT_R8G8B8_SSCALED: return TRUE; + case PIPE_FORMAT_R8G8_SSCALED: return TRUE; + case PIPE_FORMAT_R8_SSCALED: return TRUE; + + case PIPE_FORMAT_R8G8B8A8_UNORM: return TRUE; + case PIPE_FORMAT_R8G8B8_UNORM: return TRUE; + case PIPE_FORMAT_R8G8_UNORM: return TRUE; + case PIPE_FORMAT_R8_UNORM: return TRUE; + + case PIPE_FORMAT_R8G8B8A8_SNORM: return TRUE; + case PIPE_FORMAT_R8G8B8_SNORM: return TRUE; + case PIPE_FORMAT_R8G8_SNORM: return TRUE; + case PIPE_FORMAT_R8_SNORM: return TRUE; + + case PIPE_FORMAT_A8R8G8B8_UNORM: return TRUE; + case PIPE_FORMAT_B8G8R8A8_UNORM: return TRUE; + default: return FALSE; + } +} diff --git a/src/gallium/auxiliary/translate/translate_sse.c b/src/gallium/auxiliary/translate/translate_sse.c new file mode 100644 index 0000000..ef7f4be --- /dev/null +++ b/src/gallium/auxiliary/translate/translate_sse.c @@ -0,0 +1,1532 @@ +/* + * Copyright 2003 Tungsten Graphics, 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 + * 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 + * TUNGSTEN GRAPHICS 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. + * + * Authors: + * Keith Whitwell + */ + + +#include "pipe/p_config.h" +#include "pipe/p_compiler.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_format.h" + +#include "translate.h" + + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) + +#include "rtasm/rtasm_cpu.h" +#include "rtasm/rtasm_x86sse.h" + + +#define X 0 +#define Y 1 +#define Z 2 +#define W 3 + + +struct translate_buffer { + const void *base_ptr; + uintptr_t stride; + unsigned max_index; +}; + +struct translate_buffer_varient { + unsigned buffer_index; + unsigned instance_divisor; + void *ptr; /* updated either per vertex or per instance */ +}; + + +#define ELEMENT_BUFFER_INSTANCE_ID 1001 + +#define NUM_CONSTS 7 + +enum +{ + CONST_IDENTITY, + CONST_INV_127, + CONST_INV_255, + CONST_INV_32767, + CONST_INV_65535, + CONST_INV_2147483647, + CONST_255 +}; + +#define C(v) {(float)(v), (float)(v), (float)(v), (float)(v)} +static float consts[NUM_CONSTS][4] = { + {0, 0, 0, 1}, + C(1.0 / 127.0), + C(1.0 / 255.0), + C(1.0 / 32767.0), + C(1.0 / 65535.0), + C(1.0 / 2147483647.0), + C(255.0) +}; +#undef C + +struct translate_sse { + struct translate translate; + + struct x86_function linear_func; + struct x86_function elt_func; + struct x86_function elt16_func; + struct x86_function elt8_func; + struct x86_function *func; + + PIPE_ALIGN_VAR(16) float consts[NUM_CONSTS][4]; + int8_t reg_to_const[16]; + int8_t const_to_reg[NUM_CONSTS]; + + struct translate_buffer buffer[PIPE_MAX_ATTRIBS]; + unsigned nr_buffers; + + /* Multiple buffer varients can map to a single buffer. */ + struct translate_buffer_varient buffer_varient[PIPE_MAX_ATTRIBS]; + unsigned nr_buffer_varients; + + /* Multiple elements can map to a single buffer varient. */ + unsigned element_to_buffer_varient[PIPE_MAX_ATTRIBS]; + + boolean use_instancing; + unsigned instance_id; + + /* these are actually known values, but putting them in a struct + * like this is helpful to keep them in sync across the file. + */ + struct x86_reg tmp_EAX; + struct x86_reg tmp2_EDX; + struct x86_reg src_ECX; + struct x86_reg idx_ESI; /* either start+i or &elt[i] */ + struct x86_reg machine_EDI; + struct x86_reg outbuf_EBX; + struct x86_reg count_EBP; /* decrements to zero */ +}; + +static int get_offset( const void *a, const void *b ) +{ + return (const char *)b - (const char *)a; +} + +static struct x86_reg get_const( struct translate_sse *p, unsigned id) +{ + struct x86_reg reg; + unsigned i; + + if(p->const_to_reg[id] >= 0) + return x86_make_reg(file_XMM, p->const_to_reg[id]); + + for(i = 2; i < 8; ++i) + { + if(p->reg_to_const[i] < 0) + break; + } + + /* TODO: be smarter here */ + if(i == 8) + --i; + + reg = x86_make_reg(file_XMM, i); + + if(p->reg_to_const[i] >= 0) + p->const_to_reg[p->reg_to_const[i]] = -1; + + p->reg_to_const[i] = id; + p->const_to_reg[id] = i; + + /* TODO: this should happen outside the loop, if possible */ + sse_movaps(p->func, reg, + x86_make_disp(p->machine_EDI, + get_offset(p, &p->consts[id][0]))); + + return reg; +} + +/* load the data in a SSE2 register, padding with zeros */ +static boolean emit_load_sse2( struct translate_sse *p, + struct x86_reg data, + struct x86_reg src, + unsigned size) +{ + struct x86_reg tmpXMM = x86_make_reg(file_XMM, 1); + struct x86_reg tmp = p->tmp_EAX; + switch(size) + { + case 1: + x86_movzx8(p->func, tmp, src); + sse2_movd(p->func, data, tmp); + break; + case 2: + x86_movzx16(p->func, tmp, src); + sse2_movd(p->func, data, tmp); + break; + case 3: + x86_movzx8(p->func, tmp, x86_make_disp(src, 2)); + x86_shl_imm(p->func, tmp, 16); + x86_mov16(p->func, tmp, src); + sse2_movd(p->func, data, tmp); + break; + case 4: + sse2_movd(p->func, data, src); + break; + case 6: + sse2_movd(p->func, data, src); + x86_movzx16(p->func, tmp, x86_make_disp(src, 4)); + sse2_movd(p->func, tmpXMM, tmp); + sse2_punpckldq(p->func, data, tmpXMM); + break; + case 8: + sse2_movq(p->func, data, src); + break; + case 12: + sse2_movq(p->func, data, src); + sse2_movd(p->func, tmpXMM, x86_make_disp(src, 8)); + sse2_punpcklqdq(p->func, data, tmpXMM); + break; + case 16: + sse2_movdqu(p->func, data, src); + break; + default: + return FALSE; + } + return TRUE; +} + +/* this value can be passed for the out_chans argument */ +#define CHANNELS_0001 5 + +/* this function will load #chans float values, and will + * pad the register with zeroes at least up to out_chans. + * + * If out_chans is set to CHANNELS_0001, then the fourth + * value will be padded with 1. Only pass this value if + * chans < 4 or results are undefined. + */ +static void emit_load_float32( struct translate_sse *p, + struct x86_reg data, + struct x86_reg arg0, + unsigned out_chans, + unsigned chans) +{ + switch(chans) + { + case 1: + /* a 0 0 0 + * a 0 0 1 + */ + sse_movss(p->func, data, arg0); + if(out_chans == CHANNELS_0001) + sse_orps(p->func, data, get_const(p, CONST_IDENTITY) ); + break; + case 2: + /* 0 0 0 1 + * a b 0 1 + */ + if(out_chans == CHANNELS_0001) + sse_shufps(p->func, data, get_const(p, CONST_IDENTITY), SHUF(X, Y, Z, W) ); + else if(out_chans > 2) + sse_movlhps(p->func, data, get_const(p, CONST_IDENTITY) ); + sse_movlps(p->func, data, arg0); + break; + case 3: + /* Have to jump through some hoops: + * + * c 0 0 0 + * c 0 0 1 if out_chans == CHANNELS_0001 + * 0 0 c 0/1 + * a b c 0/1 + */ + sse_movss(p->func, data, x86_make_disp(arg0, 8)); + if(out_chans == CHANNELS_0001) + sse_shufps(p->func, data, get_const(p, CONST_IDENTITY), SHUF(X,Y,Z,W) ); + sse_shufps(p->func, data, data, SHUF(Y,Z,X,W) ); + sse_movlps(p->func, data, arg0); + break; + case 4: + sse_movups(p->func, data, arg0); + break; + } +} + +/* this function behaves like emit_load_float32, but loads + 64-bit floating point numbers, converting them to 32-bit + ones */ +static void emit_load_float64to32( struct translate_sse *p, + struct x86_reg data, + struct x86_reg arg0, + unsigned out_chans, + unsigned chans) +{ + struct x86_reg tmpXMM = x86_make_reg(file_XMM, 1); + switch(chans) + { + case 1: + sse2_movsd(p->func, data, arg0); + if(out_chans > 1) + sse2_cvtpd2ps(p->func, data, data); + else + sse2_cvtsd2ss(p->func, data, data); + if(out_chans == CHANNELS_0001) + sse_shufps(p->func, data, get_const(p, CONST_IDENTITY), SHUF(X, Y, Z, W) ); + break; + case 2: + sse2_movupd(p->func, data, arg0); + sse2_cvtpd2ps(p->func, data, data); + if(out_chans == CHANNELS_0001) + sse_shufps(p->func, data, get_const(p, CONST_IDENTITY), SHUF(X, Y, Z, W) ); + else if(out_chans > 2) + sse_movlhps(p->func, data, get_const(p, CONST_IDENTITY) ); + break; + case 3: + sse2_movupd(p->func, data, arg0); + sse2_cvtpd2ps(p->func, data, data); + sse2_movsd(p->func, tmpXMM, x86_make_disp(arg0, 16)); + if(out_chans > 3) + sse2_cvtpd2ps(p->func, tmpXMM, tmpXMM); + else + sse2_cvtsd2ss(p->func, tmpXMM, tmpXMM); + sse_movlhps(p->func, data, tmpXMM); + if(out_chans == CHANNELS_0001) + sse_orps(p->func, data, get_const(p, CONST_IDENTITY) ); + break; + case 4: + sse2_movupd(p->func, data, arg0); + sse2_cvtpd2ps(p->func, data, data); + sse2_movupd(p->func, tmpXMM, x86_make_disp(arg0, 16)); + sse2_cvtpd2ps(p->func, tmpXMM, tmpXMM); + sse_movlhps(p->func, data, tmpXMM); + break; + } +} + +static void emit_mov64(struct translate_sse *p, struct x86_reg dst_gpr, struct x86_reg dst_xmm, struct x86_reg src_gpr, struct x86_reg src_xmm) +{ + if(x86_target(p->func) != X86_32) + x64_mov64(p->func, dst_gpr, src_gpr); + else + { + /* TODO: when/on which CPUs is SSE2 actually better than SSE? */ + if(x86_target_caps(p->func) & X86_SSE2) + sse2_movq(p->func, dst_xmm, src_xmm); + else + sse_movlps(p->func, dst_xmm, src_xmm); + } +} + +static void emit_load64(struct translate_sse *p, struct x86_reg dst_gpr, struct x86_reg dst_xmm, struct x86_reg src) +{ + emit_mov64(p, dst_gpr, dst_xmm, src, src); +} + +static void emit_store64(struct translate_sse *p, struct x86_reg dst, struct x86_reg src_gpr, struct x86_reg src_xmm) +{ + emit_mov64(p, dst, dst, src_gpr, src_xmm); +} + +static void emit_mov128(struct translate_sse *p, struct x86_reg dst, struct x86_reg src) +{ + if(x86_target_caps(p->func) & X86_SSE2) + sse2_movdqu(p->func, dst, src); + else + sse_movups(p->func, dst, src); +} + +/* TODO: this uses unaligned accesses liberally, which is great on Nehalem, + * but may or may not be good on older processors + * TODO: may perhaps want to use non-temporal stores here if possible + */ +static void emit_memcpy(struct translate_sse *p, struct x86_reg dst, struct x86_reg src, unsigned size) +{ + struct x86_reg dataXMM = x86_make_reg(file_XMM, 0); + struct x86_reg dataXMM2 = x86_make_reg(file_XMM, 1); + struct x86_reg dataGPR = p->tmp_EAX; + struct x86_reg dataGPR2 = p->tmp2_EDX; + + if(size < 8) + { + switch (size) + { + case 1: + x86_mov8(p->func, dataGPR, src); + x86_mov8(p->func, dst, dataGPR); + break; + case 2: + x86_mov16(p->func, dataGPR, src); + x86_mov16(p->func, dst, dataGPR); + break; + case 3: + x86_mov16(p->func, dataGPR, src); + x86_mov8(p->func, dataGPR2, x86_make_disp(src, 2)); + x86_mov16(p->func, dst, dataGPR); + x86_mov8(p->func, x86_make_disp(dst, 2), dataGPR2); + break; + case 4: + x86_mov(p->func, dataGPR, src); + x86_mov(p->func, dst, dataGPR); + break; + case 6: + x86_mov(p->func, dataGPR, src); + x86_mov16(p->func, dataGPR2, x86_make_disp(src, 4)); + x86_mov(p->func, dst, dataGPR); + x86_mov16(p->func, x86_make_disp(dst, 4), dataGPR2); + break; + } + } + else if(!(x86_target_caps(p->func) & X86_SSE)) + { + unsigned i = 0; + assert((size & 3) == 0); + for(i = 0; i < size; i += 4) + { + x86_mov(p->func, dataGPR, x86_make_disp(src, i)); + x86_mov(p->func, x86_make_disp(dst, i), dataGPR); + } + } + else + { + switch(size) + { + case 8: + emit_load64(p, dataGPR, dataXMM, src); + emit_store64(p, dst, dataGPR, dataXMM); + break; + case 12: + emit_load64(p, dataGPR2, dataXMM, src); + x86_mov(p->func, dataGPR, x86_make_disp(src, 8)); + emit_store64(p, dst, dataGPR2, dataXMM); + x86_mov(p->func, x86_make_disp(dst, 8), dataGPR); + break; + case 16: + emit_mov128(p, dataXMM, src); + emit_mov128(p, dst, dataXMM); + break; + case 24: + emit_mov128(p, dataXMM, src); + emit_load64(p, dataGPR, dataXMM2, x86_make_disp(src, 16)); + emit_mov128(p, dst, dataXMM); + emit_store64(p, x86_make_disp(dst, 16), dataGPR, dataXMM2); + break; + case 32: + emit_mov128(p, dataXMM, src); + emit_mov128(p, dataXMM2, x86_make_disp(src, 16)); + emit_mov128(p, dst, dataXMM); + emit_mov128(p, x86_make_disp(dst, 16), dataXMM2); + break; + default: + assert(0); + } + } +} + +static boolean translate_attr_convert( struct translate_sse *p, + const struct translate_element *a, + struct x86_reg src, + struct x86_reg dst) + +{ + const struct util_format_description* input_desc = util_format_description(a->input_format); + const struct util_format_description* output_desc = util_format_description(a->output_format); + unsigned i; + boolean id_swizzle = TRUE; + unsigned swizzle[4] = {UTIL_FORMAT_SWIZZLE_NONE, UTIL_FORMAT_SWIZZLE_NONE, UTIL_FORMAT_SWIZZLE_NONE, UTIL_FORMAT_SWIZZLE_NONE}; + unsigned needed_chans = 0; + unsigned imms[2] = {0, 0x3f800000}; + + if(a->output_format == PIPE_FORMAT_NONE || a->input_format == PIPE_FORMAT_NONE) + return FALSE; + + if(input_desc->channel[0].size & 7) + return FALSE; + + if(input_desc->colorspace != output_desc->colorspace) + return FALSE; + + for(i = 1; i < input_desc->nr_channels; ++i) + { + if(memcmp(&input_desc->channel[i], &input_desc->channel[0], sizeof(input_desc->channel[0]))) + return FALSE; + } + + for(i = 1; i < output_desc->nr_channels; ++i) + { + if(memcmp(&output_desc->channel[i], &output_desc->channel[0], sizeof(output_desc->channel[0]))) + return FALSE; + } + + for(i = 0; i < output_desc->nr_channels; ++i) + { + if(output_desc->swizzle[i] < 4) + swizzle[output_desc->swizzle[i]] = input_desc->swizzle[i]; + } + + if((x86_target_caps(p->func) & X86_SSE) && (0 + || a->output_format == PIPE_FORMAT_R32_FLOAT + || a->output_format == PIPE_FORMAT_R32G32_FLOAT + || a->output_format == PIPE_FORMAT_R32G32B32_FLOAT + || a->output_format == PIPE_FORMAT_R32G32B32A32_FLOAT)) + { + struct x86_reg dataXMM = x86_make_reg(file_XMM, 0); + + for(i = 0; i < output_desc->nr_channels; ++i) + { + if(swizzle[i] == UTIL_FORMAT_SWIZZLE_0 && i >= input_desc->nr_channels) + swizzle[i] = i; + } + + for(i = 0; i < output_desc->nr_channels; ++i) + { + if(swizzle[i] < 4) + needed_chans = MAX2(needed_chans, swizzle[i] + 1); + if(swizzle[i] < UTIL_FORMAT_SWIZZLE_0 && swizzle[i] != i) + id_swizzle = FALSE; + } + + if(needed_chans > 0) + { + switch(input_desc->channel[0].type) + { + case UTIL_FORMAT_TYPE_UNSIGNED: + if(!(x86_target_caps(p->func) & X86_SSE2)) + return FALSE; + emit_load_sse2(p, dataXMM, src, input_desc->channel[0].size * input_desc->nr_channels >> 3); + + /* TODO: add support for SSE4.1 pmovzx */ + switch(input_desc->channel[0].size) + { + case 8: + /* TODO: this may be inefficient due to get_identity() being used both as a float and integer register */ + sse2_punpcklbw(p->func, dataXMM, get_const(p, CONST_IDENTITY)); + sse2_punpcklbw(p->func, dataXMM, get_const(p, CONST_IDENTITY)); + break; + case 16: + sse2_punpcklwd(p->func, dataXMM, get_const(p, CONST_IDENTITY)); + break; + case 32: /* we lose precision here */ + sse2_psrld_imm(p->func, dataXMM, 1); + break; + default: + return FALSE; + } + sse2_cvtdq2ps(p->func, dataXMM, dataXMM); + if(input_desc->channel[0].normalized) + { + struct x86_reg factor; + switch(input_desc->channel[0].size) + { + case 8: + factor = get_const(p, CONST_INV_255); + break; + case 16: + factor = get_const(p, CONST_INV_65535); + break; + case 32: + factor = get_const(p, CONST_INV_2147483647); + break; + default: + assert(0); + factor.disp = 0; + factor.file = 0; + factor.idx = 0; + factor.mod = 0; + break; + } + sse_mulps(p->func, dataXMM, factor); + } + else if(input_desc->channel[0].size == 32) + sse_addps(p->func, dataXMM, dataXMM); /* compensate for the bit we threw away to fit u32 into s32 */ + break; + case UTIL_FORMAT_TYPE_SIGNED: + if(!(x86_target_caps(p->func) & X86_SSE2)) + return FALSE; + emit_load_sse2(p, dataXMM, src, input_desc->channel[0].size * input_desc->nr_channels >> 3); + + /* TODO: add support for SSE4.1 pmovsx */ + switch(input_desc->channel[0].size) + { + case 8: + sse2_punpcklbw(p->func, dataXMM, dataXMM); + sse2_punpcklbw(p->func, dataXMM, dataXMM); + sse2_psrad_imm(p->func, dataXMM, 24); + break; + case 16: + sse2_punpcklwd(p->func, dataXMM, dataXMM); + sse2_psrad_imm(p->func, dataXMM, 16); + break; + case 32: /* we lose precision here */ + break; + default: + return FALSE; + } + sse2_cvtdq2ps(p->func, dataXMM, dataXMM); + if(input_desc->channel[0].normalized) + { + struct x86_reg factor; + switch(input_desc->channel[0].size) + { + case 8: + factor = get_const(p, CONST_INV_127); + break; + case 16: + factor = get_const(p, CONST_INV_32767); + break; + case 32: + factor = get_const(p, CONST_INV_2147483647); + break; + default: + assert(0); + factor.disp = 0; + factor.file = 0; + factor.idx = 0; + factor.mod = 0; + break; + } + sse_mulps(p->func, dataXMM, factor); + } + break; + + break; + case UTIL_FORMAT_TYPE_FLOAT: + if(input_desc->channel[0].size != 32 && input_desc->channel[0].size != 64) + return FALSE; + if(swizzle[3] == UTIL_FORMAT_SWIZZLE_1 && input_desc->nr_channels <= 3) + { + swizzle[3] = UTIL_FORMAT_SWIZZLE_W; + needed_chans = CHANNELS_0001; + } + switch(input_desc->channel[0].size) + { + case 32: + emit_load_float32(p, dataXMM, src, needed_chans, input_desc->nr_channels); + break; + case 64: /* we lose precision here */ + if(!(x86_target_caps(p->func) & X86_SSE2)) + return FALSE; + emit_load_float64to32(p, dataXMM, src, needed_chans, input_desc->nr_channels); + break; + default: + return FALSE; + } + break; + default: + return FALSE; + } + + if(!id_swizzle) + sse_shufps(p->func, dataXMM, dataXMM, SHUF(swizzle[0], swizzle[1], swizzle[2], swizzle[3]) ); + } + + if(output_desc->nr_channels >= 4 + && swizzle[0] < UTIL_FORMAT_SWIZZLE_0 + && swizzle[1] < UTIL_FORMAT_SWIZZLE_0 + && swizzle[2] < UTIL_FORMAT_SWIZZLE_0 + && swizzle[3] < UTIL_FORMAT_SWIZZLE_0 + ) + sse_movups(p->func, dst, dataXMM); + else + { + if(output_desc->nr_channels >= 2 + && swizzle[0] < UTIL_FORMAT_SWIZZLE_0 + && swizzle[1] < UTIL_FORMAT_SWIZZLE_0) + sse_movlps(p->func, dst, dataXMM); + else + { + if(swizzle[0] < UTIL_FORMAT_SWIZZLE_0) + sse_movss(p->func, dst, dataXMM); + else + x86_mov_imm(p->func, dst, imms[swizzle[0] - UTIL_FORMAT_SWIZZLE_0]); + + if(output_desc->nr_channels >= 2) + { + if(swizzle[1] < UTIL_FORMAT_SWIZZLE_0) + { + sse_shufps(p->func, dataXMM, dataXMM, SHUF(1, 1, 2, 3)); + sse_movss(p->func, x86_make_disp(dst, 4), dataXMM); + } + else + x86_mov_imm(p->func, x86_make_disp(dst, 4), imms[swizzle[1] - UTIL_FORMAT_SWIZZLE_0]); + } + } + + if(output_desc->nr_channels >= 3) + { + if(output_desc->nr_channels >= 4 + && swizzle[2] < UTIL_FORMAT_SWIZZLE_0 + && swizzle[3] < UTIL_FORMAT_SWIZZLE_0) + sse_movhps(p->func, x86_make_disp(dst, 8), dataXMM); + else + { + if(swizzle[2] < UTIL_FORMAT_SWIZZLE_0) + { + sse_shufps(p->func, dataXMM, dataXMM, SHUF(2, 2, 2, 3)); + sse_movss(p->func, x86_make_disp(dst, 8), dataXMM); + } + else + x86_mov_imm(p->func, x86_make_disp(dst, 8), imms[swizzle[2] - UTIL_FORMAT_SWIZZLE_0]); + + if(output_desc->nr_channels >= 4) + { + if(swizzle[3] < UTIL_FORMAT_SWIZZLE_0) + { + sse_shufps(p->func, dataXMM, dataXMM, SHUF(3, 3, 3, 3)); + sse_movss(p->func, x86_make_disp(dst, 12), dataXMM); + } + else + x86_mov_imm(p->func, x86_make_disp(dst, 12), imms[swizzle[3] - UTIL_FORMAT_SWIZZLE_0]); + } + } + } + } + return TRUE; + } + else if((x86_target_caps(p->func) & X86_SSE2) && input_desc->channel[0].size == 8 && output_desc->channel[0].size == 16 + && output_desc->channel[0].normalized == input_desc->channel[0].normalized + && (0 + || (input_desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED && output_desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED) + || (input_desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED && output_desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) + || (input_desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED && output_desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) + )) + { + struct x86_reg dataXMM = x86_make_reg(file_XMM, 0); + struct x86_reg tmpXMM = x86_make_reg(file_XMM, 1); + struct x86_reg tmp = p->tmp_EAX; + unsigned imms[2] = {0, 1}; + + for(i = 0; i < output_desc->nr_channels; ++i) + { + if(swizzle[i] == UTIL_FORMAT_SWIZZLE_0 && i >= input_desc->nr_channels) + swizzle[i] = i; + } + + for(i = 0; i < output_desc->nr_channels; ++i) + { + if(swizzle[i] < 4) + needed_chans = MAX2(needed_chans, swizzle[i] + 1); + if(swizzle[i] < UTIL_FORMAT_SWIZZLE_0 && swizzle[i] != i) + id_swizzle = FALSE; + } + + if(needed_chans > 0) + { + emit_load_sse2(p, dataXMM, src, input_desc->channel[0].size * input_desc->nr_channels >> 3); + + switch(input_desc->channel[0].type) + { + case UTIL_FORMAT_TYPE_UNSIGNED: + if(input_desc->channel[0].normalized) + { + sse2_punpcklbw(p->func, dataXMM, dataXMM); + if(output_desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) + sse2_psrlw_imm(p->func, dataXMM, 1); + } + else + sse2_punpcklbw(p->func, dataXMM, get_const(p, CONST_IDENTITY)); + break; + case UTIL_FORMAT_TYPE_SIGNED: + if(input_desc->channel[0].normalized) + { + sse2_movq(p->func, tmpXMM, get_const(p, CONST_IDENTITY)); + sse2_punpcklbw(p->func, tmpXMM, dataXMM); + sse2_psllw_imm(p->func, dataXMM, 9); + sse2_psrlw_imm(p->func, dataXMM, 8); + sse2_por(p->func, tmpXMM, dataXMM); + sse2_psrlw_imm(p->func, dataXMM, 7); + sse2_por(p->func, tmpXMM, dataXMM); + { + struct x86_reg t = dataXMM; + dataXMM = tmpXMM; + tmpXMM = t; + } + } + else + { + sse2_punpcklbw(p->func, dataXMM, dataXMM); + sse2_psraw_imm(p->func, dataXMM, 8); + } + break; + default: + assert(0); + } + + if(output_desc->channel[0].normalized) + imms[1] = (output_desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED) ? 0xffff : 0x7ffff; + + if(!id_swizzle) + sse2_pshuflw(p->func, dataXMM, dataXMM, (swizzle[0] & 3) | ((swizzle[1] & 3) << 2) | ((swizzle[2] & 3) << 4) | ((swizzle[3] & 3) << 6)); + } + + if(output_desc->nr_channels >= 4 + && swizzle[0] < UTIL_FORMAT_SWIZZLE_0 + && swizzle[1] < UTIL_FORMAT_SWIZZLE_0 + && swizzle[2] < UTIL_FORMAT_SWIZZLE_0 + && swizzle[3] < UTIL_FORMAT_SWIZZLE_0 + ) + sse2_movq(p->func, dst, dataXMM); + else + { + if(swizzle[0] < UTIL_FORMAT_SWIZZLE_0) + { + if(output_desc->nr_channels >= 2 && swizzle[1] < UTIL_FORMAT_SWIZZLE_0) + sse2_movd(p->func, dst, dataXMM); + else + { + sse2_movd(p->func, tmp, dataXMM); + x86_mov16(p->func, dst, tmp); + if(output_desc->nr_channels >= 2) + x86_mov16_imm(p->func, x86_make_disp(dst, 2), imms[swizzle[1] - UTIL_FORMAT_SWIZZLE_0]); + } + } + else + { + if(output_desc->nr_channels >= 2 && swizzle[1] >= UTIL_FORMAT_SWIZZLE_0) + x86_mov_imm(p->func, dst, (imms[swizzle[1] - UTIL_FORMAT_SWIZZLE_0] << 16) | imms[swizzle[0] - UTIL_FORMAT_SWIZZLE_0]); + else + { + x86_mov16_imm(p->func, dst, imms[swizzle[0] - UTIL_FORMAT_SWIZZLE_0]); + if(output_desc->nr_channels >= 2) + { + sse2_movd(p->func, tmp, dataXMM); + x86_shr_imm(p->func, tmp, 16); + x86_mov16(p->func, x86_make_disp(dst, 2), tmp); + } + } + } + + if(output_desc->nr_channels >= 3) + { + if(swizzle[2] < UTIL_FORMAT_SWIZZLE_0) + { + if(output_desc->nr_channels >= 4 && swizzle[3] < UTIL_FORMAT_SWIZZLE_0) + { + sse2_psrlq_imm(p->func, dataXMM, 32); + sse2_movd(p->func, x86_make_disp(dst, 4), dataXMM); + } + else + { + sse2_psrlq_imm(p->func, dataXMM, 32); + sse2_movd(p->func, tmp, dataXMM); + x86_mov16(p->func, x86_make_disp(dst, 4), tmp); + if(output_desc->nr_channels >= 4) + { + x86_mov16_imm(p->func, x86_make_disp(dst, 6), imms[swizzle[3] - UTIL_FORMAT_SWIZZLE_0]); + } + } + } + else + { + if(output_desc->nr_channels >= 4 && swizzle[3] >= UTIL_FORMAT_SWIZZLE_0) + x86_mov_imm(p->func, x86_make_disp(dst, 4), (imms[swizzle[3] - UTIL_FORMAT_SWIZZLE_0] << 16) | imms[swizzle[2] - UTIL_FORMAT_SWIZZLE_0]); + else + { + x86_mov16_imm(p->func, x86_make_disp(dst, 4), imms[swizzle[2] - UTIL_FORMAT_SWIZZLE_0]); + + if(output_desc->nr_channels >= 4) + { + sse2_psrlq_imm(p->func, dataXMM, 48); + sse2_movd(p->func, tmp, dataXMM); + x86_mov16(p->func, x86_make_disp(dst, 6), tmp); + } + } + } + } + } + return TRUE; + } + else if(!memcmp(&output_desc->channel[0], &input_desc->channel[0], sizeof(output_desc->channel[0]))) + { + struct x86_reg tmp = p->tmp_EAX; + unsigned i; + if(input_desc->channel[0].size == 8 && input_desc->nr_channels == 4 && output_desc->nr_channels == 4 + && swizzle[0] == UTIL_FORMAT_SWIZZLE_W + && swizzle[1] == UTIL_FORMAT_SWIZZLE_Z + && swizzle[2] == UTIL_FORMAT_SWIZZLE_Y + && swizzle[3] == UTIL_FORMAT_SWIZZLE_X) + { + /* TODO: support movbe */ + x86_mov(p->func, tmp, src); + x86_bswap(p->func, tmp); + x86_mov(p->func, dst, tmp); + return TRUE; + } + + for(i = 0; i < output_desc->nr_channels; ++i) + { + switch(output_desc->channel[0].size) + { + case 8: + if(swizzle[i] >= UTIL_FORMAT_SWIZZLE_0) + { + unsigned v = 0; + if(swizzle[i] == UTIL_FORMAT_SWIZZLE_1) + { + switch(output_desc->channel[0].type) + { + case UTIL_FORMAT_TYPE_UNSIGNED: + v = output_desc->channel[0].normalized ? 0xff : 1; + break; + case UTIL_FORMAT_TYPE_SIGNED: + v = output_desc->channel[0].normalized ? 0x7f : 1; + break; + default: + return FALSE; + } + } + x86_mov8_imm(p->func, x86_make_disp(dst, i * 1), v); + } + else + { + x86_mov8(p->func, tmp, x86_make_disp(src, swizzle[i] * 1)); + x86_mov8(p->func, x86_make_disp(dst, i * 1), tmp); + } + break; + case 16: + if(swizzle[i] >= UTIL_FORMAT_SWIZZLE_0) + { + unsigned v = 0; + if(swizzle[i] == UTIL_FORMAT_SWIZZLE_1) + { + switch(output_desc->channel[1].type) + { + case UTIL_FORMAT_TYPE_UNSIGNED: + v = output_desc->channel[1].normalized ? 0xffff : 1; + break; + case UTIL_FORMAT_TYPE_SIGNED: + v = output_desc->channel[1].normalized ? 0x7fff : 1; + break; + case UTIL_FORMAT_TYPE_FLOAT: + v = 0x3c00; + break; + default: + return FALSE; + } + } + x86_mov16_imm(p->func, x86_make_disp(dst, i * 2), v); + } + else if(swizzle[i] == UTIL_FORMAT_SWIZZLE_0) + x86_mov16_imm(p->func, x86_make_disp(dst, i * 2), 0); + else + { + x86_mov16(p->func, tmp, x86_make_disp(src, swizzle[i] * 2)); + x86_mov16(p->func, x86_make_disp(dst, i * 2), tmp); + } + break; + case 32: + if(swizzle[i] >= UTIL_FORMAT_SWIZZLE_0) + { + unsigned v = 0; + if(swizzle[i] == UTIL_FORMAT_SWIZZLE_1) + { + switch(output_desc->channel[1].type) + { + case UTIL_FORMAT_TYPE_UNSIGNED: + v = output_desc->channel[1].normalized ? 0xffffffff : 1; + break; + case UTIL_FORMAT_TYPE_SIGNED: + v = output_desc->channel[1].normalized ? 0x7fffffff : 1; + break; + case UTIL_FORMAT_TYPE_FLOAT: + v = 0x3f800000; + break; + default: + return FALSE; + } + } + x86_mov_imm(p->func, x86_make_disp(dst, i * 4), v); + } + else + { + x86_mov(p->func, tmp, x86_make_disp(src, swizzle[i] * 4)); + x86_mov(p->func, x86_make_disp(dst, i * 4), tmp); + } + break; + case 64: + if(swizzle[i] >= UTIL_FORMAT_SWIZZLE_0) + { + unsigned l = 0; + unsigned h = 0; + if(swizzle[i] == UTIL_FORMAT_SWIZZLE_1) + { + switch(output_desc->channel[1].type) + { + case UTIL_FORMAT_TYPE_UNSIGNED: + h = output_desc->channel[1].normalized ? 0xffffffff : 0; + l = output_desc->channel[1].normalized ? 0xffffffff : 1; + break; + case UTIL_FORMAT_TYPE_SIGNED: + h = output_desc->channel[1].normalized ? 0x7fffffff : 0; + l = output_desc->channel[1].normalized ? 0xffffffff : 1; + break; + case UTIL_FORMAT_TYPE_FLOAT: + h = 0x3ff00000; + l = 0; + break; + default: + return FALSE; + } + } + x86_mov_imm(p->func, x86_make_disp(dst, i * 8), l); + x86_mov_imm(p->func, x86_make_disp(dst, i * 8 + 4), h); + } + else + { + if(x86_target_caps(p->func) & X86_SSE) + { + struct x86_reg tmpXMM = x86_make_reg(file_XMM, 0); + emit_load64(p, tmp, tmpXMM, x86_make_disp(src, swizzle[i] * 8)); + emit_store64(p, x86_make_disp(dst, i * 8), tmp, tmpXMM); + } + else + { + x86_mov(p->func, tmp, x86_make_disp(src, swizzle[i] * 8)); + x86_mov(p->func, x86_make_disp(dst, i * 8), tmp); + x86_mov(p->func, tmp, x86_make_disp(src, swizzle[i] * 8 + 4)); + x86_mov(p->func, x86_make_disp(dst, i * 8 + 4), tmp); + } + } + break; + default: + return FALSE; + } + } + return TRUE; + } + /* special case for draw's EMIT_4UB (RGBA) and EMIT_4UB_BGRA */ + else if((x86_target_caps(p->func) & X86_SSE2) && + a->input_format == PIPE_FORMAT_R32G32B32A32_FLOAT && (0 + || a->output_format == PIPE_FORMAT_B8G8R8A8_UNORM + || a->output_format == PIPE_FORMAT_R8G8B8A8_UNORM + )) + { + struct x86_reg dataXMM = x86_make_reg(file_XMM, 0); + + /* load */ + sse_movups(p->func, dataXMM, src); + + if (a->output_format == PIPE_FORMAT_B8G8R8A8_UNORM) + sse_shufps(p->func, dataXMM, dataXMM, SHUF(2,1,0,3)); + + /* scale by 255.0 */ + sse_mulps(p->func, dataXMM, get_const(p, CONST_255)); + + /* pack and emit */ + sse2_cvtps2dq(p->func, dataXMM, dataXMM); + sse2_packssdw(p->func, dataXMM, dataXMM); + sse2_packuswb(p->func, dataXMM, dataXMM); + sse2_movd(p->func, dst, dataXMM); + + return TRUE; + } + + return FALSE; +} + +static boolean translate_attr( struct translate_sse *p, + const struct translate_element *a, + struct x86_reg src, + struct x86_reg dst) +{ + if(a->input_format == a->output_format) + { + emit_memcpy(p, dst, src, util_format_get_stride(a->input_format, 1)); + return TRUE; + } + + return translate_attr_convert(p, a, src, dst); +} + +static boolean init_inputs( struct translate_sse *p, + unsigned index_size ) +{ + unsigned i; + struct x86_reg instance_id = x86_make_disp(p->machine_EDI, + get_offset(p, &p->instance_id)); + + for (i = 0; i < p->nr_buffer_varients; i++) { + struct translate_buffer_varient *varient = &p->buffer_varient[i]; + struct translate_buffer *buffer = &p->buffer[varient->buffer_index]; + + if (!index_size || varient->instance_divisor) { + struct x86_reg buf_stride = x86_make_disp(p->machine_EDI, + get_offset(p, &buffer->stride)); + struct x86_reg buf_ptr = x86_make_disp(p->machine_EDI, + get_offset(p, &varient->ptr)); + struct x86_reg buf_base_ptr = x86_make_disp(p->machine_EDI, + get_offset(p, &buffer->base_ptr)); + struct x86_reg elt = p->idx_ESI; + struct x86_reg tmp_EAX = p->tmp_EAX; + + /* Calculate pointer to first attrib: + * base_ptr + stride * index, where index depends on instance divisor + */ + if (varient->instance_divisor) { + /* Our index is instance ID divided by instance divisor. + */ + x86_mov(p->func, tmp_EAX, instance_id); + + if (varient->instance_divisor != 1) { + struct x86_reg tmp_EDX = p->tmp2_EDX; + struct x86_reg tmp_ECX = p->src_ECX; + + /* TODO: Add x86_shr() to rtasm and use it whenever + * instance divisor is power of two. + */ + + x86_xor(p->func, tmp_EDX, tmp_EDX); + x86_mov_reg_imm(p->func, tmp_ECX, varient->instance_divisor); + x86_div(p->func, tmp_ECX); /* EAX = EDX:EAX / ECX */ + } + } else { + x86_mov(p->func, tmp_EAX, elt); + } + + /* + * TODO: Respect translate_buffer::max_index. + */ + + x86_imul(p->func, tmp_EAX, buf_stride); + x64_rexw(p->func); + x86_add(p->func, tmp_EAX, buf_base_ptr); + + + /* In the linear case, keep the buffer pointer instead of the + * index number. + */ + if (!index_size && p->nr_buffer_varients == 1) + { + x64_rexw(p->func); + x86_mov(p->func, elt, tmp_EAX); + } + else + { + x64_rexw(p->func); + x86_mov(p->func, buf_ptr, tmp_EAX); + } + } + } + + return TRUE; +} + + +static struct x86_reg get_buffer_ptr( struct translate_sse *p, + unsigned index_size, + unsigned var_idx, + struct x86_reg elt ) +{ + if (var_idx == ELEMENT_BUFFER_INSTANCE_ID) { + return x86_make_disp(p->machine_EDI, + get_offset(p, &p->instance_id)); + } + if (!index_size && p->nr_buffer_varients == 1) { + return p->idx_ESI; + } + else if (!index_size || p->buffer_varient[var_idx].instance_divisor) { + struct x86_reg ptr = p->src_ECX; + struct x86_reg buf_ptr = + x86_make_disp(p->machine_EDI, + get_offset(p, &p->buffer_varient[var_idx].ptr)); + + x64_rexw(p->func); + x86_mov(p->func, ptr, buf_ptr); + return ptr; + } + else { + struct x86_reg ptr = p->src_ECX; + const struct translate_buffer_varient *varient = &p->buffer_varient[var_idx]; + + struct x86_reg buf_stride = + x86_make_disp(p->machine_EDI, + get_offset(p, &p->buffer[varient->buffer_index].stride)); + + struct x86_reg buf_base_ptr = + x86_make_disp(p->machine_EDI, + get_offset(p, &p->buffer[varient->buffer_index].base_ptr)); + + + + /* Calculate pointer to current attrib: + */ + switch(index_size) + { + case 1: + x86_movzx8(p->func, ptr, elt); + break; + case 2: + x86_movzx16(p->func, ptr, elt); + break; + case 4: + x86_mov(p->func, ptr, elt); + break; + } + x86_imul(p->func, ptr, buf_stride); + x64_rexw(p->func); + x86_add(p->func, ptr, buf_base_ptr); + return ptr; + } +} + + + +static boolean incr_inputs( struct translate_sse *p, + unsigned index_size ) +{ + if (!index_size && p->nr_buffer_varients == 1) { + struct x86_reg stride = x86_make_disp(p->machine_EDI, + get_offset(p, &p->buffer[0].stride)); + + if (p->buffer_varient[0].instance_divisor == 0) { + x64_rexw(p->func); + x86_add(p->func, p->idx_ESI, stride); + sse_prefetchnta(p->func, x86_make_disp(p->idx_ESI, 192)); + } + } + else if (!index_size) { + unsigned i; + + /* Is this worthwhile?? + */ + for (i = 0; i < p->nr_buffer_varients; i++) { + struct translate_buffer_varient *varient = &p->buffer_varient[i]; + struct x86_reg buf_ptr = x86_make_disp(p->machine_EDI, + get_offset(p, &varient->ptr)); + struct x86_reg buf_stride = x86_make_disp(p->machine_EDI, + get_offset(p, &p->buffer[varient->buffer_index].stride)); + + if (varient->instance_divisor == 0) { + x86_mov(p->func, p->tmp_EAX, buf_stride); + x64_rexw(p->func); + x86_add(p->func, p->tmp_EAX, buf_ptr); + if (i == 0) sse_prefetchnta(p->func, x86_make_disp(p->tmp_EAX, 192)); + x64_rexw(p->func); + x86_mov(p->func, buf_ptr, p->tmp_EAX); + } + } + } + else { + x64_rexw(p->func); + x86_lea(p->func, p->idx_ESI, x86_make_disp(p->idx_ESI, index_size)); + } + + return TRUE; +} + + +/* Build run( struct translate *machine, + * unsigned start, + * unsigned count, + * void *output_buffer ) + * or + * run_elts( struct translate *machine, + * unsigned *elts, + * unsigned count, + * void *output_buffer ) + * + * Lots of hardcoding + * + * EAX -- pointer to current output vertex + * ECX -- pointer to current attribute + * + */ +static boolean build_vertex_emit( struct translate_sse *p, + struct x86_function *func, + unsigned index_size ) +{ + int fixup, label; + unsigned j; + + memset(p->reg_to_const, 0xff, sizeof(p->reg_to_const)); + memset(p->const_to_reg, 0xff, sizeof(p->const_to_reg)); + + p->tmp_EAX = x86_make_reg(file_REG32, reg_AX); + p->idx_ESI = x86_make_reg(file_REG32, reg_SI); + p->outbuf_EBX = x86_make_reg(file_REG32, reg_BX); + p->machine_EDI = x86_make_reg(file_REG32, reg_DI); + p->count_EBP = x86_make_reg(file_REG32, reg_BP); + p->tmp2_EDX = x86_make_reg(file_REG32, reg_DX); + p->src_ECX = x86_make_reg(file_REG32, reg_CX); + + p->func = func; + + x86_init_func(p->func); + + if(x86_target(p->func) == X86_64_WIN64_ABI) + { + /* the ABI guarantees a 16-byte aligned 32-byte "shadow space" above the return address */ + sse2_movdqa(p->func, x86_make_disp(x86_make_reg(file_REG32, reg_SP), 8), x86_make_reg(file_XMM, 6)); + sse2_movdqa(p->func, x86_make_disp(x86_make_reg(file_REG32, reg_SP), 24), x86_make_reg(file_XMM, 7)); + } + + x86_push(p->func, p->outbuf_EBX); + x86_push(p->func, p->count_EBP); + +/* on non-Win64 x86-64, these are already in the right registers */ + if(x86_target(p->func) != X86_64_STD_ABI) + { + x86_push(p->func, p->machine_EDI); + x86_push(p->func, p->idx_ESI); + + x86_mov(p->func, p->machine_EDI, x86_fn_arg(p->func, 1)); + x86_mov(p->func, p->idx_ESI, x86_fn_arg(p->func, 2)); + } + + x86_mov(p->func, p->count_EBP, x86_fn_arg(p->func, 3)); + + if(x86_target(p->func) != X86_32) + x64_mov64(p->func, p->outbuf_EBX, x86_fn_arg(p->func, 5)); + else + x86_mov(p->func, p->outbuf_EBX, x86_fn_arg(p->func, 5)); + + /* Load instance ID. + */ + if (p->use_instancing) { + x86_mov(p->func, + p->tmp_EAX, + x86_fn_arg(p->func, 4)); + x86_mov(p->func, + x86_make_disp(p->machine_EDI, get_offset(p, &p->instance_id)), + p->tmp_EAX); + } + + /* Get vertex count, compare to zero + */ + x86_xor(p->func, p->tmp_EAX, p->tmp_EAX); + x86_cmp(p->func, p->count_EBP, p->tmp_EAX); + fixup = x86_jcc_forward(p->func, cc_E); + + /* always load, needed or not: + */ + init_inputs(p, index_size); + + /* Note address for loop jump + */ + label = x86_get_label(p->func); + { + struct x86_reg elt = !index_size ? p->idx_ESI : x86_deref(p->idx_ESI); + int last_varient = -1; + struct x86_reg vb; + + for (j = 0; j < p->translate.key.nr_elements; j++) { + const struct translate_element *a = &p->translate.key.element[j]; + unsigned varient = p->element_to_buffer_varient[j]; + + /* Figure out source pointer address: + */ + if (varient != last_varient) { + last_varient = varient; + vb = get_buffer_ptr(p, index_size, varient, elt); + } + + if (!translate_attr( p, a, + x86_make_disp(vb, a->input_offset), + x86_make_disp(p->outbuf_EBX, a->output_offset))) + return FALSE; + } + + /* Next output vertex: + */ + x64_rexw(p->func); + x86_lea(p->func, + p->outbuf_EBX, + x86_make_disp(p->outbuf_EBX, + p->translate.key.output_stride)); + + /* Incr index + */ + incr_inputs( p, index_size ); + } + + /* decr count, loop if not zero + */ + x86_dec(p->func, p->count_EBP); + x86_jcc(p->func, cc_NZ, label); + + /* Exit mmx state? + */ + if (p->func->need_emms) + mmx_emms(p->func); + + /* Land forward jump here: + */ + x86_fixup_fwd_jump(p->func, fixup); + + /* Pop regs and return + */ + + if(x86_target(p->func) != X86_64_STD_ABI) + { + x86_pop(p->func, p->idx_ESI); + x86_pop(p->func, p->machine_EDI); + } + + x86_pop(p->func, p->count_EBP); + x86_pop(p->func, p->outbuf_EBX); + + if(x86_target(p->func) == X86_64_WIN64_ABI) + { + sse2_movdqa(p->func, x86_make_reg(file_XMM, 6), x86_make_disp(x86_make_reg(file_REG32, reg_SP), 8)); + sse2_movdqa(p->func, x86_make_reg(file_XMM, 7), x86_make_disp(x86_make_reg(file_REG32, reg_SP), 24)); + } + x86_ret(p->func); + + return TRUE; +} + + + + + + + +static void translate_sse_set_buffer( struct translate *translate, + unsigned buf, + const void *ptr, + unsigned stride, + unsigned max_index ) +{ + struct translate_sse *p = (struct translate_sse *)translate; + + if (buf < p->nr_buffers) { + p->buffer[buf].base_ptr = (char *)ptr; + p->buffer[buf].stride = stride; + p->buffer[buf].max_index = max_index; + } + + if (0) debug_printf("%s %d/%d: %p %d\n", + __FUNCTION__, buf, + p->nr_buffers, + ptr, stride); +} + + +static void translate_sse_release( struct translate *translate ) +{ + struct translate_sse *p = (struct translate_sse *)translate; + + x86_release_func( &p->linear_func ); + x86_release_func( &p->elt_func ); + + os_free_aligned(p); +} + + +struct translate *translate_sse2_create( const struct translate_key *key ) +{ + struct translate_sse *p = NULL; + unsigned i; + + /* this is misnamed, it actually refers to whether rtasm is enabled or not */ + if (!rtasm_cpu_has_sse()) + goto fail; + + p = os_malloc_aligned(sizeof(struct translate_sse), 16); + if (p == NULL) + goto fail; + memset(p, 0, sizeof(*p)); + memcpy(p->consts, consts, sizeof(consts)); + + p->translate.key = *key; + p->translate.release = translate_sse_release; + p->translate.set_buffer = translate_sse_set_buffer; + + for (i = 0; i < key->nr_elements; i++) { + if (key->element[i].type == TRANSLATE_ELEMENT_NORMAL) { + unsigned j; + + p->nr_buffers = MAX2(p->nr_buffers, key->element[i].input_buffer + 1); + + if (key->element[i].instance_divisor) { + p->use_instancing = TRUE; + } + + /* + * Map vertex element to vertex buffer varient. + */ + for (j = 0; j < p->nr_buffer_varients; j++) { + if (p->buffer_varient[j].buffer_index == key->element[i].input_buffer && + p->buffer_varient[j].instance_divisor == key->element[i].instance_divisor) { + break; + } + } + if (j == p->nr_buffer_varients) { + p->buffer_varient[j].buffer_index = key->element[i].input_buffer; + p->buffer_varient[j].instance_divisor = key->element[i].instance_divisor; + p->nr_buffer_varients++; + } + p->element_to_buffer_varient[i] = j; + } else { + assert(key->element[i].type == TRANSLATE_ELEMENT_INSTANCE_ID); + + p->element_to_buffer_varient[i] = ELEMENT_BUFFER_INSTANCE_ID; + } + } + + if (0) debug_printf("nr_buffers: %d\n", p->nr_buffers); + + if (!build_vertex_emit(p, &p->linear_func, 0)) + goto fail; + + if (!build_vertex_emit(p, &p->elt_func, 4)) + goto fail; + + if (!build_vertex_emit(p, &p->elt16_func, 2)) + goto fail; + + if (!build_vertex_emit(p, &p->elt8_func, 1)) + goto fail; + + p->translate.run = (run_func) x86_get_func(&p->linear_func); + if (p->translate.run == NULL) + goto fail; + + p->translate.run_elts = (run_elts_func) x86_get_func(&p->elt_func); + if (p->translate.run_elts == NULL) + goto fail; + + p->translate.run_elts16 = (run_elts16_func) x86_get_func(&p->elt16_func); + if (p->translate.run_elts16 == NULL) + goto fail; + + p->translate.run_elts8 = (run_elts8_func) x86_get_func(&p->elt8_func); + if (p->translate.run_elts8 == NULL) + goto fail; + + return &p->translate; + + fail: + if (p) + translate_sse_release( &p->translate ); + + return NULL; +} + + + +#else + +struct translate *translate_sse2_create( const struct translate_key *key ) +{ + return NULL; +} + +#endif diff --git a/src/gallium/auxiliary/util/u_atomic.h b/src/gallium/auxiliary/util/u_atomic.h new file mode 100644 index 0000000..8434491 --- /dev/null +++ b/src/gallium/auxiliary/util/u_atomic.h @@ -0,0 +1,352 @@ +/** + * Many similar implementations exist. See for example libwsbm + * or the linux kernel include/atomic.h + * + * No copyright claimed on this file. + * + */ + +#ifndef U_ATOMIC_H +#define U_ATOMIC_H + +#include "pipe/p_compiler.h" +#include "pipe/p_defines.h" + +/* Favor OS-provided implementations. + * + * Where no OS-provided implementation is available, fall back to + * locally coded assembly, compiler intrinsic or ultimately a + * mutex-based implementation. + */ +#if (defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || \ + defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)) +#define PIPE_ATOMIC_OS_UNLOCKED +#elif defined(PIPE_OS_SOLARIS) +#define PIPE_ATOMIC_OS_SOLARIS +#elif defined(PIPE_CC_MSVC) +#define PIPE_ATOMIC_MSVC_INTRINSIC +#elif (defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)) +#define PIPE_ATOMIC_ASM_MSVC_X86 +#elif (defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)) +#define PIPE_ATOMIC_ASM_GCC_X86 +#elif (defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86_64)) +#define PIPE_ATOMIC_ASM_GCC_X86_64 +#elif defined(PIPE_CC_GCC) && (PIPE_CC_GCC_VERSION >= 401) +#define PIPE_ATOMIC_GCC_INTRINSIC +#else +#error "Unsupported platform" +#endif + + +#if defined(PIPE_ATOMIC_ASM_GCC_X86_64) +#define PIPE_ATOMIC "GCC x86_64 assembly" + +#ifdef __cplusplus +extern "C" { +#endif + +#define p_atomic_set(_v, _i) (*(_v) = (_i)) +#define p_atomic_read(_v) (*(_v)) + +static INLINE boolean +p_atomic_dec_zero(int32_t *v) +{ + unsigned char c; + + __asm__ __volatile__("lock; decl %0; sete %1":"+m"(*v), "=qm"(c) + ::"memory"); + + return c != 0; +} + +static INLINE void +p_atomic_inc(int32_t *v) +{ + __asm__ __volatile__("lock; incl %0":"+m"(*v)); +} + +static INLINE void +p_atomic_dec(int32_t *v) +{ + __asm__ __volatile__("lock; decl %0":"+m"(*v)); +} + +static INLINE int32_t +p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new) +{ + return __sync_val_compare_and_swap(v, old, _new); +} + +#ifdef __cplusplus +} +#endif + +#endif /* PIPE_ATOMIC_ASM_GCC_X86_64 */ + + +#if defined(PIPE_ATOMIC_ASM_GCC_X86) + +#define PIPE_ATOMIC "GCC x86 assembly" + +#ifdef __cplusplus +extern "C" { +#endif + +#define p_atomic_set(_v, _i) (*(_v) = (_i)) +#define p_atomic_read(_v) (*(_v)) + +static INLINE boolean +p_atomic_dec_zero(int32_t *v) +{ + unsigned char c; + + __asm__ __volatile__("lock; decl %0; sete %1":"+m"(*v), "=qm"(c) + ::"memory"); + + return c != 0; +} + +static INLINE void +p_atomic_inc(int32_t *v) +{ + __asm__ __volatile__("lock; incl %0":"+m"(*v)); +} + +static INLINE void +p_atomic_dec(int32_t *v) +{ + __asm__ __volatile__("lock; decl %0":"+m"(*v)); +} + +static INLINE int32_t +p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new) +{ + return __sync_val_compare_and_swap(v, old, _new); +} + +#ifdef __cplusplus +} +#endif + +#endif + + + +/* Implementation using GCC-provided synchronization intrinsics + */ +#if defined(PIPE_ATOMIC_GCC_INTRINSIC) + +#define PIPE_ATOMIC "GCC Sync Intrinsics" + +#ifdef __cplusplus +extern "C" { +#endif + +#define p_atomic_set(_v, _i) (*(_v) = (_i)) +#define p_atomic_read(_v) (*(_v)) + +static INLINE boolean +p_atomic_dec_zero(int32_t *v) +{ + return (__sync_sub_and_fetch(v, 1) == 0); +} + +static INLINE void +p_atomic_inc(int32_t *v) +{ + (void) __sync_add_and_fetch(v, 1); +} + +static INLINE void +p_atomic_dec(int32_t *v) +{ + (void) __sync_sub_and_fetch(v, 1); +} + +static INLINE int32_t +p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new) +{ + return __sync_val_compare_and_swap(v, old, _new); +} + +#ifdef __cplusplus +} +#endif + +#endif + + + +/* Unlocked version for single threaded environments, such as some + * windows kernel modules. + */ +#if defined(PIPE_ATOMIC_OS_UNLOCKED) + +#define PIPE_ATOMIC "Unlocked" + +#define p_atomic_set(_v, _i) (*(_v) = (_i)) +#define p_atomic_read(_v) (*(_v)) +#define p_atomic_dec_zero(_v) ((boolean) --(*(_v))) +#define p_atomic_inc(_v) ((void) (*(_v))++) +#define p_atomic_dec(_v) ((void) (*(_v))--) +#define p_atomic_cmpxchg(_v, old, _new) (*(_v) == old ? *(_v) = (_new) : *(_v)) + +#endif + + +/* Locally coded assembly for MSVC on x86: + */ +#if defined(PIPE_ATOMIC_ASM_MSVC_X86) + +#define PIPE_ATOMIC "MSVC x86 assembly" + +#ifdef __cplusplus +extern "C" { +#endif + +#define p_atomic_set(_v, _i) (*(_v) = (_i)) +#define p_atomic_read(_v) (*(_v)) + +static INLINE boolean +p_atomic_dec_zero(int32_t *v) +{ + unsigned char c; + + __asm { + mov eax, [v] + lock dec dword ptr [eax] + sete byte ptr [c] + } + + return c != 0; +} + +static INLINE void +p_atomic_inc(int32_t *v) +{ + __asm { + mov eax, [v] + lock inc dword ptr [eax] + } +} + +static INLINE void +p_atomic_dec(int32_t *v) +{ + __asm { + mov eax, [v] + lock dec dword ptr [eax] + } +} + +static INLINE int32_t +p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new) +{ + int32_t orig; + + __asm { + mov ecx, [v] + mov eax, [old] + mov edx, [_new] + lock cmpxchg [ecx], edx + mov [orig], eax + } + + return orig; +} + +#ifdef __cplusplus +} +#endif + +#endif + + +#if defined(PIPE_ATOMIC_MSVC_INTRINSIC) + +#define PIPE_ATOMIC "MSVC Intrinsics" + +#include + +#pragma intrinsic(_InterlockedIncrement) +#pragma intrinsic(_InterlockedDecrement) +#pragma intrinsic(_InterlockedCompareExchange) + +#ifdef __cplusplus +extern "C" { +#endif + +#define p_atomic_set(_v, _i) (*(_v) = (_i)) +#define p_atomic_read(_v) (*(_v)) + +static INLINE boolean +p_atomic_dec_zero(int32_t *v) +{ + return _InterlockedDecrement((long *)v) == 0; +} + +static INLINE void +p_atomic_inc(int32_t *v) +{ + _InterlockedIncrement((long *)v); +} + +static INLINE void +p_atomic_dec(int32_t *v) +{ + _InterlockedDecrement((long *)v); +} + +static INLINE int32_t +p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new) +{ + return _InterlockedCompareExchange((long *)v, _new, old); +} + +#ifdef __cplusplus +} +#endif + +#endif + +#if defined(PIPE_ATOMIC_OS_SOLARIS) + +#define PIPE_ATOMIC "Solaris OS atomic functions" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define p_atomic_set(_v, _i) (*(_v) = (_i)) +#define p_atomic_read(_v) (*(_v)) + +static INLINE boolean +p_atomic_dec_zero(int32_t *v) +{ + uint32_t n = atomic_dec_32_nv((uint32_t *) v); + + return n != 0; +} + +#define p_atomic_inc(_v) atomic_inc_32((uint32_t *) _v) +#define p_atomic_dec(_v) atomic_dec_32((uint32_t *) _v) + +#define p_atomic_cmpxchg(_v, _old, _new) \ + atomic_cas_32( (uint32_t *) _v, (uint32_t) _old, (uint32_t) _new) + +#ifdef __cplusplus +} +#endif + +#endif + + +#ifndef PIPE_ATOMIC +#error "No pipe_atomic implementation selected" +#endif + + + +#endif /* U_ATOMIC_H */ diff --git a/src/gallium/auxiliary/util/u_bitmask.c b/src/gallium/auxiliary/util/u_bitmask.c new file mode 100644 index 0000000..23c93a3 --- /dev/null +++ b/src/gallium/auxiliary/util/u_bitmask.c @@ -0,0 +1,328 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Generic bitmask implementation. + * + * @author Jose Fonseca + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" + +#include "util/u_memory.h" +#include "util/u_bitmask.h" + + +typedef uint32_t util_bitmask_word; + + +#define UTIL_BITMASK_INITIAL_WORDS 16 +#define UTIL_BITMASK_BITS_PER_BYTE 8 +#define UTIL_BITMASK_BITS_PER_WORD (sizeof(util_bitmask_word) * UTIL_BITMASK_BITS_PER_BYTE) + + +struct util_bitmask +{ + util_bitmask_word *words; + + /** Number of bits we can currently hold */ + unsigned size; + + /** Number of consecutive bits set at the start of the bitmask */ + unsigned filled; +}; + + +struct util_bitmask * +util_bitmask_create(void) +{ + struct util_bitmask *bm; + + bm = MALLOC_STRUCT(util_bitmask); + if(!bm) + return NULL; + + bm->words = (util_bitmask_word *)CALLOC(UTIL_BITMASK_INITIAL_WORDS, sizeof(util_bitmask_word)); + if(!bm->words) { + FREE(bm); + return NULL; + } + + bm->size = UTIL_BITMASK_INITIAL_WORDS * UTIL_BITMASK_BITS_PER_WORD; + bm->filled = 0; + + return bm; +} + + +/** + * Resize the bitmask if necessary + */ +static INLINE boolean +util_bitmask_resize(struct util_bitmask *bm, + unsigned minimum_index) +{ + unsigned minimum_size = minimum_index + 1; + unsigned new_size; + util_bitmask_word *new_words; + + /* Check integer overflow */ + if(!minimum_size) + return FALSE; + + if(bm->size >= minimum_size) + return TRUE; + + assert(bm->size % UTIL_BITMASK_BITS_PER_WORD == 0); + new_size = bm->size; + while(new_size < minimum_size) { + new_size *= 2; + /* Check integer overflow */ + if(new_size < bm->size) + return FALSE; + } + assert(new_size); + assert(new_size % UTIL_BITMASK_BITS_PER_WORD == 0); + + new_words = (util_bitmask_word *)REALLOC((void *)bm->words, + bm->size / UTIL_BITMASK_BITS_PER_BYTE, + new_size / UTIL_BITMASK_BITS_PER_BYTE); + if(!new_words) + return FALSE; + + memset(new_words + bm->size/UTIL_BITMASK_BITS_PER_WORD, + 0, + (new_size - bm->size)/UTIL_BITMASK_BITS_PER_BYTE); + + bm->size = new_size; + bm->words = new_words; + + return TRUE; +} + + +/** + * Lazily update the filled. + */ +static INLINE void +util_bitmask_filled_set(struct util_bitmask *bm, + unsigned index) +{ + assert(bm->filled <= bm->size); + assert(index < bm->size); + + if(index == bm->filled) { + ++bm->filled; + assert(bm->filled <= bm->size); + } +} + +static INLINE void +util_bitmask_filled_unset(struct util_bitmask *bm, + unsigned index) +{ + assert(bm->filled <= bm->size); + assert(index < bm->size); + + if(index < bm->filled) + bm->filled = index; +} + + +unsigned +util_bitmask_add(struct util_bitmask *bm) +{ + unsigned word; + unsigned bit; + util_bitmask_word mask; + + assert(bm); + + /* linear search for an empty index */ + word = bm->filled / UTIL_BITMASK_BITS_PER_WORD; + bit = bm->filled % UTIL_BITMASK_BITS_PER_WORD; + mask = 1 << bit; + while(word < bm->size / UTIL_BITMASK_BITS_PER_WORD) { + while(bit < UTIL_BITMASK_BITS_PER_WORD) { + if(!(bm->words[word] & mask)) + goto found; + ++bm->filled; + ++bit; + mask <<= 1; + } + ++word; + bit = 0; + mask = 1; + } +found: + + /* grow the bitmask if necessary */ + if(!util_bitmask_resize(bm, bm->filled)) + return UTIL_BITMASK_INVALID_INDEX; + + assert(!(bm->words[word] & mask)); + bm->words[word] |= mask; + + return bm->filled++; +} + + +unsigned +util_bitmask_set(struct util_bitmask *bm, + unsigned index) +{ + unsigned word; + unsigned bit; + util_bitmask_word mask; + + assert(bm); + + /* grow the bitmask if necessary */ + if(!util_bitmask_resize(bm, index)) + return UTIL_BITMASK_INVALID_INDEX; + + word = index / UTIL_BITMASK_BITS_PER_WORD; + bit = index % UTIL_BITMASK_BITS_PER_WORD; + mask = 1 << bit; + + bm->words[word] |= mask; + + util_bitmask_filled_set(bm, index); + + return index; +} + + +void +util_bitmask_clear(struct util_bitmask *bm, + unsigned index) +{ + unsigned word; + unsigned bit; + util_bitmask_word mask; + + assert(bm); + + if(index >= bm->size) + return; + + word = index / UTIL_BITMASK_BITS_PER_WORD; + bit = index % UTIL_BITMASK_BITS_PER_WORD; + mask = 1 << bit; + + bm->words[word] &= ~mask; + + util_bitmask_filled_unset(bm, index); +} + + +boolean +util_bitmask_get(struct util_bitmask *bm, + unsigned index) +{ + unsigned word = index / UTIL_BITMASK_BITS_PER_WORD; + unsigned bit = index % UTIL_BITMASK_BITS_PER_WORD; + util_bitmask_word mask = 1 << bit; + + assert(bm); + + if(index < bm->filled) { + assert(bm->words[word] & mask); + return TRUE; + } + + if(index >= bm->size) + return FALSE; + + if(bm->words[word] & mask) { + util_bitmask_filled_set(bm, index); + return TRUE; + } + else + return FALSE; +} + + +unsigned +util_bitmask_get_next_index(struct util_bitmask *bm, + unsigned index) +{ + unsigned word = index / UTIL_BITMASK_BITS_PER_WORD; + unsigned bit = index % UTIL_BITMASK_BITS_PER_WORD; + util_bitmask_word mask = 1 << bit; + + if(index < bm->filled) { + assert(bm->words[word] & mask); + return index; + } + + if(index >= bm->size) { + return UTIL_BITMASK_INVALID_INDEX; + } + + /* Do a linear search */ + while(word < bm->size / UTIL_BITMASK_BITS_PER_WORD) { + while(bit < UTIL_BITMASK_BITS_PER_WORD) { + if(bm->words[word] & mask) { + if(index == bm->filled) { + ++bm->filled; + assert(bm->filled <= bm->size); + } + return index; + } + ++index; + ++bit; + mask <<= 1; + } + ++word; + bit = 0; + mask = 1; + } + + return UTIL_BITMASK_INVALID_INDEX; +} + + +unsigned +util_bitmask_get_first_index(struct util_bitmask *bm) +{ + return util_bitmask_get_next_index(bm, 0); +} + + +void +util_bitmask_destroy(struct util_bitmask *bm) +{ + assert(bm); + + FREE(bm->words); + FREE(bm); +} + diff --git a/src/gallium/auxiliary/util/u_bitmask.h b/src/gallium/auxiliary/util/u_bitmask.h new file mode 100644 index 0000000..98b85dd --- /dev/null +++ b/src/gallium/auxiliary/util/u_bitmask.h @@ -0,0 +1,117 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Generic bitmask. + * + * @author Jose Fonseca + */ + +#ifndef U_HANDLE_BITMASK_H_ +#define U_HANDLE_BITMASK_H_ + + +#include "pipe/p_compiler.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define UTIL_BITMASK_INVALID_INDEX (~0U) + + +/** + * Abstract data type to represent arbitrary set of bits. + */ +struct util_bitmask; + + +struct util_bitmask * +util_bitmask_create(void); + + +/** + * Search a cleared bit and set it. + * + * It searches for the first cleared bit. + * + * Returns the bit index on success, or UTIL_BITMASK_INVALID_INDEX on out of + * memory growing the bitmask. + */ +unsigned +util_bitmask_add(struct util_bitmask *bm); + +/** + * Set a bit. + * + * Returns the input index on success, or UTIL_BITMASK_INVALID_INDEX on out of + * memory growing the bitmask. + */ +unsigned +util_bitmask_set(struct util_bitmask *bm, + unsigned index); + +void +util_bitmask_clear(struct util_bitmask *bm, + unsigned index); + +boolean +util_bitmask_get(struct util_bitmask *bm, + unsigned index); + + +void +util_bitmask_destroy(struct util_bitmask *bm); + + +/** + * Search for the first set bit. + * + * Returns UTIL_BITMASK_INVALID_INDEX if a set bit cannot be found. + */ +unsigned +util_bitmask_get_first_index(struct util_bitmask *bm); + + +/** + * Search for the first set bit, starting from the giving index. + * + * Returns UTIL_BITMASK_INVALID_INDEX if a set bit cannot be found. + */ +unsigned +util_bitmask_get_next_index(struct util_bitmask *bm, + unsigned index); + + +#ifdef __cplusplus +} +#endif + +#endif /* U_HANDLE_BITMASK_H_ */ diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c new file mode 100644 index 0000000..c11f7d3 --- /dev/null +++ b/src/gallium/auxiliary/util/u_blit.c @@ -0,0 +1,743 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Copy/blit pixel rect between surfaces + * + * @author Brian Paul + */ + + +#include "pipe/p_context.h" +#include "util/u_debug.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/p_state.h" + +#include "util/u_blit.h" +#include "util/u_draw_quad.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_sampler.h" +#include "util/u_simple_shaders.h" + +#include "cso_cache/cso_context.h" + + +struct blit_state +{ + struct pipe_context *pipe; + struct cso_context *cso; + + struct pipe_blend_state blend; + struct pipe_depth_stencil_alpha_state depthstencil_keep; + struct pipe_depth_stencil_alpha_state depthstencil_write; + struct pipe_rasterizer_state rasterizer; + struct pipe_sampler_state sampler; + struct pipe_viewport_state viewport; + struct pipe_clip_state clip; + struct pipe_vertex_element velem[2]; + enum pipe_texture_target internal_target; + + void *vs; + void *fs[TGSI_WRITEMASK_XYZW + 1]; + void *fs_depth; + + struct pipe_resource *vbuf; /**< quad vertices */ + unsigned vbuf_slot; + + float vertices[4][2][4]; /**< vertex/texcoords for quad */ +}; + + +/** + * Create state object for blit. + * Intended to be created once and re-used for many blit() calls. + */ +struct blit_state * +util_create_blit(struct pipe_context *pipe, struct cso_context *cso) +{ + struct blit_state *ctx; + uint i; + + ctx = CALLOC_STRUCT(blit_state); + if (!ctx) + return NULL; + + ctx->pipe = pipe; + ctx->cso = cso; + + /* disabled blending/masking */ + memset(&ctx->blend, 0, sizeof(ctx->blend)); + ctx->blend.rt[0].colormask = PIPE_MASK_RGBA; + + /* no-op depth/stencil/alpha */ + memset(&ctx->depthstencil_keep, 0, sizeof(ctx->depthstencil_keep)); + memset(&ctx->depthstencil_write, 0, sizeof(ctx->depthstencil_write)); + ctx->depthstencil_write.depth.enabled = 1; + ctx->depthstencil_write.depth.writemask = 1; + ctx->depthstencil_write.depth.func = PIPE_FUNC_ALWAYS; + + /* rasterizer */ + memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer)); + ctx->rasterizer.cull_face = PIPE_FACE_NONE; + ctx->rasterizer.gl_rasterization_rules = 1; + + /* samplers */ + memset(&ctx->sampler, 0, sizeof(ctx->sampler)); + ctx->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + ctx->sampler.min_img_filter = 0; /* set later */ + ctx->sampler.mag_img_filter = 0; /* set later */ + + /* vertex elements state */ + memset(&ctx->velem[0], 0, sizeof(ctx->velem[0]) * 2); + for (i = 0; i < 2; i++) { + ctx->velem[i].src_offset = i * 4 * sizeof(float); + ctx->velem[i].instance_divisor = 0; + ctx->velem[i].vertex_buffer_index = 0; + ctx->velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + } + + /* vertex shader - still required to provide the linkage between + * fragment shader input semantics and vertex_element/buffers. + */ + { + const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, + TGSI_SEMANTIC_GENERIC }; + const uint semantic_indexes[] = { 0, 0 }; + ctx->vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names, + semantic_indexes); + } + + /* fragment shader */ + ctx->fs[TGSI_WRITEMASK_XYZW] = + util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D, + TGSI_INTERPOLATE_LINEAR); + ctx->vbuf = NULL; + + /* init vertex data that doesn't change */ + for (i = 0; i < 4; i++) { + ctx->vertices[i][0][3] = 1.0f; /* w */ + ctx->vertices[i][1][2] = 0.0f; /* r */ + ctx->vertices[i][1][3] = 1.0f; /* q */ + } + + if(pipe->screen->get_param(pipe->screen, PIPE_CAP_NPOT_TEXTURES)) + ctx->internal_target = PIPE_TEXTURE_2D; + else + ctx->internal_target = PIPE_TEXTURE_RECT; + + return ctx; +} + + +/** + * Destroy a blit context + */ +void +util_destroy_blit(struct blit_state *ctx) +{ + struct pipe_context *pipe = ctx->pipe; + unsigned i; + + pipe->delete_vs_state(pipe, ctx->vs); + + for (i = 0; i < Elements(ctx->fs); i++) + if (ctx->fs[i]) + pipe->delete_fs_state(pipe, ctx->fs[i]); + + if (ctx->fs_depth) + pipe->delete_fs_state(pipe, ctx->fs_depth); + + pipe_resource_reference(&ctx->vbuf, NULL); + + FREE(ctx); +} + + +/** + * Get offset of next free slot in vertex buffer for quad vertices. + */ +static unsigned +get_next_slot( struct blit_state *ctx ) +{ + const unsigned max_slots = 4096 / sizeof ctx->vertices; + + if (ctx->vbuf_slot >= max_slots) + util_blit_flush( ctx ); + + if (!ctx->vbuf) { + ctx->vbuf = pipe_buffer_create(ctx->pipe->screen, + PIPE_BIND_VERTEX_BUFFER, + max_slots * sizeof ctx->vertices); + } + + return ctx->vbuf_slot++ * sizeof ctx->vertices; +} + + + + +/** + * Setup vertex data for the textured quad we'll draw. + * Note: y=0=top + */ +static unsigned +setup_vertex_data_tex(struct blit_state *ctx, + float x0, float y0, float x1, float y1, + float s0, float t0, float s1, float t1, + float z) +{ + unsigned offset; + + ctx->vertices[0][0][0] = x0; + ctx->vertices[0][0][1] = y0; + ctx->vertices[0][0][2] = z; + ctx->vertices[0][1][0] = s0; /*s*/ + ctx->vertices[0][1][1] = t0; /*t*/ + + ctx->vertices[1][0][0] = x1; + ctx->vertices[1][0][1] = y0; + ctx->vertices[1][0][2] = z; + ctx->vertices[1][1][0] = s1; /*s*/ + ctx->vertices[1][1][1] = t0; /*t*/ + + ctx->vertices[2][0][0] = x1; + ctx->vertices[2][0][1] = y1; + ctx->vertices[2][0][2] = z; + ctx->vertices[2][1][0] = s1; + ctx->vertices[2][1][1] = t1; + + ctx->vertices[3][0][0] = x0; + ctx->vertices[3][0][1] = y1; + ctx->vertices[3][0][2] = z; + ctx->vertices[3][1][0] = s0; + ctx->vertices[3][1][1] = t1; + + offset = get_next_slot( ctx ); + + pipe_buffer_write_nooverlap(ctx->pipe, ctx->vbuf, + offset, sizeof(ctx->vertices), ctx->vertices); + + return offset; +} + + +/** + * \return TRUE if two regions overlap, FALSE otherwise + */ +static boolean +regions_overlap(int srcX0, int srcY0, + int srcX1, int srcY1, + int dstX0, int dstY0, + int dstX1, int dstY1) +{ + if (MAX2(srcX0, srcX1) < MIN2(dstX0, dstX1)) + return FALSE; /* src completely left of dst */ + + if (MAX2(dstX0, dstX1) < MIN2(srcX0, srcX1)) + return FALSE; /* dst completely left of src */ + + if (MAX2(srcY0, srcY1) < MIN2(dstY0, dstY1)) + return FALSE; /* src completely above dst */ + + if (MAX2(dstY0, dstY1) < MIN2(srcY0, srcY1)) + return FALSE; /* dst completely above src */ + + return TRUE; /* some overlap */ +} + + +/** + * Copy pixel block from src surface to dst surface. + * Overlapping regions are acceptable. + * Flipping and stretching are supported. + * \param filter one of PIPE_TEX_MIPFILTER_NEAREST/LINEAR + * \param writemask controls which channels in the dest surface are sourced + * from the src surface. Disabled channels are sourced + * from (0,0,0,1). + * XXX need some control over blitting stencil. + */ +void +util_blit_pixels_writemask(struct blit_state *ctx, + struct pipe_resource *src_tex, + unsigned src_level, + int srcX0, int srcY0, + int srcX1, int srcY1, + int srcZ0, + struct pipe_surface *dst, + int dstX0, int dstY0, + int dstX1, int dstY1, + float z, uint filter, + uint writemask) +{ + struct pipe_context *pipe = ctx->pipe; + struct pipe_screen *screen = pipe->screen; + struct pipe_sampler_view *sampler_view = NULL; + struct pipe_sampler_view sv_templ; + struct pipe_framebuffer_state fb; + const int srcW = abs(srcX1 - srcX0); + const int srcH = abs(srcY1 - srcY0); + unsigned offset; + boolean overlap, dst_is_depth; + float s0, t0, s1, t1; + boolean normalized; + + assert(filter == PIPE_TEX_MIPFILTER_NEAREST || + filter == PIPE_TEX_MIPFILTER_LINEAR); + + assert(src_level <= src_tex->last_level); + + /* do the regions overlap? */ + overlap = src_tex == dst->texture && + dst->u.tex.level == src_level && + dst->u.tex.first_layer == srcZ0 && + regions_overlap(srcX0, srcY0, srcX1, srcY1, + dstX0, dstY0, dstX1, dstY1); + + /* + * Check for simple case: no format conversion, no flipping, no stretching, + * no overlapping. + * Filter mode should not matter since there's no stretching. + */ + if (dst->format == src_tex->format && + srcX0 < srcX1 && + dstX0 < dstX1 && + srcY0 < srcY1 && + dstY0 < dstY1 && + (dstX1 - dstX0) == (srcX1 - srcX0) && + (dstY1 - dstY0) == (srcY1 - srcY0) && + !overlap) { + struct pipe_box src_box; + src_box.x = srcX0; + src_box.y = srcY0; + src_box.z = srcZ0; + src_box.width = srcW; + src_box.height = srcH; + src_box.depth = 1; + pipe->resource_copy_region(pipe, + dst->texture, dst->u.tex.level, + dstX0, dstY0, dst->u.tex.first_layer,/* dest */ + src_tex, src_level, + &src_box); + return; + } + + /* Create a temporary texture when src and dest alias or when src + * is anything other than a 2d texture. + * XXX should just use appropriate shader to access 1d / 3d slice / cube face, + * much like the u_blitter code does (should be pretty trivial). + * + * This can still be improved upon. + */ + if ((src_tex == dst->texture && + dst->u.tex.level == src_level && + dst->u.tex.first_layer == srcZ0) || + (src_tex->target != PIPE_TEXTURE_2D && + src_tex->target != PIPE_TEXTURE_2D && + src_tex->target != PIPE_TEXTURE_RECT)) + { + struct pipe_resource texTemp; + struct pipe_resource *tex; + struct pipe_sampler_view sv_templ; + struct pipe_box src_box; + const int srcLeft = MIN2(srcX0, srcX1); + const int srcTop = MIN2(srcY0, srcY1); + + if (srcLeft != srcX0) { + /* left-right flip */ + int tmp = dstX0; + dstX0 = dstX1; + dstX1 = tmp; + } + + if (srcTop != srcY0) { + /* up-down flip */ + int tmp = dstY0; + dstY0 = dstY1; + dstY1 = tmp; + } + + /* create temp texture */ + memset(&texTemp, 0, sizeof(texTemp)); + texTemp.target = ctx->internal_target; + texTemp.format = src_tex->format; + texTemp.last_level = 0; + texTemp.width0 = srcW; + texTemp.height0 = srcH; + texTemp.depth0 = 1; + texTemp.array_size = 1; + texTemp.bind = PIPE_BIND_SAMPLER_VIEW; + + tex = screen->resource_create(screen, &texTemp); + if (!tex) + return; + + src_box.x = srcLeft; + src_box.y = srcTop; + src_box.z = srcZ0; + src_box.width = srcW; + src_box.height = srcH; + src_box.depth = 1; + /* load temp texture */ + pipe->resource_copy_region(pipe, + tex, 0, 0, 0, 0, /* dest */ + src_tex, src_level, &src_box); + + normalized = tex->target != PIPE_TEXTURE_RECT; + if(normalized) { + s0 = 0.0f; + s1 = 1.0f; + t0 = 0.0f; + t1 = 1.0f; + } + else { + s0 = 0; + s1 = srcW; + t0 = 0; + t1 = srcH; + } + + u_sampler_view_default_template(&sv_templ, tex, tex->format); + sampler_view = pipe->create_sampler_view(pipe, tex, &sv_templ); + + if (!sampler_view) { + pipe_resource_reference(&tex, NULL); + return; + } + pipe_resource_reference(&tex, NULL); + } + else { + u_sampler_view_default_template(&sv_templ, src_tex, src_tex->format); + sampler_view = pipe->create_sampler_view(pipe, src_tex, &sv_templ); + + if (!sampler_view) { + return; + } + + s0 = srcX0; + s1 = srcX1; + t0 = srcY0; + t1 = srcY1; + normalized = sampler_view->texture->target != PIPE_TEXTURE_RECT; + if(normalized) + { + s0 /= (float)(u_minify(sampler_view->texture->width0, src_level)); + s1 /= (float)(u_minify(sampler_view->texture->width0, src_level)); + t0 /= (float)(u_minify(sampler_view->texture->height0, src_level)); + t1 /= (float)(u_minify(sampler_view->texture->height0, src_level)); + } + } + + dst_is_depth = util_format_is_depth_or_stencil(dst->format); + + assert(screen->is_format_supported(screen, sampler_view->format, ctx->internal_target, + sampler_view->texture->nr_samples, + PIPE_BIND_SAMPLER_VIEW, 0)); + assert(screen->is_format_supported(screen, dst->format, ctx->internal_target, + dst->texture->nr_samples, + dst_is_depth ? PIPE_BIND_DEPTH_STENCIL : + PIPE_BIND_RENDER_TARGET, 0)); + /* save state (restored below) */ + cso_save_blend(ctx->cso); + cso_save_depth_stencil_alpha(ctx->cso); + cso_save_rasterizer(ctx->cso); + cso_save_samplers(ctx->cso); + cso_save_fragment_sampler_views(ctx->cso); + cso_save_viewport(ctx->cso); + cso_save_framebuffer(ctx->cso); + cso_save_fragment_shader(ctx->cso); + cso_save_vertex_shader(ctx->cso); + cso_save_clip(ctx->cso); + cso_save_vertex_elements(ctx->cso); + + /* set misc state we care about */ + cso_set_blend(ctx->cso, &ctx->blend); + cso_set_depth_stencil_alpha(ctx->cso, + dst_is_depth ? &ctx->depthstencil_write : + &ctx->depthstencil_keep); + cso_set_rasterizer(ctx->cso, &ctx->rasterizer); + cso_set_clip(ctx->cso, &ctx->clip); + cso_set_vertex_elements(ctx->cso, 2, ctx->velem); + + /* sampler */ + ctx->sampler.normalized_coords = normalized; + ctx->sampler.min_img_filter = filter; + ctx->sampler.mag_img_filter = filter; + ctx->sampler.min_lod = src_level; + ctx->sampler.max_lod = src_level; + cso_single_sampler(ctx->cso, 0, &ctx->sampler); + cso_single_sampler_done(ctx->cso); + + /* viewport */ + ctx->viewport.scale[0] = 0.5f * dst->width; + ctx->viewport.scale[1] = 0.5f * dst->height; + ctx->viewport.scale[2] = 0.5f; + ctx->viewport.scale[3] = 1.0f; + ctx->viewport.translate[0] = 0.5f * dst->width; + ctx->viewport.translate[1] = 0.5f * dst->height; + ctx->viewport.translate[2] = 0.5f; + ctx->viewport.translate[3] = 0.0f; + cso_set_viewport(ctx->cso, &ctx->viewport); + + /* texture */ + cso_set_fragment_sampler_views(ctx->cso, 1, &sampler_view); + + /* shaders */ + if (dst_is_depth) { + if (ctx->fs_depth == NULL) + ctx->fs_depth = + util_make_fragment_tex_shader_writedepth(pipe, TGSI_TEXTURE_2D, + TGSI_INTERPOLATE_LINEAR); + + cso_set_fragment_shader_handle(ctx->cso, ctx->fs_depth); + } else { + if (ctx->fs[writemask] == NULL) + ctx->fs[writemask] = + util_make_fragment_tex_shader_writemask(pipe, TGSI_TEXTURE_2D, + TGSI_INTERPOLATE_LINEAR, + writemask); + + cso_set_fragment_shader_handle(ctx->cso, ctx->fs[writemask]); + } + cso_set_vertex_shader_handle(ctx->cso, ctx->vs); + + /* drawing dest */ + memset(&fb, 0, sizeof(fb)); + fb.width = dst->width; + fb.height = dst->height; + if (dst_is_depth) { + fb.zsbuf = dst; + } else { + fb.nr_cbufs = 1; + fb.cbufs[0] = dst; + } + cso_set_framebuffer(ctx->cso, &fb); + + /* draw quad */ + offset = setup_vertex_data_tex(ctx, + (float) dstX0 / dst->width * 2.0f - 1.0f, + (float) dstY0 / dst->height * 2.0f - 1.0f, + (float) dstX1 / dst->width * 2.0f - 1.0f, + (float) dstY1 / dst->height * 2.0f - 1.0f, + s0, t0, + s1, t1, + z); + + util_draw_vertex_buffer(ctx->pipe, ctx->vbuf, offset, + PIPE_PRIM_TRIANGLE_FAN, + 4, /* verts */ + 2); /* attribs/vert */ + + /* restore state we changed */ + cso_restore_blend(ctx->cso); + cso_restore_depth_stencil_alpha(ctx->cso); + cso_restore_rasterizer(ctx->cso); + cso_restore_samplers(ctx->cso); + cso_restore_fragment_sampler_views(ctx->cso); + cso_restore_viewport(ctx->cso); + cso_restore_framebuffer(ctx->cso); + cso_restore_fragment_shader(ctx->cso); + cso_restore_vertex_shader(ctx->cso); + cso_restore_clip(ctx->cso); + cso_restore_vertex_elements(ctx->cso); + + pipe_sampler_view_reference(&sampler_view, NULL); +} + + +void +util_blit_pixels(struct blit_state *ctx, + struct pipe_resource *src_tex, + unsigned src_level, + int srcX0, int srcY0, + int srcX1, int srcY1, + int srcZ, + struct pipe_surface *dst, + int dstX0, int dstY0, + int dstX1, int dstY1, + float z, uint filter ) +{ + util_blit_pixels_writemask( ctx, src_tex, + src_level, + srcX0, srcY0, + srcX1, srcY1, + srcZ, + dst, + dstX0, dstY0, + dstX1, dstY1, + z, filter, + TGSI_WRITEMASK_XYZW ); +} + + +/* Release vertex buffer at end of frame to avoid synchronous + * rendering. + */ +void util_blit_flush( struct blit_state *ctx ) +{ + pipe_resource_reference(&ctx->vbuf, NULL); + ctx->vbuf_slot = 0; +} + + + +/** + * Copy pixel block from src texture to dst surface. + * + * XXX Should support selection of level. + * XXX need some control over blitting Z and/or stencil. + */ +void +util_blit_pixels_tex(struct blit_state *ctx, + struct pipe_sampler_view *src_sampler_view, + int srcX0, int srcY0, + int srcX1, int srcY1, + struct pipe_surface *dst, + int dstX0, int dstY0, + int dstX1, int dstY1, + float z, uint filter) +{ + boolean normalized = src_sampler_view->texture->target != PIPE_TEXTURE_RECT; + struct pipe_framebuffer_state fb; + float s0, t0, s1, t1; + unsigned offset; + struct pipe_resource *tex = src_sampler_view->texture; + + assert(filter == PIPE_TEX_MIPFILTER_NEAREST || + filter == PIPE_TEX_MIPFILTER_LINEAR); + + assert(tex); + assert(tex->width0 != 0); + assert(tex->height0 != 0); + + s0 = srcX0; + s1 = srcX1; + t0 = srcY0; + t1 = srcY1; + + if(normalized) + { + s0 /= (float)tex->width0; + s1 /= (float)tex->width0; + t0 /= (float)tex->height0; + t1 /= (float)tex->height0; + } + + assert(ctx->pipe->screen->is_format_supported(ctx->pipe->screen, dst->format, + PIPE_TEXTURE_2D, + dst->texture->nr_samples, + PIPE_BIND_RENDER_TARGET, + 0)); + + /* save state (restored below) */ + cso_save_blend(ctx->cso); + cso_save_depth_stencil_alpha(ctx->cso); + cso_save_rasterizer(ctx->cso); + cso_save_samplers(ctx->cso); + cso_save_fragment_sampler_views(ctx->cso); + cso_save_viewport(ctx->cso); + cso_save_framebuffer(ctx->cso); + cso_save_fragment_shader(ctx->cso); + cso_save_vertex_shader(ctx->cso); + cso_save_clip(ctx->cso); + cso_save_vertex_elements(ctx->cso); + + /* set misc state we care about */ + cso_set_blend(ctx->cso, &ctx->blend); + cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil_keep); + cso_set_rasterizer(ctx->cso, &ctx->rasterizer); + cso_set_clip(ctx->cso, &ctx->clip); + cso_set_vertex_elements(ctx->cso, 2, ctx->velem); + + /* sampler */ + ctx->sampler.normalized_coords = normalized; + ctx->sampler.min_img_filter = filter; + ctx->sampler.mag_img_filter = filter; + cso_single_sampler(ctx->cso, 0, &ctx->sampler); + cso_single_sampler_done(ctx->cso); + + /* viewport */ + ctx->viewport.scale[0] = 0.5f * dst->width; + ctx->viewport.scale[1] = 0.5f * dst->height; + ctx->viewport.scale[2] = 0.5f; + ctx->viewport.scale[3] = 1.0f; + ctx->viewport.translate[0] = 0.5f * dst->width; + ctx->viewport.translate[1] = 0.5f * dst->height; + ctx->viewport.translate[2] = 0.5f; + ctx->viewport.translate[3] = 0.0f; + cso_set_viewport(ctx->cso, &ctx->viewport); + + /* texture */ + cso_set_fragment_sampler_views(ctx->cso, 1, &src_sampler_view); + + /* shaders */ + cso_set_fragment_shader_handle(ctx->cso, ctx->fs[TGSI_WRITEMASK_XYZW]); + cso_set_vertex_shader_handle(ctx->cso, ctx->vs); + + /* drawing dest */ + memset(&fb, 0, sizeof(fb)); + fb.width = dst->width; + fb.height = dst->height; + fb.nr_cbufs = 1; + fb.cbufs[0] = dst; + cso_set_framebuffer(ctx->cso, &fb); + + /* draw quad */ + offset = setup_vertex_data_tex(ctx, + (float) dstX0 / dst->width * 2.0f - 1.0f, + (float) dstY0 / dst->height * 2.0f - 1.0f, + (float) dstX1 / dst->width * 2.0f - 1.0f, + (float) dstY1 / dst->height * 2.0f - 1.0f, + s0, t0, s1, t1, + z); + + util_draw_vertex_buffer(ctx->pipe, + ctx->vbuf, offset, + PIPE_PRIM_TRIANGLE_FAN, + 4, /* verts */ + 2); /* attribs/vert */ + + /* restore state we changed */ + cso_restore_blend(ctx->cso); + cso_restore_depth_stencil_alpha(ctx->cso); + cso_restore_rasterizer(ctx->cso); + cso_restore_samplers(ctx->cso); + cso_restore_fragment_sampler_views(ctx->cso); + cso_restore_viewport(ctx->cso); + cso_restore_framebuffer(ctx->cso); + cso_restore_fragment_shader(ctx->cso); + cso_restore_vertex_shader(ctx->cso); + cso_restore_clip(ctx->cso); + cso_restore_vertex_elements(ctx->cso); +} diff --git a/src/gallium/auxiliary/util/u_blit.h b/src/gallium/auxiliary/util/u_blit.h new file mode 100644 index 0000000..3009e25 --- /dev/null +++ b/src/gallium/auxiliary/util/u_blit.h @@ -0,0 +1,98 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef U_BLIT_H +#define U_BLIT_H + + +#include "pipe/p_compiler.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct cso_context; +struct pipe_context; +struct pipe_resource; +struct pipe_sampler_view; +struct pipe_surface; + + +extern struct blit_state * +util_create_blit(struct pipe_context *pipe, struct cso_context *cso); + +extern void +util_destroy_blit(struct blit_state *ctx); + +extern void +util_blit_pixels(struct blit_state *ctx, + struct pipe_resource *src_tex, + unsigned src_level, + int srcX0, int srcY0, + int srcX1, int srcY1, + int srcZ0, + struct pipe_surface *dst, + int dstX0, int dstY0, + int dstX1, int dstY1, + float z, uint filter); + +void +util_blit_pixels_writemask(struct blit_state *ctx, + struct pipe_resource *src_tex, + unsigned src_level, + int srcX0, int srcY0, + int srcX1, int srcY1, + int srcZ0, + struct pipe_surface *dst, + int dstX0, int dstY0, + int dstX1, int dstY1, + float z, uint filter, + uint writemask); + +extern void +util_blit_pixels_tex(struct blit_state *ctx, + struct pipe_sampler_view *src_sampler_view, + int srcX0, int srcY0, + int srcX1, int srcY1, + struct pipe_surface *dst, + int dstX0, int dstY0, + int dstX1, int dstY1, + float z, uint filter); + +/* Call at end of frame to avoid synchronous rendering. + */ +extern void +util_blit_flush( struct blit_state *ctx ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c new file mode 100644 index 0000000..4c986e3 --- /dev/null +++ b/src/gallium/auxiliary/util/u_blitter.c @@ -0,0 +1,1025 @@ +/************************************************************************** + * + * Copyright 2009 Marek Olšák + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Blitter utility to facilitate acceleration of the clear, clear_render_target, clear_depth_stencil + * resource_copy_region functions. + * + * @author Marek Olšák + */ + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/p_state.h" + +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_blitter.h" +#include "util/u_draw_quad.h" +#include "util/u_sampler.h" +#include "util/u_simple_shaders.h" +#include "util/u_surface.h" +#include "util/u_texture.h" + +#define INVALID_PTR ((void*)~0) + +struct blitter_context_priv +{ + struct blitter_context base; + + struct pipe_resource *vbuf; /**< quad */ + + float vertices[4][2][4]; /**< {pos, color} or {pos, texcoord} */ + + /* Templates for various state objects. */ + struct pipe_sampler_state template_sampler_state; + + /* Constant state objects. */ + /* Vertex shaders. */ + void *vs; /**< Vertex shader which passes {pos, generic} to the output.*/ + + /* Fragment shaders. */ + /* The shader at index i outputs color to color buffers 0,1,...,i-1. */ + void *fs_col[PIPE_MAX_COLOR_BUFS+1]; + + /* FS which outputs a color from a texture, + where the index is PIPE_TEXTURE_* to be sampled. */ + void *fs_texfetch_col[PIPE_MAX_TEXTURE_TYPES]; + + /* FS which outputs a depth from a texture, + where the index is PIPE_TEXTURE_* to be sampled. */ + void *fs_texfetch_depth[PIPE_MAX_TEXTURE_TYPES]; + + /* Blend state. */ + void *blend_write_color; /**< blend state with writemask of RGBA */ + void *blend_keep_color; /**< blend state with writemask of 0 */ + + /* Depth stencil alpha state. */ + void *dsa_write_depth_stencil; + void *dsa_write_depth_keep_stencil; + void *dsa_keep_depth_stencil; + void *dsa_keep_depth_write_stencil; + void *dsa_flush_depth_stencil; + + void *velem_state; + + /* Sampler state for clamping to a miplevel. */ + void *sampler_state[PIPE_MAX_TEXTURE_LEVELS * 2]; + + /* Rasterizer state. */ + void *rs_state; + + /* Viewport state. */ + struct pipe_viewport_state viewport; + + /* Clip state. */ + struct pipe_clip_state clip; + + /* Destination surface dimensions. */ + unsigned dst_width; + unsigned dst_height; +}; + +static void blitter_draw_rectangle(struct blitter_context *blitter, + unsigned x, unsigned y, + unsigned width, unsigned height, + float depth, + enum blitter_attrib_type type, + const float attrib[4]); + + +struct blitter_context *util_blitter_create(struct pipe_context *pipe) +{ + struct blitter_context_priv *ctx; + struct pipe_blend_state blend; + struct pipe_depth_stencil_alpha_state dsa; + struct pipe_rasterizer_state rs_state; + struct pipe_sampler_state *sampler_state; + struct pipe_vertex_element velem[2]; + unsigned i; + + ctx = CALLOC_STRUCT(blitter_context_priv); + if (!ctx) + return NULL; + + ctx->base.pipe = pipe; + ctx->base.draw_rectangle = blitter_draw_rectangle; + + /* init state objects for them to be considered invalid */ + ctx->base.saved_blend_state = INVALID_PTR; + ctx->base.saved_dsa_state = INVALID_PTR; + ctx->base.saved_rs_state = INVALID_PTR; + ctx->base.saved_fs = INVALID_PTR; + ctx->base.saved_vs = INVALID_PTR; + ctx->base.saved_velem_state = INVALID_PTR; + ctx->base.saved_fb_state.nr_cbufs = ~0; + ctx->base.saved_num_sampler_views = ~0; + ctx->base.saved_num_sampler_states = ~0; + ctx->base.saved_num_vertex_buffers = ~0; + + /* blend state objects */ + memset(&blend, 0, sizeof(blend)); + ctx->blend_keep_color = pipe->create_blend_state(pipe, &blend); + + blend.rt[0].colormask = PIPE_MASK_RGBA; + ctx->blend_write_color = pipe->create_blend_state(pipe, &blend); + + /* depth stencil alpha state objects */ + memset(&dsa, 0, sizeof(dsa)); + ctx->dsa_keep_depth_stencil = + pipe->create_depth_stencil_alpha_state(pipe, &dsa); + + dsa.depth.writemask = 1; + ctx->dsa_flush_depth_stencil = + pipe->create_depth_stencil_alpha_state(pipe, &dsa); + + dsa.depth.enabled = 1; + dsa.depth.writemask = 1; + dsa.depth.func = PIPE_FUNC_ALWAYS; + ctx->dsa_write_depth_keep_stencil = + pipe->create_depth_stencil_alpha_state(pipe, &dsa); + + dsa.stencil[0].enabled = 1; + dsa.stencil[0].func = PIPE_FUNC_ALWAYS; + dsa.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE; + dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE; + dsa.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE; + dsa.stencil[0].valuemask = 0xff; + dsa.stencil[0].writemask = 0xff; + ctx->dsa_write_depth_stencil = + pipe->create_depth_stencil_alpha_state(pipe, &dsa); + + + dsa.depth.enabled = 0; + dsa.depth.writemask = 0; + ctx->dsa_keep_depth_write_stencil = + pipe->create_depth_stencil_alpha_state(pipe, &dsa); + + /* sampler state */ + sampler_state = &ctx->template_sampler_state; + sampler_state->wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler_state->wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler_state->wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler_state->normalized_coords = TRUE; + /* The sampler state objects which sample from a specified mipmap level + * are created on-demand. */ + + /* rasterizer state */ + memset(&rs_state, 0, sizeof(rs_state)); + rs_state.cull_face = PIPE_FACE_NONE; + rs_state.gl_rasterization_rules = 1; + rs_state.flatshade = 1; + ctx->rs_state = pipe->create_rasterizer_state(pipe, &rs_state); + + /* vertex elements state */ + memset(&velem[0], 0, sizeof(velem[0]) * 2); + for (i = 0; i < 2; i++) { + velem[i].src_offset = i * 4 * sizeof(float); + velem[i].instance_divisor = 0; + velem[i].vertex_buffer_index = 0; + velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + } + ctx->velem_state = pipe->create_vertex_elements_state(pipe, 2, &velem[0]); + + /* fragment shaders are created on-demand */ + + /* vertex shader */ + { + const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, + TGSI_SEMANTIC_GENERIC }; + const uint semantic_indices[] = { 0, 0 }; + ctx->vs = + util_make_vertex_passthrough_shader(pipe, 2, semantic_names, + semantic_indices); + } + + /* set invariant vertex coordinates */ + for (i = 0; i < 4; i++) + ctx->vertices[i][0][3] = 1; /*v.w*/ + + /* create the vertex buffer */ + ctx->vbuf = pipe_buffer_create(ctx->base.pipe->screen, + PIPE_BIND_VERTEX_BUFFER, + sizeof(ctx->vertices)); + + return &ctx->base; +} + +void util_blitter_destroy(struct blitter_context *blitter) +{ + struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; + struct pipe_context *pipe = blitter->pipe; + int i; + + pipe->delete_blend_state(pipe, ctx->blend_write_color); + pipe->delete_blend_state(pipe, ctx->blend_keep_color); + pipe->delete_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil); + pipe->delete_depth_stencil_alpha_state(pipe, + ctx->dsa_write_depth_keep_stencil); + pipe->delete_depth_stencil_alpha_state(pipe, ctx->dsa_write_depth_stencil); + pipe->delete_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_write_stencil); + pipe->delete_depth_stencil_alpha_state(pipe, ctx->dsa_flush_depth_stencil); + + pipe->delete_rasterizer_state(pipe, ctx->rs_state); + pipe->delete_vs_state(pipe, ctx->vs); + pipe->delete_vertex_elements_state(pipe, ctx->velem_state); + + for (i = 0; i < PIPE_MAX_TEXTURE_TYPES; i++) { + if (ctx->fs_texfetch_col[i]) + pipe->delete_fs_state(pipe, ctx->fs_texfetch_col[i]); + if (ctx->fs_texfetch_depth[i]) + pipe->delete_fs_state(pipe, ctx->fs_texfetch_depth[i]); + } + + for (i = 0; i <= PIPE_MAX_COLOR_BUFS; i++) + if (ctx->fs_col[i]) + pipe->delete_fs_state(pipe, ctx->fs_col[i]); + + for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS * 2; i++) + if (ctx->sampler_state[i]) + pipe->delete_sampler_state(pipe, ctx->sampler_state[i]); + + pipe_resource_reference(&ctx->vbuf, NULL); + FREE(ctx); +} + +static void blitter_check_saved_CSOs(struct blitter_context_priv *ctx) +{ + /* make sure these CSOs have been saved */ + assert(ctx->base.saved_blend_state != INVALID_PTR && + ctx->base.saved_dsa_state != INVALID_PTR && + ctx->base.saved_rs_state != INVALID_PTR && + ctx->base.saved_fs != INVALID_PTR && + ctx->base.saved_vs != INVALID_PTR && + ctx->base.saved_velem_state != INVALID_PTR); +} + +static void blitter_restore_CSOs(struct blitter_context_priv *ctx) +{ + struct pipe_context *pipe = ctx->base.pipe; + unsigned i; + + /* restore the state objects which are always required to be saved */ + pipe->bind_blend_state(pipe, ctx->base.saved_blend_state); + pipe->bind_depth_stencil_alpha_state(pipe, ctx->base.saved_dsa_state); + pipe->bind_rasterizer_state(pipe, ctx->base.saved_rs_state); + pipe->bind_fs_state(pipe, ctx->base.saved_fs); + pipe->bind_vs_state(pipe, ctx->base.saved_vs); + pipe->bind_vertex_elements_state(pipe, ctx->base.saved_velem_state); + + ctx->base.saved_blend_state = INVALID_PTR; + ctx->base.saved_dsa_state = INVALID_PTR; + ctx->base.saved_rs_state = INVALID_PTR; + ctx->base.saved_fs = INVALID_PTR; + ctx->base.saved_vs = INVALID_PTR; + ctx->base.saved_velem_state = INVALID_PTR; + + pipe->set_stencil_ref(pipe, &ctx->base.saved_stencil_ref); + + pipe->set_viewport_state(pipe, &ctx->base.saved_viewport); + pipe->set_clip_state(pipe, &ctx->base.saved_clip); + + /* restore the state objects which are required to be saved before copy/fill + */ + if (ctx->base.saved_fb_state.nr_cbufs != ~0) { + pipe->set_framebuffer_state(pipe, &ctx->base.saved_fb_state); + util_unreference_framebuffer_state(&ctx->base.saved_fb_state); + ctx->base.saved_fb_state.nr_cbufs = ~0; + } + + if (ctx->base.saved_num_sampler_states != ~0) { + pipe->bind_fragment_sampler_states(pipe, + ctx->base.saved_num_sampler_states, + ctx->base.saved_sampler_states); + ctx->base.saved_num_sampler_states = ~0; + } + + if (ctx->base.saved_num_sampler_views != ~0) { + pipe->set_fragment_sampler_views(pipe, + ctx->base.saved_num_sampler_views, + ctx->base.saved_sampler_views); + + for (i = 0; i < ctx->base.saved_num_sampler_views; i++) + pipe_sampler_view_reference(&ctx->base.saved_sampler_views[i], + NULL); + + ctx->base.saved_num_sampler_views = ~0; + } + + if (ctx->base.saved_num_vertex_buffers != ~0) { + pipe->set_vertex_buffers(pipe, + ctx->base.saved_num_vertex_buffers, + ctx->base.saved_vertex_buffers); + + for (i = 0; i < ctx->base.saved_num_vertex_buffers; i++) { + if (ctx->base.saved_vertex_buffers[i].buffer) { + pipe_resource_reference(&ctx->base.saved_vertex_buffers[i].buffer, + NULL); + } + } + ctx->base.saved_num_vertex_buffers = ~0; + } +} + +static void blitter_set_rectangle(struct blitter_context_priv *ctx, + unsigned x1, unsigned y1, + unsigned x2, unsigned y2, + float depth) +{ + int i; + + /* set vertex positions */ + ctx->vertices[0][0][0] = (float)x1 / ctx->dst_width * 2.0f - 1.0f; /*v0.x*/ + ctx->vertices[0][0][1] = (float)y1 / ctx->dst_height * 2.0f - 1.0f; /*v0.y*/ + + ctx->vertices[1][0][0] = (float)x2 / ctx->dst_width * 2.0f - 1.0f; /*v1.x*/ + ctx->vertices[1][0][1] = (float)y1 / ctx->dst_height * 2.0f - 1.0f; /*v1.y*/ + + ctx->vertices[2][0][0] = (float)x2 / ctx->dst_width * 2.0f - 1.0f; /*v2.x*/ + ctx->vertices[2][0][1] = (float)y2 / ctx->dst_height * 2.0f - 1.0f; /*v2.y*/ + + ctx->vertices[3][0][0] = (float)x1 / ctx->dst_width * 2.0f - 1.0f; /*v3.x*/ + ctx->vertices[3][0][1] = (float)y2 / ctx->dst_height * 2.0f - 1.0f; /*v3.y*/ + + for (i = 0; i < 4; i++) + ctx->vertices[i][0][2] = depth; /*z*/ + + /* viewport */ + ctx->viewport.scale[0] = 0.5f * ctx->dst_width; + ctx->viewport.scale[1] = 0.5f * ctx->dst_height; + ctx->viewport.scale[2] = 1.0f; + ctx->viewport.scale[3] = 1.0f; + ctx->viewport.translate[0] = 0.5f * ctx->dst_width; + ctx->viewport.translate[1] = 0.5f * ctx->dst_height; + ctx->viewport.translate[2] = 0.0f; + ctx->viewport.translate[3] = 0.0f; + ctx->base.pipe->set_viewport_state(ctx->base.pipe, &ctx->viewport); + + /* clip */ + ctx->base.pipe->set_clip_state(ctx->base.pipe, &ctx->clip); +} + +static void blitter_set_clear_color(struct blitter_context_priv *ctx, + const float *rgba) +{ + int i; + + if (rgba) { + for (i = 0; i < 4; i++) { + ctx->vertices[i][1][0] = rgba[0]; + ctx->vertices[i][1][1] = rgba[1]; + ctx->vertices[i][1][2] = rgba[2]; + ctx->vertices[i][1][3] = rgba[3]; + } + } else { + for (i = 0; i < 4; i++) { + ctx->vertices[i][1][0] = 0; + ctx->vertices[i][1][1] = 0; + ctx->vertices[i][1][2] = 0; + ctx->vertices[i][1][3] = 0; + } + } +} + +static void get_texcoords(struct pipe_resource *src, + unsigned level, + unsigned x1, unsigned y1, + unsigned x2, unsigned y2, + boolean normalized, float out[4]) +{ + if(normalized) + { + out[0] = x1 / (float)u_minify(src->width0, level); + out[1] = y1 / (float)u_minify(src->height0, level); + out[2] = x2 / (float)u_minify(src->width0, level); + out[3] = y2 / (float)u_minify(src->height0, level); + } + else + { + out[0] = x1; + out[1] = y1; + out[2] = x2; + out[3] = y2; + } +} + +static void set_texcoords_in_vertices(const float coord[4], + float *out, unsigned stride) +{ + out[0] = coord[0]; /*t0.s*/ + out[1] = coord[1]; /*t0.t*/ + out += stride; + out[0] = coord[2]; /*t1.s*/ + out[1] = coord[1]; /*t1.t*/ + out += stride; + out[0] = coord[2]; /*t2.s*/ + out[1] = coord[3]; /*t2.t*/ + out += stride; + out[0] = coord[0]; /*t3.s*/ + out[1] = coord[3]; /*t3.t*/ +} + +static void blitter_set_texcoords_2d(struct blitter_context_priv *ctx, + struct pipe_resource *src, + unsigned level, + unsigned x1, unsigned y1, + unsigned x2, unsigned y2) +{ + unsigned i; + float coord[4]; + + get_texcoords(src, level, x1, y1, x2, y2, TRUE, coord); + set_texcoords_in_vertices(coord, &ctx->vertices[0][1][0], 8); + + for (i = 0; i < 4; i++) { + ctx->vertices[i][1][2] = 0; /*r*/ + ctx->vertices[i][1][3] = 1; /*q*/ + } +} + +static void blitter_set_texcoords_3d(struct blitter_context_priv *ctx, + struct pipe_resource *src, + unsigned level, + unsigned zslice, + unsigned x1, unsigned y1, + unsigned x2, unsigned y2) +{ + int i; + float r = zslice / (float)u_minify(src->depth0, level); + + blitter_set_texcoords_2d(ctx, src, level, x1, y1, x2, y2); + + for (i = 0; i < 4; i++) + ctx->vertices[i][1][2] = r; /*r*/ +} + +static void blitter_set_texcoords_cube(struct blitter_context_priv *ctx, + struct pipe_resource *src, + unsigned level, unsigned face, + unsigned x1, unsigned y1, + unsigned x2, unsigned y2) +{ + int i; + float coord[4]; + float st[4][2]; + + get_texcoords(src, level, x1, y1, x2, y2, TRUE, coord); + set_texcoords_in_vertices(coord, &st[0][0], 2); + + util_map_texcoords2d_onto_cubemap(face, + /* pointer, stride in floats */ + &st[0][0], 2, + &ctx->vertices[0][1][0], 8); + + for (i = 0; i < 4; i++) + ctx->vertices[i][1][3] = 1; /*q*/ +} + +static void blitter_set_dst_dimensions(struct blitter_context_priv *ctx, + unsigned width, unsigned height) +{ + ctx->dst_width = width; + ctx->dst_height = height; +} + +static void blitter_draw_quad(struct blitter_context_priv *ctx) +{ + struct pipe_context *pipe = ctx->base.pipe; + struct pipe_box box; + + /* write vertices and draw them */ + u_box_1d(0, sizeof(ctx->vertices), &box); + pipe->transfer_inline_write(pipe, ctx->vbuf, 0, + PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD, + &box, ctx->vertices, sizeof(ctx->vertices), 0); + + util_draw_vertex_buffer(pipe, ctx->vbuf, 0, PIPE_PRIM_TRIANGLE_FAN, + 4, /* verts */ + 2); /* attribs/vert */ +} + +static INLINE +void **blitter_get_sampler_state(struct blitter_context_priv *ctx, + int miplevel, boolean normalized) +{ + struct pipe_context *pipe = ctx->base.pipe; + struct pipe_sampler_state *sampler_state = &ctx->template_sampler_state; + + assert(miplevel < PIPE_MAX_TEXTURE_LEVELS); + + /* Create the sampler state on-demand. */ + if (!ctx->sampler_state[miplevel * 2 + normalized]) { + sampler_state->lod_bias = miplevel; + sampler_state->min_lod = miplevel; + sampler_state->max_lod = miplevel; + sampler_state->normalized_coords = normalized; + + ctx->sampler_state[miplevel * 2 + normalized] = pipe->create_sampler_state(pipe, + sampler_state); + } + + /* Return void** so that it can be passed to bind_fragment_sampler_states + * directly. */ + return &ctx->sampler_state[miplevel * 2 + normalized]; +} + +static INLINE +void *blitter_get_fs_col(struct blitter_context_priv *ctx, unsigned num_cbufs) +{ + struct pipe_context *pipe = ctx->base.pipe; + + assert(num_cbufs <= PIPE_MAX_COLOR_BUFS); + + if (!ctx->fs_col[num_cbufs]) + ctx->fs_col[num_cbufs] = + util_make_fragment_cloneinput_shader(pipe, num_cbufs, + TGSI_SEMANTIC_GENERIC, + TGSI_INTERPOLATE_LINEAR); + + return ctx->fs_col[num_cbufs]; +} + +/** Convert PIPE_TEXTURE_x to TGSI_TEXTURE_x */ +static unsigned +pipe_tex_to_tgsi_tex(enum pipe_texture_target pipe_tex_target) +{ + switch (pipe_tex_target) { + case PIPE_TEXTURE_1D: + return TGSI_TEXTURE_1D; + case PIPE_TEXTURE_2D: + return TGSI_TEXTURE_2D; + case PIPE_TEXTURE_RECT: + return TGSI_TEXTURE_RECT; + case PIPE_TEXTURE_3D: + return TGSI_TEXTURE_3D; + case PIPE_TEXTURE_CUBE: + return TGSI_TEXTURE_CUBE; + default: + assert(0 && "unexpected texture target"); + return TGSI_TEXTURE_UNKNOWN; + } +} + + +static INLINE +void *blitter_get_fs_texfetch_col(struct blitter_context_priv *ctx, + unsigned tex_target) +{ + struct pipe_context *pipe = ctx->base.pipe; + + assert(tex_target < PIPE_MAX_TEXTURE_TYPES); + + /* Create the fragment shader on-demand. */ + if (!ctx->fs_texfetch_col[tex_target]) { + unsigned tgsi_tex = pipe_tex_to_tgsi_tex(tex_target); + + ctx->fs_texfetch_col[tex_target] = + util_make_fragment_tex_shader(pipe, tgsi_tex, TGSI_INTERPOLATE_LINEAR); + } + + return ctx->fs_texfetch_col[tex_target]; +} + +static INLINE +void *blitter_get_fs_texfetch_depth(struct blitter_context_priv *ctx, + unsigned tex_target) +{ + struct pipe_context *pipe = ctx->base.pipe; + + assert(tex_target < PIPE_MAX_TEXTURE_TYPES); + + /* Create the fragment shader on-demand. */ + if (!ctx->fs_texfetch_depth[tex_target]) { + unsigned tgsi_tex = pipe_tex_to_tgsi_tex(tex_target); + + ctx->fs_texfetch_depth[tex_target] = + util_make_fragment_tex_shader_writedepth(pipe, tgsi_tex, + TGSI_INTERPOLATE_LINEAR); + } + + return ctx->fs_texfetch_depth[tex_target]; +} + +static void blitter_draw_rectangle(struct blitter_context *blitter, + unsigned x1, unsigned y1, + unsigned x2, unsigned y2, + float depth, + enum blitter_attrib_type type, + const float attrib[4]) +{ + struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; + + switch (type) { + case UTIL_BLITTER_ATTRIB_COLOR: + blitter_set_clear_color(ctx, attrib); + break; + + case UTIL_BLITTER_ATTRIB_TEXCOORD: + set_texcoords_in_vertices(attrib, &ctx->vertices[0][1][0], 8); + break; + + default:; + } + + blitter_set_rectangle(ctx, x1, y1, x2, y2, depth); + blitter_draw_quad(ctx); +} + +void util_blitter_clear(struct blitter_context *blitter, + unsigned width, unsigned height, + unsigned num_cbufs, + unsigned clear_buffers, + const float *rgba, + double depth, unsigned stencil) +{ + struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; + struct pipe_context *pipe = ctx->base.pipe; + struct pipe_stencil_ref sr = { { 0 } }; + + assert(num_cbufs <= PIPE_MAX_COLOR_BUFS); + + blitter_check_saved_CSOs(ctx); + + /* bind CSOs */ + if (clear_buffers & PIPE_CLEAR_COLOR) + pipe->bind_blend_state(pipe, ctx->blend_write_color); + else + pipe->bind_blend_state(pipe, ctx->blend_keep_color); + + if ((clear_buffers & PIPE_CLEAR_DEPTHSTENCIL) == PIPE_CLEAR_DEPTHSTENCIL) { + sr.ref_value[0] = stencil & 0xff; + pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_write_depth_stencil); + pipe->set_stencil_ref(pipe, &sr); + } + else if (clear_buffers & PIPE_CLEAR_DEPTH) { + pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_write_depth_keep_stencil); + } + else if (clear_buffers & PIPE_CLEAR_STENCIL) { + sr.ref_value[0] = stencil & 0xff; + pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_write_stencil); + pipe->set_stencil_ref(pipe, &sr); + } + else + pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil); + + pipe->bind_rasterizer_state(pipe, ctx->rs_state); + pipe->bind_vertex_elements_state(pipe, ctx->velem_state); + pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, num_cbufs)); + pipe->bind_vs_state(pipe, ctx->vs); + + blitter_set_dst_dimensions(ctx, width, height); + blitter->draw_rectangle(blitter, 0, 0, width, height, depth, + UTIL_BLITTER_ATTRIB_COLOR, rgba); + blitter_restore_CSOs(ctx); +} + +static +boolean is_overlap(unsigned sx1, unsigned sx2, unsigned sy1, unsigned sy2, + unsigned dx1, unsigned dx2, unsigned dy1, unsigned dy2) +{ + return sx1 < dx2 && sx2 > dx1 && sy1 < dy2 && sy2 > dy1; +} + +void util_blitter_copy_region(struct blitter_context *blitter, + struct pipe_resource *dst, + unsigned dstlevel, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource *src, + unsigned srclevel, + const struct pipe_box *srcbox, + boolean ignore_stencil) +{ + struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; + struct pipe_context *pipe = ctx->base.pipe; + struct pipe_screen *screen = pipe->screen; + struct pipe_surface *dstsurf, surf_templ; + struct pipe_framebuffer_state fb_state; + struct pipe_sampler_view viewTempl, *view; + unsigned bind; + unsigned width = srcbox->width; + unsigned height = srcbox->height; + boolean is_stencil, is_depth; + boolean normalized; + + /* Give up if textures are not set. */ + assert(dst && src); + if (!dst || !src) + return; + + /* Sanity checks. */ + if (dst == src) { + assert(!is_overlap(srcbox->x, srcbox->x + width, srcbox->y, srcbox->y + height, + dstx, dstx + width, dsty, dsty + height)); + } else { + assert(util_is_format_compatible(util_format_description(dst->format), + util_format_description(src->format))); + } + assert(src->target < PIPE_MAX_TEXTURE_TYPES); + /* XXX should handle 3d regions */ + assert(srcbox->depth == 1); + + /* Is this a ZS format? */ + is_depth = util_format_get_component_bits(src->format, UTIL_FORMAT_COLORSPACE_ZS, 0) != 0; + is_stencil = util_format_get_component_bits(src->format, UTIL_FORMAT_COLORSPACE_ZS, 1) != 0; + + if (is_depth || is_stencil) + bind = PIPE_BIND_DEPTH_STENCIL; + else + bind = PIPE_BIND_RENDER_TARGET; + + /* Check if we can sample from and render to the surfaces. */ + /* (assuming copying a stencil buffer is not possible) */ + if ((!ignore_stencil && is_stencil) || + !screen->is_format_supported(screen, dst->format, dst->target, + dst->nr_samples, bind, 0) || + !screen->is_format_supported(screen, src->format, src->target, + src->nr_samples, PIPE_BIND_SAMPLER_VIEW, 0)) { + util_resource_copy_region(pipe, dst, dstlevel, dstx, dsty, dstz, + src, srclevel, srcbox); + return; + } + + /* Get surface. */ + memset(&surf_templ, 0, sizeof(surf_templ)); + u_surface_default_template(&surf_templ, dst, bind); + surf_templ.u.tex.level = dstlevel; + surf_templ.u.tex.first_layer = dstz; + surf_templ.u.tex.last_layer = dstz; + dstsurf = pipe->create_surface(pipe, dst, &surf_templ); + + /* Check whether the states are properly saved. */ + blitter_check_saved_CSOs(ctx); + assert(blitter->saved_fb_state.nr_cbufs != ~0); + assert(blitter->saved_num_sampler_views != ~0); + assert(blitter->saved_num_sampler_states != ~0); + + /* Initialize framebuffer state. */ + fb_state.width = dstsurf->width; + fb_state.height = dstsurf->height; + + if (is_depth) { + pipe->bind_blend_state(pipe, ctx->blend_keep_color); + pipe->bind_depth_stencil_alpha_state(pipe, + ctx->dsa_write_depth_keep_stencil); + pipe->bind_fs_state(pipe, + blitter_get_fs_texfetch_depth(ctx, src->target)); + + fb_state.nr_cbufs = 0; + fb_state.zsbuf = dstsurf; + } else { + pipe->bind_blend_state(pipe, ctx->blend_write_color); + pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil); + pipe->bind_fs_state(pipe, + blitter_get_fs_texfetch_col(ctx, src->target)); + + fb_state.nr_cbufs = 1; + fb_state.cbufs[0] = dstsurf; + fb_state.zsbuf = 0; + } + + normalized = src->target != PIPE_TEXTURE_RECT; + + /* Initialize sampler view. */ + u_sampler_view_default_template(&viewTempl, src, src->format); + view = pipe->create_sampler_view(pipe, src, &viewTempl); + + /* Set rasterizer state, shaders, and textures. */ + pipe->bind_rasterizer_state(pipe, ctx->rs_state); + pipe->bind_vs_state(pipe, ctx->vs); + pipe->bind_fragment_sampler_states(pipe, 1, + blitter_get_sampler_state(ctx, srclevel, normalized)); + pipe->bind_vertex_elements_state(pipe, ctx->velem_state); + pipe->set_fragment_sampler_views(pipe, 1, &view); + pipe->set_framebuffer_state(pipe, &fb_state); + + blitter_set_dst_dimensions(ctx, dstsurf->width, dstsurf->height); + + switch (src->target) { + /* Draw the quad with the draw_rectangle callback. */ + case PIPE_TEXTURE_1D: + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + { + /* Set texture coordinates. */ + float coord[4]; + get_texcoords(src, srclevel, srcbox->x, srcbox->y, + srcbox->x+width, srcbox->y+height, normalized, coord); + + /* Draw. */ + blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height, 0, + UTIL_BLITTER_ATTRIB_TEXCOORD, coord); + } + break; + + /* Draw the quad with the generic codepath. */ + case PIPE_TEXTURE_3D: + case PIPE_TEXTURE_CUBE: + /* Set texture coordinates. */ + if (src->target == PIPE_TEXTURE_3D) + blitter_set_texcoords_3d(ctx, src, srclevel, srcbox->z, + srcbox->x, srcbox->y, + srcbox->x + width, srcbox->y + height); + else + blitter_set_texcoords_cube(ctx, src, srclevel, srcbox->z, + srcbox->x, srcbox->y, + srcbox->x + width, srcbox->y + height); + + /* Draw. */ + blitter_set_rectangle(ctx, dstx, dsty, dstx+width, dsty+height, 0); + blitter_draw_quad(ctx); + break; + + default: + assert(0); + return; + } + + blitter_restore_CSOs(ctx); + + pipe_surface_reference(&dstsurf, NULL); + pipe_sampler_view_reference(&view, NULL); +} + +/* Clear a region of a color surface to a constant value. */ +void util_blitter_clear_render_target(struct blitter_context *blitter, + struct pipe_surface *dstsurf, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; + struct pipe_context *pipe = ctx->base.pipe; + struct pipe_framebuffer_state fb_state; + + assert(dstsurf->texture); + if (!dstsurf->texture) + return; + + /* check the saved state */ + blitter_check_saved_CSOs(ctx); + assert(blitter->saved_fb_state.nr_cbufs != ~0); + + /* bind CSOs */ + pipe->bind_blend_state(pipe, ctx->blend_write_color); + pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil); + pipe->bind_rasterizer_state(pipe, ctx->rs_state); + pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1)); + pipe->bind_vs_state(pipe, ctx->vs); + pipe->bind_vertex_elements_state(pipe, ctx->velem_state); + + /* set a framebuffer state */ + fb_state.width = dstsurf->width; + fb_state.height = dstsurf->height; + fb_state.nr_cbufs = 1; + fb_state.cbufs[0] = dstsurf; + fb_state.zsbuf = 0; + pipe->set_framebuffer_state(pipe, &fb_state); + + blitter_set_dst_dimensions(ctx, dstsurf->width, dstsurf->height); + blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height, 0, + UTIL_BLITTER_ATTRIB_COLOR, rgba); + blitter_restore_CSOs(ctx); +} + +/* Clear a region of a depth stencil surface. */ +void util_blitter_clear_depth_stencil(struct blitter_context *blitter, + struct pipe_surface *dstsurf, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; + struct pipe_context *pipe = ctx->base.pipe; + struct pipe_framebuffer_state fb_state; + struct pipe_stencil_ref sr = { { 0 } }; + + assert(dstsurf->texture); + if (!dstsurf->texture) + return; + + /* check the saved state */ + blitter_check_saved_CSOs(ctx); + assert(blitter->saved_fb_state.nr_cbufs != ~0); + + /* bind CSOs */ + pipe->bind_blend_state(pipe, ctx->blend_keep_color); + if ((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) == PIPE_CLEAR_DEPTHSTENCIL) { + sr.ref_value[0] = stencil & 0xff; + pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_write_depth_stencil); + pipe->set_stencil_ref(pipe, &sr); + } + else if (clear_flags & PIPE_CLEAR_DEPTH) { + pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_write_depth_keep_stencil); + } + else if (clear_flags & PIPE_CLEAR_STENCIL) { + sr.ref_value[0] = stencil & 0xff; + pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_write_stencil); + pipe->set_stencil_ref(pipe, &sr); + } + else + /* hmm that should be illegal probably, or make it a no-op somewhere */ + pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil); + + pipe->bind_rasterizer_state(pipe, ctx->rs_state); + pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0)); + pipe->bind_vs_state(pipe, ctx->vs); + pipe->bind_vertex_elements_state(pipe, ctx->velem_state); + + /* set a framebuffer state */ + fb_state.width = dstsurf->width; + fb_state.height = dstsurf->height; + fb_state.nr_cbufs = 0; + fb_state.cbufs[0] = 0; + fb_state.zsbuf = dstsurf; + pipe->set_framebuffer_state(pipe, &fb_state); + + blitter_set_dst_dimensions(ctx, dstsurf->width, dstsurf->height); + blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height, depth, + UTIL_BLITTER_ATTRIB_NONE, NULL); + blitter_restore_CSOs(ctx); +} + +/* draw a rectangle across a region using a custom dsa stage - for r600g */ +void util_blitter_custom_depth_stencil(struct blitter_context *blitter, + struct pipe_surface *zsurf, + struct pipe_surface *cbsurf, + void *dsa_stage, float depth) +{ + struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; + struct pipe_context *pipe = ctx->base.pipe; + struct pipe_framebuffer_state fb_state; + + assert(zsurf->texture); + if (!zsurf->texture) + return; + + /* check the saved state */ + blitter_check_saved_CSOs(ctx); + assert(blitter->saved_fb_state.nr_cbufs != ~0); + + /* bind CSOs */ + pipe->bind_blend_state(pipe, ctx->blend_write_color); + pipe->bind_depth_stencil_alpha_state(pipe, dsa_stage); + + pipe->bind_rasterizer_state(pipe, ctx->rs_state); + pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0)); + pipe->bind_vs_state(pipe, ctx->vs); + pipe->bind_vertex_elements_state(pipe, ctx->velem_state); + + /* set a framebuffer state */ + fb_state.width = zsurf->width; + fb_state.height = zsurf->height; + fb_state.nr_cbufs = 1; + if (cbsurf) { + fb_state.cbufs[0] = cbsurf; + fb_state.nr_cbufs = 1; + } else { + fb_state.cbufs[0] = NULL; + fb_state.nr_cbufs = 0; + } + fb_state.zsbuf = zsurf; + pipe->set_framebuffer_state(pipe, &fb_state); + + blitter_set_dst_dimensions(ctx, zsurf->width, zsurf->height); + blitter->draw_rectangle(blitter, 0, 0, zsurf->width, zsurf->height, depth, + UTIL_BLITTER_ATTRIB_NONE, NULL); + blitter_restore_CSOs(ctx); +} + +/* flush a region of a depth stencil surface for r300g */ +void util_blitter_flush_depth_stencil(struct blitter_context *blitter, + struct pipe_surface *dstsurf) +{ + struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; + util_blitter_custom_depth_stencil(blitter, dstsurf, NULL, + ctx->dsa_flush_depth_stencil, 0.0f); +} diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h new file mode 100644 index 0000000..c5660cf --- /dev/null +++ b/src/gallium/auxiliary/util/u_blitter.h @@ -0,0 +1,342 @@ +/************************************************************************** + * + * Copyright 2009 Marek Olšák + * + * 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. + * + **************************************************************************/ + +#ifndef U_BLITTER_H +#define U_BLITTER_H + +#include "util/u_framebuffer.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" + +#include "pipe/p_state.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +struct pipe_context; + +enum blitter_attrib_type { + UTIL_BLITTER_ATTRIB_NONE, + UTIL_BLITTER_ATTRIB_COLOR, + UTIL_BLITTER_ATTRIB_TEXCOORD +}; + +struct blitter_context +{ + /** + * Draw a rectangle. + * + * \param x1 An X coordinate of the top-left corner. + * \param y1 A Y coordinate of the top-left corner. + * \param x2 An X coordinate of the bottom-right corner. + * \param y2 A Y coordinate of the bottom-right corner. + * \param depth A depth which the rectangle is rendered at. + * + * \param type Semantics of the attributes "attrib". + * If type is UTIL_BLITTER_ATTRIB_NONE, ignore them. + * If type is UTIL_BLITTER_ATTRIB_COLOR, the attributes + * make up a constant RGBA color, and should go to the COLOR0 + * varying slot of a fragment shader. + * If type is UTIL_BLITTER_ATTRIB_TEXCOORD, {a1, a2} and + * {a3, a4} specify top-left and bottom-right texture + * coordinates of the rectangle, respectively, and should go + * to the GENERIC0 varying slot of a fragment shader. + * + * \param attrib See type. + * + * \note A driver may optionally override this callback to implement + * a specialized hardware path for drawing a rectangle, e.g. using + * a rectangular point sprite. + */ + void (*draw_rectangle)(struct blitter_context *blitter, + unsigned x1, unsigned y1, unsigned x2, unsigned y2, + float depth, + enum blitter_attrib_type type, + const float attrib[4]); + + /* Private members, really. */ + struct pipe_context *pipe; /**< pipe context */ + + void *saved_blend_state; /**< blend state */ + void *saved_dsa_state; /**< depth stencil alpha state */ + void *saved_velem_state; /**< vertex elements state */ + void *saved_rs_state; /**< rasterizer state */ + void *saved_fs, *saved_vs; /**< fragment shader, vertex shader */ + + struct pipe_framebuffer_state saved_fb_state; /**< framebuffer state */ + struct pipe_stencil_ref saved_stencil_ref; /**< stencil ref */ + struct pipe_viewport_state saved_viewport; + struct pipe_clip_state saved_clip; + + int saved_num_sampler_states; + void *saved_sampler_states[PIPE_MAX_SAMPLERS]; + + int saved_num_sampler_views; + struct pipe_sampler_view *saved_sampler_views[PIPE_MAX_SAMPLERS]; + + int saved_num_vertex_buffers; + struct pipe_vertex_buffer saved_vertex_buffers[PIPE_MAX_ATTRIBS]; +}; + +/** + * Create a blitter context. + */ +struct blitter_context *util_blitter_create(struct pipe_context *pipe); + +/** + * Destroy a blitter context. + */ +void util_blitter_destroy(struct blitter_context *blitter); + +/** + * Return the pipe context associated with a blitter context. + */ +static INLINE +struct pipe_context *util_blitter_get_pipe(struct blitter_context *blitter) +{ + return blitter->pipe; +} + +/* + * These CSOs must be saved before any of the following functions is called: + * - blend state + * - depth stencil alpha state + * - rasterizer state + * - vertex shader + * - fragment shader + */ + +/** + * Clear a specified set of currently bound buffers to specified values. + */ +void util_blitter_clear(struct blitter_context *blitter, + unsigned width, unsigned height, + unsigned num_cbufs, + unsigned clear_buffers, + const float *rgba, + double depth, unsigned stencil); + +/** + * Copy a block of pixels from one surface to another. + * + * You can copy from any color format to any other color format provided + * the former can be sampled and the latter can be rendered to. Otherwise, + * a software fallback path is taken and both surfaces must be of the same + * format. + * + * The same holds for depth-stencil formats with the exception that stencil + * cannot be copied unless you set ignore_stencil to FALSE. In that case, + * a software fallback path is taken and both surfaces must be of the same + * format. + * + * Use pipe_screen->is_format_supported to know your options. + * + * These states must be saved in the blitter in addition to the state objects + * already required to be saved: + * - framebuffer state + * - fragment sampler states + * - fragment sampler textures + */ +void util_blitter_copy_region(struct blitter_context *blitter, + struct pipe_resource *dst, + unsigned dstlevel, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource *src, + unsigned srclevel, + const struct pipe_box *srcbox, + boolean ignore_stencil); + +/** + * Clear a region of a (color) surface to a constant value. + * + * These states must be saved in the blitter in addition to the state objects + * already required to be saved: + * - framebuffer state + */ +void util_blitter_clear_render_target(struct blitter_context *blitter, + struct pipe_surface *dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height); + +/** + * Clear a region of a depth-stencil surface, both stencil and depth + * or only one of them if this is a combined depth-stencil surface. + * + * These states must be saved in the blitter in addition to the state objects + * already required to be saved: + * - framebuffer state + */ +void util_blitter_clear_depth_stencil(struct blitter_context *blitter, + struct pipe_surface *dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height); + +void util_blitter_flush_depth_stencil(struct blitter_context *blitter, + struct pipe_surface *dstsurf); + +void util_blitter_custom_depth_stencil(struct blitter_context *blitter, + struct pipe_surface *zsurf, + struct pipe_surface *cbsurf, + void *dsa_stage, float depth); + +/* The functions below should be used to save currently bound constant state + * objects inside a driver. The objects are automatically restored at the end + * of the util_blitter_{clear, copy_region, fill_region} functions and then + * forgotten. + * + * CSOs not listed here are not affected by util_blitter. */ + +static INLINE +void util_blitter_save_blend(struct blitter_context *blitter, + void *state) +{ + blitter->saved_blend_state = state; +} + +static INLINE +void util_blitter_save_depth_stencil_alpha(struct blitter_context *blitter, + void *state) +{ + blitter->saved_dsa_state = state; +} + +static INLINE +void util_blitter_save_vertex_elements(struct blitter_context *blitter, + void *state) +{ + blitter->saved_velem_state = state; +} + +static INLINE +void util_blitter_save_stencil_ref(struct blitter_context *blitter, + const struct pipe_stencil_ref *state) +{ + blitter->saved_stencil_ref = *state; +} + +static INLINE +void util_blitter_save_rasterizer(struct blitter_context *blitter, + void *state) +{ + blitter->saved_rs_state = state; +} + +static INLINE +void util_blitter_save_fragment_shader(struct blitter_context *blitter, + void *fs) +{ + blitter->saved_fs = fs; +} + +static INLINE +void util_blitter_save_vertex_shader(struct blitter_context *blitter, + void *vs) +{ + blitter->saved_vs = vs; +} + +static INLINE +void util_blitter_save_framebuffer(struct blitter_context *blitter, + const struct pipe_framebuffer_state *state) +{ + blitter->saved_fb_state.nr_cbufs = 0; /* It's ~0 now, meaning it's unsaved. */ + util_copy_framebuffer_state(&blitter->saved_fb_state, state); +} + +static INLINE +void util_blitter_save_viewport(struct blitter_context *blitter, + struct pipe_viewport_state *state) +{ + blitter->saved_viewport = *state; +} + +static INLINE +void util_blitter_save_clip(struct blitter_context *blitter, + struct pipe_clip_state *state) +{ + blitter->saved_clip = *state; +} + +static INLINE +void util_blitter_save_fragment_sampler_states( + struct blitter_context *blitter, + int num_sampler_states, + void **sampler_states) +{ + assert(num_sampler_states <= Elements(blitter->saved_sampler_states)); + + blitter->saved_num_sampler_states = num_sampler_states; + memcpy(blitter->saved_sampler_states, sampler_states, + num_sampler_states * sizeof(void *)); +} + +static INLINE void +util_blitter_save_fragment_sampler_views(struct blitter_context *blitter, + int num_views, + struct pipe_sampler_view **views) +{ + unsigned i; + assert(num_views <= Elements(blitter->saved_sampler_views)); + + blitter->saved_num_sampler_views = num_views; + for (i = 0; i < num_views; i++) + pipe_sampler_view_reference(&blitter->saved_sampler_views[i], + views[i]); +} + +static INLINE void +util_blitter_save_vertex_buffers(struct blitter_context *blitter, + int num_vertex_buffers, + struct pipe_vertex_buffer *vertex_buffers) +{ + unsigned i; + assert(num_vertex_buffers <= Elements(blitter->saved_vertex_buffers)); + + blitter->saved_num_vertex_buffers = num_vertex_buffers; + + for (i = 0; i < num_vertex_buffers; i++) { + if (vertex_buffers[i].buffer) { + pipe_resource_reference(&blitter->saved_vertex_buffers[i].buffer, + vertex_buffers[i].buffer); + } + } + + memcpy(blitter->saved_vertex_buffers, + vertex_buffers, + num_vertex_buffers * sizeof(struct pipe_vertex_buffer)); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/auxiliary/util/u_box.h b/src/gallium/auxiliary/util/u_box.h new file mode 100644 index 0000000..0b28d0f --- /dev/null +++ b/src/gallium/auxiliary/util/u_box.h @@ -0,0 +1,80 @@ +#ifndef UTIL_BOX_INLINES_H +#define UTIL_BOX_INLINES_H + +#include "pipe/p_state.h" + +static INLINE +void u_box_1d( unsigned x, + unsigned w, + struct pipe_box *box ) +{ + box->x = x; + box->y = 0; + box->z = 0; + box->width = w; + box->height = 1; + box->depth = 1; +} + +static INLINE +void u_box_2d( unsigned x, + unsigned y, + unsigned w, + unsigned h, + struct pipe_box *box ) +{ + box->x = x; + box->y = y; + box->z = 0; + box->width = w; + box->height = h; + box->depth = 1; +} + +static INLINE +void u_box_origin_2d( unsigned w, + unsigned h, + struct pipe_box *box ) +{ + box->x = 0; + box->y = 0; + box->z = 0; + box->width = w; + box->height = h; + box->depth = 1; +} + +static INLINE +void u_box_2d_zslice( unsigned x, + unsigned y, + unsigned z, + unsigned w, + unsigned h, + struct pipe_box *box ) +{ + box->x = x; + box->y = y; + box->z = z; + box->width = w; + box->height = h; + box->depth = 1; +} + +static INLINE +void u_box_3d( unsigned x, + unsigned y, + unsigned z, + unsigned w, + unsigned h, + unsigned d, + struct pipe_box *box ) +{ + box->x = x; + box->y = y; + box->z = z; + box->width = w; + box->height = h; + box->depth = d; +} + +#endif diff --git a/src/gallium/auxiliary/util/u_cache.c b/src/gallium/auxiliary/util/u_cache.c new file mode 100644 index 0000000..15f4a88 --- /dev/null +++ b/src/gallium/auxiliary/util/u_cache.c @@ -0,0 +1,217 @@ +/************************************************************************** + * + * Copyright 2008 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Simple cache implementation. + * + * We simply have fixed size array, and destroy previous values on collision. + * + * @author Jose Fonseca + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_cache.h" + + +struct util_cache_entry +{ + void *key; + void *value; + +#ifdef DEBUG + unsigned count; +#endif +}; + + +struct util_cache +{ + /** Hash function */ + uint32_t (*hash)(const void *key); + + /** Compare two keys */ + int (*compare)(const void *key1, const void *key2); + + /** Destroy a (key, value) pair */ + void (*destroy)(void *key, void *value); + + uint32_t size; + + struct util_cache_entry *entries; + +#ifdef DEBUG + unsigned count; +#endif +}; + + +struct util_cache * +util_cache_create(uint32_t (*hash)(const void *key), + int (*compare)(const void *key1, const void *key2), + void (*destroy)(void *key, void *value), + uint32_t size) +{ + struct util_cache *cache; + + cache = CALLOC_STRUCT(util_cache); + if(!cache) + return NULL; + + cache->hash = hash; + cache->compare = compare; + cache->destroy = destroy; + cache->size = size; + + cache->entries = CALLOC(size, sizeof(struct util_cache_entry)); + if(!cache->entries) { + FREE(cache); + return NULL; + } + + return cache; +} + + +static INLINE struct util_cache_entry * +util_cache_entry_get(struct util_cache *cache, + const void *key) +{ + uint32_t hash; + + hash = cache->hash(key); + + return &cache->entries[hash % cache->size]; +} + +static INLINE void +util_cache_entry_destroy(struct util_cache *cache, + struct util_cache_entry *entry) +{ + void *key = entry->key; + void *value = entry->value; + + entry->key = NULL; + entry->value = NULL; + + if(key || value) + if(cache->destroy) + cache->destroy(key, value); +} + + +void +util_cache_set(struct util_cache *cache, + void *key, + void *value) +{ + struct util_cache_entry *entry; + + assert(cache); + if (!cache) + return; + + entry = util_cache_entry_get(cache, key); + util_cache_entry_destroy(cache, entry); + +#ifdef DEBUG + ++entry->count; + ++cache->count; +#endif + + entry->key = key; + entry->value = value; +} + + +void * +util_cache_get(struct util_cache *cache, + const void *key) +{ + struct util_cache_entry *entry; + + assert(cache); + if (!cache) + return NULL; + + entry = util_cache_entry_get(cache, key); + if(!entry->key && !entry->value) + return NULL; + + if(cache->compare(key, entry->key) != 0) + return NULL; + + return entry->value; +} + + +void +util_cache_clear(struct util_cache *cache) +{ + uint32_t i; + + assert(cache); + if (!cache) + return; + + for(i = 0; i < cache->size; ++i) + util_cache_entry_destroy(cache, &cache->entries[i]); +} + + +void +util_cache_destroy(struct util_cache *cache) +{ + assert(cache); + if (!cache) + return; + +#ifdef DEBUG + if(cache->count >= 20*cache->size) { + /* Normal approximation of the Poisson distribution */ + double mean = (double)cache->count/(double)cache->size; + double stddev = sqrt(mean); + unsigned i; + for(i = 0; i < cache->size; ++i) { + double z = fabs(cache->entries[i].count - mean)/stddev; + /* This assert should not fail 99.9999998027% of the times, unless + * the hash function is a poor one */ + assert(z <= 6.0); + } + } +#endif + + util_cache_clear(cache); + + FREE(cache->entries); + FREE(cache); +} diff --git a/src/gallium/auxiliary/util/u_cache.h b/src/gallium/auxiliary/util/u_cache.h new file mode 100644 index 0000000..8a612c6 --- /dev/null +++ b/src/gallium/auxiliary/util/u_cache.h @@ -0,0 +1,87 @@ +/************************************************************************** + * + * Copyright 2008 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Simple cache. + * + * @author Jose Fonseca + */ + +#ifndef U_CACHE_H_ +#define U_CACHE_H_ + + +#include "pipe/p_compiler.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Least Recently Used (LRU) cache. + */ +struct util_cache; + + +/** + * Create a cache. + * + * @param hash hash function + * @param compare should return 0 for two equal keys + * @param destroy destruction callback (optional) + * @param size maximum number of entries + */ +struct util_cache * +util_cache_create(uint32_t (*hash)(const void *key), + int (*compare)(const void *key1, const void *key2), + void (*destroy)(void *key, void *value), + uint32_t size); + +void +util_cache_set(struct util_cache *cache, + void *key, + void *value); + +void * +util_cache_get(struct util_cache *cache, + const void *key); + +void +util_cache_clear(struct util_cache *cache); + +void +util_cache_destroy(struct util_cache *cache); + + +#ifdef __cplusplus +} +#endif + +#endif /* U_CACHE_H_ */ diff --git a/src/gallium/auxiliary/util/u_caps.c b/src/gallium/auxiliary/util/u_caps.c new file mode 100644 index 0000000..e209a98 --- /dev/null +++ b/src/gallium/auxiliary/util/u_caps.c @@ -0,0 +1,271 @@ +/************************************************************************** + * + * Copyright 2010 Vmware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "pipe/p_screen.h" +#include "util/u_format.h" +#include "util/u_debug.h" +#include "u_caps.h" + +/** + * Iterates over a list of caps checks as defined in u_caps.h. Should + * all checks pass returns TRUE and out is set to the last element of + * the list (TERMINATE). Should any check fail returns FALSE and set + * out to the index of the start of the first failing check. + */ +boolean +util_check_caps_out(struct pipe_screen *screen, const unsigned *list, int *out) +{ + int i, tmpi; + float tmpf; + + for (i = 0; list[i];) { + switch(list[i++]) { + case UTIL_CAPS_CHECK_CAP: + if (!screen->get_param(screen, list[i++])) { + *out = i - 2; + return FALSE; + } + break; + case UTIL_CAPS_CHECK_INT: + tmpi = screen->get_param(screen, list[i++]); + if (tmpi < (int)list[i++]) { + *out = i - 3; + return FALSE; + } + break; + case UTIL_CAPS_CHECK_FLOAT: + tmpf = screen->get_paramf(screen, list[i++]); + if (tmpf < (float)list[i++]) { + *out = i - 3; + return FALSE; + } + break; + case UTIL_CAPS_CHECK_FORMAT: + if (!screen->is_format_supported(screen, + list[i++], + PIPE_TEXTURE_2D, + 0, + PIPE_BIND_SAMPLER_VIEW, + 0)) { + *out = i - 2; + return FALSE; + } + break; + case UTIL_CAPS_CHECK_SHADER: + tmpi = screen->get_shader_param(screen, list[i] >> 24, list[i] & ((1 << 24) - 1)); + ++i; + if (tmpi < (int)list[i++]) { + *out = i - 3; + return FALSE; + } + break; + case UTIL_CAPS_CHECK_UNIMPLEMENTED: + *out = i - 1; + return FALSE; + default: + assert(!"Unsupported check"); + return FALSE; + } + } + + *out = i; + return TRUE; +} + +/** + * Iterates over a list of caps checks as defined in u_caps.h. + * Returns TRUE if all caps checks pass returns FALSE otherwise. + */ +boolean +util_check_caps(struct pipe_screen *screen, const unsigned *list) +{ + int out; + return util_check_caps_out(screen, list, &out); +} + + +/* + * Below follows some demo lists. + * + * None of these lists are exhausting lists of what is + * actually needed to support said API and more here for + * as example on how to uses the above functions. Especially + * for DX10 and DX11 where Gallium is missing features. + */ + +/* DX 9_1 */ +static unsigned caps_dx_9_1[] = { + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1), + UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */ + UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */ + UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */ + UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 2), + UTIL_CHECK_TERMINATE +}; + +/* DX 9_2 */ +static unsigned caps_dx_9_2[] = { + UTIL_CHECK_CAP(OCCLUSION_QUERY), + UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE), + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1), + UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */ + UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */ + UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */ + UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16), + UTIL_CHECK_TERMINATE +}; + +/* DX 9_3 */ +static unsigned caps_dx_9_3[] = { + UTIL_CHECK_CAP(SM3), + //UTIL_CHECK_CAP(INSTANCING), + UTIL_CHECK_CAP(OCCLUSION_QUERY), + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 4), + UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 13), /* 4096 */ + UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */ + UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */ + UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16), + UTIL_CHECK_TERMINATE +}; + +/* DX 10 */ +static unsigned caps_dx_10[] = { + UTIL_CHECK_CAP(SM3), + //UTIL_CHECK_CAP(INSTANCING), + UTIL_CHECK_CAP(OCCLUSION_QUERY), + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8), + UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 14), /* 8192 */ + UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 12), /* 2048 */ + UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 14), /* 8192 */ + UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16), + UTIL_CHECK_UNIMPLEMENTED, /* XXX Unimplemented features in Gallium */ + UTIL_CHECK_TERMINATE +}; + +/* DX11 */ +static unsigned caps_dx_11[] = { + UTIL_CHECK_CAP(SM3), + //UTIL_CHECK_CAP(INSTANCING), + UTIL_CHECK_CAP(OCCLUSION_QUERY), + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8), + UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 14), /* 16384 */ + UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 12), /* 2048 */ + UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 14), /* 16384 */ + UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16), + UTIL_CHECK_FORMAT(B8G8R8A8_UNORM), + UTIL_CHECK_UNIMPLEMENTED, /* XXX Unimplemented features in Gallium */ + UTIL_CHECK_TERMINATE +}; + +/* OpenGL 2.1 */ +static unsigned caps_opengl_2_1[] = { + UTIL_CHECK_CAP(GLSL), + UTIL_CHECK_CAP(OCCLUSION_QUERY), + UTIL_CHECK_CAP(TWO_SIDED_STENCIL), + UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE), + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 2), + UTIL_CHECK_TERMINATE +}; + +/* OpenGL 3.0 */ +/* UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8), */ + +/* Shader Model 3 */ +static unsigned caps_sm3[] = { + UTIL_CHECK_SHADER(FRAGMENT, MAX_INSTRUCTIONS, 512), + UTIL_CHECK_SHADER(FRAGMENT, MAX_INPUTS, 10), + UTIL_CHECK_SHADER(FRAGMENT, MAX_TEMPS, 32), + UTIL_CHECK_SHADER(FRAGMENT, MAX_ADDRS, 1), + UTIL_CHECK_SHADER(FRAGMENT, MAX_CONSTS, 224), + + UTIL_CHECK_SHADER(VERTEX, MAX_INSTRUCTIONS, 512), + UTIL_CHECK_SHADER(VERTEX, MAX_INPUTS, 16), + UTIL_CHECK_SHADER(VERTEX, MAX_TEMPS, 32), + UTIL_CHECK_SHADER(VERTEX, MAX_ADDRS, 2), + UTIL_CHECK_SHADER(VERTEX, MAX_CONSTS, 256), + + UTIL_CHECK_TERMINATE +}; + +/** + * Demo function which checks against theoretical caps needed for different APIs. + */ +void util_caps_demo_print(struct pipe_screen *screen) +{ + struct { + char* name; + unsigned *list; + } list[] = { + {"DX 9.1", caps_dx_9_1}, + {"DX 9.2", caps_dx_9_2}, + {"DX 9.3", caps_dx_9_3}, + {"DX 10", caps_dx_10}, + {"DX 11", caps_dx_11}, + {"OpenGL 2.1", caps_opengl_2_1}, +/* {"OpenGL 3.0", caps_opengl_3_0},*/ + {"SM3", caps_sm3}, + {NULL, NULL} + }; + int i, out = 0; + + for (i = 0; list[i].name; i++) { + if (util_check_caps_out(screen, list[i].list, &out)) { + debug_printf("%s: %s yes\n", __FUNCTION__, list[i].name); + continue; + } + switch (list[i].list[out]) { + case UTIL_CAPS_CHECK_CAP: + debug_printf("%s: %s no (cap %u not supported)\n", __FUNCTION__, + list[i].name, + list[i].list[out + 1]); + break; + case UTIL_CAPS_CHECK_INT: + debug_printf("%s: %s no (cap %u less then %u)\n", __FUNCTION__, + list[i].name, + list[i].list[out + 1], + list[i].list[out + 2]); + break; + case UTIL_CAPS_CHECK_FLOAT: + debug_printf("%s: %s no (cap %u less then %f)\n", __FUNCTION__, + list[i].name, + list[i].list[out + 1], + (double)(int)list[i].list[out + 2]); + break; + case UTIL_CAPS_CHECK_FORMAT: + debug_printf("%s: %s no (format %s not supported)\n", __FUNCTION__, + list[i].name, + util_format_name(list[i].list[out + 1]) + 12); + break; + case UTIL_CAPS_CHECK_UNIMPLEMENTED: + debug_printf("%s: %s no (not implemented in gallium or state tracker)\n", + __FUNCTION__, list[i].name); + break; + default: + assert(!"Unsupported check"); + } + } +} diff --git a/src/gallium/auxiliary/util/u_caps.h b/src/gallium/auxiliary/util/u_caps.h new file mode 100644 index 0000000..7bd2380 --- /dev/null +++ b/src/gallium/auxiliary/util/u_caps.h @@ -0,0 +1,71 @@ +/************************************************************************** + * + * Copyright 2010 Vmware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef U_CAPS_H +#define U_CAPS_H + +#include "pipe/p_compiler.h" + +struct pipe_screen; + +enum u_caps_check_enum { + UTIL_CAPS_CHECK_TERMINATE = 0, + UTIL_CAPS_CHECK_CAP, + UTIL_CAPS_CHECK_INT, + UTIL_CAPS_CHECK_FLOAT, + UTIL_CAPS_CHECK_FORMAT, + UTIL_CAPS_CHECK_SHADER, + UTIL_CAPS_CHECK_UNIMPLEMENTED, +}; + +#define UTIL_CHECK_CAP(cap) \ + UTIL_CAPS_CHECK_CAP, PIPE_CAP_##cap + +#define UTIL_CHECK_INT(cap, higher) \ + UTIL_CAPS_CHECK_INT, PIPE_CAP_##cap, (unsigned)(higher) + +/* Floats currently lose precision */ +#define UTIL_CHECK_FLOAT(cap, higher) \ + UTIL_CAPS_CHECK_FLOAT, PIPE_CAP_##cap, (unsigned)(int)(higher) + +#define UTIL_CHECK_FORMAT(format) \ + UTIL_CAPS_CHECK_FORMAT, PIPE_FORMAT_##format + +#define UTIL_CHECK_SHADER(shader, cap, higher) \ + UTIL_CAPS_CHECK_SHADER, (PIPE_SHADER_##shader << 24) | PIPE_SHADER_CAP_##cap, (unsigned)(higher) + +#define UTIL_CHECK_UNIMPLEMENTED \ + UTIL_CAPS_CHECK_UNIMPLEMENTED + +#define UTIL_CHECK_TERMINATE \ + UTIL_CAPS_CHECK_TERMINATE + +boolean util_check_caps(struct pipe_screen *screen, const unsigned *list); +boolean util_check_caps_out(struct pipe_screen *screen, const unsigned *list, int *out); +void util_caps_demo_print(struct pipe_screen *screen); + +#endif diff --git a/src/gallium/auxiliary/util/u_clear.h b/src/gallium/auxiliary/util/u_clear.h new file mode 100644 index 0000000..ad69df3 --- /dev/null +++ b/src/gallium/auxiliary/util/u_clear.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 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. + * + **************************************************************************/ + +/* Authors: + * Michel Dänzer + */ + + +#include "pipe/p_context.h" +#include "pipe/p_state.h" + + +/** + * Clear the given buffers to the specified values. + * No masking, no scissor (clear entire buffer). + */ +static INLINE void +util_clear(struct pipe_context *pipe, + struct pipe_framebuffer_state *framebuffer, unsigned buffers, + const float *rgba, double depth, unsigned stencil) +{ + if (buffers & PIPE_CLEAR_COLOR) { + unsigned i; + for (i = 0; i < framebuffer->nr_cbufs; i++) { + struct pipe_surface *ps = framebuffer->cbufs[i]; + pipe->clear_render_target(pipe, ps, rgba, 0, 0, ps->width, ps->height); + } + } + + if (buffers & PIPE_CLEAR_DEPTHSTENCIL) { + struct pipe_surface *ps = framebuffer->zsbuf; + pipe->clear_depth_stencil(pipe, ps, buffers & PIPE_CLEAR_DEPTHSTENCIL, + depth, stencil, + 0, 0, ps->width, ps->height); + } +} diff --git a/src/gallium/auxiliary/util/u_cpu_detect.c b/src/gallium/auxiliary/util/u_cpu_detect.c new file mode 100644 index 0000000..32519b1 --- /dev/null +++ b/src/gallium/auxiliary/util/u_cpu_detect.c @@ -0,0 +1,339 @@ +/************************************************************************** + * + * Copyright 2008 Dennis Smit + * 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 + * 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 + * AUTHORS, COPYRIGHT HOLDERS, 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. + * + **************************************************************************/ + +/** + * @file + * CPU feature detection. + * + * @author Dennis Smit + * @author Based on the work of Eric Anholt + */ + +#include "pipe/p_config.h" + +#include "u_debug.h" +#include "u_cpu_detect.h" + +#if defined(PIPE_ARCH_PPC) +#if defined(PIPE_OS_APPLE) +#include +#else +#include +#include +#endif +#endif + +#if defined(PIPE_OS_NETBSD) || defined(PIPE_OS_OPENBSD) +#include +#include +#include +#endif + +#if defined(PIPE_OS_FREEBSD) +#include +#include +#endif + +#if defined(PIPE_OS_LINUX) +#include +#endif + +#ifdef PIPE_OS_UNIX +#include +#endif + +#if defined(PIPE_OS_WINDOWS) +#include +#if defined(MSVC) +#include +#endif +#endif + + +#ifdef DEBUG +DEBUG_GET_ONCE_BOOL_OPTION(dump_cpu, "GALLIUM_DUMP_CPU", FALSE) +#endif + + +struct util_cpu_caps util_cpu_caps; + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) +static int has_cpuid(void); +#endif + + +#if defined(PIPE_ARCH_PPC) && !defined(PIPE_OS_APPLE) +static jmp_buf __lv_powerpc_jmpbuf; +static volatile sig_atomic_t __lv_powerpc_canjump = 0; + +static void +sigill_handler(int sig) +{ + if (!__lv_powerpc_canjump) { + signal (sig, SIG_DFL); + raise (sig); + } + + __lv_powerpc_canjump = 0; + longjmp(__lv_powerpc_jmpbuf, 1); +} +#endif + +#if defined(PIPE_ARCH_PPC) +static void +check_os_altivec_support(void) +{ +#if defined(PIPE_OS_APPLE) + int sels[2] = {CTL_HW, HW_VECTORUNIT}; + int has_vu = 0; + int len = sizeof (has_vu); + int err; + + err = sysctl(sels, 2, &has_vu, &len, NULL, 0); + + if (err == 0) { + if (has_vu != 0) { + util_cpu_caps.has_altivec = 1; + } + } +#else /* !PIPE_OS_APPLE */ + /* not on Apple/Darwin, do it the brute-force way */ + /* this is borrowed from the libmpeg2 library */ + signal(SIGILL, sigill_handler); + if (setjmp(__lv_powerpc_jmpbuf)) { + signal(SIGILL, SIG_DFL); + } else { + __lv_powerpc_canjump = 1; + + __asm __volatile + ("mtspr 256, %0\n\t" + "vand %%v0, %%v0, %%v0" + : + : "r" (-1)); + + signal(SIGILL, SIG_DFL); + util_cpu_caps.has_altivec = 1; + } +#endif /* !PIPE_OS_APPLE */ +} +#endif /* PIPE_ARCH_PPC */ + + +#if defined(PIPE_ARCH_X86) || defined (PIPE_ARCH_X86_64) +static int has_cpuid(void) +{ +#if defined(PIPE_ARCH_X86) +#if defined(PIPE_OS_GCC) + int a, c; + + __asm __volatile + ("pushf\n" + "popl %0\n" + "movl %0, %1\n" + "xorl $0x200000, %0\n" + "push %0\n" + "popf\n" + "pushf\n" + "popl %0\n" + : "=a" (a), "=c" (c) + : + : "cc"); + + return a != c; +#else + /* FIXME */ + return 1; +#endif +#elif defined(PIPE_ARCH_X86_64) + return 1; +#else + return 0; +#endif +} + + +/** + * @sa cpuid.h included in gcc-4.3 onwards. + * @sa http://msdn.microsoft.com/en-us/library/hskdteyh.aspx + */ +static INLINE void +cpuid(uint32_t ax, uint32_t *p) +{ +#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86) + __asm __volatile ( + "xchgl %%ebx, %1\n\t" + "cpuid\n\t" + "xchgl %%ebx, %1" + : "=a" (p[0]), + "=S" (p[1]), + "=c" (p[2]), + "=d" (p[3]) + : "0" (ax) + ); +#elif defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86_64) + __asm __volatile ( + "cpuid\n\t" + : "=a" (p[0]), + "=b" (p[1]), + "=c" (p[2]), + "=d" (p[3]) + : "0" (ax) + ); +#elif defined(PIPE_CC_MSVC) + __cpuid(p, ax); +#else + p[0] = 0; + p[1] = 0; + p[2] = 0; + p[3] = 0; +#endif +} +#endif /* X86 or X86_64 */ + +void +util_cpu_detect(void) +{ + static boolean util_cpu_detect_initialized = FALSE; + + if(util_cpu_detect_initialized) + return; + + memset(&util_cpu_caps, 0, sizeof util_cpu_caps); + + /* Count the number of CPUs in system */ +#if defined(PIPE_OS_WINDOWS) + { + SYSTEM_INFO system_info; + GetSystemInfo(&system_info); + util_cpu_caps.nr_cpus = system_info.dwNumberOfProcessors; + } +#elif defined(PIPE_OS_UNIX) && defined(_SC_NPROCESSORS_ONLN) + util_cpu_caps.nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); + if (util_cpu_caps.nr_cpus == -1) + util_cpu_caps.nr_cpus = 1; +#elif defined(PIPE_OS_BSD) + { + int mib[2], ncpu; + int len; + + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + + len = sizeof (ncpu); + sysctl(mib, 2, &ncpu, &len, NULL, 0); + util_cpu_caps.nr_cpus = ncpu; + } +#else + util_cpu_caps.nr_cpus = 1; +#endif + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) + if (has_cpuid()) { + uint32_t regs[4]; + uint32_t regs2[4]; + + util_cpu_caps.cacheline = 32; + + /* Get max cpuid level */ + cpuid(0x00000000, regs); + + if (regs[0] >= 0x00000001) { + unsigned int cacheline; + + cpuid (0x00000001, regs2); + + util_cpu_caps.x86_cpu_type = (regs2[0] >> 8) & 0xf; + if (util_cpu_caps.x86_cpu_type == 0xf) + util_cpu_caps.x86_cpu_type = 8 + ((regs2[0] >> 20) & 255); /* use extended family (P4, IA64) */ + + /* general feature flags */ + util_cpu_caps.has_tsc = (regs2[3] & (1 << 8 )) >> 8; /* 0x0000010 */ + util_cpu_caps.has_mmx = (regs2[3] & (1 << 23 )) >> 23; /* 0x0800000 */ + util_cpu_caps.has_sse = (regs2[3] & (1 << 25 )) >> 25; /* 0x2000000 */ + util_cpu_caps.has_sse2 = (regs2[3] & (1 << 26 )) >> 26; /* 0x4000000 */ + util_cpu_caps.has_sse3 = (regs2[2] & (1)); /* 0x0000001 */ + util_cpu_caps.has_ssse3 = (regs2[2] & (1 << 9 )) >> 9; /* 0x0000020 */ + util_cpu_caps.has_sse4_1 = (regs2[2] & (1 << 19)) >> 19; + util_cpu_caps.has_mmx2 = util_cpu_caps.has_sse; /* SSE cpus supports mmxext too */ + + cacheline = ((regs2[1] >> 8) & 0xFF) * 8; + if (cacheline > 0) + util_cpu_caps.cacheline = cacheline; + } + + cpuid(0x80000000, regs); + + if (regs[0] >= 0x80000001) { + + cpuid(0x80000001, regs2); + + util_cpu_caps.has_mmx |= (regs2[3] & (1 << 23 )) >> 23; /* 0x0800000 */ + util_cpu_caps.has_mmx2 |= (regs2[3] & (1 << 22 )) >> 22; /* 0x400000 */ + util_cpu_caps.has_3dnow = (regs2[3] & (1 << 31 )) >> 31; /* 0x80000000 */ + util_cpu_caps.has_3dnow_ext = (regs2[3] & (1 << 30 )) >> 30; + } + + if (regs[0] >= 0x80000006) { + cpuid(0x80000006, regs2); + util_cpu_caps.cacheline = regs2[2] & 0xFF; + } + + if (!util_cpu_caps.has_sse) { + util_cpu_caps.has_sse2 = 0; + util_cpu_caps.has_sse3 = 0; + util_cpu_caps.has_ssse3 = 0; + util_cpu_caps.has_sse4_1 = 0; + } + } +#endif /* PIPE_ARCH_X86 || PIPE_ARCH_X86_64 */ + +#if defined(PIPE_ARCH_PPC) + check_os_altivec_support(); +#endif /* PIPE_ARCH_PPC */ + +#ifdef DEBUG + if (debug_get_option_dump_cpu()) { + debug_printf("util_cpu_caps.nr_cpus = %u\n", util_cpu_caps.nr_cpus); + + debug_printf("util_cpu_caps.x86_cpu_type = %u\n", util_cpu_caps.x86_cpu_type); + debug_printf("util_cpu_caps.cacheline = %u\n", util_cpu_caps.cacheline); + + debug_printf("util_cpu_caps.has_tsc = %u\n", util_cpu_caps.has_tsc); + debug_printf("util_cpu_caps.has_mmx = %u\n", util_cpu_caps.has_mmx); + debug_printf("util_cpu_caps.has_mmx2 = %u\n", util_cpu_caps.has_mmx2); + debug_printf("util_cpu_caps.has_sse = %u\n", util_cpu_caps.has_sse); + debug_printf("util_cpu_caps.has_sse2 = %u\n", util_cpu_caps.has_sse2); + debug_printf("util_cpu_caps.has_sse3 = %u\n", util_cpu_caps.has_sse3); + debug_printf("util_cpu_caps.has_ssse3 = %u\n", util_cpu_caps.has_ssse3); + debug_printf("util_cpu_caps.has_sse4_1 = %u\n", util_cpu_caps.has_sse4_1); + debug_printf("util_cpu_caps.has_3dnow = %u\n", util_cpu_caps.has_3dnow); + debug_printf("util_cpu_caps.has_3dnow_ext = %u\n", util_cpu_caps.has_3dnow_ext); + debug_printf("util_cpu_caps.has_altivec = %u\n", util_cpu_caps.has_altivec); + } +#endif + + util_cpu_detect_initialized = TRUE; +} diff --git a/src/gallium/auxiliary/util/u_cpu_detect.h b/src/gallium/auxiliary/util/u_cpu_detect.h new file mode 100644 index 0000000..f3bef09 --- /dev/null +++ b/src/gallium/auxiliary/util/u_cpu_detect.h @@ -0,0 +1,67 @@ +/************************************************************************** + * + * Copyright 2008 Dennis Smit + * 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 + * 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 + * AUTHORS, COPYRIGHT HOLDERS, 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. + * + ***************************************************************************/ + +/** + * @file + * CPU feature detection. + * + * @author Dennis Smit + * @author Based on the work of Eric Anholt + */ + +#ifndef _UTIL_CPU_DETECT_H +#define _UTIL_CPU_DETECT_H + +#include "pipe/p_compiler.h" +#include "pipe/p_config.h" + +struct util_cpu_caps { + unsigned nr_cpus; + + /* Feature flags */ + int x86_cpu_type; + unsigned cacheline; + + unsigned has_tsc:1; + unsigned has_mmx:1; + unsigned has_mmx2:1; + unsigned has_sse:1; + unsigned has_sse2:1; + unsigned has_sse3:1; + unsigned has_ssse3:1; + unsigned has_sse4_1:1; + unsigned has_3dnow:1; + unsigned has_3dnow_ext:1; + unsigned has_altivec:1; +}; + +extern struct util_cpu_caps +util_cpu_caps; + +void util_cpu_detect(void); + + +#endif /* _UTIL_CPU_DETECT_H */ diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c new file mode 100644 index 0000000..2ad2f95 --- /dev/null +++ b/src/gallium/auxiliary/util/u_debug.c @@ -0,0 +1,661 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright (c) 2008 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 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. + * + **************************************************************************/ + + +#include "pipe/p_config.h" + +#include "pipe/p_compiler.h" +#include "os/os_stream.h" +#include "util/u_debug.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_string.h" +#include "util/u_math.h" +#include "util/u_tile.h" +#include "util/u_prim.h" +#include "util/u_surface.h" + +#include /* CHAR_BIT */ + +void _debug_vprintf(const char *format, va_list ap) +{ + /* We buffer until we find a newline. */ + static char buf[4096] = {'\0'}; + size_t len = strlen(buf); + int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap); + if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) { + os_log_message(buf); + buf[0] = '\0'; + } +} + + +#ifdef DEBUG +void debug_print_blob( const char *name, + const void *blob, + unsigned size ) +{ + const unsigned *ublob = (const unsigned *)blob; + unsigned i; + + debug_printf("%s (%d dwords%s)\n", name, size/4, + size%4 ? "... plus a few bytes" : ""); + + for (i = 0; i < size/4; i++) { + debug_printf("%d:\t%08x\n", i, ublob[i]); + } +} +#endif + + +static boolean +debug_get_option_should_print(void) +{ + static boolean first = TRUE; + static boolean value = FALSE; + + if (!first) + return value; + + /* Oh hey this will call into this function, + * but its cool since we set first to false + */ + first = FALSE; + value = debug_get_bool_option("GALLIUM_PRINT_OPTIONS", FALSE); + /* XXX should we print this option? Currently it wont */ + return value; +} + +const char * +debug_get_option(const char *name, const char *dfault) +{ + const char *result; + + result = os_get_option(name); + if(!result) + result = dfault; + + if (debug_get_option_should_print()) + debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? result : "(null)"); + + return result; +} + +boolean +debug_get_bool_option(const char *name, boolean dfault) +{ + const char *str = os_get_option(name); + boolean result; + + if(str == NULL) + result = dfault; + else if(!util_strcmp(str, "n")) + result = FALSE; + else if(!util_strcmp(str, "no")) + result = FALSE; + else if(!util_strcmp(str, "0")) + result = FALSE; + else if(!util_strcmp(str, "f")) + result = FALSE; + else if(!util_strcmp(str, "F")) + result = FALSE; + else if(!util_strcmp(str, "false")) + result = FALSE; + else if(!util_strcmp(str, "FALSE")) + result = FALSE; + else + result = TRUE; + + if (debug_get_option_should_print()) + debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? "TRUE" : "FALSE"); + + return result; +} + + +long +debug_get_num_option(const char *name, long dfault) +{ + long result; + const char *str; + + str = os_get_option(name); + if(!str) + result = dfault; + else { + long sign; + char c; + c = *str++; + if(c == '-') { + sign = -1; + c = *str++; + } + else { + sign = 1; + } + result = 0; + while('0' <= c && c <= '9') { + result = result*10 + (c - '0'); + c = *str++; + } + result *= sign; + } + + if (debug_get_option_should_print()) + debug_printf("%s: %s = %li\n", __FUNCTION__, name, result); + + return result; +} + + +unsigned long +debug_get_flags_option(const char *name, + const struct debug_named_value *flags, + unsigned long dfault) +{ + unsigned long result; + const char *str; + const struct debug_named_value *orig = flags; + int namealign = 0; + + str = os_get_option(name); + if(!str) + result = dfault; + else if (!util_strcmp(str, "help")) { + result = dfault; + _debug_printf("%s: help for %s:\n", __FUNCTION__, name); + for (; flags->name; ++flags) + namealign = MAX2(namealign, strlen(flags->name)); + for (flags = orig; flags->name; ++flags) + _debug_printf("| %*s [0x%0*lx]%s%s\n", namealign, flags->name, + (int)sizeof(unsigned long)*CHAR_BIT/4, flags->value, + flags->desc ? " " : "", flags->desc ? flags->desc : ""); + } + else { + result = 0; + while( flags->name ) { + if (!util_strcmp(str, "all") || util_strstr(str, flags->name )) + result |= flags->value; + ++flags; + } + } + + if (debug_get_option_should_print()) { + if (str) { + debug_printf("%s: %s = 0x%lx (%s)\n", __FUNCTION__, name, result, str); + } else { + debug_printf("%s: %s = 0x%lx\n", __FUNCTION__, name, result); + } + } + + return result; +} + + +void _debug_assert_fail(const char *expr, + const char *file, + unsigned line, + const char *function) +{ + _debug_printf("%s:%u:%s: Assertion `%s' failed.\n", file, line, function, expr); +#if defined(PIPE_OS_WINDOWS) && !defined(PIPE_SUBSYSTEM_WINDOWS_USER) + if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", FALSE)) +#else + if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", TRUE)) +#endif + os_abort(); + else + _debug_printf("continuing...\n"); +} + + +const char * +debug_dump_enum(const struct debug_named_value *names, + unsigned long value) +{ + static char rest[64]; + + while(names->name) { + if(names->value == value) + return names->name; + ++names; + } + + util_snprintf(rest, sizeof(rest), "0x%08lx", value); + return rest; +} + + +const char * +debug_dump_enum_noprefix(const struct debug_named_value *names, + const char *prefix, + unsigned long value) +{ + static char rest[64]; + + while(names->name) { + if(names->value == value) { + const char *name = names->name; + while (*name == *prefix) { + name++; + prefix++; + } + return name; + } + ++names; + } + + + + util_snprintf(rest, sizeof(rest), "0x%08lx", value); + return rest; +} + + +const char * +debug_dump_flags(const struct debug_named_value *names, + unsigned long value) +{ + static char output[4096]; + static char rest[256]; + int first = 1; + + output[0] = '\0'; + + while(names->name) { + if((names->value & value) == names->value) { + if (!first) + util_strncat(output, "|", sizeof(output)); + else + first = 0; + util_strncat(output, names->name, sizeof(output) - 1); + output[sizeof(output) - 1] = '\0'; + value &= ~names->value; + } + ++names; + } + + if (value) { + if (!first) + util_strncat(output, "|", sizeof(output)); + else + first = 0; + + util_snprintf(rest, sizeof(rest), "0x%08lx", value); + util_strncat(output, rest, sizeof(output) - 1); + output[sizeof(output) - 1] = '\0'; + } + + if(first) + return "0"; + + return output; +} + + +#ifdef DEBUG +void debug_print_format(const char *msg, unsigned fmt ) +{ + debug_printf("%s: %s\n", msg, util_format_name(fmt)); +} +#endif + + + +static const struct debug_named_value pipe_prim_names[] = { +#ifdef DEBUG + DEBUG_NAMED_VALUE(PIPE_PRIM_POINTS), + DEBUG_NAMED_VALUE(PIPE_PRIM_LINES), + DEBUG_NAMED_VALUE(PIPE_PRIM_LINE_LOOP), + DEBUG_NAMED_VALUE(PIPE_PRIM_LINE_STRIP), + DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLES), + DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLE_STRIP), + DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLE_FAN), + DEBUG_NAMED_VALUE(PIPE_PRIM_QUADS), + DEBUG_NAMED_VALUE(PIPE_PRIM_QUAD_STRIP), + DEBUG_NAMED_VALUE(PIPE_PRIM_POLYGON), +#endif + DEBUG_NAMED_VALUE_END +}; + + +const char *u_prim_name( unsigned prim ) +{ + return debug_dump_enum(pipe_prim_names, prim); +} + + + + +#ifdef DEBUG +/** + * Dump an image to a .raw or .ppm file (depends on OS). + * \param format PIPE_FORMAT_x + * \param cpp bytes per pixel + * \param width width in pixels + * \param height height in pixels + * \param stride row stride in bytes + */ +void debug_dump_image(const char *prefix, + unsigned format, unsigned cpp, + unsigned width, unsigned height, + unsigned stride, + const void *data) +{ +#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY + static unsigned no = 0; + char filename[256]; + WCHAR wfilename[sizeof(filename)]; + ULONG_PTR iFile = 0; + struct { + unsigned format; + unsigned cpp; + unsigned width; + unsigned height; + } header; + unsigned char *pMap = NULL; + unsigned i; + + util_snprintf(filename, sizeof(filename), "\\??\\c:\\%03u%s.raw", ++no, prefix); + for(i = 0; i < sizeof(filename); ++i) + wfilename[i] = (WCHAR)filename[i]; + + pMap = (unsigned char *)EngMapFile(wfilename, sizeof(header) + height*width*cpp, &iFile); + if(!pMap) + return; + + header.format = format; + header.cpp = cpp; + header.width = width; + header.height = height; + memcpy(pMap, &header, sizeof(header)); + pMap += sizeof(header); + + for(i = 0; i < height; ++i) { + memcpy(pMap, (unsigned char *)data + stride*i, cpp*width); + pMap += cpp*width; + } + + EngUnmapFile(iFile); +#elif defined(PIPE_OS_UNIX) + /* write a ppm file */ + char filename[256]; + FILE *f; + + util_snprintf(filename, sizeof(filename), "%s.ppm", prefix); + + f = fopen(filename, "w"); + if (f) { + int i, x, y; + int r, g, b; + const uint8_t *ptr = (uint8_t *) data; + + /* XXX this is a hack */ + switch (format) { + case PIPE_FORMAT_B8G8R8A8_UNORM: + r = 2; + g = 1; + b = 0; + break; + default: + r = 0; + g = 1; + b = 1; + } + + 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 = 0; y < height; y++) { + for (x = 0; x < width; x++) { + i = y * stride + x * cpp; + fputc(ptr[i + r], f); /* write red */ + fputc(ptr[i + g], f); /* write green */ + fputc(ptr[i + b], f); /* write blue */ + } + } + fclose(f); + } + else { + fprintf(stderr, "Can't open %s for writing\n", filename); + } +#endif +} + +/* FIXME: dump resources, not surfaces... */ +void debug_dump_surface(struct pipe_context *pipe, + const char *prefix, + struct pipe_surface *surface) +{ + struct pipe_resource *texture; + struct pipe_transfer *transfer; + void *data; + + if (!surface) + return; + + /* XXX: this doesn't necessarily work, as the driver may be using + * temporary storage for the surface which hasn't been propagated + * back into the texture. Need to nail down the semantics of views + * and transfers a bit better before we can say if extra work needs + * to be done here: + */ + texture = surface->texture; + + transfer = pipe_get_transfer(pipe, texture, surface->u.tex.level, + surface->u.tex.first_layer, + PIPE_TRANSFER_READ, + 0, 0, surface->width, surface->height); + + data = pipe->transfer_map(pipe, transfer); + if(!data) + goto error; + + debug_dump_image(prefix, + texture->format, + util_format_get_blocksize(texture->format), + util_format_get_nblocksx(texture->format, surface->width), + util_format_get_nblocksy(texture->format, surface->height), + transfer->stride, + data); + + pipe->transfer_unmap(pipe, transfer); +error: + pipe->transfer_destroy(pipe, transfer); +} + + +void debug_dump_texture(struct pipe_context *pipe, + const char *prefix, + struct pipe_resource *texture) +{ + struct pipe_surface *surface, surf_tmpl; + + if (!texture) + return; + + /* XXX for now, just dump image for layer=0, level=0 */ + memset(&surf_tmpl, 0, sizeof(surf_tmpl)); + u_surface_default_template(&surf_tmpl, texture, 0 /* no bind flag - not a surface */); + surface = pipe->create_surface(pipe, texture, &surf_tmpl); + if (surface) { + debug_dump_surface(pipe, prefix, surface); + pipe->surface_destroy(pipe, surface); + } +} + + +#pragma pack(push,2) +struct bmp_file_header { + uint16_t bfType; + uint32_t bfSize; + uint16_t bfReserved1; + uint16_t bfReserved2; + uint32_t bfOffBits; +}; +#pragma pack(pop) + +struct bmp_info_header { + uint32_t biSize; + int32_t biWidth; + int32_t biHeight; + uint16_t biPlanes; + uint16_t biBitCount; + uint32_t biCompression; + uint32_t biSizeImage; + int32_t biXPelsPerMeter; + int32_t biYPelsPerMeter; + uint32_t biClrUsed; + uint32_t biClrImportant; +}; + +struct bmp_rgb_quad { + uint8_t rgbBlue; + uint8_t rgbGreen; + uint8_t rgbRed; + uint8_t rgbAlpha; +}; + +void +debug_dump_surface_bmp(struct pipe_context *pipe, + const char *filename, + struct pipe_surface *surface) +{ +#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT + struct pipe_transfer *transfer; + struct pipe_resource *texture = surface->texture; + + transfer = pipe_get_transfer(pipe, texture, surface->u.tex.level, + surface->u.tex.first_layer, PIPE_TRANSFER_READ, + 0, 0, surface->width, surface->height); + + debug_dump_transfer_bmp(pipe, filename, transfer); + + pipe->transfer_destroy(pipe, transfer); +#endif +} + +void +debug_dump_transfer_bmp(struct pipe_context *pipe, + const char *filename, + struct pipe_transfer *transfer) +{ +#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT + float *rgba; + + if (!transfer) + goto error1; + + rgba = MALLOC(transfer->box.width * + transfer->box.height * + transfer->box.depth * + 4*sizeof(float)); + if(!rgba) + goto error1; + + pipe_get_tile_rgba(pipe, transfer, 0, 0, + transfer->box.width, transfer->box.height, + rgba); + + debug_dump_float_rgba_bmp(filename, + transfer->box.width, transfer->box.height, + rgba, transfer->box.width); + + FREE(rgba); +error1: + ; +#endif +} + +void +debug_dump_float_rgba_bmp(const char *filename, + unsigned width, unsigned height, + float *rgba, unsigned stride) +{ +#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT + struct os_stream *stream; + struct bmp_file_header bmfh; + struct bmp_info_header bmih; + unsigned x, y; + + if(!rgba) + goto error1; + + bmfh.bfType = 0x4d42; + bmfh.bfSize = 14 + 40 + height*width*4; + bmfh.bfReserved1 = 0; + bmfh.bfReserved2 = 0; + bmfh.bfOffBits = 14 + 40; + + bmih.biSize = 40; + bmih.biWidth = width; + bmih.biHeight = height; + bmih.biPlanes = 1; + bmih.biBitCount = 32; + bmih.biCompression = 0; + bmih.biSizeImage = height*width*4; + bmih.biXPelsPerMeter = 0; + bmih.biYPelsPerMeter = 0; + bmih.biClrUsed = 0; + bmih.biClrImportant = 0; + + stream = os_file_stream_create(filename); + if(!stream) + goto error1; + + os_stream_write(stream, &bmfh, 14); + os_stream_write(stream, &bmih, 40); + + y = height; + while(y--) { + float *ptr = rgba + (stride * y * 4); + for(x = 0; x < width; ++x) + { + struct bmp_rgb_quad pixel; + pixel.rgbRed = float_to_ubyte(ptr[x*4 + 0]); + pixel.rgbGreen = float_to_ubyte(ptr[x*4 + 1]); + pixel.rgbBlue = float_to_ubyte(ptr[x*4 + 2]); + pixel.rgbAlpha = 255; + os_stream_write(stream, &pixel, 4); + } + } + + os_stream_close(stream); +error1: + ; +#endif +} + +#endif diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h new file mode 100644 index 0000000..1c9624e --- /dev/null +++ b/src/gallium/auxiliary/util/u_debug.h @@ -0,0 +1,394 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Cross-platform debugging helpers. + * + * For now it just has assert and printf replacements, but it might be extended + * with stack trace reports and more advanced logging in the near future. + * + * @author Jose Fonseca + */ + +#ifndef U_DEBUG_H_ +#define U_DEBUG_H_ + + +#include "os/os_misc.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +#if defined(__GNUC__) +#define _util_printf_format(fmt, list) __attribute__ ((format (printf, fmt, list))) +#else +#define _util_printf_format(fmt, list) +#endif + +void _debug_vprintf(const char *format, va_list ap); + + +static INLINE void +_debug_printf(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + _debug_vprintf(format, ap); + va_end(ap); +} + + +/** + * Print debug messages. + * + * The actual channel used to output debug message is platform specific. To + * avoid misformating or truncation, follow these rules of thumb: + * - output whole lines + * - avoid outputing large strings (512 bytes is the current maximum length + * that is guaranteed to be printed in all platforms) + */ +#if !defined(PIPE_OS_HAIKU) +static INLINE void +debug_printf(const char *format, ...) _util_printf_format(1,2); + +static INLINE void +debug_printf(const char *format, ...) +{ +#ifdef DEBUG + va_list ap; + va_start(ap, format); + _debug_vprintf(format, ap); + va_end(ap); +#else + (void) format; /* silence warning */ +#endif +} + +#endif /* !PIPE_OS_HAIKU */ + +/* + * ... isn't portable so we need to pass arguments in parentheses. + * + * usage: + * debug_printf_once(("awnser: %i\n", 42)); + */ +#define debug_printf_once(args) \ + do { \ + static boolean once = TRUE; \ + if (once) { \ + once = FALSE; \ + debug_printf args; \ + } \ + } while (0) + + +#ifdef DEBUG +#define debug_vprintf(_format, _ap) _debug_vprintf(_format, _ap) +#else +#define debug_vprintf(_format, _ap) ((void)0) +#endif + + +#ifdef DEBUG +/** + * Dump a blob in hex to the same place that debug_printf sends its + * messages. + */ +void debug_print_blob( const char *name, const void *blob, unsigned size ); + +/* Print a message along with a prettified format string + */ +void debug_print_format(const char *msg, unsigned fmt ); +#else +#define debug_print_blob(_name, _blob, _size) ((void)0) +#define debug_print_format(_msg, _fmt) ((void)0) +#endif + + +/** + * Hard-coded breakpoint. + */ +#ifdef DEBUG +#define debug_break() os_break() +#else /* !DEBUG */ +#define debug_break() ((void)0) +#endif /* !DEBUG */ + + +long +debug_get_num_option(const char *name, long dfault); + +void _debug_assert_fail(const char *expr, + const char *file, + unsigned line, + const char *function); + + +/** + * Assert macro + * + * Do not expect that the assert call terminates -- errors must be handled + * regardless of assert behavior. + * + * For non debug builds the assert macro will expand to a no-op, so do not + * call functions with side effects in the assert expression. + */ +#ifdef DEBUG +#define debug_assert(expr) ((expr) ? (void)0 : _debug_assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__)) +#else +#define debug_assert(expr) do { } while (0 && (expr)) +#endif + + +/** Override standard assert macro */ +#ifdef assert +#undef assert +#endif +#define assert(expr) debug_assert(expr) + + +/** + * Output the current function name. + */ +#ifdef DEBUG +#define debug_checkpoint() \ + _debug_printf("%s\n", __FUNCTION__) +#else +#define debug_checkpoint() \ + ((void)0) +#endif + + +/** + * Output the full source code position. + */ +#ifdef DEBUG +#define debug_checkpoint_full() \ + _debug_printf("%s:%u:%s", __FILE__, __LINE__, __FUNCTION__) +#else +#define debug_checkpoint_full() \ + ((void)0) +#endif + + +/** + * Output a warning message. Muted on release version. + */ +#ifdef DEBUG +#define debug_warning(__msg) \ + _debug_printf("%s:%u:%s: warning: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg) +#else +#define debug_warning(__msg) \ + ((void)0) +#endif + + +/** + * Output an error message. Not muted on release version. + */ +#ifdef DEBUG +#define debug_error(__msg) \ + _debug_printf("%s:%u:%s: error: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg) +#else +#define debug_error(__msg) \ + _debug_printf("error: %s\n", __msg) +#endif + + +/** + * Used by debug_dump_enum and debug_dump_flags to describe symbols. + */ +struct debug_named_value +{ + const char *name; + unsigned long value; + const char *desc; +}; + + +/** + * Some C pre-processor magic to simplify creating named values. + * + * Example: + * @code + * static const debug_named_value my_names[] = { + * DEBUG_NAMED_VALUE(MY_ENUM_VALUE_X), + * DEBUG_NAMED_VALUE(MY_ENUM_VALUE_Y), + * DEBUG_NAMED_VALUE(MY_ENUM_VALUE_Z), + * DEBUG_NAMED_VALUE_END + * }; + * + * ... + * debug_printf("%s = %s\n", + * name, + * debug_dump_enum(my_names, my_value)); + * ... + * @endcode + */ +#define DEBUG_NAMED_VALUE(__symbol) DEBUG_NAMED_VALUE_WITH_DESCRIPTION(__symbol, NULL) +#define DEBUG_NAMED_VALUE_WITH_DESCRIPTION(__symbol, __desc) {#__symbol, (unsigned long)__symbol, __desc} +#define DEBUG_NAMED_VALUE_END {NULL, 0, NULL} + + +/** + * Convert a enum value to a string. + */ +const char * +debug_dump_enum(const struct debug_named_value *names, + unsigned long value); + +const char * +debug_dump_enum_noprefix(const struct debug_named_value *names, + const char *prefix, + unsigned long value); + + +/** + * Convert binary flags value to a string. + */ +const char * +debug_dump_flags(const struct debug_named_value *names, + unsigned long value); + + +/** + * Get option. + * + * It is an alias for getenv on Linux. + * + * On Windows it reads C:\gallium.cfg, which is a text file with CR+LF line + * endings with one option per line as + * + * NAME=value + * + * This file must be terminated with an extra empty line. + */ +const char * +debug_get_option(const char *name, const char *dfault); + +boolean +debug_get_bool_option(const char *name, boolean dfault); + +long +debug_get_num_option(const char *name, long dfault); + +unsigned long +debug_get_flags_option(const char *name, + const struct debug_named_value *flags, + unsigned long dfault); + +#define DEBUG_GET_ONCE_BOOL_OPTION(sufix, name, dfault) \ +static boolean \ +debug_get_option_ ## sufix (void) \ +{ \ + static boolean first = TRUE; \ + static boolean value; \ + if (first) { \ + first = FALSE; \ + value = debug_get_bool_option(name, dfault); \ + } \ + return value; \ +} + +#define DEBUG_GET_ONCE_NUM_OPTION(sufix, name, dfault) \ +static long \ +debug_get_option_ ## sufix (void) \ +{ \ + static boolean first = TRUE; \ + static long value; \ + if (first) { \ + first = FALSE; \ + value = debug_get_num_option(name, dfault); \ + } \ + return value; \ +} + +#define DEBUG_GET_ONCE_FLAGS_OPTION(sufix, name, flags, dfault) \ +static unsigned long \ +debug_get_option_ ## sufix (void) \ +{ \ + static boolean first = TRUE; \ + static unsigned long value; \ + if (first) { \ + first = FALSE; \ + value = debug_get_flags_option(name, flags, dfault); \ + } \ + return value; \ +} + + +unsigned long +debug_memory_begin(void); + +void +debug_memory_end(unsigned long beginning); + + +#ifdef DEBUG +struct pipe_context; +struct pipe_surface; +struct pipe_transfer; +struct pipe_resource; + +void debug_dump_image(const char *prefix, + unsigned format, unsigned cpp, + unsigned width, unsigned height, + unsigned stride, + const void *data); +void debug_dump_surface(struct pipe_context *pipe, + const char *prefix, + struct pipe_surface *surface); +void debug_dump_texture(struct pipe_context *pipe, + const char *prefix, + struct pipe_resource *texture); +void debug_dump_surface_bmp(struct pipe_context *pipe, + const char *filename, + struct pipe_surface *surface); +void debug_dump_transfer_bmp(struct pipe_context *pipe, + const char *filename, + struct pipe_transfer *transfer); +void debug_dump_float_rgba_bmp(const char *filename, + unsigned width, unsigned height, + float *rgba, unsigned stride); +#else +#define debug_dump_image(prefix, format, cpp, width, height, stride, data) ((void)0) +#define debug_dump_surface(pipe, prefix, surface) ((void)0) +#define debug_dump_surface_bmp(pipe, filename, surface) ((void)0) +#define debug_dump_transfer_bmp(filename, transfer) ((void)0) +#define debug_dump_float_rgba_bmp(filename, width, height, rgba, stride) ((void)0) +#endif + + +#ifdef __cplusplus +} +#endif + +#endif /* U_DEBUG_H_ */ diff --git a/src/gallium/auxiliary/util/u_debug_describe.c b/src/gallium/auxiliary/util/u_debug_describe.c new file mode 100644 index 0000000..7ed8ee6 --- /dev/null +++ b/src/gallium/auxiliary/util/u_debug_describe.c @@ -0,0 +1,81 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include +#include +#include +#include + +void +debug_describe_reference(char* buf, const struct pipe_reference*ptr) +{ + strcpy(buf, "pipe_object"); +} + +void +debug_describe_resource(char* buf, const struct pipe_resource *ptr) +{ + switch(ptr->target) + { + case PIPE_BUFFER: + util_sprintf(buf, "pipe_buffer<%u>", (unsigned)util_format_get_stride(ptr->format, ptr->width0)); + break; + case PIPE_TEXTURE_1D: + util_sprintf(buf, "pipe_texture1d<%u,%s,%u>", ptr->width0, util_format_short_name(ptr->format), ptr->last_level); + break; + case PIPE_TEXTURE_2D: + util_sprintf(buf, "pipe_texture2d<%u,%u,%s,%u>", ptr->width0, ptr->height0, util_format_short_name(ptr->format), ptr->last_level); + break; + case PIPE_TEXTURE_RECT: + util_sprintf(buf, "pipe_texture_rect<%u,%u,%s>", ptr->width0, ptr->height0, util_format_short_name(ptr->format)); + break; + case PIPE_TEXTURE_CUBE: + util_sprintf(buf, "pipe_texture_cube<%u,%u,%s,%u>", ptr->width0, ptr->height0, util_format_short_name(ptr->format), ptr->last_level); + break; + case PIPE_TEXTURE_3D: + util_sprintf(buf, "pipe_texture3d<%u,%u,%u,%s,%u>", ptr->width0, ptr->height0, ptr->depth0, util_format_short_name(ptr->format), ptr->last_level); + break; + default: + util_sprintf(buf, "pipe_martian_resource<%u>", ptr->target); + break; + } +} + +void +debug_describe_surface(char* buf, const struct pipe_surface *ptr) +{ + char res[128]; + debug_describe_resource(res, ptr->texture); + util_sprintf(buf, "pipe_surface<%s,%u,%u,%u>", res, ptr->u.tex.level, ptr->u.tex.first_layer, ptr->u.tex.last_layer); +} + +void +debug_describe_sampler_view(char* buf, const struct pipe_sampler_view *ptr) +{ + char res[128]; + debug_describe_resource(res, ptr->texture); + util_sprintf(buf, "pipe_sampler_view<%s,%s>", res, util_format_short_name(ptr->format)); +} diff --git a/src/gallium/auxiliary/util/u_debug_describe.h b/src/gallium/auxiliary/util/u_debug_describe.h new file mode 100644 index 0000000..26d1f80 --- /dev/null +++ b/src/gallium/auxiliary/util/u_debug_describe.h @@ -0,0 +1,49 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef U_DEBUG_DESCRIBE_H_ +#define U_DEBUG_DESCRIBE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +struct pipe_reference; +struct pipe_resource; +struct pipe_surface; +struct pipe_sampler_view; + +/* a 256-byte buffer is necessary and sufficient */ +void debug_describe_reference(char* buf, const struct pipe_reference*ptr); +void debug_describe_resource(char* buf, const struct pipe_resource *ptr); +void debug_describe_surface(char* buf, const struct pipe_surface *ptr); +void debug_describe_sampler_view(char* buf, const struct pipe_sampler_view *ptr); + +#ifdef __cplusplus +} +#endif + +#endif /* U_DEBUG_DESCRIBE_H_ */ diff --git a/src/gallium/auxiliary/util/u_debug_memory.c b/src/gallium/auxiliary/util/u_debug_memory.c new file mode 100644 index 0000000..f1baa62 --- /dev/null +++ b/src/gallium/auxiliary/util/u_debug_memory.c @@ -0,0 +1,307 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Memory debugging. + * + * @author José Fonseca + */ + +#include "pipe/p_config.h" + +#define DEBUG_MEMORY_IMPLEMENTATION + +#include "os/os_memory.h" +#include "os/os_memory_debug.h" + +#include "util/u_debug.h" +#include "util/u_debug_stack.h" +#include "util/u_double_list.h" + + +#define DEBUG_MEMORY_MAGIC 0x6e34090aU +#define DEBUG_MEMORY_STACK 0 /* XXX: disabled until we have symbol lookup */ + + +struct debug_memory_header +{ + struct list_head head; + + unsigned long no; + const char *file; + unsigned line; + const char *function; +#if DEBUG_MEMORY_STACK + struct debug_stack_frame backtrace[DEBUG_MEMORY_STACK]; +#endif + size_t size; + + unsigned magic; +}; + +struct debug_memory_footer +{ + unsigned magic; +}; + + +static struct list_head list = { &list, &list }; + +static unsigned long last_no = 0; + + +static INLINE struct debug_memory_header * +header_from_data(void *data) +{ + if(data) + return (struct debug_memory_header *)((char *)data - sizeof(struct debug_memory_header)); + else + return NULL; +} + +static INLINE void * +data_from_header(struct debug_memory_header *hdr) +{ + if(hdr) + return (void *)((char *)hdr + sizeof(struct debug_memory_header)); + else + return NULL; +} + +static INLINE struct debug_memory_footer * +footer_from_header(struct debug_memory_header *hdr) +{ + if(hdr) + return (struct debug_memory_footer *)((char *)hdr + sizeof(struct debug_memory_header) + hdr->size); + else + return NULL; +} + + +void * +debug_malloc(const char *file, unsigned line, const char *function, + size_t size) +{ + struct debug_memory_header *hdr; + struct debug_memory_footer *ftr; + + hdr = os_malloc(sizeof(*hdr) + size + sizeof(*ftr)); + if(!hdr) { + debug_printf("%s:%u:%s: out of memory when trying to allocate %lu bytes\n", + file, line, function, + (long unsigned)size); + return NULL; + } + + hdr->no = last_no++; + hdr->file = file; + hdr->line = line; + hdr->function = function; + hdr->size = size; + hdr->magic = DEBUG_MEMORY_MAGIC; + +#if DEBUG_MEMORY_STACK + debug_backtrace_capture(hdr->backtrace, 0, DEBUG_MEMORY_STACK); +#endif + + ftr = footer_from_header(hdr); + ftr->magic = DEBUG_MEMORY_MAGIC; + + LIST_ADDTAIL(&hdr->head, &list); + + return data_from_header(hdr); +} + +void +debug_free(const char *file, unsigned line, const char *function, + void *ptr) +{ + struct debug_memory_header *hdr; + struct debug_memory_footer *ftr; + + if(!ptr) + return; + + hdr = header_from_data(ptr); + if(hdr->magic != DEBUG_MEMORY_MAGIC) { + debug_printf("%s:%u:%s: freeing bad or corrupted memory %p\n", + file, line, function, + ptr); + debug_assert(0); + return; + } + + ftr = footer_from_header(hdr); + if(ftr->magic != DEBUG_MEMORY_MAGIC) { + debug_printf("%s:%u:%s: buffer overflow %p\n", + hdr->file, hdr->line, hdr->function, + ptr); + debug_assert(0); + } + + LIST_DEL(&hdr->head); + hdr->magic = 0; + ftr->magic = 0; + + os_free(hdr); +} + +void * +debug_calloc(const char *file, unsigned line, const char *function, + size_t count, size_t size ) +{ + void *ptr = debug_malloc( file, line, function, count * size ); + if( ptr ) + memset( ptr, 0, count * size ); + return ptr; +} + +void * +debug_realloc(const char *file, unsigned line, const char *function, + void *old_ptr, size_t old_size, size_t new_size ) +{ + struct debug_memory_header *old_hdr, *new_hdr; + struct debug_memory_footer *old_ftr, *new_ftr; + void *new_ptr; + + if(!old_ptr) + return debug_malloc( file, line, function, new_size ); + + if(!new_size) { + debug_free( file, line, function, old_ptr ); + return NULL; + } + + old_hdr = header_from_data(old_ptr); + if(old_hdr->magic != DEBUG_MEMORY_MAGIC) { + debug_printf("%s:%u:%s: reallocating bad or corrupted memory %p\n", + file, line, function, + old_ptr); + debug_assert(0); + return NULL; + } + + old_ftr = footer_from_header(old_hdr); + if(old_ftr->magic != DEBUG_MEMORY_MAGIC) { + debug_printf("%s:%u:%s: buffer overflow %p\n", + old_hdr->file, old_hdr->line, old_hdr->function, + old_ptr); + debug_assert(0); + } + + /* alloc new */ + new_hdr = os_malloc(sizeof(*new_hdr) + new_size + sizeof(*new_ftr)); + if(!new_hdr) { + debug_printf("%s:%u:%s: out of memory when trying to allocate %lu bytes\n", + file, line, function, + (long unsigned)new_size); + return NULL; + } + new_hdr->no = old_hdr->no; + new_hdr->file = old_hdr->file; + new_hdr->line = old_hdr->line; + new_hdr->function = old_hdr->function; + new_hdr->size = new_size; + new_hdr->magic = DEBUG_MEMORY_MAGIC; + + new_ftr = footer_from_header(new_hdr); + new_ftr->magic = DEBUG_MEMORY_MAGIC; + + LIST_REPLACE(&old_hdr->head, &new_hdr->head); + + /* copy data */ + new_ptr = data_from_header(new_hdr); + memcpy( new_ptr, old_ptr, old_size < new_size ? old_size : new_size ); + + /* free old */ + old_hdr->magic = 0; + old_ftr->magic = 0; + os_free(old_hdr); + + return new_ptr; +} + +unsigned long +debug_memory_begin(void) +{ + return last_no; +} + +void +debug_memory_end(unsigned long start_no) +{ + size_t total_size = 0; + struct list_head *entry; + + if(start_no == last_no) + return; + + entry = list.prev; + for (; entry != &list; entry = entry->prev) { + struct debug_memory_header *hdr; + void *ptr; + struct debug_memory_footer *ftr; + + hdr = LIST_ENTRY(struct debug_memory_header, entry, head); + ptr = data_from_header(hdr); + ftr = footer_from_header(hdr); + + if(hdr->magic != DEBUG_MEMORY_MAGIC) { + debug_printf("%s:%u:%s: bad or corrupted memory %p\n", + hdr->file, hdr->line, hdr->function, + ptr); + debug_assert(0); + } + + if((start_no <= hdr->no && hdr->no < last_no) || + (last_no < start_no && (hdr->no < last_no || start_no <= hdr->no))) { + debug_printf("%s:%u:%s: %lu bytes at %p not freed\n", + hdr->file, hdr->line, hdr->function, + (unsigned long) hdr->size, ptr); +#if DEBUG_MEMORY_STACK + debug_backtrace_dump(hdr->backtrace, DEBUG_MEMORY_STACK); +#endif + total_size += hdr->size; + } + + if(ftr->magic != DEBUG_MEMORY_MAGIC) { + debug_printf("%s:%u:%s: buffer overflow %p\n", + hdr->file, hdr->line, hdr->function, + ptr); + debug_assert(0); + } + } + + if(total_size) { + debug_printf("Total of %lu KB of system memory apparently leaked\n", + (unsigned long) (total_size + 1023)/1024); + } + else { + debug_printf("No memory leaks detected.\n"); + } +} diff --git a/src/gallium/auxiliary/util/u_debug_refcnt.c b/src/gallium/auxiliary/util/u_debug_refcnt.c new file mode 100644 index 0000000..40a26c9 --- /dev/null +++ b/src/gallium/auxiliary/util/u_debug_refcnt.c @@ -0,0 +1,181 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#if defined(DEBUG) && (!defined(PIPE_OS_WINDOWS) || defined(PIPE_SUBSYSTEM_WINDOWS_USER)) + +/* see http://www.mozilla.org/performance/refcnt-balancer.html for what do with the output + * on Linux, use tools/addr2line.sh to postprocess it before anything else + **/ +#include +#include +#include +#include +#include +#include +#include +#include + +int debug_refcnt_state; + +struct os_stream* stream; + +/* TODO: maybe move this serial machinery to a stand-alone module and expose it? */ +static pipe_mutex serials_mutex; +static struct util_hash_table* serials_hash; +static unsigned serials_last; + +static unsigned hash_ptr(void* p) +{ + return (unsigned)(uintptr_t)p; +} + +static int compare_ptr(void* a, void* b) +{ + if(a == b) + return 0; + else if(a < b) + return -1; + else + return 1; +} + +static boolean debug_serial(void* p, unsigned* pserial) +{ + unsigned serial; + boolean found = TRUE; + pipe_mutex_lock(serials_mutex); + if(!serials_hash) + serials_hash = util_hash_table_create(hash_ptr, compare_ptr); + serial = (unsigned)(uintptr_t)util_hash_table_get(serials_hash, p); + if(!serial) + { + /* time to stop logging... (you'll have a 100 GB logfile at least at this point) + * TODO: avoid this + */ + serial = ++serials_last; + if(!serial) + { + debug_error("More than 2^32 objects detected, aborting.\n"); + os_abort(); + } + + util_hash_table_set(serials_hash, p, (void*)(uintptr_t)serial); + found = FALSE; + } + pipe_mutex_unlock(serials_mutex); + *pserial = serial; + return found; +} + +static void debug_serial_delete(void* p) +{ + pipe_mutex_lock(serials_mutex); + util_hash_table_remove(serials_hash, p); + pipe_mutex_unlock(serials_mutex); +} + +#define STACK_LEN 64 + +static void dump_stack(const char* symbols[STACK_LEN]) +{ + unsigned i; + for(i = 0; i < STACK_LEN; ++i) + { + if(symbols[i]) + os_stream_printf(stream, "%s\n", symbols[i]); + } + os_stream_write(stream, "\n", 1); +} + +void debug_reference_slowpath(const struct pipe_reference* p, debug_reference_descriptor get_desc, int change) +{ + if(debug_refcnt_state < 0) + return; + + if(!debug_refcnt_state) + { + const char* filename = debug_get_option("GALLIUM_REFCNT_LOG", NULL); + if(filename && filename[0]) + stream = os_file_stream_create(filename); + + if(stream) + debug_refcnt_state = 1; + else + debug_refcnt_state = -1; + } + + if(debug_refcnt_state > 0) + { + struct debug_stack_frame frames[STACK_LEN]; + const char* symbols[STACK_LEN]; + char buf[1024]; + + unsigned i; + unsigned refcnt = p->count; + unsigned serial; + boolean existing = debug_serial((void*)p, &serial); + + debug_backtrace_capture(frames, 1, STACK_LEN); + for(i = 0; i < STACK_LEN; ++i) + { + if(frames[i].function) + symbols[i] = debug_symbol_name_cached(frames[i].function); + else + symbols[i] = 0; + } + + get_desc(buf, p); + + if(!existing) + { + os_stream_printf(stream, "<%s> %p %u Create\n", buf, p, serial); + dump_stack(symbols); + + /* this is there to provide a gradual change even if we don't see the initialization */ + for(i = 1; i <= refcnt - change; ++i) + { + os_stream_printf(stream, "<%s> %p %u AddRef %u\n", buf, p, serial, i); + dump_stack(symbols); + } + } + + if(change) + { + os_stream_printf(stream, "<%s> %p %u %s %u\n", buf, p, serial, change > 0 ? "AddRef" : "Release", refcnt); + dump_stack(symbols); + } + + if(!refcnt) + { + debug_serial_delete((void*)p); + os_stream_printf(stream, "<%s> %p %u Destroy\n", buf, p, serial); + dump_stack(symbols); + } + + os_stream_flush(stream); + } +} +#endif diff --git a/src/gallium/auxiliary/util/u_debug_refcnt.h b/src/gallium/auxiliary/util/u_debug_refcnt.h new file mode 100644 index 0000000..bea2d1c --- /dev/null +++ b/src/gallium/auxiliary/util/u_debug_refcnt.h @@ -0,0 +1,63 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef U_DEBUG_REFCNT_H_ +#define U_DEBUG_REFCNT_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*debug_reference_descriptor)(char*, const struct pipe_reference*); + +#if defined(DEBUG) && (!defined(PIPE_OS_WINDOWS) || defined(PIPE_SUBSYSTEM_WINDOWS_USER)) + +extern int debug_refcnt_state; + +void debug_reference_slowpath(const struct pipe_reference* p, debug_reference_descriptor get_desc, int change); + +static INLINE void debug_reference(const struct pipe_reference* p, debug_reference_descriptor get_desc, int change) +{ + if (debug_refcnt_state >= 0) + debug_reference_slowpath(p, get_desc, change); +} + +#else + +static INLINE void debug_reference(const struct pipe_reference* p, debug_reference_descriptor get_desc, int change) +{ +} + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* U_DEBUG_REFCNT_H_ */ diff --git a/src/gallium/auxiliary/util/u_debug_stack.c b/src/gallium/auxiliary/util/u_debug_stack.c new file mode 100644 index 0000000..24e039f --- /dev/null +++ b/src/gallium/auxiliary/util/u_debug_stack.c @@ -0,0 +1,110 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Stack backtracing. + * + * @author Jose Fonseca + */ + +#include "u_debug.h" +#include "u_debug_symbol.h" +#include "u_debug_stack.h" + + +void +debug_backtrace_capture(struct debug_stack_frame *backtrace, + unsigned start_frame, + unsigned nr_frames) +{ + const void **frame_pointer = NULL; + unsigned i = 0; + + if(!nr_frames) + return; + +#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86) + __asm__ __volatile__("mov (%%ebp),%0": "=r" (frame_pointer)); + frame_pointer = (const void **)frame_pointer[0]; +#elif defined(PIPE_CC_GCC) + frame_pointer = ((const void **)__builtin_frame_address(1)); +#elif defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86) + __asm { + mov frame_pointer, ebp + } + frame_pointer = (const void **)frame_pointer[0]; +#else + frame_pointer = NULL; +#endif + + +#ifdef PIPE_ARCH_X86 + while(nr_frames) { + const void **next_frame_pointer; + + if(!frame_pointer) + break; + + if(start_frame) + --start_frame; + else { + backtrace[i++].function = frame_pointer[1]; + --nr_frames; + } + + next_frame_pointer = (const void **)frame_pointer[0]; + + /* Limit the stack walk to avoid referencing undefined memory */ + if((uintptr_t)next_frame_pointer <= (uintptr_t)frame_pointer || + (uintptr_t)next_frame_pointer > (uintptr_t)frame_pointer + 64*1024) + break; + + frame_pointer = next_frame_pointer; + } +#endif + + while(nr_frames) { + backtrace[i++].function = NULL; + --nr_frames; + } +} + + +void +debug_backtrace_dump(const struct debug_stack_frame *backtrace, + unsigned nr_frames) +{ + unsigned i; + + for(i = 0; i < nr_frames; ++i) { + if(!backtrace[i].function) + break; + debug_symbol_print(backtrace[i].function); + } +} + diff --git a/src/gallium/auxiliary/util/u_debug_stack.h b/src/gallium/auxiliary/util/u_debug_stack.h new file mode 100644 index 0000000..f50f04e --- /dev/null +++ b/src/gallium/auxiliary/util/u_debug_stack.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, 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 U_DEBUG_STACK_H_ +#define U_DEBUG_STACK_H_ + + +/** + * @file + * Stack backtracing. + * + * @author Jose Fonseca + */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct debug_stack_frame +{ + const void *function; +}; + + +void +debug_backtrace_capture(struct debug_stack_frame *backtrace, + unsigned start_frame, + unsigned nr_frames); + +void +debug_backtrace_dump(const struct debug_stack_frame *backtrace, + unsigned nr_frames); + + +#ifdef __cplusplus +} +#endif + +#endif /* U_DEBUG_STACK_H_ */ diff --git a/src/gallium/auxiliary/util/u_debug_symbol.c b/src/gallium/auxiliary/util/u_debug_symbol.c new file mode 100644 index 0000000..44d4377 --- /dev/null +++ b/src/gallium/auxiliary/util/u_debug_symbol.c @@ -0,0 +1,228 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Symbol lookup. + * + * @author Jose Fonseca + */ + +#include "pipe/p_compiler.h" +#include "os/os_thread.h" +#include "u_string.h" + +#include "u_debug.h" +#include "u_debug_symbol.h" +#include "u_hash_table.h" + +#if defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86) + +#include +#include +#include + +/* + * TODO: Cleanup code. + * TODO: Support x86_64 + */ + +static BOOL bSymInitialized = FALSE; + +static HMODULE hModule_Imagehlp = NULL; + +typedef BOOL (WINAPI *PFNSYMINITIALIZE)(HANDLE, LPSTR, BOOL); +static PFNSYMINITIALIZE pfnSymInitialize = NULL; + +static +BOOL WINAPI j_SymInitialize(HANDLE hProcess, PSTR UserSearchPath, BOOL fInvadeProcess) +{ + if( + (hModule_Imagehlp || (hModule_Imagehlp = LoadLibraryA("IMAGEHLP.DLL"))) && + (pfnSymInitialize || (pfnSymInitialize = (PFNSYMINITIALIZE) GetProcAddress(hModule_Imagehlp, "SymInitialize"))) + ) + return pfnSymInitialize(hProcess, UserSearchPath, fInvadeProcess); + else + return FALSE; +} + +typedef DWORD (WINAPI *PFNSYMSETOPTIONS)(DWORD); +static PFNSYMSETOPTIONS pfnSymSetOptions = NULL; + +static +DWORD WINAPI j_SymSetOptions(DWORD SymOptions) +{ + if( + (hModule_Imagehlp || (hModule_Imagehlp = LoadLibraryA("IMAGEHLP.DLL"))) && + (pfnSymSetOptions || (pfnSymSetOptions = (PFNSYMSETOPTIONS) GetProcAddress(hModule_Imagehlp, "SymSetOptions"))) + ) + return pfnSymSetOptions(SymOptions); + else + return FALSE; +} + +typedef PGET_MODULE_BASE_ROUTINE PFNSYMGETMODULEBASE; +static PFNSYMGETMODULEBASE pfnSymGetModuleBase = NULL; + +static +DWORD WINAPI j_SymGetModuleBase(HANDLE hProcess, DWORD dwAddr) +{ + if( + (hModule_Imagehlp || (hModule_Imagehlp = LoadLibraryA("IMAGEHLP.DLL"))) && + (pfnSymGetModuleBase || (pfnSymGetModuleBase = (PFNSYMGETMODULEBASE) GetProcAddress(hModule_Imagehlp, "SymGetModuleBase"))) + ) + return pfnSymGetModuleBase(hProcess, dwAddr); + else + return 0; +} + +typedef BOOL (WINAPI *PFNSYMGETSYMFROMADDR)(HANDLE, DWORD, LPDWORD, PIMAGEHLP_SYMBOL); +static PFNSYMGETSYMFROMADDR pfnSymGetSymFromAddr = NULL; + +static +BOOL WINAPI j_SymGetSymFromAddr(HANDLE hProcess, DWORD Address, PDWORD Displacement, PIMAGEHLP_SYMBOL Symbol) +{ + if( + (hModule_Imagehlp || (hModule_Imagehlp = LoadLibraryA("IMAGEHLP.DLL"))) && + (pfnSymGetSymFromAddr || (pfnSymGetSymFromAddr = (PFNSYMGETSYMFROMADDR) GetProcAddress(hModule_Imagehlp, "SymGetSymFromAddr"))) + ) + return pfnSymGetSymFromAddr(hProcess, Address, Displacement, Symbol); + else + return FALSE; +} + + +static INLINE void +debug_symbol_name_imagehlp(const void *addr, char* buf, unsigned size) +{ + HANDLE hProcess; + BYTE symbolBuffer[1024]; + PIMAGEHLP_SYMBOL pSymbol = (PIMAGEHLP_SYMBOL) symbolBuffer; + DWORD dwDisplacement = 0; /* Displacement of the input address, relative to the start of the symbol */ + + hProcess = GetCurrentProcess(); + + pSymbol->SizeOfStruct = sizeof(symbolBuffer); + pSymbol->MaxNameLength = sizeof(symbolBuffer) - offsetof(IMAGEHLP_SYMBOL, Name); + + if(!bSymInitialized) { + j_SymSetOptions(/* SYMOPT_UNDNAME | */ SYMOPT_LOAD_LINES); + if(j_SymInitialize(hProcess, NULL, TRUE)) + bSymInitialized = TRUE; + } + + if(!j_SymGetSymFromAddr(hProcess, (DWORD)addr, &dwDisplacement, pSymbol)) + buf[0] = 0; + else + { + strncpy(buf, pSymbol->Name, size); + buf[size - 1] = 0; + } +} +#endif + +#ifdef __GLIBC__ +#include + +/* This can only provide dynamic symbols, or binary offsets into a file. + * + * To fix this, post-process the output with tools/addr2line.sh + */ +static INLINE void +debug_symbol_name_glibc(const void *addr, char* buf, unsigned size) +{ + char** syms = backtrace_symbols((void**)&addr, 1); + strncpy(buf, syms[0], size); + buf[size - 1] = 0; + free(syms); +} +#endif + +void +debug_symbol_name(const void *addr, char* buf, unsigned size) +{ +#if defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86) + debug_symbol_name_imagehlp(addr, buf, size); + if(buf[0]) + return; +#endif + +#ifdef __GLIBC__ + debug_symbol_name_glibc(addr, buf, size); + if(buf[0]) + return; +#endif + + util_snprintf(buf, size, "%p", addr); + buf[size - 1] = 0; +} + +void +debug_symbol_print(const void *addr) +{ + char buf[1024]; + debug_symbol_name(addr, buf, sizeof(buf)); + debug_printf("\t%s\n", buf); +} + +struct util_hash_table* symbols_hash; +pipe_mutex symbols_mutex; + +static unsigned hash_ptr(void* p) +{ + return (unsigned)(uintptr_t)p; +} + +static int compare_ptr(void* a, void* b) +{ + if(a == b) + return 0; + else if(a < b) + return -1; + else + return 1; +} + +const char* +debug_symbol_name_cached(const void *addr) +{ + const char* name; + pipe_mutex_lock(symbols_mutex); + if(!symbols_hash) + symbols_hash = util_hash_table_create(hash_ptr, compare_ptr); + name = util_hash_table_get(symbols_hash, (void*)addr); + if(!name) + { + char buf[1024]; + debug_symbol_name(addr, buf, sizeof(buf)); + name = strdup(buf); + + util_hash_table_set(symbols_hash, (void*)addr, (void*)name); + } + pipe_mutex_unlock(symbols_mutex); + return name; +} diff --git a/src/gallium/auxiliary/util/u_debug_symbol.h b/src/gallium/auxiliary/util/u_debug_symbol.h new file mode 100644 index 0000000..b247706 --- /dev/null +++ b/src/gallium/auxiliary/util/u_debug_symbol.h @@ -0,0 +1,58 @@ +/************************************************************************** + * + * 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 U_DEBUG_SYMBOL_H_ +#define U_DEBUG_SYMBOL_H_ + + +/** + * @file + * Symbol lookup. + * + * @author Jose Fonseca + */ + + +#ifdef __cplusplus +extern "C" { +#endif + + +void +debug_symbol_name(const void *addr, char* buf, unsigned size); + +const char* +debug_symbol_name_cached(const void *addr); + +void +debug_symbol_print(const void *addr); + +#ifdef __cplusplus +} +#endif + +#endif /* U_DEBUG_SYMBOL_H_ */ diff --git a/src/gallium/auxiliary/util/u_dirty_flags.h b/src/gallium/auxiliary/util/u_dirty_flags.h new file mode 100644 index 0000000..40539f0 --- /dev/null +++ b/src/gallium/auxiliary/util/u_dirty_flags.h @@ -0,0 +1,32 @@ +#ifndef U_DIRTY_FLAGS_H +#define U_DIRTY_FLAGS_H + +/* Here's a convenient list of dirty flags to use in a driver. Either + * include it directly or use it as a starting point for your own + * list. + */ +#define U_NEW_VIEWPORT 0x1 +#define U_NEW_RASTERIZER 0x2 +#define U_NEW_FS 0x4 +#define U_NEW_FS_CONSTANTS 0x8 +#define U_NEW_FS_SAMPLER_VIEW 0x10 +#define U_NEW_FS_SAMPLER_STATES 0x20 +#define U_NEW_VS 0x40 +#define U_NEW_VS_CONSTANTS 0x80 +#define U_NEW_VS_SAMPLER_VIEW 0x100 +#define U_NEW_VS_SAMPLER_STATES 0x200 +#define U_NEW_BLEND 0x400 +#define U_NEW_CLIP 0x800 +#define U_NEW_SCISSOR 0x1000 +#define U_NEW_POLYGON_STIPPLE 0x2000 +#define U_NEW_FRAMEBUFFER 0x4000 +#define U_NEW_VERTEX_ELEMENTS 0x8000 +#define U_NEW_VERTEX_BUFFER 0x10000 +#define U_NEW_QUERY 0x20000 +#define U_NEW_DEPTH_STENCIL 0x40000 +#define U_NEW_GS 0x80000 +#define U_NEW_GS_CONSTANTS 0x100000 +#define U_NEW_GS_SAMPLER_VIEW 0x200000 +#define U_NEW_GS_SAMPLER_STATES 0x400000 + +#endif diff --git a/src/gallium/auxiliary/util/u_dirty_surfaces.h b/src/gallium/auxiliary/util/u_dirty_surfaces.h new file mode 100644 index 0000000..f3618d9 --- /dev/null +++ b/src/gallium/auxiliary/util/u_dirty_surfaces.h @@ -0,0 +1,119 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef U_DIRTY_SURFACES_H_ +#define U_DIRTY_SURFACES_H_ + +#include "pipe/p_state.h" + +#include "util/u_double_list.h" +#include "util/u_math.h" + +struct pipe_context; + +typedef void (*util_dirty_surface_flush_t) (struct pipe_context *, struct pipe_surface *); + +struct util_dirty_surfaces +{ + struct list_head dirty_list; +}; + +struct util_dirty_surface +{ + struct pipe_surface base; + struct list_head dirty_list; +}; + +static INLINE void +util_dirty_surfaces_init(struct util_dirty_surfaces *ds) +{ + LIST_INITHEAD(&ds->dirty_list); +} + +static INLINE void +util_dirty_surfaces_use_for_sampling(struct pipe_context *pipe, struct util_dirty_surfaces *dss, util_dirty_surface_flush_t flush) +{ + struct list_head *p, *next; + for(p = dss->dirty_list.next; p != &dss->dirty_list; p = next) + { + struct util_dirty_surface *ds = LIST_ENTRY(struct util_dirty_surface, p, dirty_list); + next = p->next; + + flush(pipe, &ds->base); + } +} + +static INLINE void +util_dirty_surfaces_use_levels_for_sampling(struct pipe_context *pipe, struct util_dirty_surfaces *dss, unsigned first, unsigned last, util_dirty_surface_flush_t flush) +{ + struct list_head *p, *next; + if(first > last) + return; + for(p = dss->dirty_list.next; p != &dss->dirty_list; p = next) + { + struct util_dirty_surface *ds = LIST_ENTRY(struct util_dirty_surface, p, dirty_list); + next = p->next; + + if(ds->base.u.tex.level >= first && ds->base.u.tex.level <= last) + flush(pipe, &ds->base); + } +} + +static INLINE void +util_dirty_surfaces_use_for_sampling_with(struct pipe_context *pipe, struct util_dirty_surfaces *dss, struct pipe_sampler_view *psv, struct pipe_sampler_state *pss, util_dirty_surface_flush_t flush) +{ + if(!LIST_IS_EMPTY(&dss->dirty_list)) + util_dirty_surfaces_use_levels_for_sampling(pipe, dss, (unsigned)pss->min_lod + psv->u.tex.first_level, + MIN2((unsigned)ceilf(pss->max_lod) + psv->u.tex.first_level, psv->u.tex.last_level), flush); +} + +static INLINE void +util_dirty_surface_init(struct util_dirty_surface *ds) +{ + LIST_INITHEAD(&ds->dirty_list); +} + +static INLINE boolean +util_dirty_surface_is_dirty(struct util_dirty_surface *ds) +{ + return !LIST_IS_EMPTY(&ds->dirty_list); +} + +static INLINE void +util_dirty_surface_set_dirty(struct util_dirty_surfaces *dss, struct util_dirty_surface *ds) +{ + if(LIST_IS_EMPTY(&ds->dirty_list)) + LIST_ADDTAIL(&ds->dirty_list, &dss->dirty_list); +} + +static INLINE void +util_dirty_surface_set_clean(struct util_dirty_surfaces *dss, struct util_dirty_surface *ds) +{ + if(!LIST_IS_EMPTY(&ds->dirty_list)) + LIST_DELINIT(&ds->dirty_list); +} + +#endif diff --git a/src/gallium/auxiliary/util/u_dl.c b/src/gallium/auxiliary/util/u_dl.c new file mode 100644 index 0000000..aca435d --- /dev/null +++ b/src/gallium/auxiliary/util/u_dl.c @@ -0,0 +1,94 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * Copyright 1999-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, 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. + * + **************************************************************************/ + + +#include "pipe/p_config.h" +#include "pipe/p_compiler.h" + +#if defined(PIPE_OS_UNIX) +#include +#endif +#if defined(PIPE_OS_WINDOWS) +#include +#endif + +#include "u_dl.h" +#include "u_pointer.h" + + +struct util_dl_library * +util_dl_open(const char *filename) +{ +#if defined(PIPE_OS_UNIX) + return (struct util_dl_library *)dlopen(filename, RTLD_LAZY | RTLD_GLOBAL); +#elif defined(PIPE_OS_WINDOWS) + return (struct util_dl_library *)LoadLibraryA(filename); +#else + return NULL; +#endif +} + + +util_dl_proc +util_dl_get_proc_address(struct util_dl_library *library, + const char *procname) +{ +#if defined(PIPE_OS_UNIX) + return (util_dl_proc) pointer_to_func(dlsym((void *)library, procname)); +#elif defined(PIPE_OS_WINDOWS) + return (util_dl_proc)GetProcAddress((HMODULE)library, procname); +#else + return (util_dl_proc)NULL; +#endif +} + + +void +util_dl_close(struct util_dl_library *library) +{ +#if defined(PIPE_OS_UNIX) + dlclose((void *)library); +#elif defined(PIPE_OS_WINDOWS) + FreeLibrary((HMODULE)library); +#else + (void)library; +#endif +} + + +const char * +util_dl_error(void) +{ +#if defined(PIPE_OS_UNIX) + return dlerror(); +#elif defined(PIPE_OS_WINDOWS) + return "unknown error"; +#else + return "unknown error"; +#endif +} diff --git a/src/gallium/auxiliary/util/u_dl.h b/src/gallium/auxiliary/util/u_dl.h new file mode 100644 index 0000000..80a00ed --- /dev/null +++ b/src/gallium/auxiliary/util/u_dl.h @@ -0,0 +1,83 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef U_DL_H_ +#define U_DL_H_ + + +#include "pipe/p_config.h" + + +#if defined(PIPE_OS_WINDOWS) +# define UTIL_DL_EXT ".dll" +# define UTIL_DL_PREFIX "" +#elif defined(PIPE_OS_APPLE) +# define UTIL_DL_EXT ".dylib" +# define UTIL_DL_PREFIX "lib" +#else +# define UTIL_DL_EXT ".so" +# define UTIL_DL_PREFIX "lib" +#endif + + +struct util_dl_library; + + +typedef void (*util_dl_proc)(void); + + +/** + * Open a library dynamically. + */ +struct util_dl_library * +util_dl_open(const char *filename); + + +/** + * Lookup a function in a library. + */ +util_dl_proc +util_dl_get_proc_address(struct util_dl_library *library, + const char *procname); + + +/** + * Close a library. + */ +void +util_dl_close(struct util_dl_library *library); + + +/** + * Return most recent error message. + */ +const char * +util_dl_error(void); + + +#endif /* U_DL_H_ */ diff --git a/src/gallium/auxiliary/util/u_double_list.h b/src/gallium/auxiliary/util/u_double_list.h new file mode 100644 index 0000000..42adb1f --- /dev/null +++ b/src/gallium/auxiliary/util/u_double_list.h @@ -0,0 +1,117 @@ +/************************************************************************** + * + * Copyright 2006 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. + * + **************************************************************************/ + +/** + * \file + * List macros heavily inspired by the Linux kernel + * list handling. No list looping yet. + * + * Is not threadsafe, so common operations need to + * be protected using an external mutex. + */ + +#ifndef _U_DOUBLE_LIST_H_ +#define _U_DOUBLE_LIST_H_ + + +#include + + +struct list_head +{ + struct list_head *prev; + struct list_head *next; +}; + + +#define LIST_INITHEAD(__item) \ + do { \ + (__item)->prev = (__item); \ + (__item)->next = (__item); \ + } while (0) + +#define LIST_ADD(__item, __list) \ + do { \ + (__item)->prev = (__list); \ + (__item)->next = (__list)->next; \ + (__list)->next->prev = (__item); \ + (__list)->next = (__item); \ + } while (0) + +#define LIST_ADDTAIL(__item, __list) \ + do { \ + (__item)->next = (__list); \ + (__item)->prev = (__list)->prev; \ + (__list)->prev->next = (__item); \ + (__list)->prev = (__item); \ + } while(0) + +#define LIST_REPLACE(__from, __to) \ + do { \ + (__to)->prev = (__from)->prev; \ + (__to)->next = (__from)->next; \ + (__from)->next->prev = (__to); \ + (__from)->prev->next = (__to); \ + } while (0) + +#define LIST_DEL(__item) \ + do { \ + (__item)->prev->next = (__item)->next; \ + (__item)->next->prev = (__item)->prev; \ + } while(0) + +#define LIST_DELINIT(__item) \ + do { \ + (__item)->prev->next = (__item)->next; \ + (__item)->next->prev = (__item)->prev; \ + (__item)->next = (__item); \ + (__item)->prev = (__item); \ + } while(0) + +#define LIST_ENTRY(__type, __item, __field) \ + ((__type *)(((char *)(__item)) - offsetof(__type, __field))) + +#define LIST_IS_EMPTY(__list) \ + ((__list)->next == (__list)) + +#ifndef container_of +#define container_of(ptr, sample, member) \ + (void *)((char *)(ptr) \ + - ((char *)&(sample)->member - (char *)(sample))) +#endif + +#define LIST_FOR_EACH_ENTRY(pos, head, member) \ + for (pos = container_of((head)->next, pos, member); \ + &pos->member != (head); \ + pos = container_of(pos->member.next, pos, member)) + +#define LIST_FOR_EACH_ENTRY_SAFE(pos, storage, head, member) \ + for (pos = container_of((head)->next, pos, member), \ + storage = container_of(pos->member.next, pos, member); \ + &pos->member != (head); \ + pos = storage, storage = container_of(storage->member.next, storage, member)) +#endif /*_U_DOUBLE_LIST_H_*/ diff --git a/src/gallium/auxiliary/util/u_draw.h b/src/gallium/auxiliary/util/u_draw.h new file mode 100644 index 0000000..f06d09e --- /dev/null +++ b/src/gallium/auxiliary/util/u_draw.h @@ -0,0 +1,139 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef U_DRAW_H +#define U_DRAW_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" + + +static INLINE void +util_draw_init_info(struct pipe_draw_info *info) +{ + memset(info, 0, sizeof(*info)); + info->instance_count = 1; + info->max_index = 0xffffffff; +} + + +static INLINE void +util_draw_arrays(struct pipe_context *pipe, uint mode, uint start, uint count) +{ + struct pipe_draw_info info; + + util_draw_init_info(&info); + info.mode = mode; + info.start = start; + info.count = count; + info.min_index = start; + info.max_index = start + count - 1; + + pipe->draw_vbo(pipe, &info); +} + +static INLINE void +util_draw_elements(struct pipe_context *pipe, int index_bias, + uint mode, uint start, uint count) +{ + struct pipe_draw_info info; + + util_draw_init_info(&info); + info.indexed = TRUE; + info.mode = mode; + info.start = start; + info.count = count; + info.index_bias = index_bias; + + pipe->draw_vbo(pipe, &info); +} + +static INLINE void +util_draw_arrays_instanced(struct pipe_context *pipe, + uint mode, uint start, uint count, + uint start_instance, + uint instance_count) +{ + struct pipe_draw_info info; + + util_draw_init_info(&info); + info.mode = mode; + info.start = start; + info.count = count; + info.start_instance = start_instance; + info.instance_count = instance_count; + info.min_index = start; + info.max_index = start + count - 1; + + pipe->draw_vbo(pipe, &info); +} + +static INLINE void +util_draw_elements_instanced(struct pipe_context *pipe, + int index_bias, + uint mode, uint start, uint count, + uint start_instance, + uint instance_count) +{ + struct pipe_draw_info info; + + util_draw_init_info(&info); + info.indexed = TRUE; + info.mode = mode; + info.start = start; + info.count = count; + info.index_bias = index_bias; + info.start_instance = start_instance; + info.instance_count = instance_count; + + pipe->draw_vbo(pipe, &info); +} + +static INLINE void +util_draw_range_elements(struct pipe_context *pipe, + int index_bias, + uint min_index, + uint max_index, + uint mode, uint start, uint count) +{ + struct pipe_draw_info info; + + util_draw_init_info(&info); + info.indexed = TRUE; + info.mode = mode; + info.start = start; + info.count = count; + info.index_bias = index_bias; + info.min_index = min_index; + info.max_index = max_index; + + pipe->draw_vbo(pipe, &info); +} + +#endif diff --git a/src/gallium/auxiliary/util/u_draw_quad.c b/src/gallium/auxiliary/util/u_draw_quad.c new file mode 100644 index 0000000..0b6dc58 --- /dev/null +++ b/src/gallium/auxiliary/util/u_draw_quad.c @@ -0,0 +1,129 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_draw_quad.h" +#include "util/u_memory.h" + + +/** + * Draw a simple vertex buffer / primitive. + * Limited to float[4] vertex attribs, tightly packed. + */ +void +util_draw_vertex_buffer(struct pipe_context *pipe, + struct pipe_resource *vbuf, + uint offset, + uint prim_type, + uint num_verts, + uint num_attribs) +{ + struct pipe_vertex_buffer vbuffer; + + assert(num_attribs <= PIPE_MAX_ATTRIBS); + + /* tell pipe about the vertex buffer */ + memset(&vbuffer, 0, sizeof(vbuffer)); + vbuffer.buffer = vbuf; + vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */ + vbuffer.buffer_offset = offset; + vbuffer.max_index = num_verts - 1; + pipe->set_vertex_buffers(pipe, 1, &vbuffer); + + /* note: vertex elements already set by caller */ + + /* draw */ + util_draw_arrays(pipe, prim_type, 0, num_verts); +} + + + +/** + * Draw screen-aligned textured quad. + * Note: this isn't especially efficient. + */ +void +util_draw_texquad(struct pipe_context *pipe, + float x0, float y0, float x1, float y1, float z) +{ + uint numAttribs = 2, i, j; + uint vertexBytes = 4 * (4 * numAttribs * sizeof(float)); + struct pipe_resource *vbuf = NULL; + uint *v = NULL; + + v = MALLOC(vertexBytes); + if (v == NULL) + goto out; + + /* + * Load vertex buffer + */ + for (i = j = 0; i < 4; i++) { + v[j + 2] = z; /* z */ + v[j + 3] = 1.0; /* w */ + v[j + 6] = 0.0; /* r */ + v[j + 7] = 1.0; /* q */ + j += 8; + } + + v[0] = x0; + v[1] = y0; + v[4] = 0.0; /*s*/ + v[5] = 0.0; /*t*/ + + v[8] = x1; + v[9] = y0; + v[12] = 1.0; + v[13] = 0.0; + + v[16] = x1; + v[17] = y1; + v[20] = 1.0; + v[21] = 1.0; + + v[24] = x0; + v[25] = y1; + v[28] = 0.0; + v[29] = 1.0; + + vbuf = pipe_user_buffer_create(pipe->screen, v, vertexBytes, + PIPE_BIND_VERTEX_BUFFER); + if (!vbuf) + goto out; + + util_draw_vertex_buffer(pipe, vbuf, 0, PIPE_PRIM_TRIANGLE_FAN, 4, 2); + +out: + if (vbuf) + pipe_resource_reference(&vbuf, NULL); + + if (v) + FREE(v); +} diff --git a/src/gallium/auxiliary/util/u_draw_quad.h b/src/gallium/auxiliary/util/u_draw_quad.h new file mode 100644 index 0000000..52994fe --- /dev/null +++ b/src/gallium/auxiliary/util/u_draw_quad.h @@ -0,0 +1,60 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef U_DRAWQUAD_H +#define U_DRAWQUAD_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_context.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +struct pipe_resource; + +#include "util/u_draw.h" + +extern void +util_draw_vertex_buffer(struct pipe_context *pipe, + struct pipe_resource *vbuf, uint offset, + uint num_attribs, uint num_verts, uint prim_type); + + +extern void +util_draw_texquad(struct pipe_context *pipe, + float x0, float y0, float x1, float y1, float z); + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/src/gallium/auxiliary/util/u_dump.h b/src/gallium/auxiliary/util/u_dump.h new file mode 100644 index 0000000..49536c0 --- /dev/null +++ b/src/gallium/auxiliary/util/u_dump.h @@ -0,0 +1,179 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Dump data in human/machine readable format. + * + * @author Jose Fonseca + */ + +#ifndef U_DEBUG_DUMP_H_ +#define U_DEBUG_DUMP_H_ + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define UTIL_DUMP_INVALID_NAME "" + + +struct os_stream; + + +/* Duplicated here for convenience */ +extern struct os_stream * +os_log_stream; + + +/* + * p_defines.h + * + * XXX: These functions don't really dump anything -- just translate into + * strings so a verb better than "dump" should be used instead, in order to + * free up the namespace to the true dumper functions. + */ + +const char * +util_dump_blend_factor(unsigned value, boolean shortened); + +const char * +util_dump_blend_func(unsigned value, boolean shortened); + +const char * +util_dump_logicop(unsigned value, boolean shortened); + +const char * +util_dump_func(unsigned value, boolean shortened); + +const char * +util_dump_stencil_op(unsigned value, boolean shortened); + +const char * +util_dump_tex_target(unsigned value, boolean shortened); + +const char * +util_dump_tex_wrap(unsigned value, boolean shortened); + +const char * +util_dump_tex_mipfilter(unsigned value, boolean shortened); + +const char * +util_dump_tex_filter(unsigned value, boolean shortened); + + +/* + * p_state.h, through an os_stream + */ + +void +util_dump_template(struct os_stream *stream, + const struct pipe_resource *templat); + +void +util_dump_rasterizer_state(struct os_stream *stream, + const struct pipe_rasterizer_state *state); + +void +util_dump_poly_stipple(struct os_stream *stream, + const struct pipe_poly_stipple *state); + +void +util_dump_viewport_state(struct os_stream *stream, + const struct pipe_viewport_state *state); + +void +util_dump_scissor_state(struct os_stream *stream, + const struct pipe_scissor_state *state); + +void +util_dump_clip_state(struct os_stream *stream, + const struct pipe_clip_state *state); + +void +util_dump_shader_state(struct os_stream *stream, + const struct pipe_shader_state *state); + +void +util_dump_depth_stencil_alpha_state(struct os_stream *stream, + const struct pipe_depth_stencil_alpha_state *state); + +void +util_dump_rt_blend_state(struct os_stream *stream, + const struct pipe_rt_blend_state *state); + +void +util_dump_blend_state(struct os_stream *stream, + const struct pipe_blend_state *state); + +void +util_dump_blend_color(struct os_stream *stream, + const struct pipe_blend_color *state); + +void +util_dump_stencil_ref(struct os_stream *stream, + const struct pipe_stencil_ref *state); + +void +util_dump_framebuffer_state(struct os_stream *stream, + const struct pipe_framebuffer_state *state); + +void +util_dump_sampler_state(struct os_stream *stream, + const struct pipe_sampler_state *state); + +void +util_dump_surface(struct os_stream *stream, + const struct pipe_surface *state); + +void +util_dump_transfer(struct os_stream *stream, + const struct pipe_transfer *state); + +void +util_dump_vertex_buffer(struct os_stream *stream, + const struct pipe_vertex_buffer *state); + +void +util_dump_vertex_element(struct os_stream *stream, + const struct pipe_vertex_element *state); + + +/* FIXME: Move the other debug_dump_xxx functions out of u_debug.h into here. */ + + +#ifdef __cplusplus +} +#endif + +#endif /* U_DEBUG_H_ */ diff --git a/src/gallium/auxiliary/util/u_dump_defines.c b/src/gallium/auxiliary/util/u_dump_defines.c new file mode 100644 index 0000000..692d444 --- /dev/null +++ b/src/gallium/auxiliary/util/u_dump_defines.c @@ -0,0 +1,336 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_dump.h" + + +#if 0 +static const char * +util_dump_strip_prefix(const char *name, + const char *prefix) +{ + const char *stripped; + assert(name); + assert(prefix); + stripped = name; + while(*prefix) { + if(*stripped != *prefix) + return name; + + ++stripped; + ++prefix; + } + return stripped; +} +#endif + +static const char * +util_dump_enum_continuous(unsigned value, + unsigned num_names, + const char **names) +{ + if (value >= num_names) + return UTIL_DUMP_INVALID_NAME; + return names[value]; +} + + +#define DEFINE_UTIL_DUMP_CONTINUOUS(_name) \ + const char * \ + util_dump_##_name(unsigned value, boolean shortened) \ + { \ + if(shortened) \ + return util_dump_enum_continuous(value, Elements(util_dump_##_name##_short_names), util_dump_##_name##_short_names); \ + else \ + return util_dump_enum_continuous(value, Elements(util_dump_##_name##_names), util_dump_##_name##_names); \ + } + + +static const char * +util_dump_blend_factor_names[] = { + UTIL_DUMP_INVALID_NAME, /* 0x0 */ + "PIPE_BLENDFACTOR_ONE", + "PIPE_BLENDFACTOR_SRC_COLOR", + "PIPE_BLENDFACTOR_SRC_ALPHA", + "PIPE_BLENDFACTOR_DST_ALPHA", + "PIPE_BLENDFACTOR_DST_COLOR", + "PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE", + "PIPE_BLENDFACTOR_CONST_COLOR", + "PIPE_BLENDFACTOR_CONST_ALPHA", + "PIPE_BLENDFACTOR_SRC1_COLOR", + "PIPE_BLENDFACTOR_SRC1_ALPHA", + UTIL_DUMP_INVALID_NAME, /* 0x0b */ + UTIL_DUMP_INVALID_NAME, /* 0x0c */ + UTIL_DUMP_INVALID_NAME, /* 0x0d */ + UTIL_DUMP_INVALID_NAME, /* 0x0e */ + UTIL_DUMP_INVALID_NAME, /* 0x0f */ + UTIL_DUMP_INVALID_NAME, /* 0x10 */ + "PIPE_BLENDFACTOR_ZERO", + "PIPE_BLENDFACTOR_INV_SRC_COLOR", + "PIPE_BLENDFACTOR_INV_SRC_ALPHA", + "PIPE_BLENDFACTOR_INV_DST_ALPHA", + "PIPE_BLENDFACTOR_INV_DST_COLOR", + UTIL_DUMP_INVALID_NAME, /* 0x16 */ + "PIPE_BLENDFACTOR_INV_CONST_COLOR", + "PIPE_BLENDFACTOR_INV_CONST_ALPHA", + "PIPE_BLENDFACTOR_INV_SRC1_COLOR", + "PIPE_BLENDFACTOR_INV_SRC1_ALPHA" +}; + +static const char * +util_dump_blend_factor_short_names[] = { + UTIL_DUMP_INVALID_NAME, /* 0x0 */ + "one", + "src_color", + "src_alpha", + "dst_alpha", + "dst_color", + "src_alpha_saturate", + "const_color", + "const_alpha", + "src1_color", + "src1_alpha", + UTIL_DUMP_INVALID_NAME, /* 0x0b */ + UTIL_DUMP_INVALID_NAME, /* 0x0c */ + UTIL_DUMP_INVALID_NAME, /* 0x0d */ + UTIL_DUMP_INVALID_NAME, /* 0x0e */ + UTIL_DUMP_INVALID_NAME, /* 0x0f */ + UTIL_DUMP_INVALID_NAME, /* 0x10 */ + "zero", + "inv_src_color", + "inv_src_alpha", + "inv_dst_alpha", + "inv_dst_color", + UTIL_DUMP_INVALID_NAME, /* 0x16 */ + "inv_const_color", + "inv_const_alpha", + "inv_src1_color", + "inv_src1_alpha" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(blend_factor) + + +static const char * +util_dump_blend_func_names[] = { + "PIPE_BLEND_ADD", + "PIPE_BLEND_SUBTRACT", + "PIPE_BLEND_REVERSE_SUBTRACT", + "PIPE_BLEND_MIN", + "PIPE_BLEND_MAX" +}; + +static const char * +util_dump_blend_func_short_names[] = { + "add", + "sub", + "rev_sub", + "min", + "max" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(blend_func) + + +static const char * +util_dump_logicop_names[] = { + "PIPE_LOGICOP_CLEAR", + "PIPE_LOGICOP_NOR", + "PIPE_LOGICOP_AND_INVERTED", + "PIPE_LOGICOP_COPY_INVERTED", + "PIPE_LOGICOP_AND_REVERSE", + "PIPE_LOGICOP_INVERT", + "PIPE_LOGICOP_XOR", + "PIPE_LOGICOP_NAND", + "PIPE_LOGICOP_AND", + "PIPE_LOGICOP_EQUIV", + "PIPE_LOGICOP_NOOP", + "PIPE_LOGICOP_OR_INVERTED", + "PIPE_LOGICOP_COPY", + "PIPE_LOGICOP_OR_REVERSE", + "PIPE_LOGICOP_OR", + "PIPE_LOGICOP_SET" +}; + +static const char * +util_dump_logicop_short_names[] = { + "clear", + "nor", + "and_inverted", + "copy_inverted", + "and_reverse", + "invert", + "xor", + "nand", + "and", + "equiv", + "noop", + "or_inverted", + "copy", + "or_reverse", + "or", + "set" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(logicop) + + +static const char * +util_dump_func_names[] = { + "PIPE_FUNC_NEVER", + "PIPE_FUNC_LESS", + "PIPE_FUNC_EQUAL", + "PIPE_FUNC_LEQUAL", + "PIPE_FUNC_GREATER", + "PIPE_FUNC_NOTEQUAL", + "PIPE_FUNC_GEQUAL", + "PIPE_FUNC_ALWAYS" +}; + +static const char * +util_dump_func_short_names[] = { + "never", + "less", + "equal", + "less_equal", + "greater", + "not_equal", + "greater_equal", + "always" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(func) + + +static const char * +util_dump_stencil_op_names[] = { + "PIPE_STENCIL_OP_KEEP", + "PIPE_STENCIL_OP_ZERO", + "PIPE_STENCIL_OP_REPLACE", + "PIPE_STENCIL_OP_INCR", + "PIPE_STENCIL_OP_DECR", + "PIPE_STENCIL_OP_INCR_WRAP", + "PIPE_STENCIL_OP_DECR_WRAP", + "PIPE_STENCIL_OP_INVERT" +}; + +static const char * +util_dump_stencil_op_short_names[] = { + "keep", + "zero", + "replace", + "incr", + "decr", + "incr_wrap", + "decr_wrap", + "invert" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(stencil_op) + + +static const char * +util_dump_tex_target_names[] = { + "PIPE_BUFFER", + "PIPE_TEXTURE_1D", + "PIPE_TEXTURE_2D", + "PIPE_TEXTURE_3D", + "PIPE_TEXTURE_CUBE" +}; + +static const char * +util_dump_tex_target_short_names[] = { + "buffer", + "1d", + "2d", + "3d", + "cube" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(tex_target) + + +static const char * +util_dump_tex_wrap_names[] = { + "PIPE_TEX_WRAP_REPEAT", + "PIPE_TEX_WRAP_CLAMP", + "PIPE_TEX_WRAP_CLAMP_TO_EDGE", + "PIPE_TEX_WRAP_CLAMP_TO_BORDER", + "PIPE_TEX_WRAP_MIRROR_REPEAT", + "PIPE_TEX_WRAP_MIRROR_CLAMP", + "PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE", + "PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER" +}; + +static const char * +util_dump_tex_wrap_short_names[] = { + "repeat", + "clamp", + "clamp_to_edge", + "clamp_to_border", + "mirror_repeat", + "mirror_clamp", + "mirror_clamp_to_edge", + "mirror_clamp_to_border" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(tex_wrap) + + +static const char * +util_dump_tex_mipfilter_names[] = { + "PIPE_TEX_MIPFILTER_NEAREST", + "PIPE_TEX_MIPFILTER_LINEAR", + "PIPE_TEX_MIPFILTER_NONE" +}; + +static const char * +util_dump_tex_mipfilter_short_names[] = { + "nearest", + "linear", + "none" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(tex_mipfilter) + + +static const char * +util_dump_tex_filter_names[] = { + "PIPE_TEX_FILTER_NEAREST", + "PIPE_TEX_FILTER_LINEAR" +}; + +static const char * +util_dump_tex_filter_short_names[] = { + "nearest", + "linear" +}; + +DEFINE_UTIL_DUMP_CONTINUOUS(tex_filter) diff --git a/src/gallium/auxiliary/util/u_dump_state.c b/src/gallium/auxiliary/util/u_dump_state.c new file mode 100644 index 0000000..b471d59 --- /dev/null +++ b/src/gallium/auxiliary/util/u_dump_state.c @@ -0,0 +1,709 @@ +/************************************************************************** + * + * Copyright 2008-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "pipe/p_compiler.h" +#include "os/os_stream.h" +#include "util/u_memory.h" +#include "util/u_string.h" +#include "util/u_format.h" +#include "tgsi/tgsi_dump.h" + +#include "u_dump.h" + + +/* + * Dump primitives + */ + +static INLINE void +util_stream_writef(struct os_stream *stream, const char *format, ...) +{ + static char buf[1024]; + unsigned len; + va_list ap; + va_start(ap, format); + len = util_vsnprintf(buf, sizeof(buf), format, ap); + va_end(ap); + os_stream_write(stream, buf, len); +} + +static void +util_dump_bool(struct os_stream *stream, int value) +{ + util_stream_writef(stream, "%c", value ? '1' : '0'); +} + +static void +util_dump_int(struct os_stream *stream, long long int value) +{ + util_stream_writef(stream, "%lli", value); +} + +static void +util_dump_uint(struct os_stream *stream, long long unsigned value) +{ + util_stream_writef(stream, "%llu", value); +} + +static void +util_dump_float(struct os_stream *stream, double value) +{ + util_stream_writef(stream, "%g", value); +} + +static void +util_dump_string(struct os_stream *stream, const char *str) +{ + os_stream_write_str(stream, "\""); + os_stream_write_str(stream, str); + os_stream_write_str(stream, "\""); +} + +static void +util_dump_enum(struct os_stream *stream, const char *value) +{ + os_stream_write_str(stream, value); +} + +static void +util_dump_array_begin(struct os_stream *stream) +{ + os_stream_write_str(stream, "{"); +} + +static void +util_dump_array_end(struct os_stream *stream) +{ + os_stream_write_str(stream, "}"); +} + +static void +util_dump_elem_begin(struct os_stream *stream) +{ +} + +static void +util_dump_elem_end(struct os_stream *stream) +{ + os_stream_write_str(stream, ", "); +} + +static void +util_dump_struct_begin(struct os_stream *stream, const char *name) +{ + os_stream_write_str(stream, "{"); +} + +static void +util_dump_struct_end(struct os_stream *stream) +{ + os_stream_write_str(stream, "}"); +} + +static void +util_dump_member_begin(struct os_stream *stream, const char *name) +{ + util_stream_writef(stream, "%s = ", name); +} + +static void +util_dump_member_end(struct os_stream *stream) +{ + os_stream_write_str(stream, ", "); +} + +static void +util_dump_null(struct os_stream *stream) +{ + os_stream_write_str(stream, "NULL"); +} + +static void +util_dump_ptr(struct os_stream *stream, const void *value) +{ + if(value) + util_stream_writef(stream, "0x%08lx", (unsigned long)(uintptr_t)value); + else + util_dump_null(stream); +} + + +/* + * Code saving macros. + */ + +#define util_dump_arg(_stream, _type, _arg) \ + do { \ + util_dump_arg_begin(_stream, #_arg); \ + util_dump_##_type(_stream, _arg); \ + util_dump_arg_end(_stream); \ + } while(0) + +#define util_dump_ret(_stream, _type, _arg) \ + do { \ + util_dump_ret_begin(_stream); \ + util_dump_##_type(_stream, _arg); \ + util_dump_ret_end(_stream); \ + } while(0) + +#define util_dump_array(_stream, _type, _obj, _size) \ + do { \ + size_t idx; \ + util_dump_array_begin(_stream); \ + for(idx = 0; idx < (_size); ++idx) { \ + util_dump_elem_begin(_stream); \ + util_dump_##_type(_stream, (_obj)[idx]); \ + util_dump_elem_end(_stream); \ + } \ + util_dump_array_end(_stream); \ + } while(0) + +#define util_dump_struct_array(_stream, _type, _obj, _size) \ + do { \ + size_t idx; \ + util_dump_array_begin(_stream); \ + for(idx = 0; idx < (_size); ++idx) { \ + util_dump_elem_begin(_stream); \ + util_dump_##_type(_stream, &(_obj)[idx]); \ + util_dump_elem_end(_stream); \ + } \ + util_dump_array_end(_stream); \ + } while(0) + +#define util_dump_member(_stream, _type, _obj, _member) \ + do { \ + util_dump_member_begin(_stream, #_member); \ + util_dump_##_type(_stream, (_obj)->_member); \ + util_dump_member_end(_stream); \ + } while(0) + +#define util_dump_arg_array(_stream, _type, _arg, _size) \ + do { \ + util_dump_arg_begin(_stream, #_arg); \ + util_dump_array(_stream, _type, _arg, _size); \ + util_dump_arg_end(_stream); \ + } while(0) + +#define util_dump_member_array(_stream, _type, _obj, _member) \ + do { \ + util_dump_member_begin(_stream, #_member); \ + util_dump_array(_stream, _type, (_obj)->_member, sizeof((_obj)->_member)/sizeof((_obj)->_member[0])); \ + util_dump_member_end(_stream); \ + } while(0) + + + +/* + * Wrappers for enum -> string dumpers. + */ + + +static void +util_dump_format(struct os_stream *stream, enum pipe_format format) +{ + util_dump_enum(stream, util_format_name(format)); +} + + +static void +util_dump_enum_blend_factor(struct os_stream *stream, unsigned value) +{ + util_dump_enum(stream, util_dump_blend_factor(value, TRUE)); +} + +static void +util_dump_enum_blend_func(struct os_stream *stream, unsigned value) +{ + util_dump_enum(stream, util_dump_blend_func(value, TRUE)); +} + +static void +util_dump_enum_func(struct os_stream *stream, unsigned value) +{ + util_dump_enum(stream, util_dump_func(value, TRUE)); +} + + +/* + * Public functions + */ + + +void +util_dump_template(struct os_stream *stream, const struct pipe_resource *templat) +{ + if(!templat) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_resource"); + + util_dump_member(stream, int, templat, target); + util_dump_member(stream, format, templat, format); + + util_dump_member_begin(stream, "width"); + util_dump_uint(stream, templat->width0); + util_dump_member_end(stream); + + util_dump_member_begin(stream, "height"); + util_dump_uint(stream, templat->height0); + util_dump_member_end(stream); + + util_dump_member_begin(stream, "depth"); + util_dump_uint(stream, templat->depth0); + util_dump_member_end(stream); + + util_dump_member_begin(stream, "array_size"); + util_dump_uint(stream, templat->array_size); + util_dump_member_end(stream); + + util_dump_member(stream, uint, templat, last_level); + util_dump_member(stream, uint, templat, usage); + util_dump_member(stream, uint, templat, bind); + util_dump_member(stream, uint, templat, flags); + + util_dump_struct_end(stream); +} + + +void +util_dump_rasterizer_state(struct os_stream *stream, const struct pipe_rasterizer_state *state) +{ + if(!state) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_rasterizer_state"); + + util_dump_member(stream, bool, state, flatshade); + util_dump_member(stream, bool, state, light_twoside); + util_dump_member(stream, uint, state, front_ccw); + util_dump_member(stream, uint, state, cull_face); + util_dump_member(stream, uint, state, fill_front); + util_dump_member(stream, uint, state, fill_back); + util_dump_member(stream, bool, state, offset_point); + util_dump_member(stream, bool, state, offset_line); + util_dump_member(stream, bool, state, offset_tri); + util_dump_member(stream, bool, state, scissor); + util_dump_member(stream, bool, state, poly_smooth); + util_dump_member(stream, bool, state, poly_stipple_enable); + util_dump_member(stream, bool, state, point_smooth); + util_dump_member(stream, uint, state, sprite_coord_enable); + util_dump_member(stream, bool, state, sprite_coord_mode); + util_dump_member(stream, bool, state, point_quad_rasterization); + util_dump_member(stream, bool, state, point_size_per_vertex); + util_dump_member(stream, bool, state, multisample); + util_dump_member(stream, bool, state, line_smooth); + util_dump_member(stream, bool, state, line_stipple_enable); + util_dump_member(stream, uint, state, line_stipple_factor); + util_dump_member(stream, uint, state, line_stipple_pattern); + util_dump_member(stream, bool, state, line_last_pixel); + util_dump_member(stream, bool, state, flatshade_first); + util_dump_member(stream, bool, state, gl_rasterization_rules); + + util_dump_member(stream, float, state, line_width); + util_dump_member(stream, float, state, point_size); + util_dump_member(stream, float, state, offset_units); + util_dump_member(stream, float, state, offset_scale); + + util_dump_struct_end(stream); +} + + +void +util_dump_poly_stipple(struct os_stream *stream, const struct pipe_poly_stipple *state) +{ + if(!state) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_poly_stipple"); + + util_dump_member_begin(stream, "stipple"); + util_dump_member_array(stream, uint, state, stipple); + util_dump_member_end(stream); + + util_dump_struct_end(stream); +} + + +void +util_dump_viewport_state(struct os_stream *stream, const struct pipe_viewport_state *state) +{ + if(!state) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_viewport_state"); + + util_dump_member_array(stream, float, state, scale); + util_dump_member_array(stream, float, state, translate); + + util_dump_struct_end(stream); +} + + +void +util_dump_scissor_state(struct os_stream *stream, const struct pipe_scissor_state *state) +{ + if(!state) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_scissor_state"); + + util_dump_member(stream, uint, state, minx); + util_dump_member(stream, uint, state, miny); + util_dump_member(stream, uint, state, maxx); + util_dump_member(stream, uint, state, maxy); + + util_dump_struct_end(stream); +} + + +void +util_dump_clip_state(struct os_stream *stream, const struct pipe_clip_state *state) +{ + unsigned i; + + if(!state) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_clip_state"); + + util_dump_member_begin(stream, "ucp"); + util_dump_array_begin(stream); + for(i = 0; i < PIPE_MAX_CLIP_PLANES; ++i) { + util_dump_elem_begin(stream); + util_dump_array(stream, float, state->ucp[i], 4); + util_dump_elem_end(stream); + } + util_dump_array_end(stream); + util_dump_member_end(stream); + + util_dump_member(stream, uint, state, nr); + + util_dump_struct_end(stream); +} + + +void +util_dump_shader_state(struct os_stream *stream, const struct pipe_shader_state *state) +{ + char str[8192]; + + if(!state) { + util_dump_null(stream); + return; + } + + tgsi_dump_str(state->tokens, 0, str, sizeof(str)); + + util_dump_struct_begin(stream, "pipe_shader_state"); + + util_dump_member_begin(stream, "tokens"); + util_dump_string(stream, str); + util_dump_member_end(stream); + + util_dump_struct_end(stream); +} + + +void +util_dump_depth_stencil_alpha_state(struct os_stream *stream, const struct pipe_depth_stencil_alpha_state *state) +{ + unsigned i; + + if(!state) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_depth_stencil_alpha_state"); + + util_dump_member_begin(stream, "depth"); + util_dump_struct_begin(stream, "pipe_depth_state"); + util_dump_member(stream, bool, &state->depth, enabled); + if (state->depth.enabled) { + util_dump_member(stream, bool, &state->depth, writemask); + util_dump_member(stream, enum_func, &state->depth, func); + } + util_dump_struct_end(stream); + util_dump_member_end(stream); + + util_dump_member_begin(stream, "stencil"); + util_dump_array_begin(stream); + for(i = 0; i < Elements(state->stencil); ++i) { + util_dump_elem_begin(stream); + util_dump_struct_begin(stream, "pipe_stencil_state"); + util_dump_member(stream, bool, &state->stencil[i], enabled); + if (state->stencil[i].enabled) { + util_dump_member(stream, enum_func, &state->stencil[i], func); + util_dump_member(stream, uint, &state->stencil[i], fail_op); + util_dump_member(stream, uint, &state->stencil[i], zpass_op); + util_dump_member(stream, uint, &state->stencil[i], zfail_op); + util_dump_member(stream, uint, &state->stencil[i], valuemask); + util_dump_member(stream, uint, &state->stencil[i], writemask); + } + util_dump_struct_end(stream); + util_dump_elem_end(stream); + } + util_dump_array_end(stream); + util_dump_member_end(stream); + + util_dump_member_begin(stream, "alpha"); + util_dump_struct_begin(stream, "pipe_alpha_state"); + util_dump_member(stream, bool, &state->alpha, enabled); + if (state->alpha.enabled) { + util_dump_member(stream, enum_func, &state->alpha, func); + util_dump_member(stream, float, &state->alpha, ref_value); + } + util_dump_struct_end(stream); + util_dump_member_end(stream); + + util_dump_struct_end(stream); +} + +void +util_dump_rt_blend_state(struct os_stream *stream, const struct pipe_rt_blend_state *state) +{ + util_dump_struct_begin(stream, "pipe_rt_blend_state"); + + util_dump_member(stream, uint, state, blend_enable); + if (state->blend_enable) { + util_dump_member(stream, enum_blend_func, state, rgb_func); + util_dump_member(stream, enum_blend_factor, state, rgb_src_factor); + util_dump_member(stream, enum_blend_factor, state, rgb_dst_factor); + + util_dump_member(stream, enum_blend_func, state, alpha_func); + util_dump_member(stream, enum_blend_factor, state, alpha_src_factor); + util_dump_member(stream, enum_blend_factor, state, alpha_dst_factor); + } + + util_dump_member(stream, uint, state, colormask); + + util_dump_struct_end(stream); +} + +void +util_dump_blend_state(struct os_stream *stream, const struct pipe_blend_state *state) +{ + unsigned valid_entries = 1; + + if(!state) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_blend_state"); + + util_dump_member(stream, bool, state, dither); + + util_dump_member(stream, bool, state, logicop_enable); + if (state->logicop_enable) { + util_dump_member(stream, enum_func, state, logicop_func); + } + else { + util_dump_member(stream, bool, state, independent_blend_enable); + + util_dump_member_begin(stream, "rt"); + if (state->independent_blend_enable) + valid_entries = PIPE_MAX_COLOR_BUFS; + util_dump_struct_array(stream, rt_blend_state, state->rt, valid_entries); + util_dump_member_end(stream); + } + + util_dump_struct_end(stream); +} + + +void +util_dump_blend_color(struct os_stream *stream, const struct pipe_blend_color *state) +{ + if(!state) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_blend_color"); + + util_dump_member_array(stream, float, state, color); + + util_dump_struct_end(stream); +} + +void +util_dump_stencil_ref(struct os_stream *stream, const struct pipe_stencil_ref *state) +{ + if(!state) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_stencil_ref"); + + util_dump_member_array(stream, uint, state, ref_value); + + util_dump_struct_end(stream); +} + +void +util_dump_framebuffer_state(struct os_stream *stream, const struct pipe_framebuffer_state *state) +{ + util_dump_struct_begin(stream, "pipe_framebuffer_state"); + + util_dump_member(stream, uint, state, width); + util_dump_member(stream, uint, state, height); + util_dump_member(stream, uint, state, nr_cbufs); + util_dump_member_array(stream, ptr, state, cbufs); + util_dump_member(stream, ptr, state, zsbuf); + + util_dump_struct_end(stream); +} + + +void +util_dump_sampler_state(struct os_stream *stream, const struct pipe_sampler_state *state) +{ + if(!state) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_sampler_state"); + + util_dump_member(stream, uint, state, wrap_s); + util_dump_member(stream, uint, state, wrap_t); + util_dump_member(stream, uint, state, wrap_r); + util_dump_member(stream, uint, state, min_img_filter); + util_dump_member(stream, uint, state, min_mip_filter); + util_dump_member(stream, uint, state, mag_img_filter); + util_dump_member(stream, uint, state, compare_mode); + util_dump_member(stream, enum_func, state, compare_func); + util_dump_member(stream, bool, state, normalized_coords); + util_dump_member(stream, uint, state, max_anisotropy); + util_dump_member(stream, float, state, lod_bias); + util_dump_member(stream, float, state, min_lod); + util_dump_member(stream, float, state, max_lod); + util_dump_member_array(stream, float, state, border_color); + + util_dump_struct_end(stream); +} + + +void +util_dump_surface(struct os_stream *stream, const struct pipe_surface *state) +{ + if(!state) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_surface"); + + util_dump_member(stream, format, state, format); + util_dump_member(stream, uint, state, width); + util_dump_member(stream, uint, state, height); + + util_dump_member(stream, uint, state, usage); + + util_dump_member(stream, ptr, state, texture); + util_dump_member(stream, uint, state, u.tex.level); + util_dump_member(stream, uint, state, u.tex.first_layer); + util_dump_member(stream, uint, state, u.tex.last_layer); + + util_dump_struct_end(stream); +} + + +void +util_dump_transfer(struct os_stream *stream, const struct pipe_transfer *state) +{ + if(!state) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_transfer"); + + util_dump_member(stream, ptr, state, resource); + /*util_dump_member(stream, uint, state, box);*/ + + util_dump_member(stream, uint, state, stride); + util_dump_member(stream, uint, state, layer_stride); + + /*util_dump_member(stream, ptr, state, data);*/ + + util_dump_struct_end(stream); +} + + +void +util_dump_vertex_buffer(struct os_stream *stream, const struct pipe_vertex_buffer *state) +{ + if(!state) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_vertex_buffer"); + + util_dump_member(stream, uint, state, stride); + util_dump_member(stream, uint, state, max_index); + util_dump_member(stream, uint, state, buffer_offset); + util_dump_member(stream, ptr, state, buffer); + + util_dump_struct_end(stream); +} + + +void +util_dump_vertex_element(struct os_stream *stream, const struct pipe_vertex_element *state) +{ + if(!state) { + util_dump_null(stream); + return; + } + + util_dump_struct_begin(stream, "pipe_vertex_element"); + + util_dump_member(stream, uint, state, src_offset); + + util_dump_member(stream, uint, state, vertex_buffer_index); + + util_dump_member(stream, format, state, src_format); + + util_dump_struct_end(stream); +} diff --git a/src/gallium/auxiliary/util/u_dynarray.h b/src/gallium/auxiliary/util/u_dynarray.h new file mode 100644 index 0000000..980cadf --- /dev/null +++ b/src/gallium/auxiliary/util/u_dynarray.h @@ -0,0 +1,114 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef U_DYNARRAY_H +#define U_DYNARRAY_H + +#include "pipe/p_compiler.h" +#include "util/u_memory.h" + +/* A zero-initialized version of this is guaranteed to represent an + * empty array. + * + * Also, size <= capacity and data != 0 if and only if capacity != 0 + * capacity will always be the allocation size of data + */ +struct util_dynarray +{ + void *data; + unsigned size; + unsigned capacity; +}; + +static INLINE void +util_dynarray_init(struct util_dynarray *buf) +{ + memset(buf, 0, sizeof(*buf)); +} + +static INLINE void +util_dynarray_fini(struct util_dynarray *buf) +{ + if(buf->data) + { + FREE(buf->data); + util_dynarray_init(buf); + } +} + +/* use util_dynarray_trim to reduce the allocated storage */ +static INLINE void * +util_dynarray_resize(struct util_dynarray *buf, unsigned newsize) +{ + char *p; + if(newsize > buf->capacity) + { + unsigned newcap = buf->capacity << 1; + if(newsize > newcap) + newcap = newsize; + buf->data = REALLOC(buf->data, buf->capacity, newcap); + buf->capacity = newcap; + } + + p = (char *)buf->data + buf->size; + buf->size = newsize; + return p; +} + +static INLINE void * +util_dynarray_grow(struct util_dynarray *buf, int diff) +{ + return util_dynarray_resize(buf, buf->size + diff); +} + +static INLINE void +util_dynarray_trim(struct util_dynarray *buf) +{ + if (buf->size != buf->capacity) { + if (buf->size) { + buf->data = REALLOC(buf->data, buf->capacity, buf->size); + buf->capacity = buf->size; + } + else { + FREE(buf->data); + buf->data = 0; + buf->capacity = 0; + } + } +} + +#define util_dynarray_append(buf, type, v) do {type __v = (v); memcpy(util_dynarray_grow((buf), sizeof(type)), &__v, sizeof(type));} while(0) +#define util_dynarray_top_ptr(buf, type) (type*)((char*)(buf)->data + (buf)->size - sizeof(type)) +#define util_dynarray_top(buf, type) *util_dynarray_top_ptr(buf, type) +#define util_dynarray_pop_ptr(buf, type) (type*)((char*)(buf)->data + ((buf)->size -= sizeof(type))) +#define util_dynarray_pop(buf, type) *util_dynarray_pop_ptr(buf, type) +#define util_dynarray_contains(buf, type) ((buf)->size >= sizeof(type)) +#define util_dynarray_element(buf, type, idx) ((type*)(buf)->data + (idx)) +#define util_dynarray_begin(buf) ((buf)->data) +#define util_dynarray_end(buf) ((void*)util_dynarray_element((buf), char, (buf)->size)) + +#endif /* U_DYNARRAY_H */ + diff --git a/src/gallium/auxiliary/util/u_fifo.h b/src/gallium/auxiliary/util/u_fifo.h new file mode 100644 index 0000000..9e007de --- /dev/null +++ b/src/gallium/auxiliary/util/u_fifo.h @@ -0,0 +1,94 @@ +/************************************************************************** + * + * Copyright © 2009 Jakob Bornecrantz + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef U_FIFO_H +#define U_FIFO_H + +#include "util/u_memory.h" + +struct util_fifo +{ + size_t head; + size_t tail; + size_t num; + size_t size; +}; + +static INLINE struct util_fifo * +u_fifo_create(size_t size) +{ + struct util_fifo *fifo; + fifo = MALLOC(sizeof(*fifo) + size * sizeof(void*)); + + fifo->head = 0; + fifo->tail = 0; + fifo->num = 0; + fifo->size = size; + + return fifo; +} + +static INLINE boolean +u_fifo_add(struct util_fifo *fifo, void *ptr) +{ + void **array = (void**)&fifo[1]; + if (fifo->num >= fifo->size) + return FALSE; + + if (++fifo->head >= fifo->size) + fifo->head = 0; + + array[fifo->head] = ptr; + + ++fifo->num; + + return TRUE; +} + +static INLINE boolean +u_fifo_pop(struct util_fifo *fifo, void **ptr) +{ + void **array = (void**)&fifo[1]; + + if (!fifo->num) + return FALSE; + + if (++fifo->tail >= fifo->size) + fifo->tail = 0; + + *ptr = array[fifo->tail]; + + ++fifo->num; + + return TRUE; +} + +static INLINE void +u_fifo_destroy(struct util_fifo *fifo) +{ + FREE(fifo); +} + +#endif diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c new file mode 100644 index 0000000..4896faa --- /dev/null +++ b/src/gallium/auxiliary/util/u_format.c @@ -0,0 +1,343 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Pixel format accessor functions. + * + * @author Jose Fonseca + */ + +#include "u_math.h" +#include "u_memory.h" +#include "u_rect.h" +#include "u_format.h" + + +void +util_format_read_4f(enum pipe_format format, + float *dst, unsigned dst_stride, + const void *src, unsigned src_stride, + unsigned x, unsigned y, unsigned w, unsigned h) +{ + const struct util_format_description *format_desc; + const uint8_t *src_row; + float *dst_row; + + format_desc = util_format_description(format); + + assert(x % format_desc->block.width == 0); + assert(y % format_desc->block.height == 0); + + src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8); + dst_row = dst; + + format_desc->unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, w, h); +} + + +void +util_format_write_4f(enum pipe_format format, + const float *src, unsigned src_stride, + void *dst, unsigned dst_stride, + unsigned x, unsigned y, unsigned w, unsigned h) +{ + const struct util_format_description *format_desc; + uint8_t *dst_row; + const float *src_row; + + format_desc = util_format_description(format); + + assert(x % format_desc->block.width == 0); + assert(y % format_desc->block.height == 0); + + dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8); + src_row = src; + + format_desc->pack_rgba_float(dst_row, dst_stride, src_row, src_stride, w, h); +} + + +void +util_format_read_4ub(enum pipe_format format, uint8_t *dst, unsigned dst_stride, const void *src, unsigned src_stride, unsigned x, unsigned y, unsigned w, unsigned h) +{ + const struct util_format_description *format_desc; + const uint8_t *src_row; + uint8_t *dst_row; + + format_desc = util_format_description(format); + + assert(x % format_desc->block.width == 0); + assert(y % format_desc->block.height == 0); + + src_row = (const uint8_t *)src + y*src_stride + x*(format_desc->block.bits/8); + dst_row = dst; + + format_desc->unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, w, h); +} + + +void +util_format_write_4ub(enum pipe_format format, const uint8_t *src, unsigned src_stride, void *dst, unsigned dst_stride, unsigned x, unsigned y, unsigned w, unsigned h) +{ + const struct util_format_description *format_desc; + uint8_t *dst_row; + const uint8_t *src_row; + + format_desc = util_format_description(format); + + assert(x % format_desc->block.width == 0); + assert(y % format_desc->block.height == 0); + + dst_row = (uint8_t *)dst + y*dst_stride + x*(format_desc->block.bits/8); + src_row = src; + + format_desc->pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, w, h); +} + + +boolean +util_is_format_compatible(const struct util_format_description *src_desc, + const struct util_format_description *dst_desc) +{ + unsigned chan; + + if (src_desc->format == dst_desc->format) { + return TRUE; + } + + if (src_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN || + dst_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { + return FALSE; + } + + if (src_desc->block.bits != dst_desc->block.bits || + src_desc->nr_channels != dst_desc->nr_channels || + src_desc->colorspace != dst_desc->colorspace) { + return FALSE; + } + + for (chan = 0; chan < 4; ++chan) { + if (src_desc->channel[chan].size != + dst_desc->channel[chan].size) { + return FALSE; + } + } + + for (chan = 0; chan < 4; ++chan) { + enum util_format_swizzle swizzle = dst_desc->swizzle[chan]; + + if (swizzle < 4) { + if (src_desc->swizzle[chan] != swizzle) { + return FALSE; + } + if ((src_desc->channel[swizzle].type != + dst_desc->channel[swizzle].type) || + (src_desc->channel[swizzle].normalized != + dst_desc->channel[swizzle].normalized)) { + return FALSE; + } + } + } + + return TRUE; +} + + +boolean +util_format_fits_8unorm(const struct util_format_description *format_desc) +{ + unsigned chan; + + /* + * After linearized sRGB values require more than 8bits. + */ + + if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) { + return FALSE; + } + + switch (format_desc->layout) { + + case UTIL_FORMAT_LAYOUT_S3TC: + case UTIL_FORMAT_LAYOUT_RGTC: + /* + * These are straight forward. + */ + + return TRUE; + + case UTIL_FORMAT_LAYOUT_PLAIN: + /* + * For these we can find a generic rule. + */ + + for (chan = 0; chan < format_desc->nr_channels; ++chan) { + switch (format_desc->channel[chan].type) { + case UTIL_FORMAT_TYPE_VOID: + break; + case UTIL_FORMAT_TYPE_UNSIGNED: + if (!format_desc->channel[chan].normalized || + format_desc->channel[chan].size > 8) { + return FALSE; + } + break; + default: + return FALSE; + } + } + return TRUE; + + default: + /* + * Handle all others on a case by case basis. + */ + + switch (format_desc->format) { + case PIPE_FORMAT_R1_UNORM: + case PIPE_FORMAT_UYVY: + case PIPE_FORMAT_YUYV: + case PIPE_FORMAT_R8G8_B8G8_UNORM: + case PIPE_FORMAT_G8R8_G8B8_UNORM: + return TRUE; + + default: + return FALSE; + } + } +} + + +void +util_format_translate(enum pipe_format dst_format, + void *dst, unsigned dst_stride, + unsigned dst_x, unsigned dst_y, + enum pipe_format src_format, + const void *src, unsigned src_stride, + unsigned src_x, unsigned src_y, + unsigned width, unsigned height) +{ + const struct util_format_description *dst_format_desc; + const struct util_format_description *src_format_desc; + uint8_t *dst_row; + const uint8_t *src_row; + unsigned x_step, y_step; + unsigned dst_step; + unsigned src_step; + + dst_format_desc = util_format_description(dst_format); + src_format_desc = util_format_description(src_format); + + if (util_is_format_compatible(src_format_desc, dst_format_desc)) { + /* + * Trivial case. + */ + + util_copy_rect(dst, dst_format, dst_stride, dst_x, dst_y, + width, height, src, (int)src_stride, + src_x, src_y); + return; + } + + assert(dst_x % dst_format_desc->block.width == 0); + assert(dst_y % dst_format_desc->block.height == 0); + assert(src_x % src_format_desc->block.width == 0); + assert(src_y % src_format_desc->block.height == 0); + + dst_row = (uint8_t *)dst + dst_y*dst_stride + dst_x*(dst_format_desc->block.bits/8); + src_row = (const uint8_t *)src + src_y*src_stride + src_x*(src_format_desc->block.bits/8); + + /* + * This works because all pixel formats have pixel blocks with power of two + * sizes. + */ + + y_step = MAX2(dst_format_desc->block.height, src_format_desc->block.height); + x_step = MAX2(dst_format_desc->block.width, src_format_desc->block.width); + assert(y_step % dst_format_desc->block.height == 0); + assert(y_step % src_format_desc->block.height == 0); + + dst_step = y_step / dst_format_desc->block.height * dst_stride; + src_step = y_step / src_format_desc->block.height * src_stride; + + /* + * TODO: double formats will loose precision + * TODO: Add a special case for formats that are mere swizzles of each other + */ + + if (util_format_fits_8unorm(src_format_desc) || + util_format_fits_8unorm(dst_format_desc)) { + unsigned tmp_stride; + uint8_t *tmp_row; + + tmp_stride = MAX2(width, x_step) * 4 * sizeof *tmp_row; + tmp_row = MALLOC(y_step * tmp_stride); + if (!tmp_row) + return; + + while (height >= y_step) { + src_format_desc->unpack_rgba_8unorm(tmp_row, tmp_stride, src_row, src_stride, width, y_step); + dst_format_desc->pack_rgba_8unorm(dst_row, dst_stride, tmp_row, tmp_stride, width, y_step); + + dst_row += dst_step; + src_row += src_step; + height -= y_step; + } + + if (height) { + src_format_desc->unpack_rgba_8unorm(tmp_row, tmp_stride, src_row, src_stride, width, height); + dst_format_desc->pack_rgba_8unorm(dst_row, dst_stride, tmp_row, tmp_stride, width, height); + } + + FREE(tmp_row); + } + else { + unsigned tmp_stride; + float *tmp_row; + + tmp_stride = MAX2(width, x_step) * 4 * sizeof *tmp_row; + tmp_row = MALLOC(y_step * tmp_stride); + if (!tmp_row) + return; + + while (height >= y_step) { + src_format_desc->unpack_rgba_float(tmp_row, tmp_stride, src_row, src_stride, width, y_step); + dst_format_desc->pack_rgba_float(dst_row, dst_stride, tmp_row, tmp_stride, width, y_step); + + dst_row += dst_step; + src_row += src_step; + height -= y_step; + } + + if (height) { + src_format_desc->unpack_rgba_float(tmp_row, tmp_stride, src_row, src_stride, width, height); + dst_format_desc->pack_rgba_float(dst_row, dst_stride, tmp_row, tmp_stride, width, height); + } + + FREE(tmp_row); + } +} diff --git a/src/gallium/auxiliary/util/u_format.csv b/src/gallium/auxiliary/util/u_format.csv new file mode 100644 index 0000000..1fbd838 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format.csv @@ -0,0 +1,235 @@ +########################################################################### +# +# Copyright 2009-2010 VMware, Inc. +# All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sub license, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice (including the +# next paragraph) shall be included in all copies or substantial portions +# of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +# IN NO EVENT SHALL THE 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. +# +########################################################################### + +# This CSV file has the input data for u_format.h's struct +# util_format_description. +# +# Each format entry contains: +# - name, per enum pipe_format +# - layout, per enum util_format_layout, in shortened lower caps +# - pixel block's width +# - pixel block's height +# - channel encoding (only meaningful for plain layout), containing for each +# channel the following information: +# - type, one of +# - 'x': void +# - 'u': unsigned +# - 's': signed +# - 'h': fixed +# - 'f': FLOAT +# - optionally followed by 'n' if it is normalized +# - number of bits +# - channel swizzle +# - color space: rgb, yub, sz +# +# See also: +# - http://msdn.microsoft.com/en-us/library/bb172558.aspx (D3D9) +# - http://msdn.microsoft.com/en-us/library/bb205073.aspx#mapping_texture_formats (D3D9 -> D3D10) +# - http://msdn.microsoft.com/en-us/library/bb173059.aspx (D3D10) +# +# Note that GL doesn't really specify the layout of internal formats. See +# OpenGL 2.1 specification, Table 3.16, on the "Correspondence of sized +# internal formats to base in- ternal formats, and desired component +# resolutions for each sized internal format." + +# None +# Described as regular uint_8 bytes, i.e. PIPE_FORMAT_R8_USCALED +PIPE_FORMAT_NONE , plain, 1, 1, u8 , , , , x001, rgb + +# Typical rendertarget formats +PIPE_FORMAT_B8G8R8A8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , zyxw, rgb +PIPE_FORMAT_B8G8R8X8_UNORM , plain, 1, 1, un8 , un8 , un8 , x8 , zyx1, rgb +PIPE_FORMAT_A8R8G8B8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , yzwx, rgb +PIPE_FORMAT_X8R8G8B8_UNORM , plain, 1, 1, x8 , un8 , un8 , un8 , yzw1, rgb +PIPE_FORMAT_A8B8G8R8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , wzyx, rgb +PIPE_FORMAT_X8B8G8R8_UNORM , plain, 1, 1, x8 , un8 , un8 , un8 , wzy1, rgb +# PIPE_FORMAT_R8G8B8A8_UNORM is below +PIPE_FORMAT_R8G8B8X8_UNORM , plain, 1, 1, un8 , un8 , un8 , x8 , xyz1, rgb +PIPE_FORMAT_B5G5R5X1_UNORM , plain, 1, 1, un5 , un5 , un5 , x1 , zyx1, rgb +PIPE_FORMAT_B5G5R5A1_UNORM , plain, 1, 1, un5 , un5 , un5 , un1 , zyxw, rgb +PIPE_FORMAT_B4G4R4A4_UNORM , plain, 1, 1, un4 , un4 , un4 , un4 , zyxw, rgb +PIPE_FORMAT_B4G4R4X4_UNORM , plain, 1, 1, un4 , un4 , un4 , x4 , zyx1, rgb +PIPE_FORMAT_B5G6R5_UNORM , plain, 1, 1, un5 , un6 , un5 , , zyx1, rgb +PIPE_FORMAT_R10G10B10A2_UNORM , plain, 1, 1, un10, un10, un10, un2 , xyzw, rgb +PIPE_FORMAT_B10G10R10A2_UNORM , plain, 1, 1, un10, un10, un10, un2 , zyxw, rgb + +# Luminance/Intensity/Alpha formats +PIPE_FORMAT_L8_UNORM , plain, 1, 1, un8 , , , , xxx1, rgb +PIPE_FORMAT_A8_UNORM , plain, 1, 1, un8 , , , , 000x, rgb +PIPE_FORMAT_I8_UNORM , plain, 1, 1, un8 , , , , xxxx, rgb +PIPE_FORMAT_L4A4_UNORM , plain, 1, 1, un4 , un4 , , , xxxy, rgb +PIPE_FORMAT_L8A8_UNORM , plain, 1, 1, un8 , un8 , , , xxxy, rgb +PIPE_FORMAT_L16_UNORM , plain, 1, 1, un16, , , , xxx1, rgb + +# SRGB formats +PIPE_FORMAT_L8_SRGB , plain, 1, 1, un8 , , , , xxx1, srgb +PIPE_FORMAT_L8A8_SRGB , plain, 1, 1, un8 , un8 , , , xxxy, srgb +PIPE_FORMAT_R8G8B8_SRGB , plain, 1, 1, un8 , un8 , un8 , , xyz1, srgb +PIPE_FORMAT_R8G8B8A8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , xyzw, srgb +PIPE_FORMAT_A8B8G8R8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , wzyx, srgb +PIPE_FORMAT_X8B8G8R8_SRGB , plain, 1, 1, x8 , un8 , un8 , un8 , wzy1, srgb +PIPE_FORMAT_B8G8R8A8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , zyxw, srgb +PIPE_FORMAT_B8G8R8X8_SRGB , plain, 1, 1, un8 , un8 , un8 , x8 , zyx1, srgb +PIPE_FORMAT_A8R8G8B8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , yzwx, srgb +PIPE_FORMAT_X8R8G8B8_SRGB , plain, 1, 1, x8 , un8 , un8 , un8 , yzw1, srgb + +# Mixed-sign formats (typically used for bump map textures) +PIPE_FORMAT_R8SG8SB8UX8U_NORM , plain, 1, 1, sn8 , sn8 , un8 , x8 , xyz1, rgb +PIPE_FORMAT_R10SG10SB10SA2U_NORM , plain, 1, 1, sn10, sn10, sn10, un2 , xyzw, rgb +PIPE_FORMAT_R5SG5SB6U_NORM , plain, 1, 1, sn5 , sn5 , un6 , , xyz1, rgb + +# Depth-stencil formats +PIPE_FORMAT_S8_USCALED , plain, 1, 1, u8 , , , , _x__, zs +PIPE_FORMAT_Z16_UNORM , plain, 1, 1, un16, , , , x___, zs +PIPE_FORMAT_Z32_UNORM , plain, 1, 1, un32, , , , x___, zs +PIPE_FORMAT_Z32_FLOAT , plain, 1, 1, f32 , , , , x___, zs +PIPE_FORMAT_Z24_UNORM_S8_USCALED , plain, 1, 1, un24, u8 , , , xy__, zs +PIPE_FORMAT_S8_USCALED_Z24_UNORM , plain, 1, 1, u8 , un24, , , yx__, zs +PIPE_FORMAT_X24S8_USCALED , plain, 1, 1, x24, u8 , , , _y__, zs +PIPE_FORMAT_S8X24_USCALED , plain, 1, 1, u8 , x24 , , , _x__, zs +PIPE_FORMAT_Z24X8_UNORM , plain, 1, 1, un24, x8 , , , x___, zs +PIPE_FORMAT_X8Z24_UNORM , plain, 1, 1, x8 , un24, , , y___, zs +PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED , plain, 1, 1, f32, u8 , x24 , , xy__, zs +PIPE_FORMAT_X32_S8X24_USCALED , plain, 1, 1, x32, u8 , x24 , , _y__, zs + +# YUV formats +# http://www.fourcc.org/yuv.php#UYVY +PIPE_FORMAT_UYVY , subsampled, 2, 1, x32 , , , , xyz1, yuv +# http://www.fourcc.org/yuv.php#YUYV (a.k.a http://www.fourcc.org/yuv.php#YUY2) +PIPE_FORMAT_YUYV , subsampled, 2, 1, x32 , , , , xyz1, yuv +# same subsampling but with rgb channels +PIPE_FORMAT_R8G8_B8G8_UNORM , subsampled, 2, 1, x32 , , , , xyz1, rgb +PIPE_FORMAT_G8R8_G8B8_UNORM , subsampled, 2, 1, x32 , , , , xyz1, rgb + +# some special formats not fitting anywhere else +PIPE_FORMAT_R10G10B10A2_USCALED , plain, 1, 1, u10 , u10 , u10 , u2 , xyzw, rgb +PIPE_FORMAT_R11G11B10_FLOAT , plain, 1, 1, f11 , f11 , f10 , , xyz1, rgb +PIPE_FORMAT_R9G9B9E5_FLOAT , other, 1, 1, x32 , , , , xyz1, rgb +PIPE_FORMAT_R1_UNORM , other, 8, 1, x8 , , , , x001, rgb +# A.k.a. D3DFMT_CxV8U8 +PIPE_FORMAT_R8G8Bx_SNORM , other, 1, 1, sn8 , sn8 , , , xyz1, rgb + +# Compressed formats +# - http://en.wikipedia.org/wiki/S3_Texture_Compression +# - http://www.opengl.org/registry/specs/EXT/texture_compression_s3tc.txt +# - http://www.opengl.org/registry/specs/ARB/texture_compression_rgtc.txt +# - http://msdn.microsoft.com/en-us/library/bb694531.aspx +PIPE_FORMAT_DXT1_RGB , s3tc, 4, 4, x64 , , , , xyz1, rgb +PIPE_FORMAT_DXT1_RGBA , s3tc, 4, 4, x64 , , , , xyzw, rgb +PIPE_FORMAT_DXT3_RGBA , s3tc, 4, 4, x128, , , , xyzw, rgb +PIPE_FORMAT_DXT5_RGBA , s3tc, 4, 4, x128, , , , xyzw, rgb +PIPE_FORMAT_DXT1_SRGB , s3tc, 4, 4, x64 , , , , xyz1, srgb +PIPE_FORMAT_DXT1_SRGBA , s3tc, 4, 4, x64 , , , , xyzw, srgb +PIPE_FORMAT_DXT3_SRGBA , s3tc, 4, 4, x128, , , , xyzw, srgb +PIPE_FORMAT_DXT5_SRGBA , s3tc, 4, 4, x128, , , , xyzw, srgb + +PIPE_FORMAT_RGTC1_UNORM , rgtc, 4, 4, x64, , , , x001, rgb +PIPE_FORMAT_RGTC1_SNORM , rgtc, 4, 4, x64, , , , x001, rgb +PIPE_FORMAT_RGTC2_UNORM , rgtc, 4, 4, x128, , , , xy01, rgb +PIPE_FORMAT_RGTC2_SNORM , rgtc, 4, 4, x128, , , , xy01, rgb + +# Straightforward D3D10-like formats (also used for +# vertex buffer element description) +# +# See also: +# - src/gallium/auxiliary/translate/translate_generic.c +# - src/mesa/state_tracker/st_draw.c +PIPE_FORMAT_R64_FLOAT , plain, 1, 1, f64 , , , , x001, rgb +PIPE_FORMAT_R64G64_FLOAT , plain, 1, 1, f64 , f64 , , , xy01, rgb +PIPE_FORMAT_R64G64B64_FLOAT , plain, 1, 1, f64 , f64 , f64 , , xyz1, rgb +PIPE_FORMAT_R64G64B64A64_FLOAT , plain, 1, 1, f64 , f64 , f64 , f64 , xyzw, rgb +PIPE_FORMAT_R32_FLOAT , plain, 1, 1, f32 , , , , x001, rgb +PIPE_FORMAT_R32G32_FLOAT , plain, 1, 1, f32 , f32 , , , xy01, rgb +PIPE_FORMAT_R32G32B32_FLOAT , plain, 1, 1, f32 , f32 , f32 , , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_FLOAT , plain, 1, 1, f32 , f32 , f32 , f32 , xyzw, rgb +PIPE_FORMAT_R32_UNORM , plain, 1, 1, un32, , , , x001, rgb +PIPE_FORMAT_R32G32_UNORM , plain, 1, 1, un32, un32, , , xy01, rgb +PIPE_FORMAT_R32G32B32_UNORM , plain, 1, 1, un32, un32, un32, , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_UNORM , plain, 1, 1, un32, un32, un32, un32, xyzw, rgb +PIPE_FORMAT_R32_USCALED , plain, 1, 1, u32 , , , , x001, rgb +PIPE_FORMAT_R32G32_USCALED , plain, 1, 1, u32 , u32 , , , xy01, rgb +PIPE_FORMAT_R32G32B32_USCALED , plain, 1, 1, u32 , u32 , u32 , , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_USCALED , plain, 1, 1, u32 , u32 , u32 , u32 , xyzw, rgb +PIPE_FORMAT_R32_SNORM , plain, 1, 1, sn32, , , , x001, rgb +PIPE_FORMAT_R32G32_SNORM , plain, 1, 1, sn32, sn32, , , xy01, rgb +PIPE_FORMAT_R32G32B32_SNORM , plain, 1, 1, sn32, sn32, sn32, , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_SNORM , plain, 1, 1, sn32, sn32, sn32, sn32, xyzw, rgb +PIPE_FORMAT_R32_SSCALED , plain, 1, 1, s32 , , , , x001, rgb +PIPE_FORMAT_R32G32_SSCALED , plain, 1, 1, s32 , s32 , , , xy01, rgb +PIPE_FORMAT_R32G32B32_SSCALED , plain, 1, 1, s32 , s32 , s32 , , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_SSCALED , plain, 1, 1, s32 , s32 , s32 , s32 , xyzw, rgb +PIPE_FORMAT_R16_FLOAT , plain, 1, 1, f16 , , , , x001, rgb +PIPE_FORMAT_R16G16_FLOAT , plain, 1, 1, f16 , f16 , , , xy01, rgb +PIPE_FORMAT_R16G16B16_FLOAT , plain, 1, 1, f16 , f16 , f16 , , xyz1, rgb +PIPE_FORMAT_R16G16B16A16_FLOAT , plain, 1, 1, f16 , f16 , f16 , f16 , xyzw, rgb +PIPE_FORMAT_R16_UNORM , plain, 1, 1, un16, , , , x001, rgb +PIPE_FORMAT_R16G16_UNORM , plain, 1, 1, un16, un16, , , xy01, rgb +PIPE_FORMAT_R16G16B16_UNORM , plain, 1, 1, un16, un16, un16, , xyz1, rgb +PIPE_FORMAT_R16G16B16A16_UNORM , plain, 1, 1, un16, un16, un16, un16, xyzw, rgb +PIPE_FORMAT_R16_USCALED , plain, 1, 1, u16 , , , , x001, rgb +PIPE_FORMAT_R16G16_USCALED , plain, 1, 1, u16 , u16 , , , xy01, rgb +PIPE_FORMAT_R16G16B16_USCALED , plain, 1, 1, u16 , u16 , u16 , , xyz1, rgb +PIPE_FORMAT_R16G16B16A16_USCALED , plain, 1, 1, u16 , u16 , u16 , u16 , xyzw, rgb +PIPE_FORMAT_R16_SNORM , plain, 1, 1, sn16, , , , x001, rgb +PIPE_FORMAT_R16G16_SNORM , plain, 1, 1, sn16, sn16, , , xy01, rgb +PIPE_FORMAT_R16G16B16_SNORM , plain, 1, 1, sn16, sn16, sn16, , xyz1, rgb +PIPE_FORMAT_R16G16B16A16_SNORM , plain, 1, 1, sn16, sn16, sn16, sn16, xyzw, rgb +PIPE_FORMAT_R16_SSCALED , plain, 1, 1, s16 , , , , x001, rgb +PIPE_FORMAT_R16G16_SSCALED , plain, 1, 1, s16 , s16 , , , xy01, rgb +PIPE_FORMAT_R16G16B16_SSCALED , plain, 1, 1, s16 , s16 , s16 , , xyz1, rgb +PIPE_FORMAT_R16G16B16A16_SSCALED , plain, 1, 1, s16 , s16 , s16 , s16 , xyzw, rgb +PIPE_FORMAT_R8_UNORM , plain, 1, 1, un8 , , , , x001, rgb +PIPE_FORMAT_R8G8_UNORM , plain, 1, 1, un8 , un8 , , , xy01, rgb +PIPE_FORMAT_R8G8B8_UNORM , plain, 1, 1, un8 , un8 , un8 , , xyz1, rgb +PIPE_FORMAT_R8G8B8A8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , xyzw, rgb +PIPE_FORMAT_R8_USCALED , plain, 1, 1, u8 , , , , x001, rgb +PIPE_FORMAT_R8G8_USCALED , plain, 1, 1, u8 , u8 , , , xy01, rgb +PIPE_FORMAT_R8G8B8_USCALED , plain, 1, 1, u8 , u8 , u8 , , xyz1, rgb +PIPE_FORMAT_R8G8B8A8_USCALED , plain, 1, 1, u8 , u8 , u8 , u8 , xyzw, rgb +PIPE_FORMAT_R8_SNORM , plain, 1, 1, sn8 , , , , x001, rgb +PIPE_FORMAT_R8G8_SNORM , plain, 1, 1, sn8 , sn8 , , , xy01, rgb +PIPE_FORMAT_R8G8B8_SNORM , plain, 1, 1, sn8 , sn8 , sn8 , , xyz1, rgb +PIPE_FORMAT_R8G8B8A8_SNORM , plain, 1, 1, sn8 , sn8 , sn8 , sn8 , xyzw, rgb +PIPE_FORMAT_R8_SSCALED , plain, 1, 1, s8 , , , , x001, rgb +PIPE_FORMAT_R8G8_SSCALED , plain, 1, 1, s8 , s8 , , , xy01, rgb +PIPE_FORMAT_R8G8B8_SSCALED , plain, 1, 1, s8 , s8 , s8 , , xyz1, rgb +PIPE_FORMAT_R8G8B8A8_SSCALED , plain, 1, 1, s8 , s8 , s8 , s8 , xyzw, rgb + +# GL-specific vertex buffer element formats +# A.k.a. GL_FIXED +PIPE_FORMAT_R32_FIXED , plain, 1, 1, h32 , , , , x001, rgb +PIPE_FORMAT_R32G32_FIXED , plain, 1, 1, h32 , h32 , , , xy01, rgb +PIPE_FORMAT_R32G32B32_FIXED , plain, 1, 1, h32 , h32 , h32 , , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_FIXED , plain, 1, 1, h32 , h32 , h32 , h32 , xyzw, rgb + +# D3D9-specific vertex buffer element formats +# See also: +# - http://msdn.microsoft.com/en-us/library/bb172533.aspx +# A.k.a. D3DDECLTYPE_UDEC3 +PIPE_FORMAT_R10G10B10X2_USCALED , plain, 1, 1, u10 , u10 , u10 , x2 , xyz1, rgb +# A.k.a. D3DDECLTYPE_DEC3N +PIPE_FORMAT_R10G10B10X2_SNORM , plain, 1, 1, sn10, sn10, sn10 , x2 , xyz1, rgb diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h new file mode 100644 index 0000000..03b73c0 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format.h @@ -0,0 +1,772 @@ +/************************************************************************** + * + * Copyright 2009-2010 Vmware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef U_FORMAT_H +#define U_FORMAT_H + + +#include "pipe/p_format.h" +#include "util/u_debug.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Describe how to pack/unpack pixels into/from the prescribed format. + * + * XXX: This could be renamed to something like util_format_pack, or broke down + * in flags inside util_format_block that said exactly what we want. + */ +enum util_format_layout { + /** + * Formats with util_format_block::width == util_format_block::height == 1 + * that can be described as an ordinary data structure. + */ + UTIL_FORMAT_LAYOUT_PLAIN = 0, + + /** + * Formats with sub-sampled channels. + * + * This is for formats like YV12 where there is less than one sample per + * pixel. + */ + UTIL_FORMAT_LAYOUT_SUBSAMPLED = 3, + + /** + * S3 Texture Compression formats. + */ + UTIL_FORMAT_LAYOUT_S3TC = 4, + + /** + * Red-Green Texture Compression formats. + */ + UTIL_FORMAT_LAYOUT_RGTC = 5, + + /** + * Everything else that doesn't fit in any of the above layouts. + */ + UTIL_FORMAT_LAYOUT_OTHER = 6 +}; + + +struct util_format_block +{ + /** Block width in pixels */ + unsigned width; + + /** Block height in pixels */ + unsigned height; + + /** Block size in bits */ + unsigned bits; +}; + + +enum util_format_type { + UTIL_FORMAT_TYPE_VOID = 0, + UTIL_FORMAT_TYPE_UNSIGNED = 1, + UTIL_FORMAT_TYPE_SIGNED = 2, + UTIL_FORMAT_TYPE_FIXED = 3, + UTIL_FORMAT_TYPE_FLOAT = 4 +}; + + +enum util_format_swizzle { + UTIL_FORMAT_SWIZZLE_X = 0, + UTIL_FORMAT_SWIZZLE_Y = 1, + UTIL_FORMAT_SWIZZLE_Z = 2, + UTIL_FORMAT_SWIZZLE_W = 3, + UTIL_FORMAT_SWIZZLE_0 = 4, + UTIL_FORMAT_SWIZZLE_1 = 5, + UTIL_FORMAT_SWIZZLE_NONE = 6 +}; + + +enum util_format_colorspace { + UTIL_FORMAT_COLORSPACE_RGB = 0, + UTIL_FORMAT_COLORSPACE_SRGB = 1, + UTIL_FORMAT_COLORSPACE_YUV = 2, + UTIL_FORMAT_COLORSPACE_ZS = 3 +}; + + +struct util_format_channel_description +{ + unsigned type:6; + unsigned normalized:1; + unsigned size:9; +}; + + +struct util_format_description +{ + enum pipe_format format; + + const char *name; + + /** + * Short name, striped of the prefix, lower case. + */ + const char *short_name; + + /** + * Pixel block dimensions. + */ + struct util_format_block block; + + enum util_format_layout layout; + + /** + * The number of channels. + */ + unsigned nr_channels:3; + + /** + * Whether all channels have the same number of (whole) bytes. + */ + unsigned is_array:1; + + /** + * Whether the pixel format can be described as a bitfield structure. + * + * In particular: + * - pixel depth must be 8, 16, or 32 bits; + * - all channels must be unsigned, signed, or void + */ + unsigned is_bitmask:1; + + /** + * Whether channels have mixed types (ignoring UTIL_FORMAT_TYPE_VOID). + */ + unsigned is_mixed:1; + + /** + * Input channel description. + * + * Only valid for UTIL_FORMAT_LAYOUT_PLAIN formats. + */ + struct util_format_channel_description channel[4]; + + /** + * Output channel swizzle. + * + * The order is either: + * - RGBA + * - YUV(A) + * - ZS + * depending on the colorspace. + */ + unsigned char swizzle[4]; + + /** + * Colorspace transformation. + */ + enum util_format_colorspace colorspace; + + /** + * Unpack pixel blocks to R8G8B8A8_UNORM. + * Note: strides are in bytes. + * + * Only defined for non-depth-stencil formats. + */ + void + (*unpack_rgba_8unorm)(uint8_t *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Pack pixel blocks from R8G8B8A8_UNORM. + * Note: strides are in bytes. + * + * Only defined for non-depth-stencil formats. + */ + void + (*pack_rgba_8unorm)(uint8_t *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Fetch a single pixel (i, j) from a block. + * + * XXX: Only defined for a very few select formats. + */ + void + (*fetch_rgba_8unorm)(uint8_t *dst, + const uint8_t *src, + unsigned i, unsigned j); + + /** + * Unpack pixel blocks to R32G32B32A32_FLOAT. + * Note: strides are in bytes. + * + * Only defined for non-depth-stencil formats. + */ + void + (*unpack_rgba_float)(float *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Pack pixel blocks from R32G32B32A32_FLOAT. + * Note: strides are in bytes. + * + * Only defined for non-depth-stencil formats. + */ + void + (*pack_rgba_float)(uint8_t *dst, unsigned dst_stride, + const float *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Fetch a single pixel (i, j) from a block. + * + * Only defined for non-depth-stencil formats. + */ + void + (*fetch_rgba_float)(float *dst, + const uint8_t *src, + unsigned i, unsigned j); + + /** + * Unpack pixels to Z32_UNORM. + * Note: strides are in bytes. + * + * Only defined for depth formats. + */ + void + (*unpack_z_32unorm)(uint32_t *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Pack pixels from Z32_FLOAT. + * Note: strides are in bytes. + * + * Only defined for depth formats. + */ + void + (*pack_z_32unorm)(uint8_t *dst, unsigned dst_stride, + const uint32_t *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Unpack pixels to Z32_FLOAT. + * Note: strides are in bytes. + * + * Only defined for depth formats. + */ + void + (*unpack_z_float)(float *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Pack pixels from Z32_FLOAT. + * Note: strides are in bytes. + * + * Only defined for depth formats. + */ + void + (*pack_z_float)(uint8_t *dst, unsigned dst_stride, + const float *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Unpack pixels to S8_USCALED. + * Note: strides are in bytes. + * + * Only defined for stencil formats. + */ + void + (*unpack_s_8uscaled)(uint8_t *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); + + /** + * Pack pixels from S8_USCALED. + * Note: strides are in bytes. + * + * Only defined for stencil formats. + */ + void + (*pack_s_8uscaled)(uint8_t *dst, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height); + +}; + + +extern const struct util_format_description +util_format_description_table[]; + + +const struct util_format_description * +util_format_description(enum pipe_format format); + + +/* + * Format query functions. + */ + +static INLINE const char * +util_format_name(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return "PIPE_FORMAT_???"; + } + + return desc->name; +} + +static INLINE const char * +util_format_short_name(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return "???"; + } + + return desc->short_name; +} + +/** + * Whether this format is plain, see UTIL_FORMAT_LAYOUT_PLAIN for more info. + */ +static INLINE boolean +util_format_is_plain(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + if (!format) { + return FALSE; + } + + return desc->layout == UTIL_FORMAT_LAYOUT_PLAIN ? TRUE : FALSE; +} + +static INLINE boolean +util_format_is_compressed(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return FALSE; + } + + switch (desc->layout) { + case UTIL_FORMAT_LAYOUT_S3TC: + case UTIL_FORMAT_LAYOUT_RGTC: + /* XXX add other formats in the future */ + return TRUE; + default: + return FALSE; + } +} + +static INLINE boolean +util_format_is_s3tc(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return FALSE; + } + + return desc->layout == UTIL_FORMAT_LAYOUT_S3TC ? TRUE : FALSE; +} + +static INLINE boolean +util_format_is_depth_or_stencil(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return FALSE; + } + + return desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS ? TRUE : FALSE; +} + +static INLINE boolean +util_format_is_depth_and_stencil(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return FALSE; + } + + if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS) { + return FALSE; + } + + return (desc->swizzle[0] != UTIL_FORMAT_SWIZZLE_NONE && + desc->swizzle[1] != UTIL_FORMAT_SWIZZLE_NONE) ? TRUE : FALSE; +} + + +/** + * Give the RGBA colormask of the channels that can be represented in this + * format. + * + * That is, the channels whose values are preserved. + */ +static INLINE unsigned +util_format_colormask(const struct util_format_description *desc) +{ + unsigned colormask; + unsigned chan; + + switch (desc->colorspace) { + case UTIL_FORMAT_COLORSPACE_RGB: + case UTIL_FORMAT_COLORSPACE_SRGB: + case UTIL_FORMAT_COLORSPACE_YUV: + colormask = 0; + for (chan = 0; chan < 4; ++chan) { + if (desc->swizzle[chan] < 4) { + colormask |= (1 << chan); + } + } + return colormask; + case UTIL_FORMAT_COLORSPACE_ZS: + return 0; + default: + assert(0); + return 0; + } +} + + +/** + * Whether the src format can be blitted to destation format with a simple + * memcpy. + */ +boolean +util_is_format_compatible(const struct util_format_description *src_desc, + const struct util_format_description *dst_desc); + + +/** + * Whether this format is a rgab8 variant. + * + * That is, any format that matches the + * + * PIPE_FORMAT_?8?8?8?8_UNORM + */ +static INLINE boolean +util_format_is_rgba8_variant(const struct util_format_description *desc) +{ + unsigned chan; + + if(desc->block.width != 1 || + desc->block.height != 1 || + desc->block.bits != 32) + return FALSE; + + for(chan = 0; chan < 4; ++chan) { + if(desc->channel[chan].type != UTIL_FORMAT_TYPE_UNSIGNED && + desc->channel[chan].type != UTIL_FORMAT_TYPE_VOID) + return FALSE; + if(desc->channel[chan].size != 8) + return FALSE; + } + + return TRUE; +} + + +/** + * Return total bits needed for the pixel format per block. + */ +static INLINE uint +util_format_get_blocksizebits(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return 0; + } + + return desc->block.bits; +} + +/** + * Return bytes per block (not pixel) for the given format. + */ +static INLINE uint +util_format_get_blocksize(enum pipe_format format) +{ + uint bits = util_format_get_blocksizebits(format); + + assert(bits % 8 == 0); + + return bits / 8; +} + +static INLINE uint +util_format_get_blockwidth(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return 1; + } + + return desc->block.width; +} + +static INLINE uint +util_format_get_blockheight(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return 1; + } + + return desc->block.height; +} + +static INLINE unsigned +util_format_get_nblocksx(enum pipe_format format, + unsigned x) +{ + unsigned blockwidth = util_format_get_blockwidth(format); + return (x + blockwidth - 1) / blockwidth; +} + +static INLINE unsigned +util_format_get_nblocksy(enum pipe_format format, + unsigned y) +{ + unsigned blockheight = util_format_get_blockheight(format); + return (y + blockheight - 1) / blockheight; +} + +static INLINE unsigned +util_format_get_nblocks(enum pipe_format format, + unsigned width, + unsigned height) +{ + return util_format_get_nblocksx(format, width) * util_format_get_nblocksy(format, height); +} + +static INLINE size_t +util_format_get_stride(enum pipe_format format, + unsigned width) +{ + return util_format_get_nblocksx(format, width) * util_format_get_blocksize(format); +} + +static INLINE size_t +util_format_get_2d_size(enum pipe_format format, + size_t stride, + unsigned height) +{ + return util_format_get_nblocksy(format, height) * stride; +} + +static INLINE uint +util_format_get_component_bits(enum pipe_format format, + enum util_format_colorspace colorspace, + uint component) +{ + const struct util_format_description *desc = util_format_description(format); + enum util_format_colorspace desc_colorspace; + + assert(format); + if (!format) { + return 0; + } + + assert(component < 4); + + /* Treat RGB and SRGB as equivalent. */ + if (colorspace == UTIL_FORMAT_COLORSPACE_SRGB) { + colorspace = UTIL_FORMAT_COLORSPACE_RGB; + } + if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) { + desc_colorspace = UTIL_FORMAT_COLORSPACE_RGB; + } else { + desc_colorspace = desc->colorspace; + } + + if (desc_colorspace != colorspace) { + return 0; + } + + switch (desc->swizzle[component]) { + case UTIL_FORMAT_SWIZZLE_X: + return desc->channel[0].size; + case UTIL_FORMAT_SWIZZLE_Y: + return desc->channel[1].size; + case UTIL_FORMAT_SWIZZLE_Z: + return desc->channel[2].size; + case UTIL_FORMAT_SWIZZLE_W: + return desc->channel[3].size; + default: + return 0; + } +} + +static INLINE boolean +util_format_has_alpha(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(format); + if (!format) { + return FALSE; + } + + switch (desc->colorspace) { + case UTIL_FORMAT_COLORSPACE_RGB: + case UTIL_FORMAT_COLORSPACE_SRGB: + return desc->swizzle[3] != UTIL_FORMAT_SWIZZLE_1; + case UTIL_FORMAT_COLORSPACE_YUV: + return FALSE; + case UTIL_FORMAT_COLORSPACE_ZS: + return FALSE; + default: + assert(0); + return FALSE; + } +} + +/** + * Return the matching SRGB format, or PIPE_FORMAT_NONE if none. + */ +static INLINE enum pipe_format +util_format_srgb(enum pipe_format format) +{ + switch (format) { + case PIPE_FORMAT_L8_UNORM: + return PIPE_FORMAT_L8_SRGB; + case PIPE_FORMAT_L8A8_UNORM: + return PIPE_FORMAT_L8A8_SRGB; + case PIPE_FORMAT_R8G8B8_UNORM: + return PIPE_FORMAT_R8G8B8_SRGB; + case PIPE_FORMAT_A8B8G8R8_UNORM: + return PIPE_FORMAT_A8B8G8R8_SRGB; + case PIPE_FORMAT_X8B8G8R8_UNORM: + return PIPE_FORMAT_X8B8G8R8_SRGB; + case PIPE_FORMAT_B8G8R8A8_UNORM: + return PIPE_FORMAT_B8G8R8A8_SRGB; + case PIPE_FORMAT_B8G8R8X8_UNORM: + return PIPE_FORMAT_B8G8R8X8_SRGB; + case PIPE_FORMAT_A8R8G8B8_UNORM: + return PIPE_FORMAT_A8R8G8B8_SRGB; + case PIPE_FORMAT_X8R8G8B8_UNORM: + return PIPE_FORMAT_X8R8G8B8_SRGB; + case PIPE_FORMAT_DXT1_RGB: + return PIPE_FORMAT_DXT1_SRGB; + case PIPE_FORMAT_DXT1_RGBA: + return PIPE_FORMAT_DXT1_SRGBA; + case PIPE_FORMAT_DXT3_RGBA: + return PIPE_FORMAT_DXT3_SRGBA; + case PIPE_FORMAT_DXT5_RGBA: + return PIPE_FORMAT_DXT5_SRGBA; + default: + return PIPE_FORMAT_NONE; + } +} + +/** + * Return the number of components stored. + * Formats with block size != 1x1 will always have 1 component (the block). + */ +static INLINE unsigned +util_format_get_nr_components(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + return desc->nr_channels; +} + +/* + * Format access functions. + */ + +void +util_format_read_4f(enum pipe_format format, + float *dst, unsigned dst_stride, + const void *src, unsigned src_stride, + unsigned x, unsigned y, unsigned w, unsigned h); + +void +util_format_write_4f(enum pipe_format format, + const float *src, unsigned src_stride, + void *dst, unsigned dst_stride, + unsigned x, unsigned y, unsigned w, unsigned h); + +void +util_format_read_4ub(enum pipe_format format, + uint8_t *dst, unsigned dst_stride, + const void *src, unsigned src_stride, + unsigned x, unsigned y, unsigned w, unsigned h); + +void +util_format_write_4ub(enum pipe_format format, + const uint8_t *src, unsigned src_stride, + void *dst, unsigned dst_stride, + unsigned x, unsigned y, unsigned w, unsigned h); + +/* + * Generic format conversion; + */ + +boolean +util_format_fits_8unorm(const struct util_format_description *format_desc); + +void +util_format_translate(enum pipe_format dst_format, + void *dst, unsigned dst_stride, + unsigned dst_x, unsigned dst_y, + enum pipe_format src_format, + const void *src, unsigned src_stride, + unsigned src_x, unsigned src_y, + unsigned width, unsigned height); + +#ifdef __cplusplus +} // extern "C" { +#endif + +#endif /* ! U_FORMAT_H */ diff --git a/src/gallium/auxiliary/util/u_format_other.c b/src/gallium/auxiliary/util/u_format_other.c new file mode 100644 index 0000000..fa42ec3 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_other.c @@ -0,0 +1,276 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "u_math.h" +#include "u_format_other.h" + + +void +util_format_r9g9b9e5_float_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + +} + +void +util_format_r9g9b9e5_float_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + +} + +void +util_format_r9g9b9e5_float_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + +} + + +void +util_format_r9g9b9e5_float_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + +} + + +void +util_format_r9g9b9e5_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + +} + + +void +util_format_r1_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + +} + + +void +util_format_r1_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + +} + + +void +util_format_r1_unorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + +} + + +void +util_format_r1_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + +} + + +void +util_format_r1_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ +} + + +/* + * PIPE_FORMAT_R8G8Bx_SNORM + * + * A.k.a. D3DFMT_CxV8U8 + */ + +static uint8_t +r8g8bx_derive(int16_t r, int16_t g) +{ + /* Derive blue from red and green components. + * Apparently, we must always use integers to perform calculations, + * otherwise the results won't match D3D's CxV8U8 definition. + */ + return (uint8_t)sqrtf(0x7f * 0x7f - r * r - g * g) * 0xff / 0x7f; +} + +void +util_format_r8g8bx_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for(y = 0; y < height; y += 1) { + float *dst = dst_row; + const uint16_t *src = (const uint16_t *)src_row; + for(x = 0; x < width; x += 1) { + uint16_t value = *src++; + int16_t r, g; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + r = ((int16_t)(value << 8)) >> 8; + g = ((int16_t)(value << 0)) >> 8; + + dst[0] = (float)(r * (1.0f/0x7f)); /* r */ + dst[1] = (float)(g * (1.0f/0x7f)); /* g */ + dst[2] = r8g8bx_derive(r, g) * (1.0f/0xff); /* b */ + dst[3] = 1.0f; /* a */ + dst += 4; + } + src_row += src_stride; + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_r8g8bx_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; y += 1) { + uint8_t *dst = dst_row; + const uint16_t *src = (const uint16_t *)src_row; + for(x = 0; x < width; x += 1) { + uint16_t value = *src++; + int16_t r, g; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + r = ((int16_t)(value << 8)) >> 8; + g = ((int16_t)(value << 0)) >> 8; + + dst[0] = (uint8_t)(((uint16_t)MAX2(r, 0)) * 0xff / 0x7f); /* r */ + dst[1] = (uint8_t)(((uint16_t)MAX2(g, 0)) * 0xff / 0x7f); /* g */ + dst[2] = r8g8bx_derive(r, g); /* b */ + dst[3] = 255; /* a */ + dst += 4; + } + src_row += src_stride; + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_r8g8bx_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; y += 1) { + const float *src = src_row; + uint16_t *dst = (uint16_t *)dst_row; + for(x = 0; x < width; x += 1) { + uint16_t value = 0; + + value |= (uint16_t)(((int8_t)(CLAMP(src[0], -1, 1) * 0x7f)) & 0xff) ; + value |= (uint16_t)((((int8_t)(CLAMP(src[1], -1, 1) * 0x7f)) & 0xff) << 8) ; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 4; + } + dst_row += dst_stride; + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_r8g8bx_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for(y = 0; y < height; y += 1) { + const uint8_t *src = src_row; + uint16_t *dst = (uint16_t *)dst_row; + for(x = 0; x < width; x += 1) { + uint16_t value = 0; + + value |= src[0] >> 1; + value |= (src[1] >> 1) << 8; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 4; + } + dst_row += dst_stride; + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_r8g8bx_snorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + uint16_t value = *(const uint16_t *)src; + int16_t r, g; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + r = ((int16_t)(value << 8)) >> 8; + g = ((int16_t)(value << 0)) >> 8; + + dst[0] = r * (1.0f/0x7f); /* r */ + dst[1] = g * (1.0f/0x7f); /* g */ + dst[2] = r8g8bx_derive(r, g) * (1.0f/0xff); /* b */ + dst[3] = 1.0f; /* a */ +} diff --git a/src/gallium/auxiliary/util/u_format_other.h b/src/gallium/auxiliary/util/u_format_other.h new file mode 100644 index 0000000..98c97be --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_other.h @@ -0,0 +1,108 @@ +/************************************************************************** + * + * 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 U_FORMAT_OTHER_H_ +#define U_FORMAT_OTHER_H_ + + +#include "pipe/p_compiler.h" + + +void +util_format_r9g9b9e5_float_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r9g9b9e5_float_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r9g9b9e5_float_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + +void +util_format_r9g9b9e5_float_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r9g9b9e5_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r1_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r1_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r1_unorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + +void +util_format_r1_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r1_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8bx_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8bx_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8bx_snorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + +void +util_format_r8g8bx_snorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8bx_snorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +#endif /* U_FORMAT_OTHER_H_ */ diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py new file mode 100644 index 0000000..6d0016c --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -0,0 +1,670 @@ +#!/usr/bin/env python + +''' +/************************************************************************** + * + * Copyright 2009-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Pixel format packing and unpacking functions. + * + * @author Jose Fonseca + */ +''' + + +from u_format_parse import * + + +def generate_format_type(format): + '''Generate a structure that describes the format.''' + + assert format.layout == PLAIN + + print 'union util_format_%s {' % format.short_name() + + if format.block_size() in (8, 16, 32, 64): + print ' uint%u_t value;' % (format.block_size(),) + + use_bitfields = False + for channel in format.channels: + if channel.size % 8 or not is_pot(channel.size): + use_bitfields = True + + print ' struct {' + for channel in format.channels: + if use_bitfields: + if channel.type == VOID: + if channel.size: + print ' unsigned %s:%u;' % (channel.name, channel.size) + elif channel.type == UNSIGNED: + print ' unsigned %s:%u;' % (channel.name, channel.size) + elif channel.type in (SIGNED, FIXED): + print ' int %s:%u;' % (channel.name, channel.size) + elif channel.type == FLOAT: + if channel.size == 64: + print ' double %s;' % (channel.name) + elif channel.size == 32: + print ' float %s;' % (channel.name) + else: + print ' unsigned %s:%u;' % (channel.name, channel.size) + else: + assert 0 + else: + assert channel.size % 8 == 0 and is_pot(channel.size) + if channel.type == VOID: + if channel.size: + print ' uint%u_t %s;' % (channel.size, channel.name) + elif channel.type == UNSIGNED: + print ' uint%u_t %s;' % (channel.size, channel.name) + elif channel.type in (SIGNED, FIXED): + print ' int%u_t %s;' % (channel.size, channel.name) + elif channel.type == FLOAT: + if channel.size == 64: + print ' double %s;' % (channel.name) + elif channel.size == 32: + print ' float %s;' % (channel.name) + elif channel.size == 16: + print ' uint16_t %s;' % (channel.name) + else: + assert 0 + else: + assert 0 + print ' } chan;' + print '};' + print + + +def bswap_format(format): + '''Generate a structure that describes the format.''' + + if format.is_bitmask() and not format.is_array() and format.block_size() > 8: + print '#ifdef PIPE_ARCH_BIG_ENDIAN' + print ' pixel.value = util_bswap%u(pixel.value);' % format.block_size() + print '#endif' + + +def is_format_supported(format): + '''Determines whether we actually have the plumbing necessary to generate the + to read/write to/from this format.''' + + # FIXME: Ideally we would support any format combination here. + + if format.layout != PLAIN: + return False + + for i in range(4): + channel = format.channels[i] + if channel.type not in (VOID, UNSIGNED, SIGNED, FLOAT, FIXED): + return False + if channel.type == FLOAT and channel.size not in (16, 32, 64): + return False + + return True + + +def native_type(format): + '''Get the native appropriate for a format.''' + + if format.layout == PLAIN: + if not format.is_array(): + # For arithmetic pixel formats return the integer type that matches the whole pixel + return 'uint%u_t' % format.block_size() + else: + # For array pixel formats return the integer type that matches the color channel + channel = format.channels[0] + if channel.type in (UNSIGNED, VOID): + return 'uint%u_t' % channel.size + elif channel.type in (SIGNED, FIXED): + return 'int%u_t' % channel.size + elif channel.type == FLOAT: + if channel.size == 16: + return 'uint16_t' + elif channel.size == 32: + return 'float' + elif channel.size == 64: + return 'double' + else: + assert False + else: + assert False + else: + assert False + + +def intermediate_native_type(bits, sign): + '''Find a native type adequate to hold intermediate results of the request bit size.''' + + bytes = 4 # don't use anything smaller than 32bits + while bytes * 8 < bits: + bytes *= 2 + bits = bytes*8 + + if sign: + return 'int%u_t' % bits + else: + return 'uint%u_t' % bits + + +def get_one_shift(type): + '''Get the number of the bit that matches unity for this type.''' + if type.type == 'FLOAT': + assert False + if not type.norm: + return 0 + if type.type == UNSIGNED: + return type.size + if type.type == SIGNED: + return type.size - 1 + if type.type == FIXED: + return type.size / 2 + assert False + + +def value_to_native(type, value): + '''Get the value of unity for this type.''' + if type.type == FLOAT: + return value + if type.type == FIXED: + return int(value * (1 << (type.size/2))) + if not type.norm: + return int(value) + if type.type == UNSIGNED: + return int(value * ((1 << type.size) - 1)) + if type.type == SIGNED: + return int(value * ((1 << (type.size - 1)) - 1)) + assert False + + +def native_to_constant(type, value): + '''Get the value of unity for this type.''' + if type.type == FLOAT: + if type.size <= 32: + return "%ff" % value + else: + return "%ff" % value + else: + return str(int(value)) + + +def get_one(type): + '''Get the value of unity for this type.''' + return value_to_native(type, 1) + + +def clamp_expr(src_channel, dst_channel, dst_native_type, value): + '''Generate the expression to clamp the value in the source type to the + destination type range.''' + + if src_channel == dst_channel: + return value + + src_min = src_channel.min() + src_max = src_channel.max() + dst_min = dst_channel.min() + dst_max = dst_channel.max() + + # Translate the destination range to the src native value + dst_min_native = value_to_native(src_channel, dst_min) + dst_max_native = value_to_native(src_channel, dst_max) + + if src_min < dst_min and src_max > dst_max: + return 'CLAMP(%s, %s, %s)' % (value, dst_min_native, dst_max_native) + + if src_max > dst_max: + return 'MIN2(%s, %s)' % (value, dst_max_native) + + if src_min < dst_min: + return 'MAX2(%s, %s)' % (value, dst_min_native) + + return value + + +def conversion_expr(src_channel, + dst_channel, dst_native_type, + value, + clamp=True, + src_colorspace = RGB, + dst_colorspace = RGB): + '''Generate the expression to convert a value between two types.''' + + if src_colorspace != dst_colorspace: + if src_colorspace == SRGB: + assert src_channel.type == UNSIGNED + assert src_channel.norm + assert src_channel.size == 8 + assert dst_colorspace == RGB + if dst_channel.type == FLOAT: + return 'util_format_srgb_8unorm_to_linear_float(%s)' % value + else: + assert dst_channel.type == UNSIGNED + assert dst_channel.norm + assert dst_channel.size == 8 + return 'util_format_srgb_to_linear_8unorm(%s)' % value + elif dst_colorspace == SRGB: + assert dst_channel.type == UNSIGNED + assert dst_channel.norm + assert dst_channel.size == 8 + assert src_colorspace == RGB + if src_channel.type == FLOAT: + return 'util_format_linear_float_to_srgb_8unorm(%s)' % value + else: + assert src_channel.type == UNSIGNED + assert src_channel.norm + assert src_channel.size == 8 + return 'util_format_linear_to_srgb_8unorm(%s)' % value + elif src_colorspace == ZS: + pass + elif dst_colorspace == ZS: + pass + else: + assert 0 + + if src_channel == dst_channel: + return value + + src_type = src_channel.type + src_size = src_channel.size + src_norm = src_channel.norm + + # Promote half to float + if src_type == FLOAT and src_size == 16: + value = 'util_half_to_float(%s)' % value + src_size = 32 + + # Special case for float <-> ubytes for more accurate results + # Done before clamping since these functions already take care of that + if src_type == UNSIGNED and src_norm and src_size == 8 and dst_channel.type == FLOAT and dst_channel.size == 32: + return 'ubyte_to_float(%s)' % value + if src_type == FLOAT and src_size == 32 and dst_channel.type == UNSIGNED and dst_channel.norm and dst_channel.size == 8: + return 'float_to_ubyte(%s)' % value + + if clamp: + if dst_channel.type != FLOAT or src_type != FLOAT: + value = clamp_expr(src_channel, dst_channel, dst_native_type, value) + + if src_type in (SIGNED, UNSIGNED) and dst_channel.type in (SIGNED, UNSIGNED): + if not src_norm and not dst_channel.norm: + # neither is normalized -- just cast + return '(%s)%s' % (dst_native_type, value) + + src_one = get_one(src_channel) + dst_one = get_one(dst_channel) + + if src_one > dst_one and src_norm and dst_channel.norm: + # We can just bitshift + src_shift = get_one_shift(src_channel) + dst_shift = get_one_shift(dst_channel) + value = '(%s >> %s)' % (value, src_shift - dst_shift) + else: + # We need to rescale using an intermediate type big enough to hold the multiplication of both + tmp_native_type = intermediate_native_type(src_size + dst_channel.size, src_channel.sign and dst_channel.sign) + value = '((%s)%s)' % (tmp_native_type, value) + value = '(%s * 0x%x / 0x%x)' % (value, dst_one, src_one) + value = '(%s)%s' % (dst_native_type, value) + return value + + # Promote to either float or double + if src_type != FLOAT: + if src_norm or src_type == FIXED: + one = get_one(src_channel) + if src_size <= 23: + value = '(%s * (1.0f/0x%x))' % (value, one) + if dst_channel.size <= 32: + value = '(float)%s' % value + src_size = 32 + else: + # bigger than single precision mantissa, use double + value = '(%s * (1.0/0x%x))' % (value, one) + src_size = 64 + src_norm = False + else: + if src_size <= 23 or dst_channel.size <= 32: + value = '(float)%s' % value + src_size = 32 + else: + # bigger than single precision mantissa, use double + value = '(double)%s' % value + src_size = 64 + src_type = FLOAT + + # Convert double or float to non-float + if dst_channel.type != FLOAT: + if dst_channel.norm or dst_channel.type == FIXED: + dst_one = get_one(dst_channel) + if dst_channel.size <= 23: + value = '(%s * 0x%x)' % (value, dst_one) + else: + # bigger than single precision mantissa, use double + value = '(%s * (double)0x%x)' % (value, dst_one) + value = '(%s)%s' % (dst_native_type, value) + else: + # Cast double to float when converting to either half or float + if dst_channel.size <= 32 and src_size > 32: + value = '(float)%s' % value + src_size = 32 + + if dst_channel.size == 16: + value = 'util_float_to_half(%s)' % value + elif dst_channel.size == 64 and src_size < 64: + value = '(double)%s' % value + + return value + + +def generate_unpack_kernel(format, dst_channel, dst_native_type): + + if not is_format_supported(format): + return + + assert format.layout == PLAIN + + src_native_type = native_type(format) + + if format.is_bitmask(): + depth = format.block_size() + print ' uint%u_t value = *(const uint%u_t *)src;' % (depth, depth) + + # Declare the intermediate variables + for i in range(format.nr_channels()): + src_channel = format.channels[i] + if src_channel.type == UNSIGNED: + print ' uint%u_t %s;' % (depth, src_channel.name) + elif src_channel.type == SIGNED: + print ' int%u_t %s;' % (depth, src_channel.name) + + if depth > 8: + print '#ifdef PIPE_ARCH_BIG_ENDIAN' + print ' value = util_bswap%u(value);' % depth + print '#endif' + + # Compute the intermediate unshifted values + shift = 0 + for i in range(format.nr_channels()): + src_channel = format.channels[i] + value = 'value' + if src_channel.type == UNSIGNED: + if shift: + value = '%s >> %u' % (value, shift) + if shift + src_channel.size < depth: + value = '(%s) & 0x%x' % (value, (1 << src_channel.size) - 1) + elif src_channel.type == SIGNED: + if shift + src_channel.size < depth: + # Align the sign bit + lshift = depth - (shift + src_channel.size) + value = '%s << %u' % (value, lshift) + # Cast to signed + value = '(int%u_t)(%s) ' % (depth, value) + if src_channel.size < depth: + # Align the LSB bit + rshift = depth - src_channel.size + value = '(%s) >> %u' % (value, rshift) + else: + value = None + + if value is not None: + print ' %s = %s;' % (src_channel.name, value) + + shift += src_channel.size + + # Convert, swizzle, and store final values + for i in range(4): + swizzle = format.swizzles[i] + if swizzle < 4: + src_channel = format.channels[swizzle] + src_colorspace = format.colorspace + if src_colorspace == SRGB and i == 3: + # Alpha channel is linear + src_colorspace = RGB + value = src_channel.name + value = conversion_expr(src_channel, + dst_channel, dst_native_type, + value, + src_colorspace = src_colorspace) + elif swizzle == SWIZZLE_0: + value = '0' + elif swizzle == SWIZZLE_1: + value = get_one(dst_channel) + elif swizzle == SWIZZLE_NONE: + value = '0' + else: + assert False + print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) + + else: + print ' union util_format_%s pixel;' % format.short_name() + print ' memcpy(&pixel, src, sizeof pixel);' + bswap_format(format) + + for i in range(4): + swizzle = format.swizzles[i] + if swizzle < 4: + src_channel = format.channels[swizzle] + src_colorspace = format.colorspace + if src_colorspace == SRGB and i == 3: + # Alpha channel is linear + src_colorspace = RGB + value = 'pixel.chan.%s' % src_channel.name + value = conversion_expr(src_channel, + dst_channel, dst_native_type, + value, + src_colorspace = src_colorspace) + elif swizzle == SWIZZLE_0: + value = '0' + elif swizzle == SWIZZLE_1: + value = get_one(dst_channel) + elif swizzle == SWIZZLE_NONE: + value = '0' + else: + assert False + print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) + + +def generate_pack_kernel(format, src_channel, src_native_type): + + if not is_format_supported(format): + return + + dst_native_type = native_type(format) + + assert format.layout == PLAIN + + inv_swizzle = format.inv_swizzles() + + if format.is_bitmask(): + depth = format.block_size() + print ' uint%u_t value = 0;' % depth + + shift = 0 + for i in range(4): + dst_channel = format.channels[i] + if inv_swizzle[i] is not None: + value ='src[%u]' % inv_swizzle[i] + dst_colorspace = format.colorspace + if dst_colorspace == SRGB and inv_swizzle[i] == 3: + # Alpha channel is linear + dst_colorspace = RGB + value = conversion_expr(src_channel, + dst_channel, dst_native_type, + value, + dst_colorspace = dst_colorspace) + if dst_channel.type in (UNSIGNED, SIGNED): + if shift + dst_channel.size < depth: + value = '(%s) & 0x%x' % (value, (1 << dst_channel.size) - 1) + if shift: + value = '(%s) << %u' % (value, shift) + if dst_channel.type == SIGNED: + # Cast to unsigned + value = '(uint%u_t)(%s) ' % (depth, value) + else: + value = None + if value is not None: + print ' value |= %s;' % (value) + + shift += dst_channel.size + + if depth > 8: + print '#ifdef PIPE_ARCH_BIG_ENDIAN' + print ' value = util_bswap%u(value);' % depth + print '#endif' + + print ' *(uint%u_t *)dst = value;' % depth + + else: + print ' union util_format_%s pixel;' % format.short_name() + + for i in range(4): + dst_channel = format.channels[i] + width = dst_channel.size + if inv_swizzle[i] is None: + continue + dst_colorspace = format.colorspace + if dst_colorspace == SRGB and inv_swizzle[i] == 3: + # Alpha channel is linear + dst_colorspace = RGB + value ='src[%u]' % inv_swizzle[i] + value = conversion_expr(src_channel, + dst_channel, dst_native_type, + value, + dst_colorspace = dst_colorspace) + print ' pixel.chan.%s = %s;' % (dst_channel.name, value) + + bswap_format(format) + print ' memcpy(dst, &pixel, sizeof pixel);' + + +def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix): + '''Generate the function to unpack pixels from a particular format''' + + name = format.short_name() + + print 'static INLINE void' + print 'util_format_%s_unpack_%s(%s *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)' % (name, dst_suffix, dst_native_type) + print '{' + + if is_format_supported(format): + print ' unsigned x, y;' + print ' for(y = 0; y < height; y += %u) {' % (format.block_height,) + print ' %s *dst = dst_row;' % (dst_native_type) + print ' const uint8_t *src = src_row;' + print ' for(x = 0; x < width; x += %u) {' % (format.block_width,) + + generate_unpack_kernel(format, dst_channel, dst_native_type) + + print ' src += %u;' % (format.block_size() / 8,) + print ' dst += 4;' + print ' }' + print ' src_row += src_stride;' + print ' dst_row += dst_stride/sizeof(*dst_row);' + print ' }' + + print '}' + print + + +def generate_format_pack(format, src_channel, src_native_type, src_suffix): + '''Generate the function to pack pixels to a particular format''' + + name = format.short_name() + + print 'static INLINE void' + print 'util_format_%s_pack_%s(uint8_t *dst_row, unsigned dst_stride, const %s *src_row, unsigned src_stride, unsigned width, unsigned height)' % (name, src_suffix, src_native_type) + print '{' + + if is_format_supported(format): + print ' unsigned x, y;' + print ' for(y = 0; y < height; y += %u) {' % (format.block_height,) + print ' const %s *src = src_row;' % (src_native_type) + print ' uint8_t *dst = dst_row;' + print ' for(x = 0; x < width; x += %u) {' % (format.block_width,) + + generate_pack_kernel(format, src_channel, src_native_type) + + print ' src += 4;' + print ' dst += %u;' % (format.block_size() / 8,) + print ' }' + print ' dst_row += dst_stride;' + print ' src_row += src_stride/sizeof(*src_row);' + print ' }' + + print '}' + print + + +def generate_format_fetch(format, dst_channel, dst_native_type, dst_suffix): + '''Generate the function to unpack pixels from a particular format''' + + name = format.short_name() + + print 'static INLINE void' + print 'util_format_%s_fetch_%s(%s *dst, const uint8_t *src, unsigned i, unsigned j)' % (name, dst_suffix, dst_native_type) + print '{' + + if is_format_supported(format): + generate_unpack_kernel(format, dst_channel, dst_native_type) + + print '}' + print + + +def is_format_hand_written(format): + return format.layout in ('s3tc', 'subsampled', 'other') or format.colorspace == ZS + + +def generate(formats): + print + print '#include "pipe/p_compiler.h"' + print '#include "u_math.h"' + print '#include "u_half.h"' + print '#include "u_format.h"' + print '#include "u_format_other.h"' + print '#include "u_format_srgb.h"' + print '#include "u_format_yuv.h"' + print '#include "u_format_zs.h"' + print + + for format in formats: + if not is_format_hand_written(format): + + if is_format_supported(format): + generate_format_type(format) + + channel = Channel(FLOAT, False, 32) + native_type = 'float' + suffix = 'rgba_float' + + generate_format_unpack(format, channel, native_type, suffix) + generate_format_pack(format, channel, native_type, suffix) + generate_format_fetch(format, channel, native_type, suffix) + + channel = Channel(UNSIGNED, True, 8) + native_type = 'uint8_t' + suffix = 'rgba_8unorm' + + generate_format_unpack(format, channel, native_type, suffix) + generate_format_pack(format, channel, native_type, suffix) + diff --git a/src/gallium/auxiliary/util/u_format_parse.py b/src/gallium/auxiliary/util/u_format_parse.py new file mode 100755 index 0000000..ddb9f24 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_parse.py @@ -0,0 +1,291 @@ +#!/usr/bin/env python + +''' +/************************************************************************** + * + * 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. + * + **************************************************************************/ +''' + + +VOID, UNSIGNED, SIGNED, FIXED, FLOAT = range(5) + +SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W, SWIZZLE_0, SWIZZLE_1, SWIZZLE_NONE, = range(7) + +PLAIN = 'plain' + +RGB = 'rgb' +SRGB = 'srgb' +YUV = 'yuv' +ZS = 'zs' + + +def is_pot(x): + return (x & (x - 1)) == 0 + + +VERY_LARGE = 99999999999999999999999 + + +class Channel: + '''Describe the channel of a color channel.''' + + def __init__(self, type, norm, size, name = ''): + self.type = type + self.norm = norm + self.size = size + self.sign = type in (SIGNED, FIXED, FLOAT) + self.name = name + + def __str__(self): + s = str(self.type) + if self.norm: + s += 'n' + s += str(self.size) + return s + + def __eq__(self, other): + return self.type == other.type and self.norm == other.norm and self.size == other.size + + def max(self): + '''Maximum representable number.''' + if self.type == FLOAT: + return VERY_LARGE + if self.type == FIXED: + return (1 << (self.size/2)) - 1 + if self.norm: + return 1 + if self.type == UNSIGNED: + return (1 << self.size) - 1 + if self.type == SIGNED: + return (1 << (self.size - 1)) - 1 + assert False + + def min(self): + '''Minimum representable number.''' + if self.type == FLOAT: + return -VERY_LARGE + if self.type == FIXED: + return -(1 << (self.size/2)) + if self.type == UNSIGNED: + return 0 + if self.norm: + return -1 + if self.type == SIGNED: + return -(1 << (self.size - 1)) + assert False + + +class Format: + '''Describe a pixel format.''' + + def __init__(self, name, layout, block_width, block_height, channels, swizzles, colorspace): + self.name = name + self.layout = layout + self.block_width = block_width + self.block_height = block_height + self.channels = channels + self.swizzles = swizzles + self.name = name + self.colorspace = colorspace + + def __str__(self): + return self.name + + def short_name(self): + '''Make up a short norm for a format, suitable to be used as suffix in + function names.''' + + name = self.name + if name.startswith('PIPE_FORMAT_'): + name = name[len('PIPE_FORMAT_'):] + name = name.lower() + return name + + def block_size(self): + size = 0 + for channel in self.channels: + size += channel.size + return size + + def nr_channels(self): + nr_channels = 0 + for channel in self.channels: + if channel.size: + nr_channels += 1 + return nr_channels + + def is_array(self): + if self.layout != PLAIN: + return False + ref_channel = self.channels[0] + for channel in self.channels[1:]: + if channel.size and (channel.size != ref_channel.size or channel.size % 8): + return False + return True + + def is_mixed(self): + if self.layout != PLAIN: + return False + ref_channel = self.channels[0] + if ref_channel.type == VOID: + ref_channel = self.channels[1] + for channel in self.channels[1:]: + if channel.type != VOID: + if channel.type != ref_channel.type: + return True + if channel.norm != ref_channel.norm: + return True + return False + + def is_pot(self): + return is_pot(self.block_size()) + + def is_int(self): + if self.layout != PLAIN: + return False + for channel in self.channels: + if channel.type not in (VOID, UNSIGNED, SIGNED): + return False + return True + + def is_float(self): + if self.layout != PLAIN: + return False + for channel in self.channels: + if channel.type not in (VOID, FLOAT): + return False + return True + + def is_bitmask(self): + if self.layout != PLAIN: + return False + if self.block_size() not in (8, 16, 32): + return False + for channel in self.channels: + if channel.type not in (VOID, UNSIGNED, SIGNED): + return False + return True + + def inv_swizzles(self): + '''Return an array[4] of inverse swizzle terms''' + inv_swizzle = [None]*4 + for i in range(4): + swizzle = self.swizzles[i] + if swizzle < 4: + inv_swizzle[swizzle] = i + return inv_swizzle + + def stride(self): + return self.block_size()/8 + + +_type_parse_map = { + '': VOID, + 'x': VOID, + 'u': UNSIGNED, + 's': SIGNED, + 'h': FIXED, + 'f': FLOAT, +} + +_swizzle_parse_map = { + 'x': SWIZZLE_X, + 'y': SWIZZLE_Y, + 'z': SWIZZLE_Z, + 'w': SWIZZLE_W, + '0': SWIZZLE_0, + '1': SWIZZLE_1, + '_': SWIZZLE_NONE, +} + +def parse(filename): + '''Parse the format descrition in CSV format in terms of the + Channel and Format classes above.''' + + stream = open(filename) + formats = [] + for line in stream: + try: + comment = line.index('#') + except ValueError: + pass + else: + line = line[:comment] + line = line.strip() + if not line: + continue + + fields = [field.strip() for field in line.split(',')] + + name = fields[0] + layout = fields[1] + block_width, block_height = map(int, fields[2:4]) + + swizzles = [_swizzle_parse_map[swizzle] for swizzle in fields[8]] + colorspace = fields[9] + + if layout == PLAIN: + names = ['']*4 + if colorspace in (RGB, SRGB): + for i in range(4): + swizzle = swizzles[i] + if swizzle < 4: + names[swizzle] += 'rgba'[i] + elif colorspace == ZS: + for i in range(4): + swizzle = swizzles[i] + if swizzle < 4: + names[swizzle] += 'zs'[i] + else: + assert False + for i in range(4): + if names[i] == '': + names[i] = 'x' + else: + names = ['x', 'y', 'z', 'w'] + + channels = [] + for i in range(0, 4): + field = fields[4 + i] + if field: + type = _type_parse_map[field[0]] + if field[1] == 'n': + norm = True + size = int(field[2:]) + else: + norm = False + size = int(field[1:]) + else: + type = VOID + norm = False + size = 0 + channel = Channel(type, norm, size, names[i]) + channels.append(channel) + + format = Format(name, layout, block_width, block_height, channels, swizzles, colorspace) + formats.append(format) + return formats + diff --git a/src/gallium/auxiliary/util/u_format_s3tc.c b/src/gallium/auxiliary/util/u_format_s3tc.c new file mode 100644 index 0000000..bb989c2 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_s3tc.c @@ -0,0 +1,728 @@ +/************************************************************************** + * + * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. + * Copyright (c) 2008 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 + * 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. + * + **************************************************************************/ + +#include "u_dl.h" +#include "u_math.h" +#include "u_format.h" +#include "u_format_s3tc.h" + + +#if defined(_WIN32) || defined(WIN32) +#define DXTN_LIBNAME "dxtn.dll" +#elif defined(__APPLE__) +#define DXTN_LIBNAME "libtxc_dxtn.dylib" +#else +#define DXTN_LIBNAME "libtxc_dxtn.so" +#endif + + +static void +util_format_dxt1_rgb_fetch_stub(int src_stride, + const uint8_t *src, + int col, int row, + uint8_t *dst) +{ + assert(0); +} + + +static void +util_format_dxt1_rgba_fetch_stub(int src_stride, + const uint8_t *src, + int col, int row, + uint8_t *dst ) +{ + assert(0); +} + + +static void +util_format_dxt3_rgba_fetch_stub(int src_stride, + const uint8_t *src, + int col, int row, + uint8_t *dst ) +{ + assert(0); +} + + +static void +util_format_dxt5_rgba_fetch_stub(int src_stride, + const uint8_t *src, + int col, int row, + uint8_t *dst ) +{ + assert(0); +} + + +static void +util_format_dxtn_pack_stub(int src_comps, + int width, int height, + const uint8_t *src, + enum util_format_dxtn dst_format, + uint8_t *dst, + int dst_stride) +{ + assert(0); +} + + +boolean util_format_s3tc_enabled = FALSE; + +util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch = util_format_dxt1_rgb_fetch_stub; +util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch = util_format_dxt1_rgba_fetch_stub; +util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch = util_format_dxt3_rgba_fetch_stub; +util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch = util_format_dxt5_rgba_fetch_stub; + +util_format_dxtn_pack_t util_format_dxtn_pack = util_format_dxtn_pack_stub; + + +void +util_format_s3tc_init(void) +{ + static boolean first_time = TRUE; + struct util_dl_library *library = NULL; + util_dl_proc fetch_2d_texel_rgb_dxt1; + util_dl_proc fetch_2d_texel_rgba_dxt1; + util_dl_proc fetch_2d_texel_rgba_dxt3; + util_dl_proc fetch_2d_texel_rgba_dxt5; + util_dl_proc tx_compress_dxtn; + + if (!first_time) + return; + first_time = FALSE; + + if (util_format_s3tc_enabled) + return; + + library = util_dl_open(DXTN_LIBNAME); + if (!library) { + debug_printf("couldn't open " DXTN_LIBNAME ", software DXTn " + "compression/decompression unavailable\n"); + return; + } + + fetch_2d_texel_rgb_dxt1 = + util_dl_get_proc_address(library, "fetch_2d_texel_rgb_dxt1"); + fetch_2d_texel_rgba_dxt1 = + util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt1"); + fetch_2d_texel_rgba_dxt3 = + util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt3"); + fetch_2d_texel_rgba_dxt5 = + util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt5"); + tx_compress_dxtn = + util_dl_get_proc_address(library, "tx_compress_dxtn"); + + if (!util_format_dxt1_rgb_fetch || + !util_format_dxt1_rgba_fetch || + !util_format_dxt3_rgba_fetch || + !util_format_dxt5_rgba_fetch || + !util_format_dxtn_pack) { + debug_printf("couldn't reference all symbols in " DXTN_LIBNAME + ", software DXTn compression/decompression " + "unavailable\n"); + util_dl_close(library); + return; + } + + util_format_dxt1_rgb_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgb_dxt1; + util_format_dxt1_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt1; + util_format_dxt3_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt3; + util_format_dxt5_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt5; + util_format_dxtn_pack = (util_format_dxtn_pack_t)tx_compress_dxtn; + util_format_s3tc_enabled = TRUE; +} + + +/* + * Pixel fetch. + */ + +void +util_format_dxt1_rgb_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt1_rgb_fetch(0, src, i, j, dst); +} + +void +util_format_dxt1_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt1_rgba_fetch(0, src, i, j, dst); +} + +void +util_format_dxt3_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt3_rgba_fetch(0, src, i, j, dst); +} + +void +util_format_dxt5_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt5_rgba_fetch(0, src, i, j, dst); +} + +void +util_format_dxt1_rgb_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + uint8_t tmp[4]; + util_format_dxt1_rgb_fetch(0, src, i, j, tmp); + dst[0] = ubyte_to_float(tmp[0]); + dst[1] = ubyte_to_float(tmp[1]); + dst[2] = ubyte_to_float(tmp[2]); + dst[3] = 1.0; +} + +void +util_format_dxt1_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + uint8_t tmp[4]; + util_format_dxt1_rgba_fetch(0, src, i, j, tmp); + dst[0] = ubyte_to_float(tmp[0]); + dst[1] = ubyte_to_float(tmp[1]); + dst[2] = ubyte_to_float(tmp[2]); + dst[3] = ubyte_to_float(tmp[3]); +} + +void +util_format_dxt3_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + uint8_t tmp[4]; + util_format_dxt3_rgba_fetch(0, src, i, j, tmp); + dst[0] = ubyte_to_float(tmp[0]); + dst[1] = ubyte_to_float(tmp[1]); + dst[2] = ubyte_to_float(tmp[2]); + dst[3] = ubyte_to_float(tmp[3]); +} + +void +util_format_dxt5_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + uint8_t tmp[4]; + util_format_dxt5_rgba_fetch(0, src, i, j, tmp); + dst[0] = ubyte_to_float(tmp[0]); + dst[1] = ubyte_to_float(tmp[1]); + dst[2] = ubyte_to_float(tmp[2]); + dst[3] = ubyte_to_float(tmp[3]); +} + + +/* + * Block decompression. + */ + +static INLINE void +util_format_dxtn_rgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height, + util_format_dxtn_fetch_t fetch, + unsigned block_size) +{ + const unsigned bw = 4, bh = 4, comps = 4; + unsigned x, y, i, j; + for(y = 0; y < height; y += bh) { + const uint8_t *src = src_row; + for(x = 0; x < width; x += bw) { + for(j = 0; j < bh; ++j) { + for(i = 0; i < bw; ++i) { + uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*comps; + fetch(0, src, i, j, dst); + } + } + src += block_size; + } + src_row += src_stride; + } +} + +void +util_format_dxt1_rgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride, + src_row, src_stride, + width, height, + util_format_dxt1_rgb_fetch, 8); +} + +void +util_format_dxt1_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride, + src_row, src_stride, + width, height, + util_format_dxt1_rgba_fetch, 8); +} + +void +util_format_dxt3_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride, + src_row, src_stride, + width, height, + util_format_dxt3_rgba_fetch, 16); +} + +void +util_format_dxt5_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + util_format_dxtn_rgb_unpack_rgba_8unorm(dst_row, dst_stride, + src_row, src_stride, + width, height, + util_format_dxt5_rgba_fetch, 16); +} + +static INLINE void +util_format_dxtn_rgb_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height, + util_format_dxtn_fetch_t fetch, + unsigned block_size) +{ + unsigned x, y, i, j; + for(y = 0; y < height; y += 4) { + const uint8_t *src = src_row; + for(x = 0; x < width; x += 4) { + for(j = 0; j < 4; ++j) { + for(i = 0; i < 4; ++i) { + float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4; + uint8_t tmp[4]; + fetch(0, src, i, j, tmp); + dst[0] = ubyte_to_float(tmp[0]); + dst[1] = ubyte_to_float(tmp[1]); + dst[2] = ubyte_to_float(tmp[2]); + dst[3] = ubyte_to_float(tmp[3]); + } + } + src += block_size; + } + src_row += src_stride; + } +} + +void +util_format_dxt1_rgb_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride, + src_row, src_stride, + width, height, + util_format_dxt1_rgb_fetch, 8); +} + +void +util_format_dxt1_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride, + src_row, src_stride, + width, height, + util_format_dxt1_rgba_fetch, 8); +} + +void +util_format_dxt3_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride, + src_row, src_stride, + width, height, + util_format_dxt3_rgba_fetch, 16); +} + +void +util_format_dxt5_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + util_format_dxtn_rgb_unpack_rgba_float(dst_row, dst_stride, + src_row, src_stride, + width, height, + util_format_dxt5_rgba_fetch, 16); +} + + +/* + * Block compression. + */ + +void +util_format_dxt1_rgb_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height) +{ + const unsigned bw = 4, bh = 4, bytes_per_block = 8; + unsigned x, y, i, j, k; + for(y = 0; y < height; y += bh) { + uint8_t *dst = dst_row; + for(x = 0; x < width; x += bw) { + uint8_t tmp[4][4][3]; /* [bh][bw][comps] */ + for(j = 0; j < bh; ++j) { + for(i = 0; i < bw; ++i) { + for(k = 0; k < 3; ++k) { + tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + (x + i)*4 + k]; + } + } + } + util_format_dxtn_pack(3, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGB, dst, 0); + dst += bytes_per_block; + } + dst_row += dst_stride / sizeof(*dst_row); + } +} + +void +util_format_dxt1_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height) +{ + const unsigned bw = 4, bh = 4, comps = 4, bytes_per_block = 8; + unsigned x, y, i, j, k; + for(y = 0; y < height; y += bh) { + uint8_t *dst = dst_row; + for(x = 0; x < width; x += bw) { + uint8_t tmp[4][4][4]; /* [bh][bw][comps] */ + for(j = 0; j < bh; ++j) { + for(i = 0; i < bw; ++i) { + for(k = 0; k < comps; ++k) { + tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + (x + i)*comps + k]; + } + } + } + util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGBA, dst, 0); + dst += bytes_per_block; + } + dst_row += dst_stride / sizeof(*dst_row); + } +} + +void +util_format_dxt3_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height) +{ + const unsigned bw = 4, bh = 4, comps = 4, bytes_per_block = 16; + unsigned x, y, i, j, k; + for(y = 0; y < height; y += bh) { + uint8_t *dst = dst_row; + for(x = 0; x < width; x += bw) { + uint8_t tmp[4][4][4]; /* [bh][bw][comps] */ + for(j = 0; j < bh; ++j) { + for(i = 0; i < bw; ++i) { + for(k = 0; k < comps; ++k) { + tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + (x + i)*comps + k]; + } + } + } + util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT3_RGBA, dst, 0); + dst += bytes_per_block; + } + dst_row += dst_stride / sizeof(*dst_row); + } +} + +void +util_format_dxt5_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src, unsigned src_stride, + unsigned width, unsigned height) +{ + const unsigned bw = 4, bh = 4, comps = 4, bytes_per_block = 16; + unsigned x, y, i, j, k; + + for(y = 0; y < height; y += bh) { + uint8_t *dst = dst_row; + for(x = 0; x < width; x += bw) { + uint8_t tmp[4][4][4]; /* [bh][bw][comps] */ + for(j = 0; j < bh; ++j) { + for(i = 0; i < bw; ++i) { + for(k = 0; k < comps; ++k) { + tmp[j][i][k] = src[(y + j)*src_stride/sizeof(*src) + (x + i)*comps + k]; + } + } + } + util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT5_RGBA, dst, 0); + dst += bytes_per_block; + } + dst_row += dst_stride / sizeof(*dst_row); + } +} + +void +util_format_dxt1_rgb_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y, i, j, k; + for(y = 0; y < height; y += 4) { + uint8_t *dst = dst_row; + for(x = 0; x < width; x += 4) { + uint8_t tmp[4][4][3]; + for(j = 0; j < 4; ++j) { + for(i = 0; i < 4; ++i) { + for(k = 0; k < 3; ++k) { + tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + (x+i)*4 + k]); + } + } + } + util_format_dxtn_pack(3, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGB, dst, 0); + dst += 8; + } + dst_row += 4*dst_stride/sizeof(*dst_row); + } +} + +void +util_format_dxt1_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y, i, j, k; + for(y = 0; y < height; y += 4) { + uint8_t *dst = dst_row; + for(x = 0; x < width; x += 4) { + uint8_t tmp[4][4][4]; + for(j = 0; j < 4; ++j) { + for(i = 0; i < 4; ++i) { + for(k = 0; k < 4; ++k) { + tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + (x+i)*4 + k]); + } + } + } + util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT1_RGBA, dst, 0); + dst += 8; + } + dst_row += 4*dst_stride/sizeof(*dst_row); + } +} + +void +util_format_dxt3_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y, i, j, k; + for(y = 0; y < height; y += 4) { + uint8_t *dst = dst_row; + for(x = 0; x < width; x += 4) { + uint8_t tmp[4][4][4]; + for(j = 0; j < 4; ++j) { + for(i = 0; i < 4; ++i) { + for(k = 0; k < 4; ++k) { + tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + (x+i)*4 + k]); + } + } + } + util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT3_RGBA, dst, 0); + dst += 16; + } + dst_row += 4*dst_stride/sizeof(*dst_row); + } +} + +void +util_format_dxt5_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y, i, j, k; + for(y = 0; y < height; y += 4) { + uint8_t *dst = dst_row; + for(x = 0; x < width; x += 4) { + uint8_t tmp[4][4][4]; + for(j = 0; j < 4; ++j) { + for(i = 0; i < 4; ++i) { + for(k = 0; k < 4; ++k) { + tmp[j][i][k] = float_to_ubyte(src[(y + j)*src_stride/sizeof(*src) + (x+i)*4 + k]); + } + } + } + util_format_dxtn_pack(4, 4, 4, &tmp[0][0][0], UTIL_FORMAT_DXT5_RGBA, dst, 0); + dst += 16; + } + dst_row += 4*dst_stride/sizeof(*dst_row); + } +} + + +/* + * SRGB variants. + * + * FIXME: shunts to RGB for now + */ + +void +util_format_dxt1_srgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgb_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgb_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgb_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgb_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt1_rgb_fetch_rgba_8unorm(dst, src, i, j); +} + +void +util_format_dxt1_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgba_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgba_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt1_rgba_fetch_rgba_8unorm(dst, src, i, j); +} + +void +util_format_dxt3_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt3_rgba_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt3_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt3_rgba_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt3_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt3_rgba_fetch_rgba_8unorm(dst, src, i, j); +} + +void +util_format_dxt5_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt5_rgba_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt5_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt5_rgba_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt5_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt5_rgba_fetch_rgba_8unorm(dst, src, i, j); +} + +void +util_format_dxt1_srgb_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgb_unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgb_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgb_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgb_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt1_rgb_fetch_rgba_float(dst, src, i, j); +} + +void +util_format_dxt1_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgba_unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt1_rgba_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt1_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt1_rgba_fetch_rgba_float(dst, src, i, j); +} + +void +util_format_dxt3_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt3_rgba_unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt3_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt3_rgba_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt3_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt3_rgba_fetch_rgba_float(dst, src, i, j); +} + +void +util_format_dxt5_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt5_rgba_unpack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt5_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_dxt5_rgba_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height); +} + +void +util_format_dxt5_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j) +{ + util_format_dxt5_rgba_fetch_rgba_float(dst, src, i, j); +} + diff --git a/src/gallium/auxiliary/util/u_format_s3tc.h b/src/gallium/auxiliary/util/u_format_s3tc.h new file mode 100644 index 0000000..97770ab --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_s3tc.h @@ -0,0 +1,218 @@ +/************************************************************************** + * + * 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 U_FORMAT_S3TC_H_ +#define U_FORMAT_S3TC_H_ + + +#include "pipe/p_compiler.h" + + +enum util_format_dxtn { + UTIL_FORMAT_DXT1_RGB = 0x83F0, + UTIL_FORMAT_DXT1_RGBA = 0x83F1, + UTIL_FORMAT_DXT3_RGBA = 0x83F2, + UTIL_FORMAT_DXT5_RGBA = 0x83F3 +}; + + +typedef void +(*util_format_dxtn_fetch_t)( int src_stride, + const uint8_t *src, + int col, int row, + uint8_t *dst ); + +typedef void +(*util_format_dxtn_pack_t)( int src_comps, + int width, int height, + const uint8_t *src, + enum util_format_dxtn dst_format, + uint8_t *dst, + int dst_stride); + +extern boolean util_format_s3tc_enabled; + +extern util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch; +extern util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch; +extern util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch; +extern util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch; + +extern util_format_dxtn_pack_t util_format_dxtn_pack; + + +void +util_format_s3tc_init(void); + + +void +util_format_dxt1_rgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgb_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgb_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt3_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt5_rgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_rgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_rgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_srgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgb_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgb_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt3_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt5_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_srgba_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j); + + +void +util_format_dxt1_rgb_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgb_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgb_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt3_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt5_rgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_rgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_rgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_srgb_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgb_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgb_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt1_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt1_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt3_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt3_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + +void +util_format_dxt5_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_dxt5_srgba_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j); + + +#endif /* U_FORMAT_S3TC_H_ */ diff --git a/src/gallium/auxiliary/util/u_format_srgb.h b/src/gallium/auxiliary/util/u_format_srgb.h new file mode 100644 index 0000000..43213fb --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_srgb.h @@ -0,0 +1,106 @@ +/************************************************************************** + * + * 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 + * SRGB translation. + * + * @author Brian Paul + * @author Michal Krol + * @author Jose Fonseca + */ + +#ifndef U_FORMAT_SRGB_H_ +#define U_FORMAT_SRGB_H_ + + +#include "pipe/p_compiler.h" +#include "u_math.h" + + +extern const float +util_format_srgb_8unorm_to_linear_float_table[256]; + +extern const uint8_t +util_format_srgb_to_linear_8unorm_table[256]; + +extern const uint8_t +util_format_linear_to_srgb_8unorm_table[256]; + + +/** + * Convert a unclamped linear float to srgb value in the [0,255]. + * XXX this hasn't been tested (render to srgb surface). + * XXX this needs optimization. + */ +static INLINE uint8_t +util_format_linear_float_to_srgb_8unorm(float x) +{ + if (x >= 1.0f) + return 255; + else if (x >= 0.0031308f) + return float_to_ubyte(1.055f * powf(x, 0.41666f) - 0.055f); + else if (x > 0.0f) + return float_to_ubyte(12.92f * x); + else + return 0; +} + + +/** + * Convert an 8-bit sRGB value from non-linear space to a + * linear RGB value in [0, 1]. + * Implemented with a 256-entry lookup table. + */ +static INLINE float +util_format_srgb_8unorm_to_linear_float(uint8_t x) +{ + return util_format_srgb_8unorm_to_linear_float_table[x]; +} + + +/** + * Convert a 8bit normalized value from linear to srgb. + */ +static INLINE uint8_t +util_format_linear_to_srgb_8unorm(uint8_t x) +{ + return util_format_linear_to_srgb_8unorm_table[x]; +} + + +/** + * Convert a 8bit normalized value from srgb to linear. + */ +static INLINE uint8_t +util_format_srgb_to_linear_8unorm(uint8_t x) +{ + return util_format_srgb_to_linear_8unorm_table[x]; +} + + +#endif /* U_FORMAT_SRGB_H_ */ diff --git a/src/gallium/auxiliary/util/u_format_srgb.py b/src/gallium/auxiliary/util/u_format_srgb.py new file mode 100644 index 0000000..cd63ae7 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_srgb.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python + +CopyRight = ''' +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * SRGB translation. + * + * @author Brian Paul + * @author Michal Krol + * @author Jose Fonseca + */ +''' + + +import math + + +def srgb_to_linear(x): + if x <= 0.04045: + return x / 12.92 + else: + return math.pow((x + 0.055) / 1.055, 2.4) + + +def linear_to_srgb(x): + if x >= 0.0031308: + return 1.055 * math.pow(x, 0.41666) - 0.055 + else: + return 12.92 * x + +def generate_srgb_tables(): + print 'const float' + print 'util_format_srgb_8unorm_to_linear_float_table[256] = {' + for j in range(0, 256, 4): + print ' ', + for i in range(j, j + 4): + print '%.7e,' % (srgb_to_linear(i / 255.0),), + print + print '};' + print + print 'const uint8_t' + print 'util_format_srgb_to_linear_8unorm_table[256] = {' + for j in range(0, 256, 16): + print ' ', + for i in range(j, j + 16): + print '%3u,' % (int(srgb_to_linear(i / 255.0) * 255.0 + 0.5),), + print + print '};' + print + print 'const uint8_t' + print 'util_format_linear_to_srgb_8unorm_table[256] = {' + for j in range(0, 256, 16): + print ' ', + for i in range(j, j + 16): + print '%3u,' % (int(linear_to_srgb(i / 255.0) * 255.0 + 0.5),), + print + print '};' + print + + +def main(): + print '/* This file is autogenerated by u_format_srgb.py. Do not edit directly. */' + print + # This will print the copyright message on the top of this file + print CopyRight.strip() + print + print '#include "u_format_srgb.h"' + print + generate_srgb_tables() + + +if __name__ == '__main__': + main() diff --git a/src/gallium/auxiliary/util/u_format_table.py b/src/gallium/auxiliary/util/u_format_table.py new file mode 100755 index 0000000..8cc22a5 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_table.py @@ -0,0 +1,195 @@ +#!/usr/bin/env python + +CopyRight = ''' +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +''' + + +import sys + +from u_format_parse import * +import u_format_pack + + +def layout_map(layout): + return 'UTIL_FORMAT_LAYOUT_' + str(layout).upper() + + +def colorspace_map(colorspace): + return 'UTIL_FORMAT_COLORSPACE_' + str(colorspace).upper() + + +colorspace_channels_map = { + 'rgb': ['r', 'g', 'b', 'a'], + 'srgb': ['sr', 'sg', 'sb', 'a'], + 'zs': ['z', 's'], + 'yuv': ['y', 'u', 'v'], +} + + +type_map = { + VOID: "UTIL_FORMAT_TYPE_VOID", + UNSIGNED: "UTIL_FORMAT_TYPE_UNSIGNED", + SIGNED: "UTIL_FORMAT_TYPE_SIGNED", + FIXED: "UTIL_FORMAT_TYPE_FIXED", + FLOAT: "UTIL_FORMAT_TYPE_FLOAT", +} + + +def bool_map(value): + if value: + return "TRUE" + else: + return "FALSE" + + +swizzle_map = { + SWIZZLE_X: "UTIL_FORMAT_SWIZZLE_X", + SWIZZLE_Y: "UTIL_FORMAT_SWIZZLE_Y", + SWIZZLE_Z: "UTIL_FORMAT_SWIZZLE_Z", + SWIZZLE_W: "UTIL_FORMAT_SWIZZLE_W", + SWIZZLE_0: "UTIL_FORMAT_SWIZZLE_0", + SWIZZLE_1: "UTIL_FORMAT_SWIZZLE_1", + SWIZZLE_NONE: "UTIL_FORMAT_SWIZZLE_NONE", +} + + +def write_format_table(formats): + print '/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */' + print + # This will print the copyright message on the top of this file + print CopyRight.strip() + print + print '#include "u_format.h"' + print '#include "u_format_s3tc.h"' + print + + u_format_pack.generate(formats) + + for format in formats: + print 'const struct util_format_description' + print 'util_format_%s_description = {' % (format.short_name(),) + print " %s," % (format.name,) + print " \"%s\"," % (format.name,) + print " \"%s\"," % (format.short_name(),) + print " {%u, %u, %u},\t/* block */" % (format.block_width, format.block_height, format.block_size()) + print " %s," % (layout_map(format.layout),) + print " %u,\t/* nr_channels */" % (format.nr_channels(),) + print " %s,\t/* is_array */" % (bool_map(format.is_array()),) + print " %s,\t/* is_bitmask */" % (bool_map(format.is_bitmask()),) + print " %s,\t/* is_mixed */" % (bool_map(format.is_mixed()),) + print " {" + for i in range(4): + channel = format.channels[i] + if i < 3: + sep = "," + else: + sep = "" + if channel.size: + print " {%s, %s, %u}%s\t/* %s = %s */" % (type_map[channel.type], bool_map(channel.norm), channel.size, sep, "xyzw"[i], channel.name) + else: + print " {0, 0, 0}%s" % (sep,) + print " }," + print " {" + for i in range(4): + swizzle = format.swizzles[i] + if i < 3: + sep = "," + else: + sep = "" + try: + comment = colorspace_channels_map[format.colorspace][i] + except (KeyError, IndexError): + comment = 'ignored' + print " %s%s\t/* %s */" % (swizzle_map[swizzle], sep, comment) + print " }," + print " %s," % (colorspace_map(format.colorspace),) + if format.colorspace != ZS: + print " &util_format_%s_unpack_rgba_8unorm," % format.short_name() + print " &util_format_%s_pack_rgba_8unorm," % format.short_name() + if format.layout == 's3tc': + print " &util_format_%s_fetch_rgba_8unorm," % format.short_name() + else: + print " NULL, /* fetch_rgba_8unorm */" + print " &util_format_%s_unpack_rgba_float," % format.short_name() + print " &util_format_%s_pack_rgba_float," % format.short_name() + print " &util_format_%s_fetch_rgba_float," % format.short_name() + else: + print " NULL, /* unpack_rgba_8unorm */" + print " NULL, /* pack_rgba_8unorm */" + print " NULL, /* fetch_rgba_8unorm */" + print " NULL, /* unpack_rgba_float */" + print " NULL, /* pack_rgba_float */" + print " NULL, /* fetch_rgba_float */" + if format.colorspace == ZS and format.swizzles[0] != SWIZZLE_NONE: + print " &util_format_%s_unpack_z_32unorm," % format.short_name() + print " &util_format_%s_pack_z_32unorm," % format.short_name() + print " &util_format_%s_unpack_z_float," % format.short_name() + print " &util_format_%s_pack_z_float," % format.short_name() + else: + print " NULL, /* unpack_z_32unorm */" + print " NULL, /* pack_z_32unorm */" + print " NULL, /* unpack_z_float */" + print " NULL, /* pack_z_float */" + if format.colorspace == ZS and format.swizzles[1] != SWIZZLE_NONE: + print " &util_format_%s_unpack_s_8uscaled," % format.short_name() + print " &util_format_%s_pack_s_8uscaled" % format.short_name() + else: + print " NULL, /* unpack_s_8uscaled */" + print " NULL /* pack_s_8uscaled */" + print "};" + print + + print "const struct util_format_description *" + print "util_format_description(enum pipe_format format)" + print "{" + print " if (format >= PIPE_FORMAT_COUNT) {" + print " return NULL;" + print " }" + print + print " switch (format) {" + for format in formats: + print " case %s:" % format.name + print " return &util_format_%s_description;" % (format.short_name(),) + print " default:" + print " return NULL;" + print " }" + print "}" + print + + +def main(): + + formats = [] + for arg in sys.argv[1:]: + formats.extend(parse(arg)) + write_format_table(formats) + + +if __name__ == '__main__': + main() diff --git a/src/gallium/auxiliary/util/u_format_tests.c b/src/gallium/auxiliary/util/u_format_tests.c new file mode 100644 index 0000000..b1df6c4 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_tests.c @@ -0,0 +1,970 @@ +/************************************************************************** + * + * Copyright 2009-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "u_memory.h" +#include "u_format_tests.h" + + +/* + * Helper macros to create the packed bytes for longer words. + */ + +#define PACKED_1x8(x) {x, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_2x8(x, y) {x, y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_3x8(x, y, z) {x, y, z, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_4x8(x, y, z, w) {x, y, z, w, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_8x8(a, b, c, d, e, f, g, h) {a, b, c, d, e, f, g, h, 0, 0, 0, 0, 0, 0, 0, 0} + +#define PACKED_1x16(x) {(x) & 0xff, (x) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_2x16(x, y) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_3x16(x, y, z) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, (z) & 0xff, (z) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_4x16(x, y, z, w) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, (z) & 0xff, (z) >> 8, (w) & 0xff, (w) >> 8, 0, 0, 0, 0, 0, 0, 0, 0} + +#define PACKED_1x32(x) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_2x32(x, y) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_3x32(x, y, z) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, (z) & 0xff, ((z) >> 8) & 0xff, ((z) >> 16) & 0xff, (z) >> 24, 0, 0, 0, 0} +#define PACKED_4x32(x, y, z, w) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, (z) & 0xff, ((z) >> 8) & 0xff, ((z) >> 16) & 0xff, (z) >> 24, (w) & 0xff, ((w) >> 8) & 0xff, ((w) >> 16) & 0xff, (w) >> 24} + +#define UNPACKED_1x1(r, g, b, a) \ + {{{r, g, b, a}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, \ + {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, \ + {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, \ + {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}} + +#define UNPACKED_2x1(r0, g0, b0, a0, r1, g1, b1, a1) \ + {{{r0, g0, b0, a0}, {r1, g1, b1, a1}, {0, 0, 0, 0}, {0, 0, 0, 0}}, \ + {{ 0, 0, 0, 0}, { 0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, \ + {{ 0, 0, 0, 0}, { 0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, \ + {{ 0, 0, 0, 0}, { 0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}} + + +/** + * Test cases. + * + * These were manually entered. We could generate these + * + * To keep this to a we cover only the corner cases, which should produce + * good enough coverage since that pixel format transformations are afine for + * non SRGB formats. + */ +const struct util_format_test_case +util_format_test_cases[] = +{ + + /* + * 32-bit rendertarget formats + */ + + {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x000000ff), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x0000ff00), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00ff0000), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xff000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x000000ff), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000ff00), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00ff0000), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xff000000), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x000000ff), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000ff00), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00ff0000), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xff000000), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R8G8B8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x000000ff), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x0000ff00), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00ff0000), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R8G8B8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xff000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000003ff), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000ffc00), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x3ff00000), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xc0000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_B10G10R10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_B10G10R10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000003ff), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_B10G10R10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000ffc00), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_B10G10R10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x3ff00000), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_B10G10R10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xc0000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B10G10R10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + /* + * 16-bit rendertarget formats + */ + + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x001f), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x03e0), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x7c00), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x7fff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x03e0), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x7c00), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x8000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_B4G4R4X4_UNORM, PACKED_1x16(0x0fff), PACKED_1x16(0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B4G4R4X4_UNORM, PACKED_1x16(0x0fff), PACKED_1x16(0x000f), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_B4G4R4X4_UNORM, PACKED_1x16(0x0fff), PACKED_1x16(0x00f0), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_B4G4R4X4_UNORM, PACKED_1x16(0x0fff), PACKED_1x16(0x0f00), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B4G4R4X4_UNORM, PACKED_1x16(0x0fff), PACKED_1x16(0x0fff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x000f), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x00f0), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0f00), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xf000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x07e0), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xf800), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + /* + * Luminance/intensity/alpha formats + */ + + {PIPE_FORMAT_L8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_L8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_A8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_I8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_I8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_L4A4_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_L4A4_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x0f), UNPACKED_1x1(1.0, 1.0, 1.0, 0.0)}, + {PIPE_FORMAT_L4A4_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xf0), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_L4A4_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x00ff), UNPACKED_1x1(1.0, 1.0, 1.0, 0.0)}, + {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xff00), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_L16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_L16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + /* + * SRGB formats + */ + + {PIPE_FORMAT_L8_SRGB, PACKED_1x8(0xff), PACKED_1x8(0x00), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_L8_SRGB, PACKED_1x8(0xff), PACKED_1x8(0xbc), UNPACKED_1x1(0.502886458033, 0.502886458033, 0.502886458033, 1.0)}, + {PIPE_FORMAT_L8_SRGB, PACKED_1x8(0xff), PACKED_1x8(0xff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_L8A8_SRGB, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_L8A8_SRGB, PACKED_1x16(0xffff), PACKED_1x16(0x00bc), UNPACKED_1x1(0.502886458033, 0.502886458033, 0.502886458033, 0.0)}, + {PIPE_FORMAT_L8A8_SRGB, PACKED_1x16(0xffff), PACKED_1x16(0x00ff), UNPACKED_1x1(1.0, 1.0, 1.0, 0.0)}, + {PIPE_FORMAT_L8A8_SRGB, PACKED_1x16(0xffff), PACKED_1x16(0xcc00), UNPACKED_1x1(0.0, 0.0, 0.0, 0.8)}, + {PIPE_FORMAT_L8A8_SRGB, PACKED_1x16(0xffff), PACKED_1x16(0xff00), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_L8A8_SRGB, PACKED_1x16(0xffff), PACKED_1x16(0xffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R8G8B8_SRGB, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SRGB, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xbc, 0x00, 0x00), UNPACKED_1x1(0.502886458033, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SRGB, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0x00, 0x00), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SRGB, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0xbc, 0x00), UNPACKED_1x1(0.0, 0.502886458033, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SRGB, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0xff, 0x00), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SRGB, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0xbc), UNPACKED_1x1(0.0, 0.0, 0.502886458033, 1.0)}, + {PIPE_FORMAT_R8G8B8_SRGB, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0xff), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SRGB, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0xff, 0xff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R8G8B8A8_SRGB, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SRGB, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xbc, 0x00, 0x00, 0x00), UNPACKED_1x1(0.502886458033, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SRGB, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0x00, 0x00, 0x00), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SRGB, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0xbc, 0x00, 0x00), UNPACKED_1x1(0.0, 0.502886458033, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SRGB, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0xff, 0x00, 0x00), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SRGB, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0xbc, 0x00), UNPACKED_1x1(0.0, 0.0, 0.502886458033, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SRGB, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0xff, 0x00), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SRGB, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0xcc), UNPACKED_1x1(0.0, 0.0, 0.0, 0.8)}, + {PIPE_FORMAT_R8G8B8A8_SRGB, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0xff), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8A8_SRGB, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0xff, 0xff, 0xff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_B8G8R8A8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_B8G8R8A8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000bc), UNPACKED_1x1(0.0, 0.0, 0.502886458033, 0.0)}, + {PIPE_FORMAT_B8G8R8A8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_B8G8R8A8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000bc00), UNPACKED_1x1(0.0, 0.502886458033, 0.0, 0.0)}, + {PIPE_FORMAT_B8G8R8A8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_B8G8R8A8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x00bc0000), UNPACKED_1x1(0.502886458033, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_B8G8R8A8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_B8G8R8A8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0xcc000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.8)}, + {PIPE_FORMAT_B8G8R8A8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B8G8R8A8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_B8G8R8X8_SRGB, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B8G8R8X8_SRGB, PACKED_1x32(0x00ffffff), PACKED_1x32(0x000000bc), UNPACKED_1x1(0.0, 0.0, 0.502886458033, 1.0)}, + {PIPE_FORMAT_B8G8R8X8_SRGB, PACKED_1x32(0x00ffffff), PACKED_1x32(0x000000ff), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_B8G8R8X8_SRGB, PACKED_1x32(0x00ffffff), PACKED_1x32(0x0000bc00), UNPACKED_1x1(0.0, 0.502886458033, 0.0, 1.0)}, + {PIPE_FORMAT_B8G8R8X8_SRGB, PACKED_1x32(0x00ffffff), PACKED_1x32(0x0000ff00), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_B8G8R8X8_SRGB, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00bc0000), UNPACKED_1x1(0.502886458033, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B8G8R8X8_SRGB, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00ff0000), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_B8G8R8X8_SRGB, PACKED_1x32(0x00ffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_A8R8G8B8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8R8G8B8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000cc), UNPACKED_1x1(0.0, 0.0, 0.0, 0.8)}, + {PIPE_FORMAT_A8R8G8B8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_A8R8G8B8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000bc00), UNPACKED_1x1(0.502886458033, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8R8G8B8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8R8G8B8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x00bc0000), UNPACKED_1x1(0.0, 0.502886458033, 0.0, 0.0)}, + {PIPE_FORMAT_A8R8G8B8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8R8G8B8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0xbc000000), UNPACKED_1x1(0.0, 0.0, 0.502886458033, 0.0)}, + {PIPE_FORMAT_A8R8G8B8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_A8R8G8B8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_X8R8G8B8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8R8G8B8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000bc00), UNPACKED_1x1(0.502886458033, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8R8G8B8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000ff00), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8R8G8B8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0x00bc0000), UNPACKED_1x1(0.0, 0.502886458033, 0.0, 1.0)}, + {PIPE_FORMAT_X8R8G8B8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0x00ff0000), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8R8G8B8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0xbc000000), UNPACKED_1x1(0.0, 0.0, 0.502886458033, 1.0)}, + {PIPE_FORMAT_X8R8G8B8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0xff000000), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_X8R8G8B8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_A8B8G8R8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8B8G8R8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000cc), UNPACKED_1x1(0.0, 0.0, 0.0, 0.8)}, + {PIPE_FORMAT_A8B8G8R8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_A8B8G8R8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000bc00), UNPACKED_1x1(0.0, 0.0, 0.502886458033, 0.0)}, + {PIPE_FORMAT_A8B8G8R8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_A8B8G8R8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x00bc0000), UNPACKED_1x1(0.0, 0.502886458033, 0.0, 0.0)}, + {PIPE_FORMAT_A8B8G8R8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8B8G8R8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0xbc000000), UNPACKED_1x1(0.502886458033, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8B8G8R8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_A8B8G8R8_SRGB, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_X8B8G8R8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8B8G8R8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000bc00), UNPACKED_1x1(0.0, 0.0, 0.502886458033, 1.0)}, + {PIPE_FORMAT_X8B8G8R8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000ff00), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_X8B8G8R8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0x00bc0000), UNPACKED_1x1(0.0, 0.502886458033, 0.0, 1.0)}, + {PIPE_FORMAT_X8B8G8R8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0x00ff0000), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8B8G8R8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0xbc000000), UNPACKED_1x1(0.502886458033, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8B8G8R8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0xff000000), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_X8B8G8R8_SRGB, PACKED_1x32(0xffffff00), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + /* + * Mixed-signed formats + */ + + {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_4x8(0xff, 0xff, 0xff, 0x00), PACKED_4x8(0x00, 0x00, 0x00, 0x00), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_4x8(0xff, 0xff, 0xff, 0x00), PACKED_4x8(0x7f, 0x00, 0x00, 0x00), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_4x8(0xff, 0xff, 0xff, 0x00), PACKED_4x8(0x81, 0x00, 0x00, 0x00), UNPACKED_1x1(-1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_4x8(0xff, 0xff, 0xff, 0x00), PACKED_4x8(0x00, 0x7f, 0x00, 0x00), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_4x8(0xff, 0xff, 0xff, 0x00), PACKED_4x8(0x00, 0x81, 0x00, 0x00), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_4x8(0xff, 0xff, 0xff, 0x00), PACKED_4x8(0x00, 0x00, 0xff, 0x00), UNPACKED_1x1( 0.0, 0.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R10SG10SB10SA2U_NORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R10SG10SB10SA2U_NORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000001ff), UNPACKED_1x1( 1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R10SG10SB10SA2U_NORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000201), UNPACKED_1x1(-1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R10SG10SB10SA2U_NORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0007fc00), UNPACKED_1x1( 0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R10SG10SB10SA2U_NORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00080400), UNPACKED_1x1( 0.0, -1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R10SG10SB10SA2U_NORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x1ff00000), UNPACKED_1x1( 0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_R10SG10SB10SA2U_NORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x20100000), UNPACKED_1x1( 0.0, 0.0, -1.0, 0.0)}, + {PIPE_FORMAT_R10SG10SB10SA2U_NORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xc0000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x000f), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0011), UNPACKED_1x1(-1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x01e0), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0220), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0xfc00), UNPACKED_1x1( 0.0, 0.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R8G8Bx_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), UNPACKED_1x1( 0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R8G8Bx_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x7f, 0x00), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8Bx_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x81, 0x00), UNPACKED_1x1(-1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8Bx_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x7f), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8Bx_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x81), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + + /* + * Depth-stencil formats + */ + + {PIPE_FORMAT_S8_USCALED, PACKED_1x8(0xff), PACKED_1x8(0x00), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_S8_USCALED, PACKED_1x8(0xff), PACKED_1x8(0xff), UNPACKED_1x1(0.0, 255.0, 0.0, 0.0)}, + + {PIPE_FORMAT_Z16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_Z16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + + {PIPE_FORMAT_Z32_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_Z32_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + + {PIPE_FORMAT_Z32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_Z32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0x3f800000), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + + {PIPE_FORMAT_Z24_UNORM_S8_USCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_Z24_UNORM_S8_USCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ffffff), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_Z24_UNORM_S8_USCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), UNPACKED_1x1(0.0, 255.0, 0.0, 0.0)}, + {PIPE_FORMAT_Z24_UNORM_S8_USCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 255.0, 0.0, 0.0)}, + + {PIPE_FORMAT_S8_USCALED_Z24_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_S8_USCALED_Z24_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffff00), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_S8_USCALED_Z24_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), UNPACKED_1x1(0.0, 255.0, 0.0, 0.0)}, + {PIPE_FORMAT_S8_USCALED_Z24_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 255.0, 0.0, 0.0)}, + + {PIPE_FORMAT_Z24X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_Z24X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00ffffff), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + + {PIPE_FORMAT_X8Z24_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_X8Z24_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xffffff00), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + + {PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED, PACKED_2x32(0xffffffff, 0x000000ff), PACKED_2x32(0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED, PACKED_2x32(0xffffffff, 0x000000ff), PACKED_2x32(0x3f800000, 0x00000000), UNPACKED_1x1( 1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED, PACKED_2x32(0xffffffff, 0x000000ff), PACKED_2x32(0x00000000, 0x000000ff), UNPACKED_1x1( 0.0, 255.0, 0.0, 0.0)}, + + /* + * YUV formats + */ + + {PIPE_FORMAT_R8G8_B8G8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), UNPACKED_2x1(0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_B8G8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0x00, 0x00, 0x00), UNPACKED_2x1(1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_B8G8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0xff, 0x00, 0x00), UNPACKED_2x1(0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_B8G8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0xff, 0x00), UNPACKED_2x1(0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R8G8_B8G8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0xff), UNPACKED_2x1(0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_B8G8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0xff, 0xff, 0xff), UNPACKED_2x1(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_G8R8_G8B8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), UNPACKED_2x1(0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_G8R8_G8B8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0x00, 0x00, 0x00), UNPACKED_2x1(0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_G8R8_G8B8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0xff, 0x00, 0x00), UNPACKED_2x1(1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_G8R8_G8B8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0xff, 0x00), UNPACKED_2x1(0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_G8R8_G8B8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0xff), UNPACKED_2x1(0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_G8R8_G8B8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0xff, 0xff, 0xff), UNPACKED_2x1(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)}, + + /* + * TODO: Exercise the UV channels as well. + */ + {PIPE_FORMAT_UYVY, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x80, 0x10, 0x80, 0x10), UNPACKED_2x1(0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_UYVY, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x80, 0xeb, 0x80, 0x10), UNPACKED_2x1(1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_UYVY, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x80, 0x10, 0x80, 0xeb), UNPACKED_2x1(0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_YUYV, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x10, 0x80, 0x10, 0x80), UNPACKED_2x1(0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_YUYV, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xeb, 0x80, 0x10, 0x80), UNPACKED_2x1(1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_YUYV, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x10, 0x80, 0xeb, 0x80), UNPACKED_2x1(0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0)}, + + /* + * Compressed formats + */ + + { + PIPE_FORMAT_DXT1_RGB, + PACKED_8x8(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff), + PACKED_8x8(0xf2, 0xd7, 0xb0, 0x20, 0xae, 0x2c, 0x6f, 0x97), + { + { + {0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0}, + {0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0}, + {0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0}, + {0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0} + }, + { + {0xd6/255.0, 0xff/255.0, 0x94/255.0, 0xff/255.0}, + {0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0}, + {0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0}, + {0xd6/255.0, 0xff/255.0, 0x94/255.0, 0xff/255.0} + }, + { + {0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0}, + {0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0}, + {0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0}, + {0x21/255.0, 0x14/255.0, 0x84/255.0, 0xff/255.0} + }, + { + {0x5d/255.0, 0x62/255.0, 0x89/255.0, 0xff/255.0}, + {0x21/255.0, 0x14/255.0, 0x84/255.0, 0xff/255.0}, + {0x21/255.0, 0x14/255.0, 0x84/255.0, 0xff/255.0}, + {0x99/255.0, 0xb0/255.0, 0x8e/255.0, 0xff/255.0} + } + } + }, + { + PIPE_FORMAT_DXT1_RGBA, + PACKED_8x8(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff), + PACKED_8x8(0xff, 0x2f, 0xa4, 0x72, 0xeb, 0xb2, 0xbd, 0xbe), + { + { + {0x00/255.0, 0x00/255.0, 0x00/255.0, 0x00/255.0}, + {0x4e/255.0, 0xaa/255.0, 0x90/255.0, 0xff/255.0}, + {0x4e/255.0, 0xaa/255.0, 0x90/255.0, 0xff/255.0}, + {0x00/255.0, 0x00/255.0, 0x00/255.0, 0x00/255.0} + }, + { + {0x4e/255.0, 0xaa/255.0, 0x90/255.0, 0xff/255.0}, + {0x29/255.0, 0xff/255.0, 0xff/255.0, 0xff/255.0}, + {0x00/255.0, 0x00/255.0, 0x00/255.0, 0x00/255.0}, + {0x4e/255.0, 0xaa/255.0, 0x90/255.0, 0xff/255.0} + }, + { + {0x73/255.0, 0x55/255.0, 0x21/255.0, 0xff/255.0}, + {0x00/255.0, 0x00/255.0, 0x00/255.0, 0x00/255.0}, + {0x00/255.0, 0x00/255.0, 0x00/255.0, 0x00/255.0}, + {0x4e/255.0, 0xaa/255.0, 0x90/255.0, 0xff/255.0} + }, + { + {0x4e/255.0, 0xaa/255.0, 0x90/255.0, 0xff/255.0}, + {0x00/255.0, 0x00/255.0, 0x00/255.0, 0x00/255.0}, + {0x00/255.0, 0x00/255.0, 0x00/255.0, 0x00/255.0}, + {0x4e/255.0, 0xaa/255.0, 0x90/255.0, 0xff/255.0} + } + } + }, + { + PIPE_FORMAT_DXT3_RGBA, + {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, + {0xe7, 0x4a, 0x8f, 0x96, 0x5b, 0xc1, 0x1c, 0x84, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a}, + { + { + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x77/255.0}, + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xee/255.0}, + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xaa/255.0}, + {0x8c/255.0, 0xff/255.0, 0xb5/255.0, 0x44/255.0} + }, + { + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xff/255.0}, + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x88/255.0}, + {0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x66/255.0}, + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x99/255.0} + }, + { + {0x31/255.0, 0x55/255.0, 0x5a/255.0, 0xbb/255.0}, + {0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x55/255.0}, + {0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x11/255.0}, + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xcc/255.0} + }, + { + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xcc/255.0}, + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x11/255.0}, + {0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x44/255.0}, + {0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x88/255.0} + } + } + }, + { + PIPE_FORMAT_DXT5_RGBA, + {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, + {0xf8, 0x11, 0xc5, 0x0c, 0x9a, 0x73, 0xb4, 0x9c, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a}, + { + { + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x74/255.0}, + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xf8/255.0}, + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xb6/255.0}, + {0x8c/255.0, 0xff/255.0, 0xb5/255.0, 0x53/255.0} + }, + { + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xf8/255.0}, + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x95/255.0}, + {0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x53/255.0}, + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x95/255.0} + }, + { + {0x31/255.0, 0x55/255.0, 0x5a/255.0, 0xb6/255.0}, + {0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x53/255.0}, + {0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x11/255.0}, + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xd7/255.0} + }, + { + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0xb6/255.0}, + {0x6d/255.0, 0xc6/255.0, 0x96/255.0, 0x11/255.0}, + {0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x32/255.0}, + {0x31/255.0, 0x55/255.0, 0x5a/255.0, 0x95/255.0} + } + } + }, + + + /* + * Standard 8-bit integer formats + */ + + {PIPE_FORMAT_R8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0x00), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0xff), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0xff), UNPACKED_1x1(1.0, 1.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0x00, 0x00), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0xff, 0x00), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0xff), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0xff, 0xff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0x00, 0x00, 0x00), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0xff, 0x00, 0x00), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0xff, 0x00), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0xff), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0xff, 0xff, 0xff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R8_USCALED, PACKED_1x8(0xff), PACKED_1x8(0x00), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8_USCALED, PACKED_1x8(0xff), PACKED_1x8(0xff), UNPACKED_1x1(255.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0x00), UNPACKED_1x1(255.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0xff), UNPACKED_1x1( 0.0, 255.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0xff), UNPACKED_1x1(255.0, 255.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0x00, 0x00), UNPACKED_1x1(255.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0xff, 0x00), UNPACKED_1x1( 0.0, 255.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0xff), UNPACKED_1x1( 0.0, 0.0, 255.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0xff, 0xff), UNPACKED_1x1(255.0, 255.0, 255.0, 1.0)}, + + {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), UNPACKED_1x1( 0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0x00, 0x00, 0x00), UNPACKED_1x1(255.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0xff, 0x00, 0x00), UNPACKED_1x1( 0.0, 255.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0xff, 0x00), UNPACKED_1x1( 0.0, 0.0, 255.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0xff), UNPACKED_1x1( 0.0, 0.0, 0.0, 255.0)}, + {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0xff, 0xff, 0xff), UNPACKED_1x1(255.0, 255.0, 255.0, 255.0)}, + + {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x7f), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x81), UNPACKED_1x1(-1.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x7f, 0x00), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x81, 0x00), UNPACKED_1x1(-1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x7f), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x81), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x7f, 0x00, 0x00), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x81, 0x00, 0x00), UNPACKED_1x1(-1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x7f, 0x00), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x81, 0x00), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x7f), UNPACKED_1x1( 0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x81), UNPACKED_1x1( 0.0, 0.0, -1.0, 1.0)}, + + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), UNPACKED_1x1( 0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x7f, 0x00, 0x00, 0x00), UNPACKED_1x1( 1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x81, 0x00, 0x00, 0x00), UNPACKED_1x1(-1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x7f, 0x00, 0x00), UNPACKED_1x1( 0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x81, 0x00, 0x00), UNPACKED_1x1( 0.0, -1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x7f, 0x00), UNPACKED_1x1( 0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x81, 0x00), UNPACKED_1x1( 0.0, 0.0, -1.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x7f), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x81), UNPACKED_1x1( 0.0, 0.0, 0.0, -1.0)}, + + {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x00), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x7f), UNPACKED_1x1( 127.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x80), UNPACKED_1x1(-128.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x7f, 0x00), UNPACKED_1x1( 127.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x80, 0x00), UNPACKED_1x1(-128.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x7f), UNPACKED_1x1( 0.0, 127.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x80), UNPACKED_1x1( 0.0, -128.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x7f, 0x00, 0x00), UNPACKED_1x1( 127.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x80, 0x00, 0x00), UNPACKED_1x1(-128.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x7f, 0x00), UNPACKED_1x1( 0.0, 127.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x80, 0x00), UNPACKED_1x1( 0.0, -128.0, 0.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x7f), UNPACKED_1x1( 0.0, 0.0, 127.0, 1.0)}, + {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x80), UNPACKED_1x1( 0.0, 0.0, -128.0, 1.0)}, + + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), UNPACKED_1x1( 0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x7f, 0x00, 0x00, 0x00), UNPACKED_1x1( 127.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x80, 0x00, 0x00, 0x00), UNPACKED_1x1(-128.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x7f, 0x00, 0x00), UNPACKED_1x1( 0.0, 127.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x80, 0x00, 0x00), UNPACKED_1x1( 0.0, -128.0, 0.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x7f, 0x00), UNPACKED_1x1( 0.0, 0.0, 127.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x80, 0x00), UNPACKED_1x1( 0.0, 0.0, -128.0, 0.0)}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x7f), UNPACKED_1x1( 0.0, 0.0, 0.0, 127.0)}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x80), UNPACKED_1x1( 0.0, 0.0, 0.0, -128.0)}, + + /* + * Standard 16-bit integer formats + */ + + {PIPE_FORMAT_R16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0x0000), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0xffff), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0xffff), UNPACKED_1x1(1.0, 1.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0x0000, 0x0000), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0xffff, 0x0000), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0xffff), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0xffff, 0xffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0x0000, 0x0000, 0x0000), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0xffff, 0x0000, 0x0000), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0xffff, 0x0000), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0xffff), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R16_USCALED, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16_USCALED, PACKED_1x16(0xffff), PACKED_1x16(0xffff), UNPACKED_1x1(65535.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0x0000), UNPACKED_1x1(65535.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0xffff), UNPACKED_1x1( 0.0, 65535.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0xffff), UNPACKED_1x1(65535.0, 65535.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0x0000, 0x0000), UNPACKED_1x1(65535.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0xffff, 0x0000), UNPACKED_1x1( 0.0, 65535.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0xffff), UNPACKED_1x1( 0.0, 0.0, 65535.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0xffff, 0xffff), UNPACKED_1x1(65535.0, 65535.0, 65535.0, 1.0)}, + + {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0x0000, 0x0000, 0x0000), UNPACKED_1x1(65535.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0xffff, 0x0000, 0x0000), UNPACKED_1x1( 0.0, 65535.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0xffff, 0x0000), UNPACKED_1x1( 0.0, 0.0, 65535.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0xffff), UNPACKED_1x1( 0.0, 0.0, 0.0, 65535.0)}, + {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), UNPACKED_1x1(65535.0, 65535.0, 65535.0, 65535.0)}, + + {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x7fff), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x8001), UNPACKED_1x1( -1.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x7fff, 0x0000), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x8001, 0x0000), UNPACKED_1x1( -1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x7fff), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x8001), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x7fff, 0x0000, 0x0000), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x8001, 0x0000, 0x0000), UNPACKED_1x1( -1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x7fff, 0x0000), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x8001, 0x0000), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x7fff), UNPACKED_1x1( 0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x8001), UNPACKED_1x1( 0.0, 0.0, -1.0, 1.0)}, + + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x7fff, 0x0000, 0x0000, 0x0000), UNPACKED_1x1( 1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x8001, 0x0000, 0x0000, 0x0000), UNPACKED_1x1( -1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x7fff, 0x0000, 0x0000), UNPACKED_1x1( 0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x8001, 0x0000, 0x0000), UNPACKED_1x1( 0.0, -1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x7fff, 0x0000), UNPACKED_1x1( 0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x8001, 0x0000), UNPACKED_1x1( 0.0, 0.0, -1.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x7fff), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x8001), UNPACKED_1x1( 0.0, 0.0, 0.0, -1.0)}, + + {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x7fff), UNPACKED_1x1( 32767.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x8000), UNPACKED_1x1(-32768.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x7fff, 0x0000), UNPACKED_1x1( 32767.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x8000, 0x0000), UNPACKED_1x1(-32768.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x7fff), UNPACKED_1x1( 0.0, 32767.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x8000), UNPACKED_1x1( 0.0, -32768.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x7fff, 0x0000, 0x0000), UNPACKED_1x1( 32767.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x8000, 0x0000, 0x0000), UNPACKED_1x1(-32768.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x7fff, 0x0000), UNPACKED_1x1( 0.0, 32767.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x8000, 0x0000), UNPACKED_1x1( 0.0, -32768.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x7fff), UNPACKED_1x1( 0.0, 0.0, 32767.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x8000), UNPACKED_1x1( 0.0, 0.0, -32768.0, 1.0)}, + + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x7fff, 0x0000, 0x0000, 0x0000), UNPACKED_1x1( 32767.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x8000, 0x0000, 0x0000, 0x0000), UNPACKED_1x1(-32768.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x7fff, 0x0000, 0x0000), UNPACKED_1x1( 0.0, 32767.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x8000, 0x0000, 0x0000), UNPACKED_1x1( 0.0, -32768.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x7fff, 0x0000), UNPACKED_1x1( 0.0, 0.0, 32767.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x8000, 0x0000), UNPACKED_1x1( 0.0, 0.0, -32768.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x7fff), UNPACKED_1x1( 0.0, 0.0, 0.0, 32767.0)}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x8000), UNPACKED_1x1( 0.0, 0.0, 0.0, -32768.0)}, + + /* + * Standard 32-bit integer formats + * + * NOTE: We can't accurately represent integers larger than +/-0x1000000 + * with single precision floats, so that's as far as we test. + */ + + {PIPE_FORMAT_R32_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xffffffff, 0x00000000), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xffffffff), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xffffffff, 0xffffffff), UNPACKED_1x1(1.0, 1.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xffffffff, 0x00000000, 0x00000000), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xffffffff, 0x00000000), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xffffffff), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xffffffff, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xffffffff, 0x00000000, 0x00000000), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xffffffff, 0x00000000), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xffffffff), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R32_USCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32_USCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x01000000), UNPACKED_1x1(16777216.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x00000000), UNPACKED_1x1(16777216.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x01000000), UNPACKED_1x1( 0.0, 16777216.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x01000000), UNPACKED_1x1(16777216.0, 16777216.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x00000000, 0x00000000), UNPACKED_1x1(16777216.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x01000000, 0x00000000), UNPACKED_1x1( 0.0, 16777216.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x01000000), UNPACKED_1x1( 0.0, 0.0, 16777216.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x01000000, 0x01000000), UNPACKED_1x1(16777216.0, 16777216.0, 16777216.0, 1.0)}, + + {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1(16777216.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x01000000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 16777216.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x01000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 16777216.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x01000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 16777216.0)}, + {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x01000000, 0x01000000, 0x01000000), UNPACKED_1x1(16777216.0, 16777216.0, 16777216.0, 16777216.0)}, + + {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x7fffffff), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x80000001), UNPACKED_1x1( -1.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x7fffffff, 0x00000000), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x80000001, 0x00000000), UNPACKED_1x1( -1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x7fffffff), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x80000001), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x7fffffff, 0x00000000, 0x00000000), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x80000001, 0x00000000, 0x00000000), UNPACKED_1x1( -1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x7fffffff, 0x00000000), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x80000001, 0x00000000), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x7fffffff), UNPACKED_1x1( 0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x80000001), UNPACKED_1x1( 0.0, 0.0, -1.0, 1.0)}, + + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x7fffffff, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( 1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x80000001, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( -1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x7fffffff, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x80000001, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, -1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x7fffffff, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x80000001, 0x00000000), UNPACKED_1x1( 0.0, 0.0, -1.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x7fffffff), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x80000001), UNPACKED_1x1( 0.0, 0.0, 0.0, -1.0)}, + + {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x01000000), UNPACKED_1x1( 16777216.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), UNPACKED_1x1(-16777216.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x00000000), UNPACKED_1x1( 16777216.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xff000000, 0x00000000), UNPACKED_1x1(-16777216.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x01000000), UNPACKED_1x1( 0.0, 16777216.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xff000000), UNPACKED_1x1( 0.0, -16777216.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x00000000, 0x00000000), UNPACKED_1x1( 16777216.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xff000000, 0x00000000, 0x00000000), UNPACKED_1x1(-16777216.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x01000000, 0x00000000), UNPACKED_1x1( 0.0, 16777216.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xff000000, 0x00000000), UNPACKED_1x1( 0.0, -16777216.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x01000000), UNPACKED_1x1( 0.0, 0.0, 16777216.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xff000000), UNPACKED_1x1( 0.0, 0.0, -16777216.0, 1.0)}, + + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( 16777216.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xff000000, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1(-16777216.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x01000000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 16777216.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xff000000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, -16777216.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x01000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 16777216.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xff000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, -16777216.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x01000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 16777216.0)}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xff000000), UNPACKED_1x1( 0.0, 0.0, 0.0, -16777216.0)}, + + /* + * Standard 32-bit float formats + */ + + {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0x3f800000), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0xbf800000), UNPACKED_1x1( -1.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x3f800000, 0x00000000), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xbf800000, 0x00000000), UNPACKED_1x1(-1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x3f800000), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xbf800000), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x3f800000, 0x3f800000), UNPACKED_1x1( 1.0, 1.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x3f800000, 0x00000000, 0x00000000), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xbf800000, 0x00000000, 0x00000000), UNPACKED_1x1(-1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x3f800000, 0x00000000), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xbf800000, 0x00000000), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x3f800000), UNPACKED_1x1( 0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xbf800000), UNPACKED_1x1( 0.0, 0.0, -1.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x3f800000, 0x3f800000, 0x3f800000), UNPACKED_1x1( 1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x3f800000, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( 1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xbf800000, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1(-1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x3f800000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xbf800000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, -1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x3f800000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xbf800000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, -1.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x3f800000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xbf800000), UNPACKED_1x1( 0.0, 0.0, 0.0, -1.0)}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000), UNPACKED_1x1( 1.0, 1.0, 1.0, 1.0)}, + + /* + * Half float formats + */ + + {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0x3c00), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16_FLOAT, PACKED_1x16(0xffff), PACKED_1x16(0xbc00), UNPACKED_1x1( -1.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R16G16_FLOAT, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_FLOAT, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x3c00, 0x0000), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_FLOAT, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xbc00, 0x0000), UNPACKED_1x1(-1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_FLOAT, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x3c00), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_FLOAT, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0xbc00), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16_FLOAT, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x3c00, 0x3c00), UNPACKED_1x1( 1.0, 1.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R16G16B16_FLOAT, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_FLOAT, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x3c00, 0x0000, 0x0000), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_FLOAT, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xbc00, 0x0000, 0x0000), UNPACKED_1x1(-1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_FLOAT, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x3c00, 0x0000), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_FLOAT, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0xbc00, 0x0000), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_FLOAT, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x3c00), UNPACKED_1x1( 0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_FLOAT, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0xbc00), UNPACKED_1x1( 0.0, 0.0, -1.0, 1.0)}, + {PIPE_FORMAT_R16G16B16_FLOAT, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x3c00, 0x3c00, 0x3c00), UNPACKED_1x1( 1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R16G16B16A16_FLOAT, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), UNPACKED_1x1( 0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_FLOAT, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x3c00, 0x0000, 0x0000, 0x0000), UNPACKED_1x1( 1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_FLOAT, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xbc00, 0x0000, 0x0000, 0x0000), UNPACKED_1x1(-1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_FLOAT, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x3c00, 0x0000, 0x0000), UNPACKED_1x1( 0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_FLOAT, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0xbc00, 0x0000, 0x0000), UNPACKED_1x1( 0.0, -1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_FLOAT, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x3c00, 0x0000), UNPACKED_1x1( 0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_FLOAT, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0xbc00, 0x0000), UNPACKED_1x1( 0.0, 0.0, -1.0, 0.0)}, + {PIPE_FORMAT_R16G16B16A16_FLOAT, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x3c00), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R16G16B16A16_FLOAT, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0xbc00), UNPACKED_1x1( 0.0, 0.0, 0.0, -1.0)}, + {PIPE_FORMAT_R16G16B16A16_FLOAT, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x3c00, 0x3c00, 0x3c00, 0x3c00), UNPACKED_1x1( 1.0, 1.0, 1.0, 1.0)}, + + /* + * 32-bit fixed point formats + */ + + {PIPE_FORMAT_R32_FIXED, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32_FIXED, PACKED_1x32(0xffffffff), PACKED_1x32(0x00010000), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32_FIXED, PACKED_1x32(0xffffffff), PACKED_1x32(0xffff0000), UNPACKED_1x1( -1.0, 0.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R32G32_FIXED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_FIXED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00010000, 0x00000000), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_FIXED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xffff0000, 0x00000000), UNPACKED_1x1(-1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_FIXED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00010000), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_FIXED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xffff0000), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32_FIXED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00010000, 0x00010000), UNPACKED_1x1( 1.0, 1.0, 0.0, 1.0)}, + + {PIPE_FORMAT_R32G32B32_FIXED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_FIXED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00010000, 0x00000000, 0x00000000), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_FIXED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xffff0000, 0x00000000, 0x00000000), UNPACKED_1x1(-1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_FIXED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00010000, 0x00000000), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_FIXED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xffff0000, 0x00000000), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_FIXED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00010000), UNPACKED_1x1( 0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_FIXED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xffff0000), UNPACKED_1x1( 0.0, 0.0, -1.0, 1.0)}, + {PIPE_FORMAT_R32G32B32_FIXED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00010000, 0x00010000, 0x00010000), UNPACKED_1x1( 1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_R32G32B32A32_FIXED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_FIXED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00010000, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1( 1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_FIXED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xffff0000, 0x00000000, 0x00000000, 0x00000000), UNPACKED_1x1(-1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_FIXED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00010000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_FIXED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xffff0000, 0x00000000, 0x00000000), UNPACKED_1x1( 0.0, -1.0, 0.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_FIXED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00010000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_FIXED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xffff0000, 0x00000000), UNPACKED_1x1( 0.0, 0.0, -1.0, 0.0)}, + {PIPE_FORMAT_R32G32B32A32_FIXED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00010000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R32G32B32A32_FIXED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xffff0000), UNPACKED_1x1( 0.0, 0.0, 0.0, -1.0)}, + {PIPE_FORMAT_R32G32B32A32_FIXED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00010000, 0x00010000, 0x00010000, 0x00010000), UNPACKED_1x1( 1.0, 1.0, 1.0, 1.0)}, + + /* + * D3D9 specific vertex formats + */ + + {PIPE_FORMAT_R10G10B10X2_USCALED, PACKED_1x32(0x3fffffff), PACKED_1x32(0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_USCALED, PACKED_1x32(0x3fffffff), PACKED_1x32(0x000003ff), UNPACKED_1x1(1023.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_USCALED, PACKED_1x32(0x3fffffff), PACKED_1x32(0x000ffc00), UNPACKED_1x1( 0.0, 1023.0, 0.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_USCALED, PACKED_1x32(0x3fffffff), PACKED_1x32(0x3ff00000), UNPACKED_1x1( 0.0, 0.0, 1023.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_USCALED, PACKED_1x32(0x3fffffff), PACKED_1x32(0x3fffffff), UNPACKED_1x1(1023.0, 1023.0, 1023.0, 1.0)}, + + {PIPE_FORMAT_R10G10B10X2_SNORM, PACKED_1x32(0x3fffffff), PACKED_1x32(0x00000000), UNPACKED_1x1( 0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_SNORM, PACKED_1x32(0x3fffffff), PACKED_1x32(0x000001ff), UNPACKED_1x1( 1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_SNORM, PACKED_1x32(0x3fffffff), PACKED_1x32(0x00000201), UNPACKED_1x1(-1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_SNORM, PACKED_1x32(0x3fffffff), PACKED_1x32(0x0007fc00), UNPACKED_1x1( 0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_SNORM, PACKED_1x32(0x3fffffff), PACKED_1x32(0x00080400), UNPACKED_1x1( 0.0, -1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_SNORM, PACKED_1x32(0x3fffffff), PACKED_1x32(0x1ff00000), UNPACKED_1x1( 0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_SNORM, PACKED_1x32(0x3fffffff), PACKED_1x32(0x20100000), UNPACKED_1x1( 0.0, 0.0, -1.0, 1.0)}, + + /* + * Special formats that not fit anywhere else + */ + +}; + + +const unsigned util_format_nr_test_cases = Elements(util_format_test_cases); diff --git a/src/gallium/auxiliary/util/u_format_tests.h b/src/gallium/auxiliary/util/u_format_tests.h new file mode 100644 index 0000000..f59563f --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_tests.h @@ -0,0 +1,71 @@ +/************************************************************************** + * + * 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 U_FORMAT_TESTS_H_ +#define U_FORMAT_TESTS_H_ + + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" + + +#define UTIL_FORMAT_MAX_PACKED_BYTES 16 +#define UTIL_FORMAT_MAX_UNPACKED_WIDTH 4 +#define UTIL_FORMAT_MAX_UNPACKED_HEIGHT 4 + + +/** + * A (packed, unpacked) color pair. + */ +struct util_format_test_case +{ + enum pipe_format format; + + /** + * Mask of the bits that actually meaningful data. Used to mask out the + * "X" channels. + */ + uint8_t mask[UTIL_FORMAT_MAX_PACKED_BYTES]; + + uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; + + /** + * RGBA. + */ + double unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4]; +}; + + +extern const struct util_format_test_case +util_format_test_cases[]; + + +extern const unsigned util_format_nr_test_cases; + + +#endif /* U_FORMAT_TESTS_H_ */ diff --git a/src/gallium/auxiliary/util/u_format_yuv.c b/src/gallium/auxiliary/util/u_format_yuv.c new file mode 100644 index 0000000..ab8bf29 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_yuv.c @@ -0,0 +1,1047 @@ +/************************************************************************** + * + * 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 + * YUV and RGB subsampled formats conversion. + * + * @author Jose Fonseca + */ + + +#include "util/u_format_yuv.h" + + +void +util_format_r8g8_b8g8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + float *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + float r, g0, g1, b; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + r = ubyte_to_float((value >> 0) & 0xff); + g0 = ubyte_to_float((value >> 8) & 0xff); + b = ubyte_to_float((value >> 16) & 0xff); + g1 = ubyte_to_float((value >> 24) & 0xff); + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 1.0f; /* a */ + dst += 4; + + dst[0] = r; /* r */ + dst[1] = g1; /* g */ + dst[2] = b; /* b */ + dst[3] = 1.0f; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + r = ubyte_to_float((value >> 0) & 0xff); + g0 = ubyte_to_float((value >> 8) & 0xff); + b = ubyte_to_float((value >> 16) & 0xff); + g1 = ubyte_to_float((value >> 24) & 0xff); + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 1.0f; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_r8g8_b8g8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + uint8_t *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + uint8_t r, g0, g1, b; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + r = (value >> 0) & 0xff; + g0 = (value >> 8) & 0xff; + b = (value >> 16) & 0xff; + g1 = (value >> 24) & 0xff; + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 0xff; /* a */ + dst += 4; + + dst[0] = r; /* r */ + dst[1] = g1; /* g */ + dst[2] = b; /* b */ + dst[3] = 0xff; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + r = (value >> 0) & 0xff; + g0 = (value >> 8) & 0xff; + b = (value >> 16) & 0xff; + g1 = (value >> 24) & 0xff; + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 0xff; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_r8g8_b8g8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const float *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + float r, g0, g1, b; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + r = 0.5f*(src[0] + src[4]); + g0 = src[1]; + g1 = src[5]; + b = 0.5f*(src[2] + src[6]); + + value = float_to_ubyte(r); + value |= float_to_ubyte(g0) << 8; + value |= float_to_ubyte(b) << 16; + value |= float_to_ubyte(g1) << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + r = src[0]; + g0 = src[1]; + g1 = 0; + b = src[2]; + + value = float_to_ubyte(r); + value |= float_to_ubyte(g0) << 8; + value |= float_to_ubyte(b) << 16; + value |= float_to_ubyte(g1) << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_r8g8_b8g8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const uint8_t *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + uint32_t r, g0, g1, b; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + r = (src[0] + src[4] + 1) >> 1; + g0 = src[1]; + g1 = src[5]; + b = (src[2] + src[6] + 1) >> 1; + + value = r; + value |= g0 << 8; + value |= b << 16; + value |= g1 << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + r = src[0]; + g0 = src[1]; + g1 = 0; + b = src[2]; + + value = r; + value |= g0 << 8; + value |= b << 16; + value |= g1 << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_r8g8_b8g8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + assert(i < 2); + assert(j < 1); + + dst[0] = ubyte_to_float(src[0]); /* r */ + dst[1] = ubyte_to_float(src[1 + 2*i]); /* g */ + dst[2] = ubyte_to_float(src[2]); /* b */ + dst[3] = 1.0f; /* a */ +} + + +void +util_format_g8r8_g8b8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + float *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + float r, g0, g1, b; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + g0 = ubyte_to_float((value >> 0) & 0xff); + r = ubyte_to_float((value >> 8) & 0xff); + g1 = ubyte_to_float((value >> 16) & 0xff); + b = ubyte_to_float((value >> 24) & 0xff); + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 1.0f; /* a */ + dst += 4; + + dst[0] = r; /* r */ + dst[1] = g1; /* g */ + dst[2] = b; /* b */ + dst[3] = 1.0f; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + g0 = ubyte_to_float((value >> 0) & 0xff); + r = ubyte_to_float((value >> 8) & 0xff); + g1 = ubyte_to_float((value >> 16) & 0xff); + b = ubyte_to_float((value >> 24) & 0xff); + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 1.0f; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_g8r8_g8b8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + uint8_t *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + uint8_t r, g0, g1, b; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + g0 = (value >> 0) & 0xff; + r = (value >> 8) & 0xff; + g1 = (value >> 16) & 0xff; + b = (value >> 24) & 0xff; + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 0xff; /* a */ + dst += 4; + + dst[0] = r; /* r */ + dst[1] = g1; /* g */ + dst[2] = b; /* b */ + dst[3] = 0xff; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + g0 = (value >> 0) & 0xff; + r = (value >> 8) & 0xff; + g1 = (value >> 16) & 0xff; + b = (value >> 24) & 0xff; + + dst[0] = r; /* r */ + dst[1] = g0; /* g */ + dst[2] = b; /* b */ + dst[3] = 0xff; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_g8r8_g8b8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const float *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + float r, g0, g1, b; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + r = 0.5f*(src[0] + src[4]); + g0 = src[1]; + g1 = src[5]; + b = 0.5f*(src[2] + src[6]); + + value = float_to_ubyte(g0); + value |= float_to_ubyte(r) << 8; + value |= float_to_ubyte(g1) << 16; + value |= float_to_ubyte(b) << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + r = src[0]; + g0 = src[1]; + g1 = 0; + b = src[2]; + + value = float_to_ubyte(g0); + value |= float_to_ubyte(r) << 8; + value |= float_to_ubyte(g1) << 16; + value |= float_to_ubyte(b) << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_g8r8_g8b8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const uint8_t *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + uint32_t r, g0, g1, b; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + r = (src[0] + src[4] + 1) >> 1; + g0 = src[1]; + g1 = src[5]; + b = (src[2] + src[6] + 1) >> 1; + + value = g0; + value |= r << 8; + value |= g1 << 16; + value |= b << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + r = src[0]; + g0 = src[1]; + g1 = 0; + b = src[2]; + + value = g0; + value |= r << 8; + value |= g1 << 16; + value |= b << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_g8r8_g8b8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + assert(i < 2); + assert(j < 1); + + dst[0] = ubyte_to_float(src[1]); /* r */ + dst[1] = ubyte_to_float(src[0 + 2*i]); /* g */ + dst[2] = ubyte_to_float(src[3]); /* b */ + dst[3] = 1.0f; /* a */ +} + + +void +util_format_uyvy_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + float *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + uint8_t y0, y1, u, v; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + u = (value >> 0) & 0xff; + y0 = (value >> 8) & 0xff; + v = (value >> 16) & 0xff; + y1 = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 1.0f; /* a */ + dst += 4; + + util_format_yuv_to_rgb_float(y1, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 1.0f; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + u = (value >> 0) & 0xff; + y0 = (value >> 8) & 0xff; + v = (value >> 16) & 0xff; + y1 = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 1.0f; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_uyvy_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + uint8_t *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + uint8_t y0, y1, u, v; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + u = (value >> 0) & 0xff; + y0 = (value >> 8) & 0xff; + v = (value >> 16) & 0xff; + y1 = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 0xff; /* a */ + dst += 4; + + util_format_yuv_to_rgb_8unorm(y1, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 0xff; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + u = (value >> 0) & 0xff; + y0 = (value >> 8) & 0xff; + v = (value >> 16) & 0xff; + y1 = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 0xff; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_uyvy_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const float *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + uint8_t y0, y1, u, v; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + uint8_t y0, y1, u0, u1, v0, v1, u, v; + + util_format_rgb_float_to_yuv(src[0], src[1], src[2], + &y0, &u0, &v0); + util_format_rgb_float_to_yuv(src[4], src[5], src[6], + &y1, &u1, &v1); + + u = (u0 + u1 + 1) >> 1; + v = (v0 + v1 + 1) >> 1; + + value = u; + value |= y0 << 8; + value |= v << 16; + value |= y1 << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + util_format_rgb_float_to_yuv(src[0], src[1], src[2], + &y0, &u, &v); + y1 = 0; + + value = u; + value |= y0 << 8; + value |= v << 16; + value |= y1 << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_uyvy_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const uint8_t *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + uint8_t y0, y1, u, v; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + uint8_t y0, y1, u0, u1, v0, v1, u, v; + + util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2], + &y0, &u0, &v0); + util_format_rgb_8unorm_to_yuv(src[4], src[5], src[6], + &y1, &u1, &v1); + + u = (u0 + u1 + 1) >> 1; + v = (v0 + v1 + 1) >> 1; + + value = u; + value |= y0 << 8; + value |= v << 16; + value |= y1 << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2], + &y0, &u, &v); + y1 = 0; + + value = u; + value |= y0 << 8; + value |= v << 16; + value |= y1 << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_uyvy_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + uint8_t y, u, v; + + assert(i < 2); + assert(j < 1); + + y = src[1 + i*2]; + u = src[0]; + v = src[2]; + + util_format_yuv_to_rgb_float(y, u, v, &dst[0], &dst[1], &dst[2]); + + dst[3] = 1.0f; +} + + +void +util_format_yuyv_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + float *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + uint8_t y0, y1, u, v; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + y0 = (value >> 0) & 0xff; + u = (value >> 8) & 0xff; + y1 = (value >> 16) & 0xff; + v = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 1.0f; /* a */ + dst += 4; + + util_format_yuv_to_rgb_float(y1, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 1.0f; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + y0 = (value >> 0) & 0xff; + u = (value >> 8) & 0xff; + y1 = (value >> 16) & 0xff; + v = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_float(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 1.0f; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_yuyv_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + uint8_t *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + uint32_t value; + uint8_t y0, y1, u, v; + + for (x = 0; x + 1 < width; x += 2) { + value = *src++; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + y0 = (value >> 0) & 0xff; + u = (value >> 8) & 0xff; + y1 = (value >> 16) & 0xff; + v = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 0xff; /* a */ + dst += 4; + + util_format_yuv_to_rgb_8unorm(y1, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 0xff; /* a */ + dst += 4; + } + + if (x < width) { + value = *src; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + y0 = (value >> 0) & 0xff; + u = (value >> 8) & 0xff; + y1 = (value >> 16) & 0xff; + v = (value >> 24) & 0xff; + + util_format_yuv_to_rgb_8unorm(y0, u, v, &dst[0], &dst[1], &dst[2]); + dst[3] = 0xff; /* a */ + } + + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + + +void +util_format_yuyv_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const float *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + uint8_t y0, y1, u, v; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + uint8_t y0, y1, u0, u1, v0, v1, u, v; + + util_format_rgb_float_to_yuv(src[0], src[1], src[2], + &y0, &u0, &v0); + util_format_rgb_float_to_yuv(src[4], src[5], src[6], + &y1, &u1, &v1); + + u = (u0 + u1 + 1) >> 1; + v = (v0 + v1 + 1) >> 1; + + value = y0; + value |= u << 8; + value |= y1 << 16; + value |= v << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + util_format_rgb_float_to_yuv(src[0], src[1], src[2], + &y0, &u, &v); + y1 = 0; + + value = y0; + value |= u << 8; + value |= y1 << 16; + value |= v << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_yuyv_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + + for (y = 0; y < height; y += 1) { + const uint8_t *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + uint8_t y0, y1, u, v; + uint32_t value; + + for (x = 0; x + 1 < width; x += 2) { + uint8_t y0, y1, u0, u1, v0, v1, u, v; + + util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2], + &y0, &u0, &v0); + util_format_rgb_8unorm_to_yuv(src[4], src[5], src[6], + &y1, &u1, &v1); + + u = (u0 + u1 + 1) >> 1; + v = (v0 + v1 + 1) >> 1; + + value = y0; + value |= u << 8; + value |= y1 << 16; + value |= v << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst++ = value; + + src += 8; + } + + if (x < width) { + util_format_rgb_8unorm_to_yuv(src[0], src[1], src[2], + &y0, &u, &v); + y1 = 0; + + value = y0; + value |= u << 8; + value |= y1 << 16; + value |= v << 24; + +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + + *dst = value; + } + + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_yuyv_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j) +{ + uint8_t y, u, v; + + assert(i < 2); + assert(j < 1); + + y = src[0 + i*2]; + u = src[1]; + v = src[3]; + + util_format_yuv_to_rgb_float(y, u, v, &dst[0], &dst[1], &dst[2]); + + dst[3] = 1.0f; +} diff --git a/src/gallium/auxiliary/util/u_format_yuv.h b/src/gallium/auxiliary/util/u_format_yuv.h new file mode 100644 index 0000000..dc96323 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_yuv.h @@ -0,0 +1,223 @@ +/************************************************************************** + * + * 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 + * YUV colorspace conversion. + * + * @author Brian Paul + * @author Michal Krol + * @author Jose Fonseca + * + * See also: + * - http://www.fourcc.org/fccyvrgb.php + * - http://msdn.microsoft.com/en-us/library/ms893078 + * - http://en.wikipedia.org/wiki/YUV + */ + + +#ifndef U_FORMAT_YUV_H_ +#define U_FORMAT_YUV_H_ + + +#include "pipe/p_compiler.h" +#include "u_math.h" + + +/* + * TODO: Ensure we use consistent and right floating formulas, with enough + * precision in the coefficients. + */ + +static INLINE void +util_format_rgb_float_to_yuv(float r, float g, float b, + uint8_t *y, uint8_t *u, uint8_t *v) +{ + const float _r = CLAMP(r, 0.0f, 1.0f); + const float _g = CLAMP(g, 0.0f, 1.0f); + const float _b = CLAMP(b, 0.0f, 1.0f); + + const float scale = 255.0f; + + const int _y = scale * ( (0.257f * _r) + (0.504f * _g) + (0.098f * _b)); + const int _u = scale * (-(0.148f * _r) - (0.291f * _g) + (0.439f * _b)); + const int _v = scale * ( (0.439f * _r) - (0.368f * _g) - (0.071f * _b)); + + *y = _y + 16; + *u = _u + 128; + *v = _v + 128; +} + + +static INLINE void +util_format_yuv_to_rgb_float(uint8_t y, uint8_t u, uint8_t v, + float *r, float *g, float *b) +{ + const int _y = y - 16; + const int _u = u - 128; + const int _v = v - 128; + + const float y_factor = 255.0f / 219.0f; + + const float scale = 1.0f / 255.0f; + + *r = scale * (y_factor * _y + 1.596f * _v); + *g = scale * (y_factor * _y - 0.391f * _u - 0.813f * _v); + *b = scale * (y_factor * _y + 2.018f * _u ); +} + + +static INLINE void +util_format_rgb_8unorm_to_yuv(uint8_t r, uint8_t g, uint8_t b, + uint8_t *y, uint8_t *u, uint8_t *v) +{ + *y = (( 66 * r + 129 * g + 25 * b + 128) >> 8) + 16; + *u = (( -38 * r - 74 * g + 112 * b + 128) >> 8) + 128; + *v = (( 112 * r - 94 * g - 18 * b + 128) >> 8) + 128; +} + + +static INLINE void +util_format_yuv_to_rgb_8unorm(uint8_t y, uint8_t u, uint8_t v, + uint8_t *r, uint8_t *g, uint8_t *b) +{ + const int _y = y - 16; + const int _u = u - 128; + const int _v = v - 128; + + const int _r = (298 * _y + 409 * _v + 128) >> 8; + const int _g = (298 * _y - 100 * _u - 208 * _v + 128) >> 8; + const int _b = (298 * _y + 516 * _u + 128) >> 8; + + *r = CLAMP(_r, 0, 255); + *g = CLAMP(_g, 0, 255); + *b = CLAMP(_b, 0, 255); +} + + + +void +util_format_uyvy_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_uyvy_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_uyvy_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_uyvy_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_uyvy_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + +void +util_format_yuyv_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_yuyv_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_yuyv_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_yuyv_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_yuyv_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + + +void +util_format_r8g8_b8g8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8_b8g8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8_b8g8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8_b8g8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_r8g8_b8g8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + +void +util_format_g8r8_g8b8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_g8r8_g8b8_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_g8r8_g8b8_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_g8r8_g8b8_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); + +void +util_format_g8r8_g8b8_unorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned i, unsigned j); + + + +#endif /* U_FORMAT_YUV_H_ */ diff --git a/src/gallium/auxiliary/util/u_format_zs.c b/src/gallium/auxiliary/util/u_format_zs.c new file mode 100644 index 0000000..80081e2 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_zs.c @@ -0,0 +1,973 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "u_debug.h" +#include "u_math.h" +#include "u_format_zs.h" + + +/* + * z32_unorm conversion functions + */ + +static INLINE uint16_t +z32_unorm_to_z16_unorm(uint32_t z) +{ + /* z * 0xffff / 0xffffffff */ + return z >> 16; +} + +static INLINE uint32_t +z16_unorm_to_z32_unorm(uint16_t z) +{ + /* z * 0xffffffff / 0xffff */ + return (z << 16) | z; +} + +static INLINE uint32_t +z32_unorm_to_z24_unorm(uint32_t z) +{ + /* z * 0xffffff / 0xffffffff */ + return z >> 8; +} + +static INLINE uint32_t +z24_unorm_to_z32_unorm(uint32_t z) +{ + /* z * 0xffffffff / 0xffffff */ + return (z << 8) | (z >> 16); +} + + +/* + * z32_float conversion functions + */ + +static INLINE uint16_t +z32_float_to_z16_unorm(float z) +{ + const float scale = 0xffff; + return (uint16_t)(z * scale); +} + +static INLINE float +z16_unorm_to_z32_float(uint16_t z) +{ + const float scale = 1.0 / 0xffff; + return (float)(z * scale); +} + +static INLINE uint32_t +z32_float_to_z24_unorm(float z) +{ + const double scale = 0xffffff; + return (uint32_t)(z * scale) & 0xffffff; +} + +static INLINE float +z24_unorm_to_z32_float(uint32_t z) +{ + const double scale = 1.0 / 0xffffff; + return (float)(z * scale); +} + +static INLINE uint32_t +z32_float_to_z32_unorm(float z) +{ + const double scale = 0xffffffff; + return (uint32_t)(z * scale); +} + +static INLINE float +z32_unorm_to_z32_float(uint32_t z) +{ + const double scale = 1.0 / 0xffffffff; + return (float)(z * scale); +} + + +void +util_format_s8_uscaled_unpack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned y; + for(y = 0; y < height; ++y) { + memcpy(dst_row, src_row, width); + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_s8_uscaled_pack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned y; + for(y = 0; y < height; ++y) { + memcpy(dst_row, src_row, width); + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z16_unorm_unpack_z_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + float *dst = dst_row; + const uint16_t *src = (const uint16_t *)src_row; + for(x = 0; x < width; ++x) { + uint16_t value = *src++; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap16(value); +#endif + *dst++ = z16_unorm_to_z32_float(value); + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z16_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const float *src = src_row; + uint16_t *dst = (uint16_t *)dst_row; + for(x = 0; x < width; ++x) { + uint16_t value; + value = z32_float_to_z16_unorm(*src++); +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap16(value); +#endif + *dst++ = value; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_z16_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + uint32_t *dst = dst_row; + const uint16_t *src = (const uint16_t *)src_row; + for(x = 0; x < width; ++x) { + uint16_t value = *src++; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap16(value); +#endif + *dst++ = z16_unorm_to_z32_unorm(value); + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z16_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, + const uint32_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const uint32_t *src = src_row; + uint16_t *dst = (uint16_t *)dst_row; + for(x = 0; x < width; ++x) { + uint16_t value; + value = z32_unorm_to_z16_unorm(*src++); +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap16(value); +#endif + *dst++ = value; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_z32_unorm_unpack_z_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + float *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + for(x = 0; x < width; ++x) { + uint32_t value = *src++; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = z32_unorm_to_z32_float(value); + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z32_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const float *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + for(x = 0; x < width; ++x) { + uint32_t value; + value = z32_float_to_z32_unorm(*src++); +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = value; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_z32_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned y; + for(y = 0; y < height; ++y) { + memcpy(dst_row, src_row, width * 4); + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z32_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, + const uint32_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned y; + for(y = 0; y < height; ++y) { + memcpy(dst_row, src_row, width * 4); + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z32_float_unpack_z_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned y; + for(y = 0; y < height; ++y) { + memcpy(dst_row, src_row, width * 4); + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z32_float_pack_z_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned y; + for(y = 0; y < height; ++y) { + memcpy(dst_row, src_row, width * 4); + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z32_float_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + uint32_t *dst = dst_row; + const float *src = (const float *)src_row; + for(x = 0; x < width; ++x) { + *dst++ = z32_float_to_z32_unorm(*src++); + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z32_float_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, + const uint32_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const uint32_t *src = src_row; + float *dst = (float *)dst_row; + for(x = 0; x < width; ++x) { + *dst++ = z32_unorm_to_z32_float(*src++); + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_z24_unorm_s8_uscaled_unpack_z_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + float *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + for(x = 0; x < width; ++x) { + uint32_t value = *src++; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = z24_unorm_to_z32_float(value & 0xffffff); + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z24_unorm_s8_uscaled_pack_z_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const float *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + for(x = 0; x < width; ++x) { + uint32_t value = *dst; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + value &= 0xff000000; + value |= z32_float_to_z24_unorm(*src++); +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = value; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_z24_unorm_s8_uscaled_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + uint32_t *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + for(x = 0; x < width; ++x) { + uint32_t value = *src++; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = z24_unorm_to_z32_unorm(value & 0xffffff); + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z24_unorm_s8_uscaled_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, + const uint32_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const uint32_t *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + for(x = 0; x < width; ++x) { + uint32_t value= *dst; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + value &= 0xff000000; + value |= z32_unorm_to_z24_unorm(*src++); +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = value; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_z24_unorm_s8_uscaled_unpack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + uint8_t *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + for(x = 0; x < width; ++x) { + uint32_t value = *src++; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = value >> 24; + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z24_unorm_s8_uscaled_pack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const uint8_t *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + for(x = 0; x < width; ++x) { + uint32_t value = *dst; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + value &= 0x00ffffff; + value |= *src++ << 24; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = value; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_s8_uscaled_z24_unorm_unpack_z_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + float *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + for(x = 0; x < width; ++x) { + uint32_t value = *src++; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = z24_unorm_to_z32_float(value >> 8); + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_s8_uscaled_z24_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const float *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + for(x = 0; x < width; ++x) { + uint32_t value = *dst; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + value &= 0x000000ff; + value |= z32_float_to_z24_unorm(*src++) << 8; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = value; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_s8_uscaled_z24_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + uint32_t *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + for(x = 0; x < width; ++x) { + uint32_t value = *src++; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = z24_unorm_to_z32_unorm(value >> 8); + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_s8_uscaled_z24_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, + const uint32_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const uint32_t *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + for(x = 0; x < width; ++x) { + uint32_t value = *dst; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + value &= 0x000000ff; + value |= *src++ & 0xffffff00; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = value; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_s8_uscaled_z24_unorm_unpack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + uint8_t *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + for(x = 0; x < width; ++x) { + uint32_t value = *src++; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = value & 0xff; + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_s8_uscaled_z24_unorm_pack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const uint8_t *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + for(x = 0; x < width; ++x) { + uint32_t value = *dst; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + value &= 0xffffff00; + value |= *src++; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = value; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_z24x8_unorm_unpack_z_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + float *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + for(x = 0; x < width; ++x) { + uint32_t value = *src++; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = z24_unorm_to_z32_float(value & 0xffffff); + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z24x8_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const float *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + for(x = 0; x < width; ++x) { + uint32_t value; + value = z32_float_to_z24_unorm(*src++); +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = value; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_z24x8_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + uint32_t *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + for(x = 0; x < width; ++x) { + uint32_t value = *src++; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = z24_unorm_to_z32_unorm(value & 0xffffff); + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z24x8_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, + const uint32_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const uint32_t *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + for(x = 0; x < width; ++x) { + uint32_t value; + value = z32_unorm_to_z24_unorm(*src++); +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = value; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_x8z24_unorm_unpack_z_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + float *dst = dst_row; + const uint32_t *src = (uint32_t *)src_row; + for(x = 0; x < width; ++x) { + uint32_t value = *src++; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = z24_unorm_to_z32_float(value >> 8); + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_x8z24_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const float *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + for(x = 0; x < width; ++x) { + uint32_t value; + value = z32_float_to_z24_unorm(*src++) << 8; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = value; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_x8z24_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + uint32_t *dst = dst_row; + const uint32_t *src = (const uint32_t *)src_row; + for(x = 0; x < width; ++x) { + uint32_t value = *src++; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = z24_unorm_to_z32_unorm(value >> 8); + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_x8z24_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, + const uint32_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const uint32_t *src = src_row; + uint32_t *dst = (uint32_t *)dst_row; + for(x = 0; x < width; ++x) { + uint32_t value; + value = z32_unorm_to_z24_unorm(*src++) << 8; +#ifdef PIPE_ARCH_BIG_ENDIAN + value = util_bswap32(value); +#endif + *dst++ = value; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_z32_float_s8x24_uscaled_unpack_z_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + float *dst = dst_row; + const float *src = (const float *)src_row; + for(x = 0; x < width; ++x) { + *dst = *src; + src += 2; + dst += 1; + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z32_float_s8x24_uscaled_pack_z_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const float *src = src_row; + float *dst = (float *)dst_row; + for(x = 0; x < width; ++x) { + *dst = *src; + src += 1; + dst += 2; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_z32_float_s8x24_uscaled_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + uint32_t *dst = dst_row; + const float *src = (const float *)src_row; + for(x = 0; x < width; ++x) { + *dst = z32_float_to_z32_unorm(*src); + src += 2; + dst += 1; + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z32_float_s8x24_uscaled_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, + const uint32_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const uint32_t *src = src_row; + float *dst = (float *)dst_row; + for(x = 0; x < width; ++x) { + *dst++ = z32_unorm_to_z32_float(*src++); + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + +void +util_format_z32_float_s8x24_uscaled_unpack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + uint8_t *dst = dst_row; + const uint8_t *src = src_row + 4; + for(x = 0; x < width; ++x) { + *dst = *src; + src += 8; + dst += 1; + } + src_row += src_stride/sizeof(*src_row); + dst_row += dst_stride/sizeof(*dst_row); + } +} + +void +util_format_z32_float_s8x24_uscaled_pack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + unsigned x, y; + for(y = 0; y < height; ++y) { + const uint8_t *src = src_row; + uint8_t *dst = dst_row + 4; + for(x = 0; x < width; ++x) { + *dst = *src; + src += 1; + dst += 8; + } + dst_row += dst_stride/sizeof(*dst_row); + src_row += src_stride/sizeof(*src_row); + } +} + + +void +util_format_x24s8_uscaled_unpack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_z24_unorm_s8_uscaled_unpack_s_8uscaled(dst_row, dst_stride, + src_row, src_stride, + width, height); +} + +void +util_format_x24s8_uscaled_pack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_z24_unorm_s8_uscaled_pack_s_8uscaled(dst_row, dst_stride, + src_row, src_stride, + width, height); +} + +void +util_format_s8x24_uscaled_unpack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_s8_uscaled_z24_unorm_unpack_s_8uscaled(dst_row, dst_stride, + src_row, src_stride, + width, height); +} + +void +util_format_s8x24_uscaled_pack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) +{ + util_format_s8_uscaled_z24_unorm_pack_s_8uscaled(dst_row, dst_stride, + src_row, src_stride, + width, height); +} + +void +util_format_x32_s8x24_uscaled_unpack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + util_format_z32_float_s8x24_uscaled_unpack_s_8uscaled(dst_row, dst_stride, + src_row, src_stride, + width, height); + +} + +void +util_format_x32_s8x24_uscaled_pack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + util_format_z32_float_s8x24_uscaled_pack_s_8uscaled(dst_row, dst_stride, + src_row, src_stride, + width, height); +} diff --git a/src/gallium/auxiliary/util/u_format_zs.h b/src/gallium/auxiliary/util/u_format_zs.h new file mode 100644 index 0000000..1604cc3 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_zs.h @@ -0,0 +1,212 @@ +/************************************************************************** + * + * 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 U_FORMAT_ZS_H_ +#define U_FORMAT_ZS_H_ + + +#include "pipe/p_compiler.h" + + +void +util_format_s8_uscaled_unpack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_s8_uscaled_pack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z16_unorm_unpack_z_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z16_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z16_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z16_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, const uint32_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z32_unorm_unpack_z_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z32_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z32_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z32_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, const uint32_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z32_float_unpack_z_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z32_float_pack_z_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z32_float_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z32_float_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, const uint32_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z24_unorm_s8_uscaled_unpack_z_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z24_unorm_s8_uscaled_pack_z_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z24_unorm_s8_uscaled_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z24_unorm_s8_uscaled_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, const uint32_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z24_unorm_s8_uscaled_unpack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z24_unorm_s8_uscaled_pack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_s8_uscaled_z24_unorm_unpack_z_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_s8_uscaled_z24_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_s8_uscaled_z24_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_s8_uscaled_z24_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, const uint32_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_s8_uscaled_z24_unorm_unpack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_s8_uscaled_z24_unorm_pack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z24x8_unorm_unpack_z_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z24x8_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z24x8_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z24x8_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, const uint32_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_x8z24_unorm_unpack_z_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_x8z24_unorm_pack_z_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_x8z24_unorm_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_x8z24_unorm_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, const uint32_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z32_float_s8x24_uscaled_unpack_z_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z32_float_s8x24_uscaled_pack_z_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z32_float_s8x24_uscaled_unpack_z_32unorm(uint32_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z32_float_s8x24_uscaled_pack_z_32unorm(uint8_t *dst_row, unsigned dst_stride, const uint32_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z32_float_s8x24_uscaled_unpack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + + +void +util_format_z32_float_s8x24_uscaled_pack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_x24s8_uscaled_unpack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_x24s8_uscaled_pack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_s8x24_uscaled_unpack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_s8x24_uscaled_pack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_x32_s8x24_uscaled_unpack_s_8uscaled(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); + +void +util_format_x32_s8x24_uscaled_pack_s_8uscaled(uint8_t *dst_row, unsigned dst_sride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); +#endif /* U_FORMAT_ZS_H_ */ diff --git a/src/gallium/auxiliary/util/u_framebuffer.c b/src/gallium/auxiliary/util/u_framebuffer.c new file mode 100644 index 0000000..7803ec6 --- /dev/null +++ b/src/gallium/auxiliary/util/u_framebuffer.c @@ -0,0 +1,148 @@ +/************************************************************************** + * + * Copyright 2009-2010 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Framebuffer utility functions. + * + * @author Brian Paul + */ + + +#include "pipe/p_screen.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" + +#include "util/u_memory.h" +#include "util/u_framebuffer.h" + + +/** + * Compare pipe_framebuffer_state objects. + * \return TRUE if same, FALSE if different + */ +boolean +util_framebuffer_state_equal(const struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src) +{ + unsigned i; + + if (dst->width != src->width || + dst->height != src->height) + return FALSE; + + for (i = 0; i < Elements(src->cbufs); i++) { + if (dst->cbufs[i] != src->cbufs[i]) { + return FALSE; + } + } + + if (dst->nr_cbufs != src->nr_cbufs) { + return FALSE; + } + + if (dst->zsbuf != src->zsbuf) { + return FALSE; + } + + return TRUE; +} + + +/** + * Copy framebuffer state from src to dst, updating refcounts. + */ +void +util_copy_framebuffer_state(struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src) +{ + unsigned i; + + dst->width = src->width; + dst->height = src->height; + + for (i = 0; i < src->nr_cbufs; i++) + pipe_surface_reference(&dst->cbufs[i], src->cbufs[i]); + + for (i = src->nr_cbufs; i < dst->nr_cbufs; i++) + pipe_surface_reference(&dst->cbufs[i], NULL); + + dst->nr_cbufs = src->nr_cbufs; + + pipe_surface_reference(&dst->zsbuf, src->zsbuf); +} + + +void +util_unreference_framebuffer_state(struct pipe_framebuffer_state *fb) +{ + unsigned i; + + for (i = 0; i < fb->nr_cbufs; i++) { + pipe_surface_reference(&fb->cbufs[i], NULL); + } + + pipe_surface_reference(&fb->zsbuf, NULL); + + fb->width = fb->height = 0; + fb->nr_cbufs = 0; +} + + +/* Where multiple sizes are allowed for framebuffer surfaces, find the + * minimum width and height of all bound surfaces. + */ +boolean +util_framebuffer_min_size(const struct pipe_framebuffer_state *fb, + unsigned *width, + unsigned *height) +{ + unsigned w = ~0; + unsigned h = ~0; + unsigned i; + + for (i = 0; i < fb->nr_cbufs; i++) { + w = MIN2(w, fb->cbufs[i]->width); + h = MIN2(h, fb->cbufs[i]->height); + } + + if (fb->zsbuf) { + w = MIN2(w, fb->zsbuf->width); + h = MIN2(h, fb->zsbuf->height); + } + + if (w == ~0) { + *width = 0; + *height = 0; + return FALSE; + } + else { + *width = w; + *height = h; + return TRUE; + } +} diff --git a/src/gallium/auxiliary/util/u_framebuffer.h b/src/gallium/auxiliary/util/u_framebuffer.h new file mode 100644 index 0000000..e7dc1e9 --- /dev/null +++ b/src/gallium/auxiliary/util/u_framebuffer.h @@ -0,0 +1,54 @@ +/************************************************************************** + * + * Copyright 2009-2010 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef U_FRAMEBUFFER_H +#define U_FRAMEBUFFER_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" + + +extern boolean +util_framebuffer_state_equal(const struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src); + +extern void +util_copy_framebuffer_state(struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src); + + +extern void +util_unreference_framebuffer_state(struct pipe_framebuffer_state *fb); + + +extern boolean +util_framebuffer_min_size(const struct pipe_framebuffer_state *fb, + unsigned *width, + unsigned *height); + +#endif /* U_FRAMEBUFFER_H */ diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c new file mode 100644 index 0000000..d22ae8b --- /dev/null +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -0,0 +1,1645 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2008 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 TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Mipmap generation utility + * + * @author Brian Paul + */ + + +#include "pipe/p_context.h" +#include "util/u_debug.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/p_state.h" + +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_draw_quad.h" +#include "util/u_gen_mipmap.h" +#include "util/u_simple_shaders.h" +#include "util/u_math.h" +#include "util/u_texture.h" +#include "util/u_half.h" +#include "util/u_surface.h" + +#include "cso_cache/cso_context.h" + + +struct gen_mipmap_state +{ + struct pipe_context *pipe; + struct cso_context *cso; + + struct pipe_blend_state blend; + struct pipe_depth_stencil_alpha_state depthstencil; + struct pipe_rasterizer_state rasterizer; + struct pipe_sampler_state sampler; + struct pipe_clip_state clip; + struct pipe_vertex_element velem[2]; + + void *vs; + void *fs1d, *fs2d, *fs3d, *fsCube; + + struct pipe_resource *vbuf; /**< quad vertices */ + unsigned vbuf_slot; + + float vertices[4][2][4]; /**< vertex/texcoords for quad */ +}; + + + +enum dtype +{ + DTYPE_UBYTE, + DTYPE_UBYTE_3_3_2, + DTYPE_USHORT, + DTYPE_USHORT_4_4_4_4, + DTYPE_USHORT_5_6_5, + DTYPE_USHORT_1_5_5_5_REV, + DTYPE_UINT, + DTYPE_FLOAT, + DTYPE_HALF_FLOAT +}; + + +typedef uint16_t half_float; + + +/** + * \name Support macros for do_row and do_row_3d + * + * The macro madness is here for two reasons. First, it compacts the code + * slightly. Second, it makes it much easier to adjust the specifics of the + * filter to tune the rounding characteristics. + */ +/*@{*/ +#define DECLARE_ROW_POINTERS(t, e) \ + const t(*rowA)[e] = (const t(*)[e]) srcRowA; \ + const t(*rowB)[e] = (const t(*)[e]) srcRowB; \ + const t(*rowC)[e] = (const t(*)[e]) srcRowC; \ + const t(*rowD)[e] = (const t(*)[e]) srcRowD; \ + t(*dst)[e] = (t(*)[e]) dstRow + +#define DECLARE_ROW_POINTERS0(t) \ + const t *rowA = (const t *) srcRowA; \ + const t *rowB = (const t *) srcRowB; \ + const t *rowC = (const t *) srcRowC; \ + const t *rowD = (const t *) srcRowD; \ + t *dst = (t *) dstRow + +#define FILTER_SUM_3D(Aj, Ak, Bj, Bk, Cj, Ck, Dj, Dk) \ + ((unsigned) Aj + (unsigned) Ak \ + + (unsigned) Bj + (unsigned) Bk \ + + (unsigned) Cj + (unsigned) Ck \ + + (unsigned) Dj + (unsigned) Dk \ + + 4) >> 3 + +#define FILTER_3D(e) \ + do { \ + dst[i][e] = FILTER_SUM_3D(rowA[j][e], rowA[k][e], \ + rowB[j][e], rowB[k][e], \ + rowC[j][e], rowC[k][e], \ + rowD[j][e], rowD[k][e]); \ + } while(0) + +#define FILTER_F_3D(e) \ + do { \ + dst[i][e] = (rowA[j][e] + rowA[k][e] \ + + rowB[j][e] + rowB[k][e] \ + + rowC[j][e] + rowC[k][e] \ + + rowD[j][e] + rowD[k][e]) * 0.125F; \ + } while(0) + +#define FILTER_HF_3D(e) \ + do { \ + const float aj = util_half_to_float(rowA[j][e]); \ + const float ak = util_half_to_float(rowA[k][e]); \ + const float bj = util_half_to_float(rowB[j][e]); \ + const float bk = util_half_to_float(rowB[k][e]); \ + const float cj = util_half_to_float(rowC[j][e]); \ + const float ck = util_half_to_float(rowC[k][e]); \ + const float dj = util_half_to_float(rowD[j][e]); \ + const float dk = util_half_to_float(rowD[k][e]); \ + dst[i][e] = util_float_to_half((aj + ak + bj + bk + cj + ck + dj + dk) \ + * 0.125F); \ + } while(0) +/*@}*/ + + +/** + * Average together two rows of a source image to produce a single new + * row in the dest image. It's legal for the two source rows to point + * to the same data. The source width must be equal to either the + * dest width or two times the dest width. + * \param datatype GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_FLOAT, etc. + * \param comps number of components per pixel (1..4) + */ +static void +do_row(enum dtype datatype, uint comps, int srcWidth, + const void *srcRowA, const void *srcRowB, + int dstWidth, void *dstRow) +{ + const uint k0 = (srcWidth == dstWidth) ? 0 : 1; + const uint colStride = (srcWidth == dstWidth) ? 1 : 2; + + assert(comps >= 1); + assert(comps <= 4); + + /* This assertion is no longer valid with non-power-of-2 textures + assert(srcWidth == dstWidth || srcWidth == 2 * dstWidth); + */ + + if (datatype == DTYPE_UBYTE && comps == 4) { + uint i, j, k; + const ubyte(*rowA)[4] = (const ubyte(*)[4]) srcRowA; + const ubyte(*rowB)[4] = (const ubyte(*)[4]) srcRowB; + ubyte(*dst)[4] = (ubyte(*)[4]) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4; + dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4; + dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4; + dst[i][3] = (rowA[j][3] + rowA[k][3] + rowB[j][3] + rowB[k][3]) / 4; + } + } + else if (datatype == DTYPE_UBYTE && comps == 3) { + uint i, j, k; + const ubyte(*rowA)[3] = (const ubyte(*)[3]) srcRowA; + const ubyte(*rowB)[3] = (const ubyte(*)[3]) srcRowB; + ubyte(*dst)[3] = (ubyte(*)[3]) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4; + dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4; + dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4; + } + } + else if (datatype == DTYPE_UBYTE && comps == 2) { + uint i, j, k; + const ubyte(*rowA)[2] = (const ubyte(*)[2]) srcRowA; + const ubyte(*rowB)[2] = (const ubyte(*)[2]) srcRowB; + ubyte(*dst)[2] = (ubyte(*)[2]) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) >> 2; + dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) >> 2; + } + } + else if (datatype == DTYPE_UBYTE && comps == 1) { + uint i, j, k; + const ubyte *rowA = (const ubyte *) srcRowA; + const ubyte *rowB = (const ubyte *) srcRowB; + ubyte *dst = (ubyte *) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) >> 2; + } + } + + else if (datatype == DTYPE_USHORT && comps == 4) { + uint i, j, k; + const ushort(*rowA)[4] = (const ushort(*)[4]) srcRowA; + const ushort(*rowB)[4] = (const ushort(*)[4]) srcRowB; + ushort(*dst)[4] = (ushort(*)[4]) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4; + dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4; + dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4; + dst[i][3] = (rowA[j][3] + rowA[k][3] + rowB[j][3] + rowB[k][3]) / 4; + } + } + else if (datatype == DTYPE_USHORT && comps == 3) { + uint i, j, k; + const ushort(*rowA)[3] = (const ushort(*)[3]) srcRowA; + const ushort(*rowB)[3] = (const ushort(*)[3]) srcRowB; + ushort(*dst)[3] = (ushort(*)[3]) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4; + dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4; + dst[i][2] = (rowA[j][2] + rowA[k][2] + rowB[j][2] + rowB[k][2]) / 4; + } + } + else if (datatype == DTYPE_USHORT && comps == 2) { + uint i, j, k; + const ushort(*rowA)[2] = (const ushort(*)[2]) srcRowA; + const ushort(*rowB)[2] = (const ushort(*)[2]) srcRowB; + ushort(*dst)[2] = (ushort(*)[2]) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + dst[i][0] = (rowA[j][0] + rowA[k][0] + rowB[j][0] + rowB[k][0]) / 4; + dst[i][1] = (rowA[j][1] + rowA[k][1] + rowB[j][1] + rowB[k][1]) / 4; + } + } + else if (datatype == DTYPE_USHORT && comps == 1) { + uint i, j, k; + const ushort *rowA = (const ushort *) srcRowA; + const ushort *rowB = (const ushort *) srcRowB; + ushort *dst = (ushort *) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) / 4; + } + } + + else if (datatype == DTYPE_FLOAT && comps == 4) { + uint i, j, k; + const float(*rowA)[4] = (const float(*)[4]) srcRowA; + const float(*rowB)[4] = (const float(*)[4]) srcRowB; + float(*dst)[4] = (float(*)[4]) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + dst[i][0] = (rowA[j][0] + rowA[k][0] + + rowB[j][0] + rowB[k][0]) * 0.25F; + dst[i][1] = (rowA[j][1] + rowA[k][1] + + rowB[j][1] + rowB[k][1]) * 0.25F; + dst[i][2] = (rowA[j][2] + rowA[k][2] + + rowB[j][2] + rowB[k][2]) * 0.25F; + dst[i][3] = (rowA[j][3] + rowA[k][3] + + rowB[j][3] + rowB[k][3]) * 0.25F; + } + } + else if (datatype == DTYPE_FLOAT && comps == 3) { + uint i, j, k; + const float(*rowA)[3] = (const float(*)[3]) srcRowA; + const float(*rowB)[3] = (const float(*)[3]) srcRowB; + float(*dst)[3] = (float(*)[3]) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + dst[i][0] = (rowA[j][0] + rowA[k][0] + + rowB[j][0] + rowB[k][0]) * 0.25F; + dst[i][1] = (rowA[j][1] + rowA[k][1] + + rowB[j][1] + rowB[k][1]) * 0.25F; + dst[i][2] = (rowA[j][2] + rowA[k][2] + + rowB[j][2] + rowB[k][2]) * 0.25F; + } + } + else if (datatype == DTYPE_FLOAT && comps == 2) { + uint i, j, k; + const float(*rowA)[2] = (const float(*)[2]) srcRowA; + const float(*rowB)[2] = (const float(*)[2]) srcRowB; + float(*dst)[2] = (float(*)[2]) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + dst[i][0] = (rowA[j][0] + rowA[k][0] + + rowB[j][0] + rowB[k][0]) * 0.25F; + dst[i][1] = (rowA[j][1] + rowA[k][1] + + rowB[j][1] + rowB[k][1]) * 0.25F; + } + } + else if (datatype == DTYPE_FLOAT && comps == 1) { + uint i, j, k; + const float *rowA = (const float *) srcRowA; + const float *rowB = (const float *) srcRowB; + float *dst = (float *) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) * 0.25F; + } + } + + else if (datatype == DTYPE_HALF_FLOAT && comps == 4) { + uint i, j, k, comp; + const half_float(*rowA)[4] = (const half_float(*)[4]) srcRowA; + const half_float(*rowB)[4] = (const half_float(*)[4]) srcRowB; + half_float(*dst)[4] = (half_float(*)[4]) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + for (comp = 0; comp < 4; comp++) { + float aj, ak, bj, bk; + aj = util_half_to_float(rowA[j][comp]); + ak = util_half_to_float(rowA[k][comp]); + bj = util_half_to_float(rowB[j][comp]); + bk = util_half_to_float(rowB[k][comp]); + dst[i][comp] = util_float_to_half((aj + ak + bj + bk) * 0.25F); + } + } + } + else if (datatype == DTYPE_HALF_FLOAT && comps == 3) { + uint i, j, k, comp; + const half_float(*rowA)[3] = (const half_float(*)[3]) srcRowA; + const half_float(*rowB)[3] = (const half_float(*)[3]) srcRowB; + half_float(*dst)[3] = (half_float(*)[3]) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + for (comp = 0; comp < 3; comp++) { + float aj, ak, bj, bk; + aj = util_half_to_float(rowA[j][comp]); + ak = util_half_to_float(rowA[k][comp]); + bj = util_half_to_float(rowB[j][comp]); + bk = util_half_to_float(rowB[k][comp]); + dst[i][comp] = util_float_to_half((aj + ak + bj + bk) * 0.25F); + } + } + } + else if (datatype == DTYPE_HALF_FLOAT && comps == 2) { + uint i, j, k, comp; + const half_float(*rowA)[2] = (const half_float(*)[2]) srcRowA; + const half_float(*rowB)[2] = (const half_float(*)[2]) srcRowB; + half_float(*dst)[2] = (half_float(*)[2]) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + for (comp = 0; comp < 2; comp++) { + float aj, ak, bj, bk; + aj = util_half_to_float(rowA[j][comp]); + ak = util_half_to_float(rowA[k][comp]); + bj = util_half_to_float(rowB[j][comp]); + bk = util_half_to_float(rowB[k][comp]); + dst[i][comp] = util_float_to_half((aj + ak + bj + bk) * 0.25F); + } + } + } + else if (datatype == DTYPE_HALF_FLOAT && comps == 1) { + uint i, j, k; + const half_float *rowA = (const half_float *) srcRowA; + const half_float *rowB = (const half_float *) srcRowB; + half_float *dst = (half_float *) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + float aj, ak, bj, bk; + aj = util_half_to_float(rowA[j]); + ak = util_half_to_float(rowA[k]); + bj = util_half_to_float(rowB[j]); + bk = util_half_to_float(rowB[k]); + dst[i] = util_float_to_half((aj + ak + bj + bk) * 0.25F); + } + } + + else if (datatype == DTYPE_UINT && comps == 1) { + uint i, j, k; + const uint *rowA = (const uint *) srcRowA; + const uint *rowB = (const uint *) srcRowB; + uint *dst = (uint *) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + dst[i] = rowA[j] / 4 + rowA[k] / 4 + rowB[j] / 4 + rowB[k] / 4; + } + } + + else if (datatype == DTYPE_USHORT_5_6_5 && comps == 3) { + uint i, j, k; + const ushort *rowA = (const ushort *) srcRowA; + const ushort *rowB = (const ushort *) srcRowB; + ushort *dst = (ushort *) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + const int rowAr0 = rowA[j] & 0x1f; + const int rowAr1 = rowA[k] & 0x1f; + const int rowBr0 = rowB[j] & 0x1f; + const int rowBr1 = rowB[k] & 0x1f; + const int rowAg0 = (rowA[j] >> 5) & 0x3f; + const int rowAg1 = (rowA[k] >> 5) & 0x3f; + const int rowBg0 = (rowB[j] >> 5) & 0x3f; + const int rowBg1 = (rowB[k] >> 5) & 0x3f; + const int rowAb0 = (rowA[j] >> 11) & 0x1f; + const int rowAb1 = (rowA[k] >> 11) & 0x1f; + const int rowBb0 = (rowB[j] >> 11) & 0x1f; + const int rowBb1 = (rowB[k] >> 11) & 0x1f; + const int red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2; + const int green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2; + const int blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2; + dst[i] = (blue << 11) | (green << 5) | red; + } + } + else if (datatype == DTYPE_USHORT_4_4_4_4 && comps == 4) { + uint i, j, k; + const ushort *rowA = (const ushort *) srcRowA; + const ushort *rowB = (const ushort *) srcRowB; + ushort *dst = (ushort *) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + const int rowAr0 = rowA[j] & 0xf; + const int rowAr1 = rowA[k] & 0xf; + const int rowBr0 = rowB[j] & 0xf; + const int rowBr1 = rowB[k] & 0xf; + const int rowAg0 = (rowA[j] >> 4) & 0xf; + const int rowAg1 = (rowA[k] >> 4) & 0xf; + const int rowBg0 = (rowB[j] >> 4) & 0xf; + const int rowBg1 = (rowB[k] >> 4) & 0xf; + const int rowAb0 = (rowA[j] >> 8) & 0xf; + const int rowAb1 = (rowA[k] >> 8) & 0xf; + const int rowBb0 = (rowB[j] >> 8) & 0xf; + const int rowBb1 = (rowB[k] >> 8) & 0xf; + const int rowAa0 = (rowA[j] >> 12) & 0xf; + const int rowAa1 = (rowA[k] >> 12) & 0xf; + const int rowBa0 = (rowB[j] >> 12) & 0xf; + const int rowBa1 = (rowB[k] >> 12) & 0xf; + const int red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2; + const int green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2; + const int blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2; + const int alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 2; + dst[i] = (alpha << 12) | (blue << 8) | (green << 4) | red; + } + } + else if (datatype == DTYPE_USHORT_1_5_5_5_REV && comps == 4) { + uint i, j, k; + const ushort *rowA = (const ushort *) srcRowA; + const ushort *rowB = (const ushort *) srcRowB; + ushort *dst = (ushort *) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + const int rowAr0 = rowA[j] & 0x1f; + const int rowAr1 = rowA[k] & 0x1f; + const int rowBr0 = rowB[j] & 0x1f; + const int rowBr1 = rowB[k] & 0x1f; + const int rowAg0 = (rowA[j] >> 5) & 0x1f; + const int rowAg1 = (rowA[k] >> 5) & 0x1f; + const int rowBg0 = (rowB[j] >> 5) & 0x1f; + const int rowBg1 = (rowB[k] >> 5) & 0x1f; + const int rowAb0 = (rowA[j] >> 10) & 0x1f; + const int rowAb1 = (rowA[k] >> 10) & 0x1f; + const int rowBb0 = (rowB[j] >> 10) & 0x1f; + const int rowBb1 = (rowB[k] >> 10) & 0x1f; + const int rowAa0 = (rowA[j] >> 15) & 0x1; + const int rowAa1 = (rowA[k] >> 15) & 0x1; + const int rowBa0 = (rowB[j] >> 15) & 0x1; + const int rowBa1 = (rowB[k] >> 15) & 0x1; + const int red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2; + const int green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2; + const int blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2; + const int alpha = (rowAa0 + rowAa1 + rowBa0 + rowBa1) >> 2; + dst[i] = (alpha << 15) | (blue << 10) | (green << 5) | red; + } + } + else if (datatype == DTYPE_UBYTE_3_3_2 && comps == 3) { + uint i, j, k; + const ubyte *rowA = (const ubyte *) srcRowA; + const ubyte *rowB = (const ubyte *) srcRowB; + ubyte *dst = (ubyte *) dstRow; + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + const int rowAr0 = rowA[j] & 0x3; + const int rowAr1 = rowA[k] & 0x3; + const int rowBr0 = rowB[j] & 0x3; + const int rowBr1 = rowB[k] & 0x3; + const int rowAg0 = (rowA[j] >> 2) & 0x7; + const int rowAg1 = (rowA[k] >> 2) & 0x7; + const int rowBg0 = (rowB[j] >> 2) & 0x7; + const int rowBg1 = (rowB[k] >> 2) & 0x7; + const int rowAb0 = (rowA[j] >> 5) & 0x7; + const int rowAb1 = (rowA[k] >> 5) & 0x7; + const int rowBb0 = (rowB[j] >> 5) & 0x7; + const int rowBb1 = (rowB[k] >> 5) & 0x7; + const int red = (rowAr0 + rowAr1 + rowBr0 + rowBr1) >> 2; + const int green = (rowAg0 + rowAg1 + rowBg0 + rowBg1) >> 2; + const int blue = (rowAb0 + rowAb1 + rowBb0 + rowBb1) >> 2; + dst[i] = (blue << 5) | (green << 2) | red; + } + } + else { + debug_printf("bad format in do_row()"); + } +} + + +/** + * Average together four rows of a source image to produce a single new + * row in the dest image. It's legal for the two source rows to point + * to the same data. The source width must be equal to either the + * dest width or two times the dest width. + * + * \param datatype GL pixel type \c GL_UNSIGNED_BYTE, \c GL_UNSIGNED_SHORT, + * \c GL_FLOAT, etc. + * \param comps number of components per pixel (1..4) + * \param srcWidth Width of a row in the source data + * \param srcRowA Pointer to one of the rows of source data + * \param srcRowB Pointer to one of the rows of source data + * \param srcRowC Pointer to one of the rows of source data + * \param srcRowD Pointer to one of the rows of source data + * \param dstWidth Width of a row in the destination data + * \param srcRowA Pointer to the row of destination data + */ +static void +do_row_3D(enum dtype datatype, uint comps, int srcWidth, + const void *srcRowA, const void *srcRowB, + const void *srcRowC, const void *srcRowD, + int dstWidth, void *dstRow) +{ + const uint k0 = (srcWidth == dstWidth) ? 0 : 1; + const uint colStride = (srcWidth == dstWidth) ? 1 : 2; + uint i, j, k; + + assert(comps >= 1); + assert(comps <= 4); + + if ((datatype == DTYPE_UBYTE) && (comps == 4)) { + DECLARE_ROW_POINTERS(ubyte, 4); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_3D(0); + FILTER_3D(1); + FILTER_3D(2); + FILTER_3D(3); + } + } + else if ((datatype == DTYPE_UBYTE) && (comps == 3)) { + DECLARE_ROW_POINTERS(ubyte, 3); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_3D(0); + FILTER_3D(1); + FILTER_3D(2); + } + } + else if ((datatype == DTYPE_UBYTE) && (comps == 2)) { + DECLARE_ROW_POINTERS(ubyte, 2); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_3D(0); + FILTER_3D(1); + } + } + else if ((datatype == DTYPE_UBYTE) && (comps == 1)) { + DECLARE_ROW_POINTERS(ubyte, 1); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_3D(0); + } + } + else if ((datatype == DTYPE_USHORT) && (comps == 4)) { + DECLARE_ROW_POINTERS(ushort, 4); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_3D(0); + FILTER_3D(1); + FILTER_3D(2); + FILTER_3D(3); + } + } + else if ((datatype == DTYPE_USHORT) && (comps == 3)) { + DECLARE_ROW_POINTERS(ushort, 3); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_3D(0); + FILTER_3D(1); + FILTER_3D(2); + } + } + else if ((datatype == DTYPE_USHORT) && (comps == 2)) { + DECLARE_ROW_POINTERS(ushort, 2); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_3D(0); + FILTER_3D(1); + } + } + else if ((datatype == DTYPE_USHORT) && (comps == 1)) { + DECLARE_ROW_POINTERS(ushort, 1); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_3D(0); + } + } + else if ((datatype == DTYPE_FLOAT) && (comps == 4)) { + DECLARE_ROW_POINTERS(float, 4); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_F_3D(0); + FILTER_F_3D(1); + FILTER_F_3D(2); + FILTER_F_3D(3); + } + } + else if ((datatype == DTYPE_FLOAT) && (comps == 3)) { + DECLARE_ROW_POINTERS(float, 3); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_F_3D(0); + FILTER_F_3D(1); + FILTER_F_3D(2); + } + } + else if ((datatype == DTYPE_FLOAT) && (comps == 2)) { + DECLARE_ROW_POINTERS(float, 2); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_F_3D(0); + FILTER_F_3D(1); + } + } + else if ((datatype == DTYPE_FLOAT) && (comps == 1)) { + DECLARE_ROW_POINTERS(float, 1); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_F_3D(0); + } + } + else if ((datatype == DTYPE_HALF_FLOAT) && (comps == 4)) { + DECLARE_ROW_POINTERS(half_float, 4); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_HF_3D(0); + FILTER_HF_3D(1); + FILTER_HF_3D(2); + FILTER_HF_3D(3); + } + } + else if ((datatype == DTYPE_HALF_FLOAT) && (comps == 3)) { + DECLARE_ROW_POINTERS(half_float, 4); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_HF_3D(0); + FILTER_HF_3D(1); + FILTER_HF_3D(2); + } + } + else if ((datatype == DTYPE_HALF_FLOAT) && (comps == 2)) { + DECLARE_ROW_POINTERS(half_float, 4); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_HF_3D(0); + FILTER_HF_3D(1); + } + } + else if ((datatype == DTYPE_HALF_FLOAT) && (comps == 1)) { + DECLARE_ROW_POINTERS(half_float, 4); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + FILTER_HF_3D(0); + } + } + else if ((datatype == DTYPE_UINT) && (comps == 1)) { + const uint *rowA = (const uint *) srcRowA; + const uint *rowB = (const uint *) srcRowB; + const uint *rowC = (const uint *) srcRowC; + const uint *rowD = (const uint *) srcRowD; + float *dst = (float *) dstRow; + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + const uint64_t tmp = (((uint64_t) rowA[j] + (uint64_t) rowA[k]) + + ((uint64_t) rowB[j] + (uint64_t) rowB[k]) + + ((uint64_t) rowC[j] + (uint64_t) rowC[k]) + + ((uint64_t) rowD[j] + (uint64_t) rowD[k])); + dst[i] = (float)((double) tmp * 0.125); + } + } + else if ((datatype == DTYPE_USHORT_5_6_5) && (comps == 3)) { + DECLARE_ROW_POINTERS0(ushort); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + const int rowAr0 = rowA[j] & 0x1f; + const int rowAr1 = rowA[k] & 0x1f; + const int rowBr0 = rowB[j] & 0x1f; + const int rowBr1 = rowB[k] & 0x1f; + const int rowCr0 = rowC[j] & 0x1f; + const int rowCr1 = rowC[k] & 0x1f; + const int rowDr0 = rowD[j] & 0x1f; + const int rowDr1 = rowD[k] & 0x1f; + const int rowAg0 = (rowA[j] >> 5) & 0x3f; + const int rowAg1 = (rowA[k] >> 5) & 0x3f; + const int rowBg0 = (rowB[j] >> 5) & 0x3f; + const int rowBg1 = (rowB[k] >> 5) & 0x3f; + const int rowCg0 = (rowC[j] >> 5) & 0x3f; + const int rowCg1 = (rowC[k] >> 5) & 0x3f; + const int rowDg0 = (rowD[j] >> 5) & 0x3f; + const int rowDg1 = (rowD[k] >> 5) & 0x3f; + const int rowAb0 = (rowA[j] >> 11) & 0x1f; + const int rowAb1 = (rowA[k] >> 11) & 0x1f; + const int rowBb0 = (rowB[j] >> 11) & 0x1f; + const int rowBb1 = (rowB[k] >> 11) & 0x1f; + const int rowCb0 = (rowC[j] >> 11) & 0x1f; + const int rowCb1 = (rowC[k] >> 11) & 0x1f; + const int rowDb0 = (rowD[j] >> 11) & 0x1f; + const int rowDb1 = (rowD[k] >> 11) & 0x1f; + const int r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1, + rowCr0, rowCr1, rowDr0, rowDr1); + const int g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1, + rowCg0, rowCg1, rowDg0, rowDg1); + const int b = FILTER_SUM_3D(rowAb0, rowAb1, rowBb0, rowBb1, + rowCb0, rowCb1, rowDb0, rowDb1); + dst[i] = (b << 11) | (g << 5) | r; + } + } + else if ((datatype == DTYPE_USHORT_4_4_4_4) && (comps == 4)) { + DECLARE_ROW_POINTERS0(ushort); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + const int rowAr0 = rowA[j] & 0xf; + const int rowAr1 = rowA[k] & 0xf; + const int rowBr0 = rowB[j] & 0xf; + const int rowBr1 = rowB[k] & 0xf; + const int rowCr0 = rowC[j] & 0xf; + const int rowCr1 = rowC[k] & 0xf; + const int rowDr0 = rowD[j] & 0xf; + const int rowDr1 = rowD[k] & 0xf; + const int rowAg0 = (rowA[j] >> 4) & 0xf; + const int rowAg1 = (rowA[k] >> 4) & 0xf; + const int rowBg0 = (rowB[j] >> 4) & 0xf; + const int rowBg1 = (rowB[k] >> 4) & 0xf; + const int rowCg0 = (rowC[j] >> 4) & 0xf; + const int rowCg1 = (rowC[k] >> 4) & 0xf; + const int rowDg0 = (rowD[j] >> 4) & 0xf; + const int rowDg1 = (rowD[k] >> 4) & 0xf; + const int rowAb0 = (rowA[j] >> 8) & 0xf; + const int rowAb1 = (rowA[k] >> 8) & 0xf; + const int rowBb0 = (rowB[j] >> 8) & 0xf; + const int rowBb1 = (rowB[k] >> 8) & 0xf; + const int rowCb0 = (rowC[j] >> 8) & 0xf; + const int rowCb1 = (rowC[k] >> 8) & 0xf; + const int rowDb0 = (rowD[j] >> 8) & 0xf; + const int rowDb1 = (rowD[k] >> 8) & 0xf; + const int rowAa0 = (rowA[j] >> 12) & 0xf; + const int rowAa1 = (rowA[k] >> 12) & 0xf; + const int rowBa0 = (rowB[j] >> 12) & 0xf; + const int rowBa1 = (rowB[k] >> 12) & 0xf; + const int rowCa0 = (rowC[j] >> 12) & 0xf; + const int rowCa1 = (rowC[k] >> 12) & 0xf; + const int rowDa0 = (rowD[j] >> 12) & 0xf; + const int rowDa1 = (rowD[k] >> 12) & 0xf; + const int r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1, + rowCr0, rowCr1, rowDr0, rowDr1); + const int g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1, + rowCg0, rowCg1, rowDg0, rowDg1); + const int b = FILTER_SUM_3D(rowAb0, rowAb1, rowBb0, rowBb1, + rowCb0, rowCb1, rowDb0, rowDb1); + const int a = FILTER_SUM_3D(rowAa0, rowAa1, rowBa0, rowBa1, + rowCa0, rowCa1, rowDa0, rowDa1); + + dst[i] = (a << 12) | (b << 8) | (g << 4) | r; + } + } + else if ((datatype == DTYPE_USHORT_1_5_5_5_REV) && (comps == 4)) { + DECLARE_ROW_POINTERS0(ushort); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + const int rowAr0 = rowA[j] & 0x1f; + const int rowAr1 = rowA[k] & 0x1f; + const int rowBr0 = rowB[j] & 0x1f; + const int rowBr1 = rowB[k] & 0x1f; + const int rowCr0 = rowC[j] & 0x1f; + const int rowCr1 = rowC[k] & 0x1f; + const int rowDr0 = rowD[j] & 0x1f; + const int rowDr1 = rowD[k] & 0x1f; + const int rowAg0 = (rowA[j] >> 5) & 0x1f; + const int rowAg1 = (rowA[k] >> 5) & 0x1f; + const int rowBg0 = (rowB[j] >> 5) & 0x1f; + const int rowBg1 = (rowB[k] >> 5) & 0x1f; + const int rowCg0 = (rowC[j] >> 5) & 0x1f; + const int rowCg1 = (rowC[k] >> 5) & 0x1f; + const int rowDg0 = (rowD[j] >> 5) & 0x1f; + const int rowDg1 = (rowD[k] >> 5) & 0x1f; + const int rowAb0 = (rowA[j] >> 10) & 0x1f; + const int rowAb1 = (rowA[k] >> 10) & 0x1f; + const int rowBb0 = (rowB[j] >> 10) & 0x1f; + const int rowBb1 = (rowB[k] >> 10) & 0x1f; + const int rowCb0 = (rowC[j] >> 10) & 0x1f; + const int rowCb1 = (rowC[k] >> 10) & 0x1f; + const int rowDb0 = (rowD[j] >> 10) & 0x1f; + const int rowDb1 = (rowD[k] >> 10) & 0x1f; + const int rowAa0 = (rowA[j] >> 15) & 0x1; + const int rowAa1 = (rowA[k] >> 15) & 0x1; + const int rowBa0 = (rowB[j] >> 15) & 0x1; + const int rowBa1 = (rowB[k] >> 15) & 0x1; + const int rowCa0 = (rowC[j] >> 15) & 0x1; + const int rowCa1 = (rowC[k] >> 15) & 0x1; + const int rowDa0 = (rowD[j] >> 15) & 0x1; + const int rowDa1 = (rowD[k] >> 15) & 0x1; + const int r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1, + rowCr0, rowCr1, rowDr0, rowDr1); + const int g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1, + rowCg0, rowCg1, rowDg0, rowDg1); + const int b = FILTER_SUM_3D(rowAb0, rowAb1, rowBb0, rowBb1, + rowCb0, rowCb1, rowDb0, rowDb1); + const int a = FILTER_SUM_3D(rowAa0, rowAa1, rowBa0, rowBa1, + rowCa0, rowCa1, rowDa0, rowDa1); + + dst[i] = (a << 15) | (b << 10) | (g << 5) | r; + } + } + else if ((datatype == DTYPE_UBYTE_3_3_2) && (comps == 3)) { + DECLARE_ROW_POINTERS0(ushort); + + for (i = j = 0, k = k0; i < (uint) dstWidth; + i++, j += colStride, k += colStride) { + const int rowAr0 = rowA[j] & 0x3; + const int rowAr1 = rowA[k] & 0x3; + const int rowBr0 = rowB[j] & 0x3; + const int rowBr1 = rowB[k] & 0x3; + const int rowCr0 = rowC[j] & 0x3; + const int rowCr1 = rowC[k] & 0x3; + const int rowDr0 = rowD[j] & 0x3; + const int rowDr1 = rowD[k] & 0x3; + const int rowAg0 = (rowA[j] >> 2) & 0x7; + const int rowAg1 = (rowA[k] >> 2) & 0x7; + const int rowBg0 = (rowB[j] >> 2) & 0x7; + const int rowBg1 = (rowB[k] >> 2) & 0x7; + const int rowCg0 = (rowC[j] >> 2) & 0x7; + const int rowCg1 = (rowC[k] >> 2) & 0x7; + const int rowDg0 = (rowD[j] >> 2) & 0x7; + const int rowDg1 = (rowD[k] >> 2) & 0x7; + const int rowAb0 = (rowA[j] >> 5) & 0x7; + const int rowAb1 = (rowA[k] >> 5) & 0x7; + const int rowBb0 = (rowB[j] >> 5) & 0x7; + const int rowBb1 = (rowB[k] >> 5) & 0x7; + const int rowCb0 = (rowC[j] >> 5) & 0x7; + const int rowCb1 = (rowC[k] >> 5) & 0x7; + const int rowDb0 = (rowD[j] >> 5) & 0x7; + const int rowDb1 = (rowD[k] >> 5) & 0x7; + const int r = FILTER_SUM_3D(rowAr0, rowAr1, rowBr0, rowBr1, + rowCr0, rowCr1, rowDr0, rowDr1); + const int g = FILTER_SUM_3D(rowAg0, rowAg1, rowBg0, rowBg1, + rowCg0, rowCg1, rowDg0, rowDg1); + const int b = FILTER_SUM_3D(rowAb0, rowAb1, rowBb0, rowBb1, + rowCb0, rowCb1, rowDb0, rowDb1); + dst[i] = (b << 5) | (g << 2) | r; + } + } + else { + debug_printf("bad format in do_row_3D()"); + } +} + + + +static void +format_to_type_comps(enum pipe_format pformat, + enum dtype *datatype, uint *comps) +{ + /* XXX I think this could be implemented in terms of the pf_*() functions */ + switch (pformat) { + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_A8B8G8R8_SRGB: + case PIPE_FORMAT_X8B8G8R8_SRGB: + case PIPE_FORMAT_B8G8R8A8_SRGB: + case PIPE_FORMAT_B8G8R8X8_SRGB: + case PIPE_FORMAT_A8R8G8B8_SRGB: + case PIPE_FORMAT_X8R8G8B8_SRGB: + case PIPE_FORMAT_R8G8B8_SRGB: + *datatype = DTYPE_UBYTE; + *comps = 4; + return; + case PIPE_FORMAT_B5G5R5X1_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: + *datatype = DTYPE_USHORT_1_5_5_5_REV; + *comps = 4; + return; + case PIPE_FORMAT_B4G4R4A4_UNORM: + *datatype = DTYPE_USHORT_4_4_4_4; + *comps = 4; + return; + case PIPE_FORMAT_B5G6R5_UNORM: + *datatype = DTYPE_USHORT_5_6_5; + *comps = 3; + return; + case PIPE_FORMAT_L8_UNORM: + case PIPE_FORMAT_L8_SRGB: + case PIPE_FORMAT_A8_UNORM: + case PIPE_FORMAT_I8_UNORM: + *datatype = DTYPE_UBYTE; + *comps = 1; + return; + case PIPE_FORMAT_L8A8_UNORM: + case PIPE_FORMAT_L8A8_SRGB: + *datatype = DTYPE_UBYTE; + *comps = 2; + return; + default: + assert(0); + *datatype = DTYPE_UBYTE; + *comps = 0; + break; + } +} + + +static void +reduce_1d(enum pipe_format pformat, + int srcWidth, const ubyte *srcPtr, + int dstWidth, ubyte *dstPtr) +{ + enum dtype datatype; + uint comps; + + format_to_type_comps(pformat, &datatype, &comps); + + /* we just duplicate the input row, kind of hack, saves code */ + do_row(datatype, comps, + srcWidth, srcPtr, srcPtr, + dstWidth, dstPtr); +} + + +/** + * Strides are in bytes. If zero, it'll be computed as width * bpp. + */ +static void +reduce_2d(enum pipe_format pformat, + int srcWidth, int srcHeight, + int srcRowStride, const ubyte *srcPtr, + int dstWidth, int dstHeight, + int dstRowStride, ubyte *dstPtr) +{ + enum dtype datatype; + uint comps; + const int bpt = util_format_get_blocksize(pformat); + const ubyte *srcA, *srcB; + ubyte *dst; + int row; + + format_to_type_comps(pformat, &datatype, &comps); + + if (!srcRowStride) + srcRowStride = bpt * srcWidth; + + if (!dstRowStride) + dstRowStride = bpt * dstWidth; + + /* Compute src and dst pointers */ + srcA = srcPtr; + if (srcHeight > 1) + srcB = srcA + srcRowStride; + else + srcB = srcA; + dst = dstPtr; + + for (row = 0; row < dstHeight; row++) { + do_row(datatype, comps, + srcWidth, srcA, srcB, + dstWidth, dst); + srcA += 2 * srcRowStride; + srcB += 2 * srcRowStride; + dst += dstRowStride; + } +} + + +static void +reduce_3d(enum pipe_format pformat, + int srcWidth, int srcHeight, int srcDepth, + int srcRowStride, int srcImageStride, const ubyte *srcPtr, + int dstWidth, int dstHeight, int dstDepth, + int dstRowStride, int dstImageStride, ubyte *dstPtr) +{ + const int bpt = util_format_get_blocksize(pformat); + int img, row; + int srcImageOffset, srcRowOffset; + enum dtype datatype; + uint comps; + + format_to_type_comps(pformat, &datatype, &comps); + + /* XXX I think we should rather assert those strides */ + if (!srcImageStride) + srcImageStride = srcWidth * srcHeight * bpt; + if (!dstImageStride) + dstImageStride = dstWidth * dstHeight * bpt; + + if (!srcRowStride) + srcRowStride = srcWidth * bpt; + if (!dstRowStride) + dstRowStride = dstWidth * bpt; + + /* Offset between adjacent src images to be averaged together */ + srcImageOffset = (srcDepth == dstDepth) ? 0 : srcImageStride; + + /* Offset between adjacent src rows to be averaged together */ + srcRowOffset = (srcHeight == dstHeight) ? 0 : srcRowStride; + + /* + * Need to average together up to 8 src pixels for each dest pixel. + * Break that down into 3 operations: + * 1. take two rows from source image and average them together. + * 2. take two rows from next source image and average them together. + * 3. take the two averaged rows and average them for the final dst row. + */ + + /* + printf("mip3d %d x %d x %d -> %d x %d x %d\n", + srcWidth, srcHeight, srcDepth, dstWidth, dstHeight, dstDepth); + */ + + for (img = 0; img < dstDepth; img++) { + /* first source image pointer */ + const ubyte *imgSrcA = srcPtr + + img * (srcImageStride + srcImageOffset); + /* second source image pointer */ + const ubyte *imgSrcB = imgSrcA + srcImageOffset; + /* address of the dest image */ + ubyte *imgDst = dstPtr + img * dstImageStride; + + /* setup the four source row pointers and the dest row pointer */ + const ubyte *srcImgARowA = imgSrcA; + const ubyte *srcImgARowB = imgSrcA + srcRowOffset; + const ubyte *srcImgBRowA = imgSrcB; + const ubyte *srcImgBRowB = imgSrcB + srcRowOffset; + ubyte *dstImgRow = imgDst; + + for (row = 0; row < dstHeight; row++) { + do_row_3D(datatype, comps, srcWidth, + srcImgARowA, srcImgARowB, + srcImgBRowA, srcImgBRowB, + dstWidth, dstImgRow); + + /* advance to next rows */ + srcImgARowA += srcRowStride + srcRowOffset; + srcImgARowB += srcRowStride + srcRowOffset; + srcImgBRowA += srcRowStride + srcRowOffset; + srcImgBRowB += srcRowStride + srcRowOffset; + dstImgRow += dstImageStride; + } + } +} + + + + +static void +make_1d_mipmap(struct gen_mipmap_state *ctx, + struct pipe_resource *pt, + uint layer, uint baseLevel, uint lastLevel) +{ + struct pipe_context *pipe = ctx->pipe; + uint dstLevel; + + for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) { + const uint srcLevel = dstLevel - 1; + struct pipe_transfer *srcTrans, *dstTrans; + void *srcMap, *dstMap; + + srcTrans = pipe_get_transfer(pipe, pt, srcLevel, layer, + PIPE_TRANSFER_READ, 0, 0, + u_minify(pt->width0, srcLevel), + u_minify(pt->height0, srcLevel)); + dstTrans = pipe_get_transfer(pipe, pt, dstLevel, layer, + PIPE_TRANSFER_WRITE, 0, 0, + u_minify(pt->width0, dstLevel), + u_minify(pt->height0, dstLevel)); + + srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans); + dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans); + + reduce_1d(pt->format, + srcTrans->box.width, srcMap, + dstTrans->box.width, dstMap); + + pipe->transfer_unmap(pipe, srcTrans); + pipe->transfer_unmap(pipe, dstTrans); + + pipe->transfer_destroy(pipe, srcTrans); + pipe->transfer_destroy(pipe, dstTrans); + } +} + + +static void +make_2d_mipmap(struct gen_mipmap_state *ctx, + struct pipe_resource *pt, + uint layer, uint baseLevel, uint lastLevel) +{ + struct pipe_context *pipe = ctx->pipe; + uint dstLevel; + + assert(util_format_get_blockwidth(pt->format) == 1); + assert(util_format_get_blockheight(pt->format) == 1); + + for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) { + const uint srcLevel = dstLevel - 1; + struct pipe_transfer *srcTrans, *dstTrans; + ubyte *srcMap, *dstMap; + + srcTrans = pipe_get_transfer(pipe, pt, srcLevel, layer, + PIPE_TRANSFER_READ, 0, 0, + u_minify(pt->width0, srcLevel), + u_minify(pt->height0, srcLevel)); + dstTrans = pipe_get_transfer(pipe, pt, dstLevel, layer, + PIPE_TRANSFER_WRITE, 0, 0, + u_minify(pt->width0, dstLevel), + u_minify(pt->height0, dstLevel)); + + srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans); + dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans); + + reduce_2d(pt->format, + srcTrans->box.width, srcTrans->box.height, + srcTrans->stride, srcMap, + dstTrans->box.width, dstTrans->box.height, + dstTrans->stride, dstMap); + + pipe->transfer_unmap(pipe, srcTrans); + pipe->transfer_unmap(pipe, dstTrans); + + pipe->transfer_destroy(pipe, srcTrans); + pipe->transfer_destroy(pipe, dstTrans); + } +} + + +/* XXX looks a bit more like it could work now but need to test */ +static void +make_3d_mipmap(struct gen_mipmap_state *ctx, + struct pipe_resource *pt, + uint face, uint baseLevel, uint lastLevel) +{ + struct pipe_context *pipe = ctx->pipe; + uint dstLevel; + struct pipe_box src_box, dst_box; + + assert(util_format_get_blockwidth(pt->format) == 1); + assert(util_format_get_blockheight(pt->format) == 1); + + src_box.x = src_box.y = src_box.z = 0; + dst_box.x = dst_box.y = dst_box.z = 0; + + for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) { + const uint srcLevel = dstLevel - 1; + struct pipe_transfer *srcTrans, *dstTrans; + ubyte *srcMap, *dstMap; + struct pipe_box src_box, dst_box; + src_box.width = u_minify(pt->width0, srcLevel); + src_box.height = u_minify(pt->height0, srcLevel); + src_box.depth = u_minify(pt->depth0, srcLevel); + dst_box.width = u_minify(pt->width0, dstLevel); + dst_box.height = u_minify(pt->height0, dstLevel); + dst_box.depth = u_minify(pt->depth0, dstLevel); + + srcTrans = pipe->get_transfer(pipe, pt, srcLevel, + PIPE_TRANSFER_READ, + &src_box); + dstTrans = pipe->get_transfer(pipe, pt, dstLevel, + PIPE_TRANSFER_WRITE, + &dst_box); + + srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans); + dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans); + + reduce_3d(pt->format, + srcTrans->box.width, srcTrans->box.height, srcTrans->box.depth, + srcTrans->stride, srcTrans->layer_stride, srcMap, + dstTrans->box.width, dstTrans->box.height, dstTrans->box.depth, + dstTrans->stride, dstTrans->layer_stride, dstMap); + + pipe->transfer_unmap(pipe, srcTrans); + pipe->transfer_unmap(pipe, dstTrans); + + pipe->transfer_destroy(pipe, srcTrans); + pipe->transfer_destroy(pipe, dstTrans); + } +} + + +static void +fallback_gen_mipmap(struct gen_mipmap_state *ctx, + struct pipe_resource *pt, + uint layer, uint baseLevel, uint lastLevel) +{ + switch (pt->target) { + case PIPE_TEXTURE_1D: + make_1d_mipmap(ctx, pt, layer, baseLevel, lastLevel); + break; + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + case PIPE_TEXTURE_CUBE: + make_2d_mipmap(ctx, pt, layer, baseLevel, lastLevel); + break; + case PIPE_TEXTURE_3D: + make_3d_mipmap(ctx, pt, layer, baseLevel, lastLevel); + break; + default: + assert(0); + } +} + + +/** + * Create a mipmap generation context. + * The idea is to create one of these and re-use it each time we need to + * generate a mipmap. + */ +struct gen_mipmap_state * +util_create_gen_mipmap(struct pipe_context *pipe, + struct cso_context *cso) +{ + struct gen_mipmap_state *ctx; + uint i; + + ctx = CALLOC_STRUCT(gen_mipmap_state); + if (!ctx) + return NULL; + + ctx->pipe = pipe; + ctx->cso = cso; + + /* disabled blending/masking */ + memset(&ctx->blend, 0, sizeof(ctx->blend)); + ctx->blend.rt[0].colormask = PIPE_MASK_RGBA; + + /* no-op depth/stencil/alpha */ + memset(&ctx->depthstencil, 0, sizeof(ctx->depthstencil)); + + /* rasterizer */ + memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer)); + ctx->rasterizer.cull_face = PIPE_FACE_NONE; + ctx->rasterizer.gl_rasterization_rules = 1; + + /* sampler state */ + memset(&ctx->sampler, 0, sizeof(ctx->sampler)); + ctx->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; + ctx->sampler.normalized_coords = 1; + + /* vertex elements state */ + memset(&ctx->velem[0], 0, sizeof(ctx->velem[0]) * 2); + for (i = 0; i < 2; i++) { + ctx->velem[i].src_offset = i * 4 * sizeof(float); + ctx->velem[i].instance_divisor = 0; + ctx->velem[i].vertex_buffer_index = 0; + ctx->velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + } + + /* vertex shader - still needed to specify mapping from fragment + * shader input semantics to vertex elements + */ + { + const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, + TGSI_SEMANTIC_GENERIC }; + const uint semantic_indexes[] = { 0, 0 }; + ctx->vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names, + semantic_indexes); + } + + /* fragment shader */ + ctx->fs1d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_1D, + TGSI_INTERPOLATE_LINEAR); + ctx->fs2d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D, + TGSI_INTERPOLATE_LINEAR); + ctx->fs3d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_3D, + TGSI_INTERPOLATE_LINEAR); + ctx->fsCube = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_CUBE, + TGSI_INTERPOLATE_LINEAR); + + /* vertex data that doesn't change */ + for (i = 0; i < 4; i++) { + ctx->vertices[i][0][2] = 0.0f; /* z */ + ctx->vertices[i][0][3] = 1.0f; /* w */ + ctx->vertices[i][1][3] = 1.0f; /* q */ + } + + /* Note: the actual vertex buffer is allocated as needed below */ + + return ctx; +} + + +/** + * Get next "slot" of vertex space in the vertex buffer. + * We're allocating one large vertex buffer and using it piece by piece. + */ +static unsigned +get_next_slot(struct gen_mipmap_state *ctx) +{ + const unsigned max_slots = 4096 / sizeof ctx->vertices; + + if (ctx->vbuf_slot >= max_slots) + util_gen_mipmap_flush( ctx ); + + if (!ctx->vbuf) { + ctx->vbuf = pipe_buffer_create(ctx->pipe->screen, + PIPE_BIND_VERTEX_BUFFER, + max_slots * sizeof ctx->vertices); + } + + return ctx->vbuf_slot++ * sizeof ctx->vertices; +} + + +static unsigned +set_vertex_data(struct gen_mipmap_state *ctx, + enum pipe_texture_target tex_target, + uint layer, float r) +{ + unsigned offset; + + /* vert[0].position */ + ctx->vertices[0][0][0] = -1.0f; /*x*/ + ctx->vertices[0][0][1] = -1.0f; /*y*/ + + /* vert[1].position */ + ctx->vertices[1][0][0] = 1.0f; + ctx->vertices[1][0][1] = -1.0f; + + /* vert[2].position */ + ctx->vertices[2][0][0] = 1.0f; + ctx->vertices[2][0][1] = 1.0f; + + /* vert[3].position */ + ctx->vertices[3][0][0] = -1.0f; + ctx->vertices[3][0][1] = 1.0f; + + /* Setup vertex texcoords. This is a little tricky for cube maps. */ + if (tex_target == PIPE_TEXTURE_CUBE) { + static const float st[4][2] = { + {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f} + }; + + util_map_texcoords2d_onto_cubemap(layer, &st[0][0], 2, + &ctx->vertices[0][1][0], 8); + } + else { + /* 1D/2D/3D */ + ctx->vertices[0][1][0] = 0.0f; /*s*/ + ctx->vertices[0][1][1] = 0.0f; /*t*/ + ctx->vertices[0][1][2] = r; /*r*/ + + ctx->vertices[1][1][0] = 1.0f; + ctx->vertices[1][1][1] = 0.0f; + ctx->vertices[1][1][2] = r; + + ctx->vertices[2][1][0] = 1.0f; + ctx->vertices[2][1][1] = 1.0f; + ctx->vertices[2][1][2] = r; + + ctx->vertices[3][1][0] = 0.0f; + ctx->vertices[3][1][1] = 1.0f; + ctx->vertices[3][1][2] = r; + } + + offset = get_next_slot( ctx ); + + pipe_buffer_write_nooverlap(ctx->pipe, ctx->vbuf, + offset, sizeof(ctx->vertices), ctx->vertices); + + return offset; +} + + + +/** + * Destroy a mipmap generation context + */ +void +util_destroy_gen_mipmap(struct gen_mipmap_state *ctx) +{ + struct pipe_context *pipe = ctx->pipe; + + pipe->delete_fs_state(pipe, ctx->fsCube); + pipe->delete_fs_state(pipe, ctx->fs3d); + pipe->delete_fs_state(pipe, ctx->fs2d); + pipe->delete_fs_state(pipe, ctx->fs1d); + pipe->delete_vs_state(pipe, ctx->vs); + + pipe_resource_reference(&ctx->vbuf, NULL); + + FREE(ctx); +} + + + +/* Release vertex buffer at end of frame to avoid synchronous + * rendering. + */ +void util_gen_mipmap_flush( struct gen_mipmap_state *ctx ) +{ + pipe_resource_reference(&ctx->vbuf, NULL); + ctx->vbuf_slot = 0; +} + + +/** + * Generate mipmap images. It's assumed all needed texture memory is + * already allocated. + * + * \param psv the sampler view to the texture to generate mipmap levels for + * \param face which cube face to generate mipmaps for (0 for non-cube maps) + * \param baseLevel the first mipmap level to use as a src + * \param lastLevel the last mipmap level to generate + * \param filter the minification filter used to generate mipmap levels with + * \param filter one of PIPE_TEX_FILTER_LINEAR, PIPE_TEX_FILTER_NEAREST + */ +void +util_gen_mipmap(struct gen_mipmap_state *ctx, + struct pipe_sampler_view *psv, + uint face, uint baseLevel, uint lastLevel, uint filter) +{ + struct pipe_context *pipe = ctx->pipe; + struct pipe_screen *screen = pipe->screen; + struct pipe_framebuffer_state fb; + struct pipe_resource *pt = psv->texture; + void *fs; + uint dstLevel; + uint offset; + + /* The texture object should have room for the levels which we're + * about to generate. + */ + assert(lastLevel <= pt->last_level); + + /* If this fails, why are we here? */ + assert(lastLevel > baseLevel); + + assert(filter == PIPE_TEX_FILTER_LINEAR || + filter == PIPE_TEX_FILTER_NEAREST); + + switch (pt->target) { + case PIPE_TEXTURE_1D: + fs = ctx->fs1d; + break; + case PIPE_TEXTURE_2D: + fs = ctx->fs2d; + break; + case PIPE_TEXTURE_3D: + fs = ctx->fs3d; + break; + case PIPE_TEXTURE_CUBE: + fs = ctx->fsCube; + break; + case PIPE_TEXTURE_1D_ARRAY: + case PIPE_TEXTURE_2D_ARRAY: + default: + assert(0); + fs = ctx->fs2d; + } + + /* check if we can render in the texture's format */ + if (!screen->is_format_supported(screen, psv->format, pt->target, + pt->nr_samples, PIPE_BIND_RENDER_TARGET, 0)) { + fallback_gen_mipmap(ctx, pt, face, baseLevel, lastLevel); + return; + } + + /* save state (restored below) */ + cso_save_blend(ctx->cso); + cso_save_depth_stencil_alpha(ctx->cso); + cso_save_rasterizer(ctx->cso); + cso_save_samplers(ctx->cso); + cso_save_fragment_sampler_views(ctx->cso); + cso_save_framebuffer(ctx->cso); + cso_save_fragment_shader(ctx->cso); + cso_save_vertex_shader(ctx->cso); + cso_save_viewport(ctx->cso); + cso_save_clip(ctx->cso); + cso_save_vertex_elements(ctx->cso); + + /* bind our state */ + cso_set_blend(ctx->cso, &ctx->blend); + cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil); + cso_set_rasterizer(ctx->cso, &ctx->rasterizer); + cso_set_clip(ctx->cso, &ctx->clip); + cso_set_vertex_elements(ctx->cso, 2, ctx->velem); + + cso_set_fragment_shader_handle(ctx->cso, fs); + cso_set_vertex_shader_handle(ctx->cso, ctx->vs); + + /* init framebuffer state */ + memset(&fb, 0, sizeof(fb)); + fb.nr_cbufs = 1; + + /* set min/mag to same filter for faster sw speed */ + ctx->sampler.mag_img_filter = filter; + ctx->sampler.min_img_filter = filter; + + /* + * XXX for small mipmap levels, it may be faster to use the software + * fallback path... + */ + for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) { + const uint srcLevel = dstLevel - 1; + struct pipe_viewport_state vp; + unsigned nr_layers, layer, i; + float rcoord = 0.0f; + + if (pt->target == PIPE_TEXTURE_3D) + nr_layers = u_minify(pt->depth0, dstLevel); + else + nr_layers = 1; + + for (i = 0; i < nr_layers; i++) { + struct pipe_surface *surf, surf_templ; + if (pt->target == PIPE_TEXTURE_3D) { + /* in theory with geom shaders and driver with full layer support + could do that in one go. */ + layer = i; + offset = 1.0f / (float)(nr_layers * 2); + /* XXX hmm really? */ + rcoord = (float)layer / (float)nr_layers + 1.0f / (float)(nr_layers * 2); + } + else + layer = face; + + memset(&surf_templ, 0, sizeof(surf_templ)); + u_surface_default_template(&surf_templ, pt, PIPE_BIND_RENDER_TARGET); + surf_templ.u.tex.level = dstLevel; + surf_templ.u.tex.first_layer = layer; + surf_templ.u.tex.last_layer = layer; + surf = pipe->create_surface(pipe, pt, &surf_templ); + + /* + * Setup framebuffer / dest surface + */ + fb.cbufs[0] = surf; + fb.width = u_minify(pt->width0, dstLevel); + fb.height = u_minify(pt->height0, dstLevel); + cso_set_framebuffer(ctx->cso, &fb); + + /* viewport */ + vp.scale[0] = 0.5f * fb.width; + vp.scale[1] = 0.5f * fb.height; + vp.scale[2] = 1.0f; + vp.scale[3] = 1.0f; + vp.translate[0] = 0.5f * fb.width; + vp.translate[1] = 0.5f * fb.height; + vp.translate[2] = 0.0f; + vp.translate[3] = 0.0f; + cso_set_viewport(ctx->cso, &vp); + + /* + * Setup sampler state + * Note: we should only have to set the min/max LOD clamps to ensure + * we grab texels from the right mipmap level. But some hardware + * has trouble with min clamping so we also set the lod_bias to + * try to work around that. + */ + ctx->sampler.min_lod = ctx->sampler.max_lod = (float) srcLevel; + ctx->sampler.lod_bias = (float) srcLevel; + cso_single_sampler(ctx->cso, 0, &ctx->sampler); + cso_single_sampler_done(ctx->cso); + + cso_set_fragment_sampler_views(ctx->cso, 1, &psv); + + /* quad coords in clip coords */ + offset = set_vertex_data(ctx, + pt->target, + face, + rcoord); + + util_draw_vertex_buffer(ctx->pipe, + ctx->vbuf, + offset, + PIPE_PRIM_TRIANGLE_FAN, + 4, /* verts */ + 2); /* attribs/vert */ + + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + + /* need to signal that the texture has changed _after_ rendering to it */ + pipe_surface_reference( &surf, NULL ); + } + } + + /* restore state we changed */ + cso_restore_blend(ctx->cso); + cso_restore_depth_stencil_alpha(ctx->cso); + cso_restore_rasterizer(ctx->cso); + cso_restore_samplers(ctx->cso); + cso_restore_fragment_sampler_views(ctx->cso); + cso_restore_framebuffer(ctx->cso); + cso_restore_fragment_shader(ctx->cso); + cso_restore_vertex_shader(ctx->cso); + cso_restore_viewport(ctx->cso); + cso_restore_clip(ctx->cso); + cso_restore_vertex_elements(ctx->cso); +} diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.h b/src/gallium/auxiliary/util/u_gen_mipmap.h new file mode 100644 index 0000000..a10b6a4 --- /dev/null +++ b/src/gallium/auxiliary/util/u_gen_mipmap.h @@ -0,0 +1,70 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef U_GENMIPMAP_H +#define U_GENMIPMAP_H + +#include "pipe/p_state.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct pipe_context; +struct pipe_resource; +struct cso_context; + +struct gen_mipmap_state; + + +extern struct gen_mipmap_state * +util_create_gen_mipmap(struct pipe_context *pipe, struct cso_context *cso); + + +extern void +util_destroy_gen_mipmap(struct gen_mipmap_state *ctx); + +/* Release vertex buffer at end of frame to avoid synchronous + * rendering. + */ +extern void +util_gen_mipmap_flush( struct gen_mipmap_state *ctx ); + + +extern void +util_gen_mipmap(struct gen_mipmap_state *ctx, + struct pipe_sampler_view *psv, + uint layer, uint baseLevel, uint lastLevel, uint filter); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/auxiliary/util/u_half.h b/src/gallium/auxiliary/util/u_half.h new file mode 100644 index 0000000..ad030e9 --- /dev/null +++ b/src/gallium/auxiliary/util/u_half.h @@ -0,0 +1,90 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef U_HALF_H +#define U_HALF_H + +#include "pipe/p_compiler.h" +#include "util/u_math.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern const uint32_t util_half_to_float_mantissa_table[2048]; +extern const uint32_t util_half_to_float_exponent_table[64]; +extern const uint32_t util_half_to_float_offset_table[64]; +extern const uint16_t util_float_to_half_base_table[512]; +extern const uint8_t util_float_to_half_shift_table[512]; + +/* + * Note that if the half float is a signaling NaN, the x87 FPU will turn + * it into a quiet NaN immediately upon loading into a float. + * + * Additionally, denormals may be flushed to zero. + * + * To avoid this, use the floatui functions instead of the float ones + * when just doing conversion rather than computation on the resulting + * floats. + */ + +static INLINE uint32_t +util_half_to_floatui(uint16_t h) +{ + unsigned exp = h >> 10; + return util_half_to_float_mantissa_table[util_half_to_float_offset_table[exp] + (h & 0x3ff)] + util_half_to_float_exponent_table[exp]; +} + +static INLINE float +util_half_to_float(uint16_t h) +{ + union fi r; + r.ui = util_half_to_floatui(h); + return r.f; +} + +static INLINE uint16_t +util_floatui_to_half(uint32_t v) +{ + unsigned signexp = v >> 23; + return util_float_to_half_base_table[signexp] + ((v & 0x007fffff) >> util_float_to_half_shift_table[signexp]); +} + +static INLINE uint16_t +util_float_to_half(float f) +{ + union fi i; + i.f = f; + return util_floatui_to_half(i.ui); +} + +#ifdef __cplusplus +} +#endif + +#endif /* U_HALF_H */ + diff --git a/src/gallium/auxiliary/util/u_half.py b/src/gallium/auxiliary/util/u_half.py new file mode 100644 index 0000000..915cf3b --- /dev/null +++ b/src/gallium/auxiliary/util/u_half.py @@ -0,0 +1,179 @@ +# Copyright 2010 Luca Barbieri +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice (including the +# next paragraph) shall be included in all copies or substantial +# portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# ************************************************************************* + +# The code is a reimplementation of the algorithm in +# www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf +# "Fast Half Float Conversions" by Jeroen van der Zijp, Nov 2008 +# +# The table contents have been slightly changed so that the exponent +# bias is now in the exponent table instead of the mantissa table (mostly +# for cosmetic reasons, and because it theoretically allows a variant +# that flushes denormal to zero but uses a mantissa table with 24-bit +# entries). +# +# The tables are also constructed slightly differently. +# + +# Note that using a 64K * 4 table is a terrible idea since it will not fit +# in the L1 cache and will massively pollute the L2 cache as well +# +# These should instead fit in the L1 cache. +# +# TODO: we could use a denormal bias table instead of the mantissa/offset +# tables: this would reduce the L1 cache usage from 8704 to 2304 bytes +# but would involve more computation +# +# Note however that if denormals are never encountered, the L1 cache usage +# is only about 4608 bytes anyway. + +table_index = None +table_length = None + +def begin(t, n, l): + global table_length + global table_index + table_index = 0 + table_length = l + print + print "const " + t + " " + n + "[" + str(l) + "] = {" + +def value(v): + global table_index + table_index += 1 + print "\t" + hex(v) + "," + +def end(): + global table_length + global table_index + print "};" + assert table_index == table_length + +print "/* This file is autogenerated by u_half.py. Do not edit directly. */" +print "#include \"util/u_half.h\"" + +begin("uint32_t", "util_half_to_float_mantissa_table", 2048) +# zero +value(0) + +# denormals +for i in xrange(1, 1024): + m = i << 13 + e = 0 + + # normalize number + while (m & 0x00800000) == 0: + e -= 0x00800000 + m <<= 1 + + m &= ~0x00800000 + e += 0x38800000 + value(m | e) + +# normals +for i in xrange(1024, 2048): + value((i - 1024) << 13) +end() + +begin("uint32_t", "util_half_to_float_exponent_table", 64) +# positive zero or denormals +value(0) + +# positive numbers +for i in xrange(1, 31): + value(0x38000000 + (i << 23)) + +# positive infinity/NaN +value(0x7f800000) + +# negative zero or denormals +value(0x80000000) + +# negative numbers +for i in range(33, 63): + value(0xb8000000 + ((i - 32) << 23)) + +# negative infinity/NaN +value(0xff800000) +end() + +begin("uint32_t", "util_half_to_float_offset_table", 64) +# positive zero or denormals +value(0) + +# positive normals +for i in range(1, 32): + value(1024) + +# negative zero or denormals +value(0) + +# negative normals +for i in xrange(33, 64): + value(1024) +end() + +begin("uint16_t", "util_float_to_half_base_table", 512) +for sign in (0, 0x8000): + # very small numbers mapping to zero + for i in xrange(-127, -24): + value(sign | 0) + + # small numbers mapping to denormals + for i in xrange(-24, -14): + value(sign | (0x400 >> (-14 -i))) + + # normal numbers + for i in xrange(-14, 16): + value(sign | ((i + 15) << 10)) + + # large numbers mapping to infinity + for i in xrange(16, 128): + value(sign | 0x7c00) + + # infinity and NaNs + value(sign | 0x7c00) +end() + +begin("uint8_t", "util_float_to_half_shift_table", 512) +for sign in (0, 0x8000): + # very small numbers mapping to zero + for i in xrange(-127, -24): + value(24) + + # small numbers mapping to denormals + for i in xrange(-24, -14): + value(-1 - i) + + # normal numbers + for i in xrange(-14, 16): + value(13) + + # large numbers mapping to infinity + for i in xrange(16, 128): + value(24) + + # infinity and NaNs + value(13) +end() + diff --git a/src/gallium/auxiliary/util/u_handle_table.c b/src/gallium/auxiliary/util/u_handle_table.c new file mode 100644 index 0000000..3703718 --- /dev/null +++ b/src/gallium/auxiliary/util/u_handle_table.c @@ -0,0 +1,298 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Generic handle table implementation. + * + * @author José Fonseca + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" + +#include "util/u_memory.h" +#include "util/u_handle_table.h" + + +#define HANDLE_TABLE_INITIAL_SIZE 16 + + +struct handle_table +{ + /** Object array. Empty handles have a null object */ + void **objects; + + /** Number of objects the handle can currently hold */ + unsigned size; + /** Number of consecutive objects allocated at the start of the table */ + unsigned filled; + + /** Optional object destructor */ + void (*destroy)(void *object); +}; + + +struct handle_table * +handle_table_create(void) +{ + struct handle_table *ht; + + ht = MALLOC_STRUCT(handle_table); + if(!ht) + return NULL; + + ht->objects = (void **)CALLOC(HANDLE_TABLE_INITIAL_SIZE, sizeof(void *)); + if(!ht->objects) { + FREE(ht); + return NULL; + } + + ht->size = HANDLE_TABLE_INITIAL_SIZE; + ht->filled = 0; + + ht->destroy = NULL; + + return ht; +} + + +void +handle_table_set_destroy(struct handle_table *ht, + void (*destroy)(void *object)) +{ + assert(ht); + if (!ht) + return; + ht->destroy = destroy; +} + + +/** + * Resize the table if necessary + */ +static INLINE int +handle_table_resize(struct handle_table *ht, + unsigned minimum_size) +{ + unsigned new_size; + void **new_objects; + + if(ht->size > minimum_size) + return ht->size; + + new_size = ht->size; + while(!(new_size > minimum_size)) + new_size *= 2; + assert(new_size); + + new_objects = (void **)REALLOC((void *)ht->objects, + ht->size*sizeof(void *), + new_size*sizeof(void *)); + if(!new_objects) + return 0; + + memset(new_objects + ht->size, 0, (new_size - ht->size)*sizeof(void *)); + + ht->size = new_size; + ht->objects = new_objects; + + return ht->size; +} + + +static INLINE void +handle_table_clear(struct handle_table *ht, + unsigned index) +{ + void *object; + + /* The order here is important so that the object being destroyed is not + * present in the table when seen by the destroy callback, because the + * destroy callback may directly or indirectly call the other functions in + * this module. + */ + + object = ht->objects[index]; + if(object) { + ht->objects[index] = NULL; + + if(ht->destroy) + ht->destroy(object); + } +} + + +unsigned +handle_table_add(struct handle_table *ht, + void *object) +{ + unsigned index; + unsigned handle; + + assert(ht); + assert(object); + if(!object || !ht) + return 0; + + /* linear search for an empty handle */ + while(ht->filled < ht->size) { + if(!ht->objects[ht->filled]) + break; + ++ht->filled; + } + + index = ht->filled; + handle = index + 1; + + /* check integer overflow */ + if(!handle) + return 0; + + /* grow the table if necessary */ + if(!handle_table_resize(ht, index)) + return 0; + + assert(!ht->objects[index]); + ht->objects[index] = object; + ++ht->filled; + + return handle; +} + + +unsigned +handle_table_set(struct handle_table *ht, + unsigned handle, + void *object) +{ + unsigned index; + + assert(ht); + assert(handle); + if(!handle || !ht) + return 0; + + assert(object); + if(!object) + return 0; + + index = handle - 1; + + /* grow the table if necessary */ + if(!handle_table_resize(ht, index)) + return 0; + + handle_table_clear(ht, index); + + ht->objects[index] = object; + + return handle; +} + + +void * +handle_table_get(struct handle_table *ht, + unsigned handle) +{ + void *object; + + assert(ht); + assert(handle); + if(!handle || !ht || handle > ht->size) + return NULL; + + object = ht->objects[handle - 1]; + + return object; +} + + +void +handle_table_remove(struct handle_table *ht, + unsigned handle) +{ + void *object; + unsigned index; + + assert(ht); + assert(handle); + if(!handle || !ht || handle > ht->size) + return; + + index = handle - 1; + object = ht->objects[index]; + if(!object) + return; + + handle_table_clear(ht, index); + + if(index < ht->filled) + ht->filled = index; +} + + +unsigned +handle_table_get_next_handle(struct handle_table *ht, + unsigned handle) +{ + unsigned index; + + for(index = handle; index < ht->size; ++index) { + if(ht->objects[index]) + return index + 1; + } + + return 0; +} + + +unsigned +handle_table_get_first_handle(struct handle_table *ht) +{ + return handle_table_get_next_handle(ht, 0); +} + + +void +handle_table_destroy(struct handle_table *ht) +{ + unsigned index; + assert(ht); + + if (!ht) + return; + + if(ht->destroy) + for(index = 0; index < ht->size; ++index) + handle_table_clear(ht, index); + + FREE(ht->objects); + FREE(ht); +} + diff --git a/src/gallium/auxiliary/util/u_handle_table.h b/src/gallium/auxiliary/util/u_handle_table.h new file mode 100644 index 0000000..d080135 --- /dev/null +++ b/src/gallium/auxiliary/util/u_handle_table.h @@ -0,0 +1,116 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Generic handle table. + * + * @author José Fonseca + */ + +#ifndef U_HANDLE_TABLE_H_ +#define U_HANDLE_TABLE_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Abstract data type to map integer handles to objects. + * + * Also referred as "pointer array". + */ +struct handle_table; + + +struct handle_table * +handle_table_create(void); + + +/** + * Set an optional destructor callback. + * + * If set, it will be called during handle_table_remove and + * handle_table_destroy calls. + */ +void +handle_table_set_destroy(struct handle_table *ht, + void (*destroy)(void *object)); + + +/** + * Add a new object. + * + * Returns a zero handle on failure (out of memory). + */ +unsigned +handle_table_add(struct handle_table *ht, + void *object); + +/** + * Returns zero on failure (out of memory). + */ +unsigned +handle_table_set(struct handle_table *ht, + unsigned handle, + void *object); + +/** + * Fetch an existing object. + * + * Returns NULL for an invalid handle. + */ +void * +handle_table_get(struct handle_table *ht, + unsigned handle); + + +void +handle_table_remove(struct handle_table *ht, + unsigned handle); + + +void +handle_table_destroy(struct handle_table *ht); + + +unsigned +handle_table_get_first_handle(struct handle_table *ht); + + +unsigned +handle_table_get_next_handle(struct handle_table *ht, + unsigned handle); + + +#ifdef __cplusplus +} +#endif + +#endif /* U_HANDLE_TABLE_H_ */ diff --git a/src/gallium/auxiliary/util/u_hash.c b/src/gallium/auxiliary/util/u_hash.c new file mode 100644 index 0000000..b67653e --- /dev/null +++ b/src/gallium/auxiliary/util/u_hash.c @@ -0,0 +1,121 @@ +/************************************************************************** + * + * Copyright 2008 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Hash functions implementation. + * + * @author Jose Fonseca + */ + + +#include "u_hash.h" + + +static const uint32_t +util_crc32_table[256] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + + +/** + * @sa http://www.w3.org/TR/PNG/#D-CRCAppendix + */ +uint32_t +util_hash_crc32(const void *data, size_t size) +{ + uint8_t *p = (uint8_t *)data; + uint32_t crc = 0xffffffff; + + while (size--) + crc = util_crc32_table[(crc ^ *p++) & 0xff] ^ (crc >> 8); + + return crc; +} diff --git a/src/gallium/auxiliary/util/u_hash.h b/src/gallium/auxiliary/util/u_hash.h new file mode 100644 index 0000000..8d92b07 --- /dev/null +++ b/src/gallium/auxiliary/util/u_hash.h @@ -0,0 +1,55 @@ +/************************************************************************** + * + * Copyright 2008 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Hash functions. + * + * @author Jose Fonseca + */ + +#ifndef U_HASH_H_ +#define U_HASH_H_ + + +#include "pipe/p_compiler.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +uint32_t +util_hash_crc32(const void *data, size_t size); + + +#ifdef __cplusplus +} +#endif + +#endif /* U_HASH_H_ */ diff --git a/src/gallium/auxiliary/util/u_hash_table.c b/src/gallium/auxiliary/util/u_hash_table.c new file mode 100644 index 0000000..5604e3a --- /dev/null +++ b/src/gallium/auxiliary/util/u_hash_table.c @@ -0,0 +1,293 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * General purpose hash table implementation. + * + * Just uses the cso_hash for now, but it might be better switch to a linear + * probing hash table implementation at some point -- as it is said they have + * better lookup and cache performance and it appears to be possible to write + * a lock-free implementation of such hash tables . + * + * @author José Fonseca + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" + +#include "cso_cache/cso_hash.h" + +#include "util/u_memory.h" +#include "util/u_hash_table.h" + + +struct util_hash_table +{ + struct cso_hash *cso; + + /** Hash function */ + unsigned (*hash)(void *key); + + /** Compare two keys */ + int (*compare)(void *key1, void *key2); + + /* TODO: key, value destructors? */ +}; + + +struct util_hash_table_item +{ + void *key; + void *value; +}; + + +static INLINE struct util_hash_table_item * +util_hash_table_item(struct cso_hash_iter iter) +{ + return (struct util_hash_table_item *)cso_hash_iter_data(iter); +} + + +struct util_hash_table * +util_hash_table_create(unsigned (*hash)(void *key), + int (*compare)(void *key1, void *key2)) +{ + struct util_hash_table *ht; + + ht = MALLOC_STRUCT(util_hash_table); + if(!ht) + return NULL; + + ht->cso = cso_hash_create(); + if(!ht->cso) { + FREE(ht); + return NULL; + } + + ht->hash = hash; + ht->compare = compare; + + return ht; +} + + +static INLINE struct cso_hash_iter +util_hash_table_find_iter(struct util_hash_table *ht, + void *key, + unsigned key_hash) +{ + struct cso_hash_iter iter; + struct util_hash_table_item *item; + + iter = cso_hash_find(ht->cso, key_hash); + while (!cso_hash_iter_is_null(iter)) { + item = (struct util_hash_table_item *)cso_hash_iter_data(iter); + if (!ht->compare(item->key, key)) + break; + iter = cso_hash_iter_next(iter); + } + + return iter; +} + + +static INLINE struct util_hash_table_item * +util_hash_table_find_item(struct util_hash_table *ht, + void *key, + unsigned key_hash) +{ + struct cso_hash_iter iter; + struct util_hash_table_item *item; + + iter = cso_hash_find(ht->cso, key_hash); + while (!cso_hash_iter_is_null(iter)) { + item = (struct util_hash_table_item *)cso_hash_iter_data(iter); + if (!ht->compare(item->key, key)) + return item; + iter = cso_hash_iter_next(iter); + } + + return NULL; +} + + +enum pipe_error +util_hash_table_set(struct util_hash_table *ht, + void *key, + void *value) +{ + unsigned key_hash; + struct util_hash_table_item *item; + struct cso_hash_iter iter; + + assert(ht); + if (!ht) + return PIPE_ERROR_BAD_INPUT; + + key_hash = ht->hash(key); + + item = util_hash_table_find_item(ht, key, key_hash); + if(item) { + /* TODO: key/value destruction? */ + item->value = value; + return PIPE_OK; + } + + item = MALLOC_STRUCT(util_hash_table_item); + if(!item) + return PIPE_ERROR_OUT_OF_MEMORY; + + item->key = key; + item->value = value; + + iter = cso_hash_insert(ht->cso, key_hash, item); + if(cso_hash_iter_is_null(iter)) { + FREE(item); + return PIPE_ERROR_OUT_OF_MEMORY; + } + + return PIPE_OK; +} + + +void * +util_hash_table_get(struct util_hash_table *ht, + void *key) +{ + unsigned key_hash; + struct util_hash_table_item *item; + + assert(ht); + if (!ht) + return NULL; + + key_hash = ht->hash(key); + + item = util_hash_table_find_item(ht, key, key_hash); + if(!item) + return NULL; + + return item->value; +} + + +void +util_hash_table_remove(struct util_hash_table *ht, + void *key) +{ + unsigned key_hash; + struct cso_hash_iter iter; + struct util_hash_table_item *item; + + assert(ht); + if (!ht) + return; + + key_hash = ht->hash(key); + + iter = util_hash_table_find_iter(ht, key, key_hash); + if(cso_hash_iter_is_null(iter)) + return; + + item = util_hash_table_item(iter); + assert(item); + FREE(item); + + cso_hash_erase(ht->cso, iter); +} + + +void +util_hash_table_clear(struct util_hash_table *ht) +{ + struct cso_hash_iter iter; + struct util_hash_table_item *item; + + assert(ht); + if (!ht) + return; + + iter = cso_hash_first_node(ht->cso); + while (!cso_hash_iter_is_null(iter)) { + item = (struct util_hash_table_item *)cso_hash_take(ht->cso, cso_hash_iter_key(iter)); + FREE(item); + iter = cso_hash_first_node(ht->cso); + } +} + + +enum pipe_error +util_hash_table_foreach(struct util_hash_table *ht, + enum pipe_error (*callback) + (void *key, void *value, void *data), + void *data) +{ + struct cso_hash_iter iter; + struct util_hash_table_item *item; + enum pipe_error result; + + assert(ht); + if (!ht) + return PIPE_ERROR_BAD_INPUT; + + iter = cso_hash_first_node(ht->cso); + while (!cso_hash_iter_is_null(iter)) { + item = (struct util_hash_table_item *)cso_hash_iter_data(iter); + result = callback(item->key, item->value, data); + if(result != PIPE_OK) + return result; + iter = cso_hash_iter_next(iter); + } + + return PIPE_OK; +} + + +void +util_hash_table_destroy(struct util_hash_table *ht) +{ + struct cso_hash_iter iter; + struct util_hash_table_item *item; + + assert(ht); + if (!ht) + return; + + iter = cso_hash_first_node(ht->cso); + while (!cso_hash_iter_is_null(iter)) { + item = (struct util_hash_table_item *)cso_hash_iter_data(iter); + FREE(item); + iter = cso_hash_iter_next(iter); + } + + cso_hash_delete(ht->cso); + + FREE(ht); +} diff --git a/src/gallium/auxiliary/util/u_hash_table.h b/src/gallium/auxiliary/util/u_hash_table.h new file mode 100644 index 0000000..51ec10a --- /dev/null +++ b/src/gallium/auxiliary/util/u_hash_table.h @@ -0,0 +1,96 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * General purpose hash table. + * + * @author José Fonseca + */ + +#ifndef U_HASH_TABLE_H_ +#define U_HASH_TABLE_H_ + + +#include "pipe/p_defines.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Generic purpose hash table. + */ +struct util_hash_table; + + +/** + * Create an hash table. + * + * @param hash hash function + * @param compare should return 0 for two equal keys. + */ +struct util_hash_table * +util_hash_table_create(unsigned (*hash)(void *key), + int (*compare)(void *key1, void *key2)); + + +enum pipe_error +util_hash_table_set(struct util_hash_table *ht, + void *key, + void *value); + +void * +util_hash_table_get(struct util_hash_table *ht, + void *key); + + +void +util_hash_table_remove(struct util_hash_table *ht, + void *key); + + +void +util_hash_table_clear(struct util_hash_table *ht); + + +enum pipe_error +util_hash_table_foreach(struct util_hash_table *ht, + enum pipe_error (*callback) + (void *key, void *value, void *data), + void *data); + +void +util_hash_table_destroy(struct util_hash_table *ht); + + +#ifdef __cplusplus +} +#endif + +#endif /* U_HASH_TABLE_H_ */ diff --git a/src/gallium/auxiliary/util/u_index_modify.c b/src/gallium/auxiliary/util/u_index_modify.c new file mode 100644 index 0000000..65b079e --- /dev/null +++ b/src/gallium/auxiliary/util/u_index_modify.c @@ -0,0 +1,127 @@ +/* + * Copyright 2010 Marek Olšák + * + * 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 "pipe/p_context.h" +#include "util/u_index_modify.h" +#include "util/u_inlines.h" + +void util_shorten_ubyte_elts(struct pipe_context *context, + struct pipe_resource **elts, + int index_bias, + unsigned start, + unsigned count) +{ + struct pipe_screen* screen = context->screen; + struct pipe_resource* new_elts; + unsigned char *in_map; + unsigned short *out_map; + struct pipe_transfer *src_transfer, *dst_transfer; + unsigned i; + + new_elts = pipe_buffer_create(screen, + PIPE_BIND_INDEX_BUFFER, + 2 * count); + + in_map = pipe_buffer_map(context, *elts, PIPE_TRANSFER_READ, &src_transfer); + out_map = pipe_buffer_map(context, new_elts, PIPE_TRANSFER_WRITE, &dst_transfer); + + in_map += start; + + for (i = 0; i < count; i++) { + *out_map = (unsigned short)(*in_map + index_bias); + in_map++; + out_map++; + } + + pipe_buffer_unmap(context, *elts, src_transfer); + pipe_buffer_unmap(context, new_elts, dst_transfer); + + *elts = new_elts; +} + +void util_rebuild_ushort_elts(struct pipe_context *context, + struct pipe_resource **elts, + int index_bias, + unsigned start, unsigned count) +{ + struct pipe_transfer *in_transfer = NULL; + struct pipe_transfer *out_transfer = NULL; + struct pipe_resource *new_elts; + unsigned short *in_map; + unsigned short *out_map; + unsigned i; + + new_elts = pipe_buffer_create(context->screen, + PIPE_BIND_INDEX_BUFFER, + 2 * count); + + in_map = pipe_buffer_map(context, *elts, + PIPE_TRANSFER_READ, &in_transfer); + out_map = pipe_buffer_map(context, new_elts, + PIPE_TRANSFER_WRITE, &out_transfer); + + in_map += start; + for (i = 0; i < count; i++) { + *out_map = (unsigned short)(*in_map + index_bias); + in_map++; + out_map++; + } + + pipe_buffer_unmap(context, *elts, in_transfer); + pipe_buffer_unmap(context, new_elts, out_transfer); + + *elts = new_elts; +} + +void util_rebuild_uint_elts(struct pipe_context *context, + struct pipe_resource **elts, + int index_bias, + unsigned start, unsigned count) +{ + struct pipe_transfer *in_transfer = NULL; + struct pipe_transfer *out_transfer = NULL; + struct pipe_resource *new_elts; + unsigned int *in_map; + unsigned int *out_map; + unsigned i; + + new_elts = pipe_buffer_create(context->screen, + PIPE_BIND_INDEX_BUFFER, + 2 * count); + + in_map = pipe_buffer_map(context, *elts, + PIPE_TRANSFER_READ, &in_transfer); + out_map = pipe_buffer_map(context, new_elts, + PIPE_TRANSFER_WRITE, &out_transfer); + + in_map += start; + for (i = 0; i < count; i++) { + *out_map = (unsigned int)(*in_map + index_bias); + in_map++; + out_map++; + } + + pipe_buffer_unmap(context, *elts, in_transfer); + pipe_buffer_unmap(context, new_elts, out_transfer); + + *elts = new_elts; +} diff --git a/src/gallium/auxiliary/util/u_index_modify.h b/src/gallium/auxiliary/util/u_index_modify.h new file mode 100644 index 0000000..01a6cae --- /dev/null +++ b/src/gallium/auxiliary/util/u_index_modify.h @@ -0,0 +1,41 @@ +/* + * Copyright 2010 Marek Olšák + * + * 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 UTIL_INDEX_MODIFY_H +#define UTIL_INDEX_MODIFY_H + +void util_shorten_ubyte_elts(struct pipe_context *context, + struct pipe_resource **elts, + int index_bias, + unsigned start, + unsigned count); + +void util_rebuild_ushort_elts(struct pipe_context *context, + struct pipe_resource **elts, + int index_bias, + unsigned start, unsigned count); + +void util_rebuild_uint_elts(struct pipe_context *context, + struct pipe_resource **elts, + int index_bias, + unsigned start, unsigned count); +#endif diff --git a/src/gallium/auxiliary/util/u_init.h b/src/gallium/auxiliary/util/u_init.h new file mode 100644 index 0000000..7bc356a --- /dev/null +++ b/src/gallium/auxiliary/util/u_init.h @@ -0,0 +1,52 @@ +/* + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef U_INIT_H +#define U_INIT_H + +/* Use UTIL_INIT(f) to have f called at program initialization. + Note that it is only guaranteed to be called if any symbol in the + .c file it is in sis referenced by the program. + + UTIL_INIT functions are called in arbitrary order. +*/ + +#ifdef __cplusplus +/* use a C++ global constructor */ +#define UTIL_INIT(f) struct f##__gctor_t {f##__gctor_t() {x();}} f##__gctor; +#elif defined(_MSC_VER) +/* add a pointer to the section where MSVC stores global constructor pointers */ +/* see http://blogs.msdn.com/vcblog/archive/2006/10/20/crt-initialization.aspx and + http://stackoverflow.com/questions/1113409/attribute-constructor-equivalent-in-vc */ +#pragma section(".CRT$XCU",read) +#define UTIL_INIT(f) static void __cdecl f##__init(void) {f();}; __declspec(allocate(".CRT$XCU")) void (__cdecl* f##__xcu)(void) = f##__init; +#elif defined(__GNUC__) +#define UTIL_INIT(f) static void f##__init(void) __attribute__((constructor)); static void f##__init(void) {f();} +#else +#error Unsupported compiler: please find out how to implement global initializers in C on it +#endif + +#endif + diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h new file mode 100644 index 0000000..e55aafe --- /dev/null +++ b/src/gallium/auxiliary/util/u_inlines.h @@ -0,0 +1,408 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef U_INLINES_H +#define U_INLINES_H + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" +#include "pipe/p_screen.h" +#include "util/u_debug.h" +#include "util/u_debug_describe.h" +#include "util/u_debug_refcnt.h" +#include "util/u_atomic.h" +#include "util/u_box.h" +#include "util/u_math.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* + * Reference counting helper functions. + */ + + +static INLINE void +pipe_reference_init(struct pipe_reference *reference, unsigned count) +{ + p_atomic_set(&reference->count, count); +} + +static INLINE boolean +pipe_is_referenced(struct pipe_reference *reference) +{ + return p_atomic_read(&reference->count) != 0; +} + +/** + * Update reference counting. + * The old thing pointed to, if any, will be unreferenced. + * Both 'ptr' and 'reference' may be NULL. + * \return TRUE if the object's refcount hits zero and should be destroyed. + */ +static INLINE boolean +pipe_reference_described(struct pipe_reference *ptr, + struct pipe_reference *reference, + debug_reference_descriptor get_desc) +{ + boolean destroy = FALSE; + + if(ptr != reference) { + /* bump the reference.count first */ + if (reference) { + assert(pipe_is_referenced(reference)); + p_atomic_inc(&reference->count); + debug_reference(reference, get_desc, 1); + } + + if (ptr) { + assert(pipe_is_referenced(ptr)); + if (p_atomic_dec_zero(&ptr->count)) { + destroy = TRUE; + } + debug_reference(ptr, get_desc, -1); + } + } + + return destroy; +} + +static INLINE boolean +pipe_reference(struct pipe_reference *ptr, struct pipe_reference *reference) +{ + return pipe_reference_described(ptr, reference, + (debug_reference_descriptor)debug_describe_reference); +} + +static INLINE void +pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) +{ + struct pipe_surface *old_surf = *ptr; + + if (pipe_reference_described(&(*ptr)->reference, &surf->reference, + (debug_reference_descriptor)debug_describe_surface)) + old_surf->context->surface_destroy(old_surf->context, old_surf); + *ptr = surf; +} + +static INLINE void +pipe_resource_reference(struct pipe_resource **ptr, struct pipe_resource *tex) +{ + struct pipe_resource *old_tex = *ptr; + + if (pipe_reference_described(&(*ptr)->reference, &tex->reference, + (debug_reference_descriptor)debug_describe_resource)) + old_tex->screen->resource_destroy(old_tex->screen, old_tex); + *ptr = tex; +} + +static INLINE void +pipe_sampler_view_reference(struct pipe_sampler_view **ptr, struct pipe_sampler_view *view) +{ + struct pipe_sampler_view *old_view = *ptr; + + if (pipe_reference_described(&(*ptr)->reference, &view->reference, + (debug_reference_descriptor)debug_describe_sampler_view)) + old_view->context->sampler_view_destroy(old_view->context, old_view); + *ptr = view; +} + +static INLINE void +pipe_surface_reset(struct pipe_context *ctx, struct pipe_surface* ps, + struct pipe_resource *pt, unsigned level, unsigned layer, + unsigned flags) +{ + pipe_resource_reference(&ps->texture, pt); + ps->format = pt->format; + ps->width = u_minify(pt->width0, level); + ps->height = u_minify(pt->height0, level); + ps->usage = flags; + ps->u.tex.level = level; + ps->u.tex.first_layer = ps->u.tex.last_layer = layer; + ps->context = ctx; +} + +static INLINE void +pipe_surface_init(struct pipe_context *ctx, struct pipe_surface* ps, + struct pipe_resource *pt, unsigned level, unsigned layer, + unsigned flags) +{ + ps->texture = 0; + pipe_reference_init(&ps->reference, 1); + pipe_surface_reset(ctx, ps, pt, level, layer, flags); +} + +/* + * Convenience wrappers for screen buffer functions. + */ + +static INLINE struct pipe_resource * +pipe_buffer_create( struct pipe_screen *screen, + unsigned bind, + unsigned size ) +{ + struct pipe_resource buffer; + memset(&buffer, 0, sizeof buffer); + buffer.target = PIPE_BUFFER; + buffer.format = PIPE_FORMAT_R8_UNORM; /* want TYPELESS or similar */ + buffer.bind = bind; + buffer.usage = PIPE_USAGE_DEFAULT; + buffer.flags = 0; + buffer.width0 = size; + buffer.height0 = 1; + buffer.depth0 = 1; + buffer.array_size = 1; + return screen->resource_create(screen, &buffer); +} + + +static INLINE struct pipe_resource * +pipe_user_buffer_create( struct pipe_screen *screen, void *ptr, unsigned size, + unsigned usage ) +{ + return screen->user_buffer_create(screen, ptr, size, usage); +} + +static INLINE void * +pipe_buffer_map_range(struct pipe_context *pipe, + struct pipe_resource *buffer, + unsigned offset, + unsigned length, + unsigned usage, + struct pipe_transfer **transfer) +{ + struct pipe_box box; + void *map; + + assert(offset < buffer->width0); + assert(offset + length <= buffer->width0); + assert(length); + + u_box_1d(offset, length, &box); + + *transfer = pipe->get_transfer( pipe, + buffer, + 0, + usage, + &box); + + if (*transfer == NULL) + return NULL; + + map = pipe->transfer_map( pipe, *transfer ); + if (map == NULL) { + pipe->transfer_destroy( pipe, *transfer ); + return NULL; + } + + /* Match old screen->buffer_map_range() behaviour, return pointer + * to where the beginning of the buffer would be: + */ + return (void *)((char *)map - offset); +} + + +static INLINE void * +pipe_buffer_map(struct pipe_context *pipe, + struct pipe_resource *buffer, + unsigned usage, + struct pipe_transfer **transfer) +{ + return pipe_buffer_map_range(pipe, buffer, 0, buffer->width0, usage, transfer); +} + + +static INLINE void +pipe_buffer_unmap(struct pipe_context *pipe, + struct pipe_resource *buf, + struct pipe_transfer *transfer) +{ + if (transfer) { + pipe->transfer_unmap(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); + } +} + +static INLINE void +pipe_buffer_flush_mapped_range(struct pipe_context *pipe, + struct pipe_transfer *transfer, + unsigned offset, + unsigned length) +{ + struct pipe_box box; + int transfer_offset; + + assert(length); + assert(transfer->box.x <= offset); + assert(offset + length <= transfer->box.x + transfer->box.width); + + /* Match old screen->buffer_flush_mapped_range() behaviour, where + * offset parameter is relative to the start of the buffer, not the + * mapped range. + */ + transfer_offset = offset - transfer->box.x; + + u_box_1d(transfer_offset, length, &box); + + pipe->transfer_flush_region(pipe, transfer, &box); +} + +static INLINE void +pipe_buffer_write(struct pipe_context *pipe, + struct pipe_resource *buf, + unsigned offset, + unsigned size, + const void *data) +{ + struct pipe_box box; + + u_box_1d(offset, size, &box); + + pipe->transfer_inline_write( pipe, + buf, + 0, + PIPE_TRANSFER_WRITE, + &box, + data, + size, + 0); +} + +/** + * Special case for writing non-overlapping ranges. + * + * We can avoid GPU/CPU synchronization when writing range that has never + * been written before. + */ +static INLINE void +pipe_buffer_write_nooverlap(struct pipe_context *pipe, + struct pipe_resource *buf, + unsigned offset, unsigned size, + const void *data) +{ + struct pipe_box box; + + u_box_1d(offset, size, &box); + + pipe->transfer_inline_write(pipe, + buf, + 0, + (PIPE_TRANSFER_WRITE | + PIPE_TRANSFER_NOOVERWRITE), + &box, + data, + 0, 0); +} + +static INLINE void +pipe_buffer_read(struct pipe_context *pipe, + struct pipe_resource *buf, + unsigned offset, + unsigned size, + void *data) +{ + struct pipe_transfer *src_transfer; + ubyte *map; + + map = (ubyte *) pipe_buffer_map_range(pipe, + buf, + offset, size, + PIPE_TRANSFER_READ, + &src_transfer); + + if (map) + memcpy(data, map + offset, size); + + pipe_buffer_unmap(pipe, buf, src_transfer); +} + +static INLINE struct pipe_transfer * +pipe_get_transfer( struct pipe_context *context, + struct pipe_resource *resource, + unsigned level, unsigned layer, + enum pipe_transfer_usage usage, + unsigned x, unsigned y, + unsigned w, unsigned h) +{ + struct pipe_box box; + u_box_2d_zslice( x, y, layer, w, h, &box ); + return context->get_transfer( context, + resource, + level, + usage, + &box ); +} + +static INLINE void * +pipe_transfer_map( struct pipe_context *context, + struct pipe_transfer *transfer ) +{ + return context->transfer_map( context, transfer ); +} + +static INLINE void +pipe_transfer_unmap( struct pipe_context *context, + struct pipe_transfer *transfer ) +{ + context->transfer_unmap( context, transfer ); +} + + +static INLINE void +pipe_transfer_destroy( struct pipe_context *context, + struct pipe_transfer *transfer ) +{ + context->transfer_destroy(context, transfer); +} + + +static INLINE boolean util_get_offset( + const struct pipe_rasterizer_state *templ, + unsigned fill_mode) +{ + switch(fill_mode) { + case PIPE_POLYGON_MODE_POINT: + return templ->offset_point; + case PIPE_POLYGON_MODE_LINE: + return templ->offset_line; + case PIPE_POLYGON_MODE_FILL: + return templ->offset_tri; + default: + assert(0); + return FALSE; + } +} + +#ifdef __cplusplus +} +#endif + +#endif /* U_INLINES_H */ diff --git a/src/gallium/auxiliary/util/u_keymap.c b/src/gallium/auxiliary/util/u_keymap.c new file mode 100644 index 0000000..e161ccd --- /dev/null +++ b/src/gallium/auxiliary/util/u_keymap.c @@ -0,0 +1,318 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * Key lookup/associative container. + * + * Like Jose's util_hash_table, based on CSO cache code for now. + * + * Author: Brian Paul + */ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" + +#include "cso_cache/cso_hash.h" + +#include "util/u_memory.h" +#include "util/u_keymap.h" + + +struct keymap +{ + struct cso_hash *cso; + unsigned key_size; + unsigned max_entries; /* XXX not obeyed net */ + unsigned num_entries; + keymap_delete_func delete_func; +}; + + +struct keymap_item +{ + void *key, *value; +}; + + +/** + * This the default key-delete function used when the client doesn't + * provide one. + */ +static void +default_delete_func(const struct keymap *map, + const void *key, void *data, void *user) +{ + FREE((void*) data); +} + + +static INLINE struct keymap_item * +hash_table_item(struct cso_hash_iter iter) +{ + return (struct keymap_item *) cso_hash_iter_data(iter); +} + + +/** + * Return 4-byte hash key for a block of bytes. + */ +static unsigned +hash(const void *key, unsigned keySize) +{ + unsigned i, hash; + + keySize /= 4; /* convert from bytes to uints */ + + hash = 0; + for (i = 0; i < keySize; i++) { + hash ^= (i + 1) * ((const unsigned *) key)[i]; + } + + /*hash = hash ^ (hash >> 11) ^ (hash >> 22);*/ + + return hash; +} + + +/** + * Create a new map. + * \param keySize size of the keys in bytes + * \param maxEntries max number of entries to allow (~0 = infinity) + * \param deleteFunc optional callback to call when entries + * are deleted/replaced + */ +struct keymap * +util_new_keymap(unsigned keySize, unsigned maxEntries, + keymap_delete_func deleteFunc) +{ + struct keymap *map = MALLOC_STRUCT(keymap); + if (!map) + return NULL; + + map->cso = cso_hash_create(); + if (!map->cso) { + FREE(map); + return NULL; + } + + map->max_entries = maxEntries; + map->num_entries = 0; + map->key_size = keySize; + map->delete_func = deleteFunc ? deleteFunc : default_delete_func; + + return map; +} + + +/** + * Delete/free a keymap and all entries. The deleteFunc that was given at + * create time will be called for each entry. + * \param user user-provided pointer passed through to the delete callback + */ +void +util_delete_keymap(struct keymap *map, void *user) +{ + util_keymap_remove_all(map, user); + cso_hash_delete(map->cso); + FREE(map); +} + + +static INLINE struct cso_hash_iter +hash_table_find_iter(const struct keymap *map, const void *key, + unsigned key_hash) +{ + struct cso_hash_iter iter; + struct keymap_item *item; + + iter = cso_hash_find(map->cso, key_hash); + while (!cso_hash_iter_is_null(iter)) { + item = (struct keymap_item *) cso_hash_iter_data(iter); + if (!memcmp(item->key, key, map->key_size)) + break; + iter = cso_hash_iter_next(iter); + } + + return iter; +} + + +static INLINE struct keymap_item * +hash_table_find_item(const struct keymap *map, const void *key, + unsigned key_hash) +{ + struct cso_hash_iter iter = hash_table_find_iter(map, key, key_hash); + if (cso_hash_iter_is_null(iter)) { + return NULL; + } + else { + return hash_table_item(iter); + } +} + + +/** + * Insert a new key + data pointer into the table. + * Note: we create a copy of the key, but not the data! + * If the key is already present in the table, replace the existing + * entry (calling the delete callback on the previous entry). + * If the maximum capacity of the map is reached an old entry + * will be deleted (the delete callback will be called). + */ +boolean +util_keymap_insert(struct keymap *map, const void *key, + const void *data, void *user) +{ + unsigned key_hash; + struct keymap_item *item; + struct cso_hash_iter iter; + + assert(map); + if (!map) + return FALSE; + + key_hash = hash(key, map->key_size); + + item = hash_table_find_item(map, key, key_hash); + if (item) { + /* call delete callback for old entry/item */ + map->delete_func(map, item->key, item->value, user); + item->value = (void *) data; + return TRUE; + } + + item = MALLOC_STRUCT(keymap_item); + if (!item) + return FALSE; + + item->key = mem_dup(key, map->key_size); + item->value = (void *) data; + + iter = cso_hash_insert(map->cso, key_hash, item); + if (cso_hash_iter_is_null(iter)) { + FREE(item); + return FALSE; + } + + map->num_entries++; + + return TRUE; +} + + +/** + * Look up a key in the map and return the associated data pointer. + */ +const void * +util_keymap_lookup(const struct keymap *map, const void *key) +{ + unsigned key_hash; + struct keymap_item *item; + + assert(map); + if (!map) + return NULL; + + key_hash = hash(key, map->key_size); + + item = hash_table_find_item(map, key, key_hash); + if (!item) + return NULL; + + return item->value; +} + + +/** + * Remove an entry from the map. + * The delete callback will be called if the given key/entry is found. + * \param user passed to the delete callback as the last param. + */ +void +util_keymap_remove(struct keymap *map, const void *key, void *user) +{ + unsigned key_hash; + struct cso_hash_iter iter; + struct keymap_item *item; + + assert(map); + if (!map) + return; + + key_hash = hash(key, map->key_size); + + iter = hash_table_find_iter(map, key, key_hash); + if (cso_hash_iter_is_null(iter)) + return; + + item = hash_table_item(iter); + assert(item); + if (!item) + return; + map->delete_func(map, item->key, item->value, user); + FREE(item->key); + FREE(item); + + map->num_entries--; + + cso_hash_erase(map->cso, iter); +} + + +/** + * Remove all entries from the map, calling the delete callback for each. + * \param user passed to the delete callback as the last param. + */ +void +util_keymap_remove_all(struct keymap *map, void *user) +{ + struct cso_hash_iter iter; + struct keymap_item *item; + + assert(map); + if (!map) + return; + + iter = cso_hash_first_node(map->cso); + while (!cso_hash_iter_is_null(iter)) { + item = (struct keymap_item *) + cso_hash_take(map->cso, cso_hash_iter_key(iter)); + map->delete_func(map, item->key, item->value, user); + FREE(item->key); + FREE(item); + iter = cso_hash_first_node(map->cso); + } +} + + +extern void +util_keymap_info(const struct keymap *map) +{ + debug_printf("Keymap %p: %u of max %u entries\n", + (void *) map, map->num_entries, map->max_entries); +} diff --git a/src/gallium/auxiliary/util/u_keymap.h b/src/gallium/auxiliary/util/u_keymap.h new file mode 100644 index 0000000..8d60a76 --- /dev/null +++ b/src/gallium/auxiliary/util/u_keymap.h @@ -0,0 +1,68 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef U_KEYMAP_H +#define U_KEYMAP_H + +#include "pipe/p_compiler.h" + + +/** opaque keymap type */ +struct keymap; + + +/** Delete/callback function type */ +typedef void (*keymap_delete_func)(const struct keymap *map, + const void *key, void *data, + void *user); + + +extern struct keymap * +util_new_keymap(unsigned keySize, unsigned maxEntries, + keymap_delete_func deleteFunc); + +extern void +util_delete_keymap(struct keymap *map, void *user); + +extern boolean +util_keymap_insert(struct keymap *map, const void *key, + const void *data, void *user); + +extern const void * +util_keymap_lookup(const struct keymap *map, const void *key); + +extern void +util_keymap_remove(struct keymap *map, const void *key, void *user); + +extern void +util_keymap_remove_all(struct keymap *map, void *user); + +extern void +util_keymap_info(const struct keymap *map); + + +#endif /* U_KEYMAP_H */ diff --git a/src/gallium/auxiliary/util/u_linear.c b/src/gallium/auxiliary/util/u_linear.c new file mode 100644 index 0000000..f1aef21 --- /dev/null +++ b/src/gallium/auxiliary/util/u_linear.c @@ -0,0 +1,101 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * Functions for converting tiled data to linear and vice versa. + */ + + +#include "util/u_debug.h" +#include "u_linear.h" + +void +pipe_linear_to_tile(size_t src_stride, const void *src_ptr, + struct pipe_tile_info *t, void *dst_ptr) +{ + int x, y, z; + char *ptr; + size_t bytes = t->cols * t->block.size; + char *dst_ptr2 = (char *) dst_ptr; + + assert(pipe_linear_check_tile(t)); + + /* lets write lineary to the tiled buffer */ + for (y = 0; y < t->tiles_y; y++) { + for (x = 0; x < t->tiles_x; x++) { + /* this inner loop could be replace with SSE magic */ + ptr = (char*)src_ptr + src_stride * t->rows * y + bytes * x; + for (z = 0; z < t->rows; z++) { + memcpy(dst_ptr2, ptr, bytes); + dst_ptr2 += bytes; + ptr += src_stride; + } + } + } +} + +void pipe_linear_from_tile(struct pipe_tile_info *t, const void *src_ptr, + size_t dst_stride, void *dst_ptr) +{ + int x, y, z; + char *ptr; + size_t bytes = t->cols * t->block.size; + const char *src_ptr2 = (const char *) src_ptr; + + /* lets read lineary from the tiled buffer */ + for (y = 0; y < t->tiles_y; y++) { + for (x = 0; x < t->tiles_x; x++) { + /* this inner loop could be replace with SSE magic */ + ptr = (char*)dst_ptr + dst_stride * t->rows * y + bytes * x; + for (z = 0; z < t->rows; z++) { + memcpy(ptr, src_ptr2, bytes); + src_ptr2 += bytes; + ptr += dst_stride; + } + } + } +} + +void +pipe_linear_fill_info(struct pipe_tile_info *t, + const struct u_linear_format_block *block, + unsigned tile_width, unsigned tile_height, + unsigned tiles_x, unsigned tiles_y) +{ + t->block = *block; + + t->tile.width = tile_width; + t->tile.height = tile_height; + t->cols = t->tile.width / t->block.width; + t->rows = t->tile.height / t->block.height; + t->tile.size = t->cols * t->rows * t->block.size; + + t->tiles_x = tiles_x; + t->tiles_y = tiles_y; + t->stride = t->cols * t->tiles_x * t->block.size; + t->size = t->tiles_x * t->tiles_y * t->tile.size; +} diff --git a/src/gallium/auxiliary/util/u_linear.h b/src/gallium/auxiliary/util/u_linear.h new file mode 100644 index 0000000..81ffc9f --- /dev/null +++ b/src/gallium/auxiliary/util/u_linear.h @@ -0,0 +1,106 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * Functions for converting tiled data to linear and vice versa. + */ + + +#ifndef U_LINEAR_H +#define U_LINEAR_H + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" + +struct u_linear_format_block +{ + /** Block size in bytes */ + unsigned size; + + /** Block width in pixels */ + unsigned width; + + /** Block height in pixels */ + unsigned height; +}; + + +struct pipe_tile_info +{ + unsigned size; + unsigned stride; + + /* The number of tiles */ + unsigned tiles_x; + unsigned tiles_y; + + /* size of each tile expressed in blocks */ + unsigned cols; + unsigned rows; + + /* Describe the tile in pixels */ + struct u_linear_format_block tile; + + /* Describe each block within the tile */ + struct u_linear_format_block block; +}; + +void pipe_linear_to_tile(size_t src_stride, const void *src_ptr, + struct pipe_tile_info *t, void *dst_ptr); + +void pipe_linear_from_tile(struct pipe_tile_info *t, const void *src_ptr, + size_t dst_stride, void *dst_ptr); + +/** + * Convenience function to fillout a pipe_tile_info struct. + * @t info to fill out. + * @block block info about pixel layout + * @tile_width the width of the tile in pixels + * @tile_height the height of the tile in pixels + * @tiles_x number of tiles in x axis + * @tiles_y number of tiles in y axis + */ +void pipe_linear_fill_info(struct pipe_tile_info *t, + const struct u_linear_format_block *block, + unsigned tile_width, unsigned tile_height, + unsigned tiles_x, unsigned tiles_y); + +static INLINE boolean pipe_linear_check_tile(const struct pipe_tile_info *t) +{ + if (t->tile.size != t->block.size * t->cols * t->rows) + return FALSE; + + if (t->stride != t->block.size * t->cols * t->tiles_x) + return FALSE; + + if (t->size < t->stride * t->rows * t->tiles_y) + return FALSE; + + return TRUE; +} + +#endif /* U_LINEAR_H */ diff --git a/src/gallium/auxiliary/util/u_linkage.c b/src/gallium/auxiliary/util/u_linkage.c new file mode 100644 index 0000000..2f6f41b --- /dev/null +++ b/src/gallium/auxiliary/util/u_linkage.c @@ -0,0 +1,149 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_debug.h" +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_scan.h" +#include "util/u_linkage.h" + +/* we must only record the registers that are actually used, not just declared */ +static INLINE boolean +util_semantic_set_test_and_set(struct util_semantic_set *set, unsigned value) +{ + unsigned mask = 1 << (value % (sizeof(long) * 8)); + unsigned long *p = &set->masks[value / (sizeof(long) * 8)]; + unsigned long v = *p & mask; + *p |= mask; + return !!v; +} + +unsigned +util_semantic_set_from_program_file(struct util_semantic_set *set, const struct tgsi_token *tokens, enum tgsi_file_type file) +{ + struct tgsi_shader_info info; + struct tgsi_parse_context parse; + unsigned count = 0; + ubyte *semantic_name; + ubyte *semantic_index; + + tgsi_scan_shader(tokens, &info); + + if(file == TGSI_FILE_INPUT) + { + semantic_name = info.input_semantic_name; + semantic_index = info.input_semantic_index; + } + else if(file == TGSI_FILE_OUTPUT) + { + semantic_name = info.output_semantic_name; + semantic_index = info.output_semantic_index; + } + else + { + assert(0); + semantic_name = NULL; + semantic_index = NULL; + } + + tgsi_parse_init(&parse, tokens); + + memset(set->masks, 0, sizeof(set->masks)); + while(!tgsi_parse_end_of_tokens(&parse)) + { + tgsi_parse_token(&parse); + + if(parse.FullToken.Token.Type == TGSI_TOKEN_TYPE_INSTRUCTION) + { + const struct tgsi_full_instruction *finst = &parse.FullToken.FullInstruction; + unsigned i; + for(i = 0; i < finst->Instruction.NumDstRegs; ++i) + { + if(finst->Dst[i].Register.File == file) + { + unsigned idx = finst->Dst[i].Register.Index; + if(semantic_name[idx] == TGSI_SEMANTIC_GENERIC) + { + if(!util_semantic_set_test_and_set(set, semantic_index[idx])) + ++count; + } + } + } + + for(i = 0; i < finst->Instruction.NumSrcRegs; ++i) + { + if(finst->Src[i].Register.File == file) + { + unsigned idx = finst->Src[i].Register.Index; + if(semantic_name[idx] == TGSI_SEMANTIC_GENERIC) + { + if(!util_semantic_set_test_and_set(set, semantic_index[idx])) + ++count; + } + } + } + } + } + tgsi_parse_free(&parse); + + return count; +} + +#define UTIL_SEMANTIC_SET_FOR_EACH(i, set) for(i = 0; i < 256; ++i) if(set->masks[i / (sizeof(long) * 8)] & (1 << (i % (sizeof(long) * 8)))) + +void +util_semantic_layout_from_set(unsigned char *layout, const struct util_semantic_set *set, unsigned efficient_slots, unsigned num_slots) +{ + int first = -1; + int last = -1; + unsigned i; + + memset(layout, 0xff, num_slots); + + UTIL_SEMANTIC_SET_FOR_EACH(i, set) + { + if(first < 0) + first = i; + last = i; + } + + if(last < efficient_slots) + { + UTIL_SEMANTIC_SET_FOR_EACH(i, set) + layout[i] = i; + } + else if((last - first) < efficient_slots) + { + UTIL_SEMANTIC_SET_FOR_EACH(i, set) + layout[i - first] = i; + } + else + { + unsigned idx = 0; + UTIL_SEMANTIC_SET_FOR_EACH(i, set) + layout[idx++] = i; + } +} diff --git a/src/gallium/auxiliary/util/u_linkage.h b/src/gallium/auxiliary/util/u_linkage.h new file mode 100644 index 0000000..4720e0e --- /dev/null +++ b/src/gallium/auxiliary/util/u_linkage.h @@ -0,0 +1,66 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef U_LINKAGE_H_ +#define U_LINKAGE_H_ + +#include "pipe/p_compiler.h" +#include "pipe/p_shader_tokens.h" + +struct util_semantic_set +{ + unsigned long masks[256 / 8 / sizeof(unsigned long)]; +}; + +static INLINE bool +util_semantic_set_contains(struct util_semantic_set *set, unsigned char value) +{ + return !!(set->masks[value / (sizeof(long) * 8)] & (1 << (value / (sizeof(long) * 8)))); +} + +unsigned util_semantic_set_from_program_file(struct util_semantic_set *set, const struct tgsi_token *tokens, enum tgsi_file_type file); + +/* efficient_slots is the number of slots such that hardware performance is + * the same for using that amount, with holes, or less slots but with less + * holes. + * + * num_slots is the size of the layout array and hardware limit instead. + * + * efficient_slots == 0 or efficient_solts == num_slots are typical settings. + */ +void util_semantic_layout_from_set(unsigned char *layout, const struct util_semantic_set *set, unsigned efficient_slots, unsigned num_slots); + +static INLINE void +util_semantic_table_from_layout(unsigned char *table, unsigned char *layout, unsigned char first_slot_value, unsigned char num_slots) +{ + int i; + memset(table, 0xff, sizeof(table)); + + for(i = 0; i < num_slots; ++i) + table[layout[i]] = first_slot_value + i; +} + +#endif /* U_LINKAGE_H_ */ diff --git a/src/gallium/auxiliary/util/u_math.c b/src/gallium/auxiliary/util/u_math.c new file mode 100644 index 0000000..2811475 --- /dev/null +++ b/src/gallium/auxiliary/util/u_math.c @@ -0,0 +1,73 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + + +#include "util/u_math.h" + + +/** 2^x, for x in [-1.0, 1.0) */ +float pow2_table[POW2_TABLE_SIZE]; + + +static void +init_pow2_table(void) +{ + int i; + for (i = 0; i < POW2_TABLE_SIZE; i++) + pow2_table[i] = (float) pow(2.0, (i - POW2_TABLE_OFFSET) / POW2_TABLE_SCALE); +} + + +/** log2(x), for x in [1.0, 2.0) */ +float log2_table[LOG2_TABLE_SIZE]; + + +static void +init_log2_table(void) +{ + unsigned i; + for (i = 0; i < LOG2_TABLE_SIZE; i++) + log2_table[i] = (float) log2(1.0 + i * (1.0 / LOG2_TABLE_SCALE)); +} + + +/** + * One time init for math utilities. + */ +void +util_init_math(void) +{ + static boolean initialized = FALSE; + if (!initialized) { + init_pow2_table(); + init_log2_table(); + initialized = TRUE; + } +} + + diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h new file mode 100644 index 0000000..37294b7 --- /dev/null +++ b/src/gallium/auxiliary/util/u_math.h @@ -0,0 +1,637 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * Math utilities and approximations for common math functions. + * Reduced precision is usually acceptable in shaders... + * + * "fast" is used in the names of functions which are low-precision, + * or at least lower-precision than the normal C lib functions. + */ + + +#ifndef U_MATH_H +#define U_MATH_H + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +#if defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) +__inline double ceil(double val) +{ + double ceil_val; + + if ((val - (long) val) == 0) { + ceil_val = val; + } + else { + if (val > 0) { + ceil_val = (long) val + 1; + } + else { + ceil_val = (long) val; + } + } + + return ceil_val; +} + +#ifndef PIPE_SUBSYSTEM_WINDOWS_CE_OGL +__inline double floor(double val) +{ + double floor_val; + + if ((val - (long) val) == 0) { + floor_val = val; + } + else { + if (val > 0) { + floor_val = (long) val; + } + else { + floor_val = (long) val - 1; + } + } + + return floor_val; +} +#endif + +#pragma function(pow) +__inline double __cdecl pow(double val, double exponent) +{ + /* XXX */ + assert(0); + return 0; +} + +#pragma function(log) +__inline double __cdecl log(double val) +{ + /* XXX */ + assert(0); + return 0; +} + +#pragma function(atan2) +__inline double __cdecl atan2(double val) +{ + /* XXX */ + assert(0); + return 0; +} +#else +#include +#include +#endif + + +#ifndef M_SQRT2 +#define M_SQRT2 1.41421356237309504880 +#endif + + +#if defined(_MSC_VER) + +#if _MSC_VER < 1400 && !defined(__cplusplus) || defined(PIPE_SUBSYSTEM_WINDOWS_CE) + +static INLINE float cosf( float f ) +{ + return (float) cos( (double) f ); +} + +static INLINE float sinf( float f ) +{ + return (float) sin( (double) f ); +} + +static INLINE float ceilf( float f ) +{ + return (float) ceil( (double) f ); +} + +static INLINE float floorf( float f ) +{ + return (float) floor( (double) f ); +} + +static INLINE float powf( float f, float g ) +{ + return (float) pow( (double) f, (double) g ); +} + +static INLINE float sqrtf( float f ) +{ + return (float) sqrt( (double) f ); +} + +static INLINE float fabsf( float f ) +{ + return (float) fabs( (double) f ); +} + +static INLINE float logf( float f ) +{ + return (float) log( (double) f ); +} + +#else +/* Work-around an extra semi-colon in VS 2005 logf definition */ +#ifdef logf +#undef logf +#define logf(x) ((float)log((double)(x))) +#endif /* logf */ + +#define isfinite(x) _finite((double)(x)) +#define isnan(x) _isnan((double)(x)) +#endif + +static INLINE double log2( double x ) +{ + const double invln2 = 1.442695041; + return log( x ) * invln2; +} + +#endif /* _MSC_VER */ + + + + + +#define POW2_TABLE_SIZE_LOG2 9 +#define POW2_TABLE_SIZE (1 << POW2_TABLE_SIZE_LOG2) +#define POW2_TABLE_OFFSET (POW2_TABLE_SIZE/2) +#define POW2_TABLE_SCALE ((float)(POW2_TABLE_SIZE/2)) +extern float pow2_table[POW2_TABLE_SIZE]; + + +/** + * Initialize math module. This should be called before using any + * other functions in this module. + */ +extern void +util_init_math(void); + + +union fi { + float f; + int32_t i; + uint32_t ui; +}; + + +/** + * Fast version of 2^x + * Identity: exp2(a + b) = exp2(a) * exp2(b) + * Let ipart = int(x) + * Let fpart = x - ipart; + * So, exp2(x) = exp2(ipart) * exp2(fpart) + * Compute exp2(ipart) with i << ipart + * Compute exp2(fpart) with lookup table. + */ +static INLINE float +util_fast_exp2(float x) +{ + int32_t ipart; + float fpart, mpart; + union fi epart; + + if(x > 129.00000f) + return 3.402823466e+38f; + + if (x < -126.99999f) + return 0.0f; + + ipart = (int32_t) x; + fpart = x - (float) ipart; + + /* same as + * epart.f = (float) (1 << ipart) + * but faster and without integer overflow for ipart > 31 + */ + epart.i = (ipart + 127 ) << 23; + + mpart = pow2_table[POW2_TABLE_OFFSET + (int)(fpart * POW2_TABLE_SCALE)]; + + return epart.f * mpart; +} + + +/** + * Fast approximation to exp(x). + */ +static INLINE float +util_fast_exp(float x) +{ + const float k = 1.44269f; /* = log2(e) */ + return util_fast_exp2(k * x); +} + + +#define LOG2_TABLE_SIZE_LOG2 16 +#define LOG2_TABLE_SCALE (1 << LOG2_TABLE_SIZE_LOG2) +#define LOG2_TABLE_SIZE (LOG2_TABLE_SCALE + 1) +extern float log2_table[LOG2_TABLE_SIZE]; + + +/** + * Fast approximation to log2(x). + */ +static INLINE float +util_fast_log2(float x) +{ + union fi num; + float epart, mpart; + num.f = x; + epart = (float)(((num.i & 0x7f800000) >> 23) - 127); + /* mpart = log2_table[mantissa*LOG2_TABLE_SCALE + 0.5] */ + mpart = log2_table[((num.i & 0x007fffff) + (1 << (22 - LOG2_TABLE_SIZE_LOG2))) >> (23 - LOG2_TABLE_SIZE_LOG2)]; + return epart + mpart; +} + + +/** + * Fast approximation to x^y. + */ +static INLINE float +util_fast_pow(float x, float y) +{ + return util_fast_exp2(util_fast_log2(x) * y); +} + +/* Note that this counts zero as a power of two. + */ +static INLINE boolean +util_is_power_of_two( unsigned v ) +{ + return (v & (v-1)) == 0; +} + + +/** + * Floor(x), returned as int. + */ +static INLINE int +util_ifloor(float f) +{ + int ai, bi; + double af, bf; + union fi u; + af = (3 << 22) + 0.5 + (double) f; + bf = (3 << 22) + 0.5 - (double) f; + u.f = (float) af; ai = u.i; + u.f = (float) bf; bi = u.i; + return (ai - bi) >> 1; +} + + +/** + * Round float to nearest int. + */ +static INLINE int +util_iround(float f) +{ +#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86) + int r; + __asm__ ("fistpl %0" : "=m" (r) : "t" (f) : "st"); + return r; +#elif defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86) + int r; + _asm { + fld f + fistp r + } + return r; +#else + if (f >= 0.0f) + return (int) (f + 0.5f); + else + return (int) (f - 0.5f); +#endif +} + + +/** + * Approximate floating point comparison + */ +static INLINE boolean +util_is_approx(float a, float b, float tol) +{ + return fabs(b - a) <= tol; +} + + +/** + * Test if x is NaN or +/- infinity. + */ +static INLINE boolean +util_is_inf_or_nan(float x) +{ + union fi tmp; + tmp.f = x; + return !(int)((unsigned int)((tmp.i & 0x7fffffff)-0x7f800000) >> 31); +} + + +/** + * Find first bit set in word. Least significant bit is 1. + * Return 0 if no bits set. + */ +#if defined(_MSC_VER) && _MSC_VER >= 1300 && (_M_IX86 || _M_AMD64 || _M_IA64) +unsigned char _BitScanForward(unsigned long* Index, unsigned long Mask); +#pragma intrinsic(_BitScanForward) +static INLINE +unsigned long ffs( unsigned long u ) +{ + unsigned long i; + if (_BitScanForward(&i, u)) + return i + 1; + else + return 0; +} +#elif defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86) +static INLINE +unsigned ffs( unsigned u ) +{ + unsigned i; + + if (u == 0) { + return 0; + } + + __asm bsf eax, [u] + __asm inc eax + __asm mov [i], eax + + return i; +} +#elif defined(__MINGW32__) +#define ffs __builtin_ffs +#endif + +#ifdef __MINGW32__ +#define ffs __builtin_ffs +#endif + + +/* Could also binary search for the highest bit. + */ +static INLINE unsigned +util_unsigned_logbase2(unsigned n) +{ + unsigned log2 = 0; + while (n >>= 1) + ++log2; + return log2; +} + + +/** + * Return float bits. + */ +static INLINE unsigned +fui( float f ) +{ + union fi fi; + fi.f = f; + return fi.ui; +} + + +/** + * Convert ubyte to float in [0, 1]. + * XXX a 256-entry lookup table would be slightly faster. + */ +static INLINE float +ubyte_to_float(ubyte ub) +{ + return (float) ub * (1.0f / 255.0f); +} + + +/** + * Convert float in [0,1] to ubyte in [0,255] with clamping. + */ +static INLINE ubyte +float_to_ubyte(float f) +{ + const int ieee_0996 = 0x3f7f0000; /* 0.996 or so */ + union fi tmp; + + tmp.f = f; + if (tmp.i < 0) { + return (ubyte) 0; + } + else if (tmp.i >= ieee_0996) { + return (ubyte) 255; + } + else { + tmp.f = tmp.f * (255.0f/256.0f) + 32768.0f; + return (ubyte) tmp.i; + } +} + + +/** + * Calc log base 2 + */ +static INLINE unsigned +util_logbase2(unsigned n) +{ + unsigned log2 = 0; + while (n >>= 1) + ++log2; + return log2; +} + + +/** + * Returns the smallest power of two >= x + */ +static INLINE unsigned +util_next_power_of_two(unsigned x) +{ + unsigned i; + + if (x == 0) + return 1; + + --x; + + for (i = 1; i < sizeof(unsigned) * 8; i <<= 1) + x |= x >> i; + + return x + 1; +} + + +/** + * Return number of bits set in n. + */ +static INLINE unsigned +util_bitcount(unsigned n) +{ +#if defined(PIPE_CC_GCC) + return __builtin_popcount(n); +#else + /* K&R classic bitcount. + * + * For each iteration, clear the LSB from the bitfield. + * Requires only one iteration per set bit, instead of + * one iteration per bit less than highest set bit. + */ + unsigned bits = 0; + for (bits; n; bits++) { + n &= n - 1; + } + return bits; +#endif +} + + +/** + * Reverse byte order of a 32 bit word. + */ +static INLINE uint32_t +util_bswap32(uint32_t n) +{ +#if defined(PIPE_CC_GCC) && (PIPE_CC_GCC_VERSION >= 403) + return __builtin_bswap32(n); +#else + return (n >> 24) | + ((n >> 8) & 0x0000ff00) | + ((n << 8) & 0x00ff0000) | + (n << 24); +#endif +} + + +/** + * Reverse byte order of a 16 bit word. + */ +static INLINE uint16_t +util_bswap16(uint16_t n) +{ + return (n >> 8) | + (n << 8); +} + + +/** + * Clamp X to [MIN, MAX]. + * This is a macro to allow float, int, uint, etc. types. + */ +#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) ) + +#define MIN2( A, B ) ( (A)<(B) ? (A) : (B) ) +#define MAX2( A, B ) ( (A)>(B) ? (A) : (B) ) + +#define MIN3( A, B, C ) MIN2( MIN2( A, B ), C ) +#define MAX3( A, B, C ) MAX2( MAX2( A, B ), C ) + +#define MIN4( A, B, C, D ) MIN2( MIN2( A, B ), MIN2(C, D) ) +#define MAX4( A, B, C, D ) MAX2( MAX2( A, B ), MAX2(C, D) ) + + +/** + * Align a value, only works pot alignemnts. + */ +static INLINE int +align(int value, int alignment) +{ + return (value + alignment - 1) & ~(alignment - 1); +} + +/** + * Works like align but on npot alignments. + */ +static INLINE size_t +util_align_npot(size_t value, size_t alignment) +{ + if (value % alignment) + return value + (alignment - (value % alignment)); + return value; +} + +static INLINE unsigned +u_minify(unsigned value, unsigned levels) +{ + return MAX2(1, value >> levels); +} + +#ifndef COPY_4V +#define COPY_4V( DST, SRC ) \ +do { \ + (DST)[0] = (SRC)[0]; \ + (DST)[1] = (SRC)[1]; \ + (DST)[2] = (SRC)[2]; \ + (DST)[3] = (SRC)[3]; \ +} while (0) +#endif + + +#ifndef COPY_4FV +#define COPY_4FV( DST, SRC ) COPY_4V(DST, SRC) +#endif + + +#ifndef ASSIGN_4V +#define ASSIGN_4V( DST, V0, V1, V2, V3 ) \ +do { \ + (DST)[0] = (V0); \ + (DST)[1] = (V1); \ + (DST)[2] = (V2); \ + (DST)[3] = (V3); \ +} while (0) +#endif + + +static INLINE uint32_t util_unsigned_fixed(float value, unsigned frac_bits) +{ + return value < 0 ? 0 : (uint32_t)(value * (1<MEMBER)) + + + +#ifdef __cplusplus +} +#endif + + +#endif /* U_MEMORY_H */ diff --git a/src/gallium/auxiliary/util/u_mm.c b/src/gallium/auxiliary/util/u_mm.c new file mode 100644 index 0000000..82f8370 --- /dev/null +++ b/src/gallium/auxiliary/util/u_mm.c @@ -0,0 +1,296 @@ +/************************************************************************** + * + * Copyright (C) 1999 Wittawat Yamwong + * + * 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 + * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS 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_debug.h" + +#include "util/u_memory.h" +#include "util/u_mm.h" + + +void +u_mmDumpMemInfo(const struct mem_block *heap) +{ + debug_printf("Memory heap %p:\n", (void *) heap); + if (heap == 0) { + debug_printf(" heap == 0\n"); + } + else { + const struct mem_block *p; + int total_used = 0, total_free = 0; + + for (p = heap->next; p != heap; p = p->next) { + debug_printf(" Offset:%08x, Size:%08x, %c%c\n", p->ofs, p->size, + p->free ? 'F':'.', + p->reserved ? 'R':'.'); + if (p->free) + total_free += p->size; + else + total_used += p->size; + } + + debug_printf("'\nMemory stats: total = %d, used = %d, free = %d\n", + total_used + total_free, total_used, total_free); + debug_printf("\nFree list:\n"); + + for (p = heap->next_free; p != heap; p = p->next_free) { + debug_printf(" FREE Offset:%08x, Size:%08x, %c%c\n", p->ofs, p->size, + p->free ? 'F':'.', + p->reserved ? 'R':'.'); + } + + } + debug_printf("End of memory blocks\n"); +} + + +struct mem_block * +u_mmInit(int ofs, int size) +{ + struct mem_block *heap, *block; + + if (size <= 0) + return NULL; + + heap = CALLOC_STRUCT(mem_block); + if (!heap) + return NULL; + + block = CALLOC_STRUCT(mem_block); + if (!block) { + FREE(heap); + return NULL; + } + + heap->next = block; + heap->prev = block; + heap->next_free = block; + heap->prev_free = block; + + block->heap = heap; + block->next = heap; + block->prev = heap; + block->next_free = heap; + block->prev_free = heap; + + block->ofs = ofs; + block->size = size; + block->free = 1; + + return heap; +} + + +static struct mem_block * +SliceBlock(struct mem_block *p, + int startofs, int size, + int reserved, int alignment) +{ + struct mem_block *newblock; + + /* break left [p, newblock, p->next], then p = newblock */ + if (startofs > p->ofs) { + newblock = CALLOC_STRUCT(mem_block); + if (!newblock) + return NULL; + newblock->ofs = startofs; + newblock->size = p->size - (startofs - p->ofs); + newblock->free = 1; + newblock->heap = p->heap; + + newblock->next = p->next; + newblock->prev = p; + p->next->prev = newblock; + p->next = newblock; + + newblock->next_free = p->next_free; + newblock->prev_free = p; + p->next_free->prev_free = newblock; + p->next_free = newblock; + + p->size -= newblock->size; + p = newblock; + } + + /* break right, also [p, newblock, p->next] */ + if (size < p->size) { + newblock = CALLOC_STRUCT(mem_block); + if (!newblock) + return NULL; + newblock->ofs = startofs + size; + newblock->size = p->size - size; + newblock->free = 1; + newblock->heap = p->heap; + + newblock->next = p->next; + newblock->prev = p; + p->next->prev = newblock; + p->next = newblock; + + newblock->next_free = p->next_free; + newblock->prev_free = p; + p->next_free->prev_free = newblock; + p->next_free = newblock; + + p->size = size; + } + + /* p = middle block */ + p->free = 0; + + /* Remove p from the free list: + */ + p->next_free->prev_free = p->prev_free; + p->prev_free->next_free = p->next_free; + + p->next_free = 0; + p->prev_free = 0; + + p->reserved = reserved; + return p; +} + + +struct mem_block * +u_mmAllocMem(struct mem_block *heap, int size, int align2, int startSearch) +{ + struct mem_block *p; + const int mask = (1 << align2)-1; + int startofs = 0; + int endofs; + + assert(size >= 0); + assert(align2 >= 0); + assert(align2 <= 12); /* sanity check, 2^12 (4KB) enough? */ + + if (!heap || align2 < 0 || size <= 0) + return NULL; + + for (p = heap->next_free; p != heap; p = p->next_free) { + assert(p->free); + + startofs = (p->ofs + mask) & ~mask; + if ( startofs < startSearch ) { + startofs = startSearch; + } + endofs = startofs+size; + if (endofs <= (p->ofs+p->size)) + break; + } + + if (p == heap) + return NULL; + + assert(p->free); + p = SliceBlock(p,startofs,size,0,mask+1); + + return p; +} + + +struct mem_block * +u_mmFindBlock(struct mem_block *heap, int start) +{ + struct mem_block *p; + + for (p = heap->next; p != heap; p = p->next) { + if (p->ofs == start) + return p; + } + + return NULL; +} + + +static INLINE int +Join2Blocks(struct mem_block *p) +{ + /* XXX there should be some assertions here */ + + /* NOTE: heap->free == 0 */ + + if (p->free && p->next->free) { + struct mem_block *q = p->next; + + assert(p->ofs + p->size == q->ofs); + p->size += q->size; + + p->next = q->next; + q->next->prev = p; + + q->next_free->prev_free = q->prev_free; + q->prev_free->next_free = q->next_free; + + FREE(q); + return 1; + } + return 0; +} + +int +u_mmFreeMem(struct mem_block *b) +{ + if (!b) + return 0; + + if (b->free) { + debug_printf("block already free\n"); + return -1; + } + if (b->reserved) { + debug_printf("block is reserved\n"); + return -1; + } + + b->free = 1; + b->next_free = b->heap->next_free; + b->prev_free = b->heap; + b->next_free->prev_free = b; + b->prev_free->next_free = b; + + Join2Blocks(b); + if (b->prev != b->heap) + Join2Blocks(b->prev); + + return 0; +} + + +void +u_mmDestroy(struct mem_block *heap) +{ + struct mem_block *p; + + if (!heap) + return; + + for (p = heap->next; p != heap; ) { + struct mem_block *next = p->next; + FREE(p); + p = next; + } + + FREE(heap); +} diff --git a/src/gallium/auxiliary/util/u_mm.h b/src/gallium/auxiliary/util/u_mm.h new file mode 100644 index 0000000..6b158aa --- /dev/null +++ b/src/gallium/auxiliary/util/u_mm.h @@ -0,0 +1,91 @@ +/************************************************************************** + * + * Copyright (C) 1999 Wittawat Yamwong + * + * 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 + * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS 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 + * Memory manager code. Primarily used by device drivers to manage texture + * heaps, etc. + */ + + +#ifndef _U_MM_H_ +#define _U_MM_H_ + + +struct mem_block { + struct mem_block *next, *prev; + struct mem_block *next_free, *prev_free; + struct mem_block *heap; + int ofs,size; + unsigned int free:1; + unsigned int reserved:1; +}; + + + +/** + * input: total size in bytes + * return: a heap pointer if OK, NULL if error + */ +extern struct mem_block *u_mmInit(int ofs, int size); + +/** + * Allocate 'size' bytes with 2^align2 bytes alignment, + * restrict the search to free memory after 'startSearch' + * depth and back buffers should be in different 4mb banks + * to get better page hits if possible + * input: size = size of block + * align2 = 2^align2 bytes alignment + * startSearch = linear offset from start of heap to begin search + * return: pointer to the allocated block, 0 if error + */ +extern struct mem_block *u_mmAllocMem(struct mem_block *heap, int size, int align2, + int startSearch); + +/** + * Free block starts at offset + * input: pointer to a block + * return: 0 if OK, -1 if error + */ +extern int u_mmFreeMem(struct mem_block *b); + +/** + * Free block starts at offset + * input: pointer to a heap, start offset + * return: pointer to a block + */ +extern struct mem_block *u_mmFindBlock(struct mem_block *heap, int start); + +/** + * destroy MM + */ +extern void u_mmDestroy(struct mem_block *mmInit); + +/** + * For debugging purposes. + */ +extern void u_mmDumpMemInfo(const struct mem_block *mmInit); + +#endif diff --git a/src/gallium/auxiliary/util/u_network.c b/src/gallium/auxiliary/util/u_network.c new file mode 100644 index 0000000..77f2c5f --- /dev/null +++ b/src/gallium/auxiliary/util/u_network.c @@ -0,0 +1,188 @@ + +#include "pipe/p_compiler.h" +#include "util/u_network.h" +#include "util/u_debug.h" + +#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) +# include +# include +#elif defined(PIPE_OS_LINUX) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_CYGWIN) +# include +# include +# include +# include +# include +#else +# warning "No socket implementation" +#endif + +boolean +u_socket_init() +{ +#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) + WORD wVersionRequested; + WSADATA wsaData; + int err; + + /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ + wVersionRequested = MAKEWORD(1, 1); + + err = WSAStartup(wVersionRequested, &wsaData); + if (err != 0) { + debug_printf("WSAStartup failed with error: %d\n", err); + return FALSE; + } + return TRUE; +#elif defined(PIPE_HAVE_SOCKETS) + return TRUE; +#else + return FALSE; +#endif +} + +void +u_socket_stop() +{ +#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) + WSACleanup(); +#endif +} + +void +u_socket_close(int s) +{ + if (s < 0) + return; + +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_APPLE) + shutdown(s, SHUT_RDWR); + close(s); +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) + shutdown(s, SD_BOTH); + closesocket(s); +#else + assert(0); +#endif +} + +int u_socket_accept(int s) +{ +#if defined(PIPE_HAVE_SOCKETS) + return accept(s, NULL, NULL); +#else + return -1; +#endif +} + +int +u_socket_send(int s, void *data, size_t size) +{ +#if defined(PIPE_HAVE_SOCKETS) + return send(s, data, size, 0); +#else + return -1; +#endif +} + +int +u_socket_peek(int s, void *data, size_t size) +{ +#if defined(PIPE_HAVE_SOCKETS) + return recv(s, data, size, MSG_PEEK); +#else + return -1; +#endif +} + +int +u_socket_recv(int s, void *data, size_t size) +{ +#if defined(PIPE_HAVE_SOCKETS) + return recv(s, data, size, 0); +#else + return -1; +#endif +} + +int +u_socket_connect(const char *hostname, uint16_t port) +{ +#if defined(PIPE_HAVE_SOCKETS) + int s; + struct sockaddr_in sa; + struct hostent *host = NULL; + + memset(&sa, 0, sizeof(struct sockaddr_in)); + host = gethostbyname(hostname); + if (!host) + return -1; + + memcpy((char *)&sa.sin_addr,host->h_addr_list[0],host->h_length); + sa.sin_family= host->h_addrtype; + sa.sin_port = htons(port); + + s = socket(host->h_addrtype, SOCK_STREAM, IPPROTO_TCP); + if (s < 0) + return -1; + + if (connect(s, (struct sockaddr *)&sa, sizeof(sa))) { + u_socket_close(s); + return -1; + } + + return s; +#else + assert(0); + return -1; +#endif +} + +int +u_socket_listen_on_port(uint16_t portnum) +{ +#if defined(PIPE_HAVE_SOCKETS) + int s; + struct sockaddr_in sa; + memset(&sa, 0, sizeof(struct sockaddr_in)); + + sa.sin_family = AF_INET; + sa.sin_port = htons(portnum); + + s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (s < 0) + return -1; + + if (bind(s, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) == -1) { + u_socket_close(s); + return -1; + } + + listen(s, 0); + + return s; +#else + assert(0); + return -1; +#endif +} + +void +u_socket_block(int s, boolean block) +{ +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_APPLE) + int old = fcntl(s, F_GETFL, 0); + if (old == -1) + return; + + /* TODO obey block */ + if (block) + fcntl(s, F_SETFL, old & ~O_NONBLOCK); + else + fcntl(s, F_SETFL, old | O_NONBLOCK); +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) + u_long iMode = block ? 0 : 1; + ioctlsocket(s, FIONBIO, &iMode); +#else + assert(0); +#endif +} diff --git a/src/gallium/auxiliary/util/u_network.h b/src/gallium/auxiliary/util/u_network.h new file mode 100644 index 0000000..187dcab --- /dev/null +++ b/src/gallium/auxiliary/util/u_network.h @@ -0,0 +1,24 @@ + +#ifndef _U_NETWORK_H_ +#define _U_NETWORK_H_ + +#include "pipe/p_compiler.h" + +#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) +# define PIPE_HAVE_SOCKETS +#elif defined(PIPE_OS_LINUX) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_APPLE) +# define PIPE_HAVE_SOCKETS +#endif + +boolean u_socket_init(void); +void u_socket_stop(void); +void u_socket_close(int s); +int u_socket_listen_on_port(uint16_t portnum); +int u_socket_accept(int s); +int u_socket_connect(const char *host, uint16_t port); +int u_socket_send(int s, void *data, size_t size); +int u_socket_peek(int s, void *data, size_t size); +int u_socket_recv(int s, void *data, size_t size); +void u_socket_block(int s, boolean block); + +#endif diff --git a/src/gallium/auxiliary/util/u_pack_color.h b/src/gallium/auxiliary/util/u_pack_color.h new file mode 100644 index 0000000..5378f2d --- /dev/null +++ b/src/gallium/auxiliary/util/u_pack_color.h @@ -0,0 +1,584 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Functions to produce packed colors/Z from floats. + */ + + +#ifndef U_PACK_COLOR_H +#define U_PACK_COLOR_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_debug.h" +#include "util/u_format.h" +#include "util/u_math.h" + + +/** + * Helper union for packing pixel values. + * Will often contain values in formats which are too complex to be described + * in simple terms, hence might just effectively contain a number of bytes. + * Must be big enough to hold data for all formats (currently 256 bits). + */ +union util_color { + ubyte ub; + ushort us; + uint ui; + float f[4]; + double d[4]; +}; + +/** + * Pack ubyte R,G,B,A into dest pixel. + */ +static INLINE void +util_pack_color_ub(ubyte r, ubyte g, ubyte b, ubyte a, + enum pipe_format format, union util_color *uc) +{ + switch (format) { + case PIPE_FORMAT_A8B8G8R8_UNORM: + { + uc->ui = (r << 24) | (g << 16) | (b << 8) | a; + } + return; + case PIPE_FORMAT_X8B8G8R8_UNORM: + { + uc->ui = (r << 24) | (g << 16) | (b << 8) | 0xff; + } + return; + case PIPE_FORMAT_B8G8R8A8_UNORM: + { + uc->ui = (a << 24) | (r << 16) | (g << 8) | b; + } + return; + case PIPE_FORMAT_B8G8R8X8_UNORM: + { + uc->ui = (0xff << 24) | (r << 16) | (g << 8) | b; + } + return; + case PIPE_FORMAT_A8R8G8B8_UNORM: + { + uc->ui = (b << 24) | (g << 16) | (r << 8) | a; + } + return; + case PIPE_FORMAT_X8R8G8B8_UNORM: + { + uc->ui = (b << 24) | (g << 16) | (r << 8) | 0xff; + } + return; + case PIPE_FORMAT_B5G6R5_UNORM: + { + uc->us = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); + } + return; + case PIPE_FORMAT_B5G5R5X1_UNORM: + { + uc->us = ((0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3); + } + return; + case PIPE_FORMAT_B5G5R5A1_UNORM: + { + uc->us = ((a & 0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3); + } + return; + case PIPE_FORMAT_B4G4R4A4_UNORM: + { + uc->us = ((a & 0xf0) << 8) | ((r & 0xf0) << 4) | ((g & 0xf0) << 0) | (b >> 4); + } + return; + case PIPE_FORMAT_A8_UNORM: + { + uc->ub = a; + } + return; + case PIPE_FORMAT_L8_UNORM: + case PIPE_FORMAT_I8_UNORM: + { + uc->ub = a; + } + return; + case PIPE_FORMAT_R32G32B32A32_FLOAT: + { + uc->f[0] = (float)r / 255.0f; + uc->f[1] = (float)g / 255.0f; + uc->f[2] = (float)b / 255.0f; + uc->f[3] = (float)a / 255.0f; + } + return; + case PIPE_FORMAT_R32G32B32_FLOAT: + { + uc->f[0] = (float)r / 255.0f; + uc->f[1] = (float)g / 255.0f; + uc->f[2] = (float)b / 255.0f; + } + return; + + /* Handle other cases with a generic function. + */ + default: + { + ubyte src[4]; + + src[0] = r; + src[1] = g; + src[2] = b; + src[3] = a; + util_format_write_4ub(format, src, 0, uc, 0, 0, 0, 1, 1); + } + } +} + + +/** + * Unpack RGBA from a packed pixel, returning values as ubytes in [0,255]. + */ +static INLINE void +util_unpack_color_ub(enum pipe_format format, union util_color *uc, + ubyte *r, ubyte *g, ubyte *b, ubyte *a) +{ + switch (format) { + case PIPE_FORMAT_A8B8G8R8_UNORM: + { + uint p = uc->ui; + *r = (ubyte) ((p >> 24) & 0xff); + *g = (ubyte) ((p >> 16) & 0xff); + *b = (ubyte) ((p >> 8) & 0xff); + *a = (ubyte) ((p >> 0) & 0xff); + } + return; + case PIPE_FORMAT_X8B8G8R8_UNORM: + { + uint p = uc->ui; + *r = (ubyte) ((p >> 24) & 0xff); + *g = (ubyte) ((p >> 16) & 0xff); + *b = (ubyte) ((p >> 8) & 0xff); + *a = (ubyte) 0xff; + } + return; + case PIPE_FORMAT_B8G8R8A8_UNORM: + { + uint p = uc->ui; + *r = (ubyte) ((p >> 16) & 0xff); + *g = (ubyte) ((p >> 8) & 0xff); + *b = (ubyte) ((p >> 0) & 0xff); + *a = (ubyte) ((p >> 24) & 0xff); + } + return; + case PIPE_FORMAT_B8G8R8X8_UNORM: + { + uint p = uc->ui; + *r = (ubyte) ((p >> 16) & 0xff); + *g = (ubyte) ((p >> 8) & 0xff); + *b = (ubyte) ((p >> 0) & 0xff); + *a = (ubyte) 0xff; + } + return; + case PIPE_FORMAT_A8R8G8B8_UNORM: + { + uint p = uc->ui; + *r = (ubyte) ((p >> 8) & 0xff); + *g = (ubyte) ((p >> 16) & 0xff); + *b = (ubyte) ((p >> 24) & 0xff); + *a = (ubyte) ((p >> 0) & 0xff); + } + return; + case PIPE_FORMAT_X8R8G8B8_UNORM: + { + uint p = uc->ui; + *r = (ubyte) ((p >> 8) & 0xff); + *g = (ubyte) ((p >> 16) & 0xff); + *b = (ubyte) ((p >> 24) & 0xff); + *a = (ubyte) 0xff; + } + return; + case PIPE_FORMAT_B5G6R5_UNORM: + { + ushort p = uc->us; + *r = (ubyte) (((p >> 8) & 0xf8) | ((p >> 13) & 0x7)); + *g = (ubyte) (((p >> 3) & 0xfc) | ((p >> 9) & 0x3)); + *b = (ubyte) (((p << 3) & 0xf8) | ((p >> 2) & 0x7)); + *a = (ubyte) 0xff; + } + return; + case PIPE_FORMAT_B5G5R5X1_UNORM: + { + ushort p = uc->us; + *r = (ubyte) (((p >> 7) & 0xf8) | ((p >> 12) & 0x7)); + *g = (ubyte) (((p >> 2) & 0xf8) | ((p >> 7) & 0x7)); + *b = (ubyte) (((p << 3) & 0xf8) | ((p >> 2) & 0x7)); + *a = (ubyte) 0xff; + } + return; + case PIPE_FORMAT_B5G5R5A1_UNORM: + { + ushort p = uc->us; + *r = (ubyte) (((p >> 7) & 0xf8) | ((p >> 12) & 0x7)); + *g = (ubyte) (((p >> 2) & 0xf8) | ((p >> 7) & 0x7)); + *b = (ubyte) (((p << 3) & 0xf8) | ((p >> 2) & 0x7)); + *a = (ubyte) (0xff * (p >> 15)); + } + return; + case PIPE_FORMAT_B4G4R4A4_UNORM: + { + ushort p = uc->us; + *r = (ubyte) (((p >> 4) & 0xf0) | ((p >> 8) & 0xf)); + *g = (ubyte) (((p >> 0) & 0xf0) | ((p >> 4) & 0xf)); + *b = (ubyte) (((p << 4) & 0xf0) | ((p >> 0) & 0xf)); + *a = (ubyte) (((p >> 8) & 0xf0) | ((p >> 12) & 0xf)); + } + return; + case PIPE_FORMAT_A8_UNORM: + { + ubyte p = uc->ub; + *r = *g = *b = (ubyte) 0xff; + *a = p; + } + return; + case PIPE_FORMAT_L8_UNORM: + { + ubyte p = uc->ub; + *r = *g = *b = p; + *a = (ubyte) 0xff; + } + return; + case PIPE_FORMAT_I8_UNORM: + { + ubyte p = uc->ub; + *r = *g = *b = *a = p; + } + return; + case PIPE_FORMAT_R32G32B32A32_FLOAT: + { + const float *p = &uc->f[0]; + *r = float_to_ubyte(p[0]); + *g = float_to_ubyte(p[1]); + *b = float_to_ubyte(p[2]); + *a = float_to_ubyte(p[3]); + } + return; + case PIPE_FORMAT_R32G32B32_FLOAT: + { + const float *p = &uc->f[0]; + *r = float_to_ubyte(p[0]); + *g = float_to_ubyte(p[1]); + *b = float_to_ubyte(p[2]); + *a = (ubyte) 0xff; + } + return; + + case PIPE_FORMAT_R32G32_FLOAT: + { + const float *p = &uc->f[0]; + *r = float_to_ubyte(p[0]); + *g = float_to_ubyte(p[1]); + *b = *a = (ubyte) 0xff; + } + return; + + case PIPE_FORMAT_R32_FLOAT: + { + const float *p = &uc->f[0]; + *r = float_to_ubyte(p[0]); + *g = *b = *a = (ubyte) 0xff; + } + return; + + /* Handle other cases with a generic function. + */ + default: + { + ubyte dst[4]; + + util_format_read_4ub(format, dst, 0, uc, 0, 0, 0, 1, 1); + *r = dst[0]; + *g = dst[1]; + *b = dst[2]; + *a = dst[3]; + } + } +} + + +/** + * Note rgba outside [0,1] will be clamped for int pixel formats. + */ +static INLINE void +util_pack_color(const float rgba[4], enum pipe_format format, union util_color *uc) +{ + ubyte r = 0; + ubyte g = 0; + ubyte b = 0; + ubyte a = 0; + + if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0) <= 8) { + /* format uses 8-bit components or less */ + r = float_to_ubyte(rgba[0]); + g = float_to_ubyte(rgba[1]); + b = float_to_ubyte(rgba[2]); + a = float_to_ubyte(rgba[3]); + } + + switch (format) { + case PIPE_FORMAT_A8B8G8R8_UNORM: + { + uc->ui = (r << 24) | (g << 16) | (b << 8) | a; + } + return; + case PIPE_FORMAT_X8B8G8R8_UNORM: + { + uc->ui = (r << 24) | (g << 16) | (b << 8) | 0xff; + } + return; + case PIPE_FORMAT_B8G8R8A8_UNORM: + { + uc->ui = (a << 24) | (r << 16) | (g << 8) | b; + } + return; + case PIPE_FORMAT_B8G8R8X8_UNORM: + { + uc->ui = (0xff << 24) | (r << 16) | (g << 8) | b; + } + return; + case PIPE_FORMAT_A8R8G8B8_UNORM: + { + uc->ui = (b << 24) | (g << 16) | (r << 8) | a; + } + return; + case PIPE_FORMAT_X8R8G8B8_UNORM: + { + uc->ui = (b << 24) | (g << 16) | (r << 8) | 0xff; + } + return; + case PIPE_FORMAT_B5G6R5_UNORM: + { + uc->us = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); + } + return; + case PIPE_FORMAT_B5G5R5X1_UNORM: + { + uc->us = ((0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3); + } + return; + case PIPE_FORMAT_B5G5R5A1_UNORM: + { + uc->us = ((a & 0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3); + } + return; + case PIPE_FORMAT_B4G4R4A4_UNORM: + { + uc->us = ((a & 0xf0) << 8) | ((r & 0xf0) << 4) | ((g & 0xf0) << 0) | (b >> 4); + } + return; + case PIPE_FORMAT_A8_UNORM: + { + uc->ub = a; + } + return; + case PIPE_FORMAT_L8_UNORM: + case PIPE_FORMAT_I8_UNORM: + { + uc->ub = r; + } + return; + case PIPE_FORMAT_R32G32B32A32_FLOAT: + { + uc->f[0] = rgba[0]; + uc->f[1] = rgba[1]; + uc->f[2] = rgba[2]; + uc->f[3] = rgba[3]; + } + return; + case PIPE_FORMAT_R32G32B32_FLOAT: + { + uc->f[0] = rgba[0]; + uc->f[1] = rgba[1]; + uc->f[2] = rgba[2]; + } + return; + + /* Handle other cases with a generic function. + */ + default: + util_format_write_4f(format, rgba, 0, uc, 0, 0, 0, 1, 1); + } +} + +/* Integer versions of util_pack_z and util_pack_z_stencil - useful for + * constructing clear masks. + */ +static INLINE uint32_t +util_pack_mask_z(enum pipe_format format, uint32_t z) +{ + switch (format) { + case PIPE_FORMAT_Z16_UNORM: + return z & 0xffff; + case PIPE_FORMAT_Z32_UNORM: + case PIPE_FORMAT_Z32_FLOAT: + return z; + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + case PIPE_FORMAT_Z24X8_UNORM: + return z & 0xffffff; + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: + return (z & 0xffffff) << 8; + case PIPE_FORMAT_S8_USCALED: + return 0; + default: + debug_print_format("gallium: unhandled format in util_pack_mask_z()", format); + assert(0); + return 0; + } +} + +static INLINE uint32_t +util_pack_mask_z_stencil(enum pipe_format format, uint32_t z, uint8_t s) +{ + uint32_t packed = util_pack_mask_z(format, z); + + switch (format) { + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + packed |= (uint32_t)s << 24; + break; + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + packed |= s; + break; + case PIPE_FORMAT_S8_USCALED: + packed |= s; + break; + default: + break; + } + + return packed; +} + + + +/** + * Note: it's assumed that z is in [0,1] + */ +static INLINE uint32_t +util_pack_z(enum pipe_format format, double z) +{ + union fi fui; + + if (z == 0.0) + return 0; + + switch (format) { + case PIPE_FORMAT_Z16_UNORM: + if (z == 1.0) + return 0xffff; + return (uint32_t) (z * 0xffff); + case PIPE_FORMAT_Z32_UNORM: + /* special-case to avoid overflow */ + if (z == 1.0) + return 0xffffffff; + return (uint32_t) (z * 0xffffffff); + case PIPE_FORMAT_Z32_FLOAT: + fui.f = (float)z; + return fui.ui; + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + case PIPE_FORMAT_Z24X8_UNORM: + if (z == 1.0) + return 0xffffff; + return (uint32_t) (z * 0xffffff); + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: + if (z == 1.0) + return 0xffffff00; + return ((uint32_t) (z * 0xffffff)) << 8; + case PIPE_FORMAT_S8_USCALED: + /* this case can get it via util_pack_z_stencil() */ + return 0; + default: + debug_print_format("gallium: unhandled format in util_pack_z()", format); + assert(0); + return 0; + } +} + + +/** + * Pack Z and/or stencil values into a 32-bit value described by format. + * Note: it's assumed that z is in [0,1] and s in [0,255] + */ +static INLINE uint32_t +util_pack_z_stencil(enum pipe_format format, double z, uint8_t s) +{ + uint32_t packed = util_pack_z(format, z); + + switch (format) { + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + packed |= (uint32_t)s << 24; + break; + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + packed |= s; + break; + case PIPE_FORMAT_S8_USCALED: + packed |= s; + break; + default: + break; + } + + return packed; +} + + +/** + * Pack 4 ubytes into a 4-byte word + */ +static INLINE unsigned +pack_ub4(ubyte b0, ubyte b1, ubyte b2, ubyte b3) +{ + return ((((unsigned int)b0) << 0) | + (((unsigned int)b1) << 8) | + (((unsigned int)b2) << 16) | + (((unsigned int)b3) << 24)); +} + + +/** + * Pack/convert 4 floats into one 4-byte word. + */ +static INLINE unsigned +pack_ui32_float4(float a, float b, float c, float d) +{ + return pack_ub4( float_to_ubyte(a), + float_to_ubyte(b), + float_to_ubyte(c), + float_to_ubyte(d) ); +} + + + +#endif /* U_PACK_COLOR_H */ diff --git a/src/gallium/auxiliary/util/u_pointer.h b/src/gallium/auxiliary/util/u_pointer.h new file mode 100644 index 0000000..cce0c74 --- /dev/null +++ b/src/gallium/auxiliary/util/u_pointer.h @@ -0,0 +1,130 @@ +/************************************************************************** + * + * Copyright 2007-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. + * + **************************************************************************/ + +#ifndef U_POINTER_H +#define U_POINTER_H + +#include "pipe/p_compiler.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static INLINE intptr_t +pointer_to_intptr( const void *p ) +{ + union { + const void *p; + intptr_t i; + } pi; + pi.p = p; + return pi.i; +} + +static INLINE void * +intptr_to_pointer( intptr_t i ) +{ + union { + void *p; + intptr_t i; + } pi; + pi.i = i; + return pi.p; +} + +static INLINE uintptr_t +pointer_to_uintptr( const void *ptr ) +{ + union { + const void *p; + uintptr_t u; + } pu; + pu.p = ptr; + return pu.u; +} + +static INLINE void * +uintptr_to_pointer( uintptr_t u ) +{ + union { + void *p; + uintptr_t u; + } pu; + pu.u = u; + return pu.p; +} + +/** + * Return a pointer aligned to next multiple of N bytes. + */ +static INLINE void * +align_pointer( const void *unaligned, uintptr_t alignment ) +{ + uintptr_t aligned = (pointer_to_uintptr( unaligned ) + alignment - 1) & ~(alignment - 1); + return uintptr_to_pointer( aligned ); +} + + +/** + * Return a pointer aligned to next multiple of 16 bytes. + */ +static INLINE void * +align16( void *unaligned ) +{ + return align_pointer( unaligned, 16 ); +} + +typedef void (*func_pointer)(void); + +static INLINE func_pointer +pointer_to_func( void *p ) +{ + union { + void *p; + func_pointer f; + } pf; + pf.p = p; + return pf.f; +} + +static INLINE void * +func_to_pointer( func_pointer f ) +{ + union { + void *p; + func_pointer f; + } pf; + pf.f = f; + return pf.p; +} + + +#ifdef __cplusplus +} +#endif + +#endif /* U_POINTER_H */ diff --git a/src/gallium/auxiliary/util/u_prim.h b/src/gallium/auxiliary/util/u_prim.h new file mode 100644 index 0000000..3c851f7 --- /dev/null +++ b/src/gallium/auxiliary/util/u_prim.h @@ -0,0 +1,234 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef U_BLIT_H +#define U_BLIT_H + + +#include "pipe/p_defines.h" +#include "util/u_debug.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static INLINE boolean u_validate_pipe_prim( unsigned pipe_prim, unsigned nr ) +{ + boolean ok = TRUE; + + switch (pipe_prim) { + case PIPE_PRIM_POINTS: + ok = (nr >= 1); + break; + case PIPE_PRIM_LINES: + ok = (nr >= 2); + break; + case PIPE_PRIM_LINE_STRIP: + case PIPE_PRIM_LINE_LOOP: + ok = (nr >= 2); + break; + case PIPE_PRIM_TRIANGLES: + ok = (nr >= 3); + break; + case PIPE_PRIM_TRIANGLE_STRIP: + case PIPE_PRIM_TRIANGLE_FAN: + case PIPE_PRIM_POLYGON: + ok = (nr >= 3); + break; + case PIPE_PRIM_QUADS: + ok = (nr >= 4); + break; + case PIPE_PRIM_QUAD_STRIP: + ok = (nr >= 4); + break; + default: + ok = 0; + break; + } + + return ok; +} + + +static INLINE boolean u_trim_pipe_prim( unsigned pipe_prim, unsigned *nr ) +{ + boolean ok = TRUE; + + switch (pipe_prim) { + case PIPE_PRIM_POINTS: + ok = (*nr >= 1); + break; + case PIPE_PRIM_LINES: + ok = (*nr >= 2); + *nr -= (*nr % 2); + break; + case PIPE_PRIM_LINE_STRIP: + case PIPE_PRIM_LINE_LOOP: + ok = (*nr >= 2); + break; + case PIPE_PRIM_TRIANGLES: + ok = (*nr >= 3); + *nr -= (*nr % 3); + break; + case PIPE_PRIM_TRIANGLE_STRIP: + case PIPE_PRIM_TRIANGLE_FAN: + case PIPE_PRIM_POLYGON: + ok = (*nr >= 3); + break; + case PIPE_PRIM_QUADS: + ok = (*nr >= 4); + *nr -= (*nr % 4); + break; + case PIPE_PRIM_QUAD_STRIP: + ok = (*nr >= 4); + *nr -= (*nr % 2); + break; + case PIPE_PRIM_LINES_ADJACENCY: + ok = (*nr >= 4); + *nr -= (*nr % 4); + break; + case PIPE_PRIM_LINE_STRIP_ADJACENCY: + ok = (*nr >= 4); + break; + case PIPE_PRIM_TRIANGLES_ADJACENCY: + ok = (*nr >= 6); + *nr -= (*nr % 5); + break; + case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY: + ok = (*nr >= 4); + break; + default: + ok = 0; + break; + } + + if (!ok) + *nr = 0; + + return ok; +} + + +static INLINE unsigned u_reduced_prim( unsigned pipe_prim ) +{ + switch (pipe_prim) { + case PIPE_PRIM_POINTS: + return PIPE_PRIM_POINTS; + + case PIPE_PRIM_LINES: + case PIPE_PRIM_LINE_STRIP: + case PIPE_PRIM_LINE_LOOP: + return PIPE_PRIM_LINES; + + default: + return PIPE_PRIM_TRIANGLES; + } +} + +static INLINE unsigned +u_vertices_per_prim(int primitive) +{ + switch(primitive) { + case PIPE_PRIM_POINTS: + return 1; + case PIPE_PRIM_LINES: + case PIPE_PRIM_LINE_LOOP: + case PIPE_PRIM_LINE_STRIP: + return 2; + case PIPE_PRIM_TRIANGLES: + case PIPE_PRIM_TRIANGLE_STRIP: + case PIPE_PRIM_TRIANGLE_FAN: + return 3; + case PIPE_PRIM_LINES_ADJACENCY: + case PIPE_PRIM_LINE_STRIP_ADJACENCY: + return 4; + case PIPE_PRIM_TRIANGLES_ADJACENCY: + case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY: + return 6; + + /* following primitives should never be used + * with geometry shaders abd their size is + * undefined */ + case PIPE_PRIM_POLYGON: + case PIPE_PRIM_QUADS: + case PIPE_PRIM_QUAD_STRIP: + default: + debug_printf("Unrecognized geometry shader primitive"); + return 3; + } +} + +/** + * Returns the number of decomposed primitives for the given + * vertex count. + * Geometry shader is invoked once for each triangle in + * triangle strip, triangle fans and triangles and once + * for each line in line strip, line loop, lines. + */ +static INLINE unsigned +u_gs_prims_for_vertices(int primitive, int vertices) +{ + switch(primitive) { + case PIPE_PRIM_POINTS: + return vertices; + case PIPE_PRIM_LINES: + return vertices / 2; + case PIPE_PRIM_LINE_LOOP: + return vertices; + case PIPE_PRIM_LINE_STRIP: + return vertices - 1; + case PIPE_PRIM_TRIANGLES: + return vertices / 3; + case PIPE_PRIM_TRIANGLE_STRIP: + return vertices - 2; + case PIPE_PRIM_TRIANGLE_FAN: + return vertices - 2; + case PIPE_PRIM_LINES_ADJACENCY: + return vertices / 2; + case PIPE_PRIM_LINE_STRIP_ADJACENCY: + return vertices - 1; + case PIPE_PRIM_TRIANGLES_ADJACENCY: + return vertices / 3; + case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY: + return vertices - 2; + + /* following primitives should never be used + * with geometry shaders abd their size is + * undefined */ + case PIPE_PRIM_POLYGON: + case PIPE_PRIM_QUADS: + case PIPE_PRIM_QUAD_STRIP: + default: + debug_printf("Unrecognized geometry shader primitive"); + return 3; + } +} + +const char *u_prim_name( unsigned pipe_prim ); + +#endif diff --git a/src/gallium/auxiliary/util/u_rect.c b/src/gallium/auxiliary/util/u_rect.c new file mode 100644 index 0000000..56fcfac --- /dev/null +++ b/src/gallium/auxiliary/util/u_rect.c @@ -0,0 +1,164 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * Rectangle-related helper functions. + */ + + +#include "util/u_format.h" +#include "util/u_rect.h" +#include "util/u_pack_color.h" + + +/** + * Copy 2D rect from one place to another. + * Position and sizes are in pixels. + * src_stride may be negative to do vertical flip of pixels from source. + */ +void +util_copy_rect(ubyte * dst, + enum pipe_format format, + unsigned dst_stride, + unsigned dst_x, + unsigned dst_y, + unsigned width, + unsigned height, + const ubyte * src, + int src_stride, + unsigned src_x, + unsigned src_y) +{ + unsigned i; + int src_stride_pos = src_stride < 0 ? -src_stride : src_stride; + int blocksize = util_format_get_blocksize(format); + int blockwidth = util_format_get_blockwidth(format); + int blockheight = util_format_get_blockheight(format); + + assert(blocksize > 0); + assert(blockwidth > 0); + assert(blockheight > 0); + + dst_x /= blockwidth; + dst_y /= blockheight; + width = (width + blockwidth - 1)/blockwidth; + height = (height + blockheight - 1)/blockheight; + src_x /= blockwidth; + src_y /= blockheight; + + dst += dst_x * blocksize; + src += src_x * blocksize; + dst += dst_y * dst_stride; + src += src_y * src_stride_pos; + width *= blocksize; + + if (width == dst_stride && width == src_stride) + memcpy(dst, src, height * width); + else { + for (i = 0; i < height; i++) { + memcpy(dst, src, width); + dst += dst_stride; + src += src_stride; + } + } +} + +void +util_fill_rect(ubyte * dst, + enum pipe_format format, + unsigned dst_stride, + unsigned dst_x, + unsigned dst_y, + unsigned width, + unsigned height, + union util_color *uc) +{ + unsigned i, j; + unsigned width_size; + int blocksize = util_format_get_blocksize(format); + int blockwidth = util_format_get_blockwidth(format); + int blockheight = util_format_get_blockheight(format); + + assert(blocksize > 0); + assert(blockwidth > 0); + assert(blockheight > 0); + + dst_x /= blockwidth; + dst_y /= blockheight; + width = (width + blockwidth - 1)/blockwidth; + height = (height + blockheight - 1)/blockheight; + + dst += dst_x * blocksize; + dst += dst_y * dst_stride; + width_size = width * blocksize; + + switch (blocksize) { + case 1: + if(dst_stride == width_size) + memset(dst, uc->ub, height * width_size); + else { + for (i = 0; i < height; i++) { + memset(dst, uc->ub, width_size); + dst += dst_stride; + } + } + break; + case 2: + for (i = 0; i < height; i++) { + uint16_t *row = (uint16_t *)dst; + for (j = 0; j < width; j++) + *row++ = uc->us; + dst += dst_stride; + } + break; + case 4: + for (i = 0; i < height; i++) { + uint32_t *row = (uint32_t *)dst; + for (j = 0; j < width; j++) + *row++ = uc->ui; + dst += dst_stride; + } + break; + case 8: + case 12: + case 16: + case 24: + case 32: + for (i = 0; i < height; i++) { + ubyte *row = dst; + for (j = 0; j < width; j++) { + memcpy(row, uc, blocksize); + row += blocksize; + } + dst += dst_stride; + } + break; + default: + assert(0); + break; + } +} diff --git a/src/gallium/auxiliary/util/u_rect.h b/src/gallium/auxiliary/util/u_rect.h new file mode 100644 index 0000000..4cb90d3 --- /dev/null +++ b/src/gallium/auxiliary/util/u_rect.h @@ -0,0 +1,103 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef U_RECT_H +#define U_RECT_H + +#include "pipe/p_compiler.h" + +struct u_rect { + int x0, x1; + int y0, y1; +}; + +/* Do two rectangles intersect? + */ +static INLINE boolean +u_rect_test_intersection(const struct u_rect *a, + const struct u_rect *b) +{ + return (!(a->x1 < b->x0 || + b->x1 < a->x0 || + a->y1 < b->y0 || + b->y1 < a->y0)); +} + +/* Find the intersection of two rectangles known to intersect. + */ +static INLINE void +u_rect_find_intersection(const struct u_rect *a, + struct u_rect *b) +{ + /* Caller should verify intersection exists before calling. + */ + if (b->x0 < a->x0) b->x0 = a->x0; + if (b->x1 > a->x1) b->x1 = a->x1; + if (b->y0 < a->y0) b->y0 = a->y0; + if (b->y1 > a->y1) b->y1 = a->y1; +} + + +static INLINE void +u_rect_possible_intersection(const struct u_rect *a, + struct u_rect *b) +{ + if (u_rect_test_intersection(a,b)) { + u_rect_find_intersection(a,b); + } + else { + b->x0 = b->x1 = b->y0 = b->y1 = 0; + } +} + +#include "pipe/p_format.h" +#include "util/u_pack_color.h" + + + +/********************************************************************** + * Pipe copy/fill rect helpers. + */ + +/* These really should move to a different file: + */ +#include "pipe/p_format.h" + +extern void +util_copy_rect(ubyte * dst, enum pipe_format format, + unsigned dst_stride, unsigned dst_x, unsigned dst_y, + unsigned width, unsigned height, const ubyte * src, + int src_stride, unsigned src_x, unsigned src_y); + +extern void +util_fill_rect(ubyte * dst, enum pipe_format format, + unsigned dst_stride, unsigned dst_x, unsigned dst_y, + unsigned width, unsigned height, union util_color *uc); + + +#endif /* U_RECT_H */ diff --git a/src/gallium/auxiliary/util/u_resource.c b/src/gallium/auxiliary/util/u_resource.c new file mode 100644 index 0000000..443c9f8 --- /dev/null +++ b/src/gallium/auxiliary/util/u_resource.c @@ -0,0 +1,96 @@ + + +#include "util/u_inlines.h" +#include "util/u_transfer.h" + +static INLINE struct u_resource * +u_resource( struct pipe_resource *res ) +{ + return (struct u_resource *)res; +} + +boolean u_resource_get_handle_vtbl(struct pipe_screen *screen, + struct pipe_resource *resource, + struct winsys_handle *handle) +{ + struct u_resource *ur = u_resource(resource); + return ur->vtbl->resource_get_handle(screen, resource, handle); +} + +void u_resource_destroy_vtbl(struct pipe_screen *screen, + struct pipe_resource *resource) +{ + struct u_resource *ur = u_resource(resource); + ur->vtbl->resource_destroy(screen, resource); +} + +unsigned u_is_resource_referenced_vtbl( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, int layer) +{ + struct u_resource *ur = u_resource(resource); + return ur->vtbl->is_resource_referenced(pipe, resource, level, layer); +} + +struct pipe_transfer *u_get_transfer_vtbl(struct pipe_context *context, + struct pipe_resource *resource, + unsigned level, + enum pipe_transfer_usage usage, + const struct pipe_box *box) +{ + struct u_resource *ur = u_resource(resource); + return ur->vtbl->get_transfer(context, resource, level, usage, box); +} + +void u_transfer_destroy_vtbl(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct u_resource *ur = u_resource(transfer->resource); + ur->vtbl->transfer_destroy(pipe, transfer); +} + +void *u_transfer_map_vtbl( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct u_resource *ur = u_resource(transfer->resource); + return ur->vtbl->transfer_map(pipe, transfer); +} + +void u_transfer_flush_region_vtbl( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box) +{ + struct u_resource *ur = u_resource(transfer->resource); + ur->vtbl->transfer_flush_region(pipe, transfer, box); +} + +void u_transfer_unmap_vtbl( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct u_resource *ur = u_resource(transfer->resource); + ur->vtbl->transfer_unmap(pipe, transfer); +} + +void u_transfer_inline_write_vtbl( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride) +{ + struct u_resource *ur = u_resource(resource); + ur->vtbl->transfer_inline_write(pipe, + resource, + level, + usage, + box, + data, + stride, + layer_stride); +} + + + + diff --git a/src/gallium/auxiliary/util/u_ringbuffer.c b/src/gallium/auxiliary/util/u_ringbuffer.c new file mode 100644 index 0000000..648b105 --- /dev/null +++ b/src/gallium/auxiliary/util/u_ringbuffer.c @@ -0,0 +1,160 @@ + +#include "os/os_thread.h" +#include "pipe/p_defines.h" +#include "util/u_ringbuffer.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +/* Generic ringbuffer: + */ +struct util_ringbuffer +{ + struct util_packet *buf; + unsigned mask; + + /* Can this be done with atomic variables?? + */ + unsigned head; + unsigned tail; + pipe_condvar change; + pipe_mutex mutex; +}; + + +struct util_ringbuffer *util_ringbuffer_create( unsigned dwords ) +{ + struct util_ringbuffer *ring = CALLOC_STRUCT(util_ringbuffer); + if (ring == NULL) + return NULL; + + assert(util_is_power_of_two(dwords)); + + ring->buf = MALLOC( dwords * sizeof(unsigned) ); + if (ring->buf == NULL) + goto fail; + + ring->mask = dwords - 1; + + pipe_condvar_init(ring->change); + pipe_mutex_init(ring->mutex); + return ring; + +fail: + FREE(ring->buf); + FREE(ring); + return NULL; +} + +void util_ringbuffer_destroy( struct util_ringbuffer *ring ) +{ + pipe_condvar_destroy(ring->change); + pipe_mutex_destroy(ring->mutex); + FREE(ring->buf); + FREE(ring); +} + +/** + * Return number of free entries in the ring + */ +static INLINE unsigned util_ringbuffer_space( const struct util_ringbuffer *ring ) +{ + return (ring->tail - (ring->head + 1)) & ring->mask; +} + +/** + * Is the ring buffer empty? + */ +static INLINE boolean util_ringbuffer_empty( const struct util_ringbuffer *ring ) +{ + return util_ringbuffer_space(ring) == ring->mask; +} + +void util_ringbuffer_enqueue( struct util_ringbuffer *ring, + const struct util_packet *packet ) +{ + unsigned i; + + /* XXX: over-reliance on mutexes, etc: + */ + pipe_mutex_lock(ring->mutex); + + /* make sure we don't request an impossible amount of space + */ + assert(packet->dwords <= ring->mask); + + /* Wait for free space: + */ + while (util_ringbuffer_space(ring) < packet->dwords) + pipe_condvar_wait(ring->change, ring->mutex); + + /* Copy data to ring: + */ + for (i = 0; i < packet->dwords; i++) { + + /* Copy all dwords of the packet. Note we're abusing the + * typesystem a little - we're being passed a pointer to + * something, but probably not an array of packet structs: + */ + ring->buf[ring->head] = packet[i]; + ring->head++; + ring->head &= ring->mask; + } + + /* Signal change: + */ + pipe_condvar_signal(ring->change); + pipe_mutex_unlock(ring->mutex); +} + +enum pipe_error util_ringbuffer_dequeue( struct util_ringbuffer *ring, + struct util_packet *packet, + unsigned max_dwords, + boolean wait ) +{ + const struct util_packet *ring_packet; + unsigned i; + int ret = PIPE_OK; + + /* XXX: over-reliance on mutexes, etc: + */ + pipe_mutex_lock(ring->mutex); + + /* Get next ring entry: + */ + if (wait) { + while (util_ringbuffer_empty(ring)) + pipe_condvar_wait(ring->change, ring->mutex); + } + else { + if (util_ringbuffer_empty(ring)) { + ret = PIPE_ERROR_OUT_OF_MEMORY; + goto out; + } + } + + ring_packet = &ring->buf[ring->tail]; + + /* Both of these are considered bugs. Raise an assert on debug builds. + */ + if (ring_packet->dwords > ring->mask + 1 - util_ringbuffer_space(ring) || + ring_packet->dwords > max_dwords) { + assert(0); + ret = PIPE_ERROR_BAD_INPUT; + goto out; + } + + /* Copy data from ring: + */ + for (i = 0; i < ring_packet->dwords; i++) { + packet[i] = ring->buf[ring->tail]; + ring->tail++; + ring->tail &= ring->mask; + } + +out: + /* Signal change: + */ + pipe_condvar_signal(ring->change); + pipe_mutex_unlock(ring->mutex); + return ret; +} diff --git a/src/gallium/auxiliary/util/u_ringbuffer.h b/src/gallium/auxiliary/util/u_ringbuffer.h new file mode 100644 index 0000000..85f0ad6 --- /dev/null +++ b/src/gallium/auxiliary/util/u_ringbuffer.h @@ -0,0 +1,29 @@ + +#ifndef UTIL_RINGBUFFER_H +#define UTIL_RINGBUFFER_H + +#include "pipe/p_compiler.h" +#include "pipe/p_defines.h" /* only for pipe_error! */ + +/* Generic header + */ +struct util_packet { + unsigned dwords:8; + unsigned data24:24; +}; + +struct util_ringbuffer; + +struct util_ringbuffer *util_ringbuffer_create( unsigned dwords ); + +void util_ringbuffer_destroy( struct util_ringbuffer *ring ); + +void util_ringbuffer_enqueue( struct util_ringbuffer *ring, + const struct util_packet *packet ); + +enum pipe_error util_ringbuffer_dequeue( struct util_ringbuffer *ring, + struct util_packet *packet, + unsigned max_dwords, + boolean wait ); + +#endif diff --git a/src/gallium/auxiliary/util/u_sampler.c b/src/gallium/auxiliary/util/u_sampler.c new file mode 100644 index 0000000..bb26099 --- /dev/null +++ b/src/gallium/auxiliary/util/u_sampler.c @@ -0,0 +1,103 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "u_format.h" +#include "u_sampler.h" + + +static void +default_template(struct pipe_sampler_view *view, + const struct pipe_resource *texture, + enum pipe_format format, + unsigned expand_green_blue) +{ + /* XXX: Check if format is compatible with texture->format. + */ + + view->format = format; + view->u.tex.first_level = 0; + view->u.tex.last_level = texture->last_level; + view->u.tex.first_layer = 0; + view->u.tex.last_layer = texture->target == PIPE_TEXTURE_3D ? + texture->depth0 - 1 : texture->array_size - 1; + view->swizzle_r = PIPE_SWIZZLE_RED; + view->swizzle_g = PIPE_SWIZZLE_GREEN; + view->swizzle_b = PIPE_SWIZZLE_BLUE; + view->swizzle_a = PIPE_SWIZZLE_ALPHA; + + /* Override default green and blue component expansion to the requested + * one. + * + * Gallium expands nonexistent components to (0,0,0,1), DX9 expands + * to (1,1,1,1). Since alpha is always expanded to 1, and red is + * always present, we only really care about green and blue + * components. + * + * To make it look less hackish, one would have to add + * UTIL_FORMAT_SWIZZLE_EXPAND to indicate components for expansion + * and then override without exceptions or favoring one component + * over another. + */ + if (format != PIPE_FORMAT_A8_UNORM) { + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (desc) { + if (desc->swizzle[1] == UTIL_FORMAT_SWIZZLE_0) { + view->swizzle_g = expand_green_blue; + } + if (desc->swizzle[2] == UTIL_FORMAT_SWIZZLE_0) { + view->swizzle_b = expand_green_blue; + } + } + } +} + +void +u_sampler_view_default_template(struct pipe_sampler_view *view, + const struct pipe_resource *texture, + enum pipe_format format) +{ + /* Expand to (0, 0, 0, 1) */ + default_template(view, + texture, + format, + PIPE_SWIZZLE_ZERO); +} + +void +u_sampler_view_default_dx9_template(struct pipe_sampler_view *view, + const struct pipe_resource *texture, + enum pipe_format format) +{ + /* Expand to (1, 1, 1, 1) */ + default_template(view, + texture, + format, + PIPE_SWIZZLE_ONE); +} diff --git a/src/gallium/auxiliary/util/u_sampler.h b/src/gallium/auxiliary/util/u_sampler.h new file mode 100644 index 0000000..f3dad74 --- /dev/null +++ b/src/gallium/auxiliary/util/u_sampler.h @@ -0,0 +1,57 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef U_SAMPLER_H +#define U_SAMPLER_H + + +#include "pipe/p_defines.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +void +u_sampler_view_default_template(struct pipe_sampler_view *view, + const struct pipe_resource *texture, + enum pipe_format format); + +void +u_sampler_view_default_dx9_template(struct pipe_sampler_view *view, + const struct pipe_resource *texture, + enum pipe_format format); + + +#ifdef __cplusplus +} /* extern "C" { */ +#endif + +#endif /* U_SAMPLER_H */ diff --git a/src/gallium/auxiliary/util/u_simple_list.h b/src/gallium/auxiliary/util/u_simple_list.h new file mode 100644 index 0000000..fe59771 --- /dev/null +++ b/src/gallium/auxiliary/util/u_simple_list.h @@ -0,0 +1,199 @@ +/** + * \file simple_list.h + * Simple macros for type-safe, intrusive lists. + * + * Intended to work with a list sentinal which is created as an empty + * list. Insert & delete are O(1). + * + * \author + * (C) 1997, Keith Whitwell + */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * 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. + */ + + +#ifndef _U_SIMPLE_LIST_H_ +#define _U_SIMPLE_LIST_H_ + +/** + * Remove an element from list. + * + * \param elem element to remove. + */ +#define remove_from_list(elem) \ +do { \ + (elem)->next->prev = (elem)->prev; \ + (elem)->prev->next = (elem)->next; \ + (elem)->next = elem; \ + (elem)->prev = elem; \ +} while (0) + +/** + * Insert an element to the list head. + * + * \param list list. + * \param elem element to insert. + */ +#define insert_at_head(list, elem) \ +do { \ + (elem)->prev = list; \ + (elem)->next = (list)->next; \ + (list)->next->prev = elem; \ + (list)->next = elem; \ +} while(0) + +/** + * Insert an element to the list tail. + * + * \param list list. + * \param elem element to insert. + */ +#define insert_at_tail(list, elem) \ +do { \ + (elem)->next = list; \ + (elem)->prev = (list)->prev; \ + (list)->prev->next = elem; \ + (list)->prev = elem; \ +} while(0) + +/** + * Move an element to the list head. + * + * \param list list. + * \param elem element to move. + */ +#define move_to_head(list, elem) \ +do { \ + remove_from_list(elem); \ + insert_at_head(list, elem); \ +} while (0) + +/** + * Move an element to the list tail. + * + * \param list list. + * \param elem element to move. + */ +#define move_to_tail(list, elem) \ +do { \ + remove_from_list(elem); \ + insert_at_tail(list, elem); \ +} while (0) + +/** + * Make a empty list empty. + * + * \param sentinal list (sentinal element). + */ +#define make_empty_list(sentinal) \ +do { \ + (sentinal)->next = sentinal; \ + (sentinal)->prev = sentinal; \ +} while (0) + +/** + * Get list first element. + * + * \param list list. + * + * \return pointer to first element. + */ +#define first_elem(list) ((list)->next) + +/** + * Get list last element. + * + * \param list list. + * + * \return pointer to last element. + */ +#define last_elem(list) ((list)->prev) + +/** + * Get next element. + * + * \param elem element. + * + * \return pointer to next element. + */ +#define next_elem(elem) ((elem)->next) + +/** + * Get previous element. + * + * \param elem element. + * + * \return pointer to previous element. + */ +#define prev_elem(elem) ((elem)->prev) + +/** + * Test whether element is at end of the list. + * + * \param list list. + * \param elem element. + * + * \return non-zero if element is at end of list, or zero otherwise. + */ +#define at_end(list, elem) ((elem) == (list)) + +/** + * Test if a list is empty. + * + * \param list list. + * + * \return non-zero if list empty, or zero otherwise. + */ +#define is_empty_list(list) ((list)->next == (list)) + +/** + * Walk through the elements of a list. + * + * \param ptr pointer to the current element. + * \param list list. + * + * \note It should be followed by a { } block or a single statement, as in a \c + * for loop. + */ +#define foreach(ptr, list) \ + for( ptr=(list)->next ; ptr!=list ; ptr=(ptr)->next ) + +/** + * Walk through the elements of a list. + * + * Same as #foreach but lets you unlink the current value during a list + * traversal. Useful for freeing a list, element by element. + * + * \param ptr pointer to the current element. + * \param t temporary pointer. + * \param list list. + * + * \note It should be followed by a { } block or a single statement, as in a \c + * for loop. + */ +#define foreach_s(ptr, t, list) \ + for(ptr=(list)->next,t=(ptr)->next; list != ptr; ptr=t, t=(t)->next) + +#endif /* _U_SIMPLE_LIST_H_ */ diff --git a/src/gallium/auxiliary/util/u_simple_screen.h b/src/gallium/auxiliary/util/u_simple_screen.h new file mode 100644 index 0000000..7139aaa --- /dev/null +++ b/src/gallium/auxiliary/util/u_simple_screen.h @@ -0,0 +1,179 @@ +/************************************************************************** + * + * 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 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. + * + **************************************************************************/ + +#ifndef U_SIMPLE_SCREEN_H +#define U_SIMPLE_SCREEN_H + +#include "pipe/p_format.h" + +struct pipe_screen; +struct pipe_fence_handle; +struct pipe_surface; +struct pipe_resource; + +/** + * Gallium3D drivers are (meant to be!) independent of both GL and the + * window system. The window system provides a buffer manager and a + * set of additional hooks for things like command buffer submission, + * etc. + * + * There clearly has to be some agreement between the window system + * driver and the hardware driver about the format of command buffers, + * etc. + */ +struct pipe_winsys +{ + void (*destroy)( struct pipe_winsys *ws ); + + /** Returns name of this winsys interface */ + const char *(*get_name)( struct pipe_winsys *ws ); + + /** + * Do any special operations to ensure frontbuffer contents are + * displayed, eg copy fake frontbuffer. + */ + void (*flush_frontbuffer)( struct pipe_winsys *ws, + struct pipe_resource *resource, + unsigned level, unsigned layer, + void *context_private ); + + + /** + * Buffer management. Buffer attributes are mostly fixed over its lifetime. + * + * Remember that gallium gets to choose the interface it needs, and the + * window systems must then implement that interface (rather than the + * other way around...). + * + * usage is a bitmask of PIPE_BIND_*. + * All possible usages must be present. + * + * alignment indicates the client's alignment requirements, eg for + * SSE instructions. + */ + struct pipe_resource *(*buffer_create)( struct pipe_winsys *ws, + unsigned alignment, + unsigned usage, + unsigned size ); + + /** + * Create a buffer that wraps user-space data. + * + * Effectively this schedules a delayed call to buffer_create + * followed by an upload of the data at *some point in the future*, + * or perhaps never. Basically the allocate/upload is delayed + * until the buffer is actually passed to hardware. + * + * The intention is to provide a quick way to turn regular data + * into a buffer, and secondly to avoid a copy operation if that + * data subsequently turns out to be only accessed by the CPU. + * + * Common example is OpenGL vertex buffers that are subsequently + * processed either by software TNL in the driver or by passing to + * hardware. + * + * XXX: What happens if the delayed call to buffer_create() fails? + * + * Note that ptr may be accessed at any time upto the time when the + * buffer is destroyed, so the data must not be freed before then. + */ + struct pipe_resource *(*user_buffer_create)(struct pipe_winsys *ws, + void *ptr, + unsigned bytes); + + /** + * Allocate storage for a display target surface. + * + * Often surfaces which are meant to be blitted to the front screen (i.e., + * display targets) must be allocated with special characteristics, memory + * pools, or obtained directly from the windowing system. + * + * This callback is invoked by the pipe_screen when creating a texture marked + * with the PIPE_BIND_DISPLAY_TARGET flag to get the underlying + * buffer storage. + */ + struct pipe_resource *(*surface_buffer_create)(struct pipe_winsys *ws, + unsigned width, unsigned height, + enum pipe_format format, + unsigned usage, + unsigned tex_usage, + unsigned *stride); + + + /** + * Map the entire data store of a buffer object into the client's address. + * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags. + */ + void *(*buffer_map)( struct pipe_winsys *ws, + struct pipe_resource *buf, + unsigned usage ); + + void (*buffer_unmap)( struct pipe_winsys *ws, + struct pipe_resource *buf ); + + void (*buffer_destroy)( struct pipe_resource *buf ); + + + /** Set ptr = fence, with reference counting */ + void (*fence_reference)( struct pipe_winsys *ws, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence ); + + /** + * Checks whether the fence has been signalled. + * \param flags driver-specific meaning + * \return zero on success. + */ + int (*fence_signalled)( struct pipe_winsys *ws, + struct pipe_fence_handle *fence, + unsigned flag ); + + /** + * Wait for the fence to finish. + * \param flags driver-specific meaning + * \return zero on success. + */ + int (*fence_finish)( struct pipe_winsys *ws, + struct pipe_fence_handle *fence, + unsigned flag ); + +}; + +/** + * The following function initializes a simple passthrough screen. + * + * All the relevant screen function pointers will forwarded to the + * winsys. + */ +void u_simple_screen_init(struct pipe_screen *screen); + +/** + * Returns the name of the winsys associated with this screen. + */ +const char* u_simple_screen_winsys_name(struct pipe_screen *screen); + +#endif diff --git a/src/gallium/auxiliary/util/u_simple_shaders.c b/src/gallium/auxiliary/util/u_simple_shaders.c new file mode 100644 index 0000000..b0f2dd8 --- /dev/null +++ b/src/gallium/auxiliary/util/u_simple_shaders.c @@ -0,0 +1,243 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2009 Marek Olšák + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Simple vertex/fragment shader generators. + * + * @author Brian Paul + Marek Olšák + */ + + +#include "pipe/p_context.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/p_state.h" +#include "util/u_simple_shaders.h" +#include "util/u_debug.h" +#include "tgsi/tgsi_ureg.h" + + + +/** + * Make simple vertex pass-through shader. + * \param num_attribs number of attributes to pass through + * \param semantic_names array of semantic names for each attribute + * \param semantic_indexes array of semantic indexes for each attribute + */ +void * +util_make_vertex_passthrough_shader(struct pipe_context *pipe, + uint num_attribs, + const uint *semantic_names, + const uint *semantic_indexes) +{ + struct ureg_program *ureg; + uint i; + + ureg = ureg_create( TGSI_PROCESSOR_VERTEX ); + if (ureg == NULL) + return NULL; + + for (i = 0; i < num_attribs; i++) { + struct ureg_src src; + struct ureg_dst dst; + + src = ureg_DECL_vs_input( ureg, i ); + + dst = ureg_DECL_output( ureg, + semantic_names[i], + semantic_indexes[i]); + + ureg_MOV( ureg, dst, src ); + } + + ureg_END( ureg ); + + return ureg_create_shader_and_destroy( ureg, pipe ); +} + + +/** + * Make simple fragment texture shader: + * IMM {0,0,0,1} // (if writemask != 0xf) + * MOV OUT[0], IMM[0] // (if writemask != 0xf) + * TEX OUT[0].writemask, IN[0], SAMP[0], 2D; + * END; + * + * \param tex_target one of PIPE_TEXTURE_x + * \parma interp_mode either TGSI_INTERPOLATE_LINEAR or PERSPECTIVE + * \param writemask mask of TGSI_WRITEMASK_x + */ +void * +util_make_fragment_tex_shader_writemask(struct pipe_context *pipe, + unsigned tex_target, + unsigned interp_mode, + unsigned writemask ) +{ + struct ureg_program *ureg; + struct ureg_src sampler; + struct ureg_src tex; + struct ureg_dst out; + + assert(interp_mode == TGSI_INTERPOLATE_LINEAR || + interp_mode == TGSI_INTERPOLATE_PERSPECTIVE); + + ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT ); + if (ureg == NULL) + return NULL; + + sampler = ureg_DECL_sampler( ureg, 0 ); + + tex = ureg_DECL_fs_input( ureg, + TGSI_SEMANTIC_GENERIC, 0, + interp_mode ); + + out = ureg_DECL_output( ureg, + TGSI_SEMANTIC_COLOR, + 0 ); + + if (writemask != TGSI_WRITEMASK_XYZW) { + struct ureg_src imm = ureg_imm4f( ureg, 0, 0, 0, 1 ); + + ureg_MOV( ureg, out, imm ); + } + + ureg_TEX( ureg, + ureg_writemask(out, writemask), + tex_target, tex, sampler ); + ureg_END( ureg ); + + return ureg_create_shader_and_destroy( ureg, pipe ); +} + + +/** + * Make a simple fragment shader that sets the output color to a color + * taken from a texture. + * \param tex_target one of PIPE_TEXTURE_x + */ +void * +util_make_fragment_tex_shader(struct pipe_context *pipe, unsigned tex_target, + unsigned interp_mode) +{ + return util_make_fragment_tex_shader_writemask( pipe, + tex_target, + interp_mode, + TGSI_WRITEMASK_XYZW ); +} + + +/** + * Make a simple fragment texture shader which reads an X component from + * a texture and writes it as depth. + */ +void * +util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe, + unsigned tex_target, + unsigned interp_mode) +{ + struct ureg_program *ureg; + struct ureg_src sampler; + struct ureg_src tex; + struct ureg_dst out, depth; + struct ureg_src imm; + + ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT ); + if (ureg == NULL) + return NULL; + + sampler = ureg_DECL_sampler( ureg, 0 ); + + tex = ureg_DECL_fs_input( ureg, + TGSI_SEMANTIC_GENERIC, 0, + interp_mode ); + + out = ureg_DECL_output( ureg, + TGSI_SEMANTIC_COLOR, + 0 ); + + depth = ureg_DECL_output( ureg, + TGSI_SEMANTIC_POSITION, + 0 ); + + imm = ureg_imm4f( ureg, 0, 0, 0, 1 ); + + ureg_MOV( ureg, out, imm ); + + ureg_TEX( ureg, + ureg_writemask(depth, TGSI_WRITEMASK_Z), + tex_target, tex, sampler ); + ureg_END( ureg ); + + return ureg_create_shader_and_destroy( ureg, pipe ); +} + + +/** + * Make simple fragment color pass-through shader. + */ +void * +util_make_fragment_passthrough_shader(struct pipe_context *pipe) +{ + return util_make_fragment_cloneinput_shader(pipe, 1, TGSI_SEMANTIC_COLOR, + TGSI_INTERPOLATE_PERSPECTIVE); +} + + +/** + * Make a fragment shader that copies the input color to N output colors. + */ +void * +util_make_fragment_cloneinput_shader(struct pipe_context *pipe, int num_cbufs, + int input_semantic, + int input_interpolate) +{ + struct ureg_program *ureg; + struct ureg_src src; + struct ureg_dst dst[PIPE_MAX_COLOR_BUFS]; + int i; + + assert(num_cbufs <= PIPE_MAX_COLOR_BUFS); + + ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT ); + if (ureg == NULL) + return NULL; + + src = ureg_DECL_fs_input( ureg, input_semantic, 0, + input_interpolate ); + + for (i = 0; i < num_cbufs; i++) + dst[i] = ureg_DECL_output( ureg, TGSI_SEMANTIC_COLOR, i ); + + for (i = 0; i < num_cbufs; i++) + ureg_MOV( ureg, dst[i], src ); + + ureg_END( ureg ); + + return ureg_create_shader_and_destroy( ureg, pipe ); +} diff --git a/src/gallium/auxiliary/util/u_simple_shaders.h b/src/gallium/auxiliary/util/u_simple_shaders.h new file mode 100644 index 0000000..1bfec18 --- /dev/null +++ b/src/gallium/auxiliary/util/u_simple_shaders.h @@ -0,0 +1,83 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef U_SIMPLE_SHADERS_H +#define U_SIMPLE_SHADERS_H + + +#include "pipe/p_compiler.h" + + +struct pipe_context; +struct pipe_shader_state; + + +#ifdef __cplusplus +extern "C" { +#endif + + +extern void * +util_make_vertex_passthrough_shader(struct pipe_context *pipe, + uint num_attribs, + const uint *semantic_names, + const uint *semantic_indexes); + + +extern void * +util_make_fragment_tex_shader_writemask(struct pipe_context *pipe, + unsigned tex_target, + unsigned interp_mode, + unsigned writemask); + +extern void * +util_make_fragment_tex_shader(struct pipe_context *pipe, unsigned tex_target, + unsigned interp_mode); + + +extern void * +util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe, + unsigned tex_target, + unsigned interp_mode); + + +extern void * +util_make_fragment_passthrough_shader(struct pipe_context *pipe); + + +extern void * +util_make_fragment_cloneinput_shader(struct pipe_context *pipe, int num_cbufs, + int input_semantic, + int input_interpolate); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/src/gallium/auxiliary/util/u_slab.c b/src/gallium/auxiliary/util/u_slab.c new file mode 100644 index 0000000..21bf2d7 --- /dev/null +++ b/src/gallium/auxiliary/util/u_slab.c @@ -0,0 +1,169 @@ +/* + * Copyright 2010 Marek Olšák + * + * 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 "util/u_slab.h" + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_simple_list.h" + +#include + +#define UTIL_SLAB_MAGIC 0xcafe4321 + +/* The block is either allocated memory or free space. */ +struct util_slab_block { + /* The header. */ + /* The first next free block. */ + struct util_slab_block *next_free; + + intptr_t magic; + + /* Memory after the last member is dedicated to the block itself. + * The allocated size is always larger than this structure. */ +}; + +static struct util_slab_block * +util_slab_get_block(struct util_slab_mempool *pool, + struct util_slab_page *page, unsigned index) +{ + return (struct util_slab_block*) + ((uint8_t*)page + sizeof(struct util_slab_page) + + (pool->block_size * index)); +} + +static void util_slab_add_new_page(struct util_slab_mempool *pool) +{ + struct util_slab_page *page; + struct util_slab_block *block; + int i; + + page = MALLOC(pool->page_size); + insert_at_tail(&pool->list, page); + + /* Mark all blocks as free. */ + for (i = 0; i < pool->num_blocks-1; i++) { + block = util_slab_get_block(pool, page, i); + block->next_free = util_slab_get_block(pool, page, i+1); + block->magic = UTIL_SLAB_MAGIC; + } + + block = util_slab_get_block(pool, page, pool->num_blocks-1); + block->next_free = pool->first_free; + block->magic = UTIL_SLAB_MAGIC; + pool->first_free = util_slab_get_block(pool, page, 0); + pool->num_pages++; + +#if 0 + fprintf(stderr, "New page! Num of pages: %i\n", pool->num_pages); +#endif +} + +static void *util_slab_alloc_st(struct util_slab_mempool *pool) +{ + struct util_slab_block *block; + + if (!pool->first_free) + util_slab_add_new_page(pool); + + block = pool->first_free; + assert(block->magic == UTIL_SLAB_MAGIC); + pool->first_free = block->next_free; + + return (uint8_t*)block + sizeof(struct util_slab_block); +} + +static void util_slab_free_st(struct util_slab_mempool *pool, void *ptr) +{ + struct util_slab_block *block = + (struct util_slab_block*) + ((uint8_t*)ptr - sizeof(struct util_slab_block)); + + assert(block->magic == UTIL_SLAB_MAGIC); + block->next_free = pool->first_free; + pool->first_free = block; +} + +static void *util_slab_alloc_mt(struct util_slab_mempool *pool) +{ + void *mem; + + pipe_mutex_lock(pool->mutex); + mem = util_slab_alloc_st(pool); + pipe_mutex_unlock(pool->mutex); + return mem; +} + +static void util_slab_free_mt(struct util_slab_mempool *pool, void *ptr) +{ + pipe_mutex_lock(pool->mutex); + util_slab_free_st(pool, ptr); + pipe_mutex_unlock(pool->mutex); +} + +void util_slab_set_thread_safety(struct util_slab_mempool *pool, + enum util_slab_threading threading) +{ + pool->threading = threading; + + if (threading) { + pool->alloc = util_slab_alloc_mt; + pool->free = util_slab_free_mt; + } else { + pool->alloc = util_slab_alloc_st; + pool->free = util_slab_free_st; + } +} + +void util_slab_create(struct util_slab_mempool *pool, + unsigned item_size, + unsigned num_blocks, + enum util_slab_threading threading) +{ + item_size = align(item_size, sizeof(intptr_t)); + + pool->num_pages = 0; + pool->num_blocks = num_blocks; + pool->block_size = sizeof(struct util_slab_block) + item_size; + pool->block_size = align(pool->block_size, sizeof(intptr_t)); + pool->page_size = sizeof(struct util_slab_page) + + num_blocks * pool->block_size; + pool->first_free = NULL; + + make_empty_list(&pool->list); + + pipe_mutex_init(pool->mutex); + + util_slab_set_thread_safety(pool, threading); +} + +void util_slab_destroy(struct util_slab_mempool *pool) +{ + struct util_slab_page *page, *temp; + + foreach_s(page, temp, &pool->list) { + remove_from_list(page); + FREE(page); + } + + pipe_mutex_destroy(pool->mutex); +} diff --git a/src/gallium/auxiliary/util/u_slab.h b/src/gallium/auxiliary/util/u_slab.h new file mode 100644 index 0000000..6b9718d --- /dev/null +++ b/src/gallium/auxiliary/util/u_slab.h @@ -0,0 +1,87 @@ +/* + * Copyright 2010 Marek Olšák + * + * 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. */ + +/** + * @file + * Simple slab allocator for equally sized memory allocations. + * util_slab_alloc and util_slab_free have time complexity in O(1). + * + * Good for allocations which have very low lifetime and are allocated + * and freed very often. Use a profiler first to know if it's worth using it! + * + * Candidates: get_transfer, user_buffer_create + * + * @author Marek Olšák + */ + +#ifndef U_SLAB_H +#define U_SLAB_H + +#include "os/os_thread.h" + +enum util_slab_threading { + UTIL_SLAB_SINGLETHREADED = FALSE, + UTIL_SLAB_MULTITHREADED = TRUE +}; + +/* The page is an array of blocks (allocations). */ +struct util_slab_page { + /* The header (linked-list pointers). */ + struct util_slab_page *prev, *next; + + /* Memory after the last member is dedicated to the page itself. + * The allocated size is always larger than this structure. */ +}; + +struct util_slab_mempool { + /* Public members. */ + void *(*alloc)(struct util_slab_mempool *pool); + void (*free)(struct util_slab_mempool *pool, void *ptr); + + /* Private members. */ + struct util_slab_block *first_free; + + struct util_slab_page list; + + unsigned block_size; + unsigned page_size; + unsigned num_blocks; + unsigned num_pages; + enum util_slab_threading threading; + + pipe_mutex mutex; +}; + +void util_slab_create(struct util_slab_mempool *pool, + unsigned item_size, + unsigned num_blocks, + enum util_slab_threading threading); + +void util_slab_destroy(struct util_slab_mempool *pool); + +void util_slab_set_thread_safety(struct util_slab_mempool *pool, + enum util_slab_threading threading); + +#define util_slab_alloc(pool) (pool)->alloc(pool) +#define util_slab_free(pool, ptr) (pool)->free(pool, ptr) + +#endif diff --git a/src/gallium/auxiliary/util/u_snprintf.c b/src/gallium/auxiliary/util/u_snprintf.c new file mode 100644 index 0000000..65bdd0d --- /dev/null +++ b/src/gallium/auxiliary/util/u_snprintf.c @@ -0,0 +1,1497 @@ +/* + * Copyright (c) 1995 Patrick Powell. + * + * This code is based on code written by Patrick Powell . + * It may be used for any purpose as long as this notice remains intact on all + * source code distributions. + */ + +/* + * Copyright (c) 2008 Holger Weiss. + * + * This version of the code is maintained by Holger Weiss . + * My changes to the code may freely be used, modified and/or redistributed for + * any purpose. It would be nice if additions and fixes to this file (including + * trivial code cleanups) would be sent back in order to let me include them in + * the version available at . + * However, this is not a requirement for using or redistributing (possibly + * modified) versions of this file, nor is leaving this notice intact mandatory. + */ + +/* + * History + * + * 2008-01-20 Holger Weiss for C99-snprintf 1.1: + * + * Fixed the detection of infinite floating point values on IRIX (and + * possibly other systems) and applied another few minor cleanups. + * + * 2008-01-06 Holger Weiss for C99-snprintf 1.0: + * + * Added a lot of new features, fixed many bugs, and incorporated various + * improvements done by Andrew Tridgell , Russ Allbery + * , Hrvoje Niksic , Damien Miller + * , and others for the Samba, INN, Wget, and OpenSSH + * projects. The additions include: support the "e", "E", "g", "G", and + * "F" conversion specifiers (and use conversion style "f" or "F" for the + * still unsupported "a" and "A" specifiers); support the "hh", "ll", "j", + * "t", and "z" length modifiers; support the "#" flag and the (non-C99) + * "'" flag; use localeconv(3) (if available) to get both the current + * locale's decimal point character and the separator between groups of + * digits; fix the handling of various corner cases of field width and + * precision specifications; fix various floating point conversion bugs; + * handle infinite and NaN floating point values; don't attempt to write to + * the output buffer (which may be NULL) if a size of zero was specified; + * check for integer overflow of the field width, precision, and return + * values and during the floating point conversion; use the OUTCHAR() macro + * instead of a function for better performance; provide asprintf(3) and + * vasprintf(3) functions; add new test cases. The replacement functions + * have been renamed to use an "rpl_" prefix, the function calls in the + * main project (and in this file) must be redefined accordingly for each + * replacement function which is needed (by using Autoconf or other means). + * Various other minor improvements have been applied and the coding style + * was cleaned up for consistency. + * + * 2007-07-23 Holger Weiss for Mutt 1.5.13: + * + * C99 compliant snprintf(3) and vsnprintf(3) functions return the number + * of characters that would have been written to a sufficiently sized + * buffer (excluding the '\0'). The original code simply returned the + * length of the resulting output string, so that's been fixed. + * + * 1998-03-05 Michael Elkins for Mutt 0.90.8: + * + * The original code assumed that both snprintf(3) and vsnprintf(3) were + * missing. Some systems only have snprintf(3) but not vsnprintf(3), so + * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF. + * + * 1998-01-27 Thomas Roessler for Mutt 0.89i: + * + * The PGP code was using unsigned hexadecimal formats. Unfortunately, + * unsigned formats simply didn't work. + * + * 1997-10-22 Brandon Long for Mutt 0.87.1: + * + * Ok, added some minimal floating point support, which means this probably + * requires libm on most operating systems. Don't yet support the exponent + * (e,E) and sigfig (g,G). Also, fmtint() was pretty badly broken, it just + * wasn't being exercised in ways which showed it, so that's been fixed. + * Also, formatted the code to Mutt conventions, and removed dead code left + * over from the original. Also, there is now a builtin-test, run with: + * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm && ./snprintf + * + * 2996-09-15 Brandon Long for Mutt 0.43: + * + * This was ugly. It is still ugly. I opted out of floating point + * numbers, but the formatter understands just about everything from the + * normal C string format, at least as far as I can tell from the Solaris + * 2.5 printf(3S) man page. + */ + +/* + * ToDo + * + * - Add wide character support. + * - Add support for "%a" and "%A" conversions. + * - Create test routines which predefine the expected results. Our test cases + * usually expose bugs in system implementations rather than in ours :-) + */ + +/* + * Usage + * + * 1) The following preprocessor macros should be defined to 1 if the feature or + * file in question is available on the target system (by using Autoconf or + * other means), though basic functionality should be available as long as + * HAVE_STDARG_H and HAVE_STDLIB_H are defined correctly: + * + * HAVE_VSNPRINTF + * HAVE_SNPRINTF + * HAVE_VASPRINTF + * HAVE_ASPRINTF + * HAVE_STDARG_H + * HAVE_STDDEF_H + * HAVE_STDINT_H + * HAVE_STDLIB_H + * HAVE_INTTYPES_H + * HAVE_LOCALE_H + * HAVE_LOCALECONV + * HAVE_LCONV_DECIMAL_POINT + * HAVE_LCONV_THOUSANDS_SEP + * HAVE_LONG_DOUBLE + * HAVE_LONG_LONG_INT + * HAVE_UNSIGNED_LONG_LONG_INT + * HAVE_INTMAX_T + * HAVE_UINTMAX_T + * HAVE_UINTPTR_T + * HAVE_PTRDIFF_T + * HAVE_VA_COPY + * HAVE___VA_COPY + * + * 2) The calls to the functions which should be replaced must be redefined + * throughout the project files (by using Autoconf or other means): + * + * #define vsnprintf rpl_vsnprintf + * #define snprintf rpl_snprintf + * #define vasprintf rpl_vasprintf + * #define asprintf rpl_asprintf + * + * 3) The required replacement functions should be declared in some header file + * included throughout the project files: + * + * #if HAVE_CONFIG_H + * #include + * #endif + * #if HAVE_STDARG_H + * #include + * #if !HAVE_VSNPRINTF + * int rpl_vsnprintf(char *, size_t, const char *, va_list); + * #endif + * #if !HAVE_SNPRINTF + * int rpl_snprintf(char *, size_t, const char *, ...); + * #endif + * #if !HAVE_VASPRINTF + * int rpl_vasprintf(char **, const char *, va_list); + * #endif + * #if !HAVE_ASPRINTF + * int rpl_asprintf(char **, const char *, ...); + * #endif + * #endif + * + * Autoconf macros for handling step 1 and step 2 are available at + * . + */ + +#include "pipe/p_config.h" + +#if HAVE_CONFIG_H +#include +#else +#ifdef WIN32 +#define vsnprintf util_vsnprintf +#define snprintf util_snprintf +#define HAVE_VSNPRINTF 0 +#define HAVE_SNPRINTF 0 +#define HAVE_VASPRINTF 1 /* not needed */ +#define HAVE_ASPRINTF 1 /* not needed */ +#define HAVE_STDARG_H 1 +#define HAVE_STDDEF_H 1 +#define HAVE_STDINT_H 0 +#define HAVE_STDLIB_H 1 +#define HAVE_INTTYPES_H 0 +#define HAVE_LOCALE_H 0 +#define HAVE_LOCALECONV 0 +#define HAVE_LCONV_DECIMAL_POINT 0 +#define HAVE_LCONV_THOUSANDS_SEP 0 +#define HAVE_LONG_DOUBLE 0 +#define HAVE_LONG_LONG_INT 1 +#define HAVE_UNSIGNED_LONG_LONG_INT 1 +#define HAVE_INTMAX_T 0 +#define HAVE_UINTMAX_T 0 +#define HAVE_UINTPTR_T 1 +#define HAVE_PTRDIFF_T 1 +#define HAVE_VA_COPY 0 +#define HAVE___VA_COPY 0 +#else +#define HAVE_VSNPRINTF 1 +#define HAVE_SNPRINTF 1 +#define HAVE_VASPRINTF 1 +#define HAVE_ASPRINTF 1 +#endif +#endif /* HAVE_CONFIG_H */ + +#if !HAVE_SNPRINTF || !HAVE_VSNPRINTF || !HAVE_ASPRINTF || !HAVE_VASPRINTF +#include /* For NULL, size_t, vsnprintf(3), and vasprintf(3). */ +#ifdef VA_START +#undef VA_START +#endif /* defined(VA_START) */ +#ifdef VA_SHIFT +#undef VA_SHIFT +#endif /* defined(VA_SHIFT) */ +#if HAVE_STDARG_H +#include +#define VA_START(ap, last) va_start(ap, last) +#define VA_SHIFT(ap, value, type) /* No-op for ANSI C. */ +#else /* Assume is available. */ +#include +#define VA_START(ap, last) va_start(ap) /* "last" is ignored. */ +#define VA_SHIFT(ap, value, type) value = va_arg(ap, type) +#endif /* HAVE_STDARG_H */ + +#if !HAVE_VASPRINTF +#if HAVE_STDLIB_H +#include /* For malloc(3). */ +#endif /* HAVE_STDLIB_H */ +#ifdef VA_COPY +#undef VA_COPY +#endif /* defined(VA_COPY) */ +#ifdef VA_END_COPY +#undef VA_END_COPY +#endif /* defined(VA_END_COPY) */ +#if HAVE_VA_COPY +#define VA_COPY(dest, src) va_copy(dest, src) +#define VA_END_COPY(ap) va_end(ap) +#elif HAVE___VA_COPY +#define VA_COPY(dest, src) __va_copy(dest, src) +#define VA_END_COPY(ap) va_end(ap) +#else +#define VA_COPY(dest, src) (void)mymemcpy(&dest, &src, sizeof(va_list)) +#define VA_END_COPY(ap) /* No-op. */ +#define NEED_MYMEMCPY 1 +static void *mymemcpy(void *, void *, size_t); +#endif /* HAVE_VA_COPY */ +#endif /* !HAVE_VASPRINTF */ + +#if !HAVE_VSNPRINTF +#include /* For *_MAX. */ +#if HAVE_INTTYPES_H +#include /* For intmax_t (if not defined in ). */ +#endif /* HAVE_INTTYPES_H */ +#if HAVE_LOCALE_H +#include /* For localeconv(3). */ +#endif /* HAVE_LOCALE_H */ +#if HAVE_STDDEF_H +#include /* For ptrdiff_t. */ +#endif /* HAVE_STDDEF_H */ +#if HAVE_STDINT_H +#include /* For intmax_t. */ +#endif /* HAVE_STDINT_H */ + +/* Support for unsigned long long int. We may also need ULLONG_MAX. */ +#ifndef ULONG_MAX /* We may need ULONG_MAX as a fallback. */ +#ifdef UINT_MAX +#define ULONG_MAX UINT_MAX +#else +#define ULONG_MAX INT_MAX +#endif /* defined(UINT_MAX) */ +#endif /* !defined(ULONG_MAX) */ +#ifdef ULLONG +#undef ULLONG +#endif /* defined(ULLONG) */ +#if HAVE_UNSIGNED_LONG_LONG_INT +#define ULLONG unsigned long long int +#ifndef ULLONG_MAX +#define ULLONG_MAX ULONG_MAX +#endif /* !defined(ULLONG_MAX) */ +#else +#define ULLONG unsigned long int +#ifdef ULLONG_MAX +#undef ULLONG_MAX +#endif /* defined(ULLONG_MAX) */ +#define ULLONG_MAX ULONG_MAX +#endif /* HAVE_LONG_LONG_INT */ + +/* Support for uintmax_t. We also need UINTMAX_MAX. */ +#ifdef UINTMAX_T +#undef UINTMAX_T +#endif /* defined(UINTMAX_T) */ +#if HAVE_UINTMAX_T || defined(uintmax_t) +#define UINTMAX_T uintmax_t +#ifndef UINTMAX_MAX +#define UINTMAX_MAX ULLONG_MAX +#endif /* !defined(UINTMAX_MAX) */ +#else +#define UINTMAX_T ULLONG +#ifdef UINTMAX_MAX +#undef UINTMAX_MAX +#endif /* defined(UINTMAX_MAX) */ +#define UINTMAX_MAX ULLONG_MAX +#endif /* HAVE_UINTMAX_T || defined(uintmax_t) */ + +/* Support for long double. */ +#ifndef LDOUBLE +#if HAVE_LONG_DOUBLE +#define LDOUBLE long double +#else +#define LDOUBLE double +#endif /* HAVE_LONG_DOUBLE */ +#endif /* !defined(LDOUBLE) */ + +/* Support for long long int. */ +#ifndef LLONG +#if HAVE_LONG_LONG_INT +#define LLONG long long int +#else +#define LLONG long int +#endif /* HAVE_LONG_LONG_INT */ +#endif /* !defined(LLONG) */ + +/* Support for intmax_t. */ +#ifndef INTMAX_T +#if HAVE_INTMAX_T || defined(intmax_t) +#define INTMAX_T intmax_t +#else +#define INTMAX_T LLONG +#endif /* HAVE_INTMAX_T || defined(intmax_t) */ +#endif /* !defined(INTMAX_T) */ + +/* Support for uintptr_t. */ +#ifndef UINTPTR_T +#if HAVE_UINTPTR_T || defined(uintptr_t) +#define UINTPTR_T uintptr_t +#else +#define UINTPTR_T unsigned long int +#endif /* HAVE_UINTPTR_T || defined(uintptr_t) */ +#endif /* !defined(UINTPTR_T) */ + +/* WinCE5.0 does not have uintptr_t defined */ +#if (_WIN32_WCE < 600) +#ifdef UINTPTR_T +#undef UINTPTR_T +#endif +#define UINTPTR_T unsigned long int +#endif + + +/* Support for ptrdiff_t. */ +#ifndef PTRDIFF_T +#if HAVE_PTRDIFF_T || defined(ptrdiff_t) +#define PTRDIFF_T ptrdiff_t +#else +#define PTRDIFF_T long int +#endif /* HAVE_PTRDIFF_T || defined(ptrdiff_t) */ +#endif /* !defined(PTRDIFF_T) */ + +/* + * We need an unsigned integer type corresponding to ptrdiff_t (cf. C99: + * 7.19.6.1, 7). However, we'll simply use PTRDIFF_T and convert it to an + * unsigned type if necessary. This should work just fine in practice. + */ +#ifndef UPTRDIFF_T +#define UPTRDIFF_T PTRDIFF_T +#endif /* !defined(UPTRDIFF_T) */ + +/* + * We need a signed integer type corresponding to size_t (cf. C99: 7.19.6.1, 7). + * However, we'll simply use size_t and convert it to a signed type if + * necessary. This should work just fine in practice. + */ +#ifndef SSIZE_T +#define SSIZE_T size_t +#endif /* !defined(SSIZE_T) */ + +/* Either ERANGE or E2BIG should be available everywhere. */ +#ifndef ERANGE +#define ERANGE E2BIG +#endif /* !defined(ERANGE) */ +#ifndef EOVERFLOW +#define EOVERFLOW ERANGE +#endif /* !defined(EOVERFLOW) */ + +/* + * Buffer size to hold the octal string representation of UINT128_MAX without + * nul-termination ("3777777777777777777777777777777777777777777"). + */ +#ifdef MAX_CONVERT_LENGTH +#undef MAX_CONVERT_LENGTH +#endif /* defined(MAX_CONVERT_LENGTH) */ +#define MAX_CONVERT_LENGTH 43 + +/* Format read states. */ +#define PRINT_S_DEFAULT 0 +#define PRINT_S_FLAGS 1 +#define PRINT_S_WIDTH 2 +#define PRINT_S_DOT 3 +#define PRINT_S_PRECISION 4 +#define PRINT_S_MOD 5 +#define PRINT_S_CONV 6 + +/* Format flags. */ +#define PRINT_F_MINUS (1 << 0) +#define PRINT_F_PLUS (1 << 1) +#define PRINT_F_SPACE (1 << 2) +#define PRINT_F_NUM (1 << 3) +#define PRINT_F_ZERO (1 << 4) +#define PRINT_F_QUOTE (1 << 5) +#define PRINT_F_UP (1 << 6) +#define PRINT_F_UNSIGNED (1 << 7) +#define PRINT_F_TYPE_G (1 << 8) +#define PRINT_F_TYPE_E (1 << 9) + +/* Conversion flags. */ +#define PRINT_C_CHAR 1 +#define PRINT_C_SHORT 2 +#define PRINT_C_LONG 3 +#define PRINT_C_LLONG 4 +#define PRINT_C_LDOUBLE 5 +#define PRINT_C_SIZE 6 +#define PRINT_C_PTRDIFF 7 +#define PRINT_C_INTMAX 8 + +#ifndef MAX +#define MAX(x, y) ((x >= y) ? x : y) +#endif /* !defined(MAX) */ +#ifndef CHARTOINT +#define CHARTOINT(ch) (ch - '0') +#endif /* !defined(CHARTOINT) */ +#ifndef ISDIGIT +#define ISDIGIT(ch) ('0' <= (unsigned char)ch && (unsigned char)ch <= '9') +#endif /* !defined(ISDIGIT) */ +#ifndef ISNAN +#define ISNAN(x) (x != x) +#endif /* !defined(ISNAN) */ +#ifndef ISINF +#define ISINF(x) (x != 0.0 && x + x == x) +#endif /* !defined(ISINF) */ + +#ifdef OUTCHAR +#undef OUTCHAR +#endif /* defined(OUTCHAR) */ +#define OUTCHAR(str, len, size, ch) \ +do { \ + if (len + 1 < size) \ + str[len] = ch; \ + (len)++; \ +} while (/* CONSTCOND */ 0) + +static void fmtstr(char *, size_t *, size_t, const char *, int, int, int); +static void fmtint(char *, size_t *, size_t, INTMAX_T, int, int, int, int); +static void fmtflt(char *, size_t *, size_t, LDOUBLE, int, int, int, int *); +static void printsep(char *, size_t *, size_t); +static int getnumsep(int); +static int getexponent(LDOUBLE); +static int convert(UINTMAX_T, char *, size_t, int, int); +static UINTMAX_T cast(LDOUBLE); +static UINTMAX_T myround(LDOUBLE); +static LDOUBLE mypow10(int); + +int +util_vsnprintf(char *str, size_t size, const char *format, va_list args) +{ + LDOUBLE fvalue; + INTMAX_T value; + unsigned char cvalue; + const char *strvalue; + INTMAX_T *intmaxptr; + PTRDIFF_T *ptrdiffptr; + SSIZE_T *sizeptr; + LLONG *llongptr; + long int *longptr; + int *intptr; + short int *shortptr; + signed char *charptr; + size_t len = 0; + int overflow = 0; + int base = 0; + int cflags = 0; + int flags = 0; + int width = 0; + int precision = -1; + int state = PRINT_S_DEFAULT; + char ch = *format++; + + /* + * C99 says: "If `n' is zero, nothing is written, and `s' may be a null + * pointer." (7.19.6.5, 2) We're forgiving and allow a NULL pointer + * even if a size larger than zero was specified. At least NetBSD's + * snprintf(3) does the same, as well as other versions of this file. + * (Though some of these versions will write to a non-NULL buffer even + * if a size of zero was specified, which violates the standard.) + */ + if (str == NULL && size != 0) + size = 0; + + while (ch != '\0') + switch (state) { + case PRINT_S_DEFAULT: + if (ch == '%') + state = PRINT_S_FLAGS; + else + OUTCHAR(str, len, size, ch); + ch = *format++; + break; + case PRINT_S_FLAGS: + switch (ch) { + case '-': + flags |= PRINT_F_MINUS; + ch = *format++; + break; + case '+': + flags |= PRINT_F_PLUS; + ch = *format++; + break; + case ' ': + flags |= PRINT_F_SPACE; + ch = *format++; + break; + case '#': + flags |= PRINT_F_NUM; + ch = *format++; + break; + case '0': + flags |= PRINT_F_ZERO; + ch = *format++; + break; + case '\'': /* SUSv2 flag (not in C99). */ + flags |= PRINT_F_QUOTE; + ch = *format++; + break; + default: + state = PRINT_S_WIDTH; + break; + } + break; + case PRINT_S_WIDTH: + if (ISDIGIT(ch)) { + ch = CHARTOINT(ch); + if (width > (INT_MAX - ch) / 10) { + overflow = 1; + goto out; + } + width = 10 * width + ch; + ch = *format++; + } else if (ch == '*') { + /* + * C99 says: "A negative field width argument is + * taken as a `-' flag followed by a positive + * field width." (7.19.6.1, 5) + */ + if ((width = va_arg(args, int)) < 0) { + flags |= PRINT_F_MINUS; + width = -width; + } + ch = *format++; + state = PRINT_S_DOT; + } else + state = PRINT_S_DOT; + break; + case PRINT_S_DOT: + if (ch == '.') { + state = PRINT_S_PRECISION; + ch = *format++; + } else + state = PRINT_S_MOD; + break; + case PRINT_S_PRECISION: + if (precision == -1) + precision = 0; + if (ISDIGIT(ch)) { + ch = CHARTOINT(ch); + if (precision > (INT_MAX - ch) / 10) { + overflow = 1; + goto out; + } + precision = 10 * precision + ch; + ch = *format++; + } else if (ch == '*') { + /* + * C99 says: "A negative precision argument is + * taken as if the precision were omitted." + * (7.19.6.1, 5) + */ + if ((precision = va_arg(args, int)) < 0) + precision = -1; + ch = *format++; + state = PRINT_S_MOD; + } else + state = PRINT_S_MOD; + break; + case PRINT_S_MOD: + switch (ch) { + case 'h': + ch = *format++; + if (ch == 'h') { /* It's a char. */ + ch = *format++; + cflags = PRINT_C_CHAR; + } else + cflags = PRINT_C_SHORT; + break; + case 'l': + ch = *format++; + if (ch == 'l') { /* It's a long long. */ + ch = *format++; + cflags = PRINT_C_LLONG; + } else + cflags = PRINT_C_LONG; + break; + case 'L': + cflags = PRINT_C_LDOUBLE; + ch = *format++; + break; + case 'j': + cflags = PRINT_C_INTMAX; + ch = *format++; + break; + case 't': + cflags = PRINT_C_PTRDIFF; + ch = *format++; + break; + case 'z': + cflags = PRINT_C_SIZE; + ch = *format++; + break; + } + state = PRINT_S_CONV; + break; + case PRINT_S_CONV: + switch (ch) { + case 'd': + /* FALLTHROUGH */ + case 'i': + switch (cflags) { + case PRINT_C_CHAR: + value = (signed char)va_arg(args, int); + break; + case PRINT_C_SHORT: + value = (short int)va_arg(args, int); + break; + case PRINT_C_LONG: + value = va_arg(args, long int); + break; + case PRINT_C_LLONG: + value = va_arg(args, LLONG); + break; + case PRINT_C_SIZE: + value = va_arg(args, SSIZE_T); + break; + case PRINT_C_INTMAX: + value = va_arg(args, INTMAX_T); + break; + case PRINT_C_PTRDIFF: + value = va_arg(args, PTRDIFF_T); + break; + default: + value = va_arg(args, int); + break; + } + fmtint(str, &len, size, value, 10, width, + precision, flags); + break; + case 'X': + flags |= PRINT_F_UP; + /* FALLTHROUGH */ + case 'x': + base = 16; + /* FALLTHROUGH */ + case 'o': + if (base == 0) + base = 8; + /* FALLTHROUGH */ + case 'u': + if (base == 0) + base = 10; + flags |= PRINT_F_UNSIGNED; + switch (cflags) { + case PRINT_C_CHAR: + value = (unsigned char)va_arg(args, + unsigned int); + break; + case PRINT_C_SHORT: + value = (unsigned short int)va_arg(args, + unsigned int); + break; + case PRINT_C_LONG: + value = va_arg(args, unsigned long int); + break; + case PRINT_C_LLONG: + value = va_arg(args, ULLONG); + break; + case PRINT_C_SIZE: + value = va_arg(args, size_t); + break; + case PRINT_C_INTMAX: + value = va_arg(args, UINTMAX_T); + break; + case PRINT_C_PTRDIFF: + value = va_arg(args, UPTRDIFF_T); + break; + default: + value = va_arg(args, unsigned int); + break; + } + fmtint(str, &len, size, value, base, width, + precision, flags); + break; + case 'A': + /* Not yet supported, we'll use "%F". */ + /* FALLTHROUGH */ + case 'F': + flags |= PRINT_F_UP; + case 'a': + /* Not yet supported, we'll use "%f". */ + /* FALLTHROUGH */ + case 'f': + if (cflags == PRINT_C_LDOUBLE) + fvalue = va_arg(args, LDOUBLE); + else + fvalue = va_arg(args, double); + fmtflt(str, &len, size, fvalue, width, + precision, flags, &overflow); + if (overflow) + goto out; + break; + case 'E': + flags |= PRINT_F_UP; + /* FALLTHROUGH */ + case 'e': + flags |= PRINT_F_TYPE_E; + if (cflags == PRINT_C_LDOUBLE) + fvalue = va_arg(args, LDOUBLE); + else + fvalue = va_arg(args, double); + fmtflt(str, &len, size, fvalue, width, + precision, flags, &overflow); + if (overflow) + goto out; + break; + case 'G': + flags |= PRINT_F_UP; + /* FALLTHROUGH */ + case 'g': + flags |= PRINT_F_TYPE_G; + if (cflags == PRINT_C_LDOUBLE) + fvalue = va_arg(args, LDOUBLE); + else + fvalue = va_arg(args, double); + /* + * If the precision is zero, it is treated as + * one (cf. C99: 7.19.6.1, 8). + */ + if (precision == 0) + precision = 1; + fmtflt(str, &len, size, fvalue, width, + precision, flags, &overflow); + if (overflow) + goto out; + break; + case 'c': + cvalue = (unsigned char)va_arg(args, int); + OUTCHAR(str, len, size, cvalue); + break; + case 's': + strvalue = va_arg(args, char *); + fmtstr(str, &len, size, strvalue, width, + precision, flags); + break; + case 'p': + /* + * C99 says: "The value of the pointer is + * converted to a sequence of printing + * characters, in an implementation-defined + * manner." (C99: 7.19.6.1, 8) + */ + if ((strvalue = va_arg(args, void *)) == NULL) + /* + * We use the glibc format. BSD prints + * "0x0", SysV "0". + */ + fmtstr(str, &len, size, "(nil)", width, + -1, flags); + else { + /* + * We use the BSD/glibc format. SysV + * omits the "0x" prefix (which we emit + * using the PRINT_F_NUM flag). + */ + flags |= PRINT_F_NUM; + flags |= PRINT_F_UNSIGNED; + fmtint(str, &len, size, + (UINTPTR_T)strvalue, 16, width, + precision, flags); + } + break; + case 'n': + switch (cflags) { + case PRINT_C_CHAR: + charptr = va_arg(args, signed char *); + *charptr = (signed char)len; + break; + case PRINT_C_SHORT: + shortptr = va_arg(args, short int *); + *shortptr = (short int)len; + break; + case PRINT_C_LONG: + longptr = va_arg(args, long int *); + *longptr = (long int)len; + break; + case PRINT_C_LLONG: + llongptr = va_arg(args, LLONG *); + *llongptr = (LLONG)len; + break; + case PRINT_C_SIZE: + /* + * C99 says that with the "z" length + * modifier, "a following `n' conversion + * specifier applies to a pointer to a + * signed integer type corresponding to + * size_t argument." (7.19.6.1, 7) + */ + sizeptr = va_arg(args, SSIZE_T *); + *sizeptr = len; + break; + case PRINT_C_INTMAX: + intmaxptr = va_arg(args, INTMAX_T *); + *intmaxptr = len; + break; + case PRINT_C_PTRDIFF: + ptrdiffptr = va_arg(args, PTRDIFF_T *); + *ptrdiffptr = len; + break; + default: + intptr = va_arg(args, int *); + *intptr = (int)len; + break; + } + break; + case '%': /* Print a "%" character verbatim. */ + OUTCHAR(str, len, size, ch); + break; + default: /* Skip other characters. */ + break; + } + ch = *format++; + state = PRINT_S_DEFAULT; + base = cflags = flags = width = 0; + precision = -1; + break; + } +out: + if (len < size) + str[len] = '\0'; + else if (size > 0) + str[size - 1] = '\0'; + + if (overflow || len >= INT_MAX) { + return -1; + } + return (int)len; +} + +static void +fmtstr(char *str, size_t *len, size_t size, const char *value, int width, + int precision, int flags) +{ + int padlen, strln; /* Amount to pad. */ + int noprecision = (precision == -1); + + if (value == NULL) /* We're forgiving. */ + value = "(null)"; + + /* If a precision was specified, don't read the string past it. */ + for (strln = 0; value[strln] != '\0' && + (noprecision || strln < precision); strln++) + continue; + + if ((padlen = width - strln) < 0) + padlen = 0; + if (flags & PRINT_F_MINUS) /* Left justify. */ + padlen = -padlen; + + while (padlen > 0) { /* Leading spaces. */ + OUTCHAR(str, *len, size, ' '); + padlen--; + } + while (*value != '\0' && (noprecision || precision-- > 0)) { + OUTCHAR(str, *len, size, *value); + value++; + } + while (padlen < 0) { /* Trailing spaces. */ + OUTCHAR(str, *len, size, ' '); + padlen++; + } +} + +static void +fmtint(char *str, size_t *len, size_t size, INTMAX_T value, int base, int width, + int precision, int flags) +{ + UINTMAX_T uvalue; + char iconvert[MAX_CONVERT_LENGTH]; + char sign = 0; + char hexprefix = 0; + int spadlen = 0; /* Amount to space pad. */ + int zpadlen = 0; /* Amount to zero pad. */ + int pos; + int separators = (flags & PRINT_F_QUOTE); + int noprecision = (precision == -1); + + if (flags & PRINT_F_UNSIGNED) + uvalue = value; + else { + uvalue = (value >= 0) ? value : -value; + if (value < 0) + sign = '-'; + else if (flags & PRINT_F_PLUS) /* Do a sign. */ + sign = '+'; + else if (flags & PRINT_F_SPACE) + sign = ' '; + } + + pos = convert(uvalue, iconvert, sizeof(iconvert), base, + flags & PRINT_F_UP); + + if (flags & PRINT_F_NUM && uvalue != 0) { + /* + * C99 says: "The result is converted to an `alternative form'. + * For `o' conversion, it increases the precision, if and only + * if necessary, to force the first digit of the result to be a + * zero (if the value and precision are both 0, a single 0 is + * printed). For `x' (or `X') conversion, a nonzero result has + * `0x' (or `0X') prefixed to it." (7.19.6.1, 6) + */ + switch (base) { + case 8: + if (precision <= pos) + precision = pos + 1; + break; + case 16: + hexprefix = (flags & PRINT_F_UP) ? 'X' : 'x'; + break; + } + } + + if (separators) /* Get the number of group separators we'll print. */ + separators = getnumsep(pos); + + zpadlen = precision - pos - separators; + spadlen = width /* Minimum field width. */ + - separators /* Number of separators. */ + - MAX(precision, pos) /* Number of integer digits. */ + - ((sign != 0) ? 1 : 0) /* Will we print a sign? */ + - ((hexprefix != 0) ? 2 : 0); /* Will we print a prefix? */ + + if (zpadlen < 0) + zpadlen = 0; + if (spadlen < 0) + spadlen = 0; + + /* + * C99 says: "If the `0' and `-' flags both appear, the `0' flag is + * ignored. For `d', `i', `o', `u', `x', and `X' conversions, if a + * precision is specified, the `0' flag is ignored." (7.19.6.1, 6) + */ + if (flags & PRINT_F_MINUS) /* Left justify. */ + spadlen = -spadlen; + else if (flags & PRINT_F_ZERO && noprecision) { + zpadlen += spadlen; + spadlen = 0; + } + while (spadlen > 0) { /* Leading spaces. */ + OUTCHAR(str, *len, size, ' '); + spadlen--; + } + if (sign != 0) /* Sign. */ + OUTCHAR(str, *len, size, sign); + if (hexprefix != 0) { /* A "0x" or "0X" prefix. */ + OUTCHAR(str, *len, size, '0'); + OUTCHAR(str, *len, size, hexprefix); + } + while (zpadlen > 0) { /* Leading zeros. */ + OUTCHAR(str, *len, size, '0'); + zpadlen--; + } + while (pos > 0) { /* The actual digits. */ + pos--; + OUTCHAR(str, *len, size, iconvert[pos]); + if (separators > 0 && pos > 0 && pos % 3 == 0) + printsep(str, len, size); + } + while (spadlen < 0) { /* Trailing spaces. */ + OUTCHAR(str, *len, size, ' '); + spadlen++; + } +} + +static void +fmtflt(char *str, size_t *len, size_t size, LDOUBLE fvalue, int width, + int precision, int flags, int *overflow) +{ + LDOUBLE ufvalue; + UINTMAX_T intpart; + UINTMAX_T fracpart; + UINTMAX_T mask; + const char *infnan = NULL; + char iconvert[MAX_CONVERT_LENGTH]; + char fconvert[MAX_CONVERT_LENGTH]; + char econvert[4]; /* "e-12" (without nul-termination). */ + char esign = 0; + char sign = 0; + int leadfraczeros = 0; + int exponent = 0; + int emitpoint = 0; + int omitzeros = 0; + int omitcount = 0; + int padlen = 0; + int epos = 0; + int fpos = 0; + int ipos = 0; + int separators = (flags & PRINT_F_QUOTE); + int estyle = (flags & PRINT_F_TYPE_E); +#if HAVE_LOCALECONV && HAVE_LCONV_DECIMAL_POINT + struct lconv *lc = localeconv(); +#endif /* HAVE_LOCALECONV && HAVE_LCONV_DECIMAL_POINT */ + + /* + * AIX' man page says the default is 0, but C99 and at least Solaris' + * and NetBSD's man pages say the default is 6, and sprintf(3) on AIX + * defaults to 6. + */ + if (precision == -1) + precision = 6; + + if (fvalue < 0.0) + sign = '-'; + else if (flags & PRINT_F_PLUS) /* Do a sign. */ + sign = '+'; + else if (flags & PRINT_F_SPACE) + sign = ' '; + + if (ISNAN(fvalue)) + infnan = (flags & PRINT_F_UP) ? "NAN" : "nan"; + else if (ISINF(fvalue)) + infnan = (flags & PRINT_F_UP) ? "INF" : "inf"; + + if (infnan != NULL) { + if (sign != 0) + iconvert[ipos++] = sign; + while (*infnan != '\0') + iconvert[ipos++] = *infnan++; + fmtstr(str, len, size, iconvert, width, ipos, flags); + return; + } + + /* "%e" (or "%E") or "%g" (or "%G") conversion. */ + if (flags & PRINT_F_TYPE_E || flags & PRINT_F_TYPE_G) { + if (flags & PRINT_F_TYPE_G) { + /* + * For "%g" (and "%G") conversions, the precision + * specifies the number of significant digits, which + * includes the digits in the integer part. The + * conversion will or will not be using "e-style" (like + * "%e" or "%E" conversions) depending on the precision + * and on the exponent. However, the exponent can be + * affected by rounding the converted value, so we'll + * leave this decision for later. Until then, we'll + * assume that we're going to do an "e-style" conversion + * (in order to get the exponent calculated). For + * "e-style", the precision must be decremented by one. + */ + precision--; + /* + * For "%g" (and "%G") conversions, trailing zeros are + * removed from the fractional portion of the result + * unless the "#" flag was specified. + */ + if (!(flags & PRINT_F_NUM)) + omitzeros = 1; + } + exponent = getexponent(fvalue); + estyle = 1; + } + +again: + /* + * Sorry, we only support 9, 19, or 38 digits (that is, the number of + * digits of the 32-bit, the 64-bit, or the 128-bit UINTMAX_MAX value + * minus one) past the decimal point due to our conversion method. + */ + switch (sizeof(UINTMAX_T)) { + case 16: + if (precision > 38) + precision = 38; + break; + case 8: + if (precision > 19) + precision = 19; + break; + default: + if (precision > 9) + precision = 9; + break; + } + + ufvalue = (fvalue >= 0.0) ? fvalue : -fvalue; + if (estyle) /* We want exactly one integer digit. */ + ufvalue /= mypow10(exponent); + + if ((intpart = cast(ufvalue)) == UINTMAX_MAX) { + *overflow = 1; + return; + } + + /* + * Factor of ten with the number of digits needed for the fractional + * part. For example, if the precision is 3, the mask will be 1000. + */ +#if defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) + mask = (unsigned long)mypow10(precision); +#else + mask = (UINTMAX_T)mypow10(precision); +#endif + /* + * We "cheat" by converting the fractional part to integer by + * multiplying by a factor of ten. + */ + if ((fracpart = myround(mask * (ufvalue - intpart))) >= mask) { + /* + * For example, ufvalue = 2.99962, intpart = 2, and mask = 1000 + * (because precision = 3). Now, myround(1000 * 0.99962) will + * return 1000. So, the integer part must be incremented by one + * and the fractional part must be set to zero. + */ + intpart++; + fracpart = 0; + if (estyle && intpart == 10) { + /* + * The value was rounded up to ten, but we only want one + * integer digit if using "e-style". So, the integer + * part must be set to one and the exponent must be + * incremented by one. + */ + intpart = 1; + exponent++; + } + } + + /* + * Now that we know the real exponent, we can check whether or not to + * use "e-style" for "%g" (and "%G") conversions. If we don't need + * "e-style", the precision must be adjusted and the integer and + * fractional parts must be recalculated from the original value. + * + * C99 says: "Let P equal the precision if nonzero, 6 if the precision + * is omitted, or 1 if the precision is zero. Then, if a conversion + * with style `E' would have an exponent of X: + * + * - if P > X >= -4, the conversion is with style `f' (or `F') and + * precision P - (X + 1). + * + * - otherwise, the conversion is with style `e' (or `E') and precision + * P - 1." (7.19.6.1, 8) + * + * Note that we had decremented the precision by one. + */ + if (flags & PRINT_F_TYPE_G && estyle && + precision + 1 > exponent && exponent >= -4) { + precision -= exponent; + estyle = 0; + goto again; + } + + if (estyle) { + if (exponent < 0) { + exponent = -exponent; + esign = '-'; + } else + esign = '+'; + + /* + * Convert the exponent. The sizeof(econvert) is 4. So, the + * econvert buffer can hold e.g. "e+99" and "e-99". We don't + * support an exponent which contains more than two digits. + * Therefore, the following stores are safe. + */ + epos = convert(exponent, econvert, 2, 10, 0); + /* + * C99 says: "The exponent always contains at least two digits, + * and only as many more digits as necessary to represent the + * exponent." (7.19.6.1, 8) + */ + if (epos == 1) + econvert[epos++] = '0'; + econvert[epos++] = esign; + econvert[epos++] = (flags & PRINT_F_UP) ? 'E' : 'e'; + } + + /* Convert the integer part and the fractional part. */ + ipos = convert(intpart, iconvert, sizeof(iconvert), 10, 0); + if (fracpart != 0) /* convert() would return 1 if fracpart == 0. */ + fpos = convert(fracpart, fconvert, sizeof(fconvert), 10, 0); + + leadfraczeros = precision - fpos; + + if (omitzeros) { + if (fpos > 0) /* Omit trailing fractional part zeros. */ + while (omitcount < fpos && fconvert[omitcount] == '0') + omitcount++; + else { /* The fractional part is zero, omit it completely. */ + omitcount = precision; + leadfraczeros = 0; + } + precision -= omitcount; + } + + /* + * Print a decimal point if either the fractional part is non-zero + * and/or the "#" flag was specified. + */ + if (precision > 0 || flags & PRINT_F_NUM) + emitpoint = 1; + if (separators) /* Get the number of group separators we'll print. */ + separators = getnumsep(ipos); + + padlen = width /* Minimum field width. */ + - ipos /* Number of integer digits. */ + - epos /* Number of exponent characters. */ + - precision /* Number of fractional digits. */ + - separators /* Number of group separators. */ + - (emitpoint ? 1 : 0) /* Will we print a decimal point? */ + - ((sign != 0) ? 1 : 0); /* Will we print a sign character? */ + + if (padlen < 0) + padlen = 0; + + /* + * C99 says: "If the `0' and `-' flags both appear, the `0' flag is + * ignored." (7.19.6.1, 6) + */ + if (flags & PRINT_F_MINUS) /* Left justifty. */ + padlen = -padlen; + else if (flags & PRINT_F_ZERO && padlen > 0) { + if (sign != 0) { /* Sign. */ + OUTCHAR(str, *len, size, sign); + sign = 0; + } + while (padlen > 0) { /* Leading zeros. */ + OUTCHAR(str, *len, size, '0'); + padlen--; + } + } + while (padlen > 0) { /* Leading spaces. */ + OUTCHAR(str, *len, size, ' '); + padlen--; + } + if (sign != 0) /* Sign. */ + OUTCHAR(str, *len, size, sign); + while (ipos > 0) { /* Integer part. */ + ipos--; + OUTCHAR(str, *len, size, iconvert[ipos]); + if (separators > 0 && ipos > 0 && ipos % 3 == 0) + printsep(str, len, size); + } + if (emitpoint) { /* Decimal point. */ +#if HAVE_LOCALECONV && HAVE_LCONV_DECIMAL_POINT + if (lc->decimal_point != NULL && *lc->decimal_point != '\0') + OUTCHAR(str, *len, size, *lc->decimal_point); + else /* We'll always print some decimal point character. */ +#endif /* HAVE_LOCALECONV && HAVE_LCONV_DECIMAL_POINT */ + OUTCHAR(str, *len, size, '.'); + } + while (leadfraczeros > 0) { /* Leading fractional part zeros. */ + OUTCHAR(str, *len, size, '0'); + leadfraczeros--; + } + while (fpos > omitcount) { /* The remaining fractional part. */ + fpos--; + OUTCHAR(str, *len, size, fconvert[fpos]); + } + while (epos > 0) { /* Exponent. */ + epos--; + OUTCHAR(str, *len, size, econvert[epos]); + } + while (padlen < 0) { /* Trailing spaces. */ + OUTCHAR(str, *len, size, ' '); + padlen++; + } +} + +static void +printsep(char *str, size_t *len, size_t size) +{ +#if HAVE_LOCALECONV && HAVE_LCONV_THOUSANDS_SEP + struct lconv *lc = localeconv(); + int i; + + if (lc->thousands_sep != NULL) + for (i = 0; lc->thousands_sep[i] != '\0'; i++) + OUTCHAR(str, *len, size, lc->thousands_sep[i]); + else +#endif /* HAVE_LOCALECONV && HAVE_LCONV_THOUSANDS_SEP */ + OUTCHAR(str, *len, size, ','); +} + +static int +getnumsep(int digits) +{ + int separators = (digits - ((digits % 3 == 0) ? 1 : 0)) / 3; +#if HAVE_LOCALECONV && HAVE_LCONV_THOUSANDS_SEP + int strln; + struct lconv *lc = localeconv(); + + /* We support an arbitrary separator length (including zero). */ + if (lc->thousands_sep != NULL) { + for (strln = 0; lc->thousands_sep[strln] != '\0'; strln++) + continue; + separators *= strln; + } +#endif /* HAVE_LOCALECONV && HAVE_LCONV_THOUSANDS_SEP */ + return separators; +} + +static int +getexponent(LDOUBLE value) +{ + LDOUBLE tmp = (value >= 0.0) ? value : -value; + int exponent = 0; + + /* + * We check for 99 > exponent > -99 in order to work around possible + * endless loops which could happen (at least) in the second loop (at + * least) if we're called with an infinite value. However, we checked + * for infinity before calling this function using our ISINF() macro, so + * this might be somewhat paranoid. + */ + while (tmp < 1.0 && tmp > 0.0 && --exponent > -99) + tmp *= 10; + while (tmp >= 10.0 && ++exponent < 99) + tmp /= 10; + + return exponent; +} + +static int +convert(UINTMAX_T value, char *buf, size_t size, int base, int caps) +{ + const char *digits = caps ? "0123456789ABCDEF" : "0123456789abcdef"; + size_t pos = 0; + + /* We return an unterminated buffer with the digits in reverse order. */ + do { + buf[pos++] = digits[value % base]; + value /= base; + } while (value != 0 && pos < size); + + return (int)pos; +} + +static UINTMAX_T +cast(LDOUBLE value) +{ + UINTMAX_T result; + + /* + * We check for ">=" and not for ">" because if UINTMAX_MAX cannot be + * represented exactly as an LDOUBLE value (but is less than LDBL_MAX), + * it may be increased to the nearest higher representable value for the + * comparison (cf. C99: 6.3.1.4, 2). It might then equal the LDOUBLE + * value although converting the latter to UINTMAX_T would overflow. + */ + if (value >= UINTMAX_MAX) + return UINTMAX_MAX; + +#if defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) + result = (unsigned long)value; +#else + result = (UINTMAX_T)value; +#endif + /* + * At least on NetBSD/sparc64 3.0.2 and 4.99.30, casting long double to + * an integer type converts e.g. 1.9 to 2 instead of 1 (which violates + * the standard). Sigh. + */ + return (result <= value) ? result : result - 1; +} + +static UINTMAX_T +myround(LDOUBLE value) +{ + UINTMAX_T intpart = cast(value); + + return ((value -= intpart) < 0.5) ? intpart : intpart + 1; +} + +static LDOUBLE +mypow10(int exponent) +{ + LDOUBLE result = 1; + + while (exponent > 0) { + result *= 10; + exponent--; + } + while (exponent < 0) { + result /= 10; + exponent++; + } + return result; +} +#endif /* !HAVE_VSNPRINTF */ + +#if !HAVE_VASPRINTF +#if NEED_MYMEMCPY +void * +mymemcpy(void *dst, void *src, size_t len) +{ + const char *from = src; + char *to = dst; + + /* No need for optimization, we use this only to replace va_copy(3). */ + while (len-- > 0) + *to++ = *from++; + return dst; +} +#endif /* NEED_MYMEMCPY */ + +int +util_vasprintf(char **ret, const char *format, va_list ap) +{ + size_t size; + int len; + va_list aq; + + VA_COPY(aq, ap); + len = vsnprintf(NULL, 0, format, aq); + VA_END_COPY(aq); + if (len < 0 || (*ret = malloc(size = len + 1)) == NULL) + return -1; + return vsnprintf(*ret, size, format, ap); +} +#endif /* !HAVE_VASPRINTF */ + +#if !HAVE_SNPRINTF +#if HAVE_STDARG_H +int +util_snprintf(char *str, size_t size, const char *format, ...) +#else +int +util_snprintf(va_alist) va_dcl +#endif /* HAVE_STDARG_H */ +{ +#if !HAVE_STDARG_H + char *str; + size_t size; + char *format; +#endif /* HAVE_STDARG_H */ + va_list ap; + int len; + + VA_START(ap, format); + VA_SHIFT(ap, str, char *); + VA_SHIFT(ap, size, size_t); + VA_SHIFT(ap, format, const char *); + len = vsnprintf(str, size, format, ap); + va_end(ap); + return len; +} +#endif /* !HAVE_SNPRINTF */ + +#if !HAVE_ASPRINTF +#if HAVE_STDARG_H +int +util_asprintf(char **ret, const char *format, ...) +#else +int +util_asprintf(va_alist) va_dcl +#endif /* HAVE_STDARG_H */ +{ +#if !HAVE_STDARG_H + char **ret; + char *format; +#endif /* HAVE_STDARG_H */ + va_list ap; + int len; + + VA_START(ap, format); + VA_SHIFT(ap, ret, char **); + VA_SHIFT(ap, format, const char *); + len = vasprintf(ret, format, ap); + va_end(ap); + return len; +} +#endif /* !HAVE_ASPRINTF */ +#else /* Dummy declaration to avoid empty translation unit warnings. */ +int main(void); +#endif /* !HAVE_SNPRINTF || !HAVE_VSNPRINTF || !HAVE_ASPRINTF || [...] */ + + +/* vim: set joinspaces textwidth=80: */ diff --git a/src/gallium/auxiliary/util/u_split_prim.h b/src/gallium/auxiliary/util/u_split_prim.h new file mode 100644 index 0000000..7f80fc1 --- /dev/null +++ b/src/gallium/auxiliary/util/u_split_prim.h @@ -0,0 +1,114 @@ +/* Originally written by Ben Skeggs for the nv50 driver*/ + +#ifndef U_SPLIT_PRIM_H +#define U_SPLIT_PRIM_H + +#include "pipe/p_defines.h" +#include "pipe/p_compiler.h" + +#include "util/u_debug.h" + +struct util_split_prim { + void *priv; + void (*emit)(void *priv, unsigned start, unsigned count); + void (*edge)(void *priv, boolean enabled); + + unsigned mode; + unsigned start; + unsigned p_start; + unsigned p_end; + + uint repeat_first:1; + uint close_first:1; + uint edgeflag_off:1; +}; + +static INLINE void +util_split_prim_init(struct util_split_prim *s, + unsigned mode, unsigned start, unsigned count) +{ + if (mode == PIPE_PRIM_LINE_LOOP) { + s->mode = PIPE_PRIM_LINE_STRIP; + s->close_first = 1; + } else { + s->mode = mode; + s->close_first = 0; + } + s->start = start; + s->p_start = start; + s->p_end = start + count; + s->edgeflag_off = 0; + s->repeat_first = 0; +} + +static INLINE boolean +util_split_prim_next(struct util_split_prim *s, unsigned max_verts) +{ + int repeat = 0; + + if (s->repeat_first) { + s->emit(s->priv, s->start, 1); + max_verts--; + if (s->edgeflag_off) { + s->edge(s->priv, TRUE); + s->edgeflag_off = FALSE; + } + } + + if ((s->p_end - s->p_start) + s->close_first <= max_verts) { + s->emit(s->priv, s->p_start, s->p_end - s->p_start); + if (s->close_first) + s->emit(s->priv, s->start, 1); + return TRUE; + } + + switch (s->mode) { + case PIPE_PRIM_LINES: + max_verts &= ~1; + break; + case PIPE_PRIM_LINE_STRIP: + repeat = 1; + break; + case PIPE_PRIM_POLYGON: + max_verts--; + s->emit(s->priv, s->p_start, max_verts); + s->edge(s->priv, FALSE); + s->emit(s->priv, s->p_start + max_verts, 1); + s->p_start += max_verts; + s->repeat_first = TRUE; + s->edgeflag_off = TRUE; + return FALSE; + case PIPE_PRIM_TRIANGLES: + max_verts = max_verts - (max_verts % 3); + break; + case PIPE_PRIM_TRIANGLE_STRIP: + /* to ensure winding stays correct, always split + * on an even number of generated triangles + */ + max_verts = max_verts & ~1; + repeat = 2; + break; + case PIPE_PRIM_TRIANGLE_FAN: + s->repeat_first = TRUE; + repeat = 1; + break; + case PIPE_PRIM_QUADS: + max_verts &= ~3; + break; + case PIPE_PRIM_QUAD_STRIP: + max_verts &= ~1; + repeat = 2; + break; + case PIPE_PRIM_POINTS: + break; + default: + /* TODO: implement adjacency primitives */ + assert(0); + } + + s->emit (s->priv, s->p_start, max_verts); + s->p_start += (max_verts - repeat); + return FALSE; +} + +#endif /* U_SPLIT_PRIM_H */ diff --git a/src/gallium/auxiliary/util/u_sse.h b/src/gallium/auxiliary/util/u_sse.h new file mode 100644 index 0000000..1df6c87 --- /dev/null +++ b/src/gallium/auxiliary/util/u_sse.h @@ -0,0 +1,255 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * SSE intrinsics portability header. + * + * Although the SSE intrinsics are support by all modern x86 and x86-64 + * compilers, there are some intrisincs missing in some implementations + * (especially older MSVC versions). This header abstracts that away. + */ + +#ifndef U_SSE_H_ +#define U_SSE_H_ + +#include "pipe/p_config.h" + +#if defined(PIPE_ARCH_SSE) + +#include + + +/* MSVC before VC8 does not support the _mm_castxxx_yyy */ +#if defined(_MSC_VER) && _MSC_VER < 1500 + +union __declspec(align(16)) m128_types { + __m128 m128; + __m128i m128i; + __m128d m128d; +}; + +static __inline __m128 +_mm_castsi128_ps(__m128i a) +{ + union m128_types u; + u.m128i = a; + return u.m128; +} + +static __inline __m128i +_mm_castps_si128(__m128 a) +{ + union m128_types u; + u.m128 = a; + return u.m128i; +} + +#endif /* defined(_MSC_VER) && _MSC_VER < 1500 */ + +union m128i { + __m128i m; + ubyte ub[16]; + ushort us[8]; + uint ui[4]; +}; + +static INLINE void u_print_epi8(const char *name, __m128i r) +{ + union { __m128i m; ubyte ub[16]; } u; + u.m = r; + + debug_printf("%s: " + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x/" + "%02x\n", + name, + u.ub[0], u.ub[1], u.ub[2], u.ub[3], + u.ub[4], u.ub[5], u.ub[6], u.ub[7], + u.ub[8], u.ub[9], u.ub[10], u.ub[11], + u.ub[12], u.ub[13], u.ub[14], u.ub[15]); +} + +static INLINE void u_print_epi16(const char *name, __m128i r) +{ + union { __m128i m; ushort us[8]; } u; + u.m = r; + + debug_printf("%s: " + "%04x/" + "%04x/" + "%04x/" + "%04x/" + "%04x/" + "%04x/" + "%04x/" + "%04x\n", + name, + u.us[0], u.us[1], u.us[2], u.us[3], + u.us[4], u.us[5], u.us[6], u.us[7]); +} + +static INLINE void u_print_epi32(const char *name, __m128i r) +{ + union { __m128i m; uint ui[4]; } u; + u.m = r; + + debug_printf("%s: " + "%08x/" + "%08x/" + "%08x/" + "%08x\n", + name, + u.ui[0], u.ui[1], u.ui[2], u.ui[3]); +} + +static INLINE void u_print_ps(const char *name, __m128 r) +{ + union { __m128 m; float f[4]; } u; + u.m = r; + + debug_printf("%s: " + "%f/" + "%f/" + "%f/" + "%f\n", + name, + u.f[0], u.f[1], u.f[2], u.f[3]); +} + + +#define U_DUMP_EPI32(a) u_print_epi32(#a, a) +#define U_DUMP_EPI16(a) u_print_epi16(#a, a) +#define U_DUMP_EPI8(a) u_print_epi8(#a, a) +#define U_DUMP_PS(a) u_print_ps(#a, a) + + + +#if defined(PIPE_ARCH_SSSE3) + +#include + +#else /* !PIPE_ARCH_SSSE3 */ + +/** + * Describe _mm_shuffle_epi8() with gcc extended inline assembly, for cases + * where -mssse3 is not supported/enabled. + * + * MSVC will never get in here as its intrinsics support do not rely on + * compiler command line options. + */ +static __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm_shuffle_epi8(__m128i a, __m128i mask) +{ + __m128i result; + __asm__("pshufb %1, %0" + : "=x" (result) + : "xm" (mask), "0" (a)); + return result; +} + +#endif /* !PIPE_ARCH_SSSE3 */ + + + + +/* Provide an SSE2 implementation of _mm_mullo_epi32() in terms of + * _mm_mul_epu32(). + * + * I suspect this works fine for us because one of our operands is + * always positive, but not sure that this can be used for general + * signed integer multiplication. + * + * This seems close enough to the speed of SSE4 and the real + * _mm_mullo_epi32() intrinsic as to not justify adding an sse4 + * dependency at this point. + */ +static INLINE __m128i mm_mullo_epi32(const __m128i a, const __m128i b) +{ + __m128i a4 = _mm_srli_epi64(a, 32); /* shift by one dword */ + __m128i b4 = _mm_srli_epi64(b, 32); /* shift by one dword */ + __m128i ba = _mm_mul_epu32(b, a); /* multply dwords 0, 2 */ + __m128i b4a4 = _mm_mul_epu32(b4, a4); /* multiply dwords 1, 3 */ + + /* Interleave the results, either with shuffles or (slightly + * faster) direct bit operations: + */ +#if 0 + __m128i ba8 = _mm_shuffle_epi32(ba, 8); + __m128i b4a48 = _mm_shuffle_epi32(b4a4, 8); + __m128i result = _mm_unpacklo_epi32(ba8, b4a48); +#else + __m128i mask = _mm_setr_epi32(~0,0,~0,0); + __m128i ba_mask = _mm_and_si128(ba, mask); + __m128i b4a4_mask_shift = _mm_slli_epi64(b4a4, 32); + __m128i result = _mm_or_si128(ba_mask, b4a4_mask_shift); +#endif + + return result; +} + + +static INLINE void +transpose4_epi32(const __m128i * restrict a, + const __m128i * restrict b, + const __m128i * restrict c, + const __m128i * restrict d, + __m128i * restrict o, + __m128i * restrict p, + __m128i * restrict q, + __m128i * restrict r) +{ + __m128i t0 = _mm_unpacklo_epi32(*a, *b); + __m128i t1 = _mm_unpacklo_epi32(*c, *d); + __m128i t2 = _mm_unpackhi_epi32(*a, *b); + __m128i t3 = _mm_unpackhi_epi32(*c, *d); + + *o = _mm_unpacklo_epi64(t0, t1); + *p = _mm_unpackhi_epi64(t0, t1); + *q = _mm_unpacklo_epi64(t2, t3); + *r = _mm_unpackhi_epi64(t2, t3); +} + +#define SCALAR_EPI32(m, i) _mm_shuffle_epi32((m), _MM_SHUFFLE(i,i,i,i)) + + +#endif /* PIPE_ARCH_SSE */ + +#endif /* U_SSE_H_ */ diff --git a/src/gallium/auxiliary/util/u_staging.c b/src/gallium/auxiliary/util/u_staging.c new file mode 100644 index 0000000..b6bf241 --- /dev/null +++ b/src/gallium/auxiliary/util/u_staging.c @@ -0,0 +1,132 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_staging.h" +#include "pipe/p_context.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" + +static void +util_staging_resource_template(struct pipe_resource *pt, unsigned width, unsigned height, unsigned depth, struct pipe_resource *template) +{ + memset(template, 0, sizeof(struct pipe_resource)); + if(pt->target != PIPE_BUFFER && depth <= 1) + template->target = PIPE_TEXTURE_RECT; + else + template->target = pt->target; + template->format = pt->format; + template->width0 = width; + template->height0 = height; + template->depth0 = depth; + template->array_size = 1; + template->last_level = 0; + template->nr_samples = pt->nr_samples; + template->bind = 0; + template->usage = PIPE_USAGE_STAGING; + template->flags = 0; +} + +struct util_staging_transfer * +util_staging_transfer_init(struct pipe_context *pipe, + struct pipe_resource *pt, + unsigned level, + unsigned usage, + const struct pipe_box *box, + bool direct, struct util_staging_transfer *tx) +{ + struct pipe_screen *pscreen = pipe->screen; + + struct pipe_resource staging_resource_template; + + pipe_resource_reference(&tx->base.resource, pt); + tx->base.level = level; + tx->base.usage = usage; + tx->base.box = *box; + + if (direct) + { + tx->staging_resource = pt; + return tx; + } + + util_staging_resource_template(pt, box->width, box->height, box->depth, &staging_resource_template); + tx->staging_resource = pscreen->resource_create(pscreen, &staging_resource_template); + if (!tx->staging_resource) + { + pipe_resource_reference(&tx->base.resource, NULL); + FREE(tx); + return NULL; + } + + if (usage & PIPE_TRANSFER_READ) + { + /* XXX this looks wrong dst is always the same but looping over src z? */ + unsigned zi; + struct pipe_box sbox; + sbox.x = box->x; + sbox.y = box->y; + sbox.z = box->z; + sbox.width = box->width; + sbox.height = box->height; + sbox.depth = 1; + for(zi = 0; zi < box->depth; ++zi) { + sbox.z = sbox.z + zi; + pipe->resource_copy_region(pipe, tx->staging_resource, 0, 0, 0, 0, + tx->base.resource, level, &sbox); + } + } + + return tx; +} + +void +util_staging_transfer_destroy(struct pipe_context *pipe, struct pipe_transfer *ptx) +{ + struct util_staging_transfer *tx = (struct util_staging_transfer *)ptx; + + if (tx->staging_resource != tx->base.resource) + { + if(tx->base.usage & PIPE_TRANSFER_WRITE) { + /* XXX this looks wrong src is always the same but looping over dst z? */ + unsigned zi; + struct pipe_box sbox; + sbox.x = 0; + sbox.y = 0; + sbox.z = 0; + sbox.width = tx->base.box.width; + sbox.height = tx->base.box.height; + sbox.depth = 1; + for(zi = 0; zi < tx->base.box.depth; ++zi) + pipe->resource_copy_region(pipe, tx->base.resource, tx->base.level, tx->base.box.x, tx->base.box.y, tx->base.box.z + zi, + tx->staging_resource, 0, &sbox); + } + + pipe_resource_reference(&tx->staging_resource, NULL); + } + + pipe_resource_reference(&ptx->resource, NULL); + FREE(ptx); +} diff --git a/src/gallium/auxiliary/util/u_staging.h b/src/gallium/auxiliary/util/u_staging.h new file mode 100644 index 0000000..49839d2 --- /dev/null +++ b/src/gallium/auxiliary/util/u_staging.h @@ -0,0 +1,63 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Direct3D 10/11 has no concept of transfers. Applications instead + * create resources with a STAGING or DYNAMIC usage, copy between them + * and the real resource and use Map to map the STAGING/DYNAMIC resource. + * + * This util module allows to implement Gallium drivers as a Direct3D + * driver would be implemented: transfers allocate a resource with + * PIPE_USAGE_STAGING, and copy the data between it and the real resource + * with resource_copy_region. + */ + +#ifndef U_STAGING_H +#define U_STAGING_H + +#include "pipe/p_state.h" + +struct util_staging_transfer { + struct pipe_transfer base; + + /* if direct, same as base.resource, otherwise the temporary staging resource */ + struct pipe_resource *staging_resource; +}; + +/* user must be stride, slice_stride and offset */ +/* pt->usage == PIPE_USAGE_DYNAMIC || pt->usage == PIPE_USAGE_STAGING should be a good value to pass for direct */ +/* staging resource is currently created with PIPE_USAGE_STAGING */ +struct util_staging_transfer * +util_staging_transfer_init(struct pipe_context *pipe, + struct pipe_resource *pt, + unsigned level, + unsigned usage, + const struct pipe_box *box, + bool direct, struct util_staging_transfer *tx); + +void +util_staging_transfer_destroy(struct pipe_context *pipe, struct pipe_transfer *ptx); + +#endif diff --git a/src/gallium/auxiliary/util/u_string.h b/src/gallium/auxiliary/util/u_string.h new file mode 100644 index 0000000..cc7992d --- /dev/null +++ b/src/gallium/auxiliary/util/u_string.h @@ -0,0 +1,220 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Platform independent functions for string manipulation. + * + * @author Jose Fonseca + */ + +#ifndef U_STRING_H_ +#define U_STRING_H_ + +#if !defined(WIN32) && !defined(XF86_LIBC_H) +#include +#endif +#include +#include + +#include "pipe/p_compiler.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef WIN32 + +int util_vsnprintf(char *, size_t, const char *, va_list); +int util_snprintf(char *str, size_t size, const char *format, ...); + +static INLINE void +util_vsprintf(char *str, const char *format, va_list ap) +{ + util_vsnprintf(str, (size_t)-1, format, ap); +} + +static INLINE void +util_sprintf(char *str, const char *format, ...) +{ + va_list ap; + va_start(ap, format); + util_vsnprintf(str, (size_t)-1, format, ap); + va_end(ap); +} + +static INLINE char * +util_strchr(const char *s, char c) +{ + while(*s) { + if(*s == c) + return (char *)s; + ++s; + } + return NULL; +} + +static INLINE char* +util_strncat(char *dst, const char *src, size_t n) +{ + char *p = dst + strlen(dst); + const char *q = src; + size_t i; + + for (i = 0; i < n && *q != '\0'; ++i) + *p++ = *q++; + *p = '\0'; + + return dst; +} + +static INLINE int +util_strcmp(const char *s1, const char *s2) +{ + unsigned char u1, u2; + + while (1) { + u1 = (unsigned char) *s1++; + u2 = (unsigned char) *s2++; + if (u1 != u2) + return u1 - u2; + if (u1 == '\0') + return 0; + } + return 0; +} + +static INLINE int +util_strncmp(const char *s1, const char *s2, size_t n) +{ + unsigned char u1, u2; + + while (n-- > 0) { + u1 = (unsigned char) *s1++; + u2 = (unsigned char) *s2++; + if (u1 != u2) + return u1 - u2; + if (u1 == '\0') + return 0; + } + return 0; +} + +static INLINE char * +util_strstr(const char *haystack, const char *needle) +{ + const char *p = haystack; + size_t len = strlen(needle); + + for (; (p = util_strchr(p, *needle)) != 0; p++) { + if (util_strncmp(p, needle, len) == 0) { + return (char *)p; + } + } + return NULL; +} + +static INLINE void * +util_memmove(void *dest, const void *src, size_t n) +{ + char *p = (char *)dest; + const char *q = (const char *)src; + if (dest < src) { + while (n--) + *p++ = *q++; + } + else + { + p += n; + q += n; + while (n--) + *--p = *--q; + } + return dest; +} + + +#else + +#define util_vsnprintf vsnprintf +#define util_snprintf snprintf +#define util_vsprintf vsprintf +#define util_sprintf sprintf +#define util_strchr strchr +#define util_strcmp strcmp +#define util_strncmp strncmp +#define util_strncat strncat +#define util_strstr strstr +#define util_memmove memmove + +#endif + + +/** + * Printable string buffer + */ +struct util_strbuf +{ + char *str; + char *ptr; + size_t left; +}; + + +static INLINE void +util_strbuf_init(struct util_strbuf *sbuf, char *str, size_t size) +{ + sbuf->str = str; + sbuf->str[0] = 0; + sbuf->ptr = sbuf->str; + sbuf->left = size; +} + + +static INLINE void +util_strbuf_printf(struct util_strbuf *sbuf, const char *format, ...) +{ + if(sbuf->left > 1) { + size_t written; + va_list ap; + va_start(ap, format); + written = util_vsnprintf(sbuf->ptr, sbuf->left, format, ap); + va_end(ap); + sbuf->ptr += written; + sbuf->left -= written; + } +} + + + +#ifdef __cplusplus +} +#endif + +#endif /* U_STRING_H_ */ diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c new file mode 100644 index 0000000..4eddd3f --- /dev/null +++ b/src/gallium/auxiliary/util/u_surface.c @@ -0,0 +1,364 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Surface utility functions. + * + * @author Brian Paul + */ + + +#include "pipe/p_defines.h" +#include "pipe/p_screen.h" +#include "pipe/p_state.h" + +#include "util/u_format.h" +#include "util/u_inlines.h" +#include "util/u_rect.h" +#include "util/u_surface.h" +#include "util/u_pack_color.h" + +void +u_surface_default_template(struct pipe_surface *view, + const struct pipe_resource *texture, + unsigned bind) +{ + view->format = texture->format; + view->u.tex.level = 0; + view->u.tex.first_layer = 0; + view->u.tex.last_layer = 0; + /* XXX should filter out all non-rt/ds bind flags ? */ + view->usage = bind; +} + +/** + * Helper to quickly create an RGBA rendering surface of a certain size. + * \param textureOut returns the new texture + * \param surfaceOut returns the new surface + * \return TRUE for success, FALSE if failure + */ +boolean +util_create_rgba_surface(struct pipe_context *pipe, + uint width, uint height, + uint bind, + struct pipe_resource **textureOut, + struct pipe_surface **surfaceOut) +{ + static const enum pipe_format rgbaFormats[] = { + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_A8R8G8B8_UNORM, + PIPE_FORMAT_A8B8G8R8_UNORM, + PIPE_FORMAT_NONE + }; + const uint target = PIPE_TEXTURE_2D; + enum pipe_format format = PIPE_FORMAT_NONE; + struct pipe_resource templ; + struct pipe_surface surf_templ; + struct pipe_screen *screen = pipe->screen; + uint i; + + /* Choose surface format */ + for (i = 0; rgbaFormats[i]; i++) { + if (screen->is_format_supported(screen, rgbaFormats[i], + target, 0, bind, 0)) { + format = rgbaFormats[i]; + break; + } + } + if (format == PIPE_FORMAT_NONE) + return FALSE; /* unable to get an rgba format!?! */ + + /* create texture */ + memset(&templ, 0, sizeof(templ)); + templ.target = target; + templ.format = format; + templ.last_level = 0; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.array_size = 1; + templ.bind = bind; + + *textureOut = screen->resource_create(screen, &templ); + if (!*textureOut) + return FALSE; + + /* create surface */ + memset(&surf_templ, 0, sizeof(surf_templ)); + u_surface_default_template(&surf_templ, *textureOut, bind); + /* create surface / view into texture */ + *surfaceOut = pipe->create_surface(pipe, + *textureOut, + &surf_templ); + if (!*surfaceOut) { + pipe_resource_reference(textureOut, NULL); + return FALSE; + } + + return TRUE; +} + + +/** + * Release the surface and texture from util_create_rgba_surface(). + */ +void +util_destroy_rgba_surface(struct pipe_resource *texture, + struct pipe_surface *surface) +{ + pipe_surface_reference(&surface, NULL); + pipe_resource_reference(&texture, NULL); +} + + + +/** + * Fallback function for pipe->resource_copy_region(). + * Note: (X,Y)=(0,0) is always the upper-left corner. + */ +void +util_resource_copy_region(struct pipe_context *pipe, + struct pipe_resource *dst, + unsigned dst_level, + unsigned dst_x, unsigned dst_y, unsigned dst_z, + struct pipe_resource *src, + unsigned src_level, + const struct pipe_box *src_box) +{ + struct pipe_transfer *src_trans, *dst_trans; + void *dst_map; + const void *src_map; + enum pipe_format src_format, dst_format; + unsigned w = src_box->width; + unsigned h = src_box->height; + + assert(src && dst); + if (!src || !dst) + return; + + src_format = src->format; + dst_format = dst->format; + + src_trans = pipe_get_transfer(pipe, + src, + src_level, + src_box->z, + PIPE_TRANSFER_READ, + src_box->x, src_box->y, w, h); + + dst_trans = pipe_get_transfer(pipe, + dst, + dst_level, + dst_z, + PIPE_TRANSFER_WRITE, + dst_x, dst_y, w, h); + + assert(util_format_get_blocksize(dst_format) == util_format_get_blocksize(src_format)); + assert(util_format_get_blockwidth(dst_format) == util_format_get_blockwidth(src_format)); + assert(util_format_get_blockheight(dst_format) == util_format_get_blockheight(src_format)); + + src_map = pipe->transfer_map(pipe, src_trans); + dst_map = pipe->transfer_map(pipe, dst_trans); + + assert(src_map); + assert(dst_map); + + if (src_map && dst_map) { + util_copy_rect(dst_map, + dst_format, + dst_trans->stride, + 0, 0, + w, h, + src_map, + src_trans->stride, + 0, + 0); + } + + pipe->transfer_unmap(pipe, src_trans); + pipe->transfer_unmap(pipe, dst_trans); + + pipe->transfer_destroy(pipe, src_trans); + pipe->transfer_destroy(pipe, dst_trans); +} + + + +#define UBYTE_TO_USHORT(B) ((B) | ((B) << 8)) + + +/** + * Fallback for pipe->clear_render_target() function. + * XXX this looks too hackish to be really useful. + * cpp > 4 looks like a gross hack at best... + * Plus can't use these transfer fallbacks when clearing + * multisampled surfaces for instance. + */ +void +util_clear_render_target(struct pipe_context *pipe, + struct pipe_surface *dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct pipe_transfer *dst_trans; + void *dst_map; + union util_color uc; + + assert(dst->texture); + if (!dst->texture) + return; + /* XXX: should handle multiple layers */ + dst_trans = pipe_get_transfer(pipe, + dst->texture, + dst->u.tex.level, + dst->u.tex.first_layer, + PIPE_TRANSFER_WRITE, + dstx, dsty, width, height); + + dst_map = pipe->transfer_map(pipe, dst_trans); + + assert(dst_map); + + if (dst_map) { + assert(dst_trans->stride > 0); + + util_pack_color(rgba, dst->texture->format, &uc); + util_fill_rect(dst_map, dst->texture->format, + dst_trans->stride, + 0, 0, width, height, &uc); + } + + pipe->transfer_unmap(pipe, dst_trans); + pipe->transfer_destroy(pipe, dst_trans); +} + +/** + * Fallback for pipe->clear_stencil() function. + * sw fallback doesn't look terribly useful here. + * Plus can't use these transfer fallbacks when clearing + * multisampled surfaces for instance. + */ +void +util_clear_depth_stencil(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct pipe_transfer *dst_trans; + ubyte *dst_map; + boolean need_rmw = FALSE; + + if ((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) && + ((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) != PIPE_CLEAR_DEPTHSTENCIL) && + util_format_is_depth_and_stencil(dst->format)) + need_rmw = TRUE; + + assert(dst->texture); + if (!dst->texture) + return; + dst_trans = pipe_get_transfer(pipe, + dst->texture, + dst->u.tex.level, + dst->u.tex.first_layer, + (need_rmw ? PIPE_TRANSFER_READ_WRITE : + PIPE_TRANSFER_WRITE), + dstx, dsty, width, height); + + dst_map = pipe->transfer_map(pipe, dst_trans); + + assert(dst_map); + + if (dst_map) { + unsigned dst_stride = dst_trans->stride; + unsigned zstencil = util_pack_z_stencil(dst->texture->format, depth, stencil); + unsigned i, j; + assert(dst_trans->stride > 0); + + switch (util_format_get_blocksize(dst->format)) { + case 1: + assert(dst->format == PIPE_FORMAT_S8_USCALED); + if(dst_stride == width) + memset(dst_map, (ubyte) zstencil, height * width); + else { + for (i = 0; i < height; i++) { + memset(dst_map, (ubyte) zstencil, width); + dst_map += dst_stride; + } + } + break; + case 2: + assert(dst->format == PIPE_FORMAT_Z16_UNORM); + for (i = 0; i < height; i++) { + uint16_t *row = (uint16_t *)dst_map; + for (j = 0; j < width; j++) + *row++ = (uint16_t) zstencil; + dst_map += dst_stride; + } + break; + case 4: + if (!need_rmw) { + for (i = 0; i < height; i++) { + uint32_t *row = (uint32_t *)dst_map; + for (j = 0; j < width; j++) + *row++ = zstencil; + dst_map += dst_stride; + } + } + else { + uint32_t dst_mask; + if (dst->format == PIPE_FORMAT_Z24_UNORM_S8_USCALED) + dst_mask = 0xffffff00; + else { + assert(dst->format == PIPE_FORMAT_S8_USCALED_Z24_UNORM); + dst_mask = 0xffffff; + } + if (clear_flags & PIPE_CLEAR_DEPTH) + dst_mask = ~dst_mask; + for (i = 0; i < height; i++) { + uint32_t *row = (uint32_t *)dst_map; + for (j = 0; j < width; j++) { + uint32_t tmp = *row & dst_mask; + *row++ = tmp | (zstencil & ~dst_mask); + } + dst_map += dst_stride; + } + } + break; + case 8: + default: + assert(0); + break; + } + } + + pipe->transfer_unmap(pipe, dst_trans); + pipe->transfer_destroy(pipe, dst_trans); +} diff --git a/src/gallium/auxiliary/util/u_surface.h b/src/gallium/auxiliary/util/u_surface.h new file mode 100644 index 0000000..6a7cc82 --- /dev/null +++ b/src/gallium/auxiliary/util/u_surface.h @@ -0,0 +1,90 @@ +/************************************************************************** + * + * 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 U_SURFACE_H +#define U_SURFACE_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +extern void +u_surface_default_template(struct pipe_surface *view, + const struct pipe_resource *texture, + unsigned bind); + +extern boolean +util_create_rgba_surface(struct pipe_context *ctx, + uint width, uint height, uint bind, + struct pipe_resource **textureOut, + struct pipe_surface **surfaceOut); + + +extern void +util_destroy_rgba_surface(struct pipe_resource *texture, + struct pipe_surface *surface); + + + +extern void +util_resource_copy_region(struct pipe_context *pipe, + struct pipe_resource *dst, + unsigned dst_level, + unsigned dst_x, unsigned dst_y, unsigned dst_z, + struct pipe_resource *src, + unsigned src_level, + const struct pipe_box *src_box); + +extern void +util_clear_render_target(struct pipe_context *pipe, + struct pipe_surface *dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height); + +extern void +util_clear_depth_stencil(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height); + + +#ifdef __cplusplus +} +#endif + + +#endif /* U_SURFACE_H */ diff --git a/src/gallium/auxiliary/util/u_surfaces.c b/src/gallium/auxiliary/util/u_surfaces.c new file mode 100644 index 0000000..b0cfec2 --- /dev/null +++ b/src/gallium/auxiliary/util/u_surfaces.c @@ -0,0 +1,124 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "u_surfaces.h" +#include "util/u_hash_table.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" + +boolean +util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, + struct pipe_context *ctx, struct pipe_resource *pt, + unsigned level, unsigned layer, unsigned flags, + struct pipe_surface **res) +{ + struct pipe_surface *ps; + + if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE) + { /* or 2D array */ + if(!us->u.hash) + us->u.hash = cso_hash_create(); + + ps = cso_hash_iter_data(cso_hash_find(us->u.hash, (layer << 8) | level)); + } + else + { + if(!us->u.array) + us->u.array = CALLOC(pt->last_level + 1, sizeof(struct pipe_surface *)); + ps = us->u.array[level]; + } + + if(ps && ps->context == ctx) + { + p_atomic_inc(&ps->reference.count); + *res = ps; + return FALSE; + } + + ps = (struct pipe_surface *)CALLOC(1, surface_struct_size); + if(!ps) + { + *res = NULL; + return FALSE; + } + + pipe_surface_init(ctx, ps, pt, level, layer, flags); + + if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE) + cso_hash_insert(us->u.hash, (layer << 8) | level, ps); + else + us->u.array[level] = ps; + + *res = ps; + return TRUE; +} + +void +util_surfaces_do_detach(struct util_surfaces *us, struct pipe_surface *ps) +{ + struct pipe_resource *pt = ps->texture; + if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE) + { /* or 2D array */ + cso_hash_erase(us->u.hash, cso_hash_find(us->u.hash, (ps->u.tex.first_layer << 8) | ps->u.tex.level)); + } + else + us->u.array[ps->u.tex.level] = 0; +} + +void +util_surfaces_destroy(struct util_surfaces *us, struct pipe_resource *pt, void (*destroy_surface) (struct pipe_surface *)) +{ + if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE) + { /* or 2D array */ + if(us->u.hash) + { + struct cso_hash_iter iter; + iter = cso_hash_first_node(us->u.hash); + while (!cso_hash_iter_is_null(iter)) { + destroy_surface(cso_hash_iter_data(iter)); + iter = cso_hash_iter_next(iter); + } + + cso_hash_delete(us->u.hash); + us->u.hash = NULL; + } + } + else + { + if(us->u.array) + { + unsigned i; + for(i = 0; i <= pt->last_level; ++i) + { + struct pipe_surface *ps = us->u.array[i]; + if(ps) + destroy_surface(ps); + } + FREE(us->u.array); + us->u.array = NULL; + } + } +} diff --git a/src/gallium/auxiliary/util/u_surfaces.h b/src/gallium/auxiliary/util/u_surfaces.h new file mode 100644 index 0000000..9581fed --- /dev/null +++ b/src/gallium/auxiliary/util/u_surfaces.h @@ -0,0 +1,101 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef U_SURFACES_H_ +#define U_SURFACES_H_ + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "util/u_atomic.h" +#include "cso_cache/cso_hash.h" + +struct util_surfaces +{ + union + { + struct cso_hash *hash; + struct pipe_surface **array; + void* pv; + } u; +}; + +/* Return value indicates if the pipe surface result is new */ +boolean +util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, + struct pipe_context *ctx, struct pipe_resource *pt, + unsigned level, unsigned layer, unsigned flags, + struct pipe_surface **res); + +/* fast inline path for the very common case */ +static INLINE boolean +util_surfaces_get(struct util_surfaces *us, unsigned surface_struct_size, + struct pipe_context *ctx, struct pipe_resource *pt, + unsigned level, unsigned layer, unsigned flags, + struct pipe_surface **res) +{ + if(likely((pt->target == PIPE_TEXTURE_2D || pt->target == PIPE_TEXTURE_RECT) && us->u.array)) + { + struct pipe_surface *ps = us->u.array[level]; + if(ps && ps->context == ctx) + { + p_atomic_inc(&ps->reference.count); + *res = ps; + return FALSE; + } + } + + return util_surfaces_do_get(us, surface_struct_size, ctx, pt, level, layer, flags, res); +} + +static INLINE struct pipe_surface * +util_surfaces_peek(struct util_surfaces *us, struct pipe_resource *pt, unsigned level, unsigned layer) +{ + if(!us->u.pv) + return 0; + + if(unlikely(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)) + return cso_hash_iter_data(cso_hash_find(us->u.hash, (layer << 8) | level)); + else + return us->u.array[level]; +} + +void util_surfaces_do_detach(struct util_surfaces *us, struct pipe_surface *ps); + +static INLINE void +util_surfaces_detach(struct util_surfaces *us, struct pipe_surface *ps) +{ + if(likely(ps->texture->target == PIPE_TEXTURE_2D || ps->texture->target == PIPE_TEXTURE_RECT)) + { + us->u.array[ps->u.tex.level] = 0; + return; + } + + util_surfaces_do_detach(us, ps); +} + +void util_surfaces_destroy(struct util_surfaces *us, struct pipe_resource *pt, void (*destroy_surface) (struct pipe_surface *)); + +#endif diff --git a/src/gallium/auxiliary/util/u_texture.c b/src/gallium/auxiliary/util/u_texture.c new file mode 100644 index 0000000..d97e57a --- /dev/null +++ b/src/gallium/auxiliary/util/u_texture.c @@ -0,0 +1,103 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2008 VMware, Inc. All rights reserved. + * Copyright 2009 Marek Olšák + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Texture mapping utility functions. + * + * @author Brian Paul + * Marek Olšák + */ + +#include "pipe/p_defines.h" + +#include "util/u_debug.h" +#include "util/u_texture.h" + +void util_map_texcoords2d_onto_cubemap(unsigned face, + const float *in_st, unsigned in_stride, + float *out_str, unsigned out_stride) +{ + int i; + float rx, ry, rz; + + /* loop over quad verts */ + for (i = 0; i < 4; i++) { + /* Compute sc = +/-scale and tc = +/-scale. + * Not +/-1 to avoid cube face selection ambiguity near the edges, + * though that can still sometimes happen with this scale factor... + */ + const float scale = 0.9999f; + const float sc = (2 * in_st[0] - 1) * scale; + const float tc = (2 * in_st[1] - 1) * scale; + + switch (face) { + case PIPE_TEX_FACE_POS_X: + rx = 1; + ry = -tc; + rz = -sc; + break; + case PIPE_TEX_FACE_NEG_X: + rx = -1; + ry = -tc; + rz = sc; + break; + case PIPE_TEX_FACE_POS_Y: + rx = sc; + ry = 1; + rz = tc; + break; + case PIPE_TEX_FACE_NEG_Y: + rx = sc; + ry = -1; + rz = -tc; + break; + case PIPE_TEX_FACE_POS_Z: + rx = sc; + ry = -tc; + rz = 1; + break; + case PIPE_TEX_FACE_NEG_Z: + rx = -sc; + ry = -tc; + rz = -1; + break; + default: + rx = ry = rz = 0; + assert(0); + } + + out_str[0] = rx; /*s*/ + out_str[1] = ry; /*t*/ + out_str[2] = rz; /*r*/ + + in_st += in_stride; + out_str += out_stride; + } +} diff --git a/src/gallium/auxiliary/util/u_texture.h b/src/gallium/auxiliary/util/u_texture.h new file mode 100644 index 0000000..93b2f1e --- /dev/null +++ b/src/gallium/auxiliary/util/u_texture.h @@ -0,0 +1,54 @@ +/************************************************************************** + * + * Copyright 2009 Marek Olšák + * + * 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. + * + **************************************************************************/ + +#ifndef U_TEXTURE_H +#define U_TEXTURE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Convert 2D texture coordinates of 4 vertices into cubemap coordinates + * in the given face. + * Coordinates must be in the range [0,1]. + * + * \param face Cubemap face. + * \param in_st 4 pairs of 2D texture coordinates to convert. + * \param in_stride Stride of in_st in floats. + * \param out_str STR cubemap texture coordinates to compute. + * \param out_stride Stride of out_str in floats. + */ +void util_map_texcoords2d_onto_cubemap(unsigned face, + const float *in_st, unsigned in_stride, + float *out_str, unsigned out_stride); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c new file mode 100644 index 0000000..44cadbf --- /dev/null +++ b/src/gallium/auxiliary/util/u_tile.c @@ -0,0 +1,702 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * RGBA/float tile get/put functions. + * Usable both by drivers and state trackers. + */ + + +#include "pipe/p_defines.h" +#include "util/u_inlines.h" + +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_rect.h" +#include "util/u_tile.h" + + +/** + * Move raw block of pixels from transfer object to user memory. + */ +void +pipe_get_tile_raw(struct pipe_context *pipe, + struct pipe_transfer *pt, + uint x, uint y, uint w, uint h, + void *dst, int dst_stride) +{ + const void *src; + + if (dst_stride == 0) + dst_stride = util_format_get_stride(pt->resource->format, w); + + if (u_clip_tile(x, y, &w, &h, &pt->box)) + return; + + src = pipe->transfer_map(pipe, pt); + assert(src); + if(!src) + return; + + util_copy_rect(dst, pt->resource->format, dst_stride, 0, 0, w, h, src, pt->stride, x, y); + + pipe->transfer_unmap(pipe, pt); +} + + +/** + * Move raw block of pixels from user memory to transfer object. + */ +void +pipe_put_tile_raw(struct pipe_context *pipe, + struct pipe_transfer *pt, + uint x, uint y, uint w, uint h, + const void *src, int src_stride) +{ + void *dst; + enum pipe_format format = pt->resource->format; + + if (src_stride == 0) + src_stride = util_format_get_stride(format, w); + + if (u_clip_tile(x, y, &w, &h, &pt->box)) + return; + + dst = pipe->transfer_map(pipe, pt); + assert(dst); + if(!dst) + return; + + util_copy_rect(dst, format, pt->stride, x, y, w, h, src, src_stride, 0, 0); + + pipe->transfer_unmap(pipe, pt); +} + + + + +/** Convert short in [-32768,32767] to GLfloat in [-1.0,1.0] */ +#define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)) + +#define UNCLAMPED_FLOAT_TO_SHORT(us, f) \ + us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) ) + + + +/*** PIPE_FORMAT_Z16_UNORM ***/ + +/** + * Return each Z value as four floats in [0,1]. + */ +static void +z16_get_tile_rgba(const ushort *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) +{ + const float scale = 1.0f / 65535.0f; + unsigned i, j; + + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = *src++ * scale; + } + p += dst_stride; + } +} + + + + +/*** PIPE_FORMAT_Z32_UNORM ***/ + +/** + * Return each Z value as four floats in [0,1]. + */ +static void +z32_get_tile_rgba(const unsigned *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) +{ + const double scale = 1.0 / (double) 0xffffffff; + unsigned i, j; + + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = (float) (*src++ * scale); + } + p += dst_stride; + } +} + + +/*** PIPE_FORMAT_Z24_UNORM_S8_USCALED ***/ + +/** + * Return Z component as four float in [0,1]. Stencil part ignored. + */ +static void +s8z24_get_tile_rgba(const unsigned *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) +{ + const double scale = 1.0 / ((1 << 24) - 1); + unsigned i, j; + + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = (float) (scale * (*src++ & 0xffffff)); + } + p += dst_stride; + } +} + + +/*** PIPE_FORMAT_S8_USCALED_Z24_UNORM ***/ + +/** + * Return Z component as four float in [0,1]. Stencil part ignored. + */ +static void +z24s8_get_tile_rgba(const unsigned *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) +{ + const double scale = 1.0 / ((1 << 24) - 1); + unsigned i, j; + + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = (float) (scale * (*src++ >> 8)); + } + p += dst_stride; + } +} + +/*** PIPE_FORMAT_S8X24_USCALED ***/ + +/** + * Return S component as four uint32_t in [0..255]. Z part ignored. + */ +static void +s8x24_get_tile_rgba(const unsigned *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) +{ + unsigned i, j; + + for (i = 0; i < h; i++) { + float *pRow = p; + + for (j = 0; j < w; j++, pRow += 4) { + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = (float)((*src++ >> 24) & 0xff); + } + + p += dst_stride; + } +} + +/*** PIPE_FORMAT_X24S8_USCALED ***/ + +/** + * Return S component as four uint32_t in [0..255]. Z part ignored. + */ +static void +x24s8_get_tile_rgba(const unsigned *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) +{ + unsigned i, j; + + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = (float)(*src++ & 0xff); + } + p += dst_stride; + } +} + + +/** + * Return S component as four uint32_t in [0..255]. Z part ignored. + */ +static void +s8_get_tile_rgba(const unsigned char *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) +{ + unsigned i, j; + + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = (float)(*src++ & 0xff); + } + p += dst_stride; + } +} + +/*** PIPE_FORMAT_Z32_FLOAT ***/ + +/** + * Return each Z value as four floats in [0,1]. + */ +static void +z32f_get_tile_rgba(const float *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) +{ + unsigned i, j; + + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = *src++; + } + p += dst_stride; + } +} + + +void +pipe_tile_raw_to_rgba(enum pipe_format format, + void *src, + uint w, uint h, + float *dst, unsigned dst_stride) +{ + switch (format) { + case PIPE_FORMAT_Z16_UNORM: + z16_get_tile_rgba((ushort *) src, w, h, dst, dst_stride); + break; + case PIPE_FORMAT_Z32_UNORM: + z32_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); + break; + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + case PIPE_FORMAT_Z24X8_UNORM: + s8z24_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); + break; + case PIPE_FORMAT_S8_USCALED: + s8_get_tile_rgba((unsigned char *) src, w, h, dst, dst_stride); + break; + case PIPE_FORMAT_X24S8_USCALED: + s8x24_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); + break; + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: + z24s8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); + break; + case PIPE_FORMAT_S8X24_USCALED: + x24s8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); + break; + case PIPE_FORMAT_Z32_FLOAT: + z32f_get_tile_rgba((float *) src, w, h, dst, dst_stride); + break; + default: + util_format_read_4f(format, + dst, dst_stride * sizeof(float), + src, util_format_get_stride(format, w), + 0, 0, w, h); + } +} + + +void +pipe_get_tile_rgba(struct pipe_context *pipe, + struct pipe_transfer *pt, + uint x, uint y, uint w, uint h, + float *p) +{ + unsigned dst_stride = w * 4; + void *packed; + enum pipe_format format = pt->resource->format; + + if (u_clip_tile(x, y, &w, &h, &pt->box)) + return; + + packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format)); + + if (!packed) + return; + + if(format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) + assert((x & 1) == 0); + + pipe_get_tile_raw(pipe, pt, x, y, w, h, packed, 0); + + pipe_tile_raw_to_rgba(format, packed, w, h, p, dst_stride); + + FREE(packed); +} + + +void +pipe_get_tile_swizzle(struct pipe_context *pipe, + struct pipe_transfer *pt, + uint x, + uint y, + uint w, + uint h, + uint swizzle_r, + uint swizzle_g, + uint swizzle_b, + uint swizzle_a, + enum pipe_format format, + float *p) +{ + unsigned dst_stride = w * 4; + void *packed; + uint iy; + float rgba01[6]; + + if (u_clip_tile(x, y, &w, &h, &pt->box)) { + return; + } + + packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format)); + if (!packed) { + return; + } + + if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) { + assert((x & 1) == 0); + } + + pipe_get_tile_raw(pipe, pt, x, y, w, h, packed, 0); + + pipe_tile_raw_to_rgba(format, packed, w, h, p, dst_stride); + + FREE(packed); + + if (swizzle_r == PIPE_SWIZZLE_RED && + swizzle_g == PIPE_SWIZZLE_GREEN && + swizzle_b == PIPE_SWIZZLE_BLUE && + swizzle_a == PIPE_SWIZZLE_ALPHA) { + /* no-op, skip */ + return; + } + + rgba01[PIPE_SWIZZLE_ZERO] = 0.0f; + rgba01[PIPE_SWIZZLE_ONE] = 1.0f; + + for (iy = 0; iy < h; iy++) { + float *row = p; + uint ix; + + for (ix = 0; ix < w; ix++) { + rgba01[PIPE_SWIZZLE_RED] = row[0]; + rgba01[PIPE_SWIZZLE_GREEN] = row[1]; + rgba01[PIPE_SWIZZLE_BLUE] = row[2]; + rgba01[PIPE_SWIZZLE_ALPHA] = row[3]; + + *row++ = rgba01[swizzle_r]; + *row++ = rgba01[swizzle_g]; + *row++ = rgba01[swizzle_b]; + *row++ = rgba01[swizzle_a]; + } + p += dst_stride; + } +} + + +void +pipe_put_tile_rgba(struct pipe_context *pipe, + struct pipe_transfer *pt, + uint x, uint y, uint w, uint h, + const float *p) +{ + unsigned src_stride = w * 4; + void *packed; + enum pipe_format format = pt->resource->format; + + if (u_clip_tile(x, y, &w, &h, &pt->box)) + return; + + packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format)); + + if (!packed) + return; + + switch (format) { + case PIPE_FORMAT_Z16_UNORM: + /*z16_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/ + break; + case PIPE_FORMAT_Z32_UNORM: + /*z32_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/ + break; + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + case PIPE_FORMAT_Z24X8_UNORM: + /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/ + break; + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: + /*z24s8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/ + break; + default: + util_format_write_4f(format, + p, src_stride * sizeof(float), + packed, util_format_get_stride(format, w), + 0, 0, w, h); + } + + pipe_put_tile_raw(pipe, pt, x, y, w, h, packed, 0); + + FREE(packed); +} + + +/** + * Get a block of Z values, converted to 32-bit range. + */ +void +pipe_get_tile_z(struct pipe_context *pipe, + struct pipe_transfer *pt, + uint x, uint y, uint w, uint h, + uint *z) +{ + const uint dstStride = w; + ubyte *map; + uint *pDest = z; + uint i, j; + enum pipe_format format = pt->resource->format; + + if (u_clip_tile(x, y, &w, &h, &pt->box)) + return; + + map = (ubyte *)pipe->transfer_map(pipe, pt); + if (!map) { + assert(0); + return; + } + + switch (format) { + case PIPE_FORMAT_Z32_UNORM: + { + const uint *ptrc + = (const uint *)(map + y * pt->stride + x*4); + for (i = 0; i < h; i++) { + memcpy(pDest, ptrc, 4 * w); + pDest += dstStride; + ptrc += pt->stride/4; + } + } + break; + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + case PIPE_FORMAT_Z24X8_UNORM: + { + const uint *ptrc + = (const uint *)(map + y * pt->stride + x*4); + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + /* convert 24-bit Z to 32-bit Z */ + pDest[j] = (ptrc[j] << 8) | ((ptrc[j] >> 16) & 0xff); + } + pDest += dstStride; + ptrc += pt->stride/4; + } + } + break; + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: + { + const uint *ptrc + = (const uint *)(map + y * pt->stride + x*4); + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + /* convert 24-bit Z to 32-bit Z */ + pDest[j] = (ptrc[j] & 0xffffff00) | ((ptrc[j] >> 24) & 0xff); + } + pDest += dstStride; + ptrc += pt->stride/4; + } + } + break; + case PIPE_FORMAT_Z16_UNORM: + { + const ushort *ptrc + = (const ushort *)(map + y * pt->stride + x*2); + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + /* convert 16-bit Z to 32-bit Z */ + pDest[j] = (ptrc[j] << 16) | ptrc[j]; + } + pDest += dstStride; + ptrc += pt->stride/2; + } + } + break; + default: + assert(0); + } + + pipe->transfer_unmap(pipe, pt); +} + + +void +pipe_put_tile_z(struct pipe_context *pipe, + struct pipe_transfer *pt, + uint x, uint y, uint w, uint h, + const uint *zSrc) +{ + const uint srcStride = w; + const uint *ptrc = zSrc; + ubyte *map; + uint i, j; + enum pipe_format format = pt->resource->format; + + if (u_clip_tile(x, y, &w, &h, &pt->box)) + return; + + map = (ubyte *)pipe->transfer_map(pipe, pt); + if (!map) { + assert(0); + return; + } + + switch (format) { + case PIPE_FORMAT_Z32_UNORM: + { + uint *pDest = (uint *) (map + y * pt->stride + x*4); + for (i = 0; i < h; i++) { + memcpy(pDest, ptrc, 4 * w); + pDest += pt->stride/4; + ptrc += srcStride; + } + } + break; + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + { + uint *pDest = (uint *) (map + y * pt->stride + x*4); + /*assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);*/ + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + /* convert 32-bit Z to 24-bit Z, preserve stencil */ + pDest[j] = (pDest[j] & 0xff000000) | ptrc[j] >> 8; + } + pDest += pt->stride/4; + ptrc += srcStride; + } + } + break; + case PIPE_FORMAT_Z24X8_UNORM: + { + uint *pDest = (uint *) (map + y * pt->stride + x*4); + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + /* convert 32-bit Z to 24-bit Z (0 stencil) */ + pDest[j] = ptrc[j] >> 8; + } + pDest += pt->stride/4; + ptrc += srcStride; + } + } + break; + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + { + uint *pDest = (uint *) (map + y * pt->stride + x*4); + /*assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);*/ + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + /* convert 32-bit Z to 24-bit Z, preserve stencil */ + pDest[j] = (pDest[j] & 0xff) | (ptrc[j] & 0xffffff00); + } + pDest += pt->stride/4; + ptrc += srcStride; + } + } + break; + case PIPE_FORMAT_X8Z24_UNORM: + { + uint *pDest = (uint *) (map + y * pt->stride + x*4); + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + /* convert 32-bit Z to 24-bit Z (0 stencil) */ + pDest[j] = ptrc[j] & 0xffffff00; + } + pDest += pt->stride/4; + ptrc += srcStride; + } + } + break; + case PIPE_FORMAT_Z16_UNORM: + { + ushort *pDest = (ushort *) (map + y * pt->stride + x*2); + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + /* convert 32-bit Z to 16-bit Z */ + pDest[j] = ptrc[j] >> 16; + } + pDest += pt->stride/2; + ptrc += srcStride; + } + } + break; + default: + assert(0); + } + + pipe->transfer_unmap(pipe, pt); +} + + diff --git a/src/gallium/auxiliary/util/u_tile.h b/src/gallium/auxiliary/util/u_tile.h new file mode 100644 index 0000000..558351d --- /dev/null +++ b/src/gallium/auxiliary/util/u_tile.h @@ -0,0 +1,126 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef P_TILE_H +#define P_TILE_H + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" + +struct pipe_context; +struct pipe_transfer; + +/** + * Clip tile against transfer dims. + * + * XXX: this only clips width and height! + * + * \return TRUE if tile is totally clipped, FALSE otherwise + */ +static INLINE boolean +u_clip_tile(uint x, uint y, uint *w, uint *h, const struct pipe_box *box) +{ + if (x >= box->width) + return TRUE; + if (y >= box->height) + return TRUE; + if (x + *w > box->width) + *w = box->width - x; + if (y + *h > box->height) + *h = box->height - y; + return FALSE; +} + +#ifdef __cplusplus +extern "C" { +#endif + +void +pipe_get_tile_raw(struct pipe_context *pipe, + struct pipe_transfer *pt, + uint x, uint y, uint w, uint h, + void *p, int dst_stride); + +void +pipe_put_tile_raw(struct pipe_context *pipe, + struct pipe_transfer *pt, + uint x, uint y, uint w, uint h, + const void *p, int src_stride); + + +void +pipe_get_tile_rgba(struct pipe_context *pipe, + struct pipe_transfer *pt, + uint x, uint y, uint w, uint h, + float *p); + +void +pipe_get_tile_swizzle(struct pipe_context *pipe, + struct pipe_transfer *pt, + uint x, + uint y, + uint w, + uint h, + uint swizzle_r, + uint swizzle_g, + uint swizzle_b, + uint swizzle_a, + enum pipe_format format, + float *p); + +void +pipe_put_tile_rgba(struct pipe_context *pipe, + struct pipe_transfer *pt, + uint x, uint y, uint w, uint h, + const float *p); + + +void +pipe_get_tile_z(struct pipe_context *pipe, + struct pipe_transfer *pt, + uint x, uint y, uint w, uint h, + uint *z); + +void +pipe_put_tile_z(struct pipe_context *pipe, + struct pipe_transfer *pt, + uint x, uint y, uint w, uint h, + const uint *z); + +void +pipe_tile_raw_to_rgba(enum pipe_format format, + void *src, + uint w, uint h, + float *dst, unsigned dst_stride); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/auxiliary/util/u_time.h b/src/gallium/auxiliary/util/u_time.h new file mode 100644 index 0000000..15899c2 --- /dev/null +++ b/src/gallium/auxiliary/util/u_time.h @@ -0,0 +1,150 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * OS independent time-manipulation functions. + * + * @author Jose Fonseca + */ + +#ifndef U_TIME_H_ +#define U_TIME_H_ + + +#include "pipe/p_config.h" + +#include "os/os_time.h" + +#include "pipe/p_compiler.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Time abstraction. + * + * Do not access this structure directly. Use the provided function instead. + */ +struct util_time +{ + int64_t counter; +}; + + +PIPE_DEPRECATED +static INLINE void +util_time_get(struct util_time *t) +{ + t->counter = os_time_get(); +} + + +/** + * Return t2 = t1 + usecs + */ +PIPE_DEPRECATED +static INLINE void +util_time_add(const struct util_time *t1, + int64_t usecs, + struct util_time *t2) +{ + t2->counter = t1->counter + usecs; +} + + +/** + * Return difference between times, in microseconds + */ +PIPE_DEPRECATED +static INLINE int64_t +util_time_diff(const struct util_time *t1, + const struct util_time *t2) +{ + return t2->counter - t1->counter; +} + + +/** + * Compare two time values. + * + * Not publicly available because it does not take in account wrap-arounds. + * Use util_time_timeout instead. + */ +static INLINE int +_util_time_compare(const struct util_time *t1, + const struct util_time *t2) +{ + if (t1->counter < t2->counter) + return -1; + else if(t1->counter > t2->counter) + return 1; + else + return 0; +} + + +/** + * Returns non-zero when the timeout expires. + */ +PIPE_DEPRECATED +static INLINE boolean +util_time_timeout(const struct util_time *start, + const struct util_time *end, + const struct util_time *curr) +{ + return os_time_timeout(start->counter, end->counter, curr->counter); +} + + +/** + * Return current time in microseconds + */ +PIPE_DEPRECATED +static INLINE int64_t +util_time_micros(void) +{ + return os_time_get(); +} + + +PIPE_DEPRECATED +static INLINE void +util_time_sleep(int64_t usecs) +{ + os_time_sleep(usecs); +} + + +#ifdef __cplusplus +} +#endif + +#endif /* U_TIME_H_ */ diff --git a/src/gallium/auxiliary/util/u_transfer.c b/src/gallium/auxiliary/util/u_transfer.c new file mode 100644 index 0000000..e2828cf --- /dev/null +++ b/src/gallium/auxiliary/util/u_transfer.c @@ -0,0 +1,114 @@ +#include "pipe/p_context.h" +#include "util/u_rect.h" +#include "util/u_inlines.h" +#include "util/u_transfer.h" +#include "util/u_memory.h" + +/* One-shot transfer operation with data supplied in a user + * pointer. XXX: strides?? + */ +void u_default_transfer_inline_write( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride) +{ + struct pipe_transfer *transfer = NULL; + uint8_t *map = NULL; + const uint8_t *src_data = data; + unsigned i; + + transfer = pipe->get_transfer(pipe, + resource, + level, + usage, + box ); + if (transfer == NULL) + goto out; + + map = pipe_transfer_map(pipe, transfer); + if (map == NULL) + goto out; + + for (i = 0; i < box->depth; i++) { + util_copy_rect(map, + resource->format, + transfer->stride, /* bytes */ + 0, 0, + box->width, + box->height, + src_data, + stride, /* bytes */ + 0, 0); + map += transfer->layer_stride; + src_data += layer_stride; + } + +out: + if (map) + pipe_transfer_unmap(pipe, transfer); + + if (transfer) + pipe_transfer_destroy(pipe, transfer); +} + + +boolean u_default_resource_get_handle(struct pipe_screen *screen, + struct pipe_resource *resource, + struct winsys_handle *handle) +{ + return FALSE; +} + + + +void u_default_transfer_flush_region( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box) +{ + /* This is a no-op implementation, nothing to do. + */ +} + +unsigned u_default_is_resource_referenced( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, int layer) +{ + return 0; +} + +struct pipe_transfer * u_default_get_transfer(struct pipe_context *context, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct pipe_transfer *transfer = CALLOC_STRUCT(pipe_transfer); + if (transfer == NULL) + return NULL; + + transfer->resource = resource; + transfer->level = level; + transfer->usage = usage; + transfer->box = *box; + + /* Note strides are zero, this is ok for buffers, but not for + * textures 2d & higher at least. + */ + return transfer; +} + +void u_default_transfer_unmap( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ +} + +void u_default_transfer_destroy(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + FREE(transfer); +} + diff --git a/src/gallium/auxiliary/util/u_transfer.h b/src/gallium/auxiliary/util/u_transfer.h new file mode 100644 index 0000000..3412e13 --- /dev/null +++ b/src/gallium/auxiliary/util/u_transfer.h @@ -0,0 +1,146 @@ + +#ifndef U_TRANSFER_H +#define U_TRANSFER_H + +/* Fallback implementations for inline read/writes which just go back + * to the regular transfer behaviour. + */ +#include "pipe/p_state.h" + +struct pipe_context; +struct winsys_handle; + +boolean u_default_resource_get_handle(struct pipe_screen *screen, + struct pipe_resource *resource, + struct winsys_handle *handle); + +void u_default_transfer_inline_write( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride); + +void u_default_transfer_flush_region( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box); + +unsigned u_default_is_resource_referenced( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, int layer); + +struct pipe_transfer * u_default_get_transfer(struct pipe_context *context, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box); + +void u_default_transfer_unmap( struct pipe_context *pipe, + struct pipe_transfer *transfer ); + +void u_default_transfer_destroy(struct pipe_context *pipe, + struct pipe_transfer *transfer); + + + +/* Useful helper to allow >1 implementation of resource functionality + * to exist in a single driver. This is intended to be transitionary! + */ +struct u_resource_vtbl { + + boolean (*resource_get_handle)(struct pipe_screen *, + struct pipe_resource *tex, + struct winsys_handle *handle); + + void (*resource_destroy)(struct pipe_screen *, + struct pipe_resource *pt); + + unsigned (*is_resource_referenced)(struct pipe_context *pipe, + struct pipe_resource *texture, + unsigned level, int layer); + + struct pipe_transfer *(*get_transfer)(struct pipe_context *, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *); + + void (*transfer_destroy)(struct pipe_context *, + struct pipe_transfer *); + + void *(*transfer_map)( struct pipe_context *, + struct pipe_transfer *transfer ); + + void (*transfer_flush_region)( struct pipe_context *, + struct pipe_transfer *transfer, + const struct pipe_box *); + + void (*transfer_unmap)( struct pipe_context *, + struct pipe_transfer *transfer ); + + void (*transfer_inline_write)( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride); +}; + + +struct u_resource { + struct pipe_resource b; + struct u_resource_vtbl *vtbl; +}; + + +boolean u_resource_get_handle_vtbl(struct pipe_screen *screen, + struct pipe_resource *resource, + struct winsys_handle *handle); + +void u_resource_destroy_vtbl(struct pipe_screen *screen, + struct pipe_resource *resource); + +unsigned u_is_resource_referenced_vtbl( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, int layer); + +struct pipe_transfer *u_get_transfer_vtbl(struct pipe_context *context, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box); + +void u_transfer_destroy_vtbl(struct pipe_context *pipe, + struct pipe_transfer *transfer); + +void *u_transfer_map_vtbl( struct pipe_context *pipe, + struct pipe_transfer *transfer ); + +void u_transfer_flush_region_vtbl( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box); + +void u_transfer_unmap_vtbl( struct pipe_context *rm_ctx, + struct pipe_transfer *transfer ); + +void u_transfer_inline_write_vtbl( struct pipe_context *rm_ctx, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride); + + + + + + + + +#endif diff --git a/src/gallium/auxiliary/util/u_upload_mgr.c b/src/gallium/auxiliary/util/u_upload_mgr.c new file mode 100644 index 0000000..af229e6 --- /dev/null +++ b/src/gallium/auxiliary/util/u_upload_mgr.c @@ -0,0 +1,249 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/* Helper utility for uploading user buffers & other data, and + * coalescing small buffers into larger ones. + */ + +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "pipe/p_context.h" +#include "util/u_memory.h" +#include "util/u_math.h" + +#include "u_upload_mgr.h" + + +struct u_upload_mgr { + struct pipe_context *pipe; + + unsigned default_size; + unsigned alignment; + unsigned usage; + + /* The active buffer: + */ + struct pipe_resource *buffer; + unsigned size; + unsigned offset; +}; + + +struct u_upload_mgr *u_upload_create( struct pipe_context *pipe, + unsigned default_size, + unsigned alignment, + unsigned usage ) +{ + struct u_upload_mgr *upload = CALLOC_STRUCT( u_upload_mgr ); + if (!upload) + return NULL; + + upload->pipe = pipe; + upload->default_size = default_size; + upload->alignment = alignment; + upload->usage = usage; + upload->buffer = NULL; + + return upload; +} + +/* Slightly specialized version of buffer_write designed to maximize + * chances of the driver consolidating successive writes into a single + * upload. + * + * dirty_size may be slightly greater than size to cope with + * alignment. We don't want to leave holes between succesively mapped + * regions as that may prevent the driver from consolidating uploads. + * + * Note that the 'data' pointer has probably come from the application + * and we cannot read even a byte past its end without risking + * segfaults, or at least complaints from valgrind.. + */ +static INLINE enum pipe_error +my_buffer_write(struct pipe_context *pipe, + struct pipe_resource *buf, + unsigned offset, unsigned size, unsigned dirty_size, + const void *data) +{ + struct pipe_transfer *transfer = NULL; + uint8_t *map; + + assert(offset < buf->width0); + assert(offset + size <= buf->width0); + assert(dirty_size >= size); + assert(size); + + map = pipe_buffer_map_range(pipe, buf, offset, dirty_size, + PIPE_TRANSFER_WRITE | + PIPE_TRANSFER_FLUSH_EXPLICIT | + PIPE_TRANSFER_DISCARD | + PIPE_TRANSFER_UNSYNCHRONIZED, + &transfer); + if (map == NULL) + return PIPE_ERROR_OUT_OF_MEMORY; + + memcpy(map + offset, data, size); + pipe_buffer_flush_mapped_range(pipe, transfer, offset, dirty_size); + pipe_buffer_unmap(pipe, buf, transfer); + + return PIPE_OK; +} + +/* Release old buffer. + * + * This must usually be called prior to firing the command stream + * which references the upload buffer, as many memory managers will + * cause subsequent maps of a fired buffer to wait. + * + * Can improve this with a change to pipe_buffer_write to use the + * DONT_WAIT bit, but for now, it's easiest just to grab a new buffer. + */ +void u_upload_flush( struct u_upload_mgr *upload ) +{ + pipe_resource_reference( &upload->buffer, NULL ); + upload->size = 0; +} + + +void u_upload_destroy( struct u_upload_mgr *upload ) +{ + u_upload_flush( upload ); + FREE( upload ); +} + + +static enum pipe_error +u_upload_alloc_buffer( struct u_upload_mgr *upload, + unsigned min_size ) +{ + unsigned size; + + /* Release old buffer, if present: + */ + u_upload_flush( upload ); + + /* Allocate a new one: + */ + size = align(MAX2(upload->default_size, min_size), 4096); + + upload->buffer = pipe_buffer_create( upload->pipe->screen, + upload->usage, + size ); + if (upload->buffer == NULL) + goto fail; + + upload->size = size; + + upload->offset = 0; + return 0; + +fail: + if (upload->buffer) + pipe_resource_reference( &upload->buffer, NULL ); + + return PIPE_ERROR_OUT_OF_MEMORY; +} + + +enum pipe_error u_upload_data( struct u_upload_mgr *upload, + unsigned size, + const void *data, + unsigned *out_offset, + struct pipe_resource **outbuf ) +{ + unsigned alloc_size = align( size, upload->alignment ); + enum pipe_error ret = PIPE_OK; + + if (upload->offset + alloc_size > upload->size) { + ret = u_upload_alloc_buffer( upload, alloc_size ); + if (ret) + return ret; + } + + /* Copy the data, using map_range if available: + */ + ret = my_buffer_write( upload->pipe, + upload->buffer, + upload->offset, + size, + alloc_size, + data ); + if (ret) + return ret; + + /* Emit the return values: + */ + pipe_resource_reference( outbuf, upload->buffer ); + *out_offset = upload->offset; + upload->offset += alloc_size; + return PIPE_OK; +} + + +/* As above, but upload the full contents of a buffer. Useful for + * uploading user buffers, avoids generating an explosion of GPU + * buffers if you have an app that does lots of small vertex buffer + * renders or DrawElements calls. + */ +enum pipe_error u_upload_buffer( struct u_upload_mgr *upload, + unsigned offset, + unsigned size, + struct pipe_resource *inbuf, + unsigned *out_offset, + struct pipe_resource **outbuf ) +{ + enum pipe_error ret = PIPE_OK; + struct pipe_transfer *transfer = NULL; + const char *map = NULL; + + map = (const char *)pipe_buffer_map(upload->pipe, + inbuf, + PIPE_TRANSFER_READ, + &transfer); + + if (map == NULL) { + ret = PIPE_ERROR_OUT_OF_MEMORY; + goto done; + } + + if (0) + debug_printf("upload ptr %p ofs %d sz %d\n", map, offset, size); + + ret = u_upload_data( upload, + size, + map + offset, + out_offset, + outbuf ); + if (ret) + goto done; + +done: + if (map) + pipe_buffer_unmap( upload->pipe, inbuf, transfer ); + + return ret; +} diff --git a/src/gallium/auxiliary/util/u_upload_mgr.h b/src/gallium/auxiliary/util/u_upload_mgr.h new file mode 100644 index 0000000..de016df --- /dev/null +++ b/src/gallium/auxiliary/util/u_upload_mgr.h @@ -0,0 +1,74 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/* Helper utility for uploading user buffers & other data, and + * coalescing small buffers into larger ones. + */ + +#ifndef U_UPLOAD_MGR_H +#define U_UPLOAD_MGR_H + +struct pipe_context; +struct pipe_resource; + + +struct u_upload_mgr *u_upload_create( struct pipe_context *pipe, + unsigned default_size, + unsigned alignment, + unsigned usage ); + +void u_upload_destroy( struct u_upload_mgr *upload ); + +/* Unmap and release old buffer. + * + * This must usually be called prior to firing the command stream + * which references the upload buffer, as many memory managers either + * don't like firing a mapped buffer or cause subsequent maps of a + * fired buffer to wait. For now, it's easiest just to grab a new + * buffer. + */ +void u_upload_flush( struct u_upload_mgr *upload ); + + +enum pipe_error u_upload_data( struct u_upload_mgr *upload, + unsigned size, + const void *data, + unsigned *out_offset, + struct pipe_resource **outbuf ); + + +enum pipe_error u_upload_buffer( struct u_upload_mgr *upload, + unsigned offset, + unsigned size, + struct pipe_resource *inbuf, + unsigned *out_offset, + struct pipe_resource **outbuf ); + + + +#endif + diff --git a/src/gallium/docs/Makefile b/src/gallium/docs/Makefile new file mode 100644 index 0000000..d4a5be4 --- /dev/null +++ b/src/gallium/docs/Makefile @@ -0,0 +1,89 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = build + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source + +.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + -rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Gallium.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Gallium.qhc" + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \ + "run these through (pdf)latex." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." diff --git a/src/gallium/docs/source/conf.py b/src/gallium/docs/source/conf.py new file mode 100644 index 0000000..0846e7d --- /dev/null +++ b/src/gallium/docs/source/conf.py @@ -0,0 +1,197 @@ +# -*- coding: utf-8 -*- +# +# Gallium documentation build configuration file, created by +# sphinx-quickstart on Sun Dec 20 14:09:05 2009. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys, os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.append(os.path.abspath('exts')) + +# -- General configuration ----------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.pngmath', 'formatting'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'Gallium' +copyright = u'2009, VMware, X.org, Nouveau' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '0.4' +# The full version, including alpha/beta/rc tags. +release = '0.4' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of documents that shouldn't be included in the build. +#unused_docs = [] + +# List of directories, relative to source directory, that shouldn't be searched +# for source files. +exclude_trees = [] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# The language for highlighting source code. +highlight_language = 'c' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. Major themes that come with +# Sphinx are currently 'default' and 'sphinxdoc'. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_use_modindex = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = '' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'Galliumdoc' + + +# -- Options for LaTeX output -------------------------------------------------- + +# The paper size ('letter' or 'a4'). +#latex_paper_size = 'letter' + +# The font size ('10pt', '11pt' or '12pt'). +#latex_font_size = '10pt' + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ('index', 'Gallium.tex', u'Gallium Documentation', + u'VMware, X.org, Nouveau', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# Additional stuff for the LaTeX preamble. +#latex_preamble = '' + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_use_modindex = True diff --git a/src/gallium/docs/source/exts/formatting.py b/src/gallium/docs/source/exts/formatting.py new file mode 100644 index 0000000..14865f3 --- /dev/null +++ b/src/gallium/docs/source/exts/formatting.py @@ -0,0 +1,31 @@ +# formatting.py +# Sphinx extension providing formatting for Gallium-specific data +# (c) Corbin Simpson 2010 +# Public domain to the extent permitted; contact author for special licensing + +import docutils.nodes +import sphinx.addnodes + +def parse_envvar(env, sig, signode): + envvar, t, default = sig.split(" ", 2) + envvar = envvar.strip().upper() + t = " Type: %s" % t.strip(" <>").lower() + default = " Default: %s" % default.strip(" ()") + signode += sphinx.addnodes.desc_name(envvar, envvar) + signode += sphinx.addnodes.desc_type(t, t) + signode += sphinx.addnodes.desc_annotation(default, default) + return envvar + +def parse_opcode(env, sig, signode): + opcode, desc = sig.split("-", 1) + opcode = opcode.strip().upper() + desc = " (%s)" % desc.strip() + signode += sphinx.addnodes.desc_name(opcode, opcode) + signode += sphinx.addnodes.desc_annotation(desc, desc) + return opcode + +def setup(app): + app.add_description_unit("envvar", "envvar", "%s (environment variable)", + parse_envvar) + app.add_description_unit("opcode", "opcode", "%s (TGSI opcode)", + parse_opcode) diff --git a/src/gallium/drivers/Makefile b/src/gallium/drivers/Makefile new file mode 100644 index 0000000..9fe9b2c --- /dev/null +++ b/src/gallium/drivers/Makefile @@ -0,0 +1,12 @@ +# src/gallium/drivers/Makefile +TOP = ../../.. +include $(TOP)/configs/current + +SUBDIRS = $(GALLIUM_DRIVERS_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/drivers/cell/Makefile b/src/gallium/drivers/cell/Makefile new file mode 100644 index 0000000..47aef7b --- /dev/null +++ b/src/gallium/drivers/cell/Makefile @@ -0,0 +1,12 @@ +# Cell Gallium driver Makefile + + +default: + ( cd spu ; make ) + ( cd ppu ; make ) + + + +clean: + ( cd spu ; make clean ) + ( cd ppu ; make clean ) diff --git a/src/gallium/drivers/cell/common.h b/src/gallium/drivers/cell/common.h new file mode 100644 index 0000000..a8cdde3 --- /dev/null +++ b/src/gallium/drivers/cell/common.h @@ -0,0 +1,377 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Types and tokens which are common to the SPU and PPU code. + */ + + +#ifndef CELL_COMMON_H +#define CELL_COMMON_H + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include + +/** The standard assert macro doesn't seem to work reliably */ +#define ASSERT(x) \ + if (!(x)) { \ + ubyte *p = NULL; \ + fprintf(stderr, "%s:%d: %s(): assertion %s failed.\n", \ + __FILE__, __LINE__, __FUNCTION__, #x); \ + *p = 0; \ + exit(1); \ + } + + +#define JOIN(x, y) JOIN_AGAIN(x, y) +#define JOIN_AGAIN(x, y) x ## y + +#define STATIC_ASSERT(e) \ +{typedef char JOIN(assertion_failed_at_line_, __LINE__) [(e) ? 1 : -1];} + + + +/** for sanity checking */ +#define ASSERT_ALIGN16(ptr) \ + ASSERT((((unsigned long) (ptr)) & 0xf) == 0); + + +/** round up value to next multiple of 4 */ +#define ROUNDUP4(k) (((k) + 0x3) & ~0x3) + +/** round up value to next multiple of 8 */ +#define ROUNDUP8(k) (((k) + 0x7) & ~0x7) + +/** round up value to next multiple of 16 */ +#define ROUNDUP16(k) (((k) + 0xf) & ~0xf) + + +#define CELL_MAX_SPUS 8 + +#define CELL_MAX_SAMPLERS 4 +#define CELL_MAX_TEXTURE_LEVELS 12 /* 2k x 2k */ +#define CELL_MAX_CONSTANTS 32 /**< number of float[4] constants */ +#define CELL_MAX_WIDTH 1024 /**< max framebuffer width */ +#define CELL_MAX_HEIGHT 1024 /**< max framebuffer width */ + +#define TILE_SIZE 32 + + +/** + * The low byte of a mailbox word contains the command opcode. + * Remaining higher bytes are command specific. + */ +#define CELL_CMD_OPCODE_MASK 0xff + +#define CELL_CMD_EXIT 1 +#define CELL_CMD_CLEAR_SURFACE 2 +#define CELL_CMD_FINISH 3 +#define CELL_CMD_RENDER 4 +#define CELL_CMD_BATCH 5 +#define CELL_CMD_RELEASE_VERTS 6 +#define CELL_CMD_STATE_FRAMEBUFFER 10 +#define CELL_CMD_STATE_FRAGMENT_OPS 11 +#define CELL_CMD_STATE_SAMPLER 12 +#define CELL_CMD_STATE_TEXTURE 13 +#define CELL_CMD_STATE_VERTEX_INFO 14 +#define CELL_CMD_STATE_VIEWPORT 15 +#define CELL_CMD_STATE_UNIFORMS 16 +#define CELL_CMD_STATE_VS_ARRAY_INFO 17 +#define CELL_CMD_STATE_BIND_VS 18 +#define CELL_CMD_STATE_FRAGMENT_PROGRAM 19 +#define CELL_CMD_STATE_ATTRIB_FETCH 20 +#define CELL_CMD_STATE_FS_CONSTANTS 21 +#define CELL_CMD_STATE_RASTERIZER 22 +#define CELL_CMD_VS_EXECUTE 23 +#define CELL_CMD_FLUSH_BUFFER_RANGE 24 +#define CELL_CMD_FENCE 25 + + +/** Command/batch buffers */ +#define CELL_NUM_BUFFERS 4 +#define CELL_BUFFER_SIZE (4*1024) /**< 16KB would be the max */ + +#define CELL_BUFFER_STATUS_FREE 10 +#define CELL_BUFFER_STATUS_USED 20 + +/** Debug flags */ +#define CELL_DEBUG_CHECKER (1 << 0) +#define CELL_DEBUG_ASM (1 << 1) +#define CELL_DEBUG_SYNC (1 << 2) +#define CELL_DEBUG_FRAGMENT_OPS (1 << 3) +#define CELL_DEBUG_FRAGMENT_OP_FALLBACK (1 << 4) +#define CELL_DEBUG_CMD (1 << 5) +#define CELL_DEBUG_CACHE (1 << 6) + +#define CELL_FENCE_IDLE 0 +#define CELL_FENCE_EMITTED 1 +#define CELL_FENCE_SIGNALLED 2 + +#define CELL_FACING_FRONT 0 +#define CELL_FACING_BACK 1 + +struct cell_fence +{ + /** There's a 16-byte status qword per SPU */ + volatile uint status[CELL_MAX_SPUS][4]; +}; + +#ifdef __SPU__ +typedef vector unsigned int opcode_t; +#else +typedef unsigned int opcode_t[4]; +#endif + +/** + * Fence command sent to SPUs. In response, the SPUs will write + * CELL_FENCE_STATUS_SIGNALLED back to the fence status word in main memory. + */ +struct cell_command_fence +{ + opcode_t opcode; /**< CELL_CMD_FENCE */ + struct cell_fence *fence; + uint32_t pad_[3]; +}; + + +/** + * Command to specify per-fragment operations state and generated code. + * Note that this is a variant-length structure, allocated with as + * much memory as needed to hold the generated code; the "code" + * field *must* be the last field in the structure. Also, the entire + * length of the structure (including the variant code field) must be + * a multiple of 8 bytes; we require that this structure itself be + * a multiple of 8 bytes, and that the generated code also be a multiple + * of 8 bytes. + * + * Also note that the dsa, blend, blend_color fields are really only needed + * for the fallback/C per-pixel code. They're not used when we generate + * dynamic SPU fragment code (which is the normal case), and will eventually + * be removed from this structure. + */ +struct cell_command_fragment_ops +{ + opcode_t opcode; /**< CELL_CMD_STATE_FRAGMENT_OPS */ + + /* Fields for the fallback case */ + struct pipe_depth_stencil_alpha_state dsa; + struct pipe_blend_state blend; + struct pipe_blend_color blend_color; + + /* Fields for the generated SPU code */ + unsigned total_code_size; + unsigned front_code_index; + unsigned back_code_index; + /* this field has variant length, and must be the last field in + * the structure + */ + unsigned code[0]; +}; + + +/** Max instructions for fragment programs */ +#define SPU_MAX_FRAGMENT_PROGRAM_INSTS 512 + +/** + * Command to send a fragment program to SPUs. + */ +struct cell_command_fragment_program +{ + opcode_t opcode; /**< CELL_CMD_STATE_FRAGMENT_PROGRAM */ + uint num_inst; /**< Number of instructions */ + uint32_t pad[3]; + unsigned code[SPU_MAX_FRAGMENT_PROGRAM_INSTS]; +}; + + +/** + * Tell SPUs about the framebuffer size, location + */ +struct cell_command_framebuffer +{ + opcode_t opcode; /**< CELL_CMD_STATE_FRAMEBUFFER */ + int width, height; + void *color_start, *depth_start; + enum pipe_format color_format, depth_format; + uint32_t pad_[2]; +}; + + +/** + * Tell SPUs about rasterizer state. + */ +struct cell_command_rasterizer +{ + opcode_t opcode; /**< CELL_CMD_STATE_RASTERIZER */ + struct pipe_rasterizer_state rasterizer; + /*uint32_t pad[1];*/ +}; + + +/** + * Clear framebuffer to the given value/color. + */ +struct cell_command_clear_surface +{ + opcode_t opcode; /**< CELL_CMD_CLEAR_SURFACE */ + uint surface; /**< Temporary: 0=color, 1=Z */ + uint value; + uint32_t pad[2]; +}; + + +/** + * Array info used by the vertex shader's vertex puller. + */ +struct cell_array_info +{ + uint64_t base; /**< Base address of the 0th element. */ + uint attr; /**< Attribute that this state is for. */ + uint pitch; /**< Byte pitch from one entry to the next. */ + uint size; + uint function_offset; +}; + + +struct cell_attribute_fetch_code +{ + uint64_t base; + uint size; +}; + + +struct cell_buffer_range +{ + uint64_t base; + unsigned size; +}; + + +struct cell_shader_info +{ + uint64_t declarations; + uint64_t instructions; + uint64_t immediates; + + unsigned num_outputs; + unsigned num_declarations; + unsigned num_instructions; + unsigned num_immediates; +}; + + +#define SPU_VERTS_PER_BATCH 64 +struct cell_command_vs +{ + opcode_t opcode; /**< CELL_CMD_VS_EXECUTE */ + uint64_t vOut[SPU_VERTS_PER_BATCH]; + unsigned num_elts; + unsigned elts[SPU_VERTS_PER_BATCH]; + float plane[12][4]; + unsigned nr_planes; + unsigned nr_attrs; +}; + + +struct cell_command_render +{ + opcode_t opcode; /**< CELL_CMD_RENDER */ + uint prim_type; /**< PIPE_PRIM_x */ + uint num_verts; + uint vertex_size; /**< bytes per vertex */ + uint num_indexes; + uint vertex_buf; /**< which cell->buffer[] contains the vertex data */ + float xmin, ymin, xmax, ymax; /* XXX another dummy field */ + uint min_index; + boolean inline_verts; + uint32_t pad_[1]; +}; + + +struct cell_command_release_verts +{ + opcode_t opcode; /**< CELL_CMD_RELEASE_VERTS */ + uint vertex_buf; /**< in [0, CELL_NUM_BUFFERS-1] */ + uint32_t pad_[3]; +}; + + +struct cell_command_sampler +{ + opcode_t opcode; /**< CELL_CMD_STATE_SAMPLER */ + uint unit; + struct pipe_sampler_state state; + uint32_t pad_[3]; +}; + + +struct cell_command_texture +{ + opcode_t opcode; /**< CELL_CMD_STATE_TEXTURE */ + uint target; /**< PIPE_TEXTURE_x */ + uint unit; + void *start[CELL_MAX_TEXTURE_LEVELS]; /**< Address in main memory */ + ushort width[CELL_MAX_TEXTURE_LEVELS]; + ushort height[CELL_MAX_TEXTURE_LEVELS]; + ushort depth[CELL_MAX_TEXTURE_LEVELS]; +}; + + +#define MAX_SPU_FUNCTIONS 12 +/** + * Used to tell the PPU about the address of particular functions in the + * SPU's address space. + */ +struct cell_spu_function_info +{ + uint num; + char names[MAX_SPU_FUNCTIONS][16]; + uint addrs[MAX_SPU_FUNCTIONS]; + char pad[12]; /**< Pad struct to multiple of 16 bytes (256 currently) */ +}; + + +/** This is the object passed to spe_create_thread() */ +PIPE_ALIGN_TYPE(16, +struct cell_init_info +{ + unsigned id; + unsigned num_spus; + unsigned debug_flags; /**< mask of CELL_DEBUG_x flags */ + float inv_timebase; /**< 1.0/timebase, for perf measurement */ + + /** Buffers for command batches, vertex/index data */ + ubyte *buffers[CELL_NUM_BUFFERS]; + uint *buffer_status; /**< points at cell_context->buffer_status */ + + struct cell_spu_function_info *spu_functions; +}); + + +#endif /* CELL_COMMON_H */ diff --git a/src/gallium/drivers/cell/ppu/Makefile b/src/gallium/drivers/cell/ppu/Makefile new file mode 100644 index 0000000..c92f8e5 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/Makefile @@ -0,0 +1,86 @@ +# Gallium3D Cell driver: PPU code + +# This makefile builds the libcell.a library which gets pulled into +# the main libGL.so library + + +TOP = ../../../../.. +include $(TOP)/configs/current + + +# This is the "top-level" cell PPU driver code, will get pulled into libGL.so +# by the winsys Makefile. +CELL_LIB = ../libcell.a + + +# This is the SPU code. We'd like to be able to put this into the libcell.a +# archive with the PPU code, but nesting .a libs doesn't seem to work. +# So, it's pulled into libGL.so in gallium/winsys/xlib/Makefile +SPU_CODE_MODULE = ../spu/g3d_spu.a + + +SOURCES = \ + cell_batch.c \ + cell_clear.c \ + cell_context.c \ + cell_draw_arrays.c \ + cell_fence.c \ + cell_flush.c \ + cell_gen_fragment.c \ + cell_gen_fp.c \ + cell_state_derived.c \ + cell_state_emit.c \ + cell_state_shader.c \ + cell_pipe_state.c \ + cell_screen.c \ + cell_state_vertex.c \ + cell_spu.c \ + cell_surface.c \ + cell_texture.c \ + cell_vbuf.c \ + cell_vertex_fetch.c \ + cell_vertex_shader.c + + +OBJECTS = $(SOURCES:.c=.o) \ + +INCLUDE_DIRS = \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers + +.c.o: + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + + +.c.s: + $(CC) -S $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + + +default: $(CELL_LIB) + + +$(CELL_LIB): $(OBJECTS) $(SPU_CODE_MODULE) +# ar -ru $(CELL_LIB) $(OBJECTS) $(SPU_CODE_MODULE) # doesn't work + ar -ru $(CELL_LIB) $(OBJECTS) + +#$(PROG): $(PPU_OBJECTS) +# $(CC) -o $(PROG) $(PPU_OBJECTS) $(SPU_CODE_MODULE) $(PPU_LFLAGS) + + + +clean: + rm -f *.o *~ $(CELL_LIB) + + + +depend: $(SOURCES) + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDE_DIRS) $(SOURCES) 2> /dev/null + +include depend + + + diff --git a/src/gallium/drivers/cell/ppu/cell_batch.c b/src/gallium/drivers/cell/ppu/cell_batch.c new file mode 100644 index 0000000..fe144f8 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_batch.c @@ -0,0 +1,260 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "cell_context.h" +#include "cell_batch.h" +#include "cell_fence.h" +#include "cell_spu.h" + + + +/** + * Search the buffer pool for an empty/free buffer and return its index. + * Buffers are used for storing vertex data, state and commands which + * will be sent to the SPUs. + * If no empty buffers are available, wait for one. + * \return buffer index in [0, CELL_NUM_BUFFERS-1] + */ +uint +cell_get_empty_buffer(struct cell_context *cell) +{ + static uint prev_buffer = 0; + uint buf = (prev_buffer + 1) % CELL_NUM_BUFFERS; + uint tries = 0; + + /* Find a buffer that's marked as free by all SPUs */ + while (1) { + uint spu, num_free = 0; + + for (spu = 0; spu < cell->num_spus; spu++) { + if (cell->buffer_status[spu][buf][0] == CELL_BUFFER_STATUS_FREE) { + num_free++; + + if (num_free == cell->num_spus) { + /* found a free buffer, now mark status as used */ + for (spu = 0; spu < cell->num_spus; spu++) { + cell->buffer_status[spu][buf][0] = CELL_BUFFER_STATUS_USED; + } + /* + printf("PPU: ALLOC BUFFER %u, %u tries\n", buf, tries); + */ + prev_buffer = buf; + + /* release tex buffer associated w/ prev use of this batch buf */ + cell_free_fenced_buffers(cell, &cell->fenced_buffers[buf]); + + return buf; + } + } + else { + break; + } + } + + /* try next buf */ + buf = (buf + 1) % CELL_NUM_BUFFERS; + + tries++; + if (tries == 100) { + /* + printf("PPU WAITING for buffer...\n"); + */ + } + } +} + + +/** + * Append a fence command to the current batch buffer. + * Note that we're sure there's always room for this because of the + * adjusted size check in cell_batch_free_space(). + */ +static void +emit_fence(struct cell_context *cell) +{ + const uint batch = cell->cur_batch; + const uint size = cell->buffer_size[batch]; + struct cell_command_fence *fence_cmd; + struct cell_fence *fence = &cell->fenced_buffers[batch].fence; + uint i; + + /* set fence status to emitted, not yet signalled */ + for (i = 0; i < cell->num_spus; i++) { + fence->status[i][0] = CELL_FENCE_EMITTED; + } + + STATIC_ASSERT(sizeof(struct cell_command_fence) % 16 == 0); + ASSERT(size % 16 == 0); + ASSERT(size + sizeof(struct cell_command_fence) <= CELL_BUFFER_SIZE); + + fence_cmd = (struct cell_command_fence *) (cell->buffer[batch] + size); + fence_cmd->opcode[0] = CELL_CMD_FENCE; + fence_cmd->fence = fence; + + /* update batch buffer size */ + cell->buffer_size[batch] = size + sizeof(struct cell_command_fence); +} + + +/** + * Flush the current batch buffer to the SPUs. + * An empty buffer will be found and set as the new current batch buffer + * for subsequent commands/data. + */ +void +cell_batch_flush(struct cell_context *cell) +{ + static boolean flushing = FALSE; + uint batch = cell->cur_batch; + uint size = cell->buffer_size[batch]; + uint spu, cmd_word; + + assert(!flushing); + + if (size == 0) + return; + + /* Before we use this batch buffer, make sure any fenced texture buffers + * are released. + */ + if (cell->fenced_buffers[batch].head) { + emit_fence(cell); + size = cell->buffer_size[batch]; + } + + flushing = TRUE; + + assert(batch < CELL_NUM_BUFFERS); + + /* + printf("cell_batch_dispatch: buf %u at %p, size %u\n", + batch, &cell->buffer[batch][0], size); + */ + + /* + * Build "BATCH" command and send to all SPUs. + */ + cmd_word = CELL_CMD_BATCH | (batch << 8) | (size << 16); + + for (spu = 0; spu < cell->num_spus; spu++) { + assert(cell->buffer_status[spu][batch][0] == CELL_BUFFER_STATUS_USED); + send_mbox_message(cell_global.spe_contexts[spu], cmd_word); + } + + /* When the SPUs are done copying the buffer into their locals stores + * they'll write a BUFFER_STATUS_FREE message into the buffer_status[] + * array indicating that the PPU can re-use the buffer. + */ + + batch = cell_get_empty_buffer(cell); + + cell->buffer_size[batch] = 0; /* empty */ + cell->cur_batch = batch; + + flushing = FALSE; +} + + +/** + * Return the number of bytes free in the current batch buffer. + */ +uint +cell_batch_free_space(const struct cell_context *cell) +{ + uint free = CELL_BUFFER_SIZE - cell->buffer_size[cell->cur_batch]; + free -= sizeof(struct cell_command_fence); + return free; +} + + +/** + * Allocate space in the current batch buffer for 'bytes' space. + * Bytes must be a multiple of 16 bytes. Allocation will be 16 byte aligned. + * \return address in batch buffer to put data + */ +void * +cell_batch_alloc16(struct cell_context *cell, uint bytes) +{ + void *pos; + uint size; + + ASSERT(bytes % 16 == 0); + ASSERT(bytes <= CELL_BUFFER_SIZE); + ASSERT(cell->cur_batch >= 0); + +#ifdef ASSERT + { + uint spu; + for (spu = 0; spu < cell->num_spus; spu++) { + ASSERT(cell->buffer_status[spu][cell->cur_batch][0] + == CELL_BUFFER_STATUS_USED); + } + } +#endif + + size = cell->buffer_size[cell->cur_batch]; + + if (bytes > cell_batch_free_space(cell)) { + cell_batch_flush(cell); + size = 0; + } + + ASSERT(size % 16 == 0); + ASSERT(size + bytes <= CELL_BUFFER_SIZE); + + pos = (void *) (cell->buffer[cell->cur_batch] + size); + + cell->buffer_size[cell->cur_batch] = size + bytes; + + return pos; +} + + +/** + * One-time init of batch buffers. + */ +void +cell_init_batch_buffers(struct cell_context *cell) +{ + uint spu, buf; + + /* init command, vertex/index buffer info */ + for (buf = 0; buf < CELL_NUM_BUFFERS; buf++) { + cell->buffer_size[buf] = 0; + + /* init batch buffer status values, + * mark 0th buffer as used, rest as free. + */ + for (spu = 0; spu < cell->num_spus; spu++) { + if (buf == 0) + cell->buffer_status[spu][buf][0] = CELL_BUFFER_STATUS_USED; + else + cell->buffer_status[spu][buf][0] = CELL_BUFFER_STATUS_FREE; + } + } +} diff --git a/src/gallium/drivers/cell/ppu/cell_batch.h b/src/gallium/drivers/cell/ppu/cell_batch.h new file mode 100644 index 0000000..2901360 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_batch.h @@ -0,0 +1,54 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef CELL_BATCH_H +#define CELL_BATCH_H + +#include "pipe/p_compiler.h" + + +struct cell_context; + + +extern uint +cell_get_empty_buffer(struct cell_context *cell); + +extern void +cell_batch_flush(struct cell_context *cell); + +extern uint +cell_batch_free_space(const struct cell_context *cell); + +extern void * +cell_batch_alloc16(struct cell_context *cell, uint bytes); + +extern void +cell_init_batch_buffers(struct cell_context *cell); + + +#endif /* CELL_BATCH_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_clear.c b/src/gallium/drivers/cell/ppu/cell_clear.c new file mode 100644 index 0000000..246fe21 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_clear.c @@ -0,0 +1,92 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Authors + * Brian Paul + */ + +#include +#include +#include +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_pack_color.h" +#include "cell/common.h" +#include "cell_clear.h" +#include "cell_context.h" +#include "cell_batch.h" +#include "cell_flush.h" +#include "cell_spu.h" +#include "cell_state.h" + + +/** + * Called via pipe->clear() + */ +void +cell_clear(struct pipe_context *pipe, unsigned buffers, const float *rgba, + double depth, unsigned stencil) +{ + struct cell_context *cell = cell_context(pipe); + + if (cell->dirty) + cell_update_derived(cell); + + if (buffers & PIPE_CLEAR_COLOR) { + uint surfIndex = 0; + union util_color uc; + + util_pack_color(rgba, cell->framebuffer.cbufs[0]->format, &uc); + + /* Build a CLEAR command and place it in the current batch buffer */ + STATIC_ASSERT(sizeof(struct cell_command_clear_surface) % 16 == 0); + struct cell_command_clear_surface *clr + = (struct cell_command_clear_surface *) + cell_batch_alloc16(cell, sizeof(*clr)); + clr->opcode[0] = CELL_CMD_CLEAR_SURFACE; + clr->surface = surfIndex; + clr->value = uc.ui; + } + + if (buffers & PIPE_CLEAR_DEPTHSTENCIL) { + uint surfIndex = 1; + uint clearValue; + + clearValue = util_pack_z_stencil(cell->framebuffer.zsbuf->format, + depth, stencil); + + /* Build a CLEAR command and place it in the current batch buffer */ + STATIC_ASSERT(sizeof(struct cell_command_clear_surface) % 16 == 0); + struct cell_command_clear_surface *clr + = (struct cell_command_clear_surface *) + cell_batch_alloc16(cell, sizeof(*clr)); + clr->opcode[0] = CELL_CMD_CLEAR_SURFACE; + clr->surface = surfIndex; + clr->value = clearValue; + } +} diff --git a/src/gallium/drivers/cell/ppu/cell_clear.h b/src/gallium/drivers/cell/ppu/cell_clear.h new file mode 100644 index 0000000..08e091a --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_clear.h @@ -0,0 +1,41 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef CELL_CLEAR_H +#define CELL_CLEAR_H + + +struct pipe_context; + + +extern void +cell_clear(struct pipe_context *pipe, unsigned buffers, const float *rgba, + double depth, unsigned stencil); + + +#endif /* CELL_CLEAR_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_context.c b/src/gallium/drivers/cell/ppu/cell_context.c new file mode 100644 index 0000000..b6b3a70 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_context.c @@ -0,0 +1,198 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Authors + * Brian Paul + */ + + +#include + +#include "pipe/p_defines.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "pipe/p_screen.h" + +#include "draw/draw_context.h" +#include "draw/draw_private.h" + +#include "cell/common.h" +#include "cell_batch.h" +#include "cell_clear.h" +#include "cell_context.h" +#include "cell_draw_arrays.h" +#include "cell_fence.h" +#include "cell_flush.h" +#include "cell_state.h" +#include "cell_surface.h" +#include "cell_spu.h" +#include "cell_pipe_state.h" +#include "cell_texture.h" +#include "cell_vbuf.h" + + + +static void +cell_destroy_context( struct pipe_context *pipe ) +{ + struct cell_context *cell = cell_context(pipe); + + util_delete_keymap(cell->fragment_ops_cache, NULL); + + cell_spu_exit(cell); + + align_free(cell); +} + + +static struct draw_context * +cell_draw_create(struct cell_context *cell) +{ + struct draw_context *draw = draw_create(&cell->pipe); + +#if 0 /* broken */ + if (getenv("GALLIUM_CELL_VS")) { + /* plug in SPU-based vertex transformation code */ + draw->shader_queue_flush = cell_vertex_shader_queue_flush; + draw->driver_private = cell; + } +#endif + + return draw; +} + + +static const struct debug_named_value cell_debug_flags[] = { + {"checker", CELL_DEBUG_CHECKER, NULL},/**< modulate tile clear color by SPU ID */ + {"asm", CELL_DEBUG_ASM, NULL}, /**< dump SPU asm code */ + {"sync", CELL_DEBUG_SYNC, NULL}, /**< SPUs do synchronous DMA */ + {"fragops", CELL_DEBUG_FRAGMENT_OPS, NULL}, /**< SPUs emit fragment ops debug messages*/ + {"fragopfallback", CELL_DEBUG_FRAGMENT_OP_FALLBACK, NULL}, /**< SPUs use reference implementation for fragment ops*/ + {"cmd", CELL_DEBUG_CMD, NULL}, /**< SPUs dump command buffer info */ + {"cache", CELL_DEBUG_CACHE, NULL}, /**< report texture cache stats on exit */ + DEBUG_NAMED_VALUE_END +}; + +static unsigned int +cell_is_resource_referenced( struct pipe_context *pipe, + struct pipe_resource *texture, + unsigned level, int layer) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + + +struct pipe_context * +cell_create_context(struct pipe_screen *screen, + void *priv ) +{ + struct cell_context *cell; + uint i; + + /* some fields need to be 16-byte aligned, so align the whole object */ + cell = (struct cell_context*) align_malloc(sizeof(struct cell_context), 16); + if (!cell) + return NULL; + + memset(cell, 0, sizeof(*cell)); + + cell->winsys = NULL; /* XXX: fixme - get this from screen? */ + cell->pipe.winsys = NULL; + cell->pipe.screen = screen; + cell->pipe.priv = priv; + cell->pipe.destroy = cell_destroy_context; + + cell->pipe.clear = cell_clear; + cell->pipe.flush = cell_flush; + + cell->pipe.is_resource_referenced = cell_is_resource_referenced; + +#if 0 + cell->pipe.begin_query = cell_begin_query; + cell->pipe.end_query = cell_end_query; + cell->pipe.wait_query = cell_wait_query; +#endif + + cell_init_draw_functions(cell); + cell_init_state_functions(cell); + cell_init_shader_functions(cell); + cell_init_surface_functions(cell); + cell_init_vertex_functions(cell); + cell_init_texture_transfer_funcs(cell); + + cell->draw = cell_draw_create(cell); + + /* Create cache of fragment ops generated code */ + cell->fragment_ops_cache = + util_new_keymap(sizeof(struct cell_fragment_ops_key), ~0, NULL); + + cell_init_vbuf(cell); + + draw_set_rasterize_stage(cell->draw, cell->vbuf); + + /* convert all points/lines to tris for the time being */ + draw_wide_point_threshold(cell->draw, 0.0); + draw_wide_line_threshold(cell->draw, 0.0); + + /* get env vars or read config file to get debug flags */ + cell->debug_flags = debug_get_flags_option("CELL_DEBUG", + cell_debug_flags, + 0 ); + + for (i = 0; i < CELL_NUM_BUFFERS; i++) + cell_fence_init(&cell->fenced_buffers[i].fence); + + + /* + * SPU stuff + */ + /* This call only works with SDK 3.0. Anyone still using 2.1??? */ + cell->num_cells = spe_cpu_info_get(SPE_COUNT_PHYSICAL_CPU_NODES, -1); + cell->num_spus = spe_cpu_info_get(SPE_COUNT_USABLE_SPES, -1); + if (cell->debug_flags) { + printf("Cell: found %d Cell(s) with %u SPUs\n", + cell->num_cells, cell->num_spus); + } + if (getenv("CELL_NUM_SPUS")) { + cell->num_spus = atoi(getenv("CELL_NUM_SPUS")); + assert(cell->num_spus > 0); + } + + cell_start_spus(cell); + + cell_init_batch_buffers(cell); + + /* make sure SPU initializations are done before proceeding */ + cell_flush_int(cell, CELL_FLUSH_WAIT); + + return &cell->pipe; +} diff --git a/src/gallium/drivers/cell/ppu/cell_context.h b/src/gallium/drivers/cell/ppu/cell_context.h new file mode 100644 index 0000000..d1aee62 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_context.h @@ -0,0 +1,210 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef CELL_CONTEXT_H +#define CELL_CONTEXT_H + + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "draw/draw_vertex.h" +#include "draw/draw_vbuf.h" +/*#include "cell_winsys.h"*/ +#include "cell/common.h" +#include "rtasm/rtasm_ppc_spe.h" +#include "tgsi/tgsi_scan.h" +#include "util/u_keymap.h" + + +struct cell_vbuf_render; + + +/** + * Cell vertex shader state, subclass of pipe_shader_state. + */ +struct cell_vertex_shader_state +{ + struct pipe_shader_state shader; + struct tgsi_shader_info info; + void *draw_data; +}; + + +/** + * Cell fragment shader state, subclass of pipe_shader_state. + */ +struct cell_fragment_shader_state +{ + struct pipe_shader_state shader; + struct tgsi_shader_info info; + struct spe_function code; + void *data; +}; + + +/** + * Key for mapping per-fragment state to cached SPU machine code. + * keymap(cell_fragment_ops_key) => cell_command_fragment_ops + */ +struct cell_fragment_ops_key +{ + struct pipe_blend_state blend; + struct pipe_blend_color blend_color; + struct pipe_depth_stencil_alpha_state dsa; + enum pipe_format color_format; + enum pipe_format zs_format; +}; + + +struct cell_buffer_node; + +/** + * Fenced buffer list. List of buffers which can be unreferenced after + * the fence has been executed/signalled. + */ +struct cell_buffer_list +{ + PIPE_ALIGN_VAR(16) struct cell_fence fence; + struct cell_buffer_node *head; +}; + +struct cell_velems_state +{ + unsigned count; + struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS]; +}; + +/** + * Per-context state, subclass of pipe_context. + */ +struct cell_context +{ + struct pipe_context pipe; + + struct cell_winsys *winsys; + + const struct pipe_blend_state *blend; + const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; + uint num_samplers; + const struct pipe_depth_stencil_alpha_state *depth_stencil; + const struct pipe_rasterizer_state *rasterizer; + const struct cell_vertex_shader_state *vs; + const struct cell_fragment_shader_state *fs; + const struct cell_velems_state *velems; + + struct spe_function logic_op; + + struct pipe_blend_color blend_color; + struct pipe_stencil_ref stencil_ref; + struct pipe_clip_state clip; + struct pipe_resource *constants[2]; + struct pipe_framebuffer_state framebuffer; + struct pipe_poly_stipple poly_stipple; + struct pipe_scissor_state scissor; + struct cell_resource *texture[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; + uint num_textures; + struct pipe_viewport_state viewport; + struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; + uint num_vertex_buffers; + struct pipe_index_buffer index_buffer; + + ubyte *cbuf_map[PIPE_MAX_COLOR_BUFS]; + ubyte *zsbuf_map; + + uint dirty; + uint dirty_textures; /* bitmask of texture units */ + uint dirty_samplers; /* bitmask of sampler units */ + + /** Cache of code generated for per-fragment ops */ + struct keymap *fragment_ops_cache; + + /** The primitive drawing context */ + struct draw_context *draw; + struct draw_stage *render_stage; + + /** For post-transformed vertex buffering: */ + struct cell_vbuf_render *vbuf_render; + struct draw_stage *vbuf; + + struct vertex_info vertex_info; + + /** Mapped constant buffers */ + const void *mapped_constants[PIPE_SHADER_TYPES]; + + PIPE_ALIGN_VAR(16) struct cell_spu_function_info spu_functions; + + uint num_cells, num_spus; + + /** Buffers for command batches, vertex/index data */ + uint buffer_size[CELL_NUM_BUFFERS]; + PIPE_ALIGN_VAR(16) ubyte buffer[CELL_NUM_BUFFERS][CELL_BUFFER_SIZE]; + + int cur_batch; /**< which buffer is being filled w/ commands */ + + /** [4] to ensure 16-byte alignment for each status word */ + PIPE_ALIGN_VAR(16) uint buffer_status[CELL_MAX_SPUS][CELL_NUM_BUFFERS][4]; + + + /** Associated with each command/batch buffer is a list of pipe_buffers + * that are fenced. When the last command in a buffer is executed, the + * fence will be signalled, indicating that any pipe_buffers preceeding + * that fence can be unreferenced (and probably freed). + */ + struct cell_buffer_list fenced_buffers[CELL_NUM_BUFFERS]; + + + struct spe_function attrib_fetch; + unsigned attrib_fetch_offsets[PIPE_MAX_ATTRIBS]; + + unsigned debug_flags; +}; + + + + +static INLINE struct cell_context * +cell_context(struct pipe_context *pipe) +{ + return (struct cell_context *) pipe; +} + + +struct pipe_context * +cell_create_context(struct pipe_screen *screen, + void *priv ); + +extern void +cell_vertex_shader_queue_flush(struct draw_context *draw); + + +/* XXX find a better home for this */ +extern void cell_update_vertex_fetch(struct draw_context *draw); + + +#endif /* CELL_CONTEXT_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_draw_arrays.c b/src/gallium/drivers/cell/ppu/cell_draw_arrays.c new file mode 100644 index 0000000..a367fa3 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_draw_arrays.c @@ -0,0 +1,113 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Author: + * Brian Paul + * Keith Whitwell + */ + + +#include "pipe/p_defines.h" +#include "pipe/p_context.h" +#include "util/u_inlines.h" + +#include "cell_context.h" +#include "cell_draw_arrays.h" +#include "cell_state.h" +#include "cell_flush.h" +#include "cell_texture.h" + +#include "draw/draw_context.h" + + + + + + +/** + * Draw vertex arrays, with optional indexing. + * Basically, map the vertex buffers (and drawing surfaces), then hand off + * the drawing to the 'draw' module. + * + * XXX should the element buffer be specified/bound with a separate function? + */ +static void +cell_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) +{ + struct cell_context *cell = cell_context(pipe); + struct draw_context *draw = cell->draw; + void *mapped_indices = NULL; + unsigned i; + + if (cell->dirty) + cell_update_derived( cell ); + +#if 0 + cell_map_surfaces(cell); +#endif + + /* + * Map vertex buffers + */ + for (i = 0; i < cell->num_vertex_buffers; i++) { + void *buf = cell_resource(cell->vertex_buffer[i].buffer)->data; + draw_set_mapped_vertex_buffer(draw, i, buf); + } + /* Map index buffer, if present */ + if (info->indexed && cell->index_buffer.buffer) + mapped_indices = cell_resource(cell->index_buffer.buffer)->data; + + draw_set_mapped_index_buffer(draw, mapped_indices); + + /* draw! */ + draw_vbo(draw, info); + + /* + * unmap vertex/index buffers - will cause draw module to flush + */ + for (i = 0; i < cell->num_vertex_buffers; i++) { + draw_set_mapped_vertex_buffer(draw, i, NULL); + } + if (mapped_indices) { + draw_set_mapped_index_buffer(draw, NULL); + } + + /* + * TODO: Flush only when a user vertex/index buffer is present + * (or even better, modify draw module to do this + * internally when this condition is seen?) + */ + draw_flush(draw); +} + + +void +cell_init_draw_functions(struct cell_context *cell) +{ + cell->pipe.draw_vbo = cell_draw_vbo; +} + diff --git a/src/gallium/drivers/cell/ppu/cell_draw_arrays.h b/src/gallium/drivers/cell/ppu/cell_draw_arrays.h new file mode 100644 index 0000000..148873a --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_draw_arrays.h @@ -0,0 +1,36 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef CELL_DRAW_ARRAYS_H +#define CELL_DRAW_ARRAYS_H + + +extern void +cell_init_draw_functions(struct cell_context *cell); + + +#endif /* CELL_DRAW_ARRAYS_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_fence.c b/src/gallium/drivers/cell/ppu/cell_fence.c new file mode 100644 index 0000000..e7c9fc4 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_fence.c @@ -0,0 +1,170 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "cell_context.h" +#include "cell_batch.h" +#include "cell_fence.h" +#include "cell_texture.h" + + +void +cell_fence_init(struct cell_fence *fence) +{ + uint i; + ASSERT_ALIGN16(fence->status); + for (i = 0; i < CELL_MAX_SPUS; i++) { + fence->status[i][0] = CELL_FENCE_IDLE; + } +} + + +boolean +cell_fence_signalled(const struct cell_context *cell, + const struct cell_fence *fence) +{ + uint i; + for (i = 0; i < cell->num_spus; i++) { + if (fence->status[i][0] != CELL_FENCE_SIGNALLED) + return FALSE; + /*assert(fence->status[i][0] == CELL_FENCE_EMITTED);*/ + } + return TRUE; +} + + +void +cell_fence_finish(const struct cell_context *cell, + const struct cell_fence *fence) +{ + while (!cell_fence_signalled(cell, fence)) { + usleep(10); + } + +#ifdef DEBUG + { + uint i; + for (i = 0; i < cell->num_spus; i++) { + assert(fence->status[i][0] == CELL_FENCE_SIGNALLED); + } + } +#endif +} + + + + +struct cell_buffer_node +{ + struct pipe_resource *buffer; + struct cell_buffer_node *next; +}; + + +#if 0 +static void +cell_add_buffer_to_list(struct cell_context *cell, + struct cell_buffer_list *list, + struct pipe_resource *buffer) +{ + struct cell_buffer_node *node = CALLOC_STRUCT(cell_buffer_node); + /* create new list node which references the buffer, insert at head */ + if (node) { + pipe_resource_reference(&node->buffer, buffer); + node->next = list->head; + list->head = node; + } +} +#endif + + +/** + * Wait for completion of the given fence, then unreference any buffers + * on the list. + * This typically unrefs/frees texture buffers after any rendering which uses + * them has completed. + */ +void +cell_free_fenced_buffers(struct cell_context *cell, + struct cell_buffer_list *list) +{ + if (list->head) { + /*struct pipe_screen *ps = cell->pipe.screen;*/ + struct cell_buffer_node *node; + + cell_fence_finish(cell, &list->fence); + + /* traverse the list, unreferencing buffers, freeing nodes */ + node = list->head; + while (node) { + struct cell_buffer_node *next = node->next; + assert(node->buffer); + /* XXX need this? pipe_buffer_unmap(ps, node->buffer);*/ +#if 0 + printf("Unref buffer %p\n", node->buffer); + if (node->buffer->reference.count == 1) + printf(" Delete!\n"); +#endif + pipe_resource_reference(&node->buffer, NULL); + FREE(node); + node = next; + } + list->head = NULL; + } +} + + +/** + * This should be called for each render command. + * Any texture buffers that are current bound will be added to a fenced + * list to be freed later when the fence is executed/signalled. + */ +void +cell_add_fenced_textures(struct cell_context *cell) +{ + /*struct cell_buffer_list *list = &cell->fenced_buffers[cell->cur_batch];*/ + uint i; + + for (i = 0; i < cell->num_textures; i++) { + struct cell_resource *ct = cell->texture[i]; + if (ct) { +#if 0 + printf("Adding texture %p buffer %p to list\n", + ct, ct->tiled_buffer[level]); +#endif +#if 00 + /* XXX this needs to be fixed/restored! + * Maybe keep pointers to textures, not buffers. + */ + if (ct->base.buffer) + cell_add_buffer_to_list(cell, list, ct->buffer); +#endif + } + } +} diff --git a/src/gallium/drivers/cell/ppu/cell_fence.h b/src/gallium/drivers/cell/ppu/cell_fence.h new file mode 100644 index 0000000..536b4ba --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_fence.h @@ -0,0 +1,57 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef CELL_FENCE_H +#define CELL_FENCE_H + + +extern void +cell_fence_init(struct cell_fence *fence); + + +extern boolean +cell_fence_signalled(const struct cell_context *cell, + const struct cell_fence *fence); + + +extern void +cell_fence_finish(const struct cell_context *cell, + const struct cell_fence *fence); + + + +extern void +cell_free_fenced_buffers(struct cell_context *cell, + struct cell_buffer_list *list); + + +extern void +cell_add_fenced_textures(struct cell_context *cell); + + +#endif /* CELL_FENCE_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_flush.c b/src/gallium/drivers/cell/ppu/cell_flush.c new file mode 100644 index 0000000..8275c9d --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_flush.c @@ -0,0 +1,112 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "cell_context.h" +#include "cell_batch.h" +#include "cell_flush.h" +#include "cell_spu.h" +#include "cell_render.h" +#include "draw/draw_context.h" + + +/** + * Called via pipe->flush() + */ +void +cell_flush(struct pipe_context *pipe, unsigned flags, + struct pipe_fence_handle **fence) +{ + struct cell_context *cell = cell_context(pipe); + + if (fence) { + *fence = NULL; + /* XXX: Implement real fencing */ + flags |= CELL_FLUSH_WAIT; + } + + if (flags & (PIPE_FLUSH_SWAPBUFFERS | PIPE_FLUSH_RENDER_CACHE)) + flags |= CELL_FLUSH_WAIT; + + draw_flush( cell->draw ); + cell_flush_int(cell, flags); +} + + +/** + * Cell internal flush function. Send the current batch buffer to all SPUs. + * If flags & CELL_FLUSH_WAIT, do not return until the SPUs are idle. + * \param flags bitmask of flags CELL_FLUSH_WAIT, or zero + */ +void +cell_flush_int(struct cell_context *cell, unsigned flags) +{ + static boolean flushing = FALSE; /* recursion catcher */ + uint i; + + ASSERT(!flushing); + flushing = TRUE; + + if (flags & CELL_FLUSH_WAIT) { + STATIC_ASSERT(sizeof(opcode_t) % 16 == 0); + opcode_t *cmd = (opcode_t*) cell_batch_alloc16(cell, sizeof(opcode_t)); + *cmd[0] = CELL_CMD_FINISH; + } + + cell_batch_flush(cell); + +#if 0 + /* Send CMD_FINISH to all SPUs */ + for (i = 0; i < cell->num_spus; i++) { + send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_FINISH); + } +#endif + + if (flags & CELL_FLUSH_WAIT) { + /* Wait for ack */ + for (i = 0; i < cell->num_spus; i++) { + uint k = wait_mbox_message(cell_global.spe_contexts[i]); + assert(k == CELL_CMD_FINISH); + } + } + + flushing = FALSE; +} + + +void +cell_flush_buffer_range(struct cell_context *cell, void *ptr, + unsigned size) +{ + STATIC_ASSERT((sizeof(opcode_t) + sizeof(struct cell_buffer_range)) % 16 == 0); + uint32_t *batch = (uint32_t*)cell_batch_alloc16(cell, + sizeof(opcode_t) + sizeof(struct cell_buffer_range)); + struct cell_buffer_range *br = (struct cell_buffer_range *) &batch[4]; + batch[0] = CELL_CMD_FLUSH_BUFFER_RANGE; + br->base = (uintptr_t) ptr; + br->size = size; +} diff --git a/src/gallium/drivers/cell/ppu/cell_flush.h b/src/gallium/drivers/cell/ppu/cell_flush.h new file mode 100644 index 0000000..509ae62 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_flush.h @@ -0,0 +1,45 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef CELL_FLUSH +#define CELL_FLUSH + +#define CELL_FLUSH_WAIT 0x80000000 + +extern void +cell_flush(struct pipe_context *pipe, unsigned flags, + struct pipe_fence_handle **fence); + +extern void +cell_flush_int(struct cell_context *cell, unsigned flags); + +extern void +cell_flush_buffer_range(struct cell_context *cell, void *ptr, + unsigned size); + +#endif diff --git a/src/gallium/drivers/cell/ppu/cell_gen_fp.c b/src/gallium/drivers/cell/ppu/cell_gen_fp.c new file mode 100644 index 0000000..1d8a11a --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_gen_fp.c @@ -0,0 +1,2036 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * 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 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. + * + **************************************************************************/ + + + +/** + * Generate SPU fragment program/shader code. + * + * Note that we generate SOA-style code here. So each TGSI instruction + * operates on four pixels (and is translated into four SPU instructions, + * generally speaking). + * + * \author Brian Paul + */ + +#include +#include "pipe/p_defines.h" +#include "pipe/p_state.h" +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "tgsi/tgsi_exec.h" +#include "tgsi/tgsi_dump.h" +#include "rtasm/rtasm_ppc_spe.h" +#include "util/u_memory.h" +#include "cell_context.h" +#include "cell_gen_fp.h" + + +#define MAX_TEMPS 16 +#define MAX_IMMED 8 + +#define CHAN_X 0 +#define CHAN_Y 1 +#define CHAN_Z 2 +#define CHAN_W 3 + +/** + * Context needed during code generation. + */ +struct codegen +{ + struct cell_context *cell; + int inputs_reg; /**< 1st function parameter */ + int outputs_reg; /**< 2nd function parameter */ + int constants_reg; /**< 3rd function parameter */ + int temp_regs[MAX_TEMPS][4]; /**< maps TGSI temps to SPE registers */ + int imm_regs[MAX_IMMED][4]; /**< maps TGSI immediates to SPE registers */ + + int num_imm; /**< number of immediates */ + + int one_reg; /**< register containing {1.0, 1.0, 1.0, 1.0} */ + + int addr_reg; /**< address register, integer values */ + + /** Per-instruction temps / intermediate temps */ + int num_itemps; + int itemps[12]; + + /** Current IF/ELSE/ENDIF nesting level */ + int if_nesting; + /** Current BGNLOOP/ENDLOOP nesting level */ + int loop_nesting; + /** Location of start of current loop */ + int loop_start; + + /** Index of if/conditional mask register */ + int cond_mask_reg; + /** Index of loop mask register */ + int loop_mask_reg; + + /** Index of master execution mask register */ + int exec_mask_reg; + + /** KIL mask: indicates which fragments have been killed */ + int kill_mask_reg; + + int frame_size; /**< Stack frame size, in words */ + + struct spe_function *f; + boolean error; +}; + + +/** + * Allocate an intermediate temporary register. + */ +static int +get_itemp(struct codegen *gen) +{ + int t = spe_allocate_available_register(gen->f); + assert(gen->num_itemps < Elements(gen->itemps)); + gen->itemps[gen->num_itemps++] = t; + return t; +} + +/** + * Free all intermediate temporary registers. To be called after each + * instruction has been emitted. + */ +static void +free_itemps(struct codegen *gen) +{ + int i; + for (i = 0; i < gen->num_itemps; i++) { + spe_release_register(gen->f, gen->itemps[i]); + } + gen->num_itemps = 0; +} + + +/** + * Return index of an SPE register containing {1.0, 1.0, 1.0, 1.0}. + * The register is allocated and initialized upon the first call. + */ +static int +get_const_one_reg(struct codegen *gen) +{ + if (gen->one_reg <= 0) { + gen->one_reg = spe_allocate_available_register(gen->f); + + spe_indent(gen->f, 4); + spe_comment(gen->f, -4, "init constant reg = 1.0:"); + + /* one = {1.0, 1.0, 1.0, 1.0} */ + spe_load_float(gen->f, gen->one_reg, 1.0f); + + spe_indent(gen->f, -4); + } + + return gen->one_reg; +} + + +/** + * Return index of the address register. + * Used for indirect register loads/stores. + */ +static int +get_address_reg(struct codegen *gen) +{ + if (gen->addr_reg <= 0) { + gen->addr_reg = spe_allocate_available_register(gen->f); + + spe_indent(gen->f, 4); + spe_comment(gen->f, -4, "init address reg = 0:"); + + /* init addr = {0, 0, 0, 0} */ + spe_zero(gen->f, gen->addr_reg); + + spe_indent(gen->f, -4); + } + + return gen->addr_reg; +} + + +/** + * Return index of the master execution mask. + * The register is allocated an initialized upon the first call. + * + * The master execution mask controls which pixels in a quad are + * modified, according to surrounding conditionals, loops, etc. + */ +static int +get_exec_mask_reg(struct codegen *gen) +{ + if (gen->exec_mask_reg <= 0) { + gen->exec_mask_reg = spe_allocate_available_register(gen->f); + + /* XXX this may not be needed */ + spe_comment(gen->f, 0*-4, "initialize master execution mask = ~0"); + spe_load_int(gen->f, gen->exec_mask_reg, ~0); + } + + return gen->exec_mask_reg; +} + + +/** Return index of the conditional (if/else) execution mask register */ +static int +get_cond_mask_reg(struct codegen *gen) +{ + if (gen->cond_mask_reg <= 0) { + gen->cond_mask_reg = spe_allocate_available_register(gen->f); + } + + return gen->cond_mask_reg; +} + + +/** Return index of the loop execution mask register */ +static int +get_loop_mask_reg(struct codegen *gen) +{ + if (gen->loop_mask_reg <= 0) { + gen->loop_mask_reg = spe_allocate_available_register(gen->f); + } + + return gen->loop_mask_reg; +} + + + +static boolean +is_register_src(struct codegen *gen, int channel, + const struct tgsi_full_src_register *src) +{ + int swizzle = tgsi_util_get_full_src_register_swizzle(src, channel); + int sign_op = tgsi_util_get_full_src_register_sign_mode(src, channel); + + if (swizzle > TGSI_SWIZZLE_W || sign_op != TGSI_UTIL_SIGN_KEEP) { + return FALSE; + } + if (src->Register.File == TGSI_FILE_TEMPORARY || + src->Register.File == TGSI_FILE_IMMEDIATE) { + return TRUE; + } + return FALSE; +} + + +static boolean +is_memory_dst(struct codegen *gen, int channel, + const struct tgsi_full_dst_register *dst) +{ + if (dst->Register.File == TGSI_FILE_OUTPUT) { + return TRUE; + } + else { + return FALSE; + } +} + + +/** + * Return the index of the SPU temporary containing the named TGSI + * source register. If the TGSI register is a TGSI_FILE_TEMPORARY we + * just return the corresponding SPE register. If the TGIS register + * is TGSI_FILE_INPUT/CONSTANT/IMMEDIATE we allocate a new SPE register + * and emit an SPE load instruction. + */ +static int +get_src_reg(struct codegen *gen, + int channel, + const struct tgsi_full_src_register *src) +{ + int reg = -1; + int swizzle = tgsi_util_get_full_src_register_swizzle(src, channel); + boolean reg_is_itemp = FALSE; + uint sign_op; + + assert(swizzle >= TGSI_SWIZZLE_X); + assert(swizzle <= TGSI_SWIZZLE_W); + + { + int index = src->Register.Index; + + assert(swizzle < 4); + + if (src->Register.Indirect) { + /* XXX unfinished */ + } + + switch (src->Register.File) { + case TGSI_FILE_TEMPORARY: + reg = gen->temp_regs[index][swizzle]; + break; + case TGSI_FILE_INPUT: + { + /* offset is measured in quadwords, not bytes */ + int offset = index * 4 + swizzle; + reg = get_itemp(gen); + reg_is_itemp = TRUE; + /* Load: reg = memory[(machine_reg) + offset] */ + spe_lqd(gen->f, reg, gen->inputs_reg, offset * 16); + } + break; + case TGSI_FILE_IMMEDIATE: + reg = gen->imm_regs[index][swizzle]; + break; + case TGSI_FILE_CONSTANT: + { + /* offset is measured in quadwords, not bytes */ + int offset = index * 4 + swizzle; + reg = get_itemp(gen); + reg_is_itemp = TRUE; + /* Load: reg = memory[(machine_reg) + offset] */ + spe_lqd(gen->f, reg, gen->constants_reg, offset * 16); + } + break; + default: + assert(0); + } + } + + /* + * Handle absolute value, negate or set-negative of src register. + */ + sign_op = tgsi_util_get_full_src_register_sign_mode(src, channel); + if (sign_op != TGSI_UTIL_SIGN_KEEP) { + /* + * All sign ops are done by manipulating bit 31, the IEEE float sign bit. + */ + const int bit31mask_reg = get_itemp(gen); + int result_reg; + + if (reg_is_itemp) { + /* re-use 'reg' for the result */ + result_reg = reg; + } + else { + /* alloc a new reg for the result */ + result_reg = get_itemp(gen); + } + + /* mask with bit 31 set, the rest cleared */ + spe_load_uint(gen->f, bit31mask_reg, (1 << 31)); + + if (sign_op == TGSI_UTIL_SIGN_CLEAR) { + spe_andc(gen->f, result_reg, reg, bit31mask_reg); + } + else if (sign_op == TGSI_UTIL_SIGN_SET) { + spe_and(gen->f, result_reg, reg, bit31mask_reg); + } + else { + assert(sign_op == TGSI_UTIL_SIGN_TOGGLE); + spe_xor(gen->f, result_reg, reg, bit31mask_reg); + } + + reg = result_reg; + } + + return reg; +} + + +/** + * Return the index of an SPE register to use for the given TGSI register. + * If the TGSI register is TGSI_FILE_TEMPORARAY, the index of the + * corresponding SPE register is returned. If the TGSI register is + * TGSI_FILE_OUTPUT we allocate an intermediate temporary register. + * See store_dest_reg() below... + */ +static int +get_dst_reg(struct codegen *gen, + int channel, + const struct tgsi_full_dst_register *dest) +{ + int reg = -1; + + switch (dest->Register.File) { + case TGSI_FILE_TEMPORARY: + if (gen->if_nesting > 0 || gen->loop_nesting > 0) + reg = get_itemp(gen); + else + reg = gen->temp_regs[dest->Register.Index][channel]; + break; + case TGSI_FILE_OUTPUT: + reg = get_itemp(gen); + break; + default: + assert(0); + } + + return reg; +} + + +/** + * When a TGSI instruction is writing to an output register, this + * function emits the SPE store instruction to store the value_reg. + * \param value_reg the SPE register containing the value to store. + * This would have been returned by get_dst_reg(). + */ +static void +store_dest_reg(struct codegen *gen, + int value_reg, int channel, + const struct tgsi_full_dst_register *dest) +{ + /* + * XXX need to implement dst reg clamping/saturation + */ +#if 0 + switch (inst->Instruction.Saturate) { + case TGSI_SAT_NONE: + break; + case TGSI_SAT_ZERO_ONE: + break; + case TGSI_SAT_MINUS_PLUS_ONE: + break; + default: + assert( 0 ); + } +#endif + + switch (dest->Register.File) { + case TGSI_FILE_TEMPORARY: + if (gen->if_nesting > 0 || gen->loop_nesting > 0) { + int d_reg = gen->temp_regs[dest->Register.Index][channel]; + int exec_reg = get_exec_mask_reg(gen); + /* Mix d with new value according to exec mask: + * d[i] = mask_reg[i] ? value_reg : d_reg + */ + spe_selb(gen->f, d_reg, d_reg, value_reg, exec_reg); + } + else { + /* we're not inside a condition or loop: do nothing special */ + + } + break; + case TGSI_FILE_OUTPUT: + { + /* offset is measured in quadwords, not bytes */ + int offset = dest->Register.Index * 4 + channel; + if (gen->if_nesting > 0 || gen->loop_nesting > 0) { + int exec_reg = get_exec_mask_reg(gen); + int curval_reg = get_itemp(gen); + /* First read the current value from memory: + * Load: curval = memory[(machine_reg) + offset] + */ + spe_lqd(gen->f, curval_reg, gen->outputs_reg, offset * 16); + /* Mix curval with newvalue according to exec mask: + * d[i] = mask_reg[i] ? value_reg : d_reg + */ + spe_selb(gen->f, curval_reg, curval_reg, value_reg, exec_reg); + /* Store: memory[(machine_reg) + offset] = curval */ + spe_stqd(gen->f, curval_reg, gen->outputs_reg, offset * 16); + } + else { + /* Store: memory[(machine_reg) + offset] = reg */ + spe_stqd(gen->f, value_reg, gen->outputs_reg, offset * 16); + } + } + break; + default: + assert(0); + } +} + + + +static void +emit_prologue(struct codegen *gen) +{ + gen->frame_size = 1024; /* XXX temporary, should be dynamic */ + + spe_comment(gen->f, 0, "Function prologue:"); + + /* save $lr on stack # stqd $lr,16($sp) */ + spe_stqd(gen->f, SPE_REG_RA, SPE_REG_SP, 16); + + if (gen->frame_size >= 512) { + /* offset is too large for ai instruction */ + int offset_reg = spe_allocate_available_register(gen->f); + int sp_reg = spe_allocate_available_register(gen->f); + /* offset = -framesize */ + spe_load_int(gen->f, offset_reg, -gen->frame_size); + /* sp = $sp */ + spe_move(gen->f, sp_reg, SPE_REG_SP); + /* $sp = $sp + offset_reg */ + spe_a(gen->f, SPE_REG_SP, SPE_REG_SP, offset_reg); + /* save $sp in stack frame */ + spe_stqd(gen->f, sp_reg, SPE_REG_SP, 0); + /* clean up */ + spe_release_register(gen->f, offset_reg); + spe_release_register(gen->f, sp_reg); + } + else { + /* save stack pointer # stqd $sp,-frameSize($sp) */ + spe_stqd(gen->f, SPE_REG_SP, SPE_REG_SP, -gen->frame_size); + + /* adjust stack pointer # ai $sp,$sp,-frameSize */ + spe_ai(gen->f, SPE_REG_SP, SPE_REG_SP, -gen->frame_size); + } +} + + +static void +emit_epilogue(struct codegen *gen) +{ + const int return_reg = 3; + + spe_comment(gen->f, 0, "Function epilogue:"); + + spe_comment(gen->f, 0, "return the killed mask"); + if (gen->kill_mask_reg > 0) { + /* shader called KIL, return the "alive" mask */ + spe_move(gen->f, return_reg, gen->kill_mask_reg); + } + else { + /* return {0,0,0,0} */ + spe_load_uint(gen->f, return_reg, 0); + } + + spe_comment(gen->f, 0, "restore stack and return"); + if (gen->frame_size >= 512) { + /* offset is too large for ai instruction */ + int offset_reg = spe_allocate_available_register(gen->f); + /* offset = framesize */ + spe_load_int(gen->f, offset_reg, gen->frame_size); + /* $sp = $sp + offset */ + spe_a(gen->f, SPE_REG_SP, SPE_REG_SP, offset_reg); + /* clean up */ + spe_release_register(gen->f, offset_reg); + } + else { + /* restore stack pointer # ai $sp,$sp,frameSize */ + spe_ai(gen->f, SPE_REG_SP, SPE_REG_SP, gen->frame_size); + } + + /* restore $lr # lqd $lr,16($sp) */ + spe_lqd(gen->f, SPE_REG_RA, SPE_REG_SP, 16); + + /* return from function call */ + spe_bi(gen->f, SPE_REG_RA, 0, 0); +} + + +#define FOR_EACH_ENABLED_CHANNEL(inst, ch) \ + for (ch = 0; ch < 4; ch++) \ + if (inst->Dst[0].Register.WriteMask & (1 << ch)) + + +static boolean +emit_ARL(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch = 0, src_reg, addr_reg; + + src_reg = get_src_reg(gen, ch, &inst->Src[0]); + addr_reg = get_address_reg(gen); + + /* convert float to int */ + spe_cflts(gen->f, addr_reg, src_reg, 0); + + free_itemps(gen); + + return TRUE; +} + + +static boolean +emit_MOV(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch, src_reg[4], dst_reg[4]; + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + src_reg[ch] = get_src_reg(gen, ch, &inst->Src[0]); + dst_reg[ch] = get_dst_reg(gen, ch, &inst->Dst[0]); + } + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + if (is_register_src(gen, ch, &inst->Src[0]) && + is_memory_dst(gen, ch, &inst->Dst[0])) { + /* special-case: register to memory store */ + store_dest_reg(gen, src_reg[ch], ch, &inst->Dst[0]); + } + else { + spe_move(gen->f, dst_reg[ch], src_reg[ch]); + store_dest_reg(gen, dst_reg[ch], ch, &inst->Dst[0]); + } + } + + free_itemps(gen); + + return TRUE; +} + +/** + * Emit binary operation + */ +static boolean +emit_binop(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch, s1_reg[4], s2_reg[4], d_reg[4]; + + /* Loop over Red/Green/Blue/Alpha channels, fetch src operands */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + s1_reg[ch] = get_src_reg(gen, ch, &inst->Src[0]); + s2_reg[ch] = get_src_reg(gen, ch, &inst->Src[1]); + d_reg[ch] = get_dst_reg(gen, ch, &inst->Dst[0]); + } + + /* Loop over Red/Green/Blue/Alpha channels, do the op, store results */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + /* Emit actual SPE instruction: d = s1 + s2 */ + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_ADD: + spe_fa(gen->f, d_reg[ch], s1_reg[ch], s2_reg[ch]); + break; + case TGSI_OPCODE_SUB: + spe_fs(gen->f, d_reg[ch], s1_reg[ch], s2_reg[ch]); + break; + case TGSI_OPCODE_MUL: + spe_fm(gen->f, d_reg[ch], s1_reg[ch], s2_reg[ch]); + break; + default: + ; + } + } + + /* Store the result (a no-op for TGSI_FILE_TEMPORARY dests) */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + store_dest_reg(gen, d_reg[ch], ch, &inst->Dst[0]); + } + + /* Free any intermediate temps we allocated */ + free_itemps(gen); + + return TRUE; +} + + +/** + * Emit multiply add. See emit_ADD for comments. + */ +static boolean +emit_MAD(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch, s1_reg[4], s2_reg[4], s3_reg[4], d_reg[4]; + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + s1_reg[ch] = get_src_reg(gen, ch, &inst->Src[0]); + s2_reg[ch] = get_src_reg(gen, ch, &inst->Src[1]); + s3_reg[ch] = get_src_reg(gen, ch, &inst->Src[2]); + d_reg[ch] = get_dst_reg(gen, ch, &inst->Dst[0]); + } + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_fma(gen->f, d_reg[ch], s1_reg[ch], s2_reg[ch], s3_reg[ch]); + } + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + store_dest_reg(gen, d_reg[ch], ch, &inst->Dst[0]); + } + free_itemps(gen); + return TRUE; +} + + +/** + * Emit linear interpolate. See emit_ADD for comments. + */ +static boolean +emit_LRP(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch, s1_reg[4], s2_reg[4], s3_reg[4], d_reg[4], tmp_reg[4]; + + /* setup/get src/dst/temp regs */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + s1_reg[ch] = get_src_reg(gen, ch, &inst->Src[0]); + s2_reg[ch] = get_src_reg(gen, ch, &inst->Src[1]); + s3_reg[ch] = get_src_reg(gen, ch, &inst->Src[2]); + d_reg[ch] = get_dst_reg(gen, ch, &inst->Dst[0]); + tmp_reg[ch] = get_itemp(gen); + } + + /* d = s3 + s1(s2 - s3) */ + /* do all subtracts, then all fma, then all stores to better pipeline */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_fs(gen->f, tmp_reg[ch], s2_reg[ch], s3_reg[ch]); + } + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_fma(gen->f, d_reg[ch], tmp_reg[ch], s1_reg[ch], s3_reg[ch]); + } + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + store_dest_reg(gen, d_reg[ch], ch, &inst->Dst[0]); + } + free_itemps(gen); + return TRUE; +} + + + +/** + * Emit reciprocal or recip sqrt. + */ +static boolean +emit_RCP_RSQ(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch, s1_reg[4], d_reg[4], tmp_reg[4]; + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + s1_reg[ch] = get_src_reg(gen, ch, &inst->Src[0]); + d_reg[ch] = get_dst_reg(gen, ch, &inst->Dst[0]); + tmp_reg[ch] = get_itemp(gen); + } + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + if (inst->Instruction.Opcode == TGSI_OPCODE_RCP) { + /* tmp = 1/s1 */ + spe_frest(gen->f, tmp_reg[ch], s1_reg[ch]); + } + else { + /* tmp = 1/sqrt(s1) */ + spe_frsqest(gen->f, tmp_reg[ch], s1_reg[ch]); + } + } + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + /* d = float_interp(s1, tmp) */ + spe_fi(gen->f, d_reg[ch], s1_reg[ch], tmp_reg[ch]); + } + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + store_dest_reg(gen, d_reg[ch], ch, &inst->Dst[0]); + } + + free_itemps(gen); + return TRUE; +} + + +/** + * Emit absolute value. See emit_ADD for comments. + */ +static boolean +emit_ABS(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch, s1_reg[4], d_reg[4]; + const int bit31mask_reg = get_itemp(gen); + + /* mask with bit 31 set, the rest cleared */ + spe_load_uint(gen->f, bit31mask_reg, (1 << 31)); + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + s1_reg[ch] = get_src_reg(gen, ch, &inst->Src[0]); + d_reg[ch] = get_dst_reg(gen, ch, &inst->Dst[0]); + } + + /* d = sign bit cleared in s1 */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_andc(gen->f, d_reg[ch], s1_reg[ch], bit31mask_reg); + } + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + store_dest_reg(gen, d_reg[ch], ch, &inst->Dst[0]); + } + + free_itemps(gen); + return TRUE; +} + +/** + * Emit 3 component dot product. See emit_ADD for comments. + */ +static boolean +emit_DP3(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch; + int s1x_reg, s1y_reg, s1z_reg; + int s2x_reg, s2y_reg, s2z_reg; + int t0_reg = get_itemp(gen), t1_reg = get_itemp(gen); + + s1x_reg = get_src_reg(gen, CHAN_X, &inst->Src[0]); + s2x_reg = get_src_reg(gen, CHAN_X, &inst->Src[1]); + s1y_reg = get_src_reg(gen, CHAN_Y, &inst->Src[0]); + s2y_reg = get_src_reg(gen, CHAN_Y, &inst->Src[1]); + s1z_reg = get_src_reg(gen, CHAN_Z, &inst->Src[0]); + s2z_reg = get_src_reg(gen, CHAN_Z, &inst->Src[1]); + + /* t0 = x0 * x1 */ + spe_fm(gen->f, t0_reg, s1x_reg, s2x_reg); + + /* t1 = y0 * y1 */ + spe_fm(gen->f, t1_reg, s1y_reg, s2y_reg); + + /* t0 = z0 * z1 + t0 */ + spe_fma(gen->f, t0_reg, s1z_reg, s2z_reg, t0_reg); + + /* t0 = t0 + t1 */ + spe_fa(gen->f, t0_reg, t0_reg, t1_reg); + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + int d_reg = get_dst_reg(gen, ch, &inst->Dst[0]); + spe_move(gen->f, d_reg, t0_reg); + store_dest_reg(gen, d_reg, ch, &inst->Dst[0]); + } + + free_itemps(gen); + return TRUE; +} + +/** + * Emit 4 component dot product. See emit_ADD for comments. + */ +static boolean +emit_DP4(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch; + int s0x_reg, s0y_reg, s0z_reg, s0w_reg; + int s1x_reg, s1y_reg, s1z_reg, s1w_reg; + int t0_reg = get_itemp(gen), t1_reg = get_itemp(gen); + + s0x_reg = get_src_reg(gen, CHAN_X, &inst->Src[0]); + s1x_reg = get_src_reg(gen, CHAN_X, &inst->Src[1]); + s0y_reg = get_src_reg(gen, CHAN_Y, &inst->Src[0]); + s1y_reg = get_src_reg(gen, CHAN_Y, &inst->Src[1]); + s0z_reg = get_src_reg(gen, CHAN_Z, &inst->Src[0]); + s1z_reg = get_src_reg(gen, CHAN_Z, &inst->Src[1]); + s0w_reg = get_src_reg(gen, CHAN_W, &inst->Src[0]); + s1w_reg = get_src_reg(gen, CHAN_W, &inst->Src[1]); + + /* t0 = x0 * x1 */ + spe_fm(gen->f, t0_reg, s0x_reg, s1x_reg); + + /* t1 = y0 * y1 */ + spe_fm(gen->f, t1_reg, s0y_reg, s1y_reg); + + /* t0 = z0 * z1 + t0 */ + spe_fma(gen->f, t0_reg, s0z_reg, s1z_reg, t0_reg); + + /* t1 = w0 * w1 + t1 */ + spe_fma(gen->f, t1_reg, s0w_reg, s1w_reg, t1_reg); + + /* t0 = t0 + t1 */ + spe_fa(gen->f, t0_reg, t0_reg, t1_reg); + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + int d_reg = get_dst_reg(gen, ch, &inst->Dst[0]); + spe_move(gen->f, d_reg, t0_reg); + store_dest_reg(gen, d_reg, ch, &inst->Dst[0]); + } + + free_itemps(gen); + return TRUE; +} + +/** + * Emit homogeneous dot product. See emit_ADD for comments. + */ +static boolean +emit_DPH(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + /* XXX rewrite this function to look more like DP3/DP4 */ + int ch; + int s1_reg = get_src_reg(gen, CHAN_X, &inst->Src[0]); + int s2_reg = get_src_reg(gen, CHAN_X, &inst->Src[1]); + int tmp_reg = get_itemp(gen); + + /* t = x0 * x1 */ + spe_fm(gen->f, tmp_reg, s1_reg, s2_reg); + + s1_reg = get_src_reg(gen, CHAN_Y, &inst->Src[0]); + s2_reg = get_src_reg(gen, CHAN_Y, &inst->Src[1]); + /* t = y0 * y1 + t */ + spe_fma(gen->f, tmp_reg, s1_reg, s2_reg, tmp_reg); + + s1_reg = get_src_reg(gen, CHAN_Z, &inst->Src[0]); + s2_reg = get_src_reg(gen, CHAN_Z, &inst->Src[1]); + /* t = z0 * z1 + t */ + spe_fma(gen->f, tmp_reg, s1_reg, s2_reg, tmp_reg); + + s2_reg = get_src_reg(gen, CHAN_W, &inst->Src[1]); + /* t = w1 + t */ + spe_fa(gen->f, tmp_reg, s2_reg, tmp_reg); + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + int d_reg = get_dst_reg(gen, ch, &inst->Dst[0]); + spe_move(gen->f, d_reg, tmp_reg); + store_dest_reg(gen, tmp_reg, ch, &inst->Dst[0]); + } + + free_itemps(gen); + return TRUE; +} + +/** + * Emit 3-component vector normalize. + */ +static boolean +emit_NRM3(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch; + int src_reg[3]; + int t0_reg = get_itemp(gen), t1_reg = get_itemp(gen); + + src_reg[0] = get_src_reg(gen, CHAN_X, &inst->Src[0]); + src_reg[1] = get_src_reg(gen, CHAN_Y, &inst->Src[0]); + src_reg[2] = get_src_reg(gen, CHAN_Z, &inst->Src[0]); + + /* t0 = x * x */ + spe_fm(gen->f, t0_reg, src_reg[0], src_reg[0]); + + /* t1 = y * y */ + spe_fm(gen->f, t1_reg, src_reg[1], src_reg[1]); + + /* t0 = z * z + t0 */ + spe_fma(gen->f, t0_reg, src_reg[2], src_reg[2], t0_reg); + + /* t0 = t0 + t1 */ + spe_fa(gen->f, t0_reg, t0_reg, t1_reg); + + /* t1 = 1.0 / sqrt(t0) */ + spe_frsqest(gen->f, t1_reg, t0_reg); + spe_fi(gen->f, t1_reg, t0_reg, t1_reg); + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + int d_reg = get_dst_reg(gen, ch, &inst->Dst[0]); + /* dst = src[ch] * t1 */ + spe_fm(gen->f, d_reg, src_reg[ch], t1_reg); + store_dest_reg(gen, d_reg, ch, &inst->Dst[0]); + } + + free_itemps(gen); + return TRUE; +} + + +/** + * Emit cross product. See emit_ADD for comments. + */ +static boolean +emit_XPD(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int s1_reg = get_src_reg(gen, CHAN_Z, &inst->Src[0]); + int s2_reg = get_src_reg(gen, CHAN_Y, &inst->Src[1]); + int tmp_reg = get_itemp(gen); + + /* t = z0 * y1 */ + spe_fm(gen->f, tmp_reg, s1_reg, s2_reg); + + s1_reg = get_src_reg(gen, CHAN_Y, &inst->Src[0]); + s2_reg = get_src_reg(gen, CHAN_Z, &inst->Src[1]); + /* t = y0 * z1 - t */ + spe_fms(gen->f, tmp_reg, s1_reg, s2_reg, tmp_reg); + + if (inst->Dst[0].Register.WriteMask & (1 << CHAN_X)) { + store_dest_reg(gen, tmp_reg, CHAN_X, &inst->Dst[0]); + } + + s1_reg = get_src_reg(gen, CHAN_X, &inst->Src[0]); + s2_reg = get_src_reg(gen, CHAN_Z, &inst->Src[1]); + /* t = x0 * z1 */ + spe_fm(gen->f, tmp_reg, s1_reg, s2_reg); + + s1_reg = get_src_reg(gen, CHAN_Z, &inst->Src[0]); + s2_reg = get_src_reg(gen, CHAN_X, &inst->Src[1]); + /* t = z0 * x1 - t */ + spe_fms(gen->f, tmp_reg, s1_reg, s2_reg, tmp_reg); + + if (inst->Dst[0].Register.WriteMask & (1 << CHAN_Y)) { + store_dest_reg(gen, tmp_reg, CHAN_Y, &inst->Dst[0]); + } + + s1_reg = get_src_reg(gen, CHAN_Y, &inst->Src[0]); + s2_reg = get_src_reg(gen, CHAN_X, &inst->Src[1]); + /* t = y0 * x1 */ + spe_fm(gen->f, tmp_reg, s1_reg, s2_reg); + + s1_reg = get_src_reg(gen, CHAN_X, &inst->Src[0]); + s2_reg = get_src_reg(gen, CHAN_Y, &inst->Src[1]); + /* t = x0 * y1 - t */ + spe_fms(gen->f, tmp_reg, s1_reg, s2_reg, tmp_reg); + + if (inst->Dst[0].Register.WriteMask & (1 << CHAN_Z)) { + store_dest_reg(gen, tmp_reg, CHAN_Z, &inst->Dst[0]); + } + + free_itemps(gen); + return TRUE; +} + + +/** + * Emit inequality instruction. + * Note that the SPE fcgt instruction produces 0x0 and 0xffffffff as + * the result but OpenGL/TGSI needs 0.0 and 1.0 results. + * We can easily convert 0x0/0xffffffff to 0.0/1.0 with a bitwise AND. + */ +static boolean +emit_inequality(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch, s1_reg[4], s2_reg[4], d_reg[4], one_reg; + boolean complement = FALSE; + + one_reg = get_const_one_reg(gen); + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + s1_reg[ch] = get_src_reg(gen, ch, &inst->Src[0]); + s2_reg[ch] = get_src_reg(gen, ch, &inst->Src[1]); + d_reg[ch] = get_dst_reg(gen, ch, &inst->Dst[0]); + } + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_SGT: + spe_fcgt(gen->f, d_reg[ch], s1_reg[ch], s2_reg[ch]); + break; + case TGSI_OPCODE_SLT: + spe_fcgt(gen->f, d_reg[ch], s2_reg[ch], s1_reg[ch]); + break; + case TGSI_OPCODE_SGE: + spe_fcgt(gen->f, d_reg[ch], s2_reg[ch], s1_reg[ch]); + complement = TRUE; + break; + case TGSI_OPCODE_SLE: + spe_fcgt(gen->f, d_reg[ch], s1_reg[ch], s2_reg[ch]); + complement = TRUE; + break; + case TGSI_OPCODE_SEQ: + spe_fceq(gen->f, d_reg[ch], s1_reg[ch], s2_reg[ch]); + break; + case TGSI_OPCODE_SNE: + spe_fceq(gen->f, d_reg[ch], s1_reg[ch], s2_reg[ch]); + complement = TRUE; + break; + default: + assert(0); + } + } + + /* convert d from 0x0/0xffffffff to 0.0/1.0 */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + /* d = d & one_reg */ + if (complement) + spe_andc(gen->f, d_reg[ch], one_reg, d_reg[ch]); + else + spe_and(gen->f, d_reg[ch], one_reg, d_reg[ch]); + } + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + store_dest_reg(gen, d_reg[ch], ch, &inst->Dst[0]); + } + + free_itemps(gen); + return TRUE; +} + + +/** + * Emit compare. + */ +static boolean +emit_CMP(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch; + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + int s1_reg = get_src_reg(gen, ch, &inst->Src[0]); + int s2_reg = get_src_reg(gen, ch, &inst->Src[1]); + int s3_reg = get_src_reg(gen, ch, &inst->Src[2]); + int d_reg = get_dst_reg(gen, ch, &inst->Dst[0]); + int zero_reg = get_itemp(gen); + + spe_zero(gen->f, zero_reg); + + /* d = (s1 < 0) ? s2 : s3 */ + spe_fcgt(gen->f, d_reg, zero_reg, s1_reg); + spe_selb(gen->f, d_reg, s3_reg, s2_reg, d_reg); + + store_dest_reg(gen, d_reg, ch, &inst->Dst[0]); + free_itemps(gen); + } + + return TRUE; +} + +/** + * Emit trunc. + * Convert float to signed int + * Convert signed int to float + */ +static boolean +emit_TRUNC(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch, s1_reg[4], d_reg[4]; + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + s1_reg[ch] = get_src_reg(gen, ch, &inst->Src[0]); + d_reg[ch] = get_dst_reg(gen, ch, &inst->Dst[0]); + } + + /* Convert float to int */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_cflts(gen->f, d_reg[ch], s1_reg[ch], 0); + } + + /* Convert int to float */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_csflt(gen->f, d_reg[ch], d_reg[ch], 0); + } + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + store_dest_reg(gen, d_reg[ch], ch, &inst->Dst[0]); + } + + free_itemps(gen); + return TRUE; +} + + +/** + * Emit floor. + * If negative int subtract one + * Convert float to signed int + * Convert signed int to float + */ +static boolean +emit_FLR(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch, s1_reg[4], d_reg[4], tmp_reg[4], zero_reg, one_reg; + + zero_reg = get_itemp(gen); + spe_zero(gen->f, zero_reg); + one_reg = get_const_one_reg(gen); + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + s1_reg[ch] = get_src_reg(gen, ch, &inst->Src[0]); + d_reg[ch] = get_dst_reg(gen, ch, &inst->Dst[0]); + tmp_reg[ch] = get_itemp(gen); + } + + /* If negative, subtract 1.0 */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_fcgt(gen->f, tmp_reg[ch], zero_reg, s1_reg[ch]); + } + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_selb(gen->f, tmp_reg[ch], zero_reg, one_reg, tmp_reg[ch]); + } + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_fs(gen->f, tmp_reg[ch], s1_reg[ch], tmp_reg[ch]); + } + + /* Convert float to int */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_cflts(gen->f, tmp_reg[ch], tmp_reg[ch], 0); + } + + /* Convert int to float */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_csflt(gen->f, d_reg[ch], tmp_reg[ch], 0); + } + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + store_dest_reg(gen, d_reg[ch], ch, &inst->Dst[0]); + } + + free_itemps(gen); + return TRUE; +} + + +/** + * Compute frac = Input - FLR(Input) + */ +static boolean +emit_FRC(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch, s1_reg[4], d_reg[4], tmp_reg[4], zero_reg, one_reg; + + zero_reg = get_itemp(gen); + spe_zero(gen->f, zero_reg); + one_reg = get_const_one_reg(gen); + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + s1_reg[ch] = get_src_reg(gen, ch, &inst->Src[0]); + d_reg[ch] = get_dst_reg(gen, ch, &inst->Dst[0]); + tmp_reg[ch] = get_itemp(gen); + } + + /* If negative, subtract 1.0 */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_fcgt(gen->f, tmp_reg[ch], zero_reg, s1_reg[ch]); + } + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_selb(gen->f, tmp_reg[ch], zero_reg, one_reg, tmp_reg[ch]); + } + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_fs(gen->f, tmp_reg[ch], s1_reg[ch], tmp_reg[ch]); + } + + /* Convert float to int */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_cflts(gen->f, tmp_reg[ch], tmp_reg[ch], 0); + } + + /* Convert int to float */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_csflt(gen->f, tmp_reg[ch], tmp_reg[ch], 0); + } + + /* d = s1 - FLR(s1) */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_fs(gen->f, d_reg[ch], s1_reg[ch], tmp_reg[ch]); + } + + /* store result */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + store_dest_reg(gen, d_reg[ch], ch, &inst->Dst[0]); + } + + free_itemps(gen); + return TRUE; +} + + +#if 0 +static void +print_functions(struct cell_context *cell) +{ + struct cell_spu_function_info *funcs = &cell->spu_functions; + uint i; + for (i = 0; i < funcs->num; i++) { + printf("SPU func %u: %s at %u\n", + i, funcs->names[i], funcs->addrs[i]); + } +} +#endif + + +static uint +lookup_function(struct cell_context *cell, const char *funcname) +{ + const struct cell_spu_function_info *funcs = &cell->spu_functions; + uint i, addr = 0; + for (i = 0; i < funcs->num; i++) { + if (strcmp(funcs->names[i], funcname) == 0) { + addr = funcs->addrs[i]; + } + } + assert(addr && "spu function not found"); + return addr / 4; /* discard 2 least significant bits */ +} + + +/** + * Emit code to call a SPU function. + * Used to implement instructions like SIN/COS/POW/TEX/etc. + * If scalar, only the X components of the src regs are used, and the + * result is replicated across the dest register's XYZW components. + */ +static boolean +emit_function_call(struct codegen *gen, + const struct tgsi_full_instruction *inst, + char *funcname, uint num_args, boolean scalar) +{ + const uint addr = lookup_function(gen->cell, funcname); + char comment[100]; + int s_regs[3]; + int func_called = FALSE; + uint a, ch; + int retval_reg = -1; + + assert(num_args <= 3); + + snprintf(comment, sizeof(comment), "CALL %s:", funcname); + spe_comment(gen->f, -4, comment); + + if (scalar) { + for (a = 0; a < num_args; a++) { + s_regs[a] = get_src_reg(gen, CHAN_X, &inst->Src[a]); + } + /* we'll call the function, put the return value in this register, + * then replicate it across all write-enabled components in d_reg. + */ + retval_reg = spe_allocate_available_register(gen->f); + } + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + int d_reg; + ubyte usedRegs[SPE_NUM_REGS]; + uint i, numUsed; + + if (!scalar) { + for (a = 0; a < num_args; a++) { + s_regs[a] = get_src_reg(gen, ch, &inst->Src[a]); + } + } + + d_reg = get_dst_reg(gen, ch, &inst->Dst[0]); + + if (!scalar || !func_called) { + /* for a scalar function, we'll really only call the function once */ + + numUsed = spe_get_registers_used(gen->f, usedRegs); + assert(numUsed < gen->frame_size / 16 - 2); + + /* save registers to stack */ + for (i = 0; i < numUsed; i++) { + uint reg = usedRegs[i]; + int offset = 2 + i; + spe_stqd(gen->f, reg, SPE_REG_SP, 16 * offset); + } + + /* setup function arguments */ + for (a = 0; a < num_args; a++) { + spe_move(gen->f, 3 + a, s_regs[a]); + } + + /* branch to function, save return addr */ + spe_brasl(gen->f, SPE_REG_RA, addr); + + /* save function's return value */ + if (scalar) + spe_move(gen->f, retval_reg, 3); + else + spe_move(gen->f, d_reg, 3); + + /* restore registers from stack */ + for (i = 0; i < numUsed; i++) { + uint reg = usedRegs[i]; + if (reg != d_reg && reg != retval_reg) { + int offset = 2 + i; + spe_lqd(gen->f, reg, SPE_REG_SP, 16 * offset); + } + } + + func_called = TRUE; + } + + if (scalar) { + spe_move(gen->f, d_reg, retval_reg); + } + + store_dest_reg(gen, d_reg, ch, &inst->Dst[0]); + free_itemps(gen); + } + + if (scalar) { + spe_release_register(gen->f, retval_reg); + } + + return TRUE; +} + + +static boolean +emit_TEX(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + const uint target = inst->Texture.Texture; + const uint unit = inst->Src[1].Register.Index; + uint addr; + int ch; + int coord_regs[4], d_regs[4]; + + switch (target) { + case TGSI_TEXTURE_1D: + case TGSI_TEXTURE_2D: + addr = lookup_function(gen->cell, "spu_tex_2d"); + break; + case TGSI_TEXTURE_3D: + addr = lookup_function(gen->cell, "spu_tex_3d"); + break; + case TGSI_TEXTURE_CUBE: + addr = lookup_function(gen->cell, "spu_tex_cube"); + break; + default: + ASSERT(0 && "unsupported texture target"); + return FALSE; + } + + assert(inst->Src[1].Register.File == TGSI_FILE_SAMPLER); + + spe_comment(gen->f, -4, "CALL tex:"); + + /* get src/dst reg info */ + for (ch = 0; ch < 4; ch++) { + coord_regs[ch] = get_src_reg(gen, ch, &inst->Src[0]); + d_regs[ch] = get_dst_reg(gen, ch, &inst->Dst[0]); + } + + { + ubyte usedRegs[SPE_NUM_REGS]; + uint i, numUsed; + + numUsed = spe_get_registers_used(gen->f, usedRegs); + assert(numUsed < gen->frame_size / 16 - 2); + + /* save registers to stack */ + for (i = 0; i < numUsed; i++) { + uint reg = usedRegs[i]; + int offset = 2 + i; + spe_stqd(gen->f, reg, SPE_REG_SP, 16 * offset); + } + + /* setup function arguments (XXX depends on target) */ + for (i = 0; i < 4; i++) { + spe_move(gen->f, 3 + i, coord_regs[i]); + } + spe_load_uint(gen->f, 7, unit); /* sampler unit */ + + /* branch to function, save return addr */ + spe_brasl(gen->f, SPE_REG_RA, addr); + + /* save function's return values (four pixel's colors) */ + for (i = 0; i < 4; i++) { + spe_move(gen->f, d_regs[i], 3 + i); + } + + /* restore registers from stack */ + for (i = 0; i < numUsed; i++) { + uint reg = usedRegs[i]; + if (reg != d_regs[0] && + reg != d_regs[1] && + reg != d_regs[2] && + reg != d_regs[3]) { + int offset = 2 + i; + spe_lqd(gen->f, reg, SPE_REG_SP, 16 * offset); + } + } + } + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + store_dest_reg(gen, d_regs[ch], ch, &inst->Dst[0]); + free_itemps(gen); + } + + return TRUE; +} + + +/** + * KILL if any of src reg values are less than zero. + */ +static boolean +emit_KIL(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch; + int s_regs[4], kil_reg = -1, cmp_reg, zero_reg; + + spe_comment(gen->f, -4, "CALL kil:"); + + /* zero = {0,0,0,0} */ + zero_reg = get_itemp(gen); + spe_zero(gen->f, zero_reg); + + cmp_reg = get_itemp(gen); + + /* get src regs */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + s_regs[ch] = get_src_reg(gen, ch, &inst->Src[0]); + } + + /* test if any src regs are < 0 */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + if (kil_reg >= 0) { + /* cmp = 0 > src ? : ~0 : 0 */ + spe_fcgt(gen->f, cmp_reg, zero_reg, s_regs[ch]); + /* kil = kil | cmp */ + spe_or(gen->f, kil_reg, kil_reg, cmp_reg); + } + else { + kil_reg = get_itemp(gen); + /* kil = 0 > src ? : ~0 : 0 */ + spe_fcgt(gen->f, kil_reg, zero_reg, s_regs[ch]); + } + } + + if (gen->if_nesting || gen->loop_nesting) { + /* may have been a conditional kil */ + spe_and(gen->f, kil_reg, kil_reg, gen->exec_mask_reg); + } + + /* allocate the kill mask reg if needed */ + if (gen->kill_mask_reg <= 0) { + gen->kill_mask_reg = spe_allocate_available_register(gen->f); + spe_move(gen->f, gen->kill_mask_reg, kil_reg); + } + else { + spe_or(gen->f, gen->kill_mask_reg, gen->kill_mask_reg, kil_reg); + } + + free_itemps(gen); + + return TRUE; +} + + + +/** + * Emit min or max. + */ +static boolean +emit_MIN_MAX(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int ch, s0_reg[4], s1_reg[4], d_reg[4], tmp_reg[4]; + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + s0_reg[ch] = get_src_reg(gen, ch, &inst->Src[0]); + s1_reg[ch] = get_src_reg(gen, ch, &inst->Src[1]); + d_reg[ch] = get_dst_reg(gen, ch, &inst->Dst[0]); + tmp_reg[ch] = get_itemp(gen); + } + + /* d = (s0 > s1) ? s0 : s1 */ + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + if (inst->Instruction.Opcode == TGSI_OPCODE_MAX) + spe_fcgt(gen->f, tmp_reg[ch], s0_reg[ch], s1_reg[ch]); + else + spe_fcgt(gen->f, tmp_reg[ch], s1_reg[ch], s0_reg[ch]); + } + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + spe_selb(gen->f, d_reg[ch], s1_reg[ch], s0_reg[ch], tmp_reg[ch]); + } + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + store_dest_reg(gen, d_reg[ch], ch, &inst->Dst[0]); + } + + free_itemps(gen); + return TRUE; +} + + +/** + * Emit code to update the execution mask. + * This needs to be done whenever the execution status of a conditional + * or loop is changed. + */ +static void +emit_update_exec_mask(struct codegen *gen) +{ + const int exec_reg = get_exec_mask_reg(gen); + const int cond_reg = gen->cond_mask_reg; + const int loop_reg = gen->loop_mask_reg; + + spe_comment(gen->f, 0, "Update master execution mask"); + + if (gen->if_nesting > 0 && gen->loop_nesting > 0) { + /* exec_mask = cond_mask & loop_mask */ + assert(cond_reg > 0); + assert(loop_reg > 0); + spe_and(gen->f, exec_reg, cond_reg, loop_reg); + } + else if (gen->if_nesting > 0) { + assert(cond_reg > 0); + spe_move(gen->f, exec_reg, cond_reg); + } + else if (gen->loop_nesting > 0) { + assert(loop_reg > 0); + spe_move(gen->f, exec_reg, loop_reg); + } + else { + spe_load_int(gen->f, exec_reg, ~0x0); + } +} + + +static boolean +emit_IF(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + const int channel = 0; + int cond_reg; + + cond_reg = get_cond_mask_reg(gen); + + /* XXX push cond exec mask */ + + spe_comment(gen->f, 0, "init conditional exec mask = ~0:"); + spe_load_int(gen->f, cond_reg, ~0); + + /* update conditional execution mask with the predicate register */ + int tmp_reg = get_itemp(gen); + int s1_reg = get_src_reg(gen, channel, &inst->Src[0]); + + /* tmp = (s1_reg == 0) */ + spe_ceqi(gen->f, tmp_reg, s1_reg, 0); + /* tmp = !tmp */ + spe_complement(gen->f, tmp_reg, tmp_reg); + /* cond_mask = cond_mask & tmp */ + spe_and(gen->f, cond_reg, cond_reg, tmp_reg); + + gen->if_nesting++; + + /* update the master execution mask */ + emit_update_exec_mask(gen); + + free_itemps(gen); + + return TRUE; +} + + +static boolean +emit_ELSE(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + const int cond_reg = get_cond_mask_reg(gen); + + spe_comment(gen->f, 0, "cond exec mask = !cond exec mask"); + spe_complement(gen->f, cond_reg, cond_reg); + emit_update_exec_mask(gen); + + return TRUE; +} + + +static boolean +emit_ENDIF(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + /* XXX todo: pop cond exec mask */ + + gen->if_nesting--; + + emit_update_exec_mask(gen); + + return TRUE; +} + + +static boolean +emit_BGNLOOP(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + int exec_reg, loop_reg; + + exec_reg = get_exec_mask_reg(gen); + loop_reg = get_loop_mask_reg(gen); + + /* XXX push loop_exec mask */ + + spe_comment(gen->f, 0*-4, "initialize loop exec mask = ~0"); + spe_load_int(gen->f, loop_reg, ~0x0); + + gen->loop_nesting++; + gen->loop_start = spe_code_size(gen->f); /* in bytes */ + + return TRUE; +} + + +static boolean +emit_ENDLOOP(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + const int loop_reg = get_loop_mask_reg(gen); + const int tmp_reg = get_itemp(gen); + int offset; + + /* tmp_reg = exec[0] | exec[1] | exec[2] | exec[3] */ + spe_orx(gen->f, tmp_reg, loop_reg); + + offset = gen->loop_start - spe_code_size(gen->f); /* in bytes */ + + /* branch back to top of loop if tmp_reg != 0 */ + spe_brnz(gen->f, tmp_reg, offset / 4); + + /* XXX pop loop_exec mask */ + + gen->loop_nesting--; + + emit_update_exec_mask(gen); + + return TRUE; +} + + +static boolean +emit_BRK(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + const int exec_reg = get_exec_mask_reg(gen); + const int loop_reg = get_loop_mask_reg(gen); + + assert(gen->loop_nesting > 0); + + spe_comment(gen->f, 0, "loop exec mask &= ~master exec mask"); + spe_andc(gen->f, loop_reg, loop_reg, exec_reg); + + emit_update_exec_mask(gen); + + return TRUE; +} + + +static boolean +emit_CONT(struct codegen *gen, const struct tgsi_full_instruction *inst) +{ + assert(gen->loop_nesting > 0); + + return TRUE; +} + + +static boolean +emit_DDX_DDY(struct codegen *gen, const struct tgsi_full_instruction *inst, + boolean ddx) +{ + int ch; + + FOR_EACH_ENABLED_CHANNEL(inst, ch) { + int s_reg = get_src_reg(gen, ch, &inst->Src[0]); + int d_reg = get_dst_reg(gen, ch, &inst->Dst[0]); + + int t1_reg = get_itemp(gen); + int t2_reg = get_itemp(gen); + + spe_splat_word(gen->f, t1_reg, s_reg, 0); /* upper-left pixel */ + if (ddx) { + spe_splat_word(gen->f, t2_reg, s_reg, 1); /* upper-right pixel */ + } + else { + spe_splat_word(gen->f, t2_reg, s_reg, 2); /* lower-left pixel */ + } + spe_fs(gen->f, d_reg, t2_reg, t1_reg); + + free_itemps(gen); + } + + return TRUE; +} + + + + +/** + * Emit END instruction. + * We just return from the shader function at this point. + * + * Note that there may be more code after this that would be + * called by TGSI_OPCODE_CALL. + */ +static boolean +emit_END(struct codegen *gen) +{ + emit_epilogue(gen); + return TRUE; +} + + +/** + * Emit code for the given instruction. Just a big switch stmt. + */ +static boolean +emit_instruction(struct codegen *gen, + const struct tgsi_full_instruction *inst) +{ + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_ARL: + return emit_ARL(gen, inst); + case TGSI_OPCODE_MOV: + return emit_MOV(gen, inst); + case TGSI_OPCODE_ADD: + case TGSI_OPCODE_SUB: + case TGSI_OPCODE_MUL: + return emit_binop(gen, inst); + case TGSI_OPCODE_MAD: + return emit_MAD(gen, inst); + case TGSI_OPCODE_LRP: + return emit_LRP(gen, inst); + case TGSI_OPCODE_DP3: + return emit_DP3(gen, inst); + case TGSI_OPCODE_DP4: + return emit_DP4(gen, inst); + case TGSI_OPCODE_DPH: + return emit_DPH(gen, inst); + case TGSI_OPCODE_NRM: + return emit_NRM3(gen, inst); + case TGSI_OPCODE_XPD: + return emit_XPD(gen, inst); + case TGSI_OPCODE_RCP: + case TGSI_OPCODE_RSQ: + return emit_RCP_RSQ(gen, inst); + case TGSI_OPCODE_ABS: + return emit_ABS(gen, inst); + case TGSI_OPCODE_SGT: + case TGSI_OPCODE_SLT: + case TGSI_OPCODE_SGE: + case TGSI_OPCODE_SLE: + case TGSI_OPCODE_SEQ: + case TGSI_OPCODE_SNE: + return emit_inequality(gen, inst); + case TGSI_OPCODE_CMP: + return emit_CMP(gen, inst); + case TGSI_OPCODE_MIN: + case TGSI_OPCODE_MAX: + return emit_MIN_MAX(gen, inst); + case TGSI_OPCODE_TRUNC: + return emit_TRUNC(gen, inst); + case TGSI_OPCODE_FLR: + return emit_FLR(gen, inst); + case TGSI_OPCODE_FRC: + return emit_FRC(gen, inst); + case TGSI_OPCODE_END: + return emit_END(gen); + + case TGSI_OPCODE_COS: + return emit_function_call(gen, inst, "spu_cos", 1, TRUE); + case TGSI_OPCODE_SIN: + return emit_function_call(gen, inst, "spu_sin", 1, TRUE); + case TGSI_OPCODE_POW: + return emit_function_call(gen, inst, "spu_pow", 2, TRUE); + case TGSI_OPCODE_EX2: + return emit_function_call(gen, inst, "spu_exp2", 1, TRUE); + case TGSI_OPCODE_LG2: + return emit_function_call(gen, inst, "spu_log2", 1, TRUE); + case TGSI_OPCODE_TEX: + /* fall-through for now */ + case TGSI_OPCODE_TXD: + /* fall-through for now */ + case TGSI_OPCODE_TXB: + /* fall-through for now */ + case TGSI_OPCODE_TXL: + /* fall-through for now */ + case TGSI_OPCODE_TXP: + return emit_TEX(gen, inst); + case TGSI_OPCODE_KIL: + return emit_KIL(gen, inst); + + case TGSI_OPCODE_IF: + return emit_IF(gen, inst); + case TGSI_OPCODE_ELSE: + return emit_ELSE(gen, inst); + case TGSI_OPCODE_ENDIF: + return emit_ENDIF(gen, inst); + + case TGSI_OPCODE_BGNLOOP: + return emit_BGNLOOP(gen, inst); + case TGSI_OPCODE_ENDLOOP: + return emit_ENDLOOP(gen, inst); + case TGSI_OPCODE_BRK: + return emit_BRK(gen, inst); + case TGSI_OPCODE_CONT: + return emit_CONT(gen, inst); + + case TGSI_OPCODE_DDX: + return emit_DDX_DDY(gen, inst, TRUE); + case TGSI_OPCODE_DDY: + return emit_DDX_DDY(gen, inst, FALSE); + + /* XXX lots more cases to do... */ + + default: + fprintf(stderr, "Cell: unimplemented TGSI instruction %d!\n", + inst->Instruction.Opcode); + return FALSE; + } + + return TRUE; +} + + + +/** + * Emit code for a TGSI immediate value (vector of four floats). + * This involves register allocation and initialization. + * XXX the initialization should be done by a "prepare" stage, not + * per quad execution! + */ +static boolean +emit_immediate(struct codegen *gen, const struct tgsi_full_immediate *immed) +{ + int ch; + + assert(gen->num_imm < MAX_TEMPS); + + for (ch = 0; ch < 4; ch++) { + float val = immed->u[ch].Float; + + if (ch > 0 && val == immed->u[ch - 1].Float) { + /* re-use previous register */ + gen->imm_regs[gen->num_imm][ch] = gen->imm_regs[gen->num_imm][ch - 1]; + } + else { + char str[100]; + int reg = spe_allocate_available_register(gen->f); + + if (reg < 0) + return FALSE; + + sprintf(str, "init $%d = %f", reg, val); + spe_comment(gen->f, 0, str); + + /* update immediate map */ + gen->imm_regs[gen->num_imm][ch] = reg; + + /* emit initializer instruction */ + spe_load_float(gen->f, reg, val); + } + } + + gen->num_imm++; + + return TRUE; +} + + + +/** + * Emit "code" for a TGSI declaration. + * We only care about TGSI TEMPORARY register declarations at this time. + * For each TGSI TEMPORARY we allocate four SPE registers. + */ +static boolean +emit_declaration(struct cell_context *cell, + struct codegen *gen, const struct tgsi_full_declaration *decl) +{ + int i, ch; + + switch (decl->Declaration.File) { + case TGSI_FILE_TEMPORARY: + for (i = decl->Range.First; + i <= decl->Range.Last; + i++) { + assert(i < MAX_TEMPS); + for (ch = 0; ch < 4; ch++) { + gen->temp_regs[i][ch] = spe_allocate_available_register(gen->f); + if (gen->temp_regs[i][ch] < 0) + return FALSE; /* out of regs */ + } + + /* XXX if we run out of SPE registers, we need to spill + * to SPU memory. someday... + */ + + { + char buf[100]; + sprintf(buf, "TGSI temp[%d] maps to SPU regs [$%d $%d $%d $%d]", i, + gen->temp_regs[i][0], gen->temp_regs[i][1], + gen->temp_regs[i][2], gen->temp_regs[i][3]); + spe_comment(gen->f, 0, buf); + } + } + break; + default: + ; /* ignore */ + } + + return TRUE; +} + + + +/** + * Translate TGSI shader code to SPE instructions. This is done when + * the state tracker gives us a new shader (via pipe->create_fs_state()). + * + * \param cell the rendering context (in) + * \param tokens the TGSI shader (in) + * \param f the generated function (out) + */ +boolean +cell_gen_fragment_program(struct cell_context *cell, + const struct tgsi_token *tokens, + struct spe_function *f) +{ + struct tgsi_parse_context parse; + struct codegen gen; + uint ic = 0; + + memset(&gen, 0, sizeof(gen)); + gen.cell = cell; + gen.f = f; + + /* For SPE function calls: reg $3 = first param, $4 = second param, etc. */ + gen.inputs_reg = 3; /* pointer to inputs array */ + gen.outputs_reg = 4; /* pointer to outputs array */ + gen.constants_reg = 5; /* pointer to constants array */ + + spe_init_func(f, SPU_MAX_FRAGMENT_PROGRAM_INSTS * SPE_INST_SIZE); + spe_allocate_register(f, gen.inputs_reg); + spe_allocate_register(f, gen.outputs_reg); + spe_allocate_register(f, gen.constants_reg); + + if (cell->debug_flags & CELL_DEBUG_ASM) { + spe_print_code(f, TRUE); + spe_indent(f, 2*8); + printf("Begin %s\n", __FUNCTION__); + tgsi_dump(tokens, 0); + } + + tgsi_parse_init(&parse, tokens); + + emit_prologue(&gen); + + while (!tgsi_parse_end_of_tokens(&parse) && !gen.error) { + tgsi_parse_token(&parse); + + switch (parse.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_IMMEDIATE: + if (f->print) { + _debug_printf(" # "); + tgsi_dump_immediate(&parse.FullToken.FullImmediate); + } + if (!emit_immediate(&gen, &parse.FullToken.FullImmediate)) + gen.error = TRUE; + break; + + case TGSI_TOKEN_TYPE_DECLARATION: + if (f->print) { + _debug_printf(" # "); + tgsi_dump_declaration(&parse.FullToken.FullDeclaration); + } + if (!emit_declaration(cell, &gen, &parse.FullToken.FullDeclaration)) + gen.error = TRUE; + break; + + case TGSI_TOKEN_TYPE_INSTRUCTION: + if (f->print) { + _debug_printf(" # "); + ic++; + tgsi_dump_instruction(&parse.FullToken.FullInstruction, ic); + } + if (!emit_instruction(&gen, &parse.FullToken.FullInstruction)) + gen.error = TRUE; + break; + + default: + assert(0); + } + } + + if (gen.error) { + /* terminate the SPE code */ + return emit_END(&gen); + } + + if (cell->debug_flags & CELL_DEBUG_ASM) { + printf("cell_gen_fragment_program nr instructions: %d\n", f->num_inst); + printf("End %s\n", __FUNCTION__); + } + + tgsi_parse_free( &parse ); + + return !gen.error; +} diff --git a/src/gallium/drivers/cell/ppu/cell_gen_fp.h b/src/gallium/drivers/cell/ppu/cell_gen_fp.h new file mode 100644 index 0000000..99faea7 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_gen_fp.h @@ -0,0 +1,42 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + + +#ifndef CELL_GEN_FP_H +#define CELL_GEN_FP_H + + + +extern boolean +cell_gen_fragment_program(struct cell_context *cell, + const struct tgsi_token *tokens, + struct spe_function *f); + + +#endif /* CELL_GEN_FP_H */ + diff --git a/src/gallium/drivers/cell/ppu/cell_gen_fragment.c b/src/gallium/drivers/cell/ppu/cell_gen_fragment.c new file mode 100644 index 0000000..628bc1c --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_gen_fragment.c @@ -0,0 +1,2189 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * 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 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. + * + **************************************************************************/ + +/** + * Generate SPU per-fragment code (actually per-quad code). + * \author Brian Paul + * \author Bob Ellison + */ + + +#include "pipe/p_defines.h" +#include "pipe/p_state.h" +#include "rtasm/rtasm_ppc_spe.h" +#include "cell_context.h" +#include "cell_gen_fragment.h" + + + +/** Do extra optimizations? */ +#define OPTIMIZATIONS 1 + + +/** + * Generate SPE code to perform Z/depth testing. + * + * \param dsa Gallium depth/stencil/alpha state to gen code for + * \param f SPE function to append instruction onto. + * \param mask_reg register containing quad/pixel "alive" mask (in/out) + * \param ifragZ_reg register containing integer fragment Z values (in) + * \param ifbZ_reg register containing integer frame buffer Z values (in/out) + * \param zmask_reg register containing result of Z test/comparison (out) + * + * Returns TRUE if the Z-buffer needs to be updated. + */ +static boolean +gen_depth_test(struct spe_function *f, + const struct pipe_depth_stencil_alpha_state *dsa, + int mask_reg, int ifragZ_reg, int ifbZ_reg, int zmask_reg) +{ + /* NOTE: we use clgt below, not cgt, because we want to compare _unsigned_ + * quantities. This only makes a difference for 32-bit Z values though. + */ + ASSERT(dsa->depth.enabled); + + switch (dsa->depth.func) { + case PIPE_FUNC_EQUAL: + /* zmask = (ifragZ == ref) */ + spe_ceq(f, zmask_reg, ifragZ_reg, ifbZ_reg); + /* mask = (mask & zmask) */ + spe_and(f, mask_reg, mask_reg, zmask_reg); + break; + + case PIPE_FUNC_NOTEQUAL: + /* zmask = (ifragZ == ref) */ + spe_ceq(f, zmask_reg, ifragZ_reg, ifbZ_reg); + /* mask = (mask & ~zmask) */ + spe_andc(f, mask_reg, mask_reg, zmask_reg); + break; + + case PIPE_FUNC_GREATER: + /* zmask = (ifragZ > ref) */ + spe_clgt(f, zmask_reg, ifragZ_reg, ifbZ_reg); + /* mask = (mask & zmask) */ + spe_and(f, mask_reg, mask_reg, zmask_reg); + break; + + case PIPE_FUNC_LESS: + /* zmask = (ref > ifragZ) */ + spe_clgt(f, zmask_reg, ifbZ_reg, ifragZ_reg); + /* mask = (mask & zmask) */ + spe_and(f, mask_reg, mask_reg, zmask_reg); + break; + + case PIPE_FUNC_LEQUAL: + /* zmask = (ifragZ > ref) */ + spe_clgt(f, zmask_reg, ifragZ_reg, ifbZ_reg); + /* mask = (mask & ~zmask) */ + spe_andc(f, mask_reg, mask_reg, zmask_reg); + break; + + case PIPE_FUNC_GEQUAL: + /* zmask = (ref > ifragZ) */ + spe_clgt(f, zmask_reg, ifbZ_reg, ifragZ_reg); + /* mask = (mask & ~zmask) */ + spe_andc(f, mask_reg, mask_reg, zmask_reg); + break; + + case PIPE_FUNC_NEVER: + spe_il(f, mask_reg, 0); /* mask = {0,0,0,0} */ + spe_move(f, zmask_reg, mask_reg); /* zmask = mask */ + break; + + case PIPE_FUNC_ALWAYS: + /* mask unchanged */ + spe_il(f, zmask_reg, ~0); /* zmask = {~0,~0,~0,~0} */ + break; + + default: + ASSERT(0); + break; + } + + if (dsa->depth.writemask) { + /* + * If (ztest passed) { + * framebufferZ = fragmentZ; + * } + * OR, + * framebufferZ = (ztest_passed ? fragmentZ : framebufferZ; + */ + spe_selb(f, ifbZ_reg, ifbZ_reg, ifragZ_reg, mask_reg); + return TRUE; + } + + return FALSE; +} + + +/** + * Generate SPE code to perform alpha testing. + * + * \param dsa Gallium depth/stencil/alpha state to gen code for + * \param f SPE function to append instruction onto. + * \param mask_reg register containing quad/pixel "alive" mask (in/out) + * \param fragA_reg register containing four fragment alpha values (in) + */ +static void +gen_alpha_test(const struct pipe_depth_stencil_alpha_state *dsa, + struct spe_function *f, int mask_reg, int fragA_reg) +{ + int ref_reg = spe_allocate_available_register(f); + int amask_reg = spe_allocate_available_register(f); + + ASSERT(dsa->alpha.enabled); + + if ((dsa->alpha.func != PIPE_FUNC_NEVER) && + (dsa->alpha.func != PIPE_FUNC_ALWAYS)) { + /* load/splat the alpha reference float value */ + spe_load_float(f, ref_reg, dsa->alpha.ref_value); + } + + /* emit code to do the alpha comparison, updating 'mask' */ + switch (dsa->alpha.func) { + case PIPE_FUNC_EQUAL: + /* amask = (fragA == ref) */ + spe_fceq(f, amask_reg, fragA_reg, ref_reg); + /* mask = (mask & amask) */ + spe_and(f, mask_reg, mask_reg, amask_reg); + break; + + case PIPE_FUNC_NOTEQUAL: + /* amask = (fragA == ref) */ + spe_fceq(f, amask_reg, fragA_reg, ref_reg); + /* mask = (mask & ~amask) */ + spe_andc(f, mask_reg, mask_reg, amask_reg); + break; + + case PIPE_FUNC_GREATER: + /* amask = (fragA > ref) */ + spe_fcgt(f, amask_reg, fragA_reg, ref_reg); + /* mask = (mask & amask) */ + spe_and(f, mask_reg, mask_reg, amask_reg); + break; + + case PIPE_FUNC_LESS: + /* amask = (ref > fragA) */ + spe_fcgt(f, amask_reg, ref_reg, fragA_reg); + /* mask = (mask & amask) */ + spe_and(f, mask_reg, mask_reg, amask_reg); + break; + + case PIPE_FUNC_LEQUAL: + /* amask = (fragA > ref) */ + spe_fcgt(f, amask_reg, fragA_reg, ref_reg); + /* mask = (mask & ~amask) */ + spe_andc(f, mask_reg, mask_reg, amask_reg); + break; + + case PIPE_FUNC_GEQUAL: + /* amask = (ref > fragA) */ + spe_fcgt(f, amask_reg, ref_reg, fragA_reg); + /* mask = (mask & ~amask) */ + spe_andc(f, mask_reg, mask_reg, amask_reg); + break; + + case PIPE_FUNC_NEVER: + spe_il(f, mask_reg, 0); /* mask = [0,0,0,0] */ + break; + + case PIPE_FUNC_ALWAYS: + /* no-op, mask unchanged */ + break; + + default: + ASSERT(0); + break; + } + +#if OPTIMIZATIONS + /* if mask == {0,0,0,0} we're all done, return */ + { + /* re-use amask reg here */ + int tmp_reg = amask_reg; + /* tmp[0] = (mask[0] | mask[1] | mask[2] | mask[3]) */ + spe_orx(f, tmp_reg, mask_reg); + /* if tmp[0] == 0 then return from function call */ + spe_biz(f, tmp_reg, SPE_REG_RA, 0, 0); + } +#endif + + spe_release_register(f, ref_reg); + spe_release_register(f, amask_reg); +} + + +/** + * This pair of functions is used inline to allocate and deallocate + * optional constant registers. Once a constant is discovered to be + * needed, we will likely need it again, so we don't want to deallocate + * it and have to allocate and load it again unnecessarily. + */ +static INLINE void +setup_optional_register(struct spe_function *f, + int *r) +{ + if (*r < 0) + *r = spe_allocate_available_register(f); +} + +static INLINE void +release_optional_register(struct spe_function *f, + int r) +{ + if (r >= 0) + spe_release_register(f, r); +} + +static INLINE void +setup_const_register(struct spe_function *f, + int *r, + float value) +{ + if (*r >= 0) + return; + setup_optional_register(f, r); + spe_load_float(f, *r, value); +} + +static INLINE void +release_const_register(struct spe_function *f, + int r) +{ + release_optional_register(f, r); +} + + + +/** + * Unpack/convert framebuffer colors from four 32-bit packed colors + * (fbRGBA) to four float RGBA vectors (fbR, fbG, fbB, fbA). + * Each 8-bit color component is expanded into a float in [0.0, 1.0]. + */ +static void +unpack_colors(struct spe_function *f, + enum pipe_format color_format, + int fbRGBA_reg, + int fbR_reg, int fbG_reg, int fbB_reg, int fbA_reg) +{ + int mask0_reg = spe_allocate_available_register(f); + int mask1_reg = spe_allocate_available_register(f); + int mask2_reg = spe_allocate_available_register(f); + int mask3_reg = spe_allocate_available_register(f); + + spe_load_int(f, mask0_reg, 0xff); + spe_load_int(f, mask1_reg, 0xff00); + spe_load_int(f, mask2_reg, 0xff0000); + spe_load_int(f, mask3_reg, 0xff000000); + + spe_comment(f, 0, "Unpack framebuffer colors, convert to floats"); + + switch (color_format) { + case PIPE_FORMAT_B8G8R8A8_UNORM: + /* fbB = fbRGBA & mask */ + spe_and(f, fbB_reg, fbRGBA_reg, mask0_reg); + + /* fbG = fbRGBA & mask */ + spe_and(f, fbG_reg, fbRGBA_reg, mask1_reg); + + /* fbR = fbRGBA & mask */ + spe_and(f, fbR_reg, fbRGBA_reg, mask2_reg); + + /* fbA = fbRGBA & mask */ + spe_and(f, fbA_reg, fbRGBA_reg, mask3_reg); + + /* fbG = fbG >> 8 */ + spe_roti(f, fbG_reg, fbG_reg, -8); + + /* fbR = fbR >> 16 */ + spe_roti(f, fbR_reg, fbR_reg, -16); + + /* fbA = fbA >> 24 */ + spe_roti(f, fbA_reg, fbA_reg, -24); + break; + + case PIPE_FORMAT_A8R8G8B8_UNORM: + /* fbA = fbRGBA & mask */ + spe_and(f, fbA_reg, fbRGBA_reg, mask0_reg); + + /* fbR = fbRGBA & mask */ + spe_and(f, fbR_reg, fbRGBA_reg, mask1_reg); + + /* fbG = fbRGBA & mask */ + spe_and(f, fbG_reg, fbRGBA_reg, mask2_reg); + + /* fbB = fbRGBA & mask */ + spe_and(f, fbB_reg, fbRGBA_reg, mask3_reg); + + /* fbR = fbR >> 8 */ + spe_roti(f, fbR_reg, fbR_reg, -8); + + /* fbG = fbG >> 16 */ + spe_roti(f, fbG_reg, fbG_reg, -16); + + /* fbB = fbB >> 24 */ + spe_roti(f, fbB_reg, fbB_reg, -24); + break; + + default: + ASSERT(0); + } + + /* convert int[4] in [0,255] to float[4] in [0.0, 1.0] */ + spe_cuflt(f, fbR_reg, fbR_reg, 8); + spe_cuflt(f, fbG_reg, fbG_reg, 8); + spe_cuflt(f, fbB_reg, fbB_reg, 8); + spe_cuflt(f, fbA_reg, fbA_reg, 8); + + spe_release_register(f, mask0_reg); + spe_release_register(f, mask1_reg); + spe_release_register(f, mask2_reg); + spe_release_register(f, mask3_reg); +} + + +/** + * Generate SPE code to implement the given blend mode for a quad of pixels. + * \param f SPE function to append instruction onto. + * \param fragR_reg register with fragment red values (float) (in/out) + * \param fragG_reg register with fragment green values (float) (in/out) + * \param fragB_reg register with fragment blue values (float) (in/out) + * \param fragA_reg register with fragment alpha values (float) (in/out) + * \param fbRGBA_reg register with packed framebuffer colors (integer) (in) + */ +static void +gen_blend(const struct pipe_blend_state *blend, + const struct pipe_blend_color *blend_color, + struct spe_function *f, + enum pipe_format color_format, + int fragR_reg, int fragG_reg, int fragB_reg, int fragA_reg, + int fbRGBA_reg) +{ + int term1R_reg = spe_allocate_available_register(f); + int term1G_reg = spe_allocate_available_register(f); + int term1B_reg = spe_allocate_available_register(f); + int term1A_reg = spe_allocate_available_register(f); + + int term2R_reg = spe_allocate_available_register(f); + int term2G_reg = spe_allocate_available_register(f); + int term2B_reg = spe_allocate_available_register(f); + int term2A_reg = spe_allocate_available_register(f); + + int fbR_reg = spe_allocate_available_register(f); + int fbG_reg = spe_allocate_available_register(f); + int fbB_reg = spe_allocate_available_register(f); + int fbA_reg = spe_allocate_available_register(f); + + int tmp_reg = spe_allocate_available_register(f); + + /* Optional constant registers we might or might not end up using; + * if we do use them, make sure we only allocate them once by + * keeping a flag on each one. + */ + int one_reg = -1; + int constR_reg = -1, constG_reg = -1, constB_reg = -1, constA_reg = -1; + + ASSERT(blend->rt[0].blend_enable); + + /* packed RGBA -> float colors */ + unpack_colors(f, color_format, fbRGBA_reg, + fbR_reg, fbG_reg, fbB_reg, fbA_reg); + + /* + * Compute Src RGB terms. We're actually looking for the value + * of (the appropriate RGB factors) * (the incoming source RGB color), + * because in some cases (like PIPE_BLENDFACTOR_ONE and + * PIPE_BLENDFACTOR_ZERO) we can avoid doing unnecessary math. + */ + switch (blend->rt[0].rgb_src_factor) { + case PIPE_BLENDFACTOR_ONE: + /* factors = (1,1,1), so term = (R,G,B) */ + spe_move(f, term1R_reg, fragR_reg); + spe_move(f, term1G_reg, fragG_reg); + spe_move(f, term1B_reg, fragB_reg); + break; + case PIPE_BLENDFACTOR_ZERO: + /* factors = (0,0,0), so term = (0,0,0) */ + spe_load_float(f, term1R_reg, 0.0f); + spe_load_float(f, term1G_reg, 0.0f); + spe_load_float(f, term1B_reg, 0.0f); + break; + case PIPE_BLENDFACTOR_SRC_COLOR: + /* factors = (R,G,B), so term = (R*R, G*G, B*B) */ + spe_fm(f, term1R_reg, fragR_reg, fragR_reg); + spe_fm(f, term1G_reg, fragG_reg, fragG_reg); + spe_fm(f, term1B_reg, fragB_reg, fragB_reg); + break; + case PIPE_BLENDFACTOR_SRC_ALPHA: + /* factors = (A,A,A), so term = (R*A, G*A, B*A) */ + spe_fm(f, term1R_reg, fragR_reg, fragA_reg); + spe_fm(f, term1G_reg, fragG_reg, fragA_reg); + spe_fm(f, term1B_reg, fragB_reg, fragA_reg); + break; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + /* factors = (1-R,1-G,1-B), so term = (R*(1-R), G*(1-G), B*(1-B)) + * or in other words term = (R-R*R, G-G*G, B-B*B) + * fnms(a,b,c,d) computes a = d - b*c + */ + spe_fnms(f, term1R_reg, fragR_reg, fragR_reg, fragR_reg); + spe_fnms(f, term1G_reg, fragG_reg, fragG_reg, fragG_reg); + spe_fnms(f, term1B_reg, fragB_reg, fragB_reg, fragB_reg); + break; + case PIPE_BLENDFACTOR_DST_COLOR: + /* factors = (Rfb,Gfb,Bfb), so term = (R*Rfb, G*Gfb, B*Bfb) */ + spe_fm(f, term1R_reg, fragR_reg, fbR_reg); + spe_fm(f, term1G_reg, fragG_reg, fbG_reg); + spe_fm(f, term1B_reg, fragB_reg, fbB_reg); + break; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + /* factors = (1-Rfb,1-Gfb,1-Bfb), so term = (R*(1-Rfb),G*(1-Gfb),B*(1-Bfb)) + * or term = (R-R*Rfb, G-G*Gfb, B-B*Bfb) + * fnms(a,b,c,d) computes a = d - b*c + */ + spe_fnms(f, term1R_reg, fragR_reg, fbR_reg, fragR_reg); + spe_fnms(f, term1G_reg, fragG_reg, fbG_reg, fragG_reg); + spe_fnms(f, term1B_reg, fragB_reg, fbB_reg, fragB_reg); + break; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + /* factors = (1-A,1-A,1-A), so term = (R*(1-A),G*(1-A),B*(1-A)) + * or term = (R-R*A,G-G*A,B-B*A) + * fnms(a,b,c,d) computes a = d - b*c + */ + spe_fnms(f, term1R_reg, fragR_reg, fragA_reg, fragR_reg); + spe_fnms(f, term1G_reg, fragG_reg, fragA_reg, fragG_reg); + spe_fnms(f, term1B_reg, fragB_reg, fragA_reg, fragB_reg); + break; + case PIPE_BLENDFACTOR_DST_ALPHA: + /* factors = (Afb, Afb, Afb), so term = (R*Afb, G*Afb, B*Afb) */ + spe_fm(f, term1R_reg, fragR_reg, fbA_reg); + spe_fm(f, term1G_reg, fragG_reg, fbA_reg); + spe_fm(f, term1B_reg, fragB_reg, fbA_reg); + break; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + /* factors = (1-Afb, 1-Afb, 1-Afb), so term = (R*(1-Afb),G*(1-Afb),B*(1-Afb)) + * or term = (R-R*Afb,G-G*Afb,b-B*Afb) + * fnms(a,b,c,d) computes a = d - b*c + */ + spe_fnms(f, term1R_reg, fragR_reg, fbA_reg, fragR_reg); + spe_fnms(f, term1G_reg, fragG_reg, fbA_reg, fragG_reg); + spe_fnms(f, term1B_reg, fragB_reg, fbA_reg, fragB_reg); + break; + case PIPE_BLENDFACTOR_CONST_COLOR: + /* We need the optional constant color registers */ + setup_const_register(f, &constR_reg, blend_color->color[0]); + setup_const_register(f, &constG_reg, blend_color->color[1]); + setup_const_register(f, &constB_reg, blend_color->color[2]); + /* now, factor = (Rc,Gc,Bc), so term = (R*Rc,G*Gc,B*Bc) */ + spe_fm(f, term1R_reg, fragR_reg, constR_reg); + spe_fm(f, term1G_reg, fragG_reg, constG_reg); + spe_fm(f, term1B_reg, fragB_reg, constB_reg); + break; + case PIPE_BLENDFACTOR_CONST_ALPHA: + /* we'll need the optional constant alpha register */ + setup_const_register(f, &constA_reg, blend_color->color[3]); + /* factor = (Ac,Ac,Ac), so term = (R*Ac,G*Ac,B*Ac) */ + spe_fm(f, term1R_reg, fragR_reg, constA_reg); + spe_fm(f, term1G_reg, fragG_reg, constA_reg); + spe_fm(f, term1B_reg, fragB_reg, constA_reg); + break; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + /* We need the optional constant color registers */ + setup_const_register(f, &constR_reg, blend_color->color[0]); + setup_const_register(f, &constG_reg, blend_color->color[1]); + setup_const_register(f, &constB_reg, blend_color->color[2]); + /* factor = (1-Rc,1-Gc,1-Bc), so term = (R*(1-Rc),G*(1-Gc),B*(1-Bc)) + * or term = (R-R*Rc, G-G*Gc, B-B*Bc) + * fnms(a,b,c,d) computes a = d - b*c + */ + spe_fnms(f, term1R_reg, fragR_reg, constR_reg, fragR_reg); + spe_fnms(f, term1G_reg, fragG_reg, constG_reg, fragG_reg); + spe_fnms(f, term1B_reg, fragB_reg, constB_reg, fragB_reg); + break; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + /* We need the optional constant color registers */ + setup_const_register(f, &constR_reg, blend_color->color[0]); + setup_const_register(f, &constG_reg, blend_color->color[1]); + setup_const_register(f, &constB_reg, blend_color->color[2]); + /* factor = (1-Ac,1-Ac,1-Ac), so term = (R*(1-Ac),G*(1-Ac),B*(1-Ac)) + * or term = (R-R*Ac,G-G*Ac,B-B*Ac) + * fnms(a,b,c,d) computes a = d - b*c + */ + spe_fnms(f, term1R_reg, fragR_reg, constA_reg, fragR_reg); + spe_fnms(f, term1G_reg, fragG_reg, constA_reg, fragG_reg); + spe_fnms(f, term1B_reg, fragB_reg, constA_reg, fragB_reg); + break; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + /* We'll need the optional {1,1,1,1} register */ + setup_const_register(f, &one_reg, 1.0f); + /* factor = (min(A,1-Afb),min(A,1-Afb),min(A,1-Afb)), so + * term = (R*min(A,1-Afb), G*min(A,1-Afb), B*min(A,1-Afb)) + * We could expand the term (as a*min(b,c) == min(a*b,a*c) + * as long as a is positive), but then we'd have to do three + * spe_float_min() functions instead of one, so this is simpler. + */ + /* tmp = 1 - Afb */ + spe_fs(f, tmp_reg, one_reg, fbA_reg); + /* tmp = min(A,tmp) */ + spe_float_min(f, tmp_reg, fragA_reg, tmp_reg); + /* term = R*tmp */ + spe_fm(f, term1R_reg, fragR_reg, tmp_reg); + spe_fm(f, term1G_reg, fragG_reg, tmp_reg); + spe_fm(f, term1B_reg, fragB_reg, tmp_reg); + break; + + /* These are special D3D cases involving a second color output + * from the fragment shader. I'm not sure we can support them + * yet... XXX + */ + case PIPE_BLENDFACTOR_SRC1_COLOR: + case PIPE_BLENDFACTOR_SRC1_ALPHA: + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + + default: + ASSERT(0); + } + + /* + * Compute Src Alpha term. Like the above, we're looking for + * the full term A*factor, not just the factor itself, because + * in many cases we can avoid doing unnecessary multiplies. + */ + switch (blend->rt[0].alpha_src_factor) { + case PIPE_BLENDFACTOR_ZERO: + /* factor = 0, so term = 0 */ + spe_load_float(f, term1A_reg, 0.0f); + break; + + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: /* fall through */ + case PIPE_BLENDFACTOR_ONE: + /* factor = 1, so term = A */ + spe_move(f, term1A_reg, fragA_reg); + break; + + case PIPE_BLENDFACTOR_SRC_COLOR: + /* factor = A, so term = A*A */ + spe_fm(f, term1A_reg, fragA_reg, fragA_reg); + break; + case PIPE_BLENDFACTOR_SRC_ALPHA: + spe_fm(f, term1A_reg, fragA_reg, fragA_reg); + break; + + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: /* fall through */ + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + /* factor = 1-A, so term = A*(1-A) = A-A*A */ + /* fnms(a,b,c,d) computes a = d - b*c */ + spe_fnms(f, term1A_reg, fragA_reg, fragA_reg, fragA_reg); + break; + + case PIPE_BLENDFACTOR_DST_ALPHA: /* fall through */ + case PIPE_BLENDFACTOR_DST_COLOR: + /* factor = Afb, so term = A*Afb */ + spe_fm(f, term1A_reg, fragA_reg, fbA_reg); + break; + + case PIPE_BLENDFACTOR_INV_DST_ALPHA: /* fall through */ + case PIPE_BLENDFACTOR_INV_DST_COLOR: + /* factor = 1-Afb, so term = A*(1-Afb) = A - A*Afb */ + /* fnms(a,b,c,d) computes a = d - b*c */ + spe_fnms(f, term1A_reg, fragA_reg, fbA_reg, fragA_reg); + break; + + case PIPE_BLENDFACTOR_CONST_ALPHA: /* fall through */ + case PIPE_BLENDFACTOR_CONST_COLOR: + /* We need the optional constA_reg register */ + setup_const_register(f, &constA_reg, blend_color->color[3]); + /* factor = Ac, so term = A*Ac */ + spe_fm(f, term1A_reg, fragA_reg, constA_reg); + break; + + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: /* fall through */ + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + /* We need the optional constA_reg register */ + setup_const_register(f, &constA_reg, blend_color->color[3]); + /* factor = 1-Ac, so term = A*(1-Ac) = A-A*Ac */ + /* fnms(a,b,c,d) computes a = d - b*c */ + spe_fnms(f, term1A_reg, fragA_reg, constA_reg, fragA_reg); + break; + + /* These are special D3D cases involving a second color output + * from the fragment shader. I'm not sure we can support them + * yet... XXX + */ + case PIPE_BLENDFACTOR_SRC1_COLOR: + case PIPE_BLENDFACTOR_SRC1_ALPHA: + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + default: + ASSERT(0); + } + + /* + * Compute Dest RGB term. Like the above, we're looking for + * the full term (Rfb,Gfb,Bfb)*(factor), not just the factor itself, because + * in many cases we can avoid doing unnecessary multiplies. + */ + switch (blend->rt[0].rgb_dst_factor) { + case PIPE_BLENDFACTOR_ONE: + /* factors = (1,1,1), so term = (Rfb,Gfb,Bfb) */ + spe_move(f, term2R_reg, fbR_reg); + spe_move(f, term2G_reg, fbG_reg); + spe_move(f, term2B_reg, fbB_reg); + break; + case PIPE_BLENDFACTOR_ZERO: + /* factor s= (0,0,0), so term = (0,0,0) */ + spe_load_float(f, term2R_reg, 0.0f); + spe_load_float(f, term2G_reg, 0.0f); + spe_load_float(f, term2B_reg, 0.0f); + break; + case PIPE_BLENDFACTOR_SRC_COLOR: + /* factors = (R,G,B), so term = (R*Rfb, G*Gfb, B*Bfb) */ + spe_fm(f, term2R_reg, fbR_reg, fragR_reg); + spe_fm(f, term2G_reg, fbG_reg, fragG_reg); + spe_fm(f, term2B_reg, fbB_reg, fragB_reg); + break; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + /* factors = (1-R,1-G,1-B), so term = (Rfb*(1-R), Gfb*(1-G), Bfb*(1-B)) + * or in other words term = (Rfb-Rfb*R, Gfb-Gfb*G, Bfb-Bfb*B) + * fnms(a,b,c,d) computes a = d - b*c + */ + spe_fnms(f, term2R_reg, fragR_reg, fbR_reg, fbR_reg); + spe_fnms(f, term2G_reg, fragG_reg, fbG_reg, fbG_reg); + spe_fnms(f, term2B_reg, fragB_reg, fbB_reg, fbB_reg); + break; + case PIPE_BLENDFACTOR_SRC_ALPHA: + /* factors = (A,A,A), so term = (Rfb*A, Gfb*A, Bfb*A) */ + spe_fm(f, term2R_reg, fbR_reg, fragA_reg); + spe_fm(f, term2G_reg, fbG_reg, fragA_reg); + spe_fm(f, term2B_reg, fbB_reg, fragA_reg); + break; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + /* factors = (1-A,1-A,1-A) so term = (Rfb-Rfb*A,Gfb-Gfb*A,Bfb-Bfb*A) */ + /* fnms(a,b,c,d) computes a = d - b*c */ + spe_fnms(f, term2R_reg, fbR_reg, fragA_reg, fbR_reg); + spe_fnms(f, term2G_reg, fbG_reg, fragA_reg, fbG_reg); + spe_fnms(f, term2B_reg, fbB_reg, fragA_reg, fbB_reg); + break; + case PIPE_BLENDFACTOR_DST_COLOR: + /* factors = (Rfb,Gfb,Bfb), so term = (Rfb*Rfb, Gfb*Gfb, Bfb*Bfb) */ + spe_fm(f, term2R_reg, fbR_reg, fbR_reg); + spe_fm(f, term2G_reg, fbG_reg, fbG_reg); + spe_fm(f, term2B_reg, fbB_reg, fbB_reg); + break; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + /* factors = (1-Rfb,1-Gfb,1-Bfb), so term = (Rfb*(1-Rfb),Gfb*(1-Gfb),Bfb*(1-Bfb)) + * or term = (Rfb-Rfb*Rfb, Gfb-Gfb*Gfb, Bfb-Bfb*Bfb) + * fnms(a,b,c,d) computes a = d - b*c + */ + spe_fnms(f, term2R_reg, fbR_reg, fbR_reg, fbR_reg); + spe_fnms(f, term2G_reg, fbG_reg, fbG_reg, fbG_reg); + spe_fnms(f, term2B_reg, fbB_reg, fbB_reg, fbB_reg); + break; + + case PIPE_BLENDFACTOR_DST_ALPHA: + /* factors = (Afb, Afb, Afb), so term = (Rfb*Afb, Gfb*Afb, Bfb*Afb) */ + spe_fm(f, term2R_reg, fbR_reg, fbA_reg); + spe_fm(f, term2G_reg, fbG_reg, fbA_reg); + spe_fm(f, term2B_reg, fbB_reg, fbA_reg); + break; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + /* factors = (1-Afb, 1-Afb, 1-Afb), so term = (Rfb*(1-Afb),Gfb*(1-Afb),Bfb*(1-Afb)) + * or term = (Rfb-Rfb*Afb,Gfb-Gfb*Afb,Bfb-Bfb*Afb) + * fnms(a,b,c,d) computes a = d - b*c + */ + spe_fnms(f, term2R_reg, fbR_reg, fbA_reg, fbR_reg); + spe_fnms(f, term2G_reg, fbG_reg, fbA_reg, fbG_reg); + spe_fnms(f, term2B_reg, fbB_reg, fbA_reg, fbB_reg); + break; + case PIPE_BLENDFACTOR_CONST_COLOR: + /* We need the optional constant color registers */ + setup_const_register(f, &constR_reg, blend_color->color[0]); + setup_const_register(f, &constG_reg, blend_color->color[1]); + setup_const_register(f, &constB_reg, blend_color->color[2]); + /* now, factor = (Rc,Gc,Bc), so term = (Rfb*Rc,Gfb*Gc,Bfb*Bc) */ + spe_fm(f, term2R_reg, fbR_reg, constR_reg); + spe_fm(f, term2G_reg, fbG_reg, constG_reg); + spe_fm(f, term2B_reg, fbB_reg, constB_reg); + break; + case PIPE_BLENDFACTOR_CONST_ALPHA: + /* we'll need the optional constant alpha register */ + setup_const_register(f, &constA_reg, blend_color->color[3]); + /* factor = (Ac,Ac,Ac), so term = (Rfb*Ac,Gfb*Ac,Bfb*Ac) */ + spe_fm(f, term2R_reg, fbR_reg, constA_reg); + spe_fm(f, term2G_reg, fbG_reg, constA_reg); + spe_fm(f, term2B_reg, fbB_reg, constA_reg); + break; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + /* We need the optional constant color registers */ + setup_const_register(f, &constR_reg, blend_color->color[0]); + setup_const_register(f, &constG_reg, blend_color->color[1]); + setup_const_register(f, &constB_reg, blend_color->color[2]); + /* factor = (1-Rc,1-Gc,1-Bc), so term = (Rfb*(1-Rc),Gfb*(1-Gc),Bfb*(1-Bc)) + * or term = (Rfb-Rfb*Rc, Gfb-Gfb*Gc, Bfb-Bfb*Bc) + * fnms(a,b,c,d) computes a = d - b*c + */ + spe_fnms(f, term2R_reg, fbR_reg, constR_reg, fbR_reg); + spe_fnms(f, term2G_reg, fbG_reg, constG_reg, fbG_reg); + spe_fnms(f, term2B_reg, fbB_reg, constB_reg, fbB_reg); + break; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + /* We need the optional constant color registers */ + setup_const_register(f, &constR_reg, blend_color->color[0]); + setup_const_register(f, &constG_reg, blend_color->color[1]); + setup_const_register(f, &constB_reg, blend_color->color[2]); + /* factor = (1-Ac,1-Ac,1-Ac), so term = (Rfb*(1-Ac),Gfb*(1-Ac),Bfb*(1-Ac)) + * or term = (Rfb-Rfb*Ac,Gfb-Gfb*Ac,Bfb-Bfb*Ac) + * fnms(a,b,c,d) computes a = d - b*c + */ + spe_fnms(f, term2R_reg, fbR_reg, constA_reg, fbR_reg); + spe_fnms(f, term2G_reg, fbG_reg, constA_reg, fbG_reg); + spe_fnms(f, term2B_reg, fbB_reg, constA_reg, fbB_reg); + break; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: /* not supported for dest RGB */ + ASSERT(0); + break; + + /* These are special D3D cases involving a second color output + * from the fragment shader. I'm not sure we can support them + * yet... XXX + */ + case PIPE_BLENDFACTOR_SRC1_COLOR: + case PIPE_BLENDFACTOR_SRC1_ALPHA: + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + + default: + ASSERT(0); + } + + /* + * Compute Dest Alpha term. Like the above, we're looking for + * the full term Afb*factor, not just the factor itself, because + * in many cases we can avoid doing unnecessary multiplies. + */ + switch (blend->rt[0].alpha_dst_factor) { + case PIPE_BLENDFACTOR_ONE: + /* factor = 1, so term = Afb */ + spe_move(f, term2A_reg, fbA_reg); + break; + case PIPE_BLENDFACTOR_ZERO: + /* factor = 0, so term = 0 */ + spe_load_float(f, term2A_reg, 0.0f); + break; + + case PIPE_BLENDFACTOR_SRC_ALPHA: /* fall through */ + case PIPE_BLENDFACTOR_SRC_COLOR: + /* factor = A, so term = Afb*A */ + spe_fm(f, term2A_reg, fbA_reg, fragA_reg); + break; + + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: /* fall through */ + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + /* factor = 1-A, so term = Afb*(1-A) = Afb-Afb*A */ + /* fnms(a,b,c,d) computes a = d - b*c */ + spe_fnms(f, term2A_reg, fbA_reg, fragA_reg, fbA_reg); + break; + + case PIPE_BLENDFACTOR_DST_ALPHA: /* fall through */ + case PIPE_BLENDFACTOR_DST_COLOR: + /* factor = Afb, so term = Afb*Afb */ + spe_fm(f, term2A_reg, fbA_reg, fbA_reg); + break; + + case PIPE_BLENDFACTOR_INV_DST_ALPHA: /* fall through */ + case PIPE_BLENDFACTOR_INV_DST_COLOR: + /* factor = 1-Afb, so term = Afb*(1-Afb) = Afb - Afb*Afb */ + /* fnms(a,b,c,d) computes a = d - b*c */ + spe_fnms(f, term2A_reg, fbA_reg, fbA_reg, fbA_reg); + break; + + case PIPE_BLENDFACTOR_CONST_ALPHA: /* fall through */ + case PIPE_BLENDFACTOR_CONST_COLOR: + /* We need the optional constA_reg register */ + setup_const_register(f, &constA_reg, blend_color->color[3]); + /* factor = Ac, so term = Afb*Ac */ + spe_fm(f, term2A_reg, fbA_reg, constA_reg); + break; + + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: /* fall through */ + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + /* We need the optional constA_reg register */ + setup_const_register(f, &constA_reg, blend_color->color[3]); + /* factor = 1-Ac, so term = Afb*(1-Ac) = Afb-Afb*Ac */ + /* fnms(a,b,c,d) computes a = d - b*c */ + spe_fnms(f, term2A_reg, fbA_reg, constA_reg, fbA_reg); + break; + + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: /* not supported for dest alpha */ + ASSERT(0); + break; + + /* These are special D3D cases involving a second color output + * from the fragment shader. I'm not sure we can support them + * yet... XXX + */ + case PIPE_BLENDFACTOR_SRC1_COLOR: + case PIPE_BLENDFACTOR_SRC1_ALPHA: + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + default: + ASSERT(0); + } + + /* + * Combine Src/Dest RGB terms as per the blend equation. + */ + switch (blend->rt[0].rgb_func) { + case PIPE_BLEND_ADD: + spe_fa(f, fragR_reg, term1R_reg, term2R_reg); + spe_fa(f, fragG_reg, term1G_reg, term2G_reg); + spe_fa(f, fragB_reg, term1B_reg, term2B_reg); + break; + case PIPE_BLEND_SUBTRACT: + spe_fs(f, fragR_reg, term1R_reg, term2R_reg); + spe_fs(f, fragG_reg, term1G_reg, term2G_reg); + spe_fs(f, fragB_reg, term1B_reg, term2B_reg); + break; + case PIPE_BLEND_REVERSE_SUBTRACT: + spe_fs(f, fragR_reg, term2R_reg, term1R_reg); + spe_fs(f, fragG_reg, term2G_reg, term1G_reg); + spe_fs(f, fragB_reg, term2B_reg, term1B_reg); + break; + case PIPE_BLEND_MIN: + spe_float_min(f, fragR_reg, term1R_reg, term2R_reg); + spe_float_min(f, fragG_reg, term1G_reg, term2G_reg); + spe_float_min(f, fragB_reg, term1B_reg, term2B_reg); + break; + case PIPE_BLEND_MAX: + spe_float_max(f, fragR_reg, term1R_reg, term2R_reg); + spe_float_max(f, fragG_reg, term1G_reg, term2G_reg); + spe_float_max(f, fragB_reg, term1B_reg, term2B_reg); + break; + default: + ASSERT(0); + } + + /* + * Combine Src/Dest A term + */ + switch (blend->rt[0].alpha_func) { + case PIPE_BLEND_ADD: + spe_fa(f, fragA_reg, term1A_reg, term2A_reg); + break; + case PIPE_BLEND_SUBTRACT: + spe_fs(f, fragA_reg, term1A_reg, term2A_reg); + break; + case PIPE_BLEND_REVERSE_SUBTRACT: + spe_fs(f, fragA_reg, term2A_reg, term1A_reg); + break; + case PIPE_BLEND_MIN: + spe_float_min(f, fragA_reg, term1A_reg, term2A_reg); + break; + case PIPE_BLEND_MAX: + spe_float_max(f, fragA_reg, term1A_reg, term2A_reg); + break; + default: + ASSERT(0); + } + + spe_release_register(f, term1R_reg); + spe_release_register(f, term1G_reg); + spe_release_register(f, term1B_reg); + spe_release_register(f, term1A_reg); + + spe_release_register(f, term2R_reg); + spe_release_register(f, term2G_reg); + spe_release_register(f, term2B_reg); + spe_release_register(f, term2A_reg); + + spe_release_register(f, fbR_reg); + spe_release_register(f, fbG_reg); + spe_release_register(f, fbB_reg); + spe_release_register(f, fbA_reg); + + spe_release_register(f, tmp_reg); + + /* Free any optional registers that actually got used */ + release_const_register(f, one_reg); + release_const_register(f, constR_reg); + release_const_register(f, constG_reg); + release_const_register(f, constB_reg); + release_const_register(f, constA_reg); +} + + +static void +gen_logicop(const struct pipe_blend_state *blend, + struct spe_function *f, + int fragRGBA_reg, int fbRGBA_reg) +{ + /* We've got four 32-bit RGBA packed pixels in each of + * fragRGBA_reg and fbRGBA_reg, not sets of floating-point + * reds, greens, blues, and alphas. + * */ + ASSERT(blend->logicop_enable); + + switch(blend->logicop_func) { + case PIPE_LOGICOP_CLEAR: /* 0 */ + spe_zero(f, fragRGBA_reg); + break; + case PIPE_LOGICOP_NOR: /* ~(s | d) */ + spe_nor(f, fragRGBA_reg, fragRGBA_reg, fbRGBA_reg); + break; + case PIPE_LOGICOP_AND_INVERTED: /* ~s & d */ + /* andc R, A, B computes R = A & ~B */ + spe_andc(f, fragRGBA_reg, fbRGBA_reg, fragRGBA_reg); + break; + case PIPE_LOGICOP_COPY_INVERTED: /* ~s */ + spe_complement(f, fragRGBA_reg, fragRGBA_reg); + break; + case PIPE_LOGICOP_AND_REVERSE: /* s & ~d */ + /* andc R, A, B computes R = A & ~B */ + spe_andc(f, fragRGBA_reg, fragRGBA_reg, fbRGBA_reg); + break; + case PIPE_LOGICOP_INVERT: /* ~d */ + /* Note that (A nor A) == ~(A|A) == ~A */ + spe_nor(f, fragRGBA_reg, fbRGBA_reg, fbRGBA_reg); + break; + case PIPE_LOGICOP_XOR: /* s ^ d */ + spe_xor(f, fragRGBA_reg, fragRGBA_reg, fbRGBA_reg); + break; + case PIPE_LOGICOP_NAND: /* ~(s & d) */ + spe_nand(f, fragRGBA_reg, fragRGBA_reg, fbRGBA_reg); + break; + case PIPE_LOGICOP_AND: /* s & d */ + spe_and(f, fragRGBA_reg, fragRGBA_reg, fbRGBA_reg); + break; + case PIPE_LOGICOP_EQUIV: /* ~(s ^ d) */ + spe_xor(f, fragRGBA_reg, fragRGBA_reg, fbRGBA_reg); + spe_complement(f, fragRGBA_reg, fragRGBA_reg); + break; + case PIPE_LOGICOP_NOOP: /* d */ + spe_move(f, fragRGBA_reg, fbRGBA_reg); + break; + case PIPE_LOGICOP_OR_INVERTED: /* ~s | d */ + /* orc R, A, B computes R = A | ~B */ + spe_orc(f, fragRGBA_reg, fbRGBA_reg, fragRGBA_reg); + break; + case PIPE_LOGICOP_COPY: /* s */ + break; + case PIPE_LOGICOP_OR_REVERSE: /* s | ~d */ + /* orc R, A, B computes R = A | ~B */ + spe_orc(f, fragRGBA_reg, fragRGBA_reg, fbRGBA_reg); + break; + case PIPE_LOGICOP_OR: /* s | d */ + spe_or(f, fragRGBA_reg, fragRGBA_reg, fbRGBA_reg); + break; + case PIPE_LOGICOP_SET: /* 1 */ + spe_load_int(f, fragRGBA_reg, 0xffffffff); + break; + default: + ASSERT(0); + } +} + + +/** + * Generate code to pack a quad of float colors into four 32-bit integers. + * + * \param f SPE function to append instruction onto. + * \param color_format the dest color packing format + * \param r_reg register containing four red values (in/clobbered) + * \param g_reg register containing four green values (in/clobbered) + * \param b_reg register containing four blue values (in/clobbered) + * \param a_reg register containing four alpha values (in/clobbered) + * \param rgba_reg register to store the packed RGBA colors (out) + */ +static void +gen_pack_colors(struct spe_function *f, + enum pipe_format color_format, + int r_reg, int g_reg, int b_reg, int a_reg, + int rgba_reg) +{ + int rg_reg = spe_allocate_available_register(f); + int ba_reg = spe_allocate_available_register(f); + + /* Convert float[4] in [0.0,1.0] to int[4] in [0,~0], with clamping */ + spe_cfltu(f, r_reg, r_reg, 32); + spe_cfltu(f, g_reg, g_reg, 32); + spe_cfltu(f, b_reg, b_reg, 32); + spe_cfltu(f, a_reg, a_reg, 32); + + /* Shift the most significant bytes to the least significant positions. + * I.e.: reg = reg >> 24 + */ + spe_rotmi(f, r_reg, r_reg, -24); + spe_rotmi(f, g_reg, g_reg, -24); + spe_rotmi(f, b_reg, b_reg, -24); + spe_rotmi(f, a_reg, a_reg, -24); + + /* Shift the color bytes according to the surface format */ + if (color_format == PIPE_FORMAT_B8G8R8A8_UNORM) { + spe_roti(f, g_reg, g_reg, 8); /* green <<= 8 */ + spe_roti(f, r_reg, r_reg, 16); /* red <<= 16 */ + spe_roti(f, a_reg, a_reg, 24); /* alpha <<= 24 */ + } + else if (color_format == PIPE_FORMAT_A8R8G8B8_UNORM) { + spe_roti(f, r_reg, r_reg, 8); /* red <<= 8 */ + spe_roti(f, g_reg, g_reg, 16); /* green <<= 16 */ + spe_roti(f, b_reg, b_reg, 24); /* blue <<= 24 */ + } + else { + ASSERT(0); + } + + /* Merge red, green, blue, alpha registers to make packed RGBA colors. + * Eg: after shifting according to color_format we might have: + * R = {0x00ff0000, 0x00110000, 0x00220000, 0x00330000} + * G = {0x0000ff00, 0x00004400, 0x00005500, 0x00006600} + * B = {0x000000ff, 0x00000077, 0x00000088, 0x00000099} + * A = {0xff000000, 0xaa000000, 0xbb000000, 0xcc000000} + * OR-ing all those together gives us four packed colors: + * RGBA = {0xffffffff, 0xaa114477, 0xbb225588, 0xcc336699} + */ + spe_or(f, rg_reg, r_reg, g_reg); + spe_or(f, ba_reg, a_reg, b_reg); + spe_or(f, rgba_reg, rg_reg, ba_reg); + + spe_release_register(f, rg_reg); + spe_release_register(f, ba_reg); +} + + +static void +gen_colormask(struct spe_function *f, + uint colormask, + enum pipe_format color_format, + int fragRGBA_reg, int fbRGBA_reg) +{ + /* We've got four 32-bit RGBA packed pixels in each of + * fragRGBA_reg and fbRGBA_reg, not sets of floating-point + * reds, greens, blues, and alphas. Further, the pixels + * are packed according to the given color format, not + * necessarily RGBA... + */ + uint r_mask; + uint g_mask; + uint b_mask; + uint a_mask; + + /* Calculate exactly where the bits for any particular color + * end up, so we can mask them correctly. + */ + switch(color_format) { + case PIPE_FORMAT_B8G8R8A8_UNORM: + /* ARGB */ + a_mask = 0xff000000; + r_mask = 0x00ff0000; + g_mask = 0x0000ff00; + b_mask = 0x000000ff; + break; + case PIPE_FORMAT_A8R8G8B8_UNORM: + /* BGRA */ + b_mask = 0xff000000; + g_mask = 0x00ff0000; + r_mask = 0x0000ff00; + a_mask = 0x000000ff; + break; + default: + ASSERT(0); + } + + /* For each R, G, B, and A component we're supposed to mask out, + * clear its bits. Then our mask operation later will work + * as expected. + */ + if (!(colormask & PIPE_MASK_R)) { + r_mask = 0; + } + if (!(colormask & PIPE_MASK_G)) { + g_mask = 0; + } + if (!(colormask & PIPE_MASK_B)) { + b_mask = 0; + } + if (!(colormask & PIPE_MASK_A)) { + a_mask = 0; + } + + /* Get a temporary register to hold the mask that will be applied + * to the fragment + */ + int colormask_reg = spe_allocate_available_register(f); + + /* The actual mask we're going to use is an OR of the remaining R, G, B, + * and A masks. Load the result value into our temporary register. + */ + spe_load_uint(f, colormask_reg, r_mask | g_mask | b_mask | a_mask); + + /* Use the mask register to select between the fragment color + * values and the frame buffer color values. Wherever the + * mask has a 0 bit, the current frame buffer color should override + * the fragment color. Wherever the mask has a 1 bit, the + * fragment color should persevere. The Select Bits (selb rt, rA, rB, rM) + * instruction will select bits from its first operand rA wherever the + * the mask bits rM are 0, and from its second operand rB wherever the + * mask bits rM are 1. That means that the frame buffer color is the + * first operand, and the fragment color the second. + */ + spe_selb(f, fragRGBA_reg, fbRGBA_reg, fragRGBA_reg, colormask_reg); + + /* Release the temporary register and we're done */ + spe_release_register(f, colormask_reg); +} + + +/** + * This function is annoyingly similar to gen_depth_test(), above, except + * that instead of comparing two varying values (i.e. fragment and buffer), + * we're comparing a varying value with a static value. As such, we have + * access to the Compare Immediate instructions where we don't in + * gen_depth_test(), which is what makes us very different. + * + * There's some added complexity if there's a non-trivial state->mask + * value; then stencil and reference both must be masked + * + * The return value in the stencil_pass_reg is a bitmask of valid + * fragments that also passed the stencil test. The bitmask of valid + * fragments that failed would be found in + * (fragment_mask_reg & ~stencil_pass_reg). + */ +static void +gen_stencil_test(struct spe_function *f, + const struct pipe_stencil_state *state, + const unsigned ref_value, + uint stencil_max_value, + int fragment_mask_reg, + int fbS_reg, + int stencil_pass_reg) +{ + /* Generate code that puts the set of passing fragments into the + * stencil_pass_reg register, taking into account whether each fragment + * was active to begin with. + */ + switch (state->func) { + case PIPE_FUNC_EQUAL: + if (state->valuemask == stencil_max_value) { + /* stencil_pass = fragment_mask & (s == reference) */ + spe_compare_equal_uint(f, stencil_pass_reg, fbS_reg, ref_value); + spe_and(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); + } + else { + /* stencil_pass = fragment_mask & ((s&mask) == (reference&mask)) */ + uint tmp_masked_stencil = spe_allocate_available_register(f); + spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->valuemask); + spe_compare_equal_uint(f, stencil_pass_reg, tmp_masked_stencil, + state->valuemask & ref_value); + spe_and(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); + spe_release_register(f, tmp_masked_stencil); + } + break; + + case PIPE_FUNC_NOTEQUAL: + if (state->valuemask == stencil_max_value) { + /* stencil_pass = fragment_mask & ~(s == reference) */ + spe_compare_equal_uint(f, stencil_pass_reg, fbS_reg, ref_value); + spe_andc(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); + } + else { + /* stencil_pass = fragment_mask & ~((s&mask) == (reference&mask)) */ + int tmp_masked_stencil = spe_allocate_available_register(f); + spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->valuemask); + spe_compare_equal_uint(f, stencil_pass_reg, tmp_masked_stencil, + state->valuemask & ref_value); + spe_andc(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); + spe_release_register(f, tmp_masked_stencil); + } + break; + + case PIPE_FUNC_LESS: + if (state->valuemask == stencil_max_value) { + /* stencil_pass = fragment_mask & (reference < s) */ + spe_compare_greater_uint(f, stencil_pass_reg, fbS_reg, ref_value); + spe_and(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); + } + else { + /* stencil_pass = fragment_mask & ((reference&mask) < (s & mask)) */ + int tmp_masked_stencil = spe_allocate_available_register(f); + spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->valuemask); + spe_compare_greater_uint(f, stencil_pass_reg, tmp_masked_stencil, + state->valuemask & ref_value); + spe_and(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); + spe_release_register(f, tmp_masked_stencil); + } + break; + + case PIPE_FUNC_GREATER: + if (state->valuemask == stencil_max_value) { + /* stencil_pass = fragment_mask & (reference > s) */ + /* There's no convenient Compare Less Than Immediate instruction, so + * we'll have to do this one the harder way, by loading a register and + * comparing directly. Compare Logical Greater Than Word (clgt) + * treats its operands as unsigned - no sign extension. + */ + int tmp_reg = spe_allocate_available_register(f); + spe_load_uint(f, tmp_reg, ref_value); + spe_clgt(f, stencil_pass_reg, tmp_reg, fbS_reg); + spe_and(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); + spe_release_register(f, tmp_reg); + } + else { + /* stencil_pass = fragment_mask & ((reference&mask) > (s&mask)) */ + int tmp_reg = spe_allocate_available_register(f); + int tmp_masked_stencil = spe_allocate_available_register(f); + spe_load_uint(f, tmp_reg, state->valuemask & ref_value); + spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->valuemask); + spe_clgt(f, stencil_pass_reg, tmp_reg, tmp_masked_stencil); + spe_and(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); + spe_release_register(f, tmp_reg); + spe_release_register(f, tmp_masked_stencil); + } + break; + + case PIPE_FUNC_GEQUAL: + if (state->valuemask == stencil_max_value) { + /* stencil_pass = fragment_mask & (reference >= s) + * = fragment_mask & ~(s > reference) */ + spe_compare_greater_uint(f, stencil_pass_reg, fbS_reg, + ref_value); + spe_andc(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); + } + else { + /* stencil_pass = fragment_mask & ~((s&mask) > (reference&mask)) */ + int tmp_masked_stencil = spe_allocate_available_register(f); + spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->valuemask); + spe_compare_greater_uint(f, stencil_pass_reg, tmp_masked_stencil, + state->valuemask & ref_value); + spe_andc(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); + spe_release_register(f, tmp_masked_stencil); + } + break; + + case PIPE_FUNC_LEQUAL: + if (state->valuemask == stencil_max_value) { + /* stencil_pass = fragment_mask & (reference <= s) ] + * = fragment_mask & ~(reference > s) */ + /* As above, we have to do this by loading a register */ + int tmp_reg = spe_allocate_available_register(f); + spe_load_uint(f, tmp_reg, ref_value); + spe_clgt(f, stencil_pass_reg, tmp_reg, fbS_reg); + spe_andc(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); + spe_release_register(f, tmp_reg); + } + else { + /* stencil_pass = fragment_mask & ~((reference&mask) > (s&mask)) */ + int tmp_reg = spe_allocate_available_register(f); + int tmp_masked_stencil = spe_allocate_available_register(f); + spe_load_uint(f, tmp_reg, ref_value & state->valuemask); + spe_and_uint(f, tmp_masked_stencil, fbS_reg, state->valuemask); + spe_clgt(f, stencil_pass_reg, tmp_reg, tmp_masked_stencil); + spe_andc(f, stencil_pass_reg, fragment_mask_reg, stencil_pass_reg); + spe_release_register(f, tmp_reg); + spe_release_register(f, tmp_masked_stencil); + } + break; + + case PIPE_FUNC_NEVER: + /* stencil_pass = fragment_mask & 0 = 0 */ + spe_load_uint(f, stencil_pass_reg, 0); + break; + + case PIPE_FUNC_ALWAYS: + /* stencil_pass = fragment_mask & 1 = fragment_mask */ + spe_move(f, stencil_pass_reg, fragment_mask_reg); + break; + } + + /* The fragments that passed the stencil test are now in stencil_pass_reg. + * The fragments that failed would be (fragment_mask_reg & ~stencil_pass_reg). + */ +} + + +/** + * This function generates code that calculates a set of new stencil values + * given the earlier values and the operation to apply. It does not + * apply any tests. It is intended to be called up to 3 times + * (for the stencil fail operation, for the stencil pass-z fail operation, + * and for the stencil pass-z pass operation) to collect up to three + * possible sets of values, and for the caller to combine them based + * on the result of the tests. + * + * stencil_max_value should be (2^n - 1) where n is the number of bits + * in the stencil buffer - in other words, it should be usable as a mask. + */ +static void +gen_stencil_values(struct spe_function *f, + uint stencil_op, + uint stencil_ref_value, + uint stencil_max_value, + int fbS_reg, + int newS_reg) +{ + /* The code below assumes that newS_reg and fbS_reg are not the same + * register; if they can be, the calculations below will have to use + * an additional temporary register. For now, mark the assumption + * with an assertion that will fail if they are the same. + */ + ASSERT(fbS_reg != newS_reg); + + /* The code also assumes that the stencil_max_value is of the form + * 2^n-1 and can therefore be used as a mask for the valid bits in + * addition to a maximum. Make sure this is the case as well. + * The clever math below exploits the fact that incrementing a + * binary number serves to flip all the bits of a number starting at + * the LSB and continuing to (and including) the first zero bit + * found. That means that a number and its increment will always + * have at least one bit in common (the high order bit, if nothing + * else) *unless* the number is zero, *or* the number is of a form + * consisting of some number of 1s in the low-order bits followed + * by nothing but 0s in the high-order bits. The latter case + * implies it's of the form 2^n-1. + */ + ASSERT(stencil_max_value > 0 && ((stencil_max_value + 1) & stencil_max_value) == 0); + + switch(stencil_op) { + case PIPE_STENCIL_OP_KEEP: + /* newS = S */ + spe_move(f, newS_reg, fbS_reg); + break; + + case PIPE_STENCIL_OP_ZERO: + /* newS = 0 */ + spe_zero(f, newS_reg); + break; + + case PIPE_STENCIL_OP_REPLACE: + /* newS = stencil reference value */ + spe_load_uint(f, newS_reg, stencil_ref_value); + break; + + case PIPE_STENCIL_OP_INCR: { + /* newS = (s == max ? max : s + 1) */ + int equals_reg = spe_allocate_available_register(f); + + spe_compare_equal_uint(f, equals_reg, fbS_reg, stencil_max_value); + /* Add Word Immediate computes rT = rA + 10-bit signed immediate */ + spe_ai(f, newS_reg, fbS_reg, 1); + /* Select from the current value or the new value based on the equality test */ + spe_selb(f, newS_reg, newS_reg, fbS_reg, equals_reg); + + spe_release_register(f, equals_reg); + break; + } + case PIPE_STENCIL_OP_DECR: { + /* newS = (s == 0 ? 0 : s - 1) */ + int equals_reg = spe_allocate_available_register(f); + + spe_compare_equal_uint(f, equals_reg, fbS_reg, 0); + /* Add Word Immediate with a (-1) value works */ + spe_ai(f, newS_reg, fbS_reg, -1); + /* Select from the current value or the new value based on the equality test */ + spe_selb(f, newS_reg, newS_reg, fbS_reg, equals_reg); + + spe_release_register(f, equals_reg); + break; + } + case PIPE_STENCIL_OP_INCR_WRAP: + /* newS = (s == max ? 0 : s + 1), but since max is 2^n-1, we can + * do a normal add and mask off the correct bits + */ + spe_ai(f, newS_reg, fbS_reg, 1); + spe_and_uint(f, newS_reg, newS_reg, stencil_max_value); + break; + + case PIPE_STENCIL_OP_DECR_WRAP: + /* newS = (s == 0 ? max : s - 1), but we'll pull the same mask trick as above */ + spe_ai(f, newS_reg, fbS_reg, -1); + spe_and_uint(f, newS_reg, newS_reg, stencil_max_value); + break; + + case PIPE_STENCIL_OP_INVERT: + /* newS = ~s. We take advantage of the mask/max value to invert only + * the valid bits for the field so we don't have to do an extra "and". + */ + spe_xor_uint(f, newS_reg, fbS_reg, stencil_max_value); + break; + + default: + ASSERT(0); + } +} + + +/** + * This function generates code to get all the necessary possible + * stencil values. For each of the output registers (fail_reg, + * zfail_reg, and zpass_reg), it either allocates a new register + * and calculates a new set of values based on the stencil operation, + * or it reuses a register allocation and calculation done for an + * earlier (matching) operation, or it reuses the fbS_reg register + * (if the stencil operation is KEEP, which doesn't change the + * stencil buffer). + * + * Since this function allocates a variable number of registers, + * to avoid incurring complex logic to free them, they should + * be allocated after a spe_allocate_register_set() call + * and released by the corresponding spe_release_register_set() call. + */ +static void +gen_get_stencil_values(struct spe_function *f, + const struct pipe_stencil_state *stencil, + const unsigned ref_value, + const uint depth_enabled, + int fbS_reg, + int *fail_reg, + int *zfail_reg, + int *zpass_reg) +{ + uint zfail_op; + + /* Stenciling had better be enabled here */ + ASSERT(stencil->enabled); + + /* If the depth test is not enabled, it is treated as though it always + * passes, which means that the zfail_op is not considered - a + * failing stencil test triggers the fail_op, and a passing one + * triggers the zpass_op + * + * As an optimization, override calculation of the zfail_op values + * if they aren't going to be used. By setting the value of + * the operation to PIPE_STENCIL_OP_KEEP, its value will be assumed + * to match the incoming stencil values, and no calculation will + * be done. + */ + if (depth_enabled) { + zfail_op = stencil->zfail_op; + } + else { + zfail_op = PIPE_STENCIL_OP_KEEP; + } + + /* One-sided or front-facing stencil */ + if (stencil->fail_op == PIPE_STENCIL_OP_KEEP) { + *fail_reg = fbS_reg; + } + else { + *fail_reg = spe_allocate_available_register(f); + gen_stencil_values(f, stencil->fail_op, ref_value, + 0xff, fbS_reg, *fail_reg); + } + + /* Check the possibly overridden value, not the structure value */ + if (zfail_op == PIPE_STENCIL_OP_KEEP) { + *zfail_reg = fbS_reg; + } + else if (zfail_op == stencil->fail_op) { + *zfail_reg = *fail_reg; + } + else { + *zfail_reg = spe_allocate_available_register(f); + gen_stencil_values(f, stencil->zfail_op, ref_value, + 0xff, fbS_reg, *zfail_reg); + } + + if (stencil->zpass_op == PIPE_STENCIL_OP_KEEP) { + *zpass_reg = fbS_reg; + } + else if (stencil->zpass_op == stencil->fail_op) { + *zpass_reg = *fail_reg; + } + else if (stencil->zpass_op == zfail_op) { + *zpass_reg = *zfail_reg; + } + else { + *zpass_reg = spe_allocate_available_register(f); + gen_stencil_values(f, stencil->zpass_op, ref_value, + 0xff, fbS_reg, *zpass_reg); + } +} + +/** + * Note that fbZ_reg may *not* be set on entry, if in fact + * the depth test is not enabled. This function must not use + * the register if depth is not enabled. + */ +static boolean +gen_stencil_depth_test(struct spe_function *f, + const struct pipe_depth_stencil_alpha_state *dsa, + const struct pipe_stencil_ref *stencil_ref, + const uint facing, + const int mask_reg, const int fragZ_reg, + const int fbZ_reg, const int fbS_reg) +{ + /* True if we've generated code that could require writeback to the + * depth and/or stencil buffers + */ + boolean modified_buffers = FALSE; + + boolean need_to_calculate_stencil_values; + boolean need_to_writemask_stencil_values; + + struct pipe_stencil_state *stencil; + + /* Registers. We may or may not actually allocate these, depending + * on whether the state values indicate that we need them. + */ + int stencil_pass_reg, stencil_fail_reg; + int stencil_fail_values, stencil_pass_depth_fail_values, stencil_pass_depth_pass_values; + int stencil_writemask_reg; + int zmask_reg; + int newS_reg; + unsigned ref_value; + + /* Stenciling is quite complex: up to six different configurable stencil + * operations/calculations can be required (three each for front-facing + * and back-facing fragments). Many of those operations will likely + * be identical, so there's good reason to try to avoid calculating + * the same values more than once (which unfortunately makes the code less + * straightforward). + * + * To make register management easier, we start a new + * register set; we can release all the registers in the set at + * once, and avoid having to keep track of exactly which registers + * we allocate. We can still allocate and free registers as + * desired (if we know we no longer need a register), but we don't + * have to spend the complexity to track the more difficult variant + * register usage scenarios. + */ + spe_comment(f, 0, "Allocating stencil register set"); + spe_allocate_register_set(f); + + /* The facing we're given is the fragment facing; it doesn't + * exactly match the stencil facing. If stencil is enabled, + * but two-sided stencil is *not* enabled, we use the same + * stencil settings for both front- and back-facing fragments. + * We only use the "back-facing" stencil for backfacing fragments + * if two-sided stenciling is enabled. + */ + if (facing == CELL_FACING_BACK && dsa->stencil[1].enabled) { + stencil = &dsa->stencil[1]; + ref_value = stencil_ref->ref_value[1]; + } + else { + stencil = &dsa->stencil[0]; + ref_value = stencil_ref->ref_value[0]; + } + + /* Calculate the writemask. If the writemask is trivial (either + * all 0s, meaning that we don't need to calculate any stencil values + * because they're not going to change the stencil anyway, or all 1s, + * meaning that we have to calculate the stencil values but do not + * need to mask them), we can avoid generating code. Don't forget + * that we need to consider backfacing stencil, if enabled. + * + * Note that if the backface stencil is *not* enabled, the backface + * stencil will have the same values as the frontface stencil. + */ + if (stencil->fail_op == PIPE_STENCIL_OP_KEEP && + stencil->zfail_op == PIPE_STENCIL_OP_KEEP && + stencil->zpass_op == PIPE_STENCIL_OP_KEEP) { + need_to_calculate_stencil_values = FALSE; + need_to_writemask_stencil_values = FALSE; + } + else if (stencil->writemask == 0x0) { + /* All changes are writemasked out, so no need to calculate + * what those changes might be, and no need to write anything back. + */ + need_to_calculate_stencil_values = FALSE; + need_to_writemask_stencil_values = FALSE; + } + else if (stencil->writemask == 0xff) { + /* Still trivial, but a little less so. We need to write the stencil + * values, but we don't need to mask them. + */ + need_to_calculate_stencil_values = TRUE; + need_to_writemask_stencil_values = FALSE; + } + else { + /* The general case: calculate, mask, and write */ + need_to_calculate_stencil_values = TRUE; + need_to_writemask_stencil_values = TRUE; + + /* While we're here, generate code that calculates what the + * writemask should be. If backface stenciling is enabled, + * and the backface writemask is not the same as the frontface + * writemask, we'll have to generate code that merges the + * two masks into a single effective mask based on fragment facing. + */ + spe_comment(f, 0, "Computing stencil writemask"); + stencil_writemask_reg = spe_allocate_available_register(f); + spe_load_uint(f, stencil_writemask_reg, dsa->stencil[facing].writemask); + } + + /* At least one-sided stenciling must be on. Generate code that + * runs the stencil test on the basic/front-facing stencil, leaving + * the mask of passing stencil bits in stencil_pass_reg. This mask will + * be used both to mask the set of active pixels, and also to + * determine how the stencil buffer changes. + * + * This test will *not* change the value in mask_reg (because we don't + * yet know whether to apply the two-sided stencil or one-sided stencil). + */ + spe_comment(f, 0, "Running basic stencil test"); + stencil_pass_reg = spe_allocate_available_register(f); + gen_stencil_test(f, stencil, ref_value, 0xff, mask_reg, fbS_reg, stencil_pass_reg); + + /* Generate code that, given the mask of valid fragments and the + * mask of valid fragments that passed the stencil test, computes + * the mask of valid fragments that failed the stencil test. We + * have to do this before we run a depth test (because the + * depth test should not be performed on fragments that failed the + * stencil test, and because the depth test will update the + * mask of valid fragments based on the results of the depth test). + */ + spe_comment(f, 0, "Computing stencil fail mask and updating fragment mask"); + stencil_fail_reg = spe_allocate_available_register(f); + spe_andc(f, stencil_fail_reg, mask_reg, stencil_pass_reg); + /* Now remove the stenciled-out pixels from the valid fragment mask, + * so we can later use the valid fragment mask in the depth test. + */ + spe_and(f, mask_reg, mask_reg, stencil_pass_reg); + + /* We may not need to calculate stencil values, if the writemask is off */ + if (need_to_calculate_stencil_values) { + /* Generate code that calculates exactly which stencil values we need, + * without calculating the same value twice (say, if two different + * stencil ops have the same value). This code will work for one-sided + * and two-sided stenciling (so that we take into account that operations + * may match between front and back stencils), and will also take into + * account whether the depth test is enabled (if the depth test is off, + * we don't need any of the zfail results, because the depth test always + * is considered to pass if it is disabled). Any register value that + * does not need to be calculated will come back with the same value + * that's in fbS_reg. + * + * This function will allocate a variant number of registers that + * will be released as part of the register set. + */ + spe_comment(f, 0, facing == CELL_FACING_FRONT + ? "Computing front-facing stencil values" + : "Computing back-facing stencil values"); + gen_get_stencil_values(f, stencil, ref_value, dsa->depth.enabled, fbS_reg, + &stencil_fail_values, &stencil_pass_depth_fail_values, + &stencil_pass_depth_pass_values); + } + + /* We now have all the stencil values we need. We also need + * the results of the depth test to figure out which + * stencil values will become the new stencil values. (Even if + * we aren't actually calculating stencil values, we need to apply + * the depth test if it's enabled.) + * + * The code generated by gen_depth_test() returns the results of the + * test in the given register, but also alters the mask_reg based + * on the results of the test. + */ + if (dsa->depth.enabled) { + spe_comment(f, 0, "Running stencil depth test"); + zmask_reg = spe_allocate_available_register(f); + modified_buffers |= gen_depth_test(f, dsa, mask_reg, fragZ_reg, + fbZ_reg, zmask_reg); + } + + if (need_to_calculate_stencil_values) { + + /* If we need to writemask the stencil values before going into + * the stencil buffer, we'll have to use a new register to + * hold the new values. If not, we can just keep using the + * current register. + */ + if (need_to_writemask_stencil_values) { + newS_reg = spe_allocate_available_register(f); + spe_comment(f, 0, "Saving current stencil values for writemasking"); + spe_move(f, newS_reg, fbS_reg); + } + else { + newS_reg = fbS_reg; + } + + /* Merge in the selected stencil fail values */ + if (stencil_fail_values != fbS_reg) { + spe_comment(f, 0, "Loading stencil fail values"); + spe_selb(f, newS_reg, newS_reg, stencil_fail_values, stencil_fail_reg); + modified_buffers = TRUE; + } + + /* Same for the stencil pass/depth fail values. If this calculation + * is not needed (say, if depth test is off), then the + * stencil_pass_depth_fail_values register will be equal to fbS_reg + * and we'll skip the calculation. + */ + if (stencil_pass_depth_fail_values != fbS_reg) { + /* We don't actually have a stencil pass/depth fail mask yet. + * Calculate it here from the stencil passing mask and the + * depth passing mask. Note that zmask_reg *must* have been + * set above if we're here. + */ + uint stencil_pass_depth_fail_mask = + spe_allocate_available_register(f); + + spe_comment(f, 0, "Loading stencil pass/depth fail values"); + spe_andc(f, stencil_pass_depth_fail_mask, stencil_pass_reg, zmask_reg); + + spe_selb(f, newS_reg, newS_reg, stencil_pass_depth_fail_values, + stencil_pass_depth_fail_mask); + + spe_release_register(f, stencil_pass_depth_fail_mask); + modified_buffers = TRUE; + } + + /* Same for the stencil pass/depth pass mask. Note that we + * *can* get here with zmask_reg being unset (if the depth + * test is off but the stencil test is on). In this case, + * we assume the depth test passes, and don't need to mask + * the stencil pass mask with the Z mask. + */ + if (stencil_pass_depth_pass_values != fbS_reg) { + if (dsa->depth.enabled) { + uint stencil_pass_depth_pass_mask = spe_allocate_available_register(f); + /* We'll need a separate register */ + spe_comment(f, 0, "Loading stencil pass/depth pass values"); + spe_and(f, stencil_pass_depth_pass_mask, stencil_pass_reg, zmask_reg); + spe_selb(f, newS_reg, newS_reg, stencil_pass_depth_pass_values, stencil_pass_depth_pass_mask); + spe_release_register(f, stencil_pass_depth_pass_mask); + } + else { + /* We can use the same stencil-pass register */ + spe_comment(f, 0, "Loading stencil pass values"); + spe_selb(f, newS_reg, newS_reg, stencil_pass_depth_pass_values, stencil_pass_reg); + } + modified_buffers = TRUE; + } + + /* Almost done. If we need to writemask, do it now, leaving the + * results in the fbS_reg register passed in. If we don't need + * to writemask, then the results are *already* in the fbS_reg, + * so there's nothing more to do. + */ + + if (need_to_writemask_stencil_values && modified_buffers) { + /* The Select Bytes command makes a fine writemask. Where + * the mask is 0, the first (original) values are retained, + * effectively masking out changes. Where the mask is 1, the + * second (new) values are retained, incorporating changes. + */ + spe_comment(f, 0, "Writemasking new stencil values"); + spe_selb(f, fbS_reg, fbS_reg, newS_reg, stencil_writemask_reg); + } + + } /* done calculating stencil values */ + + /* The stencil and/or depth values have been applied, and the + * mask_reg, fbS_reg, and fbZ_reg values have been updated. + * We're all done, except that we've allocated a fair number + * of registers that we didn't bother tracking. Release all + * those registers as part of the register set, and go home. + */ + spe_comment(f, 0, "Releasing stencil register set"); + spe_release_register_set(f); + + /* Return TRUE if we could have modified the stencil and/or + * depth buffers. + */ + return modified_buffers; +} + + +/** + * Generate depth and/or stencil test code. + * \param cell context + * \param dsa depth/stencil/alpha state + * \param f spe function to emit + * \param facing either CELL_FACING_FRONT or CELL_FACING_BACK + * \param mask_reg register containing the pixel alive/dead mask + * \param depth_tile_reg register containing address of z/stencil tile + * \param quad_offset_reg offset to quad from start of tile + * \param fragZ_reg register containg fragment Z values + */ +static void +gen_depth_stencil(struct cell_context *cell, + const struct pipe_depth_stencil_alpha_state *dsa, + const struct pipe_stencil_ref *stencil_ref, + struct spe_function *f, + uint facing, + int mask_reg, + int depth_tile_reg, + int quad_offset_reg, + int fragZ_reg) + +{ + const enum pipe_format zs_format = cell->framebuffer.zsbuf->format; + boolean write_depth_stencil; + + /* framebuffer's combined z/stencil values register */ + int fbZS_reg = spe_allocate_available_register(f); + + /* Framebufer Z values register */ + int fbZ_reg = spe_allocate_available_register(f); + + /* Framebuffer stencil values register (may not be used) */ + int fbS_reg = spe_allocate_available_register(f); + + /* 24-bit mask register (may not be used) */ + int zmask_reg = spe_allocate_available_register(f); + + /** + * The following code: + * 1. fetch quad of packed Z/S values from the framebuffer tile. + * 2. extract the separate the Z and S values from packed values + * 3. convert fragment Z values from float in [0,1] to 32/24/16-bit ints + * + * The instructions for doing this are interleaved for better performance. + */ + spe_comment(f, 0, "Fetch Z/stencil quad from tile"); + + switch(zs_format) { + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: /* fall through */ + case PIPE_FORMAT_Z24X8_UNORM: + /* prepare mask to extract Z vals from ZS vals */ + spe_load_uint(f, zmask_reg, 0x00ffffff); + + /* convert fragment Z from [0,1] to 32-bit ints */ + spe_cfltu(f, fragZ_reg, fragZ_reg, 32); + + /* Load: fbZS_reg = memory[depth_tile_reg + offset_reg] */ + spe_lqx(f, fbZS_reg, depth_tile_reg, quad_offset_reg); + + /* right shift 32-bit fragment Z to 24 bits */ + spe_rotmi(f, fragZ_reg, fragZ_reg, -8); + + /* extract 24-bit Z values from ZS values by masking */ + spe_and(f, fbZ_reg, fbZS_reg, zmask_reg); + + /* extract 8-bit stencil values by shifting */ + spe_rotmi(f, fbS_reg, fbZS_reg, -24); + break; + + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: /* fall through */ + case PIPE_FORMAT_X8Z24_UNORM: + /* convert fragment Z from [0,1] to 32-bit ints */ + spe_cfltu(f, fragZ_reg, fragZ_reg, 32); + + /* Load: fbZS_reg = memory[depth_tile_reg + offset_reg] */ + spe_lqx(f, fbZS_reg, depth_tile_reg, quad_offset_reg); + + /* right shift 32-bit fragment Z to 24 bits */ + spe_rotmi(f, fragZ_reg, fragZ_reg, -8); + + /* extract 24-bit Z values from ZS values by shifting */ + spe_rotmi(f, fbZ_reg, fbZS_reg, -8); + + /* extract 8-bit stencil values by masking */ + spe_and_uint(f, fbS_reg, fbZS_reg, 0x000000ff); + break; + + case PIPE_FORMAT_Z32_UNORM: + /* Load: fbZ_reg = memory[depth_tile_reg + offset_reg] */ + spe_lqx(f, fbZ_reg, depth_tile_reg, quad_offset_reg); + + /* convert fragment Z from [0,1] to 32-bit ints */ + spe_cfltu(f, fragZ_reg, fragZ_reg, 32); + + /* No stencil, so can't do anything there */ + break; + + case PIPE_FORMAT_Z16_UNORM: + /* XXX This code for 16bpp Z is broken! */ + + /* Load: fbZS_reg = memory[depth_tile_reg + offset_reg] */ + spe_lqx(f, fbZS_reg, depth_tile_reg, quad_offset_reg); + + /* Copy over 4 32-bit values */ + spe_move(f, fbZ_reg, fbZS_reg); + + /* convert Z from [0,1] to 16-bit ints */ + spe_cfltu(f, fragZ_reg, fragZ_reg, 32); + spe_rotmi(f, fragZ_reg, fragZ_reg, -16); + /* No stencil */ + break; + + default: + ASSERT(0); /* invalid format */ + } + + /* If stencil is enabled, use the stencil-specific code + * generator to generate both the stencil and depth (if needed) + * tests. Otherwise, if only depth is enabled, generate + * a quick depth test. The test generators themselves will + * report back whether the depth/stencil buffer has to be + * written back. + */ + if (dsa->stencil[0].enabled) { + /* This will perform the stencil and depth tests, and update + * the mask_reg, fbZ_reg, and fbS_reg as required by the + * tests. + */ + ASSERT(fbS_reg >= 0); + spe_comment(f, 0, "Perform stencil test"); + + /* Note that fbZ_reg may not be set on entry, if stenciling + * is enabled but there's no Z-buffer. The + * gen_stencil_depth_test() function must ignore the + * fbZ_reg register if depth is not enabled. + */ + write_depth_stencil = gen_stencil_depth_test(f, dsa, stencil_ref, facing, + mask_reg, fragZ_reg, + fbZ_reg, fbS_reg); + } + else if (dsa->depth.enabled) { + int zmask_reg = spe_allocate_available_register(f); + ASSERT(fbZ_reg >= 0); + spe_comment(f, 0, "Perform depth test"); + write_depth_stencil = gen_depth_test(f, dsa, mask_reg, fragZ_reg, + fbZ_reg, zmask_reg); + spe_release_register(f, zmask_reg); + } + else { + write_depth_stencil = FALSE; + } + + if (write_depth_stencil) { + /* Merge latest Z and Stencil values into fbZS_reg. + * fbZ_reg has four Z vals in bits [23..0] or bits [15..0]. + * fbS_reg has four 8-bit Z values in bits [7..0]. + */ + spe_comment(f, 0, "Store quad's depth/stencil values in tile"); + if (zs_format == PIPE_FORMAT_Z24_UNORM_S8_USCALED || + zs_format == PIPE_FORMAT_Z24X8_UNORM) { + spe_shli(f, fbS_reg, fbS_reg, 24); /* fbS = fbS << 24 */ + spe_or(f, fbZS_reg, fbS_reg, fbZ_reg); /* fbZS = fbS | fbZ */ + } + else if (zs_format == PIPE_FORMAT_S8_USCALED_Z24_UNORM || + zs_format == PIPE_FORMAT_X8Z24_UNORM) { + spe_shli(f, fbZ_reg, fbZ_reg, 8); /* fbZ = fbZ << 8 */ + spe_or(f, fbZS_reg, fbS_reg, fbZ_reg); /* fbZS = fbS | fbZ */ + } + else if (zs_format == PIPE_FORMAT_Z32_UNORM) { + spe_move(f, fbZS_reg, fbZ_reg); /* fbZS = fbZ */ + } + else if (zs_format == PIPE_FORMAT_Z16_UNORM) { + spe_move(f, fbZS_reg, fbZ_reg); /* fbZS = fbZ */ + } + else if (zs_format == PIPE_FORMAT_S8_USCALED) { + ASSERT(0); /* XXX to do */ + } + else { + ASSERT(0); /* bad zs_format */ + } + + /* Store: memory[depth_tile_reg + quad_offset_reg] = fbZS */ + spe_stqx(f, fbZS_reg, depth_tile_reg, quad_offset_reg); + } + + /* Don't need these any more */ + spe_release_register(f, fbZS_reg); + spe_release_register(f, fbZ_reg); + spe_release_register(f, fbS_reg); + spe_release_register(f, zmask_reg); +} + + + +/** + * Generate SPE code to implement the fragment operations (alpha test, + * depth test, stencil test, blending, colormask, and final + * framebuffer write) as specified by the current context state. + * + * Logically, this code will be called after running the fragment + * shader. But under some circumstances we could run some of this + * code before the fragment shader to cull fragments/quads that are + * totally occluded/discarded. + * + * XXX we only support PIPE_FORMAT_S8_USCALED_Z24_UNORM z/stencil buffer right now. + * + * See the spu_default_fragment_ops() function to see how the per-fragment + * operations would be done with ordinary C code. + * The code we generate here though has no branches, is SIMD, etc and + * should be much faster. + * + * \param cell the rendering context (in) + * \param facing whether the generated code is for front-facing or + * back-facing fragments + * \param f the generated function (in/out); on input, the function + * must already have been initialized. On exit, whatever + * instructions within the generated function have had + * the fragment ops appended. + */ +void +cell_gen_fragment_function(struct cell_context *cell, + const uint facing, + struct spe_function *f) +{ + const struct pipe_depth_stencil_alpha_state *dsa = cell->depth_stencil; + const struct pipe_stencil_ref *stencil_ref = &cell->stencil_ref; + const struct pipe_blend_state *blend = cell->blend; + const struct pipe_blend_color *blend_color = &cell->blend_color; + const enum pipe_format color_format = cell->framebuffer.cbufs[0]->format; + + /* For SPE function calls: reg $3 = first param, $4 = second param, etc. */ + const int x_reg = 3; /* uint */ + const int y_reg = 4; /* uint */ + const int color_tile_reg = 5; /* tile_t * */ + const int depth_tile_reg = 6; /* tile_t * */ + const int fragZ_reg = 7; /* vector float */ + const int fragR_reg = 8; /* vector float */ + const int fragG_reg = 9; /* vector float */ + const int fragB_reg = 10; /* vector float */ + const int fragA_reg = 11; /* vector float */ + const int mask_reg = 12; /* vector uint */ + + ASSERT(facing == CELL_FACING_FRONT || facing == CELL_FACING_BACK); + + /* offset of quad from start of tile + * XXX assuming 4-byte pixels for color AND Z/stencil!!!! + */ + int quad_offset_reg; + + int fbRGBA_reg; /**< framebuffer's RGBA colors for quad */ + + if (cell->debug_flags & CELL_DEBUG_ASM) { + spe_print_code(f, TRUE); + spe_indent(f, 8); + spe_comment(f, -4, facing == CELL_FACING_FRONT + ? "Begin front-facing per-fragment ops" + : "Begin back-facing per-fragment ops"); + } + + spe_allocate_register(f, x_reg); + spe_allocate_register(f, y_reg); + spe_allocate_register(f, color_tile_reg); + spe_allocate_register(f, depth_tile_reg); + spe_allocate_register(f, fragZ_reg); + spe_allocate_register(f, fragR_reg); + spe_allocate_register(f, fragG_reg); + spe_allocate_register(f, fragB_reg); + spe_allocate_register(f, fragA_reg); + spe_allocate_register(f, mask_reg); + + quad_offset_reg = spe_allocate_available_register(f); + fbRGBA_reg = spe_allocate_available_register(f); + + /* compute offset of quad from start of tile, in bytes */ + { + int x2_reg = spe_allocate_available_register(f); + int y2_reg = spe_allocate_available_register(f); + + ASSERT(TILE_SIZE == 32); + + spe_comment(f, 0, "Compute quad offset within tile"); + spe_rotmi(f, y2_reg, y_reg, -1); /* y2 = y / 2 */ + spe_rotmi(f, x2_reg, x_reg, -1); /* x2 = x / 2 */ + spe_shli(f, y2_reg, y2_reg, 4); /* y2 *= 16 */ + spe_a(f, quad_offset_reg, y2_reg, x2_reg); /* offset = y2 + x2 */ + spe_shli(f, quad_offset_reg, quad_offset_reg, 4); /* offset *= 16 */ + + spe_release_register(f, x2_reg); + spe_release_register(f, y2_reg); + } + + /* Generate the alpha test, if needed. */ + if (dsa->alpha.enabled) { + gen_alpha_test(dsa, f, mask_reg, fragA_reg); + } + + /* generate depth and/or stencil test code */ + if (dsa->depth.enabled || dsa->stencil[0].enabled) { + gen_depth_stencil(cell, dsa, stencil_ref, f, + facing, + mask_reg, + depth_tile_reg, + quad_offset_reg, + fragZ_reg); + } + + /* Get framebuffer quad/colors. We'll need these for blending, + * color masking, and to obey the quad/pixel mask. + * Load: fbRGBA_reg = memory[color_tile + quad_offset] + * Note: if mask={~0,~0,~0,~0} and we're not blending or colormasking + * we could skip this load. + */ + spe_comment(f, 0, "Fetch quad colors from tile"); + spe_lqx(f, fbRGBA_reg, color_tile_reg, quad_offset_reg); + + if (blend->rt[0].blend_enable) { + spe_comment(f, 0, "Perform blending"); + gen_blend(blend, blend_color, f, color_format, + fragR_reg, fragG_reg, fragB_reg, fragA_reg, fbRGBA_reg); + } + + /* + * Write fragment colors to framebuffer/tile. + * This involves converting the fragment colors from float[4] to the + * tile's specific format and obeying the quad/pixel mask. + */ + { + int rgba_reg = spe_allocate_available_register(f); + + /* Pack four float colors as four 32-bit int colors */ + spe_comment(f, 0, "Convert float quad colors to packed int framebuffer colors"); + gen_pack_colors(f, color_format, + fragR_reg, fragG_reg, fragB_reg, fragA_reg, + rgba_reg); + + if (blend->logicop_enable) { + spe_comment(f, 0, "Compute logic op"); + gen_logicop(blend, f, rgba_reg, fbRGBA_reg); + } + + if (blend->rt[0].colormask != PIPE_MASK_RGBA) { + spe_comment(f, 0, "Compute color mask"); + gen_colormask(f, blend->rt[0].colormask, color_format, rgba_reg, fbRGBA_reg); + } + + /* Mix fragment colors with framebuffer colors using the quad/pixel mask: + * if (mask[i]) + * rgba[i] = rgba[i]; + * else + * rgba[i] = framebuffer[i]; + */ + spe_selb(f, rgba_reg, fbRGBA_reg, rgba_reg, mask_reg); + + /* Store updated quad in tile: + * memory[color_tile + quad_offset] = rgba_reg; + */ + spe_comment(f, 0, "Store quad colors into color tile"); + spe_stqx(f, rgba_reg, color_tile_reg, quad_offset_reg); + + spe_release_register(f, rgba_reg); + } + + //printf("gen_fragment_ops nr instructions: %u\n", f->num_inst); + + spe_bi(f, SPE_REG_RA, 0, 0); /* return from function call */ + + spe_release_register(f, fbRGBA_reg); + spe_release_register(f, quad_offset_reg); + + if (cell->debug_flags & CELL_DEBUG_ASM) { + char buffer[1024]; + sprintf(buffer, "End %s-facing per-fragment ops: %d instructions", + facing == CELL_FACING_FRONT ? "front" : "back", f->num_inst); + spe_comment(f, -4, buffer); + } +} diff --git a/src/gallium/drivers/cell/ppu/cell_gen_fragment.h b/src/gallium/drivers/cell/ppu/cell_gen_fragment.h new file mode 100644 index 0000000..21b35d1 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_gen_fragment.h @@ -0,0 +1,38 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef CELL_GEN_FRAGMENT_H +#define CELL_GEN_FRAGMENT_H + + +extern void +cell_gen_fragment_function(struct cell_context *cell, const uint facing, struct spe_function *f); + + +#endif /* CELL_GEN_FRAGMENT_H */ + diff --git a/src/gallium/drivers/cell/ppu/cell_pipe_state.c b/src/gallium/drivers/cell/ppu/cell_pipe_state.c new file mode 100644 index 0000000..223adda --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_pipe_state.c @@ -0,0 +1,473 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: + * Keith Whitwell + * Brian Paul + */ + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "draw/draw_context.h" +#include "cell_context.h" +#include "cell_flush.h" +#include "cell_pipe_state.h" +#include "cell_state.h" +#include "cell_texture.h" + + + +static void * +cell_create_blend_state(struct pipe_context *pipe, + const struct pipe_blend_state *blend) +{ + return mem_dup(blend, sizeof(*blend)); +} + + +static void +cell_bind_blend_state(struct pipe_context *pipe, void *blend) +{ + struct cell_context *cell = cell_context(pipe); + + draw_flush(cell->draw); + + cell->blend = (struct pipe_blend_state *) blend; + cell->dirty |= CELL_NEW_BLEND; +} + + +static void +cell_delete_blend_state(struct pipe_context *pipe, void *blend) +{ + FREE(blend); +} + + +static void +cell_set_blend_color(struct pipe_context *pipe, + const struct pipe_blend_color *blend_color) +{ + struct cell_context *cell = cell_context(pipe); + + draw_flush(cell->draw); + + cell->blend_color = *blend_color; + + cell->dirty |= CELL_NEW_BLEND; +} + + + + +static void * +cell_create_depth_stencil_alpha_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_alpha_state *dsa) +{ + return mem_dup(dsa, sizeof(*dsa)); +} + + +static void +cell_bind_depth_stencil_alpha_state(struct pipe_context *pipe, + void *dsa) +{ + struct cell_context *cell = cell_context(pipe); + + draw_flush(cell->draw); + + cell->depth_stencil = (struct pipe_depth_stencil_alpha_state *) dsa; + cell->dirty |= CELL_NEW_DEPTH_STENCIL; +} + + +static void +cell_delete_depth_stencil_alpha_state(struct pipe_context *pipe, void *dsa) +{ + FREE(dsa); +} + + +static void +cell_set_stencil_ref(struct pipe_context *pipe, + const struct pipe_stencil_ref *stencil_ref) +{ + struct cell_context *cell = cell_context(pipe); + + draw_flush(cell->draw); + + cell->stencil_ref = *stencil_ref; + + cell->dirty |= CELL_NEW_DEPTH_STENCIL; +} + + +static void +cell_set_clip_state(struct pipe_context *pipe, + const struct pipe_clip_state *clip) +{ + struct cell_context *cell = cell_context(pipe); + + /* pass the clip state to the draw module */ + draw_set_clip_state(cell->draw, clip); +} + + +static void +cell_set_sample_mask(struct pipe_context *pipe, + unsigned sample_mask) +{ +} + + +/* Called when driver state tracker notices changes to the viewport + * matrix: + */ +static void +cell_set_viewport_state( struct pipe_context *pipe, + const struct pipe_viewport_state *viewport ) +{ + struct cell_context *cell = cell_context(pipe); + + cell->viewport = *viewport; /* struct copy */ + cell->dirty |= CELL_NEW_VIEWPORT; + + /* pass the viewport info to the draw module */ + draw_set_viewport_state(cell->draw, viewport); + + /* Using tnl/ and vf/ modules is temporary while getting started. + * Full pipe will have vertex shader, vertex fetch of its own. + */ +} + + +static void +cell_set_scissor_state( struct pipe_context *pipe, + const struct pipe_scissor_state *scissor ) +{ + struct cell_context *cell = cell_context(pipe); + + memcpy( &cell->scissor, scissor, sizeof(*scissor) ); + cell->dirty |= CELL_NEW_SCISSOR; +} + + +static void +cell_set_polygon_stipple( struct pipe_context *pipe, + const struct pipe_poly_stipple *stipple ) +{ + struct cell_context *cell = cell_context(pipe); + + memcpy( &cell->poly_stipple, stipple, sizeof(*stipple) ); + cell->dirty |= CELL_NEW_STIPPLE; +} + + + +static void * +cell_create_rasterizer_state(struct pipe_context *pipe, + const struct pipe_rasterizer_state *rasterizer) +{ + return mem_dup(rasterizer, sizeof(*rasterizer)); +} + + +static void +cell_bind_rasterizer_state(struct pipe_context *pipe, void *rast) +{ + struct pipe_rasterizer_state *rasterizer = + (struct pipe_rasterizer_state *) rast; + struct cell_context *cell = cell_context(pipe); + + /* pass-through to draw module */ + draw_set_rasterizer_state(cell->draw, rasterizer, rast); + + cell->rasterizer = rasterizer; + + cell->dirty |= CELL_NEW_RASTERIZER; +} + + +static void +cell_delete_rasterizer_state(struct pipe_context *pipe, void *rasterizer) +{ + FREE(rasterizer); +} + + + +static void * +cell_create_sampler_state(struct pipe_context *pipe, + const struct pipe_sampler_state *sampler) +{ + return mem_dup(sampler, sizeof(*sampler)); +} + + +static void +cell_bind_sampler_states(struct pipe_context *pipe, + unsigned num, void **samplers) +{ + struct cell_context *cell = cell_context(pipe); + uint i, changed = 0x0; + + assert(num <= CELL_MAX_SAMPLERS); + + draw_flush(cell->draw); + + for (i = 0; i < CELL_MAX_SAMPLERS; i++) { + struct pipe_sampler_state *new_samp = i < num ? samplers[i] : NULL; + if (cell->sampler[i] != new_samp) { + cell->sampler[i] = new_samp; + changed |= (1 << i); + } + } + + if (changed) { + cell->dirty |= CELL_NEW_SAMPLER; + cell->dirty_samplers |= changed; + } +} + + +static void +cell_delete_sampler_state(struct pipe_context *pipe, + void *sampler) +{ + FREE( sampler ); +} + + + +static void +cell_set_fragment_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct cell_context *cell = cell_context(pipe); + uint i, changed = 0x0; + + assert(num <= CELL_MAX_SAMPLERS); + + for (i = 0; i < CELL_MAX_SAMPLERS; i++) { + struct pipe_sampler_view *new_view = i < num ? views[i] : NULL; + struct pipe_sampler_view *old_view = cell->fragment_sampler_views[i]; + + if (old_view != new_view) { + struct pipe_resource *new_tex = new_view ? new_view->texture : NULL; + + pipe_sampler_view_reference(&cell->fragment_sampler_views[i], + new_view); + pipe_resource_reference((struct pipe_resource **) &cell->texture[i], + (struct pipe_resource *) new_tex); + + changed |= (1 << i); + } + } + + cell->num_textures = num; + + if (changed) { + cell->dirty |= CELL_NEW_TEXTURE; + cell->dirty_textures |= changed; + } +} + + +static struct pipe_sampler_view * +cell_create_sampler_view(struct pipe_context *pipe, + struct pipe_resource *texture, + const struct pipe_sampler_view *templ) +{ + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_resource_reference(&view->texture, texture); + view->context = pipe; + } + + return view; +} + + +static void +cell_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_resource_reference(&view->texture, NULL); + FREE(view); +} + + +/** + * Map color and z/stencil framebuffer surfaces. + */ +static void +cell_map_surfaces(struct cell_context *cell) +{ +#if 0 + struct pipe_screen *screen = cell->pipe.screen; +#endif + uint i; + + for (i = 0; i < 1; i++) { + struct pipe_surface *ps = cell->framebuffer.cbufs[i]; + if (ps) { + struct cell_resource *ct = cell_resource(ps->texture); +#if 0 + cell->cbuf_map[i] = screen->buffer_map(screen, + ct->buffer, + (PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE)); +#else + cell->cbuf_map[i] = ct->data; +#endif + } + } + + { + struct pipe_surface *ps = cell->framebuffer.zsbuf; + if (ps) { + struct cell_resource *ct = cell_resource(ps->texture); +#if 0 + cell->zsbuf_map = screen->buffer_map(screen, + ct->buffer, + (PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE)); +#else + cell->zsbuf_map = ct->data; +#endif + } + } +} + + +/** + * Unmap color and z/stencil framebuffer surfaces. + */ +static void +cell_unmap_surfaces(struct cell_context *cell) +{ + /*struct pipe_screen *screen = cell->pipe.screen;*/ + uint i; + + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + struct pipe_surface *ps = cell->framebuffer.cbufs[i]; + if (ps && cell->cbuf_map[i]) { + /*struct cell_resource *ct = cell_resource(ps->texture);*/ + assert(ps->texture); + /*assert(ct->buffer);*/ + + /*screen->buffer_unmap(screen, ct->buffer);*/ + cell->cbuf_map[i] = NULL; + } + } + + { + struct pipe_surface *ps = cell->framebuffer.zsbuf; + if (ps && cell->zsbuf_map) { + /*struct cell_resource *ct = cell_resource(ps->texture);*/ + /*screen->buffer_unmap(screen, ct->buffer);*/ + cell->zsbuf_map = NULL; + } + } +} + + +static void +cell_set_framebuffer_state(struct pipe_context *pipe, + const struct pipe_framebuffer_state *fb) +{ + struct cell_context *cell = cell_context(pipe); + + if (1 /*memcmp(&cell->framebuffer, fb, sizeof(*fb))*/) { + uint i; + + /* unmap old surfaces */ + cell_unmap_surfaces(cell); + + /* Finish any pending rendering to the current surface before + * installing a new surface! + */ + cell_flush_int(cell, CELL_FLUSH_WAIT); + + /* update my state + * (this is also where old surfaces will finally get freed) + */ + cell->framebuffer.width = fb->width; + cell->framebuffer.height = fb->height; + cell->framebuffer.nr_cbufs = fb->nr_cbufs; + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + pipe_surface_reference(&cell->framebuffer.cbufs[i], fb->cbufs[i]); + } + pipe_surface_reference(&cell->framebuffer.zsbuf, fb->zsbuf); + + /* map new surfaces */ + cell_map_surfaces(cell); + + cell->dirty |= CELL_NEW_FRAMEBUFFER; + } +} + + +void +cell_init_state_functions(struct cell_context *cell) +{ + cell->pipe.create_blend_state = cell_create_blend_state; + cell->pipe.bind_blend_state = cell_bind_blend_state; + cell->pipe.delete_blend_state = cell_delete_blend_state; + + cell->pipe.create_sampler_state = cell_create_sampler_state; + cell->pipe.bind_fragment_sampler_states = cell_bind_sampler_states; + cell->pipe.delete_sampler_state = cell_delete_sampler_state; + + cell->pipe.set_fragment_sampler_views = cell_set_fragment_sampler_views; + cell->pipe.create_sampler_view = cell_create_sampler_view; + cell->pipe.sampler_view_destroy = cell_sampler_view_destroy; + + cell->pipe.create_depth_stencil_alpha_state = cell_create_depth_stencil_alpha_state; + cell->pipe.bind_depth_stencil_alpha_state = cell_bind_depth_stencil_alpha_state; + cell->pipe.delete_depth_stencil_alpha_state = cell_delete_depth_stencil_alpha_state; + + cell->pipe.create_rasterizer_state = cell_create_rasterizer_state; + cell->pipe.bind_rasterizer_state = cell_bind_rasterizer_state; + cell->pipe.delete_rasterizer_state = cell_delete_rasterizer_state; + + cell->pipe.set_blend_color = cell_set_blend_color; + cell->pipe.set_stencil_ref = cell_set_stencil_ref; + cell->pipe.set_clip_state = cell_set_clip_state; + cell->pipe.set_sample_mask = cell_set_sample_mask; + + cell->pipe.set_framebuffer_state = cell_set_framebuffer_state; + + cell->pipe.set_polygon_stipple = cell_set_polygon_stipple; + cell->pipe.set_scissor_state = cell_set_scissor_state; + cell->pipe.set_viewport_state = cell_set_viewport_state; +} diff --git a/src/gallium/drivers/cell/ppu/cell_pipe_state.h b/src/gallium/drivers/cell/ppu/cell_pipe_state.h new file mode 100644 index 0000000..1889bd5 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_pipe_state.h @@ -0,0 +1,39 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef CELL_PIPE_STATE_H +#define CELL_PIPE_STATE_H + + +struct cell_context; + +extern void +cell_init_state_functions(struct cell_context *cell); + + +#endif /* CELL_PIPE_STATE_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_public.h b/src/gallium/drivers/cell/ppu/cell_public.h new file mode 100644 index 0000000..7e2e093 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_public.h @@ -0,0 +1,10 @@ +#ifndef CELL_PUBLIC_H +#define CELL_PUBLIC_H + +struct pipe_screen; +struct sw_winsys; + +struct pipe_screen * +cell_create_screen(struct sw_winsys *winsys); + +#endif diff --git a/src/gallium/drivers/cell/ppu/cell_render.c b/src/gallium/drivers/cell/ppu/cell_render.c new file mode 100644 index 0000000..f648482 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_render.c @@ -0,0 +1,211 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \brief Last stage of 'draw' pipeline: send tris to SPUs. + * \author Brian Paul + */ + +#include "cell_context.h" +#include "cell_render.h" +#include "cell_spu.h" +#include "util/u_memory.h" +#include "draw/draw_private.h" + + +struct render_stage { + struct draw_stage stage; /**< This must be first (base class) */ + + struct cell_context *cell; +}; + + +static INLINE struct render_stage * +render_stage(struct draw_stage *stage) +{ + return (struct render_stage *) stage; +} + + +static void render_begin( struct draw_stage *stage ) +{ +#if 0 + struct render_stage *render = render_stage(stage); + struct cell_context *sp = render->cell; + const struct pipe_shader_state *fs = &render->cell->fs->shader; + render->quad.nr_attrs = render->cell->nr_frag_attrs; + + render->firstFpInput = fs->input_semantic_name[0]; + + sp->quad.first->begin(sp->quad.first); +#endif +} + + +static void render_end( struct draw_stage *stage ) +{ +} + + +static void reset_stipple_counter( struct draw_stage *stage ) +{ + struct render_stage *render = render_stage(stage); + /*render->cell->line_stipple_counter = 0;*/ +} + + +static void +render_point(struct draw_stage *stage, struct prim_header *prim) +{ +} + + +static void +render_line(struct draw_stage *stage, struct prim_header *prim) +{ +} + + +/** Write a vertex into the prim buffer */ +static void +save_vertex(struct cell_prim_buffer *buf, uint pos, + const struct vertex_header *vert) +{ + uint attr, j; + + for (attr = 0; attr < 2; attr++) { + for (j = 0; j < 4; j++) { + buf->vertex[pos][attr][j] = vert->data[attr][j]; + } + } + + /* update bounding box */ + if (vert->data[0][0] < buf->xmin) + buf->xmin = vert->data[0][0]; + if (vert->data[0][0] > buf->xmax) + buf->xmax = vert->data[0][0]; + if (vert->data[0][1] < buf->ymin) + buf->ymin = vert->data[0][1]; + if (vert->data[0][1] > buf->ymax) + buf->ymax = vert->data[0][1]; +} + + +static void +render_tri(struct draw_stage *stage, struct prim_header *prim) +{ + struct render_stage *rs = render_stage(stage); + struct cell_context *cell = rs->cell; + struct cell_prim_buffer *buf = &cell->prim_buffer; + uint i; + + if (buf->num_verts + 3 > CELL_MAX_VERTS) { + cell_flush_prim_buffer(cell); + } + + i = buf->num_verts; + assert(i+2 <= CELL_MAX_VERTS); + save_vertex(buf, i+0, prim->v[0]); + save_vertex(buf, i+1, prim->v[1]); + save_vertex(buf, i+2, prim->v[2]); + buf->num_verts += 3; +} + + +/** + * Send the a RENDER command to all SPUs to have them render the prims + * in the current prim_buffer. + */ +void +cell_flush_prim_buffer(struct cell_context *cell) +{ + uint i; + + if (cell->prim_buffer.num_verts == 0) + return; + + for (i = 0; i < cell->num_spus; i++) { + struct cell_command_render *render = &cell_global.command[i].render; + render->prim_type = PIPE_PRIM_TRIANGLES; + render->num_verts = cell->prim_buffer.num_verts; + render->front_ccw = cell->rasterizer->front_ccw; + render->vertex_size = cell->vertex_info->size * 4; + render->xmin = cell->prim_buffer.xmin; + render->ymin = cell->prim_buffer.ymin; + render->xmax = cell->prim_buffer.xmax; + render->ymax = cell->prim_buffer.ymax; + render->vertex_data = &cell->prim_buffer.vertex; + ASSERT_ALIGN16(render->vertex_data); + send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_RENDER); + } + + cell->prim_buffer.num_verts = 0; + + cell->prim_buffer.xmin = 1e100; + cell->prim_buffer.ymin = 1e100; + cell->prim_buffer.xmax = -1e100; + cell->prim_buffer.ymax = -1e100; + + /* XXX temporary, need to double-buffer the prim buffer until we get + * a real command buffer/list system. + */ + cell_flush(&cell->pipe, 0x0); +} + + + +static void render_destroy( struct draw_stage *stage ) +{ + FREE( stage ); +} + + +/** + * Create a new draw/render stage. This will be plugged into the + * draw module as the last pipeline stage. + */ +struct draw_stage *cell_draw_render_stage( struct cell_context *cell ) +{ + struct render_stage *render = CALLOC_STRUCT(render_stage); + + render->cell = cell; + render->stage.draw = cell->draw; + render->stage.begin = render_begin; + render->stage.point = render_point; + render->stage.line = render_line; + render->stage.tri = render_tri; + render->stage.end = render_end; + render->stage.reset_stipple_counter = reset_stipple_counter; + render->stage.destroy = render_destroy; + + /* + render->quad.coef = render->coef; + render->quad.posCoef = &render->posCoef; + */ + + return &render->stage; +} diff --git a/src/gallium/drivers/cell/ppu/cell_render.h b/src/gallium/drivers/cell/ppu/cell_render.h new file mode 100644 index 0000000..826dcba --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_render.h @@ -0,0 +1,39 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef CELL_RENDER_H +#define CELL_RENDER_H + +struct cell_context; +struct draw_stage; + +extern void +cell_flush_prim_buffer(struct cell_context *cell); + +extern struct draw_stage *cell_draw_render_stage( struct cell_context *cell ); + +#endif /* CELL_RENDER_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_screen.c b/src/gallium/drivers/cell/ppu/cell_screen.c new file mode 100644 index 0000000..8d2b4b9 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_screen.c @@ -0,0 +1,223 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "util/u_memory.h" +#include "util/u_simple_screen.h" +#include "pipe/p_defines.h" +#include "pipe/p_screen.h" + +#include "cell/common.h" +#include "cell_context.h" +#include "cell_screen.h" +#include "cell_texture.h" +#include "cell_public.h" + +#include "state_tracker/sw_winsys.h" + + +static const char * +cell_get_vendor(struct pipe_screen *screen) +{ + return "VMware, Inc."; +} + + +static const char * +cell_get_name(struct pipe_screen *screen) +{ + return "Cell"; +} + + +static int +cell_get_param(struct pipe_screen *screen, enum pipe_cap param) +{ + switch (param) { + case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: + return CELL_MAX_SAMPLERS; + case PIPE_CAP_MAX_COMBINED_SAMPLERS: + return CELL_MAX_SAMPLERS; + case PIPE_CAP_NPOT_TEXTURES: + return 1; + case PIPE_CAP_TWO_SIDED_STENCIL: + return 1; + case PIPE_CAP_GLSL: + return 1; + case PIPE_CAP_ANISOTROPIC_FILTER: + return 0; + case PIPE_CAP_POINT_SPRITE: + return 1; + case PIPE_CAP_MAX_RENDER_TARGETS: + return 1; + case PIPE_CAP_OCCLUSION_QUERY: + return 1; + case PIPE_CAP_TIMER_QUERY: + return 0; + case PIPE_CAP_TEXTURE_SHADOW_MAP: + return 10; + case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: + return CELL_MAX_TEXTURE_LEVELS; + case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: + return 8; /* max 128x128x128 */ + case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: + return CELL_MAX_TEXTURE_LEVELS; + case PIPE_CAP_TEXTURE_MIRROR_REPEAT: + return 1; /* XXX not really true */ + case PIPE_CAP_TEXTURE_MIRROR_CLAMP: + return 0; /* XXX to do */ + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: + return 1; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: + return 0; + case PIPE_CAP_BLEND_EQUATION_SEPARATE: + return 1; + default: + return 0; + } +} + +static int +cell_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shader_cap param) +{ + switch(shader) + { + case PIPE_SHADER_FRAGMENT: + return tgsi_exec_get_shader_param(param); + case PIPE_SHADER_VERTEX: + case PIPE_SHADER_GEOMETRY: + return draw_get_shader_param(shader, param); + default: + return 0; + } +} + +static float +cell_get_paramf(struct pipe_screen *screen, enum pipe_cap param) +{ + switch (param) { + case PIPE_CAP_MAX_LINE_WIDTH: + /* fall-through */ + case PIPE_CAP_MAX_LINE_WIDTH_AA: + return 255.0; /* arbitrary */ + + case PIPE_CAP_MAX_POINT_WIDTH: + /* fall-through */ + case PIPE_CAP_MAX_POINT_WIDTH_AA: + return 255.0; /* arbitrary */ + + case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: + return 0.0; + + case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: + return 16.0; /* arbitrary */ + + default: + return 0; + } +} + + +static boolean +cell_is_format_supported( struct pipe_screen *screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned tex_usage, + unsigned geom_flags ) +{ + struct sw_winsys *winsys = cell_screen(screen)->winsys; + + if (sample_count > 1) + return FALSE; + + if (tex_usage & (PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SCANOUT | + PIPE_BIND_SHARED)) { + if (!winsys->is_displaytarget_format_supported(winsys, tex_usage, format)) + return FALSE; + } + + /* only a few formats are known to work at this time */ + switch (format) { + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_I8_UNORM: + return TRUE; + default: + return FALSE; + } +} + + +static void +cell_destroy_screen( struct pipe_screen *screen ) +{ + struct cell_screen *sp_screen = cell_screen(screen); + struct sw_winsys *winsys = sp_screen->winsys; + + if(winsys->destroy) + winsys->destroy(winsys); + + FREE(screen); +} + + + +/** + * Create a new pipe_screen object + * Note: we're not presently subclassing pipe_screen (no cell_screen) but + * that would be the place to put SPU thread/context info... + */ +struct pipe_screen * +cell_create_screen(struct sw_winsys *winsys) +{ + struct cell_screen *screen = CALLOC_STRUCT(cell_screen); + + if (!screen) + return NULL; + + screen->winsys = winsys; + screen->base.winsys = NULL; + + screen->base.destroy = cell_destroy_screen; + + screen->base.get_name = cell_get_name; + screen->base.get_vendor = cell_get_vendor; + screen->base.get_param = cell_get_param; + screen->base.get_shader_param = cell_get_shader_param; + screen->base.get_paramf = cell_get_paramf; + screen->base.is_format_supported = cell_is_format_supported; + screen->base.context_create = cell_create_context; + + cell_init_screen_texture_funcs(&screen->base); + + return &screen->base; +} diff --git a/src/gallium/drivers/cell/ppu/cell_screen.h b/src/gallium/drivers/cell/ppu/cell_screen.h new file mode 100644 index 0000000..baff9d3 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_screen.h @@ -0,0 +1,55 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef CELL_SCREEN_H +#define CELL_SCREEN_H + + +#include "pipe/p_screen.h" + +struct sw_winsys; + +struct cell_screen { + struct pipe_screen base; + + struct sw_winsys *winsys; + + /* Increments whenever textures are modified. Contexts can track + * this. + */ + unsigned timestamp; +}; + +static INLINE struct cell_screen * +cell_screen( struct pipe_screen *pipe ) +{ + return (struct cell_screen *)pipe; +} + + +#endif /* CELL_SCREEN_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_spu.c b/src/gallium/drivers/cell/ppu/cell_spu.c new file mode 100644 index 0000000..39284f3 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_spu.c @@ -0,0 +1,219 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/** + * Utility/wrappers for communicating with the SPUs. + */ + + +#include + +#include "cell_spu.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include "util/u_memory.h" +#include "cell/common.h" + + +/* +helpful headers: +/opt/ibm/cell-sdk/prototype/src/include/ppu/cbe_mfc.h +*/ + + +/** + * Cell/SPU info that's not per-context. + */ +struct cell_global_info cell_global; + + +/** + * Scan /proc/cpuinfo to determine the timebase for the system. + * This is used by the SPUs to convert 'decrementer' ticks to seconds. + * There may be a better way to get this value... + */ +static unsigned +get_timebase(void) +{ + FILE *f = fopen("/proc/cpuinfo", "r"); + unsigned timebase; + + assert(f); + while (!feof(f)) { + char line[80]; + fgets(line, sizeof(line), f); + if (strncmp(line, "timebase", 8) == 0) { + char *colon = strchr(line, ':'); + if (colon) { + timebase = atoi(colon + 2); + break; + } + } + } + fclose(f); + + return timebase; +} + + +/** + * Write a 1-word message to the given SPE mailbox. + */ +void +send_mbox_message(spe_context_ptr_t ctx, unsigned int msg) +{ + spe_in_mbox_write(ctx, &msg, 1, SPE_MBOX_ALL_BLOCKING); +} + + +/** + * Wait for a 1-word message to arrive in given mailbox. + */ +uint +wait_mbox_message(spe_context_ptr_t ctx) +{ + do { + unsigned data; + int count = spe_out_mbox_read(ctx, &data, 1); + + if (count == 1) { + return data; + } + + if (count < 0) { + /* error */ ; + } + } while (1); +} + + +/** + * Called by pthread_create() to spawn an SPU thread. + */ +static void * +cell_thread_function(void *arg) +{ + struct cell_init_info *init = (struct cell_init_info *) arg; + unsigned entry = SPE_DEFAULT_ENTRY; + + ASSERT_ALIGN16(init); + + if (spe_context_run(cell_global.spe_contexts[init->id], &entry, 0, + init, NULL, NULL) < 0) { + fprintf(stderr, "spe_context_run() failed\n"); + exit(1); + } + + pthread_exit(NULL); +} + + +/** + * Create the SPU threads. This is done once during driver initialization. + * This involves setting the "init" message which is sent to each SPU. + * The init message specifies an SPU id, total number of SPUs, location + * and number of batch buffers, etc. + */ +void +cell_start_spus(struct cell_context *cell) +{ + static boolean one_time_init = FALSE; + uint i, j; + uint timebase = get_timebase(); + + if (one_time_init) { + fprintf(stderr, "PPU: Multiple rendering contexts not yet supported " + "on Cell.\n"); + abort(); + } + + one_time_init = TRUE; + + assert(cell->num_spus <= CELL_MAX_SPUS); + + ASSERT_ALIGN16(&cell_global.inits[0]); + ASSERT_ALIGN16(&cell_global.inits[1]); + + /* + * Initialize the global 'inits' structure for each SPU. + * A pointer to the init struct will be passed to each SPU. + * The SPUs will then each grab their init info with mfc_get(). + */ + for (i = 0; i < cell->num_spus; i++) { + cell_global.inits[i].id = i; + cell_global.inits[i].num_spus = cell->num_spus; + cell_global.inits[i].debug_flags = cell->debug_flags; + cell_global.inits[i].inv_timebase = 1000.0f / timebase; + + for (j = 0; j < CELL_NUM_BUFFERS; j++) { + cell_global.inits[i].buffers[j] = cell->buffer[j]; + } + cell_global.inits[i].buffer_status = &cell->buffer_status[0][0][0]; + + cell_global.inits[i].spu_functions = &cell->spu_functions; + + cell_global.spe_contexts[i] = spe_context_create(0, NULL); + if (!cell_global.spe_contexts[i]) { + fprintf(stderr, "spe_context_create() failed\n"); + exit(1); + } + + if (spe_program_load(cell_global.spe_contexts[i], &g3d_spu)) { + fprintf(stderr, "spe_program_load() failed\n"); + exit(1); + } + + pthread_create(&cell_global.spe_threads[i], /* returned thread handle */ + NULL, /* pthread attribs */ + &cell_thread_function, /* start routine */ + &cell_global.inits[i]); /* thread argument */ + } +} + + +/** + * Tell all the SPUs to stop/exit. + * This is done when the driver's exiting / cleaning up. + */ +void +cell_spu_exit(struct cell_context *cell) +{ + uint i; + + for (i = 0; i < cell->num_spus; i++) { + send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_EXIT); + } + + /* wait for threads to exit */ + for (i = 0; i < cell->num_spus; i++) { + void *value; + pthread_join(cell_global.spe_threads[i], &value); + cell_global.spe_threads[i] = 0; + cell_global.spe_contexts[i] = 0; + } +} diff --git a/src/gallium/drivers/cell/ppu/cell_spu.h b/src/gallium/drivers/cell/ppu/cell_spu.h new file mode 100644 index 0000000..c93958a --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_spu.h @@ -0,0 +1,79 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef CELL_SPU +#define CELL_SPU + + +#include +#include +#include "cell/common.h" + +#include "cell_context.h" + + +/** + * Global vars, for now anyway. + */ +struct cell_global_info +{ + /** + * SPU/SPE handles, etc + */ + spe_context_ptr_t spe_contexts[CELL_MAX_SPUS]; + pthread_t spe_threads[CELL_MAX_SPUS]; + + /** + * Data sent to SPUs at start-up + */ + struct cell_init_info inits[CELL_MAX_SPUS]; +}; + + +extern struct cell_global_info cell_global; + + +/** This is the handle for the actual SPE code */ +extern spe_program_handle_t g3d_spu; + + +extern void +send_mbox_message(spe_context_ptr_t ctx, unsigned int msg); + +extern uint +wait_mbox_message(spe_context_ptr_t ctx); + + +extern void +cell_start_spus(struct cell_context *cell); + + +extern void +cell_spu_exit(struct cell_context *cell); + + +#endif /* CELL_SPU */ diff --git a/src/gallium/drivers/cell/ppu/cell_state.h b/src/gallium/drivers/cell/ppu/cell_state.h new file mode 100644 index 0000000..7adedcd --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_state.h @@ -0,0 +1,65 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef CELL_STATE_H +#define CELL_STATE_H + + +#define CELL_NEW_VIEWPORT 0x1 +#define CELL_NEW_RASTERIZER 0x2 +#define CELL_NEW_FS 0x4 +#define CELL_NEW_BLEND 0x8 +#define CELL_NEW_CLIP 0x10 +#define CELL_NEW_SCISSOR 0x20 +#define CELL_NEW_STIPPLE 0x40 +#define CELL_NEW_FRAMEBUFFER 0x80 +#define CELL_NEW_ALPHA_TEST 0x100 +#define CELL_NEW_DEPTH_STENCIL 0x200 +#define CELL_NEW_SAMPLER 0x400 +#define CELL_NEW_TEXTURE 0x800 +#define CELL_NEW_VERTEX 0x1000 +#define CELL_NEW_VS 0x2000 +#define CELL_NEW_VS_CONSTANTS 0x4000 +#define CELL_NEW_FS_CONSTANTS 0x8000 +#define CELL_NEW_VERTEX_INFO 0x10000 + + +extern void +cell_update_derived( struct cell_context *cell ); + + +extern void +cell_init_shader_functions(struct cell_context *cell); + + +extern void +cell_init_vertex_functions(struct cell_context *cell); + + +#endif /* CELL_STATE_H */ + diff --git a/src/gallium/drivers/cell/ppu/cell_state_derived.c b/src/gallium/drivers/cell/ppu/cell_state_derived.c new file mode 100644 index 0000000..b723e79 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_state_derived.c @@ -0,0 +1,170 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_memory.h" +#include "pipe/p_shader_tokens.h" +#include "draw/draw_context.h" +#include "draw/draw_vertex.h" +#include "cell_context.h" +#include "cell_batch.h" +#include "cell_state.h" +#include "cell_state_emit.h" + + +/** + * Determine how to map vertex program outputs to fragment program inputs. + * Basically, this will be used when computing the triangle interpolation + * coefficients from the post-transform vertex attributes. + */ +static void +calculate_vertex_layout( struct cell_context *cell ) +{ + const struct cell_fragment_shader_state *fs = cell->fs; + const enum interp_mode colorInterp + = cell->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR; + struct vertex_info *vinfo = &cell->vertex_info; + uint i; + int src; + +#if 0 + if (cell->vbuf) { + /* if using the post-transform vertex buffer, tell draw_vbuf to + * simply emit the whole post-xform vertex as-is: + */ + struct vertex_info *vinfo_vbuf = &cell->vertex_info_vbuf; + vinfo_vbuf->num_attribs = 0; + draw_emit_vertex_attr(vinfo_vbuf, EMIT_ALL, INTERP_NONE, 0); + vinfo_vbuf->size = 4 * vs->num_outputs + sizeof(struct vertex_header)/4; + } +#endif + + /* reset vinfo */ + vinfo->num_attribs = 0; + + /* we always want to emit vertex pos */ + src = draw_find_shader_output(cell->draw, TGSI_SEMANTIC_POSITION, 0); + assert(src >= 0); + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_POS, src); + + + /* + * Loop over fragment shader inputs, searching for the matching output + * from the vertex shader. + */ + for (i = 0; i < fs->info.num_inputs; i++) { + switch (fs->info.input_semantic_name[i]) { + case TGSI_SEMANTIC_POSITION: + /* already done above */ + break; + + case TGSI_SEMANTIC_COLOR: + src = draw_find_shader_output(cell->draw, TGSI_SEMANTIC_COLOR, + fs->info.input_semantic_index[i]); + assert(src >= 0); + draw_emit_vertex_attr(vinfo, EMIT_4F, colorInterp, src); + break; + + case TGSI_SEMANTIC_FOG: + src = draw_find_shader_output(cell->draw, TGSI_SEMANTIC_FOG, 0); +#if 1 + if (src < 0) /* XXX temp hack, try demos/fogcoord.c with this */ + src = 0; +#endif + assert(src >= 0); + draw_emit_vertex_attr(vinfo, EMIT_1F, INTERP_PERSPECTIVE, src); + break; + + case TGSI_SEMANTIC_GENERIC: + /* this includes texcoords and varying vars */ + src = draw_find_shader_output(cell->draw, TGSI_SEMANTIC_GENERIC, + fs->info.input_semantic_index[i]); + assert(src >= 0); + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src); + break; + + default: + assert(0); + } + } + + draw_compute_vertex_size(vinfo); + + /* XXX only signal this if format really changes */ + cell->dirty |= CELL_NEW_VERTEX_INFO; +} + + +#if 0 +/** + * Recompute cliprect from scissor bounds, scissor enable and surface size. + */ +static void +compute_cliprect(struct cell_context *sp) +{ + uint surfWidth = sp->framebuffer.width; + uint surfHeight = sp->framebuffer.height; + + if (sp->rasterizer->scissor) { + /* clip to scissor rect */ + sp->cliprect.minx = MAX2(sp->scissor.minx, 0); + sp->cliprect.miny = MAX2(sp->scissor.miny, 0); + sp->cliprect.maxx = MIN2(sp->scissor.maxx, surfWidth); + sp->cliprect.maxy = MIN2(sp->scissor.maxy, surfHeight); + } + else { + /* clip to surface bounds */ + sp->cliprect.minx = 0; + sp->cliprect.miny = 0; + sp->cliprect.maxx = surfWidth; + sp->cliprect.maxy = surfHeight; + } +} +#endif + + + +/** + * Update derived state, send current state to SPUs prior to rendering. + */ +void cell_update_derived( struct cell_context *cell ) +{ + if (cell->dirty & (CELL_NEW_RASTERIZER | + CELL_NEW_FS | + CELL_NEW_VS)) + calculate_vertex_layout( cell ); + +#if 0 + if (cell->dirty & (CELL_NEW_SCISSOR | + CELL_NEW_DEPTH_STENCIL_ALPHA | + CELL_NEW_FRAMEBUFFER)) + compute_cliprect(cell); +#endif + + cell_emit_state(cell); + + cell->dirty = 0; +} diff --git a/src/gallium/drivers/cell/ppu/cell_state_emit.c b/src/gallium/drivers/cell/ppu/cell_state_emit.c new file mode 100644 index 0000000..bb11c68 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_state_emit.c @@ -0,0 +1,343 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_format.h" +#include "cell_context.h" +#include "cell_gen_fragment.h" +#include "cell_state.h" +#include "cell_state_emit.h" +#include "cell_batch.h" +#include "cell_texture.h" +#include "draw/draw_context.h" +#include "draw/draw_private.h" + + +/** + * Find/create a cell_command_fragment_ops object corresponding to the + * current blend/stencil/z/colormask/etc. state. + */ +static struct cell_command_fragment_ops * +lookup_fragment_ops(struct cell_context *cell) +{ + struct cell_fragment_ops_key key; + struct cell_command_fragment_ops *ops; + + /* + * Build key + */ + memset(&key, 0, sizeof(key)); + key.blend = *cell->blend; + key.blend_color = cell->blend_color; + key.dsa = *cell->depth_stencil; + + if (cell->framebuffer.cbufs[0]) + key.color_format = cell->framebuffer.cbufs[0]->format; + else + key.color_format = PIPE_FORMAT_NONE; + + if (cell->framebuffer.zsbuf) + key.zs_format = cell->framebuffer.zsbuf->format; + else + key.zs_format = PIPE_FORMAT_NONE; + + /* + * Look up key in cache. + */ + ops = (struct cell_command_fragment_ops *) + util_keymap_lookup(cell->fragment_ops_cache, &key); + + /* + * If not found, create/save new fragment ops command. + */ + if (!ops) { + struct spe_function spe_code_front, spe_code_back; + unsigned int facing_dependent, total_code_size; + + if (0) + debug_printf("**** Create New Fragment Ops\n"); + + /* Prepare the buffer that will hold the generated code. The + * "0" passed in for the size means that the SPE code will + * use a default size. + */ + spe_init_func(&spe_code_front, 0); + spe_init_func(&spe_code_back, 0); + + /* Generate new code. Always generate new code for both front-facing + * and back-facing fragments, even if it's the same code in both + * cases. + */ + cell_gen_fragment_function(cell, CELL_FACING_FRONT, &spe_code_front); + cell_gen_fragment_function(cell, CELL_FACING_BACK, &spe_code_back); + + /* Make sure the code is a multiple of 8 bytes long; this is + * required to ensure that the dual pipe instruction alignment + * is correct. It's also important for the SPU unpacking, + * which assumes 8-byte boundaries. + */ + unsigned int front_code_size = spe_code_size(&spe_code_front); + while (front_code_size % 8 != 0) { + spe_lnop(&spe_code_front); + front_code_size = spe_code_size(&spe_code_front); + } + unsigned int back_code_size = spe_code_size(&spe_code_back); + while (back_code_size % 8 != 0) { + spe_lnop(&spe_code_back); + back_code_size = spe_code_size(&spe_code_back); + } + + /* Determine whether the code we generated is facing-dependent, by + * determining whether the generated code is different for the front- + * and back-facing fragments. + */ + if (front_code_size == back_code_size && memcmp(spe_code_front.store, spe_code_back.store, front_code_size) == 0) { + /* Code is identical; only need one copy. */ + facing_dependent = 0; + total_code_size = front_code_size; + } + else { + /* Code is different for front-facing and back-facing fragments. + * Need to send both copies. + */ + facing_dependent = 1; + total_code_size = front_code_size + back_code_size; + } + + /* alloc new fragment ops command. Note that this structure + * has variant length based on the total code size required. + */ + ops = CALLOC_VARIANT_LENGTH_STRUCT(cell_command_fragment_ops, total_code_size); + /* populate the new cell_command_fragment_ops object */ + ops->opcode[0] = CELL_CMD_STATE_FRAGMENT_OPS; + ops->total_code_size = total_code_size; + ops->front_code_index = 0; + memcpy(ops->code, spe_code_front.store, front_code_size); + if (facing_dependent) { + /* We have separate front- and back-facing code. Append the + * back-facing code to the buffer. Be careful because the code + * size is in bytes, but the buffer is of unsigned elements. + */ + ops->back_code_index = front_code_size / sizeof(spe_code_front.store[0]); + memcpy(ops->code + ops->back_code_index, spe_code_back.store, back_code_size); + } + else { + /* Use the same code for front- and back-facing fragments */ + ops->back_code_index = ops->front_code_index; + } + + /* Set the fields for the fallback case. Note that these fields + * (and the whole fallback case) will eventually go away. + */ + ops->dsa = *cell->depth_stencil; + ops->blend = *cell->blend; + ops->blend_color = cell->blend_color; + + /* insert cell_command_fragment_ops object into keymap/cache */ + util_keymap_insert(cell->fragment_ops_cache, &key, ops, NULL); + + /* release rtasm buffer */ + spe_release_func(&spe_code_front); + spe_release_func(&spe_code_back); + } + else { + if (0) + debug_printf("**** Re-use Fragment Ops\n"); + } + + return ops; +} + + + +static void +emit_state_cmd(struct cell_context *cell, uint cmd, + const void *state, uint state_size) +{ + uint32_t *dst = (uint32_t *) + cell_batch_alloc16(cell, ROUNDUP16(sizeof(opcode_t) + state_size)); + *dst = cmd; + memcpy(dst + 4, state, state_size); +} + + +/** + * For state marked as 'dirty', construct a state-update command block + * and insert it into the current batch buffer. + */ +void +cell_emit_state(struct cell_context *cell) +{ + if (cell->dirty & CELL_NEW_FRAMEBUFFER) { + struct pipe_surface *cbuf = cell->framebuffer.cbufs[0]; + struct pipe_surface *zbuf = cell->framebuffer.zsbuf; + STATIC_ASSERT(sizeof(struct cell_command_framebuffer) % 16 == 0); + struct cell_command_framebuffer *fb + = cell_batch_alloc16(cell, sizeof(*fb)); + fb->opcode[0] = CELL_CMD_STATE_FRAMEBUFFER; + fb->color_start = cell->cbuf_map[0]; + fb->color_format = cbuf->format; + fb->depth_start = cell->zsbuf_map; + fb->depth_format = zbuf ? zbuf->format : PIPE_FORMAT_NONE; + fb->width = cell->framebuffer.width; + fb->height = cell->framebuffer.height; +#if 0 + printf("EMIT color format %s\n", util_format_name(fb->color_format)); + printf("EMIT depth format %s\n", util_format_name(fb->depth_format)); +#endif + } + + if (cell->dirty & (CELL_NEW_RASTERIZER)) { + STATIC_ASSERT(sizeof(struct cell_command_rasterizer) % 16 == 0); + struct cell_command_rasterizer *rast = + cell_batch_alloc16(cell, sizeof(*rast)); + rast->opcode[0] = CELL_CMD_STATE_RASTERIZER; + rast->rasterizer = *cell->rasterizer; + } + + if (cell->dirty & (CELL_NEW_FS)) { + /* Send new fragment program to SPUs */ + STATIC_ASSERT(sizeof(struct cell_command_fragment_program) % 16 == 0); + struct cell_command_fragment_program *fp + = cell_batch_alloc16(cell, sizeof(*fp)); + fp->opcode[0] = CELL_CMD_STATE_FRAGMENT_PROGRAM; + fp->num_inst = cell->fs->code.num_inst; + memcpy(&fp->code, cell->fs->code.store, + SPU_MAX_FRAGMENT_PROGRAM_INSTS * SPE_INST_SIZE); + if (0) { + int i; + printf("PPU Emit CELL_CMD_STATE_FRAGMENT_PROGRAM:\n"); + for (i = 0; i < fp->num_inst; i++) { + printf(" %3d: 0x%08x\n", i, fp->code[i]); + } + } + } + + if (cell->dirty & (CELL_NEW_FS_CONSTANTS)) { + const uint shader = PIPE_SHADER_FRAGMENT; + const uint num_const = cell->constants[shader]->width0 / sizeof(float); + uint i, j; + float *buf = cell_batch_alloc16(cell, ROUNDUP16(32 + num_const * sizeof(float))); + uint32_t *ibuf = (uint32_t *) buf; + const float *constants = cell->mapped_constants[shader]; + ibuf[0] = CELL_CMD_STATE_FS_CONSTANTS; + ibuf[4] = num_const; + j = 8; + for (i = 0; i < num_const; i++) { + buf[j++] = constants[i]; + } + } + + if (cell->dirty & (CELL_NEW_FRAMEBUFFER | + CELL_NEW_DEPTH_STENCIL | + CELL_NEW_BLEND)) { + struct cell_command_fragment_ops *fops, *fops_cmd; + /* Note that cell_command_fragment_ops is a variant-sized record */ + fops = lookup_fragment_ops(cell); + fops_cmd = cell_batch_alloc16(cell, ROUNDUP16(sizeof(*fops_cmd) + fops->total_code_size)); + memcpy(fops_cmd, fops, sizeof(*fops) + fops->total_code_size); + } + + if (cell->dirty & CELL_NEW_SAMPLER) { + uint i; + for (i = 0; i < CELL_MAX_SAMPLERS; i++) { + if (cell->dirty_samplers & (1 << i)) { + if (cell->sampler[i]) { + STATIC_ASSERT(sizeof(struct cell_command_sampler) % 16 == 0); + struct cell_command_sampler *sampler + = cell_batch_alloc16(cell, sizeof(*sampler)); + sampler->opcode[0] = CELL_CMD_STATE_SAMPLER; + sampler->unit = i; + sampler->state = *cell->sampler[i]; + } + } + } + cell->dirty_samplers = 0x0; + } + + if (cell->dirty & CELL_NEW_TEXTURE) { + uint i; + for (i = 0;i < CELL_MAX_SAMPLERS; i++) { + if (cell->dirty_textures & (1 << i)) { + STATIC_ASSERT(sizeof(struct cell_command_texture) % 16 == 0); + struct cell_command_texture *texture = + (struct cell_command_texture *) + cell_batch_alloc16(cell, sizeof(*texture)); + + texture->opcode[0] = CELL_CMD_STATE_TEXTURE; + texture->unit = i; + if (cell->texture[i]) { + struct cell_resource *ct = cell->texture[i]; + uint level; + for (level = 0; level < CELL_MAX_TEXTURE_LEVELS; level++) { + texture->start[level] = (ct->mapped + + ct->level_offset[level]); + texture->width[level] = u_minify(ct->base.width0, level); + texture->height[level] = u_minify(ct->base.height0, level); + texture->depth[level] = u_minify(ct->base.depth0, level); + } + texture->target = ct->base.target; + } + else { + uint level; + for (level = 0; level < CELL_MAX_TEXTURE_LEVELS; level++) { + texture->start[level] = NULL; + texture->width[level] = 0; + texture->height[level] = 0; + texture->depth[level] = 0; + } + texture->target = 0; + } + } + } + cell->dirty_textures = 0x0; + } + + if (cell->dirty & CELL_NEW_VERTEX_INFO) { + emit_state_cmd(cell, CELL_CMD_STATE_VERTEX_INFO, + &cell->vertex_info, sizeof(struct vertex_info)); + } + +#if 0 + if (cell->dirty & CELL_NEW_VS) { + const struct draw_context *const draw = cell->draw; + struct cell_shader_info info; + + info.num_outputs = draw_num_shader_outputs(draw); + info.declarations = (uintptr_t) draw->vs.machine.Declarations; + info.num_declarations = draw->vs.machine.NumDeclarations; + info.instructions = (uintptr_t) draw->vs.machine.Instructions; + info.num_instructions = draw->vs.machine.NumInstructions; + info.immediates = (uintptr_t) draw->vs.machine.Imms; + info.num_immediates = draw->vs.machine.ImmLimit / 4; + + emit_state_cmd(cell, CELL_CMD_STATE_BIND_VS, &info, sizeof(info)); + } +#endif +} diff --git a/src/gallium/drivers/cell/ppu/cell_state_emit.h b/src/gallium/drivers/cell/ppu/cell_state_emit.h new file mode 100644 index 0000000..59f8aff --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_state_emit.h @@ -0,0 +1,36 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef CELL_STATE_EMIT_H +#define CELL_STATE_EMIT_H + + +extern void +cell_emit_state(struct cell_context *cell); + + +#endif /* CELL_STATE_EMIT_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_state_per_fragment.c b/src/gallium/drivers/cell/ppu/cell_state_per_fragment.c new file mode 100644 index 0000000..dc33e7c --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_state_per_fragment.c @@ -0,0 +1,1432 @@ +/* + * (C) Copyright IBM Corporation 2008 + * 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 + * 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 + * AUTHORS, COPYRIGHT HOLDERS, 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. + */ + +/** + * \file + * Generate code to perform all per-fragment operations. + * + * Code generated by these functions perform both alpha, depth, and stencil + * testing as well as alpha blending. + * + * \note + * Occlusion query is not supported, but this is the right place to add that + * support. + * + * \author Ian Romanick + */ + +#include "pipe/p_defines.h" +#include "pipe/p_state.h" + +#include "cell_context.h" + +#include "rtasm/rtasm_ppc_spe.h" + + +/** + * Generate code to perform alpha testing. + * + * The code generated by this function uses the register specificed by + * \c mask as both an input and an output. + * + * \param dsa Current alpha-test state + * \param f Function to which code should be appended + * \param mask Index of register containing active fragment mask + * \param alphas Index of register containing per-fragment alpha values + * + * \note Emits a maximum of 6 instructions. + */ +static void +emit_alpha_test(struct pipe_depth_stencil_alpha_state *dsa, + struct spe_function *f, int mask, int alphas) +{ + /* If the alpha function is either NEVER or ALWAYS, there is no need to + * load the reference value into a register. ALWAYS is a fairly common + * case, and this optimization saves 2 instructions. + */ + if (dsa->alpha.enabled + && (dsa->alpha.func != PIPE_FUNC_NEVER) + && (dsa->alpha.func != PIPE_FUNC_ALWAYS)) { + int ref = spe_allocate_available_register(f); + int tmp_a = spe_allocate_available_register(f); + int tmp_b = spe_allocate_available_register(f); + union { + float f; + unsigned u; + } ref_val; + boolean complement = FALSE; + + ref_val.f = dsa->alpha.ref; + + spe_il(f, ref, ref_val.u & 0x0000ffff); + spe_ilh(f, ref, ref_val.u >> 16); + + switch (dsa->alpha.func) { + case PIPE_FUNC_NOTEQUAL: + complement = TRUE; + /* FALLTHROUGH */ + + case PIPE_FUNC_EQUAL: + spe_fceq(f, tmp_a, ref, alphas); + break; + + case PIPE_FUNC_LEQUAL: + complement = TRUE; + /* FALLTHROUGH */ + + case PIPE_FUNC_GREATER: + spe_fcgt(f, tmp_a, ref, alphas); + break; + + case PIPE_FUNC_LESS: + complement = TRUE; + /* FALLTHROUGH */ + + case PIPE_FUNC_GEQUAL: + spe_fcgt(f, tmp_a, ref, alphas); + spe_fceq(f, tmp_b, ref, alphas); + spe_or(f, tmp_a, tmp_b, tmp_a); + break; + + case PIPE_FUNC_ALWAYS: + case PIPE_FUNC_NEVER: + default: + assert(0); + break; + } + + if (complement) { + spe_andc(f, mask, mask, tmp_a); + } else { + spe_and(f, mask, mask, tmp_a); + } + + spe_release_register(f, ref); + spe_release_register(f, tmp_a); + spe_release_register(f, tmp_b); + } else if (dsa->alpha.enabled && (dsa->alpha.func == PIPE_FUNC_NEVER)) { + spe_il(f, mask, 0); + } +} + + +/** + * Generate code to perform Z testing. Four Z values are tested at once. + * \param dsa Current depth-test state + * \param f Function to which code should be appended + * \param mask Index of register to contain depth-pass mask + * \param stored Index of register containing values from depth buffer + * \param calculated Index of register containing per-fragment depth values + * + * \return + * If the calculated depth comparison mask is the actual mask, \c FALSE is + * returned. If the calculated depth comparison mask is the compliment of + * the actual mask, \c TRUE is returned. + * + * \note Emits a maximum of 3 instructions. + */ +static boolean +emit_depth_test(struct pipe_depth_stencil_alpha_state *dsa, + struct spe_function *f, int mask, int stored, int calculated) +{ + unsigned func = (dsa->depth.enabled) + ? dsa->depth.func : PIPE_FUNC_ALWAYS; + int tmp = spe_allocate_available_register(f); + boolean compliment = FALSE; + + switch (func) { + case PIPE_FUNC_NEVER: + spe_il(f, mask, 0); + break; + + case PIPE_FUNC_NOTEQUAL: + compliment = TRUE; + /* FALLTHROUGH */ + case PIPE_FUNC_EQUAL: + spe_ceq(f, mask, calculated, stored); + break; + + case PIPE_FUNC_LEQUAL: + compliment = TRUE; + /* FALLTHROUGH */ + case PIPE_FUNC_GREATER: + spe_clgt(f, mask, calculated, stored); + break; + + case PIPE_FUNC_LESS: + compliment = TRUE; + /* FALLTHROUGH */ + case PIPE_FUNC_GEQUAL: + spe_clgt(f, mask, calculated, stored); + spe_ceq(f, tmp, calculated, stored); + spe_or(f, mask, mask, tmp); + break; + + case PIPE_FUNC_ALWAYS: + spe_il(f, mask, ~0); + break; + + default: + assert(0); + break; + } + + spe_release_register(f, tmp); + return compliment; +} + + +/** + * Generate code to apply the stencil operation (after testing). + * \note Emits a maximum of 5 instructions. + * + * \warning + * Since \c out and \c in might be the same register, this routine cannot + * generate code that uses \c out as a temporary. + */ +static void +emit_stencil_op(struct spe_function *f, + int out, int in, int mask, unsigned op, unsigned ref) +{ + const int clamp = spe_allocate_available_register(f); + const int clamp_mask = spe_allocate_available_register(f); + const int result = spe_allocate_available_register(f); + + switch(op) { + case PIPE_STENCIL_OP_KEEP: + assert(0); + case PIPE_STENCIL_OP_ZERO: + spe_il(f, result, 0); + break; + case PIPE_STENCIL_OP_REPLACE: + spe_il(f, result, ref); + break; + case PIPE_STENCIL_OP_INCR: + /* clamp = [0xff, 0xff, 0xff, 0xff] */ + spe_il(f, clamp, 0x0ff); + /* result[i] = in[i] + 1 */ + spe_ai(f, result, in, 1); + /* clamp_mask[i] = (result[i] > 0xff) */ + spe_clgti(f, clamp_mask, result, 0x0ff); + /* result[i] = clamp_mask[i] ? clamp[i] : result[i] */ + spe_selb(f, result, result, clamp, clamp_mask); + break; + case PIPE_STENCIL_OP_DECR: + spe_il(f, clamp, 0); + spe_ai(f, result, in, -1); + + /* If "(s-1) < 0" in signed arithemtic, then "(s-1) > MAX" in unsigned + * arithmetic. + */ + spe_clgti(f, clamp_mask, result, 0x0ff); + spe_selb(f, result, result, clamp, clamp_mask); + break; + case PIPE_STENCIL_OP_INCR_WRAP: + spe_ai(f, result, in, 1); + break; + case PIPE_STENCIL_OP_DECR_WRAP: + spe_ai(f, result, in, -1); + break; + case PIPE_STENCIL_OP_INVERT: + spe_nor(f, result, in, in); + break; + default: + assert(0); + } + + spe_selb(f, out, in, result, mask); + + spe_release_register(f, result); + spe_release_register(f, clamp_mask); + spe_release_register(f, clamp); +} + + +/** + * Generate code to do stencil test. Four pixels are tested at once. + * \param dsa Depth / stencil test state + * \param face 0 for front face, 1 for back face + * \param f Function to append instructions to + * \param mask Register containing mask of fragments passing the + * alpha test + * \param depth_mask Register containing mask of fragments passing the + * depth test + * \param depth_compliment Is \c depth_mask the compliment of the actual mask? + * \param stencil Register containing values from stencil buffer + * \param depth_pass Register to store mask of fragments passing stencil test + * and depth test + * + * \note + * Emits a maximum of 10 + (3 * 5) = 25 instructions. + */ +static int +emit_stencil_test(struct pipe_depth_stencil_alpha_state *dsa, + struct pipe_stencil_ref *sr, + unsigned face, + struct spe_function *f, + int mask, + int depth_mask, + boolean depth_complement, + int stencil, + int depth_pass) +{ + int stencil_fail = spe_allocate_available_register(f); + int depth_fail = spe_allocate_available_register(f); + int stencil_mask = spe_allocate_available_register(f); + int stencil_pass = spe_allocate_available_register(f); + int face_stencil = spe_allocate_available_register(f); + int stencil_src = stencil; + const unsigned ref = (sr->ref_value[face] + & dsa->stencil[face].valuemask); + boolean complement = FALSE; + int stored; + int tmp = spe_allocate_available_register(f); + + + if ((dsa->stencil[face].func != PIPE_FUNC_NEVER) + && (dsa->stencil[face].func != PIPE_FUNC_ALWAYS) + && (dsa->stencil[face].valuemask != 0x0ff)) { + stored = spe_allocate_available_register(f); + spe_andi(f, stored, stencil, dsa->stencil[face].valuemask); + } else { + stored = stencil; + } + + + switch (dsa->stencil[face].func) { + case PIPE_FUNC_NEVER: + spe_il(f, stencil_mask, 0); /* stencil_mask[0..3] = [0,0,0,0] */ + break; + + case PIPE_FUNC_NOTEQUAL: + complement = TRUE; + /* FALLTHROUGH */ + case PIPE_FUNC_EQUAL: + /* stencil_mask[i] = (stored[i] == ref) */ + spe_ceqi(f, stencil_mask, stored, ref); + break; + + case PIPE_FUNC_LEQUAL: + complement = TRUE; + /* FALLTHROUGH */ + case PIPE_FUNC_GREATER: + complement = TRUE; + /* stencil_mask[i] = (stored[i] > ref) */ + spe_clgti(f, stencil_mask, stored, ref); + break; + + case PIPE_FUNC_LESS: + complement = TRUE; + /* FALLTHROUGH */ + case PIPE_FUNC_GEQUAL: + /* stencil_mask[i] = (stored[i] > ref) */ + spe_clgti(f, stencil_mask, stored, ref); + /* tmp[i] = (stored[i] == ref) */ + spe_ceqi(f, tmp, stored, ref); + /* stencil_mask[i] = stencil_mask[i] | tmp[i] */ + spe_or(f, stencil_mask, stencil_mask, tmp); + break; + + case PIPE_FUNC_ALWAYS: + /* See comment below. */ + break; + + default: + assert(0); + break; + } + + if (stored != stencil) { + spe_release_register(f, stored); + } + spe_release_register(f, tmp); + + + /* ALWAYS is a very common stencil-test, so some effort is applied to + * optimize that case. The stencil-pass mask is the same as the input + * fragment mask. This makes the stencil-test (above) a no-op, and the + * input fragment mask can be "renamed" the stencil-pass mask. + */ + if (dsa->stencil[face].func == PIPE_FUNC_ALWAYS) { + spe_release_register(f, stencil_pass); + stencil_pass = mask; + } else { + if (complement) { + spe_andc(f, stencil_pass, mask, stencil_mask); + } else { + spe_and(f, stencil_pass, mask, stencil_mask); + } + } + + if (depth_complement) { + spe_andc(f, depth_pass, stencil_pass, depth_mask); + } else { + spe_and(f, depth_pass, stencil_pass, depth_mask); + } + + + /* Conditionally emit code to update the stencil value under various + * condititons. Note that there is no need to generate code under the + * following circumstances: + * + * - Stencil write mask is zero. + * - For stencil-fail if the stencil test is ALWAYS + * - For depth-fail if the stencil test is NEVER + * - For depth-pass if the stencil test is NEVER + * - Any of the 3 conditions if the operation is KEEP + */ + if (dsa->stencil[face].writemask != 0) { + if ((dsa->stencil[face].func != PIPE_FUNC_ALWAYS) + && (dsa->stencil[face].fail_op != PIPE_STENCIL_OP_KEEP)) { + if (complement) { + spe_and(f, stencil_fail, mask, stencil_mask); + } else { + spe_andc(f, stencil_fail, mask, stencil_mask); + } + + emit_stencil_op(f, face_stencil, stencil_src, stencil_fail, + dsa->stencil[face].fail_op, + sr->ref_value[face]); + + stencil_src = face_stencil; + } + + if ((dsa->stencil[face].func != PIPE_FUNC_NEVER) + && (dsa->stencil[face].zfail_op != PIPE_STENCIL_OP_KEEP)) { + if (depth_complement) { + spe_and(f, depth_fail, stencil_pass, depth_mask); + } else { + spe_andc(f, depth_fail, stencil_pass, depth_mask); + } + + emit_stencil_op(f, face_stencil, stencil_src, depth_fail, + dsa->stencil[face].zfail_op, + sr->ref_value[face]); + stencil_src = face_stencil; + } + + if ((dsa->stencil[face].func != PIPE_FUNC_NEVER) + && (dsa->stencil[face].zpass_op != PIPE_STENCIL_OP_KEEP)) { + emit_stencil_op(f, face_stencil, stencil_src, depth_pass, + dsa->stencil[face].zpass_op, + sr->ref_value[face]); + stencil_src = face_stencil; + } + } + + spe_release_register(f, stencil_fail); + spe_release_register(f, depth_fail); + spe_release_register(f, stencil_mask); + if (stencil_pass != mask) { + spe_release_register(f, stencil_pass); + } + + /* If all of the stencil operations were KEEP or the stencil write mask was + * zero, "stencil_src" will still be set to "stencil". In this case + * release the "face_stencil" register. Otherwise apply the stencil write + * mask to select bits from the calculated stencil value and the previous + * stencil value. + */ + if (stencil_src == stencil) { + spe_release_register(f, face_stencil); + } else if (dsa->stencil[face].writemask != 0x0ff) { + int tmp = spe_allocate_available_register(f); + + spe_il(f, tmp, dsa->stencil[face].writemask); + spe_selb(f, stencil_src, stencil, stencil_src, tmp); + + spe_release_register(f, tmp); + } + + return stencil_src; +} + + +void +cell_generate_depth_stencil_test(struct cell_depth_stencil_alpha_state *cdsa, + struct pipe_stencil_ref *sr) +{ + struct pipe_depth_stencil_alpha_state *const dsa = &cdsa->base; + struct spe_function *const f = &cdsa->code; + + /* This code generates a maximum of 6 (alpha test) + 3 (depth test) + * + 25 (front stencil) + 25 (back stencil) + 4 = 63 instructions. Round + * up to 64 to make it a happy power-of-two. + */ + spe_init_func(f, SPE_INST_SIZE * 64); + + + /* Allocate registers for the function's input parameters. Cleverly (and + * clever code is usually dangerous, but I couldn't resist) the generated + * function returns a structure. Returned structures start with register + * 3, and the structure fields are ordered to match up exactly with the + * input parameters. + */ + int mask = spe_allocate_register(f, 3); + int depth = spe_allocate_register(f, 4); + int stencil = spe_allocate_register(f, 5); + int zvals = spe_allocate_register(f, 6); + int frag_a = spe_allocate_register(f, 7); + int facing = spe_allocate_register(f, 8); + + int depth_mask = spe_allocate_available_register(f); + + boolean depth_complement; + + + emit_alpha_test(dsa, f, mask, frag_a); + + depth_complement = emit_depth_test(dsa, f, depth_mask, depth, zvals); + + if (dsa->stencil[0].enabled) { + const int front_depth_pass = spe_allocate_available_register(f); + int front_stencil = emit_stencil_test(dsa, sr, 0, f, mask, + depth_mask, depth_complement, + stencil, front_depth_pass); + + if (dsa->stencil[1].enabled) { + const int back_depth_pass = spe_allocate_available_register(f); + int back_stencil = emit_stencil_test(dsa, sr, 1, f, mask, + depth_mask, depth_complement, + stencil, back_depth_pass); + + /* If the front facing stencil value and the back facing stencil + * value are stored in the same register, there is no need to select + * a value based on the facing. This can happen if the stencil value + * was not modified due to the write masks being zero, the stencil + * operations being KEEP, etc. + */ + if (front_stencil != back_stencil) { + spe_selb(f, stencil, back_stencil, front_stencil, facing); + } + + if (back_stencil != stencil) { + spe_release_register(f, back_stencil); + } + + if (front_stencil != stencil) { + spe_release_register(f, front_stencil); + } + + spe_selb(f, mask, back_depth_pass, front_depth_pass, facing); + + spe_release_register(f, back_depth_pass); + } else { + if (front_stencil != stencil) { + spe_or(f, stencil, front_stencil, front_stencil); + spe_release_register(f, front_stencil); + } + spe_or(f, mask, front_depth_pass, front_depth_pass); + } + + spe_release_register(f, front_depth_pass); + } else if (dsa->depth.enabled) { + if (depth_complement) { + spe_andc(f, mask, mask, depth_mask); + } else { + spe_and(f, mask, mask, depth_mask); + } + } + + if (dsa->depth.writemask) { + spe_selb(f, depth, depth, zvals, mask); + } + + spe_bi(f, 0, 0, 0); /* return from function call */ + + +#if 0 + { + const uint32_t *p = f->store; + unsigned i; + + printf("# alpha (%sabled)\n", + (dsa->alpha.enabled) ? "en" : "dis"); + printf("# func: %u\n", dsa->alpha.func); + printf("# ref: %.2f\n", dsa->alpha.ref); + + printf("# depth (%sabled)\n", + (dsa->depth.enabled) ? "en" : "dis"); + printf("# func: %u\n", dsa->depth.func); + + for (i = 0; i < 2; i++) { + printf("# %s stencil (%sabled)\n", + (i == 0) ? "front" : "back", + (dsa->stencil[i].enabled) ? "en" : "dis"); + + printf("# func: %u\n", dsa->stencil[i].func); + printf("# op (sf, zf, zp): %u %u %u\n", + dsa->stencil[i].fail_op, + dsa->stencil[i].zfail_op, + dsa->stencil[i].zpass_op); + printf("# ref value / value mask / write mask: %02x %02x %02x\n", + sr->ref_value[i], + dsa->stencil[i].valuemask, + dsa->stencil[i].writemask); + } + + printf("\t.text\n"); + for (/* empty */; p < f->csr; p++) { + printf("\t.long\t0x%04x\n", *p); + } + fflush(stdout); + } +#endif +} + + +/** + * \note Emits a maximum of 3 instructions + */ +static int +emit_alpha_factor_calculation(struct spe_function *f, + unsigned factor, + int src_alpha, int dst_alpha, int const_alpha) +{ + int factor_reg; + int tmp; + + + switch (factor) { + case PIPE_BLENDFACTOR_ONE: + factor_reg = -1; + break; + + case PIPE_BLENDFACTOR_SRC_ALPHA: + factor_reg = spe_allocate_available_register(f); + + spe_or(f, factor_reg, src_alpha, src_alpha); + break; + + case PIPE_BLENDFACTOR_DST_ALPHA: + factor_reg = dst_alpha; + break; + + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + factor_reg = -1; + break; + + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + factor_reg = spe_allocate_available_register(f); + + tmp = spe_allocate_available_register(f); + spe_il(f, tmp, 1); + spe_cuflt(f, tmp, tmp, 0); + spe_fs(f, factor_reg, tmp, const_alpha); + spe_release_register(f, tmp); + break; + + case PIPE_BLENDFACTOR_CONST_ALPHA: + factor_reg = const_alpha; + break; + + case PIPE_BLENDFACTOR_ZERO: + factor_reg = -1; + break; + + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + tmp = spe_allocate_available_register(f); + factor_reg = spe_allocate_available_register(f); + + spe_il(f, tmp, 1); + spe_cuflt(f, tmp, tmp, 0); + spe_fs(f, factor_reg, tmp, src_alpha); + + spe_release_register(f, tmp); + break; + + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + tmp = spe_allocate_available_register(f); + factor_reg = spe_allocate_available_register(f); + + spe_il(f, tmp, 1); + spe_cuflt(f, tmp, tmp, 0); + spe_fs(f, factor_reg, tmp, dst_alpha); + + spe_release_register(f, tmp); + break; + + case PIPE_BLENDFACTOR_SRC1_ALPHA: + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + default: + assert(0); + factor_reg = -1; + break; + } + + return factor_reg; +} + + +/** + * \note Emits a maximum of 6 instructions + */ +static void +emit_color_factor_calculation(struct spe_function *f, + unsigned sF, unsigned mask, + const int *src, + const int *dst, + const int *const_color, + int *factor) +{ + int tmp; + unsigned i; + + + factor[0] = -1; + factor[1] = -1; + factor[2] = -1; + factor[3] = -1; + + switch (sF) { + case PIPE_BLENDFACTOR_ONE: + break; + + case PIPE_BLENDFACTOR_SRC_COLOR: + for (i = 0; i < 3; ++i) { + if ((mask & (1U << i)) != 0) { + factor[i] = spe_allocate_available_register(f); + spe_or(f, factor[i], src[i], src[i]); + } + } + break; + + case PIPE_BLENDFACTOR_SRC_ALPHA: + factor[0] = spe_allocate_available_register(f); + factor[1] = factor[0]; + factor[2] = factor[0]; + + spe_or(f, factor[0], src[3], src[3]); + break; + + case PIPE_BLENDFACTOR_DST_ALPHA: + factor[0] = dst[3]; + factor[1] = dst[3]; + factor[2] = dst[3]; + break; + + case PIPE_BLENDFACTOR_DST_COLOR: + factor[0] = dst[0]; + factor[1] = dst[1]; + factor[2] = dst[2]; + break; + + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + tmp = spe_allocate_available_register(f); + factor[0] = spe_allocate_available_register(f); + factor[1] = factor[0]; + factor[2] = factor[0]; + + /* Alpha saturate means min(As, 1-Ad). + */ + spe_il(f, tmp, 1); + spe_cuflt(f, tmp, tmp, 0); + spe_fs(f, tmp, tmp, dst[3]); + spe_fcgt(f, factor[0], tmp, src[3]); + spe_selb(f, factor[0], src[3], tmp, factor[0]); + + spe_release_register(f, tmp); + break; + + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + tmp = spe_allocate_available_register(f); + spe_il(f, tmp, 1); + spe_cuflt(f, tmp, tmp, 0); + + for (i = 0; i < 3; i++) { + factor[i] = spe_allocate_available_register(f); + + spe_fs(f, factor[i], tmp, const_color[i]); + } + spe_release_register(f, tmp); + break; + + case PIPE_BLENDFACTOR_CONST_COLOR: + for (i = 0; i < 3; i++) { + factor[i] = const_color[i]; + } + break; + + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + factor[0] = spe_allocate_available_register(f); + factor[1] = factor[0]; + factor[2] = factor[0]; + + tmp = spe_allocate_available_register(f); + spe_il(f, tmp, 1); + spe_cuflt(f, tmp, tmp, 0); + spe_fs(f, factor[0], tmp, const_color[3]); + spe_release_register(f, tmp); + break; + + case PIPE_BLENDFACTOR_CONST_ALPHA: + factor[0] = const_color[3]; + factor[1] = factor[0]; + factor[2] = factor[0]; + break; + + case PIPE_BLENDFACTOR_ZERO: + break; + + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + tmp = spe_allocate_available_register(f); + + spe_il(f, tmp, 1); + spe_cuflt(f, tmp, tmp, 0); + + for (i = 0; i < 3; ++i) { + if ((mask & (1U << i)) != 0) { + factor[i] = spe_allocate_available_register(f); + spe_fs(f, factor[i], tmp, src[i]); + } + } + + spe_release_register(f, tmp); + break; + + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + tmp = spe_allocate_available_register(f); + factor[0] = spe_allocate_available_register(f); + factor[1] = factor[0]; + factor[2] = factor[0]; + + spe_il(f, tmp, 1); + spe_cuflt(f, tmp, tmp, 0); + spe_fs(f, factor[0], tmp, src[3]); + + spe_release_register(f, tmp); + break; + + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + tmp = spe_allocate_available_register(f); + factor[0] = spe_allocate_available_register(f); + factor[1] = factor[0]; + factor[2] = factor[0]; + + spe_il(f, tmp, 1); + spe_cuflt(f, tmp, tmp, 0); + spe_fs(f, factor[0], tmp, dst[3]); + + spe_release_register(f, tmp); + break; + + case PIPE_BLENDFACTOR_INV_DST_COLOR: + tmp = spe_allocate_available_register(f); + + spe_il(f, tmp, 1); + spe_cuflt(f, tmp, tmp, 0); + + for (i = 0; i < 3; ++i) { + if ((mask & (1U << i)) != 0) { + factor[i] = spe_allocate_available_register(f); + spe_fs(f, factor[i], tmp, dst[i]); + } + } + + spe_release_register(f, tmp); + break; + + case PIPE_BLENDFACTOR_SRC1_COLOR: + case PIPE_BLENDFACTOR_SRC1_ALPHA: + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + default: + assert(0); + } +} + + +static void +emit_blend_calculation(struct spe_function *f, + unsigned func, unsigned sF, unsigned dF, + int src, int src_factor, int dst, int dst_factor) +{ + int tmp = spe_allocate_available_register(f); + + switch (func) { + case PIPE_BLEND_ADD: + if (sF == PIPE_BLENDFACTOR_ONE) { + if (dF == PIPE_BLENDFACTOR_ZERO) { + /* Do nothing. */ + } else if (dF == PIPE_BLENDFACTOR_ONE) { + spe_fa(f, src, src, dst); + } + } else if (sF == PIPE_BLENDFACTOR_ZERO) { + if (dF == PIPE_BLENDFACTOR_ZERO) { + spe_il(f, src, 0); + } else if (dF == PIPE_BLENDFACTOR_ONE) { + spe_or(f, src, dst, dst); + } else { + spe_fm(f, src, dst, dst_factor); + } + } else if (dF == PIPE_BLENDFACTOR_ZERO) { + spe_fm(f, src, src, src_factor); + } else { + spe_fm(f, tmp, dst, dst_factor); + spe_fma(f, src, src, src_factor, tmp); + } + break; + + case PIPE_BLEND_SUBTRACT: + if (sF == PIPE_BLENDFACTOR_ONE) { + if (dF == PIPE_BLENDFACTOR_ZERO) { + /* Do nothing. */ + } else if (dF == PIPE_BLENDFACTOR_ONE) { + spe_fs(f, src, src, dst); + } + } else if (sF == PIPE_BLENDFACTOR_ZERO) { + if (dF == PIPE_BLENDFACTOR_ZERO) { + spe_il(f, src, 0); + } else if (dF == PIPE_BLENDFACTOR_ONE) { + spe_il(f, tmp, 0); + spe_fs(f, src, tmp, dst); + } else { + spe_fm(f, src, dst, dst_factor); + } + } else if (dF == PIPE_BLENDFACTOR_ZERO) { + spe_fm(f, src, src, src_factor); + } else { + spe_fm(f, tmp, dst, dst_factor); + spe_fms(f, src, src, src_factor, tmp); + } + break; + + case PIPE_BLEND_REVERSE_SUBTRACT: + if (sF == PIPE_BLENDFACTOR_ONE) { + if (dF == PIPE_BLENDFACTOR_ZERO) { + spe_il(f, tmp, 0); + spe_fs(f, src, tmp, src); + } else if (dF == PIPE_BLENDFACTOR_ONE) { + spe_fs(f, src, dst, src); + } + } else if (sF == PIPE_BLENDFACTOR_ZERO) { + if (dF == PIPE_BLENDFACTOR_ZERO) { + spe_il(f, src, 0); + } else if (dF == PIPE_BLENDFACTOR_ONE) { + spe_or(f, src, dst, dst); + } else { + spe_fm(f, src, dst, dst_factor); + } + } else if (dF == PIPE_BLENDFACTOR_ZERO) { + spe_fm(f, src, src, src_factor); + } else { + spe_fm(f, tmp, src, src_factor); + spe_fms(f, src, src, dst_factor, tmp); + } + break; + + case PIPE_BLEND_MIN: + spe_cgt(f, tmp, src, dst); + spe_selb(f, src, src, dst, tmp); + break; + + case PIPE_BLEND_MAX: + spe_cgt(f, tmp, src, dst); + spe_selb(f, src, dst, src, tmp); + break; + + default: + assert(0); + } + + spe_release_register(f, tmp); +} + + +/** + * Generate code to perform alpha blending on the SPE + */ +void +cell_generate_alpha_blend(struct cell_blend_state *cb) +{ + struct pipe_blend_state *const b = &cb->base; + struct spe_function *const f = &cb->code; + + /* This code generates a maximum of 3 (source alpha factor) + * + 3 (destination alpha factor) + (3 * 6) (source color factor) + * + (3 * 6) (destination color factor) + (4 * 2) (blend equation) + * + 4 (fragment mask) + 1 (return) = 55 instlructions. Round up to 64 to + * make it a happy power-of-two. + */ + spe_init_func(f, SPE_INST_SIZE * 64); + + + const int frag[4] = { + spe_allocate_register(f, 3), + spe_allocate_register(f, 4), + spe_allocate_register(f, 5), + spe_allocate_register(f, 6), + }; + const int pixel[4] = { + spe_allocate_register(f, 7), + spe_allocate_register(f, 8), + spe_allocate_register(f, 9), + spe_allocate_register(f, 10), + }; + const int const_color[4] = { + spe_allocate_register(f, 11), + spe_allocate_register(f, 12), + spe_allocate_register(f, 13), + spe_allocate_register(f, 14), + }; + unsigned func[4]; + unsigned sF[4]; + unsigned dF[4]; + unsigned i; + int src_factor[4]; + int dst_factor[4]; + + + /* Does the selected blend mode make use of the source / destination + * color (RGB) blend factors? + */ + boolean need_color_factor = b->rt[0].blend_enable + && (b->rt[0].rgb_func != PIPE_BLEND_MIN) + && (b->rt[0].rgb_func != PIPE_BLEND_MAX); + + /* Does the selected blend mode make use of the source / destination + * alpha blend factors? + */ + boolean need_alpha_factor = b->rt[0].blend_enable + && (b->rt[0].alpha_func != PIPE_BLEND_MIN) + && (b->rt[0].alpha_func != PIPE_BLEND_MAX); + + + if (b->rt[0].blend_enable) { + sF[0] = b->rt[0].rgb_src_factor; + sF[1] = sF[0]; + sF[2] = sF[0]; + switch (b->rt[0].alpha_src_factor & 0x0f) { + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + sF[3] = PIPE_BLENDFACTOR_ONE; + break; + case PIPE_BLENDFACTOR_SRC_COLOR: + case PIPE_BLENDFACTOR_DST_COLOR: + case PIPE_BLENDFACTOR_CONST_COLOR: + case PIPE_BLENDFACTOR_SRC1_COLOR: + sF[3] = b->rt[0].alpha_src_factor + 1; + break; + default: + sF[3] = b->rt[0].alpha_src_factor; + } + + dF[0] = b->rt[0].rgb_dst_factor; + dF[1] = dF[0]; + dF[2] = dF[0]; + switch (b->rt[0].alpha_dst_factor & 0x0f) { + case PIPE_BLENDFACTOR_SRC_COLOR: + case PIPE_BLENDFACTOR_DST_COLOR: + case PIPE_BLENDFACTOR_CONST_COLOR: + case PIPE_BLENDFACTOR_SRC1_COLOR: + dF[3] = b->rt[0].alpha_dst_factor + 1; + break; + default: + dF[3] = b->rt[0].alpha_dst_factor; + } + + func[0] = b->rt[0].rgb_func; + func[1] = func[0]; + func[2] = func[0]; + func[3] = b->rt[0].alpha_func; + } else { + sF[0] = PIPE_BLENDFACTOR_ONE; + sF[1] = PIPE_BLENDFACTOR_ONE; + sF[2] = PIPE_BLENDFACTOR_ONE; + sF[3] = PIPE_BLENDFACTOR_ONE; + dF[0] = PIPE_BLENDFACTOR_ZERO; + dF[1] = PIPE_BLENDFACTOR_ZERO; + dF[2] = PIPE_BLENDFACTOR_ZERO; + dF[3] = PIPE_BLENDFACTOR_ZERO; + + func[0] = PIPE_BLEND_ADD; + func[1] = PIPE_BLEND_ADD; + func[2] = PIPE_BLEND_ADD; + func[3] = PIPE_BLEND_ADD; + } + + + /* If alpha writing is enabled and the alpha blend mode requires use of + * the alpha factor, calculate the alpha factor. + */ + if (((b->rt[0].colormask & 8) != 0) && need_alpha_factor) { + src_factor[3] = emit_alpha_factor_calculation(f, sF[3], const_color[3], + frag[3], pixel[3]); + + /* If the alpha destination blend factor is the same as the alpha source + * blend factor, re-use the previously calculated value. + */ + dst_factor[3] = (dF[3] == sF[3]) + ? src_factor[3] + : emit_alpha_factor_calculation(f, dF[3], const_color[3], + frag[3], pixel[3]); + } + + + if (sF[0] == sF[3]) { + src_factor[0] = src_factor[3]; + src_factor[1] = src_factor[3]; + src_factor[2] = src_factor[3]; + } else if (sF[0] == dF[3]) { + src_factor[0] = dst_factor[3]; + src_factor[1] = dst_factor[3]; + src_factor[2] = dst_factor[3]; + } else if (need_color_factor) { + emit_color_factor_calculation(f, + b->rt[0].rgb_src_factor, + b->rt[0].colormask, + frag, pixel, const_color, src_factor); + } + + + if (dF[0] == sF[3]) { + dst_factor[0] = src_factor[3]; + dst_factor[1] = src_factor[3]; + dst_factor[2] = src_factor[3]; + } else if (dF[0] == dF[3]) { + dst_factor[0] = dst_factor[3]; + dst_factor[1] = dst_factor[3]; + dst_factor[2] = dst_factor[3]; + } else if (dF[0] == sF[0]) { + dst_factor[0] = src_factor[0]; + dst_factor[1] = src_factor[1]; + dst_factor[2] = src_factor[2]; + } else if (need_color_factor) { + emit_color_factor_calculation(f, + b->rt[0].rgb_dst_factor, + b->rt[0].colormask, + frag, pixel, const_color, dst_factor); + } + + + + for (i = 0; i < 4; ++i) { + if ((b->rt[0].colormask & (1U << i)) != 0) { + emit_blend_calculation(f, + func[i], sF[i], dF[i], + frag[i], src_factor[i], + pixel[i], dst_factor[i]); + } + } + + spe_bi(f, 0, 0, 0); + +#if 0 + { + const uint32_t *p = f->store; + + printf("# %u instructions\n", f->csr - f->store); + printf("# blend (%sabled)\n", + (cb->base.blend_enable) ? "en" : "dis"); + printf("# RGB func / sf / df: %u %u %u\n", + cb->base.rgb_func, + cb->base.rgb_src_factor, + cb->base.rgb_dst_factor); + printf("# ALP func / sf / df: %u %u %u\n", + cb->base.alpha_func, + cb->base.alpha_src_factor, + cb->base.alpha_dst_factor); + + printf("\t.text\n"); + for (/* empty */; p < f->csr; p++) { + printf("\t.long\t0x%04x\n", *p); + } + fflush(stdout); + } +#endif +} + + +static int +PC_OFFSET(const struct spe_function *f, const void *d) +{ + const intptr_t pc = (intptr_t) &f->store[f->num_inst]; + const intptr_t ea = ~0x0f & (intptr_t) d; + + return (ea - pc) >> 2; +} + + +/** + * Generate code to perform color conversion and logic op + * + * \bug + * The code generated by this function should also perform dithering. + * + * \bug + * The code generated by this function should also perform color-write + * masking. + * + * \bug + * Only two framebuffer formats are supported at this time. + */ +void +cell_generate_logic_op(struct spe_function *f, + const struct pipe_blend_state *blend, + struct pipe_surface *surf) +{ + const unsigned logic_op = (blend->logicop_enable) + ? blend->logicop_func : PIPE_LOGICOP_COPY; + + /* This code generates a maximum of 37 instructions. An additional 32 + * bytes (equiv. to 8 instructions) are needed for data storage. Round up + * to 64 to make it a happy power-of-two. + */ + spe_init_func(f, SPE_INST_SIZE * 64); + + + /* Pixel colors in framebuffer format in AoS layout. + */ + const int pixel[4] = { + spe_allocate_register(f, 3), + spe_allocate_register(f, 4), + spe_allocate_register(f, 5), + spe_allocate_register(f, 6), + }; + + /* Fragment colors stored as floats in SoA layout. + */ + const int frag[4] = { + spe_allocate_register(f, 7), + spe_allocate_register(f, 8), + spe_allocate_register(f, 9), + spe_allocate_register(f, 10), + }; + + const int mask = spe_allocate_register(f, 11); + + + /* Short-circuit the noop and invert cases. + */ + if ((logic_op == PIPE_LOGICOP_NOOP) || (blend->rt[0].colormask == 0)) { + spe_bi(f, 0, 0, 0); + return; + } else if (logic_op == PIPE_LOGICOP_INVERT) { + spe_nor(f, pixel[0], pixel[0], pixel[0]); + spe_nor(f, pixel[1], pixel[1], pixel[1]); + spe_nor(f, pixel[2], pixel[2], pixel[2]); + spe_nor(f, pixel[3], pixel[3], pixel[3]); + spe_bi(f, 0, 0, 0); + return; + } + + + const int tmp[4] = { + spe_allocate_available_register(f), + spe_allocate_available_register(f), + spe_allocate_available_register(f), + spe_allocate_available_register(f), + }; + + const int shuf_xpose_hi = spe_allocate_available_register(f); + const int shuf_xpose_lo = spe_allocate_available_register(f); + const int shuf_color = spe_allocate_available_register(f); + + + /* Pointer to the begining of the function's private data area. + */ + uint32_t *const data = ((uint32_t *) f->store) + (64 - 8); + + + /* Convert fragment colors to framebuffer format in AoS layout. + */ + switch (surf->format) { + case PIPE_FORMAT_B8G8R8A8_UNORM: + data[0] = 0x00010203; + data[1] = 0x10111213; + data[2] = 0x04050607; + data[3] = 0x14151617; + data[4] = 0x0c000408; + data[5] = 0x80808080; + data[6] = 0x80808080; + data[7] = 0x80808080; + break; + case PIPE_FORMAT_A8R8G8B8_UNORM: + data[0] = 0x03020100; + data[1] = 0x13121110; + data[2] = 0x07060504; + data[3] = 0x17161514; + data[4] = 0x0804000c; + data[5] = 0x80808080; + data[6] = 0x80808080; + data[7] = 0x80808080; + break; + default: + fprintf(stderr, "CELL: Bad pixel format in cell_generate_logic_op()"); + ASSERT(0); + } + + spe_ilh(f, tmp[0], 0x0808); + spe_lqr(f, shuf_xpose_hi, PC_OFFSET(f, data+0)); + spe_lqr(f, shuf_color, PC_OFFSET(f, data+4)); + spe_a(f, shuf_xpose_lo, shuf_xpose_hi, tmp[0]); + + spe_shufb(f, tmp[0], frag[0], frag[2], shuf_xpose_hi); + spe_shufb(f, tmp[1], frag[0], frag[2], shuf_xpose_lo); + spe_shufb(f, tmp[2], frag[1], frag[3], shuf_xpose_hi); + spe_shufb(f, tmp[3], frag[1], frag[3], shuf_xpose_lo); + + spe_shufb(f, frag[0], tmp[0], tmp[2], shuf_xpose_hi); + spe_shufb(f, frag[1], tmp[0], tmp[2], shuf_xpose_lo); + spe_shufb(f, frag[2], tmp[1], tmp[3], shuf_xpose_hi); + spe_shufb(f, frag[3], tmp[1], tmp[3], shuf_xpose_lo); + + spe_cfltu(f, frag[0], frag[0], 32); + spe_cfltu(f, frag[1], frag[1], 32); + spe_cfltu(f, frag[2], frag[2], 32); + spe_cfltu(f, frag[3], frag[3], 32); + + spe_shufb(f, frag[0], frag[0], pixel[0], shuf_color); + spe_shufb(f, frag[1], frag[1], pixel[1], shuf_color); + spe_shufb(f, frag[2], frag[2], pixel[2], shuf_color); + spe_shufb(f, frag[3], frag[3], pixel[3], shuf_color); + + + /* If logic op is enabled, perform the requested logical operation on the + * converted fragment colors and the pixel colors. + */ + switch (logic_op) { + case PIPE_LOGICOP_CLEAR: + spe_il(f, frag[0], 0); + spe_il(f, frag[1], 0); + spe_il(f, frag[2], 0); + spe_il(f, frag[3], 0); + break; + case PIPE_LOGICOP_NOR: + spe_nor(f, frag[0], frag[0], pixel[0]); + spe_nor(f, frag[1], frag[1], pixel[1]); + spe_nor(f, frag[2], frag[2], pixel[2]); + spe_nor(f, frag[3], frag[3], pixel[3]); + break; + case PIPE_LOGICOP_AND_INVERTED: + spe_andc(f, frag[0], pixel[0], frag[0]); + spe_andc(f, frag[1], pixel[1], frag[1]); + spe_andc(f, frag[2], pixel[2], frag[2]); + spe_andc(f, frag[3], pixel[3], frag[3]); + break; + case PIPE_LOGICOP_COPY_INVERTED: + spe_nor(f, frag[0], frag[0], frag[0]); + spe_nor(f, frag[1], frag[1], frag[1]); + spe_nor(f, frag[2], frag[2], frag[2]); + spe_nor(f, frag[3], frag[3], frag[3]); + break; + case PIPE_LOGICOP_AND_REVERSE: + spe_andc(f, frag[0], frag[0], pixel[0]); + spe_andc(f, frag[1], frag[1], pixel[1]); + spe_andc(f, frag[2], frag[2], pixel[2]); + spe_andc(f, frag[3], frag[3], pixel[3]); + break; + case PIPE_LOGICOP_XOR: + spe_xor(f, frag[0], frag[0], pixel[0]); + spe_xor(f, frag[1], frag[1], pixel[1]); + spe_xor(f, frag[2], frag[2], pixel[2]); + spe_xor(f, frag[3], frag[3], pixel[3]); + break; + case PIPE_LOGICOP_NAND: + spe_nand(f, frag[0], frag[0], pixel[0]); + spe_nand(f, frag[1], frag[1], pixel[1]); + spe_nand(f, frag[2], frag[2], pixel[2]); + spe_nand(f, frag[3], frag[3], pixel[3]); + break; + case PIPE_LOGICOP_AND: + spe_and(f, frag[0], frag[0], pixel[0]); + spe_and(f, frag[1], frag[1], pixel[1]); + spe_and(f, frag[2], frag[2], pixel[2]); + spe_and(f, frag[3], frag[3], pixel[3]); + break; + case PIPE_LOGICOP_EQUIV: + spe_eqv(f, frag[0], frag[0], pixel[0]); + spe_eqv(f, frag[1], frag[1], pixel[1]); + spe_eqv(f, frag[2], frag[2], pixel[2]); + spe_eqv(f, frag[3], frag[3], pixel[3]); + break; + case PIPE_LOGICOP_OR_INVERTED: + spe_orc(f, frag[0], pixel[0], frag[0]); + spe_orc(f, frag[1], pixel[1], frag[1]); + spe_orc(f, frag[2], pixel[2], frag[2]); + spe_orc(f, frag[3], pixel[3], frag[3]); + break; + case PIPE_LOGICOP_COPY: + break; + case PIPE_LOGICOP_OR_REVERSE: + spe_orc(f, frag[0], frag[0], pixel[0]); + spe_orc(f, frag[1], frag[1], pixel[1]); + spe_orc(f, frag[2], frag[2], pixel[2]); + spe_orc(f, frag[3], frag[3], pixel[3]); + break; + case PIPE_LOGICOP_OR: + spe_or(f, frag[0], frag[0], pixel[0]); + spe_or(f, frag[1], frag[1], pixel[1]); + spe_or(f, frag[2], frag[2], pixel[2]); + spe_or(f, frag[3], frag[3], pixel[3]); + break; + case PIPE_LOGICOP_SET: + spe_il(f, frag[0], ~0); + spe_il(f, frag[1], ~0); + spe_il(f, frag[2], ~0); + spe_il(f, frag[3], ~0); + break; + + /* These two cases are short-circuited above. + */ + case PIPE_LOGICOP_INVERT: + case PIPE_LOGICOP_NOOP: + default: + assert(0); + } + + + /* Apply fragment mask. + */ + spe_ilh(f, tmp[0], 0x0000); + spe_ilh(f, tmp[1], 0x0404); + spe_ilh(f, tmp[2], 0x0808); + spe_ilh(f, tmp[3], 0x0c0c); + + spe_shufb(f, tmp[0], mask, mask, tmp[0]); + spe_shufb(f, tmp[1], mask, mask, tmp[1]); + spe_shufb(f, tmp[2], mask, mask, tmp[2]); + spe_shufb(f, tmp[3], mask, mask, tmp[3]); + + spe_selb(f, pixel[0], pixel[0], frag[0], tmp[0]); + spe_selb(f, pixel[1], pixel[1], frag[1], tmp[1]); + spe_selb(f, pixel[2], pixel[2], frag[2], tmp[2]); + spe_selb(f, pixel[3], pixel[3], frag[3], tmp[3]); + + spe_bi(f, 0, 0, 0); + +#if 0 + { + const uint32_t *p = f->store; + unsigned i; + + printf("# %u instructions\n", f->csr - f->store); + + printf("\t.text\n"); + for (i = 0; i < 64; i++) { + printf("\t.long\t0x%04x\n", p[i]); + } + fflush(stdout); + } +#endif +} diff --git a/src/gallium/drivers/cell/ppu/cell_state_per_fragment.h b/src/gallium/drivers/cell/ppu/cell_state_per_fragment.h new file mode 100644 index 0000000..a8267a5 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_state_per_fragment.h @@ -0,0 +1,39 @@ +/* + * (C) Copyright IBM Corporation 2008 + * 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 + * 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 + * AUTHORS, COPYRIGHT HOLDERS, 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 CELL_STATE_PER_FRAGMENT_H +#define CELL_STATE_PER_FRAGMENT_H + +extern void +cell_generate_depth_stencil_test(struct cell_depth_stencil_alpha_state *cdsa); + +extern void +cell_generate_alpha_blend(struct cell_blend_state *cb); + +extern void +cell_generate_logic_op(struct spe_function *f, + const struct pipe_blend_state *blend, + struct pipe_surface *surf); + +#endif /* CELL_STATE_PER_FRAGMENT_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_state_shader.c b/src/gallium/drivers/cell/ppu/cell_state_shader.c new file mode 100644 index 0000000..ddf1477 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_state_shader.c @@ -0,0 +1,229 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "pipe/p_defines.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "draw/draw_context.h" +#include "tgsi/tgsi_parse.h" + +#include "cell_context.h" +#include "cell_state.h" +#include "cell_gen_fp.h" +#include "cell_texture.h" + + +/** cast wrapper */ +static INLINE struct cell_fragment_shader_state * +cell_fragment_shader_state(void *shader) +{ + return (struct cell_fragment_shader_state *) shader; +} + + +/** cast wrapper */ +static INLINE struct cell_vertex_shader_state * +cell_vertex_shader_state(void *shader) +{ + return (struct cell_vertex_shader_state *) shader; +} + + +/** + * Create fragment shader state. + * Called via pipe->create_fs_state() + */ +static void * +cell_create_fs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct cell_context *cell = cell_context(pipe); + struct cell_fragment_shader_state *cfs; + + cfs = CALLOC_STRUCT(cell_fragment_shader_state); + if (!cfs) + return NULL; + + cfs->shader.tokens = tgsi_dup_tokens(templ->tokens); + if (!cfs->shader.tokens) { + FREE(cfs); + return NULL; + } + + tgsi_scan_shader(templ->tokens, &cfs->info); + + cell_gen_fragment_program(cell, cfs->shader.tokens, &cfs->code); + + return cfs; +} + + +/** + * Called via pipe->bind_fs_state() + */ +static void +cell_bind_fs_state(struct pipe_context *pipe, void *fs) +{ + struct cell_context *cell = cell_context(pipe); + + cell->fs = cell_fragment_shader_state(fs); + + cell->dirty |= CELL_NEW_FS; +} + + +/** + * Called via pipe->delete_fs_state() + */ +static void +cell_delete_fs_state(struct pipe_context *pipe, void *fs) +{ + struct cell_fragment_shader_state *cfs = cell_fragment_shader_state(fs); + + spe_release_func(&cfs->code); + + FREE((void *) cfs->shader.tokens); + FREE(cfs); +} + + +/** + * Create vertex shader state. + * Called via pipe->create_vs_state() + */ +static void * +cell_create_vs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct cell_context *cell = cell_context(pipe); + struct cell_vertex_shader_state *cvs; + + cvs = CALLOC_STRUCT(cell_vertex_shader_state); + if (!cvs) + return NULL; + + cvs->shader.tokens = tgsi_dup_tokens(templ->tokens); + if (!cvs->shader.tokens) { + FREE(cvs); + return NULL; + } + + tgsi_scan_shader(templ->tokens, &cvs->info); + + cvs->draw_data = draw_create_vertex_shader(cell->draw, &cvs->shader); + if (cvs->draw_data == NULL) { + FREE( (void *) cvs->shader.tokens ); + FREE( cvs ); + return NULL; + } + + return cvs; +} + + +/** + * Called via pipe->bind_vs_state() + */ +static void +cell_bind_vs_state(struct pipe_context *pipe, void *vs) +{ + struct cell_context *cell = cell_context(pipe); + + cell->vs = cell_vertex_shader_state(vs); + + draw_bind_vertex_shader(cell->draw, + (cell->vs ? cell->vs->draw_data : NULL)); + + cell->dirty |= CELL_NEW_VS; +} + + +/** + * Called via pipe->delete_vs_state() + */ +static void +cell_delete_vs_state(struct pipe_context *pipe, void *vs) +{ + struct cell_context *cell = cell_context(pipe); + struct cell_vertex_shader_state *cvs = cell_vertex_shader_state(vs); + + draw_delete_vertex_shader(cell->draw, cvs->draw_data); + FREE( (void *) cvs->shader.tokens ); + FREE( cvs ); +} + + +/** + * Called via pipe->set_constant_buffer() + */ +static void +cell_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + struct pipe_resource *constants) +{ + struct cell_context *cell = cell_context(pipe); + unsigned size = constants ? constants->width0 : 0; + const void *data = constants ? cell_resource(constants)->data : NULL; + + assert(shader < PIPE_SHADER_TYPES); + assert(index == 0); + + if (cell->constants[shader] == constants) + return; + + draw_flush(cell->draw); + + /* note: reference counting */ + pipe_resource_reference(&cell->constants[shader], constants); + + if(shader == PIPE_SHADER_VERTEX) { + draw_set_mapped_constant_buffer(cell->draw, PIPE_SHADER_VERTEX, 0, + data, size); + } + + cell->mapped_constants[shader] = data; + + if (shader == PIPE_SHADER_VERTEX) + cell->dirty |= CELL_NEW_VS_CONSTANTS; + else if (shader == PIPE_SHADER_FRAGMENT) + cell->dirty |= CELL_NEW_FS_CONSTANTS; +} + + +void +cell_init_shader_functions(struct cell_context *cell) +{ + cell->pipe.create_fs_state = cell_create_fs_state; + cell->pipe.bind_fs_state = cell_bind_fs_state; + cell->pipe.delete_fs_state = cell_delete_fs_state; + + cell->pipe.create_vs_state = cell_create_vs_state; + cell->pipe.bind_vs_state = cell_bind_vs_state; + cell->pipe.delete_vs_state = cell_delete_vs_state; + + cell->pipe.set_constant_buffer = cell_set_constant_buffer; +} diff --git a/src/gallium/drivers/cell/ppu/cell_state_vertex.c b/src/gallium/drivers/cell/ppu/cell_state_vertex.c new file mode 100644 index 0000000..a065d68 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_state_vertex.c @@ -0,0 +1,117 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + + +#include "cell_context.h" +#include "cell_state.h" + +#include "util/u_memory.h" +#include "draw/draw_context.h" + + +static void * +cell_create_vertex_elements_state(struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_element *attribs) +{ + struct cell_velems_state *velems; + assert(count <= PIPE_MAX_ATTRIBS); + velems = (struct cell_velems_state *) MALLOC(sizeof(struct cell_velems_state)); + if (velems) { + velems->count = count; + memcpy(velems->velem, attribs, sizeof(*attribs) * count); + } + return velems; +} + +static void +cell_bind_vertex_elements_state(struct pipe_context *pipe, + void *velems) +{ + struct cell_context *cell = cell_context(pipe); + struct cell_velems_state *cell_velems = (struct cell_velems_state *) velems; + + cell->velems = cell_velems; + + cell->dirty |= CELL_NEW_VERTEX; + + if (cell_velems) + draw_set_vertex_elements(cell->draw, cell_velems->count, cell_velems->velem); +} + +static void +cell_delete_vertex_elements_state(struct pipe_context *pipe, void *velems) +{ + FREE( velems ); +} + + +static void +cell_set_vertex_buffers(struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_buffer *buffers) +{ + struct cell_context *cell = cell_context(pipe); + + assert(count <= PIPE_MAX_ATTRIBS); + + memcpy(cell->vertex_buffer, buffers, count * sizeof(buffers[0])); + cell->num_vertex_buffers = count; + + cell->dirty |= CELL_NEW_VERTEX; + + draw_set_vertex_buffers(cell->draw, count, buffers); +} + + +static void +cell_set_index_buffer(struct pipe_context *pipe, + const struct pipe_index_buffer *ib) +{ + struct cell_context *cell = cell_context(pipe); + + if (ib) + memcpy(&cell->index_buffer, ib, sizeof(cell->index_buffer)); + else + memset(&cell->index_buffer, 0, sizeof(cell->index_buffer)); + + draw_set_index_buffer(cell->draw, ib); +} + + +void +cell_init_vertex_functions(struct cell_context *cell) +{ + cell->pipe.set_vertex_buffers = cell_set_vertex_buffers; + cell->pipe.set_index_buffer = cell_set_index_buffer; + cell->pipe.create_vertex_elements_state = cell_create_vertex_elements_state; + cell->pipe.bind_vertex_elements_state = cell_bind_vertex_elements_state; + cell->pipe.delete_vertex_elements_state = cell_delete_vertex_elements_state; +} diff --git a/src/gallium/drivers/cell/ppu/cell_surface.c b/src/gallium/drivers/cell/ppu/cell_surface.c new file mode 100644 index 0000000..7774544 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_surface.c @@ -0,0 +1,37 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_surface.h" +#include "cell_context.h" +#include "cell_surface.h" + + +void +cell_init_surface_functions(struct cell_context *cell) +{ + cell->pipe.resource_copy_region = util_resource_copy_region; +} diff --git a/src/gallium/drivers/cell/ppu/cell_surface.h b/src/gallium/drivers/cell/ppu/cell_surface.h new file mode 100644 index 0000000..9e58f32 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_surface.h @@ -0,0 +1,42 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef CELL_SURFACE_H +#define CELL_SURFACE_H + + +struct cell_context; + + +extern void +cell_init_surface_functions(struct cell_context *cell); + + +#endif /* SP_SURFACE_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_texture.c b/src/gallium/drivers/cell/ppu/cell_texture.c new file mode 100644 index 0000000..946a705 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_texture.c @@ -0,0 +1,644 @@ +/************************************************************************** + * + * Copyright 2006 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. + * + **************************************************************************/ + /* + * Authors: + * Keith Whitwell + * Michel Dänzer + * Brian Paul + */ + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_transfer.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "cell_context.h" +#include "cell_screen.h" +#include "cell_state.h" +#include "cell_texture.h" + +#include "state_tracker/sw_winsys.h" + + + +static boolean +cell_resource_layout(struct pipe_screen *screen, + struct cell_resource *ct) +{ + struct pipe_resource *pt = &ct->base; + unsigned level; + unsigned width = pt->width0; + unsigned height = pt->height0; + unsigned depth = pt->depth0; + + ct->buffer_size = 0; + + for (level = 0; level <= pt->last_level; level++) { + unsigned size; + unsigned w_tile, h_tile; + + assert(level < CELL_MAX_TEXTURE_LEVELS); + + /* width, height, rounded up to tile size */ + w_tile = align(width, TILE_SIZE); + h_tile = align(height, TILE_SIZE); + + ct->stride[level] = util_format_get_stride(pt->format, w_tile); + + ct->level_offset[level] = ct->buffer_size; + + size = ct->stride[level] * util_format_get_nblocksy(pt->format, h_tile); + if (pt->target == PIPE_TEXTURE_CUBE) + size *= 6; + else + size *= depth; + + ct->buffer_size += size; + + width = u_minify(width, 1); + height = u_minify(height, 1); + depth = u_minify(depth, 1); + } + + ct->data = align_malloc(ct->buffer_size, 16); + + return ct->data != NULL; +} + + +/** + * Texture layout for simple color buffers. + */ +static boolean +cell_displaytarget_layout(struct pipe_screen *screen, + struct cell_resource * ct) +{ + struct sw_winsys *winsys = cell_screen(screen)->winsys; + + /* Round up the surface size to a multiple of the tile size? + */ + ct->dt = winsys->displaytarget_create(winsys, + ct->base.bind, + ct->base.format, + ct->base.width0, + ct->base.height0, + 16, + &ct->dt_stride ); + + return ct->dt != NULL; +} + +static struct pipe_resource * +cell_resource_create(struct pipe_screen *screen, + const struct pipe_resource *templat) +{ + struct cell_resource *ct = CALLOC_STRUCT(cell_resource); + if (!ct) + return NULL; + + ct->base = *templat; + pipe_reference_init(&ct->base.reference, 1); + ct->base.screen = screen; + + /* Create both a displaytarget (linear) and regular texture + * (twiddled). Convert twiddled->linear at flush_frontbuffer time. + */ + if (ct->base.bind & (PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SCANOUT | + PIPE_BIND_SHARED)) { + if (!cell_displaytarget_layout(screen, ct)) + goto fail; + } + + if (!cell_resource_layout(screen, ct)) + goto fail; + + return &ct->base; + +fail: + if (ct->dt) { + struct sw_winsys *winsys = cell_screen(screen)->winsys; + winsys->displaytarget_destroy(winsys, ct->dt); + } + + FREE(ct); + + return NULL; +} + + +static void +cell_resource_destroy(struct pipe_screen *scrn, struct pipe_resource *pt) +{ + struct cell_screen *screen = cell_screen(scrn); + struct sw_winsys *winsys = screen->winsys; + struct cell_resource *ct = cell_resource(pt); + + if (ct->dt) { + /* display target */ + winsys->displaytarget_destroy(winsys, ct->dt); + } + else if (!ct->userBuffer) { + align_free(ct->data); + } + + FREE(ct); +} + + + +/** + * Convert image from linear layout to tiled layout. 4-byte pixels. + */ +static void +twiddle_image_uint(uint w, uint h, uint tile_size, uint *dst, + uint src_stride, const uint *src) +{ + const uint tile_size2 = tile_size * tile_size; + const uint h_t = (h + tile_size - 1) / tile_size; + const uint w_t = (w + tile_size - 1) / tile_size; + + uint it, jt; /* tile counters */ + uint i, j; /* intra-tile counters */ + + src_stride /= 4; /* convert from bytes to pixels */ + + /* loop over dest tiles */ + for (it = 0; it < h_t; it++) { + for (jt = 0; jt < w_t; jt++) { + /* start of dest tile: */ + uint *tdst = dst + (it * w_t + jt) * tile_size2; + + /* compute size of this tile (may be smaller than tile_size) */ + /* XXX note: a compiler bug was found here. That's why the code + * looks as it does. + */ + uint tile_width = w - jt * tile_size; + tile_width = MIN2(tile_width, tile_size); + uint tile_height = h - it * tile_size; + tile_height = MIN2(tile_height, tile_size); + + /* loop over texels in the tile */ + for (i = 0; i < tile_height; i++) { + for (j = 0; j < tile_width; j++) { + const uint srci = it * tile_size + i; + const uint srcj = jt * tile_size + j; + ASSERT(srci < h); + ASSERT(srcj < w); + tdst[i * tile_size + j] = src[srci * src_stride + srcj]; + } + } + } + } +} + + +/** + * For Cell. Basically, rearrange the pixels/quads from this layout: + * +--+--+--+--+ + * |p0|p1|p2|p3|.... + * +--+--+--+--+ + * + * to this layout: + * +--+--+ + * |p0|p1|.... + * +--+--+ + * |p2|p3| + * +--+--+ + */ +static void +twiddle_tile(const uint *tileIn, uint *tileOut) +{ + int y, x; + + for (y = 0; y < TILE_SIZE; y+=2) { + for (x = 0; x < TILE_SIZE; x+=2) { + int k = 4 * (y/2 * TILE_SIZE/2 + x/2); + tileOut[y * TILE_SIZE + (x + 0)] = tileIn[k]; + tileOut[y * TILE_SIZE + (x + 1)] = tileIn[k+1]; + tileOut[(y + 1) * TILE_SIZE + (x + 0)] = tileIn[k+2]; + tileOut[(y + 1) * TILE_SIZE + (x + 1)] = tileIn[k+3]; + } + } +} + + +/** + * Convert image from tiled layout to linear layout. 4-byte pixels. + */ +static void +untwiddle_image_uint(uint w, uint h, uint tile_size, uint *dst, + uint dst_stride, const uint *src) +{ + const uint tile_size2 = tile_size * tile_size; + const uint h_t = (h + tile_size - 1) / tile_size; + const uint w_t = (w + tile_size - 1) / tile_size; + uint *tile_buf; + uint it, jt; /* tile counters */ + uint i, j; /* intra-tile counters */ + + dst_stride /= 4; /* convert from bytes to pixels */ + + tile_buf = align_malloc(tile_size * tile_size * 4, 16); + + /* loop over src tiles */ + for (it = 0; it < h_t; it++) { + for (jt = 0; jt < w_t; jt++) { + /* start of src tile: */ + const uint *tsrc = src + (it * w_t + jt) * tile_size2; + + twiddle_tile(tsrc, tile_buf); + tsrc = tile_buf; + + /* compute size of this tile (may be smaller than tile_size) */ + /* XXX note: a compiler bug was found here. That's why the code + * looks as it does. + */ + uint tile_width = w - jt * tile_size; + tile_width = MIN2(tile_width, tile_size); + uint tile_height = h - it * tile_size; + tile_height = MIN2(tile_height, tile_size); + + /* loop over texels in the tile */ + for (i = 0; i < tile_height; i++) { + for (j = 0; j < tile_width; j++) { + uint dsti = it * tile_size + i; + uint dstj = jt * tile_size + j; + ASSERT(dsti < h); + ASSERT(dstj < w); + dst[dsti * dst_stride + dstj] = tsrc[i * tile_size + j]; + } + } + } + } + + align_free(tile_buf); +} + + +static struct pipe_surface * +cell_create_surface(struct pipe_context *ctx, + struct pipe_resource *pt, + const struct pipe_surface *surf_tmpl) +{ + struct cell_resource *ct = cell_resource(pt); + struct pipe_surface *ps; + + assert(surf_tmpl->u.tex.first_layer == surf_tmpl->u.tex.last_layer); + ps = CALLOC_STRUCT(pipe_surface); + if (ps) { + pipe_reference_init(&ps->reference, 1); + pipe_resource_reference(&ps->texture, pt); + ps->format = surf_tmpl->format; + ps->context = ctx; + ps->width = u_minify(pt->width0, surf_tmpl->u.tex.level); + ps->height = u_minify(pt->height0, surf_tmpl->u.tex.level); + /* XXX may need to override usage flags (see sp_texture.c) */ + ps->usage = surf_tmpl->usage; + ps->u.tex.level = surf_tmpl->u.tex.level; + ps->u.tex.first_layer = surf_tmpl->u.tex.first_layer; + ps->u.tex.last_layer = surf_tmpl->u.tex.last_layer; + } + return ps; +} + + +static void +cell_surface_destroy(struct pipe_context *ctx, struct pipe_surface *surf) +{ + pipe_resource_reference(&surf->texture, NULL); + FREE(surf); +} + + +/** + * Create new pipe_transfer object. + * This is used by the user to put tex data into a texture (and get it + * back out for glGetTexImage). + */ +static struct pipe_transfer * +cell_get_transfer(struct pipe_context *ctx, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct cell_resource *ct = cell_resource(resource); + struct cell_transfer *ctrans; + enum pipe_format format = resource->format; + + assert(resource); + assert(level <= resource->last_level); + + /* make sure the requested region is in the image bounds */ + assert(box->x + box->width <= u_minify(resource->width0, level)); + assert(box->y + box->height <= u_minify(resource->height0, level)); + assert(box->z + box->depth <= (u_minify(resource->depth0, level) + resource->array_size - 1)); + + ctrans = CALLOC_STRUCT(cell_transfer); + if (ctrans) { + struct pipe_transfer *pt = &ctrans->base; + pipe_resource_reference(&pt->resource, resource); + pt->level = level; + pt->usage = usage; + pt->box = *box; + pt->stride = ct->stride[level]; + + ctrans->offset = ct->level_offset[level]; + + if (resource->target == PIPE_TEXTURE_CUBE || resource->target == PIPE_TEXTURE_3D) { + unsigned h_tile = align(u_minify(resource->height0, level), TILE_SIZE); + ctrans->offset += box->z * util_format_get_nblocksy(format, h_tile) * pt->stride; + } + else { + assert(box->z == 0); + } + + return pt; + } + return NULL; +} + + +static void +cell_transfer_destroy(struct pipe_context *ctx, struct pipe_transfer *t) +{ + struct cell_transfer *transfer = cell_transfer(t); + /* Effectively do the texture_update work here - if texture images + * needed post-processing to put them into hardware layout, this is + * where it would happen. For cell, nothing to do. + */ + assert (transfer->base.resource); + pipe_resource_reference(&transfer->base.resource, NULL); + FREE(transfer); +} + + +/** + * Return pointer to texture image data in linear layout. + */ +static void * +cell_transfer_map(struct pipe_context *ctx, struct pipe_transfer *transfer) +{ + struct cell_transfer *ctrans = cell_transfer(transfer); + struct pipe_resource *pt = transfer->resource; + struct cell_resource *ct = cell_resource(pt); + + assert(transfer->resource); + + if (ct->mapped == NULL) { + ct->mapped = ct->data; + } + + + /* Better test would be resource->is_linear + */ + if (transfer->resource->target != PIPE_BUFFER) { + const uint level = ctrans->base.level; + const uint texWidth = u_minify(pt->width0, level); + const uint texHeight = u_minify(pt->height0, level); + unsigned size; + + + /* + * Create a buffer of ordinary memory for the linear texture. + * This is the memory that the user will read/write. + */ + size = (util_format_get_stride(pt->format, align(texWidth, TILE_SIZE)) * + util_format_get_nblocksy(pt->format, align(texHeight, TILE_SIZE))); + + ctrans->map = align_malloc(size, 16); + if (!ctrans->map) + return NULL; /* out of memory */ + + if (transfer->usage & PIPE_TRANSFER_READ) { + /* Textures always stored twiddled, need to untwiddle the + * texture to make a linear version. + */ + const uint bpp = util_format_get_blocksize(ct->base.format); + if (bpp == 4) { + const uint *src = (uint *) (ct->mapped + ctrans->offset); + uint *dst = ctrans->map; + untwiddle_image_uint(texWidth, texHeight, TILE_SIZE, + dst, transfer->stride, src); + } + else { + // xxx fix + } + } + } + else { + unsigned stride = transfer->stride; + enum pipe_format format = pt->format; + unsigned blocksize = util_format_get_blocksize(format); + + ctrans->map = (ct->mapped + + ctrans->offset + + ctrans->base.box.y / util_format_get_blockheight(format) * stride + + ctrans->base.box.x / util_format_get_blockwidth(format) * blocksize); + } + + + return ctrans->map; +} + + +/** + * Called when user is done reading/writing texture data. + * If new data was written, this is where we convert the linear data + * to tiled data. + */ +static void +cell_transfer_unmap(struct pipe_context *ctx, + struct pipe_transfer *transfer) +{ + struct cell_transfer *ctrans = cell_transfer(transfer); + struct pipe_resource *pt = transfer->resource; + struct cell_resource *ct = cell_resource(pt); + const uint level = ctrans->base.level; + const uint texWidth = u_minify(pt->width0, level); + const uint texHeight = u_minify(pt->height0, level); + const uint stride = ct->stride[level]; + + if (!ct->mapped) { + assert(0); + return; + } + + if (pt->target != PIPE_BUFFER) { + if (transfer->usage & PIPE_TRANSFER_WRITE) { + /* The user wrote new texture data into the mapped buffer. + * We need to convert the new linear data into the twiddled/tiled format. + */ + const uint bpp = util_format_get_blocksize(ct->base.format); + if (bpp == 4) { + const uint *src = ctrans->map; + uint *dst = (uint *) (ct->mapped + ctrans->offset); + twiddle_image_uint(texWidth, texHeight, TILE_SIZE, dst, stride, src); + } + else { + // xxx fix + } + } + + align_free(ctrans->map); + } + else { + /* nothing to do */ + } + + ctrans->map = NULL; +} + + + +/* This used to be overriden by the co-state tracker, but really needs + * to be active with sw_winsys. + * + * Contrasting with llvmpipe and softpipe, this is the only place + * where we use the ct->dt display target in any real sense. + * + * Basically just untwiddle our local data into the linear + * displaytarget. + */ +static void +cell_flush_frontbuffer(struct pipe_screen *_screen, + struct pipe_resource *resource, + unsigned level, unsigned layer, + void *context_private) +{ + struct cell_screen *screen = cell_screen(_screen); + struct sw_winsys *winsys = screen->winsys; + struct cell_resource *ct = cell_resource(resource); + + if (!ct->dt) + return; + + /* Need to untwiddle from our internal representation here: + */ + { + unsigned *map = winsys->displaytarget_map(winsys, ct->dt, + (PIPE_TRANSFER_READ | + PIPE_TRANSFER_WRITE)); + unsigned *src = (unsigned *)(ct->data + ct->level_offset[level]); + + untwiddle_image_uint(u_minify(resource->width0, level), + u_minify(resource->height0, level), + TILE_SIZE, + map, + ct->dt_stride, + src); + + winsys->displaytarget_unmap(winsys, ct->dt); + } + + winsys->displaytarget_display(winsys, ct->dt, context_private); +} + + + +/** + * Create buffer which wraps user-space data. + */ +static struct pipe_resource * +cell_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned bind_flags) +{ + struct cell_resource *buffer; + + buffer = CALLOC_STRUCT(cell_resource); + if(!buffer) + return NULL; + + pipe_reference_init(&buffer->base.reference, 1); + buffer->base.screen = screen; + buffer->base.format = PIPE_FORMAT_R8_UNORM; /* ?? */ + buffer->base.bind = PIPE_BIND_TRANSFER_READ | bind_flags; + buffer->base.usage = PIPE_USAGE_IMMUTABLE; + buffer->base.flags = 0; + buffer->base.width0 = bytes; + buffer->base.height0 = 1; + buffer->base.depth0 = 1; + buffer->base.array_size = 1; + buffer->userBuffer = TRUE; + buffer->data = ptr; + + return &buffer->base; +} + + +static struct pipe_resource * +cell_resource_from_handle(struct pipe_screen *screen, + const struct pipe_resource *templat, + struct winsys_handle *handle) +{ + /* XXX todo */ + return NULL; +} + + +static boolean +cell_resource_get_handle(struct pipe_screen *scree, + struct pipe_resource *tex, + struct winsys_handle *handle) +{ + /* XXX todo */ + return FALSE; +} + + +void +cell_init_screen_texture_funcs(struct pipe_screen *screen) +{ + screen->resource_create = cell_resource_create; + screen->resource_destroy = cell_resource_destroy; + screen->resource_from_handle = cell_resource_from_handle; + screen->resource_get_handle = cell_resource_get_handle; + screen->user_buffer_create = cell_user_buffer_create; + + screen->flush_frontbuffer = cell_flush_frontbuffer; +} + +void +cell_init_texture_transfer_funcs(struct cell_context *cell) +{ + cell->pipe.get_transfer = cell_get_transfer; + cell->pipe.transfer_destroy = cell_transfer_destroy; + cell->pipe.transfer_map = cell_transfer_map; + cell->pipe.transfer_unmap = cell_transfer_unmap; + + cell->pipe.transfer_flush_region = u_default_transfer_flush_region; + cell->pipe.transfer_inline_write = u_default_transfer_inline_write; + + cell->pipe.create_surface = cell_create_surface; + cell->pipe.surface_destroy = cell_surface_destroy; +} diff --git a/src/gallium/drivers/cell/ppu/cell_texture.h b/src/gallium/drivers/cell/ppu/cell_texture.h new file mode 100644 index 0000000..bd8224b --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_texture.h @@ -0,0 +1,102 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef CELL_TEXTURE_H +#define CELL_TEXTURE_H + +#include "cell/common.h" + +struct cell_context; +struct pipe_resource; + + +/** + * Subclass of pipe_resource + */ +struct cell_resource +{ + struct pipe_resource base; + + unsigned long level_offset[CELL_MAX_TEXTURE_LEVELS]; + unsigned long stride[CELL_MAX_TEXTURE_LEVELS]; + + /** + * Display target, for textures with the PIPE_BIND_DISPLAY_TARGET + * usage. + */ + struct sw_displaytarget *dt; + unsigned dt_stride; + + /** + * Malloc'ed data for regular textures, or a mapping to dt above. + */ + void *data; + boolean userBuffer; + + /* Size of the linear buffer?? + */ + unsigned long buffer_size; + + /** The buffer above, mapped. This is the memory from which the + * SPUs will fetch texels. This texture data is in the tiled layout. + */ + ubyte *mapped; +}; + + +struct cell_transfer +{ + struct pipe_transfer base; + + unsigned long offset; + void *map; +}; + + +/** cast wrapper */ +static INLINE struct cell_resource * +cell_resource(struct pipe_resource *pt) +{ + return (struct cell_resource *) pt; +} + + +/** cast wrapper */ +static INLINE struct cell_transfer * +cell_transfer(struct pipe_transfer *pt) +{ + return (struct cell_transfer *) pt; +} + + +extern void +cell_init_screen_texture_funcs(struct pipe_screen *screen); + +extern void +cell_init_texture_transfer_funcs(struct cell_context *cell); + +#endif /* CELL_TEXTURE_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_vbuf.c b/src/gallium/drivers/cell/ppu/cell_vbuf.c new file mode 100644 index 0000000..37b7195 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_vbuf.c @@ -0,0 +1,332 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Vertex buffer code. The draw module transforms vertices to window + * coords, etc. and emits the vertices into buffer supplied by this module. + * When a vertex buffer is full, or we flush, we'll send the vertex data + * to the SPUs. + * + * Authors + * Brian Paul + */ + + +#include "cell_batch.h" +#include "cell_context.h" +#include "cell_fence.h" +#include "cell_flush.h" +#include "cell_spu.h" +#include "cell_vbuf.h" +#include "draw/draw_vbuf.h" +#include "util/u_memory.h" + + +/** Allow vertex data to be inlined after RENDER command */ +#define ALLOW_INLINE_VERTS 1 + + +/** + * Subclass of vbuf_render because we need a cell_context pointer in + * a few places. + */ +struct cell_vbuf_render +{ + struct vbuf_render base; + struct cell_context *cell; + uint prim; /**< PIPE_PRIM_x */ + uint vertex_size; /**< in bytes */ + void *vertex_buffer; /**< just for debug, really */ + uint vertex_buf; /**< in [0, CELL_NUM_BUFFERS-1] */ + uint vertex_buffer_size; /**< size in bytes */ +}; + + +/** cast wrapper */ +static struct cell_vbuf_render * +cell_vbuf_render(struct vbuf_render *vbr) +{ + return (struct cell_vbuf_render *) vbr; +} + + + +static const struct vertex_info * +cell_vbuf_get_vertex_info(struct vbuf_render *vbr) +{ + struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr); + return &cvbr->cell->vertex_info; +} + + +static boolean +cell_vbuf_allocate_vertices(struct vbuf_render *vbr, + ushort vertex_size, ushort nr_vertices) +{ + struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr); + unsigned size = vertex_size * nr_vertices; + /*printf("Alloc verts %u * %u\n", vertex_size, nr_vertices);*/ + + assert(cvbr->vertex_buf == ~0); + cvbr->vertex_buf = cell_get_empty_buffer(cvbr->cell); + cvbr->vertex_buffer = cvbr->cell->buffer[cvbr->vertex_buf]; + cvbr->vertex_buffer_size = size; + cvbr->vertex_size = vertex_size; + + return cvbr->vertex_buffer != NULL; +} + + +static void +cell_vbuf_release_vertices(struct vbuf_render *vbr) +{ + struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr); + struct cell_context *cell = cvbr->cell; + + /* + printf("%s vertex_buf = %u count = %u\n", + __FUNCTION__, cvbr->vertex_buf, vertices_used); + */ + + /* Make sure texture buffers aren't released until we're done rendering + * with them. + */ + cell_add_fenced_textures(cell); + + /* Tell SPUs they can release the vert buf */ + if (cvbr->vertex_buf != ~0U) { + STATIC_ASSERT(sizeof(struct cell_command_release_verts) % 16 == 0); + struct cell_command_release_verts *release + = (struct cell_command_release_verts *) + cell_batch_alloc16(cell, sizeof(struct cell_command_release_verts)); + release->opcode[0] = CELL_CMD_RELEASE_VERTS; + release->vertex_buf = cvbr->vertex_buf; + } + + cvbr->vertex_buf = ~0; + cell_flush_int(cell, 0x0); + + cvbr->vertex_buffer = NULL; +} + + +static void * +cell_vbuf_map_vertices(struct vbuf_render *vbr) +{ + struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr); + return cvbr->vertex_buffer; +} + + +static void +cell_vbuf_unmap_vertices(struct vbuf_render *vbr, + ushort min_index, + ushort max_index ) +{ + struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr); + assert( cvbr->vertex_buffer_size >= (max_index+1) * cvbr->vertex_size ); + /* do nothing */ +} + + + +static boolean +cell_vbuf_set_primitive(struct vbuf_render *vbr, unsigned prim) +{ + struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr); + cvbr->prim = prim; + /*printf("cell_set_prim %u\n", prim);*/ + return TRUE; +} + + +static void +cell_vbuf_draw_elements(struct vbuf_render *vbr, + const ushort *indices, + uint nr_indices) +{ + struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr); + struct cell_context *cell = cvbr->cell; + float xmin, ymin, xmax, ymax; + uint i; + uint nr_vertices = 0, min_index = ~0; + const void *vertices = cvbr->vertex_buffer; + const uint vertex_size = cvbr->vertex_size; + + for (i = 0; i < nr_indices; i++) { + if (indices[i] > nr_vertices) + nr_vertices = indices[i]; + if (indices[i] < min_index) + min_index = indices[i]; + } + nr_vertices++; + +#if 0 + /*if (min_index > 0)*/ + printf("%s min_index = %u\n", __FUNCTION__, min_index); +#endif + +#if 0 + printf("cell_vbuf_draw() nr_indices = %u nr_verts = %u\n", + nr_indices, nr_vertices); + printf(" "); + for (i = 0; i < nr_indices; i += 3) { + printf("%u %u %u, ", indices[i+0], indices[i+1], indices[i+2]); + } + printf("\n"); +#elif 0 + printf("cell_vbuf_draw() nr_indices = %u nr_verts = %u indexes = [%u %u %u ...]\n", + nr_indices, nr_vertices, + indices[0], indices[1], indices[2]); + printf("ind space = %u, vert space = %u, space = %u\n", + nr_indices * 2, + nr_vertices * 4 * cell->vertex_info.size, + cell_batch_free_space(cell)); +#endif + + /* compute x/y bounding box */ + xmin = ymin = 1e50; + xmax = ymax = -1e50; + for (i = min_index; i < nr_vertices; i++) { + const float *v = (float *) ((ubyte *) vertices + i * vertex_size); + if (v[0] < xmin) + xmin = v[0]; + if (v[0] > xmax) + xmax = v[0]; + if (v[1] < ymin) + ymin = v[1]; + if (v[1] > ymax) + ymax = v[1]; + } +#if 0 + printf("PPU Bounds %g, %g .. %g, %g\n", xmin, ymin, xmax, ymax); + fflush(stdout); +#endif + + if (cvbr->prim != PIPE_PRIM_TRIANGLES) + return; /* only render tris for now */ + + /* build/insert batch RENDER command */ + { + const uint index_bytes = ROUNDUP16(nr_indices * 2); + const uint vertex_bytes = ROUNDUP16(nr_vertices * 4 * cell->vertex_info.size); + STATIC_ASSERT(sizeof(struct cell_command_render) % 16 == 0); + const uint batch_size = sizeof(struct cell_command_render) + index_bytes; + + struct cell_command_render *render + = (struct cell_command_render *) + cell_batch_alloc16(cell, batch_size); + + render->opcode[0] = CELL_CMD_RENDER; + render->prim_type = cvbr->prim; + + render->num_indexes = nr_indices; + render->min_index = min_index; + + /* append indices after render command */ + memcpy(render + 1, indices, nr_indices * 2); + + /* if there's room, append vertices after the indices, else leave + * vertices in the original/separate buffer. + */ + render->vertex_size = 4 * cell->vertex_info.size; + render->num_verts = nr_vertices; + if (ALLOW_INLINE_VERTS && + min_index == 0 && + vertex_bytes + 16 <= cell_batch_free_space(cell)) { + /* vertex data inlined, after indices, at 16-byte boundary */ + void *dst = cell_batch_alloc16(cell, vertex_bytes); + memcpy(dst, vertices, vertex_bytes); + render->inline_verts = TRUE; + render->vertex_buf = ~0; + } + else { + /* vertex data in separate buffer */ + render->inline_verts = FALSE; + ASSERT(cvbr->vertex_buf >= 0); + render->vertex_buf = cvbr->vertex_buf; + } + + render->xmin = xmin; + render->ymin = ymin; + render->xmax = xmax; + render->ymax = ymax; + } + +#if 0 + /* helpful for debug */ + cell_flush_int(cell, CELL_FLUSH_WAIT); +#endif +} + + +static void +cell_vbuf_destroy(struct vbuf_render *vbr) +{ + struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr); + cvbr->cell->vbuf_render = NULL; + FREE(cvbr); +} + + +/** + * Initialize the post-transform vertex buffer information for the given + * context. + */ +void +cell_init_vbuf(struct cell_context *cell) +{ + assert(cell->draw); + + cell->vbuf_render = CALLOC_STRUCT(cell_vbuf_render); + + /* The max number of indexes is what can fix into a batch buffer, + * minus the render and release-verts commands. + */ + cell->vbuf_render->base.max_indices + = (CELL_BUFFER_SIZE + - sizeof(struct cell_command_render) + - sizeof(struct cell_command_release_verts)) + / sizeof(ushort); + cell->vbuf_render->base.max_vertex_buffer_bytes = CELL_BUFFER_SIZE; + + cell->vbuf_render->base.get_vertex_info = cell_vbuf_get_vertex_info; + cell->vbuf_render->base.allocate_vertices = cell_vbuf_allocate_vertices; + cell->vbuf_render->base.map_vertices = cell_vbuf_map_vertices; + cell->vbuf_render->base.unmap_vertices = cell_vbuf_unmap_vertices; + cell->vbuf_render->base.set_primitive = cell_vbuf_set_primitive; + cell->vbuf_render->base.draw_elements = cell_vbuf_draw_elements; + cell->vbuf_render->base.release_vertices = cell_vbuf_release_vertices; + cell->vbuf_render->base.destroy = cell_vbuf_destroy; + + cell->vbuf_render->cell = cell; +#if 1 + cell->vbuf_render->vertex_buf = ~0; +#endif + + cell->vbuf = draw_vbuf_stage(cell->draw, &cell->vbuf_render->base); +} diff --git a/src/gallium/drivers/cell/ppu/cell_vbuf.h b/src/gallium/drivers/cell/ppu/cell_vbuf.h new file mode 100644 index 0000000..d265cbf --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_vbuf.h @@ -0,0 +1,38 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef CELL_VBUF_H +#define CELL_VBUF_H + + +struct cell_context; + +extern void +cell_init_vbuf(struct cell_context *cell); + + +#endif /* CELL_VBUF_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_vertex_fetch.c b/src/gallium/drivers/cell/ppu/cell_vertex_fetch.c new file mode 100644 index 0000000..9cba537 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_vertex_fetch.c @@ -0,0 +1,346 @@ +/* + * (C) Copyright IBM Corporation 2008 + * 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 + * 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 + * AUTHORS, COPYRIGHT HOLDERS, 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 +#include "pipe/p_defines.h" +#include "pipe/p_context.h" +#include "pipe/p_format.h" + +#include "../auxiliary/draw/draw_context.h" +#include "../auxiliary/draw/draw_private.h" + +#include "cell_context.h" +#include "rtasm/rtasm_ppc_spe.h" + + +/** + * Emit a 4x4 matrix transpose operation + * + * \param p Function that the transpose operation is to be appended to + * \param row0 Register containing row 0 of the source matrix + * \param row1 Register containing row 1 of the source matrix + * \param row2 Register containing row 2 of the source matrix + * \param row3 Register containing row 3 of the source matrix + * \param dest_ptr Register containing the address of the destination matrix + * \param shuf_ptr Register containing the address of the shuffled data + * \param count Number of colums to actually be written to the destination + * + * \note + * This function assumes that the registers named by \c row0, \c row1, + * \c row2, and \c row3 are scratch and can be modified by the generated code. + * Furthermore, these registers will be released, via calls to + * \c release_register, by this function. + * + * \note + * This function requires that four temporary are available on entry. + */ +static void +emit_matrix_transpose(struct spe_function *p, + unsigned row0, unsigned row1, unsigned row2, + unsigned row3, unsigned dest_ptr, + unsigned shuf_ptr, unsigned count) +{ + int shuf_hi = spe_allocate_available_register(p); + int shuf_lo = spe_allocate_available_register(p); + int t1 = spe_allocate_available_register(p); + int t2 = spe_allocate_available_register(p); + int t3; + int t4; + int col0; + int col1; + int col2; + int col3; + + + spe_lqd(p, shuf_hi, shuf_ptr, 3*16); + spe_lqd(p, shuf_lo, shuf_ptr, 4*16); + spe_shufb(p, t1, row0, row2, shuf_hi); + spe_shufb(p, t2, row0, row2, shuf_lo); + + + /* row0 and row2 are now no longer needed. Re-use those registers as + * temporaries. + */ + t3 = row0; + t4 = row2; + + spe_shufb(p, t3, row1, row3, shuf_hi); + spe_shufb(p, t4, row1, row3, shuf_lo); + + + /* row1 and row3 are now no longer needed. Re-use those registers as + * temporaries. + */ + col0 = row1; + col1 = row3; + + spe_shufb(p, col0, t1, t3, shuf_hi); + if (count > 1) { + spe_shufb(p, col1, t1, t3, shuf_lo); + } + + /* t1 and t3 are now no longer needed. Re-use those registers as + * temporaries. + */ + col2 = t1; + col3 = t3; + + if (count > 2) { + spe_shufb(p, col2, t2, t4, shuf_hi); + } + + if (count > 3) { + spe_shufb(p, col3, t2, t4, shuf_lo); + } + + + /* Store the results. Remember that the stqd instruction is encoded using + * the qword offset (stand-alone assemblers to the byte-offset to + * qword-offset conversion for you), so the byte-offset needs be divided by + * 16. + */ + switch (count) { + case 4: + spe_stqd(p, col3, dest_ptr, 3 * 16); + case 3: + spe_stqd(p, col2, dest_ptr, 2 * 16); + case 2: + spe_stqd(p, col1, dest_ptr, 1 * 16); + case 1: + spe_stqd(p, col0, dest_ptr, 0 * 16); + } + + + /* Release all of the temporary registers used. + */ + spe_release_register(p, col0); + spe_release_register(p, col1); + spe_release_register(p, col2); + spe_release_register(p, col3); + spe_release_register(p, shuf_hi); + spe_release_register(p, shuf_lo); + spe_release_register(p, t2); + spe_release_register(p, t4); +} + + +#if 0 +/* This appears to not be used currently */ +static void +emit_fetch(struct spe_function *p, + unsigned in_ptr, unsigned *offset, + unsigned out_ptr, unsigned shuf_ptr, + enum pipe_format format) +{ + const unsigned count = (pf_size_x(format) != 0) + (pf_size_y(format) != 0) + + (pf_size_z(format) != 0) + (pf_size_w(format) != 0); + const unsigned type = pf_type(format); + const unsigned bytes = pf_size_x(format); + + int v0 = spe_allocate_available_register(p); + int v1 = spe_allocate_available_register(p); + int v2 = spe_allocate_available_register(p); + int v3 = spe_allocate_available_register(p); + int tmp = spe_allocate_available_register(p); + int float_zero = -1; + int float_one = -1; + float scale_signed = 0.0; + float scale_unsigned = 0.0; + + spe_lqd(p, v0, in_ptr, (0 + offset[0]) * 16); + spe_lqd(p, v1, in_ptr, (1 + offset[0]) * 16); + spe_lqd(p, v2, in_ptr, (2 + offset[0]) * 16); + spe_lqd(p, v3, in_ptr, (3 + offset[0]) * 16); + offset[0] += 4; + + switch (bytes) { + case 1: + scale_signed = 1.0f / 127.0f; + scale_unsigned = 1.0f / 255.0f; + spe_lqd(p, tmp, shuf_ptr, 1 * 16); + spe_shufb(p, v0, v0, v0, tmp); + spe_shufb(p, v1, v1, v1, tmp); + spe_shufb(p, v2, v2, v2, tmp); + spe_shufb(p, v3, v3, v3, tmp); + break; + case 2: + scale_signed = 1.0f / 32767.0f; + scale_unsigned = 1.0f / 65535.0f; + spe_lqd(p, tmp, shuf_ptr, 2 * 16); + spe_shufb(p, v0, v0, v0, tmp); + spe_shufb(p, v1, v1, v1, tmp); + spe_shufb(p, v2, v2, v2, tmp); + spe_shufb(p, v3, v3, v3, tmp); + break; + case 4: + scale_signed = 1.0f / 2147483647.0f; + scale_unsigned = 1.0f / 4294967295.0f; + break; + default: + assert(0); + break; + } + + switch (type) { + case PIPE_FORMAT_TYPE_FLOAT: + break; + case PIPE_FORMAT_TYPE_UNORM: + spe_ilhu(p, tmp, ((unsigned) scale_unsigned) >> 16); + spe_iohl(p, tmp, ((unsigned) scale_unsigned) & 0x0ffff); + spe_cuflt(p, v0, v0, 0); + spe_fm(p, v0, v0, tmp); + break; + case PIPE_FORMAT_TYPE_SNORM: + spe_ilhu(p, tmp, ((unsigned) scale_signed) >> 16); + spe_iohl(p, tmp, ((unsigned) scale_signed) & 0x0ffff); + spe_csflt(p, v0, v0, 0); + spe_fm(p, v0, v0, tmp); + break; + case PIPE_FORMAT_TYPE_USCALED: + spe_cuflt(p, v0, v0, 0); + break; + case PIPE_FORMAT_TYPE_SSCALED: + spe_csflt(p, v0, v0, 0); + break; + } + + + if (count < 4) { + float_one = spe_allocate_available_register(p); + spe_il(p, float_one, 1); + spe_cuflt(p, float_one, float_one, 0); + + if (count < 3) { + float_zero = spe_allocate_available_register(p); + spe_il(p, float_zero, 0); + } + } + + spe_release_register(p, tmp); + + emit_matrix_transpose(p, v0, v1, v2, v3, out_ptr, shuf_ptr, count); + + switch (count) { + case 1: + spe_stqd(p, float_zero, out_ptr, 1 * 16); + case 2: + spe_stqd(p, float_zero, out_ptr, 2 * 16); + case 3: + spe_stqd(p, float_one, out_ptr, 3 * 16); + } + + if (float_zero != -1) { + spe_release_register(p, float_zero); + } + + if (float_one != -1) { + spe_release_register(p, float_one); + } +} +#endif + + +void cell_update_vertex_fetch(struct draw_context *draw) +{ +#if 0 + struct cell_context *const cell = + (struct cell_context *) draw->driver_private; + struct spe_function *p = &cell->attrib_fetch; + unsigned function_index[PIPE_MAX_ATTRIBS]; + unsigned unique_attr_formats; + int out_ptr; + int in_ptr; + int shuf_ptr; + unsigned i; + unsigned j; + + + /* Determine how many unique input attribute formats there are. At the + * same time, store the index of the lowest numbered attribute that has + * the same format as any non-unique format. + */ + unique_attr_formats = 1; + function_index[0] = 0; + for (i = 1; i < draw->vertex_fetch.nr_attrs; i++) { + const enum pipe_format curr_fmt = draw->vertex_element[i].src_format; + + for (j = 0; j < i; j++) { + if (curr_fmt == draw->vertex_element[j].src_format) { + break; + } + } + + if (j == i) { + unique_attr_formats++; + } + + function_index[i] = j; + } + + + /* Each fetch function can be a maximum of 34 instructions (note: this is + * actually a slight over-estimate). + */ + spe_init_func(p, 34 * SPE_INST_SIZE * unique_attr_formats); + + + /* Allocate registers for the function's input parameters. + */ + out_ptr = spe_allocate_register(p, 3); + in_ptr = spe_allocate_register(p, 4); + shuf_ptr = spe_allocate_register(p, 5); + + + /* Generate code for the individual attribute fetch functions. + */ + for (i = 0; i < draw->vertex_fetch.nr_attrs; i++) { + unsigned offset; + + if (function_index[i] == i) { + cell->attrib_fetch_offsets[i] = (unsigned) ((void *) p->csr + - (void *) p->store); + + offset = 0; + emit_fetch(p, in_ptr, &offset, out_ptr, shuf_ptr, + draw->vertex_element[i].src_format); + spe_bi(p, 0, 0, 0); + + /* Round up to the next 16-byte boundary. + */ + if ((((unsigned) p->store) & 0x0f) != 0) { + const unsigned align = ((unsigned) p->store) & 0x0f; + p->store = (uint32_t *) (((void *) p->store) + align); + } + } else { + /* Use the same function entry-point as a previously seen attribute + * with the same format. + */ + cell->attrib_fetch_offsets[i] = + cell->attrib_fetch_offsets[function_index[i]]; + } + } +#else + assert(0); +#endif +} diff --git a/src/gallium/drivers/cell/ppu/cell_vertex_shader.c b/src/gallium/drivers/cell/ppu/cell_vertex_shader.c new file mode 100644 index 0000000..3d389d6 --- /dev/null +++ b/src/gallium/drivers/cell/ppu/cell_vertex_shader.c @@ -0,0 +1,145 @@ +/* + * (C) Copyright IBM Corporation 2008 + * 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 + * 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 + * AUTHORS, COPYRIGHT HOLDERS, 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. + */ + +/** + * \file cell_vertex_shader.c + * Vertex shader interface routines for Cell. + * + * \author Ian Romanick + */ + +#include "pipe/p_defines.h" +#include "pipe/p_context.h" +#include "util/u_math.h" + +#include "cell_context.h" +#include "cell_draw_arrays.h" +#include "cell_flush.h" +#include "cell_spu.h" +#include "cell_batch.h" + +#include "cell/common.h" +#include "draw/draw_context.h" +#include "draw/draw_private.h" + +/** + * Run the vertex shader on all vertices in the vertex queue. + * Called by the draw module when the vertx cache needs to be flushed. + */ +void +cell_vertex_shader_queue_flush(struct draw_context *draw) +{ +#if 0 + struct cell_context *const cell = + (struct cell_context *) draw->driver_private; + struct cell_command_vs *const vs = &cell_global.command[0].vs; + uint64_t *batch; + struct cell_array_info *array_info; + unsigned i, j; + struct cell_attribute_fetch_code *cf; + + assert(draw->vs.queue_nr != 0); + + /* XXX: do this on statechange: + */ + draw_update_vertex_fetch(draw); + cell_update_vertex_fetch(draw); + + + batch = cell_batch_alloc(cell, sizeof(batch[0]) + sizeof(*cf)); + batch[0] = CELL_CMD_STATE_ATTRIB_FETCH; + cf = (struct cell_attribute_fetch_code *) (&batch[1]); + cf->base = (uint64_t) cell->attrib_fetch.store; + cf->size = ROUNDUP16((unsigned)((void *) cell->attrib_fetch.csr + - (void *) cell->attrib_fetch.store)); + + + for (i = 0; i < draw->vertex_fetch.nr_attrs; i++) { + const enum pipe_format format = draw->vertex_element[i].src_format; + const unsigned count = ((pf_size_x(format) != 0) + + (pf_size_y(format) != 0) + + (pf_size_z(format) != 0) + + (pf_size_w(format) != 0)); + const unsigned size = pf_size_x(format) * count; + + batch = cell_batch_alloc(cell, sizeof(batch[0]) + sizeof(*array_info)); + + batch[0] = CELL_CMD_STATE_VS_ARRAY_INFO; + + array_info = (struct cell_array_info *) &batch[1]; + assert(draw->vertex_fetch.src_ptr[i] != NULL); + array_info->base = (uintptr_t) draw->vertex_fetch.src_ptr[i]; + array_info->attr = i; + array_info->pitch = draw->vertex_fetch.pitch[i]; + array_info->size = size; + array_info->function_offset = cell->attrib_fetch_offsets[i]; + } + + batch = cell_batch_alloc(cell, sizeof(batch[0]) + + sizeof(struct pipe_viewport_state)); + batch[0] = CELL_CMD_STATE_VIEWPORT; + (void) memcpy(&batch[1], &draw->viewport, + sizeof(struct pipe_viewport_state)); + + { + uint64_t uniforms = (uintptr_t) draw->user.constants; + + batch = cell_batch_alloc(cell, 2 *sizeof(batch[0])); + batch[0] = CELL_CMD_STATE_UNIFORMS; + batch[1] = uniforms; + } + + cell_batch_flush(cell); + + vs->opcode = CELL_CMD_VS_EXECUTE; + vs->nr_attrs = draw->vertex_fetch.nr_attrs; + + (void) memcpy(vs->plane, draw->plane, sizeof(draw->plane)); + vs->nr_planes = draw->nr_planes; + + for (i = 0; i < draw->vs.queue_nr; i += SPU_VERTS_PER_BATCH) { + const unsigned n = MIN2(SPU_VERTS_PER_BATCH, draw->vs.queue_nr - i); + + for (j = 0; j < n; j++) { + vs->elts[j] = draw->vs.queue[i + j].elt; + vs->vOut[j] = (uintptr_t) draw->vs.queue[i + j].vertex; + } + + for (/* empty */; j < SPU_VERTS_PER_BATCH; j++) { + vs->elts[j] = vs->elts[0]; + vs->vOut[j] = (uintptr_t) draw->vs.queue[i + j].vertex; + } + + vs->num_elts = n; + send_mbox_message(cell_global.spe_contexts[0], CELL_CMD_VS_EXECUTE); + + cell_flush_int(cell, CELL_FLUSH_WAIT); + } + + draw->vs.post_nr = draw->vs.queue_nr; + draw->vs.queue_nr = 0; +#else + assert(0); +#endif +} diff --git a/src/gallium/drivers/cell/spu/Makefile b/src/gallium/drivers/cell/spu/Makefile new file mode 100644 index 0000000..3cc5230 --- /dev/null +++ b/src/gallium/drivers/cell/spu/Makefile @@ -0,0 +1,83 @@ +# Gallium3D Cell driver: SPU code + +# This makefile builds the g3d_spu.a file that's linked into the +# PPU code/library. + + +TOP = ../../../../.. +include $(TOP)/configs/current + + +PROG = g3d + +PROG_SPU = $(PROG)_spu +PROG_SPU_A = $(PROG)_spu.a +PROG_SPU_EMBED_O = $(PROG)_spu-embed.o + + +SOURCES = \ + spu_command.c \ + spu_dcache.c \ + spu_funcs.c \ + spu_main.c \ + spu_per_fragment_op.c \ + spu_render.c \ + spu_texture.c \ + spu_tile.c \ + spu_tri.c + +OLD_SOURCES = \ + spu_exec.c \ + spu_util.c \ + spu_vertex_fetch.c \ + spu_vertex_shader.c + + +SPU_OBJECTS = $(SOURCES:.c=.o) + +SPU_ASM_OUT = $(SOURCES:.c=.s) + + +INCLUDE_DIRS = \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers + + +.c.o: + $(SPU_CC) $(SPU_CFLAGS) -c $< + +.c.s: + $(SPU_CC) $(SPU_CFLAGS) -O3 -S $< + + +# The .a file will be linked into the main/PPU executable +default: $(PROG_SPU_A) + +$(PROG_SPU_A): $(PROG_SPU_EMBED_O) + $(SPU_AR) $(SPU_AR_FLAGS) $(PROG_SPU_A) $(PROG_SPU_EMBED_O) + +$(PROG_SPU_EMBED_O): $(PROG_SPU) + $(SPU_EMBED) $(SPU_EMBED_FLAGS) $(PROG_SPU) $(PROG_SPU) $(PROG_SPU_EMBED_O) + +$(PROG_SPU): $(SPU_OBJECTS) + $(SPU_CC) -o $(PROG_SPU) $(SPU_OBJECTS) $(SPU_LFLAGS) + + + +asmfiles: $(SPU_ASM_OUT) + + +clean: + rm -f *~ *.o *.a *.d *.s $(PROG_SPU) + + + +depend: $(SOURCES) + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDE_DIRS) $(SOURCES) 2> /dev/null + +include depend + diff --git a/src/gallium/drivers/cell/spu/spu_colorpack.h b/src/gallium/drivers/cell/spu/spu_colorpack.h new file mode 100644 index 0000000..d7ce005 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_colorpack.h @@ -0,0 +1,145 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + + +#ifndef SPU_COLORPACK_H +#define SPU_COLORPACK_H + + +#include +#include + + +static INLINE unsigned int +spu_pack_R8G8B8A8(vector float rgba) +{ + vector unsigned int out = spu_convtu(rgba, 32); + + out = spu_shuffle(out, out, ((vector unsigned char) { + 0, 4, 8, 12, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }) ); + + return spu_extract(out, 0); +} + + +static INLINE unsigned int +spu_pack_A8R8G8B8(vector float rgba) +{ + vector unsigned int out = spu_convtu(rgba, 32); + out = spu_shuffle(out, out, ((vector unsigned char) { + 12, 0, 4, 8, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0}) ); + return spu_extract(out, 0); +} + + +static INLINE unsigned int +spu_pack_B8G8R8A8(vector float rgba) +{ + vector unsigned int out = spu_convtu(rgba, 32); + out = spu_shuffle(out, out, ((vector unsigned char) { + 8, 4, 0, 12, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0}) ); + return spu_extract(out, 0); +} + + +static INLINE unsigned int +spu_pack_color_shuffle(vector float rgba, vector unsigned char shuffle) +{ + vector unsigned int out = spu_convtu(rgba, 32); + out = spu_shuffle(out, out, shuffle); + return spu_extract(out, 0); +} + + +static INLINE vector float +spu_unpack_B8G8R8A8(uint color) +{ + vector unsigned int color_u4 = spu_splats(color); + color_u4 = spu_shuffle(color_u4, color_u4, + ((vector unsigned char) { + 2, 2, 2, 2, + 1, 1, 1, 1, + 0, 0, 0, 0, + 3, 3, 3, 3}) ); + return spu_convtf(color_u4, 32); +} + + +static INLINE vector float +spu_unpack_A8R8G8B8(uint color) +{ + vector unsigned int color_u4 = spu_splats(color); + color_u4 = spu_shuffle(color_u4, color_u4, + ((vector unsigned char) { + 1, 1, 1, 1, + 2, 2, 2, 2, + 3, 3, 3, 3, + 0, 0, 0, 0}) ); + return spu_convtf(color_u4, 32); +} + + +/** + * \param color_in - array of 32-bit packed ARGB colors + * \param color_out - returns float colors in RRRR, GGGG, BBBB, AAAA order + */ +static INLINE void +spu_unpack_A8R8G8B8_transpose4(const vector unsigned int color_in[4], + vector float color_out[4]) +{ + vector unsigned int c0; + + c0 = spu_shuffle(color_in[0], color_in[0], + ((vector unsigned char) { + 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 0, 0, 0, 0}) ); + color_out[0] = spu_convtf(c0, 32); + + c0 = spu_shuffle(color_in[1], color_in[1], + ((vector unsigned char) { + 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 0, 0, 0, 0}) ); + color_out[1] = spu_convtf(c0, 32); + + c0 = spu_shuffle(color_in[2], color_in[2], + ((vector unsigned char) { + 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 0, 0, 0, 0}) ); + color_out[2] = spu_convtf(c0, 32); + + c0 = spu_shuffle(color_in[3], color_in[3], + ((vector unsigned char) { + 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 0, 0, 0, 0}) ); + color_out[3] = spu_convtf(c0, 32); + + _transpose_matrix4x4(color_out, color_out); +} + + + +#endif /* SPU_COLORPACK_H */ diff --git a/src/gallium/drivers/cell/spu/spu_command.c b/src/gallium/drivers/cell/spu/spu_command.c new file mode 100644 index 0000000..f16cabc --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_command.c @@ -0,0 +1,810 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * SPU command processing code + */ + + +#include +#include + +#include "pipe/p_defines.h" + +#include "spu_command.h" +#include "spu_main.h" +#include "spu_render.h" +#include "spu_per_fragment_op.h" +#include "spu_texture.h" +#include "spu_tile.h" +#include "spu_vertex_shader.h" +#include "spu_dcache.h" +#include "cell/common.h" + + +struct spu_vs_context draw; + + +/** + * Buffers containing dynamically generated SPU code: + */ +PIPE_ALIGN_VAR(16) static unsigned char attribute_fetch_code_buffer[136 * PIPE_MAX_ATTRIBS]; + + + +static INLINE int +align(int value, int alignment) +{ + return (value + alignment - 1) & ~(alignment - 1); +} + + + +/** + * Tell the PPU that this SPU has finished copying a buffer to + * local store and that it may be reused by the PPU. + * This is done by writting a 16-byte batch-buffer-status block back into + * main memory (in cell_context->buffer_status[]). + */ +static void +release_buffer(uint buffer) +{ + /* Evidently, using less than a 16-byte status doesn't work reliably */ + static const vector unsigned int status = {CELL_BUFFER_STATUS_FREE, + CELL_BUFFER_STATUS_FREE, + CELL_BUFFER_STATUS_FREE, + CELL_BUFFER_STATUS_FREE}; + const uint index = 4 * (spu.init.id * CELL_NUM_BUFFERS + buffer); + uint *dst = spu.init.buffer_status + index; + + ASSERT(buffer < CELL_NUM_BUFFERS); + + mfc_put((void *) &status, /* src in local memory */ + (unsigned int) dst, /* dst in main memory */ + sizeof(status), /* size */ + TAG_MISC, /* tag is unimportant */ + 0, /* tid */ + 0 /* rid */); +} + + +/** + * Write CELL_FENCE_SIGNALLED back to the fence status qword in main memory. + * There's a qword of status per SPU. + */ +static void +cmd_fence(struct cell_command_fence *fence_cmd) +{ + static const vector unsigned int status = {CELL_FENCE_SIGNALLED, + CELL_FENCE_SIGNALLED, + CELL_FENCE_SIGNALLED, + CELL_FENCE_SIGNALLED}; + uint *dst = (uint *) fence_cmd->fence; + dst += 4 * spu.init.id; /* main store/memory address, not local store */ + ASSERT_ALIGN16(dst); + mfc_put((void *) &status, /* src in local memory */ + (unsigned int) dst, /* dst in main memory */ + sizeof(status), /* size */ + TAG_FENCE, /* tag */ + 0, /* tid */ + 0 /* rid */); +} + + +static void +cmd_clear_surface(const struct cell_command_clear_surface *clear) +{ + D_PRINTF(CELL_DEBUG_CMD, "CLEAR SURF %u to 0x%08x\n", clear->surface, clear->value); + + if (clear->surface == 0) { + spu.fb.color_clear_value = clear->value; + if (spu.init.debug_flags & CELL_DEBUG_CHECKER) { + uint x = (spu.init.id << 4) | (spu.init.id << 12) | + (spu.init.id << 20) | (spu.init.id << 28); + spu.fb.color_clear_value ^= x; + } + } + else { + spu.fb.depth_clear_value = clear->value; + } + +#define CLEAR_OPT 1 +#if CLEAR_OPT + + /* Simply set all tiles' status to CLEAR. + * When we actually begin rendering into a tile, we'll initialize it to + * the clear value. If any tiles go untouched during the frame, + * really_clear_tiles() will set them to the clear value. + */ + if (clear->surface == 0) { + memset(spu.ctile_status, TILE_STATUS_CLEAR, sizeof(spu.ctile_status)); + } + else { + memset(spu.ztile_status, TILE_STATUS_CLEAR, sizeof(spu.ztile_status)); + } + +#else + + /* + * This path clears the whole framebuffer to the clear color right now. + */ + + /* + printf("SPU: %s num=%d w=%d h=%d\n", + __FUNCTION__, num_tiles, spu.fb.width_tiles, spu.fb.height_tiles); + */ + + /* init a single tile to the clear value */ + if (clear->surface == 0) { + clear_c_tile(&spu.ctile); + } + else { + clear_z_tile(&spu.ztile); + } + + /* walk over my tiles, writing the 'clear' tile's data */ + { + const uint num_tiles = spu.fb.width_tiles * spu.fb.height_tiles; + uint i; + for (i = spu.init.id; i < num_tiles; i += spu.init.num_spus) { + uint tx = i % spu.fb.width_tiles; + uint ty = i / spu.fb.width_tiles; + if (clear->surface == 0) + put_tile(tx, ty, &spu.ctile, TAG_SURFACE_CLEAR, 0); + else + put_tile(tx, ty, &spu.ztile, TAG_SURFACE_CLEAR, 1); + } + } + + if (spu.init.debug_flags & CELL_DEBUG_SYNC) { + wait_on_mask(1 << TAG_SURFACE_CLEAR); + } + +#endif /* CLEAR_OPT */ + + D_PRINTF(CELL_DEBUG_CMD, "CLEAR SURF done\n"); +} + + +static void +cmd_release_verts(const struct cell_command_release_verts *release) +{ + D_PRINTF(CELL_DEBUG_CMD, "RELEASE VERTS %u\n", release->vertex_buf); + ASSERT(release->vertex_buf != ~0U); + release_buffer(release->vertex_buf); +} + + +/** + * Process a CELL_CMD_STATE_FRAGMENT_OPS command. + * This involves installing new fragment ops SPU code. + * If this function is never called, we'll use a regular C fallback function + * for fragment processing. + */ +static void +cmd_state_fragment_ops(const struct cell_command_fragment_ops *fops) +{ + D_PRINTF(CELL_DEBUG_CMD, "CMD_STATE_FRAGMENT_OPS\n"); + + /* Copy state info (for fallback case only - this will eventually + * go away when the fallback case goes away) + */ + memcpy(&spu.depth_stencil_alpha, &fops->dsa, sizeof(fops->dsa)); + memcpy(&spu.blend, &fops->blend, sizeof(fops->blend)); + memcpy(&spu.blend_color, &fops->blend_color, sizeof(fops->blend_color)); + + /* Make sure the SPU knows which buffers it's expected to read when + * it's told to pull tiles. + */ + spu.read_depth_stencil = (spu.depth_stencil_alpha.depth.enabled || spu.depth_stencil_alpha.stencil[0].enabled); + + /* If we're forcing the fallback code to be used (for debug purposes), + * install that. Otherwise install the incoming SPU code. + */ + if ((spu.init.debug_flags & CELL_DEBUG_FRAGMENT_OP_FALLBACK) != 0) { + static unsigned int warned = 0; + if (!warned) { + fprintf(stderr, "Cell Warning: using fallback per-fragment code\n"); + warned = 1; + } + /* The following two lines aren't really necessary if you + * know the debug flags won't change during a run, and if you + * know that the function pointers are initialized correctly. + * We set them here to allow a person to change the debug + * flags during a run (from inside a debugger). + */ + spu.fragment_ops[CELL_FACING_FRONT] = spu_fallback_fragment_ops; + spu.fragment_ops[CELL_FACING_BACK] = spu_fallback_fragment_ops; + return; + } + + /* Make sure the SPU code buffer is large enough to hold the incoming code. + * Note that we *don't* use align_malloc() and align_free(), because + * those utility functions are *not* available in SPU code. + * */ + if (spu.fragment_ops_code_size < fops->total_code_size) { + if (spu.fragment_ops_code != NULL) { + free(spu.fragment_ops_code); + } + spu.fragment_ops_code_size = fops->total_code_size; + spu.fragment_ops_code = malloc(fops->total_code_size); + if (spu.fragment_ops_code == NULL) { + /* Whoops. */ + fprintf(stderr, "CELL Warning: failed to allocate fragment ops code (%d bytes) - using fallback\n", fops->total_code_size); + spu.fragment_ops_code = NULL; + spu.fragment_ops_code_size = 0; + spu.fragment_ops[CELL_FACING_FRONT] = spu_fallback_fragment_ops; + spu.fragment_ops[CELL_FACING_BACK] = spu_fallback_fragment_ops; + return; + } + } + + /* Copy the SPU code from the command buffer to the spu buffer */ + memcpy(spu.fragment_ops_code, fops->code, fops->total_code_size); + + /* Set the pointers for the front-facing and back-facing fragments + * to the specified offsets within the code. Note that if the + * front-facing and back-facing code are the same, they'll have + * the same offset. + */ + spu.fragment_ops[CELL_FACING_FRONT] = (spu_fragment_ops_func) &spu.fragment_ops_code[fops->front_code_index]; + spu.fragment_ops[CELL_FACING_BACK] = (spu_fragment_ops_func) &spu.fragment_ops_code[fops->back_code_index]; +} + +static void +cmd_state_fragment_program(const struct cell_command_fragment_program *fp) +{ + D_PRINTF(CELL_DEBUG_CMD, "CMD_STATE_FRAGMENT_PROGRAM\n"); + /* Copy SPU code from batch buffer to spu buffer */ + memcpy(spu.fragment_program_code, fp->code, + SPU_MAX_FRAGMENT_PROGRAM_INSTS * 4); +#if 01 + /* Point function pointer at new code */ + spu.fragment_program = (spu_fragment_program_func)spu.fragment_program_code; +#endif +} + + +static uint +cmd_state_fs_constants(const qword *buffer, uint pos) +{ + const uint num_const = spu_extract((vector unsigned int)buffer[pos+1], 0); + const float *constants = (const float *) &buffer[pos+2]; + uint i; + + D_PRINTF(CELL_DEBUG_CMD, "CMD_STATE_FS_CONSTANTS (%u)\n", num_const); + + /* Expand each float to float[4] for SOA execution */ + for (i = 0; i < num_const; i++) { + D_PRINTF(CELL_DEBUG_CMD, " const[%u] = %f\n", i, constants[i]); + spu.constants[i] = spu_splats(constants[i]); + } + + /* return new buffer pos (in 16-byte words) */ + return pos + 2 + (ROUNDUP16(num_const * sizeof(float)) / 16); +} + + +static void +cmd_state_framebuffer(const struct cell_command_framebuffer *cmd) +{ + D_PRINTF(CELL_DEBUG_CMD, "FRAMEBUFFER: %d x %d at %p, cformat 0x%x zformat 0x%x\n", + cmd->width, + cmd->height, + cmd->color_start, + cmd->color_format, + cmd->depth_format); + + ASSERT_ALIGN16(cmd->color_start); + ASSERT_ALIGN16(cmd->depth_start); + + spu.fb.color_start = cmd->color_start; + spu.fb.depth_start = cmd->depth_start; + spu.fb.color_format = cmd->color_format; + spu.fb.depth_format = cmd->depth_format; + spu.fb.width = cmd->width; + spu.fb.height = cmd->height; + spu.fb.width_tiles = (spu.fb.width + TILE_SIZE - 1) / TILE_SIZE; + spu.fb.height_tiles = (spu.fb.height + TILE_SIZE - 1) / TILE_SIZE; + + switch (spu.fb.depth_format) { + case PIPE_FORMAT_Z32_UNORM: + spu.fb.zsize = 4; + spu.fb.zscale = (float) 0xffffffffu; + break; + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: + spu.fb.zsize = 4; + spu.fb.zscale = (float) 0x00ffffffu; + break; + case PIPE_FORMAT_Z16_UNORM: + spu.fb.zsize = 2; + spu.fb.zscale = (float) 0xffffu; + break; + default: + spu.fb.zsize = 0; + break; + } +} + + +/** + * Tex texture mask_s/t and scale_s/t fields depend on the texture size and + * sampler wrap modes. + */ +static void +update_tex_masks(struct spu_texture *texture, + const struct pipe_sampler_state *sampler) +{ + uint i; + + for (i = 0; i < CELL_MAX_TEXTURE_LEVELS; i++) { + int width = texture->level[i].width; + int height = texture->level[i].height; + + if (sampler->wrap_s == PIPE_TEX_WRAP_REPEAT) + texture->level[i].mask_s = spu_splats(width - 1); + else + texture->level[i].mask_s = spu_splats(~0); + + if (sampler->wrap_t == PIPE_TEX_WRAP_REPEAT) + texture->level[i].mask_t = spu_splats(height - 1); + else + texture->level[i].mask_t = spu_splats(~0); + + if (sampler->normalized_coords) { + texture->level[i].scale_s = spu_splats((float) width); + texture->level[i].scale_t = spu_splats((float) height); + } + else { + texture->level[i].scale_s = spu_splats(1.0f); + texture->level[i].scale_t = spu_splats(1.0f); + } + } +} + + +static void +cmd_state_sampler(const struct cell_command_sampler *sampler) +{ + uint unit = sampler->unit; + + D_PRINTF(CELL_DEBUG_CMD, "SAMPLER [%u]\n", unit); + + spu.sampler[unit] = sampler->state; + + switch (spu.sampler[unit].min_img_filter) { + case PIPE_TEX_FILTER_LINEAR: + spu.min_sample_texture_2d[unit] = sample_texture_2d_bilinear; + break; + case PIPE_TEX_FILTER_NEAREST: + spu.min_sample_texture_2d[unit] = sample_texture_2d_nearest; + break; + default: + ASSERT(0); + } + + switch (spu.sampler[sampler->unit].mag_img_filter) { + case PIPE_TEX_FILTER_LINEAR: + spu.mag_sample_texture_2d[unit] = sample_texture_2d_bilinear; + break; + case PIPE_TEX_FILTER_NEAREST: + spu.mag_sample_texture_2d[unit] = sample_texture_2d_nearest; + break; + default: + ASSERT(0); + } + + switch (spu.sampler[sampler->unit].min_mip_filter) { + case PIPE_TEX_MIPFILTER_NEAREST: + case PIPE_TEX_MIPFILTER_LINEAR: + spu.sample_texture_2d[unit] = sample_texture_2d_lod; + break; + case PIPE_TEX_MIPFILTER_NONE: + spu.sample_texture_2d[unit] = spu.mag_sample_texture_2d[unit]; + break; + default: + ASSERT(0); + } + + update_tex_masks(&spu.texture[unit], &spu.sampler[unit]); +} + + +static void +cmd_state_texture(const struct cell_command_texture *texture) +{ + const uint unit = texture->unit; + uint i; + + D_PRINTF(CELL_DEBUG_CMD, "TEXTURE [%u]\n", texture->unit); + + spu.texture[unit].max_level = 0; + spu.texture[unit].target = texture->target; + + for (i = 0; i < CELL_MAX_TEXTURE_LEVELS; i++) { + uint width = texture->width[i]; + uint height = texture->height[i]; + uint depth = texture->depth[i]; + + D_PRINTF(CELL_DEBUG_CMD, " LEVEL %u: at %p size[0] %u x %u\n", i, + texture->start[i], texture->width[i], texture->height[i]); + + spu.texture[unit].level[i].start = texture->start[i]; + spu.texture[unit].level[i].width = width; + spu.texture[unit].level[i].height = height; + spu.texture[unit].level[i].depth = depth; + + spu.texture[unit].level[i].tiles_per_row = + (width + TILE_SIZE - 1) / TILE_SIZE; + + spu.texture[unit].level[i].bytes_per_image = + 4 * align(width, TILE_SIZE) * align(height, TILE_SIZE) * depth; + + spu.texture[unit].level[i].max_s = spu_splats((int) width - 1); + spu.texture[unit].level[i].max_t = spu_splats((int) height - 1); + + if (texture->start[i]) + spu.texture[unit].max_level = i; + } + + update_tex_masks(&spu.texture[unit], &spu.sampler[unit]); +} + + +static void +cmd_state_vertex_info(const struct vertex_info *vinfo) +{ + D_PRINTF(CELL_DEBUG_CMD, "VERTEX_INFO num_attribs=%u\n", vinfo->num_attribs); + ASSERT(vinfo->num_attribs >= 1); + ASSERT(vinfo->num_attribs <= 8); + memcpy(&spu.vertex_info, vinfo, sizeof(*vinfo)); +} + + +static void +cmd_state_vs_array_info(const struct cell_array_info *vs_info) +{ + const unsigned attr = vs_info->attr; + + ASSERT(attr < PIPE_MAX_ATTRIBS); + draw.vertex_fetch.src_ptr[attr] = vs_info->base; + draw.vertex_fetch.pitch[attr] = vs_info->pitch; + draw.vertex_fetch.size[attr] = vs_info->size; + draw.vertex_fetch.code_offset[attr] = vs_info->function_offset; + draw.vertex_fetch.dirty = 1; +} + + +static void +cmd_state_attrib_fetch(const struct cell_attribute_fetch_code *code) +{ + mfc_get(attribute_fetch_code_buffer, + (unsigned int) code->base, /* src */ + code->size, + TAG_BATCH_BUFFER, + 0, /* tid */ + 0 /* rid */); + wait_on_mask(1 << TAG_BATCH_BUFFER); + + draw.vertex_fetch.code = attribute_fetch_code_buffer; +} + + +static void +cmd_finish(void) +{ + D_PRINTF(CELL_DEBUG_CMD, "FINISH\n"); + really_clear_tiles(0); + /* wait for all outstanding DMAs to finish */ + mfc_write_tag_mask(~0); + mfc_read_tag_status_all(); + /* send mbox message to PPU */ + spu_write_out_mbox(CELL_CMD_FINISH); +} + + +/** + * Execute a batch of commands which was sent to us by the PPU. + * See the cell_emit_state.c code to see where the commands come from. + * + * The opcode param encodes the location of the buffer and its size. + */ +static void +cmd_batch(uint opcode) +{ + const uint buf = (opcode >> 8) & 0xff; + uint size = (opcode >> 16); + PIPE_ALIGN_VAR(16) qword buffer[CELL_BUFFER_SIZE / 16]; + const unsigned usize = ROUNDUP16(size) / sizeof(buffer[0]); + uint pos; + + D_PRINTF(CELL_DEBUG_CMD, "BATCH buffer %u, len %u, from %p\n", + buf, size, spu.init.buffers[buf]); + + ASSERT((opcode & CELL_CMD_OPCODE_MASK) == CELL_CMD_BATCH); + + ASSERT_ALIGN16(spu.init.buffers[buf]); + + size = ROUNDUP16(size); + + ASSERT_ALIGN16(spu.init.buffers[buf]); + + mfc_get(buffer, /* dest */ + (unsigned int) spu.init.buffers[buf], /* src */ + size, + TAG_BATCH_BUFFER, + 0, /* tid */ + 0 /* rid */); + wait_on_mask(1 << TAG_BATCH_BUFFER); + + /* Tell PPU we're done copying the buffer to local store */ + D_PRINTF(CELL_DEBUG_CMD, "release batch buf %u\n", buf); + release_buffer(buf); + + /* + * Loop over commands in the batch buffer + */ + for (pos = 0; pos < usize; /* no incr */) { + switch (si_to_uint(buffer[pos])) { + /* + * rendering commands + */ + case CELL_CMD_CLEAR_SURFACE: + { + struct cell_command_clear_surface *clr + = (struct cell_command_clear_surface *) &buffer[pos]; + cmd_clear_surface(clr); + pos += sizeof(*clr) / 16; + } + break; + case CELL_CMD_RENDER: + { + struct cell_command_render *render + = (struct cell_command_render *) &buffer[pos]; + uint pos_incr; + cmd_render(render, &pos_incr); + pos += ((pos_incr+1)&~1) / 2; // should 'fix' cmd_render return + } + break; + /* + * state-update commands + */ + case CELL_CMD_STATE_FRAMEBUFFER: + { + struct cell_command_framebuffer *fb + = (struct cell_command_framebuffer *) &buffer[pos]; + cmd_state_framebuffer(fb); + pos += sizeof(*fb) / 16; + } + break; + case CELL_CMD_STATE_FRAGMENT_OPS: + { + struct cell_command_fragment_ops *fops + = (struct cell_command_fragment_ops *) &buffer[pos]; + cmd_state_fragment_ops(fops); + /* This is a variant-sized command */ + pos += ROUNDUP16(sizeof(*fops) + fops->total_code_size) / 16; + } + break; + case CELL_CMD_STATE_FRAGMENT_PROGRAM: + { + struct cell_command_fragment_program *fp + = (struct cell_command_fragment_program *) &buffer[pos]; + cmd_state_fragment_program(fp); + pos += sizeof(*fp) / 16; + } + break; + case CELL_CMD_STATE_FS_CONSTANTS: + pos = cmd_state_fs_constants(buffer, pos); + break; + case CELL_CMD_STATE_RASTERIZER: + { + struct cell_command_rasterizer *rast = + (struct cell_command_rasterizer *) &buffer[pos]; + spu.rasterizer = rast->rasterizer; + pos += sizeof(*rast) / 16; + } + break; + case CELL_CMD_STATE_SAMPLER: + { + struct cell_command_sampler *sampler + = (struct cell_command_sampler *) &buffer[pos]; + cmd_state_sampler(sampler); + pos += sizeof(*sampler) / 16; + } + break; + case CELL_CMD_STATE_TEXTURE: + { + struct cell_command_texture *texture + = (struct cell_command_texture *) &buffer[pos]; + cmd_state_texture(texture); + pos += sizeof(*texture) / 16; + } + break; + case CELL_CMD_STATE_VERTEX_INFO: + cmd_state_vertex_info((struct vertex_info *) &buffer[pos+1]); + pos += 1 + ROUNDUP16(sizeof(struct vertex_info)) / 16; + break; + case CELL_CMD_STATE_VIEWPORT: + (void) memcpy(& draw.viewport, &buffer[pos+1], + sizeof(struct pipe_viewport_state)); + pos += 1 + ROUNDUP16(sizeof(struct pipe_viewport_state)) / 16; + break; + case CELL_CMD_STATE_UNIFORMS: + draw.constants = (const float (*)[4]) (uintptr_t)spu_extract((vector unsigned int)buffer[pos+1],0); + pos += 2; + break; + case CELL_CMD_STATE_VS_ARRAY_INFO: + cmd_state_vs_array_info((struct cell_array_info *) &buffer[pos+1]); + pos += 1 + ROUNDUP16(sizeof(struct cell_array_info)) / 16; + break; + case CELL_CMD_STATE_BIND_VS: +#if 0 + spu_bind_vertex_shader(&draw, + (struct cell_shader_info *) &buffer[pos+1]); +#endif + pos += 1 + ROUNDUP16(sizeof(struct cell_shader_info)) / 16; + break; + case CELL_CMD_STATE_ATTRIB_FETCH: + cmd_state_attrib_fetch((struct cell_attribute_fetch_code *) + &buffer[pos+1]); + pos += 1 + ROUNDUP16(sizeof(struct cell_attribute_fetch_code)) / 16; + break; + /* + * misc commands + */ + case CELL_CMD_FINISH: + cmd_finish(); + pos += 1; + break; + case CELL_CMD_FENCE: + { + struct cell_command_fence *fence_cmd = + (struct cell_command_fence *) &buffer[pos]; + cmd_fence(fence_cmd); + pos += sizeof(*fence_cmd) / 16; + } + break; + case CELL_CMD_RELEASE_VERTS: + { + struct cell_command_release_verts *release + = (struct cell_command_release_verts *) &buffer[pos]; + cmd_release_verts(release); + pos += sizeof(*release) / 16; + } + break; + case CELL_CMD_FLUSH_BUFFER_RANGE: { + struct cell_buffer_range *br = (struct cell_buffer_range *) + &buffer[pos+1]; + + spu_dcache_mark_dirty((unsigned) br->base, br->size); + pos += 1 + ROUNDUP16(sizeof(struct cell_buffer_range)) / 16; + break; + } + default: + printf("SPU %u: bad opcode: 0x%x\n", spu.init.id, si_to_uint(buffer[pos])); + ASSERT(0); + break; + } + } + + D_PRINTF(CELL_DEBUG_CMD, "BATCH complete\n"); +} + + +#define PERF 0 + + +/** + * Main loop for SPEs: Get a command, execute it, repeat. + */ +void +command_loop(void) +{ + int exitFlag = 0; + uint t0, t1; + + D_PRINTF(CELL_DEBUG_CMD, "Enter command loop\n"); + + while (!exitFlag) { + unsigned opcode; + + D_PRINTF(CELL_DEBUG_CMD, "Wait for cmd...\n"); + + if (PERF) + spu_write_decrementer(~0); + + /* read/wait from mailbox */ + opcode = (unsigned int) spu_read_in_mbox(); + D_PRINTF(CELL_DEBUG_CMD, "got cmd 0x%x\n", opcode); + + if (PERF) + t0 = spu_read_decrementer(); + + switch (opcode & CELL_CMD_OPCODE_MASK) { + case CELL_CMD_EXIT: + D_PRINTF(CELL_DEBUG_CMD, "EXIT\n"); + exitFlag = 1; + break; + case CELL_CMD_VS_EXECUTE: +#if 0 + spu_execute_vertex_shader(&draw, &cmd.vs); +#endif + break; + case CELL_CMD_BATCH: + cmd_batch(opcode); + break; + default: + printf("Bad opcode 0x%x!\n", opcode & CELL_CMD_OPCODE_MASK); + } + + if (PERF) { + t1 = spu_read_decrementer(); + printf("wait mbox time: %gms batch time: %gms\n", + (~0u - t0) * spu.init.inv_timebase, + (t0 - t1) * spu.init.inv_timebase); + } + } + + D_PRINTF(CELL_DEBUG_CMD, "Exit command loop\n"); + + if (spu.init.debug_flags & CELL_DEBUG_CACHE) + spu_dcache_report(); +} + +/* Initialize this module; we manage the fragment ops buffer here. */ +void +spu_command_init(void) +{ + /* Install default/fallback fragment processing function. + * This will normally be overriden by a code-gen'd function + * unless CELL_FORCE_FRAGMENT_OPS_FALLBACK is set. + */ + spu.fragment_ops[CELL_FACING_FRONT] = spu_fallback_fragment_ops; + spu.fragment_ops[CELL_FACING_BACK] = spu_fallback_fragment_ops; + + /* Set up the basic empty buffer for code-gen'ed fragment ops */ + spu.fragment_ops_code = NULL; + spu.fragment_ops_code_size = 0; +} + +void +spu_command_close(void) +{ + /* Deallocate the code-gen buffer for fragment ops, and reset the + * fragment ops functions to their initial setting (just to leave + * things in a good state). + */ + if (spu.fragment_ops_code != NULL) { + free(spu.fragment_ops_code); + } + spu_command_init(); +} diff --git a/src/gallium/drivers/cell/spu/spu_command.h b/src/gallium/drivers/cell/spu/spu_command.h new file mode 100644 index 0000000..83dcdad --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_command.h @@ -0,0 +1,35 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +extern void +command_loop(void); + +extern void +spu_command_init(void); + +extern void +spu_command_close(void); diff --git a/src/gallium/drivers/cell/spu/spu_dcache.c b/src/gallium/drivers/cell/spu/spu_dcache.c new file mode 100644 index 0000000..a6d6763 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_dcache.c @@ -0,0 +1,145 @@ +/* + * (C) Copyright IBM Corporation 2008 + * 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 + * 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 + * AUTHORS, COPYRIGHT HOLDERS, 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 "cell/common.h" +#include "spu_main.h" +#include "spu_dcache.h" + +#define CACHELINE_LOG2SIZE 7 +#define LINE_SIZE (1U << 7) +#define ALIGN_MASK (~(LINE_SIZE - 1)) + +#define CACHE_NAME data +#define CACHED_TYPE qword +#define CACHE_TYPE CACHE_TYPE_RO +#define CACHE_SET_TAGID(set) (((set) & 0x03) + TAG_DCACHE0) +#define CACHE_LOG2NNWAY 2 +#define CACHE_LOG2NSETS 6 +#ifdef DEBUG +#define CACHE_STATS 1 +#endif +#include + +/* Yes folks, this is ugly. + */ +#undef CACHE_NWAY +#undef CACHE_NSETS +#define CACHE_NAME data +#define CACHE_NWAY 4 +#define CACHE_NSETS (1U << 6) + + +/** + * Fetch between arbitrary number of bytes from an unaligned address + * + * \param dst Destination data buffer + * \param ea Main memory effective address of source data + * \param size Number of bytes to read + * + * \warning + * As is hinted by the type of the \c dst pointer, this function writes + * multiples of 16-bytes. + */ +void +spu_dcache_fetch_unaligned(qword *dst, unsigned ea, unsigned size) +{ + const int shift = ea & 0x0f; + const unsigned read_size = ROUNDUP16(size + shift); + const unsigned last_read = ROUNDUP16(ea + size); + const qword *const last_write = dst + (ROUNDUP16(size) / 16); + unsigned i; + + + if (shift == 0) { + /* Data is already aligned. Fetch directly into the destination buffer. + */ + for (i = 0; i < size; i += 16) { + *(dst++) = cache_rd(data, ea + i); + } + } else { + qword hi; + + + /* Please exercise extreme caution when modifying this code. This code + * must not read past the end of the page containing the source data, + * and it must not write more than ((size + 15) / 16) qwords to the + * destination buffer. + */ + ea &= ~0x0f; + hi = cache_rd(data, ea); + for (i = 16; i < read_size; i += 16) { + qword lo = cache_rd(data, ea + i); + + *(dst++) = si_or((qword) spu_slqwbyte(hi, shift), + (qword) spu_rlmaskqwbyte(lo, shift - 16)); + hi = lo; + } + + if (dst != last_write) { + *(dst++) = si_or((qword) spu_slqwbyte(hi, shift), si_il(0)); + } + } + + ASSERT((ea + i) == last_read); + ASSERT(dst == last_write); +} + + +/** + * Notify the cache that a range of main memory may have been modified + */ +void +spu_dcache_mark_dirty(unsigned ea, unsigned size) +{ + unsigned i; + const unsigned aligned_start = (ea & ALIGN_MASK); + const unsigned aligned_end = (ea + size + (LINE_SIZE - 1)) + & ALIGN_MASK; + + + for (i = 0; i < (CACHE_NWAY * CACHE_NSETS); i++) { + const unsigned entry = __cache_dir[i]; + const unsigned addr = entry & ~0x0f; + + __cache_dir[i] = ((addr >= aligned_start) && (addr < aligned_end)) + ? (entry & ~CACHELINE_VALID) : entry; + } +} + + +/** + * Print cache utilization report + */ +void +spu_dcache_report(void) +{ +#ifdef CACHE_STATS + if (spu.init.id == 0) { + printf("SPU 0: Texture cache report:\n"); + cache_pr_stats(data); + } +#endif +} + + diff --git a/src/gallium/drivers/cell/spu/spu_dcache.h b/src/gallium/drivers/cell/spu/spu_dcache.h new file mode 100644 index 0000000..39a19eb --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_dcache.h @@ -0,0 +1,37 @@ +/* + * (C) Copyright IBM Corporation 2008 + * 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 + * 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 + * AUTHORS, COPYRIGHT HOLDERS, 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 SPU_DCACHE_H +#define SPU_DCACHE_H + +extern void +spu_dcache_fetch_unaligned(qword *dst, unsigned ea, unsigned size); + +extern void +spu_dcache_mark_dirty(unsigned ea, unsigned size); + +extern void +spu_dcache_report(void); + +#endif /* SPU_DCACHE_H */ diff --git a/src/gallium/drivers/cell/spu/spu_exec.c b/src/gallium/drivers/cell/spu/spu_exec.c new file mode 100644 index 0000000..e4ebeb5 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_exec.c @@ -0,0 +1,1870 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * TGSI interpretor/executor. + * + * Flow control information: + * + * Since we operate on 'quads' (4 pixels or 4 vertices in parallel) + * flow control statements (IF/ELSE/ENDIF, LOOP/ENDLOOP) require special + * care since a condition may be true for some quad components but false + * for other components. + * + * We basically execute all statements (even if they're in the part of + * an IF/ELSE clause that's "not taken") and use a special mask to + * control writing to destination registers. This is the ExecMask. + * See store_dest(). + * + * The ExecMask is computed from three other masks (CondMask, LoopMask and + * ContMask) which are controlled by the flow control instructions (namely: + * (IF/ELSE/ENDIF, LOOP/ENDLOOP and CONT). + * + * + * Authors: + * Michal Krol + * Brian Paul + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "spu_exec.h" +#include "spu_main.h" +#include "spu_vertex_shader.h" +#include "spu_dcache.h" +#include "cell/common.h" + +#define TILE_TOP_LEFT 0 +#define TILE_TOP_RIGHT 1 +#define TILE_BOTTOM_LEFT 2 +#define TILE_BOTTOM_RIGHT 3 + +/* + * Shorthand locations of various utility registers (_I = Index, _C = Channel) + */ +#define TEMP_0_I TGSI_EXEC_TEMP_00000000_I +#define TEMP_0_C TGSI_EXEC_TEMP_00000000_C +#define TEMP_7F_I TGSI_EXEC_TEMP_7FFFFFFF_I +#define TEMP_7F_C TGSI_EXEC_TEMP_7FFFFFFF_C +#define TEMP_80_I TGSI_EXEC_TEMP_80000000_I +#define TEMP_80_C TGSI_EXEC_TEMP_80000000_C +#define TEMP_FF_I TGSI_EXEC_TEMP_FFFFFFFF_I +#define TEMP_FF_C TGSI_EXEC_TEMP_FFFFFFFF_C +#define TEMP_1_I TGSI_EXEC_TEMP_ONE_I +#define TEMP_1_C TGSI_EXEC_TEMP_ONE_C +#define TEMP_2_I TGSI_EXEC_TEMP_TWO_I +#define TEMP_2_C TGSI_EXEC_TEMP_TWO_C +#define TEMP_128_I TGSI_EXEC_TEMP_128_I +#define TEMP_128_C TGSI_EXEC_TEMP_128_C +#define TEMP_M128_I TGSI_EXEC_TEMP_MINUS_128_I +#define TEMP_M128_C TGSI_EXEC_TEMP_MINUS_128_C +#define TEMP_KILMASK_I TGSI_EXEC_TEMP_KILMASK_I +#define TEMP_KILMASK_C TGSI_EXEC_TEMP_KILMASK_C +#define TEMP_OUTPUT_I TGSI_EXEC_TEMP_OUTPUT_I +#define TEMP_OUTPUT_C TGSI_EXEC_TEMP_OUTPUT_C +#define TEMP_PRIMITIVE_I TGSI_EXEC_TEMP_PRIMITIVE_I +#define TEMP_PRIMITIVE_C TGSI_EXEC_TEMP_PRIMITIVE_C +#define TEMP_R0 TGSI_EXEC_TEMP_R0 + +#define FOR_EACH_CHANNEL(CHAN)\ + for (CHAN = 0; CHAN < 4; CHAN++) + +#define IS_CHANNEL_ENABLED(INST, CHAN)\ + ((INST).Dst[0].Register.WriteMask & (1 << (CHAN))) + +#define IS_CHANNEL_ENABLED2(INST, CHAN)\ + ((INST).Dst[1].Register.WriteMask & (1 << (CHAN))) + +#define FOR_EACH_ENABLED_CHANNEL(INST, CHAN)\ + FOR_EACH_CHANNEL( CHAN )\ + if (IS_CHANNEL_ENABLED( INST, CHAN )) + +#define FOR_EACH_ENABLED_CHANNEL2(INST, CHAN)\ + FOR_EACH_CHANNEL( CHAN )\ + if (IS_CHANNEL_ENABLED2( INST, CHAN )) + + +/** The execution mask depends on the conditional mask and the loop mask */ +#define UPDATE_EXEC_MASK(MACH) \ + MACH->ExecMask = MACH->CondMask & MACH->LoopMask & MACH->ContMask & MACH->FuncMask + + +#define CHAN_X 0 +#define CHAN_Y 1 +#define CHAN_Z 2 +#define CHAN_W 3 + + + +/** + * Initialize machine state by expanding tokens to full instructions, + * allocating temporary storage, setting up constants, etc. + * After this, we can call spu_exec_machine_run() many times. + */ +void +spu_exec_machine_init(struct spu_exec_machine *mach, + uint numSamplers, + struct spu_sampler *samplers, + unsigned processor) +{ + const qword zero = si_il(0); + const qword not_zero = si_il(~0); + + (void) numSamplers; + mach->Samplers = samplers; + mach->Processor = processor; + mach->Addrs = &mach->Temps[TGSI_EXEC_NUM_TEMPS]; + + /* Setup constants. */ + mach->Temps[TEMP_0_I].xyzw[TEMP_0_C].q = zero; + mach->Temps[TEMP_FF_I].xyzw[TEMP_FF_C].q = not_zero; + mach->Temps[TEMP_7F_I].xyzw[TEMP_7F_C].q = si_shli(not_zero, -1); + mach->Temps[TEMP_80_I].xyzw[TEMP_80_C].q = si_shli(not_zero, 31); + + mach->Temps[TEMP_1_I].xyzw[TEMP_1_C].q = (qword) spu_splats(1.0f); + mach->Temps[TEMP_2_I].xyzw[TEMP_2_C].q = (qword) spu_splats(2.0f); + mach->Temps[TEMP_128_I].xyzw[TEMP_128_C].q = (qword) spu_splats(128.0f); + mach->Temps[TEMP_M128_I].xyzw[TEMP_M128_C].q = (qword) spu_splats(-128.0f); +} + + +static INLINE qword +micro_abs(qword src) +{ + return si_rotmi(si_shli(src, 1), -1); +} + +static INLINE qword +micro_ceil(qword src) +{ + return (qword) _ceilf4((vec_float4) src); +} + +static INLINE qword +micro_cos(qword src) +{ + return (qword) _cosf4((vec_float4) src); +} + +static const qword br_shuf = { + TILE_BOTTOM_RIGHT + 0, TILE_BOTTOM_RIGHT + 1, + TILE_BOTTOM_RIGHT + 2, TILE_BOTTOM_RIGHT + 3, + TILE_BOTTOM_RIGHT + 0, TILE_BOTTOM_RIGHT + 1, + TILE_BOTTOM_RIGHT + 2, TILE_BOTTOM_RIGHT + 3, + TILE_BOTTOM_RIGHT + 0, TILE_BOTTOM_RIGHT + 1, + TILE_BOTTOM_RIGHT + 2, TILE_BOTTOM_RIGHT + 3, + TILE_BOTTOM_RIGHT + 0, TILE_BOTTOM_RIGHT + 1, + TILE_BOTTOM_RIGHT + 2, TILE_BOTTOM_RIGHT + 3, +}; + +static const qword bl_shuf = { + TILE_BOTTOM_LEFT + 0, TILE_BOTTOM_LEFT + 1, + TILE_BOTTOM_LEFT + 2, TILE_BOTTOM_LEFT + 3, + TILE_BOTTOM_LEFT + 0, TILE_BOTTOM_LEFT + 1, + TILE_BOTTOM_LEFT + 2, TILE_BOTTOM_LEFT + 3, + TILE_BOTTOM_LEFT + 0, TILE_BOTTOM_LEFT + 1, + TILE_BOTTOM_LEFT + 2, TILE_BOTTOM_LEFT + 3, + TILE_BOTTOM_LEFT + 0, TILE_BOTTOM_LEFT + 1, + TILE_BOTTOM_LEFT + 2, TILE_BOTTOM_LEFT + 3, +}; + +static const qword tl_shuf = { + TILE_TOP_LEFT + 0, TILE_TOP_LEFT + 1, + TILE_TOP_LEFT + 2, TILE_TOP_LEFT + 3, + TILE_TOP_LEFT + 0, TILE_TOP_LEFT + 1, + TILE_TOP_LEFT + 2, TILE_TOP_LEFT + 3, + TILE_TOP_LEFT + 0, TILE_TOP_LEFT + 1, + TILE_TOP_LEFT + 2, TILE_TOP_LEFT + 3, + TILE_TOP_LEFT + 0, TILE_TOP_LEFT + 1, + TILE_TOP_LEFT + 2, TILE_TOP_LEFT + 3, +}; + +static qword +micro_ddx(qword src) +{ + qword bottom_right = si_shufb(src, src, br_shuf); + qword bottom_left = si_shufb(src, src, bl_shuf); + + return si_fs(bottom_right, bottom_left); +} + +static qword +micro_ddy(qword src) +{ + qword top_left = si_shufb(src, src, tl_shuf); + qword bottom_left = si_shufb(src, src, bl_shuf); + + return si_fs(top_left, bottom_left); +} + +static INLINE qword +micro_div(qword src0, qword src1) +{ + return (qword) _divf4((vec_float4) src0, (vec_float4) src1); +} + +static qword +micro_flr(qword src) +{ + return (qword) _floorf4((vec_float4) src); +} + +static qword +micro_frc(qword src) +{ + return si_fs(src, (qword) _floorf4((vec_float4) src)); +} + +static INLINE qword +micro_ge(qword src0, qword src1) +{ + return si_or(si_fceq(src0, src1), si_fcgt(src0, src1)); +} + +static qword +micro_lg2(qword src) +{ + return (qword) _log2f4((vec_float4) src); +} + +static INLINE qword +micro_lt(qword src0, qword src1) +{ + const qword tmp = si_or(si_fceq(src0, src1), si_fcgt(src0, src1)); + + return si_xori(tmp, 0xff); +} + +static INLINE qword +micro_max(qword src0, qword src1) +{ + return si_selb(src1, src0, si_fcgt(src0, src1)); +} + +static INLINE qword +micro_min(qword src0, qword src1) +{ + return si_selb(src0, src1, si_fcgt(src0, src1)); +} + +static qword +micro_neg(qword src) +{ + return si_xor(src, (qword) spu_splats(0x80000000)); +} + +static qword +micro_set_sign(qword src) +{ + return si_or(src, (qword) spu_splats(0x80000000)); +} + +static qword +micro_pow(qword src0, qword src1) +{ + return (qword) _powf4((vec_float4) src0, (vec_float4) src1); +} + +static qword +micro_rnd(qword src) +{ + const qword half = (qword) spu_splats(0.5f); + + /* May be able to use _roundf4. There may be some difference, though. + */ + return (qword) _floorf4((vec_float4) si_fa(src, half)); +} + +static INLINE qword +micro_ishr(qword src0, qword src1) +{ + return si_rotma(src0, si_sfi(src1, 0)); +} + +static qword +micro_trunc(qword src) +{ + return (qword) _truncf4((vec_float4) src); +} + +static qword +micro_sin(qword src) +{ + return (qword) _sinf4((vec_float4) src); +} + +static INLINE qword +micro_sqrt(qword src) +{ + return (qword) _sqrtf4((vec_float4) src); +} + +static void +fetch_src_file_channel( + const struct spu_exec_machine *mach, + const uint file, + const uint swizzle, + const union spu_exec_channel *index, + union spu_exec_channel *chan ) +{ + switch( swizzle ) { + case TGSI_SWIZZLE_X: + case TGSI_SWIZZLE_Y: + case TGSI_SWIZZLE_Z: + case TGSI_SWIZZLE_W: + switch( file ) { + case TGSI_FILE_CONSTANT: { + unsigned i; + + for (i = 0; i < 4; i++) { + const float *ptr = mach->Consts[index->i[i]]; + float tmp[4]; + + spu_dcache_fetch_unaligned((qword *) tmp, + (uintptr_t)(ptr + swizzle), + sizeof(float)); + + chan->f[i] = tmp[0]; + } + break; + } + + case TGSI_FILE_INPUT: + chan->u[0] = mach->Inputs[index->i[0]].xyzw[swizzle].u[0]; + chan->u[1] = mach->Inputs[index->i[1]].xyzw[swizzle].u[1]; + chan->u[2] = mach->Inputs[index->i[2]].xyzw[swizzle].u[2]; + chan->u[3] = mach->Inputs[index->i[3]].xyzw[swizzle].u[3]; + break; + + case TGSI_FILE_TEMPORARY: + chan->u[0] = mach->Temps[index->i[0]].xyzw[swizzle].u[0]; + chan->u[1] = mach->Temps[index->i[1]].xyzw[swizzle].u[1]; + chan->u[2] = mach->Temps[index->i[2]].xyzw[swizzle].u[2]; + chan->u[3] = mach->Temps[index->i[3]].xyzw[swizzle].u[3]; + break; + + case TGSI_FILE_IMMEDIATE: + ASSERT( index->i[0] < (int) mach->ImmLimit ); + ASSERT( index->i[1] < (int) mach->ImmLimit ); + ASSERT( index->i[2] < (int) mach->ImmLimit ); + ASSERT( index->i[3] < (int) mach->ImmLimit ); + + chan->f[0] = mach->Imms[index->i[0]][swizzle]; + chan->f[1] = mach->Imms[index->i[1]][swizzle]; + chan->f[2] = mach->Imms[index->i[2]][swizzle]; + chan->f[3] = mach->Imms[index->i[3]][swizzle]; + break; + + case TGSI_FILE_ADDRESS: + chan->u[0] = mach->Addrs[index->i[0]].xyzw[swizzle].u[0]; + chan->u[1] = mach->Addrs[index->i[1]].xyzw[swizzle].u[1]; + chan->u[2] = mach->Addrs[index->i[2]].xyzw[swizzle].u[2]; + chan->u[3] = mach->Addrs[index->i[3]].xyzw[swizzle].u[3]; + break; + + case TGSI_FILE_OUTPUT: + /* vertex/fragment output vars can be read too */ + chan->u[0] = mach->Outputs[index->i[0]].xyzw[swizzle].u[0]; + chan->u[1] = mach->Outputs[index->i[1]].xyzw[swizzle].u[1]; + chan->u[2] = mach->Outputs[index->i[2]].xyzw[swizzle].u[2]; + chan->u[3] = mach->Outputs[index->i[3]].xyzw[swizzle].u[3]; + break; + + default: + ASSERT( 0 ); + } + break; + + default: + ASSERT( 0 ); + } +} + +static void +fetch_source( + const struct spu_exec_machine *mach, + union spu_exec_channel *chan, + const struct tgsi_full_src_register *reg, + const uint chan_index ) +{ + union spu_exec_channel index; + uint swizzle; + + index.i[0] = + index.i[1] = + index.i[2] = + index.i[3] = reg->Register.Index; + + if (reg->Register.Indirect) { + union spu_exec_channel index2; + union spu_exec_channel indir_index; + + index2.i[0] = + index2.i[1] = + index2.i[2] = + index2.i[3] = reg->Indirect.Index; + + swizzle = tgsi_util_get_src_register_swizzle(®->Indirect, + CHAN_X); + fetch_src_file_channel( + mach, + reg->Indirect.File, + swizzle, + &index2, + &indir_index ); + + index.q = si_a(index.q, indir_index.q); + } + + if( reg->Register.Dimension ) { + switch( reg->Register.File ) { + case TGSI_FILE_INPUT: + index.q = si_mpyi(index.q, 17); + break; + case TGSI_FILE_CONSTANT: + index.q = si_shli(index.q, 12); + break; + default: + ASSERT( 0 ); + } + + index.i[0] += reg->Dimension.Index; + index.i[1] += reg->Dimension.Index; + index.i[2] += reg->Dimension.Index; + index.i[3] += reg->Dimension.Index; + + if (reg->Dimension.Indirect) { + union spu_exec_channel index2; + union spu_exec_channel indir_index; + + index2.i[0] = + index2.i[1] = + index2.i[2] = + index2.i[3] = reg->DimIndirect.Index; + + swizzle = tgsi_util_get_src_register_swizzle( ®->DimIndirect, CHAN_X ); + fetch_src_file_channel( + mach, + reg->DimIndirect.File, + swizzle, + &index2, + &indir_index ); + + index.q = si_a(index.q, indir_index.q); + } + } + + swizzle = tgsi_util_get_full_src_register_swizzle( reg, chan_index ); + fetch_src_file_channel( + mach, + reg->Register.File, + swizzle, + &index, + chan ); + + switch (tgsi_util_get_full_src_register_sign_mode( reg, chan_index )) { + case TGSI_UTIL_SIGN_CLEAR: + chan->q = micro_abs(chan->q); + break; + + case TGSI_UTIL_SIGN_SET: + chan->q = micro_set_sign(chan->q); + break; + + case TGSI_UTIL_SIGN_TOGGLE: + chan->q = micro_neg(chan->q); + break; + + case TGSI_UTIL_SIGN_KEEP: + break; + } + + if (reg->RegisterExtMod.Complement) { + chan->q = si_fs(mach->Temps[TEMP_1_I].xyzw[TEMP_1_C].q, chan->q); + } +} + +static void +store_dest( + struct spu_exec_machine *mach, + const union spu_exec_channel *chan, + const struct tgsi_full_dst_register *reg, + const struct tgsi_full_instruction *inst, + uint chan_index ) +{ + union spu_exec_channel *dst; + + switch( reg->Register.File ) { + case TGSI_FILE_NULL: + return; + + case TGSI_FILE_OUTPUT: + dst = &mach->Outputs[mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0] + + reg->Register.Index].xyzw[chan_index]; + break; + + case TGSI_FILE_TEMPORARY: + dst = &mach->Temps[reg->Register.Index].xyzw[chan_index]; + break; + + case TGSI_FILE_ADDRESS: + dst = &mach->Addrs[reg->Register.Index].xyzw[chan_index]; + break; + + default: + ASSERT( 0 ); + return; + } + + switch (inst->Instruction.Saturate) + { + case TGSI_SAT_NONE: + if (mach->ExecMask & 0x1) + dst->i[0] = chan->i[0]; + if (mach->ExecMask & 0x2) + dst->i[1] = chan->i[1]; + if (mach->ExecMask & 0x4) + dst->i[2] = chan->i[2]; + if (mach->ExecMask & 0x8) + dst->i[3] = chan->i[3]; + break; + + case TGSI_SAT_ZERO_ONE: + /* XXX need to obey ExecMask here */ + dst->q = micro_max(chan->q, mach->Temps[TEMP_0_I].xyzw[TEMP_0_C].q); + dst->q = micro_min(dst->q, mach->Temps[TEMP_1_I].xyzw[TEMP_1_C].q); + break; + + case TGSI_SAT_MINUS_PLUS_ONE: + ASSERT( 0 ); + break; + + default: + ASSERT( 0 ); + } +} + +#define FETCH(VAL,INDEX,CHAN)\ + fetch_source (mach, VAL, &inst->Src[INDEX], CHAN) + +#define STORE(VAL,INDEX,CHAN)\ + store_dest (mach, VAL, &inst->Dst[INDEX], inst, CHAN ) + + +/** + * Execute ARB-style KIL which is predicated by a src register. + * Kill fragment if any of the four values is less than zero. + */ +static void +exec_kil(struct spu_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + uint uniquemask; + uint chan_index; + uint kilmask = 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */ + union spu_exec_channel r[1]; + + /* This mask stores component bits that were already tested. */ + uniquemask = 0; + + for (chan_index = 0; chan_index < 4; chan_index++) + { + uint swizzle; + uint i; + + /* unswizzle channel */ + swizzle = tgsi_util_get_full_src_register_swizzle ( + &inst->Src[0], + chan_index); + + /* check if the component has not been already tested */ + if (uniquemask & (1 << swizzle)) + continue; + uniquemask |= 1 << swizzle; + + FETCH(&r[0], 0, chan_index); + for (i = 0; i < 4; i++) + if (r[0].f[i] < 0.0f) + kilmask |= 1 << i; + } + + mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0] |= kilmask; +} + +/** + * Execute NVIDIA-style KIL which is predicated by a condition code. + * Kill fragment if the condition code is TRUE. + */ +static void +exec_kilp(struct spu_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + uint kilmask = 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */ + + /* TODO: build kilmask from CC mask */ + + mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0] |= kilmask; +} + +/* + * Fetch a texel using STR texture coordinates. + */ +static void +fetch_texel( struct spu_sampler *sampler, + const union spu_exec_channel *s, + const union spu_exec_channel *t, + const union spu_exec_channel *p, + float lodbias, /* XXX should be float[4] */ + union spu_exec_channel *r, + union spu_exec_channel *g, + union spu_exec_channel *b, + union spu_exec_channel *a ) +{ + qword rgba[4]; + qword out[4]; + + sampler->get_samples(sampler, s->f, t->f, p->f, lodbias, + (float (*)[4]) rgba); + + _transpose_matrix4x4((vec_float4 *) out, (vec_float4 *) rgba); + r->q = out[0]; + g->q = out[1]; + b->q = out[2]; + a->q = out[3]; +} + + +static void +exec_tex(struct spu_exec_machine *mach, + const struct tgsi_full_instruction *inst, + boolean biasLod, boolean projected) +{ + const uint unit = inst->Src[1].Register.Index; + union spu_exec_channel r[8]; + uint chan_index; + float lodBias; + + /* printf("Sampler %u unit %u\n", sampler, unit); */ + + switch (inst->InstructionExtTexture.Texture) { + case TGSI_TEXTURE_1D: + + FETCH(&r[0], 0, CHAN_X); + + if (projected) { + FETCH(&r[1], 0, CHAN_W); + r[0].q = micro_div(r[0].q, r[1].q); + } + + if (biasLod) { + FETCH(&r[1], 0, CHAN_W); + lodBias = r[2].f[0]; + } + else + lodBias = 0.0; + + fetch_texel(&mach->Samplers[unit], + &r[0], NULL, NULL, lodBias, /* S, T, P, BIAS */ + &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */ + break; + + case TGSI_TEXTURE_2D: + case TGSI_TEXTURE_RECT: + + FETCH(&r[0], 0, CHAN_X); + FETCH(&r[1], 0, CHAN_Y); + FETCH(&r[2], 0, CHAN_Z); + + if (projected) { + FETCH(&r[3], 0, CHAN_W); + r[0].q = micro_div(r[0].q, r[3].q); + r[1].q = micro_div(r[1].q, r[3].q); + r[2].q = micro_div(r[2].q, r[3].q); + } + + if (biasLod) { + FETCH(&r[3], 0, CHAN_W); + lodBias = r[3].f[0]; + } + else + lodBias = 0.0; + + fetch_texel(&mach->Samplers[unit], + &r[0], &r[1], &r[2], lodBias, /* inputs */ + &r[0], &r[1], &r[2], &r[3]); /* outputs */ + break; + + case TGSI_TEXTURE_3D: + case TGSI_TEXTURE_CUBE: + + FETCH(&r[0], 0, CHAN_X); + FETCH(&r[1], 0, CHAN_Y); + FETCH(&r[2], 0, CHAN_Z); + + if (projected) { + FETCH(&r[3], 0, CHAN_W); + r[0].q = micro_div(r[0].q, r[3].q); + r[1].q = micro_div(r[1].q, r[3].q); + r[2].q = micro_div(r[2].q, r[3].q); + } + + if (biasLod) { + FETCH(&r[3], 0, CHAN_W); + lodBias = r[3].f[0]; + } + else + lodBias = 0.0; + + fetch_texel(&mach->Samplers[unit], + &r[0], &r[1], &r[2], lodBias, + &r[0], &r[1], &r[2], &r[3]); + break; + + default: + ASSERT (0); + } + + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( &r[chan_index], 0, chan_index ); + } +} + + + +static void +constant_interpolation( + struct spu_exec_machine *mach, + unsigned attrib, + unsigned chan ) +{ + unsigned i; + + for( i = 0; i < QUAD_SIZE; i++ ) { + mach->Inputs[attrib].xyzw[chan].f[i] = mach->InterpCoefs[attrib].a0[chan]; + } +} + +static void +linear_interpolation( + struct spu_exec_machine *mach, + unsigned attrib, + unsigned chan ) +{ + const float x = mach->QuadPos.xyzw[0].f[0]; + const float y = mach->QuadPos.xyzw[1].f[0]; + const float dadx = mach->InterpCoefs[attrib].dadx[chan]; + const float dady = mach->InterpCoefs[attrib].dady[chan]; + const float a0 = mach->InterpCoefs[attrib].a0[chan] + dadx * x + dady * y; + mach->Inputs[attrib].xyzw[chan].f[0] = a0; + mach->Inputs[attrib].xyzw[chan].f[1] = a0 + dadx; + mach->Inputs[attrib].xyzw[chan].f[2] = a0 + dady; + mach->Inputs[attrib].xyzw[chan].f[3] = a0 + dadx + dady; +} + +static void +perspective_interpolation( + struct spu_exec_machine *mach, + unsigned attrib, + unsigned chan ) +{ + const float x = mach->QuadPos.xyzw[0].f[0]; + const float y = mach->QuadPos.xyzw[1].f[0]; + const float dadx = mach->InterpCoefs[attrib].dadx[chan]; + const float dady = mach->InterpCoefs[attrib].dady[chan]; + const float a0 = mach->InterpCoefs[attrib].a0[chan] + dadx * x + dady * y; + const float *w = mach->QuadPos.xyzw[3].f; + /* divide by W here */ + mach->Inputs[attrib].xyzw[chan].f[0] = a0 / w[0]; + mach->Inputs[attrib].xyzw[chan].f[1] = (a0 + dadx) / w[1]; + mach->Inputs[attrib].xyzw[chan].f[2] = (a0 + dady) / w[2]; + mach->Inputs[attrib].xyzw[chan].f[3] = (a0 + dadx + dady) / w[3]; +} + + +typedef void (* interpolation_func)( + struct spu_exec_machine *mach, + unsigned attrib, + unsigned chan ); + +static void +exec_declaration(struct spu_exec_machine *mach, + const struct tgsi_full_declaration *decl) +{ + if( mach->Processor == TGSI_PROCESSOR_FRAGMENT ) { + if( decl->Declaration.File == TGSI_FILE_INPUT ) { + unsigned first, last, mask; + interpolation_func interp; + + first = decl->Range.First; + last = decl->Range.Last; + mask = decl->Declaration.UsageMask; + + switch( decl->Declaration.Interpolate ) { + case TGSI_INTERPOLATE_CONSTANT: + interp = constant_interpolation; + break; + + case TGSI_INTERPOLATE_LINEAR: + interp = linear_interpolation; + break; + + case TGSI_INTERPOLATE_PERSPECTIVE: + interp = perspective_interpolation; + break; + + default: + ASSERT( 0 ); + } + + if( mask == TGSI_WRITEMASK_XYZW ) { + unsigned i, j; + + for( i = first; i <= last; i++ ) { + for( j = 0; j < NUM_CHANNELS; j++ ) { + interp( mach, i, j ); + } + } + } + else { + unsigned i, j; + + for( j = 0; j < NUM_CHANNELS; j++ ) { + if( mask & (1 << j) ) { + for( i = first; i <= last; i++ ) { + interp( mach, i, j ); + } + } + } + } + } + } +} + +static void +exec_instruction( + struct spu_exec_machine *mach, + const struct tgsi_full_instruction *inst, + int *pc ) +{ + uint chan_index; + union spu_exec_channel r[8]; + + (*pc)++; + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_ARL: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + r[0].q = si_cflts(r[0].q, 0); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_MOV: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_LIT: + if (IS_CHANNEL_ENABLED( *inst, CHAN_X )) { + STORE( &mach->Temps[TEMP_1_I].xyzw[TEMP_1_C], 0, CHAN_X ); + } + + if (IS_CHANNEL_ENABLED( *inst, CHAN_Y ) || IS_CHANNEL_ENABLED( *inst, CHAN_Z )) { + FETCH( &r[0], 0, CHAN_X ); + if (IS_CHANNEL_ENABLED( *inst, CHAN_Y )) { + r[0].q = micro_max(r[0].q, mach->Temps[TEMP_0_I].xyzw[TEMP_0_C].q); + STORE( &r[0], 0, CHAN_Y ); + } + + if (IS_CHANNEL_ENABLED( *inst, CHAN_Z )) { + FETCH( &r[1], 0, CHAN_Y ); + r[1].q = micro_max(r[1].q, mach->Temps[TEMP_0_I].xyzw[TEMP_0_C].q); + + FETCH( &r[2], 0, CHAN_W ); + r[2].q = micro_min(r[2].q, mach->Temps[TEMP_128_I].xyzw[TEMP_128_C].q); + r[2].q = micro_max(r[2].q, mach->Temps[TEMP_M128_I].xyzw[TEMP_M128_C].q); + r[1].q = micro_pow(r[1].q, r[2].q); + + /* r0 = (r0 > 0.0) ? r1 : 0.0 + */ + r[0].q = si_fcgt(r[0].q, mach->Temps[TEMP_0_I].xyzw[TEMP_0_C].q); + r[0].q = si_selb(mach->Temps[TEMP_0_I].xyzw[TEMP_0_C].q, r[1].q, + r[0].q); + STORE( &r[0], 0, CHAN_Z ); + } + } + + if (IS_CHANNEL_ENABLED( *inst, CHAN_W )) { + STORE( &mach->Temps[TEMP_1_I].xyzw[TEMP_1_C], 0, CHAN_W ); + } + break; + + case TGSI_OPCODE_RCP: + FETCH( &r[0], 0, CHAN_X ); + r[0].q = micro_div(mach->Temps[TEMP_1_I].xyzw[TEMP_1_C].q, r[0].q); + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_RSQ: + FETCH( &r[0], 0, CHAN_X ); + r[0].q = micro_sqrt(r[0].q); + r[0].q = micro_div(mach->Temps[TEMP_1_I].xyzw[TEMP_1_C].q, r[0].q); + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_EXP: + ASSERT (0); + break; + + case TGSI_OPCODE_LOG: + ASSERT (0); + break; + + case TGSI_OPCODE_MUL: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) + { + FETCH(&r[0], 0, chan_index); + FETCH(&r[1], 1, chan_index); + + r[0].q = si_fm(r[0].q, r[1].q); + + STORE(&r[0], 0, chan_index); + } + break; + + case TGSI_OPCODE_ADD: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + FETCH( &r[1], 1, chan_index ); + r[0].q = si_fa(r[0].q, r[1].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_DP3: + /* TGSI_OPCODE_DOT3 */ + FETCH( &r[0], 0, CHAN_X ); + FETCH( &r[1], 1, CHAN_X ); + r[0].q = si_fm(r[0].q, r[1].q); + + FETCH( &r[1], 0, CHAN_Y ); + FETCH( &r[2], 1, CHAN_Y ); + r[0].q = si_fma(r[1].q, r[2].q, r[0].q); + + + FETCH( &r[1], 0, CHAN_Z ); + FETCH( &r[2], 1, CHAN_Z ); + r[0].q = si_fma(r[1].q, r[2].q, r[0].q); + + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_DP4: + /* TGSI_OPCODE_DOT4 */ + FETCH(&r[0], 0, CHAN_X); + FETCH(&r[1], 1, CHAN_X); + + r[0].q = si_fm(r[0].q, r[1].q); + + FETCH(&r[1], 0, CHAN_Y); + FETCH(&r[2], 1, CHAN_Y); + + r[0].q = si_fma(r[1].q, r[2].q, r[0].q); + + FETCH(&r[1], 0, CHAN_Z); + FETCH(&r[2], 1, CHAN_Z); + + r[0].q = si_fma(r[1].q, r[2].q, r[0].q); + + FETCH(&r[1], 0, CHAN_W); + FETCH(&r[2], 1, CHAN_W); + + r[0].q = si_fma(r[1].q, r[2].q, r[0].q); + + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_DST: + if (IS_CHANNEL_ENABLED( *inst, CHAN_X )) { + STORE( &mach->Temps[TEMP_1_I].xyzw[TEMP_1_C], 0, CHAN_X ); + } + + if (IS_CHANNEL_ENABLED( *inst, CHAN_Y )) { + FETCH( &r[0], 0, CHAN_Y ); + FETCH( &r[1], 1, CHAN_Y); + r[0].q = si_fm(r[0].q, r[1].q); + STORE( &r[0], 0, CHAN_Y ); + } + + if (IS_CHANNEL_ENABLED( *inst, CHAN_Z )) { + FETCH( &r[0], 0, CHAN_Z ); + STORE( &r[0], 0, CHAN_Z ); + } + + if (IS_CHANNEL_ENABLED( *inst, CHAN_W )) { + FETCH( &r[0], 1, CHAN_W ); + STORE( &r[0], 0, CHAN_W ); + } + break; + + case TGSI_OPCODE_MIN: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH(&r[0], 0, chan_index); + FETCH(&r[1], 1, chan_index); + + r[0].q = micro_min(r[0].q, r[1].q); + + STORE(&r[0], 0, chan_index); + } + break; + + case TGSI_OPCODE_MAX: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH(&r[0], 0, chan_index); + FETCH(&r[1], 1, chan_index); + + r[0].q = micro_max(r[0].q, r[1].q); + + STORE(&r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_SLT: + /* TGSI_OPCODE_SETLT */ + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + FETCH( &r[1], 1, chan_index ); + + r[0].q = micro_ge(r[0].q, r[1].q); + r[0].q = si_xori(r[0].q, 0xff); + + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_SGE: + /* TGSI_OPCODE_SETGE */ + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + FETCH( &r[1], 1, chan_index ); + r[0].q = micro_ge(r[0].q, r[1].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_MAD: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + FETCH( &r[1], 1, chan_index ); + FETCH( &r[2], 2, chan_index ); + r[0].q = si_fma(r[0].q, r[1].q, r[2].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_SUB: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH(&r[0], 0, chan_index); + FETCH(&r[1], 1, chan_index); + + r[0].q = si_fs(r[0].q, r[1].q); + + STORE(&r[0], 0, chan_index); + } + break; + + case TGSI_OPCODE_LRP: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH(&r[0], 0, chan_index); + FETCH(&r[1], 1, chan_index); + FETCH(&r[2], 2, chan_index); + + r[1].q = si_fs(r[1].q, r[2].q); + r[0].q = si_fma(r[0].q, r[1].q, r[2].q); + + STORE(&r[0], 0, chan_index); + } + break; + + case TGSI_OPCODE_CND: + ASSERT (0); + break; + + case TGSI_OPCODE_DP2A: + ASSERT (0); + break; + + case TGSI_OPCODE_FRC: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + r[0].q = micro_frc(r[0].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_CLAMP: + ASSERT (0); + break; + + case TGSI_OPCODE_FLR: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + r[0].q = micro_flr(r[0].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_ROUND: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + r[0].q = micro_rnd(r[0].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_EX2: + FETCH(&r[0], 0, CHAN_X); + + r[0].q = micro_pow(mach->Temps[TEMP_2_I].xyzw[TEMP_2_C].q, r[0].q); + + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_LG2: + FETCH( &r[0], 0, CHAN_X ); + r[0].q = micro_lg2(r[0].q); + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_POW: + FETCH(&r[0], 0, CHAN_X); + FETCH(&r[1], 1, CHAN_X); + + r[0].q = micro_pow(r[0].q, r[1].q); + + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_XPD: + /* TGSI_OPCODE_XPD */ + FETCH(&r[0], 0, CHAN_Y); + FETCH(&r[1], 1, CHAN_Z); + FETCH(&r[3], 0, CHAN_Z); + FETCH(&r[4], 1, CHAN_Y); + + /* r2 = (r0 * r1) - (r3 * r5) + */ + r[2].q = si_fm(r[3].q, r[5].q); + r[2].q = si_fms(r[0].q, r[1].q, r[2].q); + + if (IS_CHANNEL_ENABLED( *inst, CHAN_X )) { + STORE( &r[2], 0, CHAN_X ); + } + + FETCH(&r[2], 1, CHAN_X); + FETCH(&r[5], 0, CHAN_X); + + /* r3 = (r3 * r2) - (r1 * r5) + */ + r[1].q = si_fm(r[1].q, r[5].q); + r[3].q = si_fms(r[3].q, r[2].q, r[1].q); + + if (IS_CHANNEL_ENABLED( *inst, CHAN_Y )) { + STORE( &r[3], 0, CHAN_Y ); + } + + /* r5 = (r5 * r4) - (r0 * r2) + */ + r[0].q = si_fm(r[0].q, r[2].q); + r[5].q = si_fms(r[5].q, r[4].q, r[0].q); + + if (IS_CHANNEL_ENABLED( *inst, CHAN_Z )) { + STORE( &r[5], 0, CHAN_Z ); + } + + if (IS_CHANNEL_ENABLED( *inst, CHAN_W )) { + STORE( &mach->Temps[TEMP_1_I].xyzw[TEMP_1_C], 0, CHAN_W ); + } + break; + + case TGSI_OPCODE_ABS: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH(&r[0], 0, chan_index); + + r[0].q = micro_abs(r[0].q); + + STORE(&r[0], 0, chan_index); + } + break; + + case TGSI_OPCODE_RCC: + ASSERT (0); + break; + + case TGSI_OPCODE_DPH: + FETCH(&r[0], 0, CHAN_X); + FETCH(&r[1], 1, CHAN_X); + + r[0].q = si_fm(r[0].q, r[1].q); + + FETCH(&r[1], 0, CHAN_Y); + FETCH(&r[2], 1, CHAN_Y); + + r[0].q = si_fma(r[1].q, r[2].q, r[0].q); + + FETCH(&r[1], 0, CHAN_Z); + FETCH(&r[2], 1, CHAN_Z); + + r[0].q = si_fma(r[1].q, r[2].q, r[0].q); + + FETCH(&r[1], 1, CHAN_W); + + r[0].q = si_fa(r[0].q, r[1].q); + + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_COS: + FETCH(&r[0], 0, CHAN_X); + + r[0].q = micro_cos(r[0].q); + + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_DDX: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + r[0].q = micro_ddx(r[0].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_DDY: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + r[0].q = micro_ddy(r[0].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_KILP: + exec_kilp (mach, inst); + break; + + case TGSI_OPCODE_KIL: + exec_kil (mach, inst); + break; + + case TGSI_OPCODE_PK2H: + ASSERT (0); + break; + + case TGSI_OPCODE_PK2US: + ASSERT (0); + break; + + case TGSI_OPCODE_PK4B: + ASSERT (0); + break; + + case TGSI_OPCODE_PK4UB: + ASSERT (0); + break; + + case TGSI_OPCODE_RFL: + ASSERT (0); + break; + + case TGSI_OPCODE_SEQ: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + FETCH( &r[1], 1, chan_index ); + + r[0].q = si_fceq(r[0].q, r[1].q); + + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_SFL: + ASSERT (0); + break; + + case TGSI_OPCODE_SGT: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + FETCH( &r[1], 1, chan_index ); + r[0].q = si_fcgt(r[0].q, r[1].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_SIN: + FETCH( &r[0], 0, CHAN_X ); + r[0].q = micro_sin(r[0].q); + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_SLE: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + FETCH( &r[1], 1, chan_index ); + + r[0].q = si_fcgt(r[0].q, r[1].q); + r[0].q = si_xori(r[0].q, 0xff); + + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_SNE: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + FETCH( &r[1], 1, chan_index ); + + r[0].q = si_fceq(r[0].q, r[1].q); + r[0].q = si_xori(r[0].q, 0xff); + + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_STR: + ASSERT (0); + break; + + case TGSI_OPCODE_TEX: + /* simple texture lookup */ + /* src[0] = texcoord */ + /* src[1] = sampler unit */ + exec_tex(mach, inst, FALSE, FALSE); + break; + + case TGSI_OPCODE_TXB: + /* Texture lookup with lod bias */ + /* src[0] = texcoord (src[0].w = load bias) */ + /* src[1] = sampler unit */ + exec_tex(mach, inst, TRUE, FALSE); + break; + + case TGSI_OPCODE_TXD: + /* Texture lookup with explict partial derivatives */ + /* src[0] = texcoord */ + /* src[1] = d[strq]/dx */ + /* src[2] = d[strq]/dy */ + /* src[3] = sampler unit */ + ASSERT (0); + break; + + case TGSI_OPCODE_TXL: + /* Texture lookup with explit LOD */ + /* src[0] = texcoord (src[0].w = load bias) */ + /* src[1] = sampler unit */ + exec_tex(mach, inst, TRUE, FALSE); + break; + + case TGSI_OPCODE_TXP: + /* Texture lookup with projection */ + /* src[0] = texcoord (src[0].w = projection) */ + /* src[1] = sampler unit */ + exec_tex(mach, inst, TRUE, TRUE); + break; + + case TGSI_OPCODE_UP2H: + ASSERT (0); + break; + + case TGSI_OPCODE_UP2US: + ASSERT (0); + break; + + case TGSI_OPCODE_UP4B: + ASSERT (0); + break; + + case TGSI_OPCODE_UP4UB: + ASSERT (0); + break; + + case TGSI_OPCODE_X2D: + ASSERT (0); + break; + + case TGSI_OPCODE_ARA: + ASSERT (0); + break; + + case TGSI_OPCODE_ARR: + ASSERT (0); + break; + + case TGSI_OPCODE_BRA: + ASSERT (0); + break; + + case TGSI_OPCODE_CAL: + /* skip the call if no execution channels are enabled */ + if (mach->ExecMask) { + /* do the call */ + + /* push the Cond, Loop, Cont stacks */ + ASSERT(mach->CondStackTop < TGSI_EXEC_MAX_COND_NESTING); + mach->CondStack[mach->CondStackTop++] = mach->CondMask; + ASSERT(mach->LoopStackTop < TGSI_EXEC_MAX_LOOP_NESTING); + mach->LoopStack[mach->LoopStackTop++] = mach->LoopMask; + ASSERT(mach->ContStackTop < TGSI_EXEC_MAX_LOOP_NESTING); + mach->ContStack[mach->ContStackTop++] = mach->ContMask; + + ASSERT(mach->FuncStackTop < TGSI_EXEC_MAX_CALL_NESTING); + mach->FuncStack[mach->FuncStackTop++] = mach->FuncMask; + + /* note that PC was already incremented above */ + mach->CallStack[mach->CallStackTop++] = *pc; + *pc = inst->InstructionExtLabel.Label; + } + break; + + case TGSI_OPCODE_RET: + mach->FuncMask &= ~mach->ExecMask; + UPDATE_EXEC_MASK(mach); + + if (mach->ExecMask == 0x0) { + /* really return now (otherwise, keep executing */ + + if (mach->CallStackTop == 0) { + /* returning from main() */ + *pc = -1; + return; + } + *pc = mach->CallStack[--mach->CallStackTop]; + + /* pop the Cond, Loop, Cont stacks */ + ASSERT(mach->CondStackTop > 0); + mach->CondMask = mach->CondStack[--mach->CondStackTop]; + ASSERT(mach->LoopStackTop > 0); + mach->LoopMask = mach->LoopStack[--mach->LoopStackTop]; + ASSERT(mach->ContStackTop > 0); + mach->ContMask = mach->ContStack[--mach->ContStackTop]; + ASSERT(mach->FuncStackTop > 0); + mach->FuncMask = mach->FuncStack[--mach->FuncStackTop]; + + UPDATE_EXEC_MASK(mach); + } + break; + + case TGSI_OPCODE_SSG: + ASSERT (0); + break; + + case TGSI_OPCODE_CMP: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH(&r[0], 0, chan_index); + FETCH(&r[1], 1, chan_index); + FETCH(&r[2], 2, chan_index); + + /* r0 = (r0 < 0.0) ? r1 : r2 + */ + r[3].q = si_xor(r[3].q, r[3].q); + r[0].q = micro_lt(r[0].q, r[3].q); + r[0].q = si_selb(r[1].q, r[2].q, r[0].q); + + STORE(&r[0], 0, chan_index); + } + break; + + case TGSI_OPCODE_SCS: + if( IS_CHANNEL_ENABLED( *inst, CHAN_X ) || IS_CHANNEL_ENABLED( *inst, CHAN_Y ) ) { + FETCH( &r[0], 0, CHAN_X ); + } + if( IS_CHANNEL_ENABLED( *inst, CHAN_X ) ) { + r[1].q = micro_cos(r[0].q); + STORE( &r[1], 0, CHAN_X ); + } + if( IS_CHANNEL_ENABLED( *inst, CHAN_Y ) ) { + r[1].q = micro_sin(r[0].q); + STORE( &r[1], 0, CHAN_Y ); + } + if( IS_CHANNEL_ENABLED( *inst, CHAN_Z ) ) { + STORE( &mach->Temps[TEMP_0_I].xyzw[TEMP_0_C], 0, CHAN_Z ); + } + if( IS_CHANNEL_ENABLED( *inst, CHAN_W ) ) { + STORE( &mach->Temps[TEMP_1_I].xyzw[TEMP_1_C], 0, CHAN_W ); + } + break; + + case TGSI_OPCODE_NRM: + ASSERT (0); + break; + + case TGSI_OPCODE_DIV: + ASSERT( 0 ); + break; + + case TGSI_OPCODE_DP2: + FETCH( &r[0], 0, CHAN_X ); + FETCH( &r[1], 1, CHAN_X ); + r[0].q = si_fm(r[0].q, r[1].q); + + FETCH( &r[1], 0, CHAN_Y ); + FETCH( &r[2], 1, CHAN_Y ); + r[0].q = si_fma(r[1].q, r[2].q, r[0].q); + + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_IF: + /* push CondMask */ + ASSERT(mach->CondStackTop < TGSI_EXEC_MAX_COND_NESTING); + mach->CondStack[mach->CondStackTop++] = mach->CondMask; + FETCH( &r[0], 0, CHAN_X ); + /* update CondMask */ + if( ! r[0].u[0] ) { + mach->CondMask &= ~0x1; + } + if( ! r[0].u[1] ) { + mach->CondMask &= ~0x2; + } + if( ! r[0].u[2] ) { + mach->CondMask &= ~0x4; + } + if( ! r[0].u[3] ) { + mach->CondMask &= ~0x8; + } + UPDATE_EXEC_MASK(mach); + /* Todo: If CondMask==0, jump to ELSE */ + break; + + case TGSI_OPCODE_ELSE: + /* invert CondMask wrt previous mask */ + { + uint prevMask; + ASSERT(mach->CondStackTop > 0); + prevMask = mach->CondStack[mach->CondStackTop - 1]; + mach->CondMask = ~mach->CondMask & prevMask; + UPDATE_EXEC_MASK(mach); + /* Todo: If CondMask==0, jump to ENDIF */ + } + break; + + case TGSI_OPCODE_ENDIF: + /* pop CondMask */ + ASSERT(mach->CondStackTop > 0); + mach->CondMask = mach->CondStack[--mach->CondStackTop]; + UPDATE_EXEC_MASK(mach); + break; + + case TGSI_OPCODE_END: + /* halt execution */ + *pc = -1; + break; + + case TGSI_OPCODE_PUSHA: + ASSERT (0); + break; + + case TGSI_OPCODE_POPA: + ASSERT (0); + break; + + case TGSI_OPCODE_CEIL: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + r[0].q = micro_ceil(r[0].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_I2F: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + r[0].q = si_csflt(r[0].q, 0); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_NOT: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + r[0].q = si_xorbi(r[0].q, 0xff); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_TRUNC: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + r[0].q = micro_trunc(r[0].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_SHL: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + FETCH( &r[1], 1, chan_index ); + + r[0].q = si_shl(r[0].q, r[1].q); + + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_ISHR: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + FETCH( &r[1], 1, chan_index ); + r[0].q = micro_ishr(r[0].q, r[1].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_AND: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + FETCH( &r[1], 1, chan_index ); + r[0].q = si_and(r[0].q, r[1].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_OR: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + FETCH( &r[1], 1, chan_index ); + r[0].q = si_or(r[0].q, r[1].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_MOD: + ASSERT (0); + break; + + case TGSI_OPCODE_XOR: + FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { + FETCH( &r[0], 0, chan_index ); + FETCH( &r[1], 1, chan_index ); + r[0].q = si_xor(r[0].q, r[1].q); + STORE( &r[0], 0, chan_index ); + } + break; + + case TGSI_OPCODE_SAD: + ASSERT (0); + break; + + case TGSI_OPCODE_TXF: + ASSERT (0); + break; + + case TGSI_OPCODE_TXQ: + ASSERT (0); + break; + + case TGSI_OPCODE_EMIT: + mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0] += 16; + mach->Primitives[mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0]]++; + break; + + case TGSI_OPCODE_ENDPRIM: + mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0]++; + mach->Primitives[mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0]] = 0; + break; + + case TGSI_OPCODE_BGNLOOP: + /* push LoopMask and ContMasks */ + ASSERT(mach->LoopStackTop < TGSI_EXEC_MAX_LOOP_NESTING); + mach->LoopStack[mach->LoopStackTop++] = mach->LoopMask; + ASSERT(mach->ContStackTop < TGSI_EXEC_MAX_LOOP_NESTING); + mach->ContStack[mach->ContStackTop++] = mach->ContMask; + break; + + case TGSI_OPCODE_ENDLOOP: + /* Restore ContMask, but don't pop */ + ASSERT(mach->ContStackTop > 0); + mach->ContMask = mach->ContStack[mach->ContStackTop - 1]; + if (mach->LoopMask) { + /* repeat loop: jump to instruction just past BGNLOOP */ + *pc = inst->InstructionExtLabel.Label + 1; + } + else { + /* exit loop: pop LoopMask */ + ASSERT(mach->LoopStackTop > 0); + mach->LoopMask = mach->LoopStack[--mach->LoopStackTop]; + /* pop ContMask */ + ASSERT(mach->ContStackTop > 0); + mach->ContMask = mach->ContStack[--mach->ContStackTop]; + } + UPDATE_EXEC_MASK(mach); + break; + + case TGSI_OPCODE_BRK: + /* turn off loop channels for each enabled exec channel */ + mach->LoopMask &= ~mach->ExecMask; + /* Todo: if mach->LoopMask == 0, jump to end of loop */ + UPDATE_EXEC_MASK(mach); + break; + + case TGSI_OPCODE_CONT: + /* turn off cont channels for each enabled exec channel */ + mach->ContMask &= ~mach->ExecMask; + /* Todo: if mach->LoopMask == 0, jump to end of loop */ + UPDATE_EXEC_MASK(mach); + break; + + case TGSI_OPCODE_BGNSUB: + /* no-op */ + break; + + case TGSI_OPCODE_ENDSUB: + /* no-op */ + break; + + case TGSI_OPCODE_NOP: + break; + + default: + ASSERT( 0 ); + } +} + + +/** + * Run TGSI interpreter. + * \return bitmask of "alive" quad components + */ +uint +spu_exec_machine_run( struct spu_exec_machine *mach ) +{ + uint i; + int pc = 0; + + mach->CondMask = 0xf; + mach->LoopMask = 0xf; + mach->ContMask = 0xf; + mach->FuncMask = 0xf; + mach->ExecMask = 0xf; + + mach->CondStackTop = 0; /* temporarily subvert this ASSERTion */ + ASSERT(mach->CondStackTop == 0); + ASSERT(mach->LoopStackTop == 0); + ASSERT(mach->ContStackTop == 0); + ASSERT(mach->CallStackTop == 0); + + mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0] = 0; + mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0] = 0; + + if( mach->Processor == TGSI_PROCESSOR_GEOMETRY ) { + mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0] = 0; + mach->Primitives[0] = 0; + } + + + /* execute declarations (interpolants) */ + if( mach->Processor == TGSI_PROCESSOR_FRAGMENT ) { + for (i = 0; i < mach->NumDeclarations; i++) { + PIPE_ALIGN_VAR(16) + union { + struct tgsi_full_declaration decl; + qword buffer[ROUNDUP16(sizeof(struct tgsi_full_declaration)) / 16]; + } d; + unsigned ea = (unsigned) (mach->Declarations + pc); + + spu_dcache_fetch_unaligned(d.buffer, ea, sizeof(d.decl)); + + exec_declaration( mach, &d.decl ); + } + } + + /* execute instructions, until pc is set to -1 */ + while (pc != -1) { + PIPE_ALIGN_VAR(16) + union { + struct tgsi_full_instruction inst; + qword buffer[ROUNDUP16(sizeof(struct tgsi_full_instruction)) / 16]; + } i; + unsigned ea = (unsigned) (mach->Instructions + pc); + + spu_dcache_fetch_unaligned(i.buffer, ea, sizeof(i.inst)); + exec_instruction( mach, & i.inst, &pc ); + } + +#if 0 + /* we scale from floats in [0,1] to Zbuffer ints in sp_quad_depth_test.c */ + if (mach->Processor == TGSI_PROCESSOR_FRAGMENT) { + /* + * Scale back depth component. + */ + for (i = 0; i < 4; i++) + mach->Outputs[0].xyzw[2].f[i] *= ctx->DrawBuffer->_DepthMaxF; + } +#endif + + return ~mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0]; +} + + diff --git a/src/gallium/drivers/cell/spu/spu_exec.h b/src/gallium/drivers/cell/spu/spu_exec.h new file mode 100644 index 0000000..68f4479 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_exec.h @@ -0,0 +1,173 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#if !defined SPU_EXEC_H +#define SPU_EXEC_H + +#include "pipe/p_compiler.h" + +#include "spu_tgsi_exec.h" + +#if defined __cplusplus +extern "C" { +#endif + +/** + * Registers may be treated as float, signed int or unsigned int. + */ +union spu_exec_channel +{ + float f[QUAD_SIZE]; + int i[QUAD_SIZE]; + unsigned u[QUAD_SIZE]; + qword q; +}; + +/** + * A vector[RGBA] of channels[4 pixels] + */ +struct spu_exec_vector +{ + union spu_exec_channel xyzw[NUM_CHANNELS]; +}; + +/** + * For fragment programs, information for computing fragment input + * values from plane equation of the triangle/line. + */ +struct spu_interp_coef +{ + float a0[NUM_CHANNELS]; /* in an xyzw layout */ + float dadx[NUM_CHANNELS]; + float dady[NUM_CHANNELS]; +}; + + +struct softpipe_tile_cache; /**< Opaque to TGSI */ + +/** + * Information for sampling textures, which must be implemented + * by code outside the TGSI executor. + */ +struct spu_sampler +{ + const struct pipe_sampler_state *state; + struct pipe_resource *texture; + /** Get samples for four fragments in a quad */ + void (*get_samples)(struct spu_sampler *sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + float lodbias, + float rgba[NUM_CHANNELS][QUAD_SIZE]); + void *pipe; /*XXX temporary*/ + struct softpipe_tile_cache *cache; +}; + + +/** + * Run-time virtual machine state for executing TGSI shader. + */ +struct spu_exec_machine +{ + /* + * 32 program temporaries + * 4 internal temporaries + * 1 address + */ + PIPE_ALIGN_VAR(16) + struct spu_exec_vector Temps[TGSI_EXEC_NUM_TEMPS + + TGSI_EXEC_NUM_TEMP_EXTRAS + 1]; + + struct spu_exec_vector *Addrs; + + struct spu_sampler *Samplers; + + float Imms[TGSI_EXEC_NUM_IMMEDIATES][4]; + unsigned ImmLimit; + float (*Consts)[4]; + struct spu_exec_vector *Inputs; + struct spu_exec_vector *Outputs; + unsigned Processor; + + /* GEOMETRY processor only. */ + unsigned *Primitives; + + /* FRAGMENT processor only. */ + const struct spu_interp_coef *InterpCoefs; + struct spu_exec_vector QuadPos; + + /* Conditional execution masks */ + uint CondMask; /**< For IF/ELSE/ENDIF */ + uint LoopMask; /**< For BGNLOOP/ENDLOOP */ + uint ContMask; /**< For loop CONT statements */ + uint FuncMask; /**< For function calls */ + uint ExecMask; /**< = CondMask & LoopMask */ + + /** Condition mask stack (for nested conditionals) */ + uint CondStack[TGSI_EXEC_MAX_COND_NESTING]; + int CondStackTop; + + /** Loop mask stack (for nested loops) */ + uint LoopStack[TGSI_EXEC_MAX_LOOP_NESTING]; + int LoopStackTop; + + /** Loop continue mask stack (see comments in tgsi_exec.c) */ + uint ContStack[TGSI_EXEC_MAX_LOOP_NESTING]; + int ContStackTop; + + /** Function execution mask stack (for executing subroutine code) */ + uint FuncStack[TGSI_EXEC_MAX_CALL_NESTING]; + int FuncStackTop; + + /** Function call stack for saving/restoring the program counter */ + uint CallStack[TGSI_EXEC_MAX_CALL_NESTING]; + int CallStackTop; + + struct tgsi_full_instruction *Instructions; + uint NumInstructions; + + struct tgsi_full_declaration *Declarations; + uint NumDeclarations; +}; + + +extern void +spu_exec_machine_init(struct spu_exec_machine *mach, + uint numSamplers, + struct spu_sampler *samplers, + unsigned processor); + +extern uint +spu_exec_machine_run( struct spu_exec_machine *mach ); + + +#if defined __cplusplus +} /* extern "C" */ +#endif + +#endif /* SPU_EXEC_H */ diff --git a/src/gallium/drivers/cell/spu/spu_funcs.c b/src/gallium/drivers/cell/spu/spu_funcs.c new file mode 100644 index 0000000..98919c4 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_funcs.c @@ -0,0 +1,173 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * SPU functions accessed by shaders. + * + * Authors: Brian Paul + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cell/common.h" +#include "spu_main.h" +#include "spu_funcs.h" +#include "spu_texture.h" + + +/** For "return"-ing four vectors */ +struct vec_4x4 +{ + vector float v[4]; +}; + + +static vector float +spu_cos(vector float x) +{ + return _cos14_v(x); +} + +static vector float +spu_sin(vector float x) +{ + return _sin14_v(x); +} + +static vector float +spu_pow(vector float x, vector float y) +{ + return _powf4(x, y); +} + +static vector float +spu_exp2(vector float x) +{ + return _exp2f4(x); +} + +static vector float +spu_log2(vector float x) +{ + return _log2f4(x); +} + + +static struct vec_4x4 +spu_tex_2d(vector float s, vector float t, vector float r, vector float q, + unsigned unit) +{ + struct vec_4x4 colors; + (void) r; + (void) q; + spu.sample_texture_2d[unit](s, t, unit, 0, 0, colors.v); + return colors; +} + +static struct vec_4x4 +spu_tex_3d(vector float s, vector float t, vector float r, vector float q, + unsigned unit) +{ + struct vec_4x4 colors; + (void) r; + (void) q; + spu.sample_texture_2d[unit](s, t, unit, 0, 0, colors.v); + return colors; +} + +static struct vec_4x4 +spu_tex_cube(vector float s, vector float t, vector float r, vector float q, + unsigned unit) +{ + struct vec_4x4 colors; + (void) q; + sample_texture_cube(s, t, r, unit, colors.v); + return colors; +} + + +/** + * Add named function to list of "exported" functions that will be + * made available to the PPU-hosted code generator. + */ +static void +export_func(struct cell_spu_function_info *spu_functions, + const char *name, void *addr) +{ + uint n = spu_functions->num; + ASSERT(strlen(name) < 16); + strcpy(spu_functions->names[n], name); + spu_functions->addrs[n] = (uint) addr; + spu_functions->num++; + ASSERT(spu_functions->num <= 16); +} + + +/** + * Return info about the SPU's function to the PPU / main memory. + * The PPU needs to know the address of some SPU-side functions so + * that we can generate shader code with function calls. + */ +void +return_function_info(void) +{ + PIPE_ALIGN_VAR(16) struct cell_spu_function_info funcs; + int tag = TAG_MISC; + + ASSERT(sizeof(funcs) == 256); /* must be multiple of 16 bytes */ + + funcs.num = 0; + export_func(&funcs, "spu_cos", &spu_cos); + export_func(&funcs, "spu_sin", &spu_sin); + export_func(&funcs, "spu_pow", &spu_pow); + export_func(&funcs, "spu_exp2", &spu_exp2); + export_func(&funcs, "spu_log2", &spu_log2); + export_func(&funcs, "spu_tex_2d", &spu_tex_2d); + export_func(&funcs, "spu_tex_3d", &spu_tex_3d); + export_func(&funcs, "spu_tex_cube", &spu_tex_cube); + + /* Send the function info back to the PPU / main memory */ + mfc_put((void *) &funcs, /* src in local store */ + (unsigned int) spu.init.spu_functions, /* dst in main memory */ + sizeof(funcs), /* bytes */ + tag, + 0, /* tid */ + 0 /* rid */); + wait_on_mask(1 << tag); +} + + + diff --git a/src/gallium/drivers/cell/spu/spu_funcs.h b/src/gallium/drivers/cell/spu/spu_funcs.h new file mode 100644 index 0000000..3adb6ae --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_funcs.h @@ -0,0 +1,35 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef SPU_FUNCS_H +#define SPU_FUNCS_H + +extern void +return_function_info(void); + +#endif + diff --git a/src/gallium/drivers/cell/spu/spu_main.c b/src/gallium/drivers/cell/spu/spu_main.c new file mode 100644 index 0000000..97c86d1 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_main.c @@ -0,0 +1,117 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/* main() for Cell SPU code */ + + +#include +#include + +#include "pipe/p_defines.h" + +#include "spu_funcs.h" +#include "spu_command.h" +#include "spu_main.h" +#include "spu_per_fragment_op.h" +#include "spu_texture.h" +//#include "spu_test.h" +#include "cell/common.h" + + +/* +helpful headers: +/usr/lib/gcc/spu/4.1.1/include/spu_mfcio.h +/opt/cell/sdk/usr/include/libmisc.h +*/ + +struct spu_global spu; + + +static void +one_time_init(void) +{ + memset(spu.ctile_status, TILE_STATUS_DEFINED, sizeof(spu.ctile_status)); + memset(spu.ztile_status, TILE_STATUS_DEFINED, sizeof(spu.ztile_status)); + invalidate_tex_cache(); +} + +/* In some versions of the SDK the SPE main takes 'unsigned long' as a + * parameter. In others it takes 'unsigned long long'. Use a define to + * select between the two. + */ +#ifdef SPU_MAIN_PARAM_LONG_LONG +typedef unsigned long long main_param_t; +#else +typedef unsigned long main_param_t; +#endif + +/** + * SPE entrypoint. + */ +int +main(main_param_t speid, main_param_t argp) +{ + int tag = 0; + + (void) speid; + + ASSERT(sizeof(tile_t) == TILE_SIZE * TILE_SIZE * 4); + ASSERT(sizeof(struct cell_command_render) % 8 == 0); + ASSERT(sizeof(struct cell_command_fragment_ops) % 8 == 0); + ASSERT(((unsigned long) &spu.fragment_program_code) % 8 == 0); + + one_time_init(); + spu_command_init(); + + D_PRINTF(CELL_DEBUG_CMD, "main() speid=%lu\n", (unsigned long) speid); + D_PRINTF(CELL_DEBUG_FRAGMENT_OP_FALLBACK, "using fragment op fallback\n"); + + /* get initialization data */ + mfc_get(&spu.init, /* dest */ + (unsigned int) argp, /* src */ + sizeof(struct cell_init_info), /* bytes */ + tag, + 0, /* tid */ + 0 /* rid */); + wait_on_mask( 1 << tag ); + + if (spu.init.id == 0) { + return_function_info(); + } + +#if 0 + if (spu.init.id==0) + spu_test_misc(spu.init.id); +#endif + + command_loop(); + + spu_command_close(); + + return 0; +} diff --git a/src/gallium/drivers/cell/spu/spu_main.h b/src/gallium/drivers/cell/spu/spu_main.h new file mode 100644 index 0000000..a9d72f8 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_main.h @@ -0,0 +1,269 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef SPU_MAIN_H +#define SPU_MAIN_H + + +#include + +#include "cell/common.h" +#include "draw/draw_vertex.h" +#include "pipe/p_state.h" + + +#if DEBUG +/* These debug macros use the unusual construction ", ##__VA_ARGS__" + * which expands to the expected comma + args if variadic arguments + * are supplied, but swallows the comma if there are no variadic + * arguments (which avoids syntax errors that would otherwise occur). + */ +#define D_PRINTF(flag, format,...) \ + if (spu.init.debug_flags & (flag)) \ + printf("SPU %u: " format, spu.init.id, ##__VA_ARGS__) +#else +#define D_PRINTF(...) +#endif + + +/** + * A tile is basically a TILE_SIZE x TILE_SIZE block of 4-byte pixels. + * The data may be addressed through several different types. + */ +typedef union { + ushort us[TILE_SIZE][TILE_SIZE]; + uint ui[TILE_SIZE][TILE_SIZE]; + vector unsigned short us8[TILE_SIZE/2][TILE_SIZE/4]; + vector unsigned int ui4[TILE_SIZE/2][TILE_SIZE/2]; +} tile_t; + + +#define TILE_STATUS_CLEAR 1 +#define TILE_STATUS_DEFINED 2 /**< defined in FB, but not in local store */ +#define TILE_STATUS_CLEAN 3 /**< in local store, but not changed */ +#define TILE_STATUS_DIRTY 4 /**< modified locally, but not put back yet */ +#define TILE_STATUS_GETTING 5 /**< mfc_get() called but not yet arrived */ + + +/** Function for sampling textures */ +typedef void (*spu_sample_texture_2d_func)(vector float s, + vector float t, + uint unit, uint level, uint face, + vector float colors[4]); + + +/** Function for performing per-fragment ops */ +typedef void (*spu_fragment_ops_func)(uint x, uint y, + tile_t *colorTile, + tile_t *depthStencilTile, + vector float fragZ, + vector float fragRed, + vector float fragGreen, + vector float fragBlue, + vector float fragAlpha, + vector unsigned int mask); + +/** Function for running fragment program */ +typedef vector unsigned int (*spu_fragment_program_func)(vector float *inputs, + vector float *outputs, + vector float *constants); + + +PIPE_ALIGN_TYPE(16, +struct spu_framebuffer +{ + void *color_start; /**< addr of color surface in main memory */ + void *depth_start; /**< addr of depth surface in main memory */ + enum pipe_format color_format; + enum pipe_format depth_format; + uint width; /**< width in pixels */ + uint height; /**< height in pixels */ + uint width_tiles; /**< width in tiles */ + uint height_tiles; /**< width in tiles */ + + uint color_clear_value; + uint depth_clear_value; + + uint zsize; /**< 0, 2 or 4 bytes per Z */ + float zscale; /**< 65535.0, 2^24-1 or 2^32-1 */ +}); + + +/** per-texture level info */ +PIPE_ALIGN_TYPE(16, +struct spu_texture_level +{ + void *start; + ushort width; + ushort height; + ushort depth; + ushort tiles_per_row; + uint bytes_per_image; + /** texcoord scale factors */ + vector float scale_s; + vector float scale_t; + vector float scale_r; + /** texcoord masks (if REPEAT then size-1, else ~0) */ + vector signed int mask_s; + vector signed int mask_t; + vector signed int mask_r; + /** texcoord clamp limits */ + vector signed int max_s; + vector signed int max_t; + vector signed int max_r; +}); + + +PIPE_ALIGN_TYPE(16, +struct spu_texture +{ + struct spu_texture_level level[CELL_MAX_TEXTURE_LEVELS]; + uint max_level; + uint target; /**< PIPE_TEXTURE_x */ +}); + + +/** + * All SPU global/context state will be in a singleton object of this type: + */ +PIPE_ALIGN_TYPE(16, +struct spu_global +{ + /** One-time init/constant info */ + struct cell_init_info init; + + /* + * Current state + */ + struct spu_framebuffer fb; + struct pipe_depth_stencil_alpha_state depth_stencil_alpha; + struct pipe_blend_state blend; + struct pipe_blend_color blend_color; + struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS]; + struct pipe_rasterizer_state rasterizer; + struct spu_texture texture[PIPE_MAX_SAMPLERS]; + struct vertex_info vertex_info; + + /** Current color and Z tiles */ + PIPE_ALIGN_VAR(16) tile_t ctile; + PIPE_ALIGN_VAR(16) tile_t ztile; + + /** Read depth/stencil tiles? */ + boolean read_depth_stencil; + + /** Current tiles' status */ + ubyte cur_ctile_status; + ubyte cur_ztile_status; + + /** Status of all tiles in framebuffer */ + PIPE_ALIGN_VAR(16) ubyte ctile_status[CELL_MAX_HEIGHT/TILE_SIZE][CELL_MAX_WIDTH/TILE_SIZE]; + PIPE_ALIGN_VAR(16) ubyte ztile_status[CELL_MAX_HEIGHT/TILE_SIZE][CELL_MAX_WIDTH/TILE_SIZE]; + + /** Current fragment ops machine code, at 8-byte boundary */ + uint *fragment_ops_code; + uint fragment_ops_code_size; + /** Current fragment ops functions, 0 = frontfacing, 1 = backfacing */ + spu_fragment_ops_func fragment_ops[2]; + + /** Current fragment program machine code, at 8-byte boundary */ + PIPE_ALIGN_VAR(8) uint fragment_program_code[SPU_MAX_FRAGMENT_PROGRAM_INSTS]; + /** Current fragment ops function */ + spu_fragment_program_func fragment_program; + + /** Current texture sampler function */ + spu_sample_texture_2d_func sample_texture_2d[CELL_MAX_SAMPLERS]; + spu_sample_texture_2d_func min_sample_texture_2d[CELL_MAX_SAMPLERS]; + spu_sample_texture_2d_func mag_sample_texture_2d[CELL_MAX_SAMPLERS]; + + /** Fragment program constants */ + vector float constants[4 * CELL_MAX_CONSTANTS]; + +}); + + +extern struct spu_global spu; + + + +/* DMA TAGS */ + +#define TAG_SURFACE_CLEAR 10 +#define TAG_VERTEX_BUFFER 11 +#define TAG_READ_TILE_COLOR 12 +#define TAG_READ_TILE_Z 13 +#define TAG_WRITE_TILE_COLOR 14 +#define TAG_WRITE_TILE_Z 15 +#define TAG_INDEX_BUFFER 16 +#define TAG_BATCH_BUFFER 17 +#define TAG_MISC 18 +#define TAG_DCACHE0 20 +#define TAG_DCACHE1 21 +#define TAG_DCACHE2 22 +#define TAG_DCACHE3 23 +#define TAG_FENCE 24 + + +static INLINE void +wait_on_mask(unsigned tagMask) +{ + mfc_write_tag_mask( tagMask ); + /* wait for completion of _any_ DMAs specified by tagMask */ + mfc_read_tag_status_any(); +} + + +static INLINE void +wait_on_mask_all(unsigned tagMask) +{ + mfc_write_tag_mask( tagMask ); + /* wait for completion of _any_ DMAs specified by tagMask */ + mfc_read_tag_status_all(); +} + + + + + +static INLINE void +memset16(ushort *d, ushort value, uint count) +{ + uint i; + for (i = 0; i < count; i++) + d[i] = value; +} + + +static INLINE void +memset32(uint *d, uint value, uint count) +{ + uint i; + for (i = 0; i < count; i++) + d[i] = value; +} + + +#endif /* SPU_MAIN_H */ diff --git a/src/gallium/drivers/cell/spu/spu_per_fragment_op.c b/src/gallium/drivers/cell/spu/spu_per_fragment_op.c new file mode 100644 index 0000000..3b95660 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_per_fragment_op.c @@ -0,0 +1,631 @@ +/************************************************************************** + * + * 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 Brian Paul + */ + + +#include +#include "pipe/p_format.h" +#include "spu_main.h" +#include "spu_colorpack.h" +#include "spu_per_fragment_op.h" + + +#define LINEAR_QUAD_LAYOUT 1 + + +static INLINE vector float +spu_min(vector float a, vector float b) +{ + vector unsigned int m; + m = spu_cmpgt(a, b); /* m = a > b ? ~0 : 0 */ + return spu_sel(a, b, m); +} + + +static INLINE vector float +spu_max(vector float a, vector float b) +{ + vector unsigned int m; + m = spu_cmpgt(a, b); /* m = a > b ? ~0 : 0 */ + return spu_sel(b, a, m); +} + + +/** + * Called by rasterizer for each quad after the shader has run. Do + * all the per-fragment operations including alpha test, z test, + * stencil test, blend, colormask and logicops. This is a + * fallback/debug function. In reality we'll use a generated function + * produced by the PPU. But this function is useful for + * debug/validation. + */ +void +spu_fallback_fragment_ops(uint x, uint y, + tile_t *colorTile, + tile_t *depthStencilTile, + vector float fragZ, + vector float fragR, + vector float fragG, + vector float fragB, + vector float fragA, + vector unsigned int mask) +{ + vector float frag_aos[4]; + unsigned int fbc0, fbc1, fbc2, fbc3 ; /* framebuffer/tile colors */ + unsigned int fragc0, fragc1, fragc2, fragc3; /* fragment colors */ + + /* + * Do alpha test + */ + if (spu.depth_stencil_alpha.alpha.enabled) { + vector float ref = spu_splats(spu.depth_stencil_alpha.alpha.ref_value); + vector unsigned int amask; + + switch (spu.depth_stencil_alpha.alpha.func) { + case PIPE_FUNC_LESS: + amask = spu_cmpgt(ref, fragA); /* mask = (fragA < ref) */ + break; + case PIPE_FUNC_GREATER: + amask = spu_cmpgt(fragA, ref); /* mask = (fragA > ref) */ + break; + case PIPE_FUNC_GEQUAL: + amask = spu_cmpgt(ref, fragA); + amask = spu_nor(amask, amask); + break; + case PIPE_FUNC_LEQUAL: + amask = spu_cmpgt(fragA, ref); + amask = spu_nor(amask, amask); + break; + case PIPE_FUNC_EQUAL: + amask = spu_cmpeq(ref, fragA); + break; + case PIPE_FUNC_NOTEQUAL: + amask = spu_cmpeq(ref, fragA); + amask = spu_nor(amask, amask); + break; + case PIPE_FUNC_ALWAYS: + amask = spu_splats(0xffffffffU); + break; + case PIPE_FUNC_NEVER: + amask = spu_splats( 0x0U); + break; + default: + ; + } + + mask = spu_and(mask, amask); + } + + + /* + * Z and/or stencil testing... + */ + if (spu.depth_stencil_alpha.depth.enabled || + spu.depth_stencil_alpha.stencil[0].enabled) { + + /* get four Z/Stencil values from tile */ + vector unsigned int mask24 = spu_splats((unsigned int)0x00ffffffU); + vector unsigned int ifbZS = depthStencilTile->ui4[y/2][x/2]; + vector unsigned int ifbZ = spu_and(ifbZS, mask24); + vector unsigned int ifbS = spu_andc(ifbZS, mask24); + + if (spu.depth_stencil_alpha.stencil[0].enabled) { + /* do stencil test */ + ASSERT(spu.fb.depth_format == PIPE_FORMAT_Z24_UNORM_S8_USCALED); + + } + else if (spu.depth_stencil_alpha.depth.enabled) { + /* do depth test */ + + ASSERT(spu.fb.depth_format == PIPE_FORMAT_Z24_UNORM_S8_USCALED || + spu.fb.depth_format == PIPE_FORMAT_Z24X8_UNORM); + + vector unsigned int ifragZ; + vector unsigned int zmask; + + /* convert four fragZ from float to uint */ + fragZ = spu_mul(fragZ, spu_splats((float) 0xffffff)); + ifragZ = spu_convtu(fragZ, 0); + + /* do depth comparison, setting zmask with results */ + switch (spu.depth_stencil_alpha.depth.func) { + case PIPE_FUNC_LESS: + zmask = spu_cmpgt(ifbZ, ifragZ); /* mask = (ifragZ < ifbZ) */ + break; + case PIPE_FUNC_GREATER: + zmask = spu_cmpgt(ifragZ, ifbZ); /* mask = (ifbZ > ifragZ) */ + break; + case PIPE_FUNC_GEQUAL: + zmask = spu_cmpgt(ifbZ, ifragZ); + zmask = spu_nor(zmask, zmask); + break; + case PIPE_FUNC_LEQUAL: + zmask = spu_cmpgt(ifragZ, ifbZ); + zmask = spu_nor(zmask, zmask); + break; + case PIPE_FUNC_EQUAL: + zmask = spu_cmpeq(ifbZ, ifragZ); + break; + case PIPE_FUNC_NOTEQUAL: + zmask = spu_cmpeq(ifbZ, ifragZ); + zmask = spu_nor(zmask, zmask); + break; + case PIPE_FUNC_ALWAYS: + zmask = spu_splats(0xffffffffU); + break; + case PIPE_FUNC_NEVER: + zmask = spu_splats( 0x0U); + break; + default: + ; + } + + mask = spu_and(mask, zmask); + + /* merge framebuffer Z and fragment Z according to the mask */ + ifbZ = spu_or(spu_and(ifragZ, mask), + spu_andc(ifbZ, mask)); + } + + if (spu_extract(spu_orx(mask), 0)) { + /* put new fragment Z/Stencil values back into Z/Stencil tile */ + depthStencilTile->ui4[y/2][x/2] = spu_or(ifbZ, ifbS); + + spu.cur_ztile_status = TILE_STATUS_DIRTY; + } + } + + + /* + * If we'll need the current framebuffer/tile colors for blending + * or logicop or colormask, fetch them now. + */ + if (spu.blend.rt[0].blend_enable || + spu.blend.logicop_enable || + spu.blend.rt[0].colormask != 0xf) { + +#if LINEAR_QUAD_LAYOUT /* See comments/diagram below */ + fbc0 = colorTile->ui[y][x*2+0]; + fbc1 = colorTile->ui[y][x*2+1]; + fbc2 = colorTile->ui[y][x*2+2]; + fbc3 = colorTile->ui[y][x*2+3]; +#else + fbc0 = colorTile->ui[y+0][x+0]; + fbc1 = colorTile->ui[y+0][x+1]; + fbc2 = colorTile->ui[y+1][x+0]; + fbc3 = colorTile->ui[y+1][x+1]; +#endif + } + + + /* + * Do blending + */ + if (spu.blend.rt[0].blend_enable) { + /* blending terms, misc regs */ + vector float term1r, term1g, term1b, term1a; + vector float term2r, term2g, term2b, term2a; + vector float one, tmp; + + vector float fbRGBA[4]; /* current framebuffer colors */ + + /* convert framebuffer colors from packed int to vector float */ + { + vector float temp[4]; /* float colors in AOS form */ + switch (spu.fb.color_format) { + case PIPE_FORMAT_A8R8G8B8_UNORM: + temp[0] = spu_unpack_B8G8R8A8(fbc0); + temp[1] = spu_unpack_B8G8R8A8(fbc1); + temp[2] = spu_unpack_B8G8R8A8(fbc2); + temp[3] = spu_unpack_B8G8R8A8(fbc3); + break; + case PIPE_FORMAT_B8G8R8A8_UNORM: + temp[0] = spu_unpack_A8R8G8B8(fbc0); + temp[1] = spu_unpack_A8R8G8B8(fbc1); + temp[2] = spu_unpack_A8R8G8B8(fbc2); + temp[3] = spu_unpack_A8R8G8B8(fbc3); + break; + default: + ASSERT(0); + } + _transpose_matrix4x4(fbRGBA, temp); /* fbRGBA = transpose(temp) */ + } + + /* + * Compute Src RGB terms (fragment color * factor) + */ + switch (spu.blend.rt[0].rgb_src_factor) { + case PIPE_BLENDFACTOR_ONE: + term1r = fragR; + term1g = fragG; + term1b = fragB; + break; + case PIPE_BLENDFACTOR_ZERO: + term1r = + term1g = + term1b = spu_splats(0.0f); + break; + case PIPE_BLENDFACTOR_SRC_COLOR: + term1r = spu_mul(fragR, fragR); + term1g = spu_mul(fragG, fragG); + term1b = spu_mul(fragB, fragB); + break; + case PIPE_BLENDFACTOR_SRC_ALPHA: + term1r = spu_mul(fragR, fragA); + term1g = spu_mul(fragG, fragA); + term1b = spu_mul(fragB, fragA); + break; + case PIPE_BLENDFACTOR_DST_COLOR: + term1r = spu_mul(fragR, fbRGBA[0]); + term1g = spu_mul(fragG, fbRGBA[1]); + term1b = spu_mul(fragB, fbRGBA[1]); + break; + case PIPE_BLENDFACTOR_DST_ALPHA: + term1r = spu_mul(fragR, fbRGBA[3]); + term1g = spu_mul(fragG, fbRGBA[3]); + term1b = spu_mul(fragB, fbRGBA[3]); + break; + case PIPE_BLENDFACTOR_CONST_COLOR: + term1r = spu_mul(fragR, spu_splats(spu.blend_color.color[0])); + term1g = spu_mul(fragG, spu_splats(spu.blend_color.color[1])); + term1b = spu_mul(fragB, spu_splats(spu.blend_color.color[2])); + break; + case PIPE_BLENDFACTOR_CONST_ALPHA: + term1r = spu_mul(fragR, spu_splats(spu.blend_color.color[3])); + term1g = spu_mul(fragG, spu_splats(spu.blend_color.color[3])); + term1b = spu_mul(fragB, spu_splats(spu.blend_color.color[3])); + break; + /* XXX more cases */ + default: + ASSERT(0); + } + + /* + * Compute Src Alpha term (fragment alpha * factor) + */ + switch (spu.blend.rt[0].alpha_src_factor) { + case PIPE_BLENDFACTOR_ONE: + term1a = fragA; + break; + case PIPE_BLENDFACTOR_SRC_COLOR: + term1a = spu_splats(0.0f); + break; + case PIPE_BLENDFACTOR_SRC_ALPHA: + term1a = spu_mul(fragA, fragA); + break; + case PIPE_BLENDFACTOR_DST_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_DST_ALPHA: + term1a = spu_mul(fragA, fbRGBA[3]); + break; + case PIPE_BLENDFACTOR_CONST_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_CONST_ALPHA: + term1a = spu_mul(fragR, spu_splats(spu.blend_color.color[3])); + break; + /* XXX more cases */ + default: + ASSERT(0); + } + + /* + * Compute Dest RGB terms (framebuffer color * factor) + */ + switch (spu.blend.rt[0].rgb_dst_factor) { + case PIPE_BLENDFACTOR_ONE: + term2r = fbRGBA[0]; + term2g = fbRGBA[1]; + term2b = fbRGBA[2]; + break; + case PIPE_BLENDFACTOR_ZERO: + term2r = + term2g = + term2b = spu_splats(0.0f); + break; + case PIPE_BLENDFACTOR_SRC_COLOR: + term2r = spu_mul(fbRGBA[0], fragR); + term2g = spu_mul(fbRGBA[1], fragG); + term2b = spu_mul(fbRGBA[2], fragB); + break; + case PIPE_BLENDFACTOR_SRC_ALPHA: + term2r = spu_mul(fbRGBA[0], fragA); + term2g = spu_mul(fbRGBA[1], fragA); + term2b = spu_mul(fbRGBA[2], fragA); + break; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + one = spu_splats(1.0f); + tmp = spu_sub(one, fragA); + term2r = spu_mul(fbRGBA[0], tmp); + term2g = spu_mul(fbRGBA[1], tmp); + term2b = spu_mul(fbRGBA[2], tmp); + break; + case PIPE_BLENDFACTOR_DST_COLOR: + term2r = spu_mul(fbRGBA[0], fbRGBA[0]); + term2g = spu_mul(fbRGBA[1], fbRGBA[1]); + term2b = spu_mul(fbRGBA[2], fbRGBA[2]); + break; + case PIPE_BLENDFACTOR_DST_ALPHA: + term2r = spu_mul(fbRGBA[0], fbRGBA[3]); + term2g = spu_mul(fbRGBA[1], fbRGBA[3]); + term2b = spu_mul(fbRGBA[2], fbRGBA[3]); + break; + case PIPE_BLENDFACTOR_CONST_COLOR: + term2r = spu_mul(fbRGBA[0], spu_splats(spu.blend_color.color[0])); + term2g = spu_mul(fbRGBA[1], spu_splats(spu.blend_color.color[1])); + term2b = spu_mul(fbRGBA[2], spu_splats(spu.blend_color.color[2])); + break; + case PIPE_BLENDFACTOR_CONST_ALPHA: + term2r = spu_mul(fbRGBA[0], spu_splats(spu.blend_color.color[3])); + term2g = spu_mul(fbRGBA[1], spu_splats(spu.blend_color.color[3])); + term2b = spu_mul(fbRGBA[2], spu_splats(spu.blend_color.color[3])); + break; + /* XXX more cases */ + default: + ASSERT(0); + } + + /* + * Compute Dest Alpha term (framebuffer alpha * factor) + */ + switch (spu.blend.rt[0].alpha_dst_factor) { + case PIPE_BLENDFACTOR_ONE: + term2a = fbRGBA[3]; + break; + case PIPE_BLENDFACTOR_SRC_COLOR: + term2a = spu_splats(0.0f); + break; + case PIPE_BLENDFACTOR_SRC_ALPHA: + term2a = spu_mul(fbRGBA[3], fragA); + break; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + one = spu_splats(1.0f); + tmp = spu_sub(one, fragA); + term2a = spu_mul(fbRGBA[3], tmp); + break; + case PIPE_BLENDFACTOR_DST_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_DST_ALPHA: + term2a = spu_mul(fbRGBA[3], fbRGBA[3]); + break; + case PIPE_BLENDFACTOR_CONST_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_CONST_ALPHA: + term2a = spu_mul(fbRGBA[3], spu_splats(spu.blend_color.color[3])); + break; + /* XXX more cases */ + default: + ASSERT(0); + } + + /* + * Combine Src/Dest RGB terms + */ + switch (spu.blend.rt[0].rgb_func) { + case PIPE_BLEND_ADD: + fragR = spu_add(term1r, term2r); + fragG = spu_add(term1g, term2g); + fragB = spu_add(term1b, term2b); + break; + case PIPE_BLEND_SUBTRACT: + fragR = spu_sub(term1r, term2r); + fragG = spu_sub(term1g, term2g); + fragB = spu_sub(term1b, term2b); + break; + case PIPE_BLEND_REVERSE_SUBTRACT: + fragR = spu_sub(term2r, term1r); + fragG = spu_sub(term2g, term1g); + fragB = spu_sub(term2b, term1b); + break; + case PIPE_BLEND_MIN: + fragR = spu_min(term1r, term2r); + fragG = spu_min(term1g, term2g); + fragB = spu_min(term1b, term2b); + break; + case PIPE_BLEND_MAX: + fragR = spu_max(term1r, term2r); + fragG = spu_max(term1g, term2g); + fragB = spu_max(term1b, term2b); + break; + default: + ASSERT(0); + } + + /* + * Combine Src/Dest A term + */ + switch (spu.blend.rt[0].alpha_func) { + case PIPE_BLEND_ADD: + fragA = spu_add(term1a, term2a); + break; + case PIPE_BLEND_SUBTRACT: + fragA = spu_sub(term1a, term2a); + break; + case PIPE_BLEND_REVERSE_SUBTRACT: + fragA = spu_sub(term2a, term1a); + break; + case PIPE_BLEND_MIN: + fragA = spu_min(term1a, term2a); + break; + case PIPE_BLEND_MAX: + fragA = spu_max(term1a, term2a); + break; + default: + ASSERT(0); + } + } + + + /* + * Convert RRRR,GGGG,BBBB,AAAA to RGBA,RGBA,RGBA,RGBA. + */ +#if 0 + /* original code */ + { + vector float frag_soa[4]; + frag_soa[0] = fragR; + frag_soa[1] = fragG; + frag_soa[2] = fragB; + frag_soa[3] = fragA; + _transpose_matrix4x4(frag_aos, frag_soa); + } +#else + /* short-cut relying on function parameter layout: */ + _transpose_matrix4x4(frag_aos, &fragR); + (void) fragG; + (void) fragB; +#endif + + /* + * Pack fragment float colors into 32-bit RGBA words. + */ + switch (spu.fb.color_format) { + case PIPE_FORMAT_B8G8R8A8_UNORM: + fragc0 = spu_pack_A8R8G8B8(frag_aos[0]); + fragc1 = spu_pack_A8R8G8B8(frag_aos[1]); + fragc2 = spu_pack_A8R8G8B8(frag_aos[2]); + fragc3 = spu_pack_A8R8G8B8(frag_aos[3]); + break; + case PIPE_FORMAT_A8R8G8B8_UNORM: + fragc0 = spu_pack_B8G8R8A8(frag_aos[0]); + fragc1 = spu_pack_B8G8R8A8(frag_aos[1]); + fragc2 = spu_pack_B8G8R8A8(frag_aos[2]); + fragc3 = spu_pack_B8G8R8A8(frag_aos[3]); + break; + default: + fprintf(stderr, "SPU: Bad pixel format in spu_default_fragment_ops\n"); + ASSERT(0); + } + + + /* + * Do color masking + */ + if (spu.blend.rt[0].colormask != 0xf) { + uint cmask = 0x0; /* each byte corresponds to a color channel */ + + /* Form bitmask depending on color buffer format and colormask bits */ + switch (spu.fb.color_format) { + case PIPE_FORMAT_B8G8R8A8_UNORM: + if (spu.blend.rt[0].colormask & PIPE_MASK_R) + cmask |= 0x00ff0000; /* red */ + if (spu.blend.rt[0].colormask & PIPE_MASK_G) + cmask |= 0x0000ff00; /* green */ + if (spu.blend.rt[0].colormask & PIPE_MASK_B) + cmask |= 0x000000ff; /* blue */ + if (spu.blend.rt[0].colormask & PIPE_MASK_A) + cmask |= 0xff000000; /* alpha */ + break; + case PIPE_FORMAT_A8R8G8B8_UNORM: + if (spu.blend.rt[0].colormask & PIPE_MASK_R) + cmask |= 0x0000ff00; /* red */ + if (spu.blend.rt[0].colormask & PIPE_MASK_G) + cmask |= 0x00ff0000; /* green */ + if (spu.blend.rt[0].colormask & PIPE_MASK_B) + cmask |= 0xff000000; /* blue */ + if (spu.blend.rt[0].colormask & PIPE_MASK_A) + cmask |= 0x000000ff; /* alpha */ + break; + default: + ASSERT(0); + } + + /* + * Apply color mask to the 32-bit packed colors. + * if (cmask[i]) + * frag color[i] = frag color[i]; + * else + * frag color[i] = framebuffer color[i]; + */ + fragc0 = (fragc0 & cmask) | (fbc0 & ~cmask); + fragc1 = (fragc1 & cmask) | (fbc1 & ~cmask); + fragc2 = (fragc2 & cmask) | (fbc2 & ~cmask); + fragc3 = (fragc3 & cmask) | (fbc3 & ~cmask); + } + + + /* + * Do logic ops + */ + if (spu.blend.logicop_enable) { + /* XXX to do */ + /* apply logicop to 32-bit packed colors (fragcx and fbcx) */ + } + + + /* + * If mask is non-zero, mark tile as dirty. + */ + if (spu_extract(spu_orx(mask), 0)) { + spu.cur_ctile_status = TILE_STATUS_DIRTY; + } + else { + /* write no fragments */ + return; + } + + + /* + * Write new fragment/quad colors to the framebuffer/tile. + * Only write pixels where the corresponding mask word is set. + */ +#if LINEAR_QUAD_LAYOUT + /* + * Quad layout: + * +--+--+--+--+ + * |p0|p1|p2|p3|... + * +--+--+--+--+ + */ + if (spu_extract(mask, 0)) + colorTile->ui[y][x*2] = fragc0; + if (spu_extract(mask, 1)) + colorTile->ui[y][x*2+1] = fragc1; + if (spu_extract(mask, 2)) + colorTile->ui[y][x*2+2] = fragc2; + if (spu_extract(mask, 3)) + colorTile->ui[y][x*2+3] = fragc3; +#else + /* + * Quad layout: + * +--+--+ + * |p0|p1|... + * +--+--+ + * |p2|p3|... + * +--+--+ + */ + if (spu_extract(mask, 0)) + colorTile->ui[y+0][x+0] = fragc0; + if (spu_extract(mask, 1)) + colorTile->ui[y+0][x+1] = fragc1; + if (spu_extract(mask, 2)) + colorTile->ui[y+1][x+0] = fragc2; + if (spu_extract(mask, 3)) + colorTile->ui[y+1][x+1] = fragc3; +#endif +} diff --git a/src/gallium/drivers/cell/spu/spu_per_fragment_op.h b/src/gallium/drivers/cell/spu/spu_per_fragment_op.h new file mode 100644 index 0000000..f817abf --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_per_fragment_op.h @@ -0,0 +1,44 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef SPU_PER_FRAGMENT_OP +#define SPU_PER_FRAGMENT_OP + + +extern void +spu_fallback_fragment_ops(uint x, uint y, + tile_t *colorTile, + tile_t *depthStencilTile, + vector float fragZ, + vector float fragRed, + vector float fragGreen, + vector float fragBlue, + vector float fragAlpha, + vector unsigned int mask); + + +#endif /* SPU_PER_FRAGMENT_OP */ diff --git a/src/gallium/drivers/cell/spu/spu_render.c b/src/gallium/drivers/cell/spu/spu_render.c new file mode 100644 index 0000000..14987e3 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_render.c @@ -0,0 +1,356 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include +#include +#include + +#include "spu_main.h" +#include "spu_render.h" +#include "spu_shuffle.h" +#include "spu_tri.h" +#include "spu_tile.h" +#include "cell/common.h" +#include "util/u_memory.h" + + +/** + * Given a rendering command's bounding box (in pixels) compute the + * location of the corresponding screen tile bounding box. + */ +static INLINE void +tile_bounding_box(const struct cell_command_render *render, + uint *txmin, uint *tymin, + uint *box_num_tiles, uint *box_width_tiles) +{ +#if 0 + /* Debug: full-window bounding box */ + uint txmax = spu.fb.width_tiles - 1; + uint tymax = spu.fb.height_tiles - 1; + *txmin = 0; + *tymin = 0; + *box_num_tiles = spu.fb.width_tiles * spu.fb.height_tiles; + *box_width_tiles = spu.fb.width_tiles; + (void) render; + (void) txmax; + (void) tymax; +#else + uint txmax, tymax, box_height_tiles; + + *txmin = (uint) render->xmin / TILE_SIZE; + *tymin = (uint) render->ymin / TILE_SIZE; + txmax = (uint) render->xmax / TILE_SIZE; + tymax = (uint) render->ymax / TILE_SIZE; + if (txmax >= spu.fb.width_tiles) + txmax = spu.fb.width_tiles-1; + if (tymax >= spu.fb.height_tiles) + tymax = spu.fb.height_tiles-1; + *box_width_tiles = txmax - *txmin + 1; + box_height_tiles = tymax - *tymin + 1; + *box_num_tiles = *box_width_tiles * box_height_tiles; +#endif +#if 0 + printf("SPU %u: bounds: %g, %g ... %g, %g\n", spu.init.id, + render->xmin, render->ymin, render->xmax, render->ymax); + printf("SPU %u: tiles: %u, %u .. %u, %u\n", + spu.init.id, *txmin, *tymin, txmax, tymax); + ASSERT(render->xmin <= render->xmax); + ASSERT(render->ymin <= render->ymax); +#endif +} + + +/** Check if the tile at (tx,ty) belongs to this SPU */ +static INLINE boolean +my_tile(uint tx, uint ty) +{ + return (spu.fb.width_tiles * ty + tx) % spu.init.num_spus == spu.init.id; +} + + +/** + * Start fetching non-clear color/Z tiles from main memory + */ +static INLINE void +get_cz_tiles(uint tx, uint ty) +{ + if (spu.read_depth_stencil) { + if (spu.cur_ztile_status != TILE_STATUS_CLEAR) { + //printf("SPU %u: getting Z tile %u, %u\n", spu.init.id, tx, ty); + get_tile(tx, ty, &spu.ztile, TAG_READ_TILE_Z, 1); + spu.cur_ztile_status = TILE_STATUS_GETTING; + } + } + + if (spu.cur_ctile_status != TILE_STATUS_CLEAR) { + //printf("SPU %u: getting C tile %u, %u\n", spu.init.id, tx, ty); + get_tile(tx, ty, &spu.ctile, TAG_READ_TILE_COLOR, 0); + spu.cur_ctile_status = TILE_STATUS_GETTING; + } +} + + +/** + * Start putting dirty color/Z tiles back to main memory + */ +static INLINE void +put_cz_tiles(uint tx, uint ty) +{ + if (spu.cur_ztile_status == TILE_STATUS_DIRTY) { + /* tile was modified and needs to be written back */ + //printf("SPU %u: put dirty Z tile %u, %u\n", spu.init.id, tx, ty); + put_tile(tx, ty, &spu.ztile, TAG_WRITE_TILE_Z, 1); + spu.cur_ztile_status = TILE_STATUS_DEFINED; + } + else if (spu.cur_ztile_status == TILE_STATUS_GETTING) { + /* tile was never used */ + spu.cur_ztile_status = TILE_STATUS_DEFINED; + //printf("SPU %u: put getting Z tile %u, %u\n", spu.init.id, tx, ty); + } + + if (spu.cur_ctile_status == TILE_STATUS_DIRTY) { + /* tile was modified and needs to be written back */ + //printf("SPU %u: put dirty C tile %u, %u\n", spu.init.id, tx, ty); + put_tile(tx, ty, &spu.ctile, TAG_WRITE_TILE_COLOR, 0); + spu.cur_ctile_status = TILE_STATUS_DEFINED; + } + else if (spu.cur_ctile_status == TILE_STATUS_GETTING) { + /* tile was never used */ + spu.cur_ctile_status = TILE_STATUS_DEFINED; + //printf("SPU %u: put getting C tile %u, %u\n", spu.init.id, tx, ty); + } +} + + +/** + * Wait for 'put' of color/z tiles to complete. + */ +static INLINE void +wait_put_cz_tiles(void) +{ + wait_on_mask(1 << TAG_WRITE_TILE_COLOR); + if (spu.read_depth_stencil) { + wait_on_mask(1 << TAG_WRITE_TILE_Z); + } +} + + +/** + * Render primitives + * \param pos_incr returns value indicating how may words to skip after + * this command in the batch buffer + */ +void +cmd_render(const struct cell_command_render *render, uint *pos_incr) +{ + /* we'll DMA into these buffers */ + PIPE_ALIGN_VAR(16) ubyte vertex_data[CELL_BUFFER_SIZE]; + const uint vertex_size = render->vertex_size; /* in bytes */ + /*const*/ uint total_vertex_bytes = render->num_verts * vertex_size; + uint index_bytes; + const ubyte *vertices; + const ushort *indexes; + uint i, j; + uint num_tiles; + + D_PRINTF(CELL_DEBUG_CMD, + "RENDER prim=%u num_vert=%u num_ind=%u inline_vert=%u\n", + render->prim_type, + render->num_verts, + render->num_indexes, + render->inline_verts); + + ASSERT(sizeof(*render) % 4 == 0); + ASSERT(total_vertex_bytes % 16 == 0); + ASSERT(render->prim_type == PIPE_PRIM_TRIANGLES); + ASSERT(render->num_indexes % 3 == 0); + + + /* indexes are right after the render command in the batch buffer */ + indexes = (const ushort *) (render + 1); + index_bytes = ROUNDUP8(render->num_indexes * 2); + *pos_incr = index_bytes / 8 + sizeof(*render) / 8; + + + if (render->inline_verts) { + /* Vertices are after indexes in batch buffer at next 16-byte addr */ + vertices = (const ubyte *) render + (*pos_incr * 8); + vertices = (const ubyte *) align_pointer((void *) vertices, 16); + ASSERT_ALIGN16(vertices); + *pos_incr = ((vertices + total_vertex_bytes) - (ubyte *) render) / 8; + } + else { + /* Begin DMA fetch of vertex buffer */ + ubyte *src = spu.init.buffers[render->vertex_buf]; + ubyte *dest = vertex_data; + + /* skip vertex data we won't use */ +#if 01 + src += render->min_index * vertex_size; + dest += render->min_index * vertex_size; + total_vertex_bytes -= render->min_index * vertex_size; +#endif + ASSERT(total_vertex_bytes % 16 == 0); + ASSERT_ALIGN16(dest); + ASSERT_ALIGN16(src); + + mfc_get(dest, /* in vertex_data[] array */ + (unsigned int) src, /* src in main memory */ + total_vertex_bytes, /* size */ + TAG_VERTEX_BUFFER, + 0, /* tid */ + 0 /* rid */); + + vertices = vertex_data; + + wait_on_mask(1 << TAG_VERTEX_BUFFER); + } + + + /** + ** find tiles which intersect the prim bounding box + **/ + uint txmin, tymin, box_width_tiles, box_num_tiles; + tile_bounding_box(render, &txmin, &tymin, + &box_num_tiles, &box_width_tiles); + + + /* make sure any pending clears have completed */ + wait_on_mask(1 << TAG_SURFACE_CLEAR); /* XXX temporary */ + + + num_tiles = 0; + + /** + ** loop over tiles, rendering tris + **/ + for (i = 0; i < box_num_tiles; i++) { + const uint tx = txmin + i % box_width_tiles; + const uint ty = tymin + i / box_width_tiles; + + ASSERT(tx < spu.fb.width_tiles); + ASSERT(ty < spu.fb.height_tiles); + + if (!my_tile(tx, ty)) + continue; + + num_tiles++; + + spu.cur_ctile_status = spu.ctile_status[ty][tx]; + spu.cur_ztile_status = spu.ztile_status[ty][tx]; + + get_cz_tiles(tx, ty); + + uint drawn = 0; + + const qword vertex_sizes = (qword)spu_splats(vertex_size); + const qword verticess = (qword)spu_splats((uint)vertices); + + ASSERT_ALIGN16(&indexes[0]); + + const uint num_indexes = render->num_indexes; + + /* loop over tris + * &indexes[0] will be 16 byte aligned. This loop is heavily unrolled + * avoiding variable rotates when extracting vertex indices. + */ + for (j = 0; j < num_indexes; j += 24) { + /* Load three vectors, containing 24 ushort indices */ + const qword* lower_qword = (qword*)&indexes[j]; + const qword indices0 = lower_qword[0]; + const qword indices1 = lower_qword[1]; + const qword indices2 = lower_qword[2]; + + /* stores three indices for each tri n in slots 0, 1 and 2 of vsn */ + /* Straightforward rotates for these */ + qword vs0 = indices0; + qword vs1 = si_shlqbyi(indices0, 6); + qword vs3 = si_shlqbyi(indices1, 2); + qword vs4 = si_shlqbyi(indices1, 8); + qword vs6 = si_shlqbyi(indices2, 4); + qword vs7 = si_shlqbyi(indices2, 10); + + /* For tri 2 and 5, the three indices are split across two machine + * words - rotate and combine */ + const qword tmp2a = si_shlqbyi(indices0, 12); + const qword tmp2b = si_rotqmbyi(indices1, 12|16); + qword vs2 = si_selb(tmp2a, tmp2b, si_fsmh(si_from_uint(0x20))); + + const qword tmp5a = si_shlqbyi(indices1, 14); + const qword tmp5b = si_rotqmbyi(indices2, 14|16); + qword vs5 = si_selb(tmp5a, tmp5b, si_fsmh(si_from_uint(0x60))); + + /* unpack indices from halfword slots to word slots */ + vs0 = si_shufb(vs0, vs0, SHUFB8(0,A,0,B,0,C,0,0)); + vs1 = si_shufb(vs1, vs1, SHUFB8(0,A,0,B,0,C,0,0)); + vs2 = si_shufb(vs2, vs2, SHUFB8(0,A,0,B,0,C,0,0)); + vs3 = si_shufb(vs3, vs3, SHUFB8(0,A,0,B,0,C,0,0)); + vs4 = si_shufb(vs4, vs4, SHUFB8(0,A,0,B,0,C,0,0)); + vs5 = si_shufb(vs5, vs5, SHUFB8(0,A,0,B,0,C,0,0)); + vs6 = si_shufb(vs6, vs6, SHUFB8(0,A,0,B,0,C,0,0)); + vs7 = si_shufb(vs7, vs7, SHUFB8(0,A,0,B,0,C,0,0)); + + /* Calculate address of vertex in vertices[] */ + vs0 = si_mpya(vs0, vertex_sizes, verticess); + vs1 = si_mpya(vs1, vertex_sizes, verticess); + vs2 = si_mpya(vs2, vertex_sizes, verticess); + vs3 = si_mpya(vs3, vertex_sizes, verticess); + vs4 = si_mpya(vs4, vertex_sizes, verticess); + vs5 = si_mpya(vs5, vertex_sizes, verticess); + vs6 = si_mpya(vs6, vertex_sizes, verticess); + vs7 = si_mpya(vs7, vertex_sizes, verticess); + + /* Select the appropriate call based on the number of vertices + * remaining */ + switch(num_indexes - j) { + default: drawn += tri_draw(vs7, tx, ty); + case 21: drawn += tri_draw(vs6, tx, ty); + case 18: drawn += tri_draw(vs5, tx, ty); + case 15: drawn += tri_draw(vs4, tx, ty); + case 12: drawn += tri_draw(vs3, tx, ty); + case 9: drawn += tri_draw(vs2, tx, ty); + case 6: drawn += tri_draw(vs1, tx, ty); + case 3: drawn += tri_draw(vs0, tx, ty); + } + } + + //printf("SPU %u: drew %u of %u\n", spu.init.id, drawn, render->num_indexes/3); + + /* write color/z tiles back to main framebuffer, if dirtied */ + put_cz_tiles(tx, ty); + + wait_put_cz_tiles(); /* XXX seems unnecessary... */ + + spu.ctile_status[ty][tx] = spu.cur_ctile_status; + spu.ztile_status[ty][tx] = spu.cur_ztile_status; + } + + D_PRINTF(CELL_DEBUG_CMD, + "RENDER done (%u tiles hit)\n", + num_tiles); +} diff --git a/src/gallium/drivers/cell/spu/spu_render.h b/src/gallium/drivers/cell/spu/spu_render.h new file mode 100644 index 0000000..493434f --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_render.h @@ -0,0 +1,38 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef SPU_RENDER_H +#define SPU_RENDER_H + +#include "cell/common.h" + +extern void +cmd_render(const struct cell_command_render *render, uint *pos_incr); + +#endif /* SPU_RENDER_H */ + diff --git a/src/gallium/drivers/cell/spu/spu_shuffle.h b/src/gallium/drivers/cell/spu/spu_shuffle.h new file mode 100644 index 0000000..74f2a0b --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_shuffle.h @@ -0,0 +1,186 @@ +#ifndef SPU_SHUFFLE_H +#define SPU_SHUFFLE_H + +/* + * Generate shuffle patterns with minimal fuss. + * + * Based on ideas from + * http://www.insomniacgames.com/tech/articles/0408/files/shuffles.pdf + * + * A-P indicates 0-15th position in first vector + * a-p indicates 0-15th position in second vector + * + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * |00|01|02|03|04|05|06|07|08|09|0a|0b|0c|0d|0e|0f| + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * | A| B| C| D| + * +-----+-----+-----+-----+-----+-----+-----+-----+ + * | A| B| C| D| E| F| G| H| + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * | A| B| C| D| E| F| G| H| I| J| K| L| M| N| O| P| + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * + * x or X indicates 0xff + * 8 indicates 0x80 + * 0 indicates 0x00 + * + * The macros SHUFFLE4() SHUFFLE8() and SHUFFLE16() provide a const vector + * unsigned char literal suitable for use with spu_shuffle(). + * + * The macros SHUFB4() SHUFB8() and SHUFB16() provide a const qword vector + * literal suitable for use with si_shufb(). + * + * + * For example : + * SHUFB4(A,A,A,A) + * expands to : + * ((const qword){0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3}) + * + * SHUFFLE8(A,B,a,b,C,c,8,8) + * expands to : + * ((const vector unsigned char){0x00,0x01,0x02,0x03,0x10,0x11,0x12,0x13, + * 0x04,0x05,0x14,0x15,0xe0,0xe0,0xe0,0xe0}) + * + */ + +#include + +#define SHUFFLE_PATTERN_4_A__ 0x00, 0x01, 0x02, 0x03 +#define SHUFFLE_PATTERN_4_B__ 0x04, 0x05, 0x06, 0x07 +#define SHUFFLE_PATTERN_4_C__ 0x08, 0x09, 0x0a, 0x0b +#define SHUFFLE_PATTERN_4_D__ 0x0c, 0x0d, 0x0e, 0x0f +#define SHUFFLE_PATTERN_4_a__ 0x10, 0x11, 0x12, 0x13 +#define SHUFFLE_PATTERN_4_b__ 0x14, 0x15, 0x16, 0x17 +#define SHUFFLE_PATTERN_4_c__ 0x18, 0x19, 0x1a, 0x1b +#define SHUFFLE_PATTERN_4_d__ 0x1c, 0x1d, 0x1e, 0x1f +#define SHUFFLE_PATTERN_4_X__ 0xc0, 0xc0, 0xc0, 0xc0 +#define SHUFFLE_PATTERN_4_x__ 0xc0, 0xc0, 0xc0, 0xc0 +#define SHUFFLE_PATTERN_4_0__ 0x80, 0x80, 0x80, 0x80 +#define SHUFFLE_PATTERN_4_8__ 0xe0, 0xe0, 0xe0, 0xe0 + +#define SHUFFLE_VECTOR_4__(A, B, C, D) \ + SHUFFLE_PATTERN_4_##A##__, \ + SHUFFLE_PATTERN_4_##B##__, \ + SHUFFLE_PATTERN_4_##C##__, \ + SHUFFLE_PATTERN_4_##D##__ + +#define SHUFFLE4(A, B, C, D) \ + ((const vector unsigned char){ \ + SHUFFLE_VECTOR_4__(A, B, C, D) \ + }) + +#define SHUFB4(A, B, C, D) \ + ((const qword){ \ + SHUFFLE_VECTOR_4__(A, B, C, D) \ + }) + + +#define SHUFFLE_PATTERN_8_A__ 0x00, 0x01 +#define SHUFFLE_PATTERN_8_B__ 0x02, 0x03 +#define SHUFFLE_PATTERN_8_C__ 0x04, 0x05 +#define SHUFFLE_PATTERN_8_D__ 0x06, 0x07 +#define SHUFFLE_PATTERN_8_E__ 0x08, 0x09 +#define SHUFFLE_PATTERN_8_F__ 0x0a, 0x0b +#define SHUFFLE_PATTERN_8_G__ 0x0c, 0x0d +#define SHUFFLE_PATTERN_8_H__ 0x0e, 0x0f +#define SHUFFLE_PATTERN_8_a__ 0x10, 0x11 +#define SHUFFLE_PATTERN_8_b__ 0x12, 0x13 +#define SHUFFLE_PATTERN_8_c__ 0x14, 0x15 +#define SHUFFLE_PATTERN_8_d__ 0x16, 0x17 +#define SHUFFLE_PATTERN_8_e__ 0x18, 0x19 +#define SHUFFLE_PATTERN_8_f__ 0x1a, 0x1b +#define SHUFFLE_PATTERN_8_g__ 0x1c, 0x1d +#define SHUFFLE_PATTERN_8_h__ 0x1e, 0x1f +#define SHUFFLE_PATTERN_8_X__ 0xc0, 0xc0 +#define SHUFFLE_PATTERN_8_x__ 0xc0, 0xc0 +#define SHUFFLE_PATTERN_8_0__ 0x80, 0x80 +#define SHUFFLE_PATTERN_8_8__ 0xe0, 0xe0 + + +#define SHUFFLE_VECTOR_8__(A, B, C, D, E, F, G, H) \ + SHUFFLE_PATTERN_8_##A##__, \ + SHUFFLE_PATTERN_8_##B##__, \ + SHUFFLE_PATTERN_8_##C##__, \ + SHUFFLE_PATTERN_8_##D##__, \ + SHUFFLE_PATTERN_8_##E##__, \ + SHUFFLE_PATTERN_8_##F##__, \ + SHUFFLE_PATTERN_8_##G##__, \ + SHUFFLE_PATTERN_8_##H##__ + +#define SHUFFLE8(A, B, C, D, E, F, G, H) \ + ((const vector unsigned char){ \ + SHUFFLE_VECTOR_8__(A, B, C, D, E, F, G, H) \ + }) + +#define SHUFB8(A, B, C, D, E, F, G, H) \ + ((const qword){ \ + SHUFFLE_VECTOR_8__(A, B, C, D, E, F, G, H) \ + }) + + +#define SHUFFLE_PATTERN_16_A__ 0x00 +#define SHUFFLE_PATTERN_16_B__ 0x01 +#define SHUFFLE_PATTERN_16_C__ 0x02 +#define SHUFFLE_PATTERN_16_D__ 0x03 +#define SHUFFLE_PATTERN_16_E__ 0x04 +#define SHUFFLE_PATTERN_16_F__ 0x05 +#define SHUFFLE_PATTERN_16_G__ 0x06 +#define SHUFFLE_PATTERN_16_H__ 0x07 +#define SHUFFLE_PATTERN_16_I__ 0x08 +#define SHUFFLE_PATTERN_16_J__ 0x09 +#define SHUFFLE_PATTERN_16_K__ 0x0a +#define SHUFFLE_PATTERN_16_L__ 0x0b +#define SHUFFLE_PATTERN_16_M__ 0x0c +#define SHUFFLE_PATTERN_16_N__ 0x0d +#define SHUFFLE_PATTERN_16_O__ 0x0e +#define SHUFFLE_PATTERN_16_P__ 0x0f +#define SHUFFLE_PATTERN_16_a__ 0x10 +#define SHUFFLE_PATTERN_16_b__ 0x11 +#define SHUFFLE_PATTERN_16_c__ 0x12 +#define SHUFFLE_PATTERN_16_d__ 0x13 +#define SHUFFLE_PATTERN_16_e__ 0x14 +#define SHUFFLE_PATTERN_16_f__ 0x15 +#define SHUFFLE_PATTERN_16_g__ 0x16 +#define SHUFFLE_PATTERN_16_h__ 0x17 +#define SHUFFLE_PATTERN_16_i__ 0x18 +#define SHUFFLE_PATTERN_16_j__ 0x19 +#define SHUFFLE_PATTERN_16_k__ 0x1a +#define SHUFFLE_PATTERN_16_l__ 0x1b +#define SHUFFLE_PATTERN_16_m__ 0x1c +#define SHUFFLE_PATTERN_16_n__ 0x1d +#define SHUFFLE_PATTERN_16_o__ 0x1e +#define SHUFFLE_PATTERN_16_p__ 0x1f +#define SHUFFLE_PATTERN_16_X__ 0xc0 +#define SHUFFLE_PATTERN_16_x__ 0xc0 +#define SHUFFLE_PATTERN_16_0__ 0x80 +#define SHUFFLE_PATTERN_16_8__ 0xe0 + +#define SHUFFLE_VECTOR_16__(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) \ + SHUFFLE_PATTERN_16_##A##__, \ + SHUFFLE_PATTERN_16_##B##__, \ + SHUFFLE_PATTERN_16_##C##__, \ + SHUFFLE_PATTERN_16_##D##__, \ + SHUFFLE_PATTERN_16_##E##__, \ + SHUFFLE_PATTERN_16_##F##__, \ + SHUFFLE_PATTERN_16_##G##__, \ + SHUFFLE_PATTERN_16_##H##__, \ + SHUFFLE_PATTERN_16_##I##__, \ + SHUFFLE_PATTERN_16_##J##__, \ + SHUFFLE_PATTERN_16_##K##__, \ + SHUFFLE_PATTERN_16_##L##__, \ + SHUFFLE_PATTERN_16_##M##__, \ + SHUFFLE_PATTERN_16_##N##__, \ + SHUFFLE_PATTERN_16_##O##__, \ + SHUFFLE_PATTERN_16_##P##__ + +#define SHUFFLE16(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) \ + ((const vector unsigned char){ \ + SHUFFLE_VECTOR_16__(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) \ + }) + +#define SHUFB16(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) \ + ((const qword){ \ + SHUFFLE_VECTOR_16__(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) \ + }) + +#endif diff --git a/src/gallium/drivers/cell/spu/spu_texture.c b/src/gallium/drivers/cell/spu/spu_texture.c new file mode 100644 index 0000000..69784c8 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_texture.c @@ -0,0 +1,641 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include + +#include "pipe/p_compiler.h" +#include "spu_main.h" +#include "spu_texture.h" +#include "spu_tile.h" +#include "spu_colorpack.h" +#include "spu_dcache.h" + + +/** + * Mark all tex cache entries as invalid. + */ +void +invalidate_tex_cache(void) +{ + uint lvl; + for (lvl = 0; lvl < CELL_MAX_TEXTURE_LEVELS; lvl++) { + uint unit = 0; + uint bytes = 4 * spu.texture[unit].level[lvl].width + * spu.texture[unit].level[lvl].height; + + if (spu.texture[unit].target == PIPE_TEXTURE_CUBE) + bytes *= 6; + else if (spu.texture[unit].target == PIPE_TEXTURE_3D) + bytes *= spu.texture[unit].level[lvl].depth; + + spu_dcache_mark_dirty((unsigned) spu.texture[unit].level[lvl].start, bytes); + } +} + + +/** + * Get four texels from locations (x[0], y[0]), (x[1], y[1]) ... + * + * NOTE: in the typical case of bilinear filtering, the four texels + * are in a 2x2 group so we could get by with just two dcache fetches + * (two side-by-side texels per fetch). But when bilinear filtering + * wraps around a texture edge, we'll probably need code like we have + * now. + * FURTHERMORE: since we're rasterizing a quad of 2x2 pixels at a time, + * it's quite likely that the four pixels in a quad will need some of the + * same texels. So look into doing texture fetches for four pixels at + * a time. + */ +static void +get_four_texels(const struct spu_texture_level *tlevel, uint face, + vec_int4 x, vec_int4 y, + vec_uint4 *texels) +{ + unsigned texture_ea = (uintptr_t) tlevel->start; + const vec_int4 tile_x = spu_rlmask(x, -5); /* tile_x = x / 32 */ + const vec_int4 tile_y = spu_rlmask(y, -5); /* tile_y = y / 32 */ + const qword offset_x = si_andi((qword) x, 0x1f); /* offset_x = x & 0x1f */ + const qword offset_y = si_andi((qword) y, 0x1f); /* offset_y = y & 0x1f */ + + const qword tiles_per_row = (qword) spu_splats(tlevel->tiles_per_row); + const qword tile_size = (qword) spu_splats((unsigned) sizeof(tile_t)); + + qword tile_offset = si_mpya((qword) tile_y, tiles_per_row, (qword) tile_x); + tile_offset = si_mpy((qword) tile_offset, tile_size); + + qword texel_offset = si_a(si_mpyui(offset_y, 32), offset_x); + texel_offset = si_mpyui(texel_offset, 4); + + vec_uint4 offset = (vec_uint4) si_a(tile_offset, texel_offset); + + texture_ea = texture_ea + face * tlevel->bytes_per_image; + + spu_dcache_fetch_unaligned((qword *) & texels[0], + texture_ea + spu_extract(offset, 0), 4); + spu_dcache_fetch_unaligned((qword *) & texels[1], + texture_ea + spu_extract(offset, 1), 4); + spu_dcache_fetch_unaligned((qword *) & texels[2], + texture_ea + spu_extract(offset, 2), 4); + spu_dcache_fetch_unaligned((qword *) & texels[3], + texture_ea + spu_extract(offset, 3), 4); +} + + +/** clamp vec to [0, max] */ +static INLINE vector signed int +spu_clamp(vector signed int vec, vector signed int max) +{ + static const vector signed int zero = {0,0,0,0}; + vector unsigned int c; + c = spu_cmpgt(vec, zero); /* c = vec > zero ? ~0 : 0 */ + vec = spu_sel(zero, vec, c); + c = spu_cmpgt(vec, max); /* c = vec > max ? ~0 : 0 */ + vec = spu_sel(vec, max, c); + return vec; +} + + + +/** + * Do nearest texture sampling for four pixels. + * \param colors returned colors in SOA format (rrrr, gggg, bbbb, aaaa). + */ +void +sample_texture_2d_nearest(vector float s, vector float t, + uint unit, uint level, uint face, + vector float colors[4]) +{ + const struct spu_texture_level *tlevel = &spu.texture[unit].level[level]; + vector float ss = spu_mul(s, tlevel->scale_s); + vector float tt = spu_mul(t, tlevel->scale_t); + vector signed int is = spu_convts(ss, 0); + vector signed int it = spu_convts(tt, 0); + vec_uint4 texels[4]; + + /* PIPE_TEX_WRAP_REPEAT */ + is = spu_and(is, tlevel->mask_s); + it = spu_and(it, tlevel->mask_t); + + /* PIPE_TEX_WRAP_CLAMP */ + is = spu_clamp(is, tlevel->max_s); + it = spu_clamp(it, tlevel->max_t); + + get_four_texels(tlevel, face, is, it, texels); + + /* convert four packed ARGBA pixels to float RRRR,GGGG,BBBB,AAAA */ + spu_unpack_A8R8G8B8_transpose4(texels, colors); +} + + +/** + * Do bilinear texture sampling for four pixels. + * \param colors returned colors in SOA format (rrrr, gggg, bbbb, aaaa). + */ +void +sample_texture_2d_bilinear(vector float s, vector float t, + uint unit, uint level, uint face, + vector float colors[4]) +{ + const struct spu_texture_level *tlevel = &spu.texture[unit].level[level]; + static const vector float half = {-0.5f, -0.5f, -0.5f, -0.5f}; + + vector float ss = spu_madd(s, tlevel->scale_s, half); + vector float tt = spu_madd(t, tlevel->scale_t, half); + + vector signed int is0 = spu_convts(ss, 0); + vector signed int it0 = spu_convts(tt, 0); + + /* is + 1, it + 1 */ + vector signed int is1 = spu_add(is0, 1); + vector signed int it1 = spu_add(it0, 1); + + /* PIPE_TEX_WRAP_REPEAT */ + is0 = spu_and(is0, tlevel->mask_s); + it0 = spu_and(it0, tlevel->mask_t); + is1 = spu_and(is1, tlevel->mask_s); + it1 = spu_and(it1, tlevel->mask_t); + + /* PIPE_TEX_WRAP_CLAMP */ + is0 = spu_clamp(is0, tlevel->max_s); + it0 = spu_clamp(it0, tlevel->max_t); + is1 = spu_clamp(is1, tlevel->max_s); + it1 = spu_clamp(it1, tlevel->max_t); + + /* get packed int texels */ + vector unsigned int texels[16]; + get_four_texels(tlevel, face, is0, it0, texels + 0); /* upper-left */ + get_four_texels(tlevel, face, is1, it0, texels + 4); /* upper-right */ + get_four_texels(tlevel, face, is0, it1, texels + 8); /* lower-left */ + get_four_texels(tlevel, face, is1, it1, texels + 12); /* lower-right */ + + /* convert packed int texels to float colors */ + vector float ftexels[16]; + spu_unpack_A8R8G8B8_transpose4(texels + 0, ftexels + 0); + spu_unpack_A8R8G8B8_transpose4(texels + 4, ftexels + 4); + spu_unpack_A8R8G8B8_transpose4(texels + 8, ftexels + 8); + spu_unpack_A8R8G8B8_transpose4(texels + 12, ftexels + 12); + + /* Compute weighting factors in [0,1] + * Multiply texcoord by 1024, AND with 1023, convert back to float. + */ + vector float ss1024 = spu_mul(ss, spu_splats(1024.0f)); + vector signed int iss1024 = spu_convts(ss1024, 0); + iss1024 = spu_and(iss1024, 1023); + vector float sWeights0 = spu_convtf(iss1024, 10); + + vector float tt1024 = spu_mul(tt, spu_splats(1024.0f)); + vector signed int itt1024 = spu_convts(tt1024, 0); + itt1024 = spu_and(itt1024, 1023); + vector float tWeights0 = spu_convtf(itt1024, 10); + + /* 1 - sWeight and 1 - tWeight */ + vector float sWeights1 = spu_sub(spu_splats(1.0f), sWeights0); + vector float tWeights1 = spu_sub(spu_splats(1.0f), tWeights0); + + /* reds, for four pixels */ + ftexels[ 0] = spu_mul(ftexels[ 0], spu_mul(sWeights1, tWeights1)); /*ul*/ + ftexels[ 4] = spu_mul(ftexels[ 4], spu_mul(sWeights0, tWeights1)); /*ur*/ + ftexels[ 8] = spu_mul(ftexels[ 8], spu_mul(sWeights1, tWeights0)); /*ll*/ + ftexels[12] = spu_mul(ftexels[12], spu_mul(sWeights0, tWeights0)); /*lr*/ + colors[0] = spu_add(spu_add(ftexels[0], ftexels[4]), + spu_add(ftexels[8], ftexels[12])); + + /* greens, for four pixels */ + ftexels[ 1] = spu_mul(ftexels[ 1], spu_mul(sWeights1, tWeights1)); /*ul*/ + ftexels[ 5] = spu_mul(ftexels[ 5], spu_mul(sWeights0, tWeights1)); /*ur*/ + ftexels[ 9] = spu_mul(ftexels[ 9], spu_mul(sWeights1, tWeights0)); /*ll*/ + ftexels[13] = spu_mul(ftexels[13], spu_mul(sWeights0, tWeights0)); /*lr*/ + colors[1] = spu_add(spu_add(ftexels[1], ftexels[5]), + spu_add(ftexels[9], ftexels[13])); + + /* blues, for four pixels */ + ftexels[ 2] = spu_mul(ftexels[ 2], spu_mul(sWeights1, tWeights1)); /*ul*/ + ftexels[ 6] = spu_mul(ftexels[ 6], spu_mul(sWeights0, tWeights1)); /*ur*/ + ftexels[10] = spu_mul(ftexels[10], spu_mul(sWeights1, tWeights0)); /*ll*/ + ftexels[14] = spu_mul(ftexels[14], spu_mul(sWeights0, tWeights0)); /*lr*/ + colors[2] = spu_add(spu_add(ftexels[2], ftexels[6]), + spu_add(ftexels[10], ftexels[14])); + + /* alphas, for four pixels */ + ftexels[ 3] = spu_mul(ftexels[ 3], spu_mul(sWeights1, tWeights1)); /*ul*/ + ftexels[ 7] = spu_mul(ftexels[ 7], spu_mul(sWeights0, tWeights1)); /*ur*/ + ftexels[11] = spu_mul(ftexels[11], spu_mul(sWeights1, tWeights0)); /*ll*/ + ftexels[15] = spu_mul(ftexels[15], spu_mul(sWeights0, tWeights0)); /*lr*/ + colors[3] = spu_add(spu_add(ftexels[3], ftexels[7]), + spu_add(ftexels[11], ftexels[15])); +} + + + +/** + * Adapted from /opt/cell/sdk/usr/spu/include/transpose_matrix4x4.h + */ +static INLINE void +transpose(vector unsigned int *mOut0, + vector unsigned int *mOut1, + vector unsigned int *mOut2, + vector unsigned int *mOut3, + vector unsigned int *mIn) +{ + vector unsigned int abcd, efgh, ijkl, mnop; /* input vectors */ + vector unsigned int aeim, bfjn, cgko, dhlp; /* output vectors */ + vector unsigned int aibj, ckdl, emfn, gohp; /* intermediate vectors */ + + vector unsigned char shufflehi = ((vector unsigned char) { + 0x00, 0x01, 0x02, 0x03, + 0x10, 0x11, 0x12, 0x13, + 0x04, 0x05, 0x06, 0x07, + 0x14, 0x15, 0x16, 0x17}); + vector unsigned char shufflelo = ((vector unsigned char) { + 0x08, 0x09, 0x0A, 0x0B, + 0x18, 0x19, 0x1A, 0x1B, + 0x0C, 0x0D, 0x0E, 0x0F, + 0x1C, 0x1D, 0x1E, 0x1F}); + abcd = *(mIn+0); + efgh = *(mIn+1); + ijkl = *(mIn+2); + mnop = *(mIn+3); + + aibj = spu_shuffle(abcd, ijkl, shufflehi); + ckdl = spu_shuffle(abcd, ijkl, shufflelo); + emfn = spu_shuffle(efgh, mnop, shufflehi); + gohp = spu_shuffle(efgh, mnop, shufflelo); + + aeim = spu_shuffle(aibj, emfn, shufflehi); + bfjn = spu_shuffle(aibj, emfn, shufflelo); + cgko = spu_shuffle(ckdl, gohp, shufflehi); + dhlp = spu_shuffle(ckdl, gohp, shufflelo); + + *mOut0 = aeim; + *mOut1 = bfjn; + *mOut2 = cgko; + *mOut3 = dhlp; +} + + +/** + * Bilinear filtering, using int instead of float arithmetic for computing + * sample weights. + */ +void +sample_texture_2d_bilinear_int(vector float s, vector float t, + uint unit, uint level, uint face, + vector float colors[4]) +{ + const struct spu_texture_level *tlevel = &spu.texture[unit].level[level]; + static const vector float half = {-0.5f, -0.5f, -0.5f, -0.5f}; + + /* Scale texcoords by size of texture, and add half pixel bias */ + vector float ss = spu_madd(s, tlevel->scale_s, half); + vector float tt = spu_madd(t, tlevel->scale_t, half); + + /* convert float coords to fixed-pt coords with 7 fraction bits */ + vector signed int is = spu_convts(ss, 7); /* XXX really need floor() here */ + vector signed int it = spu_convts(tt, 7); /* XXX really need floor() here */ + + /* compute integer texel weights in [0, 127] */ + vector signed int sWeights0 = spu_and(is, 127); + vector signed int tWeights0 = spu_and(it, 127); + vector signed int sWeights1 = spu_sub(127, sWeights0); + vector signed int tWeights1 = spu_sub(127, tWeights0); + + /* texel coords: is0 = is / 128, it0 = is / 128 */ + vector signed int is0 = spu_rlmask(is, -7); + vector signed int it0 = spu_rlmask(it, -7); + + /* texel coords: i1 = is0 + 1, it1 = it0 + 1 */ + vector signed int is1 = spu_add(is0, 1); + vector signed int it1 = spu_add(it0, 1); + + /* PIPE_TEX_WRAP_REPEAT */ + is0 = spu_and(is0, tlevel->mask_s); + it0 = spu_and(it0, tlevel->mask_t); + is1 = spu_and(is1, tlevel->mask_s); + it1 = spu_and(it1, tlevel->mask_t); + + /* PIPE_TEX_WRAP_CLAMP */ + is0 = spu_clamp(is0, tlevel->max_s); + it0 = spu_clamp(it0, tlevel->max_t); + is1 = spu_clamp(is1, tlevel->max_s); + it1 = spu_clamp(it1, tlevel->max_t); + + /* get packed int texels */ + vector unsigned int texels[16]; + get_four_texels(tlevel, face, is0, it0, texels + 0); /* upper-left */ + get_four_texels(tlevel, face, is1, it0, texels + 4); /* upper-right */ + get_four_texels(tlevel, face, is0, it1, texels + 8); /* lower-left */ + get_four_texels(tlevel, face, is1, it1, texels + 12); /* lower-right */ + + /* twiddle packed 32-bit BGRA pixels into RGBA as four unsigned ints */ + { + static const unsigned char ZERO = 0x80; + int i; + for (i = 0; i < 16; i++) { + texels[i] = spu_shuffle(texels[i], texels[i], + ((vector unsigned char) { + ZERO, ZERO, ZERO, 1, + ZERO, ZERO, ZERO, 2, + ZERO, ZERO, ZERO, 3, + ZERO, ZERO, ZERO, 0})); + } + } + + /* convert RGBA,RGBA,RGBA,RGBA to RRRR,GGGG,BBBB,AAAA */ + vector unsigned int texel0, texel1, texel2, texel3, texel4, texel5, texel6, texel7, + texel8, texel9, texel10, texel11, texel12, texel13, texel14, texel15; + transpose(&texel0, &texel1, &texel2, &texel3, texels + 0); + transpose(&texel4, &texel5, &texel6, &texel7, texels + 4); + transpose(&texel8, &texel9, &texel10, &texel11, texels + 8); + transpose(&texel12, &texel13, &texel14, &texel15, texels + 12); + + /* computed weighted colors */ + vector unsigned int c0, c1, c2, c3, cSum; + + /* red */ + c0 = (vector unsigned int) si_mpy((qword) texel0, si_mpy((qword) sWeights1, (qword) tWeights1)); /*ul*/ + c1 = (vector unsigned int) si_mpy((qword) texel4, si_mpy((qword) sWeights0, (qword) tWeights1)); /*ur*/ + c2 = (vector unsigned int) si_mpy((qword) texel8, si_mpy((qword) sWeights1, (qword) tWeights0)); /*ll*/ + c3 = (vector unsigned int) si_mpy((qword) texel12, si_mpy((qword) sWeights0, (qword) tWeights0)); /*lr*/ + cSum = spu_add(spu_add(c0, c1), spu_add(c2, c3)); + colors[0] = spu_convtf(cSum, 22); + + /* green */ + c0 = (vector unsigned int) si_mpy((qword) texel1, si_mpy((qword) sWeights1, (qword) tWeights1)); /*ul*/ + c1 = (vector unsigned int) si_mpy((qword) texel5, si_mpy((qword) sWeights0, (qword) tWeights1)); /*ur*/ + c2 = (vector unsigned int) si_mpy((qword) texel9, si_mpy((qword) sWeights1, (qword) tWeights0)); /*ll*/ + c3 = (vector unsigned int) si_mpy((qword) texel13, si_mpy((qword) sWeights0, (qword) tWeights0)); /*lr*/ + cSum = spu_add(spu_add(c0, c1), spu_add(c2, c3)); + colors[1] = spu_convtf(cSum, 22); + + /* blue */ + c0 = (vector unsigned int) si_mpy((qword) texel2, si_mpy((qword) sWeights1, (qword) tWeights1)); /*ul*/ + c1 = (vector unsigned int) si_mpy((qword) texel6, si_mpy((qword) sWeights0, (qword) tWeights1)); /*ur*/ + c2 = (vector unsigned int) si_mpy((qword) texel10, si_mpy((qword) sWeights1, (qword) tWeights0)); /*ll*/ + c3 = (vector unsigned int) si_mpy((qword) texel14, si_mpy((qword) sWeights0, (qword) tWeights0)); /*lr*/ + cSum = spu_add(spu_add(c0, c1), spu_add(c2, c3)); + colors[2] = spu_convtf(cSum, 22); + + /* alpha */ + c0 = (vector unsigned int) si_mpy((qword) texel3, si_mpy((qword) sWeights1, (qword) tWeights1)); /*ul*/ + c1 = (vector unsigned int) si_mpy((qword) texel7, si_mpy((qword) sWeights0, (qword) tWeights1)); /*ur*/ + c2 = (vector unsigned int) si_mpy((qword) texel11, si_mpy((qword) sWeights1, (qword) tWeights0)); /*ll*/ + c3 = (vector unsigned int) si_mpy((qword) texel15, si_mpy((qword) sWeights0, (qword) tWeights0)); /*lr*/ + cSum = spu_add(spu_add(c0, c1), spu_add(c2, c3)); + colors[3] = spu_convtf(cSum, 22); +} + + + +/** + * Compute level of detail factor from texcoords. + */ +static INLINE float +compute_lambda_2d(uint unit, vector float s, vector float t) +{ + uint baseLevel = 0; + float width = spu.texture[unit].level[baseLevel].width; + float height = spu.texture[unit].level[baseLevel].width; + float dsdx = width * (spu_extract(s, 1) - spu_extract(s, 0)); + float dsdy = width * (spu_extract(s, 2) - spu_extract(s, 0)); + float dtdx = height * (spu_extract(t, 1) - spu_extract(t, 0)); + float dtdy = height * (spu_extract(t, 2) - spu_extract(t, 0)); +#if 0 + /* ideal value */ + float x = dsdx * dsdx + dtdx * dtdx; + float y = dsdy * dsdy + dtdy * dtdy; + float rho = x > y ? x : y; + rho = sqrtf(rho); +#else + /* approximation */ + dsdx = fabsf(dsdx); + dsdy = fabsf(dsdy); + dtdx = fabsf(dtdx); + dtdy = fabsf(dtdy); + float rho = (dsdx + dsdy + dtdx + dtdy) * 0.5; +#endif + float lambda = logf(rho) * 1.442695f; /* compute logbase2(rho) */ + return lambda; +} + + +/** + * Blend two sets of colors according to weight. + */ +static void +blend_colors(vector float c0[4], const vector float c1[4], float weight) +{ + vector float t = spu_splats(weight); + vector float dc0 = spu_sub(c1[0], c0[0]); + vector float dc1 = spu_sub(c1[1], c0[1]); + vector float dc2 = spu_sub(c1[2], c0[2]); + vector float dc3 = spu_sub(c1[3], c0[3]); + c0[0] = spu_madd(dc0, t, c0[0]); + c0[1] = spu_madd(dc1, t, c0[1]); + c0[2] = spu_madd(dc2, t, c0[2]); + c0[3] = spu_madd(dc3, t, c0[3]); +} + + +/** + * Texture sampling with level of detail selection and possibly mipmap + * interpolation. + */ +void +sample_texture_2d_lod(vector float s, vector float t, + uint unit, uint level_ignored, uint face, + vector float colors[4]) +{ + /* + * Note that we're computing a lambda/lod here that's used for all + * four pixels in the quad. + */ + float lambda = compute_lambda_2d(unit, s, t); + + (void) face; + (void) level_ignored; + + /* apply lod bias */ + lambda += spu.sampler[unit].lod_bias; + + /* clamp */ + if (lambda < spu.sampler[unit].min_lod) + lambda = spu.sampler[unit].min_lod; + else if (lambda > spu.sampler[unit].max_lod) + lambda = spu.sampler[unit].max_lod; + + if (lambda <= 0.0f) { + /* magnify */ + spu.mag_sample_texture_2d[unit](s, t, unit, 0, face, colors); + } + else { + /* minify */ + if (spu.sampler[unit].min_img_filter == PIPE_TEX_FILTER_LINEAR) { + /* sample two mipmap levels and interpolate */ + int level = (int) lambda; + if (level > (int) spu.texture[unit].max_level) + level = spu.texture[unit].max_level; + spu.min_sample_texture_2d[unit](s, t, unit, level, face, colors); + if (spu.sampler[unit].min_img_filter == PIPE_TEX_FILTER_LINEAR) { + /* sample second mipmap level */ + float weight = lambda - (float) level; + level++; + if (level <= (int) spu.texture[unit].max_level) { + vector float colors2[4]; + spu.min_sample_texture_2d[unit](s, t, unit, level, face, colors2); + blend_colors(colors, colors2, weight); + } + } + } + else { + /* sample one mipmap level */ + int level = (int) (lambda + 0.5f); + if (level > (int) spu.texture[unit].max_level) + level = spu.texture[unit].max_level; + spu.min_sample_texture_2d[unit](s, t, unit, level, face, colors); + } + } +} + + +/** XXX need a SIMD version of this */ +static unsigned +choose_cube_face(float rx, float ry, float rz, float *newS, float *newT) +{ + /* + major axis + direction target sc tc ma + ---------- ------------------------------- --- --- --- + +rx TEXTURE_CUBE_MAP_POSITIVE_X_EXT -rz -ry rx + -rx TEXTURE_CUBE_MAP_NEGATIVE_X_EXT +rz -ry rx + +ry TEXTURE_CUBE_MAP_POSITIVE_Y_EXT +rx +rz ry + -ry TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT +rx -rz ry + +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz + -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz + */ + const float arx = fabsf(rx); + const float ary = fabsf(ry); + const float arz = fabsf(rz); + unsigned face; + float sc, tc, ma; + + if (arx > ary && arx > arz) { + if (rx >= 0.0F) { + face = PIPE_TEX_FACE_POS_X; + sc = -rz; + tc = -ry; + ma = arx; + } + else { + face = PIPE_TEX_FACE_NEG_X; + sc = rz; + tc = -ry; + ma = arx; + } + } + else if (ary > arx && ary > arz) { + if (ry >= 0.0F) { + face = PIPE_TEX_FACE_POS_Y; + sc = rx; + tc = rz; + ma = ary; + } + else { + face = PIPE_TEX_FACE_NEG_Y; + sc = rx; + tc = -rz; + ma = ary; + } + } + else { + if (rz > 0.0F) { + face = PIPE_TEX_FACE_POS_Z; + sc = rx; + tc = -ry; + ma = arz; + } + else { + face = PIPE_TEX_FACE_NEG_Z; + sc = -rx; + tc = -ry; + ma = arz; + } + } + + *newS = (sc / ma + 1.0F) * 0.5F; + *newT = (tc / ma + 1.0F) * 0.5F; + + return face; +} + + + +void +sample_texture_cube(vector float s, vector float t, vector float r, + uint unit, vector float colors[4]) +{ + uint p, faces[4], level = 0; + float newS[4], newT[4]; + + /* Compute cube faces referenced by the four sets of texcoords. + * XXX we should SIMD-ize this. + */ + for (p = 0; p < 4; p++) { + float rx = spu_extract(s, p); + float ry = spu_extract(t, p); + float rz = spu_extract(r, p); + faces[p] = choose_cube_face(rx, ry, rz, &newS[p], &newT[p]); + } + + if (faces[0] == faces[1] && + faces[0] == faces[2] && + faces[0] == faces[3]) { + /* GOOD! All four texcoords refer to the same cube face */ + s = (vector float) {newS[0], newS[1], newS[2], newS[3]}; + t = (vector float) {newT[0], newT[1], newT[2], newT[3]}; + spu.sample_texture_2d[unit](s, t, unit, level, faces[0], colors); + } + else { + /* BAD! The four texcoords refer to different faces */ + for (p = 0; p < 4; p++) { + vector float c[4]; + + spu.sample_texture_2d[unit](spu_splats(newS[p]), spu_splats(newT[p]), + unit, level, faces[p], c); + + float red = spu_extract(c[0], p); + float green = spu_extract(c[1], p); + float blue = spu_extract(c[2], p); + float alpha = spu_extract(c[3], p); + + colors[0] = spu_insert(red, colors[0], p); + colors[1] = spu_insert(green, colors[1], p); + colors[2] = spu_insert(blue, colors[2], p); + colors[3] = spu_insert(alpha, colors[3], p); + } + } +} diff --git a/src/gallium/drivers/cell/spu/spu_texture.h b/src/gallium/drivers/cell/spu/spu_texture.h new file mode 100644 index 0000000..7b75b00 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_texture.h @@ -0,0 +1,67 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef SPU_TEXTURE_H +#define SPU_TEXTURE_H + + +#include "pipe/p_compiler.h" + + +extern void +invalidate_tex_cache(void); + + +extern void +sample_texture_2d_nearest(vector float s, vector float t, + uint unit, uint level, uint face, + vector float colors[4]); + + +extern void +sample_texture_2d_bilinear(vector float s, vector float t, + uint unit, uint level, uint face, + vector float colors[4]); + +extern void +sample_texture_2d_bilinear_int(vector float s, vector float t, + uint unit, uint level, uint face, + vector float colors[4]); + + +extern void +sample_texture_2d_lod(vector float s, vector float t, + uint unit, uint level, uint face, + vector float colors[4]); + + +extern void +sample_texture_cube(vector float s, vector float t, vector float r, + uint unit, vector float colors[4]); + + +#endif /* SPU_TEXTURE_H */ diff --git a/src/gallium/drivers/cell/spu/spu_tgsi_exec.h b/src/gallium/drivers/cell/spu/spu_tgsi_exec.h new file mode 100644 index 0000000..6f2a3d3 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_tgsi_exec.h @@ -0,0 +1,158 @@ +/************************************************************************** + * + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2009-2010 VMware, Inc. All rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL 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. + * + **************************************************************************/ + +#ifndef SPU_TGSI_EXEC_H +#define SPU_TGSI_EXEC_H + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" + +#if defined __cplusplus +extern "C" { +#endif + + +#define NUM_CHANNELS 4 /* R,G,B,A */ +#define QUAD_SIZE 4 /* 4 pixel/quad */ + + + +#define TGSI_EXEC_NUM_TEMPS 128 +#define TGSI_EXEC_NUM_IMMEDIATES 256 + +/* + * Locations of various utility registers (_I = Index, _C = Channel) + */ +#define TGSI_EXEC_TEMP_00000000_IDX (TGSI_EXEC_NUM_TEMPS + 0) +#define TGSI_EXEC_TEMP_00000000_CHAN 0 + +#define TGSI_EXEC_TEMP_7FFFFFFF_IDX (TGSI_EXEC_NUM_TEMPS + 0) +#define TGSI_EXEC_TEMP_7FFFFFFF_CHAN 1 + +#define TGSI_EXEC_TEMP_80000000_IDX (TGSI_EXEC_NUM_TEMPS + 0) +#define TGSI_EXEC_TEMP_80000000_CHAN 2 + +#define TGSI_EXEC_TEMP_FFFFFFFF_IDX (TGSI_EXEC_NUM_TEMPS + 0) +#define TGSI_EXEC_TEMP_FFFFFFFF_CHAN 3 + +#define TGSI_EXEC_TEMP_ONE_IDX (TGSI_EXEC_NUM_TEMPS + 1) +#define TGSI_EXEC_TEMP_ONE_CHAN 0 + +#define TGSI_EXEC_TEMP_TWO_IDX (TGSI_EXEC_NUM_TEMPS + 1) +#define TGSI_EXEC_TEMP_TWO_CHAN 1 + +#define TGSI_EXEC_TEMP_128_IDX (TGSI_EXEC_NUM_TEMPS + 1) +#define TGSI_EXEC_TEMP_128_CHAN 2 + +#define TGSI_EXEC_TEMP_MINUS_128_IDX (TGSI_EXEC_NUM_TEMPS + 1) +#define TGSI_EXEC_TEMP_MINUS_128_CHAN 3 + +#define TGSI_EXEC_TEMP_KILMASK_IDX (TGSI_EXEC_NUM_TEMPS + 2) +#define TGSI_EXEC_TEMP_KILMASK_CHAN 0 + +#define TGSI_EXEC_TEMP_OUTPUT_IDX (TGSI_EXEC_NUM_TEMPS + 2) +#define TGSI_EXEC_TEMP_OUTPUT_CHAN 1 + +#define TGSI_EXEC_TEMP_PRIMITIVE_IDX (TGSI_EXEC_NUM_TEMPS + 2) +#define TGSI_EXEC_TEMP_PRIMITIVE_CHAN 2 + +/* NVIDIA condition code (CC) vector + */ +#define TGSI_EXEC_CC_GT 0x01 +#define TGSI_EXEC_CC_EQ 0x02 +#define TGSI_EXEC_CC_LT 0x04 +#define TGSI_EXEC_CC_UN 0x08 + +#define TGSI_EXEC_CC_X_MASK 0x000000ff +#define TGSI_EXEC_CC_X_SHIFT 0 +#define TGSI_EXEC_CC_Y_MASK 0x0000ff00 +#define TGSI_EXEC_CC_Y_SHIFT 8 +#define TGSI_EXEC_CC_Z_MASK 0x00ff0000 +#define TGSI_EXEC_CC_Z_SHIFT 16 +#define TGSI_EXEC_CC_W_MASK 0xff000000 +#define TGSI_EXEC_CC_W_SHIFT 24 + +#define TGSI_EXEC_TEMP_CC_IDX (TGSI_EXEC_NUM_TEMPS + 2) +#define TGSI_EXEC_TEMP_CC_CHAN 3 + +#define TGSI_EXEC_TEMP_THREE_IDX (TGSI_EXEC_NUM_TEMPS + 3) +#define TGSI_EXEC_TEMP_THREE_CHAN 0 + +#define TGSI_EXEC_TEMP_HALF_IDX (TGSI_EXEC_NUM_TEMPS + 3) +#define TGSI_EXEC_TEMP_HALF_CHAN 1 + +/* execution mask, each value is either 0 or ~0 */ +#define TGSI_EXEC_MASK_IDX (TGSI_EXEC_NUM_TEMPS + 3) +#define TGSI_EXEC_MASK_CHAN 2 + +/* 4 register buffer for various purposes */ +#define TGSI_EXEC_TEMP_R0 (TGSI_EXEC_NUM_TEMPS + 4) +#define TGSI_EXEC_NUM_TEMP_R 4 + +#define TGSI_EXEC_TEMP_ADDR (TGSI_EXEC_NUM_TEMPS + 8) +#define TGSI_EXEC_NUM_ADDRS 1 + +/* predicate register */ +#define TGSI_EXEC_TEMP_P0 (TGSI_EXEC_NUM_TEMPS + 9) +#define TGSI_EXEC_NUM_PREDS 1 + +#define TGSI_EXEC_NUM_TEMP_EXTRAS 10 + + + +#define TGSI_EXEC_MAX_NESTING 32 +#define TGSI_EXEC_MAX_COND_NESTING TGSI_EXEC_MAX_NESTING +#define TGSI_EXEC_MAX_LOOP_NESTING TGSI_EXEC_MAX_NESTING +#define TGSI_EXEC_MAX_SWITCH_NESTING TGSI_EXEC_MAX_NESTING +#define TGSI_EXEC_MAX_CALL_NESTING TGSI_EXEC_MAX_NESTING + +/* The maximum number of input attributes per vertex. For 2D + * input register files, this is the stride between two 1D + * arrays. + */ +#define TGSI_EXEC_MAX_INPUT_ATTRIBS 17 + +/* The maximum number of constant vectors per constant buffer. + */ +#define TGSI_EXEC_MAX_CONST_BUFFER 4096 + +/* The maximum number of vertices per primitive */ +#define TGSI_MAX_PRIM_VERTICES 6 + +/* The maximum number of primitives to be generated */ +#define TGSI_MAX_PRIMITIVES 64 + +/* The maximum total number of vertices */ +#define TGSI_MAX_TOTAL_VERTICES (TGSI_MAX_PRIM_VERTICES * TGSI_MAX_PRIMITIVES * PIPE_MAX_ATTRIBS) + + +#if defined __cplusplus +} /* extern "C" */ +#endif + +#endif /* TGSI_EXEC_H */ diff --git a/src/gallium/drivers/cell/spu/spu_tile.c b/src/gallium/drivers/cell/spu/spu_tile.c new file mode 100644 index 0000000..6905015 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_tile.c @@ -0,0 +1,126 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + + +#include "spu_tile.h" +#include "spu_main.h" + + +/** + * Get tile of color or Z values from main memory, put into SPU memory. + */ +void +get_tile(uint tx, uint ty, tile_t *tile, int tag, int zBuf) +{ + const uint offset = ty * spu.fb.width_tiles + tx; + const uint bytesPerTile = TILE_SIZE * TILE_SIZE * (zBuf ? spu.fb.zsize : 4); + const ubyte *src = zBuf ? spu.fb.depth_start : spu.fb.color_start; + + src += offset * bytesPerTile; + + ASSERT(tx < spu.fb.width_tiles); + ASSERT(ty < spu.fb.height_tiles); + ASSERT_ALIGN16(tile); + /* + printf("get_tile: dest: %p src: 0x%x size: %d\n", + tile, (unsigned int) src, bytesPerTile); + */ + mfc_get(tile->ui, /* dest in local memory */ + (unsigned int) src, /* src in main memory */ + bytesPerTile, + tag, + 0, /* tid */ + 0 /* rid */); +} + + +/** + * Move tile of color or Z values from SPU memory to main memory. + */ +void +put_tile(uint tx, uint ty, const tile_t *tile, int tag, int zBuf) +{ + const uint offset = ty * spu.fb.width_tiles + tx; + const uint bytesPerTile = TILE_SIZE * TILE_SIZE * (zBuf ? spu.fb.zsize : 4); + ubyte *dst = zBuf ? spu.fb.depth_start : spu.fb.color_start; + + dst += offset * bytesPerTile; + + ASSERT(tx < spu.fb.width_tiles); + ASSERT(ty < spu.fb.height_tiles); + ASSERT_ALIGN16(tile); + /* + printf("SPU %u: put_tile: src: %p dst: 0x%x size: %d\n", + spu.init.id, + tile, (unsigned int) dst, bytesPerTile); + */ + mfc_put((void *) tile->ui, /* src in local memory */ + (unsigned int) dst, /* dst in main memory */ + bytesPerTile, + tag, + 0, /* tid */ + 0 /* rid */); +} + + +/** + * For tiles whose status is TILE_STATUS_CLEAR, write solid-filled + * tiles back to the main framebuffer. + */ +void +really_clear_tiles(uint surfaceIndex) +{ + const uint num_tiles = spu.fb.width_tiles * spu.fb.height_tiles; + uint i; + + if (surfaceIndex == 0) { + clear_c_tile(&spu.ctile); + + for (i = spu.init.id; i < num_tiles; i += spu.init.num_spus) { + uint tx = i % spu.fb.width_tiles; + uint ty = i / spu.fb.width_tiles; + if (spu.ctile_status[ty][tx] == TILE_STATUS_CLEAR) { + put_tile(tx, ty, &spu.ctile, TAG_SURFACE_CLEAR, 0); + } + } + } + else { + clear_z_tile(&spu.ztile); + + for (i = spu.init.id; i < num_tiles; i += spu.init.num_spus) { + uint tx = i % spu.fb.width_tiles; + uint ty = i / spu.fb.width_tiles; + if (spu.ztile_status[ty][tx] == TILE_STATUS_CLEAR) + put_tile(tx, ty, &spu.ctile, TAG_SURFACE_CLEAR, 1); + } + } + +#if 0 + wait_on_mask(1 << TAG_SURFACE_CLEAR); +#endif +} diff --git a/src/gallium/drivers/cell/spu/spu_tile.h b/src/gallium/drivers/cell/spu/spu_tile.h new file mode 100644 index 0000000..7bfb52b --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_tile.h @@ -0,0 +1,75 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef SPU_TILE_H +#define SPU_TILE_H + + +#include +#include +#include "spu_main.h" +#include "cell/common.h" + + + +extern void +get_tile(uint tx, uint ty, tile_t *tile, int tag, int zBuf); + +extern void +put_tile(uint tx, uint ty, const tile_t *tile, int tag, int zBuf); + +extern void +really_clear_tiles(uint surfaceIndex); + + +static INLINE void +clear_c_tile(tile_t *ctile) +{ + memset32((uint*) ctile->ui, + spu.fb.color_clear_value, + TILE_SIZE * TILE_SIZE); +} + + +static INLINE void +clear_z_tile(tile_t *ztile) +{ + if (spu.fb.zsize == 2) { + memset16((ushort*) ztile->us, + spu.fb.depth_clear_value, + TILE_SIZE * TILE_SIZE); + } + else { + ASSERT(spu.fb.zsize != 0); + memset32((uint*) ztile->ui, + spu.fb.depth_clear_value, + TILE_SIZE * TILE_SIZE); + } +} + + +#endif /* SPU_TILE_H */ diff --git a/src/gallium/drivers/cell/spu/spu_tri.c b/src/gallium/drivers/cell/spu/spu_tri.c new file mode 100644 index 0000000..efeebca --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_tri.c @@ -0,0 +1,843 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Triangle rendering within a tile. + */ + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_math.h" +#include "spu_colorpack.h" +#include "spu_main.h" +#include "spu_shuffle.h" +#include "spu_texture.h" +#include "spu_tile.h" +#include "spu_tri.h" + + +/** Masks are uint[4] vectors with each element being 0 or 0xffffffff */ +typedef vector unsigned int mask_t; + + + +/** + * Simplified types taken from other parts of Gallium + */ +struct vertex_header { + vector float data[1]; +}; + + + +/* XXX fix this */ +#undef CEILF +#define CEILF(X) ((float) (int) ((X) + 0.99999f)) + + +#define QUAD_TOP_LEFT 0 +#define QUAD_TOP_RIGHT 1 +#define QUAD_BOTTOM_LEFT 2 +#define QUAD_BOTTOM_RIGHT 3 +#define MASK_TOP_LEFT (1 << QUAD_TOP_LEFT) +#define MASK_TOP_RIGHT (1 << QUAD_TOP_RIGHT) +#define MASK_BOTTOM_LEFT (1 << QUAD_BOTTOM_LEFT) +#define MASK_BOTTOM_RIGHT (1 << QUAD_BOTTOM_RIGHT) +#define MASK_ALL 0xf + + +#define CHAN0 0 +#define CHAN1 1 +#define CHAN2 2 +#define CHAN3 3 + + +#define DEBUG_VERTS 0 + +/** + * Triangle edge info + */ +struct edge { + union { + struct { + float dx; /**< X(v1) - X(v0), used only during setup */ + float dy; /**< Y(v1) - Y(v0), used only during setup */ + }; + vec_float4 ds; /**< vector accessor for dx and dy */ + }; + float dxdy; /**< dx/dy */ + float sx, sy; /**< first sample point coord */ + int lines; /**< number of lines on this edge */ +}; + + +struct interp_coef +{ + vector float a0; + vector float dadx; + vector float dady; +}; + + +/** + * Triangle setup info (derived from draw_stage). + * Also used for line drawing (taking some liberties). + */ +struct setup_stage { + + /* Vertices are just an array of floats making up each attribute in + * turn. Currently fixed at 4 floats, but should change in time. + * Codegen will help cope with this. + */ + union { + struct { + const struct vertex_header *vmin; + const struct vertex_header *vmid; + const struct vertex_header *vmax; + const struct vertex_header *vprovoke; + }; + qword vertex_headers; + }; + + struct edge ebot; + struct edge etop; + struct edge emaj; + + float oneOverArea; /* XXX maybe make into vector? */ + + uint facing; + + uint tx, ty; /**< position of current tile (x, y) */ + + union { + struct { + int cliprect_minx; + int cliprect_miny; + int cliprect_maxx; + int cliprect_maxy; + }; + qword cliprect; + }; + + struct interp_coef coef[PIPE_MAX_SHADER_INPUTS]; + + struct { + vec_int4 quad; /**< [0] = row0, [1] = row1; {left[0],left[1],right[0],right[1]} */ + int y; + unsigned y_flags; + unsigned mask; /**< mask of MASK_BOTTOM/TOP_LEFT/RIGHT bits */ + } span; +}; + + +static struct setup_stage setup; + + +static INLINE vector float +splatx(vector float v) +{ + return spu_splats(spu_extract(v, CHAN0)); +} + +static INLINE vector float +splaty(vector float v) +{ + return spu_splats(spu_extract(v, CHAN1)); +} + +static INLINE vector float +splatz(vector float v) +{ + return spu_splats(spu_extract(v, CHAN2)); +} + +static INLINE vector float +splatw(vector float v) +{ + return spu_splats(spu_extract(v, CHAN3)); +} + + +/** + * Setup fragment shader inputs by evaluating triangle's vertex + * attribute coefficient info. + * \param x quad x pos + * \param y quad y pos + * \param fragZ returns quad Z values + * \param fragInputs returns fragment program inputs + * Note: this code could be incorporated into the fragment program + * itself to avoid the loop and switch. + */ +static void +eval_inputs(float x, float y, vector float *fragZ, vector float fragInputs[]) +{ + static const vector float deltaX = (const vector float) {0, 1, 0, 1}; + static const vector float deltaY = (const vector float) {0, 0, 1, 1}; + + const uint posSlot = 0; + const vector float pos = setup.coef[posSlot].a0; + const vector float dposdx = setup.coef[posSlot].dadx; + const vector float dposdy = setup.coef[posSlot].dady; + const vector float fragX = spu_splats(x) + deltaX; + const vector float fragY = spu_splats(y) + deltaY; + vector float fragW, wInv; + uint i; + + *fragZ = splatz(pos) + fragX * splatz(dposdx) + fragY * splatz(dposdy); + fragW = splatw(pos) + fragX * splatw(dposdx) + fragY * splatw(dposdy); + wInv = spu_re(fragW); /* 1 / w */ + + /* loop over fragment program inputs */ + for (i = 0; i < spu.vertex_info.num_attribs; i++) { + uint attr = i + 1; + enum interp_mode interp = spu.vertex_info.attrib[attr].interp_mode; + + /* constant term */ + vector float a0 = setup.coef[attr].a0; + vector float r0 = splatx(a0); + vector float r1 = splaty(a0); + vector float r2 = splatz(a0); + vector float r3 = splatw(a0); + + if (interp == INTERP_LINEAR || interp == INTERP_PERSPECTIVE) { + /* linear term */ + vector float dadx = setup.coef[attr].dadx; + vector float dady = setup.coef[attr].dady; + /* Use SPU intrinsics here to get slightly better code. + * originally: r0 += fragX * splatx(dadx) + fragY * splatx(dady); + */ + r0 = spu_madd(fragX, splatx(dadx), spu_madd(fragY, splatx(dady), r0)); + r1 = spu_madd(fragX, splaty(dadx), spu_madd(fragY, splaty(dady), r1)); + r2 = spu_madd(fragX, splatz(dadx), spu_madd(fragY, splatz(dady), r2)); + r3 = spu_madd(fragX, splatw(dadx), spu_madd(fragY, splatw(dady), r3)); + if (interp == INTERP_PERSPECTIVE) { + /* perspective term */ + r0 *= wInv; + r1 *= wInv; + r2 *= wInv; + r3 *= wInv; + } + } + fragInputs[CHAN0] = r0; + fragInputs[CHAN1] = r1; + fragInputs[CHAN2] = r2; + fragInputs[CHAN3] = r3; + fragInputs += 4; + } +} + + +/** + * Emit a quad (pass to next stage). No clipping is done. + * Note: about 1/5 to 1/7 of the time, mask is zero and this function + * should be skipped. But adding the test for that slows things down + * overall. + */ +static INLINE void +emit_quad( int x, int y, mask_t mask) +{ + /* If any bits in mask are set... */ + if (spu_extract(spu_orx(mask), 0)) { + const int ix = x - setup.cliprect_minx; + const int iy = y - setup.cliprect_miny; + + spu.cur_ctile_status = TILE_STATUS_DIRTY; + spu.cur_ztile_status = TILE_STATUS_DIRTY; + + { + /* + * Run fragment shader, execute per-fragment ops, update fb/tile. + */ + vector float inputs[4*4], outputs[2*4]; + vector unsigned int kill_mask; + vector float fragZ; + + eval_inputs((float) x, (float) y, &fragZ, inputs); + + ASSERT(spu.fragment_program); + ASSERT(spu.fragment_ops); + + /* Execute the current fragment program */ + kill_mask = spu.fragment_program(inputs, outputs, spu.constants); + + mask = spu_andc(mask, kill_mask); + + /* Execute per-fragment/quad operations, including: + * alpha test, z test, stencil test, blend and framebuffer writing. + * Note that there are two different fragment operations functions + * that can be called, one for front-facing fragments, and one + * for back-facing fragments. (Often the two are the same; + * but in some cases, like two-sided stenciling, they can be + * very different.) So choose the correct function depending + * on the calculated facing. + */ + spu.fragment_ops[setup.facing](ix, iy, &spu.ctile, &spu.ztile, + fragZ, + outputs[0*4+0], + outputs[0*4+1], + outputs[0*4+2], + outputs[0*4+3], + mask); + } + } +} + + +/** + * Given an X or Y coordinate, return the block/quad coordinate that it + * belongs to. + */ +static INLINE int +block(int x) +{ + return x & ~1; +} + + +/** + * Render a horizontal span of quads + */ +static void +flush_spans(void) +{ + int minleft, maxright; + + const int l0 = spu_extract(setup.span.quad, 0); + const int l1 = spu_extract(setup.span.quad, 1); + const int r0 = spu_extract(setup.span.quad, 2); + const int r1 = spu_extract(setup.span.quad, 3); + + switch (setup.span.y_flags) { + case 0x3: + /* both odd and even lines written (both quad rows) */ + minleft = MIN2(l0, l1); + maxright = MAX2(r0, r1); + break; + + case 0x1: + /* only even line written (quad top row) */ + minleft = l0; + maxright = r0; + break; + + case 0x2: + /* only odd line written (quad bottom row) */ + minleft = l1; + maxright = r1; + break; + + default: + return; + } + + /* OK, we're very likely to need the tile data now. + * clear or finish waiting if needed. + */ + if (spu.cur_ctile_status == TILE_STATUS_GETTING) { + /* wait for mfc_get() to complete */ + //printf("SPU: %u: waiting for ctile\n", spu.init.id); + wait_on_mask(1 << TAG_READ_TILE_COLOR); + spu.cur_ctile_status = TILE_STATUS_CLEAN; + } + else if (spu.cur_ctile_status == TILE_STATUS_CLEAR) { + //printf("SPU %u: clearing C tile %u, %u\n", spu.init.id, setup.tx, setup.ty); + clear_c_tile(&spu.ctile); + spu.cur_ctile_status = TILE_STATUS_DIRTY; + } + ASSERT(spu.cur_ctile_status != TILE_STATUS_DEFINED); + + if (spu.read_depth_stencil) { + if (spu.cur_ztile_status == TILE_STATUS_GETTING) { + /* wait for mfc_get() to complete */ + //printf("SPU: %u: waiting for ztile\n", spu.init.id); + wait_on_mask(1 << TAG_READ_TILE_Z); + spu.cur_ztile_status = TILE_STATUS_CLEAN; + } + else if (spu.cur_ztile_status == TILE_STATUS_CLEAR) { + //printf("SPU %u: clearing Z tile %u, %u\n", spu.init.id, setup.tx, setup.ty); + clear_z_tile(&spu.ztile); + spu.cur_ztile_status = TILE_STATUS_DIRTY; + } + ASSERT(spu.cur_ztile_status != TILE_STATUS_DEFINED); + } + + /* XXX this loop could be moved into the above switch cases... */ + + /* Setup for mask calculation */ + const vec_int4 quad_LlRr = setup.span.quad; + const vec_int4 quad_RrLl = spu_rlqwbyte(quad_LlRr, 8); + const vec_int4 quad_LLll = spu_shuffle(quad_LlRr, quad_LlRr, SHUFFLE4(A,A,B,B)); + const vec_int4 quad_RRrr = spu_shuffle(quad_RrLl, quad_RrLl, SHUFFLE4(A,A,B,B)); + + const vec_int4 twos = spu_splats(2); + + const int x = block(minleft); + vec_int4 xs = {x, x+1, x, x+1}; + + for (; spu_extract(xs, 0) <= block(maxright); xs += twos) { + /** + * Computes mask to indicate which pixels in the 2x2 quad are actually + * inside the triangle's bounds. + */ + + /* Calculate ({x,x+1,x,x+1} >= {l[0],l[0],l[1],l[1]}) */ + const mask_t gt_LLll_xs = spu_cmpgt(quad_LLll, xs); + const mask_t gte_xs_LLll = spu_nand(gt_LLll_xs, gt_LLll_xs); + + /* Calculate ({r[0],r[0],r[1],r[1]} > {x,x+1,x,x+1}) */ + const mask_t gt_RRrr_xs = spu_cmpgt(quad_RRrr, xs); + + /* Combine results to create mask */ + const mask_t mask = spu_and(gte_xs_LLll, gt_RRrr_xs); + + emit_quad(spu_extract(xs, 0), setup.span.y, mask); + } + + setup.span.y = 0; + setup.span.y_flags = 0; + /* Zero right elements */ + setup.span.quad = spu_shuffle(setup.span.quad, setup.span.quad, SHUFFLE4(A,B,0,0)); +} + + +#if DEBUG_VERTS +static void +print_vertex(const struct vertex_header *v) +{ + uint i; + fprintf(stderr, " Vertex: (%p)\n", v); + for (i = 0; i < spu.vertex_info.num_attribs; i++) { + fprintf(stderr, " %d: %f %f %f %f\n", i, + spu_extract(v->data[i], 0), + spu_extract(v->data[i], 1), + spu_extract(v->data[i], 2), + spu_extract(v->data[i], 3)); + } +} +#endif + +/* Returns the minimum of each slot of two vec_float4s as qwords. + * i.e. return[n] = min(q0[n],q1[n]); + */ +static qword +minfq(qword q0, qword q1) +{ + const qword q0q1m = si_fcgt(q0, q1); + return si_selb(q0, q1, q0q1m); +} + +/* Returns the minimum of each slot of three vec_float4s as qwords. + * i.e. return[n] = min(q0[n],q1[n],q2[n]); + */ +static qword +min3fq(qword q0, qword q1, qword q2) +{ + return minfq(minfq(q0, q1), q2); +} + +/* Returns the maximum of each slot of two vec_float4s as qwords. + * i.e. return[n] = min(q0[n],q1[n],q2[n]); + */ +static qword +maxfq(qword q0, qword q1) { + const qword q0q1m = si_fcgt(q0, q1); + return si_selb(q1, q0, q0q1m); +} + +/* Returns the maximum of each slot of three vec_float4s as qwords. + * i.e. return[n] = min(q0[n],q1[n],q2[n]); + */ +static qword +max3fq(qword q0, qword q1, qword q2) { + return maxfq(maxfq(q0, q1), q2); +} + +/** + * Sort vertices from top to bottom. + * Compute area and determine front vs. back facing. + * Do coarse clip test against tile bounds + * \return FALSE if tri is totally outside tile, TRUE otherwise + */ +static boolean +setup_sort_vertices(const qword vs) +{ + float area, sign; + +#if DEBUG_VERTS + if (spu.init.id==0) { + fprintf(stderr, "SPU %u: Triangle:\n", spu.init.id); + print_vertex(v0); + print_vertex(v1); + print_vertex(v2); + } +#endif + + { + /* Load the float values for various processing... */ + const qword f0 = (qword)(((const struct vertex_header*)si_to_ptr(vs))->data[0]); + const qword f1 = (qword)(((const struct vertex_header*)si_to_ptr(si_rotqbyi(vs, 4)))->data[0]); + const qword f2 = (qword)(((const struct vertex_header*)si_to_ptr(si_rotqbyi(vs, 8)))->data[0]); + + /* Check if triangle is completely outside the tile bounds + * Find the min and max x and y positions of the three poits */ + const qword minf = min3fq(f0, f1, f2); + const qword maxf = max3fq(f0, f1, f2); + + /* Compare min and max against cliprect vals */ + const qword maxsmins = si_shufb(maxf, minf, SHUFB4(A,B,a,b)); + const qword outside = si_fcgt(maxsmins, si_csflt(setup.cliprect, 0)); + + /* Use a little magic to work out of the tri is visible or not */ + if(si_to_uint(si_xori(si_gb(outside), 0xc))) return FALSE; + + /* determine bottom to top order of vertices */ + /* A table of shuffle patterns for putting vertex_header pointers into + correct order. Quite magical. */ + const qword sort_order_patterns[] = { + SHUFB4(A,B,C,C), + SHUFB4(C,A,B,C), + SHUFB4(A,C,B,C), + SHUFB4(B,C,A,C), + SHUFB4(B,A,C,C), + SHUFB4(C,B,A,C) }; + + /* Collate y values into two vectors for comparison. + Using only one shuffle constant! ;) */ + const qword y_02_ = si_shufb(f0, f2, SHUFB4(0,B,b,C)); + const qword y_10_ = si_shufb(f1, f0, SHUFB4(0,B,b,C)); + const qword y_012 = si_shufb(y_02_, f1, SHUFB4(0,B,b,C)); + const qword y_120 = si_shufb(y_10_, f2, SHUFB4(0,B,b,C)); + + /* Perform comparison: {y0,y1,y2} > {y1,y2,y0} */ + const qword compare = si_fcgt(y_012, y_120); + /* Compress the result of the comparison into 4 bits */ + const qword gather = si_gb(compare); + /* Subtract one to attain the index into the LUT. Magical. */ + const unsigned int index = si_to_uint(gather) - 1; + + /* Load the appropriate pattern and construct the desired vector. */ + setup.vertex_headers = si_shufb(vs, vs, sort_order_patterns[index]); + + /* Using the result of the comparison, set sign. + Very magical. */ + sign = ((si_to_uint(si_cntb(gather)) == 2) ? 1.0f : -1.0f); + } + + setup.ebot.ds = spu_sub(setup.vmid->data[0], setup.vmin->data[0]); + setup.emaj.ds = spu_sub(setup.vmax->data[0], setup.vmin->data[0]); + setup.etop.ds = spu_sub(setup.vmax->data[0], setup.vmid->data[0]); + + /* + * Compute triangle's area. Use 1/area to compute partial + * derivatives of attributes later. + */ + area = setup.emaj.dx * setup.ebot.dy - setup.ebot.dx * setup.emaj.dy; + + setup.oneOverArea = 1.0f / area; + + /* The product of area * sign indicates front/back orientation (0/1). + * Just in case someone gets the bright idea of switching the front + * and back constants without noticing that we're assuming their + * values in this operation, also assert that the values are + * what we think they are. + */ + ASSERT(CELL_FACING_FRONT == 0); + ASSERT(CELL_FACING_BACK == 1); + setup.facing = (area * sign > 0.0f) + ^ (!spu.rasterizer.front_ccw); + + return TRUE; +} + + +/** + * Compute a0 for a constant-valued coefficient (GL_FLAT shading). + * The value value comes from vertex->data[slot]. + * The result will be put into setup.coef[slot].a0. + * \param slot which attribute slot + */ +static INLINE void +const_coeff4(uint slot) +{ + setup.coef[slot].dadx = (vector float) {0.0, 0.0, 0.0, 0.0}; + setup.coef[slot].dady = (vector float) {0.0, 0.0, 0.0, 0.0}; + setup.coef[slot].a0 = setup.vprovoke->data[slot]; +} + + +/** + * As above, but interp setup all four vector components. + */ +static INLINE void +tri_linear_coeff4(uint slot) +{ + const vector float vmin_d = setup.vmin->data[slot]; + const vector float vmid_d = setup.vmid->data[slot]; + const vector float vmax_d = setup.vmax->data[slot]; + const vector float xxxx = spu_splats(spu_extract(setup.vmin->data[0], 0) - 0.5f); + const vector float yyyy = spu_splats(spu_extract(setup.vmin->data[0], 1) - 0.5f); + + vector float botda = vmid_d - vmin_d; + vector float majda = vmax_d - vmin_d; + + vector float a = spu_sub(spu_mul(spu_splats(setup.ebot.dy), majda), + spu_mul(botda, spu_splats(setup.emaj.dy))); + vector float b = spu_sub(spu_mul(spu_splats(setup.emaj.dx), botda), + spu_mul(majda, spu_splats(setup.ebot.dx))); + + setup.coef[slot].dadx = spu_mul(a, spu_splats(setup.oneOverArea)); + setup.coef[slot].dady = spu_mul(b, spu_splats(setup.oneOverArea)); + + vector float tempx = spu_mul(setup.coef[slot].dadx, xxxx); + vector float tempy = spu_mul(setup.coef[slot].dady, yyyy); + + setup.coef[slot].a0 = spu_sub(vmin_d, spu_add(tempx, tempy)); +} + + +/** + * Compute a0, dadx and dady for a perspective-corrected interpolant, + * for a triangle. + * We basically multiply the vertex value by 1/w before computing + * the plane coefficients (a0, dadx, dady). + * Later, when we compute the value at a particular fragment position we'll + * divide the interpolated value by the interpolated W at that fragment. + */ +static void +tri_persp_coeff4(uint slot) +{ + const vector float xxxx = spu_splats(spu_extract(setup.vmin->data[0], 0) - 0.5f); + const vector float yyyy = spu_splats(spu_extract(setup.vmin->data[0], 1) - 0.5f); + + const vector float vmin_w = spu_splats(spu_extract(setup.vmin->data[0], 3)); + const vector float vmid_w = spu_splats(spu_extract(setup.vmid->data[0], 3)); + const vector float vmax_w = spu_splats(spu_extract(setup.vmax->data[0], 3)); + + vector float vmin_d = setup.vmin->data[slot]; + vector float vmid_d = setup.vmid->data[slot]; + vector float vmax_d = setup.vmax->data[slot]; + + vmin_d = spu_mul(vmin_d, vmin_w); + vmid_d = spu_mul(vmid_d, vmid_w); + vmax_d = spu_mul(vmax_d, vmax_w); + + vector float botda = vmid_d - vmin_d; + vector float majda = vmax_d - vmin_d; + + vector float a = spu_sub(spu_mul(spu_splats(setup.ebot.dy), majda), + spu_mul(botda, spu_splats(setup.emaj.dy))); + vector float b = spu_sub(spu_mul(spu_splats(setup.emaj.dx), botda), + spu_mul(majda, spu_splats(setup.ebot.dx))); + + setup.coef[slot].dadx = spu_mul(a, spu_splats(setup.oneOverArea)); + setup.coef[slot].dady = spu_mul(b, spu_splats(setup.oneOverArea)); + + vector float tempx = spu_mul(setup.coef[slot].dadx, xxxx); + vector float tempy = spu_mul(setup.coef[slot].dady, yyyy); + + setup.coef[slot].a0 = spu_sub(vmin_d, spu_add(tempx, tempy)); +} + + + +/** + * Compute the setup.coef[] array dadx, dady, a0 values. + * Must be called after setup.vmin,vmid,vmax,vprovoke are initialized. + */ +static void +setup_tri_coefficients(void) +{ + uint i; + + for (i = 0; i < spu.vertex_info.num_attribs; i++) { + switch (spu.vertex_info.attrib[i].interp_mode) { + case INTERP_NONE: + break; + case INTERP_CONSTANT: + const_coeff4(i); + break; + case INTERP_POS: + /* fall-through */ + case INTERP_LINEAR: + tri_linear_coeff4(i); + break; + case INTERP_PERSPECTIVE: + tri_persp_coeff4(i); + break; + default: + ASSERT(0); + } + } +} + + +static void +setup_tri_edges(void) +{ + float vmin_x = spu_extract(setup.vmin->data[0], 0) + 0.5f; + float vmid_x = spu_extract(setup.vmid->data[0], 0) + 0.5f; + + float vmin_y = spu_extract(setup.vmin->data[0], 1) - 0.5f; + float vmid_y = spu_extract(setup.vmid->data[0], 1) - 0.5f; + float vmax_y = spu_extract(setup.vmax->data[0], 1) - 0.5f; + + setup.emaj.sy = CEILF(vmin_y); + setup.emaj.lines = (int) CEILF(vmax_y - setup.emaj.sy); + setup.emaj.dxdy = setup.emaj.dx / setup.emaj.dy; + setup.emaj.sx = vmin_x + (setup.emaj.sy - vmin_y) * setup.emaj.dxdy; + + setup.etop.sy = CEILF(vmid_y); + setup.etop.lines = (int) CEILF(vmax_y - setup.etop.sy); + setup.etop.dxdy = setup.etop.dx / setup.etop.dy; + setup.etop.sx = vmid_x + (setup.etop.sy - vmid_y) * setup.etop.dxdy; + + setup.ebot.sy = CEILF(vmin_y); + setup.ebot.lines = (int) CEILF(vmid_y - setup.ebot.sy); + setup.ebot.dxdy = setup.ebot.dx / setup.ebot.dy; + setup.ebot.sx = vmin_x + (setup.ebot.sy - vmin_y) * setup.ebot.dxdy; +} + + +/** + * Render the upper or lower half of a triangle. + * Scissoring/cliprect is applied here too. + */ +static void +subtriangle(struct edge *eleft, struct edge *eright, unsigned lines) +{ + const int minx = setup.cliprect_minx; + const int maxx = setup.cliprect_maxx; + const int miny = setup.cliprect_miny; + const int maxy = setup.cliprect_maxy; + int y, start_y, finish_y; + int sy = (int)eleft->sy; + + ASSERT((int)eleft->sy == (int) eright->sy); + + /* clip top/bottom */ + start_y = sy; + finish_y = sy + lines; + + if (start_y < miny) + start_y = miny; + + if (finish_y > maxy) + finish_y = maxy; + + start_y -= sy; + finish_y -= sy; + + /* + printf("%s %d %d\n", __FUNCTION__, start_y, finish_y); + */ + + for (y = start_y; y < finish_y; y++) { + + /* avoid accumulating adds as floats don't have the precision to + * accurately iterate large triangle edges that way. luckily we + * can just multiply these days. + * + * this is all drowned out by the attribute interpolation anyway. + */ + int left = (int)(eleft->sx + y * eleft->dxdy); + int right = (int)(eright->sx + y * eright->dxdy); + + /* clip left/right */ + if (left < minx) + left = minx; + if (right > maxx) + right = maxx; + + if (left < right) { + int _y = sy + y; + if (block(_y) != setup.span.y) { + flush_spans(); + setup.span.y = block(_y); + } + + int offset = _y&1; + vec_int4 quad_LlRr = {left, left, right, right}; + /* Store left and right in 0 or 1 row of quad based on offset */ + setup.span.quad = spu_sel(quad_LlRr, setup.span.quad, spu_maskw(5<sx += lines * eleft->dxdy; + eright->sx += lines * eright->dxdy; + eleft->sy += lines; + eright->sy += lines; +} + + +/** + * Draw triangle into tile at (tx, ty) (tile coords) + * The tile data should have already been fetched. + */ +boolean +tri_draw(const qword vs, + uint tx, uint ty) +{ + setup.tx = tx; + setup.ty = ty; + + /* set clipping bounds to tile bounds */ + const qword clipbase = (qword)((vec_uint4){tx, ty}); + const qword clipmin = si_mpyui(clipbase, TILE_SIZE); + const qword clipmax = si_ai(clipmin, TILE_SIZE); + setup.cliprect = si_shufb(clipmin, clipmax, SHUFB4(A,B,a,b)); + + if(!setup_sort_vertices(vs)) { + return FALSE; /* totally clipped */ + } + + setup_tri_coefficients(); + setup_tri_edges(); + + setup.span.y = 0; + setup.span.y_flags = 0; + /* Zero right elements */ + setup.span.quad = spu_shuffle(setup.span.quad, setup.span.quad, SHUFFLE4(A,B,0,0)); + + if (setup.oneOverArea < 0.0) { + /* emaj on left */ + subtriangle( &setup.emaj, &setup.ebot, setup.ebot.lines ); + subtriangle( &setup.emaj, &setup.etop, setup.etop.lines ); + } + else { + /* emaj on right */ + subtriangle( &setup.ebot, &setup.emaj, setup.ebot.lines ); + subtriangle( &setup.etop, &setup.emaj, setup.etop.lines ); + } + + flush_spans(); + + return TRUE; +} diff --git a/src/gallium/drivers/cell/spu/spu_tri.h b/src/gallium/drivers/cell/spu/spu_tri.h new file mode 100644 index 0000000..82e3b19 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_tri.h @@ -0,0 +1,37 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef SPU_TRI_H +#define SPU_TRI_H + + +extern boolean +tri_draw(const qword vs, uint tx, uint ty); + + +#endif /* SPU_TRI_H */ diff --git a/src/gallium/drivers/cell/spu/spu_util.c b/src/gallium/drivers/cell/spu/spu_util.c new file mode 100644 index 0000000..24057e2 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_util.c @@ -0,0 +1,77 @@ + +#include "cell/common.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_debug.h" +#include "tgsi/tgsi_parse.h" +//#include "tgsi_build.h" +#include "tgsi/tgsi_util.h" + +unsigned +tgsi_util_get_src_register_swizzle( + const struct tgsi_src_register *reg, + unsigned component ) +{ + switch( component ) { + case 0: + return reg->SwizzleX; + case 1: + return reg->SwizzleY; + case 2: + return reg->SwizzleZ; + case 3: + return reg->SwizzleW; + default: + ASSERT( 0 ); + } + return 0; +} + + +unsigned +tgsi_util_get_full_src_register_swizzle( + const struct tgsi_full_src_register *reg, + unsigned component ) +{ + return tgsi_util_get_src_register_swizzle( + reg->Register, + component ); +} + + +unsigned +tgsi_util_get_full_src_register_sign_mode( + const struct tgsi_full_src_register *reg, + unsigned component ) +{ + unsigned sign_mode; + + if( reg->RegisterExtMod.Absolute ) { + /* Consider only the post-abs negation. */ + + if( reg->RegisterExtMod.Negate ) { + sign_mode = TGSI_UTIL_SIGN_SET; + } + else { + sign_mode = TGSI_UTIL_SIGN_CLEAR; + } + } + else { + /* Accumulate the three negations. */ + + unsigned negate; + + negate = reg->Register.Negate; + if( reg->RegisterExtMod.Negate ) { + negate = !negate; + } + + if( negate ) { + sign_mode = TGSI_UTIL_SIGN_TOGGLE; + } + else { + sign_mode = TGSI_UTIL_SIGN_KEEP; + } + } + + return sign_mode; +} diff --git a/src/gallium/drivers/cell/spu/spu_vertex_fetch.c b/src/gallium/drivers/cell/spu/spu_vertex_fetch.c new file mode 100644 index 0000000..0879639 --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_vertex_fetch.c @@ -0,0 +1,146 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * (C) Copyright IBM Corporation 2008 + * 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. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + * Ian Romanick + */ + +#include "pipe/p_state.h" +#include "pipe/p_shader_tokens.h" +#include "spu_exec.h" +#include "spu_vertex_shader.h" +#include "spu_main.h" +#include "spu_dcache.h" + +typedef void (*spu_fetch_func)(qword *out, const qword *in, + const qword *shuffle_data); + + +PIPE_ALIGN_VAR(16) static const qword +fetch_shuffle_data[5] = { + /* Shuffle used by CVT_64_FLOAT + */ + { + 0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + }, + + /* Shuffle used by CVT_8_USCALED and CVT_8_SSCALED + */ + { + 0x00, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0x80, + 0x02, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, + }, + + /* Shuffle used by CVT_16_USCALED and CVT_16_SSCALED + */ + { + 0x00, 0x01, 0x80, 0x80, 0x02, 0x03, 0x80, 0x80, + 0x04, 0x05, 0x80, 0x80, 0x06, 0x07, 0x80, 0x80, + }, + + /* High value shuffle used by trans4x4. + */ + { + 0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13, + 0x04, 0x05, 0x06, 0x07, 0x14, 0x15, 0x16, 0x17 + }, + + /* Low value shuffle used by trans4x4. + */ + { + 0x08, 0x09, 0x0A, 0x0B, 0x18, 0x19, 0x1A, 0x1B, + 0x0C, 0x0D, 0x0E, 0x0F, 0x1C, 0x1D, 0x1E, 0x1F + } +}; + + +/** + * Fetch vertex attributes for 'count' vertices. + */ +static void generic_vertex_fetch(struct spu_vs_context *draw, + struct spu_exec_machine *machine, + const unsigned *elts, + unsigned count) +{ + unsigned nr_attrs = draw->vertex_fetch.nr_attrs; + unsigned attr; + + ASSERT(count <= 4); + +#if DRAW_DBG + printf("SPU: %s count = %u, nr_attrs = %u\n", + __FUNCTION__, count, nr_attrs); +#endif + + /* loop over vertex attributes (vertex shader inputs) + */ + for (attr = 0; attr < nr_attrs; attr++) { + const unsigned pitch = draw->vertex_fetch.pitch[attr]; + const uint64_t src = draw->vertex_fetch.src_ptr[attr]; + const spu_fetch_func fetch = (spu_fetch_func) + (draw->vertex_fetch.code + draw->vertex_fetch.code_offset[attr]); + unsigned i; + unsigned idx; + const unsigned bytes_per_entry = draw->vertex_fetch.size[attr]; + const unsigned quads_per_entry = (bytes_per_entry + 15) / 16; + PIPE_ALIGN_VAR(16) qword in[2 * 4]; + + + /* Fetch four attributes for four vertices. + */ + idx = 0; + for (i = 0; i < count; i++) { + const uint64_t addr = src + (elts[i] * pitch); + +#if DRAW_DBG + printf("SPU: fetching = 0x%llx\n", addr); +#endif + + spu_dcache_fetch_unaligned(& in[idx], addr, bytes_per_entry); + idx += quads_per_entry; + } + + /* Be nice and zero out any missing vertices. + */ + (void) memset(& in[idx], 0, (8 - idx) * sizeof(qword)); + + + /* Convert all 4 vertices to vectors of float. + */ + (*fetch)(&machine->Inputs[attr].xyzw[0].q, in, fetch_shuffle_data); + } +} + + +void spu_update_vertex_fetch( struct spu_vs_context *draw ) +{ + draw->vertex_fetch.fetch_func = generic_vertex_fetch; +} diff --git a/src/gallium/drivers/cell/spu/spu_vertex_shader.c b/src/gallium/drivers/cell/spu/spu_vertex_shader.c new file mode 100644 index 0000000..3e9804b --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_vertex_shader.c @@ -0,0 +1,245 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Keith Whitwell + * Brian Paul + * Ian Romanick + */ + +#include + +#include "pipe/p_state.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_math.h" +#include "draw/draw_private.h" +#include "draw/draw_context.h" +#include "cell/common.h" +#include "spu_vertex_shader.h" +#include "spu_exec.h" +#include "spu_main.h" + + +#define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float)) + + +#define CLIP_RIGHT_BIT 0x01 +#define CLIP_LEFT_BIT 0x02 +#define CLIP_TOP_BIT 0x04 +#define CLIP_BOTTOM_BIT 0x08 +#define CLIP_FAR_BIT 0x10 +#define CLIP_NEAR_BIT 0x20 + + +static INLINE float +dot4(const float *a, const float *b) +{ + return (a[0]*b[0] + + a[1]*b[1] + + a[2]*b[2] + + a[3]*b[3]); +} + +static INLINE unsigned +compute_clipmask(const float *clip, /*const*/ float plane[][4], unsigned nr) +{ + unsigned mask = 0; + unsigned i; + + /* Do the hardwired planes first: + */ + if (-clip[0] + clip[3] < 0) mask |= CLIP_RIGHT_BIT; + if ( clip[0] + clip[3] < 0) mask |= CLIP_LEFT_BIT; + if (-clip[1] + clip[3] < 0) mask |= CLIP_TOP_BIT; + if ( clip[1] + clip[3] < 0) mask |= CLIP_BOTTOM_BIT; + if (-clip[2] + clip[3] < 0) mask |= CLIP_FAR_BIT; + if ( clip[2] + clip[3] < 0) mask |= CLIP_NEAR_BIT; + + /* Followed by any remaining ones: + */ + for (i = 6; i < nr; i++) { + if (dot4(clip, plane[i]) < 0) + mask |= (1<machine; + unsigned int j; + + PIPE_ALIGN_VAR(16) struct spu_exec_vector inputs[PIPE_MAX_ATTRIBS]; + PIPE_ALIGN_VAR(16) struct spu_exec_vector outputs[PIPE_MAX_ATTRIBS]; + const float *scale = draw->viewport.scale; + const float *trans = draw->viewport.translate; + + ASSERT(count <= 4); + + machine->Processor = TGSI_PROCESSOR_VERTEX; + + ASSERT_ALIGN16(draw->constants); + machine->Consts = (float (*)[4]) draw->constants; + + machine->Inputs = inputs; + machine->Outputs = outputs; + + spu_vertex_fetch( draw, machine, elts, count ); + + /* run shader */ + spu_exec_machine_run( machine ); + + + /* store machine results */ + for (j = 0; j < count; j++) { + unsigned slot; + float x, y, z, w; + PIPE_ALIGN_VAR(16) + unsigned char buffer[sizeof(struct vertex_header) + + MAX_VERTEX_SIZE]; + struct vertex_header *const tmpOut = + (struct vertex_header *) buffer; + const unsigned vert_size = ROUNDUP16(sizeof(struct vertex_header) + + (sizeof(float) * 4 + * draw->num_vs_outputs)); + + mfc_get(tmpOut, vOut[j], vert_size, TAG_VERTEX_BUFFER, 0, 0); + wait_on_mask(1 << TAG_VERTEX_BUFFER); + + + /* Handle attr[0] (position) specially: + * + * XXX: Computing the clipmask should be done in the vertex + * program as a set of DP4 instructions appended to the + * user-provided code. + */ + x = tmpOut->clip[0] = machine->Outputs[0].xyzw[0].f[j]; + y = tmpOut->clip[1] = machine->Outputs[0].xyzw[1].f[j]; + z = tmpOut->clip[2] = machine->Outputs[0].xyzw[2].f[j]; + w = tmpOut->clip[3] = machine->Outputs[0].xyzw[3].f[j]; + + tmpOut->clipmask = compute_clipmask(tmpOut->clip, draw->plane, + draw->nr_planes); + tmpOut->edgeflag = 1; + + /* divide by w */ + w = 1.0f / w; + x *= w; + y *= w; + z *= w; + + /* Viewport mapping */ + tmpOut->data[0][0] = x * scale[0] + trans[0]; + tmpOut->data[0][1] = y * scale[1] + trans[1]; + tmpOut->data[0][2] = z * scale[2] + trans[2]; + tmpOut->data[0][3] = w; + + /* Remaining attributes are packed into sequential post-transform + * vertex attrib slots. + */ + for (slot = 1; slot < draw->num_vs_outputs; slot++) { + tmpOut->data[slot][0] = machine->Outputs[slot].xyzw[0].f[j]; + tmpOut->data[slot][1] = machine->Outputs[slot].xyzw[1].f[j]; + tmpOut->data[slot][2] = machine->Outputs[slot].xyzw[2].f[j]; + tmpOut->data[slot][3] = machine->Outputs[slot].xyzw[3].f[j]; + } + + mfc_put(tmpOut, vOut[j], vert_size, TAG_VERTEX_BUFFER, 0, 0); + } /* loop over vertices */ +} + + +PIPE_ALIGN_VAR(16) unsigned char +immediates[(sizeof(float) * 4 * TGSI_EXEC_NUM_IMMEDIATES) + 32]); + + +void +spu_bind_vertex_shader(struct spu_vs_context *draw, + struct cell_shader_info *vs) +{ + const unsigned immediate_addr = vs->immediates; + const unsigned immediate_size = + ROUNDUP16((sizeof(float) * 4 * vs->num_immediates) + + (immediate_addr & 0x0f)); + + + mfc_get(immediates, immediate_addr & ~0x0f, immediate_size, + TAG_VERTEX_BUFFER, 0, 0); + + draw->machine.Instructions = (struct tgsi_full_instruction *) + vs->instructions; + draw->machine.NumInstructions = vs->num_instructions; + + draw->machine.Declarations = (struct tgsi_full_declaration *) + vs->declarations; + draw->machine.NumDeclarations = vs->num_declarations; + + draw->num_vs_outputs = vs->num_outputs; + + /* specify the shader to interpret/execute */ + spu_exec_machine_init(&draw->machine, + PIPE_MAX_SAMPLERS, + NULL /*samplers*/, + PIPE_SHADER_VERTEX); + + wait_on_mask(1 << TAG_VERTEX_BUFFER); + + (void) memcpy(& draw->machine.Imms, &immediates[immediate_addr & 0x0f], + sizeof(float) * 4 * vs->num_immediates); +} + + +void +spu_execute_vertex_shader(struct spu_vs_context *draw, + const struct cell_command_vs *vs) +{ + unsigned i; + + (void) memcpy(draw->plane, vs->plane, sizeof(float) * 4 * vs->nr_planes); + draw->nr_planes = vs->nr_planes; + draw->vertex_fetch.nr_attrs = vs->nr_attrs; + + for (i = 0; i < vs->num_elts; i += 4) { + const unsigned batch_size = MIN2(vs->num_elts - i, 4); + + run_vertex_program(draw, & vs->elts[i], batch_size, &vs->vOut[i]); + } +} diff --git a/src/gallium/drivers/cell/spu/spu_vertex_shader.h b/src/gallium/drivers/cell/spu/spu_vertex_shader.h new file mode 100644 index 0000000..4c74f5e --- /dev/null +++ b/src/gallium/drivers/cell/spu/spu_vertex_shader.h @@ -0,0 +1,66 @@ +#ifndef SPU_VERTEX_SHADER_H +#define SPU_VERTEX_SHADER_H + +#include "cell/common.h" +#include "pipe/p_format.h" +#include "spu_exec.h" + +struct spu_vs_context; + +typedef void (*spu_full_fetch_func)( struct spu_vs_context *draw, + struct spu_exec_machine *machine, + const unsigned *elts, + unsigned count ); + +struct spu_vs_context { + struct pipe_viewport_state viewport; + + struct { + uint64_t src_ptr[PIPE_MAX_ATTRIBS]; + unsigned pitch[PIPE_MAX_ATTRIBS]; + unsigned size[PIPE_MAX_ATTRIBS]; + unsigned code_offset[PIPE_MAX_ATTRIBS]; + unsigned nr_attrs; + boolean dirty; + + spu_full_fetch_func fetch_func; + void *code; + } vertex_fetch; + + /* Clip derived state: + */ + float plane[12][4]; + unsigned nr_planes; + + struct spu_exec_machine machine; + const float (*constants)[4]; + + unsigned num_vs_outputs; +}; + +extern void spu_update_vertex_fetch(struct spu_vs_context *draw); + +static INLINE void spu_vertex_fetch(struct spu_vs_context *draw, + struct spu_exec_machine *machine, + const unsigned *elts, + unsigned count) +{ + if (draw->vertex_fetch.dirty) { + spu_update_vertex_fetch(draw); + draw->vertex_fetch.dirty = 0; + } + + (*draw->vertex_fetch.fetch_func)(draw, machine, elts, count); +} + +struct cell_command_vs; + +extern void +spu_bind_vertex_shader(struct spu_vs_context *draw, + struct cell_shader_info *vs); + +extern void +spu_execute_vertex_shader(struct spu_vs_context *draw, + const struct cell_command_vs *vs); + +#endif /* SPU_VERTEX_SHADER_H */ diff --git a/src/gallium/drivers/failover/Makefile b/src/gallium/drivers/failover/Makefile new file mode 100644 index 0000000..dfb7f5d --- /dev/null +++ b/src/gallium/drivers/failover/Makefile @@ -0,0 +1,11 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = failover + +C_SOURCES = \ + fo_state.c \ + fo_state_emit.c \ + fo_context.c + +include ../../Makefile.template diff --git a/src/gallium/drivers/failover/SConscript b/src/gallium/drivers/failover/SConscript new file mode 100644 index 0000000..9347431 --- /dev/null +++ b/src/gallium/drivers/failover/SConscript @@ -0,0 +1,15 @@ +Import('*') + +env = env.Clone() + +failover = env.ConvenienceLibrary( + target = 'failover', + source = [ + 'fo_state.c', + 'fo_state_emit.c', + 'fo_context.c', + ]) + +env.Alias('failover', failover) + +Export('failover') diff --git a/src/gallium/drivers/failover/fo_context.c b/src/gallium/drivers/failover/fo_context.c new file mode 100644 index 0000000..e4d289c --- /dev/null +++ b/src/gallium/drivers/failover/fo_context.c @@ -0,0 +1,153 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + + +#include "pipe/p_defines.h" +#include "util/u_memory.h" +#include "pipe/p_context.h" + +#include "fo_context.h" +#include "fo_winsys.h" + + + +static void failover_destroy( struct pipe_context *pipe ) +{ + struct failover_context *failover = failover_context( pipe ); + + FREE( failover ); +} + + +void failover_fail_over( struct failover_context *failover ) +{ + failover->dirty = TRUE; + failover->mode = FO_SW; +} + + +static void failover_draw_vbo( struct pipe_context *pipe, + const struct pipe_draw_info *info) +{ + struct failover_context *failover = failover_context( pipe ); + + /* If there has been any statechange since last time, try hardware + * rendering again: + */ + if (failover->dirty) { + failover->mode = FO_HW; + } + + /* Try hardware: + */ + if (failover->mode == FO_HW) { + failover->hw->draw_vbo( failover->hw, info ); + } + + /* Possibly try software: + */ + if (failover->mode == FO_SW) { + + if (failover->dirty) { + failover->hw->flush( failover->hw, ~0, NULL ); + failover_state_emit( failover ); + } + + failover->sw->draw_vbo( failover->sw, info ); + + /* Be ready to switch back to hardware rendering without an + * intervening flush. Unlikely to be much performance impact to + * this: + */ + failover->sw->flush( failover->sw, ~0, NULL ); + } +} + +static unsigned int +failover_is_resource_referenced( struct pipe_context *_pipe, + struct pipe_resource *resource, + unsigned level, int layer) +{ + struct failover_context *failover = failover_context( _pipe ); + struct pipe_context *pipe = (failover->mode == FO_HW) ? + failover->hw : failover->sw; + + return pipe->is_resource_referenced(pipe, resource, level, layer); +} + +struct pipe_context *failover_create( struct pipe_context *hw, + struct pipe_context *sw ) +{ + struct failover_context *failover = CALLOC_STRUCT(failover_context); + if (failover == NULL) + return NULL; + + failover->hw = hw; + failover->sw = sw; + failover->pipe.winsys = hw->winsys; + failover->pipe.screen = hw->screen; + failover->pipe.destroy = failover_destroy; +#if 0 + failover->pipe.is_format_supported = hw->is_format_supported; + failover->pipe.get_name = hw->get_name; + failover->pipe.get_vendor = hw->get_vendor; + failover->pipe.get_param = hw->get_param; + failover->pipe.get_shader_param = hw->get_shader_param; + failover->pipe.get_paramf = hw->get_paramf; +#endif + + failover->pipe.draw_vbo = failover_draw_vbo; + failover->pipe.clear = hw->clear; + failover->pipe.clear_render_target = hw->clear_render_target; + failover->pipe.clear_depth_stencil = hw->clear_depth_stencil; + + /* No software occlusion fallback (or other optional functionality) + * at this point - if the hardware doesn't support it, don't + * advertise it to the application. + */ + failover->pipe.begin_query = hw->begin_query; + failover->pipe.end_query = hw->end_query; + + failover_init_state_functions( failover ); + + failover->pipe.resource_copy_region = hw->resource_copy_region; + +#if 0 + failover->pipe.resource_create = hw->resource_create; + failover->pipe.resource_destroy = hw->resource_destroy; + failover->pipe.create_surface = hw->create_surface; + failover->pipe.surface_destroy = hw->surface_destroy; +#endif + + failover->pipe.flush = hw->flush; + failover->pipe.is_resource_referenced = failover_is_resource_referenced; + + failover->dirty = 0; + + return &failover->pipe; +} + diff --git a/src/gallium/drivers/failover/fo_context.h b/src/gallium/drivers/failover/fo_context.h new file mode 100644 index 0000000..1afa6c9 --- /dev/null +++ b/src/gallium/drivers/failover/fo_context.h @@ -0,0 +1,144 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef FO_CONTEXT_H +#define FO_CONTEXT_H + +#include "pipe/p_state.h" +#include "pipe/p_context.h" + + + +#define FO_NEW_VIEWPORT 0x1 +#define FO_NEW_RASTERIZER 0x2 +#define FO_NEW_FRAGMENT_SHADER 0x4 +#define FO_NEW_BLEND 0x8 +#define FO_NEW_CLIP 0x10 +#define FO_NEW_SCISSOR 0x20 +#define FO_NEW_STIPPLE 0x40 +#define FO_NEW_FRAMEBUFFER 0x80 +#define FO_NEW_ALPHA_TEST 0x100 +#define FO_NEW_DEPTH_STENCIL 0x200 +#define FO_NEW_SAMPLER 0x400 +#define FO_NEW_SAMPLER_VIEW 0x800 +#define FO_NEW_VERTEX 0x2000 +#define FO_NEW_VERTEX_SHADER 0x4000 +#define FO_NEW_BLEND_COLOR 0x8000 +#define FO_NEW_STENCIL_REF 0x10000 +#define FO_NEW_CLEAR_COLOR 0x20000 +#define FO_NEW_VERTEX_BUFFER 0x40000 +#define FO_NEW_VERTEX_ELEMENT 0x80000 +#define FO_NEW_SAMPLE_MASK 0x100000 +#define FO_NEW_INDEX_BUFFER 0x200000 + + + +#define FO_HW 0 +#define FO_SW 1 + +struct fo_state { + void *sw_state; + void *hw_state; +}; + +struct fo_sampler_view { + struct pipe_sampler_view base; + struct pipe_sampler_view *sw; + struct pipe_sampler_view *hw; +}; + +struct failover_context { + struct pipe_context pipe; /**< base class */ + + + /* The most recent drawing state as set by the driver: + */ + const struct fo_state *blend; + const struct fo_state *sampler[PIPE_MAX_SAMPLERS]; + const struct fo_state *vertex_samplers[PIPE_MAX_VERTEX_SAMPLERS]; + const struct fo_state *depth_stencil; + const struct fo_state *rasterizer; + const struct fo_state *fragment_shader; + const struct fo_state *vertex_shader; + const struct fo_state *vertex_elements; + + struct pipe_blend_color blend_color; + struct pipe_stencil_ref stencil_ref; + struct pipe_clip_state clip; + unsigned sample_mask; + struct pipe_framebuffer_state framebuffer; + struct pipe_poly_stipple poly_stipple; + struct pipe_scissor_state scissor; + struct pipe_viewport_state viewport; + struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS]; + struct pipe_index_buffer index_buffer; + + uint num_vertex_buffers; + + void *sw_sampler_state[PIPE_MAX_SAMPLERS]; + void *hw_sampler_state[PIPE_MAX_SAMPLERS]; + void *sw_vertex_sampler_state[PIPE_MAX_VERTEX_SAMPLERS]; + void *hw_vertex_sampler_state[PIPE_MAX_VERTEX_SAMPLERS]; + + struct fo_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; + struct fo_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; + unsigned num_fragment_sampler_views; + unsigned num_vertex_sampler_views; + + unsigned dirty; + + unsigned num_samplers; + unsigned num_vertex_samplers; + + unsigned mode; + struct pipe_context *hw; + struct pipe_context *sw; +}; + + + +void failover_init_state_functions( struct failover_context *failover ); +void failover_state_emit( struct failover_context *failover ); + +static INLINE struct failover_context * +failover_context( struct pipe_context *pipe ) +{ + return (struct failover_context *)pipe; +} + +/* Internal functions + */ +void +failover_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + struct pipe_resource *resource); + + +#endif /* FO_CONTEXT_H */ diff --git a/src/gallium/drivers/failover/fo_state.c b/src/gallium/drivers/failover/fo_state.c new file mode 100644 index 0000000..c265f38 --- /dev/null +++ b/src/gallium/drivers/failover/fo_state.c @@ -0,0 +1,659 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#include "util/u_inlines.h" +#include "util/u_memory.h" + +#include "fo_context.h" + + +/* This looks like a lot of work at the moment - we're keeping a + * duplicate copy of the state up-to-date. + * + * This can change in two ways: + * - With constant state objects we would only need to save a pointer, + * not the whole object. + * - By adding a callback in the state tracker to re-emit state. The + * state tracker knows the current state already and can re-emit it + * without additional complexity. + * + * This works as a proof-of-concept, but a final version will have + * lower overheads. + */ + + + +static void * +failover_create_blend_state( struct pipe_context *pipe, + const struct pipe_blend_state *blend ) +{ + struct fo_state *state = MALLOC(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + + state->sw_state = failover->sw->create_blend_state(failover->sw, blend); + state->hw_state = failover->hw->create_blend_state(failover->hw, blend); + + return state; +} + +static void +failover_bind_blend_state( struct pipe_context *pipe, + void *blend ) +{ + struct failover_context *failover = failover_context(pipe); + struct fo_state *state = (struct fo_state *)blend; + failover->blend = state; + failover->dirty |= FO_NEW_BLEND; + failover->sw->bind_blend_state( failover->sw, state->sw_state ); + failover->hw->bind_blend_state( failover->hw, state->hw_state ); +} + +static void +failover_delete_blend_state( struct pipe_context *pipe, + void *blend ) +{ + struct fo_state *state = (struct fo_state*)blend; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_blend_state(failover->sw, state->sw_state); + failover->hw->delete_blend_state(failover->hw, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + FREE(state); +} + +static void +failover_set_blend_color( struct pipe_context *pipe, + const struct pipe_blend_color *blend_color ) +{ + struct failover_context *failover = failover_context(pipe); + + failover->blend_color = *blend_color; + failover->dirty |= FO_NEW_BLEND_COLOR; + failover->sw->set_blend_color( failover->sw, blend_color ); + failover->hw->set_blend_color( failover->hw, blend_color ); +} + +static void +failover_set_stencil_ref( struct pipe_context *pipe, + const struct pipe_stencil_ref *stencil_ref ) +{ + struct failover_context *failover = failover_context(pipe); + + failover->stencil_ref = *stencil_ref; + failover->dirty |= FO_NEW_STENCIL_REF; + failover->sw->set_stencil_ref( failover->sw, stencil_ref ); + failover->hw->set_stencil_ref( failover->hw, stencil_ref ); +} + +static void +failover_set_clip_state( struct pipe_context *pipe, + const struct pipe_clip_state *clip ) +{ + struct failover_context *failover = failover_context(pipe); + + failover->clip = *clip; + failover->dirty |= FO_NEW_CLIP; + failover->sw->set_clip_state( failover->sw, clip ); + failover->hw->set_clip_state( failover->hw, clip ); +} + +static void +failover_set_sample_mask(struct pipe_context *pipe, + unsigned sample_mask) +{ + struct failover_context *failover = failover_context(pipe); + + failover->sample_mask = sample_mask; + failover->dirty |= FO_NEW_SAMPLE_MASK; + failover->sw->set_sample_mask( failover->sw, sample_mask ); + failover->hw->set_sample_mask( failover->hw, sample_mask ); + +} + + +static void * +failover_create_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_alpha_state *templ) +{ + struct fo_state *state = MALLOC(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + + state->sw_state = failover->sw->create_depth_stencil_alpha_state(failover->sw, templ); + state->hw_state = failover->hw->create_depth_stencil_alpha_state(failover->hw, templ); + + return state; +} + +static void +failover_bind_depth_stencil_state(struct pipe_context *pipe, + void *depth_stencil) +{ + struct failover_context *failover = failover_context(pipe); + struct fo_state *state = (struct fo_state *)depth_stencil; + failover->depth_stencil = state; + failover->dirty |= FO_NEW_DEPTH_STENCIL; + failover->sw->bind_depth_stencil_alpha_state(failover->sw, state->sw_state); + failover->hw->bind_depth_stencil_alpha_state(failover->hw, state->hw_state); +} + +static void +failover_delete_depth_stencil_state(struct pipe_context *pipe, + void *ds) +{ + struct fo_state *state = (struct fo_state*)ds; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_depth_stencil_alpha_state(failover->sw, state->sw_state); + failover->hw->delete_depth_stencil_alpha_state(failover->hw, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + FREE(state); +} + +static void +failover_set_framebuffer_state(struct pipe_context *pipe, + const struct pipe_framebuffer_state *framebuffer) +{ + struct failover_context *failover = failover_context(pipe); + + failover->framebuffer = *framebuffer; + failover->dirty |= FO_NEW_FRAMEBUFFER; + failover->sw->set_framebuffer_state( failover->sw, framebuffer ); + failover->hw->set_framebuffer_state( failover->hw, framebuffer ); +} + + +static void * +failover_create_fs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct fo_state *state = MALLOC(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + + state->sw_state = failover->sw->create_fs_state(failover->sw, templ); + state->hw_state = failover->hw->create_fs_state(failover->hw, templ); + + return state; +} + +static void +failover_bind_fs_state(struct pipe_context *pipe, void *fs) +{ + struct failover_context *failover = failover_context(pipe); + struct fo_state *state = (struct fo_state*)fs; + failover->fragment_shader = state; + failover->dirty |= FO_NEW_FRAGMENT_SHADER; + failover->sw->bind_fs_state(failover->sw, state->sw_state); + failover->hw->bind_fs_state(failover->hw, state->hw_state); +} + +static void +failover_delete_fs_state(struct pipe_context *pipe, + void *fs) +{ + struct fo_state *state = (struct fo_state*)fs; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_fs_state(failover->sw, state->sw_state); + failover->hw->delete_fs_state(failover->hw, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + FREE(state); +} + +static void * +failover_create_vs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct fo_state *state = MALLOC(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + + state->sw_state = failover->sw->create_vs_state(failover->sw, templ); + state->hw_state = failover->hw->create_vs_state(failover->hw, templ); + + return state; +} + +static void +failover_bind_vs_state(struct pipe_context *pipe, + void *vs) +{ + struct failover_context *failover = failover_context(pipe); + + struct fo_state *state = (struct fo_state*)vs; + failover->vertex_shader = state; + failover->dirty |= FO_NEW_VERTEX_SHADER; + failover->sw->bind_vs_state(failover->sw, state->sw_state); + failover->hw->bind_vs_state(failover->hw, state->hw_state); +} + +static void +failover_delete_vs_state(struct pipe_context *pipe, + void *vs) +{ + struct fo_state *state = (struct fo_state*)vs; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_vs_state(failover->sw, state->sw_state); + failover->hw->delete_vs_state(failover->hw, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + FREE(state); +} + + + +static void * +failover_create_vertex_elements_state( struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_element *velems ) +{ + struct fo_state *state = MALLOC(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + + state->sw_state = failover->sw->create_vertex_elements_state(failover->sw, count, velems); + state->hw_state = failover->hw->create_vertex_elements_state(failover->hw, count, velems); + + return state; +} + +static void +failover_bind_vertex_elements_state(struct pipe_context *pipe, + void *velems ) +{ + struct failover_context *failover = failover_context(pipe); + struct fo_state *state = (struct fo_state*)velems; + + failover->vertex_elements = state; + failover->dirty |= FO_NEW_VERTEX_ELEMENT; + failover->sw->bind_vertex_elements_state( failover->sw, velems ); + failover->hw->bind_vertex_elements_state( failover->hw, velems ); +} + +static void +failover_delete_vertex_elements_state( struct pipe_context *pipe, + void *velems ) +{ + struct fo_state *state = (struct fo_state*)velems; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_vertex_elements_state(failover->sw, state->sw_state); + failover->hw->delete_vertex_elements_state(failover->hw, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + FREE(state); +} + +static void +failover_set_polygon_stipple( struct pipe_context *pipe, + const struct pipe_poly_stipple *stipple ) +{ + struct failover_context *failover = failover_context(pipe); + + failover->poly_stipple = *stipple; + failover->dirty |= FO_NEW_STIPPLE; + failover->sw->set_polygon_stipple( failover->sw, stipple ); + failover->hw->set_polygon_stipple( failover->hw, stipple ); +} + + +static void * +failover_create_rasterizer_state(struct pipe_context *pipe, + const struct pipe_rasterizer_state *templ) +{ + struct fo_state *state = MALLOC(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + + state->sw_state = failover->sw->create_rasterizer_state(failover->sw, templ); + state->hw_state = failover->hw->create_rasterizer_state(failover->hw, templ); + + return state; +} + +static void +failover_bind_rasterizer_state(struct pipe_context *pipe, + void *raster) +{ + struct failover_context *failover = failover_context(pipe); + + struct fo_state *state = (struct fo_state*)raster; + failover->rasterizer = state; + failover->dirty |= FO_NEW_RASTERIZER; + failover->sw->bind_rasterizer_state(failover->sw, state->sw_state); + failover->hw->bind_rasterizer_state(failover->hw, state->hw_state); +} + +static void +failover_delete_rasterizer_state(struct pipe_context *pipe, + void *raster) +{ + struct fo_state *state = (struct fo_state*)raster; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_rasterizer_state(failover->sw, state->sw_state); + failover->hw->delete_rasterizer_state(failover->hw, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + FREE(state); +} + + +static void +failover_set_scissor_state( struct pipe_context *pipe, + const struct pipe_scissor_state *scissor ) +{ + struct failover_context *failover = failover_context(pipe); + + failover->scissor = *scissor; + failover->dirty |= FO_NEW_SCISSOR; + failover->sw->set_scissor_state( failover->sw, scissor ); + failover->hw->set_scissor_state( failover->hw, scissor ); +} + + +static void * +failover_create_sampler_state(struct pipe_context *pipe, + const struct pipe_sampler_state *templ) +{ + struct fo_state *state = MALLOC(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + + state->sw_state = failover->sw->create_sampler_state(failover->sw, templ); + state->hw_state = failover->hw->create_sampler_state(failover->hw, templ); + + return state; +} + +static void +failover_bind_fragment_sampler_states(struct pipe_context *pipe, + unsigned num, + void **sampler) +{ + struct failover_context *failover = failover_context(pipe); + struct fo_state *state = (struct fo_state*)sampler; + uint i; + assert(num <= PIPE_MAX_SAMPLERS); + /* Check for no-op */ + if (num == failover->num_samplers && + !memcmp(failover->sampler, sampler, num * sizeof(void *))) + return; + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + failover->sw_sampler_state[i] = i < num ? state[i].sw_state : NULL; + failover->hw_sampler_state[i] = i < num ? state[i].hw_state : NULL; + } + failover->dirty |= FO_NEW_SAMPLER; + failover->num_samplers = num; + failover->sw->bind_fragment_sampler_states(failover->sw, num, + failover->sw_sampler_state); + failover->hw->bind_fragment_sampler_states(failover->hw, num, + failover->hw_sampler_state); +} + +static void +failover_bind_vertex_sampler_states(struct pipe_context *pipe, + unsigned num_samplers, + void **samplers) +{ + struct failover_context *failover = failover_context(pipe); + struct fo_state *state = (struct fo_state*)samplers; + uint i; + + assert(num_samplers <= PIPE_MAX_VERTEX_SAMPLERS); + + /* Check for no-op */ + if (num_samplers == failover->num_vertex_samplers && + !memcmp(failover->vertex_samplers, samplers, num_samplers * sizeof(void *))) { + return; + } + for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { + failover->sw_vertex_sampler_state[i] = i < num_samplers ? state[i].sw_state : NULL; + failover->hw_vertex_sampler_state[i] = i < num_samplers ? state[i].hw_state : NULL; + } + failover->dirty |= FO_NEW_SAMPLER; + failover->num_vertex_samplers = num_samplers; + failover->sw->bind_vertex_sampler_states(failover->sw, + num_samplers, + failover->sw_vertex_sampler_state); + failover->hw->bind_vertex_sampler_states(failover->hw, + num_samplers, + failover->hw_vertex_sampler_state); +} + +static void +failover_delete_sampler_state(struct pipe_context *pipe, void *sampler) +{ + struct fo_state *state = (struct fo_state*)sampler; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_sampler_state(failover->sw, state->sw_state); + failover->hw->delete_sampler_state(failover->hw, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + FREE(state); +} + + +static struct pipe_sampler_view * +failover_create_sampler_view(struct pipe_context *pipe, + struct pipe_resource *texture, + const struct pipe_sampler_view *templ) +{ + struct fo_sampler_view *view = MALLOC(sizeof(struct fo_sampler_view)); + struct failover_context *failover = failover_context(pipe); + + view->sw = failover->sw->create_sampler_view(failover->sw, texture, templ); + view->hw = failover->hw->create_sampler_view(failover->hw, texture, templ); + + view->base = *templ; + view->base.reference.count = 1; + view->base.texture = NULL; + pipe_resource_reference(&view->base.texture, texture); + view->base.context = pipe; + + return &view->base; +} + +static void +failover_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + struct fo_sampler_view *fo_view = (struct fo_sampler_view *)view; + struct failover_context *failover = failover_context(pipe); + + failover->sw->sampler_view_destroy(failover->sw, fo_view->sw); + failover->hw->sampler_view_destroy(failover->hw, fo_view->hw); + + pipe_resource_reference(&fo_view->base.texture, NULL); + FREE(fo_view); +} + +static void +failover_set_fragment_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct failover_context *failover = failover_context(pipe); + struct pipe_sampler_view *hw_views[PIPE_MAX_SAMPLERS]; + uint i; + + assert(num <= PIPE_MAX_SAMPLERS); + + /* Check for no-op */ + if (num == failover->num_fragment_sampler_views && + !memcmp(failover->fragment_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) + return; + for (i = 0; i < num; i++) { + struct fo_sampler_view *fo_view = (struct fo_sampler_view *)views[i]; + + pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->fragment_sampler_views[i], views[i]); + hw_views[i] = fo_view->hw; + } + for (i = num; i < failover->num_fragment_sampler_views; i++) + pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->fragment_sampler_views[i], NULL); + failover->dirty |= FO_NEW_SAMPLER_VIEW; + failover->num_fragment_sampler_views = num; + failover->hw->set_fragment_sampler_views(failover->hw, num, hw_views); +} + + +static void +failover_set_vertex_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct failover_context *failover = failover_context(pipe); + struct pipe_sampler_view *hw_views[PIPE_MAX_VERTEX_SAMPLERS]; + uint i; + + assert(num <= PIPE_MAX_VERTEX_SAMPLERS); + + /* Check for no-op */ + if (num == failover->num_vertex_sampler_views && + !memcmp(failover->vertex_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) { + return; + } + for (i = 0; i < num; i++) { + struct fo_sampler_view *fo_view = (struct fo_sampler_view *)views[i]; + + pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->vertex_sampler_views[i], views[i]); + hw_views[i] = fo_view->hw; + } + for (i = num; i < failover->num_vertex_sampler_views; i++) + pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->vertex_sampler_views[i], NULL); + failover->dirty |= FO_NEW_SAMPLER_VIEW; + failover->num_vertex_sampler_views = num; + failover->hw->set_vertex_sampler_views(failover->hw, num, hw_views); +} + + +static void +failover_set_viewport_state( struct pipe_context *pipe, + const struct pipe_viewport_state *viewport ) +{ + struct failover_context *failover = failover_context(pipe); + + failover->viewport = *viewport; + failover->dirty |= FO_NEW_VIEWPORT; + failover->sw->set_viewport_state( failover->sw, viewport ); + failover->hw->set_viewport_state( failover->hw, viewport ); +} + + +static void +failover_set_vertex_buffers(struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_buffer *vertex_buffers) +{ + struct failover_context *failover = failover_context(pipe); + + memcpy(failover->vertex_buffers, vertex_buffers, + count * sizeof(vertex_buffers[0])); + failover->dirty |= FO_NEW_VERTEX_BUFFER; + failover->num_vertex_buffers = count; + failover->sw->set_vertex_buffers( failover->sw, count, vertex_buffers ); + failover->hw->set_vertex_buffers( failover->hw, count, vertex_buffers ); +} + + +static void +failover_set_index_buffer(struct pipe_context *pipe, + const struct pipe_index_buffer *ib) +{ + struct failover_context *failover = failover_context(pipe); + + if (ib) + memcpy(&failover->index_buffer, ib, sizeof(failover->index_buffer)); + else + memset(&failover->index_buffer, 0, sizeof(failover->index_buffer)); + + failover->dirty |= FO_NEW_INDEX_BUFFER; + failover->sw->set_index_buffer( failover->sw, ib ); + failover->hw->set_index_buffer( failover->hw, ib ); +} + + +void +failover_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + struct pipe_resource *res) +{ + struct failover_context *failover = failover_context(pipe); + + assert(shader < PIPE_SHADER_TYPES); + assert(index == 0); + + failover->sw->set_constant_buffer(failover->sw, shader, index, res); + failover->hw->set_constant_buffer(failover->hw, shader, index, res); +} + + +void +failover_init_state_functions( struct failover_context *failover ) +{ + failover->pipe.create_blend_state = failover_create_blend_state; + failover->pipe.bind_blend_state = failover_bind_blend_state; + failover->pipe.delete_blend_state = failover_delete_blend_state; + failover->pipe.create_sampler_state = failover_create_sampler_state; + failover->pipe.bind_fragment_sampler_states = failover_bind_fragment_sampler_states; + failover->pipe.bind_vertex_sampler_states = failover_bind_vertex_sampler_states; + failover->pipe.delete_sampler_state = failover_delete_sampler_state; + failover->pipe.create_depth_stencil_alpha_state = failover_create_depth_stencil_state; + failover->pipe.bind_depth_stencil_alpha_state = failover_bind_depth_stencil_state; + failover->pipe.delete_depth_stencil_alpha_state = failover_delete_depth_stencil_state; + failover->pipe.create_rasterizer_state = failover_create_rasterizer_state; + failover->pipe.bind_rasterizer_state = failover_bind_rasterizer_state; + failover->pipe.delete_rasterizer_state = failover_delete_rasterizer_state; + failover->pipe.create_fs_state = failover_create_fs_state; + failover->pipe.bind_fs_state = failover_bind_fs_state; + failover->pipe.delete_fs_state = failover_delete_fs_state; + failover->pipe.create_vs_state = failover_create_vs_state; + failover->pipe.bind_vs_state = failover_bind_vs_state; + failover->pipe.delete_vs_state = failover_delete_vs_state; + failover->pipe.create_vertex_elements_state = failover_create_vertex_elements_state; + failover->pipe.bind_vertex_elements_state = failover_bind_vertex_elements_state; + failover->pipe.delete_vertex_elements_state = failover_delete_vertex_elements_state; + + failover->pipe.set_blend_color = failover_set_blend_color; + failover->pipe.set_stencil_ref = failover_set_stencil_ref; + failover->pipe.set_clip_state = failover_set_clip_state; + failover->pipe.set_sample_mask = failover_set_sample_mask; + failover->pipe.set_framebuffer_state = failover_set_framebuffer_state; + failover->pipe.set_polygon_stipple = failover_set_polygon_stipple; + failover->pipe.set_scissor_state = failover_set_scissor_state; + failover->pipe.set_fragment_sampler_views = failover_set_fragment_sampler_views; + failover->pipe.set_vertex_sampler_views = failover_set_vertex_sampler_views; + failover->pipe.set_viewport_state = failover_set_viewport_state; + failover->pipe.set_vertex_buffers = failover_set_vertex_buffers; + failover->pipe.set_index_buffer = failover_set_index_buffer; + failover->pipe.set_constant_buffer = failover_set_constant_buffer; + failover->pipe.create_sampler_view = failover_create_sampler_view; + failover->pipe.sampler_view_destroy = failover_sampler_view_destroy; +} diff --git a/src/gallium/drivers/failover/fo_state_emit.c b/src/gallium/drivers/failover/fo_state_emit.c new file mode 100644 index 0000000..7f434ff --- /dev/null +++ b/src/gallium/drivers/failover/fo_state_emit.c @@ -0,0 +1,144 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#include "fo_context.h" + +/* This looks like a lot of work at the moment - we're keeping a + * duplicate copy of the state up-to-date. + * + * This can change in two ways: + * - With constant state objects we would only need to save a pointer, + * not the whole object. + * - By adding a callback in the state tracker to re-emit state. The + * state tracker knows the current state already and can re-emit it + * without additional complexity. + * + * This works as a proof-of-concept, but a final version will have + * lower overheads. + */ + + +/* Bring the software pipe uptodate with current state. + * + * With constant state objects we would probably just send all state + * to both rasterizers all the time??? + */ +void +failover_state_emit( struct failover_context *failover ) +{ + if (failover->dirty & FO_NEW_BLEND) + failover->sw->bind_blend_state( failover->sw, + failover->blend->sw_state ); + + if (failover->dirty & FO_NEW_BLEND_COLOR) + failover->sw->set_blend_color( failover->sw, &failover->blend_color ); + + if (failover->dirty & FO_NEW_CLIP) + failover->sw->set_clip_state( failover->sw, &failover->clip ); + + if (failover->dirty & FO_NEW_SAMPLE_MASK) + failover->sw->set_sample_mask( failover->sw, failover->sample_mask ); + + if (failover->dirty & FO_NEW_DEPTH_STENCIL) + failover->sw->bind_depth_stencil_alpha_state( failover->sw, + failover->depth_stencil->sw_state ); + + if (failover->dirty & FO_NEW_STENCIL_REF) + failover->sw->set_stencil_ref( failover->sw, &failover->stencil_ref ); + + if (failover->dirty & FO_NEW_FRAMEBUFFER) + failover->sw->set_framebuffer_state( failover->sw, &failover->framebuffer ); + + if (failover->dirty & FO_NEW_FRAGMENT_SHADER) + failover->sw->bind_fs_state( failover->sw, + failover->fragment_shader->sw_state ); + + if (failover->dirty & FO_NEW_VERTEX_SHADER) + failover->sw->bind_vs_state( failover->sw, + failover->vertex_shader->sw_state ); + + if (failover->dirty & FO_NEW_VERTEX_ELEMENT) + failover->sw->bind_vertex_elements_state( failover->sw, + failover->vertex_elements->sw_state ); + + if (failover->dirty & FO_NEW_STIPPLE) + failover->sw->set_polygon_stipple( failover->sw, &failover->poly_stipple ); + + if (failover->dirty & FO_NEW_RASTERIZER) + failover->sw->bind_rasterizer_state( failover->sw, + failover->rasterizer->sw_state ); + + if (failover->dirty & FO_NEW_SCISSOR) + failover->sw->set_scissor_state( failover->sw, &failover->scissor ); + + if (failover->dirty & FO_NEW_VIEWPORT) + failover->sw->set_viewport_state( failover->sw, &failover->viewport ); + + if (failover->dirty & FO_NEW_SAMPLER) { + failover->sw->bind_fragment_sampler_states( failover->sw, failover->num_samplers, + failover->sw_sampler_state ); + failover->sw->bind_vertex_sampler_states(failover->sw, + failover->num_vertex_samplers, + failover->sw_vertex_sampler_state); + } + + if (failover->dirty & FO_NEW_SAMPLER_VIEW) { + struct pipe_sampler_view *fragment_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *vertex_views[PIPE_MAX_VERTEX_SAMPLERS]; + uint i; + + for (i = 0; i < failover->num_fragment_sampler_views; i++) { + fragment_views[i] = failover->fragment_sampler_views[i]->sw; + } + failover->sw->set_fragment_sampler_views(failover->sw, + failover->num_fragment_sampler_views, + fragment_views); + + for (i = 0; i < failover->num_vertex_sampler_views; i++) { + vertex_views[i] = failover->vertex_sampler_views[i]->sw; + } + failover->sw->set_vertex_sampler_views(failover->sw, + failover->num_vertex_sampler_views, + vertex_views); + } + + if (failover->dirty & FO_NEW_VERTEX_BUFFER) { + failover->sw->set_vertex_buffers( failover->sw, + failover->num_vertex_buffers, + failover->vertex_buffers ); + } + + if (failover->dirty & FO_NEW_INDEX_BUFFER) { + failover->sw->set_index_buffer( failover->sw, + &failover->index_buffer ); + } + + failover->dirty = 0; +} diff --git a/src/gallium/drivers/failover/fo_winsys.h b/src/gallium/drivers/failover/fo_winsys.h new file mode 100644 index 0000000..533122b --- /dev/null +++ b/src/gallium/drivers/failover/fo_winsys.h @@ -0,0 +1,48 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef FO_WINSYS_H +#define FO_WINSYS_H + + +/* This is the interface that failover requires any window system + * hosting it to implement. This is the only include file in failover + * which is public. + */ + + +struct pipe_context; +struct failover_context; + + +struct pipe_context *failover_create( struct pipe_context *hw, + struct pipe_context *sw ); + + +void failover_fail_over( struct failover_context *failover ); + +#endif /* FO_WINSYS_H */ diff --git a/src/gallium/drivers/galahad/Makefile b/src/gallium/drivers/galahad/Makefile new file mode 100644 index 0000000..e9c4f7e --- /dev/null +++ b/src/gallium/drivers/galahad/Makefile @@ -0,0 +1,11 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = galahad + +C_SOURCES = \ + glhd_objects.c \ + glhd_context.c \ + glhd_screen.c + +include ../../Makefile.template diff --git a/src/gallium/drivers/galahad/SConscript b/src/gallium/drivers/galahad/SConscript new file mode 100644 index 0000000..3f39f99 --- /dev/null +++ b/src/gallium/drivers/galahad/SConscript @@ -0,0 +1,15 @@ +Import('*') + +env = env.Clone() + +galahad = env.ConvenienceLibrary( + target = 'galahad', + source = [ + 'glhd_context.c', + 'glhd_objects.c', + 'glhd_screen.c', + ]) + +env.Alias('galahad', galahad) + +Export('galahad') diff --git a/src/gallium/drivers/galahad/glhd_context.c b/src/gallium/drivers/galahad/glhd_context.c new file mode 100644 index 0000000..a572ad2 --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_context.c @@ -0,0 +1,1043 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "pipe/p_context.h" + +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" + +#include "glhd_context.h" +#include "glhd_objects.h" + + +static void +galahad_destroy(struct pipe_context *_pipe) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->destroy(pipe); + + FREE(glhd_pipe); +} + +static void +galahad_draw_vbo(struct pipe_context *_pipe, + const struct pipe_draw_info *info) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + /* XXX we should check that all bound resources are unmapped + * before drawing. + */ + + pipe->draw_vbo(pipe, info); +} + +static struct pipe_query * +galahad_create_query(struct pipe_context *_pipe, + unsigned query_type) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + if (query_type == PIPE_QUERY_OCCLUSION_COUNTER && + !pipe->screen->get_param(pipe->screen, PIPE_CAP_OCCLUSION_QUERY)) { + glhd_error("Occlusion query requested but not supported"); + } + + if (query_type == PIPE_QUERY_TIME_ELAPSED && + !pipe->screen->get_param(pipe->screen, PIPE_CAP_TIMER_QUERY)) { + glhd_error("Timer query requested but not supported"); + } + + return pipe->create_query(pipe, + query_type); +} + +static void +galahad_destroy_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->destroy_query(pipe, + query); +} + +static void +galahad_begin_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->begin_query(pipe, + query); +} + +static void +galahad_end_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->end_query(pipe, + query); +} + +static boolean +galahad_get_query_result(struct pipe_context *_pipe, + struct pipe_query *query, + boolean wait, + void *result) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + return pipe->get_query_result(pipe, + query, + wait, + result); +} + +static void * +galahad_create_blend_state(struct pipe_context *_pipe, + const struct pipe_blend_state *blend) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + if (blend->logicop_enable) { + if (blend->rt[0].blend_enable) { + glhd_warn("Blending enabled for render target 0, but logicops " + "are enabled"); + } + } + + return pipe->create_blend_state(pipe, + blend); +} + +static void +galahad_bind_blend_state(struct pipe_context *_pipe, + void *blend) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->bind_blend_state(pipe, + blend); +} + +static void +galahad_delete_blend_state(struct pipe_context *_pipe, + void *blend) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->delete_blend_state(pipe, + blend); +} + +static void * +galahad_create_sampler_state(struct pipe_context *_pipe, + const struct pipe_sampler_state *sampler) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + return pipe->create_sampler_state(pipe, + sampler); +} + +static void +galahad_bind_fragment_sampler_states(struct pipe_context *_pipe, + unsigned num_samplers, + void **samplers) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + if (num_samplers > PIPE_MAX_SAMPLERS) { + glhd_error("%u fragment samplers requested, " + "but only %u are permitted by API", + num_samplers, PIPE_MAX_SAMPLERS); + } + + pipe->bind_fragment_sampler_states(pipe, + num_samplers, + samplers); +} + +static void +galahad_bind_vertex_sampler_states(struct pipe_context *_pipe, + unsigned num_samplers, + void **samplers) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + if (num_samplers > PIPE_MAX_VERTEX_SAMPLERS) { + glhd_error("%u vertex samplers requested, " + "but only %u are permitted by API", + num_samplers, PIPE_MAX_VERTEX_SAMPLERS); + } + + pipe->bind_vertex_sampler_states(pipe, + num_samplers, + samplers); +} + +static void +galahad_delete_sampler_state(struct pipe_context *_pipe, + void *sampler) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->delete_sampler_state(pipe, + sampler); +} + +static void * +galahad_create_rasterizer_state(struct pipe_context *_pipe, + const struct pipe_rasterizer_state *rasterizer) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + if (rasterizer->point_quad_rasterization) { + if (rasterizer->point_smooth) { + glhd_warn("Point smoothing requested but ignored"); + } + } else { + if (rasterizer->sprite_coord_enable) { + glhd_warn("Point sprites requested but ignored"); + } + } + + return pipe->create_rasterizer_state(pipe, + rasterizer); +} + +static void +galahad_bind_rasterizer_state(struct pipe_context *_pipe, + void *rasterizer) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->bind_rasterizer_state(pipe, + rasterizer); +} + +static void +galahad_delete_rasterizer_state(struct pipe_context *_pipe, + void *rasterizer) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->delete_rasterizer_state(pipe, + rasterizer); +} + +static void * +galahad_create_depth_stencil_alpha_state(struct pipe_context *_pipe, + const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + return pipe->create_depth_stencil_alpha_state(pipe, + depth_stencil_alpha); +} + +static void +galahad_bind_depth_stencil_alpha_state(struct pipe_context *_pipe, + void *depth_stencil_alpha) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->bind_depth_stencil_alpha_state(pipe, + depth_stencil_alpha); +} + +static void +galahad_delete_depth_stencil_alpha_state(struct pipe_context *_pipe, + void *depth_stencil_alpha) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->delete_depth_stencil_alpha_state(pipe, + depth_stencil_alpha); +} + +static void * +galahad_create_fs_state(struct pipe_context *_pipe, + const struct pipe_shader_state *fs) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + return pipe->create_fs_state(pipe, + fs); +} + +static void +galahad_bind_fs_state(struct pipe_context *_pipe, + void *fs) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->bind_fs_state(pipe, + fs); +} + +static void +galahad_delete_fs_state(struct pipe_context *_pipe, + void *fs) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->delete_fs_state(pipe, + fs); +} + +static void * +galahad_create_vs_state(struct pipe_context *_pipe, + const struct pipe_shader_state *vs) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + return pipe->create_vs_state(pipe, + vs); +} + +static void +galahad_bind_vs_state(struct pipe_context *_pipe, + void *vs) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->bind_vs_state(pipe, + vs); +} + +static void +galahad_delete_vs_state(struct pipe_context *_pipe, + void *vs) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->delete_vs_state(pipe, + vs); +} + + +static void * +galahad_create_vertex_elements_state(struct pipe_context *_pipe, + unsigned num_elements, + const struct pipe_vertex_element *vertex_elements) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + return pipe->create_vertex_elements_state(pipe, + num_elements, + vertex_elements); +} + +static void +galahad_bind_vertex_elements_state(struct pipe_context *_pipe, + void *velems) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->bind_vertex_elements_state(pipe, + velems); +} + +static void +galahad_delete_vertex_elements_state(struct pipe_context *_pipe, + void *velems) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->delete_vertex_elements_state(pipe, + velems); +} + +static void +galahad_set_blend_color(struct pipe_context *_pipe, + const struct pipe_blend_color *blend_color) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->set_blend_color(pipe, + blend_color); +} + +static void +galahad_set_stencil_ref(struct pipe_context *_pipe, + const struct pipe_stencil_ref *stencil_ref) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->set_stencil_ref(pipe, + stencil_ref); +} + +static void +galahad_set_clip_state(struct pipe_context *_pipe, + const struct pipe_clip_state *clip) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->set_clip_state(pipe, + clip); +} + +static void +galahad_set_sample_mask(struct pipe_context *_pipe, + unsigned sample_mask) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->set_sample_mask(pipe, + sample_mask); +} + +static void +galahad_set_constant_buffer(struct pipe_context *_pipe, + uint shader, + uint index, + struct pipe_resource *_resource) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + struct pipe_resource *unwrapped_resource; + struct pipe_resource *resource = NULL; + + if (shader >= PIPE_SHADER_TYPES) { + glhd_error("Unknown shader type %u", shader); + } + + if (index && + index >= + pipe->screen->get_shader_param(pipe->screen, shader, PIPE_SHADER_CAP_MAX_CONST_BUFFERS)) { + glhd_error("Access to constant buffer %u requested, " + "but only %d are supported", + index, + pipe->screen->get_shader_param(pipe->screen, shader, PIPE_SHADER_CAP_MAX_CONST_BUFFERS)); + } + + /* XXX hmm? unwrap the input state */ + if (_resource) { + unwrapped_resource = galahad_resource_unwrap(_resource); + resource = unwrapped_resource; + } + + pipe->set_constant_buffer(pipe, + shader, + index, + resource); +} + +static void +galahad_set_framebuffer_state(struct pipe_context *_pipe, + const struct pipe_framebuffer_state *_state) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + struct pipe_framebuffer_state unwrapped_state; + struct pipe_framebuffer_state *state = NULL; + unsigned i; + + if (_state->nr_cbufs > PIPE_MAX_COLOR_BUFS) { + glhd_error("%d render targets bound, but only %d are permitted by API", + _state->nr_cbufs, PIPE_MAX_COLOR_BUFS); + } else if (_state->nr_cbufs > + pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_RENDER_TARGETS)) { + glhd_warn("%d render targets bound, but only %d are supported", + _state->nr_cbufs, + pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_RENDER_TARGETS)); + } + + /* unwrap the input state */ + if (_state) { + memcpy(&unwrapped_state, _state, sizeof(unwrapped_state)); + for(i = 0; i < _state->nr_cbufs; i++) + unwrapped_state.cbufs[i] = galahad_surface_unwrap(_state->cbufs[i]); + for (; i < PIPE_MAX_COLOR_BUFS; i++) + unwrapped_state.cbufs[i] = NULL; + unwrapped_state.zsbuf = galahad_surface_unwrap(_state->zsbuf); + state = &unwrapped_state; + } + + pipe->set_framebuffer_state(pipe, + state); +} + +static void +galahad_set_polygon_stipple(struct pipe_context *_pipe, + const struct pipe_poly_stipple *poly_stipple) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->set_polygon_stipple(pipe, + poly_stipple); +} + +static void +galahad_set_scissor_state(struct pipe_context *_pipe, + const struct pipe_scissor_state *scissor) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->set_scissor_state(pipe, + scissor); +} + +static void +galahad_set_viewport_state(struct pipe_context *_pipe, + const struct pipe_viewport_state *viewport) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->set_viewport_state(pipe, + viewport); +} + +static void +galahad_set_fragment_sampler_views(struct pipe_context *_pipe, + unsigned num, + struct pipe_sampler_view **_views) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view **views = NULL; + unsigned i; + + if (_views) { + for (i = 0; i < num; i++) + unwrapped_views[i] = galahad_sampler_view_unwrap(_views[i]); + for (; i < PIPE_MAX_SAMPLERS; i++) + unwrapped_views[i] = NULL; + + views = unwrapped_views; + } + + pipe->set_fragment_sampler_views(pipe, num, views); +} + +static void +galahad_set_vertex_sampler_views(struct pipe_context *_pipe, + unsigned num, + struct pipe_sampler_view **_views) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + struct pipe_sampler_view *unwrapped_views[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_sampler_view **views = NULL; + unsigned i; + + if (_views) { + for (i = 0; i < num; i++) + unwrapped_views[i] = galahad_sampler_view_unwrap(_views[i]); + for (; i < PIPE_MAX_VERTEX_SAMPLERS; i++) + unwrapped_views[i] = NULL; + + views = unwrapped_views; + } + + pipe->set_vertex_sampler_views(pipe, num, views); +} + +static void +galahad_set_vertex_buffers(struct pipe_context *_pipe, + unsigned num_buffers, + const struct pipe_vertex_buffer *_buffers) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS]; + struct pipe_vertex_buffer *buffers = NULL; + unsigned i; + + if (num_buffers) { + memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers)); + for (i = 0; i < num_buffers; i++) + unwrapped_buffers[i].buffer = galahad_resource_unwrap(_buffers[i].buffer); + buffers = unwrapped_buffers; + } + + pipe->set_vertex_buffers(pipe, + num_buffers, + buffers); +} + +static void +galahad_set_index_buffer(struct pipe_context *_pipe, + const struct pipe_index_buffer *_ib) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + struct pipe_index_buffer unwrapped_ib, *ib = NULL; + + if (_ib->buffer) { + switch (_ib->index_size) { + case 1: + case 2: + case 4: + break; + default: + glhd_warn("index buffer %p has unrecognized index size %d", + (void *) _ib->buffer, _ib->index_size); + break; + } + } + else if (_ib->offset || _ib->index_size) { + glhd_warn("non-indexed state with index offset %d and index size %d", + _ib->offset, _ib->index_size); + } + + if (_ib) { + unwrapped_ib = *_ib; + unwrapped_ib.buffer = galahad_resource_unwrap(_ib->buffer); + ib = &unwrapped_ib; + } + + pipe->set_index_buffer(pipe, ib); +} + +static void +galahad_resource_copy_region(struct pipe_context *_pipe, + struct pipe_resource *_dst, + unsigned dst_level, + unsigned dstx, + unsigned dsty, + unsigned dstz, + struct pipe_resource *_src, + unsigned src_level, + const struct pipe_box *src_box) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct galahad_resource *glhd_resource_dst = galahad_resource(_dst); + struct galahad_resource *glhd_resource_src = galahad_resource(_src); + struct pipe_context *pipe = glhd_pipe->pipe; + struct pipe_resource *dst = glhd_resource_dst->resource; + struct pipe_resource *src = glhd_resource_src->resource; + + if (_dst->format != _src->format) { + glhd_warn("Format mismatch: Source is %s, destination is %s", + util_format_short_name(_src->format), + util_format_short_name(_dst->format)); + } + + pipe->resource_copy_region(pipe, + dst, + dst_level, + dstx, + dsty, + dstz, + src, + src_level, + src_box); +} + +static void +galahad_clear(struct pipe_context *_pipe, + unsigned buffers, + const float *rgba, + double depth, + unsigned stencil) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->clear(pipe, + buffers, + rgba, + depth, + stencil); +} + +static void +galahad_clear_render_target(struct pipe_context *_pipe, + struct pipe_surface *_dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct galahad_surface *glhd_surface_dst = galahad_surface(_dst); + struct pipe_context *pipe = glhd_pipe->pipe; + struct pipe_surface *dst = glhd_surface_dst->surface; + + pipe->clear_render_target(pipe, + dst, + rgba, + dstx, + dsty, + width, + height); +} +static void +galahad_clear_depth_stencil(struct pipe_context *_pipe, + struct pipe_surface *_dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct galahad_surface *glhd_surface_dst = galahad_surface(_dst); + struct pipe_context *pipe = glhd_pipe->pipe; + struct pipe_surface *dst = glhd_surface_dst->surface; + + pipe->clear_depth_stencil(pipe, + dst, + clear_flags, + depth, + stencil, + dstx, + dsty, + width, + height); + +} + +static void +galahad_flush(struct pipe_context *_pipe, + unsigned flags, + struct pipe_fence_handle **fence) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct pipe_context *pipe = glhd_pipe->pipe; + + pipe->flush(pipe, + flags, + fence); +} + +static unsigned int +galahad_is_resource_referenced(struct pipe_context *_pipe, + struct pipe_resource *_resource, + unsigned level, + int layer) +{ + struct galahad_context *glhd_pipe = galahad_context(_pipe); + struct galahad_resource *glhd_resource = galahad_resource(_resource); + struct pipe_context *pipe = glhd_pipe->pipe; + struct pipe_resource *resource = glhd_resource->resource; + + return pipe->is_resource_referenced(pipe, + resource, + level, + layer); +} + +static struct pipe_sampler_view * +galahad_context_create_sampler_view(struct pipe_context *_pipe, + struct pipe_resource *_resource, + const struct pipe_sampler_view *templ) +{ + struct galahad_context *glhd_context = galahad_context(_pipe); + struct galahad_resource *glhd_resource = galahad_resource(_resource); + struct pipe_context *pipe = glhd_context->pipe; + struct pipe_resource *resource = glhd_resource->resource; + struct pipe_sampler_view *result; + + result = pipe->create_sampler_view(pipe, + resource, + templ); + + if (result) + return galahad_sampler_view_create(glhd_context, glhd_resource, result); + return NULL; +} + +static void +galahad_context_sampler_view_destroy(struct pipe_context *_pipe, + struct pipe_sampler_view *_view) +{ + galahad_sampler_view_destroy(galahad_context(_pipe), + galahad_sampler_view(_view)); +} + +static struct pipe_surface * +galahad_context_create_surface(struct pipe_context *_pipe, + struct pipe_resource *_resource, + const struct pipe_surface *templ) +{ + struct galahad_context *glhd_context = galahad_context(_pipe); + struct galahad_resource *glhd_resource = galahad_resource(_resource); + struct pipe_context *pipe = glhd_context->pipe; + struct pipe_resource *resource = glhd_resource->resource; + struct pipe_surface *result; + + result = pipe->create_surface(pipe, + resource, + templ); + + if (result) + return galahad_surface_create(glhd_context, glhd_resource, result); + return NULL; +} + +static void +galahad_context_surface_destroy(struct pipe_context *_pipe, + struct pipe_surface *_surface) +{ + galahad_surface_destroy(galahad_context(_pipe), + galahad_surface(_surface)); +} + + + +static struct pipe_transfer * +galahad_context_get_transfer(struct pipe_context *_context, + struct pipe_resource *_resource, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct galahad_context *glhd_context = galahad_context(_context); + struct galahad_resource *glhd_resource = galahad_resource(_resource); + struct pipe_context *context = glhd_context->pipe; + struct pipe_resource *resource = glhd_resource->resource; + struct pipe_transfer *result; + + result = context->get_transfer(context, + resource, + level, + usage, + box); + + if (result) + return galahad_transfer_create(glhd_context, glhd_resource, result); + return NULL; +} + +static void +galahad_context_transfer_destroy(struct pipe_context *_pipe, + struct pipe_transfer *_transfer) +{ + galahad_transfer_destroy(galahad_context(_pipe), + galahad_transfer(_transfer)); +} + +static void * +galahad_context_transfer_map(struct pipe_context *_context, + struct pipe_transfer *_transfer) +{ + struct galahad_context *glhd_context = galahad_context(_context); + struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer); + struct pipe_context *context = glhd_context->pipe; + struct pipe_transfer *transfer = glhd_transfer->transfer; + + struct galahad_resource *glhd_resource = galahad_resource(_transfer->resource); + + glhd_resource->map_count++; + + return context->transfer_map(context, + transfer); +} + + + +static void +galahad_context_transfer_flush_region(struct pipe_context *_context, + struct pipe_transfer *_transfer, + const struct pipe_box *box) +{ + struct galahad_context *glhd_context = galahad_context(_context); + struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer); + struct pipe_context *context = glhd_context->pipe; + struct pipe_transfer *transfer = glhd_transfer->transfer; + + context->transfer_flush_region(context, + transfer, + box); +} + + +static void +galahad_context_transfer_unmap(struct pipe_context *_context, + struct pipe_transfer *_transfer) +{ + struct galahad_context *glhd_context = galahad_context(_context); + struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer); + struct pipe_context *context = glhd_context->pipe; + struct pipe_transfer *transfer = glhd_transfer->transfer; + struct galahad_resource *glhd_resource = galahad_resource(_transfer->resource); + + if (glhd_resource->map_count < 1) { + glhd_warn("context::transfer_unmap() called too many times" + " (count = %d)\n", glhd_resource->map_count); + } + + glhd_resource->map_count--; + + context->transfer_unmap(context, + transfer); +} + + +static void +galahad_context_transfer_inline_write(struct pipe_context *_context, + struct pipe_resource *_resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned slice_stride) +{ + struct galahad_context *glhd_context = galahad_context(_context); + struct galahad_resource *glhd_resource = galahad_resource(_resource); + struct pipe_context *context = glhd_context->pipe; + struct pipe_resource *resource = glhd_resource->resource; + + context->transfer_inline_write(context, + resource, + level, + usage, + box, + data, + stride, + slice_stride); +} + + +struct pipe_context * +galahad_context_create(struct pipe_screen *_screen, struct pipe_context *pipe) +{ + struct galahad_context *glhd_pipe; + (void)galahad_screen(_screen); + + glhd_pipe = CALLOC_STRUCT(galahad_context); + if (!glhd_pipe) { + return NULL; + } + + glhd_pipe->base.winsys = NULL; + glhd_pipe->base.screen = _screen; + glhd_pipe->base.priv = pipe->priv; /* expose wrapped data */ + glhd_pipe->base.draw = NULL; + + glhd_pipe->base.destroy = galahad_destroy; + glhd_pipe->base.draw_vbo = galahad_draw_vbo; + glhd_pipe->base.create_query = galahad_create_query; + glhd_pipe->base.destroy_query = galahad_destroy_query; + glhd_pipe->base.begin_query = galahad_begin_query; + glhd_pipe->base.end_query = galahad_end_query; + glhd_pipe->base.get_query_result = galahad_get_query_result; + glhd_pipe->base.create_blend_state = galahad_create_blend_state; + glhd_pipe->base.bind_blend_state = galahad_bind_blend_state; + glhd_pipe->base.delete_blend_state = galahad_delete_blend_state; + glhd_pipe->base.create_sampler_state = galahad_create_sampler_state; + glhd_pipe->base.bind_fragment_sampler_states = galahad_bind_fragment_sampler_states; + glhd_pipe->base.bind_vertex_sampler_states = galahad_bind_vertex_sampler_states; + glhd_pipe->base.delete_sampler_state = galahad_delete_sampler_state; + glhd_pipe->base.create_rasterizer_state = galahad_create_rasterizer_state; + glhd_pipe->base.bind_rasterizer_state = galahad_bind_rasterizer_state; + glhd_pipe->base.delete_rasterizer_state = galahad_delete_rasterizer_state; + glhd_pipe->base.create_depth_stencil_alpha_state = galahad_create_depth_stencil_alpha_state; + glhd_pipe->base.bind_depth_stencil_alpha_state = galahad_bind_depth_stencil_alpha_state; + glhd_pipe->base.delete_depth_stencil_alpha_state = galahad_delete_depth_stencil_alpha_state; + glhd_pipe->base.create_fs_state = galahad_create_fs_state; + glhd_pipe->base.bind_fs_state = galahad_bind_fs_state; + glhd_pipe->base.delete_fs_state = galahad_delete_fs_state; + glhd_pipe->base.create_vs_state = galahad_create_vs_state; + glhd_pipe->base.bind_vs_state = galahad_bind_vs_state; + glhd_pipe->base.delete_vs_state = galahad_delete_vs_state; + glhd_pipe->base.create_vertex_elements_state = galahad_create_vertex_elements_state; + glhd_pipe->base.bind_vertex_elements_state = galahad_bind_vertex_elements_state; + glhd_pipe->base.delete_vertex_elements_state = galahad_delete_vertex_elements_state; + glhd_pipe->base.set_blend_color = galahad_set_blend_color; + glhd_pipe->base.set_stencil_ref = galahad_set_stencil_ref; + glhd_pipe->base.set_clip_state = galahad_set_clip_state; + glhd_pipe->base.set_sample_mask = galahad_set_sample_mask; + glhd_pipe->base.set_constant_buffer = galahad_set_constant_buffer; + glhd_pipe->base.set_framebuffer_state = galahad_set_framebuffer_state; + glhd_pipe->base.set_polygon_stipple = galahad_set_polygon_stipple; + glhd_pipe->base.set_scissor_state = galahad_set_scissor_state; + glhd_pipe->base.set_viewport_state = galahad_set_viewport_state; + glhd_pipe->base.set_fragment_sampler_views = galahad_set_fragment_sampler_views; + glhd_pipe->base.set_vertex_sampler_views = galahad_set_vertex_sampler_views; + glhd_pipe->base.set_vertex_buffers = galahad_set_vertex_buffers; + glhd_pipe->base.set_index_buffer = galahad_set_index_buffer; + glhd_pipe->base.resource_copy_region = galahad_resource_copy_region; + glhd_pipe->base.clear = galahad_clear; + glhd_pipe->base.clear_render_target = galahad_clear_render_target; + glhd_pipe->base.clear_depth_stencil = galahad_clear_depth_stencil; + glhd_pipe->base.flush = galahad_flush; + glhd_pipe->base.is_resource_referenced = galahad_is_resource_referenced; + glhd_pipe->base.create_sampler_view = galahad_context_create_sampler_view; + glhd_pipe->base.sampler_view_destroy = galahad_context_sampler_view_destroy; + glhd_pipe->base.create_surface = galahad_context_create_surface; + glhd_pipe->base.surface_destroy = galahad_context_surface_destroy; + glhd_pipe->base.get_transfer = galahad_context_get_transfer; + glhd_pipe->base.transfer_destroy = galahad_context_transfer_destroy; + glhd_pipe->base.transfer_map = galahad_context_transfer_map; + glhd_pipe->base.transfer_unmap = galahad_context_transfer_unmap; + glhd_pipe->base.transfer_flush_region = galahad_context_transfer_flush_region; + glhd_pipe->base.transfer_inline_write = galahad_context_transfer_inline_write; + + glhd_pipe->pipe = pipe; + + glhd_warn("Created context %p", (void *) glhd_pipe); + + return &glhd_pipe->base; +} diff --git a/src/gallium/drivers/galahad/glhd_context.h b/src/gallium/drivers/galahad/glhd_context.h new file mode 100644 index 0000000..4e71753 --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_context.h @@ -0,0 +1,64 @@ +/************************************************************************** + * + * 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 GLHD_CONTEXT_H +#define GLHD_CONTEXT_H + +#include + +#include "pipe/p_state.h" +#include "pipe/p_context.h" + + +struct galahad_context { + struct pipe_context base; /**< base class */ + + struct pipe_context *pipe; +}; + + +struct pipe_context * +galahad_context_create(struct pipe_screen *screen, struct pipe_context *pipe); + + +static INLINE struct galahad_context * +galahad_context(struct pipe_context *pipe) +{ + return (struct galahad_context *)pipe; +} + +#define glhd_warn(...) \ +do { \ + fprintf(stderr, "galahad: %s: ", __FUNCTION__); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); \ +} while (0) + +#define glhd_error(...) \ + glhd_warn(__VA_ARGS__); + +#endif /* GLHD_CONTEXT_H */ diff --git a/src/gallium/drivers/galahad/glhd_objects.c b/src/gallium/drivers/galahad/glhd_objects.c new file mode 100644 index 0000000..b50d856 --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_objects.c @@ -0,0 +1,189 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_inlines.h" +#include "util/u_memory.h" + +#include "glhd_screen.h" +#include "glhd_objects.h" +#include "glhd_context.h" + + + +struct pipe_resource * +galahad_resource_create(struct galahad_screen *glhd_screen, + struct pipe_resource *resource) +{ + struct galahad_resource *glhd_resource; + + if(!resource) + goto error; + + assert(resource->screen == glhd_screen->screen); + + glhd_resource = CALLOC_STRUCT(galahad_resource); + if(!glhd_resource) + goto error; + + memcpy(&glhd_resource->base, resource, sizeof(struct pipe_resource)); + + pipe_reference_init(&glhd_resource->base.reference, 1); + glhd_resource->base.screen = &glhd_screen->base; + glhd_resource->resource = resource; + + return &glhd_resource->base; + +error: + pipe_resource_reference(&resource, NULL); + return NULL; +} + +void +galahad_resource_destroy(struct galahad_resource *glhd_resource) +{ + pipe_resource_reference(&glhd_resource->resource, NULL); + FREE(glhd_resource); +} + + +struct pipe_surface * +galahad_surface_create(struct galahad_context *glhd_context, + struct galahad_resource *glhd_resource, + struct pipe_surface *surface) +{ + struct galahad_surface *glhd_surface; + + if(!surface) + goto error; + + assert(surface->texture == glhd_resource->resource); + + glhd_surface = CALLOC_STRUCT(galahad_surface); + if(!glhd_surface) + goto error; + + memcpy(&glhd_surface->base, surface, sizeof(struct pipe_surface)); + + pipe_reference_init(&glhd_surface->base.reference, 1); + glhd_surface->base.texture = NULL; + pipe_resource_reference(&glhd_surface->base.texture, &glhd_resource->base); + glhd_surface->surface = surface; + + return &glhd_surface->base; + +error: + pipe_surface_reference(&surface, NULL); + return NULL; +} + +void +galahad_surface_destroy(struct galahad_context *glhd_context, + struct galahad_surface *glhd_surface) +{ + pipe_resource_reference(&glhd_surface->base.texture, NULL); + glhd_context->pipe->surface_destroy(glhd_context->pipe, glhd_surface->surface); + FREE(glhd_surface); +} + + +struct pipe_sampler_view * +galahad_sampler_view_create(struct galahad_context *glhd_context, + struct galahad_resource *glhd_resource, + struct pipe_sampler_view *view) +{ + struct galahad_sampler_view *glhd_view; + + if (!view) + goto error; + + assert(view->texture == glhd_resource->resource); + + glhd_view = CALLOC_STRUCT(galahad_sampler_view); + + glhd_view->base = *view; + glhd_view->base.reference.count = 1; + glhd_view->base.texture = NULL; + pipe_resource_reference(&glhd_view->base.texture, glhd_resource->resource); + glhd_view->base.context = glhd_context->pipe; + glhd_view->sampler_view = view; + + return &glhd_view->base; +error: + return NULL; +} + +void +galahad_sampler_view_destroy(struct galahad_context *glhd_context, + struct galahad_sampler_view *glhd_view) +{ + pipe_resource_reference(&glhd_view->base.texture, NULL); + glhd_context->pipe->sampler_view_destroy(glhd_context->pipe, + glhd_view->sampler_view); + FREE(glhd_view); +} + + +struct pipe_transfer * +galahad_transfer_create(struct galahad_context *glhd_context, + struct galahad_resource *glhd_resource, + struct pipe_transfer *transfer) +{ + struct galahad_transfer *glhd_transfer; + + if(!transfer) + goto error; + + assert(transfer->resource == glhd_resource->resource); + + glhd_transfer = CALLOC_STRUCT(galahad_transfer); + if(!glhd_transfer) + goto error; + + memcpy(&glhd_transfer->base, transfer, sizeof(struct pipe_transfer)); + + glhd_transfer->base.resource = NULL; + glhd_transfer->transfer = transfer; + + pipe_resource_reference(&glhd_transfer->base.resource, &glhd_resource->base); + assert(glhd_transfer->base.resource == &glhd_resource->base); + + return &glhd_transfer->base; + +error: + glhd_context->pipe->transfer_destroy(glhd_context->pipe, transfer); + return NULL; +} + +void +galahad_transfer_destroy(struct galahad_context *glhd_context, + struct galahad_transfer *glhd_transfer) +{ + pipe_resource_reference(&glhd_transfer->base.resource, NULL); + glhd_context->pipe->transfer_destroy(glhd_context->pipe, + glhd_transfer->transfer); + FREE(glhd_transfer); +} diff --git a/src/gallium/drivers/galahad/glhd_objects.h b/src/gallium/drivers/galahad/glhd_objects.h new file mode 100644 index 0000000..13dc748 --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_objects.h @@ -0,0 +1,179 @@ +/************************************************************************** + * + * 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 GLHD_OBJECTS_H +#define GLHD_OBJECTS_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" + +#include "glhd_screen.h" + +struct galahad_context; + + +struct galahad_resource +{ + struct pipe_resource base; + + struct pipe_resource *resource; + + int map_count; +}; + + +struct galahad_sampler_view +{ + struct pipe_sampler_view base; + + struct pipe_sampler_view *sampler_view; +}; + + +struct galahad_surface +{ + struct pipe_surface base; + + struct pipe_surface *surface; +}; + + +struct galahad_transfer +{ + struct pipe_transfer base; + + struct pipe_transfer *transfer; +}; + + +static INLINE struct galahad_resource * +galahad_resource(struct pipe_resource *_resource) +{ + if(!_resource) + return NULL; + (void)galahad_screen(_resource->screen); + return (struct galahad_resource *)_resource; +} + +static INLINE struct galahad_sampler_view * +galahad_sampler_view(struct pipe_sampler_view *_sampler_view) +{ + if (!_sampler_view) { + return NULL; + } + return (struct galahad_sampler_view *)_sampler_view; +} + +static INLINE struct galahad_surface * +galahad_surface(struct pipe_surface *_surface) +{ + if(!_surface) + return NULL; + (void)galahad_resource(_surface->texture); + return (struct galahad_surface *)_surface; +} + +static INLINE struct galahad_transfer * +galahad_transfer(struct pipe_transfer *_transfer) +{ + if(!_transfer) + return NULL; + (void)galahad_resource(_transfer->resource); + return (struct galahad_transfer *)_transfer; +} + +static INLINE struct pipe_resource * +galahad_resource_unwrap(struct pipe_resource *_resource) +{ + if(!_resource) + return NULL; + return galahad_resource(_resource)->resource; +} + +static INLINE struct pipe_sampler_view * +galahad_sampler_view_unwrap(struct pipe_sampler_view *_sampler_view) +{ + if (!_sampler_view) { + return NULL; + } + return galahad_sampler_view(_sampler_view)->sampler_view; +} + +static INLINE struct pipe_surface * +galahad_surface_unwrap(struct pipe_surface *_surface) +{ + if(!_surface) + return NULL; + return galahad_surface(_surface)->surface; +} + +static INLINE struct pipe_transfer * +galahad_transfer_unwrap(struct pipe_transfer *_transfer) +{ + if(!_transfer) + return NULL; + return galahad_transfer(_transfer)->transfer; +} + + +struct pipe_resource * +galahad_resource_create(struct galahad_screen *glhd_screen, + struct pipe_resource *resource); + +void +galahad_resource_destroy(struct galahad_resource *glhd_resource); + +struct pipe_surface * +galahad_surface_create(struct galahad_context *glhd_context, + struct galahad_resource *glhd_resource, + struct pipe_surface *surface); + +void +galahad_surface_destroy(struct galahad_context *glhd_context, + struct galahad_surface *glhd_surface); + +struct pipe_sampler_view * +galahad_sampler_view_create(struct galahad_context *glhd_context, + struct galahad_resource *glhd_resource, + struct pipe_sampler_view *view); + +void +galahad_sampler_view_destroy(struct galahad_context *glhd_context, + struct galahad_sampler_view *glhd_sampler_view); + +struct pipe_transfer * +galahad_transfer_create(struct galahad_context *glhd_context, + struct galahad_resource *glhd_resource, + struct pipe_transfer *transfer); + +void +galahad_transfer_destroy(struct galahad_context *glhd_context, + struct galahad_transfer *glhd_transfer); + + +#endif /* GLHD_OBJECTS_H */ diff --git a/src/gallium/drivers/galahad/glhd_public.h b/src/gallium/drivers/galahad/glhd_public.h new file mode 100644 index 0000000..77a3801 --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_public.h @@ -0,0 +1,37 @@ +/************************************************************************** + * + * 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 GLHD_PUBLIC_H +#define GLHD_PUBLIC_H + +struct pipe_screen; +struct pipe_context; + +struct pipe_screen * +galahad_screen_create(struct pipe_screen *screen); + +#endif /* GLHD_PUBLIC_H */ diff --git a/src/gallium/drivers/galahad/glhd_screen.c b/src/gallium/drivers/galahad/glhd_screen.c new file mode 100644 index 0000000..b4825be --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_screen.c @@ -0,0 +1,343 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * 2010 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 above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "pipe/p_screen.h" +#include "pipe/p_state.h" +#include "util/u_memory.h" +#include "util/u_math.h" + +#include "glhd_public.h" +#include "glhd_screen.h" +#include "glhd_context.h" +#include "glhd_objects.h" + +DEBUG_GET_ONCE_BOOL_OPTION(galahad, "GALLIUM_GALAHAD", FALSE) + +static void +galahad_screen_destroy(struct pipe_screen *_screen) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct pipe_screen *screen = glhd_screen->screen; + + screen->destroy(screen); + + FREE(glhd_screen); +} + +static const char * +galahad_screen_get_name(struct pipe_screen *_screen) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct pipe_screen *screen = glhd_screen->screen; + + return screen->get_name(screen); +} + +static const char * +galahad_screen_get_vendor(struct pipe_screen *_screen) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct pipe_screen *screen = glhd_screen->screen; + + return screen->get_vendor(screen); +} + +static int +galahad_screen_get_param(struct pipe_screen *_screen, + enum pipe_cap param) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct pipe_screen *screen = glhd_screen->screen; + + return screen->get_param(screen, + param); +} + +static int +galahad_screen_get_shader_param(struct pipe_screen *_screen, + unsigned shader, enum pipe_shader_cap param) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct pipe_screen *screen = glhd_screen->screen; + + return screen->get_shader_param(screen, shader, + param); +} + +static float +galahad_screen_get_paramf(struct pipe_screen *_screen, + enum pipe_cap param) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct pipe_screen *screen = glhd_screen->screen; + + return screen->get_paramf(screen, + param); +} + +static boolean +galahad_screen_is_format_supported(struct pipe_screen *_screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned tex_usage, + unsigned geom_flags) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct pipe_screen *screen = glhd_screen->screen; + + if (target >= PIPE_MAX_TEXTURE_TYPES) { + glhd_warn("Received bogus texture target %d", target); + } + + return screen->is_format_supported(screen, + format, + target, + sample_count, + tex_usage, + geom_flags); +} + +static struct pipe_context * +galahad_screen_context_create(struct pipe_screen *_screen, + void *priv) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct pipe_screen *screen = glhd_screen->screen; + struct pipe_context *result; + + result = screen->context_create(screen, priv); + if (result) + return galahad_context_create(_screen, result); + return NULL; +} + +static struct pipe_resource * +galahad_screen_resource_create(struct pipe_screen *_screen, + const struct pipe_resource *templat) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct pipe_screen *screen = glhd_screen->screen; + struct pipe_resource *result; + + if (templat->target >= PIPE_MAX_TEXTURE_TYPES) + glhd_warn("Received bogus resource target %d", templat->target); + + if(templat->target != PIPE_TEXTURE_RECT && templat->target != PIPE_BUFFER && !screen->get_param(screen, PIPE_CAP_NPOT_TEXTURES)) + { + if(!util_is_power_of_two(templat->width0) || !util_is_power_of_two(templat->height0)) + glhd_warn("Requested NPOT (%ux%u) non-rectangle texture without NPOT support", templat->width0, templat->height0); + } + + if(templat->target == PIPE_TEXTURE_RECT && templat->last_level) + glhd_warn("Rectangle textures cannot have mipmaps, but last_level = %u", templat->last_level); + + if(templat->target == PIPE_BUFFER && templat->last_level) + glhd_warn("Buffers cannot have mipmaps, but last_level = %u", templat->last_level); + + if(templat->target != PIPE_TEXTURE_3D && templat->depth0 != 1) + glhd_warn("Only 3D textures can have depth != 1, but received target %u and depth %u", templat->target, templat->depth0); + + if(templat->target == PIPE_TEXTURE_1D && templat->height0 != 1) + glhd_warn("1D textures must have height 1 but got asked for height %u", templat->height0); + + if(templat->target == PIPE_BUFFER && templat->height0 != 1) + glhd_warn("Buffers must have height 1 but got asked for height %u", templat->height0); + + if(templat->target == PIPE_TEXTURE_CUBE && templat->width0 != templat->height0) + glhd_warn("Cube maps must be square, but got asked for %ux%u", templat->width0, templat->height0); + + result = screen->resource_create(screen, + templat); + + if (result) + return galahad_resource_create(glhd_screen, result); + return NULL; +} + +static struct pipe_resource * +galahad_screen_resource_from_handle(struct pipe_screen *_screen, + const struct pipe_resource *templ, + struct winsys_handle *handle) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct pipe_screen *screen = glhd_screen->screen; + struct pipe_resource *result; + + /* TODO trace call */ + + result = screen->resource_from_handle(screen, templ, handle); + + result = galahad_resource_create(galahad_screen(_screen), result); + + return result; +} + +static boolean +galahad_screen_resource_get_handle(struct pipe_screen *_screen, + struct pipe_resource *_resource, + struct winsys_handle *handle) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct galahad_resource *glhd_resource = galahad_resource(_resource); + struct pipe_screen *screen = glhd_screen->screen; + struct pipe_resource *resource = glhd_resource->resource; + + /* TODO trace call */ + + return screen->resource_get_handle(screen, resource, handle); +} + + + +static void +galahad_screen_resource_destroy(struct pipe_screen *screen, + struct pipe_resource *_resource) +{ + galahad_resource_destroy(galahad_resource(_resource)); +} + + +static struct pipe_resource * +galahad_screen_user_buffer_create(struct pipe_screen *_screen, + void *ptr, + unsigned bytes, + unsigned usage) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct pipe_screen *screen = glhd_screen->screen; + struct pipe_resource *result; + + result = screen->user_buffer_create(screen, + ptr, + bytes, + usage); + + if (result) + return galahad_resource_create(glhd_screen, result); + return NULL; +} + + + +static void +galahad_screen_flush_frontbuffer(struct pipe_screen *_screen, + struct pipe_resource *_resource, + unsigned level, unsigned layer, + void *context_private) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct galahad_resource *glhd_resource = galahad_resource(_resource); + struct pipe_screen *screen = glhd_screen->screen; + struct pipe_resource *resource = glhd_resource->resource; + + screen->flush_frontbuffer(screen, + resource, + level, layer, + context_private); +} + +static void +galahad_screen_fence_reference(struct pipe_screen *_screen, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct pipe_screen *screen = glhd_screen->screen; + + screen->fence_reference(screen, + ptr, + fence); +} + +static int +galahad_screen_fence_signalled(struct pipe_screen *_screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct pipe_screen *screen = glhd_screen->screen; + + return screen->fence_signalled(screen, + fence, + flags); +} + +static int +galahad_screen_fence_finish(struct pipe_screen *_screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + struct galahad_screen *glhd_screen = galahad_screen(_screen); + struct pipe_screen *screen = glhd_screen->screen; + + return screen->fence_finish(screen, + fence, + flags); +} + +struct pipe_screen * +galahad_screen_create(struct pipe_screen *screen) +{ + struct galahad_screen *glhd_screen; + + if (!debug_get_option_galahad()) + return screen; + + glhd_screen = CALLOC_STRUCT(galahad_screen); + if (!glhd_screen) { + return screen; + } + + glhd_screen->base.winsys = NULL; + + glhd_screen->base.destroy = galahad_screen_destroy; + glhd_screen->base.get_name = galahad_screen_get_name; + glhd_screen->base.get_vendor = galahad_screen_get_vendor; + glhd_screen->base.get_param = galahad_screen_get_param; + glhd_screen->base.get_shader_param = galahad_screen_get_shader_param; + glhd_screen->base.get_paramf = galahad_screen_get_paramf; + glhd_screen->base.is_format_supported = galahad_screen_is_format_supported; + glhd_screen->base.context_create = galahad_screen_context_create; + glhd_screen->base.resource_create = galahad_screen_resource_create; + glhd_screen->base.resource_from_handle = galahad_screen_resource_from_handle; + glhd_screen->base.resource_get_handle = galahad_screen_resource_get_handle; + glhd_screen->base.resource_destroy = galahad_screen_resource_destroy; + glhd_screen->base.user_buffer_create = galahad_screen_user_buffer_create; + glhd_screen->base.flush_frontbuffer = galahad_screen_flush_frontbuffer; + glhd_screen->base.fence_reference = galahad_screen_fence_reference; + glhd_screen->base.fence_signalled = galahad_screen_fence_signalled; + glhd_screen->base.fence_finish = galahad_screen_fence_finish; + + glhd_screen->screen = screen; + + glhd_warn("Created screen %p", (void *) glhd_screen); + + return &glhd_screen->base; +} diff --git a/src/gallium/drivers/galahad/glhd_screen.h b/src/gallium/drivers/galahad/glhd_screen.h new file mode 100644 index 0000000..7862f4a --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_screen.h @@ -0,0 +1,48 @@ +/************************************************************************** + * + * 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 GLHD_SCREEN_H +#define GLHD_SCREEN_H + +#include "pipe/p_screen.h" +#include "pipe/p_defines.h" + + +struct galahad_screen { + struct pipe_screen base; + + struct pipe_screen *screen; +}; + + +static INLINE struct galahad_screen * +galahad_screen(struct pipe_screen *screen) +{ + return (struct galahad_screen *)screen; +} + +#endif /* GLHD_SCREEN_H */ diff --git a/src/gallium/drivers/i915/Makefile b/src/gallium/drivers/i915/Makefile new file mode 100644 index 0000000..b3f387f --- /dev/null +++ b/src/gallium/drivers/i915/Makefile @@ -0,0 +1,31 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = i915 + +C_SOURCES = \ + i915_blit.c \ + i915_clear.c \ + i915_flush.c \ + i915_context.c \ + i915_debug.c \ + i915_debug_fp.c \ + i915_state.c \ + i915_state_immediate.c \ + i915_state_dynamic.c \ + i915_state_derived.c \ + i915_state_emit.c \ + i915_state_fpc.c \ + i915_state_sampler.c \ + i915_state_static.c \ + i915_screen.c \ + i915_prim_emit.c \ + i915_prim_vbuf.c \ + i915_resource.c \ + i915_resource_texture.c \ + i915_resource_buffer.c \ + i915_fpc_emit.c \ + i915_fpc_translate.c \ + i915_surface.c + +include ../../Makefile.template diff --git a/src/gallium/drivers/i915/SConscript b/src/gallium/drivers/i915/SConscript new file mode 100644 index 0000000..8f5deed --- /dev/null +++ b/src/gallium/drivers/i915/SConscript @@ -0,0 +1,35 @@ +Import('*') + +env = env.Clone() + +i915 = env.ConvenienceLibrary( + target = 'i915', + source = [ + 'i915_blit.c', + 'i915_resource_buffer.c', + 'i915_clear.c', + 'i915_context.c', + 'i915_debug.c', + 'i915_debug_fp.c', + 'i915_flush.c', + 'i915_fpc_emit.c', + 'i915_fpc_translate.c', + 'i915_prim_emit.c', + 'i915_prim_vbuf.c', + 'i915_screen.c', + 'i915_state.c', + 'i915_state_derived.c', + 'i915_state_dynamic.c', + 'i915_state_fpc.c', + 'i915_state_emit.c', + 'i915_state_immediate.c', + 'i915_state_sampler.c', + 'i915_state_static.c', + 'i915_surface.c', + 'i915_resource.c', + 'i915_resource_texture.c', + ]) + +env.Alias('i915', i915) + +Export('i915') diff --git a/src/gallium/drivers/i915/i915_batch.h b/src/gallium/drivers/i915/i915_batch.h new file mode 100644 index 0000000..6e93da7 --- /dev/null +++ b/src/gallium/drivers/i915/i915_batch.h @@ -0,0 +1,56 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef I915_BATCH_H +#define I915_BATCH_H + +#include "i915_batchbuffer.h" + + +#define BEGIN_BATCH(dwords, relocs) \ + (i915_winsys_batchbuffer_check(i915->batch, dwords, relocs)) + +#define OUT_BATCH(dword) \ + i915_winsys_batchbuffer_dword(i915->batch, dword) + +#define OUT_RELOC(buf, usage, offset) \ + i915_winsys_batchbuffer_reloc(i915->batch, buf, usage, offset, false) + +#define OUT_RELOC_FENCED(buf, usage, offset) \ + i915_winsys_batchbuffer_reloc(i915->batch, buf, usage, offset, true) + +#define FLUSH_BATCH(fence) \ + i915_flush(i915, fence) + + +/************************************************************************ + * i915_flush.c + */ +void i915_flush(struct i915_context *i915, struct pipe_fence_handle **fence); + + +#endif diff --git a/src/gallium/drivers/i915/i915_batchbuffer.h b/src/gallium/drivers/i915/i915_batchbuffer.h new file mode 100644 index 0000000..d92b2cc --- /dev/null +++ b/src/gallium/drivers/i915/i915_batchbuffer.h @@ -0,0 +1,87 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef I915_BATCHBUFFER_H +#define I915_BATCHBUFFER_H + +#include "i915_winsys.h" +#include "util/u_debug.h" + +struct i915_context; + +static INLINE size_t +i915_winsys_batchbuffer_space(struct i915_winsys_batchbuffer *batch) +{ + return batch->size - (batch->ptr - batch->map); +} + +static INLINE boolean +i915_winsys_batchbuffer_check(struct i915_winsys_batchbuffer *batch, + size_t dwords, + size_t relocs) +{ + return dwords * 4 <= i915_winsys_batchbuffer_space(batch) && + relocs <= (batch->max_relocs - batch->relocs); +} + +static INLINE void +i915_winsys_batchbuffer_dword_unchecked(struct i915_winsys_batchbuffer *batch, + unsigned dword) +{ + *(unsigned *)batch->ptr = dword; + batch->ptr += 4; +} + +static INLINE void +i915_winsys_batchbuffer_dword(struct i915_winsys_batchbuffer *batch, + unsigned dword) +{ + assert (i915_winsys_batchbuffer_space(batch) >= 4); + i915_winsys_batchbuffer_dword_unchecked(batch, dword); +} + +static INLINE void +i915_winsys_batchbuffer_write(struct i915_winsys_batchbuffer *batch, + void *data, + size_t size) +{ + assert (i915_winsys_batchbuffer_space(batch) >= size); + + memcpy(data, batch->ptr, size); + batch->ptr += size; +} + +static INLINE int +i915_winsys_batchbuffer_reloc(struct i915_winsys_batchbuffer *batch, + struct i915_winsys_buffer *buffer, + enum i915_winsys_buffer_usage usage, + size_t offset, bool fenced) +{ + return batch->iws->batchbuffer_reloc(batch, buffer, usage, offset, fenced); +} + +#endif diff --git a/src/gallium/drivers/i915/i915_blit.c b/src/gallium/drivers/i915/i915_blit.c new file mode 100644 index 0000000..97c2566 --- /dev/null +++ b/src/gallium/drivers/i915/i915_blit.c @@ -0,0 +1,145 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + + +#include "i915_blit.h" +#include "i915_reg.h" +#include "i915_batch.h" +#include "i915_debug.h" + + +void +i915_fill_blit(struct i915_context *i915, + unsigned cpp, + unsigned rgba_mask, + unsigned short dst_pitch, + struct i915_winsys_buffer *dst_buffer, + unsigned dst_offset, + short x, short y, + short w, short h, + unsigned color) +{ + unsigned BR13, CMD; + + + I915_DBG(DBG_BLIT, "%s dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n", + __FUNCTION__, dst_buffer, dst_pitch, dst_offset, x, y, w, h); + + switch (cpp) { + case 1: + case 2: + case 3: + BR13 = (((int) dst_pitch) & 0xffff) | + (0xF0 << 16) | (1 << 24); + CMD = XY_COLOR_BLT_CMD; + break; + case 4: + BR13 = (((int) dst_pitch) & 0xffff) | + (0xF0 << 16) | (1 << 24) | (1 << 25); + CMD = (XY_COLOR_BLT_CMD | rgba_mask); + break; + default: + return; + } + + if (!BEGIN_BATCH(6, 1)) { + FLUSH_BATCH(NULL); + assert(BEGIN_BATCH(6, 1)); + } + OUT_BATCH(CMD); + OUT_BATCH(BR13); + OUT_BATCH((y << 16) | x); + OUT_BATCH(((y + h) << 16) | (x + w)); + OUT_RELOC_FENCED(dst_buffer, I915_USAGE_2D_TARGET, dst_offset); + OUT_BATCH(color); +} + +void +i915_copy_blit(struct i915_context *i915, + unsigned cpp, + unsigned short src_pitch, + struct i915_winsys_buffer *src_buffer, + unsigned src_offset, + unsigned short dst_pitch, + struct i915_winsys_buffer *dst_buffer, + unsigned dst_offset, + short src_x, short src_y, + short dst_x, short dst_y, + short w, short h) +{ + unsigned CMD, BR13; + int dst_y2 = dst_y + h; + int dst_x2 = dst_x + w; + + + I915_DBG(DBG_BLIT, + "%s src:buf(%p)/%d+%d %d,%d dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n", + __FUNCTION__, + src_buffer, src_pitch, src_offset, src_x, src_y, + dst_buffer, dst_pitch, dst_offset, dst_x, dst_y, w, h); + + switch (cpp) { + case 1: + case 2: + case 3: + BR13 = (((int) dst_pitch) & 0xffff) | + (0xCC << 16) | (1 << 24); + CMD = XY_SRC_COPY_BLT_CMD; + break; + case 4: + BR13 = (((int) dst_pitch) & 0xffff) | + (0xCC << 16) | (1 << 24) | (1 << 25); + CMD = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA | + XY_SRC_COPY_BLT_WRITE_RGB); + break; + default: + return; + } + + if (dst_y2 < dst_y || dst_x2 < dst_x) { + return; + } + + /* Hardware can handle negative pitches but loses the ability to do + * proper overlapping blits in that case. We don't really have a + * need for either at this stage. + */ + assert (dst_pitch > 0 && src_pitch > 0); + + if (!BEGIN_BATCH(8, 2)) { + FLUSH_BATCH(NULL); + assert(BEGIN_BATCH(8, 2)); + } + OUT_BATCH(CMD); + OUT_BATCH(BR13); + OUT_BATCH((dst_y << 16) | dst_x); + OUT_BATCH((dst_y2 << 16) | dst_x2); + OUT_RELOC_FENCED(dst_buffer, I915_USAGE_2D_TARGET, dst_offset); + OUT_BATCH((src_y << 16) | src_x); + OUT_BATCH(((int) src_pitch & 0xffff)); + OUT_RELOC_FENCED(src_buffer, I915_USAGE_2D_SOURCE, src_offset); +} diff --git a/src/gallium/drivers/i915/i915_blit.h b/src/gallium/drivers/i915/i915_blit.h new file mode 100644 index 0000000..d82d2f2 --- /dev/null +++ b/src/gallium/drivers/i915/i915_blit.h @@ -0,0 +1,55 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + +#ifndef I915_BLIT_H +#define I915_BLIT_H + +#include "i915_context.h" + +extern void i915_copy_blit(struct i915_context *i915, + unsigned cpp, + unsigned short src_pitch, + struct i915_winsys_buffer *src_buffer, + unsigned src_offset, + unsigned short dst_pitch, + struct i915_winsys_buffer *dst_buffer, + unsigned dst_offset, + short srcx, short srcy, + short dstx, short dsty, + short w, short h); + +extern void i915_fill_blit(struct i915_context *i915, + unsigned cpp, + unsigned rgba_mask, + unsigned short dst_pitch, + struct i915_winsys_buffer *dst_buffer, + unsigned dst_offset, + short x, short y, + short w, short h, unsigned color); + + +#endif diff --git a/src/gallium/drivers/i915/i915_clear.c b/src/gallium/drivers/i915/i915_clear.c new file mode 100644 index 0000000..6d824a5 --- /dev/null +++ b/src/gallium/drivers/i915/i915_clear.c @@ -0,0 +1,47 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: + * Brian Paul + */ + + +#include "util/u_clear.h" +#include "i915_context.h" + + +/** + * Clear the given buffers to the specified values. + * No masking, no scissor (clear entire buffer). + */ +void +i915_clear(struct pipe_context *pipe, unsigned buffers, const float *rgba, + double depth, unsigned stencil) +{ + util_clear(pipe, &i915_context(pipe)->framebuffer, buffers, rgba, depth, + stencil); +} diff --git a/src/gallium/drivers/i915/i915_context.c b/src/gallium/drivers/i915/i915_context.c new file mode 100644 index 0000000..847dd6d --- /dev/null +++ b/src/gallium/drivers/i915/i915_context.c @@ -0,0 +1,166 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + +#include "i915_context.h" +#include "i915_state.h" +#include "i915_screen.h" +#include "i915_surface.h" +#include "i915_batch.h" +#include "i915_resource.h" + +#include "draw/draw_context.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "pipe/p_screen.h" + + +/* + * Draw functions + */ + + +static void +i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) +{ + struct i915_context *i915 = i915_context(pipe); + struct draw_context *draw = i915->draw; + void *mapped_indices = NULL; + unsigned i; + + if (i915->dirty) + i915_update_derived(i915); + + /* + * Map vertex buffers + */ + for (i = 0; i < i915->num_vertex_buffers; i++) { + void *buf = i915_buffer(i915->vertex_buffer[i].buffer)->data; + draw_set_mapped_vertex_buffer(draw, i, buf); + } + + /* + * Map index buffer, if present + */ + if (info->indexed && i915->index_buffer.buffer) + mapped_indices = i915_buffer(i915->index_buffer.buffer)->data; + draw_set_mapped_index_buffer(draw, mapped_indices); + + draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 0, + i915->current.constants[PIPE_SHADER_VERTEX], + (i915->current.num_user_constants[PIPE_SHADER_VERTEX] * + 4 * sizeof(float))); + + /* + * Do the drawing + */ + draw_vbo(i915->draw, info); + + /* + * unmap vertex/index buffers + */ + for (i = 0; i < i915->num_vertex_buffers; i++) { + draw_set_mapped_vertex_buffer(draw, i, NULL); + } + + if (mapped_indices) + draw_set_mapped_index_buffer(draw, NULL); +} + + +/* + * Generic context functions + */ + + +static void i915_destroy(struct pipe_context *pipe) +{ + struct i915_context *i915 = i915_context(pipe); + int i; + + draw_destroy(i915->draw); + + if(i915->batch) + i915->iws->batchbuffer_destroy(i915->batch); + + /* unbind framebuffer */ + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + pipe_surface_reference(&i915->framebuffer.cbufs[i], NULL); + } + pipe_surface_reference(&i915->framebuffer.zsbuf, NULL); + + FREE(i915); +} + +struct pipe_context * +i915_create_context(struct pipe_screen *screen, void *priv) +{ + struct i915_context *i915; + + i915 = CALLOC_STRUCT(i915_context); + if (i915 == NULL) + return NULL; + + i915->iws = i915_screen(screen)->iws; + i915->base.winsys = NULL; + i915->base.screen = screen; + i915->base.priv = priv; + + i915->base.destroy = i915_destroy; + + i915->base.clear = i915_clear; + + i915->base.draw_vbo = i915_draw_vbo; + + /* + * Create drawing context and plug our rendering stage into it. + */ + i915->draw = draw_create(&i915->base); + assert(i915->draw); + if (!debug_get_bool_option("I915_NO_VBUF", FALSE)) { + draw_set_rasterize_stage(i915->draw, i915_draw_vbuf_stage(i915)); + } else { + draw_set_rasterize_stage(i915->draw, i915_draw_render_stage(i915)); + } + + i915_init_surface_functions(i915); + i915_init_state_functions(i915); + i915_init_flush_functions(i915); + i915_init_resource_functions(i915); + + draw_install_aaline_stage(i915->draw, &i915->base); + draw_install_aapoint_stage(i915->draw, &i915->base); + + i915->dirty = ~0; + i915->hardware_dirty = ~0; + + /* Batch stream debugging is a bit hacked up at the moment: + */ + i915->batch = i915->iws->batchbuffer_create(i915->iws); + + return &i915->base; +} diff --git a/src/gallium/drivers/i915/i915_context.h b/src/gallium/drivers/i915/i915_context.h new file mode 100644 index 0000000..7103a1b --- /dev/null +++ b/src/gallium/drivers/i915/i915_context.h @@ -0,0 +1,330 @@ + /************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + +#ifndef I915_CONTEXT_H +#define I915_CONTEXT_H + + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" + +#include "draw/draw_vertex.h" + +#include "tgsi/tgsi_scan.h" + + +struct i915_winsys; +struct i915_winsys_buffer; +struct i915_winsys_batchbuffer; + + +#define I915_TEX_UNITS 8 + +#define I915_DYNAMIC_MODES4 0 +#define I915_DYNAMIC_DEPTHSCALE_0 1 /* just the header */ +#define I915_DYNAMIC_DEPTHSCALE_1 2 +#define I915_DYNAMIC_IAB 3 +#define I915_DYNAMIC_BC_0 4 /* just the header */ +#define I915_DYNAMIC_BC_1 5 +#define I915_DYNAMIC_BFO_0 6 +#define I915_DYNAMIC_BFO_1 7 +#define I915_DYNAMIC_STP_0 8 +#define I915_DYNAMIC_STP_1 9 +#define I915_DYNAMIC_SC_ENA_0 10 +#define I915_DYNAMIC_SC_RECT_0 11 +#define I915_DYNAMIC_SC_RECT_1 12 +#define I915_DYNAMIC_SC_RECT_2 13 +#define I915_MAX_DYNAMIC 14 + + +#define I915_IMMEDIATE_S0 0 +#define I915_IMMEDIATE_S1 1 +#define I915_IMMEDIATE_S2 2 +#define I915_IMMEDIATE_S3 3 +#define I915_IMMEDIATE_S4 4 +#define I915_IMMEDIATE_S5 5 +#define I915_IMMEDIATE_S6 6 +#define I915_IMMEDIATE_S7 7 +#define I915_MAX_IMMEDIATE 8 + +/* These must mach the order of LI0_STATE_* bits, as they will be used + * to generate hardware packets: + */ +#define I915_CACHE_STATIC 0 +#define I915_CACHE_DYNAMIC 1 /* handled specially */ +#define I915_CACHE_SAMPLER 2 +#define I915_CACHE_MAP 3 +#define I915_CACHE_PROGRAM 4 +#define I915_CACHE_CONSTANTS 5 +#define I915_MAX_CACHE 6 + +#define I915_MAX_CONSTANT 32 + + +/** See constant_flags[] below */ +#define I915_CONSTFLAG_USER 0x1f + + +/** + * Subclass of pipe_shader_state + */ +struct i915_fragment_shader +{ + struct pipe_shader_state state; + + struct tgsi_shader_info info; + + uint *program; + uint program_len; + + /** + * constants introduced during translation. + * These are placed at the end of the constant buffer and grow toward + * the beginning (eg: slot 31, 30 29, ...) + * User-provided constants start at 0. + * This allows both types of constants to co-exist (until there's too many) + * and doesn't require regenerating/changing the fragment program to + * shuffle constants around. + */ + uint num_constants; + float constants[I915_MAX_CONSTANT][4]; + + /** + * Status of each constant + * if I915_CONSTFLAG_PARAM, the value must be taken from the corresponding + * slot of the user's constant buffer. (set by pipe->set_constant_buffer()) + * Else, the bitmask indicates which components are occupied by immediates. + */ + ubyte constant_flags[I915_MAX_CONSTANT]; +}; + + +struct i915_cache_context; + +/* Use to calculate differences between state emitted to hardware and + * current driver-calculated state. + */ +struct i915_state +{ + unsigned immediate[I915_MAX_IMMEDIATE]; + unsigned dynamic[I915_MAX_DYNAMIC]; + + float constants[PIPE_SHADER_TYPES][I915_MAX_CONSTANT][4]; + /** number of constants passed in through a constant buffer */ + uint num_user_constants[PIPE_SHADER_TYPES]; + + /* texture sampler state */ + unsigned sampler[I915_TEX_UNITS][3]; + unsigned sampler_enable_flags; + unsigned sampler_enable_nr; + + /* texture image buffers */ + unsigned texbuffer[I915_TEX_UNITS][2]; + + /** Describes the current hardware vertex layout */ + struct vertex_info vertex_info; + + unsigned id; /* track lost context events */ +}; + +struct i915_blend_state { + unsigned iab; + unsigned modes4; + unsigned LIS5; + unsigned LIS6; +}; + +struct i915_depth_stencil_state { + unsigned stencil_modes4; + unsigned bfo[2]; + unsigned stencil_LIS5; + unsigned depth_LIS6; +}; + +struct i915_rasterizer_state { + unsigned light_twoside : 1; + unsigned st; + enum interp_mode color_interp; + + unsigned LIS4; + unsigned LIS7; + unsigned sc[1]; + + const struct pipe_rasterizer_state *templ; + + union { float f; unsigned u; } ds[2]; +}; + +struct i915_sampler_state { + unsigned state[3]; + const struct pipe_sampler_state *templ; + unsigned minlod; + unsigned maxlod; +}; + +struct i915_velems_state { + unsigned count; + struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS]; +}; + + +struct i915_context { + struct pipe_context base; + + struct i915_winsys *iws; + + struct draw_context *draw; + + /* The most recent drawing state as set by the driver: + */ + const struct i915_blend_state *blend; + const struct i915_sampler_state *sampler[PIPE_MAX_SAMPLERS]; + const struct i915_depth_stencil_state *depth_stencil; + const struct i915_rasterizer_state *rasterizer; + + struct i915_fragment_shader *fs; + + struct pipe_blend_color blend_color; + struct pipe_stencil_ref stencil_ref; + struct pipe_clip_state clip; + /* XXX unneded */ + struct pipe_resource *constants[PIPE_SHADER_TYPES]; + struct pipe_framebuffer_state framebuffer; + struct pipe_poly_stipple poly_stipple; + struct pipe_scissor_state scissor; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; + struct pipe_viewport_state viewport; + struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; + struct pipe_index_buffer index_buffer; + + unsigned dirty; + + unsigned num_samplers; + unsigned num_fragment_sampler_views; + unsigned num_vertex_buffers; + + struct i915_winsys_batchbuffer *batch; + + /** Vertex buffer */ + struct i915_winsys_buffer *vbo; + size_t vbo_offset; + unsigned vbo_flushed; + + struct i915_state current; + unsigned hardware_dirty; +}; + +/* A flag for each state_tracker state object: + */ +#define I915_NEW_VIEWPORT 0x1 +#define I915_NEW_RASTERIZER 0x2 +#define I915_NEW_FS 0x4 +#define I915_NEW_BLEND 0x8 +#define I915_NEW_CLIP 0x10 +#define I915_NEW_SCISSOR 0x20 +#define I915_NEW_STIPPLE 0x40 +#define I915_NEW_FRAMEBUFFER 0x80 +#define I915_NEW_ALPHA_TEST 0x100 +#define I915_NEW_DEPTH_STENCIL 0x200 +#define I915_NEW_SAMPLER 0x400 +#define I915_NEW_SAMPLER_VIEW 0x800 +#define I915_NEW_CONSTANTS 0x1000 +#define I915_NEW_VBO 0x2000 +#define I915_NEW_VS 0x4000 + + +/* Driver's internally generated state flags: + */ +#define I915_NEW_VERTEX_FORMAT 0x10000 + + +/* Dirty flags for hardware emit + */ +#define I915_HW_STATIC (1<ptr + stream->offset); + + if (len == 0) { + PRINTF(stream, "Error - zero length packet (0x%08x)\n", stream->ptr[0]); + assert(0); + return FALSE; + } + + if (stream->print_addresses) + PRINTF(stream, "%08x: ", stream->offset); + + + PRINTF(stream, "%s (%d dwords):\n", name, len); + for (i = 0; i < len; i++) + PRINTF(stream, "\t0x%08x\n", ptr[i]); + PRINTF(stream, "\n"); + + stream->offset += len * sizeof(unsigned); + + return TRUE; +} + + +static const char *get_prim_name( unsigned val ) +{ + switch (val & PRIM3D_MASK) { + case PRIM3D_TRILIST: return "TRILIST"; break; + case PRIM3D_TRISTRIP: return "TRISTRIP"; break; + case PRIM3D_TRISTRIP_RVRSE: return "TRISTRIP_RVRSE"; break; + case PRIM3D_TRIFAN: return "TRIFAN"; break; + case PRIM3D_POLY: return "POLY"; break; + case PRIM3D_LINELIST: return "LINELIST"; break; + case PRIM3D_LINESTRIP: return "LINESTRIP"; break; + case PRIM3D_RECTLIST: return "RECTLIST"; break; + case PRIM3D_POINTLIST: return "POINTLIST"; break; + case PRIM3D_DIB: return "DIB"; break; + case PRIM3D_CLEAR_RECT: return "CLEAR_RECT"; break; + case PRIM3D_ZONE_INIT: return "ZONE_INIT"; break; + default: return "????"; break; + } +} + +static boolean debug_prim( struct debug_stream *stream, const char *name, + boolean dump_floats, + unsigned len ) +{ + unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); + const char *prim = get_prim_name( ptr[0] ); + unsigned i; + + + + PRINTF(stream, "%s %s (%d dwords):\n", name, prim, len); + PRINTF(stream, "\t0x%08x\n", ptr[0]); + for (i = 1; i < len; i++) { + if (dump_floats) + PRINTF(stream, "\t0x%08x // %f\n", ptr[i], *(float *)&ptr[i]); + else + PRINTF(stream, "\t0x%08x\n", ptr[i]); + } + + + PRINTF(stream, "\n"); + + stream->offset += len * sizeof(unsigned); + + return TRUE; +} + + + + +static boolean debug_program( struct debug_stream *stream, const char *name, unsigned len ) +{ + unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); + + if (len == 0) { + PRINTF(stream, "Error - zero length packet (0x%08x)\n", stream->ptr[0]); + assert(0); + return FALSE; + } + + if (stream->print_addresses) + PRINTF(stream, "%08x: ", stream->offset); + + PRINTF(stream, "%s (%d dwords):\n", name, len); + i915_disassemble_program( stream, ptr, len ); + + stream->offset += len * sizeof(unsigned); + return TRUE; +} + + +static boolean debug_chain( struct debug_stream *stream, const char *name, unsigned len ) +{ + unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); + unsigned old_offset = stream->offset + len * sizeof(unsigned); + unsigned i; + + PRINTF(stream, "%s (%d dwords):\n", name, len); + for (i = 0; i < len; i++) + PRINTF(stream, "\t0x%08x\n", ptr[i]); + + stream->offset = ptr[1] & ~0x3; + + if (stream->offset < old_offset) + PRINTF(stream, "\n... skipping backwards from 0x%x --> 0x%x ...\n\n", + old_offset, stream->offset ); + else + PRINTF(stream, "\n... skipping from 0x%x --> 0x%x ...\n\n", + old_offset, stream->offset ); + + + return TRUE; +} + + +static boolean debug_variable_length_prim( struct debug_stream *stream ) +{ + unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); + const char *prim = get_prim_name( ptr[0] ); + unsigned i, len; + + ushort *idx = (ushort *)(ptr+1); + for (i = 0; idx[i] != 0xffff; i++) + ; + + len = 1+(i+2)/2; + + PRINTF(stream, "3DPRIM, %s variable length %d indicies (%d dwords):\n", prim, i, len); + for (i = 0; i < len; i++) + PRINTF(stream, "\t0x%08x\n", ptr[i]); + PRINTF(stream, "\n"); + + stream->offset += len * sizeof(unsigned); + return TRUE; +} + + +static void +BITS( + struct debug_stream *stream, + unsigned dw, + unsigned hi, + unsigned lo, + const char *fmt, + ... ) +{ + va_list args; + unsigned himask = ~0UL >> (31 - (hi)); + + PRINTF(stream, "\t\t "); + + va_start( args, fmt ); + debug_vprintf( fmt, args ); + va_end( args ); + + PRINTF(stream, ": 0x%x\n", ((dw) & himask) >> (lo)); +} + +#ifdef DEBUG +#define MBZ( dw, hi, lo) do { \ + unsigned x = (dw) >> (lo); \ + unsigned lomask = (1 << (lo)) - 1; \ + unsigned himask; \ + himask = (1UL << (hi)) - 1; \ + assert ((x & himask & ~lomask) == 0); \ +} while (0) +#else +#define MBZ( dw, hi, lo) do { \ +} while (0) +#endif + +static void +FLAG( + struct debug_stream *stream, + unsigned dw, + unsigned bit, + const char *fmt, + ... ) +{ + if (((dw) >> (bit)) & 1) { + va_list args; + + PRINTF(stream, "\t\t "); + + va_start( args, fmt ); + debug_vprintf( fmt, args ); + va_end( args ); + + PRINTF(stream, "\n"); + } +} + +static boolean debug_load_immediate( struct debug_stream *stream, + const char *name, + unsigned len ) +{ + unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); + unsigned bits = (ptr[0] >> 4) & 0xff; + unsigned j = 0; + + PRINTF(stream, "%s (%d dwords, flags: %x):\n", name, len, bits); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); + + if (bits & (1<<0)) { + PRINTF(stream, "\t LIS0: 0x%08x\n", ptr[j]); + PRINTF(stream, "\t vb address: 0x%08x\n", (ptr[j] & ~0x3)); + BITS(stream, ptr[j], 0, 0, "vb invalidate disable"); + j++; + } + if (bits & (1<<1)) { + PRINTF(stream, "\t LIS1: 0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 29, 24, "vb dword width"); + BITS(stream, ptr[j], 21, 16, "vb dword pitch"); + BITS(stream, ptr[j], 15, 0, "vb max index"); + j++; + } + if (bits & (1<<2)) { + int i; + PRINTF(stream, "\t LIS2: 0x%08x\n", ptr[j]); + for (i = 0; i < 8; i++) { + unsigned tc = (ptr[j] >> (i * 4)) & 0xf; + if (tc != 0xf) + BITS(stream, tc, 3, 0, "tex coord %d", i); + } + j++; + } + if (bits & (1<<3)) { + PRINTF(stream, "\t LIS3: 0x%08x\n", ptr[j]); + j++; + } + if (bits & (1<<4)) { + PRINTF(stream, "\t LIS4: 0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 31, 23, "point width"); + BITS(stream, ptr[j], 22, 19, "line width"); + FLAG(stream, ptr[j], 18, "alpha flatshade"); + FLAG(stream, ptr[j], 17, "fog flatshade"); + FLAG(stream, ptr[j], 16, "spec flatshade"); + FLAG(stream, ptr[j], 15, "rgb flatshade"); + BITS(stream, ptr[j], 14, 13, "cull mode"); + FLAG(stream, ptr[j], 12, "vfmt: point width"); + FLAG(stream, ptr[j], 11, "vfmt: specular/fog"); + FLAG(stream, ptr[j], 10, "vfmt: rgba"); + FLAG(stream, ptr[j], 9, "vfmt: depth offset"); + BITS(stream, ptr[j], 8, 6, "vfmt: position (2==xyzw)"); + FLAG(stream, ptr[j], 5, "force dflt diffuse"); + FLAG(stream, ptr[j], 4, "force dflt specular"); + FLAG(stream, ptr[j], 3, "local depth offset enable"); + FLAG(stream, ptr[j], 2, "vfmt: fp32 fog coord"); + FLAG(stream, ptr[j], 1, "sprite point"); + FLAG(stream, ptr[j], 0, "antialiasing"); + j++; + } + if (bits & (1<<5)) { + PRINTF(stream, "\t LIS5: 0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 31, 28, "rgba write disables"); + FLAG(stream, ptr[j], 27, "force dflt point width"); + FLAG(stream, ptr[j], 26, "last pixel enable"); + FLAG(stream, ptr[j], 25, "global z offset enable"); + FLAG(stream, ptr[j], 24, "fog enable"); + BITS(stream, ptr[j], 23, 16, "stencil ref"); + BITS(stream, ptr[j], 15, 13, "stencil test"); + BITS(stream, ptr[j], 12, 10, "stencil fail op"); + BITS(stream, ptr[j], 9, 7, "stencil pass z fail op"); + BITS(stream, ptr[j], 6, 4, "stencil pass z pass op"); + FLAG(stream, ptr[j], 3, "stencil write enable"); + FLAG(stream, ptr[j], 2, "stencil test enable"); + FLAG(stream, ptr[j], 1, "color dither enable"); + FLAG(stream, ptr[j], 0, "logiop enable"); + j++; + } + if (bits & (1<<6)) { + PRINTF(stream, "\t LIS6: 0x%08x\n", ptr[j]); + FLAG(stream, ptr[j], 31, "alpha test enable"); + BITS(stream, ptr[j], 30, 28, "alpha func"); + BITS(stream, ptr[j], 27, 20, "alpha ref"); + FLAG(stream, ptr[j], 19, "depth test enable"); + BITS(stream, ptr[j], 18, 16, "depth func"); + FLAG(stream, ptr[j], 15, "blend enable"); + BITS(stream, ptr[j], 14, 12, "blend func"); + BITS(stream, ptr[j], 11, 8, "blend src factor"); + BITS(stream, ptr[j], 7, 4, "blend dst factor"); + FLAG(stream, ptr[j], 3, "depth write enable"); + FLAG(stream, ptr[j], 2, "color write enable"); + BITS(stream, ptr[j], 1, 0, "provoking vertex"); + j++; + } + + + PRINTF(stream, "\n"); + + assert(j == len); + + stream->offset += len * sizeof(unsigned); + + return TRUE; +} + + + +static boolean debug_load_indirect( struct debug_stream *stream, + const char *name, + unsigned len ) +{ + unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); + unsigned bits = (ptr[0] >> 8) & 0x3f; + unsigned i, j = 0; + + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); + + for (i = 0; i < 6; i++) { + if (bits & (1<offset += len * sizeof(unsigned); + + return TRUE; +} + +static void BR13( struct debug_stream *stream, + unsigned val ) +{ + PRINTF(stream, "\t0x%08x\n", val); + FLAG(stream, val, 30, "clipping enable"); + BITS(stream, val, 25, 24, "color depth (3==32bpp)"); + BITS(stream, val, 23, 16, "raster op"); + BITS(stream, val, 15, 0, "dest pitch"); +} + + +static void BR22( struct debug_stream *stream, + unsigned val ) +{ + PRINTF(stream, "\t0x%08x\n", val); + BITS(stream, val, 31, 16, "dest y1"); + BITS(stream, val, 15, 0, "dest x1"); +} + +static void BR23( struct debug_stream *stream, + unsigned val ) +{ + PRINTF(stream, "\t0x%08x\n", val); + BITS(stream, val, 31, 16, "dest y2"); + BITS(stream, val, 15, 0, "dest x2"); +} + +static void BR09( struct debug_stream *stream, + unsigned val ) +{ + PRINTF(stream, "\t0x%08x -- dest address\n", val); +} + +static void BR26( struct debug_stream *stream, + unsigned val ) +{ + PRINTF(stream, "\t0x%08x\n", val); + BITS(stream, val, 31, 16, "src y1"); + BITS(stream, val, 15, 0, "src x1"); +} + +static void BR11( struct debug_stream *stream, + unsigned val ) +{ + PRINTF(stream, "\t0x%08x\n", val); + BITS(stream, val, 15, 0, "src pitch"); +} + +static void BR12( struct debug_stream *stream, + unsigned val ) +{ + PRINTF(stream, "\t0x%08x -- src address\n", val); +} + +static void BR16( struct debug_stream *stream, + unsigned val ) +{ + PRINTF(stream, "\t0x%08x -- color\n", val); +} + +static boolean debug_copy_blit( struct debug_stream *stream, + const char *name, + unsigned len ) +{ + unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); + int j = 0; + + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); + + BR13(stream, ptr[j++]); + BR22(stream, ptr[j++]); + BR23(stream, ptr[j++]); + BR09(stream, ptr[j++]); + BR26(stream, ptr[j++]); + BR11(stream, ptr[j++]); + BR12(stream, ptr[j++]); + + stream->offset += len * sizeof(unsigned); + assert(j == len); + return TRUE; +} + +static boolean debug_color_blit( struct debug_stream *stream, + const char *name, + unsigned len ) +{ + unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); + int j = 0; + + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); + + BR13(stream, ptr[j++]); + BR22(stream, ptr[j++]); + BR23(stream, ptr[j++]); + BR09(stream, ptr[j++]); + BR16(stream, ptr[j++]); + + stream->offset += len * sizeof(unsigned); + assert(j == len); + return TRUE; +} + +static boolean debug_modes4( struct debug_stream *stream, + const char *name, + unsigned len ) +{ + unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); + int j = 0; + + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 21, 18, "logicop func"); + FLAG(stream, ptr[j], 17, "stencil test mask modify-enable"); + FLAG(stream, ptr[j], 16, "stencil write mask modify-enable"); + BITS(stream, ptr[j], 15, 8, "stencil test mask"); + BITS(stream, ptr[j], 7, 0, "stencil write mask"); + j++; + + stream->offset += len * sizeof(unsigned); + assert(j == len); + return TRUE; +} + +static boolean debug_map_state( struct debug_stream *stream, + const char *name, + unsigned len ) +{ + unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); + unsigned j = 0; + + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); + + { + PRINTF(stream, "\t0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 15, 0, "map mask"); + j++; + } + + while (j < len) { + { + PRINTF(stream, "\t TMn.0: 0x%08x\n", ptr[j]); + PRINTF(stream, "\t map address: 0x%08x\n", (ptr[j] & ~0x3)); + FLAG(stream, ptr[j], 1, "vertical line stride"); + FLAG(stream, ptr[j], 0, "vertical line stride offset"); + j++; + } + + { + PRINTF(stream, "\t TMn.1: 0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 31, 21, "height"); + BITS(stream, ptr[j], 20, 10, "width"); + BITS(stream, ptr[j], 9, 7, "surface format"); + BITS(stream, ptr[j], 6, 3, "texel format"); + FLAG(stream, ptr[j], 2, "use fence regs"); + FLAG(stream, ptr[j], 1, "tiled surface"); + FLAG(stream, ptr[j], 0, "tile walk ymajor"); + j++; + } + { + PRINTF(stream, "\t TMn.2: 0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 31, 21, "dword pitch"); + BITS(stream, ptr[j], 20, 15, "cube face enables"); + BITS(stream, ptr[j], 14, 9, "max lod"); + FLAG(stream, ptr[j], 8, "mip layout right"); + BITS(stream, ptr[j], 7, 0, "depth"); + j++; + } + } + + stream->offset += len * sizeof(unsigned); + assert(j == len); + return TRUE; +} + +static boolean debug_sampler_state( struct debug_stream *stream, + const char *name, + unsigned len ) +{ + unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); + unsigned j = 0; + + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); + + { + PRINTF(stream, "\t0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 15, 0, "sampler mask"); + j++; + } + + while (j < len) { + { + PRINTF(stream, "\t TSn.0: 0x%08x\n", ptr[j]); + FLAG(stream, ptr[j], 31, "reverse gamma"); + FLAG(stream, ptr[j], 30, "planar to packed"); + FLAG(stream, ptr[j], 29, "yuv->rgb"); + BITS(stream, ptr[j], 28, 27, "chromakey index"); + BITS(stream, ptr[j], 26, 22, "base mip level"); + BITS(stream, ptr[j], 21, 20, "mip mode filter"); + BITS(stream, ptr[j], 19, 17, "mag mode filter"); + BITS(stream, ptr[j], 16, 14, "min mode filter"); + BITS(stream, ptr[j], 13, 5, "lod bias (s4.4)"); + FLAG(stream, ptr[j], 4, "shadow enable"); + FLAG(stream, ptr[j], 3, "max-aniso-4"); + BITS(stream, ptr[j], 2, 0, "shadow func"); + j++; + } + + { + PRINTF(stream, "\t TSn.1: 0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 31, 24, "min lod"); + MBZ( ptr[j], 23, 18 ); + FLAG(stream, ptr[j], 17, "kill pixel enable"); + FLAG(stream, ptr[j], 16, "keyed tex filter mode"); + FLAG(stream, ptr[j], 15, "chromakey enable"); + BITS(stream, ptr[j], 14, 12, "tcx wrap mode"); + BITS(stream, ptr[j], 11, 9, "tcy wrap mode"); + BITS(stream, ptr[j], 8, 6, "tcz wrap mode"); + FLAG(stream, ptr[j], 5, "normalized coords"); + BITS(stream, ptr[j], 4, 1, "map (surface) index"); + FLAG(stream, ptr[j], 0, "EAST deinterlacer enable"); + j++; + } + { + PRINTF(stream, "\t TSn.2: 0x%08x (default color)\n", ptr[j]); + j++; + } + } + + stream->offset += len * sizeof(unsigned); + assert(j == len); + return TRUE; +} + +static boolean debug_dest_vars( struct debug_stream *stream, + const char *name, + unsigned len ) +{ + unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); + int j = 0; + + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); + + { + PRINTF(stream, "\t0x%08x\n", ptr[j]); + FLAG(stream, ptr[j], 31, "early classic ztest"); + FLAG(stream, ptr[j], 30, "opengl tex default color"); + FLAG(stream, ptr[j], 29, "bypass iz"); + FLAG(stream, ptr[j], 28, "lod preclamp"); + BITS(stream, ptr[j], 27, 26, "dither pattern"); + FLAG(stream, ptr[j], 25, "linear gamma blend"); + FLAG(stream, ptr[j], 24, "debug dither"); + BITS(stream, ptr[j], 23, 20, "dstorg x"); + BITS(stream, ptr[j], 19, 16, "dstorg y"); + MBZ (ptr[j], 15, 15 ); + BITS(stream, ptr[j], 14, 12, "422 write select"); + BITS(stream, ptr[j], 11, 8, "cbuf format"); + BITS(stream, ptr[j], 3, 2, "zbuf format"); + FLAG(stream, ptr[j], 1, "vert line stride"); + FLAG(stream, ptr[j], 1, "vert line stride offset"); + j++; + } + + stream->offset += len * sizeof(unsigned); + assert(j == len); + return TRUE; +} + +static boolean debug_buf_info( struct debug_stream *stream, + const char *name, + unsigned len ) +{ + unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); + int j = 0; + + PRINTF(stream, "%s (%d dwords):\n", name, len); + PRINTF(stream, "\t0x%08x\n", ptr[j++]); + + { + PRINTF(stream, "\t0x%08x\n", ptr[j]); + BITS(stream, ptr[j], 28, 28, "aux buffer id"); + BITS(stream, ptr[j], 27, 24, "buffer id (7=depth, 3=back)"); + FLAG(stream, ptr[j], 23, "use fence regs"); + FLAG(stream, ptr[j], 22, "tiled surface"); + FLAG(stream, ptr[j], 21, "tile walk ymajor"); + MBZ (ptr[j], 20, 14); + BITS(stream, ptr[j], 13, 2, "dword pitch"); + MBZ (ptr[j], 2, 0); + j++; + } + + PRINTF(stream, "\t0x%08x -- buffer base address\n", ptr[j++]); + + stream->offset += len * sizeof(unsigned); + assert(j == len); + return TRUE; +} + +static boolean i915_debug_packet( struct debug_stream *stream ) +{ + unsigned *ptr = (unsigned *)(stream->ptr + stream->offset); + unsigned cmd = *ptr; + + switch (((cmd >> 29) & 0x7)) { + case 0x0: + switch ((cmd >> 23) & 0x3f) { + case 0x0: + return debug(stream, "MI_NOOP", 1); + case 0x3: + return debug(stream, "MI_WAIT_FOR_EVENT", 1); + case 0x4: + return debug(stream, "MI_FLUSH", 1); + case 0xA: + debug(stream, "MI_BATCH_BUFFER_END", 1); + return FALSE; + case 0x22: + return debug(stream, "MI_LOAD_REGISTER_IMM", 3); + case 0x31: + return debug_chain(stream, "MI_BATCH_BUFFER_START", 2); + default: + (void)debug(stream, "UNKNOWN 0x0 case!", 1); + assert(0); + break; + } + break; + case 0x1: + (void) debug(stream, "UNKNOWN 0x1 case!", 1); + assert(0); + break; + case 0x2: + switch ((cmd >> 22) & 0xff) { + case 0x50: + return debug_color_blit(stream, "XY_COLOR_BLT", (cmd & 0xff) + 2); + case 0x53: + return debug_copy_blit(stream, "XY_SRC_COPY_BLT", (cmd & 0xff) + 2); + default: + return debug(stream, "blit command", (cmd & 0xff) + 2); + } + break; + case 0x3: + switch ((cmd >> 24) & 0x1f) { + case 0x6: + return debug(stream, "3DSTATE_ANTI_ALIASING", 1); + case 0x7: + return debug(stream, "3DSTATE_RASTERIZATION_RULES", 1); + case 0x8: + return debug(stream, "3DSTATE_BACKFACE_STENCIL_OPS", 2); + case 0x9: + return debug(stream, "3DSTATE_BACKFACE_STENCIL_MASKS", 1); + case 0xb: + return debug(stream, "3DSTATE_INDEPENDENT_ALPHA_BLEND", 1); + case 0xc: + return debug(stream, "3DSTATE_MODES5", 1); + case 0xd: + return debug_modes4(stream, "3DSTATE_MODES4", 1); + case 0x15: + return debug(stream, "3DSTATE_FOG_COLOR", 1); + case 0x16: + return debug(stream, "3DSTATE_COORD_SET_BINDINGS", 1); + case 0x1c: + /* 3DState16NP */ + switch((cmd >> 19) & 0x1f) { + case 0x10: + return debug(stream, "3DSTATE_SCISSOR_ENABLE", 1); + case 0x11: + return debug(stream, "3DSTATE_DEPTH_SUBRECTANGLE_DISABLE", 1); + default: + (void) debug(stream, "UNKNOWN 0x1c case!", 1); + assert(0); + break; + } + break; + case 0x1d: + /* 3DStateMW */ + switch ((cmd >> 16) & 0xff) { + case 0x0: + return debug_map_state(stream, "3DSTATE_MAP_STATE", (cmd & 0x1f) + 2); + case 0x1: + return debug_sampler_state(stream, "3DSTATE_SAMPLER_STATE", (cmd & 0x1f) + 2); + case 0x4: + return debug_load_immediate(stream, "3DSTATE_LOAD_STATE_IMMEDIATE", (cmd & 0xf) + 2); + case 0x5: + return debug_program(stream, "3DSTATE_PIXEL_SHADER_PROGRAM", (cmd & 0x1ff) + 2); + case 0x6: + return debug(stream, "3DSTATE_PIXEL_SHADER_CONSTANTS", (cmd & 0xff) + 2); + case 0x7: + return debug_load_indirect(stream, "3DSTATE_LOAD_INDIRECT", (cmd & 0xff) + 2); + case 0x80: + return debug(stream, "3DSTATE_DRAWING_RECTANGLE", (cmd & 0xffff) + 2); + case 0x81: + return debug(stream, "3DSTATE_SCISSOR_RECTANGLE", (cmd & 0xffff) + 2); + case 0x83: + return debug(stream, "3DSTATE_SPAN_STIPPLE", (cmd & 0xffff) + 2); + case 0x85: + return debug_dest_vars(stream, "3DSTATE_DEST_BUFFER_VARS", (cmd & 0xffff) + 2); + case 0x88: + return debug(stream, "3DSTATE_CONSTANT_BLEND_COLOR", (cmd & 0xffff) + 2); + case 0x89: + return debug(stream, "3DSTATE_FOG_MODE", (cmd & 0xffff) + 2); + case 0x8e: + return debug_buf_info(stream, "3DSTATE_BUFFER_INFO", (cmd & 0xffff) + 2); + case 0x97: + return debug(stream, "3DSTATE_DEPTH_OFFSET_SCALE", (cmd & 0xffff) + 2); + case 0x98: + return debug(stream, "3DSTATE_DEFAULT_Z", (cmd & 0xffff) + 2); + case 0x99: + return debug(stream, "3DSTATE_DEFAULT_DIFFUSE", (cmd & 0xffff) + 2); + case 0x9a: + return debug(stream, "3DSTATE_DEFAULT_SPECULAR", (cmd & 0xffff) + 2); + case 0x9c: + return debug(stream, "3DSTATE_CLEAR_PARAMETERS", (cmd & 0xffff) + 2); + default: + assert(0); + return 0; + } + break; + case 0x1e: + if (cmd & (1 << 23)) + return debug(stream, "???", (cmd & 0xffff) + 1); + else + return debug(stream, "", 1); + break; + case 0x1f: + if ((cmd & (1 << 23)) == 0) + return debug_prim(stream, "3DPRIM (inline)", 1, (cmd & 0x1ffff) + 2); + else if (cmd & (1 << 17)) + { + if ((cmd & 0xffff) == 0) + return debug_variable_length_prim(stream); + else + return debug_prim(stream, "3DPRIM (indexed)", 0, (((cmd & 0xffff) + 1) / 2) + 1); + } + else + return debug_prim(stream, "3DPRIM (indirect sequential)", 0, 2); + break; + default: + return debug(stream, "", 0); + } + break; + default: + assert(0); + return 0; + } + + assert(0); + return 0; +} + + + +void +i915_dump_batchbuffer( struct i915_winsys_batchbuffer *batch ) +{ + struct debug_stream stream; + unsigned *start = (unsigned*)batch->map; + unsigned *end = (unsigned*)batch->ptr; + unsigned long bytes = (unsigned long) (end - start) * 4; + boolean done = FALSE; + + stream.offset = 0; + stream.ptr = (char *)start; + stream.print_addresses = 0; + + if (!start || !end) { + debug_printf( "\n\nBATCH: ???\n"); + return; + } + + debug_printf( "\n\nBATCH: (%d)\n", (int)bytes / 4); + + while (!done && + stream.offset < bytes) + { + if (!i915_debug_packet( &stream )) + break; + + assert(stream.offset <= bytes && + stream.offset >= 0); + } + + debug_printf( "END-BATCH\n\n\n"); +} + + + +/*********************************************************************** + * Dirty state atom dumping + */ + +void +i915_dump_dirty(struct i915_context *i915, const char *func) +{ + struct { + unsigned dirty; + const char *name; + } l[] = { + {I915_NEW_VIEWPORT, "viewport"}, + {I915_NEW_RASTERIZER, "rasterizer"}, + {I915_NEW_FS, "fs"}, + {I915_NEW_BLEND, "blend"}, + {I915_NEW_CLIP, "clip"}, + {I915_NEW_SCISSOR, "scissor"}, + {I915_NEW_STIPPLE, "stipple"}, + {I915_NEW_FRAMEBUFFER, "framebuffer"}, + {I915_NEW_ALPHA_TEST, "alpha_test"}, + {I915_NEW_DEPTH_STENCIL, "depth_stencil"}, + {I915_NEW_SAMPLER, "sampler"}, + {I915_NEW_SAMPLER_VIEW, "sampler_view"}, + {I915_NEW_CONSTANTS, "constants"}, + {I915_NEW_VBO, "vbo"}, + {I915_NEW_VS, "vs"}, + {0, NULL}, + }; + int i; + + debug_printf("%s: ", func); + for (i = 0; l[i].name; i++) + if (i915->dirty & l[i].dirty) + debug_printf("%s ", l[i].name); + debug_printf("\n"); +} + +void +i915_dump_hardware_dirty(struct i915_context *i915, const char *func) +{ + struct { + unsigned dirty; + const char *name; + } l[] = { + {I915_HW_STATIC, "static"}, + {I915_HW_DYNAMIC, "dynamic"}, + {I915_HW_SAMPLER, "sampler"}, + {I915_HW_MAP, "map"}, + {I915_HW_PROGRAM, "program"}, + {I915_HW_CONSTANTS, "constants"}, + {I915_HW_IMMEDIATE, "immediate"}, + {I915_HW_INVARIENT, "invarient"}, + {0, NULL}, + }; + int i; + + debug_printf("%s: ", func); + for (i = 0; l[i].name; i++) + if (i915->hardware_dirty & l[i].dirty) + debug_printf("%s ", l[i].name); + debug_printf("\n"); +} diff --git a/src/gallium/drivers/i915/i915_debug.h b/src/gallium/drivers/i915/i915_debug.h new file mode 100644 index 0000000..11af766 --- /dev/null +++ b/src/gallium/drivers/i915/i915_debug.h @@ -0,0 +1,82 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + * Jakob Bornecrantz + */ + +#ifndef I915_DEBUG_H +#define I915_DEBUG_H + +#include "util/u_debug.h" + +struct i915_screen; +struct i915_context; +struct i915_winsys_batchbuffer; + +#define DBG_BLIT 0x1 +#define DBG_EMIT 0x2 +#define DBG_ATOMS 0x4 +#define DBG_FLUSH 0x8 +#define DBG_TEXTURE 0x10 +#define DBG_CONSTANTS 0x20 + +extern unsigned i915_debug; +extern boolean i915_tiling; + +#ifdef DEBUG +static INLINE boolean +I915_DBG_ON(unsigned flags) +{ + return i915_debug & flags; +} + +static INLINE void +I915_DBG(unsigned flags, const char *fmt, ...) +{ + if (I915_DBG_ON(flags)) { + va_list args; + + va_start(args, fmt); + debug_vprintf(fmt, args); + va_end(args); + } +} +#else +#define I915_DBG_ON(flags) (0) +static INLINE void I915_DBG(unsigned flags, const char *fmt, ...) {} +#endif + +void i915_debug_init(struct i915_screen *i915); + +void i915_dump_batchbuffer(struct i915_winsys_batchbuffer *i915); + +void i915_dump_dirty(struct i915_context *i915, const char *func); + +void i915_dump_hardware_dirty(struct i915_context *i915, const char *func); + +#endif diff --git a/src/gallium/drivers/i915/i915_debug_fp.c b/src/gallium/drivers/i915/i915_debug_fp.c new file mode 100644 index 0000000..50f49c5 --- /dev/null +++ b/src/gallium/drivers/i915/i915_debug_fp.c @@ -0,0 +1,363 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + + +#include "i915_reg.h" +#include "i915_debug.h" +#include "i915_debug_private.h" +#include "util/u_debug.h" + + +static void +PRINTF( + struct debug_stream *stream, + const char *fmt, + ... ) +{ + va_list args; + + va_start( args, fmt ); + debug_vprintf( fmt, args ); + va_end( args ); +} + + +static const char *opcodes[0x20] = { + "NOP", + "ADD", + "MOV", + "MUL", + "MAD", + "DP2ADD", + "DP3", + "DP4", + "FRC", + "RCP", + "RSQ", + "EXP", + "LOG", + "CMP", + "MIN", + "MAX", + "FLR", + "MOD", + "TRC", + "SGE", + "SLT", + "TEXLD", + "TEXLDP", + "TEXLDB", + "TEXKILL", + "DCL", + "0x1a", + "0x1b", + "0x1c", + "0x1d", + "0x1e", + "0x1f", +}; + + +static const int args[0x20] = { + 0, /* 0 nop */ + 2, /* 1 add */ + 1, /* 2 mov */ + 2, /* 3 m ul */ + 3, /* 4 mad */ + 3, /* 5 dp2add */ + 2, /* 6 dp3 */ + 2, /* 7 dp4 */ + 1, /* 8 frc */ + 1, /* 9 rcp */ + 1, /* a rsq */ + 1, /* b exp */ + 1, /* c log */ + 3, /* d cmp */ + 2, /* e min */ + 2, /* f max */ + 1, /* 10 flr */ + 1, /* 11 mod */ + 1, /* 12 trc */ + 2, /* 13 sge */ + 2, /* 14 slt */ + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +}; + + +static const char *regname[0x8] = { + "R", + "T", + "CONST", + "S", + "OC", + "OD", + "U", + "UNKNOWN", +}; + +static void +print_reg_type_nr(struct debug_stream *stream, unsigned type, unsigned nr) +{ + switch (type) { + case REG_TYPE_T: + switch (nr) { + case T_DIFFUSE: + PRINTF(stream, "T_DIFFUSE"); + return; + case T_SPECULAR: + PRINTF(stream, "T_SPECULAR"); + return; + case T_FOG_W: + PRINTF(stream, "T_FOG_W"); + return; + default: + PRINTF(stream, "T_TEX%d", nr); + return; + } + case REG_TYPE_OC: + if (nr == 0) { + PRINTF(stream, "oC"); + return; + } + break; + case REG_TYPE_OD: + if (nr == 0) { + PRINTF(stream, "oD"); + return; + } + break; + default: + break; + } + + PRINTF(stream, "%s[%d]", regname[type], nr); +} + +#define REG_SWIZZLE_MASK 0x7777 +#define REG_NEGATE_MASK 0x8888 + +#define REG_SWIZZLE_XYZW ((SRC_X << A2_SRC2_CHANNEL_X_SHIFT) | \ + (SRC_Y << A2_SRC2_CHANNEL_Y_SHIFT) | \ + (SRC_Z << A2_SRC2_CHANNEL_Z_SHIFT) | \ + (SRC_W << A2_SRC2_CHANNEL_W_SHIFT)) + + +static void +print_reg_neg_swizzle(struct debug_stream *stream, unsigned reg) +{ + int i; + + if ((reg & REG_SWIZZLE_MASK) == REG_SWIZZLE_XYZW && + (reg & REG_NEGATE_MASK) == 0) + return; + + PRINTF(stream, "."); + + for (i = 3; i >= 0; i--) { + if (reg & (1 << ((i * 4) + 3))) + PRINTF(stream, "-"); + + switch ((reg >> (i * 4)) & 0x7) { + case 0: + PRINTF(stream, "x"); + break; + case 1: + PRINTF(stream, "y"); + break; + case 2: + PRINTF(stream, "z"); + break; + case 3: + PRINTF(stream, "w"); + break; + case 4: + PRINTF(stream, "0"); + break; + case 5: + PRINTF(stream, "1"); + break; + default: + PRINTF(stream, "?"); + break; + } + } +} + + +static void +print_src_reg(struct debug_stream *stream, unsigned dword) +{ + unsigned nr = (dword >> A2_SRC2_NR_SHIFT) & REG_NR_MASK; + unsigned type = (dword >> A2_SRC2_TYPE_SHIFT) & REG_TYPE_MASK; + print_reg_type_nr(stream, type, nr); + print_reg_neg_swizzle(stream, dword); +} + + +static void +print_dest_reg(struct debug_stream *stream, unsigned dword) +{ + unsigned nr = (dword >> A0_DEST_NR_SHIFT) & REG_NR_MASK; + unsigned type = (dword >> A0_DEST_TYPE_SHIFT) & REG_TYPE_MASK; + print_reg_type_nr(stream, type, nr); + if ((dword & A0_DEST_CHANNEL_ALL) == A0_DEST_CHANNEL_ALL) + return; + PRINTF(stream, "."); + if (dword & A0_DEST_CHANNEL_X) + PRINTF(stream, "x"); + if (dword & A0_DEST_CHANNEL_Y) + PRINTF(stream, "y"); + if (dword & A0_DEST_CHANNEL_Z) + PRINTF(stream, "z"); + if (dword & A0_DEST_CHANNEL_W) + PRINTF(stream, "w"); +} + + +#define GET_SRC0_REG(r0, r1) ((r0<<14)|(r1>>A1_SRC0_CHANNEL_W_SHIFT)) +#define GET_SRC1_REG(r0, r1) ((r0<<8)|(r1>>A2_SRC1_CHANNEL_W_SHIFT)) +#define GET_SRC2_REG(r) (r) + + +static void +print_arith_op(struct debug_stream *stream, + unsigned opcode, const unsigned * program) +{ + if (opcode != A0_NOP) { + print_dest_reg(stream, program[0]); + if (program[0] & A0_DEST_SATURATE) + PRINTF(stream, " = SATURATE "); + else + PRINTF(stream, " = "); + } + + PRINTF(stream, "%s ", opcodes[opcode]); + + print_src_reg(stream, GET_SRC0_REG(program[0], program[1])); + if (args[opcode] == 1) { + PRINTF(stream, "\n"); + return; + } + + PRINTF(stream, ", "); + print_src_reg(stream, GET_SRC1_REG(program[1], program[2])); + if (args[opcode] == 2) { + PRINTF(stream, "\n"); + return; + } + + PRINTF(stream, ", "); + print_src_reg(stream, GET_SRC2_REG(program[2])); + PRINTF(stream, "\n"); + return; +} + + +static void +print_tex_op(struct debug_stream *stream, + unsigned opcode, const unsigned * program) +{ + print_dest_reg(stream, program[0] | A0_DEST_CHANNEL_ALL); + PRINTF(stream, " = "); + + PRINTF(stream, "%s ", opcodes[opcode]); + + PRINTF(stream, "S[%d],", program[0] & T0_SAMPLER_NR_MASK); + + print_reg_type_nr(stream, + (program[1] >> T1_ADDRESS_REG_TYPE_SHIFT) & + REG_TYPE_MASK, + (program[1] >> T1_ADDRESS_REG_NR_SHIFT) & REG_NR_MASK); + PRINTF(stream, "\n"); +} + +static void +print_texkil_op(struct debug_stream *stream, + unsigned opcode, const unsigned * program) +{ + PRINTF(stream, "TEXKIL "); + + print_reg_type_nr(stream, + (program[1] >> T1_ADDRESS_REG_TYPE_SHIFT) & + REG_TYPE_MASK, + (program[1] >> T1_ADDRESS_REG_NR_SHIFT) & REG_NR_MASK); + PRINTF(stream, "\n"); +} + +static void +print_dcl_op(struct debug_stream *stream, + unsigned opcode, const unsigned * program) +{ + PRINTF(stream, "%s ", opcodes[opcode]); + print_dest_reg(stream, + program[0] | A0_DEST_CHANNEL_ALL); + PRINTF(stream, "\n"); +} + + +void +i915_disassemble_program(struct debug_stream *stream, + const unsigned * program, unsigned sz) +{ + unsigned i; + + PRINTF(stream, "\t\tBEGIN\n"); + + assert((program[0] & 0x1ff) + 2 == sz); + + program++; + for (i = 1; i < sz; i += 3, program += 3) { + unsigned opcode = program[0] & (0x1f << 24); + + PRINTF(stream, "\t\t"); + + if ((int) opcode >= A0_NOP && opcode <= A0_SLT) + print_arith_op(stream, opcode >> 24, program); + else if (opcode >= T0_TEXLD && opcode < T0_TEXKILL) + print_tex_op(stream, opcode >> 24, program); + else if (opcode == T0_TEXKILL) + print_texkil_op(stream, opcode >> 24, program); + else if (opcode == D0_DCL) + print_dcl_op(stream, opcode >> 24, program); + else + PRINTF(stream, "Unknown opcode 0x%x\n", opcode); + } + + PRINTF(stream, "\t\tEND\n\n"); +} + + diff --git a/src/gallium/drivers/i915/i915_debug_private.h b/src/gallium/drivers/i915/i915_debug_private.h new file mode 100644 index 0000000..b3668d0 --- /dev/null +++ b/src/gallium/drivers/i915/i915_debug_private.h @@ -0,0 +1,45 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef I915_DEBUG_PRIVATE_H +#define I915_DEBUG_PRIVATE_H + +struct debug_stream +{ + unsigned offset; /* current gtt offset */ + char *ptr; /* pointer to gtt offset zero */ + char *end; /* pointer to gtt offset zero */ + unsigned print_addresses; +}; + +void i915_disassemble_program(struct debug_stream *stream, + const unsigned *program, unsigned sz); + +#endif diff --git a/src/gallium/drivers/i915/i915_flush.c b/src/gallium/drivers/i915/i915_flush.c new file mode 100644 index 0000000..a2c70b1 --- /dev/null +++ b/src/gallium/drivers/i915/i915_flush.c @@ -0,0 +1,97 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Author: + * Keith Whitwell + */ + + +#include "pipe/p_defines.h" +#include "draw/draw_context.h" +#include "i915_context.h" +#include "i915_reg.h" +#include "i915_batch.h" +#include "i915_debug.h" + + +static void i915_flush_pipe( struct pipe_context *pipe, + unsigned flags, + struct pipe_fence_handle **fence ) +{ + struct i915_context *i915 = i915_context(pipe); + + draw_flush(i915->draw); + +#if 0 + /* Do we need to emit an MI_FLUSH command to flush the hardware + * caches? + */ + if (flags & (PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_TEXTURE_CACHE)) { + unsigned flush = MI_FLUSH; + + if (!(flags & PIPE_FLUSH_RENDER_CACHE)) + flush |= INHIBIT_FLUSH_RENDER_CACHE; + + if (flags & PIPE_FLUSH_TEXTURE_CACHE) + flush |= FLUSH_MAP_CACHE; + + if (!BEGIN_BATCH(1, 0)) { + FLUSH_BATCH(NULL); + assert(BEGIN_BATCH(1, 0)); + } + OUT_BATCH( flush ); + } +#endif + + if (i915->batch->map == i915->batch->ptr) { + return; + } + + /* If there are no flags, just flush pending commands to hardware: + */ + FLUSH_BATCH(fence); + i915->vbo_flushed = 1; + + I915_DBG(DBG_FLUSH, "%s: #####\n", __FUNCTION__); +} + +void i915_init_flush_functions( struct i915_context *i915 ) +{ + i915->base.flush = i915_flush_pipe; +} + +/** + * Here we handle all the notifications that needs to go out on a flush. + * XXX might move above function to i915_pipe_flush.c and leave this here. + */ +void i915_flush(struct i915_context *i915, struct pipe_fence_handle **fence) +{ + struct i915_winsys_batchbuffer *batch = i915->batch; + + batch->iws->batchbuffer_flush(batch, fence); + i915->hardware_dirty = ~0; +} diff --git a/src/gallium/drivers/i915/i915_fpc.h b/src/gallium/drivers/i915/i915_fpc.h new file mode 100644 index 0000000..2f0f99d --- /dev/null +++ b/src/gallium/drivers/i915/i915_fpc.h @@ -0,0 +1,207 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + + +#ifndef I915_FPC_H +#define I915_FPC_H + + +#include "i915_context.h" +#include "i915_reg.h" + + + +#define I915_PROGRAM_SIZE 192 + + + +/** + * Program translation state + */ +struct i915_fp_compile { + struct i915_fragment_shader *shader; /* the shader we're compiling */ + + boolean used_constants[I915_MAX_CONSTANT]; + + /** maps TGSI immediate index to constant slot */ + uint num_immediates; + uint immediates_map[I915_MAX_CONSTANT]; + float immediates[I915_MAX_CONSTANT][4]; + + boolean first_instruction; + + uint declarations[I915_PROGRAM_SIZE]; + uint program[I915_PROGRAM_SIZE]; + + uint *csr; /**< Cursor, points into program. */ + + uint *decl; /**< Cursor, points into declarations. */ + + uint decl_s; /**< flags for which s regs need to be decl'd */ + uint decl_t; /**< flags for which t regs need to be decl'd */ + + uint temp_flag; /**< Tracks temporary regs which are in use */ + uint utemp_flag; /**< Tracks TYPE_U temporary regs which are in use */ + + uint nr_tex_indirect; + uint nr_tex_insn; + uint nr_alu_insn; + uint nr_decl_insn; + + boolean error; /**< Set if i915_program_error() is called */ + uint wpos_tex; + uint NumNativeInstructions; + uint NumNativeAluInstructions; + uint NumNativeTexInstructions; + uint NumNativeTexIndirections; +}; + + +/* Having zero and one in here makes the definition of swizzle a lot + * easier. + */ +#define UREG_TYPE_SHIFT 29 +#define UREG_NR_SHIFT 24 +#define UREG_CHANNEL_X_NEGATE_SHIFT 23 +#define UREG_CHANNEL_X_SHIFT 20 +#define UREG_CHANNEL_Y_NEGATE_SHIFT 19 +#define UREG_CHANNEL_Y_SHIFT 16 +#define UREG_CHANNEL_Z_NEGATE_SHIFT 15 +#define UREG_CHANNEL_Z_SHIFT 12 +#define UREG_CHANNEL_W_NEGATE_SHIFT 11 +#define UREG_CHANNEL_W_SHIFT 8 +#define UREG_CHANNEL_ZERO_NEGATE_MBZ 5 +#define UREG_CHANNEL_ZERO_SHIFT 4 +#define UREG_CHANNEL_ONE_NEGATE_MBZ 1 +#define UREG_CHANNEL_ONE_SHIFT 0 + +#define UREG_BAD 0xffffffff /* not a valid ureg */ + +#define X SRC_X +#define Y SRC_Y +#define Z SRC_Z +#define W SRC_W +#define ZERO SRC_ZERO +#define ONE SRC_ONE + +/* Construct a ureg: + */ +#define UREG( type, nr ) (((type)<< UREG_TYPE_SHIFT) | \ + ((nr) << UREG_NR_SHIFT) | \ + (X << UREG_CHANNEL_X_SHIFT) | \ + (Y << UREG_CHANNEL_Y_SHIFT) | \ + (Z << UREG_CHANNEL_Z_SHIFT) | \ + (W << UREG_CHANNEL_W_SHIFT) | \ + (ZERO << UREG_CHANNEL_ZERO_SHIFT) | \ + (ONE << UREG_CHANNEL_ONE_SHIFT)) + +#define GET_CHANNEL_SRC( reg, channel ) ((reg<<(channel*4)) & (0xf<<20)) +#define CHANNEL_SRC( src, channel ) (src>>(channel*4)) + +#define GET_UREG_TYPE(reg) (((reg)>>UREG_TYPE_SHIFT)®_TYPE_MASK) +#define GET_UREG_NR(reg) (((reg)>>UREG_NR_SHIFT)®_NR_MASK) + + + +#define UREG_XYZW_CHANNEL_MASK 0x00ffff00 + +/* One neat thing about the UREG representation: + */ +static INLINE int +swizzle(int reg, uint x, uint y, uint z, uint w) +{ + assert(x <= SRC_ONE); + assert(y <= SRC_ONE); + assert(z <= SRC_ONE); + assert(w <= SRC_ONE); + return ((reg & ~UREG_XYZW_CHANNEL_MASK) | + CHANNEL_SRC(GET_CHANNEL_SRC(reg, x), 0) | + CHANNEL_SRC(GET_CHANNEL_SRC(reg, y), 1) | + CHANNEL_SRC(GET_CHANNEL_SRC(reg, z), 2) | + CHANNEL_SRC(GET_CHANNEL_SRC(reg, w), 3)); +} + + + +/*********************************************************************** + * Public interface for the compiler + */ +extern void +i915_translate_fragment_program( struct i915_context *i915, + struct i915_fragment_shader *fs); + + + +extern uint i915_get_temp(struct i915_fp_compile *p); +extern uint i915_get_utemp(struct i915_fp_compile *p); +extern void i915_release_utemps(struct i915_fp_compile *p); + + +extern uint i915_emit_texld(struct i915_fp_compile *p, + uint dest, + uint destmask, + uint sampler, uint coord, uint op); + +extern uint i915_emit_arith(struct i915_fp_compile *p, + uint op, + uint dest, + uint mask, + uint saturate, + uint src0, uint src1, uint src2); + +extern uint i915_emit_decl(struct i915_fp_compile *p, + uint type, uint nr, uint d0_flags); + + +extern uint i915_emit_const1f(struct i915_fp_compile *p, float c0); + +extern uint i915_emit_const2f(struct i915_fp_compile *p, + float c0, float c1); + +extern uint i915_emit_const4fv(struct i915_fp_compile *p, + const float * c); + +extern uint i915_emit_const4f(struct i915_fp_compile *p, + float c0, float c1, + float c2, float c3); + + +/*====================================================================== + * i915_fpc_debug.c + */ +extern void i915_disassemble_program(const uint * program, uint sz); + + +/*====================================================================== + * i915_fpc_translate.c + */ + +extern void +i915_program_error(struct i915_fp_compile *p, const char *msg, ...); + + +#endif diff --git a/src/gallium/drivers/i915/i915_fpc_emit.c b/src/gallium/drivers/i915/i915_fpc_emit.c new file mode 100644 index 0000000..76c24d2 --- /dev/null +++ b/src/gallium/drivers/i915/i915_fpc_emit.c @@ -0,0 +1,375 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + +#include "i915_reg.h" +#include "i915_context.h" +#include "i915_fpc.h" +#include "util/u_math.h" + + +#define A0_DEST( reg ) (((reg)&UREG_TYPE_NR_MASK)>>UREG_A0_DEST_SHIFT_LEFT) +#define D0_DEST( reg ) (((reg)&UREG_TYPE_NR_MASK)>>UREG_A0_DEST_SHIFT_LEFT) +#define T0_DEST( reg ) (((reg)&UREG_TYPE_NR_MASK)>>UREG_A0_DEST_SHIFT_LEFT) +#define A0_SRC0( reg ) (((reg)&UREG_MASK)>>UREG_A0_SRC0_SHIFT_LEFT) +#define A1_SRC0( reg ) (((reg)&UREG_MASK)<>UREG_A1_SRC1_SHIFT_LEFT) +#define A2_SRC1( reg ) (((reg)&UREG_MASK)<>UREG_A2_SRC2_SHIFT_LEFT) + +/* These are special, and don't have swizzle/negate bits. + */ +#define T0_SAMPLER( reg ) (GET_UREG_NR(reg)<temp_flag); + if (!bit) { + i915_program_error(p, "i915_get_temp: out of temporaries\n"); + return 0; + } + + p->temp_flag |= 1 << (bit - 1); + return bit - 1; +} + + +static void +i915_release_temp(struct i915_fp_compile *p, int reg) +{ + p->temp_flag &= ~(1 << reg); +} + + +/** + * Get unpreserved temporary, a temp whose value is not preserved between + * PS program phases. + */ +uint +i915_get_utemp(struct i915_fp_compile * p) +{ + int bit = ffs(~p->utemp_flag); + if (!bit) { + i915_program_error(p, "i915_get_utemp: out of temporaries\n"); + return 0; + } + + p->utemp_flag |= 1 << (bit - 1); + return UREG(REG_TYPE_U, (bit - 1)); +} + +void +i915_release_utemps(struct i915_fp_compile *p) +{ + p->utemp_flag = ~0x7; +} + + +uint +i915_emit_decl(struct i915_fp_compile *p, + uint type, uint nr, uint d0_flags) +{ + uint reg = UREG(type, nr); + + if (type == REG_TYPE_T) { + if (p->decl_t & (1 << nr)) + return reg; + + p->decl_t |= (1 << nr); + } + else if (type == REG_TYPE_S) { + if (p->decl_s & (1 << nr)) + return reg; + + p->decl_s |= (1 << nr); + } + else + return reg; + + *(p->decl++) = (D0_DCL | D0_DEST(reg) | d0_flags); + *(p->decl++) = D1_MBZ; + *(p->decl++) = D2_MBZ; + + p->nr_decl_insn++; + return reg; +} + +uint +i915_emit_arith(struct i915_fp_compile * p, + uint op, + uint dest, + uint mask, + uint saturate, uint src0, uint src1, uint src2) +{ + uint c[3]; + uint nr_const = 0; + + assert(GET_UREG_TYPE(dest) != REG_TYPE_CONST); + dest = UREG(GET_UREG_TYPE(dest), GET_UREG_NR(dest)); + assert(dest); + + if (GET_UREG_TYPE(src0) == REG_TYPE_CONST) + c[nr_const++] = 0; + if (GET_UREG_TYPE(src1) == REG_TYPE_CONST) + c[nr_const++] = 1; + if (GET_UREG_TYPE(src2) == REG_TYPE_CONST) + c[nr_const++] = 2; + + /* Recursively call this function to MOV additional const values + * into temporary registers. Use utemp registers for this - + * currently shouldn't be possible to run out, but keep an eye on + * this. + */ + if (nr_const > 1) { + uint s[3], first, i, old_utemp_flag; + + s[0] = src0; + s[1] = src1; + s[2] = src2; + old_utemp_flag = p->utemp_flag; + + first = GET_UREG_NR(s[c[0]]); + for (i = 1; i < nr_const; i++) { + if (GET_UREG_NR(s[c[i]]) != first) { + uint tmp = i915_get_utemp(p); + + i915_emit_arith(p, A0_MOV, tmp, A0_DEST_CHANNEL_ALL, 0, + s[c[i]], 0, 0); + s[c[i]] = tmp; + } + } + + src0 = s[0]; + src1 = s[1]; + src2 = s[2]; + p->utemp_flag = old_utemp_flag; /* restore */ + } + + *(p->csr++) = (op | A0_DEST(dest) | mask | saturate | A0_SRC0(src0)); + *(p->csr++) = (A1_SRC0(src0) | A1_SRC1(src1)); + *(p->csr++) = (A2_SRC1(src1) | A2_SRC2(src2)); + + p->nr_alu_insn++; + return dest; +} + + +/** + * Emit a texture load or texkill instruction. + * \param dest the dest i915 register + * \param destmask the dest register writemask + * \param sampler the i915 sampler register + * \param coord the i915 source texcoord operand + * \param opcode the instruction opcode + */ +uint i915_emit_texld( struct i915_fp_compile *p, + uint dest, + uint destmask, + uint sampler, + uint coord, + uint opcode ) +{ + const uint k = UREG(GET_UREG_TYPE(coord), GET_UREG_NR(coord)); + int temp = -1; + + if (coord != k) { + /* texcoord is swizzled or negated. Need to allocate a new temporary + * register (a utemp / unpreserved temp) won't do. + */ + uint tempReg; + + temp = i915_get_temp(p); /* get temp reg index */ + tempReg = UREG(REG_TYPE_R, temp); /* make i915 register */ + + i915_emit_arith( p, A0_MOV, + tempReg, A0_DEST_CHANNEL_ALL, /* dest reg, writemask */ + 0, /* saturate */ + coord, 0, 0 ); /* src0, src1, src2 */ + + /* new src texcoord is tempReg */ + coord = tempReg; + } + + /* Don't worry about saturate as we only support + */ + if (destmask != A0_DEST_CHANNEL_ALL) { + /* if not writing to XYZW... */ + uint tmp = i915_get_utemp(p); + i915_emit_texld( p, tmp, A0_DEST_CHANNEL_ALL, sampler, coord, opcode ); + i915_emit_arith( p, A0_MOV, dest, destmask, 0, tmp, 0, 0 ); + /* XXX release utemp here? */ + } + else { + assert(GET_UREG_TYPE(dest) != REG_TYPE_CONST); + assert(dest == UREG(GET_UREG_TYPE(dest), GET_UREG_NR(dest))); + + /* is the sampler coord a texcoord input reg? */ + if (GET_UREG_TYPE(coord) != REG_TYPE_T) { + p->nr_tex_indirect++; + } + + *(p->csr++) = (opcode | + T0_DEST( dest ) | + T0_SAMPLER( sampler )); + + *(p->csr++) = T1_ADDRESS_REG( coord ); + *(p->csr++) = T2_MBZ; + + p->nr_tex_insn++; + } + + if (temp >= 0) + i915_release_temp(p, temp); + + return dest; +} + + +uint +i915_emit_const1f(struct i915_fp_compile * p, float c0) +{ + struct i915_fragment_shader *ifs = p->shader; + unsigned reg, idx; + + if (c0 == 0.0) + return swizzle(UREG(REG_TYPE_R, 0), ZERO, ZERO, ZERO, ZERO); + if (c0 == 1.0) + return swizzle(UREG(REG_TYPE_R, 0), ONE, ONE, ONE, ONE); + + for (reg = 0; reg < I915_MAX_CONSTANT; reg++) { + if (ifs->constant_flags[reg] == I915_CONSTFLAG_USER) + continue; + for (idx = 0; idx < 4; idx++) { + if (!(ifs->constant_flags[reg] & (1 << idx)) || + ifs->constants[reg][idx] == c0) { + ifs->constants[reg][idx] = c0; + ifs->constant_flags[reg] |= 1 << idx; + if (reg + 1 > ifs->num_constants) + ifs->num_constants = reg + 1; + return swizzle(UREG(REG_TYPE_CONST, reg), idx, ZERO, ZERO, ONE); + } + } + } + + i915_program_error(p, "i915_emit_const1f: out of constants\n"); + return 0; +} + +uint +i915_emit_const2f(struct i915_fp_compile * p, float c0, float c1) +{ + struct i915_fragment_shader *ifs = p->shader; + unsigned reg, idx; + + if (c0 == 0.0) + return swizzle(i915_emit_const1f(p, c1), ZERO, X, Z, W); + if (c0 == 1.0) + return swizzle(i915_emit_const1f(p, c1), ONE, X, Z, W); + + if (c1 == 0.0) + return swizzle(i915_emit_const1f(p, c0), X, ZERO, Z, W); + if (c1 == 1.0) + return swizzle(i915_emit_const1f(p, c0), X, ONE, Z, W); + + for (reg = 0; reg < I915_MAX_CONSTANT; reg++) { + if (ifs->constant_flags[reg] == 0xf || + ifs->constant_flags[reg] == I915_CONSTFLAG_USER) + continue; + for (idx = 0; idx < 3; idx++) { + if (!(ifs->constant_flags[reg] & (3 << idx))) { + ifs->constants[reg][idx + 0] = c0; + ifs->constants[reg][idx + 1] = c1; + ifs->constant_flags[reg] |= 3 << idx; + if (reg + 1 > ifs->num_constants) + ifs->num_constants = reg + 1; + return swizzle(UREG(REG_TYPE_CONST, reg), idx, idx + 1, ZERO, ONE); + } + } + } + + i915_program_error(p, "i915_emit_const2f: out of constants\n"); + return 0; +} + + + +uint +i915_emit_const4f(struct i915_fp_compile * p, + float c0, float c1, float c2, float c3) +{ + struct i915_fragment_shader *ifs = p->shader; + unsigned reg; + + for (reg = 0; reg < I915_MAX_CONSTANT; reg++) { + if (ifs->constant_flags[reg] == 0xf && + ifs->constants[reg][0] == c0 && + ifs->constants[reg][1] == c1 && + ifs->constants[reg][2] == c2 && + ifs->constants[reg][3] == c3) { + return UREG(REG_TYPE_CONST, reg); + } + else if (ifs->constant_flags[reg] == 0) { + + ifs->constants[reg][0] = c0; + ifs->constants[reg][1] = c1; + ifs->constants[reg][2] = c2; + ifs->constants[reg][3] = c3; + ifs->constant_flags[reg] = 0xf; + if (reg + 1 > ifs->num_constants) + ifs->num_constants = reg + 1; + return UREG(REG_TYPE_CONST, reg); + } + } + + i915_program_error(p, "i915_emit_const4f: out of constants\n"); + return 0; +} + + +uint +i915_emit_const4fv(struct i915_fp_compile * p, const float * c) +{ + return i915_emit_const4f(p, c[0], c[1], c[2], c[3]); +} diff --git a/src/gallium/drivers/i915/i915_fpc_translate.c b/src/gallium/drivers/i915/i915_fpc_translate.c new file mode 100644 index 0000000..25c5321 --- /dev/null +++ b/src/gallium/drivers/i915/i915_fpc_translate.c @@ -0,0 +1,1182 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include + +#include "i915_reg.h" +#include "i915_context.h" +#include "i915_fpc.h" + +#include "pipe/p_shader_tokens.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_string.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_dump.h" + +#include "draw/draw_vertex.h" + + +/** + * Simple pass-through fragment shader to use when we don't have + * a real shader (or it fails to compile for some reason). + */ +static unsigned passthrough[] = +{ + _3DSTATE_PIXEL_SHADER_PROGRAM | ((2*3)-1), + + /* declare input color: + */ + (D0_DCL | + (REG_TYPE_T << D0_TYPE_SHIFT) | + (T_DIFFUSE << D0_NR_SHIFT) | + D0_CHANNEL_ALL), + 0, + 0, + + /* move to output color: + */ + (A0_MOV | + (REG_TYPE_OC << A0_DEST_TYPE_SHIFT) | + A0_DEST_CHANNEL_ALL | + (REG_TYPE_T << A0_SRC0_TYPE_SHIFT) | + (T_DIFFUSE << A0_SRC0_NR_SHIFT)), + 0x01230000, /* .xyzw */ + 0 +}; + + +/* 1, -1/3!, 1/5!, -1/7! */ +static const float sin_constants[4] = { 1.0, + -1.0f / (3 * 2 * 1), + 1.0f / (5 * 4 * 3 * 2 * 1), + -1.0f / (7 * 6 * 5 * 4 * 3 * 2 * 1) +}; + +/* 1, -1/2!, 1/4!, -1/6! */ +static const float cos_constants[4] = { 1.0, + -1.0f / (2 * 1), + 1.0f / (4 * 3 * 2 * 1), + -1.0f / (6 * 5 * 4 * 3 * 2 * 1) +}; + + + +/** + * component-wise negation of ureg + */ +static INLINE int +negate(int reg, int x, int y, int z, int w) +{ + /* Another neat thing about the UREG representation */ + return reg ^ (((x & 1) << UREG_CHANNEL_X_NEGATE_SHIFT) | + ((y & 1) << UREG_CHANNEL_Y_NEGATE_SHIFT) | + ((z & 1) << UREG_CHANNEL_Z_NEGATE_SHIFT) | + ((w & 1) << UREG_CHANNEL_W_NEGATE_SHIFT)); +} + + +/** + * In the event of a translation failure, we'll generate a simple color + * pass-through program. + */ +static void +i915_use_passthrough_shader(struct i915_fragment_shader *fs) +{ + fs->program = (uint *) MALLOC(sizeof(passthrough)); + if (fs->program) { + memcpy(fs->program, passthrough, sizeof(passthrough)); + fs->program_len = Elements(passthrough); + } + fs->num_constants = 0; +} + + +void +i915_program_error(struct i915_fp_compile *p, const char *msg, ...) +{ + va_list args; + char buffer[1024]; + + debug_printf("i915_program_error: "); + va_start( args, msg ); + util_vsnprintf( buffer, sizeof(buffer), msg, args ); + va_end( args ); + debug_printf("%s", buffer); + debug_printf("\n"); + + p->error = 1; +} + + + +/** + * Construct a ureg for the given source register. Will emit + * constants, apply swizzling and negation as needed. + */ +static uint +src_vector(struct i915_fp_compile *p, + const struct tgsi_full_src_register *source) +{ + uint index = source->Register.Index; + uint src = 0, sem_name, sem_ind; + + switch (source->Register.File) { + case TGSI_FILE_TEMPORARY: + if (source->Register.Index >= I915_MAX_TEMPORARY) { + i915_program_error(p, "Exceeded max temporary reg"); + return 0; + } + src = UREG(REG_TYPE_R, index); + break; + case TGSI_FILE_INPUT: + /* XXX: Packing COL1, FOGC into a single attribute works for + * texenv programs, but will fail for real fragment programs + * that use these attributes and expect them to be a full 4 + * components wide. Could use a texcoord to pass these + * attributes if necessary, but that won't work in the general + * case. + * + * We also use a texture coordinate to pass wpos when possible. + */ + + sem_name = p->shader->info.input_semantic_name[index]; + sem_ind = p->shader->info.input_semantic_index[index]; + + switch (sem_name) { + case TGSI_SEMANTIC_POSITION: + debug_printf("SKIP SEM POS\n"); + /* + assert(p->wpos_tex != -1); + src = i915_emit_decl(p, REG_TYPE_T, p->wpos_tex, D0_CHANNEL_ALL); + */ + break; + case TGSI_SEMANTIC_COLOR: + if (sem_ind == 0) { + src = i915_emit_decl(p, REG_TYPE_T, T_DIFFUSE, D0_CHANNEL_ALL); + } + else { + /* secondary color */ + assert(sem_ind == 1); + src = i915_emit_decl(p, REG_TYPE_T, T_SPECULAR, D0_CHANNEL_XYZ); + src = swizzle(src, X, Y, Z, ONE); + } + break; + case TGSI_SEMANTIC_FOG: + src = i915_emit_decl(p, REG_TYPE_T, T_FOG_W, D0_CHANNEL_W); + src = swizzle(src, W, W, W, W); + break; + case TGSI_SEMANTIC_GENERIC: + /* usually a texcoord */ + src = i915_emit_decl(p, REG_TYPE_T, T_TEX0 + sem_ind, D0_CHANNEL_ALL); + break; + default: + i915_program_error(p, "Bad source->Index"); + return 0; + } + break; + + case TGSI_FILE_IMMEDIATE: + assert(index < p->num_immediates); + index = p->immediates_map[index]; + /* fall-through */ + case TGSI_FILE_CONSTANT: + src = UREG(REG_TYPE_CONST, index); + break; + + default: + i915_program_error(p, "Bad source->File"); + return 0; + } + + src = swizzle(src, + source->Register.SwizzleX, + source->Register.SwizzleY, + source->Register.SwizzleZ, + source->Register.SwizzleW); + + + /* There's both negate-all-components and per-component negation. + * Try to handle both here. + */ + { + int n = source->Register.Negate; + src = negate(src, n, n, n, n); + } + + /* no abs() */ +#if 0 + /* XXX assertions disabled to allow arbfplight.c to run */ + /* XXX enable these assertions, or fix things */ + assert(!source->Register.Absolute); +#endif + return src; +} + + +/** + * Construct a ureg for a destination register. + */ +static uint +get_result_vector(struct i915_fp_compile *p, + const struct tgsi_full_dst_register *dest) +{ + switch (dest->Register.File) { + case TGSI_FILE_OUTPUT: + { + uint sem_name = p->shader->info.output_semantic_name[dest->Register.Index]; + switch (sem_name) { + case TGSI_SEMANTIC_POSITION: + return UREG(REG_TYPE_OD, 0); + case TGSI_SEMANTIC_COLOR: + return UREG(REG_TYPE_OC, 0); + default: + i915_program_error(p, "Bad inst->DstReg.Index/semantics"); + return 0; + } + } + case TGSI_FILE_TEMPORARY: + return UREG(REG_TYPE_R, dest->Register.Index); + default: + i915_program_error(p, "Bad inst->DstReg.File"); + return 0; + } +} + + +/** + * Compute flags for saturation and writemask. + */ +static uint +get_result_flags(const struct tgsi_full_instruction *inst) +{ + const uint writeMask + = inst->Dst[0].Register.WriteMask; + uint flags = 0x0; + + if (inst->Instruction.Saturate == TGSI_SAT_ZERO_ONE) + flags |= A0_DEST_SATURATE; + + if (writeMask & TGSI_WRITEMASK_X) + flags |= A0_DEST_CHANNEL_X; + if (writeMask & TGSI_WRITEMASK_Y) + flags |= A0_DEST_CHANNEL_Y; + if (writeMask & TGSI_WRITEMASK_Z) + flags |= A0_DEST_CHANNEL_Z; + if (writeMask & TGSI_WRITEMASK_W) + flags |= A0_DEST_CHANNEL_W; + + return flags; +} + + +/** + * Convert TGSI_TEXTURE_x token to DO_SAMPLE_TYPE_x token + */ +static uint +translate_tex_src_target(struct i915_fp_compile *p, uint tex) +{ + switch (tex) { + case TGSI_TEXTURE_SHADOW1D: + /* fall-through */ + case TGSI_TEXTURE_1D: + return D0_SAMPLE_TYPE_2D; + + case TGSI_TEXTURE_SHADOW2D: + /* fall-through */ + case TGSI_TEXTURE_2D: + return D0_SAMPLE_TYPE_2D; + + case TGSI_TEXTURE_SHADOWRECT: + /* fall-through */ + case TGSI_TEXTURE_RECT: + return D0_SAMPLE_TYPE_2D; + + case TGSI_TEXTURE_3D: + return D0_SAMPLE_TYPE_VOLUME; + + case TGSI_TEXTURE_CUBE: + return D0_SAMPLE_TYPE_CUBE; + + default: + i915_program_error(p, "TexSrc type"); + return 0; + } +} + + +/** + * Generate texel lookup instruction. + */ +static void +emit_tex(struct i915_fp_compile *p, + const struct tgsi_full_instruction *inst, + uint opcode) +{ + uint texture = inst->Texture.Texture; + uint unit = inst->Src[1].Register.Index; + uint tex = translate_tex_src_target( p, texture ); + uint sampler = i915_emit_decl(p, REG_TYPE_S, unit, tex); + uint coord = src_vector( p, &inst->Src[0]); + + i915_emit_texld( p, + get_result_vector( p, &inst->Dst[0] ), + get_result_flags( inst ), + sampler, + coord, + opcode); +} + + +/** + * Generate a simple arithmetic instruction + * \param opcode the i915 opcode + * \param numArgs the number of input/src arguments + */ +static void +emit_simple_arith(struct i915_fp_compile *p, + const struct tgsi_full_instruction *inst, + uint opcode, uint numArgs) +{ + uint arg1, arg2, arg3; + + assert(numArgs <= 3); + + arg1 = (numArgs < 1) ? 0 : src_vector( p, &inst->Src[0] ); + arg2 = (numArgs < 2) ? 0 : src_vector( p, &inst->Src[1] ); + arg3 = (numArgs < 3) ? 0 : src_vector( p, &inst->Src[2] ); + + i915_emit_arith( p, + opcode, + get_result_vector( p, &inst->Dst[0]), + get_result_flags( inst ), 0, + arg1, + arg2, + arg3 ); +} + + +/** As above, but swap the first two src regs */ +static void +emit_simple_arith_swap2(struct i915_fp_compile *p, + const struct tgsi_full_instruction *inst, + uint opcode, uint numArgs) +{ + struct tgsi_full_instruction inst2; + + assert(numArgs == 2); + + /* transpose first two registers */ + inst2 = *inst; + inst2.Src[0] = inst->Src[1]; + inst2.Src[1] = inst->Src[0]; + + emit_simple_arith(p, &inst2, opcode, numArgs); +} + + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +/* + * Translate TGSI instruction to i915 instruction. + * + * Possible concerns: + * + * SIN, COS -- could use another taylor step? + * LIT -- results seem a little different to sw mesa + * LOG -- different to mesa on negative numbers, but this is conformant. + */ +static void +i915_translate_instruction(struct i915_fp_compile *p, + const struct tgsi_full_instruction *inst) +{ + uint writemask; + uint src0, src1, src2, flags; + uint tmp = 0; + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_ABS: + src0 = src_vector(p, &inst->Src[0]); + i915_emit_arith(p, + A0_MAX, + get_result_vector(p, &inst->Dst[0]), + get_result_flags(inst), 0, + src0, negate(src0, 1, 1, 1, 1), 0); + break; + + case TGSI_OPCODE_ADD: + emit_simple_arith(p, inst, A0_ADD, 2); + break; + + case TGSI_OPCODE_CMP: + src0 = src_vector(p, &inst->Src[0]); + src1 = src_vector(p, &inst->Src[1]); + src2 = src_vector(p, &inst->Src[2]); + i915_emit_arith(p, A0_CMP, + get_result_vector(p, &inst->Dst[0]), + get_result_flags(inst), + 0, src0, src2, src1); /* NOTE: order of src2, src1 */ + break; + + case TGSI_OPCODE_COS: + src0 = src_vector(p, &inst->Src[0]); + tmp = i915_get_utemp(p); + + i915_emit_arith(p, + A0_MUL, + tmp, A0_DEST_CHANNEL_X, 0, + src0, i915_emit_const1f(p, 1.0f / (float) (M_PI * 2.0)), 0); + + i915_emit_arith(p, A0_MOD, tmp, A0_DEST_CHANNEL_X, 0, tmp, 0, 0); + + /* By choosing different taylor constants, could get rid of this mul: + */ + i915_emit_arith(p, + A0_MUL, + tmp, A0_DEST_CHANNEL_X, 0, + tmp, i915_emit_const1f(p, (float) (M_PI * 2.0)), 0); + + /* + * t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1 + * t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, 1 + * t0 = MUL t0.xxz1 t0.z111 ; x^6 x^4 x^2 1 + * result = DP4 t0, cos_constants + */ + i915_emit_arith(p, + A0_MUL, + tmp, A0_DEST_CHANNEL_XY, 0, + swizzle(tmp, X, X, ONE, ONE), + swizzle(tmp, X, ONE, ONE, ONE), 0); + + i915_emit_arith(p, + A0_MUL, + tmp, A0_DEST_CHANNEL_XYZ, 0, + swizzle(tmp, X, Y, X, ONE), + swizzle(tmp, X, X, ONE, ONE), 0); + + i915_emit_arith(p, + A0_MUL, + tmp, A0_DEST_CHANNEL_XYZ, 0, + swizzle(tmp, X, X, Z, ONE), + swizzle(tmp, Z, ONE, ONE, ONE), 0); + + i915_emit_arith(p, + A0_DP4, + get_result_vector(p, &inst->Dst[0]), + get_result_flags(inst), 0, + swizzle(tmp, ONE, Z, Y, X), + i915_emit_const4fv(p, cos_constants), 0); + break; + + case TGSI_OPCODE_DP3: + emit_simple_arith(p, inst, A0_DP3, 2); + break; + + case TGSI_OPCODE_DP4: + emit_simple_arith(p, inst, A0_DP4, 2); + break; + + case TGSI_OPCODE_DPH: + src0 = src_vector(p, &inst->Src[0]); + src1 = src_vector(p, &inst->Src[1]); + + i915_emit_arith(p, + A0_DP4, + get_result_vector(p, &inst->Dst[0]), + get_result_flags(inst), 0, + swizzle(src0, X, Y, Z, ONE), src1, 0); + break; + + case TGSI_OPCODE_DST: + src0 = src_vector(p, &inst->Src[0]); + src1 = src_vector(p, &inst->Src[1]); + + /* result[0] = 1 * 1; + * result[1] = a[1] * b[1]; + * result[2] = a[2] * 1; + * result[3] = 1 * b[3]; + */ + i915_emit_arith(p, + A0_MUL, + get_result_vector(p, &inst->Dst[0]), + get_result_flags(inst), 0, + swizzle(src0, ONE, Y, Z, ONE), + swizzle(src1, ONE, Y, ONE, W), 0); + break; + + case TGSI_OPCODE_END: + /* no-op */ + break; + + case TGSI_OPCODE_EX2: + src0 = src_vector(p, &inst->Src[0]); + + i915_emit_arith(p, + A0_EXP, + get_result_vector(p, &inst->Dst[0]), + get_result_flags(inst), 0, + swizzle(src0, X, X, X, X), 0, 0); + break; + + case TGSI_OPCODE_FLR: + emit_simple_arith(p, inst, A0_FLR, 1); + break; + + case TGSI_OPCODE_FRC: + emit_simple_arith(p, inst, A0_FRC, 1); + break; + + case TGSI_OPCODE_KIL: + /* kill if src[0].x < 0 || src[0].y < 0 ... */ + src0 = src_vector(p, &inst->Src[0]); + tmp = i915_get_utemp(p); + + i915_emit_texld(p, + tmp, /* dest reg: a dummy reg */ + A0_DEST_CHANNEL_ALL, /* dest writemask */ + 0, /* sampler */ + src0, /* coord*/ + T0_TEXKILL); /* opcode */ + break; + + case TGSI_OPCODE_KILP: + assert(0); /* not tested yet */ + break; + + case TGSI_OPCODE_LG2: + src0 = src_vector(p, &inst->Src[0]); + + i915_emit_arith(p, + A0_LOG, + get_result_vector(p, &inst->Dst[0]), + get_result_flags(inst), 0, + swizzle(src0, X, X, X, X), 0, 0); + break; + + case TGSI_OPCODE_LIT: + src0 = src_vector(p, &inst->Src[0]); + tmp = i915_get_utemp(p); + + /* tmp = max( a.xyzw, a.00zw ) + * XXX: Clamp tmp.w to -128..128 + * tmp.y = log(tmp.y) + * tmp.y = tmp.w * tmp.y + * tmp.y = exp(tmp.y) + * result = cmp (a.11-x1, a.1x01, a.1xy1 ) + */ + i915_emit_arith(p, A0_MAX, tmp, A0_DEST_CHANNEL_ALL, 0, + src0, swizzle(src0, ZERO, ZERO, Z, W), 0); + + i915_emit_arith(p, A0_LOG, tmp, A0_DEST_CHANNEL_Y, 0, + swizzle(tmp, Y, Y, Y, Y), 0, 0); + + i915_emit_arith(p, A0_MUL, tmp, A0_DEST_CHANNEL_Y, 0, + swizzle(tmp, ZERO, Y, ZERO, ZERO), + swizzle(tmp, ZERO, W, ZERO, ZERO), 0); + + i915_emit_arith(p, A0_EXP, tmp, A0_DEST_CHANNEL_Y, 0, + swizzle(tmp, Y, Y, Y, Y), 0, 0); + + i915_emit_arith(p, A0_CMP, + get_result_vector(p, &inst->Dst[0]), + get_result_flags(inst), 0, + negate(swizzle(tmp, ONE, ONE, X, ONE), 0, 0, 1, 0), + swizzle(tmp, ONE, X, ZERO, ONE), + swizzle(tmp, ONE, X, Y, ONE)); + + break; + + case TGSI_OPCODE_LRP: + src0 = src_vector(p, &inst->Src[0]); + src1 = src_vector(p, &inst->Src[1]); + src2 = src_vector(p, &inst->Src[2]); + flags = get_result_flags(inst); + tmp = i915_get_utemp(p); + + /* b*a + c*(1-a) + * + * b*a + c - ca + * + * tmp = b*a + c, + * result = (-c)*a + tmp + */ + i915_emit_arith(p, A0_MAD, tmp, + flags & A0_DEST_CHANNEL_ALL, 0, src1, src0, src2); + + i915_emit_arith(p, A0_MAD, + get_result_vector(p, &inst->Dst[0]), + flags, 0, negate(src2, 1, 1, 1, 1), src0, tmp); + break; + + case TGSI_OPCODE_MAD: + emit_simple_arith(p, inst, A0_MAD, 3); + break; + + case TGSI_OPCODE_MAX: + emit_simple_arith(p, inst, A0_MAX, 2); + break; + + case TGSI_OPCODE_MIN: + src0 = src_vector(p, &inst->Src[0]); + src1 = src_vector(p, &inst->Src[1]); + tmp = i915_get_utemp(p); + flags = get_result_flags(inst); + + i915_emit_arith(p, + A0_MAX, + tmp, flags & A0_DEST_CHANNEL_ALL, 0, + negate(src0, 1, 1, 1, 1), + negate(src1, 1, 1, 1, 1), 0); + + i915_emit_arith(p, + A0_MOV, + get_result_vector(p, &inst->Dst[0]), + flags, 0, negate(tmp, 1, 1, 1, 1), 0, 0); + break; + + case TGSI_OPCODE_MOV: + emit_simple_arith(p, inst, A0_MOV, 1); + break; + + case TGSI_OPCODE_MUL: + emit_simple_arith(p, inst, A0_MUL, 2); + break; + + case TGSI_OPCODE_POW: + src0 = src_vector(p, &inst->Src[0]); + src1 = src_vector(p, &inst->Src[1]); + tmp = i915_get_utemp(p); + flags = get_result_flags(inst); + + /* XXX: masking on intermediate values, here and elsewhere. + */ + i915_emit_arith(p, + A0_LOG, + tmp, A0_DEST_CHANNEL_X, 0, + swizzle(src0, X, X, X, X), 0, 0); + + i915_emit_arith(p, A0_MUL, tmp, A0_DEST_CHANNEL_X, 0, tmp, src1, 0); + + i915_emit_arith(p, + A0_EXP, + get_result_vector(p, &inst->Dst[0]), + flags, 0, swizzle(tmp, X, X, X, X), 0, 0); + break; + + case TGSI_OPCODE_RET: + /* XXX: no-op? */ + break; + + case TGSI_OPCODE_RCP: + src0 = src_vector(p, &inst->Src[0]); + + i915_emit_arith(p, + A0_RCP, + get_result_vector(p, &inst->Dst[0]), + get_result_flags(inst), 0, + swizzle(src0, X, X, X, X), 0, 0); + break; + + case TGSI_OPCODE_RSQ: + src0 = src_vector(p, &inst->Src[0]); + + i915_emit_arith(p, + A0_RSQ, + get_result_vector(p, &inst->Dst[0]), + get_result_flags(inst), 0, + swizzle(src0, X, X, X, X), 0, 0); + break; + + case TGSI_OPCODE_SCS: + src0 = src_vector(p, &inst->Src[0]); + tmp = i915_get_utemp(p); + + /* + * t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1 + * t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, x + * t1 = MUL t0.xyyw t0.yz11 ; x^7 x^5 x^3 x + * scs.x = DP4 t1, sin_constants + * t1 = MUL t0.xxz1 t0.z111 ; x^6 x^4 x^2 1 + * scs.y = DP4 t1, cos_constants + */ + i915_emit_arith(p, + A0_MUL, + tmp, A0_DEST_CHANNEL_XY, 0, + swizzle(src0, X, X, ONE, ONE), + swizzle(src0, X, ONE, ONE, ONE), 0); + + i915_emit_arith(p, + A0_MUL, + tmp, A0_DEST_CHANNEL_ALL, 0, + swizzle(tmp, X, Y, X, Y), + swizzle(tmp, X, X, ONE, ONE), 0); + + writemask = inst->Dst[0].Register.WriteMask; + + if (writemask & TGSI_WRITEMASK_Y) { + uint tmp1; + + if (writemask & TGSI_WRITEMASK_X) + tmp1 = i915_get_utemp(p); + else + tmp1 = tmp; + + i915_emit_arith(p, + A0_MUL, + tmp1, A0_DEST_CHANNEL_ALL, 0, + swizzle(tmp, X, Y, Y, W), + swizzle(tmp, X, Z, ONE, ONE), 0); + + i915_emit_arith(p, + A0_DP4, + get_result_vector(p, &inst->Dst[0]), + A0_DEST_CHANNEL_Y, 0, + swizzle(tmp1, W, Z, Y, X), + i915_emit_const4fv(p, sin_constants), 0); + } + + if (writemask & TGSI_WRITEMASK_X) { + i915_emit_arith(p, + A0_MUL, + tmp, A0_DEST_CHANNEL_XYZ, 0, + swizzle(tmp, X, X, Z, ONE), + swizzle(tmp, Z, ONE, ONE, ONE), 0); + + i915_emit_arith(p, + A0_DP4, + get_result_vector(p, &inst->Dst[0]), + A0_DEST_CHANNEL_X, 0, + swizzle(tmp, ONE, Z, Y, X), + i915_emit_const4fv(p, cos_constants), 0); + } + break; + + case TGSI_OPCODE_SGE: + emit_simple_arith(p, inst, A0_SGE, 2); + break; + + case TGSI_OPCODE_SLE: + /* like SGE, but swap reg0, reg1 */ + emit_simple_arith_swap2(p, inst, A0_SGE, 2); + break; + + case TGSI_OPCODE_SIN: + src0 = src_vector(p, &inst->Src[0]); + tmp = i915_get_utemp(p); + + i915_emit_arith(p, + A0_MUL, + tmp, A0_DEST_CHANNEL_X, 0, + src0, i915_emit_const1f(p, 1.0f / (float) (M_PI * 2.0)), 0); + + i915_emit_arith(p, A0_MOD, tmp, A0_DEST_CHANNEL_X, 0, tmp, 0, 0); + + /* By choosing different taylor constants, could get rid of this mul: + */ + i915_emit_arith(p, + A0_MUL, + tmp, A0_DEST_CHANNEL_X, 0, + tmp, i915_emit_const1f(p, (float) (M_PI * 2.0)), 0); + + /* + * t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1 + * t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, x + * t1 = MUL t0.xyyw t0.yz11 ; x^7 x^5 x^3 x + * result = DP4 t1.wzyx, sin_constants + */ + i915_emit_arith(p, + A0_MUL, + tmp, A0_DEST_CHANNEL_XY, 0, + swizzle(tmp, X, X, ONE, ONE), + swizzle(tmp, X, ONE, ONE, ONE), 0); + + i915_emit_arith(p, + A0_MUL, + tmp, A0_DEST_CHANNEL_ALL, 0, + swizzle(tmp, X, Y, X, Y), + swizzle(tmp, X, X, ONE, ONE), 0); + + i915_emit_arith(p, + A0_MUL, + tmp, A0_DEST_CHANNEL_ALL, 0, + swizzle(tmp, X, Y, Y, W), + swizzle(tmp, X, Z, ONE, ONE), 0); + + i915_emit_arith(p, + A0_DP4, + get_result_vector(p, &inst->Dst[0]), + get_result_flags(inst), 0, + swizzle(tmp, W, Z, Y, X), + i915_emit_const4fv(p, sin_constants), 0); + break; + + case TGSI_OPCODE_SLT: + emit_simple_arith(p, inst, A0_SLT, 2); + break; + + case TGSI_OPCODE_SGT: + /* like SLT, but swap reg0, reg1 */ + emit_simple_arith_swap2(p, inst, A0_SLT, 2); + break; + + case TGSI_OPCODE_SUB: + src0 = src_vector(p, &inst->Src[0]); + src1 = src_vector(p, &inst->Src[1]); + + i915_emit_arith(p, + A0_ADD, + get_result_vector(p, &inst->Dst[0]), + get_result_flags(inst), 0, + src0, negate(src1, 1, 1, 1, 1), 0); + break; + + case TGSI_OPCODE_TEX: + emit_tex(p, inst, T0_TEXLD); + break; + + case TGSI_OPCODE_TXB: + emit_tex(p, inst, T0_TEXLDB); + break; + + case TGSI_OPCODE_TXP: + emit_tex(p, inst, T0_TEXLDP); + break; + + case TGSI_OPCODE_XPD: + /* Cross product: + * result.x = src0.y * src1.z - src0.z * src1.y; + * result.y = src0.z * src1.x - src0.x * src1.z; + * result.z = src0.x * src1.y - src0.y * src1.x; + * result.w = undef; + */ + src0 = src_vector(p, &inst->Src[0]); + src1 = src_vector(p, &inst->Src[1]); + tmp = i915_get_utemp(p); + + i915_emit_arith(p, + A0_MUL, + tmp, A0_DEST_CHANNEL_ALL, 0, + swizzle(src0, Z, X, Y, ONE), + swizzle(src1, Y, Z, X, ONE), 0); + + i915_emit_arith(p, + A0_MAD, + get_result_vector(p, &inst->Dst[0]), + get_result_flags(inst), 0, + swizzle(src0, Y, Z, X, ONE), + swizzle(src1, Z, X, Y, ONE), + negate(tmp, 1, 1, 1, 0)); + break; + + default: + i915_program_error(p, "bad opcode %d", inst->Instruction.Opcode); + p->error = 1; + return; + } + + i915_release_utemps(p); +} + + +/** + * Translate TGSI fragment shader into i915 hardware instructions. + * \param p the translation state + * \param tokens the TGSI token array + */ +static void +i915_translate_instructions(struct i915_fp_compile *p, + const struct tgsi_token *tokens) +{ + struct i915_fragment_shader *ifs = p->shader; + struct tgsi_parse_context parse; + + tgsi_parse_init( &parse, tokens ); + + while( !tgsi_parse_end_of_tokens( &parse ) ) { + + tgsi_parse_token( &parse ); + + switch( parse.FullToken.Token.Type ) { + case TGSI_TOKEN_TYPE_DECLARATION: + if (parse.FullToken.FullDeclaration.Declaration.File + == TGSI_FILE_CONSTANT) { + uint i; + for (i = parse.FullToken.FullDeclaration.Range.First; + i <= parse.FullToken.FullDeclaration.Range.Last; + i++) { + assert(ifs->constant_flags[i] == 0x0); + ifs->constant_flags[i] = I915_CONSTFLAG_USER; + ifs->num_constants = MAX2(ifs->num_constants, i + 1); + } + } + else if (parse.FullToken.FullDeclaration.Declaration.File + == TGSI_FILE_TEMPORARY) { + uint i; + for (i = parse.FullToken.FullDeclaration.Range.First; + i <= parse.FullToken.FullDeclaration.Range.Last; + i++) { + assert(i < I915_MAX_TEMPORARY); + /* XXX just use shader->info->file_mask[TGSI_FILE_TEMPORARY] */ + p->temp_flag |= (1 << i); /* mark temp as used */ + } + } + break; + + case TGSI_TOKEN_TYPE_IMMEDIATE: + { + const struct tgsi_full_immediate *imm + = &parse.FullToken.FullImmediate; + const uint pos = p->num_immediates++; + uint j; + assert( imm->Immediate.NrTokens <= 4 + 1 ); + for (j = 0; j < imm->Immediate.NrTokens - 1; j++) { + p->immediates[pos][j] = imm->u[j].Float; + } + } + break; + + case TGSI_TOKEN_TYPE_INSTRUCTION: + if (p->first_instruction) { + /* resolve location of immediates */ + uint i, j; + for (i = 0; i < p->num_immediates; i++) { + /* find constant slot for this immediate */ + for (j = 0; j < I915_MAX_CONSTANT; j++) { + if (ifs->constant_flags[j] == 0x0) { + memcpy(ifs->constants[j], + p->immediates[i], + 4 * sizeof(float)); + /*printf("immediate %d maps to const %d\n", i, j);*/ + ifs->constant_flags[j] = 0xf; /* all four comps used */ + p->immediates_map[i] = j; + ifs->num_constants = MAX2(ifs->num_constants, j + 1); + break; + } + } + } + + p->first_instruction = FALSE; + } + + i915_translate_instruction(p, &parse.FullToken.FullInstruction); + break; + + default: + assert( 0 ); + } + + } /* while */ + + tgsi_parse_free (&parse); +} + + +static struct i915_fp_compile * +i915_init_compile(struct i915_context *i915, + struct i915_fragment_shader *ifs) +{ + struct i915_fp_compile *p = CALLOC_STRUCT(i915_fp_compile); + + p->shader = ifs; + + /* Put new constants at end of const buffer, growing downward. + * The problem is we don't know how many user-defined constants might + * be specified with pipe->set_constant_buffer(). + * Should pre-scan the user's program to determine the highest-numbered + * constant referenced. + */ + ifs->num_constants = 0; + memset(ifs->constant_flags, 0, sizeof(ifs->constant_flags)); + + p->first_instruction = TRUE; + + p->nr_tex_indirect = 1; /* correct? */ + p->nr_tex_insn = 0; + p->nr_alu_insn = 0; + p->nr_decl_insn = 0; + + p->csr = p->program; + p->decl = p->declarations; + p->decl_s = 0; + p->decl_t = 0; + p->temp_flag = ~0x0 << I915_MAX_TEMPORARY; + p->utemp_flag = ~0x7; + + p->wpos_tex = -1; + + /* initialize the first program word */ + *(p->decl++) = _3DSTATE_PIXEL_SHADER_PROGRAM; + + return p; +} + + +/* Copy compile results to the fragment program struct and destroy the + * compilation context. + */ +static void +i915_fini_compile(struct i915_context *i915, struct i915_fp_compile *p) +{ + struct i915_fragment_shader *ifs = p->shader; + unsigned long program_size = (unsigned long) (p->csr - p->program); + unsigned long decl_size = (unsigned long) (p->decl - p->declarations); + + if (p->nr_tex_indirect > I915_MAX_TEX_INDIRECT) + i915_program_error(p, "Exceeded max nr indirect texture lookups"); + + if (p->nr_tex_insn > I915_MAX_TEX_INSN) + i915_program_error(p, "Exceeded max TEX instructions"); + + if (p->nr_alu_insn > I915_MAX_ALU_INSN) + i915_program_error(p, "Exceeded max ALU instructions"); + + if (p->nr_decl_insn > I915_MAX_DECL_INSN) + i915_program_error(p, "Exceeded max DECL instructions"); + + if (p->error) { + p->NumNativeInstructions = 0; + p->NumNativeAluInstructions = 0; + p->NumNativeTexInstructions = 0; + p->NumNativeTexIndirections = 0; + + i915_use_passthrough_shader(ifs); + } + else { + p->NumNativeInstructions + = p->nr_alu_insn + p->nr_tex_insn + p->nr_decl_insn; + p->NumNativeAluInstructions = p->nr_alu_insn; + p->NumNativeTexInstructions = p->nr_tex_insn; + p->NumNativeTexIndirections = p->nr_tex_indirect; + + /* patch in the program length */ + p->declarations[0] |= program_size + decl_size - 2; + + /* Copy compilation results to fragment program struct: + */ + assert(!ifs->program); + ifs->program + = (uint *) MALLOC((program_size + decl_size) * sizeof(uint)); + if (ifs->program) { + ifs->program_len = program_size + decl_size; + + memcpy(ifs->program, + p->declarations, + decl_size * sizeof(uint)); + + memcpy(ifs->program + decl_size, + p->program, + program_size * sizeof(uint)); + } + } + + /* Release the compilation struct: + */ + FREE(p); +} + + +/** + * Find an unused texture coordinate slot to use for fragment WPOS. + * Update p->fp->wpos_tex with the result (-1 if no used texcoord slot is found). + */ +static void +i915_find_wpos_space(struct i915_fp_compile *p) +{ +#if 0 + const uint inputs + = p->shader->inputs_read | (1 << TGSI_ATTRIB_POS); /*XXX hack*/ + uint i; + + p->wpos_tex = -1; + + if (inputs & (1 << TGSI_ATTRIB_POS)) { + for (i = 0; i < I915_TEX_UNITS; i++) { + if ((inputs & (1 << (TGSI_ATTRIB_TEX0 + i))) == 0) { + p->wpos_tex = i; + return; + } + } + + i915_program_error(p, "No free texcoord for wpos value"); + } +#else + if (p->shader->info.input_semantic_name[0] == TGSI_SEMANTIC_POSITION) { + /* frag shader using the fragment position input */ +#if 0 + assert(0); +#endif + } +#endif +} + + + + +/** + * Rather than trying to intercept and jiggle depth writes during + * emit, just move the value into its correct position at the end of + * the program: + */ +static void +i915_fixup_depth_write(struct i915_fp_compile *p) +{ + /* XXX assuming pos/depth is always in output[0] */ + if (p->shader->info.output_semantic_name[0] == TGSI_SEMANTIC_POSITION) { + const uint depth = UREG(REG_TYPE_OD, 0); + + i915_emit_arith(p, + A0_MOV, /* opcode */ + depth, /* dest reg */ + A0_DEST_CHANNEL_W, /* write mask */ + 0, /* saturate? */ + swizzle(depth, X, Y, Z, Z), /* src0 */ + 0, 0 /* src1, src2 */); + } +} + + +void +i915_translate_fragment_program( struct i915_context *i915, + struct i915_fragment_shader *fs) +{ + struct i915_fp_compile *p = i915_init_compile(i915, fs); + const struct tgsi_token *tokens = fs->state.tokens; + + i915_find_wpos_space(p); + +#if 0 + tgsi_dump(tokens, 0); +#endif + + i915_translate_instructions(p, tokens); + i915_fixup_depth_write(p); + + i915_fini_compile(i915, p); +} diff --git a/src/gallium/drivers/i915/i915_prim_emit.c b/src/gallium/drivers/i915/i915_prim_emit.c new file mode 100644 index 0000000..dd997e2 --- /dev/null +++ b/src/gallium/drivers/i915/i915_prim_emit.c @@ -0,0 +1,226 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "draw/draw_pipe.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_pack_color.h" + +#include "i915_context.h" +#include "i915_reg.h" +#include "i915_state.h" +#include "i915_batch.h" + + + +/** + * Primitive emit to hardware. No support for vertex buffers or any + * nice fast paths. + */ +struct setup_stage { + struct draw_stage stage; /**< This must be first (base class) */ + + struct i915_context *i915; +}; + + + +/** + * Basically a cast wrapper. + */ +static INLINE struct setup_stage *setup_stage( struct draw_stage *stage ) +{ + return (struct setup_stage *)stage; +} + + +/** + * Extract the needed fields from vertex_header and emit i915 dwords. + * Recall that the vertices are constructed by the 'draw' module and + * have a couple of slots at the beginning (1-dword header, 4-dword + * clip pos) that we ignore here. + */ +static INLINE void +emit_hw_vertex( struct i915_context *i915, + const struct vertex_header *vertex) +{ + const struct vertex_info *vinfo = &i915->current.vertex_info; + uint i; + uint count = 0; /* for debug/sanity */ + + assert(!i915->dirty); + + for (i = 0; i < vinfo->num_attribs; i++) { + const uint j = vinfo->attrib[i].src_index; + const float *attrib = vertex->data[j]; + switch (vinfo->attrib[i].emit) { + case EMIT_1F: + OUT_BATCH( fui(attrib[0]) ); + count++; + break; + case EMIT_2F: + OUT_BATCH( fui(attrib[0]) ); + OUT_BATCH( fui(attrib[1]) ); + count += 2; + break; + case EMIT_3F: + OUT_BATCH( fui(attrib[0]) ); + OUT_BATCH( fui(attrib[1]) ); + OUT_BATCH( fui(attrib[2]) ); + count += 3; + break; + case EMIT_4F: + OUT_BATCH( fui(attrib[0]) ); + OUT_BATCH( fui(attrib[1]) ); + OUT_BATCH( fui(attrib[2]) ); + OUT_BATCH( fui(attrib[3]) ); + count += 4; + break; + case EMIT_4UB: + OUT_BATCH( pack_ub4(float_to_ubyte( attrib[0] ), + float_to_ubyte( attrib[1] ), + float_to_ubyte( attrib[2] ), + float_to_ubyte( attrib[3] )) ); + count += 1; + break; + case EMIT_4UB_BGRA: + OUT_BATCH( pack_ub4(float_to_ubyte( attrib[2] ), + float_to_ubyte( attrib[1] ), + float_to_ubyte( attrib[0] ), + float_to_ubyte( attrib[3] )) ); + count += 1; + break; + default: + assert(0); + } + } + assert(count == vinfo->size); +} + + + +static INLINE void +emit_prim( struct draw_stage *stage, + struct prim_header *prim, + unsigned hwprim, + unsigned nr ) +{ + struct i915_context *i915 = setup_stage(stage)->i915; + unsigned vertex_size; + unsigned i; + + if (i915->dirty) + i915_update_derived( i915 ); + + if (i915->hardware_dirty) + i915_emit_hardware_state( i915 ); + + /* need to do this after validation! */ + vertex_size = i915->current.vertex_info.size * 4; /* in bytes */ + assert(vertex_size >= 12); /* never smaller than 12 bytes */ + + if (!BEGIN_BATCH( 1 + nr * vertex_size / 4, 0 )) { + FLUSH_BATCH(NULL); + + /* Make sure state is re-emitted after a flush: + */ + i915_update_derived( i915 ); + i915_emit_hardware_state( i915 ); + + if (!BEGIN_BATCH( 1 + nr * vertex_size / 4, 0 )) { + assert(0); + return; + } + } + + /* Emit each triangle as a single primitive. I told you this was + * simple. + */ + OUT_BATCH(_3DPRIMITIVE | + hwprim | + ((4 + vertex_size * nr)/4 - 2)); + + for (i = 0; i < nr; i++) + emit_hw_vertex(i915, prim->v[i]); +} + + +static void +setup_tri( struct draw_stage *stage, struct prim_header *prim ) +{ + emit_prim( stage, prim, PRIM3D_TRILIST, 3 ); +} + + +static void +setup_line(struct draw_stage *stage, struct prim_header *prim) +{ + emit_prim( stage, prim, PRIM3D_LINELIST, 2 ); +} + + +static void +setup_point(struct draw_stage *stage, struct prim_header *prim) +{ + emit_prim( stage, prim, PRIM3D_POINTLIST, 1 ); +} + + +static void setup_flush( struct draw_stage *stage, unsigned flags ) +{ +} + +static void reset_stipple_counter( struct draw_stage *stage ) +{ +} + +static void render_destroy( struct draw_stage *stage ) +{ + FREE( stage ); +} + + +/** + * Create a new primitive setup/render stage. This gets plugged into + * the 'draw' module's pipeline. + */ +struct draw_stage *i915_draw_render_stage( struct i915_context *i915 ) +{ + struct setup_stage *setup = CALLOC_STRUCT(setup_stage); + + setup->i915 = i915; + setup->stage.draw = i915->draw; + setup->stage.point = setup_point; + setup->stage.line = setup_line; + setup->stage.tri = setup_tri; + setup->stage.flush = setup_flush; + setup->stage.reset_stipple_counter = reset_stipple_counter; + setup->stage.destroy = render_destroy; + + return &setup->stage; +} diff --git a/src/gallium/drivers/i915/i915_prim_vbuf.c b/src/gallium/drivers/i915/i915_prim_vbuf.c new file mode 100644 index 0000000..baebbc7 --- /dev/null +++ b/src/gallium/drivers/i915/i915_prim_vbuf.c @@ -0,0 +1,769 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \file + * Build post-transformation, post-clipping vertex buffers and element + * lists by hooking into the end of the primitive pipeline and + * manipulating the vertex_id field in the vertex headers. + * + * XXX: work in progress + * + * \author José Fonseca + * \author Keith Whitwell + */ + + +#include "draw/draw_context.h" +#include "draw/draw_vbuf.h" +#include "util/u_debug.h" +#include "util/u_inlines.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_fifo.h" + +#include "i915_context.h" +#include "i915_reg.h" +#include "i915_batch.h" +#include "i915_state.h" + + +#define VBUF_MAP_BUFFER + +/** + * Primitive renderer for i915. + */ +struct i915_vbuf_render { + struct vbuf_render base; + + struct i915_context *i915; + + /** Vertex size in bytes */ + size_t vertex_size; + + /** Software primitive */ + unsigned prim; + + /** Hardware primitive */ + unsigned hwprim; + + /** Genereate a vertex list */ + unsigned fallback; + + /* Stuff for the vbo */ + struct i915_winsys_buffer *vbo; + size_t vbo_size; /**< current size of allocated buffer */ + size_t vbo_alloc_size; /**< minimum buffer size to allocate */ + size_t vbo_hw_offset; /**< offset that we program the hardware with */ + size_t vbo_sw_offset; /**< offset that we work with */ + size_t vbo_index; /**< index offset to be added to all indices */ + void *vbo_ptr; + size_t vbo_max_used; + size_t vbo_max_index; /**< index offset to be added to all indices */ + +#ifndef VBUF_MAP_BUFFER + size_t map_used_start; + size_t map_used_end; + size_t map_size; +#endif +}; + + +/** + * Basically a cast wrapper. + */ +static INLINE struct i915_vbuf_render * +i915_vbuf_render(struct vbuf_render *render) +{ + assert(render); + return (struct i915_vbuf_render *)render; +} + +/** + * If vbo state differs between renderer and context + * push state to the context. This function pushes + * hw_offset to i915->vbo_offset and vbo to i915->vbo. + * + * Side effects: + * May updates context vbo_offset and vbo fields. + */ +static void +i915_vbuf_update_vbo_state(struct vbuf_render *render) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + struct i915_context *i915 = i915_render->i915; + + if (i915->vbo != i915_render->vbo || + i915->vbo_offset != i915_render->vbo_hw_offset) { + i915->vbo = i915_render->vbo; + i915->vbo_offset = i915_render->vbo_hw_offset; + i915->dirty |= I915_NEW_VBO; + } +} + +/** + * Callback exported to the draw module. + * Returns the current vertex_info. + * + * Side effects: + * If state is dirty update derived state. + */ +static const struct vertex_info * +i915_vbuf_render_get_vertex_info(struct vbuf_render *render) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + struct i915_context *i915 = i915_render->i915; + + if (i915->dirty) { + /* make sure we have up to date vertex layout */ + i915_update_derived(i915); + } + + return &i915->current.vertex_info; +} + +/** + * Reserve space in the vbo for vertices. + * + * Side effects: + * None. + */ +static boolean +i915_vbuf_render_reserve(struct i915_vbuf_render *i915_render, size_t size) +{ + struct i915_context *i915 = i915_render->i915; + + if (i915_render->vbo_size < size + i915_render->vbo_sw_offset) + return FALSE; + + if (i915->vbo_flushed) + return FALSE; + + return TRUE; +} + +/** + * Allocate a new vbo buffer should there not be enough space for + * the requested number of vertices by the draw module. + * + * Side effects: + * Updates hw_offset, sw_offset, index and allocates a new buffer. + * Will set i915->vbo to null on buffer allocation. + */ +static void +i915_vbuf_render_new_buf(struct i915_vbuf_render *i915_render, size_t size) +{ + struct i915_context *i915 = i915_render->i915; + struct i915_winsys *iws = i915->iws; + + if (i915_render->vbo) { + iws->buffer_destroy(iws, i915_render->vbo); + /* + * XXX If buffers where referenced then this should be done in + * update_vbo_state but since they arn't and malloc likes to reuse + * memory we need to set it to null + */ + i915->vbo = NULL; + i915_render->vbo = NULL; + } + + i915->vbo_flushed = 0; + + i915_render->vbo_size = MAX2(size, i915_render->vbo_alloc_size); + i915_render->vbo_hw_offset = 0; + i915_render->vbo_sw_offset = 0; + i915_render->vbo_index = 0; + +#ifndef VBUF_MAP_BUFFER + if (i915_render->vbo_size > i915_render->map_size) { + i915_render->map_size = i915_render->vbo_size; + FREE(i915_render->vbo_ptr); + i915_render->vbo_ptr = MALLOC(i915_render->map_size); + } +#endif + + i915_render->vbo = iws->buffer_create(iws, i915_render->vbo_size, + I915_NEW_VERTEX); +} + +/** + * Callback exported to the draw module. + * + * Side effects: + * Updates hw_offset, sw_offset, index and may allocate + * a new buffer. Also updates may update the vbo state + * on the i915 context. + */ +static boolean +i915_vbuf_render_allocate_vertices(struct vbuf_render *render, + ushort vertex_size, + ushort nr_vertices) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + size_t size = (size_t)vertex_size * (size_t)nr_vertices; + size_t offset; + + /* + * Align sw_offset with first multiple of vertex size from hw_offset. + * Set index to be the multiples from from hw_offset to sw_offset. + * i915_vbuf_render_new_buf will reset index, sw_offset, hw_offset + * when it allocates a new buffer this is correct. + */ + { + offset = i915_render->vbo_sw_offset - i915_render->vbo_hw_offset; + offset = util_align_npot(offset, vertex_size); + i915_render->vbo_sw_offset = i915_render->vbo_hw_offset + offset; + i915_render->vbo_index = offset / vertex_size; + } + + if (!i915_vbuf_render_reserve(i915_render, size)) + i915_vbuf_render_new_buf(i915_render, size); + + /* + * If a new buffer has been alocated sw_offset, + * hw_offset & index will be reset by new_buf + */ + + i915_render->vertex_size = vertex_size; + + i915_vbuf_update_vbo_state(render); + + if (!i915_render->vbo) + return FALSE; + return TRUE; +} + +static void * +i915_vbuf_render_map_vertices(struct vbuf_render *render) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + struct i915_context *i915 = i915_render->i915; + struct i915_winsys *iws = i915->iws; + + if (i915->vbo_flushed) + debug_printf("%s bad vbo flush occured stalling on hw\n", __FUNCTION__); + +#ifdef VBUF_MAP_BUFFER + i915_render->vbo_ptr = iws->buffer_map(iws, i915_render->vbo, TRUE); + return (unsigned char *)i915_render->vbo_ptr + i915_render->vbo_sw_offset; +#else + (void)iws; + return (unsigned char *)i915_render->vbo_ptr; +#endif +} + +static void +i915_vbuf_render_unmap_vertices(struct vbuf_render *render, + ushort min_index, + ushort max_index) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + struct i915_context *i915 = i915_render->i915; + struct i915_winsys *iws = i915->iws; + + i915_render->vbo_max_index = max_index; + i915_render->vbo_max_used = MAX2(i915_render->vbo_max_used, i915_render->vertex_size * (max_index + 1)); +#ifdef VBUF_MAP_BUFFER + iws->buffer_unmap(iws, i915_render->vbo); +#else + i915_render->map_used_start = i915_render->vertex_size * min_index; + i915_render->map_used_end = i915_render->vertex_size * (max_index + 1); + iws->buffer_write(iws, i915_render->vbo, + i915_render->map_used_start + i915_render->vbo_sw_offset, + i915_render->map_used_end - i915_render->map_used_start, + (unsigned char *)i915_render->vbo_ptr + i915_render->map_used_start); + +#endif +} + +/** + * Ensure that the given max_index given is not larger ushort max. + * If it is larger then ushort max it advanced the hw_offset to the + * same position in the vbo as sw_offset and set index to zero. + * + * Side effects: + * On failure update hw_offset and index. + */ +static void +i915_vbuf_ensure_index_bounds(struct vbuf_render *render, + unsigned max_index) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + + if (max_index + i915_render->vbo_index < ((1 << 17) - 1)) + return; + + i915_render->vbo_hw_offset = i915_render->vbo_sw_offset; + i915_render->vbo_index = 0; + + i915_vbuf_update_vbo_state(render); +} + +static boolean +i915_vbuf_render_set_primitive(struct vbuf_render *render, + unsigned prim) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + i915_render->prim = prim; + + switch(prim) { + case PIPE_PRIM_POINTS: + i915_render->hwprim = PRIM3D_POINTLIST; + i915_render->fallback = 0; + return TRUE; + case PIPE_PRIM_LINES: + i915_render->hwprim = PRIM3D_LINELIST; + i915_render->fallback = 0; + return TRUE; + case PIPE_PRIM_LINE_LOOP: + i915_render->hwprim = PRIM3D_LINELIST; + i915_render->fallback = PIPE_PRIM_LINE_LOOP; + return TRUE; + case PIPE_PRIM_LINE_STRIP: + i915_render->hwprim = PRIM3D_LINESTRIP; + i915_render->fallback = 0; + return TRUE; + case PIPE_PRIM_TRIANGLES: + i915_render->hwprim = PRIM3D_TRILIST; + i915_render->fallback = 0; + return TRUE; + case PIPE_PRIM_TRIANGLE_STRIP: + i915_render->hwprim = PRIM3D_TRISTRIP; + i915_render->fallback = 0; + return TRUE; + case PIPE_PRIM_TRIANGLE_FAN: + i915_render->hwprim = PRIM3D_TRIFAN; + i915_render->fallback = 0; + return TRUE; + case PIPE_PRIM_QUADS: + i915_render->hwprim = PRIM3D_TRILIST; + i915_render->fallback = PIPE_PRIM_QUADS; + return TRUE; + case PIPE_PRIM_QUAD_STRIP: + i915_render->hwprim = PRIM3D_TRILIST; + i915_render->fallback = PIPE_PRIM_QUAD_STRIP; + return TRUE; + case PIPE_PRIM_POLYGON: + i915_render->hwprim = PRIM3D_POLY; + i915_render->fallback = 0; + return TRUE; + default: + /* FIXME: Actually, can handle a lot more just fine... */ + return FALSE; + } +} + +/** + * Used for fallbacks in draw_arrays + */ +static void +draw_arrays_generate_indices(struct vbuf_render *render, + unsigned start, uint nr, + unsigned type) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + struct i915_context *i915 = i915_render->i915; + unsigned i; + unsigned end = start + nr + i915_render->vbo_index; + start += i915_render->vbo_index; + + switch(type) { + case 0: + for (i = start; i+1 < end; i += 2) + OUT_BATCH((i+0) | (i+1) << 16); + if (i < end) + OUT_BATCH(i); + break; + case PIPE_PRIM_LINE_LOOP: + if (nr >= 2) { + for (i = start + 1; i < end; i++) + OUT_BATCH((i-0) | (i+0) << 16); + OUT_BATCH((i-0) | ( start) << 16); + } + break; + case PIPE_PRIM_QUADS: + for (i = start; i + 3 < end; i += 4) { + OUT_BATCH((i+0) | (i+1) << 16); + OUT_BATCH((i+3) | (i+1) << 16); + OUT_BATCH((i+2) | (i+3) << 16); + } + break; + case PIPE_PRIM_QUAD_STRIP: + for (i = start; i + 3 < end; i += 2) { + OUT_BATCH((i+0) | (i+1) << 16); + OUT_BATCH((i+3) | (i+2) << 16); + OUT_BATCH((i+0) | (i+3) << 16); + } + break; + default: + assert(0); + } +} + +static unsigned +draw_arrays_calc_nr_indices(uint nr, unsigned type) +{ + switch (type) { + case 0: + return nr; + case PIPE_PRIM_LINE_LOOP: + if (nr >= 2) + return nr * 2; + else + return 0; + case PIPE_PRIM_QUADS: + return (nr / 4) * 6; + case PIPE_PRIM_QUAD_STRIP: + return ((nr - 2) / 2) * 6; + default: + assert(0); + return 0; + } +} + +static void +draw_arrays_fallback(struct vbuf_render *render, + unsigned start, + uint nr) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + struct i915_context *i915 = i915_render->i915; + unsigned nr_indices; + + nr_indices = draw_arrays_calc_nr_indices(nr, i915_render->fallback); + if (!nr_indices) + return; + + i915_vbuf_ensure_index_bounds(render, start + nr_indices); + + if (i915->dirty) + i915_update_derived(i915); + + if (i915->hardware_dirty) + i915_emit_hardware_state(i915); + + if (!BEGIN_BATCH(1 + (nr_indices + 1)/2, 1)) { + FLUSH_BATCH(NULL); + + /* Make sure state is re-emitted after a flush: + */ + i915_update_derived(i915); + i915_emit_hardware_state(i915); + i915->vbo_flushed = 1; + + if (!BEGIN_BATCH(1 + (nr_indices + 1)/2, 1)) { + assert(0); + goto out; + } + } + + OUT_BATCH(_3DPRIMITIVE | + PRIM_INDIRECT | + i915_render->hwprim | + PRIM_INDIRECT_ELTS | + nr_indices); + + draw_arrays_generate_indices(render, start, nr, i915_render->fallback); + +out: + return; +} + +static void +i915_vbuf_render_draw_arrays(struct vbuf_render *render, + unsigned start, + uint nr) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + struct i915_context *i915 = i915_render->i915; + + if (i915_render->fallback) { + draw_arrays_fallback(render, start, nr); + return; + } + + i915_vbuf_ensure_index_bounds(render, start + nr); + start += i915_render->vbo_index; + + if (i915->dirty) + i915_update_derived(i915); + + if (i915->hardware_dirty) + i915_emit_hardware_state(i915); + + if (!BEGIN_BATCH(2, 0)) { + FLUSH_BATCH(NULL); + + /* Make sure state is re-emitted after a flush: + */ + i915_update_derived(i915); + i915_emit_hardware_state(i915); + i915->vbo_flushed = 1; + + if (!BEGIN_BATCH(2, 0)) { + assert(0); + goto out; + } + } + + OUT_BATCH(_3DPRIMITIVE | + PRIM_INDIRECT | + PRIM_INDIRECT_SEQUENTIAL | + i915_render->hwprim | + nr); + OUT_BATCH(start); /* Beginning vertex index */ + +out: + return; +} + +/** + * Used for normal and fallback emitting of indices + * If type is zero normal operation assumed. + */ +static void +draw_generate_indices(struct vbuf_render *render, + const ushort *indices, + uint nr_indices, + unsigned type) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + struct i915_context *i915 = i915_render->i915; + unsigned i; + unsigned o = i915_render->vbo_index; + + switch(type) { + case 0: + for (i = 0; i + 1 < nr_indices; i += 2) { + OUT_BATCH((o+indices[i]) | (o+indices[i+1]) << 16); + } + if (i < nr_indices) { + OUT_BATCH((o+indices[i])); + } + break; + case PIPE_PRIM_LINE_LOOP: + if (nr_indices >= 2) { + for (i = 1; i < nr_indices; i++) + OUT_BATCH((o+indices[i-1]) | (o+indices[i]) << 16); + OUT_BATCH((o+indices[i-1]) | (o+indices[0]) << 16); + } + break; + case PIPE_PRIM_QUADS: + for (i = 0; i + 3 < nr_indices; i += 4) { + OUT_BATCH((o+indices[i+0]) | (o+indices[i+1]) << 16); + OUT_BATCH((o+indices[i+3]) | (o+indices[i+1]) << 16); + OUT_BATCH((o+indices[i+2]) | (o+indices[i+3]) << 16); + } + break; + case PIPE_PRIM_QUAD_STRIP: + for (i = 0; i + 3 < nr_indices; i += 2) { + OUT_BATCH((o+indices[i+0]) | (o+indices[i+1]) << 16); + OUT_BATCH((o+indices[i+3]) | (o+indices[i+2]) << 16); + OUT_BATCH((o+indices[i+0]) | (o+indices[i+3]) << 16); + } + break; + default: + assert(0); + break; + } +} + +static unsigned +draw_calc_nr_indices(uint nr_indices, unsigned type) +{ + switch (type) { + case 0: + return nr_indices; + case PIPE_PRIM_LINE_LOOP: + if (nr_indices >= 2) + return nr_indices * 2; + else + return 0; + case PIPE_PRIM_QUADS: + return (nr_indices / 4) * 6; + case PIPE_PRIM_QUAD_STRIP: + return ((nr_indices - 2) / 2) * 6; + default: + assert(0); + return 0; + } +} + +static void +i915_vbuf_render_draw_elements(struct vbuf_render *render, + const ushort *indices, + uint nr_indices) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + struct i915_context *i915 = i915_render->i915; + unsigned save_nr_indices; + + save_nr_indices = nr_indices; + + nr_indices = draw_calc_nr_indices(nr_indices, i915_render->fallback); + if (!nr_indices) + return; + + i915_vbuf_ensure_index_bounds(render, i915_render->vbo_max_index); + + if (i915->dirty) + i915_update_derived(i915); + + if (i915->hardware_dirty) + i915_emit_hardware_state(i915); + + if (!BEGIN_BATCH(1 + (nr_indices + 1)/2, 1)) { + FLUSH_BATCH(NULL); + + /* Make sure state is re-emitted after a flush: + */ + i915_update_derived(i915); + i915_emit_hardware_state(i915); + i915->vbo_flushed = 1; + + if (!BEGIN_BATCH(1 + (nr_indices + 1)/2, 1)) { + assert(0); + goto out; + } + } + + OUT_BATCH(_3DPRIMITIVE | + PRIM_INDIRECT | + i915_render->hwprim | + PRIM_INDIRECT_ELTS | + nr_indices); + draw_generate_indices(render, + indices, + save_nr_indices, + i915_render->fallback); + +out: + return; +} + +static void +i915_vbuf_render_release_vertices(struct vbuf_render *render) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + + i915_render->vbo_sw_offset += i915_render->vbo_max_used; + i915_render->vbo_max_used = 0; + + /* + * Micro optimization, by calling update here we the offset change + * will be picked up on the next pipe_context::draw_*. + */ + i915_vbuf_update_vbo_state(render); +} + +static void +i915_vbuf_render_destroy(struct vbuf_render *render) +{ + struct i915_vbuf_render *i915_render = i915_vbuf_render(render); + FREE(i915_render); +} + +/** + * Create a new primitive render. + */ +static struct vbuf_render * +i915_vbuf_render_create(struct i915_context *i915) +{ + struct i915_vbuf_render *i915_render = CALLOC_STRUCT(i915_vbuf_render); + struct i915_winsys *iws = i915->iws; + int i; + + i915_render->i915 = i915; + + i915_render->base.max_vertex_buffer_bytes = 16*4096; + + /* NOTE: it must be such that state and vertices indices fit in a single + * batch buffer. + */ + i915_render->base.max_indices = 16*1024; + + i915_render->base.get_vertex_info = i915_vbuf_render_get_vertex_info; + i915_render->base.allocate_vertices = i915_vbuf_render_allocate_vertices; + i915_render->base.map_vertices = i915_vbuf_render_map_vertices; + i915_render->base.unmap_vertices = i915_vbuf_render_unmap_vertices; + i915_render->base.set_primitive = i915_vbuf_render_set_primitive; + i915_render->base.draw_elements = i915_vbuf_render_draw_elements; + i915_render->base.draw_arrays = i915_vbuf_render_draw_arrays; + i915_render->base.release_vertices = i915_vbuf_render_release_vertices; + i915_render->base.destroy = i915_vbuf_render_destroy; + +#ifndef VBUF_MAP_BUFFER + i915_render->map_size = 0; + i915_render->map_used_start = 0; + i915_render->map_used_end = 0; +#endif + + i915_render->vbo = NULL; + i915_render->vbo_ptr = NULL; + i915_render->vbo_size = 0; + i915_render->vbo_hw_offset = 0; + i915_render->vbo_sw_offset = 0; + i915_render->vbo_alloc_size = i915_render->base.max_vertex_buffer_bytes * 4; + +#ifdef VBUF_USE_POOL + i915_render->pool_used = FALSE; + i915_render->pool_buffer_size = i915_render->vbo_alloc_size; + i915_render->pool_fifo = u_fifo_create(6); + for (i = 0; i < 6; i++) + u_fifo_add(i915_render->pool_fifo, + iws->buffer_create(iws, i915_render->pool_buffer_size, + I915_NEW_VERTEX)); +#else + (void)i; + (void)iws; +#endif + + return &i915_render->base; +} + +/** + * Create a new primitive vbuf/render stage. + */ +struct draw_stage *i915_draw_vbuf_stage(struct i915_context *i915) +{ + struct vbuf_render *render; + struct draw_stage *stage; + + render = i915_vbuf_render_create(i915); + if(!render) + return NULL; + + stage = draw_vbuf_stage(i915->draw, render); + if(!stage) { + render->destroy(render); + return NULL; + } + /** TODO JB: this shouldn't be here */ + draw_set_render(i915->draw, render); + + return stage; +} diff --git a/src/gallium/drivers/i915/i915_public.h b/src/gallium/drivers/i915/i915_public.h new file mode 100644 index 0000000..588654d --- /dev/null +++ b/src/gallium/drivers/i915/i915_public.h @@ -0,0 +1,13 @@ + +#ifndef I915_PUBLIC_H +#define I915_PUBLIC_H + +struct i915_winsys; +struct pipe_screen; + +/** + * Create i915 pipe_screen. + */ +struct pipe_screen * i915_screen_create(struct i915_winsys *iws); + +#endif diff --git a/src/gallium/drivers/i915/i915_reg.h b/src/gallium/drivers/i915/i915_reg.h new file mode 100644 index 0000000..5e4e80d --- /dev/null +++ b/src/gallium/drivers/i915/i915_reg.h @@ -0,0 +1,981 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + + +#ifndef I915_REG_H +#define I915_REG_H + + +#define I915_SET_FIELD( var, mask, value ) (var &= ~(mask), var |= value) + +#define CMD_3D (0x3<<29) + +#define PRIM3D_INLINE (CMD_3D | (0x1f<<24)) +#define PRIM3D_TRILIST (0x0<<18) +#define PRIM3D_TRISTRIP (0x1<<18) +#define PRIM3D_TRISTRIP_RVRSE (0x2<<18) +#define PRIM3D_TRIFAN (0x3<<18) +#define PRIM3D_POLY (0x4<<18) +#define PRIM3D_LINELIST (0x5<<18) +#define PRIM3D_LINESTRIP (0x6<<18) +#define PRIM3D_RECTLIST (0x7<<18) +#define PRIM3D_POINTLIST (0x8<<18) +#define PRIM3D_DIB (0x9<<18) +#define PRIM3D_CLEAR_RECT (0xa<<18) +#define PRIM3D_ZONE_INIT (0xd<<18) +#define PRIM3D_MASK (0x1f<<18) + +/* p137 */ +#define _3DSTATE_AA_CMD (CMD_3D | (0x06<<24)) +#define AA_LINE_ECAAR_WIDTH_ENABLE (1<<16) +#define AA_LINE_ECAAR_WIDTH_0_5 0 +#define AA_LINE_ECAAR_WIDTH_1_0 (1<<14) +#define AA_LINE_ECAAR_WIDTH_2_0 (2<<14) +#define AA_LINE_ECAAR_WIDTH_4_0 (3<<14) +#define AA_LINE_REGION_WIDTH_ENABLE (1<<8) +#define AA_LINE_REGION_WIDTH_0_5 0 +#define AA_LINE_REGION_WIDTH_1_0 (1<<6) +#define AA_LINE_REGION_WIDTH_2_0 (2<<6) +#define AA_LINE_REGION_WIDTH_4_0 (3<<6) + +/* 3DSTATE_BACKFACE_STENCIL_OPS, p138*/ +#define _3DSTATE_BACKFACE_STENCIL_OPS (CMD_3D | (0x8<<24)) +#define BFO_ENABLE_STENCIL_REF (1<<23) +#define BFO_STENCIL_REF_SHIFT 15 +#define BFO_STENCIL_REF_MASK (0xff<<15) +#define BFO_ENABLE_STENCIL_FUNCS (1<<14) +#define BFO_STENCIL_TEST_SHIFT 11 +#define BFO_STENCIL_TEST_MASK (0x7<<11) +#define BFO_STENCIL_FAIL_SHIFT 8 +#define BFO_STENCIL_FAIL_MASK (0x7<<8) +#define BFO_STENCIL_PASS_Z_FAIL_SHIFT 5 +#define BFO_STENCIL_PASS_Z_FAIL_MASK (0x7<<5) +#define BFO_STENCIL_PASS_Z_PASS_SHIFT 2 +#define BFO_STENCIL_PASS_Z_PASS_MASK (0x7<<2) +#define BFO_ENABLE_STENCIL_TWO_SIDE (1<<1) +#define BFO_STENCIL_TWO_SIDE (1<<0) + + +/* 3DSTATE_BACKFACE_STENCIL_MASKS, p140 */ +#define _3DSTATE_BACKFACE_STENCIL_MASKS (CMD_3D | (0x9<<24)) +#define BFM_ENABLE_STENCIL_TEST_MASK (1<<17) +#define BFM_ENABLE_STENCIL_WRITE_MASK (1<<16) +#define BFM_STENCIL_TEST_MASK_SHIFT 8 +#define BFM_STENCIL_TEST_MASK_MASK (0xff<<8) +#define BFM_STENCIL_WRITE_MASK_SHIFT 0 +#define BFM_STENCIL_WRITE_MASK_MASK (0xff<<0) + + + +/* 3DSTATE_BIN_CONTROL p141 */ + +/* p143 */ +#define _3DSTATE_BUF_INFO_CMD (CMD_3D | (0x1d<<24) | (0x8e<<16) | 1) +/* Dword 1 */ +#define BUF_3D_ID_COLOR_BACK (0x3<<24) +#define BUF_3D_ID_DEPTH (0x7<<24) +#define BUF_3D_USE_FENCE (1<<23) +#define BUF_3D_TILED_SURFACE (1<<22) +#define BUF_3D_TILE_WALK_X 0 +#define BUF_3D_TILE_WALK_Y (1<<21) +#define BUF_3D_PITCH(x) (((x)/4)<<2) +/* Dword 2 */ +#define BUF_3D_ADDR(x) ((x) & ~0x3) + + +/* 3DSTATE_CHROMA_KEY */ + +/* 3DSTATE_CLEAR_PARAMETERS, p150 */ +#define _3DSTATE_CLEAR_PARAMETERS (CMD_3D | (0x1d<<24) | (0x9c<<16) | 5) +/* Dword 1 */ +#define CLEARPARAM_CLEAR_RECT (1 << 16) +#define CLEARPARAM_ZONE_INIT (0 << 16) +#define CLEARPARAM_WRITE_COLOR (1 << 2) +#define CLEARPARAM_WRITE_DEPTH (1 << 1) +#define CLEARPARAM_WRITE_STENCIL (1 << 0) + +/* 3DSTATE_CONSTANT_BLEND_COLOR, p153 */ +#define _3DSTATE_CONST_BLEND_COLOR_CMD (CMD_3D | (0x1d<<24) | (0x88<<16)) + + + +/* 3DSTATE_COORD_SET_BINDINGS, p154 */ +#define _3DSTATE_COORD_SET_BINDINGS (CMD_3D | (0x16<<24)) +#define CSB_TCB(iunit, eunit) ((eunit)<<(iunit*3)) + +/* p156 */ +#define _3DSTATE_DFLT_DIFFUSE_CMD (CMD_3D | (0x1d<<24) | (0x99<<16)) + +/* p157 */ +#define _3DSTATE_DFLT_SPEC_CMD (CMD_3D | (0x1d<<24) | (0x9a<<16)) + +/* p158 */ +#define _3DSTATE_DFLT_Z_CMD (CMD_3D | (0x1d<<24) | (0x98<<16)) + + +/* 3DSTATE_DEPTH_OFFSET_SCALE, p159 */ +#define _3DSTATE_DEPTH_OFFSET_SCALE (CMD_3D | (0x1d<<24) | (0x97<<16)) +/* scale in dword 1 */ + + +/* 3DSTATE_DEPTH_SUBRECT_DISABLE, p160 */ +#define _3DSTATE_DEPTH_SUBRECT_DISABLE (CMD_3D | (0x1c<<24) | (0x11<<19) | 0x2) + +/* p161 */ +#define _3DSTATE_DST_BUF_VARS_CMD (CMD_3D | (0x1d<<24) | (0x85<<16)) +/* Dword 1 */ +#define TEX_DEFAULT_COLOR_OGL (0<<30) +#define TEX_DEFAULT_COLOR_D3D (1<<30) +#define ZR_EARLY_DEPTH (1<<29) +#define LOD_PRECLAMP_OGL (1<<28) +#define LOD_PRECLAMP_D3D (0<<28) +#define DITHER_FULL_ALWAYS (0<<26) +#define DITHER_FULL_ON_FB_BLEND (1<<26) +#define DITHER_CLAMPED_ALWAYS (2<<26) +#define LINEAR_GAMMA_BLEND_32BPP (1<<25) +#define DEBUG_DISABLE_ENH_DITHER (1<<24) +#define DSTORG_HORT_BIAS(x) ((x)<<20) +#define DSTORG_VERT_BIAS(x) ((x)<<16) +#define COLOR_4_2_2_CHNL_WRT_ALL 0 +#define COLOR_4_2_2_CHNL_WRT_Y (1<<12) +#define COLOR_4_2_2_CHNL_WRT_CR (2<<12) +#define COLOR_4_2_2_CHNL_WRT_CB (3<<12) +#define COLOR_4_2_2_CHNL_WRT_CRCB (4<<12) +#define COLOR_BUF_8BIT 0 +#define COLOR_BUF_RGB555 (1<<8) +#define COLOR_BUF_RGB565 (2<<8) +#define COLOR_BUF_ARGB8888 (3<<8) +#define DEPTH_FRMT_16_FIXED 0 +#define DEPTH_FRMT_16_FLOAT (1<<2) +#define DEPTH_FRMT_24_FIXED_8_OTHER (2<<2) +#define VERT_LINE_STRIDE_1 (1<<1) +#define VERT_LINE_STRIDE_0 (0<<1) +#define VERT_LINE_STRIDE_OFS_1 1 +#define VERT_LINE_STRIDE_OFS_0 0 + +/* p166 */ +#define _3DSTATE_DRAW_RECT_CMD (CMD_3D|(0x1d<<24)|(0x80<<16)|3) +/* Dword 1 */ +#define DRAW_RECT_DIS_DEPTH_OFS (1<<30) +#define DRAW_DITHER_OFS_X(x) ((x)<<26) +#define DRAW_DITHER_OFS_Y(x) ((x)<<24) +/* Dword 2 */ +#define DRAW_YMIN(x) ((x)<<16) +#define DRAW_XMIN(x) (x) +/* Dword 3 */ +#define DRAW_YMAX(x) ((x)<<16) +#define DRAW_XMAX(x) (x) +/* Dword 4 */ +#define DRAW_YORG(x) ((x)<<16) +#define DRAW_XORG(x) (x) + + +/* 3DSTATE_FILTER_COEFFICIENTS_4X4, p170 */ + +/* 3DSTATE_FILTER_COEFFICIENTS_6X5, p172 */ + + +/* _3DSTATE_FOG_COLOR, p173 */ +#define _3DSTATE_FOG_COLOR_CMD (CMD_3D|(0x15<<24)) +#define FOG_COLOR_RED(x) ((x)<<16) +#define FOG_COLOR_GREEN(x) ((x)<<8) +#define FOG_COLOR_BLUE(x) (x) + +/* _3DSTATE_FOG_MODE, p174 */ +#define _3DSTATE_FOG_MODE_CMD (CMD_3D|(0x1d<<24)|(0x89<<16)|2) +/* Dword 1 */ +#define FMC1_FOGFUNC_MODIFY_ENABLE (1<<31) +#define FMC1_FOGFUNC_VERTEX (0<<28) +#define FMC1_FOGFUNC_PIXEL_EXP (1<<28) +#define FMC1_FOGFUNC_PIXEL_EXP2 (2<<28) +#define FMC1_FOGFUNC_PIXEL_LINEAR (3<<28) +#define FMC1_FOGFUNC_MASK (3<<28) +#define FMC1_FOGINDEX_MODIFY_ENABLE (1<<27) +#define FMC1_FOGINDEX_Z (0<<25) +#define FMC1_FOGINDEX_W (1<<25) +#define FMC1_C1_C2_MODIFY_ENABLE (1<<24) +#define FMC1_DENSITY_MODIFY_ENABLE (1<<23) +#define FMC1_C1_ONE (1<<13) +#define FMC1_C1_MASK (0xffff<<4) +/* Dword 2 */ +#define FMC2_C2_ONE (1<<16) +/* Dword 3 */ +#define FMC3_D_ONE (1<<16) + + + +/* _3DSTATE_INDEPENDENT_ALPHA_BLEND, p177 */ +#define _3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD (CMD_3D|(0x0b<<24)) +#define IAB_MODIFY_ENABLE (1<<23) +#define IAB_ENABLE (1<<22) +#define IAB_MODIFY_FUNC (1<<21) +#define IAB_FUNC_SHIFT 16 +#define IAB_MODIFY_SRC_FACTOR (1<<11) +#define IAB_SRC_FACTOR_SHIFT 6 +#define IAB_SRC_FACTOR_MASK (BLENDFACT_MASK<<6) +#define IAB_MODIFY_DST_FACTOR (1<<5) +#define IAB_DST_FACTOR_SHIFT 0 +#define IAB_DST_FACTOR_MASK (BLENDFACT_MASK<<0) + + +#define BLENDFUNC_ADD 0x0 +#define BLENDFUNC_SUBTRACT 0x1 +#define BLENDFUNC_REVERSE_SUBTRACT 0x2 +#define BLENDFUNC_MIN 0x3 +#define BLENDFUNC_MAX 0x4 +#define BLENDFUNC_MASK 0x7 + +/* 3DSTATE_LOAD_INDIRECT, p180 */ + +#define _3DSTATE_LOAD_INDIRECT (CMD_3D|(0x1d<<24)|(0x7<<16)) +#define LI0_STATE_STATIC_INDIRECT (0x01<<8) +#define LI0_STATE_DYNAMIC_INDIRECT (0x02<<8) +#define LI0_STATE_SAMPLER (0x04<<8) +#define LI0_STATE_MAP (0x08<<8) +#define LI0_STATE_PROGRAM (0x10<<8) +#define LI0_STATE_CONSTANTS (0x20<<8) + +#define SIS0_BUFFER_ADDRESS(x) ((x)&~0x3) +#define SIS0_FORCE_LOAD (1<<1) +#define SIS0_BUFFER_VALID (1<<0) +#define SIS1_BUFFER_LENGTH(x) ((x)&0xff) + +#define DIS0_BUFFER_ADDRESS(x) ((x)&~0x3) +#define DIS0_BUFFER_RESET (1<<1) +#define DIS0_BUFFER_VALID (1<<0) + +#define SSB0_BUFFER_ADDRESS(x) ((x)&~0x3) +#define SSB0_FORCE_LOAD (1<<1) +#define SSB0_BUFFER_VALID (1<<0) +#define SSB1_BUFFER_LENGTH(x) ((x)&0xff) + +#define MSB0_BUFFER_ADDRESS(x) ((x)&~0x3) +#define MSB0_FORCE_LOAD (1<<1) +#define MSB0_BUFFER_VALID (1<<0) +#define MSB1_BUFFER_LENGTH(x) ((x)&0xff) + +#define PSP0_BUFFER_ADDRESS(x) ((x)&~0x3) +#define PSP0_FORCE_LOAD (1<<1) +#define PSP0_BUFFER_VALID (1<<0) +#define PSP1_BUFFER_LENGTH(x) ((x)&0xff) + +#define PSC0_BUFFER_ADDRESS(x) ((x)&~0x3) +#define PSC0_FORCE_LOAD (1<<1) +#define PSC0_BUFFER_VALID (1<<0) +#define PSC1_BUFFER_LENGTH(x) ((x)&0xff) + + + + + +/* _3DSTATE_RASTERIZATION_RULES */ +#define _3DSTATE_RASTER_RULES_CMD (CMD_3D|(0x07<<24)) +#define ENABLE_POINT_RASTER_RULE (1<<15) +#define OGL_POINT_RASTER_RULE (1<<13) +#define ENABLE_TEXKILL_3D_4D (1<<10) +#define TEXKILL_3D (0<<9) +#define TEXKILL_4D (1<<9) +#define ENABLE_LINE_STRIP_PROVOKE_VRTX (1<<8) +#define ENABLE_TRI_FAN_PROVOKE_VRTX (1<<5) +#define LINE_STRIP_PROVOKE_VRTX(x) ((x)<<6) +#define TRI_FAN_PROVOKE_VRTX(x) ((x)<<3) + +/* _3DSTATE_SCISSOR_ENABLE, p256 */ +#define _3DSTATE_SCISSOR_ENABLE_CMD (CMD_3D|(0x1c<<24)|(0x10<<19)) +#define ENABLE_SCISSOR_RECT ((1<<1) | 1) +#define DISABLE_SCISSOR_RECT (1<<1) + +/* _3DSTATE_SCISSOR_RECTANGLE_0, p257 */ +#define _3DSTATE_SCISSOR_RECT_0_CMD (CMD_3D|(0x1d<<24)|(0x81<<16)|1) +/* Dword 1 */ +#define SCISSOR_RECT_0_YMIN(x) ((x)<<16) +#define SCISSOR_RECT_0_XMIN(x) (x) +/* Dword 2 */ +#define SCISSOR_RECT_0_YMAX(x) ((x)<<16) +#define SCISSOR_RECT_0_XMAX(x) (x) + +/* p189 */ +#define _3DSTATE_LOAD_STATE_IMMEDIATE_1 ((0x3<<29)|(0x1d<<24)|(0x04<<16)) +#define I1_LOAD_S(n) (1<<(4+n)) + +#define S0_VB_OFFSET_MASK 0xffffffc +#define S0_AUTO_CACHE_INV_DISABLE (1<<0) + +#define S1_VERTEX_WIDTH_SHIFT 24 +#define S1_VERTEX_WIDTH_MASK (0x3f<<24) +#define S1_VERTEX_PITCH_SHIFT 16 +#define S1_VERTEX_PITCH_MASK (0x3f<<16) + +#define TEXCOORDFMT_2D 0x0 +#define TEXCOORDFMT_3D 0x1 +#define TEXCOORDFMT_4D 0x2 +#define TEXCOORDFMT_1D 0x3 +#define TEXCOORDFMT_2D_16 0x4 +#define TEXCOORDFMT_4D_16 0x5 +#define TEXCOORDFMT_NOT_PRESENT 0xf +#define S2_TEXCOORD_FMT0_MASK 0xf +#define S2_TEXCOORD_FMT1_SHIFT 4 +#define S2_TEXCOORD_FMT(unit, type) ((type)<<(unit*4)) +#define S2_TEXCOORD_NONE (~0) + +/* S3 not interesting */ + +#define S4_POINT_WIDTH_SHIFT 23 +#define S4_POINT_WIDTH_MASK (0x1ff<<23) +#define S4_LINE_WIDTH_SHIFT 19 +#define S4_LINE_WIDTH_ONE (0x2<<19) +#define S4_LINE_WIDTH_MASK (0xf<<19) +#define S4_FLATSHADE_ALPHA (1<<18) +#define S4_FLATSHADE_FOG (1<<17) +#define S4_FLATSHADE_SPECULAR (1<<16) +#define S4_FLATSHADE_COLOR (1<<15) +#define S4_CULLMODE_BOTH (0<<13) +#define S4_CULLMODE_NONE (1<<13) +#define S4_CULLMODE_CW (2<<13) +#define S4_CULLMODE_CCW (3<<13) +#define S4_CULLMODE_MASK (3<<13) +#define S4_VFMT_POINT_WIDTH (1<<12) +#define S4_VFMT_SPEC_FOG (1<<11) +#define S4_VFMT_COLOR (1<<10) +#define S4_VFMT_DEPTH_OFFSET (1<<9) +#define S4_VFMT_XYZ (1<<6) +#define S4_VFMT_XYZW (2<<6) +#define S4_VFMT_XY (3<<6) +#define S4_VFMT_XYW (4<<6) +#define S4_VFMT_XYZW_MASK (7<<6) +#define S4_FORCE_DEFAULT_DIFFUSE (1<<5) +#define S4_FORCE_DEFAULT_SPECULAR (1<<4) +#define S4_LOCAL_DEPTH_OFFSET_ENABLE (1<<3) +#define S4_VFMT_FOG_PARAM (1<<2) +#define S4_SPRITE_POINT_ENABLE (1<<1) +#define S4_LINE_ANTIALIAS_ENABLE (1<<0) + +#define S4_VFMT_MASK (S4_VFMT_POINT_WIDTH | \ + S4_VFMT_SPEC_FOG | \ + S4_VFMT_COLOR | \ + S4_VFMT_DEPTH_OFFSET | \ + S4_VFMT_XYZW_MASK | \ + S4_VFMT_FOG_PARAM) + + +#define S5_WRITEDISABLE_ALPHA (1<<31) +#define S5_WRITEDISABLE_RED (1<<30) +#define S5_WRITEDISABLE_GREEN (1<<29) +#define S5_WRITEDISABLE_BLUE (1<<28) +#define S5_WRITEDISABLE_MASK (0xf<<28) +#define S5_FORCE_DEFAULT_POINT_SIZE (1<<27) +#define S5_LAST_PIXEL_ENABLE (1<<26) +#define S5_GLOBAL_DEPTH_OFFSET_ENABLE (1<<25) +#define S5_FOG_ENABLE (1<<24) +#define S5_STENCIL_REF_SHIFT 16 +#define S5_STENCIL_REF_MASK (0xff<<16) +#define S5_STENCIL_TEST_FUNC_SHIFT 13 +#define S5_STENCIL_TEST_FUNC_MASK (0x7<<13) +#define S5_STENCIL_FAIL_SHIFT 10 +#define S5_STENCIL_FAIL_MASK (0x7<<10) +#define S5_STENCIL_PASS_Z_FAIL_SHIFT 7 +#define S5_STENCIL_PASS_Z_FAIL_MASK (0x7<<7) +#define S5_STENCIL_PASS_Z_PASS_SHIFT 4 +#define S5_STENCIL_PASS_Z_PASS_MASK (0x7<<4) +#define S5_STENCIL_WRITE_ENABLE (1<<3) +#define S5_STENCIL_TEST_ENABLE (1<<2) +#define S5_COLOR_DITHER_ENABLE (1<<1) +#define S5_LOGICOP_ENABLE (1<<0) + + +#define S6_ALPHA_TEST_ENABLE (1<<31) +#define S6_ALPHA_TEST_FUNC_SHIFT 28 +#define S6_ALPHA_TEST_FUNC_MASK (0x7<<28) +#define S6_ALPHA_REF_SHIFT 20 +#define S6_ALPHA_REF_MASK (0xff<<20) +#define S6_DEPTH_TEST_ENABLE (1<<19) +#define S6_DEPTH_TEST_FUNC_SHIFT 16 +#define S6_DEPTH_TEST_FUNC_MASK (0x7<<16) +#define S6_CBUF_BLEND_ENABLE (1<<15) +#define S6_CBUF_BLEND_FUNC_SHIFT 12 +#define S6_CBUF_BLEND_FUNC_MASK (0x7<<12) +#define S6_CBUF_SRC_BLEND_FACT_SHIFT 8 +#define S6_CBUF_SRC_BLEND_FACT_MASK (0xf<<8) +#define S6_CBUF_DST_BLEND_FACT_SHIFT 4 +#define S6_CBUF_DST_BLEND_FACT_MASK (0xf<<4) +#define S6_DEPTH_WRITE_ENABLE (1<<3) +#define S6_COLOR_WRITE_ENABLE (1<<2) +#define S6_TRISTRIP_PV_SHIFT 0 +#define S6_TRISTRIP_PV_MASK (0x3<<0) + +#define S7_DEPTH_OFFSET_CONST_MASK ~0 + + + +#define DST_BLND_FACT(f) ((f)<= 0.0) ? src1 : src2 */ +#define A0_MIN (0xe<<24) /* dst = (src0 < src1) ? src0 : src1 */ +#define A0_MAX (0xf<<24) /* dst = (src0 >= src1) ? src0 : src1 */ +#define A0_FLR (0x10<<24) /* dst = floor(src0) */ +#define A0_MOD (0x11<<24) /* dst = src0 fmod 1.0 */ +#define A0_TRC (0x12<<24) /* dst = int(src0) */ +#define A0_SGE (0x13<<24) /* dst = src0 >= src1 ? 1.0 : 0.0 */ +#define A0_SLT (0x14<<24) /* dst = src0 < src1 ? 1.0 : 0.0 */ +#define A0_DEST_SATURATE (1<<22) +#define A0_DEST_TYPE_SHIFT 19 +/* Allow: R, OC, OD, U */ +#define A0_DEST_NR_SHIFT 14 +/* Allow R: 0..15, OC,OD: 0..0, U: 0..2 */ +#define A0_DEST_CHANNEL_X (1<<10) +#define A0_DEST_CHANNEL_Y (2<<10) +#define A0_DEST_CHANNEL_Z (4<<10) +#define A0_DEST_CHANNEL_W (8<<10) +#define A0_DEST_CHANNEL_ALL (0xf<<10) +#define A0_DEST_CHANNEL_SHIFT 10 +#define A0_SRC0_TYPE_SHIFT 7 +#define A0_SRC0_NR_SHIFT 2 + +#define A0_DEST_CHANNEL_XY (A0_DEST_CHANNEL_X|A0_DEST_CHANNEL_Y) +#define A0_DEST_CHANNEL_XYZ (A0_DEST_CHANNEL_XY|A0_DEST_CHANNEL_Z) + + +#define SRC_X 0 +#define SRC_Y 1 +#define SRC_Z 2 +#define SRC_W 3 +#define SRC_ZERO 4 +#define SRC_ONE 5 + +#define A1_SRC0_CHANNEL_X_NEGATE (1<<31) +#define A1_SRC0_CHANNEL_X_SHIFT 28 +#define A1_SRC0_CHANNEL_Y_NEGATE (1<<27) +#define A1_SRC0_CHANNEL_Y_SHIFT 24 +#define A1_SRC0_CHANNEL_Z_NEGATE (1<<23) +#define A1_SRC0_CHANNEL_Z_SHIFT 20 +#define A1_SRC0_CHANNEL_W_NEGATE (1<<19) +#define A1_SRC0_CHANNEL_W_SHIFT 16 +#define A1_SRC1_TYPE_SHIFT 13 +#define A1_SRC1_NR_SHIFT 8 +#define A1_SRC1_CHANNEL_X_NEGATE (1<<7) +#define A1_SRC1_CHANNEL_X_SHIFT 4 +#define A1_SRC1_CHANNEL_Y_NEGATE (1<<3) +#define A1_SRC1_CHANNEL_Y_SHIFT 0 + +#define A2_SRC1_CHANNEL_Z_NEGATE (1<<31) +#define A2_SRC1_CHANNEL_Z_SHIFT 28 +#define A2_SRC1_CHANNEL_W_NEGATE (1<<27) +#define A2_SRC1_CHANNEL_W_SHIFT 24 +#define A2_SRC2_TYPE_SHIFT 21 +#define A2_SRC2_NR_SHIFT 16 +#define A2_SRC2_CHANNEL_X_NEGATE (1<<15) +#define A2_SRC2_CHANNEL_X_SHIFT 12 +#define A2_SRC2_CHANNEL_Y_NEGATE (1<<11) +#define A2_SRC2_CHANNEL_Y_SHIFT 8 +#define A2_SRC2_CHANNEL_Z_NEGATE (1<<7) +#define A2_SRC2_CHANNEL_Z_SHIFT 4 +#define A2_SRC2_CHANNEL_W_NEGATE (1<<3) +#define A2_SRC2_CHANNEL_W_SHIFT 0 + + + +/* Texture instructions */ +#define T0_TEXLD (0x15<<24) /* Sample texture using predeclared + * sampler and address, and output + * filtered texel data to destination + * register */ +#define T0_TEXLDP (0x16<<24) /* Same as texld but performs a + * perspective divide of the texture + * coordinate .xyz values by .w before + * sampling. */ +#define T0_TEXLDB (0x17<<24) /* Same as texld but biases the + * computed LOD by w. Only S4.6 two's + * comp is used. This implies that a + * float to fixed conversion is + * done. */ +#define T0_TEXKILL (0x18<<24) /* Does not perform a sampling + * operation. Simply kills the pixel + * if any channel of the address + * register is < 0.0. */ +#define T0_DEST_TYPE_SHIFT 19 +/* Allow: R, OC, OD, U */ +/* Note: U (unpreserved) regs do not retain their values between + * phases (cannot be used for feedback) + * + * Note: oC and OD registers can only be used as the destination of a + * texture instruction once per phase (this is an implementation + * restriction). + */ +#define T0_DEST_NR_SHIFT 14 +/* Allow R: 0..15, OC,OD: 0..0, U: 0..2 */ +#define T0_SAMPLER_NR_SHIFT 0 /* This field ignored for TEXKILL */ +#define T0_SAMPLER_NR_MASK (0xf<<0) + +#define T1_ADDRESS_REG_TYPE_SHIFT 24 /* Reg to use as texture coord */ +/* Allow R, T, OC, OD -- R, OC, OD are 'dependent' reads, new program phase */ +#define T1_ADDRESS_REG_NR_SHIFT 17 +#define T2_MBZ 0 + +/* Declaration instructions */ +#define D0_DCL (0x19<<24) /* Declare a t (interpolated attrib) + * register or an s (sampler) + * register. */ +#define D0_SAMPLE_TYPE_SHIFT 22 +#define D0_SAMPLE_TYPE_2D (0x0<<22) +#define D0_SAMPLE_TYPE_CUBE (0x1<<22) +#define D0_SAMPLE_TYPE_VOLUME (0x2<<22) +#define D0_SAMPLE_TYPE_MASK (0x3<<22) + +#define D0_TYPE_SHIFT 19 +/* Allow: T, S */ +#define D0_NR_SHIFT 14 +/* Allow T: 0..10, S: 0..15 */ +#define D0_CHANNEL_X (1<<10) +#define D0_CHANNEL_Y (2<<10) +#define D0_CHANNEL_Z (4<<10) +#define D0_CHANNEL_W (8<<10) +#define D0_CHANNEL_ALL (0xf<<10) +#define D0_CHANNEL_NONE (0<<10) + +#define D0_CHANNEL_XY (D0_CHANNEL_X|D0_CHANNEL_Y) +#define D0_CHANNEL_XYZ (D0_CHANNEL_XY|D0_CHANNEL_Z) + +/* I915 Errata: Do not allow (xz), (xw), (xzw) combinations for diffuse + * or specular declarations. + * + * For T dcls, only allow: (x), (xy), (xyz), (w), (xyzw) + * + * Must be zero for S (sampler) dcls + */ +#define D1_MBZ 0 +#define D2_MBZ 0 + + + +/* p207 */ +#define _3DSTATE_MAP_STATE (CMD_3D|(0x1d<<24)|(0x0<<16)) + +#define MS1_MAPMASK_SHIFT 0 +#define MS1_MAPMASK_MASK (0x8fff<<0) + +#define MS2_UNTRUSTED_SURFACE (1<<31) +#define MS2_ADDRESS_MASK 0xfffffffc +#define MS2_VERTICAL_LINE_STRIDE (1<<1) +#define MS2_VERTICAL_OFFSET (1<<1) + +#define MS3_HEIGHT_SHIFT 21 +#define MS3_WIDTH_SHIFT 10 +#define MS3_PALETTE_SELECT (1<<9) +#define MS3_MAPSURF_FORMAT_SHIFT 7 +#define MS3_MAPSURF_FORMAT_MASK (0x7<<7) +#define MAPSURF_8BIT (1<<7) +#define MAPSURF_16BIT (2<<7) +#define MAPSURF_32BIT (3<<7) +#define MAPSURF_422 (5<<7) +#define MAPSURF_COMPRESSED (6<<7) +#define MAPSURF_4BIT_INDEXED (7<<7) +#define MS3_MT_FORMAT_MASK (0x7 << 3) +#define MS3_MT_FORMAT_SHIFT 3 +#define MT_4BIT_IDX_ARGB8888 (7<<3) /* SURFACE_4BIT_INDEXED */ +#define MT_8BIT_I8 (0<<3) /* SURFACE_8BIT */ +#define MT_8BIT_L8 (1<<3) +#define MT_8BIT_A8 (4<<3) +#define MT_8BIT_MONO8 (5<<3) +#define MT_16BIT_RGB565 (0<<3) /* SURFACE_16BIT */ +#define MT_16BIT_ARGB1555 (1<<3) +#define MT_16BIT_ARGB4444 (2<<3) +#define MT_16BIT_AY88 (3<<3) +#define MT_16BIT_88DVDU (5<<3) +#define MT_16BIT_BUMP_655LDVDU (6<<3) +#define MT_16BIT_I16 (7<<3) +#define MT_16BIT_L16 (8<<3) +#define MT_16BIT_A16 (9<<3) +#define MT_32BIT_ARGB8888 (0<<3) /* SURFACE_32BIT */ +#define MT_32BIT_ABGR8888 (1<<3) +#define MT_32BIT_XRGB8888 (2<<3) +#define MT_32BIT_XBGR8888 (3<<3) +#define MT_32BIT_QWVU8888 (4<<3) +#define MT_32BIT_AXVU8888 (5<<3) +#define MT_32BIT_LXVU8888 (6<<3) +#define MT_32BIT_XLVU8888 (7<<3) +#define MT_32BIT_ARGB2101010 (8<<3) +#define MT_32BIT_ABGR2101010 (9<<3) +#define MT_32BIT_AWVU2101010 (0xA<<3) +#define MT_32BIT_GR1616 (0xB<<3) +#define MT_32BIT_VU1616 (0xC<<3) +#define MT_32BIT_xI824 (0xD<<3) +#define MT_32BIT_xA824 (0xE<<3) +#define MT_32BIT_xL824 (0xF<<3) +#define MT_422_YCRCB_SWAPY (0<<3) /* SURFACE_422 */ +#define MT_422_YCRCB_NORMAL (1<<3) +#define MT_422_YCRCB_SWAPUV (2<<3) +#define MT_422_YCRCB_SWAPUVY (3<<3) +#define MT_COMPRESS_DXT1 (0<<3) /* SURFACE_COMPRESSED */ +#define MT_COMPRESS_DXT2_3 (1<<3) +#define MT_COMPRESS_DXT4_5 (2<<3) +#define MT_COMPRESS_FXT1 (3<<3) +#define MT_COMPRESS_DXT1_RGB (4<<3) +#define MS3_USE_FENCE_REGS (1<<2) +#define MS3_TILED_SURFACE (1<<1) +#define MS3_TILE_WALK_Y (1<<0) + +#define MS4_PITCH_SHIFT 21 +#define MS4_CUBE_FACE_ENA_NEGX (1<<20) +#define MS4_CUBE_FACE_ENA_POSX (1<<19) +#define MS4_CUBE_FACE_ENA_NEGY (1<<18) +#define MS4_CUBE_FACE_ENA_POSY (1<<17) +#define MS4_CUBE_FACE_ENA_NEGZ (1<<16) +#define MS4_CUBE_FACE_ENA_POSZ (1<<15) +#define MS4_CUBE_FACE_ENA_MASK (0x3f<<15) +#define MS4_MAX_LOD_SHIFT 9 +#define MS4_MAX_LOD_MASK (0x3f<<9) +#define MS4_MIP_LAYOUT_LEGACY (0<<8) +#define MS4_MIP_LAYOUT_BELOW_LPT (0<<8) +#define MS4_MIP_LAYOUT_RIGHT_LPT (1<<8) +#define MS4_VOLUME_DEPTH_SHIFT 0 +#define MS4_VOLUME_DEPTH_MASK (0xff<<0) + +/* p244 */ +#define _3DSTATE_SAMPLER_STATE (CMD_3D|(0x1d<<24)|(0x1<<16)) + +#define SS1_MAPMASK_SHIFT 0 +#define SS1_MAPMASK_MASK (0x8fff<<0) + +#define SS2_REVERSE_GAMMA_ENABLE (1<<31) +#define SS2_PACKED_TO_PLANAR_ENABLE (1<<30) +#define SS2_COLORSPACE_CONVERSION (1<<29) +#define SS2_CHROMAKEY_SHIFT 27 +#define SS2_BASE_MIP_LEVEL_SHIFT 22 +#define SS2_BASE_MIP_LEVEL_MASK (0x1f<<22) +#define SS2_MIP_FILTER_SHIFT 20 +#define SS2_MIP_FILTER_MASK (0x3<<20) +#define MIPFILTER_NONE 0 +#define MIPFILTER_NEAREST 1 +#define MIPFILTER_LINEAR 3 +#define SS2_MAG_FILTER_SHIFT 17 +#define SS2_MAG_FILTER_MASK (0x7<<17) +#define FILTER_NEAREST 0 +#define FILTER_LINEAR 1 +#define FILTER_ANISOTROPIC 2 +#define FILTER_4X4_1 3 +#define FILTER_4X4_2 4 +#define FILTER_4X4_FLAT 5 +#define FILTER_6X5_MONO 6 /* XXX - check */ +#define SS2_MIN_FILTER_SHIFT 14 +#define SS2_MIN_FILTER_MASK (0x7<<14) +#define SS2_LOD_BIAS_SHIFT 5 +#define SS2_LOD_BIAS_ONE (0x10<<5) +#define SS2_LOD_BIAS_MASK (0x1ff<<5) +/* Shadow requires: + * MT_X8{I,L,A}24 or MT_{I,L,A}16 texture format + * FILTER_4X4_x MIN and MAG filters + */ +#define SS2_SHADOW_ENABLE (1<<4) +#define SS2_MAX_ANISO_MASK (1<<3) +#define SS2_MAX_ANISO_2 (0<<3) +#define SS2_MAX_ANISO_4 (1<<3) +#define SS2_SHADOW_FUNC_SHIFT 0 +#define SS2_SHADOW_FUNC_MASK (0x7<<0) +/* SS2_SHADOW_FUNC values: see COMPAREFUNC_* */ + +#define SS3_MIN_LOD_SHIFT 24 +#define SS3_MIN_LOD_ONE (0x10<<24) +#define SS3_MIN_LOD_MASK (0xff<<24) +#define SS3_KILL_PIXEL_ENABLE (1<<17) +#define SS3_TCX_ADDR_MODE_SHIFT 12 +#define SS3_TCX_ADDR_MODE_MASK (0x7<<12) +#define TEXCOORDMODE_WRAP 0 +#define TEXCOORDMODE_MIRROR 1 +#define TEXCOORDMODE_CLAMP_EDGE 2 +#define TEXCOORDMODE_CUBE 3 +#define TEXCOORDMODE_CLAMP_BORDER 4 +#define TEXCOORDMODE_MIRROR_ONCE 5 +#define SS3_TCY_ADDR_MODE_SHIFT 9 +#define SS3_TCY_ADDR_MODE_MASK (0x7<<9) +#define SS3_TCZ_ADDR_MODE_SHIFT 6 +#define SS3_TCZ_ADDR_MODE_MASK (0x7<<6) +#define SS3_NORMALIZED_COORDS (1<<5) +#define SS3_TEXTUREMAP_INDEX_SHIFT 1 +#define SS3_TEXTUREMAP_INDEX_MASK (0xf<<1) +#define SS3_DEINTERLACER_ENABLE (1<<0) + +#define SS4_BORDER_COLOR_MASK (~0) + +/* 3DSTATE_SPAN_STIPPLE, p258 + */ +#define _3DSTATE_STIPPLE ((0x3<<29)|(0x1d<<24)|(0x83<<16)) +#define ST1_ENABLE (1<<16) +#define ST1_MASK (0xffff) + +#define _3DSTATE_DEFAULT_Z ((0x3<<29)|(0x1d<<24)|(0x98<<16)) +#define _3DSTATE_DEFAULT_DIFFUSE ((0x3<<29)|(0x1d<<24)|(0x99<<16)) +#define _3DSTATE_DEFAULT_SPECULAR ((0x3<<29)|(0x1d<<24)|(0x9a<<16)) + + +#define MI_FLUSH ((0<<29)|(4<<23)) +#define FLUSH_MAP_CACHE (1<<0) +#define INHIBIT_FLUSH_RENDER_CACHE (1<<2) +#define MI_NOOP 0 + + +#define CMD_3D (0x3<<29) + + +#define _3DPRIMITIVE ((0x3<<29)|(0x1f<<24)) +#define PRIM_INDIRECT (1<<23) +#define PRIM_INLINE (0<<23) +#define PRIM_INDIRECT_SEQUENTIAL (0<<17) +#define PRIM_INDIRECT_ELTS (1<<17) + +#define PRIM3D_TRILIST (0x0<<18) +#define PRIM3D_TRISTRIP (0x1<<18) +#define PRIM3D_TRISTRIP_RVRSE (0x2<<18) +#define PRIM3D_TRIFAN (0x3<<18) +#define PRIM3D_POLY (0x4<<18) +#define PRIM3D_LINELIST (0x5<<18) +#define PRIM3D_LINESTRIP (0x6<<18) +#define PRIM3D_RECTLIST (0x7<<18) +#define PRIM3D_POINTLIST (0x8<<18) +#define PRIM3D_DIB (0x9<<18) +#define PRIM3D_MASK (0x1f<<18) + +#define I915PACKCOLOR4444(r,g,b,a) \ + ((((a) & 0xf0) << 8) | (((r) & 0xf0) << 4) | ((g) & 0xf0) | ((b) >> 4)) + +#define I915PACKCOLOR1555(r,g,b,a) \ + ((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | (((b) & 0xf8) >> 3) | \ + ((a) ? 0x8000 : 0)) + +#define I915PACKCOLOR565(r,g,b) \ + ((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3)) + +#define I915PACKCOLOR8888(r,g,b,a) \ + ((a<<24) | (r<<16) | (g<<8) | b) + + + + +#define BR00_BITBLT_CLIENT 0x40000000 +#define BR00_OP_COLOR_BLT 0x10000000 +#define BR00_OP_SRC_COPY_BLT 0x10C00000 +#define BR13_SOLID_PATTERN 0x80000000 + +#define XY_COLOR_BLT_CMD ((2<<29)|(0x50<<22)|0x4) +#define XY_COLOR_BLT_WRITE_ALPHA (1<<21) +#define XY_COLOR_BLT_WRITE_RGB (1<<20) + +#define XY_SRC_COPY_BLT_CMD ((2<<29)|(0x53<<22)|6) +#define XY_SRC_COPY_BLT_WRITE_ALPHA (1<<21) +#define XY_SRC_COPY_BLT_WRITE_RGB (1<<20) + +#define MI_WAIT_FOR_EVENT ((0x3<<23)) +#define MI_WAIT_FOR_PLANE_B_FLIP (1<<6) +#define MI_WAIT_FOR_PLANE_A_FLIP (1<<2) + +#define MI_BATCH_BUFFER (0x30<<23) +#define MI_BATCH_BUFFER_START (0x31<<23) +#define MI_BATCH_BUFFER_END (0xa<<23) + + + +#define COMPAREFUNC_ALWAYS 0 +#define COMPAREFUNC_NEVER 0x1 +#define COMPAREFUNC_LESS 0x2 +#define COMPAREFUNC_EQUAL 0x3 +#define COMPAREFUNC_LEQUAL 0x4 +#define COMPAREFUNC_GREATER 0x5 +#define COMPAREFUNC_NOTEQUAL 0x6 +#define COMPAREFUNC_GEQUAL 0x7 + +#define STENCILOP_KEEP 0 +#define STENCILOP_ZERO 0x1 +#define STENCILOP_REPLACE 0x2 +#define STENCILOP_INCRSAT 0x3 +#define STENCILOP_DECRSAT 0x4 +#define STENCILOP_INCR 0x5 +#define STENCILOP_DECR 0x6 +#define STENCILOP_INVERT 0x7 + +#define LOGICOP_CLEAR 0 +#define LOGICOP_NOR 0x1 +#define LOGICOP_AND_INV 0x2 +#define LOGICOP_COPY_INV 0x3 +#define LOGICOP_AND_RVRSE 0x4 +#define LOGICOP_INV 0x5 +#define LOGICOP_XOR 0x6 +#define LOGICOP_NAND 0x7 +#define LOGICOP_AND 0x8 +#define LOGICOP_EQUIV 0x9 +#define LOGICOP_NOOP 0xa +#define LOGICOP_OR_INV 0xb +#define LOGICOP_COPY 0xc +#define LOGICOP_OR_RVRSE 0xd +#define LOGICOP_OR 0xe +#define LOGICOP_SET 0xf + +#define BLENDFACT_ZERO 0x01 +#define BLENDFACT_ONE 0x02 +#define BLENDFACT_SRC_COLR 0x03 +#define BLENDFACT_INV_SRC_COLR 0x04 +#define BLENDFACT_SRC_ALPHA 0x05 +#define BLENDFACT_INV_SRC_ALPHA 0x06 +#define BLENDFACT_DST_ALPHA 0x07 +#define BLENDFACT_INV_DST_ALPHA 0x08 +#define BLENDFACT_DST_COLR 0x09 +#define BLENDFACT_INV_DST_COLR 0x0a +#define BLENDFACT_SRC_ALPHA_SATURATE 0x0b +#define BLENDFACT_CONST_COLOR 0x0c +#define BLENDFACT_INV_CONST_COLOR 0x0d +#define BLENDFACT_CONST_ALPHA 0x0e +#define BLENDFACT_INV_CONST_ALPHA 0x0f +#define BLENDFACT_MASK 0x0f + +#define PCI_CHIP_I915_G 0x2582 +#define PCI_CHIP_I915_GM 0x2592 +#define PCI_CHIP_I945_G 0x2772 +#define PCI_CHIP_I945_GM 0x27A2 +#define PCI_CHIP_I945_GME 0x27AE +#define PCI_CHIP_G33_G 0x29C2 +#define PCI_CHIP_Q35_G 0x29B2 +#define PCI_CHIP_Q33_G 0x29D2 +#define PCI_CHIP_PINEVIEW_G 0xA001 +#define PCI_CHIP_PINEVIEW_M 0xA011 + + +#endif diff --git a/src/gallium/drivers/i915/i915_resource.c b/src/gallium/drivers/i915/i915_resource.c new file mode 100644 index 0000000..499233c --- /dev/null +++ b/src/gallium/drivers/i915/i915_resource.c @@ -0,0 +1,51 @@ +#include "util/u_debug.h" + +#include "i915_resource.h" +#include "i915_context.h" +#include "i915_screen.h" + + +static struct pipe_resource * +i915_resource_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + if (template->target == PIPE_BUFFER) + return i915_buffer_create(screen, template); + else + return i915_texture_create(screen, template); + +} + +static struct pipe_resource * +i915_resource_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle) +{ + if (template->target == PIPE_BUFFER) + return NULL; + else + return i915_texture_from_handle(screen, template, whandle); +} + + +void +i915_init_resource_functions(struct i915_context *i915 ) +{ + i915->base.is_resource_referenced = u_default_is_resource_referenced; + i915->base.get_transfer = u_get_transfer_vtbl; + i915->base.transfer_map = u_transfer_map_vtbl; + i915->base.transfer_flush_region = u_transfer_flush_region_vtbl; + i915->base.transfer_unmap = u_transfer_unmap_vtbl; + i915->base.transfer_destroy = u_transfer_destroy_vtbl; + i915->base.transfer_inline_write = u_transfer_inline_write_vtbl; +} + +void +i915_init_screen_resource_functions(struct i915_screen *is) +{ + is->base.resource_create = i915_resource_create; + is->base.resource_from_handle = i915_resource_from_handle; + is->base.resource_get_handle = u_resource_get_handle_vtbl; + is->base.resource_destroy = u_resource_destroy_vtbl; + is->base.user_buffer_create = i915_user_buffer_create; +} diff --git a/src/gallium/drivers/i915/i915_resource.h b/src/gallium/drivers/i915/i915_resource.h new file mode 100644 index 0000000..86620e6 --- /dev/null +++ b/src/gallium/drivers/i915/i915_resource.h @@ -0,0 +1,122 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef I915_RESOURCE_H +#define I915_RESOURCE_H + +struct i915_screen; + +#include "util/u_transfer.h" +#include "util/u_debug.h" +#include "i915_winsys.h" + + +struct i915_context; +struct i915_screen; + + +struct i915_buffer { + struct u_resource b; + uint8_t *data; + boolean free_on_destroy; +}; + +#define I915_MAX_TEXTURE_2D_LEVELS 11 /* max 1024x1024 */ +#define I915_MAX_TEXTURE_3D_LEVELS 8 /* max 128x128x128 */ + + +struct offset_pair { + unsigned short nblocksx; + unsigned short nblocksy; +}; + +struct i915_texture { + struct u_resource b; + + /* tiling flags */ + enum i915_winsys_buffer_tile tiling; + unsigned stride; + unsigned depth_stride; /* per-image on i945? */ + unsigned total_nblocksy; + + unsigned nr_images[I915_MAX_TEXTURE_2D_LEVELS]; + + /* Explicitly store the offset of each image for each cube face or + * depth value. + * + * Array [depth] off offsets. + */ + struct offset_pair *image_offset[I915_MAX_TEXTURE_2D_LEVELS]; + + /* The data is held here: + */ + struct i915_winsys_buffer *buffer; +}; + +unsigned i915_texture_offset(struct i915_texture *tex, + unsigned level, unsigned layer); +void i915_init_screen_resource_functions(struct i915_screen *is); +void i915_init_resource_functions(struct i915_context *i915); + +extern struct u_resource_vtbl i915_buffer_vtbl; +extern struct u_resource_vtbl i915_texture_vtbl; + +static INLINE struct i915_texture *i915_texture(struct pipe_resource *resource) +{ + struct i915_texture *tex = (struct i915_texture *)resource; + assert(tex->b.vtbl == &i915_texture_vtbl); + return tex; +} + +static INLINE struct i915_buffer *i915_buffer(struct pipe_resource *resource) +{ + struct i915_buffer *tex = (struct i915_buffer *)resource; + assert(tex->b.vtbl == &i915_buffer_vtbl); + return tex; +} + +struct pipe_resource * +i915_texture_create(struct pipe_screen *screen, + const struct pipe_resource *template); + +struct pipe_resource * +i915_texture_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle); + + +struct pipe_resource * +i915_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage); + +struct pipe_resource * +i915_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *template); + +#endif /* I915_RESOURCE_H */ diff --git a/src/gallium/drivers/i915/i915_resource_buffer.c b/src/gallium/drivers/i915/i915_resource_buffer.c new file mode 100644 index 0000000..450203d --- /dev/null +++ b/src/gallium/drivers/i915/i915_resource_buffer.c @@ -0,0 +1,161 @@ +/************************************************************************** + * + * Copyright 2006 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. + * + **************************************************************************/ + /* + * Authors: + * Keith Whitwell + * Michel Dänzer + */ + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "i915_context.h" +#include "i915_resource.h" + + + +static boolean +i915_buffer_get_handle(struct pipe_screen *screen, + struct pipe_resource *resource, + struct winsys_handle *handle) +{ + return FALSE; +} + +static void +i915_buffer_destroy(struct pipe_screen *screen, + struct pipe_resource *resource) +{ + struct i915_buffer *buffer = i915_buffer(resource); + if (buffer->free_on_destroy) + align_free(buffer->data); + FREE(buffer); +} + + +static void * +i915_buffer_transfer_map( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct i915_buffer *buffer = i915_buffer(transfer->resource); + return buffer->data + transfer->box.x; +} + + +static void +i915_buffer_transfer_inline_write( struct pipe_context *rm_ctx, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride) +{ + struct i915_buffer *buffer = i915_buffer(resource); + + memcpy(buffer->data + box->x, + data, + box->width); +} + + +struct u_resource_vtbl i915_buffer_vtbl = +{ + i915_buffer_get_handle, /* get_handle */ + i915_buffer_destroy, /* resource_destroy */ + NULL, /* is_resource_referenced */ + u_default_get_transfer, /* get_transfer */ + u_default_transfer_destroy, /* transfer_destroy */ + i915_buffer_transfer_map, /* transfer_map */ + u_default_transfer_flush_region, /* transfer_flush_region */ + u_default_transfer_unmap, /* transfer_unmap */ + i915_buffer_transfer_inline_write /* transfer_inline_write */ +}; + + + +struct pipe_resource * +i915_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + struct i915_buffer *buf = CALLOC_STRUCT(i915_buffer); + + if (!buf) + return NULL; + + buf->b.b = *template; + buf->b.vtbl = &i915_buffer_vtbl; + pipe_reference_init(&buf->b.b.reference, 1); + buf->b.b.screen = screen; + + buf->data = MALLOC(template->width0); + buf->free_on_destroy = TRUE; + + if (!buf->data) + goto err; + + return &buf->b.b; + +err: + FREE(buf); + return NULL; +} + + + +struct pipe_resource * +i915_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned bind) +{ + struct i915_buffer *buf = CALLOC_STRUCT(i915_buffer); + + if (!buf) + return NULL; + + pipe_reference_init(&buf->b.b.reference, 1); + buf->b.vtbl = &i915_buffer_vtbl; + buf->b.b.screen = screen; + buf->b.b.format = PIPE_FORMAT_R8_UNORM; /* ?? */ + buf->b.b.usage = PIPE_USAGE_IMMUTABLE; + buf->b.b.bind = bind; + buf->b.b.flags = 0; + buf->b.b.width0 = bytes; + buf->b.b.height0 = 1; + buf->b.b.depth0 = 1; + buf->b.b.array_size = 1; + + buf->data = ptr; + buf->free_on_destroy = FALSE; + + return &buf->b.b; +} diff --git a/src/gallium/drivers/i915/i915_resource_texture.c b/src/gallium/drivers/i915/i915_resource_texture.c new file mode 100644 index 0000000..f19106f --- /dev/null +++ b/src/gallium/drivers/i915/i915_resource_texture.c @@ -0,0 +1,895 @@ +/************************************************************************** + * + * Copyright 2006 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. + * + **************************************************************************/ + /* + * Authors: + * Keith Whitwell + * Michel Dänzer + */ + +#include "pipe/p_state.h" +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "i915_context.h" +#include "i915_resource.h" +#include "i915_screen.h" +#include "i915_winsys.h" +#include "i915_debug.h" + + +#define DEBUG_TEXTURES 0 + +/* + * Helper function and arrays + */ + + +/** + * Initial offset for Cube map. + */ +static const int initial_offsets[6][2] = { + [PIPE_TEX_FACE_POS_X] = {0, 0}, + [PIPE_TEX_FACE_POS_Y] = {1, 0}, + [PIPE_TEX_FACE_POS_Z] = {1, 1}, + [PIPE_TEX_FACE_NEG_X] = {0, 2}, + [PIPE_TEX_FACE_NEG_Y] = {1, 2}, + [PIPE_TEX_FACE_NEG_Z] = {1, 3}, +}; + +/** + * Step offsets for Cube map. + */ +static const int step_offsets[6][2] = { + [PIPE_TEX_FACE_POS_X] = { 0, 2}, + [PIPE_TEX_FACE_POS_Y] = {-1, 2}, + [PIPE_TEX_FACE_POS_Z] = {-1, 1}, + [PIPE_TEX_FACE_NEG_X] = { 0, 2}, + [PIPE_TEX_FACE_NEG_Y] = {-1, 2}, + [PIPE_TEX_FACE_NEG_Z] = {-1, 1}, +}; + +/** + * For compressed level 2 + */ +static const int bottom_offsets[6] = { + [PIPE_TEX_FACE_POS_X] = 16 + 0 * 8, + [PIPE_TEX_FACE_POS_Y] = 16 + 1 * 8, + [PIPE_TEX_FACE_POS_Z] = 16 + 2 * 8, + [PIPE_TEX_FACE_NEG_X] = 16 + 3 * 8, + [PIPE_TEX_FACE_NEG_Y] = 16 + 4 * 8, + [PIPE_TEX_FACE_NEG_Z] = 16 + 5 * 8, +}; + +static INLINE unsigned +align_nblocksx(enum pipe_format format, unsigned width, unsigned align_to) +{ + return align(util_format_get_nblocksx(format, width), align_to); +} + +static INLINE unsigned +align_nblocksy(enum pipe_format format, unsigned width, unsigned align_to) +{ + return align(util_format_get_nblocksy(format, width), align_to); +} + +static INLINE unsigned +get_pot_stride(enum pipe_format format, unsigned width) +{ + return util_next_power_of_two(util_format_get_stride(format, width)); +} + +static INLINE const char* +get_tiling_string(enum i915_winsys_buffer_tile tile) +{ + switch(tile) { + case I915_TILE_NONE: + return "none"; + case I915_TILE_X: + return "x"; + case I915_TILE_Y: + return "y"; + default: + assert(FALSE); + return "?"; + } +} + + +/* + * More advanced helper funcs + */ + + +static void +i915_texture_set_level_info(struct i915_texture *tex, + unsigned level, unsigned nr_images) +{ + assert(level < Elements(tex->nr_images)); + assert(nr_images); + assert(!tex->image_offset[level]); + + tex->nr_images[level] = nr_images; + tex->image_offset[level] = MALLOC(nr_images * sizeof(struct offset_pair)); + tex->image_offset[level][0].nblocksx = 0; + tex->image_offset[level][0].nblocksy = 0; +} + +INLINE unsigned i915_texture_offset(struct i915_texture *tex, + unsigned level, unsigned layer) +{ + unsigned x, y; + x = tex->image_offset[level][layer].nblocksx + * util_format_get_blocksize(tex->b.b.format); + y = tex->image_offset[level][layer].nblocksy; + + return y * tex->stride + x; +} + +static void +i915_texture_set_image_offset(struct i915_texture *tex, + unsigned level, unsigned img, + unsigned nblocksx, unsigned nblocksy) +{ + /* for the first image and level make sure offset is zero */ + assert(!(img == 0 && level == 0) || (nblocksx == 0 && nblocksy == 0)); + assert(img < tex->nr_images[level]); + + tex->image_offset[level][img].nblocksx = nblocksx; + tex->image_offset[level][img].nblocksy = nblocksy; + +#if DEBUG_TEXTURES + debug_printf("%s: %p level %u, img %u (%u, %u)\n", __FUNCTION__, + tex, level, img, x, y); +#endif +} + +static enum i915_winsys_buffer_tile +i915_texture_tiling(struct pipe_resource *pt) +{ + if (!i915_tiling) + return I915_TILE_NONE; + + if (pt->target == PIPE_TEXTURE_1D) + return I915_TILE_NONE; + + if (util_format_is_s3tc(pt->format)) + /* XXX X-tiling might make sense */ + return I915_TILE_NONE; + + return I915_TILE_X; +} + + +/* + * Shared layout functions + */ + + +/** + * Special case to deal with scanout textures. + */ +static boolean +i9x5_scanout_layout(struct i915_texture *tex) +{ + struct pipe_resource *pt = &tex->b.b; + + if (pt->last_level > 0 || util_format_get_blocksize(pt->format) != 4) + return FALSE; + + i915_texture_set_level_info(tex, 0, 1); + i915_texture_set_image_offset(tex, 0, 0, 0, 0); + + if (pt->width0 >= 240) { + tex->stride = align(util_format_get_stride(pt->format, pt->width0), 64); + tex->total_nblocksy = align_nblocksy(pt->format, pt->height0, 8); + tex->tiling = I915_TILE_X; + /* special case for cursors */ + } else if (pt->width0 == 64 && pt->height0 == 64) { + tex->stride = get_pot_stride(pt->format, pt->width0); + tex->total_nblocksy = align_nblocksy(pt->format, pt->height0, 8); + } else { + return FALSE; + } + +#if DEBUG_TEXTURE + debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, + pt->width0, pt->height0, util_format_get_blocksize(pt->format), + tex->stride, tex->total_nblocksy, tex->stride * tex->total_nblocksy); +#endif + + return TRUE; +} + +/** + * Special case to deal with shared textures. + */ +static boolean +i9x5_display_target_layout(struct i915_texture *tex) +{ + struct pipe_resource *pt = &tex->b.b; + + if (pt->last_level > 0 || util_format_get_blocksize(pt->format) != 4) + return FALSE; + + /* fallback to normal textures for small textures */ + if (pt->width0 < 240) + return FALSE; + + i915_texture_set_level_info(tex, 0, 1); + i915_texture_set_image_offset(tex, 0, 0, 0, 0); + + tex->stride = align(util_format_get_stride(pt->format, pt->width0), 64); + tex->total_nblocksy = align_nblocksy(pt->format, pt->height0, 8); + tex->tiling = I915_TILE_X; + +#if DEBUG_TEXTURE + debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, + pt->width0, pt->height0, util_format_get_blocksize(pt->format), + tex->stride, tex->total_nblocksy, tex->stride * tex->total_nblocksy); +#endif + + return TRUE; +} + +/** + * Helper function for special layouts + */ +static boolean +i9x5_special_layout(struct i915_texture *tex) +{ + struct pipe_resource *pt = &tex->b.b; + + /* Scanouts needs special care */ + if (pt->bind & PIPE_BIND_SCANOUT) + if (i9x5_scanout_layout(tex)) + return TRUE; + + /* Shared buffers needs to be compatible with X servers + * + * XXX: need a better name than shared for this if it is to be part + * of core gallium, and probably move the flag to resource.flags, + * rather than bindings. + */ + if (pt->bind & (PIPE_BIND_SHARED | PIPE_BIND_DISPLAY_TARGET)) + if (i9x5_display_target_layout(tex)) + return TRUE; + + return FALSE; +} + +/** + * Cube layout used on i915 and for non-compressed textures on i945. + */ +static void +i9x5_texture_layout_cube(struct i915_texture *tex) +{ + struct pipe_resource *pt = &tex->b.b; + const unsigned nblocks = util_format_get_nblocksx(pt->format, pt->width0); + unsigned level; + unsigned face; + + assert(pt->width0 == pt->height0); /* cubemap images are square */ + + /* double pitch for cube layouts */ + tex->stride = align(nblocks * util_format_get_blocksize(pt->format) * 2, 4); + tex->total_nblocksy = nblocks * 4; + + for (level = 0; level <= pt->last_level; level++) + i915_texture_set_level_info(tex, level, 6); + + for (face = 0; face < 6; face++) { + unsigned x = initial_offsets[face][0] * nblocks; + unsigned y = initial_offsets[face][1] * nblocks; + unsigned d = nblocks; + + for (level = 0; level <= pt->last_level; level++) { + i915_texture_set_image_offset(tex, level, face, x, y); + d >>= 1; + x += step_offsets[face][0] * d; + y += step_offsets[face][1] * d; + } + } +} + + +/* + * i915 layout functions + */ + + +static void +i915_texture_layout_2d(struct i915_texture *tex) +{ + struct pipe_resource *pt = &tex->b.b; + unsigned level; + unsigned width = pt->width0; + unsigned height = pt->height0; + unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->width0); + unsigned align_y = 2; + + if (util_format_is_s3tc(pt->format)) + align_y = 1; + + tex->stride = align(util_format_get_stride(pt->format, pt->width0), 4); + tex->total_nblocksy = 0; + + for (level = 0; level <= pt->last_level; level++) { + i915_texture_set_level_info(tex, level, 1); + i915_texture_set_image_offset(tex, level, 0, 0, tex->total_nblocksy); + + tex->total_nblocksy += nblocksy; + + width = u_minify(width, 1); + height = u_minify(height, 1); + nblocksy = align_nblocksy(pt->format, height, align_y); + } +} + +static void +i915_texture_layout_3d(struct i915_texture *tex) +{ + struct pipe_resource *pt = &tex->b.b; + unsigned level; + + unsigned width = pt->width0; + unsigned height = pt->height0; + unsigned depth = pt->depth0; + unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->height0); + unsigned stack_nblocksy = 0; + + /* Calculate the size of a single slice. + */ + tex->stride = align(util_format_get_stride(pt->format, pt->width0), 4); + + /* XXX: hardware expects/requires 9 levels at minimum. + */ + for (level = 0; level <= MAX2(8, pt->last_level); level++) { + i915_texture_set_level_info(tex, level, depth); + + stack_nblocksy += MAX2(2, nblocksy); + + width = u_minify(width, 1); + height = u_minify(height, 1); + nblocksy = util_format_get_nblocksy(pt->format, height); + } + + /* Fixup depth image_offsets: + */ + for (level = 0; level <= pt->last_level; level++) { + unsigned i; + for (i = 0; i < depth; i++) + i915_texture_set_image_offset(tex, level, i, 0, i * stack_nblocksy); + + depth = u_minify(depth, 1); + } + + /* Multiply slice size by texture depth for total size. It's + * remarkable how wasteful of memory the i915 texture layouts + * are. They are largely fixed in the i945. + */ + tex->total_nblocksy = stack_nblocksy * pt->depth0; +} + +static boolean +i915_texture_layout(struct i915_texture * tex) +{ + struct pipe_resource *pt = &tex->b.b; + + tex->tiling = i915_texture_tiling(pt); + + switch (pt->target) { + case PIPE_TEXTURE_1D: + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + if (!i9x5_special_layout(tex)) + i915_texture_layout_2d(tex); + break; + case PIPE_TEXTURE_3D: + i915_texture_layout_3d(tex); + break; + case PIPE_TEXTURE_CUBE: + i9x5_texture_layout_cube(tex); + break; + default: + assert(0); + return FALSE; + } + + return TRUE; +} + + +/* + * i945 layout functions + */ + + +static void +i945_texture_layout_2d(struct i915_texture *tex) +{ + struct pipe_resource *pt = &tex->b.b; + int align_x = 4, align_y = 2; + unsigned level; + unsigned x = 0; + unsigned y = 0; + unsigned width = pt->width0; + unsigned height = pt->height0; + unsigned nblocksx = util_format_get_nblocksx(pt->format, pt->width0); + unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->height0); + + if (util_format_is_s3tc(pt->format)) { + align_x = 1; + align_y = 1; + } + + tex->stride = align(util_format_get_stride(pt->format, pt->width0), 4); + + /* May need to adjust pitch to accomodate the placement of + * the 2nd mipmap level. This occurs when the alignment + * constraints of mipmap placement push the right edge of the + * 2nd mipmap level out past the width of its parent. + */ + if (pt->last_level > 0) { + unsigned mip1_nblocksx = + align_nblocksx(pt->format, u_minify(pt->width0, 1), align_x) + + util_format_get_nblocksx(pt->format, u_minify(pt->width0, 2)); + + if (mip1_nblocksx > nblocksx) + tex->stride = mip1_nblocksx * util_format_get_blocksize(pt->format); + } + + /* Pitch must be a whole number of dwords + */ + tex->stride = align(tex->stride, 64); + tex->total_nblocksy = 0; + + for (level = 0; level <= pt->last_level; level++) { + i915_texture_set_level_info(tex, level, 1); + i915_texture_set_image_offset(tex, level, 0, x, y); + + /* Because the images are packed better, the final offset + * might not be the maximal one: + */ + tex->total_nblocksy = MAX2(tex->total_nblocksy, y + nblocksy); + + /* Layout_below: step right after second mipmap level. + */ + if (level == 1) { + x += nblocksx; + } else { + y += nblocksy; + } + + width = u_minify(width, 1); + height = u_minify(height, 1); + nblocksx = align_nblocksx(pt->format, width, align_x); + nblocksy = align_nblocksy(pt->format, height, align_y); + } +} + +static void +i945_texture_layout_3d(struct i915_texture *tex) +{ + struct pipe_resource *pt = &tex->b.b; + unsigned width = pt->width0; + unsigned height = pt->height0; + unsigned depth = pt->depth0; + unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->width0); + unsigned pack_x_pitch, pack_x_nr; + unsigned pack_y_pitch; + unsigned level; + + tex->stride = align(util_format_get_stride(pt->format, pt->width0), 4); + tex->total_nblocksy = 0; + + pack_y_pitch = MAX2(nblocksy, 2); + pack_x_pitch = tex->stride / util_format_get_blocksize(pt->format); + pack_x_nr = 1; + + for (level = 0; level <= pt->last_level; level++) { + int x = 0; + int y = 0; + unsigned q, j; + + i915_texture_set_level_info(tex, level, depth); + + for (q = 0; q < depth;) { + for (j = 0; j < pack_x_nr && q < depth; j++, q++) { + i915_texture_set_image_offset(tex, level, q, x, y + tex->total_nblocksy); + x += pack_x_pitch; + } + + x = 0; + y += pack_y_pitch; + } + + tex->total_nblocksy += y; + + if (pack_x_pitch > 4) { + pack_x_pitch >>= 1; + pack_x_nr <<= 1; + assert(pack_x_pitch * pack_x_nr * util_format_get_blocksize(pt->format) <= tex->stride); + } + + if (pack_y_pitch > 2) { + pack_y_pitch >>= 1; + } + + width = u_minify(width, 1); + height = u_minify(height, 1); + depth = u_minify(depth, 1); + nblocksy = util_format_get_nblocksy(pt->format, height); + } +} + +static void +i945_texture_layout_cube(struct i915_texture *tex) +{ + struct pipe_resource *pt = &tex->b.b; + const unsigned nblocks = util_format_get_nblocksx(pt->format, pt->width0); + const unsigned dim = pt->width0; + unsigned level; + unsigned face; + + assert(pt->width0 == pt->height0); /* cubemap images are square */ + assert(util_next_power_of_two(pt->width0) == pt->width0); /* npot only */ + assert(util_format_is_s3tc(pt->format)); /* compressed only */ + + /* + * Depending on the size of the largest images, pitch can be + * determined either by the old-style packing of cubemap faces, + * or the final row of 4x4, 2x2 and 1x1 faces below this. + * + * 64 * 2 / 4 = 32 + * 14 * 2 = 28 + */ + if (pt->width0 >= 64) + tex->stride = nblocks * 2 * util_format_get_blocksize(pt->format); + else + tex->stride = 14 * 2 * util_format_get_blocksize(pt->format); + + /* + * Something similary apply for height as well. + */ + if (pt->width0 >= 4) + tex->total_nblocksy = nblocks * 4 + 1; + else + tex->total_nblocksy = 1; + + /* Set all the levels to effectively occupy the whole rectangular region */ + for (level = 0; level <= pt->last_level; level++) + i915_texture_set_level_info(tex, level, 6); + + for (face = 0; face < 6; face++) { + /* all calculations in pixels */ + unsigned total_height = tex->total_nblocksy * 4; + unsigned x = initial_offsets[face][0] * dim; + unsigned y = initial_offsets[face][1] * dim; + unsigned d = dim; + + if (dim == 4 && face >= 4) { + x = (face - 4) * 8; + y = tex->total_nblocksy * 4 - 4; /* 4 = 1 block */ + } else if (dim < 4 && (face > 0)) { + x = face * 8; + y = total_height - 4; + } + + for (level = 0; level <= pt->last_level; level++) { + i915_texture_set_image_offset(tex, level, face, + util_format_get_nblocksx(pt->format, x), + util_format_get_nblocksy(pt->format, y)); + + d >>= 1; + + switch (d) { + case 4: + switch (face) { + case PIPE_TEX_FACE_POS_X: + case PIPE_TEX_FACE_NEG_X: + x += step_offsets[face][0] * d; + y += step_offsets[face][1] * d; + break; + case PIPE_TEX_FACE_POS_Y: + case PIPE_TEX_FACE_NEG_Y: + y += 12; + x -= 8; + break; + case PIPE_TEX_FACE_POS_Z: + case PIPE_TEX_FACE_NEG_Z: + y = total_height - 4; + x = (face - 4) * 8; + break; + } + break; + case 2: + y = total_height - 4; + x = bottom_offsets[face]; + break; + case 1: + x += 48; + break; + default: + x += step_offsets[face][0] * d; + y += step_offsets[face][1] * d; + break; + } + } + } +} + +static boolean +i945_texture_layout(struct i915_texture * tex) +{ + struct pipe_resource *pt = &tex->b.b; + + tex->tiling = i915_texture_tiling(pt); + + switch (pt->target) { + case PIPE_TEXTURE_1D: + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + if (!i9x5_special_layout(tex)) + i945_texture_layout_2d(tex); + break; + case PIPE_TEXTURE_3D: + i945_texture_layout_3d(tex); + break; + case PIPE_TEXTURE_CUBE: + if (!util_format_is_s3tc(pt->format)) + i9x5_texture_layout_cube(tex); + else + i945_texture_layout_cube(tex); + break; + default: + assert(0); + return FALSE; + } + + return TRUE; +} + + + +/* + * Screen texture functions + */ + + + +static boolean +i915_texture_get_handle(struct pipe_screen * screen, + struct pipe_resource *texture, + struct winsys_handle *whandle) +{ + struct i915_screen *is = i915_screen(screen); + struct i915_texture *tex = i915_texture(texture); + struct i915_winsys *iws = is->iws; + + return iws->buffer_get_handle(iws, tex->buffer, whandle, tex->stride); +} + + +static void +i915_texture_destroy(struct pipe_screen *screen, + struct pipe_resource *pt) +{ + struct i915_texture *tex = i915_texture(pt); + struct i915_winsys *iws = i915_screen(screen)->iws; + uint i; + + iws->buffer_destroy(iws, tex->buffer); + + for (i = 0; i < Elements(tex->image_offset); i++) + if (tex->image_offset[i]) + FREE(tex->image_offset[i]); + + FREE(tex); +} + +static struct pipe_transfer * +i915_texture_get_transfer(struct pipe_context *context, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct i915_texture *tex = i915_texture(resource); + struct pipe_transfer *transfer = CALLOC_STRUCT(pipe_transfer); + if (transfer == NULL) + return NULL; + + transfer->resource = resource; + transfer->level = level; + transfer->usage = usage; + transfer->box = *box; + transfer->stride = tex->stride; + /* FIXME: layer_stride */ + + return transfer; +} + +static void * +i915_texture_transfer_map(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct pipe_resource *resource = transfer->resource; + struct i915_texture *tex = i915_texture(resource); + struct i915_winsys *iws = i915_screen(pipe->screen)->iws; + struct pipe_box *box = &transfer->box; + enum pipe_format format = resource->format; + unsigned offset; + char *map; + + if (resource->target != PIPE_TEXTURE_3D && + resource->target != PIPE_TEXTURE_CUBE) + assert(box->z == 0); + offset = i915_texture_offset(tex, transfer->level, box->z); + + map = iws->buffer_map(iws, tex->buffer, + (transfer->usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE); + if (map == NULL) + return NULL; + + return map + offset + + box->y / util_format_get_blockheight(format) * transfer->stride + + box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); +} + +static void +i915_texture_transfer_unmap(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct i915_texture *tex = i915_texture(transfer->resource); + struct i915_winsys *iws = i915_screen(tex->b.b.screen)->iws; + iws->buffer_unmap(iws, tex->buffer); +} + + + +struct u_resource_vtbl i915_texture_vtbl = +{ + i915_texture_get_handle, /* get_handle */ + i915_texture_destroy, /* resource_destroy */ + NULL, /* is_resource_referenced */ + i915_texture_get_transfer, /* get_transfer */ + u_default_transfer_destroy, /* transfer_destroy */ + i915_texture_transfer_map, /* transfer_map */ + u_default_transfer_flush_region, /* transfer_flush_region */ + i915_texture_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; + + + + +struct pipe_resource * +i915_texture_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + struct i915_screen *is = i915_screen(screen); + struct i915_winsys *iws = is->iws; + struct i915_texture *tex = CALLOC_STRUCT(i915_texture); + unsigned buf_usage = 0; + + if (!tex) + return NULL; + + tex->b.b = *template; + tex->b.vtbl = &i915_texture_vtbl; + pipe_reference_init(&tex->b.b.reference, 1); + tex->b.b.screen = screen; + + if (is->is_i945) { + if (!i945_texture_layout(tex)) + goto fail; + } else { + if (!i915_texture_layout(tex)) + goto fail; + } + + /* for scanouts and cursors, cursors arn't scanouts */ + + /* XXX: use a custom flag for cursors, don't rely on magically + * guessing that this is Xorg asking for a cursor + */ + if ((template->bind & PIPE_BIND_SCANOUT) && template->width0 != 64) + buf_usage = I915_NEW_SCANOUT; + else + buf_usage = I915_NEW_TEXTURE; + + tex->buffer = iws->buffer_create_tiled(iws, &tex->stride, tex->total_nblocksy, + &tex->tiling, buf_usage); + if (!tex->buffer) + goto fail; + + I915_DBG(DBG_TEXTURE, "%s: %p stride %u, blocks (%u, %u) tiling %s\n", __func__, + tex, tex->stride, + tex->stride / util_format_get_blocksize(tex->b.b.format), + tex->total_nblocksy, get_tiling_string(tex->tiling)); + + return &tex->b.b; + +fail: + FREE(tex); + return NULL; +} + +struct pipe_resource * +i915_texture_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle) +{ + struct i915_screen *is = i915_screen(screen); + struct i915_texture *tex; + struct i915_winsys *iws = is->iws; + struct i915_winsys_buffer *buffer; + unsigned stride; + enum i915_winsys_buffer_tile tiling; + + assert(screen); + + buffer = iws->buffer_from_handle(iws, whandle, &tiling, &stride); + + /* Only supports one type */ + if ((template->target != PIPE_TEXTURE_2D && + template->target != PIPE_TEXTURE_RECT) || + template->last_level != 0 || + template->depth0 != 1) { + return NULL; + } + + tex = CALLOC_STRUCT(i915_texture); + if (!tex) + return NULL; + + tex->b.b = *template; + tex->b.vtbl = &i915_texture_vtbl; + pipe_reference_init(&tex->b.b.reference, 1); + tex->b.b.screen = screen; + + tex->stride = stride; + tex->tiling = tiling; + tex->total_nblocksy = align_nblocksy(tex->b.b.format, tex->b.b.height0, 8); + + i915_texture_set_level_info(tex, 0, 1); + i915_texture_set_image_offset(tex, 0, 0, 0, 0); + + tex->buffer = buffer; + + I915_DBG(DBG_TEXTURE, "%s: %p stride %u, blocks (%u, %u) tiling %s\n", __func__, + tex, tex->stride, + tex->stride / util_format_get_blocksize(tex->b.b.format), + tex->total_nblocksy, get_tiling_string(tex->tiling)); + + return &tex->b.b; +} + diff --git a/src/gallium/drivers/i915/i915_screen.c b/src/gallium/drivers/i915/i915_screen.c new file mode 100644 index 0000000..f66478e --- /dev/null +++ b/src/gallium/drivers/i915/i915_screen.c @@ -0,0 +1,394 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "draw/draw_context.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_string.h" + +#include "i915_reg.h" +#include "i915_debug.h" +#include "i915_context.h" +#include "i915_screen.h" +#include "i915_surface.h" +#include "i915_resource.h" +#include "i915_winsys.h" +#include "i915_public.h" + + +/* + * Probe functions + */ + + +static const char * +i915_get_vendor(struct pipe_screen *screen) +{ + return "VMware, Inc."; +} + +static const char * +i915_get_name(struct pipe_screen *screen) +{ + static char buffer[128]; + const char *chipset; + + switch (i915_screen(screen)->iws->pci_id) { + case PCI_CHIP_I915_G: + chipset = "915G"; + break; + case PCI_CHIP_I915_GM: + chipset = "915GM"; + break; + case PCI_CHIP_I945_G: + chipset = "945G"; + break; + case PCI_CHIP_I945_GM: + chipset = "945GM"; + break; + case PCI_CHIP_I945_GME: + chipset = "945GME"; + break; + case PCI_CHIP_G33_G: + chipset = "G33"; + break; + case PCI_CHIP_Q35_G: + chipset = "Q35"; + break; + case PCI_CHIP_Q33_G: + chipset = "Q33"; + break; + case PCI_CHIP_PINEVIEW_G: + chipset = "Pineview G"; + break; + case PCI_CHIP_PINEVIEW_M: + chipset = "Pineview M"; + break; + default: + chipset = "unknown"; + break; + } + + util_snprintf(buffer, sizeof(buffer), "i915 (chipset: %s)", chipset); + return buffer; +} + +static int +i915_get_param(struct pipe_screen *screen, enum pipe_cap param) +{ + switch (param) { + case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: + return 8; + case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS: + return 0; + case PIPE_CAP_MAX_COMBINED_SAMPLERS: + return 8; + case PIPE_CAP_NPOT_TEXTURES: + return 1; + case PIPE_CAP_TWO_SIDED_STENCIL: + return 1; + case PIPE_CAP_GLSL: + return 0; + case PIPE_CAP_ANISOTROPIC_FILTER: + return 0; + case PIPE_CAP_POINT_SPRITE: + return 0; + case PIPE_CAP_MAX_RENDER_TARGETS: + return 1; + case PIPE_CAP_OCCLUSION_QUERY: + return 0; + case PIPE_CAP_TIMER_QUERY: + return 0; + case PIPE_CAP_TEXTURE_SHADOW_MAP: + return 1; + case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: + return I915_MAX_TEXTURE_2D_LEVELS; + case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: + return I915_MAX_TEXTURE_3D_LEVELS; + case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: + return I915_MAX_TEXTURE_2D_LEVELS; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: + return 1; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: + return 0; + case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: + /* disable for now */ + return 0; + default: + return 0; + } +} + +static int +i915_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shader_cap param) +{ + switch(shader) { + case PIPE_SHADER_VERTEX: + return draw_get_shader_param(shader, param); + case PIPE_SHADER_FRAGMENT: + break; + default: + return 0; + } + + /* XXX: these are just shader model 2.0 values, fix this! */ + switch(param) { + case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: + return 96; + case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: + return 64; + case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: + return 32; + case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: + return 8; + case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: + return 0; + case PIPE_SHADER_CAP_MAX_INPUTS: + return 10; + case PIPE_SHADER_CAP_MAX_CONSTS: + return 32; + case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: + return 1; + case PIPE_SHADER_CAP_MAX_TEMPS: + return 12; /* XXX: 12 -> 32 ? */ + case PIPE_SHADER_CAP_MAX_ADDRS: + return 0; + case PIPE_SHADER_CAP_MAX_PREDS: + return 0; + case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: + return 0; + case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: + case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: + return 1; + case PIPE_SHADER_CAP_SUBROUTINES: + return 0; + default: + assert(0); + return 0; + } +} + +static float +i915_get_paramf(struct pipe_screen *screen, enum pipe_cap param) +{ + switch (param) { + case PIPE_CAP_MAX_LINE_WIDTH: + /* fall-through */ + case PIPE_CAP_MAX_LINE_WIDTH_AA: + return 7.5; + + case PIPE_CAP_MAX_POINT_WIDTH: + /* fall-through */ + case PIPE_CAP_MAX_POINT_WIDTH_AA: + return 255.0; + + case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: + return 4.0; + + case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: + return 16.0; + + default: + return 0; + } +} + +static boolean +i915_is_format_supported(struct pipe_screen *screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned tex_usage, + unsigned geom_flags) +{ + static const enum pipe_format tex_supported[] = { + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_B8G8R8X8_UNORM, + PIPE_FORMAT_B5G6R5_UNORM, + PIPE_FORMAT_L8_UNORM, + PIPE_FORMAT_A8_UNORM, + PIPE_FORMAT_I8_UNORM, + PIPE_FORMAT_L8A8_UNORM, + PIPE_FORMAT_UYVY, + PIPE_FORMAT_YUYV, + /* XXX why not? + PIPE_FORMAT_Z16_UNORM, */ + PIPE_FORMAT_Z24X8_UNORM, + PIPE_FORMAT_Z24_UNORM_S8_USCALED, + PIPE_FORMAT_NONE /* list terminator */ + }; + static const enum pipe_format render_supported[] = { + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_B5G6R5_UNORM, + PIPE_FORMAT_NONE /* list terminator */ + }; + static const enum pipe_format depth_supported[] = { + /* XXX why not? + PIPE_FORMAT_Z16_UNORM, */ + PIPE_FORMAT_Z24X8_UNORM, + PIPE_FORMAT_Z24_UNORM_S8_USCALED, + PIPE_FORMAT_NONE /* list terminator */ + }; + const enum pipe_format *list; + uint i; + + if (sample_count > 1) + return FALSE; + + if(tex_usage & PIPE_BIND_DEPTH_STENCIL) + list = depth_supported; + else if (tex_usage & PIPE_BIND_RENDER_TARGET) + list = render_supported; + else + list = tex_supported; + + for (i = 0; list[i] != PIPE_FORMAT_NONE; i++) { + if (list[i] == format) + return TRUE; + } + + return FALSE; +} + + +/* + * Fence functions + */ + + +static void +i915_fence_reference(struct pipe_screen *screen, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + struct i915_screen *is = i915_screen(screen); + + is->iws->fence_reference(is->iws, ptr, fence); +} + +static int +i915_fence_signalled(struct pipe_screen *screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + struct i915_screen *is = i915_screen(screen); + + return is->iws->fence_signalled(is->iws, fence); +} + +static int +i915_fence_finish(struct pipe_screen *screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + struct i915_screen *is = i915_screen(screen); + + return is->iws->fence_finish(is->iws, fence); +} + + +/* + * Generic functions + */ + + +static void +i915_destroy_screen(struct pipe_screen *screen) +{ + struct i915_screen *is = i915_screen(screen); + + if (is->iws) + is->iws->destroy(is->iws); + + FREE(is); +} + +/** + * Create a new i915_screen object + */ +struct pipe_screen * +i915_screen_create(struct i915_winsys *iws) +{ + struct i915_screen *is = CALLOC_STRUCT(i915_screen); + + if (!is) + return NULL; + + switch (iws->pci_id) { + case PCI_CHIP_I915_G: + case PCI_CHIP_I915_GM: + is->is_i945 = FALSE; + break; + + case PCI_CHIP_I945_G: + case PCI_CHIP_I945_GM: + case PCI_CHIP_I945_GME: + case PCI_CHIP_G33_G: + case PCI_CHIP_Q33_G: + case PCI_CHIP_Q35_G: + case PCI_CHIP_PINEVIEW_G: + case PCI_CHIP_PINEVIEW_M: + is->is_i945 = TRUE; + break; + + default: + debug_printf("%s: unknown pci id 0x%x, cannot create screen\n", + __FUNCTION__, iws->pci_id); + FREE(is); + return NULL; + } + + is->iws = iws; + + is->base.winsys = NULL; + + is->base.destroy = i915_destroy_screen; + + is->base.get_name = i915_get_name; + is->base.get_vendor = i915_get_vendor; + is->base.get_param = i915_get_param; + is->base.get_shader_param = i915_get_shader_param; + is->base.get_paramf = i915_get_paramf; + is->base.is_format_supported = i915_is_format_supported; + + is->base.context_create = i915_create_context; + + is->base.fence_reference = i915_fence_reference; + is->base.fence_signalled = i915_fence_signalled; + is->base.fence_finish = i915_fence_finish; + + i915_init_screen_resource_functions(is); + + i915_debug_init(is); + + return &is->base; +} diff --git a/src/gallium/drivers/i915/i915_screen.h b/src/gallium/drivers/i915/i915_screen.h new file mode 100644 index 0000000..0c4186c --- /dev/null +++ b/src/gallium/drivers/i915/i915_screen.h @@ -0,0 +1,79 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef I915_SCREEN_H +#define I915_SCREEN_H + +#include "pipe/p_state.h" +#include "pipe/p_screen.h" + + +struct i915_winsys; + + +/** + * Subclass of pipe_screen + */ +struct i915_screen +{ + struct pipe_screen base; + + struct i915_winsys *iws; + + boolean is_i945; +}; + +/** + * Subclass of pipe_transfer + */ +struct i915_transfer +{ + struct pipe_transfer base; + + unsigned offset; +}; + + +/* + * Cast wrappers + */ + + +static INLINE struct i915_screen * +i915_screen(struct pipe_screen *pscreen) +{ + return (struct i915_screen *) pscreen; +} + +static INLINE struct i915_transfer * +i915_transfer(struct pipe_transfer *transfer) +{ + return (struct i915_transfer *)transfer; +} + + +#endif /* I915_SCREEN_H */ diff --git a/src/gallium/drivers/i915/i915_state.c b/src/gallium/drivers/i915/i915_state.c new file mode 100644 index 0000000..bbfcff6 --- /dev/null +++ b/src/gallium/drivers/i915/i915_state.c @@ -0,0 +1,873 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + + +#include "draw/draw_context.h" +#include "util/u_inlines.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "tgsi/tgsi_parse.h" + +#include "i915_context.h" +#include "i915_reg.h" +#include "i915_state_inlines.h" +#include "i915_fpc.h" +#include "i915_resource.h" + +/* The i915 (and related graphics cores) do not support GL_CLAMP. The + * Intel drivers for "other operating systems" implement GL_CLAMP as + * GL_CLAMP_TO_EDGE, so the same is done here. + */ +static unsigned +translate_wrap_mode(unsigned wrap) +{ + switch (wrap) { + case PIPE_TEX_WRAP_REPEAT: + return TEXCOORDMODE_WRAP; + case PIPE_TEX_WRAP_CLAMP: + return TEXCOORDMODE_CLAMP_EDGE; /* not quite correct */ + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return TEXCOORDMODE_CLAMP_EDGE; + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + return TEXCOORDMODE_CLAMP_BORDER; + /* + case PIPE_TEX_WRAP_MIRRORED_REPEAT: + return TEXCOORDMODE_MIRROR; + */ + default: + return TEXCOORDMODE_WRAP; + } +} + +static unsigned translate_img_filter( unsigned filter ) +{ + switch (filter) { + case PIPE_TEX_FILTER_NEAREST: + return FILTER_NEAREST; + case PIPE_TEX_FILTER_LINEAR: + return FILTER_LINEAR; + default: + assert(0); + return FILTER_NEAREST; + } +} + +static unsigned translate_mip_filter( unsigned filter ) +{ + switch (filter) { + case PIPE_TEX_MIPFILTER_NONE: + return MIPFILTER_NONE; + case PIPE_TEX_MIPFILTER_NEAREST: + return MIPFILTER_NEAREST; + case PIPE_TEX_MIPFILTER_LINEAR: + return MIPFILTER_LINEAR; + default: + assert(0); + return MIPFILTER_NONE; + } +} + + +/* None of this state is actually used for anything yet. + */ +static void * +i915_create_blend_state(struct pipe_context *pipe, + const struct pipe_blend_state *blend) +{ + struct i915_blend_state *cso_data = CALLOC_STRUCT( i915_blend_state ); + + { + unsigned eqRGB = blend->rt[0].rgb_func; + unsigned srcRGB = blend->rt[0].rgb_src_factor; + unsigned dstRGB = blend->rt[0].rgb_dst_factor; + + unsigned eqA = blend->rt[0].alpha_func; + unsigned srcA = blend->rt[0].alpha_src_factor; + unsigned dstA = blend->rt[0].alpha_dst_factor; + + /* Special handling for MIN/MAX filter modes handled at + * state_tracker level. + */ + + if (srcA != srcRGB || + dstA != dstRGB || + eqA != eqRGB) { + + cso_data->iab = (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD | + IAB_MODIFY_ENABLE | + IAB_ENABLE | + IAB_MODIFY_FUNC | + IAB_MODIFY_SRC_FACTOR | + IAB_MODIFY_DST_FACTOR | + SRC_ABLND_FACT(i915_translate_blend_factor(srcA)) | + DST_ABLND_FACT(i915_translate_blend_factor(dstA)) | + (i915_translate_blend_func(eqA) << IAB_FUNC_SHIFT)); + } + else { + cso_data->iab = (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD | + IAB_MODIFY_ENABLE | + 0); + } + } + + cso_data->modes4 |= (_3DSTATE_MODES_4_CMD | + ENABLE_LOGIC_OP_FUNC | + LOGIC_OP_FUNC(i915_translate_logic_op(blend->logicop_func))); + + if (blend->logicop_enable) + cso_data->LIS5 |= S5_LOGICOP_ENABLE; + + if (blend->dither) + cso_data->LIS5 |= S5_COLOR_DITHER_ENABLE; + + if ((blend->rt[0].colormask & PIPE_MASK_R) == 0) + cso_data->LIS5 |= S5_WRITEDISABLE_RED; + + if ((blend->rt[0].colormask & PIPE_MASK_G) == 0) + cso_data->LIS5 |= S5_WRITEDISABLE_GREEN; + + if ((blend->rt[0].colormask & PIPE_MASK_B) == 0) + cso_data->LIS5 |= S5_WRITEDISABLE_BLUE; + + if ((blend->rt[0].colormask & PIPE_MASK_A) == 0) + cso_data->LIS5 |= S5_WRITEDISABLE_ALPHA; + + if (blend->rt[0].blend_enable) { + unsigned funcRGB = blend->rt[0].rgb_func; + unsigned srcRGB = blend->rt[0].rgb_src_factor; + unsigned dstRGB = blend->rt[0].rgb_dst_factor; + + cso_data->LIS6 |= (S6_CBUF_BLEND_ENABLE | + SRC_BLND_FACT(i915_translate_blend_factor(srcRGB)) | + DST_BLND_FACT(i915_translate_blend_factor(dstRGB)) | + (i915_translate_blend_func(funcRGB) << S6_CBUF_BLEND_FUNC_SHIFT)); + } + + return cso_data; +} + +static void i915_bind_blend_state(struct pipe_context *pipe, + void *blend) +{ + struct i915_context *i915 = i915_context(pipe); + draw_flush(i915->draw); + + i915->blend = (struct i915_blend_state*)blend; + + i915->dirty |= I915_NEW_BLEND; +} + + +static void i915_delete_blend_state(struct pipe_context *pipe, void *blend) +{ + FREE(blend); +} + +static void i915_set_blend_color( struct pipe_context *pipe, + const struct pipe_blend_color *blend_color ) +{ + struct i915_context *i915 = i915_context(pipe); + draw_flush(i915->draw); + + i915->blend_color = *blend_color; + + i915->dirty |= I915_NEW_BLEND; +} + +static void i915_set_stencil_ref( struct pipe_context *pipe, + const struct pipe_stencil_ref *stencil_ref ) +{ + struct i915_context *i915 = i915_context(pipe); + draw_flush(i915->draw); + + i915->stencil_ref = *stencil_ref; + + i915->dirty |= I915_NEW_DEPTH_STENCIL; +} + +static void * +i915_create_sampler_state(struct pipe_context *pipe, + const struct pipe_sampler_state *sampler) +{ + struct i915_sampler_state *cso = CALLOC_STRUCT( i915_sampler_state ); + const unsigned ws = sampler->wrap_s; + const unsigned wt = sampler->wrap_t; + const unsigned wr = sampler->wrap_r; + unsigned minFilt, magFilt; + unsigned mipFilt; + + cso->templ = sampler; + + mipFilt = translate_mip_filter(sampler->min_mip_filter); + minFilt = translate_img_filter( sampler->min_img_filter ); + magFilt = translate_img_filter( sampler->mag_img_filter ); + + if (sampler->max_anisotropy > 1) + minFilt = magFilt = FILTER_ANISOTROPIC; + + if (sampler->max_anisotropy > 2) { + cso->state[0] |= SS2_MAX_ANISO_4; + } + + { + int b = (int) (sampler->lod_bias * 16.0); + b = CLAMP(b, -256, 255); + cso->state[0] |= ((b << SS2_LOD_BIAS_SHIFT) & SS2_LOD_BIAS_MASK); + } + + /* Shadow: + */ + if (sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) + { + cso->state[0] |= (SS2_SHADOW_ENABLE | + i915_translate_compare_func(sampler->compare_func)); + + minFilt = FILTER_4X4_FLAT; + magFilt = FILTER_4X4_FLAT; + } + + cso->state[0] |= ((minFilt << SS2_MIN_FILTER_SHIFT) | + (mipFilt << SS2_MIP_FILTER_SHIFT) | + (magFilt << SS2_MAG_FILTER_SHIFT)); + + cso->state[1] |= + ((translate_wrap_mode(ws) << SS3_TCX_ADDR_MODE_SHIFT) | + (translate_wrap_mode(wt) << SS3_TCY_ADDR_MODE_SHIFT) | + (translate_wrap_mode(wr) << SS3_TCZ_ADDR_MODE_SHIFT)); + + if (sampler->normalized_coords) + cso->state[1] |= SS3_NORMALIZED_COORDS; + + { + int minlod = (int) (16.0 * sampler->min_lod); + int maxlod = (int) (16.0 * sampler->max_lod); + minlod = CLAMP(minlod, 0, 16 * 11); + maxlod = CLAMP(maxlod, 0, 16 * 11); + + if (minlod > maxlod) + maxlod = minlod; + + cso->minlod = minlod; + cso->maxlod = maxlod; + } + + { + ubyte r = float_to_ubyte(sampler->border_color[0]); + ubyte g = float_to_ubyte(sampler->border_color[1]); + ubyte b = float_to_ubyte(sampler->border_color[2]); + ubyte a = float_to_ubyte(sampler->border_color[3]); + cso->state[2] = I915PACKCOLOR8888(r, g, b, a); + } + return cso; +} + +static void i915_bind_sampler_states(struct pipe_context *pipe, + unsigned num, void **sampler) +{ + struct i915_context *i915 = i915_context(pipe); + unsigned i; + + /* Check for no-op */ + if (num == i915->num_samplers && + !memcmp(i915->sampler, sampler, num * sizeof(void *))) + return; + + draw_flush(i915->draw); + + for (i = 0; i < num; ++i) + i915->sampler[i] = sampler[i]; + for (i = num; i < PIPE_MAX_SAMPLERS; ++i) + i915->sampler[i] = NULL; + + i915->num_samplers = num; + + i915->dirty |= I915_NEW_SAMPLER; +} + +static void i915_delete_sampler_state(struct pipe_context *pipe, + void *sampler) +{ + FREE(sampler); +} + + +/** XXX move someday? Or consolidate all these simple state setters + * into one file. + */ + +static void * +i915_create_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_alpha_state *depth_stencil) +{ + struct i915_depth_stencil_state *cso = CALLOC_STRUCT( i915_depth_stencil_state ); + + { + int testmask = depth_stencil->stencil[0].valuemask & 0xff; + int writemask = depth_stencil->stencil[0].writemask & 0xff; + + cso->stencil_modes4 |= (_3DSTATE_MODES_4_CMD | + ENABLE_STENCIL_TEST_MASK | + STENCIL_TEST_MASK(testmask) | + ENABLE_STENCIL_WRITE_MASK | + STENCIL_WRITE_MASK(writemask)); + } + + if (depth_stencil->stencil[0].enabled) { + int test = i915_translate_compare_func(depth_stencil->stencil[0].func); + int fop = i915_translate_stencil_op(depth_stencil->stencil[0].fail_op); + int dfop = i915_translate_stencil_op(depth_stencil->stencil[0].zfail_op); + int dpop = i915_translate_stencil_op(depth_stencil->stencil[0].zpass_op); + + cso->stencil_LIS5 |= (S5_STENCIL_TEST_ENABLE | + S5_STENCIL_WRITE_ENABLE | + (test << S5_STENCIL_TEST_FUNC_SHIFT) | + (fop << S5_STENCIL_FAIL_SHIFT) | + (dfop << S5_STENCIL_PASS_Z_FAIL_SHIFT) | + (dpop << S5_STENCIL_PASS_Z_PASS_SHIFT)); + } + + if (depth_stencil->stencil[1].enabled) { + int test = i915_translate_compare_func(depth_stencil->stencil[1].func); + int fop = i915_translate_stencil_op(depth_stencil->stencil[1].fail_op); + int dfop = i915_translate_stencil_op(depth_stencil->stencil[1].zfail_op); + int dpop = i915_translate_stencil_op(depth_stencil->stencil[1].zpass_op); + int tmask = depth_stencil->stencil[1].valuemask & 0xff; + int wmask = depth_stencil->stencil[1].writemask & 0xff; + + cso->bfo[0] = (_3DSTATE_BACKFACE_STENCIL_OPS | + BFO_ENABLE_STENCIL_FUNCS | + BFO_ENABLE_STENCIL_TWO_SIDE | + BFO_ENABLE_STENCIL_REF | + BFO_STENCIL_TWO_SIDE | + (test << BFO_STENCIL_TEST_SHIFT) | + (fop << BFO_STENCIL_FAIL_SHIFT) | + (dfop << BFO_STENCIL_PASS_Z_FAIL_SHIFT) | + (dpop << BFO_STENCIL_PASS_Z_PASS_SHIFT)); + + cso->bfo[1] = (_3DSTATE_BACKFACE_STENCIL_MASKS | + BFM_ENABLE_STENCIL_TEST_MASK | + BFM_ENABLE_STENCIL_WRITE_MASK | + (tmask << BFM_STENCIL_TEST_MASK_SHIFT) | + (wmask << BFM_STENCIL_WRITE_MASK_SHIFT)); + } + else { + /* This actually disables two-side stencil: The bit set is a + * modify-enable bit to indicate we are changing the two-side + * setting. Then there is a symbolic zero to show that we are + * setting the flag to zero/off. + */ + cso->bfo[0] = (_3DSTATE_BACKFACE_STENCIL_OPS | + BFO_ENABLE_STENCIL_TWO_SIDE | + 0); + cso->bfo[1] = 0; + } + + if (depth_stencil->depth.enabled) { + int func = i915_translate_compare_func(depth_stencil->depth.func); + + cso->depth_LIS6 |= (S6_DEPTH_TEST_ENABLE | + (func << S6_DEPTH_TEST_FUNC_SHIFT)); + + if (depth_stencil->depth.writemask) + cso->depth_LIS6 |= S6_DEPTH_WRITE_ENABLE; + } + + if (depth_stencil->alpha.enabled) { + int test = i915_translate_compare_func(depth_stencil->alpha.func); + ubyte refByte = float_to_ubyte(depth_stencil->alpha.ref_value); + + cso->depth_LIS6 |= (S6_ALPHA_TEST_ENABLE | + (test << S6_ALPHA_TEST_FUNC_SHIFT) | + (((unsigned) refByte) << S6_ALPHA_REF_SHIFT)); + } + + return cso; +} + +static void i915_bind_depth_stencil_state(struct pipe_context *pipe, + void *depth_stencil) +{ + struct i915_context *i915 = i915_context(pipe); + draw_flush(i915->draw); + + i915->depth_stencil = (const struct i915_depth_stencil_state *)depth_stencil; + + i915->dirty |= I915_NEW_DEPTH_STENCIL; +} + +static void i915_delete_depth_stencil_state(struct pipe_context *pipe, + void *depth_stencil) +{ + FREE(depth_stencil); +} + + +static void i915_set_scissor_state( struct pipe_context *pipe, + const struct pipe_scissor_state *scissor ) +{ + struct i915_context *i915 = i915_context(pipe); + draw_flush(i915->draw); + + memcpy( &i915->scissor, scissor, sizeof(*scissor) ); + i915->dirty |= I915_NEW_SCISSOR; +} + + +static void i915_set_polygon_stipple( struct pipe_context *pipe, + const struct pipe_poly_stipple *stipple ) +{ +} + + + +static void * +i915_create_fs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct i915_context *i915 = i915_context(pipe); + struct i915_fragment_shader *ifs = CALLOC_STRUCT(i915_fragment_shader); + if (!ifs) + return NULL; + + ifs->state.tokens = tgsi_dup_tokens(templ->tokens); + + tgsi_scan_shader(templ->tokens, &ifs->info); + + /* The shader's compiled to i915 instructions here */ + i915_translate_fragment_program(i915, ifs); + + return ifs; +} + +static void +i915_bind_fs_state(struct pipe_context *pipe, void *shader) +{ + struct i915_context *i915 = i915_context(pipe); + draw_flush(i915->draw); + + i915->fs = (struct i915_fragment_shader*) shader; + + i915->dirty |= I915_NEW_FS; +} + +static +void i915_delete_fs_state(struct pipe_context *pipe, void *shader) +{ + struct i915_fragment_shader *ifs = (struct i915_fragment_shader *) shader; + + if (ifs->program) + FREE(ifs->program); + ifs->program_len = 0; + + FREE((struct tgsi_token *)ifs->state.tokens); + + FREE(ifs); +} + + +static void * +i915_create_vs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct i915_context *i915 = i915_context(pipe); + + /* just pass-through to draw module */ + return draw_create_vertex_shader(i915->draw, templ); +} + +static void i915_bind_vs_state(struct pipe_context *pipe, void *shader) +{ + struct i915_context *i915 = i915_context(pipe); + + /* just pass-through to draw module */ + draw_bind_vertex_shader(i915->draw, (struct draw_vertex_shader *) shader); + + i915->dirty |= I915_NEW_VS; +} + +static void i915_delete_vs_state(struct pipe_context *pipe, void *shader) +{ + struct i915_context *i915 = i915_context(pipe); + + /* just pass-through to draw module */ + draw_delete_vertex_shader(i915->draw, (struct draw_vertex_shader *) shader); +} + +static void i915_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + struct pipe_resource *buf) +{ + struct i915_context *i915 = i915_context(pipe); + draw_flush(i915->draw); + + /* Make a copy of shader constants. + * During fragment program translation we may add additional + * constants to the array. + * + * We want to consider the situation where some user constants + * (ex: a material color) may change frequently but the shader program + * stays the same. In that case we should only be updating the first + * N constants, leaving any extras from shader translation alone. + */ + if (buf) { + struct i915_buffer *ir = i915_buffer(buf); + memcpy(i915->current.constants[shader], ir->data, ir->b.b.width0); + i915->current.num_user_constants[shader] = (ir->b.b.width0 / + 4 * sizeof(float)); + } + else { + i915->current.num_user_constants[shader] = 0; + } + + + i915->dirty |= I915_NEW_CONSTANTS; +} + + +static void i915_set_fragment_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct i915_context *i915 = i915_context(pipe); + uint i; + + assert(num <= PIPE_MAX_SAMPLERS); + + /* Check for no-op */ + if (num == i915->num_fragment_sampler_views && + !memcmp(i915->fragment_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) + return; + + /* Fixes wrong texture in texobj with VBUF */ + draw_flush(i915->draw); + + for (i = 0; i < num; i++) + pipe_sampler_view_reference(&i915->fragment_sampler_views[i], + views[i]); + + for (i = num; i < i915->num_fragment_sampler_views; i++) + pipe_sampler_view_reference(&i915->fragment_sampler_views[i], + NULL); + + i915->num_fragment_sampler_views = num; + + i915->dirty |= I915_NEW_SAMPLER_VIEW; +} + + +static struct pipe_sampler_view * +i915_create_sampler_view(struct pipe_context *pipe, + struct pipe_resource *texture, + const struct pipe_sampler_view *templ) +{ + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_resource_reference(&view->texture, texture); + view->context = pipe; + } + + return view; +} + + +static void +i915_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_resource_reference(&view->texture, NULL); + FREE(view); +} + + +static void i915_set_framebuffer_state(struct pipe_context *pipe, + const struct pipe_framebuffer_state *fb) +{ + struct i915_context *i915 = i915_context(pipe); + int i; + + draw_flush(i915->draw); + + i915->framebuffer.width = fb->width; + i915->framebuffer.height = fb->height; + i915->framebuffer.nr_cbufs = fb->nr_cbufs; + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + pipe_surface_reference(&i915->framebuffer.cbufs[i], fb->cbufs[i]); + } + pipe_surface_reference(&i915->framebuffer.zsbuf, fb->zsbuf); + + i915->dirty |= I915_NEW_FRAMEBUFFER; +} + + + +static void i915_set_clip_state( struct pipe_context *pipe, + const struct pipe_clip_state *clip ) +{ + struct i915_context *i915 = i915_context(pipe); + draw_flush(i915->draw); + + draw_set_clip_state(i915->draw, clip); + + i915->dirty |= I915_NEW_CLIP; +} + + + +/* Called when driver state tracker notices changes to the viewport + * matrix: + */ +static void i915_set_viewport_state( struct pipe_context *pipe, + const struct pipe_viewport_state *viewport ) +{ + struct i915_context *i915 = i915_context(pipe); + + i915->viewport = *viewport; /* struct copy */ + + /* pass the viewport info to the draw module */ + draw_set_viewport_state(i915->draw, &i915->viewport); + + i915->dirty |= I915_NEW_VIEWPORT; +} + + +static void * +i915_create_rasterizer_state(struct pipe_context *pipe, + const struct pipe_rasterizer_state *rasterizer) +{ + struct i915_rasterizer_state *cso = CALLOC_STRUCT( i915_rasterizer_state ); + + cso->templ = rasterizer; + cso->color_interp = rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR; + cso->light_twoside = rasterizer->light_twoside; + cso->ds[0].u = _3DSTATE_DEPTH_OFFSET_SCALE; + cso->ds[1].f = rasterizer->offset_scale; + if (rasterizer->poly_stipple_enable) { + cso->st |= ST1_ENABLE; + } + + if (rasterizer->scissor) + cso->sc[0] = _3DSTATE_SCISSOR_ENABLE_CMD | ENABLE_SCISSOR_RECT; + else + cso->sc[0] = _3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT; + + switch (rasterizer->cull_face) { + case PIPE_FACE_NONE: + cso->LIS4 |= S4_CULLMODE_NONE; + break; + case PIPE_FACE_FRONT: + if (rasterizer->front_ccw) + cso->LIS4 |= S4_CULLMODE_CCW; + else + cso->LIS4 |= S4_CULLMODE_CW; + break; + case PIPE_FACE_BACK: + if (rasterizer->front_ccw) + cso->LIS4 |= S4_CULLMODE_CW; + else + cso->LIS4 |= S4_CULLMODE_CCW; + break; + case PIPE_FACE_FRONT_AND_BACK: + cso->LIS4 |= S4_CULLMODE_BOTH; + break; + } + + { + int line_width = CLAMP((int)(rasterizer->line_width * 2), 1, 0xf); + + cso->LIS4 |= line_width << S4_LINE_WIDTH_SHIFT; + + if (rasterizer->line_smooth) + cso->LIS4 |= S4_LINE_ANTIALIAS_ENABLE; + } + + { + int point_size = CLAMP((int) rasterizer->point_size, 1, 0xff); + + cso->LIS4 |= point_size << S4_POINT_WIDTH_SHIFT; + } + + if (rasterizer->flatshade) { + cso->LIS4 |= (S4_FLATSHADE_ALPHA | + S4_FLATSHADE_COLOR | + S4_FLATSHADE_SPECULAR); + } + + cso->LIS7 = fui( rasterizer->offset_units ); + + + return cso; +} + +static void i915_bind_rasterizer_state( struct pipe_context *pipe, + void *raster ) +{ + struct i915_context *i915 = i915_context(pipe); + + i915->rasterizer = (struct i915_rasterizer_state *)raster; + + /* pass-through to draw module */ + draw_set_rasterizer_state(i915->draw, + (i915->rasterizer ? i915->rasterizer->templ : NULL), + raster); + + i915->dirty |= I915_NEW_RASTERIZER; +} + +static void i915_delete_rasterizer_state(struct pipe_context *pipe, + void *raster) +{ + FREE(raster); +} + +static void i915_set_vertex_buffers(struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_buffer *buffers) +{ + struct i915_context *i915 = i915_context(pipe); + /* Because we change state before the draw_set_vertex_buffers call + * we need a flush here, just to be sure. + */ + draw_flush(i915->draw); + + memcpy(i915->vertex_buffer, buffers, count * sizeof(buffers[0])); + i915->num_vertex_buffers = count; + + /* pass-through to draw module */ + draw_set_vertex_buffers(i915->draw, count, buffers); +} + +static void * +i915_create_vertex_elements_state(struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_element *attribs) +{ + struct i915_velems_state *velems; + assert(count <= PIPE_MAX_ATTRIBS); + velems = (struct i915_velems_state *) MALLOC(sizeof(struct i915_velems_state)); + if (velems) { + velems->count = count; + memcpy(velems->velem, attribs, sizeof(*attribs) * count); + } + return velems; +} + +static void +i915_bind_vertex_elements_state(struct pipe_context *pipe, + void *velems) +{ + struct i915_context *i915 = i915_context(pipe); + struct i915_velems_state *i915_velems = (struct i915_velems_state *) velems; + + /* Because we change state before the draw_set_vertex_buffers call + * we need a flush here, just to be sure. + */ + draw_flush(i915->draw); + + /* pass-through to draw module */ + if (i915_velems) { + draw_set_vertex_elements(i915->draw, + i915_velems->count, i915_velems->velem); + } +} + +static void +i915_delete_vertex_elements_state(struct pipe_context *pipe, void *velems) +{ + FREE( velems ); +} + +static void i915_set_index_buffer(struct pipe_context *pipe, + const struct pipe_index_buffer *ib) +{ + struct i915_context *i915 = i915_context(pipe); + + if (ib) + memcpy(&i915->index_buffer, ib, sizeof(i915->index_buffer)); + else + memset(&i915->index_buffer, 0, sizeof(i915->index_buffer)); + + /* pass-through to draw module */ + draw_set_index_buffer(i915->draw, ib); +} + +static void +i915_set_sample_mask(struct pipe_context *pipe, + unsigned sample_mask) +{ +} + +void +i915_init_state_functions( struct i915_context *i915 ) +{ + i915->base.create_blend_state = i915_create_blend_state; + i915->base.bind_blend_state = i915_bind_blend_state; + i915->base.delete_blend_state = i915_delete_blend_state; + + i915->base.create_sampler_state = i915_create_sampler_state; + i915->base.bind_fragment_sampler_states = i915_bind_sampler_states; + i915->base.delete_sampler_state = i915_delete_sampler_state; + + i915->base.create_depth_stencil_alpha_state = i915_create_depth_stencil_state; + i915->base.bind_depth_stencil_alpha_state = i915_bind_depth_stencil_state; + i915->base.delete_depth_stencil_alpha_state = i915_delete_depth_stencil_state; + + i915->base.create_rasterizer_state = i915_create_rasterizer_state; + i915->base.bind_rasterizer_state = i915_bind_rasterizer_state; + i915->base.delete_rasterizer_state = i915_delete_rasterizer_state; + i915->base.create_fs_state = i915_create_fs_state; + i915->base.bind_fs_state = i915_bind_fs_state; + i915->base.delete_fs_state = i915_delete_fs_state; + i915->base.create_vs_state = i915_create_vs_state; + i915->base.bind_vs_state = i915_bind_vs_state; + i915->base.delete_vs_state = i915_delete_vs_state; + i915->base.create_vertex_elements_state = i915_create_vertex_elements_state; + i915->base.bind_vertex_elements_state = i915_bind_vertex_elements_state; + i915->base.delete_vertex_elements_state = i915_delete_vertex_elements_state; + + i915->base.set_blend_color = i915_set_blend_color; + i915->base.set_stencil_ref = i915_set_stencil_ref; + i915->base.set_clip_state = i915_set_clip_state; + i915->base.set_sample_mask = i915_set_sample_mask; + i915->base.set_constant_buffer = i915_set_constant_buffer; + i915->base.set_framebuffer_state = i915_set_framebuffer_state; + + i915->base.set_polygon_stipple = i915_set_polygon_stipple; + i915->base.set_scissor_state = i915_set_scissor_state; + i915->base.set_fragment_sampler_views = i915_set_fragment_sampler_views; + i915->base.create_sampler_view = i915_create_sampler_view; + i915->base.sampler_view_destroy = i915_sampler_view_destroy; + i915->base.set_viewport_state = i915_set_viewport_state; + i915->base.set_vertex_buffers = i915_set_vertex_buffers; + i915->base.set_index_buffer = i915_set_index_buffer; +} diff --git a/src/gallium/drivers/i915/i915_state.h b/src/gallium/drivers/i915/i915_state.h new file mode 100644 index 0000000..b4074dc --- /dev/null +++ b/src/gallium/drivers/i915/i915_state.h @@ -0,0 +1,56 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef I915_STATE_H +#define I915_STATE_H + +struct i915_context; + + +struct i915_tracked_state { + const char *name; + void (*update)(struct i915_context *); + unsigned dirty; +}; + +extern struct i915_tracked_state i915_update_vertex_layout; + +extern struct i915_tracked_state i915_hw_samplers; +extern struct i915_tracked_state i915_hw_sampler_views; +extern struct i915_tracked_state i915_hw_immediate; +extern struct i915_tracked_state i915_hw_dynamic; +extern struct i915_tracked_state i915_hw_fs; +extern struct i915_tracked_state i915_hw_framebuffer; +extern struct i915_tracked_state i915_hw_constants; + +void i915_update_derived(struct i915_context *i915); +void i915_emit_hardware_state(struct i915_context *i915); + +#endif diff --git a/src/gallium/drivers/i915/i915_state_derived.c b/src/gallium/drivers/i915/i915_state_derived.c new file mode 100644 index 0000000..1d4026a --- /dev/null +++ b/src/gallium/drivers/i915/i915_state_derived.c @@ -0,0 +1,184 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + + +#include "util/u_memory.h" +#include "pipe/p_shader_tokens.h" +#include "draw/draw_context.h" +#include "draw/draw_vertex.h" +#include "i915_context.h" +#include "i915_state.h" +#include "i915_debug.h" +#include "i915_reg.h" + + + +/*********************************************************************** + * Determine the hardware vertex layout. + * Depends on vertex/fragment shader state. + */ +static void calculate_vertex_layout(struct i915_context *i915) +{ + const struct i915_fragment_shader *fs = i915->fs; + const enum interp_mode colorInterp = i915->rasterizer->color_interp; + struct vertex_info vinfo; + boolean texCoords[8], colors[2], fog, needW; + uint i; + int src; + + memset(texCoords, 0, sizeof(texCoords)); + colors[0] = colors[1] = fog = needW = FALSE; + memset(&vinfo, 0, sizeof(vinfo)); + + /* Determine which fragment program inputs are needed. Setup HW vertex + * layout below, in the HW-specific attribute order. + */ + for (i = 0; i < fs->info.num_inputs; i++) { + switch (fs->info.input_semantic_name[i]) { + case TGSI_SEMANTIC_POSITION: + break; + case TGSI_SEMANTIC_COLOR: + assert(fs->info.input_semantic_index[i] < 2); + colors[fs->info.input_semantic_index[i]] = TRUE; + break; + case TGSI_SEMANTIC_GENERIC: + /* usually a texcoord */ + { + const uint unit = fs->info.input_semantic_index[i]; + assert(unit < 8); + texCoords[unit] = TRUE; + needW = TRUE; + } + break; + case TGSI_SEMANTIC_FOG: + fog = TRUE; + break; + default: + assert(0); + } + } + + + /* pos */ + src = draw_find_shader_output(i915->draw, TGSI_SEMANTIC_POSITION, 0); + if (needW) { + draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_LINEAR, src); + vinfo.hwfmt[0] |= S4_VFMT_XYZW; + vinfo.attrib[0].emit = EMIT_4F; + } + else { + draw_emit_vertex_attr(&vinfo, EMIT_3F, INTERP_LINEAR, src); + vinfo.hwfmt[0] |= S4_VFMT_XYZ; + vinfo.attrib[0].emit = EMIT_3F; + } + + /* hardware point size */ + /* XXX todo */ + + /* primary color */ + if (colors[0]) { + src = draw_find_shader_output(i915->draw, TGSI_SEMANTIC_COLOR, 0); + draw_emit_vertex_attr(&vinfo, EMIT_4UB_BGRA, colorInterp, src); + vinfo.hwfmt[0] |= S4_VFMT_COLOR; + } + + /* secondary color */ + if (colors[1]) { + src = draw_find_shader_output(i915->draw, TGSI_SEMANTIC_COLOR, 1); + draw_emit_vertex_attr(&vinfo, EMIT_4UB_BGRA, colorInterp, src); + vinfo.hwfmt[0] |= S4_VFMT_SPEC_FOG; + } + + /* fog coord, not fog blend factor */ + if (fog) { + src = draw_find_shader_output(i915->draw, TGSI_SEMANTIC_FOG, 0); + draw_emit_vertex_attr(&vinfo, EMIT_1F, INTERP_PERSPECTIVE, src); + vinfo.hwfmt[0] |= S4_VFMT_FOG_PARAM; + } + + /* texcoords */ + for (i = 0; i < 8; i++) { + uint hwtc; + if (texCoords[i]) { + hwtc = TEXCOORDFMT_4D; + src = draw_find_shader_output(i915->draw, TGSI_SEMANTIC_GENERIC, i); + draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, src); + } + else { + hwtc = TEXCOORDFMT_NOT_PRESENT; + } + vinfo.hwfmt[1] |= hwtc << (i * 4); + } + + draw_compute_vertex_size(&vinfo); + + if (memcmp(&i915->current.vertex_info, &vinfo, sizeof(vinfo))) { + /* Need to set this flag so that the LIS2/4 registers get set. + * It also means the i915_update_immediate() function must be called + * after this one, in i915_update_derived(). + */ + i915->dirty |= I915_NEW_VERTEX_FORMAT; + + memcpy(&i915->current.vertex_info, &vinfo, sizeof(vinfo)); + } +} + +struct i915_tracked_state i915_update_vertex_layout = { + "vertex_layout", + calculate_vertex_layout, + I915_NEW_RASTERIZER | I915_NEW_FS | I915_NEW_VS +}; + + + +/*********************************************************************** + */ +static struct i915_tracked_state *atoms[] = { + &i915_update_vertex_layout, + &i915_hw_samplers, + &i915_hw_sampler_views, + &i915_hw_immediate, + &i915_hw_dynamic, + &i915_hw_fs, + &i915_hw_framebuffer, + &i915_hw_constants, + NULL, +}; + +void i915_update_derived(struct i915_context *i915) +{ + int i; + + if (I915_DBG_ON(DBG_ATOMS)) + i915_dump_dirty(i915, __FUNCTION__); + + for (i = 0; atoms[i]; i++) + if (atoms[i]->dirty & i915->dirty) + atoms[i]->update(i915); + + i915->dirty = 0; +} diff --git a/src/gallium/drivers/i915/i915_state_dynamic.c b/src/gallium/drivers/i915/i915_state_dynamic.c new file mode 100644 index 0000000..d61a8c3 --- /dev/null +++ b/src/gallium/drivers/i915/i915_state_dynamic.c @@ -0,0 +1,328 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + +#include "i915_batch.h" +#include "i915_state_inlines.h" +#include "i915_context.h" +#include "i915_reg.h" +#include "i915_state.h" + +#include "util/u_memory.h" +#include "util/u_pack_color.h" + + +/* State that we have chosen to store in the DYNAMIC segment of the + * i915 indirect state mechanism. + * + * Can't cache these in the way we do the static state, as there is no + * start/size in the command packet, instead an 'end' value that gets + * incremented. + * + * Additionally, there seems to be a requirement to re-issue the full + * (active) state every time a 4kb boundary is crossed. + */ + +static INLINE void set_dynamic_indirect(struct i915_context *i915, + unsigned offset, + const unsigned *src, + unsigned dwords) +{ + unsigned i; + + if (!memcmp(src, &i915->current.dynamic[offset], dwords * 4)) + return; + + for (i = 0; i < dwords; i++) + i915->current.dynamic[offset + i] = src[i]; + + i915->hardware_dirty |= I915_HW_DYNAMIC; +} + + + +/*********************************************************************** + * Modes4: stencil masks and logicop + */ +static void upload_MODES4(struct i915_context *i915) +{ + unsigned modes4 = 0; + + /* I915_NEW_STENCIL + */ + modes4 |= i915->depth_stencil->stencil_modes4; + + /* I915_NEW_BLEND + */ + modes4 |= i915->blend->modes4; + + /* Always, so that we know when state is in-active: + */ + set_dynamic_indirect(i915, + I915_DYNAMIC_MODES4, + &modes4, + 1); +} + +const struct i915_tracked_state i915_upload_MODES4 = { + "MODES4", + upload_MODES4, + I915_NEW_BLEND | I915_NEW_DEPTH_STENCIL +}; + + + +/*********************************************************************** + */ +static void upload_BFO(struct i915_context *i915) +{ + unsigned bfo[2]; + bfo[0] = i915->depth_stencil->bfo[0]; + bfo[1] = i915->depth_stencil->bfo[1]; + /* I don't get it only allowed to set a ref mask when the enable bit is set? */ + if (bfo[0] & BFO_ENABLE_STENCIL_REF) { + bfo[0] |= i915->stencil_ref.ref_value[1] << BFO_STENCIL_REF_SHIFT; + } + + set_dynamic_indirect(i915, + I915_DYNAMIC_BFO_0, + &(bfo[0]), + 2); +} + +const struct i915_tracked_state i915_upload_BFO = { + "BFO", + upload_BFO, + I915_NEW_DEPTH_STENCIL +}; + + + +/*********************************************************************** + */ +static void upload_BLENDCOLOR(struct i915_context *i915) +{ + unsigned bc[2]; + + memset(bc, 0, sizeof(bc)); + + /* I915_NEW_BLEND + */ + { + const float *color = i915->blend_color.color; + + bc[0] = _3DSTATE_CONST_BLEND_COLOR_CMD; + bc[1] = pack_ui32_float4(color[0], + color[1], + color[2], + color[3]); + } + + set_dynamic_indirect(i915, + I915_DYNAMIC_BC_0, + bc, + 2); +} + +const struct i915_tracked_state i915_upload_BLENDCOLOR = { + "BLENDCOLOR", + upload_BLENDCOLOR, + I915_NEW_BLEND +}; + + + +/*********************************************************************** + */ +static void upload_IAB(struct i915_context *i915) +{ + unsigned iab = i915->blend->iab; + + set_dynamic_indirect(i915, + I915_DYNAMIC_IAB, + &iab, + 1); +} + +const struct i915_tracked_state i915_upload_IAB = { + "IAB", + upload_IAB, + I915_NEW_BLEND +}; + + + +/*********************************************************************** + */ +static void upload_DEPTHSCALE(struct i915_context *i915) +{ + set_dynamic_indirect(i915, + I915_DYNAMIC_DEPTHSCALE_0, + &(i915->rasterizer->ds[0].u), + 2); +} + +const struct i915_tracked_state i915_upload_DEPTHSCALE = { + "DEPTHSCALE", + upload_DEPTHSCALE, + I915_NEW_RASTERIZER +}; + + + +/*********************************************************************** + * Polygon stipple + * + * The i915 supports a 4x4 stipple natively, GL wants 32x32. + * Fortunately stipple is usually a repeating pattern. + * + * XXX: does stipple pattern need to be adjusted according to + * the window position? + * + * XXX: possibly need workaround for conform paths test. + */ +static void upload_STIPPLE(struct i915_context *i915) +{ + unsigned st[2]; + + st[0] = _3DSTATE_STIPPLE; + st[1] = 0; + + /* I915_NEW_RASTERIZER + */ + st[1] |= i915->rasterizer->st; + + /* I915_NEW_STIPPLE + */ + { + const ubyte *mask = (const ubyte *)i915->poly_stipple.stipple; + ubyte p[4]; + + p[0] = mask[12] & 0xf; + p[1] = mask[8] & 0xf; + p[2] = mask[4] & 0xf; + p[3] = mask[0] & 0xf; + + /* Not sure what to do about fallbacks, so for now just dont: + */ + st[1] |= ((p[0] << 0) | + (p[1] << 4) | + (p[2] << 8) | + (p[3] << 12)); + } + + set_dynamic_indirect(i915, + I915_DYNAMIC_STP_0, + &st[0], + 2); +} + +const struct i915_tracked_state i915_upload_STIPPLE = { + "STIPPLE", + upload_STIPPLE, + I915_NEW_RASTERIZER | I915_NEW_STIPPLE +}; + + + +/*********************************************************************** + * Scissor enable + */ +static void upload_SCISSOR_ENABLE( struct i915_context *i915 ) +{ + set_dynamic_indirect(i915, + I915_DYNAMIC_SC_ENA_0, + &(i915->rasterizer->sc[0]), + 1); +} + +const struct i915_tracked_state i915_upload_SCISSOR_ENABLE = { + "SCISSOR ENABLE", + upload_SCISSOR_ENABLE, + I915_NEW_RASTERIZER +}; + + + +/*********************************************************************** + * Scissor rect + */ +static void upload_SCISSOR_RECT(struct i915_context *i915) +{ + unsigned x1 = i915->scissor.minx; + unsigned y1 = i915->scissor.miny; + unsigned x2 = i915->scissor.maxx; + unsigned y2 = i915->scissor.maxy; + unsigned sc[3]; + + sc[0] = _3DSTATE_SCISSOR_RECT_0_CMD; + sc[1] = (y1 << 16) | (x1 & 0xffff); + sc[2] = (y2 << 16) | (x2 & 0xffff); + + set_dynamic_indirect(i915, + I915_DYNAMIC_SC_RECT_0, + &sc[0], + 3); +} + +const struct i915_tracked_state i915_upload_SCISSOR_RECT = { + "SCISSOR RECT", + upload_SCISSOR_RECT, + I915_NEW_SCISSOR +}; + + + +/*********************************************************************** + */ +static const struct i915_tracked_state *atoms[] = { + &i915_upload_MODES4, + &i915_upload_BFO, + &i915_upload_BLENDCOLOR, + &i915_upload_IAB, + &i915_upload_DEPTHSCALE, + &i915_upload_STIPPLE, + &i915_upload_SCISSOR_ENABLE, + &i915_upload_SCISSOR_RECT +}; + +/* These will be dynamic indirect state commands, but for now just end + * up on the batch buffer with everything else. + */ +static void update_dynamic(struct i915_context *i915) +{ + int i; + + for (i = 0; i < Elements(atoms); i++) + if (i915->dirty & atoms[i]->dirty) + atoms[i]->update(i915); +} + +struct i915_tracked_state i915_hw_dynamic = { + "dynamic", + update_dynamic, + ~0 /* all state atoms, becuase we do internal checking */ +}; diff --git a/src/gallium/drivers/i915/i915_state_emit.c b/src/gallium/drivers/i915/i915_state_emit.c new file mode 100644 index 0000000..c48d53f --- /dev/null +++ b/src/gallium/drivers/i915/i915_state_emit.c @@ -0,0 +1,445 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + + +#include "i915_reg.h" +#include "i915_context.h" +#include "i915_batch.h" +#include "i915_debug.h" +#include "i915_resource.h" + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" + +static unsigned translate_format( enum pipe_format format ) +{ + switch (format) { + case PIPE_FORMAT_B8G8R8A8_UNORM: + return COLOR_BUF_ARGB8888; + case PIPE_FORMAT_B5G6R5_UNORM: + return COLOR_BUF_RGB565; + default: + assert(0); + return 0; + } +} + +static unsigned translate_depth_format( enum pipe_format zformat ) +{ + switch (zformat) { + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + return DEPTH_FRMT_24_FIXED_8_OTHER; + case PIPE_FORMAT_Z16_UNORM: + return DEPTH_FRMT_16_FIXED; + default: + assert(0); + return 0; + } +} + + +/** + * Examine framebuffer state to determine width, height. + */ +static boolean +framebuffer_size(const struct pipe_framebuffer_state *fb, + uint *width, uint *height) +{ + if (fb->cbufs[0]) { + *width = fb->cbufs[0]->width; + *height = fb->cbufs[0]->height; + return TRUE; + } + else if (fb->zsbuf) { + *width = fb->zsbuf->width; + *height = fb->zsbuf->height; + return TRUE; + } + else { + *width = *height = 0; + return FALSE; + } +} + +static inline uint32_t +buf_3d_tiling_bits(enum i915_winsys_buffer_tile tiling) +{ + uint32_t tiling_bits = 0; + + switch (tiling) { + case I915_TILE_Y: + tiling_bits |= BUF_3D_TILE_WALK_Y; + case I915_TILE_X: + tiling_bits |= BUF_3D_TILED_SURFACE; + case I915_TILE_NONE: + break; + } + + return tiling_bits; +} + +/* Push the state into the sarea and/or texture memory. + */ +void +i915_emit_hardware_state(struct i915_context *i915 ) +{ + /* XXX: there must be an easier way */ + const unsigned dwords = ( 14 + + 7 + + I915_MAX_DYNAMIC + + 8 + + 2 + I915_TEX_UNITS*3 + + 2 + I915_TEX_UNITS*3 + + 2 + I915_MAX_CONSTANT*4 + +#if 0 + i915->current.program_len + +#else + i915->fs->program_len + +#endif + 6 + ) * 3/2; /* plus 50% margin */ + const unsigned relocs = ( I915_TEX_UNITS + + 3 + ) * 3/2; /* plus 50% margin */ + + uintptr_t save_ptr; + size_t save_relocs; + + if (I915_DBG_ON(DBG_ATOMS)) + i915_dump_hardware_dirty(i915, __FUNCTION__); + + if(!BEGIN_BATCH(dwords, relocs)) { + FLUSH_BATCH(NULL); + assert(BEGIN_BATCH(dwords, relocs)); + } + + save_ptr = (uintptr_t)i915->batch->ptr; + save_relocs = i915->batch->relocs; + + /* 14 dwords, 0 relocs */ + if (i915->hardware_dirty & I915_HW_INVARIENT) + { + OUT_BATCH(_3DSTATE_AA_CMD | + AA_LINE_ECAAR_WIDTH_ENABLE | + AA_LINE_ECAAR_WIDTH_1_0 | + AA_LINE_REGION_WIDTH_ENABLE | AA_LINE_REGION_WIDTH_1_0); + + OUT_BATCH(_3DSTATE_DFLT_DIFFUSE_CMD); + OUT_BATCH(0); + + OUT_BATCH(_3DSTATE_DFLT_SPEC_CMD); + OUT_BATCH(0); + + OUT_BATCH(_3DSTATE_DFLT_Z_CMD); + OUT_BATCH(0); + + OUT_BATCH(_3DSTATE_COORD_SET_BINDINGS | + CSB_TCB(0, 0) | + CSB_TCB(1, 1) | + CSB_TCB(2, 2) | + CSB_TCB(3, 3) | + CSB_TCB(4, 4) | + CSB_TCB(5, 5) | + CSB_TCB(6, 6) | + CSB_TCB(7, 7)); + + OUT_BATCH(_3DSTATE_RASTER_RULES_CMD | + ENABLE_POINT_RASTER_RULE | + OGL_POINT_RASTER_RULE | + ENABLE_LINE_STRIP_PROVOKE_VRTX | + ENABLE_TRI_FAN_PROVOKE_VRTX | + LINE_STRIP_PROVOKE_VRTX(1) | + TRI_FAN_PROVOKE_VRTX(2) | + ENABLE_TEXKILL_3D_4D | + TEXKILL_4D); + + /* Need to initialize this to zero. + */ + OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(3) | (0)); + OUT_BATCH(0); + + OUT_BATCH(_3DSTATE_DEPTH_SUBRECT_DISABLE); + + /* disable indirect state for now + */ + OUT_BATCH(_3DSTATE_LOAD_INDIRECT | 0); + OUT_BATCH(0); + } + + /* 7 dwords, 1 relocs */ + if (i915->hardware_dirty & I915_HW_IMMEDIATE) + { + OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | + I1_LOAD_S(0) | + I1_LOAD_S(1) | + I1_LOAD_S(2) | + I1_LOAD_S(4) | + I1_LOAD_S(5) | + I1_LOAD_S(6) | + (5)); + + if(i915->vbo) + OUT_RELOC(i915->vbo, + I915_USAGE_VERTEX, + i915->current.immediate[I915_IMMEDIATE_S0]); + else + /* FIXME: we should not do this */ + OUT_BATCH(0); + OUT_BATCH(i915->current.immediate[I915_IMMEDIATE_S1]); + OUT_BATCH(i915->current.immediate[I915_IMMEDIATE_S2]); + OUT_BATCH(i915->current.immediate[I915_IMMEDIATE_S4]); + OUT_BATCH(i915->current.immediate[I915_IMMEDIATE_S5]); + OUT_BATCH(i915->current.immediate[I915_IMMEDIATE_S6]); + } + +#if 01 + /* I915_MAX_DYNAMIC dwords, 0 relocs */ + if (i915->hardware_dirty & I915_HW_DYNAMIC) + { + int i; + for (i = 0; i < I915_MAX_DYNAMIC; i++) { + OUT_BATCH(i915->current.dynamic[i]); + } + } +#endif + +#if 01 + /* 8 dwords, 2 relocs */ + if (i915->hardware_dirty & I915_HW_STATIC) + { + struct pipe_surface *cbuf_surface = i915->framebuffer.cbufs[0]; + struct pipe_surface *depth_surface = i915->framebuffer.zsbuf; + + if (cbuf_surface) { + struct i915_texture *tex = i915_texture(cbuf_surface->texture); + assert(tex); + + OUT_BATCH(_3DSTATE_BUF_INFO_CMD); + + OUT_BATCH(BUF_3D_ID_COLOR_BACK | + BUF_3D_PITCH(tex->stride) | /* pitch in bytes */ + buf_3d_tiling_bits(tex->tiling)); + + OUT_RELOC(tex->buffer, + I915_USAGE_RENDER, + 0); + } + + /* What happens if no zbuf?? + */ + if (depth_surface) { + struct i915_texture *tex = i915_texture(depth_surface->texture); + unsigned offset = i915_texture_offset(tex, depth_surface->u.tex.level, + depth_surface->u.tex.first_layer); + assert(tex); + assert(offset == 0); + + OUT_BATCH(_3DSTATE_BUF_INFO_CMD); + + assert(tex); + OUT_BATCH(BUF_3D_ID_DEPTH | + BUF_3D_PITCH(tex->stride) | /* pitch in bytes */ + buf_3d_tiling_bits(tex->tiling)); + + OUT_RELOC(tex->buffer, + I915_USAGE_RENDER, + 0); + } + + { + unsigned cformat, zformat = 0; + + if (cbuf_surface) + cformat = cbuf_surface->format; + else + cformat = PIPE_FORMAT_B8G8R8A8_UNORM; /* arbitrary */ + cformat = translate_format(cformat); + + if (depth_surface) + zformat = translate_depth_format( i915->framebuffer.zsbuf->format ); + + OUT_BATCH(_3DSTATE_DST_BUF_VARS_CMD); + OUT_BATCH(DSTORG_HORT_BIAS(0x8) | /* .5 */ + DSTORG_VERT_BIAS(0x8) | /* .5 */ + LOD_PRECLAMP_OGL | + TEX_DEFAULT_COLOR_OGL | + cformat | + zformat ); + } + } +#endif + +#if 01 + /* texture images */ + /* 2 + I915_TEX_UNITS*3 dwords, I915_TEX_UNITS relocs */ + if (i915->hardware_dirty & (I915_HW_MAP | I915_HW_SAMPLER)) + { + const uint nr = i915->current.sampler_enable_nr; + if (nr) { + const uint enabled = i915->current.sampler_enable_flags; + uint unit; + uint count = 0; + OUT_BATCH(_3DSTATE_MAP_STATE | (3 * nr)); + OUT_BATCH(enabled); + for (unit = 0; unit < I915_TEX_UNITS; unit++) { + if (enabled & (1 << unit)) { + struct i915_texture *texture = i915_texture(i915->fragment_sampler_views[unit]->texture); + struct i915_winsys_buffer *buf = texture->buffer; + assert(buf); + + count++; + + OUT_RELOC(buf, I915_USAGE_SAMPLER, 0); + OUT_BATCH(i915->current.texbuffer[unit][0]); /* MS3 */ + OUT_BATCH(i915->current.texbuffer[unit][1]); /* MS4 */ + } + } + assert(count == nr); + } + } +#endif + +#if 01 + /* samplers */ + /* 2 + I915_TEX_UNITS*3 dwords, 0 relocs */ + if (i915->hardware_dirty & I915_HW_SAMPLER) + { + if (i915->current.sampler_enable_nr) { + int i; + + OUT_BATCH( _3DSTATE_SAMPLER_STATE | + (3 * i915->current.sampler_enable_nr) ); + + OUT_BATCH( i915->current.sampler_enable_flags ); + + for (i = 0; i < I915_TEX_UNITS; i++) { + if (i915->current.sampler_enable_flags & (1<current.sampler[i][0] ); + OUT_BATCH( i915->current.sampler[i][1] ); + OUT_BATCH( i915->current.sampler[i][2] ); + } + } + } + } +#endif + +#if 01 + /* constants */ + /* 2 + I915_MAX_CONSTANT*4 dwords, 0 relocs */ + if (i915->hardware_dirty & I915_HW_CONSTANTS) + { + /* Collate the user-defined constants with the fragment shader's + * immediates according to the constant_flags[] array. + */ + const uint nr = i915->fs->num_constants; + if (nr) { + uint i; + + OUT_BATCH( _3DSTATE_PIXEL_SHADER_CONSTANTS | (nr * 4) ); + OUT_BATCH( (1 << (nr - 1)) | ((1 << (nr - 1)) - 1) ); + + for (i = 0; i < nr; i++) { + const uint *c; + if (i915->fs->constant_flags[i] == I915_CONSTFLAG_USER) { + /* grab user-defined constant */ + c = (uint *) i915->current.constants[PIPE_SHADER_FRAGMENT][i]; + } + else { + /* emit program constant */ + c = (uint *) i915->fs->constants[i]; + } +#if 0 /* debug */ + { + float *f = (float *) c; + printf("Const %2d: %f %f %f %f %s\n", i, f[0], f[1], f[2], f[3], + (i915->fs->constant_flags[i] == I915_CONSTFLAG_USER + ? "user" : "immediate")); + } +#endif + OUT_BATCH(*c++); + OUT_BATCH(*c++); + OUT_BATCH(*c++); + OUT_BATCH(*c++); + } + } + } +#endif + +#if 01 + /* Fragment program */ + /* i915->current.program_len dwords, 0 relocs */ + if (i915->hardware_dirty & I915_HW_PROGRAM) + { + uint i; + /* we should always have, at least, a pass-through program */ + assert(i915->fs->program_len > 0); + for (i = 0; i < i915->fs->program_len; i++) { + OUT_BATCH(i915->fs->program[i]); + } + } +#endif + +#if 01 + /* drawing surface size */ + /* 6 dwords, 0 relocs */ + if (i915->hardware_dirty & I915_HW_STATIC) + { + uint w, h; + struct pipe_surface *cbuf_surface = i915->framebuffer.cbufs[0]; + struct i915_texture *tex = i915_texture(cbuf_surface->texture); + unsigned x, y; + int layer; + uint32_t draw_offset; + boolean ret; + + ret = framebuffer_size(&i915->framebuffer, &w, &h); + assert(ret); + + layer = cbuf_surface->u.tex.first_layer; + + x = tex->image_offset[cbuf_surface->u.tex.level][layer].nblocksx; + y = tex->image_offset[cbuf_surface->u.tex.level][layer].nblocksy; + + draw_offset = x | (y << 16); + + /* XXX flush only required when the draw_offset changes! */ + OUT_BATCH(MI_FLUSH | INHIBIT_FLUSH_RENDER_CACHE); + OUT_BATCH(_3DSTATE_DRAW_RECT_CMD); + OUT_BATCH(DRAW_RECT_DIS_DEPTH_OFS); + OUT_BATCH(draw_offset); + OUT_BATCH((w - 1 + x) | ((h - 1 + y) << 16)); + OUT_BATCH(draw_offset); + } +#endif + + I915_DBG(DBG_EMIT, "%s: used %d dwords, %d relocs\n", __FUNCTION__, + ((uintptr_t)i915->batch->ptr - save_ptr) / 4, + i915->batch->relocs - save_relocs); + + i915->hardware_dirty = 0; +} diff --git a/src/gallium/drivers/i915/i915_state_fpc.c b/src/gallium/drivers/i915/i915_state_fpc.c new file mode 100644 index 0000000..ec7cec0 --- /dev/null +++ b/src/gallium/drivers/i915/i915_state_fpc.c @@ -0,0 +1,59 @@ +/************************************************************************** + * + * Copyright © 2010 Jakob Bornecrantz + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "i915_reg.h" +#include "i915_context.h" +#include "i915_state.h" + + + +/*********************************************************************** + */ +static void update_hw_constants(struct i915_context *i915) +{ + i915->hardware_dirty |= I915_HW_CONSTANTS; +} + +struct i915_tracked_state i915_hw_constants = { + "hw_constants", + update_hw_constants, + I915_NEW_CONSTANTS | I915_NEW_FS +}; + + + +/*********************************************************************** + */ +static void update_fs(struct i915_context *i915) +{ + i915->hardware_dirty |= I915_HW_PROGRAM; +} + +struct i915_tracked_state i915_hw_fs = { + "fs", + update_fs, + I915_NEW_FS +}; diff --git a/src/gallium/drivers/i915/i915_state_immediate.c b/src/gallium/drivers/i915/i915_state_immediate.c new file mode 100644 index 0000000..f9ade70 --- /dev/null +++ b/src/gallium/drivers/i915/i915_state_immediate.c @@ -0,0 +1,244 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "i915_state_inlines.h" +#include "i915_context.h" +#include "i915_state.h" +#include "i915_reg.h" +#include "util/u_memory.h" + + +/* All state expressable with the LOAD_STATE_IMMEDIATE_1 packet. + * Would like to opportunistically recombine all these fragments into + * a single packet containing only what has changed, but for now emit + * as multiple packets. + */ + + + + +/*********************************************************************** + * S0,S1: Vertex buffer state. + */ +static void upload_S0S1(struct i915_context *i915) +{ + unsigned LIS0, LIS1; + + /* I915_NEW_VBO + */ + LIS0 = i915->vbo_offset; + + /* I915_NEW_VERTEX_SIZE + */ + /* XXX do this where the vertex size is calculated! */ + { + unsigned vertex_size = i915->current.vertex_info.size; + + LIS1 = ((vertex_size << 24) | + (vertex_size << 16)); + } + + /* I915_NEW_VBO + */ + if (1 || + i915->current.immediate[I915_IMMEDIATE_S0] != LIS0 || + i915->current.immediate[I915_IMMEDIATE_S1] != LIS1) + { + i915->current.immediate[I915_IMMEDIATE_S0] = LIS0; + i915->current.immediate[I915_IMMEDIATE_S1] = LIS1; + i915->hardware_dirty |= I915_HW_IMMEDIATE; + } +} + +const struct i915_tracked_state i915_upload_S0S1 = { + "imm S0 S1", + upload_S0S1, + I915_NEW_VBO | I915_NEW_VERTEX_FORMAT +}; + + + +/*********************************************************************** + * S4: Vertex format, rasterization state + */ +static void upload_S2S4(struct i915_context *i915) +{ + unsigned LIS2, LIS4; + + /* I915_NEW_VERTEX_FORMAT + */ + { + LIS2 = i915->current.vertex_info.hwfmt[1]; + LIS4 = i915->current.vertex_info.hwfmt[0]; + /* + debug_printf("LIS2: 0x%x LIS4: 0x%x\n", LIS2, LIS4); + */ + assert(LIS4); /* should never be zero? */ + } + + LIS4 |= i915->rasterizer->LIS4; + + if (LIS2 != i915->current.immediate[I915_IMMEDIATE_S2] || + LIS4 != i915->current.immediate[I915_IMMEDIATE_S4]) { + + i915->current.immediate[I915_IMMEDIATE_S2] = LIS2; + i915->current.immediate[I915_IMMEDIATE_S4] = LIS4; + i915->hardware_dirty |= I915_HW_IMMEDIATE; + } +} + +const struct i915_tracked_state i915_upload_S2S4 = { + "imm S2 S4", + upload_S2S4, + I915_NEW_RASTERIZER | I915_NEW_VERTEX_FORMAT +}; + + + +/*********************************************************************** + */ +static void upload_S5(struct i915_context *i915) +{ + unsigned LIS5 = 0; + + /* I915_NEW_DEPTH_STENCIL + */ + LIS5 |= i915->depth_stencil->stencil_LIS5; + /* hope it's safe to set stencil ref value even if stencil test is disabled? */ + LIS5 |= i915->stencil_ref.ref_value[0] << S5_STENCIL_REF_SHIFT; + + /* I915_NEW_BLEND + */ + LIS5 |= i915->blend->LIS5; + +#if 0 + /* I915_NEW_RASTERIZER + */ + if (i915->state.Polygon->OffsetFill) { + LIS5 |= S5_GLOBAL_DEPTH_OFFSET_ENABLE; + } +#endif + + if (LIS5 != i915->current.immediate[I915_IMMEDIATE_S5]) { + i915->current.immediate[I915_IMMEDIATE_S5] = LIS5; + i915->hardware_dirty |= I915_HW_IMMEDIATE; + } +} + +const struct i915_tracked_state i915_upload_S5 = { + "imm S5", + upload_S5, + I915_NEW_DEPTH_STENCIL | I915_NEW_BLEND | I915_NEW_RASTERIZER +}; + + + +/*********************************************************************** + */ +static void upload_S6(struct i915_context *i915) +{ + unsigned LIS6 = (2 << S6_TRISTRIP_PV_SHIFT); + + /* I915_NEW_FRAMEBUFFER + */ + if (i915->framebuffer.cbufs[0]) + LIS6 |= S6_COLOR_WRITE_ENABLE; + + /* I915_NEW_BLEND + */ + LIS6 |= i915->blend->LIS6; + + /* I915_NEW_DEPTH + */ + LIS6 |= i915->depth_stencil->depth_LIS6; + + if (LIS6 != i915->current.immediate[I915_IMMEDIATE_S6]) { + i915->current.immediate[I915_IMMEDIATE_S6] = LIS6; + i915->hardware_dirty |= I915_HW_IMMEDIATE; + } +} + +const struct i915_tracked_state i915_upload_S6 = { + "imm s6", + upload_S6, + I915_NEW_BLEND | I915_NEW_DEPTH_STENCIL | I915_NEW_FRAMEBUFFER +}; + + + +/*********************************************************************** + */ +static void upload_S7(struct i915_context *i915) +{ + unsigned LIS7; + + /* I915_NEW_RASTERIZER + */ + LIS7 = i915->rasterizer->LIS7; + + if (LIS7 != i915->current.immediate[I915_IMMEDIATE_S7]) { + i915->current.immediate[I915_IMMEDIATE_S7] = LIS7; + i915->hardware_dirty |= I915_HW_IMMEDIATE; + } +} + +const struct i915_tracked_state i915_upload_S7 = { + "imm S7", + upload_S7, + I915_NEW_RASTERIZER +}; + + + +/*********************************************************************** + */ +static const struct i915_tracked_state *atoms[] = { + &i915_upload_S0S1, + &i915_upload_S2S4, + &i915_upload_S5, + &i915_upload_S6, + &i915_upload_S7 +}; + +static void update_immediate(struct i915_context *i915) +{ + int i; + + for (i = 0; i < Elements(atoms); i++) + if (i915->dirty & atoms[i]->dirty) + atoms[i]->update(i915); +} + +struct i915_tracked_state i915_hw_immediate = { + "immediate", + update_immediate, + ~0 /* all state atoms, becuase we do internal checking */ +}; diff --git a/src/gallium/drivers/i915/i915_state_inlines.h b/src/gallium/drivers/i915/i915_state_inlines.h new file mode 100644 index 0000000..b589117 --- /dev/null +++ b/src/gallium/drivers/i915/i915_state_inlines.h @@ -0,0 +1,231 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + +#ifndef I915_STATE_INLINES_H +#define I915_STATE_INLINES_H + +#include "pipe/p_compiler.h" +#include "pipe/p_defines.h" +#include "util/u_debug.h" +#include "i915_reg.h" + + +static INLINE unsigned +i915_translate_compare_func(unsigned func) +{ + switch (func) { + case PIPE_FUNC_NEVER: + return COMPAREFUNC_NEVER; + case PIPE_FUNC_LESS: + return COMPAREFUNC_LESS; + case PIPE_FUNC_LEQUAL: + return COMPAREFUNC_LEQUAL; + case PIPE_FUNC_GREATER: + return COMPAREFUNC_GREATER; + case PIPE_FUNC_GEQUAL: + return COMPAREFUNC_GEQUAL; + case PIPE_FUNC_NOTEQUAL: + return COMPAREFUNC_NOTEQUAL; + case PIPE_FUNC_EQUAL: + return COMPAREFUNC_EQUAL; + case PIPE_FUNC_ALWAYS: + return COMPAREFUNC_ALWAYS; + default: + return COMPAREFUNC_ALWAYS; + } +} + +static INLINE unsigned +i915_translate_stencil_op(unsigned op) +{ + switch (op) { + case PIPE_STENCIL_OP_KEEP: + return STENCILOP_KEEP; + case PIPE_STENCIL_OP_ZERO: + return STENCILOP_ZERO; + case PIPE_STENCIL_OP_REPLACE: + return STENCILOP_REPLACE; + case PIPE_STENCIL_OP_INCR: + return STENCILOP_INCRSAT; + case PIPE_STENCIL_OP_DECR: + return STENCILOP_DECRSAT; + case PIPE_STENCIL_OP_INCR_WRAP: + return STENCILOP_INCR; + case PIPE_STENCIL_OP_DECR_WRAP: + return STENCILOP_DECR; + case PIPE_STENCIL_OP_INVERT: + return STENCILOP_INVERT; + default: + return STENCILOP_ZERO; + } +} + +static INLINE unsigned +i915_translate_blend_factor(unsigned factor) +{ + switch (factor) { + case PIPE_BLENDFACTOR_ZERO: + return BLENDFACT_ZERO; + case PIPE_BLENDFACTOR_SRC_ALPHA: + return BLENDFACT_SRC_ALPHA; + case PIPE_BLENDFACTOR_ONE: + return BLENDFACT_ONE; + case PIPE_BLENDFACTOR_SRC_COLOR: + return BLENDFACT_SRC_COLR; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + return BLENDFACT_INV_SRC_COLR; + case PIPE_BLENDFACTOR_DST_COLOR: + return BLENDFACT_DST_COLR; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + return BLENDFACT_INV_DST_COLR; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + return BLENDFACT_INV_SRC_ALPHA; + case PIPE_BLENDFACTOR_DST_ALPHA: + return BLENDFACT_DST_ALPHA; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + return BLENDFACT_INV_DST_ALPHA; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + return BLENDFACT_SRC_ALPHA_SATURATE; + case PIPE_BLENDFACTOR_CONST_COLOR: + return BLENDFACT_CONST_COLOR; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + return BLENDFACT_INV_CONST_COLOR; + case PIPE_BLENDFACTOR_CONST_ALPHA: + return BLENDFACT_CONST_ALPHA; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + return BLENDFACT_INV_CONST_ALPHA; + default: + return BLENDFACT_ZERO; + } +} + +static INLINE unsigned +i915_translate_blend_func(unsigned mode) +{ + switch (mode) { + case PIPE_BLEND_ADD: + return BLENDFUNC_ADD; + case PIPE_BLEND_MIN: + return BLENDFUNC_MIN; + case PIPE_BLEND_MAX: + return BLENDFUNC_MAX; + case PIPE_BLEND_SUBTRACT: + return BLENDFUNC_SUBTRACT; + case PIPE_BLEND_REVERSE_SUBTRACT: + return BLENDFUNC_REVERSE_SUBTRACT; + default: + return 0; + } +} + + +static INLINE unsigned +i915_translate_logic_op(unsigned opcode) +{ + switch (opcode) { + case PIPE_LOGICOP_CLEAR: + return LOGICOP_CLEAR; + case PIPE_LOGICOP_AND: + return LOGICOP_AND; + case PIPE_LOGICOP_AND_REVERSE: + return LOGICOP_AND_RVRSE; + case PIPE_LOGICOP_COPY: + return LOGICOP_COPY; + case PIPE_LOGICOP_COPY_INVERTED: + return LOGICOP_COPY_INV; + case PIPE_LOGICOP_AND_INVERTED: + return LOGICOP_AND_INV; + case PIPE_LOGICOP_NOOP: + return LOGICOP_NOOP; + case PIPE_LOGICOP_XOR: + return LOGICOP_XOR; + case PIPE_LOGICOP_OR: + return LOGICOP_OR; + case PIPE_LOGICOP_OR_INVERTED: + return LOGICOP_OR_INV; + case PIPE_LOGICOP_NOR: + return LOGICOP_NOR; + case PIPE_LOGICOP_EQUIV: + return LOGICOP_EQUIV; + case PIPE_LOGICOP_INVERT: + return LOGICOP_INV; + case PIPE_LOGICOP_OR_REVERSE: + return LOGICOP_OR_RVRSE; + case PIPE_LOGICOP_NAND: + return LOGICOP_NAND; + case PIPE_LOGICOP_SET: + return LOGICOP_SET; + default: + return LOGICOP_SET; + } +} + + + +static INLINE boolean i915_validate_vertices( unsigned hw_prim, unsigned nr ) +{ + boolean ok; + + switch (hw_prim) { + case PRIM3D_POINTLIST: + ok = (nr >= 1); + assert(ok); + break; + case PRIM3D_LINELIST: + ok = (nr >= 2) && (nr % 2) == 0; + assert(ok); + break; + case PRIM3D_LINESTRIP: + ok = (nr >= 2); + assert(ok); + break; + case PRIM3D_TRILIST: + ok = (nr >= 3) && (nr % 3) == 0; + assert(ok); + break; + case PRIM3D_TRISTRIP: + ok = (nr >= 3); + assert(ok); + break; + case PRIM3D_TRIFAN: + ok = (nr >= 3); + assert(ok); + break; + case PRIM3D_POLY: + ok = (nr >= 3); + assert(ok); + break; + default: + assert(0); + ok = 0; + break; + } + + return ok; +} + +#endif diff --git a/src/gallium/drivers/i915/i915_state_sampler.c b/src/gallium/drivers/i915/i915_state_sampler.c new file mode 100644 index 0000000..916cb76 --- /dev/null +++ b/src/gallium/drivers/i915/i915_state_sampler.c @@ -0,0 +1,336 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + +#include "pipe/p_context.h" +#include "pipe/p_state.h" + +#include "i915_state_inlines.h" +#include "i915_context.h" +#include "i915_reg.h" +#include "i915_state.h" +#include "i915_resource.h" + + +/* + * A note about min_lod & max_lod. + * + * There is a circular dependancy between the sampler state + * and the map state to be submitted to hw. + * + * Two condition must be meet: + * min_lod =< max_lod == true + * max_lod =< last_level == true + * + * + * This is all fine and dandy if it where for the fact that max_lod + * is set on the map state instead of the sampler state. That is + * the max_lod we submit on map is: + * max_lod = MIN2(last_level, max_lod); + * + * So we need to update the map state when we change samplers and + * we need to be change the sampler state when map state is changed. + * The first part is done by calling update_texture in update_samplers + * and the second part is done else where in code tracking the state + * changes. + */ + +static void update_map(struct i915_context *i915, + uint unit, + const struct i915_texture *tex, + const struct i915_sampler_state *sampler, + uint state[2]); + + + +/*********************************************************************** + * Samplers + */ + +/** + * Compute i915 texture sampling state. + * + * Recalculate all state from scratch. Perhaps not the most + * efficient, but this has gotten complex enough that we need + * something which is understandable and reliable. + * \param state returns the 3 words of compute state + */ +static void update_sampler(struct i915_context *i915, + uint unit, + const struct i915_sampler_state *sampler, + const struct i915_texture *tex, + unsigned state[3]) +{ + const struct pipe_resource *pt = &tex->b.b; + unsigned minlod, lastlod; + + state[0] = sampler->state[0]; + state[1] = sampler->state[1]; + state[2] = sampler->state[2]; + + if (pt->format == PIPE_FORMAT_UYVY || + pt->format == PIPE_FORMAT_YUYV) + state[0] |= SS2_COLORSPACE_CONVERSION; + + /* 3D textures don't seem to respect the border color. + * Fallback if there's ever a danger that they might refer to + * it. + * + * Effectively this means fallback on 3D clamp or + * clamp_to_border. + * + * XXX: Check if this is true on i945. + * XXX: Check if this bug got fixed in release silicon. + */ +#if 0 + { + const unsigned ws = sampler->templ->wrap_s; + const unsigned wt = sampler->templ->wrap_t; + const unsigned wr = sampler->templ->wrap_r; + if (pt->target == PIPE_TEXTURE_3D && + (sampler->templ->min_img_filter != PIPE_TEX_FILTER_NEAREST || + sampler->templ->mag_img_filter != PIPE_TEX_FILTER_NEAREST) && + (ws == PIPE_TEX_WRAP_CLAMP || + wt == PIPE_TEX_WRAP_CLAMP || + wr == PIPE_TEX_WRAP_CLAMP || + ws == PIPE_TEX_WRAP_CLAMP_TO_BORDER || + wt == PIPE_TEX_WRAP_CLAMP_TO_BORDER || + wr == PIPE_TEX_WRAP_CLAMP_TO_BORDER)) { + if (i915->conformance_mode > 0) { + assert(0); + /* sampler->fallback = true; */ + /* TODO */ + } + } + } +#endif + + /* See note at the top of file */ + minlod = sampler->minlod; + lastlod = pt->last_level << 4; + + if (lastlod < minlod) { + minlod = lastlod; + } + + state[1] |= (sampler->minlod << SS3_MIN_LOD_SHIFT); + state[1] |= (unit << SS3_TEXTUREMAP_INDEX_SHIFT); +} + +static void update_samplers(struct i915_context *i915) +{ + uint unit; + + i915->current.sampler_enable_nr = 0; + i915->current.sampler_enable_flags = 0x0; + + for (unit = 0; unit < i915->num_fragment_sampler_views && unit < i915->num_samplers; + unit++) { + /* determine unit enable/disable by looking for a bound texture */ + /* could also examine the fragment program? */ + if (i915->fragment_sampler_views[unit]) { + struct i915_texture *texture = i915_texture(i915->fragment_sampler_views[unit]->texture); + + update_sampler(i915, + unit, + i915->sampler[unit], /* sampler state */ + texture, /* texture */ + i915->current.sampler[unit]); /* the result */ + update_map(i915, + unit, + texture, /* texture */ + i915->sampler[unit], /* sampler state */ + i915->current.texbuffer[unit]); /* the result */ + + i915->current.sampler_enable_nr++; + i915->current.sampler_enable_flags |= (1 << unit); + } + } + + i915->hardware_dirty |= I915_HW_SAMPLER | I915_HW_MAP; +} + +struct i915_tracked_state i915_hw_samplers = { + "samplers", + update_samplers, + I915_NEW_SAMPLER | I915_NEW_SAMPLER_VIEW +}; + + + +/*********************************************************************** + * Sampler views + */ + +static uint translate_texture_format(enum pipe_format pipeFormat) +{ + switch (pipeFormat) { + case PIPE_FORMAT_L8_UNORM: + return MAPSURF_8BIT | MT_8BIT_L8; + case PIPE_FORMAT_I8_UNORM: + return MAPSURF_8BIT | MT_8BIT_I8; + case PIPE_FORMAT_A8_UNORM: + return MAPSURF_8BIT | MT_8BIT_A8; + case PIPE_FORMAT_L8A8_UNORM: + return MAPSURF_16BIT | MT_16BIT_AY88; + case PIPE_FORMAT_B5G6R5_UNORM: + return MAPSURF_16BIT | MT_16BIT_RGB565; + case PIPE_FORMAT_B5G5R5A1_UNORM: + return MAPSURF_16BIT | MT_16BIT_ARGB1555; + case PIPE_FORMAT_B4G4R4A4_UNORM: + return MAPSURF_16BIT | MT_16BIT_ARGB4444; + case PIPE_FORMAT_B8G8R8A8_UNORM: + return MAPSURF_32BIT | MT_32BIT_ARGB8888; + case PIPE_FORMAT_B8G8R8X8_UNORM: + return MAPSURF_32BIT | MT_32BIT_XRGB8888; + case PIPE_FORMAT_R8G8B8A8_UNORM: + return MAPSURF_32BIT | MT_32BIT_ABGR8888; +#if 0 + case PIPE_FORMAT_R8G8B8X8_UNORM: + return MAPSURF_32BIT | MT_32BIT_XBGR8888; +#endif + case PIPE_FORMAT_YUYV: + return (MAPSURF_422 | MT_422_YCRCB_NORMAL); + case PIPE_FORMAT_UYVY: + return (MAPSURF_422 | MT_422_YCRCB_SWAPY); +#if 0 + case PIPE_FORMAT_RGB_FXT1: + case PIPE_FORMAT_RGBA_FXT1: + return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1); +#endif + case PIPE_FORMAT_Z16_UNORM: + return (MAPSURF_16BIT | MT_16BIT_L16); +#if 0 + case PIPE_FORMAT_RGBA_DXT1: + case PIPE_FORMAT_RGB_DXT1: + return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1); + case PIPE_FORMAT_RGBA_DXT3: + return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT2_3); + case PIPE_FORMAT_RGBA_DXT5: + return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5); +#endif + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + case PIPE_FORMAT_Z24X8_UNORM: + return (MAPSURF_32BIT | MT_32BIT_xI824); + default: + debug_printf("i915: translate_texture_format() bad image format %x\n", + pipeFormat); + assert(0); + return 0; + } +} + +static inline uint32_t +ms3_tiling_bits(enum i915_winsys_buffer_tile tiling) +{ + uint32_t tiling_bits = 0; + + switch (tiling) { + case I915_TILE_Y: + tiling_bits |= MS3_TILE_WALK_Y; + case I915_TILE_X: + tiling_bits |= MS3_TILED_SURFACE; + case I915_TILE_NONE: + break; + } + + return tiling_bits; +} + +static void update_map(struct i915_context *i915, + uint unit, + const struct i915_texture *tex, + const struct i915_sampler_state *sampler, + uint state[2]) +{ + const struct pipe_resource *pt = &tex->b.b; + uint format, pitch; + const uint width = pt->width0, height = pt->height0, depth = pt->depth0; + const uint num_levels = pt->last_level; + unsigned max_lod = num_levels * 4; + + assert(tex); + assert(width); + assert(height); + assert(depth); + + format = translate_texture_format(pt->format); + pitch = tex->stride; + + assert(format); + assert(pitch); + + /* MS3 state */ + state[0] = + (((height - 1) << MS3_HEIGHT_SHIFT) + | ((width - 1) << MS3_WIDTH_SHIFT) + | format + | ms3_tiling_bits(tex->tiling)); + + /* + * XXX When min_filter != mag_filter and there's just one mipmap level, + * set max_lod = 1 to make sure i915 chooses between min/mag filtering. + */ + + /* See note at the top of file */ + if (max_lod > (sampler->maxlod >> 2)) + max_lod = sampler->maxlod >> 2; + + /* MS4 state */ + state[1] = + ((((pitch / 4) - 1) << MS4_PITCH_SHIFT) + | MS4_CUBE_FACE_ENA_MASK + | ((max_lod) << MS4_MAX_LOD_SHIFT) + | ((depth - 1) << MS4_VOLUME_DEPTH_SHIFT)); +} + +static void update_maps(struct i915_context *i915) +{ + uint unit; + + for (unit = 0; unit < i915->num_fragment_sampler_views && unit < i915->num_samplers; + unit++) { + /* determine unit enable/disable by looking for a bound texture */ + /* could also examine the fragment program? */ + if (i915->fragment_sampler_views[unit]) { + struct i915_texture *texture = i915_texture(i915->fragment_sampler_views[unit]->texture); + + update_map(i915, + unit, + texture, /* texture */ + i915->sampler[unit], /* sampler state */ + i915->current.texbuffer[unit]); + } + } + + i915->hardware_dirty |= I915_HW_MAP; +} + +struct i915_tracked_state i915_hw_sampler_views = { + "sampler_views", + update_maps, + I915_NEW_SAMPLER_VIEW +}; diff --git a/src/gallium/drivers/i915/i915_state_static.c b/src/gallium/drivers/i915/i915_state_static.c new file mode 100644 index 0000000..dc9a4c1 --- /dev/null +++ b/src/gallium/drivers/i915/i915_state_static.c @@ -0,0 +1,47 @@ +/************************************************************************** + * + * Copyright © 2010 Jakob Bornecrantz + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "i915_reg.h" +#include "i915_context.h" +#include "i915_state.h" + + + +/*********************************************************************** + * Update framebuffer state + */ +static void update_framebuffer(struct i915_context *i915) +{ + /* HW emit currently references framebuffer state directly: + */ + i915->hardware_dirty |= I915_HW_STATIC; +} + +struct i915_tracked_state i915_hw_framebuffer = { + "framebuffer", + update_framebuffer, + I915_NEW_FRAMEBUFFER +}; diff --git a/src/gallium/drivers/i915/i915_surface.c b/src/gallium/drivers/i915/i915_surface.c new file mode 100644 index 0000000..becc6e9 --- /dev/null +++ b/src/gallium/drivers/i915/i915_surface.c @@ -0,0 +1,201 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + +#include "i915_surface.h" +#include "i915_resource.h" +#include "i915_blit.h" +#include "i915_reg.h" +#include "i915_screen.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_math.h" +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_pack_color.h" + + +/* Assumes all values are within bounds -- no checking at this level - + * do it higher up if required. + */ +static void +i915_surface_copy(struct pipe_context *pipe, + struct pipe_resource *dst, unsigned dst_level, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource *src, unsigned src_level, + const struct pipe_box *src_box) +{ + struct i915_texture *dst_tex = i915_texture(dst); + struct i915_texture *src_tex = i915_texture(src); + struct pipe_resource *dpt = &dst_tex->b.b; + struct pipe_resource *spt = &src_tex->b.b; + unsigned dst_offset, src_offset; /* in bytes */ + + /* XXX cannot copy 3d regions at this time */ + assert(src_box->depth == 1); + if (dst->target != PIPE_TEXTURE_CUBE && + dst->target != PIPE_TEXTURE_3D) + assert(dstz == 0); + dst_offset = i915_texture_offset(dst_tex, dst_level, dstz); + + if (src->target != PIPE_TEXTURE_CUBE && + src->target != PIPE_TEXTURE_3D) + assert(src_box->z == 0); + src_offset = i915_texture_offset(src_tex, src_level, src_box->z); + + assert( dst != src ); + assert( util_format_get_blocksize(dpt->format) == util_format_get_blocksize(spt->format) ); + assert( util_format_get_blockwidth(dpt->format) == util_format_get_blockwidth(spt->format) ); + assert( util_format_get_blockheight(dpt->format) == util_format_get_blockheight(spt->format) ); + assert( util_format_get_blockwidth(dpt->format) == 1 ); + assert( util_format_get_blockheight(dpt->format) == 1 ); + + i915_copy_blit( i915_context(pipe), + util_format_get_blocksize(dpt->format), + (unsigned short) src_tex->stride, src_tex->buffer, src_offset, + (unsigned short) dst_tex->stride, dst_tex->buffer, dst_offset, + (short) src_box->x, (short) src_box->y, (short) dstx, (short) dsty, + (short) src_box->width, (short) src_box->height ); +} + + +static void +i915_clear_render_target(struct pipe_context *pipe, + struct pipe_surface *dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct i915_texture *tex = i915_texture(dst->texture); + struct pipe_resource *pt = &tex->b.b; + union util_color uc; + unsigned offset = i915_texture_offset(tex, dst->u.tex.level, dst->u.tex.first_layer); + + assert(util_format_get_blockwidth(pt->format) == 1); + assert(util_format_get_blockheight(pt->format) == 1); + + util_pack_color(rgba, dst->format, &uc); + i915_fill_blit( i915_context(pipe), + util_format_get_blocksize(pt->format), + XY_COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB, + (unsigned short) tex->stride, + tex->buffer, offset, + (short) dstx, (short) dsty, + (short) width, (short) height, + uc.ui ); +} + +static void +i915_clear_depth_stencil(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct i915_texture *tex = i915_texture(dst->texture); + struct pipe_resource *pt = &tex->b.b; + unsigned packedds; + unsigned mask = 0; + unsigned offset = i915_texture_offset(tex, dst->u.tex.level, dst->u.tex.first_layer); + + assert(util_format_get_blockwidth(pt->format) == 1); + assert(util_format_get_blockheight(pt->format) == 1); + + packedds = util_pack_z_stencil(dst->format, depth, stencil); + + if (clear_flags & PIPE_CLEAR_DEPTH) + mask |= XY_COLOR_BLT_WRITE_RGB; + /* XXX presumably this does read-modify-write + (otherwise this won't work anyway). Hence will only want to + do it if really have stencil and it isn't cleared */ + if ((clear_flags & PIPE_CLEAR_STENCIL) || + (dst->format != PIPE_FORMAT_Z24_UNORM_S8_USCALED)) + mask |= XY_COLOR_BLT_WRITE_ALPHA; + + i915_fill_blit( i915_context(pipe), + util_format_get_blocksize(pt->format), + mask, + (unsigned short) tex->stride, + tex->buffer, offset, + (short) dstx, (short) dsty, + (short) width, (short) height, + packedds ); +} + +/* + * Screen surface functions + */ + + +static struct pipe_surface * +i915_create_surface(struct pipe_context *ctx, + struct pipe_resource *pt, + const struct pipe_surface *surf_tmpl) +{ + struct pipe_surface *ps; + + assert(surf_tmpl->u.tex.first_layer == surf_tmpl->u.tex.last_layer); + if (pt->target != PIPE_TEXTURE_CUBE && + pt->target != PIPE_TEXTURE_3D) + assert(surf_tmpl->u.tex.first_layer == 0); + + ps = CALLOC_STRUCT(pipe_surface); + if (ps) { + /* could subclass pipe_surface and store offset as it used to do */ + pipe_reference_init(&ps->reference, 1); + pipe_resource_reference(&ps->texture, pt); + ps->format = surf_tmpl->format; + ps->width = u_minify(pt->width0, surf_tmpl->u.tex.level); + ps->height = u_minify(pt->height0, surf_tmpl->u.tex.level); + ps->u.tex.level = surf_tmpl->u.tex.level; + ps->u.tex.first_layer = surf_tmpl->u.tex.first_layer; + ps->u.tex.last_layer = surf_tmpl->u.tex.last_layer; + ps->usage = surf_tmpl->usage; + ps->context = ctx; + } + return ps; +} + +static void +i915_surface_destroy(struct pipe_context *ctx, + struct pipe_surface *surf) +{ + pipe_resource_reference(&surf->texture, NULL); + FREE(surf); +} + + +void +i915_init_surface_functions(struct i915_context *i915) +{ + i915->base.resource_copy_region = i915_surface_copy; + i915->base.clear_render_target = i915_clear_render_target; + i915->base.clear_depth_stencil = i915_clear_depth_stencil; + i915->base.create_surface = i915_create_surface; + i915->base.surface_destroy = i915_surface_destroy; +} diff --git a/src/gallium/drivers/i915/i915_surface.h b/src/gallium/drivers/i915/i915_surface.h new file mode 100644 index 0000000..70b61de --- /dev/null +++ b/src/gallium/drivers/i915/i915_surface.h @@ -0,0 +1,37 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef I915_SURFACE_H +#define I915_SURFACE_H + +struct i915_context; +struct i915_screen; + +void i915_init_surface_functions( struct i915_context *i915 ); + + +#endif /* I915_SCREEN_H */ diff --git a/src/gallium/drivers/i915/i915_winsys.h b/src/gallium/drivers/i915/i915_winsys.h new file mode 100644 index 0000000..24ea416 --- /dev/null +++ b/src/gallium/drivers/i915/i915_winsys.h @@ -0,0 +1,232 @@ +/************************************************************************** + * + * Copyright © 2009 Jakob Bornecrantz + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef I915_WINSYS_H +#define I915_WINSYS_H + +#include "pipe/p_compiler.h" + +struct i915_winsys; +struct i915_winsys_buffer; +struct i915_winsys_batchbuffer; +struct pipe_resource; +struct pipe_fence_handle; +struct winsys_handle; + +enum i915_winsys_buffer_usage +{ + /* use on textures */ + I915_USAGE_RENDER = 0x01, + I915_USAGE_SAMPLER = 0x02, + I915_USAGE_2D_TARGET = 0x04, + I915_USAGE_2D_SOURCE = 0x08, + /* use on vertex */ + I915_USAGE_VERTEX = 0x10 +}; + +enum i915_winsys_buffer_type +{ + I915_NEW_TEXTURE, + I915_NEW_SCANOUT, /**< a texture used for scanning out from */ + I915_NEW_VERTEX +}; + +/* These need to be in sync with the definitions of libdrm-intel! */ +enum i915_winsys_buffer_tile +{ + I915_TILE_NONE, + I915_TILE_X, + I915_TILE_Y +}; + +struct i915_winsys_batchbuffer { + + struct i915_winsys *iws; + + /** + * Values exported to speed up the writing the batchbuffer, + * instead of having to go trough a accesor function for + * each dword written. + */ + /*{@*/ + uint8_t *map; + uint8_t *ptr; + size_t size; + + size_t relocs; + size_t max_relocs; + /*@}*/ +}; + +struct i915_winsys { + + unsigned pci_id; /**< PCI ID for the device */ + + /** + * Batchbuffer functions. + */ + /*@{*/ + /** + * Create a new batchbuffer. + */ + struct i915_winsys_batchbuffer * + (*batchbuffer_create)(struct i915_winsys *iws); + + /** + * Emit a relocation to a buffer. + * Target position in batchbuffer is the same as ptr. + * + * @batch + * @reloc buffer address to be inserted into target. + * @usage how is the hardware going to use the buffer. + * @offset add this to the reloc buffers address + * @target buffer where to write the address, null for batchbuffer. + */ + int (*batchbuffer_reloc)(struct i915_winsys_batchbuffer *batch, + struct i915_winsys_buffer *reloc, + enum i915_winsys_buffer_usage usage, + unsigned offset, bool fenced); + + /** + * Flush a bufferbatch. + */ + void (*batchbuffer_flush)(struct i915_winsys_batchbuffer *batch, + struct pipe_fence_handle **fence); + + /** + * Destroy a batchbuffer. + */ + void (*batchbuffer_destroy)(struct i915_winsys_batchbuffer *batch); + /*@}*/ + + + /** + * Buffer functions. + */ + /*@{*/ + /** + * Create a buffer. + */ + struct i915_winsys_buffer * + (*buffer_create)(struct i915_winsys *iws, + unsigned size, + enum i915_winsys_buffer_type type); + + /** + * Create a tiled buffer. + * + * *stride, height are in bytes. The winsys tries to allocate the buffer with + * the tiling mode provide in *tiling. If tiling is no possible, *tiling will + * be set to I915_TILE_NONE. The calculated stride (incorporateing hw/kernel + * requirements) is always returned in *stride. + */ + struct i915_winsys_buffer * + (*buffer_create_tiled)(struct i915_winsys *iws, + unsigned *stride, unsigned height, + enum i915_winsys_buffer_tile *tiling, + enum i915_winsys_buffer_type type); + + /** + * Creates a buffer from a handle. + * Used to implement pipe_screen::resource_from_handle. + * Also provides the stride information needed for the + * texture via the stride argument. + */ + struct i915_winsys_buffer * + (*buffer_from_handle)(struct i915_winsys *iws, + struct winsys_handle *whandle, + enum i915_winsys_buffer_tile *tiling, + unsigned *stride); + + /** + * Used to implement pipe_screen::resource_get_handle. + * The winsys might need the stride information. + */ + boolean (*buffer_get_handle)(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + struct winsys_handle *whandle, + unsigned stride); + + /** + * Map a buffer. + */ + void *(*buffer_map)(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + boolean write); + + /** + * Unmap a buffer. + */ + void (*buffer_unmap)(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer); + + /** + * Write to a buffer. + * + * Arguments follows pipe_buffer_write. + */ + int (*buffer_write)(struct i915_winsys *iws, + struct i915_winsys_buffer *dst, + size_t offset, + size_t size, + const void *data); + + void (*buffer_destroy)(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer); + /*@}*/ + + + /** + * Fence functions. + */ + /*@{*/ + /** + * Reference fence and set ptr to fence. + */ + void (*fence_reference)(struct i915_winsys *iws, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence); + + /** + * Check if a fence has finished. + */ + int (*fence_signalled)(struct i915_winsys *iws, + struct pipe_fence_handle *fence); + + /** + * Wait on a fence to finish. + */ + int (*fence_finish)(struct i915_winsys *iws, + struct pipe_fence_handle *fence); + /*@}*/ + + + /** + * Destroy the winsys. + */ + void (*destroy)(struct i915_winsys *iws); +}; + +#endif diff --git a/src/gallium/drivers/i965/Makefile b/src/gallium/drivers/i965/Makefile new file mode 100644 index 0000000..a0331f8 --- /dev/null +++ b/src/gallium/drivers/i965/Makefile @@ -0,0 +1,74 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = i965 + +C_SOURCES = \ + brw_cc.c \ + brw_clip.c \ + brw_clip_line.c \ + brw_clip_point.c \ + brw_clip_state.c \ + brw_clip_tri.c \ + brw_clip_unfilled.c \ + brw_clip_util.c \ + brw_context.c \ + brw_curbe.c \ + brw_disasm.c \ + brw_draw.c \ + brw_draw_upload.c \ + brw_eu.c \ + brw_eu_debug.c \ + brw_eu_emit.c \ + brw_eu_util.c \ + brw_gs.c \ + brw_gs_emit.c \ + brw_gs_state.c \ + brw_misc_state.c \ + brw_pipe_blend.c \ + brw_pipe_depth.c \ + brw_pipe_fb.c \ + brw_pipe_query.c \ + brw_pipe_shader.c \ + brw_pipe_flush.c \ + brw_pipe_misc.c \ + brw_pipe_sampler.c \ + brw_pipe_surface.c \ + brw_pipe_vertex.c \ + brw_pipe_clear.c \ + brw_pipe_rast.c \ + brw_resource.c \ + brw_sf.c \ + brw_sf_emit.c \ + brw_sf_state.c \ + brw_state_batch.c \ + brw_state_debug.c \ + brw_state_cache.c \ + brw_state_upload.c \ + brw_structs_dump.c \ + brw_swtnl.c \ + brw_urb.c \ + brw_vs.c \ + brw_vs_emit.c \ + brw_vs_state.c \ + brw_vs_surface_state.c \ + brw_wm.c \ + brw_wm_debug.c \ + brw_wm_emit.c \ + brw_wm_fp.c \ + brw_wm_iz.c \ + brw_wm_pass0.c \ + brw_wm_pass1.c \ + brw_wm_pass2.c \ + brw_wm_sampler_state.c \ + brw_wm_state.c \ + brw_wm_surface_state.c \ + brw_screen.c \ + brw_resource_buffer.c \ + brw_resource_texture.c \ + brw_resource_texture_layout.c \ + brw_batchbuffer.c \ + brw_winsys_debug.c \ + intel_decode.c + +include ../../Makefile.template diff --git a/src/gallium/drivers/i965/SConscript b/src/gallium/drivers/i965/SConscript new file mode 100644 index 0000000..3ef6c88 --- /dev/null +++ b/src/gallium/drivers/i965/SConscript @@ -0,0 +1,79 @@ +Import('*') + +env = env.Clone() + +i965 = env.ConvenienceLibrary( + target = 'i965', + source = [ + 'brw_batchbuffer.c', + 'brw_cc.c', + 'brw_clip.c', + 'brw_clip_line.c', + 'brw_clip_point.c', + 'brw_clip_state.c', + 'brw_clip_tri.c', + 'brw_clip_unfilled.c', + 'brw_clip_util.c', + 'brw_context.c', + 'brw_curbe.c', + 'brw_disasm.c', + 'brw_draw.c', + 'brw_draw_upload.c', + 'brw_eu.c', + 'brw_eu_debug.c', + 'brw_eu_emit.c', + 'brw_eu_util.c', + 'brw_gs.c', + 'brw_gs_emit.c', + 'brw_gs_state.c', + 'brw_misc_state.c', + 'brw_pipe_blend.c', + 'brw_pipe_clear.c', + 'brw_pipe_depth.c', + 'brw_pipe_fb.c', + 'brw_pipe_flush.c', + 'brw_pipe_misc.c', + 'brw_pipe_query.c', + 'brw_pipe_rast.c', + 'brw_pipe_sampler.c', + 'brw_pipe_surface.c', + 'brw_pipe_surface.c', + 'brw_pipe_shader.c', + 'brw_pipe_vertex.c', + 'brw_resource.c', + 'brw_resource_buffer.c', + 'brw_resource_texture.c', + 'brw_resource_texture_layout.c', + 'brw_screen.c', + 'brw_structs_dump.c', + 'brw_sf.c', + 'brw_sf_emit.c', + 'brw_sf_state.c', + 'brw_state_batch.c', + 'brw_state_cache.c', + 'brw_state_debug.c', + 'brw_state_upload.c', + 'brw_swtnl.c', + 'brw_urb.c', + 'brw_vs.c', + 'brw_vs_emit.c', + 'brw_vs_state.c', + 'brw_vs_surface_state.c', + 'brw_winsys_debug.c', + 'brw_wm.c', +# 'brw_wm_constant_buffer.c', + 'brw_wm_debug.c', + 'brw_wm_emit.c', + 'brw_wm_fp.c', +# 'brw_wm_glsl.c', + 'brw_wm_iz.c', + 'brw_wm_pass0.c', + 'brw_wm_pass1.c', + 'brw_wm_pass2.c', + 'brw_wm_sampler_state.c', + 'brw_wm_state.c', + 'brw_wm_surface_state.c', + 'intel_decode.c', + ]) + +Export('i965') diff --git a/src/gallium/drivers/i965/brw_batchbuffer.c b/src/gallium/drivers/i965/brw_batchbuffer.c new file mode 100644 index 0000000..e80067f --- /dev/null +++ b/src/gallium/drivers/i965/brw_batchbuffer.c @@ -0,0 +1,202 @@ +/************************************************************************** + * + * Copyright 2006 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. + * + **************************************************************************/ + +#include "util/u_memory.h" + +#include "brw_batchbuffer.h" +#include "brw_reg.h" +#include "brw_winsys.h" +#include "brw_debug.h" +#include "brw_structs.h" + +#define ALWAYS_EMIT_MI_FLUSH 1 + +enum pipe_error +brw_batchbuffer_reset(struct brw_batchbuffer *batch) +{ + enum pipe_error ret; + + ret = batch->sws->bo_alloc( batch->sws, + BRW_BUFFER_TYPE_BATCH, + BRW_BATCH_SIZE, 4096, + &batch->buf ); + if (ret) + return ret; + + batch->size = BRW_BATCH_SIZE; + + /* With map_range semantics, the winsys can decide whether to + * inject a malloc'ed bounce buffer instead of mapping directly. + */ + batch->map = batch->sws->bo_map(batch->buf, + BRW_DATA_BATCH_BUFFER, + 0, batch->size, + GL_TRUE, + GL_TRUE, + GL_TRUE); + + batch->ptr = batch->map; + return PIPE_OK; +} + +struct brw_batchbuffer * +brw_batchbuffer_alloc(struct brw_winsys_screen *sws, + struct brw_chipset chipset) +{ + struct brw_batchbuffer *batch = CALLOC_STRUCT(brw_batchbuffer); + + batch->sws = sws; + batch->chipset = chipset; + brw_batchbuffer_reset(batch); + + return batch; +} + +void +brw_batchbuffer_free(struct brw_batchbuffer *batch) +{ + if (batch->map) { + batch->sws->bo_unmap(batch->buf); + batch->map = NULL; + } + + bo_reference(&batch->buf, NULL); + FREE(batch); +} + + +void +_brw_batchbuffer_flush(struct brw_batchbuffer *batch, + const char *file, + int line) +{ + GLuint used = batch->ptr - batch->map; + + if (used == 0) + return; + + /* Post-swap throttling done by the state tracker. + */ + + if (BRW_DEBUG & DEBUG_BATCH) + debug_printf("%s:%d: Batchbuffer flush with %db used\n", + file, line, used); + + if (ALWAYS_EMIT_MI_FLUSH) { + *(GLuint *) (batch->ptr) = MI_FLUSH | BRW_FLUSH_STATE_CACHE; + batch->ptr += 4; + used = batch->ptr - batch->map; + } + + /* Round batchbuffer usage to 2 DWORDs. + */ + if ((used & 4) == 0) { + *(GLuint *) (batch->ptr) = 0; /* noop */ + batch->ptr += 4; + used = batch->ptr - batch->map; + } + + /* Mark the end of the buffer. + */ + *(GLuint *) (batch->ptr) = MI_BATCH_BUFFER_END; + batch->ptr += 4; + used = batch->ptr - batch->map; + + batch->sws->bo_flush_range(batch->buf, 0, used); + batch->sws->bo_unmap(batch->buf); + batch->map = NULL; + batch->ptr = NULL; + + batch->sws->bo_exec(batch->buf, used ); + + if (BRW_DEBUG & DEBUG_SYNC) { + /* Abuse map/unmap to achieve wait-for-fence. + * + * XXX: hide this inside the winsys and export a fence + * interface. + */ + debug_printf("waiting for idle\n"); + batch->sws->bo_wait_idle(batch->buf); + } + + /* Reset the buffer: + */ + brw_batchbuffer_reset(batch); +} + + +/* The OUT_RELOC() macro ends up here, generating a relocation within + * the batch buffer. + */ +enum pipe_error +brw_batchbuffer_emit_reloc(struct brw_batchbuffer *batch, + struct brw_winsys_buffer *buffer, + enum brw_buffer_usage usage, + uint32_t delta) +{ + int ret; + + if (batch->ptr - batch->map > batch->buf->size) { + debug_printf("bad relocation ptr %p map %p offset %li size %i\n", + batch->ptr, batch->map, (long) (batch->ptr - batch->map), batch->buf->size); + + return PIPE_ERROR_OUT_OF_MEMORY; + } + + ret = batch->sws->bo_emit_reloc(batch->buf, + usage, + delta, + batch->ptr - batch->map, + buffer); + if (ret != 0) + return ret; + + /* bo_emit_reloc was resposible for writing a zero into the + * batchbuffer if necessary. Just need to update our pointer. + */ + batch->ptr += 4; + + return 0; +} + +enum pipe_error +brw_batchbuffer_data(struct brw_batchbuffer *batch, + const void *data, GLuint bytes, + enum cliprect_mode cliprect_mode) +{ + enum pipe_error ret; + + assert((bytes & 3) == 0); + + ret = brw_batchbuffer_require_space(batch, bytes); + if (ret) + return ret; + + memcpy(batch->ptr, data, bytes); + batch->ptr += bytes; + return 0; +} diff --git a/src/gallium/drivers/i965/brw_batchbuffer.h b/src/gallium/drivers/i965/brw_batchbuffer.h new file mode 100644 index 0000000..6ca9f61 --- /dev/null +++ b/src/gallium/drivers/i965/brw_batchbuffer.h @@ -0,0 +1,148 @@ +#ifndef BRW_BATCHBUFFER_H +#define BRW_BATCHBUFFER_H + +#include "util/u_debug.h" + +#include "brw_types.h" +#include "brw_winsys.h" +#include "brw_reg.h" + +#define BATCH_SZ 16384 +#define BATCH_RESERVED 16 + +/* All ignored: + */ +enum cliprect_mode { + IGNORE_CLIPRECTS, + LOOP_CLIPRECTS, + NO_LOOP_CLIPRECTS, + REFERENCES_CLIPRECTS +}; + + + + +struct brw_batchbuffer { + + struct brw_winsys_screen *sws; + struct brw_winsys_buffer *buf; + struct brw_chipset chipset; + + /** + * Values exported to speed up the writing the batchbuffer, + * instead of having to go trough a accesor function for + * each dword written. + */ + /*{@*/ + uint8_t *map; + uint8_t *ptr; + size_t size; + struct { + uint8_t *end_ptr; + } emit; + + + size_t relocs; + size_t max_relocs; + /*@}*/ +}; + +struct brw_batchbuffer *brw_batchbuffer_alloc( struct brw_winsys_screen *sws, + struct brw_chipset chipset ); + +void brw_batchbuffer_free(struct brw_batchbuffer *batch); + +void _brw_batchbuffer_flush(struct brw_batchbuffer *batch, + const char *file, int line); + + +enum pipe_error +brw_batchbuffer_reset(struct brw_batchbuffer *batch); + + +/* Unlike bmBufferData, this currently requires the buffer be mapped. + * Consider it a convenience function wrapping multple + * intel_buffer_dword() calls. + */ +enum pipe_error brw_batchbuffer_data(struct brw_batchbuffer *batch, + const void *data, GLuint bytes, + enum cliprect_mode cliprect_mode); + + +enum pipe_error brw_batchbuffer_emit_reloc(struct brw_batchbuffer *batch, + struct brw_winsys_buffer *buffer, + enum brw_buffer_usage usage, + uint32_t offset); + +/* Inline functions - might actually be better off with these + * non-inlined. Certainly better off switching all command packets to + * be passed as structs rather than dwords, but that's a little bit of + * work... + */ +static INLINE GLint +brw_batchbuffer_space(struct brw_batchbuffer *batch) +{ + return (batch->size - BATCH_RESERVED) - (batch->ptr - batch->map); +} + + +static INLINE void +brw_batchbuffer_emit_dword(struct brw_batchbuffer *batch, GLuint dword) +{ + assert(batch->map); + assert(brw_batchbuffer_space(batch) >= 4); + *(GLuint *) (batch->ptr) = dword; + batch->ptr += 4; +} + +static INLINE enum pipe_error +brw_batchbuffer_require_space(struct brw_batchbuffer *batch, + GLuint sz) +{ + assert(sz < batch->size - 8); + if (brw_batchbuffer_space(batch) < sz) { + assert(0); + return PIPE_ERROR_OUT_OF_MEMORY; + } +#ifdef DEBUG + batch->emit.end_ptr = batch->ptr + sz; +#endif + return 0; +} + +/* Here are the crusty old macros, to be removed: + */ +#define BEGIN_BATCH(n, cliprect_mode) do { \ + brw_batchbuffer_require_space(brw->batch, (n)*4); \ + } while (0) + +#define OUT_BATCH(d) brw_batchbuffer_emit_dword(brw->batch, d) + +#define OUT_RELOC(buf, usage, delta) do { \ + assert((unsigned) (delta) < buf->size); \ + brw_batchbuffer_emit_reloc(brw->batch, buf, \ + usage, delta); \ + } while (0) + +#ifdef DEBUG +#define ADVANCE_BATCH() do { \ + unsigned int _n = brw->batch->ptr - brw->batch->emit.end_ptr; \ + if (_n != 0) { \ + debug_printf("%s: %d too many bytes emitted to batch\n", \ + __FUNCTION__, _n); \ + abort(); \ + } \ + brw->batch->emit.end_ptr = NULL; \ + } while(0) +#else +#define ADVANCE_BATCH() +#endif + +static INLINE void +brw_batchbuffer_emit_mi_flush(struct brw_batchbuffer *batch) +{ + brw_batchbuffer_require_space(batch, 4); + brw_batchbuffer_emit_dword(batch, MI_FLUSH); +} + +#endif diff --git a/src/gallium/drivers/i965/brw_cc.c b/src/gallium/drivers/i965/brw_cc.c new file mode 100644 index 0000000..cc8e380 --- /dev/null +++ b/src/gallium/drivers/i965/brw_cc.c @@ -0,0 +1,129 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#include "brw_context.h" +#include "brw_state.h" + + +static enum pipe_error prepare_cc_vp( struct brw_context *brw ) +{ + return brw_cache_data( &brw->cache, + BRW_CC_VP, + &brw->curr.ccv, + NULL, 0, + &brw->cc.reloc[CC_RELOC_VP].bo ); +} + +const struct brw_tracked_state brw_cc_vp = { + .dirty = { + .mesa = PIPE_NEW_VIEWPORT, + .brw = BRW_NEW_CONTEXT, + .cache = 0 + }, + .prepare = prepare_cc_vp +}; + + +/* A long-winded way to OR two unsigned integers together: + */ +static INLINE struct brw_cc3 +combine_cc3( struct brw_cc3 a, struct brw_cc3 b ) +{ + union { struct brw_cc3 cc3; unsigned i; } ca, cb; + ca.cc3 = a; + cb.cc3 = b; + ca.i |= cb.i; + return ca.cc3; +} + +static INLINE struct brw_cc1 +combine_cc1( struct brw_cc1 a, struct brw_cc1 b ) +{ + union { struct brw_cc1 cc1; unsigned i; } ca, cb; + ca.cc1 = a; + cb.cc1 = b; + ca.i |= cb.i; + return ca.cc1; +} + +static INLINE struct brw_cc2 +combine_cc2( struct brw_cc2 a, struct brw_cc2 b ) +{ + union { struct brw_cc2 cc2; unsigned i; } ca, cb; + ca.cc2 = a; + cb.cc2 = b; + ca.i |= cb.i; + return ca.cc2; +} + +static int prepare_cc_unit( struct brw_context *brw ) +{ + brw->cc.cc.cc0 = brw->curr.zstencil->cc0; + brw->cc.cc.cc1 = combine_cc1( brw->curr.zstencil->cc1, brw->curr.cc1_stencil_ref ); + brw->cc.cc.cc2 = combine_cc2( brw->curr.zstencil->cc2, brw->curr.blend->cc2 ); + brw->cc.cc.cc3 = combine_cc3( brw->curr.zstencil->cc3, brw->curr.blend->cc3 ); + + brw->cc.cc.cc5 = brw->curr.blend->cc5; + brw->cc.cc.cc6 = brw->curr.blend->cc6; + brw->cc.cc.cc7 = brw->curr.zstencil->cc7; + + return brw_cache_data_sz(&brw->cache, BRW_CC_UNIT, + &brw->cc.cc, sizeof(brw->cc.cc), + brw->cc.reloc, 1, + &brw->cc.state_bo); +} + +const struct brw_tracked_state brw_cc_unit = { + .dirty = { + .mesa = PIPE_NEW_DEPTH_STENCIL_ALPHA | PIPE_NEW_BLEND, + .brw = 0, + .cache = CACHE_NEW_CC_VP + }, + .prepare = prepare_cc_unit, +}; + + +void brw_hw_cc_init( struct brw_context *brw ) +{ + make_reloc(&brw->cc.reloc[0], + BRW_USAGE_STATE, + 0, + offsetof(struct brw_cc_unit_state, cc4), + NULL); +} + + +void brw_hw_cc_cleanup( struct brw_context *brw ) +{ + bo_reference(&brw->cc.state_bo, NULL); + bo_reference(&brw->cc.reloc[0].bo, NULL); +} diff --git a/src/gallium/drivers/i965/brw_clip.c b/src/gallium/drivers/i965/brw_clip.c new file mode 100644 index 0000000..ccba205 --- /dev/null +++ b/src/gallium/drivers/i965/brw_clip.c @@ -0,0 +1,223 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "pipe/p_state.h" + +#include "util/u_math.h" + +#include "brw_screen.h" +#include "brw_batchbuffer.h" +#include "brw_defines.h" +#include "brw_context.h" +#include "brw_eu.h" +#include "brw_state.h" +#include "brw_pipe_rast.h" +#include "brw_clip.h" + + +#define FRONT_UNFILLED_BIT 0x1 +#define BACK_UNFILLED_BIT 0x2 + + +static enum pipe_error +compile_clip_prog( struct brw_context *brw, + struct brw_clip_prog_key *key, + struct brw_winsys_buffer **bo_out ) +{ + enum pipe_error ret; + struct brw_clip_compile c; + const GLuint *program; + GLuint program_size; + GLuint delta; + + memset(&c, 0, sizeof(c)); + + /* Begin the compilation: + */ + brw_init_compile(brw, &c.func); + + c.func.single_program_flow = 1; + + c.chipset = brw->chipset; + c.key = *key; + c.need_ff_sync = c.chipset.is_igdng; + + /* Need to locate the two positions present in vertex + header. + * These are currently hardcoded: + */ + c.header_position_offset = ATTR_SIZE; + + if (c.chipset.is_igdng) + delta = 3 * REG_SIZE; + else + delta = REG_SIZE; + + c.offset_hpos = delta + c.key.output_hpos * ATTR_SIZE; + + if (c.key.output_color0 != BRW_OUTPUT_NOT_PRESENT) + c.offset_color0 = delta + c.key.output_color0 * ATTR_SIZE; + + if (c.key.output_color1 != BRW_OUTPUT_NOT_PRESENT) + c.offset_color1 = delta + c.key.output_color1 * ATTR_SIZE; + + if (c.key.output_bfc0 != BRW_OUTPUT_NOT_PRESENT) + c.offset_bfc0 = delta + c.key.output_bfc0 * ATTR_SIZE; + + if (c.key.output_bfc1 != BRW_OUTPUT_NOT_PRESENT) + c.offset_bfc1 = delta + c.key.output_bfc1 * ATTR_SIZE; + + if (c.key.output_edgeflag != BRW_OUTPUT_NOT_PRESENT) + c.offset_edgeflag = delta + c.key.output_edgeflag * ATTR_SIZE; + + if (BRW_IS_IGDNG(brw)) + c.nr_regs = (c.key.nr_attrs + 1) / 2 + 3; /* are vertices packed, or reg-aligned? */ + else + c.nr_regs = (c.key.nr_attrs + 1) / 2 + 1; /* are vertices packed, or reg-aligned? */ + + c.nr_bytes = c.nr_regs * REG_SIZE; + + c.prog_data.clip_mode = c.key.clip_mode; /* XXX */ + + /* For some reason the thread is spawned with only 4 channels + * unmasked. + */ + brw_set_mask_control(&c.func, BRW_MASK_DISABLE); + + + /* Would ideally have the option of producing a program which could + * do all three: + */ + switch (key->primitive) { + case PIPE_PRIM_TRIANGLES: + if (key->do_unfilled) + brw_emit_unfilled_clip( &c ); + else + brw_emit_tri_clip( &c ); + break; + case PIPE_PRIM_LINES: + brw_emit_line_clip( &c ); + break; + case PIPE_PRIM_POINTS: + brw_emit_point_clip( &c ); + break; + default: + assert(0); + return PIPE_ERROR_BAD_INPUT; + } + + + + /* get the program + */ + ret = brw_get_program(&c.func, &program, &program_size); + if (ret) + return ret; + + /* Upload + */ + ret = brw_upload_cache( &brw->cache, + BRW_CLIP_PROG, + &c.key, sizeof(c.key), + NULL, 0, + program, program_size, + &c.prog_data, + &brw->clip.prog_data, + bo_out ); + if (ret) + return ret; + + return PIPE_OK; +} + +/* Calculate interpolants for triangle and line rasterization. + */ +static enum pipe_error +upload_clip_prog(struct brw_context *brw) +{ + const struct brw_vertex_shader *vs = brw->curr.vertex_shader; + struct brw_clip_prog_key key; + enum pipe_error ret; + + /* Populate the key, starting from the almost-complete version from + * the rast state. + */ + + /* PIPE_NEW_RAST */ + key = brw->curr.rast->clip_key; + + /* BRW_NEW_REDUCED_PRIMITIVE */ + key.primitive = brw->reduced_primitive; + + /* XXX: if edgeflag is moved to a proper TGSI vs output, can remove + * dependency on CACHE_NEW_VS_PROG + */ + /* CACHE_NEW_VS_PROG */ + key.nr_attrs = brw->vs.prog_data->nr_outputs; + + /* PIPE_NEW_VS */ + key.output_hpos = vs->output_hpos; + key.output_color0 = vs->output_color0; + key.output_color1 = vs->output_color1; + key.output_bfc0 = vs->output_bfc0; + key.output_bfc1 = vs->output_bfc1; + key.output_edgeflag = vs->output_edgeflag; + + /* PIPE_NEW_CLIP */ + key.nr_userclip = brw->curr.ucp.nr; + + /* Already cached? + */ + if (brw_search_cache(&brw->cache, BRW_CLIP_PROG, + &key, sizeof(key), + NULL, 0, + &brw->clip.prog_data, + &brw->clip.prog_bo)) + return PIPE_OK; + + /* Compile new program: + */ + ret = compile_clip_prog( brw, &key, &brw->clip.prog_bo ); + if (ret) + return ret; + + return PIPE_OK; +} + + +const struct brw_tracked_state brw_clip_prog = { + .dirty = { + .mesa = (PIPE_NEW_RAST | + PIPE_NEW_CLIP), + .brw = (BRW_NEW_REDUCED_PRIMITIVE), + .cache = CACHE_NEW_VS_PROG + }, + .prepare = upload_clip_prog +}; diff --git a/src/gallium/drivers/i965/brw_clip.h b/src/gallium/drivers/i965/brw_clip.h new file mode 100644 index 0000000..80e3a11 --- /dev/null +++ b/src/gallium/drivers/i965/brw_clip.h @@ -0,0 +1,199 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#ifndef BRW_CLIP_H +#define BRW_CLIP_H + +#include "pipe/p_state.h" +#include "brw_reg.h" +#include "brw_eu.h" + +#define MAX_VERTS (3+6+6) + +/* Note that if unfilled primitives are being emitted, we have to fix + * up polygon offset and flatshading at this point: + */ +struct brw_clip_prog_key { + GLuint nr_attrs:6; + GLuint primitive:4; + GLuint nr_userclip:3; + GLuint do_flat_shading:1; + GLuint do_unfilled:1; + GLuint fill_cw:2; /* includes cull information */ + GLuint fill_ccw:2; /* includes cull information */ + GLuint offset_cw:1; + GLuint offset_ccw:1; + GLuint copy_bfc_cw:1; + GLuint copy_bfc_ccw:1; + GLuint clip_mode:3; + GLuint output_hpos:6; /* not always zero? */ + + GLuint output_color0:6; + GLuint output_color1:6; + GLuint output_bfc0:6; + GLuint output_bfc1:6; + GLuint output_edgeflag:6; + GLuint pad1:2; + + GLfloat offset_factor; + GLfloat offset_units; +}; + +struct brw_clip_prog_data { + GLuint curb_read_length; /* user planes? */ + GLuint clip_mode; + GLuint urb_read_length; + GLuint total_grf; +}; + +#define CLIP_LINE 0 +#define CLIP_POINT 1 +#define CLIP_FILL 2 +#define CLIP_CULL 3 + + +#define PRIM_MASK (0x1f) + +struct brw_clip_compile { + struct brw_compile func; + struct brw_clip_prog_key key; + struct brw_clip_prog_data prog_data; + + struct { + struct brw_reg R0; + struct brw_reg vertex[MAX_VERTS]; + + struct brw_reg t; + struct brw_reg t0, t1; + struct brw_reg dp0, dp1; + + struct brw_reg dpPrev; + struct brw_reg dp; + struct brw_reg loopcount; + struct brw_reg nr_verts; + struct brw_reg planemask; + + struct brw_reg inlist; + struct brw_reg outlist; + struct brw_reg freelist; + + struct brw_reg dir; + struct brw_reg tmp0, tmp1; + struct brw_reg offset; + + struct brw_reg fixed_planes; + struct brw_reg plane_equation; + + struct brw_reg ff_sync; + } reg; + + /* 3 different ways of expressing vertex size, including + * key.nr_attrs. + */ + GLuint nr_regs; + GLuint nr_bytes; + + GLuint first_tmp; + GLuint last_tmp; + + GLboolean need_direction; + struct brw_chipset chipset; + + GLuint last_mrf; + + GLuint header_position_offset; + GLboolean need_ff_sync; + + GLuint nr_color_attrs; + GLuint offset_color0; + GLuint offset_color1; + GLuint offset_bfc0; + GLuint offset_bfc1; + + GLuint offset_hpos; + GLuint offset_edgeflag; +}; + +#define ATTR_SIZE (4*4) + +/* Points are only culled, so no need for a clip routine, however it + * works out easier to have a dummy one. + */ +void brw_emit_unfilled_clip( struct brw_clip_compile *c ); +void brw_emit_tri_clip( struct brw_clip_compile *c ); +void brw_emit_line_clip( struct brw_clip_compile *c ); +void brw_emit_point_clip( struct brw_clip_compile *c ); + +/* brw_clip_tri.c, for use by the unfilled clip routine: + */ +void brw_clip_tri_init_vertices( struct brw_clip_compile *c ); +void brw_clip_tri_flat_shade( struct brw_clip_compile *c ); +void brw_clip_tri( struct brw_clip_compile *c ); +void brw_clip_tri_emit_polygon( struct brw_clip_compile *c ); +void brw_clip_tri_alloc_regs( struct brw_clip_compile *c, + GLuint nr_verts ); + + +/* Utils: + */ + +void brw_clip_interp_vertex( struct brw_clip_compile *c, + struct brw_indirect dest_ptr, + struct brw_indirect v0_ptr, /* from */ + struct brw_indirect v1_ptr, /* to */ + struct brw_reg t0, + GLboolean force_edgeflag ); + +void brw_clip_init_planes( struct brw_clip_compile *c ); + +void brw_clip_emit_vue(struct brw_clip_compile *c, + struct brw_indirect vert, + GLboolean allocate, + GLboolean eot, + GLuint header); + +void brw_clip_kill_thread(struct brw_clip_compile *c); + +struct brw_reg brw_clip_plane_stride( struct brw_clip_compile *c ); +struct brw_reg brw_clip_plane0_address( struct brw_clip_compile *c ); + +void brw_clip_copy_colors( struct brw_clip_compile *c, + GLuint to, GLuint from ); + +void brw_clip_init_clipmask( struct brw_clip_compile *c ); + +struct brw_reg get_tmp( struct brw_clip_compile *c ); + +void brw_clip_project_position(struct brw_clip_compile *c, + struct brw_reg pos ); +void brw_clip_ff_sync(struct brw_clip_compile *c); +void brw_clip_init_ff_sync(struct brw_clip_compile *c); +#endif diff --git a/src/gallium/drivers/i965/brw_clip_line.c b/src/gallium/drivers/i965/brw_clip_line.c new file mode 100644 index 0000000..66caadc --- /dev/null +++ b/src/gallium/drivers/i965/brw_clip_line.c @@ -0,0 +1,270 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_debug.h" + +#include "brw_defines.h" +#include "brw_eu.h" +#include "brw_clip.h" + + + + +static void brw_clip_line_alloc_regs( struct brw_clip_compile *c ) +{ + GLuint i = 0,j; + + /* Register usage is static, precompute here: + */ + c->reg.R0 = retype(brw_vec8_grf(i, 0), BRW_REGISTER_TYPE_UD); i++; + + if (c->key.nr_userclip) { + c->reg.fixed_planes = brw_vec4_grf(i, 0); + i += (6 + c->key.nr_userclip + 1) / 2; + + c->prog_data.curb_read_length = (6 + c->key.nr_userclip + 1) / 2; + } + else + c->prog_data.curb_read_length = 0; + + + /* Payload vertices plus space for more generated vertices: + */ + for (j = 0; j < 4; j++) { + c->reg.vertex[j] = brw_vec4_grf(i, 0); + i += c->nr_regs; + } + + c->reg.t = brw_vec1_grf(i, 0); + c->reg.t0 = brw_vec1_grf(i, 1); + c->reg.t1 = brw_vec1_grf(i, 2); + c->reg.planemask = retype(brw_vec1_grf(i, 3), BRW_REGISTER_TYPE_UD); + c->reg.plane_equation = brw_vec4_grf(i, 4); + i++; + + c->reg.dp0 = brw_vec1_grf(i, 0); /* fixme - dp4 will clobber r.1,2,3 */ + c->reg.dp1 = brw_vec1_grf(i, 4); + i++; + + if (!c->key.nr_userclip) { + c->reg.fixed_planes = brw_vec8_grf(i, 0); + i++; + } + + if (c->need_ff_sync) { + c->reg.ff_sync = retype(brw_vec1_grf(i, 0), BRW_REGISTER_TYPE_UD); + i++; + } + + c->first_tmp = i; + c->last_tmp = i; + + c->prog_data.urb_read_length = c->nr_regs; /* ? */ + c->prog_data.total_grf = i; +} + + + +/* Line clipping, more or less following the following algorithm: + * + * for (p=0;p t1) t1 = t; + * } else { + * GLfloat t = dp0 / (dp0 - dp1); + * if (t > t0) t0 = t; + * } + * + * if (t0 + t1 >= 1.0) + * return; + * } + * } + * + * interp( ctx, newvtx0, vtx0, vtx1, t0 ); + * interp( ctx, newvtx1, vtx1, vtx0, t1 ); + * + */ +static void clip_and_emit_line( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_indirect vtx0 = brw_indirect(0, 0); + struct brw_indirect vtx1 = brw_indirect(1, 0); + struct brw_indirect newvtx0 = brw_indirect(2, 0); + struct brw_indirect newvtx1 = brw_indirect(3, 0); + struct brw_indirect plane_ptr = brw_indirect(4, 0); + struct brw_instruction *plane_loop; + struct brw_instruction *plane_active; + struct brw_instruction *is_negative; + struct brw_instruction *is_neg2 = NULL; + struct brw_instruction *not_culled; + struct brw_reg v1_null_ud = retype(vec1(brw_null_reg()), BRW_REGISTER_TYPE_UD); + + brw_MOV(p, get_addr_reg(vtx0), brw_address(c->reg.vertex[0])); + brw_MOV(p, get_addr_reg(vtx1), brw_address(c->reg.vertex[1])); + brw_MOV(p, get_addr_reg(newvtx0), brw_address(c->reg.vertex[2])); + brw_MOV(p, get_addr_reg(newvtx1), brw_address(c->reg.vertex[3])); + brw_MOV(p, get_addr_reg(plane_ptr), brw_clip_plane0_address(c)); + + /* Note: init t0, t1 together: + */ + brw_MOV(p, vec2(c->reg.t0), brw_imm_f(0)); + + brw_clip_init_planes(c); + brw_clip_init_clipmask(c); + + /* -ve rhw workaround */ + if (c->chipset.is_965) { + brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ); + brw_AND(p, brw_null_reg(), get_element_ud(c->reg.R0, 2), + brw_imm_ud(1<<20)); + brw_OR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud(0x3f)); + } + + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + + plane_loop = brw_DO(p, BRW_EXECUTE_1); + { + /* if (planemask & 1) + */ + brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ); + brw_AND(p, v1_null_ud, c->reg.planemask, brw_imm_ud(1)); + + plane_active = brw_IF(p, BRW_EXECUTE_1); + { + if (c->key.nr_userclip) + brw_MOV(p, c->reg.plane_equation, deref_4f(plane_ptr, 0)); + else + brw_MOV(p, c->reg.plane_equation, deref_4b(plane_ptr, 0)); + + /* dp = DP4(vtx->position, plane) + */ + brw_DP4(p, vec4(c->reg.dp0), deref_4f(vtx0, c->offset_hpos), c->reg.plane_equation); + + /* if (IS_NEGATIVE(dp1)) + */ + brw_set_conditionalmod(p, BRW_CONDITIONAL_L); + brw_DP4(p, vec4(c->reg.dp1), deref_4f(vtx1, c->offset_hpos), c->reg.plane_equation); + is_negative = brw_IF(p, BRW_EXECUTE_1); + { + /* + * Both can be negative on GM965/G965 due to RHW workaround + * if so, this object should be rejected. + */ + if (c->chipset.is_965) { + brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_LE, c->reg.dp0, brw_imm_f(0.0)); + is_neg2 = brw_IF(p, BRW_EXECUTE_1); + { + brw_clip_kill_thread(c); + } + brw_ENDIF(p, is_neg2); + } + + brw_ADD(p, c->reg.t, c->reg.dp1, negate(c->reg.dp0)); + brw_math_invert(p, c->reg.t, c->reg.t); + brw_MUL(p, c->reg.t, c->reg.t, c->reg.dp1); + + brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_G, c->reg.t, c->reg.t1 ); + brw_MOV(p, c->reg.t1, c->reg.t); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + } + is_negative = brw_ELSE(p, is_negative); + { + /* Coming back in. We know that both cannot be negative + * because the line would have been culled in that case. + */ + + /* If both are positive, do nothing */ + /* Only on GM965/G965 */ + if (c->chipset.is_965) { + brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_L, c->reg.dp0, brw_imm_f(0.0)); + is_neg2 = brw_IF(p, BRW_EXECUTE_1); + } + + { + brw_ADD(p, c->reg.t, c->reg.dp0, negate(c->reg.dp1)); + brw_math_invert(p, c->reg.t, c->reg.t); + brw_MUL(p, c->reg.t, c->reg.t, c->reg.dp0); + + brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_G, c->reg.t, c->reg.t0 ); + brw_MOV(p, c->reg.t0, c->reg.t); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + } + + if (c->chipset.is_965) { + brw_ENDIF(p, is_neg2); + } + } + brw_ENDIF(p, is_negative); + } + brw_ENDIF(p, plane_active); + + /* plane_ptr++; + */ + brw_ADD(p, get_addr_reg(plane_ptr), get_addr_reg(plane_ptr), brw_clip_plane_stride(c)); + + /* while (planemask>>=1) != 0 + */ + brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ); + brw_SHR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud(1)); + } + brw_WHILE(p, plane_loop); + + brw_ADD(p, c->reg.t, c->reg.t0, c->reg.t1); + brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_L, c->reg.t, brw_imm_f(1.0)); + not_culled = brw_IF(p, BRW_EXECUTE_1); + { + brw_clip_interp_vertex(c, newvtx0, vtx0, vtx1, c->reg.t0, FALSE); + brw_clip_interp_vertex(c, newvtx1, vtx1, vtx0, c->reg.t1, FALSE); + + brw_clip_emit_vue(c, newvtx0, 1, 0, (_3DPRIM_LINESTRIP << 2) | R02_PRIM_START); + brw_clip_emit_vue(c, newvtx1, 0, 1, (_3DPRIM_LINESTRIP << 2) | R02_PRIM_END); + } + brw_ENDIF(p, not_culled); + brw_clip_kill_thread(c); +} + + + +void brw_emit_line_clip( struct brw_clip_compile *c ) +{ + brw_clip_line_alloc_regs(c); + brw_clip_init_ff_sync(c); + + if (c->key.do_flat_shading) + brw_clip_copy_colors(c, 0, 1); + + clip_and_emit_line(c); +} diff --git a/src/gallium/drivers/i965/brw_clip_point.c b/src/gallium/drivers/i965/brw_clip_point.c new file mode 100644 index 0000000..124156c --- /dev/null +++ b/src/gallium/drivers/i965/brw_clip_point.c @@ -0,0 +1,47 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "brw_defines.h" +#include "brw_eu.h" +#include "brw_clip.h" + + +/* Point clipping, nothing to do? + */ +void brw_emit_point_clip( struct brw_clip_compile *c ) +{ + /* Send an empty message to kill the thread: + */ + brw_clip_tri_alloc_regs(c, 0); + brw_clip_init_ff_sync(c); + + brw_clip_kill_thread(c); +} diff --git a/src/gallium/drivers/i965/brw_clip_state.c b/src/gallium/drivers/i965/brw_clip_state.c new file mode 100644 index 0000000..5c3ccfd --- /dev/null +++ b/src/gallium/drivers/i965/brw_clip_state.c @@ -0,0 +1,209 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_math.h" + +#include "brw_context.h" +#include "brw_clip.h" +#include "brw_state.h" +#include "brw_defines.h" +#include "brw_debug.h" + +struct brw_clip_unit_key { + unsigned int total_grf; + unsigned int urb_entry_read_length; + unsigned int curb_entry_read_length; + unsigned int clip_mode; + + unsigned int curbe_offset; + + unsigned int nr_urb_entries, urb_size; + + GLboolean depth_clamp; +}; + +static void +clip_unit_populate_key(struct brw_context *brw, struct brw_clip_unit_key *key) +{ + memset(key, 0, sizeof(*key)); + + /* CACHE_NEW_CLIP_PROG */ + key->total_grf = brw->clip.prog_data->total_grf; + key->urb_entry_read_length = brw->clip.prog_data->urb_read_length; + key->curb_entry_read_length = brw->clip.prog_data->curb_read_length; + key->clip_mode = brw->clip.prog_data->clip_mode; + + /* BRW_NEW_CURBE_OFFSETS */ + key->curbe_offset = brw->curbe.clip_start; + + /* BRW_NEW_URB_FENCE */ + key->nr_urb_entries = brw->urb.nr_clip_entries; + key->urb_size = brw->urb.vsize; + + /* */ + key->depth_clamp = 0; /* XXX: add this to gallium: ctx->Transform.DepthClamp; */ +} + +static enum pipe_error +clip_unit_create_from_key(struct brw_context *brw, + struct brw_clip_unit_key *key, + struct brw_winsys_reloc *reloc, + struct brw_winsys_buffer **bo_out) +{ + struct brw_clip_unit_state clip; + enum pipe_error ret; + + memset(&clip, 0, sizeof(clip)); + + clip.thread0.grf_reg_count = align(key->total_grf, 16) / 16 - 1; + /* reloc */ + clip.thread0.kernel_start_pointer = 0; + + clip.thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754; + clip.thread1.single_program_flow = 1; + + clip.thread3.urb_entry_read_length = key->urb_entry_read_length; + clip.thread3.const_urb_entry_read_length = key->curb_entry_read_length; + clip.thread3.const_urb_entry_read_offset = key->curbe_offset * 2; + clip.thread3.dispatch_grf_start_reg = 1; + clip.thread3.urb_entry_read_offset = 0; + + clip.thread4.nr_urb_entries = key->nr_urb_entries; + clip.thread4.urb_entry_allocation_size = key->urb_size - 1; + /* If we have enough clip URB entries to run two threads, do so. + */ + if (key->nr_urb_entries >= 10) { + /* Half of the URB entries go to each thread, and it has to be an + * even number. + */ + assert(key->nr_urb_entries % 2 == 0); + + /* Although up to 16 concurrent Clip threads are allowed on IGDNG, + * only 2 threads can output VUEs at a time. + */ + if (BRW_IS_IGDNG(brw)) + clip.thread4.max_threads = 16 - 1; + else + clip.thread4.max_threads = 2 - 1; + } else { + assert(key->nr_urb_entries >= 5); + clip.thread4.max_threads = 1 - 1; + } + + if (BRW_DEBUG & DEBUG_SINGLE_THREAD) + clip.thread4.max_threads = 0; + + if (BRW_DEBUG & DEBUG_STATS) + clip.thread4.stats_enable = 1; + + clip.clip5.userclip_enable_flags = 0x7f; + clip.clip5.userclip_must_clip = 1; + clip.clip5.guard_band_enable = 0; + if (!key->depth_clamp) + clip.clip5.viewport_z_clip_enable = 1; + clip.clip5.viewport_xy_clip_enable = 1; + clip.clip5.vertex_position_space = BRW_CLIP_NDCSPACE; + clip.clip5.api_mode = BRW_CLIP_API_OGL; + clip.clip5.clip_mode = key->clip_mode; + + if (BRW_IS_G4X(brw)) + clip.clip5.negative_w_clip_test = 1; + + clip.clip6.clipper_viewport_state_ptr = 0; + clip.viewport_xmin = -1; + clip.viewport_xmax = 1; + clip.viewport_ymin = -1; + clip.viewport_ymax = 1; + + ret = brw_upload_cache(&brw->cache, BRW_CLIP_UNIT, + key, sizeof(*key), + reloc, 1, + &clip, sizeof(clip), + NULL, NULL, + bo_out); + if (ret) + return ret; + + return PIPE_OK; +} + +static int upload_clip_unit( struct brw_context *brw ) +{ + struct brw_clip_unit_key key; + struct brw_winsys_reloc reloc[1]; + unsigned grf_reg_count; + enum pipe_error ret; + + clip_unit_populate_key(brw, &key); + + grf_reg_count = align(key.total_grf, 16) / 16 - 1; + + /* clip program relocation + * + * XXX: these reloc structs are long lived and only need to be + * updated when the bound BO changes. Hopefully the stuff mixed in + * in the delta's is non-orthogonal. + */ + assert(brw->clip.prog_bo); + make_reloc(&reloc[0], + BRW_USAGE_STATE, + grf_reg_count << 1, + offsetof(struct brw_clip_unit_state, thread0), + brw->clip.prog_bo); + + + if (brw_search_cache(&brw->cache, BRW_CLIP_UNIT, + &key, sizeof(key), + reloc, 1, + NULL, + &brw->clip.state_bo)) + return PIPE_OK; + + /* Create new: + */ + ret = clip_unit_create_from_key(brw, &key, + reloc, + &brw->clip.state_bo); + if (ret) + return ret; + + return PIPE_OK; +} + +const struct brw_tracked_state brw_clip_unit = { + .dirty = { + .mesa = 0, + .brw = (BRW_NEW_CURBE_OFFSETS | + BRW_NEW_URB_FENCE), + .cache = CACHE_NEW_CLIP_PROG + }, + .prepare = upload_clip_unit, +}; diff --git a/src/gallium/drivers/i965/brw_clip_tri.c b/src/gallium/drivers/i965/brw_clip_tri.c new file mode 100644 index 0000000..069524b --- /dev/null +++ b/src/gallium/drivers/i965/brw_clip_tri.c @@ -0,0 +1,594 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "brw_defines.h" +#include "brw_eu.h" +#include "brw_clip.h" + +static void release_tmps( struct brw_clip_compile *c ) +{ + c->last_tmp = c->first_tmp; +} + + +void brw_clip_tri_alloc_regs( struct brw_clip_compile *c, + GLuint nr_verts ) +{ + GLuint i = 0,j; + + /* Register usage is static, precompute here: + */ + c->reg.R0 = retype(brw_vec8_grf(i, 0), BRW_REGISTER_TYPE_UD); i++; + + if (c->key.nr_userclip) { + c->reg.fixed_planes = brw_vec4_grf(i, 0); + i += (6 + c->key.nr_userclip + 1) / 2; + + c->prog_data.curb_read_length = (6 + c->key.nr_userclip + 1) / 2; + } + else + c->prog_data.curb_read_length = 0; + + + /* Payload vertices plus space for more generated vertices: + */ + for (j = 0; j < nr_verts; j++) { + c->reg.vertex[j] = brw_vec4_grf(i, 0); + i += c->nr_regs; + } + + if (c->key.nr_attrs & 1) { + for (j = 0; j < 3; j++) { + GLuint delta = c->key.nr_attrs*16 + 32; + + if (c->chipset.is_igdng) + delta = c->key.nr_attrs * 16 + 32 * 3; + + brw_MOV(&c->func, byte_offset(c->reg.vertex[j], delta), brw_imm_f(0)); + } + } + + c->reg.t = brw_vec1_grf(i, 0); + c->reg.loopcount = retype(brw_vec1_grf(i, 1), BRW_REGISTER_TYPE_D); + c->reg.nr_verts = retype(brw_vec1_grf(i, 2), BRW_REGISTER_TYPE_UD); + c->reg.planemask = retype(brw_vec1_grf(i, 3), BRW_REGISTER_TYPE_UD); + c->reg.plane_equation = brw_vec4_grf(i, 4); + i++; + + c->reg.dpPrev = brw_vec1_grf(i, 0); /* fixme - dp4 will clobber r.1,2,3 */ + c->reg.dp = brw_vec1_grf(i, 4); + i++; + + c->reg.inlist = brw_uw16_reg(BRW_GENERAL_REGISTER_FILE, i, 0); + i++; + + c->reg.outlist = brw_uw16_reg(BRW_GENERAL_REGISTER_FILE, i, 0); + i++; + + c->reg.freelist = brw_uw16_reg(BRW_GENERAL_REGISTER_FILE, i, 0); + i++; + + if (!c->key.nr_userclip) { + c->reg.fixed_planes = brw_vec8_grf(i, 0); + i++; + } + + if (c->key.do_unfilled) { + c->reg.dir = brw_vec4_grf(i, 0); + c->reg.offset = brw_vec4_grf(i, 4); + i++; + c->reg.tmp0 = brw_vec4_grf(i, 0); + c->reg.tmp1 = brw_vec4_grf(i, 4); + i++; + } + + if (c->need_ff_sync) { + c->reg.ff_sync = retype(brw_vec1_grf(i, 0), BRW_REGISTER_TYPE_UD); + i++; + } + + c->first_tmp = i; + c->last_tmp = i; + + c->prog_data.urb_read_length = c->nr_regs; /* ? */ + c->prog_data.total_grf = i; +} + + + +void brw_clip_tri_init_vertices( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_reg tmp0 = c->reg.loopcount; /* handy temporary */ + struct brw_instruction *is_rev; + + /* Initial list of indices for incoming vertexes: + */ + brw_AND(p, tmp0, get_element_ud(c->reg.R0, 2), brw_imm_ud(PRIM_MASK)); + brw_CMP(p, + vec1(brw_null_reg()), + BRW_CONDITIONAL_EQ, + tmp0, + brw_imm_ud(_3DPRIM_TRISTRIP_REVERSE)); + + /* XXX: Is there an easier way to do this? Need to reverse every + * second tristrip element: Can ignore sometimes? + */ + is_rev = brw_IF(p, BRW_EXECUTE_1); + { + brw_MOV(p, get_element(c->reg.inlist, 0), brw_address(c->reg.vertex[1]) ); + brw_MOV(p, get_element(c->reg.inlist, 1), brw_address(c->reg.vertex[0]) ); + if (c->need_direction) + brw_MOV(p, c->reg.dir, brw_imm_f(-1)); + } + is_rev = brw_ELSE(p, is_rev); + { + brw_MOV(p, get_element(c->reg.inlist, 0), brw_address(c->reg.vertex[0]) ); + brw_MOV(p, get_element(c->reg.inlist, 1), brw_address(c->reg.vertex[1]) ); + if (c->need_direction) + brw_MOV(p, c->reg.dir, brw_imm_f(1)); + } + brw_ENDIF(p, is_rev); + + brw_MOV(p, get_element(c->reg.inlist, 2), brw_address(c->reg.vertex[2]) ); + brw_MOV(p, brw_vec8_grf(c->reg.outlist.nr, 0), brw_imm_f(0)); + brw_MOV(p, c->reg.nr_verts, brw_imm_ud(3)); +} + + + +void brw_clip_tri_flat_shade( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_instruction *is_poly; + struct brw_reg tmp0 = c->reg.loopcount; /* handy temporary */ + + brw_AND(p, tmp0, get_element_ud(c->reg.R0, 2), brw_imm_ud(PRIM_MASK)); + brw_CMP(p, + vec1(brw_null_reg()), + BRW_CONDITIONAL_EQ, + tmp0, + brw_imm_ud(_3DPRIM_POLYGON)); + + is_poly = brw_IF(p, BRW_EXECUTE_1); + { + brw_clip_copy_colors(c, 1, 0); + brw_clip_copy_colors(c, 2, 0); + } + is_poly = brw_ELSE(p, is_poly); + { + brw_clip_copy_colors(c, 0, 2); + brw_clip_copy_colors(c, 1, 2); + } + brw_ENDIF(p, is_poly); +} + + + +/* Use mesa's clipping algorithms, translated to GEN4 assembly. + */ +void brw_clip_tri( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_indirect vtx = brw_indirect(0, 0); + struct brw_indirect vtxPrev = brw_indirect(1, 0); + struct brw_indirect vtxOut = brw_indirect(2, 0); + struct brw_indirect plane_ptr = brw_indirect(3, 0); + struct brw_indirect inlist_ptr = brw_indirect(4, 0); + struct brw_indirect outlist_ptr = brw_indirect(5, 0); + struct brw_indirect freelist_ptr = brw_indirect(6, 0); + struct brw_instruction *plane_loop; + struct brw_instruction *plane_active; + struct brw_instruction *vertex_loop; + struct brw_instruction *next_test; + struct brw_instruction *prev_test; + + brw_MOV(p, get_addr_reg(vtxPrev), brw_address(c->reg.vertex[2]) ); + brw_MOV(p, get_addr_reg(plane_ptr), brw_clip_plane0_address(c)); + brw_MOV(p, get_addr_reg(inlist_ptr), brw_address(c->reg.inlist)); + brw_MOV(p, get_addr_reg(outlist_ptr), brw_address(c->reg.outlist)); + + brw_MOV(p, get_addr_reg(freelist_ptr), brw_address(c->reg.vertex[3]) ); + + plane_loop = brw_DO(p, BRW_EXECUTE_1); + { + /* if (planemask & 1) + */ + brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ); + brw_AND(p, vec1(brw_null_reg()), c->reg.planemask, brw_imm_ud(1)); + + plane_active = brw_IF(p, BRW_EXECUTE_1); + { + /* vtxOut = freelist_ptr++ + */ + brw_MOV(p, get_addr_reg(vtxOut), get_addr_reg(freelist_ptr) ); + brw_ADD(p, get_addr_reg(freelist_ptr), get_addr_reg(freelist_ptr), brw_imm_uw(c->nr_regs * REG_SIZE)); + + if (c->key.nr_userclip) + brw_MOV(p, c->reg.plane_equation, deref_4f(plane_ptr, 0)); + else + brw_MOV(p, c->reg.plane_equation, deref_4b(plane_ptr, 0)); + + brw_MOV(p, c->reg.loopcount, c->reg.nr_verts); + brw_MOV(p, c->reg.nr_verts, brw_imm_ud(0)); + + vertex_loop = brw_DO(p, BRW_EXECUTE_1); + { + /* vtx = *input_ptr; + */ + brw_MOV(p, get_addr_reg(vtx), deref_1uw(inlist_ptr, 0)); + + /* IS_NEGATIVE(prev) */ + brw_set_conditionalmod(p, BRW_CONDITIONAL_L); + brw_DP4(p, vec4(c->reg.dpPrev), deref_4f(vtxPrev, c->offset_hpos), c->reg.plane_equation); + prev_test = brw_IF(p, BRW_EXECUTE_1); + { + /* IS_POSITIVE(next) + */ + brw_set_conditionalmod(p, BRW_CONDITIONAL_GE); + brw_DP4(p, vec4(c->reg.dp), deref_4f(vtx, c->offset_hpos), c->reg.plane_equation); + next_test = brw_IF(p, BRW_EXECUTE_1); + { + + /* Coming back in. + */ + brw_ADD(p, c->reg.t, c->reg.dpPrev, negate(c->reg.dp)); + brw_math_invert(p, c->reg.t, c->reg.t); + brw_MUL(p, c->reg.t, c->reg.t, c->reg.dpPrev); + + /* If (vtxOut == 0) vtxOut = vtxPrev + */ + brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_EQ, get_addr_reg(vtxOut), brw_imm_uw(0) ); + brw_MOV(p, get_addr_reg(vtxOut), get_addr_reg(vtxPrev) ); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + + brw_clip_interp_vertex(c, vtxOut, vtxPrev, vtx, c->reg.t, GL_FALSE); + + /* *outlist_ptr++ = vtxOut; + * nr_verts++; + * vtxOut = 0; + */ + brw_MOV(p, deref_1uw(outlist_ptr, 0), get_addr_reg(vtxOut)); + brw_ADD(p, get_addr_reg(outlist_ptr), get_addr_reg(outlist_ptr), brw_imm_uw(sizeof(short))); + brw_ADD(p, c->reg.nr_verts, c->reg.nr_verts, brw_imm_ud(1)); + brw_MOV(p, get_addr_reg(vtxOut), brw_imm_uw(0) ); + } + brw_ENDIF(p, next_test); + + } + prev_test = brw_ELSE(p, prev_test); + { + /* *outlist_ptr++ = vtxPrev; + * nr_verts++; + */ + brw_MOV(p, deref_1uw(outlist_ptr, 0), get_addr_reg(vtxPrev)); + brw_ADD(p, get_addr_reg(outlist_ptr), get_addr_reg(outlist_ptr), brw_imm_uw(sizeof(short))); + brw_ADD(p, c->reg.nr_verts, c->reg.nr_verts, brw_imm_ud(1)); + + /* IS_NEGATIVE(next) + */ + brw_set_conditionalmod(p, BRW_CONDITIONAL_L); + brw_DP4(p, vec4(c->reg.dp), deref_4f(vtx, c->offset_hpos), c->reg.plane_equation); + next_test = brw_IF(p, BRW_EXECUTE_1); + { + /* Going out of bounds. Avoid division by zero as we + * know dp != dpPrev from DIFFERENT_SIGNS, above. + */ + brw_ADD(p, c->reg.t, c->reg.dp, negate(c->reg.dpPrev)); + brw_math_invert(p, c->reg.t, c->reg.t); + brw_MUL(p, c->reg.t, c->reg.t, c->reg.dp); + + /* If (vtxOut == 0) vtxOut = vtx + */ + brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_EQ, get_addr_reg(vtxOut), brw_imm_uw(0) ); + brw_MOV(p, get_addr_reg(vtxOut), get_addr_reg(vtx) ); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + + brw_clip_interp_vertex(c, vtxOut, vtx, vtxPrev, c->reg.t, GL_TRUE); + + /* *outlist_ptr++ = vtxOut; + * nr_verts++; + * vtxOut = 0; + */ + brw_MOV(p, deref_1uw(outlist_ptr, 0), get_addr_reg(vtxOut)); + brw_ADD(p, get_addr_reg(outlist_ptr), get_addr_reg(outlist_ptr), brw_imm_uw(sizeof(short))); + brw_ADD(p, c->reg.nr_verts, c->reg.nr_verts, brw_imm_ud(1)); + brw_MOV(p, get_addr_reg(vtxOut), brw_imm_uw(0) ); + } + brw_ENDIF(p, next_test); + } + brw_ENDIF(p, prev_test); + + /* vtxPrev = vtx; + * inlist_ptr++; + */ + brw_MOV(p, get_addr_reg(vtxPrev), get_addr_reg(vtx)); + brw_ADD(p, get_addr_reg(inlist_ptr), get_addr_reg(inlist_ptr), brw_imm_uw(sizeof(short))); + + /* while (--loopcount != 0) + */ + brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ); + brw_ADD(p, c->reg.loopcount, c->reg.loopcount, brw_imm_d(-1)); + } + brw_WHILE(p, vertex_loop); + + /* vtxPrev = *(outlist_ptr-1) OR: outlist[nr_verts-1] + * inlist = outlist + * inlist_ptr = &inlist[0] + * outlist_ptr = &outlist[0] + */ + brw_ADD(p, get_addr_reg(outlist_ptr), get_addr_reg(outlist_ptr), brw_imm_w(-2)); + brw_MOV(p, get_addr_reg(vtxPrev), deref_1uw(outlist_ptr, 0)); + brw_MOV(p, brw_vec8_grf(c->reg.inlist.nr, 0), brw_vec8_grf(c->reg.outlist.nr, 0)); + brw_MOV(p, get_addr_reg(inlist_ptr), brw_address(c->reg.inlist)); + brw_MOV(p, get_addr_reg(outlist_ptr), brw_address(c->reg.outlist)); + } + brw_ENDIF(p, plane_active); + + /* plane_ptr++; + */ + brw_ADD(p, get_addr_reg(plane_ptr), get_addr_reg(plane_ptr), brw_clip_plane_stride(c)); + + /* nr_verts >= 3 + */ + brw_CMP(p, + vec1(brw_null_reg()), + BRW_CONDITIONAL_GE, + c->reg.nr_verts, + brw_imm_ud(3)); + + /* && (planemask>>=1) != 0 + */ + brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ); + brw_SHR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud(1)); + } + brw_WHILE(p, plane_loop); +} + + + +void brw_clip_tri_emit_polygon(struct brw_clip_compile *c) +{ + struct brw_compile *p = &c->func; + struct brw_instruction *loop, *if_insn; + + /* for (loopcount = nr_verts-2; loopcount > 0; loopcount--) + */ + brw_set_conditionalmod(p, BRW_CONDITIONAL_G); + brw_ADD(p, + c->reg.loopcount, + c->reg.nr_verts, + brw_imm_d(-2)); + + if_insn = brw_IF(p, BRW_EXECUTE_1); + { + struct brw_indirect v0 = brw_indirect(0, 0); + struct brw_indirect vptr = brw_indirect(1, 0); + + brw_MOV(p, get_addr_reg(vptr), brw_address(c->reg.inlist)); + brw_MOV(p, get_addr_reg(v0), deref_1uw(vptr, 0)); + + brw_clip_emit_vue(c, v0, 1, 0, ((_3DPRIM_TRIFAN << 2) | R02_PRIM_START)); + + brw_ADD(p, get_addr_reg(vptr), get_addr_reg(vptr), brw_imm_uw(2)); + brw_MOV(p, get_addr_reg(v0), deref_1uw(vptr, 0)); + + loop = brw_DO(p, BRW_EXECUTE_1); + { + brw_clip_emit_vue(c, v0, 1, 0, (_3DPRIM_TRIFAN << 2)); + + brw_ADD(p, get_addr_reg(vptr), get_addr_reg(vptr), brw_imm_uw(2)); + brw_MOV(p, get_addr_reg(v0), deref_1uw(vptr, 0)); + + brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ); + brw_ADD(p, c->reg.loopcount, c->reg.loopcount, brw_imm_d(-1)); + } + brw_WHILE(p, loop); + + brw_clip_emit_vue(c, v0, 0, 1, ((_3DPRIM_TRIFAN << 2) | R02_PRIM_END)); + } + brw_ENDIF(p, if_insn); +} + +static void do_clip_tri( struct brw_clip_compile *c ) +{ + brw_clip_init_planes(c); + + brw_clip_tri(c); +} + + +static void maybe_do_clip_tri( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_instruction *do_clip; + + brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_NZ, c->reg.planemask, brw_imm_ud(0)); + do_clip = brw_IF(p, BRW_EXECUTE_1); + { + do_clip_tri(c); + } + brw_ENDIF(p, do_clip); +} + +static void brw_clip_test( struct brw_clip_compile *c ) +{ + struct brw_reg t = retype(get_tmp(c), BRW_REGISTER_TYPE_UD); + struct brw_reg t1 = retype(get_tmp(c), BRW_REGISTER_TYPE_UD); + struct brw_reg t2 = retype(get_tmp(c), BRW_REGISTER_TYPE_UD); + struct brw_reg t3 = retype(get_tmp(c), BRW_REGISTER_TYPE_UD); + + struct brw_reg v0 = get_tmp(c); + struct brw_reg v1 = get_tmp(c); + struct brw_reg v2 = get_tmp(c); + + struct brw_indirect vt0 = brw_indirect(0, 0); + struct brw_indirect vt1 = brw_indirect(1, 0); + struct brw_indirect vt2 = brw_indirect(2, 0); + + struct brw_compile *p = &c->func; + struct brw_instruction *is_outside; + struct brw_reg tmp0 = c->reg.loopcount; /* handy temporary */ + + brw_MOV(p, get_addr_reg(vt0), brw_address(c->reg.vertex[0])); + brw_MOV(p, get_addr_reg(vt1), brw_address(c->reg.vertex[1])); + brw_MOV(p, get_addr_reg(vt2), brw_address(c->reg.vertex[2])); + brw_MOV(p, v0, deref_4f(vt0, c->offset_hpos)); + brw_MOV(p, v1, deref_4f(vt1, c->offset_hpos)); + brw_MOV(p, v2, deref_4f(vt2, c->offset_hpos)); + brw_AND(p, c->reg.planemask, c->reg.planemask, brw_imm_ud(~0x3f)); + + /* test nearz, xmin, ymin plane */ + /* clip.xyz < -clip.w */ + brw_CMP(p, t1, BRW_CONDITIONAL_L, v0, negate(get_element(v0, 3))); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + brw_CMP(p, t2, BRW_CONDITIONAL_L, v1, negate(get_element(v1, 3))); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + brw_CMP(p, t3, BRW_CONDITIONAL_L, v2, negate(get_element(v2, 3))); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + + /* All vertices are outside of a plane, rejected */ + brw_AND(p, t, t1, t2); + brw_AND(p, t, t, t3); + brw_OR(p, tmp0, get_element(t, 0), get_element(t, 1)); + brw_OR(p, tmp0, tmp0, get_element(t, 2)); + brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ); + brw_AND(p, brw_null_reg(), tmp0, brw_imm_ud(0x1)); + is_outside = brw_IF(p, BRW_EXECUTE_1); + { + brw_clip_kill_thread(c); + } + brw_ENDIF(p, is_outside); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + + /* some vertices are inside a plane, some are outside,need to clip */ + brw_XOR(p, t, t1, t2); + brw_XOR(p, t1, t2, t3); + brw_OR(p, t, t, t1); + brw_AND(p, t, t, brw_imm_ud(0x1)); + brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_NZ, + get_element(t, 0), brw_imm_ud(0)); + brw_OR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud((1<<5))); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_NZ, + get_element(t, 1), brw_imm_ud(0)); + brw_OR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud((1<<3))); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_NZ, + get_element(t, 2), brw_imm_ud(0)); + brw_OR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud((1<<1))); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + + /* test farz, xmax, ymax plane */ + /* clip.xyz > clip.w */ + brw_CMP(p, t1, BRW_CONDITIONAL_G, v0, get_element(v0, 3)); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + brw_CMP(p, t2, BRW_CONDITIONAL_G, v1, get_element(v1, 3)); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + brw_CMP(p, t3, BRW_CONDITIONAL_G, v2, get_element(v2, 3)); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + + /* All vertices are outside of a plane, rejected */ + brw_AND(p, t, t1, t2); + brw_AND(p, t, t, t3); + brw_OR(p, tmp0, get_element(t, 0), get_element(t, 1)); + brw_OR(p, tmp0, tmp0, get_element(t, 2)); + brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ); + brw_AND(p, brw_null_reg(), tmp0, brw_imm_ud(0x1)); + is_outside = brw_IF(p, BRW_EXECUTE_1); + { + brw_clip_kill_thread(c); + } + brw_ENDIF(p, is_outside); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + + /* some vertices are inside a plane, some are outside,need to clip */ + brw_XOR(p, t, t1, t2); + brw_XOR(p, t1, t2, t3); + brw_OR(p, t, t, t1); + brw_AND(p, t, t, brw_imm_ud(0x1)); + brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_NZ, + get_element(t, 0), brw_imm_ud(0)); + brw_OR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud((1<<4))); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_NZ, + get_element(t, 1), brw_imm_ud(0)); + brw_OR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud((1<<2))); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_NZ, + get_element(t, 2), brw_imm_ud(0)); + brw_OR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud((1<<0))); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + + release_tmps(c); +} + + +void brw_emit_tri_clip( struct brw_clip_compile *c ) +{ + struct brw_instruction *neg_rhw; + struct brw_compile *p = &c->func; + brw_clip_tri_alloc_regs(c, 3 + c->key.nr_userclip + 6); + brw_clip_tri_init_vertices(c); + brw_clip_init_clipmask(c); + brw_clip_init_ff_sync(c); + + /* if -ve rhw workaround bit is set, + do cliptest */ + if (c->chipset.is_965) { + brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ); + brw_AND(p, brw_null_reg(), get_element_ud(c->reg.R0, 2), + brw_imm_ud(1<<20)); + neg_rhw = brw_IF(p, BRW_EXECUTE_1); + { + brw_clip_test(c); + } + brw_ENDIF(p, neg_rhw); + } + /* Can't push into do_clip_tri because with polygon (or quad) + * flatshading, need to apply the flatshade here because we don't + * respect the PV when converting to trifan for emit: + */ + if (c->key.do_flat_shading) + brw_clip_tri_flat_shade(c); + + if ((c->key.clip_mode == BRW_CLIPMODE_NORMAL) || + (c->key.clip_mode == BRW_CLIPMODE_KERNEL_CLIP)) + do_clip_tri(c); + else + maybe_do_clip_tri(c); + + brw_clip_tri_emit_polygon(c); + + /* Send an empty message to kill the thread: + */ + brw_clip_kill_thread(c); +} diff --git a/src/gallium/drivers/i965/brw_clip_unfilled.c b/src/gallium/drivers/i965/brw_clip_unfilled.c new file mode 100644 index 0000000..aec835b --- /dev/null +++ b/src/gallium/drivers/i965/brw_clip_unfilled.c @@ -0,0 +1,497 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "brw_defines.h" +#include "brw_eu.h" +#include "brw_util.h" +#include "brw_clip.h" + + + +/* This is performed against the original triangles, so no indirection + * required: +BZZZT! + */ +static void compute_tri_direction( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_reg e = c->reg.tmp0; + struct brw_reg f = c->reg.tmp1; + struct brw_reg v0 = byte_offset(c->reg.vertex[0], c->offset_hpos); + struct brw_reg v1 = byte_offset(c->reg.vertex[1], c->offset_hpos); + struct brw_reg v2 = byte_offset(c->reg.vertex[2], c->offset_hpos); + + + struct brw_reg v0n = get_tmp(c); + struct brw_reg v1n = get_tmp(c); + struct brw_reg v2n = get_tmp(c); + + /* Convert to NDC. + * NOTE: We can't modify the original vertex coordinates, + * as it may impact further operations. + * So, we have to keep normalized coordinates in temp registers. + * + * TBD-KC + * Try to optimize unnecessary MOV's. + */ + brw_MOV(p, v0n, v0); + brw_MOV(p, v1n, v1); + brw_MOV(p, v2n, v2); + + brw_clip_project_position(c, v0n); + brw_clip_project_position(c, v1n); + brw_clip_project_position(c, v2n); + + /* Calculate the vectors of two edges of the triangle: + */ + brw_ADD(p, e, v0n, negate(v2n)); + brw_ADD(p, f, v1n, negate(v2n)); + + /* Take their crossproduct: + */ + brw_set_access_mode(p, BRW_ALIGN_16); + brw_MUL(p, vec4(brw_null_reg()), brw_swizzle(e, 1,2,0,3), brw_swizzle(f,2,0,1,3)); + brw_MAC(p, vec4(e), negate(brw_swizzle(e, 2,0,1,3)), brw_swizzle(f,1,2,0,3)); + brw_set_access_mode(p, BRW_ALIGN_1); + + brw_MUL(p, c->reg.dir, c->reg.dir, vec4(e)); +} + + +static void cull_direction( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_instruction *ccw; + GLuint conditional; + + assert (!(c->key.fill_ccw == CLIP_CULL && + c->key.fill_cw == CLIP_CULL)); + + if (c->key.fill_ccw == CLIP_CULL) + conditional = BRW_CONDITIONAL_GE; + else + conditional = BRW_CONDITIONAL_L; + + brw_CMP(p, + vec1(brw_null_reg()), + conditional, + get_element(c->reg.dir, 2), + brw_imm_f(0)); + + ccw = brw_IF(p, BRW_EXECUTE_1); + { + brw_clip_kill_thread(c); + } + brw_ENDIF(p, ccw); +} + + + +static void copy_bfc( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_instruction *ccw; + GLuint conditional; + + /* Do we have any colors to copy? + */ + if ((c->offset_color0 == 0 || c->offset_bfc0 == 0) && + (c->offset_color1 == 0 || c->offset_bfc1 == 0)) + return; + + /* In some wierd degnerate cases we can end up testing the + * direction twice, once for culling and once for bfc copying. Oh + * well, that's what you get for setting wierd GL state. + */ + if (c->key.copy_bfc_ccw) + conditional = BRW_CONDITIONAL_GE; + else + conditional = BRW_CONDITIONAL_L; + + brw_CMP(p, + vec1(brw_null_reg()), + conditional, + get_element(c->reg.dir, 2), + brw_imm_f(0)); + + ccw = brw_IF(p, BRW_EXECUTE_1); + { + GLuint i; + + for (i = 0; i < 3; i++) { + if (c->offset_color0 && c->offset_bfc0) + brw_MOV(p, + byte_offset(c->reg.vertex[i], c->offset_color0), + byte_offset(c->reg.vertex[i], c->offset_bfc0)); + + if (c->offset_color1 && c->offset_bfc1) + brw_MOV(p, + byte_offset(c->reg.vertex[i], c->offset_color0), + byte_offset(c->reg.vertex[i], c->offset_bfc0)); + } + } + brw_ENDIF(p, ccw); +} + + + + +/* + GLfloat iz = 1.0 / dir.z; + GLfloat ac = dir.x * iz; + GLfloat bc = dir.y * iz; + offset = ctx->Polygon.OffsetUnits * DEPTH_SCALE; + offset += MAX2( abs(ac), abs(bc) ) * ctx->Polygon.OffsetFactor; + offset *= MRD; +*/ +static void compute_offset( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_reg off = c->reg.offset; + struct brw_reg dir = c->reg.dir; + + brw_math_invert(p, get_element(off, 2), get_element(dir, 2)); + brw_MUL(p, vec2(off), dir, get_element(off, 2)); + + brw_CMP(p, + vec1(brw_null_reg()), + BRW_CONDITIONAL_GE, + brw_abs(get_element(off, 0)), + brw_abs(get_element(off, 1))); + + brw_SEL(p, vec1(off), brw_abs(get_element(off, 0)), brw_abs(get_element(off, 1))); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + + brw_MUL(p, vec1(off), off, brw_imm_f(c->key.offset_factor)); + brw_ADD(p, vec1(off), off, brw_imm_f(c->key.offset_units)); +} + + +static void merge_edgeflags( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_instruction *is_poly; + struct brw_reg tmp0 = get_element_ud(c->reg.tmp0, 0); + + brw_AND(p, tmp0, get_element_ud(c->reg.R0, 2), brw_imm_ud(PRIM_MASK)); + brw_CMP(p, + vec1(brw_null_reg()), + BRW_CONDITIONAL_EQ, + tmp0, + brw_imm_ud(_3DPRIM_POLYGON)); + + /* Get away with using reg.vertex because we know that this is not + * a _3DPRIM_TRISTRIP_REVERSE: + */ + is_poly = brw_IF(p, BRW_EXECUTE_1); + { + brw_set_conditionalmod(p, BRW_CONDITIONAL_EQ); + brw_AND(p, vec1(brw_null_reg()), get_element_ud(c->reg.R0, 2), brw_imm_ud(1<<8)); + brw_MOV(p, byte_offset(c->reg.vertex[0], c->offset_edgeflag), brw_imm_f(0)); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + + brw_set_conditionalmod(p, BRW_CONDITIONAL_EQ); + brw_AND(p, vec1(brw_null_reg()), get_element_ud(c->reg.R0, 2), brw_imm_ud(1<<9)); + brw_MOV(p, byte_offset(c->reg.vertex[2], c->offset_edgeflag), brw_imm_f(0)); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + } + brw_ENDIF(p, is_poly); +} + + + +static void apply_one_offset( struct brw_clip_compile *c, + struct brw_indirect vert ) +{ + struct brw_compile *p = &c->func; + struct brw_reg z = deref_1f(vert, c->header_position_offset + + 2 * type_sz(BRW_REGISTER_TYPE_F)); + + brw_ADD(p, z, z, vec1(c->reg.offset)); +} + + + +/*********************************************************************** + * Output clipped polygon as an unfilled primitive: + */ +static void emit_lines(struct brw_clip_compile *c, + GLboolean do_offset) +{ + struct brw_compile *p = &c->func; + struct brw_instruction *loop; + struct brw_instruction *draw_edge; + struct brw_indirect v0 = brw_indirect(0, 0); + struct brw_indirect v1 = brw_indirect(1, 0); + struct brw_indirect v0ptr = brw_indirect(2, 0); + struct brw_indirect v1ptr = brw_indirect(3, 0); + + /* Need a seperate loop for offset: + */ + if (do_offset) { + brw_MOV(p, c->reg.loopcount, c->reg.nr_verts); + brw_MOV(p, get_addr_reg(v0ptr), brw_address(c->reg.inlist)); + + loop = brw_DO(p, BRW_EXECUTE_1); + { + brw_MOV(p, get_addr_reg(v0), deref_1uw(v0ptr, 0)); + brw_ADD(p, get_addr_reg(v0ptr), get_addr_reg(v0ptr), brw_imm_uw(2)); + + apply_one_offset(c, v0); + + brw_set_conditionalmod(p, BRW_CONDITIONAL_G); + brw_ADD(p, c->reg.loopcount, c->reg.loopcount, brw_imm_d(-1)); + } + brw_WHILE(p, loop); + } + + /* v1ptr = &inlist[nr_verts] + * *v1ptr = v0 + */ + brw_MOV(p, c->reg.loopcount, c->reg.nr_verts); + brw_MOV(p, get_addr_reg(v0ptr), brw_address(c->reg.inlist)); + brw_ADD(p, get_addr_reg(v1ptr), get_addr_reg(v0ptr), retype(c->reg.nr_verts, BRW_REGISTER_TYPE_UW)); + brw_ADD(p, get_addr_reg(v1ptr), get_addr_reg(v1ptr), retype(c->reg.nr_verts, BRW_REGISTER_TYPE_UW)); + brw_MOV(p, deref_1uw(v1ptr, 0), deref_1uw(v0ptr, 0)); + + loop = brw_DO(p, BRW_EXECUTE_1); + { + brw_MOV(p, get_addr_reg(v0), deref_1uw(v0ptr, 0)); + brw_MOV(p, get_addr_reg(v1), deref_1uw(v0ptr, 2)); + brw_ADD(p, get_addr_reg(v0ptr), get_addr_reg(v0ptr), brw_imm_uw(2)); + + /* draw edge if edgeflag != 0 */ + brw_CMP(p, + vec1(brw_null_reg()), BRW_CONDITIONAL_NZ, + deref_1f(v0, c->offset_edgeflag), + brw_imm_f(0)); + draw_edge = brw_IF(p, BRW_EXECUTE_1); + { + brw_clip_emit_vue(c, v0, 1, 0, (_3DPRIM_LINESTRIP << 2) | R02_PRIM_START); + brw_clip_emit_vue(c, v1, 1, 0, (_3DPRIM_LINESTRIP << 2) | R02_PRIM_END); + } + brw_ENDIF(p, draw_edge); + + brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ); + brw_ADD(p, c->reg.loopcount, c->reg.loopcount, brw_imm_d(-1)); + } + brw_WHILE(p, loop); +} + + + +static void emit_points(struct brw_clip_compile *c, + GLboolean do_offset ) +{ + struct brw_compile *p = &c->func; + struct brw_instruction *loop; + struct brw_instruction *draw_point; + + struct brw_indirect v0 = brw_indirect(0, 0); + struct brw_indirect v0ptr = brw_indirect(2, 0); + + brw_MOV(p, c->reg.loopcount, c->reg.nr_verts); + brw_MOV(p, get_addr_reg(v0ptr), brw_address(c->reg.inlist)); + + loop = brw_DO(p, BRW_EXECUTE_1); + { + brw_MOV(p, get_addr_reg(v0), deref_1uw(v0ptr, 0)); + brw_ADD(p, get_addr_reg(v0ptr), get_addr_reg(v0ptr), brw_imm_uw(2)); + + /* draw if edgeflag != 0 + */ + brw_CMP(p, + vec1(brw_null_reg()), BRW_CONDITIONAL_NZ, + deref_1f(v0, c->offset_edgeflag), + brw_imm_f(0)); + draw_point = brw_IF(p, BRW_EXECUTE_1); + { + if (do_offset) + apply_one_offset(c, v0); + + brw_clip_emit_vue(c, v0, 1, 0, (_3DPRIM_POINTLIST << 2) | R02_PRIM_START | R02_PRIM_END); + } + brw_ENDIF(p, draw_point); + + brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ); + brw_ADD(p, c->reg.loopcount, c->reg.loopcount, brw_imm_d(-1)); + } + brw_WHILE(p, loop); +} + + + + + + + +static void emit_primitives( struct brw_clip_compile *c, + GLuint mode, + GLboolean do_offset ) +{ + switch (mode) { + case CLIP_FILL: + brw_clip_tri_emit_polygon(c); + break; + + case CLIP_LINE: + emit_lines(c, do_offset); + break; + + case CLIP_POINT: + emit_points(c, do_offset); + break; + + case CLIP_CULL: + assert(0); + break; + } +} + + + +static void emit_unfilled_primitives( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_instruction *ccw; + + /* Direction culling has already been done. + */ + if (c->key.fill_ccw != c->key.fill_cw && + c->key.fill_ccw != CLIP_CULL && + c->key.fill_cw != CLIP_CULL) + { + brw_CMP(p, + vec1(brw_null_reg()), + BRW_CONDITIONAL_GE, + get_element(c->reg.dir, 2), + brw_imm_f(0)); + + ccw = brw_IF(p, BRW_EXECUTE_1); + { + emit_primitives(c, c->key.fill_ccw, c->key.offset_ccw); + } + ccw = brw_ELSE(p, ccw); + { + emit_primitives(c, c->key.fill_cw, c->key.offset_cw); + } + brw_ENDIF(p, ccw); + } + else if (c->key.fill_cw != CLIP_CULL) { + emit_primitives(c, c->key.fill_cw, c->key.offset_cw); + } + else if (c->key.fill_ccw != CLIP_CULL) { + emit_primitives(c, c->key.fill_ccw, c->key.offset_ccw); + } +} + + + + +static void check_nr_verts( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_instruction *if_insn; + + brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_L, c->reg.nr_verts, brw_imm_d(3)); + if_insn = brw_IF(p, BRW_EXECUTE_1); + { + brw_clip_kill_thread(c); + } + brw_ENDIF(p, if_insn); +} + + +void brw_emit_unfilled_clip( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_instruction *do_clip; + + + c->need_direction = ((c->key.offset_ccw || c->key.offset_cw) || + (c->key.fill_ccw != c->key.fill_cw) || + c->key.fill_ccw == CLIP_CULL || + c->key.fill_cw == CLIP_CULL || + c->key.copy_bfc_cw || + c->key.copy_bfc_ccw); + + brw_clip_tri_alloc_regs(c, 3 + c->key.nr_userclip + 6); + brw_clip_tri_init_vertices(c); + brw_clip_init_ff_sync(c); + + assert(c->offset_edgeflag); + + if (c->key.fill_ccw == CLIP_CULL && + c->key.fill_cw == CLIP_CULL) { + brw_clip_kill_thread(c); + return; + } + + merge_edgeflags(c); + + /* Need to use the inlist indirection here: + */ + if (c->need_direction) + compute_tri_direction(c); + + if (c->key.fill_ccw == CLIP_CULL || + c->key.fill_cw == CLIP_CULL) + cull_direction(c); + + if (c->key.offset_ccw || + c->key.offset_cw) + compute_offset(c); + + if (c->key.copy_bfc_ccw || + c->key.copy_bfc_cw) + copy_bfc(c); + + /* Need to do this whether we clip or not: + */ + if (c->key.do_flat_shading) + brw_clip_tri_flat_shade(c); + + brw_clip_init_clipmask(c); + brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_NZ, c->reg.planemask, brw_imm_ud(0)); + do_clip = brw_IF(p, BRW_EXECUTE_1); + { + brw_clip_init_planes(c); + brw_clip_tri(c); + check_nr_verts(c); + } + brw_ENDIF(p, do_clip); + + emit_unfilled_primitives(c); + brw_clip_kill_thread(c); +} + + + diff --git a/src/gallium/drivers/i965/brw_clip_util.c b/src/gallium/drivers/i965/brw_clip_util.c new file mode 100644 index 0000000..23e51ee --- /dev/null +++ b/src/gallium/drivers/i965/brw_clip_util.c @@ -0,0 +1,387 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#include "brw_defines.h" +#include "brw_eu.h" +#include "brw_clip.h" + + + + +struct brw_reg get_tmp( struct brw_clip_compile *c ) +{ + struct brw_reg tmp = brw_vec4_grf(c->last_tmp, 0); + + if (++c->last_tmp > c->prog_data.total_grf) + c->prog_data.total_grf = c->last_tmp; + + return tmp; +} + +static void release_tmp( struct brw_clip_compile *c, struct brw_reg tmp ) +{ + if (tmp.nr == c->last_tmp-1) + c->last_tmp--; +} + + +static struct brw_reg make_plane_ud(GLuint x, GLuint y, GLuint z, GLuint w) +{ + return brw_imm_ud((w<<24) | (z<<16) | (y<<8) | x); +} + + +void brw_clip_init_planes( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + + if (!c->key.nr_userclip) { + brw_MOV(p, get_element_ud(c->reg.fixed_planes, 0), make_plane_ud( 0, 0, 0xff, 1)); + brw_MOV(p, get_element_ud(c->reg.fixed_planes, 1), make_plane_ud( 0, 0, 1, 1)); + brw_MOV(p, get_element_ud(c->reg.fixed_planes, 2), make_plane_ud( 0, 0xff, 0, 1)); + brw_MOV(p, get_element_ud(c->reg.fixed_planes, 3), make_plane_ud( 0, 1, 0, 1)); + brw_MOV(p, get_element_ud(c->reg.fixed_planes, 4), make_plane_ud(0xff, 0, 0, 1)); + brw_MOV(p, get_element_ud(c->reg.fixed_planes, 5), make_plane_ud( 1, 0, 0, 1)); + } +} + + + +#define W 3 + +/* Project 'pos' to screen space (or back again), overwrite with results: + */ +void brw_clip_project_position(struct brw_clip_compile *c, struct brw_reg pos ) +{ + struct brw_compile *p = &c->func; + + /* calc rhw + */ + brw_math_invert(p, get_element(pos, W), get_element(pos, W)); + + /* value.xyz *= value.rhw + */ + brw_set_access_mode(p, BRW_ALIGN_16); + brw_MUL(p, brw_writemask(pos, BRW_WRITEMASK_XYZ), pos, brw_swizzle1(pos, W)); + brw_set_access_mode(p, BRW_ALIGN_1); +} + + +static void brw_clip_project_vertex( struct brw_clip_compile *c, + struct brw_indirect vert_addr ) +{ + struct brw_compile *p = &c->func; + struct brw_reg tmp = get_tmp(c); + + /* Fixup position. Extract from the original vertex and re-project + * to screen space: + */ + brw_MOV(p, tmp, deref_4f(vert_addr, c->offset_hpos)); + brw_clip_project_position(c, tmp); + brw_MOV(p, deref_4f(vert_addr, c->header_position_offset), tmp); + + release_tmp(c, tmp); +} + + + + +/* Interpolate between two vertices and put the result into a0.0. + * Increment a0.0 accordingly. + */ +void brw_clip_interp_vertex( struct brw_clip_compile *c, + struct brw_indirect dest_ptr, + struct brw_indirect v0_ptr, /* from */ + struct brw_indirect v1_ptr, /* to */ + struct brw_reg t0, + GLboolean force_edgeflag) +{ + struct brw_compile *p = &c->func; + struct brw_reg tmp = get_tmp(c); + GLuint i; + + /* Just copy the vertex header: + */ + /* + * After CLIP stage, only first 256 bits of the VUE are read + * back on IGDNG, so needn't change it + */ + brw_copy_indirect_to_indirect(p, dest_ptr, v0_ptr, 1); + + /* Iterate over each attribute (could be done in pairs?) + */ + for (i = 0; i < c->key.nr_attrs; i++) { + GLuint delta = i*16 + 32; + + if (c->chipset.is_igdng) + delta = i * 16 + 32 * 3; + + if (delta == c->offset_edgeflag) { + if (force_edgeflag) + brw_MOV(p, deref_4f(dest_ptr, delta), brw_imm_f(1)); + else + brw_MOV(p, deref_4f(dest_ptr, delta), deref_4f(v0_ptr, delta)); + } + else { + /* Interpolate: + * + * New = attr0 + t*attr1 - t*attr0 + */ + brw_MUL(p, + vec4(brw_null_reg()), + deref_4f(v1_ptr, delta), + t0); + + brw_MAC(p, + tmp, + negate(deref_4f(v0_ptr, delta)), + t0); + + brw_ADD(p, + deref_4f(dest_ptr, delta), + deref_4f(v0_ptr, delta), + tmp); + } + } + + if (i & 1) { + GLuint delta = i*16 + 32; + + if (c->chipset.is_igdng) + delta = i * 16 + 32 * 3; + + brw_MOV(p, deref_4f(dest_ptr, delta), brw_imm_f(0)); + } + + release_tmp(c, tmp); + + /* Recreate the projected (NDC) coordinate in the new vertex + * header: + */ + brw_clip_project_vertex(c, dest_ptr ); +} + + + + +#define MAX_MRF 16 + +void brw_clip_emit_vue(struct brw_clip_compile *c, + struct brw_indirect vert, + GLboolean allocate, + GLboolean eot, + GLuint header) +{ + struct brw_compile *p = &c->func; + GLuint start = c->last_mrf; + + brw_clip_ff_sync(c); + + assert(!(allocate && eot)); + + /* Cycle through mrf regs - probably futile as we have to wait for + * the allocation response anyway. Also, the order this function + * is invoked doesn't correspond to the order the instructions will + * be executed, so it won't have any effect in many cases. + */ +#if 0 + if (start + c->nr_regs + 1 >= MAX_MRF) + start = 0; + + c->last_mrf = start + c->nr_regs + 1; +#endif + + /* Copy the vertex from vertn into m1..mN+1: + */ + brw_copy_from_indirect(p, brw_message_reg(start+1), vert, c->nr_regs); + + /* Overwrite PrimType and PrimStart in the message header, for + * each vertex in turn: + */ + brw_MOV(p, get_element_ud(c->reg.R0, 2), brw_imm_ud(header)); + + + /* Send each vertex as a seperate write to the urb. This + * is different to the concept in brw_sf_emit.c, where + * subsequent writes are used to build up a single urb + * entry. Each of these writes instantiates a seperate + * urb entry - (I think... what about 'allocate'?) + */ + brw_urb_WRITE(p, + allocate ? c->reg.R0 : retype(brw_null_reg(), BRW_REGISTER_TYPE_UD), + start, + c->reg.R0, + allocate, + 1, /* used */ + c->nr_regs + 1, /* msg length */ + allocate ? 1 : 0, /* response_length */ + eot, /* eot */ + 1, /* writes_complete */ + 0, /* urb offset */ + BRW_URB_SWIZZLE_NONE); +} + + + +void brw_clip_kill_thread(struct brw_clip_compile *c) +{ + struct brw_compile *p = &c->func; + + brw_clip_ff_sync(c); + /* Send an empty message to kill the thread and release any + * allocated urb entry: + */ + brw_urb_WRITE(p, + retype(brw_null_reg(), BRW_REGISTER_TYPE_UD), + 0, + c->reg.R0, + 0, /* allocate */ + 0, /* used */ + 1, /* msg len */ + 0, /* response len */ + 1, /* eot */ + 1, /* writes complete */ + 0, + BRW_URB_SWIZZLE_NONE); +} + + + + +struct brw_reg brw_clip_plane0_address( struct brw_clip_compile *c ) +{ + return brw_address(c->reg.fixed_planes); +} + + +struct brw_reg brw_clip_plane_stride( struct brw_clip_compile *c ) +{ + if (c->key.nr_userclip) { + return brw_imm_uw(16); + } + else { + return brw_imm_uw(4); + } +} + + +/* If flatshading, distribute color from provoking vertex prior to + * clipping. + */ +void brw_clip_copy_colors( struct brw_clip_compile *c, + GLuint to, GLuint from ) +{ + struct brw_compile *p = &c->func; + + if (c->offset_color0) + brw_MOV(p, + byte_offset(c->reg.vertex[to], c->offset_color0), + byte_offset(c->reg.vertex[from], c->offset_color0)); + + if (c->offset_color1) + brw_MOV(p, + byte_offset(c->reg.vertex[to], c->offset_color1), + byte_offset(c->reg.vertex[from], c->offset_color1)); + + if (c->offset_bfc0) + brw_MOV(p, + byte_offset(c->reg.vertex[to], c->offset_bfc0), + byte_offset(c->reg.vertex[from], c->offset_bfc0)); + + if (c->offset_bfc1) + brw_MOV(p, + byte_offset(c->reg.vertex[to], c->offset_bfc1), + byte_offset(c->reg.vertex[from], c->offset_bfc1)); +} + + + +void brw_clip_init_clipmask( struct brw_clip_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_reg incoming = get_element_ud(c->reg.R0, 2); + + /* Shift so that lowest outcode bit is rightmost: + */ + brw_SHR(p, c->reg.planemask, incoming, brw_imm_ud(26)); + + if (c->key.nr_userclip) { + struct brw_reg tmp = retype(vec1(get_tmp(c)), BRW_REGISTER_TYPE_UD); + + /* Rearrange userclip outcodes so that they come directly after + * the fixed plane bits. + */ + brw_AND(p, tmp, incoming, brw_imm_ud(0x3f<<14)); + brw_SHR(p, tmp, tmp, brw_imm_ud(8)); + brw_OR(p, c->reg.planemask, c->reg.planemask, tmp); + + release_tmp(c, tmp); + } +} + +void brw_clip_ff_sync(struct brw_clip_compile *c) +{ + if (c->need_ff_sync) { + struct brw_compile *p = &c->func; + struct brw_instruction *need_ff_sync; + + brw_set_conditionalmod(p, BRW_CONDITIONAL_Z); + brw_AND(p, brw_null_reg(), c->reg.ff_sync, brw_imm_ud(0x1)); + need_ff_sync = brw_IF(p, BRW_EXECUTE_1); + { + brw_OR(p, c->reg.ff_sync, c->reg.ff_sync, brw_imm_ud(0x1)); + brw_ff_sync(p, + c->reg.R0, + 0, + c->reg.R0, + 1, + 1, /* used */ + 1, /* msg length */ + 1, /* response length */ + 0, /* eot */ + 1, /* write compelete */ + 0, /* urb offset */ + BRW_URB_SWIZZLE_NONE); + } + brw_ENDIF(p, need_ff_sync); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + } +} + +void brw_clip_init_ff_sync(struct brw_clip_compile *c) +{ + if (c->need_ff_sync) { + struct brw_compile *p = &c->func; + + brw_MOV(p, c->reg.ff_sync, brw_imm_ud(0)); + } +} diff --git a/src/gallium/drivers/i965/brw_context.c b/src/gallium/drivers/i965/brw_context.c new file mode 100644 index 0000000..a2736f7 --- /dev/null +++ b/src/gallium/drivers/i965/brw_context.c @@ -0,0 +1,159 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#include "pipe/p_context.h" +#include "util/u_inlines.h" +#include "util/u_simple_list.h" + +#include "brw_context.h" +#include "brw_draw.h" +#include "brw_state.h" +#include "brw_batchbuffer.h" +#include "brw_winsys.h" +#include "brw_resource.h" +#include "brw_screen.h" + + +static void brw_destroy_context( struct pipe_context *pipe ) +{ + struct brw_context *brw = brw_context(pipe); + int i; + + brw_context_flush( brw ); + brw_batchbuffer_free( brw->batch ); + brw_destroy_state(brw); + + brw_draw_cleanup( brw ); + + brw_pipe_blend_cleanup( brw ); + brw_pipe_depth_stencil_cleanup( brw ); + brw_pipe_framebuffer_cleanup( brw ); + brw_pipe_flush_cleanup( brw ); + brw_pipe_misc_cleanup( brw ); + brw_pipe_query_cleanup( brw ); + brw_pipe_rast_cleanup( brw ); + brw_pipe_sampler_cleanup( brw ); + brw_pipe_shader_cleanup( brw ); + brw_pipe_vertex_cleanup( brw ); + brw_pipe_clear_cleanup( brw ); + + brw_hw_cc_cleanup( brw ); + + + FREE(brw->wm.compile_data); + + for (i = 0; i < brw->curr.fb.nr_cbufs; i++) + pipe_surface_reference(&brw->curr.fb.cbufs[i], NULL); + brw->curr.fb.nr_cbufs = 0; + pipe_surface_reference(&brw->curr.fb.zsbuf, NULL); + + bo_reference(&brw->curbe.curbe_bo, NULL); + bo_reference(&brw->vs.prog_bo, NULL); + bo_reference(&brw->vs.state_bo, NULL); + bo_reference(&brw->vs.bind_bo, NULL); + bo_reference(&brw->gs.prog_bo, NULL); + bo_reference(&brw->gs.state_bo, NULL); + bo_reference(&brw->clip.prog_bo, NULL); + bo_reference(&brw->clip.state_bo, NULL); + bo_reference(&brw->clip.vp_bo, NULL); + bo_reference(&brw->sf.prog_bo, NULL); + bo_reference(&brw->sf.state_bo, NULL); + bo_reference(&brw->sf.vp_bo, NULL); + + for (i = 0; i < Elements(brw->wm.sdc_bo); i++) + bo_reference(&brw->wm.sdc_bo[i], NULL); + + bo_reference(&brw->wm.bind_bo, NULL); + + for (i = 0; i < Elements(brw->wm.surf_bo); i++) + bo_reference(&brw->wm.surf_bo[i], NULL); + + bo_reference(&brw->wm.sampler_bo, NULL); + bo_reference(&brw->wm.prog_bo, NULL); + bo_reference(&brw->wm.state_bo, NULL); +} + + +struct pipe_context *brw_create_context(struct pipe_screen *screen, + void *priv) +{ + struct brw_context *brw = (struct brw_context *) CALLOC_STRUCT(brw_context); + + if (!brw) { + debug_printf("%s: failed to alloc context\n", __FUNCTION__); + return NULL; + } + + brw->base.screen = screen; + brw->base.priv = priv; + brw->base.destroy = brw_destroy_context; + brw->sws = brw_screen(screen)->sws; + brw->chipset = brw_screen(screen)->chipset; + + brw_init_resource_functions( brw ); + brw_pipe_blend_init( brw ); + brw_pipe_depth_stencil_init( brw ); + brw_pipe_framebuffer_init( brw ); + brw_pipe_flush_init( brw ); + brw_pipe_misc_init( brw ); + brw_pipe_query_init( brw ); + brw_pipe_rast_init( brw ); + brw_pipe_sampler_init( brw ); + brw_pipe_shader_init( brw ); + brw_pipe_vertex_init( brw ); + brw_pipe_clear_init( brw ); + brw_pipe_surface_init( brw ); + + brw_hw_cc_init( brw ); + + brw_init_state( brw ); + brw_draw_init( brw ); + + brw->state.dirty.mesa = ~0; + brw->state.dirty.brw = ~0; + + brw->flags.always_emit_state = 0; + + make_empty_list(&brw->query.active_head); + + brw->batch = brw_batchbuffer_alloc( brw->sws, brw->chipset ); + if (brw->batch == NULL) + goto fail; + + return &brw->base; + +fail: + if (brw->batch) + brw_batchbuffer_free( brw->batch ); + return NULL; +} + diff --git a/src/gallium/drivers/i965/brw_context.h b/src/gallium/drivers/i965/brw_context.h new file mode 100644 index 0000000..d927f38 --- /dev/null +++ b/src/gallium/drivers/i965/brw_context.h @@ -0,0 +1,864 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#ifndef BRWCONTEXT_INC +#define BRWCONTEXT_INC + +#include "brw_structs.h" +#include "brw_winsys.h" +#include "brw_reg.h" +#include "pipe/p_state.h" +#include "pipe/p_context.h" +#include "tgsi/tgsi_scan.h" + + +/* Glossary: + * + * URB - uniform resource buffer. A mid-sized buffer which is + * partitioned between the fixed function units and used for passing + * values (vertices, primitives, constants) between them. + * + * CURBE - constant URB entry. An urb region (entry) used to hold + * constant values which the fixed function units can be instructed to + * preload into the GRF when spawning a thread. + * + * VUE - vertex URB entry. An urb entry holding a vertex and usually + * a vertex header. The header contains control information and + * things like primitive type, Begin/end flags and clip codes. + * + * PUE - primitive URB entry. An urb entry produced by the setup (SF) + * unit holding rasterization and interpolation parameters. + * + * GRF - general register file. One of several register files + * addressable by programmed threads. The inputs (r0, payload, curbe, + * urb) of the thread are preloaded to this area before the thread is + * spawned. The registers are individually 8 dwords wide and suitable + * for general usage. Registers holding thread input values are not + * special and may be overwritten. + * + * MRF - message register file. Threads communicate (and terminate) + * by sending messages. Message parameters are placed in contiguous + * MRF registers. All program output is via these messages. URB + * entries are populated by sending a message to the shared URB + * function containing the new data, together with a control word, + * often an unmodified copy of R0. + * + * R0 - GRF register 0. Typically holds control information used when + * sending messages to other threads. + * + * EU or GEN4 EU: The name of the programmable subsystem of the + * i965 hardware. Threads are executed by the EU, the registers + * described above are part of the EU architecture. + * + * Fixed function units: + * + * CS - Command streamer. Notional first unit, little software + * interaction. Holds the URB entries used for constant data, ie the + * CURBEs. + * + * VF/VS - Vertex Fetch / Vertex Shader. The fixed function part of + * this unit is responsible for pulling vertices out of vertex buffers + * in vram and injecting them into the processing pipe as VUEs. If + * enabled, it first passes them to a VS thread which is a good place + * for the driver to implement any active vertex shader. + * + * GS - Geometry Shader. This corresponds to a new DX10 concept. If + * enabled, incoming strips etc are passed to GS threads in individual + * line/triangle/point units. The GS thread may perform arbitary + * computation and emit whatever primtives with whatever vertices it + * chooses. This makes GS an excellent place to implement GL's + * unfilled polygon modes, though of course it is capable of much + * more. Additionally, GS is used to translate away primitives not + * handled by latter units, including Quads and Lineloops. + * + * CS - Clipper. Mesa's clipping algorithms are imported to run on + * this unit. The fixed function part performs cliptesting against + * the 6 fixed clipplanes and makes decisions on whether or not the + * incoming primitive needs to be passed to a thread for clipping. + * User clip planes are handled via cooperation with the VS thread. + * + * SF - Strips Fans or Setup: Triangles are prepared for + * rasterization. Interpolation coefficients are calculated. + * Flatshading and two-side lighting usually performed here. + * + * WM - Windower. Interpolation of vertex attributes performed here. + * Fragment shader implemented here. SIMD aspects of EU taken full + * advantage of, as pixels are processed in blocks of 16. + * + * CC - Color Calculator. No EU threads associated with this unit. + * Handles blending and (presumably) depth and stencil testing. + */ + +#define BRW_MAX_CURBE (32*16) + + +/* Need a value to say a particular vertex shader output isn't + * present. Limits us to 63 outputs currently. + */ +#define BRW_OUTPUT_NOT_PRESENT ((1<<6)-1) + + +struct brw_context; + +struct brw_depth_stencil_state { + /* Precalculated hardware state: + */ + struct brw_cc0 cc0; + struct brw_cc1 cc1; + struct brw_cc2 cc2; + struct brw_cc3 cc3; + struct brw_cc7 cc7; + + unsigned iz_lookup; +}; + + +struct brw_blend_state { + /* Precalculated hardware state: + */ + struct brw_cc2 cc2; + struct brw_cc3 cc3; + struct brw_cc5 cc5; + struct brw_cc6 cc6; + + struct brw_surf_ss0 ss0; +}; + +struct brw_rasterizer_state; + +struct brw_immediate_data { + unsigned nr; + float (*data)[4]; +}; + +struct brw_vertex_shader { + const struct tgsi_token *tokens; + struct brw_winsys_buffer *const_buffer; /** Program constant buffer/surface */ + + struct tgsi_shader_info info; + struct brw_immediate_data immediates; + + GLuint has_flow_control:1; + GLuint use_const_buffer:1; + + /* Offsets of special vertex shader outputs required for clipping. + */ + GLuint output_hpos:6; /* not always zero? */ + GLuint output_color0:6; + GLuint output_color1:6; + GLuint output_bfc0:6; + GLuint output_bfc1:6; + GLuint output_edgeflag:6; + + unsigned id; +}; + +struct brw_fs_signature { + GLuint nr_inputs; + struct { + GLuint interp:3; /* TGSI_INTERPOLATE_x */ + GLuint semantic:5; /* TGSI_SEMANTIC_x */ + GLuint semantic_index:24; + } input[PIPE_MAX_SHADER_INPUTS]; +}; + +#define brw_fs_signature_size(s) (offsetof(struct brw_fs_signature, input) + \ + ((s)->nr_inputs * sizeof (s)->input[0])) + + +struct brw_fragment_shader { + const struct tgsi_token *tokens; + struct tgsi_shader_info info; + + struct brw_fs_signature signature; + struct brw_immediate_data immediates; + + unsigned iz_lookup; + /*unsigned wm_lookup;*/ + + unsigned uses_depth:1; + unsigned has_flow_control:1; + + unsigned id; + struct brw_winsys_buffer *const_buffer; /** Program constant buffer/surface */ + GLboolean use_const_buffer; +}; + + +struct brw_sampler { + struct brw_ss0 ss0; + struct brw_ss1 ss1; + float border_color[4]; + struct brw_ss3 ss3; +}; + + + +#define PIPE_NEW_DEPTH_STENCIL_ALPHA 0x1 +#define PIPE_NEW_RAST 0x2 +#define PIPE_NEW_BLEND 0x4 +#define PIPE_NEW_VIEWPORT 0x8 +#define PIPE_NEW_SAMPLERS 0x10 +#define PIPE_NEW_VERTEX_BUFFER 0x20 +#define PIPE_NEW_VERTEX_ELEMENT 0x40 +#define PIPE_NEW_FRAGMENT_SHADER 0x80 +#define PIPE_NEW_VERTEX_SHADER 0x100 +#define PIPE_NEW_FRAGMENT_CONSTANTS 0x200 +#define PIPE_NEW_VERTEX_CONSTANTS 0x400 +#define PIPE_NEW_CLIP 0x800 +#define PIPE_NEW_INDEX_BUFFER 0x1000 +#define PIPE_NEW_INDEX_RANGE 0x2000 +#define PIPE_NEW_BLEND_COLOR 0x4000 +#define PIPE_NEW_POLYGON_STIPPLE 0x8000 +#define PIPE_NEW_FRAMEBUFFER_DIMENSIONS 0x10000 +#define PIPE_NEW_DEPTH_BUFFER 0x20000 +#define PIPE_NEW_COLOR_BUFFERS 0x40000 +#define PIPE_NEW_QUERY 0x80000 +#define PIPE_NEW_SCISSOR 0x100000 +#define PIPE_NEW_BOUND_TEXTURES 0x200000 +#define PIPE_NEW_NR_CBUFS 0x400000 +#define PIPE_NEW_FRAGMENT_SIGNATURE 0x800000 + + + +#define BRW_NEW_URB_FENCE 0x1 +#define BRW_NEW_FRAGMENT_PROGRAM 0x2 +#define BRW_NEW_VERTEX_PROGRAM 0x4 +#define BRW_NEW_INPUT_DIMENSIONS 0x8 +#define BRW_NEW_CURBE_OFFSETS 0x10 +#define BRW_NEW_REDUCED_PRIMITIVE 0x20 +#define BRW_NEW_PRIMITIVE 0x40 +#define BRW_NEW_CONTEXT 0x80 +#define BRW_NEW_WM_INPUT_DIMENSIONS 0x100 +#define BRW_NEW_PSP 0x800 +#define BRW_NEW_WM_SURFACES 0x1000 +#define BRW_NEW_xxx 0x2000 /* was FENCE */ +#define BRW_NEW_INDICES 0x4000 + +/** + * Used for any batch entry with a relocated pointer that will be used + * by any 3D rendering. Need to re-emit these fresh in each + * batchbuffer as the referenced buffers may be relocated in the + * meantime. + */ +#define BRW_NEW_BATCH 0x10000 +#define BRW_NEW_NR_WM_SURFACES 0x40000 +#define BRW_NEW_NR_VS_SURFACES 0x80000 +#define BRW_NEW_INDEX_BUFFER 0x100000 + +struct brw_state_flags { + /** State update flags signalled by mesa internals */ + GLuint mesa; + /** + * State update flags signalled as the result of brw_tracked_state updates + */ + GLuint brw; + /** State update flags signalled by brw_state_cache.c searches */ + GLuint cache; +}; + + + +/* Data about a particular attempt to compile a program. Note that + * there can be many of these, each in a different GL state + * corresponding to a different brw_wm_prog_key struct, with different + * compiled programs: + */ +struct brw_wm_prog_data { + GLuint curb_read_length; + GLuint urb_read_length; + + GLuint first_curbe_grf; + GLuint total_grf; + GLuint total_scratch; + + GLuint nr_params; /**< number of float params/constants */ + GLboolean error; + + /* Pointer to tracked values (only valid once + * _mesa_load_state_parameters has been called at runtime). + */ + const GLfloat *param[BRW_MAX_CURBE]; +}; + +struct brw_sf_prog_data { + GLuint urb_read_length; + GLuint total_grf; + + /* Each vertex may have upto 12 attributes, 4 components each, + * except WPOS which requires only 2. (11*4 + 2) == 44 ==> 11 + * rows. + * + * Actually we use 4 for each, so call it 12 rows. + */ + GLuint urb_entry_size; +}; + + +struct brw_clip_prog_data; + +struct brw_gs_prog_data { + GLuint urb_read_length; + GLuint total_grf; +}; + +struct brw_vs_prog_data { + GLuint curb_read_length; + GLuint urb_read_length; + GLuint total_grf; + + GLuint nr_outputs; + GLuint nr_inputs; + + GLuint nr_params; /**< number of TGSI_FILE_CONSTANT's */ + + GLboolean writes_psiz; + + /* Used for calculating urb partitions: + */ + GLuint urb_entry_size; +}; + + +/* Size == 0 if output either not written, or always [0,0,0,1] + */ +struct brw_vs_output_sizes { + GLubyte output_size[PIPE_MAX_SHADER_OUTPUTS]; +}; + + +/** Number of texture sampler units */ +#define BRW_MAX_TEX_UNIT 16 + +/** Max number of render targets in a shader */ +#define BRW_MAX_DRAW_BUFFERS 4 + +/** + * Size of our surface binding table for the WM. + * This contains pointers to the drawing surfaces and current texture + * objects and shader constant buffers (+2). + */ +#define BRW_WM_MAX_SURF (BRW_MAX_DRAW_BUFFERS + BRW_MAX_TEX_UNIT + 1) + +/** + * Helpers to convert drawing buffers, textures and constant buffers + * to surface binding table indexes, for WM. + */ +#define BTI_COLOR_BUF(d) (d) +#define BTI_FRAGMENT_CONSTANTS (BRW_MAX_DRAW_BUFFERS) +#define BTI_TEXTURE(t) (BRW_MAX_DRAW_BUFFERS + 1 + (t)) + +/** + * Size of surface binding table for the VS. + * Only one constant buffer for now. + */ +#define BRW_VS_MAX_SURF 1 + +/** + * Only a VS constant buffer + */ +#define SURF_INDEX_VERT_CONST_BUFFER 0 + + +/* Bit of a hack to align these with the winsys buffer_data_type enum. + */ +enum brw_cache_id { + BRW_CC_VP = BRW_DATA_GS_CC_VP, + BRW_CC_UNIT = BRW_DATA_GS_CC_UNIT, + BRW_WM_PROG = BRW_DATA_GS_WM_PROG, + BRW_SAMPLER_DEFAULT_COLOR = BRW_DATA_GS_SAMPLER_DEFAULT_COLOR, + BRW_SAMPLER = BRW_DATA_GS_SAMPLER, + BRW_WM_UNIT = BRW_DATA_GS_WM_UNIT, + BRW_SF_PROG = BRW_DATA_GS_SF_PROG, + BRW_SF_VP = BRW_DATA_GS_SF_VP, + BRW_SF_UNIT = BRW_DATA_GS_SF_UNIT, + BRW_VS_UNIT = BRW_DATA_GS_VS_UNIT, + BRW_VS_PROG = BRW_DATA_GS_VS_PROG, + BRW_GS_UNIT = BRW_DATA_GS_GS_UNIT, + BRW_GS_PROG = BRW_DATA_GS_GS_PROG, + BRW_CLIP_VP = BRW_DATA_GS_CLIP_VP, + BRW_CLIP_UNIT = BRW_DATA_GS_CLIP_UNIT, + BRW_CLIP_PROG = BRW_DATA_GS_CLIP_PROG, + BRW_SS_SURFACE = BRW_DATA_SS_SURFACE, + BRW_SS_SURF_BIND = BRW_DATA_SS_SURF_BIND, + + BRW_MAX_CACHE +}; + +struct brw_cache_item { + /** + * Effectively part of the key, cache_id identifies what kind of state + * buffer is involved, and also which brw->state.dirty.cache flag should + * be set when this cache item is chosen. + */ + enum brw_cache_id cache_id; + /** 32-bit hash of the key data */ + GLuint hash; + GLuint key_size; /* for variable-sized keys */ + const void *key; + struct brw_winsys_reloc *relocs; + GLuint nr_relocs; + + struct brw_winsys_buffer *bo; + GLuint data_size; + + struct brw_cache_item *next; +}; + + + +struct brw_cache { + struct brw_context *brw; + struct brw_winsys_screen *sws; + + struct brw_cache_item **items; + GLuint size, n_items; + + enum brw_buffer_type buffer_type; + + GLuint key_size[BRW_MAX_CACHE]; /* for fixed-size keys */ + GLuint aux_size[BRW_MAX_CACHE]; + char *name[BRW_MAX_CACHE]; + + + /* Record of the last BOs chosen for each cache_id. Used to set + * brw->state.dirty.cache when a new cache item is chosen. + */ + struct brw_winsys_buffer *last_bo[BRW_MAX_CACHE]; +}; + + +struct brw_tracked_state { + struct brw_state_flags dirty; + int (*prepare)( struct brw_context *brw ); + int (*emit)( struct brw_context *brw ); +}; + +/* Flags for brw->state.cache. + */ +#define CACHE_NEW_CC_VP (1< 32. Wouldn't life + * be easier if C allowed arrays of packed elements? + */ +#define VS_INPUT_BITMASK_DWORDS ((PIPE_MAX_SHADER_INPUTS+31)/32) + + + + +struct brw_vertex_info { + GLuint sizes[VS_INPUT_BITMASK_DWORDS * 2]; /* sizes:2[VERT_ATTRIB_MAX] */ +}; + + +struct brw_query_object { + /** Doubly linked list of active query objects in the context. */ + struct brw_query_object *prev, *next; + + /** Last query BO associated with this query. */ + struct brw_winsys_buffer *bo; + /** First index in bo with query data for this object. */ + int first_index; + /** Last index in bo with query data for this object. */ + int last_index; + + /* Total count of pixels from previous BOs */ + uint64_t result; +}; + +#define CC_RELOC_VP 0 + + +/** + * brw_context is derived from pipe_context + */ +struct brw_context +{ + struct pipe_context base; + struct brw_chipset chipset; + + struct brw_winsys_screen *sws; + + struct brw_batchbuffer *batch; + + GLuint primitive; + GLuint reduced_primitive; + + /* Active state from the state tracker: + */ + struct { + struct brw_vertex_shader *vertex_shader; + struct brw_fragment_shader *fragment_shader; + const struct brw_blend_state *blend; + const struct brw_rasterizer_state *rast; + const struct brw_depth_stencil_state *zstencil; + const struct brw_vertex_element_packet *velems; + + const struct brw_sampler *sampler[PIPE_MAX_SAMPLERS]; + unsigned num_samplers; + + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; + struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; + unsigned num_fragment_sampler_views; + unsigned num_vertex_buffers; + + struct pipe_scissor_state scissor; + struct pipe_viewport_state viewport; + struct pipe_stencil_ref stencil_ref; + struct pipe_framebuffer_state fb; + struct pipe_clip_state ucp; + struct pipe_resource *vertex_constants; + struct pipe_resource *fragment_constants; + + struct brw_blend_constant_color bcc; + struct brw_cc1 cc1_stencil_ref; + struct brw_polygon_stipple bps; + struct brw_cc_viewport ccv; + + /** + * Index buffer for this draw_prims call. + * + * Updates are signaled by PIPE_NEW_INDEX_BUFFER. + */ + struct pipe_resource *index_buffer; + unsigned index_size; + unsigned index_offset; + + /* Updates are signalled by PIPE_NEW_INDEX_RANGE: + */ + unsigned min_index; + unsigned max_index; + + } curr; + + struct { + struct brw_state_flags dirty; + + /** + * List of buffers accumulated in brw_validate_state to receive + * dri_bo_check_aperture treatment before exec, so we can know if we + * should flush the batch and try again before emitting primitives. + * + * This can be a fixed number as we only have a limited number of + * objects referenced from the batchbuffer in a primitive emit, + * consisting of the vertex buffers, pipelined state pointers, + * the CURBE, the depth buffer, and a query BO. + */ + struct brw_winsys_buffer *validated_bos[PIPE_MAX_SHADER_INPUTS + 16]; + int validated_bo_count; + } state; + + struct brw_cache cache; /** non-surface items */ + struct brw_cache surface_cache; /* surface items */ + struct brw_cached_batch_item *cached_batch_items; + + struct { + struct u_upload_mgr *upload_vertex; + struct u_upload_mgr *upload_index; + + /* Information on uploaded vertex buffers: + */ + struct { + unsigned stride; /* in bytes between successive vertices */ + unsigned offset; /* in bytes, of first vertex in bo */ + unsigned vertex_count; /* count of valid vertices which may be accessed */ + struct brw_winsys_buffer *bo; + } vb[PIPE_MAX_ATTRIBS]; + + unsigned nr_vb; /* currently the same as curr.num_vertex_buffers */ + } vb; + + struct { + /* Updates to these fields are signaled by BRW_NEW_INDEX_BUFFER. */ + struct brw_winsys_buffer *bo; + unsigned int offset; + unsigned int size; + /* Offset to index buffer index to use in CMD_3D_PRIM so that we can + * avoid re-uploading the IB packet over and over if we're actually + * referencing the same index buffer. + */ + unsigned int start_vertex_offset; + } ib; + + + /* BRW_NEW_URB_ALLOCATIONS: + */ + struct { + GLuint vsize; /* vertex size plus header in urb registers */ + GLuint csize; /* constant buffer size in urb registers */ + GLuint sfsize; /* setup data size in urb registers */ + + GLboolean constrained; + + GLuint nr_vs_entries; + GLuint nr_gs_entries; + GLuint nr_clip_entries; + GLuint nr_sf_entries; + GLuint nr_cs_entries; + + GLuint vs_start; + GLuint gs_start; + GLuint clip_start; + GLuint sf_start; + GLuint cs_start; + } urb; + + + /* BRW_NEW_CURBE_OFFSETS: + */ + struct { + GLuint wm_start; /**< pos of first wm const in CURBE buffer */ + GLuint wm_size; /**< number of float[4] consts, multiple of 16 */ + GLuint clip_start; + GLuint clip_size; + GLuint vs_start; + GLuint vs_size; + GLuint total_size; + + struct brw_winsys_buffer *curbe_bo; + /** Offset within curbe_bo of space for current curbe entry */ + GLuint curbe_offset; + /** Offset within curbe_bo of space for next curbe entry */ + GLuint curbe_next_offset; + + GLfloat *last_buf; + GLuint last_bufsz; + /** + * Whether we should create a new bo instead of reusing the old one + * (if we just dispatch the batch pointing at the old one. + */ + GLboolean need_new_bo; + } curbe; + + struct { + struct brw_vs_prog_data *prog_data; + + struct brw_winsys_buffer *prog_bo; + struct brw_winsys_buffer *state_bo; + + /** Binding table of pointers to surf_bo entries */ + struct brw_winsys_buffer *bind_bo; + struct brw_winsys_buffer *surf_bo[BRW_VS_MAX_SURF]; + GLuint nr_surfaces; + } vs; + + struct { + struct brw_gs_prog_data *prog_data; + + GLboolean prog_active; + struct brw_winsys_buffer *prog_bo; + struct brw_winsys_buffer *state_bo; + } gs; + + struct { + struct brw_clip_prog_data *prog_data; + + struct brw_winsys_buffer *prog_bo; + struct brw_winsys_buffer *state_bo; + struct brw_winsys_buffer *vp_bo; + } clip; + + + struct { + struct brw_sf_prog_data *prog_data; + + struct brw_winsys_buffer *prog_bo; + struct brw_winsys_buffer *state_bo; + struct brw_winsys_buffer *vp_bo; + } sf; + + struct { + struct brw_wm_prog_data *prog_data; + struct brw_wm_compile *compile_data; + + /** Input sizes, calculated from active vertex program. + * One bit per fragment program input attribute. + */ + /*GLbitfield input_size_masks[4];*/ + + /** Array of surface default colors (texture border color) */ + struct brw_winsys_buffer *sdc_bo[BRW_MAX_TEX_UNIT]; + + GLuint render_surf; + GLuint nr_surfaces; + + GLuint max_threads; + struct brw_winsys_buffer *scratch_bo; + + GLuint sampler_count; + struct brw_winsys_buffer *sampler_bo; + + /** Binding table of pointers to surf_bo entries */ + struct brw_winsys_buffer *bind_bo; + struct brw_winsys_buffer *surf_bo[BRW_WM_MAX_SURF]; + + struct brw_winsys_buffer *prog_bo; + struct brw_winsys_buffer *state_bo; + } wm; + + + struct { + struct brw_winsys_buffer *state_bo; + + struct brw_cc_unit_state cc; + struct brw_winsys_reloc reloc[1]; + } cc; + + struct { + struct brw_query_object active_head; + struct brw_winsys_buffer *bo; + int index; + GLboolean active; + int stats_wm; + } query; + + struct { + unsigned always_emit_state:1; + unsigned always_flush_batch:1; + unsigned force_swtnl:1; + unsigned no_swtnl:1; + } flags; + + /* Used to give every program string a unique id + */ + GLuint program_id; +}; + + + +/*====================================================================== + * brw_queryobj.c + */ +void brw_init_query(struct brw_context *brw); +enum pipe_error brw_prepare_query_begin(struct brw_context *brw); +void brw_emit_query_begin(struct brw_context *brw); +void brw_emit_query_end(struct brw_context *brw); + +/*====================================================================== + * brw_state_dump.c + */ +void brw_debug_batch(struct brw_context *intel); + + +/*====================================================================== + * brw_pipe_*.c + */ +void brw_pipe_blend_init( struct brw_context *brw ); +void brw_pipe_depth_stencil_init( struct brw_context *brw ); +void brw_pipe_framebuffer_init( struct brw_context *brw ); +void brw_pipe_flush_init( struct brw_context *brw ); +void brw_pipe_misc_init( struct brw_context *brw ); +void brw_pipe_query_init( struct brw_context *brw ); +void brw_pipe_rast_init( struct brw_context *brw ); +void brw_pipe_sampler_init( struct brw_context *brw ); +void brw_pipe_shader_init( struct brw_context *brw ); +void brw_pipe_vertex_init( struct brw_context *brw ); +void brw_pipe_clear_init( struct brw_context *brw ); + + +void brw_pipe_blend_cleanup( struct brw_context *brw ); +void brw_pipe_depth_stencil_cleanup( struct brw_context *brw ); +void brw_pipe_framebuffer_cleanup( struct brw_context *brw ); +void brw_pipe_flush_cleanup( struct brw_context *brw ); +void brw_pipe_misc_cleanup( struct brw_context *brw ); +void brw_pipe_query_cleanup( struct brw_context *brw ); +void brw_pipe_rast_cleanup( struct brw_context *brw ); +void brw_pipe_sampler_cleanup( struct brw_context *brw ); +void brw_pipe_shader_cleanup( struct brw_context *brw ); +void brw_pipe_vertex_cleanup( struct brw_context *brw ); +void brw_pipe_clear_cleanup( struct brw_context *brw ); +void brw_pipe_surface_init( struct brw_context *brw ); + +void brw_hw_cc_init( struct brw_context *brw ); +void brw_hw_cc_cleanup( struct brw_context *brw ); + + + +void brw_context_flush( struct brw_context *brw ); + + +/* brw_urb.c + */ +int brw_upload_urb_fence(struct brw_context *brw); + +/* brw_curbe.c + */ +int brw_upload_cs_urb_state(struct brw_context *brw); + +/* brw_context.c + */ +struct pipe_context *brw_create_context(struct pipe_screen *screen, + void *priv); + +/*====================================================================== + * Inline conversion functions. These are better-typed than the + * macros used previously: + */ +static INLINE struct brw_context * +brw_context( struct pipe_context *ctx ) +{ + return (struct brw_context *)ctx; +} + + +#define BRW_IS_965(brw) ((brw)->chipset.is_965) +#define BRW_IS_IGDNG(brw) ((brw)->chipset.is_igdng) +#define BRW_IS_G4X(brw) ((brw)->chipset.is_g4x) + + +#endif + diff --git a/src/gallium/drivers/i965/brw_curbe.c b/src/gallium/drivers/i965/brw_curbe.c new file mode 100644 index 0000000..a701de3 --- /dev/null +++ b/src/gallium/drivers/i965/brw_curbe.c @@ -0,0 +1,382 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_memory.h" +#include "util/u_math.h" + +#include "brw_batchbuffer.h" +#include "brw_context.h" +#include "brw_defines.h" +#include "brw_state.h" +#include "brw_debug.h" + + +/** + * Partition the CURBE between the various users of constant values: + * Note that vertex and fragment shaders can now fetch constants out + * of constant buffers. We no longer allocatea block of the GRF for + * constants. That greatly reduces the demand for space in the CURBE. + * Some of the comments within are dated... + */ +static int calculate_curbe_offsets( struct brw_context *brw ) +{ + /* CACHE_NEW_WM_PROG */ + const GLuint nr_fp_regs = brw->wm.prog_data->curb_read_length; + + /* BRW_NEW_VERTEX_PROGRAM */ + const GLuint nr_vp_regs = brw->vs.prog_data->curb_read_length; + GLuint nr_clip_regs = 0; + GLuint total_regs; + + /* PIPE_NEW_CLIP */ + if (brw->curr.ucp.nr) { + GLuint nr_planes = 6 + brw->curr.ucp.nr; + nr_clip_regs = (nr_planes * 4 + 15) / 16; + } + + + total_regs = nr_fp_regs + nr_vp_regs + nr_clip_regs; + + /* When this is > 32, want to use a true constant buffer to hold + * the extra constants. + */ + assert(total_regs <= 32); + + /* Lazy resize: + */ + if (nr_fp_regs > brw->curbe.wm_size || + nr_vp_regs > brw->curbe.vs_size || + nr_clip_regs != brw->curbe.clip_size || + (total_regs < brw->curbe.total_size / 4 && + brw->curbe.total_size > 16)) { + + GLuint reg = 0; + + /* Calculate a new layout: + */ + reg = 0; + brw->curbe.wm_start = reg; + brw->curbe.wm_size = nr_fp_regs; reg += nr_fp_regs; + brw->curbe.clip_start = reg; + brw->curbe.clip_size = nr_clip_regs; reg += nr_clip_regs; + brw->curbe.vs_start = reg; + brw->curbe.vs_size = nr_vp_regs; reg += nr_vp_regs; + brw->curbe.total_size = reg; + + if (BRW_DEBUG & DEBUG_CURBE) + debug_printf("curbe wm %d+%d clip %d+%d vs %d+%d\n", + brw->curbe.wm_start, + brw->curbe.wm_size, + brw->curbe.clip_start, + brw->curbe.clip_size, + brw->curbe.vs_start, + brw->curbe.vs_size ); + + brw->state.dirty.brw |= BRW_NEW_CURBE_OFFSETS; + } + + return 0; +} + + +const struct brw_tracked_state brw_curbe_offsets = { + .dirty = { + .mesa = PIPE_NEW_CLIP, + .brw = BRW_NEW_VERTEX_PROGRAM, + .cache = CACHE_NEW_WM_PROG + }, + .prepare = calculate_curbe_offsets +}; + + + + +/* Define the number of curbes within CS's urb allocation. Multiple + * urb entries -> multiple curbes. These will be used by + * fixed-function hardware in a double-buffering scheme to avoid a + * pipeline stall each time the contents of the curbe is changed. + */ +int brw_upload_cs_urb_state(struct brw_context *brw) +{ + struct brw_cs_urb_state cs_urb; + memset(&cs_urb, 0, sizeof(cs_urb)); + + /* It appears that this is the state packet for the CS unit, ie. the + * urb entries detailed here are housed in the CS range from the + * URB_FENCE command. + */ + cs_urb.header.opcode = CMD_CS_URB_STATE; + cs_urb.header.length = sizeof(cs_urb)/4 - 2; + + /* BRW_NEW_URB_FENCE */ + cs_urb.bits0.nr_urb_entries = brw->urb.nr_cs_entries; + cs_urb.bits0.urb_entry_size = brw->urb.csize - 1; + + assert(brw->urb.nr_cs_entries); + BRW_CACHED_BATCH_STRUCT(brw, &cs_urb); + return 0; +} + +static GLfloat fixed_plane[6][4] = { + { 0, 0, -1, 1 }, + { 0, 0, 1, 1 }, + { 0, -1, 0, 1 }, + { 0, 1, 0, 1 }, + {-1, 0, 0, 1 }, + { 1, 0, 0, 1 } +}; + +/* Upload a new set of constants. Too much variability to go into the + * cache mechanism, but maybe would benefit from a comparison against + * the current uploaded set of constants. + */ +static enum pipe_error prepare_curbe_buffer(struct brw_context *brw) +{ + const GLuint sz = brw->curbe.total_size; + const GLuint bufsz = sz * 16 * sizeof(GLfloat); + enum pipe_error ret; + GLfloat *buf; + GLuint i; + + if (sz == 0) { + if (brw->curbe.last_buf) { + FREE(brw->curbe.last_buf); + brw->curbe.last_buf = NULL; + brw->curbe.last_bufsz = 0; + } + return 0; + } + + buf = (GLfloat *) CALLOC(bufsz, 1); + + /* fragment shader constants */ + if (brw->curbe.wm_size) { + const struct brw_fragment_shader *fs = brw->curr.fragment_shader; + GLuint offset = brw->curbe.wm_start * 16; + GLuint nr_immediate, nr_const; + + nr_immediate = fs->immediates.nr; + if (nr_immediate) { + memcpy(&buf[offset], + fs->immediates.data, + nr_immediate * 4 * sizeof(float)); + + offset += nr_immediate * 4; + } + + nr_const = fs->info.file_max[TGSI_FILE_CONSTANT] + 1; +/* nr_const = brw->wm.prog_data->nr_params; */ + if (nr_const) { + pipe_buffer_read( &brw->base, + brw->curr.fragment_constants, + 0, + nr_const * 4 * sizeof(float), + &buf[offset]); + } + } + + + /* The clipplanes are actually delivered to both CLIP and VS units. + * VS uses them to calculate the outcode bitmasks. + */ + if (brw->curbe.clip_size) { + GLuint offset = brw->curbe.clip_start * 16; + GLuint j; + + /* If any planes are going this way, send them all this way: + */ + for (i = 0; i < 6; i++) { + buf[offset + i * 4 + 0] = fixed_plane[i][0]; + buf[offset + i * 4 + 1] = fixed_plane[i][1]; + buf[offset + i * 4 + 2] = fixed_plane[i][2]; + buf[offset + i * 4 + 3] = fixed_plane[i][3]; + } + + /* Clip planes: + */ + assert(brw->curr.ucp.nr <= 6); + for (j = 0; j < brw->curr.ucp.nr; j++) { + buf[offset + i * 4 + 0] = brw->curr.ucp.ucp[j][0]; + buf[offset + i * 4 + 1] = brw->curr.ucp.ucp[j][1]; + buf[offset + i * 4 + 2] = brw->curr.ucp.ucp[j][2]; + buf[offset + i * 4 + 3] = brw->curr.ucp.ucp[j][3]; + i++; + } + } + + /* vertex shader constants */ + if (brw->curbe.vs_size) { + GLuint offset = brw->curbe.vs_start * 16; + const struct brw_vertex_shader *vs = brw->curr.vertex_shader; + GLuint nr_immediate, nr_const; + + nr_immediate = vs->immediates.nr; + if (nr_immediate) { + memcpy(&buf[offset], + vs->immediates.data, + nr_immediate * 4 * sizeof(float)); + + offset += nr_immediate * 4; + } + + nr_const = vs->info.file_max[TGSI_FILE_CONSTANT] + 1; + if (nr_const) { + /* XXX: note that constant buffers are currently *already* in + * buffer objects. If we want to keep on putting them into the + * curbe, makes sense to treat constbuf's specially with malloc. + */ + + /* XXX: what if user's constant buffer is too small? + */ + pipe_buffer_read(&brw->base, + brw->curr.vertex_constants, + 0, + nr_const * 4 * sizeof(float), + &buf[offset]); + } + } + + if (BRW_DEBUG & DEBUG_CURBE) { + for (i = 0; i < sz*16; i+=4) + debug_printf("curbe %d.%d: %f %f %f %f\n", i/8, i&4, + buf[i+0], buf[i+1], buf[i+2], buf[i+3]); + + debug_printf("last_buf %p buf %p sz %d/%d cmp %d\n", + (void *)brw->curbe.last_buf, (void *)buf, + bufsz, brw->curbe.last_bufsz, + brw->curbe.last_buf ? memcmp(buf, brw->curbe.last_buf, bufsz) : -1); + } + + if (brw->curbe.curbe_bo != NULL && + brw->curbe.last_buf && + bufsz == brw->curbe.last_bufsz && + memcmp(buf, brw->curbe.last_buf, bufsz) == 0) { + /* constants have not changed */ + FREE(buf); + } + else { + /* constants have changed */ + FREE(brw->curbe.last_buf); + + brw->curbe.last_buf = buf; + brw->curbe.last_bufsz = bufsz; + + if (brw->curbe.curbe_bo != NULL && + (brw->curbe.need_new_bo || + brw->curbe.curbe_next_offset + bufsz > brw->curbe.curbe_bo->size)) + { + bo_reference(&brw->curbe.curbe_bo, NULL); + } + + if (brw->curbe.curbe_bo == NULL) { + /* Allocate a single page for CURBE entries for this + * batchbuffer. They're generally around 64b. We will + * discard the curbe buffer after the batch is flushed to + * avoid synchronous updates. + */ + ret = brw->sws->bo_alloc(brw->sws, + BRW_BUFFER_TYPE_CURBE, + 4096, 1 << 6, + &brw->curbe.curbe_bo); + if (ret) + return ret; + + brw->curbe.curbe_next_offset = 0; + } + + brw->curbe.curbe_offset = brw->curbe.curbe_next_offset; + brw->curbe.curbe_next_offset += bufsz; + brw->curbe.curbe_next_offset = align(brw->curbe.curbe_next_offset, 64); + + /* Copy data to the buffer: + */ + brw->sws->bo_subdata(brw->curbe.curbe_bo, + BRW_DATA_CONSTANT_BUFFER, + brw->curbe.curbe_offset, + bufsz, + buf, + NULL, 0); + } + + brw_add_validated_bo(brw, brw->curbe.curbe_bo); + + /* Because this provokes an action (ie copy the constants into the + * URB), it shouldn't be shortcircuited if identical to the + * previous time - because eg. the urb destination may have + * changed, or the urb contents different to last time. + * + * Note that the data referred to is actually copied internally, + * not just used in place according to passed pointer. + * + * It appears that the CS unit takes care of using each available + * URB entry (Const URB Entry == CURBE) in turn, and issuing + * flushes as necessary when doublebuffering of CURBEs isn't + * possible. + */ + + return 0; +} + +static enum pipe_error emit_curbe_buffer(struct brw_context *brw) +{ + GLuint sz = brw->curbe.total_size; + + BEGIN_BATCH(2, IGNORE_CLIPRECTS); + if (sz == 0) { + OUT_BATCH((CMD_CONST_BUFFER << 16) | (2 - 2)); + OUT_BATCH(0); + } else { + OUT_BATCH((CMD_CONST_BUFFER << 16) | (1 << 8) | (2 - 2)); + OUT_RELOC(brw->curbe.curbe_bo, + BRW_USAGE_STATE, + (sz - 1) + brw->curbe.curbe_offset); + } + ADVANCE_BATCH(); + return 0; +} + +const struct brw_tracked_state brw_curbe_buffer = { + .dirty = { + .mesa = (PIPE_NEW_FRAGMENT_CONSTANTS | + PIPE_NEW_VERTEX_CONSTANTS | + PIPE_NEW_CLIP), + .brw = (BRW_NEW_FRAGMENT_PROGRAM | + BRW_NEW_VERTEX_PROGRAM | + BRW_NEW_URB_FENCE | /* Implicit - hardware requires this, not used above */ + BRW_NEW_PSP | /* Implicit - hardware requires this, not used above */ + BRW_NEW_CURBE_OFFSETS | + BRW_NEW_BATCH), + .cache = (CACHE_NEW_WM_PROG) + }, + .prepare = prepare_curbe_buffer, + .emit = emit_curbe_buffer, +}; + diff --git a/src/gallium/drivers/i965/brw_debug.h b/src/gallium/drivers/i965/brw_debug.h new file mode 100644 index 0000000..ae8e925 --- /dev/null +++ b/src/gallium/drivers/i965/brw_debug.h @@ -0,0 +1,43 @@ +#ifndef BRW_DEBUG_H +#define BRW_DEBUG_H + +/* ================================================================ + * Debugging: + */ + +#define DEBUG_TEXTURE 0x1 +#define DEBUG_STATE 0x2 +#define DEBUG_IOCTL 0x4 +#define DEBUG_BLIT 0x8 +#define DEBUG_CURBE 0x10 +#define DEBUG_FALLBACKS 0x20 +#define DEBUG_VERBOSE 0x40 +#define DEBUG_BATCH 0x80 +#define DEBUG_PIXEL 0x100 +#define DEBUG_WINSYS 0x200 +#define DEBUG_MIN_URB 0x400 +#define DEBUG_DISASSEM 0x800 +#define DEBUG_unused3 0x1000 +#define DEBUG_SYNC 0x2000 +#define DEBUG_PRIMS 0x4000 +#define DEBUG_VERTS 0x8000 +#define DEBUG_unused4 0x10000 +#define DEBUG_DMA 0x20000 +#define DEBUG_SANITY 0x40000 +#define DEBUG_SLEEP 0x80000 +#define DEBUG_STATS 0x100000 +#define DEBUG_unused5 0x200000 +#define DEBUG_SINGLE_THREAD 0x400000 +#define DEBUG_WM 0x800000 +#define DEBUG_URB 0x1000000 +#define DEBUG_VS 0x2000000 + +#ifdef DEBUG +extern int BRW_DEBUG; +#else +#define BRW_DEBUG 0 +#endif + + + +#endif diff --git a/src/gallium/drivers/i965/brw_defines.h b/src/gallium/drivers/i965/brw_defines.h new file mode 100644 index 0000000..e201ce4 --- /dev/null +++ b/src/gallium/drivers/i965/brw_defines.h @@ -0,0 +1,847 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#ifndef BRW_DEFINES_H +#define BRW_DEFINES_H + +/* 3D state: + */ +#define _3DOP_3DSTATE_PIPELINED 0x0 +#define _3DOP_3DSTATE_NONPIPELINED 0x1 +#define _3DOP_3DCONTROL 0x2 +#define _3DOP_3DPRIMITIVE 0x3 + +#define _3DSTATE_PIPELINED_POINTERS 0x00 +#define _3DSTATE_BINDING_TABLE_POINTERS 0x01 +#define _3DSTATE_VERTEX_BUFFERS 0x08 +#define _3DSTATE_VERTEX_ELEMENTS 0x09 +#define _3DSTATE_INDEX_BUFFER 0x0A +#define _3DSTATE_VF_STATISTICS 0x0B +#define _3DSTATE_DRAWING_RECTANGLE 0x00 +#define _3DSTATE_CONSTANT_COLOR 0x01 +#define _3DSTATE_SAMPLER_PALETTE_LOAD 0x02 +#define _3DSTATE_CHROMA_KEY 0x04 +#define _3DSTATE_DEPTH_BUFFER 0x05 +#define _3DSTATE_POLY_STIPPLE_OFFSET 0x06 +#define _3DSTATE_POLY_STIPPLE_PATTERN 0x07 +#define _3DSTATE_LINE_STIPPLE 0x08 +#define _3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP 0x09 +#define _3DCONTROL 0x00 + +#define PIPE_CONTROL_NOWRITE 0x00 +#define PIPE_CONTROL_WRITEIMMEDIATE 0x01 +#define PIPE_CONTROL_WRITEDEPTH 0x02 +#define PIPE_CONTROL_WRITETIMESTAMP 0x03 + +#define PIPE_CONTROL_GTTWRITE_PROCESS_LOCAL 0x00 +#define PIPE_CONTROL_GTTWRITE_GLOBAL 0x01 + +#define _3DPRIM_POINTLIST 0x01 +#define _3DPRIM_LINELIST 0x02 +#define _3DPRIM_LINESTRIP 0x03 +#define _3DPRIM_TRILIST 0x04 +#define _3DPRIM_TRISTRIP 0x05 +#define _3DPRIM_TRIFAN 0x06 +#define _3DPRIM_QUADLIST 0x07 +#define _3DPRIM_QUADSTRIP 0x08 +#define _3DPRIM_LINELIST_ADJ 0x09 +#define _3DPRIM_LINESTRIP_ADJ 0x0A +#define _3DPRIM_TRILIST_ADJ 0x0B +#define _3DPRIM_TRISTRIP_ADJ 0x0C +#define _3DPRIM_TRISTRIP_REVERSE 0x0D +#define _3DPRIM_POLYGON 0x0E +#define _3DPRIM_RECTLIST 0x0F +#define _3DPRIM_LINELOOP 0x10 +#define _3DPRIM_POINTLIST_BF 0x11 +#define _3DPRIM_LINESTRIP_CONT 0x12 +#define _3DPRIM_LINESTRIP_BF 0x13 +#define _3DPRIM_LINESTRIP_CONT_BF 0x14 +#define _3DPRIM_TRIFAN_NOSTIPPLE 0x15 + +#define _3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL 0 +#define _3DPRIM_VERTEXBUFFER_ACCESS_RANDOM 1 + +#define BRW_ANISORATIO_2 0 +#define BRW_ANISORATIO_4 1 +#define BRW_ANISORATIO_6 2 +#define BRW_ANISORATIO_8 3 +#define BRW_ANISORATIO_10 4 +#define BRW_ANISORATIO_12 5 +#define BRW_ANISORATIO_14 6 +#define BRW_ANISORATIO_16 7 + +#define BRW_BLENDFACTOR_ONE 0x1 +#define BRW_BLENDFACTOR_SRC_COLOR 0x2 +#define BRW_BLENDFACTOR_SRC_ALPHA 0x3 +#define BRW_BLENDFACTOR_DST_ALPHA 0x4 +#define BRW_BLENDFACTOR_DST_COLOR 0x5 +#define BRW_BLENDFACTOR_SRC_ALPHA_SATURATE 0x6 +#define BRW_BLENDFACTOR_CONST_COLOR 0x7 +#define BRW_BLENDFACTOR_CONST_ALPHA 0x8 +#define BRW_BLENDFACTOR_SRC1_COLOR 0x9 +#define BRW_BLENDFACTOR_SRC1_ALPHA 0x0A +#define BRW_BLENDFACTOR_ZERO 0x11 +#define BRW_BLENDFACTOR_INV_SRC_COLOR 0x12 +#define BRW_BLENDFACTOR_INV_SRC_ALPHA 0x13 +#define BRW_BLENDFACTOR_INV_DST_ALPHA 0x14 +#define BRW_BLENDFACTOR_INV_DST_COLOR 0x15 +#define BRW_BLENDFACTOR_INV_CONST_COLOR 0x17 +#define BRW_BLENDFACTOR_INV_CONST_ALPHA 0x18 +#define BRW_BLENDFACTOR_INV_SRC1_COLOR 0x19 +#define BRW_BLENDFACTOR_INV_SRC1_ALPHA 0x1A + +#define BRW_BLENDFUNCTION_ADD 0 +#define BRW_BLENDFUNCTION_SUBTRACT 1 +#define BRW_BLENDFUNCTION_REVERSE_SUBTRACT 2 +#define BRW_BLENDFUNCTION_MIN 3 +#define BRW_BLENDFUNCTION_MAX 4 + +#define BRW_ALPHATEST_FORMAT_UNORM8 0 +#define BRW_ALPHATEST_FORMAT_FLOAT32 1 + +#define BRW_CHROMAKEY_KILL_ON_ANY_MATCH 0 +#define BRW_CHROMAKEY_REPLACE_BLACK 1 + +#define BRW_CLIP_API_OGL 0 +#define BRW_CLIP_API_DX 1 + +#define BRW_CLIPMODE_NORMAL 0 +#define BRW_CLIPMODE_CLIP_ALL 1 +#define BRW_CLIPMODE_CLIP_NON_REJECTED 2 +#define BRW_CLIPMODE_REJECT_ALL 3 +#define BRW_CLIPMODE_ACCEPT_ALL 4 +#define BRW_CLIPMODE_KERNEL_CLIP 5 + +#define BRW_CLIP_NDCSPACE 0 +#define BRW_CLIP_SCREENSPACE 1 + +#define BRW_COMPAREFUNCTION_ALWAYS 0 +#define BRW_COMPAREFUNCTION_NEVER 1 +#define BRW_COMPAREFUNCTION_LESS 2 +#define BRW_COMPAREFUNCTION_EQUAL 3 +#define BRW_COMPAREFUNCTION_LEQUAL 4 +#define BRW_COMPAREFUNCTION_GREATER 5 +#define BRW_COMPAREFUNCTION_NOTEQUAL 6 +#define BRW_COMPAREFUNCTION_GEQUAL 7 + +#define BRW_COVERAGE_PIXELS_HALF 0 +#define BRW_COVERAGE_PIXELS_1 1 +#define BRW_COVERAGE_PIXELS_2 2 +#define BRW_COVERAGE_PIXELS_4 3 + +#define BRW_CULLMODE_BOTH 0 +#define BRW_CULLMODE_NONE 1 +#define BRW_CULLMODE_FRONT 2 +#define BRW_CULLMODE_BACK 3 + +#define BRW_DEFAULTCOLOR_R8G8B8A8_UNORM 0 +#define BRW_DEFAULTCOLOR_R32G32B32A32_FLOAT 1 + +#define BRW_DEPTHFORMAT_D32_FLOAT_S8X24_UINT 0 +#define BRW_DEPTHFORMAT_D32_FLOAT 1 +#define BRW_DEPTHFORMAT_D24_UNORM_S8_UINT 2 +#define BRW_DEPTHFORMAT_D16_UNORM 5 + +#define BRW_FLOATING_POINT_IEEE_754 0 +#define BRW_FLOATING_POINT_NON_IEEE_754 1 + +#define BRW_FRONTWINDING_CW 0 +#define BRW_FRONTWINDING_CCW 1 + +#define BRW_SPRITE_POINT_ENABLE 16 + +#define BRW_INDEX_BYTE 0 +#define BRW_INDEX_WORD 1 +#define BRW_INDEX_DWORD 2 + +#define BRW_LOGICOPFUNCTION_CLEAR 0 +#define BRW_LOGICOPFUNCTION_NOR 1 +#define BRW_LOGICOPFUNCTION_AND_INVERTED 2 +#define BRW_LOGICOPFUNCTION_COPY_INVERTED 3 +#define BRW_LOGICOPFUNCTION_AND_REVERSE 4 +#define BRW_LOGICOPFUNCTION_INVERT 5 +#define BRW_LOGICOPFUNCTION_XOR 6 +#define BRW_LOGICOPFUNCTION_NAND 7 +#define BRW_LOGICOPFUNCTION_AND 8 +#define BRW_LOGICOPFUNCTION_EQUIV 9 +#define BRW_LOGICOPFUNCTION_NOOP 10 +#define BRW_LOGICOPFUNCTION_OR_INVERTED 11 +#define BRW_LOGICOPFUNCTION_COPY 12 +#define BRW_LOGICOPFUNCTION_OR_REVERSE 13 +#define BRW_LOGICOPFUNCTION_OR 14 +#define BRW_LOGICOPFUNCTION_SET 15 + +#define BRW_MAPFILTER_NEAREST 0x0 +#define BRW_MAPFILTER_LINEAR 0x1 +#define BRW_MAPFILTER_ANISOTROPIC 0x2 + +#define BRW_MIPFILTER_NONE 0 +#define BRW_MIPFILTER_NEAREST 1 +#define BRW_MIPFILTER_LINEAR 3 + +#define BRW_POLYGON_FRONT_FACING 0 +#define BRW_POLYGON_BACK_FACING 1 + +#define BRW_PREFILTER_ALWAYS 0x0 +#define BRW_PREFILTER_NEVER 0x1 +#define BRW_PREFILTER_LESS 0x2 +#define BRW_PREFILTER_EQUAL 0x3 +#define BRW_PREFILTER_LEQUAL 0x4 +#define BRW_PREFILTER_GREATER 0x5 +#define BRW_PREFILTER_NOTEQUAL 0x6 +#define BRW_PREFILTER_GEQUAL 0x7 + +#define BRW_PROVOKING_VERTEX_0 0 +#define BRW_PROVOKING_VERTEX_1 1 +#define BRW_PROVOKING_VERTEX_2 2 + +#define BRW_RASTRULE_UPPER_LEFT 0 +#define BRW_RASTRULE_UPPER_RIGHT 1 +/* These are listed as "Reserved, but not seen as useful" + * in Intel documentation (page 212, "Point Rasterization Rule", + * section 7.4 "SF Pipeline State Summary", of document + * "Intel® 965 Express Chipset Family and Intel® G35 Express + * Chipset Graphics Controller Programmer's Reference Manual, + * Volume 2: 3D/Media", Revision 1.0b as of January 2008, + * available at + * http://intellinuxgraphics.org/documentation.html + * at the time of this writing). + * + * These appear to be supported on at least some + * i965-family devices, and the BRW_RASTRULE_LOWER_RIGHT + * is useful when using OpenGL to render to a FBO + * (which has the pixel coordinate Y orientation inverted + * with respect to the normal OpenGL pixel coordinate system). + */ +#define BRW_RASTRULE_LOWER_LEFT 2 +#define BRW_RASTRULE_LOWER_RIGHT 3 + +#define BRW_RENDERTARGET_CLAMPRANGE_UNORM 0 +#define BRW_RENDERTARGET_CLAMPRANGE_SNORM 1 +#define BRW_RENDERTARGET_CLAMPRANGE_FORMAT 2 + +#define BRW_STENCILOP_KEEP 0 +#define BRW_STENCILOP_ZERO 1 +#define BRW_STENCILOP_REPLACE 2 +#define BRW_STENCILOP_INCRSAT 3 +#define BRW_STENCILOP_DECRSAT 4 +#define BRW_STENCILOP_INCR 5 +#define BRW_STENCILOP_DECR 6 +#define BRW_STENCILOP_INVERT 7 + +#define BRW_SURFACE_MIPMAPLAYOUT_BELOW 0 +#define BRW_SURFACE_MIPMAPLAYOUT_RIGHT 1 + +#define BRW_SURFACEFORMAT_R32G32B32A32_FLOAT 0x000 +#define BRW_SURFACEFORMAT_R32G32B32A32_SINT 0x001 +#define BRW_SURFACEFORMAT_R32G32B32A32_UINT 0x002 +#define BRW_SURFACEFORMAT_R32G32B32A32_UNORM 0x003 +#define BRW_SURFACEFORMAT_R32G32B32A32_SNORM 0x004 +#define BRW_SURFACEFORMAT_R64G64_FLOAT 0x005 +#define BRW_SURFACEFORMAT_R32G32B32X32_FLOAT 0x006 +#define BRW_SURFACEFORMAT_R32G32B32A32_SSCALED 0x007 +#define BRW_SURFACEFORMAT_R32G32B32A32_USCALED 0x008 +#define BRW_SURFACEFORMAT_R32G32B32_FLOAT 0x040 +#define BRW_SURFACEFORMAT_R32G32B32_SINT 0x041 +#define BRW_SURFACEFORMAT_R32G32B32_UINT 0x042 +#define BRW_SURFACEFORMAT_R32G32B32_UNORM 0x043 +#define BRW_SURFACEFORMAT_R32G32B32_SNORM 0x044 +#define BRW_SURFACEFORMAT_R32G32B32_SSCALED 0x045 +#define BRW_SURFACEFORMAT_R32G32B32_USCALED 0x046 +#define BRW_SURFACEFORMAT_R16G16B16A16_UNORM 0x080 +#define BRW_SURFACEFORMAT_R16G16B16A16_SNORM 0x081 +#define BRW_SURFACEFORMAT_R16G16B16A16_SINT 0x082 +#define BRW_SURFACEFORMAT_R16G16B16A16_UINT 0x083 +#define BRW_SURFACEFORMAT_R16G16B16A16_FLOAT 0x084 +#define BRW_SURFACEFORMAT_R32G32_FLOAT 0x085 +#define BRW_SURFACEFORMAT_R32G32_SINT 0x086 +#define BRW_SURFACEFORMAT_R32G32_UINT 0x087 +#define BRW_SURFACEFORMAT_R32_FLOAT_X8X24_TYPELESS 0x088 +#define BRW_SURFACEFORMAT_X32_TYPELESS_G8X24_UINT 0x089 +#define BRW_SURFACEFORMAT_L32A32_FLOAT 0x08A +#define BRW_SURFACEFORMAT_R32G32_UNORM 0x08B +#define BRW_SURFACEFORMAT_R32G32_SNORM 0x08C +#define BRW_SURFACEFORMAT_R64_FLOAT 0x08D +#define BRW_SURFACEFORMAT_R16G16B16X16_UNORM 0x08E +#define BRW_SURFACEFORMAT_R16G16B16X16_FLOAT 0x08F +#define BRW_SURFACEFORMAT_A32X32_FLOAT 0x090 +#define BRW_SURFACEFORMAT_L32X32_FLOAT 0x091 +#define BRW_SURFACEFORMAT_I32X32_FLOAT 0x092 +#define BRW_SURFACEFORMAT_R16G16B16A16_SSCALED 0x093 +#define BRW_SURFACEFORMAT_R16G16B16A16_USCALED 0x094 +#define BRW_SURFACEFORMAT_R32G32_SSCALED 0x095 +#define BRW_SURFACEFORMAT_R32G32_USCALED 0x096 +#define BRW_SURFACEFORMAT_B8G8R8A8_UNORM 0x0C0 +#define BRW_SURFACEFORMAT_B8G8R8A8_UNORM_SRGB 0x0C1 +#define BRW_SURFACEFORMAT_R10G10B10A2_UNORM 0x0C2 +#define BRW_SURFACEFORMAT_R10G10B10A2_UNORM_SRGB 0x0C3 +#define BRW_SURFACEFORMAT_R10G10B10A2_UINT 0x0C4 +#define BRW_SURFACEFORMAT_R10G10B10_SNORM_A2_UNORM 0x0C5 +#define BRW_SURFACEFORMAT_R8G8B8A8_UNORM 0x0C7 +#define BRW_SURFACEFORMAT_R8G8B8A8_UNORM_SRGB 0x0C8 +#define BRW_SURFACEFORMAT_R8G8B8A8_SNORM 0x0C9 +#define BRW_SURFACEFORMAT_R8G8B8A8_SINT 0x0CA +#define BRW_SURFACEFORMAT_R8G8B8A8_UINT 0x0CB +#define BRW_SURFACEFORMAT_R16G16_UNORM 0x0CC +#define BRW_SURFACEFORMAT_R16G16_SNORM 0x0CD +#define BRW_SURFACEFORMAT_R16G16_SINT 0x0CE +#define BRW_SURFACEFORMAT_R16G16_UINT 0x0CF +#define BRW_SURFACEFORMAT_R16G16_FLOAT 0x0D0 +#define BRW_SURFACEFORMAT_B10G10R10A2_UNORM 0x0D1 +#define BRW_SURFACEFORMAT_B10G10R10A2_UNORM_SRGB 0x0D2 +#define BRW_SURFACEFORMAT_R11G11B10_FLOAT 0x0D3 +#define BRW_SURFACEFORMAT_R32_SINT 0x0D6 +#define BRW_SURFACEFORMAT_R32_UINT 0x0D7 +#define BRW_SURFACEFORMAT_R32_FLOAT 0x0D8 +#define BRW_SURFACEFORMAT_R24_UNORM_X8_TYPELESS 0x0D9 +#define BRW_SURFACEFORMAT_X24_TYPELESS_G8_UINT 0x0DA +#define BRW_SURFACEFORMAT_L16A16_UNORM 0x0DF +#define BRW_SURFACEFORMAT_I24X8_UNORM 0x0E0 +#define BRW_SURFACEFORMAT_L24X8_UNORM 0x0E1 +#define BRW_SURFACEFORMAT_A24X8_UNORM 0x0E2 +#define BRW_SURFACEFORMAT_I32_FLOAT 0x0E3 +#define BRW_SURFACEFORMAT_L32_FLOAT 0x0E4 +#define BRW_SURFACEFORMAT_A32_FLOAT 0x0E5 +#define BRW_SURFACEFORMAT_B8G8R8X8_UNORM 0x0E9 +#define BRW_SURFACEFORMAT_B8G8R8X8_UNORM_SRGB 0x0EA +#define BRW_SURFACEFORMAT_R8G8B8X8_UNORM 0x0EB +#define BRW_SURFACEFORMAT_R8G8B8X8_UNORM_SRGB 0x0EC +#define BRW_SURFACEFORMAT_R9G9B9E5_SHAREDEXP 0x0ED +#define BRW_SURFACEFORMAT_B10G10R10X2_UNORM 0x0EE +#define BRW_SURFACEFORMAT_L16A16_FLOAT 0x0F0 +#define BRW_SURFACEFORMAT_R32_UNORM 0x0F1 +#define BRW_SURFACEFORMAT_R32_SNORM 0x0F2 +#define BRW_SURFACEFORMAT_R10G10B10X2_USCALED 0x0F3 +#define BRW_SURFACEFORMAT_R8G8B8A8_SSCALED 0x0F4 +#define BRW_SURFACEFORMAT_R8G8B8A8_USCALED 0x0F5 +#define BRW_SURFACEFORMAT_R16G16_SSCALED 0x0F6 +#define BRW_SURFACEFORMAT_R16G16_USCALED 0x0F7 +#define BRW_SURFACEFORMAT_R32_SSCALED 0x0F8 +#define BRW_SURFACEFORMAT_R32_USCALED 0x0F9 +#define BRW_SURFACEFORMAT_B5G6R5_UNORM 0x100 +#define BRW_SURFACEFORMAT_B5G6R5_UNORM_SRGB 0x101 +#define BRW_SURFACEFORMAT_B5G5R5A1_UNORM 0x102 +#define BRW_SURFACEFORMAT_B5G5R5A1_UNORM_SRGB 0x103 +#define BRW_SURFACEFORMAT_B4G4R4A4_UNORM 0x104 +#define BRW_SURFACEFORMAT_B4G4R4A4_UNORM_SRGB 0x105 +#define BRW_SURFACEFORMAT_R8G8_UNORM 0x106 +#define BRW_SURFACEFORMAT_R8G8_SNORM 0x107 +#define BRW_SURFACEFORMAT_R8G8_SINT 0x108 +#define BRW_SURFACEFORMAT_R8G8_UINT 0x109 +#define BRW_SURFACEFORMAT_R16_UNORM 0x10A +#define BRW_SURFACEFORMAT_R16_SNORM 0x10B +#define BRW_SURFACEFORMAT_R16_SINT 0x10C +#define BRW_SURFACEFORMAT_R16_UINT 0x10D +#define BRW_SURFACEFORMAT_R16_FLOAT 0x10E +#define BRW_SURFACEFORMAT_I16_UNORM 0x111 +#define BRW_SURFACEFORMAT_L16_UNORM 0x112 +#define BRW_SURFACEFORMAT_A16_UNORM 0x113 +#define BRW_SURFACEFORMAT_L8A8_UNORM 0x114 +#define BRW_SURFACEFORMAT_I16_FLOAT 0x115 +#define BRW_SURFACEFORMAT_L16_FLOAT 0x116 +#define BRW_SURFACEFORMAT_A16_FLOAT 0x117 +#define BRW_SURFACEFORMAT_L8A8_UNORM_SRGB 0x118 +#define BRW_SURFACEFORMAT_R5G5_SNORM_B6_UNORM 0x119 +#define BRW_SURFACEFORMAT_B5G5R5X1_UNORM 0x11A +#define BRW_SURFACEFORMAT_B5G5R5X1_UNORM_SRGB 0x11B +#define BRW_SURFACEFORMAT_R8G8_SSCALED 0x11C +#define BRW_SURFACEFORMAT_R8G8_USCALED 0x11D +#define BRW_SURFACEFORMAT_R16_SSCALED 0x11E +#define BRW_SURFACEFORMAT_R16_USCALED 0x11F +#define BRW_SURFACEFORMAT_R8_UNORM 0x140 +#define BRW_SURFACEFORMAT_R8_SNORM 0x141 +#define BRW_SURFACEFORMAT_R8_SINT 0x142 +#define BRW_SURFACEFORMAT_R8_UINT 0x143 +#define BRW_SURFACEFORMAT_A8_UNORM 0x144 +#define BRW_SURFACEFORMAT_I8_UNORM 0x145 +#define BRW_SURFACEFORMAT_L8_UNORM 0x146 +#define BRW_SURFACEFORMAT_P4A4_UNORM 0x147 +#define BRW_SURFACEFORMAT_A4P4_UNORM 0x148 +#define BRW_SURFACEFORMAT_R8_SSCALED 0x149 +#define BRW_SURFACEFORMAT_R8_USCALED 0x14A +#define BRW_SURFACEFORMAT_L8_UNORM_SRGB 0x14C +#define BRW_SURFACEFORMAT_R1_UINT 0x181 +#define BRW_SURFACEFORMAT_YCRCB_NORMAL 0x182 +#define BRW_SURFACEFORMAT_YCRCB_SWAPUVY 0x183 +#define BRW_SURFACEFORMAT_BC1_UNORM 0x186 +#define BRW_SURFACEFORMAT_BC2_UNORM 0x187 +#define BRW_SURFACEFORMAT_BC3_UNORM 0x188 +#define BRW_SURFACEFORMAT_BC4_UNORM 0x189 +#define BRW_SURFACEFORMAT_BC5_UNORM 0x18A +#define BRW_SURFACEFORMAT_BC1_UNORM_SRGB 0x18B +#define BRW_SURFACEFORMAT_BC2_UNORM_SRGB 0x18C +#define BRW_SURFACEFORMAT_BC3_UNORM_SRGB 0x18D +#define BRW_SURFACEFORMAT_MONO8 0x18E +#define BRW_SURFACEFORMAT_YCRCB_SWAPUV 0x18F +#define BRW_SURFACEFORMAT_YCRCB_SWAPY 0x190 +#define BRW_SURFACEFORMAT_DXT1_RGB 0x191 +#define BRW_SURFACEFORMAT_FXT1 0x192 +#define BRW_SURFACEFORMAT_R8G8B8_UNORM 0x193 +#define BRW_SURFACEFORMAT_R8G8B8_SNORM 0x194 +#define BRW_SURFACEFORMAT_R8G8B8_SSCALED 0x195 +#define BRW_SURFACEFORMAT_R8G8B8_USCALED 0x196 +#define BRW_SURFACEFORMAT_R64G64B64A64_FLOAT 0x197 +#define BRW_SURFACEFORMAT_R64G64B64_FLOAT 0x198 +#define BRW_SURFACEFORMAT_BC4_SNORM 0x199 +#define BRW_SURFACEFORMAT_BC5_SNORM 0x19A +#define BRW_SURFACEFORMAT_R16G16B16_UNORM 0x19C +#define BRW_SURFACEFORMAT_R16G16B16_SNORM 0x19D +#define BRW_SURFACEFORMAT_R16G16B16_SSCALED 0x19E +#define BRW_SURFACEFORMAT_R16G16B16_USCALED 0x19F +#define BRW_SURFACEFORMAT_INVALID 0xFFF + +#define BRW_SURFACERETURNFORMAT_FLOAT32 0 +#define BRW_SURFACERETURNFORMAT_S1 1 + +#define BRW_SURFACE_1D 0 +#define BRW_SURFACE_2D 1 +#define BRW_SURFACE_3D 2 +#define BRW_SURFACE_CUBE 3 +#define BRW_SURFACE_BUFFER 4 +#define BRW_SURFACE_NULL 7 + +#define BRW_TEXCOORDMODE_WRAP 0 +#define BRW_TEXCOORDMODE_MIRROR 1 +#define BRW_TEXCOORDMODE_CLAMP 2 +#define BRW_TEXCOORDMODE_CUBE 3 +#define BRW_TEXCOORDMODE_CLAMP_BORDER 4 +#define BRW_TEXCOORDMODE_MIRROR_ONCE 5 + +#define BRW_THREAD_PRIORITY_NORMAL 0 +#define BRW_THREAD_PRIORITY_HIGH 1 + +#define BRW_TILEWALK_XMAJOR 0 +#define BRW_TILEWALK_YMAJOR 1 + +#define BRW_VERTEX_SUBPIXEL_PRECISION_8BITS 0 +#define BRW_VERTEX_SUBPIXEL_PRECISION_4BITS 1 + +/* Execution Unit (EU) defines + */ + +#define BRW_ALIGN_1 0 +#define BRW_ALIGN_16 1 + +#define BRW_ADDRESS_DIRECT 0 +#define BRW_ADDRESS_REGISTER_INDIRECT_REGISTER 1 + +#define BRW_CHANNEL_X 0 +#define BRW_CHANNEL_Y 1 +#define BRW_CHANNEL_Z 2 +#define BRW_CHANNEL_W 3 + +#define BRW_COMPRESSION_NONE 0 +#define BRW_COMPRESSION_2NDHALF 1 +#define BRW_COMPRESSION_COMPRESSED 2 + +#define BRW_CONDITIONAL_NONE 0 +#define BRW_CONDITIONAL_Z 1 +#define BRW_CONDITIONAL_NZ 2 +#define BRW_CONDITIONAL_EQ 1 /* Z */ +#define BRW_CONDITIONAL_NEQ 2 /* NZ */ +#define BRW_CONDITIONAL_G 3 +#define BRW_CONDITIONAL_GE 4 +#define BRW_CONDITIONAL_L 5 +#define BRW_CONDITIONAL_LE 6 +#define BRW_CONDITIONAL_R 7 +#define BRW_CONDITIONAL_O 8 +#define BRW_CONDITIONAL_U 9 + +#define BRW_DEBUG_NONE 0 +#define BRW_DEBUG_BREAKPOINT 1 + +#define BRW_DEPENDENCY_NORMAL 0 +#define BRW_DEPENDENCY_NOTCLEARED 1 +#define BRW_DEPENDENCY_NOTCHECKED 2 +#define BRW_DEPENDENCY_DISABLE 3 + +#define BRW_EXECUTE_1 0 +#define BRW_EXECUTE_2 1 +#define BRW_EXECUTE_4 2 +#define BRW_EXECUTE_8 3 +#define BRW_EXECUTE_16 4 +#define BRW_EXECUTE_32 5 + +#define BRW_HORIZONTAL_STRIDE_0 0 +#define BRW_HORIZONTAL_STRIDE_1 1 +#define BRW_HORIZONTAL_STRIDE_2 2 +#define BRW_HORIZONTAL_STRIDE_4 3 + +#define BRW_INSTRUCTION_NORMAL 0 +#define BRW_INSTRUCTION_SATURATE 1 + +#define BRW_MASK_ENABLE 0 +#define BRW_MASK_DISABLE 1 + +#define BRW_OPCODE_MOV 1 +#define BRW_OPCODE_SEL 2 +#define BRW_OPCODE_NOT 4 +#define BRW_OPCODE_AND 5 +#define BRW_OPCODE_OR 6 +#define BRW_OPCODE_XOR 7 +#define BRW_OPCODE_SHR 8 +#define BRW_OPCODE_SHL 9 +#define BRW_OPCODE_RSR 10 +#define BRW_OPCODE_RSL 11 +#define BRW_OPCODE_ASR 12 +#define BRW_OPCODE_CMP 16 +#define BRW_OPCODE_CMPN 17 +#define BRW_OPCODE_JMPI 32 +#define BRW_OPCODE_IF 34 +#define BRW_OPCODE_IFF 35 +#define BRW_OPCODE_ELSE 36 +#define BRW_OPCODE_ENDIF 37 +#define BRW_OPCODE_DO 38 +#define BRW_OPCODE_WHILE 39 +#define BRW_OPCODE_BREAK 40 +#define BRW_OPCODE_CONTINUE 41 +#define BRW_OPCODE_HALT 42 +#define BRW_OPCODE_MSAVE 44 +#define BRW_OPCODE_MRESTORE 45 +#define BRW_OPCODE_PUSH 46 +#define BRW_OPCODE_POP 47 +#define BRW_OPCODE_WAIT 48 +#define BRW_OPCODE_SEND 49 +#define BRW_OPCODE_ADD 64 +#define BRW_OPCODE_MUL 65 +#define BRW_OPCODE_AVG 66 +#define BRW_OPCODE_FRC 67 +#define BRW_OPCODE_RNDU 68 +#define BRW_OPCODE_RNDD 69 +#define BRW_OPCODE_RNDE 70 +#define BRW_OPCODE_RNDZ 71 +#define BRW_OPCODE_MAC 72 +#define BRW_OPCODE_MACH 73 +#define BRW_OPCODE_LZD 74 +#define BRW_OPCODE_SAD2 80 +#define BRW_OPCODE_SADA2 81 +#define BRW_OPCODE_DP4 84 +#define BRW_OPCODE_DPH 85 +#define BRW_OPCODE_DP3 86 +#define BRW_OPCODE_DP2 87 +#define BRW_OPCODE_DPA2 88 +#define BRW_OPCODE_LINE 89 +#define BRW_OPCODE_NOP 126 + +#define BRW_PREDICATE_NONE 0 +#define BRW_PREDICATE_NORMAL 1 +#define BRW_PREDICATE_ALIGN1_ANYV 2 +#define BRW_PREDICATE_ALIGN1_ALLV 3 +#define BRW_PREDICATE_ALIGN1_ANY2H 4 +#define BRW_PREDICATE_ALIGN1_ALL2H 5 +#define BRW_PREDICATE_ALIGN1_ANY4H 6 +#define BRW_PREDICATE_ALIGN1_ALL4H 7 +#define BRW_PREDICATE_ALIGN1_ANY8H 8 +#define BRW_PREDICATE_ALIGN1_ALL8H 9 +#define BRW_PREDICATE_ALIGN1_ANY16H 10 +#define BRW_PREDICATE_ALIGN1_ALL16H 11 +#define BRW_PREDICATE_ALIGN16_REPLICATE_X 2 +#define BRW_PREDICATE_ALIGN16_REPLICATE_Y 3 +#define BRW_PREDICATE_ALIGN16_REPLICATE_Z 4 +#define BRW_PREDICATE_ALIGN16_REPLICATE_W 5 +#define BRW_PREDICATE_ALIGN16_ANY4H 6 +#define BRW_PREDICATE_ALIGN16_ALL4H 7 + +#define BRW_ARCHITECTURE_REGISTER_FILE 0 +#define BRW_GENERAL_REGISTER_FILE 1 +#define BRW_MESSAGE_REGISTER_FILE 2 +#define BRW_IMMEDIATE_VALUE 3 + +#define BRW_REGISTER_TYPE_UD 0 +#define BRW_REGISTER_TYPE_D 1 +#define BRW_REGISTER_TYPE_UW 2 +#define BRW_REGISTER_TYPE_W 3 +#define BRW_REGISTER_TYPE_UB 4 +#define BRW_REGISTER_TYPE_B 5 +#define BRW_REGISTER_TYPE_VF 5 /* packed float vector, immediates only? */ +#define BRW_REGISTER_TYPE_HF 6 +#define BRW_REGISTER_TYPE_V 6 /* packed int vector, immediates only, uword dest only */ +#define BRW_REGISTER_TYPE_F 7 + +#define BRW_ARF_NULL 0x00 +#define BRW_ARF_ADDRESS 0x10 +#define BRW_ARF_ACCUMULATOR 0x20 +#define BRW_ARF_FLAG 0x30 +#define BRW_ARF_MASK 0x40 +#define BRW_ARF_MASK_STACK 0x50 +#define BRW_ARF_MASK_STACK_DEPTH 0x60 +#define BRW_ARF_STATE 0x70 +#define BRW_ARF_CONTROL 0x80 +#define BRW_ARF_NOTIFICATION_COUNT 0x90 +#define BRW_ARF_IP 0xA0 + +#define BRW_AMASK 0 +#define BRW_IMASK 1 +#define BRW_LMASK 2 +#define BRW_CMASK 3 + + + +#define BRW_THREAD_NORMAL 0 +#define BRW_THREAD_ATOMIC 1 +#define BRW_THREAD_SWITCH 2 + +#define BRW_VERTICAL_STRIDE_0 0 +#define BRW_VERTICAL_STRIDE_1 1 +#define BRW_VERTICAL_STRIDE_2 2 +#define BRW_VERTICAL_STRIDE_4 3 +#define BRW_VERTICAL_STRIDE_8 4 +#define BRW_VERTICAL_STRIDE_16 5 +#define BRW_VERTICAL_STRIDE_32 6 +#define BRW_VERTICAL_STRIDE_64 7 +#define BRW_VERTICAL_STRIDE_128 8 +#define BRW_VERTICAL_STRIDE_256 9 +#define BRW_VERTICAL_STRIDE_ONE_DIMENSIONAL 0xF + +#define BRW_WIDTH_1 0 +#define BRW_WIDTH_2 1 +#define BRW_WIDTH_4 2 +#define BRW_WIDTH_8 3 +#define BRW_WIDTH_16 4 + +#define BRW_STATELESS_BUFFER_BOUNDARY_1K 0 +#define BRW_STATELESS_BUFFER_BOUNDARY_2K 1 +#define BRW_STATELESS_BUFFER_BOUNDARY_4K 2 +#define BRW_STATELESS_BUFFER_BOUNDARY_8K 3 +#define BRW_STATELESS_BUFFER_BOUNDARY_16K 4 +#define BRW_STATELESS_BUFFER_BOUNDARY_32K 5 +#define BRW_STATELESS_BUFFER_BOUNDARY_64K 6 +#define BRW_STATELESS_BUFFER_BOUNDARY_128K 7 +#define BRW_STATELESS_BUFFER_BOUNDARY_256K 8 +#define BRW_STATELESS_BUFFER_BOUNDARY_512K 9 +#define BRW_STATELESS_BUFFER_BOUNDARY_1M 10 +#define BRW_STATELESS_BUFFER_BOUNDARY_2M 11 + +#define BRW_POLYGON_FACING_FRONT 0 +#define BRW_POLYGON_FACING_BACK 1 + +#define BRW_MESSAGE_TARGET_NULL 0 +#define BRW_MESSAGE_TARGET_MATH 1 +#define BRW_MESSAGE_TARGET_SAMPLER 2 +#define BRW_MESSAGE_TARGET_GATEWAY 3 +#define BRW_MESSAGE_TARGET_DATAPORT_READ 4 +#define BRW_MESSAGE_TARGET_DATAPORT_WRITE 5 +#define BRW_MESSAGE_TARGET_URB 6 +#define BRW_MESSAGE_TARGET_THREAD_SPAWNER 7 + +#define BRW_SAMPLER_RETURN_FORMAT_FLOAT32 0 +#define BRW_SAMPLER_RETURN_FORMAT_UINT32 2 +#define BRW_SAMPLER_RETURN_FORMAT_SINT32 3 + +#define BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE 0 +#define BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE 0 +#define BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS 0 +#define BRW_SAMPLER_MESSAGE_SIMD8_KILLPIX 1 +#define BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD 1 +#define BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD 1 +#define BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_GRADIENTS 2 +#define BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS 2 +#define BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_COMPARE 0 +#define BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_COMPARE 2 +#define BRW_SAMPLER_MESSAGE_SIMD4X2_RESINFO 2 +#define BRW_SAMPLER_MESSAGE_SIMD8_RESINFO 2 +#define BRW_SAMPLER_MESSAGE_SIMD16_RESINFO 2 +#define BRW_SAMPLER_MESSAGE_SIMD4X2_LD 3 +#define BRW_SAMPLER_MESSAGE_SIMD8_LD 3 +#define BRW_SAMPLER_MESSAGE_SIMD16_LD 3 + +#define BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_IGDNG 0 +#define BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_IGDNG 0 +#define BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_IGDNG 0 +#define BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_BIAS_IGDNG 1 +#define BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_BIAS_IGDNG 1 +#define BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS_IGDNG 1 +#define BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_LOD_IGDNG 2 +#define BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD_IGDNG 2 +#define BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD_IGDNG 2 +#define BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_COMPARE_IGDNG 3 +#define BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_COMPARE_IGDNG 3 +#define BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_COMPARE_IGDNG 3 + +/* for IGDNG only */ +#define BRW_SAMPLER_SIMD_MODE_SIMD4X2 0 +#define BRW_SAMPLER_SIMD_MODE_SIMD8 1 +#define BRW_SAMPLER_SIMD_MODE_SIMD16 2 +#define BRW_SAMPLER_SIMD_MODE_SIMD32_64 3 + +#define BRW_DATAPORT_OWORD_BLOCK_1_OWORDLOW 0 +#define BRW_DATAPORT_OWORD_BLOCK_1_OWORDHIGH 1 +#define BRW_DATAPORT_OWORD_BLOCK_2_OWORDS 2 +#define BRW_DATAPORT_OWORD_BLOCK_4_OWORDS 3 +#define BRW_DATAPORT_OWORD_BLOCK_8_OWORDS 4 + +#define BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD 0 +#define BRW_DATAPORT_OWORD_DUAL_BLOCK_4OWORDS 2 + +#define BRW_DATAPORT_DWORD_SCATTERED_BLOCK_8DWORDS 2 +#define BRW_DATAPORT_DWORD_SCATTERED_BLOCK_16DWORDS 3 + +#define BRW_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ 0 +#define BRW_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ 1 +#define BRW_DATAPORT_READ_MESSAGE_DWORD_BLOCK_READ 2 +#define BRW_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ 3 + +#define BRW_DATAPORT_READ_TARGET_DATA_CACHE 0 +#define BRW_DATAPORT_READ_TARGET_RENDER_CACHE 1 +#define BRW_DATAPORT_READ_TARGET_SAMPLER_CACHE 2 + +#define BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE 0 +#define BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE_REPLICATED 1 +#define BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01 2 +#define BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN23 3 +#define BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01 4 + +#define BRW_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE 0 +#define BRW_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE 1 +#define BRW_DATAPORT_WRITE_MESSAGE_DWORD_BLOCK_WRITE 2 +#define BRW_DATAPORT_WRITE_MESSAGE_DWORD_SCATTERED_WRITE 3 +#define BRW_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE 4 +#define BRW_DATAPORT_WRITE_MESSAGE_STREAMED_VERTEX_BUFFER_WRITE 5 +#define BRW_DATAPORT_WRITE_MESSAGE_FLUSH_RENDER_CACHE 7 + +#define BRW_MATH_FUNCTION_INV 1 +#define BRW_MATH_FUNCTION_LOG 2 +#define BRW_MATH_FUNCTION_EXP 3 +#define BRW_MATH_FUNCTION_SQRT 4 +#define BRW_MATH_FUNCTION_RSQ 5 +#define BRW_MATH_FUNCTION_SIN 6 /* was 7 */ +#define BRW_MATH_FUNCTION_COS 7 /* was 8 */ +#define BRW_MATH_FUNCTION_SINCOS 8 /* was 6 */ +#define BRW_MATH_FUNCTION_TAN 9 +#define BRW_MATH_FUNCTION_POW 10 +#define BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER 11 +#define BRW_MATH_FUNCTION_INT_DIV_QUOTIENT 12 +#define BRW_MATH_FUNCTION_INT_DIV_REMAINDER 13 + +#define BRW_MATH_INTEGER_UNSIGNED 0 +#define BRW_MATH_INTEGER_SIGNED 1 + +#define BRW_MATH_PRECISION_FULL 0 +#define BRW_MATH_PRECISION_PARTIAL 1 + +#define BRW_MATH_SATURATE_NONE 0 +#define BRW_MATH_SATURATE_SATURATE 1 + +#define BRW_MATH_DATA_VECTOR 0 +#define BRW_MATH_DATA_SCALAR 1 + +#define BRW_URB_OPCODE_WRITE 0 + +#define BRW_URB_SWIZZLE_NONE 0 +#define BRW_URB_SWIZZLE_INTERLEAVE 1 +#define BRW_URB_SWIZZLE_TRANSPOSE 2 + +#define BRW_SCRATCH_SPACE_SIZE_1K 0 +#define BRW_SCRATCH_SPACE_SIZE_2K 1 +#define BRW_SCRATCH_SPACE_SIZE_4K 2 +#define BRW_SCRATCH_SPACE_SIZE_8K 3 +#define BRW_SCRATCH_SPACE_SIZE_16K 4 +#define BRW_SCRATCH_SPACE_SIZE_32K 5 +#define BRW_SCRATCH_SPACE_SIZE_64K 6 +#define BRW_SCRATCH_SPACE_SIZE_128K 7 +#define BRW_SCRATCH_SPACE_SIZE_256K 8 +#define BRW_SCRATCH_SPACE_SIZE_512K 9 +#define BRW_SCRATCH_SPACE_SIZE_1M 10 +#define BRW_SCRATCH_SPACE_SIZE_2M 11 + + + + +#define CMD_URB_FENCE 0x6000 +#define CMD_CS_URB_STATE 0x6001 +#define CMD_CONST_BUFFER 0x6002 + +#define CMD_STATE_BASE_ADDRESS 0x6101 +#define CMD_STATE_INSN_POINTER 0x6102 +#define CMD_PIPELINE_SELECT_965 0x6104 +#define CMD_PIPELINE_SELECT_GM45 0x6904 + +#define CMD_PIPELINED_STATE_POINTERS 0x7800 +#define CMD_BINDING_TABLE_PTRS 0x7801 + +#define CMD_VERTEX_BUFFER 0x7808 +# define BRW_VB0_INDEX_SHIFT 27 +# define BRW_VB0_ACCESS_VERTEXDATA (0 << 26) +# define BRW_VB0_ACCESS_INSTANCEDATA (1 << 26) +# define BRW_VB0_PITCH_SHIFT 0 + +#define CMD_VERTEX_ELEMENT 0x7809 +# define BRW_VE0_INDEX_SHIFT 27 +# define BRW_VE0_FORMAT_SHIFT 16 +# define BRW_VE0_VALID (1 << 26) +# define BRW_VE0_SRC_OFFSET_SHIFT 0 +# define BRW_VE1_COMPONENT_NOSTORE 0 +# define BRW_VE1_COMPONENT_STORE_SRC 1 +# define BRW_VE1_COMPONENT_STORE_0 2 +# define BRW_VE1_COMPONENT_STORE_1_FLT 3 +# define BRW_VE1_COMPONENT_STORE_1_INT 4 +# define BRW_VE1_COMPONENT_STORE_VID 5 +# define BRW_VE1_COMPONENT_STORE_IID 6 +# define BRW_VE1_COMPONENT_STORE_PID 7 +# define BRW_VE1_COMPONENT_0_SHIFT 28 +# define BRW_VE1_COMPONENT_1_SHIFT 24 +# define BRW_VE1_COMPONENT_2_SHIFT 20 +# define BRW_VE1_COMPONENT_3_SHIFT 16 +# define BRW_VE1_DST_OFFSET_SHIFT 0 + +#define CMD_INDEX_BUFFER 0x780a +#define CMD_VF_STATISTICS_965 0x780b +#define CMD_VF_STATISTICS_GM45 0x680b + +#define CMD_DRAW_RECT 0x7900 +#define CMD_BLEND_CONSTANT_COLOR 0x7901 +#define CMD_CHROMA_KEY 0x7904 +#define CMD_DEPTH_BUFFER 0x7905 +#define CMD_POLY_STIPPLE_OFFSET 0x7906 +#define CMD_POLY_STIPPLE_PATTERN 0x7907 +#define CMD_LINE_STIPPLE_PATTERN 0x7908 +#define CMD_GLOBAL_DEPTH_OFFSET_CLAMP 0x7909 +#define CMD_AA_LINE_PARAMETERS 0x790a + +#define CMD_PIPE_CONTROL 0x7a00 + +#define CMD_3D_PRIM 0x7b00 + +#define CMD_MI_FLUSH 0x0200 + + +/* Various values from the R0 vertex header: + */ +#define R02_PRIM_END 0x1 +#define R02_PRIM_START 0x2 + +#define URB_SIZES(brw) (BRW_IS_IGDNG(brw) ? 1024 : \ + (BRW_IS_G4X(brw) ? 384 : 256)) /* 512 bit units */ + + + +#endif diff --git a/src/gallium/drivers/i965/brw_disasm.c b/src/gallium/drivers/i965/brw_disasm.c new file mode 100644 index 0000000..28c8351 --- /dev/null +++ b/src/gallium/drivers/i965/brw_disasm.c @@ -0,0 +1,922 @@ +/* + * Copyright © 2008 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#include "brw_disasm.h" +#include "brw_structs.h" +#include "brw_reg.h" +#include "brw_defines.h" + +struct { + char *name; + int nsrc; + int ndst; +} opcode[128] = { + [BRW_OPCODE_MOV] = { .name = "mov", .nsrc = 1, .ndst = 1 }, + [BRW_OPCODE_FRC] = { .name = "frc", .nsrc = 1, .ndst = 1 }, + [BRW_OPCODE_RNDU] = { .name = "rndu", .nsrc = 1, .ndst = 1 }, + [BRW_OPCODE_RNDD] = { .name = "rndd", .nsrc = 1, .ndst = 1 }, + [BRW_OPCODE_RNDE] = { .name = "rnde", .nsrc = 1, .ndst = 1 }, + [BRW_OPCODE_RNDZ] = { .name = "rndz", .nsrc = 1, .ndst = 1 }, + [BRW_OPCODE_NOT] = { .name = "not", .nsrc = 1, .ndst = 1 }, + [BRW_OPCODE_LZD] = { .name = "lzd", .nsrc = 1, .ndst = 1 }, + + [BRW_OPCODE_MUL] = { .name = "mul", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_MAC] = { .name = "mac", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_MACH] = { .name = "mach", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_LINE] = { .name = "line", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_SAD2] = { .name = "sad2", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_SADA2] = { .name = "sada2", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_DP4] = { .name = "dp4", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_DPH] = { .name = "dph", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_DP3] = { .name = "dp3", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_DP2] = { .name = "dp2", .nsrc = 2, .ndst = 1 }, + + [BRW_OPCODE_AVG] = { .name = "avg", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_ADD] = { .name = "add", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_SEL] = { .name = "sel", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_AND] = { .name = "and", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_OR] = { .name = "or", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_XOR] = { .name = "xor", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_SHR] = { .name = "shr", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_SHL] = { .name = "shl", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_ASR] = { .name = "asr", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_CMP] = { .name = "cmp", .nsrc = 2, .ndst = 1 }, + [BRW_OPCODE_CMPN] = { .name = "cmpn", .nsrc = 2, .ndst = 1 }, + + [BRW_OPCODE_SEND] = { .name = "send", .nsrc = 1, .ndst = 1 }, + [BRW_OPCODE_NOP] = { .name = "nop", .nsrc = 0, .ndst = 0 }, + [BRW_OPCODE_JMPI] = { .name = "jmpi", .nsrc = 1, .ndst = 0 }, + [BRW_OPCODE_IF] = { .name = "if", .nsrc = 2, .ndst = 0 }, + [BRW_OPCODE_IFF] = { .name = "iff", .nsrc = 1, .ndst = 01 }, + [BRW_OPCODE_WHILE] = { .name = "while", .nsrc = 1, .ndst = 0 }, + [BRW_OPCODE_ELSE] = { .name = "else", .nsrc = 2, .ndst = 0 }, + [BRW_OPCODE_BREAK] = { .name = "break", .nsrc = 1, .ndst = 0 }, + [BRW_OPCODE_CONTINUE] = { .name = "cont", .nsrc = 1, .ndst = 0 }, + [BRW_OPCODE_HALT] = { .name = "halt", .nsrc = 1, .ndst = 0 }, + [BRW_OPCODE_MSAVE] = { .name = "msave", .nsrc = 1, .ndst = 1 }, + [BRW_OPCODE_PUSH] = { .name = "push", .nsrc = 1, .ndst = 1 }, + [BRW_OPCODE_MRESTORE] = { .name = "mrest", .nsrc = 1, .ndst = 1 }, + [BRW_OPCODE_POP] = { .name = "pop", .nsrc = 2, .ndst = 0 }, + [BRW_OPCODE_WAIT] = { .name = "wait", .nsrc = 1, .ndst = 0 }, + [BRW_OPCODE_DO] = { .name = "do", .nsrc = 0, .ndst = 0 }, + [BRW_OPCODE_ENDIF] = { .name = "endif", .nsrc = 2, .ndst = 0 }, +}; + +char *conditional_modifier[16] = { + [BRW_CONDITIONAL_NONE] = "", + [BRW_CONDITIONAL_Z] = ".e", + [BRW_CONDITIONAL_NZ] = ".ne", + [BRW_CONDITIONAL_G] = ".g", + [BRW_CONDITIONAL_GE] = ".ge", + [BRW_CONDITIONAL_L] = ".l", + [BRW_CONDITIONAL_LE] = ".le", + [BRW_CONDITIONAL_R] = ".r", + [BRW_CONDITIONAL_O] = ".o", + [BRW_CONDITIONAL_U] = ".u", +}; + +char *negate[2] = { + [0] = "", + [1] = "-", +}; + +char *_abs[2] = { + [0] = "", + [1] = "(abs)", +}; + +char *vert_stride[16] = { + [0] = "0", + [1] = "1", + [2] = "2", + [3] = "4", + [4] = "8", + [5] = "16", + [6] = "32", + [15] = "VxH", +}; + +char *width[8] = { + [0] = "1", + [1] = "2", + [2] = "4", + [3] = "8", + [4] = "16", +}; + +char *horiz_stride[4] = { + [0] = "0", + [1] = "1", + [2] = "2", + [3] = "4" +}; + +char *chan_sel[4] = { + [0] = "x", + [1] = "y", + [2] = "z", + [3] = "w", +}; + +char *dest_condmod[16] = { + [0] = NULL +}; + +char *debug_ctrl[2] = { + [0] = "", + [1] = ".breakpoint" +}; + +char *saturate[2] = { + [0] = "", + [1] = ".sat" +}; + +char *exec_size[8] = { + [0] = "1", + [1] = "2", + [2] = "4", + [3] = "8", + [4] = "16", + [5] = "32" +}; + +char *pred_inv[2] = { + [0] = "+", + [1] = "-" +}; + +char *pred_ctrl_align16[16] = { + [1] = "", + [2] = ".x", + [3] = ".y", + [4] = ".z", + [5] = ".w", + [6] = ".any4h", + [7] = ".all4h", +}; + +char *pred_ctrl_align1[16] = { + [1] = "", + [2] = ".anyv", + [3] = ".allv", + [4] = ".any2h", + [5] = ".all2h", + [6] = ".any4h", + [7] = ".all4h", + [8] = ".any8h", + [9] = ".all8h", + [10] = ".any16h", + [11] = ".all16h", +}; + +char *thread_ctrl[4] = { + [0] = "", + [2] = "switch" +}; + +char *compr_ctrl[4] = { + [0] = "", + [1] = "sechalf", + [2] = "compr", +}; + +char *dep_ctrl[4] = { + [0] = "", + [1] = "NoDDClr", + [2] = "NoDDChk", + [3] = "NoDDClr,NoDDChk", +}; + +char *mask_ctrl[4] = { + [0] = "", + [1] = "nomask", +}; + +char *access_mode[2] = { + [0] = "align1", + [1] = "align16", +}; + +char *reg_encoding[8] = { + [0] = "UD", + [1] = "D", + [2] = "UW", + [3] = "W", + [4] = "UB", + [5] = "B", + [7] = "F" +}; + +char *imm_encoding[8] = { + [0] = "UD", + [1] = "D", + [2] = "UW", + [3] = "W", + [5] = "VF", + [6] = "V", + [7] = "F" +}; + +char *reg_file[4] = { + [0] = "A", + [1] = "g", + [2] = "m", + [3] = "imm", +}; + +char *writemask[16] = { + [0x0] = ".", + [0x1] = ".x", + [0x2] = ".y", + [0x3] = ".xy", + [0x4] = ".z", + [0x5] = ".xz", + [0x6] = ".yz", + [0x7] = ".xyz", + [0x8] = ".w", + [0x9] = ".xw", + [0xa] = ".yw", + [0xb] = ".xyw", + [0xc] = ".zw", + [0xd] = ".xzw", + [0xe] = ".yzw", + [0xf] = "", +}; + +char *end_of_thread[2] = { + [0] = "", + [1] = "EOT" +}; + +char *target_function[16] = { + [BRW_MESSAGE_TARGET_NULL] = "null", + [BRW_MESSAGE_TARGET_MATH] = "math", + [BRW_MESSAGE_TARGET_SAMPLER] = "sampler", + [BRW_MESSAGE_TARGET_GATEWAY] = "gateway", + [BRW_MESSAGE_TARGET_DATAPORT_READ] = "read", + [BRW_MESSAGE_TARGET_DATAPORT_WRITE] = "write", + [BRW_MESSAGE_TARGET_URB] = "urb", + [BRW_MESSAGE_TARGET_THREAD_SPAWNER] = "thread_spawner" +}; + +char *math_function[16] = { + [BRW_MATH_FUNCTION_INV] = "inv", + [BRW_MATH_FUNCTION_LOG] = "log", + [BRW_MATH_FUNCTION_EXP] = "exp", + [BRW_MATH_FUNCTION_SQRT] = "sqrt", + [BRW_MATH_FUNCTION_RSQ] = "rsq", + [BRW_MATH_FUNCTION_SIN] = "sin", + [BRW_MATH_FUNCTION_COS] = "cos", + [BRW_MATH_FUNCTION_SINCOS] = "sincos", + [BRW_MATH_FUNCTION_TAN] = "tan", + [BRW_MATH_FUNCTION_POW] = "pow", + [BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER] = "intdivmod", + [BRW_MATH_FUNCTION_INT_DIV_QUOTIENT] = "intmod", + [BRW_MATH_FUNCTION_INT_DIV_REMAINDER] = "intdiv", +}; + +char *math_saturate[2] = { + [0] = "", + [1] = "sat" +}; + +char *math_signed[2] = { + [0] = "", + [1] = "signed" +}; + +char *math_scalar[2] = { + [0] = "", + [1] = "scalar" +}; + +char *math_precision[2] = { + [0] = "", + [1] = "partial_precision" +}; + +char *urb_swizzle[4] = { + [BRW_URB_SWIZZLE_NONE] = "", + [BRW_URB_SWIZZLE_INTERLEAVE] = "interleave", + [BRW_URB_SWIZZLE_TRANSPOSE] = "transpose", +}; + +char *urb_allocate[2] = { + [0] = "", + [1] = "allocate" +}; + +char *urb_used[2] = { + [0] = "", + [1] = "used" +}; + +char *urb_complete[2] = { + [0] = "", + [1] = "complete" +}; + +char *sampler_target_format[4] = { + [0] = "F", + [2] = "UD", + [3] = "D" +}; + + +static int column; + +static int string (FILE *file, char *string) +{ + fputs (string, file); + column += strlen (string); + return 0; +} + +static int format (FILE *f, char *format, ...) +{ + char buf[1024]; + va_list args; + va_start (args, format); + + vsnprintf (buf, sizeof (buf) - 1, format, args); + va_end (args); + string (f, buf); + return 0; +} + +static int newline (FILE *f) +{ + putc ('\n', f); + column = 0; + return 0; +} + +static int pad (FILE *f, int c) +{ + do + string (f, " "); + while (column < c); + return 0; +} + +static int control (FILE *file, char *name, char *ctrl[], GLuint id, int *space) +{ + if (!ctrl[id]) { + fprintf (file, "*** invalid %s value %d ", + name, id); + return 1; + } + if (ctrl[id][0]) + { + if (space && *space) + string (file, " "); + string (file, ctrl[id]); + if (space) + *space = 1; + } + return 0; +} + +static int print_opcode (FILE *file, int id) +{ + if (!opcode[id].name) { + format (file, "*** invalid opcode value %d ", id); + return 1; + } + string (file, opcode[id].name); + return 0; +} + +static int reg (FILE *file, GLuint _reg_file, GLuint _reg_nr) +{ + int err = 0; + if (_reg_file == BRW_ARCHITECTURE_REGISTER_FILE) { + switch (_reg_nr & 0xf0) { + case BRW_ARF_NULL: + string (file, "null"); + return -1; + case BRW_ARF_ADDRESS: + format (file, "a%d", _reg_nr & 0x0f); + break; + case BRW_ARF_ACCUMULATOR: + format (file, "acc%d", _reg_nr & 0x0f); + break; + case BRW_ARF_MASK: + format (file, "mask%d", _reg_nr & 0x0f); + break; + case BRW_ARF_MASK_STACK: + format (file, "msd%d", _reg_nr & 0x0f); + break; + case BRW_ARF_STATE: + format (file, "sr%d", _reg_nr & 0x0f); + break; + case BRW_ARF_CONTROL: + format (file, "cr%d", _reg_nr & 0x0f); + break; + case BRW_ARF_NOTIFICATION_COUNT: + format (file, "n%d", _reg_nr & 0x0f); + break; + case BRW_ARF_IP: + string (file, "ip"); + return -1; + break; + default: + format (file, "ARF%d", _reg_nr); + break; + } + } else { + err |= control (file, "src reg file", reg_file, _reg_file, NULL); + format (file, "%d", _reg_nr); + } + return err; +} + +static int dest (FILE *file, const struct brw_instruction *inst) +{ + int err = 0; + + if (inst->header.access_mode == BRW_ALIGN_1) + { + if (inst->bits1.da1.dest_address_mode == BRW_ADDRESS_DIRECT) + { + err |= reg (file, inst->bits1.da1.dest_reg_file, inst->bits1.da1.dest_reg_nr); + if (err == -1) + return 0; + if (inst->bits1.da1.dest_subreg_nr) + format (file, ".%d", inst->bits1.da1.dest_subreg_nr); + format (file, "<%d>", inst->bits1.da1.dest_horiz_stride); + err |= control (file, "dest reg encoding", reg_encoding, inst->bits1.da1.dest_reg_type, NULL); + } + else + { + string (file, "g[a0"); + if (inst->bits1.ia1.dest_subreg_nr) + format (file, ".%d", inst->bits1.ia1.dest_subreg_nr); + if (inst->bits1.ia1.dest_indirect_offset) + format (file, " %d", inst->bits1.ia1.dest_indirect_offset); + string (file, "]"); + format (file, "<%d>", inst->bits1.ia1.dest_horiz_stride); + err |= control (file, "dest reg encoding", reg_encoding, inst->bits1.ia1.dest_reg_type, NULL); + } + } + else + { + if (inst->bits1.da16.dest_address_mode == BRW_ADDRESS_DIRECT) + { + err |= reg (file, inst->bits1.da16.dest_reg_file, inst->bits1.da16.dest_reg_nr); + if (err == -1) + return 0; + if (inst->bits1.da16.dest_subreg_nr) + format (file, ".%d", inst->bits1.da16.dest_subreg_nr); + string (file, "<1>"); + err |= control (file, "writemask", writemask, inst->bits1.da16.dest_writemask, NULL); + err |= control (file, "dest reg encoding", reg_encoding, inst->bits1.da16.dest_reg_type, NULL); + } + else + { + err = 1; + string (file, "Indirect align16 address mode not supported"); + } + } + + return 0; +} + +static int src_align1_region (FILE *file, + GLuint _vert_stride, GLuint _width, GLuint _horiz_stride) +{ + int err = 0; + string (file, "<"); + err |= control (file, "vert stride", vert_stride, _vert_stride, NULL); + string (file, ","); + err |= control (file, "width", width, _width, NULL); + string (file, ","); + err |= control (file, "horiz_stride", horiz_stride, _horiz_stride, NULL); + string (file, ">"); + return err; +} + +static int src_da1 (FILE *file, GLuint type, GLuint _reg_file, + GLuint _vert_stride, GLuint _width, GLuint _horiz_stride, + GLuint reg_num, GLuint sub_reg_num, GLuint __abs, GLuint _negate) +{ + int err = 0; + err |= control (file, "negate", negate, _negate, NULL); + err |= control (file, "abs", _abs, __abs, NULL); + + err |= reg (file, _reg_file, reg_num); + if (err == -1) + return 0; + if (sub_reg_num) + format (file, ".%d", sub_reg_num); + src_align1_region (file, _vert_stride, _width, _horiz_stride); + err |= control (file, "src reg encoding", reg_encoding, type, NULL); + return err; +} + +static int src_ia1 (FILE *file, + GLuint type, + GLuint _reg_file, + GLint _addr_imm, + GLuint _addr_subreg_nr, + GLuint _negate, + GLuint __abs, + GLuint _addr_mode, + GLuint _horiz_stride, + GLuint _width, + GLuint _vert_stride) +{ + int err = 0; + err |= control (file, "negate", negate, _negate, NULL); + err |= control (file, "abs", _abs, __abs, NULL); + + string (file, "g[a0"); + if (_addr_subreg_nr) + format (file, ".%d", _addr_subreg_nr); + if (_addr_imm) + format (file, " %d", _addr_imm); + string (file, "]"); + src_align1_region (file, _vert_stride, _width, _horiz_stride); + err |= control (file, "src reg encoding", reg_encoding, type, NULL); + return err; +} + +static int src_da16 (FILE *file, + GLuint _reg_type, + GLuint _reg_file, + GLuint _vert_stride, + GLuint _reg_nr, + GLuint _subreg_nr, + GLuint __abs, + GLuint _negate, + GLuint swz_x, + GLuint swz_y, + GLuint swz_z, + GLuint swz_w) +{ + int err = 0; + err |= control (file, "negate", negate, _negate, NULL); + err |= control (file, "abs", _abs, __abs, NULL); + + err |= reg (file, _reg_file, _reg_nr); + if (err == -1) + return 0; + if (_subreg_nr) + format (file, ".%d", _subreg_nr); + string (file, "<"); + err |= control (file, "vert stride", vert_stride, _vert_stride, NULL); + string (file, ",1,1>"); + err |= control (file, "src da16 reg type", reg_encoding, _reg_type, NULL); + /* + * Three kinds of swizzle display: + * identity - nothing printed + * 1->all - print the single channel + * 1->1 - print the mapping + */ + if (swz_x == BRW_CHANNEL_X && + swz_y == BRW_CHANNEL_Y && + swz_z == BRW_CHANNEL_Z && + swz_w == BRW_CHANNEL_W) + { + ; + } + else if (swz_x == swz_y && swz_x == swz_z && swz_x == swz_w) + { + string (file, "."); + err |= control (file, "channel select", chan_sel, swz_x, NULL); + } + else + { + string (file, "."); + err |= control (file, "channel select", chan_sel, swz_x, NULL); + err |= control (file, "channel select", chan_sel, swz_y, NULL); + err |= control (file, "channel select", chan_sel, swz_z, NULL); + err |= control (file, "channel select", chan_sel, swz_w, NULL); + } + return err; +} + + +static int imm (FILE *file, GLuint type, const struct brw_instruction *inst) { + switch (type) { + case BRW_REGISTER_TYPE_UD: + format (file, "0x%08xUD", inst->bits3.ud); + break; + case BRW_REGISTER_TYPE_D: + format (file, "%dD", inst->bits3.d); + break; + case BRW_REGISTER_TYPE_UW: + format (file, "0x%04xUW", (uint16_t) inst->bits3.ud); + break; + case BRW_REGISTER_TYPE_W: + format (file, "%dW", (int16_t) inst->bits3.d); + break; + case BRW_REGISTER_TYPE_UB: + format (file, "0x%02xUB", (int8_t) inst->bits3.ud); + break; + case BRW_REGISTER_TYPE_VF: + format (file, "Vector Float"); + break; + case BRW_REGISTER_TYPE_V: + format (file, "0x%08xV", inst->bits3.ud); + break; + case BRW_REGISTER_TYPE_F: + format (file, "%-gF", inst->bits3.f); + } + return 0; +} + +static int src0 (FILE *file, const struct brw_instruction *inst) +{ + if (inst->bits1.da1.src0_reg_file == BRW_IMMEDIATE_VALUE) + return imm (file, inst->bits1.da1.src0_reg_type, + inst); + else if (inst->header.access_mode == BRW_ALIGN_1) + { + if (inst->bits2.da1.src0_address_mode == BRW_ADDRESS_DIRECT) + { + return src_da1 (file, + inst->bits1.da1.src0_reg_type, + inst->bits1.da1.src0_reg_file, + inst->bits2.da1.src0_vert_stride, + inst->bits2.da1.src0_width, + inst->bits2.da1.src0_horiz_stride, + inst->bits2.da1.src0_reg_nr, + inst->bits2.da1.src0_subreg_nr, + inst->bits2.da1.src0_abs, + inst->bits2.da1.src0_negate); + } + else + { + return src_ia1 (file, + inst->bits1.ia1.src0_reg_type, + inst->bits1.ia1.src0_reg_file, + inst->bits2.ia1.src0_indirect_offset, + inst->bits2.ia1.src0_subreg_nr, + inst->bits2.ia1.src0_negate, + inst->bits2.ia1.src0_abs, + inst->bits2.ia1.src0_address_mode, + inst->bits2.ia1.src0_horiz_stride, + inst->bits2.ia1.src0_width, + inst->bits2.ia1.src0_vert_stride); + } + } + else + { + if (inst->bits2.da16.src0_address_mode == BRW_ADDRESS_DIRECT) + { + return src_da16 (file, + inst->bits1.da16.src0_reg_type, + inst->bits1.da16.src0_reg_file, + inst->bits2.da16.src0_vert_stride, + inst->bits2.da16.src0_reg_nr, + inst->bits2.da16.src0_subreg_nr, + inst->bits2.da16.src0_abs, + inst->bits2.da16.src0_negate, + inst->bits2.da16.src0_swz_x, + inst->bits2.da16.src0_swz_y, + inst->bits2.da16.src0_swz_z, + inst->bits2.da16.src0_swz_w); + } + else + { + string (file, "Indirect align16 address mode not supported"); + return 1; + } + } +} + +static int src1 (FILE *file, const struct brw_instruction *inst) +{ + if (inst->bits1.da1.src1_reg_file == BRW_IMMEDIATE_VALUE) + return imm (file, inst->bits1.da1.src1_reg_type, + inst); + else if (inst->header.access_mode == BRW_ALIGN_1) + { + if (inst->bits3.da1.src1_address_mode == BRW_ADDRESS_DIRECT) + { + return src_da1 (file, + inst->bits1.da1.src1_reg_type, + inst->bits1.da1.src1_reg_file, + inst->bits3.da1.src1_vert_stride, + inst->bits3.da1.src1_width, + inst->bits3.da1.src1_horiz_stride, + inst->bits3.da1.src1_reg_nr, + inst->bits3.da1.src1_subreg_nr, + inst->bits3.da1.src1_abs, + inst->bits3.da1.src1_negate); + } + else + { + return src_ia1 (file, + inst->bits1.ia1.src1_reg_type, + inst->bits1.ia1.src1_reg_file, + inst->bits3.ia1.src1_indirect_offset, + inst->bits3.ia1.src1_subreg_nr, + inst->bits3.ia1.src1_negate, + inst->bits3.ia1.src1_abs, + inst->bits3.ia1.src1_address_mode, + inst->bits3.ia1.src1_horiz_stride, + inst->bits3.ia1.src1_width, + inst->bits3.ia1.src1_vert_stride); + } + } + else + { + if (inst->bits3.da16.src1_address_mode == BRW_ADDRESS_DIRECT) + { + return src_da16 (file, + inst->bits1.da16.src1_reg_type, + inst->bits1.da16.src1_reg_file, + inst->bits3.da16.src1_vert_stride, + inst->bits3.da16.src1_reg_nr, + inst->bits3.da16.src1_subreg_nr, + inst->bits3.da16.src1_abs, + inst->bits3.da16.src1_negate, + inst->bits3.da16.src1_swz_x, + inst->bits3.da16.src1_swz_y, + inst->bits3.da16.src1_swz_z, + inst->bits3.da16.src1_swz_w); + } + else + { + string (file, "Indirect align16 address mode not supported"); + return 1; + } + } +} + +int brw_disasm_insn (FILE *file, const struct brw_instruction *inst) +{ + int err = 0; + int space = 0; + + if (inst->header.predicate_control) { + string (file, "("); + err |= control (file, "predicate inverse", pred_inv, inst->header.predicate_inverse, NULL); + string (file, "f0"); + if (inst->bits2.da1.flag_reg_nr) + format (file, ".%d", inst->bits2.da1.flag_reg_nr); + if (inst->header.access_mode == BRW_ALIGN_1) + err |= control (file, "predicate control align1", pred_ctrl_align1, + inst->header.predicate_control, NULL); + else + err |= control (file, "predicate control align16", pred_ctrl_align16, + inst->header.predicate_control, NULL); + string (file, ") "); + } + + err |= print_opcode (file, inst->header.opcode); + err |= control (file, "saturate", saturate, inst->header.saturate, NULL); + err |= control (file, "debug control", debug_ctrl, inst->header.debug_control, NULL); + + if (inst->header.opcode != BRW_OPCODE_SEND) + err |= control (file, "conditional modifier", conditional_modifier, + inst->header.destreg__conditionalmod, NULL); + + if (inst->header.opcode != BRW_OPCODE_NOP) { + string (file, "("); + err |= control (file, "execution size", exec_size, inst->header.execution_size, NULL); + string (file, ")"); + } + + if (inst->header.opcode == BRW_OPCODE_SEND) + format (file, " %d", inst->header.destreg__conditionalmod); + + if (opcode[inst->header.opcode].ndst > 0) { + pad (file, 16); + err |= dest (file, inst); + } + if (opcode[inst->header.opcode].nsrc > 0) { + pad (file, 32); + err |= src0 (file, inst); + } + if (opcode[inst->header.opcode].nsrc > 1) { + pad (file, 48); + err |= src1 (file, inst); + } + + if (inst->header.opcode == BRW_OPCODE_SEND) { + newline (file); + pad (file, 16); + space = 0; + err |= control (file, "target function", target_function, + inst->bits3.generic.msg_target, &space); + switch (inst->bits3.generic.msg_target) { + case BRW_MESSAGE_TARGET_MATH: + err |= control (file, "math function", math_function, + inst->bits3.math.function, &space); + err |= control (file, "math saturate", math_saturate, + inst->bits3.math.saturate, &space); + err |= control (file, "math signed", math_signed, + inst->bits3.math.int_type, &space); + err |= control (file, "math scalar", math_scalar, + inst->bits3.math.data_type, &space); + err |= control (file, "math precision", math_precision, + inst->bits3.math.precision, &space); + break; + case BRW_MESSAGE_TARGET_SAMPLER: + format (file, " (%d, %d, ", + inst->bits3.sampler.binding_table_index, + inst->bits3.sampler.sampler); + err |= control (file, "sampler target format", sampler_target_format, + inst->bits3.sampler.return_format, NULL); + string (file, ")"); + break; + case BRW_MESSAGE_TARGET_DATAPORT_WRITE: + format (file, " (%d, %d, %d, %d)", + inst->bits3.dp_write.binding_table_index, + (inst->bits3.dp_write.pixel_scoreboard_clear << 3) | + inst->bits3.dp_write.msg_control, + inst->bits3.dp_write.msg_type, + inst->bits3.dp_write.send_commit_msg); + break; + case BRW_MESSAGE_TARGET_URB: + format (file, " %d", inst->bits3.urb.offset); + space = 1; + err |= control (file, "urb swizzle", urb_swizzle, + inst->bits3.urb.swizzle_control, &space); + err |= control (file, "urb allocate", urb_allocate, + inst->bits3.urb.allocate, &space); + err |= control (file, "urb used", urb_used, + inst->bits3.urb.used, &space); + err |= control (file, "urb complete", urb_complete, + inst->bits3.urb.complete, &space); + break; + case BRW_MESSAGE_TARGET_THREAD_SPAWNER: + break; + default: + format (file, "unsupported target %d", inst->bits3.generic.msg_target); + break; + } + if (space) + string (file, " "); + format (file, "mlen %d", + inst->bits3.generic.msg_length); + format (file, " rlen %d", + inst->bits3.generic.response_length); + } + pad (file, 64); + if (inst->header.opcode != BRW_OPCODE_NOP) { + string (file, "{"); + space = 1; + err |= control(file, "access mode", access_mode, inst->header.access_mode, &space); + err |= control (file, "mask control", mask_ctrl, inst->header.mask_control, &space); + err |= control (file, "dependency control", dep_ctrl, inst->header.dependency_control, &space); + err |= control (file, "compression control", compr_ctrl, inst->header.compression_control, &space); + err |= control (file, "thread control", thread_ctrl, inst->header.thread_control, &space); + if (inst->header.opcode == BRW_OPCODE_SEND) + err |= control (file, "end of thread", end_of_thread, + inst->bits3.generic.end_of_thread, &space); + if (space) + string (file, " "); + string (file, "}"); + } + string (file, ";"); + newline (file); + return err; +} + + +int brw_disasm (FILE *file, + const struct brw_instruction *inst, + unsigned count) +{ + int i, err; + + for (i = 0; i < count; i++) { + err = brw_disasm_insn(stderr, &inst[i]); + if (err) + return err; + } + + fprintf(file, "\n"); + return 0; +} + diff --git a/src/gallium/drivers/i965/brw_disasm.h b/src/gallium/drivers/i965/brw_disasm.h new file mode 100644 index 0000000..ba5b109 --- /dev/null +++ b/src/gallium/drivers/i965/brw_disasm.h @@ -0,0 +1,36 @@ +/* + * Copyright © 2008 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef BRW_DISASM_H +#define BRW_DISASM_H + +#include + +struct brw_instruction; + +int brw_disasm_insn (FILE *file, const struct brw_instruction *inst); +int brw_disasm (FILE *file, + const struct brw_instruction *inst, + unsigned count); + +#endif + diff --git a/src/gallium/drivers/i965/brw_draw.c b/src/gallium/drivers/i965/brw_draw.c new file mode 100644 index 0000000..3ab9024 --- /dev/null +++ b/src/gallium/drivers/i965/brw_draw.c @@ -0,0 +1,254 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + + +#include "util/u_inlines.h" +#include "util/u_prim.h" +#include "util/u_upload_mgr.h" + +#include "brw_draw.h" +#include "brw_defines.h" +#include "brw_context.h" +#include "brw_state.h" +#include "brw_debug.h" + +#include "brw_batchbuffer.h" + + +static uint32_t prim_to_hw_prim[PIPE_PRIM_POLYGON+1] = { + _3DPRIM_POINTLIST, + _3DPRIM_LINELIST, + _3DPRIM_LINELOOP, + _3DPRIM_LINESTRIP, + _3DPRIM_TRILIST, + _3DPRIM_TRISTRIP, + _3DPRIM_TRIFAN, + _3DPRIM_QUADLIST, + _3DPRIM_QUADSTRIP, + _3DPRIM_POLYGON +}; + + + +/* When the primitive changes, set a state bit and re-validate. Not + * the nicest and would rather deal with this by having all the + * programs be immune to the active primitive (ie. cope with all + * possibilities). That may not be realistic however. + */ +static int brw_set_prim(struct brw_context *brw, unsigned prim ) +{ + + if (BRW_DEBUG & DEBUG_PRIMS) + debug_printf("PRIM: %s\n", u_prim_name(prim)); + + if (prim != brw->primitive) { + unsigned reduced_prim; + + brw->primitive = prim; + brw->state.dirty.brw |= BRW_NEW_PRIMITIVE; + + reduced_prim = u_reduced_prim(prim); + if (reduced_prim != brw->reduced_primitive) { + brw->reduced_primitive = reduced_prim; + brw->state.dirty.brw |= BRW_NEW_REDUCED_PRIMITIVE; + } + } + + return prim_to_hw_prim[prim]; +} + + + +static int brw_emit_prim(struct brw_context *brw, + unsigned start, + unsigned count, + boolean indexed, + uint32_t hw_prim) +{ + struct brw_3d_primitive prim_packet; + int ret; + + if (BRW_DEBUG & DEBUG_PRIMS) + debug_printf("%s start %d count %d indexed %d hw_prim %d\n", + __FUNCTION__, start, count, indexed, hw_prim); + + prim_packet.header.opcode = CMD_3D_PRIM; + prim_packet.header.length = sizeof(prim_packet)/4 - 2; + prim_packet.header.pad = 0; + prim_packet.header.topology = hw_prim; + prim_packet.header.indexed = indexed; + + prim_packet.verts_per_instance = count; + prim_packet.start_vert_location = start; + if (indexed) + prim_packet.start_vert_location += brw->ib.start_vertex_offset; + prim_packet.instance_count = 1; + prim_packet.start_instance_location = 0; + prim_packet.base_vert_location = 0; /* prim->basevertex; XXX: add this to gallium */ + + + /* If we're set to always flush, do it before and after the primitive emit. + * We want to catch both missed flushes that hurt instruction/state cache + * and missed flushes of the render cache as it heads to other parts of + * the besides the draw code. + */ + if (0) { + BEGIN_BATCH(1, IGNORE_CLIPRECTS); + OUT_BATCH((CMD_MI_FLUSH << 16) | BRW_FLUSH_STATE_CACHE); + ADVANCE_BATCH(); + } + if (prim_packet.verts_per_instance) { + ret = brw_batchbuffer_data( brw->batch, &prim_packet, + sizeof(prim_packet), LOOP_CLIPRECTS); + if (ret) + return ret; + } + if (0) { + BEGIN_BATCH(1, IGNORE_CLIPRECTS); + OUT_BATCH((CMD_MI_FLUSH << 16) | BRW_FLUSH_STATE_CACHE); + ADVANCE_BATCH(); + } + + return 0; +} + + +/* May fail if out of video memory for texture or vbo upload, or on + * fallback conditions. + */ +static int +try_draw_range_elements(struct brw_context *brw, + boolean indexed, + unsigned hw_prim, + unsigned start, unsigned count) +{ + int ret; + + ret = brw_validate_state(brw); + if (ret) + return ret; + + /* Check that we can fit our state in with our existing batchbuffer, or + * flush otherwise. + */ + ret = brw->sws->check_aperture_space(brw->sws, + brw->state.validated_bos, + brw->state.validated_bo_count); + if (ret) + return ret; + + ret = brw_upload_state(brw); + if (ret) + return ret; + + ret = brw_emit_prim(brw, start, count, indexed, hw_prim); + if (ret) + return ret; + + if (brw->flags.always_flush_batch) + brw_context_flush( brw ); + + return 0; +} + + +static void +brw_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) +{ + struct brw_context *brw = brw_context(pipe); + int ret; + uint32_t hw_prim; + + hw_prim = brw_set_prim(brw, info->mode); + + if (BRW_DEBUG & DEBUG_PRIMS) + debug_printf("PRIM: %s start %d count %d index_buffer %p\n", + u_prim_name(info->mode), info->start, info->count, + (void *) brw->curr.index_buffer); + + assert(info->index_bias == 0); + + /* Potentially trigger upload of new index buffer range. + * XXX: do we really care? + */ + if (brw->curr.min_index != info->min_index || + brw->curr.max_index != info->max_index) + { + brw->curr.min_index = info->min_index; + brw->curr.max_index = info->max_index; + brw->state.dirty.mesa |= PIPE_NEW_INDEX_RANGE; + } + + + /* Make a first attempt at drawing: + */ + ret = try_draw_range_elements(brw, info->indexed, + hw_prim, info->start, info->count); + + /* Otherwise, flush and retry: + */ + if (ret != 0) { + brw_context_flush( brw ); + ret = try_draw_range_elements(brw, info->indexed, + hw_prim, info->start, info->count); + assert(ret == 0); + } +} + + +boolean brw_draw_init( struct brw_context *brw ) +{ + /* Register our drawing function: + */ + brw->base.draw_vbo = brw_draw_vbo; + + /* Create helpers for uploading data in user buffers: + */ + brw->vb.upload_vertex = u_upload_create( &brw->base, + 128 * 1024, + 64, + PIPE_BIND_VERTEX_BUFFER ); + if (brw->vb.upload_vertex == NULL) + return FALSE; + + brw->vb.upload_index = u_upload_create( &brw->base, + 32 * 1024, + 64, + PIPE_BIND_INDEX_BUFFER ); + if (brw->vb.upload_index == NULL) + return FALSE; + + return TRUE; +} + +void brw_draw_cleanup( struct brw_context *brw ) +{ + u_upload_destroy( brw->vb.upload_vertex ); + u_upload_destroy( brw->vb.upload_index ); + + bo_reference(&brw->ib.bo, NULL); +} diff --git a/src/gallium/drivers/i965/brw_draw.h b/src/gallium/drivers/i965/brw_draw.h new file mode 100644 index 0000000..8dc5dbc --- /dev/null +++ b/src/gallium/drivers/i965/brw_draw.h @@ -0,0 +1,39 @@ + /************************************************************************** + * + * Copyright 2005 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. + * + **************************************************************************/ + +#ifndef BRW_DRAW_H +#define BRW_DRAW_H + +#include "brw_types.h" + +struct brw_context; + +boolean brw_draw_init( struct brw_context *brw ); +void brw_draw_cleanup( struct brw_context *brw ); + + +#endif diff --git a/src/gallium/drivers/i965/brw_draw_upload.c b/src/gallium/drivers/i965/brw_draw_upload.c new file mode 100644 index 0000000..ebeb1e1 --- /dev/null +++ b/src/gallium/drivers/i965/brw_draw_upload.c @@ -0,0 +1,353 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + +#include "pipe/p_context.h" +#include "util/u_inlines.h" + +#include "util/u_upload_mgr.h" +#include "util/u_math.h" + +#include "brw_draw.h" +#include "brw_defines.h" +#include "brw_context.h" +#include "brw_state.h" +#include "brw_screen.h" +#include "brw_batchbuffer.h" +#include "brw_debug.h" +#include "brw_resource.h" + + + + +static unsigned get_index_type(int type) +{ + switch (type) { + case 1: return BRW_INDEX_BYTE; + case 2: return BRW_INDEX_WORD; + case 4: return BRW_INDEX_DWORD; + default: assert(0); return 0; + } +} + + +static int brw_prepare_vertices(struct brw_context *brw) +{ + unsigned int min_index = brw->curr.min_index; + unsigned int max_index = brw->curr.max_index; + GLuint i; + int ret; + + if (BRW_DEBUG & DEBUG_VERTS) + debug_printf("%s %d..%d\n", __FUNCTION__, min_index, max_index); + + + for (i = 0; i < brw->curr.num_vertex_buffers; i++) { + struct pipe_vertex_buffer *vb = &brw->curr.vertex_buffer[i]; + struct brw_winsys_buffer *bo; + struct pipe_resource *upload_buf = NULL; + unsigned offset; + + if (BRW_DEBUG & DEBUG_VERTS) + debug_printf("%s vb[%d] user:%d offset:0x%x sz:0x%x stride:0x%x\n", + __FUNCTION__, i, + brw_buffer_is_user_buffer(vb->buffer), + vb->buffer_offset, + vb->buffer->width0, + vb->stride); + + if (brw_buffer_is_user_buffer(vb->buffer)) { + + /* XXX: simplify this. Stop the state trackers from generating + * zero-stride buffers & have them use additional constants (or + * add support for >1 constant buffer) instead. + */ + unsigned size = (vb->stride == 0 ? + vb->buffer->width0 - vb->buffer_offset : + MAX2(vb->buffer->width0 - vb->buffer_offset, + vb->stride * (max_index + 1 - min_index))); + + ret = u_upload_buffer( brw->vb.upload_vertex, + vb->buffer_offset + min_index * vb->stride, + size, + vb->buffer, + &offset, + &upload_buf ); + if (ret) + return ret; + + bo = brw_buffer(upload_buf)->bo; + + assert(offset + size <= bo->size); + } + else + { + offset = vb->buffer_offset; + bo = brw_buffer(vb->buffer)->bo; + } + + assert(offset < bo->size); + + /* Set up post-upload info about this vertex buffer: + */ + brw->vb.vb[i].offset = offset; + brw->vb.vb[i].stride = vb->stride; + brw->vb.vb[i].vertex_count = (vb->stride == 0 ? + 1 : + (bo->size - offset) / vb->stride); + + bo_reference( &brw->vb.vb[i].bo, bo ); + + /* Don't need to retain this reference. We have a reference on + * the underlying winsys buffer: + */ + pipe_resource_reference( &upload_buf, NULL ); + } + + brw->vb.nr_vb = i; + brw_prepare_query_begin(brw); + + for (i = 0; i < brw->vb.nr_vb; i++) { + brw_add_validated_bo(brw, brw->vb.vb[i].bo); + } + + return 0; +} + +static int brw_emit_vertex_buffers( struct brw_context *brw ) +{ + int i; + + /* If the VS doesn't read any inputs (calculating vertex position from + * a state variable for some reason, for example), just bail. + * + * The stale VB state stays in place, but they don't do anything unless + * a VE loads from them. + */ + if (brw->vb.nr_vb == 0) { + if (BRW_DEBUG & DEBUG_VERTS) + debug_printf("%s: no active vertex buffers\n", __FUNCTION__); + + return 0; + } + + /* Emit VB state packets. + */ + BEGIN_BATCH(1 + brw->vb.nr_vb * 4, IGNORE_CLIPRECTS); + OUT_BATCH((CMD_VERTEX_BUFFER << 16) | + ((1 + brw->vb.nr_vb * 4) - 2)); + + for (i = 0; i < brw->vb.nr_vb; i++) { + OUT_BATCH((i << BRW_VB0_INDEX_SHIFT) | + BRW_VB0_ACCESS_VERTEXDATA | + (brw->vb.vb[i].stride << BRW_VB0_PITCH_SHIFT)); + OUT_RELOC(brw->vb.vb[i].bo, + BRW_USAGE_VERTEX, + brw->vb.vb[i].offset); + if (BRW_IS_IGDNG(brw)) { + OUT_RELOC(brw->vb.vb[i].bo, + BRW_USAGE_VERTEX, + brw->vb.vb[i].bo->size - 1); + } else + OUT_BATCH(brw->vb.vb[i].stride ? brw->vb.vb[i].vertex_count : 0); + OUT_BATCH(0); /* Instance data step rate */ + } + ADVANCE_BATCH(); + return 0; +} + + + +static int brw_emit_vertex_elements(struct brw_context *brw) +{ + const struct brw_vertex_element_packet *brw_velems = brw->curr.velems; + unsigned size = brw_velems->header.length + 2; + + /* why is this here */ + brw_emit_query_begin(brw); + + brw_batchbuffer_data(brw->batch, brw_velems, size * 4, IGNORE_CLIPRECTS); + + return 0; +} + + +static int brw_emit_vertices( struct brw_context *brw ) +{ + int ret; + + ret = brw_emit_vertex_buffers( brw ); + if (ret) + return ret; + + /* XXX should separate this? */ + ret = brw_emit_vertex_elements( brw ); + if (ret) + return ret; + + return 0; +} + + +const struct brw_tracked_state brw_vertices = { + .dirty = { + .mesa = (PIPE_NEW_INDEX_RANGE | + PIPE_NEW_VERTEX_BUFFER | + PIPE_NEW_VERTEX_ELEMENT), + .brw = BRW_NEW_BATCH, + .cache = 0, + }, + .prepare = brw_prepare_vertices, + .emit = brw_emit_vertices, +}; + + +static int brw_prepare_indices(struct brw_context *brw) +{ + struct pipe_resource *index_buffer = brw->curr.index_buffer; + struct pipe_resource *upload_buf = NULL; + struct brw_winsys_buffer *bo = NULL; + GLuint offset; + GLuint index_size, index_offset; + GLuint ib_size; + int ret; + + if (index_buffer == NULL) + return 0; + + if (BRW_DEBUG & DEBUG_VERTS) + debug_printf("%s: index_size:%d index_buffer->size:%d\n", + __FUNCTION__, + brw->curr.index_size, + brw->curr.index_buffer->width0); + + ib_size = index_buffer->width0; + index_size = brw->curr.index_size; + index_offset = brw->curr.index_offset; + + /* Turn userbuffer into a proper hardware buffer? + */ + if (brw_buffer_is_user_buffer(index_buffer)) { + + ret = u_upload_buffer( brw->vb.upload_index, + index_offset, + ib_size, + index_buffer, + &offset, + &upload_buf ); + if (ret) + return ret; + + bo = brw_buffer(upload_buf)->bo; + + /* XXX: annotate the userbuffer with the upload information so + * that successive calls don't get re-uploaded. + */ + } + else { + bo = brw_buffer(index_buffer)->bo; + ib_size = bo->size; + offset = index_offset; + } + + /* Use CMD_3D_PRIM's start_vertex_offset to avoid re-uploading the + * index buffer state when we're just moving the start index of our + * drawing. + * + * In gallium this will happen in the case where successive draw + * calls are made with (distinct?) userbuffers, but the upload_mgr + * places the data into a single winsys buffer. + * + * This statechange doesn't raise any state flags and is always + * just merged into the final draw packet: + */ + if (1) { + assert((offset & (index_size - 1)) == 0); + brw->ib.start_vertex_offset = offset / index_size; + } + + /* These statechanges trigger a new CMD_INDEX_BUFFER packet: + */ + if (brw->ib.bo != bo || + brw->ib.size != ib_size) + { + bo_reference(&brw->ib.bo, bo); + brw->ib.size = ib_size; + brw->state.dirty.brw |= BRW_NEW_INDEX_BUFFER; + } + + pipe_resource_reference( &upload_buf, NULL ); + brw_add_validated_bo(brw, brw->ib.bo); + return 0; +} + +const struct brw_tracked_state brw_indices = { + .dirty = { + .mesa = PIPE_NEW_INDEX_BUFFER, + .brw = 0, + .cache = 0, + }, + .prepare = brw_prepare_indices, +}; + +static int brw_emit_index_buffer(struct brw_context *brw) +{ + /* Emit the indexbuffer packet: + */ + if (brw->ib.bo) + { + struct brw_indexbuffer ib; + + memset(&ib, 0, sizeof(ib)); + + ib.header.bits.opcode = CMD_INDEX_BUFFER; + ib.header.bits.length = sizeof(ib)/4 - 2; + ib.header.bits.index_format = get_index_type(brw->ib.size); + ib.header.bits.cut_index_enable = 0; + + BEGIN_BATCH(4, IGNORE_CLIPRECTS); + OUT_BATCH( ib.header.dword ); + OUT_RELOC(brw->ib.bo, + BRW_USAGE_VERTEX, + brw->ib.offset); + OUT_RELOC(brw->ib.bo, + BRW_USAGE_VERTEX, + brw->ib.offset + brw->ib.size - 1); + OUT_BATCH( 0 ); + ADVANCE_BATCH(); + } + + return 0; +} + +const struct brw_tracked_state brw_index_buffer = { + .dirty = { + .mesa = 0, + .brw = BRW_NEW_BATCH | BRW_NEW_INDEX_BUFFER, + .cache = 0, + }, + .emit = brw_emit_index_buffer, +}; diff --git a/src/gallium/drivers/i965/brw_eu.c b/src/gallium/drivers/i965/brw_eu.c new file mode 100644 index 0000000..a8fcb5f --- /dev/null +++ b/src/gallium/drivers/i965/brw_eu.c @@ -0,0 +1,262 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_memory.h" + +#include "brw_context.h" +#include "brw_defines.h" +#include "brw_eu.h" + + + +/* How does predicate control work when execution_size != 8? Do I + * need to test/set for 0xffff when execution_size is 16? + */ +void brw_set_predicate_control_flag_value( struct brw_compile *p, GLuint value ) +{ + p->current->header.predicate_control = BRW_PREDICATE_NONE; + + if (value != 0xff) { + if (value != p->flag_value) { + brw_push_insn_state(p); + brw_MOV(p, brw_flag_reg(), brw_imm_uw(value)); + p->flag_value = value; + brw_pop_insn_state(p); + } + + p->current->header.predicate_control = BRW_PREDICATE_NORMAL; + } +} + +void brw_set_predicate_control( struct brw_compile *p, GLuint pc ) +{ + p->current->header.predicate_control = pc; +} + +void brw_set_conditionalmod( struct brw_compile *p, GLuint conditional ) +{ + p->current->header.destreg__conditionalmod = conditional; +} + +void brw_set_access_mode( struct brw_compile *p, GLuint access_mode ) +{ + p->current->header.access_mode = access_mode; +} + +void brw_set_compression_control( struct brw_compile *p, GLboolean compression_control ) +{ + p->current->header.compression_control = compression_control; +} + +void brw_set_mask_control( struct brw_compile *p, GLuint value ) +{ + p->current->header.mask_control = value; +} + +void brw_set_saturate( struct brw_compile *p, GLuint value ) +{ + p->current->header.saturate = value; +} + +void brw_push_insn_state( struct brw_compile *p ) +{ + assert(p->current != &p->stack[BRW_EU_MAX_INSN_STACK-1]); + memcpy(p->current+1, p->current, sizeof(struct brw_instruction)); + p->current++; +} + +void brw_pop_insn_state( struct brw_compile *p ) +{ + assert(p->current != p->stack); + p->current--; +} + + +/*********************************************************************** + */ +void brw_init_compile( struct brw_context *brw, struct brw_compile *p ) +{ + p->brw = brw; + p->nr_insn = 0; + p->current = p->stack; + memset(p->current, 0, sizeof(p->current[0])); + + /* Some defaults? + */ + brw_set_mask_control(p, BRW_MASK_ENABLE); /* what does this do? */ + brw_set_saturate(p, 0); + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + brw_set_predicate_control_flag_value(p, 0xff); +} + + +enum pipe_error brw_get_program( struct brw_compile *p, + const GLuint **data, + GLuint *sz ) +{ + GLuint i; + + for (i = 0; i < 8; i++) + brw_NOP(p); + + /* Is the generated program malformed for some reason? + */ + if (p->error) + return PIPE_ERROR_BAD_INPUT; + + *sz = p->nr_insn * sizeof(struct brw_instruction); + *data = (const GLuint *)p->store; + return PIPE_OK; +} + + + +/** + * Subroutine calls require special attention. + * Mesa instructions may be expanded into multiple hardware instructions + * so the prog_instruction::BranchTarget field can't be used as an index + * into the hardware instructions. + * + * The BranchTarget field isn't needed, however. Mesa's GLSL compiler + * emits CAL and BGNSUB instructions with labels that can be used to map + * subroutine calls to actual subroutine code blocks. + * + * The structures and function here implement patching of CAL instructions + * so they jump to the right subroutine code... + */ + + +/** + * For each OPCODE_BGNSUB we create one of these. + */ +struct brw_eu_label +{ + GLuint label; /**< the label number */ + GLuint position; /**< the position of the brw instruction for this label */ + struct brw_eu_label *next; /**< next in linked list */ +}; + + +/** + * For each OPCODE_CAL we create one of these. + */ +struct brw_eu_call +{ + GLuint call_inst_pos; /**< location of the CAL instruction */ + GLuint label; + struct brw_eu_call *next; /**< next in linked list */ +}; + + +/** + * Called for each OPCODE_BGNSUB. + */ +void +brw_save_label(struct brw_compile *c, unsigned l, GLuint position) +{ + struct brw_eu_label *label = CALLOC_STRUCT(brw_eu_label); + label->label = l; + label->position = position; + label->next = c->first_label; + c->first_label = label; +} + + +/** + * Called for each OPCODE_CAL. + */ +void +brw_save_call(struct brw_compile *c, GLuint label, GLuint call_pos) +{ + struct brw_eu_call *call = CALLOC_STRUCT(brw_eu_call); + call->call_inst_pos = call_pos; + call->label = label; + call->next = c->first_call; + c->first_call = call; +} + + +/** + * Lookup a label, return label's position/offset. + */ +static GLuint +brw_lookup_label(struct brw_compile *c, unsigned l) +{ + const struct brw_eu_label *label; + for (label = c->first_label; label; label = label->next) { + if (l == label->label) { + return label->position; + } + } + abort(); /* should never happen */ + return ~0; +} + + +/** + * When we're done generating code, this function is called to resolve + * subroutine calls. + */ +void +brw_resolve_cals(struct brw_compile *c) +{ + const struct brw_eu_call *call; + + for (call = c->first_call; call; call = call->next) { + const GLuint sub_loc = brw_lookup_label(c, call->label); + struct brw_instruction *brw_call_inst = &c->store[call->call_inst_pos]; + struct brw_instruction *brw_sub_inst = &c->store[sub_loc]; + GLint offset = brw_sub_inst - brw_call_inst; + + /* patch brw_inst1 to point to brw_inst2 */ + brw_set_src1(brw_call_inst, brw_imm_d(offset * 16)); + } + + /* free linked list of calls */ + { + struct brw_eu_call *call, *next; + for (call = c->first_call; call; call = next) { + next = call->next; + FREE(call); + } + c->first_call = NULL; + } + + /* free linked list of labels */ + { + struct brw_eu_label *label, *next; + for (label = c->first_label; label; label = next) { + next = label->next; + FREE(label); + } + c->first_label = NULL; + } +} diff --git a/src/gallium/drivers/i965/brw_eu.h b/src/gallium/drivers/i965/brw_eu.h new file mode 100644 index 0000000..af509b2 --- /dev/null +++ b/src/gallium/drivers/i965/brw_eu.h @@ -0,0 +1,992 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#ifndef BRW_EU_H +#define BRW_EU_H + +#include "util/u_debug.h" +#include "pipe/p_defines.h" + +#include "brw_structs.h" +#include "brw_defines.h" + +#define BRW_SWIZZLE4(a,b,c,d) (((a)<<0) | ((b)<<2) | ((c)<<4) | ((d)<<6)) +#define BRW_GET_SWZ(swz, idx) (((swz) >> ((idx)*2)) & 0x3) + +#define BRW_SWIZZLE_NOOP BRW_SWIZZLE4(0,1,2,3) +#define BRW_SWIZZLE_XYZW BRW_SWIZZLE4(0,1,2,3) +#define BRW_SWIZZLE_XXXX BRW_SWIZZLE4(0,0,0,0) +#define BRW_SWIZZLE_XYXY BRW_SWIZZLE4(0,1,0,1) + +#define BRW_WRITEMASK_NONE 0x00 +#define BRW_WRITEMASK_X 0x01 +#define BRW_WRITEMASK_Y 0x02 +#define BRW_WRITEMASK_XY 0x03 +#define BRW_WRITEMASK_Z 0x04 +#define BRW_WRITEMASK_XZ 0x05 +#define BRW_WRITEMASK_YZ 0x06 +#define BRW_WRITEMASK_XYZ 0x07 +#define BRW_WRITEMASK_W 0x08 +#define BRW_WRITEMASK_XW 0x09 +#define BRW_WRITEMASK_YW 0x0A +#define BRW_WRITEMASK_XYW 0x0B +#define BRW_WRITEMASK_ZW 0x0C +#define BRW_WRITEMASK_XZW 0x0D +#define BRW_WRITEMASK_YZW 0x0E +#define BRW_WRITEMASK_XYZW 0x0F + + +#define REG_SIZE (8*4) + + +/* These aren't hardware structs, just something useful for us to pass around: + * + * Align1 operation has a lot of control over input ranges. Used in + * WM programs to implement shaders decomposed into "channel serial" + * or "structure of array" form: + */ +struct brw_reg +{ + GLuint type:4; + GLuint file:2; + GLuint nr:8; + GLuint subnr:5; /* :1 in align16 */ + GLuint negate:1; /* source only */ + GLuint abs:1; /* source only */ + GLuint vstride:4; /* source only */ + GLuint width:3; /* src only, align1 only */ + GLuint hstride:2; /* align1 only */ + GLuint address_mode:1; /* relative addressing, hopefully! */ + GLuint pad0:1; + + union { + struct { + GLuint swizzle:8; /* src only, align16 only */ + GLuint writemask:4; /* dest only, align16 only */ + GLint indirect_offset:10; /* relative addressing offset */ + GLuint pad1:10; /* two dwords total */ + } bits; + + GLfloat f; + GLint d; + GLuint ud; + } dw1; +}; + + +struct brw_indirect { + GLuint addr_subnr:4; + GLint addr_offset:10; + GLuint pad:18; +}; + + +struct brw_eu_label; +struct brw_eu_call; + + + +#define BRW_EU_MAX_INSN_STACK 5 +#define BRW_EU_MAX_INSN 10000 + +struct brw_compile { + struct brw_instruction store[BRW_EU_MAX_INSN]; + GLuint nr_insn; + + /* Allow clients to push/pop instruction state: + */ + struct brw_instruction stack[BRW_EU_MAX_INSN_STACK]; + struct brw_instruction *current; + + GLuint flag_value; + GLboolean single_program_flow; + struct brw_context *brw; + + struct brw_eu_label *first_label; /**< linked list of labels */ + struct brw_eu_call *first_call; /**< linked list of CALs */ + + boolean error; +}; + + +void +brw_save_label(struct brw_compile *c, unsigned label, GLuint position); + +void +brw_save_call(struct brw_compile *c, unsigned label, GLuint call_pos); + +void +brw_resolve_cals(struct brw_compile *c); + + + +static INLINE int type_sz( GLuint type ) +{ + switch( type ) { + case BRW_REGISTER_TYPE_UD: + case BRW_REGISTER_TYPE_D: + case BRW_REGISTER_TYPE_F: + return 4; + case BRW_REGISTER_TYPE_HF: + case BRW_REGISTER_TYPE_UW: + case BRW_REGISTER_TYPE_W: + return 2; + case BRW_REGISTER_TYPE_UB: + case BRW_REGISTER_TYPE_B: + return 1; + default: + return 0; + } +} + +/** + * Construct a brw_reg. + * \param file one of the BRW_x_REGISTER_FILE values + * \param nr register number/index + * \param subnr register sub number + * \param type one of BRW_REGISTER_TYPE_x + * \param vstride one of BRW_VERTICAL_STRIDE_x + * \param width one of BRW_WIDTH_x + * \param hstride one of BRW_HORIZONTAL_STRIDE_x + * \param swizzle one of BRW_SWIZZLE_x + * \param writemask BRW_WRITEMASK_X/Y/Z/W bitfield + */ +static INLINE struct brw_reg brw_reg( GLuint file, + GLuint nr, + GLuint subnr, + GLuint type, + GLuint vstride, + GLuint width, + GLuint hstride, + GLuint swizzle, + GLuint writemask ) +{ + struct brw_reg reg; + if (type == BRW_GENERAL_REGISTER_FILE) + assert(nr < BRW_MAX_GRF); + else if (type == BRW_MESSAGE_REGISTER_FILE) + assert(nr < BRW_MAX_MRF); + else if (type == BRW_ARCHITECTURE_REGISTER_FILE) + assert(nr <= BRW_ARF_IP); + + reg.type = type; + reg.file = file; + reg.nr = nr; + reg.subnr = subnr * type_sz(type); + reg.negate = 0; + reg.abs = 0; + reg.vstride = vstride; + reg.width = width; + reg.hstride = hstride; + reg.address_mode = BRW_ADDRESS_DIRECT; + reg.pad0 = 0; + + /* Could do better: If the reg is r5.3<0;1,0>, we probably want to + * set swizzle and writemask to W, as the lower bits of subnr will + * be lost when converted to align16. This is probably too much to + * keep track of as you'd want it adjusted by suboffset(), etc. + * Perhaps fix up when converting to align16? + */ + reg.dw1.bits.swizzle = swizzle; + reg.dw1.bits.writemask = writemask; + reg.dw1.bits.indirect_offset = 0; + reg.dw1.bits.pad1 = 0; + return reg; +} + +/** Construct float[16] register */ +static INLINE struct brw_reg brw_vec16_reg( GLuint file, + GLuint nr, + GLuint subnr ) +{ + return brw_reg(file, + nr, + subnr, + BRW_REGISTER_TYPE_F, + BRW_VERTICAL_STRIDE_16, + BRW_WIDTH_16, + BRW_HORIZONTAL_STRIDE_1, + BRW_SWIZZLE_XYZW, + BRW_WRITEMASK_XYZW); +} + +/** Construct float[8] register */ +static INLINE struct brw_reg brw_vec8_reg( GLuint file, + GLuint nr, + GLuint subnr ) +{ + return brw_reg(file, + nr, + subnr, + BRW_REGISTER_TYPE_F, + BRW_VERTICAL_STRIDE_8, + BRW_WIDTH_8, + BRW_HORIZONTAL_STRIDE_1, + BRW_SWIZZLE_XYZW, + BRW_WRITEMASK_XYZW); +} + +/** Construct float[4] register */ +static INLINE struct brw_reg brw_vec4_reg( GLuint file, + GLuint nr, + GLuint subnr ) +{ + return brw_reg(file, + nr, + subnr, + BRW_REGISTER_TYPE_F, + BRW_VERTICAL_STRIDE_4, + BRW_WIDTH_4, + BRW_HORIZONTAL_STRIDE_1, + BRW_SWIZZLE_XYZW, + BRW_WRITEMASK_XYZW); +} + +/** Construct float[2] register */ +static INLINE struct brw_reg brw_vec2_reg( GLuint file, + GLuint nr, + GLuint subnr ) +{ + return brw_reg(file, + nr, + subnr, + BRW_REGISTER_TYPE_F, + BRW_VERTICAL_STRIDE_2, + BRW_WIDTH_2, + BRW_HORIZONTAL_STRIDE_1, + BRW_SWIZZLE_XYXY, + BRW_WRITEMASK_XY); +} + +/** Construct float[1] register */ +static INLINE struct brw_reg brw_vec1_reg( GLuint file, + GLuint nr, + GLuint subnr ) +{ + return brw_reg(file, + nr, + subnr, + BRW_REGISTER_TYPE_F, + BRW_VERTICAL_STRIDE_0, + BRW_WIDTH_1, + BRW_HORIZONTAL_STRIDE_0, + BRW_SWIZZLE_XXXX, + BRW_WRITEMASK_X); +} + + +static INLINE struct brw_reg retype( struct brw_reg reg, + GLuint type ) +{ + reg.type = type; + return reg; +} + +static INLINE struct brw_reg suboffset( struct brw_reg reg, + GLuint delta ) +{ + reg.subnr += delta * type_sz(reg.type); + return reg; +} + + +static INLINE struct brw_reg offset( struct brw_reg reg, + GLuint delta ) +{ + reg.nr += delta; + return reg; +} + + +static INLINE struct brw_reg byte_offset( struct brw_reg reg, + GLuint bytes ) +{ + GLuint newoffset = reg.nr * REG_SIZE + reg.subnr + bytes; + reg.nr = newoffset / REG_SIZE; + reg.subnr = newoffset % REG_SIZE; + return reg; +} + + +/** Construct unsigned word[16] register */ +static INLINE struct brw_reg brw_uw16_reg( GLuint file, + GLuint nr, + GLuint subnr ) +{ + return suboffset(retype(brw_vec16_reg(file, nr, 0), BRW_REGISTER_TYPE_UW), subnr); +} + +/** Construct unsigned word[8] register */ +static INLINE struct brw_reg brw_uw8_reg( GLuint file, + GLuint nr, + GLuint subnr ) +{ + return suboffset(retype(brw_vec8_reg(file, nr, 0), BRW_REGISTER_TYPE_UW), subnr); +} + +/** Construct unsigned word[1] register */ +static INLINE struct brw_reg brw_uw1_reg( GLuint file, + GLuint nr, + GLuint subnr ) +{ + return suboffset(retype(brw_vec1_reg(file, nr, 0), BRW_REGISTER_TYPE_UW), subnr); +} + +static INLINE struct brw_reg brw_imm_reg( GLuint type ) +{ + return brw_reg( BRW_IMMEDIATE_VALUE, + 0, + 0, + type, + BRW_VERTICAL_STRIDE_0, + BRW_WIDTH_1, + BRW_HORIZONTAL_STRIDE_0, + 0, + 0); +} + +/** Construct float immediate register */ +static INLINE struct brw_reg brw_imm_f( GLfloat f ) +{ + struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_F); + imm.dw1.f = f; + return imm; +} + +/** Construct integer immediate register */ +static INLINE struct brw_reg brw_imm_d( GLint d ) +{ + struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_D); + imm.dw1.d = d; + return imm; +} + +/** Construct uint immediate register */ +static INLINE struct brw_reg brw_imm_ud( GLuint ud ) +{ + struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_UD); + imm.dw1.ud = ud; + return imm; +} + +/** Construct ushort immediate register */ +static INLINE struct brw_reg brw_imm_uw( GLushort uw ) +{ + struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_UW); + imm.dw1.ud = uw | (uw << 16); + return imm; +} + +/** Construct short immediate register */ +static INLINE struct brw_reg brw_imm_w( GLshort w ) +{ + struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_W); + imm.dw1.d = w | (w << 16); + return imm; +} + +/* brw_imm_b and brw_imm_ub aren't supported by hardware - the type + * numbers alias with _V and _VF below: + */ + +/** Construct vector of eight signed half-byte values */ +static INLINE struct brw_reg brw_imm_v( GLuint v ) +{ + struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_V); + imm.vstride = BRW_VERTICAL_STRIDE_0; + imm.width = BRW_WIDTH_8; + imm.hstride = BRW_HORIZONTAL_STRIDE_1; + imm.dw1.ud = v; + return imm; +} + +/** Construct vector of four 8-bit float values */ +static INLINE struct brw_reg brw_imm_vf( GLuint v ) +{ + struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_VF); + imm.vstride = BRW_VERTICAL_STRIDE_0; + imm.width = BRW_WIDTH_4; + imm.hstride = BRW_HORIZONTAL_STRIDE_1; + imm.dw1.ud = v; + return imm; +} + +#define VF_ZERO 0x0 +#define VF_ONE 0x30 +#define VF_NEG (1<<7) + +static INLINE struct brw_reg brw_imm_vf4( GLuint v0, + GLuint v1, + GLuint v2, + GLuint v3) +{ + struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_VF); + imm.vstride = BRW_VERTICAL_STRIDE_0; + imm.width = BRW_WIDTH_4; + imm.hstride = BRW_HORIZONTAL_STRIDE_1; + imm.dw1.ud = ((v0 << 0) | + (v1 << 8) | + (v2 << 16) | + (v3 << 24)); + return imm; +} + + +static INLINE struct brw_reg brw_address( struct brw_reg reg ) +{ + return brw_imm_uw(reg.nr * REG_SIZE + reg.subnr); +} + +/** Construct float[1] general-purpose register */ +static INLINE struct brw_reg brw_vec1_grf( GLuint nr, GLuint subnr ) +{ + return brw_vec1_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr); +} + +/** Construct float[2] general-purpose register */ +static INLINE struct brw_reg brw_vec2_grf( GLuint nr, GLuint subnr ) +{ + return brw_vec2_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr); +} + +/** Construct float[4] general-purpose register */ +static INLINE struct brw_reg brw_vec4_grf( GLuint nr, GLuint subnr ) +{ + return brw_vec4_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr); +} + +/** Construct float[8] general-purpose register */ +static INLINE struct brw_reg brw_vec8_grf( GLuint nr, GLuint subnr ) +{ + return brw_vec8_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr); +} + + +static INLINE struct brw_reg brw_uw8_grf( GLuint nr, GLuint subnr ) +{ + return brw_uw8_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr); +} + +static INLINE struct brw_reg brw_uw16_grf( GLuint nr, GLuint subnr ) +{ + return brw_uw16_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr); +} + + +/** Construct null register (usually used for setting condition codes) */ +static INLINE struct brw_reg brw_null_reg( void ) +{ + return brw_vec8_reg(BRW_ARCHITECTURE_REGISTER_FILE, + BRW_ARF_NULL, + 0); +} + +static INLINE struct brw_reg brw_address_reg( GLuint subnr ) +{ + return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE, + BRW_ARF_ADDRESS, + subnr); +} + +/* If/else instructions break in align16 mode if writemask & swizzle + * aren't xyzw. This goes against the convention for other scalar + * regs: + */ +static INLINE struct brw_reg brw_ip_reg( void ) +{ + return brw_reg(BRW_ARCHITECTURE_REGISTER_FILE, + BRW_ARF_IP, + 0, + BRW_REGISTER_TYPE_UD, + BRW_VERTICAL_STRIDE_4, /* ? */ + BRW_WIDTH_1, + BRW_HORIZONTAL_STRIDE_0, + BRW_SWIZZLE_XYZW, /* NOTE! */ + BRW_WRITEMASK_XYZW); /* NOTE! */ +} + +static INLINE struct brw_reg brw_acc_reg( void ) +{ + return brw_vec8_reg(BRW_ARCHITECTURE_REGISTER_FILE, + BRW_ARF_ACCUMULATOR, + 0); +} + + +static INLINE struct brw_reg brw_flag_reg( void ) +{ + return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE, + BRW_ARF_FLAG, + 0); +} + + +static INLINE struct brw_reg brw_mask_reg( GLuint subnr ) +{ + return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE, + BRW_ARF_MASK, + subnr); +} + +static INLINE struct brw_reg brw_message_reg( GLuint nr ) +{ + assert(nr < BRW_MAX_MRF); + return brw_vec8_reg(BRW_MESSAGE_REGISTER_FILE, + nr, + 0); +} + + + + +/* This is almost always called with a numeric constant argument, so + * make things easy to evaluate at compile time: + */ +static INLINE GLuint cvt( GLuint val ) +{ + switch (val) { + case 0: return 0; + case 1: return 1; + case 2: return 2; + case 4: return 3; + case 8: return 4; + case 16: return 5; + case 32: return 6; + } + return 0; +} + +static INLINE struct brw_reg stride( struct brw_reg reg, + GLuint vstride, + GLuint width, + GLuint hstride ) +{ + reg.vstride = cvt(vstride); + reg.width = cvt(width) - 1; + reg.hstride = cvt(hstride); + return reg; +} + + +static INLINE struct brw_reg vec16( struct brw_reg reg ) +{ + return stride(reg, 16,16,1); +} + +static INLINE struct brw_reg vec8( struct brw_reg reg ) +{ + return stride(reg, 8,8,1); +} + +static INLINE struct brw_reg vec4( struct brw_reg reg ) +{ + return stride(reg, 4,4,1); +} + +static INLINE struct brw_reg vec2( struct brw_reg reg ) +{ + return stride(reg, 2,2,1); +} + +static INLINE struct brw_reg vec1( struct brw_reg reg ) +{ + return stride(reg, 0,1,0); +} + + +static INLINE struct brw_reg get_element( struct brw_reg reg, GLuint elt ) +{ + return vec1(suboffset(reg, elt)); +} + +static INLINE struct brw_reg get_element_ud( struct brw_reg reg, GLuint elt ) +{ + return vec1(suboffset(retype(reg, BRW_REGISTER_TYPE_UD), elt)); +} + + +static INLINE struct brw_reg brw_swizzle( struct brw_reg reg, + GLuint x, + GLuint y, + GLuint z, + GLuint w) +{ + reg.dw1.bits.swizzle = BRW_SWIZZLE4(BRW_GET_SWZ(reg.dw1.bits.swizzle, x), + BRW_GET_SWZ(reg.dw1.bits.swizzle, y), + BRW_GET_SWZ(reg.dw1.bits.swizzle, z), + BRW_GET_SWZ(reg.dw1.bits.swizzle, w)); + return reg; +} + + +static INLINE struct brw_reg brw_swizzle1( struct brw_reg reg, + GLuint x ) +{ + return brw_swizzle(reg, x, x, x, x); +} + +static INLINE struct brw_reg brw_writemask( struct brw_reg reg, + GLuint mask ) +{ + reg.dw1.bits.writemask &= mask; + return reg; +} + +static INLINE struct brw_reg brw_set_writemask( struct brw_reg reg, + GLuint mask ) +{ + reg.dw1.bits.writemask = mask; + return reg; +} + +static INLINE struct brw_reg negate( struct brw_reg reg ) +{ + reg.negate ^= 1; + return reg; +} + +static INLINE struct brw_reg brw_abs( struct brw_reg reg ) +{ + reg.abs = 1; + return reg; +} + +/*********************************************************************** + */ +static INLINE struct brw_reg brw_vec4_indirect( GLuint subnr, + GLint offset ) +{ + struct brw_reg reg = brw_vec4_grf(0, 0); + reg.subnr = subnr; + reg.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER; + reg.dw1.bits.indirect_offset = offset; + return reg; +} + +static INLINE struct brw_reg brw_vec1_indirect( GLuint subnr, + GLint offset ) +{ + struct brw_reg reg = brw_vec1_grf(0, 0); + reg.subnr = subnr; + reg.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER; + reg.dw1.bits.indirect_offset = offset; + return reg; +} + +static INLINE struct brw_reg deref_4f(struct brw_indirect ptr, GLint offset) +{ + return brw_vec4_indirect(ptr.addr_subnr, ptr.addr_offset + offset); +} + +static INLINE struct brw_reg deref_1f(struct brw_indirect ptr, GLint offset) +{ + return brw_vec1_indirect(ptr.addr_subnr, ptr.addr_offset + offset); +} + +static INLINE struct brw_reg deref_4b(struct brw_indirect ptr, GLint offset) +{ + return retype(deref_4f(ptr, offset), BRW_REGISTER_TYPE_B); +} + +static INLINE struct brw_reg deref_1uw(struct brw_indirect ptr, GLint offset) +{ + return retype(deref_1f(ptr, offset), BRW_REGISTER_TYPE_UW); +} + +static INLINE struct brw_reg deref_1d(struct brw_indirect ptr, GLint offset) +{ + return retype(deref_1f(ptr, offset), BRW_REGISTER_TYPE_D); +} + +static INLINE struct brw_reg deref_1ud(struct brw_indirect ptr, GLint offset) +{ + return retype(deref_1f(ptr, offset), BRW_REGISTER_TYPE_UD); +} + +static INLINE struct brw_reg get_addr_reg(struct brw_indirect ptr) +{ + return brw_address_reg(ptr.addr_subnr); +} + +static INLINE struct brw_indirect brw_indirect_offset( struct brw_indirect ptr, GLint offset ) +{ + ptr.addr_offset += offset; + return ptr; +} + +static INLINE struct brw_indirect brw_indirect( GLuint addr_subnr, GLint offset ) +{ + struct brw_indirect ptr; + ptr.addr_subnr = addr_subnr; + ptr.addr_offset = offset; + ptr.pad = 0; + return ptr; +} + +/** Do two brw_regs refer to the same register? */ +static INLINE GLboolean +brw_same_reg(struct brw_reg r1, struct brw_reg r2) +{ + return r1.file == r2.file && r1.nr == r2.nr; +} + +static INLINE struct brw_instruction *current_insn( struct brw_compile *p) +{ + return &p->store[p->nr_insn]; +} + +void brw_pop_insn_state( struct brw_compile *p ); +void brw_push_insn_state( struct brw_compile *p ); +void brw_set_mask_control( struct brw_compile *p, GLuint value ); +void brw_set_saturate( struct brw_compile *p, GLuint value ); +void brw_set_access_mode( struct brw_compile *p, GLuint access_mode ); +void brw_set_compression_control( struct brw_compile *p, GLboolean control ); +void brw_set_predicate_control_flag_value( struct brw_compile *p, GLuint value ); +void brw_set_predicate_control( struct brw_compile *p, GLuint pc ); +void brw_set_conditionalmod( struct brw_compile *p, GLuint conditional ); + +void brw_init_compile( struct brw_context *, struct brw_compile *p ); + +enum pipe_error brw_get_program( struct brw_compile *p, + const GLuint **program, + GLuint *sz ); + + +/* Helpers for regular instructions: + */ +#define ALU1(OP) \ +struct brw_instruction *brw_##OP(struct brw_compile *p, \ + struct brw_reg dest, \ + struct brw_reg src0); + +#define ALU2(OP) \ +struct brw_instruction *brw_##OP(struct brw_compile *p, \ + struct brw_reg dest, \ + struct brw_reg src0, \ + struct brw_reg src1); + +ALU1(MOV) +ALU2(SEL) +ALU1(NOT) +ALU2(AND) +ALU2(OR) +ALU2(XOR) +ALU2(SHR) +ALU2(SHL) +ALU2(RSR) +ALU2(RSL) +ALU2(ASR) +ALU2(JMPI) +ALU2(ADD) +ALU2(MUL) +ALU1(FRC) +ALU1(RNDD) +ALU1(RNDZ) +ALU2(MAC) +ALU2(MACH) +ALU1(LZD) +ALU2(DP4) +ALU2(DPH) +ALU2(DP3) +ALU2(DP2) +ALU2(LINE) + +#undef ALU1 +#undef ALU2 + + + +/* Helpers for SEND instruction: + */ +void brw_urb_WRITE(struct brw_compile *p, + struct brw_reg dest, + GLuint msg_reg_nr, + struct brw_reg src0, + GLboolean allocate, + GLboolean used, + GLuint msg_length, + GLuint response_length, + GLboolean eot, + GLboolean writes_complete, + GLuint offset, + GLuint swizzle); + +void brw_ff_sync(struct brw_compile *p, + struct brw_reg dest, + GLuint msg_reg_nr, + struct brw_reg src0, + GLboolean allocate, + GLboolean used, + GLuint msg_length, + GLuint response_length, + GLboolean eot, + GLboolean writes_complete, + GLuint offset, + GLuint swizzle); + +void brw_fb_WRITE(struct brw_compile *p, + struct brw_reg dest, + GLuint msg_reg_nr, + struct brw_reg src0, + GLuint binding_table_index, + GLuint msg_length, + GLuint response_length, + GLboolean eot); + +void brw_SAMPLE(struct brw_compile *p, + struct brw_reg dest, + GLuint msg_reg_nr, + struct brw_reg src0, + GLuint binding_table_index, + GLuint sampler, + GLuint writemask, + GLuint msg_type, + GLuint response_length, + GLuint msg_length, + GLboolean eot, + GLuint header_present, + GLuint simd_mode); + +void brw_math_16( struct brw_compile *p, + struct brw_reg dest, + GLuint function, + GLuint saturate, + GLuint msg_reg_nr, + struct brw_reg src, + GLuint precision ); + +void brw_math( struct brw_compile *p, + struct brw_reg dest, + GLuint function, + GLuint saturate, + GLuint msg_reg_nr, + struct brw_reg src, + GLuint data_type, + GLuint precision ); + +void brw_dp_READ_16( struct brw_compile *p, + struct brw_reg dest, + GLuint scratch_offset ); + +void brw_dp_READ_4( struct brw_compile *p, + struct brw_reg dest, + GLboolean relAddr, + GLuint location, + GLuint bind_table_index ); + +void brw_dp_READ_4_vs( struct brw_compile *p, + struct brw_reg dest, + GLuint oword, + GLboolean relAddr, + struct brw_reg addrReg, + GLuint location, + GLuint bind_table_index ); + +void brw_dp_WRITE_16( struct brw_compile *p, + struct brw_reg src, + GLuint scratch_offset ); + +/* If/else/endif. Works by manipulating the execution flags on each + * channel. + */ +struct brw_instruction *brw_IF(struct brw_compile *p, + GLuint execute_size); + +struct brw_instruction *brw_ELSE(struct brw_compile *p, + struct brw_instruction *if_insn); + +void brw_ENDIF(struct brw_compile *p, + struct brw_instruction *if_or_else_insn); + + +/* DO/WHILE loops: + */ +struct brw_instruction *brw_DO(struct brw_compile *p, + GLuint execute_size); + +struct brw_instruction *brw_WHILE(struct brw_compile *p, + struct brw_instruction *patch_insn); + +struct brw_instruction *brw_BREAK(struct brw_compile *p); +struct brw_instruction *brw_CONT(struct brw_compile *p); +/* Forward jumps: + */ +void brw_land_fwd_jump(struct brw_compile *p, + struct brw_instruction *jmp_insn); + + + +void brw_NOP(struct brw_compile *p); + +/* Special case: there is never a destination, execution size will be + * taken from src0: + */ +void brw_CMP(struct brw_compile *p, + struct brw_reg dest, + GLuint conditional, + struct brw_reg src0, + struct brw_reg src1); + +void brw_print_reg( struct brw_reg reg ); + + +/*********************************************************************** + * brw_eu_util.c: + */ + +void brw_copy_indirect_to_indirect(struct brw_compile *p, + struct brw_indirect dst_ptr, + struct brw_indirect src_ptr, + GLuint count); + +void brw_copy_from_indirect(struct brw_compile *p, + struct brw_reg dst, + struct brw_indirect ptr, + GLuint count); + +void brw_copy4(struct brw_compile *p, + struct brw_reg dst, + struct brw_reg src, + GLuint count); + +void brw_copy8(struct brw_compile *p, + struct brw_reg dst, + struct brw_reg src, + GLuint count); + +void brw_math_invert( struct brw_compile *p, + struct brw_reg dst, + struct brw_reg src); + +void brw_set_src1( struct brw_instruction *insn, + struct brw_reg reg ); +#endif diff --git a/src/gallium/drivers/i965/brw_eu_debug.c b/src/gallium/drivers/i965/brw_eu_debug.c new file mode 100644 index 0000000..5989f5a --- /dev/null +++ b/src/gallium/drivers/i965/brw_eu_debug.c @@ -0,0 +1,94 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_debug.h" + +#include "brw_eu.h" + +void brw_print_reg( struct brw_reg hwreg ) +{ + static const char *file[] = { + "arf", + "grf", + "msg", + "imm" + }; + + static const char *type[] = { + "ud", + "d", + "uw", + "w", + "ub", + "vf", + "hf", + "f" + }; + + debug_printf("%s%s", + hwreg.abs ? "abs/" : "", + hwreg.negate ? "-" : ""); + + if (hwreg.file == BRW_GENERAL_REGISTER_FILE && + hwreg.nr % 2 == 0 && + hwreg.subnr == 0 && + hwreg.vstride == BRW_VERTICAL_STRIDE_8 && + hwreg.width == BRW_WIDTH_8 && + hwreg.hstride == BRW_HORIZONTAL_STRIDE_1 && + hwreg.type == BRW_REGISTER_TYPE_F) { + /* vector register */ + debug_printf("vec%d", hwreg.nr); + } + else if (hwreg.file == BRW_GENERAL_REGISTER_FILE && + hwreg.vstride == BRW_VERTICAL_STRIDE_0 && + hwreg.width == BRW_WIDTH_1 && + hwreg.hstride == BRW_HORIZONTAL_STRIDE_0 && + hwreg.type == BRW_REGISTER_TYPE_F) { + /* "scalar" register */ + debug_printf("scl%d.%d", hwreg.nr, hwreg.subnr / 4); + } + else if (hwreg.file == BRW_IMMEDIATE_VALUE) { + debug_printf("imm %f", hwreg.dw1.f); + } + else { + debug_printf("%s%d.%d<%d;%d,%d>:%s", + file[hwreg.file], + hwreg.nr, + hwreg.subnr / type_sz(hwreg.type), + hwreg.vstride ? (1<<(hwreg.vstride-1)) : 0, + 1< + */ + + +#include "brw_context.h" +#include "brw_defines.h" +#include "brw_eu.h" +#include "brw_debug.h" +#include "brw_disasm.h" + + + + +/*********************************************************************** + * Internal helper for constructing instructions + */ + +static void guess_execution_size( struct brw_instruction *insn, + struct brw_reg reg ) +{ + if (reg.width == BRW_WIDTH_8 && + insn->header.compression_control == BRW_COMPRESSION_COMPRESSED) + insn->header.execution_size = BRW_EXECUTE_16; + else + insn->header.execution_size = reg.width; /* note - definitions are compatible */ +} + + +static void brw_set_dest( struct brw_instruction *insn, + struct brw_reg dest ) +{ + if (dest.type != BRW_ARCHITECTURE_REGISTER_FILE) + assert(dest.nr < 128); + + insn->bits1.da1.dest_reg_file = dest.file; + insn->bits1.da1.dest_reg_type = dest.type; + insn->bits1.da1.dest_address_mode = dest.address_mode; + + if (dest.address_mode == BRW_ADDRESS_DIRECT) { + insn->bits1.da1.dest_reg_nr = dest.nr; + + if (insn->header.access_mode == BRW_ALIGN_1) { + insn->bits1.da1.dest_subreg_nr = dest.subnr; + if (dest.hstride == BRW_HORIZONTAL_STRIDE_0) + dest.hstride = BRW_HORIZONTAL_STRIDE_1; + insn->bits1.da1.dest_horiz_stride = dest.hstride; + } + else { + insn->bits1.da16.dest_subreg_nr = dest.subnr / 16; + insn->bits1.da16.dest_writemask = dest.dw1.bits.writemask; + } + } + else { + insn->bits1.ia1.dest_subreg_nr = dest.subnr; + + /* These are different sizes in align1 vs align16: + */ + if (insn->header.access_mode == BRW_ALIGN_1) { + insn->bits1.ia1.dest_indirect_offset = dest.dw1.bits.indirect_offset; + if (dest.hstride == BRW_HORIZONTAL_STRIDE_0) + dest.hstride = BRW_HORIZONTAL_STRIDE_1; + insn->bits1.ia1.dest_horiz_stride = dest.hstride; + } + else { + insn->bits1.ia16.dest_indirect_offset = dest.dw1.bits.indirect_offset; + } + } + + /* NEW: Set the execution size based on dest.width and + * insn->compression_control: + */ + guess_execution_size(insn, dest); +} + +static void brw_set_src0( struct brw_instruction *insn, + struct brw_reg reg ) +{ + assert(reg.file != BRW_MESSAGE_REGISTER_FILE); + + if (reg.type != BRW_ARCHITECTURE_REGISTER_FILE) + assert(reg.nr < 128); + + insn->bits1.da1.src0_reg_file = reg.file; + insn->bits1.da1.src0_reg_type = reg.type; + insn->bits2.da1.src0_abs = reg.abs; + insn->bits2.da1.src0_negate = reg.negate; + insn->bits2.da1.src0_address_mode = reg.address_mode; + + if (reg.file == BRW_IMMEDIATE_VALUE) { + insn->bits3.ud = reg.dw1.ud; + + /* Required to set some fields in src1 as well: + */ + insn->bits1.da1.src1_reg_file = 0; /* arf */ + insn->bits1.da1.src1_reg_type = reg.type; + } + else + { + if (reg.address_mode == BRW_ADDRESS_DIRECT) { + if (insn->header.access_mode == BRW_ALIGN_1) { + insn->bits2.da1.src0_subreg_nr = reg.subnr; + insn->bits2.da1.src0_reg_nr = reg.nr; + } + else { + insn->bits2.da16.src0_subreg_nr = reg.subnr / 16; + insn->bits2.da16.src0_reg_nr = reg.nr; + } + } + else { + insn->bits2.ia1.src0_subreg_nr = reg.subnr; + + if (insn->header.access_mode == BRW_ALIGN_1) { + insn->bits2.ia1.src0_indirect_offset = reg.dw1.bits.indirect_offset; + } + else { + insn->bits2.ia16.src0_subreg_nr = reg.dw1.bits.indirect_offset; + } + } + + if (insn->header.access_mode == BRW_ALIGN_1) { + if (reg.width == BRW_WIDTH_1 && + insn->header.execution_size == BRW_EXECUTE_1) { + insn->bits2.da1.src0_horiz_stride = BRW_HORIZONTAL_STRIDE_0; + insn->bits2.da1.src0_width = BRW_WIDTH_1; + insn->bits2.da1.src0_vert_stride = BRW_VERTICAL_STRIDE_0; + } + else { + insn->bits2.da1.src0_horiz_stride = reg.hstride; + insn->bits2.da1.src0_width = reg.width; + insn->bits2.da1.src0_vert_stride = reg.vstride; + } + } + else { + insn->bits2.da16.src0_swz_x = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_X); + insn->bits2.da16.src0_swz_y = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_Y); + insn->bits2.da16.src0_swz_z = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_Z); + insn->bits2.da16.src0_swz_w = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_W); + + /* This is an oddity of the fact we're using the same + * descriptions for registers in align_16 as align_1: + */ + if (reg.vstride == BRW_VERTICAL_STRIDE_8) + insn->bits2.da16.src0_vert_stride = BRW_VERTICAL_STRIDE_4; + else + insn->bits2.da16.src0_vert_stride = reg.vstride; + } + } +} + + +void brw_set_src1( struct brw_instruction *insn, + struct brw_reg reg ) +{ + assert(reg.file != BRW_MESSAGE_REGISTER_FILE); + + assert(reg.nr < 128); + + insn->bits1.da1.src1_reg_file = reg.file; + insn->bits1.da1.src1_reg_type = reg.type; + insn->bits3.da1.src1_abs = reg.abs; + insn->bits3.da1.src1_negate = reg.negate; + + /* Only src1 can be immediate in two-argument instructions. + */ + assert(insn->bits1.da1.src0_reg_file != BRW_IMMEDIATE_VALUE); + + if (reg.file == BRW_IMMEDIATE_VALUE) { + insn->bits3.ud = reg.dw1.ud; + } + else { + /* This is a hardware restriction, which may or may not be lifted + * in the future: + */ + assert (reg.address_mode == BRW_ADDRESS_DIRECT); + /*assert (reg.file == BRW_GENERAL_REGISTER_FILE); */ + + if (insn->header.access_mode == BRW_ALIGN_1) { + insn->bits3.da1.src1_subreg_nr = reg.subnr; + insn->bits3.da1.src1_reg_nr = reg.nr; + } + else { + insn->bits3.da16.src1_subreg_nr = reg.subnr / 16; + insn->bits3.da16.src1_reg_nr = reg.nr; + } + + if (insn->header.access_mode == BRW_ALIGN_1) { + if (reg.width == BRW_WIDTH_1 && + insn->header.execution_size == BRW_EXECUTE_1) { + insn->bits3.da1.src1_horiz_stride = BRW_HORIZONTAL_STRIDE_0; + insn->bits3.da1.src1_width = BRW_WIDTH_1; + insn->bits3.da1.src1_vert_stride = BRW_VERTICAL_STRIDE_0; + } + else { + insn->bits3.da1.src1_horiz_stride = reg.hstride; + insn->bits3.da1.src1_width = reg.width; + insn->bits3.da1.src1_vert_stride = reg.vstride; + } + } + else { + insn->bits3.da16.src1_swz_x = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_X); + insn->bits3.da16.src1_swz_y = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_Y); + insn->bits3.da16.src1_swz_z = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_Z); + insn->bits3.da16.src1_swz_w = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_W); + + /* This is an oddity of the fact we're using the same + * descriptions for registers in align_16 as align_1: + */ + if (reg.vstride == BRW_VERTICAL_STRIDE_8) + insn->bits3.da16.src1_vert_stride = BRW_VERTICAL_STRIDE_4; + else + insn->bits3.da16.src1_vert_stride = reg.vstride; + } + } +} + + + +static void brw_set_math_message( struct brw_context *brw, + struct brw_instruction *insn, + GLuint msg_length, + GLuint response_length, + GLuint function, + GLuint integer_type, + GLboolean low_precision, + GLboolean saturate, + GLuint dataType ) +{ + brw_set_src1(insn, brw_imm_d(0)); + + if (BRW_IS_IGDNG(brw)) { + insn->bits3.math_igdng.function = function; + insn->bits3.math_igdng.int_type = integer_type; + insn->bits3.math_igdng.precision = low_precision; + insn->bits3.math_igdng.saturate = saturate; + insn->bits3.math_igdng.data_type = dataType; + insn->bits3.math_igdng.snapshot = 0; + insn->bits3.math_igdng.header_present = 0; + insn->bits3.math_igdng.response_length = response_length; + insn->bits3.math_igdng.msg_length = msg_length; + insn->bits3.math_igdng.end_of_thread = 0; + insn->bits2.send_igdng.sfid = BRW_MESSAGE_TARGET_MATH; + insn->bits2.send_igdng.end_of_thread = 0; + } else { + insn->bits3.math.function = function; + insn->bits3.math.int_type = integer_type; + insn->bits3.math.precision = low_precision; + insn->bits3.math.saturate = saturate; + insn->bits3.math.data_type = dataType; + insn->bits3.math.response_length = response_length; + insn->bits3.math.msg_length = msg_length; + insn->bits3.math.msg_target = BRW_MESSAGE_TARGET_MATH; + insn->bits3.math.end_of_thread = 0; + } +} + + +static void brw_set_ff_sync_message( struct brw_context *brw, + struct brw_instruction *insn, + GLboolean allocate, + GLboolean used, + GLuint msg_length, + GLuint response_length, + GLboolean end_of_thread, + GLboolean complete, + GLuint offset, + GLuint swizzle_control ) +{ + brw_set_src1(insn, brw_imm_d(0)); + + insn->bits3.urb_igdng.opcode = 1; + insn->bits3.urb_igdng.offset = offset; + insn->bits3.urb_igdng.swizzle_control = swizzle_control; + insn->bits3.urb_igdng.allocate = allocate; + insn->bits3.urb_igdng.used = used; + insn->bits3.urb_igdng.complete = complete; + insn->bits3.urb_igdng.header_present = 1; + insn->bits3.urb_igdng.response_length = response_length; + insn->bits3.urb_igdng.msg_length = msg_length; + insn->bits3.urb_igdng.end_of_thread = end_of_thread; + insn->bits2.send_igdng.sfid = BRW_MESSAGE_TARGET_URB; + insn->bits2.send_igdng.end_of_thread = end_of_thread; +} + +static void brw_set_urb_message( struct brw_context *brw, + struct brw_instruction *insn, + GLboolean allocate, + GLboolean used, + GLuint msg_length, + GLuint response_length, + GLboolean end_of_thread, + GLboolean complete, + GLuint offset, + GLuint swizzle_control ) +{ + brw_set_src1(insn, brw_imm_d(0)); + + if (BRW_IS_IGDNG(brw)) { + insn->bits3.urb_igdng.opcode = 0; /* ? */ + insn->bits3.urb_igdng.offset = offset; + insn->bits3.urb_igdng.swizzle_control = swizzle_control; + insn->bits3.urb_igdng.allocate = allocate; + insn->bits3.urb_igdng.used = used; /* ? */ + insn->bits3.urb_igdng.complete = complete; + insn->bits3.urb_igdng.header_present = 1; + insn->bits3.urb_igdng.response_length = response_length; + insn->bits3.urb_igdng.msg_length = msg_length; + insn->bits3.urb_igdng.end_of_thread = end_of_thread; + insn->bits2.send_igdng.sfid = BRW_MESSAGE_TARGET_URB; + insn->bits2.send_igdng.end_of_thread = end_of_thread; + } else { + insn->bits3.urb.opcode = 0; /* ? */ + insn->bits3.urb.offset = offset; + insn->bits3.urb.swizzle_control = swizzle_control; + insn->bits3.urb.allocate = allocate; + insn->bits3.urb.used = used; /* ? */ + insn->bits3.urb.complete = complete; + insn->bits3.urb.response_length = response_length; + insn->bits3.urb.msg_length = msg_length; + insn->bits3.urb.msg_target = BRW_MESSAGE_TARGET_URB; + insn->bits3.urb.end_of_thread = end_of_thread; + } +} + +static void brw_set_dp_write_message( struct brw_context *brw, + struct brw_instruction *insn, + GLuint binding_table_index, + GLuint msg_control, + GLuint msg_type, + GLuint msg_length, + GLuint pixel_scoreboard_clear, + GLuint response_length, + GLuint end_of_thread ) +{ + brw_set_src1(insn, brw_imm_d(0)); + + if (BRW_IS_IGDNG(brw)) { + insn->bits3.dp_write_igdng.binding_table_index = binding_table_index; + insn->bits3.dp_write_igdng.msg_control = msg_control; + insn->bits3.dp_write_igdng.pixel_scoreboard_clear = pixel_scoreboard_clear; + insn->bits3.dp_write_igdng.msg_type = msg_type; + insn->bits3.dp_write_igdng.send_commit_msg = 0; + insn->bits3.dp_write_igdng.header_present = 1; + insn->bits3.dp_write_igdng.response_length = response_length; + insn->bits3.dp_write_igdng.msg_length = msg_length; + insn->bits3.dp_write_igdng.end_of_thread = end_of_thread; + insn->bits2.send_igdng.sfid = BRW_MESSAGE_TARGET_DATAPORT_WRITE; + insn->bits2.send_igdng.end_of_thread = end_of_thread; + } else { + insn->bits3.dp_write.binding_table_index = binding_table_index; + insn->bits3.dp_write.msg_control = msg_control; + insn->bits3.dp_write.pixel_scoreboard_clear = pixel_scoreboard_clear; + insn->bits3.dp_write.msg_type = msg_type; + insn->bits3.dp_write.send_commit_msg = 0; + insn->bits3.dp_write.response_length = response_length; + insn->bits3.dp_write.msg_length = msg_length; + insn->bits3.dp_write.msg_target = BRW_MESSAGE_TARGET_DATAPORT_WRITE; + insn->bits3.dp_write.end_of_thread = end_of_thread; + } +} + +static void brw_set_dp_read_message( struct brw_context *brw, + struct brw_instruction *insn, + GLuint binding_table_index, + GLuint msg_control, + GLuint msg_type, + GLuint target_cache, + GLuint msg_length, + GLuint response_length, + GLuint end_of_thread ) +{ + brw_set_src1(insn, brw_imm_d(0)); + + if (BRW_IS_IGDNG(brw)) { + insn->bits3.dp_read_igdng.binding_table_index = binding_table_index; + insn->bits3.dp_read_igdng.msg_control = msg_control; + insn->bits3.dp_read_igdng.msg_type = msg_type; + insn->bits3.dp_read_igdng.target_cache = target_cache; + insn->bits3.dp_read_igdng.header_present = 1; + insn->bits3.dp_read_igdng.response_length = response_length; + insn->bits3.dp_read_igdng.msg_length = msg_length; + insn->bits3.dp_read_igdng.pad1 = 0; + insn->bits3.dp_read_igdng.end_of_thread = end_of_thread; + insn->bits2.send_igdng.sfid = BRW_MESSAGE_TARGET_DATAPORT_READ; + insn->bits2.send_igdng.end_of_thread = end_of_thread; + } else { + insn->bits3.dp_read.binding_table_index = binding_table_index; /*0:7*/ + insn->bits3.dp_read.msg_control = msg_control; /*8:11*/ + insn->bits3.dp_read.msg_type = msg_type; /*12:13*/ + insn->bits3.dp_read.target_cache = target_cache; /*14:15*/ + insn->bits3.dp_read.response_length = response_length; /*16:19*/ + insn->bits3.dp_read.msg_length = msg_length; /*20:23*/ + insn->bits3.dp_read.msg_target = BRW_MESSAGE_TARGET_DATAPORT_READ; /*24:27*/ + insn->bits3.dp_read.pad1 = 0; /*28:30*/ + insn->bits3.dp_read.end_of_thread = end_of_thread; /*31*/ + } +} + +static void brw_set_sampler_message(struct brw_context *brw, + struct brw_instruction *insn, + GLuint binding_table_index, + GLuint sampler, + GLuint msg_type, + GLuint response_length, + GLuint msg_length, + GLboolean eot, + GLuint header_present, + GLuint simd_mode) +{ + assert(eot == 0); + brw_set_src1(insn, brw_imm_d(0)); + + if (BRW_IS_IGDNG(brw)) { + insn->bits3.sampler_igdng.binding_table_index = binding_table_index; + insn->bits3.sampler_igdng.sampler = sampler; + insn->bits3.sampler_igdng.msg_type = msg_type; + insn->bits3.sampler_igdng.simd_mode = simd_mode; + insn->bits3.sampler_igdng.header_present = header_present; + insn->bits3.sampler_igdng.response_length = response_length; + insn->bits3.sampler_igdng.msg_length = msg_length; + insn->bits3.sampler_igdng.end_of_thread = eot; + insn->bits2.send_igdng.sfid = BRW_MESSAGE_TARGET_SAMPLER; + insn->bits2.send_igdng.end_of_thread = eot; + } else if (BRW_IS_G4X(brw)) { + insn->bits3.sampler_g4x.binding_table_index = binding_table_index; + insn->bits3.sampler_g4x.sampler = sampler; + insn->bits3.sampler_g4x.msg_type = msg_type; + insn->bits3.sampler_g4x.response_length = response_length; + insn->bits3.sampler_g4x.msg_length = msg_length; + insn->bits3.sampler_g4x.end_of_thread = eot; + insn->bits3.sampler_g4x.msg_target = BRW_MESSAGE_TARGET_SAMPLER; + } else { + insn->bits3.sampler.binding_table_index = binding_table_index; + insn->bits3.sampler.sampler = sampler; + insn->bits3.sampler.msg_type = msg_type; + insn->bits3.sampler.return_format = BRW_SAMPLER_RETURN_FORMAT_FLOAT32; + insn->bits3.sampler.response_length = response_length; + insn->bits3.sampler.msg_length = msg_length; + insn->bits3.sampler.end_of_thread = eot; + insn->bits3.sampler.msg_target = BRW_MESSAGE_TARGET_SAMPLER; + } +} + + + +static struct brw_instruction *next_insn( struct brw_compile *p, + GLuint opcode ) +{ + struct brw_instruction *insn; + + if (0 && (BRW_DEBUG & DEBUG_DISASSEM)) + { + if (p->nr_insn) + brw_disasm_insn(stderr, &p->store[p->nr_insn-1]); + } + + assert(p->nr_insn + 1 < BRW_EU_MAX_INSN); + + insn = &p->store[p->nr_insn++]; + memcpy(insn, p->current, sizeof(*insn)); + + /* Reset this one-shot flag: + */ + + if (p->current->header.destreg__conditionalmod) { + p->current->header.destreg__conditionalmod = 0; + p->current->header.predicate_control = BRW_PREDICATE_NORMAL; + } + + insn->header.opcode = opcode; + return insn; +} + + +static struct brw_instruction *brw_alu1( struct brw_compile *p, + GLuint opcode, + struct brw_reg dest, + struct brw_reg src ) +{ + struct brw_instruction *insn = next_insn(p, opcode); + brw_set_dest(insn, dest); + brw_set_src0(insn, src); + return insn; +} + +static struct brw_instruction *brw_alu2(struct brw_compile *p, + GLuint opcode, + struct brw_reg dest, + struct brw_reg src0, + struct brw_reg src1 ) +{ + struct brw_instruction *insn = next_insn(p, opcode); + brw_set_dest(insn, dest); + brw_set_src0(insn, src0); + brw_set_src1(insn, src1); + return insn; +} + + +/*********************************************************************** + * Convenience routines. + */ +#define ALU1(OP) \ +struct brw_instruction *brw_##OP(struct brw_compile *p, \ + struct brw_reg dest, \ + struct brw_reg src0) \ +{ \ + return brw_alu1(p, BRW_OPCODE_##OP, dest, src0); \ +} + +#define ALU2(OP) \ +struct brw_instruction *brw_##OP(struct brw_compile *p, \ + struct brw_reg dest, \ + struct brw_reg src0, \ + struct brw_reg src1) \ +{ \ + return brw_alu2(p, BRW_OPCODE_##OP, dest, src0, src1); \ +} + + +ALU1(MOV) +ALU2(SEL) +ALU1(NOT) +ALU2(AND) +ALU2(OR) +ALU2(XOR) +ALU2(SHR) +ALU2(SHL) +ALU2(RSR) +ALU2(RSL) +ALU2(ASR) +ALU2(ADD) +ALU2(MUL) +ALU1(FRC) +ALU1(RNDD) +ALU1(RNDZ) +ALU2(MAC) +ALU2(MACH) +ALU1(LZD) +ALU2(DP4) +ALU2(DPH) +ALU2(DP3) +ALU2(DP2) +ALU2(LINE) + + + + +void brw_NOP(struct brw_compile *p) +{ + struct brw_instruction *insn = next_insn(p, BRW_OPCODE_NOP); + brw_set_dest(insn, retype(brw_vec4_grf(0,0), BRW_REGISTER_TYPE_UD)); + brw_set_src0(insn, retype(brw_vec4_grf(0,0), BRW_REGISTER_TYPE_UD)); + brw_set_src1(insn, brw_imm_ud(0x0)); +} + + + + + +/*********************************************************************** + * Comparisons, if/else/endif + */ + +struct brw_instruction *brw_JMPI(struct brw_compile *p, + struct brw_reg dest, + struct brw_reg src0, + struct brw_reg src1) +{ + struct brw_instruction *insn = brw_alu2(p, BRW_OPCODE_JMPI, dest, src0, src1); + + insn->header.execution_size = 1; + insn->header.compression_control = BRW_COMPRESSION_NONE; + insn->header.mask_control = BRW_MASK_DISABLE; + + p->current->header.predicate_control = BRW_PREDICATE_NONE; + + return insn; +} + +/* EU takes the value from the flag register and pushes it onto some + * sort of a stack (presumably merging with any flag value already on + * the stack). Within an if block, the flags at the top of the stack + * control execution on each channel of the unit, eg. on each of the + * 16 pixel values in our wm programs. + * + * When the matching 'else' instruction is reached (presumably by + * countdown of the instruction count patched in by our ELSE/ENDIF + * functions), the relevent flags are inverted. + * + * When the matching 'endif' instruction is reached, the flags are + * popped off. If the stack is now empty, normal execution resumes. + * + * No attempt is made to deal with stack overflow (14 elements?). + */ +struct brw_instruction *brw_IF(struct brw_compile *p, GLuint execute_size) +{ + struct brw_instruction *insn; + + if (p->single_program_flow) { + assert(execute_size == BRW_EXECUTE_1); + + insn = next_insn(p, BRW_OPCODE_ADD); + insn->header.predicate_inverse = 1; + } else { + insn = next_insn(p, BRW_OPCODE_IF); + } + + /* Override the defaults for this instruction: + */ + brw_set_dest(insn, brw_ip_reg()); + brw_set_src0(insn, brw_ip_reg()); + brw_set_src1(insn, brw_imm_d(0x0)); + + insn->header.execution_size = execute_size; + insn->header.compression_control = BRW_COMPRESSION_NONE; + insn->header.predicate_control = BRW_PREDICATE_NORMAL; + insn->header.mask_control = BRW_MASK_ENABLE; + if (!p->single_program_flow) + insn->header.thread_control = BRW_THREAD_SWITCH; + + p->current->header.predicate_control = BRW_PREDICATE_NONE; + + return insn; +} + + +struct brw_instruction *brw_ELSE(struct brw_compile *p, + struct brw_instruction *if_insn) +{ + struct brw_instruction *insn; + GLuint br = 1; + + if (BRW_IS_IGDNG(p->brw)) + br = 2; + + if (p->single_program_flow) { + insn = next_insn(p, BRW_OPCODE_ADD); + } else { + insn = next_insn(p, BRW_OPCODE_ELSE); + } + + brw_set_dest(insn, brw_ip_reg()); + brw_set_src0(insn, brw_ip_reg()); + brw_set_src1(insn, brw_imm_d(0x0)); + + insn->header.compression_control = BRW_COMPRESSION_NONE; + insn->header.execution_size = if_insn->header.execution_size; + insn->header.mask_control = BRW_MASK_ENABLE; + if (!p->single_program_flow) + insn->header.thread_control = BRW_THREAD_SWITCH; + + /* Patch the if instruction to point at this instruction. + */ + if (p->single_program_flow) { + assert(if_insn->header.opcode == BRW_OPCODE_ADD); + + if_insn->bits3.ud = (insn - if_insn + 1) * 16; + } else { + assert(if_insn->header.opcode == BRW_OPCODE_IF); + + if_insn->bits3.if_else.jump_count = br * (insn - if_insn); + if_insn->bits3.if_else.pop_count = 0; + if_insn->bits3.if_else.pad0 = 0; + } + + return insn; +} + +void brw_ENDIF(struct brw_compile *p, + struct brw_instruction *patch_insn) +{ + GLuint br = 1; + + if (BRW_IS_IGDNG(p->brw)) + br = 2; + + if (p->single_program_flow) { + /* In single program flow mode, there's no need to execute an ENDIF, + * since we don't need to do any stack operations, and if we're executing + * currently, we want to just continue executing. + */ + struct brw_instruction *next = &p->store[p->nr_insn]; + + assert(patch_insn->header.opcode == BRW_OPCODE_ADD); + + patch_insn->bits3.ud = (next - patch_insn) * 16; + } else { + struct brw_instruction *insn = next_insn(p, BRW_OPCODE_ENDIF); + + brw_set_dest(insn, retype(brw_vec4_grf(0,0), BRW_REGISTER_TYPE_UD)); + brw_set_src0(insn, retype(brw_vec4_grf(0,0), BRW_REGISTER_TYPE_UD)); + brw_set_src1(insn, brw_imm_d(0x0)); + + insn->header.compression_control = BRW_COMPRESSION_NONE; + insn->header.execution_size = patch_insn->header.execution_size; + insn->header.mask_control = BRW_MASK_ENABLE; + insn->header.thread_control = BRW_THREAD_SWITCH; + + assert(patch_insn->bits3.if_else.jump_count == 0); + + /* Patch the if or else instructions to point at this or the next + * instruction respectively. + */ + if (patch_insn->header.opcode == BRW_OPCODE_IF) { + /* Automagically turn it into an IFF: + */ + patch_insn->header.opcode = BRW_OPCODE_IFF; + patch_insn->bits3.if_else.jump_count = br * (insn - patch_insn + 1); + patch_insn->bits3.if_else.pop_count = 0; + patch_insn->bits3.if_else.pad0 = 0; + } else if (patch_insn->header.opcode == BRW_OPCODE_ELSE) { + patch_insn->bits3.if_else.jump_count = br * (insn - patch_insn + 1); + patch_insn->bits3.if_else.pop_count = 1; + patch_insn->bits3.if_else.pad0 = 0; + } else { + assert(0); + } + + /* Also pop item off the stack in the endif instruction: + */ + insn->bits3.if_else.jump_count = 0; + insn->bits3.if_else.pop_count = 1; + insn->bits3.if_else.pad0 = 0; + } +} + +struct brw_instruction *brw_BREAK(struct brw_compile *p) +{ + struct brw_instruction *insn; + insn = next_insn(p, BRW_OPCODE_BREAK); + brw_set_dest(insn, brw_ip_reg()); + brw_set_src0(insn, brw_ip_reg()); + brw_set_src1(insn, brw_imm_d(0x0)); + insn->header.compression_control = BRW_COMPRESSION_NONE; + insn->header.execution_size = BRW_EXECUTE_8; + /* insn->header.mask_control = BRW_MASK_DISABLE; */ + insn->bits3.if_else.pad0 = 0; + return insn; +} + +struct brw_instruction *brw_CONT(struct brw_compile *p) +{ + struct brw_instruction *insn; + insn = next_insn(p, BRW_OPCODE_CONTINUE); + brw_set_dest(insn, brw_ip_reg()); + brw_set_src0(insn, brw_ip_reg()); + brw_set_src1(insn, brw_imm_d(0x0)); + insn->header.compression_control = BRW_COMPRESSION_NONE; + insn->header.execution_size = BRW_EXECUTE_8; + /* insn->header.mask_control = BRW_MASK_DISABLE; */ + insn->bits3.if_else.pad0 = 0; + return insn; +} + +/* DO/WHILE loop: + */ +struct brw_instruction *brw_DO(struct brw_compile *p, GLuint execute_size) +{ + if (p->single_program_flow) { + return &p->store[p->nr_insn]; + } else { + struct brw_instruction *insn = next_insn(p, BRW_OPCODE_DO); + + /* Override the defaults for this instruction: + */ + brw_set_dest(insn, brw_null_reg()); + brw_set_src0(insn, brw_null_reg()); + brw_set_src1(insn, brw_null_reg()); + + insn->header.compression_control = BRW_COMPRESSION_NONE; + insn->header.execution_size = execute_size; + insn->header.predicate_control = BRW_PREDICATE_NONE; + /* insn->header.mask_control = BRW_MASK_ENABLE; */ + /* insn->header.mask_control = BRW_MASK_DISABLE; */ + + return insn; + } +} + + + +struct brw_instruction *brw_WHILE(struct brw_compile *p, + struct brw_instruction *do_insn) +{ + struct brw_instruction *insn; + GLuint br = 1; + + if (BRW_IS_IGDNG(p->brw)) + br = 2; + + if (p->single_program_flow) + insn = next_insn(p, BRW_OPCODE_ADD); + else + insn = next_insn(p, BRW_OPCODE_WHILE); + + brw_set_dest(insn, brw_ip_reg()); + brw_set_src0(insn, brw_ip_reg()); + brw_set_src1(insn, brw_imm_d(0x0)); + + insn->header.compression_control = BRW_COMPRESSION_NONE; + + if (p->single_program_flow) { + insn->header.execution_size = BRW_EXECUTE_1; + + insn->bits3.d = (do_insn - insn) * 16; + } else { + insn->header.execution_size = do_insn->header.execution_size; + + assert(do_insn->header.opcode == BRW_OPCODE_DO); + insn->bits3.if_else.jump_count = br * (do_insn - insn + 1); + insn->bits3.if_else.pop_count = 0; + insn->bits3.if_else.pad0 = 0; + } + +/* insn->header.mask_control = BRW_MASK_ENABLE; */ + + /* insn->header.mask_control = BRW_MASK_DISABLE; */ + p->current->header.predicate_control = BRW_PREDICATE_NONE; + return insn; +} + + +/* FORWARD JUMPS: + */ +void brw_land_fwd_jump(struct brw_compile *p, + struct brw_instruction *jmp_insn) +{ + struct brw_instruction *landing = &p->store[p->nr_insn]; + GLuint jmpi = 1; + + if (BRW_IS_IGDNG(p->brw)) + jmpi = 2; + + assert(jmp_insn->header.opcode == BRW_OPCODE_JMPI); + assert(jmp_insn->bits1.da1.src1_reg_file == BRW_IMMEDIATE_VALUE); + + jmp_insn->bits3.ud = jmpi * ((landing - jmp_insn) - 1); +} + + + +/* To integrate with the above, it makes sense that the comparison + * instruction should populate the flag register. It might be simpler + * just to use the flag reg for most WM tasks? + */ +void brw_CMP(struct brw_compile *p, + struct brw_reg dest, + GLuint conditional, + struct brw_reg src0, + struct brw_reg src1) +{ + struct brw_instruction *insn = next_insn(p, BRW_OPCODE_CMP); + + insn->header.destreg__conditionalmod = conditional; + brw_set_dest(insn, dest); + brw_set_src0(insn, src0); + brw_set_src1(insn, src1); + +/* guess_execution_size(insn, src0); */ + + + /* Make it so that future instructions will use the computed flag + * value until brw_set_predicate_control_flag_value() is called + * again. + */ + if (dest.file == BRW_ARCHITECTURE_REGISTER_FILE && + dest.nr == 0) { + p->current->header.predicate_control = BRW_PREDICATE_NORMAL; + p->flag_value = 0xff; + } +} + + + +/*********************************************************************** + * Helpers for the various SEND message types: + */ + +/** Extended math function, float[8]. + */ +void brw_math( struct brw_compile *p, + struct brw_reg dest, + GLuint function, + GLuint saturate, + GLuint msg_reg_nr, + struct brw_reg src, + GLuint data_type, + GLuint precision ) +{ + struct brw_instruction *insn = next_insn(p, BRW_OPCODE_SEND); + GLuint msg_length = (function == BRW_MATH_FUNCTION_POW) ? 2 : 1; + GLuint response_length = (function == BRW_MATH_FUNCTION_SINCOS) ? 2 : 1; + + /* Example code doesn't set predicate_control for send + * instructions. + */ + insn->header.predicate_control = 0; + insn->header.destreg__conditionalmod = msg_reg_nr; + + brw_set_dest(insn, dest); + brw_set_src0(insn, src); + brw_set_math_message(p->brw, + insn, + msg_length, response_length, + function, + BRW_MATH_INTEGER_UNSIGNED, + precision, + saturate, + data_type); +} + +/** + * Extended math function, float[16]. + * Use 2 send instructions. + */ +void brw_math_16( struct brw_compile *p, + struct brw_reg dest, + GLuint function, + GLuint saturate, + GLuint msg_reg_nr, + struct brw_reg src, + GLuint precision ) +{ + struct brw_instruction *insn; + GLuint msg_length = (function == BRW_MATH_FUNCTION_POW) ? 2 : 1; + GLuint response_length = (function == BRW_MATH_FUNCTION_SINCOS) ? 2 : 1; + + /* First instruction: + */ + brw_push_insn_state(p); + brw_set_predicate_control_flag_value(p, 0xff); + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + + insn = next_insn(p, BRW_OPCODE_SEND); + insn->header.destreg__conditionalmod = msg_reg_nr; + + brw_set_dest(insn, dest); + brw_set_src0(insn, src); + brw_set_math_message(p->brw, + insn, + msg_length, response_length, + function, + BRW_MATH_INTEGER_UNSIGNED, + precision, + saturate, + BRW_MATH_DATA_VECTOR); + + /* Second instruction: + */ + insn = next_insn(p, BRW_OPCODE_SEND); + insn->header.compression_control = BRW_COMPRESSION_2NDHALF; + insn->header.destreg__conditionalmod = msg_reg_nr+1; + + brw_set_dest(insn, offset(dest,1)); + brw_set_src0(insn, src); + brw_set_math_message(p->brw, + insn, + msg_length, response_length, + function, + BRW_MATH_INTEGER_UNSIGNED, + precision, + saturate, + BRW_MATH_DATA_VECTOR); + + brw_pop_insn_state(p); +} + + +/** + * Write block of 16 dwords/floats to the data port Render Cache scratch buffer. + * Scratch offset should be a multiple of 64. + * Used for register spilling. + */ +void brw_dp_WRITE_16( struct brw_compile *p, + struct brw_reg src, + GLuint scratch_offset ) +{ + GLuint msg_reg_nr = 1; + { + brw_push_insn_state(p); + brw_set_mask_control(p, BRW_MASK_DISABLE); + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + + /* set message header global offset field (reg 0, element 2) */ + brw_MOV(p, + retype(brw_vec1_grf(0, 2), BRW_REGISTER_TYPE_D), + brw_imm_d(scratch_offset)); + + brw_pop_insn_state(p); + } + + { + GLuint msg_length = 3; + struct brw_reg dest = retype(brw_null_reg(), BRW_REGISTER_TYPE_UW); + struct brw_instruction *insn = next_insn(p, BRW_OPCODE_SEND); + + insn->header.predicate_control = 0; /* XXX */ + insn->header.compression_control = BRW_COMPRESSION_NONE; + insn->header.destreg__conditionalmod = msg_reg_nr; + + brw_set_dest(insn, dest); + brw_set_src0(insn, src); + + brw_set_dp_write_message(p->brw, + insn, + 255, /* binding table index (255=stateless) */ + BRW_DATAPORT_OWORD_BLOCK_4_OWORDS, /* msg_control */ + BRW_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE, /* msg_type */ + msg_length, + 0, /* pixel scoreboard */ + 0, /* response_length */ + 0); /* eot */ + } +} + + +/** + * Read block of 16 dwords/floats from the data port Render Cache scratch buffer. + * Scratch offset should be a multiple of 64. + * Used for register spilling. + */ +void brw_dp_READ_16( struct brw_compile *p, + struct brw_reg dest, + GLuint scratch_offset ) +{ + GLuint msg_reg_nr = 1; + { + brw_push_insn_state(p); + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + brw_set_mask_control(p, BRW_MASK_DISABLE); + + /* set message header global offset field (reg 0, element 2) */ + brw_MOV(p, + retype(brw_vec1_grf(0, 2), BRW_REGISTER_TYPE_D), + brw_imm_d(scratch_offset)); + + brw_pop_insn_state(p); + } + + { + struct brw_instruction *insn = next_insn(p, BRW_OPCODE_SEND); + + insn->header.predicate_control = 0; /* XXX */ + insn->header.compression_control = BRW_COMPRESSION_NONE; + insn->header.destreg__conditionalmod = msg_reg_nr; + + brw_set_dest(insn, dest); /* UW? */ + brw_set_src0(insn, retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW)); + + brw_set_dp_read_message(p->brw, + insn, + 255, /* binding table index (255=stateless) */ + 3, /* msg_control (3 means 4 Owords) */ + BRW_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ, /* msg_type */ + 1, /* target cache (render/scratch) */ + 1, /* msg_length */ + 2, /* response_length */ + 0); /* eot */ + } +} + + +/** + * Read a float[4] vector from the data port Data Cache (const buffer). + * Location (in buffer) should be a multiple of 16. + * Used for fetching shader constants. + * If relAddr is true, we'll do an indirect fetch using the address register. + */ +void brw_dp_READ_4( struct brw_compile *p, + struct brw_reg dest, + GLboolean relAddr, + GLuint location, + GLuint bind_table_index ) +{ + /* XXX: relAddr not implemented */ + GLuint msg_reg_nr = 1; + { + struct brw_reg b; + brw_push_insn_state(p); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + brw_set_mask_control(p, BRW_MASK_DISABLE); + + /* Setup MRF[1] with location/offset into const buffer */ + b = brw_message_reg(msg_reg_nr); + b = retype(b, BRW_REGISTER_TYPE_UD); + /* XXX I think we're setting all the dwords of MRF[1] to 'location'. + * when the docs say only dword[2] should be set. Hmmm. But it works. + */ + brw_MOV(p, b, brw_imm_ud(location)); + brw_pop_insn_state(p); + } + + { + struct brw_instruction *insn = next_insn(p, BRW_OPCODE_SEND); + + insn->header.predicate_control = BRW_PREDICATE_NONE; + insn->header.compression_control = BRW_COMPRESSION_NONE; + insn->header.destreg__conditionalmod = msg_reg_nr; + insn->header.mask_control = BRW_MASK_DISABLE; + + /* cast dest to a uword[8] vector */ + dest = retype(vec8(dest), BRW_REGISTER_TYPE_UW); + + brw_set_dest(insn, dest); + brw_set_src0(insn, brw_null_reg()); + + brw_set_dp_read_message(p->brw, + insn, + bind_table_index, + 0, /* msg_control (0 means 1 Oword) */ + BRW_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ, /* msg_type */ + 0, /* source cache = data cache */ + 1, /* msg_length */ + 1, /* response_length (1 Oword) */ + 0); /* eot */ + } +} + + +/** + * Read float[4] constant(s) from VS constant buffer. + * For relative addressing, two float[4] constants will be read into 'dest'. + * Otherwise, one float[4] constant will be read into the lower half of 'dest'. + */ +void brw_dp_READ_4_vs(struct brw_compile *p, + struct brw_reg dest, + GLuint oword, + GLboolean relAddr, + struct brw_reg addrReg, + GLuint location, + GLuint bind_table_index) +{ + GLuint msg_reg_nr = 1; + + assert(oword < 2); + /* + printf("vs const read msg, location %u, msg_reg_nr %d\n", + location, msg_reg_nr); + */ + + /* Setup MRF[1] with location/offset into const buffer */ + { + struct brw_reg b; + + brw_push_insn_state(p); + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + brw_set_mask_control(p, BRW_MASK_DISABLE); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + /*brw_set_access_mode(p, BRW_ALIGN_16);*/ + + /* XXX I think we're setting all the dwords of MRF[1] to 'location'. + * when the docs say only dword[2] should be set. Hmmm. But it works. + */ + b = brw_message_reg(msg_reg_nr); + b = retype(b, BRW_REGISTER_TYPE_UD); + /*b = get_element_ud(b, 2);*/ + if (relAddr) { + brw_ADD(p, b, addrReg, brw_imm_ud(location)); + } + else { + brw_MOV(p, b, brw_imm_ud(location)); + } + + brw_pop_insn_state(p); + } + + { + struct brw_instruction *insn = next_insn(p, BRW_OPCODE_SEND); + + insn->header.predicate_control = BRW_PREDICATE_NONE; + insn->header.compression_control = BRW_COMPRESSION_NONE; + insn->header.destreg__conditionalmod = msg_reg_nr; + insn->header.mask_control = BRW_MASK_DISABLE; + /*insn->header.access_mode = BRW_ALIGN_16;*/ + + brw_set_dest(insn, dest); + brw_set_src0(insn, brw_null_reg()); + + brw_set_dp_read_message(p->brw, + insn, + bind_table_index, + oword, /* 0 = lower Oword, 1 = upper Oword */ + BRW_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ, /* msg_type */ + 0, /* source cache = data cache */ + 1, /* msg_length */ + 1, /* response_length (1 Oword) */ + 0); /* eot */ + } +} + + + +void brw_fb_WRITE(struct brw_compile *p, + struct brw_reg dest, + GLuint msg_reg_nr, + struct brw_reg src0, + GLuint binding_table_index, + GLuint msg_length, + GLuint response_length, + GLboolean eot) +{ + struct brw_instruction *insn = next_insn(p, BRW_OPCODE_SEND); + + insn->header.predicate_control = 0; /* XXX */ + insn->header.compression_control = BRW_COMPRESSION_NONE; + insn->header.destreg__conditionalmod = msg_reg_nr; + + brw_set_dest(insn, dest); + brw_set_src0(insn, src0); + brw_set_dp_write_message(p->brw, + insn, + binding_table_index, + BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE, /* msg_control */ + BRW_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE, /* msg_type */ + msg_length, + 1, /* pixel scoreboard */ + response_length, + eot); +} + + +/** + * Texture sample instruction. + * Note: the msg_type plus msg_length values determine exactly what kind + * of sampling operation is performed. See volume 4, page 161 of docs. + */ +void brw_SAMPLE(struct brw_compile *p, + struct brw_reg dest, + GLuint msg_reg_nr, + struct brw_reg src0, + GLuint binding_table_index, + GLuint sampler, + GLuint writemask, + GLuint msg_type, + GLuint response_length, + GLuint msg_length, + GLboolean eot, + GLuint header_present, + GLuint simd_mode) +{ + GLboolean need_stall = 0; + + if (writemask == 0) { + /*debug_printf("%s: zero writemask??\n", __FUNCTION__); */ + return; + } + + /* Hardware doesn't do destination dependency checking on send + * instructions properly. Add a workaround which generates the + * dependency by other means. In practice it seems like this bug + * only crops up for texture samples, and only where registers are + * written by the send and then written again later without being + * read in between. Luckily for us, we already track that + * information and use it to modify the writemask for the + * instruction, so that is a guide for whether a workaround is + * needed. + */ + if (writemask != BRW_WRITEMASK_XYZW) { + GLuint dst_offset = 0; + GLuint i, newmask = 0, len = 0; + + for (i = 0; i < 4; i++) { + if (writemask & (1<header.predicate_control = 0; /* XXX */ + insn->header.compression_control = BRW_COMPRESSION_NONE; + insn->header.destreg__conditionalmod = msg_reg_nr; + + brw_set_dest(insn, dest); + brw_set_src0(insn, src0); + brw_set_sampler_message(p->brw, insn, + binding_table_index, + sampler, + msg_type, + response_length, + msg_length, + eot, + header_present, + simd_mode); + } + + if (need_stall) { + struct brw_reg reg = vec8(offset(dest, response_length-1)); + + /* mov (8) r9.0<1>:f r9.0<8;8,1>:f { Align1 } + */ + brw_push_insn_state(p); + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + brw_MOV(p, reg, reg); + brw_pop_insn_state(p); + } + +} + +/* All these variables are pretty confusing - we might be better off + * using bitmasks and macros for this, in the old style. Or perhaps + * just having the caller instantiate the fields in dword3 itself. + */ +void brw_urb_WRITE(struct brw_compile *p, + struct brw_reg dest, + GLuint msg_reg_nr, + struct brw_reg src0, + GLboolean allocate, + GLboolean used, + GLuint msg_length, + GLuint response_length, + GLboolean eot, + GLboolean writes_complete, + GLuint offset, + GLuint swizzle) +{ + struct brw_instruction *insn = next_insn(p, BRW_OPCODE_SEND); + + assert(msg_length < BRW_MAX_MRF); + + brw_set_dest(insn, dest); + brw_set_src0(insn, src0); + brw_set_src1(insn, brw_imm_d(0)); + + insn->header.destreg__conditionalmod = msg_reg_nr; + + brw_set_urb_message(p->brw, + insn, + allocate, + used, + msg_length, + response_length, + eot, + writes_complete, + offset, + swizzle); +} + +void brw_ff_sync(struct brw_compile *p, + struct brw_reg dest, + GLuint msg_reg_nr, + struct brw_reg src0, + GLboolean allocate, + GLboolean used, + GLuint msg_length, + GLuint response_length, + GLboolean eot, + GLboolean writes_complete, + GLuint offset, + GLuint swizzle) +{ + struct brw_instruction *insn = next_insn(p, BRW_OPCODE_SEND); + + assert(msg_length < 16); + + brw_set_dest(insn, dest); + brw_set_src0(insn, src0); + brw_set_src1(insn, brw_imm_d(0)); + + insn->header.destreg__conditionalmod = msg_reg_nr; + + brw_set_ff_sync_message(p->brw, + insn, + allocate, + used, + msg_length, + response_length, + eot, + writes_complete, + offset, + swizzle); +} diff --git a/src/gallium/drivers/i965/brw_eu_util.c b/src/gallium/drivers/i965/brw_eu_util.c new file mode 100644 index 0000000..5405cf1 --- /dev/null +++ b/src/gallium/drivers/i965/brw_eu_util.c @@ -0,0 +1,126 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#include "brw_context.h" +#include "brw_defines.h" +#include "brw_eu.h" + + +void brw_math_invert( struct brw_compile *p, + struct brw_reg dst, + struct brw_reg src) +{ + brw_math( p, + dst, + BRW_MATH_FUNCTION_INV, + BRW_MATH_SATURATE_NONE, + 0, + src, + BRW_MATH_PRECISION_FULL, + BRW_MATH_DATA_VECTOR ); +} + + + +void brw_copy4(struct brw_compile *p, + struct brw_reg dst, + struct brw_reg src, + GLuint count) +{ + GLuint i; + + dst = vec4(dst); + src = vec4(src); + + for (i = 0; i < count; i++) + { + GLuint delta = i*32; + brw_MOV(p, byte_offset(dst, delta), byte_offset(src, delta)); + brw_MOV(p, byte_offset(dst, delta+16), byte_offset(src, delta+16)); + } +} + + +void brw_copy8(struct brw_compile *p, + struct brw_reg dst, + struct brw_reg src, + GLuint count) +{ + GLuint i; + + dst = vec8(dst); + src = vec8(src); + + for (i = 0; i < count; i++) + { + GLuint delta = i*32; + brw_MOV(p, byte_offset(dst, delta), byte_offset(src, delta)); + } +} + + +void brw_copy_indirect_to_indirect(struct brw_compile *p, + struct brw_indirect dst_ptr, + struct brw_indirect src_ptr, + GLuint count) +{ + GLuint i; + + for (i = 0; i < count; i++) + { + GLuint delta = i*32; + brw_MOV(p, deref_4f(dst_ptr, delta), deref_4f(src_ptr, delta)); + brw_MOV(p, deref_4f(dst_ptr, delta+16), deref_4f(src_ptr, delta+16)); + } +} + + +void brw_copy_from_indirect(struct brw_compile *p, + struct brw_reg dst, + struct brw_indirect ptr, + GLuint count) +{ + GLuint i; + + dst = vec4(dst); + + for (i = 0; i < count; i++) + { + GLuint delta = i*32; + brw_MOV(p, byte_offset(dst, delta), deref_4f(ptr, delta)); + brw_MOV(p, byte_offset(dst, delta+16), deref_4f(ptr, delta+16)); + } +} + + + + diff --git a/src/gallium/drivers/i965/brw_gs.c b/src/gallium/drivers/i965/brw_gs.c new file mode 100644 index 0000000..0682663 --- /dev/null +++ b/src/gallium/drivers/i965/brw_gs.c @@ -0,0 +1,215 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "brw_batchbuffer.h" + +#include "brw_defines.h" +#include "brw_context.h" +#include "brw_eu.h" +#include "brw_state.h" +#include "brw_gs.h" + + + +static enum pipe_error compile_gs_prog( struct brw_context *brw, + struct brw_gs_prog_key *key, + struct brw_winsys_buffer **bo_out ) +{ + struct brw_gs_compile c; + enum pipe_error ret; + const GLuint *program; + GLuint program_size; + + memset(&c, 0, sizeof(c)); + + c.key = *key; + c.need_ff_sync = BRW_IS_IGDNG(brw); + /* Need to locate the two positions present in vertex + header. + * These are currently hardcoded: + */ + c.nr_attrs = c.key.nr_attrs; + + if (BRW_IS_IGDNG(brw)) + c.nr_regs = (c.nr_attrs + 1) / 2 + 3; /* are vertices packed, or reg-aligned? */ + else + c.nr_regs = (c.nr_attrs + 1) / 2 + 1; /* are vertices packed, or reg-aligned? */ + + c.nr_bytes = c.nr_regs * REG_SIZE; + + + /* Begin the compilation: + */ + brw_init_compile(brw, &c.func); + + c.func.single_program_flow = 1; + + /* For some reason the thread is spawned with only 4 channels + * unmasked. + */ + brw_set_mask_control(&c.func, BRW_MASK_DISABLE); + + + /* Note that primitives which don't require a GS program have + * already been weeded out by this stage: + */ + switch (key->primitive) { + case PIPE_PRIM_QUADS: + brw_gs_quads( &c ); + break; + case PIPE_PRIM_QUAD_STRIP: + brw_gs_quad_strip( &c ); + break; + case PIPE_PRIM_LINE_LOOP: + brw_gs_lines( &c ); + break; + case PIPE_PRIM_LINES: + if (key->hint_gs_always) + brw_gs_lines( &c ); + else { + return PIPE_OK; + } + break; + case PIPE_PRIM_TRIANGLES: + if (key->hint_gs_always) + brw_gs_tris( &c ); + else { + return PIPE_OK; + } + break; + case PIPE_PRIM_POINTS: + if (key->hint_gs_always) + brw_gs_points( &c ); + else { + return PIPE_OK; + } + break; + default: + assert(0); + return PIPE_ERROR_BAD_INPUT; + } + + /* get the program + */ + ret = brw_get_program(&c.func, &program, &program_size); + if (ret) + return ret; + + /* Upload + */ + ret = brw_upload_cache( &brw->cache, BRW_GS_PROG, + &c.key, sizeof(c.key), + NULL, 0, + program, program_size, + &c.prog_data, + &brw->gs.prog_data, + bo_out ); + if (ret) + return ret; + + return PIPE_OK; +} + +static const unsigned gs_prim[PIPE_PRIM_MAX] = { + PIPE_PRIM_POINTS, + PIPE_PRIM_LINES, + PIPE_PRIM_LINE_LOOP, + PIPE_PRIM_LINES, + PIPE_PRIM_TRIANGLES, + PIPE_PRIM_TRIANGLES, + PIPE_PRIM_TRIANGLES, + PIPE_PRIM_QUADS, + PIPE_PRIM_QUAD_STRIP, + PIPE_PRIM_TRIANGLES +}; + +static void populate_key( struct brw_context *brw, + struct brw_gs_prog_key *key ) +{ + const struct brw_fs_signature *sig = &brw->curr.fragment_shader->signature; + + memset(key, 0, sizeof(*key)); + + /* PIPE_NEW_FRAGMENT_SIGNATURE */ + key->nr_attrs = sig->nr_inputs + 1; + + /* BRW_NEW_PRIMITIVE */ + key->primitive = gs_prim[brw->primitive]; + + key->hint_gs_always = 0; /* debug code? */ + + key->need_gs_prog = (key->hint_gs_always || + brw->primitive == PIPE_PRIM_QUADS || + brw->primitive == PIPE_PRIM_QUAD_STRIP || + brw->primitive == PIPE_PRIM_LINE_LOOP); +} + +/* Calculate interpolants for triangle and line rasterization. + */ +static int prepare_gs_prog(struct brw_context *brw) +{ + struct brw_gs_prog_key key; + enum pipe_error ret; + + /* Populate the key: + */ + populate_key(brw, &key); + + if (brw->gs.prog_active != key.need_gs_prog) { + brw->state.dirty.cache |= CACHE_NEW_GS_PROG; + brw->gs.prog_active = key.need_gs_prog; + } + + if (!brw->gs.prog_active) + return PIPE_OK; + + if (brw_search_cache(&brw->cache, BRW_GS_PROG, + &key, sizeof(key), + NULL, 0, + &brw->gs.prog_data, + &brw->gs.prog_bo)) + return PIPE_OK; + + ret = compile_gs_prog( brw, &key, &brw->gs.prog_bo ); + if (ret) + return ret; + + return PIPE_OK; +} + + +const struct brw_tracked_state brw_gs_prog = { + .dirty = { + .mesa = PIPE_NEW_FRAGMENT_SIGNATURE, + .brw = BRW_NEW_PRIMITIVE, + .cache = 0, + }, + .prepare = prepare_gs_prog +}; diff --git a/src/gallium/drivers/i965/brw_gs.h b/src/gallium/drivers/i965/brw_gs.h new file mode 100644 index 0000000..6e616dc --- /dev/null +++ b/src/gallium/drivers/i965/brw_gs.h @@ -0,0 +1,76 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#ifndef BRW_GS_H +#define BRW_GS_H + + +#include "brw_context.h" +#include "brw_eu.h" + +#define MAX_GS_VERTS (4) + +struct brw_gs_prog_key { + GLuint nr_attrs:8; + GLuint primitive:4; + GLuint hint_gs_always:1; + GLuint need_gs_prog:1; + GLuint pad:18; +}; + +struct brw_gs_compile { + struct brw_compile func; + struct brw_gs_prog_key key; + struct brw_gs_prog_data prog_data; + + struct { + struct brw_reg R0; + struct brw_reg vertex[MAX_GS_VERTS]; + } reg; + + /* 3 different ways of expressing vertex size: + */ + GLuint nr_attrs; + GLuint nr_regs; + GLuint nr_bytes; + GLboolean need_ff_sync; +}; + +#define ATTR_SIZE (4*4) + +void brw_gs_quads( struct brw_gs_compile *c ); +void brw_gs_quad_strip( struct brw_gs_compile *c ); +void brw_gs_tris( struct brw_gs_compile *c ); +void brw_gs_lines( struct brw_gs_compile *c ); +void brw_gs_points( struct brw_gs_compile *c ); + +#endif diff --git a/src/gallium/drivers/i965/brw_gs_emit.c b/src/gallium/drivers/i965/brw_gs_emit.c new file mode 100644 index 0000000..9b58773 --- /dev/null +++ b/src/gallium/drivers/i965/brw_gs_emit.c @@ -0,0 +1,180 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#include "brw_batchbuffer.h" + +#include "brw_defines.h" +#include "brw_context.h" +#include "brw_eu.h" +#include "brw_gs.h" + +static void brw_gs_alloc_regs( struct brw_gs_compile *c, + GLuint nr_verts ) +{ + GLuint i = 0,j; + + /* Register usage is static, precompute here: + */ + c->reg.R0 = retype(brw_vec8_grf(i, 0), BRW_REGISTER_TYPE_UD); i++; + + /* Payload vertices plus space for more generated vertices: + */ + for (j = 0; j < nr_verts; j++) { + c->reg.vertex[j] = brw_vec4_grf(i, 0); + i += c->nr_regs; + } + + c->prog_data.urb_read_length = c->nr_regs; + c->prog_data.total_grf = i; +} + + +static void brw_gs_emit_vue(struct brw_gs_compile *c, + struct brw_reg vert, + GLboolean last, + GLuint header) +{ + struct brw_compile *p = &c->func; + GLboolean allocate = !last; + + /* Overwrite PrimType and PrimStart in the message header, for + * each vertex in turn: + */ + brw_MOV(p, get_element_ud(c->reg.R0, 2), brw_imm_ud(header)); + + /* Copy the vertex from vertn into m1..mN+1: + */ + brw_copy8(p, brw_message_reg(1), vert, c->nr_regs); + + /* Send each vertex as a seperate write to the urb. This is + * different to the concept in brw_sf_emit.c, where subsequent + * writes are used to build up a single urb entry. Each of these + * writes instantiates a seperate urb entry, and a new one must be + * allocated each time. + */ + brw_urb_WRITE(p, + allocate ? c->reg.R0 : retype(brw_null_reg(), BRW_REGISTER_TYPE_UD), + 0, + c->reg.R0, + allocate, + 1, /* used */ + c->nr_regs + 1, /* msg length */ + allocate ? 1 : 0, /* response length */ + allocate ? 0 : 1, /* eot */ + 1, /* writes_complete */ + 0, /* urb offset */ + BRW_URB_SWIZZLE_NONE); +} + +static void brw_gs_ff_sync(struct brw_gs_compile *c, int num_prim) +{ + struct brw_compile *p = &c->func; + brw_MOV(p, get_element_ud(c->reg.R0, 1), brw_imm_ud(num_prim)); + brw_ff_sync(p, + c->reg.R0, + 0, + c->reg.R0, + 1, + 1, /* used */ + 1, /* msg length */ + 1, /* response length */ + 0, /* eot */ + 1, /* write compelete */ + 0, /* urb offset */ + BRW_URB_SWIZZLE_NONE); +} + + +void brw_gs_quads( struct brw_gs_compile *c ) +{ + brw_gs_alloc_regs(c, 4); + + /* Use polygons for correct edgeflag behaviour. Note that vertex 3 + * is the PV for quads, but vertex 0 for polygons: + */ + if (c->need_ff_sync) + brw_gs_ff_sync(c, 1); + brw_gs_emit_vue(c, c->reg.vertex[3], 0, ((_3DPRIM_POLYGON << 2) | R02_PRIM_START)); + brw_gs_emit_vue(c, c->reg.vertex[0], 0, (_3DPRIM_POLYGON << 2)); + brw_gs_emit_vue(c, c->reg.vertex[1], 0, (_3DPRIM_POLYGON << 2)); + brw_gs_emit_vue(c, c->reg.vertex[2], 1, ((_3DPRIM_POLYGON << 2) | R02_PRIM_END)); +} + +void brw_gs_quad_strip( struct brw_gs_compile *c ) +{ + brw_gs_alloc_regs(c, 4); + + if (c->need_ff_sync) + brw_gs_ff_sync(c, 1); + brw_gs_emit_vue(c, c->reg.vertex[2], 0, ((_3DPRIM_POLYGON << 2) | R02_PRIM_START)); + brw_gs_emit_vue(c, c->reg.vertex[3], 0, (_3DPRIM_POLYGON << 2)); + brw_gs_emit_vue(c, c->reg.vertex[0], 0, (_3DPRIM_POLYGON << 2)); + brw_gs_emit_vue(c, c->reg.vertex[1], 1, ((_3DPRIM_POLYGON << 2) | R02_PRIM_END)); +} + +void brw_gs_tris( struct brw_gs_compile *c ) +{ + brw_gs_alloc_regs(c, 3); + + if (c->need_ff_sync) + brw_gs_ff_sync(c, 1); + brw_gs_emit_vue(c, c->reg.vertex[0], 0, ((_3DPRIM_TRILIST << 2) | R02_PRIM_START)); + brw_gs_emit_vue(c, c->reg.vertex[1], 0, (_3DPRIM_TRILIST << 2)); + brw_gs_emit_vue(c, c->reg.vertex[2], 1, ((_3DPRIM_TRILIST << 2) | R02_PRIM_END)); +} + +void brw_gs_lines( struct brw_gs_compile *c ) +{ + brw_gs_alloc_regs(c, 2); + + if (c->need_ff_sync) + brw_gs_ff_sync(c, 1); + brw_gs_emit_vue(c, c->reg.vertex[0], 0, ((_3DPRIM_LINESTRIP << 2) | R02_PRIM_START)); + brw_gs_emit_vue(c, c->reg.vertex[1], 1, ((_3DPRIM_LINESTRIP << 2) | R02_PRIM_END)); +} + +void brw_gs_points( struct brw_gs_compile *c ) +{ + brw_gs_alloc_regs(c, 1); + + if (c->need_ff_sync) + brw_gs_ff_sync(c, 1); + brw_gs_emit_vue(c, c->reg.vertex[0], 1, ((_3DPRIM_POINTLIST << 2) | R02_PRIM_START | R02_PRIM_END)); +} + + + + + + + + diff --git a/src/gallium/drivers/i965/brw_gs_state.c b/src/gallium/drivers/i965/brw_gs_state.c new file mode 100644 index 0000000..b64ec28 --- /dev/null +++ b/src/gallium/drivers/i965/brw_gs_state.c @@ -0,0 +1,169 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_math.h" + +#include "brw_context.h" +#include "brw_state.h" +#include "brw_defines.h" +#include "brw_debug.h" + +struct brw_gs_unit_key { + unsigned int total_grf; + unsigned int urb_entry_read_length; + + unsigned int curbe_offset; + + unsigned int nr_urb_entries, urb_size; + GLboolean prog_active; +}; + +static void +gs_unit_populate_key(struct brw_context *brw, struct brw_gs_unit_key *key) +{ + memset(key, 0, sizeof(*key)); + + /* CACHE_NEW_GS_PROG */ + key->prog_active = brw->gs.prog_active; + if (key->prog_active) { + key->total_grf = brw->gs.prog_data->total_grf; + key->urb_entry_read_length = brw->gs.prog_data->urb_read_length; + } else { + key->total_grf = 1; + key->urb_entry_read_length = 1; + } + + /* BRW_NEW_CURBE_OFFSETS */ + key->curbe_offset = brw->curbe.clip_start; + + /* BRW_NEW_URB_FENCE */ + key->nr_urb_entries = brw->urb.nr_gs_entries; + key->urb_size = brw->urb.vsize; +} + +static enum pipe_error +gs_unit_create_from_key(struct brw_context *brw, + struct brw_gs_unit_key *key, + struct brw_winsys_reloc *reloc, + unsigned nr_reloc, + struct brw_winsys_buffer **bo_out) +{ + struct brw_gs_unit_state gs; + enum pipe_error ret; + + + memset(&gs, 0, sizeof(gs)); + + /* reloc */ + gs.thread0.grf_reg_count = align(key->total_grf, 16) / 16 - 1; + gs.thread0.kernel_start_pointer = 0; + + gs.thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754; + gs.thread1.single_program_flow = 1; + + gs.thread3.dispatch_grf_start_reg = 1; + gs.thread3.const_urb_entry_read_offset = 0; + gs.thread3.const_urb_entry_read_length = 0; + gs.thread3.urb_entry_read_offset = 0; + gs.thread3.urb_entry_read_length = key->urb_entry_read_length; + + gs.thread4.nr_urb_entries = key->nr_urb_entries; + gs.thread4.urb_entry_allocation_size = key->urb_size - 1; + + if (key->nr_urb_entries >= 8) + gs.thread4.max_threads = 1; + else + gs.thread4.max_threads = 0; + + if (BRW_IS_IGDNG(brw)) + gs.thread4.rendering_enable = 1; + + if (BRW_DEBUG & DEBUG_STATS) + gs.thread4.stats_enable = 1; + + ret = brw_upload_cache(&brw->cache, BRW_GS_UNIT, + key, sizeof(*key), + reloc, nr_reloc, + &gs, sizeof(gs), + NULL, NULL, + bo_out); + if (ret) + return ret; + + return PIPE_OK; +} + +static enum pipe_error prepare_gs_unit(struct brw_context *brw) +{ + struct brw_gs_unit_key key; + enum pipe_error ret; + struct brw_winsys_reloc reloc[1]; + unsigned nr_reloc = 0; + unsigned grf_reg_count; + + gs_unit_populate_key(brw, &key); + + grf_reg_count = (align(key.total_grf, 16) / 16 - 1); + + /* GS program relocation */ + if (key.prog_active) { + make_reloc(&reloc[nr_reloc++], + BRW_USAGE_STATE, + grf_reg_count << 1, + offsetof(struct brw_gs_unit_state, thread0), + brw->gs.prog_bo); + } + + if (brw_search_cache(&brw->cache, BRW_GS_UNIT, + &key, sizeof(key), + reloc, nr_reloc, + NULL, + &brw->gs.state_bo)) + return PIPE_OK; + + ret = gs_unit_create_from_key(brw, &key, + reloc, nr_reloc, + &brw->gs.state_bo); + if (ret) + return ret; + + return PIPE_OK; +} + +const struct brw_tracked_state brw_gs_unit = { + .dirty = { + .mesa = 0, + .brw = (BRW_NEW_CURBE_OFFSETS | + BRW_NEW_URB_FENCE), + .cache = CACHE_NEW_GS_PROG + }, + .prepare = prepare_gs_unit, +}; diff --git a/src/gallium/drivers/i965/brw_misc_state.c b/src/gallium/drivers/i965/brw_misc_state.c new file mode 100644 index 0000000..6d89b5d --- /dev/null +++ b/src/gallium/drivers/i965/brw_misc_state.c @@ -0,0 +1,514 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + + +#include "brw_debug.h" +#include "brw_batchbuffer.h" +#include "brw_context.h" +#include "brw_state.h" +#include "brw_defines.h" +#include "brw_screen.h" +#include "brw_pipe_rast.h" + + + + + +/*********************************************************************** + * Blend color + */ + +static int upload_blend_constant_color(struct brw_context *brw) +{ + BRW_CACHED_BATCH_STRUCT(brw, &brw->curr.bcc); + return 0; +} + + +const struct brw_tracked_state brw_blend_constant_color = { + .dirty = { + .mesa = PIPE_NEW_BLEND_COLOR, + .brw = 0, + .cache = 0 + }, + .emit = upload_blend_constant_color +}; + +/*********************************************************************** + * Drawing rectangle - framebuffer dimensions + */ +static int upload_drawing_rect(struct brw_context *brw) +{ + BEGIN_BATCH(4, NO_LOOP_CLIPRECTS); + OUT_BATCH(_3DSTATE_DRAWRECT_INFO_I965); + OUT_BATCH(0); + OUT_BATCH(((brw->curr.fb.width - 1) & 0xffff) | + ((brw->curr.fb.height - 1) << 16)); + OUT_BATCH(0); + ADVANCE_BATCH(); + return 0; +} + +const struct brw_tracked_state brw_drawing_rect = { + .dirty = { + .mesa = PIPE_NEW_FRAMEBUFFER_DIMENSIONS, + .brw = 0, + .cache = 0 + }, + .emit = upload_drawing_rect +}; + + +/*********************************************************************** + * Binding table pointers + */ + +static int prepare_binding_table_pointers(struct brw_context *brw) +{ + brw_add_validated_bo(brw, brw->vs.bind_bo); + brw_add_validated_bo(brw, brw->wm.bind_bo); + return 0; +} + +/** + * Upload the binding table pointers, which point each stage's array of surface + * state pointers. + * + * The binding table pointers are relative to the surface state base address, + * which is 0. + */ +static int upload_binding_table_pointers(struct brw_context *brw) +{ + BEGIN_BATCH(6, IGNORE_CLIPRECTS); + OUT_BATCH(CMD_BINDING_TABLE_PTRS << 16 | (6 - 2)); + if (brw->vs.bind_bo != NULL) + OUT_RELOC(brw->vs.bind_bo, + BRW_USAGE_SAMPLER, + 0); /* vs */ + else + OUT_BATCH(0); + OUT_BATCH(0); /* gs */ + OUT_BATCH(0); /* clip */ + OUT_BATCH(0); /* sf */ + OUT_RELOC(brw->wm.bind_bo, + BRW_USAGE_SAMPLER, + 0); /* wm/ps */ + ADVANCE_BATCH(); + return 0; +} + +const struct brw_tracked_state brw_binding_table_pointers = { + .dirty = { + .mesa = 0, + .brw = BRW_NEW_BATCH, + .cache = CACHE_NEW_SURF_BIND, + }, + .prepare = prepare_binding_table_pointers, + .emit = upload_binding_table_pointers, +}; + + +/********************************************************************** + * Upload pointers to the per-stage state. + * + * The state pointers in this packet are all relative to the general state + * base address set by CMD_STATE_BASE_ADDRESS, which is 0. + */ +static int upload_pipelined_state_pointers(struct brw_context *brw ) +{ + BEGIN_BATCH(7, IGNORE_CLIPRECTS); + OUT_BATCH(CMD_PIPELINED_STATE_POINTERS << 16 | (7 - 2)); + OUT_RELOC(brw->vs.state_bo, + BRW_USAGE_STATE, + 0); + if (brw->gs.prog_active) + OUT_RELOC(brw->gs.state_bo, + BRW_USAGE_STATE, + 1); + else + OUT_BATCH(0); + OUT_RELOC(brw->clip.state_bo, + BRW_USAGE_STATE, + 1); + OUT_RELOC(brw->sf.state_bo, + BRW_USAGE_STATE, + 0); + OUT_RELOC(brw->wm.state_bo, + BRW_USAGE_STATE, + 0); + OUT_RELOC(brw->cc.state_bo, + BRW_USAGE_STATE, + 0); + ADVANCE_BATCH(); + + brw->state.dirty.brw |= BRW_NEW_PSP; + return 0; +} + + +static int prepare_psp_urb_cbs(struct brw_context *brw) +{ + brw_add_validated_bo(brw, brw->vs.state_bo); + brw_add_validated_bo(brw, brw->gs.state_bo); + brw_add_validated_bo(brw, brw->clip.state_bo); + brw_add_validated_bo(brw, brw->sf.state_bo); + brw_add_validated_bo(brw, brw->wm.state_bo); + brw_add_validated_bo(brw, brw->cc.state_bo); + return 0; +} + +static int upload_psp_urb_cbs(struct brw_context *brw ) +{ + int ret; + + ret = upload_pipelined_state_pointers(brw); + if (ret) + return ret; + + ret = brw_upload_urb_fence(brw); + if (ret) + return ret; + + ret = brw_upload_cs_urb_state(brw); + if (ret) + return ret; + + return 0; +} + +const struct brw_tracked_state brw_psp_urb_cbs = { + .dirty = { + .mesa = 0, + .brw = BRW_NEW_URB_FENCE | BRW_NEW_BATCH, + .cache = (CACHE_NEW_VS_UNIT | + CACHE_NEW_GS_UNIT | + CACHE_NEW_GS_PROG | + CACHE_NEW_CLIP_UNIT | + CACHE_NEW_SF_UNIT | + CACHE_NEW_WM_UNIT | + CACHE_NEW_CC_UNIT) + }, + .prepare = prepare_psp_urb_cbs, + .emit = upload_psp_urb_cbs, +}; + + +/*********************************************************************** + * Depth buffer + */ + +static int prepare_depthbuffer(struct brw_context *brw) +{ + struct pipe_surface *zsbuf = brw->curr.fb.zsbuf; + + if (zsbuf) + brw_add_validated_bo(brw, brw_surface(zsbuf)->bo); + + return 0; +} + +static int emit_depthbuffer(struct brw_context *brw) +{ + struct pipe_surface *surface = brw->curr.fb.zsbuf; + unsigned int len = (BRW_IS_G4X(brw) || BRW_IS_IGDNG(brw)) ? 6 : 5; + + if (surface == NULL) { + BEGIN_BATCH(len, IGNORE_CLIPRECTS); + OUT_BATCH(CMD_DEPTH_BUFFER << 16 | (len - 2)); + OUT_BATCH((BRW_DEPTHFORMAT_D32_FLOAT << 18) | + (BRW_SURFACE_NULL << 29)); + OUT_BATCH(0); + OUT_BATCH(0); + OUT_BATCH(0); + + if (BRW_IS_G4X(brw) || BRW_IS_IGDNG(brw)) + OUT_BATCH(0); + + ADVANCE_BATCH(); + } else { + struct brw_winsys_buffer *bo; + unsigned int format; + unsigned int pitch; + unsigned int cpp; + + switch (surface->format) { + case PIPE_FORMAT_Z16_UNORM: + format = BRW_DEPTHFORMAT_D16_UNORM; + cpp = 2; + break; + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + format = BRW_DEPTHFORMAT_D24_UNORM_S8_UINT; + cpp = 4; + break; + case PIPE_FORMAT_Z32_FLOAT: + format = BRW_DEPTHFORMAT_D32_FLOAT; + cpp = 4; + break; + default: + assert(0); + return PIPE_ERROR_BAD_INPUT; + } + + bo = brw_surface(surface)->bo; + pitch = brw_surface(surface)->pitch; + + BEGIN_BATCH(len, IGNORE_CLIPRECTS); + OUT_BATCH(CMD_DEPTH_BUFFER << 16 | (len - 2)); + OUT_BATCH(((pitch * cpp) - 1) | + (format << 18) | + (BRW_TILEWALK_YMAJOR << 26) | + /* always linear ? + ((surface->layout != PIPE_SURFACE_LAYOUT_LINEAR) << 27) |*/ + (BRW_SURFACE_2D << 29)); + OUT_RELOC(bo, + BRW_USAGE_DEPTH_BUFFER, + brw_surface(surface)->offset); + OUT_BATCH((BRW_SURFACE_MIPMAPLAYOUT_BELOW << 1) | + ((pitch - 1) << 6) | + ((surface->height - 1) << 19)); + OUT_BATCH(0); + + if (BRW_IS_G4X(brw) || BRW_IS_IGDNG(brw)) + OUT_BATCH(0); + + ADVANCE_BATCH(); + } + + return 0; +} + +const struct brw_tracked_state brw_depthbuffer = { + .dirty = { + .mesa = PIPE_NEW_DEPTH_BUFFER, + .brw = BRW_NEW_BATCH, + .cache = 0, + }, + .prepare = prepare_depthbuffer, + .emit = emit_depthbuffer, +}; + + + +/*********************************************************************** + * Polygon stipple packet + */ + +static int upload_polygon_stipple(struct brw_context *brw) +{ + BRW_CACHED_BATCH_STRUCT(brw, &brw->curr.bps); + return 0; +} + +const struct brw_tracked_state brw_polygon_stipple = { + .dirty = { + .mesa = PIPE_NEW_POLYGON_STIPPLE, + .brw = 0, + .cache = 0 + }, + .emit = upload_polygon_stipple +}; + + +/*********************************************************************** + * Line stipple packet + */ + +static int upload_line_stipple(struct brw_context *brw) +{ + const struct brw_line_stipple *bls = &brw->curr.rast->bls; + if (bls->header.opcode) { + BRW_CACHED_BATCH_STRUCT(brw, bls); + } + return 0; +} + +const struct brw_tracked_state brw_line_stipple = { + .dirty = { + .mesa = PIPE_NEW_RAST, + .brw = 0, + .cache = 0 + }, + .emit = upload_line_stipple +}; + + +/*********************************************************************** + * Misc invarient state packets + */ + +static int upload_invarient_state( struct brw_context *brw ) +{ + { + /* 0x61040000 Pipeline Select */ + /* PipelineSelect : 0 */ + struct brw_pipeline_select ps; + + memset(&ps, 0, sizeof(ps)); + if (BRW_IS_G4X(brw) || BRW_IS_IGDNG(brw)) + ps.header.opcode = CMD_PIPELINE_SELECT_GM45; + else + ps.header.opcode = CMD_PIPELINE_SELECT_965; + ps.header.pipeline_select = 0; + BRW_BATCH_STRUCT(brw, &ps); + } + + { + struct brw_global_depth_offset_clamp gdo; + memset(&gdo, 0, sizeof(gdo)); + + /* Disable depth offset clamping. + */ + gdo.header.opcode = CMD_GLOBAL_DEPTH_OFFSET_CLAMP; + gdo.header.length = sizeof(gdo)/4 - 2; + gdo.depth_offset_clamp = 0.0; + + BRW_BATCH_STRUCT(brw, &gdo); + } + + + /* 0x61020000 State Instruction Pointer */ + { + struct brw_system_instruction_pointer sip; + memset(&sip, 0, sizeof(sip)); + + sip.header.opcode = CMD_STATE_INSN_POINTER; + sip.header.length = 0; + sip.bits0.pad = 0; + sip.bits0.system_instruction_pointer = 0; + BRW_BATCH_STRUCT(brw, &sip); + } + + /* VF Statistics */ + { + struct brw_vf_statistics vfs; + memset(&vfs, 0, sizeof(vfs)); + + if (BRW_IS_G4X(brw) || BRW_IS_IGDNG(brw)) + vfs.opcode = CMD_VF_STATISTICS_GM45; + else + vfs.opcode = CMD_VF_STATISTICS_965; + + if (BRW_DEBUG & DEBUG_STATS) + vfs.statistics_enable = 1; + + BRW_BATCH_STRUCT(brw, &vfs); + } + + if (!BRW_IS_965(brw)) + { + struct brw_aa_line_parameters balp; + + /* use legacy aa line coverage computation */ + memset(&balp, 0, sizeof(balp)); + balp.header.opcode = CMD_AA_LINE_PARAMETERS; + balp.header.length = sizeof(balp) / 4 - 2; + + BRW_BATCH_STRUCT(brw, &balp); + } + + { + struct brw_polygon_stipple_offset bpso; + + /* This is invarient state in gallium: + */ + memset(&bpso, 0, sizeof(bpso)); + bpso.header.opcode = CMD_POLY_STIPPLE_OFFSET; + bpso.header.length = sizeof(bpso)/4-2; + bpso.bits0.y_offset = 0; + bpso.bits0.x_offset = 0; + + BRW_BATCH_STRUCT(brw, &bpso); + } + + return 0; +} + +const struct brw_tracked_state brw_invarient_state = { + .dirty = { + .mesa = 0, + .brw = BRW_NEW_CONTEXT, + .cache = 0 + }, + .emit = upload_invarient_state +}; + + +/*********************************************************************** + * State base address + */ + +/** + * Define the base addresses which some state is referenced from. + * + * This allows us to avoid having to emit relocations in many places for + * cached state, and instead emit pointers inside of large, mostly-static + * state pools. This comes at the expense of memory, and more expensive cache + * misses. + */ +static int upload_state_base_address( struct brw_context *brw ) +{ + /* Output the structure (brw_state_base_address) directly to the + * batchbuffer, so we can emit relocations inline. + */ + if (BRW_IS_IGDNG(brw)) { + BEGIN_BATCH(8, IGNORE_CLIPRECTS); + OUT_BATCH(CMD_STATE_BASE_ADDRESS << 16 | (8 - 2)); + OUT_BATCH(1); /* General state base address */ + OUT_BATCH(1); /* Surface state base address */ + OUT_BATCH(1); /* Indirect object base address */ + OUT_BATCH(1); /* Instruction base address */ + OUT_BATCH(1); /* General state upper bound */ + OUT_BATCH(1); /* Indirect object upper bound */ + OUT_BATCH(1); /* Instruction access upper bound */ + ADVANCE_BATCH(); + } else { + BEGIN_BATCH(6, IGNORE_CLIPRECTS); + OUT_BATCH(CMD_STATE_BASE_ADDRESS << 16 | (6 - 2)); + OUT_BATCH(1); /* General state base address */ + OUT_BATCH(1); /* Surface state base address */ + OUT_BATCH(1); /* Indirect object base address */ + OUT_BATCH(1); /* General state upper bound */ + OUT_BATCH(1); /* Indirect object upper bound */ + ADVANCE_BATCH(); + } + return 0; +} + +const struct brw_tracked_state brw_state_base_address = { + .dirty = { + .mesa = 0, + .brw = BRW_NEW_CONTEXT, + .cache = 0, + }, + .emit = upload_state_base_address +}; diff --git a/src/gallium/drivers/i965/brw_pipe_blend.c b/src/gallium/drivers/i965/brw_pipe_blend.c new file mode 100644 index 0000000..21f786f --- /dev/null +++ b/src/gallium/drivers/i965/brw_pipe_blend.c @@ -0,0 +1,208 @@ + +#include "util/u_memory.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" + +#include "brw_context.h" +#include "brw_defines.h" +#include "brw_debug.h" + +static int translate_logicop(unsigned logicop) +{ + switch (logicop) { + case PIPE_LOGICOP_CLEAR: + return BRW_LOGICOPFUNCTION_CLEAR; + case PIPE_LOGICOP_AND: + return BRW_LOGICOPFUNCTION_AND; + case PIPE_LOGICOP_AND_REVERSE: + return BRW_LOGICOPFUNCTION_AND_REVERSE; + case PIPE_LOGICOP_COPY: + return BRW_LOGICOPFUNCTION_COPY; + case PIPE_LOGICOP_COPY_INVERTED: + return BRW_LOGICOPFUNCTION_COPY_INVERTED; + case PIPE_LOGICOP_AND_INVERTED: + return BRW_LOGICOPFUNCTION_AND_INVERTED; + case PIPE_LOGICOP_NOOP: + return BRW_LOGICOPFUNCTION_NOOP; + case PIPE_LOGICOP_XOR: + return BRW_LOGICOPFUNCTION_XOR; + case PIPE_LOGICOP_OR: + return BRW_LOGICOPFUNCTION_OR; + case PIPE_LOGICOP_OR_INVERTED: + return BRW_LOGICOPFUNCTION_OR_INVERTED; + case PIPE_LOGICOP_NOR: + return BRW_LOGICOPFUNCTION_NOR; + case PIPE_LOGICOP_EQUIV: + return BRW_LOGICOPFUNCTION_EQUIV; + case PIPE_LOGICOP_INVERT: + return BRW_LOGICOPFUNCTION_INVERT; + case PIPE_LOGICOP_OR_REVERSE: + return BRW_LOGICOPFUNCTION_OR_REVERSE; + case PIPE_LOGICOP_NAND: + return BRW_LOGICOPFUNCTION_NAND; + case PIPE_LOGICOP_SET: + return BRW_LOGICOPFUNCTION_SET; + default: + assert(0); + return BRW_LOGICOPFUNCTION_SET; + } +} + + +static unsigned translate_blend_equation( unsigned mode ) +{ + switch (mode) { + case PIPE_BLEND_ADD: + return BRW_BLENDFUNCTION_ADD; + case PIPE_BLEND_MIN: + return BRW_BLENDFUNCTION_MIN; + case PIPE_BLEND_MAX: + return BRW_BLENDFUNCTION_MAX; + case PIPE_BLEND_SUBTRACT: + return BRW_BLENDFUNCTION_SUBTRACT; + case PIPE_BLEND_REVERSE_SUBTRACT: + return BRW_BLENDFUNCTION_REVERSE_SUBTRACT; + default: + assert(0); + return BRW_BLENDFUNCTION_ADD; + } +} + +static unsigned translate_blend_factor( unsigned factor ) +{ + switch(factor) { + case PIPE_BLENDFACTOR_ZERO: + return BRW_BLENDFACTOR_ZERO; + case PIPE_BLENDFACTOR_SRC_ALPHA: + return BRW_BLENDFACTOR_SRC_ALPHA; + case PIPE_BLENDFACTOR_ONE: + return BRW_BLENDFACTOR_ONE; + case PIPE_BLENDFACTOR_SRC_COLOR: + return BRW_BLENDFACTOR_SRC_COLOR; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + return BRW_BLENDFACTOR_INV_SRC_COLOR; + case PIPE_BLENDFACTOR_DST_COLOR: + return BRW_BLENDFACTOR_DST_COLOR; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + return BRW_BLENDFACTOR_INV_DST_COLOR; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + return BRW_BLENDFACTOR_INV_SRC_ALPHA; + case PIPE_BLENDFACTOR_DST_ALPHA: + return BRW_BLENDFACTOR_DST_ALPHA; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + return BRW_BLENDFACTOR_INV_DST_ALPHA; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + return BRW_BLENDFACTOR_SRC_ALPHA_SATURATE; + case PIPE_BLENDFACTOR_CONST_COLOR: + return BRW_BLENDFACTOR_CONST_COLOR; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + return BRW_BLENDFACTOR_INV_CONST_COLOR; + case PIPE_BLENDFACTOR_CONST_ALPHA: + return BRW_BLENDFACTOR_CONST_ALPHA; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + return BRW_BLENDFACTOR_INV_CONST_ALPHA; + default: + assert(0); + return BRW_BLENDFACTOR_ZERO; + } +} + +static void *brw_create_blend_state( struct pipe_context *pipe, + const struct pipe_blend_state *templ ) +{ + struct brw_blend_state *blend = CALLOC_STRUCT(brw_blend_state); + if (blend == NULL) + return NULL; + + if (templ->logicop_enable) { + blend->cc2.logicop_enable = 1; + blend->cc5.logicop_func = translate_logicop(templ->logicop_func); + } + else if (templ->rt[0].blend_enable) { + blend->cc6.dest_blend_factor = translate_blend_factor(templ->rt[0].rgb_dst_factor); + blend->cc6.src_blend_factor = translate_blend_factor(templ->rt[0].rgb_src_factor); + blend->cc6.blend_function = translate_blend_equation(templ->rt[0].rgb_func); + + blend->cc5.ia_dest_blend_factor = translate_blend_factor(templ->rt[0].alpha_dst_factor); + blend->cc5.ia_src_blend_factor = translate_blend_factor(templ->rt[0].alpha_src_factor); + blend->cc5.ia_blend_function = translate_blend_equation(templ->rt[0].alpha_func); + + blend->cc3.blend_enable = 1; + blend->cc3.ia_blend_enable = + (blend->cc6.dest_blend_factor != blend->cc5.ia_dest_blend_factor || + blend->cc6.src_blend_factor != blend->cc5.ia_src_blend_factor || + blend->cc6.blend_function != blend->cc5.ia_blend_function); + + /* Per-surface blend enables, currently just follow global + * state: + */ + blend->ss0.color_blend = 1; + } + + blend->cc5.dither_enable = templ->dither; + + if (BRW_DEBUG & DEBUG_STATS) + blend->cc5.statistics_enable = 1; + + /* Per-surface color mask -- just follow global state: + */ + blend->ss0.writedisable_red = (templ->rt[0].colormask & PIPE_MASK_R) ? 0 : 1; + blend->ss0.writedisable_green = (templ->rt[0].colormask & PIPE_MASK_G) ? 0 : 1; + blend->ss0.writedisable_blue = (templ->rt[0].colormask & PIPE_MASK_B) ? 0 : 1; + blend->ss0.writedisable_alpha = (templ->rt[0].colormask & PIPE_MASK_A) ? 0 : 1; + + return (void *)blend; +} + +static void brw_bind_blend_state(struct pipe_context *pipe, + void *cso) +{ + struct brw_context *brw = brw_context(pipe); + brw->curr.blend = (const struct brw_blend_state *)cso; + brw->state.dirty.mesa |= PIPE_NEW_BLEND; +} + +static void brw_delete_blend_state(struct pipe_context *pipe, + void *cso) +{ + struct brw_context *brw = brw_context(pipe); + assert((const void *)cso != (const void *)brw->curr.blend); + FREE(cso); +} + + +static void brw_set_blend_color(struct pipe_context *pipe, + const struct pipe_blend_color *blend_color) +{ + struct brw_context *brw = brw_context(pipe); + struct brw_blend_constant_color *bcc = &brw->curr.bcc; + + bcc->blend_constant_color[0] = blend_color->color[0]; + bcc->blend_constant_color[1] = blend_color->color[1]; + bcc->blend_constant_color[2] = blend_color->color[2]; + bcc->blend_constant_color[3] = blend_color->color[3]; + + brw->state.dirty.mesa |= PIPE_NEW_BLEND_COLOR; +} + + +void brw_pipe_blend_init( struct brw_context *brw ) +{ + brw->base.set_blend_color = brw_set_blend_color; + brw->base.create_blend_state = brw_create_blend_state; + brw->base.bind_blend_state = brw_bind_blend_state; + brw->base.delete_blend_state = brw_delete_blend_state; + + { + struct brw_blend_constant_color *bcc = &brw->curr.bcc; + + memset(bcc, 0, sizeof(*bcc)); + bcc->header.opcode = CMD_BLEND_CONSTANT_COLOR; + bcc->header.length = sizeof(*bcc)/4-2; + } + +} + +void brw_pipe_blend_cleanup( struct brw_context *brw ) +{ +} diff --git a/src/gallium/drivers/i965/brw_pipe_clear.c b/src/gallium/drivers/i965/brw_pipe_clear.c new file mode 100644 index 0000000..7bf3ea6 --- /dev/null +++ b/src/gallium/drivers/i965/brw_pipe_clear.c @@ -0,0 +1,270 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + +#include "util/u_pack_color.h" +#include "util/u_math.h" + +#include "pipe/p_state.h" + +#include "brw_batchbuffer.h" +#include "brw_screen.h" +#include "brw_context.h" + +#define MASK16 0xffff +#define MASK24 0xffffff + + +/** + * Use blitting to clear the renderbuffers named by 'flags'. + * Note: we can't use the ctx->DrawBuffer->_ColorDrawBufferIndexes field + * since that might include software renderbuffers or renderbuffers + * which we're clearing with triangles. + */ +static enum pipe_error +try_clear( struct brw_context *brw, + struct brw_surface *surface, + unsigned value, + unsigned rgba_mask) +{ + uint32_t BR13, CMD; + int x1 = 0; + int y1 = 0; + int x2 = surface->base.width; + int y2 = surface->base.height; + int pitch = surface->pitch; + int cpp = surface->cpp; + + if (x2 == 0 || y2 == 0) + return 0; + + debug_printf("%s dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n", + __FUNCTION__, + (void *)surface->bo, pitch * cpp, + surface->offset, + x1, y1, x2 - x1, y2 - y1); + + BR13 = 0xf0 << 16; + CMD = XY_COLOR_BLT_CMD | rgba_mask; + + /* Setup the blit command */ + if (cpp == 4) { + BR13 |= BR13_8888; + } + else { + assert(cpp == 2); + BR13 |= BR13_565; + } + + /* XXX: nasty hack for clearing depth buffers + */ + if (surface->tiling == BRW_TILING_Y) { + x2 = pitch; + } + + if (surface->tiling == BRW_TILING_X) { + CMD |= XY_DST_TILED; + pitch /= 4; + } + + BR13 |= (pitch * cpp); + + BEGIN_BATCH(6, 0); + OUT_BATCH(CMD); + OUT_BATCH(BR13); + OUT_BATCH((y1 << 16) | x1); + OUT_BATCH((y2 << 16) | x2); + OUT_RELOC(surface->bo, + BRW_USAGE_BLIT_DEST, + surface->offset); + OUT_BATCH(value); + ADVANCE_BATCH(); + + return 0; +} + + + + +static void color_clear(struct brw_context *brw, + struct brw_surface *bsurface, + const float *rgba ) +{ + enum pipe_error ret; + union util_color value; + + util_pack_color( rgba, bsurface->base.format, &value ); + + if (bsurface->cpp == 2) + value.ui |= value.ui << 16; + + ret = try_clear( brw, bsurface, value.ui, + XY_BLT_WRITE_RGB | XY_BLT_WRITE_ALPHA ); + + if (ret != 0) { + brw_context_flush( brw ); + ret = try_clear( brw, bsurface, value.ui, + XY_BLT_WRITE_RGB | XY_BLT_WRITE_ALPHA ); + assert( ret == 0 ); + } +} + +static void zstencil_clear(struct brw_context *brw, + struct brw_surface *bsurface, + unsigned clear_flags, + double depth, + unsigned stencil ) +{ + enum pipe_error ret; + unsigned value; + unsigned mask = 0; + union fi tmp; + + if (clear_flags & PIPE_CLEAR_DEPTH) + mask |= XY_BLT_WRITE_RGB; + + switch (bsurface->base.format) { + case PIPE_FORMAT_Z32_FLOAT: + tmp.f = (float)depth; + value = tmp.ui; + break; + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + value = ((unsigned)(depth * MASK24) & MASK24); + break; + case PIPE_FORMAT_Z16_UNORM: + value = ((unsigned)(depth * MASK16) & MASK16); + break; + default: + assert(0); + return; + } + + switch (bsurface->base.format) { + case PIPE_FORMAT_Z32_FLOAT: + mask |= XY_BLT_WRITE_ALPHA; + break; + case PIPE_FORMAT_Z24X8_UNORM: + value = value | (stencil << 24); + mask |= XY_BLT_WRITE_ALPHA; + break; + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + value = value | (stencil << 24); + if (clear_flags & PIPE_CLEAR_STENCIL) + mask |= XY_BLT_WRITE_ALPHA; + break; + case PIPE_FORMAT_Z16_UNORM: + value = value | (value << 16); + mask |= XY_BLT_WRITE_ALPHA; + break; + default: + break; + } + + ret = try_clear( brw, bsurface, value, mask ); + + if (ret != 0) { + brw_context_flush( brw ); + ret = try_clear( brw, bsurface, value, mask ); + assert( ret == 0 ); + } +} + + + +/** + * Clear the given surface to the specified value. + * No masking, no scissor (clear entire buffer). + */ +static void brw_clear(struct pipe_context *pipe, + unsigned buffers, + const float *rgba, + double depth, + unsigned stencil) +{ + struct brw_context *brw = brw_context( pipe ); + int i; + + if (buffers & PIPE_CLEAR_COLOR) { + for (i = 0; i < brw->curr.fb.nr_cbufs; i++) { + color_clear( brw, + brw_surface(brw->curr.fb.cbufs[i]), + rgba ); + } + } + + if (buffers & PIPE_CLEAR_DEPTHSTENCIL) { + if (brw->curr.fb.zsbuf) { + zstencil_clear( brw, + brw_surface(brw->curr.fb.zsbuf), + buffers & PIPE_CLEAR_DEPTHSTENCIL, + depth, stencil ); + } + } +} + +/* XXX should respect region */ +static void brw_clear_render_target(struct pipe_context *pipe, + struct pipe_surface *dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct brw_context *brw = brw_context( pipe ); + + color_clear( brw, + brw_surface(dst), + rgba ); +} + +/* XXX should respect region */ +static void brw_clear_depth_stencil(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct brw_context *brw = brw_context( pipe ); + + zstencil_clear( brw, + brw_surface(dst), + clear_flags, + depth, stencil ); +} + +void brw_pipe_clear_init( struct brw_context *brw ) +{ + brw->base.clear = brw_clear; + brw->base.clear_render_target = brw_clear_render_target; + brw->base.clear_depth_stencil = brw_clear_depth_stencil; +} + + +void brw_pipe_clear_cleanup( struct brw_context *brw ) +{ +} diff --git a/src/gallium/drivers/i965/brw_pipe_depth.c b/src/gallium/drivers/i965/brw_pipe_depth.c new file mode 100644 index 0000000..31c2c34 --- /dev/null +++ b/src/gallium/drivers/i965/brw_pipe_depth.c @@ -0,0 +1,187 @@ + +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "brw_context.h" +#include "brw_defines.h" + +/* XXX: Fixme - include this to get IZ_ defines + */ +#include "brw_wm.h" + +static unsigned brw_translate_compare_func(unsigned func) +{ + switch (func) { + case PIPE_FUNC_NEVER: + return BRW_COMPAREFUNCTION_NEVER; + case PIPE_FUNC_LESS: + return BRW_COMPAREFUNCTION_LESS; + case PIPE_FUNC_LEQUAL: + return BRW_COMPAREFUNCTION_LEQUAL; + case PIPE_FUNC_GREATER: + return BRW_COMPAREFUNCTION_GREATER; + case PIPE_FUNC_GEQUAL: + return BRW_COMPAREFUNCTION_GEQUAL; + case PIPE_FUNC_NOTEQUAL: + return BRW_COMPAREFUNCTION_NOTEQUAL; + case PIPE_FUNC_EQUAL: + return BRW_COMPAREFUNCTION_EQUAL; + case PIPE_FUNC_ALWAYS: + return BRW_COMPAREFUNCTION_ALWAYS; + default: + assert(0); + return BRW_COMPAREFUNCTION_ALWAYS; + } +} + +static unsigned translate_stencil_op(unsigned op) +{ + switch (op) { + case PIPE_STENCIL_OP_KEEP: + return BRW_STENCILOP_KEEP; + case PIPE_STENCIL_OP_ZERO: + return BRW_STENCILOP_ZERO; + case PIPE_STENCIL_OP_REPLACE: + return BRW_STENCILOP_REPLACE; + case PIPE_STENCIL_OP_INCR: + return BRW_STENCILOP_INCRSAT; + case PIPE_STENCIL_OP_DECR: + return BRW_STENCILOP_DECRSAT; + case PIPE_STENCIL_OP_INCR_WRAP: + return BRW_STENCILOP_INCR; + case PIPE_STENCIL_OP_DECR_WRAP: + return BRW_STENCILOP_DECR; + case PIPE_STENCIL_OP_INVERT: + return BRW_STENCILOP_INVERT; + default: + assert(0); + return BRW_STENCILOP_ZERO; + } +} + +static void create_bcc_state( struct brw_depth_stencil_state *zstencil, + const struct pipe_depth_stencil_alpha_state *templ ) +{ + if (templ->stencil[0].enabled) { + zstencil->cc0.stencil_enable = 1; + zstencil->cc0.stencil_func = + brw_translate_compare_func(templ->stencil[0].func); + zstencil->cc0.stencil_fail_op = + translate_stencil_op(templ->stencil[0].fail_op); + zstencil->cc0.stencil_pass_depth_fail_op = + translate_stencil_op(templ->stencil[0].zfail_op); + zstencil->cc0.stencil_pass_depth_pass_op = + translate_stencil_op(templ->stencil[0].zpass_op); + zstencil->cc1.stencil_write_mask = templ->stencil[0].writemask; + zstencil->cc1.stencil_test_mask = templ->stencil[0].valuemask; + + if (templ->stencil[1].enabled) { + zstencil->cc0.bf_stencil_enable = 1; + zstencil->cc0.bf_stencil_func = + brw_translate_compare_func(templ->stencil[1].func); + zstencil->cc0.bf_stencil_fail_op = + translate_stencil_op(templ->stencil[1].fail_op); + zstencil->cc0.bf_stencil_pass_depth_fail_op = + translate_stencil_op(templ->stencil[1].zfail_op); + zstencil->cc0.bf_stencil_pass_depth_pass_op = + translate_stencil_op(templ->stencil[1].zpass_op); + zstencil->cc2.bf_stencil_write_mask = templ->stencil[1].writemask; + zstencil->cc2.bf_stencil_test_mask = templ->stencil[1].valuemask; + } + + zstencil->cc0.stencil_write_enable = (zstencil->cc1.stencil_write_mask || + zstencil->cc2.bf_stencil_write_mask); + } + + + if (templ->alpha.enabled) { + zstencil->cc3.alpha_test = 1; + zstencil->cc3.alpha_test_func = brw_translate_compare_func(templ->alpha.func); + zstencil->cc3.alpha_test_format = BRW_ALPHATEST_FORMAT_UNORM8; + zstencil->cc7.alpha_ref.ub[0] = float_to_ubyte(templ->alpha.ref_value); + } + + if (templ->depth.enabled) { + zstencil->cc2.depth_test = 1; + zstencil->cc2.depth_test_function = brw_translate_compare_func(templ->depth.func); + zstencil->cc2.depth_write_enable = templ->depth.writemask; + } +} + +static void create_wm_iz_state( struct brw_depth_stencil_state *zstencil ) +{ + if (zstencil->cc3.alpha_test) + zstencil->iz_lookup |= IZ_PS_KILL_ALPHATEST_BIT; + + if (zstencil->cc2.depth_test) + zstencil->iz_lookup |= IZ_DEPTH_TEST_ENABLE_BIT; + + if (zstencil->cc2.depth_write_enable) + zstencil->iz_lookup |= IZ_DEPTH_WRITE_ENABLE_BIT; + + if (zstencil->cc0.stencil_enable) + zstencil->iz_lookup |= IZ_STENCIL_TEST_ENABLE_BIT; + + if (zstencil->cc0.stencil_write_enable) + zstencil->iz_lookup |= IZ_STENCIL_WRITE_ENABLE_BIT; + +} + + +static void * +brw_create_depth_stencil_state( struct pipe_context *pipe, + const struct pipe_depth_stencil_alpha_state *templ ) +{ + struct brw_depth_stencil_state *zstencil = CALLOC_STRUCT(brw_depth_stencil_state); + + create_bcc_state( zstencil, templ ); + create_wm_iz_state( zstencil ); + + return (void *)zstencil; +} + + +static void brw_bind_depth_stencil_state(struct pipe_context *pipe, + void *cso) +{ + struct brw_context *brw = brw_context(pipe); + brw->curr.zstencil = (const struct brw_depth_stencil_state *)cso; + brw->state.dirty.mesa |= PIPE_NEW_DEPTH_STENCIL_ALPHA; +} + +static void brw_delete_depth_stencil_state(struct pipe_context *pipe, + void *cso) +{ + struct brw_context *brw = brw_context(pipe); + assert((const void *)cso != (const void *)brw->curr.zstencil); + FREE(cso); +} + +static void brw_set_stencil_ref(struct pipe_context *pipe, + const struct pipe_stencil_ref *stencil_ref) +{ + struct brw_context *brw = brw_context(pipe); + brw->curr.cc1_stencil_ref.stencil_ref = stencil_ref->ref_value[0]; + brw->curr.cc1_stencil_ref.bf_stencil_ref = stencil_ref->ref_value[1]; + + brw->state.dirty.mesa |= PIPE_NEW_DEPTH_STENCIL_ALPHA; +} + +static void +brw_set_sample_mask(struct pipe_context *pipe, + unsigned sample_mask) +{ +} + +void brw_pipe_depth_stencil_init( struct brw_context *brw ) +{ + brw->base.set_stencil_ref = brw_set_stencil_ref; + brw->base.create_depth_stencil_alpha_state = brw_create_depth_stencil_state; + brw->base.bind_depth_stencil_alpha_state = brw_bind_depth_stencil_state; + brw->base.delete_depth_stencil_alpha_state = brw_delete_depth_stencil_state; + brw->base.set_sample_mask = brw_set_sample_mask; +} + +void brw_pipe_depth_stencil_cleanup( struct brw_context *brw ) +{ +} diff --git a/src/gallium/drivers/i965/brw_pipe_fb.c b/src/gallium/drivers/i965/brw_pipe_fb.c new file mode 100644 index 0000000..a90b7c7 --- /dev/null +++ b/src/gallium/drivers/i965/brw_pipe_fb.c @@ -0,0 +1,84 @@ +#include "util/u_math.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" + +#include "brw_context.h" + +/** + * called from intelDrawBuffer() + */ +static void brw_set_framebuffer_state( struct pipe_context *pipe, + const struct pipe_framebuffer_state *fb ) +{ + struct brw_context *brw = brw_context(pipe); + unsigned i; + + /* Dimensions: + */ + if (brw->curr.fb.width != fb->width || + brw->curr.fb.height != fb->height) { + brw->curr.fb.width = fb->width; + brw->curr.fb.height = fb->height; + brw->state.dirty.mesa |= PIPE_NEW_FRAMEBUFFER_DIMENSIONS; + } + + /* Z/Stencil + */ + if (brw->curr.fb.zsbuf != fb->zsbuf) { + pipe_surface_reference(&brw->curr.fb.zsbuf, fb->zsbuf); + brw->state.dirty.mesa |= PIPE_NEW_DEPTH_BUFFER; + } + + /* Color buffers: + */ + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + if (brw->curr.fb.cbufs[i] != fb->cbufs[i]) { + brw->state.dirty.mesa |= PIPE_NEW_COLOR_BUFFERS; + pipe_surface_reference(&brw->curr.fb.cbufs[i], fb->cbufs[i]); + } + } + + if (brw->curr.fb.nr_cbufs != fb->nr_cbufs) { + brw->curr.fb.nr_cbufs = MIN2(BRW_MAX_DRAW_BUFFERS, fb->nr_cbufs); + brw->state.dirty.mesa |= PIPE_NEW_NR_CBUFS; + } +} + + +static void brw_set_viewport_state( struct pipe_context *pipe, + const struct pipe_viewport_state *viewport ) +{ + struct brw_context *brw = brw_context(pipe); + + brw->curr.viewport = *viewport; + brw->curr.ccv.min_depth = viewport->scale[2] * -1.0 + viewport->translate[2]; + brw->curr.ccv.max_depth = viewport->scale[2] * 1.0 + viewport->translate[2]; + + if (0) + debug_printf("%s depth range %f .. %f\n", + __FUNCTION__, + brw->curr.ccv.min_depth, + brw->curr.ccv.max_depth); + + brw->state.dirty.mesa |= PIPE_NEW_VIEWPORT; +} + + +void brw_pipe_framebuffer_init( struct brw_context *brw ) +{ + brw->base.set_framebuffer_state = brw_set_framebuffer_state; + brw->base.set_viewport_state = brw_set_viewport_state; +} + +void brw_pipe_framebuffer_cleanup( struct brw_context *brw ) +{ + struct pipe_framebuffer_state *fb = &brw->curr.fb; + int i; + + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + pipe_surface_reference(&fb->cbufs[i], NULL); + } + + pipe_surface_reference(&fb->zsbuf, NULL); +} diff --git a/src/gallium/drivers/i965/brw_pipe_flush.c b/src/gallium/drivers/i965/brw_pipe_flush.c new file mode 100644 index 0000000..0ae1a6b --- /dev/null +++ b/src/gallium/drivers/i965/brw_pipe_flush.c @@ -0,0 +1,57 @@ + +#include "brw_context.h" +#include "brw_batchbuffer.h" + +#include "util/u_upload_mgr.h" + + + + +/* All batchbuffer flushes must go through this function. + */ +void brw_context_flush( struct brw_context *brw ) +{ + /* + * + */ + brw_emit_query_end(brw); + + /* Move to the end of the current upload buffer so that we'll force choosing + * a new buffer next time. + */ + u_upload_flush( brw->vb.upload_vertex ); + u_upload_flush( brw->vb.upload_index ); + + _brw_batchbuffer_flush( brw->batch, __FILE__, __LINE__ ); + + /* Mark all context state as needing to be re-emitted. + * This is probably not as severe as on 915, since almost all of our state + * is just in referenced buffers. + */ + brw->state.dirty.brw |= BRW_NEW_CONTEXT; + brw->state.dirty.mesa |= ~0; + brw->state.dirty.brw |= ~0; + brw->state.dirty.cache |= ~0; + + brw->curbe.need_new_bo = GL_TRUE; +} + +static void +brw_flush( struct pipe_context *pipe, + unsigned flags, + struct pipe_fence_handle **fence ) +{ + brw_context_flush( brw_context( pipe ) ); + if (fence) + *fence = NULL; +} + +void brw_pipe_flush_init( struct brw_context *brw ) +{ + brw->base.flush = brw_flush; +} + + +void brw_pipe_flush_cleanup( struct brw_context *brw ) +{ +} diff --git a/src/gallium/drivers/i965/brw_pipe_misc.c b/src/gallium/drivers/i965/brw_pipe_misc.c new file mode 100644 index 0000000..3035907 --- /dev/null +++ b/src/gallium/drivers/i965/brw_pipe_misc.c @@ -0,0 +1,54 @@ + +#include "brw_context.h" +#include "brw_structs.h" +#include "brw_defines.h" + +static void brw_set_polygon_stipple( struct pipe_context *pipe, + const struct pipe_poly_stipple *stip ) +{ + struct brw_context *brw = brw_context(pipe); + struct brw_polygon_stipple *bps = &brw->curr.bps; + GLuint i; + + memset(bps, 0, sizeof *bps); + bps->header.opcode = CMD_POLY_STIPPLE_PATTERN; + bps->header.length = sizeof *bps/4-2; + + for (i = 0; i < 32; i++) + bps->stipple[i] = stip->stipple[i]; /* don't invert */ + + brw->state.dirty.mesa |= PIPE_NEW_POLYGON_STIPPLE; +} + + +static void brw_set_scissor_state( struct pipe_context *pipe, + const struct pipe_scissor_state *scissor ) +{ + struct brw_context *brw = brw_context(pipe); + + brw->curr.scissor = *scissor; + brw->state.dirty.mesa |= PIPE_NEW_SCISSOR; +} + + +static void brw_set_clip_state( struct pipe_context *pipe, + const struct pipe_clip_state *clip ) +{ + struct brw_context *brw = brw_context(pipe); + + brw->curr.ucp = *clip; + brw->state.dirty.mesa |= PIPE_NEW_CLIP; +} + + +void brw_pipe_misc_init( struct brw_context *brw ) +{ + brw->base.set_polygon_stipple = brw_set_polygon_stipple; + brw->base.set_scissor_state = brw_set_scissor_state; + brw->base.set_clip_state = brw_set_clip_state; +} + + +void brw_pipe_misc_cleanup( struct brw_context *brw ) +{ +} diff --git a/src/gallium/drivers/i965/brw_pipe_query.c b/src/gallium/drivers/i965/brw_pipe_query.c new file mode 100644 index 0000000..0745254 --- /dev/null +++ b/src/gallium/drivers/i965/brw_pipe_query.c @@ -0,0 +1,264 @@ +/* + * Copyright © 2008 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * Eric Anholt + * + */ + +/** @file support for ARB_query_object + * + * ARB_query_object is implemented by using the PIPE_CONTROL command to stall + * execution on the completion of previous depth tests, and write the + * current PS_DEPTH_COUNT to a buffer object. + * + * We use before and after counts when drawing during a query so that + * we don't pick up other clients' query data in ours. To reduce overhead, + * a single BO is used to record the query data for all active queries at + * once. This also gives us a simple bound on how much batchbuffer space is + * required for handling queries, so that we can be sure that we won't + * have to emit a batchbuffer without getting the ending PS_DEPTH_COUNT. + */ +#include "util/u_simple_list.h" + +#include "brw_context.h" +#include "brw_state.h" +#include "brw_batchbuffer.h" +#include "brw_reg.h" + +/** Waits on the query object's BO and totals the results for this query */ +static boolean +brw_query_get_result(struct pipe_context *pipe, + struct pipe_query *q, + boolean wait, + void *vresult) +{ + struct brw_context *brw = brw_context(pipe); + struct brw_query_object *query = (struct brw_query_object *)q; + uint64_t *result = (uint64_t*)vresult; + + /* Map and count the pixels from the current query BO */ + if (query->bo) { + int i; + uint64_t *map; + + if (brw->sws->bo_is_busy(query->bo) && !wait) + return FALSE; + + map = bo_map_read(brw->sws, query->bo); + if (map == NULL) + return FALSE; + + for (i = query->first_index; i <= query->last_index; i++) { + query->result += map[i * 2 + 1] - map[i * 2]; + } + + brw->sws->bo_unmap(query->bo); + bo_reference(&query->bo, NULL); + } + + *result = query->result; + return TRUE; +} + +static struct pipe_query * +brw_query_create(struct pipe_context *pipe, unsigned type ) +{ + struct brw_query_object *query; + + switch (type) { + case PIPE_QUERY_OCCLUSION_COUNTER: + query = CALLOC_STRUCT( brw_query_object ); + if (query == NULL) + return NULL; + return (struct pipe_query *)query; + + default: + return NULL; + } +} + +static void +brw_query_destroy(struct pipe_context *pipe, struct pipe_query *q) +{ + struct brw_query_object *query = (struct brw_query_object *)q; + + bo_reference(&query->bo, NULL); + FREE(query); +} + +static void +brw_query_begin(struct pipe_context *pipe, struct pipe_query *q) +{ + struct brw_context *brw = brw_context(pipe); + struct brw_query_object *query = (struct brw_query_object *)q; + + /* Reset our driver's tracking of query state. */ + bo_reference(&query->bo, NULL); + query->result = 0; + query->first_index = -1; + query->last_index = -1; + + insert_at_head(&brw->query.active_head, query); + brw->query.stats_wm++; + brw->state.dirty.mesa |= PIPE_NEW_QUERY; +} + +static void +brw_query_end(struct pipe_context *pipe, struct pipe_query *q) +{ + struct brw_context *brw = brw_context(pipe); + struct brw_query_object *query = (struct brw_query_object *)q; + + /* Flush the batchbuffer in case it has writes to our query BO. + * Have later queries write to a new query BO so that further rendering + * doesn't delay the collection of our results. + */ + if (query->bo) { + brw_emit_query_end(brw); + brw_context_flush( brw ); + + bo_reference(&brw->query.bo, NULL); + } + + remove_from_list(query); + brw->query.stats_wm--; + brw->state.dirty.mesa |= PIPE_NEW_QUERY; +} + +/*********************************************************************** + * Internal functions and callbacks to implement queries + */ + +/** Called to set up the query BO and account for its aperture space */ +enum pipe_error +brw_prepare_query_begin(struct brw_context *brw) +{ + enum pipe_error ret; + + /* Skip if we're not doing any queries. */ + if (is_empty_list(&brw->query.active_head)) + return PIPE_OK; + + /* Get a new query BO if we're going to need it. */ + if (brw->query.bo == NULL || + brw->query.index * 2 + 1 >= 4096 / sizeof(uint64_t)) { + + ret = brw->sws->bo_alloc(brw->sws, BRW_BUFFER_TYPE_QUERY, 4096, 1, + &brw->query.bo); + if (ret) + return ret; + + brw->query.index = 0; + } + + brw_add_validated_bo(brw, brw->query.bo); + + return PIPE_OK; +} + +/** Called just before primitive drawing to get a beginning PS_DEPTH_COUNT. */ +void +brw_emit_query_begin(struct brw_context *brw) +{ + struct brw_query_object *query; + + /* Skip if we're not doing any queries, or we've emitted the start. */ + if (brw->query.active || is_empty_list(&brw->query.active_head)) + return; + + BEGIN_BATCH(4, IGNORE_CLIPRECTS); + OUT_BATCH(_3DSTATE_PIPE_CONTROL | + PIPE_CONTROL_DEPTH_STALL | + PIPE_CONTROL_WRITE_DEPTH_COUNT); + /* This object could be mapped cacheable, but we don't have an exposed + * mechanism to support that. Since it's going uncached, tell GEM that + * we're writing to it. The usual clflush should be all that's required + * to pick up the results. + */ + OUT_RELOC(brw->query.bo, + BRW_USAGE_QUERY_RESULT, + PIPE_CONTROL_GLOBAL_GTT_WRITE | + ((brw->query.index * 2) * sizeof(uint64_t))); + OUT_BATCH(0); + OUT_BATCH(0); + ADVANCE_BATCH(); + + foreach(query, &brw->query.active_head) { + if (query->bo != brw->query.bo) { + uint64_t tmp; + + /* Propogate the results from this buffer to all of the + * active queries, as the bo is going away. + */ + if (query->bo != NULL) + brw_query_get_result( &brw->base, + (struct pipe_query *)query, + FALSE, + &tmp ); + + bo_reference( &query->bo, brw->query.bo ); + query->first_index = brw->query.index; + } + query->last_index = brw->query.index; + } + brw->query.active = GL_TRUE; +} + +/** Called at batchbuffer flush to get an ending PS_DEPTH_COUNT */ +void +brw_emit_query_end(struct brw_context *brw) +{ + if (!brw->query.active) + return; + + BEGIN_BATCH(4, IGNORE_CLIPRECTS); + OUT_BATCH(_3DSTATE_PIPE_CONTROL | + PIPE_CONTROL_DEPTH_STALL | + PIPE_CONTROL_WRITE_DEPTH_COUNT); + OUT_RELOC(brw->query.bo, + BRW_USAGE_QUERY_RESULT, + PIPE_CONTROL_GLOBAL_GTT_WRITE | + ((brw->query.index * 2 + 1) * sizeof(uint64_t))); + OUT_BATCH(0); + OUT_BATCH(0); + ADVANCE_BATCH(); + + brw->query.active = GL_FALSE; + brw->query.index++; +} + +void brw_pipe_query_init( struct brw_context *brw ) +{ + brw->base.create_query = brw_query_create; + brw->base.destroy_query = brw_query_destroy; + brw->base.begin_query = brw_query_begin; + brw->base.end_query = brw_query_end; + brw->base.get_query_result = brw_query_get_result; +} + + +void brw_pipe_query_cleanup( struct brw_context *brw ) +{ + /* Unreference brw->query.bo ?? + */ +} diff --git a/src/gallium/drivers/i965/brw_pipe_rast.c b/src/gallium/drivers/i965/brw_pipe_rast.c new file mode 100644 index 0000000..4c1a6d7 --- /dev/null +++ b/src/gallium/drivers/i965/brw_pipe_rast.c @@ -0,0 +1,188 @@ + +#include "util/u_memory.h" +#include "pipe/p_defines.h" +#include "brw_context.h" +#include "brw_defines.h" +#include "brw_pipe_rast.h" +#include "brw_wm.h" + + +static unsigned translate_fill( unsigned fill ) +{ + switch (fill) { + case PIPE_POLYGON_MODE_FILL: + return CLIP_FILL; + case PIPE_POLYGON_MODE_LINE: + return CLIP_LINE; + case PIPE_POLYGON_MODE_POINT: + return CLIP_POINT; + default: + assert(0); + return CLIP_FILL; + } +} + + +/* Calculates the key for triangle-mode clipping. Non-triangle + * clipping keys use much less information and are computed on the + * fly. + */ +static void +calculate_clip_key_rast( const struct brw_context *brw, + const struct pipe_rasterizer_state *templ, + const struct brw_rasterizer_state *rast, + struct brw_clip_prog_key *key) +{ + memset(key, 0, sizeof *key); + + if (brw->chipset.is_igdng) + key->clip_mode = BRW_CLIPMODE_KERNEL_CLIP; + else + key->clip_mode = BRW_CLIPMODE_NORMAL; + + key->do_flat_shading = templ->flatshade; + + if (templ->cull_face == PIPE_FACE_FRONT_AND_BACK) { + key->clip_mode = BRW_CLIPMODE_REJECT_ALL; + return; + } + + key->fill_ccw = CLIP_CULL; + key->fill_cw = CLIP_CULL; + + if (!(templ->cull_face & PIPE_FACE_FRONT)) { + if (templ->front_ccw) + key->fill_ccw = translate_fill(templ->fill_front); + else + key->fill_cw = translate_fill(templ->fill_front); + } + + if (!(templ->cull_face & PIPE_FACE_BACK)) { + if (templ->front_ccw) + key->fill_cw = translate_fill(templ->fill_back); + else + key->fill_ccw = translate_fill(templ->fill_back); + } + + if (key->fill_cw == CLIP_LINE || + key->fill_ccw == CLIP_LINE || + key->fill_cw == CLIP_POINT || + key->fill_ccw == CLIP_POINT) { + key->do_unfilled = 1; + key->clip_mode = BRW_CLIPMODE_CLIP_NON_REJECTED; + } + + switch (key->fill_cw) { + case CLIP_POINT: + key->offset_cw = templ->offset_point; + break; + case CLIP_LINE: + key->offset_cw = templ->offset_line; + break; + case CLIP_FILL: + key->offset_cw = templ->offset_tri; + break; + } + + switch (key->fill_ccw) { + case CLIP_POINT: + key->offset_ccw = templ->offset_point; + break; + case CLIP_LINE: + key->offset_ccw = templ->offset_line; + break; + case CLIP_FILL: + key->offset_ccw = templ->offset_tri; + break; + } + + if (templ->light_twoside && key->fill_cw != CLIP_CULL) + key->copy_bfc_cw = 1; + + if (templ->light_twoside && key->fill_ccw != CLIP_CULL) + key->copy_bfc_ccw = 1; +} + + +static void +calculate_line_stipple_rast( const struct pipe_rasterizer_state *templ, + struct brw_line_stipple *bls ) +{ + GLfloat tmp = 1.0f / (templ->line_stipple_factor + 1); + GLint tmpi = tmp * (1<<13); + + bls->header.opcode = CMD_LINE_STIPPLE_PATTERN; + bls->header.length = sizeof(*bls)/4 - 2; + bls->bits0.pattern = templ->line_stipple_pattern; + bls->bits1.repeat_count = templ->line_stipple_factor + 1; + bls->bits1.inverse_repeat_count = tmpi; +} + +static void *brw_create_rasterizer_state( struct pipe_context *pipe, + const struct pipe_rasterizer_state *templ ) +{ + struct brw_context *brw = brw_context(pipe); + struct brw_rasterizer_state *rast; + + rast = CALLOC_STRUCT(brw_rasterizer_state); + if (rast == NULL) + return NULL; + + rast->templ = *templ; + + calculate_clip_key_rast( brw, templ, rast, &rast->clip_key ); + + if (templ->line_stipple_enable) + calculate_line_stipple_rast( templ, &rast->bls ); + + /* Caclculate lookup value for WM IZ table. + */ + if (templ->line_smooth) { + if (templ->fill_front == PIPE_POLYGON_MODE_LINE && + templ->fill_back == PIPE_POLYGON_MODE_LINE) { + rast->unfilled_aa_line = AA_ALWAYS; + } + else if (templ->fill_front == PIPE_POLYGON_MODE_LINE || + templ->fill_back == PIPE_POLYGON_MODE_LINE) { + rast->unfilled_aa_line = AA_SOMETIMES; + } + else { + rast->unfilled_aa_line = AA_NEVER; + } + } + else { + rast->unfilled_aa_line = AA_NEVER; + } + + return (void *)rast; +} + + +static void brw_bind_rasterizer_state(struct pipe_context *pipe, + void *cso) +{ + struct brw_context *brw = brw_context(pipe); + brw->curr.rast = (const struct brw_rasterizer_state *)cso; + brw->state.dirty.mesa |= PIPE_NEW_RAST; +} + +static void brw_delete_rasterizer_state(struct pipe_context *pipe, + void *cso) +{ + struct brw_context *brw = brw_context(pipe); + assert((const void *)cso != (const void *)brw->curr.rast); + FREE(cso); +} + + + +void brw_pipe_rast_init( struct brw_context *brw ) +{ + brw->base.create_rasterizer_state = brw_create_rasterizer_state; + brw->base.bind_rasterizer_state = brw_bind_rasterizer_state; + brw->base.delete_rasterizer_state = brw_delete_rasterizer_state; +} + +void brw_pipe_rast_cleanup( struct brw_context *brw ) +{ +} diff --git a/src/gallium/drivers/i965/brw_pipe_rast.h b/src/gallium/drivers/i965/brw_pipe_rast.h new file mode 100644 index 0000000..9354f01 --- /dev/null +++ b/src/gallium/drivers/i965/brw_pipe_rast.h @@ -0,0 +1,16 @@ +#ifndef BRW_PIPE_RAST_H +#define BRW_PIPE_RAST_H + +#include "brw_clip.h" + +struct brw_rasterizer_state { + struct pipe_rasterizer_state templ; /* for draw module */ + + /* Precalculated hardware state: + */ + struct brw_clip_prog_key clip_key; + struct brw_line_stipple bls; + unsigned unfilled_aa_line; +}; + +#endif diff --git a/src/gallium/drivers/i965/brw_pipe_sampler.c b/src/gallium/drivers/i965/brw_pipe_sampler.c new file mode 100644 index 0000000..3fe753e --- /dev/null +++ b/src/gallium/drivers/i965/brw_pipe_sampler.c @@ -0,0 +1,259 @@ + +#include "util/u_memory.h" +#include "util/u_math.h" + +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" + +#include "brw_context.h" +#include "brw_defines.h" + + + +/* The brw (and related graphics cores) do not support GL_CLAMP. The + * Intel drivers for "other operating systems" implement GL_CLAMP as + * GL_CLAMP_TO_EDGE, so the same is done here. + */ +static GLuint translate_wrap_mode( unsigned wrap ) +{ + switch( wrap ) { + case PIPE_TEX_WRAP_REPEAT: + return BRW_TEXCOORDMODE_WRAP; + + case PIPE_TEX_WRAP_CLAMP: + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return BRW_TEXCOORDMODE_CLAMP; + + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + return BRW_TEXCOORDMODE_CLAMP_BORDER; + + case PIPE_TEX_WRAP_MIRROR_REPEAT: + return BRW_TEXCOORDMODE_MIRROR; + + case PIPE_TEX_WRAP_MIRROR_CLAMP: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + return BRW_TEXCOORDMODE_MIRROR_ONCE; + + default: + return BRW_TEXCOORDMODE_WRAP; + } +} + +static GLuint translate_img_filter( unsigned filter ) +{ + switch (filter) { + case PIPE_TEX_FILTER_NEAREST: + return BRW_MAPFILTER_NEAREST; + case PIPE_TEX_FILTER_LINEAR: + return BRW_MAPFILTER_LINEAR; + default: + assert(0); + return BRW_MAPFILTER_NEAREST; + } +} + +static GLuint translate_mip_filter( unsigned filter ) +{ + switch (filter) { + case PIPE_TEX_MIPFILTER_NONE: + return BRW_MIPFILTER_NONE; + case PIPE_TEX_MIPFILTER_NEAREST: + return BRW_MIPFILTER_NEAREST; + case PIPE_TEX_MIPFILTER_LINEAR: + return BRW_MIPFILTER_LINEAR; + default: + assert(0); + return BRW_MIPFILTER_NONE; + } +} + +/* XXX: not sure why there are special translations for the shadow tex + * compare functions. In particular ALWAYS is translated to NEVER. + * Is this a hardware issue? Does i965 really suffer from this? + */ +static GLuint translate_shadow_compare_func( unsigned func ) +{ + switch (func) { + case PIPE_FUNC_NEVER: + return BRW_COMPAREFUNCTION_ALWAYS; + case PIPE_FUNC_LESS: + return BRW_COMPAREFUNCTION_LEQUAL; + case PIPE_FUNC_LEQUAL: + return BRW_COMPAREFUNCTION_LESS; + case PIPE_FUNC_GREATER: + return BRW_COMPAREFUNCTION_GEQUAL; + case PIPE_FUNC_GEQUAL: + return BRW_COMPAREFUNCTION_GREATER; + case PIPE_FUNC_NOTEQUAL: + return BRW_COMPAREFUNCTION_EQUAL; + case PIPE_FUNC_EQUAL: + return BRW_COMPAREFUNCTION_NOTEQUAL; + case PIPE_FUNC_ALWAYS: + return BRW_COMPAREFUNCTION_NEVER; + default: + assert(0); + return BRW_COMPAREFUNCTION_NEVER; + } +} + + + + +static void * +brw_create_sampler_state( struct pipe_context *pipe, + const struct pipe_sampler_state *template ) +{ + struct brw_sampler *sampler = CALLOC_STRUCT(brw_sampler); + + sampler->ss0.min_filter = translate_img_filter( template->min_img_filter ); + sampler->ss0.mag_filter = translate_img_filter( template->mag_img_filter ); + sampler->ss0.mip_filter = translate_mip_filter( template->min_mip_filter ); + + + /* XXX: anisotropy logic slightly changed: + */ + if (template->max_anisotropy > 1) { + sampler->ss0.min_filter = BRW_MAPFILTER_ANISOTROPIC; + sampler->ss0.mag_filter = BRW_MAPFILTER_ANISOTROPIC; + + sampler->ss3.max_aniso = MIN2((template->max_anisotropy - 2) / 2, + BRW_ANISORATIO_16); + } + + sampler->ss1.r_wrap_mode = translate_wrap_mode(template->wrap_r); + sampler->ss1.s_wrap_mode = translate_wrap_mode(template->wrap_s); + sampler->ss1.t_wrap_mode = translate_wrap_mode(template->wrap_t); + + /* Set LOD bias: + */ + sampler->ss0.lod_bias = + util_signed_fixed(CLAMP(template->lod_bias, -16, 15), 6); + + + sampler->ss0.lod_preclamp = 1; /* OpenGL mode */ + sampler->ss0.default_color_mode = 0; /* OpenGL/DX10 mode */ + + /* Set shadow function: + */ + if (template->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) { + + /* Shadowing is "enabled" by emitting a particular sampler + * message (sample_c). So need to recompile WM program when + * shadow comparison is enabled on each/any texture unit. + */ + sampler->ss0.shadow_function = + translate_shadow_compare_func(template->compare_func); + } + + /* Set BaseMipLevel, MaxLOD, MinLOD: + */ + sampler->ss0.base_level = + util_unsigned_fixed(0, 1); + + sampler->ss1.max_lod = + util_unsigned_fixed(CLAMP(template->max_lod, 0, 13), 6); + + sampler->ss1.min_lod = + util_unsigned_fixed(CLAMP(template->min_lod, 0, 13), 6); + + return (void *)sampler; +} + +static void brw_bind_sampler_state(struct pipe_context *pipe, + unsigned num, void **sampler) +{ + struct brw_context *brw = brw_context(pipe); + int i; + + for (i = 0; i < num; i++) + brw->curr.sampler[i] = sampler[i]; + + for (i = num; i < brw->curr.num_samplers; i++) + brw->curr.sampler[i] = NULL; + + brw->curr.num_samplers = num; + brw->state.dirty.mesa |= PIPE_NEW_SAMPLERS; +} + +static void brw_delete_sampler_state(struct pipe_context *pipe, + void *cso) +{ + FREE(cso); +} + +static void brw_set_fragment_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct brw_context *brw = brw_context(pipe); + int i; + + for (i = 0; i < num; i++) + pipe_sampler_view_reference(&brw->curr.fragment_sampler_views[i], views[i]); + + for (i = num; i < brw->curr.num_fragment_sampler_views; i++) + pipe_sampler_view_reference(&brw->curr.fragment_sampler_views[i], NULL); + + brw->curr.num_fragment_sampler_views = num; + brw->state.dirty.mesa |= PIPE_NEW_BOUND_TEXTURES; +} + +static void brw_set_vertex_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ +} + +static void brw_bind_vertex_sampler_state(struct pipe_context *pipe, + unsigned num, void **sampler) +{ +} + + +static struct pipe_sampler_view * +brw_create_sampler_view(struct pipe_context *pipe, + struct pipe_resource *texture, + const struct pipe_sampler_view *templ) +{ + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_resource_reference(&view->texture, texture); + view->context = pipe; + } + + return view; +} + + +static void +brw_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_resource_reference(&view->texture, NULL); + FREE(view); +} + + +void brw_pipe_sampler_init( struct brw_context *brw ) +{ + brw->base.create_sampler_state = brw_create_sampler_state; + brw->base.delete_sampler_state = brw_delete_sampler_state; + + brw->base.set_fragment_sampler_views = brw_set_fragment_sampler_views; + brw->base.bind_fragment_sampler_states = brw_bind_sampler_state; + + brw->base.set_vertex_sampler_views = brw_set_vertex_sampler_views; + brw->base.bind_vertex_sampler_states = brw_bind_vertex_sampler_state; + + brw->base.create_sampler_view = brw_create_sampler_view; + brw->base.sampler_view_destroy = brw_sampler_view_destroy; +} +void brw_pipe_sampler_cleanup( struct brw_context *brw ) +{ +} diff --git a/src/gallium/drivers/i965/brw_pipe_shader.c b/src/gallium/drivers/i965/brw_pipe_shader.c new file mode 100644 index 0000000..d9bee96 --- /dev/null +++ b/src/gallium/drivers/i965/brw_pipe_shader.c @@ -0,0 +1,303 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_inlines.h" +#include "util/u_memory.h" + +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_scan.h" + +#include "brw_context.h" +#include "brw_wm.h" + + +/** + * Determine if the given shader uses complex features such as flow + * conditionals, loops, subroutines. + */ +static GLboolean has_flow_control(const struct tgsi_shader_info *info) +{ + return (info->opcode_count[TGSI_OPCODE_ARL] > 0 || + info->opcode_count[TGSI_OPCODE_IF] > 0 || + info->opcode_count[TGSI_OPCODE_ENDIF] > 0 || /* redundant - IF */ + info->opcode_count[TGSI_OPCODE_CAL] > 0 || + info->opcode_count[TGSI_OPCODE_BRK] > 0 || /* redundant - BGNLOOP */ + info->opcode_count[TGSI_OPCODE_RET] > 0 || /* redundant - CAL */ + info->opcode_count[TGSI_OPCODE_BGNLOOP] > 0); +} + + +static void scan_immediates(const struct tgsi_token *tokens, + const struct tgsi_shader_info *info, + struct brw_immediate_data *imm) +{ + struct tgsi_parse_context parse; + boolean done = FALSE; + + imm->nr = 0; + imm->data = MALLOC(info->immediate_count * 4 * sizeof(float)); + + tgsi_parse_init( &parse, tokens ); + while (!tgsi_parse_end_of_tokens( &parse ) && !done) { + tgsi_parse_token( &parse ); + + switch (parse.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_DECLARATION: + break; + + case TGSI_TOKEN_TYPE_IMMEDIATE: { + static const float id[4] = {0,0,0,1}; + const float *value = &parse.FullToken.FullImmediate.u[0].Float; + unsigned size = parse.FullToken.FullImmediate.Immediate.NrTokens - 1; + unsigned i; + + for (i = 0; i < size; i++) + imm->data[imm->nr][i] = value[i]; + + for (; i < 4; i++) + imm->data[imm->nr][i] = id[i]; + + imm->nr++; + break; + } + + case TGSI_TOKEN_TYPE_INSTRUCTION: + done = 1; + break; + } + } +} + + +static void brw_bind_fs_state( struct pipe_context *pipe, void *prog ) +{ + struct brw_fragment_shader *fs = (struct brw_fragment_shader *)prog; + struct brw_context *brw = brw_context(pipe); + + if (brw->curr.fragment_shader == fs) + return; + + if (brw->curr.fragment_shader == NULL || + fs == NULL || + memcmp(&brw->curr.fragment_shader->signature, &fs->signature, + brw_fs_signature_size(&fs->signature)) != 0) { + brw->state.dirty.mesa |= PIPE_NEW_FRAGMENT_SIGNATURE; + } + + brw->curr.fragment_shader = fs; + brw->state.dirty.mesa |= PIPE_NEW_FRAGMENT_SHADER; +} + +static void brw_bind_vs_state( struct pipe_context *pipe, void *prog ) +{ + struct brw_context *brw = brw_context(pipe); + + brw->curr.vertex_shader = (struct brw_vertex_shader *)prog; + brw->state.dirty.mesa |= PIPE_NEW_VERTEX_SHADER; +} + + + +static void *brw_create_fs_state( struct pipe_context *pipe, + const struct pipe_shader_state *shader ) +{ + struct brw_context *brw = brw_context(pipe); + struct brw_fragment_shader *fs; + int i; + + fs = CALLOC_STRUCT(brw_fragment_shader); + if (fs == NULL) + return NULL; + + /* Duplicate tokens, scan shader + */ + fs->id = brw->program_id++; + fs->has_flow_control = has_flow_control(&fs->info); + + fs->tokens = tgsi_dup_tokens(shader->tokens); + if (fs->tokens == NULL) + goto fail; + + tgsi_scan_shader(fs->tokens, &fs->info); + scan_immediates(fs->tokens, &fs->info, &fs->immediates); + + fs->signature.nr_inputs = fs->info.num_inputs; + for (i = 0; i < fs->info.num_inputs; i++) { + fs->signature.input[i].interp = fs->info.input_interpolate[i]; + fs->signature.input[i].semantic = fs->info.input_semantic_name[i]; + fs->signature.input[i].semantic_index = fs->info.input_semantic_index[i]; + } + + for (i = 0; i < fs->info.num_inputs; i++) + if (fs->info.input_semantic_name[i] == TGSI_SEMANTIC_POSITION) + fs->uses_depth = 1; + + if (fs->info.uses_kill) + fs->iz_lookup |= IZ_PS_KILL_ALPHATEST_BIT; + + if (fs->info.writes_z) + fs->iz_lookup |= IZ_PS_COMPUTES_DEPTH_BIT; + + return (void *)fs; + +fail: + FREE(fs); + return NULL; +} + + +static void *brw_create_vs_state( struct pipe_context *pipe, + const struct pipe_shader_state *shader ) +{ + struct brw_context *brw = brw_context(pipe); + struct brw_vertex_shader *vs; + unsigned i; + + vs = CALLOC_STRUCT(brw_vertex_shader); + if (vs == NULL) + return NULL; + + /* Duplicate tokens, scan shader + */ + vs->tokens = tgsi_dup_tokens(shader->tokens); + if (vs->tokens == NULL) + goto fail; + + tgsi_scan_shader(vs->tokens, &vs->info); + scan_immediates(vs->tokens, &vs->info, &vs->immediates); + + vs->id = brw->program_id++; + vs->has_flow_control = has_flow_control(&vs->info); + + vs->output_hpos = BRW_OUTPUT_NOT_PRESENT; + vs->output_color0 = BRW_OUTPUT_NOT_PRESENT; + vs->output_color1 = BRW_OUTPUT_NOT_PRESENT; + vs->output_bfc0 = BRW_OUTPUT_NOT_PRESENT; + vs->output_bfc1 = BRW_OUTPUT_NOT_PRESENT; + vs->output_edgeflag = BRW_OUTPUT_NOT_PRESENT; + + for (i = 0; i < vs->info.num_outputs; i++) { + int index = vs->info.output_semantic_index[i]; + switch (vs->info.output_semantic_name[i]) { + case TGSI_SEMANTIC_POSITION: + vs->output_hpos = i; + break; + case TGSI_SEMANTIC_COLOR: + if (index == 0) + vs->output_color0 = i; + else + vs->output_color1 = i; + break; + case TGSI_SEMANTIC_BCOLOR: + if (index == 0) + vs->output_bfc0 = i; + else + vs->output_bfc1 = i; + break; + case TGSI_SEMANTIC_EDGEFLAG: + vs->output_edgeflag = i; + break; + } + } + + + /* Done: + */ + return (void *)vs; + +fail: + FREE(vs); + return NULL; +} + + +static void brw_delete_fs_state( struct pipe_context *pipe, void *prog ) +{ + struct brw_fragment_shader *fs = (struct brw_fragment_shader *)prog; + + bo_reference(&fs->const_buffer, NULL); + FREE( (void *)fs->tokens ); + FREE( fs ); +} + + +static void brw_delete_vs_state( struct pipe_context *pipe, void *prog ) +{ + struct brw_fragment_shader *vs = (struct brw_fragment_shader *)prog; + + /* Delete draw shader + */ + FREE( (void *)vs->tokens ); + FREE( vs ); +} + + +static void brw_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + struct pipe_resource *buf) +{ + struct brw_context *brw = brw_context(pipe); + + assert(index == 0); + + if (shader == PIPE_SHADER_FRAGMENT) { + pipe_resource_reference( &brw->curr.fragment_constants, + buf ); + + brw->state.dirty.mesa |= PIPE_NEW_FRAGMENT_CONSTANTS; + } + else { + pipe_resource_reference( &brw->curr.vertex_constants, + buf ); + + brw->state.dirty.mesa |= PIPE_NEW_VERTEX_CONSTANTS; + } +} + + +void brw_pipe_shader_init( struct brw_context *brw ) +{ + brw->base.set_constant_buffer = brw_set_constant_buffer; + + brw->base.create_vs_state = brw_create_vs_state; + brw->base.bind_vs_state = brw_bind_vs_state; + brw->base.delete_vs_state = brw_delete_vs_state; + + brw->base.create_fs_state = brw_create_fs_state; + brw->base.bind_fs_state = brw_bind_fs_state; + brw->base.delete_fs_state = brw_delete_fs_state; +} + +void brw_pipe_shader_cleanup( struct brw_context *brw ) +{ + pipe_resource_reference( &brw->curr.fragment_constants, NULL ); + pipe_resource_reference( &brw->curr.vertex_constants, NULL ); +} diff --git a/src/gallium/drivers/i965/brw_pipe_surface.c b/src/gallium/drivers/i965/brw_pipe_surface.c new file mode 100644 index 0000000..4deead9 --- /dev/null +++ b/src/gallium/drivers/i965/brw_pipe_surface.c @@ -0,0 +1,263 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_memory.h" +#include "util/u_simple_list.h" +#include "util/u_math.h" + +#include "pipe/p_screen.h" +#include "brw_screen.h" +#include "brw_context.h" +#include "brw_defines.h" +#include "brw_resource.h" +#include "brw_winsys.h" + +enum { + BRW_VIEW_LINEAR, + BRW_VIEW_IN_PLACE +}; + + +static boolean need_linear_view( struct brw_screen *brw_screen, + struct brw_texture *brw_texture, + union brw_surface_id id, + unsigned usage ) +{ +#if 0 + /* XXX: what about IDGNG? + */ + if (!BRW_IS_G4X(brw->brw_screen->pci_id)) + { + struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[i]; + struct intel_renderbuffer *irb = intel_renderbuffer(rb); + + /* The original gen4 hardware couldn't set up WM surfaces pointing + * at an offset within a tile, which can happen when rendering to + * anything but the base level of a texture or the +X face/0 depth. + * This was fixed with the 4 Series hardware. + * + * For these original chips, you would have to make the depth and + * color destination surfaces include information on the texture + * type, LOD, face, and various limits to use them as a destination. + * + * This is easy in Gallium as surfaces are all backed by + * textures, but there's also a nasty requirement that the depth + * and the color surfaces all be of the same LOD, which is + * harder to get around as we can't look at a surface in + * isolation and decide if it's legal. + * + * Instead, end up being pessimistic and say that for i965, + * ... ?? + */ + if (brw_tex->tiling != I915_TILING_NONE && + (brw_tex_image_offset(brw_tex, face, level, zslize) & 4095)) { + if (BRW_DEBUG & DEBUG_VIEW) + debug_printf("%s: need surface view for non-aligned tex image\n", + __FUNCTION__); + return GL_TRUE; + } + } +#endif + + /* Tiled 3d textures don't have subsets that look like 2d surfaces: + */ + + /* Everything else should be fine to render to in-place: + */ + return GL_FALSE; +} + +/* Look at all texture views and figure out if any of them need to be + * back-copied into the texture for sampling + */ +void brw_update_texture( struct brw_screen *brw_screen, + struct brw_texture *tex ) +{ + /* currently nothing to do */ +} + + +/* Create a new surface with linear layout to serve as a render-target + * where it would be illegal (perhaps due to tiling constraints) to do + * this in-place. + * + * Currently not implemented, not sure if it's needed. + */ +static struct brw_surface *create_linear_view( struct brw_screen *brw_screen, + struct pipe_context *pipe, + struct brw_texture *tex, + union brw_surface_id id, + unsigned usage ) +{ + return NULL; +} + + +/* Create a pipe_surface that just points directly into the existing + * texture's storage. + */ +static struct brw_surface *create_in_place_view( struct brw_screen *brw_screen, + struct pipe_context *pipe, + struct brw_texture *tex, + union brw_surface_id id, + unsigned usage ) +{ + struct brw_surface *surface; + + surface = CALLOC_STRUCT(brw_surface); + if (surface == NULL) + return NULL; + + pipe_reference_init(&surface->base.reference, 1); + + /* XXX: ignoring render-to-slice-of-3d-texture + */ + assert(tex->b.b.target != PIPE_TEXTURE_3D || id.bits.layer == 0); + + surface->base.context = pipe; + surface->base.format = tex->b.b.format; + surface->base.width = u_minify(tex->b.b.width0, id.bits.level); + surface->base.height = u_minify(tex->b.b.height0, id.bits.level); + surface->base.usage = usage; + surface->base.u.tex.first_layer = id.bits.layer; + surface->base.u.tex.last_layer = surface->base.u.tex.first_layer; + surface->base.u.tex.level = id.bits.level; + surface->id = id; + surface->offset = tex->image_offset[id.bits.level][id.bits.layer]; + surface->cpp = tex->cpp; + surface->pitch = tex->pitch; + surface->tiling = tex->tiling; + + bo_reference( &surface->bo, tex->bo ); + pipe_resource_reference( &surface->base.texture, &tex->b.b ); + + surface->ss.ss0.surface_format = tex->ss.ss0.surface_format; + surface->ss.ss0.surface_type = BRW_SURFACE_2D; + + if (tex->tiling == BRW_TILING_NONE) { + surface->ss.ss1.base_addr = surface->offset; + } else { + uint32_t tile_offset = surface->offset % 4096; + + surface->ss.ss1.base_addr = surface->offset - tile_offset; + + if (brw_screen->chipset.is_g4x) { + if (tex->tiling == BRW_TILING_X) { + /* Note that the low bits of these fields are missing, so + * there's the possibility of getting in trouble. + */ + surface->ss.ss5.x_offset = (tile_offset % 512) / tex->cpp / 4; + surface->ss.ss5.y_offset = tile_offset / 512 / 2; + } else { + surface->ss.ss5.x_offset = (tile_offset % 128) / tex->cpp / 4; + surface->ss.ss5.y_offset = tile_offset / 128 / 2; + } + } + else { + assert(tile_offset == 0); + } + } + +#if 0 + if (region_bo != NULL) + surface->ss.ss1.base_addr += region_bo->offset; /* reloc */ +#endif + + surface->ss.ss2.width = surface->base.width - 1; + surface->ss.ss2.height = surface->base.height - 1; + surface->ss.ss3.tiled_surface = tex->ss.ss3.tiled_surface; + surface->ss.ss3.tile_walk = tex->ss.ss3.tile_walk; + surface->ss.ss3.pitch = tex->ss.ss3.pitch; + + return surface; +} + +/* Get a surface which is view into a texture + */ +static struct pipe_surface *brw_create_surface(struct pipe_context *pipe, + struct pipe_resource *pt, + const struct pipe_surface *surf_tmpl) +{ + struct brw_texture *tex = brw_texture(pt); + struct brw_screen *bscreen = brw_screen(pipe->screen); + struct brw_surface *surface; + union brw_surface_id id; + int type; + + assert(surf_tmpl->u.tex.first_layer == surf_tmpl->u.tex.last_layer); + id.bits.level = surf_tmpl->u.tex.level; + id.bits.layer = surf_tmpl->u.tex.first_layer; + + if (need_linear_view(bscreen, tex, id, surf_tmpl->usage)) + type = BRW_VIEW_LINEAR; + else + type = BRW_VIEW_IN_PLACE; + + + foreach (surface, &tex->views[type]) { + if (id.value == surface->id.value) + return &surface->base; + } + + switch (type) { + case BRW_VIEW_LINEAR: + surface = create_linear_view( bscreen, pipe, tex, id, surf_tmpl->usage ); + break; + case BRW_VIEW_IN_PLACE: + surface = create_in_place_view( bscreen, pipe, tex, id, surf_tmpl->usage ); + break; + } + + insert_at_head( &tex->views[type], surface ); + return &surface->base; +} + + +static void brw_surface_destroy( struct pipe_context *pipe, + struct pipe_surface *surf ) +{ + struct brw_surface *surface = brw_surface(surf); + + /* Unreference texture, shared buffer: + */ + remove_from_list(surface); + bo_reference(&surface->bo, NULL); + pipe_resource_reference( &surface->base.texture, NULL ); + + FREE(surface); +} + + +void brw_pipe_surface_init( struct brw_context *brw ) +{ + brw->base.create_surface = brw_create_surface; + brw->base.surface_destroy = brw_surface_destroy; +} diff --git a/src/gallium/drivers/i965/brw_pipe_vertex.c b/src/gallium/drivers/i965/brw_pipe_vertex.c new file mode 100644 index 0000000..007239e --- /dev/null +++ b/src/gallium/drivers/i965/brw_pipe_vertex.c @@ -0,0 +1,333 @@ +#include "brw_context.h" +#include "brw_defines.h" +#include "brw_structs.h" + +#include "util/u_memory.h" +#include "util/u_format.h" + + +static unsigned brw_translate_surface_format( unsigned id ) +{ + switch (id) { + case PIPE_FORMAT_R64_FLOAT: + return BRW_SURFACEFORMAT_R64_FLOAT; + case PIPE_FORMAT_R64G64_FLOAT: + return BRW_SURFACEFORMAT_R64G64_FLOAT; + case PIPE_FORMAT_R64G64B64_FLOAT: + return BRW_SURFACEFORMAT_R64G64B64_FLOAT; + case PIPE_FORMAT_R64G64B64A64_FLOAT: + return BRW_SURFACEFORMAT_R64G64B64A64_FLOAT; + + case PIPE_FORMAT_R32_FLOAT: + return BRW_SURFACEFORMAT_R32_FLOAT; + case PIPE_FORMAT_R32G32_FLOAT: + return BRW_SURFACEFORMAT_R32G32_FLOAT; + case PIPE_FORMAT_R32G32B32_FLOAT: + return BRW_SURFACEFORMAT_R32G32B32_FLOAT; + case PIPE_FORMAT_R32G32B32A32_FLOAT: + return BRW_SURFACEFORMAT_R32G32B32A32_FLOAT; + + case PIPE_FORMAT_R32_UNORM: + return BRW_SURFACEFORMAT_R32_UNORM; + case PIPE_FORMAT_R32G32_UNORM: + return BRW_SURFACEFORMAT_R32G32_UNORM; + case PIPE_FORMAT_R32G32B32_UNORM: + return BRW_SURFACEFORMAT_R32G32B32_UNORM; + case PIPE_FORMAT_R32G32B32A32_UNORM: + return BRW_SURFACEFORMAT_R32G32B32A32_UNORM; + + case PIPE_FORMAT_R32_USCALED: + return BRW_SURFACEFORMAT_R32_USCALED; + case PIPE_FORMAT_R32G32_USCALED: + return BRW_SURFACEFORMAT_R32G32_USCALED; + case PIPE_FORMAT_R32G32B32_USCALED: + return BRW_SURFACEFORMAT_R32G32B32_USCALED; + case PIPE_FORMAT_R32G32B32A32_USCALED: + return BRW_SURFACEFORMAT_R32G32B32A32_USCALED; + + case PIPE_FORMAT_R32_SNORM: + return BRW_SURFACEFORMAT_R32_SNORM; + case PIPE_FORMAT_R32G32_SNORM: + return BRW_SURFACEFORMAT_R32G32_SNORM; + case PIPE_FORMAT_R32G32B32_SNORM: + return BRW_SURFACEFORMAT_R32G32B32_SNORM; + case PIPE_FORMAT_R32G32B32A32_SNORM: + return BRW_SURFACEFORMAT_R32G32B32A32_SNORM; + + case PIPE_FORMAT_R32_SSCALED: + return BRW_SURFACEFORMAT_R32_SSCALED; + case PIPE_FORMAT_R32G32_SSCALED: + return BRW_SURFACEFORMAT_R32G32_SSCALED; + case PIPE_FORMAT_R32G32B32_SSCALED: + return BRW_SURFACEFORMAT_R32G32B32_SSCALED; + case PIPE_FORMAT_R32G32B32A32_SSCALED: + return BRW_SURFACEFORMAT_R32G32B32A32_SSCALED; + + case PIPE_FORMAT_R16_UNORM: + return BRW_SURFACEFORMAT_R16_UNORM; + case PIPE_FORMAT_R16G16_UNORM: + return BRW_SURFACEFORMAT_R16G16_UNORM; + case PIPE_FORMAT_R16G16B16_UNORM: + return BRW_SURFACEFORMAT_R16G16B16_UNORM; + case PIPE_FORMAT_R16G16B16A16_UNORM: + return BRW_SURFACEFORMAT_R16G16B16A16_UNORM; + + case PIPE_FORMAT_R16_USCALED: + return BRW_SURFACEFORMAT_R16_USCALED; + case PIPE_FORMAT_R16G16_USCALED: + return BRW_SURFACEFORMAT_R16G16_USCALED; + case PIPE_FORMAT_R16G16B16_USCALED: + return BRW_SURFACEFORMAT_R16G16B16_USCALED; + case PIPE_FORMAT_R16G16B16A16_USCALED: + return BRW_SURFACEFORMAT_R16G16B16A16_USCALED; + + case PIPE_FORMAT_R16_SNORM: + return BRW_SURFACEFORMAT_R16_SNORM; + case PIPE_FORMAT_R16G16_SNORM: + return BRW_SURFACEFORMAT_R16G16_SNORM; + case PIPE_FORMAT_R16G16B16_SNORM: + return BRW_SURFACEFORMAT_R16G16B16_SNORM; + case PIPE_FORMAT_R16G16B16A16_SNORM: + return BRW_SURFACEFORMAT_R16G16B16A16_SNORM; + + case PIPE_FORMAT_R16_SSCALED: + return BRW_SURFACEFORMAT_R16_SSCALED; + case PIPE_FORMAT_R16G16_SSCALED: + return BRW_SURFACEFORMAT_R16G16_SSCALED; + case PIPE_FORMAT_R16G16B16_SSCALED: + return BRW_SURFACEFORMAT_R16G16B16_SSCALED; + case PIPE_FORMAT_R16G16B16A16_SSCALED: + return BRW_SURFACEFORMAT_R16G16B16A16_SSCALED; + + case PIPE_FORMAT_R8_UNORM: + return BRW_SURFACEFORMAT_R8_UNORM; + case PIPE_FORMAT_R8G8_UNORM: + return BRW_SURFACEFORMAT_R8G8_UNORM; + case PIPE_FORMAT_R8G8B8_UNORM: + return BRW_SURFACEFORMAT_R8G8B8_UNORM; + case PIPE_FORMAT_R8G8B8A8_UNORM: + return BRW_SURFACEFORMAT_R8G8B8A8_UNORM; + + case PIPE_FORMAT_R8_USCALED: + return BRW_SURFACEFORMAT_R8_USCALED; + case PIPE_FORMAT_R8G8_USCALED: + return BRW_SURFACEFORMAT_R8G8_USCALED; + case PIPE_FORMAT_R8G8B8_USCALED: + return BRW_SURFACEFORMAT_R8G8B8_USCALED; + case PIPE_FORMAT_R8G8B8A8_USCALED: + return BRW_SURFACEFORMAT_R8G8B8A8_USCALED; + + case PIPE_FORMAT_R8_SNORM: + return BRW_SURFACEFORMAT_R8_SNORM; + case PIPE_FORMAT_R8G8_SNORM: + return BRW_SURFACEFORMAT_R8G8_SNORM; + case PIPE_FORMAT_R8G8B8_SNORM: + return BRW_SURFACEFORMAT_R8G8B8_SNORM; + case PIPE_FORMAT_R8G8B8A8_SNORM: + return BRW_SURFACEFORMAT_R8G8B8A8_SNORM; + + case PIPE_FORMAT_R8_SSCALED: + return BRW_SURFACEFORMAT_R8_SSCALED; + case PIPE_FORMAT_R8G8_SSCALED: + return BRW_SURFACEFORMAT_R8G8_SSCALED; + case PIPE_FORMAT_R8G8B8_SSCALED: + return BRW_SURFACEFORMAT_R8G8B8_SSCALED; + case PIPE_FORMAT_R8G8B8A8_SSCALED: + return BRW_SURFACEFORMAT_R8G8B8A8_SSCALED; + + default: + assert(0); + return 0; + } +} + +static void brw_translate_vertex_elements(struct brw_context *brw, + struct brw_vertex_element_packet *brw_velems, + const struct pipe_vertex_element *attribs, + unsigned count) +{ + unsigned i; + + /* If the VS doesn't read any inputs (calculating vertex position from + * a state variable for some reason, for example), emit a single pad + * VERTEX_ELEMENT struct and bail. + * + * The stale VB state stays in place, but they don't do anything unless + * a VE loads from them. + */ + brw_velems->header.opcode = CMD_VERTEX_ELEMENT; + + if (count == 0) { + brw_velems->header.length = 1; + brw_velems->ve[0].ve0.src_offset = 0; + brw_velems->ve[0].ve0.src_format = BRW_SURFACEFORMAT_R32G32B32A32_FLOAT; + brw_velems->ve[0].ve0.valid = 1; + brw_velems->ve[0].ve0.vertex_buffer_index = 0; + brw_velems->ve[0].ve1.dst_offset = 0; + brw_velems->ve[0].ve1.vfcomponent0 = BRW_VE1_COMPONENT_STORE_0; + brw_velems->ve[0].ve1.vfcomponent1 = BRW_VE1_COMPONENT_STORE_0; + brw_velems->ve[0].ve1.vfcomponent2 = BRW_VE1_COMPONENT_STORE_0; + brw_velems->ve[0].ve1.vfcomponent3 = BRW_VE1_COMPONENT_STORE_1_FLT; + return; + } + + + /* Now emit vertex element (VEP) state packets. + * + */ + brw_velems->header.length = (1 + count * 2) - 2; + for (i = 0; i < count; i++) { + const struct pipe_vertex_element *input = &attribs[i]; + unsigned nr_components = util_format_get_nr_components(input->src_format); + + uint32_t format = brw_translate_surface_format( input->src_format ); + uint32_t comp0 = BRW_VE1_COMPONENT_STORE_SRC; + uint32_t comp1 = BRW_VE1_COMPONENT_STORE_SRC; + uint32_t comp2 = BRW_VE1_COMPONENT_STORE_SRC; + uint32_t comp3 = BRW_VE1_COMPONENT_STORE_SRC; + + switch (nr_components) { + case 0: comp0 = BRW_VE1_COMPONENT_STORE_0; /* fallthrough */ + case 1: comp1 = BRW_VE1_COMPONENT_STORE_0; /* fallthrough */ + case 2: comp2 = BRW_VE1_COMPONENT_STORE_0; /* fallthrough */ + case 3: comp3 = BRW_VE1_COMPONENT_STORE_1_FLT; + break; + } + + brw_velems->ve[i].ve0.src_offset = input->src_offset; + brw_velems->ve[i].ve0.src_format = format; + brw_velems->ve[i].ve0.valid = 1; + brw_velems->ve[i].ve0.vertex_buffer_index = input->vertex_buffer_index; + brw_velems->ve[i].ve1.vfcomponent0 = comp0; + brw_velems->ve[i].ve1.vfcomponent1 = comp1; + brw_velems->ve[i].ve1.vfcomponent2 = comp2; + brw_velems->ve[i].ve1.vfcomponent3 = comp3; + + if (BRW_IS_IGDNG(brw)) + brw_velems->ve[i].ve1.dst_offset = 0; + else + brw_velems->ve[i].ve1.dst_offset = i * 4; + } +} + +static void* brw_create_vertex_elements_state( struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_element *attribs ) +{ + /* note: for the brw_swtnl.c code (if ever we need draw fallback) we'd also need + to store the original data */ + struct brw_context *brw = brw_context(pipe); + struct brw_vertex_element_packet *velems; + assert(count <= BRW_VEP_MAX); + velems = (struct brw_vertex_element_packet *) MALLOC(sizeof(struct brw_vertex_element_packet)); + if (velems) { + brw_translate_vertex_elements(brw, velems, attribs, count); + } + return velems; +} + +static void brw_bind_vertex_elements_state(struct pipe_context *pipe, + void *velems) +{ + struct brw_context *brw = brw_context(pipe); + struct brw_vertex_element_packet *brw_velems = (struct brw_vertex_element_packet *) velems; + + brw->curr.velems = brw_velems; + + brw->state.dirty.mesa |= PIPE_NEW_VERTEX_ELEMENT; +} + +static void brw_delete_vertex_elements_state(struct pipe_context *pipe, void *velems) +{ + FREE( velems ); +} + + +static void brw_set_vertex_buffers(struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_buffer *buffers) +{ + struct brw_context *brw = brw_context(pipe); + unsigned i; + + /* Check for no change */ + if (count == brw->curr.num_vertex_buffers && + memcmp(brw->curr.vertex_buffer, + buffers, + count * sizeof buffers[0]) == 0) + return; + + /* Adjust refcounts */ + for (i = 0; i < count; i++) + pipe_resource_reference(&brw->curr.vertex_buffer[i].buffer, + buffers[i].buffer); + + for ( ; i < brw->curr.num_vertex_buffers; i++) + pipe_resource_reference(&brw->curr.vertex_buffer[i].buffer, + NULL); + + /* Copy remaining data */ + memcpy(brw->curr.vertex_buffer, buffers, count * sizeof buffers[0]); + brw->curr.num_vertex_buffers = count; + + brw->state.dirty.mesa |= PIPE_NEW_VERTEX_BUFFER; +} + + +static void brw_set_index_buffer(struct pipe_context *pipe, + const struct pipe_index_buffer *ib) +{ + struct brw_context *brw = brw_context(pipe); + + if (ib) { + if (brw->curr.index_buffer == ib->buffer && + brw->curr.index_offset == ib->offset && + brw->curr.index_size == ib->index_size) + return; + + pipe_resource_reference(&brw->curr.index_buffer, ib->buffer); + brw->curr.index_offset = ib->offset; + brw->curr.index_size = ib->index_size; + } + else { + if (!brw->curr.index_buffer && + !brw->curr.index_offset && + !brw->curr.index_size) + return; + + pipe_resource_reference(&brw->curr.index_buffer, NULL); + brw->curr.index_offset = 0; + brw->curr.index_size = 0; + } + + brw->state.dirty.mesa |= PIPE_NEW_INDEX_BUFFER; +} + + +void +brw_pipe_vertex_init( struct brw_context *brw ) +{ + brw->base.set_vertex_buffers = brw_set_vertex_buffers; + brw->base.set_index_buffer = brw_set_index_buffer; + brw->base.create_vertex_elements_state = brw_create_vertex_elements_state; + brw->base.bind_vertex_elements_state = brw_bind_vertex_elements_state; + brw->base.delete_vertex_elements_state = brw_delete_vertex_elements_state; +} + + +void +brw_pipe_vertex_cleanup( struct brw_context *brw ) +{ + + /* Release bound pipe vertex_buffers + */ + + /* Release some other stuff + */ +#if 0 + for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { + bo_reference(&brw->vb.inputs[i].bo, NULL); + brw->vb.inputs[i].bo = NULL; + } +#endif +} diff --git a/src/gallium/drivers/i965/brw_public.h b/src/gallium/drivers/i965/brw_public.h new file mode 100644 index 0000000..be2cd6b --- /dev/null +++ b/src/gallium/drivers/i965/brw_public.h @@ -0,0 +1,13 @@ + +#ifndef BRW_PUBLIC_H +#define BRW_PUBLIC_H + +struct brw_winsys_screen; +struct pipe_screen; + +/** + * Create brw AKA i965 pipe_screen. + */ +struct pipe_screen * brw_screen_create(struct brw_winsys_screen *bws); + +#endif diff --git a/src/gallium/drivers/i965/brw_reg.h b/src/gallium/drivers/i965/brw_reg.h new file mode 100644 index 0000000..ba10f9d --- /dev/null +++ b/src/gallium/drivers/i965/brw_reg.h @@ -0,0 +1,115 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + +#ifndef BRW_REG_H +#define BRW_REG_H + +#define CMD_MI (0x0 << 29) +#define CMD_2D (0x2 << 29) +#define CMD_3D (0x3 << 29) + +#define MI_NOOP (CMD_MI | 0) +#define MI_BATCH_BUFFER_END (CMD_MI | 0xA << 23) +#define MI_FLUSH (CMD_MI | (4 << 23)) + +#define _3DSTATE_DRAWRECT_INFO_I965 (CMD_3D | (3 << 27) | (1 << 24) | 0x2) + +/** @{ + * + * PIPE_CONTROL operation, a combination MI_FLUSH and register write with + * additional flushing control. + */ +#define _3DSTATE_PIPE_CONTROL (CMD_3D | (3 << 27) | (2 << 24) | 2) +#define PIPE_CONTROL_NO_WRITE (0 << 14) +#define PIPE_CONTROL_WRITE_IMMEDIATE (1 << 14) +#define PIPE_CONTROL_WRITE_DEPTH_COUNT (2 << 14) +#define PIPE_CONTROL_WRITE_TIMESTAMP (3 << 14) +#define PIPE_CONTROL_DEPTH_STALL (1 << 13) +#define PIPE_CONTROL_WRITE_FLUSH (1 << 12) +#define PIPE_CONTROL_INSTRUCTION_FLUSH (1 << 11) +#define PIPE_CONTROL_INTERRUPT_ENABLE (1 << 8) +#define PIPE_CONTROL_PPGTT_WRITE (0 << 2) +#define PIPE_CONTROL_GLOBAL_GTT_WRITE (1 << 2) + +/** @} */ + +#define XY_SETUP_BLT_CMD (CMD_2D | (0x01 << 22) | 6) +#define XY_COLOR_BLT_CMD (CMD_2D | (0x50 << 22) | 4) +#define XY_SRC_COPY_BLT_CMD (CMD_2D | (0x53 << 22) | 6) + +/* BR00 */ +#define XY_BLT_WRITE_ALPHA (1 << 21) +#define XY_BLT_WRITE_RGB (1 << 20) +#define XY_SRC_TILED (1 << 15) +#define XY_DST_TILED (1 << 11) + +/* BR13 */ +#define BR13_565 (0x1 << 24) +#define BR13_8888 (0x3 << 24) + +#define FENCE_LINEAR 0 +#define FENCE_XMAJOR 1 +#define FENCE_YMAJOR 2 + + + +/* PCI IDs + */ +#define PCI_CHIP_I965_G 0x29A2 +#define PCI_CHIP_I965_Q 0x2992 +#define PCI_CHIP_I965_G_1 0x2982 +#define PCI_CHIP_I946_GZ 0x2972 +#define PCI_CHIP_I965_GM 0x2A02 +#define PCI_CHIP_I965_GME 0x2A12 + +#define PCI_CHIP_GM45_GM 0x2A42 + +#define PCI_CHIP_IGD_E_G 0x2E02 +#define PCI_CHIP_Q45_G 0x2E12 +#define PCI_CHIP_G45_G 0x2E22 +#define PCI_CHIP_G41_G 0x2E32 +#define PCI_CHIP_B43_G 0x2E42 + +#define PCI_CHIP_ILD_G 0x0042 +#define PCI_CHIP_ILM_G 0x0046 + +struct brw_chipset { + unsigned pci_id:16; + unsigned is_965:1; + unsigned is_igdng:1; + unsigned is_g4x:1; + unsigned pad:13; +}; + + +/* XXX: hacks + */ +#define VERT_RESULT_HPOS 0 /* not always true */ +#define VERT_RESULT_PSIZ 127 /* disabled */ + + +#endif diff --git a/src/gallium/drivers/i965/brw_resource.c b/src/gallium/drivers/i965/brw_resource.c new file mode 100644 index 0000000..3b61ffb --- /dev/null +++ b/src/gallium/drivers/i965/brw_resource.c @@ -0,0 +1,52 @@ +#include "util/u_debug.h" +#include "util/u_surface.h" + +#include "brw_resource.h" +#include "brw_context.h" +#include "brw_screen.h" + + +static struct pipe_resource * +brw_resource_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + if (template->target == PIPE_BUFFER) + return brw_buffer_create(screen, template); + else + return brw_texture_create(screen, template); + +} + +static struct pipe_resource * +brw_resource_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle) +{ + if (template->target == PIPE_BUFFER) + return NULL; + else + return brw_texture_from_handle(screen, template, whandle); +} + + +void +brw_init_resource_functions(struct brw_context *brw ) +{ + brw->base.get_transfer = u_get_transfer_vtbl; + brw->base.transfer_map = u_transfer_map_vtbl; + brw->base.transfer_flush_region = u_transfer_flush_region_vtbl; + brw->base.transfer_unmap = u_transfer_unmap_vtbl; + brw->base.transfer_destroy = u_transfer_destroy_vtbl; + brw->base.transfer_inline_write = u_transfer_inline_write_vtbl; + brw->base.resource_copy_region = util_resource_copy_region; +} + +void +brw_init_screen_resource_functions(struct brw_screen *is) +{ + is->base.resource_create = brw_resource_create; + is->base.resource_from_handle = brw_resource_from_handle; + is->base.resource_get_handle = u_resource_get_handle_vtbl; + is->base.resource_destroy = u_resource_destroy_vtbl; + is->base.user_buffer_create = brw_user_buffer_create; +} diff --git a/src/gallium/drivers/i965/brw_resource.h b/src/gallium/drivers/i965/brw_resource.h new file mode 100644 index 0000000..78defb3 --- /dev/null +++ b/src/gallium/drivers/i965/brw_resource.h @@ -0,0 +1,152 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef BRW_RESOURCE_H +#define BRW_RESOURCE_H + +struct brw_screen; + +#include "util/u_transfer.h" +#include "util/u_debug.h" + +#include "brw_screen.h" /* for brw_surface */ + +struct brw_context; +struct brw_screen; + + +struct brw_buffer { + struct u_resource b; + + /* One of either bo or user_buffer will be non-null, depending on + * whether this is a hardware or user buffer. + */ + struct brw_winsys_buffer *bo; + void *user_buffer; + + /* Mapped pointer?? + */ + void *ptr; +}; + +#define BRW_MAX_TEXTURE_2D_LEVELS 11 /* max 1024x1024 */ +#define BRW_MAX_TEXTURE_3D_LEVELS 8 /* max 128x128x128 */ + + + +struct brw_texture { + struct u_resource b; + struct brw_winsys_buffer *bo; + struct brw_surface_state ss; + + unsigned *image_offset[BRW_MAX_TEXTURE_2D_LEVELS]; + unsigned nr_images[BRW_MAX_TEXTURE_2D_LEVELS]; + unsigned level_offset[BRW_MAX_TEXTURE_2D_LEVELS]; + + boolean compressed; + unsigned brw_target; + unsigned pitch; + unsigned tiling; + unsigned cpp; + unsigned total_height; + + struct brw_surface views[2]; +}; + + +void brw_init_screen_resource_functions(struct brw_screen *is); +void brw_init_resource_functions(struct brw_context *brw ); + +extern struct u_resource_vtbl brw_buffer_vtbl; +extern struct u_resource_vtbl brw_texture_vtbl; + +static INLINE struct brw_texture *brw_texture( struct pipe_resource *resource ) +{ + struct brw_texture *tex = (struct brw_texture *)resource; + assert(tex->b.vtbl == &brw_texture_vtbl); + return tex; +} + +static INLINE struct brw_buffer *brw_buffer( struct pipe_resource *resource ) +{ + struct brw_buffer *tex = (struct brw_buffer *)resource; + assert(tex->b.vtbl == &brw_buffer_vtbl); + return tex; +} + +struct pipe_resource * +brw_texture_create(struct pipe_screen *screen, + const struct pipe_resource *template); + +struct pipe_resource * +brw_texture_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle); + + +struct pipe_resource * +brw_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage); + +struct pipe_resource * +brw_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *template); + + +/* +boolean +brw_is_format_supported( struct pipe_screen *screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned tex_usage, + unsigned geom_flags ); +*/ + +/* Pipe buffer helpers + */ +static INLINE boolean +brw_buffer_is_user_buffer( const struct pipe_resource *buf ) +{ + return ((const struct brw_buffer *)buf)->user_buffer != NULL; +} + + +/*********************************************************************** + * Internal functions + */ +GLboolean brw_texture_layout(struct brw_screen *brw_screen, + struct brw_texture *tex ); + +void brw_update_texture( struct brw_screen *brw_screen, + struct brw_texture *tex ); + + + +#endif /* BRW_RESOURCE_H */ diff --git a/src/gallium/drivers/i965/brw_resource_buffer.c b/src/gallium/drivers/i965/brw_resource_buffer.c new file mode 100644 index 0000000..afb96ee --- /dev/null +++ b/src/gallium/drivers/i965/brw_resource_buffer.c @@ -0,0 +1,202 @@ + +#include "util/u_memory.h" +#include "util/u_math.h" + +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" + +#include "brw_resource.h" +#include "brw_context.h" +#include "brw_batchbuffer.h" +#include "brw_winsys.h" + +static boolean +brw_buffer_get_handle(struct pipe_screen *screen, + struct pipe_resource *resource, + struct winsys_handle *handle) +{ + return FALSE; +} + + +static void +brw_buffer_destroy(struct pipe_screen *screen, + struct pipe_resource *resource) +{ + struct brw_buffer *buf = brw_buffer( resource ); + + bo_reference(&buf->bo, NULL); + FREE(buf); +} + + +static void * +brw_buffer_transfer_map( struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct brw_screen *bscreen = brw_screen(pipe->screen); + struct brw_winsys_screen *sws = bscreen->sws; + struct brw_buffer *buf = brw_buffer(transfer->resource); + unsigned offset = transfer->box.x; + unsigned length = transfer->box.width; + unsigned usage = transfer->usage; + uint8_t *map; + + if (buf->user_buffer) + map = buf->user_buffer; + else + map = sws->bo_map( buf->bo, + BRW_DATA_OTHER, + offset, + length, + (usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE, + (usage & PIPE_TRANSFER_DISCARD) ? TRUE : FALSE, + (usage & PIPE_TRANSFER_FLUSH_EXPLICIT) ? TRUE : FALSE); + + return map + offset; +} + + +static void +brw_buffer_transfer_flush_region( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box) +{ + struct brw_screen *bscreen = brw_screen(pipe->screen); + struct brw_winsys_screen *sws = bscreen->sws; + struct brw_buffer *buf = brw_buffer(transfer->resource); + unsigned offset = box->x; + unsigned length = box->width; + + if (buf->user_buffer) + return; + + sws->bo_flush_range( buf->bo, + offset, + length ); +} + + +static void +brw_buffer_transfer_unmap( struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct brw_screen *bscreen = brw_screen(pipe->screen); + struct brw_winsys_screen *sws = bscreen->sws; + struct brw_buffer *buf = brw_buffer( transfer->resource ); + + if (buf->bo) + sws->bo_unmap(buf->bo); +} + + +static unsigned brw_buffer_is_referenced( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + int layer) +{ + struct brw_context *brw = brw_context(pipe); + struct brw_winsys_buffer *batch_bo = brw->batch->buf; + struct brw_buffer *buf = brw_buffer(resource); + + if (buf->bo == NULL) + return PIPE_UNREFERENCED; + + if (!brw_screen(pipe->screen)->sws->bo_references( batch_bo, buf->bo )) + return PIPE_UNREFERENCED; + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + + +struct u_resource_vtbl brw_buffer_vtbl = +{ + brw_buffer_get_handle, /* get_handle */ + brw_buffer_destroy, /* resource_destroy */ + brw_buffer_is_referenced, /* is_resource_referenced */ + u_default_get_transfer, /* get_transfer */ + u_default_transfer_destroy, /* transfer_destroy */ + brw_buffer_transfer_map, /* transfer_map */ + brw_buffer_transfer_flush_region, /* transfer_flush_region */ + brw_buffer_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; + + +struct pipe_resource * +brw_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + struct brw_screen *bscreen = brw_screen(screen); + struct brw_winsys_screen *sws = bscreen->sws; + struct brw_buffer *buf; + unsigned buffer_type; + enum pipe_error ret; + + buf = CALLOC_STRUCT(brw_buffer); + if (!buf) + return NULL; + + buf->b.b = *template; + buf->b.vtbl = &brw_buffer_vtbl; + pipe_reference_init(&buf->b.b.reference, 1); + buf->b.b.screen = screen; + + switch (template->bind & (PIPE_BIND_VERTEX_BUFFER | + PIPE_BIND_INDEX_BUFFER | + PIPE_BIND_CONSTANT_BUFFER)) + { + case PIPE_BIND_VERTEX_BUFFER: + case PIPE_BIND_INDEX_BUFFER: + case (PIPE_BIND_VERTEX_BUFFER|PIPE_BIND_INDEX_BUFFER): + buffer_type = BRW_BUFFER_TYPE_VERTEX; + break; + + case PIPE_BIND_CONSTANT_BUFFER: + buffer_type = BRW_BUFFER_TYPE_SHADER_CONSTANTS; + break; + + default: + buffer_type = BRW_BUFFER_TYPE_GENERIC; + break; + } + + ret = sws->bo_alloc( sws, buffer_type, + template->width0, + 64, /* alignment */ + &buf->bo ); + if (ret != PIPE_OK) + return NULL; + + return &buf->b.b; +} + + +struct pipe_resource * +brw_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned bind) +{ + struct brw_buffer *buf; + + buf = CALLOC_STRUCT(brw_buffer); + if (!buf) + return NULL; + + pipe_reference_init(&buf->b.b.reference, 1); + buf->b.vtbl = &brw_buffer_vtbl; + buf->b.b.screen = screen; + buf->b.b.format = PIPE_FORMAT_R8_UNORM; /* ?? */ + buf->b.b.usage = PIPE_USAGE_IMMUTABLE; + buf->b.b.bind = bind; + buf->b.b.width0 = bytes; + buf->b.b.height0 = 1; + buf->b.b.depth0 = 1; + buf->b.b.array_size = 1; + + buf->user_buffer = ptr; + + return &buf->b.b; +} diff --git a/src/gallium/drivers/i965/brw_resource_texture.c b/src/gallium/drivers/i965/brw_resource_texture.c new file mode 100644 index 0000000..fded2da --- /dev/null +++ b/src/gallium/drivers/i965/brw_resource_texture.c @@ -0,0 +1,598 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_memory.h" +#include "util/u_simple_list.h" +#include "util/u_format.h" + +#include "brw_screen.h" +#include "brw_defines.h" +#include "brw_structs.h" +#include "brw_winsys.h" +#include "brw_batchbuffer.h" +#include "brw_context.h" +#include "brw_resource.h" + + +/** + * Subclass of pipe_transfer + */ +struct brw_transfer +{ + struct pipe_transfer base; + + unsigned offset; +}; + +static INLINE struct brw_transfer * +brw_transfer(struct pipe_transfer *transfer) +{ + return (struct brw_transfer *)transfer; +} + + +static GLuint translate_tex_target( unsigned target ) +{ + switch (target) { + case PIPE_TEXTURE_1D: + return BRW_SURFACE_1D; + + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + return BRW_SURFACE_2D; + + case PIPE_TEXTURE_3D: + return BRW_SURFACE_3D; + + case PIPE_TEXTURE_CUBE: + return BRW_SURFACE_CUBE; + + default: + assert(0); + return BRW_SURFACE_1D; + } +} + + +static GLuint translate_tex_format( enum pipe_format pf ) +{ + switch( pf ) { + case PIPE_FORMAT_L8_UNORM: + return BRW_SURFACEFORMAT_L8_UNORM; + + case PIPE_FORMAT_I8_UNORM: + return BRW_SURFACEFORMAT_I8_UNORM; + + case PIPE_FORMAT_A8_UNORM: + return BRW_SURFACEFORMAT_A8_UNORM; + + case PIPE_FORMAT_L16_UNORM: + return BRW_SURFACEFORMAT_L16_UNORM; + + /* XXX: Add these to gallium + case PIPE_FORMAT_I16_UNORM: + return BRW_SURFACEFORMAT_I16_UNORM; + + case PIPE_FORMAT_A16_UNORM: + return BRW_SURFACEFORMAT_A16_UNORM; + */ + + case PIPE_FORMAT_L8A8_UNORM: + return BRW_SURFACEFORMAT_L8A8_UNORM; + + case PIPE_FORMAT_B5G6R5_UNORM: + return BRW_SURFACEFORMAT_B5G6R5_UNORM; + + case PIPE_FORMAT_B5G5R5A1_UNORM: + return BRW_SURFACEFORMAT_B5G5R5A1_UNORM; + + case PIPE_FORMAT_B4G4R4A4_UNORM: + return BRW_SURFACEFORMAT_B4G4R4A4_UNORM; + + case PIPE_FORMAT_B8G8R8X8_UNORM: + return BRW_SURFACEFORMAT_R8G8B8X8_UNORM; + + case PIPE_FORMAT_B8G8R8A8_UNORM: + return BRW_SURFACEFORMAT_B8G8R8A8_UNORM; + + /* + * Video formats + */ + + case PIPE_FORMAT_YUYV: + return BRW_SURFACEFORMAT_YCRCB_NORMAL; + + case PIPE_FORMAT_UYVY: + return BRW_SURFACEFORMAT_YCRCB_SWAPUVY; + + /* + * Compressed formats. + */ + /* XXX: Add FXT to gallium? + case PIPE_FORMAT_FXT1_RGBA: + return BRW_SURFACEFORMAT_FXT1; + */ + + case PIPE_FORMAT_DXT1_RGB: + return BRW_SURFACEFORMAT_DXT1_RGB; + + case PIPE_FORMAT_DXT1_RGBA: + return BRW_SURFACEFORMAT_BC1_UNORM; + + case PIPE_FORMAT_DXT3_RGBA: + return BRW_SURFACEFORMAT_BC2_UNORM; + + case PIPE_FORMAT_DXT5_RGBA: + return BRW_SURFACEFORMAT_BC3_UNORM; + + /* + * sRGB formats + */ + + case PIPE_FORMAT_A8B8G8R8_SRGB: + return BRW_SURFACEFORMAT_B8G8R8A8_UNORM_SRGB; + + case PIPE_FORMAT_L8A8_SRGB: + return BRW_SURFACEFORMAT_L8A8_UNORM_SRGB; + + case PIPE_FORMAT_L8_SRGB: + return BRW_SURFACEFORMAT_L8_UNORM_SRGB; + + case PIPE_FORMAT_DXT1_SRGB: + return BRW_SURFACEFORMAT_BC1_UNORM_SRGB; + + /* + * Depth formats + */ + + case PIPE_FORMAT_Z16_UNORM: + return BRW_SURFACEFORMAT_I16_UNORM; + + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + case PIPE_FORMAT_Z24X8_UNORM: + return BRW_SURFACEFORMAT_I24X8_UNORM; + + case PIPE_FORMAT_Z32_FLOAT: + return BRW_SURFACEFORMAT_I32_FLOAT; + + /* XXX: presumably for bump mapping. Add this to mesa state + * tracker? + * + * XXX: Add flipped versions of these formats to Gallium. + */ + case PIPE_FORMAT_R8G8_SNORM: + return BRW_SURFACEFORMAT_R8G8_SNORM; + + case PIPE_FORMAT_R8G8B8A8_SNORM: + return BRW_SURFACEFORMAT_R8G8B8A8_SNORM; + + default: + return BRW_SURFACEFORMAT_INVALID; + } +} + + +static boolean +brw_texture_get_handle(struct pipe_screen *screen, + struct pipe_resource *texture, + struct winsys_handle *whandle) +{ + struct brw_screen *bscreen = brw_screen(screen); + struct brw_texture *tex = brw_texture(texture); + unsigned stride; + + stride = tex->pitch * tex->cpp; + + return bscreen->sws->bo_get_handle(tex->bo, whandle, stride) == PIPE_OK; +} + + + +static void brw_texture_destroy(struct pipe_screen *screen, + struct pipe_resource *pt) +{ + struct brw_texture *tex = brw_texture(pt); + bo_reference(&tex->bo, NULL); + FREE(pt); +} + + + + +static unsigned brw_texture_is_referenced( struct pipe_context *pipe, + struct pipe_resource *texture, + unsigned level, + int layer ) +{ + struct brw_context *brw = brw_context(pipe); + struct brw_screen *bscreen = brw_screen(pipe->screen); + struct brw_winsys_buffer *batch_bo = brw->batch->buf; + struct brw_texture *tex = brw_texture(texture); + struct brw_surface *surf; + int i; + + /* XXX: this is subject to false positives if the underlying + * texture BO is referenced, we can't tell whether the sub-region + * we care about participates in that. + */ + if (bscreen->sws->bo_references( batch_bo, tex->bo )) + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; + + /* Find any view on this texture for this level/layer and see if it + * is referenced: + */ + for (i = 0; i < 2; i++) { + foreach (surf, &tex->views[i]) { + if (surf->bo == tex->bo) + continue; + + if (!(layer == -1 || surf->id.bits.layer == layer) || + surf->id.bits.level != level) + continue; + + if (bscreen->sws->bo_references( batch_bo, surf->bo)) + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; + } + } + + return PIPE_UNREFERENCED; +} + + +/* + * Transfer functions + */ + + +static struct pipe_transfer * +brw_texture_get_transfer(struct pipe_context *context, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct brw_texture *tex = brw_texture(resource); + struct pipe_transfer *transfer = CALLOC_STRUCT(pipe_transfer); + if (transfer == NULL) + return NULL; + + transfer->resource = resource; + transfer->level = level; + transfer->usage = usage; + transfer->box = *box; + transfer->stride = tex->pitch * tex->cpp; + /* FIXME: layer_stride */ + + return transfer; +} + + +static void * +brw_texture_transfer_map(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct pipe_resource *resource = transfer->resource; + struct brw_texture *tex = brw_texture(transfer->resource); + struct brw_winsys_screen *sws = brw_screen(pipe->screen)->sws; + struct pipe_box *box = &transfer->box; + enum pipe_format format = resource->format; + unsigned usage = transfer->usage; + unsigned offset; + char *map; + + if (resource->target != PIPE_TEXTURE_3D && + resource->target != PIPE_TEXTURE_CUBE) + assert(box->z == 0); + offset = tex->image_offset[transfer->level][box->z]; + + map = sws->bo_map(tex->bo, + BRW_DATA_OTHER, + 0, + tex->bo->size, + (usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE, + (usage & 0) ? TRUE : FALSE, + (usage & 0) ? TRUE : FALSE); + + if (!map) + return NULL; + + return map + offset + + box->y / util_format_get_blockheight(format) * transfer->stride + + box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); +} + +static void +brw_texture_transfer_unmap(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct brw_texture *tex = brw_texture(transfer->resource); + struct brw_winsys_screen *sws = brw_screen(pipe->screen)->sws; + + sws->bo_unmap(tex->bo); +} + + + + + +struct u_resource_vtbl brw_texture_vtbl = +{ + brw_texture_get_handle, /* get_handle */ + brw_texture_destroy, /* resource_destroy */ + brw_texture_is_referenced, /* is_resource_referenced */ + brw_texture_get_transfer, /* get_transfer */ + u_default_transfer_destroy, /* transfer_destroy */ + brw_texture_transfer_map, /* transfer_map */ + u_default_transfer_flush_region, /* transfer_flush_region */ + brw_texture_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; + + + + + +struct pipe_resource * +brw_texture_create( struct pipe_screen *screen, + const struct pipe_resource *template ) +{ + struct brw_screen *bscreen = brw_screen(screen); + struct brw_texture *tex; + enum brw_buffer_type buffer_type; + enum pipe_error ret; + GLuint format; + + tex = CALLOC_STRUCT(brw_texture); + if (tex == NULL) + return NULL; + + tex->b.b = *template; + tex->b.vtbl = &brw_texture_vtbl; + pipe_reference_init(&tex->b.b.reference, 1); + tex->b.b.screen = screen; + + /* XXX: compressed textures need special treatment here + */ + tex->cpp = util_format_get_blocksize(tex->b.b.format); + tex->compressed = util_format_is_s3tc(tex->b.b.format); + + make_empty_list(&tex->views[0]); + make_empty_list(&tex->views[1]); + + /* XXX: No tiling with compressed textures?? + */ + if (tex->compressed == 0 && + !bscreen->no_tiling) + { + if (bscreen->chipset.is_965 && + util_format_is_depth_or_stencil(template->format)) + tex->tiling = BRW_TILING_Y; + else + tex->tiling = BRW_TILING_X; + } + else { + tex->tiling = BRW_TILING_NONE; + } + + + if (!brw_texture_layout( bscreen, tex )) + goto fail; + + + if (template->bind & (PIPE_BIND_SCANOUT | + PIPE_BIND_SHARED)) { + buffer_type = BRW_BUFFER_TYPE_SCANOUT; + } + else { + buffer_type = BRW_BUFFER_TYPE_TEXTURE; + } + + ret = bscreen->sws->bo_alloc( bscreen->sws, + buffer_type, + tex->pitch * tex->total_height * tex->cpp, + 64, + &tex->bo ); + if (ret) + goto fail; + + tex->ss.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW; + tex->ss.ss0.surface_type = translate_tex_target(tex->b.b.target); + + format = translate_tex_format(tex->b.b.format); + assert(format != BRW_SURFACEFORMAT_INVALID); + tex->ss.ss0.surface_format = format; + + /* This is ok for all textures with channel width 8bit or less: + */ +/* tex->ss.ss0.data_return_format = BRW_SURFACERETURNFORMAT_S1; */ + + + /* XXX: what happens when tex->bo->offset changes??? + */ + tex->ss.ss1.base_addr = 0; /* reloc */ + tex->ss.ss2.mip_count = tex->b.b.last_level; + tex->ss.ss2.width = tex->b.b.width0 - 1; + tex->ss.ss2.height = tex->b.b.height0 - 1; + + switch (tex->tiling) { + case BRW_TILING_NONE: + tex->ss.ss3.tiled_surface = 0; + tex->ss.ss3.tile_walk = 0; + break; + case BRW_TILING_X: + tex->ss.ss3.tiled_surface = 1; + tex->ss.ss3.tile_walk = BRW_TILEWALK_XMAJOR; + break; + case BRW_TILING_Y: + tex->ss.ss3.tiled_surface = 1; + tex->ss.ss3.tile_walk = BRW_TILEWALK_YMAJOR; + break; + } + + tex->ss.ss3.pitch = (tex->pitch * tex->cpp) - 1; + tex->ss.ss3.depth = tex->b.b.depth0 - 1; + + tex->ss.ss4.min_lod = 0; + + if (tex->b.b.target == PIPE_TEXTURE_CUBE) { + tex->ss.ss0.cube_pos_x = 1; + tex->ss.ss0.cube_pos_y = 1; + tex->ss.ss0.cube_pos_z = 1; + tex->ss.ss0.cube_neg_x = 1; + tex->ss.ss0.cube_neg_y = 1; + tex->ss.ss0.cube_neg_z = 1; + } + + return &tex->b.b; + +fail: + bo_reference(&tex->bo, NULL); + FREE(tex); + return NULL; +} + + +struct pipe_resource * +brw_texture_from_handle(struct pipe_screen *screen, + const struct pipe_resource *template, + struct winsys_handle *whandle) +{ + struct brw_screen *bscreen = brw_screen(screen); + struct brw_texture *tex; + struct brw_winsys_buffer *buffer; + unsigned tiling; + unsigned pitch; + GLuint format; + + if ((template->target != PIPE_TEXTURE_2D + && template->target != PIPE_TEXTURE_RECT) || + template->last_level != 0 || + template->depth0 != 1) + return NULL; + + if (util_format_is_s3tc(template->format)) + return NULL; + + tex = CALLOC_STRUCT(brw_texture); + if (!tex) + return NULL; + + if (bscreen->sws->bo_from_handle(bscreen->sws, whandle, &pitch, &tiling, &buffer) != PIPE_OK) + goto fail; + + tex->b.b = *template; + tex->b.vtbl = &brw_texture_vtbl; + pipe_reference_init(&tex->b.b.reference, 1); + tex->b.b.screen = screen; + + /* XXX: cpp vs. blocksize + */ + tex->cpp = util_format_get_blocksize(tex->b.b.format); + tex->tiling = tiling; + + make_empty_list(&tex->views[0]); + make_empty_list(&tex->views[1]); + + if (!brw_texture_layout(bscreen, tex)) + goto fail; + + /* XXX Maybe some more checks? */ + if ((pitch / tex->cpp) < tex->pitch) + goto fail; + + tex->pitch = pitch / tex->cpp; + + tex->bo = buffer; + + /* fix this warning */ +#if 0 + if (tex->size > buffer->size) + goto fail; +#endif + + tex->ss.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW; + tex->ss.ss0.surface_type = translate_tex_target(tex->b.b.target); + + format = translate_tex_format(tex->b.b.format); + assert(format != BRW_SURFACEFORMAT_INVALID); + tex->ss.ss0.surface_format = format; + + /* This is ok for all textures with channel width 8bit or less: + */ +/* tex->ss.ss0.data_return_format = BRW_SURFACERETURNFORMAT_S1; */ + + + /* XXX: what happens when tex->bo->offset changes??? + */ + tex->ss.ss1.base_addr = 0; /* reloc */ + tex->ss.ss2.mip_count = tex->b.b.last_level; + tex->ss.ss2.width = tex->b.b.width0 - 1; + tex->ss.ss2.height = tex->b.b.height0 - 1; + + switch (tex->tiling) { + case BRW_TILING_NONE: + tex->ss.ss3.tiled_surface = 0; + tex->ss.ss3.tile_walk = 0; + break; + case BRW_TILING_X: + tex->ss.ss3.tiled_surface = 1; + tex->ss.ss3.tile_walk = BRW_TILEWALK_XMAJOR; + break; + case BRW_TILING_Y: + tex->ss.ss3.tiled_surface = 1; + tex->ss.ss3.tile_walk = BRW_TILEWALK_YMAJOR; + break; + } + + tex->ss.ss3.pitch = (tex->pitch * tex->cpp) - 1; + tex->ss.ss3.depth = tex->b.b.depth0 - 1; + + tex->ss.ss4.min_lod = 0; + + return &tex->b.b; + +fail: + FREE(tex); + return NULL; +} + + +#if 0 +boolean brw_is_format_supported( struct pipe_screen *screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned tex_usage, + unsigned geom_flags ) +{ + return translate_tex_format(format) != BRW_SURFACEFORMAT_INVALID; +} +#endif diff --git a/src/gallium/drivers/i965/brw_resource_texture_layout.c b/src/gallium/drivers/i965/brw_resource_texture_layout.c new file mode 100644 index 0000000..2187bdd --- /dev/null +++ b/src/gallium/drivers/i965/brw_resource_texture_layout.c @@ -0,0 +1,414 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + +#include "pipe/p_format.h" + +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "brw_resource.h" +#include "brw_debug.h" +#include "brw_winsys.h" + +/* Code to layout images in a mipmap tree for i965. + */ + +static int +brw_tex_pitch_align (struct brw_texture *tex, + int pitch) +{ + if (!tex->compressed) { + int pitch_align; + + switch (tex->tiling) { + case BRW_TILING_X: + pitch_align = 512; + break; + case BRW_TILING_Y: + pitch_align = 128; + break; + default: + /* XXX: Untiled pitch alignment of 64 bytes for now to allow + * render-to-texture to work in all cases. This should + * probably be replaced at some point by some scheme to only + * do this when really necessary, for example standalone + * render target views. + */ + pitch_align = 64; + break; + } + + pitch = align(pitch * tex->cpp, pitch_align); + pitch /= tex->cpp; + } + + return pitch; +} + + +static void +brw_tex_alignment_unit(enum pipe_format pf, + GLuint *w, GLuint *h) +{ + switch (pf) { + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + case PIPE_FORMAT_DXT3_RGBA: + case PIPE_FORMAT_DXT5_RGBA: + case PIPE_FORMAT_DXT1_SRGB: + case PIPE_FORMAT_DXT1_SRGBA: + case PIPE_FORMAT_DXT3_SRGBA: + case PIPE_FORMAT_DXT5_SRGBA: + *w = 4; + *h = 4; + break; + + default: + *w = 4; + *h = 2; + break; + } +} + + +static void +brw_tex_set_level_info(struct brw_texture *tex, + GLuint level, + GLuint nr_images, + GLuint x, GLuint y, + GLuint w, GLuint h, GLuint d) +{ + + if (BRW_DEBUG & DEBUG_TEXTURE) + debug_printf("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, + level, w, h, d, x, y, tex->level_offset[level]); + + assert(tex->image_offset[level] == NULL); + assert(nr_images >= 1); + + tex->level_offset[level] = (x + y * tex->pitch) * tex->cpp; + tex->nr_images[level] = nr_images; + + tex->image_offset[level] = MALLOC(nr_images * sizeof(GLuint)); + tex->image_offset[level][0] = 0; +} + + +static void +brw_tex_set_image_offset(struct brw_texture *tex, + GLuint level, GLuint img, + GLuint x, GLuint y, + GLuint offset) +{ + assert((x == 0 && y == 0) || img != 0 || level != 0); + assert(img < tex->nr_images[level]); + + if (BRW_DEBUG & DEBUG_TEXTURE) + debug_printf("%s level %d img %d pos %d,%d image_offset %x\n", + __FUNCTION__, level, img, x, y, + tex->image_offset[level][img]); + + tex->image_offset[level][img] = (x + y * tex->pitch) * tex->cpp + offset; +} + + + +static void brw_layout_2d( struct brw_texture *tex ) +{ + GLuint align_h = 2, align_w = 4; + GLuint level; + GLuint x = 0; + GLuint y = 0; + GLuint width = tex->b.b.width0; + GLuint height = tex->b.b.height0; + + tex->pitch = tex->b.b.width0; + brw_tex_alignment_unit(tex->b.b.format, &align_w, &align_h); + + if (tex->compressed) { + tex->pitch = align(tex->b.b.width0, align_w); + } + + /* May need to adjust pitch to accomodate the placement of + * the 2nd mipmap. This occurs when the alignment + * constraints of mipmap placement push the right edge of the + * 2nd mipmap out past the width of its parent. + */ + if (tex->b.b.last_level > 0) { + GLuint mip1_width; + + if (tex->compressed) { + mip1_width = (align(u_minify(tex->b.b.width0, 1), align_w) + + align(u_minify(tex->b.b.width0, 2), align_w)); + } else { + mip1_width = (align(u_minify(tex->b.b.width0, 1), align_w) + + u_minify(tex->b.b.width0, 2)); + } + + if (mip1_width > tex->pitch) { + tex->pitch = mip1_width; + } + } + + /* Pitch must be a whole number of dwords, even though we + * express it in texels. + */ + tex->pitch = brw_tex_pitch_align (tex, tex->pitch); + tex->total_height = 0; + + for ( level = 0 ; level <= tex->b.b.last_level ; level++ ) { + GLuint img_height; + + brw_tex_set_level_info(tex, level, 1, x, y, width, height, 1); + + if (tex->compressed) + img_height = MAX2(1, height/4); + else + img_height = align(height, align_h); + + + /* Because the images are packed better, the final offset + * might not be the maximal one: + */ + tex->total_height = MAX2(tex->total_height, y + img_height); + + /* Layout_below: step right after second mipmap. + */ + if (level == 1) { + x += align(width, align_w); + } + else { + y += img_height; + } + + width = u_minify(width, 1); + height = u_minify(height, 1); + } +} + + +static boolean +brw_layout_cubemap_idgng( struct brw_texture *tex ) +{ + GLuint align_h = 2, align_w = 4; + GLuint level; + GLuint x = 0; + GLuint y = 0; + GLuint width = tex->b.b.width0; + GLuint height = tex->b.b.height0; + GLuint qpitch = 0; + GLuint y_pitch = 0; + + tex->pitch = tex->b.b.width0; + brw_tex_alignment_unit(tex->b.b.format, &align_w, &align_h); + y_pitch = align(height, align_h); + + if (tex->compressed) { + tex->pitch = align(tex->b.b.width0, align_w); + } + + if (tex->b.b.last_level != 0) { + GLuint mip1_width; + + if (tex->compressed) { + mip1_width = (align(u_minify(tex->b.b.width0, 1), align_w) + + align(u_minify(tex->b.b.width0, 2), align_w)); + } else { + mip1_width = (align(u_minify(tex->b.b.width0, 1), align_w) + + u_minify(tex->b.b.width0, 2)); + } + + if (mip1_width > tex->pitch) { + tex->pitch = mip1_width; + } + } + + tex->pitch = brw_tex_pitch_align(tex, tex->pitch); + + if (tex->compressed) { + qpitch = ((y_pitch + + align(u_minify(y_pitch, 1), align_h) + + 11 * align_h) / 4) * tex->pitch * tex->cpp; + + tex->total_height = ((y_pitch + + align(u_minify(y_pitch, 1), align_h) + + 11 * align_h) / 4) * 6; + } else { + qpitch = (y_pitch + + align(u_minify(y_pitch, 1), align_h) + + 11 * align_h) * tex->pitch * tex->cpp; + + tex->total_height = (y_pitch + + align(u_minify(y_pitch, 1), align_h) + + 11 * align_h) * 6; + } + + for (level = 0; level <= tex->b.b.last_level; level++) { + GLuint img_height; + GLuint nr_images = 6; + GLuint q = 0; + + brw_tex_set_level_info(tex, level, nr_images, x, y, width, height, 1); + + for (q = 0; q < nr_images; q++) + brw_tex_set_image_offset(tex, level, q, x, y, q * qpitch); + + if (tex->compressed) + img_height = MAX2(1, height/4); + else + img_height = align(height, align_h); + + if (level == 1) { + x += align(width, align_w); + } + else { + y += img_height; + } + + width = u_minify(width, 1); + height = u_minify(height, 1); + } + + return TRUE; +} + + +static boolean +brw_layout_3d_cube( struct brw_texture *tex ) +{ + GLuint width = tex->b.b.width0; + GLuint height = tex->b.b.height0; + GLuint depth = tex->b.b.depth0; + GLuint pack_x_pitch, pack_x_nr; + GLuint pack_y_pitch; + GLuint level; + GLuint align_h = 2; + GLuint align_w = 4; + + tex->total_height = 0; + brw_tex_alignment_unit(tex->b.b.format, &align_w, &align_h); + + if (tex->compressed) { + tex->pitch = align(width, align_w); + pack_y_pitch = (height + 3) / 4; + } else { + tex->pitch = brw_tex_pitch_align(tex, tex->b.b.width0); + pack_y_pitch = align(tex->b.b.height0, align_h); + } + + pack_x_pitch = width; + pack_x_nr = 1; + + for (level = 0 ; level <= tex->b.b.last_level ; level++) { + GLuint nr_images = tex->b.b.target == PIPE_TEXTURE_3D ? depth : 6; + GLint x = 0; + GLint y = 0; + GLint q, j; + + brw_tex_set_level_info(tex, level, nr_images, + 0, tex->total_height, + width, height, depth); + + for (q = 0; q < nr_images;) { + for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) { + brw_tex_set_image_offset(tex, level, q, x, y, 0); + x += pack_x_pitch; + } + + x = 0; + y += pack_y_pitch; + } + + + tex->total_height += y; + width = u_minify(width, 1); + height = u_minify(height, 1); + depth = u_minify(depth, 1); + + if (tex->compressed) { + pack_y_pitch = (height + 3) / 4; + + if (pack_x_pitch > align(width, align_w)) { + pack_x_pitch = align(width, align_w); + pack_x_nr <<= 1; + } + } else { + if (pack_x_pitch > 4) { + pack_x_pitch >>= 1; + pack_x_nr <<= 1; + assert(pack_x_pitch * pack_x_nr <= tex->pitch); + } + + if (pack_y_pitch > 2) { + pack_y_pitch >>= 1; + pack_y_pitch = align(pack_y_pitch, align_h); + } + } + } + + /* The 965's sampler lays cachelines out according to how accesses + * in the texture surfaces run, so they may be "vertical" through + * memory. As a result, the docs say in Surface Padding Requirements: + * Sampling Engine Surfaces that two extra rows of padding are required. + */ + if (tex->b.b.target == PIPE_TEXTURE_CUBE) + tex->total_height += 2; + + return TRUE; +} + + + +GLboolean brw_texture_layout(struct brw_screen *brw_screen, + struct brw_texture *tex ) +{ + switch (tex->b.b.target) { + case PIPE_TEXTURE_CUBE: + if (brw_screen->chipset.is_igdng) + brw_layout_cubemap_idgng( tex ); + else + brw_layout_3d_cube( tex ); + break; + + case PIPE_TEXTURE_3D: + brw_layout_3d_cube( tex ); + break; + + default: + brw_layout_2d( tex ); + break; + } + + if (BRW_DEBUG & DEBUG_TEXTURE) + debug_printf("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, + tex->pitch, + tex->total_height, + tex->cpp, + tex->pitch * tex->total_height * tex->cpp ); + + return GL_TRUE; +} diff --git a/src/gallium/drivers/i965/brw_screen.c b/src/gallium/drivers/i965/brw_screen.c new file mode 100644 index 0000000..f5b75b1 --- /dev/null +++ b/src/gallium/drivers/i965/brw_screen.c @@ -0,0 +1,478 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_string.h" + +#include "brw_reg.h" +#include "brw_context.h" +#include "brw_screen.h" +#include "brw_winsys.h" +#include "brw_public.h" +#include "brw_debug.h" +#include "brw_resource.h" + +#ifdef DEBUG +static const struct debug_named_value debug_names[] = { + { "tex", DEBUG_TEXTURE, NULL }, + { "state", DEBUG_STATE, NULL }, + { "ioctl", DEBUG_IOCTL, NULL }, + { "blit", DEBUG_BLIT, NULL }, + { "curbe", DEBUG_CURBE, NULL }, + { "fall", DEBUG_FALLBACKS, NULL }, + { "verb", DEBUG_VERBOSE, NULL }, + { "bat", DEBUG_BATCH, NULL }, + { "pix", DEBUG_PIXEL, NULL }, + { "wins", DEBUG_WINSYS, NULL }, + { "min", DEBUG_MIN_URB, NULL }, + { "dis", DEBUG_DISASSEM, NULL }, + { "sync", DEBUG_SYNC, NULL }, + { "prim", DEBUG_PRIMS, NULL }, + { "vert", DEBUG_VERTS, NULL }, + { "dma", DEBUG_DMA, NULL }, + { "san", DEBUG_SANITY, NULL }, + { "sleep", DEBUG_SLEEP, NULL }, + { "stats", DEBUG_STATS, NULL }, + { "sing", DEBUG_SINGLE_THREAD, NULL }, + { "thre", DEBUG_SINGLE_THREAD, NULL }, + { "wm", DEBUG_WM, NULL }, + { "urb", DEBUG_URB, NULL }, + { "vs", DEBUG_VS, NULL }, + DEBUG_NAMED_VALUE_END +}; + +static const struct debug_named_value dump_names[] = { + { "asm", DUMP_ASM, NULL }, + { "state", DUMP_STATE, NULL }, + { "batch", DUMP_BATCH, NULL }, + DEBUG_NAMED_VALUE_END +}; + +int BRW_DEBUG = 0; +int BRW_DUMP = 0; + +#endif + + +/* + * Probe functions + */ + + +static const char * +brw_get_vendor(struct pipe_screen *screen) +{ + return "VMware, Inc."; +} + +static const char * +brw_get_name(struct pipe_screen *screen) +{ + static char buffer[128]; + const char *chipset; + + switch (brw_screen(screen)->chipset.pci_id) { + case PCI_CHIP_I965_G: + chipset = "I965_G"; + break; + case PCI_CHIP_I965_Q: + chipset = "I965_Q"; + break; + case PCI_CHIP_I965_G_1: + chipset = "I965_G_1"; + break; + case PCI_CHIP_I946_GZ: + chipset = "I946_GZ"; + break; + case PCI_CHIP_I965_GM: + chipset = "I965_GM"; + break; + case PCI_CHIP_I965_GME: + chipset = "I965_GME"; + break; + case PCI_CHIP_GM45_GM: + chipset = "GM45_GM"; + break; + case PCI_CHIP_IGD_E_G: + chipset = "IGD_E_G"; + break; + case PCI_CHIP_Q45_G: + chipset = "Q45_G"; + break; + case PCI_CHIP_G45_G: + chipset = "G45_G"; + break; + case PCI_CHIP_G41_G: + chipset = "G41_G"; + break; + case PCI_CHIP_B43_G: + chipset = "B43_G"; + break; + case PCI_CHIP_ILD_G: + chipset = "ILD_G"; + break; + case PCI_CHIP_ILM_G: + chipset = "ILM_G"; + break; + default: + chipset = "unknown"; + break; + } + + util_snprintf(buffer, sizeof(buffer), "i965 (chipset: %s)", chipset); + return buffer; +} + +static int +brw_get_param(struct pipe_screen *screen, enum pipe_cap param) +{ + switch (param) { + case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: + return 8; + case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS: + return 8; + case PIPE_CAP_MAX_COMBINED_SAMPLERS: + return 16; /* XXX correct? */ + case PIPE_CAP_NPOT_TEXTURES: + return 1; + case PIPE_CAP_TWO_SIDED_STENCIL: + return 1; + case PIPE_CAP_GLSL: + return 0; + case PIPE_CAP_ANISOTROPIC_FILTER: + return 0; + case PIPE_CAP_POINT_SPRITE: + return 0; + case PIPE_CAP_MAX_RENDER_TARGETS: + return 1; + case PIPE_CAP_OCCLUSION_QUERY: + return 0; + case PIPE_CAP_TIMER_QUERY: + return 0; + case PIPE_CAP_TEXTURE_SHADOW_MAP: + return 1; + case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: + return BRW_MAX_TEXTURE_2D_LEVELS; + case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: + return BRW_MAX_TEXTURE_3D_LEVELS; + case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: + return BRW_MAX_TEXTURE_2D_LEVELS; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: + return 1; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: + return 0; + case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: + /* disable for now */ + return 0; + default: + return 0; + } +} + +static int +brw_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shader_cap param) +{ + switch(shader) { + case PIPE_SHADER_VERTEX: + case PIPE_SHADER_FRAGMENT: + case PIPE_SHADER_GEOMETRY: + break; + default: + return 0; + } + + /* XXX: these are just shader model 4.0 values, fix this! */ + switch(param) { + case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: + return 65536; + case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: + return 65536; + case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: + return 65536; + case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: + return 65536; + case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: + return 65536; + case PIPE_SHADER_CAP_MAX_INPUTS: + return 32; + case PIPE_SHADER_CAP_MAX_CONSTS: + return 4096; + case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: + return PIPE_MAX_CONSTANT_BUFFERS; + case PIPE_SHADER_CAP_MAX_TEMPS: + return 4096; + case PIPE_SHADER_CAP_MAX_ADDRS: + return 0; + case PIPE_SHADER_CAP_MAX_PREDS: + return 0; + case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: + return 1; + case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: + case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: + return 1; + case PIPE_SHADER_CAP_SUBROUTINES: + return 1; + default: + assert(0); + return 0; + } +} + +static float +brw_get_paramf(struct pipe_screen *screen, enum pipe_cap param) +{ + switch (param) { + case PIPE_CAP_MAX_LINE_WIDTH: + /* fall-through */ + case PIPE_CAP_MAX_LINE_WIDTH_AA: + return 7.5; + + case PIPE_CAP_MAX_POINT_WIDTH: + /* fall-through */ + case PIPE_CAP_MAX_POINT_WIDTH_AA: + return 255.0; + + case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: + return 4.0; + + case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: + return 16.0; + + default: + return 0; + } +} + +static boolean +brw_is_format_supported(struct pipe_screen *screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned tex_usage, + unsigned geom_flags) +{ + static const enum pipe_format tex_supported[] = { + PIPE_FORMAT_L8_UNORM, + PIPE_FORMAT_I8_UNORM, + PIPE_FORMAT_A8_UNORM, + PIPE_FORMAT_L16_UNORM, + /*PIPE_FORMAT_I16_UNORM,*/ + /*PIPE_FORMAT_A16_UNORM,*/ + PIPE_FORMAT_L8A8_UNORM, + PIPE_FORMAT_B5G6R5_UNORM, + PIPE_FORMAT_B5G5R5A1_UNORM, + PIPE_FORMAT_B4G4R4A4_UNORM, + PIPE_FORMAT_B8G8R8X8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + /* video */ + PIPE_FORMAT_UYVY, + PIPE_FORMAT_YUYV, + /* compressed */ + /*PIPE_FORMAT_FXT1_RGBA,*/ + PIPE_FORMAT_DXT1_RGB, + PIPE_FORMAT_DXT1_RGBA, + PIPE_FORMAT_DXT3_RGBA, + PIPE_FORMAT_DXT5_RGBA, + /* sRGB */ + PIPE_FORMAT_A8B8G8R8_SRGB, + PIPE_FORMAT_L8A8_SRGB, + PIPE_FORMAT_L8_SRGB, + PIPE_FORMAT_DXT1_SRGB, + /* depth */ + PIPE_FORMAT_Z32_FLOAT, + PIPE_FORMAT_Z24X8_UNORM, + PIPE_FORMAT_Z24_UNORM_S8_USCALED, + PIPE_FORMAT_Z16_UNORM, + /* signed */ + PIPE_FORMAT_R8G8_SNORM, + PIPE_FORMAT_R8G8B8A8_SNORM, + PIPE_FORMAT_NONE /* list terminator */ + }; + static const enum pipe_format render_supported[] = { + PIPE_FORMAT_B8G8R8X8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_B5G6R5_UNORM, + PIPE_FORMAT_NONE /* list terminator */ + }; + static const enum pipe_format depth_supported[] = { + PIPE_FORMAT_Z32_FLOAT, + PIPE_FORMAT_Z24X8_UNORM, + PIPE_FORMAT_Z24_UNORM_S8_USCALED, + PIPE_FORMAT_Z16_UNORM, + PIPE_FORMAT_NONE /* list terminator */ + }; + const enum pipe_format *list; + uint i; + + if (sample_count > 1) + return FALSE; + + if (tex_usage & PIPE_BIND_DEPTH_STENCIL) + list = depth_supported; + else if (tex_usage & PIPE_BIND_RENDER_TARGET) + list = render_supported; + else + list = tex_supported; + + for (i = 0; list[i] != PIPE_FORMAT_NONE; i++) { + if (list[i] == format) + return TRUE; + } + + return FALSE; +} + + +/* + * Fence functions + */ + + +static void +brw_fence_reference(struct pipe_screen *screen, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ +} + +static int +brw_fence_signalled(struct pipe_screen *screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + return 0; /* XXX shouldn't this be a boolean? */ +} + +static int +brw_fence_finish(struct pipe_screen *screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + return 0; +} + + +/* + * Generic functions + */ + + +static void +brw_destroy_screen(struct pipe_screen *screen) +{ + struct brw_screen *bscreen = brw_screen(screen); + + if (bscreen->sws) + bscreen->sws->destroy(bscreen->sws); + + FREE(bscreen); +} + +/** + * Create a new brw_screen object + */ +struct pipe_screen * +brw_screen_create(struct brw_winsys_screen *sws) +{ + struct brw_screen *bscreen; + struct brw_chipset chipset; + +#ifdef DEBUG + BRW_DEBUG = debug_get_flags_option("BRW_DEBUG", debug_names, 0); + BRW_DEBUG |= debug_get_flags_option("INTEL_DEBUG", debug_names, 0); + BRW_DEBUG |= DEBUG_STATS | DEBUG_MIN_URB | DEBUG_WM; + + BRW_DUMP = debug_get_flags_option("BRW_DUMP", dump_names, 0); +#endif + + memset(&chipset, 0, sizeof chipset); + + chipset.pci_id = sws->pci_id; + + switch (chipset.pci_id) { + case PCI_CHIP_I965_G: + case PCI_CHIP_I965_Q: + case PCI_CHIP_I965_G_1: + case PCI_CHIP_I946_GZ: + case PCI_CHIP_I965_GM: + case PCI_CHIP_I965_GME: + chipset.is_965 = TRUE; + break; + + case PCI_CHIP_GM45_GM: + case PCI_CHIP_IGD_E_G: + case PCI_CHIP_Q45_G: + case PCI_CHIP_G45_G: + case PCI_CHIP_G41_G: + case PCI_CHIP_B43_G: + chipset.is_g4x = TRUE; + break; + + case PCI_CHIP_ILD_G: + case PCI_CHIP_ILM_G: + chipset.is_igdng = TRUE; + break; + + default: + debug_printf("%s: unknown pci id 0x%x, cannot create screen\n", + __FUNCTION__, chipset.pci_id); + return NULL; + } + + + bscreen = CALLOC_STRUCT(brw_screen); + if (!bscreen) + return NULL; + + bscreen->chipset = chipset; + bscreen->sws = sws; + bscreen->base.winsys = NULL; + bscreen->base.destroy = brw_destroy_screen; + bscreen->base.get_name = brw_get_name; + bscreen->base.get_vendor = brw_get_vendor; + bscreen->base.get_param = brw_get_param; + bscreen->base.get_shader_param = brw_get_shader_param; + bscreen->base.get_paramf = brw_get_paramf; + bscreen->base.is_format_supported = brw_is_format_supported; + bscreen->base.context_create = brw_create_context; + bscreen->base.fence_reference = brw_fence_reference; + bscreen->base.fence_signalled = brw_fence_signalled; + bscreen->base.fence_finish = brw_fence_finish; + + brw_init_screen_resource_functions(bscreen); + + bscreen->no_tiling = debug_get_option("BRW_NO_TILING", FALSE) != NULL; + + + return &bscreen->base; +} diff --git a/src/gallium/drivers/i965/brw_screen.h b/src/gallium/drivers/i965/brw_screen.h new file mode 100644 index 0000000..58e293b --- /dev/null +++ b/src/gallium/drivers/i965/brw_screen.h @@ -0,0 +1,100 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef BRW_SCREEN_H +#define BRW_SCREEN_H + +#include "pipe/p_state.h" +#include "pipe/p_screen.h" + +#include "brw_reg.h" +#include "brw_structs.h" + +struct brw_winsys_screen; + + +/** + * Subclass of pipe_screen + */ +struct brw_screen +{ + struct pipe_screen base; + struct brw_chipset chipset; + struct brw_winsys_screen *sws; + boolean no_tiling; +}; + + + +union brw_surface_id { + struct { + unsigned level:16; + unsigned layer:16; + } bits; + unsigned value; +}; + + +struct brw_surface +{ + struct pipe_surface base; + + union brw_surface_id id; + unsigned offset; + unsigned cpp; + unsigned pitch; + unsigned draw_offset; + unsigned tiling; + + struct brw_surface_state ss; + struct brw_winsys_buffer *bo; + struct brw_surface *next, *prev; +}; + + + +/* + * Cast wrappers + */ +static INLINE struct brw_screen * +brw_screen(struct pipe_screen *pscreen) +{ + return (struct brw_screen *) pscreen; +} + + +static INLINE struct brw_surface * +brw_surface(struct pipe_surface *surface) +{ + return (struct brw_surface *)surface; +} + +unsigned +brw_surface_pitch( const struct pipe_surface *surface ); + + +#endif /* BRW_SCREEN_H */ diff --git a/src/gallium/drivers/i965/brw_sf.c b/src/gallium/drivers/i965/brw_sf.c new file mode 100644 index 0000000..5abf384 --- /dev/null +++ b/src/gallium/drivers/i965/brw_sf.c @@ -0,0 +1,216 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "pipe/p_state.h" + +#include "brw_batchbuffer.h" +#include "brw_defines.h" +#include "brw_context.h" +#include "brw_pipe_rast.h" +#include "brw_eu.h" +#include "brw_sf.h" +#include "brw_state.h" + +static enum pipe_error compile_sf_prog( struct brw_context *brw, + struct brw_sf_prog_key *key, + struct brw_winsys_buffer **bo_out ) +{ + enum pipe_error ret; + struct brw_sf_compile c; + const GLuint *program; + GLuint program_size; + + memset(&c, 0, sizeof(c)); + + /* Begin the compilation: + */ + brw_init_compile(brw, &c.func); + + c.key = *key; + c.nr_attrs = c.key.nr_attrs; + c.nr_attr_regs = (c.nr_attrs+1)/2; + c.nr_setup_attrs = c.key.nr_attrs; + c.nr_setup_regs = (c.nr_setup_attrs+1)/2; + + c.prog_data.urb_read_length = c.nr_attr_regs; + c.prog_data.urb_entry_size = c.nr_setup_regs * 2; + + /* Special case when there are no attributes to setup. + * + * XXX: should be able to set nr_setup_attrs to nr_attrs-1 -- but + * breaks vp-tris.c + */ + if (c.nr_attrs - 1 == 0) { + c.nr_verts = 0; + brw_emit_null_setup( &c ); + } + else { + /* Which primitive? Or all three? + */ + switch (key->primitive) { + case SF_TRIANGLES: + c.nr_verts = 3; + brw_emit_tri_setup( &c, GL_TRUE ); + break; + case SF_LINES: + c.nr_verts = 2; + brw_emit_line_setup( &c, GL_TRUE ); + break; + case SF_POINTS: + c.nr_verts = 1; + if (key->do_point_sprite) + brw_emit_point_sprite_setup( &c, GL_TRUE ); + else + brw_emit_point_setup( &c, GL_TRUE ); + break; + case SF_UNFILLED_TRIS: + c.nr_verts = 3; + brw_emit_anyprim_setup( &c ); + break; + default: + assert(0); + return PIPE_ERROR_BAD_INPUT; + } + } + + /* get the program + */ + ret = brw_get_program(&c.func, &program, &program_size); + if (ret) + return ret; + + /* Upload + */ + ret = brw_upload_cache( &brw->cache, BRW_SF_PROG, + &c.key, sizeof(c.key), + NULL, 0, + program, program_size, + &c.prog_data, + &brw->sf.prog_data, + bo_out); + if (ret) + return ret; + + return PIPE_OK; +} + +/* Calculate interpolants for triangle and line rasterization. + */ +static enum pipe_error upload_sf_prog(struct brw_context *brw) +{ + const struct brw_fs_signature *sig = &brw->curr.fragment_shader->signature; + const struct pipe_rasterizer_state *rast = &brw->curr.rast->templ; + struct brw_sf_prog_key key; + enum pipe_error ret; + unsigned i; + + memset(&key, 0, sizeof(key)); + + /* Populate the key, noting state dependencies: + */ + + /* XXX: Add one to account for the position input. + */ + /* PIPE_NEW_FRAGMENT_SIGNATURE */ + key.nr_attrs = sig->nr_inputs + 1; + + + /* XXX: why is position required to be linear? why do we care + * about it at all? + */ + key.linear_attrs = 1; /* position -- but why? */ + + for (i = 0; i < sig->nr_inputs; i++) { + switch (sig->input[i].interp) { + case TGSI_INTERPOLATE_CONSTANT: + break; + case TGSI_INTERPOLATE_LINEAR: + key.linear_attrs |= 1 << (i+1); + break; + case TGSI_INTERPOLATE_PERSPECTIVE: + key.persp_attrs |= 1 << (i+1); + break; + } + } + + /* BRW_NEW_REDUCED_PRIMITIVE */ + switch (brw->reduced_primitive) { + case PIPE_PRIM_TRIANGLES: + /* PIPE_NEW_RAST + */ + if (rast->fill_front != PIPE_POLYGON_MODE_FILL || + rast->fill_back != PIPE_POLYGON_MODE_FILL) + key.primitive = SF_UNFILLED_TRIS; + else + key.primitive = SF_TRIANGLES; + break; + case PIPE_PRIM_LINES: + key.primitive = SF_LINES; + break; + case PIPE_PRIM_POINTS: + key.primitive = SF_POINTS; + break; + } + + key.do_point_sprite = rast->sprite_coord_enable ? 1 : 0; + key.sprite_origin_lower_left = (rast->sprite_coord_mode == PIPE_SPRITE_COORD_LOWER_LEFT); + key.point_coord_replace_attrs = rast->sprite_coord_enable; + key.do_flat_shading = rast->flatshade; + key.do_twoside_color = rast->light_twoside; + + if (key.do_twoside_color) { + key.frontface_ccw = rast->front_ccw; + } + + if (brw_search_cache(&brw->cache, BRW_SF_PROG, + &key, sizeof(key), + NULL, 0, + &brw->sf.prog_data, + &brw->sf.prog_bo)) + return PIPE_OK; + + ret = compile_sf_prog( brw, &key, &brw->sf.prog_bo ); + if (ret) + return ret; + + return PIPE_OK; +} + + +const struct brw_tracked_state brw_sf_prog = { + .dirty = { + .mesa = (PIPE_NEW_RAST | PIPE_NEW_FRAGMENT_SIGNATURE), + .brw = (BRW_NEW_REDUCED_PRIMITIVE), + .cache = 0 + }, + .prepare = upload_sf_prog +}; + diff --git a/src/gallium/drivers/i965/brw_sf.h b/src/gallium/drivers/i965/brw_sf.h new file mode 100644 index 0000000..a895c7d --- /dev/null +++ b/src/gallium/drivers/i965/brw_sf.h @@ -0,0 +1,122 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#ifndef BRW_SF_H +#define BRW_SF_H + + +#include "brw_context.h" +#include "brw_eu.h" + + +#define SF_POINTS 0 +#define SF_LINES 1 +#define SF_TRIANGLES 2 +#define SF_UNFILLED_TRIS 3 + +struct brw_sf_prog_key { + + /* Bitmask of linear and perspective interpolated inputs, 0..nr + */ + GLuint persp_attrs:32; + GLuint linear_attrs:32; + GLuint point_coord_replace_attrs:32; + + GLuint nr_attrs:8; + GLuint primitive:2; + GLuint do_twoside_color:1; + GLuint do_flat_shading:1; + GLuint frontface_ccw:1; + GLuint do_point_sprite:1; + GLuint sprite_origin_lower_left:1; + GLuint pad:17; + + GLuint attr_col0:8; + GLuint attr_col1:8; + GLuint attr_bfc0:8; + GLuint attr_bfc1:8; +}; + +struct brw_sf_point_tex { + GLboolean CoordReplace; +}; + +struct brw_sf_compile { + struct brw_compile func; + struct brw_sf_prog_key key; + struct brw_sf_prog_data prog_data; + + struct brw_reg pv; + struct brw_reg det; + struct brw_reg dx0; + struct brw_reg dx2; + struct brw_reg dy0; + struct brw_reg dy2; + + /* z and 1/w passed in seperately: + */ + struct brw_reg z[3]; + struct brw_reg inv_w[3]; + + /* The vertices: + */ + struct brw_reg vert[3]; + + /* Temporaries, allocated after last vertex reg. + */ + struct brw_reg inv_det; + struct brw_reg a1_sub_a0; + struct brw_reg a2_sub_a0; + struct brw_reg tmp; + + struct brw_reg m1Cx; + struct brw_reg m2Cy; + struct brw_reg m3C0; + + GLuint nr_verts; + GLuint nr_attrs; + GLuint nr_attr_regs; + GLuint nr_setup_attrs; + GLuint nr_setup_regs; + + GLuint point_coord_replace_mask; +}; + + +void brw_emit_null_setup( struct brw_sf_compile *c ); +void brw_emit_tri_setup( struct brw_sf_compile *c, GLboolean allocate ); +void brw_emit_line_setup( struct brw_sf_compile *c, GLboolean allocate ); +void brw_emit_point_setup( struct brw_sf_compile *c, GLboolean allocate ); +void brw_emit_point_sprite_setup( struct brw_sf_compile *c, GLboolean allocate ); +void brw_emit_anyprim_setup( struct brw_sf_compile *c ); + +#endif diff --git a/src/gallium/drivers/i965/brw_sf_emit.c b/src/gallium/drivers/i965/brw_sf_emit.c new file mode 100644 index 0000000..497634e --- /dev/null +++ b/src/gallium/drivers/i965/brw_sf_emit.c @@ -0,0 +1,764 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#include "brw_batchbuffer.h" + +#include "brw_defines.h" +#include "brw_context.h" +#include "brw_eu.h" +#include "brw_sf.h" + + +static struct brw_reg get_vert_attr(struct brw_sf_compile *c, + struct brw_reg vert, + GLuint attr) +{ + GLuint off = attr / 2; + GLuint sub = attr % 2; + + return brw_vec4_grf(vert.nr + off, sub * 4); +} + + +/*********************************************************************** + * Twoside lighting + */ +static void copy_bfc( struct brw_sf_compile *c, + struct brw_reg vert ) +{ + struct brw_compile *p = &c->func; + + if (c->key.attr_col0 && c->key.attr_bfc0) + brw_MOV(p, + get_vert_attr(c, vert, c->key.attr_col0), + get_vert_attr(c, vert, c->key.attr_bfc0)); + + if (c->key.attr_col1 && c->key.attr_bfc1) + brw_MOV(p, + get_vert_attr(c, vert, c->key.attr_col1), + get_vert_attr(c, vert, c->key.attr_bfc1)); +} + + +static void do_twoside_color( struct brw_sf_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_instruction *if_insn; + GLuint backface_conditional = c->key.frontface_ccw ? BRW_CONDITIONAL_G : BRW_CONDITIONAL_L; + + /* Already done in clip program: + */ + if (c->key.primitive == SF_UNFILLED_TRIS) + return; + + /* XXX: What happens if BFC isn't present? This could only happen + * for user-supplied vertex programs, as t_vp_build.c always does + * the right thing. + */ + if (!(c->key.attr_col0 && c->key.attr_bfc0) && + !(c->key.attr_col1 && c->key.attr_bfc1)) + return; + + /* Need to use BRW_EXECUTE_4 and also do an 4-wide compare in order + * to get all channels active inside the IF. In the clipping code + * we run with NoMask, so it's not an option and we can use + * BRW_EXECUTE_1 for all comparisions. + */ + brw_push_insn_state(p); + brw_CMP(p, vec4(brw_null_reg()), backface_conditional, c->det, brw_imm_f(0)); + if_insn = brw_IF(p, BRW_EXECUTE_4); + { + switch (c->nr_verts) { + case 3: copy_bfc(c, c->vert[2]); + case 2: copy_bfc(c, c->vert[1]); + case 1: copy_bfc(c, c->vert[0]); + } + } + brw_ENDIF(p, if_insn); + brw_pop_insn_state(p); +} + + + +/*********************************************************************** + * Flat shading + */ + +#define VERT_RESULT_COLOR_BITS ((1<func; + + if (c->key.attr_col0) + brw_MOV(p, + get_vert_attr(c, dst, c->key.attr_col0), + get_vert_attr(c, src, c->key.attr_col0)); + + if (c->key.attr_col1) + brw_MOV(p, + get_vert_attr(c, dst, c->key.attr_col1), + get_vert_attr(c, src, c->key.attr_col1)); + +} + + + +/* Need to use a computed jump to copy flatshaded attributes as the + * vertices are ordered according to y-coordinate before reaching this + * point, so the PV could be anywhere. + */ +static void do_flatshade_triangle( struct brw_sf_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_reg ip = brw_ip_reg(); + GLuint jmpi = 1; + GLuint nr = 0; + + if (c->key.attr_col0) + nr++; + + if (c->key.attr_col1) + nr++; + + if (nr == 0) + return; + + /* Already done in clip program: + */ + if (c->key.primitive == SF_UNFILLED_TRIS) + return; + + if (BRW_IS_IGDNG(p->brw)) + jmpi = 2; + + brw_push_insn_state(p); + + brw_MUL(p, c->pv, c->pv, brw_imm_d(jmpi*(nr*2+1))); + brw_JMPI(p, ip, ip, c->pv); + + copy_colors(c, c->vert[1], c->vert[0]); + copy_colors(c, c->vert[2], c->vert[0]); + brw_JMPI(p, ip, ip, brw_imm_d(jmpi*(nr*4+1))); + + copy_colors(c, c->vert[0], c->vert[1]); + copy_colors(c, c->vert[2], c->vert[1]); + brw_JMPI(p, ip, ip, brw_imm_d(jmpi*nr*2)); + + copy_colors(c, c->vert[0], c->vert[2]); + copy_colors(c, c->vert[1], c->vert[2]); + + brw_pop_insn_state(p); +} + + +static void do_flatshade_line( struct brw_sf_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_reg ip = brw_ip_reg(); + GLuint jmpi = 1; + GLuint nr = 0; + + if (c->key.attr_col0) + nr++; + + if (c->key.attr_col1) + nr++; + + if (nr == 0) + return; + + /* Already done in clip program: + */ + if (c->key.primitive == SF_UNFILLED_TRIS) + return; + + if (BRW_IS_IGDNG(p->brw)) + jmpi = 2; + + brw_push_insn_state(p); + + brw_MUL(p, c->pv, c->pv, brw_imm_d(jmpi*(nr+1))); + brw_JMPI(p, ip, ip, c->pv); + copy_colors(c, c->vert[1], c->vert[0]); + + brw_JMPI(p, ip, ip, brw_imm_ud(jmpi*nr)); + copy_colors(c, c->vert[0], c->vert[1]); + + brw_pop_insn_state(p); +} + + + +/*********************************************************************** + * Triangle setup. + */ + + +static void alloc_regs( struct brw_sf_compile *c ) +{ + GLuint reg, i; + + /* Values computed by fixed function unit: + */ + c->pv = retype(brw_vec1_grf(1, 1), BRW_REGISTER_TYPE_D); + c->det = brw_vec1_grf(1, 2); + c->dx0 = brw_vec1_grf(1, 3); + c->dx2 = brw_vec1_grf(1, 4); + c->dy0 = brw_vec1_grf(1, 5); + c->dy2 = brw_vec1_grf(1, 6); + + /* z and 1/w passed in seperately: + */ + c->z[0] = brw_vec1_grf(2, 0); + c->inv_w[0] = brw_vec1_grf(2, 1); + c->z[1] = brw_vec1_grf(2, 2); + c->inv_w[1] = brw_vec1_grf(2, 3); + c->z[2] = brw_vec1_grf(2, 4); + c->inv_w[2] = brw_vec1_grf(2, 5); + + /* The vertices: + */ + reg = 3; + for (i = 0; i < c->nr_verts; i++) { + c->vert[i] = brw_vec8_grf(reg, 0); + reg += c->nr_attr_regs; + } + + /* Temporaries, allocated after last vertex reg. + */ + c->inv_det = brw_vec1_grf(reg, 0); reg++; + c->a1_sub_a0 = brw_vec8_grf(reg, 0); reg++; + c->a2_sub_a0 = brw_vec8_grf(reg, 0); reg++; + c->tmp = brw_vec8_grf(reg, 0); reg++; + + /* Note grf allocation: + */ + c->prog_data.total_grf = reg; + + + /* Outputs of this program - interpolation coefficients for + * rasterization: + */ + c->m1Cx = brw_vec8_reg(BRW_MESSAGE_REGISTER_FILE, 1, 0); + c->m2Cy = brw_vec8_reg(BRW_MESSAGE_REGISTER_FILE, 2, 0); + c->m3C0 = brw_vec8_reg(BRW_MESSAGE_REGISTER_FILE, 3, 0); +} + + +static void copy_z_inv_w( struct brw_sf_compile *c ) +{ + struct brw_compile *p = &c->func; + GLuint i; + + brw_push_insn_state(p); + + /* Copy both scalars with a single MOV: + */ + for (i = 0; i < c->nr_verts; i++) + brw_MOV(p, vec2(suboffset(c->vert[i], 2)), vec2(c->z[i])); + + brw_pop_insn_state(p); +} + + +static void invert_det( struct brw_sf_compile *c) +{ + /* Looks like we invert all 8 elements just to get 1/det in + * position 2 !?! + */ + brw_math(&c->func, + c->inv_det, + BRW_MATH_FUNCTION_INV, + BRW_MATH_SATURATE_NONE, + 0, + c->det, + BRW_MATH_DATA_SCALAR, + BRW_MATH_PRECISION_FULL); + +} + + +/* Two attributes packed into a wide register. Figure out if either + * or both of them need linear/perspective interpolation. Constant + * regs are left as-is. + */ +static GLboolean calculate_masks( struct brw_sf_compile *c, + GLuint reg, + GLushort *pc, + GLushort *pc_persp, + GLushort *pc_linear) +{ + GLboolean is_last_attr = (reg == c->nr_setup_regs - 1); + GLuint persp_mask = c->key.persp_attrs; + GLuint linear_mask = (c->key.persp_attrs | c->key.linear_attrs); + + *pc_persp = 0; + *pc_linear = 0; + *pc = 0xf; + + if (persp_mask & (1 << (reg*2))) + *pc_persp = 0xf; + + if (linear_mask & (1 << (reg*2))) + *pc_linear = 0xf; + + /* Maybe only processs one attribute on the final round: + */ + if (reg*2+1 < c->nr_setup_attrs) { + *pc |= 0xf0; + + if (persp_mask & (1 << (reg*2+1))) + *pc_persp |= 0xf0; + + if (linear_mask & (1 << (reg*2+1))) + *pc_linear |= 0xf0; + } + + return is_last_attr; +} + + +void brw_emit_null_setup( struct brw_sf_compile *c ) +{ + struct brw_compile *p = &c->func; + + /* m0 is implicitly copied from r0 in the send instruction: + */ + brw_urb_WRITE(p, + brw_null_reg(), + 0, + brw_vec8_grf(0, 0), /* r0, will be copied to m0 */ + 0, /* allocate */ + 1, /* used */ + 1, /* msg len */ + 0, /* response len */ + 1, /* eot */ + 1, /* writes complete */ + 0, /* offset */ + BRW_URB_SWIZZLE_TRANSPOSE); +} + +void brw_emit_tri_setup( struct brw_sf_compile *c, GLboolean allocate) +{ + struct brw_compile *p = &c->func; + GLuint i; + + c->nr_verts = 3; + + if (allocate) + alloc_regs(c); + + invert_det(c); + copy_z_inv_w(c); + + if (c->key.do_twoside_color) + do_twoside_color(c); + + if (c->key.do_flat_shading) + do_flatshade_triangle(c); + + + for (i = 0; i < c->nr_setup_regs; i++) + { + /* Pair of incoming attributes: + */ + struct brw_reg a0 = offset(c->vert[0], i); + struct brw_reg a1 = offset(c->vert[1], i); + struct brw_reg a2 = offset(c->vert[2], i); + GLushort pc, pc_persp, pc_linear; + GLboolean last = calculate_masks(c, i, &pc, &pc_persp, &pc_linear); + + if (pc_persp) + { + brw_set_predicate_control_flag_value(p, pc_persp); + brw_MUL(p, a0, a0, c->inv_w[0]); + brw_MUL(p, a1, a1, c->inv_w[1]); + brw_MUL(p, a2, a2, c->inv_w[2]); + } + + + /* Calculate coefficients for interpolated values: + */ + if (pc_linear) + { + brw_set_predicate_control_flag_value(p, pc_linear); + + brw_ADD(p, c->a1_sub_a0, a1, negate(a0)); + brw_ADD(p, c->a2_sub_a0, a2, negate(a0)); + + /* calculate dA/dx + */ + brw_MUL(p, brw_null_reg(), c->a1_sub_a0, c->dy2); + brw_MAC(p, c->tmp, c->a2_sub_a0, negate(c->dy0)); + brw_MUL(p, c->m1Cx, c->tmp, c->inv_det); + + /* calculate dA/dy + */ + brw_MUL(p, brw_null_reg(), c->a2_sub_a0, c->dx0); + brw_MAC(p, c->tmp, c->a1_sub_a0, negate(c->dx2)); + brw_MUL(p, c->m2Cy, c->tmp, c->inv_det); + } + + { + brw_set_predicate_control_flag_value(p, pc); + /* start point for interpolation + */ + brw_MOV(p, c->m3C0, a0); + + /* Copy m0..m3 to URB. m0 is implicitly copied from r0 in + * the send instruction: + */ + brw_urb_WRITE(p, + brw_null_reg(), + 0, + brw_vec8_grf(0, 0), /* r0, will be copied to m0 */ + 0, /* allocate */ + 1, /* used */ + 4, /* msg len */ + 0, /* response len */ + last, /* eot */ + last, /* writes complete */ + i*4, /* offset */ + BRW_URB_SWIZZLE_TRANSPOSE); /* XXX: Swizzle control "SF to windower" */ + } + } +} + + + +void brw_emit_line_setup( struct brw_sf_compile *c, GLboolean allocate) +{ + struct brw_compile *p = &c->func; + GLuint i; + + + c->nr_verts = 2; + + if (allocate) + alloc_regs(c); + + invert_det(c); + copy_z_inv_w(c); + + if (c->key.do_flat_shading) + do_flatshade_line(c); + + for (i = 0; i < c->nr_setup_regs; i++) + { + /* Pair of incoming attributes: + */ + struct brw_reg a0 = offset(c->vert[0], i); + struct brw_reg a1 = offset(c->vert[1], i); + GLushort pc, pc_persp, pc_linear; + GLboolean last = calculate_masks(c, i, &pc, &pc_persp, &pc_linear); + + if (pc_persp) + { + brw_set_predicate_control_flag_value(p, pc_persp); + brw_MUL(p, a0, a0, c->inv_w[0]); + brw_MUL(p, a1, a1, c->inv_w[1]); + } + + /* Calculate coefficients for position, color: + */ + if (pc_linear) { + brw_set_predicate_control_flag_value(p, pc_linear); + + brw_ADD(p, c->a1_sub_a0, a1, negate(a0)); + + brw_MUL(p, c->tmp, c->a1_sub_a0, c->dx0); + brw_MUL(p, c->m1Cx, c->tmp, c->inv_det); + + brw_MUL(p, c->tmp, c->a1_sub_a0, c->dy0); + brw_MUL(p, c->m2Cy, c->tmp, c->inv_det); + } + + { + brw_set_predicate_control_flag_value(p, pc); + + /* start point for interpolation + */ + brw_MOV(p, c->m3C0, a0); + + /* Copy m0..m3 to URB. + */ + brw_urb_WRITE(p, + brw_null_reg(), + 0, + brw_vec8_grf(0, 0), + 0, /* allocate */ + 1, /* used */ + 4, /* msg len */ + 0, /* response len */ + last, /* eot */ + last, /* writes complete */ + i*4, /* urb destination offset */ + BRW_URB_SWIZZLE_TRANSPOSE); + } + } +} + +void brw_emit_point_sprite_setup( struct brw_sf_compile *c, GLboolean allocate) +{ + struct brw_compile *p = &c->func; + GLuint i; + + c->nr_verts = 1; + + if (allocate) + alloc_regs(c); + + copy_z_inv_w(c); + + for (i = 0; i < c->nr_setup_regs; i++) + { + /* XXX: only seems to check point_coord_replace_attrs for every + * second attribute?!? + */ + boolean coord_replace = !!(c->key.point_coord_replace_attrs & (1<<(2*i))); + struct brw_reg a0 = offset(c->vert[0], i); + GLushort pc, pc_persp, pc_linear; + GLboolean last = calculate_masks(c, i, &pc, &pc_persp, &pc_linear); + + if (pc_persp) + { + if (coord_replace) { + brw_set_predicate_control_flag_value(p, pc_persp); + brw_MUL(p, a0, a0, c->inv_w[0]); + } + } + + if (coord_replace) { + /* Caculate 1.0/PointWidth */ + brw_math(&c->func, + c->tmp, + BRW_MATH_FUNCTION_INV, + BRW_MATH_SATURATE_NONE, + 0, + c->dx0, + BRW_MATH_DATA_SCALAR, + BRW_MATH_PRECISION_FULL); + + if (c->key.sprite_origin_lower_left) { + brw_MUL(p, c->m1Cx, c->tmp, c->inv_w[0]); + brw_MOV(p, vec1(suboffset(c->m1Cx, 1)), brw_imm_f(0.0)); + brw_MUL(p, c->m2Cy, c->tmp, negate(c->inv_w[0])); + brw_MOV(p, vec1(suboffset(c->m2Cy, 0)), brw_imm_f(0.0)); + } + else { + brw_MUL(p, c->m1Cx, c->tmp, c->inv_w[0]); + brw_MOV(p, vec1(suboffset(c->m1Cx, 1)), brw_imm_f(0.0)); + brw_MUL(p, c->m2Cy, c->tmp, c->inv_w[0]); + brw_MOV(p, vec1(suboffset(c->m2Cy, 0)), brw_imm_f(0.0)); + } + } + else { + brw_MOV(p, c->m1Cx, brw_imm_ud(0)); + brw_MOV(p, c->m2Cy, brw_imm_ud(0)); + } + + { + brw_set_predicate_control_flag_value(p, pc); + if (coord_replace) { + if (c->key.sprite_origin_lower_left) { + brw_MUL(p, c->m3C0, c->inv_w[0], brw_imm_f(1.0)); + brw_MOV(p, vec1(suboffset(c->m3C0, 0)), brw_imm_f(0.0)); + } + else { + brw_MOV(p, c->m3C0, brw_imm_f(0.0)); + } + } + else { + brw_MOV(p, c->m3C0, a0); /* constant value */ + } + + /* Copy m0..m3 to URB. + */ + brw_urb_WRITE(p, + brw_null_reg(), + 0, + brw_vec8_grf(0, 0), + 0, /* allocate */ + 1, /* used */ + 4, /* msg len */ + 0, /* response len */ + last, /* eot */ + last, /* writes complete */ + i*4, /* urb destination offset */ + BRW_URB_SWIZZLE_TRANSPOSE); + } + } +} + +/* Points setup - several simplifications as all attributes are + * constant across the face of the point (point sprites excluded!) + */ +void brw_emit_point_setup( struct brw_sf_compile *c, GLboolean allocate) +{ + struct brw_compile *p = &c->func; + GLuint i; + + c->nr_verts = 1; + + if (allocate) + alloc_regs(c); + + copy_z_inv_w(c); + + brw_MOV(p, c->m1Cx, brw_imm_ud(0)); /* zero - move out of loop */ + brw_MOV(p, c->m2Cy, brw_imm_ud(0)); /* zero - move out of loop */ + + for (i = 0; i < c->nr_setup_regs; i++) + { + struct brw_reg a0 = offset(c->vert[0], i); + GLushort pc, pc_persp, pc_linear; + GLboolean last = calculate_masks(c, i, &pc, &pc_persp, &pc_linear); + + if (pc_persp) + { + /* This seems odd as the values are all constant, but the + * fragment shader will be expecting it: + */ + brw_set_predicate_control_flag_value(p, pc_persp); + brw_MUL(p, a0, a0, c->inv_w[0]); + } + + + /* The delta values are always zero, just send the starting + * coordinate. Again, this is to fit in with the interpolation + * code in the fragment shader. + */ + { + brw_set_predicate_control_flag_value(p, pc); + + brw_MOV(p, c->m3C0, a0); /* constant value */ + + /* Copy m0..m3 to URB. + */ + brw_urb_WRITE(p, + brw_null_reg(), + 0, + brw_vec8_grf(0, 0), + 0, /* allocate */ + 1, /* used */ + 4, /* msg len */ + 0, /* response len */ + last, /* eot */ + last, /* writes complete */ + i*4, /* urb destination offset */ + BRW_URB_SWIZZLE_TRANSPOSE); + } + } +} + +void brw_emit_anyprim_setup( struct brw_sf_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_reg ip = brw_ip_reg(); + struct brw_reg payload_prim = brw_uw1_reg(BRW_GENERAL_REGISTER_FILE, 1, 0); + struct brw_reg payload_attr = get_element_ud(brw_vec1_reg(BRW_GENERAL_REGISTER_FILE, 1, 0), 0); + struct brw_reg primmask; + struct brw_instruction *jmp; + struct brw_reg v1_null_ud = vec1(retype(brw_null_reg(), BRW_REGISTER_TYPE_UD)); + + GLuint saveflag; + + c->nr_verts = 3; + alloc_regs(c); + + primmask = retype(get_element(c->tmp, 0), BRW_REGISTER_TYPE_UD); + + brw_MOV(p, primmask, brw_imm_ud(1)); + brw_SHL(p, primmask, primmask, payload_prim); + + brw_set_conditionalmod(p, BRW_CONDITIONAL_Z); + brw_AND(p, v1_null_ud, primmask, brw_imm_ud((1<<_3DPRIM_TRILIST) | + (1<<_3DPRIM_TRISTRIP) | + (1<<_3DPRIM_TRIFAN) | + (1<<_3DPRIM_TRISTRIP_REVERSE) | + (1<<_3DPRIM_POLYGON) | + (1<<_3DPRIM_RECTLIST) | + (1<<_3DPRIM_TRIFAN_NOSTIPPLE))); + jmp = brw_JMPI(p, ip, ip, brw_imm_d(0)); + { + saveflag = p->flag_value; + brw_push_insn_state(p); + brw_emit_tri_setup( c, GL_FALSE ); + brw_pop_insn_state(p); + p->flag_value = saveflag; + /* note - thread killed in subroutine, so must + * restore the flag which is changed when building + * the subroutine. fix #13240 + */ + } + brw_land_fwd_jump(p, jmp); + + brw_set_conditionalmod(p, BRW_CONDITIONAL_Z); + brw_AND(p, v1_null_ud, primmask, brw_imm_ud((1<<_3DPRIM_LINELIST) | + (1<<_3DPRIM_LINESTRIP) | + (1<<_3DPRIM_LINELOOP) | + (1<<_3DPRIM_LINESTRIP_CONT) | + (1<<_3DPRIM_LINESTRIP_BF) | + (1<<_3DPRIM_LINESTRIP_CONT_BF))); + jmp = brw_JMPI(p, ip, ip, brw_imm_d(0)); + { + saveflag = p->flag_value; + brw_push_insn_state(p); + brw_emit_line_setup( c, GL_FALSE ); + brw_pop_insn_state(p); + p->flag_value = saveflag; + /* note - thread killed in subroutine */ + } + brw_land_fwd_jump(p, jmp); + + brw_set_conditionalmod(p, BRW_CONDITIONAL_Z); + brw_AND(p, v1_null_ud, payload_attr, brw_imm_ud(1<flag_value; + brw_push_insn_state(p); + brw_emit_point_sprite_setup( c, GL_FALSE ); + brw_pop_insn_state(p); + p->flag_value = saveflag; + } + brw_land_fwd_jump(p, jmp); + + brw_emit_point_setup( c, GL_FALSE ); +} + + + + diff --git a/src/gallium/drivers/i965/brw_sf_state.c b/src/gallium/drivers/i965/brw_sf_state.c new file mode 100644 index 0000000..6c299a8 --- /dev/null +++ b/src/gallium/drivers/i965/brw_sf_state.c @@ -0,0 +1,331 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_math.h" + +#include "pipe/p_state.h" + +#include "brw_context.h" +#include "brw_state.h" +#include "brw_defines.h" +#include "brw_debug.h" +#include "brw_pipe_rast.h" + +static enum pipe_error upload_sf_vp(struct brw_context *brw) +{ + const struct pipe_viewport_state *vp = &brw->curr.viewport; + const struct pipe_scissor_state *scissor = &brw->curr.scissor; + struct brw_sf_viewport sfv; + enum pipe_error ret; + + memset(&sfv, 0, sizeof(sfv)); + + /* PIPE_NEW_VIEWPORT, PIPE_NEW_SCISSOR */ + + sfv.viewport.m00 = vp->scale[0]; + sfv.viewport.m11 = vp->scale[1]; + sfv.viewport.m22 = vp->scale[2]; + sfv.viewport.m30 = vp->translate[0]; + sfv.viewport.m31 = vp->translate[1]; + sfv.viewport.m32 = vp->translate[2]; + + sfv.scissor.xmin = scissor->minx; + sfv.scissor.xmax = scissor->maxx - 1; /* ? */ + sfv.scissor.ymin = scissor->miny; + sfv.scissor.ymax = scissor->maxy - 1; /* ? */ + + ret = brw_cache_data( &brw->cache, BRW_SF_VP, &sfv, NULL, 0, + &brw->sf.vp_bo ); + if (ret) + return ret; + + return PIPE_OK; +} + +const struct brw_tracked_state brw_sf_vp = { + .dirty = { + .mesa = (PIPE_NEW_VIEWPORT | + PIPE_NEW_SCISSOR), + .brw = 0, + .cache = 0 + }, + .prepare = upload_sf_vp +}; + +struct brw_sf_unit_key { + unsigned int total_grf; + unsigned int urb_entry_read_length; + unsigned int nr_urb_entries, urb_size, sfsize; + + unsigned scissor:1; + unsigned line_smooth:1; + unsigned point_sprite:1; + unsigned point_attenuated:1; + unsigned front_ccw:1; + unsigned cull_face:2; + unsigned flatshade_first:1; + unsigned gl_rasterization_rules:1; + unsigned line_last_pixel_enable:1; + float line_width; + float point_size; +}; + +static void +sf_unit_populate_key(struct brw_context *brw, struct brw_sf_unit_key *key) +{ + const struct pipe_rasterizer_state *rast = &brw->curr.rast->templ; + memset(key, 0, sizeof(*key)); + + /* CACHE_NEW_SF_PROG */ + key->total_grf = brw->sf.prog_data->total_grf; + key->urb_entry_read_length = brw->sf.prog_data->urb_read_length; + + /* BRW_NEW_URB_FENCE */ + key->nr_urb_entries = brw->urb.nr_sf_entries; + key->urb_size = brw->urb.vsize; + key->sfsize = brw->urb.sfsize; + + /* PIPE_NEW_RAST */ + key->scissor = rast->scissor; + key->front_ccw = rast->front_ccw; + key->cull_face = rast->cull_face; + key->line_smooth = rast->line_smooth; + key->line_width = rast->line_width; + key->flatshade_first = rast->flatshade_first; + key->line_last_pixel_enable = rast->line_last_pixel; + key->gl_rasterization_rules = rast->gl_rasterization_rules; + + key->point_sprite = rast->sprite_coord_enable ? 1 : 0; + key->point_attenuated = rast->point_size_per_vertex; + + key->point_size = rast->point_size; +} + +static enum pipe_error +sf_unit_create_from_key(struct brw_context *brw, + struct brw_sf_unit_key *key, + struct brw_winsys_reloc *reloc, + struct brw_winsys_buffer **bo_out) +{ + struct brw_sf_unit_state sf; + enum pipe_error ret; + int chipset_max_threads; + memset(&sf, 0, sizeof(sf)); + + sf.thread0.grf_reg_count = align(key->total_grf, 16) / 16 - 1; + /* reloc */ + sf.thread0.kernel_start_pointer = 0; + + sf.thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754; + + sf.thread3.dispatch_grf_start_reg = 3; + + if (BRW_IS_IGDNG(brw)) + sf.thread3.urb_entry_read_offset = 3; + else + sf.thread3.urb_entry_read_offset = 1; + + sf.thread3.urb_entry_read_length = key->urb_entry_read_length; + + sf.thread4.nr_urb_entries = key->nr_urb_entries; + sf.thread4.urb_entry_allocation_size = key->sfsize - 1; + + /* Each SF thread produces 1 PUE, and there can be up to 24(Pre-IGDNG) or + * 48(IGDNG) threads + */ + if (BRW_IS_IGDNG(brw)) + chipset_max_threads = 48; + else + chipset_max_threads = 24; + + sf.thread4.max_threads = MIN2(chipset_max_threads, key->nr_urb_entries) - 1; + + if (BRW_DEBUG & DEBUG_SINGLE_THREAD) + sf.thread4.max_threads = 0; + + if (BRW_DEBUG & DEBUG_STATS) + sf.thread4.stats_enable = 1; + + /* CACHE_NEW_SF_VP */ + /* reloc */ + sf.sf5.sf_viewport_state_offset = 0; + + sf.sf5.viewport_transform = 1; + + if (key->scissor) + sf.sf6.scissor = 1; + + if (key->front_ccw) + sf.sf5.front_winding = BRW_FRONTWINDING_CCW; + else + sf.sf5.front_winding = BRW_FRONTWINDING_CW; + + switch (key->cull_face) { + case PIPE_FACE_FRONT: + sf.sf6.cull_mode = BRW_CULLMODE_FRONT; + break; + case PIPE_FACE_BACK: + sf.sf6.cull_mode = BRW_CULLMODE_BACK; + break; + case PIPE_FACE_FRONT_AND_BACK: + sf.sf6.cull_mode = BRW_CULLMODE_BOTH; + break; + case PIPE_FACE_NONE: + sf.sf6.cull_mode = BRW_CULLMODE_NONE; + break; + default: + assert(0); + sf.sf6.cull_mode = BRW_CULLMODE_NONE; + break; + } + + /* _NEW_LINE */ + /* XXX use ctx->Const.Min/MaxLineWidth here */ + sf.sf6.line_width = CLAMP(key->line_width, 1.0, 5.0) * (1<<1); + + sf.sf6.line_endcap_aa_region_width = 1; + if (key->line_smooth) + sf.sf6.aa_enable = 1; + else if (sf.sf6.line_width <= 0x2) + sf.sf6.line_width = 0; + + /* XXX: gl_rasterization_rules? something else? + */ + sf.sf6.point_rast_rule = BRW_RASTRULE_UPPER_RIGHT; + sf.sf6.point_rast_rule = BRW_RASTRULE_LOWER_RIGHT; + sf.sf6.point_rast_rule = 1; + + /* XXX clamp max depends on AA vs. non-AA */ + + /* _NEW_POINT */ + sf.sf7.sprite_point = key->point_sprite; + sf.sf7.point_size = CLAMP(rint(key->point_size), 1, 255) * (1<<3); + sf.sf7.use_point_size_state = !key->point_attenuated; + sf.sf7.aa_line_distance_mode = 0; + + /* might be BRW_NEW_PRIMITIVE if we have to adjust pv for polygons: + */ + if (!key->flatshade_first) { + sf.sf7.trifan_pv = 2; + sf.sf7.linestrip_pv = 1; + sf.sf7.tristrip_pv = 2; + } else { + sf.sf7.trifan_pv = 1; + sf.sf7.linestrip_pv = 0; + sf.sf7.tristrip_pv = 0; + } + + sf.sf7.line_last_pixel_enable = key->line_last_pixel_enable; + + /* Set bias for OpenGL rasterization rules: + */ + if (key->gl_rasterization_rules) { + sf.sf6.dest_org_vbias = 0x8; + sf.sf6.dest_org_hbias = 0x8; + } + else { + sf.sf6.dest_org_vbias = 0x0; + sf.sf6.dest_org_hbias = 0x0; + } + + ret = brw_upload_cache(&brw->cache, BRW_SF_UNIT, + key, sizeof(*key), + reloc, 2, + &sf, sizeof(sf), + NULL, NULL, + bo_out); + if (ret) + return ret; + + + return PIPE_OK; +} + +static enum pipe_error upload_sf_unit( struct brw_context *brw ) +{ + struct brw_sf_unit_key key; + struct brw_winsys_reloc reloc[2]; + unsigned total_grf; + unsigned viewport_transform; + unsigned front_winding; + enum pipe_error ret; + + sf_unit_populate_key(brw, &key); + + /* XXX: cut this crap and pre calculate the key: + */ + total_grf = (align(key.total_grf, 16) / 16 - 1); + viewport_transform = 1; + front_winding = (key.front_ccw ? + BRW_FRONTWINDING_CCW : + BRW_FRONTWINDING_CW); + + /* Emit SF program relocation */ + make_reloc(&reloc[0], + BRW_USAGE_STATE, + total_grf << 1, + offsetof(struct brw_sf_unit_state, thread0), + brw->sf.prog_bo); + + /* Emit SF viewport relocation */ + make_reloc(&reloc[1], + BRW_USAGE_STATE, + front_winding | (viewport_transform << 1), + offsetof(struct brw_sf_unit_state, sf5), + brw->sf.vp_bo); + + + if (brw_search_cache(&brw->cache, BRW_SF_UNIT, + &key, sizeof(key), + reloc, 2, + NULL, + &brw->sf.state_bo)) + return PIPE_OK; + + + ret = sf_unit_create_from_key(brw, &key, + reloc, + &brw->sf.state_bo); + if (ret) + return ret; + + return PIPE_OK; +} + +const struct brw_tracked_state brw_sf_unit = { + .dirty = { + .mesa = (PIPE_NEW_RAST), + .brw = BRW_NEW_URB_FENCE, + .cache = (CACHE_NEW_SF_VP | + CACHE_NEW_SF_PROG) + }, + .prepare = upload_sf_unit, +}; diff --git a/src/gallium/drivers/i965/brw_state.h b/src/gallium/drivers/i965/brw_state.h new file mode 100644 index 0000000..d2bbd01 --- /dev/null +++ b/src/gallium/drivers/i965/brw_state.h @@ -0,0 +1,174 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#ifndef BRW_STATE_H +#define BRW_STATE_H + +#include "pipe/p_defines.h" +#include "util/u_memory.h" + +#include "brw_context.h" + +static INLINE void +brw_add_validated_bo(struct brw_context *brw, struct brw_winsys_buffer *bo) +{ + assert(brw->state.validated_bo_count < Elements(brw->state.validated_bos)); + + if (bo != NULL) { + bo_reference( &brw->state.validated_bos[brw->state.validated_bo_count++], + bo ); + } +} + +const struct brw_tracked_state brw_blend_constant_color; +const struct brw_tracked_state brw_cc_unit; +const struct brw_tracked_state brw_cc_vp; +const struct brw_tracked_state brw_clip_prog; +const struct brw_tracked_state brw_clip_unit; +const struct brw_tracked_state brw_curbe_buffer; +const struct brw_tracked_state brw_curbe_offsets; +const struct brw_tracked_state brw_invarient_state; +const struct brw_tracked_state brw_gs_prog; +const struct brw_tracked_state brw_gs_unit; +const struct brw_tracked_state brw_line_stipple; +const struct brw_tracked_state brw_aa_line_parameters; +const struct brw_tracked_state brw_pipelined_state_pointers; +const struct brw_tracked_state brw_binding_table_pointers; +const struct brw_tracked_state brw_depthbuffer; +const struct brw_tracked_state brw_polygon_stipple; +const struct brw_tracked_state brw_program_parameters; +const struct brw_tracked_state brw_recalculate_urb_fence; +const struct brw_tracked_state brw_sf_prog; +const struct brw_tracked_state brw_sf_unit; +const struct brw_tracked_state brw_sf_vp; +const struct brw_tracked_state brw_state_base_address; +const struct brw_tracked_state brw_urb_fence; +const struct brw_tracked_state brw_vertex_state; +const struct brw_tracked_state brw_vs_surfaces; +const struct brw_tracked_state brw_vs_prog; +const struct brw_tracked_state brw_vs_unit; +const struct brw_tracked_state brw_wm_input_sizes; +const struct brw_tracked_state brw_wm_prog; +const struct brw_tracked_state brw_wm_samplers; +const struct brw_tracked_state brw_wm_constant_surface; +const struct brw_tracked_state brw_wm_surfaces; +const struct brw_tracked_state brw_wm_unit; + +const struct brw_tracked_state brw_psp_urb_cbs; + +const struct brw_tracked_state brw_pipe_control; + +const struct brw_tracked_state brw_drawing_rect; +const struct brw_tracked_state brw_indices; +const struct brw_tracked_state brw_vertices; +const struct brw_tracked_state brw_index_buffer; + + +/*********************************************************************** + * brw_state.c + */ +int brw_validate_state(struct brw_context *brw); +int brw_upload_state(struct brw_context *brw); +void brw_init_state(struct brw_context *brw); +void brw_destroy_state(struct brw_context *brw); + +/*********************************************************************** + * brw_state_cache.c + */ +enum pipe_error brw_cache_data(struct brw_cache *cache, + enum brw_cache_id cache_id, + const void *data, + struct brw_winsys_reloc *relocs, + GLuint nr_relocs, + struct brw_winsys_buffer **bo_out ); + +enum pipe_error brw_cache_data_sz(struct brw_cache *cache, + enum brw_cache_id cache_id, + const void *data, + GLuint data_size, + struct brw_winsys_reloc *relocs, + GLuint nr_relocs, + struct brw_winsys_buffer **bo_out); + +enum pipe_error brw_upload_cache( struct brw_cache *cache, + enum brw_cache_id cache_id, + const void *key, + GLuint key_sz, + struct brw_winsys_reloc *relocs, + GLuint nr_relocs, + const void *data, + GLuint data_sz, + const void *aux, + void *aux_return , + struct brw_winsys_buffer **bo_out); + +boolean brw_search_cache( struct brw_cache *cache, + enum brw_cache_id cache_id, + const void *key, + GLuint key_size, + struct brw_winsys_reloc *relocs, + GLuint nr_relocs, + void *aux_return, + struct brw_winsys_buffer **bo_out); + +void brw_state_cache_check_size( struct brw_context *brw ); + +void brw_init_caches( struct brw_context *brw ); +void brw_destroy_caches( struct brw_context *brw ); +void brw_state_cache_bo_delete(struct brw_cache *cache, struct brw_winsys_buffer *bo); + +/*********************************************************************** + * brw_state_batch.c + */ +#define BRW_BATCH_STRUCT(brw, s) brw_batchbuffer_data( brw->batch, (s), sizeof(*(s)), IGNORE_CLIPRECTS) +#define BRW_CACHED_BATCH_STRUCT(brw, s) brw_cached_batch_struct( brw, (s), sizeof(*(s)) ) + +GLboolean brw_cached_batch_struct( struct brw_context *brw, + const void *data, + GLuint sz ); +void brw_destroy_batch_cache( struct brw_context *brw ); +void brw_clear_batch_cache( struct brw_context *brw ); + +/*********************************************************************** + * brw_wm_surface_state.c + */ + +/*********************************************************************** + * brw_state_debug.c + */ +void brw_update_dirty_counts( unsigned mesa, + unsigned brw, + unsigned cache ); + + + +#endif diff --git a/src/gallium/drivers/i965/brw_state_batch.c b/src/gallium/drivers/i965/brw_state_batch.c new file mode 100644 index 0000000..ce5ed0a --- /dev/null +++ b/src/gallium/drivers/i965/brw_state_batch.c @@ -0,0 +1,98 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + + +#include "brw_state.h" +#include "brw_batchbuffer.h" + + + +/* A facility similar to the data caching code above, which aims to + * prevent identical commands being issued repeatedly. + */ +GLboolean brw_cached_batch_struct( struct brw_context *brw, + const void *data, + GLuint sz ) +{ + struct brw_cached_batch_item *item = brw->cached_batch_items; + struct header *newheader = (struct header *)data; + + if (brw->flags.always_emit_state) { + brw_batchbuffer_data(brw->batch, data, sz, IGNORE_CLIPRECTS); + return GL_TRUE; + } + + while (item) { + if (item->header->opcode == newheader->opcode) { + if (item->sz == sz && memcmp(item->header, newheader, sz) == 0) + return GL_FALSE; + if (item->sz != sz) { + FREE(item->header); + item->header = MALLOC(sz); + item->sz = sz; + } + goto emit; + } + item = item->next; + } + + assert(!item); + item = CALLOC_STRUCT(brw_cached_batch_item); + item->header = MALLOC(sz); + item->sz = sz; + item->next = brw->cached_batch_items; + brw->cached_batch_items = item; + + emit: + memcpy(item->header, newheader, sz); + brw_batchbuffer_data(brw->batch, data, sz, IGNORE_CLIPRECTS); + return GL_TRUE; +} + +void brw_clear_batch_cache( struct brw_context *brw ) +{ + struct brw_cached_batch_item *item = brw->cached_batch_items; + + while (item) { + struct brw_cached_batch_item *next = item->next; + FREE((void *)item->header); + FREE(item); + item = next; + } + + brw->cached_batch_items = NULL; +} + +void brw_destroy_batch_cache( struct brw_context *brw ) +{ + brw_clear_batch_cache(brw); +} diff --git a/src/gallium/drivers/i965/brw_state_cache.c b/src/gallium/drivers/i965/brw_state_cache.c new file mode 100644 index 0000000..c911f39 --- /dev/null +++ b/src/gallium/drivers/i965/brw_state_cache.c @@ -0,0 +1,617 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +/** @file brw_state_cache.c + * + * This file implements a simple static state cache for 965. The consumers + * can query the hash table of state using a cache_id, opaque key data, + * and list of buffers that will be used in relocations, and receive the + * corresponding state buffer object of state (plus associated auxiliary + * data) in return. + * + * The inner workings are a simple hash table based on a CRC of the key data. + * The cache_id and relocation target buffers associated with the state + * buffer are included as auxiliary key data, but are not part of the hash + * value (this should be fixed, but will likely be fixed instead by making + * consumers use structured keys). + * + * Replacement is not implemented. Instead, when the cache gets too big, at + * a safe point (unlock) we throw out all of the cache data and let it + * regenerate for the next rendering operation. + * + * The reloc structs need to be included as key data, otherwise the + * non-unique values stuffed in the offset in key data through + * brw_cache_data() may result in successful probe for state buffers + * even when the buffer being referenced doesn't match. The result would be + * that the same state cache entry is used twice for different buffers, + * only one of the two buffers referenced gets put into the offset, and the + * incorrect program is run for the other instance. + */ +#include "util/u_memory.h" + +#include "brw_debug.h" +#include "brw_state.h" + +/* XXX: Fixme - have to include these to get the sizes of the prog_key + * structs: + */ +#include "brw_wm.h" +#include "brw_vs.h" +#include "brw_clip.h" +#include "brw_sf.h" +#include "brw_gs.h" + + +static GLuint +hash_key(const void *key, GLuint key_size, + struct brw_winsys_reloc *relocs, GLuint nr_relocs) +{ + GLuint *ikey = (GLuint *)key; + GLuint hash = 0, i; + + assert(key_size % 4 == 0); + + /* I'm sure this can be improved on: + */ + for (i = 0; i < key_size/4; i++) { + hash ^= ikey[i]; + hash = (hash << 5) | (hash >> 27); + } + + /* Include the BO pointers as key data as well */ + ikey = (GLuint *)relocs; + key_size = nr_relocs * sizeof(struct brw_winsys_reloc); + for (i = 0; i < key_size/4; i++) { + hash ^= ikey[i]; + hash = (hash << 5) | (hash >> 27); + } + + return hash; +} + + +/** + * Marks a new buffer as being chosen for the given cache id. + */ +static void +update_cache_last(struct brw_cache *cache, enum brw_cache_id cache_id, + struct brw_winsys_buffer *bo) +{ + if (bo == cache->last_bo[cache_id]) + return; /* no change */ + + bo_reference( &cache->last_bo[cache_id], bo ); + + cache->brw->state.dirty.cache |= 1 << cache_id; +} + + +static struct brw_cache_item * +search_cache(struct brw_cache *cache, enum brw_cache_id cache_id, + GLuint hash, const void *key, GLuint key_size, + struct brw_winsys_reloc *relocs, GLuint nr_relocs) +{ + struct brw_cache_item *c; + +#if 0 + int bucketcount = 0; + + for (c = cache->items[hash % cache->size]; c; c = c->next) + bucketcount++; + + debug_printf("bucket %d/%d = %d/%d items\n", hash % cache->size, + cache->size, bucketcount, cache->n_items); +#endif + + for (c = cache->items[hash % cache->size]; c; c = c->next) { + if (c->cache_id == cache_id && + c->hash == hash && + c->key_size == key_size && + memcmp(c->key, key, key_size) == 0 && + c->nr_relocs == nr_relocs && + memcmp(c->relocs, relocs, nr_relocs * sizeof *relocs) == 0) + return c; + } + + return NULL; +} + + +static void +rehash(struct brw_cache *cache) +{ + struct brw_cache_item **items; + struct brw_cache_item *c, *next; + GLuint size, i; + + size = cache->size * 3; + items = (struct brw_cache_item**) CALLOC(size, sizeof(*items)); + + for (i = 0; i < cache->size; i++) + for (c = cache->items[i]; c; c = next) { + next = c->next; + c->next = items[c->hash % size]; + items[c->hash % size] = c; + } + + FREE(cache->items); + cache->items = items; + cache->size = size; +} + + +/** + * Returns the buffer object matching cache_id and key, or NULL. + */ +boolean +brw_search_cache(struct brw_cache *cache, + enum brw_cache_id cache_id, + const void *key, + GLuint key_size, + struct brw_winsys_reloc *relocs, + GLuint nr_relocs, + void *aux_return, + struct brw_winsys_buffer **bo_out) +{ + struct brw_cache_item *item; + GLuint hash = hash_key(key, key_size, relocs, nr_relocs); + + item = search_cache(cache, cache_id, hash, key, key_size, + relocs, nr_relocs); + + if (item) { + if (aux_return) + *(void **)aux_return = (void *)((char *)item->key + item->key_size); + + update_cache_last(cache, cache_id, item->bo); + bo_reference(bo_out, item->bo); + return TRUE; + } + + return FALSE; +} + + +enum pipe_error +brw_upload_cache( struct brw_cache *cache, + enum brw_cache_id cache_id, + const void *key, + GLuint key_size, + struct brw_winsys_reloc *relocs, + GLuint nr_relocs, + const void *data, + GLuint data_size, + const void *aux, + void *aux_return, + struct brw_winsys_buffer **bo_out) +{ + struct brw_cache_item *item; + GLuint hash = hash_key(key, key_size, relocs, nr_relocs); + GLuint relocs_size = nr_relocs * sizeof relocs[0]; + GLuint aux_size = cache->aux_size[cache_id]; + enum pipe_error ret; + void *tmp; + int i; + + /* Create the buffer object to contain the data. For now, use a + * single buffer type to describe all cached state atoms. Later, + * may want to take advantage of hardware distinctions between + * these various entities. + */ + ret = cache->sws->bo_alloc(cache->sws, + cache->buffer_type, + data_size, 1 << 6, + bo_out); + if (ret) + return ret; + + item = CALLOC_STRUCT(brw_cache_item); + + /* Set up the memory containing the key, aux_data, and relocs */ + tmp = MALLOC(key_size + aux_size + relocs_size); + + memcpy(tmp, key, key_size); + memcpy((char *)tmp + key_size, aux, cache->aux_size[cache_id]); + memcpy((char *)tmp + key_size + aux_size, relocs, relocs_size); + for (i = 0; i < nr_relocs; i++) { + p_atomic_inc(&relocs[i].bo->reference.count); + } + + item->cache_id = cache_id; + item->key = tmp; + item->hash = hash; + item->key_size = key_size; + item->relocs = (struct brw_winsys_reloc *)((char *)tmp + key_size + aux_size); + item->nr_relocs = nr_relocs; + bo_reference( &item->bo, *bo_out ); + item->data_size = data_size; + + if (cache->n_items > cache->size * 1.5) + rehash(cache); + + hash %= cache->size; + item->next = cache->items[hash]; + cache->items[hash] = item; + cache->n_items++; + + if (aux_return) { + assert(cache->aux_size[cache_id]); + *(void **)aux_return = (void *)((char *)item->key + item->key_size); + } + + if (BRW_DEBUG & DEBUG_STATE) + debug_printf("upload %s: %d bytes to cache id %d\n", + cache->name[cache_id], + data_size, cache_id); + + /* Copy data to the buffer */ + ret = cache->sws->bo_subdata(item->bo, + cache_id, + 0, data_size, data, + relocs, nr_relocs); + if (ret) + return ret; + + update_cache_last(cache, cache_id, item->bo); + + return PIPE_OK; +} + + +/** + * This doesn't really work with aux data. Use search/upload instead + */ +enum pipe_error +brw_cache_data_sz(struct brw_cache *cache, + enum brw_cache_id cache_id, + const void *data, + GLuint data_size, + struct brw_winsys_reloc *relocs, + GLuint nr_relocs, + struct brw_winsys_buffer **bo_out) +{ + struct brw_cache_item *item; + GLuint hash = hash_key(data, data_size, relocs, nr_relocs); + + item = search_cache(cache, cache_id, hash, data, data_size, + relocs, nr_relocs); + if (item) { + update_cache_last(cache, cache_id, item->bo); + + bo_reference(bo_out, item->bo); + return PIPE_OK; + } + + return brw_upload_cache(cache, cache_id, + data, data_size, + relocs, nr_relocs, + data, data_size, + NULL, NULL, + bo_out); +} + + +/** + * Wrapper around brw_cache_data_sz using the cache_id's canonical key size. + * + * If nr_relocs is nonzero, brw_search_cache()/brw_upload_cache() would be + * better to use, as the potentially changing offsets in the data-used-as-key + * will result in excessive cache misses. + * + * XXX: above is no longer true -- can we remove some code? + */ +enum pipe_error +brw_cache_data(struct brw_cache *cache, + enum brw_cache_id cache_id, + const void *data, + struct brw_winsys_reloc *relocs, + GLuint nr_relocs, + struct brw_winsys_buffer **bo_out) +{ + return brw_cache_data_sz(cache, cache_id, data, cache->key_size[cache_id], + relocs, nr_relocs, bo_out); +} + + +static void +brw_init_cache_id(struct brw_cache *cache, + const char *name, + enum brw_cache_id id, + GLuint key_size, + GLuint aux_size) +{ + cache->name[id] = strdup(name); + cache->key_size[id] = key_size; + cache->aux_size[id] = aux_size; +} + + +static void +brw_init_general_state_cache(struct brw_context *brw) +{ + struct brw_cache *cache = &brw->cache; + + cache->brw = brw; + cache->sws = brw->sws; + + cache->buffer_type = BRW_BUFFER_TYPE_GENERAL_STATE; + + cache->size = 7; + cache->n_items = 0; + cache->items = (struct brw_cache_item **) + CALLOC(cache->size, sizeof(struct brw_cache_item)); + + brw_init_cache_id(cache, + "CC_VP", + BRW_CC_VP, + sizeof(struct brw_cc_viewport), + 0); + + brw_init_cache_id(cache, + "CC_UNIT", + BRW_CC_UNIT, + sizeof(struct brw_cc_unit_state), + 0); + + brw_init_cache_id(cache, + "WM_PROG", + BRW_WM_PROG, + sizeof(struct brw_wm_prog_key), + sizeof(struct brw_wm_prog_data)); + + brw_init_cache_id(cache, + "SAMPLER_DEFAULT_COLOR", + BRW_SAMPLER_DEFAULT_COLOR, + sizeof(struct brw_sampler_default_color), + 0); + + brw_init_cache_id(cache, + "SAMPLER", + BRW_SAMPLER, + 0, /* variable key/data size */ + 0); + + brw_init_cache_id(cache, + "WM_UNIT", + BRW_WM_UNIT, + sizeof(struct brw_wm_unit_state), + 0); + + brw_init_cache_id(cache, + "SF_PROG", + BRW_SF_PROG, + sizeof(struct brw_sf_prog_key), + sizeof(struct brw_sf_prog_data)); + + brw_init_cache_id(cache, + "SF_VP", + BRW_SF_VP, + sizeof(struct brw_sf_viewport), + 0); + + brw_init_cache_id(cache, + "SF_UNIT", + BRW_SF_UNIT, + sizeof(struct brw_sf_unit_state), + 0); + + brw_init_cache_id(cache, + "VS_UNIT", + BRW_VS_UNIT, + sizeof(struct brw_vs_unit_state), + 0); + + brw_init_cache_id(cache, + "VS_PROG", + BRW_VS_PROG, + sizeof(struct brw_vs_prog_key), + sizeof(struct brw_vs_prog_data)); + + brw_init_cache_id(cache, + "CLIP_UNIT", + BRW_CLIP_UNIT, + sizeof(struct brw_clip_unit_state), + 0); + + brw_init_cache_id(cache, + "CLIP_PROG", + BRW_CLIP_PROG, + sizeof(struct brw_clip_prog_key), + sizeof(struct brw_clip_prog_data)); + + brw_init_cache_id(cache, + "GS_UNIT", + BRW_GS_UNIT, + sizeof(struct brw_gs_unit_state), + 0); + + brw_init_cache_id(cache, + "GS_PROG", + BRW_GS_PROG, + sizeof(struct brw_gs_prog_key), + sizeof(struct brw_gs_prog_data)); +} + + +static void +brw_init_surface_state_cache(struct brw_context *brw) +{ + struct brw_cache *cache = &brw->surface_cache; + + cache->brw = brw; + cache->sws = brw->sws; + + cache->buffer_type = BRW_BUFFER_TYPE_SURFACE_STATE; + + cache->size = 7; + cache->n_items = 0; + cache->items = (struct brw_cache_item **) + CALLOC(cache->size, sizeof(struct brw_cache_item)); + + brw_init_cache_id(cache, + "SS_SURFACE", + BRW_SS_SURFACE, + sizeof(struct brw_surface_state), + 0); + + brw_init_cache_id(cache, + "SS_SURF_BIND", + BRW_SS_SURF_BIND, + 0, + 0); +} + + +void +brw_init_caches(struct brw_context *brw) +{ + brw_init_general_state_cache(brw); + brw_init_surface_state_cache(brw); +} + + +static void +brw_clear_cache(struct brw_context *brw, struct brw_cache *cache) +{ + struct brw_cache_item *c, *next; + GLuint i; + + if (BRW_DEBUG & DEBUG_STATE) + debug_printf("%s\n", __FUNCTION__); + + for (i = 0; i < cache->size; i++) { + for (c = cache->items[i]; c; c = next) { + int j; + + next = c->next; + + for (j = 0; j < c->nr_relocs; j++) + bo_reference(&c->relocs[j].bo, NULL); + + bo_reference(&c->bo, NULL); + FREE((void *)c->key); + FREE(c); + } + cache->items[i] = NULL; + } + + cache->n_items = 0; + + if (brw->curbe.last_buf) { + FREE(brw->curbe.last_buf); + brw->curbe.last_buf = NULL; + } + + brw->state.dirty.mesa |= ~0; + brw->state.dirty.brw |= ~0; + brw->state.dirty.cache |= ~0; +} + +/* Clear all entries from the cache that point to the given bo. + * + * This lets us release memory for reuse earlier for known-dead buffers, + * at the cost of walking the entire hash table. + */ +void +brw_state_cache_bo_delete(struct brw_cache *cache, struct brw_winsys_buffer *bo) +{ + struct brw_cache_item **prev; + GLuint i; + + if (BRW_DEBUG & DEBUG_STATE) + debug_printf("%s\n", __FUNCTION__); + + for (i = 0; i < cache->size; i++) { + for (prev = &cache->items[i]; *prev;) { + struct brw_cache_item *c = *prev; + + if (cache->sws->bo_references(c->bo, bo)) { + int j; + + *prev = c->next; + + for (j = 0; j < c->nr_relocs; j++) + bo_reference(&c->relocs[j].bo, NULL); + + bo_reference(&c->bo, NULL); + + FREE((void *)c->key); + FREE(c); + cache->n_items--; + } else { + prev = &c->next; + } + } + } +} + +void +brw_state_cache_check_size(struct brw_context *brw) +{ + if (BRW_DEBUG & DEBUG_STATE) + debug_printf("%s (n_items=%d)\n", __FUNCTION__, brw->cache.n_items); + + /* un-tuned guess. We've got around 20 state objects for a total of around + * 32k, so 1000 of them is around 1.5MB. + */ + if (brw->cache.n_items > 1000) + brw_clear_cache(brw, &brw->cache); + + if (brw->surface_cache.n_items > 1000) + brw_clear_cache(brw, &brw->surface_cache); +} + + +static void +brw_destroy_cache(struct brw_context *brw, struct brw_cache *cache) +{ + GLuint i; + + if (BRW_DEBUG & DEBUG_STATE) + debug_printf("%s\n", __FUNCTION__); + + brw_clear_cache(brw, cache); + for (i = 0; i < BRW_MAX_CACHE; i++) { + bo_reference(&cache->last_bo[i], NULL); + FREE(cache->name[i]); + } + FREE(cache->items); + cache->items = NULL; + cache->size = 0; +} + + +void +brw_destroy_caches(struct brw_context *brw) +{ + brw_destroy_cache(brw, &brw->cache); + brw_destroy_cache(brw, &brw->surface_cache); +} diff --git a/src/gallium/drivers/i965/brw_state_debug.c b/src/gallium/drivers/i965/brw_state_debug.c new file mode 100644 index 0000000..049c278 --- /dev/null +++ b/src/gallium/drivers/i965/brw_state_debug.c @@ -0,0 +1,153 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + + + +#include "brw_context.h" +#include "brw_state.h" + + +struct dirty_bit_map { + uint32_t bit; + char *name; + uint32_t count; +}; + +#define DEFINE_BIT(name) {name, #name, 0} + +static struct dirty_bit_map mesa_bits[] = { + DEFINE_BIT(PIPE_NEW_DEPTH_STENCIL_ALPHA), + DEFINE_BIT(PIPE_NEW_RAST), + DEFINE_BIT(PIPE_NEW_BLEND), + DEFINE_BIT(PIPE_NEW_VIEWPORT), + DEFINE_BIT(PIPE_NEW_SAMPLERS), + DEFINE_BIT(PIPE_NEW_VERTEX_BUFFER), + DEFINE_BIT(PIPE_NEW_VERTEX_ELEMENT), + DEFINE_BIT(PIPE_NEW_FRAGMENT_SHADER), + DEFINE_BIT(PIPE_NEW_VERTEX_SHADER), + DEFINE_BIT(PIPE_NEW_FRAGMENT_CONSTANTS), + DEFINE_BIT(PIPE_NEW_VERTEX_CONSTANTS), + DEFINE_BIT(PIPE_NEW_CLIP), + DEFINE_BIT(PIPE_NEW_INDEX_BUFFER), + DEFINE_BIT(PIPE_NEW_INDEX_RANGE), + DEFINE_BIT(PIPE_NEW_BLEND_COLOR), + DEFINE_BIT(PIPE_NEW_POLYGON_STIPPLE), + DEFINE_BIT(PIPE_NEW_FRAMEBUFFER_DIMENSIONS), + DEFINE_BIT(PIPE_NEW_DEPTH_BUFFER), + DEFINE_BIT(PIPE_NEW_COLOR_BUFFERS), + DEFINE_BIT(PIPE_NEW_QUERY), + DEFINE_BIT(PIPE_NEW_SCISSOR), + DEFINE_BIT(PIPE_NEW_BOUND_TEXTURES), + DEFINE_BIT(PIPE_NEW_NR_CBUFS), + {0, 0, 0} +}; + +static struct dirty_bit_map brw_bits[] = { + DEFINE_BIT(BRW_NEW_URB_FENCE), + DEFINE_BIT(BRW_NEW_FRAGMENT_PROGRAM), + DEFINE_BIT(BRW_NEW_VERTEX_PROGRAM), + DEFINE_BIT(BRW_NEW_INPUT_DIMENSIONS), + DEFINE_BIT(BRW_NEW_CURBE_OFFSETS), + DEFINE_BIT(BRW_NEW_REDUCED_PRIMITIVE), + DEFINE_BIT(BRW_NEW_PRIMITIVE), + DEFINE_BIT(BRW_NEW_CONTEXT), + DEFINE_BIT(BRW_NEW_WM_INPUT_DIMENSIONS), + DEFINE_BIT(BRW_NEW_PSP), + DEFINE_BIT(BRW_NEW_WM_SURFACES), + DEFINE_BIT(BRW_NEW_xxx), + DEFINE_BIT(BRW_NEW_INDICES), + {0, 0, 0} +}; + +static struct dirty_bit_map cache_bits[] = { + DEFINE_BIT(CACHE_NEW_CC_VP), + DEFINE_BIT(CACHE_NEW_CC_UNIT), + DEFINE_BIT(CACHE_NEW_WM_PROG), + DEFINE_BIT(CACHE_NEW_SAMPLER_DEFAULT_COLOR), + DEFINE_BIT(CACHE_NEW_SAMPLER), + DEFINE_BIT(CACHE_NEW_WM_UNIT), + DEFINE_BIT(CACHE_NEW_SF_PROG), + DEFINE_BIT(CACHE_NEW_SF_VP), + DEFINE_BIT(CACHE_NEW_SF_UNIT), + DEFINE_BIT(CACHE_NEW_VS_UNIT), + DEFINE_BIT(CACHE_NEW_VS_PROG), + DEFINE_BIT(CACHE_NEW_GS_UNIT), + DEFINE_BIT(CACHE_NEW_GS_PROG), + DEFINE_BIT(CACHE_NEW_CLIP_VP), + DEFINE_BIT(CACHE_NEW_CLIP_UNIT), + DEFINE_BIT(CACHE_NEW_CLIP_PROG), + DEFINE_BIT(CACHE_NEW_SURFACE), + DEFINE_BIT(CACHE_NEW_SURF_BIND), + {0, 0, 0} +}; + + +static void +brw_update_dirty_count(struct dirty_bit_map *bit_map, int32_t bits) +{ + int i; + + for (i = 0; i < 32; i++) { + if (bit_map[i].bit == 0) + return; + + if (bit_map[i].bit & bits) + bit_map[i].count++; + } +} + +static void +brw_print_dirty_count(struct dirty_bit_map *bit_map, int32_t bits) +{ + int i; + + for (i = 0; i < 32; i++) { + if (bit_map[i].bit == 0) + return; + + debug_printf("0x%08x: %12d (%s)\n", + bit_map[i].bit, bit_map[i].count, bit_map[i].name); + } +} + +void +brw_update_dirty_counts( unsigned mesa, + unsigned brw, + unsigned cache ) +{ + static int dirty_count = 0; + + brw_update_dirty_count(mesa_bits, mesa); + brw_update_dirty_count(brw_bits, brw); + brw_update_dirty_count(cache_bits, cache); + if (dirty_count++ % 1000 == 0) { + brw_print_dirty_count(mesa_bits, mesa); + brw_print_dirty_count(brw_bits, brw); + brw_print_dirty_count(cache_bits, cache); + debug_printf("\n"); + } +} diff --git a/src/gallium/drivers/i965/brw_state_upload.c b/src/gallium/drivers/i965/brw_state_upload.c new file mode 100644 index 0000000..f8b91ef --- /dev/null +++ b/src/gallium/drivers/i965/brw_state_upload.c @@ -0,0 +1,270 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + + +#include "brw_context.h" +#include "brw_state.h" +#include "brw_batchbuffer.h" +#include "brw_debug.h" + +const struct brw_tracked_state *atoms[] = +{ +/* &brw_wm_input_sizes, */ + &brw_vs_prog, + &brw_gs_prog, + &brw_clip_prog, + &brw_sf_prog, + &brw_wm_prog, + + /* Once all the programs are done, we know how large urb entry + * sizes need to be and can decide if we need to change the urb + * layout. + */ + &brw_curbe_offsets, + &brw_recalculate_urb_fence, + + &brw_cc_vp, + &brw_cc_unit, + + &brw_vs_surfaces, /* must do before unit */ + /*&brw_wm_constant_surface,*/ /* must do before wm surfaces/bind bo */ + &brw_wm_surfaces, /* must do before samplers and unit */ + &brw_wm_samplers, + + &brw_wm_unit, + &brw_sf_vp, + &brw_sf_unit, + &brw_vs_unit, /* always required, enabled or not */ + &brw_clip_unit, + &brw_gs_unit, + + /* Command packets: + */ + &brw_invarient_state, + &brw_state_base_address, + + &brw_binding_table_pointers, + &brw_blend_constant_color, + + &brw_depthbuffer, + &brw_polygon_stipple, + &brw_line_stipple, + + &brw_psp_urb_cbs, + + &brw_drawing_rect, + &brw_indices, + &brw_index_buffer, + &brw_vertices, + + &brw_curbe_buffer +}; + + +void brw_init_state( struct brw_context *brw ) +{ + brw_init_caches(brw); +} + + +void brw_destroy_state( struct brw_context *brw ) +{ + brw_destroy_caches(brw); + brw_destroy_batch_cache(brw); +} + +/*********************************************************************** + */ + +static GLboolean check_state( const struct brw_state_flags *a, + const struct brw_state_flags *b ) +{ + return ((a->mesa & b->mesa) || + (a->brw & b->brw) || + (a->cache & b->cache)); +} + +static void accumulate_state( struct brw_state_flags *a, + const struct brw_state_flags *b ) +{ + a->mesa |= b->mesa; + a->brw |= b->brw; + a->cache |= b->cache; +} + + +static void xor_states( struct brw_state_flags *result, + const struct brw_state_flags *a, + const struct brw_state_flags *b ) +{ + result->mesa = a->mesa ^ b->mesa; + result->brw = a->brw ^ b->brw; + result->cache = a->cache ^ b->cache; +} + +static void +brw_clear_validated_bos(struct brw_context *brw) +{ + int i; + + /* Clear the last round of validated bos */ + for (i = 0; i < brw->state.validated_bo_count; i++) { + bo_reference(&brw->state.validated_bos[i], NULL); + } + brw->state.validated_bo_count = 0; +} + + +/*********************************************************************** + * Emit all state: + */ +enum pipe_error brw_validate_state( struct brw_context *brw ) +{ + struct brw_state_flags *state = &brw->state.dirty; + GLuint i; + int ret; + + brw_clear_validated_bos(brw); + brw_add_validated_bo(brw, brw->batch->buf); + + if (brw->flags.always_emit_state) { + state->mesa |= ~0; + state->brw |= ~0; + state->cache |= ~0; + } + + if (state->mesa == 0 && + state->cache == 0 && + state->brw == 0) + return 0; + + if (brw->state.dirty.brw & BRW_NEW_CONTEXT) + brw_clear_batch_cache(brw); + + /* do prepare stage for all atoms */ + for (i = 0; i < Elements(atoms); i++) { + const struct brw_tracked_state *atom = atoms[i]; + + if (check_state(state, &atom->dirty)) { + if (atom->prepare) { + ret = atom->prepare(brw); + if (ret) + return ret; + } + } + } + + /* Make sure that the textures which are referenced by the current + * brw fragment program are actually present/valid. + * If this fails, we can experience GPU lock-ups. + */ + { + const struct brw_fragment_shader *fp = brw->curr.fragment_shader; + if (fp) { + assert(fp->info.file_max[TGSI_FILE_SAMPLER] < (int)brw->curr.num_samplers); + /*assert(fp->info.texture_max <= brw->curr.num_textures);*/ + } + } + + return 0; +} + + +enum pipe_error brw_upload_state(struct brw_context *brw) +{ + struct brw_state_flags *state = &brw->state.dirty; + int ret; + int i; + + brw_clear_validated_bos(brw); + + if (BRW_DEBUG) { + /* Debug version which enforces various sanity checks on the + * state flags which are generated and checked to help ensure + * state atoms are ordered correctly in the list. + */ + struct brw_state_flags examined, prev; + memset(&examined, 0, sizeof(examined)); + prev = *state; + + for (i = 0; i < Elements(atoms); i++) { + const struct brw_tracked_state *atom = atoms[i]; + struct brw_state_flags generated; + + assert(atom->dirty.mesa || + atom->dirty.brw || + atom->dirty.cache); + + if (check_state(state, &atom->dirty)) { + if (atom->emit) { + ret = atom->emit( brw ); + if (ret) + return ret; + } + } + + accumulate_state(&examined, &atom->dirty); + + /* generated = (prev ^ state) + * if (examined & generated) + * fail; + */ + xor_states(&generated, &prev, state); + assert(!check_state(&examined, &generated)); + prev = *state; + } + } + else { + for (i = 0; i < Elements(atoms); i++) { + const struct brw_tracked_state *atom = atoms[i]; + + if (check_state(state, &atom->dirty)) { + if (atom->emit) { + ret = atom->emit( brw ); + if (ret) + return ret; + } + } + } + } + + if (BRW_DEBUG & DEBUG_STATE) { + brw_update_dirty_counts( state->mesa, + state->brw, + state->cache ); + } + + /* Clear dirty flags: + */ + memset(state, 0, sizeof(*state)); + return 0; +} diff --git a/src/gallium/drivers/i965/brw_structs.h b/src/gallium/drivers/i965/brw_structs.h new file mode 100644 index 0000000..e97ddeb --- /dev/null +++ b/src/gallium/drivers/i965/brw_structs.h @@ -0,0 +1,1576 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#ifndef BRW_STRUCTS_H +#define BRW_STRUCTS_H + +#include "brw_types.h" + +/** Number of general purpose registers (VS, WM, etc) */ +#define BRW_MAX_GRF 128 + +/** Number of message register file registers */ +#define BRW_MAX_MRF 16 + + +/* Command packets: + */ +struct header +{ + GLuint length:16; + GLuint opcode:16; +}; + + +union header_union +{ + struct header bits; + GLuint dword; +}; + +struct brw_3d_control +{ + struct + { + GLuint length:8; + GLuint notify_enable:1; + GLuint pad:3; + GLuint wc_flush_enable:1; + GLuint depth_stall_enable:1; + GLuint operation:2; + GLuint opcode:16; + } header; + + struct + { + GLuint pad:2; + GLuint dest_addr_type:1; + GLuint dest_addr:29; + } dest; + + GLuint dword2; + GLuint dword3; +}; + + +struct brw_3d_primitive +{ + struct + { + GLuint length:8; + GLuint pad:2; + GLuint topology:5; + GLuint indexed:1; + GLuint opcode:16; + } header; + + GLuint verts_per_instance; + GLuint start_vert_location; + GLuint instance_count; + GLuint start_instance_location; + GLuint base_vert_location; +}; + +/* These seem to be passed around as function args, so it works out + * better to keep them as #defines: + */ +#define BRW_FLUSH_READ_CACHE 0x1 +#define BRW_FLUSH_STATE_CACHE 0x2 +#define BRW_INHIBIT_FLUSH_RENDER_CACHE 0x4 +#define BRW_FLUSH_SNAPSHOT_COUNTERS 0x8 + +struct brw_mi_flush +{ + GLuint flags:4; + GLuint pad:12; + GLuint opcode:16; +}; + +struct brw_vf_statistics +{ + GLuint statistics_enable:1; + GLuint pad:15; + GLuint opcode:16; +}; + + + +struct brw_binding_table_pointers +{ + struct header header; + GLuint vs; + GLuint gs; + GLuint clp; + GLuint sf; + GLuint wm; +}; + + +struct brw_blend_constant_color +{ + struct header header; + GLfloat blend_constant_color[4]; +}; + + +struct brw_depthbuffer +{ + union header_union header; + + union { + struct { + GLuint pitch:18; + GLuint format:3; + GLuint pad:2; + GLuint software_tiled_rendering_mode:2; + GLuint depth_offset_disable:1; + GLuint tile_walk:1; + GLuint tiled_surface:1; + GLuint pad2:1; + GLuint surface_type:3; + } bits; + GLuint dword; + } dword1; + + GLuint dword2_base_addr; + + union { + struct { + GLuint pad:1; + GLuint mipmap_layout:1; + GLuint lod:4; + GLuint width:13; + GLuint height:13; + } bits; + GLuint dword; + } dword3; + + union { + struct { + GLuint pad:10; + GLuint min_array_element:11; + GLuint depth:11; + } bits; + GLuint dword; + } dword4; +}; + +struct brw_depthbuffer_g4x +{ + union header_union header; + + union { + struct { + GLuint pitch:18; + GLuint format:3; + GLuint pad:2; + GLuint software_tiled_rendering_mode:2; + GLuint depth_offset_disable:1; + GLuint tile_walk:1; + GLuint tiled_surface:1; + GLuint pad2:1; + GLuint surface_type:3; + } bits; + GLuint dword; + } dword1; + + GLuint dword2_base_addr; + + union { + struct { + GLuint pad:1; + GLuint mipmap_layout:1; + GLuint lod:4; + GLuint width:13; + GLuint height:13; + } bits; + GLuint dword; + } dword3; + + union { + struct { + GLuint pad:10; + GLuint min_array_element:11; + GLuint depth:11; + } bits; + GLuint dword; + } dword4; + + union { + struct { + GLuint xoffset:16; + GLuint yoffset:16; + } bits; + GLuint dword; + } dword5; /* NEW in Integrated Graphics Device */ +}; + +struct brw_drawrect +{ + struct header header; + GLuint xmin:16; + GLuint ymin:16; + GLuint xmax:16; + GLuint ymax:16; + GLuint xorg:16; + GLuint yorg:16; +}; + + + + +struct brw_global_depth_offset_clamp +{ + struct header header; + GLfloat depth_offset_clamp; +}; + +struct brw_indexbuffer +{ + union { + struct + { + GLuint length:8; + GLuint index_format:2; + GLuint cut_index_enable:1; + GLuint pad:5; + GLuint opcode:16; + } bits; + GLuint dword; + + } header; + + GLuint buffer_start; + GLuint buffer_end; +}; + +/* NEW in Integrated Graphics Device */ +struct brw_aa_line_parameters +{ + struct header header; + + struct { + GLuint aa_coverage_scope:8; + GLuint pad0:8; + GLuint aa_coverage_bias:8; + GLuint pad1:8; + } bits0; + + struct { + GLuint aa_coverage_endcap_slope:8; + GLuint pad0:8; + GLuint aa_coverage_endcap_bias:8; + GLuint pad1:8; + } bits1; +}; + +struct brw_line_stipple +{ + struct header header; + + struct + { + GLuint pattern:16; + GLuint pad:16; + } bits0; + + struct + { + GLuint repeat_count:9; + GLuint pad:7; + GLuint inverse_repeat_count:16; + } bits1; +}; + + +struct brw_pipelined_state_pointers +{ + struct header header; + + struct { + GLuint pad:5; + GLuint offset:27; /* Offset from GENERAL_STATE_BASE */ + } vs; + + struct + { + GLuint enable:1; + GLuint pad:4; + GLuint offset:27; /* Offset from GENERAL_STATE_BASE */ + } gs; + + struct + { + GLuint enable:1; + GLuint pad:4; + GLuint offset:27; /* Offset from GENERAL_STATE_BASE */ + } clp; + + struct + { + GLuint pad:5; + GLuint offset:27; /* Offset from GENERAL_STATE_BASE */ + } sf; + + struct + { + GLuint pad:5; + GLuint offset:27; /* Offset from GENERAL_STATE_BASE */ + } wm; + + struct + { + GLuint pad:5; + GLuint offset:27; /* Offset from GENERAL_STATE_BASE. KW: check me! */ + } cc; +}; + + +struct brw_polygon_stipple_offset +{ + struct header header; + + struct { + GLuint y_offset:5; + GLuint pad:3; + GLuint x_offset:5; + GLuint pad0:19; + } bits0; +}; + + + +struct brw_polygon_stipple +{ + struct header header; + GLuint stipple[32]; +}; + + + +struct brw_pipeline_select +{ + struct + { + GLuint pipeline_select:1; + GLuint pad:15; + GLuint opcode:16; + } header; +}; + + +struct brw_pipe_control +{ + struct + { + GLuint length:8; + GLuint notify_enable:1; + GLuint texture_cache_flush_enable:1; + GLuint indirect_state_pointers_disable:1; + GLuint instruction_state_cache_flush_enable:1; + GLuint write_cache_flush_enable:1; + GLuint depth_stall_enable:1; + GLuint post_sync_operation:2; + + GLuint opcode:16; + } header; + + struct + { + GLuint pad:2; + GLuint dest_addr_type:1; + GLuint dest_addr:29; + } bits1; + + GLuint data0; + GLuint data1; +}; + + +struct brw_urb_fence +{ + struct + { + GLuint length:8; + GLuint vs_realloc:1; + GLuint gs_realloc:1; + GLuint clp_realloc:1; + GLuint sf_realloc:1; + GLuint vfe_realloc:1; + GLuint cs_realloc:1; + GLuint pad:2; + GLuint opcode:16; + } header; + + struct + { + GLuint vs_fence:10; + GLuint gs_fence:10; + GLuint clp_fence:10; + GLuint pad:2; + } bits0; + + struct + { + GLuint sf_fence:10; + GLuint vf_fence:10; + GLuint cs_fence:11; + GLuint pad:1; + } bits1; +}; + +struct brw_cs_urb_state +{ + struct header header; + + struct + { + GLuint nr_urb_entries:3; + GLuint pad:1; + GLuint urb_entry_size:5; + GLuint pad0:23; + } bits0; +}; + +struct brw_constant_buffer +{ + struct + { + GLuint length:8; + GLuint valid:1; + GLuint pad:7; + GLuint opcode:16; + } header; + + struct + { + GLuint buffer_length:6; + GLuint buffer_address:26; + } bits0; +}; + +struct brw_state_base_address +{ + struct header header; + + struct + { + GLuint modify_enable:1; + GLuint pad:4; + GLuint general_state_address:27; + } bits0; + + struct + { + GLuint modify_enable:1; + GLuint pad:4; + GLuint surface_state_address:27; + } bits1; + + struct + { + GLuint modify_enable:1; + GLuint pad:4; + GLuint indirect_object_state_address:27; + } bits2; + + struct + { + GLuint modify_enable:1; + GLuint pad:11; + GLuint general_state_upper_bound:20; + } bits3; + + struct + { + GLuint modify_enable:1; + GLuint pad:11; + GLuint indirect_object_state_upper_bound:20; + } bits4; +}; + +struct brw_state_prefetch +{ + struct header header; + + struct + { + GLuint prefetch_count:3; + GLuint pad:3; + GLuint prefetch_pointer:26; + } bits0; +}; + +struct brw_system_instruction_pointer +{ + struct header header; + + struct + { + GLuint pad:4; + GLuint system_instruction_pointer:28; + } bits0; +}; + + + + +/* State structs for the various fixed function units: + */ + + +struct thread0 +{ + GLuint pad0:1; + GLuint grf_reg_count:3; + GLuint pad1:2; + GLuint kernel_start_pointer:26; /* Offset from GENERAL_STATE_BASE */ +}; + +struct thread1 +{ + GLuint ext_halt_exception_enable:1; + GLuint sw_exception_enable:1; + GLuint mask_stack_exception_enable:1; + GLuint timeout_exception_enable:1; + GLuint illegal_op_exception_enable:1; + GLuint pad0:3; + GLuint depth_coef_urb_read_offset:6; /* WM only */ + GLuint pad1:2; + GLuint floating_point_mode:1; + GLuint thread_priority:1; + GLuint binding_table_entry_count:8; + GLuint pad3:5; + GLuint single_program_flow:1; +}; + +struct thread2 +{ + GLuint per_thread_scratch_space:4; + GLuint pad0:6; + GLuint scratch_space_base_pointer:22; +}; + + +struct thread3 +{ + GLuint dispatch_grf_start_reg:4; + GLuint urb_entry_read_offset:6; + GLuint pad0:1; + GLuint urb_entry_read_length:6; + GLuint pad1:1; + GLuint const_urb_entry_read_offset:6; + GLuint pad2:1; + GLuint const_urb_entry_read_length:6; + GLuint pad3:1; +}; + + + +struct brw_clip_unit_state +{ + struct thread0 thread0; + struct + { + GLuint pad0:7; + GLuint sw_exception_enable:1; + GLuint pad1:3; + GLuint mask_stack_exception_enable:1; + GLuint pad2:1; + GLuint illegal_op_exception_enable:1; + GLuint pad3:2; + GLuint floating_point_mode:1; + GLuint thread_priority:1; + GLuint binding_table_entry_count:8; + GLuint pad4:5; + GLuint single_program_flow:1; + } thread1; + + struct thread2 thread2; + struct thread3 thread3; + + struct + { + GLuint pad0:9; + GLuint gs_output_stats:1; /* not always */ + GLuint stats_enable:1; + GLuint nr_urb_entries:7; + GLuint pad1:1; + GLuint urb_entry_allocation_size:5; + GLuint pad2:1; + GLuint max_threads:5; /* may be less */ + GLuint pad3:2; + } thread4; + + struct + { + GLuint pad0:13; + GLuint clip_mode:3; + GLuint userclip_enable_flags:8; + GLuint userclip_must_clip:1; + GLuint negative_w_clip_test:1; + GLuint guard_band_enable:1; + GLuint viewport_z_clip_enable:1; + GLuint viewport_xy_clip_enable:1; + GLuint vertex_position_space:1; + GLuint api_mode:1; + GLuint pad2:1; + } clip5; + + struct + { + GLuint pad0:5; + GLuint clipper_viewport_state_ptr:27; + } clip6; + + + GLfloat viewport_xmin; + GLfloat viewport_xmax; + GLfloat viewport_ymin; + GLfloat viewport_ymax; +}; + + + +struct brw_cc_unit_state +{ + struct brw_cc0 + { + GLuint pad0:3; + GLuint bf_stencil_pass_depth_pass_op:3; + GLuint bf_stencil_pass_depth_fail_op:3; + GLuint bf_stencil_fail_op:3; + GLuint bf_stencil_func:3; + GLuint bf_stencil_enable:1; + GLuint pad1:2; + GLuint stencil_write_enable:1; + GLuint stencil_pass_depth_pass_op:3; + GLuint stencil_pass_depth_fail_op:3; + GLuint stencil_fail_op:3; + GLuint stencil_func:3; + GLuint stencil_enable:1; + } cc0; + + + struct brw_cc1 + { + GLuint bf_stencil_ref:8; + GLuint stencil_write_mask:8; + GLuint stencil_test_mask:8; + GLuint stencil_ref:8; + } cc1; + + + struct brw_cc2 + { + GLuint logicop_enable:1; + GLuint pad0:10; + GLuint depth_write_enable:1; + GLuint depth_test_function:3; + GLuint depth_test:1; + GLuint bf_stencil_write_mask:8; + GLuint bf_stencil_test_mask:8; + } cc2; + + + struct brw_cc3 + { + GLuint pad0:8; + GLuint alpha_test_func:3; + GLuint alpha_test:1; + GLuint blend_enable:1; + GLuint ia_blend_enable:1; + GLuint pad1:1; + GLuint alpha_test_format:1; + GLuint pad2:16; + } cc3; + + struct brw_cc4 + { + GLuint pad0:5; + GLuint cc_viewport_state_offset:27; /* Offset from GENERAL_STATE_BASE */ + } cc4; + + struct brw_cc5 + { + GLuint pad0:2; + GLuint ia_dest_blend_factor:5; + GLuint ia_src_blend_factor:5; + GLuint ia_blend_function:3; + GLuint statistics_enable:1; + GLuint logicop_func:4; + GLuint pad1:11; + GLuint dither_enable:1; + } cc5; + + struct brw_cc6 + { + GLuint clamp_post_alpha_blend:1; + GLuint clamp_pre_alpha_blend:1; + GLuint clamp_range:2; + GLuint pad0:11; + GLuint y_dither_offset:2; + GLuint x_dither_offset:2; + GLuint dest_blend_factor:5; + GLuint src_blend_factor:5; + GLuint blend_function:3; + } cc6; + + struct brw_cc7 { + union { + GLfloat f; + GLubyte ub[4]; + } alpha_ref; + } cc7; +}; + + + +struct brw_sf_unit_state +{ + struct thread0 thread0; + struct thread1 thread1; + struct thread2 thread2; + struct thread3 thread3; + + struct + { + GLuint pad0:10; + GLuint stats_enable:1; + GLuint nr_urb_entries:7; + GLuint pad1:1; + GLuint urb_entry_allocation_size:5; + GLuint pad2:1; + GLuint max_threads:6; + GLuint pad3:1; + } thread4; + + struct + { + GLuint front_winding:1; + GLuint viewport_transform:1; + GLuint pad0:3; + GLuint sf_viewport_state_offset:27; /* Offset from GENERAL_STATE_BASE */ + } sf5; + + struct + { + GLuint pad0:9; + GLuint dest_org_vbias:4; + GLuint dest_org_hbias:4; + GLuint scissor:1; + GLuint disable_2x2_trifilter:1; + GLuint disable_zero_pix_trifilter:1; + GLuint point_rast_rule:2; + GLuint line_endcap_aa_region_width:2; + GLuint line_width:4; + GLuint fast_scissor_disable:1; + GLuint cull_mode:2; + GLuint aa_enable:1; + } sf6; + + struct + { + GLuint point_size:11; + GLuint use_point_size_state:1; + GLuint subpixel_precision:1; + GLuint sprite_point:1; + GLuint pad0:10; + GLuint aa_line_distance_mode:1; + GLuint trifan_pv:2; + GLuint linestrip_pv:2; + GLuint tristrip_pv:2; + GLuint line_last_pixel_enable:1; + } sf7; + +}; + + +struct brw_gs_unit_state +{ + struct thread0 thread0; + struct thread1 thread1; + struct thread2 thread2; + struct thread3 thread3; + + struct + { + GLuint pad0:8; + GLuint rendering_enable:1; /* for IGDNG */ + GLuint pad4:1; + GLuint stats_enable:1; + GLuint nr_urb_entries:7; + GLuint pad1:1; + GLuint urb_entry_allocation_size:5; + GLuint pad2:1; + GLuint max_threads:5; + GLuint pad3:2; + } thread4; + + struct + { + GLuint sampler_count:3; + GLuint pad0:2; + GLuint sampler_state_pointer:27; + } gs5; + + + struct + { + GLuint max_vp_index:4; + GLuint pad0:12; + GLuint svbi_post_inc_value:10; + GLuint pad1:1; + GLuint svbi_post_inc_enable:1; + GLuint svbi_payload:1; + GLuint discard_adjaceny:1; + GLuint reorder_enable:1; + GLuint pad2:1; + } gs6; +}; + + +struct brw_vs_unit_state +{ + struct thread0 thread0; + struct thread1 thread1; + struct thread2 thread2; + struct thread3 thread3; + + struct + { + GLuint pad0:10; + GLuint stats_enable:1; + GLuint nr_urb_entries:7; + GLuint pad1:1; + GLuint urb_entry_allocation_size:5; + GLuint pad2:1; + GLuint max_threads:6; + GLuint pad3:1; + } thread4; + + struct + { + GLuint sampler_count:3; + GLuint pad0:2; + GLuint sampler_state_pointer:27; + } vs5; + + struct + { + GLuint vs_enable:1; + GLuint vert_cache_disable:1; + GLuint pad0:30; + } vs6; +}; + + +struct brw_wm_unit_state +{ + struct thread0 thread0; + struct thread1 thread1; + struct thread2 thread2; + struct thread3 thread3; + + struct { + GLuint stats_enable:1; + GLuint depth_buffer_clear:1; + GLuint sampler_count:3; + GLuint sampler_state_pointer:27; + } wm4; + + struct + { + GLuint enable_8_pix:1; + GLuint enable_16_pix:1; + GLuint enable_32_pix:1; + GLuint enable_con_32_pix:1; + GLuint enable_con_64_pix:1; + GLuint pad0:5; + GLuint legacy_global_depth_bias:1; + GLuint line_stipple:1; + GLuint depth_offset:1; + GLuint polygon_stipple:1; + GLuint line_aa_region_width:2; + GLuint line_endcap_aa_region_width:2; + GLuint early_depth_test:1; + GLuint thread_dispatch_enable:1; + GLuint program_uses_depth:1; + GLuint program_computes_depth:1; + GLuint program_uses_killpixel:1; + GLuint legacy_line_rast: 1; + GLuint transposed_urb_read_enable:1; + GLuint max_threads:7; + } wm5; + + GLfloat global_depth_offset_constant; + GLfloat global_depth_offset_scale; + + /* for IGDNG only */ + struct { + GLuint pad0:1; + GLuint grf_reg_count_1:3; + GLuint pad1:2; + GLuint kernel_start_pointer_1:26; + } wm8; + + struct { + GLuint pad0:1; + GLuint grf_reg_count_2:3; + GLuint pad1:2; + GLuint kernel_start_pointer_2:26; + } wm9; + + struct { + GLuint pad0:1; + GLuint grf_reg_count_3:3; + GLuint pad1:2; + GLuint kernel_start_pointer_3:26; + } wm10; +}; + +struct brw_sampler_default_color { + GLfloat color[4]; +}; + +struct brw_sampler_state +{ + + struct brw_ss0 + { + GLuint shadow_function:3; + GLuint lod_bias:11; + GLuint min_filter:3; + GLuint mag_filter:3; + GLuint mip_filter:2; + GLuint base_level:5; + GLuint pad:1; + GLuint lod_preclamp:1; + GLuint default_color_mode:1; + GLuint pad0:1; + GLuint disable:1; + } ss0; + + struct brw_ss1 + { + GLuint r_wrap_mode:3; + GLuint t_wrap_mode:3; + GLuint s_wrap_mode:3; + GLuint pad:3; + GLuint max_lod:10; + GLuint min_lod:10; + } ss1; + + + struct brw_ss2 + { + GLuint pad:5; + GLuint default_color_pointer:27; + } ss2; + + struct brw_ss3 + { + GLuint pad:19; + GLuint max_aniso:3; + GLuint chroma_key_mode:1; + GLuint chroma_key_index:2; + GLuint chroma_key_enable:1; + GLuint monochrome_filter_width:3; + GLuint monochrome_filter_height:3; + } ss3; +}; + + +struct brw_clipper_viewport +{ + GLfloat xmin; + GLfloat xmax; + GLfloat ymin; + GLfloat ymax; +}; + +struct brw_cc_viewport +{ + GLfloat min_depth; + GLfloat max_depth; +}; + +struct brw_sf_viewport +{ + struct { + GLfloat m00; + GLfloat m11; + GLfloat m22; + GLfloat m30; + GLfloat m31; + GLfloat m32; + } viewport; + + /* scissor coordinates are inclusive */ + struct { + GLshort xmin; + GLshort ymin; + GLshort xmax; + GLshort ymax; + } scissor; +}; + +/* Documented in the subsystem/shared-functions/sampler chapter... + */ +struct brw_surface_state +{ + struct brw_surf_ss0 { + GLuint cube_pos_z:1; + GLuint cube_neg_z:1; + GLuint cube_pos_y:1; + GLuint cube_neg_y:1; + GLuint cube_pos_x:1; + GLuint cube_neg_x:1; + GLuint pad:4; + GLuint mipmap_layout_mode:1; + GLuint vert_line_stride_ofs:1; + GLuint vert_line_stride:1; + GLuint color_blend:1; + GLuint writedisable_blue:1; + GLuint writedisable_green:1; + GLuint writedisable_red:1; + GLuint writedisable_alpha:1; + GLuint surface_format:9; /**< BRW_SURFACEFORMAT_x */ + GLuint data_return_format:1; + GLuint pad0:1; + GLuint surface_type:3; /**< BRW_SURFACE_1D/2D/3D/CUBE */ + } ss0; + + struct brw_surf_ss1 { + GLuint base_addr; + } ss1; + + struct brw_surf_ss2 { + GLuint pad:2; + GLuint mip_count:4; + GLuint width:13; + GLuint height:13; + } ss2; + + struct brw_surf_ss3 { + GLuint tile_walk:1; + GLuint tiled_surface:1; + GLuint pad:1; + GLuint pitch:18; + GLuint depth:11; + } ss3; + + struct brw_surf_ss4 { + GLuint multisample_position_palette_index:3; + GLuint pad1:1; + GLuint num_multisamples:3; + GLuint pad0:1; + GLuint render_target_view_extent:9; + GLuint min_array_elt:11; + GLuint min_lod:4; + } ss4; + + struct brw_surf_ss5 { + GLuint pad1:16; + GLuint llc_mapping:1; + GLuint mlc_mapping:1; + GLuint gfdt:1; + GLuint gfdt_src:1; + GLuint y_offset:4; + GLuint pad0:1; + GLuint x_offset:7; + } ss5; /* New in G4X */ + +}; + + + +struct brw_vertex_buffer_state +{ + struct { + GLuint pitch:11; + GLuint pad:15; + GLuint access_type:1; + GLuint vb_index:5; + } vb0; + + GLuint start_addr; + GLuint max_index; +#if 1 + GLuint instance_data_step_rate; /* not included for sequential/random vertices? */ +#endif +}; + +#define BRW_VBP_MAX 17 + +struct brw_vb_array_state { + struct header header; + struct brw_vertex_buffer_state vb[BRW_VBP_MAX]; +}; + + +struct brw_vertex_element_state +{ + struct + { + GLuint src_offset:11; + GLuint pad:5; + GLuint src_format:9; + GLuint pad0:1; + GLuint valid:1; + GLuint vertex_buffer_index:5; + } ve0; + + struct + { + GLuint dst_offset:8; + GLuint pad:8; + GLuint vfcomponent3:4; + GLuint vfcomponent2:4; + GLuint vfcomponent1:4; + GLuint vfcomponent0:4; + } ve1; +}; + +#define BRW_VEP_MAX 18 + +struct brw_vertex_element_packet { + struct header header; + struct brw_vertex_element_state ve[BRW_VEP_MAX]; /* note: less than _TNL_ATTRIB_MAX */ +}; + + +struct brw_urb_immediate { + GLuint opcode:4; + GLuint offset:6; + GLuint swizzle_control:2; + GLuint pad:1; + GLuint allocate:1; + GLuint used:1; + GLuint complete:1; + GLuint response_length:4; + GLuint msg_length:4; + GLuint msg_target:4; + GLuint pad1:3; + GLuint end_of_thread:1; +}; + +/* Instruction format for the execution units: + */ + +struct brw_instruction +{ + struct + { + GLuint opcode:7; + GLuint pad:1; + GLuint access_mode:1; + GLuint mask_control:1; + GLuint dependency_control:2; + GLuint compression_control:2; + GLuint thread_control:2; + GLuint predicate_control:4; + GLuint predicate_inverse:1; + GLuint execution_size:3; + GLuint destreg__conditionalmod:4; /* destreg - send, conditionalmod - others */ + GLuint pad0:2; + GLuint debug_control:1; + GLuint saturate:1; + } header; + + union { + struct + { + GLuint dest_reg_file:2; + GLuint dest_reg_type:3; + GLuint src0_reg_file:2; + GLuint src0_reg_type:3; + GLuint src1_reg_file:2; + GLuint src1_reg_type:3; + GLuint pad:1; + GLuint dest_subreg_nr:5; + GLuint dest_reg_nr:8; + GLuint dest_horiz_stride:2; + GLuint dest_address_mode:1; + } da1; + + struct + { + GLuint dest_reg_file:2; + GLuint dest_reg_type:3; + GLuint src0_reg_file:2; + GLuint src0_reg_type:3; + GLuint src1_reg_file:2; /* 0x00000c00 */ + GLuint src1_reg_type:3; /* 0x00007000 */ + GLuint pad:1; + GLint dest_indirect_offset:10; /* offset against the deref'd address reg */ + GLuint dest_subreg_nr:3; /* subnr for the address reg a0.x */ + GLuint dest_horiz_stride:2; + GLuint dest_address_mode:1; + } ia1; + + struct + { + GLuint dest_reg_file:2; + GLuint dest_reg_type:3; + GLuint src0_reg_file:2; + GLuint src0_reg_type:3; + GLuint src1_reg_file:2; + GLuint src1_reg_type:3; + GLuint pad:1; + GLuint dest_writemask:4; + GLuint dest_subreg_nr:1; + GLuint dest_reg_nr:8; + GLuint pad1:2; + GLuint dest_address_mode:1; + } da16; + + struct + { + GLuint dest_reg_file:2; + GLuint dest_reg_type:3; + GLuint src0_reg_file:2; + GLuint src0_reg_type:3; + GLuint pad0:6; + GLuint dest_writemask:4; + GLint dest_indirect_offset:6; + GLuint dest_subreg_nr:3; + GLuint pad1:2; + GLuint dest_address_mode:1; + } ia16; + } bits1; + + + union { + struct + { + GLuint src0_subreg_nr:5; + GLuint src0_reg_nr:8; + GLuint src0_abs:1; + GLuint src0_negate:1; + GLuint src0_address_mode:1; + GLuint src0_horiz_stride:2; + GLuint src0_width:3; + GLuint src0_vert_stride:4; + GLuint flag_reg_nr:1; + GLuint pad:6; + } da1; + + struct + { + GLint src0_indirect_offset:10; + GLuint src0_subreg_nr:3; + GLuint src0_abs:1; + GLuint src0_negate:1; + GLuint src0_address_mode:1; + GLuint src0_horiz_stride:2; + GLuint src0_width:3; + GLuint src0_vert_stride:4; + GLuint flag_reg_nr:1; + GLuint pad:6; + } ia1; + + struct + { + GLuint src0_swz_x:2; + GLuint src0_swz_y:2; + GLuint src0_subreg_nr:1; + GLuint src0_reg_nr:8; + GLuint src0_abs:1; + GLuint src0_negate:1; + GLuint src0_address_mode:1; + GLuint src0_swz_z:2; + GLuint src0_swz_w:2; + GLuint pad0:1; + GLuint src0_vert_stride:4; + GLuint flag_reg_nr:1; + GLuint pad1:6; + } da16; + + struct + { + GLuint src0_swz_x:2; + GLuint src0_swz_y:2; + GLint src0_indirect_offset:6; + GLuint src0_subreg_nr:3; + GLuint src0_abs:1; + GLuint src0_negate:1; + GLuint src0_address_mode:1; + GLuint src0_swz_z:2; + GLuint src0_swz_w:2; + GLuint pad0:1; + GLuint src0_vert_stride:4; + GLuint flag_reg_nr:1; + GLuint pad1:6; + } ia16; + + struct + { + GLuint pad:26; + GLuint end_of_thread:1; + GLuint pad1:1; + GLuint sfid:4; + } send_igdng; /* for IGDNG only */ + + } bits2; + + union + { + struct + { + GLuint src1_subreg_nr:5; + GLuint src1_reg_nr:8; + GLuint src1_abs:1; + GLuint src1_negate:1; + GLuint src1_address_mode:1; + GLuint src1_horiz_stride:2; + GLuint src1_width:3; + GLuint src1_vert_stride:4; + GLuint pad0:7; + } da1; + + struct + { + GLuint src1_swz_x:2; + GLuint src1_swz_y:2; + GLuint src1_subreg_nr:1; + GLuint src1_reg_nr:8; + GLuint src1_abs:1; + GLuint src1_negate:1; + GLuint src1_address_mode:1; + GLuint src1_swz_z:2; + GLuint src1_swz_w:2; + GLuint pad1:1; + GLuint src1_vert_stride:4; + GLuint pad2:7; + } da16; + + struct + { + GLint src1_indirect_offset:10; + GLuint src1_subreg_nr:3; + GLuint src1_abs:1; + GLuint src1_negate:1; + GLuint src1_address_mode:1; + GLuint src1_horiz_stride:2; + GLuint src1_width:3; + GLuint src1_vert_stride:4; + GLuint flag_reg_nr:1; + GLuint pad1:6; + } ia1; + + struct + { + GLuint src1_swz_x:2; + GLuint src1_swz_y:2; + GLint src1_indirect_offset:6; + GLuint src1_subreg_nr:3; + GLuint src1_abs:1; + GLuint src1_negate:1; + GLuint pad0:1; + GLuint src1_swz_z:2; + GLuint src1_swz_w:2; + GLuint pad1:1; + GLuint src1_vert_stride:4; + GLuint flag_reg_nr:1; + GLuint pad2:6; + } ia16; + + + struct + { + GLint jump_count:16; /* note: signed */ + GLuint pop_count:4; + GLuint pad0:12; + } if_else; + + struct { + GLuint function:4; + GLuint int_type:1; + GLuint precision:1; + GLuint saturate:1; + GLuint data_type:1; + GLuint pad0:8; + GLuint response_length:4; + GLuint msg_length:4; + GLuint msg_target:4; + GLuint pad1:3; + GLuint end_of_thread:1; + } math; + + struct { + GLuint function:4; + GLuint int_type:1; + GLuint precision:1; + GLuint saturate:1; + GLuint data_type:1; + GLuint snapshot:1; + GLuint pad0:10; + GLuint header_present:1; + GLuint response_length:5; + GLuint msg_length:4; + GLuint pad1:2; + GLuint end_of_thread:1; + } math_igdng; + + struct { + GLuint binding_table_index:8; + GLuint sampler:4; + GLuint return_format:2; + GLuint msg_type:2; + GLuint response_length:4; + GLuint msg_length:4; + GLuint msg_target:4; + GLuint pad1:3; + GLuint end_of_thread:1; + } sampler; + + struct { + GLuint binding_table_index:8; + GLuint sampler:4; + GLuint msg_type:4; + GLuint response_length:4; + GLuint msg_length:4; + GLuint msg_target:4; + GLuint pad1:3; + GLuint end_of_thread:1; + } sampler_g4x; + + struct { + GLuint binding_table_index:8; + GLuint sampler:4; + GLuint msg_type:4; + GLuint simd_mode:2; + GLuint pad0:1; + GLuint header_present:1; + GLuint response_length:5; + GLuint msg_length:4; + GLuint pad1:2; + GLuint end_of_thread:1; + } sampler_igdng; + + struct brw_urb_immediate urb; + + struct { + GLuint opcode:4; + GLuint offset:6; + GLuint swizzle_control:2; + GLuint pad:1; + GLuint allocate:1; + GLuint used:1; + GLuint complete:1; + GLuint pad0:3; + GLuint header_present:1; + GLuint response_length:5; + GLuint msg_length:4; + GLuint pad1:2; + GLuint end_of_thread:1; + } urb_igdng; + + struct { + GLuint binding_table_index:8; + GLuint msg_control:4; + GLuint msg_type:2; + GLuint target_cache:2; + GLuint response_length:4; + GLuint msg_length:4; + GLuint msg_target:4; + GLuint pad1:3; + GLuint end_of_thread:1; + } dp_read; + + struct { + GLuint binding_table_index:8; + GLuint msg_control:3; + GLuint msg_type:3; + GLuint target_cache:2; + GLuint pad0:3; + GLuint header_present:1; + GLuint response_length:5; + GLuint msg_length:4; + GLuint pad1:2; + GLuint end_of_thread:1; + } dp_read_igdng; + + struct { + GLuint binding_table_index:8; + GLuint msg_control:3; + GLuint pixel_scoreboard_clear:1; + GLuint msg_type:3; + GLuint send_commit_msg:1; + GLuint response_length:4; + GLuint msg_length:4; + GLuint msg_target:4; + GLuint pad1:3; + GLuint end_of_thread:1; + } dp_write; + + struct { + GLuint binding_table_index:8; + GLuint msg_control:3; + GLuint pixel_scoreboard_clear:1; + GLuint msg_type:3; + GLuint send_commit_msg:1; + GLuint pad0:3; + GLuint header_present:1; + GLuint response_length:5; + GLuint msg_length:4; + GLuint pad1:2; + GLuint end_of_thread:1; + } dp_write_igdng; + + struct { + GLuint pad:16; + GLuint response_length:4; + GLuint msg_length:4; + GLuint msg_target:4; + GLuint pad1:3; + GLuint end_of_thread:1; + } generic; + + struct { + GLuint pad:19; + GLuint header_present:1; + GLuint response_length:5; + GLuint msg_length:4; + GLuint pad1:2; + GLuint end_of_thread:1; + } generic_igdng; + + GLint d; + GLuint ud; + float f; + } bits3; +}; + + +#endif diff --git a/src/gallium/drivers/i965/brw_structs_dump.c b/src/gallium/drivers/i965/brw_structs_dump.c new file mode 100644 index 0000000..cd40fc6 --- /dev/null +++ b/src/gallium/drivers/i965/brw_structs_dump.c @@ -0,0 +1,1247 @@ +/************************************************************************** + * + * 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 + * Dump i965 data structures. + * + * Generated automatically from brw_structs.h by brw_structs_dump.py. + */ + +#include "util/u_debug.h" + +#include "brw_types.h" +#include "brw_structs.h" +#include "brw_structs_dump.h" + +void +brw_dump_3d_control(const struct brw_3d_control *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.notify_enable = 0x%x\n", (*ptr).header.notify_enable); + debug_printf("\t\t.header.wc_flush_enable = 0x%x\n", (*ptr).header.wc_flush_enable); + debug_printf("\t\t.header.depth_stall_enable = 0x%x\n", (*ptr).header.depth_stall_enable); + debug_printf("\t\t.header.operation = 0x%x\n", (*ptr).header.operation); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.dest.dest_addr_type = 0x%x\n", (*ptr).dest.dest_addr_type); + debug_printf("\t\t.dest.dest_addr = 0x%x\n", (*ptr).dest.dest_addr); + debug_printf("\t\t.dword2 = 0x%x\n", (*ptr).dword2); + debug_printf("\t\t.dword3 = 0x%x\n", (*ptr).dword3); +} + +void +brw_dump_3d_primitive(const struct brw_3d_primitive *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.topology = 0x%x\n", (*ptr).header.topology); + debug_printf("\t\t.header.indexed = 0x%x\n", (*ptr).header.indexed); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.verts_per_instance = 0x%x\n", (*ptr).verts_per_instance); + debug_printf("\t\t.start_vert_location = 0x%x\n", (*ptr).start_vert_location); + debug_printf("\t\t.instance_count = 0x%x\n", (*ptr).instance_count); + debug_printf("\t\t.start_instance_location = 0x%x\n", (*ptr).start_instance_location); + debug_printf("\t\t.base_vert_location = 0x%x\n", (*ptr).base_vert_location); +} + +void +brw_dump_aa_line_parameters(const struct brw_aa_line_parameters *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.bits0.aa_coverage_scope = 0x%x\n", (*ptr).bits0.aa_coverage_scope); + debug_printf("\t\t.bits0.aa_coverage_bias = 0x%x\n", (*ptr).bits0.aa_coverage_bias); + debug_printf("\t\t.bits1.aa_coverage_endcap_slope = 0x%x\n", (*ptr).bits1.aa_coverage_endcap_slope); + debug_printf("\t\t.bits1.aa_coverage_endcap_bias = 0x%x\n", (*ptr).bits1.aa_coverage_endcap_bias); +} + +void +brw_dump_binding_table_pointers(const struct brw_binding_table_pointers *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.vs = 0x%x\n", (*ptr).vs); + debug_printf("\t\t.gs = 0x%x\n", (*ptr).gs); + debug_printf("\t\t.clp = 0x%x\n", (*ptr).clp); + debug_printf("\t\t.sf = 0x%x\n", (*ptr).sf); + debug_printf("\t\t.wm = 0x%x\n", (*ptr).wm); +} + +void +brw_dump_blend_constant_color(const struct brw_blend_constant_color *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.blend_constant_color[0] = %f\n", (*ptr).blend_constant_color[0]); + debug_printf("\t\t.blend_constant_color[1] = %f\n", (*ptr).blend_constant_color[1]); + debug_printf("\t\t.blend_constant_color[2] = %f\n", (*ptr).blend_constant_color[2]); + debug_printf("\t\t.blend_constant_color[3] = %f\n", (*ptr).blend_constant_color[3]); +} + +void +brw_dump_cc0(const struct brw_cc0 *ptr) +{ + debug_printf("\t\t.bf_stencil_pass_depth_pass_op = 0x%x\n", (*ptr).bf_stencil_pass_depth_pass_op); + debug_printf("\t\t.bf_stencil_pass_depth_fail_op = 0x%x\n", (*ptr).bf_stencil_pass_depth_fail_op); + debug_printf("\t\t.bf_stencil_fail_op = 0x%x\n", (*ptr).bf_stencil_fail_op); + debug_printf("\t\t.bf_stencil_func = 0x%x\n", (*ptr).bf_stencil_func); + debug_printf("\t\t.bf_stencil_enable = 0x%x\n", (*ptr).bf_stencil_enable); + debug_printf("\t\t.stencil_write_enable = 0x%x\n", (*ptr).stencil_write_enable); + debug_printf("\t\t.stencil_pass_depth_pass_op = 0x%x\n", (*ptr).stencil_pass_depth_pass_op); + debug_printf("\t\t.stencil_pass_depth_fail_op = 0x%x\n", (*ptr).stencil_pass_depth_fail_op); + debug_printf("\t\t.stencil_fail_op = 0x%x\n", (*ptr).stencil_fail_op); + debug_printf("\t\t.stencil_func = 0x%x\n", (*ptr).stencil_func); + debug_printf("\t\t.stencil_enable = 0x%x\n", (*ptr).stencil_enable); +} + +void +brw_dump_cc1(const struct brw_cc1 *ptr) +{ + debug_printf("\t\t.bf_stencil_ref = 0x%x\n", (*ptr).bf_stencil_ref); + debug_printf("\t\t.stencil_write_mask = 0x%x\n", (*ptr).stencil_write_mask); + debug_printf("\t\t.stencil_test_mask = 0x%x\n", (*ptr).stencil_test_mask); + debug_printf("\t\t.stencil_ref = 0x%x\n", (*ptr).stencil_ref); +} + +void +brw_dump_cc2(const struct brw_cc2 *ptr) +{ + debug_printf("\t\t.logicop_enable = 0x%x\n", (*ptr).logicop_enable); + debug_printf("\t\t.depth_write_enable = 0x%x\n", (*ptr).depth_write_enable); + debug_printf("\t\t.depth_test_function = 0x%x\n", (*ptr).depth_test_function); + debug_printf("\t\t.depth_test = 0x%x\n", (*ptr).depth_test); + debug_printf("\t\t.bf_stencil_write_mask = 0x%x\n", (*ptr).bf_stencil_write_mask); + debug_printf("\t\t.bf_stencil_test_mask = 0x%x\n", (*ptr).bf_stencil_test_mask); +} + +void +brw_dump_cc3(const struct brw_cc3 *ptr) +{ + debug_printf("\t\t.alpha_test_func = 0x%x\n", (*ptr).alpha_test_func); + debug_printf("\t\t.alpha_test = 0x%x\n", (*ptr).alpha_test); + debug_printf("\t\t.blend_enable = 0x%x\n", (*ptr).blend_enable); + debug_printf("\t\t.ia_blend_enable = 0x%x\n", (*ptr).ia_blend_enable); + debug_printf("\t\t.alpha_test_format = 0x%x\n", (*ptr).alpha_test_format); +} + +void +brw_dump_cc4(const struct brw_cc4 *ptr) +{ + debug_printf("\t\t.cc_viewport_state_offset = 0x%x\n", (*ptr).cc_viewport_state_offset); +} + +void +brw_dump_cc5(const struct brw_cc5 *ptr) +{ + debug_printf("\t\t.ia_dest_blend_factor = 0x%x\n", (*ptr).ia_dest_blend_factor); + debug_printf("\t\t.ia_src_blend_factor = 0x%x\n", (*ptr).ia_src_blend_factor); + debug_printf("\t\t.ia_blend_function = 0x%x\n", (*ptr).ia_blend_function); + debug_printf("\t\t.statistics_enable = 0x%x\n", (*ptr).statistics_enable); + debug_printf("\t\t.logicop_func = 0x%x\n", (*ptr).logicop_func); + debug_printf("\t\t.dither_enable = 0x%x\n", (*ptr).dither_enable); +} + +void +brw_dump_cc6(const struct brw_cc6 *ptr) +{ + debug_printf("\t\t.clamp_post_alpha_blend = 0x%x\n", (*ptr).clamp_post_alpha_blend); + debug_printf("\t\t.clamp_pre_alpha_blend = 0x%x\n", (*ptr).clamp_pre_alpha_blend); + debug_printf("\t\t.clamp_range = 0x%x\n", (*ptr).clamp_range); + debug_printf("\t\t.y_dither_offset = 0x%x\n", (*ptr).y_dither_offset); + debug_printf("\t\t.x_dither_offset = 0x%x\n", (*ptr).x_dither_offset); + debug_printf("\t\t.dest_blend_factor = 0x%x\n", (*ptr).dest_blend_factor); + debug_printf("\t\t.src_blend_factor = 0x%x\n", (*ptr).src_blend_factor); + debug_printf("\t\t.blend_function = 0x%x\n", (*ptr).blend_function); +} + +void +brw_dump_cc7(const struct brw_cc7 *ptr) +{ + debug_printf("\t\t.alpha_ref.f = %f\n", (*ptr).alpha_ref.f); + debug_printf("\t\t.alpha_ref.ub[0] = 0x%x\n", (*ptr).alpha_ref.ub[0]); + debug_printf("\t\t.alpha_ref.ub[1] = 0x%x\n", (*ptr).alpha_ref.ub[1]); + debug_printf("\t\t.alpha_ref.ub[2] = 0x%x\n", (*ptr).alpha_ref.ub[2]); + debug_printf("\t\t.alpha_ref.ub[3] = 0x%x\n", (*ptr).alpha_ref.ub[3]); +} + +void +brw_dump_cc_unit_state(const struct brw_cc_unit_state *ptr) +{ + debug_printf("\t\t.cc0.bf_stencil_pass_depth_pass_op = 0x%x\n", (*ptr).cc0.bf_stencil_pass_depth_pass_op); + debug_printf("\t\t.cc0.bf_stencil_pass_depth_fail_op = 0x%x\n", (*ptr).cc0.bf_stencil_pass_depth_fail_op); + debug_printf("\t\t.cc0.bf_stencil_fail_op = 0x%x\n", (*ptr).cc0.bf_stencil_fail_op); + debug_printf("\t\t.cc0.bf_stencil_func = 0x%x\n", (*ptr).cc0.bf_stencil_func); + debug_printf("\t\t.cc0.bf_stencil_enable = 0x%x\n", (*ptr).cc0.bf_stencil_enable); + debug_printf("\t\t.cc0.stencil_write_enable = 0x%x\n", (*ptr).cc0.stencil_write_enable); + debug_printf("\t\t.cc0.stencil_pass_depth_pass_op = 0x%x\n", (*ptr).cc0.stencil_pass_depth_pass_op); + debug_printf("\t\t.cc0.stencil_pass_depth_fail_op = 0x%x\n", (*ptr).cc0.stencil_pass_depth_fail_op); + debug_printf("\t\t.cc0.stencil_fail_op = 0x%x\n", (*ptr).cc0.stencil_fail_op); + debug_printf("\t\t.cc0.stencil_func = 0x%x\n", (*ptr).cc0.stencil_func); + debug_printf("\t\t.cc0.stencil_enable = 0x%x\n", (*ptr).cc0.stencil_enable); + debug_printf("\t\t.cc1.bf_stencil_ref = 0x%x\n", (*ptr).cc1.bf_stencil_ref); + debug_printf("\t\t.cc1.stencil_write_mask = 0x%x\n", (*ptr).cc1.stencil_write_mask); + debug_printf("\t\t.cc1.stencil_test_mask = 0x%x\n", (*ptr).cc1.stencil_test_mask); + debug_printf("\t\t.cc1.stencil_ref = 0x%x\n", (*ptr).cc1.stencil_ref); + debug_printf("\t\t.cc2.logicop_enable = 0x%x\n", (*ptr).cc2.logicop_enable); + debug_printf("\t\t.cc2.depth_write_enable = 0x%x\n", (*ptr).cc2.depth_write_enable); + debug_printf("\t\t.cc2.depth_test_function = 0x%x\n", (*ptr).cc2.depth_test_function); + debug_printf("\t\t.cc2.depth_test = 0x%x\n", (*ptr).cc2.depth_test); + debug_printf("\t\t.cc2.bf_stencil_write_mask = 0x%x\n", (*ptr).cc2.bf_stencil_write_mask); + debug_printf("\t\t.cc2.bf_stencil_test_mask = 0x%x\n", (*ptr).cc2.bf_stencil_test_mask); + debug_printf("\t\t.cc3.alpha_test_func = 0x%x\n", (*ptr).cc3.alpha_test_func); + debug_printf("\t\t.cc3.alpha_test = 0x%x\n", (*ptr).cc3.alpha_test); + debug_printf("\t\t.cc3.blend_enable = 0x%x\n", (*ptr).cc3.blend_enable); + debug_printf("\t\t.cc3.ia_blend_enable = 0x%x\n", (*ptr).cc3.ia_blend_enable); + debug_printf("\t\t.cc3.alpha_test_format = 0x%x\n", (*ptr).cc3.alpha_test_format); + debug_printf("\t\t.cc4.cc_viewport_state_offset = 0x%x\n", (*ptr).cc4.cc_viewport_state_offset); + debug_printf("\t\t.cc5.ia_dest_blend_factor = 0x%x\n", (*ptr).cc5.ia_dest_blend_factor); + debug_printf("\t\t.cc5.ia_src_blend_factor = 0x%x\n", (*ptr).cc5.ia_src_blend_factor); + debug_printf("\t\t.cc5.ia_blend_function = 0x%x\n", (*ptr).cc5.ia_blend_function); + debug_printf("\t\t.cc5.statistics_enable = 0x%x\n", (*ptr).cc5.statistics_enable); + debug_printf("\t\t.cc5.logicop_func = 0x%x\n", (*ptr).cc5.logicop_func); + debug_printf("\t\t.cc5.dither_enable = 0x%x\n", (*ptr).cc5.dither_enable); + debug_printf("\t\t.cc6.clamp_post_alpha_blend = 0x%x\n", (*ptr).cc6.clamp_post_alpha_blend); + debug_printf("\t\t.cc6.clamp_pre_alpha_blend = 0x%x\n", (*ptr).cc6.clamp_pre_alpha_blend); + debug_printf("\t\t.cc6.clamp_range = 0x%x\n", (*ptr).cc6.clamp_range); + debug_printf("\t\t.cc6.y_dither_offset = 0x%x\n", (*ptr).cc6.y_dither_offset); + debug_printf("\t\t.cc6.x_dither_offset = 0x%x\n", (*ptr).cc6.x_dither_offset); + debug_printf("\t\t.cc6.dest_blend_factor = 0x%x\n", (*ptr).cc6.dest_blend_factor); + debug_printf("\t\t.cc6.src_blend_factor = 0x%x\n", (*ptr).cc6.src_blend_factor); + debug_printf("\t\t.cc6.blend_function = 0x%x\n", (*ptr).cc6.blend_function); + debug_printf("\t\t.cc7.alpha_ref.f = %f\n", (*ptr).cc7.alpha_ref.f); + debug_printf("\t\t.cc7.alpha_ref.ub[0] = 0x%x\n", (*ptr).cc7.alpha_ref.ub[0]); + debug_printf("\t\t.cc7.alpha_ref.ub[1] = 0x%x\n", (*ptr).cc7.alpha_ref.ub[1]); + debug_printf("\t\t.cc7.alpha_ref.ub[2] = 0x%x\n", (*ptr).cc7.alpha_ref.ub[2]); + debug_printf("\t\t.cc7.alpha_ref.ub[3] = 0x%x\n", (*ptr).cc7.alpha_ref.ub[3]); +} + +void +brw_dump_cc_viewport(const struct brw_cc_viewport *ptr) +{ + debug_printf("\t\t.min_depth = %f\n", (*ptr).min_depth); + debug_printf("\t\t.max_depth = %f\n", (*ptr).max_depth); +} + +void +brw_dump_clip_unit_state(const struct brw_clip_unit_state *ptr) +{ + debug_printf("\t\t.thread0.grf_reg_count = 0x%x\n", (*ptr).thread0.grf_reg_count); + debug_printf("\t\t.thread0.kernel_start_pointer = 0x%x\n", (*ptr).thread0.kernel_start_pointer); + debug_printf("\t\t.thread1.sw_exception_enable = 0x%x\n", (*ptr).thread1.sw_exception_enable); + debug_printf("\t\t.thread1.mask_stack_exception_enable = 0x%x\n", (*ptr).thread1.mask_stack_exception_enable); + debug_printf("\t\t.thread1.illegal_op_exception_enable = 0x%x\n", (*ptr).thread1.illegal_op_exception_enable); + debug_printf("\t\t.thread1.floating_point_mode = 0x%x\n", (*ptr).thread1.floating_point_mode); + debug_printf("\t\t.thread1.thread_priority = 0x%x\n", (*ptr).thread1.thread_priority); + debug_printf("\t\t.thread1.binding_table_entry_count = 0x%x\n", (*ptr).thread1.binding_table_entry_count); + debug_printf("\t\t.thread1.single_program_flow = 0x%x\n", (*ptr).thread1.single_program_flow); + debug_printf("\t\t.thread2.per_thread_scratch_space = 0x%x\n", (*ptr).thread2.per_thread_scratch_space); + debug_printf("\t\t.thread2.scratch_space_base_pointer = 0x%x\n", (*ptr).thread2.scratch_space_base_pointer); + debug_printf("\t\t.thread3.dispatch_grf_start_reg = 0x%x\n", (*ptr).thread3.dispatch_grf_start_reg); + debug_printf("\t\t.thread3.urb_entry_read_offset = 0x%x\n", (*ptr).thread3.urb_entry_read_offset); + debug_printf("\t\t.thread3.urb_entry_read_length = 0x%x\n", (*ptr).thread3.urb_entry_read_length); + debug_printf("\t\t.thread3.const_urb_entry_read_offset = 0x%x\n", (*ptr).thread3.const_urb_entry_read_offset); + debug_printf("\t\t.thread3.const_urb_entry_read_length = 0x%x\n", (*ptr).thread3.const_urb_entry_read_length); + debug_printf("\t\t.thread4.gs_output_stats = 0x%x\n", (*ptr).thread4.gs_output_stats); + debug_printf("\t\t.thread4.stats_enable = 0x%x\n", (*ptr).thread4.stats_enable); + debug_printf("\t\t.thread4.nr_urb_entries = 0x%x\n", (*ptr).thread4.nr_urb_entries); + debug_printf("\t\t.thread4.urb_entry_allocation_size = 0x%x\n", (*ptr).thread4.urb_entry_allocation_size); + debug_printf("\t\t.thread4.max_threads = 0x%x\n", (*ptr).thread4.max_threads); + debug_printf("\t\t.clip5.clip_mode = 0x%x\n", (*ptr).clip5.clip_mode); + debug_printf("\t\t.clip5.userclip_enable_flags = 0x%x\n", (*ptr).clip5.userclip_enable_flags); + debug_printf("\t\t.clip5.userclip_must_clip = 0x%x\n", (*ptr).clip5.userclip_must_clip); + debug_printf("\t\t.clip5.negative_w_clip_test = 0x%x\n", (*ptr).clip5.negative_w_clip_test); + debug_printf("\t\t.clip5.guard_band_enable = 0x%x\n", (*ptr).clip5.guard_band_enable); + debug_printf("\t\t.clip5.viewport_z_clip_enable = 0x%x\n", (*ptr).clip5.viewport_z_clip_enable); + debug_printf("\t\t.clip5.viewport_xy_clip_enable = 0x%x\n", (*ptr).clip5.viewport_xy_clip_enable); + debug_printf("\t\t.clip5.vertex_position_space = 0x%x\n", (*ptr).clip5.vertex_position_space); + debug_printf("\t\t.clip5.api_mode = 0x%x\n", (*ptr).clip5.api_mode); + debug_printf("\t\t.clip6.clipper_viewport_state_ptr = 0x%x\n", (*ptr).clip6.clipper_viewport_state_ptr); + debug_printf("\t\t.viewport_xmin = %f\n", (*ptr).viewport_xmin); + debug_printf("\t\t.viewport_xmax = %f\n", (*ptr).viewport_xmax); + debug_printf("\t\t.viewport_ymin = %f\n", (*ptr).viewport_ymin); + debug_printf("\t\t.viewport_ymax = %f\n", (*ptr).viewport_ymax); +} + +void +brw_dump_clipper_viewport(const struct brw_clipper_viewport *ptr) +{ + debug_printf("\t\t.xmin = %f\n", (*ptr).xmin); + debug_printf("\t\t.xmax = %f\n", (*ptr).xmax); + debug_printf("\t\t.ymin = %f\n", (*ptr).ymin); + debug_printf("\t\t.ymax = %f\n", (*ptr).ymax); +} + +void +brw_dump_constant_buffer(const struct brw_constant_buffer *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.valid = 0x%x\n", (*ptr).header.valid); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.bits0.buffer_length = 0x%x\n", (*ptr).bits0.buffer_length); + debug_printf("\t\t.bits0.buffer_address = 0x%x\n", (*ptr).bits0.buffer_address); +} + +void +brw_dump_cs_urb_state(const struct brw_cs_urb_state *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.bits0.nr_urb_entries = 0x%x\n", (*ptr).bits0.nr_urb_entries); + debug_printf("\t\t.bits0.urb_entry_size = 0x%x\n", (*ptr).bits0.urb_entry_size); +} + +void +brw_dump_depthbuffer(const struct brw_depthbuffer *ptr) +{ + debug_printf("\t\t.header.bits.length = 0x%x\n", (*ptr).header.bits.length); + debug_printf("\t\t.header.bits.opcode = 0x%x\n", (*ptr).header.bits.opcode); + debug_printf("\t\t.dword1.bits.pitch = 0x%x\n", (*ptr).dword1.bits.pitch); + debug_printf("\t\t.dword1.bits.format = 0x%x\n", (*ptr).dword1.bits.format); + debug_printf("\t\t.dword1.bits.software_tiled_rendering_mode = 0x%x\n", (*ptr).dword1.bits.software_tiled_rendering_mode); + debug_printf("\t\t.dword1.bits.depth_offset_disable = 0x%x\n", (*ptr).dword1.bits.depth_offset_disable); + debug_printf("\t\t.dword1.bits.tile_walk = 0x%x\n", (*ptr).dword1.bits.tile_walk); + debug_printf("\t\t.dword1.bits.tiled_surface = 0x%x\n", (*ptr).dword1.bits.tiled_surface); + debug_printf("\t\t.dword1.bits.surface_type = 0x%x\n", (*ptr).dword1.bits.surface_type); + debug_printf("\t\t.dword2_base_addr = 0x%x\n", (*ptr).dword2_base_addr); + debug_printf("\t\t.dword3.bits.mipmap_layout = 0x%x\n", (*ptr).dword3.bits.mipmap_layout); + debug_printf("\t\t.dword3.bits.lod = 0x%x\n", (*ptr).dword3.bits.lod); + debug_printf("\t\t.dword3.bits.width = 0x%x\n", (*ptr).dword3.bits.width); + debug_printf("\t\t.dword3.bits.height = 0x%x\n", (*ptr).dword3.bits.height); + debug_printf("\t\t.dword4.bits.min_array_element = 0x%x\n", (*ptr).dword4.bits.min_array_element); + debug_printf("\t\t.dword4.bits.depth = 0x%x\n", (*ptr).dword4.bits.depth); +} + +void +brw_dump_depthbuffer_g4x(const struct brw_depthbuffer_g4x *ptr) +{ + debug_printf("\t\t.header.bits.length = 0x%x\n", (*ptr).header.bits.length); + debug_printf("\t\t.header.bits.opcode = 0x%x\n", (*ptr).header.bits.opcode); + debug_printf("\t\t.dword1.bits.pitch = 0x%x\n", (*ptr).dword1.bits.pitch); + debug_printf("\t\t.dword1.bits.format = 0x%x\n", (*ptr).dword1.bits.format); + debug_printf("\t\t.dword1.bits.software_tiled_rendering_mode = 0x%x\n", (*ptr).dword1.bits.software_tiled_rendering_mode); + debug_printf("\t\t.dword1.bits.depth_offset_disable = 0x%x\n", (*ptr).dword1.bits.depth_offset_disable); + debug_printf("\t\t.dword1.bits.tile_walk = 0x%x\n", (*ptr).dword1.bits.tile_walk); + debug_printf("\t\t.dword1.bits.tiled_surface = 0x%x\n", (*ptr).dword1.bits.tiled_surface); + debug_printf("\t\t.dword1.bits.surface_type = 0x%x\n", (*ptr).dword1.bits.surface_type); + debug_printf("\t\t.dword2_base_addr = 0x%x\n", (*ptr).dword2_base_addr); + debug_printf("\t\t.dword3.bits.mipmap_layout = 0x%x\n", (*ptr).dword3.bits.mipmap_layout); + debug_printf("\t\t.dword3.bits.lod = 0x%x\n", (*ptr).dword3.bits.lod); + debug_printf("\t\t.dword3.bits.width = 0x%x\n", (*ptr).dword3.bits.width); + debug_printf("\t\t.dword3.bits.height = 0x%x\n", (*ptr).dword3.bits.height); + debug_printf("\t\t.dword4.bits.min_array_element = 0x%x\n", (*ptr).dword4.bits.min_array_element); + debug_printf("\t\t.dword4.bits.depth = 0x%x\n", (*ptr).dword4.bits.depth); + debug_printf("\t\t.dword5.bits.xoffset = 0x%x\n", (*ptr).dword5.bits.xoffset); + debug_printf("\t\t.dword5.bits.yoffset = 0x%x\n", (*ptr).dword5.bits.yoffset); +} + +void +brw_dump_drawrect(const struct brw_drawrect *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.xmin = 0x%x\n", (*ptr).xmin); + debug_printf("\t\t.ymin = 0x%x\n", (*ptr).ymin); + debug_printf("\t\t.xmax = 0x%x\n", (*ptr).xmax); + debug_printf("\t\t.ymax = 0x%x\n", (*ptr).ymax); + debug_printf("\t\t.xorg = 0x%x\n", (*ptr).xorg); + debug_printf("\t\t.yorg = 0x%x\n", (*ptr).yorg); +} + +void +brw_dump_global_depth_offset_clamp(const struct brw_global_depth_offset_clamp *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.depth_offset_clamp = %f\n", (*ptr).depth_offset_clamp); +} + +void +brw_dump_gs_unit_state(const struct brw_gs_unit_state *ptr) +{ + debug_printf("\t\t.thread0.grf_reg_count = 0x%x\n", (*ptr).thread0.grf_reg_count); + debug_printf("\t\t.thread0.kernel_start_pointer = 0x%x\n", (*ptr).thread0.kernel_start_pointer); + debug_printf("\t\t.thread1.ext_halt_exception_enable = 0x%x\n", (*ptr).thread1.ext_halt_exception_enable); + debug_printf("\t\t.thread1.sw_exception_enable = 0x%x\n", (*ptr).thread1.sw_exception_enable); + debug_printf("\t\t.thread1.mask_stack_exception_enable = 0x%x\n", (*ptr).thread1.mask_stack_exception_enable); + debug_printf("\t\t.thread1.timeout_exception_enable = 0x%x\n", (*ptr).thread1.timeout_exception_enable); + debug_printf("\t\t.thread1.illegal_op_exception_enable = 0x%x\n", (*ptr).thread1.illegal_op_exception_enable); + debug_printf("\t\t.thread1.depth_coef_urb_read_offset = 0x%x\n", (*ptr).thread1.depth_coef_urb_read_offset); + debug_printf("\t\t.thread1.floating_point_mode = 0x%x\n", (*ptr).thread1.floating_point_mode); + debug_printf("\t\t.thread1.thread_priority = 0x%x\n", (*ptr).thread1.thread_priority); + debug_printf("\t\t.thread1.binding_table_entry_count = 0x%x\n", (*ptr).thread1.binding_table_entry_count); + debug_printf("\t\t.thread1.single_program_flow = 0x%x\n", (*ptr).thread1.single_program_flow); + debug_printf("\t\t.thread2.per_thread_scratch_space = 0x%x\n", (*ptr).thread2.per_thread_scratch_space); + debug_printf("\t\t.thread2.scratch_space_base_pointer = 0x%x\n", (*ptr).thread2.scratch_space_base_pointer); + debug_printf("\t\t.thread3.dispatch_grf_start_reg = 0x%x\n", (*ptr).thread3.dispatch_grf_start_reg); + debug_printf("\t\t.thread3.urb_entry_read_offset = 0x%x\n", (*ptr).thread3.urb_entry_read_offset); + debug_printf("\t\t.thread3.urb_entry_read_length = 0x%x\n", (*ptr).thread3.urb_entry_read_length); + debug_printf("\t\t.thread3.const_urb_entry_read_offset = 0x%x\n", (*ptr).thread3.const_urb_entry_read_offset); + debug_printf("\t\t.thread3.const_urb_entry_read_length = 0x%x\n", (*ptr).thread3.const_urb_entry_read_length); + debug_printf("\t\t.thread4.rendering_enable = 0x%x\n", (*ptr).thread4.rendering_enable); + debug_printf("\t\t.thread4.stats_enable = 0x%x\n", (*ptr).thread4.stats_enable); + debug_printf("\t\t.thread4.nr_urb_entries = 0x%x\n", (*ptr).thread4.nr_urb_entries); + debug_printf("\t\t.thread4.urb_entry_allocation_size = 0x%x\n", (*ptr).thread4.urb_entry_allocation_size); + debug_printf("\t\t.thread4.max_threads = 0x%x\n", (*ptr).thread4.max_threads); + debug_printf("\t\t.gs5.sampler_count = 0x%x\n", (*ptr).gs5.sampler_count); + debug_printf("\t\t.gs5.sampler_state_pointer = 0x%x\n", (*ptr).gs5.sampler_state_pointer); + debug_printf("\t\t.gs6.max_vp_index = 0x%x\n", (*ptr).gs6.max_vp_index); + debug_printf("\t\t.gs6.svbi_post_inc_value = 0x%x\n", (*ptr).gs6.svbi_post_inc_value); + debug_printf("\t\t.gs6.svbi_post_inc_enable = 0x%x\n", (*ptr).gs6.svbi_post_inc_enable); + debug_printf("\t\t.gs6.svbi_payload = 0x%x\n", (*ptr).gs6.svbi_payload); + debug_printf("\t\t.gs6.discard_adjaceny = 0x%x\n", (*ptr).gs6.discard_adjaceny); + debug_printf("\t\t.gs6.reorder_enable = 0x%x\n", (*ptr).gs6.reorder_enable); +} + +void +brw_dump_indexbuffer(const struct brw_indexbuffer *ptr) +{ + debug_printf("\t\t.header.bits.length = 0x%x\n", (*ptr).header.bits.length); + debug_printf("\t\t.header.bits.index_format = 0x%x\n", (*ptr).header.bits.index_format); + debug_printf("\t\t.header.bits.cut_index_enable = 0x%x\n", (*ptr).header.bits.cut_index_enable); + debug_printf("\t\t.header.bits.opcode = 0x%x\n", (*ptr).header.bits.opcode); + debug_printf("\t\t.buffer_start = 0x%x\n", (*ptr).buffer_start); + debug_printf("\t\t.buffer_end = 0x%x\n", (*ptr).buffer_end); +} + +void +brw_dump_line_stipple(const struct brw_line_stipple *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.bits0.pattern = 0x%x\n", (*ptr).bits0.pattern); + debug_printf("\t\t.bits1.repeat_count = 0x%x\n", (*ptr).bits1.repeat_count); + debug_printf("\t\t.bits1.inverse_repeat_count = 0x%x\n", (*ptr).bits1.inverse_repeat_count); +} + +void +brw_dump_mi_flush(const struct brw_mi_flush *ptr) +{ + debug_printf("\t\t.flags = 0x%x\n", (*ptr).flags); + debug_printf("\t\t.opcode = 0x%x\n", (*ptr).opcode); +} + +void +brw_dump_pipe_control(const struct brw_pipe_control *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.notify_enable = 0x%x\n", (*ptr).header.notify_enable); + debug_printf("\t\t.header.texture_cache_flush_enable = 0x%x\n", (*ptr).header.texture_cache_flush_enable); + debug_printf("\t\t.header.indirect_state_pointers_disable = 0x%x\n", (*ptr).header.indirect_state_pointers_disable); + debug_printf("\t\t.header.instruction_state_cache_flush_enable = 0x%x\n", (*ptr).header.instruction_state_cache_flush_enable); + debug_printf("\t\t.header.write_cache_flush_enable = 0x%x\n", (*ptr).header.write_cache_flush_enable); + debug_printf("\t\t.header.depth_stall_enable = 0x%x\n", (*ptr).header.depth_stall_enable); + debug_printf("\t\t.header.post_sync_operation = 0x%x\n", (*ptr).header.post_sync_operation); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.bits1.dest_addr_type = 0x%x\n", (*ptr).bits1.dest_addr_type); + debug_printf("\t\t.bits1.dest_addr = 0x%x\n", (*ptr).bits1.dest_addr); + debug_printf("\t\t.data0 = 0x%x\n", (*ptr).data0); + debug_printf("\t\t.data1 = 0x%x\n", (*ptr).data1); +} + +void +brw_dump_pipeline_select(const struct brw_pipeline_select *ptr) +{ + debug_printf("\t\t.header.pipeline_select = 0x%x\n", (*ptr).header.pipeline_select); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); +} + +void +brw_dump_pipelined_state_pointers(const struct brw_pipelined_state_pointers *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.vs.offset = 0x%x\n", (*ptr).vs.offset); + debug_printf("\t\t.gs.enable = 0x%x\n", (*ptr).gs.enable); + debug_printf("\t\t.gs.offset = 0x%x\n", (*ptr).gs.offset); + debug_printf("\t\t.clp.enable = 0x%x\n", (*ptr).clp.enable); + debug_printf("\t\t.clp.offset = 0x%x\n", (*ptr).clp.offset); + debug_printf("\t\t.sf.offset = 0x%x\n", (*ptr).sf.offset); + debug_printf("\t\t.wm.offset = 0x%x\n", (*ptr).wm.offset); + debug_printf("\t\t.cc.offset = 0x%x\n", (*ptr).cc.offset); +} + +void +brw_dump_polygon_stipple(const struct brw_polygon_stipple *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.stipple[0] = 0x%x\n", (*ptr).stipple[0]); + debug_printf("\t\t.stipple[1] = 0x%x\n", (*ptr).stipple[1]); + debug_printf("\t\t.stipple[2] = 0x%x\n", (*ptr).stipple[2]); + debug_printf("\t\t.stipple[3] = 0x%x\n", (*ptr).stipple[3]); + debug_printf("\t\t.stipple[4] = 0x%x\n", (*ptr).stipple[4]); + debug_printf("\t\t.stipple[5] = 0x%x\n", (*ptr).stipple[5]); + debug_printf("\t\t.stipple[6] = 0x%x\n", (*ptr).stipple[6]); + debug_printf("\t\t.stipple[7] = 0x%x\n", (*ptr).stipple[7]); + debug_printf("\t\t.stipple[8] = 0x%x\n", (*ptr).stipple[8]); + debug_printf("\t\t.stipple[9] = 0x%x\n", (*ptr).stipple[9]); + debug_printf("\t\t.stipple[10] = 0x%x\n", (*ptr).stipple[10]); + debug_printf("\t\t.stipple[11] = 0x%x\n", (*ptr).stipple[11]); + debug_printf("\t\t.stipple[12] = 0x%x\n", (*ptr).stipple[12]); + debug_printf("\t\t.stipple[13] = 0x%x\n", (*ptr).stipple[13]); + debug_printf("\t\t.stipple[14] = 0x%x\n", (*ptr).stipple[14]); + debug_printf("\t\t.stipple[15] = 0x%x\n", (*ptr).stipple[15]); + debug_printf("\t\t.stipple[16] = 0x%x\n", (*ptr).stipple[16]); + debug_printf("\t\t.stipple[17] = 0x%x\n", (*ptr).stipple[17]); + debug_printf("\t\t.stipple[18] = 0x%x\n", (*ptr).stipple[18]); + debug_printf("\t\t.stipple[19] = 0x%x\n", (*ptr).stipple[19]); + debug_printf("\t\t.stipple[20] = 0x%x\n", (*ptr).stipple[20]); + debug_printf("\t\t.stipple[21] = 0x%x\n", (*ptr).stipple[21]); + debug_printf("\t\t.stipple[22] = 0x%x\n", (*ptr).stipple[22]); + debug_printf("\t\t.stipple[23] = 0x%x\n", (*ptr).stipple[23]); + debug_printf("\t\t.stipple[24] = 0x%x\n", (*ptr).stipple[24]); + debug_printf("\t\t.stipple[25] = 0x%x\n", (*ptr).stipple[25]); + debug_printf("\t\t.stipple[26] = 0x%x\n", (*ptr).stipple[26]); + debug_printf("\t\t.stipple[27] = 0x%x\n", (*ptr).stipple[27]); + debug_printf("\t\t.stipple[28] = 0x%x\n", (*ptr).stipple[28]); + debug_printf("\t\t.stipple[29] = 0x%x\n", (*ptr).stipple[29]); + debug_printf("\t\t.stipple[30] = 0x%x\n", (*ptr).stipple[30]); + debug_printf("\t\t.stipple[31] = 0x%x\n", (*ptr).stipple[31]); +} + +void +brw_dump_polygon_stipple_offset(const struct brw_polygon_stipple_offset *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.bits0.y_offset = 0x%x\n", (*ptr).bits0.y_offset); + debug_printf("\t\t.bits0.x_offset = 0x%x\n", (*ptr).bits0.x_offset); +} + +void +brw_dump_sampler_default_color(const struct brw_sampler_default_color *ptr) +{ + debug_printf("\t\t.color[0] = %f\n", (*ptr).color[0]); + debug_printf("\t\t.color[1] = %f\n", (*ptr).color[1]); + debug_printf("\t\t.color[2] = %f\n", (*ptr).color[2]); + debug_printf("\t\t.color[3] = %f\n", (*ptr).color[3]); +} + +void +brw_dump_sampler_state(const struct brw_sampler_state *ptr) +{ + debug_printf("\t\t.ss0.shadow_function = 0x%x\n", (*ptr).ss0.shadow_function); + debug_printf("\t\t.ss0.lod_bias = 0x%x\n", (*ptr).ss0.lod_bias); + debug_printf("\t\t.ss0.min_filter = 0x%x\n", (*ptr).ss0.min_filter); + debug_printf("\t\t.ss0.mag_filter = 0x%x\n", (*ptr).ss0.mag_filter); + debug_printf("\t\t.ss0.mip_filter = 0x%x\n", (*ptr).ss0.mip_filter); + debug_printf("\t\t.ss0.base_level = 0x%x\n", (*ptr).ss0.base_level); + debug_printf("\t\t.ss0.lod_preclamp = 0x%x\n", (*ptr).ss0.lod_preclamp); + debug_printf("\t\t.ss0.default_color_mode = 0x%x\n", (*ptr).ss0.default_color_mode); + debug_printf("\t\t.ss0.disable = 0x%x\n", (*ptr).ss0.disable); + debug_printf("\t\t.ss1.r_wrap_mode = 0x%x\n", (*ptr).ss1.r_wrap_mode); + debug_printf("\t\t.ss1.t_wrap_mode = 0x%x\n", (*ptr).ss1.t_wrap_mode); + debug_printf("\t\t.ss1.s_wrap_mode = 0x%x\n", (*ptr).ss1.s_wrap_mode); + debug_printf("\t\t.ss1.max_lod = 0x%x\n", (*ptr).ss1.max_lod); + debug_printf("\t\t.ss1.min_lod = 0x%x\n", (*ptr).ss1.min_lod); + debug_printf("\t\t.ss2.default_color_pointer = 0x%x\n", (*ptr).ss2.default_color_pointer); + debug_printf("\t\t.ss3.max_aniso = 0x%x\n", (*ptr).ss3.max_aniso); + debug_printf("\t\t.ss3.chroma_key_mode = 0x%x\n", (*ptr).ss3.chroma_key_mode); + debug_printf("\t\t.ss3.chroma_key_index = 0x%x\n", (*ptr).ss3.chroma_key_index); + debug_printf("\t\t.ss3.chroma_key_enable = 0x%x\n", (*ptr).ss3.chroma_key_enable); + debug_printf("\t\t.ss3.monochrome_filter_width = 0x%x\n", (*ptr).ss3.monochrome_filter_width); + debug_printf("\t\t.ss3.monochrome_filter_height = 0x%x\n", (*ptr).ss3.monochrome_filter_height); +} + +void +brw_dump_sf_unit_state(const struct brw_sf_unit_state *ptr) +{ + debug_printf("\t\t.thread0.grf_reg_count = 0x%x\n", (*ptr).thread0.grf_reg_count); + debug_printf("\t\t.thread0.kernel_start_pointer = 0x%x\n", (*ptr).thread0.kernel_start_pointer); + debug_printf("\t\t.thread1.ext_halt_exception_enable = 0x%x\n", (*ptr).thread1.ext_halt_exception_enable); + debug_printf("\t\t.thread1.sw_exception_enable = 0x%x\n", (*ptr).thread1.sw_exception_enable); + debug_printf("\t\t.thread1.mask_stack_exception_enable = 0x%x\n", (*ptr).thread1.mask_stack_exception_enable); + debug_printf("\t\t.thread1.timeout_exception_enable = 0x%x\n", (*ptr).thread1.timeout_exception_enable); + debug_printf("\t\t.thread1.illegal_op_exception_enable = 0x%x\n", (*ptr).thread1.illegal_op_exception_enable); + debug_printf("\t\t.thread1.depth_coef_urb_read_offset = 0x%x\n", (*ptr).thread1.depth_coef_urb_read_offset); + debug_printf("\t\t.thread1.floating_point_mode = 0x%x\n", (*ptr).thread1.floating_point_mode); + debug_printf("\t\t.thread1.thread_priority = 0x%x\n", (*ptr).thread1.thread_priority); + debug_printf("\t\t.thread1.binding_table_entry_count = 0x%x\n", (*ptr).thread1.binding_table_entry_count); + debug_printf("\t\t.thread1.single_program_flow = 0x%x\n", (*ptr).thread1.single_program_flow); + debug_printf("\t\t.thread2.per_thread_scratch_space = 0x%x\n", (*ptr).thread2.per_thread_scratch_space); + debug_printf("\t\t.thread2.scratch_space_base_pointer = 0x%x\n", (*ptr).thread2.scratch_space_base_pointer); + debug_printf("\t\t.thread3.dispatch_grf_start_reg = 0x%x\n", (*ptr).thread3.dispatch_grf_start_reg); + debug_printf("\t\t.thread3.urb_entry_read_offset = 0x%x\n", (*ptr).thread3.urb_entry_read_offset); + debug_printf("\t\t.thread3.urb_entry_read_length = 0x%x\n", (*ptr).thread3.urb_entry_read_length); + debug_printf("\t\t.thread3.const_urb_entry_read_offset = 0x%x\n", (*ptr).thread3.const_urb_entry_read_offset); + debug_printf("\t\t.thread3.const_urb_entry_read_length = 0x%x\n", (*ptr).thread3.const_urb_entry_read_length); + debug_printf("\t\t.thread4.stats_enable = 0x%x\n", (*ptr).thread4.stats_enable); + debug_printf("\t\t.thread4.nr_urb_entries = 0x%x\n", (*ptr).thread4.nr_urb_entries); + debug_printf("\t\t.thread4.urb_entry_allocation_size = 0x%x\n", (*ptr).thread4.urb_entry_allocation_size); + debug_printf("\t\t.thread4.max_threads = 0x%x\n", (*ptr).thread4.max_threads); + debug_printf("\t\t.sf5.front_winding = 0x%x\n", (*ptr).sf5.front_winding); + debug_printf("\t\t.sf5.viewport_transform = 0x%x\n", (*ptr).sf5.viewport_transform); + debug_printf("\t\t.sf5.sf_viewport_state_offset = 0x%x\n", (*ptr).sf5.sf_viewport_state_offset); + debug_printf("\t\t.sf6.dest_org_vbias = 0x%x\n", (*ptr).sf6.dest_org_vbias); + debug_printf("\t\t.sf6.dest_org_hbias = 0x%x\n", (*ptr).sf6.dest_org_hbias); + debug_printf("\t\t.sf6.scissor = 0x%x\n", (*ptr).sf6.scissor); + debug_printf("\t\t.sf6.disable_2x2_trifilter = 0x%x\n", (*ptr).sf6.disable_2x2_trifilter); + debug_printf("\t\t.sf6.disable_zero_pix_trifilter = 0x%x\n", (*ptr).sf6.disable_zero_pix_trifilter); + debug_printf("\t\t.sf6.point_rast_rule = 0x%x\n", (*ptr).sf6.point_rast_rule); + debug_printf("\t\t.sf6.line_endcap_aa_region_width = 0x%x\n", (*ptr).sf6.line_endcap_aa_region_width); + debug_printf("\t\t.sf6.line_width = 0x%x\n", (*ptr).sf6.line_width); + debug_printf("\t\t.sf6.fast_scissor_disable = 0x%x\n", (*ptr).sf6.fast_scissor_disable); + debug_printf("\t\t.sf6.cull_mode = 0x%x\n", (*ptr).sf6.cull_mode); + debug_printf("\t\t.sf6.aa_enable = 0x%x\n", (*ptr).sf6.aa_enable); + debug_printf("\t\t.sf7.point_size = 0x%x\n", (*ptr).sf7.point_size); + debug_printf("\t\t.sf7.use_point_size_state = 0x%x\n", (*ptr).sf7.use_point_size_state); + debug_printf("\t\t.sf7.subpixel_precision = 0x%x\n", (*ptr).sf7.subpixel_precision); + debug_printf("\t\t.sf7.sprite_point = 0x%x\n", (*ptr).sf7.sprite_point); + debug_printf("\t\t.sf7.aa_line_distance_mode = 0x%x\n", (*ptr).sf7.aa_line_distance_mode); + debug_printf("\t\t.sf7.trifan_pv = 0x%x\n", (*ptr).sf7.trifan_pv); + debug_printf("\t\t.sf7.linestrip_pv = 0x%x\n", (*ptr).sf7.linestrip_pv); + debug_printf("\t\t.sf7.tristrip_pv = 0x%x\n", (*ptr).sf7.tristrip_pv); + debug_printf("\t\t.sf7.line_last_pixel_enable = 0x%x\n", (*ptr).sf7.line_last_pixel_enable); +} + +void +brw_dump_sf_viewport(const struct brw_sf_viewport *ptr) +{ + debug_printf("\t\t.viewport.m00 = %f\n", (*ptr).viewport.m00); + debug_printf("\t\t.viewport.m11 = %f\n", (*ptr).viewport.m11); + debug_printf("\t\t.viewport.m22 = %f\n", (*ptr).viewport.m22); + debug_printf("\t\t.viewport.m30 = %f\n", (*ptr).viewport.m30); + debug_printf("\t\t.viewport.m31 = %f\n", (*ptr).viewport.m31); + debug_printf("\t\t.viewport.m32 = %f\n", (*ptr).viewport.m32); + debug_printf("\t\t.scissor.xmin = 0x%x\n", (*ptr).scissor.xmin); + debug_printf("\t\t.scissor.ymin = 0x%x\n", (*ptr).scissor.ymin); + debug_printf("\t\t.scissor.xmax = 0x%x\n", (*ptr).scissor.xmax); + debug_printf("\t\t.scissor.ymax = 0x%x\n", (*ptr).scissor.ymax); +} + +void +brw_dump_ss0(const struct brw_ss0 *ptr) +{ + debug_printf("\t\t.shadow_function = 0x%x\n", (*ptr).shadow_function); + debug_printf("\t\t.lod_bias = 0x%x\n", (*ptr).lod_bias); + debug_printf("\t\t.min_filter = 0x%x\n", (*ptr).min_filter); + debug_printf("\t\t.mag_filter = 0x%x\n", (*ptr).mag_filter); + debug_printf("\t\t.mip_filter = 0x%x\n", (*ptr).mip_filter); + debug_printf("\t\t.base_level = 0x%x\n", (*ptr).base_level); + debug_printf("\t\t.lod_preclamp = 0x%x\n", (*ptr).lod_preclamp); + debug_printf("\t\t.default_color_mode = 0x%x\n", (*ptr).default_color_mode); + debug_printf("\t\t.disable = 0x%x\n", (*ptr).disable); +} + +void +brw_dump_ss1(const struct brw_ss1 *ptr) +{ + debug_printf("\t\t.r_wrap_mode = 0x%x\n", (*ptr).r_wrap_mode); + debug_printf("\t\t.t_wrap_mode = 0x%x\n", (*ptr).t_wrap_mode); + debug_printf("\t\t.s_wrap_mode = 0x%x\n", (*ptr).s_wrap_mode); + debug_printf("\t\t.max_lod = 0x%x\n", (*ptr).max_lod); + debug_printf("\t\t.min_lod = 0x%x\n", (*ptr).min_lod); +} + +void +brw_dump_ss2(const struct brw_ss2 *ptr) +{ + debug_printf("\t\t.default_color_pointer = 0x%x\n", (*ptr).default_color_pointer); +} + +void +brw_dump_ss3(const struct brw_ss3 *ptr) +{ + debug_printf("\t\t.max_aniso = 0x%x\n", (*ptr).max_aniso); + debug_printf("\t\t.chroma_key_mode = 0x%x\n", (*ptr).chroma_key_mode); + debug_printf("\t\t.chroma_key_index = 0x%x\n", (*ptr).chroma_key_index); + debug_printf("\t\t.chroma_key_enable = 0x%x\n", (*ptr).chroma_key_enable); + debug_printf("\t\t.monochrome_filter_width = 0x%x\n", (*ptr).monochrome_filter_width); + debug_printf("\t\t.monochrome_filter_height = 0x%x\n", (*ptr).monochrome_filter_height); +} + +void +brw_dump_state_base_address(const struct brw_state_base_address *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.bits0.modify_enable = 0x%x\n", (*ptr).bits0.modify_enable); + debug_printf("\t\t.bits0.general_state_address = 0x%x\n", (*ptr).bits0.general_state_address); + debug_printf("\t\t.bits1.modify_enable = 0x%x\n", (*ptr).bits1.modify_enable); + debug_printf("\t\t.bits1.surface_state_address = 0x%x\n", (*ptr).bits1.surface_state_address); + debug_printf("\t\t.bits2.modify_enable = 0x%x\n", (*ptr).bits2.modify_enable); + debug_printf("\t\t.bits2.indirect_object_state_address = 0x%x\n", (*ptr).bits2.indirect_object_state_address); + debug_printf("\t\t.bits3.modify_enable = 0x%x\n", (*ptr).bits3.modify_enable); + debug_printf("\t\t.bits3.general_state_upper_bound = 0x%x\n", (*ptr).bits3.general_state_upper_bound); + debug_printf("\t\t.bits4.modify_enable = 0x%x\n", (*ptr).bits4.modify_enable); + debug_printf("\t\t.bits4.indirect_object_state_upper_bound = 0x%x\n", (*ptr).bits4.indirect_object_state_upper_bound); +} + +void +brw_dump_state_prefetch(const struct brw_state_prefetch *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.bits0.prefetch_count = 0x%x\n", (*ptr).bits0.prefetch_count); + debug_printf("\t\t.bits0.prefetch_pointer = 0x%x\n", (*ptr).bits0.prefetch_pointer); +} + +void +brw_dump_surf_ss0(const struct brw_surf_ss0 *ptr) +{ + debug_printf("\t\t.cube_pos_z = 0x%x\n", (*ptr).cube_pos_z); + debug_printf("\t\t.cube_neg_z = 0x%x\n", (*ptr).cube_neg_z); + debug_printf("\t\t.cube_pos_y = 0x%x\n", (*ptr).cube_pos_y); + debug_printf("\t\t.cube_neg_y = 0x%x\n", (*ptr).cube_neg_y); + debug_printf("\t\t.cube_pos_x = 0x%x\n", (*ptr).cube_pos_x); + debug_printf("\t\t.cube_neg_x = 0x%x\n", (*ptr).cube_neg_x); + debug_printf("\t\t.mipmap_layout_mode = 0x%x\n", (*ptr).mipmap_layout_mode); + debug_printf("\t\t.vert_line_stride_ofs = 0x%x\n", (*ptr).vert_line_stride_ofs); + debug_printf("\t\t.vert_line_stride = 0x%x\n", (*ptr).vert_line_stride); + debug_printf("\t\t.color_blend = 0x%x\n", (*ptr).color_blend); + debug_printf("\t\t.writedisable_blue = 0x%x\n", (*ptr).writedisable_blue); + debug_printf("\t\t.writedisable_green = 0x%x\n", (*ptr).writedisable_green); + debug_printf("\t\t.writedisable_red = 0x%x\n", (*ptr).writedisable_red); + debug_printf("\t\t.writedisable_alpha = 0x%x\n", (*ptr).writedisable_alpha); + debug_printf("\t\t.surface_format = 0x%x\n", (*ptr).surface_format); + debug_printf("\t\t.data_return_format = 0x%x\n", (*ptr).data_return_format); + debug_printf("\t\t.surface_type = 0x%x\n", (*ptr).surface_type); +} + +void +brw_dump_surf_ss1(const struct brw_surf_ss1 *ptr) +{ + debug_printf("\t\t.base_addr = 0x%x\n", (*ptr).base_addr); +} + +void +brw_dump_surf_ss2(const struct brw_surf_ss2 *ptr) +{ + debug_printf("\t\t.mip_count = 0x%x\n", (*ptr).mip_count); + debug_printf("\t\t.width = 0x%x\n", (*ptr).width); + debug_printf("\t\t.height = 0x%x\n", (*ptr).height); +} + +void +brw_dump_surf_ss3(const struct brw_surf_ss3 *ptr) +{ + debug_printf("\t\t.tile_walk = 0x%x\n", (*ptr).tile_walk); + debug_printf("\t\t.tiled_surface = 0x%x\n", (*ptr).tiled_surface); + debug_printf("\t\t.pitch = 0x%x\n", (*ptr).pitch); + debug_printf("\t\t.depth = 0x%x\n", (*ptr).depth); +} + +void +brw_dump_surf_ss4(const struct brw_surf_ss4 *ptr) +{ + debug_printf("\t\t.multisample_position_palette_index = 0x%x\n", (*ptr).multisample_position_palette_index); + debug_printf("\t\t.num_multisamples = 0x%x\n", (*ptr).num_multisamples); + debug_printf("\t\t.render_target_view_extent = 0x%x\n", (*ptr).render_target_view_extent); + debug_printf("\t\t.min_array_elt = 0x%x\n", (*ptr).min_array_elt); + debug_printf("\t\t.min_lod = 0x%x\n", (*ptr).min_lod); +} + +void +brw_dump_surf_ss5(const struct brw_surf_ss5 *ptr) +{ + debug_printf("\t\t.llc_mapping = 0x%x\n", (*ptr).llc_mapping); + debug_printf("\t\t.mlc_mapping = 0x%x\n", (*ptr).mlc_mapping); + debug_printf("\t\t.gfdt = 0x%x\n", (*ptr).gfdt); + debug_printf("\t\t.gfdt_src = 0x%x\n", (*ptr).gfdt_src); + debug_printf("\t\t.y_offset = 0x%x\n", (*ptr).y_offset); + debug_printf("\t\t.x_offset = 0x%x\n", (*ptr).x_offset); +} + +void +brw_dump_surface_state(const struct brw_surface_state *ptr) +{ + debug_printf("\t\t.ss0.cube_pos_z = 0x%x\n", (*ptr).ss0.cube_pos_z); + debug_printf("\t\t.ss0.cube_neg_z = 0x%x\n", (*ptr).ss0.cube_neg_z); + debug_printf("\t\t.ss0.cube_pos_y = 0x%x\n", (*ptr).ss0.cube_pos_y); + debug_printf("\t\t.ss0.cube_neg_y = 0x%x\n", (*ptr).ss0.cube_neg_y); + debug_printf("\t\t.ss0.cube_pos_x = 0x%x\n", (*ptr).ss0.cube_pos_x); + debug_printf("\t\t.ss0.cube_neg_x = 0x%x\n", (*ptr).ss0.cube_neg_x); + debug_printf("\t\t.ss0.mipmap_layout_mode = 0x%x\n", (*ptr).ss0.mipmap_layout_mode); + debug_printf("\t\t.ss0.vert_line_stride_ofs = 0x%x\n", (*ptr).ss0.vert_line_stride_ofs); + debug_printf("\t\t.ss0.vert_line_stride = 0x%x\n", (*ptr).ss0.vert_line_stride); + debug_printf("\t\t.ss0.color_blend = 0x%x\n", (*ptr).ss0.color_blend); + debug_printf("\t\t.ss0.writedisable_blue = 0x%x\n", (*ptr).ss0.writedisable_blue); + debug_printf("\t\t.ss0.writedisable_green = 0x%x\n", (*ptr).ss0.writedisable_green); + debug_printf("\t\t.ss0.writedisable_red = 0x%x\n", (*ptr).ss0.writedisable_red); + debug_printf("\t\t.ss0.writedisable_alpha = 0x%x\n", (*ptr).ss0.writedisable_alpha); + debug_printf("\t\t.ss0.surface_format = 0x%x\n", (*ptr).ss0.surface_format); + debug_printf("\t\t.ss0.data_return_format = 0x%x\n", (*ptr).ss0.data_return_format); + debug_printf("\t\t.ss0.surface_type = 0x%x\n", (*ptr).ss0.surface_type); + debug_printf("\t\t.ss1.base_addr = 0x%x\n", (*ptr).ss1.base_addr); + debug_printf("\t\t.ss2.mip_count = 0x%x\n", (*ptr).ss2.mip_count); + debug_printf("\t\t.ss2.width = 0x%x\n", (*ptr).ss2.width); + debug_printf("\t\t.ss2.height = 0x%x\n", (*ptr).ss2.height); + debug_printf("\t\t.ss3.tile_walk = 0x%x\n", (*ptr).ss3.tile_walk); + debug_printf("\t\t.ss3.tiled_surface = 0x%x\n", (*ptr).ss3.tiled_surface); + debug_printf("\t\t.ss3.pitch = 0x%x\n", (*ptr).ss3.pitch); + debug_printf("\t\t.ss3.depth = 0x%x\n", (*ptr).ss3.depth); + debug_printf("\t\t.ss4.multisample_position_palette_index = 0x%x\n", (*ptr).ss4.multisample_position_palette_index); + debug_printf("\t\t.ss4.num_multisamples = 0x%x\n", (*ptr).ss4.num_multisamples); + debug_printf("\t\t.ss4.render_target_view_extent = 0x%x\n", (*ptr).ss4.render_target_view_extent); + debug_printf("\t\t.ss4.min_array_elt = 0x%x\n", (*ptr).ss4.min_array_elt); + debug_printf("\t\t.ss4.min_lod = 0x%x\n", (*ptr).ss4.min_lod); + debug_printf("\t\t.ss5.llc_mapping = 0x%x\n", (*ptr).ss5.llc_mapping); + debug_printf("\t\t.ss5.mlc_mapping = 0x%x\n", (*ptr).ss5.mlc_mapping); + debug_printf("\t\t.ss5.gfdt = 0x%x\n", (*ptr).ss5.gfdt); + debug_printf("\t\t.ss5.gfdt_src = 0x%x\n", (*ptr).ss5.gfdt_src); + debug_printf("\t\t.ss5.y_offset = 0x%x\n", (*ptr).ss5.y_offset); + debug_printf("\t\t.ss5.x_offset = 0x%x\n", (*ptr).ss5.x_offset); +} + +void +brw_dump_system_instruction_pointer(const struct brw_system_instruction_pointer *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.bits0.system_instruction_pointer = 0x%x\n", (*ptr).bits0.system_instruction_pointer); +} + +void +brw_dump_urb_fence(const struct brw_urb_fence *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.vs_realloc = 0x%x\n", (*ptr).header.vs_realloc); + debug_printf("\t\t.header.gs_realloc = 0x%x\n", (*ptr).header.gs_realloc); + debug_printf("\t\t.header.clp_realloc = 0x%x\n", (*ptr).header.clp_realloc); + debug_printf("\t\t.header.sf_realloc = 0x%x\n", (*ptr).header.sf_realloc); + debug_printf("\t\t.header.vfe_realloc = 0x%x\n", (*ptr).header.vfe_realloc); + debug_printf("\t\t.header.cs_realloc = 0x%x\n", (*ptr).header.cs_realloc); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.bits0.vs_fence = 0x%x\n", (*ptr).bits0.vs_fence); + debug_printf("\t\t.bits0.gs_fence = 0x%x\n", (*ptr).bits0.gs_fence); + debug_printf("\t\t.bits0.clp_fence = 0x%x\n", (*ptr).bits0.clp_fence); + debug_printf("\t\t.bits1.sf_fence = 0x%x\n", (*ptr).bits1.sf_fence); + debug_printf("\t\t.bits1.vf_fence = 0x%x\n", (*ptr).bits1.vf_fence); + debug_printf("\t\t.bits1.cs_fence = 0x%x\n", (*ptr).bits1.cs_fence); +} + +void +brw_dump_urb_immediate(const struct brw_urb_immediate *ptr) +{ + debug_printf("\t\t.opcode = 0x%x\n", (*ptr).opcode); + debug_printf("\t\t.offset = 0x%x\n", (*ptr).offset); + debug_printf("\t\t.swizzle_control = 0x%x\n", (*ptr).swizzle_control); + debug_printf("\t\t.allocate = 0x%x\n", (*ptr).allocate); + debug_printf("\t\t.used = 0x%x\n", (*ptr).used); + debug_printf("\t\t.complete = 0x%x\n", (*ptr).complete); + debug_printf("\t\t.response_length = 0x%x\n", (*ptr).response_length); + debug_printf("\t\t.msg_length = 0x%x\n", (*ptr).msg_length); + debug_printf("\t\t.msg_target = 0x%x\n", (*ptr).msg_target); + debug_printf("\t\t.end_of_thread = 0x%x\n", (*ptr).end_of_thread); +} + +void +brw_dump_vb_array_state(const struct brw_vb_array_state *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.vb[0].vb0.pitch = 0x%x\n", (*ptr).vb[0].vb0.pitch); + debug_printf("\t\t.vb[0].vb0.access_type = 0x%x\n", (*ptr).vb[0].vb0.access_type); + debug_printf("\t\t.vb[0].vb0.vb_index = 0x%x\n", (*ptr).vb[0].vb0.vb_index); + debug_printf("\t\t.vb[0].start_addr = 0x%x\n", (*ptr).vb[0].start_addr); + debug_printf("\t\t.vb[0].max_index = 0x%x\n", (*ptr).vb[0].max_index); + debug_printf("\t\t.vb[0].instance_data_step_rate = 0x%x\n", (*ptr).vb[0].instance_data_step_rate); + debug_printf("\t\t.vb[1].vb0.pitch = 0x%x\n", (*ptr).vb[1].vb0.pitch); + debug_printf("\t\t.vb[1].vb0.access_type = 0x%x\n", (*ptr).vb[1].vb0.access_type); + debug_printf("\t\t.vb[1].vb0.vb_index = 0x%x\n", (*ptr).vb[1].vb0.vb_index); + debug_printf("\t\t.vb[1].start_addr = 0x%x\n", (*ptr).vb[1].start_addr); + debug_printf("\t\t.vb[1].max_index = 0x%x\n", (*ptr).vb[1].max_index); + debug_printf("\t\t.vb[1].instance_data_step_rate = 0x%x\n", (*ptr).vb[1].instance_data_step_rate); + debug_printf("\t\t.vb[2].vb0.pitch = 0x%x\n", (*ptr).vb[2].vb0.pitch); + debug_printf("\t\t.vb[2].vb0.access_type = 0x%x\n", (*ptr).vb[2].vb0.access_type); + debug_printf("\t\t.vb[2].vb0.vb_index = 0x%x\n", (*ptr).vb[2].vb0.vb_index); + debug_printf("\t\t.vb[2].start_addr = 0x%x\n", (*ptr).vb[2].start_addr); + debug_printf("\t\t.vb[2].max_index = 0x%x\n", (*ptr).vb[2].max_index); + debug_printf("\t\t.vb[2].instance_data_step_rate = 0x%x\n", (*ptr).vb[2].instance_data_step_rate); + debug_printf("\t\t.vb[3].vb0.pitch = 0x%x\n", (*ptr).vb[3].vb0.pitch); + debug_printf("\t\t.vb[3].vb0.access_type = 0x%x\n", (*ptr).vb[3].vb0.access_type); + debug_printf("\t\t.vb[3].vb0.vb_index = 0x%x\n", (*ptr).vb[3].vb0.vb_index); + debug_printf("\t\t.vb[3].start_addr = 0x%x\n", (*ptr).vb[3].start_addr); + debug_printf("\t\t.vb[3].max_index = 0x%x\n", (*ptr).vb[3].max_index); + debug_printf("\t\t.vb[3].instance_data_step_rate = 0x%x\n", (*ptr).vb[3].instance_data_step_rate); + debug_printf("\t\t.vb[4].vb0.pitch = 0x%x\n", (*ptr).vb[4].vb0.pitch); + debug_printf("\t\t.vb[4].vb0.access_type = 0x%x\n", (*ptr).vb[4].vb0.access_type); + debug_printf("\t\t.vb[4].vb0.vb_index = 0x%x\n", (*ptr).vb[4].vb0.vb_index); + debug_printf("\t\t.vb[4].start_addr = 0x%x\n", (*ptr).vb[4].start_addr); + debug_printf("\t\t.vb[4].max_index = 0x%x\n", (*ptr).vb[4].max_index); + debug_printf("\t\t.vb[4].instance_data_step_rate = 0x%x\n", (*ptr).vb[4].instance_data_step_rate); + debug_printf("\t\t.vb[5].vb0.pitch = 0x%x\n", (*ptr).vb[5].vb0.pitch); + debug_printf("\t\t.vb[5].vb0.access_type = 0x%x\n", (*ptr).vb[5].vb0.access_type); + debug_printf("\t\t.vb[5].vb0.vb_index = 0x%x\n", (*ptr).vb[5].vb0.vb_index); + debug_printf("\t\t.vb[5].start_addr = 0x%x\n", (*ptr).vb[5].start_addr); + debug_printf("\t\t.vb[5].max_index = 0x%x\n", (*ptr).vb[5].max_index); + debug_printf("\t\t.vb[5].instance_data_step_rate = 0x%x\n", (*ptr).vb[5].instance_data_step_rate); + debug_printf("\t\t.vb[6].vb0.pitch = 0x%x\n", (*ptr).vb[6].vb0.pitch); + debug_printf("\t\t.vb[6].vb0.access_type = 0x%x\n", (*ptr).vb[6].vb0.access_type); + debug_printf("\t\t.vb[6].vb0.vb_index = 0x%x\n", (*ptr).vb[6].vb0.vb_index); + debug_printf("\t\t.vb[6].start_addr = 0x%x\n", (*ptr).vb[6].start_addr); + debug_printf("\t\t.vb[6].max_index = 0x%x\n", (*ptr).vb[6].max_index); + debug_printf("\t\t.vb[6].instance_data_step_rate = 0x%x\n", (*ptr).vb[6].instance_data_step_rate); + debug_printf("\t\t.vb[7].vb0.pitch = 0x%x\n", (*ptr).vb[7].vb0.pitch); + debug_printf("\t\t.vb[7].vb0.access_type = 0x%x\n", (*ptr).vb[7].vb0.access_type); + debug_printf("\t\t.vb[7].vb0.vb_index = 0x%x\n", (*ptr).vb[7].vb0.vb_index); + debug_printf("\t\t.vb[7].start_addr = 0x%x\n", (*ptr).vb[7].start_addr); + debug_printf("\t\t.vb[7].max_index = 0x%x\n", (*ptr).vb[7].max_index); + debug_printf("\t\t.vb[7].instance_data_step_rate = 0x%x\n", (*ptr).vb[7].instance_data_step_rate); + debug_printf("\t\t.vb[8].vb0.pitch = 0x%x\n", (*ptr).vb[8].vb0.pitch); + debug_printf("\t\t.vb[8].vb0.access_type = 0x%x\n", (*ptr).vb[8].vb0.access_type); + debug_printf("\t\t.vb[8].vb0.vb_index = 0x%x\n", (*ptr).vb[8].vb0.vb_index); + debug_printf("\t\t.vb[8].start_addr = 0x%x\n", (*ptr).vb[8].start_addr); + debug_printf("\t\t.vb[8].max_index = 0x%x\n", (*ptr).vb[8].max_index); + debug_printf("\t\t.vb[8].instance_data_step_rate = 0x%x\n", (*ptr).vb[8].instance_data_step_rate); + debug_printf("\t\t.vb[9].vb0.pitch = 0x%x\n", (*ptr).vb[9].vb0.pitch); + debug_printf("\t\t.vb[9].vb0.access_type = 0x%x\n", (*ptr).vb[9].vb0.access_type); + debug_printf("\t\t.vb[9].vb0.vb_index = 0x%x\n", (*ptr).vb[9].vb0.vb_index); + debug_printf("\t\t.vb[9].start_addr = 0x%x\n", (*ptr).vb[9].start_addr); + debug_printf("\t\t.vb[9].max_index = 0x%x\n", (*ptr).vb[9].max_index); + debug_printf("\t\t.vb[9].instance_data_step_rate = 0x%x\n", (*ptr).vb[9].instance_data_step_rate); + debug_printf("\t\t.vb[10].vb0.pitch = 0x%x\n", (*ptr).vb[10].vb0.pitch); + debug_printf("\t\t.vb[10].vb0.access_type = 0x%x\n", (*ptr).vb[10].vb0.access_type); + debug_printf("\t\t.vb[10].vb0.vb_index = 0x%x\n", (*ptr).vb[10].vb0.vb_index); + debug_printf("\t\t.vb[10].start_addr = 0x%x\n", (*ptr).vb[10].start_addr); + debug_printf("\t\t.vb[10].max_index = 0x%x\n", (*ptr).vb[10].max_index); + debug_printf("\t\t.vb[10].instance_data_step_rate = 0x%x\n", (*ptr).vb[10].instance_data_step_rate); + debug_printf("\t\t.vb[11].vb0.pitch = 0x%x\n", (*ptr).vb[11].vb0.pitch); + debug_printf("\t\t.vb[11].vb0.access_type = 0x%x\n", (*ptr).vb[11].vb0.access_type); + debug_printf("\t\t.vb[11].vb0.vb_index = 0x%x\n", (*ptr).vb[11].vb0.vb_index); + debug_printf("\t\t.vb[11].start_addr = 0x%x\n", (*ptr).vb[11].start_addr); + debug_printf("\t\t.vb[11].max_index = 0x%x\n", (*ptr).vb[11].max_index); + debug_printf("\t\t.vb[11].instance_data_step_rate = 0x%x\n", (*ptr).vb[11].instance_data_step_rate); + debug_printf("\t\t.vb[12].vb0.pitch = 0x%x\n", (*ptr).vb[12].vb0.pitch); + debug_printf("\t\t.vb[12].vb0.access_type = 0x%x\n", (*ptr).vb[12].vb0.access_type); + debug_printf("\t\t.vb[12].vb0.vb_index = 0x%x\n", (*ptr).vb[12].vb0.vb_index); + debug_printf("\t\t.vb[12].start_addr = 0x%x\n", (*ptr).vb[12].start_addr); + debug_printf("\t\t.vb[12].max_index = 0x%x\n", (*ptr).vb[12].max_index); + debug_printf("\t\t.vb[12].instance_data_step_rate = 0x%x\n", (*ptr).vb[12].instance_data_step_rate); + debug_printf("\t\t.vb[13].vb0.pitch = 0x%x\n", (*ptr).vb[13].vb0.pitch); + debug_printf("\t\t.vb[13].vb0.access_type = 0x%x\n", (*ptr).vb[13].vb0.access_type); + debug_printf("\t\t.vb[13].vb0.vb_index = 0x%x\n", (*ptr).vb[13].vb0.vb_index); + debug_printf("\t\t.vb[13].start_addr = 0x%x\n", (*ptr).vb[13].start_addr); + debug_printf("\t\t.vb[13].max_index = 0x%x\n", (*ptr).vb[13].max_index); + debug_printf("\t\t.vb[13].instance_data_step_rate = 0x%x\n", (*ptr).vb[13].instance_data_step_rate); + debug_printf("\t\t.vb[14].vb0.pitch = 0x%x\n", (*ptr).vb[14].vb0.pitch); + debug_printf("\t\t.vb[14].vb0.access_type = 0x%x\n", (*ptr).vb[14].vb0.access_type); + debug_printf("\t\t.vb[14].vb0.vb_index = 0x%x\n", (*ptr).vb[14].vb0.vb_index); + debug_printf("\t\t.vb[14].start_addr = 0x%x\n", (*ptr).vb[14].start_addr); + debug_printf("\t\t.vb[14].max_index = 0x%x\n", (*ptr).vb[14].max_index); + debug_printf("\t\t.vb[14].instance_data_step_rate = 0x%x\n", (*ptr).vb[14].instance_data_step_rate); + debug_printf("\t\t.vb[15].vb0.pitch = 0x%x\n", (*ptr).vb[15].vb0.pitch); + debug_printf("\t\t.vb[15].vb0.access_type = 0x%x\n", (*ptr).vb[15].vb0.access_type); + debug_printf("\t\t.vb[15].vb0.vb_index = 0x%x\n", (*ptr).vb[15].vb0.vb_index); + debug_printf("\t\t.vb[15].start_addr = 0x%x\n", (*ptr).vb[15].start_addr); + debug_printf("\t\t.vb[15].max_index = 0x%x\n", (*ptr).vb[15].max_index); + debug_printf("\t\t.vb[15].instance_data_step_rate = 0x%x\n", (*ptr).vb[15].instance_data_step_rate); + debug_printf("\t\t.vb[16].vb0.pitch = 0x%x\n", (*ptr).vb[16].vb0.pitch); + debug_printf("\t\t.vb[16].vb0.access_type = 0x%x\n", (*ptr).vb[16].vb0.access_type); + debug_printf("\t\t.vb[16].vb0.vb_index = 0x%x\n", (*ptr).vb[16].vb0.vb_index); + debug_printf("\t\t.vb[16].start_addr = 0x%x\n", (*ptr).vb[16].start_addr); + debug_printf("\t\t.vb[16].max_index = 0x%x\n", (*ptr).vb[16].max_index); + debug_printf("\t\t.vb[16].instance_data_step_rate = 0x%x\n", (*ptr).vb[16].instance_data_step_rate); +} + +void +brw_dump_vertex_buffer_state(const struct brw_vertex_buffer_state *ptr) +{ + debug_printf("\t\t.vb0.pitch = 0x%x\n", (*ptr).vb0.pitch); + debug_printf("\t\t.vb0.access_type = 0x%x\n", (*ptr).vb0.access_type); + debug_printf("\t\t.vb0.vb_index = 0x%x\n", (*ptr).vb0.vb_index); + debug_printf("\t\t.start_addr = 0x%x\n", (*ptr).start_addr); + debug_printf("\t\t.max_index = 0x%x\n", (*ptr).max_index); + debug_printf("\t\t.instance_data_step_rate = 0x%x\n", (*ptr).instance_data_step_rate); +} + +void +brw_dump_vertex_element_packet(const struct brw_vertex_element_packet *ptr) +{ + debug_printf("\t\t.header.length = 0x%x\n", (*ptr).header.length); + debug_printf("\t\t.header.opcode = 0x%x\n", (*ptr).header.opcode); + debug_printf("\t\t.ve[0].ve0.src_offset = 0x%x\n", (*ptr).ve[0].ve0.src_offset); + debug_printf("\t\t.ve[0].ve0.src_format = 0x%x\n", (*ptr).ve[0].ve0.src_format); + debug_printf("\t\t.ve[0].ve0.valid = 0x%x\n", (*ptr).ve[0].ve0.valid); + debug_printf("\t\t.ve[0].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[0].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[0].ve1.dst_offset = 0x%x\n", (*ptr).ve[0].ve1.dst_offset); + debug_printf("\t\t.ve[0].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[0].ve1.vfcomponent3); + debug_printf("\t\t.ve[0].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[0].ve1.vfcomponent2); + debug_printf("\t\t.ve[0].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[0].ve1.vfcomponent1); + debug_printf("\t\t.ve[0].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[0].ve1.vfcomponent0); + debug_printf("\t\t.ve[1].ve0.src_offset = 0x%x\n", (*ptr).ve[1].ve0.src_offset); + debug_printf("\t\t.ve[1].ve0.src_format = 0x%x\n", (*ptr).ve[1].ve0.src_format); + debug_printf("\t\t.ve[1].ve0.valid = 0x%x\n", (*ptr).ve[1].ve0.valid); + debug_printf("\t\t.ve[1].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[1].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[1].ve1.dst_offset = 0x%x\n", (*ptr).ve[1].ve1.dst_offset); + debug_printf("\t\t.ve[1].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[1].ve1.vfcomponent3); + debug_printf("\t\t.ve[1].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[1].ve1.vfcomponent2); + debug_printf("\t\t.ve[1].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[1].ve1.vfcomponent1); + debug_printf("\t\t.ve[1].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[1].ve1.vfcomponent0); + debug_printf("\t\t.ve[2].ve0.src_offset = 0x%x\n", (*ptr).ve[2].ve0.src_offset); + debug_printf("\t\t.ve[2].ve0.src_format = 0x%x\n", (*ptr).ve[2].ve0.src_format); + debug_printf("\t\t.ve[2].ve0.valid = 0x%x\n", (*ptr).ve[2].ve0.valid); + debug_printf("\t\t.ve[2].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[2].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[2].ve1.dst_offset = 0x%x\n", (*ptr).ve[2].ve1.dst_offset); + debug_printf("\t\t.ve[2].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[2].ve1.vfcomponent3); + debug_printf("\t\t.ve[2].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[2].ve1.vfcomponent2); + debug_printf("\t\t.ve[2].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[2].ve1.vfcomponent1); + debug_printf("\t\t.ve[2].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[2].ve1.vfcomponent0); + debug_printf("\t\t.ve[3].ve0.src_offset = 0x%x\n", (*ptr).ve[3].ve0.src_offset); + debug_printf("\t\t.ve[3].ve0.src_format = 0x%x\n", (*ptr).ve[3].ve0.src_format); + debug_printf("\t\t.ve[3].ve0.valid = 0x%x\n", (*ptr).ve[3].ve0.valid); + debug_printf("\t\t.ve[3].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[3].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[3].ve1.dst_offset = 0x%x\n", (*ptr).ve[3].ve1.dst_offset); + debug_printf("\t\t.ve[3].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[3].ve1.vfcomponent3); + debug_printf("\t\t.ve[3].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[3].ve1.vfcomponent2); + debug_printf("\t\t.ve[3].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[3].ve1.vfcomponent1); + debug_printf("\t\t.ve[3].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[3].ve1.vfcomponent0); + debug_printf("\t\t.ve[4].ve0.src_offset = 0x%x\n", (*ptr).ve[4].ve0.src_offset); + debug_printf("\t\t.ve[4].ve0.src_format = 0x%x\n", (*ptr).ve[4].ve0.src_format); + debug_printf("\t\t.ve[4].ve0.valid = 0x%x\n", (*ptr).ve[4].ve0.valid); + debug_printf("\t\t.ve[4].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[4].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[4].ve1.dst_offset = 0x%x\n", (*ptr).ve[4].ve1.dst_offset); + debug_printf("\t\t.ve[4].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[4].ve1.vfcomponent3); + debug_printf("\t\t.ve[4].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[4].ve1.vfcomponent2); + debug_printf("\t\t.ve[4].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[4].ve1.vfcomponent1); + debug_printf("\t\t.ve[4].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[4].ve1.vfcomponent0); + debug_printf("\t\t.ve[5].ve0.src_offset = 0x%x\n", (*ptr).ve[5].ve0.src_offset); + debug_printf("\t\t.ve[5].ve0.src_format = 0x%x\n", (*ptr).ve[5].ve0.src_format); + debug_printf("\t\t.ve[5].ve0.valid = 0x%x\n", (*ptr).ve[5].ve0.valid); + debug_printf("\t\t.ve[5].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[5].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[5].ve1.dst_offset = 0x%x\n", (*ptr).ve[5].ve1.dst_offset); + debug_printf("\t\t.ve[5].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[5].ve1.vfcomponent3); + debug_printf("\t\t.ve[5].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[5].ve1.vfcomponent2); + debug_printf("\t\t.ve[5].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[5].ve1.vfcomponent1); + debug_printf("\t\t.ve[5].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[5].ve1.vfcomponent0); + debug_printf("\t\t.ve[6].ve0.src_offset = 0x%x\n", (*ptr).ve[6].ve0.src_offset); + debug_printf("\t\t.ve[6].ve0.src_format = 0x%x\n", (*ptr).ve[6].ve0.src_format); + debug_printf("\t\t.ve[6].ve0.valid = 0x%x\n", (*ptr).ve[6].ve0.valid); + debug_printf("\t\t.ve[6].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[6].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[6].ve1.dst_offset = 0x%x\n", (*ptr).ve[6].ve1.dst_offset); + debug_printf("\t\t.ve[6].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[6].ve1.vfcomponent3); + debug_printf("\t\t.ve[6].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[6].ve1.vfcomponent2); + debug_printf("\t\t.ve[6].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[6].ve1.vfcomponent1); + debug_printf("\t\t.ve[6].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[6].ve1.vfcomponent0); + debug_printf("\t\t.ve[7].ve0.src_offset = 0x%x\n", (*ptr).ve[7].ve0.src_offset); + debug_printf("\t\t.ve[7].ve0.src_format = 0x%x\n", (*ptr).ve[7].ve0.src_format); + debug_printf("\t\t.ve[7].ve0.valid = 0x%x\n", (*ptr).ve[7].ve0.valid); + debug_printf("\t\t.ve[7].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[7].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[7].ve1.dst_offset = 0x%x\n", (*ptr).ve[7].ve1.dst_offset); + debug_printf("\t\t.ve[7].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[7].ve1.vfcomponent3); + debug_printf("\t\t.ve[7].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[7].ve1.vfcomponent2); + debug_printf("\t\t.ve[7].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[7].ve1.vfcomponent1); + debug_printf("\t\t.ve[7].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[7].ve1.vfcomponent0); + debug_printf("\t\t.ve[8].ve0.src_offset = 0x%x\n", (*ptr).ve[8].ve0.src_offset); + debug_printf("\t\t.ve[8].ve0.src_format = 0x%x\n", (*ptr).ve[8].ve0.src_format); + debug_printf("\t\t.ve[8].ve0.valid = 0x%x\n", (*ptr).ve[8].ve0.valid); + debug_printf("\t\t.ve[8].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[8].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[8].ve1.dst_offset = 0x%x\n", (*ptr).ve[8].ve1.dst_offset); + debug_printf("\t\t.ve[8].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[8].ve1.vfcomponent3); + debug_printf("\t\t.ve[8].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[8].ve1.vfcomponent2); + debug_printf("\t\t.ve[8].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[8].ve1.vfcomponent1); + debug_printf("\t\t.ve[8].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[8].ve1.vfcomponent0); + debug_printf("\t\t.ve[9].ve0.src_offset = 0x%x\n", (*ptr).ve[9].ve0.src_offset); + debug_printf("\t\t.ve[9].ve0.src_format = 0x%x\n", (*ptr).ve[9].ve0.src_format); + debug_printf("\t\t.ve[9].ve0.valid = 0x%x\n", (*ptr).ve[9].ve0.valid); + debug_printf("\t\t.ve[9].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[9].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[9].ve1.dst_offset = 0x%x\n", (*ptr).ve[9].ve1.dst_offset); + debug_printf("\t\t.ve[9].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[9].ve1.vfcomponent3); + debug_printf("\t\t.ve[9].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[9].ve1.vfcomponent2); + debug_printf("\t\t.ve[9].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[9].ve1.vfcomponent1); + debug_printf("\t\t.ve[9].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[9].ve1.vfcomponent0); + debug_printf("\t\t.ve[10].ve0.src_offset = 0x%x\n", (*ptr).ve[10].ve0.src_offset); + debug_printf("\t\t.ve[10].ve0.src_format = 0x%x\n", (*ptr).ve[10].ve0.src_format); + debug_printf("\t\t.ve[10].ve0.valid = 0x%x\n", (*ptr).ve[10].ve0.valid); + debug_printf("\t\t.ve[10].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[10].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[10].ve1.dst_offset = 0x%x\n", (*ptr).ve[10].ve1.dst_offset); + debug_printf("\t\t.ve[10].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[10].ve1.vfcomponent3); + debug_printf("\t\t.ve[10].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[10].ve1.vfcomponent2); + debug_printf("\t\t.ve[10].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[10].ve1.vfcomponent1); + debug_printf("\t\t.ve[10].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[10].ve1.vfcomponent0); + debug_printf("\t\t.ve[11].ve0.src_offset = 0x%x\n", (*ptr).ve[11].ve0.src_offset); + debug_printf("\t\t.ve[11].ve0.src_format = 0x%x\n", (*ptr).ve[11].ve0.src_format); + debug_printf("\t\t.ve[11].ve0.valid = 0x%x\n", (*ptr).ve[11].ve0.valid); + debug_printf("\t\t.ve[11].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[11].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[11].ve1.dst_offset = 0x%x\n", (*ptr).ve[11].ve1.dst_offset); + debug_printf("\t\t.ve[11].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[11].ve1.vfcomponent3); + debug_printf("\t\t.ve[11].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[11].ve1.vfcomponent2); + debug_printf("\t\t.ve[11].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[11].ve1.vfcomponent1); + debug_printf("\t\t.ve[11].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[11].ve1.vfcomponent0); + debug_printf("\t\t.ve[12].ve0.src_offset = 0x%x\n", (*ptr).ve[12].ve0.src_offset); + debug_printf("\t\t.ve[12].ve0.src_format = 0x%x\n", (*ptr).ve[12].ve0.src_format); + debug_printf("\t\t.ve[12].ve0.valid = 0x%x\n", (*ptr).ve[12].ve0.valid); + debug_printf("\t\t.ve[12].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[12].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[12].ve1.dst_offset = 0x%x\n", (*ptr).ve[12].ve1.dst_offset); + debug_printf("\t\t.ve[12].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[12].ve1.vfcomponent3); + debug_printf("\t\t.ve[12].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[12].ve1.vfcomponent2); + debug_printf("\t\t.ve[12].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[12].ve1.vfcomponent1); + debug_printf("\t\t.ve[12].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[12].ve1.vfcomponent0); + debug_printf("\t\t.ve[13].ve0.src_offset = 0x%x\n", (*ptr).ve[13].ve0.src_offset); + debug_printf("\t\t.ve[13].ve0.src_format = 0x%x\n", (*ptr).ve[13].ve0.src_format); + debug_printf("\t\t.ve[13].ve0.valid = 0x%x\n", (*ptr).ve[13].ve0.valid); + debug_printf("\t\t.ve[13].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[13].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[13].ve1.dst_offset = 0x%x\n", (*ptr).ve[13].ve1.dst_offset); + debug_printf("\t\t.ve[13].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[13].ve1.vfcomponent3); + debug_printf("\t\t.ve[13].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[13].ve1.vfcomponent2); + debug_printf("\t\t.ve[13].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[13].ve1.vfcomponent1); + debug_printf("\t\t.ve[13].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[13].ve1.vfcomponent0); + debug_printf("\t\t.ve[14].ve0.src_offset = 0x%x\n", (*ptr).ve[14].ve0.src_offset); + debug_printf("\t\t.ve[14].ve0.src_format = 0x%x\n", (*ptr).ve[14].ve0.src_format); + debug_printf("\t\t.ve[14].ve0.valid = 0x%x\n", (*ptr).ve[14].ve0.valid); + debug_printf("\t\t.ve[14].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[14].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[14].ve1.dst_offset = 0x%x\n", (*ptr).ve[14].ve1.dst_offset); + debug_printf("\t\t.ve[14].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[14].ve1.vfcomponent3); + debug_printf("\t\t.ve[14].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[14].ve1.vfcomponent2); + debug_printf("\t\t.ve[14].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[14].ve1.vfcomponent1); + debug_printf("\t\t.ve[14].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[14].ve1.vfcomponent0); + debug_printf("\t\t.ve[15].ve0.src_offset = 0x%x\n", (*ptr).ve[15].ve0.src_offset); + debug_printf("\t\t.ve[15].ve0.src_format = 0x%x\n", (*ptr).ve[15].ve0.src_format); + debug_printf("\t\t.ve[15].ve0.valid = 0x%x\n", (*ptr).ve[15].ve0.valid); + debug_printf("\t\t.ve[15].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[15].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[15].ve1.dst_offset = 0x%x\n", (*ptr).ve[15].ve1.dst_offset); + debug_printf("\t\t.ve[15].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[15].ve1.vfcomponent3); + debug_printf("\t\t.ve[15].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[15].ve1.vfcomponent2); + debug_printf("\t\t.ve[15].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[15].ve1.vfcomponent1); + debug_printf("\t\t.ve[15].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[15].ve1.vfcomponent0); + debug_printf("\t\t.ve[16].ve0.src_offset = 0x%x\n", (*ptr).ve[16].ve0.src_offset); + debug_printf("\t\t.ve[16].ve0.src_format = 0x%x\n", (*ptr).ve[16].ve0.src_format); + debug_printf("\t\t.ve[16].ve0.valid = 0x%x\n", (*ptr).ve[16].ve0.valid); + debug_printf("\t\t.ve[16].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[16].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[16].ve1.dst_offset = 0x%x\n", (*ptr).ve[16].ve1.dst_offset); + debug_printf("\t\t.ve[16].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[16].ve1.vfcomponent3); + debug_printf("\t\t.ve[16].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[16].ve1.vfcomponent2); + debug_printf("\t\t.ve[16].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[16].ve1.vfcomponent1); + debug_printf("\t\t.ve[16].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[16].ve1.vfcomponent0); + debug_printf("\t\t.ve[17].ve0.src_offset = 0x%x\n", (*ptr).ve[17].ve0.src_offset); + debug_printf("\t\t.ve[17].ve0.src_format = 0x%x\n", (*ptr).ve[17].ve0.src_format); + debug_printf("\t\t.ve[17].ve0.valid = 0x%x\n", (*ptr).ve[17].ve0.valid); + debug_printf("\t\t.ve[17].ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve[17].ve0.vertex_buffer_index); + debug_printf("\t\t.ve[17].ve1.dst_offset = 0x%x\n", (*ptr).ve[17].ve1.dst_offset); + debug_printf("\t\t.ve[17].ve1.vfcomponent3 = 0x%x\n", (*ptr).ve[17].ve1.vfcomponent3); + debug_printf("\t\t.ve[17].ve1.vfcomponent2 = 0x%x\n", (*ptr).ve[17].ve1.vfcomponent2); + debug_printf("\t\t.ve[17].ve1.vfcomponent1 = 0x%x\n", (*ptr).ve[17].ve1.vfcomponent1); + debug_printf("\t\t.ve[17].ve1.vfcomponent0 = 0x%x\n", (*ptr).ve[17].ve1.vfcomponent0); +} + +void +brw_dump_vertex_element_state(const struct brw_vertex_element_state *ptr) +{ + debug_printf("\t\t.ve0.src_offset = 0x%x\n", (*ptr).ve0.src_offset); + debug_printf("\t\t.ve0.src_format = 0x%x\n", (*ptr).ve0.src_format); + debug_printf("\t\t.ve0.valid = 0x%x\n", (*ptr).ve0.valid); + debug_printf("\t\t.ve0.vertex_buffer_index = 0x%x\n", (*ptr).ve0.vertex_buffer_index); + debug_printf("\t\t.ve1.dst_offset = 0x%x\n", (*ptr).ve1.dst_offset); + debug_printf("\t\t.ve1.vfcomponent3 = 0x%x\n", (*ptr).ve1.vfcomponent3); + debug_printf("\t\t.ve1.vfcomponent2 = 0x%x\n", (*ptr).ve1.vfcomponent2); + debug_printf("\t\t.ve1.vfcomponent1 = 0x%x\n", (*ptr).ve1.vfcomponent1); + debug_printf("\t\t.ve1.vfcomponent0 = 0x%x\n", (*ptr).ve1.vfcomponent0); +} + +void +brw_dump_vf_statistics(const struct brw_vf_statistics *ptr) +{ + debug_printf("\t\t.statistics_enable = 0x%x\n", (*ptr).statistics_enable); + debug_printf("\t\t.opcode = 0x%x\n", (*ptr).opcode); +} + +void +brw_dump_vs_unit_state(const struct brw_vs_unit_state *ptr) +{ + debug_printf("\t\t.thread0.grf_reg_count = 0x%x\n", (*ptr).thread0.grf_reg_count); + debug_printf("\t\t.thread0.kernel_start_pointer = 0x%x\n", (*ptr).thread0.kernel_start_pointer); + debug_printf("\t\t.thread1.ext_halt_exception_enable = 0x%x\n", (*ptr).thread1.ext_halt_exception_enable); + debug_printf("\t\t.thread1.sw_exception_enable = 0x%x\n", (*ptr).thread1.sw_exception_enable); + debug_printf("\t\t.thread1.mask_stack_exception_enable = 0x%x\n", (*ptr).thread1.mask_stack_exception_enable); + debug_printf("\t\t.thread1.timeout_exception_enable = 0x%x\n", (*ptr).thread1.timeout_exception_enable); + debug_printf("\t\t.thread1.illegal_op_exception_enable = 0x%x\n", (*ptr).thread1.illegal_op_exception_enable); + debug_printf("\t\t.thread1.depth_coef_urb_read_offset = 0x%x\n", (*ptr).thread1.depth_coef_urb_read_offset); + debug_printf("\t\t.thread1.floating_point_mode = 0x%x\n", (*ptr).thread1.floating_point_mode); + debug_printf("\t\t.thread1.thread_priority = 0x%x\n", (*ptr).thread1.thread_priority); + debug_printf("\t\t.thread1.binding_table_entry_count = 0x%x\n", (*ptr).thread1.binding_table_entry_count); + debug_printf("\t\t.thread1.single_program_flow = 0x%x\n", (*ptr).thread1.single_program_flow); + debug_printf("\t\t.thread2.per_thread_scratch_space = 0x%x\n", (*ptr).thread2.per_thread_scratch_space); + debug_printf("\t\t.thread2.scratch_space_base_pointer = 0x%x\n", (*ptr).thread2.scratch_space_base_pointer); + debug_printf("\t\t.thread3.dispatch_grf_start_reg = 0x%x\n", (*ptr).thread3.dispatch_grf_start_reg); + debug_printf("\t\t.thread3.urb_entry_read_offset = 0x%x\n", (*ptr).thread3.urb_entry_read_offset); + debug_printf("\t\t.thread3.urb_entry_read_length = 0x%x\n", (*ptr).thread3.urb_entry_read_length); + debug_printf("\t\t.thread3.const_urb_entry_read_offset = 0x%x\n", (*ptr).thread3.const_urb_entry_read_offset); + debug_printf("\t\t.thread3.const_urb_entry_read_length = 0x%x\n", (*ptr).thread3.const_urb_entry_read_length); + debug_printf("\t\t.thread4.stats_enable = 0x%x\n", (*ptr).thread4.stats_enable); + debug_printf("\t\t.thread4.nr_urb_entries = 0x%x\n", (*ptr).thread4.nr_urb_entries); + debug_printf("\t\t.thread4.urb_entry_allocation_size = 0x%x\n", (*ptr).thread4.urb_entry_allocation_size); + debug_printf("\t\t.thread4.max_threads = 0x%x\n", (*ptr).thread4.max_threads); + debug_printf("\t\t.vs5.sampler_count = 0x%x\n", (*ptr).vs5.sampler_count); + debug_printf("\t\t.vs5.sampler_state_pointer = 0x%x\n", (*ptr).vs5.sampler_state_pointer); + debug_printf("\t\t.vs6.vs_enable = 0x%x\n", (*ptr).vs6.vs_enable); + debug_printf("\t\t.vs6.vert_cache_disable = 0x%x\n", (*ptr).vs6.vert_cache_disable); +} + +void +brw_dump_wm_unit_state(const struct brw_wm_unit_state *ptr) +{ + debug_printf("\t\t.thread0.grf_reg_count = 0x%x\n", (*ptr).thread0.grf_reg_count); + debug_printf("\t\t.thread0.kernel_start_pointer = 0x%x\n", (*ptr).thread0.kernel_start_pointer); + debug_printf("\t\t.thread1.ext_halt_exception_enable = 0x%x\n", (*ptr).thread1.ext_halt_exception_enable); + debug_printf("\t\t.thread1.sw_exception_enable = 0x%x\n", (*ptr).thread1.sw_exception_enable); + debug_printf("\t\t.thread1.mask_stack_exception_enable = 0x%x\n", (*ptr).thread1.mask_stack_exception_enable); + debug_printf("\t\t.thread1.timeout_exception_enable = 0x%x\n", (*ptr).thread1.timeout_exception_enable); + debug_printf("\t\t.thread1.illegal_op_exception_enable = 0x%x\n", (*ptr).thread1.illegal_op_exception_enable); + debug_printf("\t\t.thread1.depth_coef_urb_read_offset = 0x%x\n", (*ptr).thread1.depth_coef_urb_read_offset); + debug_printf("\t\t.thread1.floating_point_mode = 0x%x\n", (*ptr).thread1.floating_point_mode); + debug_printf("\t\t.thread1.thread_priority = 0x%x\n", (*ptr).thread1.thread_priority); + debug_printf("\t\t.thread1.binding_table_entry_count = 0x%x\n", (*ptr).thread1.binding_table_entry_count); + debug_printf("\t\t.thread1.single_program_flow = 0x%x\n", (*ptr).thread1.single_program_flow); + debug_printf("\t\t.thread2.per_thread_scratch_space = 0x%x\n", (*ptr).thread2.per_thread_scratch_space); + debug_printf("\t\t.thread2.scratch_space_base_pointer = 0x%x\n", (*ptr).thread2.scratch_space_base_pointer); + debug_printf("\t\t.thread3.dispatch_grf_start_reg = 0x%x\n", (*ptr).thread3.dispatch_grf_start_reg); + debug_printf("\t\t.thread3.urb_entry_read_offset = 0x%x\n", (*ptr).thread3.urb_entry_read_offset); + debug_printf("\t\t.thread3.urb_entry_read_length = 0x%x\n", (*ptr).thread3.urb_entry_read_length); + debug_printf("\t\t.thread3.const_urb_entry_read_offset = 0x%x\n", (*ptr).thread3.const_urb_entry_read_offset); + debug_printf("\t\t.thread3.const_urb_entry_read_length = 0x%x\n", (*ptr).thread3.const_urb_entry_read_length); + debug_printf("\t\t.wm4.stats_enable = 0x%x\n", (*ptr).wm4.stats_enable); + debug_printf("\t\t.wm4.depth_buffer_clear = 0x%x\n", (*ptr).wm4.depth_buffer_clear); + debug_printf("\t\t.wm4.sampler_count = 0x%x\n", (*ptr).wm4.sampler_count); + debug_printf("\t\t.wm4.sampler_state_pointer = 0x%x\n", (*ptr).wm4.sampler_state_pointer); + debug_printf("\t\t.wm5.enable_8_pix = 0x%x\n", (*ptr).wm5.enable_8_pix); + debug_printf("\t\t.wm5.enable_16_pix = 0x%x\n", (*ptr).wm5.enable_16_pix); + debug_printf("\t\t.wm5.enable_32_pix = 0x%x\n", (*ptr).wm5.enable_32_pix); + debug_printf("\t\t.wm5.enable_con_32_pix = 0x%x\n", (*ptr).wm5.enable_con_32_pix); + debug_printf("\t\t.wm5.enable_con_64_pix = 0x%x\n", (*ptr).wm5.enable_con_64_pix); + debug_printf("\t\t.wm5.legacy_global_depth_bias = 0x%x\n", (*ptr).wm5.legacy_global_depth_bias); + debug_printf("\t\t.wm5.line_stipple = 0x%x\n", (*ptr).wm5.line_stipple); + debug_printf("\t\t.wm5.depth_offset = 0x%x\n", (*ptr).wm5.depth_offset); + debug_printf("\t\t.wm5.polygon_stipple = 0x%x\n", (*ptr).wm5.polygon_stipple); + debug_printf("\t\t.wm5.line_aa_region_width = 0x%x\n", (*ptr).wm5.line_aa_region_width); + debug_printf("\t\t.wm5.line_endcap_aa_region_width = 0x%x\n", (*ptr).wm5.line_endcap_aa_region_width); + debug_printf("\t\t.wm5.early_depth_test = 0x%x\n", (*ptr).wm5.early_depth_test); + debug_printf("\t\t.wm5.thread_dispatch_enable = 0x%x\n", (*ptr).wm5.thread_dispatch_enable); + debug_printf("\t\t.wm5.program_uses_depth = 0x%x\n", (*ptr).wm5.program_uses_depth); + debug_printf("\t\t.wm5.program_computes_depth = 0x%x\n", (*ptr).wm5.program_computes_depth); + debug_printf("\t\t.wm5.program_uses_killpixel = 0x%x\n", (*ptr).wm5.program_uses_killpixel); + debug_printf("\t\t.wm5.legacy_line_rast = 0x%x\n", (*ptr).wm5.legacy_line_rast); + debug_printf("\t\t.wm5.transposed_urb_read_enable = 0x%x\n", (*ptr).wm5.transposed_urb_read_enable); + debug_printf("\t\t.wm5.max_threads = 0x%x\n", (*ptr).wm5.max_threads); + debug_printf("\t\t.global_depth_offset_constant = %f\n", (*ptr).global_depth_offset_constant); + debug_printf("\t\t.global_depth_offset_scale = %f\n", (*ptr).global_depth_offset_scale); + debug_printf("\t\t.wm8.grf_reg_count_1 = 0x%x\n", (*ptr).wm8.grf_reg_count_1); + debug_printf("\t\t.wm8.kernel_start_pointer_1 = 0x%x\n", (*ptr).wm8.kernel_start_pointer_1); + debug_printf("\t\t.wm9.grf_reg_count_2 = 0x%x\n", (*ptr).wm9.grf_reg_count_2); + debug_printf("\t\t.wm9.kernel_start_pointer_2 = 0x%x\n", (*ptr).wm9.kernel_start_pointer_2); + debug_printf("\t\t.wm10.grf_reg_count_3 = 0x%x\n", (*ptr).wm10.grf_reg_count_3); + debug_printf("\t\t.wm10.kernel_start_pointer_3 = 0x%x\n", (*ptr).wm10.kernel_start_pointer_3); +} + diff --git a/src/gallium/drivers/i965/brw_structs_dump.h b/src/gallium/drivers/i965/brw_structs_dump.h new file mode 100644 index 0000000..7c02dbf --- /dev/null +++ b/src/gallium/drivers/i965/brw_structs_dump.h @@ -0,0 +1,276 @@ +/************************************************************************** + * + * 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 + * Dump i965 data structures. + * + * Generated automatically from brw_structs.h by brw_structs_dump.py. + */ + +#ifndef BRW_STRUCTS_DUMP_H +#define BRW_STRUCTS_DUMP_H + +struct brw_3d_control; +struct brw_3d_primitive; +struct brw_aa_line_parameters; +struct brw_binding_table_pointers; +struct brw_blend_constant_color; +struct brw_cc0; +struct brw_cc1; +struct brw_cc2; +struct brw_cc3; +struct brw_cc4; +struct brw_cc5; +struct brw_cc6; +struct brw_cc7; +struct brw_cc_unit_state; +struct brw_cc_viewport; +struct brw_clip_unit_state; +struct brw_clipper_viewport; +struct brw_constant_buffer; +struct brw_cs_urb_state; +struct brw_depthbuffer; +struct brw_depthbuffer_g4x; +struct brw_drawrect; +struct brw_global_depth_offset_clamp; +struct brw_gs_unit_state; +struct brw_indexbuffer; +struct brw_line_stipple; +struct brw_mi_flush; +struct brw_pipe_control; +struct brw_pipeline_select; +struct brw_pipelined_state_pointers; +struct brw_polygon_stipple; +struct brw_polygon_stipple_offset; +struct brw_sampler_default_color; +struct brw_sampler_state; +struct brw_sf_unit_state; +struct brw_sf_viewport; +struct brw_ss0; +struct brw_ss1; +struct brw_ss2; +struct brw_ss3; +struct brw_state_base_address; +struct brw_state_prefetch; +struct brw_surf_ss0; +struct brw_surf_ss1; +struct brw_surf_ss2; +struct brw_surf_ss3; +struct brw_surf_ss4; +struct brw_surf_ss5; +struct brw_surface_state; +struct brw_system_instruction_pointer; +struct brw_urb_fence; +struct brw_urb_immediate; +struct brw_vb_array_state; +struct brw_vertex_buffer_state; +struct brw_vertex_element_packet; +struct brw_vertex_element_state; +struct brw_vf_statistics; +struct brw_vs_unit_state; +struct brw_wm_unit_state; + +void +brw_dump_3d_control(const struct brw_3d_control *ptr); + +void +brw_dump_3d_primitive(const struct brw_3d_primitive *ptr); + +void +brw_dump_aa_line_parameters(const struct brw_aa_line_parameters *ptr); + +void +brw_dump_binding_table_pointers(const struct brw_binding_table_pointers *ptr); + +void +brw_dump_blend_constant_color(const struct brw_blend_constant_color *ptr); + +void +brw_dump_cc0(const struct brw_cc0 *ptr); + +void +brw_dump_cc1(const struct brw_cc1 *ptr); + +void +brw_dump_cc2(const struct brw_cc2 *ptr); + +void +brw_dump_cc3(const struct brw_cc3 *ptr); + +void +brw_dump_cc4(const struct brw_cc4 *ptr); + +void +brw_dump_cc5(const struct brw_cc5 *ptr); + +void +brw_dump_cc6(const struct brw_cc6 *ptr); + +void +brw_dump_cc7(const struct brw_cc7 *ptr); + +void +brw_dump_cc_unit_state(const struct brw_cc_unit_state *ptr); + +void +brw_dump_cc_viewport(const struct brw_cc_viewport *ptr); + +void +brw_dump_clip_unit_state(const struct brw_clip_unit_state *ptr); + +void +brw_dump_clipper_viewport(const struct brw_clipper_viewport *ptr); + +void +brw_dump_constant_buffer(const struct brw_constant_buffer *ptr); + +void +brw_dump_cs_urb_state(const struct brw_cs_urb_state *ptr); + +void +brw_dump_depthbuffer(const struct brw_depthbuffer *ptr); + +void +brw_dump_depthbuffer_g4x(const struct brw_depthbuffer_g4x *ptr); + +void +brw_dump_drawrect(const struct brw_drawrect *ptr); + +void +brw_dump_global_depth_offset_clamp(const struct brw_global_depth_offset_clamp *ptr); + +void +brw_dump_gs_unit_state(const struct brw_gs_unit_state *ptr); + +void +brw_dump_indexbuffer(const struct brw_indexbuffer *ptr); + +void +brw_dump_line_stipple(const struct brw_line_stipple *ptr); + +void +brw_dump_mi_flush(const struct brw_mi_flush *ptr); + +void +brw_dump_pipe_control(const struct brw_pipe_control *ptr); + +void +brw_dump_pipeline_select(const struct brw_pipeline_select *ptr); + +void +brw_dump_pipelined_state_pointers(const struct brw_pipelined_state_pointers *ptr); + +void +brw_dump_polygon_stipple(const struct brw_polygon_stipple *ptr); + +void +brw_dump_polygon_stipple_offset(const struct brw_polygon_stipple_offset *ptr); + +void +brw_dump_sampler_default_color(const struct brw_sampler_default_color *ptr); + +void +brw_dump_sampler_state(const struct brw_sampler_state *ptr); + +void +brw_dump_sf_unit_state(const struct brw_sf_unit_state *ptr); + +void +brw_dump_sf_viewport(const struct brw_sf_viewport *ptr); + +void +brw_dump_ss0(const struct brw_ss0 *ptr); + +void +brw_dump_ss1(const struct brw_ss1 *ptr); + +void +brw_dump_ss2(const struct brw_ss2 *ptr); + +void +brw_dump_ss3(const struct brw_ss3 *ptr); + +void +brw_dump_state_base_address(const struct brw_state_base_address *ptr); + +void +brw_dump_state_prefetch(const struct brw_state_prefetch *ptr); + +void +brw_dump_surf_ss0(const struct brw_surf_ss0 *ptr); + +void +brw_dump_surf_ss1(const struct brw_surf_ss1 *ptr); + +void +brw_dump_surf_ss2(const struct brw_surf_ss2 *ptr); + +void +brw_dump_surf_ss3(const struct brw_surf_ss3 *ptr); + +void +brw_dump_surf_ss4(const struct brw_surf_ss4 *ptr); + +void +brw_dump_surf_ss5(const struct brw_surf_ss5 *ptr); + +void +brw_dump_surface_state(const struct brw_surface_state *ptr); + +void +brw_dump_system_instruction_pointer(const struct brw_system_instruction_pointer *ptr); + +void +brw_dump_urb_fence(const struct brw_urb_fence *ptr); + +void +brw_dump_urb_immediate(const struct brw_urb_immediate *ptr); + +void +brw_dump_vb_array_state(const struct brw_vb_array_state *ptr); + +void +brw_dump_vertex_buffer_state(const struct brw_vertex_buffer_state *ptr); + +void +brw_dump_vertex_element_packet(const struct brw_vertex_element_packet *ptr); + +void +brw_dump_vertex_element_state(const struct brw_vertex_element_state *ptr); + +void +brw_dump_vf_statistics(const struct brw_vf_statistics *ptr); + +void +brw_dump_vs_unit_state(const struct brw_vs_unit_state *ptr); + +void +brw_dump_wm_unit_state(const struct brw_wm_unit_state *ptr); + + +#endif /* BRW_STRUCTS_DUMP_H */ diff --git a/src/gallium/drivers/i965/brw_structs_dump.py b/src/gallium/drivers/i965/brw_structs_dump.py new file mode 100755 index 0000000..6dba49a --- /dev/null +++ b/src/gallium/drivers/i965/brw_structs_dump.py @@ -0,0 +1,291 @@ +#!/usr/bin/env python +''' +Generates dumpers for the i965 state strucutures using pygccxml. + +Run as + + PYTHONPATH=/path/to/pygccxml-1.0.0 python brw_structs_dump.py + +Jose Fonseca +''' + +copyright = ''' +/************************************************************************** + * + * 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. + * + **************************************************************************/ + ''' + +import os +import sys +import re + +from pygccxml import parser +from pygccxml import declarations + +from pygccxml.declarations import algorithm +from pygccxml.declarations import decl_visitor +from pygccxml.declarations import type_traits +from pygccxml.declarations import type_visitor + + +enums = True + + +def vars_filter(variable): + name = variable.name + return not re.match('^pad\d*', name) and name != 'dword' + + +class decl_dumper_t(decl_visitor.decl_visitor_t): + + def __init__(self, stream, instance = '', decl = None): + decl_visitor.decl_visitor_t.__init__(self) + self.stream = stream + self._instance = instance + self.decl = decl + + def clone(self): + return decl_dumper_t(self.stream, self._instance, self.decl) + + def visit_class(self): + class_ = self.decl + assert self.decl.class_type in ('struct', 'union') + + for variable in class_.variables(recursive = False): + if vars_filter(variable): + dump_type(self.stream, self._instance + '.' + variable.name, variable.type) + + def visit_enumeration(self): + if enums: + self.stream.write(' switch(%s) {\n' % ("(*ptr)" + self._instance,)) + for name, value in self.decl.values: + self.stream.write(' case %s:\n' % (name,)) + self.stream.write(' debug_printf("\\t\\t%s = %s\\n");\n' % (self._instance, name)) + self.stream.write(' break;\n') + self.stream.write(' default:\n') + self.stream.write(' debug_printf("\\t\\t%s = %%i\\n", %s);\n' % (self._instance, "(*ptr)" + self._instance)) + self.stream.write(' break;\n') + self.stream.write(' }\n') + else: + self.stream.write(' debug_printf("\\t\\t%s = %%i\\n", %s);\n' % (self._instance, "(*ptr)" + self._instance)) + + +def dump_decl(stream, instance, decl): + dumper = decl_dumper_t(stream, instance, decl) + algorithm.apply_visitor(dumper, decl) + + +class type_dumper_t(type_visitor.type_visitor_t): + + def __init__(self, stream, instance, type_): + type_visitor.type_visitor_t.__init__(self) + self.stream = stream + self.instance = instance + self.type = type_ + + def clone(self): + return type_dumper_t(self.instance, self.type) + + def visit_bool(self): + self.print_instance('%i') + + def visit_char(self): + #self.print_instance('%i') + self.print_instance('0x%x') + + def visit_unsigned_char(self): + #self.print_instance('%u') + self.print_instance('0x%x') + + def visit_signed_char(self): + #self.print_instance('%i') + self.print_instance('0x%x') + + def visit_wchar(self): + self.print_instance('0x%x') + + def visit_short_int(self): + #self.print_instance('%i') + self.print_instance('0x%x') + + def visit_short_unsigned_int(self): + #self.print_instance('%u') + self.print_instance('0x%x') + + def visit_int(self): + #self.print_instance('%i') + self.print_instance('0x%x') + + def visit_unsigned_int(self): + #self.print_instance('%u') + self.print_instance('0x%x') + + def visit_long_int(self): + #self.print_instance('%li') + self.print_instance('0x%lx') + + def visit_long_unsigned_int(self): + #self.print_instance('%lu') + self.print_instance('%0xlx') + + def visit_long_long_int(self): + #self.print_instance('%lli') + self.print_instance('%0xllx') + + def visit_long_long_unsigned_int(self): + #self.print_instance('%llu') + self.print_instance('0x%llx') + + def visit_float(self): + self.print_instance('%f') + + def visit_double(self): + self.print_instance('%f') + + def visit_array(self): + for i in range(type_traits.array_size(self.type)): + dump_type(self.stream, self.instance + '[%i]' % i, type_traits.base_type(self.type)) + + def visit_pointer(self): + self.print_instance('%p') + + def visit_declarated(self): + #stream.write('decl = %r\n' % self.type.decl_string) + decl = type_traits.remove_declarated(self.type) + dump_decl(self.stream, self.instance, decl) + + def print_instance(self, format): + self.stream.write(' debug_printf("\\t\\t%s = %s\\n", %s);\n' % (self.instance, format, "(*ptr)" + self.instance)) + + + +def dump_type(stream, instance, type_): + type_ = type_traits.remove_alias(type_) + visitor = type_dumper_t(stream, instance, type_) + algorithm.apply_visitor(visitor, type_) + + +def dump_struct_interface(stream, class_, suffix = ';'): + name = class_.name + assert name.startswith('brw_'); + name = name[:4] + 'dump_' + name[4:] + stream.write('void\n') + stream.write('%s(const struct %s *ptr)%s\n' % (name, class_.name, suffix)) + + +def dump_struct_implementation(stream, decls, class_): + dump_struct_interface(stream, class_, suffix = '') + stream.write('{\n') + dump_decl(stream, '', class_) + stream.write('}\n') + stream.write('\n') + + +def dump_header(stream): + stream.write(copyright.strip() + '\n') + stream.write('\n') + stream.write('/**\n') + stream.write(' * @file\n') + stream.write(' * Dump i965 data structures.\n') + stream.write(' *\n') + stream.write(' * Generated automatically from brw_structs.h by brw_structs_dump.py.\n') + stream.write(' */\n') + stream.write('\n') + + +def dump_interfaces(decls, global_ns, names): + stream = open('brw_structs_dump.h', 'wt') + + dump_header(stream) + + stream.write('#ifndef BRW_STRUCTS_DUMP_H\n') + stream.write('#define BRW_STRUCTS_DUMP_H\n') + stream.write('\n') + + for name in names: + stream.write('struct %s;\n' % (name,)) + stream.write('\n') + + for name in names: + (class_,) = global_ns.classes(name = name) + dump_struct_interface(stream, class_) + stream.write('\n') + stream.write('\n') + + stream.write('#endif /* BRW_STRUCTS_DUMP_H */\n') + + +def dump_implementations(decls, global_ns, names): + stream = open('brw_structs_dump.c', 'wt') + + dump_header(stream) + + stream.write('#include "util/u_debug.h"\n') + stream.write('\n') + stream.write('#include "brw_types.h"\n') + stream.write('#include "brw_structs.h"\n') + stream.write('#include "brw_structs_dump.h"\n') + stream.write('\n') + + for name in names: + (class_,) = global_ns.classes(name = name) + dump_struct_implementation(stream, decls, class_) + + +def decl_filter(decl): + '''Filter the declarations we're interested in''' + name = decl.name + return name.startswith('brw_') and name not in ('brw_instruction',) + + +def main(): + + config = parser.config_t( + include_paths = [ + '../../include', + ], + compiler = 'gcc', + ) + + headers = [ + 'brw_types.h', + 'brw_structs.h', + ] + + decls = parser.parse(headers, config, parser.COMPILATION_MODE.ALL_AT_ONCE) + global_ns = declarations.get_global_namespace(decls) + + names = [] + for class_ in global_ns.classes(decl_filter): + names.append(class_.name) + names.sort() + + dump_interfaces(decls, global_ns, names) + dump_implementations(decls, global_ns, names) + + +if __name__ == '__main__': + main() diff --git a/src/gallium/drivers/i965/brw_swtnl.c b/src/gallium/drivers/i965/brw_swtnl.c new file mode 100644 index 0000000..f96301e --- /dev/null +++ b/src/gallium/drivers/i965/brw_swtnl.c @@ -0,0 +1,95 @@ + +#include "brw_context.h" +#include "brw_pipe_rast.h" + + +#if 0 + +static GLboolean need_swtnl( struct brw_context *brw ) +{ + const struct pipe_rasterizer_state *rast = &brw->curr.rast->templ; + + /* If we don't require strict OpenGL conformance, never + * use fallbacks. If we're forcing fallbacks, always + * use fallfacks. + */ + if (brw->flags.no_swtnl) + return FALSE; + + if (brw->flags.force_swtnl) + return TRUE; + + /* Exceeding hw limits on number of VS inputs? + */ + if (brw->curr.num_vertex_elements == 0 || + brw->curr.num_vertex_elements >= BRW_VEP_MAX) { + return TRUE; + } + + /* Position array with zero stride? + * + * XXX: position isn't always at zero... + * XXX: eliminate zero-stride arrays + */ + { + int ve0_vb = brw->curr.vertex_element[0].vertex_buffer_index; + + if (brw->curr.vertex_buffer[ve0_vb].stride == 0) + return TRUE; + } + + /* XXX: short-circuit + */ + return FALSE; + + if (brw->reduced_primitive == PIPE_PRIM_TRIANGLES) { + if (rast->poly_smooth) + return TRUE; + + } + + if (brw->reduced_primitive == PIPE_PRIM_LINES || + (brw->reduced_primitive == PIPE_PRIM_TRIANGLES && + (rast->fill_cw == PIPE_POLYGON_MODE_LINE || + rast->fill_ccw == PIPE_POLYGON_MODE_LINE))) + { + /* BRW hardware will do AA lines, but they are non-conformant it + * seems. TBD whether we keep this fallback: + */ + if (rast->line_smooth) + return TRUE; + + /* XXX: was a fallback in mesa (gs doesn't get enough + * information to know when to reset stipple counter), but there + * must be a way around it. + */ + if (rast->line_stipple_enable && + (brw->reduced_primitive == PIPE_PRIM_TRIANGLES || + brw->primitive == PIPE_PRIM_LINE_LOOP || + brw->primitive == PIPE_PRIM_LINE_STRIP)) + return TRUE; + } + + + if (brw->reduced_primitive == PIPE_PRIM_POINTS || + (brw->reduced_primitive == PIPE_PRIM_TRIANGLES && + (rast->fill_cw == PIPE_POLYGON_MODE_POINT || + rast->fill_ccw == PIPE_POLYGON_MODE_POINT))) + { + if (rast->point_smooth) + return TRUE; + } + + /* BRW hardware doesn't handle CLAMP texturing correctly; + * brw_wm_sampler_state:translate_wrap_mode() treats CLAMP + * as CLAMP_TO_EDGE instead. If we're using CLAMP, and + * we want strict conformance, force the fallback. + * + * XXX: need a workaround for this. + */ + + /* Nothing stopping us from the fast path now */ + return FALSE; +} + +#endif diff --git a/src/gallium/drivers/i965/brw_types.h b/src/gallium/drivers/i965/brw_types.h new file mode 100644 index 0000000..89e08a5 --- /dev/null +++ b/src/gallium/drivers/i965/brw_types.h @@ -0,0 +1,21 @@ +#ifndef BRW_TYPES_H +#define BRW_TYPES_H + +#include "pipe/p_compiler.h" + +typedef uint32_t GLuint; +typedef uint8_t GLubyte; +typedef uint16_t GLushort; +typedef int32_t GLint; +typedef int8_t GLbyte; +typedef int16_t GLshort; +typedef float GLfloat; + +/* no GLenum, translate all away */ + +typedef uint8_t GLboolean; + +#define GL_FALSE FALSE +#define GL_TRUE TRUE + +#endif diff --git a/src/gallium/drivers/i965/brw_urb.c b/src/gallium/drivers/i965/brw_urb.c new file mode 100644 index 0000000..907ec56 --- /dev/null +++ b/src/gallium/drivers/i965/brw_urb.c @@ -0,0 +1,263 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + + +#include "brw_batchbuffer.h" +#include "brw_context.h" +#include "brw_state.h" +#include "brw_defines.h" +#include "brw_debug.h" + +#define VS 0 +#define GS 1 +#define CLP 2 +#define SF 3 +#define CS 4 + +/** @file brw_urb.c + * + * Manages the division of the URB space between the various fixed-function + * units. + * + * See the Thread Initiation Management section of the GEN4 B-Spec, and + * the individual *_STATE structures for restrictions on numbers of + * entries and threads. + */ + +/* + * Generally, a unit requires a min_nr_entries based on how many entries + * it produces before the downstream unit gets unblocked and can use and + * dereference some of its handles. + * + * The SF unit preallocates a PUE at the start of thread dispatch, and only + * uses that one. So it requires one entry per thread. + * + * For CLIP, the SF unit will hold the previous primitive while the + * next is getting assembled, meaning that linestrips require 3 CLIP VUEs + * (vertices) to ensure continued processing, trifans require 4, and tristrips + * require 5. There can be 1 or 2 threads, and each has the same requirement. + * + * GS has the same requirement as CLIP, but it never handles tristrips, + * so we can lower the minimum to 4 for the POLYGONs (trifans) it produces. + * We only run it single-threaded. + * + * For VS, the number of entries may be 8, 12, 16, or 32 (or 64 on G4X). + * Each thread processes 2 preallocated VUEs (vertices) at a time, and they + * get streamed down as soon as threads processing earlier vertices get + * theirs accepted. + * + * Each unit will take the number of URB entries we give it (based on the + * entry size calculated in brw_vs_emit.c for VUEs, brw_sf_emit.c for PUEs, + * and brw_curbe.c for the CURBEs) and decide its maximum number of + * threads it can support based on that. in brw_*_state.c. + * + * XXX: Are the min_entry_size numbers useful? + * XXX: Verify min_nr_entries, esp for VS. + * XXX: Verify SF min_entry_size. + */ +static const struct urb_limits { + GLuint min_nr_entries; + GLuint preferred_nr_entries; + GLuint min_entry_size; + GLuint max_entry_size; +} limits[CS+1] = { + { 16, 32, 1, 5 }, /* vs */ + { 4, 8, 1, 5 }, /* gs */ + { 5, 10, 1, 5 }, /* clp */ + { 1, 8, 1, 12 }, /* sf */ + { 1, 4, 1, 32 } /* cs */ +}; + + +static GLboolean check_urb_layout( struct brw_context *brw ) +{ + brw->urb.vs_start = 0; + brw->urb.gs_start = brw->urb.nr_vs_entries * brw->urb.vsize; + brw->urb.clip_start = brw->urb.gs_start + brw->urb.nr_gs_entries * brw->urb.vsize; + brw->urb.sf_start = brw->urb.clip_start + brw->urb.nr_clip_entries * brw->urb.vsize; + brw->urb.cs_start = brw->urb.sf_start + brw->urb.nr_sf_entries * brw->urb.sfsize; + + return brw->urb.cs_start + brw->urb.nr_cs_entries * brw->urb.csize <= URB_SIZES(brw); +} + +/* Most minimal update, forces re-emit of URB fence packet after GS + * unit turned on/off. + */ +static int recalculate_urb_fence( struct brw_context *brw ) +{ + GLuint csize = brw->curbe.total_size; + GLuint vsize = brw->vs.prog_data->urb_entry_size; + GLuint sfsize = brw->sf.prog_data->urb_entry_size; + + if (csize < limits[CS].min_entry_size) + csize = limits[CS].min_entry_size; + + if (vsize < limits[VS].min_entry_size) + vsize = limits[VS].min_entry_size; + + if (sfsize < limits[SF].min_entry_size) + sfsize = limits[SF].min_entry_size; + + if (brw->urb.vsize < vsize || + brw->urb.sfsize < sfsize || + brw->urb.csize < csize || + (brw->urb.constrained && (brw->urb.vsize > vsize || + brw->urb.sfsize > sfsize || + brw->urb.csize > csize))) { + + + brw->urb.csize = csize; + brw->urb.sfsize = sfsize; + brw->urb.vsize = vsize; + + brw->urb.nr_vs_entries = limits[VS].preferred_nr_entries; + brw->urb.nr_gs_entries = limits[GS].preferred_nr_entries; + brw->urb.nr_clip_entries = limits[CLP].preferred_nr_entries; + brw->urb.nr_sf_entries = limits[SF].preferred_nr_entries; + brw->urb.nr_cs_entries = limits[CS].preferred_nr_entries; + + brw->urb.constrained = 0; + + if (BRW_IS_IGDNG(brw)) { + brw->urb.nr_vs_entries = 128; + brw->urb.nr_sf_entries = 48; + if (check_urb_layout(brw)) { + goto done; + } else { + brw->urb.constrained = 1; + brw->urb.nr_vs_entries = limits[VS].preferred_nr_entries; + brw->urb.nr_sf_entries = limits[SF].preferred_nr_entries; + } + } else if (BRW_IS_G4X(brw)) { + brw->urb.nr_vs_entries = 64; + if (check_urb_layout(brw)) { + goto done; + } else { + brw->urb.constrained = 1; + brw->urb.nr_vs_entries = limits[VS].preferred_nr_entries; + } + } + + if (BRW_DEBUG & DEBUG_MIN_URB) { + brw->urb.nr_vs_entries = limits[VS].min_nr_entries; + brw->urb.nr_gs_entries = limits[GS].min_nr_entries; + brw->urb.nr_clip_entries = limits[CLP].min_nr_entries; + brw->urb.nr_sf_entries = limits[SF].min_nr_entries; + brw->urb.nr_cs_entries = limits[CS].min_nr_entries; + brw->urb.constrained = 1; + } + + if (!check_urb_layout(brw)) { + brw->urb.nr_vs_entries = limits[VS].min_nr_entries; + brw->urb.nr_gs_entries = limits[GS].min_nr_entries; + brw->urb.nr_clip_entries = limits[CLP].min_nr_entries; + brw->urb.nr_sf_entries = limits[SF].min_nr_entries; + brw->urb.nr_cs_entries = limits[CS].min_nr_entries; + + /* Mark us as operating with constrained nr_entries, so that next + * time we recalculate we'll resize the fences in the hope of + * escaping constrained mode and getting back to normal performance. + */ + brw->urb.constrained = 1; + + if (!check_urb_layout(brw)) { + /* This is impossible, given the maximal sizes of urb + * entries and the values for minimum nr of entries + * provided above. + */ + debug_printf("couldn't calculate URB layout!\n"); + exit(1); + } + + if (BRW_DEBUG & (DEBUG_URB|DEBUG_FALLBACKS)) + debug_printf("URB CONSTRAINED\n"); + } + +done: + if (BRW_DEBUG & DEBUG_URB) + debug_printf("URB fence: %d ..VS.. %d ..GS.. %d ..CLP.. %d ..SF.. %d ..CS.. %d\n", + brw->urb.vs_start, + brw->urb.gs_start, + brw->urb.clip_start, + brw->urb.sf_start, + brw->urb.cs_start, + URB_SIZES(brw)); + + brw->state.dirty.brw |= BRW_NEW_URB_FENCE; + } + + return 0; +} + + +const struct brw_tracked_state brw_recalculate_urb_fence = { + .dirty = { + .mesa = 0, + .brw = BRW_NEW_CURBE_OFFSETS, + .cache = (CACHE_NEW_VS_PROG | + CACHE_NEW_SF_PROG) + }, + .prepare = recalculate_urb_fence +}; + + + + + +int brw_upload_urb_fence(struct brw_context *brw) +{ + struct brw_urb_fence uf; + memset(&uf, 0, sizeof(uf)); + + uf.header.opcode = CMD_URB_FENCE; + uf.header.length = sizeof(uf)/4-2; + uf.header.vs_realloc = 1; + uf.header.gs_realloc = 1; + uf.header.clp_realloc = 1; + uf.header.sf_realloc = 1; + uf.header.vfe_realloc = 1; + uf.header.cs_realloc = 1; + + /* The ordering below is correct, not the layout in the + * instruction. + * + * There are 256/384 urb reg pairs in total. + */ + uf.bits0.vs_fence = brw->urb.gs_start; + uf.bits0.gs_fence = brw->urb.clip_start; + uf.bits0.clp_fence = brw->urb.sf_start; + uf.bits1.sf_fence = brw->urb.cs_start; + uf.bits1.cs_fence = URB_SIZES(brw); + + BRW_BATCH_STRUCT(brw, &uf); + return 0; +} diff --git a/src/gallium/drivers/i965/brw_util.h b/src/gallium/drivers/i965/brw_util.h new file mode 100644 index 0000000..b5f9a36 --- /dev/null +++ b/src/gallium/drivers/i965/brw_util.h @@ -0,0 +1,44 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#ifndef BRW_UTIL_H +#define BRW_UTIL_H + +#include "brw_types.h" + +extern GLuint brw_count_bits( GLuint val ); +extern GLuint brw_translate_blend_factor( unsigned factor ); +extern GLuint brw_translate_blend_equation( unsigned mode ); + + + +#endif diff --git a/src/gallium/drivers/i965/brw_vs.c b/src/gallium/drivers/i965/brw_vs.c new file mode 100644 index 0000000..ca8ee79 --- /dev/null +++ b/src/gallium/drivers/i965/brw_vs.c @@ -0,0 +1,129 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "tgsi/tgsi_dump.h" + +#include "brw_context.h" +#include "brw_vs.h" +#include "brw_state.h" + + + +static enum pipe_error do_vs_prog( struct brw_context *brw, + struct brw_vertex_shader *vp, + struct brw_vs_prog_key *key, + struct brw_winsys_buffer **bo_out) +{ + enum pipe_error ret; + GLuint program_size; + const GLuint *program; + struct brw_vs_compile c; + + memset(&c, 0, sizeof(c)); + memcpy(&c.key, key, sizeof(*key)); + + brw_init_compile(brw, &c.func); + c.vp = vp; + + c.prog_data.nr_outputs = vp->info.num_outputs; + c.prog_data.nr_inputs = vp->info.num_inputs; + + if (1) + tgsi_dump(c.vp->tokens, 0); + + /* Emit GEN4 code. + */ + brw_vs_emit(&c); + + /* get the program + */ + ret = brw_get_program(&c.func, &program, &program_size); + if (ret) + return ret; + + ret = brw_upload_cache( &brw->cache, BRW_VS_PROG, + &c.key, brw_vs_prog_key_size(&c.key), + NULL, 0, + program, program_size, + &c.prog_data, + &brw->vs.prog_data, + bo_out); + if (ret) + return ret; + + return PIPE_OK; +} + + +static enum pipe_error brw_upload_vs_prog(struct brw_context *brw) +{ + struct brw_vs_prog_key key; + struct brw_vertex_shader *vp = brw->curr.vertex_shader; + struct brw_fs_signature *sig = &brw->curr.fragment_shader->signature; + enum pipe_error ret; + + memset(&key, 0, sizeof(key)); + + key.program_string_id = vp->id; + key.nr_userclip = brw->curr.ucp.nr; + + memcpy(&key.fs_signature, sig, brw_fs_signature_size(sig)); + + + /* Make an early check for the key. + */ + if (brw_search_cache(&brw->cache, BRW_VS_PROG, + &key, brw_vs_prog_key_size(&key), + NULL, 0, + &brw->vs.prog_data, + &brw->vs.prog_bo)) + return PIPE_OK; + + ret = do_vs_prog(brw, vp, &key, &brw->vs.prog_bo); + if (ret) + return ret; + + return PIPE_OK; +} + + +/* See brw_vs.c: + */ +const struct brw_tracked_state brw_vs_prog = { + .dirty = { + .mesa = (PIPE_NEW_CLIP | + PIPE_NEW_RAST | + PIPE_NEW_FRAGMENT_SIGNATURE), + .brw = BRW_NEW_VERTEX_PROGRAM, + .cache = 0 + }, + .prepare = brw_upload_vs_prog +}; diff --git a/src/gallium/drivers/i965/brw_vs.h b/src/gallium/drivers/i965/brw_vs.h new file mode 100644 index 0000000..944d88c --- /dev/null +++ b/src/gallium/drivers/i965/brw_vs.h @@ -0,0 +1,106 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#ifndef BRW_VS_H +#define BRW_VS_H + + +#include "brw_context.h" +#include "brw_eu.h" + + +struct brw_vs_prog_key { + GLuint program_string_id; + GLuint nr_userclip:4; + GLuint pad:26; + struct brw_fs_signature fs_signature; +}; + +#define brw_vs_prog_key_size(s) (offsetof(struct brw_vs_prog_key, fs_signature) + \ + brw_fs_signature_size(&(s)->fs_signature)) + + +#define MAX_IF_DEPTH 32 +#define MAX_LOOP_DEPTH 32 + +struct brw_vs_compile { + struct brw_compile func; + struct brw_vs_prog_key key; + struct brw_vs_prog_data prog_data; + struct brw_chipset chipset; + + struct brw_vertex_shader *vp; + + GLuint nr_inputs; + GLuint nr_outputs; + GLuint nr_immediates; + GLfloat immediate[128][4]; + + GLuint overflow_grf_start; + GLuint overflow_count; + + GLuint first_tmp; + GLuint last_tmp; + + struct brw_reg r0; + struct brw_reg r1; + struct brw_reg regs[TGSI_FILE_COUNT][128]; + struct brw_reg tmp; + struct brw_reg stack; + + struct { + GLboolean used_in_src; + struct brw_reg reg; + } output_regs[128]; + + struct brw_reg userplane[6]; + + /** we may need up to 3 constants per instruction (if use_const_buffer) */ + struct { + GLint index; + struct brw_reg reg; + } current_const[3]; + + struct brw_instruction *if_inst[MAX_IF_DEPTH]; + struct brw_instruction *loop_inst[MAX_LOOP_DEPTH]; + GLuint insn; + GLuint if_depth; + GLuint loop_depth; + GLuint end_offset; + + struct brw_indirect stack_index; +}; + + +void brw_vs_emit( struct brw_vs_compile *c ); + +#endif diff --git a/src/gallium/drivers/i965/brw_vs_emit.c b/src/gallium/drivers/i965/brw_vs_emit.c new file mode 100644 index 0000000..5dcbd59 --- /dev/null +++ b/src/gallium/drivers/i965/brw_vs_emit.c @@ -0,0 +1,1657 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "pipe/p_shader_tokens.h" + +#include "util/u_memory.h" +#include "util/u_math.h" + +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_info.h" + +#include "brw_context.h" +#include "brw_vs.h" +#include "brw_debug.h" +#include "brw_disasm.h" + +/* Choose one of the 4 vec4's which can be packed into each 16-wide reg. + */ +static INLINE struct brw_reg brw_vec4_grf_repeat( GLuint reg, GLuint slot ) +{ + int nr = reg + slot/2; + int subnr = (slot%2) * 4; + + return stride(brw_vec4_grf(nr, subnr), 0, 4, 1); +} + + +static struct brw_reg get_tmp( struct brw_vs_compile *c ) +{ + struct brw_reg tmp = brw_vec8_grf(c->last_tmp, 0); + + if (++c->last_tmp > c->prog_data.total_grf) + c->prog_data.total_grf = c->last_tmp; + + return tmp; +} + +static void release_tmp( struct brw_vs_compile *c, struct brw_reg tmp ) +{ + if (tmp.nr == c->last_tmp-1) + c->last_tmp--; +} + +static void release_tmps( struct brw_vs_compile *c ) +{ + c->last_tmp = c->first_tmp; +} + + +static boolean is_position_output( struct brw_vs_compile *c, + unsigned vs_output ) +{ + const struct brw_vertex_shader *vs = c->vp; + unsigned semantic = vs->info.output_semantic_name[vs_output]; + unsigned index = vs->info.output_semantic_index[vs_output]; + + return (semantic == TGSI_SEMANTIC_POSITION && + index == 0); +} + + +static boolean find_output_slot( struct brw_vs_compile *c, + unsigned vs_output, + unsigned *fs_input_slot ) +{ + const struct brw_vertex_shader *vs = c->vp; + unsigned semantic = vs->info.output_semantic_name[vs_output]; + unsigned index = vs->info.output_semantic_index[vs_output]; + unsigned i; + + for (i = 0; i < c->key.fs_signature.nr_inputs; i++) { + if (c->key.fs_signature.input[i].semantic == semantic && + c->key.fs_signature.input[i].semantic_index == index) { + *fs_input_slot = i; + return TRUE; + } + } + + return FALSE; +} + + +/** + * Preallocate GRF register before code emit. + * Do things as simply as possible. Allocate and populate all regs + * ahead of time. + */ +static void brw_vs_alloc_regs( struct brw_vs_compile *c ) +{ + GLuint i, reg = 0, subreg = 0, mrf; + int attributes_in_vue; + + /* Determine whether to use a real constant buffer or use a block + * of GRF registers for constants. The later is faster but only + * works if everything fits in the GRF. + * XXX this heuristic/check may need some fine tuning... + */ + if (c->vp->info.file_max[TGSI_FILE_CONSTANT] + 1 + + c->vp->info.file_max[TGSI_FILE_IMMEDIATE] + 1 + + c->vp->info.file_max[TGSI_FILE_TEMPORARY] + 1 + 21 > BRW_MAX_GRF) + c->vp->use_const_buffer = GL_TRUE; + else { + /* XXX: immediates can go elsewhere if necessary: + */ + assert(c->vp->info.file_max[TGSI_FILE_IMMEDIATE] + 1 + + c->vp->info.file_max[TGSI_FILE_TEMPORARY] + 1 + 21 <= BRW_MAX_GRF); + + c->vp->use_const_buffer = GL_FALSE; + } + + /*printf("use_const_buffer = %d\n", c->vp->use_const_buffer);*/ + + /* r0 -- reserved as usual + */ + c->r0 = brw_vec8_grf(reg, 0); + reg++; + + /* User clip planes from curbe: + */ + if (c->key.nr_userclip) { + /* Skip over fixed planes: Or never read them into vs unit? + */ + subreg += 6; + + for (i = 0; i < c->key.nr_userclip; i++, subreg++) { + c->userplane[i] = + stride( brw_vec4_grf(reg+subreg/2, (subreg%2) * 4), 0, 4, 1); + } + + /* Deal with curbe alignment: + */ + subreg = align(subreg, 2); + /*reg += ((6 + c->key.nr_userclip + 3) / 4) * 2;*/ + } + + + /* Immediates: always in the curbe. + * + * XXX: Can try to encode some immediates as brw immediates + * XXX: Make sure ureg sets minimal immediate size and respect it + * here. + */ + for (i = 0; i < c->vp->info.immediate_count; i++, subreg++) { + c->regs[TGSI_FILE_IMMEDIATE][i] = + stride( brw_vec4_grf(reg+subreg/2, (subreg%2) * 4), 0, 4, 1); + } + c->prog_data.nr_params = c->vp->info.immediate_count * 4; + + + /* Vertex constant buffer. + * + * Constants from the buffer can be either cached in the curbe or + * loaded as needed from the actual constant buffer. + */ + if (!c->vp->use_const_buffer) { + GLuint nr_params = c->vp->info.file_max[TGSI_FILE_CONSTANT] + 1; + + for (i = 0; i < nr_params; i++, subreg++) { + c->regs[TGSI_FILE_CONSTANT][i] = + stride( brw_vec4_grf(reg+subreg/2, (subreg%2) * 4), 0, 4, 1); + } + + c->prog_data.nr_params += nr_params * 4; + } + + /* All regs allocated + */ + reg += (subreg + 1) / 2; + c->prog_data.curb_read_length = reg - 1; + + + /* Allocate input regs: + */ + c->nr_inputs = c->vp->info.num_inputs; + for (i = 0; i < c->nr_inputs; i++) { + c->regs[TGSI_FILE_INPUT][i] = brw_vec8_grf(reg, 0); + reg++; + } + + /* If there are no inputs, we'll still be reading one attribute's worth + * because it's required -- see urb_read_length setting. + */ + if (c->nr_inputs == 0) + reg++; + + + + /* Allocate outputs. The non-position outputs go straight into message regs. + */ + c->nr_outputs = c->prog_data.nr_outputs; + + if (c->chipset.is_igdng) + mrf = 8; + else + mrf = 4; + + + if (c->key.fs_signature.nr_inputs > BRW_MAX_MRF) { + c->overflow_grf_start = reg; + c->overflow_count = c->key.fs_signature.nr_inputs - BRW_MAX_MRF; + reg += c->overflow_count; + } + + /* XXX: need to access vertex output semantics here: + */ + for (i = 0; i < c->nr_outputs; i++) { + unsigned slot; + + /* XXX: Put output position in slot zero always. Clipper, etc, + * need access to this reg. + */ + if (is_position_output(c, i)) { + c->regs[TGSI_FILE_OUTPUT][i] = brw_vec8_grf(reg, 0); /* copy to mrf 0 */ + reg++; + } + else if (find_output_slot(c, i, &slot)) { + + if (0 /* is_psize_output(c, i) */ ) { + /* c->psize_out.grf = reg; */ + /* c->psize_out.mrf = i; */ + } + + /* The first (16-4) outputs can go straight into the message regs. + */ + if (slot + mrf < BRW_MAX_MRF) { + c->regs[TGSI_FILE_OUTPUT][i] = brw_message_reg(slot + mrf); + } + else { + int grf = c->overflow_grf_start + slot - BRW_MAX_MRF; + c->regs[TGSI_FILE_OUTPUT][i] = brw_vec8_grf(grf, 0); + } + } + else { + c->regs[TGSI_FILE_OUTPUT][i] = brw_null_reg(); + } + } + + /* Allocate program temporaries: + */ + + for (i = 0; i < c->vp->info.file_max[TGSI_FILE_TEMPORARY]+1; i++) { + c->regs[TGSI_FILE_TEMPORARY][i] = brw_vec8_grf(reg, 0); + reg++; + } + + /* Address reg(s). Don't try to use the internal address reg until + * deref time. + */ + for (i = 0; i < c->vp->info.file_max[TGSI_FILE_ADDRESS]+1; i++) { + c->regs[TGSI_FILE_ADDRESS][i] = brw_reg(BRW_GENERAL_REGISTER_FILE, + reg, + 0, + BRW_REGISTER_TYPE_D, + BRW_VERTICAL_STRIDE_8, + BRW_WIDTH_8, + BRW_HORIZONTAL_STRIDE_1, + BRW_SWIZZLE_XXXX, + BRW_WRITEMASK_X); + reg++; + } + + if (c->vp->use_const_buffer) { + for (i = 0; i < 3; i++) { + c->current_const[i].index = -1; + c->current_const[i].reg = brw_vec8_grf(reg, 0); + reg++; + } + } + +#if 0 + for (i = 0; i < 128; i++) { + if (c->output_regs[i].used_in_src) { + c->output_regs[i].reg = brw_vec8_grf(reg, 0); + reg++; + } + } +#endif + + if (c->vp->has_flow_control) { + c->stack = brw_uw16_reg(BRW_GENERAL_REGISTER_FILE, reg, 0); + reg += 2; + } + + /* Some opcodes need an internal temporary: + */ + c->first_tmp = reg; + c->last_tmp = reg; /* for allocation purposes */ + + /* Each input reg holds data from two vertices. The + * urb_read_length is the number of registers read from *each* + * vertex urb, so is half the amount: + */ + c->prog_data.urb_read_length = (c->nr_inputs + 1) / 2; + + /* Setting this field to 0 leads to undefined behavior according to the + * the VS_STATE docs. Our VUEs will always have at least one attribute + * sitting in them, even if it's padding. + */ + if (c->prog_data.urb_read_length == 0) + c->prog_data.urb_read_length = 1; + + /* The VS VUEs are shared by VF (outputting our inputs) and VS, so size + * them to fit the biggest thing they need to. + */ + attributes_in_vue = MAX2(c->nr_outputs, c->nr_inputs); + + if (c->chipset.is_igdng) + c->prog_data.urb_entry_size = (attributes_in_vue + 6 + 3) / 4; + else + c->prog_data.urb_entry_size = (attributes_in_vue + 2 + 3) / 4; + + c->prog_data.total_grf = reg; + + if (BRW_DEBUG & DEBUG_VS) { + debug_printf("%s NumAddrRegs %d\n", __FUNCTION__, + c->vp->info.file_max[TGSI_FILE_ADDRESS]+1); + debug_printf("%s NumTemps %d\n", __FUNCTION__, + c->vp->info.file_max[TGSI_FILE_TEMPORARY]+1); + debug_printf("%s reg = %d\n", __FUNCTION__, reg); + } +} + + +/** + * If an instruction uses a temp reg both as a src and the dest, we + * sometimes need to allocate an intermediate temporary. + */ +static void unalias1( struct brw_vs_compile *c, + struct brw_reg dst, + struct brw_reg arg0, + void (*func)( struct brw_vs_compile *, + struct brw_reg, + struct brw_reg )) +{ + if (dst.file == arg0.file && dst.nr == arg0.nr) { + struct brw_compile *p = &c->func; + struct brw_reg tmp = brw_writemask(get_tmp(c), dst.dw1.bits.writemask); + func(c, tmp, arg0); + brw_MOV(p, dst, tmp); + release_tmp(c, tmp); + } + else { + func(c, dst, arg0); + } +} + +/** + * \sa unalias2 + * Checkes if 2-operand instruction needs an intermediate temporary. + */ +static void unalias2( struct brw_vs_compile *c, + struct brw_reg dst, + struct brw_reg arg0, + struct brw_reg arg1, + void (*func)( struct brw_vs_compile *, + struct brw_reg, + struct brw_reg, + struct brw_reg )) +{ + if ((dst.file == arg0.file && dst.nr == arg0.nr) || + (dst.file == arg1.file && dst.nr == arg1.nr)) { + struct brw_compile *p = &c->func; + struct brw_reg tmp = brw_writemask(get_tmp(c), dst.dw1.bits.writemask); + func(c, tmp, arg0, arg1); + brw_MOV(p, dst, tmp); + release_tmp(c, tmp); + } + else { + func(c, dst, arg0, arg1); + } +} + +/** + * \sa unalias2 + * Checkes if 3-operand instruction needs an intermediate temporary. + */ +static void unalias3( struct brw_vs_compile *c, + struct brw_reg dst, + struct brw_reg arg0, + struct brw_reg arg1, + struct brw_reg arg2, + void (*func)( struct brw_vs_compile *, + struct brw_reg, + struct brw_reg, + struct brw_reg, + struct brw_reg )) +{ + if ((dst.file == arg0.file && dst.nr == arg0.nr) || + (dst.file == arg1.file && dst.nr == arg1.nr) || + (dst.file == arg2.file && dst.nr == arg2.nr)) { + struct brw_compile *p = &c->func; + struct brw_reg tmp = brw_writemask(get_tmp(c), dst.dw1.bits.writemask); + func(c, tmp, arg0, arg1, arg2); + brw_MOV(p, dst, tmp); + release_tmp(c, tmp); + } + else { + func(c, dst, arg0, arg1, arg2); + } +} + +static void emit_sop( struct brw_compile *p, + struct brw_reg dst, + struct brw_reg arg0, + struct brw_reg arg1, + GLuint cond) +{ + brw_MOV(p, dst, brw_imm_f(0.0f)); + brw_CMP(p, brw_null_reg(), cond, arg0, arg1); + brw_MOV(p, dst, brw_imm_f(1.0f)); + brw_set_predicate_control_flag_value(p, 0xff); +} + +static void emit_seq( struct brw_compile *p, + struct brw_reg dst, + struct brw_reg arg0, + struct brw_reg arg1 ) +{ + emit_sop(p, dst, arg0, arg1, BRW_CONDITIONAL_EQ); +} + +static void emit_sne( struct brw_compile *p, + struct brw_reg dst, + struct brw_reg arg0, + struct brw_reg arg1 ) +{ + emit_sop(p, dst, arg0, arg1, BRW_CONDITIONAL_NEQ); +} +static void emit_slt( struct brw_compile *p, + struct brw_reg dst, + struct brw_reg arg0, + struct brw_reg arg1 ) +{ + emit_sop(p, dst, arg0, arg1, BRW_CONDITIONAL_L); +} + +static void emit_sle( struct brw_compile *p, + struct brw_reg dst, + struct brw_reg arg0, + struct brw_reg arg1 ) +{ + emit_sop(p, dst, arg0, arg1, BRW_CONDITIONAL_LE); +} + +static void emit_sgt( struct brw_compile *p, + struct brw_reg dst, + struct brw_reg arg0, + struct brw_reg arg1 ) +{ + emit_sop(p, dst, arg0, arg1, BRW_CONDITIONAL_G); +} + +static void emit_sge( struct brw_compile *p, + struct brw_reg dst, + struct brw_reg arg0, + struct brw_reg arg1 ) +{ + emit_sop(p, dst, arg0, arg1, BRW_CONDITIONAL_GE); +} + +static void emit_max( struct brw_compile *p, + struct brw_reg dst, + struct brw_reg arg0, + struct brw_reg arg1 ) +{ + brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_L, arg0, arg1); + brw_SEL(p, dst, arg1, arg0); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); +} + +static void emit_min( struct brw_compile *p, + struct brw_reg dst, + struct brw_reg arg0, + struct brw_reg arg1 ) +{ + brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_L, arg0, arg1); + brw_SEL(p, dst, arg0, arg1); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); +} + + +static void emit_math1( struct brw_vs_compile *c, + GLuint function, + struct brw_reg dst, + struct brw_reg arg0, + GLuint precision) +{ + /* There are various odd behaviours with SEND on the simulator. In + * addition there are documented issues with the fact that the GEN4 + * processor doesn't do dependency control properly on SEND + * results. So, on balance, this kludge to get around failures + * with writemasked math results looks like it might be necessary + * whether that turns out to be a simulator bug or not: + */ + struct brw_compile *p = &c->func; + struct brw_reg tmp = dst; + GLboolean need_tmp = (dst.dw1.bits.writemask != 0xf || + dst.file != BRW_GENERAL_REGISTER_FILE); + + if (need_tmp) + tmp = get_tmp(c); + + brw_math(p, + tmp, + function, + BRW_MATH_SATURATE_NONE, + 2, + arg0, + BRW_MATH_DATA_SCALAR, + precision); + + if (need_tmp) { + brw_MOV(p, dst, tmp); + release_tmp(c, tmp); + } +} + + +static void emit_math2( struct brw_vs_compile *c, + GLuint function, + struct brw_reg dst, + struct brw_reg arg0, + struct brw_reg arg1, + GLuint precision) +{ + struct brw_compile *p = &c->func; + struct brw_reg tmp = dst; + GLboolean need_tmp = (dst.dw1.bits.writemask != 0xf || + dst.file != BRW_GENERAL_REGISTER_FILE); + + if (need_tmp) + tmp = get_tmp(c); + + brw_MOV(p, brw_message_reg(3), arg1); + + brw_math(p, + tmp, + function, + BRW_MATH_SATURATE_NONE, + 2, + arg0, + BRW_MATH_DATA_SCALAR, + precision); + + if (need_tmp) { + brw_MOV(p, dst, tmp); + release_tmp(c, tmp); + } +} + + +static void emit_exp_noalias( struct brw_vs_compile *c, + struct brw_reg dst, + struct brw_reg arg0 ) +{ + struct brw_compile *p = &c->func; + + + if (dst.dw1.bits.writemask & BRW_WRITEMASK_X) { + struct brw_reg tmp = get_tmp(c); + struct brw_reg tmp_d = retype(tmp, BRW_REGISTER_TYPE_D); + + /* tmp_d = floor(arg0.x) */ + brw_RNDD(p, tmp_d, brw_swizzle1(arg0, 0)); + + /* result[0] = 2.0 ^ tmp */ + + /* Adjust exponent for floating point: + * exp += 127 + */ + brw_ADD(p, brw_writemask(tmp_d, BRW_WRITEMASK_X), tmp_d, brw_imm_d(127)); + + /* Install exponent and sign. + * Excess drops off the edge: + */ + brw_SHL(p, brw_writemask(retype(dst, BRW_REGISTER_TYPE_D), BRW_WRITEMASK_X), + tmp_d, brw_imm_d(23)); + + release_tmp(c, tmp); + } + + if (dst.dw1.bits.writemask & BRW_WRITEMASK_Y) { + /* result[1] = arg0.x - floor(arg0.x) */ + brw_FRC(p, brw_writemask(dst, BRW_WRITEMASK_Y), brw_swizzle1(arg0, 0)); + } + + if (dst.dw1.bits.writemask & BRW_WRITEMASK_Z) { + /* As with the LOG instruction, we might be better off just + * doing a taylor expansion here, seeing as we have to do all + * the prep work. + * + * If mathbox partial precision is too low, consider also: + * result[3] = result[0] * EXP(result[1]) + */ + emit_math1(c, + BRW_MATH_FUNCTION_EXP, + brw_writemask(dst, BRW_WRITEMASK_Z), + brw_swizzle1(arg0, 0), + BRW_MATH_PRECISION_FULL); + } + + if (dst.dw1.bits.writemask & BRW_WRITEMASK_W) { + /* result[3] = 1.0; */ + brw_MOV(p, brw_writemask(dst, BRW_WRITEMASK_W), brw_imm_f(1)); + } +} + + +static void emit_log_noalias( struct brw_vs_compile *c, + struct brw_reg dst, + struct brw_reg arg0 ) +{ + struct brw_compile *p = &c->func; + struct brw_reg tmp = dst; + struct brw_reg tmp_ud = retype(tmp, BRW_REGISTER_TYPE_UD); + struct brw_reg arg0_ud = retype(arg0, BRW_REGISTER_TYPE_UD); + GLboolean need_tmp = (dst.dw1.bits.writemask != 0xf || + dst.file != BRW_GENERAL_REGISTER_FILE); + + if (need_tmp) { + tmp = get_tmp(c); + tmp_ud = retype(tmp, BRW_REGISTER_TYPE_UD); + } + + /* Perform mant = frexpf(fabsf(x), &exp), adjust exp and mnt + * according to spec: + * + * These almost look likey they could be joined up, but not really + * practical: + * + * result[0].f = (x.i & ((1<<31)-1) >> 23) - 127 + * result[1].i = (x.i & ((1<<23)-1) + (127<<23) + */ + if (dst.dw1.bits.writemask & BRW_WRITEMASK_XZ) { + brw_AND(p, + brw_writemask(tmp_ud, BRW_WRITEMASK_X), + brw_swizzle1(arg0_ud, 0), + brw_imm_ud((1U<<31)-1)); + + brw_SHR(p, + brw_writemask(tmp_ud, BRW_WRITEMASK_X), + tmp_ud, + brw_imm_ud(23)); + + brw_ADD(p, + brw_writemask(tmp, BRW_WRITEMASK_X), + retype(tmp_ud, BRW_REGISTER_TYPE_D), /* does it matter? */ + brw_imm_d(-127)); + } + + if (dst.dw1.bits.writemask & BRW_WRITEMASK_YZ) { + brw_AND(p, + brw_writemask(tmp_ud, BRW_WRITEMASK_Y), + brw_swizzle1(arg0_ud, 0), + brw_imm_ud((1<<23)-1)); + + brw_OR(p, + brw_writemask(tmp_ud, BRW_WRITEMASK_Y), + tmp_ud, + brw_imm_ud(127<<23)); + } + + if (dst.dw1.bits.writemask & BRW_WRITEMASK_Z) { + /* result[2] = result[0] + LOG2(result[1]); */ + + /* Why bother? The above is just a hint how to do this with a + * taylor series. Maybe we *should* use a taylor series as by + * the time all the above has been done it's almost certainly + * quicker than calling the mathbox, even with low precision. + * + * Options are: + * - result[0] + mathbox.LOG2(result[1]) + * - mathbox.LOG2(arg0.x) + * - result[0] + inline_taylor_approx(result[1]) + */ + emit_math1(c, + BRW_MATH_FUNCTION_LOG, + brw_writemask(tmp, BRW_WRITEMASK_Z), + brw_swizzle1(tmp, 1), + BRW_MATH_PRECISION_FULL); + + brw_ADD(p, + brw_writemask(tmp, BRW_WRITEMASK_Z), + brw_swizzle1(tmp, 2), + brw_swizzle1(tmp, 0)); + } + + if (dst.dw1.bits.writemask & BRW_WRITEMASK_W) { + /* result[3] = 1.0; */ + brw_MOV(p, brw_writemask(tmp, BRW_WRITEMASK_W), brw_imm_f(1)); + } + + if (need_tmp) { + brw_MOV(p, dst, tmp); + release_tmp(c, tmp); + } +} + + +/* Need to unalias - consider swizzles: r0 = DST r0.xxxx r1 + */ +static void emit_dst_noalias( struct brw_vs_compile *c, + struct brw_reg dst, + struct brw_reg arg0, + struct brw_reg arg1) +{ + struct brw_compile *p = &c->func; + + /* There must be a better way to do this: + */ + if (dst.dw1.bits.writemask & BRW_WRITEMASK_X) + brw_MOV(p, brw_writemask(dst, BRW_WRITEMASK_X), brw_imm_f(1.0)); + if (dst.dw1.bits.writemask & BRW_WRITEMASK_Y) + brw_MUL(p, brw_writemask(dst, BRW_WRITEMASK_Y), arg0, arg1); + if (dst.dw1.bits.writemask & BRW_WRITEMASK_Z) + brw_MOV(p, brw_writemask(dst, BRW_WRITEMASK_Z), arg0); + if (dst.dw1.bits.writemask & BRW_WRITEMASK_W) + brw_MOV(p, brw_writemask(dst, BRW_WRITEMASK_W), arg1); +} + + +static void emit_xpd( struct brw_compile *p, + struct brw_reg dst, + struct brw_reg t, + struct brw_reg u) +{ + brw_MUL(p, brw_null_reg(), brw_swizzle(t, 1,2,0,3), brw_swizzle(u,2,0,1,3)); + brw_MAC(p, dst, negate(brw_swizzle(t, 2,0,1,3)), brw_swizzle(u,1,2,0,3)); +} + + +static void emit_lit_noalias( struct brw_vs_compile *c, + struct brw_reg dst, + struct brw_reg arg0 ) +{ + struct brw_compile *p = &c->func; + struct brw_instruction *if_insn; + struct brw_reg tmp = dst; + GLboolean need_tmp = (dst.file != BRW_GENERAL_REGISTER_FILE); + + if (need_tmp) + tmp = get_tmp(c); + + brw_MOV(p, brw_writemask(dst, BRW_WRITEMASK_YZ), brw_imm_f(0)); + brw_MOV(p, brw_writemask(dst, BRW_WRITEMASK_XW), brw_imm_f(1)); + + /* Need to use BRW_EXECUTE_8 and also do an 8-wide compare in order + * to get all channels active inside the IF. In the clipping code + * we run with NoMask, so it's not an option and we can use + * BRW_EXECUTE_1 for all comparisions. + */ + brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_G, brw_swizzle1(arg0,0), brw_imm_f(0)); + if_insn = brw_IF(p, BRW_EXECUTE_8); + { + brw_MOV(p, brw_writemask(dst, BRW_WRITEMASK_Y), brw_swizzle1(arg0,0)); + + brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_G, brw_swizzle1(arg0,1), brw_imm_f(0)); + brw_MOV(p, brw_writemask(tmp, BRW_WRITEMASK_Z), brw_swizzle1(arg0,1)); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + + emit_math2(c, + BRW_MATH_FUNCTION_POW, + brw_writemask(dst, BRW_WRITEMASK_Z), + brw_swizzle1(tmp, 2), + brw_swizzle1(arg0, 3), + BRW_MATH_PRECISION_PARTIAL); + } + + brw_ENDIF(p, if_insn); + + release_tmp(c, tmp); +} + +static void emit_lrp_noalias(struct brw_vs_compile *c, + struct brw_reg dst, + struct brw_reg arg0, + struct brw_reg arg1, + struct brw_reg arg2) +{ + struct brw_compile *p = &c->func; + + brw_ADD(p, dst, negate(arg0), brw_imm_f(1.0)); + brw_MUL(p, brw_null_reg(), dst, arg2); + brw_MAC(p, dst, arg0, arg1); +} + +/** 3 or 4-component vector normalization */ +static void emit_nrm( struct brw_vs_compile *c, + struct brw_reg dst, + struct brw_reg arg0, + int num_comps) +{ + struct brw_compile *p = &c->func; + struct brw_reg tmp = get_tmp(c); + + /* tmp = dot(arg0, arg0) */ + if (num_comps == 3) + brw_DP3(p, tmp, arg0, arg0); + else + brw_DP4(p, tmp, arg0, arg0); + + /* tmp = 1 / sqrt(tmp) */ + emit_math1(c, BRW_MATH_FUNCTION_RSQ, tmp, tmp, BRW_MATH_PRECISION_FULL); + + /* dst = arg0 * tmp */ + brw_MUL(p, dst, arg0, tmp); + + release_tmp(c, tmp); +} + + +static struct brw_reg +get_constant(struct brw_vs_compile *c, + GLuint argIndex, + GLuint index, + GLboolean relAddr) +{ + struct brw_compile *p = &c->func; + struct brw_reg const_reg; + struct brw_reg const2_reg; + + assert(argIndex < 3); + + if (c->current_const[argIndex].index != index || relAddr) { + struct brw_reg addrReg = c->regs[TGSI_FILE_ADDRESS][0]; + + c->current_const[argIndex].index = index; + +#if 0 + printf(" fetch const[%d] for arg %d into reg %d\n", + src.Index, argIndex, c->current_const[argIndex].reg.nr); +#endif + /* need to fetch the constant now */ + brw_dp_READ_4_vs(p, + c->current_const[argIndex].reg,/* writeback dest */ + 0, /* oword */ + relAddr, /* relative indexing? */ + addrReg, /* address register */ + 16 * index, /* byte offset */ + SURF_INDEX_VERT_CONST_BUFFER /* binding table index */ + ); + + if (relAddr) { + /* second read */ + const2_reg = get_tmp(c); + + /* use upper half of address reg for second read */ + addrReg = stride(addrReg, 0, 4, 0); + addrReg.subnr = 16; + + brw_dp_READ_4_vs(p, + const2_reg, /* writeback dest */ + 1, /* oword */ + relAddr, /* relative indexing? */ + addrReg, /* address register */ + 16 * index, /* byte offset */ + SURF_INDEX_VERT_CONST_BUFFER + ); + } + } + + const_reg = c->current_const[argIndex].reg; + + if (relAddr) { + /* merge the two Owords into the constant register */ + /* const_reg[7..4] = const2_reg[7..4] */ + brw_MOV(p, + suboffset(stride(const_reg, 0, 4, 1), 4), + suboffset(stride(const2_reg, 0, 4, 1), 4)); + release_tmp(c, const2_reg); + } + else { + /* replicate lower four floats into upper half (to get XYZWXYZW) */ + const_reg = stride(const_reg, 0, 4, 0); + const_reg.subnr = 0; + } + + return const_reg; +} + + +#if 0 + +/* TODO: relative addressing! + */ +static struct brw_reg get_reg( struct brw_vs_compile *c, + enum tgsi_file_type file, + GLuint index ) +{ + switch (file) { + case TGSI_FILE_TEMPORARY: + case TGSI_FILE_INPUT: + case TGSI_FILE_OUTPUT: + case TGSI_FILE_CONSTANT: + assert(c->regs[file][index].nr != 0); + return c->regs[file][index]; + + case TGSI_FILE_ADDRESS: + assert(index == 0); + return c->regs[file][index]; + + case TGSI_FILE_NULL: /* undef values */ + return brw_null_reg(); + + default: + assert(0); + return brw_null_reg(); + } +} + +#endif + + +/** + * Indirect addressing: get reg[[arg] + offset]. + */ +static struct brw_reg deref( struct brw_vs_compile *c, + struct brw_reg arg, + GLint offset) +{ + struct brw_compile *p = &c->func; + struct brw_reg tmp = vec4(get_tmp(c)); + struct brw_reg addr_reg = c->regs[TGSI_FILE_ADDRESS][0]; + struct brw_reg vp_address = retype(vec1(addr_reg), BRW_REGISTER_TYPE_UW); + GLuint byte_offset = arg.nr * 32 + arg.subnr + offset * 16; + struct brw_reg indirect = brw_vec4_indirect(0,0); + + { + brw_push_insn_state(p); + brw_set_access_mode(p, BRW_ALIGN_1); + + /* This is pretty clunky - load the address register twice and + * fetch each 4-dword value in turn. There must be a way to do + * this in a single pass, but I couldn't get it to work. + */ + brw_ADD(p, brw_address_reg(0), vp_address, brw_imm_d(byte_offset)); + brw_MOV(p, tmp, indirect); + + brw_ADD(p, brw_address_reg(0), suboffset(vp_address, 8), brw_imm_d(byte_offset)); + brw_MOV(p, suboffset(tmp, 4), indirect); + + brw_pop_insn_state(p); + } + + /* NOTE: tmp not released */ + return vec8(tmp); +} + + +/** + * Get brw reg corresponding to the instruction's [argIndex] src reg. + * TODO: relative addressing! + */ +static struct brw_reg +get_src_reg( struct brw_vs_compile *c, + GLuint argIndex, + GLuint file, + GLint index, + GLboolean relAddr ) +{ + + switch (file) { + case TGSI_FILE_TEMPORARY: + case TGSI_FILE_INPUT: + case TGSI_FILE_OUTPUT: + if (relAddr) { + return deref(c, c->regs[file][0], index); + } + else { + assert(c->regs[file][index].nr != 0); + return c->regs[file][index]; + } + + case TGSI_FILE_IMMEDIATE: + return c->regs[file][index]; + + case TGSI_FILE_CONSTANT: + if (c->vp->use_const_buffer) { + return get_constant(c, argIndex, index, relAddr); + } + else if (relAddr) { + return deref(c, c->regs[TGSI_FILE_CONSTANT][0], index); + } + else { + assert(c->regs[TGSI_FILE_CONSTANT][index].nr != 0); + return c->regs[TGSI_FILE_CONSTANT][index]; + } + case TGSI_FILE_ADDRESS: + assert(index == 0); + return c->regs[file][index]; + + case TGSI_FILE_NULL: + /* this is a normal case since we loop over all three src args */ + return brw_null_reg(); + + default: + assert(0); + return brw_null_reg(); + } +} + + +static void emit_arl( struct brw_vs_compile *c, + struct brw_reg dst, + struct brw_reg arg0 ) +{ + struct brw_compile *p = &c->func; + struct brw_reg tmp = dst; + GLboolean need_tmp = (dst.file != BRW_GENERAL_REGISTER_FILE); + + if (need_tmp) + tmp = get_tmp(c); + + brw_RNDD(p, tmp, arg0); /* tmp = round(arg0) */ + brw_MUL(p, dst, tmp, brw_imm_d(16)); /* dst = tmp * 16 */ + + if (need_tmp) + release_tmp(c, tmp); +} + + +/** + * Return the brw reg for the given instruction's src argument. + */ +static struct brw_reg get_arg( struct brw_vs_compile *c, + const struct tgsi_full_src_register *src, + GLuint argIndex ) +{ + struct brw_reg reg; + + if (src->Register.File == TGSI_FILE_NULL) + return brw_null_reg(); + + reg = get_src_reg(c, argIndex, + src->Register.File, + src->Register.Index, + src->Register.Indirect); + + /* Convert 3-bit swizzle to 2-bit. + */ + reg.dw1.bits.swizzle = BRW_SWIZZLE4(src->Register.SwizzleX, + src->Register.SwizzleY, + src->Register.SwizzleZ, + src->Register.SwizzleW); + + reg.negate = src->Register.Negate ? 1 : 0; + + /* XXX: abs, absneg + */ + + return reg; +} + + +/** + * Get brw register for the given program dest register. + */ +static struct brw_reg get_dst( struct brw_vs_compile *c, + unsigned file, + unsigned index, + unsigned writemask ) +{ + struct brw_reg reg; + + switch (file) { + case TGSI_FILE_TEMPORARY: + case TGSI_FILE_OUTPUT: + assert(c->regs[file][index].nr != 0); + reg = c->regs[file][index]; + break; + case TGSI_FILE_ADDRESS: + assert(index == 0); + reg = c->regs[file][index]; + break; + case TGSI_FILE_NULL: + /* we may hit this for OPCODE_END, OPCODE_KIL, etc */ + reg = brw_null_reg(); + break; + default: + assert(0); + reg = brw_null_reg(); + } + + reg.dw1.bits.writemask = writemask; + + return reg; +} + + + + +/** + * Post-vertex-program processing. Send the results to the URB. + */ +static void emit_vertex_write( struct brw_vs_compile *c) +{ + struct brw_compile *p = &c->func; + struct brw_reg m0 = brw_message_reg(0); + struct brw_reg pos = c->regs[TGSI_FILE_OUTPUT][VERT_RESULT_HPOS]; + struct brw_reg ndc; + int eot; + int i; + GLuint len_vertext_header = 2; + + /* Build ndc coords */ + ndc = get_tmp(c); + /* ndc = 1.0 / pos.w */ + emit_math1(c, BRW_MATH_FUNCTION_INV, ndc, brw_swizzle1(pos, 3), BRW_MATH_PRECISION_FULL); + /* ndc.xyz = pos * ndc */ + brw_MUL(p, brw_writemask(ndc, BRW_WRITEMASK_XYZ), pos, ndc); + + /* Update the header for point size, user clipping flags, and -ve rhw + * workaround. + */ + if (c->prog_data.writes_psiz || + c->key.nr_userclip || + c->chipset.is_965) + { + struct brw_reg header1 = retype(get_tmp(c), BRW_REGISTER_TYPE_UD); + GLuint i; + + brw_MOV(p, header1, brw_imm_ud(0)); + + brw_set_access_mode(p, BRW_ALIGN_16); + + if (c->prog_data.writes_psiz) { + struct brw_reg psiz = c->regs[TGSI_FILE_OUTPUT][VERT_RESULT_PSIZ]; + brw_MUL(p, brw_writemask(header1, BRW_WRITEMASK_W), brw_swizzle1(psiz, 0), brw_imm_f(1<<11)); + brw_AND(p, brw_writemask(header1, BRW_WRITEMASK_W), header1, brw_imm_ud(0x7ff<<8)); + } + + for (i = 0; i < c->key.nr_userclip; i++) { + brw_set_conditionalmod(p, BRW_CONDITIONAL_L); + brw_DP4(p, brw_null_reg(), pos, c->userplane[i]); + brw_OR(p, brw_writemask(header1, BRW_WRITEMASK_W), header1, brw_imm_ud(1<chipset.is_965) { + brw_CMP(p, + vec8(brw_null_reg()), + BRW_CONDITIONAL_L, + brw_swizzle1(ndc, 3), + brw_imm_f(0)); + + brw_OR(p, brw_writemask(header1, BRW_WRITEMASK_W), header1, brw_imm_ud(1<<6)); + brw_MOV(p, ndc, brw_imm_f(0)); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + } + + brw_set_access_mode(p, BRW_ALIGN_1); /* why? */ + brw_MOV(p, retype(brw_message_reg(1), BRW_REGISTER_TYPE_UD), header1); + brw_set_access_mode(p, BRW_ALIGN_16); + + release_tmp(c, header1); + } + else { + brw_MOV(p, retype(brw_message_reg(1), BRW_REGISTER_TYPE_UD), brw_imm_ud(0)); + } + + /* Emit the (interleaved) headers for the two vertices - an 8-reg + * of zeros followed by two sets of NDC coordinates: + */ + brw_set_access_mode(p, BRW_ALIGN_1); + brw_MOV(p, offset(m0, 2), ndc); + + if (c->chipset.is_igdng) { + /* There are 20 DWs (D0-D19) in VUE vertex header on IGDNG */ + brw_MOV(p, offset(m0, 3), pos); /* a portion of vertex header */ + /* m4, m5 contain the distances from vertex to the user clip planeXXX. + * Seems it is useless for us. + * m6 is used for aligning, so that the remainder of vertex element is + * reg-aligned. + */ + brw_MOV(p, offset(m0, 7), pos); /* the remainder of vertex element */ + len_vertext_header = 6; + } else { + brw_MOV(p, offset(m0, 3), pos); + len_vertext_header = 2; + } + + eot = (c->overflow_count == 0); + + brw_urb_WRITE(p, + brw_null_reg(), /* dest */ + 0, /* starting mrf reg nr */ + c->r0, /* src */ + 0, /* allocate */ + 1, /* used */ + MIN2(c->nr_outputs + 1 + len_vertext_header, (BRW_MAX_MRF-1)), /* msg len */ + 0, /* response len */ + eot, /* eot */ + eot, /* writes complete */ + 0, /* urb destination offset */ + BRW_URB_SWIZZLE_INTERLEAVE); + + /* Not all of the vertex outputs/results fit into the MRF. + * Move the overflowed attributes from the GRF to the MRF and + * issue another brw_urb_WRITE(). + */ + for (i = 0; i < c->overflow_count; i += BRW_MAX_MRF) { + unsigned nr = MIN2(c->overflow_count - i, BRW_MAX_MRF); + GLuint j; + + eot = (i + nr >= c->overflow_count); + + /* XXX I'm not 100% sure about which MRF regs to use here. Starting + * at mrf[4] atm... + */ + for (j = 0; j < nr; j++) { + brw_MOV(p, brw_message_reg(4+j), + brw_vec8_grf(c->overflow_grf_start + i + j, 0)); + } + + brw_urb_WRITE(p, + brw_null_reg(), /* dest */ + 4, /* starting mrf reg nr */ + c->r0, /* src */ + 0, /* allocate */ + 1, /* used */ + nr+1, /* msg len */ + 0, /* response len */ + eot, /* eot */ + eot, /* writes complete */ + i-1, /* urb destination offset */ + BRW_URB_SWIZZLE_INTERLEAVE); + } +} + + +/** + * Called after code generation to resolve subroutine calls and the + * END instruction. + * \param end_inst points to brw code for END instruction + * \param last_inst points to last instruction emitted before vertex write + */ +static void +post_vs_emit( struct brw_vs_compile *c, + struct brw_instruction *end_inst, + struct brw_instruction *last_inst ) +{ + GLint offset; + + brw_resolve_cals(&c->func); + + /* patch up the END code to jump past subroutines, etc */ + offset = last_inst - end_inst; + if (offset > 1) { + brw_set_src1(end_inst, brw_imm_d(offset * 16)); + } else { + end_inst->header.opcode = BRW_OPCODE_NOP; + } +} + +static uint32_t +get_predicate(const struct tgsi_full_instruction *inst) +{ + /* XXX: disabling for now + */ +#if 0 + if (inst->dst.CondMask == COND_TR) + return BRW_PREDICATE_NONE; + + /* All of GLSL only produces predicates for COND_NE and one channel per + * vector. Fail badly if someone starts doing something else, as it might + * mean infinite looping or something. + * + * We'd like to support all the condition codes, but our hardware doesn't + * quite match the Mesa IR, which is modeled after the NV extensions. For + * those, the instruction may update the condition codes or not, then any + * later instruction may use one of those condition codes. For gen4, the + * instruction may update the flags register based on one of the condition + * codes output by the instruction, and then further instructions may + * predicate on that. We can probably support this, but it won't + * necessarily be easy. + */ +/* assert(inst->dst.CondMask == COND_NE); */ + + switch (inst->dst.CondSwizzle) { + case SWIZZLE_XXXX: + return BRW_PREDICATE_ALIGN16_REPLICATE_X; + case SWIZZLE_YYYY: + return BRW_PREDICATE_ALIGN16_REPLICATE_Y; + case SWIZZLE_ZZZZ: + return BRW_PREDICATE_ALIGN16_REPLICATE_Z; + case SWIZZLE_WWWW: + return BRW_PREDICATE_ALIGN16_REPLICATE_W; + default: + debug_printf("Unexpected predicate: 0x%08x\n", + inst->dst.CondMask); + return BRW_PREDICATE_NORMAL; + } +#else + return BRW_PREDICATE_NORMAL; +#endif +} + +static void emit_insn(struct brw_vs_compile *c, + const struct tgsi_full_instruction *inst) +{ + unsigned opcode = inst->Instruction.Opcode; + unsigned label = inst->Label.Label; + struct brw_compile *p = &c->func; + struct brw_reg args[3], dst; + GLuint i; + +#if 0 + printf("%d: ", insn); + _mesa_print_instruction(inst); +#endif + + /* Get argument regs. + */ + for (i = 0; i < 3; i++) { + args[i] = get_arg(c, &inst->Src[i], i); + } + + /* Get dest regs. Note that it is possible for a reg to be both + * dst and arg, given the static allocation of registers. So + * care needs to be taken emitting multi-operation instructions. + */ + dst = get_dst(c, + inst->Dst[0].Register.File, + inst->Dst[0].Register.Index, + inst->Dst[0].Register.WriteMask); + + /* XXX: saturate + */ + if (inst->Instruction.Saturate != TGSI_SAT_NONE) { + debug_printf("Unsupported saturate in vertex shader"); + } + + switch (opcode) { + case TGSI_OPCODE_ABS: + brw_MOV(p, dst, brw_abs(args[0])); + break; + case TGSI_OPCODE_ADD: + brw_ADD(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_COS: + emit_math1(c, BRW_MATH_FUNCTION_COS, dst, args[0], BRW_MATH_PRECISION_FULL); + break; + case TGSI_OPCODE_DP3: + brw_DP3(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_DP4: + brw_DP4(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_DPH: + brw_DPH(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_NRM: + emit_nrm(c, dst, args[0], 3); + break; + case TGSI_OPCODE_NRM4: + emit_nrm(c, dst, args[0], 4); + break; + case TGSI_OPCODE_DST: + unalias2(c, dst, args[0], args[1], emit_dst_noalias); + break; + case TGSI_OPCODE_EXP: + unalias1(c, dst, args[0], emit_exp_noalias); + break; + case TGSI_OPCODE_EX2: + emit_math1(c, BRW_MATH_FUNCTION_EXP, dst, args[0], BRW_MATH_PRECISION_FULL); + break; + case TGSI_OPCODE_ARL: + emit_arl(c, dst, args[0]); + break; + case TGSI_OPCODE_FLR: + brw_RNDD(p, dst, args[0]); + break; + case TGSI_OPCODE_FRC: + brw_FRC(p, dst, args[0]); + break; + case TGSI_OPCODE_LOG: + unalias1(c, dst, args[0], emit_log_noalias); + break; + case TGSI_OPCODE_LG2: + emit_math1(c, BRW_MATH_FUNCTION_LOG, dst, args[0], BRW_MATH_PRECISION_FULL); + break; + case TGSI_OPCODE_LIT: + unalias1(c, dst, args[0], emit_lit_noalias); + break; + case TGSI_OPCODE_LRP: + unalias3(c, dst, args[0], args[1], args[2], emit_lrp_noalias); + break; + case TGSI_OPCODE_MAD: + brw_MOV(p, brw_acc_reg(), args[2]); + brw_MAC(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_MAX: + emit_max(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_MIN: + emit_min(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_MOV: + brw_MOV(p, dst, args[0]); + break; + case TGSI_OPCODE_MUL: + brw_MUL(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_POW: + emit_math2(c, BRW_MATH_FUNCTION_POW, dst, args[0], args[1], BRW_MATH_PRECISION_FULL); + break; + case TGSI_OPCODE_RCP: + emit_math1(c, BRW_MATH_FUNCTION_INV, dst, args[0], BRW_MATH_PRECISION_FULL); + break; + case TGSI_OPCODE_RSQ: + emit_math1(c, BRW_MATH_FUNCTION_RSQ, dst, + brw_swizzle(args[0], 0,0,0,0), BRW_MATH_PRECISION_FULL); + break; + case TGSI_OPCODE_SEQ: + emit_seq(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_SIN: + emit_math1(c, BRW_MATH_FUNCTION_SIN, dst, args[0], BRW_MATH_PRECISION_FULL); + break; + case TGSI_OPCODE_SNE: + emit_sne(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_SGE: + emit_sge(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_SGT: + emit_sgt(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_SLT: + emit_slt(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_SLE: + emit_sle(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_SUB: + brw_ADD(p, dst, args[0], negate(args[1])); + break; + case TGSI_OPCODE_TRUNC: + /* round toward zero */ + brw_RNDZ(p, dst, args[0]); + break; + case TGSI_OPCODE_XPD: + emit_xpd(p, dst, args[0], args[1]); + break; + case TGSI_OPCODE_IF: + assert(c->if_depth < MAX_IF_DEPTH); + c->if_inst[c->if_depth] = brw_IF(p, BRW_EXECUTE_8); + /* Note that brw_IF smashes the predicate_control field. */ + c->if_inst[c->if_depth]->header.predicate_control = get_predicate(inst); + c->if_depth++; + break; + case TGSI_OPCODE_ELSE: + c->if_inst[c->if_depth-1] = brw_ELSE(p, c->if_inst[c->if_depth-1]); + break; + case TGSI_OPCODE_ENDIF: + assert(c->if_depth > 0); + brw_ENDIF(p, c->if_inst[--c->if_depth]); + break; + case TGSI_OPCODE_BGNLOOP: + c->loop_inst[c->loop_depth++] = brw_DO(p, BRW_EXECUTE_8); + break; + case TGSI_OPCODE_BRK: + brw_set_predicate_control(p, get_predicate(inst)); + brw_BREAK(p); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + break; + case TGSI_OPCODE_CONT: + brw_set_predicate_control(p, get_predicate(inst)); + brw_CONT(p); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + break; + case TGSI_OPCODE_ENDLOOP: + { + struct brw_instruction *inst0, *inst1; + GLuint br = 1; + + c->loop_depth--; + + if (c->chipset.is_igdng) + br = 2; + + inst0 = inst1 = brw_WHILE(p, c->loop_inst[c->loop_depth]); + /* patch all the BREAK/CONT instructions from last BEGINLOOP */ + while (inst0 > c->loop_inst[c->loop_depth]) { + inst0--; + if (inst0->header.opcode == TGSI_OPCODE_BRK) { + inst0->bits3.if_else.jump_count = br * (inst1 - inst0 + 1); + inst0->bits3.if_else.pop_count = 0; + } + else if (inst0->header.opcode == TGSI_OPCODE_CONT) { + inst0->bits3.if_else.jump_count = br * (inst1 - inst0); + inst0->bits3.if_else.pop_count = 0; + } + } + } + break; + case TGSI_OPCODE_BRA: + brw_set_predicate_control(p, get_predicate(inst)); + brw_ADD(p, brw_ip_reg(), brw_ip_reg(), brw_imm_d(1*16)); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + break; + case TGSI_OPCODE_CAL: + brw_set_access_mode(p, BRW_ALIGN_1); + brw_ADD(p, deref_1d(c->stack_index, 0), brw_ip_reg(), brw_imm_d(3*16)); + brw_set_access_mode(p, BRW_ALIGN_16); + brw_ADD(p, get_addr_reg(c->stack_index), + get_addr_reg(c->stack_index), brw_imm_d(4)); + brw_save_call(p, label, p->nr_insn); + brw_ADD(p, brw_ip_reg(), brw_ip_reg(), brw_imm_d(1*16)); + break; + case TGSI_OPCODE_RET: + brw_ADD(p, get_addr_reg(c->stack_index), + get_addr_reg(c->stack_index), brw_imm_d(-4)); + brw_set_access_mode(p, BRW_ALIGN_1); + brw_MOV(p, brw_ip_reg(), deref_1d(c->stack_index, 0)); + brw_set_access_mode(p, BRW_ALIGN_16); + break; + case TGSI_OPCODE_END: + c->end_offset = p->nr_insn; + /* this instruction will get patched later to jump past subroutine + * code, etc. + */ + brw_ADD(p, brw_ip_reg(), brw_ip_reg(), brw_imm_d(1*16)); + break; + case TGSI_OPCODE_BGNSUB: + brw_save_label(p, p->nr_insn, p->nr_insn); + break; + case TGSI_OPCODE_ENDSUB: + /* no-op */ + break; + default: + debug_printf("Unsupported opcode %i (%s) in vertex shader", + opcode, + tgsi_get_opcode_name(opcode)); + } + + /* Set the predication update on the last instruction of the native + * instruction sequence. + * + * This would be problematic if it was set on a math instruction, + * but that shouldn't be the case with the current GLSL compiler. + */ +#if 0 + /* XXX: disabled + */ + if (inst->CondUpdate) { + struct brw_instruction *hw_insn = &p->store[p->nr_insn - 1]; + + assert(hw_insn->header.destreg__conditionalmod == 0); + hw_insn->header.destreg__conditionalmod = BRW_CONDITIONAL_NZ; + } +#endif + + release_tmps(c); +} + + +/* Emit the vertex program instructions here. + */ +void brw_vs_emit(struct brw_vs_compile *c) +{ + struct brw_compile *p = &c->func; + const struct tgsi_token *tokens = c->vp->tokens; + struct brw_instruction *end_inst, *last_inst; + struct tgsi_parse_context parse; + struct tgsi_full_instruction *inst; + + if (BRW_DEBUG & DEBUG_VS) + tgsi_dump(c->vp->tokens, 0); + + c->stack_index = brw_indirect(0, 0); + + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + brw_set_access_mode(p, BRW_ALIGN_16); + + + /* Static register allocation + */ + brw_vs_alloc_regs(c); + + if (c->vp->has_flow_control) { + brw_MOV(p, get_addr_reg(c->stack_index), brw_address(c->stack)); + } + + /* Instructions + */ + tgsi_parse_init( &parse, tokens ); + while( !tgsi_parse_end_of_tokens( &parse ) ) { + tgsi_parse_token( &parse ); + + switch( parse.FullToken.Token.Type ) { + case TGSI_TOKEN_TYPE_DECLARATION: + case TGSI_TOKEN_TYPE_IMMEDIATE: + break; + + case TGSI_TOKEN_TYPE_INSTRUCTION: + inst = &parse.FullToken.FullInstruction; + emit_insn( c, inst ); + break; + + default: + assert( 0 ); + } + } + tgsi_parse_free( &parse ); + + end_inst = &p->store[c->end_offset]; + last_inst = &p->store[p->nr_insn]; + + /* The END instruction will be patched to jump to this code */ + emit_vertex_write(c); + + post_vs_emit(c, end_inst, last_inst); + + if (BRW_DEBUG & DEBUG_VS) { + debug_printf("vs-native:\n"); + brw_disasm(stderr, p->store, p->nr_insn); + } +} diff --git a/src/gallium/drivers/i965/brw_vs_state.c b/src/gallium/drivers/i965/brw_vs_state.c new file mode 100644 index 0000000..dadbb62 --- /dev/null +++ b/src/gallium/drivers/i965/brw_vs_state.c @@ -0,0 +1,201 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_math.h" + + +#include "brw_debug.h" +#include "brw_context.h" +#include "brw_state.h" +#include "brw_defines.h" + +struct brw_vs_unit_key { + unsigned int total_grf; + unsigned int urb_entry_read_length; + unsigned int curb_entry_read_length; + + unsigned int curbe_offset; + + unsigned int nr_urb_entries, urb_size; + + unsigned int nr_surfaces; +}; + +static void +vs_unit_populate_key(struct brw_context *brw, struct brw_vs_unit_key *key) +{ + memset(key, 0, sizeof(*key)); + + /* CACHE_NEW_VS_PROG */ + key->total_grf = brw->vs.prog_data->total_grf; + key->urb_entry_read_length = brw->vs.prog_data->urb_read_length; + key->curb_entry_read_length = brw->vs.prog_data->curb_read_length; + + /* BRW_NEW_URB_FENCE */ + key->nr_urb_entries = brw->urb.nr_vs_entries; + key->urb_size = brw->urb.vsize; + + /* BRW_NEW_NR_VS_SURFACES */ + key->nr_surfaces = brw->vs.nr_surfaces; + + /* PIPE_NEW_CLIP */ + if (brw->curr.ucp.nr) { + /* Note that we read in the userclip planes as well, hence + * clip_start: + */ + key->curbe_offset = brw->curbe.clip_start; + } + else { + key->curbe_offset = brw->curbe.vs_start; + } +} + +static enum pipe_error +vs_unit_create_from_key(struct brw_context *brw, + struct brw_vs_unit_key *key, + struct brw_winsys_reloc *reloc, + struct brw_winsys_buffer **bo_out) +{ + enum pipe_error ret; + struct brw_vs_unit_state vs; + int chipset_max_threads; + + memset(&vs, 0, sizeof(vs)); + + vs.thread0.kernel_start_pointer = 0; /* reloc */ + vs.thread0.grf_reg_count = align(key->total_grf, 16) / 16 - 1; + vs.thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754; + /* Choosing multiple program flow means that we may get 2-vertex threads, + * which will have the channel mask for dwords 4-7 enabled in the thread, + * and those dwords will be written to the second URB handle when we + * brw_urb_WRITE() results. + */ + vs.thread1.single_program_flow = 0; + + if (BRW_IS_IGDNG(brw)) + vs.thread1.binding_table_entry_count = 0; /* hardware requirement */ + else + vs.thread1.binding_table_entry_count = key->nr_surfaces; + + vs.thread3.urb_entry_read_length = key->urb_entry_read_length; + vs.thread3.const_urb_entry_read_length = key->curb_entry_read_length; + vs.thread3.dispatch_grf_start_reg = 1; + vs.thread3.urb_entry_read_offset = 0; + vs.thread3.const_urb_entry_read_offset = key->curbe_offset * 2; + + if (BRW_IS_IGDNG(brw)) + vs.thread4.nr_urb_entries = key->nr_urb_entries >> 2; + else + vs.thread4.nr_urb_entries = key->nr_urb_entries; + + vs.thread4.urb_entry_allocation_size = key->urb_size - 1; + + if (BRW_IS_IGDNG(brw)) + chipset_max_threads = 72; + else if (BRW_IS_G4X(brw)) + chipset_max_threads = 32; + else + chipset_max_threads = 16; + + vs.thread4.max_threads = CLAMP(key->nr_urb_entries / 2, + 1, chipset_max_threads) - 1; + + if (BRW_DEBUG & DEBUG_SINGLE_THREAD) + vs.thread4.max_threads = 0; + + /* No samplers for ARB_vp programs: + */ + /* It has to be set to 0 for IGDNG + */ + vs.vs5.sampler_count = 0; + + if (BRW_DEBUG & DEBUG_STATS) + vs.thread4.stats_enable = 1; + + /* Vertex program always enabled: + */ + vs.vs6.vs_enable = 1; + + ret = brw_upload_cache(&brw->cache, BRW_VS_UNIT, + key, sizeof(*key), + reloc, 1, + &vs, sizeof(vs), + NULL, NULL, + bo_out); + if (ret) + return ret; + + return PIPE_OK; +} + +static int prepare_vs_unit(struct brw_context *brw) +{ + struct brw_vs_unit_key key; + enum pipe_error ret; + struct brw_winsys_reloc reloc[1]; + unsigned grf_reg_count; + + vs_unit_populate_key(brw, &key); + + grf_reg_count = (align(key.total_grf, 16) / 16 - 1); + + /* Emit VS program relocation */ + make_reloc(&reloc[0], + BRW_USAGE_STATE, + grf_reg_count << 1, + offsetof(struct brw_vs_unit_state, thread0), + brw->vs.prog_bo); + + + if (brw_search_cache(&brw->cache, BRW_VS_UNIT, + &key, sizeof(key), + reloc, 1, + NULL, + &brw->vs.state_bo)) + return PIPE_OK; + + ret = vs_unit_create_from_key(brw, &key, reloc, &brw->vs.state_bo); + if (ret) + return ret; + + return PIPE_OK; +} + +const struct brw_tracked_state brw_vs_unit = { + .dirty = { + .mesa = (PIPE_NEW_CLIP), + .brw = (BRW_NEW_CURBE_OFFSETS | + BRW_NEW_NR_VS_SURFACES | + BRW_NEW_URB_FENCE), + .cache = CACHE_NEW_VS_PROG + }, + .prepare = prepare_vs_unit, +}; diff --git a/src/gallium/drivers/i965/brw_vs_surface_state.c b/src/gallium/drivers/i965/brw_vs_surface_state.c new file mode 100644 index 0000000..424bb0d --- /dev/null +++ b/src/gallium/drivers/i965/brw_vs_surface_state.c @@ -0,0 +1,231 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "brw_context.h" +#include "brw_state.h" +#include "brw_winsys.h" + +/* XXX: disabled true constant buffer functionality + */ + + +/* Creates a new VS constant buffer reflecting the current VS program's + * constants, if needed by the VS program. + * + * Otherwise, constants go through the CURBEs using the brw_constant_buffer + * state atom. + */ +#if 0 +static struct brw_winsys_buffer * +brw_vs_update_constant_buffer(struct brw_context *brw) +{ + /* XXX: true constant buffers + */ + struct brw_vertex_program *vp = + (struct brw_vertex_program *) brw->vertex_program; + const struct gl_program_parameter_list *params = vp->program.Base.Parameters; + const int size = params->NumParameters * 4 * sizeof(GLfloat); + drm_intel_bo *const_buffer; + + /* BRW_NEW_VERTEX_PROGRAM */ + if (!vp->use_const_buffer) + return NULL; + + const_buffer = brw->sws->bo_alloc(brw->sws, + BRW_BUFFER_TYPE_SHADER_CONSTANTS, + size, 64); + + /* _NEW_PROGRAM_CONSTANTS */ + brw->sws->bo_subdata(const_buffer, 0, size, params->ParameterValues, + NULL, 0); + + return const_buffer; +} +#endif + +/** + * Update the surface state for a VS constant buffer. + * + * Sets brw->vs.surf_bo[surf] and brw->vp->const_buffer. + */ +#if 0 +static void +brw_update_vs_constant_surface( struct brw_context *brw, + GLuint surf) +{ + struct brw_surface_key key; + struct pipe_resource *cb = brw->curr.vs_constants; + enum pipe_error ret; + + assert(surf == 0); + + /* If we're in this state update atom, we need to update VS constants, so + * free the old buffer and create a new one for the new contents. + */ + ret = brw_vs_update_constant_buffer(brw, &vp->const_buffer); + if (ret) + return ret; + + /* If there's no constant buffer, then no surface BO is needed to point at + * it. + */ + if (vp->const_buffer == NULL) { + bo_reference(brw->vs.surf_bo[surf], NULL); + return PIPE_OK; + } + + memset(&key, 0, sizeof(key)); + + key.format = PIPE_FORMAT_R32G32B32A32_FLOAT; + key.bo = vp->const_buffer; + key.depthmode = GL_NONE; + key.pitch = params->NumParameters; + key.width = params->NumParameters; + key.height = 1; + key.depth = 1; + key.cpp = 16; + + /* + printf("%s:\n", __FUNCTION__); + printf(" width %d height %d depth %d cpp %d pitch %d\n", + key.width, key.height, key.depth, key.cpp, key.pitch); + */ + + if (brw_search_cache(&brw->surface_cache, + BRW_SS_SURFACE, + &key, sizeof(key), + &key.bo, key.bo ? 1 : 0, + NULL, + &brw->vs.surf_bo[surf])) + return PIPE_OK; + + ret = brw_create_constant_surface(brw, &key + &brw->vs.surf_bo[surf]); + if (ret) + return ret; + + return PIPE_OK; +} +#endif + + +/** + * Constructs the binding table for the VS surface state. + */ +static enum pipe_error +brw_vs_get_binding_table(struct brw_context *brw, + struct brw_winsys_buffer **bo_out) +{ +#if 0 + static GLuint data[BRW_VS_MAX_SURF]; /* always zero */ + struct brw_winsys_reloc reloc[BRW_VS_MAX_SURF]; + int i; + + /* Emit binding table relocations to surface state */ + for (i = 0; i < BRW_VS_MAX_SURF; i++) { + make_reloc(&reloc[i], + BRW_USAGE_STATE, + 0, + i * 4, + brw->vs.surf_bo[i]); + } + + ret = brw_cache_data( &brw->surface_cache, + BRW_SS_SURF_BIND, + NULL, 0, + reloc, nr_reloc, + data, sizeof data, + NULL, NULL, + bo_out); + if (ret) + return ret; + + FREE(data); + return PIPE_OK; +#else + return PIPE_OK; +#endif +} + +/** + * Vertex shader surfaces (constant buffer). + * + * This consumes the state updates for the constant buffer needing + * to be updated, and produces BRW_NEW_NR_VS_SURFACES for the VS unit and + * CACHE_NEW_SURF_BIND for the binding table upload. + */ +static enum pipe_error prepare_vs_surfaces(struct brw_context *brw ) +{ + enum pipe_error ret; + +#if 0 + int i; + int nr_surfaces = 0; + + brw_update_vs_constant_surface(ctx, SURF_INDEX_VERT_CONST_BUFFER); + + for (i = 0; i < BRW_VS_MAX_SURF; i++) { + if (brw->vs.surf_bo[i] != NULL) { + nr_surfaces = i + 1; + } + } + + if (brw->vs.nr_surfaces != nr_surfaces) { + brw->state.dirty.brw |= BRW_NEW_NR_VS_SURFACES; + brw->vs.nr_surfaces = nr_surfaces; + } +#endif + + /* Note that we don't end up updating the bind_bo if we don't have a + * surface to be pointing at. This should be relatively harmless, as it + * just slightly increases our working set size. + */ + if (brw->vs.nr_surfaces != 0) { + ret = brw_vs_get_binding_table(brw, &brw->vs.bind_bo); + if (ret) + return ret; + } + + return PIPE_OK; +} + +const struct brw_tracked_state brw_vs_surfaces = { + .dirty = { + .mesa = (PIPE_NEW_VERTEX_CONSTANTS | + PIPE_NEW_VERTEX_SHADER), + .brw = 0, + .cache = 0 + }, + .prepare = prepare_vs_surfaces, +}; + + + diff --git a/src/gallium/drivers/i965/brw_winsys.h b/src/gallium/drivers/i965/brw_winsys.h new file mode 100644 index 0000000..a06f8bb --- /dev/null +++ b/src/gallium/drivers/i965/brw_winsys.h @@ -0,0 +1,288 @@ +/************************************************************************** + * + * Copyright © 2009 Jakob Bornecrantz + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef BRW_WINSYS_H +#define BRW_WINSYS_H + +#include "pipe/p_compiler.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" + +struct brw_winsys; +struct pipe_fence_handle; + +/* Not sure why the winsys needs this: + */ +#define BRW_BATCH_SIZE (32*1024) + +struct brw_winsys_screen; + +/* Need a tiny bit of information inside the abstract buffer struct: + */ +struct brw_winsys_buffer { + struct pipe_reference reference; + struct brw_winsys_screen *sws; + unsigned size; +}; + + +/* Should be possible to validate usages above against buffer creation + * types, below: + */ +enum brw_buffer_type +{ + BRW_BUFFER_TYPE_TEXTURE, + BRW_BUFFER_TYPE_SCANOUT, /**< a texture used for scanning out from */ + BRW_BUFFER_TYPE_VERTEX, + BRW_BUFFER_TYPE_CURBE, + BRW_BUFFER_TYPE_QUERY, + BRW_BUFFER_TYPE_SHADER_CONSTANTS, + BRW_BUFFER_TYPE_SHADER_SCRATCH, + BRW_BUFFER_TYPE_BATCH, + BRW_BUFFER_TYPE_GENERAL_STATE, + BRW_BUFFER_TYPE_SURFACE_STATE, + BRW_BUFFER_TYPE_PIXEL, /* image uploads, pbo's, etc */ + BRW_BUFFER_TYPE_GENERIC, /* unknown */ + BRW_BUFFER_TYPE_MAX /* Count of possible values */ +}; + + +/* Describe the usage of a particular buffer in a relocation. The DRM + * winsys will translate these back to GEM read/write domain flags. + */ +enum brw_buffer_usage { + BRW_USAGE_STATE, /* INSTRUCTION, 0 */ + BRW_USAGE_QUERY_RESULT, /* INSTRUCTION, INSTRUCTION */ + BRW_USAGE_RENDER_TARGET, /* RENDER, 0 */ + BRW_USAGE_DEPTH_BUFFER, /* RENDER, RENDER */ + BRW_USAGE_BLIT_SOURCE, /* RENDER, 0 */ + BRW_USAGE_BLIT_DEST, /* RENDER, RENDER */ + BRW_USAGE_SAMPLER, /* SAMPLER, 0 */ + BRW_USAGE_VERTEX, /* VERTEX, 0 */ + BRW_USAGE_SCRATCH, /* 0, 0 */ + BRW_USAGE_MAX +}; + +enum brw_buffer_data_type { + BRW_DATA_GS_CC_VP, + BRW_DATA_GS_CC_UNIT, + BRW_DATA_GS_WM_PROG, + BRW_DATA_GS_SAMPLER_DEFAULT_COLOR, + BRW_DATA_GS_SAMPLER, + BRW_DATA_GS_WM_UNIT, + BRW_DATA_GS_SF_PROG, + BRW_DATA_GS_SF_VP, + BRW_DATA_GS_SF_UNIT, + BRW_DATA_GS_VS_UNIT, + BRW_DATA_GS_VS_PROG, + BRW_DATA_GS_GS_UNIT, + BRW_DATA_GS_GS_PROG, + BRW_DATA_GS_CLIP_VP, + BRW_DATA_GS_CLIP_UNIT, + BRW_DATA_GS_CLIP_PROG, + BRW_DATA_SS_SURFACE, + BRW_DATA_SS_SURF_BIND, + BRW_DATA_CONSTANT_BUFFER, + BRW_DATA_BATCH_BUFFER, + BRW_DATA_OTHER, + BRW_DATA_MAX +}; + + +/* Matches the i915_drm definitions: + */ +#define BRW_TILING_NONE 0 +#define BRW_TILING_X 1 +#define BRW_TILING_Y 2 + + +/* Relocations to be applied with subdata in a call to sws->bo_subdata, below. + * + * Effectively this encodes: + * + * (unsigned *)(subdata + offset) = bo->offset + delta + */ +struct brw_winsys_reloc { + enum brw_buffer_usage usage; /* debug only */ + unsigned delta; + unsigned offset; + struct brw_winsys_buffer *bo; +}; + +static INLINE void make_reloc(struct brw_winsys_reloc *reloc, + enum brw_buffer_usage usage, + unsigned delta, + unsigned offset, + struct brw_winsys_buffer *bo) +{ + reloc->usage = usage; + reloc->delta = delta; + reloc->offset = offset; + reloc->bo = bo; /* Note - note taking a reference yet */ +} + + + +struct brw_winsys_screen { + + unsigned pci_id; + + /** + * Buffer functions. + */ + + /*@{*/ + /** + * Create a buffer. + */ + enum pipe_error (*bo_alloc)(struct brw_winsys_screen *sws, + enum brw_buffer_type type, + unsigned size, + unsigned alignment, + struct brw_winsys_buffer **bo_out); + + enum pipe_error (*bo_from_handle)(struct brw_winsys_screen *sws, + struct winsys_handle *whandle, + unsigned *stride, + unsigned *tiling, + struct brw_winsys_buffer **bo_out); + + enum pipe_error (*bo_get_handle)(struct brw_winsys_buffer *buffer, + struct winsys_handle *whandle, + unsigned stride); + + /* Destroy a buffer when our refcount goes to zero: + */ + void (*bo_destroy)(struct brw_winsys_buffer *buffer); + + /* delta -- added to b2->offset, and written into buffer + * offset -- location above value is written to within buffer + */ + enum pipe_error (*bo_emit_reloc)(struct brw_winsys_buffer *buffer, + enum brw_buffer_usage usage, + unsigned delta, + unsigned offset, + struct brw_winsys_buffer *b2); + + enum pipe_error (*bo_exec)(struct brw_winsys_buffer *buffer, + unsigned bytes_used); + + enum pipe_error (*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 ); + + boolean (*bo_is_busy)(struct brw_winsys_buffer *buffer); + boolean (*bo_references)(struct brw_winsys_buffer *a, + struct brw_winsys_buffer *b); + + /* XXX: couldn't this be handled by returning true/false on + * bo_emit_reloc? + */ + enum pipe_error (*check_aperture_space)(struct brw_winsys_screen *iws, + struct brw_winsys_buffer **buffers, + unsigned count); + + /** + * Map a buffer. + */ + void *(*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); + + void (*bo_flush_range)(struct brw_winsys_buffer *buffer, + unsigned offset, + unsigned length); + + /** + * Unmap a buffer. + */ + void (*bo_unmap)(struct brw_winsys_buffer *buffer); + /*@}*/ + + + /* Wait for buffer to go idle. Similar to map+unmap, but doesn't + * mark buffer contents as dirty. + */ + void (*bo_wait_idle)(struct brw_winsys_buffer *buffer); + + /** + * Destroy the winsys. + */ + void (*destroy)(struct brw_winsys_screen *iws); +}; + +static INLINE void * +bo_map_read(struct brw_winsys_screen *sws, struct brw_winsys_buffer *buf) +{ + return sws->bo_map( buf, + BRW_DATA_OTHER, + 0, buf->size, + FALSE, FALSE, FALSE ); +} + +static INLINE void +bo_reference(struct brw_winsys_buffer **ptr, struct brw_winsys_buffer *buf) +{ + struct brw_winsys_buffer *old_buf = *ptr; + + if (pipe_reference(&(*ptr)->reference, &buf->reference)) + old_buf->sws->bo_destroy(old_buf); + + *ptr = buf; +} + + + +/************************************************************************* + * Cooperative dumping between winsys and driver. TODO: make this + * driver-only by wrapping calls to winsys->bo_subdata(). + */ + +#ifdef DEBUG +extern int BRW_DUMP; +#else +#define BRW_DUMP 0 +#endif + +#define DUMP_ASM 0x1 +#define DUMP_STATE 0x2 +#define DUMP_BATCH 0x4 + +void brw_dump_data( unsigned pci_id, + enum brw_buffer_data_type data_type, + unsigned offset, + const void *data, + size_t size ); + + +#endif diff --git a/src/gallium/drivers/i965/brw_winsys_debug.c b/src/gallium/drivers/i965/brw_winsys_debug.c new file mode 100644 index 0000000..f8f6a53 --- /dev/null +++ b/src/gallium/drivers/i965/brw_winsys_debug.c @@ -0,0 +1,87 @@ +#include "brw_winsys.h" +#include "brw_disasm.h" +#include "brw_structs_dump.h" +#include "brw_structs.h" +#include "intel_decode.h" + + +void brw_dump_data( unsigned pci_id, + enum brw_buffer_data_type data_type, + unsigned offset, + const void *data, + size_t size ) +{ + if (BRW_DUMP & DUMP_ASM) { + switch (data_type) { + case BRW_DATA_GS_WM_PROG: + case BRW_DATA_GS_SF_PROG: + case BRW_DATA_GS_VS_PROG: + case BRW_DATA_GS_GS_PROG: + case BRW_DATA_GS_CLIP_PROG: + brw_disasm( stderr, data, size / sizeof(struct brw_instruction) ); + break; + default: + break; + } + } + + if (BRW_DUMP & DUMP_STATE) { + switch (data_type) { + case BRW_DATA_GS_CC_VP: + brw_dump_cc_viewport( data ); + break; + case BRW_DATA_GS_CC_UNIT: + brw_dump_cc_unit_state( data ); + break; + case BRW_DATA_GS_SAMPLER_DEFAULT_COLOR: + brw_dump_sampler_default_color( data ); + break; + case BRW_DATA_GS_SAMPLER: + brw_dump_sampler_state( data ); + break; + case BRW_DATA_GS_WM_UNIT: + brw_dump_wm_unit_state( data ); + break; + case BRW_DATA_GS_SF_VP: + brw_dump_sf_viewport( data ); + break; + case BRW_DATA_GS_SF_UNIT: + brw_dump_sf_unit_state( data ); + break; + case BRW_DATA_GS_VS_UNIT: + brw_dump_vs_unit_state( data ); + break; + case BRW_DATA_GS_GS_UNIT: + brw_dump_gs_unit_state( data ); + break; + case BRW_DATA_GS_CLIP_VP: + brw_dump_clipper_viewport( data ); + break; + case BRW_DATA_GS_CLIP_UNIT: + brw_dump_clip_unit_state( data ); + break; + case BRW_DATA_SS_SURFACE: + brw_dump_surface_state( data ); + break; + case BRW_DATA_SS_SURF_BIND: + break; + case BRW_DATA_OTHER: + break; + case BRW_DATA_CONSTANT_BUFFER: + break; + default: + break; + } + } + + if (BRW_DUMP & DUMP_BATCH) { + switch (data_type) { + case BRW_DATA_BATCH_BUFFER: + intel_decode(data, size / 4, offset, pci_id); + break; + default: + break; + } + } +} + diff --git a/src/gallium/drivers/i965/brw_wm.c b/src/gallium/drivers/i965/brw_wm.c new file mode 100644 index 0000000..5d66e61 --- /dev/null +++ b/src/gallium/drivers/i965/brw_wm.c @@ -0,0 +1,319 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ +#include "tgsi/tgsi_info.h" + +#include "brw_context.h" +#include "brw_screen.h" +#include "brw_wm.h" +#include "brw_state.h" +#include "brw_debug.h" +#include "brw_resource.h" +#include "brw_pipe_rast.h" + + +/** Return number of src args for given instruction */ +GLuint brw_wm_nr_args( GLuint opcode ) +{ + switch (opcode) { + case WM_FRONTFACING: + case WM_PIXELXY: + return 0; + case WM_CINTERP: + case WM_WPOSXY: + case WM_DELTAXY: + return 1; + case WM_LINTERP: + case WM_PIXELW: + return 2; + case WM_FB_WRITE: + case WM_PINTERP: + return 3; + case TGSI_OPCODE_TEX: + case TGSI_OPCODE_TXP: + case TGSI_OPCODE_TXB: + case TGSI_OPCODE_TXD: + /* sampler arg is held as a field in the instruction, not in an + * actual register: + */ + return tgsi_get_opcode_info(opcode)->num_src - 1; + + default: + assert(opcode < MAX_OPCODE); + return tgsi_get_opcode_info(opcode)->num_src; + } +} + + +GLuint brw_wm_is_scalar_result( GLuint opcode ) +{ + switch (opcode) { + case TGSI_OPCODE_COS: + case TGSI_OPCODE_EX2: + case TGSI_OPCODE_LG2: + case TGSI_OPCODE_POW: + case TGSI_OPCODE_RCP: + case TGSI_OPCODE_RSQ: + case TGSI_OPCODE_SIN: + case TGSI_OPCODE_DP3: + case TGSI_OPCODE_DP4: + case TGSI_OPCODE_DPH: + case TGSI_OPCODE_DST: + return 1; + + default: + return 0; + } +} + + +/** + * Do GPU code generation for shaders without flow control. Shaders + * without flow control instructions can more readily be analysed for + * SSA-style optimizations. + */ +static void +brw_wm_linear_shader_emit(struct brw_context *brw, struct brw_wm_compile *c) +{ + /* Augment fragment program. Add instructions for pre- and + * post-fragment-program tasks such as interpolation and fogging. + */ + brw_wm_pass_fp(c); + + /* Translate to intermediate representation. Build register usage + * chains. + */ + brw_wm_pass0(c); + + /* Dead code removal. + */ + brw_wm_pass1(c); + + /* Register allocation. + * Divide by two because we operate on 16 pixels at a time and require + * two GRF entries for each logical shader register. + */ + c->grf_limit = BRW_WM_MAX_GRF / 2; + + brw_wm_pass2(c); + + /* how many general-purpose registers are used */ + c->prog_data.total_grf = c->max_wm_grf; + + /* Scratch space is used for register spilling */ + if (c->last_scratch) { + c->prog_data.total_scratch = c->last_scratch + 0x40; + } + else { + c->prog_data.total_scratch = 0; + } + + /* Emit GEN4 code. + */ + brw_wm_emit(c); +} + + +/** + * All Mesa program -> GPU code generation goes through this function. + * Depending on the instructions used (i.e. flow control instructions) + * we'll use one of two code generators. + */ +static enum pipe_error do_wm_prog( struct brw_context *brw, + struct brw_fragment_shader *fp, + struct brw_wm_prog_key *key, + struct brw_winsys_buffer **bo_out) +{ + enum pipe_error ret; + struct brw_wm_compile *c; + const GLuint *program; + GLuint program_size; + + if (brw->wm.compile_data == NULL) { + brw->wm.compile_data = MALLOC(sizeof(*brw->wm.compile_data)); + if (!brw->wm.compile_data) + return PIPE_ERROR_OUT_OF_MEMORY; + } + + c = brw->wm.compile_data; + memset(c, 0, sizeof *c); + + c->key = *key; + c->fp = fp; + c->env_param = NULL; /*brw->intel.ctx.FragmentProgram.Parameters;*/ + + brw_init_compile(brw, &c->func); + + /* + * Shader which use GLSL features such as flow control are handled + * differently from "simple" shaders. + */ + if (fp->has_flow_control) { + c->dispatch_width = 8; + /* XXX: GLSL support + */ + exit(1); + /* brw_wm_branching_shader_emit(brw, c); */ + } + else { + c->dispatch_width = 16; + brw_wm_linear_shader_emit(brw, c); + } + + if (BRW_DEBUG & DEBUG_WM) + debug_printf("\n"); + + /* get the program + */ + ret = brw_get_program(&c->func, &program, &program_size); + if (ret) + return ret; + + ret = brw_upload_cache( &brw->cache, BRW_WM_PROG, + &c->key, sizeof(c->key), + NULL, 0, + program, program_size, + &c->prog_data, + &brw->wm.prog_data, + bo_out ); + if (ret) + return ret; + + return PIPE_OK; +} + + + +static void brw_wm_populate_key( struct brw_context *brw, + struct brw_wm_prog_key *key ) +{ + unsigned lookup, line_aa; + unsigned i; + + memset(key, 0, sizeof(*key)); + + /* PIPE_NEW_FRAGMENT_SHADER + * PIPE_NEW_DEPTH_STENCIL_ALPHA + */ + lookup = (brw->curr.zstencil->iz_lookup | + brw->curr.fragment_shader->iz_lookup); + + + /* PIPE_NEW_RAST + * BRW_NEW_REDUCED_PRIMITIVE + */ + switch (brw->reduced_primitive) { + case PIPE_PRIM_POINTS: + line_aa = AA_NEVER; + break; + case PIPE_PRIM_LINES: + line_aa = (brw->curr.rast->templ.line_smooth ? + AA_ALWAYS : AA_NEVER); + break; + default: + line_aa = brw->curr.rast->unfilled_aa_line; + break; + } + + brw_wm_lookup_iz(line_aa, + lookup, + brw->curr.fragment_shader->uses_depth, + key); + + /* PIPE_NEW_RAST */ + key->flat_shade = brw->curr.rast->templ.flatshade; + + + /* PIPE_NEW_BOUND_TEXTURES */ + for (i = 0; i < brw->curr.num_fragment_sampler_views; i++) { + const struct brw_texture *tex = brw_texture(brw->curr.fragment_sampler_views[i]->texture); + + if (tex->b.b.format == PIPE_FORMAT_UYVY) + key->yuvtex_mask |= 1 << i; + + if (tex->b.b.format == PIPE_FORMAT_YUYV) + key->yuvtex_swap_mask |= 1 << i; + + /* XXX: shadow texture + */ + /* key->shadowtex_mask |= 1<vp_nr_outputs = brw->vs.prog_data->nr_outputs; + + key->nr_cbufs = brw->curr.fb.nr_cbufs; + + key->nr_inputs = brw->curr.fragment_shader->info.num_inputs; + + /* The unique fragment program ID */ + key->program_string_id = brw->curr.fragment_shader->id; +} + + +static enum pipe_error brw_prepare_wm_prog(struct brw_context *brw) +{ + struct brw_wm_prog_key key; + struct brw_fragment_shader *fs = brw->curr.fragment_shader; + enum pipe_error ret; + + brw_wm_populate_key(brw, &key); + + /* Make an early check for the key. + */ + if (brw_search_cache(&brw->cache, BRW_WM_PROG, + &key, sizeof(key), + NULL, 0, + &brw->wm.prog_data, + &brw->wm.prog_bo)) + return PIPE_OK; + + ret = do_wm_prog(brw, fs, &key, &brw->wm.prog_bo); + if (ret) + return ret; + + return PIPE_OK; +} + + +const struct brw_tracked_state brw_wm_prog = { + .dirty = { + .mesa = (PIPE_NEW_FRAGMENT_SHADER | + PIPE_NEW_DEPTH_STENCIL_ALPHA | + PIPE_NEW_RAST | + PIPE_NEW_NR_CBUFS | + PIPE_NEW_BOUND_TEXTURES), + .brw = (BRW_NEW_WM_INPUT_DIMENSIONS | + BRW_NEW_REDUCED_PRIMITIVE), + .cache = CACHE_NEW_VS_PROG, + }, + .prepare = brw_prepare_wm_prog +}; + diff --git a/src/gallium/drivers/i965/brw_wm.h b/src/gallium/drivers/i965/brw_wm.h new file mode 100644 index 0000000..f1ca9f6 --- /dev/null +++ b/src/gallium/drivers/i965/brw_wm.h @@ -0,0 +1,344 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#ifndef BRW_WM_H +#define BRW_WM_H + +#include "brw_context.h" +#include "brw_eu.h" + +#define SATURATE (1<<5) + +/* A big lookup table is used to figure out which and how many + * additional regs will inserted before the main payload in the WM + * program execution. These mainly relate to depth and stencil + * processing and the early-depth-test optimization. + */ +#define IZ_PS_KILL_ALPHATEST_BIT 0x1 +#define IZ_PS_COMPUTES_DEPTH_BIT 0x2 +#define IZ_DEPTH_WRITE_ENABLE_BIT 0x4 +#define IZ_DEPTH_TEST_ENABLE_BIT 0x8 +#define IZ_STENCIL_WRITE_ENABLE_BIT 0x10 +#define IZ_STENCIL_TEST_ENABLE_BIT 0x20 +#define IZ_BIT_MAX 0x40 + +#define AA_NEVER 0 +#define AA_SOMETIMES 1 +#define AA_ALWAYS 2 + +struct brw_wm_prog_key { + GLuint source_depth_reg:3; + GLuint aa_dest_stencil_reg:3; + GLuint dest_depth_reg:3; + GLuint nr_depth_regs:3; + GLuint computes_depth:1; + GLuint source_depth_to_render_target:1; + GLuint flat_shade:1; + GLuint runtime_check_aads_emit:1; + + GLuint shadowtex_mask:16; + GLuint yuvtex_mask:16; + GLuint yuvtex_swap_mask:16; /* UV swaped */ + + GLuint vp_nr_outputs:6; + GLuint nr_inputs:6; + GLuint nr_cbufs:3; + GLuint has_flow_control:1; + + GLuint program_string_id; +}; + + +/* A bit of a glossary: + * + * brw_wm_value: A computed value or program input. Values are + * constant, they are created once and are never modified. When a + * fragment program register is written or overwritten, new values are + * created fresh, preserving the rule that values are constant. + * + * brw_wm_ref: A reference to a value. Wherever a value used is by an + * instruction or as a program output, that is tracked with an + * instance of this struct. All references to a value occur after it + * is created. After the last reference, a value is dead and can be + * discarded. + * + * brw_wm_grf: Represents a physical hardware register. May be either + * empty or hold a value. Register allocation is the process of + * assigning values to grf registers. This occurs in pass2 and the + * brw_wm_grf struct is not used before that. + * + * Fragment program registers: These are time-varying constructs that + * are hard to reason about and which we translate away in pass0. A + * single fragment program register element (eg. temp[0].x) will be + * translated to one or more brw_wm_value structs, one for each time + * that temp[0].x is written to during the program. + */ + + + +/* Used in pass2 to track register allocation. + */ +struct brw_wm_grf { + struct brw_wm_value *value; + GLuint nextuse; +}; + +struct brw_wm_value { + struct brw_reg hw_reg; /* emitted to this reg, may not always be there */ + struct brw_wm_ref *lastuse; + struct brw_wm_grf *resident; + GLuint contributes_to_output:1; + GLuint spill_slot:16; /* if non-zero, spill immediately after calculation */ +}; + +struct brw_wm_ref { + struct brw_reg hw_reg; /* nr filled in in pass2, everything else, pass0 */ + struct brw_wm_value *value; + struct brw_wm_ref *prevuse; + GLuint unspill_reg:7; /* unspill to reg */ + GLuint emitted:1; + GLuint insn:24; +}; + +struct brw_wm_instruction { + struct brw_wm_value *dst[4]; + struct brw_wm_ref *src[3][4]; + GLuint opcode:8; + GLuint saturate:1; + GLuint writemask:4; + GLuint sampler:4; + GLuint tex_unit:4; /* texture/sampler unit for texture instructions */ + GLuint target:4; /* TGSI_TEXTURE_x for texture instructions, + * target binding table index for FB_WRITE + */ + GLuint eot:1; /* End of thread indicator for FB_WRITE*/ +}; + + +#define BRW_WM_MAX_INSN 2048 +#define BRW_WM_MAX_GRF 128 /* hardware limit */ +#define BRW_WM_MAX_VREG (BRW_WM_MAX_INSN * 4) +#define BRW_WM_MAX_REF (BRW_WM_MAX_INSN * 12) +#define BRW_WM_MAX_PARAM 256 +#define BRW_WM_MAX_CONST 256 +#define BRW_WM_MAX_KILLS MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS +#define BRW_WM_MAX_SUBROUTINE 16 + + +/* New opcodes to track internal operations required for WM unit. + * These are added early so that the registers used can be tracked, + * freed and reused like those of other instructions. + */ +#define MAX_OPCODE TGSI_OPCODE_LAST +#define WM_PIXELXY (MAX_OPCODE) +#define WM_DELTAXY (MAX_OPCODE + 1) +#define WM_PIXELW (MAX_OPCODE + 2) +#define WM_LINTERP (MAX_OPCODE + 3) +#define WM_PINTERP (MAX_OPCODE + 4) +#define WM_CINTERP (MAX_OPCODE + 5) +#define WM_WPOSXY (MAX_OPCODE + 6) +#define WM_FB_WRITE (MAX_OPCODE + 7) +#define WM_FRONTFACING (MAX_OPCODE + 8) +#define MAX_WM_OPCODE (MAX_OPCODE + 9) + +#define BRW_FILE_PAYLOAD (TGSI_FILE_COUNT) +#define PAYLOAD_DEPTH (PIPE_MAX_SHADER_INPUTS) /* ?? */ + +#define X 0 +#define Y 1 +#define Z 2 +#define W 3 + + +struct brw_fp_src { + unsigned file:4; + unsigned index:16; + unsigned swizzle:8; + unsigned indirect:1; + unsigned negate:1; + unsigned abs:1; +}; + +struct brw_fp_dst { + unsigned file:4; + unsigned index:16; + unsigned writemask:4; + unsigned indirect:1; + unsigned saturate:1; +}; + +struct brw_fp_instruction { + struct brw_fp_dst dst; + struct brw_fp_src src[3]; + unsigned opcode:8; + unsigned target:8; /* XXX: special usage for FB_WRITE */ + unsigned tex_unit:4; + unsigned sampler:4; + unsigned pad:8; +}; + + +struct brw_wm_compile { + struct brw_compile func; + struct brw_wm_prog_key key; + struct brw_wm_prog_data prog_data; + + struct brw_fragment_shader *fp; + + GLfloat (*env_param)[4]; + + enum { + START, + PASS2_DONE + } state; + + /* Initial pass - translate fp instructions to fp instructions, + * simplifying and adding instructions for interpolation and + * framebuffer writes. + */ + struct { + GLfloat v[4]; + unsigned nr; + } immediate[BRW_WM_MAX_CONST+3]; + GLuint nr_immediates; + + struct brw_fp_instruction fp_instructions[BRW_WM_MAX_INSN]; + GLuint nr_fp_insns; + GLuint fp_temp; + GLuint fp_interp_emitted; + GLuint fp_fragcolor_emitted; + GLuint fp_first_internal_temp; + + struct brw_fp_src fp_pixel_xy; + struct brw_fp_src fp_delta_xy; + struct brw_fp_src fp_pixel_w; + + + /* Subsequent passes using SSA representation: + */ + struct brw_wm_value vreg[BRW_WM_MAX_VREG]; + GLuint nr_vreg; + + struct brw_wm_value creg[BRW_WM_MAX_PARAM]; + GLuint nr_creg; + + struct { + struct brw_wm_value depth[4]; /* includes r0/r1 */ + struct brw_wm_value input_interp[PIPE_MAX_SHADER_INPUTS]; + } payload; + + + const struct brw_wm_ref *pass0_fp_reg[BRW_FILE_PAYLOAD+1][256][4]; + + struct brw_wm_ref undef_ref; + struct brw_wm_value undef_value; + + struct brw_wm_ref refs[BRW_WM_MAX_REF]; + GLuint nr_refs; + + struct brw_wm_instruction instruction[BRW_WM_MAX_INSN]; + GLuint nr_insns; + + struct brw_wm_grf pass2_grf[BRW_WM_MAX_GRF/2]; + + GLuint grf_limit; + GLuint max_wm_grf; + GLuint last_scratch; + + GLuint cur_inst; /**< index of current instruction */ + + GLboolean out_of_regs; /**< ran out of GRF registers? */ + + /** Mapping from Mesa registers to hardware registers */ + struct { + GLboolean inited; + struct brw_reg reg; + } wm_regs[BRW_FILE_PAYLOAD+1][256][4]; + + GLboolean used_grf[BRW_WM_MAX_GRF]; + GLuint first_free_grf; + struct brw_reg stack; + struct brw_reg emit_mask_reg; + GLuint tmp_regs[BRW_WM_MAX_GRF]; + GLuint tmp_index; + GLuint tmp_max; + GLuint subroutines[BRW_WM_MAX_SUBROUTINE]; + GLuint dispatch_width; + + /** we may need up to 3 constants per instruction (if use_const_buffer) */ + struct { + GLint index; + struct brw_reg reg; + } current_const[3]; + + GLuint error; +}; + + +GLuint brw_wm_nr_args( GLuint opcode ); +GLuint brw_wm_is_scalar_result( GLuint opcode ); + +int brw_wm_pass_fp( struct brw_wm_compile *c ); +void brw_wm_pass0( struct brw_wm_compile *c ); +void brw_wm_pass1( struct brw_wm_compile *c ); +void brw_wm_pass2( struct brw_wm_compile *c ); +void brw_wm_emit( struct brw_wm_compile *c ); + +void brw_wm_print_value( struct brw_wm_compile *c, + struct brw_wm_value *value ); + +void brw_wm_print_ref( struct brw_wm_compile *c, + struct brw_wm_ref *ref ); + +void brw_wm_print_insn( struct brw_wm_compile *c, + struct brw_wm_instruction *inst ); + +void brw_wm_print_program( struct brw_wm_compile *c, + const char *stage ); + +void brw_wm_print_fp_program( struct brw_wm_compile *c, + const char *stage ); + +void brw_wm_lookup_iz( GLuint line_aa, + GLuint lookup, + GLboolean ps_uses_depth, + struct brw_wm_prog_key *key ); + +void brw_wm_branching_shader_emit(struct brw_context *brw, struct brw_wm_compile *c); + +void emit_ddxy(struct brw_compile *p, + const struct brw_reg *dst, + GLuint mask, + GLboolean is_ddx, + const struct brw_reg *arg0); + +#endif diff --git a/src/gallium/drivers/i965/brw_wm_constant_buffer.c b/src/gallium/drivers/i965/brw_wm_constant_buffer.c new file mode 100644 index 0000000..df5cd03 --- /dev/null +++ b/src/gallium/drivers/i965/brw_wm_constant_buffer.c @@ -0,0 +1,165 @@ +/* XXX: Constant buffers disabled + */ + + +/** + * Create the constant buffer surface. Vertex/fragment shader constants will be + * read from this buffer with Data Port Read instructions/messages. + */ +enum pipe_error +brw_create_constant_surface( struct brw_context *brw, + struct brw_surface_key *key, + struct brw_winsys_buffer **bo_out ) +{ + const GLint w = key->width - 1; + struct brw_winsys_buffer *bo; + struct brw_winsys_reloc reloc[1]; + enum pipe_error ret; + + /* Emit relocation to surface contents */ + make_reloc(&reloc[0], + BRW_USAGE_SAMPLER, + 0, + offsetof(struct brw_surface_state, ss1), + key->bo); + + + memset(&surf, 0, sizeof(surf)); + + surf.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW; + surf.ss0.surface_type = BRW_SURFACE_BUFFER; + surf.ss0.surface_format = BRW_SURFACEFORMAT_R32G32B32A32_FLOAT; + + surf.ss1.base_addr = 0; /* reloc */ + + surf.ss2.width = w & 0x7f; /* bits 6:0 of size or width */ + surf.ss2.height = (w >> 7) & 0x1fff; /* bits 19:7 of size or width */ + surf.ss3.depth = (w >> 20) & 0x7f; /* bits 26:20 of size or width */ + surf.ss3.pitch = (key->pitch * key->cpp) - 1; /* ignored?? */ + brw_set_surface_tiling(&surf, key->tiling); /* tiling now allowed */ + + ret = brw_upload_cache(&brw->surface_cache, BRW_SS_SURFACE, + key, sizeof(*key), + reloc, Elements(reloc), + &surf, sizeof(surf), + NULL, NULL, + &bo_out); + if (ret) + return ret; + + return PIPE_OK; +} + + + +/** + * Update the surface state for a WM constant buffer. + * The constant buffer will be (re)allocated here if needed. + */ +static enum pipe_error +brw_update_wm_constant_surface( struct brw_context *brw, + GLuint surf) +{ + struct brw_surface_key key; + struct brw_fragment_shader *fp = brw->curr.fragment_shader; + struct pipe_resource *cbuf = brw->curr.fragment_constants; + int pitch = cbuf->size / (4 * sizeof(float)); + enum pipe_error ret; + + /* If we're in this state update atom, we need to update WM constants, so + * free the old buffer and create a new one for the new contents. + */ + ret = brw_wm_update_constant_buffer(brw, &fp->const_buffer); + if (ret) + return ret; + + /* If there's no constant buffer, then no surface BO is needed to point at + * it. + */ + if (cbuf == NULL) { + bo_reference(&brw->wm.surf_bo[surf], NULL); + return PIPE_OK; + } + + memset(&key, 0, sizeof(key)); + + key.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW; + key.ss0.surface_type = BRW_SURFACE_BUFFER; + key.ss0.surface_format = BRW_SURFACEFORMAT_R32G32B32A32_FLOAT; + + key.bo = brw_buffer(cbuf)->bo; + + key.ss2.width = (pitch-1) & 0x7f; /* bits 6:0 of size or width */ + key.ss2.height = ((pitch-1) >> 7) & 0x1fff; /* bits 19:7 of size or width */ + key.ss3.depth = ((pitch-1) >> 20) & 0x7f; /* bits 26:20 of size or width */ + key.ss3.pitch = (pitch * 4 * sizeof(float)) - 1; /* ignored?? */ + brw_set_surface_tiling(&surf, key->tiling); /* tiling now allowed */ + + + /* + printf("%s:\n", __FUNCTION__); + printf(" width %d height %d depth %d cpp %d pitch %d\n", + key.width, key.height, key.depth, key.cpp, key.pitch); + */ + + if (brw_search_cache(&brw->surface_cache, + BRW_SS_SURFACE, + &key, sizeof(key), + &key.bo, 1, + NULL, + &brw->wm.surf_bo[surf])) + return PIPE_OK; + + ret = brw_create_constant_surface(brw, &key, &brw->wm.surf_bo[surf]); + if (ret) + return ret; + + brw->state.dirty.brw |= BRW_NEW_WM_SURFACES; + return PIPE_OK; +} + +/** + * Updates surface / buffer for fragment shader constant buffer, if + * one is required. + * + * This consumes the state updates for the constant buffer, and produces + * BRW_NEW_WM_SURFACES to get picked up by brw_prepare_wm_surfaces for + * inclusion in the binding table. + */ +static enum pipe_error prepare_wm_constant_surface(struct brw_context *brw ) +{ + struct brw_fragment_program *fp = + (struct brw_fragment_program *) brw->fragment_program; + GLuint surf = SURF_INDEX_FRAG_CONST_BUFFER; + + ret = brw_wm_update_constant_buffer(brw, + &fp->const_buffer); + if (ret) + return ret; + + /* If there's no constant buffer, then no surface BO is needed to point at + * it. + */ + if (fp->const_buffer == 0) { + if (brw->wm.surf_bo[surf] != NULL) { + bo_reference(&brw->wm.surf_bo[surf], NULL); + brw->state.dirty.brw |= BRW_NEW_WM_SURFACES; + } + return PIPE_OK; + } + + ret = brw_update_wm_constant_surface(ctx, surf); + if (ret) + return ret; + + return PIPE_OK +} + +const struct brw_tracked_state brw_wm_constant_surface = { + .dirty = { + .mesa = (_NEW_PROGRAM_CONSTANTS), + .brw = (BRW_NEW_FRAGMENT_PROGRAM), + .cache = 0 + }, + .prepare = prepare_wm_constant_surface, +}; diff --git a/src/gallium/drivers/i965/brw_wm_debug.c b/src/gallium/drivers/i965/brw_wm_debug.c new file mode 100644 index 0000000..1b2aa93 --- /dev/null +++ b/src/gallium/drivers/i965/brw_wm_debug.c @@ -0,0 +1,257 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "tgsi/tgsi_info.h" + +#include "brw_context.h" +#include "brw_wm.h" + +static void print_writemask( unsigned writemask ) +{ + if (writemask != BRW_WRITEMASK_XYZW) + debug_printf(".%s%s%s%s", + (writemask & BRW_WRITEMASK_X) ? "x" : "", + (writemask & BRW_WRITEMASK_Y) ? "y" : "", + (writemask & BRW_WRITEMASK_Z) ? "z" : "", + (writemask & BRW_WRITEMASK_W) ? "w" : ""); +} + +static void print_swizzle( unsigned swizzle ) +{ + char *swz = "xyzw"; + if (swizzle != BRW_SWIZZLE_XYZW) + debug_printf(".%c%c%c%c", + swz[BRW_GET_SWZ(swizzle, X)], + swz[BRW_GET_SWZ(swizzle, Y)], + swz[BRW_GET_SWZ(swizzle, Z)], + swz[BRW_GET_SWZ(swizzle, W)]); +} + +static void print_opcode( unsigned opcode ) +{ + switch (opcode) { + case WM_PIXELXY: + debug_printf("PIXELXY"); + break; + case WM_DELTAXY: + debug_printf("DELTAXY"); + break; + case WM_PIXELW: + debug_printf("PIXELW"); + break; + case WM_WPOSXY: + debug_printf("WPOSXY"); + break; + case WM_PINTERP: + debug_printf("PINTERP"); + break; + case WM_LINTERP: + debug_printf("LINTERP"); + break; + case WM_CINTERP: + debug_printf("CINTERP"); + break; + case WM_FB_WRITE: + debug_printf("FB_WRITE"); + break; + case WM_FRONTFACING: + debug_printf("FRONTFACING"); + break; + default: + debug_printf("%s", tgsi_get_opcode_info(opcode)->mnemonic); + break; + } +} + +void brw_wm_print_value( struct brw_wm_compile *c, + struct brw_wm_value *value ) +{ + assert(value); + if (c->state >= PASS2_DONE) + brw_print_reg(value->hw_reg); + else if( value == &c->undef_value ) + debug_printf("undef"); + else if( value - c->vreg >= 0 && + value - c->vreg < BRW_WM_MAX_VREG) + debug_printf("r%ld", (long) (value - c->vreg)); + else if (value - c->creg >= 0 && + value - c->creg < BRW_WM_MAX_PARAM) + debug_printf("c%ld", (long) (value - c->creg)); + else if (value - c->payload.input_interp >= 0 && + value - c->payload.input_interp < PIPE_MAX_SHADER_INPUTS) + debug_printf("i%ld", (long) (value - c->payload.input_interp)); + else if (value - c->payload.depth >= 0 && + value - c->payload.depth < PIPE_MAX_SHADER_INPUTS) + debug_printf("d%ld", (long) (value - c->payload.depth)); + else + debug_printf("?"); +} + +void brw_wm_print_ref( struct brw_wm_compile *c, + struct brw_wm_ref *ref ) +{ + struct brw_reg hw_reg = ref->hw_reg; + + if (ref->unspill_reg) + debug_printf("UNSPILL(%x)/", ref->value->spill_slot); + + if (c->state >= PASS2_DONE) + brw_print_reg(ref->hw_reg); + else { + debug_printf("%s", hw_reg.negate ? "-" : ""); + debug_printf("%s", hw_reg.abs ? "abs/" : ""); + brw_wm_print_value(c, ref->value); + if ((hw_reg.nr&1) || hw_reg.subnr) { + debug_printf("->%d.%d", (hw_reg.nr&1), hw_reg.subnr); + } + } +} + +void brw_wm_print_insn( struct brw_wm_compile *c, + struct brw_wm_instruction *inst ) +{ + GLuint i, arg; + GLuint nr_args = brw_wm_nr_args(inst->opcode); + + debug_printf("["); + for (i = 0; i < 4; i++) { + if (inst->dst[i]) { + brw_wm_print_value(c, inst->dst[i]); + if (inst->dst[i]->spill_slot) + debug_printf("/SPILL(%x)",inst->dst[i]->spill_slot); + } + else + debug_printf("#"); + if (i < 3) + debug_printf(","); + } + debug_printf("]"); + print_writemask(inst->writemask); + + debug_printf(" = "); + print_opcode(inst->opcode); + + if (inst->saturate) + debug_printf("_SAT"); + + for (arg = 0; arg < nr_args; arg++) { + + debug_printf(" ["); + + for (i = 0; i < 4; i++) { + if (inst->src[arg][i]) { + brw_wm_print_ref(c, inst->src[arg][i]); + } + else + debug_printf("%%"); + + if (i < 3) + debug_printf(","); + else + debug_printf("]"); + } + } + debug_printf("\n"); +} + +void brw_wm_print_program( struct brw_wm_compile *c, + const char *stage ) +{ + GLuint insn; + + debug_printf("%s:\n", stage); + for (insn = 0; insn < c->nr_insns; insn++) + brw_wm_print_insn(c, &c->instruction[insn]); + debug_printf("\n"); +} + +static const char *file_strings[TGSI_FILE_COUNT+1] = { + "NULL", + "CONST", + "IN", + "OUT", + "TEMP", + "SAMPLER", + "ADDR", + "IMM", + "PRED", + "SV", + "PAYLOAD" +}; + +static void brw_wm_print_fp_insn( struct brw_wm_compile *c, + struct brw_fp_instruction *inst ) +{ + GLuint i; + GLuint nr_args = brw_wm_nr_args(inst->opcode); + + print_opcode(inst->opcode); + if (inst->dst.saturate) + debug_printf("_SAT"); + debug_printf(" "); + + if (inst->dst.indirect) + debug_printf("["); + + debug_printf("%s[%d]", + file_strings[inst->dst.file], + inst->dst.index ); + print_writemask(inst->dst.writemask); + + if (inst->dst.indirect) + debug_printf("]"); + + debug_printf(nr_args ? ", " : "\n"); + + for (i = 0; i < nr_args; i++) { + debug_printf("%s%s%s[%d]%s", + inst->src[i].negate ? "-" : "", + inst->src[i].abs ? "ABS(" : "", + file_strings[inst->src[i].file], + inst->src[i].index, + inst->src[i].abs ? ")" : ""); + print_swizzle(inst->src[i].swizzle); + debug_printf("%s", i == nr_args - 1 ? "\n" : ", "); + } +} + + +void brw_wm_print_fp_program( struct brw_wm_compile *c, + const char *stage ) +{ + GLuint insn; + + debug_printf("%s:\n", stage); + for (insn = 0; insn < c->nr_fp_insns; insn++) + brw_wm_print_fp_insn(c, &c->fp_instructions[insn]); + debug_printf("\n"); +} + diff --git a/src/gallium/drivers/i965/brw_wm_emit.c b/src/gallium/drivers/i965/brw_wm_emit.c new file mode 100644 index 0000000..8f983a6 --- /dev/null +++ b/src/gallium/drivers/i965/brw_wm_emit.c @@ -0,0 +1,1521 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_math.h" +#include "tgsi/tgsi_info.h" + +#include "brw_context.h" +#include "brw_wm.h" +#include "brw_debug.h" +#include "brw_disasm.h" + +/* Not quite sure how correct this is - need to understand horiz + * vs. vertical strides a little better. + */ +static INLINE struct brw_reg sechalf( struct brw_reg reg ) +{ + if (reg.vstride) + reg.nr++; + return reg; +} + +/* Payload R0: + * + * R0.0 -- pixel mask, one bit for each of 4 pixels in 4 quads, + * corresponding to each of the 16 execution channels. + * R0.1..8 -- ? + * R1.0 -- triangle vertex 0.X + * R1.1 -- triangle vertex 0.Y + * R1.2 -- quad 0 x,y coords (2 packed uwords) + * R1.3 -- quad 1 x,y coords (2 packed uwords) + * R1.4 -- quad 2 x,y coords (2 packed uwords) + * R1.5 -- quad 3 x,y coords (2 packed uwords) + * R1.6 -- ? + * R1.7 -- ? + * R1.8 -- ? + */ + + +static void emit_pixel_xy(struct brw_compile *p, + const struct brw_reg *dst, + GLuint mask) +{ + struct brw_reg r1 = brw_vec1_grf(1, 0); + struct brw_reg r1_uw = retype(r1, BRW_REGISTER_TYPE_UW); + + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + + /* Calculate pixel centers by adding 1 or 0 to each of the + * micro-tile coordinates passed in r1. + */ + if (mask & BRW_WRITEMASK_X) { + brw_ADD(p, + vec16(retype(dst[0], BRW_REGISTER_TYPE_UW)), + stride(suboffset(r1_uw, 4), 2, 4, 0), + brw_imm_v(0x10101010)); + } + + if (mask & BRW_WRITEMASK_Y) { + brw_ADD(p, + vec16(retype(dst[1], BRW_REGISTER_TYPE_UW)), + stride(suboffset(r1_uw,5), 2, 4, 0), + brw_imm_v(0x11001100)); + } + + brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED); +} + + + +static void emit_delta_xy(struct brw_compile *p, + const struct brw_reg *dst, + GLuint mask, + const struct brw_reg *arg0) +{ + struct brw_reg r1 = brw_vec1_grf(1, 0); + + /* Calc delta X,Y by subtracting origin in r1 from the pixel + * centers. + */ + if (mask & BRW_WRITEMASK_X) { + brw_ADD(p, + dst[0], + retype(arg0[0], BRW_REGISTER_TYPE_UW), + negate(r1)); + } + + if (mask & BRW_WRITEMASK_Y) { + brw_ADD(p, + dst[1], + retype(arg0[1], BRW_REGISTER_TYPE_UW), + negate(suboffset(r1,1))); + + } +} + +static void emit_wpos_xy(struct brw_wm_compile *c, + const struct brw_reg *dst, + GLuint mask, + const struct brw_reg *arg0) +{ + struct brw_compile *p = &c->func; + + if (mask & BRW_WRITEMASK_X) { + /* X' = X */ + brw_MOV(p, + dst[0], + retype(arg0[0], BRW_REGISTER_TYPE_W)); + } + + /* XXX: is this needed any more, or is this a NOOP? + */ + if (mask & BRW_WRITEMASK_Y) { +#if 0 + /* Y' = height - 1 - Y */ + brw_ADD(p, + dst[1], + negate(retype(arg0[1], BRW_REGISTER_TYPE_W)), + brw_imm_d(c->key.drawable_height - 1)); +#else + brw_MOV(p, + dst[0], + retype(arg0[0], BRW_REGISTER_TYPE_W)); +#endif + } +} + + +static void emit_pixel_w( struct brw_compile *p, + const struct brw_reg *dst, + GLuint mask, + const struct brw_reg *arg0, + const struct brw_reg *deltas) +{ + /* Don't need this if all you are doing is interpolating color, for + * instance. + */ + if (mask & BRW_WRITEMASK_W) { + struct brw_reg interp3 = brw_vec1_grf(arg0[0].nr+1, 4); + + /* Calc 1/w - just linterp wpos[3] optimized by putting the + * result straight into a message reg. + */ + brw_LINE(p, brw_null_reg(), interp3, deltas[0]); + brw_MAC(p, brw_message_reg(2), suboffset(interp3, 1), deltas[1]); + + /* Calc w */ + brw_math_16( p, dst[3], + BRW_MATH_FUNCTION_INV, + BRW_MATH_SATURATE_NONE, + 2, brw_null_reg(), + BRW_MATH_PRECISION_FULL); + } +} + + + +static void emit_linterp( struct brw_compile *p, + const struct brw_reg *dst, + GLuint mask, + const struct brw_reg *arg0, + const struct brw_reg *deltas ) +{ + struct brw_reg interp[4]; + GLuint nr = arg0[0].nr; + GLuint i; + + interp[0] = brw_vec1_grf(nr, 0); + interp[1] = brw_vec1_grf(nr, 4); + interp[2] = brw_vec1_grf(nr+1, 0); + interp[3] = brw_vec1_grf(nr+1, 4); + + for (i = 0; i < 4; i++) { + if (mask & (1<func; + GLuint msgLength, responseLength; + GLuint i, nr; + GLuint emit; + GLuint msg_type; + GLboolean shadow = FALSE; + + /* How many input regs are there? + */ + switch (inst->target) { + case TGSI_TEXTURE_1D: + emit = BRW_WRITEMASK_X; + nr = 1; + break; + case TGSI_TEXTURE_SHADOW1D: + emit = BRW_WRITEMASK_XW; + nr = 4; + shadow = TRUE; + break; + case TGSI_TEXTURE_2D: + emit = BRW_WRITEMASK_XY; + nr = 2; + break; + case TGSI_TEXTURE_SHADOW2D: + case TGSI_TEXTURE_SHADOWRECT: + emit = BRW_WRITEMASK_XYW; + nr = 4; + shadow = TRUE; + break; + case TGSI_TEXTURE_3D: + case TGSI_TEXTURE_CUBE: + emit = BRW_WRITEMASK_XYZ; + nr = 3; + break; + default: + /* unexpected target */ + abort(); + } + + msgLength = 1; + + for (i = 0; i < nr; i++) { + static const GLuint swz[4] = {0,1,2,2}; + if (emit & (1<brw)) { + if (shadow) + msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_COMPARE_IGDNG; + else + msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_IGDNG; + } else { + if (shadow) + msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_COMPARE; + else + msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE; + } + + brw_SAMPLE(p, + retype(vec16(dst[0]), BRW_REGISTER_TYPE_UW), + 1, + retype(c->payload.depth[0].hw_reg, BRW_REGISTER_TYPE_UW), + BTI_TEXTURE(inst->tex_unit), + sampler, /* sampler index */ + inst->writemask, + msg_type, + responseLength, + msgLength, + 0, + 1, + BRW_SAMPLER_SIMD_MODE_SIMD16); +} + + +static void emit_txb( struct brw_wm_compile *c, + const struct brw_wm_instruction *inst, + struct brw_reg *dst, + GLuint dst_flags, + struct brw_reg *coord, + GLuint sampler ) +{ + struct brw_compile *p = &c->func; + GLuint msgLength; + GLuint msg_type; + /* Shadow ignored for txb. + */ + switch (inst->target) { + case TGSI_TEXTURE_1D: + case TGSI_TEXTURE_SHADOW1D: + brw_MOV(p, brw_message_reg(2), coord[0]); + brw_MOV(p, brw_message_reg(4), brw_imm_f(0)); + brw_MOV(p, brw_message_reg(6), brw_imm_f(0)); + break; + case TGSI_TEXTURE_2D: + case TGSI_TEXTURE_RECT: + case TGSI_TEXTURE_SHADOW2D: + case TGSI_TEXTURE_SHADOWRECT: + brw_MOV(p, brw_message_reg(2), coord[0]); + brw_MOV(p, brw_message_reg(4), coord[1]); + brw_MOV(p, brw_message_reg(6), brw_imm_f(0)); + break; + case TGSI_TEXTURE_3D: + case TGSI_TEXTURE_CUBE: + brw_MOV(p, brw_message_reg(2), coord[0]); + brw_MOV(p, brw_message_reg(4), coord[1]); + brw_MOV(p, brw_message_reg(6), coord[2]); + break; + default: + /* unexpected target */ + abort(); + } + + brw_MOV(p, brw_message_reg(8), coord[3]); + msgLength = 9; + + if (BRW_IS_IGDNG(p->brw)) + msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS_IGDNG; + else + msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS; + + brw_SAMPLE(p, + retype(vec16(dst[0]), BRW_REGISTER_TYPE_UW), + 1, + retype(c->payload.depth[0].hw_reg, BRW_REGISTER_TYPE_UW), + BTI_TEXTURE(inst->tex_unit), + sampler, /* sampler index */ + inst->writemask, + msg_type, + 8, /* responseLength */ + msgLength, + 0, + 1, + BRW_SAMPLER_SIMD_MODE_SIMD16); +} + + +static void emit_lit( struct brw_compile *p, + const struct brw_reg *dst, + GLuint mask, + const struct brw_reg *arg0 ) +{ + assert((mask & BRW_WRITEMASK_XW) == 0); + + if (mask & BRW_WRITEMASK_Y) { + brw_set_saturate(p, (mask & SATURATE) ? 1 : 0); + brw_MOV(p, dst[1], arg0[0]); + brw_set_saturate(p, 0); + } + + if (mask & BRW_WRITEMASK_Z) { + emit_math2(p, BRW_MATH_FUNCTION_POW, + &dst[2], + BRW_WRITEMASK_X | (mask & SATURATE), + &arg0[1], + &arg0[3]); + } + + /* Ordinarily you'd use an iff statement to skip or shortcircuit + * some of the POW calculations above, but 16-wide iff statements + * seem to lock c1 hardware, so this is a nasty workaround: + */ + brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_LE, arg0[0], brw_imm_f(0)); + { + if (mask & BRW_WRITEMASK_Y) + brw_MOV(p, dst[1], brw_imm_f(0)); + + if (mask & BRW_WRITEMASK_Z) + brw_MOV(p, dst[2], brw_imm_f(0)); + } + brw_set_predicate_control(p, BRW_PREDICATE_NONE); +} + + +/* Kill pixel - set execution mask to zero for those pixels which + * fail. + */ +static void emit_kil( struct brw_wm_compile *c, + struct brw_reg *arg0) +{ + struct brw_compile *p = &c->func; + struct brw_reg r0uw = retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW); + GLuint i; + + /* XXX - usually won't need 4 compares! + */ + for (i = 0; i < 4; i++) { + brw_push_insn_state(p); + brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_GE, arg0[i], brw_imm_f(0)); + brw_set_predicate_control_flag_value(p, 0xff); + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + brw_AND(p, r0uw, brw_flag_reg(), r0uw); + brw_pop_insn_state(p); + } +} + +/* KILLP kills the pixels that are currently executing, not based on a test + * of the arguments. + */ +static void emit_killp( struct brw_wm_compile *c ) +{ + struct brw_compile *p = &c->func; + struct brw_reg r0uw = retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW); + + brw_push_insn_state(p); + brw_set_mask_control(p, BRW_MASK_DISABLE); + brw_NOT(p, c->emit_mask_reg, brw_mask_reg(1)); /* IMASK */ + brw_AND(p, r0uw, c->emit_mask_reg, r0uw); + brw_pop_insn_state(p); +} + +static void fire_fb_write( struct brw_wm_compile *c, + GLuint base_reg, + GLuint nr, + GLuint target, + GLuint eot ) +{ + struct brw_compile *p = &c->func; + + /* Pass through control information: + */ +/* mov (8) m1.0<1>:ud r1.0<8;8,1>:ud { Align1 NoMask } */ + { + brw_push_insn_state(p); + brw_set_mask_control(p, BRW_MASK_DISABLE); /* ? */ + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + brw_MOV(p, + brw_message_reg(base_reg + 1), + brw_vec8_grf(1, 0)); + brw_pop_insn_state(p); + } + + /* Send framebuffer write message: */ +/* send (16) null.0<1>:uw m0 r0.0<8;8,1>:uw 0x85a04000:ud { Align1 EOT } */ + brw_fb_WRITE(p, + retype(vec16(brw_null_reg()), BRW_REGISTER_TYPE_UW), + base_reg, + retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW), + target, + nr, + 0, + eot); +} + + +static void emit_aa( struct brw_wm_compile *c, + struct brw_reg *arg1, + GLuint reg ) +{ + struct brw_compile *p = &c->func; + GLuint comp = c->key.aa_dest_stencil_reg / 2; + GLuint off = c->key.aa_dest_stencil_reg % 2; + struct brw_reg aa = offset(arg1[comp], off); + + brw_push_insn_state(p); + brw_set_compression_control(p, BRW_COMPRESSION_NONE); /* ?? */ + brw_MOV(p, brw_message_reg(reg), aa); + brw_pop_insn_state(p); +} + + +/* Post-fragment-program processing. Send the results to the + * framebuffer. + * \param arg0 the fragment color + * \param arg1 the pass-through depth value + * \param arg2 the shader-computed depth value + */ +static void emit_fb_write( struct brw_wm_compile *c, + struct brw_reg *arg0, + struct brw_reg *arg1, + struct brw_reg *arg2, + GLuint target, + GLuint eot) +{ + struct brw_compile *p = &c->func; + GLuint nr = 2; + GLuint channel; + + /* Reserve a space for AA - may not be needed: + */ + if (c->key.aa_dest_stencil_reg) + nr += 1; + + /* I don't really understand how this achieves the color interleave + * (ie RGBARGBA) in the result: [Do the saturation here] + */ + { + brw_push_insn_state(p); + + for (channel = 0; channel < 4; channel++) { + /* mov (8) m2.0<1>:ud r28.0<8;8,1>:ud { Align1 } */ + /* mov (8) m6.0<1>:ud r29.0<8;8,1>:ud { Align1 SecHalf } */ + + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + brw_MOV(p, + brw_message_reg(nr + channel), + arg0[channel]); + + brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF); + brw_MOV(p, + brw_message_reg(nr + channel + 4), + sechalf(arg0[channel])); + } + + /* skip over the regs populated above: + */ + nr += 8; + + brw_pop_insn_state(p); + } + + if (c->key.source_depth_to_render_target) + { + if (c->key.computes_depth) + brw_MOV(p, brw_message_reg(nr), arg2[2]); + else + brw_MOV(p, brw_message_reg(nr), arg1[1]); /* ? */ + + nr += 2; + } + + if (c->key.dest_depth_reg) + { + GLuint comp = c->key.dest_depth_reg / 2; + GLuint off = c->key.dest_depth_reg % 2; + + if (off != 0) { + brw_push_insn_state(p); + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + + brw_MOV(p, brw_message_reg(nr), offset(arg1[comp],1)); + /* 2nd half? */ + brw_MOV(p, brw_message_reg(nr+1), arg1[comp+1]); + brw_pop_insn_state(p); + } + else { + brw_MOV(p, brw_message_reg(nr), arg1[comp]); + } + nr += 2; + } + + if (!c->key.runtime_check_aads_emit) { + if (c->key.aa_dest_stencil_reg) + emit_aa(c, arg1, 2); + + fire_fb_write(c, 0, nr, target, eot); + } + else { + struct brw_reg v1_null_ud = vec1(retype(brw_null_reg(), BRW_REGISTER_TYPE_UD)); + struct brw_reg ip = brw_ip_reg(); + struct brw_instruction *jmp; + + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + brw_set_conditionalmod(p, BRW_CONDITIONAL_Z); + brw_AND(p, + v1_null_ud, + get_element_ud(brw_vec8_grf(1,0), 6), + brw_imm_ud(1<<26)); + + jmp = brw_JMPI(p, ip, ip, brw_imm_d(0)); + { + emit_aa(c, arg1, 2); + fire_fb_write(c, 0, nr, target, eot); + /* note - thread killed in subroutine */ + } + brw_land_fwd_jump(p, jmp); + + /* ELSE: Shuffle up one register to fill in the hole left for AA: + */ + fire_fb_write(c, 1, nr-1, target, eot); + } +} + + +/** + * Move a GPR to scratch memory. + */ +static void emit_spill( struct brw_wm_compile *c, + struct brw_reg reg, + GLuint slot ) +{ + struct brw_compile *p = &c->func; + + /* + mov (16) m2.0<1>:ud r2.0<8;8,1>:ud { Align1 Compr } + */ + brw_MOV(p, brw_message_reg(2), reg); + + /* + mov (1) r0.2<1>:d 0x00000080:d { Align1 NoMask } + send (16) null.0<1>:uw m1 r0.0<8;8,1>:uw 0x053003ff:ud { Align1 } + */ + brw_dp_WRITE_16(p, + retype(vec16(brw_vec8_grf(0, 0)), BRW_REGISTER_TYPE_UW), + slot); +} + + +/** + * Load a GPR from scratch memory. + */ +static void emit_unspill( struct brw_wm_compile *c, + struct brw_reg reg, + GLuint slot ) +{ + struct brw_compile *p = &c->func; + + /* Slot 0 is the undef value. + */ + if (slot == 0) { + brw_MOV(p, reg, brw_imm_f(0)); + return; + } + + /* + mov (1) r0.2<1>:d 0x000000c0:d { Align1 NoMask } + send (16) r110.0<1>:uw m1 r0.0<8;8,1>:uw 0x041243ff:ud { Align1 } + */ + + brw_dp_READ_16(p, + retype(vec16(reg), BRW_REGISTER_TYPE_UW), + slot); +} + + +/** + * Retrieve up to 4 GEN4 register pairs for the given wm reg: + * Args with unspill_reg != 0 will be loaded from scratch memory. + */ +static void get_argument_regs( struct brw_wm_compile *c, + struct brw_wm_ref *arg[], + struct brw_reg *regs ) +{ + GLuint i; + + for (i = 0; i < 4; i++) { + if (arg[i]) { + if (arg[i]->unspill_reg) + emit_unspill(c, + brw_vec8_grf(arg[i]->unspill_reg, 0), + arg[i]->value->spill_slot); + + regs[i] = arg[i]->hw_reg; + } + else { + regs[i] = brw_null_reg(); + } + } +} + + +/** + * For values that have a spill_slot!=0, write those regs to scratch memory. + */ +static void spill_values( struct brw_wm_compile *c, + struct brw_wm_value *values, + GLuint nr ) +{ + GLuint i; + + for (i = 0; i < nr; i++) + if (values[i].spill_slot) + emit_spill(c, values[i].hw_reg, values[i].spill_slot); +} + + +/* Emit the fragment program instructions here. + */ +void brw_wm_emit( struct brw_wm_compile *c ) +{ + struct brw_compile *p = &c->func; + GLuint insn; + + brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED); + + /* Check if any of the payload regs need to be spilled: + */ + spill_values(c, c->payload.depth, 4); + spill_values(c, c->creg, c->nr_creg); + spill_values(c, c->payload.input_interp, PIPE_MAX_SHADER_INPUTS); + + + for (insn = 0; insn < c->nr_insns; insn++) { + + struct brw_wm_instruction *inst = &c->instruction[insn]; + struct brw_reg args[3][4], dst[4]; + GLuint i, dst_flags; + + /* Get argument regs: + */ + for (i = 0; i < 3; i++) + get_argument_regs(c, inst->src[i], args[i]); + + /* Get dest regs: + */ + for (i = 0; i < 4; i++) + if (inst->dst[i]) + dst[i] = inst->dst[i]->hw_reg; + else + dst[i] = brw_null_reg(); + + /* Flags + */ + dst_flags = inst->writemask; + if (inst->saturate) + dst_flags |= SATURATE; + + switch (inst->opcode) { + /* Generated instructions for calculating triangle interpolants: + */ + case WM_PIXELXY: + emit_pixel_xy(p, dst, dst_flags); + break; + + case WM_DELTAXY: + emit_delta_xy(p, dst, dst_flags, args[0]); + break; + + case WM_WPOSXY: + emit_wpos_xy(c, dst, dst_flags, args[0]); + break; + + case WM_PIXELW: + emit_pixel_w(p, dst, dst_flags, args[0], args[1]); + break; + + case WM_LINTERP: + emit_linterp(p, dst, dst_flags, args[0], args[1]); + break; + + case WM_PINTERP: + emit_pinterp(p, dst, dst_flags, args[0], args[1], args[2]); + break; + + case WM_CINTERP: + emit_cinterp(p, dst, dst_flags, args[0]); + break; + + case WM_FB_WRITE: + emit_fb_write(c, args[0], args[1], args[2], inst->target, inst->eot); + break; + + case WM_FRONTFACING: + emit_frontfacing(p, dst, dst_flags); + break; + + /* Straightforward arithmetic: + */ + case TGSI_OPCODE_ADD: + emit_alu2(p, brw_ADD, dst, dst_flags, args[0], args[1]); + break; + + case TGSI_OPCODE_FRC: + emit_alu1(p, brw_FRC, dst, dst_flags, args[0]); + break; + + case TGSI_OPCODE_FLR: + emit_alu1(p, brw_RNDD, dst, dst_flags, args[0]); + break; + + case TGSI_OPCODE_DDX: + emit_ddxy(p, dst, dst_flags, GL_TRUE, args[0]); + break; + + case TGSI_OPCODE_DDY: + emit_ddxy(p, dst, dst_flags, GL_FALSE, args[0]); + break; + + case TGSI_OPCODE_DP3: + emit_dp3(p, dst, dst_flags, args[0], args[1]); + break; + + case TGSI_OPCODE_DP4: + emit_dp4(p, dst, dst_flags, args[0], args[1]); + break; + + case TGSI_OPCODE_DPH: + emit_dph(p, dst, dst_flags, args[0], args[1]); + break; + + case TGSI_OPCODE_TRUNC: + emit_trunc(p, dst, dst_flags, args[0]); + break; + + case TGSI_OPCODE_LRP: + emit_lrp(p, dst, dst_flags, args[0], args[1], args[2]); + break; + + case TGSI_OPCODE_MAD: + emit_mad(p, dst, dst_flags, args[0], args[1], args[2]); + break; + + case TGSI_OPCODE_MOV: + emit_alu1(p, brw_MOV, dst, dst_flags, args[0]); + break; + + case TGSI_OPCODE_MUL: + emit_alu2(p, brw_MUL, dst, dst_flags, args[0], args[1]); + break; + + case TGSI_OPCODE_XPD: + emit_xpd(p, dst, dst_flags, args[0], args[1]); + break; + + /* Higher math functions: + */ + case TGSI_OPCODE_RCP: + emit_math1(p, BRW_MATH_FUNCTION_INV, dst, dst_flags, args[0]); + break; + + case TGSI_OPCODE_RSQ: + emit_math1(p, BRW_MATH_FUNCTION_RSQ, dst, dst_flags, args[0]); + break; + + case TGSI_OPCODE_SIN: + emit_math1(p, BRW_MATH_FUNCTION_SIN, dst, dst_flags, args[0]); + break; + + case TGSI_OPCODE_COS: + emit_math1(p, BRW_MATH_FUNCTION_COS, dst, dst_flags, args[0]); + break; + + case TGSI_OPCODE_EX2: + emit_math1(p, BRW_MATH_FUNCTION_EXP, dst, dst_flags, args[0]); + break; + + case TGSI_OPCODE_LG2: + emit_math1(p, BRW_MATH_FUNCTION_LOG, dst, dst_flags, args[0]); + break; + + case TGSI_OPCODE_SCS: + /* There is an scs math function, but it would need some + * fixup for 16-element execution. + */ + if (dst_flags & BRW_WRITEMASK_X) + emit_math1(p, BRW_MATH_FUNCTION_COS, dst, (dst_flags&SATURATE)|BRW_WRITEMASK_X, args[0]); + if (dst_flags & BRW_WRITEMASK_Y) + emit_math1(p, BRW_MATH_FUNCTION_SIN, dst+1, (dst_flags&SATURATE)|BRW_WRITEMASK_X, args[0]); + break; + + case TGSI_OPCODE_POW: + emit_math2(p, BRW_MATH_FUNCTION_POW, dst, dst_flags, args[0], args[1]); + break; + + /* Comparisons: + */ + case TGSI_OPCODE_CMP: + emit_cmp(p, dst, dst_flags, args[0], args[1], args[2]); + break; + + case TGSI_OPCODE_MAX: + emit_max(p, dst, dst_flags, args[0], args[1]); + break; + + case TGSI_OPCODE_MIN: + emit_min(p, dst, dst_flags, args[0], args[1]); + break; + + case TGSI_OPCODE_SLT: + emit_slt(p, dst, dst_flags, args[0], args[1]); + break; + + case TGSI_OPCODE_SLE: + emit_sle(p, dst, dst_flags, args[0], args[1]); + break; + case TGSI_OPCODE_SGT: + emit_sgt(p, dst, dst_flags, args[0], args[1]); + break; + case TGSI_OPCODE_SGE: + emit_sge(p, dst, dst_flags, args[0], args[1]); + break; + case TGSI_OPCODE_SEQ: + emit_seq(p, dst, dst_flags, args[0], args[1]); + break; + case TGSI_OPCODE_SNE: + emit_sne(p, dst, dst_flags, args[0], args[1]); + break; + + case TGSI_OPCODE_LIT: + emit_lit(p, dst, dst_flags, args[0]); + break; + + /* Texturing operations: + */ + case TGSI_OPCODE_TEX: + emit_tex(c, inst, dst, dst_flags, args[0], inst->sampler); + break; + + case TGSI_OPCODE_TXB: + emit_txb(c, inst, dst, dst_flags, args[0], inst->sampler); + break; + + case TGSI_OPCODE_KIL: + emit_kil(c, args[0]); + break; + + case TGSI_OPCODE_KILP: + emit_killp(c); + break; + + default: + debug_printf("Unsupported opcode %i (%s) in fragment shader\n", + inst->opcode, + tgsi_get_opcode_info(inst->opcode)->mnemonic); + } + + for (i = 0; i < 4; i++) + if (inst->dst[i] && inst->dst[i]->spill_slot) + emit_spill(c, + inst->dst[i]->hw_reg, + inst->dst[i]->spill_slot); + } + + if (BRW_DEBUG & DEBUG_WM) { + debug_printf("wm-native:\n"); + brw_disasm(stderr, p->store, p->nr_insn); + } +} diff --git a/src/gallium/drivers/i965/brw_wm_fp.c b/src/gallium/drivers/i965/brw_wm_fp.c new file mode 100644 index 0000000..f7ee55c --- /dev/null +++ b/src/gallium/drivers/i965/brw_wm_fp.c @@ -0,0 +1,1223 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#include "pipe/p_shader_tokens.h" + +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_info.h" +#include "tgsi/tgsi_util.h" + +#include "brw_wm.h" +#include "brw_debug.h" + + +/*********************************************************************** + * Source regs + */ + +static struct brw_fp_src src_reg(GLuint file, GLuint idx) +{ + struct brw_fp_src reg; + reg.file = file; + reg.index = idx; + reg.swizzle = BRW_SWIZZLE_XYZW; + reg.indirect = 0; + reg.negate = 0; + reg.abs = 0; + return reg; +} + +static struct brw_fp_src src_reg_from_dst(struct brw_fp_dst dst) +{ + return src_reg(dst.file, dst.index); +} + +static struct brw_fp_src src_undef( void ) +{ + return src_reg(TGSI_FILE_NULL, 0); +} + +static GLboolean src_is_undef(struct brw_fp_src src) +{ + return src.file == TGSI_FILE_NULL; +} + +static struct brw_fp_src src_swizzle( struct brw_fp_src reg, int x, int y, int z, int w ) +{ + unsigned swz = reg.swizzle; + + reg.swizzle = ( BRW_GET_SWZ(swz, x) << 0 | + BRW_GET_SWZ(swz, y) << 2 | + BRW_GET_SWZ(swz, z) << 4 | + BRW_GET_SWZ(swz, w) << 6 ); + + return reg; +} + +static struct brw_fp_src src_scalar( struct brw_fp_src reg, int x ) +{ + return src_swizzle(reg, x, x, x, x); +} + +static struct brw_fp_src src_abs( struct brw_fp_src src ) +{ + src.negate = 0; + src.abs = 1; + return src; +} + +static struct brw_fp_src src_negate( struct brw_fp_src src ) +{ + src.negate = 1; + src.abs = 0; + return src; +} + + +static int match_or_expand_immediate( const float *v, + unsigned nr, + float *v2, + unsigned *nr2, + unsigned *swizzle ) +{ + unsigned i, j; + + *swizzle = 0; + + for (i = 0; i < nr; i++) { + boolean found = FALSE; + + for (j = 0; j < *nr2 && !found; j++) { + if (v[i] == v2[j]) { + *swizzle |= j << (i * 2); + found = TRUE; + } + } + + if (!found) { + if (*nr2 >= 4) + return FALSE; + + v2[*nr2] = v[i]; + *swizzle |= *nr2 << (i * 2); + (*nr2)++; + } + } + + return TRUE; +} + + + +/* Internally generated immediates: overkill... + */ +static struct brw_fp_src src_imm( struct brw_wm_compile *c, + const GLfloat *v, + unsigned nr) +{ + unsigned i, j; + unsigned swizzle; + + /* Could do a first pass where we examine all existing immediates + * without expanding. + */ + + for (i = 0; i < c->nr_immediates; i++) { + if (match_or_expand_immediate( v, + nr, + c->immediate[i].v, + &c->immediate[i].nr, + &swizzle )) + goto out; + } + + if (c->nr_immediates < Elements(c->immediate)) { + i = c->nr_immediates++; + if (match_or_expand_immediate( v, + nr, + c->immediate[i].v, + &c->immediate[i].nr, + &swizzle )) + goto out; + } + + c->error = 1; + return src_undef(); + +out: + /* Make sure that all referenced elements are from this immediate. + * Has the effect of making size-one immediates into scalars. + */ + for (j = nr; j < 4; j++) + swizzle |= (swizzle & 0x3) << (j * 2); + + return src_swizzle( src_reg( TGSI_FILE_IMMEDIATE, i ), + BRW_GET_SWZ(swizzle, X), + BRW_GET_SWZ(swizzle, Y), + BRW_GET_SWZ(swizzle, Z), + BRW_GET_SWZ(swizzle, W) ); +} + + + +static struct brw_fp_src src_imm1f( struct brw_wm_compile *c, + GLfloat f ) +{ + return src_imm(c, &f, 1); +} + +static struct brw_fp_src src_imm4f( struct brw_wm_compile *c, + GLfloat x, + GLfloat y, + GLfloat z, + GLfloat w) +{ + GLfloat f[4] = {x,y,z,w}; + return src_imm(c, f, 4); +} + + + +/*********************************************************************** + * Dest regs + */ + +static struct brw_fp_dst dst_reg(GLuint file, GLuint idx) +{ + struct brw_fp_dst reg; + reg.file = file; + reg.index = idx; + reg.writemask = BRW_WRITEMASK_XYZW; + reg.indirect = 0; + reg.saturate = 0; + return reg; +} + +static struct brw_fp_dst dst_mask( struct brw_fp_dst reg, int mask ) +{ + reg.writemask &= mask; + return reg; +} + +static struct brw_fp_dst dst_undef( void ) +{ + return dst_reg(TGSI_FILE_NULL, 0); +} + +static boolean dst_is_undef( struct brw_fp_dst dst ) +{ + return dst.file == TGSI_FILE_NULL; +} + +static struct brw_fp_dst dst_saturate( struct brw_fp_dst reg, boolean flag ) +{ + reg.saturate = flag; + return reg; +} + +static struct brw_fp_dst get_temp( struct brw_wm_compile *c ) +{ + int bit = ffs( ~c->fp_temp ); + + if (!bit) { + debug_printf("%s: out of temporaries\n", __FILE__); + } + + c->fp_temp |= 1<<(bit-1); + return dst_reg(TGSI_FILE_TEMPORARY, c->fp_first_internal_temp+(bit-1)); +} + + +static void release_temp( struct brw_wm_compile *c, struct brw_fp_dst temp ) +{ + c->fp_temp &= ~(1 << (temp.index - c->fp_first_internal_temp)); +} + + +/*********************************************************************** + * Instructions + */ + +static struct brw_fp_instruction *get_fp_inst(struct brw_wm_compile *c) +{ + return &c->fp_instructions[c->nr_fp_insns++]; +} + +static struct brw_fp_instruction * emit_tex_op(struct brw_wm_compile *c, + GLuint op, + struct brw_fp_dst dest, + GLuint tex_unit, + GLuint target, + GLuint sampler, + struct brw_fp_src src0, + struct brw_fp_src src1, + struct brw_fp_src src2 ) +{ + struct brw_fp_instruction *inst = get_fp_inst(c); + + if (tex_unit || target) + assert(op == TGSI_OPCODE_TXP || + op == TGSI_OPCODE_TXB || + op == TGSI_OPCODE_TEX || + op == WM_FB_WRITE); + + inst->opcode = op; + inst->dst = dest; + inst->tex_unit = tex_unit; + inst->target = target; + inst->sampler = sampler; + inst->src[0] = src0; + inst->src[1] = src1; + inst->src[2] = src2; + + return inst; +} + + +static INLINE void emit_op3(struct brw_wm_compile *c, + GLuint op, + struct brw_fp_dst dest, + struct brw_fp_src src0, + struct brw_fp_src src1, + struct brw_fp_src src2 ) +{ + emit_tex_op(c, op, dest, 0, 0, 0, src0, src1, src2); +} + + +static INLINE void emit_op2(struct brw_wm_compile *c, + GLuint op, + struct brw_fp_dst dest, + struct brw_fp_src src0, + struct brw_fp_src src1) +{ + emit_tex_op(c, op, dest, 0, 0, 0, src0, src1, src_undef()); +} + +static INLINE void emit_op1(struct brw_wm_compile *c, + GLuint op, + struct brw_fp_dst dest, + struct brw_fp_src src0) +{ + emit_tex_op(c, op, dest, 0, 0, 0, src0, src_undef(), src_undef()); +} + +static INLINE void emit_op0(struct brw_wm_compile *c, + GLuint op, + struct brw_fp_dst dest) +{ + emit_tex_op(c, op, dest, 0, 0, 0, src_undef(), src_undef(), src_undef()); +} + + + +/* Many opcodes produce the same value across all the result channels. + * We'd rather not have to support that splatting in the opcode implementations, + * and brw_wm_pass*.c wants to optimize them out by shuffling references around + * anyway. We can easily get both by emitting the opcode to one channel, and + * then MOVing it to the others, which brw_wm_pass*.c already understands. + */ +static void emit_scalar_insn(struct brw_wm_compile *c, + unsigned opcode, + struct brw_fp_dst dst, + struct brw_fp_src src0, + struct brw_fp_src src1, + struct brw_fp_src src2 ) +{ + unsigned first_chan = ffs(dst.writemask) - 1; + unsigned first_mask = 1 << first_chan; + + if (dst.writemask == 0) + return; + + emit_op3( c, opcode, + dst_mask(dst, first_mask), + src0, src1, src2 ); + + if (dst.writemask != first_mask) { + emit_op1(c, TGSI_OPCODE_MOV, + dst_mask(dst, ~first_mask), + src_scalar(src_reg_from_dst(dst), first_chan)); + } +} + + +/*********************************************************************** + * Special instructions for interpolation and other tasks + */ + +static struct brw_fp_src get_pixel_xy( struct brw_wm_compile *c ) +{ + if (src_is_undef(c->fp_pixel_xy)) { + struct brw_fp_dst pixel_xy = get_temp(c); + struct brw_fp_src payload_r0_depth = src_reg(BRW_FILE_PAYLOAD, PAYLOAD_DEPTH); + + + /* Emit the out calculations, and hold onto the results. Use + * two instructions as a temporary is required. + */ + /* pixel_xy.xy = PIXELXY payload[0]; + */ + emit_op1(c, + WM_PIXELXY, + dst_mask(pixel_xy, BRW_WRITEMASK_XY), + payload_r0_depth); + + c->fp_pixel_xy = src_reg_from_dst(pixel_xy); + } + + return c->fp_pixel_xy; +} + +static struct brw_fp_src get_delta_xy( struct brw_wm_compile *c ) +{ + if (src_is_undef(c->fp_delta_xy)) { + struct brw_fp_dst delta_xy = get_temp(c); + struct brw_fp_src pixel_xy = get_pixel_xy(c); + struct brw_fp_src payload_r0_depth = src_reg(BRW_FILE_PAYLOAD, PAYLOAD_DEPTH); + + /* deltas.xy = DELTAXY pixel_xy, payload[0] + */ + emit_op3(c, + WM_DELTAXY, + dst_mask(delta_xy, BRW_WRITEMASK_XY), + pixel_xy, + payload_r0_depth, + src_undef()); + + c->fp_delta_xy = src_reg_from_dst(delta_xy); + } + + return c->fp_delta_xy; +} + +static struct brw_fp_src get_pixel_w( struct brw_wm_compile *c ) +{ + if (src_is_undef(c->fp_pixel_w)) { + struct brw_fp_dst pixel_w = get_temp(c); + struct brw_fp_src deltas = get_delta_xy(c); + + /* XXX: assuming position is always first -- valid? + */ + struct brw_fp_src interp_wpos = src_reg(BRW_FILE_PAYLOAD, 0); + + /* deltas.xyw = DELTAS2 deltas.xy, payload.interp_wpos.x + */ + emit_op3(c, + WM_PIXELW, + dst_mask(pixel_w, BRW_WRITEMASK_W), + interp_wpos, + deltas, + src_undef()); + + + c->fp_pixel_w = src_reg_from_dst(pixel_w); + } + + return c->fp_pixel_w; +} + + +/*********************************************************************** + * Emit INTERP instructions ahead of first use of each attrib. + */ + +static void emit_interp( struct brw_wm_compile *c, + GLuint idx, + GLuint semantic, + GLuint interp_mode ) +{ + struct brw_fp_dst dst = dst_reg(TGSI_FILE_INPUT, idx); + struct brw_fp_src interp = src_reg(BRW_FILE_PAYLOAD, idx); + struct brw_fp_src deltas = get_delta_xy(c); + + /* Need to use PINTERP on attributes which have been + * multiplied by 1/W in the SF program, and LINTERP on those + * which have not: + */ + switch (semantic) { + case TGSI_SEMANTIC_POSITION: + /* Have to treat wpos.xy specially: + */ + emit_op1(c, + WM_WPOSXY, + dst_mask(dst, BRW_WRITEMASK_XY), + get_pixel_xy(c)); + + /* TGSI_FILE_INPUT.attr.xyzw = INTERP payload.interp[attr].x, deltas.xyw + */ + emit_op2(c, + WM_LINTERP, + dst_mask(dst, BRW_WRITEMASK_ZW), + interp, + deltas); + break; + + case TGSI_SEMANTIC_COLOR: + if (c->key.flat_shade) { + emit_op1(c, + WM_CINTERP, + dst, + interp); + } + else if (interp_mode == TGSI_INTERPOLATE_LINEAR) { + emit_op2(c, + WM_LINTERP, + dst, + interp, + deltas); + } + else { + emit_op3(c, + WM_PINTERP, + dst, + interp, + deltas, + get_pixel_w(c)); + } + + break; + + case TGSI_SEMANTIC_FOG: + /* Interpolate the fog coordinate */ + emit_op3(c, + WM_PINTERP, + dst_mask(dst, BRW_WRITEMASK_X), + interp, + deltas, + get_pixel_w(c)); + + emit_op1(c, + TGSI_OPCODE_MOV, + dst_mask(dst, BRW_WRITEMASK_YZ), + src_imm1f(c, 0.0)); + + emit_op1(c, + TGSI_OPCODE_MOV, + dst_mask(dst, BRW_WRITEMASK_W), + src_imm1f(c, 1.0)); + break; + + case TGSI_SEMANTIC_FACE: + /* XXX review/test this case */ + emit_op0(c, + WM_FRONTFACING, + dst_mask(dst, BRW_WRITEMASK_X)); + + emit_op1(c, + TGSI_OPCODE_MOV, + dst_mask(dst, BRW_WRITEMASK_YZ), + src_imm1f(c, 0.0)); + + emit_op1(c, + TGSI_OPCODE_MOV, + dst_mask(dst, BRW_WRITEMASK_W), + src_imm1f(c, 1.0)); + break; + + case TGSI_SEMANTIC_PSIZE: + /* XXX review/test this case */ + emit_op3(c, + WM_PINTERP, + dst_mask(dst, BRW_WRITEMASK_XY), + interp, + deltas, + get_pixel_w(c)); + + emit_op1(c, + TGSI_OPCODE_MOV, + dst_mask(dst, BRW_WRITEMASK_Z), + src_imm1f(c, 0.0f)); + + emit_op1(c, + TGSI_OPCODE_MOV, + dst_mask(dst, BRW_WRITEMASK_W), + src_imm1f(c, 1.0f)); + break; + + default: + switch (interp_mode) { + case TGSI_INTERPOLATE_CONSTANT: + emit_op1(c, + WM_CINTERP, + dst, + interp); + break; + + case TGSI_INTERPOLATE_LINEAR: + emit_op2(c, + WM_LINTERP, + dst, + interp, + deltas); + break; + + case TGSI_INTERPOLATE_PERSPECTIVE: + emit_op3(c, + WM_PINTERP, + dst, + interp, + deltas, + get_pixel_w(c)); + break; + } + break; + } +} + + +/*********************************************************************** + * Expand various instructions here to simpler forms. + */ +static void precalc_dst( struct brw_wm_compile *c, + struct brw_fp_dst dst, + struct brw_fp_src src0, + struct brw_fp_src src1 ) +{ + if (dst.writemask & BRW_WRITEMASK_Y) { + /* dst.y = mul src0.y, src1.y + */ + emit_op2(c, + TGSI_OPCODE_MUL, + dst_mask(dst, BRW_WRITEMASK_Y), + src0, + src1); + } + + if (dst.writemask & BRW_WRITEMASK_XZ) { + /* dst.z = mov src0.zzzz + */ + emit_op1(c, + TGSI_OPCODE_MOV, + dst_mask(dst, BRW_WRITEMASK_Z), + src_scalar(src0, Z)); + + /* dst.x = imm1f(1.0) + */ + emit_op1(c, + TGSI_OPCODE_MOV, + dst_saturate(dst_mask(dst, BRW_WRITEMASK_X), 0), + src_imm1f(c, 1.0)); + } + if (dst.writemask & BRW_WRITEMASK_W) { + /* dst.w = mov src1.w + */ + emit_op1(c, + TGSI_OPCODE_MOV, + dst_mask(dst, BRW_WRITEMASK_W), + src1); + } +} + + +static void precalc_lit( struct brw_wm_compile *c, + struct brw_fp_dst dst, + struct brw_fp_src src0 ) +{ + if (dst.writemask & BRW_WRITEMASK_XW) { + /* dst.xw = imm(1.0f) + */ + emit_op1(c, + TGSI_OPCODE_MOV, + dst_saturate(dst_mask(dst, BRW_WRITEMASK_XW), 0), + src_imm1f(c, 1.0f)); + } + + if (dst.writemask & BRW_WRITEMASK_YZ) { + emit_op1(c, + TGSI_OPCODE_LIT, + dst_mask(dst, BRW_WRITEMASK_YZ), + src0); + } +} + + +/** + * Some TEX instructions require extra code, cube map coordinate + * normalization, or coordinate scaling for RECT textures, etc. + * This function emits those extra instructions and the TEX + * instruction itself. + */ +static void precalc_tex( struct brw_wm_compile *c, + struct brw_fp_dst dst, + unsigned target, + unsigned unit, + struct brw_fp_src src0, + struct brw_fp_src sampler ) +{ + struct brw_fp_src coord; + struct brw_fp_dst tmp = dst_undef(); + + assert(unit < BRW_MAX_TEX_UNIT); + + /* Cubemap: find longest component of coord vector and normalize + * it. + */ + if (target == TGSI_TEXTURE_CUBE) { + struct brw_fp_src tmpsrc; + + tmp = get_temp(c); + tmpsrc = src_reg_from_dst(tmp); + + /* tmp = abs(src0) */ + emit_op1(c, + TGSI_OPCODE_MOV, + tmp, + src_abs(src0)); + + /* tmp.X = MAX(tmp.X, tmp.Y) */ + emit_op2(c, TGSI_OPCODE_MAX, + dst_mask(tmp, BRW_WRITEMASK_X), + src_scalar(tmpsrc, X), + src_scalar(tmpsrc, Y)); + + /* tmp.X = MAX(tmp.X, tmp.Z) */ + emit_op2(c, TGSI_OPCODE_MAX, + dst_mask(tmp, BRW_WRITEMASK_X), + tmpsrc, + src_scalar(tmpsrc, Z)); + + /* tmp.X = 1 / tmp.X */ + emit_op1(c, TGSI_OPCODE_RCP, + dst_mask(tmp, BRW_WRITEMASK_X), + tmpsrc); + + /* tmp = src0 * tmp.xxxx */ + emit_op2(c, TGSI_OPCODE_MUL, + tmp, + src0, + src_scalar(tmpsrc, X)); + + coord = tmpsrc; + } + else if (target == TGSI_TEXTURE_RECT || + target == TGSI_TEXTURE_SHADOWRECT) { + /* XXX: need a mechanism for internally generated constants. + */ + coord = src0; + } + else { + coord = src0; + } + + /* Need to emit YUV texture conversions by hand. Probably need to + * do this here - the alternative is in brw_wm_emit.c, but the + * conversion requires allocating a temporary variable which we + * don't have the facility to do that late in the compilation. + */ + if (c->key.yuvtex_mask & (1 << unit)) { + /* convert ycbcr to RGBA */ + GLboolean swap_uv = c->key.yuvtex_swap_mask & (1<fp->info.input_interpolate[src.index] != TGSI_INTERPOLATE_PERSPECTIVE) + return GL_FALSE; + + return GL_TRUE; +} + + +/** + * Emit code for TXP. + */ +static void precalc_txp( struct brw_wm_compile *c, + struct brw_fp_dst dst, + unsigned target, + unsigned unit, + struct brw_fp_src src0, + struct brw_fp_src sampler ) +{ + if (projtex(c, target, src0)) { + struct brw_fp_dst tmp = get_temp(c); + + /* tmp0.w = RCP inst.arg[0][3] + */ + emit_op1(c, + TGSI_OPCODE_RCP, + dst_mask(tmp, BRW_WRITEMASK_W), + src_scalar(src0, W)); + + /* tmp0.xyz = MUL inst.arg[0], tmp0.wwww + */ + emit_op2(c, + TGSI_OPCODE_MUL, + dst_mask(tmp, BRW_WRITEMASK_XYZ), + src0, + src_scalar(src_reg_from_dst(tmp), W)); + + /* dst = TEX tmp0 + */ + precalc_tex(c, + dst, + target, + unit, + src_reg_from_dst(tmp), + sampler ); + + release_temp(c, tmp); + } + else + { + /* dst = TEX src0 + */ + precalc_tex(c, dst, target, unit, src0, sampler); + } +} + + +/* XXX: note this returns a src_reg. + */ +static struct brw_fp_src +find_output_by_semantic( struct brw_wm_compile *c, + unsigned semantic, + unsigned index ) +{ + const struct tgsi_shader_info *info = &c->fp->info; + unsigned i; + + for (i = 0; i < info->num_outputs; i++) + if (info->output_semantic_name[i] == semantic && + info->output_semantic_index[i] == index) + return src_reg( TGSI_FILE_OUTPUT, i ); + + /* If not found, return some arbitrary immediate value: + * + * XXX: this is a good idea but immediates are up generating extra + * curbe entries atm, as they would have in the original driver. + */ + return src_reg( TGSI_FILE_OUTPUT, 0 ); /* src_imm1f(c, 1.0); */ +} + + +static void emit_fb_write( struct brw_wm_compile *c ) +{ + struct brw_fp_src payload_r0_depth = src_reg(BRW_FILE_PAYLOAD, PAYLOAD_DEPTH); + struct brw_fp_src outdepth = find_output_by_semantic(c, TGSI_SEMANTIC_POSITION, 0); + GLuint i; + + + outdepth = src_scalar(outdepth, Z); + + for (i = 0 ; i < c->key.nr_cbufs; i++) { + struct brw_fp_src outcolor; + + outcolor = find_output_by_semantic(c, TGSI_SEMANTIC_COLOR, i); + + /* Use emit_tex_op so that we can specify the inst->target + * field, which is abused to contain the FB write target and the + * EOT marker + */ + emit_tex_op(c, WM_FB_WRITE, + dst_undef(), + (i == c->key.nr_cbufs - 1), /* EOT */ + i, + 0, /* no sampler */ + outcolor, + payload_r0_depth, + outdepth); + } +} + + +static struct brw_fp_dst translate_dst( struct brw_wm_compile *c, + const struct tgsi_full_dst_register *dst, + unsigned saturate ) +{ + struct brw_fp_dst out; + + out.file = dst->Register.File; + out.index = dst->Register.Index; + out.writemask = dst->Register.WriteMask; + out.indirect = dst->Register.Indirect; + out.saturate = (saturate == TGSI_SAT_ZERO_ONE); + + if (out.indirect) { + assert(dst->Indirect.File == TGSI_FILE_ADDRESS); + assert(dst->Indirect.Index == 0); + } + + return out; +} + + +static struct brw_fp_src translate_src( struct brw_wm_compile *c, + const struct tgsi_full_src_register *src ) +{ + struct brw_fp_src out; + + out.file = src->Register.File; + out.index = src->Register.Index; + out.indirect = src->Register.Indirect; + + out.swizzle = ((src->Register.SwizzleX << 0) | + (src->Register.SwizzleY << 2) | + (src->Register.SwizzleZ << 4) | + (src->Register.SwizzleW << 6)); + + switch (tgsi_util_get_full_src_register_sign_mode( src, 0 )) { + case TGSI_UTIL_SIGN_CLEAR: + out.abs = 1; + out.negate = 0; + break; + + case TGSI_UTIL_SIGN_SET: + out.abs = 1; + out.negate = 1; + break; + + case TGSI_UTIL_SIGN_TOGGLE: + out.abs = 0; + out.negate = 1; + break; + + case TGSI_UTIL_SIGN_KEEP: + default: + out.abs = 0; + out.negate = 0; + break; + } + + if (out.indirect) { + assert(src->Indirect.File == TGSI_FILE_ADDRESS); + assert(src->Indirect.Index == 0); + } + + return out; +} + + + +static void emit_insn( struct brw_wm_compile *c, + const struct tgsi_full_instruction *inst ) +{ + unsigned opcode = inst->Instruction.Opcode; + struct brw_fp_dst dst; + struct brw_fp_src src[3]; + int i; + + dst = translate_dst( c, &inst->Dst[0], + inst->Instruction.Saturate ); + + for (i = 0; i < inst->Instruction.NumSrcRegs; i++) + src[i] = translate_src( c, &inst->Src[i] ); + + switch (opcode) { + case TGSI_OPCODE_ABS: + emit_op1(c, TGSI_OPCODE_MOV, + dst, + src_abs(src[0])); + break; + + case TGSI_OPCODE_SUB: + emit_op2(c, TGSI_OPCODE_ADD, + dst, + src[0], + src_negate(src[1])); + break; + + case TGSI_OPCODE_SCS: + emit_op1(c, TGSI_OPCODE_SCS, + dst_mask(dst, BRW_WRITEMASK_XY), + src[0]); + break; + + case TGSI_OPCODE_DST: + precalc_dst(c, dst, src[0], src[1]); + break; + + case TGSI_OPCODE_LIT: + precalc_lit(c, dst, src[0]); + break; + + case TGSI_OPCODE_TEX: + precalc_tex(c, dst, + inst->Texture.Texture, + src[1].index, /* use sampler unit for tex idx */ + src[0], /* coord */ + src[1]); /* sampler */ + break; + + case TGSI_OPCODE_TXP: + precalc_txp(c, dst, + inst->Texture.Texture, + src[1].index, /* use sampler unit for tex idx */ + src[0], /* coord */ + src[1]); /* sampler */ + break; + + case TGSI_OPCODE_TXB: + /* XXX: TXB not done + */ + precalc_tex(c, dst, + inst->Texture.Texture, + src[1].index, /* use sampler unit for tex idx*/ + src[0], + src[1]); + break; + + case TGSI_OPCODE_XPD: + emit_op2(c, TGSI_OPCODE_XPD, + dst_mask(dst, BRW_WRITEMASK_XYZ), + src[0], + src[1]); + break; + + case TGSI_OPCODE_KIL: + emit_op1(c, TGSI_OPCODE_KIL, + dst_mask(dst_undef(), 0), + src[0]); + break; + + case TGSI_OPCODE_END: + emit_fb_write(c); + break; + default: + if (!c->key.has_flow_control && + brw_wm_is_scalar_result(opcode)) + emit_scalar_insn(c, opcode, dst, src[0], src[1], src[2]); + else + emit_op3(c, opcode, dst, src[0], src[1], src[2]); + break; + } +} + +/** + * Initial pass for fragment program code generation. + * This function is used by both the GLSL and non-GLSL paths. + */ +int brw_wm_pass_fp( struct brw_wm_compile *c ) +{ + struct brw_fragment_shader *fs = c->fp; + struct tgsi_parse_context parse; + struct tgsi_full_instruction *inst; + struct tgsi_full_declaration *decl; + const float *imm; + GLuint size; + GLuint i; + + if (BRW_DEBUG & DEBUG_WM) { + debug_printf("pre-fp:\n"); + tgsi_dump(fs->tokens, 0); + } + + c->fp_pixel_xy = src_undef(); + c->fp_delta_xy = src_undef(); + c->fp_pixel_w = src_undef(); + c->nr_fp_insns = 0; + c->nr_immediates = 0; + + + /* Loop over all instructions doing assorted simplifications and + * transformations. + */ + tgsi_parse_init( &parse, fs->tokens ); + while( !tgsi_parse_end_of_tokens( &parse ) ) { + tgsi_parse_token( &parse ); + + switch( parse.FullToken.Token.Type ) { + case TGSI_TOKEN_TYPE_DECLARATION: + /* Turn intput declarations into special WM_* instructions. + * + * XXX: For non-branching shaders, consider deferring variable + * initialization as late as possible to minimize register + * usage. This is how the original BRW driver worked. + * + * In a branching shader, must preamble instructions at decl + * time, as instruction order in the shader does not + * correspond to the order instructions are executed in the + * wild. + * + * This is where special instructions such as WM_CINTERP, + * WM_LINTERP, WM_PINTERP and WM_WPOSXY are emitted to + * compute shader inputs from the payload registers and pixel + * position. + */ + decl = &parse.FullToken.FullDeclaration; + if( decl->Declaration.File == TGSI_FILE_INPUT ) { + unsigned first, last, mask; + unsigned attrib; + + first = decl->Range.First; + last = decl->Range.Last; + mask = decl->Declaration.UsageMask; + + for (attrib = first; attrib <= last; attrib++) { + emit_interp(c, + attrib, + decl->Semantic.Name, + decl->Declaration.Interpolate ); + } + } + + break; + + case TGSI_TOKEN_TYPE_IMMEDIATE: + /* Unlike VS programs we can probably manage fine encoding + * immediate values directly into the emitted EU + * instructions, as we probably only need to reference one + * float value per instruction. Just save the data for now + * and use directly later. + */ + i = c->nr_immediates++; + imm = &parse.FullToken.FullImmediate.u[i].Float; + size = parse.FullToken.FullImmediate.Immediate.NrTokens - 1; + + if (c->nr_immediates >= BRW_WM_MAX_CONST) + return PIPE_ERROR_OUT_OF_MEMORY; + + for (i = 0; i < size; i++) + c->immediate[c->nr_immediates].v[i] = imm[i]; + + for (; i < 4; i++) + c->immediate[c->nr_immediates].v[i] = 0.0; + + c->immediate[c->nr_immediates].nr = size; + c->nr_immediates++; + break; + + case TGSI_TOKEN_TYPE_INSTRUCTION: + inst = &parse.FullToken.FullInstruction; + emit_insn(c, inst); + break; + } + } + + if (BRW_DEBUG & DEBUG_WM) { + brw_wm_print_fp_program( c, "pass_fp" ); + debug_printf("\n"); + } + + return c->error; +} + diff --git a/src/gallium/drivers/i965/brw_wm_glsl.c b/src/gallium/drivers/i965/brw_wm_glsl.c new file mode 100644 index 0000000..3b3afc3 --- /dev/null +++ b/src/gallium/drivers/i965/brw_wm_glsl.c @@ -0,0 +1,2032 @@ +#include "util/u_math.h" + + +#include "brw_context.h" +#include "brw_eu.h" +#include "brw_wm.h" + + +static struct brw_reg get_dst_reg(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst, + GLuint component); + + +static void +reclaim_temps(struct brw_wm_compile *c); + + +/** Mark GRF register as used. */ +static void +prealloc_grf(struct brw_wm_compile *c, int r) +{ + c->used_grf[r] = GL_TRUE; +} + + +/** Mark given GRF register as not in use. */ +static void +release_grf(struct brw_wm_compile *c, int r) +{ + /*assert(c->used_grf[r]);*/ + c->used_grf[r] = GL_FALSE; + c->first_free_grf = MIN2(c->first_free_grf, r); +} + + +/** Return index of a free GRF, mark it as used. */ +static int +alloc_grf(struct brw_wm_compile *c) +{ + GLuint r; + for (r = c->first_free_grf; r < BRW_WM_MAX_GRF; r++) { + if (!c->used_grf[r]) { + c->used_grf[r] = GL_TRUE; + c->first_free_grf = r + 1; /* a guess */ + return r; + } + } + + /* no free temps, try to reclaim some */ + reclaim_temps(c); + c->first_free_grf = 0; + + /* try alloc again */ + for (r = c->first_free_grf; r < BRW_WM_MAX_GRF; r++) { + if (!c->used_grf[r]) { + c->used_grf[r] = GL_TRUE; + c->first_free_grf = r + 1; /* a guess */ + return r; + } + } + + for (r = 0; r < BRW_WM_MAX_GRF; r++) { + assert(c->used_grf[r]); + } + + /* really, no free GRF regs found */ + if (!c->out_of_regs) { + /* print warning once per compilation */ + debug_printf("%s: ran out of registers for fragment program", __FUNCTION__); + c->out_of_regs = GL_TRUE; + } + + return -1; +} + + +/** Return number of GRF registers used */ +static int +num_grf_used(const struct brw_wm_compile *c) +{ + int r; + for (r = BRW_WM_MAX_GRF - 1; r >= 0; r--) + if (c->used_grf[r]) + return r + 1; + return 0; +} + + + +/** + * Record the mapping of a Mesa register to a hardware register. + */ +static void set_reg(struct brw_wm_compile *c, int file, int index, + int component, struct brw_reg reg) +{ + c->wm_regs[file][index][component].reg = reg; + c->wm_regs[file][index][component].inited = GL_TRUE; +} + +static struct brw_reg alloc_tmp(struct brw_wm_compile *c) +{ + struct brw_reg reg; + + /* if we need to allocate another temp, grow the tmp_regs[] array */ + if (c->tmp_index == c->tmp_max) { + int r = alloc_grf(c); + if (r < 0) { + /*printf("Out of temps in %s\n", __FUNCTION__);*/ + r = 50; /* XXX random register! */ + } + c->tmp_regs[ c->tmp_max++ ] = r; + } + + /* form the GRF register */ + reg = brw_vec8_grf(c->tmp_regs[ c->tmp_index++ ], 0); + /*printf("alloc_temp %d\n", reg.nr);*/ + assert(reg.nr < BRW_WM_MAX_GRF); + return reg; + +} + +/** + * Save current temp register info. + * There must be a matching call to release_tmps(). + */ +static int mark_tmps(struct brw_wm_compile *c) +{ + return c->tmp_index; +} + +static struct brw_reg lookup_tmp( struct brw_wm_compile *c, int index ) +{ + return brw_vec8_grf( c->tmp_regs[ index ], 0 ); +} + +static void release_tmps(struct brw_wm_compile *c, int mark) +{ + c->tmp_index = mark; +} + +/** + * Convert Mesa src register to brw register. + * + * Since we're running in SOA mode each Mesa register corresponds to four + * hardware registers. We allocate the hardware registers as needed here. + * + * \param file register file, one of PROGRAM_x + * \param index register number + * \param component src component (X=0, Y=1, Z=2, W=3) + * \param nr not used?!? + * \param neg negate value? + * \param abs take absolute value? + */ +static struct brw_reg +get_reg(struct brw_wm_compile *c, int file, int index, int component, + int nr, GLuint neg, GLuint abs) +{ + struct brw_reg reg; + switch (file) { + case TGSI_FILE_NULL: + return brw_null_reg(); + + case TGSI_FILE_CONSTANT: + case TGSI_FILE_TEMPORARY: + case TGSI_FILE_INPUT: + case TGSI_FILE_OUTPUT: + case BRW_FILE_PAYLOAD: + break; + + default: + debug_printf("%s: Unexpected file type\n", __FUNCTION__); + return brw_null_reg(); + } + + assert(index < 256); + assert(component < 4); + + /* see if we've already allocated a HW register for this Mesa register */ + if (c->wm_regs[file][index][component].inited) { + /* yes, re-use */ + reg = c->wm_regs[file][index][component].reg; + } + else { + /* no, allocate new register */ + int grf = alloc_grf(c); + /*printf("alloc grf %d for reg %d:%d.%d\n", grf, file, index, component);*/ + if (grf < 0) { + /* totally out of temps */ + grf = 51; /* XXX random register! */ + } + + reg = brw_vec8_grf(grf, 0); + /*printf("Alloc new grf %d for %d.%d\n", reg.nr, index, component);*/ + + set_reg(c, file, index, component, reg); + } + + if (neg & (1 << component)) { + reg = negate(reg); + } + if (abs) + reg = brw_abs(reg); + return reg; +} + + + + +/** + * Find first/last instruction that references each temporary register. + */ +GLboolean +_mesa_find_temp_intervals(const struct prog_instruction *instructions, + GLuint numInstructions, + GLint intBegin[MAX_PROGRAM_TEMPS], + GLint intEnd[MAX_PROGRAM_TEMPS]) +{ + struct loop_info + { + GLuint Start, End; /**< Start, end instructions of loop */ + }; + struct loop_info loopStack[MAX_LOOP_NESTING]; + GLuint loopStackDepth = 0; + GLuint i; + + for (i = 0; i < MAX_PROGRAM_TEMPS; i++){ + intBegin[i] = intEnd[i] = -1; + } + + /* Scan instructions looking for temporary registers */ + for (i = 0; i < numInstructions; i++) { + const struct prog_instruction *inst = instructions + i; + if (inst->Opcode == OPCODE_BGNLOOP) { + loopStack[loopStackDepth].Start = i; + loopStack[loopStackDepth].End = inst->BranchTarget; + loopStackDepth++; + } + else if (inst->Opcode == OPCODE_ENDLOOP) { + loopStackDepth--; + } + else if (inst->Opcode == OPCODE_CAL) { + return GL_FALSE; + } + else { + const GLuint numSrc = 3; + GLuint j; + for (j = 0; j < numSrc; j++) { + if (inst->SrcReg[j].File == PROGRAM_TEMPORARY) { + const GLuint index = inst->SrcReg[j].Index; + if (inst->SrcReg[j].RelAddr) + return GL_FALSE; + update_interval(intBegin, intEnd, index, i); + if (loopStackDepth > 0) { + /* extend temp register's interval to end of loop */ + GLuint loopEnd = loopStack[loopStackDepth - 1].End; + update_interval(intBegin, intEnd, index, loopEnd); + } + } + } + if (inst->DstReg.File == PROGRAM_TEMPORARY) { + const GLuint index = inst->DstReg.Index; + if (inst->DstReg.RelAddr) + return GL_FALSE; + update_interval(intBegin, intEnd, index, i); + if (loopStackDepth > 0) { + /* extend temp register's interval to end of loop */ + GLuint loopEnd = loopStack[loopStackDepth - 1].End; + update_interval(intBegin, intEnd, index, loopEnd); + } + } + } + } + + return GL_TRUE; +} + + +/** + * This is called if we run out of GRF registers. Examine the live intervals + * of temp regs in the program and free those which won't be used again. + */ +static void +reclaim_temps(struct brw_wm_compile *c) +{ + GLint intBegin[BRW_WM_MAX_TEMPS]; + GLint intEnd[BRW_WM_MAX_TEMPS]; + int index; + + /*printf("Reclaim temps:\n");*/ + + _mesa_find_temp_intervals(c->fp_instructions, c->nr_fp_insns, + intBegin, intEnd); + + for (index = 0; index < BRW_WM_MAX_TEMPS; index++) { + if (intEnd[index] != -1 && intEnd[index] < c->cur_inst) { + /* program temp[i] can be freed */ + int component; + /*printf(" temp[%d] is dead\n", index);*/ + for (component = 0; component < 4; component++) { + if (c->wm_regs[TGSI_FILE_TEMPORARY][index][component].inited) { + int r = c->wm_regs[TGSI_FILE_TEMPORARY][index][component].reg.nr; + release_grf(c, r); + /* + printf(" Reclaim temp %d, reg %d at inst %d\n", + index, r, c->cur_inst); + */ + c->wm_regs[TGSI_FILE_TEMPORARY][index][component].inited = GL_FALSE; + } + } + } + } +} + + + + +/** + * Preallocate registers. This sets up the Mesa to hardware register + * mapping for certain registers, such as constants (uniforms/state vars) + * and shader inputs. + */ +static void prealloc_reg(struct brw_wm_compile *c) +{ + int i, j; + struct brw_reg reg; + int urb_read_length = 0; + GLuint inputs = FRAG_BIT_WPOS | c->fp_interp_emitted; + GLuint reg_index = 0; + + memset(c->used_grf, GL_FALSE, sizeof(c->used_grf)); + c->first_free_grf = 0; + + for (i = 0; i < 4; i++) { + if (i < c->key.nr_depth_regs) + reg = brw_vec8_grf(i * 2, 0); + else + reg = brw_vec8_grf(0, 0); + set_reg(c, TGSI_FILE_PAYLOAD, PAYLOAD_DEPTH, i, reg); + } + reg_index += 2 * c->key.nr_depth_regs; + + /* constants */ + { + const GLuint nr_params = c->fp->program.Base.Parameters->NumParameters; + const GLuint nr_temps = c->fp->program.Base.NumTemporaries; + + /* use a real constant buffer, or just use a section of the GRF? */ + /* XXX this heuristic may need adjustment... */ + if ((nr_params + nr_temps) * 4 + reg_index > 80) + c->fp->use_const_buffer = GL_TRUE; + else + c->fp->use_const_buffer = GL_FALSE; + /*printf("WM use_const_buffer = %d\n", c->fp->use_const_buffer);*/ + + if (c->fp->use_const_buffer) { + /* We'll use a real constant buffer and fetch constants from + * it with a dataport read message. + */ + + /* number of float constants in CURBE */ + c->prog_data.nr_params = 0; + } + else { + const struct gl_program_parameter_list *plist = + c->fp->program.Base.Parameters; + int index = 0; + + /* number of float constants in CURBE */ + c->prog_data.nr_params = 4 * nr_params; + + /* loop over program constants (float[4]) */ + for (i = 0; i < nr_params; i++) { + /* loop over XYZW channels */ + for (j = 0; j < 4; j++, index++) { + reg = brw_vec1_grf(reg_index + index / 8, index % 8); + /* Save pointer to parameter/constant value. + * Constants will be copied in prepare_constant_buffer() + */ + c->prog_data.param[index] = &plist->ParameterValues[i][j]; + set_reg(c, TGSI_FILE_STATE_VAR, i, j, reg); + } + } + /* number of constant regs used (each reg is float[8]) */ + c->nr_creg = 2 * ((4 * nr_params + 15) / 16); + reg_index += c->nr_creg; + } + } + + /* fragment shader inputs */ + for (i = 0; i < VERT_RESULT_MAX; i++) { + int fp_input; + + if (i >= VERT_RESULT_VAR0) + fp_input = i - VERT_RESULT_VAR0 + FRAG_ATTRIB_VAR0; + else if (i <= VERT_RESULT_TEX7) + fp_input = i; + else + fp_input = -1; + + if (fp_input >= 0 && inputs & (1 << fp_input)) { + urb_read_length = reg_index; + reg = brw_vec8_grf(reg_index, 0); + for (j = 0; j < 4; j++) + set_reg(c, TGSI_FILE_PAYLOAD, fp_input, j, reg); + } + if (c->key.nr_vp_outputs > i) { + reg_index += 2; + } + } + + c->prog_data.first_curbe_grf = c->key.nr_depth_regs * 2; + c->prog_data.urb_read_length = urb_read_length; + c->prog_data.curb_read_length = c->nr_creg; + c->emit_mask_reg = brw_uw1_reg(BRW_GENERAL_REGISTER_FILE, reg_index, 0); + reg_index++; + c->stack = brw_uw16_reg(BRW_GENERAL_REGISTER_FILE, reg_index, 0); + reg_index += 2; + + /* mark GRF regs [0..reg_index-1] as in-use */ + for (i = 0; i < reg_index; i++) + prealloc_grf(c, i); + + /* Don't use GRF 126, 127. Using them seems to lead to GPU lock-ups */ + prealloc_grf(c, 126); + prealloc_grf(c, 127); + + for (i = 0; i < c->nr_fp_insns; i++) { + const struct brw_fp_instruction *inst = &c->fp_instructions[i]; + struct brw_reg dst[4]; + + switch (inst->Opcode) { + case OPCODE_TEX: + case OPCODE_TXB: + /* Allocate the channels of texture results contiguously, + * since they are written out that way by the sampler unit. + */ + for (j = 0; j < 4; j++) { + dst[j] = get_dst_reg(c, inst, j); + if (j != 0) + assert(dst[j].nr == dst[j - 1].nr + 1); + } + break; + default: + break; + } + } + + /* An instruction may reference up to three constants. + * They'll be found in these registers. + * XXX alloc these on demand! + */ + if (c->fp->use_const_buffer) { + for (i = 0; i < 3; i++) { + c->current_const[i].index = -1; + c->current_const[i].reg = brw_vec8_grf(alloc_grf(c), 0); + } + } +#if 0 + printf("USE CONST BUFFER? %d\n", c->fp->use_const_buffer); + printf("AFTER PRE_ALLOC, reg_index = %d\n", reg_index); +#endif +} + + +/** + * Check if any of the instruction's src registers are constants, uniforms, + * or statevars. If so, fetch any constants that we don't already have in + * the three GRF slots. + */ +static void fetch_constants(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_compile *p = &c->func; + GLuint i; + + /* loop over instruction src regs */ + for (i = 0; i < 3; i++) { + const struct prog_src_register *src = &inst->SrcReg[i]; + if (src->File == TGSI_FILE_IMMEDIATE || + src->File == TGSI_FILE_CONSTANT) { + c->current_const[i].index = src->Index; + +#if 0 + printf(" fetch const[%d] for arg %d into reg %d\n", + src->Index, i, c->current_const[i].reg.nr); +#endif + + /* need to fetch the constant now */ + brw_dp_READ_4(p, + c->current_const[i].reg, /* writeback dest */ + src->RelAddr, /* relative indexing? */ + 16 * src->Index, /* byte offset */ + SURF_INDEX_FRAG_CONST_BUFFER/* binding table index */ + ); + } + } +} + + +/** + * Convert Mesa dst register to brw register. + */ +static struct brw_reg get_dst_reg(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst, + GLuint component) +{ + const int nr = 1; + return get_reg(c, inst->DstReg.File, inst->DstReg.Index, component, nr, + 0, 0); +} + + +static struct brw_reg +get_src_reg_const(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst, + GLuint srcRegIndex, GLuint component) +{ + /* We should have already fetched the constant from the constant + * buffer in fetch_constants(). Now we just have to return a + * register description that extracts the needed component and + * smears it across all eight vector components. + */ + const struct prog_src_register *src = &inst->SrcReg[srcRegIndex]; + struct brw_reg const_reg; + + assert(component < 4); + assert(srcRegIndex < 3); + assert(c->current_const[srcRegIndex].index != -1); + const_reg = c->current_const[srcRegIndex].reg; + + /* extract desired float from the const_reg, and smear */ + const_reg = stride(const_reg, 0, 1, 0); + const_reg.subnr = component * 4; + + if (src->Negate) + const_reg = negate(const_reg); + if (src->Abs) + const_reg = brw_abs(const_reg); + +#if 0 + printf(" form const[%d].%d for arg %d, reg %d\n", + c->current_const[srcRegIndex].index, + component, + srcRegIndex, + const_reg.nr); +#endif + + return const_reg; +} + + +/** + * Convert Mesa src register to brw register. + */ +static struct brw_reg get_src_reg(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst, + GLuint srcRegIndex, GLuint channel) +{ + const struct prog_src_register *src = &inst->SrcReg[srcRegIndex]; + const GLuint nr = 1; + const GLuint component = BRW_GET_SWZ(src->Swizzle, channel); + + /* Extended swizzle terms */ + if (component == SWIZZLE_ZERO) { + return brw_imm_f(0.0F); + } + else if (component == SWIZZLE_ONE) { + return brw_imm_f(1.0F); + } + + if (c->fp->use_const_buffer && + (src->File == TGSI_FILE_STATE_VAR || + src->File == TGSI_FILE_CONSTANT || + src->File == TGSI_FILE_UNIFORM)) { + return get_src_reg_const(c, inst, srcRegIndex, component); + } + else { + /* other type of source register */ + return get_reg(c, src->File, src->Index, component, nr, + src->Negate, src->Abs); + } +} + + +/** + * Same as \sa get_src_reg() but if the register is a immediate, emit + * a brw_reg encoding the immediate. + * Note that a brw instruction only allows one src operand to be a immediate. + * For instructions with more than one operand, only the second can be a + * immediate. This means that we treat some immediates as constants + * (which why TGSI_FILE_IMMEDIATE is checked in fetch_constants()). + * + */ +static struct brw_reg get_src_reg_imm(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst, + GLuint srcRegIndex, GLuint channel) +{ + const struct prog_src_register *src = &inst->SrcReg[srcRegIndex]; + if (src->File == TGSI_FILE_IMMEDIATE) { + /* an immediate */ + const int component = BRW_GET_SWZ(src->Swizzle, channel); + const GLfloat *param = + c->fp->program.Base.Parameters->ParameterValues[src->Index]; + GLfloat value = param[component]; + if (src->Negate) + value = -value; + if (src->Abs) + value = FABSF(value); +#if 0 + printf(" form immed value %f for chan %d\n", value, channel); +#endif + return brw_imm_f(value); + } + else { + return get_src_reg(c, inst, srcRegIndex, channel); + } +} + + +/** + * Subroutines are minimal support for resusable instruction sequences. + * They are implemented as simply as possible to minimise overhead: there + * is no explicit support for communication between the caller and callee + * other than saving the return address in a temporary register, nor is + * there any automatic local storage. This implies that great care is + * required before attempting reentrancy or any kind of nested + * subroutine invocations. + */ +static void invoke_subroutine( struct brw_wm_compile *c, + enum _subroutine subroutine, + void (*emit)( struct brw_wm_compile * ) ) +{ + struct brw_compile *p = &c->func; + + assert( subroutine < BRW_WM_MAX_SUBROUTINE ); + + if( c->subroutines[ subroutine ] ) { + /* subroutine previously emitted: reuse existing instructions */ + + int mark = mark_tmps( c ); + struct brw_reg return_address = retype( alloc_tmp( c ), + BRW_REGISTER_TYPE_UD ); + int here = p->nr_insn; + + brw_push_insn_state(p); + brw_set_mask_control(p, BRW_MASK_DISABLE); + brw_ADD( p, return_address, brw_ip_reg(), brw_imm_ud( 2 << 4 ) ); + + brw_ADD( p, brw_ip_reg(), brw_ip_reg(), + brw_imm_d( ( c->subroutines[ subroutine ] - + here - 1 ) << 4 ) ); + brw_pop_insn_state(p); + + release_tmps( c, mark ); + } else { + /* previously unused subroutine: emit, and mark for later reuse */ + + int mark = mark_tmps( c ); + struct brw_reg return_address = retype( alloc_tmp( c ), + BRW_REGISTER_TYPE_UD ); + struct brw_instruction *calc; + int base = p->nr_insn; + + brw_push_insn_state(p); + brw_set_mask_control(p, BRW_MASK_DISABLE); + calc = brw_ADD( p, return_address, brw_ip_reg(), brw_imm_ud( 0 ) ); + brw_pop_insn_state(p); + + c->subroutines[ subroutine ] = p->nr_insn; + + emit( c ); + + brw_push_insn_state(p); + brw_set_mask_control(p, BRW_MASK_DISABLE); + brw_MOV( p, brw_ip_reg(), return_address ); + brw_pop_insn_state(p); + + brw_set_src1( calc, brw_imm_ud( ( p->nr_insn - base ) << 4 ) ); + + release_tmps( c, mark ); + } +} + +static void emit_trunc( struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + int i; + struct brw_compile *p = &c->func; + GLuint mask = inst->DstReg.WriteMask; + brw_set_saturate(p, inst->SaturateMode != SATURATE_OFF); + for (i = 0; i < 4; i++) { + if (mask & (1<func; + GLuint mask = inst->DstReg.WriteMask; + brw_set_saturate(p, inst->SaturateMode != SATURATE_OFF); + for (i = 0; i < 4; i++) { + if (mask & (1<func; + GLuint mask = inst->DstReg.WriteMask; + + dst0 = get_dst_reg(c, inst, 0); + dst1 = get_dst_reg(c, inst, 1); + /* Calculate pixel centers by adding 1 or 0 to each of the + * micro-tile coordinates passed in r1. + */ + if (mask & WRITEMASK_X) { + brw_ADD(p, + vec8(retype(dst0, BRW_REGISTER_TYPE_UW)), + stride(suboffset(r1_uw, 4), 2, 4, 0), + brw_imm_v(0x10101010)); + } + + if (mask & WRITEMASK_Y) { + brw_ADD(p, + vec8(retype(dst1, BRW_REGISTER_TYPE_UW)), + stride(suboffset(r1_uw, 5), 2, 4, 0), + brw_imm_v(0x11001100)); + } +} + +static void emit_delta_xy(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_reg r1 = brw_vec1_grf(1, 0); + struct brw_reg dst0, dst1, src0, src1; + struct brw_compile *p = &c->func; + GLuint mask = inst->DstReg.WriteMask; + + dst0 = get_dst_reg(c, inst, 0); + dst1 = get_dst_reg(c, inst, 1); + src0 = get_src_reg(c, inst, 0, 0); + src1 = get_src_reg(c, inst, 0, 1); + /* Calc delta X,Y by subtracting origin in r1 from the pixel + * centers. + */ + if (mask & WRITEMASK_X) { + brw_ADD(p, + dst0, + retype(src0, BRW_REGISTER_TYPE_UW), + negate(r1)); + } + + if (mask & WRITEMASK_Y) { + brw_ADD(p, + dst1, + retype(src1, BRW_REGISTER_TYPE_UW), + negate(suboffset(r1,1))); + + } +} + +static void fire_fb_write( struct brw_wm_compile *c, + GLuint base_reg, + GLuint nr, + GLuint target, + GLuint eot) +{ + struct brw_compile *p = &c->func; + /* Pass through control information: + */ + /* mov (8) m1.0<1>:ud r1.0<8;8,1>:ud { Align1 NoMask } */ + { + brw_push_insn_state(p); + brw_set_mask_control(p, BRW_MASK_DISABLE); /* ? */ + brw_MOV(p, + brw_message_reg(base_reg + 1), + brw_vec8_grf(1, 0)); + brw_pop_insn_state(p); + } + /* Send framebuffer write message: */ + brw_fb_WRITE(p, + retype(vec8(brw_null_reg()), BRW_REGISTER_TYPE_UW), + base_reg, + retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW), + target, + nr, + 0, + eot); +} + +static void emit_fb_write(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_compile *p = &c->func; + int nr = 2; + int channel; + GLuint target, eot; + struct brw_reg src0; + + /* Reserve a space for AA - may not be needed: + */ + if (c->key.aa_dest_stencil_reg) + nr += 1; + + brw_push_insn_state(p); + for (channel = 0; channel < 4; channel++) { + src0 = get_src_reg(c, inst, 0, channel); + /* mov (8) m2.0<1>:ud r28.0<8;8,1>:ud { Align1 } */ + /* mov (8) m6.0<1>:ud r29.0<8;8,1>:ud { Align1 SecHalf } */ + brw_MOV(p, brw_message_reg(nr + channel), src0); + } + /* skip over the regs populated above: */ + nr += 8; + brw_pop_insn_state(p); + + if (c->key.source_depth_to_render_target) { + if (c->key.computes_depth) { + src0 = get_src_reg(c, inst, 2, 2); + brw_MOV(p, brw_message_reg(nr), src0); + } + else { + src0 = get_src_reg(c, inst, 1, 1); + brw_MOV(p, brw_message_reg(nr), src0); + } + + nr += 2; + } + + if (c->key.dest_depth_reg) { + const GLuint comp = c->key.dest_depth_reg / 2; + const GLuint off = c->key.dest_depth_reg % 2; + + if (off != 0) { + /* XXX this code needs review/testing */ + struct brw_reg arg1_0 = get_src_reg(c, inst, 1, comp); + struct brw_reg arg1_1 = get_src_reg(c, inst, 1, comp+1); + + brw_push_insn_state(p); + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + + brw_MOV(p, brw_message_reg(nr), offset(arg1_0, 1)); + /* 2nd half? */ + brw_MOV(p, brw_message_reg(nr+1), arg1_1); + brw_pop_insn_state(p); + } + else + { + struct brw_reg src = get_src_reg(c, inst, 1, 1); + brw_MOV(p, brw_message_reg(nr), src); + } + nr += 2; + } + + target = inst->Aux >> 1; + eot = inst->Aux & 1; + fire_fb_write(c, 0, nr, target, eot); +} + +static void emit_pixel_w( struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_compile *p = &c->func; + GLuint mask = inst->DstReg.WriteMask; + if (mask & WRITEMASK_W) { + struct brw_reg dst, src0, delta0, delta1; + struct brw_reg interp3; + + dst = get_dst_reg(c, inst, 3); + src0 = get_src_reg(c, inst, 0, 0); + delta0 = get_src_reg(c, inst, 1, 0); + delta1 = get_src_reg(c, inst, 1, 1); + + interp3 = brw_vec1_grf(src0.nr+1, 4); + /* Calc 1/w - just linterp wpos[3] optimized by putting the + * result straight into a message reg. + */ + brw_LINE(p, brw_null_reg(), interp3, delta0); + brw_MAC(p, brw_message_reg(2), suboffset(interp3, 1), delta1); + + /* Calc w */ + brw_math_16( p, dst, + BRW_MATH_FUNCTION_INV, + BRW_MATH_SATURATE_NONE, + 2, brw_null_reg(), + BRW_MATH_PRECISION_FULL); + } +} + +static void emit_linterp(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_compile *p = &c->func; + GLuint mask = inst->DstReg.WriteMask; + struct brw_reg interp[4]; + struct brw_reg dst, delta0, delta1; + struct brw_reg src0; + GLuint nr, i; + + src0 = get_src_reg(c, inst, 0, 0); + delta0 = get_src_reg(c, inst, 1, 0); + delta1 = get_src_reg(c, inst, 1, 1); + nr = src0.nr; + + interp[0] = brw_vec1_grf(nr, 0); + interp[1] = brw_vec1_grf(nr, 4); + interp[2] = brw_vec1_grf(nr+1, 0); + interp[3] = brw_vec1_grf(nr+1, 4); + + for(i = 0; i < 4; i++ ) { + if (mask & (1<func; + GLuint mask = inst->DstReg.WriteMask; + + struct brw_reg interp[4]; + struct brw_reg dst, src0; + GLuint nr, i; + + src0 = get_src_reg(c, inst, 0, 0); + nr = src0.nr; + + interp[0] = brw_vec1_grf(nr, 0); + interp[1] = brw_vec1_grf(nr, 4); + interp[2] = brw_vec1_grf(nr+1, 0); + interp[3] = brw_vec1_grf(nr+1, 4); + + for(i = 0; i < 4; i++ ) { + if (mask & (1<func; + GLuint mask = inst->DstReg.WriteMask; + + struct brw_reg interp[4]; + struct brw_reg dst, delta0, delta1; + struct brw_reg src0, w; + GLuint nr, i; + + src0 = get_src_reg(c, inst, 0, 0); + delta0 = get_src_reg(c, inst, 1, 0); + delta1 = get_src_reg(c, inst, 1, 1); + w = get_src_reg(c, inst, 2, 3); + nr = src0.nr; + + interp[0] = brw_vec1_grf(nr, 0); + interp[1] = brw_vec1_grf(nr, 4); + interp[2] = brw_vec1_grf(nr+1, 0); + interp[3] = brw_vec1_grf(nr+1, 4); + + for(i = 0; i < 4; i++ ) { + if (mask & (1<func; + struct brw_reg r1_6ud = retype(brw_vec1_grf(1, 6), BRW_REGISTER_TYPE_UD); + struct brw_reg dst; + GLuint mask = inst->DstReg.WriteMask; + int i; + + for (i = 0; i < 4; i++) { + if (mask & (1<func; + GLuint mask = inst->DstReg.WriteMask; + for (i = 0; i < 4; i++) { + GLuint i2 = (i+2)%3; + GLuint i1 = (i+1)%3; + if (mask & (1<SaturateMode != SATURATE_OFF); + brw_MAC(p, dst, src0, src1); + brw_set_saturate(p, 0); + } + } + brw_set_saturate(p, 0); +} + +static void emit_dp3(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_reg src0[3], src1[3], dst; + int i; + struct brw_compile *p = &c->func; + GLuint mask = inst->DstReg.WriteMask; + int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1; + + if (!(mask & WRITEMASK_XYZW)) + return; + + assert(is_power_of_two(mask & WRITEMASK_XYZW)); + + for (i = 0; i < 3; i++) { + src0[i] = get_src_reg(c, inst, 0, i); + src1[i] = get_src_reg_imm(c, inst, 1, i); + } + + dst = get_dst_reg(c, inst, dst_chan); + brw_MUL(p, brw_null_reg(), src0[0], src1[0]); + brw_MAC(p, brw_null_reg(), src0[1], src1[1]); + brw_set_saturate(p, (inst->SaturateMode != SATURATE_OFF) ? 1 : 0); + brw_MAC(p, dst, src0[2], src1[2]); + brw_set_saturate(p, 0); +} + +static void emit_dp4(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_reg src0[4], src1[4], dst; + int i; + struct brw_compile *p = &c->func; + GLuint mask = inst->DstReg.WriteMask; + int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1; + + if (!(mask & WRITEMASK_XYZW)) + return; + + assert(is_power_of_two(mask & WRITEMASK_XYZW)); + + for (i = 0; i < 4; i++) { + src0[i] = get_src_reg(c, inst, 0, i); + src1[i] = get_src_reg_imm(c, inst, 1, i); + } + dst = get_dst_reg(c, inst, dst_chan); + brw_MUL(p, brw_null_reg(), src0[0], src1[0]); + brw_MAC(p, brw_null_reg(), src0[1], src1[1]); + brw_MAC(p, brw_null_reg(), src0[2], src1[2]); + brw_set_saturate(p, (inst->SaturateMode != SATURATE_OFF) ? 1 : 0); + brw_MAC(p, dst, src0[3], src1[3]); + brw_set_saturate(p, 0); +} + +static void emit_dph(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_reg src0[4], src1[4], dst; + int i; + struct brw_compile *p = &c->func; + GLuint mask = inst->DstReg.WriteMask; + int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1; + + if (!(mask & WRITEMASK_XYZW)) + return; + + assert(is_power_of_two(mask & WRITEMASK_XYZW)); + + for (i = 0; i < 4; i++) { + src0[i] = get_src_reg(c, inst, 0, i); + src1[i] = get_src_reg_imm(c, inst, 1, i); + } + dst = get_dst_reg(c, inst, dst_chan); + brw_MUL(p, brw_null_reg(), src0[0], src1[0]); + brw_MAC(p, brw_null_reg(), src0[1], src1[1]); + brw_MAC(p, dst, src0[2], src1[2]); + brw_set_saturate(p, (inst->SaturateMode != SATURATE_OFF) ? 1 : 0); + brw_ADD(p, dst, dst, src1[3]); + brw_set_saturate(p, 0); +} + +/** + * Emit a scalar instruction, like RCP, RSQ, LOG, EXP. + * Note that the result of the function is smeared across the dest + * register's X, Y, Z and W channels (subject to writemasking of course). + */ +static void emit_math1(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst, GLuint func) +{ + struct brw_compile *p = &c->func; + struct brw_reg src0, dst; + GLuint mask = inst->DstReg.WriteMask; + int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1; + + if (!(mask & WRITEMASK_XYZW)) + return; + + assert(is_power_of_two(mask & WRITEMASK_XYZW)); + + /* Get first component of source register */ + dst = get_dst_reg(c, inst, dst_chan); + src0 = get_src_reg(c, inst, 0, 0); + + brw_MOV(p, brw_message_reg(2), src0); + brw_math(p, + dst, + func, + (inst->SaturateMode != SATURATE_OFF) ? BRW_MATH_SATURATE_SATURATE : BRW_MATH_SATURATE_NONE, + 2, + brw_null_reg(), + BRW_MATH_DATA_VECTOR, + BRW_MATH_PRECISION_FULL); +} + +static void emit_rcp(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + emit_math1(c, inst, BRW_MATH_FUNCTION_INV); +} + +static void emit_rsq(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + emit_math1(c, inst, BRW_MATH_FUNCTION_RSQ); +} + +static void emit_sin(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + emit_math1(c, inst, BRW_MATH_FUNCTION_SIN); +} + +static void emit_cos(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + emit_math1(c, inst, BRW_MATH_FUNCTION_COS); +} + +static void emit_ex2(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + emit_math1(c, inst, BRW_MATH_FUNCTION_EXP); +} + +static void emit_lg2(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + emit_math1(c, inst, BRW_MATH_FUNCTION_LOG); +} + +static void emit_add(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_compile *p = &c->func; + struct brw_reg src0, src1, dst; + GLuint mask = inst->DstReg.WriteMask; + int i; + brw_set_saturate(p, (inst->SaturateMode != SATURATE_OFF) ? 1 : 0); + for (i = 0 ; i < 4; i++) { + if (mask & (1<func; + struct brw_reg src0, addr_reg; + brw_set_saturate(p, (inst->SaturateMode != SATURATE_OFF) ? 1 : 0); + addr_reg = brw_uw8_reg(BRW_ARCHITECTURE_REGISTER_FILE, + BRW_ARF_ADDRESS, 0); + src0 = get_src_reg(c, inst, 0, 0); /* channel 0 */ + brw_MOV(p, addr_reg, src0); + brw_set_saturate(p, 0); +} + + +static void emit_mul(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_compile *p = &c->func; + struct brw_reg src0, src1, dst; + GLuint mask = inst->DstReg.WriteMask; + int i; + brw_set_saturate(p, (inst->SaturateMode != SATURATE_OFF) ? 1 : 0); + for (i = 0 ; i < 4; i++) { + if (mask & (1<func; + struct brw_reg src0, dst; + GLuint mask = inst->DstReg.WriteMask; + int i; + brw_set_saturate(p, (inst->SaturateMode != SATURATE_OFF) ? 1 : 0); + for (i = 0 ; i < 4; i++) { + if (mask & (1<SaturateMode != SATURATE_OFF) + brw_set_saturate(p, 0); +} + +static void emit_flr(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_compile *p = &c->func; + struct brw_reg src0, dst; + GLuint mask = inst->DstReg.WriteMask; + int i; + brw_set_saturate(p, (inst->SaturateMode != SATURATE_OFF) ? 1 : 0); + for (i = 0 ; i < 4; i++) { + if (mask & (1<func; + const GLuint mask = inst->DstReg.WriteMask; + const int mark = mark_tmps(c); + int i; + brw_push_insn_state(p); + for (i = 0; i < 4; i++) { + if (mask & (1<SaturateMode != SATURATE_OFF) ? 1 : 0); + brw_MOV(p, dst, src0); + brw_set_saturate(p, 0); + + if (inst->Opcode == OPCODE_MIN) + brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_L, src1, src0); + else + brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_G, src1, src0); + + brw_set_saturate(p, (inst->SaturateMode != SATURATE_OFF) ? 1 : 0); + brw_set_predicate_control(p, BRW_PREDICATE_NORMAL); + brw_MOV(p, dst, src1); + brw_set_saturate(p, 0); + brw_set_predicate_control_flag_value(p, 0xff); + if (use_temp) + brw_MOV(p, real_dst, dst); + } + } + brw_pop_insn_state(p); + release_tmps(c, mark); +} + +static void emit_pow(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_compile *p = &c->func; + struct brw_reg dst, src0, src1; + GLuint mask = inst->DstReg.WriteMask; + int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1; + + if (!(mask & WRITEMASK_XYZW)) + return; + + assert(is_power_of_two(mask & WRITEMASK_XYZW)); + + dst = get_dst_reg(c, inst, dst_chan); + src0 = get_src_reg_imm(c, inst, 0, 0); + src1 = get_src_reg_imm(c, inst, 1, 0); + + brw_MOV(p, brw_message_reg(2), src0); + brw_MOV(p, brw_message_reg(3), src1); + + brw_math(p, + dst, + BRW_MATH_FUNCTION_POW, + (inst->SaturateMode != SATURATE_OFF) ? BRW_MATH_SATURATE_SATURATE : BRW_MATH_SATURATE_NONE, + 2, + brw_null_reg(), + BRW_MATH_DATA_VECTOR, + BRW_MATH_PRECISION_FULL); +} + +static void emit_lrp(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_compile *p = &c->func; + GLuint mask = inst->DstReg.WriteMask; + struct brw_reg dst, tmp1, tmp2, src0, src1, src2; + int i; + int mark = mark_tmps(c); + for (i = 0; i < 4; i++) { + if (mask & (1<SaturateMode != SATURATE_OFF) ? 1 : 0); + brw_MAC(p, dst, src0, tmp1); + brw_set_saturate(p, 0); + } + release_tmps(c, mark); + } +} + +/** + * For GLSL shaders, this KIL will be unconditional. + * It may be contained inside an IF/ENDIF structure of course. + */ +static void emit_kil(struct brw_wm_compile *c) +{ + struct brw_compile *p = &c->func; + struct brw_reg depth = retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW); + brw_push_insn_state(p); + brw_set_mask_control(p, BRW_MASK_DISABLE); + brw_NOT(p, c->emit_mask_reg, brw_mask_reg(1)); //IMASK + brw_AND(p, depth, c->emit_mask_reg, depth); + brw_pop_insn_state(p); +} + +static void emit_mad(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_compile *p = &c->func; + GLuint mask = inst->DstReg.WriteMask; + struct brw_reg dst, src0, src1, src2; + int i; + + for (i = 0; i < 4; i++) { + if (mask & (1<SaturateMode != SATURATE_OFF) ? 1 : 0); + brw_ADD(p, dst, dst, src2); + brw_set_saturate(p, 0); + } + } +} + +static void emit_sop(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst, GLuint cond) +{ + struct brw_compile *p = &c->func; + GLuint mask = inst->DstReg.WriteMask; + struct brw_reg dst, src0, src1; + int i; + + for (i = 0; i < 4; i++) { + if (mask & (1<func; + GLuint mask = inst->DstReg.WriteMask; + struct brw_reg src0[2], dst[2]; + + dst[0] = get_dst_reg(c, inst, 0); + dst[1] = get_dst_reg(c, inst, 1); + + src0[0] = get_src_reg(c, inst, 0, 0); + src0[1] = get_src_reg(c, inst, 0, 1); + + /* Calculate the pixel offset from window bottom left into destination + * X and Y channels. + */ + if (mask & WRITEMASK_X) { + /* X' = X */ + brw_MOV(p, + dst[0], + retype(src0[0], BRW_REGISTER_TYPE_W)); + } + + if (mask & WRITEMASK_Y) { + /* Y' = height - 1 - Y */ + brw_ADD(p, + dst[1], + negate(retype(src0[1], BRW_REGISTER_TYPE_W)), + brw_imm_d(c->key.drawable_height - 1)); + } +} + +/* TODO + BIAS on SIMD8 not working yet... + */ +static void emit_txb(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_compile *p = &c->func; + struct brw_reg dst[4], src[4], payload_reg; + /* Note: tex_unit was already looked up through SamplerTextures[] */ + const GLuint unit = inst->tex_unit; + GLuint i; + GLuint msg_type; + + assert(unit < BRW_MAX_TEX_UNIT); + + payload_reg = get_reg(c, TGSI_FILE_PAYLOAD, PAYLOAD_DEPTH, 0, 1, 0, 0); + + for (i = 0; i < 4; i++) + dst[i] = get_dst_reg(c, inst, i); + for (i = 0; i < 4; i++) + src[i] = get_src_reg(c, inst, 0, i); + + switch (inst->tex_target) { + case TEXTURE_1D_INDEX: + brw_MOV(p, brw_message_reg(2), src[0]); /* s coord */ + brw_MOV(p, brw_message_reg(3), brw_imm_f(0)); /* t coord */ + brw_MOV(p, brw_message_reg(4), brw_imm_f(0)); /* r coord */ + break; + case TEXTURE_2D_INDEX: + case TEXTURE_RECT_INDEX: + brw_MOV(p, brw_message_reg(2), src[0]); + brw_MOV(p, brw_message_reg(3), src[1]); + brw_MOV(p, brw_message_reg(4), brw_imm_f(0)); + break; + case TEXTURE_3D_INDEX: + case TEXTURE_CUBE_INDEX: + brw_MOV(p, brw_message_reg(2), src[0]); + brw_MOV(p, brw_message_reg(3), src[1]); + brw_MOV(p, brw_message_reg(4), src[2]); + break; + default: + /* invalid target */ + abort(); + } + brw_MOV(p, brw_message_reg(5), src[3]); /* bias */ + brw_MOV(p, brw_message_reg(6), brw_imm_f(0)); /* ref (unused?) */ + + if (BRW_IS_IGDNG(p->brw)) { + msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_BIAS_IGDNG; + } else { + /* Does it work well on SIMD8? */ + msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS; + } + + brw_SAMPLE(p, + retype(vec8(dst[0]), BRW_REGISTER_TYPE_UW), /* dest */ + 1, /* msg_reg_nr */ + retype(payload_reg, BRW_REGISTER_TYPE_UW), /* src0 */ + SURF_INDEX_TEXTURE(unit), + unit, /* sampler */ + inst->DstReg.WriteMask, /* writemask */ + msg_type, /* msg_type */ + 4, /* response_length */ + 4, /* msg_length */ + 0, /* eot */ + 1, + BRW_SAMPLER_SIMD_MODE_SIMD8); +} + + +static void emit_tex(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_compile *p = &c->func; + struct brw_reg dst[4], src[4], payload_reg; + /* Note: tex_unit was already looked up through SamplerTextures[] */ + const GLuint unit = inst->tex_unit; + GLuint msg_len; + GLuint i, nr; + GLuint emit; + GLboolean shadow = (c->key.shadowtex_mask & (1<tex_target) { + case TEXTURE_1D_INDEX: + emit = WRITEMASK_X; + nr = 1; + break; + case TEXTURE_2D_INDEX: + case TEXTURE_RECT_INDEX: + emit = WRITEMASK_XY; + nr = 2; + break; + case TEXTURE_3D_INDEX: + case TEXTURE_CUBE_INDEX: + emit = WRITEMASK_XYZ; + nr = 3; + break; + default: + /* invalid target */ + abort(); + } + msg_len = 1; + + /* move/load S, T, R coords */ + for (i = 0; i < nr; i++) { + static const GLuint swz[4] = {0,1,2,2}; + if (emit & (1<brw)) { + if (shadow) + msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_COMPARE_IGDNG; + else + msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_IGDNG; + } else { + /* Does it work for shadow on SIMD8 ? */ + msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE; + } + + brw_SAMPLE(p, + retype(vec8(dst[0]), BRW_REGISTER_TYPE_UW), /* dest */ + 1, /* msg_reg_nr */ + retype(payload_reg, BRW_REGISTER_TYPE_UW), /* src0 */ + SURF_INDEX_TEXTURE(unit), + unit, /* sampler */ + inst->DstReg.WriteMask, /* writemask */ + msg_type, /* msg_type */ + 4, /* response_length */ + shadow ? 6 : 4, /* msg_length */ + 0, /* eot */ + 1, + BRW_SAMPLER_SIMD_MODE_SIMD8); + + if (shadow) + brw_MOV(p, dst[3], brw_imm_f(1.0)); +} + + +/** + * Resolve subroutine calls after code emit is done. + */ +static void post_wm_emit( struct brw_wm_compile *c ) +{ + brw_resolve_cals(&c->func); +} + +static void +get_argument_regs(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst, + int index, + struct brw_reg *regs, + int mask) +{ + int i; + + for (i = 0; i < 4; i++) { + if (mask & (1 << i)) + regs[i] = get_src_reg(c, inst, index, i); + } +} + +static void brw_wm_emit_branching_shader(struct brw_context *brw, struct brw_wm_compile *c) +{ +#define MAX_IF_DEPTH 32 +#define MAX_LOOP_DEPTH 32 + struct brw_instruction *if_inst[MAX_IF_DEPTH], *loop_inst[MAX_LOOP_DEPTH]; + GLuint i, if_depth = 0, loop_depth = 0; + struct brw_compile *p = &c->func; + struct brw_indirect stack_index = brw_indirect(0, 0); + + c->out_of_regs = GL_FALSE; + + prealloc_reg(c); + brw_set_compression_control(p, BRW_COMPRESSION_NONE); + brw_MOV(p, get_addr_reg(stack_index), brw_address(c->stack)); + + for (i = 0; i < c->nr_fp_insns; i++) { + const struct brw_fp_instruction *inst = &c->fp_instructions[i]; + int dst_flags; + struct brw_reg args[3][4], dst[4]; + int j; + + c->cur_inst = i; + +#if 0 + debug_printf("Inst %d: ", i); + _mesa_print_instruction(inst); +#endif + + /* fetch any constants that this instruction needs */ + if (c->fp->use_const_buffer) + fetch_constants(c, inst); + + if (inst->CondUpdate) + brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ); + else + brw_set_conditionalmod(p, BRW_CONDITIONAL_NONE); + + dst_flags = inst->DstReg.WriteMask; + if (inst->SaturateMode == SATURATE_ZERO_ONE) + dst_flags |= SATURATE; + + switch (inst->Opcode) { + case WM_PIXELXY: + emit_pixel_xy(c, inst); + break; + case WM_DELTAXY: + emit_delta_xy(c, inst); + break; + case WM_PIXELW: + emit_pixel_w(c, inst); + break; + case WM_LINTERP: + emit_linterp(c, inst); + break; + case WM_PINTERP: + emit_pinterp(c, inst); + break; + case WM_CINTERP: + emit_cinterp(c, inst); + break; + case WM_WPOSXY: + emit_wpos_xy(c, inst); + break; + case WM_FB_WRITE: + emit_fb_write(c, inst); + break; + case WM_FRONTFACING: + emit_frontfacing(c, inst); + break; + case OPCODE_ADD: + emit_add(c, inst); + break; + case OPCODE_ARL: + emit_arl(c, inst); + break; + case OPCODE_FRC: + emit_frc(c, inst); + break; + case OPCODE_FLR: + emit_flr(c, inst); + break; + case OPCODE_LRP: + emit_lrp(c, inst); + break; + case OPCODE_TRUNC: + emit_trunc(c, inst); + break; + case OPCODE_MOV: + emit_mov(c, inst); + break; + case OPCODE_DP3: + emit_dp3(c, inst); + break; + case OPCODE_DP4: + emit_dp4(c, inst); + break; + case OPCODE_XPD: + emit_xpd(c, inst); + break; + case OPCODE_DPH: + emit_dph(c, inst); + break; + case OPCODE_RCP: + emit_rcp(c, inst); + break; + case OPCODE_RSQ: + emit_rsq(c, inst); + break; + case OPCODE_SIN: + emit_sin(c, inst); + break; + case OPCODE_COS: + emit_cos(c, inst); + break; + case OPCODE_EX2: + emit_ex2(c, inst); + break; + case OPCODE_LG2: + emit_lg2(c, inst); + break; + case OPCODE_MIN: + case OPCODE_MAX: + emit_min_max(c, inst); + break; + case OPCODE_DDX: + case OPCODE_DDY: + for (j = 0; j < 4; j++) { + if (inst->DstReg.WriteMask & (1 << j)) + dst[j] = get_dst_reg(c, inst, j); + else + dst[j] = brw_null_reg(); + } + get_argument_regs(c, inst, 0, args[0], WRITEMASK_XYZW); + emit_ddxy(p, dst, dst_flags, (inst->Opcode == OPCODE_DDX), + args[0]); + break; + case OPCODE_SLT: + emit_slt(c, inst); + break; + case OPCODE_SLE: + emit_sle(c, inst); + break; + case OPCODE_SGT: + emit_sgt(c, inst); + break; + case OPCODE_SGE: + emit_sge(c, inst); + break; + case OPCODE_SEQ: + emit_seq(c, inst); + break; + case OPCODE_SNE: + emit_sne(c, inst); + break; + case OPCODE_MUL: + emit_mul(c, inst); + break; + case OPCODE_POW: + emit_pow(c, inst); + break; + case OPCODE_MAD: + emit_mad(c, inst); + break; + case OPCODE_TEX: + emit_tex(c, inst); + break; + case OPCODE_TXB: + emit_txb(c, inst); + break; + case OPCODE_KIL_NV: + emit_kil(c); + break; + case OPCODE_IF: + assert(if_depth < MAX_IF_DEPTH); + if_inst[if_depth++] = brw_IF(p, BRW_EXECUTE_8); + break; + case OPCODE_ELSE: + if_inst[if_depth-1] = brw_ELSE(p, if_inst[if_depth-1]); + break; + case OPCODE_ENDIF: + assert(if_depth > 0); + brw_ENDIF(p, if_inst[--if_depth]); + break; + case OPCODE_BGNSUB: + brw_save_label(p, inst->Comment, p->nr_insn); + break; + case OPCODE_ENDSUB: + /* no-op */ + break; + case OPCODE_CAL: + brw_push_insn_state(p); + brw_set_mask_control(p, BRW_MASK_DISABLE); + brw_set_access_mode(p, BRW_ALIGN_1); + brw_ADD(p, deref_1ud(stack_index, 0), brw_ip_reg(), brw_imm_d(3*16)); + brw_set_access_mode(p, BRW_ALIGN_16); + brw_ADD(p, get_addr_reg(stack_index), + get_addr_reg(stack_index), brw_imm_d(4)); + brw_save_call(&c->func, inst->label, p->nr_insn); + brw_ADD(p, brw_ip_reg(), brw_ip_reg(), brw_imm_d(1*16)); + brw_pop_insn_state(p); + break; + + case OPCODE_RET: + brw_push_insn_state(p); + brw_set_mask_control(p, BRW_MASK_DISABLE); + brw_ADD(p, get_addr_reg(stack_index), + get_addr_reg(stack_index), brw_imm_d(-4)); + brw_set_access_mode(p, BRW_ALIGN_1); + brw_MOV(p, brw_ip_reg(), deref_1ud(stack_index, 0)); + brw_set_access_mode(p, BRW_ALIGN_16); + brw_pop_insn_state(p); + + break; + case OPCODE_BGNLOOP: + /* XXX may need to invalidate the current_constant regs */ + loop_inst[loop_depth++] = brw_DO(p, BRW_EXECUTE_8); + break; + case OPCODE_BRK: + brw_BREAK(p); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + break; + case OPCODE_CONT: + brw_CONT(p); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + break; + case OPCODE_ENDLOOP: + { + struct brw_instruction *inst0, *inst1; + GLuint br = 1; + + if (BRW_IS_IGDNG(brw)) + br = 2; + + loop_depth--; + inst0 = inst1 = brw_WHILE(p, loop_inst[loop_depth]); + /* patch all the BREAK/CONT instructions from last BGNLOOP */ + while (inst0 > loop_inst[loop_depth]) { + inst0--; + if (inst0->header.opcode == BRW_OPCODE_BREAK) { + inst0->bits3.if_else.jump_count = br * (inst1 - inst0 + 1); + inst0->bits3.if_else.pop_count = 0; + } + else if (inst0->header.opcode == BRW_OPCODE_CONTINUE) { + inst0->bits3.if_else.jump_count = br * (inst1 - inst0); + inst0->bits3.if_else.pop_count = 0; + } + } + } + break; + default: + debug_printf("unsupported IR in fragment shader %d\n", + inst->Opcode); + } + + if (inst->CondUpdate) + brw_set_predicate_control(p, BRW_PREDICATE_NORMAL); + else + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + } + post_wm_emit(c); + + if (BRW_DEBUG & DEBUG_WM) { + debug_printf("wm-native:\n"); + brw_disasm(stderr, p->store, p->nr_insn); + } +} + +/** + * Do GPU code generation for shaders that use GLSL features such as + * flow control. Other shaders will be compiled with the + */ +void brw_wm_branching_shader_emit(struct brw_context *brw, struct brw_wm_compile *c) +{ + if (BRW_DEBUG & DEBUG_WM) { + debug_printf("%s:\n", __FUNCTION__); + } + + /* initial instruction translation/simplification */ + brw_wm_pass_fp(c); + + /* actual code generation */ + brw_wm_emit_branching_shader(brw, c); + + if (BRW_DEBUG & DEBUG_WM) { + brw_wm_print_program(c, "brw_wm_branching_shader_emit done"); + } + + c->prog_data.total_grf = num_grf_used(c); + c->prog_data.total_scratch = 0; +} diff --git a/src/gallium/drivers/i965/brw_wm_iz.c b/src/gallium/drivers/i965/brw_wm_iz.c new file mode 100644 index 0000000..6f1e9fc --- /dev/null +++ b/src/gallium/drivers/i965/brw_wm_iz.c @@ -0,0 +1,156 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#include "brw_wm.h" + + +#undef P /* prompted depth */ +#undef C /* computed */ +#undef N /* non-promoted? */ + +#define P 0 +#define C 1 +#define N 2 + +const struct { + GLuint mode:2; + GLuint sd_present:1; + GLuint sd_to_rt:1; + GLuint dd_present:1; + GLuint ds_present:1; +} wm_iz_table[IZ_BIT_MAX] = +{ + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { N, 1, 1, 0, 0 }, + { N, 0, 1, 0, 0 }, + { N, 0, 1, 0, 0 }, + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { C, 0, 1, 1, 0 }, + { C, 0, 1, 1, 0 }, + { P, 0, 0, 0, 0 }, + { N, 1, 1, 0, 0 }, + { C, 0, 1, 1, 0 }, + { C, 0, 1, 1, 0 }, + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { N, 1, 1, 0, 0 }, + { N, 0, 1, 0, 0 }, + { N, 0, 1, 0, 0 }, + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { C, 0, 1, 1, 0 }, + { C, 0, 1, 1, 0 }, + { P, 0, 0, 0, 0 }, + { N, 1, 1, 0, 0 }, + { C, 0, 1, 1, 0 }, + { C, 0, 1, 1, 0 }, + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { N, 1, 1, 0, 1 }, + { N, 0, 1, 0, 1 }, + { N, 0, 1, 0, 1 }, + { P, 0, 0, 0, 0 }, + { P, 0, 0, 0, 0 }, + { C, 0, 1, 1, 1 }, + { C, 0, 1, 1, 1 }, + { P, 0, 0, 0, 0 }, + { N, 1, 1, 0, 1 }, + { C, 0, 1, 1, 1 }, + { C, 0, 1, 1, 1 }, + { P, 0, 0, 0, 0 }, + { C, 0, 0, 0, 1 }, + { P, 0, 0, 0, 0 }, + { C, 0, 1, 0, 1 }, + { P, 0, 0, 0, 0 }, + { C, 1, 1, 0, 1 }, + { C, 0, 1, 0, 1 }, + { C, 0, 1, 0, 1 }, + { P, 0, 0, 0, 0 }, + { C, 1, 1, 1, 1 }, + { C, 0, 1, 1, 1 }, + { C, 0, 1, 1, 1 }, + { P, 0, 0, 0, 0 }, + { C, 1, 1, 1, 1 }, + { C, 0, 1, 1, 1 }, + { C, 0, 1, 1, 1 } +}; + +/** + * \param line_aa AA_NEVER, AA_ALWAYS or AA_SOMETIMES + * \param lookup bitmask of IZ_* flags + */ +void brw_wm_lookup_iz( GLuint line_aa, + GLuint lookup, + GLboolean ps_uses_depth, + struct brw_wm_prog_key *key ) +{ + GLuint reg = 2; + + assert (lookup < IZ_BIT_MAX); + + if (lookup & IZ_PS_COMPUTES_DEPTH_BIT) + key->computes_depth = 1; + + if (wm_iz_table[lookup].sd_present || ps_uses_depth) { + key->source_depth_reg = reg; + reg += 2; + } + + if (wm_iz_table[lookup].sd_to_rt) + key->source_depth_to_render_target = 1; + + if (wm_iz_table[lookup].ds_present || line_aa != AA_NEVER) { + key->aa_dest_stencil_reg = reg; + key->runtime_check_aads_emit = (!wm_iz_table[lookup].ds_present && + line_aa == AA_SOMETIMES); + reg++; + } + + if (wm_iz_table[lookup].dd_present) { + key->dest_depth_reg = reg; + reg+=2; + } + + key->nr_depth_regs = (reg+1)/2; +} + diff --git a/src/gallium/drivers/i965/brw_wm_pass0.c b/src/gallium/drivers/i965/brw_wm_pass0.c new file mode 100644 index 0000000..0bacad2 --- /dev/null +++ b/src/gallium/drivers/i965/brw_wm_pass0.c @@ -0,0 +1,366 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_memory.h" +#include "util/u_math.h" + +#include "brw_debug.h" +#include "brw_wm.h" + + + +/*********************************************************************** + */ + +static struct brw_wm_ref *get_ref( struct brw_wm_compile *c ) +{ + assert(c->nr_refs < BRW_WM_MAX_REF); + return &c->refs[c->nr_refs++]; +} + +static struct brw_wm_value *get_value( struct brw_wm_compile *c) +{ + assert(c->nr_refs < BRW_WM_MAX_VREG); + return &c->vreg[c->nr_vreg++]; +} + +/** return pointer to a newly allocated instruction */ +static struct brw_wm_instruction *get_instruction( struct brw_wm_compile *c ) +{ + assert(c->nr_insns < BRW_WM_MAX_INSN); + return &c->instruction[c->nr_insns++]; +} + +/*********************************************************************** + */ + +/** Init the "undef" register */ +static void pass0_init_undef( struct brw_wm_compile *c) +{ + struct brw_wm_ref *ref = &c->undef_ref; + ref->value = &c->undef_value; + ref->hw_reg = brw_vec8_grf(0, 0); + ref->insn = 0; + ref->prevuse = NULL; +} + +/** Set a FP register to a value */ +static void pass0_set_fpreg_value( struct brw_wm_compile *c, + GLuint file, + GLuint idx, + GLuint component, + struct brw_wm_value *value ) +{ + struct brw_wm_ref *ref = get_ref(c); + ref->value = value; + ref->hw_reg = brw_vec8_grf(0, 0); + ref->insn = 0; + ref->prevuse = NULL; + c->pass0_fp_reg[file][idx][component] = ref; +} + +/** Set a FP register to a ref */ +static void pass0_set_fpreg_ref( struct brw_wm_compile *c, + GLuint file, + GLuint idx, + GLuint component, + const struct brw_wm_ref *src_ref ) +{ + c->pass0_fp_reg[file][idx][component] = src_ref; +} + +static const struct brw_wm_ref *get_param_ref( struct brw_wm_compile *c, + unsigned idx, + unsigned component) +{ + GLuint i = idx * 4 + component; + + if (i >= BRW_WM_MAX_PARAM) { + debug_printf("%s: out of params\n", __FUNCTION__); + c->prog_data.error = 1; + return NULL; + } + else { + struct brw_wm_ref *ref = get_ref(c); + + c->nr_creg = MAX2(c->nr_creg, (i+16)/16); + + /* Push the offsets into hw_reg. These will be added to the + * real register numbers once one is allocated in pass2. + */ + ref->hw_reg = brw_vec1_grf((i&8)?1:0, i%8); + ref->value = &c->creg[i/16]; + ref->insn = 0; + ref->prevuse = NULL; + + return ref; + } +} + + + + +/* Lookup our internal registers + */ +static const struct brw_wm_ref *pass0_get_reg( struct brw_wm_compile *c, + GLuint file, + GLuint idx, + GLuint component ) +{ + const struct brw_wm_ref *ref = c->pass0_fp_reg[file][idx][component]; + + if (!ref) { + switch (file) { + case TGSI_FILE_INPUT: + case TGSI_FILE_TEMPORARY: + case TGSI_FILE_OUTPUT: + case BRW_FILE_PAYLOAD: + /* should already be done?? */ + break; + + case TGSI_FILE_CONSTANT: + ref = get_param_ref(c, + c->fp->info.immediate_count + idx, + component); + break; + + case TGSI_FILE_IMMEDIATE: + ref = get_param_ref(c, + idx, + component); + break; + + default: + assert(0); + break; + } + + c->pass0_fp_reg[file][idx][component] = ref; + } + + if (!ref) + ref = &c->undef_ref; + + return ref; +} + + + +/*********************************************************************** + * Straight translation to internal instruction format + */ + +static void pass0_set_dst( struct brw_wm_compile *c, + struct brw_wm_instruction *out, + const struct brw_fp_instruction *inst, + GLuint writemask ) +{ + const struct brw_fp_dst dst = inst->dst; + GLuint i; + + for (i = 0; i < 4; i++) { + if (writemask & (1<dst[i] = get_value(c); + pass0_set_fpreg_value(c, dst.file, dst.index, i, out->dst[i]); + } + } + + out->writemask = writemask; +} + + +static const struct brw_wm_ref *get_fp_src_reg_ref( struct brw_wm_compile *c, + struct brw_fp_src src, + GLuint i ) +{ + return pass0_get_reg(c, src.file, src.index, BRW_GET_SWZ(src.swizzle,i)); +} + + +static struct brw_wm_ref *get_new_ref( struct brw_wm_compile *c, + struct brw_fp_src src, + GLuint i, + struct brw_wm_instruction *insn) +{ + const struct brw_wm_ref *ref = get_fp_src_reg_ref(c, src, i); + struct brw_wm_ref *newref = get_ref(c); + + newref->value = ref->value; + newref->hw_reg = ref->hw_reg; + + if (insn) { + newref->insn = insn - c->instruction; + newref->prevuse = newref->value->lastuse; + newref->value->lastuse = newref; + } + + if (src.negate) + newref->hw_reg.negate ^= 1; + + if (src.abs) { + newref->hw_reg.negate = 0; + newref->hw_reg.abs = 1; + } + + return newref; +} + + +static void +translate_insn(struct brw_wm_compile *c, + const struct brw_fp_instruction *inst) +{ + struct brw_wm_instruction *out = get_instruction(c); + GLuint writemask = inst->dst.writemask; + GLuint nr_args = brw_wm_nr_args(inst->opcode); + GLuint i, j; + + /* Copy some data out of the instruction + */ + out->opcode = inst->opcode; + out->saturate = inst->dst.saturate; + out->tex_unit = inst->tex_unit; + out->target = inst->target; + + /* Nasty hack: + */ + out->eot = (inst->opcode == WM_FB_WRITE && + inst->tex_unit != 0); + + + /* Args: + */ + for (i = 0; i < nr_args; i++) { + for (j = 0; j < 4; j++) { + out->src[i][j] = get_new_ref(c, inst->src[i], j, out); + } + } + + /* Dst: + */ + pass0_set_dst(c, out, inst, writemask); +} + + + +/*********************************************************************** + * Optimize moves and swizzles away: + */ +static void pass0_precalc_mov( struct brw_wm_compile *c, + const struct brw_fp_instruction *inst ) +{ + const struct brw_fp_dst dst = inst->dst; + GLuint writemask = dst.writemask; + struct brw_wm_ref *refs[4]; + GLuint i; + + /* Get the effect of a MOV by manipulating our register table: + * First get all refs, then assign refs. This ensures that "in-place" + * swizzles such as: + * MOV t, t.xxyx + * are handled correctly. Previously, these two steps were done in + * one loop and the above case was incorrectly handled. + */ + for (i = 0; i < 4; i++) { + refs[i] = get_new_ref(c, inst->src[0], i, NULL); + } + for (i = 0; i < 4; i++) { + if (writemask & (1 << i)) { + pass0_set_fpreg_ref( c, dst.file, dst.index, i, refs[i]); + } + } +} + + +/* Initialize payload "registers". + */ +static void pass0_init_payload( struct brw_wm_compile *c ) +{ + GLuint i; + + for (i = 0; i < 4; i++) { + GLuint j = i >= c->key.nr_depth_regs ? 0 : i; + pass0_set_fpreg_value( c, BRW_FILE_PAYLOAD, PAYLOAD_DEPTH, i, + &c->payload.depth[j] ); + } + + for (i = 0; i < c->key.nr_inputs; i++) + pass0_set_fpreg_value( c, BRW_FILE_PAYLOAD, i, 0, + &c->payload.input_interp[i] ); +} + + +/*********************************************************************** + * PASS 0 + * + * Work forwards to give each calculated value a unique number. Where + * an instruction produces duplicate values (eg DP3), all are given + * the same number. + * + * Translate away swizzling and eliminate non-saturating moves. + * + * Translate instructions from our fp_instruction structs to our + * internal brw_wm_instruction representation. + */ +void brw_wm_pass0( struct brw_wm_compile *c ) +{ + GLuint insn; + + c->nr_vreg = 0; + c->nr_insns = 0; + + pass0_init_undef(c); + pass0_init_payload(c); + + for (insn = 0; insn < c->nr_fp_insns; insn++) { + const struct brw_fp_instruction *inst = &c->fp_instructions[insn]; + + /* Optimize away moves, otherwise emit translated instruction: + */ + switch (inst->opcode) { + case TGSI_OPCODE_MOV: + if (!inst->dst.saturate) { + pass0_precalc_mov(c, inst); + } + else { + translate_insn(c, inst); + } + break; + default: + translate_insn(c, inst); + break; + } + } + + if (BRW_DEBUG & DEBUG_WM) { + brw_wm_print_program(c, "pass0"); + } +} diff --git a/src/gallium/drivers/i965/brw_wm_pass1.c b/src/gallium/drivers/i965/brw_wm_pass1.c new file mode 100644 index 0000000..005747f --- /dev/null +++ b/src/gallium/drivers/i965/brw_wm_pass1.c @@ -0,0 +1,292 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#include "brw_wm.h" +#include "brw_debug.h" + + +static GLuint get_tracked_mask(struct brw_wm_compile *c, + struct brw_wm_instruction *inst) +{ + GLuint i; + for (i = 0; i < 4; i++) { + if (inst->writemask & (1<dst[i]->contributes_to_output) { + inst->writemask &= ~(1<dst[i] = 0; + } + } + } + + return inst->writemask; +} + +/* Remove a reference from a value's usage chain. + */ +static void unlink_ref(struct brw_wm_ref *ref) +{ + struct brw_wm_value *value = ref->value; + + if (ref == value->lastuse) { + value->lastuse = ref->prevuse; + } + else { + struct brw_wm_ref *i = value->lastuse; + while (i->prevuse != ref) i = i->prevuse; + i->prevuse = ref->prevuse; + } +} + +static void track_arg(struct brw_wm_compile *c, + struct brw_wm_instruction *inst, + GLuint arg, + GLuint readmask) +{ + GLuint i; + + for (i = 0; i < 4; i++) { + struct brw_wm_ref *ref = inst->src[arg][i]; + if (ref) { + if (readmask & (1<value->contributes_to_output = 1; + } + else { + unlink_ref(ref); + inst->src[arg][i] = NULL; + } + } + } +} + +static GLuint get_texcoord_mask( GLuint tex_idx ) +{ + switch (tex_idx) { + case TGSI_TEXTURE_1D: + return BRW_WRITEMASK_X; + case TGSI_TEXTURE_2D: + case TGSI_TEXTURE_RECT: + return BRW_WRITEMASK_XY; + case TGSI_TEXTURE_3D: + return BRW_WRITEMASK_XYZ; + case TGSI_TEXTURE_CUBE: + return BRW_WRITEMASK_XYZ; + + case TGSI_TEXTURE_SHADOW1D: + return BRW_WRITEMASK_XZ; + case TGSI_TEXTURE_SHADOW2D: + case TGSI_TEXTURE_SHADOWRECT: + return BRW_WRITEMASK_XYZ; + default: + assert(0); + return 0; + } +} + + +/* Step two: Basically this is dead code elimination. + * + * Iterate backwards over instructions, noting which values + * contribute to the final result. Adjust writemasks to only + * calculate these values. + */ +void brw_wm_pass1( struct brw_wm_compile *c ) +{ + GLint insn; + + for (insn = c->nr_insns-1; insn >= 0; insn--) { + struct brw_wm_instruction *inst = &c->instruction[insn]; + GLuint writemask; + GLuint read0, read1, read2; + + if (inst->opcode == TGSI_OPCODE_KIL) { + track_arg(c, inst, 0, BRW_WRITEMASK_XYZW); /* All args contribute to final */ + continue; + } + + if (inst->opcode == WM_FB_WRITE) { + track_arg(c, inst, 0, BRW_WRITEMASK_XYZW); + track_arg(c, inst, 1, BRW_WRITEMASK_XYZW); + if (c->key.source_depth_to_render_target && + c->key.computes_depth) + track_arg(c, inst, 2, BRW_WRITEMASK_Z); + else + track_arg(c, inst, 2, 0); + continue; + } + + /* Lookup all the registers which were written by this + * instruction and get a mask of those that contribute to the output: + */ + writemask = get_tracked_mask(c, inst); + if (!writemask) { + GLuint arg; + for (arg = 0; arg < 3; arg++) + track_arg(c, inst, arg, 0); + continue; + } + + read0 = 0; + read1 = 0; + read2 = 0; + + /* Mark all inputs which contribute to the marked outputs: + */ + switch (inst->opcode) { + case TGSI_OPCODE_ABS: + case TGSI_OPCODE_FLR: + case TGSI_OPCODE_FRC: + case TGSI_OPCODE_MOV: + case TGSI_OPCODE_TRUNC: + read0 = writemask; + break; + + case TGSI_OPCODE_SUB: + case TGSI_OPCODE_SLT: + case TGSI_OPCODE_SLE: + case TGSI_OPCODE_SGE: + case TGSI_OPCODE_SGT: + case TGSI_OPCODE_SEQ: + case TGSI_OPCODE_SNE: + case TGSI_OPCODE_ADD: + case TGSI_OPCODE_MAX: + case TGSI_OPCODE_MIN: + case TGSI_OPCODE_MUL: + read0 = writemask; + read1 = writemask; + break; + + case TGSI_OPCODE_DDX: + case TGSI_OPCODE_DDY: + read0 = writemask; + break; + + case TGSI_OPCODE_MAD: + case TGSI_OPCODE_CMP: + case TGSI_OPCODE_LRP: + read0 = writemask; + read1 = writemask; + read2 = writemask; + break; + + case TGSI_OPCODE_XPD: + if (writemask & BRW_WRITEMASK_X) read0 |= BRW_WRITEMASK_YZ; + if (writemask & BRW_WRITEMASK_Y) read0 |= BRW_WRITEMASK_XZ; + if (writemask & BRW_WRITEMASK_Z) read0 |= BRW_WRITEMASK_XY; + read1 = read0; + break; + + case TGSI_OPCODE_COS: + case TGSI_OPCODE_EX2: + case TGSI_OPCODE_LG2: + case TGSI_OPCODE_RCP: + case TGSI_OPCODE_RSQ: + case TGSI_OPCODE_SIN: + case TGSI_OPCODE_SCS: + case WM_CINTERP: + case WM_PIXELXY: + read0 = BRW_WRITEMASK_X; + break; + + case TGSI_OPCODE_POW: + read0 = BRW_WRITEMASK_X; + read1 = BRW_WRITEMASK_X; + break; + + case TGSI_OPCODE_TEX: + case TGSI_OPCODE_TXP: + read0 = get_texcoord_mask(inst->target); + break; + + case TGSI_OPCODE_TXB: + read0 = get_texcoord_mask(inst->target) | BRW_WRITEMASK_W; + break; + + case WM_WPOSXY: + read0 = writemask & BRW_WRITEMASK_XY; + break; + + case WM_DELTAXY: + read0 = writemask & BRW_WRITEMASK_XY; + read1 = BRW_WRITEMASK_X; + break; + + case WM_PIXELW: + read0 = BRW_WRITEMASK_X; + read1 = BRW_WRITEMASK_XY; + break; + + case WM_LINTERP: + read0 = BRW_WRITEMASK_X; + read1 = BRW_WRITEMASK_XY; + break; + + case WM_PINTERP: + read0 = BRW_WRITEMASK_X; /* interpolant */ + read1 = BRW_WRITEMASK_XY; /* deltas */ + read2 = BRW_WRITEMASK_W; /* pixel w */ + break; + + case TGSI_OPCODE_DP3: + read0 = BRW_WRITEMASK_XYZ; + read1 = BRW_WRITEMASK_XYZ; + break; + + case TGSI_OPCODE_DPH: + read0 = BRW_WRITEMASK_XYZ; + read1 = BRW_WRITEMASK_XYZW; + break; + + case TGSI_OPCODE_DP4: + read0 = BRW_WRITEMASK_XYZW; + read1 = BRW_WRITEMASK_XYZW; + break; + + case TGSI_OPCODE_LIT: + read0 = BRW_WRITEMASK_XYW; + break; + + case TGSI_OPCODE_DST: + case WM_FRONTFACING: + case TGSI_OPCODE_KILP: + default: + break; + } + + track_arg(c, inst, 0, read0); + track_arg(c, inst, 1, read1); + track_arg(c, inst, 2, read2); + } + + if (BRW_DEBUG & DEBUG_WM) { + brw_wm_print_program(c, "pass1"); + } +} diff --git a/src/gallium/drivers/i965/brw_wm_pass2.c b/src/gallium/drivers/i965/brw_wm_pass2.c new file mode 100644 index 0000000..19248b4 --- /dev/null +++ b/src/gallium/drivers/i965/brw_wm_pass2.c @@ -0,0 +1,334 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + + +#include "brw_debug.h" +#include "brw_wm.h" + + +/* Use these to force spilling so that that functionality can be + * tested with known-good examples rather than having to construct new + * tests. + */ +#define TEST_PAYLOAD_SPILLS 0 +#define TEST_DST_SPILLS 0 + +static void spill_value(struct brw_wm_compile *c, + struct brw_wm_value *value); + +static void prealloc_reg(struct brw_wm_compile *c, + struct brw_wm_value *value, + GLuint reg) +{ + if (value->lastuse) { + /* Set nextuse to zero, it will be corrected by + * update_register_usage(). + */ + c->pass2_grf[reg].value = value; + c->pass2_grf[reg].nextuse = 0; + + value->resident = &c->pass2_grf[reg]; + value->hw_reg = brw_vec8_grf(reg*2, 0); + + if (TEST_PAYLOAD_SPILLS) + spill_value(c, value); + } +} + + +/* Initialize all the register values. Do the initial setup + * calculations for interpolants. + */ +static void init_registers( struct brw_wm_compile *c ) +{ + GLuint reg = 0; + GLuint j; + + for (j = 0; j < c->grf_limit; j++) + c->pass2_grf[j].nextuse = BRW_WM_MAX_INSN; + + /* Pre-allocate incoming payload regs: + */ + for (j = 0; j < c->key.nr_depth_regs; j++) + prealloc_reg(c, &c->payload.depth[j], reg++); + + for (j = 0; j < c->nr_creg; j++) + prealloc_reg(c, &c->creg[j], reg++); + + reg++; /* XXX: skip over position output */ + + /* XXX: currently just hope the VS outputs line up with FS inputs: + */ + for (j = 0; j < c->key.nr_inputs; j++) + prealloc_reg(c, &c->payload.input_interp[j], reg++); + + c->prog_data.first_curbe_grf = c->key.nr_depth_regs * 2; + c->prog_data.urb_read_length = (c->key.nr_inputs + 1) * 2; + c->prog_data.curb_read_length = c->nr_creg * 2; + + /* Note this allocation: + */ + c->max_wm_grf = reg * 2; +} + + +/* Update the nextuse value for each register in our file. + */ +static void update_register_usage(struct brw_wm_compile *c, + GLuint thisinsn) +{ + GLuint i; + + for (i = 1; i < c->grf_limit; i++) { + struct brw_wm_grf *grf = &c->pass2_grf[i]; + + /* Only search those which can change: + */ + if (grf->nextuse < thisinsn) { + const struct brw_wm_ref *ref = grf->value->lastuse; + + /* Has last use of value been passed? + */ + if (ref->insn < thisinsn) { + grf->value->resident = 0; + grf->value = 0; + grf->nextuse = BRW_WM_MAX_INSN; + } + else { + /* Else loop through chain to update: + */ + while (ref->prevuse && ref->prevuse->insn >= thisinsn) + ref = ref->prevuse; + + grf->nextuse = ref->insn; + } + } + } +} + + +static void spill_value(struct brw_wm_compile *c, + struct brw_wm_value *value) +{ + /* Allocate a spill slot. Note that allocations start from 0x40 - + * the first slot is reserved to mean "undef" in brw_wm_emit.c + */ + if (!value->spill_slot) { + c->last_scratch += 0x40; + value->spill_slot = c->last_scratch; + } + + /* The spill will be done in brw_wm_emit.c immediately after the + * value is calculated, so we can just take this reg without any + * further work. + */ + value->resident->value = NULL; + value->resident->nextuse = BRW_WM_MAX_INSN; + value->resident = NULL; +} + + + +/* Search for contiguous region with the most distant nearest + * member. Free regs count as very distant. + * + * TODO: implement spill-to-reg so that we can rearrange discontigous + * free regs and then spill the oldest non-free regs in sequence. + * This would mean inserting instructions in this pass. + */ +static GLuint search_contiguous_regs(struct brw_wm_compile *c, + GLuint nr, + GLuint thisinsn) +{ + struct brw_wm_grf *grf = c->pass2_grf; + GLuint furthest = 0; + GLuint reg = 0; + GLuint i, j; + + /* Start search at 1: r0 is special and can't be used or spilled. + */ + for (i = 1; i < c->grf_limit && furthest < BRW_WM_MAX_INSN; i++) { + GLuint group_nextuse = BRW_WM_MAX_INSN; + + for (j = 0; j < nr; j++) { + if (grf[i+j].nextuse < group_nextuse) + group_nextuse = grf[i+j].nextuse; + } + + if (group_nextuse > furthest) { + furthest = group_nextuse; + reg = i; + } + } + + assert(furthest != thisinsn); + + /* Any non-empty regs will need to be spilled: + */ + for (j = 0; j < nr; j++) + if (grf[reg+j].value) + spill_value(c, grf[reg+j].value); + + return reg; +} + + +static void alloc_contiguous_dest(struct brw_wm_compile *c, + struct brw_wm_value *dst[], + GLuint nr, + GLuint thisinsn) +{ + GLuint reg = search_contiguous_regs(c, nr, thisinsn); + GLuint i; + + for (i = 0; i < nr; i++) { + if (!dst[i]) { + /* Need to grab a dummy value in TEX case. Don't introduce + * it into the tracking scheme. + */ + dst[i] = &c->vreg[c->nr_vreg++]; + } + else { + assert(!dst[i]->resident); + assert(c->pass2_grf[reg+i].nextuse != thisinsn); + + c->pass2_grf[reg+i].value = dst[i]; + c->pass2_grf[reg+i].nextuse = thisinsn; + + dst[i]->resident = &c->pass2_grf[reg+i]; + } + + dst[i]->hw_reg = brw_vec8_grf((reg+i)*2, 0); + } + + if ((reg+nr)*2 > c->max_wm_grf) + c->max_wm_grf = (reg+nr) * 2; +} + + +static void load_args(struct brw_wm_compile *c, + struct brw_wm_instruction *inst) +{ + GLuint thisinsn = inst - c->instruction; + GLuint i,j; + + for (i = 0; i < 3; i++) { + for (j = 0; j < 4; j++) { + struct brw_wm_ref *ref = inst->src[i][j]; + + if (ref) { + if (!ref->value->resident) { + /* Need to bring the value in from scratch space. The code for + * this will be done in brw_wm_emit.c, here we just do the + * register allocation and mark the ref as requiring a fill. + */ + GLuint reg = search_contiguous_regs(c, 1, thisinsn); + + c->pass2_grf[reg].value = ref->value; + c->pass2_grf[reg].nextuse = thisinsn; + + ref->value->resident = &c->pass2_grf[reg]; + + /* Note that a fill is required: + */ + ref->unspill_reg = reg*2; + } + + /* Adjust the hw_reg to point at the value's current location: + */ + assert(ref->value == ref->value->resident->value); + ref->hw_reg.nr += (ref->value->resident - c->pass2_grf) * 2; + } + } + } +} + + + +/* Step 3: Work forwards once again. Perform register allocations, + * taking into account instructions like TEX which require contiguous + * result registers. Where necessary spill registers to scratch space + * and reload later. + */ +void brw_wm_pass2( struct brw_wm_compile *c ) +{ + GLuint insn; + GLuint i; + + init_registers(c); + + for (insn = 0; insn < c->nr_insns; insn++) { + struct brw_wm_instruction *inst = &c->instruction[insn]; + + /* Update registers' nextuse values: + */ + update_register_usage(c, insn); + + /* May need to unspill some args. + */ + load_args(c, inst); + + /* Allocate registers to hold results: + */ + switch (inst->opcode) { + case TGSI_OPCODE_TEX: + case TGSI_OPCODE_TXB: + case TGSI_OPCODE_TXP: + alloc_contiguous_dest(c, inst->dst, 4, insn); + break; + + default: + for (i = 0; i < 4; i++) { + if (inst->writemask & (1<dst[i]); + alloc_contiguous_dest(c, &inst->dst[i], 1, insn); + } + } + break; + } + + if (TEST_DST_SPILLS && inst->opcode != WM_PIXELXY) { + for (i = 0; i < 4; i++) + if (inst->dst[i]) + spill_value(c, inst->dst[i]); + } + } + + if (BRW_DEBUG & DEBUG_WM) { + brw_wm_print_program(c, "pass2"); + } + + c->state = PASS2_DONE; + + if (BRW_DEBUG & DEBUG_WM) { + brw_wm_print_program(c, "pass2/done"); + } +} diff --git a/src/gallium/drivers/i965/brw_wm_sampler_state.c b/src/gallium/drivers/i965/brw_wm_sampler_state.c new file mode 100644 index 0000000..8406a1a --- /dev/null +++ b/src/gallium/drivers/i965/brw_wm_sampler_state.c @@ -0,0 +1,228 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_math.h" +#include "util/u_format.h" + +#include "brw_context.h" +#include "brw_state.h" +#include "brw_defines.h" +#include "brw_resource.h" + + +/* Samplers aren't strictly wm state from the hardware's perspective, + * but that is the only situation in which we use them in this driver. + */ + + + +static enum pipe_error +upload_default_color( struct brw_context *brw, + const GLfloat *color, + struct brw_winsys_buffer **bo_out ) +{ + struct brw_sampler_default_color sdc; + enum pipe_error ret; + + COPY_4V(sdc.color, color); + + ret = brw_cache_data( &brw->cache, BRW_SAMPLER_DEFAULT_COLOR, &sdc, + NULL, 0, bo_out ); + if (ret) + return ret; + + return PIPE_OK; +} + + +struct wm_sampler_key { + int sampler_count; + struct brw_sampler_state sampler[BRW_MAX_TEX_UNIT]; +}; + + +/** Sets up the cache key for sampler state for all texture units */ +static void +brw_wm_sampler_populate_key(struct brw_context *brw, + struct wm_sampler_key *key) +{ + int i; + + memset(key, 0, sizeof(*key)); + + key->sampler_count = MIN2(brw->curr.num_fragment_sampler_views, + brw->curr.num_samplers); + + for (i = 0; i < key->sampler_count; i++) { + const struct brw_texture *tex = brw_texture(brw->curr.fragment_sampler_views[i]->texture); + const struct brw_sampler *sampler = brw->curr.sampler[i]; + struct brw_sampler_state *entry = &key->sampler[i]; + + entry->ss0 = sampler->ss0; + entry->ss1 = sampler->ss1; + entry->ss2.default_color_pointer = 0; /* reloc */ + entry->ss3 = sampler->ss3; + + /* Cube-maps on 965 and later must use the same wrap mode for all 3 + * coordinate dimensions. Futher, only CUBE and CLAMP are valid. + */ + if (tex->b.b.target == PIPE_TEXTURE_CUBE) { + if (FALSE && + (sampler->ss0.min_filter != BRW_MAPFILTER_NEAREST || + sampler->ss0.mag_filter != BRW_MAPFILTER_NEAREST)) { + entry->ss1.r_wrap_mode = BRW_TEXCOORDMODE_CUBE; + entry->ss1.s_wrap_mode = BRW_TEXCOORDMODE_CUBE; + entry->ss1.t_wrap_mode = BRW_TEXCOORDMODE_CUBE; + } else { + entry->ss1.r_wrap_mode = BRW_TEXCOORDMODE_CLAMP; + entry->ss1.s_wrap_mode = BRW_TEXCOORDMODE_CLAMP; + entry->ss1.t_wrap_mode = BRW_TEXCOORDMODE_CLAMP; + } + } else if (tex->b.b.target == PIPE_TEXTURE_1D) { + /* There's a bug in 1D texture sampling - it actually pays + * attention to the wrap_t value, though it should not. + * Override the wrap_t value here to GL_REPEAT to keep + * any nonexistent border pixels from floating in. + */ + entry->ss1.t_wrap_mode = BRW_TEXCOORDMODE_WRAP; + } + } +} + + +static enum pipe_error +brw_wm_sampler_update_default_colors(struct brw_context *brw) +{ + enum pipe_error ret; + int nr = MIN2(brw->curr.num_fragment_sampler_views, + brw->curr.num_samplers); + int i; + + for (i = 0; i < nr; i++) { + const struct brw_texture *tex = brw_texture(brw->curr.fragment_sampler_views[i]->texture); + const struct brw_sampler *sampler = brw->curr.sampler[i]; + const float *bc; + float bordercolor[4] = { + sampler->border_color[0], + sampler->border_color[0], + sampler->border_color[0], + sampler->border_color[0] + }; + + if (util_format_is_depth_or_stencil(tex->b.b.format)) { + bc = bordercolor; + } + else { + bc = sampler->border_color; + } + + /* GL specs that border color for depth textures is taken from the + * R channel, while the hardware uses A. Spam R into all the + * channels for safety. + */ + ret = upload_default_color(brw, + bc, + &brw->wm.sdc_bo[i]); + if (ret) + return ret; + } + + return PIPE_OK; +} + + + +/* All samplers must be uploaded in a single contiguous array. + */ +static int upload_wm_samplers( struct brw_context *brw ) +{ + struct wm_sampler_key key; + struct brw_winsys_reloc reloc[BRW_MAX_TEX_UNIT]; + enum pipe_error ret; + int i; + + brw_wm_sampler_update_default_colors(brw); + brw_wm_sampler_populate_key(brw, &key); + + if (brw->wm.sampler_count != key.sampler_count) { + brw->wm.sampler_count = key.sampler_count; + brw->state.dirty.cache |= CACHE_NEW_SAMPLER; + } + + if (brw->wm.sampler_count == 0) { + bo_reference(&brw->wm.sampler_bo, NULL); + return PIPE_OK; + } + + /* Emit SDC relocations */ + for (i = 0; i < key.sampler_count; i++) { + make_reloc( &reloc[i], + BRW_USAGE_SAMPLER, + 0, + i * sizeof(struct brw_sampler_state) + + offsetof(struct brw_sampler_state, ss2), + brw->wm.sdc_bo[i]); + } + + + if (brw_search_cache(&brw->cache, BRW_SAMPLER, + &key, sizeof(key), + reloc, key.sampler_count, + NULL, + &brw->wm.sampler_bo)) + return PIPE_OK; + + /* If we didnt find it in the cache, compute the state and put it in the + * cache. + */ + ret = brw_upload_cache(&brw->cache, BRW_SAMPLER, + &key, sizeof(key), + reloc, key.sampler_count, + &key.sampler, sizeof(key.sampler), + NULL, NULL, + &brw->wm.sampler_bo); + if (ret) + return ret; + + + return 0; +} + +const struct brw_tracked_state brw_wm_samplers = { + .dirty = { + .mesa = PIPE_NEW_BOUND_TEXTURES | PIPE_NEW_SAMPLERS, + .brw = 0, + .cache = 0 + }, + .prepare = upload_wm_samplers, +}; + + diff --git a/src/gallium/drivers/i965/brw_wm_state.c b/src/gallium/drivers/i965/brw_wm_state.c new file mode 100644 index 0000000..efc2d96 --- /dev/null +++ b/src/gallium/drivers/i965/brw_wm_state.c @@ -0,0 +1,340 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "util/u_math.h" + +#include "brw_context.h" +#include "brw_state.h" +#include "brw_defines.h" +#include "brw_wm.h" +#include "brw_debug.h" +#include "brw_pipe_rast.h" + +/*********************************************************************** + * WM unit - fragment programs and rasterization + */ + +struct brw_wm_unit_key { + unsigned int total_grf, total_scratch; + unsigned int urb_entry_read_length; + unsigned int curb_entry_read_length; + unsigned int dispatch_grf_start_reg; + + unsigned int curbe_offset; + unsigned int urb_size; + + unsigned int max_threads; + + unsigned int nr_surfaces, sampler_count; + GLboolean uses_depth, computes_depth, uses_kill, has_flow_control; + GLboolean polygon_stipple, stats_wm, line_stipple, offset_enable; + GLfloat offset_units, offset_factor; +}; + +static void +wm_unit_populate_key(struct brw_context *brw, struct brw_wm_unit_key *key) +{ + const struct brw_fragment_shader *fp = brw->curr.fragment_shader; + + memset(key, 0, sizeof(*key)); + + if (BRW_DEBUG & DEBUG_SINGLE_THREAD) + key->max_threads = 1; + else { + /* WM maximum threads is number of EUs times number of threads per EU. */ + if (BRW_IS_IGDNG(brw)) + key->max_threads = 12 * 6; + else if (BRW_IS_G4X(brw)) + key->max_threads = 10 * 5; + else + key->max_threads = 8 * 4; + } + + /* CACHE_NEW_WM_PROG */ + key->total_grf = brw->wm.prog_data->total_grf; + key->urb_entry_read_length = brw->wm.prog_data->urb_read_length; + key->curb_entry_read_length = brw->wm.prog_data->curb_read_length; + key->dispatch_grf_start_reg = brw->wm.prog_data->first_curbe_grf; + key->total_scratch = align(brw->wm.prog_data->total_scratch, 1024); + + /* BRW_NEW_URB_FENCE */ + key->urb_size = brw->urb.vsize; + + /* BRW_NEW_CURBE_OFFSETS */ + key->curbe_offset = brw->curbe.wm_start; + + /* BRW_NEW_NR_SURFACEs */ + key->nr_surfaces = brw->wm.nr_surfaces; + + /* CACHE_NEW_SAMPLER */ + key->sampler_count = brw->wm.sampler_count; + + /* PIPE_NEW_RAST */ + key->polygon_stipple = brw->curr.rast->templ.poly_stipple_enable; + + /* PIPE_NEW_FRAGMENT_PROGRAM */ + key->uses_depth = fp->uses_depth; + key->computes_depth = fp->info.writes_z; + + /* PIPE_NEW_DEPTH_BUFFER + * + * Override for NULL depthbuffer case, required by the Pixel Shader Computed + * Depth field. + */ + if (brw->curr.fb.zsbuf == NULL) + key->computes_depth = 0; + + /* PIPE_NEW_DEPTH_STENCIL_ALPHA */ + key->uses_kill = (fp->info.uses_kill || + brw->curr.zstencil->cc3.alpha_test); + + key->has_flow_control = fp->has_flow_control; + + /* temporary sanity check assertion */ + assert(fp->has_flow_control == 0); + + /* PIPE_NEW_QUERY */ + key->stats_wm = (brw->query.stats_wm != 0); + + /* PIPE_NEW_RAST */ + key->line_stipple = brw->curr.rast->templ.line_stipple_enable; + + + key->offset_enable = (brw->curr.rast->templ.offset_point || + brw->curr.rast->templ.offset_line || + brw->curr.rast->templ.offset_tri); + + key->offset_units = brw->curr.rast->templ.offset_units; + key->offset_factor = brw->curr.rast->templ.offset_scale; +} + +/** + * Setup wm hardware state. See page 225 of Volume 2 + */ +static enum pipe_error +wm_unit_create_from_key(struct brw_context *brw, struct brw_wm_unit_key *key, + struct brw_winsys_reloc *reloc, + unsigned nr_reloc, + struct brw_winsys_buffer **bo_out) +{ + struct brw_wm_unit_state wm; + enum pipe_error ret; + + memset(&wm, 0, sizeof(wm)); + + wm.thread0.grf_reg_count = align(key->total_grf, 16) / 16 - 1; + wm.thread0.kernel_start_pointer = 0; /* reloc */ + wm.thread1.depth_coef_urb_read_offset = 1; + wm.thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754; + + if (BRW_IS_IGDNG(brw)) + wm.thread1.binding_table_entry_count = 0; /* hardware requirement */ + else + wm.thread1.binding_table_entry_count = key->nr_surfaces; + + if (key->total_scratch != 0) { + wm.thread2.scratch_space_base_pointer = 0; /* reloc */ + wm.thread2.per_thread_scratch_space = key->total_scratch / 1024 - 1; + } else { + wm.thread2.scratch_space_base_pointer = 0; + wm.thread2.per_thread_scratch_space = 0; + } + + wm.thread3.dispatch_grf_start_reg = key->dispatch_grf_start_reg; + wm.thread3.urb_entry_read_length = key->urb_entry_read_length; + wm.thread3.urb_entry_read_offset = 0; + wm.thread3.const_urb_entry_read_length = key->curb_entry_read_length; + wm.thread3.const_urb_entry_read_offset = key->curbe_offset * 2; + + if (BRW_IS_IGDNG(brw)) + wm.wm4.sampler_count = 0; /* hardware requirement */ + else + wm.wm4.sampler_count = (key->sampler_count + 1) / 4; + + /* reloc */ + wm.wm4.sampler_state_pointer = 0; + + wm.wm5.program_uses_depth = key->uses_depth; + wm.wm5.program_computes_depth = key->computes_depth; + wm.wm5.program_uses_killpixel = key->uses_kill; + + if (key->has_flow_control) + wm.wm5.enable_8_pix = 1; + else + wm.wm5.enable_16_pix = 1; + + wm.wm5.max_threads = key->max_threads - 1; + wm.wm5.thread_dispatch_enable = 1; /* AKA: color_write */ + wm.wm5.legacy_line_rast = 0; + wm.wm5.legacy_global_depth_bias = 0; + wm.wm5.early_depth_test = 1; /* never need to disable */ + wm.wm5.line_aa_region_width = 0; + wm.wm5.line_endcap_aa_region_width = 1; + + wm.wm5.polygon_stipple = key->polygon_stipple; + + if (key->offset_enable) { + wm.wm5.depth_offset = 1; + /* Something wierd going on with legacy_global_depth_bias, + * offset_constant, scaling and MRD. This value passes glean + * but gives some odd results elsewere (eg. the + * quad-offset-units test). + */ + wm.global_depth_offset_constant = key->offset_units * 2; + + /* This is the only value that passes glean: + */ + wm.global_depth_offset_scale = key->offset_factor; + } + + wm.wm5.line_stipple = key->line_stipple; + + if ((BRW_DEBUG & DEBUG_STATS) || key->stats_wm) + wm.wm4.stats_enable = 1; + + ret = brw_upload_cache(&brw->cache, BRW_WM_UNIT, + key, sizeof(*key), + reloc, nr_reloc, + &wm, sizeof(wm), + NULL, NULL, + bo_out); + if (ret) + return ret; + + return PIPE_OK; +} + + +static enum pipe_error upload_wm_unit( struct brw_context *brw ) +{ + struct brw_wm_unit_key key; + struct brw_winsys_reloc reloc[3]; + unsigned nr_reloc = 0; + enum pipe_error ret; + unsigned grf_reg_count; + unsigned per_thread_scratch_space; + unsigned stats_enable; + unsigned sampler_count; + + wm_unit_populate_key(brw, &key); + + + /* Allocate the necessary scratch space if we haven't already. Don't + * bother reducing the allocation later, since we use scratch so + * rarely. + */ + assert(key.total_scratch <= 12 * 1024); + if (key.total_scratch) { + GLuint total = key.total_scratch * key.max_threads; + + /* Do we need a new buffer: + */ + if (brw->wm.scratch_bo && total > brw->wm.scratch_bo->size) + bo_reference(&brw->wm.scratch_bo, NULL); + + if (brw->wm.scratch_bo == NULL) { + ret = brw->sws->bo_alloc(brw->sws, + BRW_BUFFER_TYPE_SHADER_SCRATCH, + total, + 4096, + &brw->wm.scratch_bo); + if (ret) + return ret; + } + } + + + /* XXX: temporary: + */ + grf_reg_count = (align(key.total_grf, 16) / 16 - 1); + per_thread_scratch_space = key.total_scratch / 1024 - 1; + stats_enable = (BRW_DEBUG & DEBUG_STATS) || key.stats_wm; + sampler_count = BRW_IS_IGDNG(brw) ? 0 :(key.sampler_count + 1) / 4; + + /* Emit WM program relocation */ + make_reloc(&reloc[nr_reloc++], + BRW_USAGE_STATE, + grf_reg_count << 1, + offsetof(struct brw_wm_unit_state, thread0), + brw->wm.prog_bo); + + /* Emit scratch space relocation */ + if (key.total_scratch != 0) { + make_reloc(&reloc[nr_reloc++], + BRW_USAGE_SCRATCH, + per_thread_scratch_space, + offsetof(struct brw_wm_unit_state, thread2), + brw->wm.scratch_bo); + } + + /* Emit sampler state relocation */ + if (key.sampler_count != 0) { + make_reloc(&reloc[nr_reloc++], + BRW_USAGE_STATE, + stats_enable | (sampler_count << 2), + offsetof(struct brw_wm_unit_state, wm4), + brw->wm.sampler_bo); + } + + + if (brw_search_cache(&brw->cache, BRW_WM_UNIT, + &key, sizeof(key), + reloc, nr_reloc, + NULL, + &brw->wm.state_bo)) + return PIPE_OK; + + ret = wm_unit_create_from_key(brw, &key, + reloc, nr_reloc, + &brw->wm.state_bo); + if (ret) + return ret; + + return PIPE_OK; +} + +const struct brw_tracked_state brw_wm_unit = { + .dirty = { + .mesa = (PIPE_NEW_FRAGMENT_SHADER | + PIPE_NEW_DEPTH_BUFFER | + PIPE_NEW_RAST | + PIPE_NEW_DEPTH_STENCIL_ALPHA | + PIPE_NEW_QUERY), + + .brw = (BRW_NEW_CURBE_OFFSETS | + BRW_NEW_NR_WM_SURFACES), + + .cache = (CACHE_NEW_WM_PROG | + CACHE_NEW_SAMPLER) + }, + .prepare = upload_wm_unit, +}; + diff --git a/src/gallium/drivers/i965/brw_wm_surface_state.c b/src/gallium/drivers/i965/brw_wm_surface_state.c new file mode 100644 index 0000000..0d80a01 --- /dev/null +++ b/src/gallium/drivers/i965/brw_wm_surface_state.c @@ -0,0 +1,293 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + /* + * Authors: + * Keith Whitwell + */ + +#include "pipe/p_format.h" + +#include "brw_batchbuffer.h" +#include "brw_context.h" +#include "brw_state.h" +#include "brw_resource.h" + + + + +static enum pipe_error +brw_update_texture_surface( struct brw_context *brw, + struct brw_texture *tex, + struct brw_winsys_buffer **bo_out) +{ + struct brw_winsys_reloc reloc[1]; + enum pipe_error ret; + + /* Emit relocation to surface contents */ + make_reloc(&reloc[0], + BRW_USAGE_SAMPLER, + 0, + offsetof(struct brw_surface_state, ss1), + tex->bo); + + if (brw_search_cache(&brw->surface_cache, + BRW_SS_SURFACE, + &tex->ss, sizeof tex->ss, + reloc, Elements(reloc), + NULL, + bo_out)) + return PIPE_OK; + + ret = brw_upload_cache(&brw->surface_cache, BRW_SS_SURFACE, + &tex->ss, sizeof tex->ss, + reloc, Elements(reloc), + &tex->ss, sizeof tex->ss, + NULL, NULL, + bo_out); + if (ret) + return ret; + + return PIPE_OK; +} + + + + + + + + +/** + * Sets up a surface state structure to point at the given region. + * While it is only used for the front/back buffer currently, it should be + * usable for further buffers when doing ARB_draw_buffer support. + */ +static enum pipe_error +brw_update_render_surface(struct brw_context *brw, + struct brw_surface *surface, + struct brw_winsys_buffer **bo_out) +{ + struct brw_surf_ss0 blend_ss0 = brw->curr.blend->ss0; + struct brw_surface_state ss; + struct brw_winsys_reloc reloc[1]; + enum pipe_error ret; + + /* XXX: we will only be rendering to this surface: + */ + make_reloc(&reloc[0], + BRW_USAGE_RENDER_TARGET, + 0, + offsetof(struct brw_surface_state, ss1), + surface->bo); + + /* Surfaces are potentially shared between contexts, so can't + * scribble the in-place ss0 value in the surface. + */ + memcpy(&ss, &surface->ss, sizeof ss); + + ss.ss0.color_blend = blend_ss0.color_blend; + ss.ss0.writedisable_blue = blend_ss0.writedisable_blue; + ss.ss0.writedisable_green = blend_ss0.writedisable_green; + ss.ss0.writedisable_red = blend_ss0.writedisable_red; + ss.ss0.writedisable_alpha = blend_ss0.writedisable_alpha; + + if (brw_search_cache(&brw->surface_cache, + BRW_SS_SURFACE, + &ss, sizeof(ss), + reloc, Elements(reloc), + NULL, + bo_out)) + return PIPE_OK; + + ret = brw_upload_cache(&brw->surface_cache, + BRW_SS_SURFACE, + &ss, sizeof ss, + reloc, Elements(reloc), + &ss, sizeof ss, + NULL, NULL, + bo_out); + if (ret) + return ret; + + return PIPE_OK; +} + + +/** + * Constructs the binding table for the WM surface state, which maps unit + * numbers to surface state objects. + */ +static enum pipe_error +brw_wm_get_binding_table(struct brw_context *brw, + struct brw_winsys_buffer **bo_out ) +{ + enum pipe_error ret; + struct brw_winsys_reloc reloc[BRW_WM_MAX_SURF]; + uint32_t data[BRW_WM_MAX_SURF]; + GLuint nr_relocs = 0; + GLuint data_size = brw->wm.nr_surfaces * sizeof data[0]; + int i; + + assert(brw->wm.nr_surfaces <= BRW_WM_MAX_SURF); + assert(brw->wm.nr_surfaces > 0); + + /* Emit binding table relocations to surface state + */ + for (i = 0; i < brw->wm.nr_surfaces; i++) { + if (brw->wm.surf_bo[i]) { + make_reloc(&reloc[nr_relocs++], + BRW_USAGE_STATE, + 0, + i * sizeof(GLuint), + brw->wm.surf_bo[i]); + } + } + + /* Note there is no key for this search beyond the values in the + * relocation array: + */ + if (brw_search_cache(&brw->surface_cache, BRW_SS_SURF_BIND, + NULL, 0, + reloc, nr_relocs, + NULL, + bo_out)) + return PIPE_OK; + + /* Upload zero data, will all be overwitten with relocation + * offsets: + */ + for (i = 0; i < brw->wm.nr_surfaces; i++) + data[i] = 0; + + ret = brw_upload_cache( &brw->surface_cache, BRW_SS_SURF_BIND, + NULL, 0, + reloc, nr_relocs, + data, data_size, + NULL, NULL, + bo_out); + if (ret) + return ret; + + return PIPE_OK; +} + +static enum pipe_error prepare_wm_surfaces(struct brw_context *brw ) +{ + enum pipe_error ret; + int nr_surfaces = 0; + GLuint i; + + /* PIPE_NEW_COLOR_BUFFERS | PIPE_NEW_BLEND + * + * Update surfaces for drawing buffers. Mixes in colormask and + * blend state. + * + * XXX: no color buffer case + */ + for (i = 0; i < brw->curr.fb.nr_cbufs; i++) { + ret = brw_update_render_surface(brw, + brw_surface(brw->curr.fb.cbufs[i]), + &brw->wm.surf_bo[BTI_COLOR_BUF(i)]); + if (ret) + return ret; + + nr_surfaces = BTI_COLOR_BUF(i) + 1; + } + + + + /* PIPE_NEW_FRAGMENT_CONSTANTS + */ +#if 0 + if (brw->curr.fragment_constants) { + ret = brw_update_fragment_constant_surface( + brw, + brw->curr.fragment_constants, + &brw->wm.surf_bo[BTI_FRAGMENT_CONSTANTS]); + + if (ret) + return ret; + + nr_surfaces = BTI_FRAGMENT_CONSTANTS + 1; + } + else { + bo_reference(&brw->wm.surf_bo[SURF_FRAG_CONSTANTS], NULL); + } +#endif + + + /* PIPE_NEW_TEXTURE + */ + for (i = 0; i < brw->curr.num_fragment_sampler_views; i++) { + ret = brw_update_texture_surface(brw, + brw_texture(brw->curr.fragment_sampler_views[i]->texture), + &brw->wm.surf_bo[BTI_TEXTURE(i)]); + if (ret) + return ret; + + nr_surfaces = BTI_TEXTURE(i) + 1; + } + + /* Clear any inactive entries: + */ + for (i = brw->curr.fb.nr_cbufs; i < BRW_MAX_DRAW_BUFFERS; i++) + bo_reference(&brw->wm.surf_bo[BTI_COLOR_BUF(i)], NULL); + + if (!brw->curr.fragment_constants) + bo_reference(&brw->wm.surf_bo[BTI_FRAGMENT_CONSTANTS], NULL); + + /* XXX: no pipe_max_textures define?? */ + for (i = brw->curr.num_fragment_sampler_views; i < PIPE_MAX_SAMPLERS; i++) + bo_reference(&brw->wm.surf_bo[BTI_TEXTURE(i)], NULL); + + if (brw->wm.nr_surfaces != nr_surfaces) { + brw->wm.nr_surfaces = nr_surfaces; + brw->state.dirty.brw |= BRW_NEW_NR_WM_SURFACES; + } + + ret = brw_wm_get_binding_table(brw, &brw->wm.bind_bo); + if (ret) + return ret; + + return PIPE_OK; +} + +const struct brw_tracked_state brw_wm_surfaces = { + .dirty = { + .mesa = (PIPE_NEW_COLOR_BUFFERS | + PIPE_NEW_BOUND_TEXTURES | + PIPE_NEW_FRAGMENT_CONSTANTS | + PIPE_NEW_BLEND), + .brw = (BRW_NEW_CONTEXT | + BRW_NEW_WM_SURFACES), + .cache = 0 + }, + .prepare = prepare_wm_surfaces, +}; + + + diff --git a/src/gallium/drivers/i965/intel_decode.c b/src/gallium/drivers/i965/intel_decode.c new file mode 100644 index 0000000..36c04a3 --- /dev/null +++ b/src/gallium/drivers/i965/intel_decode.c @@ -0,0 +1,1785 @@ +/* -*- c-basic-offset: 4 -*- */ +/* + * Copyright © 2007 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * Eric Anholt + * + */ + +/** @file intel_decode.c + * This file contains code to print out batchbuffer contents in a + * human-readable format. + * + * The current version only supports i915 packets, and only pretty-prints a + * subset of them. The intention is for it to make just a best attempt to + * decode, but never crash in the process. + */ + +#include +#include +#include +#include + +#include "util/u_memory.h" +#include "util/u_string.h" +#include "intel_decode.h" + +/*#include "intel_chipset.h"*/ +#define IS_965(x) 1 /* XXX */ +#define IS_9XX(x) 1 /* XXX */ + +#define BUFFER_FAIL(_count, _len, _name) do { \ + fprintf(out, "Buffer size too small in %s (%d < %d)\n", \ + (_name), (_count), (_len)); \ + (*failures)++; \ + return count; \ +} while (0) + +static FILE *out; +static uint32_t saved_s2 = 0, saved_s4 = 0; +static char saved_s2_set = 0, saved_s4_set = 0; + +static float +int_as_float(uint32_t intval) +{ + union intfloat { + uint32_t i; + float f; + } uval; + + uval.i = intval; + return uval.f; +} + +static void +instr_out(const uint32_t *data, uint32_t hw_offset, unsigned int index, + char *fmt, ...) +{ + va_list va; + + fprintf(out, "0x%08x: 0x%08x:%s ", hw_offset + index * 4, data[index], + index == 0 ? "" : " "); + va_start(va, fmt); + vfprintf(out, fmt, va); + va_end(va); +} + + +static int +decode_mi(const uint32_t *data, int count, uint32_t hw_offset, int *failures) +{ + unsigned int opcode; + + struct { + uint32_t opcode; + int len_mask; + int min_len; + int max_len; + char *name; + } opcodes_mi[] = { + { 0x08, 0, 1, 1, "MI_ARB_ON_OFF" }, + { 0x0a, 0, 1, 1, "MI_BATCH_BUFFER_END" }, + { 0x31, 0x3f, 2, 2, "MI_BATCH_BUFFER_START" }, + { 0x14, 0x3f, 3, 3, "MI_DISPLAY_BUFFER_INFO" }, + { 0x04, 0, 1, 1, "MI_FLUSH" }, + { 0x22, 0, 3, 3, "MI_LOAD_REGISTER_IMM" }, + { 0x13, 0x3f, 2, 2, "MI_LOAD_SCAN_LINES_EXCL" }, + { 0x12, 0x3f, 2, 2, "MI_LOAD_SCAN_LINES_INCL" }, + { 0x00, 0, 1, 1, "MI_NOOP" }, + { 0x11, 0x3f, 2, 2, "MI_OVERLAY_FLIP" }, + { 0x07, 0, 1, 1, "MI_REPORT_HEAD" }, + { 0x18, 0x3f, 2, 2, "MI_SET_CONTEXT" }, + { 0x20, 0x3f, 3, 4, "MI_STORE_DATA_IMM" }, + { 0x21, 0x3f, 3, 4, "MI_STORE_DATA_INDEX" }, + { 0x24, 0x3f, 3, 3, "MI_STORE_REGISTER_MEM" }, + { 0x02, 0, 1, 1, "MI_USER_INTERRUPT" }, + { 0x03, 0, 1, 1, "MI_WAIT_FOR_EVENT" }, + }; + + + for (opcode = 0; opcode < Elements(opcodes_mi); opcode++) { + if ((data[0] & 0x1f800000) >> 23 == opcodes_mi[opcode].opcode) { + unsigned int len = 1, i; + + instr_out(data, hw_offset, 0, "%s\n", opcodes_mi[opcode].name); + if (opcodes_mi[opcode].max_len > 1) { + len = (data[0] & opcodes_mi[opcode].len_mask) + 2; + if (len < opcodes_mi[opcode].min_len || + len > opcodes_mi[opcode].max_len) + { + fprintf(out, "Bad length (%d) in %s, [%d, %d]\n", + len, opcodes_mi[opcode].name, + opcodes_mi[opcode].min_len, + opcodes_mi[opcode].max_len); + } + } + + for (i = 1; i < len; i++) { + if (i >= count) + BUFFER_FAIL(count, len, opcodes_mi[opcode].name); + instr_out(data, hw_offset, i, "dword %d\n", i); + } + + return len; + } + } + + instr_out(data, hw_offset, 0, "MI UNKNOWN\n"); + (*failures)++; + return 1; +} + +static int +decode_2d(const uint32_t *data, int count, uint32_t hw_offset, int *failures) +{ + unsigned int opcode, len; + char *format = NULL; + + struct { + uint32_t opcode; + int min_len; + int max_len; + char *name; + } opcodes_2d[] = { + { 0x40, 5, 5, "COLOR_BLT" }, + { 0x43, 6, 6, "SRC_COPY_BLT" }, + { 0x01, 8, 8, "XY_SETUP_BLT" }, + { 0x11, 9, 9, "XY_SETUP_MONO_PATTERN_SL_BLT" }, + { 0x03, 3, 3, "XY_SETUP_CLIP_BLT" }, + { 0x24, 2, 2, "XY_PIXEL_BLT" }, + { 0x25, 3, 3, "XY_SCANLINES_BLT" }, + { 0x26, 4, 4, "Y_TEXT_BLT" }, + { 0x31, 5, 134, "XY_TEXT_IMMEDIATE_BLT" }, + { 0x50, 6, 6, "XY_COLOR_BLT" }, + { 0x51, 6, 6, "XY_PAT_BLT" }, + { 0x76, 8, 8, "XY_PAT_CHROMA_BLT" }, + { 0x72, 7, 135, "XY_PAT_BLT_IMMEDIATE" }, + { 0x77, 9, 137, "XY_PAT_CHROMA_BLT_IMMEDIATE" }, + { 0x52, 9, 9, "XY_MONO_PAT_BLT" }, + { 0x59, 7, 7, "XY_MONO_PAT_FIXED_BLT" }, + { 0x53, 8, 8, "XY_SRC_COPY_BLT" }, + { 0x54, 8, 8, "XY_MONO_SRC_COPY_BLT" }, + { 0x71, 9, 137, "XY_MONO_SRC_COPY_IMMEDIATE_BLT" }, + { 0x55, 9, 9, "XY_FULL_BLT" }, + { 0x55, 9, 137, "XY_FULL_IMMEDIATE_PATTERN_BLT" }, + { 0x56, 9, 9, "XY_FULL_MONO_SRC_BLT" }, + { 0x75, 10, 138, "XY_FULL_MONO_SRC_IMMEDIATE_PATTERN_BLT" }, + { 0x57, 12, 12, "XY_FULL_MONO_PATTERN_BLT" }, + { 0x58, 12, 12, "XY_FULL_MONO_PATTERN_MONO_SRC_BLT" }, + }; + + switch ((data[0] & 0x1fc00000) >> 22) { + case 0x50: + instr_out(data, hw_offset, 0, + "XY_COLOR_BLT (rgb %sabled, alpha %sabled, dst tile %d)\n", + (data[0] & (1 << 20)) ? "en" : "dis", + (data[0] & (1 << 21)) ? "en" : "dis", + (data[0] >> 11) & 1); + + len = (data[0] & 0x000000ff) + 2; + if (len != 6) + fprintf(out, "Bad count in XY_COLOR_BLT\n"); + if (count < 6) + BUFFER_FAIL(count, len, "XY_COLOR_BLT"); + + switch ((data[1] >> 24) & 0x3) { + case 0: + format="8"; + break; + case 1: + format="565"; + break; + case 2: + format="1555"; + break; + case 3: + format="8888"; + break; + } + + instr_out(data, hw_offset, 1, "format %s, pitch %d, " + "clipping %sabled\n", format, + (short)(data[1] & 0xffff), + data[1] & (1 << 30) ? "en" : "dis"); + instr_out(data, hw_offset, 2, "(%d,%d)\n", + data[2] & 0xffff, data[2] >> 16); + instr_out(data, hw_offset, 3, "(%d,%d)\n", + data[3] & 0xffff, data[3] >> 16); + instr_out(data, hw_offset, 4, "offset 0x%08x\n", data[4]); + instr_out(data, hw_offset, 5, "color\n"); + return len; + case 0x53: + instr_out(data, hw_offset, 0, + "XY_SRC_COPY_BLT (rgb %sabled, alpha %sabled, " + "src tile %d, dst tile %d)\n", + (data[0] & (1 << 20)) ? "en" : "dis", + (data[0] & (1 << 21)) ? "en" : "dis", + (data[0] >> 15) & 1, + (data[0] >> 11) & 1); + + len = (data[0] & 0x000000ff) + 2; + if (len != 8) + fprintf(out, "Bad count in XY_SRC_COPY_BLT\n"); + if (count < 8) + BUFFER_FAIL(count, len, "XY_SRC_COPY_BLT"); + + switch ((data[1] >> 24) & 0x3) { + case 0: + format="8"; + break; + case 1: + format="565"; + break; + case 2: + format="1555"; + break; + case 3: + format="8888"; + break; + } + + instr_out(data, hw_offset, 1, "format %s, dst pitch %d, " + "clipping %sabled\n", format, + (short)(data[1] & 0xffff), + data[1] & (1 << 30) ? "en" : "dis"); + instr_out(data, hw_offset, 2, "dst (%d,%d)\n", + data[2] & 0xffff, data[2] >> 16); + instr_out(data, hw_offset, 3, "dst (%d,%d)\n", + data[3] & 0xffff, data[3] >> 16); + instr_out(data, hw_offset, 4, "dst offset 0x%08x\n", data[4]); + instr_out(data, hw_offset, 5, "src (%d,%d)\n", + data[5] & 0xffff, data[5] >> 16); + instr_out(data, hw_offset, 6, "src pitch %d\n", + (short)(data[6] & 0xffff)); + instr_out(data, hw_offset, 7, "src offset 0x%08x\n", data[7]); + return len; + } + + for (opcode = 0; opcode < Elements(opcodes_2d); opcode++) { + if ((data[0] & 0x1fc00000) >> 22 == opcodes_2d[opcode].opcode) { + unsigned int i; + + len = 1; + instr_out(data, hw_offset, 0, "%s\n", opcodes_2d[opcode].name); + if (opcodes_2d[opcode].max_len > 1) { + len = (data[0] & 0x000000ff) + 2; + if (len < opcodes_2d[opcode].min_len || + len > opcodes_2d[opcode].max_len) + { + fprintf(out, "Bad count in %s\n", opcodes_2d[opcode].name); + } + } + + for (i = 1; i < len; i++) { + if (i >= count) + BUFFER_FAIL(count, len, opcodes_2d[opcode].name); + instr_out(data, hw_offset, i, "dword %d\n", i); + } + + return len; + } + } + + instr_out(data, hw_offset, 0, "2D UNKNOWN\n"); + (*failures)++; + return 1; +} + +static int +decode_3d_1c(const uint32_t *data, int count, uint32_t hw_offset, int *failures) +{ + switch ((data[0] & 0x00f80000) >> 19) { + case 0x11: + instr_out(data, hw_offset, 0, "3DSTATE_DEPTH_SUBRECTANGLE_DISALBE\n"); + return 1; + case 0x10: + instr_out(data, hw_offset, 0, "3DSTATE_SCISSOR_ENABLE\n"); + return 1; + case 0x01: + instr_out(data, hw_offset, 0, "3DSTATE_MAP_COORD_SET_I830\n"); + return 1; + case 0x0a: + instr_out(data, hw_offset, 0, "3DSTATE_MAP_CUBE_I830\n"); + return 1; + case 0x05: + instr_out(data, hw_offset, 0, "3DSTATE_MAP_TEX_STREAM_I830\n"); + return 1; + } + + instr_out(data, hw_offset, 0, "3D UNKNOWN\n"); + (*failures)++; + return 1; +} + +/** Sets the string dstname to describe the destination of the PS instruction */ +static void +i915_get_instruction_dst(const uint32_t *data, int i, char *dstname, int do_mask) +{ + uint32_t a0 = data[i]; + int dst_nr = (a0 >> 14) & 0xf; + char dstmask[8]; + char *sat; + + if (do_mask) { + if (((a0 >> 10) & 0xf) == 0xf) { + dstmask[0] = 0; + } else { + int dstmask_index = 0; + + dstmask[dstmask_index++] = '.'; + if (a0 & (1 << 10)) + dstmask[dstmask_index++] = 'x'; + if (a0 & (1 << 11)) + dstmask[dstmask_index++] = 'y'; + if (a0 & (1 << 12)) + dstmask[dstmask_index++] = 'z'; + if (a0 & (1 << 13)) + dstmask[dstmask_index++] = 'w'; + dstmask[dstmask_index++] = 0; + } + + if (a0 & (1 << 22)) + sat = ".sat"; + else + sat = ""; + } else { + dstmask[0] = 0; + sat = ""; + } + + switch ((a0 >> 19) & 0x7) { + case 0: + if (dst_nr > 15) + fprintf(out, "bad destination reg R%d\n", dst_nr); + sprintf(dstname, "R%d%s%s", dst_nr, dstmask, sat); + break; + case 4: + if (dst_nr > 0) + fprintf(out, "bad destination reg oC%d\n", dst_nr); + sprintf(dstname, "oC%s%s", dstmask, sat); + break; + case 5: + if (dst_nr > 0) + fprintf(out, "bad destination reg oD%d\n", dst_nr); + sprintf(dstname, "oD%s%s", dstmask, sat); + break; + case 6: + if (dst_nr > 2) + fprintf(out, "bad destination reg U%d\n", dst_nr); + sprintf(dstname, "U%d%s%s", dst_nr, dstmask, sat); + break; + default: + sprintf(dstname, "RESERVED"); + break; + } +} + +static char * +i915_get_channel_swizzle(uint32_t select) +{ + switch (select & 0x7) { + case 0: + return (select & 8) ? "-x" : "x"; + case 1: + return (select & 8) ? "-y" : "y"; + case 2: + return (select & 8) ? "-z" : "z"; + case 3: + return (select & 8) ? "-w" : "w"; + case 4: + return (select & 8) ? "-0" : "0"; + case 5: + return (select & 8) ? "-1" : "1"; + default: + return (select & 8) ? "-bad" : "bad"; + } +} + +static void +i915_get_instruction_src_name(uint32_t src_type, uint32_t src_nr, char *name) +{ + switch (src_type) { + case 0: + sprintf(name, "R%d", src_nr); + if (src_nr > 15) + fprintf(out, "bad src reg %s\n", name); + break; + case 1: + if (src_nr < 8) + sprintf(name, "T%d", src_nr); + else if (src_nr == 8) + sprintf(name, "DIFFUSE"); + else if (src_nr == 9) + sprintf(name, "SPECULAR"); + else if (src_nr == 10) + sprintf(name, "FOG"); + else { + fprintf(out, "bad src reg T%d\n", src_nr); + sprintf(name, "RESERVED"); + } + break; + case 2: + sprintf(name, "C%d", src_nr); + if (src_nr > 31) + fprintf(out, "bad src reg %s\n", name); + break; + case 4: + sprintf(name, "oC"); + if (src_nr > 0) + fprintf(out, "bad src reg oC%d\n", src_nr); + break; + case 5: + sprintf(name, "oD"); + if (src_nr > 0) + fprintf(out, "bad src reg oD%d\n", src_nr); + break; + case 6: + sprintf(name, "U%d", src_nr); + if (src_nr > 2) + fprintf(out, "bad src reg %s\n", name); + break; + default: + fprintf(out, "bad src reg type %d\n", src_type); + sprintf(name, "RESERVED"); + break; + } +} + +static void +i915_get_instruction_src0(const uint32_t *data, int i, char *srcname) +{ + uint32_t a0 = data[i]; + uint32_t a1 = data[i + 1]; + int src_nr = (a0 >> 2) & 0x1f; + char *swizzle_x = i915_get_channel_swizzle((a1 >> 28) & 0xf); + char *swizzle_y = i915_get_channel_swizzle((a1 >> 24) & 0xf); + char *swizzle_z = i915_get_channel_swizzle((a1 >> 20) & 0xf); + char *swizzle_w = i915_get_channel_swizzle((a1 >> 16) & 0xf); + char swizzle[100]; + + i915_get_instruction_src_name((a0 >> 7) & 0x7, src_nr, srcname); + util_snprintf(swizzle, sizeof(swizzle), ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z, swizzle_w); + if (strcmp(swizzle, ".xyzw") != 0) + strcat(srcname, swizzle); +} + +static void +i915_get_instruction_src1(const uint32_t *data, int i, char *srcname) +{ + uint32_t a1 = data[i + 1]; + uint32_t a2 = data[i + 2]; + int src_nr = (a1 >> 8) & 0x1f; + char *swizzle_x = i915_get_channel_swizzle((a1 >> 4) & 0xf); + char *swizzle_y = i915_get_channel_swizzle((a1 >> 0) & 0xf); + char *swizzle_z = i915_get_channel_swizzle((a2 >> 28) & 0xf); + char *swizzle_w = i915_get_channel_swizzle((a2 >> 24) & 0xf); + char swizzle[100]; + + i915_get_instruction_src_name((a1 >> 13) & 0x7, src_nr, srcname); + util_snprintf(swizzle, sizeof(swizzle), ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z, swizzle_w); + if (strcmp(swizzle, ".xyzw") != 0) + strcat(srcname, swizzle); +} + +static void +i915_get_instruction_src2(const uint32_t *data, int i, char *srcname) +{ + uint32_t a2 = data[i + 2]; + int src_nr = (a2 >> 16) & 0x1f; + char *swizzle_x = i915_get_channel_swizzle((a2 >> 12) & 0xf); + char *swizzle_y = i915_get_channel_swizzle((a2 >> 8) & 0xf); + char *swizzle_z = i915_get_channel_swizzle((a2 >> 4) & 0xf); + char *swizzle_w = i915_get_channel_swizzle((a2 >> 0) & 0xf); + char swizzle[100]; + + i915_get_instruction_src_name((a2 >> 21) & 0x7, src_nr, srcname); + util_snprintf(swizzle, sizeof(swizzle), ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z, swizzle_w); + if (strcmp(swizzle, ".xyzw") != 0) + strcat(srcname, swizzle); +} + +static void +i915_get_instruction_addr(uint32_t src_type, uint32_t src_nr, char *name) +{ + switch (src_type) { + case 0: + sprintf(name, "R%d", src_nr); + if (src_nr > 15) + fprintf(out, "bad src reg %s\n", name); + break; + case 1: + if (src_nr < 8) + sprintf(name, "T%d", src_nr); + else if (src_nr == 8) + sprintf(name, "DIFFUSE"); + else if (src_nr == 9) + sprintf(name, "SPECULAR"); + else if (src_nr == 10) + sprintf(name, "FOG"); + else { + fprintf(out, "bad src reg T%d\n", src_nr); + sprintf(name, "RESERVED"); + } + break; + case 4: + sprintf(name, "oC"); + if (src_nr > 0) + fprintf(out, "bad src reg oC%d\n", src_nr); + break; + case 5: + sprintf(name, "oD"); + if (src_nr > 0) + fprintf(out, "bad src reg oD%d\n", src_nr); + break; + default: + fprintf(out, "bad src reg type %d\n", src_type); + sprintf(name, "RESERVED"); + break; + } +} + +static void +i915_decode_alu1(const uint32_t *data, uint32_t hw_offset, + int i, char *instr_prefix, char *op_name) +{ + char dst[100], src0[100]; + + i915_get_instruction_dst(data, i, dst, 1); + i915_get_instruction_src0(data, i, src0); + + instr_out(data, hw_offset, i++, "%s: %s %s, %s\n", instr_prefix, + op_name, dst, src0); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); +} + +static void +i915_decode_alu2(const uint32_t *data, uint32_t hw_offset, + int i, char *instr_prefix, char *op_name) +{ + char dst[100], src0[100], src1[100]; + + i915_get_instruction_dst(data, i, dst, 1); + i915_get_instruction_src0(data, i, src0); + i915_get_instruction_src1(data, i, src1); + + instr_out(data, hw_offset, i++, "%s: %s %s, %s, %s\n", instr_prefix, + op_name, dst, src0, src1); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); +} + +static void +i915_decode_alu3(const uint32_t *data, uint32_t hw_offset, + int i, char *instr_prefix, char *op_name) +{ + char dst[100], src0[100], src1[100], src2[100]; + + i915_get_instruction_dst(data, i, dst, 1); + i915_get_instruction_src0(data, i, src0); + i915_get_instruction_src1(data, i, src1); + i915_get_instruction_src2(data, i, src2); + + instr_out(data, hw_offset, i++, "%s: %s %s, %s, %s, %s\n", instr_prefix, + op_name, dst, src0, src1, src2); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); +} + +static void +i915_decode_tex(const uint32_t *data, uint32_t hw_offset, int i, char *instr_prefix, + char *tex_name) +{ + uint32_t t0 = data[i]; + uint32_t t1 = data[i + 1]; + char dst_name[100]; + char addr_name[100]; + int sampler_nr; + + i915_get_instruction_dst(data, i, dst_name, 0); + i915_get_instruction_addr((t1 >> 24) & 0x7, + (t1 >> 17) & 0xf, + addr_name); + sampler_nr = t0 & 0xf; + + instr_out(data, hw_offset, i++, "%s: %s %s, S%d, %s\n", instr_prefix, + tex_name, dst_name, sampler_nr, addr_name); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); +} + +static void +i915_decode_dcl(const uint32_t *data, uint32_t hw_offset, int i, char *instr_prefix) +{ + uint32_t d0 = data[i]; + char *sampletype; + int dcl_nr = (d0 >> 14) & 0xf; + char *dcl_x = d0 & (1 << 10) ? "x" : ""; + char *dcl_y = d0 & (1 << 11) ? "y" : ""; + char *dcl_z = d0 & (1 << 12) ? "z" : ""; + char *dcl_w = d0 & (1 << 13) ? "w" : ""; + char dcl_mask[10]; + + switch ((d0 >> 19) & 0x3) { + case 1: + util_snprintf(dcl_mask, sizeof(dcl_mask), ".%s%s%s%s", dcl_x, dcl_y, dcl_z, dcl_w); + if (strcmp(dcl_mask, ".") == 0) + fprintf(out, "bad (empty) dcl mask\n"); + + if (dcl_nr > 10) + fprintf(out, "bad T%d dcl register number\n", dcl_nr); + if (dcl_nr < 8) { + if (strcmp(dcl_mask, ".x") != 0 && + strcmp(dcl_mask, ".xy") != 0 && + strcmp(dcl_mask, ".xz") != 0 && + strcmp(dcl_mask, ".w") != 0 && + strcmp(dcl_mask, ".xyzw") != 0) { + fprintf(out, "bad T%d.%s dcl mask\n", dcl_nr, dcl_mask); + } + instr_out(data, hw_offset, i++, "%s: DCL T%d%s\n", instr_prefix, + dcl_nr, dcl_mask); + } else { + if (strcmp(dcl_mask, ".xz") == 0) + fprintf(out, "errataed bad dcl mask %s\n", dcl_mask); + else if (strcmp(dcl_mask, ".xw") == 0) + fprintf(out, "errataed bad dcl mask %s\n", dcl_mask); + else if (strcmp(dcl_mask, ".xzw") == 0) + fprintf(out, "errataed bad dcl mask %s\n", dcl_mask); + + if (dcl_nr == 8) { + instr_out(data, hw_offset, i++, "%s: DCL DIFFUSE%s\n", instr_prefix, + dcl_mask); + } else if (dcl_nr == 9) { + instr_out(data, hw_offset, i++, "%s: DCL SPECULAR%s\n", instr_prefix, + dcl_mask); + } else if (dcl_nr == 10) { + instr_out(data, hw_offset, i++, "%s: DCL FOG%s\n", instr_prefix, + dcl_mask); + } + } + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); + break; + case 3: + switch ((d0 >> 22) & 0x3) { + case 0: + sampletype = "2D"; + break; + case 1: + sampletype = "CUBE"; + break; + case 2: + sampletype = "3D"; + break; + default: + sampletype = "RESERVED"; + break; + } + if (dcl_nr > 15) + fprintf(out, "bad S%d dcl register number\n", dcl_nr); + instr_out(data, hw_offset, i++, "%s: DCL S%d %s\n", instr_prefix, + dcl_nr, sampletype); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); + break; + default: + instr_out(data, hw_offset, i++, "%s: DCL RESERVED%d\n", instr_prefix, dcl_nr); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); + } +} + +static void +i915_decode_instruction(const uint32_t *data, uint32_t hw_offset, + int i, char *instr_prefix) +{ + switch ((data[i] >> 24) & 0x1f) { + case 0x0: + instr_out(data, hw_offset, i++, "%s: NOP\n", instr_prefix); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); + break; + case 0x01: + i915_decode_alu2(data, hw_offset, i, instr_prefix, "ADD"); + break; + case 0x02: + i915_decode_alu1(data, hw_offset, i, instr_prefix, "MOV"); + break; + case 0x03: + i915_decode_alu2(data, hw_offset, i, instr_prefix, "MUL"); + break; + case 0x04: + i915_decode_alu3(data, hw_offset, i, instr_prefix, "MAD"); + break; + case 0x05: + i915_decode_alu3(data, hw_offset, i, instr_prefix, "DP2ADD"); + break; + case 0x06: + i915_decode_alu2(data, hw_offset, i, instr_prefix, "DP3"); + break; + case 0x07: + i915_decode_alu2(data, hw_offset, i, instr_prefix, "DP4"); + break; + case 0x08: + i915_decode_alu1(data, hw_offset, i, instr_prefix, "FRC"); + break; + case 0x09: + i915_decode_alu1(data, hw_offset, i, instr_prefix, "RCP"); + break; + case 0x0a: + i915_decode_alu1(data, hw_offset, i, instr_prefix, "RSQ"); + break; + case 0x0b: + i915_decode_alu1(data, hw_offset, i, instr_prefix, "EXP"); + break; + case 0x0c: + i915_decode_alu1(data, hw_offset, i, instr_prefix, "LOG"); + break; + case 0x0d: + i915_decode_alu2(data, hw_offset, i, instr_prefix, "CMP"); + break; + case 0x0e: + i915_decode_alu2(data, hw_offset, i, instr_prefix, "MIN"); + break; + case 0x0f: + i915_decode_alu2(data, hw_offset, i, instr_prefix, "MAX"); + break; + case 0x10: + i915_decode_alu1(data, hw_offset, i, instr_prefix, "FLR"); + break; + case 0x11: + i915_decode_alu1(data, hw_offset, i, instr_prefix, "MOD"); + break; + case 0x12: + i915_decode_alu1(data, hw_offset, i, instr_prefix, "TRC"); + break; + case 0x13: + i915_decode_alu2(data, hw_offset, i, instr_prefix, "SGE"); + break; + case 0x14: + i915_decode_alu2(data, hw_offset, i, instr_prefix, "SLT"); + break; + case 0x15: + i915_decode_tex(data, hw_offset, i, instr_prefix, "TEXLD"); + break; + case 0x16: + i915_decode_tex(data, hw_offset, i, instr_prefix, "TEXLDP"); + break; + case 0x17: + i915_decode_tex(data, hw_offset, i, instr_prefix, "TEXLDB"); + break; + case 0x19: + i915_decode_dcl(data, hw_offset, i, instr_prefix); + break; + default: + instr_out(data, hw_offset, i++, "%s: unknown\n", instr_prefix); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); + instr_out(data, hw_offset, i++, "%s\n", instr_prefix); + break; + } +} + +static int +decode_3d_1d(const uint32_t *data, int count, uint32_t hw_offset, int *failures, int i830) +{ + unsigned int len, i, c, opcode, word, map, sampler, instr; + char *format; + + struct { + uint32_t opcode; + int i830_only; + int min_len; + int max_len; + char *name; + } opcodes_3d_1d[] = { + { 0x8e, 0, 3, 3, "3DSTATE_BUFFER_INFO" }, + { 0x86, 0, 4, 4, "3DSTATE_CHROMA_KEY" }, + { 0x9c, 0, 1, 1, "3DSTATE_CLEAR_PARAMETERS" }, + { 0x88, 0, 2, 2, "3DSTATE_CONSTANT_BLEND_COLOR" }, + { 0x99, 0, 2, 2, "3DSTATE_DEFAULT_DIFFUSE" }, + { 0x9a, 0, 2, 2, "3DSTATE_DEFAULT_SPECULAR" }, + { 0x98, 0, 2, 2, "3DSTATE_DEFAULT_Z" }, + { 0x97, 0, 2, 2, "3DSTATE_DEPTH_OFFSET_SCALE" }, + { 0x85, 0, 2, 2, "3DSTATE_DEST_BUFFER_VARIABLES" }, + { 0x80, 0, 5, 5, "3DSTATE_DRAWING_RECTANGLE" }, + { 0x8e, 0, 3, 3, "3DSTATE_BUFFER_INFO" }, + { 0x9d, 0, 65, 65, "3DSTATE_FILTER_COEFFICIENTS_4X4" }, + { 0x9e, 0, 4, 4, "3DSTATE_MONO_FILTER" }, + { 0x89, 0, 4, 4, "3DSTATE_FOG_MODE" }, + { 0x8f, 0, 2, 16, "3DSTATE_MAP_PALLETE_LOAD_32" }, + { 0x81, 0, 3, 3, "3DSTATE_SCISSOR_RECTANGLE" }, + { 0x83, 0, 2, 2, "3DSTATE_SPAN_STIPPLE" }, + { 0x8c, 1, 2, 2, "3DSTATE_MAP_COORD_TRANSFORM_I830" }, + { 0x8b, 1, 2, 2, "3DSTATE_MAP_VERTEX_TRANSFORM_I830" }, + { 0x8d, 1, 3, 3, "3DSTATE_W_STATE_I830" }, + { 0x01, 1, 2, 2, "3DSTATE_COLOR_FACTOR_I830" }, + { 0x02, 1, 2, 2, "3DSTATE_MAP_COORD_SETBIND_I830" }, + }; + + switch ((data[0] & 0x00ff0000) >> 16) { + case 0x07: + /* This instruction is unusual. A 0 length means just 1 DWORD instead of + * 2. The 0 length is specified in one place to be unsupported, but + * stated to be required in another, and 0 length LOAD_INDIRECTs appear + * to cause no harm at least. + */ + instr_out(data, hw_offset, 0, "3DSTATE_LOAD_INDIRECT\n"); + len = (data[0] & 0x000000ff) + 1; + i = 1; + if (data[0] & (0x01 << 8)) { + if (i + 2 >= count) + BUFFER_FAIL(count, len, "3DSTATE_LOAD_INDIRECT"); + instr_out(data, hw_offset, i++, "SIS.0\n"); + instr_out(data, hw_offset, i++, "SIS.1\n"); + } + if (data[0] & (0x02 << 8)) { + if (i + 1 >= count) + BUFFER_FAIL(count, len, "3DSTATE_LOAD_INDIRECT"); + instr_out(data, hw_offset, i++, "DIS.0\n"); + } + if (data[0] & (0x04 << 8)) { + if (i + 2 >= count) + BUFFER_FAIL(count, len, "3DSTATE_LOAD_INDIRECT"); + instr_out(data, hw_offset, i++, "SSB.0\n"); + instr_out(data, hw_offset, i++, "SSB.1\n"); + } + if (data[0] & (0x08 << 8)) { + if (i + 2 >= count) + BUFFER_FAIL(count, len, "3DSTATE_LOAD_INDIRECT"); + instr_out(data, hw_offset, i++, "MSB.0\n"); + instr_out(data, hw_offset, i++, "MSB.1\n"); + } + if (data[0] & (0x10 << 8)) { + if (i + 2 >= count) + BUFFER_FAIL(count, len, "3DSTATE_LOAD_INDIRECT"); + instr_out(data, hw_offset, i++, "PSP.0\n"); + instr_out(data, hw_offset, i++, "PSP.1\n"); + } + if (data[0] & (0x20 << 8)) { + if (i + 2 >= count) + BUFFER_FAIL(count, len, "3DSTATE_LOAD_INDIRECT"); + instr_out(data, hw_offset, i++, "PSC.0\n"); + instr_out(data, hw_offset, i++, "PSC.1\n"); + } + if (len != i) { + fprintf(out, "Bad count in 3DSTATE_LOAD_INDIRECT\n"); + (*failures)++; + return len; + } + return len; + case 0x04: + instr_out(data, hw_offset, 0, "3DSTATE_LOAD_STATE_IMMEDIATE_1\n"); + len = (data[0] & 0x0000000f) + 2; + i = 1; + for (word = 0; word <= 7; word++) { + if (data[0] & (1 << (4 + word))) { + if (i >= count) + BUFFER_FAIL(count, len, "3DSTATE_LOAD_STATE_IMMEDIATE_1"); + + /* save vertex state for decode */ + if (word == 2) { + saved_s2_set = 1; + saved_s2 = data[i]; + } + if (word == 4) { + saved_s4_set = 1; + saved_s4 = data[i]; + } + + instr_out(data, hw_offset, i++, "S%d\n", word); + } + } + if (len != i) { + fprintf(out, "Bad count in 3DSTATE_LOAD_INDIRECT\n"); + (*failures)++; + } + return len; + case 0x00: + instr_out(data, hw_offset, 0, "3DSTATE_MAP_STATE\n"); + len = (data[0] & 0x0000003f) + 2; + instr_out(data, hw_offset, 1, "mask\n"); + + i = 2; + for (map = 0; map <= 15; map++) { + if (data[1] & (1 << map)) { + if (i + 3 >= count) + BUFFER_FAIL(count, len, "3DSTATE_MAP_STATE"); + instr_out(data, hw_offset, i++, "map %d MS2\n", map); + instr_out(data, hw_offset, i++, "map %d MS3\n", map); + instr_out(data, hw_offset, i++, "map %d MS4\n", map); + } + } + if (len != i) { + fprintf(out, "Bad count in 3DSTATE_MAP_STATE\n"); + (*failures)++; + return len; + } + return len; + case 0x06: + instr_out(data, hw_offset, 0, "3DSTATE_PIXEL_SHADER_CONSTANTS\n"); + len = (data[0] & 0x000000ff) + 2; + + i = 2; + for (c = 0; c <= 31; c++) { + if (data[1] & (1 << c)) { + if (i + 4 >= count) + BUFFER_FAIL(count, len, "3DSTATE_PIXEL_SHADER_CONSTANTS"); + instr_out(data, hw_offset, i, "C%d.X = %f\n", + c, int_as_float(data[i])); + i++; + instr_out(data, hw_offset, i, "C%d.Y = %f\n", + c, int_as_float(data[i])); + i++; + instr_out(data, hw_offset, i, "C%d.Z = %f\n", + c, int_as_float(data[i])); + i++; + instr_out(data, hw_offset, i, "C%d.W = %f\n", + c, int_as_float(data[i])); + i++; + } + } + if (len != i) { + fprintf(out, "Bad count in 3DSTATE_PIXEL_SHADER_CONSTANTS\n"); + (*failures)++; + } + return len; + case 0x05: + instr_out(data, hw_offset, 0, "3DSTATE_PIXEL_SHADER_PROGRAM\n"); + len = (data[0] & 0x000000ff) + 2; + if ((len - 1) % 3 != 0 || len > 370) { + fprintf(out, "Bad count in 3DSTATE_PIXEL_SHADER_PROGRAM\n"); + (*failures)++; + } + i = 1; + for (instr = 0; instr < (len - 1) / 3; instr++) { + char instr_prefix[10]; + + if (i + 3 >= count) + BUFFER_FAIL(count, len, "3DSTATE_PIXEL_SHADER_PROGRAM"); + util_snprintf(instr_prefix, sizeof(instr_prefix), "PS%03d", instr); + i915_decode_instruction(data, hw_offset, i, instr_prefix); + i += 3; + } + return len; + case 0x01: + if (i830) + break; + instr_out(data, hw_offset, 0, "3DSTATE_SAMPLER_STATE\n"); + instr_out(data, hw_offset, 1, "mask\n"); + len = (data[0] & 0x0000003f) + 2; + i = 2; + for (sampler = 0; sampler <= 15; sampler++) { + if (data[1] & (1 << sampler)) { + if (i + 3 >= count) + BUFFER_FAIL(count, len, "3DSTATE_SAMPLER_STATE"); + instr_out(data, hw_offset, i++, "sampler %d SS2\n", + sampler); + instr_out(data, hw_offset, i++, "sampler %d SS3\n", + sampler); + instr_out(data, hw_offset, i++, "sampler %d SS4\n", + sampler); + } + } + if (len != i) { + fprintf(out, "Bad count in 3DSTATE_SAMPLER_STATE\n"); + (*failures)++; + } + return len; + case 0x85: + len = (data[0] & 0x0000000f) + 2; + + if (len != 2) + fprintf(out, "Bad count in 3DSTATE_DEST_BUFFER_VARIABLES\n"); + if (count < 2) + BUFFER_FAIL(count, len, "3DSTATE_DEST_BUFFER_VARIABLES"); + + instr_out(data, hw_offset, 0, + "3DSTATE_DEST_BUFFER_VARIABLES\n"); + + switch ((data[1] >> 8) & 0xf) { + case 0x0: format = "g8"; break; + case 0x1: format = "x1r5g5b5"; break; + case 0x2: format = "r5g6b5"; break; + case 0x3: format = "a8r8g8b8"; break; + case 0x4: format = "ycrcb_swapy"; break; + case 0x5: format = "ycrcb_normal"; break; + case 0x6: format = "ycrcb_swapuv"; break; + case 0x7: format = "ycrcb_swapuvy"; break; + case 0x8: format = "a4r4g4b4"; break; + case 0x9: format = "a1r5g5b5"; break; + case 0xa: format = "a2r10g10b10"; break; + default: format = "BAD"; break; + } + instr_out(data, hw_offset, 1, "%s format, early Z %sabled\n", + format, + (data[1] & (1 << 31)) ? "en" : "dis"); + return len; + } + + for (opcode = 0; opcode < Elements(opcodes_3d_1d); opcode++) { + if (opcodes_3d_1d[opcode].i830_only && !i830) + continue; + + if (((data[0] & 0x00ff0000) >> 16) == opcodes_3d_1d[opcode].opcode) { + len = 1; + + instr_out(data, hw_offset, 0, "%s\n", opcodes_3d_1d[opcode].name); + if (opcodes_3d_1d[opcode].max_len > 1) { + len = (data[0] & 0x0000ffff) + 2; + if (len < opcodes_3d_1d[opcode].min_len || + len > opcodes_3d_1d[opcode].max_len) + { + fprintf(out, "Bad count in %s\n", + opcodes_3d_1d[opcode].name); + (*failures)++; + } + } + + for (i = 1; i < len; i++) { + if (i >= count) + BUFFER_FAIL(count, len, opcodes_3d_1d[opcode].name); + instr_out(data, hw_offset, i, "dword %d\n", i); + } + + return len; + } + } + + instr_out(data, hw_offset, 0, "3D UNKNOWN\n"); + (*failures)++; + return 1; +} + +static int +decode_3d_primitive(const uint32_t *data, int count, uint32_t hw_offset, + int *failures) +{ + char immediate = (data[0] & (1 << 23)) == 0; + unsigned int len, i; + char *primtype; + + switch ((data[0] >> 18) & 0xf) { + case 0x0: primtype = "TRILIST"; break; + case 0x1: primtype = "TRISTRIP"; break; + case 0x2: primtype = "TRISTRIP_REVERSE"; break; + case 0x3: primtype = "TRIFAN"; break; + case 0x4: primtype = "POLYGON"; break; + case 0x5: primtype = "LINELIST"; break; + case 0x6: primtype = "LINESTRIP"; break; + case 0x7: primtype = "RECTLIST"; break; + case 0x8: primtype = "POINTLIST"; break; + case 0x9: primtype = "DIB"; break; + case 0xa: primtype = "CLEAR_RECT"; break; + default: primtype = "unknown"; break; + } + + /* XXX: 3DPRIM_DIB not supported */ + if (immediate) { + len = (data[0] & 0x0003ffff) + 2; + instr_out(data, hw_offset, 0, "3DPRIMITIVE inline %s\n", primtype); + if (count < len) + BUFFER_FAIL(count, len, "3DPRIMITIVE inline"); + if (!saved_s2_set || !saved_s4_set) { + fprintf(out, "unknown vertex format\n"); + for (i = 1; i < len; i++) { + instr_out(data, hw_offset, i, + " vertex data (%f float)\n", + int_as_float(data[i])); + } + } else { + unsigned int vertex = 0; + for (i = 1; i < len;) { + unsigned int tc; + +#define VERTEX_OUT(fmt, ...) do { \ + if (i < len) \ + instr_out(data, hw_offset, i, " V%d."fmt"\n", vertex, __VA_ARGS__); \ + else \ + fprintf(out, " missing data in V%d\n", vertex); \ + i++; \ +} while (0) + + VERTEX_OUT("X = %f", int_as_float(data[i])); + VERTEX_OUT("Y = %f", int_as_float(data[i])); + switch (saved_s4 >> 6 & 0x7) { + case 0x1: + VERTEX_OUT("Z = %f", int_as_float(data[i])); + break; + case 0x2: + VERTEX_OUT("Z = %f", int_as_float(data[i])); + VERTEX_OUT("W = %f", int_as_float(data[i])); + break; + case 0x3: + break; + case 0x4: + VERTEX_OUT("W = %f", int_as_float(data[i])); + break; + default: + fprintf(out, "bad S4 position mask\n"); + } + + if (saved_s4 & (1 << 10)) { + VERTEX_OUT("color = (A=0x%02x, R=0x%02x, G=0x%02x, " + "B=0x%02x)", + data[i] >> 24, + (data[i] >> 16) & 0xff, + (data[i] >> 8) & 0xff, + data[i] & 0xff); + } + if (saved_s4 & (1 << 11)) { + VERTEX_OUT("spec = (A=0x%02x, R=0x%02x, G=0x%02x, " + "B=0x%02x)", + data[i] >> 24, + (data[i] >> 16) & 0xff, + (data[i] >> 8) & 0xff, + data[i] & 0xff); + } + if (saved_s4 & (1 << 12)) + VERTEX_OUT("width = 0x%08x)", data[i]); + + for (tc = 0; tc <= 7; tc++) { + switch ((saved_s2 >> (tc * 4)) & 0xf) { + case 0x0: + VERTEX_OUT("T%d.X = %f", tc, int_as_float(data[i])); + VERTEX_OUT("T%d.Y = %f", tc, int_as_float(data[i])); + break; + case 0x1: + VERTEX_OUT("T%d.X = %f", tc, int_as_float(data[i])); + VERTEX_OUT("T%d.Y = %f", tc, int_as_float(data[i])); + VERTEX_OUT("T%d.Z = %f", tc, int_as_float(data[i])); + break; + case 0x2: + VERTEX_OUT("T%d.X = %f", tc, int_as_float(data[i])); + VERTEX_OUT("T%d.Y = %f", tc, int_as_float(data[i])); + VERTEX_OUT("T%d.Z = %f", tc, int_as_float(data[i])); + VERTEX_OUT("T%d.W = %f", tc, int_as_float(data[i])); + break; + case 0x3: + VERTEX_OUT("T%d.X = %f", tc, int_as_float(data[i])); + break; + case 0x4: + VERTEX_OUT("T%d.XY = 0x%08x half-float", tc, data[i]); + break; + case 0x5: + VERTEX_OUT("T%d.XY = 0x%08x half-float", tc, data[i]); + VERTEX_OUT("T%d.ZW = 0x%08x half-float", tc, data[i]); + break; + case 0xf: + break; + default: + fprintf(out, "bad S2.T%d format\n", tc); + } + } + vertex++; + } + } + } else { + /* indirect vertices */ + len = data[0] & 0x0000ffff; /* index count */ + if (data[0] & (1 << 17)) { + /* random vertex access */ + if (count < (len + 1) / 2 + 1) { + BUFFER_FAIL(count, (len + 1) / 2 + 1, + "3DPRIMITIVE random indirect"); + } + instr_out(data, hw_offset, 0, + "3DPRIMITIVE random indirect %s (%d)\n", primtype, len); + if (len == 0) { + /* vertex indices continue until 0xffff is found */ + for (i = 1; i < count; i++) { + if ((data[i] & 0xffff) == 0xffff) { + instr_out(data, hw_offset, i, + " indices: (terminator)\n"); + return i; + } else if ((data[i] >> 16) == 0xffff) { + instr_out(data, hw_offset, i, + " indices: 0x%04x, " + "(terminator)\n", + data[i] & 0xffff); + return i; + } else { + instr_out(data, hw_offset, i, + " indices: 0x%04x, 0x%04x\n", + data[i] & 0xffff, data[i] >> 16); + } + } + fprintf(out, + "3DPRIMITIVE: no terminator found in index buffer\n"); + (*failures)++; + return count; + } else { + /* fixed size vertex index buffer */ + for (i = 0; i < len; i += 2) { + if (i * 2 == len - 1) { + instr_out(data, hw_offset, i, + " indices: 0x%04x\n", + data[i] & 0xffff); + } else { + instr_out(data, hw_offset, i, + " indices: 0x%04x, 0x%04x\n", + data[i] & 0xffff, data[i] >> 16); + } + } + } + return (len + 1) / 2 + 1; + } else { + /* sequential vertex access */ + if (count < 2) + BUFFER_FAIL(count, 2, "3DPRIMITIVE seq indirect"); + instr_out(data, hw_offset, 0, + "3DPRIMITIVE sequential indirect %s, %d starting from " + "%d\n", primtype, len, data[1] & 0xffff); + instr_out(data, hw_offset, 1, " start\n"); + return 2; + } + } + + return len; +} + +static int +decode_3d(const uint32_t *data, int count, uint32_t hw_offset, int *failures) +{ + unsigned int opcode; + + struct { + uint32_t opcode; + int min_len; + int max_len; + char *name; + } opcodes_3d[] = { + { 0x06, 1, 1, "3DSTATE_ANTI_ALIASING" }, + { 0x08, 1, 1, "3DSTATE_BACKFACE_STENCIL_OPS" }, + { 0x09, 1, 1, "3DSTATE_BACKFACE_STENCIL_MASKS" }, + { 0x16, 1, 1, "3DSTATE_COORD_SET_BINDINGS" }, + { 0x15, 1, 1, "3DSTATE_FOG_COLOR" }, + { 0x0b, 1, 1, "3DSTATE_INDEPENDENT_ALPHA_BLEND" }, + { 0x0d, 1, 1, "3DSTATE_MODES_4" }, + { 0x0c, 1, 1, "3DSTATE_MODES_5" }, + { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES" }, + }; + + switch ((data[0] & 0x1f000000) >> 24) { + case 0x1f: + return decode_3d_primitive(data, count, hw_offset, failures); + case 0x1d: + return decode_3d_1d(data, count, hw_offset, failures, 0); + case 0x1c: + return decode_3d_1c(data, count, hw_offset, failures); + } + + for (opcode = 0; opcode < Elements(opcodes_3d); opcode++) { + if ((data[0] & 0x1f000000) >> 24 == opcodes_3d[opcode].opcode) { + unsigned int len = 1, i; + + instr_out(data, hw_offset, 0, "%s\n", opcodes_3d[opcode].name); + if (opcodes_3d[opcode].max_len > 1) { + len = (data[0] & 0xff) + 2; + if (len < opcodes_3d[opcode].min_len || + len > opcodes_3d[opcode].max_len) + { + fprintf(out, "Bad count in %s\n", opcodes_3d[opcode].name); + } + } + + for (i = 1; i < len; i++) { + if (i >= count) + BUFFER_FAIL(count, len, opcodes_3d[opcode].name); + instr_out(data, hw_offset, i, "dword %d\n", i); + } + return len; + } + } + + instr_out(data, hw_offset, 0, "3D UNKNOWN\n"); + (*failures)++; + return 1; +} + +static const char * +get_965_surfacetype(unsigned int surfacetype) +{ + switch (surfacetype) { + case 0: return "1D"; + case 1: return "2D"; + case 2: return "3D"; + case 3: return "CUBE"; + case 4: return "BUFFER"; + case 7: return "NULL"; + default: return "unknown"; + } +} + +static const char * +get_965_depthformat(unsigned int depthformat) +{ + switch (depthformat) { + case 0: return "s8_z24float"; + case 1: return "z32float"; + case 2: return "z24s8"; + case 5: return "z16"; + default: return "unknown"; + } +} + +static const char * +get_965_element_component(uint32_t data, int component) +{ + uint32_t component_control = (data >> (16 + (3 - component) * 4)) & 0x7; + + switch (component_control) { + case 0: + return "nostore"; + case 1: + switch (component) { + case 0: return "X"; + case 1: return "Y"; + case 2: return "Z"; + case 3: return "W"; + default: return "fail"; + } + case 2: + return "0.0"; + case 3: + return "1.0"; + case 4: + return "0x1"; + case 5: + return "VID"; + default: + return "fail"; + } +} + +static const char * +get_965_prim_type(uint32_t data) +{ + uint32_t primtype = (data >> 10) & 0x1f; + + switch (primtype) { + case 0x01: return "point list"; + case 0x02: return "line list"; + case 0x03: return "line strip"; + case 0x04: return "tri list"; + case 0x05: return "tri strip"; + case 0x06: return "tri fan"; + case 0x07: return "quad list"; + case 0x08: return "quad strip"; + case 0x09: return "line list adj"; + case 0x0a: return "line strip adj"; + case 0x0b: return "tri list adj"; + case 0x0c: return "tri strip adj"; + case 0x0d: return "tri strip reverse"; + case 0x0e: return "polygon"; + case 0x0f: return "rect list"; + case 0x10: return "line loop"; + case 0x11: return "point list bf"; + case 0x12: return "line strip cont"; + case 0x13: return "line strip bf"; + case 0x14: return "line strip cont bf"; + case 0x15: return "tri fan no stipple"; + default: return "fail"; + } +} + +static int +decode_3d_965(const uint32_t *data, int count, uint32_t hw_offset, int *failures) +{ + unsigned int opcode, len; + int i; + + struct { + uint32_t opcode; + int min_len; + int max_len; + char *name; + } opcodes_3d[] = { + { 0x6000, 3, 3, "URB_FENCE" }, + { 0x6001, 2, 2, "CS_URB_STATE" }, + { 0x6002, 2, 2, "CONSTANT_BUFFER" }, + { 0x6101, 6, 6, "STATE_BASE_ADDRESS" }, + { 0x6102, 2, 2 , "STATE_SIP" }, + { 0x6104, 1, 1, "3DSTATE_PIPELINE_SELECT" }, + { 0x680b, 1, 1, "3DSTATE_VF_STATISTICS" }, + { 0x6904, 1, 1, "3DSTATE_PIPELINE_SELECT" }, + { 0x7800, 7, 7, "3DSTATE_PIPELINED_POINTERS" }, + { 0x7801, 6, 6, "3DSTATE_BINDING_TABLE_POINTERS" }, + { 0x780b, 1, 1, "3DSTATE_VF_STATISTICS" }, + { 0x7808, 5, 257, "3DSTATE_VERTEX_BUFFERS" }, + { 0x7809, 3, 256, "3DSTATE_VERTEX_ELEMENTS" }, + { 0x780a, 3, 3, "3DSTATE_INDEX_BUFFER" }, + { 0x7900, 4, 4, "3DSTATE_DRAWING_RECTANGLE" }, + { 0x7901, 5, 5, "3DSTATE_CONSTANT_COLOR" }, + { 0x7905, 5, 7, "3DSTATE_DEPTH_BUFFER" }, + { 0x7906, 2, 2, "3DSTATE_POLY_STIPPLE_OFFSET" }, + { 0x7907, 33, 33, "3DSTATE_POLY_STIPPLE_PATTERN" }, + { 0x7908, 3, 3, "3DSTATE_LINE_STIPPLE" }, + { 0x7909, 2, 2, "3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP" }, + { 0x790a, 3, 3, "3DSTATE_AA_LINE_PARAMETERS" }, + { 0x7b00, 6, 6, "3DPRIMITIVE" }, + }; + + len = (data[0] & 0x0000ffff) + 2; + + switch ((data[0] & 0xffff0000) >> 16) { + case 0x6101: + if (len != 6) + fprintf(out, "Bad count in STATE_BASE_ADDRESS\n"); + if (count < 6) + BUFFER_FAIL(count, len, "STATE_BASE_ADDRESS"); + + instr_out(data, hw_offset, 0, + "STATE_BASE_ADDRESS\n"); + + if (data[1] & 1) { + instr_out(data, hw_offset, 1, "General state at 0x%08x\n", + data[1] & ~1); + } else + instr_out(data, hw_offset, 1, "General state not updated\n"); + + if (data[2] & 1) { + instr_out(data, hw_offset, 2, "Surface state at 0x%08x\n", + data[2] & ~1); + } else + instr_out(data, hw_offset, 2, "Surface state not updated\n"); + + if (data[3] & 1) { + instr_out(data, hw_offset, 3, "Indirect state at 0x%08x\n", + data[3] & ~1); + } else + instr_out(data, hw_offset, 3, "Indirect state not updated\n"); + + if (data[4] & 1) { + instr_out(data, hw_offset, 4, "General state upper bound 0x%08x\n", + data[4] & ~1); + } else + instr_out(data, hw_offset, 4, "General state not updated\n"); + + if (data[5] & 1) { + instr_out(data, hw_offset, 5, "Indirect state upper bound 0x%08x\n", + data[5] & ~1); + } else + instr_out(data, hw_offset, 5, "Indirect state not updated\n"); + + return len; + case 0x7800: + if (len != 7) + fprintf(out, "Bad count in 3DSTATE_PIPELINED_POINTERS\n"); + if (count < 7) + BUFFER_FAIL(count, len, "3DSTATE_PIPELINED_POINTERS"); + + instr_out(data, hw_offset, 0, + "3DSTATE_PIPELINED_POINTERS\n"); + instr_out(data, hw_offset, 1, "VS state\n"); + instr_out(data, hw_offset, 2, "GS state\n"); + instr_out(data, hw_offset, 3, "Clip state\n"); + instr_out(data, hw_offset, 4, "SF state\n"); + instr_out(data, hw_offset, 5, "WM state\n"); + instr_out(data, hw_offset, 6, "CC state\n"); + return len; + case 0x7801: + if (len != 6) + fprintf(out, "Bad count in 3DSTATE_BINDING_TABLE_POINTERS\n"); + if (count < 6) + BUFFER_FAIL(count, len, "3DSTATE_BINDING_TABLE_POINTERS"); + + instr_out(data, hw_offset, 0, + "3DSTATE_BINDING_TABLE_POINTERS\n"); + instr_out(data, hw_offset, 1, "VS binding table\n"); + instr_out(data, hw_offset, 2, "GS binding table\n"); + instr_out(data, hw_offset, 3, "Clip binding table\n"); + instr_out(data, hw_offset, 4, "SF binding table\n"); + instr_out(data, hw_offset, 5, "WM binding table\n"); + + return len; + + case 0x7808: + len = (data[0] & 0xff) + 2; + if ((len - 1) % 4 != 0) + fprintf(out, "Bad count in 3DSTATE_VERTEX_BUFFERS\n"); + if (count < len) + BUFFER_FAIL(count, len, "3DSTATE_VERTEX_BUFFERS"); + instr_out(data, hw_offset, 0, "3DSTATE_VERTEX_BUFFERS\n"); + + for (i = 1; i < len;) { + instr_out(data, hw_offset, i, "buffer %d: %s, pitch %db\n", + data[i] >> 27, + data[i] & (1 << 26) ? "random" : "sequential", + data[i] & 0x07ff); + i++; + instr_out(data, hw_offset, i++, "buffer address\n"); + instr_out(data, hw_offset, i++, "max index\n"); + instr_out(data, hw_offset, i++, "mbz\n"); + } + return len; + + case 0x7809: + len = (data[0] & 0xff) + 2; + if ((len + 1) % 2 != 0) + fprintf(out, "Bad count in 3DSTATE_VERTEX_ELEMENTS\n"); + if (count < len) + BUFFER_FAIL(count, len, "3DSTATE_VERTEX_ELEMENTS"); + instr_out(data, hw_offset, 0, "3DSTATE_VERTEX_ELEMENTS\n"); + + for (i = 1; i < len;) { + instr_out(data, hw_offset, i, "buffer %d: %svalid, type 0x%04x, " + "src offset 0x%04x bytes\n", + data[i] >> 27, + data[i] & (1 << 26) ? "" : "in", + (data[i] >> 16) & 0x1ff, + data[i] & 0x07ff); + i++; + instr_out(data, hw_offset, i, "(%s, %s, %s, %s), " + "dst offset 0x%02x bytes\n", + get_965_element_component(data[i], 0), + get_965_element_component(data[i], 1), + get_965_element_component(data[i], 2), + get_965_element_component(data[i], 3), + (data[i] & 0xff) * 4); + i++; + } + return len; + + case 0x780a: + len = (data[0] & 0xff) + 2; + if (len != 3) + fprintf(out, "Bad count in 3DSTATE_INDEX_BUFFER\n"); + if (count < len) + BUFFER_FAIL(count, len, "3DSTATE_INDEX_BUFFER"); + instr_out(data, hw_offset, 0, "3DSTATE_INDEX_BUFFER\n"); + instr_out(data, hw_offset, 1, "beginning buffer address\n"); + instr_out(data, hw_offset, 2, "ending buffer address\n"); + return len; + + case 0x7900: + if (len != 4) + fprintf(out, "Bad count in 3DSTATE_DRAWING_RECTANGLE\n"); + if (count < 4) + BUFFER_FAIL(count, len, "3DSTATE_DRAWING_RECTANGLE"); + + instr_out(data, hw_offset, 0, + "3DSTATE_DRAWING_RECTANGLE\n"); + instr_out(data, hw_offset, 1, "top left: %d,%d\n", + data[1] & 0xffff, + (data[1] >> 16) & 0xffff); + instr_out(data, hw_offset, 2, "bottom right: %d,%d\n", + data[2] & 0xffff, + (data[2] >> 16) & 0xffff); + instr_out(data, hw_offset, 3, "origin: %d,%d\n", + (int)data[3] & 0xffff, + ((int)data[3] >> 16) & 0xffff); + + return len; + + case 0x7905: + if (len != 5 && len != 6) + fprintf(out, "Bad count in 3DSTATE_DEPTH_BUFFER\n"); + if (count < len) + BUFFER_FAIL(count, len, "3DSTATE_DEPTH_BUFFER"); + + instr_out(data, hw_offset, 0, + "3DSTATE_DEPTH_BUFFER\n"); + instr_out(data, hw_offset, 1, "%s, %s, pitch = %d bytes, %stiled\n", + get_965_surfacetype(data[1] >> 29), + get_965_depthformat((data[1] >> 18) & 0x7), + (data[1] & 0x0001ffff) + 1, + data[1] & (1 << 27) ? "" : "not "); + instr_out(data, hw_offset, 2, "depth offset\n"); + instr_out(data, hw_offset, 3, "%dx%d\n", + ((data[3] & 0x0007ffc0) >> 6) + 1, + ((data[3] & 0xfff80000) >> 19) + 1); + instr_out(data, hw_offset, 4, "volume depth\n"); + if (len == 6) + instr_out(data, hw_offset, 5, "\n"); + + return len; + + case 0x7b00: + len = (data[0] & 0xff) + 2; + if (len != 6) + fprintf(out, "Bad count in 3DPRIMITIVE\n"); + if (count < len) + BUFFER_FAIL(count, len, "3DPRIMITIVE"); + + instr_out(data, hw_offset, 0, + "3DPRIMITIVE: %s %s\n", + get_965_prim_type(data[0]), + (data[0] & (1 << 15)) ? "random" : "sequential"); + instr_out(data, hw_offset, 1, "vertex count\n"); + instr_out(data, hw_offset, 2, "start vertex\n"); + instr_out(data, hw_offset, 3, "instance count\n"); + instr_out(data, hw_offset, 4, "start instance\n"); + instr_out(data, hw_offset, 5, "index bias\n"); + return len; + } + + for (opcode = 0; opcode < Elements(opcodes_3d); opcode++) { + if ((data[0] & 0xffff0000) >> 16 == opcodes_3d[opcode].opcode) { + unsigned int i; + len = 1; + + instr_out(data, hw_offset, 0, "%s\n", opcodes_3d[opcode].name); + if (opcodes_3d[opcode].max_len > 1) { + len = (data[0] & 0xff) + 2; + if (len < opcodes_3d[opcode].min_len || + len > opcodes_3d[opcode].max_len) + { + fprintf(out, "Bad count in %s\n", opcodes_3d[opcode].name); + } + } + + for (i = 1; i < len; i++) { + if (i >= count) + BUFFER_FAIL(count, len, opcodes_3d[opcode].name); + instr_out(data, hw_offset, i, "dword %d\n", i); + } + return len; + } + } + + instr_out(data, hw_offset, 0, "3D UNKNOWN\n"); + (*failures)++; + return 1; +} + +static int +decode_3d_i830(const uint32_t *data, int count, uint32_t hw_offset, int *failures) +{ + unsigned int opcode; + + struct { + uint32_t opcode; + int min_len; + int max_len; + char *name; + } opcodes_3d[] = { + { 0x02, 1, 1, "3DSTATE_MODES_3" }, + { 0x03, 1, 1, "3DSTATE_ENABLES_1"}, + { 0x04, 1, 1, "3DSTATE_ENABLES_2"}, + { 0x05, 1, 1, "3DSTATE_VFT0"}, + { 0x06, 1, 1, "3DSTATE_AA"}, + { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES" }, + { 0x08, 1, 1, "3DSTATE_MODES_1" }, + { 0x09, 1, 1, "3DSTATE_STENCIL_TEST" }, + { 0x0a, 1, 1, "3DSTATE_VFT1"}, + { 0x0b, 1, 1, "3DSTATE_INDPT_ALPHA_BLEND" }, + { 0x0c, 1, 1, "3DSTATE_MODES_5" }, + { 0x0d, 1, 1, "3DSTATE_MAP_BLEND_OP" }, + { 0x0e, 1, 1, "3DSTATE_MAP_BLEND_ARG" }, + { 0x0f, 1, 1, "3DSTATE_MODES_2" }, + { 0x15, 1, 1, "3DSTATE_FOG_COLOR" }, + { 0x16, 1, 1, "3DSTATE_MODES_4" }, + }; + + switch ((data[0] & 0x1f000000) >> 24) { + case 0x1f: + return decode_3d_primitive(data, count, hw_offset, failures); + case 0x1d: + return decode_3d_1d(data, count, hw_offset, failures, 1); + case 0x1c: + return decode_3d_1c(data, count, hw_offset, failures); + } + + for (opcode = 0; opcode < Elements(opcodes_3d); opcode++) { + if ((data[0] & 0x1f000000) >> 24 == opcodes_3d[opcode].opcode) { + unsigned int len = 1, i; + + instr_out(data, hw_offset, 0, "%s\n", opcodes_3d[opcode].name); + if (opcodes_3d[opcode].max_len > 1) { + len = (data[0] & 0xff) + 2; + if (len < opcodes_3d[opcode].min_len || + len > opcodes_3d[opcode].max_len) + { + fprintf(out, "Bad count in %s\n", opcodes_3d[opcode].name); + } + } + + for (i = 1; i < len; i++) { + if (i >= count) + BUFFER_FAIL(count, len, opcodes_3d[opcode].name); + instr_out(data, hw_offset, i, "dword %d\n", i); + } + return len; + } + } + + instr_out(data, hw_offset, 0, "3D UNKNOWN\n"); + (*failures)++; + return 1; +} + +/** + * Decodes an i830-i915 batch buffer, writing the output to stdout. + * + * \param data batch buffer contents + * \param count number of DWORDs to decode in the batch buffer + * \param hw_offset hardware address for the buffer + */ +int +intel_decode(const uint32_t *data, int count, uint32_t hw_offset, uint32_t devid) +{ + int index = 0; + int failures = 0; + + out = stderr; + + while (index < count) { + switch ((data[index] & 0xe0000000) >> 29) { + case 0x0: + index += decode_mi(data + index, count - index, + hw_offset + index * 4, &failures); + break; + case 0x2: + index += decode_2d(data + index, count - index, + hw_offset + index * 4, &failures); + break; + case 0x3: + if (IS_965(devid)) { + index += decode_3d_965(data + index, count - index, + hw_offset + index * 4, &failures); + } else if (IS_9XX(devid)) { + index += decode_3d(data + index, count - index, + hw_offset + index * 4, &failures); + } else { + index += decode_3d_i830(data + index, count - index, + hw_offset + index * 4, &failures); + } + break; + default: + instr_out(data, hw_offset, index, "UNKNOWN\n"); + failures++; + index++; + break; + } + fflush(out); + } + + return failures; +} + +void intel_decode_context_reset(void) +{ + saved_s2_set = 0; + saved_s4_set = 1; +} + diff --git a/src/gallium/drivers/i965/intel_decode.h b/src/gallium/drivers/i965/intel_decode.h new file mode 100644 index 0000000..7683097 --- /dev/null +++ b/src/gallium/drivers/i965/intel_decode.h @@ -0,0 +1,29 @@ +/* + * Copyright © 2007 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * Eric Anholt + * + */ + +int intel_decode(const uint32_t *data, int count, uint32_t hw_offset, uint32_t devid); +void intel_decode_context_reset(void); diff --git a/src/gallium/drivers/i965/intel_structs.h b/src/gallium/drivers/i965/intel_structs.h new file mode 100644 index 0000000..522e3bd --- /dev/null +++ b/src/gallium/drivers/i965/intel_structs.h @@ -0,0 +1,132 @@ +#ifndef INTEL_STRUCTS_H +#define INTEL_STRUCTS_H + +struct br0 { + GLuint length:8; + GLuint pad0:3; + GLuint dst_tiled:1; + GLuint pad1:8; + GLuint write_rgb:1; + GLuint write_alpha:1; + GLuint opcode:7; + GLuint client:3; +}; + + +struct br13 { + GLint dest_pitch:16; + GLuint rop:8; + GLuint color_depth:2; + GLuint pad1:3; + GLuint mono_source_transparency:1; + GLuint clipping_enable:1; + GLuint pad0:1; +}; + + + +/* This is an attempt to move some of the 2D interaction in this + * driver to using structs for packets rather than a bunch of #defines + * and dwords. + */ +struct xy_color_blit { + struct br0 br0; + struct br13 br13; + + struct { + GLuint dest_x1:16; + GLuint dest_y1:16; + } dw2; + + struct { + GLuint dest_x2:16; + GLuint dest_y2:16; + } dw3; + + GLuint dest_base_addr; + GLuint color; +}; + +struct xy_src_copy_blit { + struct br0 br0; + struct br13 br13; + + struct { + GLuint dest_x1:16; + GLuint dest_y1:16; + } dw2; + + struct { + GLuint dest_x2:16; + GLuint dest_y2:16; + } dw3; + + GLuint dest_base_addr; + + struct { + GLuint src_x1:16; + GLuint src_y1:16; + } dw5; + + struct { + GLint src_pitch:16; + GLuint pad:16; + } dw6; + + GLuint src_base_addr; +}; + +struct xy_setup_blit { + struct br0 br0; + struct br13 br13; + + struct { + GLuint clip_x1:16; + GLuint clip_y1:16; + } dw2; + + struct { + GLuint clip_x2:16; + GLuint clip_y2:16; + } dw3; + + GLuint dest_base_addr; + GLuint background_color; + GLuint foreground_color; + GLuint pattern_base_addr; +}; + + +struct xy_text_immediate_blit { + struct { + GLuint length:8; + GLuint pad2:3; + GLuint dst_tiled:1; + GLuint pad1:4; + GLuint byte_packed:1; + GLuint pad0:5; + GLuint opcode:7; + GLuint client:3; + } dw0; + + struct { + GLuint dest_x1:16; + GLuint dest_y1:16; + } dw1; + + struct { + GLuint dest_x2:16; + GLuint dest_y2:16; + } dw2; + + /* Src bitmap data follows as inline dwords. + */ +}; + + +#define CLIENT_2D 0x2 +#define OPCODE_XY_SETUP_BLT 0x1 +#define OPCODE_XY_COLOR_BLT 0x50 +#define OPCODE_XY_TEXT_IMMEDIATE_BLT 0x31 + +#endif diff --git a/src/gallium/drivers/identity/Makefile b/src/gallium/drivers/identity/Makefile new file mode 100644 index 0000000..74692d9 --- /dev/null +++ b/src/gallium/drivers/identity/Makefile @@ -0,0 +1,11 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = identity + +C_SOURCES = \ + id_objects.c \ + id_context.c \ + id_screen.c + +include ../../Makefile.template diff --git a/src/gallium/drivers/identity/SConscript b/src/gallium/drivers/identity/SConscript new file mode 100644 index 0000000..d24d1ec --- /dev/null +++ b/src/gallium/drivers/identity/SConscript @@ -0,0 +1,15 @@ +Import('*') + +env = env.Clone() + +identity = env.ConvenienceLibrary( + target = 'identity', + source = [ + 'id_context.c', + 'id_objects.c', + 'id_screen.c', + ]) + +env.Alias('identity', identity) + +Export('identity') diff --git a/src/gallium/drivers/identity/id_context.c b/src/gallium/drivers/identity/id_context.c new file mode 100644 index 0000000..3efbd6a --- /dev/null +++ b/src/gallium/drivers/identity/id_context.c @@ -0,0 +1,936 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "pipe/p_context.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" + +#include "id_context.h" +#include "id_objects.h" + + +static void +identity_destroy(struct pipe_context *_pipe) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->destroy(pipe); + + FREE(id_pipe); +} + +static void +identity_draw_vbo(struct pipe_context *_pipe, + const struct pipe_draw_info *info) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->draw_vbo(pipe, info); +} + +static struct pipe_query * +identity_create_query(struct pipe_context *_pipe, + unsigned query_type) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + return pipe->create_query(pipe, + query_type); +} + +static void +identity_destroy_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->destroy_query(pipe, + query); +} + +static void +identity_begin_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->begin_query(pipe, + query); +} + +static void +identity_end_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->end_query(pipe, + query); +} + +static boolean +identity_get_query_result(struct pipe_context *_pipe, + struct pipe_query *query, + boolean wait, + void *result) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + return pipe->get_query_result(pipe, + query, + wait, + result); +} + +static void * +identity_create_blend_state(struct pipe_context *_pipe, + const struct pipe_blend_state *blend) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + return pipe->create_blend_state(pipe, + blend); +} + +static void +identity_bind_blend_state(struct pipe_context *_pipe, + void *blend) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->bind_blend_state(pipe, + blend); +} + +static void +identity_delete_blend_state(struct pipe_context *_pipe, + void *blend) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->delete_blend_state(pipe, + blend); +} + +static void * +identity_create_sampler_state(struct pipe_context *_pipe, + const struct pipe_sampler_state *sampler) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + return pipe->create_sampler_state(pipe, + sampler); +} + +static void +identity_bind_fragment_sampler_states(struct pipe_context *_pipe, + unsigned num_samplers, + void **samplers) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->bind_fragment_sampler_states(pipe, + num_samplers, + samplers); +} + +static void +identity_bind_vertex_sampler_states(struct pipe_context *_pipe, + unsigned num_samplers, + void **samplers) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->bind_vertex_sampler_states(pipe, + num_samplers, + samplers); +} + +static void +identity_delete_sampler_state(struct pipe_context *_pipe, + void *sampler) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->delete_sampler_state(pipe, + sampler); +} + +static void * +identity_create_rasterizer_state(struct pipe_context *_pipe, + const struct pipe_rasterizer_state *rasterizer) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + return pipe->create_rasterizer_state(pipe, + rasterizer); +} + +static void +identity_bind_rasterizer_state(struct pipe_context *_pipe, + void *rasterizer) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->bind_rasterizer_state(pipe, + rasterizer); +} + +static void +identity_delete_rasterizer_state(struct pipe_context *_pipe, + void *rasterizer) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->delete_rasterizer_state(pipe, + rasterizer); +} + +static void * +identity_create_depth_stencil_alpha_state(struct pipe_context *_pipe, + const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + return pipe->create_depth_stencil_alpha_state(pipe, + depth_stencil_alpha); +} + +static void +identity_bind_depth_stencil_alpha_state(struct pipe_context *_pipe, + void *depth_stencil_alpha) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->bind_depth_stencil_alpha_state(pipe, + depth_stencil_alpha); +} + +static void +identity_delete_depth_stencil_alpha_state(struct pipe_context *_pipe, + void *depth_stencil_alpha) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->delete_depth_stencil_alpha_state(pipe, + depth_stencil_alpha); +} + +static void * +identity_create_fs_state(struct pipe_context *_pipe, + const struct pipe_shader_state *fs) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + return pipe->create_fs_state(pipe, + fs); +} + +static void +identity_bind_fs_state(struct pipe_context *_pipe, + void *fs) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->bind_fs_state(pipe, + fs); +} + +static void +identity_delete_fs_state(struct pipe_context *_pipe, + void *fs) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->delete_fs_state(pipe, + fs); +} + +static void * +identity_create_vs_state(struct pipe_context *_pipe, + const struct pipe_shader_state *vs) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + return pipe->create_vs_state(pipe, + vs); +} + +static void +identity_bind_vs_state(struct pipe_context *_pipe, + void *vs) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->bind_vs_state(pipe, + vs); +} + +static void +identity_delete_vs_state(struct pipe_context *_pipe, + void *vs) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->delete_vs_state(pipe, + vs); +} + + +static void * +identity_create_vertex_elements_state(struct pipe_context *_pipe, + unsigned num_elements, + const struct pipe_vertex_element *vertex_elements) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + return pipe->create_vertex_elements_state(pipe, + num_elements, + vertex_elements); +} + +static void +identity_bind_vertex_elements_state(struct pipe_context *_pipe, + void *velems) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->bind_vertex_elements_state(pipe, + velems); +} + +static void +identity_delete_vertex_elements_state(struct pipe_context *_pipe, + void *velems) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->delete_vertex_elements_state(pipe, + velems); +} + +static void +identity_set_blend_color(struct pipe_context *_pipe, + const struct pipe_blend_color *blend_color) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->set_blend_color(pipe, + blend_color); +} + +static void +identity_set_stencil_ref(struct pipe_context *_pipe, + const struct pipe_stencil_ref *stencil_ref) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->set_stencil_ref(pipe, + stencil_ref); +} + +static void +identity_set_clip_state(struct pipe_context *_pipe, + const struct pipe_clip_state *clip) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->set_clip_state(pipe, + clip); +} + +static void +identity_set_sample_mask(struct pipe_context *_pipe, + unsigned sample_mask) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->set_sample_mask(pipe, + sample_mask); +} + +static void +identity_set_constant_buffer(struct pipe_context *_pipe, + uint shader, + uint index, + struct pipe_resource *_resource) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + struct pipe_resource *unwrapped_resource; + struct pipe_resource *resource = NULL; + + /* XXX hmm? unwrap the input state */ + if (_resource) { + unwrapped_resource = identity_resource_unwrap(_resource); + resource = unwrapped_resource; + } + + pipe->set_constant_buffer(pipe, + shader, + index, + resource); +} + +static void +identity_set_framebuffer_state(struct pipe_context *_pipe, + const struct pipe_framebuffer_state *_state) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + struct pipe_framebuffer_state unwrapped_state; + struct pipe_framebuffer_state *state = NULL; + unsigned i; + + /* unwrap the input state */ + if (_state) { + memcpy(&unwrapped_state, _state, sizeof(unwrapped_state)); + for(i = 0; i < _state->nr_cbufs; i++) + unwrapped_state.cbufs[i] = identity_surface_unwrap(_state->cbufs[i]); + for (; i < PIPE_MAX_COLOR_BUFS; i++) + unwrapped_state.cbufs[i] = NULL; + unwrapped_state.zsbuf = identity_surface_unwrap(_state->zsbuf); + state = &unwrapped_state; + } + + pipe->set_framebuffer_state(pipe, + state); +} + +static void +identity_set_polygon_stipple(struct pipe_context *_pipe, + const struct pipe_poly_stipple *poly_stipple) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->set_polygon_stipple(pipe, + poly_stipple); +} + +static void +identity_set_scissor_state(struct pipe_context *_pipe, + const struct pipe_scissor_state *scissor) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->set_scissor_state(pipe, + scissor); +} + +static void +identity_set_viewport_state(struct pipe_context *_pipe, + const struct pipe_viewport_state *viewport) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->set_viewport_state(pipe, + viewport); +} + +static void +identity_set_fragment_sampler_views(struct pipe_context *_pipe, + unsigned num, + struct pipe_sampler_view **_views) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view **views = NULL; + unsigned i; + + if (_views) { + for (i = 0; i < num; i++) + unwrapped_views[i] = identity_sampler_view_unwrap(_views[i]); + for (; i < PIPE_MAX_SAMPLERS; i++) + unwrapped_views[i] = NULL; + + views = unwrapped_views; + } + + pipe->set_fragment_sampler_views(pipe, num, views); +} + +static void +identity_set_vertex_sampler_views(struct pipe_context *_pipe, + unsigned num, + struct pipe_sampler_view **_views) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + struct pipe_sampler_view *unwrapped_views[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_sampler_view **views = NULL; + unsigned i; + + if (_views) { + for (i = 0; i < num; i++) + unwrapped_views[i] = identity_sampler_view_unwrap(_views[i]); + for (; i < PIPE_MAX_VERTEX_SAMPLERS; i++) + unwrapped_views[i] = NULL; + + views = unwrapped_views; + } + + pipe->set_vertex_sampler_views(pipe, num, views); +} + +static void +identity_set_vertex_buffers(struct pipe_context *_pipe, + unsigned num_buffers, + const struct pipe_vertex_buffer *_buffers) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS]; + struct pipe_vertex_buffer *buffers = NULL; + unsigned i; + + if (num_buffers) { + memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers)); + for (i = 0; i < num_buffers; i++) + unwrapped_buffers[i].buffer = identity_resource_unwrap(_buffers[i].buffer); + buffers = unwrapped_buffers; + } + + pipe->set_vertex_buffers(pipe, + num_buffers, + buffers); +} + +static void +identity_set_index_buffer(struct pipe_context *_pipe, + const struct pipe_index_buffer *_ib) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + struct pipe_index_buffer unwrapped_ib, *ib = NULL; + + if (_ib) { + unwrapped_ib = *_ib; + unwrapped_ib.buffer = identity_resource_unwrap(_ib->buffer); + ib = &unwrapped_ib; + } + + pipe->set_index_buffer(pipe, ib); +} + +static void +identity_resource_copy_region(struct pipe_context *_pipe, + struct pipe_resource *_dst, + unsigned dst_level, + unsigned dstx, + unsigned dsty, + unsigned dstz, + struct pipe_resource *_src, + unsigned src_level, + const struct pipe_box *src_box) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct identity_resource *id_resource_dst = identity_resource(_dst); + struct identity_resource *id_resource_src = identity_resource(_src); + struct pipe_context *pipe = id_pipe->pipe; + struct pipe_resource *dst = id_resource_dst->resource; + struct pipe_resource *src = id_resource_src->resource; + + pipe->resource_copy_region(pipe, + dst, + dst_level, + dstx, + dsty, + dstz, + src, + src_level, + src_box); +} + +static void +identity_clear(struct pipe_context *_pipe, + unsigned buffers, + const float *rgba, + double depth, + unsigned stencil) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->clear(pipe, + buffers, + rgba, + depth, + stencil); +} + +static void +identity_clear_render_target(struct pipe_context *_pipe, + struct pipe_surface *_dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct identity_surface *id_surface_dst = identity_surface(_dst); + struct pipe_context *pipe = id_pipe->pipe; + struct pipe_surface *dst = id_surface_dst->surface; + + pipe->clear_render_target(pipe, + dst, + rgba, + dstx, + dsty, + width, + height); +} +static void +identity_clear_depth_stencil(struct pipe_context *_pipe, + struct pipe_surface *_dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct identity_surface *id_surface_dst = identity_surface(_dst); + struct pipe_context *pipe = id_pipe->pipe; + struct pipe_surface *dst = id_surface_dst->surface; + + pipe->clear_depth_stencil(pipe, + dst, + clear_flags, + depth, + stencil, + dstx, + dsty, + width, + height); + +} + +static void +identity_flush(struct pipe_context *_pipe, + unsigned flags, + struct pipe_fence_handle **fence) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct pipe_context *pipe = id_pipe->pipe; + + pipe->flush(pipe, + flags, + fence); +} + +static unsigned int +identity_is_resource_referenced(struct pipe_context *_pipe, + struct pipe_resource *_resource, + unsigned level, + int layer) +{ + struct identity_context *id_pipe = identity_context(_pipe); + struct identity_resource *id_resource = identity_resource(_resource); + struct pipe_context *pipe = id_pipe->pipe; + struct pipe_resource *resource = id_resource->resource; + + return pipe->is_resource_referenced(pipe, + resource, + level, + layer); +} + +static struct pipe_sampler_view * +identity_context_create_sampler_view(struct pipe_context *_pipe, + struct pipe_resource *_resource, + const struct pipe_sampler_view *templ) +{ + struct identity_context *id_context = identity_context(_pipe); + struct identity_resource *id_resource = identity_resource(_resource); + struct pipe_context *pipe = id_context->pipe; + struct pipe_resource *resource = id_resource->resource; + struct pipe_sampler_view *result; + + result = pipe->create_sampler_view(pipe, + resource, + templ); + + if (result) + return identity_sampler_view_create(id_context, id_resource, result); + return NULL; +} + +static void +identity_context_sampler_view_destroy(struct pipe_context *_pipe, + struct pipe_sampler_view *_view) +{ + identity_sampler_view_destroy(identity_context(_pipe), + identity_sampler_view(_view)); +} + +static struct pipe_surface * +identity_context_create_surface(struct pipe_context *_pipe, + struct pipe_resource *_resource, + const struct pipe_surface *templ) +{ + struct identity_context *id_context = identity_context(_pipe); + struct identity_resource *id_resource = identity_resource(_resource); + struct pipe_context *pipe = id_context->pipe; + struct pipe_resource *resource = id_resource->resource; + struct pipe_surface *result; + + result = pipe->create_surface(pipe, + resource, + templ); + + if (result) + return identity_surface_create(id_context, id_resource, result); + return NULL; +} + +static void +identity_context_surface_destroy(struct pipe_context *_pipe, + struct pipe_surface *_surf) +{ + identity_surface_destroy(identity_context(_pipe), + identity_surface(_surf)); +} + +static struct pipe_transfer * +identity_context_get_transfer(struct pipe_context *_context, + struct pipe_resource *_resource, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct identity_context *id_context = identity_context(_context); + struct identity_resource *id_resource = identity_resource(_resource); + struct pipe_context *context = id_context->pipe; + struct pipe_resource *resource = id_resource->resource; + struct pipe_transfer *result; + + result = context->get_transfer(context, + resource, + level, + usage, + box); + + if (result) + return identity_transfer_create(id_context, id_resource, result); + return NULL; +} + +static void +identity_context_transfer_destroy(struct pipe_context *_pipe, + struct pipe_transfer *_transfer) +{ + identity_transfer_destroy(identity_context(_pipe), + identity_transfer(_transfer)); +} + +static void * +identity_context_transfer_map(struct pipe_context *_context, + struct pipe_transfer *_transfer) +{ + struct identity_context *id_context = identity_context(_context); + struct identity_transfer *id_transfer = identity_transfer(_transfer); + struct pipe_context *context = id_context->pipe; + struct pipe_transfer *transfer = id_transfer->transfer; + + return context->transfer_map(context, + transfer); +} + + + +static void +identity_context_transfer_flush_region(struct pipe_context *_context, + struct pipe_transfer *_transfer, + const struct pipe_box *box) +{ + struct identity_context *id_context = identity_context(_context); + struct identity_transfer *id_transfer = identity_transfer(_transfer); + struct pipe_context *context = id_context->pipe; + struct pipe_transfer *transfer = id_transfer->transfer; + + context->transfer_flush_region(context, + transfer, + box); +} + + +static void +identity_context_transfer_unmap(struct pipe_context *_context, + struct pipe_transfer *_transfer) +{ + struct identity_context *id_context = identity_context(_context); + struct identity_transfer *id_transfer = identity_transfer(_transfer); + struct pipe_context *context = id_context->pipe; + struct pipe_transfer *transfer = id_transfer->transfer; + + context->transfer_unmap(context, + transfer); +} + + +static void +identity_context_transfer_inline_write(struct pipe_context *_context, + struct pipe_resource *_resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride) +{ + struct identity_context *id_context = identity_context(_context); + struct identity_resource *id_resource = identity_resource(_resource); + struct pipe_context *context = id_context->pipe; + struct pipe_resource *resource = id_resource->resource; + + context->transfer_inline_write(context, + resource, + level, + usage, + box, + data, + stride, + layer_stride); +} + + +struct pipe_context * +identity_context_create(struct pipe_screen *_screen, struct pipe_context *pipe) +{ + struct identity_context *id_pipe; + (void)identity_screen(_screen); + + id_pipe = CALLOC_STRUCT(identity_context); + if (!id_pipe) { + return NULL; + } + + id_pipe->base.winsys = NULL; + id_pipe->base.screen = _screen; + id_pipe->base.priv = pipe->priv; /* expose wrapped data */ + id_pipe->base.draw = NULL; + + id_pipe->base.destroy = identity_destroy; + id_pipe->base.draw_vbo = identity_draw_vbo; + id_pipe->base.create_query = identity_create_query; + id_pipe->base.destroy_query = identity_destroy_query; + id_pipe->base.begin_query = identity_begin_query; + id_pipe->base.end_query = identity_end_query; + id_pipe->base.get_query_result = identity_get_query_result; + id_pipe->base.create_blend_state = identity_create_blend_state; + id_pipe->base.bind_blend_state = identity_bind_blend_state; + id_pipe->base.delete_blend_state = identity_delete_blend_state; + id_pipe->base.create_sampler_state = identity_create_sampler_state; + id_pipe->base.bind_fragment_sampler_states = identity_bind_fragment_sampler_states; + id_pipe->base.bind_vertex_sampler_states = identity_bind_vertex_sampler_states; + id_pipe->base.delete_sampler_state = identity_delete_sampler_state; + id_pipe->base.create_rasterizer_state = identity_create_rasterizer_state; + id_pipe->base.bind_rasterizer_state = identity_bind_rasterizer_state; + id_pipe->base.delete_rasterizer_state = identity_delete_rasterizer_state; + id_pipe->base.create_depth_stencil_alpha_state = identity_create_depth_stencil_alpha_state; + id_pipe->base.bind_depth_stencil_alpha_state = identity_bind_depth_stencil_alpha_state; + id_pipe->base.delete_depth_stencil_alpha_state = identity_delete_depth_stencil_alpha_state; + id_pipe->base.create_fs_state = identity_create_fs_state; + id_pipe->base.bind_fs_state = identity_bind_fs_state; + id_pipe->base.delete_fs_state = identity_delete_fs_state; + id_pipe->base.create_vs_state = identity_create_vs_state; + id_pipe->base.bind_vs_state = identity_bind_vs_state; + id_pipe->base.delete_vs_state = identity_delete_vs_state; + id_pipe->base.create_vertex_elements_state = identity_create_vertex_elements_state; + id_pipe->base.bind_vertex_elements_state = identity_bind_vertex_elements_state; + id_pipe->base.delete_vertex_elements_state = identity_delete_vertex_elements_state; + id_pipe->base.set_blend_color = identity_set_blend_color; + id_pipe->base.set_stencil_ref = identity_set_stencil_ref; + id_pipe->base.set_clip_state = identity_set_clip_state; + id_pipe->base.set_sample_mask = identity_set_sample_mask; + id_pipe->base.set_constant_buffer = identity_set_constant_buffer; + id_pipe->base.set_framebuffer_state = identity_set_framebuffer_state; + id_pipe->base.set_polygon_stipple = identity_set_polygon_stipple; + id_pipe->base.set_scissor_state = identity_set_scissor_state; + id_pipe->base.set_viewport_state = identity_set_viewport_state; + id_pipe->base.set_fragment_sampler_views = identity_set_fragment_sampler_views; + id_pipe->base.set_vertex_sampler_views = identity_set_vertex_sampler_views; + id_pipe->base.set_vertex_buffers = identity_set_vertex_buffers; + id_pipe->base.set_index_buffer = identity_set_index_buffer; + id_pipe->base.resource_copy_region = identity_resource_copy_region; + id_pipe->base.clear = identity_clear; + id_pipe->base.clear_render_target = identity_clear_render_target; + id_pipe->base.clear_depth_stencil = identity_clear_depth_stencil; + id_pipe->base.flush = identity_flush; + id_pipe->base.is_resource_referenced = identity_is_resource_referenced; + id_pipe->base.create_surface = identity_context_create_surface; + id_pipe->base.surface_destroy = identity_context_surface_destroy; + id_pipe->base.create_sampler_view = identity_context_create_sampler_view; + id_pipe->base.sampler_view_destroy = identity_context_sampler_view_destroy; + id_pipe->base.get_transfer = identity_context_get_transfer; + id_pipe->base.transfer_destroy = identity_context_transfer_destroy; + id_pipe->base.transfer_map = identity_context_transfer_map; + id_pipe->base.transfer_unmap = identity_context_transfer_unmap; + id_pipe->base.transfer_flush_region = identity_context_transfer_flush_region; + id_pipe->base.transfer_inline_write = identity_context_transfer_inline_write; + + id_pipe->pipe = pipe; + + return &id_pipe->base; +} diff --git a/src/gallium/drivers/identity/id_context.h b/src/gallium/drivers/identity/id_context.h new file mode 100644 index 0000000..6d3c189 --- /dev/null +++ b/src/gallium/drivers/identity/id_context.h @@ -0,0 +1,52 @@ +/************************************************************************** + * + * 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 ID_CONTEXT_H +#define ID_CONTEXT_H + +#include "pipe/p_state.h" +#include "pipe/p_context.h" + + +struct identity_context { + struct pipe_context base; /**< base class */ + + struct pipe_context *pipe; +}; + + +struct pipe_context * +identity_context_create(struct pipe_screen *screen, struct pipe_context *pipe); + + +static INLINE struct identity_context * +identity_context(struct pipe_context *pipe) +{ + return (struct identity_context *)pipe; +} + +#endif /* ID_CONTEXT_H */ diff --git a/src/gallium/drivers/identity/id_objects.c b/src/gallium/drivers/identity/id_objects.c new file mode 100644 index 0000000..6345441 --- /dev/null +++ b/src/gallium/drivers/identity/id_objects.c @@ -0,0 +1,191 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_inlines.h" +#include "util/u_memory.h" + +#include "id_screen.h" +#include "id_objects.h" +#include "id_context.h" + + + +struct pipe_resource * +identity_resource_create(struct identity_screen *id_screen, + struct pipe_resource *resource) +{ + struct identity_resource *id_resource; + + if(!resource) + goto error; + + assert(resource->screen == id_screen->screen); + + id_resource = CALLOC_STRUCT(identity_resource); + if(!id_resource) + goto error; + + memcpy(&id_resource->base, resource, sizeof(struct pipe_resource)); + + pipe_reference_init(&id_resource->base.reference, 1); + id_resource->base.screen = &id_screen->base; + id_resource->resource = resource; + + return &id_resource->base; + +error: + pipe_resource_reference(&resource, NULL); + return NULL; +} + +void +identity_resource_destroy(struct identity_resource *id_resource) +{ + pipe_resource_reference(&id_resource->resource, NULL); + FREE(id_resource); +} + + +struct pipe_surface * +identity_surface_create(struct identity_context *id_context, + struct identity_resource *id_resource, + struct pipe_surface *surface) +{ + struct identity_surface *id_surface; + + if(!surface) + goto error; + + assert(surface->texture == id_resource->resource); + + id_surface = CALLOC_STRUCT(identity_surface); + if(!id_surface) + goto error; + + memcpy(&id_surface->base, surface, sizeof(struct pipe_surface)); + + pipe_reference_init(&id_surface->base.reference, 1); + id_surface->base.texture = NULL; + pipe_resource_reference(&id_surface->base.texture, &id_resource->base); + id_surface->surface = surface; + + return &id_surface->base; + +error: + pipe_surface_reference(&surface, NULL); + return NULL; +} + +void +identity_surface_destroy(struct identity_context *id_context, + struct identity_surface *id_surface) +{ + pipe_resource_reference(&id_surface->base.texture, NULL); + id_context->pipe->surface_destroy(id_context->pipe, + id_surface->surface); + FREE(id_surface); +} + + +struct pipe_sampler_view * +identity_sampler_view_create(struct identity_context *id_context, + struct identity_resource *id_resource, + struct pipe_sampler_view *view) +{ + struct identity_sampler_view *id_view; + + if (!view) + goto error; + + assert(view->texture == id_resource->resource); + + id_view = CALLOC_STRUCT(identity_sampler_view); + + id_view->base = *view; + id_view->base.reference.count = 1; + id_view->base.texture = NULL; + pipe_resource_reference(&id_view->base.texture, id_resource->resource); + id_view->base.context = id_context->pipe; + id_view->sampler_view = view; + + return &id_view->base; +error: + return NULL; +} + +void +identity_sampler_view_destroy(struct identity_context *id_context, + struct identity_sampler_view *id_view) +{ + pipe_resource_reference(&id_view->base.texture, NULL); + id_context->pipe->sampler_view_destroy(id_context->pipe, + id_view->sampler_view); + FREE(id_view); +} + + +struct pipe_transfer * +identity_transfer_create(struct identity_context *id_context, + struct identity_resource *id_resource, + struct pipe_transfer *transfer) +{ + struct identity_transfer *id_transfer; + + if(!transfer) + goto error; + + assert(transfer->resource == id_resource->resource); + + id_transfer = CALLOC_STRUCT(identity_transfer); + if(!id_transfer) + goto error; + + memcpy(&id_transfer->base, transfer, sizeof(struct pipe_transfer)); + + id_transfer->base.resource = NULL; + id_transfer->transfer = transfer; + + pipe_resource_reference(&id_transfer->base.resource, &id_resource->base); + assert(id_transfer->base.resource == &id_resource->base); + + return &id_transfer->base; + +error: + id_context->pipe->transfer_destroy(id_context->pipe, transfer); + return NULL; +} + +void +identity_transfer_destroy(struct identity_context *id_context, + struct identity_transfer *id_transfer) +{ + pipe_resource_reference(&id_transfer->base.resource, NULL); + id_context->pipe->transfer_destroy(id_context->pipe, + id_transfer->transfer); + FREE(id_transfer); +} + diff --git a/src/gallium/drivers/identity/id_objects.h b/src/gallium/drivers/identity/id_objects.h new file mode 100644 index 0000000..181f2d6 --- /dev/null +++ b/src/gallium/drivers/identity/id_objects.h @@ -0,0 +1,177 @@ +/************************************************************************** + * + * 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 ID_OBJECTS_H +#define ID_OBJECTS_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" + +#include "id_screen.h" + +struct identity_context; + + +struct identity_resource +{ + struct pipe_resource base; + + struct pipe_resource *resource; +}; + + +struct identity_sampler_view +{ + struct pipe_sampler_view base; + + struct pipe_sampler_view *sampler_view; +}; + + +struct identity_surface +{ + struct pipe_surface base; + + struct pipe_surface *surface; +}; + + +struct identity_transfer +{ + struct pipe_transfer base; + + struct pipe_transfer *transfer; +}; + + +static INLINE struct identity_resource * +identity_resource(struct pipe_resource *_resource) +{ + if(!_resource) + return NULL; + (void)identity_screen(_resource->screen); + return (struct identity_resource *)_resource; +} + +static INLINE struct identity_sampler_view * +identity_sampler_view(struct pipe_sampler_view *_sampler_view) +{ + if (!_sampler_view) { + return NULL; + } + return (struct identity_sampler_view *)_sampler_view; +} + +static INLINE struct identity_surface * +identity_surface(struct pipe_surface *_surface) +{ + if(!_surface) + return NULL; + (void)identity_resource(_surface->texture); + return (struct identity_surface *)_surface; +} + +static INLINE struct identity_transfer * +identity_transfer(struct pipe_transfer *_transfer) +{ + if(!_transfer) + return NULL; + (void)identity_resource(_transfer->resource); + return (struct identity_transfer *)_transfer; +} + +static INLINE struct pipe_resource * +identity_resource_unwrap(struct pipe_resource *_resource) +{ + if(!_resource) + return NULL; + return identity_resource(_resource)->resource; +} + +static INLINE struct pipe_sampler_view * +identity_sampler_view_unwrap(struct pipe_sampler_view *_sampler_view) +{ + if (!_sampler_view) { + return NULL; + } + return identity_sampler_view(_sampler_view)->sampler_view; +} + +static INLINE struct pipe_surface * +identity_surface_unwrap(struct pipe_surface *_surface) +{ + if(!_surface) + return NULL; + return identity_surface(_surface)->surface; +} + +static INLINE struct pipe_transfer * +identity_transfer_unwrap(struct pipe_transfer *_transfer) +{ + if(!_transfer) + return NULL; + return identity_transfer(_transfer)->transfer; +} + + +struct pipe_resource * +identity_resource_create(struct identity_screen *id_screen, + struct pipe_resource *resource); + +void +identity_resource_destroy(struct identity_resource *id_resource); + +struct pipe_surface * +identity_surface_create(struct identity_context *id_context, + struct identity_resource *id_resource, + struct pipe_surface *surface); + +void +identity_surface_destroy(struct identity_context *id_context, + struct identity_surface *id_surface); + +struct pipe_sampler_view * +identity_sampler_view_create(struct identity_context *id_context, + struct identity_resource *id_resource, + struct pipe_sampler_view *view); + +void +identity_sampler_view_destroy(struct identity_context *id_context, + struct identity_sampler_view *id_sampler_view); + +struct pipe_transfer * +identity_transfer_create(struct identity_context *id_context, + struct identity_resource *id_resource, + struct pipe_transfer *transfer); + +void +identity_transfer_destroy(struct identity_context *id_context, + struct identity_transfer *id_transfer); + + +#endif /* ID_OBJECTS_H */ diff --git a/src/gallium/drivers/identity/id_public.h b/src/gallium/drivers/identity/id_public.h new file mode 100644 index 0000000..d0d5847 --- /dev/null +++ b/src/gallium/drivers/identity/id_public.h @@ -0,0 +1,37 @@ +/************************************************************************** + * + * 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 ID_PUBLIC_H +#define ID_PUBLIC_H + +struct pipe_screen; +struct pipe_context; + +struct pipe_screen * +identity_screen_create(struct pipe_screen *screen); + +#endif /* ID_PUBLIC_H */ diff --git a/src/gallium/drivers/identity/id_screen.c b/src/gallium/drivers/identity/id_screen.c new file mode 100644 index 0000000..644481b --- /dev/null +++ b/src/gallium/drivers/identity/id_screen.c @@ -0,0 +1,304 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "pipe/p_screen.h" +#include "pipe/p_state.h" +#include "util/u_memory.h" + +#include "id_public.h" +#include "id_screen.h" +#include "id_context.h" +#include "id_objects.h" + + +static void +identity_screen_destroy(struct pipe_screen *_screen) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct pipe_screen *screen = id_screen->screen; + + screen->destroy(screen); + + FREE(id_screen); +} + +static const char * +identity_screen_get_name(struct pipe_screen *_screen) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct pipe_screen *screen = id_screen->screen; + + return screen->get_name(screen); +} + +static const char * +identity_screen_get_vendor(struct pipe_screen *_screen) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct pipe_screen *screen = id_screen->screen; + + return screen->get_vendor(screen); +} + +static int +identity_screen_get_param(struct pipe_screen *_screen, + enum pipe_cap param) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct pipe_screen *screen = id_screen->screen; + + return screen->get_param(screen, + param); +} + +static int +identity_screen_get_shader_param(struct pipe_screen *_screen, + unsigned shader, enum pipe_shader_cap param) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct pipe_screen *screen = id_screen->screen; + + return screen->get_shader_param(screen, shader, + param); +} + +static float +identity_screen_get_paramf(struct pipe_screen *_screen, + enum pipe_cap param) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct pipe_screen *screen = id_screen->screen; + + return screen->get_paramf(screen, + param); +} + +static boolean +identity_screen_is_format_supported(struct pipe_screen *_screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned tex_usage, + unsigned geom_flags) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct pipe_screen *screen = id_screen->screen; + + return screen->is_format_supported(screen, + format, + target, + sample_count, + tex_usage, + geom_flags); +} + +static struct pipe_context * +identity_screen_context_create(struct pipe_screen *_screen, + void *priv) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct pipe_screen *screen = id_screen->screen; + struct pipe_context *result; + + result = screen->context_create(screen, priv); + if (result) + return identity_context_create(_screen, result); + return NULL; +} + +static struct pipe_resource * +identity_screen_resource_create(struct pipe_screen *_screen, + const struct pipe_resource *templat) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct pipe_screen *screen = id_screen->screen; + struct pipe_resource *result; + + result = screen->resource_create(screen, + templat); + + if (result) + return identity_resource_create(id_screen, result); + return NULL; +} + +static struct pipe_resource * +identity_screen_resource_from_handle(struct pipe_screen *_screen, + const struct pipe_resource *templ, + struct winsys_handle *handle) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct pipe_screen *screen = id_screen->screen; + struct pipe_resource *result; + + /* TODO trace call */ + + result = screen->resource_from_handle(screen, templ, handle); + + result = identity_resource_create(identity_screen(_screen), result); + + return result; +} + +static boolean +identity_screen_resource_get_handle(struct pipe_screen *_screen, + struct pipe_resource *_resource, + struct winsys_handle *handle) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct identity_resource *id_resource = identity_resource(_resource); + struct pipe_screen *screen = id_screen->screen; + struct pipe_resource *resource = id_resource->resource; + + /* TODO trace call */ + + return screen->resource_get_handle(screen, resource, handle); +} + + + +static void +identity_screen_resource_destroy(struct pipe_screen *screen, + struct pipe_resource *_resource) +{ + identity_resource_destroy(identity_resource(_resource)); +} + + +static struct pipe_resource * +identity_screen_user_buffer_create(struct pipe_screen *_screen, + void *ptr, + unsigned bytes, + unsigned usage) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct pipe_screen *screen = id_screen->screen; + struct pipe_resource *result; + + result = screen->user_buffer_create(screen, + ptr, + bytes, + usage); + + if (result) + return identity_resource_create(id_screen, result); + return NULL; +} + + + +static void +identity_screen_flush_frontbuffer(struct pipe_screen *_screen, + struct pipe_resource *_resource, + unsigned level, unsigned layer, + void *context_private) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct identity_resource *id_resource = identity_resource(_resource); + struct pipe_screen *screen = id_screen->screen; + struct pipe_resource *resource = id_resource->resource; + + screen->flush_frontbuffer(screen, + resource, + level, layer, + context_private); +} + +static void +identity_screen_fence_reference(struct pipe_screen *_screen, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct pipe_screen *screen = id_screen->screen; + + screen->fence_reference(screen, + ptr, + fence); +} + +static int +identity_screen_fence_signalled(struct pipe_screen *_screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct pipe_screen *screen = id_screen->screen; + + return screen->fence_signalled(screen, + fence, + flags); +} + +static int +identity_screen_fence_finish(struct pipe_screen *_screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct pipe_screen *screen = id_screen->screen; + + return screen->fence_finish(screen, + fence, + flags); +} + +struct pipe_screen * +identity_screen_create(struct pipe_screen *screen) +{ + struct identity_screen *id_screen; + + id_screen = CALLOC_STRUCT(identity_screen); + if (!id_screen) { + return NULL; + } + + id_screen->base.winsys = NULL; + + id_screen->base.destroy = identity_screen_destroy; + id_screen->base.get_name = identity_screen_get_name; + id_screen->base.get_vendor = identity_screen_get_vendor; + id_screen->base.get_param = identity_screen_get_param; + id_screen->base.get_shader_param = identity_screen_get_shader_param; + id_screen->base.get_paramf = identity_screen_get_paramf; + id_screen->base.is_format_supported = identity_screen_is_format_supported; + id_screen->base.context_create = identity_screen_context_create; + id_screen->base.resource_create = identity_screen_resource_create; + id_screen->base.resource_from_handle = identity_screen_resource_from_handle; + id_screen->base.resource_get_handle = identity_screen_resource_get_handle; + id_screen->base.resource_destroy = identity_screen_resource_destroy; + id_screen->base.user_buffer_create = identity_screen_user_buffer_create; + id_screen->base.flush_frontbuffer = identity_screen_flush_frontbuffer; + id_screen->base.fence_reference = identity_screen_fence_reference; + id_screen->base.fence_signalled = identity_screen_fence_signalled; + id_screen->base.fence_finish = identity_screen_fence_finish; + + id_screen->screen = screen; + + return &id_screen->base; +} diff --git a/src/gallium/drivers/identity/id_screen.h b/src/gallium/drivers/identity/id_screen.h new file mode 100644 index 0000000..2c4f129 --- /dev/null +++ b/src/gallium/drivers/identity/id_screen.h @@ -0,0 +1,48 @@ +/************************************************************************** + * + * 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 ID_SCREEN_H +#define ID_SCREEN_H + +#include "pipe/p_screen.h" +#include "pipe/p_defines.h" + + +struct identity_screen { + struct pipe_screen base; + + struct pipe_screen *screen; +}; + + +static INLINE struct identity_screen * +identity_screen(struct pipe_screen *screen) +{ + return (struct identity_screen *)screen; +} + +#endif /* ID_SCREEN_H */ diff --git a/src/gallium/drivers/llvmpipe/Makefile b/src/gallium/drivers/llvmpipe/Makefile new file mode 100644 index 0000000..4068bed --- /dev/null +++ b/src/gallium/drivers/llvmpipe/Makefile @@ -0,0 +1,77 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = llvmpipe + +C_SOURCES = \ + lp_bld_alpha.c \ + lp_bld_blend_aos.c \ + lp_bld_blend_logicop.c \ + lp_bld_blend_soa.c \ + lp_bld_depth.c \ + lp_bld_interp.c \ + lp_clear.c \ + lp_context.c \ + lp_draw_arrays.c \ + lp_fence.c \ + lp_flush.c \ + lp_jit.c \ + lp_memory.c \ + lp_perf.c \ + lp_query.c \ + lp_rast.c \ + lp_rast_debug.c \ + lp_rast_tri.c \ + lp_scene.c \ + lp_scene_queue.c \ + lp_screen.c \ + lp_setup.c \ + lp_setup_line.c \ + lp_setup_point.c \ + lp_setup_tri.c \ + lp_setup_vbuf.c \ + lp_state_blend.c \ + lp_state_clip.c \ + lp_state_derived.c \ + lp_state_fs.c \ + lp_state_setup.c \ + lp_state_gs.c \ + lp_state_rasterizer.c \ + lp_state_sampler.c \ + lp_state_so.c \ + lp_state_surface.c \ + lp_state_vertex.c \ + lp_state_vs.c \ + lp_surface.c \ + lp_tex_sample.c \ + lp_texture.c \ + lp_tile_image.c \ + lp_tile_soa.c + +CPP_SOURCES = \ + +PROGS := lp_test_format \ + lp_test_blend \ + lp_test_conv \ + lp_test_printf \ + lp_test_round \ + lp_test_sincos + +# Need this for the lp_test_*.o files +CLEAN_EXTRA = *.o + +include ../../Makefile.template + +lp_test_sincos.o : sse_mathfun.h + +PROGS_DEPS := ../../auxiliary/libgallium.a + +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 + $(PYTHON2) $(PYTHON_FLAGS) lp_tile_soa.py ../../auxiliary/util/u_format.csv > $@ + +LDFLAGS += $(LLVM_LDFLAGS) +LIBS += -L../../auxiliary/ -lgallium libllvmpipe.a $(LLVM_LIBS) $(GL_LIB_DEPS) +LD=g++ + +$(PROGS): lp_test_main.o libllvmpipe.a + diff --git a/src/gallium/drivers/llvmpipe/SConscript b/src/gallium/drivers/llvmpipe/SConscript new file mode 100644 index 0000000..26b258b --- /dev/null +++ b/src/gallium/drivers/llvmpipe/SConscript @@ -0,0 +1,105 @@ +from sys import executable as python_cmd +import distutils.version + +Import('*') + +if not env['llvm']: + print 'warning: LLVM disabled: not building llvmpipe' + Return() + +env = env.Clone() + +env.Append(CPPPATH = ['.']) + +env.CodeGenerate( + target = 'lp_tile_soa.c', + script = 'lp_tile_soa.py', + source = ['#src/gallium/auxiliary/util/u_format.csv'], + command = python_cmd + ' $SCRIPT $SOURCE > $TARGET' +) + +# XXX: Our dependency scanner only finds depended modules in relative dirs. +env.Depends('lp_tile_soa.c', [ + '#src/gallium/auxiliary/util/u_format_parse.py', + '#src/gallium/auxiliary/util/u_format_pack.py', +]) + + +lp_tile_soa_os = env.SharedObject('lp_tile_soa.c') + + +llvmpipe = env.ConvenienceLibrary( + target = 'llvmpipe', + source = [ + 'lp_bld_alpha.c', + 'lp_bld_blend_aos.c', + 'lp_bld_blend_logicop.c', + 'lp_bld_blend_soa.c', + 'lp_bld_depth.c', + 'lp_bld_interp.c', + 'lp_clear.c', + 'lp_context.c', + 'lp_draw_arrays.c', + 'lp_fence.c', + 'lp_flush.c', + 'lp_jit.c', + 'lp_memory.c', + 'lp_perf.c', + 'lp_query.c', + 'lp_rast.c', + 'lp_rast_debug.c', + 'lp_rast_tri.c', + 'lp_scene.c', + 'lp_scene_queue.c', + 'lp_screen.c', + 'lp_setup.c', + 'lp_setup_line.c', + 'lp_setup_point.c', + 'lp_setup_tri.c', + 'lp_setup_vbuf.c', + 'lp_state_blend.c', + 'lp_state_clip.c', + 'lp_state_derived.c', + 'lp_state_fs.c', + 'lp_state_setup.c', + 'lp_state_gs.c', + 'lp_state_rasterizer.c', + 'lp_state_sampler.c', + 'lp_state_so.c', + 'lp_state_surface.c', + 'lp_state_vertex.c', + 'lp_state_vs.c', + 'lp_surface.c', + 'lp_tex_sample.c', + 'lp_texture.c', + 'lp_tile_image.c', + lp_tile_soa_os, + ]) + +env.Alias('llvmpipe', llvmpipe) + + +if env['platform'] != 'embedded': + env = env.Clone() + + env.Prepend(LIBS = [llvmpipe] + gallium) + + tests = [ + 'format', + 'blend', + 'conv', + 'printf', + 'sincos', + ] + + if not env['msvc']: + tests.append('round') + + for test in tests: + target = env.Program( + target = 'lp_test_' + test, + source = ['lp_test_' + test + '.c', 'lp_test_main.c'], + ) + env.InstallProgram(target) + +Export('llvmpipe') diff --git a/src/gallium/drivers/llvmpipe/lp_bld_alpha.c b/src/gallium/drivers/llvmpipe/lp_bld_alpha.c new file mode 100644 index 0000000..518969c --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_bld_alpha.c @@ -0,0 +1,67 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * Alpha testing to LLVM IR translation. + * + * @author Jose Fonseca + */ + +#include "pipe/p_state.h" + +#include "gallivm/lp_bld_type.h" +#include "gallivm/lp_bld_const.h" +#include "gallivm/lp_bld_logic.h" +#include "gallivm/lp_bld_flow.h" +#include "gallivm/lp_bld_debug.h" + +#include "lp_bld_alpha.h" + + +void +lp_build_alpha_test(struct gallivm_state *gallivm, + unsigned func, + struct lp_type type, + struct lp_build_mask_context *mask, + LLVMValueRef alpha, + LLVMValueRef ref, + boolean do_branch) +{ + struct lp_build_context bld; + LLVMValueRef test; + + lp_build_context_init(&bld, gallivm, type); + + test = lp_build_cmp(&bld, func, alpha, ref); + + lp_build_name(test, "alpha_mask"); + + lp_build_mask_update(mask, test); + + if (do_branch) + lp_build_mask_check(mask); +} diff --git a/src/gallium/drivers/llvmpipe/lp_bld_alpha.h b/src/gallium/drivers/llvmpipe/lp_bld_alpha.h new file mode 100644 index 0000000..5c93925 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_bld_alpha.h @@ -0,0 +1,55 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * Alpha testing to LLVM IR translation. + * + * @author Jose Fonseca + */ + +#ifndef LP_BLD_ALPHA_H +#define LP_BLD_ALPHA_H + + +#include "gallivm/lp_bld.h" + +struct pipe_alpha_state; +struct lp_type; +struct lp_build_mask_context; + + +void +lp_build_alpha_test(struct gallivm_state *gallivm, + unsigned func, + struct lp_type type, + struct lp_build_mask_context *mask, + LLVMValueRef alpha, + LLVMValueRef ref, + boolean do_branch); + + +#endif /* !LP_BLD_ALPHA_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_bld_blend.h b/src/gallium/drivers/llvmpipe/lp_bld_blend.h new file mode 100644 index 0000000..f82ae30 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_bld_blend.h @@ -0,0 +1,99 @@ +/************************************************************************** + * + * 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 LP_BLD_BLEND_H +#define LP_BLD_BLEND_H + + +#include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_init.h" + +#include "pipe/p_format.h" + + +struct pipe_blend_state; +struct lp_type; +struct lp_build_context; + + +/** + * Whether the blending function is commutative or not. + */ +boolean +lp_build_blend_func_commutative(unsigned func); + + +/** + * Whether the blending functions are the reverse of each other. + */ +boolean +lp_build_blend_func_reverse(unsigned rgb_func, unsigned alpha_func); + + +LLVMValueRef +lp_build_blend_func(struct lp_build_context *bld, + unsigned func, + LLVMValueRef term1, + LLVMValueRef term2); + + +LLVMValueRef +lp_build_blend_aos(struct gallivm_state *gallivm, + const struct pipe_blend_state *blend, + struct lp_type type, + unsigned rt, + LLVMValueRef src, + LLVMValueRef dst, + LLVMValueRef const_, + unsigned alpha_swizzle); + + +void +lp_build_blend_soa(struct gallivm_state *gallivm, + const struct pipe_blend_state *blend, + struct lp_type type, + unsigned rt, + LLVMValueRef src[4], + LLVMValueRef dst[4], + LLVMValueRef const_[4], + LLVMValueRef res[4]); + + +/** + * Apply a logic op. + * + * src/dst parameters are packed values. It should work regardless the inputs + * are scalars, or a vector. + */ +LLVMValueRef +lp_build_logicop(LLVMBuilderRef builder, + unsigned logicop_func, + LLVMValueRef src, + LLVMValueRef dst); + + +#endif /* !LP_BLD_BLEND_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c b/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c new file mode 100644 index 0000000..c342346 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_bld_blend_aos.c @@ -0,0 +1,356 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * @file + * Blend LLVM IR generation -- AoS layout. + * + * AoS blending is in general much slower than SoA, but there are some cases + * where it might be faster. In particular, if a pixel is rendered only once + * then the overhead of tiling and untiling will dominate over the speedup that + * SoA gives. So we might want to detect such cases and fallback to AoS in the + * future, but for now this function is here for historical/benchmarking + * purposes. + * + * Run lp_blend_test after any change to this file. + * + * @author Jose Fonseca + */ + + +#include "pipe/p_state.h" +#include "util/u_debug.h" + +#include "gallivm/lp_bld_type.h" +#include "gallivm/lp_bld_const.h" +#include "gallivm/lp_bld_arit.h" +#include "gallivm/lp_bld_logic.h" +#include "gallivm/lp_bld_swizzle.h" +#include "gallivm/lp_bld_debug.h" + +#include "lp_bld_blend.h" + + +/** + * We may the same values several times, so we keep them here to avoid + * recomputing them. Also reusing the values allows us to do simplifications + * that LLVM optimization passes wouldn't normally be able to do. + */ +struct lp_build_blend_aos_context +{ + struct lp_build_context base; + + LLVMValueRef src; + LLVMValueRef dst; + LLVMValueRef const_; + + LLVMValueRef inv_src; + LLVMValueRef inv_dst; + LLVMValueRef inv_const; + LLVMValueRef saturate; + + LLVMValueRef rgb_src_factor; + LLVMValueRef alpha_src_factor; + LLVMValueRef rgb_dst_factor; + LLVMValueRef alpha_dst_factor; +}; + + +static LLVMValueRef +lp_build_blend_factor_unswizzled(struct lp_build_blend_aos_context *bld, + unsigned factor, + boolean alpha) +{ + switch (factor) { + case PIPE_BLENDFACTOR_ZERO: + return bld->base.zero; + case PIPE_BLENDFACTOR_ONE: + return bld->base.one; + case PIPE_BLENDFACTOR_SRC_COLOR: + case PIPE_BLENDFACTOR_SRC_ALPHA: + return bld->src; + case PIPE_BLENDFACTOR_DST_COLOR: + case PIPE_BLENDFACTOR_DST_ALPHA: + return bld->dst; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + if(alpha) + return bld->base.one; + else { + if(!bld->inv_dst) + bld->inv_dst = lp_build_comp(&bld->base, bld->dst); + if(!bld->saturate) + bld->saturate = lp_build_min(&bld->base, bld->src, bld->inv_dst); + return bld->saturate; + } + case PIPE_BLENDFACTOR_CONST_COLOR: + case PIPE_BLENDFACTOR_CONST_ALPHA: + return bld->const_; + case PIPE_BLENDFACTOR_SRC1_COLOR: + case PIPE_BLENDFACTOR_SRC1_ALPHA: + /* TODO */ + assert(0); + return bld->base.zero; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + if(!bld->inv_src) + bld->inv_src = lp_build_comp(&bld->base, bld->src); + return bld->inv_src; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + if(!bld->inv_dst) + bld->inv_dst = lp_build_comp(&bld->base, bld->dst); + return bld->inv_dst; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + if(!bld->inv_const) + bld->inv_const = lp_build_comp(&bld->base, bld->const_); + return bld->inv_const; + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + /* TODO */ + assert(0); + return bld->base.zero; + default: + assert(0); + return bld->base.zero; + } +} + + +enum lp_build_blend_swizzle { + LP_BUILD_BLEND_SWIZZLE_RGBA = 0, + LP_BUILD_BLEND_SWIZZLE_AAAA = 1 +}; + + +/** + * How should we shuffle the base factor. + */ +static enum lp_build_blend_swizzle +lp_build_blend_factor_swizzle(unsigned factor) +{ + switch (factor) { + case PIPE_BLENDFACTOR_ONE: + case PIPE_BLENDFACTOR_ZERO: + case PIPE_BLENDFACTOR_SRC_COLOR: + case PIPE_BLENDFACTOR_DST_COLOR: + case PIPE_BLENDFACTOR_CONST_COLOR: + case PIPE_BLENDFACTOR_SRC1_COLOR: + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + case PIPE_BLENDFACTOR_INV_DST_COLOR: + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + return LP_BUILD_BLEND_SWIZZLE_RGBA; + case PIPE_BLENDFACTOR_SRC_ALPHA: + case PIPE_BLENDFACTOR_DST_ALPHA: + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + case PIPE_BLENDFACTOR_SRC1_ALPHA: + case PIPE_BLENDFACTOR_CONST_ALPHA: + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + return LP_BUILD_BLEND_SWIZZLE_AAAA; + default: + assert(0); + return LP_BUILD_BLEND_SWIZZLE_RGBA; + } +} + + +static LLVMValueRef +lp_build_blend_swizzle(struct lp_build_blend_aos_context *bld, + LLVMValueRef rgb, + LLVMValueRef alpha, + enum lp_build_blend_swizzle rgb_swizzle, + unsigned alpha_swizzle) +{ + LLVMValueRef swizzled_rgb; + + switch (rgb_swizzle) { + case LP_BUILD_BLEND_SWIZZLE_RGBA: + swizzled_rgb = rgb; + break; + case LP_BUILD_BLEND_SWIZZLE_AAAA: + swizzled_rgb = lp_build_swizzle_scalar_aos(&bld->base, rgb, alpha_swizzle); + break; + default: + assert(0); + swizzled_rgb = bld->base.undef; + } + + if (rgb != alpha) { + swizzled_rgb = lp_build_select_aos(&bld->base, 1 << alpha_swizzle, + alpha, swizzled_rgb); + } + + return swizzled_rgb; +} + + +/** + * @sa http://www.opengl.org/sdk/docs/man/xhtml/glBlendFuncSeparate.xml + */ +static LLVMValueRef +lp_build_blend_factor(struct lp_build_blend_aos_context *bld, + LLVMValueRef factor1, + unsigned rgb_factor, + unsigned alpha_factor, + unsigned alpha_swizzle) +{ + LLVMValueRef rgb_factor_; + LLVMValueRef alpha_factor_; + LLVMValueRef factor2; + enum lp_build_blend_swizzle rgb_swizzle; + + rgb_factor_ = lp_build_blend_factor_unswizzled(bld, rgb_factor, FALSE); + alpha_factor_ = lp_build_blend_factor_unswizzled(bld, alpha_factor, TRUE); + + rgb_swizzle = lp_build_blend_factor_swizzle(rgb_factor); + + factor2 = lp_build_blend_swizzle(bld, rgb_factor_, alpha_factor_, rgb_swizzle, alpha_swizzle); + + return lp_build_mul(&bld->base, factor1, factor2); +} + + +/** + * Is (a OP b) == (b OP a)? + */ +boolean +lp_build_blend_func_commutative(unsigned func) +{ + switch (func) { + case PIPE_BLEND_ADD: + case PIPE_BLEND_MIN: + case PIPE_BLEND_MAX: + return TRUE; + case PIPE_BLEND_SUBTRACT: + case PIPE_BLEND_REVERSE_SUBTRACT: + return FALSE; + default: + assert(0); + return TRUE; + } +} + + +boolean +lp_build_blend_func_reverse(unsigned rgb_func, unsigned alpha_func) +{ + if(rgb_func == alpha_func) + return FALSE; + if(rgb_func == PIPE_BLEND_SUBTRACT && alpha_func == PIPE_BLEND_REVERSE_SUBTRACT) + return TRUE; + if(rgb_func == PIPE_BLEND_REVERSE_SUBTRACT && alpha_func == PIPE_BLEND_SUBTRACT) + return TRUE; + return FALSE; +} + + +/** + * @sa http://www.opengl.org/sdk/docs/man/xhtml/glBlendEquationSeparate.xml + */ +LLVMValueRef +lp_build_blend_func(struct lp_build_context *bld, + unsigned func, + LLVMValueRef term1, + LLVMValueRef term2) +{ + switch (func) { + case PIPE_BLEND_ADD: + return lp_build_add(bld, term1, term2); + case PIPE_BLEND_SUBTRACT: + return lp_build_sub(bld, term1, term2); + case PIPE_BLEND_REVERSE_SUBTRACT: + return lp_build_sub(bld, term2, term1); + case PIPE_BLEND_MIN: + return lp_build_min(bld, term1, term2); + case PIPE_BLEND_MAX: + return lp_build_max(bld, term1, term2); + default: + assert(0); + return bld->zero; + } +} + + +LLVMValueRef +lp_build_blend_aos(struct gallivm_state *gallivm, + const struct pipe_blend_state *blend, + struct lp_type type, + unsigned rt, + LLVMValueRef src, + LLVMValueRef dst, + LLVMValueRef const_, + unsigned alpha_swizzle) +{ + struct lp_build_blend_aos_context bld; + LLVMValueRef src_term; + LLVMValueRef dst_term; + + /* FIXME: color masking not implemented yet */ + assert(blend->rt[rt].colormask == 0xf); + + if(!blend->rt[rt].blend_enable) + return src; + + /* Setup build context */ + memset(&bld, 0, sizeof bld); + lp_build_context_init(&bld.base, gallivm, type); + bld.src = src; + bld.dst = dst; + bld.const_ = const_; + + /* TODO: There are still a few optimization opportunities here. For certain + * combinations it is possible to reorder the operations and therefore saving + * some instructions. */ + + src_term = lp_build_blend_factor(&bld, src, blend->rt[rt].rgb_src_factor, + blend->rt[rt].alpha_src_factor, alpha_swizzle); + dst_term = lp_build_blend_factor(&bld, dst, blend->rt[rt].rgb_dst_factor, + blend->rt[rt].alpha_dst_factor, alpha_swizzle); + + lp_build_name(src_term, "src_term"); + lp_build_name(dst_term, "dst_term"); + + if(blend->rt[rt].rgb_func == blend->rt[rt].alpha_func) { + return lp_build_blend_func(&bld.base, blend->rt[rt].rgb_func, src_term, dst_term); + } + else { + /* Seperate RGB / A functions */ + + LLVMValueRef rgb; + LLVMValueRef alpha; + + rgb = lp_build_blend_func(&bld.base, blend->rt[rt].rgb_func, src_term, dst_term); + alpha = lp_build_blend_func(&bld.base, blend->rt[rt].alpha_func, src_term, dst_term); + + return lp_build_blend_swizzle(&bld, rgb, alpha, LP_BUILD_BLEND_SWIZZLE_RGBA, alpha_swizzle); + } +} diff --git a/src/gallium/drivers/llvmpipe/lp_bld_blend_logicop.c b/src/gallium/drivers/llvmpipe/lp_bld_blend_logicop.c new file mode 100644 index 0000000..1eac0a5 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_bld_blend_logicop.c @@ -0,0 +1,109 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * @file + * Blend LLVM IR generation -- logic ops. + * + * @author Jose Fonseca + */ + + +#include "pipe/p_state.h" +#include "util/u_debug.h" + +#include "lp_bld_blend.h" + + +LLVMValueRef +lp_build_logicop(LLVMBuilderRef builder, + unsigned logicop_func, + LLVMValueRef src, + LLVMValueRef dst) +{ + LLVMTypeRef type; + LLVMValueRef res; + + type = LLVMTypeOf(src); + + switch (logicop_func) { + case PIPE_LOGICOP_CLEAR: + res = LLVMConstNull(type); + break; + case PIPE_LOGICOP_NOR: + res = LLVMBuildNot(builder, LLVMBuildOr(builder, src, dst, ""), ""); + break; + case PIPE_LOGICOP_AND_INVERTED: + res = LLVMBuildAnd(builder, LLVMBuildNot(builder, src, ""), dst, ""); + break; + case PIPE_LOGICOP_COPY_INVERTED: + res = LLVMBuildNot(builder, src, ""); + break; + case PIPE_LOGICOP_AND_REVERSE: + res = LLVMBuildAnd(builder, src, LLVMBuildNot(builder, dst, ""), ""); + break; + case PIPE_LOGICOP_INVERT: + res = LLVMBuildNot(builder, dst, ""); + break; + case PIPE_LOGICOP_XOR: + res = LLVMBuildXor(builder, src, dst, ""); + break; + case PIPE_LOGICOP_NAND: + res = LLVMBuildNot(builder, LLVMBuildAnd(builder, src, dst, ""), ""); + break; + case PIPE_LOGICOP_AND: + res = LLVMBuildAnd(builder, src, dst, ""); + break; + case PIPE_LOGICOP_EQUIV: + res = LLVMBuildNot(builder, LLVMBuildXor(builder, src, dst, ""), ""); + break; + case PIPE_LOGICOP_NOOP: + res = dst; + break; + case PIPE_LOGICOP_OR_INVERTED: + res = LLVMBuildOr(builder, LLVMBuildNot(builder, src, ""), dst, ""); + break; + case PIPE_LOGICOP_COPY: + res = src; + break; + case PIPE_LOGICOP_OR_REVERSE: + res = LLVMBuildOr(builder, src, LLVMBuildNot(builder, dst, ""), ""); + break; + case PIPE_LOGICOP_OR: + res = LLVMBuildOr(builder, src, dst, ""); + break; + case PIPE_LOGICOP_SET: + res = LLVMConstAllOnes(type); + break; + default: + assert(0); + res = src; + } + + return res; +} diff --git a/src/gallium/drivers/llvmpipe/lp_bld_blend_soa.c b/src/gallium/drivers/llvmpipe/lp_bld_blend_soa.c new file mode 100644 index 0000000..4d5bc96 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_bld_blend_soa.c @@ -0,0 +1,368 @@ +/************************************************************************** + * + * Copyright 2009-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/** + * @file + * Blend LLVM IR generation -- SoA layout. + * + * Blending in SoA is much faster than AoS, especially when separate rgb/alpha + * factors/functions are used, since no channel masking/shuffling is necessary + * and we can achieve the full throughput of the SIMD operations. Furthermore + * the fragment shader output is also in SoA, so it fits nicely with the rest + * of the fragment pipeline. + * + * The drawback is that to be displayed the color buffer needs to be in AoS + * layout, so we need to tile/untile the color buffer before/after rendering. + * A color buffer like + * + * R11 G11 B11 A11 R12 G12 B12 A12 R13 G13 B13 A13 R14 G14 B14 A14 ... + * R21 G21 B21 A21 R22 G22 B22 A22 R23 G23 B23 A23 R24 G24 B24 A24 ... + * + * R31 G31 B31 A31 R32 G32 B32 A32 R33 G33 B33 A33 R34 G34 B34 A34 ... + * R41 G41 B41 A41 R42 G42 B42 A42 R43 G43 B43 A43 R44 G44 B44 A44 ... + * + * ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... + * + * will actually be stored in memory as + * + * R11 R12 R21 R22 R13 R14 R23 R24 ... G11 G12 G21 G22 G13 G14 G23 G24 ... B11 B12 B21 B22 B13 B14 B23 B24 ... A11 A12 A21 A22 A13 A14 A23 A24 ... + * R31 R32 R41 R42 R33 R34 R43 R44 ... G31 G32 G41 G42 G33 G34 G43 G44 ... B31 B32 B41 B42 B33 B34 B43 B44 ... A31 A32 A41 A42 A33 A34 A43 A44 ... + * ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... + * + * NOTE: Run lp_blend_test after any change to this file. + * + * You can also run lp_blend_test to obtain AoS vs SoA benchmarks. Invoking it + * as: + * + * lp_blend_test -o blend.tsv + * + * will generate a tab-seperated-file with the test results and performance + * measurements. + * + * @author Jose Fonseca + */ + + +#include "pipe/p_state.h" +#include "util/u_debug.h" + +#include "gallivm/lp_bld_type.h" +#include "gallivm/lp_bld_arit.h" +#include "gallivm/lp_bld_init.h" +#include "lp_bld_blend.h" + + +/** + * We may use the same values several times, so we keep them here to avoid + * recomputing them. Also reusing the values allows us to do simplifications + * that LLVM optimization passes wouldn't normally be able to do. + */ +struct lp_build_blend_soa_context +{ + struct lp_build_context base; + + LLVMValueRef src[4]; + LLVMValueRef dst[4]; + LLVMValueRef con[4]; + + LLVMValueRef inv_src[4]; + LLVMValueRef inv_dst[4]; + LLVMValueRef inv_con[4]; + + LLVMValueRef src_alpha_saturate; + + /** + * We store all factors in a table in order to eliminate redundant + * multiplications later. + * Indexes are: factor[src,dst][color,term][r,g,b,a] + */ + LLVMValueRef factor[2][2][4]; + + /** + * Table with all terms. + * Indexes are: term[src,dst][r,g,b,a] + */ + LLVMValueRef term[2][4]; +}; + + +/** + * Build a single SOA blend factor for a color channel. + * \param i the color channel in [0,3] + */ +static LLVMValueRef +lp_build_blend_soa_factor(struct lp_build_blend_soa_context *bld, + unsigned factor, unsigned i) +{ + /* + * Compute src/first term RGB + */ + switch (factor) { + case PIPE_BLENDFACTOR_ONE: + return bld->base.one; + case PIPE_BLENDFACTOR_SRC_COLOR: + return bld->src[i]; + case PIPE_BLENDFACTOR_SRC_ALPHA: + return bld->src[3]; + case PIPE_BLENDFACTOR_DST_COLOR: + return bld->dst[i]; + case PIPE_BLENDFACTOR_DST_ALPHA: + return bld->dst[3]; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + if(i == 3) + return bld->base.one; + else { + if(!bld->inv_dst[3]) + bld->inv_dst[3] = lp_build_comp(&bld->base, bld->dst[3]); + if(!bld->src_alpha_saturate) + bld->src_alpha_saturate = lp_build_min(&bld->base, bld->src[3], bld->inv_dst[3]); + return bld->src_alpha_saturate; + } + case PIPE_BLENDFACTOR_CONST_COLOR: + return bld->con[i]; + case PIPE_BLENDFACTOR_CONST_ALPHA: + return bld->con[3]; + case PIPE_BLENDFACTOR_SRC1_COLOR: + /* TODO */ + assert(0); + return bld->base.zero; + case PIPE_BLENDFACTOR_SRC1_ALPHA: + /* TODO */ + assert(0); + return bld->base.zero; + case PIPE_BLENDFACTOR_ZERO: + return bld->base.zero; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + if(!bld->inv_src[i]) + bld->inv_src[i] = lp_build_comp(&bld->base, bld->src[i]); + return bld->inv_src[i]; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + if(!bld->inv_src[3]) + bld->inv_src[3] = lp_build_comp(&bld->base, bld->src[3]); + return bld->inv_src[3]; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + if(!bld->inv_dst[i]) + bld->inv_dst[i] = lp_build_comp(&bld->base, bld->dst[i]); + return bld->inv_dst[i]; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + if(!bld->inv_dst[3]) + bld->inv_dst[3] = lp_build_comp(&bld->base, bld->dst[3]); + return bld->inv_dst[3]; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + if(!bld->inv_con[i]) + bld->inv_con[i] = lp_build_comp(&bld->base, bld->con[i]); + return bld->inv_con[i]; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + if(!bld->inv_con[3]) + bld->inv_con[3] = lp_build_comp(&bld->base, bld->con[3]); + return bld->inv_con[3]; + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + /* TODO */ + assert(0); + return bld->base.zero; + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + /* TODO */ + assert(0); + return bld->base.zero; + default: + assert(0); + return bld->base.zero; + } +} + + +static boolean +lp_build_blend_factor_complementary(unsigned src_factor, unsigned dst_factor) +{ + return dst_factor == (src_factor ^ 0x10); +} + + +/** + * Generate blend code in SOA mode. + * \param rt render target index (to index the blend / colormask state) + * \param src src/fragment color + * \param dst dst/framebuffer color + * \param con constant blend color + * \param res the result/output + */ +void +lp_build_blend_soa(struct gallivm_state *gallivm, + const struct pipe_blend_state *blend, + struct lp_type type, + unsigned rt, + LLVMValueRef src[4], + LLVMValueRef dst[4], + LLVMValueRef con[4], + LLVMValueRef res[4]) +{ + LLVMBuilderRef builder = gallivm->builder; + struct lp_build_blend_soa_context bld; + unsigned i, j, k; + + assert(rt < PIPE_MAX_COLOR_BUFS); + + /* Setup build context */ + memset(&bld, 0, sizeof bld); + lp_build_context_init(&bld.base, gallivm, type); + for (i = 0; i < 4; ++i) { + bld.src[i] = src[i]; + bld.dst[i] = dst[i]; + bld.con[i] = con[i]; + } + + for (i = 0; i < 4; ++i) { + /* only compute blending for the color channels enabled for writing */ + if (blend->rt[rt].colormask & (1 << i)) { + if (blend->logicop_enable) { + if(!type.floating) { + res[i] = lp_build_logicop(builder, blend->logicop_func, src[i], dst[i]); + } + else + res[i] = dst[i]; + } + else if (blend->rt[rt].blend_enable) { + unsigned src_factor = i < 3 ? blend->rt[rt].rgb_src_factor : blend->rt[rt].alpha_src_factor; + unsigned dst_factor = i < 3 ? blend->rt[rt].rgb_dst_factor : blend->rt[rt].alpha_dst_factor; + unsigned func = i < 3 ? blend->rt[rt].rgb_func : blend->rt[rt].alpha_func; + boolean func_commutative = lp_build_blend_func_commutative(func); + + if (func == PIPE_BLEND_ADD && + lp_build_blend_factor_complementary(src_factor, dst_factor) && 0) { + /* + * Special case linear interpolation, (i.e., complementary factors). + */ + + LLVMValueRef weight; + if (src_factor < dst_factor) { + weight = lp_build_blend_soa_factor(&bld, src_factor, i); + res[i] = lp_build_lerp(&bld.base, weight, dst[i], src[i]); + } else { + weight = lp_build_blend_soa_factor(&bld, dst_factor, i); + res[i] = lp_build_lerp(&bld.base, weight, src[i], dst[i]); + } + continue; + } + + if ((func == PIPE_BLEND_ADD || + func == PIPE_BLEND_SUBTRACT || + func == PIPE_BLEND_REVERSE_SUBTRACT) && + src_factor == dst_factor && + type.floating) { + /* + * Special common factor. + * + * XXX: Only for floating points for now, since saturation will + * cause different results. + */ + + LLVMValueRef factor; + factor = lp_build_blend_soa_factor(&bld, src_factor, i); + res[i] = lp_build_blend_func(&bld.base, func, src[i], dst[i]); + res[i] = lp_build_mul(&bld.base, res[i], factor); + continue; + } + + /* + * Compute src/dst factors. + */ + + bld.factor[0][0][i] = src[i]; + bld.factor[0][1][i] = lp_build_blend_soa_factor(&bld, src_factor, i); + bld.factor[1][0][i] = dst[i]; + bld.factor[1][1][i] = lp_build_blend_soa_factor(&bld, dst_factor, i); + + /* + * Compute src/dst terms + */ + + for(k = 0; k < 2; ++k) { + /* See if this multiplication has been previously computed */ + for(j = 0; j < i; ++j) { + if((bld.factor[k][0][j] == bld.factor[k][0][i] && + bld.factor[k][1][j] == bld.factor[k][1][i]) || + (bld.factor[k][0][j] == bld.factor[k][1][i] && + bld.factor[k][1][j] == bld.factor[k][0][i])) + break; + } + + if(j < i) + bld.term[k][i] = bld.term[k][j]; + else + bld.term[k][i] = lp_build_mul(&bld.base, bld.factor[k][0][i], bld.factor[k][1][i]); + + if (src_factor == PIPE_BLENDFACTOR_ZERO && + (dst_factor == PIPE_BLENDFACTOR_DST_ALPHA || + dst_factor == PIPE_BLENDFACTOR_INV_DST_ALPHA)) { + /* XXX special case these combos to work around an apparent + * bug in LLVM. + * This hack disables the check for multiplication by zero + * in lp_bld_mul(). When we optimize away the + * multiplication, something goes wrong during code + * generation and we segfault at runtime. + */ + LLVMValueRef zeroSave = bld.base.zero; + bld.base.zero = NULL; + bld.term[k][i] = lp_build_mul(&bld.base, bld.factor[k][0][i], + bld.factor[k][1][i]); + bld.base.zero = zeroSave; + } + } + + /* + * Combine terms + */ + + /* See if this function has been previously applied */ + for(j = 0; j < i; ++j) { + unsigned prev_func = j < 3 ? blend->rt[rt].rgb_func : blend->rt[rt].alpha_func; + unsigned func_reverse = lp_build_blend_func_reverse(func, prev_func); + + if((!func_reverse && + bld.term[0][j] == bld.term[0][i] && + bld.term[1][j] == bld.term[1][i]) || + ((func_commutative || func_reverse) && + bld.term[0][j] == bld.term[1][i] && + bld.term[1][j] == bld.term[0][i])) + break; + } + + if(j < i) + res[i] = res[j]; + else + res[i] = lp_build_blend_func(&bld.base, func, bld.term[0][i], bld.term[1][i]); + } + else { + res[i] = src[i]; + } + } + else { + res[i] = dst[i]; + } + } +} diff --git a/src/gallium/drivers/llvmpipe/lp_bld_depth.c b/src/gallium/drivers/llvmpipe/lp_bld_depth.c new file mode 100644 index 0000000..1bf7411 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_bld_depth.c @@ -0,0 +1,810 @@ +/************************************************************************** + * + * Copyright 2009-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Depth/stencil testing to LLVM IR translation. + * + * To be done accurately/efficiently the depth/stencil test must be done with + * the same type/format of the depth/stencil buffer, which implies massaging + * the incoming depths to fit into place. Using a more straightforward + * type/format for depth/stencil values internally and only convert when + * flushing would avoid this, but it would most likely result in depth fighting + * artifacts. + * + * We are free to use a different pixel layout though. Since our basic + * processing unit is a quad (2x2 pixel block) we store the depth/stencil + * values tiled, a quad at time. That is, a depth buffer containing + * + * Z11 Z12 Z13 Z14 ... + * Z21 Z22 Z23 Z24 ... + * Z31 Z32 Z33 Z34 ... + * Z41 Z42 Z43 Z44 ... + * ... ... ... ... ... + * + * will actually be stored in memory as + * + * Z11 Z12 Z21 Z22 Z13 Z14 Z23 Z24 ... + * Z31 Z32 Z41 Z42 Z33 Z34 Z43 Z44 ... + * ... ... ... ... ... ... ... ... ... + * + * + * @author Jose Fonseca + * @author Brian Paul + */ + +#include "pipe/p_state.h" +#include "util/u_format.h" + +#include "gallivm/lp_bld_type.h" +#include "gallivm/lp_bld_arit.h" +#include "gallivm/lp_bld_bitarit.h" +#include "gallivm/lp_bld_const.h" +#include "gallivm/lp_bld_conv.h" +#include "gallivm/lp_bld_logic.h" +#include "gallivm/lp_bld_flow.h" +#include "gallivm/lp_bld_intr.h" +#include "gallivm/lp_bld_debug.h" +#include "gallivm/lp_bld_swizzle.h" + +#include "lp_bld_depth.h" + + +/** Used to select fields from pipe_stencil_state */ +enum stencil_op { + S_FAIL_OP, + Z_FAIL_OP, + Z_PASS_OP +}; + + + +/** + * Do the stencil test comparison (compare FB stencil values against ref value). + * This will be used twice when generating two-sided stencil code. + * \param stencil the front/back stencil state + * \param stencilRef the stencil reference value, replicated as a vector + * \param stencilVals vector of stencil values from framebuffer + * \return vector mask of pass/fail values (~0 or 0) + */ +static LLVMValueRef +lp_build_stencil_test_single(struct lp_build_context *bld, + const struct pipe_stencil_state *stencil, + LLVMValueRef stencilRef, + LLVMValueRef stencilVals) +{ + LLVMBuilderRef builder = bld->gallivm->builder; + const unsigned stencilMax = 255; /* XXX fix */ + struct lp_type type = bld->type; + LLVMValueRef res; + + assert(type.sign); + + assert(stencil->enabled); + + if (stencil->valuemask != stencilMax) { + /* compute stencilRef = stencilRef & valuemask */ + LLVMValueRef valuemask = lp_build_const_int_vec(bld->gallivm, type, stencil->valuemask); + stencilRef = LLVMBuildAnd(builder, stencilRef, valuemask, ""); + /* compute stencilVals = stencilVals & valuemask */ + stencilVals = LLVMBuildAnd(builder, stencilVals, valuemask, ""); + } + + res = lp_build_cmp(bld, stencil->func, stencilRef, stencilVals); + + return res; +} + + +/** + * Do the one or two-sided stencil test comparison. + * \sa lp_build_stencil_test_single + * \param front_facing an integer vector mask, indicating front (~0) or back + * (0) facing polygon. If NULL, assume front-facing. + */ +static LLVMValueRef +lp_build_stencil_test(struct lp_build_context *bld, + const struct pipe_stencil_state stencil[2], + LLVMValueRef stencilRefs[2], + LLVMValueRef stencilVals, + LLVMValueRef front_facing) +{ + LLVMValueRef res; + + assert(stencil[0].enabled); + + /* do front face test */ + res = lp_build_stencil_test_single(bld, &stencil[0], + stencilRefs[0], stencilVals); + + if (stencil[1].enabled && front_facing) { + /* do back face test */ + LLVMValueRef back_res; + + back_res = lp_build_stencil_test_single(bld, &stencil[1], + stencilRefs[1], stencilVals); + + res = lp_build_select(bld, front_facing, res, back_res); + } + + return res; +} + + +/** + * Apply the stencil operator (add/sub/keep/etc) to the given vector + * of stencil values. + * \return new stencil values vector + */ +static LLVMValueRef +lp_build_stencil_op_single(struct lp_build_context *bld, + const struct pipe_stencil_state *stencil, + enum stencil_op op, + LLVMValueRef stencilRef, + LLVMValueRef stencilVals) + +{ + LLVMBuilderRef builder = bld->gallivm->builder; + struct lp_type type = bld->type; + LLVMValueRef res; + LLVMValueRef max = lp_build_const_int_vec(bld->gallivm, type, 0xff); + unsigned stencil_op; + + assert(type.sign); + + switch (op) { + case S_FAIL_OP: + stencil_op = stencil->fail_op; + break; + case Z_FAIL_OP: + stencil_op = stencil->zfail_op; + break; + case Z_PASS_OP: + stencil_op = stencil->zpass_op; + break; + default: + assert(0 && "Invalid stencil_op mode"); + stencil_op = PIPE_STENCIL_OP_KEEP; + } + + switch (stencil_op) { + case PIPE_STENCIL_OP_KEEP: + res = stencilVals; + /* we can return early for this case */ + return res; + case PIPE_STENCIL_OP_ZERO: + res = bld->zero; + break; + case PIPE_STENCIL_OP_REPLACE: + res = stencilRef; + break; + case PIPE_STENCIL_OP_INCR: + res = lp_build_add(bld, stencilVals, bld->one); + res = lp_build_min(bld, res, max); + break; + case PIPE_STENCIL_OP_DECR: + res = lp_build_sub(bld, stencilVals, bld->one); + res = lp_build_max(bld, res, bld->zero); + break; + case PIPE_STENCIL_OP_INCR_WRAP: + res = lp_build_add(bld, stencilVals, bld->one); + res = LLVMBuildAnd(builder, res, max, ""); + break; + case PIPE_STENCIL_OP_DECR_WRAP: + res = lp_build_sub(bld, stencilVals, bld->one); + res = LLVMBuildAnd(builder, res, max, ""); + break; + case PIPE_STENCIL_OP_INVERT: + res = LLVMBuildNot(builder, stencilVals, ""); + res = LLVMBuildAnd(builder, res, max, ""); + break; + default: + assert(0 && "bad stencil op mode"); + res = bld->undef; + } + + return res; +} + + +/** + * Do the one or two-sided stencil test op/update. + */ +static LLVMValueRef +lp_build_stencil_op(struct lp_build_context *bld, + const struct pipe_stencil_state stencil[2], + enum stencil_op op, + LLVMValueRef stencilRefs[2], + LLVMValueRef stencilVals, + LLVMValueRef mask, + LLVMValueRef front_facing) + +{ + LLVMBuilderRef builder = bld->gallivm->builder; + LLVMValueRef res; + + assert(stencil[0].enabled); + + /* do front face op */ + res = lp_build_stencil_op_single(bld, &stencil[0], op, + stencilRefs[0], stencilVals); + + if (stencil[1].enabled && front_facing) { + /* do back face op */ + LLVMValueRef back_res; + + back_res = lp_build_stencil_op_single(bld, &stencil[1], op, + stencilRefs[1], stencilVals); + + res = lp_build_select(bld, front_facing, res, back_res); + } + + if (stencil->writemask != 0xff) { + /* mask &= stencil->writemask */ + LLVMValueRef writemask = lp_build_const_int_vec(bld->gallivm, bld->type, + stencil->writemask); + mask = LLVMBuildAnd(builder, mask, writemask, ""); + /* res = (res & mask) | (stencilVals & ~mask) */ + res = lp_build_select_bitwise(bld, mask, res, stencilVals); + } + else { + /* res = mask ? res : stencilVals */ + res = lp_build_select(bld, mask, res, stencilVals); + } + + return res; +} + + + +/** + * Return a type appropriate for depth/stencil testing. + */ +struct lp_type +lp_depth_type(const struct util_format_description *format_desc, + unsigned length) +{ + struct lp_type type; + unsigned swizzle; + + assert(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS); + assert(format_desc->block.width == 1); + assert(format_desc->block.height == 1); + + swizzle = format_desc->swizzle[0]; + assert(swizzle < 4); + + memset(&type, 0, sizeof type); + type.width = format_desc->block.bits; + + if(format_desc->channel[swizzle].type == UTIL_FORMAT_TYPE_FLOAT) { + type.floating = TRUE; + assert(swizzle == 0); + assert(format_desc->channel[swizzle].size == format_desc->block.bits); + } + else if(format_desc->channel[swizzle].type == UTIL_FORMAT_TYPE_UNSIGNED) { + assert(format_desc->block.bits <= 32); + assert(format_desc->channel[swizzle].normalized); + if (format_desc->channel[swizzle].size < format_desc->block.bits) { + /* Prefer signed integers when possible, as SSE has less support + * for unsigned comparison; + */ + type.sign = TRUE; + } + } + else + assert(0); + + assert(type.width <= length); + type.length = length / type.width; + + return type; +} + + +/** + * Compute bitmask and bit shift to apply to the incoming fragment Z values + * and the Z buffer values needed before doing the Z comparison. + * + * Note that we leave the Z bits in the position that we find them + * in the Z buffer (typically 0xffffff00 or 0x00ffffff). That lets us + * get by with fewer bit twiddling steps. + */ +static boolean +get_z_shift_and_mask(const struct util_format_description *format_desc, + unsigned *shift, unsigned *width, unsigned *mask) +{ + const unsigned total_bits = format_desc->block.bits; + unsigned z_swizzle; + unsigned chan; + unsigned padding_left, padding_right; + + assert(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS); + assert(format_desc->block.width == 1); + assert(format_desc->block.height == 1); + + z_swizzle = format_desc->swizzle[0]; + + if (z_swizzle == UTIL_FORMAT_SWIZZLE_NONE) + return FALSE; + + *width = format_desc->channel[z_swizzle].size; + + padding_right = 0; + for (chan = 0; chan < z_swizzle; ++chan) + padding_right += format_desc->channel[chan].size; + + padding_left = + total_bits - (padding_right + *width); + + if (padding_left || padding_right) { + unsigned long long mask_left = (1ULL << (total_bits - padding_left)) - 1; + unsigned long long mask_right = (1ULL << (padding_right)) - 1; + *mask = mask_left ^ mask_right; + } + else { + *mask = 0xffffffff; + } + + *shift = padding_right; + + return TRUE; +} + + +/** + * Compute bitmask and bit shift to apply to the framebuffer pixel values + * to put the stencil bits in the least significant position. + * (i.e. 0x000000ff) + */ +static boolean +get_s_shift_and_mask(const struct util_format_description *format_desc, + unsigned *shift, unsigned *mask) +{ + unsigned s_swizzle; + unsigned chan, sz; + + s_swizzle = format_desc->swizzle[1]; + + if (s_swizzle == UTIL_FORMAT_SWIZZLE_NONE) + return FALSE; + + *shift = 0; + for (chan = 0; chan < s_swizzle; chan++) + *shift += format_desc->channel[chan].size; + + sz = format_desc->channel[s_swizzle].size; + *mask = (1U << sz) - 1U; + + return TRUE; +} + + +/** + * Perform the occlusion test and increase the counter. + * Test the depth mask. Add the number of channel which has none zero mask + * into the occlusion counter. e.g. maskvalue is {-1, -1, -1, -1}. + * The counter will add 4. + * + * \param type holds element type of the mask vector. + * \param maskvalue is the depth test mask. + * \param counter is a pointer of the uint32 counter. + */ +void +lp_build_occlusion_count(struct gallivm_state *gallivm, + struct lp_type type, + LLVMValueRef maskvalue, + LLVMValueRef counter) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMContextRef context = gallivm->context; + LLVMValueRef countmask = lp_build_const_int_vec(gallivm, type, 1); + LLVMValueRef countv = LLVMBuildAnd(builder, maskvalue, countmask, "countv"); + LLVMTypeRef i8v16 = LLVMVectorType(LLVMInt8TypeInContext(context), 16); + LLVMValueRef counti = LLVMBuildBitCast(builder, countv, i8v16, "counti"); + LLVMValueRef maskarray[4] = { + lp_build_const_int32(gallivm, 0), + lp_build_const_int32(gallivm, 4), + lp_build_const_int32(gallivm, 8), + lp_build_const_int32(gallivm, 12) + }; + LLVMValueRef shufflemask = LLVMConstVector(maskarray, 4); + LLVMValueRef shufflev = LLVMBuildShuffleVector(builder, counti, LLVMGetUndef(i8v16), shufflemask, "shufflev"); + LLVMValueRef shuffle = LLVMBuildBitCast(builder, shufflev, LLVMInt32TypeInContext(context), "shuffle"); + LLVMValueRef count = lp_build_intrinsic_unary(builder, "llvm.ctpop.i32", LLVMInt32TypeInContext(context), shuffle); + LLVMValueRef orig = LLVMBuildLoad(builder, counter, "orig"); + LLVMValueRef incr = LLVMBuildAdd(builder, orig, count, "incr"); + LLVMBuildStore(builder, incr, counter); +} + + + +/** + * Generate code for performing depth and/or stencil tests. + * We operate on a vector of values (typically a 2x2 quad). + * + * \param depth the depth test state + * \param stencil the front/back stencil state + * \param type the data type of the fragment depth/stencil values + * \param format_desc description of the depth/stencil surface + * \param mask the alive/dead pixel mask for the quad (vector) + * \param stencil_refs the front/back stencil ref values (scalar) + * \param z_src the incoming depth/stencil values (a 2x2 quad, float32) + * \param zs_dst_ptr pointer to depth/stencil values in framebuffer + * \param facing contains boolean value indicating front/back facing polygon + */ +void +lp_build_depth_stencil_test(struct gallivm_state *gallivm, + const struct pipe_depth_state *depth, + const struct pipe_stencil_state stencil[2], + struct lp_type z_src_type, + const struct util_format_description *format_desc, + struct lp_build_mask_context *mask, + LLVMValueRef stencil_refs[2], + LLVMValueRef z_src, + LLVMValueRef zs_dst_ptr, + LLVMValueRef face, + LLVMValueRef *zs_value, + boolean do_branch) +{ + LLVMBuilderRef builder = gallivm->builder; + struct lp_type z_type; + struct lp_build_context z_bld; + struct lp_build_context s_bld; + struct lp_type s_type; + unsigned z_shift = 0, z_width = 0, z_mask = 0; + LLVMValueRef zs_dst, z_dst = NULL; + LLVMValueRef stencil_vals = NULL; + LLVMValueRef z_bitmask = NULL, stencil_shift = NULL; + LLVMValueRef z_pass = NULL, s_pass_mask = NULL; + LLVMValueRef orig_mask = lp_build_mask_value(mask); + LLVMValueRef front_facing = NULL; + + + /* + * Depths are expected to be between 0 and 1, even if they are stored in + * floats. Setting these bits here will ensure that the lp_build_conv() call + * below won't try to unnecessarily clamp the incoming values. + */ + if(z_src_type.floating) { + z_src_type.sign = FALSE; + z_src_type.norm = TRUE; + } + else { + assert(!z_src_type.sign); + assert(z_src_type.norm); + } + + /* Pick the depth type. */ + z_type = lp_depth_type(format_desc, z_src_type.width*z_src_type.length); + + /* FIXME: Cope with a depth test type with a different bit width. */ + assert(z_type.width == z_src_type.width); + assert(z_type.length == z_src_type.length); + + /* Sanity checking */ + { + const unsigned z_swizzle = format_desc->swizzle[0]; + const unsigned s_swizzle = format_desc->swizzle[1]; + + assert(z_swizzle != UTIL_FORMAT_SWIZZLE_NONE || + s_swizzle != UTIL_FORMAT_SWIZZLE_NONE); + + assert(depth->enabled || stencil[0].enabled); + + assert(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS); + assert(format_desc->block.width == 1); + assert(format_desc->block.height == 1); + + if (stencil[0].enabled) { + assert(format_desc->format == PIPE_FORMAT_Z24_UNORM_S8_USCALED || + format_desc->format == PIPE_FORMAT_S8_USCALED_Z24_UNORM); + } + + assert(z_swizzle < 4); + assert(format_desc->block.bits == z_type.width); + if (z_type.floating) { + assert(z_swizzle == 0); + assert(format_desc->channel[z_swizzle].type == + UTIL_FORMAT_TYPE_FLOAT); + assert(format_desc->channel[z_swizzle].size == + format_desc->block.bits); + } + else { + assert(format_desc->channel[z_swizzle].type == + UTIL_FORMAT_TYPE_UNSIGNED); + assert(format_desc->channel[z_swizzle].normalized); + assert(!z_type.fixed); + } + } + + + /* Setup build context for Z vals */ + lp_build_context_init(&z_bld, gallivm, z_type); + + /* Setup build context for stencil vals */ + s_type = lp_type_int_vec(z_type.width); + lp_build_context_init(&s_bld, gallivm, s_type); + + /* Load current z/stencil value from z/stencil buffer */ + zs_dst_ptr = LLVMBuildBitCast(builder, + zs_dst_ptr, + LLVMPointerType(z_bld.vec_type, 0), ""); + zs_dst = LLVMBuildLoad(builder, zs_dst_ptr, ""); + + lp_build_name(zs_dst, "zs_dst"); + + + /* Compute and apply the Z/stencil bitmasks and shifts. + */ + { + unsigned s_shift, s_mask; + + if (get_z_shift_and_mask(format_desc, &z_shift, &z_width, &z_mask)) { + if (z_mask != 0xffffffff) { + z_bitmask = lp_build_const_int_vec(gallivm, z_type, z_mask); + } + + /* + * Align the framebuffer Z 's LSB to the right. + */ + if (z_shift) { + LLVMValueRef shift = lp_build_const_int_vec(gallivm, z_type, z_shift); + z_dst = LLVMBuildLShr(builder, zs_dst, shift, "z_dst"); + } else if (z_bitmask) { + /* TODO: Instead of loading a mask from memory and ANDing, it's + * probably faster to just shake the bits with two shifts. */ + z_dst = LLVMBuildAnd(builder, zs_dst, z_bitmask, "z_dst"); + } else { + z_dst = zs_dst; + lp_build_name(z_dst, "z_dst"); + } + } + + if (get_s_shift_and_mask(format_desc, &s_shift, &s_mask)) { + if (s_shift) { + LLVMValueRef shift = lp_build_const_int_vec(gallivm, s_type, s_shift); + stencil_vals = LLVMBuildLShr(builder, zs_dst, shift, ""); + stencil_shift = shift; /* used below */ + } + else { + stencil_vals = zs_dst; + } + + if (s_mask != 0xffffffff) { + LLVMValueRef mask = lp_build_const_int_vec(gallivm, s_type, s_mask); + stencil_vals = LLVMBuildAnd(builder, stencil_vals, mask, ""); + } + + lp_build_name(stencil_vals, "s_dst"); + } + } + + if (stencil[0].enabled) { + + if (face) { + LLVMValueRef zero = lp_build_const_int32(gallivm, 0); + + /* front_facing = face != 0 ? ~0 : 0 */ + front_facing = LLVMBuildICmp(builder, LLVMIntNE, face, zero, ""); + front_facing = LLVMBuildSExt(builder, front_facing, + LLVMIntTypeInContext(gallivm->context, + s_bld.type.length*s_bld.type.width), + ""); + front_facing = LLVMBuildBitCast(builder, front_facing, + s_bld.int_vec_type, ""); + } + + /* convert scalar stencil refs into vectors */ + stencil_refs[0] = lp_build_broadcast_scalar(&s_bld, stencil_refs[0]); + stencil_refs[1] = lp_build_broadcast_scalar(&s_bld, stencil_refs[1]); + + s_pass_mask = lp_build_stencil_test(&s_bld, stencil, + stencil_refs, stencil_vals, + front_facing); + + /* apply stencil-fail operator */ + { + LLVMValueRef s_fail_mask = lp_build_andnot(&s_bld, orig_mask, s_pass_mask); + stencil_vals = lp_build_stencil_op(&s_bld, stencil, S_FAIL_OP, + stencil_refs, stencil_vals, + s_fail_mask, front_facing); + } + } + + if (depth->enabled) { + /* + * Convert fragment Z to the desired type, aligning the LSB to the right. + */ + + assert(z_type.width == z_src_type.width); + assert(z_type.length == z_src_type.length); + assert(lp_check_value(z_src_type, z_src)); + if (z_src_type.floating) { + /* + * Convert from floating point values + */ + + if (!z_type.floating) { + z_src = lp_build_clamped_float_to_unsigned_norm(gallivm, + z_src_type, + z_width, + z_src); + } + } else { + /* + * Convert from unsigned normalized values. + */ + + assert(!z_src_type.sign); + assert(!z_src_type.fixed); + assert(z_src_type.norm); + assert(!z_type.floating); + if (z_src_type.width > z_width) { + LLVMValueRef shift = lp_build_const_int_vec(gallivm, z_src_type, + z_src_type.width - z_width); + z_src = LLVMBuildLShr(builder, z_src, shift, ""); + } + } + assert(lp_check_value(z_type, z_src)); + + lp_build_name(z_src, "z_src"); + + /* compare src Z to dst Z, returning 'pass' mask */ + z_pass = lp_build_cmp(&z_bld, depth->func, z_src, z_dst); + + if (!stencil[0].enabled) { + /* We can potentially skip all remaining operations here, but only + * if stencil is disabled because we still need to update the stencil + * buffer values. Don't need to update Z buffer values. + */ + lp_build_mask_update(mask, z_pass); + + if (do_branch) { + lp_build_mask_check(mask); + do_branch = FALSE; + } + } + + if (depth->writemask) { + LLVMValueRef zselectmask; + + /* mask off bits that failed Z test */ + zselectmask = LLVMBuildAnd(builder, orig_mask, z_pass, ""); + + /* mask off bits that failed stencil test */ + if (s_pass_mask) { + zselectmask = LLVMBuildAnd(builder, zselectmask, s_pass_mask, ""); + } + + /* Mix the old and new Z buffer values. + * z_dst[i] = zselectmask[i] ? z_src[i] : z_dst[i] + */ + z_dst = lp_build_select(&z_bld, zselectmask, z_src, z_dst); + } + + if (stencil[0].enabled) { + /* update stencil buffer values according to z pass/fail result */ + LLVMValueRef z_fail_mask, z_pass_mask; + + /* apply Z-fail operator */ + z_fail_mask = lp_build_andnot(&z_bld, orig_mask, z_pass); + stencil_vals = lp_build_stencil_op(&s_bld, stencil, Z_FAIL_OP, + stencil_refs, stencil_vals, + z_fail_mask, front_facing); + + /* apply Z-pass operator */ + z_pass_mask = LLVMBuildAnd(builder, orig_mask, z_pass, ""); + stencil_vals = lp_build_stencil_op(&s_bld, stencil, Z_PASS_OP, + stencil_refs, stencil_vals, + z_pass_mask, front_facing); + } + } + else { + /* No depth test: apply Z-pass operator to stencil buffer values which + * passed the stencil test. + */ + s_pass_mask = LLVMBuildAnd(builder, orig_mask, s_pass_mask, ""); + stencil_vals = lp_build_stencil_op(&s_bld, stencil, Z_PASS_OP, + stencil_refs, stencil_vals, + s_pass_mask, front_facing); + } + + /* Put Z and ztencil bits in the right place */ + if (z_dst && z_shift) { + LLVMValueRef shift = lp_build_const_int_vec(gallivm, z_type, z_shift); + z_dst = LLVMBuildShl(builder, z_dst, shift, ""); + } + if (stencil_vals && stencil_shift) + stencil_vals = LLVMBuildShl(builder, stencil_vals, + stencil_shift, ""); + + /* Finally, merge/store the z/stencil values */ + if ((depth->enabled && depth->writemask) || + (stencil[0].enabled && stencil[0].writemask)) { + + if (z_dst && stencil_vals) + zs_dst = LLVMBuildOr(builder, z_dst, stencil_vals, ""); + else if (z_dst) + zs_dst = z_dst; + else + zs_dst = stencil_vals; + + *zs_value = zs_dst; + } + + if (s_pass_mask) + lp_build_mask_update(mask, s_pass_mask); + + if (depth->enabled && stencil[0].enabled) + lp_build_mask_update(mask, z_pass); + + if (do_branch) + lp_build_mask_check(mask); + +} + + +void +lp_build_depth_write(LLVMBuilderRef builder, + const struct util_format_description *format_desc, + LLVMValueRef zs_dst_ptr, + LLVMValueRef zs_value) +{ + zs_dst_ptr = LLVMBuildBitCast(builder, zs_dst_ptr, + LLVMPointerType(LLVMTypeOf(zs_value), 0), ""); + + LLVMBuildStore(builder, zs_value, zs_dst_ptr); +} + + +void +lp_build_deferred_depth_write(struct gallivm_state *gallivm, + struct lp_type z_src_type, + const struct util_format_description *format_desc, + struct lp_build_mask_context *mask, + LLVMValueRef zs_dst_ptr, + LLVMValueRef zs_value) +{ + struct lp_type z_type; + struct lp_build_context z_bld; + LLVMValueRef z_dst; + LLVMBuilderRef builder = gallivm->builder; + + /* XXX: pointlessly redo type logic: + */ + z_type = lp_depth_type(format_desc, z_src_type.width*z_src_type.length); + lp_build_context_init(&z_bld, gallivm, z_type); + + zs_dst_ptr = LLVMBuildBitCast(builder, zs_dst_ptr, + LLVMPointerType(z_bld.vec_type, 0), ""); + + z_dst = LLVMBuildLoad(builder, zs_dst_ptr, "zsbufval"); + z_dst = lp_build_select(&z_bld, lp_build_mask_value(mask), zs_value, z_dst); + + LLVMBuildStore(builder, z_dst, zs_dst_ptr); +} diff --git a/src/gallium/drivers/llvmpipe/lp_bld_depth.h b/src/gallium/drivers/llvmpipe/lp_bld_depth.h new file mode 100644 index 0000000..038b136 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_bld_depth.h @@ -0,0 +1,87 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * Depth/stencil testing to LLVM IR translation. + * + * @author Jose Fonseca + */ + +#ifndef LP_BLD_DEPTH_H +#define LP_BLD_DEPTH_H + + +#include "gallivm/lp_bld.h" + + +struct pipe_depth_state; +struct util_format_description; +struct lp_type; +struct lp_build_mask_context; + + +struct lp_type +lp_depth_type(const struct util_format_description *format_desc, + unsigned length); + + +void +lp_build_depth_stencil_test(struct gallivm_state *gallivm, + const struct pipe_depth_state *depth, + const struct pipe_stencil_state stencil[2], + struct lp_type type, + const struct util_format_description *format_desc, + struct lp_build_mask_context *mask, + LLVMValueRef stencil_refs[2], + LLVMValueRef zs_src, + LLVMValueRef zs_dst_ptr, + LLVMValueRef facing, + LLVMValueRef *zs_value, + boolean do_branch); + +void +lp_build_depth_write(LLVMBuilderRef builder, + const struct util_format_description *format_desc, + LLVMValueRef zs_dst_ptr, + LLVMValueRef zs_value); + +void +lp_build_deferred_depth_write(struct gallivm_state *gallivm, + struct lp_type z_src_type, + const struct util_format_description *format_desc, + struct lp_build_mask_context *mask, + LLVMValueRef zs_dst_ptr, + LLVMValueRef zs_value); + +void +lp_build_occlusion_count(struct gallivm_state *gallivm, + struct lp_type type, + LLVMValueRef maskvalue, + LLVMValueRef counter); + +#endif /* !LP_BLD_DEPTH_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.c b/src/gallium/drivers/llvmpipe/lp_bld_interp.c new file mode 100644 index 0000000..45ddf54 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.c @@ -0,0 +1,479 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Position and shader input interpolation. + * + * @author Jose Fonseca + */ + +#include "pipe/p_shader_tokens.h" +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "tgsi/tgsi_scan.h" +#include "gallivm/lp_bld_debug.h" +#include "gallivm/lp_bld_const.h" +#include "gallivm/lp_bld_arit.h" +#include "gallivm/lp_bld_swizzle.h" +#include "lp_bld_interp.h" + + +/* + * The shader JIT function operates on blocks of quads. + * Each block has 2x2 quads and each quad has 2x2 pixels. + * + * We iterate over the quads in order 0, 1, 2, 3: + * + * ################# + * # | # | # + * #---0---#---1---# + * # | # | # + * ################# + * # | # | # + * #---2---#---3---# + * # | # | # + * ################# + * + * Within each quad, we have four pixels which are represented in SOA + * order: + * + * ######### + * # 0 | 1 # + * #---+---# + * # 2 | 3 # + * ######### + * + * So the green channel (for example) of the four pixels is stored in + * a single vector register: {g0, g1, g2, g3}. + */ + + +/** + * Do one perspective divide per quad. + * + * For perspective interpolation, the final attribute value is given + * + * a' = a/w = a * oow + * + * where + * + * a = a0 + dadx*x + dady*y + * w = w0 + dwdx*x + dwdy*y + * oow = 1/w = 1/(w0 + dwdx*x + dwdy*y) + * + * Instead of computing the division per pixel, with this macro we compute the + * division on the upper left pixel of each quad, and use a linear + * approximation in the remaining pixels, given by: + * + * da'dx = (dadx - dwdx*a)*oow + * da'dy = (dady - dwdy*a)*oow + * + * Ironically, this actually makes things slower -- probably because the + * divide hardware unit is rarely used, whereas the multiply unit is typically + * already saturated. + */ +#define PERSPECTIVE_DIVIDE_PER_QUAD 0 + + +static const unsigned char quad_offset_x[4] = {0, 1, 0, 1}; +static const unsigned char quad_offset_y[4] = {0, 0, 1, 1}; + + +static void +attrib_name(LLVMValueRef val, unsigned attrib, unsigned chan, const char *suffix) +{ + if(attrib == 0) + lp_build_name(val, "pos.%c%s", "xyzw"[chan], suffix); + else + lp_build_name(val, "input%u.%c%s", attrib - 1, "xyzw"[chan], suffix); +} + + +/** + * Initialize the bld->a0, dadx, dady fields. This involves fetching + * those values from the arrays which are passed into the JIT function. + */ +static void +coeffs_init(struct lp_build_interp_soa_context *bld, + LLVMValueRef a0_ptr, + LLVMValueRef dadx_ptr, + LLVMValueRef dady_ptr) +{ + struct lp_build_context *coeff_bld = &bld->coeff_bld; + struct gallivm_state *gallivm = coeff_bld->gallivm; + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef zero = LLVMConstNull(coeff_bld->elem_type); + LLVMValueRef one = LLVMConstReal(coeff_bld->elem_type, 1.0); + LLVMValueRef i0 = lp_build_const_int32(gallivm, 0); + LLVMValueRef i1 = lp_build_const_int32(gallivm, 1); + LLVMValueRef i2 = lp_build_const_int32(gallivm, 2); + LLVMValueRef i3 = lp_build_const_int32(gallivm, 3); + unsigned attrib; + unsigned chan; + + /* TODO: Use more vector operations */ + + for (attrib = 0; attrib < bld->num_attribs; ++attrib) { + const unsigned mask = bld->mask[attrib]; + const unsigned interp = bld->interp[attrib]; + for (chan = 0; chan < NUM_CHANNELS; ++chan) { + if (mask & (1 << chan)) { + LLVMValueRef index = lp_build_const_int32(gallivm, + attrib * NUM_CHANNELS + chan); + LLVMValueRef a0 = zero; + LLVMValueRef dadx = zero; + LLVMValueRef dady = zero; + LLVMValueRef dadxy = zero; + LLVMValueRef dadq; + LLVMValueRef dadq2; + LLVMValueRef a; + + switch (interp) { + case LP_INTERP_PERSPECTIVE: + /* fall-through */ + + case LP_INTERP_LINEAR: + if (attrib == 0 && chan == 0) { + dadxy = dadx = one; + } + else if (attrib == 0 && chan == 1) { + dadxy = dady = one; + } + else { + dadx = LLVMBuildLoad(builder, LLVMBuildGEP(builder, dadx_ptr, &index, 1, ""), ""); + dady = LLVMBuildLoad(builder, LLVMBuildGEP(builder, dady_ptr, &index, 1, ""), ""); + dadxy = LLVMBuildFAdd(builder, dadx, dady, ""); + attrib_name(dadx, attrib, chan, ".dadx"); + attrib_name(dady, attrib, chan, ".dady"); + attrib_name(dadxy, attrib, chan, ".dadxy"); + } + /* fall-through */ + + case LP_INTERP_CONSTANT: + case LP_INTERP_FACING: + a0 = LLVMBuildLoad(builder, LLVMBuildGEP(builder, a0_ptr, &index, 1, ""), ""); + attrib_name(a0, attrib, chan, ".a0"); + break; + + case LP_INTERP_POSITION: + /* Nothing to do as the position coeffs are already setup in slot 0 */ + continue; + + default: + assert(0); + break; + } + + /* + * dadq = {0, dadx, dady, dadx + dady} + */ + + dadq = coeff_bld->undef; + dadq = LLVMBuildInsertElement(builder, dadq, zero, i0, ""); + dadq = LLVMBuildInsertElement(builder, dadq, dadx, i1, ""); + dadq = LLVMBuildInsertElement(builder, dadq, dady, i2, ""); + dadq = LLVMBuildInsertElement(builder, dadq, dadxy, i3, ""); + + /* + * dadq2 = 2 * dq + */ + + dadq2 = LLVMBuildFAdd(builder, dadq, dadq, ""); + + /* + * a = a0 + (x * dadx + y * dady) + */ + + if (attrib == 0 && chan == 0) { + a = bld->x; + } + else if (attrib == 0 && chan == 1) { + a = bld->y; + } + else { + a = a0; + if (interp != LP_INTERP_CONSTANT && + interp != LP_INTERP_FACING) { + LLVMValueRef ax, ay, axy; + ax = LLVMBuildFMul(builder, bld->x, dadx, ""); + ay = LLVMBuildFMul(builder, bld->y, dady, ""); + axy = LLVMBuildFAdd(builder, ax, ay, ""); + a = LLVMBuildFAdd(builder, a, axy, ""); + } + } + + /* + * a = {a, a, a, a} + */ + + a = lp_build_broadcast(gallivm, coeff_bld->vec_type, a); + + /* + * Compute the attrib values on the upper-left corner of each quad. + */ + + a = LLVMBuildFAdd(builder, a, dadq2, ""); + +#if PERSPECTIVE_DIVIDE_PER_QUAD + /* + * a *= 1 / w + */ + + if (interp == LP_INTERP_PERSPECTIVE) { + LLVMValueRef w = bld->a[0][3]; + assert(attrib != 0); + assert(bld->mask[0] & TGSI_WRITEMASK_W); + if (!bld->oow) { + bld->oow = lp_build_rcp(coeff_bld, w); + lp_build_name(bld->oow, "oow"); + } + a = lp_build_mul(coeff_bld, a, bld->oow); + } +#endif + + attrib_name(a, attrib, chan, ".a"); + attrib_name(dadq, attrib, chan, ".dadq"); + + bld->a [attrib][chan] = a; + bld->dadq[attrib][chan] = dadq; + } + } + } +} + + +/** + * Increment the shader input attribute values. + * This is called when we move from one quad to the next. + */ +static void +attribs_update(struct lp_build_interp_soa_context *bld, + struct gallivm_state *gallivm, + int quad_index, + int start, + int end) +{ + LLVMBuilderRef builder = gallivm->builder; + struct lp_build_context *coeff_bld = &bld->coeff_bld; + LLVMValueRef shuffle = lp_build_const_int_vec(gallivm, coeff_bld->type, quad_index); + LLVMValueRef oow = NULL; + unsigned attrib; + unsigned chan; + + assert(quad_index < 4); + + for(attrib = start; attrib < end; ++attrib) { + const unsigned mask = bld->mask[attrib]; + const unsigned interp = bld->interp[attrib]; + for(chan = 0; chan < NUM_CHANNELS; ++chan) { + if(mask & (1 << chan)) { + LLVMValueRef a; + if (interp == LP_INTERP_CONSTANT || + interp == LP_INTERP_FACING) { + a = bld->a[attrib][chan]; + } + else if (interp == LP_INTERP_POSITION) { + assert(attrib > 0); + a = bld->attribs[0][chan]; + } + else { + LLVMValueRef dadq; + + a = bld->a[attrib][chan]; + + /* + * Broadcast the attribute value for this quad into all elements + */ + + a = LLVMBuildShuffleVector(builder, + a, coeff_bld->undef, shuffle, ""); + + /* + * Get the derivatives. + */ + + dadq = bld->dadq[attrib][chan]; + +#if PERSPECTIVE_DIVIDE_PER_QUAD + if (interp == LP_INTERP_PERSPECTIVE) { + LLVMValueRef dwdq = bld->dadq[0][3]; + + if (oow == NULL) { + assert(bld->oow); + oow = LLVMBuildShuffleVector(coeff_bld->builder, + bld->oow, coeff_bld->undef, + shuffle, ""); + } + + dadq = lp_build_sub(coeff_bld, + dadq, + lp_build_mul(coeff_bld, a, dwdq)); + dadq = lp_build_mul(coeff_bld, dadq, oow); + } +#endif + + /* + * Add the derivatives + */ + + a = lp_build_add(coeff_bld, a, dadq); + +#if !PERSPECTIVE_DIVIDE_PER_QUAD + if (interp == LP_INTERP_PERSPECTIVE) { + if (oow == NULL) { + LLVMValueRef w = bld->attribs[0][3]; + assert(attrib != 0); + assert(bld->mask[0] & TGSI_WRITEMASK_W); + oow = lp_build_rcp(coeff_bld, w); + } + a = lp_build_mul(coeff_bld, a, oow); + } +#endif + + if (attrib == 0 && chan == 2) { + /* FIXME: Depth values can exceed 1.0, due to the fact that + * setup interpolation coefficients refer to (0,0) which causes + * precision loss. So we must clamp to 1.0 here to avoid artifacts + */ + a = lp_build_min(coeff_bld, a, coeff_bld->one); + } + + attrib_name(a, attrib, chan, ""); + } + bld->attribs[attrib][chan] = a; + } + } + } +} + + +/** + * Generate the position vectors. + * + * Parameter x0, y0 are the integer values with upper left coordinates. + */ +static void +pos_init(struct lp_build_interp_soa_context *bld, + LLVMValueRef x0, + LLVMValueRef y0) +{ + LLVMBuilderRef builder = bld->coeff_bld.gallivm->builder; + struct lp_build_context *coeff_bld = &bld->coeff_bld; + + bld->x = LLVMBuildSIToFP(builder, x0, coeff_bld->elem_type, ""); + bld->y = LLVMBuildSIToFP(builder, y0, coeff_bld->elem_type, ""); +} + + +/** + * Initialize fragment shader input attribute info. + */ +void +lp_build_interp_soa_init(struct lp_build_interp_soa_context *bld, + struct gallivm_state *gallivm, + unsigned num_inputs, + const struct lp_shader_input *inputs, + LLVMBuilderRef builder, + struct lp_type type, + LLVMValueRef a0_ptr, + LLVMValueRef dadx_ptr, + LLVMValueRef dady_ptr, + LLVMValueRef x0, + LLVMValueRef y0) +{ + struct lp_type coeff_type; + unsigned attrib; + unsigned chan; + + memset(bld, 0, sizeof *bld); + + memset(&coeff_type, 0, sizeof coeff_type); + coeff_type.floating = TRUE; + coeff_type.sign = TRUE; + coeff_type.width = 32; + coeff_type.length = QUAD_SIZE; + + /* XXX: we don't support interpolating into any other types */ + assert(memcmp(&coeff_type, &type, sizeof coeff_type) == 0); + + lp_build_context_init(&bld->coeff_bld, gallivm, coeff_type); + + /* For convenience */ + bld->pos = bld->attribs[0]; + bld->inputs = (const LLVMValueRef (*)[NUM_CHANNELS]) bld->attribs[1]; + + /* Position */ + bld->num_attribs = 1; + bld->mask[0] = TGSI_WRITEMASK_XYZW; + bld->interp[0] = LP_INTERP_LINEAR; + + /* Inputs */ + for (attrib = 0; attrib < num_inputs; ++attrib) { + bld->mask[1 + attrib] = inputs[attrib].usage_mask; + bld->interp[1 + attrib] = inputs[attrib].interp; + } + bld->num_attribs = 1 + num_inputs; + + /* Ensure all masked out input channels have a valid value */ + for (attrib = 0; attrib < bld->num_attribs; ++attrib) { + for (chan = 0; chan < NUM_CHANNELS; ++chan) { + bld->attribs[attrib][chan] = bld->coeff_bld.undef; + } + } + + pos_init(bld, x0, y0); + + coeffs_init(bld, a0_ptr, dadx_ptr, dady_ptr); +} + + +/** + * Advance the position and inputs to the given quad within the block. + */ +void +lp_build_interp_soa_update_inputs(struct lp_build_interp_soa_context *bld, + struct gallivm_state *gallivm, + int quad_index) +{ + assert(quad_index < 4); + + attribs_update(bld, gallivm, quad_index, 1, bld->num_attribs); +} + +void +lp_build_interp_soa_update_pos(struct lp_build_interp_soa_context *bld, + struct gallivm_state *gallivm, + int quad_index) +{ + assert(quad_index < 4); + + attribs_update(bld, gallivm, quad_index, 0, 1); +} + diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.h b/src/gallium/drivers/llvmpipe/lp_bld_interp.h new file mode 100644 index 0000000..b58b2dc --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.h @@ -0,0 +1,127 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Position and shader input interpolation. + * + * Special attention is given to the interpolation of side by side quads. + * Multiplications are made only for the first quad. Interpolation of + * inputs for posterior quads are done exclusively with additions, and + * perspective divide if necessary. + * + * @author Jose Fonseca + */ + +#ifndef LP_BLD_INTERP_H +#define LP_BLD_INTERP_H + + +#include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_type.h" + +#include "tgsi/tgsi_exec.h" + +/** + * Describes how to compute the interpolation coefficients (a0, dadx, dady) + * from the vertices passed into our triangle/line/point functions by the + * draw module. + * + * Vertices are treated as an array of float[4] values, indexed by + * src_index. + * + * LP_INTERP_COLOR is translated to either LP_INTERP_CONSTANT or + * LINEAR depending on flatshade state. + */ +enum lp_interp { + LP_INTERP_CONSTANT, + LP_INTERP_COLOR, + LP_INTERP_LINEAR, + LP_INTERP_PERSPECTIVE, + LP_INTERP_POSITION, + LP_INTERP_FACING +}; + +struct lp_shader_input { + ushort interp:4; /* enum lp_interp */ + ushort usage_mask:4; /* bitmask of TGSI_WRITEMASK_x flags */ + ushort src_index:8; /* where to find values in incoming vertices */ +}; + + +struct lp_build_interp_soa_context +{ + /* QUAD_SIZE x float */ + struct lp_build_context coeff_bld; + + unsigned num_attribs; + unsigned mask[1 + PIPE_MAX_SHADER_INPUTS]; /**< TGSI_WRITE_MASK_x */ + enum lp_interp interp[1 + PIPE_MAX_SHADER_INPUTS]; + + LLVMValueRef x; + LLVMValueRef y; + + LLVMValueRef a [1 + PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS]; + LLVMValueRef dadq[1 + PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS]; + + LLVMValueRef oow; + + LLVMValueRef attribs[1 + PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS]; + + /* + * Convenience pointers. Callers may access this one. + */ + const LLVMValueRef *pos; + const LLVMValueRef (*inputs)[NUM_CHANNELS]; +}; + + +void +lp_build_interp_soa_init(struct lp_build_interp_soa_context *bld, + struct gallivm_state *gallivm, + unsigned num_inputs, + const struct lp_shader_input *inputs, + LLVMBuilderRef builder, + struct lp_type type, + LLVMValueRef a0_ptr, + LLVMValueRef dadx_ptr, + LLVMValueRef dady_ptr, + LLVMValueRef x, + LLVMValueRef y); + +void +lp_build_interp_soa_update_inputs(struct lp_build_interp_soa_context *bld, + struct gallivm_state *gallivm, + int quad_index); + +void +lp_build_interp_soa_update_pos(struct lp_build_interp_soa_context *bld, + struct gallivm_state *gallivm, + int quad_index); + + +#endif /* LP_BLD_INTERP_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_clear.c b/src/gallium/drivers/llvmpipe/lp_clear.c new file mode 100644 index 0000000..b486b24 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_clear.c @@ -0,0 +1,62 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * 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 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: + * Brian Paul + * Michel Dänzer + */ + + +#include "pipe/p_defines.h" +#include "lp_clear.h" +#include "lp_context.h" +#include "lp_setup.h" +#include "lp_debug.h" + + +/** + * Clear the given buffers to the specified values. + * No masking, no scissor (clear entire buffer). + */ +void +llvmpipe_clear(struct pipe_context *pipe, + unsigned buffers, + const float *rgba, + double depth, + unsigned stencil) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + if (llvmpipe->no_rast) + return; + + if (LP_PERF & PERF_NO_DEPTH) + buffers &= ~PIPE_CLEAR_DEPTHSTENCIL; + + lp_setup_clear( llvmpipe->setup, rgba, depth, stencil, buffers ); +} diff --git a/src/gallium/drivers/llvmpipe/lp_clear.h b/src/gallium/drivers/llvmpipe/lp_clear.h new file mode 100644 index 0000000..6d4ffcc --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_clear.h @@ -0,0 +1,43 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Author: + * Brian Paul + */ + +#ifndef LP_CLEAR_H +#define LP_CLEAR_H + +#include "pipe/p_state.h" +struct pipe_context; + +extern void +llvmpipe_clear(struct pipe_context *pipe, unsigned buffers, const float *rgba, + double depth, unsigned stencil); + + +#endif /* LP_CLEAR_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_context.c b/src/gallium/drivers/llvmpipe/lp_context.c new file mode 100644 index 0000000..2de20d6 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_context.c @@ -0,0 +1,232 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2008 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 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: + * Keith Whitwell + */ + +#include "draw/draw_context.h" +#include "draw/draw_vbuf.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_simple_list.h" +#include "lp_clear.h" +#include "lp_context.h" +#include "lp_flush.h" +#include "lp_perf.h" +#include "lp_state.h" +#include "lp_surface.h" +#include "lp_query.h" +#include "lp_setup.h" + + +DEBUG_GET_ONCE_BOOL_OPTION(lp_no_rast, "LP_NO_RAST", FALSE) + + +/** shared by all contexts */ +unsigned llvmpipe_variant_count; + + +/** + * This function is called by the gallivm "garbage collector" when + * the LLVM global data structures are freed. We must free all LLVM-related + * data. Specifically, all JIT'd shader variants. + */ +static void +garbage_collect_callback(void *cb_data) +{ + struct llvmpipe_context *lp = (struct llvmpipe_context *) cb_data; + struct lp_fs_variant_list_item *li; + + /* Free all the context's shader variants */ + li = first_elem(&lp->fs_variants_list); + while (!at_end(&lp->fs_variants_list, li)) { + struct lp_fs_variant_list_item *next = next_elem(li); + llvmpipe_remove_shader_variant(lp, li->base); + li = next; + } + + /* Free all the context's primitive setup variants */ + lp_delete_setup_variants(lp); + + /* release references to setup variants, shaders */ + lp_setup_set_setup_variant(lp->setup, NULL); + lp_setup_set_fs_variant(lp->setup, NULL); + lp_setup_reset(lp->setup); + + /* This type will be recreated upon demand */ + lp->jit_context_ptr_type = NULL; + + /* mark all state as dirty to ensure new shaders are jit'd, etc. */ + lp->dirty = ~0; +} + + + +static void llvmpipe_destroy( struct pipe_context *pipe ) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe ); + uint i, j; + + lp_print_counters(); + + gallivm_remove_garbage_collector_callback(garbage_collect_callback, + llvmpipe); + + /* This will also destroy llvmpipe->setup: + */ + if (llvmpipe->draw) + draw_destroy( llvmpipe->draw ); + + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + pipe_surface_reference(&llvmpipe->framebuffer.cbufs[i], NULL); + } + + pipe_surface_reference(&llvmpipe->framebuffer.zsbuf, NULL); + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + pipe_sampler_view_reference(&llvmpipe->fragment_sampler_views[i], NULL); + } + + for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { + pipe_sampler_view_reference(&llvmpipe->vertex_sampler_views[i], NULL); + } + + for (i = 0; i < Elements(llvmpipe->constants); i++) { + for (j = 0; j < Elements(llvmpipe->constants[i]); j++) { + pipe_resource_reference(&llvmpipe->constants[i][j], NULL); + } + } + + gallivm_destroy(llvmpipe->gallivm); + + align_free( llvmpipe ); +} + +static void +do_flush( struct pipe_context *pipe, + unsigned flags, + struct pipe_fence_handle **fence) +{ + llvmpipe_flush(pipe, flags, fence, __FUNCTION__); +} + + +struct pipe_context * +llvmpipe_create_context( struct pipe_screen *screen, void *priv ) +{ + struct llvmpipe_context *llvmpipe; + + llvmpipe = align_malloc(sizeof(struct llvmpipe_context), 16); + if (!llvmpipe) + return NULL; + + util_init_math(); + + memset(llvmpipe, 0, sizeof *llvmpipe); + + make_empty_list(&llvmpipe->fs_variants_list); + + make_empty_list(&llvmpipe->setup_variants_list); + + + llvmpipe->pipe.winsys = screen->winsys; + llvmpipe->pipe.screen = screen; + llvmpipe->pipe.priv = priv; + + /* Init the pipe context methods */ + llvmpipe->pipe.destroy = llvmpipe_destroy; + llvmpipe->pipe.set_framebuffer_state = llvmpipe_set_framebuffer_state; + llvmpipe->pipe.clear = llvmpipe_clear; + llvmpipe->pipe.flush = do_flush; + + llvmpipe_init_blend_funcs(llvmpipe); + llvmpipe_init_clip_funcs(llvmpipe); + llvmpipe_init_draw_funcs(llvmpipe); + llvmpipe_init_sampler_funcs(llvmpipe); + llvmpipe_init_query_funcs( llvmpipe ); + llvmpipe_init_vertex_funcs(llvmpipe); + llvmpipe_init_so_funcs(llvmpipe); + llvmpipe_init_fs_funcs(llvmpipe); + llvmpipe_init_vs_funcs(llvmpipe); + llvmpipe_init_gs_funcs(llvmpipe); + llvmpipe_init_rasterizer_funcs(llvmpipe); + llvmpipe_init_context_resource_funcs( &llvmpipe->pipe ); + llvmpipe_init_surface_functions(llvmpipe); + + llvmpipe->gallivm = gallivm_create(); + + /* + * Create drawing context and plug our rendering stage into it. + */ + llvmpipe->draw = draw_create_gallivm(&llvmpipe->pipe, llvmpipe->gallivm); + if (!llvmpipe->draw) + goto fail; + + /* FIXME: devise alternative to draw_texture_samplers */ + + if (debug_get_option_lp_no_rast()) + llvmpipe->no_rast = TRUE; + + llvmpipe->setup = lp_setup_create( &llvmpipe->pipe, + llvmpipe->draw ); + if (!llvmpipe->setup) + goto fail; + + /* plug in AA line/point stages */ + draw_install_aaline_stage(llvmpipe->draw, &llvmpipe->pipe); + draw_install_aapoint_stage(llvmpipe->draw, &llvmpipe->pipe); + draw_install_pstipple_stage(llvmpipe->draw, &llvmpipe->pipe); + + /* convert points and lines into triangles: + * (otherwise, draw points and lines natively) + */ + draw_wide_point_sprites(llvmpipe->draw, FALSE); + draw_enable_point_sprites(llvmpipe->draw, FALSE); + draw_wide_point_threshold(llvmpipe->draw, 10000.0); + draw_wide_line_threshold(llvmpipe->draw, 10000.0); + +#if USE_DRAW_STAGE_PSTIPPLE + /* Do polygon stipple w/ texture map + frag prog? */ + draw_install_pstipple_stage(llvmpipe->draw, &llvmpipe->pipe); +#endif + + lp_reset_counters(); + + gallivm_register_garbage_collector_callback(garbage_collect_callback, + llvmpipe); + + return &llvmpipe->pipe; + + fail: + llvmpipe_destroy(&llvmpipe->pipe); + return NULL; +} + diff --git a/src/gallium/drivers/llvmpipe/lp_context.h b/src/gallium/drivers/llvmpipe/lp_context.h new file mode 100644 index 0000000..503f09d --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_context.h @@ -0,0 +1,161 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef LP_CONTEXT_H +#define LP_CONTEXT_H + +#include "pipe/p_context.h" + +#include "draw/draw_vertex.h" + +#include "lp_tex_sample.h" +#include "lp_jit.h" +#include "lp_setup.h" +#include "lp_state_fs.h" +#include "lp_state_setup.h" + + +struct llvmpipe_vbuf_render; +struct draw_context; +struct draw_stage; +struct lp_fragment_shader; +struct lp_vertex_shader; +struct lp_blend_state; +struct lp_setup_context; +struct lp_setup_variant; +struct lp_velems_state; + +struct llvmpipe_context { + struct pipe_context pipe; /**< base class */ + + /** Constant state objects */ + const struct pipe_blend_state *blend; + const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_state *vertex_samplers[PIPE_MAX_VERTEX_SAMPLERS]; + const struct pipe_depth_stencil_alpha_state *depth_stencil; + const struct pipe_rasterizer_state *rasterizer; + struct lp_fragment_shader *fs; + const struct lp_vertex_shader *vs; + const struct lp_geometry_shader *gs; + const struct lp_velems_state *velems; + const struct lp_so_state *so; + + /** Other rendering state */ + struct pipe_blend_color blend_color; + struct pipe_stencil_ref stencil_ref; + struct pipe_clip_state clip; + struct pipe_resource *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS]; + struct pipe_framebuffer_state framebuffer; + struct pipe_poly_stipple poly_stipple; + struct pipe_scissor_state scissor; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_viewport_state viewport; + struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; + struct pipe_index_buffer index_buffer; + struct { + struct llvmpipe_resource *buffer[PIPE_MAX_SO_BUFFERS]; + int offset[PIPE_MAX_SO_BUFFERS]; + int so_count[PIPE_MAX_SO_BUFFERS]; + int num_buffers; + } so_target; + struct pipe_resource *mapped_vs_tex[PIPE_MAX_VERTEX_SAMPLERS]; + + unsigned num_samplers; + unsigned num_fragment_sampler_views; + unsigned num_vertex_samplers; + unsigned num_vertex_sampler_views; + unsigned num_vertex_buffers; + + unsigned dirty; /**< Mask of LP_NEW_x flags */ + + int active_query_count; + + /** Mapped vertex buffers */ + ubyte *mapped_vbuffer[PIPE_MAX_ATTRIBS]; + + /** Vertex format */ + struct vertex_info vertex_info; + + /** Which vertex shader output slot contains color */ + int color_slot[2]; + + /** Which vertex shader output slot contains bcolor */ + int bcolor_slot[2]; + + /** Which vertex shader output slot contains point size */ + int psize_slot; + + /**< minimum resolvable depth value, for polygon offset */ + double mrd; + + /** The tiling engine */ + struct lp_setup_context *setup; + struct lp_setup_variant setup_variant; + + /** The primitive drawing context */ + struct draw_context *draw; + + unsigned tex_timestamp; + boolean no_rast; + + /** List of all fragment shader variants */ + struct lp_fs_variant_list_item fs_variants_list; + unsigned nr_fs_variants; + + /** JIT code generation */ + struct gallivm_state *gallivm; + LLVMTypeRef jit_context_ptr_type; + + struct lp_setup_variant_list_item setup_variants_list; + unsigned nr_setup_variants; +}; + + +/** + * Fragment and setup variant count, used to trigger garbage collection. + * This is global since all variants in all contexts will be free when + * we do garbage collection. + */ +extern unsigned llvmpipe_variant_count; + + +struct pipe_context * +llvmpipe_create_context( struct pipe_screen *screen, void *priv ); + + +static INLINE struct llvmpipe_context * +llvmpipe_context( struct pipe_context *pipe ) +{ + return (struct llvmpipe_context *)pipe; +} + +#endif /* LP_CONTEXT_H */ + diff --git a/src/gallium/drivers/llvmpipe/lp_debug.h b/src/gallium/drivers/llvmpipe/lp_debug.h new file mode 100644 index 0000000..15dca52 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_debug.h @@ -0,0 +1,90 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef LP_DEBUG_H +#define LP_DEBUG_H + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" + +extern void +st_print_current(void); + + +#define DEBUG_PIPE 0x1 +#define DEBUG_TGSI 0x2 +#define DEBUG_TEX 0x4 +#define DEBUG_SETUP 0x10 +#define DEBUG_RAST 0x20 +#define DEBUG_QUERY 0x40 +#define DEBUG_SCREEN 0x80 +#define DEBUG_SHOW_TILES 0x200 +#define DEBUG_SHOW_SUBTILES 0x400 +#define DEBUG_COUNTERS 0x800 +#define DEBUG_SCENE 0x1000 +#define DEBUG_FENCE 0x2000 +#define DEBUG_MEM 0x4000 +#define DEBUG_FS 0x8000 + +/* Performance flags. These are active even on release builds. + */ +#define PERF_TEX_MEM 0x1 /* minimize texture cache footprint */ +#define PERF_NO_MIP_LINEAR 0x2 /* MIP_FILTER_LINEAR ==> _NEAREST */ +#define PERF_NO_MIPMAPS 0x4 /* MIP_FILTER_NONE always */ +#define PERF_NO_LINEAR 0x8 /* FILTER_NEAREST always */ +#define PERF_NO_TEX 0x10 /* sample white always */ +#define PERF_NO_BLEND 0x20 /* disable blending */ +#define PERF_NO_DEPTH 0x40 /* disable depth buffering entirely */ +#define PERF_NO_ALPHATEST 0x80 /* disable alpha testing */ + + +extern int LP_PERF; + +#ifdef DEBUG +extern int LP_DEBUG; +#else +#define LP_DEBUG 0 +#endif + +void st_debug_init( void ); + +static INLINE void +LP_DBG( unsigned flag, const char *fmt, ... ) +{ + if (LP_DEBUG & flag) + { + va_list args; + + va_start( args, fmt ); + debug_vprintf( fmt, args ); + va_end( args ); + } +} + + +#endif /* LP_DEBUG_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_draw_arrays.c b/src/gallium/drivers/llvmpipe/lp_draw_arrays.c new file mode 100644 index 0000000..3af5c8d --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_draw_arrays.c @@ -0,0 +1,107 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Author: + * Brian Paul + * Keith Whitwell + */ + + +#include "pipe/p_defines.h" +#include "pipe/p_context.h" +#include "util/u_prim.h" + +#include "lp_context.h" +#include "lp_state.h" + +#include "draw/draw_context.h" + + + +/** + * Draw vertex arrays, with optional indexing, optional instancing. + * All the other drawing functions are implemented in terms of this function. + * Basically, map the vertex buffers (and drawing surfaces), then hand off + * the drawing to the 'draw' module. + */ +static void +llvmpipe_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) +{ + struct llvmpipe_context *lp = llvmpipe_context(pipe); + struct draw_context *draw = lp->draw; + void *mapped_indices = NULL; + unsigned i; + + if (lp->dirty) + llvmpipe_update_derived( lp ); + + /* + * Map vertex buffers + */ + for (i = 0; i < lp->num_vertex_buffers; i++) { + void *buf = llvmpipe_resource_data(lp->vertex_buffer[i].buffer); + draw_set_mapped_vertex_buffer(draw, i, buf); + } + + /* Map index buffer, if present */ + if (info->indexed && lp->index_buffer.buffer) + mapped_indices = llvmpipe_resource_data(lp->index_buffer.buffer); + + draw_set_mapped_index_buffer(draw, mapped_indices); + + llvmpipe_prepare_vertex_sampling(lp, + lp->num_vertex_sampler_views, + lp->vertex_sampler_views); + + /* draw! */ + draw_vbo(draw, info); + + /* + * unmap vertex/index buffers + */ + for (i = 0; i < lp->num_vertex_buffers; i++) { + draw_set_mapped_vertex_buffer(draw, i, NULL); + } + if (mapped_indices) { + draw_set_mapped_index_buffer(draw, NULL); + } + llvmpipe_cleanup_vertex_sampling(lp); + + /* + * TODO: Flush only when a user vertex/index buffer is present + * (or even better, modify draw module to do this + * internally when this condition is seen?) + */ + draw_flush(draw); +} + + +void +llvmpipe_init_draw_funcs(struct llvmpipe_context *llvmpipe) +{ + llvmpipe->pipe.draw_vbo = llvmpipe_draw_vbo; +} diff --git a/src/gallium/drivers/llvmpipe/lp_fence.c b/src/gallium/drivers/llvmpipe/lp_fence.c new file mode 100644 index 0000000..3a55e76 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_fence.c @@ -0,0 +1,124 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "pipe/p_screen.h" +#include "util/u_memory.h" +#include "lp_debug.h" +#include "lp_fence.h" + + +/** + * Create a new fence object. + * + * The rank will be the number of bins in the scene. Whenever a rendering + * thread hits a fence command, it'll increment the fence counter. When + * the counter == the rank, the fence is finished. + * + * \param rank the expected finished value of the fence counter. + */ +struct lp_fence * +lp_fence_create(unsigned rank) +{ + static int fence_id; + struct lp_fence *fence = CALLOC_STRUCT(lp_fence); + + pipe_reference_init(&fence->reference, 1); + + pipe_mutex_init(fence->mutex); + pipe_condvar_init(fence->signalled); + + fence->id = fence_id++; + fence->rank = rank; + + if (LP_DEBUG & DEBUG_FENCE) + debug_printf("%s %d\n", __FUNCTION__, fence->id); + + return fence; +} + + +/** Destroy a fence. Called when refcount hits zero. */ +void +lp_fence_destroy(struct lp_fence *fence) +{ + if (LP_DEBUG & DEBUG_FENCE) + debug_printf("%s %d\n", __FUNCTION__, fence->id); + + pipe_mutex_destroy(fence->mutex); + pipe_condvar_destroy(fence->signalled); + FREE(fence); +} + + +/** + * Called by the rendering threads to increment the fence counter. + * When the counter == the rank, the fence is finished. + */ +void +lp_fence_signal(struct lp_fence *fence) +{ + if (LP_DEBUG & DEBUG_FENCE) + debug_printf("%s %d\n", __FUNCTION__, fence->id); + + pipe_mutex_lock(fence->mutex); + + fence->count++; + assert(fence->count <= fence->rank); + + if (LP_DEBUG & DEBUG_FENCE) + debug_printf("%s count=%u rank=%u\n", __FUNCTION__, + fence->count, fence->rank); + + /* Wakeup all threads waiting on the mutex: + */ + pipe_condvar_broadcast(fence->signalled); + + pipe_mutex_unlock(fence->mutex); +} + +boolean +lp_fence_signalled(struct lp_fence *f) +{ + return f->count == f->rank; +} + +void +lp_fence_wait(struct lp_fence *f) +{ + if (LP_DEBUG & DEBUG_FENCE) + debug_printf("%s %d\n", __FUNCTION__, f->id); + + pipe_mutex_lock(f->mutex); + assert(f->issued); + while (f->count < f->rank) { + pipe_condvar_wait(f->signalled, f->mutex); + } + pipe_mutex_unlock(f->mutex); +} + + diff --git a/src/gallium/drivers/llvmpipe/lp_fence.h b/src/gallium/drivers/llvmpipe/lp_fence.h new file mode 100644 index 0000000..3c59118 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_fence.h @@ -0,0 +1,95 @@ +/************************************************************************** + * + * 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 LP_FENCE_H +#define LP_FENCE_H + + +#include "os/os_thread.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" + + +struct pipe_screen; + + +struct lp_fence +{ + struct pipe_reference reference; + unsigned id; + + pipe_mutex mutex; + pipe_condvar signalled; + + boolean issued; + unsigned rank; + unsigned count; +}; + + +struct lp_fence * +lp_fence_create(unsigned rank); + + +void +lp_fence_signal(struct lp_fence *fence); + +boolean +lp_fence_signalled(struct lp_fence *fence); + +void +lp_fence_wait(struct lp_fence *fence); + +void +llvmpipe_init_screen_fence_funcs(struct pipe_screen *screen); + + +void +lp_fence_destroy(struct lp_fence *fence); + +static INLINE void +lp_fence_reference(struct lp_fence **ptr, + struct lp_fence *f) +{ + struct lp_fence *old = *ptr; + + if (pipe_reference(&old->reference, &f->reference)) { + lp_fence_destroy(old); + } + + *ptr = f; +} + +static INLINE boolean +lp_fence_issued(const struct lp_fence *fence) +{ + return fence->issued; +} + + +#endif /* LP_FENCE_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_flush.c b/src/gallium/drivers/llvmpipe/lp_flush.c new file mode 100644 index 0000000..85e3cde --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_flush.c @@ -0,0 +1,144 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Author: + * Keith Whitwell + */ + + +#include "pipe/p_defines.h" +#include "pipe/p_screen.h" +#include "util/u_string.h" +#include "draw/draw_context.h" +#include "lp_flush.h" +#include "lp_context.h" +#include "lp_setup.h" + + +/** + * \param flags bitmask of PIPE_FLUSH_x flags + * \param fence if non-null, returns pointer to a fence which can be waited on + */ +void +llvmpipe_flush( struct pipe_context *pipe, + unsigned flags, + struct pipe_fence_handle **fence, + const char *reason) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + draw_flush(llvmpipe->draw); + + /* ask the setup module to flush */ + lp_setup_flush(llvmpipe->setup, flags, fence, reason); + + + if (llvmpipe_variant_count > 1000) { + /* time to do a garbage collection */ + gallivm_garbage_collect(llvmpipe->gallivm); + llvmpipe_variant_count = 0; + } + + /* Enable to dump BMPs of the color/depth buffers each frame */ + if (0) { + if (flags & PIPE_FLUSH_FRAME) { + static unsigned frame_no = 1; + char filename[256]; + unsigned i; + + for (i = 0; i < llvmpipe->framebuffer.nr_cbufs; i++) { + util_snprintf(filename, sizeof(filename), "cbuf%u_%u", i, frame_no); + debug_dump_surface_bmp(&llvmpipe->pipe, filename, llvmpipe->framebuffer.cbufs[0]); + } + + if (0) { + util_snprintf(filename, sizeof(filename), "zsbuf_%u", frame_no); + debug_dump_surface_bmp(&llvmpipe->pipe, filename, llvmpipe->framebuffer.zsbuf); + } + + ++frame_no; + } + } +} + +void +llvmpipe_finish( struct pipe_context *pipe, + const char *reason ) +{ + struct pipe_fence_handle *fence = NULL; + llvmpipe_flush(pipe, 0, &fence, reason); + if (fence) { + pipe->screen->fence_finish(pipe->screen, fence, 0); + pipe->screen->fence_reference(pipe->screen, &fence, NULL); + } +} + +/** + * Flush context if necessary. + * + * Returns FALSE if it would have block, but do_not_block was set, TRUE + * otherwise. + * + * TODO: move this logic to an auxiliary library? + */ +boolean +llvmpipe_flush_resource(struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + int layer, + unsigned flush_flags, + boolean read_only, + boolean cpu_access, + boolean do_not_block, + const char *reason) +{ + unsigned referenced; + + referenced = pipe->is_resource_referenced(pipe, resource, level, layer); + + if ((referenced & PIPE_REFERENCED_FOR_WRITE) || + ((referenced & PIPE_REFERENCED_FOR_READ) && !read_only)) { + + if (cpu_access) { + /* + * Flush and wait. + */ + if (do_not_block) + return FALSE; + + llvmpipe_finish(pipe, reason); + } else { + /* + * Just flush. + */ + + llvmpipe_flush(pipe, flush_flags, NULL, reason); + } + } + + return TRUE; +} diff --git a/src/gallium/drivers/llvmpipe/lp_flush.h b/src/gallium/drivers/llvmpipe/lp_flush.h new file mode 100644 index 0000000..579d24c --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_flush.h @@ -0,0 +1,58 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef LP_FLUSH_H +#define LP_FLUSH_H + +#include "pipe/p_compiler.h" + +struct pipe_context; +struct pipe_fence_handle; +struct pipe_resource; + +void +llvmpipe_flush(struct pipe_context *pipe, + unsigned flags, + struct pipe_fence_handle **fence, + const char *reason); + +void +llvmpipe_finish( struct pipe_context *pipe, + const char *reason ); + +boolean +llvmpipe_flush_resource(struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + int layer, + unsigned flush_flags, + boolean read_only, + boolean cpu_access, + boolean do_not_block, + const char *reason); + +#endif diff --git a/src/gallium/drivers/llvmpipe/lp_jit.c b/src/gallium/drivers/llvmpipe/lp_jit.c new file mode 100644 index 0000000..a775990 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_jit.c @@ -0,0 +1,188 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * C - JIT interfaces + * + * @author Jose Fonseca + */ + + +#include "util/u_memory.h" +#include "gallivm/lp_bld_init.h" +#include "gallivm/lp_bld_debug.h" +#include "gallivm/lp_bld_intr.h" +#include "lp_context.h" +#include "lp_screen.h" +#include "lp_jit.h" + + +static void +lp_jit_create_types(struct llvmpipe_context *lp) +{ + struct gallivm_state *gallivm = lp->gallivm; + LLVMContextRef lc = gallivm->context; + LLVMTypeRef texture_type; + + /* struct lp_jit_texture */ + { + LLVMTypeRef elem_types[LP_JIT_TEXTURE_NUM_FIELDS]; + + elem_types[LP_JIT_TEXTURE_WIDTH] = + elem_types[LP_JIT_TEXTURE_HEIGHT] = + elem_types[LP_JIT_TEXTURE_DEPTH] = + elem_types[LP_JIT_TEXTURE_LAST_LEVEL] = LLVMInt32TypeInContext(lc); + elem_types[LP_JIT_TEXTURE_ROW_STRIDE] = + elem_types[LP_JIT_TEXTURE_IMG_STRIDE] = + LLVMArrayType(LLVMInt32TypeInContext(lc), LP_MAX_TEXTURE_LEVELS); + elem_types[LP_JIT_TEXTURE_DATA] = + LLVMArrayType(LLVMPointerType(LLVMInt8TypeInContext(lc), 0), + LP_MAX_TEXTURE_LEVELS); + elem_types[LP_JIT_TEXTURE_MIN_LOD] = + elem_types[LP_JIT_TEXTURE_MAX_LOD] = + elem_types[LP_JIT_TEXTURE_LOD_BIAS] = LLVMFloatTypeInContext(lc); + elem_types[LP_JIT_TEXTURE_BORDER_COLOR] = + LLVMArrayType(LLVMFloatTypeInContext(lc), 4); + + texture_type = LLVMStructTypeInContext(lc, elem_types, + Elements(elem_types), 0); + + LLVMInvalidateStructLayout(gallivm->target, texture_type); + + LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, width, + gallivm->target, texture_type, + LP_JIT_TEXTURE_WIDTH); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, height, + gallivm->target, texture_type, + LP_JIT_TEXTURE_HEIGHT); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, depth, + gallivm->target, texture_type, + LP_JIT_TEXTURE_DEPTH); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, last_level, + gallivm->target, texture_type, + LP_JIT_TEXTURE_LAST_LEVEL); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, row_stride, + gallivm->target, texture_type, + LP_JIT_TEXTURE_ROW_STRIDE); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, img_stride, + gallivm->target, texture_type, + LP_JIT_TEXTURE_IMG_STRIDE); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, data, + gallivm->target, texture_type, + LP_JIT_TEXTURE_DATA); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, min_lod, + gallivm->target, texture_type, + LP_JIT_TEXTURE_MIN_LOD); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, max_lod, + gallivm->target, texture_type, + LP_JIT_TEXTURE_MAX_LOD); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, lod_bias, + gallivm->target, texture_type, + LP_JIT_TEXTURE_LOD_BIAS); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, border_color, + gallivm->target, texture_type, + LP_JIT_TEXTURE_BORDER_COLOR); + + LP_CHECK_STRUCT_SIZE(struct lp_jit_texture, + gallivm->target, texture_type); + + LLVMAddTypeName(gallivm->module, "texture", texture_type); + } + + /* struct lp_jit_context */ + { + LLVMTypeRef elem_types[LP_JIT_CTX_COUNT]; + LLVMTypeRef context_type; + + elem_types[LP_JIT_CTX_CONSTANTS] = LLVMPointerType(LLVMFloatTypeInContext(lc), 0); + elem_types[LP_JIT_CTX_ALPHA_REF] = LLVMFloatTypeInContext(lc); + elem_types[LP_JIT_CTX_STENCIL_REF_FRONT] = + elem_types[LP_JIT_CTX_STENCIL_REF_BACK] = LLVMInt32TypeInContext(lc); + elem_types[LP_JIT_CTX_BLEND_COLOR] = LLVMPointerType(LLVMInt8TypeInContext(lc), 0); + elem_types[LP_JIT_CTX_TEXTURES] = LLVMArrayType(texture_type, + PIPE_MAX_SAMPLERS); + + context_type = LLVMStructTypeInContext(lc, elem_types, + Elements(elem_types), 0); + + LLVMInvalidateStructLayout(gallivm->target, context_type); + + LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, constants, + gallivm->target, context_type, + LP_JIT_CTX_CONSTANTS); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, alpha_ref_value, + gallivm->target, context_type, + LP_JIT_CTX_ALPHA_REF); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, stencil_ref_front, + gallivm->target, context_type, + LP_JIT_CTX_STENCIL_REF_FRONT); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, stencil_ref_back, + gallivm->target, context_type, + LP_JIT_CTX_STENCIL_REF_BACK); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, blend_color, + gallivm->target, context_type, + LP_JIT_CTX_BLEND_COLOR); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, textures, + gallivm->target, context_type, + LP_JIT_CTX_TEXTURES); + LP_CHECK_STRUCT_SIZE(struct lp_jit_context, + gallivm->target, context_type); + + LLVMAddTypeName(gallivm->module, "context", context_type); + + lp->jit_context_ptr_type = LLVMPointerType(context_type, 0); + } + + if (gallivm_debug & GALLIVM_DEBUG_IR) { + LLVMDumpModule(gallivm->module); + } +} + + +void +lp_jit_screen_cleanup(struct llvmpipe_screen *screen) +{ + /* nothing */ +} + + +void +lp_jit_screen_init(struct llvmpipe_screen *screen) +{ + lp_build_init(); +} + + +LLVMTypeRef +lp_jit_get_context_type(struct llvmpipe_context *lp) +{ + if (!lp->jit_context_ptr_type) + lp_jit_create_types(lp); + + return lp->jit_context_ptr_type; +} diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h new file mode 100644 index 0000000..a6763dc --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -0,0 +1,169 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * C - JIT interfaces + * + * @author Jose Fonseca + */ + +#ifndef LP_JIT_H +#define LP_JIT_H + + +#include "gallivm/lp_bld_struct.h" + +#include "pipe/p_state.h" +#include "lp_texture.h" + + +struct llvmpipe_screen; + + +struct lp_jit_texture +{ + uint32_t width; + uint32_t height; + uint32_t depth; + uint32_t last_level; + uint32_t row_stride[LP_MAX_TEXTURE_LEVELS]; + uint32_t img_stride[LP_MAX_TEXTURE_LEVELS]; + const void *data[LP_MAX_TEXTURE_LEVELS]; + /* sampler state, actually */ + float min_lod; + float max_lod; + float lod_bias; + float border_color[4]; +}; + + +enum { + LP_JIT_TEXTURE_WIDTH = 0, + LP_JIT_TEXTURE_HEIGHT, + LP_JIT_TEXTURE_DEPTH, + LP_JIT_TEXTURE_LAST_LEVEL, + LP_JIT_TEXTURE_ROW_STRIDE, + LP_JIT_TEXTURE_IMG_STRIDE, + LP_JIT_TEXTURE_DATA, + LP_JIT_TEXTURE_MIN_LOD, + LP_JIT_TEXTURE_MAX_LOD, + LP_JIT_TEXTURE_LOD_BIAS, + LP_JIT_TEXTURE_BORDER_COLOR, + LP_JIT_TEXTURE_NUM_FIELDS /* number of fields above */ +}; + + + +/** + * This structure is passed directly to the generated fragment shader. + * + * It contains the derived state. + * + * Changes here must be reflected in the lp_jit_context_* macros and + * lp_jit_init_types function. Changes to the ordering should be avoided. + * + * Only use types with a clear size and padding here, in particular prefer the + * stdint.h types to the basic integer types. + */ +struct lp_jit_context +{ + const float *constants; + + float alpha_ref_value; + + uint32_t stencil_ref_front, stencil_ref_back; + + /* FIXME: store (also?) in floats */ + uint8_t *blend_color; + + struct lp_jit_texture textures[PIPE_MAX_SAMPLERS]; +}; + + +/** + * These enum values must match the position of the fields in the + * lp_jit_context struct above. + */ +enum { + LP_JIT_CTX_CONSTANTS = 0, + LP_JIT_CTX_ALPHA_REF, + LP_JIT_CTX_STENCIL_REF_FRONT, + LP_JIT_CTX_STENCIL_REF_BACK, + LP_JIT_CTX_BLEND_COLOR, + LP_JIT_CTX_TEXTURES, + LP_JIT_CTX_COUNT +}; + + +#define lp_jit_context_constants(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants") + +#define lp_jit_context_alpha_ref_value(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value") + +#define lp_jit_context_stencil_ref_front_value(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_FRONT, "stencil_ref_front") + +#define lp_jit_context_stencil_ref_back_value(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_BACK, "stencil_ref_back") + +#define lp_jit_context_blend_color(_gallivm, _ptr) \ + lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_BLEND_COLOR, "blend_color") + +#define lp_jit_context_textures(_gallivm, _ptr) \ + lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_TEXTURES, "textures") + + + +typedef void +(*lp_jit_frag_func)(const struct lp_jit_context *context, + uint32_t x, + uint32_t y, + uint32_t facing, + const void *a0, + const void *dadx, + const void *dady, + uint8_t **color, + void *depth, + uint32_t mask, + uint32_t *counter); + + +void +lp_jit_screen_cleanup(struct llvmpipe_screen *screen); + + +void +lp_jit_screen_init(struct llvmpipe_screen *screen); + + +LLVMTypeRef +lp_jit_get_context_type(struct llvmpipe_context *lp); + + +#endif /* LP_JIT_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_limits.h b/src/gallium/drivers/llvmpipe/lp_limits.h new file mode 100644 index 0000000..2538164 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_limits.h @@ -0,0 +1,85 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL THE 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. + * + **************************************************************************/ + +/** + * Implementation limits for LLVMpipe driver. + */ + +#ifndef LP_LIMITS_H +#define LP_LIMITS_H + + +/** + * Tile size (width and height). This needs to be a power of two. + */ +#define TILE_ORDER 6 +#define TILE_SIZE (1 << TILE_ORDER) + + +/** + * Max texture sizes + */ +#define LP_MAX_TEXTURE_2D_LEVELS 13 /* 4K x 4K for now */ +#define LP_MAX_TEXTURE_3D_LEVELS 10 /* 512 x 512 x 512 for now */ + + +/** This must be the larger of LP_MAX_TEXTURE_2D/3D_LEVELS */ +#define LP_MAX_TEXTURE_LEVELS LP_MAX_TEXTURE_2D_LEVELS + + +/** + * Max drawing surface size is the max texture size + */ +#define LP_MAX_HEIGHT (1 << (LP_MAX_TEXTURE_LEVELS - 1)) +#define LP_MAX_WIDTH (1 << (LP_MAX_TEXTURE_LEVELS - 1)) + + +#define LP_MAX_THREADS 8 + + +/** + * Max bytes per scene. This may be replaced by a runtime parameter. + */ +#define LP_MAX_SCENE_SIZE (512 * 1024 * 1024) + +/** + * Max number of shader variants (for all shaders combined, + * per context) that will be kept around. + */ +#define LP_MAX_SHADER_VARIANTS 1024 + +/** + * Max number of setup variants that will be kept around. + * + * These are determined by the combination of the fragment shader + * input signature and a small amount of rasterization state (eg + * flatshading). It is likely that many active fragment shaders will + * share the same setup variant. + */ +#define LP_MAX_SETUP_VARIANTS 64 + +#endif /* LP_LIMITS_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_memory.c b/src/gallium/drivers/llvmpipe/lp_memory.c new file mode 100644 index 0000000..0f55d4a --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_memory.c @@ -0,0 +1,45 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "util/u_debug.h" +#include "lp_limits.h" +#include "lp_memory.h" + +/** + * 32bpp RGBA swizzled tiles. One for for each thread and each + * possible colorbuf. Adds up to quite a bit 8*8*64*64*4 == 1MB. + * Several schemes exist to reduce this, such as scaling back the + * number of threads or using a smaller tilesize when multiple + * colorbuffers are bound. + */ +PIPE_ALIGN_VAR(16) uint8_t lp_swizzled_cbuf[LP_MAX_THREADS][PIPE_MAX_COLOR_BUFS][TILE_SIZE * TILE_SIZE * 4]; + + +/* A single dummy tile used in a couple of out-of-memory situations. + */ +PIPE_ALIGN_VAR(16) uint8_t lp_dummy_tile[TILE_SIZE * TILE_SIZE * 4]; + diff --git a/src/gallium/drivers/llvmpipe/lp_memory.h b/src/gallium/drivers/llvmpipe/lp_memory.h new file mode 100644 index 0000000..f7418f5 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_memory.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 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 LP_MEMORY_H +#define LP_MEMORY_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "lp_limits.h" + +extern PIPE_ALIGN_VAR(16) uint8_t lp_swizzled_cbuf[LP_MAX_THREADS][PIPE_MAX_COLOR_BUFS][TILE_SIZE * TILE_SIZE * 4]; + +extern PIPE_ALIGN_VAR(16) uint8_t lp_dummy_tile[TILE_SIZE * TILE_SIZE * 4]; + +#endif /* LP_MEMORY_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_perf.c b/src/gallium/drivers/llvmpipe/lp_perf.c new file mode 100644 index 0000000..e22532f --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_perf.c @@ -0,0 +1,109 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_debug.h" +#include "lp_debug.h" +#include "lp_perf.h" + + + +struct lp_counters lp_count; + + +void +lp_reset_counters(void) +{ + memset(&lp_count, 0, sizeof(lp_count)); +} + + +void +lp_print_counters(void) +{ + if (LP_DEBUG & DEBUG_COUNTERS) { + unsigned total_64, total_16, total_4; + float p1, p2, p3, p5, p6; + + debug_printf("llvmpipe: nr_triangles: %9u\n", lp_count.nr_tris); + debug_printf("llvmpipe: nr_culled_triangles: %9u\n", lp_count.nr_culled_tris); + + total_64 = (lp_count.nr_empty_64 + + lp_count.nr_fully_covered_64 + + lp_count.nr_partially_covered_64); + + p1 = 100.0 * (float) lp_count.nr_empty_64 / (float) total_64; + p2 = 100.0 * (float) lp_count.nr_fully_covered_64 / (float) total_64; + p3 = 100.0 * (float) lp_count.nr_partially_covered_64 / (float) total_64; + p5 = 100.0 * (float) lp_count.nr_shade_opaque_64 / (float) total_64; + p6 = 100.0 * (float) lp_count.nr_shade_64 / (float) total_64; + + debug_printf("llvmpipe: nr_64x64: %9u\n", total_64); + debug_printf("llvmpipe: nr_fully_covered_64x64: %9u (%3.0f%% of %u)\n", lp_count.nr_fully_covered_64, p2, total_64); + debug_printf("llvmpipe: nr_shade_opaque_64x64: %9u (%3.0f%% of %u)\n", lp_count.nr_shade_opaque_64, p5, total_64); + debug_printf("llvmpipe: nr_pure_shade_opaque: %9u (%3.0f%% of %u)\n", lp_count.nr_pure_shade_opaque_64, 0.0, lp_count.nr_shade_opaque_64); + debug_printf("llvmpipe: nr_shade_64x64: %9u (%3.0f%% of %u)\n", lp_count.nr_shade_64, p6, total_64); + debug_printf("llvmpipe: nr_pure_shade: %9u (%3.0f%% of %u)\n", lp_count.nr_pure_shade_64, 0.0, lp_count.nr_shade_64); + debug_printf("llvmpipe: nr_partially_covered_64x64: %9u (%3.0f%% of %u)\n", lp_count.nr_partially_covered_64, p3, total_64); + debug_printf("llvmpipe: nr_empty_64x64: %9u (%3.0f%% of %u)\n", lp_count.nr_empty_64, p1, total_64); + + total_16 = (lp_count.nr_empty_16 + + lp_count.nr_fully_covered_16 + + lp_count.nr_partially_covered_16); + + p1 = 100.0 * (float) lp_count.nr_empty_16 / (float) total_16; + p2 = 100.0 * (float) lp_count.nr_fully_covered_16 / (float) total_16; + p3 = 100.0 * (float) lp_count.nr_partially_covered_16 / (float) total_16; + + debug_printf("llvmpipe: nr_16x16: %9u\n", total_16); + debug_printf("llvmpipe: nr_fully_covered_16x16: %9u (%3.0f%% of %u)\n", lp_count.nr_fully_covered_16, p2, total_16); + debug_printf("llvmpipe: nr_partially_covered_16x16: %9u (%3.0f%% of %u)\n", lp_count.nr_partially_covered_16, p3, total_16); + debug_printf("llvmpipe: nr_empty_16x16: %9u (%3.0f%% of %u)\n", lp_count.nr_empty_16, p1, total_16); + + total_4 = (lp_count.nr_empty_4 + + lp_count.nr_fully_covered_4 + + lp_count.nr_partially_covered_4); + + p1 = 100.0 * (float) lp_count.nr_empty_4 / (float) total_4; + p2 = 100.0 * (float) lp_count.nr_fully_covered_4 / (float) total_4; + p3 = 100.0 * (float) lp_count.nr_partially_covered_4 / (float) total_4; + + debug_printf("llvmpipe: nr_tri_4x4: %9u\n", total_4); + debug_printf("llvmpipe: nr_fully_covered_4x4: %9u (%3.0f%% of %u)\n", lp_count.nr_fully_covered_4, p2, total_4); + debug_printf("llvmpipe: nr_partially_covered_4x4: %9u (%3.0f%% of %u)\n", lp_count.nr_partially_covered_4, p3, total_4); + debug_printf("llvmpipe: nr_empty_4x4: %9u (%3.0f%% of %u)\n", lp_count.nr_empty_4, p1, total_4); + debug_printf("llvmpipe: nr_non_empty_4x4: %9u (%3.0f%% of %u)\n", lp_count.nr_non_empty_4, p2, total_4); + + debug_printf("llvmpipe: nr_color_tile_clear: %9u\n", lp_count.nr_color_tile_clear); + debug_printf("llvmpipe: nr_color_tile_load: %9u\n", lp_count.nr_color_tile_load); + debug_printf("llvmpipe: nr_color_tile_store: %9u\n", lp_count.nr_color_tile_store); + + debug_printf("llvmpipe: nr_llvm_compiles: %u\n", lp_count.nr_llvm_compiles); + debug_printf("llvmpipe: total LLVM compile time: %.2f sec\n", lp_count.llvm_compile_time / 1000000.0); + debug_printf("llvmpipe: average LLVM compile time: %.2f sec\n", lp_count.llvm_compile_time / 1000000.0 / lp_count.nr_llvm_compiles); + + } +} diff --git a/src/gallium/drivers/llvmpipe/lp_perf.h b/src/gallium/drivers/llvmpipe/lp_perf.h new file mode 100644 index 0000000..b23a100 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_perf.h @@ -0,0 +1,90 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * Performance / statistic counters, etc. + */ + + +#ifndef LP_PERF_H +#define LP_PERF_H + + +/** + * Various counters + */ +struct lp_counters +{ + unsigned nr_tris; + unsigned nr_culled_tris; + unsigned nr_empty_64; + unsigned nr_fully_covered_64; + unsigned nr_partially_covered_64; + unsigned nr_pure_shade_opaque_64; + unsigned nr_pure_shade_64; + unsigned nr_shade_64; + unsigned nr_shade_opaque_64; + unsigned nr_empty_16; + unsigned nr_fully_covered_16; + unsigned nr_partially_covered_16; + unsigned nr_empty_4; + unsigned nr_fully_covered_4; + unsigned nr_partially_covered_4; + unsigned nr_non_empty_4; + unsigned nr_llvm_compiles; + int64_t llvm_compile_time; /**< total, in microseconds */ + + unsigned nr_color_tile_clear; + unsigned nr_color_tile_load; + unsigned nr_color_tile_store; +}; + + +extern struct lp_counters lp_count; + + +/** Increment the named counter (only for debug builds) */ +#ifdef DEBUG +#define LP_COUNT(counter) lp_count.counter++ +#define LP_COUNT_ADD(counter, incr) lp_count.counter += (incr) +#define LP_COUNT_GET(counter) (lp_count.counter) +#else +#define LP_COUNT(counter) +#define LP_COUNT_ADD(counter, incr) (void)(incr) +#define LP_COUNT_GET(counter) 0 +#endif + + +extern void +lp_reset_counters(void); + + +extern void +lp_print_counters(void); + + +#endif /* LP_PERF_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_public.h b/src/gallium/drivers/llvmpipe/lp_public.h new file mode 100644 index 0000000..ec6b660 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_public.h @@ -0,0 +1,10 @@ +#ifndef LP_PUBLIC_H +#define LP_PUBLIC_H + +struct pipe_screen; +struct sw_winsys; + +struct pipe_screen * +llvmpipe_create_screen(struct sw_winsys *winsys); + +#endif diff --git a/src/gallium/drivers/llvmpipe/lp_query.c b/src/gallium/drivers/llvmpipe/lp_query.c new file mode 100644 index 0000000..84c66dd --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_query.c @@ -0,0 +1,167 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL THE 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. + * + **************************************************************************/ + +/* Authors: + * Keith Whitwell, Qicheng Christopher Li, Brian Paul + */ + +#include "draw/draw_context.h" +#include "pipe/p_defines.h" +#include "util/u_memory.h" +#include "lp_context.h" +#include "lp_flush.h" +#include "lp_fence.h" +#include "lp_query.h" +#include "lp_state.h" + + +static struct llvmpipe_query *llvmpipe_query( struct pipe_query *p ) +{ + return (struct llvmpipe_query *)p; +} + +static struct pipe_query * +llvmpipe_create_query(struct pipe_context *pipe, + unsigned type) +{ + struct llvmpipe_query *pq; + + assert(type == PIPE_QUERY_OCCLUSION_COUNTER); + + pq = CALLOC_STRUCT( llvmpipe_query ); + + return (struct pipe_query *) pq; +} + + +static void +llvmpipe_destroy_query(struct pipe_context *pipe, struct pipe_query *q) +{ + struct llvmpipe_query *pq = llvmpipe_query(q); + + /* Ideally we would refcount queries & not get destroyed until the + * last scene had finished with us. + */ + if (pq->fence) { + if (!lp_fence_issued(pq->fence)) + llvmpipe_flush(pipe, 0, NULL, __FUNCTION__); + + if (!lp_fence_signalled(pq->fence)) + lp_fence_wait(pq->fence); + + lp_fence_reference(&pq->fence, NULL); + } + + FREE(pq); +} + + +static boolean +llvmpipe_get_query_result(struct pipe_context *pipe, + struct pipe_query *q, + boolean wait, + void *vresult) +{ + struct llvmpipe_query *pq = llvmpipe_query(q); + uint64_t *result = (uint64_t *)vresult; + int i; + + if (!pq->fence) { + /* no fence because there was no scene, so results is zero */ + *result = 0; + return TRUE; + } + + if (!lp_fence_signalled(pq->fence)) { + if (!lp_fence_issued(pq->fence)) + llvmpipe_flush(pipe, 0, NULL, __FUNCTION__); + + if (!wait) + return FALSE; + + lp_fence_wait(pq->fence); + } + + /* Sum the results from each of the threads: + */ + *result = 0; + for (i = 0; i < LP_MAX_THREADS; i++) { + *result += pq->count[i]; + } + + return TRUE; +} + + +static void +llvmpipe_begin_query(struct pipe_context *pipe, struct pipe_query *q) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe ); + struct llvmpipe_query *pq = llvmpipe_query(q); + + /* Check if the query is already in the scene. If so, we need to + * flush the scene now. Real apps shouldn't re-use a query in a + * frame of rendering. + */ + if (pq->fence && !lp_fence_issued(pq->fence)) { + llvmpipe_finish(pipe, __FUNCTION__); + } + + + memset(pq->count, 0, sizeof(pq->count)); + lp_setup_begin_query(llvmpipe->setup, pq); + + llvmpipe->active_query_count++; + llvmpipe->dirty |= LP_NEW_QUERY; +} + + +static void +llvmpipe_end_query(struct pipe_context *pipe, struct pipe_query *q) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe ); + struct llvmpipe_query *pq = llvmpipe_query(q); + + lp_setup_end_query(llvmpipe->setup, pq); + + assert(llvmpipe->active_query_count); + llvmpipe->active_query_count--; + llvmpipe->dirty |= LP_NEW_QUERY; +} + + +void llvmpipe_init_query_funcs(struct llvmpipe_context *llvmpipe ) +{ + llvmpipe->pipe.create_query = llvmpipe_create_query; + llvmpipe->pipe.destroy_query = llvmpipe_destroy_query; + llvmpipe->pipe.begin_query = llvmpipe_begin_query; + llvmpipe->pipe.end_query = llvmpipe_end_query; + llvmpipe->pipe.get_query_result = llvmpipe_get_query_result; +} + + diff --git a/src/gallium/drivers/llvmpipe/lp_query.h b/src/gallium/drivers/llvmpipe/lp_query.h new file mode 100644 index 0000000..e93842a --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_query.h @@ -0,0 +1,53 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL 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. + * + **************************************************************************/ + +/* Authors: + * Keith Whitwell, Qicheng Christopher Li, Brian Paul + */ + +#ifndef LP_QUERY_H +#define LP_QUERY_H + +#include +#include "os/os_thread.h" +#include "lp_limits.h" + + +struct llvmpipe_context; + + +struct llvmpipe_query { + uint64_t count[LP_MAX_THREADS]; /**< a counter for each thread */ + struct lp_fence *fence; /* fence from last scene this was binned in */ +}; + + +extern void llvmpipe_init_query_funcs(struct llvmpipe_context * ); + + +#endif /* LP_QUERY_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c new file mode 100644 index 0000000..dafadc1 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_rast.c @@ -0,0 +1,936 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_rect.h" +#include "util/u_surface.h" +#include "util/u_pack_color.h" + +#include "lp_scene_queue.h" +#include "lp_debug.h" +#include "lp_fence.h" +#include "lp_perf.h" +#include "lp_query.h" +#include "lp_rast.h" +#include "lp_rast_priv.h" +#include "lp_tile_soa.h" +#include "gallivm/lp_bld_debug.h" +#include "lp_scene.h" + + +#ifdef DEBUG +int jit_line = 0; +const struct lp_rast_state *jit_state = NULL; +const struct lp_rasterizer_task *jit_task = NULL; +#endif + + +/** + * Begin rasterizing a scene. + * Called once per scene by one thread. + */ +static void +lp_rast_begin( struct lp_rasterizer *rast, + struct lp_scene *scene ) +{ + + rast->curr_scene = scene; + + LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__); + + lp_scene_begin_rasterization( scene ); + lp_scene_bin_iter_begin( scene ); +} + + +static void +lp_rast_end( struct lp_rasterizer *rast ) +{ + lp_scene_end_rasterization( rast->curr_scene ); + + rast->curr_scene = NULL; + +#ifdef DEBUG + if (0) + debug_printf("Post render scene: tile unswizzle: %u tile swizzle: %u\n", + lp_tile_unswizzle_count, lp_tile_swizzle_count); +#endif +} + + +/** + * Begining rasterization of a tile. + * \param x window X position of the tile, in pixels + * \param y window Y position of the tile, in pixels + */ +static void +lp_rast_tile_begin(struct lp_rasterizer_task *task, + const struct cmd_bin *bin) +{ + const struct lp_scene *scene = task->scene; + enum lp_texture_usage usage; + + LP_DBG(DEBUG_RAST, "%s %d,%d\n", __FUNCTION__, bin->x, bin->y); + + task->bin = bin; + task->x = bin->x * TILE_SIZE; + task->y = bin->y * TILE_SIZE; + + /* reset pointers to color tile(s) */ + memset(task->color_tiles, 0, sizeof(task->color_tiles)); + + /* get pointer to depth/stencil tile */ + { + struct pipe_surface *zsbuf = task->scene->fb.zsbuf; + if (zsbuf) { + struct llvmpipe_resource *lpt = llvmpipe_resource(zsbuf->texture); + + if (scene->has_depthstencil_clear) + usage = LP_TEX_USAGE_WRITE_ALL; + else + usage = LP_TEX_USAGE_READ_WRITE; + + /* "prime" the tile: convert data from linear to tiled if necessary + * and update the tile's layout info. + */ + (void) llvmpipe_get_texture_tile(lpt, + zsbuf->u.tex.first_layer, + zsbuf->u.tex.level, + usage, + task->x, + task->y); + /* Get actual pointer to the tile data. Note that depth/stencil + * data is tiled differently than color data. + */ + task->depth_tile = lp_rast_get_depth_block_pointer(task, + task->x, + task->y); + + assert(task->depth_tile); + } + else { + task->depth_tile = NULL; + } + } +} + + +/** + * Clear the rasterizer's current color tile. + * This is a bin command called during bin processing. + */ +static void +lp_rast_clear_color(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + const struct lp_scene *scene = task->scene; + const uint8_t *clear_color = arg.clear_color; + + unsigned i; + + LP_DBG(DEBUG_RAST, "%s 0x%x,0x%x,0x%x,0x%x\n", __FUNCTION__, + clear_color[0], + clear_color[1], + clear_color[2], + clear_color[3]); + + if (clear_color[0] == clear_color[1] && + clear_color[1] == clear_color[2] && + clear_color[2] == clear_color[3]) { + /* clear to grayscale value {x, x, x, x} */ + for (i = 0; i < scene->fb.nr_cbufs; i++) { + uint8_t *ptr = + lp_rast_get_color_tile_pointer(task, i, LP_TEX_USAGE_WRITE_ALL); + memset(ptr, clear_color[0], TILE_SIZE * TILE_SIZE * 4); + } + } + else { + /* Non-gray color. + * Note: if the swizzled tile layout changes (see TILE_PIXEL) this code + * will need to change. It'll be pretty obvious when clearing no longer + * works. + */ + const unsigned chunk = TILE_SIZE / 4; + for (i = 0; i < scene->fb.nr_cbufs; i++) { + uint8_t *c = + lp_rast_get_color_tile_pointer(task, i, LP_TEX_USAGE_WRITE_ALL); + unsigned j; + + for (j = 0; j < 4 * TILE_SIZE; j++) { + memset(c, clear_color[0], chunk); + c += chunk; + memset(c, clear_color[1], chunk); + c += chunk; + memset(c, clear_color[2], chunk); + c += chunk; + memset(c, clear_color[3], chunk); + c += chunk; + } + } + } + + LP_COUNT(nr_color_tile_clear); +} + + + + + + +/** + * Clear the rasterizer's current z/stencil tile. + * This is a bin command called during bin processing. + */ +static void +lp_rast_clear_zstencil(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + const struct lp_scene *scene = task->scene; + uint32_t clear_value = arg.clear_zstencil.value; + uint32_t clear_mask = arg.clear_zstencil.mask; + const unsigned height = TILE_SIZE / TILE_VECTOR_HEIGHT; + const unsigned width = TILE_SIZE * TILE_VECTOR_HEIGHT; + const unsigned block_size = scene->zsbuf.blocksize; + const unsigned dst_stride = scene->zsbuf.stride * TILE_VECTOR_HEIGHT; + uint8_t *dst; + unsigned i, j; + + LP_DBG(DEBUG_RAST, "%s: value=0x%08x, mask=0x%08x\n", + __FUNCTION__, clear_value, clear_mask); + + /* + * Clear the aera of the swizzled depth/depth buffer matching this tile, in + * stripes of TILE_VECTOR_HEIGHT x TILE_SIZE at a time. + * + * The swizzled depth format is such that the depths for + * TILE_VECTOR_HEIGHT x TILE_VECTOR_WIDTH pixels have consecutive offsets. + */ + + dst = task->depth_tile; + + clear_value &= clear_mask; + + switch (block_size) { + case 1: + assert(clear_mask == 0xff); + memset(dst, (uint8_t) clear_value, height * width); + break; + case 2: + if (clear_mask == 0xffff) { + for (i = 0; i < height; i++) { + uint16_t *row = (uint16_t *)dst; + for (j = 0; j < width; j++) + *row++ = (uint16_t) clear_value; + dst += dst_stride; + } + } + else { + for (i = 0; i < height; i++) { + uint16_t *row = (uint16_t *)dst; + for (j = 0; j < width; j++) { + uint16_t tmp = ~clear_mask & *row; + *row++ = clear_value | tmp; + } + dst += dst_stride; + } + } + break; + case 4: + if (clear_mask == 0xffffffff) { + for (i = 0; i < height; i++) { + uint32_t *row = (uint32_t *)dst; + for (j = 0; j < width; j++) + *row++ = clear_value; + dst += dst_stride; + } + } + else { + for (i = 0; i < height; i++) { + uint32_t *row = (uint32_t *)dst; + for (j = 0; j < width; j++) { + uint32_t tmp = ~clear_mask & *row; + *row++ = clear_value | tmp; + } + dst += dst_stride; + } + } + break; + default: + assert(0); + break; + } +} + + + +/** + * Convert the color tile from tiled to linear layout. + * This is generally only done when we're flushing the scene just prior to + * SwapBuffers. If we didn't do this here, we'd have to convert the entire + * tiled color buffer to linear layout in the llvmpipe_texture_unmap() + * function. It's better to do it here to take advantage of + * threading/parallelism. + * This is a bin command which is stored in all bins. + */ +static void +lp_rast_store_linear_color( struct lp_rasterizer_task *task ) +{ + const struct lp_scene *scene = task->scene; + unsigned buf; + + for (buf = 0; buf < scene->fb.nr_cbufs; buf++) { + struct pipe_surface *cbuf = scene->fb.cbufs[buf]; + const unsigned layer = cbuf->u.tex.first_layer; + const unsigned level = cbuf->u.tex.level; + struct llvmpipe_resource *lpt = llvmpipe_resource(cbuf->texture); + + if (!task->color_tiles[buf]) + continue; + + llvmpipe_unswizzle_cbuf_tile(lpt, + layer, + level, + task->x, task->y, + task->color_tiles[buf]); + } +} + + + +/** + * Run the shader on all blocks in a tile. This is used when a tile is + * completely contained inside a triangle. + * This is a bin command called during bin processing. + */ +static void +lp_rast_shade_tile(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + const struct lp_scene *scene = task->scene; + const struct lp_rast_shader_inputs *inputs = arg.shade_tile; + const struct lp_rast_state *state = task->state; + struct lp_fragment_shader_variant *variant = state->variant; + const unsigned tile_x = task->x, tile_y = task->y; + unsigned x, y; + + if (inputs->disable) { + /* This command was partially binned and has been disabled */ + return; + } + + LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__); + + /* render the whole 64x64 tile in 4x4 chunks */ + for (y = 0; y < TILE_SIZE; y += 4){ + for (x = 0; x < TILE_SIZE; x += 4) { + uint8_t *color[PIPE_MAX_COLOR_BUFS]; + uint32_t *depth; + unsigned i; + + /* color buffer */ + for (i = 0; i < scene->fb.nr_cbufs; i++) + color[i] = lp_rast_get_color_block_pointer(task, i, + tile_x + x, tile_y + y); + + /* depth buffer */ + depth = lp_rast_get_depth_block_pointer(task, tile_x + x, tile_y + y); + + /* run shader on 4x4 block */ + BEGIN_JIT_CALL(state, task); + variant->jit_function[RAST_WHOLE]( &state->jit_context, + tile_x + x, tile_y + y, + inputs->frontfacing, + GET_A0(inputs), + GET_DADX(inputs), + GET_DADY(inputs), + color, + depth, + 0xffff, + &task->vis_counter); + END_JIT_CALL(); + } + } +} + + +/** + * Run the shader on all blocks in a tile. This is used when a tile is + * completely contained inside a triangle, and the shader is opaque. + * This is a bin command called during bin processing. + */ +static void +lp_rast_shade_tile_opaque(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + const struct lp_scene *scene = task->scene; + unsigned i; + + LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__); + + /* this will prevent converting the layout from tiled to linear */ + for (i = 0; i < scene->fb.nr_cbufs; i++) { + (void)lp_rast_get_color_tile_pointer(task, i, LP_TEX_USAGE_WRITE_ALL); + } + + lp_rast_shade_tile(task, arg); +} + + +/** + * Compute shading for a 4x4 block of pixels inside a triangle. + * This is a bin command called during bin processing. + * \param x X position of quad in window coords + * \param y Y position of quad in window coords + */ +void +lp_rast_shade_quads_mask(struct lp_rasterizer_task *task, + const struct lp_rast_shader_inputs *inputs, + unsigned x, unsigned y, + unsigned mask) +{ + const struct lp_rast_state *state = task->state; + struct lp_fragment_shader_variant *variant = state->variant; + const struct lp_scene *scene = task->scene; + uint8_t *color[PIPE_MAX_COLOR_BUFS]; + void *depth; + unsigned i; + + assert(state); + + /* Sanity checks */ + assert(x % TILE_VECTOR_WIDTH == 0); + assert(y % TILE_VECTOR_HEIGHT == 0); + + assert((x % 4) == 0); + assert((y % 4) == 0); + + /* color buffer */ + for (i = 0; i < scene->fb.nr_cbufs; i++) { + color[i] = lp_rast_get_color_block_pointer(task, i, x, y); + assert(lp_check_alignment(color[i], 16)); + } + + /* depth buffer */ + depth = lp_rast_get_depth_block_pointer(task, x, y); + + + assert(lp_check_alignment(state->jit_context.blend_color, 16)); + + /* run shader on 4x4 block */ + BEGIN_JIT_CALL(state, task); + variant->jit_function[RAST_EDGE_TEST](&state->jit_context, + x, y, + inputs->frontfacing, + GET_A0(inputs), + GET_DADX(inputs), + GET_DADY(inputs), + color, + depth, + mask, + &task->vis_counter); + END_JIT_CALL(); +} + + + +/** + * Begin a new occlusion query. + * This is a bin command put in all bins. + * Called per thread. + */ +static void +lp_rast_begin_query(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + struct llvmpipe_query *pq = arg.query_obj; + + assert(task->query == NULL); + task->vis_counter = 0; + task->query = pq; +} + + +/** + * End the current occlusion query. + * This is a bin command put in all bins. + * Called per thread. + */ +static void +lp_rast_end_query(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + assert(task->query); + if (task->query) { + task->query->count[task->thread_index] += task->vis_counter; + task->query = NULL; + } +} + + +void +lp_rast_set_state(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + task->state = arg.state; +} + + + +/** + * Set top row and left column of the tile's pixels to white. For debugging. + */ +static void +outline_tile(uint8_t *tile) +{ + const uint8_t val = 0xff; + unsigned i; + + for (i = 0; i < TILE_SIZE; i++) { + TILE_PIXEL(tile, i, 0, 0) = val; + TILE_PIXEL(tile, i, 0, 1) = val; + TILE_PIXEL(tile, i, 0, 2) = val; + TILE_PIXEL(tile, i, 0, 3) = val; + + TILE_PIXEL(tile, 0, i, 0) = val; + TILE_PIXEL(tile, 0, i, 1) = val; + TILE_PIXEL(tile, 0, i, 2) = val; + TILE_PIXEL(tile, 0, i, 3) = val; + } +} + + +/** + * Draw grid of gray lines at 16-pixel intervals across the tile to + * show the sub-tile boundaries. For debugging. + */ +static void +outline_subtiles(uint8_t *tile) +{ + const uint8_t val = 0x80; + const unsigned step = 16; + unsigned i, j; + + for (i = 0; i < TILE_SIZE; i += step) { + for (j = 0; j < TILE_SIZE; j++) { + TILE_PIXEL(tile, i, j, 0) = val; + TILE_PIXEL(tile, i, j, 1) = val; + TILE_PIXEL(tile, i, j, 2) = val; + TILE_PIXEL(tile, i, j, 3) = val; + + TILE_PIXEL(tile, j, i, 0) = val; + TILE_PIXEL(tile, j, i, 1) = val; + TILE_PIXEL(tile, j, i, 2) = val; + TILE_PIXEL(tile, j, i, 3) = val; + } + } + + outline_tile(tile); +} + + + +/** + * Called when we're done writing to a color tile. + */ +static void +lp_rast_tile_end(struct lp_rasterizer_task *task) +{ +#ifdef DEBUG + if (LP_DEBUG & (DEBUG_SHOW_SUBTILES | DEBUG_SHOW_TILES)) { + const struct lp_scene *scene = task->scene; + unsigned buf; + + for (buf = 0; buf < scene->fb.nr_cbufs; buf++) { + uint8_t *color = lp_rast_get_color_block_pointer(task, buf, + task->x, task->y); + + if (LP_DEBUG & DEBUG_SHOW_SUBTILES) + outline_subtiles(color); + else if (LP_DEBUG & DEBUG_SHOW_TILES) + outline_tile(color); + } + } +#else + (void) outline_subtiles; +#endif + + lp_rast_store_linear_color(task); + + if (task->query) { + union lp_rast_cmd_arg dummy = {0}; + lp_rast_end_query(task, dummy); + } + + /* debug */ + memset(task->color_tiles, 0, sizeof(task->color_tiles)); + task->depth_tile = NULL; + + task->bin = NULL; +} + +static lp_rast_cmd_func dispatch[LP_RAST_OP_MAX] = +{ + lp_rast_clear_color, + lp_rast_clear_zstencil, + lp_rast_triangle_1, + lp_rast_triangle_2, + lp_rast_triangle_3, + lp_rast_triangle_4, + lp_rast_triangle_5, + lp_rast_triangle_6, + lp_rast_triangle_7, + lp_rast_triangle_8, + lp_rast_triangle_3_4, + lp_rast_triangle_3_16, + lp_rast_triangle_4_16, + lp_rast_shade_tile, + lp_rast_shade_tile_opaque, + lp_rast_begin_query, + lp_rast_end_query, + lp_rast_set_state, +}; + + +static void +do_rasterize_bin(struct lp_rasterizer_task *task, + const struct cmd_bin *bin) +{ + const struct cmd_block *block; + unsigned k; + + if (0) + lp_debug_bin(bin); + + for (block = bin->head; block; block = block->next) { + for (k = 0; k < block->count; k++) { + dispatch[block->cmd[k]]( task, block->arg[k] ); + } + } +} + + + +/** + * Rasterize commands for a single bin. + * \param x, y position of the bin's tile in the framebuffer + * Must be called between lp_rast_begin() and lp_rast_end(). + * Called per thread. + */ +static void +rasterize_bin(struct lp_rasterizer_task *task, + const struct cmd_bin *bin ) +{ + lp_rast_tile_begin( task, bin ); + + do_rasterize_bin(task, bin); + + lp_rast_tile_end(task); + + + /* Debug/Perf flags: + */ + if (bin->head->count == 1) { + if (bin->head->cmd[0] == LP_RAST_OP_SHADE_TILE_OPAQUE) + LP_COUNT(nr_pure_shade_opaque_64); + else if (bin->head->cmd[0] == LP_RAST_OP_SHADE_TILE) + LP_COUNT(nr_pure_shade_64); + } +} + + +/* An empty bin is one that just loads the contents of the tile and + * stores them again unchanged. This typically happens when bins have + * been flushed for some reason in the middle of a frame, or when + * incremental updates are being made to a render target. + * + * Try to avoid doing pointless work in this case. + */ +static boolean +is_empty_bin( const struct cmd_bin *bin ) +{ + return bin->head == NULL; +} + + +/** + * Rasterize/execute all bins within a scene. + * Called per thread. + */ +static void +rasterize_scene(struct lp_rasterizer_task *task, + struct lp_scene *scene) +{ + task->scene = scene; + /* loop over scene bins, rasterize each */ +#if 0 + { + unsigned i, j; + for (i = 0; i < scene->tiles_x; i++) { + for (j = 0; j < scene->tiles_y; j++) { + struct cmd_bin *bin = lp_scene_get_bin(scene, i, j); + rasterize_bin(task, bin, i, j); + } + } + } +#else + { + struct cmd_bin *bin; + + assert(scene); + while ((bin = lp_scene_bin_iter_next(scene))) { + if (!is_empty_bin( bin )) + rasterize_bin(task, bin); + } + } +#endif + + if (scene->fence) { + lp_fence_signal(scene->fence); + } + + task->scene = NULL; +} + + +/** + * Called by setup module when it has something for us to render. + */ +void +lp_rast_queue_scene( struct lp_rasterizer *rast, + struct lp_scene *scene) +{ + LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); + + if (rast->num_threads == 0) { + /* no threading */ + + lp_rast_begin( rast, scene ); + + rasterize_scene( &rast->tasks[0], scene ); + + lp_rast_end( rast ); + + rast->curr_scene = NULL; + } + else { + /* threaded rendering! */ + unsigned i; + + lp_scene_enqueue( rast->full_scenes, scene ); + + /* signal the threads that there's work to do */ + for (i = 0; i < rast->num_threads; i++) { + pipe_semaphore_signal(&rast->tasks[i].work_ready); + } + } + + LP_DBG(DEBUG_SETUP, "%s done \n", __FUNCTION__); +} + + +void +lp_rast_finish( struct lp_rasterizer *rast ) +{ + if (rast->num_threads == 0) { + /* nothing to do */ + } + else { + int i; + + /* wait for work to complete */ + for (i = 0; i < rast->num_threads; i++) { + pipe_semaphore_wait(&rast->tasks[i].work_done); + } + } +} + + +/** + * This is the thread's main entrypoint. + * It's a simple loop: + * 1. wait for work + * 2. do work + * 3. signal that we're done + */ +static PIPE_THREAD_ROUTINE( thread_func, init_data ) +{ + struct lp_rasterizer_task *task = (struct lp_rasterizer_task *) init_data; + struct lp_rasterizer *rast = task->rast; + boolean debug = false; + + while (1) { + /* wait for work */ + if (debug) + debug_printf("thread %d waiting for work\n", task->thread_index); + pipe_semaphore_wait(&task->work_ready); + + if (rast->exit_flag) + break; + + if (task->thread_index == 0) { + /* thread[0]: + * - get next scene to rasterize + * - map the framebuffer surfaces + */ + lp_rast_begin( rast, + lp_scene_dequeue( rast->full_scenes, TRUE ) ); + } + + /* Wait for all threads to get here so that threads[1+] don't + * get a null rast->curr_scene pointer. + */ + pipe_barrier_wait( &rast->barrier ); + + /* do work */ + if (debug) + debug_printf("thread %d doing work\n", task->thread_index); + + rasterize_scene(task, + rast->curr_scene); + + /* wait for all threads to finish with this scene */ + pipe_barrier_wait( &rast->barrier ); + + /* XXX: shouldn't be necessary: + */ + if (task->thread_index == 0) { + lp_rast_end( rast ); + } + + /* signal done with work */ + if (debug) + debug_printf("thread %d done working\n", task->thread_index); + + pipe_semaphore_signal(&task->work_done); + } + + return NULL; +} + + +/** + * Initialize semaphores and spawn the threads. + */ +static void +create_rast_threads(struct lp_rasterizer *rast) +{ + unsigned i; + + /* NOTE: if num_threads is zero, we won't use any threads */ + for (i = 0; i < rast->num_threads; i++) { + pipe_semaphore_init(&rast->tasks[i].work_ready, 0); + pipe_semaphore_init(&rast->tasks[i].work_done, 0); + rast->threads[i] = pipe_thread_create(thread_func, + (void *) &rast->tasks[i]); + } +} + + + +/** + * Create new lp_rasterizer. If num_threads is zero, don't create any + * new threads, do rendering synchronously. + * \param num_threads number of rasterizer threads to create + */ +struct lp_rasterizer * +lp_rast_create( unsigned num_threads ) +{ + struct lp_rasterizer *rast; + unsigned i; + + rast = CALLOC_STRUCT(lp_rasterizer); + if(!rast) + return NULL; + + rast->full_scenes = lp_scene_queue_create(); + + for (i = 0; i < Elements(rast->tasks); i++) { + struct lp_rasterizer_task *task = &rast->tasks[i]; + task->rast = rast; + task->thread_index = i; + } + + rast->num_threads = num_threads; + + create_rast_threads(rast); + + /* for synchronizing rasterization threads */ + pipe_barrier_init( &rast->barrier, rast->num_threads ); + + memset(lp_swizzled_cbuf, 0, sizeof lp_swizzled_cbuf); + + memset(lp_dummy_tile, 0, sizeof lp_dummy_tile); + + return rast; +} + + +/* Shutdown: + */ +void lp_rast_destroy( struct lp_rasterizer *rast ) +{ + unsigned i; + + /* Set exit_flag and signal each thread's work_ready semaphore. + * Each thread will be woken up, notice that the exit_flag is set and + * break out of its main loop. The thread will then exit. + */ + rast->exit_flag = TRUE; + for (i = 0; i < rast->num_threads; i++) { + pipe_semaphore_signal(&rast->tasks[i].work_ready); + } + + /* Wait for threads to terminate before cleaning up per-thread data */ + for (i = 0; i < rast->num_threads; i++) { + pipe_thread_wait(rast->threads[i]); + } + + /* Clean up per-thread data */ + for (i = 0; i < rast->num_threads; i++) { + pipe_semaphore_destroy(&rast->tasks[i].work_ready); + pipe_semaphore_destroy(&rast->tasks[i].work_done); + } + + /* for synchronizing rasterization threads */ + pipe_barrier_destroy( &rast->barrier ); + + lp_scene_queue_destroy(rast->full_scenes); + + FREE(rast); +} + + +/** Return number of rasterization threads */ +unsigned +lp_rast_get_num_threads( struct lp_rasterizer *rast ) +{ + return rast->num_threads; +} + + diff --git a/src/gallium/drivers/llvmpipe/lp_rast.h b/src/gallium/drivers/llvmpipe/lp_rast.h new file mode 100644 index 0000000..a64c152 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_rast.h @@ -0,0 +1,265 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * The rast code is concerned with rasterization of command bins. + * Each screen tile has a bin associated with it. To render the + * scene we iterate over the tile bins and execute the commands + * in each bin. + * We'll do that with multiple threads... + */ + + +#ifndef LP_RAST_H +#define LP_RAST_H + +#include "pipe/p_compiler.h" +#include "lp_jit.h" + + +struct lp_rasterizer; +struct lp_scene; +struct lp_fence; +struct cmd_bin; + +/** For sub-pixel positioning */ +#define FIXED_ORDER 4 +#define FIXED_ONE (1<stride)) +#define GET_DADY(inputs) ((float (*)[4])((char *)((inputs) + 1) + 2 * (inputs)->stride)) +#define GET_PLANES(tri) ((struct lp_rast_plane *)((char *)(&(tri)->inputs + 1) + 3 * (tri)->inputs.stride)) + + + +struct lp_rasterizer * +lp_rast_create( unsigned num_threads ); + +void +lp_rast_destroy( struct lp_rasterizer * ); + +unsigned +lp_rast_get_num_threads( struct lp_rasterizer * ); + +void +lp_rast_queue_scene( struct lp_rasterizer *rast, + struct lp_scene *scene ); + +void +lp_rast_finish( struct lp_rasterizer *rast ); + + +union lp_rast_cmd_arg { + const struct lp_rast_shader_inputs *shade_tile; + struct { + const struct lp_rast_triangle *tri; + unsigned plane_mask; + } triangle; + const struct lp_rast_state *set_state; + uint8_t clear_color[4]; + struct { + uint32_t value; + uint32_t mask; + } clear_zstencil; + const struct lp_rast_state *state; + struct lp_fence *fence; + struct llvmpipe_query *query_obj; +}; + + +/* Cast wrappers. Hopefully these compile to noops! + */ +static INLINE union lp_rast_cmd_arg +lp_rast_arg_inputs( const struct lp_rast_shader_inputs *shade_tile ) +{ + union lp_rast_cmd_arg arg; + arg.shade_tile = shade_tile; + return arg; +} + +static INLINE union lp_rast_cmd_arg +lp_rast_arg_triangle( const struct lp_rast_triangle *triangle, + unsigned plane_mask) +{ + union lp_rast_cmd_arg arg; + arg.triangle.tri = triangle; + arg.triangle.plane_mask = plane_mask; + return arg; +} + +static INLINE union lp_rast_cmd_arg +lp_rast_arg_state( const struct lp_rast_state *state ) +{ + union lp_rast_cmd_arg arg; + arg.set_state = state; + return arg; +} + +static INLINE union lp_rast_cmd_arg +lp_rast_arg_fence( struct lp_fence *fence ) +{ + union lp_rast_cmd_arg arg; + arg.fence = fence; + return arg; +} + + +static INLINE union lp_rast_cmd_arg +lp_rast_arg_clearzs( unsigned value, unsigned mask ) +{ + union lp_rast_cmd_arg arg; + arg.clear_zstencil.value = value; + arg.clear_zstencil.mask = mask; + return arg; +} + + +static INLINE union lp_rast_cmd_arg +lp_rast_arg_query( struct llvmpipe_query *pq ) +{ + union lp_rast_cmd_arg arg; + arg.query_obj = pq; + return arg; +} + +static INLINE union lp_rast_cmd_arg +lp_rast_arg_null( void ) +{ + union lp_rast_cmd_arg arg; + arg.set_state = NULL; + return arg; +} + + +/** + * Binnable Commands. + * These get put into bins by the setup code and are called when + * the bins are executed. + */ +#define LP_RAST_OP_CLEAR_COLOR 0x0 +#define LP_RAST_OP_CLEAR_ZSTENCIL 0x1 +#define LP_RAST_OP_TRIANGLE_1 0x2 +#define LP_RAST_OP_TRIANGLE_2 0x3 +#define LP_RAST_OP_TRIANGLE_3 0x4 +#define LP_RAST_OP_TRIANGLE_4 0x5 +#define LP_RAST_OP_TRIANGLE_5 0x6 +#define LP_RAST_OP_TRIANGLE_6 0x7 +#define LP_RAST_OP_TRIANGLE_7 0x8 +#define LP_RAST_OP_TRIANGLE_8 0x9 +#define LP_RAST_OP_TRIANGLE_3_4 0xa +#define LP_RAST_OP_TRIANGLE_3_16 0xb +#define LP_RAST_OP_TRIANGLE_4_16 0xc +#define LP_RAST_OP_SHADE_TILE 0xd +#define LP_RAST_OP_SHADE_TILE_OPAQUE 0xe +#define LP_RAST_OP_BEGIN_QUERY 0xf +#define LP_RAST_OP_END_QUERY 0x10 +#define LP_RAST_OP_SET_STATE 0x11 + +#define LP_RAST_OP_MAX 0x12 +#define LP_RAST_OP_MASK 0xff + +void +lp_debug_bins( struct lp_scene *scene ); +void +lp_debug_draw_bins_by_cmd_length( struct lp_scene *scene ); +void +lp_debug_draw_bins_by_coverage( struct lp_scene *scene ); + + +#endif diff --git a/src/gallium/drivers/llvmpipe/lp_rast_debug.c b/src/gallium/drivers/llvmpipe/lp_rast_debug.c new file mode 100644 index 0000000..64ac616 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_rast_debug.c @@ -0,0 +1,422 @@ +#include "util/u_math.h" +#include "lp_rast_priv.h" +#include "lp_state_fs.h" + +static INLINE int u_bit_scan(unsigned *mask) +{ + int i = ffs(*mask) - 1; + *mask &= ~(1 << i); + return i; +} + +struct tile { + int coverage; + int overdraw; + const struct lp_rast_state *state; + char data[TILE_SIZE][TILE_SIZE]; +}; + +static char get_label( int i ) +{ + static const char *cmd_labels = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + unsigned max_label = (2*26+10); + + if (i < max_label) + return cmd_labels[i]; + else + return '?'; +} + + + +static const char *cmd_names[LP_RAST_OP_MAX] = +{ + "clear_color", + "clear_zstencil", + "triangle_1", + "triangle_2", + "triangle_3", + "triangle_4", + "triangle_5", + "triangle_6", + "triangle_7", + "triangle_8", + "triangle_3_4", + "triangle_3_16", + "triangle_4_16", + "shade_tile", + "shade_tile_opaque", + "begin_query", + "end_query", + "set_state", +}; + +static const char *cmd_name(unsigned cmd) +{ + assert(Elements(cmd_names) > cmd); + return cmd_names[cmd]; +} + +static const struct lp_fragment_shader_variant * +get_variant( const struct lp_rast_state *state, + const struct cmd_block *block, + int k ) +{ + if (block->cmd[k] == LP_RAST_OP_SHADE_TILE || + block->cmd[k] == LP_RAST_OP_SHADE_TILE_OPAQUE || + block->cmd[k] == LP_RAST_OP_TRIANGLE_1 || + block->cmd[k] == LP_RAST_OP_TRIANGLE_2 || + block->cmd[k] == LP_RAST_OP_TRIANGLE_3 || + block->cmd[k] == LP_RAST_OP_TRIANGLE_4 || + block->cmd[k] == LP_RAST_OP_TRIANGLE_5 || + block->cmd[k] == LP_RAST_OP_TRIANGLE_6 || + block->cmd[k] == LP_RAST_OP_TRIANGLE_7) + return state->variant; + + return NULL; +} + + +static boolean +is_blend( const struct lp_rast_state *state, + const struct cmd_block *block, + int k ) +{ + const struct lp_fragment_shader_variant *variant = get_variant(state, block, k); + + if (variant) + return variant->key.blend.rt[0].blend_enable; + + return FALSE; +} + + + +static void +debug_bin( const struct cmd_bin *bin ) +{ + const struct lp_rast_state *state = NULL; + const struct cmd_block *head = bin->head; + int i, j = 0; + + debug_printf("bin %d,%d:\n", bin->x, bin->y); + + while (head) { + for (i = 0; i < head->count; i++, j++) { + if (head->cmd[i] == LP_RAST_OP_SET_STATE) + state = head->arg[i].state; + + debug_printf("%d: %s %s\n", j, + cmd_name(head->cmd[i]), + is_blend(state, head, i) ? "blended" : ""); + } + head = head->next; + } +} + + +static void plot(struct tile *tile, + int x, int y, + char val, + boolean blend) +{ + if (tile->data[x][y] == ' ') + tile->coverage++; + else + tile->overdraw++; + + tile->data[x][y] = val; +} + + + + + + +static int +debug_shade_tile(int x, int y, + const union lp_rast_cmd_arg arg, + struct tile *tile, + char val) +{ + const struct lp_rast_shader_inputs *inputs = arg.shade_tile; + boolean blend = tile->state->variant->key.blend.rt[0].blend_enable; + unsigned i,j; + + if (inputs->disable) + return 0; + + for (i = 0; i < TILE_SIZE; i++) + for (j = 0; j < TILE_SIZE; j++) + plot(tile, i, j, val, blend); + + return TILE_SIZE * TILE_SIZE; +} + +static int +debug_clear_tile(int x, int y, + const union lp_rast_cmd_arg arg, + struct tile *tile, + char val) +{ + unsigned i,j; + + for (i = 0; i < TILE_SIZE; i++) + for (j = 0; j < TILE_SIZE; j++) + plot(tile, i, j, val, FALSE); + + return TILE_SIZE * TILE_SIZE; + +} + + +static int +debug_triangle(int tilex, int tiley, + const union lp_rast_cmd_arg arg, + struct tile *tile, + char val) +{ + const struct lp_rast_triangle *tri = arg.triangle.tri; + unsigned plane_mask = arg.triangle.plane_mask; + const struct lp_rast_plane *tri_plane = GET_PLANES(tri); + struct lp_rast_plane plane[8]; + int x, y; + int count = 0; + unsigned i, nr_planes = 0; + boolean blend = tile->state->variant->key.blend.rt[0].blend_enable; + + if (tri->inputs.disable) { + /* This triangle was partially binned and has been disabled */ + return 0; + } + + while (plane_mask) { + plane[nr_planes] = tri_plane[u_bit_scan(&plane_mask)]; + plane[nr_planes].c = (plane[nr_planes].c + + plane[nr_planes].dcdy * tiley - + plane[nr_planes].dcdx * tilex); + nr_planes++; + } + + for(y = 0; y < TILE_SIZE; y++) + { + for(x = 0; x < TILE_SIZE; x++) + { + for (i = 0; i < nr_planes; i++) + if (plane[i].c <= 0) + goto out; + + plot(tile, x, y, val, blend); + count++; + + out: + for (i = 0; i < nr_planes; i++) + plane[i].c -= plane[i].dcdx; + } + + for (i = 0; i < nr_planes; i++) { + plane[i].c += plane[i].dcdx * TILE_SIZE; + plane[i].c += plane[i].dcdy; + } + } + return count; +} + + + + + +static void +do_debug_bin( struct tile *tile, + const struct cmd_bin *bin, + boolean print_cmds) +{ + unsigned k, j = 0; + const struct cmd_block *block; + + int tx = bin->x * TILE_SIZE; + int ty = bin->y * TILE_SIZE; + + memset(tile->data, ' ', sizeof tile->data); + tile->coverage = 0; + tile->overdraw = 0; + tile->state = NULL; + + for (block = bin->head; block; block = block->next) { + for (k = 0; k < block->count; k++, j++) { + boolean blend = is_blend(tile->state, block, k); + char val = get_label(j); + int count = 0; + + if (print_cmds) + debug_printf("%c: %15s", val, cmd_name(block->cmd[k])); + + if (block->cmd[k] == LP_RAST_OP_SET_STATE) + tile->state = block->arg[k].state; + + if (block->cmd[k] == LP_RAST_OP_CLEAR_COLOR || + block->cmd[k] == LP_RAST_OP_CLEAR_ZSTENCIL) + count = debug_clear_tile(tx, ty, block->arg[k], tile, val); + + if (block->cmd[k] == LP_RAST_OP_SHADE_TILE || + block->cmd[k] == LP_RAST_OP_SHADE_TILE_OPAQUE) + count = debug_shade_tile(tx, ty, block->arg[k], tile, val); + + if (block->cmd[k] == LP_RAST_OP_TRIANGLE_1 || + block->cmd[k] == LP_RAST_OP_TRIANGLE_2 || + block->cmd[k] == LP_RAST_OP_TRIANGLE_3 || + block->cmd[k] == LP_RAST_OP_TRIANGLE_4 || + block->cmd[k] == LP_RAST_OP_TRIANGLE_5 || + block->cmd[k] == LP_RAST_OP_TRIANGLE_6 || + block->cmd[k] == LP_RAST_OP_TRIANGLE_7) + count = debug_triangle(tx, ty, block->arg[k], tile, val); + + if (print_cmds) { + debug_printf(" % 5d", count); + + if (blend) + debug_printf(" blended"); + + debug_printf("\n"); + } + } + } +} + +void +lp_debug_bin( const struct cmd_bin *bin) +{ + struct tile tile; + int x,y; + + if (bin->head) { + do_debug_bin(&tile, bin, TRUE); + + debug_printf("------------------------------------------------------------------\n"); + for (y = 0; y < TILE_SIZE; y++) { + for (x = 0; x < TILE_SIZE; x++) { + debug_printf("%c", tile.data[y][x]); + } + debug_printf("|\n"); + } + debug_printf("------------------------------------------------------------------\n"); + + debug_printf("each pixel drawn avg %f times\n", + ((float)tile.overdraw + tile.coverage)/(float)tile.coverage); + } +} + + + + + + +/** Return number of bytes used for a single bin */ +static unsigned +lp_scene_bin_size( const struct lp_scene *scene, unsigned x, unsigned y ) +{ + struct cmd_bin *bin = lp_scene_get_bin((struct lp_scene *) scene, x, y); + const struct cmd_block *cmd; + unsigned size = 0; + for (cmd = bin->head; cmd; cmd = cmd->next) { + size += (cmd->count * + (sizeof(uint8_t) + sizeof(union lp_rast_cmd_arg))); + } + return size; +} + + + +void +lp_debug_draw_bins_by_coverage( struct lp_scene *scene ) +{ + unsigned x, y; + unsigned total = 0; + unsigned possible = 0; + static unsigned long long _total; + static unsigned long long _possible; + + for (x = 0; x < scene->tiles_x; x++) + debug_printf("-"); + debug_printf("\n"); + + for (y = 0; y < scene->tiles_y; y++) { + for (x = 0; x < scene->tiles_x; x++) { + struct cmd_bin *bin = lp_scene_get_bin(scene, x, y); + const char *bits = "0123456789"; + struct tile tile; + + if (bin->head) { + //lp_debug_bin(bin); + + do_debug_bin(&tile, bin, FALSE); + + total += tile.coverage; + possible += 64*64; + + if (tile.coverage == 64*64) + debug_printf("*"); + else if (tile.coverage) { + int bit = tile.coverage/(64.0*64.0)*10; + debug_printf("%c", bits[MIN2(bit,10)]); + } + else + debug_printf("?"); + } + else { + debug_printf(" "); + } + } + debug_printf("|\n"); + } + + for (x = 0; x < scene->tiles_x; x++) + debug_printf("-"); + debug_printf("\n"); + + debug_printf("this tile total: %u possible %u: percentage: %f\n", + total, + possible, + total * 100.0 / (float)possible); + + _total += total; + _possible += possible; + + debug_printf("overall total: %llu possible %llu: percentage: %f\n", + _total, + _possible, + _total * 100.0 / (double)_possible); +} + + +void +lp_debug_draw_bins_by_cmd_length( struct lp_scene *scene ) +{ + unsigned x, y; + + for (y = 0; y < scene->tiles_y; y++) { + for (x = 0; x < scene->tiles_x; x++) { + const char *bits = " ...,-~:;=o+xaw*#XAWWWWWWWWWWWWWWWW"; + int sz = lp_scene_bin_size(scene, x, y); + int sz2 = util_unsigned_logbase2(sz); + debug_printf("%c", bits[MIN2(sz2,32)]); + } + debug_printf("\n"); + } +} + + +void +lp_debug_bins( struct lp_scene *scene ) +{ + unsigned x, y; + + for (y = 0; y < scene->tiles_y; y++) { + for (x = 0; x < scene->tiles_x; x++) { + struct cmd_bin *bin = lp_scene_get_bin(scene, x, y); + if (bin->head) { + debug_bin(bin); + } + } + } +} diff --git a/src/gallium/drivers/llvmpipe/lp_rast_priv.h b/src/gallium/drivers/llvmpipe/lp_rast_priv.h new file mode 100644 index 0000000..cd686bc --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_rast_priv.h @@ -0,0 +1,311 @@ +/************************************************************************** + * + * 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 LP_RAST_PRIV_H +#define LP_RAST_PRIV_H + +#include "os/os_thread.h" +#include "util/u_format.h" +#include "gallivm/lp_bld_debug.h" +#include "lp_memory.h" +#include "lp_rast.h" +#include "lp_scene.h" +#include "lp_state.h" +#include "lp_texture.h" +#include "lp_tile_soa.h" +#include "lp_limits.h" + + +/* If we crash in a jitted function, we can examine jit_line and jit_state + * to get some info. This is not thread-safe, however. + */ +#ifdef DEBUG + +struct lp_rasterizer_task; +extern int jit_line; +extern const struct lp_rast_state *jit_state; +extern const struct lp_rasterizer_task *jit_task; + +#define BEGIN_JIT_CALL(state, task) \ + do { \ + jit_line = __LINE__; \ + jit_state = state; \ + jit_task = task; \ + } while (0) + +#define END_JIT_CALL() \ + do { \ + jit_line = 0; \ + jit_state = NULL; \ + } while (0) + +#else + +#define BEGIN_JIT_CALL(X, Y) +#define END_JIT_CALL() + +#endif + + +struct lp_rasterizer; +struct cmd_bin; + +/** + * Per-thread rasterization state + */ +struct lp_rasterizer_task +{ + const struct cmd_bin *bin; + const struct lp_rast_state *state; + + struct lp_scene *scene; + unsigned x, y; /**< Pos of this tile in framebuffer, in pixels */ + + uint8_t *color_tiles[PIPE_MAX_COLOR_BUFS]; + uint8_t *depth_tile; + + /** "back" pointer */ + struct lp_rasterizer *rast; + + /** "my" index */ + unsigned thread_index; + + /* occlude counter for visiable pixels */ + uint32_t vis_counter; + struct llvmpipe_query *query; + + pipe_semaphore work_ready; + pipe_semaphore work_done; +}; + + +/** + * This is the state required while rasterizing tiles. + * Note that this contains per-thread information too. + * The tile size is TILE_SIZE x TILE_SIZE pixels. + */ +struct lp_rasterizer +{ + boolean exit_flag; + + /** The incoming queue of scenes ready to rasterize */ + struct lp_scene_queue *full_scenes; + + /** The scene currently being rasterized by the threads */ + struct lp_scene *curr_scene; + + /** A task object for each rasterization thread */ + struct lp_rasterizer_task tasks[LP_MAX_THREADS]; + + unsigned num_threads; + pipe_thread threads[LP_MAX_THREADS]; + + /** For synchronizing the rasterization threads */ + pipe_barrier barrier; +}; + + +void +lp_rast_shade_quads_mask(struct lp_rasterizer_task *task, + const struct lp_rast_shader_inputs *inputs, + unsigned x, unsigned y, + unsigned mask); + + + +/** + * Get the pointer to a 4x4 depth/stencil block. + * We'll map the z/stencil buffer on demand here. + * Note that this may be called even when there's no z/stencil buffer - return + * NULL in that case. + * \param x, y location of 4x4 block in window coords + */ +static INLINE void * +lp_rast_get_depth_block_pointer(struct lp_rasterizer_task *task, + unsigned x, unsigned y) +{ + const struct lp_scene *scene = task->scene; + void *depth; + + assert((x % TILE_VECTOR_WIDTH) == 0); + assert((y % TILE_VECTOR_HEIGHT) == 0); + + if (!scene->zsbuf.map) { + /* Either out of memory or no zsbuf. Can't tell without access + * to the state. Just use dummy tile memory, but don't print + * the oom warning as this most likely because there is no + * zsbuf. + */ + return lp_dummy_tile; + } + + depth = (scene->zsbuf.map + + scene->zsbuf.stride * y + + scene->zsbuf.blocksize * x * TILE_VECTOR_HEIGHT); + + assert(lp_check_alignment(depth, 16)); + return depth; +} + + +/** + * Get pointer to the swizzled color tile + */ +static INLINE uint8_t * +lp_rast_get_color_tile_pointer(struct lp_rasterizer_task *task, + unsigned buf, enum lp_texture_usage usage) +{ + const struct lp_scene *scene = task->scene; + + assert(task->x % TILE_SIZE == 0); + assert(task->y % TILE_SIZE == 0); + assert(buf < scene->fb.nr_cbufs); + + if (!task->color_tiles[buf]) { + struct pipe_surface *cbuf = scene->fb.cbufs[buf]; + struct llvmpipe_resource *lpt; + assert(cbuf); + lpt = llvmpipe_resource(cbuf->texture); + task->color_tiles[buf] = lp_swizzled_cbuf[task->thread_index][buf]; + + if (usage != LP_TEX_USAGE_WRITE_ALL) { + llvmpipe_swizzle_cbuf_tile(lpt, + cbuf->u.tex.first_layer, + cbuf->u.tex.level, + task->x, task->y, + task->color_tiles[buf]); + } + } + + return task->color_tiles[buf]; +} + + +/** + * Get the pointer to a 4x4 color block (within a 64x64 tile). + * We'll map the color buffer on demand here. + * Note that this may be called even when there's no color buffers - return + * NULL in that case. + * \param x, y location of 4x4 block in window coords + */ +static INLINE uint8_t * +lp_rast_get_color_block_pointer(struct lp_rasterizer_task *task, + unsigned buf, unsigned x, unsigned y) +{ + unsigned px, py, pixel_offset; + uint8_t *color; + + assert((x % TILE_VECTOR_WIDTH) == 0); + assert((y % TILE_VECTOR_HEIGHT) == 0); + + color = lp_rast_get_color_tile_pointer(task, buf, LP_TEX_USAGE_READ_WRITE); + assert(color); + + px = x % TILE_SIZE; + py = y % TILE_SIZE; + pixel_offset = tile_pixel_offset(px, py, 0); + + color = color + pixel_offset; + + assert(lp_check_alignment(color, 16)); + return color; +} + + + +/** + * Shade all pixels in a 4x4 block. The fragment code omits the + * triangle in/out tests. + * \param x, y location of 4x4 block in window coords + */ +static INLINE void +lp_rast_shade_quads_all( struct lp_rasterizer_task *task, + const struct lp_rast_shader_inputs *inputs, + unsigned x, unsigned y ) +{ + const struct lp_scene *scene = task->scene; + const struct lp_rast_state *state = task->state; + struct lp_fragment_shader_variant *variant = state->variant; + uint8_t *color[PIPE_MAX_COLOR_BUFS]; + void *depth; + unsigned i; + + /* color buffer */ + for (i = 0; i < scene->fb.nr_cbufs; i++) + color[i] = lp_rast_get_color_block_pointer(task, i, x, y); + + depth = lp_rast_get_depth_block_pointer(task, x, y); + + /* run shader on 4x4 block */ + BEGIN_JIT_CALL(state, task); + variant->jit_function[RAST_WHOLE]( &state->jit_context, + x, y, + inputs->frontfacing, + GET_A0(inputs), + GET_DADX(inputs), + GET_DADY(inputs), + color, + depth, + 0xffff, + &task->vis_counter ); + END_JIT_CALL(); +} + +void lp_rast_triangle_1( struct lp_rasterizer_task *, + const union lp_rast_cmd_arg ); +void lp_rast_triangle_2( struct lp_rasterizer_task *, + const union lp_rast_cmd_arg ); +void lp_rast_triangle_3( struct lp_rasterizer_task *, + const union lp_rast_cmd_arg ); +void lp_rast_triangle_4( struct lp_rasterizer_task *, + const union lp_rast_cmd_arg ); +void lp_rast_triangle_5( struct lp_rasterizer_task *, + const union lp_rast_cmd_arg ); +void lp_rast_triangle_6( struct lp_rasterizer_task *, + const union lp_rast_cmd_arg ); +void lp_rast_triangle_7( struct lp_rasterizer_task *, + const union lp_rast_cmd_arg ); +void lp_rast_triangle_8( struct lp_rasterizer_task *, + const union lp_rast_cmd_arg ); + +void lp_rast_triangle_3_4(struct lp_rasterizer_task *, + const union lp_rast_cmd_arg ); + +void lp_rast_triangle_3_16( struct lp_rasterizer_task *, + const union lp_rast_cmd_arg ); + +void lp_rast_triangle_4_16( struct lp_rasterizer_task *, + const union lp_rast_cmd_arg ); + +void +lp_rast_set_state(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg); + +void +lp_debug_bin( const struct cmd_bin *bin ); + +#endif diff --git a/src/gallium/drivers/llvmpipe/lp_rast_tri.c b/src/gallium/drivers/llvmpipe/lp_rast_tri.c new file mode 100644 index 0000000..042c315 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_rast_tri.c @@ -0,0 +1,483 @@ +/************************************************************************** + * + * Copyright 2007-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. + * + **************************************************************************/ + +/* + * Rasterization for binned triangles within a tile + */ + +#include +#include "util/u_math.h" +#include "lp_debug.h" +#include "lp_perf.h" +#include "lp_rast_priv.h" +#include "lp_tile_soa.h" + + + + +/** + * Shade all pixels in a 4x4 block. + */ +static void +block_full_4(struct lp_rasterizer_task *task, + const struct lp_rast_triangle *tri, + int x, int y) +{ + lp_rast_shade_quads_all(task, &tri->inputs, x, y); +} + + +/** + * Shade all pixels in a 16x16 block. + */ +static void +block_full_16(struct lp_rasterizer_task *task, + const struct lp_rast_triangle *tri, + int x, int y) +{ + unsigned ix, iy; + assert(x % 16 == 0); + assert(y % 16 == 0); + for (iy = 0; iy < 16; iy += 4) + for (ix = 0; ix < 16; ix += 4) + block_full_4(task, tri, x + ix, y + iy); +} + +#if !defined(PIPE_ARCH_SSE) + +static INLINE unsigned +build_mask_linear(int c, int dcdx, int dcdy) +{ + int mask = 0; + + int c0 = c; + int c1 = c0 + dcdy; + int c2 = c1 + dcdy; + int c3 = c2 + dcdy; + + mask |= ((c0 + 0 * dcdx) >> 31) & (1 << 0); + mask |= ((c0 + 1 * dcdx) >> 31) & (1 << 1); + mask |= ((c0 + 2 * dcdx) >> 31) & (1 << 2); + mask |= ((c0 + 3 * dcdx) >> 31) & (1 << 3); + mask |= ((c1 + 0 * dcdx) >> 31) & (1 << 4); + mask |= ((c1 + 1 * dcdx) >> 31) & (1 << 5); + mask |= ((c1 + 2 * dcdx) >> 31) & (1 << 6); + mask |= ((c1 + 3 * dcdx) >> 31) & (1 << 7); + mask |= ((c2 + 0 * dcdx) >> 31) & (1 << 8); + mask |= ((c2 + 1 * dcdx) >> 31) & (1 << 9); + mask |= ((c2 + 2 * dcdx) >> 31) & (1 << 10); + mask |= ((c2 + 3 * dcdx) >> 31) & (1 << 11); + mask |= ((c3 + 0 * dcdx) >> 31) & (1 << 12); + mask |= ((c3 + 1 * dcdx) >> 31) & (1 << 13); + mask |= ((c3 + 2 * dcdx) >> 31) & (1 << 14); + mask |= ((c3 + 3 * dcdx) >> 31) & (1 << 15); + + return mask; +} + + +static INLINE void +build_masks(int c, + int cdiff, + int dcdx, + int dcdy, + unsigned *outmask, + unsigned *partmask) +{ + *outmask |= build_mask_linear(c, dcdx, dcdy); + *partmask |= build_mask_linear(c + cdiff, dcdx, dcdy); +} + +void +lp_rast_triangle_3_16(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + union lp_rast_cmd_arg arg2; + arg2.triangle.tri = arg.triangle.tri; + arg2.triangle.plane_mask = (1<<3)-1; + lp_rast_triangle_3(task, arg2); +} + +void +lp_rast_triangle_4_16(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + union lp_rast_cmd_arg arg2; + arg2.triangle.tri = arg.triangle.tri; + arg2.triangle.plane_mask = (1<<4)-1; + lp_rast_triangle_3(task, arg2); +} + +void +lp_rast_triangle_3_4(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + lp_rast_triangle_3_16(task, arg); +} + +#else +#include +#include "util/u_sse.h" + + +static INLINE void +build_masks(int c, + int cdiff, + int dcdx, + int dcdy, + unsigned *outmask, + unsigned *partmask) +{ + __m128i cstep0 = _mm_setr_epi32(c, c+dcdx, c+dcdx*2, c+dcdx*3); + __m128i xdcdy = _mm_set1_epi32(dcdy); + + /* Get values across the quad + */ + __m128i cstep1 = _mm_add_epi32(cstep0, xdcdy); + __m128i cstep2 = _mm_add_epi32(cstep1, xdcdy); + __m128i cstep3 = _mm_add_epi32(cstep2, xdcdy); + + { + __m128i cstep01, cstep23, result; + + cstep01 = _mm_packs_epi32(cstep0, cstep1); + cstep23 = _mm_packs_epi32(cstep2, cstep3); + result = _mm_packs_epi16(cstep01, cstep23); + + *outmask |= _mm_movemask_epi8(result); + } + + + { + __m128i cio4 = _mm_set1_epi32(cdiff); + __m128i cstep01, cstep23, result; + + cstep0 = _mm_add_epi32(cstep0, cio4); + cstep1 = _mm_add_epi32(cstep1, cio4); + cstep2 = _mm_add_epi32(cstep2, cio4); + cstep3 = _mm_add_epi32(cstep3, cio4); + + cstep01 = _mm_packs_epi32(cstep0, cstep1); + cstep23 = _mm_packs_epi32(cstep2, cstep3); + result = _mm_packs_epi16(cstep01, cstep23); + + *partmask |= _mm_movemask_epi8(result); + } +} + + +static INLINE unsigned +build_mask_linear(int c, int dcdx, int dcdy) +{ + __m128i cstep0 = _mm_setr_epi32(c, c+dcdx, c+dcdx*2, c+dcdx*3); + __m128i xdcdy = _mm_set1_epi32(dcdy); + + /* Get values across the quad + */ + __m128i cstep1 = _mm_add_epi32(cstep0, xdcdy); + __m128i cstep2 = _mm_add_epi32(cstep1, xdcdy); + __m128i cstep3 = _mm_add_epi32(cstep2, xdcdy); + + /* pack pairs of results into epi16 + */ + __m128i cstep01 = _mm_packs_epi32(cstep0, cstep1); + __m128i cstep23 = _mm_packs_epi32(cstep2, cstep3); + + /* pack into epi8, preserving sign bits + */ + __m128i result = _mm_packs_epi16(cstep01, cstep23); + + /* extract sign bits to create mask + */ + return _mm_movemask_epi8(result); +} + +static INLINE unsigned +sign_bits4(const __m128i *cstep, int cdiff) +{ + + /* Adjust the step values + */ + __m128i cio4 = _mm_set1_epi32(cdiff); + __m128i cstep0 = _mm_add_epi32(cstep[0], cio4); + __m128i cstep1 = _mm_add_epi32(cstep[1], cio4); + __m128i cstep2 = _mm_add_epi32(cstep[2], cio4); + __m128i cstep3 = _mm_add_epi32(cstep[3], cio4); + + /* Pack down to epi8 + */ + __m128i cstep01 = _mm_packs_epi32(cstep0, cstep1); + __m128i cstep23 = _mm_packs_epi32(cstep2, cstep3); + __m128i result = _mm_packs_epi16(cstep01, cstep23); + + /* Extract the sign bits + */ + return _mm_movemask_epi8(result); +} + + +#define NR_PLANES 3 + + + + + + + +void +lp_rast_triangle_3_16(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + const struct lp_rast_triangle *tri = arg.triangle.tri; + const struct lp_rast_plane *plane = GET_PLANES(tri); + int x = (arg.triangle.plane_mask & 0xff) + task->x; + int y = (arg.triangle.plane_mask >> 8) + task->y; + unsigned i, j; + + struct { unsigned mask:16; unsigned i:8; unsigned j:8; } out[16]; + unsigned nr = 0; + + __m128i p0 = _mm_load_si128((__m128i *)&plane[0]); /* c, dcdx, dcdy, eo */ + __m128i p1 = _mm_load_si128((__m128i *)&plane[1]); /* c, dcdx, dcdy, eo */ + __m128i p2 = _mm_load_si128((__m128i *)&plane[2]); /* c, dcdx, dcdy, eo */ + __m128i zero = _mm_setzero_si128(); + + __m128i c; + __m128i dcdx; + __m128i dcdy; + __m128i rej4; + + __m128i dcdx2; + __m128i dcdx3; + + __m128i span_0; /* 0,dcdx,2dcdx,3dcdx for plane 0 */ + __m128i span_1; /* 0,dcdx,2dcdx,3dcdx for plane 1 */ + __m128i span_2; /* 0,dcdx,2dcdx,3dcdx for plane 2 */ + __m128i unused; + + transpose4_epi32(&p0, &p1, &p2, &zero, + &c, &dcdx, &dcdy, &rej4); + + /* Adjust dcdx; + */ + dcdx = _mm_sub_epi32(zero, dcdx); + + c = _mm_add_epi32(c, mm_mullo_epi32(dcdx, _mm_set1_epi32(x))); + c = _mm_add_epi32(c, mm_mullo_epi32(dcdy, _mm_set1_epi32(y))); + rej4 = _mm_slli_epi32(rej4, 2); + + dcdx2 = _mm_add_epi32(dcdx, dcdx); + dcdx3 = _mm_add_epi32(dcdx2, dcdx); + + transpose4_epi32(&zero, &dcdx, &dcdx2, &dcdx3, + &span_0, &span_1, &span_2, &unused); + + for (i = 0; i < 4; i++) { + __m128i cx = c; + + for (j = 0; j < 4; j++) { + __m128i c4rej = _mm_add_epi32(cx, rej4); + __m128i rej_masks = _mm_srai_epi32(c4rej, 31); + + /* if (is_zero(rej_masks)) */ + if (_mm_movemask_epi8(rej_masks) == 0) { + __m128i c0_0 = _mm_add_epi32(SCALAR_EPI32(cx, 0), span_0); + __m128i c1_0 = _mm_add_epi32(SCALAR_EPI32(cx, 1), span_1); + __m128i c2_0 = _mm_add_epi32(SCALAR_EPI32(cx, 2), span_2); + + __m128i c_0 = _mm_or_si128(_mm_or_si128(c0_0, c1_0), c2_0); + + __m128i c0_1 = _mm_add_epi32(c0_0, SCALAR_EPI32(dcdy, 0)); + __m128i c1_1 = _mm_add_epi32(c1_0, SCALAR_EPI32(dcdy, 1)); + __m128i c2_1 = _mm_add_epi32(c2_0, SCALAR_EPI32(dcdy, 2)); + + __m128i c_1 = _mm_or_si128(_mm_or_si128(c0_1, c1_1), c2_1); + __m128i c_01 = _mm_packs_epi32(c_0, c_1); + + __m128i c0_2 = _mm_add_epi32(c0_1, SCALAR_EPI32(dcdy, 0)); + __m128i c1_2 = _mm_add_epi32(c1_1, SCALAR_EPI32(dcdy, 1)); + __m128i c2_2 = _mm_add_epi32(c2_1, SCALAR_EPI32(dcdy, 2)); + + __m128i c_2 = _mm_or_si128(_mm_or_si128(c0_2, c1_2), c2_2); + + __m128i c0_3 = _mm_add_epi32(c0_2, SCALAR_EPI32(dcdy, 0)); + __m128i c1_3 = _mm_add_epi32(c1_2, SCALAR_EPI32(dcdy, 1)); + __m128i c2_3 = _mm_add_epi32(c2_2, SCALAR_EPI32(dcdy, 2)); + + __m128i c_3 = _mm_or_si128(_mm_or_si128(c0_3, c1_3), c2_3); + __m128i c_23 = _mm_packs_epi32(c_2, c_3); + __m128i c_0123 = _mm_packs_epi16(c_01, c_23); + + unsigned mask = _mm_movemask_epi8(c_0123); + + out[nr].i = i; + out[nr].j = j; + out[nr].mask = mask; + if (mask != 0xffff) + nr++; + } + cx = _mm_add_epi32(cx, _mm_slli_epi32(dcdx, 2)); + } + + c = _mm_add_epi32(c, _mm_slli_epi32(dcdy, 2)); + } + + for (i = 0; i < nr; i++) + lp_rast_shade_quads_mask(task, + &tri->inputs, + x + 4 * out[i].j, + y + 4 * out[i].i, + 0xffff & ~out[i].mask); +} + + + + + +void +lp_rast_triangle_3_4(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + const struct lp_rast_triangle *tri = arg.triangle.tri; + const struct lp_rast_plane *plane = GET_PLANES(tri); + int x = (arg.triangle.plane_mask & 0xff) + task->x; + int y = (arg.triangle.plane_mask >> 8) + task->y; + + __m128i p0 = _mm_load_si128((__m128i *)&plane[0]); /* c, dcdx, dcdy, eo */ + __m128i p1 = _mm_load_si128((__m128i *)&plane[1]); /* c, dcdx, dcdy, eo */ + __m128i p2 = _mm_load_si128((__m128i *)&plane[2]); /* c, dcdx, dcdy, eo */ + __m128i zero = _mm_setzero_si128(); + + __m128i c; + __m128i dcdx; + __m128i dcdy; + + __m128i dcdx2; + __m128i dcdx3; + + __m128i span_0; /* 0,dcdx,2dcdx,3dcdx for plane 0 */ + __m128i span_1; /* 0,dcdx,2dcdx,3dcdx for plane 1 */ + __m128i span_2; /* 0,dcdx,2dcdx,3dcdx for plane 2 */ + __m128i unused; + + transpose4_epi32(&p0, &p1, &p2, &zero, + &c, &dcdx, &dcdy, &unused); + + /* Adjust dcdx; + */ + dcdx = _mm_sub_epi32(zero, dcdx); + + c = _mm_add_epi32(c, mm_mullo_epi32(dcdx, _mm_set1_epi32(x))); + c = _mm_add_epi32(c, mm_mullo_epi32(dcdy, _mm_set1_epi32(y))); + + dcdx2 = _mm_add_epi32(dcdx, dcdx); + dcdx3 = _mm_add_epi32(dcdx2, dcdx); + + transpose4_epi32(&zero, &dcdx, &dcdx2, &dcdx3, + &span_0, &span_1, &span_2, &unused); + + + { + __m128i c0_0 = _mm_add_epi32(SCALAR_EPI32(c, 0), span_0); + __m128i c1_0 = _mm_add_epi32(SCALAR_EPI32(c, 1), span_1); + __m128i c2_0 = _mm_add_epi32(SCALAR_EPI32(c, 2), span_2); + + __m128i c_0 = _mm_or_si128(_mm_or_si128(c0_0, c1_0), c2_0); + + __m128i c0_1 = _mm_add_epi32(c0_0, SCALAR_EPI32(dcdy, 0)); + __m128i c1_1 = _mm_add_epi32(c1_0, SCALAR_EPI32(dcdy, 1)); + __m128i c2_1 = _mm_add_epi32(c2_0, SCALAR_EPI32(dcdy, 2)); + + __m128i c_1 = _mm_or_si128(_mm_or_si128(c0_1, c1_1), c2_1); + __m128i c_01 = _mm_packs_epi32(c_0, c_1); + + __m128i c0_2 = _mm_add_epi32(c0_1, SCALAR_EPI32(dcdy, 0)); + __m128i c1_2 = _mm_add_epi32(c1_1, SCALAR_EPI32(dcdy, 1)); + __m128i c2_2 = _mm_add_epi32(c2_1, SCALAR_EPI32(dcdy, 2)); + + __m128i c_2 = _mm_or_si128(_mm_or_si128(c0_2, c1_2), c2_2); + + __m128i c0_3 = _mm_add_epi32(c0_2, SCALAR_EPI32(dcdy, 0)); + __m128i c1_3 = _mm_add_epi32(c1_2, SCALAR_EPI32(dcdy, 1)); + __m128i c2_3 = _mm_add_epi32(c2_2, SCALAR_EPI32(dcdy, 2)); + + __m128i c_3 = _mm_or_si128(_mm_or_si128(c0_3, c1_3), c2_3); + __m128i c_23 = _mm_packs_epi32(c_2, c_3); + __m128i c_0123 = _mm_packs_epi16(c_01, c_23); + + unsigned mask = _mm_movemask_epi8(c_0123); + + if (mask != 0xffff) + lp_rast_shade_quads_mask(task, + &tri->inputs, + x, + y, + 0xffff & ~mask); + } +} + +#undef NR_PLANES +#endif + + + + +#define TAG(x) x##_1 +#define NR_PLANES 1 +#include "lp_rast_tri_tmp.h" + +#define TAG(x) x##_2 +#define NR_PLANES 2 +#include "lp_rast_tri_tmp.h" + +#define TAG(x) x##_3 +#define NR_PLANES 3 +/*#define TRI_4 lp_rast_triangle_3_4*/ +/*#define TRI_16 lp_rast_triangle_3_16*/ +#include "lp_rast_tri_tmp.h" + +#define TAG(x) x##_4 +#define NR_PLANES 4 +#define TRI_16 lp_rast_triangle_4_16 +#include "lp_rast_tri_tmp.h" + +#define TAG(x) x##_5 +#define NR_PLANES 5 +#include "lp_rast_tri_tmp.h" + +#define TAG(x) x##_6 +#define NR_PLANES 6 +#include "lp_rast_tri_tmp.h" + +#define TAG(x) x##_7 +#define NR_PLANES 7 +#include "lp_rast_tri_tmp.h" + +#define TAG(x) x##_8 +#define NR_PLANES 8 +#include "lp_rast_tri_tmp.h" + diff --git a/src/gallium/drivers/llvmpipe/lp_rast_tri_tmp.h b/src/gallium/drivers/llvmpipe/lp_rast_tri_tmp.h new file mode 100644 index 0000000..4825d65 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_rast_tri_tmp.h @@ -0,0 +1,380 @@ +/************************************************************************** + * + * Copyright 2007-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* + * Rasterization for binned triangles within a tile + */ + + + +/** + * Prototype for a 8 plane rasterizer function. Will codegenerate + * several of these. + * + * XXX: Varients for more/fewer planes. + * XXX: Need ways of dropping planes as we descend. + * XXX: SIMD + */ +static void +TAG(do_block_4)(struct lp_rasterizer_task *task, + const struct lp_rast_triangle *tri, + const struct lp_rast_plane *plane, + int x, int y, + const int *c) +{ + unsigned mask = 0xffff; + int j; + + for (j = 0; j < NR_PLANES; j++) { + mask &= ~build_mask_linear(c[j] - 1, + -plane[j].dcdx, + plane[j].dcdy); + } + + /* Now pass to the shader: + */ + if (mask) + lp_rast_shade_quads_mask(task, &tri->inputs, x, y, mask); +} + +/** + * Evaluate a 16x16 block of pixels to determine which 4x4 subblocks are in/out + * of the triangle's bounds. + */ +static void +TAG(do_block_16)(struct lp_rasterizer_task *task, + const struct lp_rast_triangle *tri, + const struct lp_rast_plane *plane, + int x, int y, + const int *c) +{ + unsigned outmask, inmask, partmask, partial_mask; + unsigned j; + + outmask = 0; /* outside one or more trivial reject planes */ + partmask = 0; /* outside one or more trivial accept planes */ + + for (j = 0; j < NR_PLANES; j++) { + const int dcdx = -plane[j].dcdx * 4; + const int dcdy = plane[j].dcdy * 4; + const int cox = plane[j].eo * 4; + const int ei = plane[j].dcdy - plane[j].dcdx - plane[j].eo; + const int cio = ei * 4 - 1; + + build_masks(c[j] + cox, + cio - cox, + dcdx, dcdy, + &outmask, /* sign bits from c[i][0..15] + cox */ + &partmask); /* sign bits from c[i][0..15] + cio */ + } + + if (outmask == 0xffff) + return; + + /* Mask of sub-blocks which are inside all trivial accept planes: + */ + inmask = ~partmask & 0xffff; + + /* Mask of sub-blocks which are inside all trivial reject planes, + * but outside at least one trivial accept plane: + */ + partial_mask = partmask & ~outmask; + + assert((partial_mask & inmask) == 0); + + LP_COUNT_ADD(nr_empty_4, util_bitcount(0xffff & ~(partial_mask | inmask))); + + /* Iterate over partials: + */ + while (partial_mask) { + int i = ffs(partial_mask) - 1; + int ix = (i & 3) * 4; + int iy = (i >> 2) * 4; + int px = x + ix; + int py = y + iy; + int cx[NR_PLANES]; + + partial_mask &= ~(1 << i); + + LP_COUNT(nr_partially_covered_4); + + for (j = 0; j < NR_PLANES; j++) + cx[j] = (c[j] + - plane[j].dcdx * ix + + plane[j].dcdy * iy); + + TAG(do_block_4)(task, tri, plane, px, py, cx); + } + + /* Iterate over fulls: + */ + while (inmask) { + int i = ffs(inmask) - 1; + int ix = (i & 3) * 4; + int iy = (i >> 2) * 4; + int px = x + ix; + int py = y + iy; + + inmask &= ~(1 << i); + + LP_COUNT(nr_fully_covered_4); + block_full_4(task, tri, px, py); + } +} + + +/** + * Scan the tile in chunks and figure out which pixels to rasterize + * for this triangle. + */ +void +TAG(lp_rast_triangle)(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + const struct lp_rast_triangle *tri = arg.triangle.tri; + unsigned plane_mask = arg.triangle.plane_mask; + const struct lp_rast_plane *tri_plane = GET_PLANES(tri); + const int x = task->x, y = task->y; + struct lp_rast_plane plane[NR_PLANES]; + int c[NR_PLANES]; + unsigned outmask, inmask, partmask, partial_mask; + unsigned j = 0; + + if (tri->inputs.disable) { + /* This triangle was partially binned and has been disabled */ + return; + } + + outmask = 0; /* outside one or more trivial reject planes */ + partmask = 0; /* outside one or more trivial accept planes */ + + while (plane_mask) { + int i = ffs(plane_mask) - 1; + plane[j] = tri_plane[i]; + plane_mask &= ~(1 << i); + c[j] = plane[j].c + plane[j].dcdy * y - plane[j].dcdx * x; + + { + const int dcdx = -plane[j].dcdx * 16; + const int dcdy = plane[j].dcdy * 16; + const int cox = plane[j].eo * 16; + const int ei = plane[j].dcdy - plane[j].dcdx - plane[j].eo; + const int cio = ei * 16 - 1; + + build_masks(c[j] + cox, + cio - cox, + dcdx, dcdy, + &outmask, /* sign bits from c[i][0..15] + cox */ + &partmask); /* sign bits from c[i][0..15] + cio */ + } + + j++; + } + + if (outmask == 0xffff) + return; + + /* Mask of sub-blocks which are inside all trivial accept planes: + */ + inmask = ~partmask & 0xffff; + + /* Mask of sub-blocks which are inside all trivial reject planes, + * but outside at least one trivial accept plane: + */ + partial_mask = partmask & ~outmask; + + assert((partial_mask & inmask) == 0); + + LP_COUNT_ADD(nr_empty_16, util_bitcount(0xffff & ~(partial_mask | inmask))); + + /* Iterate over partials: + */ + while (partial_mask) { + int i = ffs(partial_mask) - 1; + int ix = (i & 3) * 16; + int iy = (i >> 2) * 16; + int px = x + ix; + int py = y + iy; + int cx[NR_PLANES]; + + for (j = 0; j < NR_PLANES; j++) + cx[j] = (c[j] + - plane[j].dcdx * ix + + plane[j].dcdy * iy); + + partial_mask &= ~(1 << i); + + LP_COUNT(nr_partially_covered_16); + TAG(do_block_16)(task, tri, plane, px, py, cx); + } + + /* Iterate over fulls: + */ + while (inmask) { + int i = ffs(inmask) - 1; + int ix = (i & 3) * 16; + int iy = (i >> 2) * 16; + int px = x + ix; + int py = y + iy; + + inmask &= ~(1 << i); + + LP_COUNT(nr_fully_covered_16); + block_full_16(task, tri, px, py); + } +} + +#if defined(PIPE_ARCH_SSE) && defined(TRI_16) +/* XXX: special case this when intersection is not required. + * - tile completely within bbox, + * - bbox completely within tile. + */ +void +TRI_16(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + const struct lp_rast_triangle *tri = arg.triangle.tri; + const struct lp_rast_plane *plane = GET_PLANES(tri); + unsigned mask = arg.triangle.plane_mask; + unsigned outmask, partial_mask; + unsigned j; + __m128i cstep4[NR_PLANES][4]; + + int x = (mask & 0xff); + int y = (mask >> 8); + + outmask = 0; /* outside one or more trivial reject planes */ + + x += task->x; + y += task->y; + + for (j = 0; j < NR_PLANES; j++) { + const int dcdx = -plane[j].dcdx * 4; + const int dcdy = plane[j].dcdy * 4; + __m128i xdcdy = _mm_set1_epi32(dcdy); + + cstep4[j][0] = _mm_setr_epi32(0, dcdx, dcdx*2, dcdx*3); + cstep4[j][1] = _mm_add_epi32(cstep4[j][0], xdcdy); + cstep4[j][2] = _mm_add_epi32(cstep4[j][1], xdcdy); + cstep4[j][3] = _mm_add_epi32(cstep4[j][2], xdcdy); + + { + const int c = plane[j].c + plane[j].dcdy * y - plane[j].dcdx * x; + const int cox = plane[j].eo * 4; + + outmask |= sign_bits4(cstep4[j], c + cox); + } + } + + if (outmask == 0xffff) + return; + + + /* Mask of sub-blocks which are inside all trivial reject planes, + * but outside at least one trivial accept plane: + */ + partial_mask = 0xffff & ~outmask; + + /* Iterate over partials: + */ + while (partial_mask) { + int i = ffs(partial_mask) - 1; + int ix = (i & 3) * 4; + int iy = (i >> 2) * 4; + int px = x + ix; + int py = y + iy; + unsigned mask = 0xffff; + + partial_mask &= ~(1 << i); + + for (j = 0; j < NR_PLANES; j++) { + const int cx = (plane[j].c - 1 + - plane[j].dcdx * px + + plane[j].dcdy * py) * 4; + + mask &= ~sign_bits4(cstep4[j], cx); + } + + if (mask) + lp_rast_shade_quads_mask(task, &tri->inputs, px, py, mask); + } +} +#endif + +#if defined(PIPE_ARCH_SSE) && defined(TRI_4) +void +TRI_4(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) +{ + const struct lp_rast_triangle *tri = arg.triangle.tri; + const struct lp_rast_plane *plane = GET_PLANES(tri); + unsigned mask = arg.triangle.plane_mask; + const int x = task->x + (mask & 0xff); + const int y = task->y + (mask >> 8); + unsigned j; + + /* Iterate over partials: + */ + { + unsigned mask = 0xffff; + + for (j = 0; j < NR_PLANES; j++) { + const int cx = (plane[j].c + - plane[j].dcdx * x + + plane[j].dcdy * y); + + const int dcdx = -plane[j].dcdx; + const int dcdy = plane[j].dcdy; + __m128i xdcdy = _mm_set1_epi32(dcdy); + + __m128i cstep0 = _mm_setr_epi32(cx, cx + dcdx, cx + dcdx*2, cx + dcdx*3); + __m128i cstep1 = _mm_add_epi32(cstep0, xdcdy); + __m128i cstep2 = _mm_add_epi32(cstep1, xdcdy); + __m128i cstep3 = _mm_add_epi32(cstep2, xdcdy); + + __m128i cstep01 = _mm_packs_epi32(cstep0, cstep1); + __m128i cstep23 = _mm_packs_epi32(cstep2, cstep3); + __m128i result = _mm_packs_epi16(cstep01, cstep23); + + /* Extract the sign bits + */ + mask &= ~_mm_movemask_epi8(result); + } + + if (mask) + lp_rast_shade_quads_mask(task, &tri->inputs, x, y, mask); + } +} +#endif + + + +#undef TAG +#undef TRI_4 +#undef TRI_16 +#undef NR_PLANES + diff --git a/src/gallium/drivers/llvmpipe/lp_scene.c b/src/gallium/drivers/llvmpipe/lp_scene.c new file mode 100644 index 0000000..5d0f5f8 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_scene.c @@ -0,0 +1,500 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_framebuffer.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "util/u_simple_list.h" +#include "util/u_format.h" +#include "lp_scene.h" +#include "lp_fence.h" +#include "lp_debug.h" + + +#define RESOURCE_REF_SZ 32 + +/** List of resource references */ +struct resource_ref { + struct pipe_resource *resource[RESOURCE_REF_SZ]; + int count; + struct resource_ref *next; +}; + + +/** + * Create a new scene object. + * \param queue the queue to put newly rendered/emptied scenes into + */ +struct lp_scene * +lp_scene_create( struct pipe_context *pipe ) +{ + struct lp_scene *scene = CALLOC_STRUCT(lp_scene); + if (!scene) + return NULL; + + scene->pipe = pipe; + + scene->data.head = + CALLOC_STRUCT(data_block); + + pipe_mutex_init(scene->mutex); + + return scene; +} + + +/** + * Free all data associated with the given scene, and the scene itself. + */ +void +lp_scene_destroy(struct lp_scene *scene) +{ + lp_fence_reference(&scene->fence, NULL); + pipe_mutex_destroy(scene->mutex); + assert(scene->data.head->next == NULL); + FREE(scene->data.head); + FREE(scene); +} + + +/** + * Check if the scene's bins are all empty. + * For debugging purposes. + */ +boolean +lp_scene_is_empty(struct lp_scene *scene ) +{ + unsigned x, y; + + for (y = 0; y < TILES_Y; y++) { + for (x = 0; x < TILES_X; x++) { + const struct cmd_bin *bin = lp_scene_get_bin(scene, x, y); + if (bin->head) { + return FALSE; + } + } + } + return TRUE; +} + + +/* Returns true if there has ever been a failed allocation attempt in + * this scene. Used in triangle emit to avoid having to check success + * at each bin. + */ +boolean +lp_scene_is_oom(struct lp_scene *scene) +{ + return scene->alloc_failed; +} + + +/* Remove all commands from a bin. Tries to reuse some of the memory + * allocated to the bin, however. + */ +void +lp_scene_bin_reset(struct lp_scene *scene, unsigned x, unsigned y) +{ + struct cmd_bin *bin = lp_scene_get_bin(scene, x, y); + + bin->head = bin->tail; + if (bin->tail) { + bin->tail->next = NULL; + bin->tail->count = 0; + } +} + + +void +lp_scene_begin_rasterization(struct lp_scene *scene) +{ + const struct pipe_framebuffer_state *fb = &scene->fb; + int i; + + //LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__); + + for (i = 0; i < scene->fb.nr_cbufs; i++) { + struct pipe_surface *cbuf = scene->fb.cbufs[i]; + assert(cbuf->u.tex.first_layer == cbuf->u.tex.last_layer); + scene->cbufs[i].stride = llvmpipe_resource_stride(cbuf->texture, + cbuf->u.tex.level); + + scene->cbufs[i].map = llvmpipe_resource_map(cbuf->texture, + cbuf->u.tex.level, + cbuf->u.tex.first_layer, + LP_TEX_USAGE_READ_WRITE, + LP_TEX_LAYOUT_LINEAR); + } + + if (fb->zsbuf) { + struct pipe_surface *zsbuf = scene->fb.zsbuf; + assert(zsbuf->u.tex.first_layer == zsbuf->u.tex.last_layer); + scene->zsbuf.stride = llvmpipe_resource_stride(zsbuf->texture, zsbuf->u.tex.level); + scene->zsbuf.blocksize = + util_format_get_blocksize(zsbuf->texture->format); + + scene->zsbuf.map = llvmpipe_resource_map(zsbuf->texture, + zsbuf->u.tex.level, + zsbuf->u.tex.first_layer, + LP_TEX_USAGE_READ_WRITE, + LP_TEX_LAYOUT_NONE); + } +} + + + + +/** + * Free all the temporary data in a scene. + */ +void +lp_scene_end_rasterization(struct lp_scene *scene ) +{ + int i, j; + + /* Unmap color buffers */ + for (i = 0; i < scene->fb.nr_cbufs; i++) { + if (scene->cbufs[i].map) { + struct pipe_surface *cbuf = scene->fb.cbufs[i]; + llvmpipe_resource_unmap(cbuf->texture, + cbuf->u.tex.level, + cbuf->u.tex.first_layer); + scene->cbufs[i].map = NULL; + } + } + + /* Unmap z/stencil buffer */ + if (scene->zsbuf.map) { + struct pipe_surface *zsbuf = scene->fb.zsbuf; + llvmpipe_resource_unmap(zsbuf->texture, + zsbuf->u.tex.level, + zsbuf->u.tex.first_layer); + scene->zsbuf.map = NULL; + } + + /* Reset all command lists: + */ + for (i = 0; i < scene->tiles_x; i++) { + for (j = 0; j < scene->tiles_y; j++) { + struct cmd_bin *bin = lp_scene_get_bin(scene, i, j); + bin->head = NULL; + bin->tail = NULL; + bin->last_state = NULL; + } + } + + /* If there are any bins which weren't cleared by the loop above, + * they will be caught (on debug builds at least) by this assert: + */ + assert(lp_scene_is_empty(scene)); + + /* Decrement texture ref counts + */ + { + struct resource_ref *ref; + int i, j = 0; + + for (ref = scene->resources; ref; ref = ref->next) { + for (i = 0; i < ref->count; i++) { + if (LP_DEBUG & DEBUG_SETUP) + debug_printf("resource %d: %p %dx%d sz %d\n", + j, + (void *) ref->resource[i], + ref->resource[i]->width0, + ref->resource[i]->height0, + llvmpipe_resource_size(ref->resource[i])); + j++; + pipe_resource_reference(&ref->resource[i], NULL); + } + } + + if (LP_DEBUG & DEBUG_SETUP) + debug_printf("scene %d resources, sz %d\n", + j, scene->resource_reference_size); + } + + /* Free all scene data blocks: + */ + { + struct data_block_list *list = &scene->data; + struct data_block *block, *tmp; + + for (block = list->head->next; block; block = tmp) { + tmp = block->next; + FREE(block); + } + + list->head->next = NULL; + list->head->used = 0; + } + + lp_fence_reference(&scene->fence, NULL); + + scene->resources = NULL; + scene->scene_size = 0; + scene->resource_reference_size = 0; + + scene->has_depthstencil_clear = FALSE; + scene->alloc_failed = FALSE; + + util_unreference_framebuffer_state( &scene->fb ); +} + + + + + + +struct cmd_block * +lp_scene_new_cmd_block( struct lp_scene *scene, + struct cmd_bin *bin ) +{ + struct cmd_block *block = lp_scene_alloc(scene, sizeof(struct cmd_block)); + if (block) { + if (bin->tail) { + bin->tail->next = block; + bin->tail = block; + } + else { + bin->head = block; + bin->tail = block; + } + //memset(block, 0, sizeof *block); + block->next = NULL; + block->count = 0; + } + return block; +} + + +struct data_block * +lp_scene_new_data_block( struct lp_scene *scene ) +{ + if (scene->scene_size + DATA_BLOCK_SIZE > LP_SCENE_MAX_SIZE) { + if (0) debug_printf("%s: failed\n", __FUNCTION__); + scene->alloc_failed = TRUE; + return NULL; + } + else { + struct data_block *block = MALLOC_STRUCT(data_block); + if (block == NULL) + return NULL; + + scene->scene_size += sizeof *block; + + block->used = 0; + block->next = scene->data.head; + scene->data.head = block; + + return block; + } +} + + +/** + * Return number of bytes used for all bin data within a scene. + * This does not include resources (textures) referenced by the scene. + */ +static unsigned +lp_scene_data_size( const struct lp_scene *scene ) +{ + unsigned size = 0; + const struct data_block *block; + for (block = scene->data.head; block; block = block->next) { + size += block->used; + } + return size; +} + + + +/** + * Add a reference to a resource by the scene. + */ +boolean +lp_scene_add_resource_reference(struct lp_scene *scene, + struct pipe_resource *resource, + boolean initializing_scene) +{ + struct resource_ref *ref, **last = &scene->resources; + int i; + + /* Look at existing resource blocks: + */ + for (ref = scene->resources; ref; ref = ref->next) { + last = &ref->next; + + /* Search for this resource: + */ + for (i = 0; i < ref->count; i++) + if (ref->resource[i] == resource) + return TRUE; + + if (ref->count < RESOURCE_REF_SZ) { + /* If the block is half-empty, then append the reference here. + */ + break; + } + } + + /* Create a new block if no half-empty block was found. + */ + if (!ref) { + assert(*last == NULL); + *last = lp_scene_alloc(scene, sizeof *ref); + if (*last == NULL) + return FALSE; + + ref = *last; + memset(ref, 0, sizeof *ref); + } + + /* Append the reference to the reference block. + */ + pipe_resource_reference(&ref->resource[ref->count++], resource); + scene->resource_reference_size += llvmpipe_resource_size(resource); + + /* Heuristic to advise scene flushes. This isn't helpful in the + * initial setup of the scene, but after that point flush on the + * next resource added which exceeds 64MB in referenced texture + * data. + */ + if (!initializing_scene && + scene->resource_reference_size >= LP_SCENE_MAX_RESOURCE_SIZE) + return FALSE; + + return TRUE; +} + + +/** + * Does this scene have a reference to the given resource? + */ +boolean +lp_scene_is_resource_referenced(const struct lp_scene *scene, + const struct pipe_resource *resource) +{ + const struct resource_ref *ref; + int i; + + for (ref = scene->resources; ref; ref = ref->next) { + for (i = 0; i < ref->count; i++) + if (ref->resource[i] == resource) + return TRUE; + } + + return FALSE; +} + + + + +/** advance curr_x,y to the next bin */ +static boolean +next_bin(struct lp_scene *scene) +{ + scene->curr_x++; + if (scene->curr_x >= scene->tiles_x) { + scene->curr_x = 0; + scene->curr_y++; + } + if (scene->curr_y >= scene->tiles_y) { + /* no more bins */ + return FALSE; + } + return TRUE; +} + + +void +lp_scene_bin_iter_begin( struct lp_scene *scene ) +{ + scene->curr_x = scene->curr_y = -1; +} + + +/** + * Return pointer to next bin to be rendered. + * The lp_scene::curr_x and ::curr_y fields will be advanced. + * Multiple rendering threads will call this function to get a chunk + * of work (a bin) to work on. + */ +struct cmd_bin * +lp_scene_bin_iter_next( struct lp_scene *scene ) +{ + struct cmd_bin *bin = NULL; + + pipe_mutex_lock(scene->mutex); + + if (scene->curr_x < 0) { + /* first bin */ + scene->curr_x = 0; + scene->curr_y = 0; + } + else if (!next_bin(scene)) { + /* no more bins left */ + goto end; + } + + bin = lp_scene_get_bin(scene, scene->curr_x, scene->curr_y); + +end: + /*printf("return bin %p at %d, %d\n", (void *) bin, *bin_x, *bin_y);*/ + pipe_mutex_unlock(scene->mutex); + return bin; +} + + +void lp_scene_begin_binning( struct lp_scene *scene, + struct pipe_framebuffer_state *fb ) +{ + assert(lp_scene_is_empty(scene)); + + util_copy_framebuffer_state(&scene->fb, fb); + + scene->tiles_x = align(fb->width, TILE_SIZE) / TILE_SIZE; + scene->tiles_y = align(fb->height, TILE_SIZE) / TILE_SIZE; + + assert(scene->tiles_x <= TILES_X); + assert(scene->tiles_y <= TILES_Y); +} + + +void lp_scene_end_binning( struct lp_scene *scene ) +{ + if (LP_DEBUG & DEBUG_SCENE) { + debug_printf("rasterize scene:\n"); + debug_printf(" scene_size: %u\n", + scene->scene_size); + debug_printf(" data size: %u\n", + lp_scene_data_size(scene)); + + if (0) + lp_debug_bins( scene ); + } +} diff --git a/src/gallium/drivers/llvmpipe/lp_scene.h b/src/gallium/drivers/llvmpipe/lp_scene.h new file mode 100644 index 0000000..622c522 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_scene.h @@ -0,0 +1,403 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * Binner data structures and bin-related functions. + * Note: the "setup" code is concerned with building scenes while + * The "rast" code is concerned with consuming/executing scenes. + */ + +#ifndef LP_SCENE_H +#define LP_SCENE_H + +#include "os/os_thread.h" +#include "lp_tile_soa.h" +#include "lp_rast.h" +#include "lp_debug.h" + +struct lp_scene_queue; +struct lp_rast_state; + +/* We're limited to 2K by 2K for 32bit fixed point rasterization. + * Will need a 64-bit version for larger framebuffers. + */ +#define TILES_X (LP_MAX_WIDTH / TILE_SIZE) +#define TILES_Y (LP_MAX_HEIGHT / TILE_SIZE) + + +#define CMD_BLOCK_MAX 128 +#define DATA_BLOCK_SIZE (64 * 1024) + +/* Scene temporary storage is clamped to this size: + */ +#define LP_SCENE_MAX_SIZE (4*1024*1024) + +/* The maximum amount of texture storage referenced by a scene is + * clamped ot this size: + */ +#define LP_SCENE_MAX_RESOURCE_SIZE (64*1024*1024) + + +/* switch to a non-pointer value for this: + */ +typedef void (*lp_rast_cmd_func)( struct lp_rasterizer_task *, + const union lp_rast_cmd_arg ); + + +struct cmd_block { + uint8_t cmd[CMD_BLOCK_MAX]; + union lp_rast_cmd_arg arg[CMD_BLOCK_MAX]; + unsigned count; + struct cmd_block *next; +}; + +struct cmd_block_list { + struct cmd_block *head; + struct cmd_block *tail; +}; + +struct data_block { + ubyte data[DATA_BLOCK_SIZE]; + unsigned used; + struct data_block *next; +}; + + + +/** + * For each screen tile we have one of these bins. + */ +struct cmd_bin { + ushort x; + ushort y; + const struct lp_rast_state *last_state; /* most recent state set in bin */ + struct cmd_block *head; + struct cmd_block *tail; +}; + + +/** + * This stores bulk data which is used for all memory allocations + * within a scene. + * + * Examples include triangle data and state data. The commands in + * the per-tile bins will point to chunks of data in this structure. + * + * Include the first block of data statically to ensure we can always + * initiate a scene without relying on malloc succeeding. + */ +struct data_block_list { + struct data_block first; + struct data_block *head; +}; + +struct resource_ref; + +/** + * All bins and bin data are contained here. + * Per-bin data goes into the 'tile' bins. + * Shared data goes into the 'data' buffer. + * + * When there are multiple threads, will want to double-buffer between + * scenes: + */ +struct lp_scene { + struct pipe_context *pipe; + struct lp_fence *fence; + + /* Framebuffer mappings - valid only between begin_rasterization() + * and end_rasterization(). + */ + struct { + uint8_t *map; + unsigned stride; + unsigned blocksize; + } zsbuf, cbufs[PIPE_MAX_COLOR_BUFS]; + + /** the framebuffer to render the scene into */ + struct pipe_framebuffer_state fb; + + /** list of resources referenced by the scene commands */ + struct resource_ref *resources; + + /** Total memory used by the scene (in bytes). This sums all the + * data blocks and counts all bins, state, resource references and + * other random allocations within the scene. + */ + unsigned scene_size; + + /** Sum of sizes of all resources referenced by the scene. Sums + * all the textures read by the scene: + */ + unsigned resource_reference_size; + + boolean alloc_failed; + boolean has_depthstencil_clear; + + /** + * Number of active tiles in each dimension. + * This basically the framebuffer size divided by tile size + */ + unsigned tiles_x, tiles_y; + + int curr_x, curr_y; /**< for iterating over bins */ + pipe_mutex mutex; + + struct cmd_bin tile[TILES_X][TILES_Y]; + struct data_block_list data; +}; + + + +struct lp_scene *lp_scene_create(struct pipe_context *pipe); + +void lp_scene_destroy(struct lp_scene *scene); + +boolean lp_scene_is_empty(struct lp_scene *scene ); +boolean lp_scene_is_oom(struct lp_scene *scene ); + + +struct data_block *lp_scene_new_data_block( struct lp_scene *scene ); + +struct cmd_block *lp_scene_new_cmd_block( struct lp_scene *scene, + struct cmd_bin *bin ); + +boolean lp_scene_add_resource_reference(struct lp_scene *scene, + struct pipe_resource *resource, + boolean initializing_scene); + +boolean lp_scene_is_resource_referenced(const struct lp_scene *scene, + const struct pipe_resource *resource ); + + +/** + * Allocate space for a command/data in the bin's data buffer. + * Grow the block list if needed. + */ +static INLINE void * +lp_scene_alloc( struct lp_scene *scene, unsigned size) +{ + struct data_block_list *list = &scene->data; + struct data_block *block = list->head; + + assert(size <= DATA_BLOCK_SIZE); + assert(block != NULL); + + if (LP_DEBUG & DEBUG_MEM) + debug_printf("alloc %u block %u/%u tot %u/%u\n", + size, block->used, DATA_BLOCK_SIZE, + scene->scene_size, LP_SCENE_MAX_SIZE); + + if (block->used + size > DATA_BLOCK_SIZE) { + block = lp_scene_new_data_block( scene ); + if (!block) { + /* out of memory */ + return NULL; + } + } + + { + ubyte *data = block->data + block->used; + block->used += size; + return data; + } +} + + +/** + * As above, but with specific alignment. + */ +static INLINE void * +lp_scene_alloc_aligned( struct lp_scene *scene, unsigned size, + unsigned alignment ) +{ + struct data_block_list *list = &scene->data; + struct data_block *block = list->head; + + assert(block != NULL); + + if (LP_DEBUG & DEBUG_MEM) + debug_printf("alloc %u block %u/%u tot %u/%u\n", + size + alignment - 1, + block->used, DATA_BLOCK_SIZE, + scene->scene_size, LP_SCENE_MAX_SIZE); + + if (block->used + size + alignment - 1 > DATA_BLOCK_SIZE) { + block = lp_scene_new_data_block( scene ); + if (!block) + return NULL; + } + + { + ubyte *data = block->data + block->used; + unsigned offset = (((uintptr_t)data + alignment - 1) & ~(alignment - 1)) - (uintptr_t)data; + block->used += offset + size; + return data + offset; + } +} + + +/* Put back data if we decide not to use it, eg. culled triangles. + */ +static INLINE void +lp_scene_putback_data( struct lp_scene *scene, unsigned size) +{ + struct data_block_list *list = &scene->data; + assert(list->head && list->head->used >= size); + list->head->used -= size; +} + + +/** Return pointer to a particular tile's bin. */ +static INLINE struct cmd_bin * +lp_scene_get_bin(struct lp_scene *scene, unsigned x, unsigned y) +{ + return &scene->tile[x][y]; +} + + +/** Remove all commands from a bin */ +void +lp_scene_bin_reset(struct lp_scene *scene, unsigned x, unsigned y); + + +/* Add a command to bin[x][y]. + */ +static INLINE boolean +lp_scene_bin_command( struct lp_scene *scene, + unsigned x, unsigned y, + unsigned cmd, + union lp_rast_cmd_arg arg ) +{ + struct cmd_bin *bin = lp_scene_get_bin(scene, x, y); + struct cmd_block *tail = bin->tail; + + assert(x < scene->tiles_x); + assert(y < scene->tiles_y); + assert(cmd < LP_RAST_OP_MAX); + + if (tail == NULL || tail->count == CMD_BLOCK_MAX) { + tail = lp_scene_new_cmd_block( scene, bin ); + if (!tail) { + return FALSE; + } + assert(tail->count == 0); + } + + { + unsigned i = tail->count; + tail->cmd[i] = cmd & LP_RAST_OP_MASK; + tail->arg[i] = arg; + tail->count++; + } + + return TRUE; +} + + +static INLINE boolean +lp_scene_bin_cmd_with_state( struct lp_scene *scene, + unsigned x, unsigned y, + const struct lp_rast_state *state, + unsigned cmd, + union lp_rast_cmd_arg arg ) +{ + struct cmd_bin *bin = lp_scene_get_bin(scene, x, y); + + if (state != bin->last_state) { + bin->last_state = state; + if (!lp_scene_bin_command(scene, x, y, + LP_RAST_OP_SET_STATE, + lp_rast_arg_state(state))) + return FALSE; + } + + if (!lp_scene_bin_command( scene, x, y, cmd, arg )) + return FALSE; + + return TRUE; +} + + +/* Add a command to all active bins. + */ +static INLINE boolean +lp_scene_bin_everywhere( struct lp_scene *scene, + unsigned cmd, + const union lp_rast_cmd_arg arg ) +{ + unsigned i, j; + for (i = 0; i < scene->tiles_x; i++) { + for (j = 0; j < scene->tiles_y; j++) { + if (!lp_scene_bin_command( scene, i, j, cmd, arg )) + return FALSE; + } + } + + return TRUE; +} + + +static INLINE unsigned +lp_scene_get_num_bins( const struct lp_scene *scene ) +{ + return scene->tiles_x * scene->tiles_y; +} + + +void +lp_scene_bin_iter_begin( struct lp_scene *scene ); + +struct cmd_bin * +lp_scene_bin_iter_next( struct lp_scene *scene ); + + + +/* Begin/end binning of a scene + */ +void +lp_scene_begin_binning( struct lp_scene *scene, + struct pipe_framebuffer_state *fb ); + +void +lp_scene_end_binning( struct lp_scene *scene ); + + +/* Begin/end rasterization of a scene + */ +void +lp_scene_begin_rasterization(struct lp_scene *scene); + +void +lp_scene_end_rasterization(struct lp_scene *scene ); + + + + + +#endif /* LP_BIN_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_scene_queue.c b/src/gallium/drivers/llvmpipe/lp_scene_queue.c new file mode 100644 index 0000000..975db43 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_scene_queue.c @@ -0,0 +1,124 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * Scene queue. We'll use two queues. One contains "full" scenes which + * are produced by the "setup" code. The other contains "empty" scenes + * which are produced by the "rast" code when it finishes rendering a scene. + */ + +#include "util/u_ringbuffer.h" +#include "util/u_memory.h" +#include "lp_scene_queue.h" + + + +#define MAX_SCENE_QUEUE 4 + +struct scene_packet { + struct util_packet header; + struct lp_scene *scene; +}; + +/** + * A queue of scenes + */ +struct lp_scene_queue +{ + struct util_ringbuffer *ring; +}; + + + +/** Allocate a new scene queue */ +struct lp_scene_queue * +lp_scene_queue_create(void) +{ + struct lp_scene_queue *queue = CALLOC_STRUCT(lp_scene_queue); + if (queue == NULL) + return NULL; + + queue->ring = util_ringbuffer_create( MAX_SCENE_QUEUE * + sizeof( struct scene_packet ) / 4); + if (queue->ring == NULL) + goto fail; + + return queue; + +fail: + FREE(queue); + return NULL; +} + + +/** Delete a scene queue */ +void +lp_scene_queue_destroy(struct lp_scene_queue *queue) +{ + util_ringbuffer_destroy(queue->ring); + FREE(queue); +} + + +/** Remove first lp_scene from head of queue */ +struct lp_scene * +lp_scene_dequeue(struct lp_scene_queue *queue, boolean wait) +{ + struct scene_packet packet; + enum pipe_error ret; + + packet.scene = NULL; + + ret = util_ringbuffer_dequeue(queue->ring, + &packet.header, + sizeof packet / 4, + wait ); + if (ret != PIPE_OK) + return NULL; + + return packet.scene; +} + + +/** Add an lp_scene to tail of queue */ +void +lp_scene_enqueue(struct lp_scene_queue *queue, struct lp_scene *scene) +{ + struct scene_packet packet; + + packet.header.dwords = sizeof packet / 4; + packet.header.data24 = 0; + packet.scene = scene; + + util_ringbuffer_enqueue(queue->ring, &packet.header); +} + + + + + diff --git a/src/gallium/drivers/llvmpipe/lp_scene_queue.h b/src/gallium/drivers/llvmpipe/lp_scene_queue.h new file mode 100644 index 0000000..fd7c65a --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_scene_queue.h @@ -0,0 +1,51 @@ +/************************************************************************** + * + * 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 LP_SCENE_QUEUE +#define LP_SCENE_QUEUE + +struct lp_scene_queue; +struct lp_scene; + + +struct lp_scene_queue * +lp_scene_queue_create(void); + +void +lp_scene_queue_destroy(struct lp_scene_queue *queue); + +struct lp_scene * +lp_scene_dequeue(struct lp_scene_queue *queue, boolean wait); + +void +lp_scene_enqueue(struct lp_scene_queue *queue, struct lp_scene *scene); + + + + +#endif /* LP_BIN_QUEUE */ diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c new file mode 100644 index 0000000..9459a3c --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_screen.c @@ -0,0 +1,436 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_cpu_detect.h" +#include "util/u_format.h" +#include "util/u_format_s3tc.h" +#include "pipe/p_defines.h" +#include "pipe/p_screen.h" +#include "draw/draw_context.h" + +#include "lp_texture.h" +#include "lp_fence.h" +#include "lp_jit.h" +#include "lp_screen.h" +#include "lp_context.h" +#include "lp_debug.h" +#include "lp_public.h" +#include "lp_limits.h" +#include "lp_rast.h" + +#include "state_tracker/sw_winsys.h" + +#ifdef DEBUG +int LP_DEBUG = 0; + +static const struct debug_named_value lp_debug_flags[] = { + { "pipe", DEBUG_PIPE, NULL }, + { "tgsi", DEBUG_TGSI, NULL }, + { "tex", DEBUG_TEX, NULL }, + { "setup", DEBUG_SETUP, NULL }, + { "rast", DEBUG_RAST, NULL }, + { "query", DEBUG_QUERY, NULL }, + { "screen", DEBUG_SCREEN, NULL }, + { "show_tiles", DEBUG_SHOW_TILES, NULL }, + { "show_subtiles", DEBUG_SHOW_SUBTILES, NULL }, + { "counters", DEBUG_COUNTERS, NULL }, + { "scene", DEBUG_SCENE, NULL }, + { "fence", DEBUG_FENCE, NULL }, + { "mem", DEBUG_MEM, NULL }, + { "fs", DEBUG_FS, NULL }, + DEBUG_NAMED_VALUE_END +}; +#endif + +int LP_PERF = 0; +static const struct debug_named_value lp_perf_flags[] = { + { "texmem", PERF_TEX_MEM, NULL }, + { "no_mipmap", PERF_NO_MIPMAPS, NULL }, + { "no_linear", PERF_NO_LINEAR, NULL }, + { "no_mip_linear", PERF_NO_MIP_LINEAR, NULL }, + { "no_tex", PERF_NO_TEX, NULL }, + { "no_blend", PERF_NO_BLEND, NULL }, + { "no_depth", PERF_NO_DEPTH, NULL }, + { "no_alphatest", PERF_NO_ALPHATEST, NULL }, + DEBUG_NAMED_VALUE_END +}; + + +static const char * +llvmpipe_get_vendor(struct pipe_screen *screen) +{ + return "VMware, Inc."; +} + + +static const char * +llvmpipe_get_name(struct pipe_screen *screen) +{ + return "llvmpipe"; +} + + +static int +llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param) +{ + switch (param) { + case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: + return PIPE_MAX_SAMPLERS; + case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS: + /* At this time, the draw module and llvmpipe driver only + * support vertex shader texture lookups when LLVM is enabled in + * the draw module. + */ + if (debug_get_bool_option("DRAW_USE_LLVM", TRUE)) + return PIPE_MAX_VERTEX_SAMPLERS; + else + return 0; + case PIPE_CAP_MAX_COMBINED_SAMPLERS: + return PIPE_MAX_SAMPLERS + PIPE_MAX_VERTEX_SAMPLERS; + case PIPE_CAP_NPOT_TEXTURES: + return 1; + case PIPE_CAP_TWO_SIDED_STENCIL: + return 1; + case PIPE_CAP_GLSL: + return 1; + case PIPE_CAP_SM3: + return 1; + case PIPE_CAP_ANISOTROPIC_FILTER: + return 0; + case PIPE_CAP_POINT_SPRITE: + return 1; + case PIPE_CAP_MAX_RENDER_TARGETS: + return PIPE_MAX_COLOR_BUFS; + case PIPE_CAP_OCCLUSION_QUERY: + return 1; + case PIPE_CAP_TIMER_QUERY: + return 0; + case PIPE_CAP_TEXTURE_MIRROR_CLAMP: + return 1; + case PIPE_CAP_TEXTURE_MIRROR_REPEAT: + return 1; + case PIPE_CAP_TEXTURE_SHADOW_MAP: + return 1; + case PIPE_CAP_TEXTURE_SWIZZLE: + return 1; + case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: + return LP_MAX_TEXTURE_2D_LEVELS; + case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: + return LP_MAX_TEXTURE_3D_LEVELS; + case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: + return LP_MAX_TEXTURE_2D_LEVELS; + case PIPE_CAP_BLEND_EQUATION_SEPARATE: + return 1; + case PIPE_CAP_INDEP_BLEND_ENABLE: + return 1; + case PIPE_CAP_INDEP_BLEND_FUNC: + return 0; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: + return 1; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: + return 0; + case PIPE_CAP_PRIMITIVE_RESTART: + return 1; + case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: + return 1; + case PIPE_CAP_DEPTH_CLAMP: + return 0; + default: + return 0; + } +} + +static int +llvmpipe_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shader_cap param) +{ + switch(shader) + { + case PIPE_SHADER_FRAGMENT: + return tgsi_exec_get_shader_param(param); + case PIPE_SHADER_VERTEX: + case PIPE_SHADER_GEOMETRY: + return draw_get_shader_param(shader, param); + default: + return 0; + } +} + +static float +llvmpipe_get_paramf(struct pipe_screen *screen, enum pipe_cap param) +{ + switch (param) { + case PIPE_CAP_MAX_LINE_WIDTH: + /* fall-through */ + case PIPE_CAP_MAX_LINE_WIDTH_AA: + return 255.0; /* arbitrary */ + case PIPE_CAP_MAX_POINT_WIDTH: + /* fall-through */ + case PIPE_CAP_MAX_POINT_WIDTH_AA: + return 255.0; /* arbitrary */ + case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: + return 16.0; /* not actually signficant at this time */ + case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: + return 16.0; /* arbitrary */ + case PIPE_CAP_GUARD_BAND_LEFT: + case PIPE_CAP_GUARD_BAND_TOP: + case PIPE_CAP_GUARD_BAND_RIGHT: + case PIPE_CAP_GUARD_BAND_BOTTOM: + return 0.0; + default: + assert(0); + return 0; + } +} + + +/** + * Query format support for creating a texture, drawing surface, etc. + * \param format the format to test + * \param type one of PIPE_TEXTURE, PIPE_SURFACE + */ +static boolean +llvmpipe_is_format_supported( struct pipe_screen *_screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned bind, + unsigned geom_flags ) +{ + struct llvmpipe_screen *screen = llvmpipe_screen(_screen); + struct sw_winsys *winsys = screen->winsys; + const struct util_format_description *format_desc; + + format_desc = util_format_description(format); + if (!format_desc) + return FALSE; + + assert(target == PIPE_BUFFER || + target == PIPE_TEXTURE_1D || + target == PIPE_TEXTURE_2D || + target == PIPE_TEXTURE_RECT || + target == PIPE_TEXTURE_3D || + target == PIPE_TEXTURE_CUBE); + + if (sample_count > 1) + return FALSE; + + if (bind & PIPE_BIND_RENDER_TARGET) { + if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) + return FALSE; + + if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) + return FALSE; + + if (format_desc->block.width != 1 || + format_desc->block.height != 1) + return FALSE; + } + + if (bind & PIPE_BIND_DISPLAY_TARGET) { + if(!winsys->is_displaytarget_format_supported(winsys, bind, format)) + return FALSE; + } + + if (bind & PIPE_BIND_DEPTH_STENCIL) { + if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) + return FALSE; + + if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS) + return FALSE; + + /* FIXME: Temporary restriction. See lp_state_fs.c. */ + if (format_desc->block.bits != 32) + return FALSE; + } + + if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) { + return util_format_s3tc_enabled; + } + + /* + * Everything else should be supported by u_format. + */ + return TRUE; +} + + + + +static void +llvmpipe_flush_frontbuffer(struct pipe_screen *_screen, + struct pipe_resource *resource, + unsigned level, unsigned layer, + void *context_private) +{ + struct llvmpipe_screen *screen = llvmpipe_screen(_screen); + struct sw_winsys *winsys = screen->winsys; + struct llvmpipe_resource *texture = llvmpipe_resource(resource); + + assert(texture->dt); + if (texture->dt) + winsys->displaytarget_display(winsys, texture->dt, context_private); +} + + +static void +llvmpipe_destroy_screen( struct pipe_screen *_screen ) +{ + struct llvmpipe_screen *screen = llvmpipe_screen(_screen); + struct sw_winsys *winsys = screen->winsys; + + if (screen->rast) + lp_rast_destroy(screen->rast); + + lp_jit_screen_cleanup(screen); + + if(winsys->destroy) + winsys->destroy(winsys); + + pipe_mutex_destroy(screen->rast_mutex); + + FREE(screen); +} + + + + +/** + * Fence reference counting. + */ +static void +llvmpipe_fence_reference(struct pipe_screen *screen, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + struct lp_fence **old = (struct lp_fence **) ptr; + struct lp_fence *f = (struct lp_fence *) fence; + + lp_fence_reference(old, f); +} + + +/** + * Has the fence been executed/finished? + */ +static int +llvmpipe_fence_signalled(struct pipe_screen *screen, + struct pipe_fence_handle *fence, + unsigned flag) +{ + struct lp_fence *f = (struct lp_fence *) fence; + return lp_fence_signalled(f); +} + + +/** + * Wait for the fence to finish. + */ +static int +llvmpipe_fence_finish(struct pipe_screen *screen, + struct pipe_fence_handle *fence_handle, + unsigned flag) +{ + struct lp_fence *f = (struct lp_fence *) fence_handle; + + lp_fence_wait(f); + return 0; +} + + + +/** + * Create a new pipe_screen object + * Note: we're not presently subclassing pipe_screen (no llvmpipe_screen). + */ +struct pipe_screen * +llvmpipe_create_screen(struct sw_winsys *winsys) +{ + struct llvmpipe_screen *screen; + +#ifdef PIPE_ARCH_X86 + /* require SSE2 due to LLVM PR6960. */ + util_cpu_detect(); + if (!util_cpu_caps.has_sse2) + return NULL; +#endif + + screen = CALLOC_STRUCT(llvmpipe_screen); + +#ifdef DEBUG + LP_DEBUG = debug_get_flags_option("LP_DEBUG", lp_debug_flags, 0 ); +#endif + + LP_PERF = debug_get_flags_option("LP_PERF", lp_perf_flags, 0 ); + + if (!screen) + return NULL; + + screen->winsys = winsys; + + screen->base.destroy = llvmpipe_destroy_screen; + + screen->base.get_name = llvmpipe_get_name; + screen->base.get_vendor = llvmpipe_get_vendor; + screen->base.get_param = llvmpipe_get_param; + screen->base.get_shader_param = llvmpipe_get_shader_param; + screen->base.get_paramf = llvmpipe_get_paramf; + screen->base.is_format_supported = llvmpipe_is_format_supported; + + screen->base.context_create = llvmpipe_create_context; + screen->base.flush_frontbuffer = llvmpipe_flush_frontbuffer; + screen->base.fence_reference = llvmpipe_fence_reference; + screen->base.fence_signalled = llvmpipe_fence_signalled; + screen->base.fence_finish = llvmpipe_fence_finish; + + llvmpipe_init_screen_resource_funcs(&screen->base); + + lp_jit_screen_init(screen); + + screen->num_threads = util_cpu_caps.nr_cpus > 1 ? util_cpu_caps.nr_cpus : 0; +#ifdef PIPE_OS_EMBEDDED + screen->num_threads = 0; +#endif + screen->num_threads = debug_get_num_option("LP_NUM_THREADS", screen->num_threads); + screen->num_threads = MIN2(screen->num_threads, LP_MAX_THREADS); + + screen->rast = lp_rast_create(screen->num_threads); + if (!screen->rast) { + lp_jit_screen_cleanup(screen); + FREE(screen); + return NULL; + } + pipe_mutex_init(screen->rast_mutex); + + util_format_s3tc_init(); + + return &screen->base; +} diff --git a/src/gallium/drivers/llvmpipe/lp_screen.h b/src/gallium/drivers/llvmpipe/lp_screen.h new file mode 100644 index 0000000..7f69a11 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_screen.h @@ -0,0 +1,73 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @author Jose Fonseca + * @author Keith Whitwell + */ + +#ifndef LP_SCREEN_H +#define LP_SCREEN_H + +#include "pipe/p_screen.h" +#include "pipe/p_defines.h" +#include "os/os_thread.h" +#include "gallivm/lp_bld.h" + + +struct sw_winsys; + + +struct llvmpipe_screen +{ + struct pipe_screen base; + + struct sw_winsys *winsys; + + unsigned num_threads; + + /* Increments whenever textures are modified. Contexts can track this. + */ + unsigned timestamp; + + struct lp_rasterizer *rast; + pipe_mutex rast_mutex; +}; + + + + +static INLINE struct llvmpipe_screen * +llvmpipe_screen( struct pipe_screen *pipe ) +{ + return (struct llvmpipe_screen *)pipe; +} + + + +#endif /* LP_SCREEN_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c new file mode 100644 index 0000000..7b7b272 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@ -0,0 +1,1142 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Tiling engine. + * + * Builds per-tile display lists and executes them on calls to + * lp_setup_flush(). + */ + +#include + +#include "pipe/p_defines.h" +#include "util/u_framebuffer.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_pack_color.h" +#include "lp_context.h" +#include "lp_memory.h" +#include "lp_scene.h" +#include "lp_texture.h" +#include "lp_debug.h" +#include "lp_fence.h" +#include "lp_query.h" +#include "lp_rast.h" +#include "lp_setup_context.h" +#include "lp_screen.h" +#include "lp_state.h" +#include "state_tracker/sw_winsys.h" + +#include "draw/draw_context.h" +#include "draw/draw_vbuf.h" + + +static boolean set_scene_state( struct lp_setup_context *, enum setup_state, + const char *reason); +static boolean try_update_scene_state( struct lp_setup_context *setup ); + + +static void +lp_setup_get_empty_scene(struct lp_setup_context *setup) +{ + assert(setup->scene == NULL); + + setup->scene_idx++; + setup->scene_idx %= Elements(setup->scenes); + + setup->scene = setup->scenes[setup->scene_idx]; + + if (setup->scene->fence) { + if (LP_DEBUG & DEBUG_SETUP) + debug_printf("%s: wait for scene %d\n", + __FUNCTION__, setup->scene->fence->id); + + lp_fence_wait(setup->scene->fence); + } + + lp_scene_begin_binning(setup->scene, &setup->fb); + +} + + +static void +first_triangle( struct lp_setup_context *setup, + const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4]) +{ + assert(setup->state == SETUP_ACTIVE); + lp_setup_choose_triangle( setup ); + setup->triangle( setup, v0, v1, v2 ); +} + +static void +first_line( struct lp_setup_context *setup, + const float (*v0)[4], + const float (*v1)[4]) +{ + assert(setup->state == SETUP_ACTIVE); + lp_setup_choose_line( setup ); + setup->line( setup, v0, v1 ); +} + +static void +first_point( struct lp_setup_context *setup, + const float (*v0)[4]) +{ + assert(setup->state == SETUP_ACTIVE); + lp_setup_choose_point( setup ); + setup->point( setup, v0 ); +} + +void lp_setup_reset( struct lp_setup_context *setup ) +{ + LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); + + /* Reset derived state */ + setup->constants.stored_size = 0; + setup->constants.stored_data = NULL; + setup->fs.stored = NULL; + setup->dirty = ~0; + + /* no current bin */ + setup->scene = NULL; + + /* Reset some state: + */ + memset(&setup->clear, 0, sizeof setup->clear); + + /* Have an explicit "start-binning" call and get rid of this + * pointer twiddling? + */ + setup->line = first_line; + setup->point = first_point; + setup->triangle = first_triangle; +} + + +/** Rasterize all scene's bins */ +static void +lp_setup_rasterize_scene( struct lp_setup_context *setup ) +{ + struct lp_scene *scene = setup->scene; + struct llvmpipe_screen *screen = llvmpipe_screen(scene->pipe->screen); + + lp_scene_end_binning(scene); + + lp_fence_reference(&setup->last_fence, scene->fence); + + if (setup->last_fence) + setup->last_fence->issued = TRUE; + + pipe_mutex_lock(screen->rast_mutex); + lp_rast_queue_scene(screen->rast, scene); + lp_rast_finish(screen->rast); + pipe_mutex_unlock(screen->rast_mutex); + + lp_scene_end_rasterization(setup->scene); + lp_setup_reset( setup ); + + LP_DBG(DEBUG_SETUP, "%s done \n", __FUNCTION__); +} + + + +static boolean +begin_binning( struct lp_setup_context *setup ) +{ + struct lp_scene *scene = setup->scene; + boolean need_zsload = FALSE; + boolean ok; + unsigned i, j; + + assert(scene); + assert(scene->fence == NULL); + + /* Always create a fence: + */ + scene->fence = lp_fence_create(MAX2(1, setup->num_threads)); + if (!scene->fence) + return FALSE; + + /* Initialize the bin flags and x/y coords: + */ + for (i = 0; i < scene->tiles_x; i++) { + for (j = 0; j < scene->tiles_y; j++) { + scene->tile[i][j].x = i; + scene->tile[i][j].y = j; + } + } + + ok = try_update_scene_state(setup); + if (!ok) + return FALSE; + + if (setup->fb.zsbuf && + ((setup->clear.flags & PIPE_CLEAR_DEPTHSTENCIL) != PIPE_CLEAR_DEPTHSTENCIL) && + util_format_is_depth_and_stencil(setup->fb.zsbuf->format)) + need_zsload = TRUE; + + LP_DBG(DEBUG_SETUP, "%s color: %s depth: %s\n", __FUNCTION__, + (setup->clear.flags & PIPE_CLEAR_COLOR) ? "clear": "load", + need_zsload ? "clear": "load"); + + if (setup->fb.nr_cbufs) { + if (setup->clear.flags & PIPE_CLEAR_COLOR) { + ok = lp_scene_bin_everywhere( scene, + LP_RAST_OP_CLEAR_COLOR, + setup->clear.color ); + if (!ok) + return FALSE; + } + } + + if (setup->fb.zsbuf) { + if (setup->clear.flags & PIPE_CLEAR_DEPTHSTENCIL) { + if (!need_zsload) + scene->has_depthstencil_clear = TRUE; + + ok = lp_scene_bin_everywhere( scene, + LP_RAST_OP_CLEAR_ZSTENCIL, + lp_rast_arg_clearzs( + setup->clear.zsvalue, + setup->clear.zsmask)); + if (!ok) + return FALSE; + } + } + + if (setup->active_query) { + ok = lp_scene_bin_everywhere( scene, + LP_RAST_OP_BEGIN_QUERY, + lp_rast_arg_query(setup->active_query) ); + if (!ok) + return FALSE; + } + + setup->clear.flags = 0; + setup->clear.zsmask = 0; + setup->clear.zsvalue = 0; + + LP_DBG(DEBUG_SETUP, "%s done\n", __FUNCTION__); + return TRUE; +} + + +/* This basically bins and then flushes any outstanding full-screen + * clears. + * + * TODO: fast path for fullscreen clears and no triangles. + */ +static boolean +execute_clears( struct lp_setup_context *setup ) +{ + LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); + + return begin_binning( setup ); +} + +const char *states[] = { + "FLUSHED", + "CLEARED", + "ACTIVE " +}; + + +static boolean +set_scene_state( struct lp_setup_context *setup, + enum setup_state new_state, + const char *reason) +{ + unsigned old_state = setup->state; + + if (old_state == new_state) + return TRUE; + + if (LP_DEBUG & DEBUG_SCENE) { + debug_printf("%s old %s new %s%s%s\n", + __FUNCTION__, + states[old_state], + states[new_state], + (new_state == SETUP_FLUSHED) ? ": " : "", + (new_state == SETUP_FLUSHED) ? reason : ""); + + if (new_state == SETUP_FLUSHED && setup->scene) + lp_debug_draw_bins_by_cmd_length(setup->scene); + } + + /* wait for a free/empty scene + */ + if (old_state == SETUP_FLUSHED) + lp_setup_get_empty_scene(setup); + + switch (new_state) { + case SETUP_CLEARED: + break; + + case SETUP_ACTIVE: + if (!begin_binning( setup )) + goto fail; + break; + + case SETUP_FLUSHED: + if (old_state == SETUP_CLEARED) + if (!execute_clears( setup )) + goto fail; + + lp_setup_rasterize_scene( setup ); + assert(setup->scene == NULL); + break; + + default: + assert(0 && "invalid setup state mode"); + goto fail; + } + + setup->state = new_state; + return TRUE; + +fail: + if (setup->scene) { + lp_scene_end_rasterization(setup->scene); + setup->scene = NULL; + } + + setup->state = SETUP_FLUSHED; + lp_setup_reset( setup ); + return FALSE; +} + + +/** + * \param flags bitmask of PIPE_FLUSH_x flags + */ +void +lp_setup_flush( struct lp_setup_context *setup, + unsigned flags, + struct pipe_fence_handle **fence, + const char *reason) +{ + set_scene_state( setup, SETUP_FLUSHED, reason ); + + if (fence) { + lp_fence_reference((struct lp_fence **)fence, setup->last_fence); + } +} + + +void +lp_setup_bind_framebuffer( struct lp_setup_context *setup, + const struct pipe_framebuffer_state *fb ) +{ + LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); + + /* Flush any old scene. + */ + set_scene_state( setup, SETUP_FLUSHED, __FUNCTION__ ); + + /* + * Ensure the old scene is not reused. + */ + assert(!setup->scene); + + /* Set new state. This will be picked up later when we next need a + * scene. + */ + util_copy_framebuffer_state(&setup->fb, fb); + setup->framebuffer.x0 = 0; + setup->framebuffer.y0 = 0; + setup->framebuffer.x1 = fb->width-1; + setup->framebuffer.y1 = fb->height-1; + setup->dirty |= LP_SETUP_NEW_SCISSOR; +} + + +static boolean +lp_setup_try_clear( struct lp_setup_context *setup, + const float *color, + double depth, + unsigned stencil, + unsigned flags ) +{ + uint32_t zsmask = 0; + uint32_t zsvalue = 0; + union lp_rast_cmd_arg color_arg; + unsigned i; + + LP_DBG(DEBUG_SETUP, "%s state %d\n", __FUNCTION__, setup->state); + + if (flags & PIPE_CLEAR_COLOR) { + for (i = 0; i < 4; i++) + color_arg.clear_color[i] = float_to_ubyte(color[i]); + } + + if (flags & PIPE_CLEAR_DEPTHSTENCIL) { + uint32_t zmask = (flags & PIPE_CLEAR_DEPTH) ? ~0 : 0; + uint32_t smask = (flags & PIPE_CLEAR_STENCIL) ? ~0 : 0; + + zsvalue = util_pack_z_stencil(setup->fb.zsbuf->format, + depth, + stencil); + + + zsmask = util_pack_mask_z_stencil(setup->fb.zsbuf->format, + zmask, + smask); + + zsvalue &= zsmask; + } + + if (setup->state == SETUP_ACTIVE) { + struct lp_scene *scene = setup->scene; + + /* Add the clear to existing scene. In the unusual case where + * both color and depth-stencil are being cleared when there's + * already been some rendering, we could discard the currently + * binned scene and start again, but I don't see that as being + * a common usage. + */ + if (flags & PIPE_CLEAR_COLOR) { + if (!lp_scene_bin_everywhere( scene, + LP_RAST_OP_CLEAR_COLOR, + color_arg )) + return FALSE; + } + + if (flags & PIPE_CLEAR_DEPTHSTENCIL) { + if (!lp_scene_bin_everywhere( scene, + LP_RAST_OP_CLEAR_ZSTENCIL, + lp_rast_arg_clearzs(zsvalue, zsmask) )) + return FALSE; + } + } + else { + /* Put ourselves into the 'pre-clear' state, specifically to try + * and accumulate multiple clears to color and depth_stencil + * buffers which the app or state-tracker might issue + * separately. + */ + set_scene_state( setup, SETUP_CLEARED, __FUNCTION__ ); + + setup->clear.flags |= flags; + + if (flags & PIPE_CLEAR_DEPTHSTENCIL) { + setup->clear.zsmask |= zsmask; + setup->clear.zsvalue = + (setup->clear.zsvalue & ~zsmask) | (zsvalue & zsmask); + } + + if (flags & PIPE_CLEAR_COLOR) { + memcpy(setup->clear.color.clear_color, + &color_arg, + sizeof setup->clear.color.clear_color); + } + } + + return TRUE; +} + +void +lp_setup_clear( struct lp_setup_context *setup, + const float *color, + double depth, + unsigned stencil, + unsigned flags ) +{ + if (!lp_setup_try_clear( setup, color, depth, stencil, flags )) { + lp_setup_flush(setup, 0, NULL, __FUNCTION__); + + if (!lp_setup_try_clear( setup, color, depth, stencil, flags )) + assert(0); + } +} + + + + + +void +lp_setup_set_triangle_state( struct lp_setup_context *setup, + unsigned cull_mode, + boolean ccw_is_frontface, + boolean scissor, + boolean gl_rasterization_rules) +{ + LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); + + setup->ccw_is_frontface = ccw_is_frontface; + setup->cullmode = cull_mode; + setup->triangle = first_triangle; + setup->pixel_offset = gl_rasterization_rules ? 0.5f : 0.0f; + + if (setup->scissor_test != scissor) { + setup->dirty |= LP_SETUP_NEW_SCISSOR; + setup->scissor_test = scissor; + } +} + +void +lp_setup_set_line_state( struct lp_setup_context *setup, + float line_width) +{ + LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); + + setup->line_width = line_width; +} + +void +lp_setup_set_point_state( struct lp_setup_context *setup, + float point_size, + boolean point_size_per_vertex, + uint sprite_coord_enable, + uint sprite_coord_origin) +{ + LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); + + setup->point_size = point_size; + setup->sprite_coord_enable = sprite_coord_enable; + setup->sprite_coord_origin = sprite_coord_origin; + setup->point_size_per_vertex = point_size_per_vertex; +} + +void +lp_setup_set_setup_variant( struct lp_setup_context *setup, + const struct lp_setup_variant *variant) +{ + LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); + + setup->setup.variant = variant; +} + +void +lp_setup_set_fs_variant( struct lp_setup_context *setup, + struct lp_fragment_shader_variant *variant) +{ + LP_DBG(DEBUG_SETUP, "%s %p\n", __FUNCTION__, + variant); + /* FIXME: reference count */ + + setup->fs.current.variant = variant; + setup->dirty |= LP_SETUP_NEW_FS; +} + +void +lp_setup_set_fs_constants(struct lp_setup_context *setup, + struct pipe_resource *buffer) +{ + LP_DBG(DEBUG_SETUP, "%s %p\n", __FUNCTION__, (void *) buffer); + + pipe_resource_reference(&setup->constants.current, buffer); + + setup->dirty |= LP_SETUP_NEW_CONSTANTS; +} + + +void +lp_setup_set_alpha_ref_value( struct lp_setup_context *setup, + float alpha_ref_value ) +{ + LP_DBG(DEBUG_SETUP, "%s %f\n", __FUNCTION__, alpha_ref_value); + + if(setup->fs.current.jit_context.alpha_ref_value != alpha_ref_value) { + setup->fs.current.jit_context.alpha_ref_value = alpha_ref_value; + setup->dirty |= LP_SETUP_NEW_FS; + } +} + +void +lp_setup_set_stencil_ref_values( struct lp_setup_context *setup, + const ubyte refs[2] ) +{ + LP_DBG(DEBUG_SETUP, "%s %d %d\n", __FUNCTION__, refs[0], refs[1]); + + if (setup->fs.current.jit_context.stencil_ref_front != refs[0] || + setup->fs.current.jit_context.stencil_ref_back != refs[1]) { + setup->fs.current.jit_context.stencil_ref_front = refs[0]; + setup->fs.current.jit_context.stencil_ref_back = refs[1]; + setup->dirty |= LP_SETUP_NEW_FS; + } +} + +void +lp_setup_set_blend_color( struct lp_setup_context *setup, + const struct pipe_blend_color *blend_color ) +{ + LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); + + assert(blend_color); + + if(memcmp(&setup->blend_color.current, blend_color, sizeof *blend_color) != 0) { + memcpy(&setup->blend_color.current, blend_color, sizeof *blend_color); + setup->dirty |= LP_SETUP_NEW_BLEND_COLOR; + } +} + + +void +lp_setup_set_scissor( struct lp_setup_context *setup, + const struct pipe_scissor_state *scissor ) +{ + LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); + + assert(scissor); + + setup->scissor.x0 = scissor->minx; + setup->scissor.x1 = scissor->maxx-1; + setup->scissor.y0 = scissor->miny; + setup->scissor.y1 = scissor->maxy-1; + setup->dirty |= LP_SETUP_NEW_SCISSOR; +} + + +void +lp_setup_set_flatshade_first( struct lp_setup_context *setup, + boolean flatshade_first ) +{ + setup->flatshade_first = flatshade_first; +} + + +void +lp_setup_set_vertex_info( struct lp_setup_context *setup, + struct vertex_info *vertex_info ) +{ + /* XXX: just silently holding onto the pointer: + */ + setup->vertex_info = vertex_info; +} + + +/** + * Called during state validation when LP_NEW_SAMPLER_VIEW is set. + */ +void +lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup, + unsigned num, + struct pipe_sampler_view **views) +{ + unsigned i; + + LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); + + assert(num <= PIPE_MAX_SAMPLERS); + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + struct pipe_sampler_view *view = i < num ? views[i] : NULL; + + if (view) { + struct pipe_resource *tex = view->texture; + struct llvmpipe_resource *lp_tex = llvmpipe_resource(tex); + struct lp_jit_texture *jit_tex; + jit_tex = &setup->fs.current.jit_context.textures[i]; + jit_tex->width = tex->width0; + jit_tex->height = tex->height0; + jit_tex->depth = tex->depth0; + jit_tex->last_level = tex->last_level; + + /* We're referencing the texture's internal data, so save a + * reference to it. + */ + pipe_resource_reference(&setup->fs.current_tex[i], tex); + + if (!lp_tex->dt) { + /* regular texture - setup array of mipmap level pointers */ + int j; + for (j = 0; j <= tex->last_level; j++) { + jit_tex->data[j] = + llvmpipe_get_texture_image_all(lp_tex, j, LP_TEX_USAGE_READ, + LP_TEX_LAYOUT_LINEAR); + jit_tex->row_stride[j] = lp_tex->row_stride[j]; + jit_tex->img_stride[j] = lp_tex->img_stride[j]; + + if ((LP_PERF & PERF_TEX_MEM) || + !jit_tex->data[j]) { + /* out of memory - use dummy tile memory */ + jit_tex->data[j] = lp_dummy_tile; + jit_tex->width = TILE_SIZE/8; + jit_tex->height = TILE_SIZE/8; + jit_tex->depth = 1; + jit_tex->last_level = 0; + jit_tex->row_stride[j] = 0; + jit_tex->img_stride[j] = 0; + } + } + } + else { + /* display target texture/surface */ + /* + * XXX: Where should this be unmapped? + */ + struct llvmpipe_screen *screen = llvmpipe_screen(tex->screen); + struct sw_winsys *winsys = screen->winsys; + jit_tex->data[0] = winsys->displaytarget_map(winsys, lp_tex->dt, + PIPE_TRANSFER_READ); + jit_tex->row_stride[0] = lp_tex->row_stride[0]; + jit_tex->img_stride[0] = lp_tex->img_stride[0]; + assert(jit_tex->data[0]); + } + } + } + + setup->dirty |= LP_SETUP_NEW_FS; +} + + +/** + * Called during state validation when LP_NEW_SAMPLER is set. + */ +void +lp_setup_set_fragment_sampler_state(struct lp_setup_context *setup, + unsigned num, + const struct pipe_sampler_state **samplers) +{ + unsigned i; + + LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); + + assert(num <= PIPE_MAX_SAMPLERS); + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + const struct pipe_sampler_state *sampler = i < num ? samplers[i] : NULL; + + if (sampler) { + struct lp_jit_texture *jit_tex; + jit_tex = &setup->fs.current.jit_context.textures[i]; + + jit_tex->min_lod = sampler->min_lod; + jit_tex->max_lod = sampler->max_lod; + jit_tex->lod_bias = sampler->lod_bias; + COPY_4V(jit_tex->border_color, sampler->border_color); + } + } + + setup->dirty |= LP_SETUP_NEW_FS; +} + + +/** + * Is the given texture referenced by any scene? + * Note: we have to check all scenes including any scenes currently + * being rendered and the current scene being built. + */ +unsigned +lp_setup_is_resource_referenced( const struct lp_setup_context *setup, + const struct pipe_resource *texture ) +{ + unsigned i; + + /* check the render targets */ + for (i = 0; i < setup->fb.nr_cbufs; i++) { + if (setup->fb.cbufs[i]->texture == texture) + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; + } + if (setup->fb.zsbuf && setup->fb.zsbuf->texture == texture) { + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; + } + + /* check textures referenced by the scene */ + for (i = 0; i < Elements(setup->scenes); i++) { + if (lp_scene_is_resource_referenced(setup->scenes[i], texture)) { + return PIPE_REFERENCED_FOR_READ; + } + } + + return PIPE_UNREFERENCED; +} + + +/** + * Called by vbuf code when we're about to draw something. + */ +static boolean +try_update_scene_state( struct lp_setup_context *setup ) +{ + boolean new_scene = (setup->fs.stored == NULL); + struct lp_scene *scene = setup->scene; + + assert(scene); + + if(setup->dirty & LP_SETUP_NEW_BLEND_COLOR) { + uint8_t *stored; + unsigned i, j; + + stored = lp_scene_alloc_aligned(scene, 4 * 16, 16); + if (!stored) { + assert(!new_scene); + return FALSE; + } + + /* smear each blend color component across 16 ubyte elements */ + for (i = 0; i < 4; ++i) { + uint8_t c = float_to_ubyte(setup->blend_color.current.color[i]); + for (j = 0; j < 16; ++j) + stored[i*16 + j] = c; + } + + setup->blend_color.stored = stored; + setup->fs.current.jit_context.blend_color = setup->blend_color.stored; + setup->dirty |= LP_SETUP_NEW_FS; + } + + if(setup->dirty & LP_SETUP_NEW_CONSTANTS) { + struct pipe_resource *buffer = setup->constants.current; + + if(buffer) { + unsigned current_size = buffer->width0; + const void *current_data = llvmpipe_resource_data(buffer); + + /* TODO: copy only the actually used constants? */ + + if(setup->constants.stored_size != current_size || + !setup->constants.stored_data || + memcmp(setup->constants.stored_data, + current_data, + current_size) != 0) { + void *stored; + + stored = lp_scene_alloc(scene, current_size); + if (!stored) { + assert(!new_scene); + return FALSE; + } + + memcpy(stored, + current_data, + current_size); + setup->constants.stored_size = current_size; + setup->constants.stored_data = stored; + } + } + else { + setup->constants.stored_size = 0; + setup->constants.stored_data = NULL; + } + + setup->fs.current.jit_context.constants = setup->constants.stored_data; + setup->dirty |= LP_SETUP_NEW_FS; + } + + + if (setup->dirty & LP_SETUP_NEW_FS) { + if (!setup->fs.stored || + memcmp(setup->fs.stored, + &setup->fs.current, + sizeof setup->fs.current) != 0) + { + struct lp_rast_state *stored; + uint i; + + /* The fs state that's been stored in the scene is different from + * the new, current state. So allocate a new lp_rast_state object + * and append it to the bin's setup data buffer. + */ + stored = (struct lp_rast_state *) lp_scene_alloc(scene, sizeof *stored); + if (!stored) { + assert(!new_scene); + return FALSE; + } + + memcpy(stored, + &setup->fs.current, + sizeof setup->fs.current); + setup->fs.stored = stored; + + /* The scene now references the textures in the rasterization + * state record. Note that now. + */ + for (i = 0; i < Elements(setup->fs.current_tex); i++) { + if (setup->fs.current_tex[i]) { + if (!lp_scene_add_resource_reference(scene, + setup->fs.current_tex[i], + new_scene)) { + assert(!new_scene); + return FALSE; + } + } + } + } + } + + if (setup->dirty & LP_SETUP_NEW_SCISSOR) { + setup->draw_region = setup->framebuffer; + if (setup->scissor_test) { + u_rect_possible_intersection(&setup->scissor, + &setup->draw_region); + } + } + + setup->dirty = 0; + + assert(setup->fs.stored); + return TRUE; +} + +boolean +lp_setup_update_state( struct lp_setup_context *setup, + boolean update_scene ) +{ + /* Some of the 'draw' pipeline stages may have changed some driver state. + * Make sure we've processed those state changes before anything else. + * + * XXX this is the only place where llvmpipe_context is used in the + * setup code. This may get refactored/changed... + */ + { + struct llvmpipe_context *lp = llvmpipe_context(setup->pipe); + if (lp->dirty) { + llvmpipe_update_derived(lp); + } + + if (lp->setup->dirty) { + llvmpipe_update_setup(lp); + } + + assert(setup->setup.variant); + + /* Will probably need to move this somewhere else, just need + * to know about vertex shader point size attribute. + */ + setup->psize = lp->psize_slot; + + assert(lp->dirty == 0); + + assert(lp->setup_variant.key.size == + setup->setup.variant->key.size); + + assert(memcmp(&lp->setup_variant.key, + &setup->setup.variant->key, + setup->setup.variant->key.size) == 0); + } + + if (update_scene && setup->state != SETUP_ACTIVE) { + if (!set_scene_state( setup, SETUP_ACTIVE, __FUNCTION__ )) + return FALSE; + } + + /* Only call into update_scene_state() if we already have a + * scene: + */ + if (update_scene && setup->scene) { + assert(setup->state == SETUP_ACTIVE); + + if (try_update_scene_state(setup)) + return TRUE; + + /* Update failed, try to restart the scene. + * + * Cannot call lp_setup_flush_and_restart() directly here + * because of potential recursion. + */ + if (!set_scene_state(setup, SETUP_FLUSHED, __FUNCTION__)) + return FALSE; + + if (!set_scene_state(setup, SETUP_ACTIVE, __FUNCTION__)) + return FALSE; + + if (!setup->scene) + return FALSE; + + return try_update_scene_state(setup); + } + + return TRUE; +} + + + +/* Only caller is lp_setup_vbuf_destroy() + */ +void +lp_setup_destroy( struct lp_setup_context *setup ) +{ + uint i; + + lp_setup_reset( setup ); + + util_unreference_framebuffer_state(&setup->fb); + + for (i = 0; i < Elements(setup->fs.current_tex); i++) { + pipe_resource_reference(&setup->fs.current_tex[i], NULL); + } + + pipe_resource_reference(&setup->constants.current, NULL); + + /* free the scenes in the 'empty' queue */ + for (i = 0; i < Elements(setup->scenes); i++) { + struct lp_scene *scene = setup->scenes[i]; + + if (scene->fence) + lp_fence_wait(scene->fence); + + lp_scene_destroy(scene); + } + + lp_fence_reference(&setup->last_fence, NULL); + + FREE( setup ); +} + + +/** + * Create a new primitive tiling engine. Plug it into the backend of + * the draw module. Currently also creates a rasterizer to use with + * it. + */ +struct lp_setup_context * +lp_setup_create( struct pipe_context *pipe, + struct draw_context *draw ) +{ + struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen); + struct lp_setup_context *setup = CALLOC_STRUCT(lp_setup_context); + unsigned i; + + if (!setup) + return NULL; + + lp_setup_init_vbuf(setup); + + /* Used only in update_state(): + */ + setup->pipe = pipe; + + + setup->num_threads = screen->num_threads; + setup->vbuf = draw_vbuf_stage(draw, &setup->base); + if (!setup->vbuf) + goto fail; + + draw_set_rasterize_stage(draw, setup->vbuf); + draw_set_render(draw, &setup->base); + + /* create some empty scenes */ + for (i = 0; i < MAX_SCENES; i++) { + setup->scenes[i] = lp_scene_create( pipe ); + } + + setup->triangle = first_triangle; + setup->line = first_line; + setup->point = first_point; + + setup->dirty = ~0; + + return setup; + +fail: + if (setup->vbuf) + ; + + FREE(setup); + return NULL; +} + + +/** + * Put a BeginQuery command into all bins. + */ +void +lp_setup_begin_query(struct lp_setup_context *setup, + struct llvmpipe_query *pq) +{ + /* init the query to its beginning state */ + assert(setup->active_query == NULL); + + set_scene_state(setup, SETUP_ACTIVE, "begin_query"); + + if (setup->scene) { + if (!lp_scene_bin_everywhere(setup->scene, + LP_RAST_OP_BEGIN_QUERY, + lp_rast_arg_query(pq))) { + + if (!lp_setup_flush_and_restart(setup)) + return; + + if (!lp_scene_bin_everywhere(setup->scene, + LP_RAST_OP_BEGIN_QUERY, + lp_rast_arg_query(pq))) { + return; + } + } + } + + setup->active_query = pq; +} + + +/** + * Put an EndQuery command into all bins. + */ +void +lp_setup_end_query(struct lp_setup_context *setup, struct llvmpipe_query *pq) +{ + union lp_rast_cmd_arg dummy = { 0 }; + + set_scene_state(setup, SETUP_ACTIVE, "end_query"); + + assert(setup->active_query == pq); + setup->active_query = NULL; + + /* Setup will automatically re-issue any query which carried over a + * scene boundary, and the rasterizer automatically "ends" queries + * which are active at the end of a scene, so there is no need to + * retry this commands on failure. + */ + if (setup->scene) { + /* pq->fence should be the fence of the *last* scene which + * contributed to the query result. + */ + lp_fence_reference(&pq->fence, setup->scene->fence); + + if (!lp_scene_bin_everywhere(setup->scene, + LP_RAST_OP_END_QUERY, + dummy)) { + lp_setup_flush(setup, 0, NULL, __FUNCTION__); + } + } + else { + lp_fence_reference(&pq->fence, setup->last_fence); + } +} + + +boolean +lp_setup_flush_and_restart(struct lp_setup_context *setup) +{ + if (0) debug_printf("%s\n", __FUNCTION__); + + assert(setup->state == SETUP_ACTIVE); + + if (!set_scene_state(setup, SETUP_FLUSHED, __FUNCTION__)) + return FALSE; + + if (!lp_setup_update_state(setup, TRUE)) + return FALSE; + + return TRUE; +} + + diff --git a/src/gallium/drivers/llvmpipe/lp_setup.h b/src/gallium/drivers/llvmpipe/lp_setup.h new file mode 100644 index 0000000..0d6e161 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_setup.h @@ -0,0 +1,153 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +#ifndef LP_SETUP_H +#define LP_SETUP_H + +#include "pipe/p_compiler.h" +#include "lp_jit.h" + +struct draw_context; +struct vertex_info; + + +struct pipe_resource; +struct pipe_query; +struct pipe_surface; +struct pipe_blend_color; +struct pipe_screen; +struct pipe_framebuffer_state; +struct lp_fragment_shader_variant; +struct lp_jit_context; +struct llvmpipe_query; +struct pipe_fence_handle; +struct lp_setup_variant; +struct lp_setup_context; + +void lp_setup_reset( struct lp_setup_context *setup ); + +struct lp_setup_context * +lp_setup_create( struct pipe_context *pipe, + struct draw_context *draw ); + +void +lp_setup_clear(struct lp_setup_context *setup, + const float *clear_color, + double clear_depth, + unsigned clear_stencil, + unsigned flags); + + + +void +lp_setup_flush( struct lp_setup_context *setup, + unsigned flags, + struct pipe_fence_handle **fence, + const char *reason); + + +void +lp_setup_bind_framebuffer( struct lp_setup_context *setup, + const struct pipe_framebuffer_state *fb ); + +void +lp_setup_set_triangle_state( struct lp_setup_context *setup, + unsigned cullmode, + boolean front_is_ccw, + boolean scissor, + boolean gl_rasterization_rules ); + +void +lp_setup_set_line_state( struct lp_setup_context *setup, + float line_width); + +void +lp_setup_set_point_state( struct lp_setup_context *setup, + float point_size, + boolean point_size_per_vertex, + uint sprite_coord_enable, + uint sprite_coord_origin); + +void +lp_setup_set_setup_variant( struct lp_setup_context *setup, + const struct lp_setup_variant *variant ); + +void +lp_setup_set_fs_variant( struct lp_setup_context *setup, + struct lp_fragment_shader_variant *variant ); + +void +lp_setup_set_fs_constants(struct lp_setup_context *setup, + struct pipe_resource *buffer); + + +void +lp_setup_set_alpha_ref_value( struct lp_setup_context *setup, + float alpha_ref_value ); + +void +lp_setup_set_stencil_ref_values( struct lp_setup_context *setup, + const ubyte refs[2] ); + +void +lp_setup_set_blend_color( struct lp_setup_context *setup, + const struct pipe_blend_color *blend_color ); + +void +lp_setup_set_scissor( struct lp_setup_context *setup, + const struct pipe_scissor_state *scissor ); + +void +lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup, + unsigned num, + struct pipe_sampler_view **views); + +void +lp_setup_set_fragment_sampler_state(struct lp_setup_context *setup, + unsigned num, + const struct pipe_sampler_state **samplers); + +unsigned +lp_setup_is_resource_referenced( const struct lp_setup_context *setup, + const struct pipe_resource *texture ); + +void +lp_setup_set_flatshade_first( struct lp_setup_context *setup, + boolean flatshade_first ); + +void +lp_setup_set_vertex_info( struct lp_setup_context *setup, + struct vertex_info *info ); + +void +lp_setup_begin_query(struct lp_setup_context *setup, + struct llvmpipe_query *pq); + +void +lp_setup_end_query(struct lp_setup_context *setup, + struct llvmpipe_query *pq); + +#endif diff --git a/src/gallium/drivers/llvmpipe/lp_setup_context.h b/src/gallium/drivers/llvmpipe/lp_setup_context.h new file mode 100644 index 0000000..dc2533b --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_setup_context.h @@ -0,0 +1,198 @@ +/************************************************************************** + * + * Copyright 2007-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. + * + **************************************************************************/ + + +/** + * The setup code is concerned with point/line/triangle setup and + * putting commands/data into the bins. + */ + + +#ifndef LP_SETUP_CONTEXT_H +#define LP_SETUP_CONTEXT_H + +#include "lp_setup.h" +#include "lp_rast.h" +#include "lp_tile_soa.h" /* for TILE_SIZE */ +#include "lp_scene.h" +#include "lp_bld_interp.h" /* for struct lp_shader_input */ + +#include "draw/draw_vbuf.h" +#include "util/u_rect.h" + +#define LP_SETUP_NEW_FS 0x01 +#define LP_SETUP_NEW_CONSTANTS 0x02 +#define LP_SETUP_NEW_BLEND_COLOR 0x04 +#define LP_SETUP_NEW_SCISSOR 0x08 + + +struct lp_setup_variant; + + +/** Max number of scenes */ +#define MAX_SCENES 2 + + + +/** + * Point/line/triangle setup context. + * Note: "stored" below indicates data which is stored in the bins, + * not arbitrary malloc'd memory. + * + * + * Subclass of vbuf_render, plugged directly into the draw module as + * the rendering backend. + */ +struct lp_setup_context +{ + struct vbuf_render base; + + struct pipe_context *pipe; + struct vertex_info *vertex_info; + uint prim; + uint vertex_size; + uint nr_vertices; + uint sprite_coord_enable, sprite_coord_origin; + uint vertex_buffer_size; + void *vertex_buffer; + + /* Final pipeline stage for draw module. Draw module should + * create/install this itself now. + */ + struct draw_stage *vbuf; + unsigned num_threads; + unsigned scene_idx; + struct lp_scene *scenes[MAX_SCENES]; /**< all the scenes */ + struct lp_scene *scene; /**< current scene being built */ + + struct lp_fence *last_fence; + struct llvmpipe_query *active_query; + + boolean flatshade_first; + boolean ccw_is_frontface; + boolean scissor_test; + boolean point_size_per_vertex; + unsigned cullmode; + float pixel_offset; + float line_width; + float point_size; + float psize; + + struct pipe_framebuffer_state fb; + struct u_rect framebuffer; + struct u_rect scissor; + struct u_rect draw_region; /* intersection of fb & scissor */ + + struct { + unsigned flags; + union lp_rast_cmd_arg color; /**< lp_rast_clear_color() cmd */ + unsigned zsmask; + unsigned zsvalue; /**< lp_rast_clear_zstencil() cmd */ + } clear; + + enum setup_state { + SETUP_FLUSHED, /**< scene is null */ + SETUP_CLEARED, /**< scene exists but has only clears */ + SETUP_ACTIVE /**< scene exists and has at least one draw/query */ + } state; + + struct { + const struct lp_rast_state *stored; /**< what's in the scene */ + struct lp_rast_state current; /**< currently set state */ + struct pipe_resource *current_tex[PIPE_MAX_SAMPLERS]; + } fs; + + /** fragment shader constants */ + struct { + struct pipe_resource *current; + unsigned stored_size; + const void *stored_data; + } constants; + + struct { + struct pipe_blend_color current; + uint8_t *stored; + } blend_color; + + + struct { + const struct lp_setup_variant *variant; + } setup; + + unsigned dirty; /**< bitmask of LP_SETUP_NEW_x bits */ + + void (*point)( struct lp_setup_context *, + const float (*v0)[4]); + + void (*line)( struct lp_setup_context *, + const float (*v0)[4], + const float (*v1)[4]); + + void (*triangle)( struct lp_setup_context *, + const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4]); +}; + +void lp_setup_choose_triangle( struct lp_setup_context *setup ); +void lp_setup_choose_line( struct lp_setup_context *setup ); +void lp_setup_choose_point( struct lp_setup_context *setup ); + +void lp_setup_init_vbuf(struct lp_setup_context *setup); + +boolean lp_setup_update_state( struct lp_setup_context *setup, + boolean update_scene); + +void lp_setup_destroy( struct lp_setup_context *setup ); + +boolean lp_setup_flush_and_restart(struct lp_setup_context *setup); + +void +lp_setup_print_triangle(struct lp_setup_context *setup, + const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4]); + +void +lp_setup_print_vertex(struct lp_setup_context *setup, + const char *name, + const float (*v)[4]); + + +struct lp_rast_triangle * +lp_setup_alloc_triangle(struct lp_scene *scene, + unsigned num_inputs, + unsigned nr_planes, + unsigned *tri_size); + +boolean +lp_setup_bin_triangle( struct lp_setup_context *setup, + struct lp_rast_triangle *tri, + const struct u_rect *bbox, + int nr_planes ); + +#endif diff --git a/src/gallium/drivers/llvmpipe/lp_setup_line.c b/src/gallium/drivers/llvmpipe/lp_setup_line.c new file mode 100644 index 0000000..29c2317 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_setup_line.c @@ -0,0 +1,733 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* + * Binning code for lines + */ + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "lp_perf.h" +#include "lp_setup_context.h" +#include "lp_rast.h" +#include "lp_state_fs.h" +#include "lp_state_setup.h" + +#define NUM_CHANNELS 4 + +struct lp_line_info { + + float dx; + float dy; + float oneoverarea; + + const float (*v1)[4]; + const float (*v2)[4]; + + float (*a0)[4]; + float (*dadx)[4]; + float (*dady)[4]; +}; + + +/** + * Compute a0 for a constant-valued coefficient (GL_FLAT shading). + */ +static void constant_coef( struct lp_setup_context *setup, + struct lp_line_info *info, + unsigned slot, + const float value, + unsigned i ) +{ + info->a0[slot][i] = value; + info->dadx[slot][i] = 0.0f; + info->dady[slot][i] = 0.0f; +} + + +/** + * Compute a0, dadx and dady for a linearly interpolated coefficient, + * for a triangle. + */ +static void linear_coef( struct lp_setup_context *setup, + struct lp_line_info *info, + unsigned slot, + unsigned vert_attr, + unsigned i) +{ + float a1 = info->v1[vert_attr][i]; + float a2 = info->v2[vert_attr][i]; + + float da21 = a1 - a2; + float dadx = da21 * info->dx * info->oneoverarea; + float dady = da21 * info->dy * info->oneoverarea; + + info->dadx[slot][i] = dadx; + info->dady[slot][i] = dady; + + info->a0[slot][i] = (a1 - + (dadx * (info->v1[0][0] - setup->pixel_offset) + + dady * (info->v1[0][1] - setup->pixel_offset))); +} + + +/** + * Compute a0, dadx and dady for a perspective-corrected interpolant, + * for a triangle. + * We basically multiply the vertex value by 1/w before computing + * the plane coefficients (a0, dadx, dady). + * Later, when we compute the value at a particular fragment position we'll + * divide the interpolated value by the interpolated W at that fragment. + */ +static void perspective_coef( struct lp_setup_context *setup, + struct lp_line_info *info, + unsigned slot, + unsigned vert_attr, + unsigned i) +{ + /* premultiply by 1/w (v[0][3] is always 1/w): + */ + float a1 = info->v1[vert_attr][i] * info->v1[0][3]; + float a2 = info->v2[vert_attr][i] * info->v2[0][3]; + + float da21 = a1 - a2; + float dadx = da21 * info->dx * info->oneoverarea; + float dady = da21 * info->dy * info->oneoverarea; + + info->dadx[slot][i] = dadx; + info->dady[slot][i] = dady; + + info->a0[slot][i] = (a1 - + (dadx * (info->v1[0][0] - setup->pixel_offset) + + dady * (info->v1[0][1] - setup->pixel_offset))); +} + +static void +setup_fragcoord_coef( struct lp_setup_context *setup, + struct lp_line_info *info, + unsigned slot, + unsigned usage_mask) +{ + /*X*/ + if (usage_mask & TGSI_WRITEMASK_X) { + info->a0[slot][0] = 0.0; + info->dadx[slot][0] = 1.0; + info->dady[slot][0] = 0.0; + } + + /*Y*/ + if (usage_mask & TGSI_WRITEMASK_Y) { + info->a0[slot][1] = 0.0; + info->dadx[slot][1] = 0.0; + info->dady[slot][1] = 1.0; + } + + /*Z*/ + if (usage_mask & TGSI_WRITEMASK_Z) { + linear_coef(setup, info, slot, 0, 2); + } + + /*W*/ + if (usage_mask & TGSI_WRITEMASK_W) { + linear_coef(setup, info, slot, 0, 3); + } +} + +/** + * Compute the tri->coef[] array dadx, dady, a0 values. + */ +static void setup_line_coefficients( struct lp_setup_context *setup, + struct lp_line_info *info) +{ + const struct lp_setup_variant_key *key = &setup->setup.variant->key; + unsigned fragcoord_usage_mask = TGSI_WRITEMASK_XYZ; + unsigned slot; + + /* setup interpolation for all the remaining attributes: + */ + for (slot = 0; slot < key->num_inputs; slot++) { + unsigned vert_attr = key->inputs[slot].src_index; + unsigned usage_mask = key->inputs[slot].usage_mask; + unsigned i; + + switch (key->inputs[slot].interp) { + case LP_INTERP_CONSTANT: + if (key->flatshade_first) { + for (i = 0; i < NUM_CHANNELS; i++) + if (usage_mask & (1 << i)) + constant_coef(setup, info, slot+1, info->v1[vert_attr][i], i); + } + else { + for (i = 0; i < NUM_CHANNELS; i++) + if (usage_mask & (1 << i)) + constant_coef(setup, info, slot+1, info->v2[vert_attr][i], i); + } + break; + + case LP_INTERP_LINEAR: + for (i = 0; i < NUM_CHANNELS; i++) + if (usage_mask & (1 << i)) + linear_coef(setup, info, slot+1, vert_attr, i); + break; + + case LP_INTERP_PERSPECTIVE: + for (i = 0; i < NUM_CHANNELS; i++) + if (usage_mask & (1 << i)) + perspective_coef(setup, info, slot+1, vert_attr, i); + fragcoord_usage_mask |= TGSI_WRITEMASK_W; + break; + + case LP_INTERP_POSITION: + /* + * The generated pixel interpolators will pick up the coeffs from + * slot 0, so all need to ensure that the usage mask is covers all + * usages. + */ + fragcoord_usage_mask |= usage_mask; + break; + + case LP_INTERP_FACING: + for (i = 0; i < NUM_CHANNELS; i++) + if (usage_mask & (1 << i)) + constant_coef(setup, info, slot+1, 1.0, i); + break; + + default: + assert(0); + } + } + + /* The internal position input is in slot zero: + */ + setup_fragcoord_coef(setup, info, 0, + fragcoord_usage_mask); +} + + + +static INLINE int subpixel_snap( float a ) +{ + return util_iround(FIXED_ONE * a); +} + + +/** + * Print line vertex attribs (for debug). + */ +static void +print_line(struct lp_setup_context *setup, + const float (*v1)[4], + const float (*v2)[4]) +{ + const struct lp_setup_variant_key *key = &setup->setup.variant->key; + uint i; + + debug_printf("llvmpipe line\n"); + for (i = 0; i < 1 + key->num_inputs; i++) { + debug_printf(" v1[%d]: %f %f %f %f\n", i, + v1[i][0], v1[i][1], v1[i][2], v1[i][3]); + } + for (i = 0; i < 1 + key->num_inputs; i++) { + debug_printf(" v2[%d]: %f %f %f %f\n", i, + v2[i][0], v2[i][1], v2[i][2], v2[i][3]); + } +} + + +static INLINE boolean sign(float x){ + return x >= 0; +} + + +/* Used on positive floats only: + */ +static INLINE float fracf(float f) +{ + return f - floorf(f); +} + + + +static boolean +try_setup_line( struct lp_setup_context *setup, + const float (*v1)[4], + const float (*v2)[4]) +{ + struct lp_scene *scene = setup->scene; + const struct lp_setup_variant_key *key = &setup->setup.variant->key; + struct lp_rast_triangle *line; + struct lp_rast_plane *plane; + struct lp_line_info info; + float width = MAX2(1.0, setup->line_width); + struct u_rect bbox; + unsigned tri_bytes; + int x[4]; + int y[4]; + int i; + int nr_planes = 4; + + /* linewidth should be interpreted as integer */ + int fixed_width = util_iround(width) * FIXED_ONE; + + float x_offset=0; + float y_offset=0; + float x_offset_end=0; + float y_offset_end=0; + + float x1diff; + float y1diff; + float x2diff; + float y2diff; + float dx, dy; + float area; + + boolean draw_start; + boolean draw_end; + boolean will_draw_start; + boolean will_draw_end; + + if (0) + print_line(setup, v1, v2); + + if (setup->scissor_test) { + nr_planes = 8; + } + else { + nr_planes = 4; + } + + + dx = v1[0][0] - v2[0][0]; + dy = v1[0][1] - v2[0][1]; + area = (dx * dx + dy * dy); + if (area == 0) { + LP_COUNT(nr_culled_tris); + return TRUE; + } + + info.oneoverarea = 1.0f / area; + info.dx = dx; + info.dy = dy; + info.v1 = v1; + info.v2 = v2; + + + /* X-MAJOR LINE */ + if (fabsf(dx) >= fabsf(dy)) { + float dydx = dy / dx; + + x1diff = v1[0][0] - (float) floor(v1[0][0]) - 0.5; + y1diff = v1[0][1] - (float) floor(v1[0][1]) - 0.5; + x2diff = v2[0][0] - (float) floor(v2[0][0]) - 0.5; + y2diff = v2[0][1] - (float) floor(v2[0][1]) - 0.5; + + if (y2diff==-0.5 && dy<0){ + y2diff = 0.5; + } + + /* + * Diamond exit rule test for starting point + */ + if (fabsf(x1diff) + fabsf(y1diff) < 0.5) { + draw_start = TRUE; + } + else if (sign(x1diff) == sign(-dx)) { + draw_start = FALSE; + } + else if (sign(-y1diff) != sign(dy)) { + draw_start = TRUE; + } + else { + /* do intersection test */ + float yintersect = fracf(v1[0][1]) + x1diff * dydx; + draw_start = (yintersect < 1.0 && yintersect > 0.0); + } + + + /* + * Diamond exit rule test for ending point + */ + if (fabsf(x2diff) + fabsf(y2diff) < 0.5) { + draw_end = FALSE; + } + else if (sign(x2diff) != sign(-dx)) { + draw_end = FALSE; + } + else if (sign(-y2diff) == sign(dy)) { + draw_end = TRUE; + } + else { + /* do intersection test */ + float yintersect = fracf(v2[0][1]) + x2diff * dydx; + draw_end = (yintersect < 1.0 && yintersect > 0.0); + } + + /* Are we already drawing start/end? + */ + will_draw_start = sign(-x1diff) != sign(dx); + will_draw_end = (sign(x2diff) == sign(-dx)) || x2diff==0; + + if (dx < 0) { + /* if v2 is to the right of v1, swap pointers */ + const float (*temp)[4] = v1; + v1 = v2; + v2 = temp; + dx = -dx; + dy = -dy; + /* Otherwise shift planes appropriately */ + if (will_draw_start != draw_start) { + x_offset_end = - x1diff - 0.5; + y_offset_end = x_offset_end * dydx; + + } + if (will_draw_end != draw_end) { + x_offset = - x2diff - 0.5; + y_offset = x_offset * dydx; + } + + } + else{ + /* Otherwise shift planes appropriately */ + if (will_draw_start != draw_start) { + x_offset = - x1diff + 0.5; + y_offset = x_offset * dydx; + } + if (will_draw_end != draw_end) { + x_offset_end = - x2diff + 0.5; + y_offset_end = x_offset_end * dydx; + } + } + + /* x/y positions in fixed point */ + x[0] = subpixel_snap(v1[0][0] + x_offset - setup->pixel_offset); + x[1] = subpixel_snap(v2[0][0] + x_offset_end - setup->pixel_offset); + x[2] = subpixel_snap(v2[0][0] + x_offset_end - setup->pixel_offset); + x[3] = subpixel_snap(v1[0][0] + x_offset - setup->pixel_offset); + + y[0] = subpixel_snap(v1[0][1] + y_offset - setup->pixel_offset) - fixed_width/2; + y[1] = subpixel_snap(v2[0][1] + y_offset_end - setup->pixel_offset) - fixed_width/2; + y[2] = subpixel_snap(v2[0][1] + y_offset_end - setup->pixel_offset) + fixed_width/2; + y[3] = subpixel_snap(v1[0][1] + y_offset - setup->pixel_offset) + fixed_width/2; + + } + else { + const float dxdy = dx / dy; + + /* Y-MAJOR LINE */ + x1diff = v1[0][0] - (float) floor(v1[0][0]) - 0.5; + y1diff = v1[0][1] - (float) floor(v1[0][1]) - 0.5; + x2diff = v2[0][0] - (float) floor(v2[0][0]) - 0.5; + y2diff = v2[0][1] - (float) floor(v2[0][1]) - 0.5; + + if (x2diff==-0.5 && dx<0) { + x2diff = 0.5; + } + + /* + * Diamond exit rule test for starting point + */ + if (fabsf(x1diff) + fabsf(y1diff) < 0.5) { + draw_start = TRUE; + } + else if (sign(-y1diff) == sign(dy)) { + draw_start = FALSE; + } + else if (sign(x1diff) != sign(-dx)) { + draw_start = TRUE; + } + else { + /* do intersection test */ + float xintersect = fracf(v1[0][0]) + y1diff * dxdy; + draw_start = (xintersect < 1.0 && xintersect > 0.0); + } + + /* + * Diamond exit rule test for ending point + */ + if (fabsf(x2diff) + fabsf(y2diff) < 0.5) { + draw_end = FALSE; + } + else if (sign(-y2diff) != sign(dy) ) { + draw_end = FALSE; + } + else if (sign(x2diff) == sign(-dx) ) { + draw_end = TRUE; + } + else { + /* do intersection test */ + float xintersect = fracf(v2[0][0]) + y2diff * dxdy; + draw_end = (xintersect < 1.0 && xintersect >= 0.0); + } + + /* Are we already drawing start/end? + */ + will_draw_start = sign(y1diff) == sign(dy); + will_draw_end = (sign(-y2diff) == sign(dy)) || y2diff==0; + + if (dy > 0) { + /* if v2 is on top of v1, swap pointers */ + const float (*temp)[4] = v1; + v1 = v2; + v2 = temp; + dx = -dx; + dy = -dy; + + /* Otherwise shift planes appropriately */ + if (will_draw_start != draw_start) { + y_offset_end = - y1diff + 0.5; + x_offset_end = y_offset_end * dxdy; + } + if (will_draw_end != draw_end) { + y_offset = - y2diff + 0.5; + x_offset = y_offset * dxdy; + } + } + else { + /* Otherwise shift planes appropriately */ + if (will_draw_start != draw_start) { + y_offset = - y1diff - 0.5; + x_offset = y_offset * dxdy; + + } + if (will_draw_end != draw_end) { + y_offset_end = - y2diff - 0.5; + x_offset_end = y_offset_end * dxdy; + } + } + + /* x/y positions in fixed point */ + x[0] = subpixel_snap(v1[0][0] + x_offset - setup->pixel_offset) - fixed_width/2; + x[1] = subpixel_snap(v2[0][0] + x_offset_end - setup->pixel_offset) - fixed_width/2; + x[2] = subpixel_snap(v2[0][0] + x_offset_end - setup->pixel_offset) + fixed_width/2; + x[3] = subpixel_snap(v1[0][0] + x_offset - setup->pixel_offset) + fixed_width/2; + + y[0] = subpixel_snap(v1[0][1] + y_offset - setup->pixel_offset); + y[1] = subpixel_snap(v2[0][1] + y_offset_end - setup->pixel_offset); + y[2] = subpixel_snap(v2[0][1] + y_offset_end - setup->pixel_offset); + y[3] = subpixel_snap(v1[0][1] + y_offset - setup->pixel_offset); + } + + + + LP_COUNT(nr_tris); + + + /* Bounding rectangle (in pixels) */ + { + /* Yes this is necessary to accurately calculate bounding boxes + * with the two fill-conventions we support. GL (normally) ends + * up needing a bottom-left fill convention, which requires + * slightly different rounding. + */ + int adj = (setup->pixel_offset != 0) ? 1 : 0; + + bbox.x0 = (MIN4(x[0], x[1], x[2], x[3]) + (FIXED_ONE-1)) >> FIXED_ORDER; + bbox.x1 = (MAX4(x[0], x[1], x[2], x[3]) + (FIXED_ONE-1)) >> FIXED_ORDER; + bbox.y0 = (MIN4(y[0], y[1], y[2], y[3]) + (FIXED_ONE-1) + adj) >> FIXED_ORDER; + bbox.y1 = (MAX4(y[0], y[1], y[2], y[3]) + (FIXED_ONE-1) + adj) >> FIXED_ORDER; + + /* Inclusive coordinates: + */ + bbox.x1--; + bbox.y1--; + } + + if (bbox.x1 < bbox.x0 || + bbox.y1 < bbox.y0) { + if (0) debug_printf("empty bounding box\n"); + LP_COUNT(nr_culled_tris); + return TRUE; + } + + if (!u_rect_test_intersection(&setup->draw_region, &bbox)) { + if (0) debug_printf("offscreen\n"); + LP_COUNT(nr_culled_tris); + return TRUE; + } + + /* Can safely discard negative regions: + */ + bbox.x0 = MAX2(bbox.x0, 0); + bbox.y0 = MAX2(bbox.y0, 0); + + line = lp_setup_alloc_triangle(scene, + key->num_inputs, + nr_planes, + &tri_bytes); + if (!line) + return FALSE; + +#ifdef DEBUG + line->v[0][0] = v1[0][0]; + line->v[1][0] = v2[0][0]; + line->v[0][1] = v1[0][1]; + line->v[1][1] = v2[0][1]; +#endif + + /* calculate the deltas */ + plane = GET_PLANES(line); + plane[0].dcdy = x[0] - x[1]; + plane[1].dcdy = x[1] - x[2]; + plane[2].dcdy = x[2] - x[3]; + plane[3].dcdy = x[3] - x[0]; + + plane[0].dcdx = y[0] - y[1]; + plane[1].dcdx = y[1] - y[2]; + plane[2].dcdx = y[2] - y[3]; + plane[3].dcdx = y[3] - y[0]; + + + /* Setup parameter interpolants: + */ + info.a0 = GET_A0(&line->inputs); + info.dadx = GET_DADX(&line->inputs); + info.dady = GET_DADY(&line->inputs); + setup_line_coefficients(setup, &info); + + line->inputs.frontfacing = TRUE; + line->inputs.disable = FALSE; + line->inputs.opaque = FALSE; + + for (i = 0; i < 4; i++) { + + /* half-edge constants, will be interated over the whole render + * target. + */ + plane[i].c = plane[i].dcdx * x[i] - plane[i].dcdy * y[i]; + + + /* correct for top-left vs. bottom-left fill convention. + * + * note that we're overloading gl_rasterization_rules to mean + * both (0.5,0.5) pixel centers *and* bottom-left filling + * convention. + * + * GL actually has a top-left filling convention, but GL's + * notion of "top" differs from gallium's... + * + * Also, sometimes (in FBO cases) GL will render upside down + * to its usual method, in which case it will probably want + * to use the opposite, top-left convention. + */ + if (plane[i].dcdx < 0) { + /* both fill conventions want this - adjust for left edges */ + plane[i].c++; + } + else if (plane[i].dcdx == 0) { + if (setup->pixel_offset == 0) { + /* correct for top-left fill convention: + */ + if (plane[i].dcdy > 0) plane[i].c++; + } + else { + /* correct for bottom-left fill convention: + */ + if (plane[i].dcdy < 0) plane[i].c++; + } + } + + plane[i].dcdx *= FIXED_ONE; + plane[i].dcdy *= FIXED_ONE; + + /* find trivial reject offsets for each edge for a single-pixel + * sized block. These will be scaled up at each recursive level to + * match the active blocksize. Scaling in this way works best if + * the blocks are square. + */ + plane[i].eo = 0; + if (plane[i].dcdx < 0) plane[i].eo -= plane[i].dcdx; + if (plane[i].dcdy > 0) plane[i].eo += plane[i].dcdy; + } + + + /* + * When rasterizing scissored tris, use the intersection of the + * triangle bounding box and the scissor rect to generate the + * scissor planes. + * + * This permits us to cut off the triangle "tails" that are present + * in the intermediate recursive levels caused when two of the + * triangles edges don't diverge quickly enough to trivially reject + * exterior blocks from the triangle. + * + * It's not really clear if it's worth worrying about these tails, + * but since we generate the planes for each scissored tri, it's + * free to trim them in this case. + * + * Note that otherwise, the scissor planes only vary in 'C' value, + * and even then only on state-changes. Could alternatively store + * these planes elsewhere. + */ + if (nr_planes == 8) { + const struct u_rect *scissor = &setup->scissor; + + plane[4].dcdx = -1; + plane[4].dcdy = 0; + plane[4].c = 1-scissor->x0; + plane[4].eo = 1; + + plane[5].dcdx = 1; + plane[5].dcdy = 0; + plane[5].c = scissor->x1+1; + plane[5].eo = 0; + + plane[6].dcdx = 0; + plane[6].dcdy = 1; + plane[6].c = 1-scissor->y0; + plane[6].eo = 1; + + plane[7].dcdx = 0; + plane[7].dcdy = -1; + plane[7].c = scissor->y1+1; + plane[7].eo = 0; + } + + return lp_setup_bin_triangle(setup, line, &bbox, nr_planes); +} + + +static void lp_setup_line( struct lp_setup_context *setup, + const float (*v0)[4], + const float (*v1)[4] ) +{ + if (!try_setup_line( setup, v0, v1 )) + { + if (!lp_setup_flush_and_restart(setup)) + return; + + if (!try_setup_line( setup, v0, v1 )) + return; + } +} + + +void lp_setup_choose_line( struct lp_setup_context *setup ) +{ + setup->line = lp_setup_line; +} + + diff --git a/src/gallium/drivers/llvmpipe/lp_setup_point.c b/src/gallium/drivers/llvmpipe/lp_setup_point.c new file mode 100644 index 0000000..146f1bd --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_setup_point.c @@ -0,0 +1,435 @@ +/************************************************************************** + * + * Copyright 2010, VMware Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* + * Binning code for points + */ + +#include "lp_setup_context.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "lp_perf.h" +#include "lp_rast.h" +#include "lp_state_fs.h" +#include "lp_state_setup.h" +#include "tgsi/tgsi_scan.h" + +#define NUM_CHANNELS 4 + +struct point_info { + /* x,y deltas */ + int dy01, dy12; + int dx01, dx12; + + const float (*v0)[4]; + + float (*a0)[4]; + float (*dadx)[4]; + float (*dady)[4]; +}; + + +/** + * Compute a0 for a constant-valued coefficient (GL_FLAT shading). + */ +static void +constant_coef(struct lp_setup_context *setup, + struct point_info *info, + unsigned slot, + const float value, + unsigned i) +{ + info->a0[slot][i] = value; + info->dadx[slot][i] = 0.0f; + info->dady[slot][i] = 0.0f; +} + + +static void +point_persp_coeff(struct lp_setup_context *setup, + const struct point_info *info, + unsigned slot, + unsigned i) +{ + /* + * Fragment shader expects pre-multiplied w for LP_INTERP_PERSPECTIVE. A + * better stratergy would be to take the primitive in consideration when + * generating the fragment shader key, and therefore avoid the per-fragment + * perspective divide. + */ + + float w0 = info->v0[0][3]; + + assert(i < 4); + + info->a0[slot][i] = info->v0[slot][i]*w0; + info->dadx[slot][i] = 0.0f; + info->dady[slot][i] = 0.0f; +} + + +/** + * Setup automatic texcoord coefficients (for sprite rendering). + * \param slot the vertex attribute slot to setup + * \param i the attribute channel in [0,3] + * \param sprite_coord_origin one of PIPE_SPRITE_COORD_x + * \param perspective does the shader expects pre-multiplied w, i.e., + * LP_INTERP_PERSPECTIVE is specified in the shader key + */ +static void +texcoord_coef(struct lp_setup_context *setup, + const struct point_info *info, + unsigned slot, + unsigned i, + unsigned sprite_coord_origin, + boolean perspective) +{ + float w0 = info->v0[0][3]; + + assert(i < 4); + + if (i == 0) { + float dadx = FIXED_ONE / (float)info->dx12; + float dady = 0.0f; + float x0 = info->v0[0][0] - setup->pixel_offset; + float y0 = info->v0[0][1] - setup->pixel_offset; + + info->dadx[slot][0] = dadx; + info->dady[slot][0] = dady; + info->a0[slot][0] = 0.5 - (dadx * x0 + dady * y0); + + if (perspective) { + info->dadx[slot][0] *= w0; + info->dady[slot][0] *= w0; + info->a0[slot][0] *= w0; + } + } + else if (i == 1) { + float dadx = 0.0f; + float dady = FIXED_ONE / (float)info->dx12; + float x0 = info->v0[0][0] - setup->pixel_offset; + float y0 = info->v0[0][1] - setup->pixel_offset; + + if (sprite_coord_origin == PIPE_SPRITE_COORD_LOWER_LEFT) { + dady = -dady; + } + + info->dadx[slot][1] = dadx; + info->dady[slot][1] = dady; + info->a0[slot][1] = 0.5 - (dadx * x0 + dady * y0); + + if (perspective) { + info->dadx[slot][1] *= w0; + info->dady[slot][1] *= w0; + info->a0[slot][1] *= w0; + } + } + else if (i == 2) { + info->a0[slot][2] = 0.0f; + info->dadx[slot][2] = 0.0f; + info->dady[slot][2] = 0.0f; + } + else { + info->a0[slot][3] = perspective ? w0 : 1.0f; + info->dadx[slot][3] = 0.0f; + info->dady[slot][3] = 0.0f; + } +} + + +/** + * Special coefficient setup for gl_FragCoord. + * X and Y are trivial + * Z and W are copied from position_coef which should have already been computed. + * We could do a bit less work if we'd examine gl_FragCoord's swizzle mask. + */ +static void +setup_point_fragcoord_coef(struct lp_setup_context *setup, + struct point_info *info, + unsigned slot, + unsigned usage_mask) +{ + /*X*/ + if (usage_mask & TGSI_WRITEMASK_X) { + info->a0[slot][0] = 0.0; + info->dadx[slot][0] = 1.0; + info->dady[slot][0] = 0.0; + } + + /*Y*/ + if (usage_mask & TGSI_WRITEMASK_Y) { + info->a0[slot][1] = 0.0; + info->dadx[slot][1] = 0.0; + info->dady[slot][1] = 1.0; + } + + /*Z*/ + if (usage_mask & TGSI_WRITEMASK_Z) { + constant_coef(setup, info, slot, info->v0[0][2], 2); + } + + /*W*/ + if (usage_mask & TGSI_WRITEMASK_W) { + constant_coef(setup, info, slot, info->v0[0][3], 3); + } +} + + +/** + * Compute the point->coef[] array dadx, dady, a0 values. + */ +static void +setup_point_coefficients( struct lp_setup_context *setup, + struct point_info *info) +{ + const struct lp_setup_variant_key *key = &setup->setup.variant->key; + const struct lp_fragment_shader *shader = setup->fs.current.variant->shader; + unsigned fragcoord_usage_mask = TGSI_WRITEMASK_XYZ; + unsigned slot; + + /* setup interpolation for all the remaining attributes: + */ + for (slot = 0; slot < key->num_inputs; slot++) { + unsigned vert_attr = key->inputs[slot].src_index; + unsigned usage_mask = key->inputs[slot].usage_mask; + enum lp_interp interp = key->inputs[slot].interp; + boolean perspective = !!(interp == LP_INTERP_PERSPECTIVE); + unsigned i; + + if (perspective & usage_mask) { + fragcoord_usage_mask |= TGSI_WRITEMASK_W; + } + + switch (interp) { + case LP_INTERP_POSITION: + /* + * The generated pixel interpolators will pick up the coeffs from + * slot 0, so all need to ensure that the usage mask is covers all + * usages. + */ + fragcoord_usage_mask |= usage_mask; + break; + + case LP_INTERP_LINEAR: + /* Sprite tex coords may use linear interpolation someday */ + /* fall-through */ + case LP_INTERP_PERSPECTIVE: + /* check if the sprite coord flag is set for this attribute. + * If so, set it up so it up so x and y vary from 0 to 1. + */ + if (shader->info.base.input_semantic_name[slot] == TGSI_SEMANTIC_GENERIC) { + unsigned semantic_index = shader->info.base.input_semantic_index[slot]; + /* Note that sprite_coord enable is a bitfield of + * PIPE_MAX_SHADER_OUTPUTS bits. + */ + if (semantic_index < PIPE_MAX_SHADER_OUTPUTS && + (setup->sprite_coord_enable & (1 << semantic_index))) { + for (i = 0; i < NUM_CHANNELS; i++) { + if (usage_mask & (1 << i)) { + texcoord_coef(setup, info, slot + 1, i, + setup->sprite_coord_origin, + perspective); + } + } + break; + } + } + /* fall-through */ + case LP_INTERP_CONSTANT: + for (i = 0; i < NUM_CHANNELS; i++) { + if (usage_mask & (1 << i)) { + if (perspective) { + point_persp_coeff(setup, info, slot+1, i); + } + else { + constant_coef(setup, info, slot+1, info->v0[vert_attr][i], i); + } + } + } + break; + + case LP_INTERP_FACING: + for (i = 0; i < NUM_CHANNELS; i++) + if (usage_mask & (1 << i)) + constant_coef(setup, info, slot+1, 1.0, i); + break; + + default: + assert(0); + break; + } + } + + /* The internal position input is in slot zero: + */ + setup_point_fragcoord_coef(setup, info, 0, + fragcoord_usage_mask); +} + + +static INLINE int +subpixel_snap(float a) +{ + return util_iround(FIXED_ONE * a); +} + + +static boolean +try_setup_point( struct lp_setup_context *setup, + const float (*v0)[4] ) +{ + /* x/y positions in fixed point */ + const struct lp_setup_variant_key *key = &setup->setup.variant->key; + const int sizeAttr = setup->psize; + const float size + = (setup->point_size_per_vertex && sizeAttr > 0) ? v0[sizeAttr][0] + : setup->point_size; + + /* Point size as fixed point integer, remove rounding errors + * and gives minimum width for very small points + */ + int fixed_width = MAX2(FIXED_ONE, + (subpixel_snap(size) + FIXED_ONE/2 - 1) & ~(FIXED_ONE-1)); + + const int x0 = subpixel_snap(v0[0][0] - setup->pixel_offset) - fixed_width/2; + const int y0 = subpixel_snap(v0[0][1] - setup->pixel_offset) - fixed_width/2; + + struct lp_scene *scene = setup->scene; + struct lp_rast_triangle *point; + unsigned bytes; + struct u_rect bbox; + unsigned nr_planes = 4; + struct point_info info; + + + /* Bounding rectangle (in pixels) */ + { + /* Yes this is necessary to accurately calculate bounding boxes + * with the two fill-conventions we support. GL (normally) ends + * up needing a bottom-left fill convention, which requires + * slightly different rounding. + */ + int adj = (setup->pixel_offset != 0) ? 1 : 0; + + bbox.x0 = (x0 + (FIXED_ONE-1) + adj) >> FIXED_ORDER; + bbox.x1 = (x0 + fixed_width + (FIXED_ONE-1) + adj) >> FIXED_ORDER; + bbox.y0 = (y0 + (FIXED_ONE-1)) >> FIXED_ORDER; + bbox.y1 = (y0 + fixed_width + (FIXED_ONE-1)) >> FIXED_ORDER; + + /* Inclusive coordinates: + */ + bbox.x1--; + bbox.y1--; + } + + if (!u_rect_test_intersection(&setup->draw_region, &bbox)) { + if (0) debug_printf("offscreen\n"); + LP_COUNT(nr_culled_tris); + return TRUE; + } + + u_rect_find_intersection(&setup->draw_region, &bbox); + + point = lp_setup_alloc_triangle(scene, + key->num_inputs, + nr_planes, + &bytes); + if (!point) + return FALSE; + +#ifdef DEBUG + point->v[0][0] = v0[0][0]; + point->v[0][1] = v0[0][1]; +#endif + + info.v0 = v0; + info.dx01 = 0; + info.dx12 = fixed_width; + info.dy01 = fixed_width; + info.dy12 = 0; + info.a0 = GET_A0(&point->inputs); + info.dadx = GET_DADX(&point->inputs); + info.dady = GET_DADY(&point->inputs); + + /* Setup parameter interpolants: + */ + setup_point_coefficients(setup, &info); + + point->inputs.frontfacing = TRUE; + point->inputs.disable = FALSE; + point->inputs.opaque = FALSE; + + { + struct lp_rast_plane *plane = GET_PLANES(point); + + plane[0].dcdx = -1; + plane[0].dcdy = 0; + plane[0].c = 1-bbox.x0; + plane[0].eo = 1; + + plane[1].dcdx = 1; + plane[1].dcdy = 0; + plane[1].c = bbox.x1+1; + plane[1].eo = 0; + + plane[2].dcdx = 0; + plane[2].dcdy = 1; + plane[2].c = 1-bbox.y0; + plane[2].eo = 1; + + plane[3].dcdx = 0; + plane[3].dcdy = -1; + plane[3].c = bbox.y1+1; + plane[3].eo = 0; + } + + return lp_setup_bin_triangle(setup, point, &bbox, nr_planes); +} + + +static void +lp_setup_point(struct lp_setup_context *setup, + const float (*v0)[4]) +{ + if (!try_setup_point( setup, v0 )) + { + if (!lp_setup_flush_and_restart(setup)) + return; + + if (!try_setup_point( setup, v0 )) + return; + } +} + + +void +lp_setup_choose_point( struct lp_setup_context *setup ) +{ + setup->point = lp_setup_point; +} + + diff --git a/src/gallium/drivers/llvmpipe/lp_setup_tri.c b/src/gallium/drivers/llvmpipe/lp_setup_tri.c new file mode 100644 index 0000000..bfb6bf2 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_setup_tri.c @@ -0,0 +1,860 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* + * Binning code for triangles + */ + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_rect.h" +#include "util/u_sse.h" +#include "lp_perf.h" +#include "lp_setup_context.h" +#include "lp_rast.h" +#include "lp_state_fs.h" +#include "lp_state_setup.h" + +#define NUM_CHANNELS 4 + +#if defined(PIPE_ARCH_SSE) +#include +#endif + +static INLINE int +subpixel_snap(float a) +{ + return util_iround(FIXED_ONE * a); +} + +static INLINE float +fixed_to_float(int a) +{ + return a * (1.0 / FIXED_ONE); +} + + + + + + + +/** + * Alloc space for a new triangle plus the input.a0/dadx/dady arrays + * immediately after it. + * The memory is allocated from the per-scene pool, not per-tile. + * \param tri_size returns number of bytes allocated + * \param num_inputs number of fragment shader inputs + * \return pointer to triangle space + */ +struct lp_rast_triangle * +lp_setup_alloc_triangle(struct lp_scene *scene, + unsigned nr_inputs, + unsigned nr_planes, + unsigned *tri_size) +{ + unsigned input_array_sz = NUM_CHANNELS * (nr_inputs + 1) * sizeof(float); + unsigned plane_sz = nr_planes * sizeof(struct lp_rast_plane); + struct lp_rast_triangle *tri; + + *tri_size = (sizeof(struct lp_rast_triangle) + + 3 * input_array_sz + + plane_sz); + + tri = lp_scene_alloc_aligned( scene, *tri_size, 16 ); + if (tri == NULL) + return NULL; + + tri->inputs.stride = input_array_sz; + + { + char *a = (char *)tri; + char *b = (char *)&GET_PLANES(tri)[nr_planes]; + assert(b - a == *tri_size); + } + + return tri; +} + +void +lp_setup_print_vertex(struct lp_setup_context *setup, + const char *name, + const float (*v)[4]) +{ + const struct lp_setup_variant_key *key = &setup->setup.variant->key; + int i, j; + + debug_printf(" wpos (%s[0]) xyzw %f %f %f %f\n", + name, + v[0][0], v[0][1], v[0][2], v[0][3]); + + for (i = 0; i < key->num_inputs; i++) { + const float *in = v[key->inputs[i].src_index]; + + debug_printf(" in[%d] (%s[%d]) %s%s%s%s ", + i, + name, key->inputs[i].src_index, + (key->inputs[i].usage_mask & 0x1) ? "x" : " ", + (key->inputs[i].usage_mask & 0x2) ? "y" : " ", + (key->inputs[i].usage_mask & 0x4) ? "z" : " ", + (key->inputs[i].usage_mask & 0x8) ? "w" : " "); + + for (j = 0; j < 4; j++) + if (key->inputs[i].usage_mask & (1< 0.0f) + debug_printf(" - cw\n"); + else + debug_printf(" - zero area\n"); + } + + lp_setup_print_vertex(setup, "v0", v0); + lp_setup_print_vertex(setup, "v1", v1); + lp_setup_print_vertex(setup, "v2", v2); +} + + +#define MAX_PLANES 8 +static unsigned +lp_rast_tri_tab[MAX_PLANES+1] = { + 0, /* should be impossible */ + LP_RAST_OP_TRIANGLE_1, + LP_RAST_OP_TRIANGLE_2, + LP_RAST_OP_TRIANGLE_3, + LP_RAST_OP_TRIANGLE_4, + LP_RAST_OP_TRIANGLE_5, + LP_RAST_OP_TRIANGLE_6, + LP_RAST_OP_TRIANGLE_7, + LP_RAST_OP_TRIANGLE_8 +}; + + + +/** + * The primitive covers the whole tile- shade whole tile. + * + * \param tx, ty the tile position in tiles, not pixels + */ +static boolean +lp_setup_whole_tile(struct lp_setup_context *setup, + const struct lp_rast_shader_inputs *inputs, + int tx, int ty) +{ + struct lp_scene *scene = setup->scene; + + LP_COUNT(nr_fully_covered_64); + + /* if variant is opaque and scissor doesn't effect the tile */ + if (inputs->opaque) { + if (!scene->fb.zsbuf) { + /* + * All previous rendering will be overwritten so reset the bin. + */ + lp_scene_bin_reset( scene, tx, ty ); + } + + LP_COUNT(nr_shade_opaque_64); + return lp_scene_bin_cmd_with_state( scene, tx, ty, + setup->fs.stored, + LP_RAST_OP_SHADE_TILE_OPAQUE, + lp_rast_arg_inputs(inputs) ); + } else { + LP_COUNT(nr_shade_64); + return lp_scene_bin_cmd_with_state( scene, tx, ty, + setup->fs.stored, + LP_RAST_OP_SHADE_TILE, + lp_rast_arg_inputs(inputs) ); + } +} + + +/** + * Do basic setup for triangle rasterization and determine which + * framebuffer tiles are touched. Put the triangle in the scene's + * bins for the tiles which we overlap. + */ +static boolean +do_triangle_ccw(struct lp_setup_context *setup, + const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4], + boolean frontfacing ) +{ + struct lp_scene *scene = setup->scene; + const struct lp_setup_variant_key *key = &setup->setup.variant->key; + struct lp_rast_triangle *tri; + struct lp_rast_plane *plane; + int x[4]; + int y[4]; + struct u_rect bbox; + unsigned tri_bytes; + int nr_planes = 3; + + if (0) + lp_setup_print_triangle(setup, v0, v1, v2); + + if (setup->scissor_test) { + nr_planes = 7; + } + else { + nr_planes = 3; + } + + /* x/y positions in fixed point */ + x[0] = subpixel_snap(v0[0][0] - setup->pixel_offset); + x[1] = subpixel_snap(v1[0][0] - setup->pixel_offset); + x[2] = subpixel_snap(v2[0][0] - setup->pixel_offset); + x[3] = 0; + y[0] = subpixel_snap(v0[0][1] - setup->pixel_offset); + y[1] = subpixel_snap(v1[0][1] - setup->pixel_offset); + y[2] = subpixel_snap(v2[0][1] - setup->pixel_offset); + y[3] = 0; + + + /* Bounding rectangle (in pixels) */ + { + /* Yes this is necessary to accurately calculate bounding boxes + * with the two fill-conventions we support. GL (normally) ends + * up needing a bottom-left fill convention, which requires + * slightly different rounding. + */ + int adj = (setup->pixel_offset != 0) ? 1 : 0; + + bbox.x0 = (MIN3(x[0], x[1], x[2]) + (FIXED_ONE-1)) >> FIXED_ORDER; + bbox.x1 = (MAX3(x[0], x[1], x[2]) + (FIXED_ONE-1)) >> FIXED_ORDER; + bbox.y0 = (MIN3(y[0], y[1], y[2]) + (FIXED_ONE-1) + adj) >> FIXED_ORDER; + bbox.y1 = (MAX3(y[0], y[1], y[2]) + (FIXED_ONE-1) + adj) >> FIXED_ORDER; + + /* Inclusive coordinates: + */ + bbox.x1--; + bbox.y1--; + } + + if (bbox.x1 < bbox.x0 || + bbox.y1 < bbox.y0) { + if (0) debug_printf("empty bounding box\n"); + LP_COUNT(nr_culled_tris); + return TRUE; + } + + if (!u_rect_test_intersection(&setup->draw_region, &bbox)) { + if (0) debug_printf("offscreen\n"); + LP_COUNT(nr_culled_tris); + return TRUE; + } + + /* Can safely discard negative regions, but need to keep hold of + * information about when the triangle extends past screen + * boundaries. See trimmed_box in lp_setup_bin_triangle(). + */ + bbox.x0 = MAX2(bbox.x0, 0); + bbox.y0 = MAX2(bbox.y0, 0); + + tri = lp_setup_alloc_triangle(scene, + key->num_inputs, + nr_planes, + &tri_bytes); + if (!tri) + return FALSE; + +#if 0 + tri->v[0][0] = v0[0][0]; + tri->v[1][0] = v1[0][0]; + tri->v[2][0] = v2[0][0]; + tri->v[0][1] = v0[0][1]; + tri->v[1][1] = v1[0][1]; + tri->v[2][1] = v2[0][1]; +#endif + + LP_COUNT(nr_tris); + + /* Setup parameter interpolants: + */ + setup->setup.variant->jit_function( v0, + v1, + v2, + frontfacing, + GET_A0(&tri->inputs), + GET_DADX(&tri->inputs), + GET_DADY(&tri->inputs) ); + + tri->inputs.frontfacing = frontfacing; + tri->inputs.disable = FALSE; + tri->inputs.opaque = setup->fs.current.variant->opaque; + + if (0) + lp_dump_setup_coef(&setup->setup.variant->key, + (const float (*)[4])GET_A0(&tri->inputs), + (const float (*)[4])GET_DADX(&tri->inputs), + (const float (*)[4])GET_DADY(&tri->inputs)); + + plane = GET_PLANES(tri); + +#if defined(PIPE_ARCH_SSE) + { + __m128i vertx, verty; + __m128i shufx, shufy; + __m128i dcdx, dcdy, c; + __m128i unused; + __m128i dcdx_neg_mask; + __m128i dcdy_neg_mask; + __m128i dcdx_zero_mask; + __m128i top_left_flag; + __m128i c_inc_mask, c_inc; + __m128i eo, p0, p1, p2; + __m128i zero = _mm_setzero_si128(); + + vertx = _mm_loadu_si128((__m128i *)x); /* vertex x coords */ + verty = _mm_loadu_si128((__m128i *)y); /* vertex y coords */ + + shufx = _mm_shuffle_epi32(vertx, _MM_SHUFFLE(3,0,2,1)); + shufy = _mm_shuffle_epi32(verty, _MM_SHUFFLE(3,0,2,1)); + + dcdx = _mm_sub_epi32(verty, shufy); + dcdy = _mm_sub_epi32(vertx, shufx); + + dcdx_neg_mask = _mm_srai_epi32(dcdx, 31); + dcdx_zero_mask = _mm_cmpeq_epi32(dcdx, zero); + dcdy_neg_mask = _mm_srai_epi32(dcdy, 31); + + top_left_flag = _mm_set1_epi32((setup->pixel_offset == 0) ? ~0 : 0); + + c_inc_mask = _mm_or_si128(dcdx_neg_mask, + _mm_and_si128(dcdx_zero_mask, + _mm_xor_si128(dcdy_neg_mask, + top_left_flag))); + + c_inc = _mm_srli_epi32(c_inc_mask, 31); + + c = _mm_sub_epi32(mm_mullo_epi32(dcdx, vertx), + mm_mullo_epi32(dcdy, verty)); + + c = _mm_add_epi32(c, c_inc); + + /* Scale up to match c: + */ + dcdx = _mm_slli_epi32(dcdx, FIXED_ORDER); + dcdy = _mm_slli_epi32(dcdy, FIXED_ORDER); + + /* Calculate trivial reject values: + */ + eo = _mm_sub_epi32(_mm_andnot_si128(dcdy_neg_mask, dcdy), + _mm_and_si128(dcdx_neg_mask, dcdx)); + + /* ei = _mm_sub_epi32(_mm_sub_epi32(dcdy, dcdx), eo); */ + + /* Pointless transpose which gets undone immediately in + * rasterization: + */ + transpose4_epi32(&c, &dcdx, &dcdy, &eo, + &p0, &p1, &p2, &unused); + + _mm_store_si128((__m128i *)&plane[0], p0); + _mm_store_si128((__m128i *)&plane[1], p1); + _mm_store_si128((__m128i *)&plane[2], p2); + } +#else + { + int i; + plane[0].dcdy = x[0] - x[1]; + plane[1].dcdy = x[1] - x[2]; + plane[2].dcdy = x[2] - x[0]; + plane[0].dcdx = y[0] - y[1]; + plane[1].dcdx = y[1] - y[2]; + plane[2].dcdx = y[2] - y[0]; + + for (i = 0; i < 3; i++) { + /* half-edge constants, will be interated over the whole render + * target. + */ + plane[i].c = plane[i].dcdx * x[i] - plane[i].dcdy * y[i]; + + /* correct for top-left vs. bottom-left fill convention. + * + * note that we're overloading gl_rasterization_rules to mean + * both (0.5,0.5) pixel centers *and* bottom-left filling + * convention. + * + * GL actually has a top-left filling convention, but GL's + * notion of "top" differs from gallium's... + * + * Also, sometimes (in FBO cases) GL will render upside down + * to its usual method, in which case it will probably want + * to use the opposite, top-left convention. + */ + if (plane[i].dcdx < 0) { + /* both fill conventions want this - adjust for left edges */ + plane[i].c++; + } + else if (plane[i].dcdx == 0) { + if (setup->pixel_offset == 0) { + /* correct for top-left fill convention: + */ + if (plane[i].dcdy > 0) plane[i].c++; + } + else { + /* correct for bottom-left fill convention: + */ + if (plane[i].dcdy < 0) plane[i].c++; + } + } + + plane[i].dcdx *= FIXED_ONE; + plane[i].dcdy *= FIXED_ONE; + + /* find trivial reject offsets for each edge for a single-pixel + * sized block. These will be scaled up at each recursive level to + * match the active blocksize. Scaling in this way works best if + * the blocks are square. + */ + plane[i].eo = 0; + if (plane[i].dcdx < 0) plane[i].eo -= plane[i].dcdx; + if (plane[i].dcdy > 0) plane[i].eo += plane[i].dcdy; + } + } +#endif + + if (0) { + debug_printf("p0: %08x/%08x/%08x/%08x\n", + plane[0].c, + plane[0].dcdx, + plane[0].dcdy, + plane[0].eo); + + debug_printf("p1: %08x/%08x/%08x/%08x\n", + plane[1].c, + plane[1].dcdx, + plane[1].dcdy, + plane[1].eo); + + debug_printf("p0: %08x/%08x/%08x/%08x\n", + plane[2].c, + plane[2].dcdx, + plane[2].dcdy, + plane[2].eo); + } + + + /* + * When rasterizing scissored tris, use the intersection of the + * triangle bounding box and the scissor rect to generate the + * scissor planes. + * + * This permits us to cut off the triangle "tails" that are present + * in the intermediate recursive levels caused when two of the + * triangles edges don't diverge quickly enough to trivially reject + * exterior blocks from the triangle. + * + * It's not really clear if it's worth worrying about these tails, + * but since we generate the planes for each scissored tri, it's + * free to trim them in this case. + * + * Note that otherwise, the scissor planes only vary in 'C' value, + * and even then only on state-changes. Could alternatively store + * these planes elsewhere. + */ + if (nr_planes == 7) { + const struct u_rect *scissor = &setup->scissor; + + plane[3].dcdx = -1; + plane[3].dcdy = 0; + plane[3].c = 1-scissor->x0; + plane[3].eo = 1; + + plane[4].dcdx = 1; + plane[4].dcdy = 0; + plane[4].c = scissor->x1+1; + plane[4].eo = 0; + + plane[5].dcdx = 0; + plane[5].dcdy = 1; + plane[5].c = 1-scissor->y0; + plane[5].eo = 1; + + plane[6].dcdx = 0; + plane[6].dcdy = -1; + plane[6].c = scissor->y1+1; + plane[6].eo = 0; + } + + return lp_setup_bin_triangle( setup, tri, &bbox, nr_planes ); +} + +/* + * Round to nearest less or equal power of two of the input. + * + * Undefined if no bit set exists, so code should check against 0 first. + */ +static INLINE uint32_t +floor_pot(uint32_t n) +{ +#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86) + if (n == 0) + return 0; + + __asm__("bsr %1,%0" + : "=r" (n) + : "rm" (n)); + return 1 << n; +#else + n |= (n >> 1); + n |= (n >> 2); + n |= (n >> 4); + n |= (n >> 8); + n |= (n >> 16); + return n - (n >> 1); +#endif +} + + +boolean +lp_setup_bin_triangle( struct lp_setup_context *setup, + struct lp_rast_triangle *tri, + const struct u_rect *bbox, + int nr_planes ) +{ + struct lp_scene *scene = setup->scene; + struct u_rect trimmed_box = *bbox; + int i; + + /* What is the largest power-of-two boundary this triangle crosses: + */ + int dx = floor_pot((bbox->x0 ^ bbox->x1) | + (bbox->y0 ^ bbox->y1)); + + /* The largest dimension of the rasterized area of the triangle + * (aligned to a 4x4 grid), rounded down to the nearest power of two: + */ + int sz = floor_pot((bbox->x1 - (bbox->x0 & ~3)) | + (bbox->y1 - (bbox->y0 & ~3))); + + /* Now apply scissor, etc to the bounding box. Could do this + * earlier, but it confuses the logic for tri-16 and would force + * the rasterizer to also respect scissor, etc, just for the rare + * cases where a small triangle extends beyond the scissor. + */ + u_rect_find_intersection(&setup->draw_region, &trimmed_box); + + /* Determine which tile(s) intersect the triangle's bounding box + */ + if (dx < TILE_SIZE) + { + int ix0 = bbox->x0 / TILE_SIZE; + int iy0 = bbox->y0 / TILE_SIZE; + int px = bbox->x0 & 63 & ~3; + int py = bbox->y0 & 63 & ~3; + int mask = px | (py << 8); + + assert(iy0 == bbox->y1 / TILE_SIZE && + ix0 == bbox->x1 / TILE_SIZE); + + if (nr_planes == 3) { + if (sz < 4) + { + /* Triangle is contained in a single 4x4 stamp: + */ + return lp_scene_bin_cmd_with_state( scene, ix0, iy0, + setup->fs.stored, + LP_RAST_OP_TRIANGLE_3_4, + lp_rast_arg_triangle(tri, mask) ); + } + + if (sz < 16) + { + /* Triangle is contained in a single 16x16 block: + */ + return lp_scene_bin_cmd_with_state( scene, ix0, iy0, + setup->fs.stored, + LP_RAST_OP_TRIANGLE_3_16, + lp_rast_arg_triangle(tri, mask) ); + } + } + else if (nr_planes == 4 && sz < 16) + { + return lp_scene_bin_cmd_with_state(scene, ix0, iy0, + setup->fs.stored, + LP_RAST_OP_TRIANGLE_4_16, + lp_rast_arg_triangle(tri, mask) ); + } + + + /* Triangle is contained in a single tile: + */ + return lp_scene_bin_cmd_with_state( scene, ix0, iy0, setup->fs.stored, + lp_rast_tri_tab[nr_planes], + lp_rast_arg_triangle(tri, (1<> 31); + partial |= (planepartial >> 31) & (1<fs.stored, + lp_rast_tri_tab[count], + lp_rast_arg_triangle(tri, partial) )) + goto fail; + + LP_COUNT(nr_partially_covered_64); + } + else { + /* triangle covers the whole tile- shade whole tile */ + LP_COUNT(nr_fully_covered_64); + in = TRUE; + if (!lp_setup_whole_tile(setup, &tri->inputs, x, y)) + goto fail; + } + + /* Iterate cx values across the region: + */ + for (i = 0; i < nr_planes; i++) + cx[i] += xstep[i]; + } + + /* Iterate c values down the region: + */ + for (i = 0; i < nr_planes; i++) + c[i] += ystep[i]; + } + } + + return TRUE; + +fail: + /* Need to disable any partially binned triangle. This is easier + * than trying to locate all the triangle, shade-tile, etc, + * commands which may have been binned. + */ + tri->inputs.disable = TRUE; + return FALSE; +} + + +/** + * Try to draw the triangle, restart the scene on failure. + */ +static void retry_triangle_ccw( struct lp_setup_context *setup, + const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4], + boolean front) +{ + if (!do_triangle_ccw( setup, v0, v1, v2, front )) + { + if (!lp_setup_flush_and_restart(setup)) + return; + + if (!do_triangle_ccw( setup, v0, v1, v2, front )) + return; + } +} + +static INLINE float +calc_area(const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4]) +{ + float dx01 = v0[0][0] - v1[0][0]; + float dy01 = v0[0][1] - v1[0][1]; + float dx20 = v2[0][0] - v0[0][0]; + float dy20 = v2[0][1] - v0[0][1]; + return dx01 * dy20 - dx20 * dy01; +} + + +/** + * Draw triangle if it's CW, cull otherwise. + */ +static void triangle_cw( struct lp_setup_context *setup, + const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4] ) +{ + float area = calc_area(v0, v1, v2); + + if (area < 0.0f) + retry_triangle_ccw(setup, v0, v2, v1, !setup->ccw_is_frontface); +} + + +static void triangle_ccw( struct lp_setup_context *setup, + const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4]) +{ + float area = calc_area(v0, v1, v2); + + if (area > 0.0f) + retry_triangle_ccw(setup, v0, v1, v2, setup->ccw_is_frontface); +} + +/** + * Draw triangle whether it's CW or CCW. + */ +static void triangle_both( struct lp_setup_context *setup, + const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4] ) +{ + float area = calc_area(v0, v1, v2); + + if (0) { + assert(!util_is_inf_or_nan(v0[0][0])); + assert(!util_is_inf_or_nan(v0[0][1])); + assert(!util_is_inf_or_nan(v1[0][0])); + assert(!util_is_inf_or_nan(v1[0][1])); + assert(!util_is_inf_or_nan(v2[0][0])); + assert(!util_is_inf_or_nan(v2[0][1])); + assert(!util_is_inf_or_nan(area)); + } + + if (area > 0.0f) + retry_triangle_ccw( setup, v0, v1, v2, setup->ccw_is_frontface ); + else if (area < 0.0f) + retry_triangle_ccw( setup, v0, v2, v1, !setup->ccw_is_frontface ); +} + + +static void triangle_nop( struct lp_setup_context *setup, + const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4] ) +{ +} + + +void +lp_setup_choose_triangle( struct lp_setup_context *setup ) +{ + switch (setup->cullmode) { + case PIPE_FACE_NONE: + setup->triangle = triangle_both; + break; + case PIPE_FACE_BACK: + setup->triangle = setup->ccw_is_frontface ? triangle_ccw : triangle_cw; + break; + case PIPE_FACE_FRONT: + setup->triangle = setup->ccw_is_frontface ? triangle_cw : triangle_ccw; + break; + default: + setup->triangle = triangle_nop; + break; + } +} diff --git a/src/gallium/drivers/llvmpipe/lp_setup_vbuf.c b/src/gallium/drivers/llvmpipe/lp_setup_vbuf.c new file mode 100644 index 0000000..384242f --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_setup_vbuf.c @@ -0,0 +1,556 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Interface between 'draw' module's output and the llvmpipe rasterizer/setup + * code. When the 'draw' module has finished filling a vertex buffer, the + * draw_arrays() functions below will be called. Loop over the vertices and + * call the point/line/tri setup functions. + * + * Authors + * Brian Paul + */ + + +#include "lp_setup_context.h" +#include "draw/draw_vbuf.h" +#include "draw/draw_vertex.h" +#include "util/u_memory.h" + + +#define LP_MAX_VBUF_INDEXES 1024 +#define LP_MAX_VBUF_SIZE 4096 + + + +/** cast wrapper */ +static struct lp_setup_context * +lp_setup_context(struct vbuf_render *vbr) +{ + return (struct lp_setup_context *) vbr; +} + + + +static const struct vertex_info * +lp_setup_get_vertex_info(struct vbuf_render *vbr) +{ + struct lp_setup_context *setup = lp_setup_context(vbr); + + /* Vertex size/info depends on the latest state. + * The draw module may have issued additional state-change commands. + */ + lp_setup_update_state(setup, FALSE); + + return setup->vertex_info; +} + + +static boolean +lp_setup_allocate_vertices(struct vbuf_render *vbr, + ushort vertex_size, ushort nr_vertices) +{ + struct lp_setup_context *setup = lp_setup_context(vbr); + unsigned size = vertex_size * nr_vertices; + + if (setup->vertex_buffer_size < size) { + align_free(setup->vertex_buffer); + setup->vertex_buffer = align_malloc(size, 16); + setup->vertex_buffer_size = size; + } + + setup->vertex_size = vertex_size; + setup->nr_vertices = nr_vertices; + + return setup->vertex_buffer != NULL; +} + +static void +lp_setup_release_vertices(struct vbuf_render *vbr) +{ + /* keep the old allocation for next time */ +} + +static void * +lp_setup_map_vertices(struct vbuf_render *vbr) +{ + struct lp_setup_context *setup = lp_setup_context(vbr); + return setup->vertex_buffer; +} + +static void +lp_setup_unmap_vertices(struct vbuf_render *vbr, + ushort min_index, + ushort max_index ) +{ + struct lp_setup_context *setup = lp_setup_context(vbr); + assert( setup->vertex_buffer_size >= (max_index+1) * setup->vertex_size ); + /* do nothing */ +} + + +static boolean +lp_setup_set_primitive(struct vbuf_render *vbr, unsigned prim) +{ + lp_setup_context(vbr)->prim = prim; + return TRUE; +} + +typedef const float (*const_float4_ptr)[4]; + +static INLINE const_float4_ptr get_vert( const void *vertex_buffer, + int index, + int stride ) +{ + return (const_float4_ptr)((char *)vertex_buffer + index * stride); +} + +/** + * draw elements / indexed primitives + */ +static void +lp_setup_draw_elements(struct vbuf_render *vbr, const ushort *indices, uint nr) +{ + struct lp_setup_context *setup = lp_setup_context(vbr); + const unsigned stride = setup->vertex_info->size * sizeof(float); + const void *vertex_buffer = setup->vertex_buffer; + const boolean flatshade_first = setup->flatshade_first; + unsigned i; + + assert(setup->setup.variant); + + if (!lp_setup_update_state(setup, TRUE)) + return; + + switch (setup->prim) { + case PIPE_PRIM_POINTS: + for (i = 0; i < nr; i++) { + setup->point( setup, + get_vert(vertex_buffer, indices[i-0], stride) ); + } + break; + + case PIPE_PRIM_LINES: + for (i = 1; i < nr; i += 2) { + setup->line( setup, + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + break; + + case PIPE_PRIM_LINE_STRIP: + for (i = 1; i < nr; i ++) { + setup->line( setup, + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + break; + + case PIPE_PRIM_LINE_LOOP: + for (i = 1; i < nr; i ++) { + setup->line( setup, + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + if (nr) { + setup->line( setup, + get_vert(vertex_buffer, indices[nr-1], stride), + get_vert(vertex_buffer, indices[0], stride) ); + } + break; + + case PIPE_PRIM_TRIANGLES: + for (i = 2; i < nr; i += 3) { + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + break; + + case PIPE_PRIM_TRIANGLE_STRIP: + if (flatshade_first) { + for (i = 2; i < nr; i += 1) { + /* emit first triangle vertex as first triangle vertex */ + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i+(i&1)-1], stride), + get_vert(vertex_buffer, indices[i-(i&1)], stride) ); + + } + } + else { + for (i = 2; i < nr; i += 1) { + /* emit last triangle vertex as last triangle vertex */ + setup->triangle( setup, + get_vert(vertex_buffer, indices[i+(i&1)-2], stride), + get_vert(vertex_buffer, indices[i-(i&1)-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + } + break; + + case PIPE_PRIM_TRIANGLE_FAN: + if (flatshade_first) { + for (i = 2; i < nr; i += 1) { + /* emit first non-spoke vertex as first vertex */ + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride), + get_vert(vertex_buffer, indices[0], stride) ); + } + } + else { + for (i = 2; i < nr; i += 1) { + /* emit last non-spoke vertex as last vertex */ + setup->triangle( setup, + get_vert(vertex_buffer, indices[0], stride), + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + } + break; + + case PIPE_PRIM_QUADS: + /* GL quads don't follow provoking vertex convention */ + if (flatshade_first) { + /* emit last quad vertex as first triangle vertex */ + for (i = 3; i < nr; i += 4) { + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-0], stride), + get_vert(vertex_buffer, indices[i-3], stride), + get_vert(vertex_buffer, indices[i-2], stride) ); + + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-0], stride), + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i-1], stride) ); + } + } + else { + /* emit last quad vertex as last triangle vertex */ + for (i = 3; i < nr; i += 4) { + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-3], stride), + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + } + break; + + case PIPE_PRIM_QUAD_STRIP: + /* GL quad strips don't follow provoking vertex convention */ + if (flatshade_first) { + /* emit last quad vertex as first triangle vertex */ + for (i = 3; i < nr; i += 2) { + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-0], stride), + get_vert(vertex_buffer, indices[i-3], stride), + get_vert(vertex_buffer, indices[i-2], stride) ); + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-0], stride), + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-3], stride) ); + } + } + else { + /* emit last quad vertex as last triangle vertex */ + for (i = 3; i < nr; i += 2) { + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-3], stride), + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-3], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + } + break; + + case PIPE_PRIM_POLYGON: + /* Almost same as tri fan but the _first_ vertex specifies the flat + * shading color. + */ + if (flatshade_first) { + /* emit first polygon vertex as first triangle vertex */ + for (i = 2; i < nr; i += 1) { + setup->triangle( setup, + get_vert(vertex_buffer, indices[0], stride), + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + } + else { + /* emit first polygon vertex as last triangle vertex */ + for (i = 2; i < nr; i += 1) { + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride), + get_vert(vertex_buffer, indices[0], stride) ); + } + } + break; + + default: + assert(0); + } +} + + +/** + * This function is hit when the draw module is working in pass-through mode. + * It's up to us to convert the vertex array into point/line/tri prims. + */ +static void +lp_setup_draw_arrays(struct vbuf_render *vbr, uint start, uint nr) +{ + struct lp_setup_context *setup = lp_setup_context(vbr); + const unsigned stride = setup->vertex_info->size * sizeof(float); + const void *vertex_buffer = + (void *) get_vert(setup->vertex_buffer, start, stride); + const boolean flatshade_first = setup->flatshade_first; + unsigned i; + + if (!lp_setup_update_state(setup, TRUE)) + return; + + switch (setup->prim) { + case PIPE_PRIM_POINTS: + for (i = 0; i < nr; i++) { + setup->point( setup, + get_vert(vertex_buffer, i-0, stride) ); + } + break; + + case PIPE_PRIM_LINES: + for (i = 1; i < nr; i += 2) { + setup->line( setup, + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + break; + + case PIPE_PRIM_LINE_STRIP: + for (i = 1; i < nr; i ++) { + setup->line( setup, + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + break; + + case PIPE_PRIM_LINE_LOOP: + for (i = 1; i < nr; i ++) { + setup->line( setup, + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + if (nr) { + setup->line( setup, + get_vert(vertex_buffer, nr-1, stride), + get_vert(vertex_buffer, 0, stride) ); + } + break; + + case PIPE_PRIM_TRIANGLES: + for (i = 2; i < nr; i += 3) { + setup->triangle( setup, + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + break; + + case PIPE_PRIM_TRIANGLE_STRIP: + if (flatshade_first) { + for (i = 2; i < nr; i++) { + /* emit first triangle vertex as first triangle vertex */ + setup->triangle( setup, + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i+(i&1)-1, stride), + get_vert(vertex_buffer, i-(i&1), stride) ); + } + } + else { + for (i = 2; i < nr; i++) { + /* emit last triangle vertex as last triangle vertex */ + setup->triangle( setup, + get_vert(vertex_buffer, i+(i&1)-2, stride), + get_vert(vertex_buffer, i-(i&1)-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + } + break; + + case PIPE_PRIM_TRIANGLE_FAN: + if (flatshade_first) { + for (i = 2; i < nr; i += 1) { + /* emit first non-spoke vertex as first vertex */ + setup->triangle( setup, + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride), + get_vert(vertex_buffer, 0, stride) ); + } + } + else { + for (i = 2; i < nr; i += 1) { + /* emit last non-spoke vertex as last vertex */ + setup->triangle( setup, + get_vert(vertex_buffer, 0, stride), + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + } + break; + + case PIPE_PRIM_QUADS: + /* GL quads don't follow provoking vertex convention */ + if (flatshade_first) { + /* emit last quad vertex as first triangle vertex */ + for (i = 3; i < nr; i += 4) { + setup->triangle( setup, + get_vert(vertex_buffer, i-0, stride), + get_vert(vertex_buffer, i-3, stride), + get_vert(vertex_buffer, i-2, stride) ); + setup->triangle( setup, + get_vert(vertex_buffer, i-0, stride), + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i-1, stride) ); + } + } + else { + /* emit last quad vertex as last triangle vertex */ + for (i = 3; i < nr; i += 4) { + setup->triangle( setup, + get_vert(vertex_buffer, i-3, stride), + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i-0, stride) ); + setup->triangle( setup, + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + } + break; + + case PIPE_PRIM_QUAD_STRIP: + /* GL quad strips don't follow provoking vertex convention */ + if (flatshade_first) { + /* emit last quad vertex as first triangle vertex */ + for (i = 3; i < nr; i += 2) { + setup->triangle( setup, + get_vert(vertex_buffer, i-0, stride), + get_vert(vertex_buffer, i-3, stride), + get_vert(vertex_buffer, i-2, stride) ); + setup->triangle( setup, + get_vert(vertex_buffer, i-0, stride), + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-3, stride) ); + } + } + else { + /* emit last quad vertex as last triangle vertex */ + for (i = 3; i < nr; i += 2) { + setup->triangle( setup, + get_vert(vertex_buffer, i-3, stride), + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i-0, stride) ); + setup->triangle( setup, + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-3, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + } + break; + + case PIPE_PRIM_POLYGON: + /* Almost same as tri fan but the _first_ vertex specifies the flat + * shading color. + */ + if (flatshade_first) { + /* emit first polygon vertex as first triangle vertex */ + for (i = 2; i < nr; i += 1) { + setup->triangle( setup, + get_vert(vertex_buffer, 0, stride), + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + } + else { + /* emit first polygon vertex as last triangle vertex */ + for (i = 2; i < nr; i += 1) { + setup->triangle( setup, + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride), + get_vert(vertex_buffer, 0, stride) ); + } + } + break; + + default: + assert(0); + } +} + + + +static void +lp_setup_vbuf_destroy(struct vbuf_render *vbr) +{ + struct lp_setup_context *setup = lp_setup_context(vbr); + if (setup->vertex_buffer) { + align_free(setup->vertex_buffer); + setup->vertex_buffer = NULL; + } + lp_setup_destroy(setup); +} + + +/** + * Create the post-transform vertex handler for the given context. + */ +void +lp_setup_init_vbuf(struct lp_setup_context *setup) +{ + setup->base.max_indices = LP_MAX_VBUF_INDEXES; + setup->base.max_vertex_buffer_bytes = LP_MAX_VBUF_SIZE; + + setup->base.get_vertex_info = lp_setup_get_vertex_info; + setup->base.allocate_vertices = lp_setup_allocate_vertices; + setup->base.map_vertices = lp_setup_map_vertices; + setup->base.unmap_vertices = lp_setup_unmap_vertices; + setup->base.set_primitive = lp_setup_set_primitive; + setup->base.draw_elements = lp_setup_draw_elements; + setup->base.draw_arrays = lp_setup_draw_arrays; + setup->base.release_vertices = lp_setup_release_vertices; + setup->base.destroy = lp_setup_vbuf_destroy; +} diff --git a/src/gallium/drivers/llvmpipe/lp_state.h b/src/gallium/drivers/llvmpipe/lp_state.h new file mode 100644 index 0000000..7893e9c --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state.h @@ -0,0 +1,144 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef LP_STATE_H +#define LP_STATE_H + +#include "pipe/p_state.h" +#include "lp_jit.h" +#include "lp_state_fs.h" +#include "gallivm/lp_bld.h" + + +#define LP_NEW_VIEWPORT 0x1 +#define LP_NEW_RASTERIZER 0x2 +#define LP_NEW_FS 0x4 +#define LP_NEW_BLEND 0x8 +#define LP_NEW_CLIP 0x10 +#define LP_NEW_SCISSOR 0x20 +#define LP_NEW_STIPPLE 0x40 +#define LP_NEW_FRAMEBUFFER 0x80 +#define LP_NEW_DEPTH_STENCIL_ALPHA 0x100 +#define LP_NEW_CONSTANTS 0x200 +#define LP_NEW_SAMPLER 0x400 +#define LP_NEW_SAMPLER_VIEW 0x800 +#define LP_NEW_VERTEX 0x1000 +#define LP_NEW_VS 0x2000 +#define LP_NEW_QUERY 0x4000 +#define LP_NEW_BLEND_COLOR 0x8000 +#define LP_NEW_GS 0x10000 +#define LP_NEW_SO 0x20000 +#define LP_NEW_SO_BUFFERS 0x40000 + + + +struct vertex_info; +struct pipe_context; +struct llvmpipe_context; + + + +/** Subclass of pipe_shader_state */ +struct lp_vertex_shader +{ + struct pipe_shader_state shader; + struct draw_vertex_shader *draw_data; +}; + +/** Subclass of pipe_shader_state */ +struct lp_geometry_shader { + struct pipe_shader_state shader; + struct draw_geometry_shader *draw_data; +}; + +/** Vertex element state */ +struct lp_velems_state +{ + unsigned count; + struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS]; +}; + +struct lp_so_state { + struct pipe_stream_output_state base; +}; + + +void +llvmpipe_set_framebuffer_state(struct pipe_context *, + const struct pipe_framebuffer_state *); + +void +llvmpipe_update_fs(struct llvmpipe_context *lp); + +void +llvmpipe_update_setup(struct llvmpipe_context *lp); + +void +llvmpipe_update_derived(struct llvmpipe_context *llvmpipe); + +void +llvmpipe_init_sampler_funcs(struct llvmpipe_context *llvmpipe); + +void +llvmpipe_init_blend_funcs(struct llvmpipe_context *llvmpipe); + +void +llvmpipe_init_vertex_funcs(struct llvmpipe_context *llvmpipe); + +void +llvmpipe_init_draw_funcs(struct llvmpipe_context *llvmpipe); + +void +llvmpipe_init_clip_funcs(struct llvmpipe_context *llvmpipe); + +void +llvmpipe_init_fs_funcs(struct llvmpipe_context *llvmpipe); + +void +llvmpipe_init_vs_funcs(struct llvmpipe_context *llvmpipe); + +void +llvmpipe_init_gs_funcs(struct llvmpipe_context *llvmpipe); + +void +llvmpipe_init_rasterizer_funcs(struct llvmpipe_context *llvmpipe); + +void +llvmpipe_init_so_funcs(struct llvmpipe_context *llvmpipe); + +void +llvmpipe_prepare_vertex_sampling(struct llvmpipe_context *ctx, + unsigned num, + struct pipe_sampler_view **views); +void +llvmpipe_cleanup_vertex_sampling(struct llvmpipe_context *ctx); + + +#endif diff --git a/src/gallium/drivers/llvmpipe/lp_state_blend.c b/src/gallium/drivers/llvmpipe/lp_state_blend.c new file mode 100644 index 0000000..6bba907 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state_blend.c @@ -0,0 +1,197 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @author Jose Fonseca + * @author Keith Whitwell + */ + +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_dump.h" +#include "draw/draw_context.h" +#include "lp_screen.h" +#include "lp_context.h" +#include "lp_state.h" +#include "lp_debug.h" + + +static void * +llvmpipe_create_blend_state(struct pipe_context *pipe, + const struct pipe_blend_state *blend) +{ + struct pipe_blend_state *state = mem_dup(blend, sizeof *blend); + int i; + + if (LP_PERF & PERF_NO_BLEND) { + state->independent_blend_enable = 0; + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) + state->rt[i].blend_enable = 0; + } + + return state; +} + + +static void +llvmpipe_bind_blend_state(struct pipe_context *pipe, void *blend) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + if (llvmpipe->blend == blend) + return; + + draw_flush(llvmpipe->draw); + + llvmpipe->blend = blend; + + llvmpipe->dirty |= LP_NEW_BLEND; +} + + +static void +llvmpipe_delete_blend_state(struct pipe_context *pipe, void *blend) +{ + FREE( blend ); +} + + +static void +llvmpipe_set_blend_color(struct pipe_context *pipe, + const struct pipe_blend_color *blend_color) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + if(!blend_color) + return; + + if(memcmp(&llvmpipe->blend_color, blend_color, sizeof *blend_color) == 0) + return; + + draw_flush(llvmpipe->draw); + + memcpy(&llvmpipe->blend_color, blend_color, sizeof *blend_color); + + llvmpipe->dirty |= LP_NEW_BLEND_COLOR; +} + + +/** XXX move someday? Or consolidate all these simple state setters + * into one file. + */ + + +static void * +llvmpipe_create_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_alpha_state *depth_stencil) +{ + struct pipe_depth_stencil_alpha_state *state; + + state = mem_dup(depth_stencil, sizeof *depth_stencil); + + if (LP_PERF & PERF_NO_DEPTH) { + state->depth.enabled = 0; + state->depth.writemask = 0; + state->stencil[0].enabled = 0; + state->stencil[1].enabled = 0; + } + + if (LP_PERF & PERF_NO_ALPHATEST) { + state->alpha.enabled = 0; + } + + return state; +} + + +static void +llvmpipe_bind_depth_stencil_state(struct pipe_context *pipe, + void *depth_stencil) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + if (llvmpipe->depth_stencil == depth_stencil) + return; + + draw_flush(llvmpipe->draw); + + llvmpipe->depth_stencil = depth_stencil; + + llvmpipe->dirty |= LP_NEW_DEPTH_STENCIL_ALPHA; +} + + +static void +llvmpipe_delete_depth_stencil_state(struct pipe_context *pipe, void *depth) +{ + FREE( depth ); +} + + +static void +llvmpipe_set_stencil_ref(struct pipe_context *pipe, + const struct pipe_stencil_ref *stencil_ref) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + if(!stencil_ref) + return; + + if(memcmp(&llvmpipe->stencil_ref, stencil_ref, sizeof *stencil_ref) == 0) + return; + + draw_flush(llvmpipe->draw); + + memcpy(&llvmpipe->stencil_ref, stencil_ref, sizeof *stencil_ref); + + /* not sure. want new flag? */ + llvmpipe->dirty |= LP_NEW_DEPTH_STENCIL_ALPHA; +} + +static void +llvmpipe_set_sample_mask(struct pipe_context *pipe, + unsigned sample_mask) +{ +} + +void +llvmpipe_init_blend_funcs(struct llvmpipe_context *llvmpipe) +{ + llvmpipe->pipe.create_blend_state = llvmpipe_create_blend_state; + llvmpipe->pipe.bind_blend_state = llvmpipe_bind_blend_state; + llvmpipe->pipe.delete_blend_state = llvmpipe_delete_blend_state; + + llvmpipe->pipe.create_depth_stencil_alpha_state = llvmpipe_create_depth_stencil_state; + llvmpipe->pipe.bind_depth_stencil_alpha_state = llvmpipe_bind_depth_stencil_state; + llvmpipe->pipe.delete_depth_stencil_alpha_state = llvmpipe_delete_depth_stencil_state; + + llvmpipe->pipe.set_blend_color = llvmpipe_set_blend_color; + + llvmpipe->pipe.set_stencil_ref = llvmpipe_set_stencil_ref; + llvmpipe->pipe.set_sample_mask = llvmpipe_set_sample_mask; +} diff --git a/src/gallium/drivers/llvmpipe/lp_state_clip.c b/src/gallium/drivers/llvmpipe/lp_state_clip.c new file mode 100644 index 0000000..32ae079 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state_clip.c @@ -0,0 +1,94 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ +#include "lp_context.h" +#include "lp_state.h" +#include "draw/draw_context.h" + + +static void +llvmpipe_set_clip_state(struct pipe_context *pipe, + const struct pipe_clip_state *clip) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + /* pass the clip state to the draw module */ + draw_set_clip_state(llvmpipe->draw, clip); +} + + +static void +llvmpipe_set_viewport_state(struct pipe_context *pipe, + const struct pipe_viewport_state *viewport) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + /* pass the viewport info to the draw module */ + draw_set_viewport_state(llvmpipe->draw, viewport); + + llvmpipe->viewport = *viewport; /* struct copy */ + llvmpipe->dirty |= LP_NEW_VIEWPORT; +} + + +static void +llvmpipe_set_scissor_state(struct pipe_context *pipe, + const struct pipe_scissor_state *scissor) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + draw_flush(llvmpipe->draw); + + llvmpipe->scissor = *scissor; /* struct copy */ + llvmpipe->dirty |= LP_NEW_SCISSOR; +} + + +static void +llvmpipe_set_polygon_stipple(struct pipe_context *pipe, + const struct pipe_poly_stipple *stipple) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + draw_flush(llvmpipe->draw); + + llvmpipe->poly_stipple = *stipple; /* struct copy */ + llvmpipe->dirty |= LP_NEW_STIPPLE; +} + + + +void +llvmpipe_init_clip_funcs(struct llvmpipe_context *llvmpipe) +{ + llvmpipe->pipe.set_clip_state = llvmpipe_set_clip_state; + llvmpipe->pipe.set_polygon_stipple = llvmpipe_set_polygon_stipple; + llvmpipe->pipe.set_scissor_state = llvmpipe_set_scissor_state; + llvmpipe->pipe.set_viewport_state = llvmpipe_set_viewport_state; +} diff --git a/src/gallium/drivers/llvmpipe/lp_state_derived.c b/src/gallium/drivers/llvmpipe/lp_state_derived.c new file mode 100644 index 0000000..8725ea3 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state_derived.c @@ -0,0 +1,191 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "pipe/p_shader_tokens.h" +#include "draw/draw_context.h" +#include "draw/draw_vertex.h" +#include "draw/draw_private.h" +#include "lp_context.h" +#include "lp_screen.h" +#include "lp_setup.h" +#include "lp_state.h" + + + +/** + * The vertex info describes how to convert the post-transformed vertices + * (simple float[][4]) used by the 'draw' module into vertices for + * rasterization. + * + * This function validates the vertex layout. + */ +static void +compute_vertex_info(struct llvmpipe_context *llvmpipe) +{ + const struct lp_fragment_shader *lpfs = llvmpipe->fs; + struct vertex_info *vinfo = &llvmpipe->vertex_info; + unsigned vs_index; + uint i; + + llvmpipe->color_slot[0] = ~0; + llvmpipe->color_slot[1] = ~0; + llvmpipe->bcolor_slot[0] = ~0; + llvmpipe->bcolor_slot[1] = ~0; + + /* + * Match FS inputs against VS outputs, emitting the necessary + * attributes. Could cache these structs and look them up with a + * combination of fragment shader, vertex shader ids. + */ + + vinfo->num_attribs = 0; + + vs_index = draw_find_shader_output(llvmpipe->draw, + TGSI_SEMANTIC_POSITION, + 0); + + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, vs_index); + + for (i = 0; i < lpfs->info.base.num_inputs; i++) { + /* + * Search for each input in current vs output: + */ + + vs_index = draw_find_shader_output(llvmpipe->draw, + lpfs->info.base.input_semantic_name[i], + lpfs->info.base.input_semantic_index[i]); + + if (lpfs->info.base.input_semantic_name[i] == TGSI_SEMANTIC_COLOR && + lpfs->info.base.input_semantic_index[i] < 2) { + int idx = lpfs->info.base.input_semantic_index[i]; + llvmpipe->color_slot[idx] = vinfo->num_attribs; + } + + /* + * Emit the requested fs attribute for all but position. + */ + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, vs_index); + } + + /* Figure out if we need bcolor as well. + */ + for (i = 0; i < 2; i++) { + vs_index = draw_find_shader_output(llvmpipe->draw, + TGSI_SEMANTIC_BCOLOR, i); + + if (vs_index > 0) { + llvmpipe->bcolor_slot[i] = vinfo->num_attribs; + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, vs_index); + } + } + + + /* Figure out if we need pointsize as well. + */ + vs_index = draw_find_shader_output(llvmpipe->draw, + TGSI_SEMANTIC_PSIZE, 0); + + if (vs_index > 0) { + llvmpipe->psize_slot = vinfo->num_attribs; + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_CONSTANT, vs_index); + } + + draw_compute_vertex_size(vinfo); + lp_setup_set_vertex_info(llvmpipe->setup, vinfo); +} + + +/** + * Handle state changes. + * Called just prior to drawing anything (pipe::draw_arrays(), etc). + * + * Hopefully this will remain quite simple, otherwise need to pull in + * something like the state tracker mechanism. + */ +void llvmpipe_update_derived( struct llvmpipe_context *llvmpipe ) +{ + struct llvmpipe_screen *lp_screen = llvmpipe_screen(llvmpipe->pipe.screen); + + /* Check for updated textures. + */ + if (llvmpipe->tex_timestamp != lp_screen->timestamp) { + llvmpipe->tex_timestamp = lp_screen->timestamp; + llvmpipe->dirty |= LP_NEW_SAMPLER_VIEW; + } + + if (llvmpipe->dirty & (LP_NEW_RASTERIZER | + LP_NEW_FS | + LP_NEW_VS)) + compute_vertex_info( llvmpipe ); + + if (llvmpipe->dirty & (LP_NEW_FS | + LP_NEW_BLEND | + LP_NEW_SCISSOR | + LP_NEW_DEPTH_STENCIL_ALPHA | + LP_NEW_RASTERIZER | + LP_NEW_SAMPLER | + LP_NEW_SAMPLER_VIEW | + LP_NEW_QUERY)) + llvmpipe_update_fs( llvmpipe ); + + if (llvmpipe->dirty & (LP_NEW_FS | + LP_NEW_RASTERIZER)) + llvmpipe_update_setup( llvmpipe ); + + if (llvmpipe->dirty & LP_NEW_BLEND_COLOR) + lp_setup_set_blend_color(llvmpipe->setup, + &llvmpipe->blend_color); + + if (llvmpipe->dirty & LP_NEW_SCISSOR) + lp_setup_set_scissor(llvmpipe->setup, &llvmpipe->scissor); + + if (llvmpipe->dirty & LP_NEW_DEPTH_STENCIL_ALPHA) { + lp_setup_set_alpha_ref_value(llvmpipe->setup, + llvmpipe->depth_stencil->alpha.ref_value); + lp_setup_set_stencil_ref_values(llvmpipe->setup, + llvmpipe->stencil_ref.ref_value); + } + + if (llvmpipe->dirty & LP_NEW_CONSTANTS) + lp_setup_set_fs_constants(llvmpipe->setup, + llvmpipe->constants[PIPE_SHADER_FRAGMENT][0]); + + if (llvmpipe->dirty & (LP_NEW_SAMPLER_VIEW)) + lp_setup_set_fragment_sampler_views(llvmpipe->setup, + llvmpipe->num_fragment_sampler_views, + llvmpipe->fragment_sampler_views); + + if (llvmpipe->dirty & (LP_NEW_SAMPLER)) + lp_setup_set_fragment_sampler_state(llvmpipe->setup, + llvmpipe->num_samplers, + llvmpipe->sampler); + + llvmpipe->dirty = 0; +} + diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c new file mode 100644 index 0000000..2c4943a --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -0,0 +1,1404 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Code generate the whole fragment pipeline. + * + * The fragment pipeline consists of the following stages: + * - early depth test + * - fragment shader + * - alpha test + * - depth/stencil test + * - blending + * + * This file has only the glue to assemble the fragment pipeline. The actual + * plumbing of converting Gallium state into LLVM IR is done elsewhere, in the + * lp_bld_*.[ch] files, and in a complete generic and reusable way. Here we + * muster the LLVM JIT execution engine to create a function that follows an + * established binary interface and that can be called from C directly. + * + * A big source of complexity here is that we often want to run different + * stages with different precisions and data types and precisions. For example, + * the fragment shader needs typically to be done in floats, but the + * depth/stencil test and blending is better done in the type that most closely + * matches the depth/stencil and color buffer respectively. + * + * Since the width of a SIMD vector register stays the same regardless of the + * element type, different types imply different number of elements, so we must + * code generate more instances of the stages with larger types to be able to + * feed/consume the stages with smaller types. + * + * @author Jose Fonseca + */ + +#include +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_pointer.h" +#include "util/u_format.h" +#include "util/u_dump.h" +#include "util/u_string.h" +#include "util/u_simple_list.h" +#include "os/os_time.h" +#include "pipe/p_shader_tokens.h" +#include "draw/draw_context.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_scan.h" +#include "tgsi/tgsi_parse.h" +#include "gallivm/lp_bld_type.h" +#include "gallivm/lp_bld_const.h" +#include "gallivm/lp_bld_conv.h" +#include "gallivm/lp_bld_init.h" +#include "gallivm/lp_bld_intr.h" +#include "gallivm/lp_bld_logic.h" +#include "gallivm/lp_bld_tgsi.h" +#include "gallivm/lp_bld_swizzle.h" +#include "gallivm/lp_bld_flow.h" +#include "gallivm/lp_bld_debug.h" + +#include "lp_bld_alpha.h" +#include "lp_bld_blend.h" +#include "lp_bld_depth.h" +#include "lp_bld_interp.h" +#include "lp_context.h" +#include "lp_debug.h" +#include "lp_perf.h" +#include "lp_screen.h" +#include "lp_setup.h" +#include "lp_state.h" +#include "lp_tex_sample.h" +#include "lp_flush.h" +#include "lp_state_fs.h" + + +#include +#include + + +/** Fragment shader number (for debugging) */ +static unsigned fs_no = 0; + + +/** + * Expand the relevent bits of mask_input to a 4-dword mask for the + * four pixels in a 2x2 quad. This will set the four elements of the + * quad mask vector to 0 or ~0. + * + * \param quad which quad of the quad group to test, in [0,3] + * \param mask_input bitwise mask for the whole 4x4 stamp + */ +static LLVMValueRef +generate_quad_mask(struct gallivm_state *gallivm, + struct lp_type fs_type, + unsigned quad, + LLVMValueRef mask_input) /* int32 */ +{ + LLVMBuilderRef builder = gallivm->builder; + struct lp_type mask_type; + LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context); + LLVMValueRef bits[4]; + LLVMValueRef mask; + int shift; + + /* + * XXX: We'll need a different path for 16 x u8 + */ + assert(fs_type.width == 32); + assert(fs_type.length == 4); + mask_type = lp_int_type(fs_type); + + /* + * mask_input >>= (quad * 4) + */ + switch (quad) { + case 0: + shift = 0; + break; + case 1: + shift = 2; + break; + case 2: + shift = 8; + break; + case 3: + shift = 10; + break; + default: + assert(0); + shift = 0; + } + + mask_input = LLVMBuildLShr(builder, + mask_input, + LLVMConstInt(i32t, shift, 0), + ""); + + /* + * mask = { mask_input & (1 << i), for i in [0,3] } + */ + mask = lp_build_broadcast(gallivm, + lp_build_vec_type(gallivm, mask_type), + mask_input); + + bits[0] = LLVMConstInt(i32t, 1 << 0, 0); + bits[1] = LLVMConstInt(i32t, 1 << 1, 0); + bits[2] = LLVMConstInt(i32t, 1 << 4, 0); + bits[3] = LLVMConstInt(i32t, 1 << 5, 0); + + mask = LLVMBuildAnd(builder, mask, LLVMConstVector(bits, 4), ""); + + /* + * mask = mask != 0 ? ~0 : 0 + */ + mask = lp_build_compare(gallivm, + mask_type, PIPE_FUNC_NOTEQUAL, + mask, + lp_build_const_int_vec(gallivm, mask_type, 0)); + + return mask; +} + + +#define EARLY_DEPTH_TEST 0x1 +#define LATE_DEPTH_TEST 0x2 +#define EARLY_DEPTH_WRITE 0x4 +#define LATE_DEPTH_WRITE 0x8 + +static int +find_output_by_semantic( const struct tgsi_shader_info *info, + unsigned semantic, + unsigned index ) +{ + int i; + + for (i = 0; i < info->num_outputs; i++) + if (info->output_semantic_name[i] == semantic && + info->output_semantic_index[i] == index) + return i; + + return -1; +} + + +/** + * Generate the fragment shader, depth/stencil test, and alpha tests. + * \param i which quad in the tile, in range [0,3] + * \param partial_mask if 1, do mask_input testing + */ +static void +generate_fs(struct gallivm_state *gallivm, + struct lp_fragment_shader *shader, + const struct lp_fragment_shader_variant_key *key, + LLVMBuilderRef builder, + struct lp_type type, + LLVMValueRef context_ptr, + unsigned i, + struct lp_build_interp_soa_context *interp, + struct lp_build_sampler_soa *sampler, + LLVMValueRef *pmask, + LLVMValueRef (*color)[4], + LLVMValueRef depth_ptr, + LLVMValueRef facing, + unsigned partial_mask, + LLVMValueRef mask_input, + LLVMValueRef counter) +{ + const struct util_format_description *zs_format_desc = NULL; + const struct tgsi_token *tokens = shader->base.tokens; + LLVMTypeRef vec_type; + LLVMValueRef consts_ptr; + LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][NUM_CHANNELS]; + LLVMValueRef z; + LLVMValueRef zs_value = NULL; + LLVMValueRef stencil_refs[2]; + struct lp_build_mask_context mask; + boolean simple_shader = (shader->info.base.file_count[TGSI_FILE_SAMPLER] == 0 && + shader->info.base.num_inputs < 3 && + shader->info.base.num_instructions < 8); + unsigned attrib; + unsigned chan; + unsigned cbuf; + unsigned depth_mode; + + if (key->depth.enabled || + key->stencil[0].enabled || + key->stencil[1].enabled) { + + zs_format_desc = util_format_description(key->zsbuf_format); + assert(zs_format_desc); + + if (!shader->info.base.writes_z) { + if (key->alpha.enabled || shader->info.base.uses_kill) + /* With alpha test and kill, can do the depth test early + * and hopefully eliminate some quads. But need to do a + * special deferred depth write once the final mask value + * is known. + */ + depth_mode = EARLY_DEPTH_TEST | LATE_DEPTH_WRITE; + else + depth_mode = EARLY_DEPTH_TEST | EARLY_DEPTH_WRITE; + } + else { + depth_mode = LATE_DEPTH_TEST | LATE_DEPTH_WRITE; + } + + if (!(key->depth.enabled && key->depth.writemask) && + !(key->stencil[0].enabled && key->stencil[0].writemask)) + depth_mode &= ~(LATE_DEPTH_WRITE | EARLY_DEPTH_WRITE); + } + else { + depth_mode = 0; + } + + assert(i < 4); + + stencil_refs[0] = lp_jit_context_stencil_ref_front_value(gallivm, context_ptr); + stencil_refs[1] = lp_jit_context_stencil_ref_back_value(gallivm, context_ptr); + + vec_type = lp_build_vec_type(gallivm, type); + + consts_ptr = lp_jit_context_constants(gallivm, context_ptr); + + memset(outputs, 0, sizeof outputs); + + /* Declare the color and z variables */ + for(cbuf = 0; cbuf < key->nr_cbufs; cbuf++) { + for(chan = 0; chan < NUM_CHANNELS; ++chan) { + color[cbuf][chan] = lp_build_alloca(gallivm, vec_type, "color"); + } + } + + /* do triangle edge testing */ + if (partial_mask) { + *pmask = generate_quad_mask(gallivm, type, + i, mask_input); + } + else { + *pmask = lp_build_const_int_vec(gallivm, type, ~0); + } + + /* 'mask' will control execution based on quad's pixel alive/killed state */ + lp_build_mask_begin(&mask, gallivm, type, *pmask); + + if (!(depth_mode & EARLY_DEPTH_TEST) && !simple_shader) + lp_build_mask_check(&mask); + + lp_build_interp_soa_update_pos(interp, gallivm, i); + z = interp->pos[2]; + + if (depth_mode & EARLY_DEPTH_TEST) { + lp_build_depth_stencil_test(gallivm, + &key->depth, + key->stencil, + type, + zs_format_desc, + &mask, + stencil_refs, + z, + depth_ptr, facing, + &zs_value, + !simple_shader); + + if (depth_mode & EARLY_DEPTH_WRITE) { + lp_build_depth_write(builder, zs_format_desc, depth_ptr, zs_value); + } + } + + lp_build_interp_soa_update_inputs(interp, gallivm, i); + + /* Build the actual shader */ + lp_build_tgsi_soa(gallivm, tokens, type, &mask, + consts_ptr, interp->pos, interp->inputs, + outputs, sampler, &shader->info.base); + + /* Alpha test */ + if (key->alpha.enabled) { + int color0 = find_output_by_semantic(&shader->info.base, + TGSI_SEMANTIC_COLOR, + 0); + + if (color0 != -1 && outputs[color0][3]) { + LLVMValueRef alpha = LLVMBuildLoad(builder, outputs[color0][3], "alpha"); + LLVMValueRef alpha_ref_value; + + alpha_ref_value = lp_jit_context_alpha_ref_value(gallivm, context_ptr); + alpha_ref_value = lp_build_broadcast(gallivm, vec_type, alpha_ref_value); + + lp_build_alpha_test(gallivm, key->alpha.func, type, + &mask, alpha, alpha_ref_value, + (depth_mode & LATE_DEPTH_TEST) != 0); + } + } + + /* Late Z test */ + if (depth_mode & LATE_DEPTH_TEST) { + int pos0 = find_output_by_semantic(&shader->info.base, + TGSI_SEMANTIC_POSITION, + 0); + + if (pos0 != -1 && outputs[pos0][2]) { + z = LLVMBuildLoad(builder, outputs[pos0][2], "output.z"); + } + + lp_build_depth_stencil_test(gallivm, + &key->depth, + key->stencil, + type, + zs_format_desc, + &mask, + stencil_refs, + z, + depth_ptr, facing, + &zs_value, + !simple_shader); + /* Late Z write */ + if (depth_mode & LATE_DEPTH_WRITE) { + lp_build_depth_write(builder, zs_format_desc, depth_ptr, zs_value); + } + } + else if ((depth_mode & EARLY_DEPTH_TEST) && + (depth_mode & LATE_DEPTH_WRITE)) + { + /* Need to apply a reduced mask to the depth write. Reload the + * depth value, update from zs_value with the new mask value and + * write that out. + */ + lp_build_deferred_depth_write(gallivm, + type, + zs_format_desc, + &mask, + depth_ptr, + zs_value); + } + + + /* Color write */ + for (attrib = 0; attrib < shader->info.base.num_outputs; ++attrib) + { + if (shader->info.base.output_semantic_name[attrib] == TGSI_SEMANTIC_COLOR && + shader->info.base.output_semantic_index[attrib] < key->nr_cbufs) + { + unsigned cbuf = shader->info.base.output_semantic_index[attrib]; + for(chan = 0; chan < NUM_CHANNELS; ++chan) { + if(outputs[attrib][chan]) { + /* XXX: just initialize outputs to point at colors[] and + * skip this. + */ + LLVMValueRef out = LLVMBuildLoad(builder, outputs[attrib][chan], ""); + lp_build_name(out, "color%u.%u.%c", i, attrib, "rgba"[chan]); + LLVMBuildStore(builder, out, color[cbuf][chan]); + } + } + } + } + + if (counter) + lp_build_occlusion_count(gallivm, type, + lp_build_mask_value(&mask), counter); + + *pmask = lp_build_mask_end(&mask); +} + + +/** + * Generate color blending and color output. + * \param rt the render target index (to index blend, colormask state) + * \param type the pixel color type + * \param context_ptr pointer to the runtime JIT context + * \param mask execution mask (active fragment/pixel mask) + * \param src colors from the fragment shader + * \param dst_ptr the destination color buffer pointer + */ +static void +generate_blend(struct gallivm_state *gallivm, + const struct pipe_blend_state *blend, + unsigned rt, + LLVMBuilderRef builder, + struct lp_type type, + LLVMValueRef context_ptr, + LLVMValueRef mask, + LLVMValueRef *src, + LLVMValueRef dst_ptr, + boolean do_branch) +{ + struct lp_build_context bld; + struct lp_build_mask_context mask_ctx; + LLVMTypeRef vec_type; + LLVMValueRef const_ptr; + LLVMValueRef con[4]; + LLVMValueRef dst[4]; + LLVMValueRef res[4]; + unsigned chan; + + lp_build_context_init(&bld, gallivm, type); + + lp_build_mask_begin(&mask_ctx, gallivm, type, mask); + if (do_branch) + lp_build_mask_check(&mask_ctx); + + vec_type = lp_build_vec_type(gallivm, type); + + const_ptr = lp_jit_context_blend_color(gallivm, context_ptr); + const_ptr = LLVMBuildBitCast(builder, const_ptr, + LLVMPointerType(vec_type, 0), ""); + + /* load constant blend color and colors from the dest color buffer */ + for(chan = 0; chan < 4; ++chan) { + LLVMValueRef index = lp_build_const_int32(gallivm, chan); + con[chan] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, const_ptr, &index, 1, ""), ""); + + dst[chan] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, dst_ptr, &index, 1, ""), ""); + + lp_build_name(con[chan], "con.%c", "rgba"[chan]); + lp_build_name(dst[chan], "dst.%c", "rgba"[chan]); + } + + /* do blend */ + lp_build_blend_soa(gallivm, blend, type, rt, src, dst, con, res); + + /* store results to color buffer */ + for(chan = 0; chan < 4; ++chan) { + if(blend->rt[rt].colormask & (1 << chan)) { + LLVMValueRef index = lp_build_const_int32(gallivm, chan); + lp_build_name(res[chan], "res.%c", "rgba"[chan]); + res[chan] = lp_build_select(&bld, mask, res[chan], dst[chan]); + LLVMBuildStore(builder, res[chan], LLVMBuildGEP(builder, dst_ptr, &index, 1, "")); + } + } + + lp_build_mask_end(&mask_ctx); +} + + +/** + * Generate the runtime callable function for the whole fragment pipeline. + * Note that the function which we generate operates on a block of 16 + * pixels at at time. The block contains 2x2 quads. Each quad contains + * 2x2 pixels. + */ +static void +generate_fragment(struct llvmpipe_context *lp, + struct lp_fragment_shader *shader, + struct lp_fragment_shader_variant *variant, + unsigned partial_mask) +{ + struct gallivm_state *gallivm = lp->gallivm; + const struct lp_fragment_shader_variant_key *key = &variant->key; + struct lp_shader_input inputs[PIPE_MAX_SHADER_INPUTS]; + char func_name[256]; + struct lp_type fs_type; + struct lp_type blend_type; + LLVMTypeRef fs_elem_type; + LLVMTypeRef fs_int_vec_type; + LLVMTypeRef blend_vec_type; + LLVMTypeRef arg_types[11]; + LLVMTypeRef func_type; + LLVMTypeRef int32_type = LLVMInt32TypeInContext(gallivm->context); + LLVMTypeRef int8_type = LLVMInt8TypeInContext(gallivm->context); + LLVMValueRef context_ptr; + LLVMValueRef x; + LLVMValueRef y; + LLVMValueRef a0_ptr; + LLVMValueRef dadx_ptr; + LLVMValueRef dady_ptr; + LLVMValueRef color_ptr_ptr; + LLVMValueRef depth_ptr; + LLVMValueRef mask_input; + LLVMValueRef counter = NULL; + LLVMBasicBlockRef block; + LLVMBuilderRef builder; + struct lp_build_sampler_soa *sampler; + struct lp_build_interp_soa_context interp; + LLVMValueRef fs_mask[LP_MAX_VECTOR_LENGTH]; + LLVMValueRef fs_out_color[PIPE_MAX_COLOR_BUFS][NUM_CHANNELS][LP_MAX_VECTOR_LENGTH]; + LLVMValueRef blend_mask; + LLVMValueRef function; + LLVMValueRef facing; + const struct util_format_description *zs_format_desc; + unsigned num_fs; + unsigned i; + unsigned chan; + unsigned cbuf; + + /* Adjust color input interpolation according to flatshade state: + */ + memcpy(inputs, shader->inputs, shader->info.base.num_inputs * sizeof inputs[0]); + for (i = 0; i < shader->info.base.num_inputs; i++) { + if (inputs[i].interp == LP_INTERP_COLOR) { + if (key->flatshade) + inputs[i].interp = LP_INTERP_CONSTANT; + else + inputs[i].interp = LP_INTERP_LINEAR; + } + } + + + /* TODO: actually pick these based on the fs and color buffer + * characteristics. */ + + memset(&fs_type, 0, sizeof fs_type); + fs_type.floating = TRUE; /* floating point values */ + fs_type.sign = TRUE; /* values are signed */ + fs_type.norm = FALSE; /* values are not limited to [0,1] or [-1,1] */ + fs_type.width = 32; /* 32-bit float */ + fs_type.length = 4; /* 4 elements per vector */ + num_fs = 4; /* number of quads per block */ + + memset(&blend_type, 0, sizeof blend_type); + blend_type.floating = FALSE; /* values are integers */ + blend_type.sign = FALSE; /* values are unsigned */ + blend_type.norm = TRUE; /* values are in [0,1] or [-1,1] */ + blend_type.width = 8; /* 8-bit ubyte values */ + blend_type.length = 16; /* 16 elements per vector */ + + /* + * Generate the function prototype. Any change here must be reflected in + * lp_jit.h's lp_jit_frag_func function pointer type, and vice-versa. + */ + + fs_elem_type = lp_build_elem_type(gallivm, fs_type); + fs_int_vec_type = lp_build_int_vec_type(gallivm, fs_type); + + blend_vec_type = lp_build_vec_type(gallivm, blend_type); + + util_snprintf(func_name, sizeof(func_name), "fs%u_variant%u_%s", + shader->no, variant->no, partial_mask ? "partial" : "whole"); + + arg_types[0] = lp_jit_get_context_type(lp); /* context */ + arg_types[1] = int32_type; /* x */ + arg_types[2] = int32_type; /* y */ + arg_types[3] = int32_type; /* facing */ + arg_types[4] = LLVMPointerType(fs_elem_type, 0); /* a0 */ + arg_types[5] = LLVMPointerType(fs_elem_type, 0); /* dadx */ + arg_types[6] = LLVMPointerType(fs_elem_type, 0); /* dady */ + arg_types[7] = LLVMPointerType(LLVMPointerType(blend_vec_type, 0), 0); /* color */ + arg_types[8] = LLVMPointerType(int8_type, 0); /* depth */ + arg_types[9] = int32_type; /* mask_input */ + arg_types[10] = LLVMPointerType(int32_type, 0); /* counter */ + + func_type = LLVMFunctionType(LLVMVoidTypeInContext(gallivm->context), + arg_types, Elements(arg_types), 0); + + function = LLVMAddFunction(gallivm->module, func_name, func_type); + LLVMSetFunctionCallConv(function, LLVMCCallConv); + + variant->function[partial_mask] = function; + + /* XXX: need to propagate noalias down into color param now we are + * passing a pointer-to-pointer? + */ + for(i = 0; i < Elements(arg_types); ++i) + if(LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind) + LLVMAddAttribute(LLVMGetParam(function, i), LLVMNoAliasAttribute); + + context_ptr = LLVMGetParam(function, 0); + x = LLVMGetParam(function, 1); + y = LLVMGetParam(function, 2); + facing = LLVMGetParam(function, 3); + a0_ptr = LLVMGetParam(function, 4); + dadx_ptr = LLVMGetParam(function, 5); + dady_ptr = LLVMGetParam(function, 6); + color_ptr_ptr = LLVMGetParam(function, 7); + depth_ptr = LLVMGetParam(function, 8); + mask_input = LLVMGetParam(function, 9); + + lp_build_name(context_ptr, "context"); + lp_build_name(x, "x"); + lp_build_name(y, "y"); + lp_build_name(a0_ptr, "a0"); + lp_build_name(dadx_ptr, "dadx"); + lp_build_name(dady_ptr, "dady"); + lp_build_name(color_ptr_ptr, "color_ptr_ptr"); + lp_build_name(depth_ptr, "depth"); + lp_build_name(mask_input, "mask_input"); + + if (key->occlusion_count) { + counter = LLVMGetParam(function, 10); + lp_build_name(counter, "counter"); + } + + /* + * Function body + */ + + block = LLVMAppendBasicBlockInContext(gallivm->context, function, "entry"); + builder = gallivm->builder; + assert(builder); + LLVMPositionBuilderAtEnd(builder, block); + + /* + * The shader input interpolation info is not explicitely baked in the + * shader key, but everything it derives from (TGSI, and flatshade) is + * already included in the shader key. + */ + lp_build_interp_soa_init(&interp, + gallivm, + shader->info.base.num_inputs, + inputs, + builder, fs_type, + a0_ptr, dadx_ptr, dady_ptr, + x, y); + + /* code generated texture sampling */ + sampler = lp_llvm_sampler_soa_create(key->sampler, context_ptr); + + /* loop over quads in the block */ + zs_format_desc = util_format_description(key->zsbuf_format); + + for(i = 0; i < num_fs; ++i) { + LLVMValueRef depth_offset = LLVMConstInt(int32_type, + i*fs_type.length*zs_format_desc->block.bits/8, + 0); + LLVMValueRef out_color[PIPE_MAX_COLOR_BUFS][NUM_CHANNELS]; + LLVMValueRef depth_ptr_i; + + depth_ptr_i = LLVMBuildGEP(builder, depth_ptr, &depth_offset, 1, ""); + + generate_fs(gallivm, + shader, key, + builder, + fs_type, + context_ptr, + i, + &interp, + sampler, + &fs_mask[i], /* output */ + out_color, + depth_ptr_i, + facing, + partial_mask, + mask_input, + counter); + + for(cbuf = 0; cbuf < key->nr_cbufs; cbuf++) + for(chan = 0; chan < NUM_CHANNELS; ++chan) + fs_out_color[cbuf][chan][i] = out_color[cbuf][chan]; + } + + sampler->destroy(sampler); + + /* Loop over color outputs / color buffers to do blending. + */ + for(cbuf = 0; cbuf < key->nr_cbufs; cbuf++) { + LLVMValueRef color_ptr; + LLVMValueRef index = lp_build_const_int32(gallivm, cbuf); + LLVMValueRef blend_in_color[NUM_CHANNELS]; + unsigned rt; + + /* + * Convert the fs's output color and mask to fit to the blending type. + */ + for(chan = 0; chan < NUM_CHANNELS; ++chan) { + LLVMValueRef fs_color_vals[LP_MAX_VECTOR_LENGTH]; + + for (i = 0; i < num_fs; i++) { + fs_color_vals[i] = + LLVMBuildLoad(builder, fs_out_color[cbuf][chan][i], "fs_color_vals"); + } + + lp_build_conv(gallivm, fs_type, blend_type, + fs_color_vals, + num_fs, + &blend_in_color[chan], 1); + + lp_build_name(blend_in_color[chan], "color%d.%c", cbuf, "rgba"[chan]); + } + + if (partial_mask || !variant->opaque) { + lp_build_conv_mask(lp->gallivm, fs_type, blend_type, + fs_mask, num_fs, + &blend_mask, 1); + } else { + blend_mask = lp_build_const_int_vec(lp->gallivm, blend_type, ~0); + } + + color_ptr = LLVMBuildLoad(builder, + LLVMBuildGEP(builder, color_ptr_ptr, &index, 1, ""), + ""); + lp_build_name(color_ptr, "color_ptr%d", cbuf); + + /* which blend/colormask state to use */ + rt = key->blend.independent_blend_enable ? cbuf : 0; + + /* + * Blending. + */ + { + /* Could the 4x4 have been killed? + */ + boolean do_branch = ((key->depth.enabled || key->stencil[0].enabled) && + !key->alpha.enabled && + !shader->info.base.uses_kill); + + generate_blend(lp->gallivm, + &key->blend, + rt, + builder, + blend_type, + context_ptr, + blend_mask, + blend_in_color, + color_ptr, + do_branch); + } + } + + LLVMBuildRetVoid(builder); + + /* Verify the LLVM IR. If invalid, dump and abort */ +#ifdef DEBUG + if(LLVMVerifyFunction(function, LLVMPrintMessageAction)) { + if (1) + lp_debug_dump_value(function); + abort(); + } +#endif + + /* Apply optimizations to LLVM IR */ + LLVMRunFunctionPassManager(gallivm->passmgr, function); + + if ((gallivm_debug & GALLIVM_DEBUG_IR) || (LP_DEBUG & DEBUG_FS)) { + /* Print the LLVM IR to stderr */ + lp_debug_dump_value(function); + debug_printf("\n"); + } + + /* Dump byte code to a file */ + if (0) { + LLVMWriteBitcodeToFile(gallivm->module, "llvmpipe.bc"); + } + + /* + * Translate the LLVM IR into machine code. + */ + { + void *f = LLVMGetPointerToGlobal(gallivm->engine, function); + + variant->jit_function[partial_mask] = (lp_jit_frag_func)pointer_to_func(f); + + if ((gallivm_debug & GALLIVM_DEBUG_ASM) || (LP_DEBUG & DEBUG_FS)) { + lp_disassemble(f); + } + lp_func_delete_body(function); + } +} + + +static void +dump_fs_variant_key(const struct lp_fragment_shader_variant_key *key) +{ + unsigned i; + + debug_printf("fs variant %p:\n", (void *) key); + + if (key->flatshade) { + debug_printf("flatshade = 1\n"); + } + for (i = 0; i < key->nr_cbufs; ++i) { + debug_printf("cbuf_format[%u] = %s\n", i, util_format_name(key->cbuf_format[i])); + } + if (key->depth.enabled) { + debug_printf("depth.format = %s\n", util_format_name(key->zsbuf_format)); + debug_printf("depth.func = %s\n", util_dump_func(key->depth.func, TRUE)); + debug_printf("depth.writemask = %u\n", key->depth.writemask); + } + + for (i = 0; i < 2; ++i) { + if (key->stencil[i].enabled) { + debug_printf("stencil[%u].func = %s\n", i, util_dump_func(key->stencil[i].func, TRUE)); + debug_printf("stencil[%u].fail_op = %s\n", i, util_dump_stencil_op(key->stencil[i].fail_op, TRUE)); + debug_printf("stencil[%u].zpass_op = %s\n", i, util_dump_stencil_op(key->stencil[i].zpass_op, TRUE)); + debug_printf("stencil[%u].zfail_op = %s\n", i, util_dump_stencil_op(key->stencil[i].zfail_op, TRUE)); + debug_printf("stencil[%u].valuemask = 0x%x\n", i, key->stencil[i].valuemask); + debug_printf("stencil[%u].writemask = 0x%x\n", i, key->stencil[i].writemask); + } + } + + if (key->alpha.enabled) { + debug_printf("alpha.func = %s\n", util_dump_func(key->alpha.func, TRUE)); + } + + if (key->occlusion_count) { + debug_printf("occlusion_count = 1\n"); + } + + if (key->blend.logicop_enable) { + debug_printf("blend.logicop_func = %s\n", util_dump_logicop(key->blend.logicop_func, TRUE)); + } + else if (key->blend.rt[0].blend_enable) { + debug_printf("blend.rgb_func = %s\n", util_dump_blend_func (key->blend.rt[0].rgb_func, TRUE)); + debug_printf("blend.rgb_src_factor = %s\n", util_dump_blend_factor(key->blend.rt[0].rgb_src_factor, TRUE)); + debug_printf("blend.rgb_dst_factor = %s\n", util_dump_blend_factor(key->blend.rt[0].rgb_dst_factor, TRUE)); + debug_printf("blend.alpha_func = %s\n", util_dump_blend_func (key->blend.rt[0].alpha_func, TRUE)); + debug_printf("blend.alpha_src_factor = %s\n", util_dump_blend_factor(key->blend.rt[0].alpha_src_factor, TRUE)); + debug_printf("blend.alpha_dst_factor = %s\n", util_dump_blend_factor(key->blend.rt[0].alpha_dst_factor, TRUE)); + } + debug_printf("blend.colormask = 0x%x\n", key->blend.rt[0].colormask); + for (i = 0; i < key->nr_samplers; ++i) { + debug_printf("sampler[%u] = \n", i); + debug_printf(" .format = %s\n", + util_format_name(key->sampler[i].format)); + debug_printf(" .target = %s\n", + util_dump_tex_target(key->sampler[i].target, TRUE)); + debug_printf(" .pot = %u %u %u\n", + key->sampler[i].pot_width, + key->sampler[i].pot_height, + key->sampler[i].pot_depth); + debug_printf(" .wrap = %s %s %s\n", + util_dump_tex_wrap(key->sampler[i].wrap_s, TRUE), + util_dump_tex_wrap(key->sampler[i].wrap_t, TRUE), + util_dump_tex_wrap(key->sampler[i].wrap_r, TRUE)); + debug_printf(" .min_img_filter = %s\n", + util_dump_tex_filter(key->sampler[i].min_img_filter, TRUE)); + debug_printf(" .min_mip_filter = %s\n", + util_dump_tex_mipfilter(key->sampler[i].min_mip_filter, TRUE)); + debug_printf(" .mag_img_filter = %s\n", + util_dump_tex_filter(key->sampler[i].mag_img_filter, TRUE)); + if (key->sampler[i].compare_mode != PIPE_TEX_COMPARE_NONE) + debug_printf(" .compare_func = %s\n", util_dump_func(key->sampler[i].compare_func, TRUE)); + debug_printf(" .normalized_coords = %u\n", key->sampler[i].normalized_coords); + debug_printf(" .min_max_lod_equal = %u\n", key->sampler[i].min_max_lod_equal); + debug_printf(" .lod_bias_non_zero = %u\n", key->sampler[i].lod_bias_non_zero); + debug_printf(" .apply_min_lod = %u\n", key->sampler[i].apply_min_lod); + debug_printf(" .apply_max_lod = %u\n", key->sampler[i].apply_max_lod); + } +} + + +void +lp_debug_fs_variant(const struct lp_fragment_shader_variant *variant) +{ + debug_printf("llvmpipe: Fragment shader #%u variant #%u:\n", + variant->shader->no, variant->no); + tgsi_dump(variant->shader->base.tokens, 0); + dump_fs_variant_key(&variant->key); + debug_printf("variant->opaque = %u\n", variant->opaque); + debug_printf("\n"); +} + + +/** + * Generate a new fragment shader variant from the shader code and + * other state indicated by the key. + */ +static struct lp_fragment_shader_variant * +generate_variant(struct llvmpipe_context *lp, + struct lp_fragment_shader *shader, + const struct lp_fragment_shader_variant_key *key) +{ + struct lp_fragment_shader_variant *variant; + boolean fullcolormask; + + variant = CALLOC_STRUCT(lp_fragment_shader_variant); + if(!variant) + return NULL; + + variant->shader = shader; + variant->list_item_global.base = variant; + variant->list_item_local.base = variant; + variant->no = shader->variants_created++; + + memcpy(&variant->key, key, shader->variant_key_size); + + /* + * Determine whether we are touching all channels in the color buffer. + */ + fullcolormask = FALSE; + if (key->nr_cbufs == 1) { + const struct util_format_description *format_desc; + format_desc = util_format_description(key->cbuf_format[0]); + if ((~key->blend.rt[0].colormask & + util_format_colormask(format_desc)) == 0) { + fullcolormask = TRUE; + } + } + + variant->opaque = + !key->blend.logicop_enable && + !key->blend.rt[0].blend_enable && + fullcolormask && + !key->stencil[0].enabled && + !key->alpha.enabled && + !key->depth.enabled && + !shader->info.base.uses_kill + ? TRUE : FALSE; + + + if ((LP_DEBUG & DEBUG_FS) || (gallivm_debug & GALLIVM_DEBUG_IR)) { + lp_debug_fs_variant(variant); + } + + generate_fragment(lp, shader, variant, RAST_EDGE_TEST); + + if (variant->opaque) { + /* Specialized shader, which doesn't need to read the color buffer. */ + generate_fragment(lp, shader, variant, RAST_WHOLE); + } else { + variant->jit_function[RAST_WHOLE] = variant->jit_function[RAST_EDGE_TEST]; + } + + return variant; +} + + +static void * +llvmpipe_create_fs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + struct lp_fragment_shader *shader; + int nr_samplers; + int i; + + shader = CALLOC_STRUCT(lp_fragment_shader); + if (!shader) + return NULL; + + shader->no = fs_no++; + make_empty_list(&shader->variants); + + /* get/save the summary info for this shader */ + lp_build_tgsi_info(templ->tokens, &shader->info); + + /* we need to keep a local copy of the tokens */ + shader->base.tokens = tgsi_dup_tokens(templ->tokens); + + shader->draw_data = draw_create_fragment_shader(llvmpipe->draw, templ); + if (shader->draw_data == NULL) { + FREE((void *) shader->base.tokens); + FREE(shader); + return NULL; + } + + nr_samplers = shader->info.base.file_max[TGSI_FILE_SAMPLER] + 1; + + shader->variant_key_size = Offset(struct lp_fragment_shader_variant_key, + sampler[nr_samplers]); + + for (i = 0; i < shader->info.base.num_inputs; i++) { + shader->inputs[i].usage_mask = shader->info.base.input_usage_mask[i]; + + switch (shader->info.base.input_interpolate[i]) { + case TGSI_INTERPOLATE_CONSTANT: + shader->inputs[i].interp = LP_INTERP_CONSTANT; + break; + case TGSI_INTERPOLATE_LINEAR: + shader->inputs[i].interp = LP_INTERP_LINEAR; + break; + case TGSI_INTERPOLATE_PERSPECTIVE: + shader->inputs[i].interp = LP_INTERP_PERSPECTIVE; + break; + default: + assert(0); + break; + } + + switch (shader->info.base.input_semantic_name[i]) { + case TGSI_SEMANTIC_COLOR: + /* Colors may be either linearly or constant interpolated in + * the fragment shader, but that information isn't available + * here. Mark color inputs and fix them up later. + */ + shader->inputs[i].interp = LP_INTERP_COLOR; + break; + case TGSI_SEMANTIC_FACE: + shader->inputs[i].interp = LP_INTERP_FACING; + break; + case TGSI_SEMANTIC_POSITION: + /* Position was already emitted above + */ + shader->inputs[i].interp = LP_INTERP_POSITION; + shader->inputs[i].src_index = 0; + continue; + } + + shader->inputs[i].src_index = i+1; + } + + if (LP_DEBUG & DEBUG_TGSI) { + unsigned attrib; + debug_printf("llvmpipe: Create fragment shader #%u %p:\n", + shader->no, (void *) shader); + tgsi_dump(templ->tokens, 0); + debug_printf("usage masks:\n"); + for (attrib = 0; attrib < shader->info.base.num_inputs; ++attrib) { + unsigned usage_mask = shader->info.base.input_usage_mask[attrib]; + debug_printf(" IN[%u].%s%s%s%s\n", + attrib, + usage_mask & TGSI_WRITEMASK_X ? "x" : "", + usage_mask & TGSI_WRITEMASK_Y ? "y" : "", + usage_mask & TGSI_WRITEMASK_Z ? "z" : "", + usage_mask & TGSI_WRITEMASK_W ? "w" : ""); + } + debug_printf("\n"); + } + + return shader; +} + + +static void +llvmpipe_bind_fs_state(struct pipe_context *pipe, void *fs) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + if (llvmpipe->fs == fs) + return; + + draw_flush(llvmpipe->draw); + + llvmpipe->fs = (struct lp_fragment_shader *) fs; + + draw_bind_fragment_shader(llvmpipe->draw, + (llvmpipe->fs ? llvmpipe->fs->draw_data : NULL)); + + llvmpipe->dirty |= LP_NEW_FS; +} + + +/** + * Remove shader variant from two lists: the shader's variant list + * and the context's variant list. + */ +void +llvmpipe_remove_shader_variant(struct llvmpipe_context *lp, + struct lp_fragment_shader_variant *variant) +{ + unsigned i; + + if (gallivm_debug & GALLIVM_DEBUG_IR) { + debug_printf("llvmpipe: del fs #%u var #%u v created #%u v cached" + " #%u v total cached #%u\n", + variant->shader->no, + variant->no, + variant->shader->variants_created, + variant->shader->variants_cached, + lp->nr_fs_variants); + } + + /* free all the variant's JIT'd functions */ + for (i = 0; i < Elements(variant->function); i++) { + if (variant->function[i]) { + if (variant->jit_function[i]) + LLVMFreeMachineCodeForFunction(lp->gallivm->engine, + variant->function[i]); + LLVMDeleteFunction(variant->function[i]); + } + } + + /* remove from shader's list */ + remove_from_list(&variant->list_item_local); + variant->shader->variants_cached--; + + /* remove from context's list */ + remove_from_list(&variant->list_item_global); + lp->nr_fs_variants--; + + FREE(variant); +} + + +static void +llvmpipe_delete_fs_state(struct pipe_context *pipe, void *fs) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + struct lp_fragment_shader *shader = fs; + struct lp_fs_variant_list_item *li; + + assert(fs != llvmpipe->fs); + + /* + * XXX: we need to flush the context until we have some sort of reference + * counting in fragment shaders as they may still be binned + * Flushing alone might not sufficient we need to wait on it too. + */ + llvmpipe_finish(pipe, __FUNCTION__); + + /* Delete all the variants */ + li = first_elem(&shader->variants); + while(!at_end(&shader->variants, li)) { + struct lp_fs_variant_list_item *next = next_elem(li); + llvmpipe_remove_shader_variant(llvmpipe, li->base); + li = next; + } + + /* Delete draw module's data */ + draw_delete_fragment_shader(llvmpipe->draw, shader->draw_data); + + assert(shader->variants_cached == 0); + FREE((void *) shader->base.tokens); + FREE(shader); +} + + + +static void +llvmpipe_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + struct pipe_resource *constants) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + unsigned size = constants ? constants->width0 : 0; + const void *data = constants ? llvmpipe_resource_data(constants) : NULL; + + assert(shader < PIPE_SHADER_TYPES); + assert(index < PIPE_MAX_CONSTANT_BUFFERS); + + if(llvmpipe->constants[shader][index] == constants) + return; + + draw_flush(llvmpipe->draw); + + /* note: reference counting */ + pipe_resource_reference(&llvmpipe->constants[shader][index], constants); + + if(shader == PIPE_SHADER_VERTEX || + shader == PIPE_SHADER_GEOMETRY) { + draw_set_mapped_constant_buffer(llvmpipe->draw, shader, + index, data, size); + } + + llvmpipe->dirty |= LP_NEW_CONSTANTS; +} + + +/** + * Return the blend factor equivalent to a destination alpha of one. + */ +static INLINE unsigned +force_dst_alpha_one(unsigned factor) +{ + switch(factor) { + case PIPE_BLENDFACTOR_DST_ALPHA: + return PIPE_BLENDFACTOR_ONE; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + return PIPE_BLENDFACTOR_ZERO; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + return PIPE_BLENDFACTOR_ZERO; + } + + return factor; +} + + +/** + * We need to generate several variants of the fragment pipeline to match + * all the combinations of the contributing state atoms. + * + * TODO: there is actually no reason to tie this to context state -- the + * generated code could be cached globally in the screen. + */ +static void +make_variant_key(struct llvmpipe_context *lp, + struct lp_fragment_shader *shader, + struct lp_fragment_shader_variant_key *key) +{ + unsigned i; + + memset(key, 0, shader->variant_key_size); + + if (lp->framebuffer.zsbuf) { + if (lp->depth_stencil->depth.enabled) { + key->zsbuf_format = lp->framebuffer.zsbuf->format; + memcpy(&key->depth, &lp->depth_stencil->depth, sizeof key->depth); + } + if (lp->depth_stencil->stencil[0].enabled) { + key->zsbuf_format = lp->framebuffer.zsbuf->format; + memcpy(&key->stencil, &lp->depth_stencil->stencil, sizeof key->stencil); + } + } + + key->alpha.enabled = lp->depth_stencil->alpha.enabled; + if(key->alpha.enabled) + key->alpha.func = lp->depth_stencil->alpha.func; + /* alpha.ref_value is passed in jit_context */ + + key->flatshade = lp->rasterizer->flatshade; + if (lp->active_query_count) { + key->occlusion_count = TRUE; + } + + if (lp->framebuffer.nr_cbufs) { + memcpy(&key->blend, lp->blend, sizeof key->blend); + } + + key->nr_cbufs = lp->framebuffer.nr_cbufs; + for (i = 0; i < lp->framebuffer.nr_cbufs; i++) { + enum pipe_format format = lp->framebuffer.cbufs[i]->format; + struct pipe_rt_blend_state *blend_rt = &key->blend.rt[i]; + const struct util_format_description *format_desc; + + key->cbuf_format[i] = format; + + format_desc = util_format_description(format); + assert(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB || + format_desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB); + + blend_rt->colormask = lp->blend->rt[i].colormask; + + /* + * Mask out color channels not present in the color buffer. + */ + blend_rt->colormask &= util_format_colormask(format_desc); + + /* + * Our swizzled render tiles always have an alpha channel, but the linear + * render target format often does not, so force here the dst alpha to be + * one. + * + * This is not a mere optimization. Wrong results will be produced if the + * dst alpha is used, the dst format does not have alpha, and the previous + * rendering was not flushed from the swizzled to linear buffer. For + * example, NonPowTwo DCT. + * + * TODO: This should be generalized to all channels for better + * performance, but only alpha causes correctness issues. + * + * Also, force rgb/alpha func/factors match, to make AoS blending easier. + */ + if (format_desc->swizzle[3] > UTIL_FORMAT_SWIZZLE_W) { + blend_rt->rgb_src_factor = force_dst_alpha_one(blend_rt->rgb_src_factor); + blend_rt->rgb_dst_factor = force_dst_alpha_one(blend_rt->rgb_dst_factor); + blend_rt->alpha_func = blend_rt->rgb_func; + blend_rt->alpha_src_factor = blend_rt->rgb_src_factor; + blend_rt->alpha_dst_factor = blend_rt->rgb_dst_factor; + } + } + + /* This value will be the same for all the variants of a given shader: + */ + key->nr_samplers = shader->info.base.file_max[TGSI_FILE_SAMPLER] + 1; + + for(i = 0; i < key->nr_samplers; ++i) { + if(shader->info.base.file_mask[TGSI_FILE_SAMPLER] & (1 << i)) { + lp_sampler_static_state(&key->sampler[i], + lp->fragment_sampler_views[i], + lp->sampler[i]); + } + } +} + + + +/** + * Update fragment shader state. This is called just prior to drawing + * something when some fragment-related state has changed. + */ +void +llvmpipe_update_fs(struct llvmpipe_context *lp) +{ + struct lp_fragment_shader *shader = lp->fs; + struct lp_fragment_shader_variant_key key; + struct lp_fragment_shader_variant *variant = NULL; + struct lp_fs_variant_list_item *li; + + make_variant_key(lp, shader, &key); + + /* Search the variants for one which matches the key */ + li = first_elem(&shader->variants); + while(!at_end(&shader->variants, li)) { + if(memcmp(&li->base->key, &key, shader->variant_key_size) == 0) { + variant = li->base; + break; + } + li = next_elem(li); + } + + if (variant) { + /* Move this variant to the head of the list to implement LRU + * deletion of shader's when we have too many. + */ + move_to_head(&lp->fs_variants_list, &variant->list_item_global); + } + else { + /* variant not found, create it now */ + int64_t t0, t1, dt; + unsigned i; + + /* First, check if we've exceeded the max number of shader variants. + * If so, free 25% of them (the least recently used ones). + */ + if (lp->nr_fs_variants >= LP_MAX_SHADER_VARIANTS) { + struct pipe_context *pipe = &lp->pipe; + + /* + * XXX: we need to flush the context until we have some sort of + * reference counting in fragment shaders as they may still be binned + * Flushing alone might not be sufficient we need to wait on it too. + */ + llvmpipe_finish(pipe, __FUNCTION__); + + for (i = 0; i < LP_MAX_SHADER_VARIANTS / 4; i++) { + struct lp_fs_variant_list_item *item; + item = last_elem(&lp->fs_variants_list); + llvmpipe_remove_shader_variant(lp, item->base); + } + } + + /* + * Generate the new variant. + */ + t0 = os_time_get(); + variant = generate_variant(lp, shader, &key); + t1 = os_time_get(); + dt = t1 - t0; + LP_COUNT_ADD(llvm_compile_time, dt); + LP_COUNT_ADD(nr_llvm_compiles, 2); /* emit vs. omit in/out test */ + + llvmpipe_variant_count++; + + /* Put the new variant into the list */ + if (variant) { + insert_at_head(&shader->variants, &variant->list_item_local); + insert_at_head(&lp->fs_variants_list, &variant->list_item_global); + lp->nr_fs_variants++; + shader->variants_cached++; + } + } + + /* Bind this variant */ + lp_setup_set_fs_variant(lp->setup, variant); +} + + + + + + + +void +llvmpipe_init_fs_funcs(struct llvmpipe_context *llvmpipe) +{ + llvmpipe->pipe.create_fs_state = llvmpipe_create_fs_state; + llvmpipe->pipe.bind_fs_state = llvmpipe_bind_fs_state; + llvmpipe->pipe.delete_fs_state = llvmpipe_delete_fs_state; + + llvmpipe->pipe.set_constant_buffer = llvmpipe_set_constant_buffer; +} diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.h b/src/gallium/drivers/llvmpipe/lp_state_fs.h new file mode 100644 index 0000000..98410c6 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.h @@ -0,0 +1,129 @@ +/************************************************************************** + * + * 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 LP_STATE_FS_H_ +#define LP_STATE_FS_H_ + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "tgsi/tgsi_scan.h" /* for tgsi_shader_info */ +#include "gallivm/lp_bld_sample.h" /* for struct lp_sampler_static_state */ +#include "gallivm/lp_bld_tgsi.h" /* for lp_tgsi_info */ +#include "lp_bld_interp.h" /* for struct lp_shader_input */ + + +struct tgsi_token; +struct lp_fragment_shader; + + +/** Indexes into jit_function[] array */ +#define RAST_WHOLE 0 +#define RAST_EDGE_TEST 1 + + +struct lp_fragment_shader_variant_key +{ + struct pipe_depth_state depth; + struct pipe_stencil_state stencil[2]; + struct pipe_blend_state blend; + + struct { + unsigned enabled:1; + unsigned func:3; + } alpha; + + unsigned nr_cbufs:8; + unsigned nr_samplers:8; /* actually derivable from just the shader */ + unsigned flatshade:1; + unsigned occlusion_count:1; + + enum pipe_format zsbuf_format; + enum pipe_format cbuf_format[PIPE_MAX_COLOR_BUFS]; + + struct lp_sampler_static_state sampler[PIPE_MAX_SAMPLERS]; +}; + + +/** doubly-linked list item */ +struct lp_fs_variant_list_item +{ + struct lp_fragment_shader_variant *base; + struct lp_fs_variant_list_item *next, *prev; +}; + + +struct lp_fragment_shader_variant +{ + struct lp_fragment_shader_variant_key key; + + boolean opaque; + + LLVMValueRef function[2]; + + lp_jit_frag_func jit_function[2]; + + struct lp_fs_variant_list_item list_item_global, list_item_local; + struct lp_fragment_shader *shader; + + /* For debugging/profiling purposes */ + unsigned no; +}; + + +/** Subclass of pipe_shader_state */ +struct lp_fragment_shader +{ + struct pipe_shader_state base; + + struct lp_tgsi_info info; + + struct lp_fs_variant_list_item variants; + + struct draw_fragment_shader *draw_data; + + /* For debugging/profiling purposes */ + unsigned variant_key_size; + unsigned no; + unsigned variants_created; + unsigned variants_cached; + + /** Fragment shader input interpolation info */ + struct lp_shader_input inputs[PIPE_MAX_SHADER_INPUTS]; +}; + + +void +lp_debug_fs_variant(const struct lp_fragment_shader_variant *variant); + +void +llvmpipe_remove_shader_variant(struct llvmpipe_context *lp, + struct lp_fragment_shader_variant *variant); + + +#endif /* LP_STATE_FS_H_ */ diff --git a/src/gallium/drivers/llvmpipe/lp_state_gs.c b/src/gallium/drivers/llvmpipe/lp_state_gs.c new file mode 100644 index 0000000..1ba6f10 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state_gs.c @@ -0,0 +1,112 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "lp_context.h" +#include "lp_state.h" +#include "lp_texture.h" + +#include "pipe/p_defines.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "draw/draw_context.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_scan.h" +#include "tgsi/tgsi_parse.h" + + +static void * +llvmpipe_create_gs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + struct lp_geometry_shader *state; + + state = CALLOC_STRUCT(lp_geometry_shader); + if (state == NULL ) + goto fail; + + /* debug */ + if (0) + tgsi_dump(templ->tokens, 0); + + /* copy shader tokens, the ones passed in will go away. + */ + state->shader.tokens = tgsi_dup_tokens(templ->tokens); + if (state->shader.tokens == NULL) + goto fail; + + state->draw_data = draw_create_geometry_shader(llvmpipe->draw, templ); + if (state->draw_data == NULL) + goto fail; + + return state; + +fail: + if (state) { + FREE( (void *)state->shader.tokens ); + FREE( state->draw_data ); + FREE( state ); + } + return NULL; +} + + +static void +llvmpipe_bind_gs_state(struct pipe_context *pipe, void *gs) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + llvmpipe->gs = (struct lp_geometry_shader *)gs; + + draw_bind_geometry_shader(llvmpipe->draw, + (llvmpipe->gs ? llvmpipe->gs->draw_data : NULL)); + + llvmpipe->dirty |= LP_NEW_GS; +} + + +static void +llvmpipe_delete_gs_state(struct pipe_context *pipe, void *gs) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + struct lp_geometry_shader *state = + (struct lp_geometry_shader *)gs; + + draw_delete_geometry_shader(llvmpipe->draw, + (state) ? state->draw_data : 0); + FREE(state); +} + + +void +llvmpipe_init_gs_funcs(struct llvmpipe_context *llvmpipe) +{ + llvmpipe->pipe.create_gs_state = llvmpipe_create_gs_state; + llvmpipe->pipe.bind_gs_state = llvmpipe_bind_gs_state; + llvmpipe->pipe.delete_gs_state = llvmpipe_delete_gs_state; +} diff --git a/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c b/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c new file mode 100644 index 0000000..574f9e9 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c @@ -0,0 +1,149 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "pipe/p_defines.h" +#include "util/u_memory.h" +#include "lp_context.h" +#include "lp_state.h" +#include "lp_setup.h" +#include "draw/draw_context.h" + +struct lp_rast_state { + struct pipe_rasterizer_state lp_state; + struct pipe_rasterizer_state draw_state; +}; + +/* State which might be handled in either the draw module or locally. + * This function is used to turn that state off in one of the two + * places. + */ +static void +clear_flags(struct pipe_rasterizer_state *rast) +{ + rast->light_twoside = 0; + rast->offset_tri = 0; +} + + + +static void * +llvmpipe_create_rasterizer_state(struct pipe_context *pipe, + const struct pipe_rasterizer_state *rast) +{ + boolean need_pipeline; + + /* Partition rasterizer state into what we want the draw module to + * handle, and what we'll look after ourselves. + */ + struct lp_rast_state *state = MALLOC_STRUCT(lp_rast_state); + if (state == NULL) + return NULL; + + memcpy(&state->draw_state, rast, sizeof *rast); + memcpy(&state->lp_state, rast, sizeof *rast); + + /* We rely on draw module to do unfilled polyons, AA lines and + * points and stipple. + * + * Over time, reduce this list of conditions, and expand the list + * of flags which get cleared in clear_flags(). + */ + need_pipeline = (rast->fill_front != PIPE_POLYGON_MODE_FILL || + rast->fill_back != PIPE_POLYGON_MODE_FILL || + rast->point_smooth || + rast->line_smooth || + rast->line_stipple_enable || + rast->poly_stipple_enable); + + /* If not using the pipeline, clear out the flags which we can + * handle ourselves. If we *are* using the pipeline, do everything + * on the pipeline and clear those flags on our internal copy of + * the state. + */ + if (need_pipeline) + clear_flags(&state->lp_state); + else + clear_flags(&state->draw_state); + + return state; +} + + + +static void +llvmpipe_bind_rasterizer_state(struct pipe_context *pipe, void *handle) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + const struct lp_rast_state *state = + (const struct lp_rast_state *) handle; + + if (state) { + llvmpipe->rasterizer = &state->lp_state; + draw_set_rasterizer_state(llvmpipe->draw, &state->draw_state, handle); + + /* XXX: just pass lp_state directly to setup. + */ + lp_setup_set_triangle_state( llvmpipe->setup, + state->lp_state.cull_face, + state->lp_state.front_ccw, + state->lp_state.scissor, + state->lp_state.gl_rasterization_rules); + lp_setup_set_flatshade_first( llvmpipe->setup, + state->lp_state.flatshade_first); + lp_setup_set_line_state( llvmpipe->setup, + state->lp_state.line_width); + lp_setup_set_point_state( llvmpipe->setup, + state->lp_state.point_size, + state->lp_state.point_size_per_vertex, + state->lp_state.sprite_coord_enable, + state->lp_state.sprite_coord_mode); + } + else { + llvmpipe->rasterizer = NULL; + draw_set_rasterizer_state(llvmpipe->draw, NULL, handle); + } + + llvmpipe->dirty |= LP_NEW_RASTERIZER; +} + + +static void +llvmpipe_delete_rasterizer_state(struct pipe_context *pipe, + void *rasterizer) +{ + FREE( rasterizer ); +} + + + +void +llvmpipe_init_rasterizer_funcs(struct llvmpipe_context *llvmpipe) +{ + llvmpipe->pipe.create_rasterizer_state = llvmpipe_create_rasterizer_state; + llvmpipe->pipe.bind_rasterizer_state = llvmpipe_bind_rasterizer_state; + llvmpipe->pipe.delete_rasterizer_state = llvmpipe_delete_rasterizer_state; +} diff --git a/src/gallium/drivers/llvmpipe/lp_state_sampler.c b/src/gallium/drivers/llvmpipe/lp_state_sampler.c new file mode 100644 index 0000000..1dd8661 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state_sampler.c @@ -0,0 +1,325 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: + * Brian Paul + */ + +#include "util/u_inlines.h" +#include "util/u_memory.h" + +#include "draw/draw_context.h" + +#include "lp_context.h" +#include "lp_screen.h" +#include "lp_state.h" +#include "lp_debug.h" +#include "state_tracker/sw_winsys.h" + + +static void * +llvmpipe_create_sampler_state(struct pipe_context *pipe, + const struct pipe_sampler_state *sampler) +{ + struct pipe_sampler_state *state = mem_dup(sampler, sizeof *sampler); + + if (LP_PERF & PERF_NO_MIP_LINEAR) { + if (state->min_mip_filter == PIPE_TEX_MIPFILTER_LINEAR) + state->min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; + } + + if (LP_PERF & PERF_NO_MIPMAPS) + state->min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + + if (LP_PERF & PERF_NO_LINEAR) { + state->mag_img_filter = PIPE_TEX_FILTER_NEAREST; + state->min_img_filter = PIPE_TEX_FILTER_NEAREST; + } + + return state; +} + + +static void +llvmpipe_bind_sampler_states(struct pipe_context *pipe, + unsigned num, void **sampler) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + unsigned i; + + assert(num <= PIPE_MAX_SAMPLERS); + + /* Check for no-op */ + if (num == llvmpipe->num_samplers && + !memcmp(llvmpipe->sampler, sampler, num * sizeof(void *))) + return; + + draw_flush(llvmpipe->draw); + + for (i = 0; i < num; ++i) + llvmpipe->sampler[i] = sampler[i]; + for (i = num; i < PIPE_MAX_SAMPLERS; ++i) + llvmpipe->sampler[i] = NULL; + + llvmpipe->num_samplers = num; + + llvmpipe->dirty |= LP_NEW_SAMPLER; +} + + +static void +llvmpipe_bind_vertex_sampler_states(struct pipe_context *pipe, + unsigned num_samplers, + void **samplers) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + unsigned i; + + assert(num_samplers <= PIPE_MAX_VERTEX_SAMPLERS); + + /* Check for no-op */ + if (num_samplers == llvmpipe->num_vertex_samplers && + !memcmp(llvmpipe->vertex_samplers, samplers, num_samplers * sizeof(void *))) + return; + + draw_flush(llvmpipe->draw); + + for (i = 0; i < num_samplers; ++i) + llvmpipe->vertex_samplers[i] = samplers[i]; + for (i = num_samplers; i < PIPE_MAX_VERTEX_SAMPLERS; ++i) + llvmpipe->vertex_samplers[i] = NULL; + + llvmpipe->num_vertex_samplers = num_samplers; + + draw_set_samplers(llvmpipe->draw, + llvmpipe->vertex_samplers, + llvmpipe->num_vertex_samplers); + + llvmpipe->dirty |= LP_NEW_SAMPLER; +} + + +static void +llvmpipe_bind_geometry_sampler_states(struct pipe_context *pipe, + unsigned num, void **sampler) +{ + /* XXX: implementation missing */ +} + +static void +llvmpipe_set_fragment_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + uint i; + + assert(num <= PIPE_MAX_SAMPLERS); + + /* Check for no-op */ + if (num == llvmpipe->num_fragment_sampler_views && + !memcmp(llvmpipe->fragment_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) + return; + + draw_flush(llvmpipe->draw); + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + struct pipe_sampler_view *view = i < num ? views[i] : NULL; + + pipe_sampler_view_reference(&llvmpipe->fragment_sampler_views[i], view); + } + + llvmpipe->num_fragment_sampler_views = num; + + llvmpipe->dirty |= LP_NEW_SAMPLER_VIEW; +} + + +static void +llvmpipe_set_vertex_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + uint i; + + assert(num <= PIPE_MAX_VERTEX_SAMPLERS); + + /* Check for no-op */ + if (num == llvmpipe->num_vertex_sampler_views && + !memcmp(llvmpipe->vertex_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) { + return; + } + + draw_flush(llvmpipe->draw); + + for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { + struct pipe_sampler_view *view = i < num ? views[i] : NULL; + + pipe_sampler_view_reference(&llvmpipe->vertex_sampler_views[i], view); + } + + llvmpipe->num_vertex_sampler_views = num; + + draw_set_sampler_views(llvmpipe->draw, + llvmpipe->vertex_sampler_views, + llvmpipe->num_vertex_sampler_views); + + llvmpipe->dirty |= LP_NEW_SAMPLER_VIEW; +} + + +static void +llvmpipe_set_geometry_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + /*XXX: implementation missing */ +} + +static struct pipe_sampler_view * +llvmpipe_create_sampler_view(struct pipe_context *pipe, + struct pipe_resource *texture, + const struct pipe_sampler_view *templ) +{ + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_resource_reference(&view->texture, texture); + view->context = pipe; + } + + return view; +} + + +static void +llvmpipe_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_resource_reference(&view->texture, NULL); + FREE(view); +} + + +static void +llvmpipe_delete_sampler_state(struct pipe_context *pipe, + void *sampler) +{ + FREE( sampler ); +} + + +/** + * Called during state validation when LP_NEW_SAMPLER_VIEW is set. + */ +void +llvmpipe_prepare_vertex_sampling(struct llvmpipe_context *lp, + unsigned num, + struct pipe_sampler_view **views) +{ + unsigned i; + uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS]; + uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS]; + const void *data[PIPE_MAX_TEXTURE_LEVELS]; + + assert(num <= PIPE_MAX_VERTEX_SAMPLERS); + if (!num) + return; + + for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { + struct pipe_sampler_view *view = i < num ? views[i] : NULL; + + if (view) { + struct pipe_resource *tex = view->texture; + struct llvmpipe_resource *lp_tex = llvmpipe_resource(tex); + + /* We're referencing the texture's internal data, so save a + * reference to it. + */ + pipe_resource_reference(&lp->mapped_vs_tex[i], tex); + + if (!lp_tex->dt) { + /* regular texture - setup array of mipmap level pointers */ + int j; + for (j = 0; j <= tex->last_level; j++) { + data[j] = + llvmpipe_get_texture_image_all(lp_tex, j, LP_TEX_USAGE_READ, + LP_TEX_LAYOUT_LINEAR); + row_stride[j] = lp_tex->row_stride[j]; + img_stride[j] = lp_tex->img_stride[j]; + } + } + else { + /* display target texture/surface */ + /* + * XXX: Where should this be unmapped? + */ + struct llvmpipe_screen *screen = llvmpipe_screen(tex->screen); + struct sw_winsys *winsys = screen->winsys; + data[0] = winsys->displaytarget_map(winsys, lp_tex->dt, + PIPE_TRANSFER_READ); + row_stride[0] = lp_tex->row_stride[0]; + img_stride[0] = lp_tex->img_stride[0]; + assert(data[0]); + } + draw_set_mapped_texture(lp->draw, + i, + tex->width0, tex->height0, tex->depth0, + tex->last_level, + row_stride, img_stride, data); + } + } +} + +void +llvmpipe_cleanup_vertex_sampling(struct llvmpipe_context *ctx) +{ + unsigned i; + for (i = 0; i < Elements(ctx->mapped_vs_tex); i++) { + pipe_resource_reference(&ctx->mapped_vs_tex[i], NULL); + } +} + +void +llvmpipe_init_sampler_funcs(struct llvmpipe_context *llvmpipe) +{ + llvmpipe->pipe.create_sampler_state = llvmpipe_create_sampler_state; + + llvmpipe->pipe.bind_fragment_sampler_states = llvmpipe_bind_sampler_states; + llvmpipe->pipe.bind_vertex_sampler_states = llvmpipe_bind_vertex_sampler_states; + llvmpipe->pipe.bind_geometry_sampler_states = llvmpipe_bind_geometry_sampler_states; + llvmpipe->pipe.set_fragment_sampler_views = llvmpipe_set_fragment_sampler_views; + llvmpipe->pipe.set_vertex_sampler_views = llvmpipe_set_vertex_sampler_views; + llvmpipe->pipe.set_geometry_sampler_views = llvmpipe_set_geometry_sampler_views; + llvmpipe->pipe.create_sampler_view = llvmpipe_create_sampler_view; + llvmpipe->pipe.sampler_view_destroy = llvmpipe_sampler_view_destroy; + llvmpipe->pipe.delete_sampler_state = llvmpipe_delete_sampler_state; +} diff --git a/src/gallium/drivers/llvmpipe/lp_state_setup.c b/src/gallium/drivers/llvmpipe/lp_state_setup.c new file mode 100644 index 0000000..ad751b9 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state_setup.c @@ -0,0 +1,926 @@ +/************************************************************************** + * + * Copyright 2010 VMware. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_simple_list.h" +#include "os/os_time.h" +#include "gallivm/lp_bld_arit.h" +#include "gallivm/lp_bld_const.h" +#include "gallivm/lp_bld_debug.h" +#include "gallivm/lp_bld_init.h" +#include "gallivm/lp_bld_intr.h" +#include "gallivm/lp_bld_flow.h" +#include "gallivm/lp_bld_type.h" +#include /* for LLVMVerifyFunction */ + +#include "lp_perf.h" +#include "lp_debug.h" +#include "lp_flush.h" +#include "lp_screen.h" +#include "lp_context.h" +#include "lp_state.h" +#include "lp_state_fs.h" +#include "lp_state_setup.h" + + + +/* currently organized to interpolate full float[4] attributes even + * when some elements are unused. Later, can pack vertex data more + * closely. + */ + + +struct lp_setup_args +{ + /* Function arguments: + */ + LLVMValueRef v0; + LLVMValueRef v1; + LLVMValueRef v2; + LLVMValueRef facing; /* boolean */ + LLVMValueRef a0; + LLVMValueRef dadx; + LLVMValueRef dady; + + /* Derived: + */ + LLVMValueRef x0_center; + LLVMValueRef y0_center; + LLVMValueRef dy20_ooa; + LLVMValueRef dy01_ooa; + LLVMValueRef dx20_ooa; + LLVMValueRef dx01_ooa; + + /* Temporary, per-attribute: + */ + LLVMValueRef v0a; + LLVMValueRef v1a; + LLVMValueRef v2a; +}; + + + +static LLVMTypeRef +type4f(struct gallivm_state *gallivm) +{ + return LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4); +} + + +/* Equivalent of _mm_setr_ps(a,b,c,d) + */ +static LLVMValueRef +vec4f(struct gallivm_state *gallivm, + LLVMValueRef a, LLVMValueRef b, LLVMValueRef c, LLVMValueRef d, + const char *name) +{ + LLVMBuilderRef bld = gallivm->builder; + LLVMValueRef i0 = lp_build_const_int32(gallivm, 0); + LLVMValueRef i1 = lp_build_const_int32(gallivm, 1); + LLVMValueRef i2 = lp_build_const_int32(gallivm, 2); + LLVMValueRef i3 = lp_build_const_int32(gallivm, 3); + + LLVMValueRef res = LLVMGetUndef(type4f(gallivm)); + + res = LLVMBuildInsertElement(bld, res, a, i0, ""); + res = LLVMBuildInsertElement(bld, res, b, i1, ""); + res = LLVMBuildInsertElement(bld, res, c, i2, ""); + res = LLVMBuildInsertElement(bld, res, d, i3, name); + + return res; +} + +/* Equivalent of _mm_set1_ps(a) + */ +static LLVMValueRef +vec4f_from_scalar(struct gallivm_state *gallivm, + LLVMValueRef a, + const char *name) +{ + LLVMBuilderRef bld = gallivm->builder; + LLVMValueRef res = LLVMGetUndef(type4f(gallivm)); + int i; + + for(i = 0; i < 4; ++i) { + LLVMValueRef index = lp_build_const_int32(gallivm, i); + res = LLVMBuildInsertElement(bld, res, a, index, i == 3 ? name : ""); + } + + return res; +} + +static void +store_coef(struct gallivm_state *gallivm, + struct lp_setup_args *args, + unsigned slot, + LLVMValueRef a0, + LLVMValueRef dadx, + LLVMValueRef dady) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef idx = lp_build_const_int32(gallivm, slot); + + LLVMBuildStore(builder, + a0, + LLVMBuildGEP(builder, args->a0, &idx, 1, "")); + + LLVMBuildStore(builder, + dadx, + LLVMBuildGEP(builder, args->dadx, &idx, 1, "")); + + LLVMBuildStore(builder, + dady, + LLVMBuildGEP(builder, args->dady, &idx, 1, "")); +} + + + +static void +emit_constant_coef4(struct gallivm_state *gallivm, + struct lp_setup_args *args, + unsigned slot, + LLVMValueRef vert) +{ + LLVMValueRef zero = lp_build_const_float(gallivm, 0.0); + LLVMValueRef zerovec = vec4f_from_scalar(gallivm, zero, "zero"); + store_coef(gallivm, args, slot, vert, zerovec, zerovec); +} + + + +/** + * Setup the fragment input attribute with the front-facing value. + * \param frontface is the triangle front facing? + */ +static void +emit_facing_coef(struct gallivm_state *gallivm, + struct lp_setup_args *args, + unsigned slot ) +{ + LLVMBuilderRef builder = gallivm->builder; + LLVMTypeRef float_type = LLVMFloatTypeInContext(gallivm->context); + LLVMValueRef a0_0 = args->facing; + LLVMValueRef a0_0f = LLVMBuildSIToFP(builder, a0_0, float_type, ""); + LLVMValueRef zero = lp_build_const_float(gallivm, 0.0); + LLVMValueRef a0 = vec4f(gallivm, a0_0f, zero, zero, zero, "facing"); + LLVMValueRef zerovec = vec4f_from_scalar(gallivm, zero, "zero"); + + store_coef(gallivm, args, slot, a0, zerovec, zerovec); +} + + +static LLVMValueRef +vert_attrib(struct gallivm_state *gallivm, + LLVMValueRef vert, + int attr, + int elem, + const char *name) +{ + LLVMBuilderRef b = gallivm->builder; + LLVMValueRef idx[2]; + idx[0] = lp_build_const_int32(gallivm, attr); + idx[1] = lp_build_const_int32(gallivm, elem); + return LLVMBuildLoad(b, LLVMBuildGEP(b, vert, idx, 2, ""), name); +} + +static LLVMValueRef +vert_clamp(LLVMBuilderRef b, + LLVMValueRef x, + LLVMValueRef min, + LLVMValueRef max) +{ + LLVMValueRef min_result = LLVMBuildFCmp(b, LLVMRealUGT, min, x, ""); + LLVMValueRef max_result = LLVMBuildFCmp(b, LLVMRealUGT, x, max, ""); + LLVMValueRef clamp_value; + + clamp_value = LLVMBuildSelect(b, min_result, min, x, ""); + clamp_value = LLVMBuildSelect(b, max_result, max, x, ""); + + return clamp_value; +} + +static void +lp_twoside(struct gallivm_state *gallivm, + struct lp_setup_args *args, + const struct lp_setup_variant_key *key, + int bcolor_slot) +{ + LLVMBuilderRef b = gallivm->builder; + LLVMValueRef a0_back, a1_back, a2_back; + LLVMValueRef idx2 = lp_build_const_int32(gallivm, bcolor_slot); + + LLVMValueRef facing = args->facing; + LLVMValueRef front_facing = LLVMBuildICmp(b, LLVMIntEQ, facing, lp_build_const_int32(gallivm, 0), ""); /** need i1 for if condition */ + + a0_back = LLVMBuildLoad(b, LLVMBuildGEP(b, args->v0, &idx2, 1, ""), "v0a_back"); + a1_back = LLVMBuildLoad(b, LLVMBuildGEP(b, args->v1, &idx2, 1, ""), "v1a_back"); + a2_back = LLVMBuildLoad(b, LLVMBuildGEP(b, args->v2, &idx2, 1, ""), "v2a_back"); + + /* Possibly swap the front and back attrib values, + * + * Prefer select to if so we don't have to worry about phis or + * allocas. + */ + args->v0a = LLVMBuildSelect(b, front_facing, a0_back, args->v0a, ""); + args->v1a = LLVMBuildSelect(b, front_facing, a1_back, args->v1a, ""); + args->v2a = LLVMBuildSelect(b, front_facing, a2_back, args->v2a, ""); + +} + +static void +lp_do_offset_tri(struct gallivm_state *gallivm, + struct lp_setup_args *args, + const struct lp_setup_variant_key *key) +{ + LLVMBuilderRef b = gallivm->builder; + struct lp_build_context bld; + LLVMValueRef zoffset, mult; + LLVMValueRef z0_new, z1_new, z2_new; + LLVMValueRef dzdx0, dzdx, dzdy0, dzdy; + LLVMValueRef max, max_value; + + LLVMValueRef one = lp_build_const_float(gallivm, 1.0); + LLVMValueRef zero = lp_build_const_float(gallivm, 0.0); + LLVMValueRef two = lp_build_const_int32(gallivm, 2); + + /* edge vectors: e = v0 - v2, f = v1 - v2 */ + LLVMValueRef v0_x = vert_attrib(gallivm, args->v0, 0, 0, "v0_x"); + LLVMValueRef v1_x = vert_attrib(gallivm, args->v1, 0, 0, "v1_x"); + LLVMValueRef v2_x = vert_attrib(gallivm, args->v2, 0, 0, "v2_x"); + LLVMValueRef v0_y = vert_attrib(gallivm, args->v0, 0, 1, "v0_y"); + LLVMValueRef v1_y = vert_attrib(gallivm, args->v1, 0, 1, "v1_y"); + LLVMValueRef v2_y = vert_attrib(gallivm, args->v2, 0, 1, "v2_y"); + LLVMValueRef v0_z = vert_attrib(gallivm, args->v0, 0, 2, "v0_z"); + LLVMValueRef v1_z = vert_attrib(gallivm, args->v1, 0, 2, "v1_z"); + LLVMValueRef v2_z = vert_attrib(gallivm, args->v2, 0, 2, "v2_z"); + + /* edge vectors: e = v0 - v2, f = v1 - v2 */ + LLVMValueRef dx02 = LLVMBuildFSub(b, v0_x, v2_x, "dx02"); + LLVMValueRef dy02 = LLVMBuildFSub(b, v0_y, v2_y, "dy02"); + LLVMValueRef dz02 = LLVMBuildFSub(b, v0_z, v2_z, "dz02"); + LLVMValueRef dx12 = LLVMBuildFSub(b, v1_x, v2_x, "dx12"); + LLVMValueRef dy12 = LLVMBuildFSub(b, v1_y, v2_y, "dy12"); + LLVMValueRef dz12 = LLVMBuildFSub(b, v1_z, v2_z, "dz12"); + + /* det = cross(e,f).z */ + LLVMValueRef dx02_dy12 = LLVMBuildFMul(b, dx02, dy12, "dx02_dy12"); + LLVMValueRef dy02_dx12 = LLVMBuildFMul(b, dy02, dx12, "dy02_dx12"); + LLVMValueRef det = LLVMBuildFSub(b, dx02_dy12, dy02_dx12, "det"); + LLVMValueRef inv_det = LLVMBuildFDiv(b, one, det, "inv_det"); + + /* (res1,res2) = cross(e,f).xy */ + LLVMValueRef dy02_dz12 = LLVMBuildFMul(b, dy02, dz12, "dy02_dz12"); + LLVMValueRef dz02_dy12 = LLVMBuildFMul(b, dz02, dy12, "dz02_dy12"); + LLVMValueRef dz02_dx12 = LLVMBuildFMul(b, dz02, dx12, "dz02_dx12"); + LLVMValueRef dx02_dz12 = LLVMBuildFMul(b, dx02, dz12, "dx02_dz12"); + LLVMValueRef res1 = LLVMBuildFSub(b, dy02_dz12, dz02_dy12, "res1"); + LLVMValueRef res2 = LLVMBuildFSub(b, dz02_dx12, dx02_dz12, "res2"); + + /* dzdx = fabsf(res1 * inv_det), dydx = fabsf(res2 * inv_det)*/ + lp_build_context_init(&bld, gallivm, lp_type_float(32)); + dzdx0 = LLVMBuildFMul(b, res1, inv_det, "dzdx"); + dzdx = lp_build_abs(&bld, dzdx0); + dzdy0 = LLVMBuildFMul(b, res2, inv_det, "dzdy"); + dzdy = lp_build_abs(&bld, dzdy0); + + /* zoffset = offset->units + MAX2(dzdx, dzdy) * offset->scale */ + max = LLVMBuildFCmp(b, LLVMRealUGT, dzdx, dzdy, ""); + max_value = LLVMBuildSelect(b, max, dzdx, dzdy, "max"); + + mult = LLVMBuildFMul(b, max_value, lp_build_const_float(gallivm, key->scale), ""); + zoffset = LLVMBuildFAdd(b, lp_build_const_float(gallivm, key->units), mult, "zoffset"); + + /* clamp and do offset */ + z0_new = vert_clamp(b, LLVMBuildFAdd(b, v0_z, zoffset, ""), zero, one); + z1_new = vert_clamp(b, LLVMBuildFAdd(b, v1_z, zoffset, ""), zero, one); + z2_new = vert_clamp(b, LLVMBuildFAdd(b, v2_z, zoffset, ""), zero, one); + + /* insert into args->a0.z, a1.z, a2.z: + */ + args->v0a = LLVMBuildInsertElement(b, args->v0a, z0_new, two, ""); + args->v1a = LLVMBuildInsertElement(b, args->v1a, z1_new, two, ""); + args->v2a = LLVMBuildInsertElement(b, args->v2a, z2_new, two, ""); +} + +static void +load_attribute(struct gallivm_state *gallivm, + struct lp_setup_args *args, + const struct lp_setup_variant_key *key, + unsigned vert_attr) +{ + LLVMBuilderRef b = gallivm->builder; + LLVMValueRef idx = lp_build_const_int32(gallivm, vert_attr); + + /* Load the vertex data + */ + args->v0a = LLVMBuildLoad(b, LLVMBuildGEP(b, args->v0, &idx, 1, ""), "v0a"); + args->v1a = LLVMBuildLoad(b, LLVMBuildGEP(b, args->v1, &idx, 1, ""), "v1a"); + args->v2a = LLVMBuildLoad(b, LLVMBuildGEP(b, args->v2, &idx, 1, ""), "v2a"); + + + /* Potentially modify it according to twoside, offset, etc: + */ + if (vert_attr == 0 && (key->scale != 0.0f || key->units != 0.0f)) { + lp_do_offset_tri(gallivm, args, key); + } + + if (key->twoside) { + if (vert_attr == key->color_slot && key->bcolor_slot != ~0) + lp_twoside(gallivm, args, key, key->bcolor_slot); + else if (vert_attr == key->spec_slot && key->bspec_slot != ~0) + lp_twoside(gallivm, args, key, key->bspec_slot); + } +} + +static void +emit_coef4( struct gallivm_state *gallivm, + struct lp_setup_args *args, + unsigned slot, + LLVMValueRef a0, + LLVMValueRef a1, + LLVMValueRef a2) +{ + LLVMBuilderRef b = gallivm->builder; + LLVMValueRef dy20_ooa = args->dy20_ooa; + LLVMValueRef dy01_ooa = args->dy01_ooa; + LLVMValueRef dx20_ooa = args->dx20_ooa; + LLVMValueRef dx01_ooa = args->dx01_ooa; + LLVMValueRef x0_center = args->x0_center; + LLVMValueRef y0_center = args->y0_center; + + /* XXX: using fsub, fmul on vector types -- does this work?? + */ + LLVMValueRef da01 = LLVMBuildFSub(b, a0, a1, "da01"); + LLVMValueRef da20 = LLVMBuildFSub(b, a2, a0, "da20"); + + /* Calculate dadx (vec4f) + */ + LLVMValueRef da01_dy20_ooa = LLVMBuildFMul(b, da01, dy20_ooa, "da01_dy20_ooa"); + LLVMValueRef da20_dy01_ooa = LLVMBuildFMul(b, da20, dy01_ooa, "da20_dy01_ooa"); + LLVMValueRef dadx = LLVMBuildFSub(b, da01_dy20_ooa, da20_dy01_ooa, "dadx"); + + /* Calculate dady (vec4f) + */ + LLVMValueRef da01_dx20_ooa = LLVMBuildFMul(b, da01, dx20_ooa, "da01_dx20_ooa"); + LLVMValueRef da20_dx01_ooa = LLVMBuildFMul(b, da20, dx01_ooa, "da20_dx01_ooa"); + LLVMValueRef dady = LLVMBuildFSub(b, da20_dx01_ooa, da01_dx20_ooa, "dady"); + + /* Calculate a0 - the attribute value at the origin + */ + LLVMValueRef dadx_x0 = LLVMBuildFMul(b, dadx, x0_center, "dadx_x0"); + LLVMValueRef dady_y0 = LLVMBuildFMul(b, dady, y0_center, "dady_y0"); + LLVMValueRef attr_v0 = LLVMBuildFAdd(b, dadx_x0, dady_y0, "attr_v0"); + LLVMValueRef attr_0 = LLVMBuildFSub(b, a0, attr_v0, "attr_0"); + + store_coef(gallivm, args, slot, attr_0, dadx, dady); +} + + +static void +emit_linear_coef( struct gallivm_state *gallivm, + struct lp_setup_args *args, + unsigned slot) +{ + /* nothing to do anymore */ + emit_coef4(gallivm, + args, slot, + args->v0a, + args->v1a, + args->v2a); +} + + +/** + * Compute a0, dadx and dady for a perspective-corrected interpolant, + * for a triangle. + * We basically multiply the vertex value by 1/w before computing + * the plane coefficients (a0, dadx, dady). + * Later, when we compute the value at a particular fragment position we'll + * divide the interpolated value by the interpolated W at that fragment. + */ +static void +emit_perspective_coef( struct gallivm_state *gallivm, + struct lp_setup_args *args, + unsigned slot) +{ + LLVMBuilderRef b = gallivm->builder; + + /* premultiply by 1/w (v[0][3] is always 1/w): + */ + LLVMValueRef v0_oow = vec4f_from_scalar(gallivm, vert_attrib(gallivm, args->v0, 0, 3, ""), "v0_oow"); + LLVMValueRef v1_oow = vec4f_from_scalar(gallivm, vert_attrib(gallivm, args->v1, 0, 3, ""), "v1_oow"); + LLVMValueRef v2_oow = vec4f_from_scalar(gallivm, vert_attrib(gallivm, args->v2, 0, 3, ""), "v2_oow"); + + LLVMValueRef v0_oow_v0a = LLVMBuildFMul(b, args->v0a, v0_oow, "v0_oow_v0a"); + LLVMValueRef v1_oow_v1a = LLVMBuildFMul(b, args->v1a, v1_oow, "v1_oow_v1a"); + LLVMValueRef v2_oow_v2a = LLVMBuildFMul(b, args->v2a, v2_oow, "v2_oow_v2a"); + + emit_coef4(gallivm, args, slot, v0_oow_v0a, v1_oow_v1a, v2_oow_v2a); +} + + +static void +emit_position_coef( struct gallivm_state *gallivm, + struct lp_setup_args *args, + int slot ) +{ + emit_linear_coef(gallivm, args, slot); +} + + + + +/** + * Compute the inputs-> dadx, dady, a0 values. + */ +static void +emit_tri_coef( struct gallivm_state *gallivm, + const struct lp_setup_variant_key *key, + struct lp_setup_args *args ) +{ + unsigned slot; + + /* The internal position input is in slot zero: + */ + load_attribute(gallivm, args, key, 0); + emit_position_coef(gallivm, args, 0); + + /* setup interpolation for all the remaining attributes: + */ + for (slot = 0; slot < key->num_inputs; slot++) { + + if (key->inputs[slot].interp == LP_INTERP_CONSTANT || + key->inputs[slot].interp == LP_INTERP_LINEAR || + key->inputs[slot].interp == LP_INTERP_PERSPECTIVE) + load_attribute(gallivm, args, key, key->inputs[slot].src_index); + + switch (key->inputs[slot].interp) { + case LP_INTERP_CONSTANT: + if (key->flatshade_first) { + emit_constant_coef4(gallivm, args, slot+1, args->v0a); + } + else { + emit_constant_coef4(gallivm, args, slot+1, args->v2a); + } + break; + + case LP_INTERP_LINEAR: + emit_linear_coef(gallivm, args, slot+1); + break; + + case LP_INTERP_PERSPECTIVE: + emit_perspective_coef(gallivm, args, slot+1); + break; + + case LP_INTERP_POSITION: + /* + * The generated pixel interpolators will pick up the coeffs from + * slot 0. + */ + break; + + case LP_INTERP_FACING: + emit_facing_coef(gallivm, args, slot+1); + break; + + default: + assert(0); + } + } +} + + +/* XXX: This is generic code, share with fs/vs codegen: + */ +static lp_jit_setup_triangle +finalize_function(struct gallivm_state *gallivm, + LLVMBuilderRef builder, + LLVMValueRef function) +{ + void *f; + + /* Verify the LLVM IR. If invalid, dump and abort */ +#ifdef DEBUG + if (LLVMVerifyFunction(function, LLVMPrintMessageAction)) { + if (1) + lp_debug_dump_value(function); + abort(); + } +#endif + + /* Apply optimizations to LLVM IR */ + LLVMRunFunctionPassManager(gallivm->passmgr, function); + + if (gallivm_debug & GALLIVM_DEBUG_IR) + { + /* Print the LLVM IR to stderr */ + lp_debug_dump_value(function); + debug_printf("\n"); + } + + /* + * Translate the LLVM IR into machine code. + */ + f = LLVMGetPointerToGlobal(gallivm->engine, function); + + if (gallivm_debug & GALLIVM_DEBUG_ASM) + { + lp_disassemble(f); + } + + lp_func_delete_body(function); + + return f; +} + +/* XXX: Generic code: + */ +static void +lp_emit_emms(struct gallivm_state *gallivm) +{ +#ifdef PIPE_ARCH_X86 + /* Avoid corrupting the FPU stack on 32bit OSes. */ + lp_build_intrinsic(gallivm->builder, "llvm.x86.mmx.emms", + LLVMVoidTypeInContext(gallivm->context), NULL, 0); +#endif +} + + +/* XXX: generic code: + */ +static void +set_noalias(LLVMBuilderRef builder, + LLVMValueRef function, + const LLVMTypeRef *arg_types, + int nr_args) +{ + int i; + for(i = 0; i < Elements(arg_types); ++i) + if(LLVMGetTypeKind(arg_types[i]) == LLVMPointerTypeKind) + LLVMAddAttribute(LLVMGetParam(function, i), + LLVMNoAliasAttribute); +} + +static void +init_args(struct gallivm_state *gallivm, + struct lp_setup_args *args, + const struct lp_setup_variant *variant) +{ + LLVMBuilderRef b = gallivm->builder; + + LLVMValueRef v0_x = vert_attrib(gallivm, args->v0, 0, 0, "v0_x"); + LLVMValueRef v0_y = vert_attrib(gallivm, args->v0, 0, 1, "v0_y"); + + LLVMValueRef v1_x = vert_attrib(gallivm, args->v1, 0, 0, "v1_x"); + LLVMValueRef v1_y = vert_attrib(gallivm, args->v1, 0, 1, "v1_y"); + + LLVMValueRef v2_x = vert_attrib(gallivm, args->v2, 0, 0, "v2_x"); + LLVMValueRef v2_y = vert_attrib(gallivm, args->v2, 0, 1, "v2_y"); + + LLVMValueRef pixel_center = lp_build_const_float(gallivm, + variant->key.pixel_center_half ? 0.5 : 0); + + LLVMValueRef x0_center = LLVMBuildFSub(b, v0_x, pixel_center, "x0_center" ); + LLVMValueRef y0_center = LLVMBuildFSub(b, v0_y, pixel_center, "y0_center" ); + + LLVMValueRef dx01 = LLVMBuildFSub(b, v0_x, v1_x, "dx01"); + LLVMValueRef dy01 = LLVMBuildFSub(b, v0_y, v1_y, "dy01"); + LLVMValueRef dx20 = LLVMBuildFSub(b, v2_x, v0_x, "dx20"); + LLVMValueRef dy20 = LLVMBuildFSub(b, v2_y, v0_y, "dy20"); + + LLVMValueRef one = lp_build_const_float(gallivm, 1.0); + LLVMValueRef e = LLVMBuildFMul(b, dx01, dy20, "e"); + LLVMValueRef f = LLVMBuildFMul(b, dx20, dy01, "f"); + LLVMValueRef ooa = LLVMBuildFDiv(b, one, LLVMBuildFSub(b, e, f, ""), "ooa"); + + LLVMValueRef dy20_ooa = LLVMBuildFMul(b, dy20, ooa, "dy20_ooa"); + LLVMValueRef dy01_ooa = LLVMBuildFMul(b, dy01, ooa, "dy01_ooa"); + LLVMValueRef dx20_ooa = LLVMBuildFMul(b, dx20, ooa, "dx20_ooa"); + LLVMValueRef dx01_ooa = LLVMBuildFMul(b, dx01, ooa, "dx01_ooa"); + + args->dy20_ooa = vec4f_from_scalar(gallivm, dy20_ooa, "dy20_ooa_4f"); + args->dy01_ooa = vec4f_from_scalar(gallivm, dy01_ooa, "dy01_ooa_4f"); + + args->dx20_ooa = vec4f_from_scalar(gallivm, dx20_ooa, "dx20_ooa_4f"); + args->dx01_ooa = vec4f_from_scalar(gallivm, dx01_ooa, "dx01_ooa_4f"); + + args->x0_center = vec4f_from_scalar(gallivm, x0_center, "x0_center_4f"); + args->y0_center = vec4f_from_scalar(gallivm, y0_center, "y0_center_4f"); +} + +/** + * Generate the runtime callable function for the coefficient calculation. + * + */ +static struct lp_setup_variant * +generate_setup_variant(struct gallivm_state *gallivm, + struct lp_setup_variant_key *key, + struct llvmpipe_context *lp) +{ + struct lp_setup_variant *variant = NULL; + struct lp_setup_args args; + char func_name[256]; + LLVMTypeRef vec4f_type; + LLVMTypeRef func_type; + LLVMTypeRef arg_types[7]; + LLVMBasicBlockRef block; + LLVMBuilderRef builder = gallivm->builder; + int64_t t0, t1; + + if (0) + goto fail; + + variant = CALLOC_STRUCT(lp_setup_variant); + if (variant == NULL) + goto fail; + + if (LP_DEBUG & DEBUG_COUNTERS) { + t0 = os_time_get(); + } + + memcpy(&variant->key, key, key->size); + variant->list_item_global.base = variant; + + util_snprintf(func_name, sizeof(func_name), "fs%u_setup%u", + 0, + variant->no); + + /* Currently always deal with full 4-wide vertex attributes from + * the vertices. + */ + + vec4f_type = LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4); + + arg_types[0] = LLVMPointerType(vec4f_type, 0); /* v0 */ + arg_types[1] = LLVMPointerType(vec4f_type, 0); /* v1 */ + arg_types[2] = LLVMPointerType(vec4f_type, 0); /* v2 */ + arg_types[3] = LLVMInt32TypeInContext(gallivm->context); /* facing */ + arg_types[4] = LLVMPointerType(vec4f_type, 0); /* a0, aligned */ + arg_types[5] = LLVMPointerType(vec4f_type, 0); /* dadx, aligned */ + arg_types[6] = LLVMPointerType(vec4f_type, 0); /* dady, aligned */ + + func_type = LLVMFunctionType(LLVMVoidTypeInContext(gallivm->context), + arg_types, Elements(arg_types), 0); + + variant->function = LLVMAddFunction(gallivm->module, func_name, func_type); + if (!variant->function) + goto fail; + + LLVMSetFunctionCallConv(variant->function, LLVMCCallConv); + + args.v0 = LLVMGetParam(variant->function, 0); + args.v1 = LLVMGetParam(variant->function, 1); + args.v2 = LLVMGetParam(variant->function, 2); + args.facing = LLVMGetParam(variant->function, 3); + args.a0 = LLVMGetParam(variant->function, 4); + args.dadx = LLVMGetParam(variant->function, 5); + args.dady = LLVMGetParam(variant->function, 6); + + lp_build_name(args.v0, "in_v0"); + lp_build_name(args.v1, "in_v1"); + lp_build_name(args.v2, "in_v2"); + lp_build_name(args.facing, "in_facing"); + lp_build_name(args.a0, "out_a0"); + lp_build_name(args.dadx, "out_dadx"); + lp_build_name(args.dady, "out_dady"); + + /* + * Function body + */ + block = LLVMAppendBasicBlockInContext(gallivm->context, + variant->function, "entry"); + LLVMPositionBuilderAtEnd(builder, block); + + set_noalias(builder, variant->function, arg_types, Elements(arg_types)); + init_args(gallivm, &args, variant); + emit_tri_coef(gallivm, &variant->key, &args); + + lp_emit_emms(gallivm); + LLVMBuildRetVoid(builder); + + variant->jit_function = finalize_function(gallivm, builder, + variant->function); + if (!variant->jit_function) + goto fail; + + /* + * Update timing information: + */ + if (LP_DEBUG & DEBUG_COUNTERS) { + t1 = os_time_get(); + LP_COUNT_ADD(llvm_compile_time, t1 - t0); + LP_COUNT_ADD(nr_llvm_compiles, 1); + } + + return variant; + +fail: + if (variant) { + if (variant->function) { + if (variant->jit_function) + LLVMFreeMachineCodeForFunction(gallivm->engine, + variant->function); + LLVMDeleteFunction(variant->function); + } + FREE(variant); + } + + return NULL; +} + + + +static void +lp_make_setup_variant_key(struct llvmpipe_context *lp, + struct lp_setup_variant_key *key) +{ + struct lp_fragment_shader *fs = lp->fs; + unsigned i; + + assert(sizeof key->inputs[0] == sizeof(ushort)); + + key->num_inputs = fs->info.base.num_inputs; + key->flatshade_first = lp->rasterizer->flatshade_first; + key->pixel_center_half = lp->rasterizer->gl_rasterization_rules; + key->twoside = lp->rasterizer->light_twoside; + key->size = Offset(struct lp_setup_variant_key, + inputs[key->num_inputs]); + key->color_slot = lp->color_slot[0]; + key->bcolor_slot = lp->bcolor_slot[0]; + key->spec_slot = lp->color_slot[1]; + key->bspec_slot = lp->bcolor_slot[1]; + key->units = (float) (lp->rasterizer->offset_units * lp->mrd); + key->scale = lp->rasterizer->offset_scale; + key->pad = 0; + memcpy(key->inputs, fs->inputs, key->num_inputs * sizeof key->inputs[0]); + for (i = 0; i < key->num_inputs; i++) { + if (key->inputs[i].interp == LP_INTERP_COLOR) { + if (lp->rasterizer->flatshade) + key->inputs[i].interp = LP_INTERP_CONSTANT; + else + key->inputs[i].interp = LP_INTERP_LINEAR; + } + } + +} + + +static void +remove_setup_variant(struct llvmpipe_context *lp, + struct lp_setup_variant *variant) +{ + if (gallivm_debug & GALLIVM_DEBUG_IR) { + debug_printf("llvmpipe: del setup_variant #%u total %u\n", + variant->no, lp->nr_setup_variants); + } + + if (variant->function) { + if (variant->jit_function) + LLVMFreeMachineCodeForFunction(lp->gallivm->engine, + variant->function); + LLVMDeleteFunction(variant->function); + } + + remove_from_list(&variant->list_item_global); + lp->nr_setup_variants--; + FREE(variant); +} + + + +/* When the number of setup variants exceeds a threshold, cull a + * fraction (currently a quarter) of them. + */ +static void +cull_setup_variants(struct llvmpipe_context *lp) +{ + struct pipe_context *pipe = &lp->pipe; + int i; + + /* + * XXX: we need to flush the context until we have some sort of reference + * counting in fragment shaders as they may still be binned + * Flushing alone might not be sufficient we need to wait on it too. + */ + llvmpipe_finish(pipe, __FUNCTION__); + + for (i = 0; i < LP_MAX_SETUP_VARIANTS / 4; i++) { + struct lp_setup_variant_list_item *item = last_elem(&lp->setup_variants_list); + remove_setup_variant(lp, item->base); + } +} + + +/** + * Update fragment/vertex shader linkage state. This is called just + * prior to drawing something when some fragment-related state has + * changed. + */ +void +llvmpipe_update_setup(struct llvmpipe_context *lp) +{ + struct lp_setup_variant_key *key = &lp->setup_variant.key; + struct lp_setup_variant *variant = NULL; + struct lp_setup_variant_list_item *li; + + lp_make_setup_variant_key(lp, key); + + foreach(li, &lp->setup_variants_list) { + if(li->base->key.size == key->size && + memcmp(&li->base->key, key, key->size) == 0) { + variant = li->base; + break; + } + } + + if (variant) { + move_to_head(&lp->setup_variants_list, &variant->list_item_global); + } + else { + if (lp->nr_setup_variants >= LP_MAX_SETUP_VARIANTS) { + cull_setup_variants(lp); + } + + variant = generate_setup_variant(lp->gallivm, key, lp); + insert_at_head(&lp->setup_variants_list, &variant->list_item_global); + lp->nr_setup_variants++; + + llvmpipe_variant_count++; + } + + lp_setup_set_setup_variant(lp->setup, + variant); +} + +void +lp_delete_setup_variants(struct llvmpipe_context *lp) +{ + struct lp_setup_variant_list_item *li; + li = first_elem(&lp->setup_variants_list); + while(!at_end(&lp->setup_variants_list, li)) { + struct lp_setup_variant_list_item *next = next_elem(li); + remove_setup_variant(lp, li->base); + li = next; + } +} + +void +lp_dump_setup_coef( const struct lp_setup_variant_key *key, + const float (*sa0)[4], + const float (*sdadx)[4], + const float (*sdady)[4]) +{ + int i, slot; + + for (i = 0; i < NUM_CHANNELS; i++) { + float a0 = sa0 [0][i]; + float dadx = sdadx[0][i]; + float dady = sdady[0][i]; + + debug_printf("POS.%c: a0 = %f, dadx = %f, dady = %f\n", + "xyzw"[i], + a0, dadx, dady); + } + + for (slot = 0; slot < key->num_inputs; slot++) { + unsigned usage_mask = key->inputs[slot].usage_mask; + for (i = 0; i < NUM_CHANNELS; i++) { + if (usage_mask & (1 << i)) { + float a0 = sa0 [1 + slot][i]; + float dadx = sdadx[1 + slot][i]; + float dady = sdady[1 + slot][i]; + + debug_printf("IN[%u].%c: a0 = %f, dadx = %f, dady = %f\n", + slot, + "xyzw"[i], + a0, dadx, dady); + } + } + } +} diff --git a/src/gallium/drivers/llvmpipe/lp_state_setup.h b/src/gallium/drivers/llvmpipe/lp_state_setup.h new file mode 100644 index 0000000..90c55ca --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state_setup.h @@ -0,0 +1,89 @@ +#ifndef LP_STATE_SETUP_H +#define LP_STATE_SETUP_H + +#include "lp_bld_interp.h" + + +struct llvmpipe_context; +struct lp_setup_variant; + +struct lp_setup_variant_list_item +{ + struct lp_setup_variant *base; + struct lp_setup_variant_list_item *next, *prev; +}; + + +struct lp_setup_variant_key { + unsigned size:16; + unsigned num_inputs:8; + unsigned color_slot:8; + + unsigned bcolor_slot:8; + unsigned spec_slot:8; + unsigned bspec_slot:8; + unsigned flatshade_first:1; + unsigned pixel_center_half:1; + unsigned twoside:1; + unsigned pad:5; + + float units; + float scale; + struct lp_shader_input inputs[PIPE_MAX_SHADER_INPUTS]; +}; + + +typedef void (*lp_jit_setup_triangle)( const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4], + boolean front_facing, + float (*a0)[4], + float (*dadx)[4], + float (*dady)[4] ); + + + + +/* At this stage, for a given variant key, we create a + * draw_vertex_info struct telling the draw module how to format the + * vertices, and an llvm-generated function which calculates the + * attribute interpolants (a0, dadx, dady) from three of those + * vertices. + */ +struct lp_setup_variant { + struct lp_setup_variant_key key; + + struct lp_setup_variant_list_item list_item_global; + + /* XXX: this is a pointer to the LLVM IR. Once jit_function is + * generated, we never need to use the IR again - need to find a + * way to release this data without destroying the generated + * assembly. + */ + LLVMValueRef function; + + /* The actual generated setup function: + */ + lp_jit_setup_triangle jit_function; + + unsigned no; +}; + +void lp_setup_tri_fallback( const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4], + boolean front_facing, + float (*a0)[4], + float (*dadx)[4], + float (*dady)[4], + const struct lp_setup_variant_key *key ); + +void lp_delete_setup_variants(struct llvmpipe_context *lp); + +void +lp_dump_setup_coef( const struct lp_setup_variant_key *key, + const float (*sa0)[4], + const float (*sdadx)[4], + const float (*sdady)[4]); + +#endif diff --git a/src/gallium/drivers/llvmpipe/lp_state_so.c b/src/gallium/drivers/llvmpipe/lp_state_so.c new file mode 100644 index 0000000..30b17c9 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state_so.c @@ -0,0 +1,137 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "lp_context.h" +#include "lp_state.h" +#include "lp_texture.h" + +#include "util/u_memory.h" +#include "draw/draw_context.h" + + +static void * +llvmpipe_create_stream_output_state(struct pipe_context *pipe, + const struct pipe_stream_output_state *templ) +{ + struct lp_so_state *so; + so = (struct lp_so_state *) CALLOC_STRUCT(lp_so_state); + + if (so) { + so->base.num_outputs = templ->num_outputs; + so->base.stride = templ->stride; + memcpy(so->base.output_buffer, + templ->output_buffer, + sizeof(int) * templ->num_outputs); + memcpy(so->base.register_index, + templ->register_index, + sizeof(int) * templ->num_outputs); + memcpy(so->base.register_mask, + templ->register_mask, + sizeof(ubyte) * templ->num_outputs); + } + return so; +} + +static void +llvmpipe_bind_stream_output_state(struct pipe_context *pipe, + void *so) +{ + struct llvmpipe_context *lp = llvmpipe_context(pipe); + struct lp_so_state *lp_so = (struct lp_so_state *) so; + + lp->so = lp_so; + + lp->dirty |= LP_NEW_SO; + + if (lp_so) + draw_set_so_state(lp->draw, &lp_so->base); +} + +static void +llvmpipe_delete_stream_output_state(struct pipe_context *pipe, void *so) +{ + FREE( so ); +} + +static void +llvmpipe_set_stream_output_buffers(struct pipe_context *pipe, + struct pipe_resource **buffers, + int *offsets, + int num_buffers) +{ + struct llvmpipe_context *lp = llvmpipe_context(pipe); + int i; + void *map_buffers[PIPE_MAX_SO_BUFFERS]; + + assert(num_buffers <= PIPE_MAX_SO_BUFFERS); + if (num_buffers > PIPE_MAX_SO_BUFFERS) + num_buffers = PIPE_MAX_SO_BUFFERS; + + lp->dirty |= LP_NEW_SO_BUFFERS; + + for (i = 0; i < num_buffers; ++i) { + void *mapped; + struct llvmpipe_resource *res = llvmpipe_resource(buffers[i]); + + if (!res) { + /* the whole call is invalid, bail out */ + lp->so_target.num_buffers = 0; + draw_set_mapped_so_buffers(lp->draw, 0, 0); + return; + } + + lp->so_target.buffer[i] = res; + lp->so_target.offset[i] = offsets[i]; + lp->so_target.so_count[i] = 0; + + mapped = res->data; + if (offsets[i] >= 0) + map_buffers[i] = ((char*)mapped) + offsets[i]; + else { + /* this is a buffer append */ + assert(!"appending not implemented"); + map_buffers[i] = mapped; + } + } + lp->so_target.num_buffers = num_buffers; + + draw_set_mapped_so_buffers(lp->draw, map_buffers, num_buffers); +} + +void +llvmpipe_init_so_funcs(struct llvmpipe_context *llvmpipe) +{ + llvmpipe->pipe.create_stream_output_state = + llvmpipe_create_stream_output_state; + llvmpipe->pipe.bind_stream_output_state = + llvmpipe_bind_stream_output_state; + llvmpipe->pipe.delete_stream_output_state = + llvmpipe_delete_stream_output_state; + + llvmpipe->pipe.set_stream_output_buffers = + llvmpipe_set_stream_output_buffers; +} diff --git a/src/gallium/drivers/llvmpipe/lp_state_surface.c b/src/gallium/drivers/llvmpipe/lp_state_surface.c new file mode 100644 index 0000000..375ceb2 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state_surface.c @@ -0,0 +1,88 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "util/u_framebuffer.h" +#include "util/u_surface.h" +#include "lp_context.h" +#include "lp_scene.h" +#include "lp_state.h" +#include "lp_setup.h" + +#include "draw/draw_context.h" + +#include "util/u_format.h" + + +/** + * Set the framebuffer surface info: color buffers, zbuffer, stencil buffer. + */ +void +llvmpipe_set_framebuffer_state(struct pipe_context *pipe, + const struct pipe_framebuffer_state *fb) +{ + struct llvmpipe_context *lp = llvmpipe_context(pipe); + + boolean changed = !util_framebuffer_state_equal(&lp->framebuffer, fb); + + assert(fb->width <= LP_MAX_WIDTH); + assert(fb->height <= LP_MAX_HEIGHT); + + if (changed) { + + util_copy_framebuffer_state(&lp->framebuffer, fb); + + if (LP_PERF & PERF_NO_DEPTH) { + pipe_surface_reference(&lp->framebuffer.zsbuf, NULL); + } + + /* Tell draw module how deep the Z/depth buffer is */ + if (lp->framebuffer.zsbuf) { + int depth_bits; + double mrd; + depth_bits = util_format_get_component_bits(lp->framebuffer.zsbuf->format, + UTIL_FORMAT_COLORSPACE_ZS, + 0); + if (depth_bits > 16) { + mrd = 0.0000001; + } + else { + mrd = 0.00002; + } + lp->mrd = mrd; + draw_set_mrd(lp->draw, mrd); + } + + lp_setup_bind_framebuffer( lp->setup, &lp->framebuffer ); + + lp->dirty |= LP_NEW_FRAMEBUFFER; + } +} diff --git a/src/gallium/drivers/llvmpipe/lp_state_vertex.c b/src/gallium/drivers/llvmpipe/lp_state_vertex.c new file mode 100644 index 0000000..fb29423 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state_vertex.c @@ -0,0 +1,115 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + + +#include "lp_context.h" +#include "lp_state.h" + +#include "draw/draw_context.h" + + +static void * +llvmpipe_create_vertex_elements_state(struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_element *attribs) +{ + struct lp_velems_state *velems; + assert(count <= PIPE_MAX_ATTRIBS); + velems = (struct lp_velems_state *) MALLOC(sizeof(struct lp_velems_state)); + if (velems) { + velems->count = count; + memcpy(velems->velem, attribs, sizeof(*attribs) * count); + } + return velems; +} + +static void +llvmpipe_bind_vertex_elements_state(struct pipe_context *pipe, + void *velems) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + struct lp_velems_state *lp_velems = (struct lp_velems_state *) velems; + + llvmpipe->velems = lp_velems; + + llvmpipe->dirty |= LP_NEW_VERTEX; + + if (velems) + draw_set_vertex_elements(llvmpipe->draw, lp_velems->count, lp_velems->velem); +} + +static void +llvmpipe_delete_vertex_elements_state(struct pipe_context *pipe, void *velems) +{ + FREE( velems ); +} + +static void +llvmpipe_set_vertex_buffers(struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_buffer *buffers) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + assert(count <= PIPE_MAX_ATTRIBS); + + memcpy(llvmpipe->vertex_buffer, buffers, count * sizeof(buffers[0])); + llvmpipe->num_vertex_buffers = count; + + llvmpipe->dirty |= LP_NEW_VERTEX; + + draw_set_vertex_buffers(llvmpipe->draw, count, buffers); +} + + +static void +llvmpipe_set_index_buffer(struct pipe_context *pipe, + const struct pipe_index_buffer *ib) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + if (ib) + memcpy(&llvmpipe->index_buffer, ib, sizeof(llvmpipe->index_buffer)); + else + memset(&llvmpipe->index_buffer, 0, sizeof(llvmpipe->index_buffer)); + + draw_set_index_buffer(llvmpipe->draw, ib); +} + +void +llvmpipe_init_vertex_funcs(struct llvmpipe_context *llvmpipe) +{ + llvmpipe->pipe.create_vertex_elements_state = llvmpipe_create_vertex_elements_state; + llvmpipe->pipe.bind_vertex_elements_state = llvmpipe_bind_vertex_elements_state; + llvmpipe->pipe.delete_vertex_elements_state = llvmpipe_delete_vertex_elements_state; + + llvmpipe->pipe.set_vertex_buffers = llvmpipe_set_vertex_buffers; + llvmpipe->pipe.set_index_buffer = llvmpipe_set_index_buffer; +} diff --git a/src/gallium/drivers/llvmpipe/lp_state_vs.c b/src/gallium/drivers/llvmpipe/lp_state_vs.c new file mode 100644 index 0000000..f2d8808 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_state_vs.c @@ -0,0 +1,118 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "pipe/p_defines.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_parse.h" +#include "util/u_memory.h" +#include "draw/draw_context.h" + +#include "lp_context.h" +#include "lp_debug.h" +#include "lp_state.h" + + +static void * +llvmpipe_create_vs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + struct lp_vertex_shader *state; + + state = CALLOC_STRUCT(lp_vertex_shader); + if (state == NULL ) + goto fail; + + /* copy shader tokens, the ones passed in will go away. + */ + state->shader.tokens = tgsi_dup_tokens(templ->tokens); + if (state->shader.tokens == NULL) + goto fail; + + state->draw_data = draw_create_vertex_shader(llvmpipe->draw, templ); + if (state->draw_data == NULL) + goto fail; + + if (LP_DEBUG & DEBUG_TGSI) { + debug_printf("llvmpipe: Create vertex shader %p:\n", (void *) state); + tgsi_dump(templ->tokens, 0); + } + + return state; + +fail: + if (state) { + FREE( (void *)state->shader.tokens ); + FREE( state->draw_data ); + FREE( state ); + } + return NULL; +} + + +static void +llvmpipe_bind_vs_state(struct pipe_context *pipe, void *_vs) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + const struct lp_vertex_shader *vs = (const struct lp_vertex_shader *)_vs; + + if (llvmpipe->vs == vs) + return; + + draw_bind_vertex_shader(llvmpipe->draw, + vs ? vs->draw_data : NULL); + + llvmpipe->vs = vs; + + llvmpipe->dirty |= LP_NEW_VS; +} + + +static void +llvmpipe_delete_vs_state(struct pipe_context *pipe, void *vs) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + + struct lp_vertex_shader *state = + (struct lp_vertex_shader *)vs; + + draw_delete_vertex_shader(llvmpipe->draw, state->draw_data); + FREE( (void *)state->shader.tokens ); + FREE( state ); +} + + + +void +llvmpipe_init_vs_funcs(struct llvmpipe_context *llvmpipe) +{ + llvmpipe->pipe.create_vs_state = llvmpipe_create_vs_state; + llvmpipe->pipe.bind_vs_state = llvmpipe_bind_vs_state; + llvmpipe->pipe.delete_vs_state = llvmpipe_delete_vs_state; +} diff --git a/src/gallium/drivers/llvmpipe/lp_surface.c b/src/gallium/drivers/llvmpipe/lp_surface.c new file mode 100644 index 0000000..e7e46a6 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_surface.c @@ -0,0 +1,176 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_rect.h" +#include "util/u_surface.h" +#include "lp_context.h" +#include "lp_flush.h" +#include "lp_limits.h" +#include "lp_surface.h" +#include "lp_texture.h" + + +/** + * Adjust x, y, width, height to lie on tile bounds. + */ +static void +adjust_to_tile_bounds(unsigned x, unsigned y, unsigned width, unsigned height, + unsigned *x_tile, unsigned *y_tile, + unsigned *w_tile, unsigned *h_tile) +{ + *x_tile = x & ~(TILE_SIZE - 1); + *y_tile = y & ~(TILE_SIZE - 1); + *w_tile = ((x + width + TILE_SIZE - 1) & ~(TILE_SIZE - 1)) - *x_tile; + *h_tile = ((y + height + TILE_SIZE - 1) & ~(TILE_SIZE - 1)) - *y_tile; +} + + + +static void +lp_resource_copy(struct pipe_context *pipe, + struct pipe_resource *dst, unsigned dst_level, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource *src, unsigned src_level, + const struct pipe_box *src_box) +{ + /* XXX this used to ignore srcz/dstz + * assume it works the same for cube and 3d + */ + struct llvmpipe_resource *src_tex = llvmpipe_resource(src); + struct llvmpipe_resource *dst_tex = llvmpipe_resource(dst); + const enum pipe_format format = src_tex->base.format; + unsigned width = src_box->width; + unsigned height = src_box->height; + assert(src_box->depth == 1); + + llvmpipe_flush_resource(pipe, + dst, dst_level, dstz, + 0, /* flush_flags */ + FALSE, /* read_only */ + TRUE, /* cpu_access */ + FALSE, /* do_not_block */ + "blit dest"); + + llvmpipe_flush_resource(pipe, + src, src_level, src_box->z, + 0, /* flush_flags */ + TRUE, /* read_only */ + TRUE, /* cpu_access */ + FALSE, /* do_not_block */ + "blit src"); + + /* + printf("surface copy from %u lvl %u to %u lvl %u: %u,%u,%u to %u,%u,%u %u x %u x %u\n", + src_tex->id, src_level, dst_tex->id, dst_level, + src_box->x, src_box->y, src_box->z, dstx, dsty, dstz, + src_box->width, src_box->height, src_box->depth); + */ + + /* set src tiles to linear layout */ + { + unsigned tx, ty, tw, th; + unsigned x, y; + + adjust_to_tile_bounds(src_box->x, src_box->y, width, height, + &tx, &ty, &tw, &th); + + for (y = 0; y < th; y += TILE_SIZE) { + for (x = 0; x < tw; x += TILE_SIZE) { + (void) llvmpipe_get_texture_tile_linear(src_tex, + src_box->z, src_level, + LP_TEX_USAGE_READ, + tx + x, ty + y); + } + } + } + + /* set dst tiles to linear layout */ + { + unsigned tx, ty, tw, th; + unsigned x, y; + enum lp_texture_usage usage; + + adjust_to_tile_bounds(dstx, dsty, width, height, &tx, &ty, &tw, &th); + + for (y = 0; y < th; y += TILE_SIZE) { + boolean contained_y = ty + y >= dsty && + ty + y + TILE_SIZE <= dsty + height ? + TRUE : FALSE; + + for (x = 0; x < tw; x += TILE_SIZE) { + boolean contained_x = tx + x >= dstx && + tx + x + TILE_SIZE <= dstx + width ? + TRUE : FALSE; + + /* + * Set the usage mode to WRITE_ALL for the tiles which are + * completely contained by the dest rectangle. + */ + if (contained_y && contained_x) + usage = LP_TEX_USAGE_WRITE_ALL; + else + usage = LP_TEX_USAGE_READ_WRITE; + + (void) llvmpipe_get_texture_tile_linear(dst_tex, + dstz, dst_level, + usage, + tx + x, ty + y); + } + } + } + + /* copy */ + { + const ubyte *src_linear_ptr + = llvmpipe_get_texture_image_address(src_tex, src_box->z, + src_level, + LP_TEX_LAYOUT_LINEAR); + ubyte *dst_linear_ptr + = llvmpipe_get_texture_image_address(dst_tex, dstz, + dst_level, + LP_TEX_LAYOUT_LINEAR); + + if (dst_linear_ptr && src_linear_ptr) { + util_copy_rect(dst_linear_ptr, format, + llvmpipe_resource_stride(&dst_tex->base, dst_level), + dstx, dsty, + width, height, + src_linear_ptr, + llvmpipe_resource_stride(&src_tex->base, src_level), + src_box->x, src_box->y); + } + } +} + + +void +llvmpipe_init_surface_functions(struct llvmpipe_context *lp) +{ + lp->pipe.resource_copy_region = lp_resource_copy; + lp->pipe.clear_render_target = util_clear_render_target; + lp->pipe.clear_depth_stencil = util_clear_depth_stencil; +} diff --git a/src/gallium/drivers/llvmpipe/lp_surface.h b/src/gallium/drivers/llvmpipe/lp_surface.h new file mode 100644 index 0000000..b1b896e --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_surface.h @@ -0,0 +1,42 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef LP_SURFACE_H +#define LP_SURFACE_H + + +struct llvmpipe_context; + + +extern void +llvmpipe_init_surface_functions(struct llvmpipe_context *lp); + + +#endif /* LP_SURFACE_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_test.h b/src/gallium/drivers/llvmpipe/lp_test.h new file mode 100644 index 0000000..c64f3e1 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_test.h @@ -0,0 +1,145 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Shared testing code. + * + * @author Jose Fonseca + */ + + +#ifndef LP_TEST_H +#define LP_TEST_H + + +#include +#include +#include + +#include "gallivm/lp_bld.h" +#include +#include +#include +#include +#include + +#include "pipe/p_state.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_dump.h" + +#include "gallivm/lp_bld_type.h" + + +#define LP_TEST_NUM_SAMPLES 32 + + +void +write_tsv_header(FILE *fp); + + +boolean +test_some(struct gallivm_state *gallivm,unsigned verbose, FILE *fp, + unsigned long n); + +boolean +test_single(struct gallivm_state *gallivm, unsigned verbose, FILE *fp); + +boolean +test_all(struct gallivm_state *gallivm, unsigned verbose, FILE *fp); + + +#if defined(PIPE_CC_MSVC) + +unsigned __int64 __rdtsc(); +#pragma intrinsic(__rdtsc) +#define rdtsc() __rdtsc() + +#elif defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)) + +static INLINE uint64_t +rdtsc(void) +{ + uint32_t hi, lo; + __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); + return ((uint64_t)lo) | (((uint64_t)hi) << 32); +} + +#else + +#define rdtsc() 0 + +#endif + + + +float +random_float(void); + + +void +dump_type(FILE *fp, struct lp_type type); + + +double +read_elem(struct lp_type type, const void *src, unsigned index); + + +void +write_elem(struct lp_type type, void *dst, unsigned index, double src); + + +void +random_elem(struct lp_type type, void *dst, unsigned index); + + +void +read_vec(struct lp_type type, const void *src, double *dst); + + +void +write_vec(struct lp_type type, void *dst, const double *src); + + +void +random_vec(struct lp_type type, void *dst); + + +boolean +compare_vec_with_eps(struct lp_type type, const void *res, const void *ref, double eps); + + +boolean +compare_vec(struct lp_type type, const void *res, const void *ref); + + +void +dump_vec(FILE *fp, struct lp_type type, const void *src); + + +#endif /* !LP_TEST_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_test_blend.c b/src/gallium/drivers/llvmpipe/lp_test_blend.c new file mode 100644 index 0000000..b3ca134 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_test_blend.c @@ -0,0 +1,863 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * @file + * Unit tests for blend LLVM IR generation + * + * @author Jose Fonseca + * + * Blend computation code derived from code written by + * @author Brian Paul + */ + + +#include "gallivm/lp_bld_init.h" +#include "gallivm/lp_bld_type.h" +#include "gallivm/lp_bld_debug.h" +#include "lp_bld_blend.h" +#include "lp_test.h" + + +enum vector_mode +{ + AoS = 0, + SoA = 1 +}; + + +typedef void (*blend_test_ptr_t)(const void *src, const void *dst, const void *con, void *res); + +/** cast wrapper */ +static blend_test_ptr_t +voidptr_to_blend_test_ptr_t(void *p) +{ + union { + void *v; + blend_test_ptr_t f; + } u; + u.v = p; + return u.f; +} + + + +void +write_tsv_header(FILE *fp) +{ + fprintf(fp, + "result\t" + "cycles_per_channel\t" + "mode\t" + "type\t" + "sep_func\t" + "sep_src_factor\t" + "sep_dst_factor\t" + "rgb_func\t" + "rgb_src_factor\t" + "rgb_dst_factor\t" + "alpha_func\t" + "alpha_src_factor\t" + "alpha_dst_factor\n"); + + fflush(fp); +} + + +static void +write_tsv_row(FILE *fp, + const struct pipe_blend_state *blend, + enum vector_mode mode, + struct lp_type type, + double cycles, + boolean success) +{ + fprintf(fp, "%s\t", success ? "pass" : "fail"); + + if (mode == AoS) { + fprintf(fp, "%.1f\t", cycles / type.length); + fprintf(fp, "aos\t"); + } + + if (mode == SoA) { + fprintf(fp, "%.1f\t", cycles / (4 * type.length)); + fprintf(fp, "soa\t"); + } + + fprintf(fp, "%s%u%sx%u\t", + type.floating ? "f" : (type.fixed ? "h" : (type.sign ? "s" : "u")), + type.width, + type.norm ? "n" : "", + type.length); + + fprintf(fp, + "%s\t%s\t%s\t", + blend->rt[0].rgb_func != blend->rt[0].alpha_func ? "true" : "false", + blend->rt[0].rgb_src_factor != blend->rt[0].alpha_src_factor ? "true" : "false", + blend->rt[0].rgb_dst_factor != blend->rt[0].alpha_dst_factor ? "true" : "false"); + + fprintf(fp, + "%s\t%s\t%s\t%s\t%s\t%s\n", + util_dump_blend_func(blend->rt[0].rgb_func, TRUE), + util_dump_blend_factor(blend->rt[0].rgb_src_factor, TRUE), + util_dump_blend_factor(blend->rt[0].rgb_dst_factor, TRUE), + util_dump_blend_func(blend->rt[0].alpha_func, TRUE), + util_dump_blend_factor(blend->rt[0].alpha_src_factor, TRUE), + util_dump_blend_factor(blend->rt[0].alpha_dst_factor, TRUE)); + + fflush(fp); +} + + +static void +dump_blend_type(FILE *fp, + const struct pipe_blend_state *blend, + enum vector_mode mode, + struct lp_type type) +{ + fprintf(fp, "%s", mode ? "soa" : "aos"); + + fprintf(fp, " type=%s%u%sx%u", + type.floating ? "f" : (type.fixed ? "h" : (type.sign ? "s" : "u")), + type.width, + type.norm ? "n" : "", + type.length); + + fprintf(fp, + " %s=%s %s=%s %s=%s %s=%s %s=%s %s=%s", + "rgb_func", util_dump_blend_func(blend->rt[0].rgb_func, TRUE), + "rgb_src_factor", util_dump_blend_factor(blend->rt[0].rgb_src_factor, TRUE), + "rgb_dst_factor", util_dump_blend_factor(blend->rt[0].rgb_dst_factor, TRUE), + "alpha_func", util_dump_blend_func(blend->rt[0].alpha_func, TRUE), + "alpha_src_factor", util_dump_blend_factor(blend->rt[0].alpha_src_factor, TRUE), + "alpha_dst_factor", util_dump_blend_factor(blend->rt[0].alpha_dst_factor, TRUE)); + + fprintf(fp, " ...\n"); + fflush(fp); +} + + +static LLVMValueRef +add_blend_test(struct gallivm_state *gallivm, + const struct pipe_blend_state *blend, + enum vector_mode mode, + struct lp_type type) +{ + LLVMModuleRef module = gallivm->module; + LLVMContextRef context = gallivm->context; + LLVMTypeRef vec_type; + LLVMTypeRef args[4]; + LLVMValueRef func; + LLVMValueRef src_ptr; + LLVMValueRef dst_ptr; + LLVMValueRef const_ptr; + LLVMValueRef res_ptr; + LLVMBasicBlockRef block; + LLVMBuilderRef builder; + const unsigned rt = 0; + + vec_type = lp_build_vec_type(gallivm, type); + + args[3] = args[2] = args[1] = args[0] = LLVMPointerType(vec_type, 0); + func = LLVMAddFunction(module, "test", LLVMFunctionType(LLVMVoidTypeInContext(context), args, 4, 0)); + LLVMSetFunctionCallConv(func, LLVMCCallConv); + src_ptr = LLVMGetParam(func, 0); + dst_ptr = LLVMGetParam(func, 1); + const_ptr = LLVMGetParam(func, 2); + res_ptr = LLVMGetParam(func, 3); + + block = LLVMAppendBasicBlockInContext(context, func, "entry"); + builder = gallivm->builder; + LLVMPositionBuilderAtEnd(builder, block); + + if (mode == AoS) { + LLVMValueRef src; + LLVMValueRef dst; + LLVMValueRef con; + LLVMValueRef res; + + src = LLVMBuildLoad(builder, src_ptr, "src"); + dst = LLVMBuildLoad(builder, dst_ptr, "dst"); + con = LLVMBuildLoad(builder, const_ptr, "const"); + + res = lp_build_blend_aos(gallivm, blend, type, rt, src, dst, con, 3); + + lp_build_name(res, "res"); + + LLVMBuildStore(builder, res, res_ptr); + } + + if (mode == SoA) { + LLVMValueRef src[4]; + LLVMValueRef dst[4]; + LLVMValueRef con[4]; + LLVMValueRef res[4]; + unsigned i; + + for(i = 0; i < 4; ++i) { + LLVMValueRef index = LLVMConstInt(LLVMInt32TypeInContext(context), i, 0); + src[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, src_ptr, &index, 1, ""), ""); + dst[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, dst_ptr, &index, 1, ""), ""); + con[i] = LLVMBuildLoad(builder, LLVMBuildGEP(builder, const_ptr, &index, 1, ""), ""); + lp_build_name(src[i], "src.%c", "rgba"[i]); + lp_build_name(con[i], "con.%c", "rgba"[i]); + lp_build_name(dst[i], "dst.%c", "rgba"[i]); + } + + lp_build_blend_soa(gallivm, blend, type, rt, src, dst, con, res); + + for(i = 0; i < 4; ++i) { + LLVMValueRef index = LLVMConstInt(LLVMInt32TypeInContext(context), i, 0); + lp_build_name(res[i], "res.%c", "rgba"[i]); + LLVMBuildStore(builder, res[i], LLVMBuildGEP(builder, res_ptr, &index, 1, "")); + } + } + + LLVMBuildRetVoid(builder);; + + return func; +} + + +static void +compute_blend_ref_term(unsigned rgb_factor, + unsigned alpha_factor, + const double *factor, + const double *src, + const double *dst, + const double *con, + double *term) +{ + double temp; + + switch (rgb_factor) { + case PIPE_BLENDFACTOR_ONE: + term[0] = factor[0]; /* R */ + term[1] = factor[1]; /* G */ + term[2] = factor[2]; /* B */ + break; + case PIPE_BLENDFACTOR_SRC_COLOR: + term[0] = factor[0] * src[0]; /* R */ + term[1] = factor[1] * src[1]; /* G */ + term[2] = factor[2] * src[2]; /* B */ + break; + case PIPE_BLENDFACTOR_SRC_ALPHA: + term[0] = factor[0] * src[3]; /* R */ + term[1] = factor[1] * src[3]; /* G */ + term[2] = factor[2] * src[3]; /* B */ + break; + case PIPE_BLENDFACTOR_DST_COLOR: + term[0] = factor[0] * dst[0]; /* R */ + term[1] = factor[1] * dst[1]; /* G */ + term[2] = factor[2] * dst[2]; /* B */ + break; + case PIPE_BLENDFACTOR_DST_ALPHA: + term[0] = factor[0] * dst[3]; /* R */ + term[1] = factor[1] * dst[3]; /* G */ + term[2] = factor[2] * dst[3]; /* B */ + break; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + temp = MIN2(src[3], 1.0f - dst[3]); + term[0] = factor[0] * temp; /* R */ + term[1] = factor[1] * temp; /* G */ + term[2] = factor[2] * temp; /* B */ + break; + case PIPE_BLENDFACTOR_CONST_COLOR: + term[0] = factor[0] * con[0]; /* R */ + term[1] = factor[1] * con[1]; /* G */ + term[2] = factor[2] * con[2]; /* B */ + break; + case PIPE_BLENDFACTOR_CONST_ALPHA: + term[0] = factor[0] * con[3]; /* R */ + term[1] = factor[1] * con[3]; /* G */ + term[2] = factor[2] * con[3]; /* B */ + break; + case PIPE_BLENDFACTOR_SRC1_COLOR: + assert(0); /* to do */ + break; + case PIPE_BLENDFACTOR_SRC1_ALPHA: + assert(0); /* to do */ + break; + case PIPE_BLENDFACTOR_ZERO: + term[0] = 0.0f; /* R */ + term[1] = 0.0f; /* G */ + term[2] = 0.0f; /* B */ + break; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + term[0] = factor[0] * (1.0f - src[0]); /* R */ + term[1] = factor[1] * (1.0f - src[1]); /* G */ + term[2] = factor[2] * (1.0f - src[2]); /* B */ + break; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + term[0] = factor[0] * (1.0f - src[3]); /* R */ + term[1] = factor[1] * (1.0f - src[3]); /* G */ + term[2] = factor[2] * (1.0f - src[3]); /* B */ + break; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + term[0] = factor[0] * (1.0f - dst[3]); /* R */ + term[1] = factor[1] * (1.0f - dst[3]); /* G */ + term[2] = factor[2] * (1.0f - dst[3]); /* B */ + break; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + term[0] = factor[0] * (1.0f - dst[0]); /* R */ + term[1] = factor[1] * (1.0f - dst[1]); /* G */ + term[2] = factor[2] * (1.0f - dst[2]); /* B */ + break; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + term[0] = factor[0] * (1.0f - con[0]); /* R */ + term[1] = factor[1] * (1.0f - con[1]); /* G */ + term[2] = factor[2] * (1.0f - con[2]); /* B */ + break; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + term[0] = factor[0] * (1.0f - con[3]); /* R */ + term[1] = factor[1] * (1.0f - con[3]); /* G */ + term[2] = factor[2] * (1.0f - con[3]); /* B */ + break; + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + assert(0); /* to do */ + break; + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + assert(0); /* to do */ + break; + default: + assert(0); + } + + /* + * Compute src/first term A + */ + switch (alpha_factor) { + case PIPE_BLENDFACTOR_ONE: + term[3] = factor[3]; /* A */ + break; + case PIPE_BLENDFACTOR_SRC_COLOR: + case PIPE_BLENDFACTOR_SRC_ALPHA: + term[3] = factor[3] * src[3]; /* A */ + break; + case PIPE_BLENDFACTOR_DST_COLOR: + case PIPE_BLENDFACTOR_DST_ALPHA: + term[3] = factor[3] * dst[3]; /* A */ + break; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + term[3] = src[3]; /* A */ + break; + case PIPE_BLENDFACTOR_CONST_COLOR: + case PIPE_BLENDFACTOR_CONST_ALPHA: + term[3] = factor[3] * con[3]; /* A */ + break; + case PIPE_BLENDFACTOR_ZERO: + term[3] = 0.0f; /* A */ + break; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + term[3] = factor[3] * (1.0f - src[3]); /* A */ + break; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + term[3] = factor[3] * (1.0f - dst[3]); /* A */ + break; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + term[3] = factor[3] * (1.0f - con[3]); + break; + default: + assert(0); + } +} + + +static void +compute_blend_ref(const struct pipe_blend_state *blend, + const double *src, + const double *dst, + const double *con, + double *res) +{ + double src_term[4]; + double dst_term[4]; + + compute_blend_ref_term(blend->rt[0].rgb_src_factor, blend->rt[0].alpha_src_factor, + src, src, dst, con, src_term); + compute_blend_ref_term(blend->rt[0].rgb_dst_factor, blend->rt[0].alpha_dst_factor, + dst, src, dst, con, dst_term); + + /* + * Combine RGB terms + */ + switch (blend->rt[0].rgb_func) { + case PIPE_BLEND_ADD: + res[0] = src_term[0] + dst_term[0]; /* R */ + res[1] = src_term[1] + dst_term[1]; /* G */ + res[2] = src_term[2] + dst_term[2]; /* B */ + break; + case PIPE_BLEND_SUBTRACT: + res[0] = src_term[0] - dst_term[0]; /* R */ + res[1] = src_term[1] - dst_term[1]; /* G */ + res[2] = src_term[2] - dst_term[2]; /* B */ + break; + case PIPE_BLEND_REVERSE_SUBTRACT: + res[0] = dst_term[0] - src_term[0]; /* R */ + res[1] = dst_term[1] - src_term[1]; /* G */ + res[2] = dst_term[2] - src_term[2]; /* B */ + break; + case PIPE_BLEND_MIN: + res[0] = MIN2(src_term[0], dst_term[0]); /* R */ + res[1] = MIN2(src_term[1], dst_term[1]); /* G */ + res[2] = MIN2(src_term[2], dst_term[2]); /* B */ + break; + case PIPE_BLEND_MAX: + res[0] = MAX2(src_term[0], dst_term[0]); /* R */ + res[1] = MAX2(src_term[1], dst_term[1]); /* G */ + res[2] = MAX2(src_term[2], dst_term[2]); /* B */ + break; + default: + assert(0); + } + + /* + * Combine A terms + */ + switch (blend->rt[0].alpha_func) { + case PIPE_BLEND_ADD: + res[3] = src_term[3] + dst_term[3]; /* A */ + break; + case PIPE_BLEND_SUBTRACT: + res[3] = src_term[3] - dst_term[3]; /* A */ + break; + case PIPE_BLEND_REVERSE_SUBTRACT: + res[3] = dst_term[3] - src_term[3]; /* A */ + break; + case PIPE_BLEND_MIN: + res[3] = MIN2(src_term[3], dst_term[3]); /* A */ + break; + case PIPE_BLEND_MAX: + res[3] = MAX2(src_term[3], dst_term[3]); /* A */ + break; + default: + assert(0); + } +} + + +PIPE_ALIGN_STACK +static boolean +test_one(struct gallivm_state *gallivm, + unsigned verbose, + FILE *fp, + const struct pipe_blend_state *blend, + enum vector_mode mode, + struct lp_type type) +{ + LLVMModuleRef module = gallivm->module; + LLVMValueRef func = NULL; + LLVMExecutionEngineRef engine = gallivm->engine; + char *error = NULL; + blend_test_ptr_t blend_test_ptr; + boolean success; + const unsigned n = LP_TEST_NUM_SAMPLES; + int64_t cycles[LP_TEST_NUM_SAMPLES]; + double cycles_avg = 0.0; + unsigned i, j; + void *code; + + if(verbose >= 1) + dump_blend_type(stdout, blend, mode, type); + + func = add_blend_test(gallivm, blend, mode, type); + + if(LLVMVerifyModule(module, LLVMPrintMessageAction, &error)) { + LLVMDumpModule(module); + abort(); + } + LLVMDisposeMessage(error); + + code = LLVMGetPointerToGlobal(engine, func); + blend_test_ptr = voidptr_to_blend_test_ptr_t(code); + + if(verbose >= 2) + lp_disassemble(code); + + success = TRUE; + for(i = 0; i < n && success; ++i) { + if(mode == AoS) { + PIPE_ALIGN_VAR(16) uint8_t src[LP_NATIVE_VECTOR_WIDTH/8]; + PIPE_ALIGN_VAR(16) uint8_t dst[LP_NATIVE_VECTOR_WIDTH/8]; + PIPE_ALIGN_VAR(16) uint8_t con[LP_NATIVE_VECTOR_WIDTH/8]; + PIPE_ALIGN_VAR(16) uint8_t res[LP_NATIVE_VECTOR_WIDTH/8]; + PIPE_ALIGN_VAR(16) uint8_t ref[LP_NATIVE_VECTOR_WIDTH/8]; + int64_t start_counter = 0; + int64_t end_counter = 0; + + random_vec(type, src); + random_vec(type, dst); + random_vec(type, con); + + { + double fsrc[LP_MAX_VECTOR_LENGTH]; + double fdst[LP_MAX_VECTOR_LENGTH]; + double fcon[LP_MAX_VECTOR_LENGTH]; + double fref[LP_MAX_VECTOR_LENGTH]; + + read_vec(type, src, fsrc); + read_vec(type, dst, fdst); + read_vec(type, con, fcon); + + for(j = 0; j < type.length; j += 4) + compute_blend_ref(blend, fsrc + j, fdst + j, fcon + j, fref + j); + + write_vec(type, ref, fref); + } + + start_counter = rdtsc(); + blend_test_ptr(src, dst, con, res); + end_counter = rdtsc(); + + cycles[i] = end_counter - start_counter; + + if(!compare_vec(type, res, ref)) { + success = FALSE; + + if(verbose < 1) + dump_blend_type(stderr, blend, mode, type); + fprintf(stderr, "MISMATCH\n"); + + fprintf(stderr, " Src: "); + dump_vec(stderr, type, src); + fprintf(stderr, "\n"); + + fprintf(stderr, " Dst: "); + dump_vec(stderr, type, dst); + fprintf(stderr, "\n"); + + fprintf(stderr, " Con: "); + dump_vec(stderr, type, con); + fprintf(stderr, "\n"); + + fprintf(stderr, " Res: "); + dump_vec(stderr, type, res); + fprintf(stderr, "\n"); + + fprintf(stderr, " Ref: "); + dump_vec(stderr, type, ref); + fprintf(stderr, "\n"); + } + } + + if(mode == SoA) { + const unsigned stride = type.length*type.width/8; + PIPE_ALIGN_VAR(16) uint8_t src[4*LP_NATIVE_VECTOR_WIDTH/8]; + PIPE_ALIGN_VAR(16) uint8_t dst[4*LP_NATIVE_VECTOR_WIDTH/8]; + PIPE_ALIGN_VAR(16) uint8_t con[4*LP_NATIVE_VECTOR_WIDTH/8]; + PIPE_ALIGN_VAR(16) uint8_t res[4*LP_NATIVE_VECTOR_WIDTH/8]; + PIPE_ALIGN_VAR(16) uint8_t ref[4*LP_NATIVE_VECTOR_WIDTH/8]; + int64_t start_counter = 0; + int64_t end_counter = 0; + boolean mismatch; + + for(j = 0; j < 4; ++j) { + random_vec(type, src + j*stride); + random_vec(type, dst + j*stride); + random_vec(type, con + j*stride); + } + + { + double fsrc[4]; + double fdst[4]; + double fcon[4]; + double fref[4]; + unsigned k; + + for(k = 0; k < type.length; ++k) { + for(j = 0; j < 4; ++j) { + fsrc[j] = read_elem(type, src + j*stride, k); + fdst[j] = read_elem(type, dst + j*stride, k); + fcon[j] = read_elem(type, con + j*stride, k); + } + + compute_blend_ref(blend, fsrc, fdst, fcon, fref); + + for(j = 0; j < 4; ++j) + write_elem(type, ref + j*stride, k, fref[j]); + } + } + + start_counter = rdtsc(); + blend_test_ptr(src, dst, con, res); + end_counter = rdtsc(); + + cycles[i] = end_counter - start_counter; + + mismatch = FALSE; + for (j = 0; j < 4; ++j) + if(!compare_vec(type, res + j*stride, ref + j*stride)) + mismatch = TRUE; + + if (mismatch) { + success = FALSE; + + if(verbose < 1) + dump_blend_type(stderr, blend, mode, type); + fprintf(stderr, "MISMATCH\n"); + for(j = 0; j < 4; ++j) { + char channel = "RGBA"[j]; + fprintf(stderr, " Src%c: ", channel); + dump_vec(stderr, type, src + j*stride); + fprintf(stderr, "\n"); + + fprintf(stderr, " Dst%c: ", channel); + dump_vec(stderr, type, dst + j*stride); + fprintf(stderr, "\n"); + + fprintf(stderr, " Con%c: ", channel); + dump_vec(stderr, type, con + j*stride); + fprintf(stderr, "\n"); + + fprintf(stderr, " Res%c: ", channel); + dump_vec(stderr, type, res + j*stride); + fprintf(stderr, "\n"); + + fprintf(stderr, " Ref%c: ", channel); + dump_vec(stderr, type, ref + j*stride); + fprintf(stderr, "\n"); + + fprintf(stderr, "\n"); + } + } + } + } + + /* + * Unfortunately the output of cycle counter is not very reliable as it comes + * -- sometimes we get outliers (due IRQs perhaps?) which are + * better removed to avoid random or biased data. + */ + { + double sum = 0.0, sum2 = 0.0; + double avg, std; + unsigned m; + + for(i = 0; i < n; ++i) { + sum += cycles[i]; + sum2 += cycles[i]*cycles[i]; + } + + avg = sum/n; + std = sqrtf((sum2 - n*avg*avg)/n); + + m = 0; + sum = 0.0; + for(i = 0; i < n; ++i) { + if(fabs(cycles[i] - avg) <= 4.0*std) { + sum += cycles[i]; + ++m; + } + } + + cycles_avg = sum/m; + + } + + if(fp) + write_tsv_row(fp, blend, mode, type, cycles_avg, success); + + if (!success) { + if(verbose < 2) + LLVMDumpModule(module); + LLVMWriteBitcodeToFile(module, "blend.bc"); + fprintf(stderr, "blend.bc written\n"); + fprintf(stderr, "Invoke as \"llc -o - blend.bc\"\n"); + abort(); + } + + LLVMFreeMachineCodeForFunction(engine, func); + + return success; +} + + +const unsigned +blend_factors[] = { + PIPE_BLENDFACTOR_ZERO, + PIPE_BLENDFACTOR_ONE, + PIPE_BLENDFACTOR_SRC_COLOR, + PIPE_BLENDFACTOR_SRC_ALPHA, + PIPE_BLENDFACTOR_DST_COLOR, + PIPE_BLENDFACTOR_DST_ALPHA, + PIPE_BLENDFACTOR_CONST_COLOR, + PIPE_BLENDFACTOR_CONST_ALPHA, +#if 0 + PIPE_BLENDFACTOR_SRC1_COLOR, + PIPE_BLENDFACTOR_SRC1_ALPHA, +#endif + PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE, + PIPE_BLENDFACTOR_INV_SRC_COLOR, + PIPE_BLENDFACTOR_INV_SRC_ALPHA, + PIPE_BLENDFACTOR_INV_DST_COLOR, + PIPE_BLENDFACTOR_INV_DST_ALPHA, + PIPE_BLENDFACTOR_INV_CONST_COLOR, + PIPE_BLENDFACTOR_INV_CONST_ALPHA, +#if 0 + PIPE_BLENDFACTOR_INV_SRC1_COLOR, + PIPE_BLENDFACTOR_INV_SRC1_ALPHA, +#endif +}; + + +const unsigned +blend_funcs[] = { + PIPE_BLEND_ADD, + PIPE_BLEND_SUBTRACT, + PIPE_BLEND_REVERSE_SUBTRACT, + PIPE_BLEND_MIN, + PIPE_BLEND_MAX +}; + + +const struct lp_type blend_types[] = { + /* float, fixed, sign, norm, width, len */ + { TRUE, FALSE, TRUE, FALSE, 32, 4 }, /* f32 x 4 */ + { FALSE, FALSE, FALSE, TRUE, 8, 16 }, /* u8n x 16 */ +}; + + +const unsigned num_funcs = sizeof(blend_funcs)/sizeof(blend_funcs[0]); +const unsigned num_factors = sizeof(blend_factors)/sizeof(blend_factors[0]); +const unsigned num_types = sizeof(blend_types)/sizeof(blend_types[0]); + + +boolean +test_all(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + const unsigned *rgb_func; + const unsigned *rgb_src_factor; + const unsigned *rgb_dst_factor; + const unsigned *alpha_func; + const unsigned *alpha_src_factor; + const unsigned *alpha_dst_factor; + struct pipe_blend_state blend; + enum vector_mode mode; + const struct lp_type *type; + boolean success = TRUE; + + for(rgb_func = blend_funcs; rgb_func < &blend_funcs[num_funcs]; ++rgb_func) { + for(alpha_func = blend_funcs; alpha_func < &blend_funcs[num_funcs]; ++alpha_func) { + for(rgb_src_factor = blend_factors; rgb_src_factor < &blend_factors[num_factors]; ++rgb_src_factor) { + for(rgb_dst_factor = blend_factors; rgb_dst_factor <= rgb_src_factor; ++rgb_dst_factor) { + for(alpha_src_factor = blend_factors; alpha_src_factor < &blend_factors[num_factors]; ++alpha_src_factor) { + for(alpha_dst_factor = blend_factors; alpha_dst_factor <= alpha_src_factor; ++alpha_dst_factor) { + for(mode = 0; mode < 2; ++mode) { + for(type = blend_types; type < &blend_types[num_types]; ++type) { + + if(*rgb_dst_factor == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE || + *alpha_dst_factor == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE) + continue; + + memset(&blend, 0, sizeof blend); + blend.rt[0].blend_enable = 1; + blend.rt[0].rgb_func = *rgb_func; + blend.rt[0].rgb_src_factor = *rgb_src_factor; + blend.rt[0].rgb_dst_factor = *rgb_dst_factor; + blend.rt[0].alpha_func = *alpha_func; + blend.rt[0].alpha_src_factor = *alpha_src_factor; + blend.rt[0].alpha_dst_factor = *alpha_dst_factor; + blend.rt[0].colormask = PIPE_MASK_RGBA; + + if(!test_one(gallivm, verbose, fp, &blend, mode, *type)) + success = FALSE; + + } + } + } + } + } + } + } + } + + return success; +} + + +boolean +test_some(struct gallivm_state *gallivm, unsigned verbose, FILE *fp, + unsigned long n) +{ + const unsigned *rgb_func; + const unsigned *rgb_src_factor; + const unsigned *rgb_dst_factor; + const unsigned *alpha_func; + const unsigned *alpha_src_factor; + const unsigned *alpha_dst_factor; + struct pipe_blend_state blend; + enum vector_mode mode; + const struct lp_type *type; + unsigned long i; + boolean success = TRUE; + + for(i = 0; i < n; ++i) { + rgb_func = &blend_funcs[rand() % num_funcs]; + alpha_func = &blend_funcs[rand() % num_funcs]; + rgb_src_factor = &blend_factors[rand() % num_factors]; + alpha_src_factor = &blend_factors[rand() % num_factors]; + + do { + rgb_dst_factor = &blend_factors[rand() % num_factors]; + } while(*rgb_dst_factor == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE); + + do { + alpha_dst_factor = &blend_factors[rand() % num_factors]; + } while(*alpha_dst_factor == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE); + + mode = rand() & 1; + + type = &blend_types[rand() % num_types]; + + memset(&blend, 0, sizeof blend); + blend.rt[0].blend_enable = 1; + blend.rt[0].rgb_func = *rgb_func; + blend.rt[0].rgb_src_factor = *rgb_src_factor; + blend.rt[0].rgb_dst_factor = *rgb_dst_factor; + blend.rt[0].alpha_func = *alpha_func; + blend.rt[0].alpha_src_factor = *alpha_src_factor; + blend.rt[0].alpha_dst_factor = *alpha_dst_factor; + blend.rt[0].colormask = PIPE_MASK_RGBA; + + if(!test_one(gallivm, verbose, fp, &blend, mode, *type)) + success = FALSE; + } + + return success; +} + + +boolean +test_single(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + printf("no test_single()"); + return TRUE; +} diff --git a/src/gallium/drivers/llvmpipe/lp_test_conv.c b/src/gallium/drivers/llvmpipe/lp_test_conv.c new file mode 100644 index 0000000..f4a2f36 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_test_conv.c @@ -0,0 +1,437 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * @file + * Unit tests for type conversion. + * + * @author Jose Fonseca + */ + + +#include "util/u_pointer.h" +#include "gallivm/lp_bld_init.h" +#include "gallivm/lp_bld_type.h" +#include "gallivm/lp_bld_const.h" +#include "gallivm/lp_bld_conv.h" +#include "gallivm/lp_bld_debug.h" +#include "lp_test.h" + + +typedef void (*conv_test_ptr_t)(const void *src, const void *dst); + + +void +write_tsv_header(FILE *fp) +{ + fprintf(fp, + "result\t" + "cycles_per_channel\t" + "src_type\t" + "dst_type\n"); + + fflush(fp); +} + + +static void +write_tsv_row(FILE *fp, + struct lp_type src_type, + struct lp_type dst_type, + double cycles, + boolean success) +{ + fprintf(fp, "%s\t", success ? "pass" : "fail"); + + fprintf(fp, "%.1f\t", cycles / MAX2(src_type.length, dst_type.length)); + + dump_type(fp, src_type); + fprintf(fp, "\t"); + + dump_type(fp, dst_type); + fprintf(fp, "\n"); + + fflush(fp); +} + + +static void +dump_conv_types(FILE *fp, + struct lp_type src_type, + struct lp_type dst_type) +{ + fprintf(fp, "src_type="); + dump_type(fp, src_type); + + fprintf(fp, " dst_type="); + dump_type(fp, dst_type); + + fprintf(fp, " ...\n"); + fflush(fp); +} + + +static LLVMValueRef +add_conv_test(struct gallivm_state *gallivm, + struct lp_type src_type, unsigned num_srcs, + struct lp_type dst_type, unsigned num_dsts) +{ + LLVMModuleRef module = gallivm->module; + LLVMContextRef context = gallivm->context; + LLVMBuilderRef builder = gallivm->builder; + LLVMTypeRef args[2]; + LLVMValueRef func; + LLVMValueRef src_ptr; + LLVMValueRef dst_ptr; + LLVMBasicBlockRef block; + LLVMValueRef src[LP_MAX_VECTOR_LENGTH]; + LLVMValueRef dst[LP_MAX_VECTOR_LENGTH]; + unsigned i; + + args[0] = LLVMPointerType(lp_build_vec_type(gallivm, src_type), 0); + args[1] = LLVMPointerType(lp_build_vec_type(gallivm, dst_type), 0); + + func = LLVMAddFunction(module, "test", + LLVMFunctionType(LLVMVoidTypeInContext(context), + args, 2, 0)); + LLVMSetFunctionCallConv(func, LLVMCCallConv); + src_ptr = LLVMGetParam(func, 0); + dst_ptr = LLVMGetParam(func, 1); + + block = LLVMAppendBasicBlockInContext(context, func, "entry"); + LLVMPositionBuilderAtEnd(builder, block); + + for(i = 0; i < num_srcs; ++i) { + LLVMValueRef index = LLVMConstInt(LLVMInt32TypeInContext(context), i, 0); + LLVMValueRef ptr = LLVMBuildGEP(builder, src_ptr, &index, 1, ""); + src[i] = LLVMBuildLoad(builder, ptr, ""); + } + + lp_build_conv(gallivm, src_type, dst_type, src, num_srcs, dst, num_dsts); + + for(i = 0; i < num_dsts; ++i) { + LLVMValueRef index = LLVMConstInt(LLVMInt32TypeInContext(context), i, 0); + LLVMValueRef ptr = LLVMBuildGEP(builder, dst_ptr, &index, 1, ""); + LLVMBuildStore(builder, dst[i], ptr); + } + + LLVMBuildRetVoid(builder);; + + return func; +} + + +PIPE_ALIGN_STACK +static boolean +test_one(struct gallivm_state *gallivm, unsigned verbose, + FILE *fp, + struct lp_type src_type, + struct lp_type dst_type) +{ + LLVMModuleRef module = gallivm->module; + LLVMExecutionEngineRef engine = gallivm->engine; + LLVMValueRef func = NULL; + char *error = NULL; + conv_test_ptr_t conv_test_ptr; + boolean success; + const unsigned n = LP_TEST_NUM_SAMPLES; + int64_t cycles[LP_TEST_NUM_SAMPLES]; + double cycles_avg = 0.0; + unsigned num_srcs; + unsigned num_dsts; + double eps; + unsigned i, j; + void *code; + + if (src_type.width * src_type.length != dst_type.width * dst_type.length && + src_type.length != dst_type.length) { + return TRUE; + } + + if(verbose >= 1) + dump_conv_types(stdout, src_type, dst_type); + + if (src_type.length > dst_type.length) { + num_srcs = 1; + num_dsts = src_type.length/dst_type.length; + } + else if (src_type.length < dst_type.length) { + num_dsts = 1; + num_srcs = dst_type.length/src_type.length; + } + else { + num_dsts = 1; + num_srcs = 1; + } + + /* We must not loose or gain channels. Only precision */ + assert(src_type.length * num_srcs == dst_type.length * num_dsts); + + eps = MAX2(lp_const_eps(src_type), lp_const_eps(dst_type)); + + func = add_conv_test(gallivm, src_type, num_srcs, dst_type, num_dsts); + + if(LLVMVerifyModule(module, LLVMPrintMessageAction, &error)) { + LLVMDumpModule(module); + abort(); + } + LLVMDisposeMessage(error); + + if(verbose >= 2) + LLVMDumpModule(module); + + code = LLVMGetPointerToGlobal(engine, func); + conv_test_ptr = (conv_test_ptr_t)pointer_to_func(code); + + if(verbose >= 2) + lp_disassemble(code); + + success = TRUE; + for(i = 0; i < n && success; ++i) { + unsigned src_stride = src_type.length*src_type.width/8; + unsigned dst_stride = dst_type.length*dst_type.width/8; + PIPE_ALIGN_VAR(16) uint8_t src[LP_MAX_VECTOR_LENGTH*LP_MAX_VECTOR_LENGTH]; + PIPE_ALIGN_VAR(16) uint8_t dst[LP_MAX_VECTOR_LENGTH*LP_MAX_VECTOR_LENGTH]; + double fref[LP_MAX_VECTOR_LENGTH*LP_MAX_VECTOR_LENGTH]; + uint8_t ref[LP_MAX_VECTOR_LENGTH*LP_MAX_VECTOR_LENGTH]; + int64_t start_counter = 0; + int64_t end_counter = 0; + + for(j = 0; j < num_srcs; ++j) { + random_vec(src_type, src + j*src_stride); + read_vec(src_type, src + j*src_stride, fref + j*src_type.length); + } + + for(j = 0; j < num_dsts; ++j) { + write_vec(dst_type, ref + j*dst_stride, fref + j*dst_type.length); + } + + start_counter = rdtsc(); + conv_test_ptr(src, dst); + end_counter = rdtsc(); + + cycles[i] = end_counter - start_counter; + + for(j = 0; j < num_dsts; ++j) { + if(!compare_vec_with_eps(dst_type, dst + j*dst_stride, ref + j*dst_stride, eps)) + success = FALSE; + } + + if (!success || verbose >= 3) { + if(verbose < 1) + dump_conv_types(stderr, src_type, dst_type); + if (success) { + fprintf(stderr, "PASS\n"); + } + else { + fprintf(stderr, "MISMATCH\n"); + } + + for(j = 0; j < num_srcs; ++j) { + fprintf(stderr, " Src%u: ", j); + dump_vec(stderr, src_type, src + j*src_stride); + fprintf(stderr, "\n"); + } + +#if 1 + fprintf(stderr, " Ref: "); + for(j = 0; j < src_type.length*num_srcs; ++j) + fprintf(stderr, " %f", fref[j]); + fprintf(stderr, "\n"); +#endif + + for(j = 0; j < num_dsts; ++j) { + fprintf(stderr, " Dst%u: ", j); + dump_vec(stderr, dst_type, dst + j*dst_stride); + fprintf(stderr, "\n"); + + fprintf(stderr, " Ref%u: ", j); + dump_vec(stderr, dst_type, ref + j*dst_stride); + fprintf(stderr, "\n"); + } + } + } + + /* + * Unfortunately the output of cycle counter is not very reliable as it comes + * -- sometimes we get outliers (due IRQs perhaps?) which are + * better removed to avoid random or biased data. + */ + { + double sum = 0.0, sum2 = 0.0; + double avg, std; + unsigned m; + + for(i = 0; i < n; ++i) { + sum += cycles[i]; + sum2 += cycles[i]*cycles[i]; + } + + avg = sum/n; + std = sqrtf((sum2 - n*avg*avg)/n); + + m = 0; + sum = 0.0; + for(i = 0; i < n; ++i) { + if(fabs(cycles[i] - avg) <= 4.0*std) { + sum += cycles[i]; + ++m; + } + } + + cycles_avg = sum/m; + + } + + if(fp) + write_tsv_row(fp, src_type, dst_type, cycles_avg, success); + + if (!success) { + static boolean firsttime = TRUE; + if(firsttime) { + if(verbose < 2) + LLVMDumpModule(module); + LLVMWriteBitcodeToFile(module, "conv.bc"); + fprintf(stderr, "conv.bc written\n"); + fprintf(stderr, "Invoke as \"llc -o - conv.bc\"\n"); + firsttime = FALSE; + /* abort(); */ + } + } + + LLVMFreeMachineCodeForFunction(engine, func); + + return success; +} + + +const struct lp_type conv_types[] = { + /* float, fixed, sign, norm, width, len */ + + { TRUE, FALSE, TRUE, TRUE, 32, 4 }, + { TRUE, FALSE, TRUE, FALSE, 32, 4 }, + { TRUE, FALSE, FALSE, TRUE, 32, 4 }, + { TRUE, FALSE, FALSE, FALSE, 32, 4 }, + + /* TODO: test fixed formats too */ + + { FALSE, FALSE, TRUE, TRUE, 16, 8 }, + { FALSE, FALSE, TRUE, FALSE, 16, 8 }, + { FALSE, FALSE, FALSE, TRUE, 16, 8 }, + { FALSE, FALSE, FALSE, FALSE, 16, 8 }, + + { FALSE, FALSE, TRUE, TRUE, 32, 4 }, + { FALSE, FALSE, TRUE, FALSE, 32, 4 }, + { FALSE, FALSE, FALSE, TRUE, 32, 4 }, + { FALSE, FALSE, FALSE, FALSE, 32, 4 }, + + { FALSE, FALSE, TRUE, TRUE, 16, 8 }, + { FALSE, FALSE, TRUE, FALSE, 16, 8 }, + { FALSE, FALSE, FALSE, TRUE, 16, 8 }, + { FALSE, FALSE, FALSE, FALSE, 16, 8 }, + + { FALSE, FALSE, TRUE, TRUE, 8, 16 }, + { FALSE, FALSE, TRUE, FALSE, 8, 16 }, + { FALSE, FALSE, FALSE, TRUE, 8, 16 }, + { FALSE, FALSE, FALSE, FALSE, 8, 16 }, + + { FALSE, FALSE, TRUE, TRUE, 8, 4 }, + { FALSE, FALSE, TRUE, FALSE, 8, 4 }, + { FALSE, FALSE, FALSE, TRUE, 8, 4 }, + { FALSE, FALSE, FALSE, FALSE, 8, 4 }, +}; + + +const unsigned num_types = sizeof(conv_types)/sizeof(conv_types[0]); + + +boolean +test_all(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + const struct lp_type *src_type; + const struct lp_type *dst_type; + boolean success = TRUE; + + for(src_type = conv_types; src_type < &conv_types[num_types]; ++src_type) { + for(dst_type = conv_types; dst_type < &conv_types[num_types]; ++dst_type) { + + if(src_type == dst_type) + continue; + + if(src_type->norm != dst_type->norm) + continue; + + if(!test_one(gallivm, verbose, fp, *src_type, *dst_type)) + success = FALSE; + + } + } + + return success; +} + + +boolean +test_some(struct gallivm_state *gallivm, unsigned verbose, FILE *fp, + unsigned long n) +{ + const struct lp_type *src_type; + const struct lp_type *dst_type; + unsigned long i; + boolean success = TRUE; + + for(i = 0; i < n; ++i) { + src_type = &conv_types[rand() % num_types]; + + do { + dst_type = &conv_types[rand() % num_types]; + } while (src_type == dst_type || src_type->norm != dst_type->norm); + + if(!test_one(gallivm, verbose, fp, *src_type, *dst_type)) + success = FALSE; + } + + return success; +} + + +boolean +test_single(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + /* float, fixed, sign, norm, width, len */ + struct lp_type f32x4_type = + { TRUE, FALSE, TRUE, TRUE, 32, 4 }; + struct lp_type ub8x4_type = + { FALSE, FALSE, FALSE, TRUE, 8, 16 }; + + boolean success; + + success = test_one(gallivm, verbose, fp, f32x4_type, ub8x4_type); + + return success; +} diff --git a/src/gallium/drivers/llvmpipe/lp_test_format.c b/src/gallium/drivers/llvmpipe/lp_test_format.c new file mode 100644 index 0000000..4152ca6 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_test_format.c @@ -0,0 +1,375 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include +#include +#include + +#include "util/u_memory.h" +#include "util/u_pointer.h" +#include "util/u_string.h" +#include "util/u_format.h" +#include "util/u_format_tests.h" +#include "util/u_format_s3tc.h" + +#include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_debug.h" +#include "gallivm/lp_bld_format.h" +#include "gallivm/lp_bld_init.h" + +#include "lp_test.h" + + +void +write_tsv_header(FILE *fp) +{ + fprintf(fp, + "result\t" + "format\n"); + + fflush(fp); +} + + +static void +write_tsv_row(FILE *fp, + const struct util_format_description *desc, + boolean success) +{ + fprintf(fp, "%s\t", success ? "pass" : "fail"); + + fprintf(fp, "%s\n", desc->name); + + fflush(fp); +} + + +typedef void +(*fetch_ptr_t)(void *unpacked, const void *packed, + unsigned i, unsigned j); + + +static LLVMValueRef +add_fetch_rgba_test(struct gallivm_state *gallivm, unsigned verbose, + const struct util_format_description *desc, + struct lp_type type) +{ + char name[256]; + LLVMContextRef context = gallivm->context; + LLVMModuleRef module = gallivm->module; + LLVMBuilderRef builder = gallivm->builder; + LLVMPassManagerRef passmgr = gallivm->passmgr; + LLVMTypeRef args[4]; + LLVMValueRef func; + LLVMValueRef packed_ptr; + LLVMValueRef offset = LLVMConstNull(LLVMInt32TypeInContext(context)); + LLVMValueRef rgba_ptr; + LLVMValueRef i; + LLVMValueRef j; + LLVMBasicBlockRef block; + LLVMValueRef rgba; + + util_snprintf(name, sizeof name, "fetch_%s_%s", desc->short_name, + type.floating ? "float" : "unorm8"); + + args[0] = LLVMPointerType(lp_build_vec_type(gallivm, type), 0); + args[1] = LLVMPointerType(LLVMInt8TypeInContext(context), 0); + args[3] = args[2] = LLVMInt32TypeInContext(context); + + func = LLVMAddFunction(module, name, + LLVMFunctionType(LLVMVoidTypeInContext(context), + args, Elements(args), 0)); + LLVMSetFunctionCallConv(func, LLVMCCallConv); + rgba_ptr = LLVMGetParam(func, 0); + packed_ptr = LLVMGetParam(func, 1); + i = LLVMGetParam(func, 2); + j = LLVMGetParam(func, 3); + + block = LLVMAppendBasicBlockInContext(context, func, "entry"); + LLVMPositionBuilderAtEnd(builder, block); + + rgba = lp_build_fetch_rgba_aos(gallivm, desc, type, + packed_ptr, offset, i, j); + + LLVMBuildStore(builder, rgba, rgba_ptr); + + LLVMBuildRetVoid(builder); + + if (LLVMVerifyFunction(func, LLVMPrintMessageAction)) { + LLVMDumpValue(func); + abort(); + } + + LLVMRunFunctionPassManager(passmgr, func); + + if (verbose >= 1) { + LLVMDumpValue(func); + } + + return func; +} + + +PIPE_ALIGN_STACK +static boolean +test_format_float(struct gallivm_state *gallivm, unsigned verbose, FILE *fp, + const struct util_format_description *desc) +{ + LLVMValueRef fetch = NULL; + LLVMExecutionEngineRef engine = gallivm->engine; + fetch_ptr_t fetch_ptr; + PIPE_ALIGN_VAR(16) float unpacked[4]; + boolean first = TRUE; + boolean success = TRUE; + unsigned i, j, k, l; + void *f; + + fetch = add_fetch_rgba_test(gallivm, verbose, desc, lp_float32_vec4_type()); + + f = LLVMGetPointerToGlobal(engine, fetch); + fetch_ptr = (fetch_ptr_t) pointer_to_func(f); + + if (verbose >= 2) { + lp_disassemble(f); + } + + for (l = 0; l < util_format_nr_test_cases; ++l) { + const struct util_format_test_case *test = &util_format_test_cases[l]; + + if (test->format == desc->format) { + + if (first) { + printf("Testing %s (float) ...\n", + desc->name); + first = FALSE; + } + + for (i = 0; i < desc->block.height; ++i) { + for (j = 0; j < desc->block.width; ++j) { + boolean match; + + memset(unpacked, 0, sizeof unpacked); + + fetch_ptr(unpacked, test->packed, j, i); + + match = TRUE; + for(k = 0; k < 4; ++k) + if (fabs((float)test->unpacked[i][j][k] - unpacked[k]) > FLT_EPSILON) + match = FALSE; + + if (!match) { + printf("FAILED\n"); + printf(" Packed: %02x %02x %02x %02x\n", + test->packed[0], test->packed[1], test->packed[2], test->packed[3]); + printf(" Unpacked (%u,%u): %f %f %f %f obtained\n", + j, i, + unpacked[0], unpacked[1], unpacked[2], unpacked[3]); + printf(" %f %f %f %f expected\n", + test->unpacked[i][j][0], + test->unpacked[i][j][1], + test->unpacked[i][j][2], + test->unpacked[i][j][3]); + success = FALSE; + } + } + } + } + } + + if (!success) { + if (verbose < 1) { + LLVMDumpValue(fetch); + } + } + + LLVMFreeMachineCodeForFunction(engine, fetch); + LLVMDeleteFunction(fetch); + + if(fp) + write_tsv_row(fp, desc, success); + + return success; +} + + +PIPE_ALIGN_STACK +static boolean +test_format_unorm8(struct gallivm_state *gallivm, + unsigned verbose, FILE *fp, + const struct util_format_description *desc) +{ + LLVMValueRef fetch = NULL; + fetch_ptr_t fetch_ptr; + uint8_t unpacked[4]; + boolean first = TRUE; + boolean success = TRUE; + unsigned i, j, k, l; + void *f; + + fetch = add_fetch_rgba_test(gallivm, verbose, desc, lp_unorm8_vec4_type()); + + f = LLVMGetPointerToGlobal(gallivm->engine, fetch); + fetch_ptr = (fetch_ptr_t) pointer_to_func(f); + + if (verbose >= 2) { + lp_disassemble(f); + } + + for (l = 0; l < util_format_nr_test_cases; ++l) { + const struct util_format_test_case *test = &util_format_test_cases[l]; + + if (test->format == desc->format) { + + if (first) { + printf("Testing %s (unorm8) ...\n", + desc->name); + first = FALSE; + } + + for (i = 0; i < desc->block.height; ++i) { + for (j = 0; j < desc->block.width; ++j) { + boolean match; + + memset(unpacked, 0, sizeof unpacked); + + fetch_ptr(unpacked, test->packed, j, i); + + match = TRUE; + for(k = 0; k < 4; ++k) { + int error = float_to_ubyte(test->unpacked[i][j][k]) - unpacked[k]; + if (error < 0) + error = -error; + if (error > 1) + match = FALSE; + } + + if (!match) { + printf("FAILED\n"); + printf(" Packed: %02x %02x %02x %02x\n", + test->packed[0], test->packed[1], test->packed[2], test->packed[3]); + printf(" Unpacked (%u,%u): %02x %02x %02x %02x obtained\n", + j, i, + unpacked[0], unpacked[1], unpacked[2], unpacked[3]); + printf(" %02x %02x %02x %02x expected\n", + float_to_ubyte(test->unpacked[i][j][0]), + float_to_ubyte(test->unpacked[i][j][1]), + float_to_ubyte(test->unpacked[i][j][2]), + float_to_ubyte(test->unpacked[i][j][3])); + success = FALSE; + } + } + } + } + } + + if (!success) + LLVMDumpValue(fetch); + + LLVMFreeMachineCodeForFunction(gallivm->engine, fetch); + LLVMDeleteFunction(fetch); + + if(fp) + write_tsv_row(fp, desc, success); + + return success; +} + + + + +static boolean +test_one(struct gallivm_state *gallivm, + unsigned verbose, FILE *fp, + const struct util_format_description *format_desc) +{ + boolean success = TRUE; + + if (!test_format_float(gallivm, verbose, fp, format_desc)) { + success = FALSE; + } + + if (!test_format_unorm8(gallivm, verbose, fp, format_desc)) { + success = FALSE; + } + + return success; +} + + +boolean +test_all(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + enum pipe_format format; + boolean success = TRUE; + + util_format_s3tc_init(); + + for (format = 1; format < PIPE_FORMAT_COUNT; ++format) { + const struct util_format_description *format_desc; + + format_desc = util_format_description(format); + if (!format_desc) { + continue; + } + + /* + * TODO: test more + */ + + if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) { + continue; + } + + if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC && + !util_format_s3tc_enabled) { + continue; + } + + if (!test_one(gallivm, verbose, fp, format_desc)) { + success = FALSE; + } + } + + return success; +} + + +boolean +test_some(struct gallivm_state *gallivm, unsigned verbose, FILE *fp, + unsigned long n) +{ + return test_all(gallivm, verbose, fp); +} + + +boolean +test_single(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + printf("no test_single()"); + return TRUE; +} diff --git a/src/gallium/drivers/llvmpipe/lp_test_main.c b/src/gallium/drivers/llvmpipe/lp_test_main.c new file mode 100644 index 0000000..149ee6f --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_test_main.c @@ -0,0 +1,420 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +/** + * @file + * Shared testing code. + * + * @author Jose Fonseca + */ + + +#include "util/u_cpu_detect.h" + +#include "gallivm/lp_bld_const.h" +#include "gallivm/lp_bld_init.h" +#include "lp_test.h" + + +#ifdef PIPE_CC_MSVC +static INLINE double +round(double x) +{ + if (x >= 0.0) + return floor(x + 0.5); + else + return ceil(x - 0.5); +} +#endif + + +void +dump_type(FILE *fp, + struct lp_type type) +{ + fprintf(fp, "%s%s%u%sx%u", + type.sign ? (type.floating || type.fixed ? "" : "s") : "u", + type.floating ? "f" : (type.fixed ? "h" : "i"), + type.width, + type.norm ? "n" : "", + type.length); +} + + +double +read_elem(struct lp_type type, const void *src, unsigned index) +{ + double scale = lp_const_scale(type); + double value; + assert(index < type.length); + if (type.floating) { + switch(type.width) { + case 32: + value = *((const float *)src + index); + break; + case 64: + value = *((const double *)src + index); + break; + default: + assert(0); + return 0.0; + } + } + else { + if(type.sign) { + switch(type.width) { + case 8: + value = *((const int8_t *)src + index); + break; + case 16: + value = *((const int16_t *)src + index); + break; + case 32: + value = *((const int32_t *)src + index); + break; + case 64: + value = *((const int64_t *)src + index); + break; + default: + assert(0); + return 0.0; + } + } + else { + switch(type.width) { + case 8: + value = *((const uint8_t *)src + index); + break; + case 16: + value = *((const uint16_t *)src + index); + break; + case 32: + value = *((const uint32_t *)src + index); + break; + case 64: + value = *((const uint64_t *)src + index); + break; + default: + assert(0); + return 0.0; + } + } + } + return value/scale; +} + + +void +write_elem(struct lp_type type, void *dst, unsigned index, double value) +{ + assert(index < type.length); + if(!type.sign && value < 0.0) + value = 0.0; + if(type.norm && value < -1.0) + value = -1.0; + if(type.norm && value > 1.0) + value = 1.0; + if (type.floating) { + switch(type.width) { + case 32: + *((float *)dst + index) = (float)(value); + break; + case 64: + *((double *)dst + index) = value; + break; + default: + assert(0); + } + } + else { + double scale = lp_const_scale(type); + value = round(value*scale); + if(type.sign) { + long long lvalue = (long long)value; + lvalue = MIN2(lvalue, ((long long)1 << (type.width - 1)) - 1); + switch(type.width) { + case 8: + *((int8_t *)dst + index) = (int8_t)lvalue; + break; + case 16: + *((int16_t *)dst + index) = (int16_t)lvalue; + break; + case 32: + *((int32_t *)dst + index) = (int32_t)lvalue; + break; + case 64: + *((int64_t *)dst + index) = (int64_t)lvalue; + break; + default: + assert(0); + } + } + else { + unsigned long long lvalue = (long long)value; + lvalue = MIN2(lvalue, ((unsigned long long)1 << type.width) - 1); + switch(type.width) { + case 8: + *((uint8_t *)dst + index) = (uint8_t)lvalue; + break; + case 16: + *((uint16_t *)dst + index) = (uint16_t)lvalue; + break; + case 32: + *((uint32_t *)dst + index) = (uint32_t)lvalue; + break; + case 64: + *((uint64_t *)dst + index) = (uint64_t)lvalue; + break; + default: + assert(0); + } + } + } +} + + +void +random_elem(struct lp_type type, void *dst, unsigned index) +{ + double value; + assert(index < type.length); + value = (double)rand()/(double)RAND_MAX; + if(!type.norm) { + if (type.floating) { + value *= 2.0; + } + else { + unsigned long long mask; + if (type.fixed) + mask = ((unsigned long long)1 << (type.width / 2)) - 1; + else if (type.sign) + mask = ((unsigned long long)1 << (type.width - 1)) - 1; + else + mask = ((unsigned long long)1 << type.width) - 1; + value += (double)(mask & rand()); + } + } + if(!type.sign) + if(rand() & 1) + value = -value; + write_elem(type, dst, index, value); +} + + +void +read_vec(struct lp_type type, const void *src, double *dst) +{ + unsigned i; + for (i = 0; i < type.length; ++i) + dst[i] = read_elem(type, src, i); +} + + +void +write_vec(struct lp_type type, void *dst, const double *src) +{ + unsigned i; + for (i = 0; i < type.length; ++i) + write_elem(type, dst, i, src[i]); +} + + +float +random_float(void) +{ + return (float)((double)rand()/(double)RAND_MAX); +} + + +void +random_vec(struct lp_type type, void *dst) +{ + unsigned i; + for (i = 0; i < type.length; ++i) + random_elem(type, dst, i); +} + + +boolean +compare_vec_with_eps(struct lp_type type, const void *res, const void *ref, double eps) +{ + unsigned i; + eps *= type.floating ? 8.0 : 2.0; + for (i = 0; i < type.length; ++i) { + double res_elem = read_elem(type, res, i); + double ref_elem = read_elem(type, ref, i); + double delta = res_elem - ref_elem; + if (ref_elem < -1.0 || ref_elem > 1.0) { + delta /= ref_elem; + } + delta = fabs(delta); + if (delta >= eps) { + return FALSE; + } + } + + return TRUE; +} + + +boolean +compare_vec(struct lp_type type, const void *res, const void *ref) +{ + double eps = lp_const_eps(type); + return compare_vec_with_eps(type, res, ref, eps); +} + + +void +dump_vec(FILE *fp, struct lp_type type, const void *src) +{ + unsigned i; + for (i = 0; i < type.length; ++i) { + if(i) + fprintf(fp, " "); + if (type.floating) { + double value; + switch(type.width) { + case 32: + value = *((const float *)src + i); + break; + case 64: + value = *((const double *)src + i); + break; + default: + assert(0); + value = 0.0; + } + fprintf(fp, "%f", value); + } + else { + if(type.sign && !type.norm) { + long long value; + const char *format; + switch(type.width) { + case 8: + value = *((const int8_t *)src + i); + format = "%3lli"; + break; + case 16: + value = *((const int16_t *)src + i); + format = "%5lli"; + break; + case 32: + value = *((const int32_t *)src + i); + format = "%10lli"; + break; + case 64: + value = *((const int64_t *)src + i); + format = "%20lli"; + break; + default: + assert(0); + value = 0.0; + format = "?"; + } + fprintf(fp, format, value); + } + else { + unsigned long long value; + const char *format; + switch(type.width) { + case 8: + value = *((const uint8_t *)src + i); + format = type.norm ? "%2x" : "%4llu"; + break; + case 16: + value = *((const uint16_t *)src + i); + format = type.norm ? "%4x" : "%6llx"; + break; + case 32: + value = *((const uint32_t *)src + i); + format = type.norm ? "%8x" : "%11llx"; + break; + case 64: + value = *((const uint64_t *)src + i); + format = type.norm ? "%16x" : "%21llx"; + break; + default: + assert(0); + value = 0.0; + format = "?"; + } + fprintf(fp, format, value); + } + } + } +} + + +int main(int argc, char **argv) +{ + unsigned verbose = 0; + FILE *fp = NULL; + unsigned long n = 1000; + unsigned i; + boolean success; + boolean single = FALSE; + struct gallivm_state *gallivm; + + for(i = 1; i < argc; ++i) { + if(strcmp(argv[i], "-v") == 0) + ++verbose; + else if(strcmp(argv[i], "-s") == 0) + single = TRUE; + else if(strcmp(argv[i], "-o") == 0) + fp = fopen(argv[++i], "wt"); + else + n = atoi(argv[i]); + } + + lp_build_init(); + + gallivm = gallivm_create(); + + util_cpu_detect(); + + if(fp) { + /* Warm up the caches */ + test_some(gallivm, 0, NULL, 100); + + write_tsv_header(fp); + } + + if (single) + success = test_single(gallivm, verbose, fp); + else if (n) + success = test_some(gallivm, verbose, fp, n); + else + success = test_all(gallivm, verbose, fp); + + if(fp) + fclose(fp); + + return success ? 0 : 1; +} diff --git a/src/gallium/drivers/llvmpipe/lp_test_printf.c b/src/gallium/drivers/llvmpipe/lp_test_printf.c new file mode 100644 index 0000000..620cdb5 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_test_printf.c @@ -0,0 +1,144 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include +#include + +#include "util/u_pointer.h" +#include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_init.h" +#include "gallivm/lp_bld_assert.h" +#include "gallivm/lp_bld_printf.h" + +#include "lp_test.h" + + +struct printf_test_case { + int foo; +}; + +void +write_tsv_header(FILE *fp) +{ + fprintf(fp, + "result\t" + "format\n"); + + fflush(fp); +} + + + +typedef void (*test_printf_t)(int i); + + +static LLVMValueRef +add_printf_test(struct gallivm_state *gallivm) +{ + LLVMModuleRef module = gallivm->module; + LLVMTypeRef args[1] = { LLVMIntTypeInContext(gallivm->context, 32) }; + LLVMValueRef func = LLVMAddFunction(module, "test_printf", LLVMFunctionType(LLVMVoidTypeInContext(gallivm->context), args, 1, 0)); + LLVMBuilderRef builder = gallivm->builder; + LLVMBasicBlockRef block = LLVMAppendBasicBlockInContext(gallivm->context, func, "entry"); + + LLVMSetFunctionCallConv(func, LLVMCCallConv); + + LLVMPositionBuilderAtEnd(builder, block); + lp_build_printf(gallivm, "hello, world\n"); + lp_build_printf(gallivm, "print 5 6: %d %d\n", LLVMConstInt(LLVMInt32TypeInContext(gallivm->context), 5, 0), + LLVMConstInt(LLVMInt32TypeInContext(gallivm->context), 6, 0)); + + /* Also test lp_build_assert(). This should not fail. */ + lp_build_assert(gallivm, LLVMConstInt(LLVMInt32TypeInContext(gallivm->context), 1, 0), "assert(1)"); + + LLVMBuildRetVoid(builder); + + return func; +} + + +PIPE_ALIGN_STACK +static boolean +test_printf(struct gallivm_state *gallivm, + unsigned verbose, FILE *fp, + const struct printf_test_case *testcase) +{ + LLVMExecutionEngineRef engine = gallivm->engine; + LLVMModuleRef module = gallivm->module; + LLVMValueRef test; + char *error = NULL; + test_printf_t test_printf_func; + boolean success = TRUE; + void *code; + + test = add_printf_test(gallivm); + + if(LLVMVerifyModule(module, LLVMPrintMessageAction, &error)) { + LLVMDumpModule(module); + abort(); + } + LLVMDisposeMessage(error); + + code = LLVMGetPointerToGlobal(engine, test); + test_printf_func = (test_printf_t) pointer_to_func(code); + + // LLVMDumpModule(module); + + test_printf_func(0); + + LLVMFreeMachineCodeForFunction(engine, test); + + return success; +} + + +boolean +test_all(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + boolean success = TRUE; + + test_printf(gallivm, verbose, fp, NULL); + + return success; +} + + +boolean +test_some(struct gallivm_state *gallivm, unsigned verbose, FILE *fp, + unsigned long n) +{ + return test_all(gallivm, verbose, fp); +} + + +boolean +test_single(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + printf("no test_single()"); + return TRUE; +} diff --git a/src/gallium/drivers/llvmpipe/lp_test_round.c b/src/gallium/drivers/llvmpipe/lp_test_round.c new file mode 100644 index 0000000..4edee4a --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_test_round.c @@ -0,0 +1,245 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include +#include + +#include "util/u_pointer.h" +#include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_init.h" +#include "gallivm/lp_bld_arit.h" + +#include "lp_test.h" + + +void +write_tsv_header(FILE *fp) +{ + fprintf(fp, + "result\t" + "format\n"); + + fflush(fp); +} + + +#ifdef PIPE_ARCH_SSE + +#define USE_SSE2 +#include "sse_mathfun.h" + +typedef __m128 (*test_round_t)(__m128); + +typedef LLVMValueRef (*lp_func_t)(struct lp_build_context *, LLVMValueRef); + + +static LLVMValueRef +add_test(struct gallivm_state *gallivm, const char *name, lp_func_t lp_func) +{ + LLVMModuleRef module = gallivm->module; + LLVMContextRef context = gallivm->context; + LLVMBuilderRef builder = gallivm->builder; + + LLVMTypeRef v4sf = LLVMVectorType(LLVMFloatTypeInContext(context), 4); + LLVMTypeRef args[1] = { v4sf }; + LLVMValueRef func = LLVMAddFunction(module, name, LLVMFunctionType(v4sf, args, 1, 0)); + LLVMValueRef arg1 = LLVMGetParam(func, 0); + LLVMBasicBlockRef block = LLVMAppendBasicBlockInContext(context, func, "entry"); + LLVMValueRef ret; + struct lp_build_context bld; + + lp_build_context_init(&bld, gallivm, lp_float32_vec4_type()); + + LLVMSetFunctionCallConv(func, LLVMCCallConv); + + LLVMPositionBuilderAtEnd(builder, block); + + ret = lp_func(&bld, arg1); + + LLVMBuildRet(builder, ret); + + return func; +} + +static void +printv(char* string, v4sf value) +{ + v4sf v = value; + float *f = (float *)&v; + printf("%s: %10f %10f %10f %10f\n", string, + f[0], f[1], f[2], f[3]); +} + +static boolean +compare(v4sf x, v4sf y) +{ + boolean success = TRUE; + float *xp = (float *) &x; + float *yp = (float *) &y; + if (xp[0] != yp[0] || + xp[1] != yp[1] || + xp[2] != yp[2] || + xp[3] != yp[3]) { + printf(" Incorrect result! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); + success = FALSE; + } + return success; +} + + + +PIPE_ALIGN_STACK +static boolean +test_round(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + LLVMModuleRef module = gallivm->module; + LLVMValueRef test_round = NULL, test_trunc, test_floor, test_ceil; + LLVMExecutionEngineRef engine = gallivm->engine; + char *error = NULL; + test_round_t round_func, trunc_func, floor_func, ceil_func; + float unpacked[4]; + unsigned packed; + boolean success = TRUE; + int i; + + test_round = add_test(gallivm, "round", lp_build_round); + test_trunc = add_test(gallivm, "trunc", lp_build_trunc); + test_floor = add_test(gallivm, "floor", lp_build_floor); + test_ceil = add_test(gallivm, "ceil", lp_build_ceil); + + if(LLVMVerifyModule(module, LLVMPrintMessageAction, &error)) { + printf("LLVMVerifyModule: %s\n", error); + LLVMDumpModule(module); + abort(); + } + LLVMDisposeMessage(error); + + round_func = (test_round_t) pointer_to_func(LLVMGetPointerToGlobal(engine, test_round)); + trunc_func = (test_round_t) pointer_to_func(LLVMGetPointerToGlobal(engine, test_trunc)); + floor_func = (test_round_t) pointer_to_func(LLVMGetPointerToGlobal(engine, test_floor)); + ceil_func = (test_round_t) pointer_to_func(LLVMGetPointerToGlobal(engine, test_ceil)); + + memset(unpacked, 0, sizeof unpacked); + packed = 0; + + if (0) + LLVMDumpModule(module); + + for (i = 0; i < 3; i++) { + /* NOTE: There are several acceptable rules for x.5 rounding: ceiling, + * nearest even, etc. So we avoid testing such corner cases here. + */ + v4sf xvals[3] = { + {-10.0, -1, 0, 12.0}, + {-1.49, -0.25, 1.25, 2.51}, + {-0.99, -0.01, 0.01, 0.99} + }; + v4sf x = xvals[i]; + v4sf y, ref; + float *xp = (float *) &x; + float *refp = (float *) &ref; + + printf("\n"); + printv("x ", x); + + refp[0] = round(xp[0]); + refp[1] = round(xp[1]); + refp[2] = round(xp[2]); + refp[3] = round(xp[3]); + y = round_func(x); + printv("C round(x) ", ref); + printv("LLVM round(x)", y); + success = success && compare(ref, y); + + refp[0] = trunc(xp[0]); + refp[1] = trunc(xp[1]); + refp[2] = trunc(xp[2]); + refp[3] = trunc(xp[3]); + y = trunc_func(x); + printv("C trunc(x) ", ref); + printv("LLVM trunc(x)", y); + success = success && compare(ref, y); + + refp[0] = floor(xp[0]); + refp[1] = floor(xp[1]); + refp[2] = floor(xp[2]); + refp[3] = floor(xp[3]); + y = floor_func(x); + printv("C floor(x) ", ref); + printv("LLVM floor(x)", y); + success = success && compare(ref, y); + + refp[0] = ceil(xp[0]); + refp[1] = ceil(xp[1]); + refp[2] = ceil(xp[2]); + refp[3] = ceil(xp[3]); + y = ceil_func(x); + printv("C ceil(x) ", ref); + printv("LLVM ceil(x) ", y); + success = success && compare(ref, y); + } + + LLVMFreeMachineCodeForFunction(engine, test_round); + LLVMFreeMachineCodeForFunction(engine, test_trunc); + LLVMFreeMachineCodeForFunction(engine, test_floor); + LLVMFreeMachineCodeForFunction(engine, test_ceil); + + return success; +} + +#else /* !PIPE_ARCH_SSE */ + +static boolean +test_round(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + return TRUE; +} + +#endif /* !PIPE_ARCH_SSE */ + + +boolean +test_all(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + return test_round(gallivm, verbose, fp); +} + + +boolean +test_some(struct gallivm_state *gallivm, unsigned verbose, FILE *fp, + unsigned long n) +{ + return test_all(gallivm, verbose, fp); +} + +boolean +test_single(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + printf("no test_single()"); + return TRUE; +} diff --git a/src/gallium/drivers/llvmpipe/lp_test_sincos.c b/src/gallium/drivers/llvmpipe/lp_test_sincos.c new file mode 100644 index 0000000..066d633 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_test_sincos.c @@ -0,0 +1,171 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include +#include + +#include "util/u_pointer.h" + +#include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_init.h" +#include "gallivm/lp_bld_arit.h" + +#include "lp_test.h" + + +void +write_tsv_header(FILE *fp) +{ + fprintf(fp, + "result\t" + "format\n"); + + fflush(fp); +} + + +#ifdef PIPE_ARCH_SSE + +#define USE_SSE2 +#include "sse_mathfun.h" + +typedef __m128 (*test_sincos_t)(__m128); + +static LLVMValueRef +add_sincos_test(struct gallivm_state *gallivm, LLVMModuleRef module, + LLVMContextRef context, boolean sin) +{ + LLVMTypeRef v4sf = LLVMVectorType(LLVMFloatTypeInContext(context), 4); + LLVMTypeRef args[1] = { v4sf }; + LLVMValueRef func = LLVMAddFunction(module, "sincos", LLVMFunctionType(v4sf, args, 1, 0)); + LLVMValueRef arg1 = LLVMGetParam(func, 0); + LLVMBuilderRef builder = gallivm->builder; + LLVMBasicBlockRef block = LLVMAppendBasicBlockInContext(context, func, "entry"); + LLVMValueRef ret; + struct lp_build_context bld; + + lp_build_context_init(&bld, gallivm, lp_float32_vec4_type()); + + LLVMSetFunctionCallConv(func, LLVMCCallConv); + + LLVMPositionBuilderAtEnd(builder, block); + ret = sin ? lp_build_sin(&bld, arg1) : lp_build_cos(&bld, arg1); + LLVMBuildRet(builder, ret); + return func; +} + +static void +printv(char* string, v4sf value) +{ + v4sf v = value; + uint32_t *p = (uint32_t *) &v; + float *f = (float *)&v; + printf("%s: %f(%x) %f(%x) %f(%x) %f(%x)\n", string, + f[0], p[0], f[1], p[1], f[2], p[2], f[3], p[3]); +} + +PIPE_ALIGN_STACK +static boolean +test_sincos(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + LLVMModuleRef module = gallivm->module; + LLVMValueRef test_sin = NULL, test_cos = NULL; + LLVMExecutionEngineRef engine = gallivm->engine; + LLVMContextRef context = gallivm->context; + char *error = NULL; + test_sincos_t sin_func; + test_sincos_t cos_func; + float unpacked[4]; + boolean success = TRUE; + + test_sin = add_sincos_test(gallivm, module, context, TRUE); + test_cos = add_sincos_test(gallivm, module, context,FALSE); + + if(LLVMVerifyModule(module, LLVMPrintMessageAction, &error)) { + printf("LLVMVerifyModule: %s\n", error); + LLVMDumpModule(module); + abort(); + } + LLVMDisposeMessage(error); + + sin_func = (test_sincos_t) pointer_to_func(LLVMGetPointerToGlobal(engine, test_sin)); + cos_func = (test_sincos_t) pointer_to_func(LLVMGetPointerToGlobal(engine, test_cos)); + + memset(unpacked, 0, sizeof unpacked); + + + // LLVMDumpModule(module); + { + v4sf src = {3.14159/4.0, -3.14159/4.0, 1.0, -1.0}; + printv("ref ",sin_ps(src)); + printv("llvm", sin_func(src)); + printv("ref ",cos_ps(src)); + printv("llvm",cos_func(src)); + } + + LLVMFreeMachineCodeForFunction(engine, test_sin); + LLVMFreeMachineCodeForFunction(engine, test_cos); + + return success; +} + +#else /* !PIPE_ARCH_SSE */ + +static boolean +test_sincos(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + return TRUE; +} + +#endif /* !PIPE_ARCH_SSE */ + + +boolean +test_all(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + boolean success = TRUE; + + test_sincos(gallivm, verbose, fp); + + return success; +} + + +boolean +test_some(struct gallivm_state *gallivm, unsigned verbose, FILE *fp, + unsigned long n) +{ + return test_all(gallivm, verbose, fp); +} + +boolean +test_single(struct gallivm_state *gallivm, unsigned verbose, FILE *fp) +{ + printf("no test_single()"); + return TRUE; +} diff --git a/src/gallium/drivers/llvmpipe/lp_tex_sample.c b/src/gallium/drivers/llvmpipe/lp_tex_sample.c new file mode 100644 index 0000000..ed42829 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_tex_sample.c @@ -0,0 +1,236 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * Texture sampling code generation + * + * This file is nothing more than ugly glue between three largely independent + * entities: + * - TGSI -> LLVM translation (i.e., lp_build_tgsi_soa) + * - texture sampling code generation (i.e., lp_build_sample_soa) + * - LLVM pipe driver + * + * All interesting code is in the functions mentioned above. There is really + * nothing to see here. + * + * @author Jose Fonseca + */ + +#include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" +#include "gallivm/lp_bld_debug.h" +#include "gallivm/lp_bld_const.h" +#include "gallivm/lp_bld_type.h" +#include "gallivm/lp_bld_sample.h" +#include "gallivm/lp_bld_tgsi.h" +#include "lp_jit.h" +#include "lp_tex_sample.h" +#include "lp_debug.h" + + +/** + * This provides the bridge between the sampler state store in + * lp_jit_context and lp_jit_texture and the sampler code + * generator. It provides the texture layout information required by + * the texture sampler code generator in terms of the state stored in + * lp_jit_context and lp_jit_texture in runtime. + */ +struct llvmpipe_sampler_dynamic_state +{ + struct lp_sampler_dynamic_state base; + + const struct lp_sampler_static_state *static_state; + + LLVMValueRef context_ptr; +}; + + +/** + * This is the bridge between our sampler and the TGSI translator. + */ +struct lp_llvm_sampler_soa +{ + struct lp_build_sampler_soa base; + + struct llvmpipe_sampler_dynamic_state dynamic_state; +}; + + +/** + * Fetch the specified member of the lp_jit_texture structure. + * \param emit_load if TRUE, emit the LLVM load instruction to actually + * fetch the field's value. Otherwise, just emit the + * GEP code to address the field. + * + * @sa http://llvm.org/docs/GetElementPtr.html + */ +static LLVMValueRef +lp_llvm_texture_member(const struct lp_sampler_dynamic_state *base, + struct gallivm_state *gallivm, + unsigned unit, + unsigned member_index, + const char *member_name, + boolean emit_load) +{ + struct llvmpipe_sampler_dynamic_state *state = + (struct llvmpipe_sampler_dynamic_state *)base; + LLVMBuilderRef builder = gallivm->builder; + LLVMValueRef indices[4]; + LLVMValueRef ptr; + LLVMValueRef res; + + assert(unit < PIPE_MAX_SAMPLERS); + + /* context[0] */ + indices[0] = lp_build_const_int32(gallivm, 0); + /* context[0].textures */ + indices[1] = lp_build_const_int32(gallivm, LP_JIT_CTX_TEXTURES); + /* context[0].textures[unit] */ + indices[2] = lp_build_const_int32(gallivm, unit); + /* context[0].textures[unit].member */ + indices[3] = lp_build_const_int32(gallivm, member_index); + + ptr = LLVMBuildGEP(builder, state->context_ptr, indices, Elements(indices), ""); + + if (emit_load) + res = LLVMBuildLoad(builder, ptr, ""); + else + res = ptr; + + lp_build_name(res, "context.texture%u.%s", unit, member_name); + + return res; +} + + +/** + * Helper macro to instantiate the functions that generate the code to + * fetch the members of lp_jit_texture to fulfill the sampler code + * generator requests. + * + * This complexity is the price we have to pay to keep the texture + * sampler code generator a reusable module without dependencies to + * llvmpipe internals. + */ +#define LP_LLVM_TEXTURE_MEMBER(_name, _index, _emit_load) \ + static LLVMValueRef \ + lp_llvm_texture_##_name( const struct lp_sampler_dynamic_state *base, \ + struct gallivm_state *gallivm, \ + unsigned unit) \ + { \ + return lp_llvm_texture_member(base, gallivm, unit, _index, #_name, _emit_load ); \ + } + + +LP_LLVM_TEXTURE_MEMBER(width, LP_JIT_TEXTURE_WIDTH, TRUE) +LP_LLVM_TEXTURE_MEMBER(height, LP_JIT_TEXTURE_HEIGHT, TRUE) +LP_LLVM_TEXTURE_MEMBER(depth, LP_JIT_TEXTURE_DEPTH, TRUE) +LP_LLVM_TEXTURE_MEMBER(last_level, LP_JIT_TEXTURE_LAST_LEVEL, TRUE) +LP_LLVM_TEXTURE_MEMBER(row_stride, LP_JIT_TEXTURE_ROW_STRIDE, FALSE) +LP_LLVM_TEXTURE_MEMBER(img_stride, LP_JIT_TEXTURE_IMG_STRIDE, FALSE) +LP_LLVM_TEXTURE_MEMBER(data_ptr, LP_JIT_TEXTURE_DATA, FALSE) +LP_LLVM_TEXTURE_MEMBER(min_lod, LP_JIT_TEXTURE_MIN_LOD, TRUE) +LP_LLVM_TEXTURE_MEMBER(max_lod, LP_JIT_TEXTURE_MAX_LOD, TRUE) +LP_LLVM_TEXTURE_MEMBER(lod_bias, LP_JIT_TEXTURE_LOD_BIAS, TRUE) +LP_LLVM_TEXTURE_MEMBER(border_color, LP_JIT_TEXTURE_BORDER_COLOR, FALSE) + + +static void +lp_llvm_sampler_soa_destroy(struct lp_build_sampler_soa *sampler) +{ + FREE(sampler); +} + + +/** + * Fetch filtered values from texture. + * The 'texel' parameter returns four vectors corresponding to R, G, B, A. + */ +static void +lp_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base, + struct gallivm_state *gallivm, + struct lp_type type, + unsigned unit, + unsigned num_coords, + const LLVMValueRef *coords, + const LLVMValueRef *ddx, + const LLVMValueRef *ddy, + LLVMValueRef lod_bias, /* optional */ + LLVMValueRef explicit_lod, /* optional */ + LLVMValueRef *texel) +{ + struct lp_llvm_sampler_soa *sampler = (struct lp_llvm_sampler_soa *)base; + + assert(unit < PIPE_MAX_SAMPLERS); + + if (LP_PERF & PERF_NO_TEX) { + lp_build_sample_nop(gallivm, type, texel); + return; + } + + lp_build_sample_soa(gallivm, + &sampler->dynamic_state.static_state[unit], + &sampler->dynamic_state.base, + type, + unit, + num_coords, coords, + ddx, ddy, + lod_bias, explicit_lod, + texel); +} + + +struct lp_build_sampler_soa * +lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state, + LLVMValueRef context_ptr) +{ + struct lp_llvm_sampler_soa *sampler; + + sampler = CALLOC_STRUCT(lp_llvm_sampler_soa); + if(!sampler) + return NULL; + + sampler->base.destroy = lp_llvm_sampler_soa_destroy; + sampler->base.emit_fetch_texel = lp_llvm_sampler_soa_emit_fetch_texel; + sampler->dynamic_state.base.width = lp_llvm_texture_width; + sampler->dynamic_state.base.height = lp_llvm_texture_height; + sampler->dynamic_state.base.depth = lp_llvm_texture_depth; + sampler->dynamic_state.base.last_level = lp_llvm_texture_last_level; + sampler->dynamic_state.base.row_stride = lp_llvm_texture_row_stride; + sampler->dynamic_state.base.img_stride = lp_llvm_texture_img_stride; + sampler->dynamic_state.base.data_ptr = lp_llvm_texture_data_ptr; + sampler->dynamic_state.base.min_lod = lp_llvm_texture_min_lod; + sampler->dynamic_state.base.max_lod = lp_llvm_texture_max_lod; + sampler->dynamic_state.base.lod_bias = lp_llvm_texture_lod_bias; + sampler->dynamic_state.base.border_color = lp_llvm_texture_border_color; + + sampler->dynamic_state.static_state = static_state; + sampler->dynamic_state.context_ptr = context_ptr; + + return &sampler->base; +} + diff --git a/src/gallium/drivers/llvmpipe/lp_tex_sample.h b/src/gallium/drivers/llvmpipe/lp_tex_sample.h new file mode 100644 index 0000000..1228a83 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_tex_sample.h @@ -0,0 +1,48 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef LP_TEX_SAMPLE_H +#define LP_TEX_SAMPLE_H + + +#include "gallivm/lp_bld.h" + + +struct lp_sampler_static_state; + + +/** + * Pure-LLVM texture sampling code generator. + * + * @param context_ptr LLVM value with the pointer to the struct lp_jit_context. + */ +struct lp_build_sampler_soa * +lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *key, + LLVMValueRef context_ptr); + + +#endif /* LP_TEX_SAMPLE_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c new file mode 100644 index 0000000..9753da5 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_texture.c @@ -0,0 +1,1411 @@ +/************************************************************************** + * + * Copyright 2006 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. + * + **************************************************************************/ + /* + * Authors: + * Keith Whitwell + * Michel Dänzer + */ + +#include + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" + +#include "util/u_inlines.h" +#include "util/u_cpu_detect.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_simple_list.h" +#include "util/u_transfer.h" + +#include "lp_context.h" +#include "lp_flush.h" +#include "lp_screen.h" +#include "lp_tile_image.h" +#include "lp_texture.h" +#include "lp_setup.h" +#include "lp_state.h" + +#include "state_tracker/sw_winsys.h" + + +#ifdef DEBUG +static struct llvmpipe_resource resource_list; +#endif +static unsigned id_counter = 0; + + +static INLINE boolean +resource_is_texture(const struct pipe_resource *resource) +{ + switch (resource->target) { + case PIPE_BUFFER: + return FALSE; + case PIPE_TEXTURE_1D: + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + case PIPE_TEXTURE_3D: + case PIPE_TEXTURE_CUBE: + return TRUE; + default: + assert(0); + return FALSE; + } +} + + + +/** + * Allocate storage for llvmpipe_texture::layout array. + * The number of elements is width_in_tiles * height_in_tiles. + */ +static enum lp_texture_layout * +alloc_layout_array(unsigned num_slices, unsigned width, unsigned height) +{ + const unsigned tx = align(width, TILE_SIZE) / TILE_SIZE; + const unsigned ty = align(height, TILE_SIZE) / TILE_SIZE; + + assert(num_slices * tx * ty > 0); + assert(LP_TEX_LAYOUT_NONE == 0); /* calloc'ing LP_TEX_LAYOUT_NONE here */ + + return (enum lp_texture_layout *) + CALLOC(num_slices * tx * ty, sizeof(enum lp_texture_layout)); +} + + + +/** + * Conventional allocation path for non-display textures: + * Just compute row strides here. Storage is allocated on demand later. + */ +static boolean +llvmpipe_texture_layout(struct llvmpipe_screen *screen, + struct llvmpipe_resource *lpr) +{ + struct pipe_resource *pt = &lpr->base; + unsigned level; + unsigned width = pt->width0; + unsigned height = pt->height0; + unsigned depth = pt->depth0; + + assert(LP_MAX_TEXTURE_2D_LEVELS <= LP_MAX_TEXTURE_LEVELS); + assert(LP_MAX_TEXTURE_3D_LEVELS <= LP_MAX_TEXTURE_LEVELS); + + for (level = 0; level <= pt->last_level; level++) { + + /* Row stride and image stride (for linear layout) */ + { + unsigned alignment, nblocksx, nblocksy, block_size; + + /* For non-compressed formats we need to align the texture size + * to the tile size to facilitate render-to-texture. + */ + if (util_format_is_compressed(pt->format)) + alignment = 1; + else + alignment = TILE_SIZE; + + nblocksx = util_format_get_nblocksx(pt->format, + align(width, alignment)); + nblocksy = util_format_get_nblocksy(pt->format, + align(height, alignment)); + block_size = util_format_get_blocksize(pt->format); + + lpr->row_stride[level] = align(nblocksx * block_size, 16); + + lpr->img_stride[level] = lpr->row_stride[level] * nblocksy; + } + + /* Size of the image in tiles (for tiled layout) */ + { + const unsigned width_t = align(width, TILE_SIZE) / TILE_SIZE; + const unsigned height_t = align(height, TILE_SIZE) / TILE_SIZE; + lpr->tiles_per_row[level] = width_t; + lpr->tiles_per_image[level] = width_t * height_t; + } + + /* Number of 3D image slices or cube faces */ + { + unsigned num_slices; + + if (lpr->base.target == PIPE_TEXTURE_CUBE) + num_slices = 6; + else if (lpr->base.target == PIPE_TEXTURE_3D) + num_slices = depth; + else + num_slices = 1; + + lpr->num_slices_faces[level] = num_slices; + + lpr->layout[level] = alloc_layout_array(num_slices, width, height); + } + + /* Compute size of next mipmap level */ + width = u_minify(width, 1); + height = u_minify(height, 1); + depth = u_minify(depth, 1); + } + + return TRUE; +} + + + +static boolean +llvmpipe_displaytarget_layout(struct llvmpipe_screen *screen, + struct llvmpipe_resource *lpr) +{ + struct sw_winsys *winsys = screen->winsys; + + /* Round up the surface size to a multiple of the tile size to + * avoid tile clipping. + */ + const unsigned width = align(lpr->base.width0, TILE_SIZE); + const unsigned height = align(lpr->base.height0, TILE_SIZE); + const unsigned width_t = width / TILE_SIZE; + const unsigned height_t = height / TILE_SIZE; + + lpr->tiles_per_row[0] = width_t; + lpr->tiles_per_image[0] = width_t * height_t; + lpr->num_slices_faces[0] = 1; + lpr->img_stride[0] = 0; + + lpr->layout[0] = alloc_layout_array(1, width, height); + //lpr->layout[0][0] = LP_TEX_LAYOUT_LINEAR; + + lpr->dt = winsys->displaytarget_create(winsys, + lpr->base.bind, + lpr->base.format, + width, height, + 16, + &lpr->row_stride[0] ); + + return lpr->dt != NULL; +} + + +static struct pipe_resource * +llvmpipe_resource_create(struct pipe_screen *_screen, + const struct pipe_resource *templat) +{ + struct llvmpipe_screen *screen = llvmpipe_screen(_screen); + struct llvmpipe_resource *lpr = CALLOC_STRUCT(llvmpipe_resource); + if (!lpr) + return NULL; + + lpr->base = *templat; + pipe_reference_init(&lpr->base.reference, 1); + lpr->base.screen = &screen->base; + + /* assert(lpr->base.bind); */ + + if (resource_is_texture(&lpr->base)) { + if (lpr->base.bind & PIPE_BIND_DISPLAY_TARGET) { + /* displayable surface */ + if (!llvmpipe_displaytarget_layout(screen, lpr)) + goto fail; + assert(lpr->layout[0][0] == LP_TEX_LAYOUT_NONE); + } + else { + /* texture map */ + if (!llvmpipe_texture_layout(screen, lpr)) + goto fail; + assert(lpr->layout[0][0] == LP_TEX_LAYOUT_NONE); + } + assert(lpr->layout[0]); + } + else { + /* other data (vertex buffer, const buffer, etc) */ + const enum pipe_format format = templat->format; + const uint w = templat->width0 / util_format_get_blockheight(format); + /* XXX buffers should only have one dimension, those values should be 1 */ + const uint h = templat->height0 / util_format_get_blockwidth(format); + const uint d = templat->depth0; + const uint bpp = util_format_get_blocksize(format); + const uint bytes = w * h * d * bpp; + lpr->data = align_malloc(bytes, 16); + if (!lpr->data) + goto fail; + } + + lpr->id = id_counter++; + +#ifdef DEBUG + insert_at_tail(&resource_list, lpr); +#endif + + return &lpr->base; + + fail: + FREE(lpr); + return NULL; +} + + +static void +llvmpipe_resource_destroy(struct pipe_screen *pscreen, + struct pipe_resource *pt) +{ + struct llvmpipe_screen *screen = llvmpipe_screen(pscreen); + struct llvmpipe_resource *lpr = llvmpipe_resource(pt); + + if (lpr->dt) { + /* display target */ + struct sw_winsys *winsys = screen->winsys; + winsys->displaytarget_destroy(winsys, lpr->dt); + + if (lpr->tiled[0].data) { + align_free(lpr->tiled[0].data); + lpr->tiled[0].data = NULL; + } + + FREE(lpr->layout[0]); + } + else if (resource_is_texture(pt)) { + /* regular texture */ + uint level; + + /* free linear image data */ + for (level = 0; level < Elements(lpr->linear); level++) { + if (lpr->linear[level].data) { + align_free(lpr->linear[level].data); + lpr->linear[level].data = NULL; + } + } + + /* free tiled image data */ + for (level = 0; level < Elements(lpr->tiled); level++) { + if (lpr->tiled[level].data) { + align_free(lpr->tiled[level].data); + lpr->tiled[level].data = NULL; + } + } + + /* free layout flag arrays */ + for (level = 0; level < Elements(lpr->tiled); level++) { + FREE(lpr->layout[level]); + lpr->layout[level] = NULL; + } + } + else if (!lpr->userBuffer) { + assert(lpr->data); + align_free(lpr->data); + } + +#ifdef DEBUG + if (lpr->next) + remove_from_list(lpr); +#endif + + FREE(lpr); +} + + +/** + * Map a resource for read/write. + */ +void * +llvmpipe_resource_map(struct pipe_resource *resource, + unsigned level, + unsigned layer, + enum lp_texture_usage tex_usage, + enum lp_texture_layout layout) +{ + struct llvmpipe_resource *lpr = llvmpipe_resource(resource); + uint8_t *map; + + assert(level < LP_MAX_TEXTURE_LEVELS); + assert(layer < (u_minify(resource->depth0, level) + resource->array_size - 1)); + + assert(tex_usage == LP_TEX_USAGE_READ || + tex_usage == LP_TEX_USAGE_READ_WRITE || + tex_usage == LP_TEX_USAGE_WRITE_ALL); + + assert(layout == LP_TEX_LAYOUT_NONE || + layout == LP_TEX_LAYOUT_TILED || + layout == LP_TEX_LAYOUT_LINEAR); + + if (lpr->dt) { + /* display target */ + struct llvmpipe_screen *screen = llvmpipe_screen(resource->screen); + struct sw_winsys *winsys = screen->winsys; + unsigned dt_usage; + uint8_t *map2; + + if (tex_usage == LP_TEX_USAGE_READ) { + dt_usage = PIPE_TRANSFER_READ; + } + else { + dt_usage = PIPE_TRANSFER_READ_WRITE; + } + + assert(level == 0); + assert(layer == 0); + + /* FIXME: keep map count? */ + map = winsys->displaytarget_map(winsys, lpr->dt, dt_usage); + + /* install this linear image in texture data structure */ + lpr->linear[level].data = map; + + /* make sure tiled data gets converted to linear data */ + map2 = llvmpipe_get_texture_image(lpr, 0, 0, tex_usage, layout); + if (layout == LP_TEX_LAYOUT_LINEAR) + assert(map == map2); + + return map2; + } + else if (resource_is_texture(resource)) { + + map = llvmpipe_get_texture_image(lpr, layer, level, + tex_usage, layout); + return map; + } + else { + return lpr->data; + } +} + + +/** + * Unmap a resource. + */ +void +llvmpipe_resource_unmap(struct pipe_resource *resource, + unsigned level, + unsigned layer) +{ + struct llvmpipe_resource *lpr = llvmpipe_resource(resource); + + if (lpr->dt) { + /* display target */ + struct llvmpipe_screen *lp_screen = llvmpipe_screen(resource->screen); + struct sw_winsys *winsys = lp_screen->winsys; + + assert(level == 0); + assert(layer == 0); + + /* make sure linear image is up to date */ + (void) llvmpipe_get_texture_image(lpr, layer, level, + LP_TEX_USAGE_READ, + LP_TEX_LAYOUT_LINEAR); + + winsys->displaytarget_unmap(winsys, lpr->dt); + } +} + + +void * +llvmpipe_resource_data(struct pipe_resource *resource) +{ + struct llvmpipe_resource *lpr = llvmpipe_resource(resource); + + assert(!resource_is_texture(resource)); + + return lpr->data; +} + + +static struct pipe_resource * +llvmpipe_resource_from_handle(struct pipe_screen *screen, + const struct pipe_resource *template, + struct winsys_handle *whandle) +{ + struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys; + struct llvmpipe_resource *lpr = CALLOC_STRUCT(llvmpipe_resource); + unsigned width, height, width_t, height_t; + + /* XXX Seems like from_handled depth textures doesn't work that well */ + + if (!lpr) + return NULL; + + lpr->base = *template; + pipe_reference_init(&lpr->base.reference, 1); + lpr->base.screen = screen; + + width = align(lpr->base.width0, TILE_SIZE); + height = align(lpr->base.height0, TILE_SIZE); + width_t = width / TILE_SIZE; + height_t = height / TILE_SIZE; + + /* + * Looks like unaligned displaytargets work just fine, + * at least sampler/render ones. + */ +#if 0 + assert(lpr->base.width0 == width); + assert(lpr->base.height0 == height); +#endif + + lpr->tiles_per_row[0] = width_t; + lpr->tiles_per_image[0] = width_t * height_t; + lpr->num_slices_faces[0] = 1; + lpr->img_stride[0] = 0; + + lpr->dt = winsys->displaytarget_from_handle(winsys, + template, + whandle, + &lpr->row_stride[0]); + if (!lpr->dt) + goto fail; + + lpr->layout[0] = alloc_layout_array(1, lpr->base.width0, lpr->base.height0); + + assert(lpr->layout[0]); + assert(lpr->layout[0][0] == LP_TEX_LAYOUT_NONE); + + lpr->id = id_counter++; + +#ifdef DEBUG + insert_at_tail(&resource_list, lpr); +#endif + + return &lpr->base; + + fail: + FREE(lpr); + return NULL; +} + + +static boolean +llvmpipe_resource_get_handle(struct pipe_screen *screen, + struct pipe_resource *pt, + struct winsys_handle *whandle) +{ + struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys; + struct llvmpipe_resource *lpr = llvmpipe_resource(pt); + + assert(lpr->dt); + if (!lpr->dt) + return FALSE; + + return winsys->displaytarget_get_handle(winsys, lpr->dt, whandle); +} + + +static struct pipe_surface * +llvmpipe_create_surface(struct pipe_context *pipe, + struct pipe_resource *pt, + const struct pipe_surface *surf_tmpl) +{ + struct pipe_surface *ps; + + assert(surf_tmpl->u.tex.level <= pt->last_level); + + ps = CALLOC_STRUCT(pipe_surface); + if (ps) { + pipe_reference_init(&ps->reference, 1); + pipe_resource_reference(&ps->texture, pt); + ps->context = pipe; + ps->format = surf_tmpl->format; + ps->width = u_minify(pt->width0, surf_tmpl->u.tex.level); + ps->height = u_minify(pt->height0, surf_tmpl->u.tex.level); + ps->usage = surf_tmpl->usage; + + ps->u.tex.level = surf_tmpl->u.tex.level; + ps->u.tex.first_layer = surf_tmpl->u.tex.first_layer; + ps->u.tex.last_layer = surf_tmpl->u.tex.last_layer; + } + return ps; +} + + +static void +llvmpipe_surface_destroy(struct pipe_context *pipe, + struct pipe_surface *surf) +{ + /* Effectively do the texture_update work here - if texture images + * needed post-processing to put them into hardware layout, this is + * where it would happen. For llvmpipe, nothing to do. + */ + assert(surf->texture); + pipe_resource_reference(&surf->texture, NULL); + FREE(surf); +} + + +static struct pipe_transfer * +llvmpipe_get_transfer(struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); + struct llvmpipe_resource *lprex = llvmpipe_resource(resource); + struct llvmpipe_transfer *lpr; + + assert(resource); + assert(level <= resource->last_level); + + /* + * Transfers, like other pipe operations, must happen in order, so flush the + * context if necessary. + */ + if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) { + boolean read_only = !(usage & PIPE_TRANSFER_WRITE); + boolean do_not_block = !!(usage & PIPE_TRANSFER_DONTBLOCK); + if (!llvmpipe_flush_resource(pipe, resource, + level, + box->depth > 1 ? -1 : box->z, + 0, /* flush_flags */ + read_only, + TRUE, /* cpu_access */ + do_not_block, + __FUNCTION__)) { + /* + * It would have blocked, but state tracker requested no to. + */ + assert(do_not_block); + return NULL; + } + } + + if (resource == llvmpipe->constants[PIPE_SHADER_FRAGMENT][0]) + llvmpipe->dirty |= LP_NEW_CONSTANTS; + + lpr = CALLOC_STRUCT(llvmpipe_transfer); + if (lpr) { + struct pipe_transfer *pt = &lpr->base; + pipe_resource_reference(&pt->resource, resource); + pt->box = *box; + pt->level = level; + pt->stride = lprex->row_stride[level]; + pt->layer_stride = lprex->img_stride[level]; + pt->usage = usage; + + return pt; + } + return NULL; +} + + +static void +llvmpipe_transfer_destroy(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + /* Effectively do the texture_update work here - if texture images + * needed post-processing to put them into hardware layout, this is + * where it would happen. For llvmpipe, nothing to do. + */ + assert (transfer->resource); + pipe_resource_reference(&transfer->resource, NULL); + FREE(transfer); +} + + +static void * +llvmpipe_transfer_map( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen); + ubyte *map; + struct llvmpipe_resource *lpr; + enum pipe_format format; + enum lp_texture_usage tex_usage; + const char *mode; + + assert(transfer->level < LP_MAX_TEXTURE_LEVELS); + + /* + printf("tex_transfer_map(%d, %d %d x %d of %d x %d, usage %d )\n", + transfer->x, transfer->y, transfer->width, transfer->height, + transfer->texture->width0, + transfer->texture->height0, + transfer->usage); + */ + + if (transfer->usage == PIPE_TRANSFER_READ) { + tex_usage = LP_TEX_USAGE_READ; + mode = "read"; + } + else { + tex_usage = LP_TEX_USAGE_READ_WRITE; + mode = "read/write"; + } + + if (0) { + struct llvmpipe_resource *lpr = llvmpipe_resource(transfer->resource); + printf("transfer map tex %u mode %s\n", lpr->id, mode); + } + + + assert(transfer->resource); + lpr = llvmpipe_resource(transfer->resource); + format = lpr->base.format; + + map = llvmpipe_resource_map(transfer->resource, + transfer->level, + transfer->box.z, + tex_usage, LP_TEX_LAYOUT_LINEAR); + + + /* May want to do different things here depending on read/write nature + * of the map: + */ + if (transfer->usage & PIPE_TRANSFER_WRITE) { + /* Do something to notify sharing contexts of a texture change. + */ + screen->timestamp++; + } + + map += + transfer->box.y / util_format_get_blockheight(format) * transfer->stride + + transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); + + return map; +} + + +static void +llvmpipe_transfer_unmap(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + assert(transfer->resource); + + llvmpipe_resource_unmap(transfer->resource, + transfer->level, + transfer->box.z); +} + +static unsigned int +llvmpipe_is_resource_referenced( struct pipe_context *pipe, + struct pipe_resource *presource, + unsigned level, int layer) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe ); + + if (presource->target == PIPE_BUFFER) + return PIPE_UNREFERENCED; + + return lp_setup_is_resource_referenced(llvmpipe->setup, presource); +} + + + +/** + * Create buffer which wraps user-space data. + */ +static struct pipe_resource * +llvmpipe_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned bind_flags) +{ + struct llvmpipe_resource *buffer; + + buffer = CALLOC_STRUCT(llvmpipe_resource); + if(!buffer) + return NULL; + + pipe_reference_init(&buffer->base.reference, 1); + buffer->base.screen = screen; + buffer->base.format = PIPE_FORMAT_R8_UNORM; /* ?? */ + buffer->base.bind = bind_flags; + buffer->base.usage = PIPE_USAGE_IMMUTABLE; + buffer->base.flags = 0; + buffer->base.width0 = bytes; + buffer->base.height0 = 1; + buffer->base.depth0 = 1; + buffer->base.array_size = 1; + buffer->userBuffer = TRUE; + buffer->data = ptr; + + return &buffer->base; +} + + +/** + * Compute size (in bytes) need to store a texture image / mipmap level, + * for just one cube face or one 3D texture slice + */ +static unsigned +tex_image_face_size(const struct llvmpipe_resource *lpr, unsigned level, + enum lp_texture_layout layout) +{ + const unsigned width = u_minify(lpr->base.width0, level); + const unsigned height = u_minify(lpr->base.height0, level); + + assert(layout == LP_TEX_LAYOUT_TILED || + layout == LP_TEX_LAYOUT_LINEAR); + + if (layout == LP_TEX_LAYOUT_TILED) { + /* for tiled layout, force a 32bpp format */ + const enum pipe_format format = PIPE_FORMAT_B8G8R8A8_UNORM; + const unsigned block_size = util_format_get_blocksize(format); + const unsigned nblocksy = + util_format_get_nblocksy(format, align(height, TILE_SIZE)); + const unsigned nblocksx = + util_format_get_nblocksx(format, align(width, TILE_SIZE)); + const unsigned buffer_size = block_size * nblocksy * nblocksx; + return buffer_size; + } + else { + /* we already computed this */ + return lpr->img_stride[level]; + } +} + + +/** + * Compute size (in bytes) need to store a texture image / mipmap level, + * including all cube faces or 3D image slices + */ +static unsigned +tex_image_size(const struct llvmpipe_resource *lpr, unsigned level, + enum lp_texture_layout layout) +{ + const unsigned buf_size = tex_image_face_size(lpr, level, layout); + return buf_size * lpr->num_slices_faces[level]; +} + + +/** + * This function encapsulates some complicated logic for determining + * how to convert a tile of image data from linear layout to tiled + * layout, or vice versa. + * \param cur_layout the current tile layout + * \param target_layout the desired tile layout + * \param usage how the tile will be accessed (R/W vs. read-only, etc) + * \param new_layout_return returns the new layout mode + * \param convert_return returns TRUE if image conversion is needed + */ +static void +layout_logic(enum lp_texture_layout cur_layout, + enum lp_texture_layout target_layout, + enum lp_texture_usage usage, + enum lp_texture_layout *new_layout_return, + boolean *convert) +{ + enum lp_texture_layout other_layout, new_layout; + + *convert = FALSE; + + new_layout = 99; /* debug check */ + + if (target_layout == LP_TEX_LAYOUT_LINEAR) { + other_layout = LP_TEX_LAYOUT_TILED; + } + else { + assert(target_layout == LP_TEX_LAYOUT_TILED); + other_layout = LP_TEX_LAYOUT_LINEAR; + } + + new_layout = target_layout; /* may get changed below */ + + if (cur_layout == LP_TEX_LAYOUT_BOTH) { + if (usage == LP_TEX_USAGE_READ) { + new_layout = LP_TEX_LAYOUT_BOTH; + } + } + else if (cur_layout == other_layout) { + if (usage != LP_TEX_USAGE_WRITE_ALL) { + /* need to convert tiled data to linear or vice versa */ + *convert = TRUE; + + if (usage == LP_TEX_USAGE_READ) + new_layout = LP_TEX_LAYOUT_BOTH; + } + } + else { + assert(cur_layout == LP_TEX_LAYOUT_NONE || + cur_layout == target_layout); + } + + assert(new_layout == LP_TEX_LAYOUT_BOTH || + new_layout == target_layout); + + *new_layout_return = new_layout; +} + + +/** + * Return pointer to a 2D texture image/face/slice. + * No tiled/linear conversion is done. + */ +ubyte * +llvmpipe_get_texture_image_address(struct llvmpipe_resource *lpr, + unsigned face_slice, unsigned level, + enum lp_texture_layout layout) +{ + struct llvmpipe_texture_image *img; + unsigned offset; + + if (layout == LP_TEX_LAYOUT_LINEAR) { + img = &lpr->linear[level]; + } + else { + assert (layout == LP_TEX_LAYOUT_TILED); + img = &lpr->tiled[level]; + } + + if (face_slice > 0) + offset = face_slice * tex_image_face_size(lpr, level, layout); + else + offset = 0; + + return (ubyte *) img->data + offset; +} + + +static INLINE enum lp_texture_layout +llvmpipe_get_texture_tile_layout(const struct llvmpipe_resource *lpr, + unsigned face_slice, unsigned level, + unsigned x, unsigned y) +{ + uint i; + assert(resource_is_texture(&lpr->base)); + assert(x < lpr->tiles_per_row[level]); + i = face_slice * lpr->tiles_per_image[level] + + y * lpr->tiles_per_row[level] + x; + return lpr->layout[level][i]; +} + + +static INLINE void +llvmpipe_set_texture_tile_layout(struct llvmpipe_resource *lpr, + unsigned face_slice, unsigned level, + unsigned x, unsigned y, + enum lp_texture_layout layout) +{ + uint i; + assert(resource_is_texture(&lpr->base)); + assert(x < lpr->tiles_per_row[level]); + i = face_slice * lpr->tiles_per_image[level] + + y * lpr->tiles_per_row[level] + x; + lpr->layout[level][i] = layout; +} + + +/** + * Set the layout mode for all tiles in a particular image. + */ +static INLINE void +llvmpipe_set_texture_image_layout(struct llvmpipe_resource *lpr, + unsigned face_slice, unsigned level, + unsigned width_t, unsigned height_t, + enum lp_texture_layout layout) +{ + const unsigned start = face_slice * lpr->tiles_per_image[level]; + unsigned i; + + for (i = 0; i < width_t * height_t; i++) { + lpr->layout[level][start + i] = layout; + } +} + + +/** + * Allocate storage for a linear or tile texture image (all cube + * faces and all 3D slices. + */ +static void +alloc_image_data(struct llvmpipe_resource *lpr, unsigned level, + enum lp_texture_layout layout) +{ + uint alignment = MAX2(16, util_cpu_caps.cacheline); + + if (lpr->dt) + assert(level == 0); + + if (layout == LP_TEX_LAYOUT_TILED) { + /* tiled data is stored in regular memory */ + uint buffer_size = tex_image_size(lpr, level, layout); + lpr->tiled[level].data = align_malloc(buffer_size, alignment); + } + else { + assert(layout == LP_TEX_LAYOUT_LINEAR); + if (lpr->dt) { + /* we get the linear memory from the winsys */ + struct llvmpipe_screen *screen = llvmpipe_screen(lpr->base.screen); + struct sw_winsys *winsys = screen->winsys; + + lpr->linear[0].data = + winsys->displaytarget_map(winsys, lpr->dt, + PIPE_TRANSFER_READ_WRITE); + } + else { + /* not a display target - allocate regular memory */ + uint buffer_size = tex_image_size(lpr, level, LP_TEX_LAYOUT_LINEAR); + lpr->linear[level].data = align_malloc(buffer_size, alignment); + } + } +} + + + +/** + * Return pointer to texture image data (either linear or tiled layout) + * for a particular cube face or 3D texture slice. + * + * \param face_slice the cube face or 3D slice of interest + * \param usage one of LP_TEX_USAGE_READ/WRITE_ALL/READ_WRITE + * \param layout either LP_TEX_LAYOUT_LINEAR or _TILED or _NONE + */ +void * +llvmpipe_get_texture_image(struct llvmpipe_resource *lpr, + unsigned face_slice, unsigned level, + enum lp_texture_usage usage, + enum lp_texture_layout layout) +{ + /* + * 'target' refers to the image which we're retrieving (either in + * tiled or linear layout). + * 'other' refers to the same image but in the other layout. (it may + * or may not exist. + */ + struct llvmpipe_texture_image *target_img; + struct llvmpipe_texture_image *other_img; + void *target_data; + void *other_data; + const unsigned width = u_minify(lpr->base.width0, level); + const unsigned height = u_minify(lpr->base.height0, level); + const unsigned width_t = align(width, TILE_SIZE) / TILE_SIZE; + const unsigned height_t = align(height, TILE_SIZE) / TILE_SIZE; + enum lp_texture_layout other_layout; + boolean only_allocate; + + assert(layout == LP_TEX_LAYOUT_NONE || + layout == LP_TEX_LAYOUT_TILED || + layout == LP_TEX_LAYOUT_LINEAR); + + assert(usage == LP_TEX_USAGE_READ || + usage == LP_TEX_USAGE_READ_WRITE || + usage == LP_TEX_USAGE_WRITE_ALL); + + /* check for the special case of layout == LP_TEX_LAYOUT_NONE */ + if (layout == LP_TEX_LAYOUT_NONE) { + only_allocate = TRUE; + layout = LP_TEX_LAYOUT_TILED; + } + else { + only_allocate = FALSE; + } + + if (lpr->dt) { + assert(lpr->linear[level].data); + } + + /* which is target? which is other? */ + if (layout == LP_TEX_LAYOUT_LINEAR) { + target_img = &lpr->linear[level]; + other_img = &lpr->tiled[level]; + other_layout = LP_TEX_LAYOUT_TILED; + } + else { + target_img = &lpr->tiled[level]; + other_img = &lpr->linear[level]; + other_layout = LP_TEX_LAYOUT_LINEAR; + } + + target_data = target_img->data; + other_data = other_img->data; + + if (!target_data) { + /* allocate memory for the target image now */ + alloc_image_data(lpr, level, layout); + target_data = target_img->data; + } + + if (face_slice > 0) { + unsigned target_offset, other_offset; + + target_offset = face_slice * tex_image_face_size(lpr, level, layout); + other_offset = face_slice * tex_image_face_size(lpr, level, other_layout); + if (target_data) { + target_data = (uint8_t *) target_data + target_offset; + } + if (other_data) { + other_data = (uint8_t *) other_data + other_offset; + } + } + + if (only_allocate) { + /* Just allocating tiled memory. Don't initialize it from the + * linear data if it exists. + */ + return target_data; + } + + if (other_data) { + /* may need to convert other data to the requested layout */ + enum lp_texture_layout new_layout; + unsigned x, y; + + /* loop over all image tiles, doing layout conversion where needed */ + for (y = 0; y < height_t; y++) { + for (x = 0; x < width_t; x++) { + enum lp_texture_layout cur_layout = + llvmpipe_get_texture_tile_layout(lpr, face_slice, level, x, y); + boolean convert; + + layout_logic(cur_layout, layout, usage, &new_layout, &convert); + + if (convert && other_data && target_data) { + if (layout == LP_TEX_LAYOUT_TILED) { + lp_linear_to_tiled(other_data, target_data, + x * TILE_SIZE, y * TILE_SIZE, + TILE_SIZE, TILE_SIZE, + lpr->base.format, + lpr->row_stride[level], + lpr->tiles_per_row[level]); + } + else { + assert(layout == LP_TEX_LAYOUT_LINEAR); + lp_tiled_to_linear(other_data, target_data, + x * TILE_SIZE, y * TILE_SIZE, + TILE_SIZE, TILE_SIZE, + lpr->base.format, + lpr->row_stride[level], + lpr->tiles_per_row[level]); + } + } + + if (new_layout != cur_layout) + llvmpipe_set_texture_tile_layout(lpr, face_slice, level, x, y, + new_layout); + } + } + } + else { + /* no other data */ + llvmpipe_set_texture_image_layout(lpr, face_slice, level, + width_t, height_t, layout); + } + + return target_data; +} + + +/** + * Return pointer to start of a texture image (1D, 2D, 3D, CUBE). + * All cube faces and 3D slices will be converted to the requested + * layout if needed. + * This is typically used when we're about to sample from a texture. + */ +void * +llvmpipe_get_texture_image_all(struct llvmpipe_resource *lpr, + unsigned level, + enum lp_texture_usage usage, + enum lp_texture_layout layout) +{ + const int slices = lpr->num_slices_faces[level]; + int slice; + void *map = NULL; + + assert(slices > 0); + + for (slice = slices - 1; slice >= 0; slice--) { + map = llvmpipe_get_texture_image(lpr, slice, level, usage, layout); + } + + return map; +} + + +/** + * Get pointer to a linear image (not the tile!) where the tile at (x,y) + * is known to be in linear layout. + * Conversion from tiled to linear will be done if necessary. + * \return pointer to start of image/face (not the tile) + */ +ubyte * +llvmpipe_get_texture_tile_linear(struct llvmpipe_resource *lpr, + unsigned face_slice, unsigned level, + enum lp_texture_usage usage, + unsigned x, unsigned y) +{ + struct llvmpipe_texture_image *linear_img = &lpr->linear[level]; + enum lp_texture_layout cur_layout, new_layout; + const unsigned tx = x / TILE_SIZE, ty = y / TILE_SIZE; + boolean convert; + uint8_t *tiled_image, *linear_image; + + assert(resource_is_texture(&lpr->base)); + assert(x % TILE_SIZE == 0); + assert(y % TILE_SIZE == 0); + + if (!linear_img->data) { + /* allocate memory for the linear image now */ + alloc_image_data(lpr, level, LP_TEX_LAYOUT_LINEAR); + } + + /* compute address of the slice/face of the image that contains the tile */ + tiled_image = llvmpipe_get_texture_image_address(lpr, face_slice, level, + LP_TEX_LAYOUT_TILED); + linear_image = llvmpipe_get_texture_image_address(lpr, face_slice, level, + LP_TEX_LAYOUT_LINEAR); + + /* get current tile layout and determine if data conversion is needed */ + cur_layout = llvmpipe_get_texture_tile_layout(lpr, face_slice, level, tx, ty); + + layout_logic(cur_layout, LP_TEX_LAYOUT_LINEAR, usage, + &new_layout, &convert); + + if (convert && tiled_image && linear_image) { + lp_tiled_to_linear(tiled_image, linear_image, + x, y, TILE_SIZE, TILE_SIZE, lpr->base.format, + lpr->row_stride[level], + lpr->tiles_per_row[level]); + } + + if (new_layout != cur_layout) + llvmpipe_set_texture_tile_layout(lpr, face_slice, level, tx, ty, new_layout); + + return linear_image; +} + + +/** + * Get pointer to tiled data for rendering. + * \return pointer to the tiled data at the given tile position + */ +ubyte * +llvmpipe_get_texture_tile(struct llvmpipe_resource *lpr, + unsigned face_slice, unsigned level, + enum lp_texture_usage usage, + unsigned x, unsigned y) +{ + struct llvmpipe_texture_image *tiled_img = &lpr->tiled[level]; + enum lp_texture_layout cur_layout, new_layout; + const unsigned tx = x / TILE_SIZE, ty = y / TILE_SIZE; + boolean convert; + uint8_t *tiled_image, *linear_image; + unsigned tile_offset; + + assert(x % TILE_SIZE == 0); + assert(y % TILE_SIZE == 0); + + if (!tiled_img->data) { + /* allocate memory for the tiled image now */ + alloc_image_data(lpr, level, LP_TEX_LAYOUT_TILED); + } + + /* compute address of the slice/face of the image that contains the tile */ + tiled_image = llvmpipe_get_texture_image_address(lpr, face_slice, level, + LP_TEX_LAYOUT_TILED); + linear_image = llvmpipe_get_texture_image_address(lpr, face_slice, level, + LP_TEX_LAYOUT_LINEAR); + + /* get current tile layout and see if we need to convert the data */ + cur_layout = llvmpipe_get_texture_tile_layout(lpr, face_slice, level, tx, ty); + + layout_logic(cur_layout, LP_TEX_LAYOUT_TILED, usage, &new_layout, &convert); + if (convert && linear_image && tiled_image) { + lp_linear_to_tiled(linear_image, tiled_image, + x, y, TILE_SIZE, TILE_SIZE, lpr->base.format, + lpr->row_stride[level], + lpr->tiles_per_row[level]); + } + + if (!tiled_image) + return NULL; + + if (new_layout != cur_layout) + llvmpipe_set_texture_tile_layout(lpr, face_slice, level, tx, ty, new_layout); + + /* compute, return address of the 64x64 tile */ + tile_offset = (ty * lpr->tiles_per_row[level] + tx) + * TILE_SIZE * TILE_SIZE * 4; + + return (ubyte *) tiled_image + tile_offset; +} + + +/** + * Get pointer to tiled data for rendering. + * \return pointer to the tiled data at the given tile position + */ +void +llvmpipe_unswizzle_cbuf_tile(struct llvmpipe_resource *lpr, + unsigned face_slice, unsigned level, + unsigned x, unsigned y, + uint8_t *tile) +{ + struct llvmpipe_texture_image *linear_img = &lpr->linear[level]; + const unsigned tx = x / TILE_SIZE, ty = y / TILE_SIZE; + uint8_t *linear_image; + + assert(x % TILE_SIZE == 0); + assert(y % TILE_SIZE == 0); + + if (!linear_img->data) { + /* allocate memory for the linear image now */ + alloc_image_data(lpr, level, LP_TEX_LAYOUT_LINEAR); + } + + /* compute address of the slice/face of the image that contains the tile */ + linear_image = llvmpipe_get_texture_image_address(lpr, face_slice, level, + LP_TEX_LAYOUT_LINEAR); + + { + uint ii = x, jj = y; + uint tile_offset = jj / TILE_SIZE + ii / TILE_SIZE; + uint byte_offset = tile_offset * TILE_SIZE * TILE_SIZE * 4; + + /* Note that lp_tiled_to_linear expects the tile parameter to + * point at the first tile in a whole-image sized array. In + * this code, we have only a single tile and have to do some + * pointer arithmetic to figure out where the "image" would have + * started. + */ + lp_tiled_to_linear(tile - byte_offset, linear_image, + x, y, TILE_SIZE, TILE_SIZE, + lpr->base.format, + lpr->row_stride[level], + 1); /* tiles per row */ + } + + llvmpipe_set_texture_tile_layout(lpr, face_slice, level, tx, ty, + LP_TEX_LAYOUT_LINEAR); +} + + +/** + * Get pointer to tiled data for rendering. + * \return pointer to the tiled data at the given tile position + */ +void +llvmpipe_swizzle_cbuf_tile(struct llvmpipe_resource *lpr, + unsigned face_slice, unsigned level, + unsigned x, unsigned y, + uint8_t *tile) +{ + uint8_t *linear_image; + + assert(x % TILE_SIZE == 0); + assert(y % TILE_SIZE == 0); + + /* compute address of the slice/face of the image that contains the tile */ + linear_image = llvmpipe_get_texture_image_address(lpr, face_slice, level, + LP_TEX_LAYOUT_LINEAR); + + if (linear_image) { + uint ii = x, jj = y; + uint tile_offset = jj / TILE_SIZE + ii / TILE_SIZE; + uint byte_offset = tile_offset * TILE_SIZE * TILE_SIZE * 4; + + /* Note that lp_linear_to_tiled expects the tile parameter to + * point at the first tile in a whole-image sized array. In + * this code, we have only a single tile and have to do some + * pointer arithmetic to figure out where the "image" would have + * started. + */ + lp_linear_to_tiled(linear_image, tile - byte_offset, + x, y, TILE_SIZE, TILE_SIZE, + lpr->base.format, + lpr->row_stride[level], + 1); /* tiles per row */ + } +} + + +/** + * Return size of resource in bytes + */ +unsigned +llvmpipe_resource_size(const struct pipe_resource *resource) +{ + const struct llvmpipe_resource *lpr = llvmpipe_resource_const(resource); + unsigned lvl, size = 0; + + for (lvl = 0; lvl <= lpr->base.last_level; lvl++) { + if (lpr->linear[lvl].data) + size += tex_image_size(lpr, lvl, LP_TEX_LAYOUT_LINEAR); + + if (lpr->tiled[lvl].data) + size += tex_image_size(lpr, lvl, LP_TEX_LAYOUT_TILED); + } + + return size; +} + + +#ifdef DEBUG +void +llvmpipe_print_resources(void) +{ + struct llvmpipe_resource *lpr; + unsigned n = 0, total = 0; + + debug_printf("LLVMPIPE: current resources:\n"); + foreach(lpr, &resource_list) { + unsigned size = llvmpipe_resource_size(&lpr->base); + debug_printf("resource %u at %p, size %ux%ux%u: %u bytes, refcount %u\n", + lpr->id, (void *) lpr, + lpr->base.width0, lpr->base.height0, lpr->base.depth0, + size, lpr->base.reference.count); + total += size; + n++; + } + debug_printf("LLVMPIPE: total size of %u resources: %u\n", n, total); +} +#endif + + +void +llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen) +{ +#ifdef DEBUG + /* init linked list for tracking resources */ + { + static boolean first_call = TRUE; + if (first_call) { + memset(&resource_list, 0, sizeof(resource_list)); + make_empty_list(&resource_list); + first_call = FALSE; + } + } +#endif + + screen->resource_create = llvmpipe_resource_create; + screen->resource_destroy = llvmpipe_resource_destroy; + screen->resource_from_handle = llvmpipe_resource_from_handle; + screen->resource_get_handle = llvmpipe_resource_get_handle; + screen->user_buffer_create = llvmpipe_user_buffer_create; + +} + + +void +llvmpipe_init_context_resource_funcs(struct pipe_context *pipe) +{ + pipe->get_transfer = llvmpipe_get_transfer; + pipe->transfer_destroy = llvmpipe_transfer_destroy; + pipe->transfer_map = llvmpipe_transfer_map; + pipe->transfer_unmap = llvmpipe_transfer_unmap; + pipe->is_resource_referenced = llvmpipe_is_resource_referenced; + + pipe->transfer_flush_region = u_default_transfer_flush_region; + pipe->transfer_inline_write = u_default_transfer_inline_write; + + pipe->create_surface = llvmpipe_create_surface; + pipe->surface_destroy = llvmpipe_surface_destroy; +} diff --git a/src/gallium/drivers/llvmpipe/lp_texture.h b/src/gallium/drivers/llvmpipe/lp_texture.h new file mode 100644 index 0000000..b789c0f --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_texture.h @@ -0,0 +1,246 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef LP_TEXTURE_H +#define LP_TEXTURE_H + + +#include "pipe/p_state.h" +#include "util/u_debug.h" +#include "lp_limits.h" + + +enum lp_texture_usage +{ + LP_TEX_USAGE_READ = 100, + LP_TEX_USAGE_READ_WRITE, + LP_TEX_USAGE_WRITE_ALL +}; + + +/** Per-tile layout mode */ +enum lp_texture_layout +{ + LP_TEX_LAYOUT_NONE = 0, /**< no layout for the tile data yet */ + LP_TEX_LAYOUT_TILED, /**< the tile data is in tiled layout */ + LP_TEX_LAYOUT_LINEAR, /**< the tile data is in linear layout */ + LP_TEX_LAYOUT_BOTH /**< the tile data is in both modes */ +}; + + +struct pipe_context; +struct pipe_screen; +struct llvmpipe_context; + +struct sw_displaytarget; + + +/** + * We keep one or two copies of the texture image data: one in a simple + * linear layout (for texture sampling) and another in a tiled layout (for + * render targets). We keep track of whether each image tile is linear + * or tiled on a per-tile basis. + */ + + +/** A 1D/2D/3D image, one mipmap level */ +struct llvmpipe_texture_image +{ + void *data; +}; + + +/** + * llvmpipe subclass of pipe_resource. A texture, drawing surface, + * vertex buffer, const buffer, etc. + * Textures are stored differently than othere types of objects such as + * vertex buffers and const buffers. + * The former are tiled and have per-tile layout flags. + * The later are simple malloc'd blocks of memory. + */ +struct llvmpipe_resource +{ + struct pipe_resource base; + + /** Row stride in bytes */ + unsigned row_stride[LP_MAX_TEXTURE_LEVELS]; + /** Image stride (for cube maps or 3D textures) in bytes */ + unsigned img_stride[LP_MAX_TEXTURE_LEVELS]; + unsigned tiles_per_row[LP_MAX_TEXTURE_LEVELS]; + unsigned tiles_per_image[LP_MAX_TEXTURE_LEVELS]; + /** Number of 3D slices or cube faces per level */ + unsigned num_slices_faces[LP_MAX_TEXTURE_LEVELS]; + + /** + * Display target, for textures with the PIPE_BIND_DISPLAY_TARGET + * usage. + */ + struct sw_displaytarget *dt; + + /** + * Malloc'ed data for regular textures, or a mapping to dt above. + */ + struct llvmpipe_texture_image tiled[LP_MAX_TEXTURE_LEVELS]; + struct llvmpipe_texture_image linear[LP_MAX_TEXTURE_LEVELS]; + + /** + * Data for non-texture resources. + */ + void *data; + + /** array [level][face or slice][tile_y][tile_x] of layout values) */ + enum lp_texture_layout *layout[LP_MAX_TEXTURE_LEVELS]; + + boolean userBuffer; /** Is this a user-space buffer? */ + unsigned timestamp; + + unsigned id; /**< temporary, for debugging */ + +#ifdef DEBUG + /** for linked list */ + struct llvmpipe_resource *prev, *next; +#endif +}; + + +struct llvmpipe_transfer +{ + struct pipe_transfer base; + + unsigned long offset; +}; + + +/** cast wrappers */ +static INLINE struct llvmpipe_resource * +llvmpipe_resource(struct pipe_resource *pt) +{ + return (struct llvmpipe_resource *) pt; +} + + +static INLINE const struct llvmpipe_resource * +llvmpipe_resource_const(const struct pipe_resource *pt) +{ + return (const struct llvmpipe_resource *) pt; +} + + +static INLINE struct llvmpipe_transfer * +llvmpipe_transfer(struct pipe_transfer *pt) +{ + return (struct llvmpipe_transfer *) pt; +} + + +void llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen); +void llvmpipe_init_context_resource_funcs(struct pipe_context *pipe); + +static INLINE unsigned +llvmpipe_resource_stride(struct pipe_resource *resource, + unsigned level) +{ + struct llvmpipe_resource *lpr = llvmpipe_resource(resource); + assert(level < LP_MAX_TEXTURE_2D_LEVELS); + return lpr->row_stride[level]; +} + + +void * +llvmpipe_resource_map(struct pipe_resource *resource, + unsigned level, + unsigned layer, + enum lp_texture_usage tex_usage, + enum lp_texture_layout layout); + +void +llvmpipe_resource_unmap(struct pipe_resource *resource, + unsigned level, + unsigned layer); + + +void * +llvmpipe_resource_data(struct pipe_resource *resource); + + +unsigned +llvmpipe_resource_size(const struct pipe_resource *resource); + + +ubyte * +llvmpipe_get_texture_image_address(struct llvmpipe_resource *lpr, + unsigned face_slice, unsigned level, + enum lp_texture_layout layout); + +void * +llvmpipe_get_texture_image(struct llvmpipe_resource *resource, + unsigned face_slice, unsigned level, + enum lp_texture_usage usage, + enum lp_texture_layout layout); + +void * +llvmpipe_get_texture_image_all(struct llvmpipe_resource *lpr, + unsigned level, + enum lp_texture_usage usage, + enum lp_texture_layout layout); + +ubyte * +llvmpipe_get_texture_tile_linear(struct llvmpipe_resource *lpr, + unsigned face_slice, unsigned level, + enum lp_texture_usage usage, + unsigned x, unsigned y); + +ubyte * +llvmpipe_get_texture_tile(struct llvmpipe_resource *lpr, + unsigned face_slice, unsigned level, + enum lp_texture_usage usage, + unsigned x, unsigned y); + + +void +llvmpipe_unswizzle_cbuf_tile(struct llvmpipe_resource *lpr, + unsigned face_slice, unsigned level, + unsigned x, unsigned y, + uint8_t *tile); + +void +llvmpipe_swizzle_cbuf_tile(struct llvmpipe_resource *lpr, + unsigned face_slice, unsigned level, + unsigned x, unsigned y, + uint8_t *tile); + +extern void +llvmpipe_print_resources(void); + + +extern void +llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen); + +extern void +llvmpipe_init_context_texture_funcs(struct pipe_context *pipe); + +#endif /* LP_TEXTURE_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_tile_image.c b/src/gallium/drivers/llvmpipe/lp_tile_image.c new file mode 100644 index 0000000..0938f7a --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_tile_image.c @@ -0,0 +1,328 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL THE 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. + * + **************************************************************************/ + + +/** + * Code to convert images from tiled to linear and back. + * XXX there are quite a few assumptions about color and z/stencil being + * 32bpp. + */ + + +#include "util/u_format.h" +#include "lp_tile_soa.h" +#include "lp_tile_image.h" + + +#define BYTES_PER_TILE (TILE_SIZE * TILE_SIZE * 4) + + +/** + * Untile a 4x4 block of 32-bit words (all contiguous) to linear layout + * at dst, with dst_stride words between rows. + */ +static void +untile_4_4_uint32(const uint32_t *src, uint32_t *dst, unsigned dst_stride) +{ + uint32_t *d0 = dst; + uint32_t *d1 = d0 + dst_stride; + uint32_t *d2 = d1 + dst_stride; + uint32_t *d3 = d2 + dst_stride; + + d0[0] = src[0]; d0[1] = src[1]; d0[2] = src[4]; d0[3] = src[5]; + d1[0] = src[2]; d1[1] = src[3]; d1[2] = src[6]; d1[3] = src[7]; + d2[0] = src[8]; d2[1] = src[9]; d2[2] = src[12]; d2[3] = src[13]; + d3[0] = src[10]; d3[1] = src[11]; d3[2] = src[14]; d3[3] = src[15]; +} + + + +/** + * Untile a 4x4 block of 16-bit words (all contiguous) to linear layout + * at dst, with dst_stride words between rows. + */ +static void +untile_4_4_uint16(const uint16_t *src, uint16_t *dst, unsigned dst_stride) +{ + uint16_t *d0 = dst; + uint16_t *d1 = d0 + dst_stride; + uint16_t *d2 = d1 + dst_stride; + uint16_t *d3 = d2 + dst_stride; + + d0[0] = src[0]; d0[1] = src[1]; d0[2] = src[4]; d0[3] = src[5]; + d1[0] = src[2]; d1[1] = src[3]; d1[2] = src[6]; d1[3] = src[7]; + d2[0] = src[8]; d2[1] = src[9]; d2[2] = src[12]; d2[3] = src[13]; + d3[0] = src[10]; d3[1] = src[11]; d3[2] = src[14]; d3[3] = src[15]; +} + + + +/** + * Convert a 4x4 rect of 32-bit words from a linear layout into tiled + * layout (in which all 16 words are contiguous). + */ +static void +tile_4_4_uint32(const uint32_t *src, uint32_t *dst, unsigned src_stride) +{ + const uint32_t *s0 = src; + const uint32_t *s1 = s0 + src_stride; + const uint32_t *s2 = s1 + src_stride; + const uint32_t *s3 = s2 + src_stride; + + dst[0] = s0[0]; dst[1] = s0[1]; dst[4] = s0[2]; dst[5] = s0[3]; + dst[2] = s1[0]; dst[3] = s1[1]; dst[6] = s1[2]; dst[7] = s1[3]; + dst[8] = s2[0]; dst[9] = s2[1]; dst[12] = s2[2]; dst[13] = s2[3]; + dst[10] = s3[0]; dst[11] = s3[1]; dst[14] = s3[2]; dst[15] = s3[3]; +} + + + +/** + * Convert a 4x4 rect of 16-bit words from a linear layout into tiled + * layout (in which all 16 words are contiguous). + */ +static void +tile_4_4_uint16(const uint16_t *src, uint16_t *dst, unsigned src_stride) +{ + const uint16_t *s0 = src; + const uint16_t *s1 = s0 + src_stride; + const uint16_t *s2 = s1 + src_stride; + const uint16_t *s3 = s2 + src_stride; + + dst[0] = s0[0]; dst[1] = s0[1]; dst[4] = s0[2]; dst[5] = s0[3]; + dst[2] = s1[0]; dst[3] = s1[1]; dst[6] = s1[2]; dst[7] = s1[3]; + dst[8] = s2[0]; dst[9] = s2[1]; dst[12] = s2[2]; dst[13] = s2[3]; + dst[10] = s3[0]; dst[11] = s3[1]; dst[14] = s3[2]; dst[15] = s3[3]; +} + + + +/** + * Convert a tiled image into a linear image. + * \param dst_stride dest row stride in bytes + */ +void +lp_tiled_to_linear(const void *src, void *dst, + unsigned x, unsigned y, + unsigned width, unsigned height, + enum pipe_format format, + unsigned dst_stride, + unsigned tiles_per_row) +{ + assert(x % TILE_SIZE == 0); + assert(y % TILE_SIZE == 0); + /*assert(width % TILE_SIZE == 0); + assert(height % TILE_SIZE == 0);*/ + + /* Note that Z/stencil surfaces use a different tiling size than + * color surfaces. + */ + if (util_format_is_depth_or_stencil(format)) { + const uint bpp = util_format_get_blocksize(format); + const uint src_stride = dst_stride * TILE_VECTOR_WIDTH; + const uint tile_w = TILE_VECTOR_WIDTH, tile_h = TILE_VECTOR_HEIGHT; + const uint tiles_per_row = src_stride / (tile_w * tile_h * bpp); + + dst_stride /= bpp; /* convert from bytes to words */ + + if (bpp == 4) { + const uint32_t *src32 = (const uint32_t *) src; + uint32_t *dst32 = (uint32_t *) dst; + uint i, j; + + for (j = 0; j < height; j += tile_h) { + for (i = 0; i < width; i += tile_w) { + /* compute offsets in 32-bit words */ + uint ii = i + x, jj = j + y; + uint src_offset = (jj / tile_h * tiles_per_row + ii / tile_w) + * (tile_w * tile_h); + uint dst_offset = jj * dst_stride + ii; + untile_4_4_uint32(src32 + src_offset, + dst32 + dst_offset, + dst_stride); + } + } + } + else { + const uint16_t *src16 = (const uint16_t *) src; + uint16_t *dst16 = (uint16_t *) dst; + uint i, j; + + assert(bpp == 2); + + for (j = 0; j < height; j += tile_h) { + for (i = 0; i < width; i += tile_w) { + /* compute offsets in 16-bit words */ + uint ii = i + x, jj = j + y; + uint src_offset = (jj / tile_h * tiles_per_row + ii / tile_w) + * (tile_w * tile_h); + uint dst_offset = jj * dst_stride + ii; + untile_4_4_uint16(src16 + src_offset, + dst16 + dst_offset, + dst_stride); + } + } + } + } + else { + /* color image */ + const uint bpp = 4; + const uint tile_w = TILE_SIZE, tile_h = TILE_SIZE; + const uint bytes_per_tile = tile_w * tile_h * bpp; + uint i, j; + + for (j = 0; j < height; j += tile_h) { + for (i = 0; i < width; i += tile_w) { + uint ii = i + x, jj = j + y; + uint tile_offset = ((jj / tile_h) * tiles_per_row + ii / tile_w); + uint byte_offset = tile_offset * bytes_per_tile; + const uint8_t *src_tile = (uint8_t *) src + byte_offset; + + lp_tile_unswizzle_4ub(format, + src_tile, + dst, dst_stride, + ii, jj); + } + } + } +} + + +/** + * Convert a linear image into a tiled image. + * \param src_stride source row stride in bytes + */ +void +lp_linear_to_tiled(const void *src, void *dst, + unsigned x, unsigned y, + unsigned width, unsigned height, + enum pipe_format format, + unsigned src_stride, + unsigned tiles_per_row) +{ + assert(x % TILE_SIZE == 0); + assert(y % TILE_SIZE == 0); + /* + assert(width % TILE_SIZE == 0); + assert(height % TILE_SIZE == 0); + */ + + if (util_format_is_depth_or_stencil(format)) { + const uint bpp = util_format_get_blocksize(format); + const uint dst_stride = src_stride * TILE_VECTOR_WIDTH; + const uint tile_w = TILE_VECTOR_WIDTH, tile_h = TILE_VECTOR_HEIGHT; + const uint tiles_per_row = dst_stride / (tile_w * tile_h * bpp); + + src_stride /= bpp; /* convert from bytes to words */ + + if (bpp == 4) { + const uint32_t *src32 = (const uint32_t *) src; + uint32_t *dst32 = (uint32_t *) dst; + uint i, j; + + for (j = 0; j < height; j += tile_h) { + for (i = 0; i < width; i += tile_w) { + /* compute offsets in 32-bit words */ + uint ii = i + x, jj = j + y; + uint src_offset = jj * src_stride + ii; + uint dst_offset = (jj / tile_h * tiles_per_row + ii / tile_w) + * (tile_w * tile_h); + tile_4_4_uint32(src32 + src_offset, + dst32 + dst_offset, + src_stride); + } + } + } + else { + const uint16_t *src16 = (const uint16_t *) src; + uint16_t *dst16 = (uint16_t *) dst; + uint i, j; + + assert(bpp == 2); + + for (j = 0; j < height; j += tile_h) { + for (i = 0; i < width; i += tile_w) { + /* compute offsets in 16-bit words */ + uint ii = i + x, jj = j + y; + uint src_offset = jj * src_stride + ii; + uint dst_offset = (jj / tile_h * tiles_per_row + ii / tile_w) + * (tile_w * tile_h); + tile_4_4_uint16(src16 + src_offset, + dst16 + dst_offset, + src_stride); + } + } + } + } + else { + const uint bpp = 4; + const uint tile_w = TILE_SIZE, tile_h = TILE_SIZE; + const uint bytes_per_tile = tile_w * tile_h * bpp; + uint i, j; + + for (j = 0; j < height; j += TILE_SIZE) { + for (i = 0; i < width; i += TILE_SIZE) { + uint ii = i + x, jj = j + y; + uint tile_offset = ((jj / tile_h) * tiles_per_row + ii / tile_w); + uint byte_offset = tile_offset * bytes_per_tile; + uint8_t *dst_tile = (uint8_t *) dst + byte_offset; + + lp_tile_swizzle_4ub(format, + dst_tile, + src, src_stride, + ii, jj); + } + } + } +} + + +/** + * For testing only. + */ +void +test_tiled_linear_conversion(void *data, + enum pipe_format format, + unsigned width, unsigned height, + unsigned stride) +{ + /* size in tiles */ + unsigned wt = (width + TILE_SIZE - 1) / TILE_SIZE; + unsigned ht = (height + TILE_SIZE - 1) / TILE_SIZE; + + uint8_t *tiled = malloc(wt * ht * TILE_SIZE * TILE_SIZE * 4); + + /*unsigned tiled_stride = wt * TILE_SIZE * TILE_SIZE * 4;*/ + + lp_linear_to_tiled(data, tiled, 0, 0, width, height, format, + stride, wt); + + lp_tiled_to_linear(tiled, data, 0, 0, width, height, format, + stride, wt); + + free(tiled); +} + diff --git a/src/gallium/drivers/llvmpipe/lp_tile_image.h b/src/gallium/drivers/llvmpipe/lp_tile_image.h new file mode 100644 index 0000000..8de8efc --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_tile_image.h @@ -0,0 +1,57 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL THE 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 LP_TILE_IMAGE_H +#define LP_TILE_IMAGE_H + + +void +lp_tiled_to_linear(const void *src, void *dst, + unsigned x, unsigned y, + unsigned width, unsigned height, + enum pipe_format format, + unsigned dst_stride, + unsigned tiles_per_row); + + +void +lp_linear_to_tiled(const void *src, void *dst, + unsigned x, unsigned y, + unsigned width, unsigned height, + enum pipe_format format, + unsigned src_stride, + unsigned tiles_per_row); + + +void +test_tiled_linear_conversion(void *data, + enum pipe_format format, + unsigned width, unsigned height, + unsigned stride); + + +#endif /* LP_TILE_IMAGE_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_tile_shuffle_mask.py b/src/gallium/drivers/llvmpipe/lp_tile_shuffle_mask.py new file mode 100644 index 0000000..ea2fc0f --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_tile_shuffle_mask.py @@ -0,0 +1,32 @@ + +tile = [[0,1,4,5], + [2,3,6,7], + [8,9,12,13], + [10,11,14,15]] +shift = 0 +align = 1 +value = 0L +holder = [] + +import sys + +basemask = [0x +fd = sys.stdout +indent = " "*9 +for c in range(4): + fd.write(indent + "*pdst++ = \n"); + for l,line in enumerate(tile): + fd.write(indent + " %s_mm_shuffle_epi8(line%d, (__m128i){"%(l and '+' or ' ',l)) + for i,pos in enumerate(line): + mask = 0x00ffffffff & (~(0xffL << shift)) + value = mask | ((pos) << shift) + holder.append(value) + if holder and (i + 1) %2 == 0: + fd.write("0x%8.0x"%(holder[0] + (holder[1] << 32))) + holder = [] + if (i) %4 == 1: + fd.write( ',') + + fd.write("})%s\n"%((l == 3) and ';' or '')) + print + shift += 8 diff --git a/src/gallium/drivers/llvmpipe/lp_tile_soa.h b/src/gallium/drivers/llvmpipe/lp_tile_soa.h new file mode 100644 index 0000000..12dac1d --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_tile_soa.h @@ -0,0 +1,97 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef LP_TILE_SOA_H +#define LP_TILE_SOA_H + +#include "pipe/p_compiler.h" +#include "tgsi/tgsi_exec.h" /* for NUM_CHANNELS */ +#include "lp_limits.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +struct pipe_transfer; + + +#define TILE_VECTOR_HEIGHT 4 +#define TILE_VECTOR_WIDTH 4 + +extern const unsigned char +tile_offset[TILE_VECTOR_HEIGHT][TILE_VECTOR_WIDTH]; + +#define TILE_C_STRIDE (TILE_VECTOR_HEIGHT * TILE_VECTOR_WIDTH) //16 +#define TILE_X_STRIDE (NUM_CHANNELS * TILE_C_STRIDE) //64 +#define TILE_Y_STRIDE (TILE_VECTOR_HEIGHT * TILE_SIZE * NUM_CHANNELS) //1024 + + +#ifdef DEBUG +extern unsigned lp_tile_unswizzle_count; +extern unsigned lp_tile_swizzle_count; +#endif + + +/** + * Return offset of the given pixel (and color channel) from the start + * of a tile, in bytes. + */ +static INLINE unsigned +tile_pixel_offset(unsigned x, unsigned y, unsigned c) +{ + unsigned ix = (x / TILE_VECTOR_WIDTH) * TILE_X_STRIDE; + unsigned iy = (y / TILE_VECTOR_HEIGHT) * TILE_Y_STRIDE; + unsigned offset = iy + ix + c * TILE_C_STRIDE + + tile_offset[y % TILE_VECTOR_HEIGHT][x % TILE_VECTOR_WIDTH]; + return offset; +} + + +#define TILE_PIXEL(_p, _x, _y, _c) ((_p)[tile_pixel_offset(_x, _y, _c)]) + + +void +lp_tile_swizzle_4ub(enum pipe_format format, + uint8_t *dst, + const void *src, unsigned src_stride, + unsigned x, unsigned y); + + +void +lp_tile_unswizzle_4ub(enum pipe_format format, + const uint8_t *src, + void *dst, unsigned dst_stride, + unsigned x, unsigned y); + + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/drivers/llvmpipe/lp_tile_soa.py b/src/gallium/drivers/llvmpipe/lp_tile_soa.py new file mode 100644 index 0000000..8df7b23 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_tile_soa.py @@ -0,0 +1,560 @@ +#!/usr/bin/env python + +CopyRight = ''' +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +/** + * @file + * Pixel format accessor functions. + * + * @author Jose Fonseca + */ +''' + + +import sys +import os.path + +sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]), '../../auxiliary/util')) + +from u_format_pack import * + + +def is_format_supported(format): + '''Determines whether we actually have the plumbing necessary to generate the + to read/write to/from this format.''' + + # FIXME: Ideally we would support any format combination here. + + if format.layout != PLAIN: + return False + + for i in range(4): + channel = format.channels[i] + if channel.type not in (VOID, UNSIGNED, SIGNED, FLOAT): + return False + if channel.type == FLOAT and channel.size not in (16, 32 ,64): + return False + + if format.colorspace not in ('rgb', 'srgb'): + return False + + return True + + +def generate_format_read(format, dst_channel, dst_native_type, dst_suffix): + '''Generate the function to read pixels from a particular format''' + + name = format.short_name() + + src_native_type = native_type(format) + + print 'static void' + print 'lp_tile_%s_swizzle_%s(%s *dst, const uint8_t *src, unsigned src_stride, unsigned x0, unsigned y0)' % (name, dst_suffix, dst_native_type) + print '{' + print ' unsigned x, y;' + print ' const uint8_t *src_row = src + y0*src_stride;' + print ' for (y = 0; y < TILE_SIZE; ++y) {' + print ' const %s *src_pixel = (const %s *)(src_row + x0*%u);' % (src_native_type, src_native_type, format.stride()) + print ' for (x = 0; x < TILE_SIZE; ++x) {' + + names = ['']*4 + if format.colorspace in ('rgb', 'srgb'): + for i in range(4): + swizzle = format.swizzles[i] + if swizzle < 4: + names[swizzle] += 'rgba'[i] + elif format.colorspace == 'zs': + swizzle = format.swizzles[0] + if swizzle < 4: + names[swizzle] = 'z' + else: + assert False + else: + assert False + + if format.layout == PLAIN: + if not format.is_array(): + print ' %s pixel = *src_pixel++;' % src_native_type + shift = 0; + for i in range(4): + src_channel = format.channels[i] + width = src_channel.size + if names[i]: + value = 'pixel' + mask = (1 << width) - 1 + if shift: + value = '(%s >> %u)' % (value, shift) + if shift + width < format.block_size(): + value = '(%s & 0x%x)' % (value, mask) + value = conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=False) + print ' %s %s = %s;' % (dst_native_type, names[i], value) + shift += width + else: + for i in range(4): + if names[i]: + print ' %s %s;' % (dst_native_type, names[i]) + for i in range(4): + src_channel = format.channels[i] + if names[i]: + value = '(*src_pixel++)' + value = conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=False) + print ' %s = %s;' % (names[i], value) + elif src_channel.size: + print ' ++src_pixel;' + else: + assert False + + for i in range(4): + if format.colorspace in ('rgb', 'srgb'): + swizzle = format.swizzles[i] + if swizzle < 4: + value = names[swizzle] + elif swizzle == SWIZZLE_0: + value = '0' + elif swizzle == SWIZZLE_1: + value = get_one(dst_channel) + else: + assert False + elif format.colorspace == 'zs': + if i < 3: + value = 'z' + else: + value = get_one(dst_channel) + else: + assert False + print ' TILE_PIXEL(dst, x, y, %u) = %s; /* %s */' % (i, value, 'rgba'[i]) + + print ' }' + print ' src_row += src_stride;' + print ' }' + print '}' + print + + +def pack_rgba(format, src_channel, r, g, b, a): + """Return an expression for packing r, g, b, a into a pixel of the + given format. Ex: '(b << 24) | (g << 16) | (r << 8) | (a << 0)' + """ + assert format.colorspace in ('rgb', 'srgb') + inv_swizzle = format.inv_swizzles() + shift = 0 + expr = None + for i in range(4): + # choose r, g, b, or a depending on the inverse swizzle term + if inv_swizzle[i] == 0: + value = r + elif inv_swizzle[i] == 1: + value = g + elif inv_swizzle[i] == 2: + value = b + elif inv_swizzle[i] == 3: + value = a + else: + value = None + + if value: + dst_channel = format.channels[i] + dst_native_type = native_type(format) + value = conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=False) + term = "((%s) << %d)" % (value, shift) + if expr: + expr = expr + " | " + term + else: + expr = term + + width = format.channels[i].size + shift = shift + width + return expr + + +def emit_unrolled_unswizzle_code(format, src_channel): + '''Emit code for writing a block based on unrolled loops. + This is considerably faster than the TILE_PIXEL-based code below. + ''' + dst_native_type = 'uint%u_t' % format.block_size() + print ' const unsigned dstpix_stride = dst_stride / %d;' % format.stride() + print ' %s *dstpix = (%s *) dst;' % (dst_native_type, dst_native_type) + print ' unsigned int qx, qy, i;' + print + print ' for (qy = 0; qy < TILE_SIZE; qy += TILE_VECTOR_HEIGHT) {' + print ' const unsigned py = y0 + qy;' + print ' for (qx = 0; qx < TILE_SIZE; qx += TILE_VECTOR_WIDTH) {' + print ' const unsigned px = x0 + qx;' + print ' const uint8_t *r = src + 0 * TILE_C_STRIDE;' + print ' const uint8_t *g = src + 1 * TILE_C_STRIDE;' + print ' const uint8_t *b = src + 2 * TILE_C_STRIDE;' + print ' const uint8_t *a = src + 3 * TILE_C_STRIDE;' + print ' (void) r; (void) g; (void) b; (void) a; /* silence warnings */' + print ' for (i = 0; i < TILE_C_STRIDE; i += 2) {' + print ' const uint32_t pixel0 = %s;' % pack_rgba(format, src_channel, "r[i+0]", "g[i+0]", "b[i+0]", "a[i+0]") + print ' const uint32_t pixel1 = %s;' % pack_rgba(format, src_channel, "r[i+1]", "g[i+1]", "b[i+1]", "a[i+1]") + print ' const unsigned offset = (py + tile_y_offset[i]) * dstpix_stride + (px + tile_x_offset[i]);' + print ' dstpix[offset + 0] = pixel0;' + print ' dstpix[offset + 1] = pixel1;' + print ' }' + print ' src += TILE_X_STRIDE;' + print ' }' + print ' }' + + +def emit_tile_pixel_unswizzle_code(format, src_channel): + '''Emit code for writing a block based on the TILE_PIXEL macro.''' + dst_native_type = native_type(format) + + inv_swizzle = format.inv_swizzles() + + print ' unsigned x, y;' + print ' uint8_t *dst_row = dst + y0*dst_stride;' + print ' for (y = 0; y < TILE_SIZE; ++y) {' + print ' %s *dst_pixel = (%s *)(dst_row + x0*%u);' % (dst_native_type, dst_native_type, format.stride()) + print ' for (x = 0; x < TILE_SIZE; ++x) {' + + if format.layout == PLAIN: + if not format.is_array(): + print ' %s pixel = 0;' % dst_native_type + shift = 0; + for i in range(4): + dst_channel = format.channels[i] + width = dst_channel.size + if inv_swizzle[i] is not None: + value = 'TILE_PIXEL(src, x, y, %u)' % inv_swizzle[i] + value = conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=False) + if shift: + value = '(%s << %u)' % (value, shift) + print ' pixel |= %s;' % value + shift += width + print ' *dst_pixel++ = pixel;' + else: + for i in range(4): + dst_channel = format.channels[i] + if inv_swizzle[i] is not None: + value = 'TILE_PIXEL(src, x, y, %u)' % inv_swizzle[i] + value = conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=False) + print ' *dst_pixel++ = %s;' % value + elif dst_channel.size: + print ' ++dst_pixel;' + else: + assert False + + print ' }' + print ' dst_row += dst_stride;' + print ' }' + + +def generate_format_write(format, src_channel, src_native_type, src_suffix): + '''Generate the function to write pixels to a particular format''' + + name = format.short_name() + + print 'static void' + print 'lp_tile_%s_unswizzle_%s(const %s *src, uint8_t *dst, unsigned dst_stride, unsigned x0, unsigned y0)' % (name, src_suffix, src_native_type) + print '{' + if format.layout == PLAIN \ + and format.colorspace == 'rgb' \ + and format.block_size() <= 32 \ + and format.is_pot() \ + and not format.is_mixed() \ + and (format.channels[0].type == UNSIGNED \ + or format.channels[1].type == UNSIGNED): + emit_unrolled_unswizzle_code(format, src_channel) + else: + emit_tile_pixel_unswizzle_code(format, src_channel) + print '}' + print + + +def generate_sse2(): + print ''' +#if defined(PIPE_ARCH_SSE) + +#include "util/u_sse.h" + +static ALWAYS_INLINE void +swz4( const __m128i * restrict x, + const __m128i * restrict y, + const __m128i * restrict z, + const __m128i * restrict w, + __m128i * restrict a, + __m128i * restrict b, + __m128i * restrict c, + __m128i * restrict d) +{ + __m128i i, j, k, l; + __m128i m, n, o, p; + __m128i e, f, g, h; + + m = _mm_unpacklo_epi8(*x,*y); + n = _mm_unpackhi_epi8(*x,*y); + o = _mm_unpacklo_epi8(*z,*w); + p = _mm_unpackhi_epi8(*z,*w); + + i = _mm_unpacklo_epi16(m,n); + j = _mm_unpackhi_epi16(m,n); + k = _mm_unpacklo_epi16(o,p); + l = _mm_unpackhi_epi16(o,p); + + e = _mm_unpacklo_epi8(i,j); + f = _mm_unpackhi_epi8(i,j); + g = _mm_unpacklo_epi8(k,l); + h = _mm_unpackhi_epi8(k,l); + + *a = _mm_unpacklo_epi64(e,g); + *b = _mm_unpackhi_epi64(e,g); + *c = _mm_unpacklo_epi64(f,h); + *d = _mm_unpackhi_epi64(f,h); +} + +static ALWAYS_INLINE void +unswz4( const __m128i * restrict a, + const __m128i * restrict b, + const __m128i * restrict c, + const __m128i * restrict d, + __m128i * restrict x, + __m128i * restrict y, + __m128i * restrict z, + __m128i * restrict w) +{ + __m128i i, j, k, l; + __m128i m, n, o, p; + + i = _mm_unpacklo_epi8(*a,*b); + j = _mm_unpackhi_epi8(*a,*b); + k = _mm_unpacklo_epi8(*c,*d); + l = _mm_unpackhi_epi8(*c,*d); + + m = _mm_unpacklo_epi16(i,k); + n = _mm_unpackhi_epi16(i,k); + o = _mm_unpacklo_epi16(j,l); + p = _mm_unpackhi_epi16(j,l); + + *x = _mm_unpacklo_epi64(m,n); + *y = _mm_unpackhi_epi64(m,n); + *z = _mm_unpacklo_epi64(o,p); + *w = _mm_unpackhi_epi64(o,p); +} + +static void +lp_tile_b8g8r8a8_unorm_swizzle_4ub_sse2(uint8_t * restrict dst, + const uint8_t * restrict src, unsigned src_stride, + unsigned x0, unsigned y0) +{ + __m128i *dst128 = (__m128i *) dst; + unsigned x, y; + + src += y0 * src_stride; + src += x0 * sizeof(uint32_t); + + for (y = 0; y < TILE_SIZE; y += 4) { + const uint8_t *src_row = src; + + for (x = 0; x < TILE_SIZE; x += 4) { + swz4((const __m128i *) (src_row + 0 * src_stride), + (const __m128i *) (src_row + 1 * src_stride), + (const __m128i *) (src_row + 2 * src_stride), + (const __m128i *) (src_row + 3 * src_stride), + dst128 + 2, /* b */ + dst128 + 1, /* g */ + dst128 + 0, /* r */ + dst128 + 3); /* a */ + + dst128 += 4; + src_row += sizeof(__m128i); + } + + src += 4 * src_stride; + } +} + +static void +lp_tile_b8g8r8a8_unorm_unswizzle_4ub_sse2(const uint8_t * restrict src, + uint8_t * restrict dst, unsigned dst_stride, + unsigned x0, unsigned y0) +{ + unsigned int x, y; + const __m128i *src128 = (const __m128i *) src; + + dst += y0 * dst_stride; + dst += x0 * sizeof(uint32_t); + + for (y = 0; y < TILE_SIZE; y += 4) { + const uint8_t *dst_row = dst; + + for (x = 0; x < TILE_SIZE; x += 4) { + unswz4( &src128[2], /* b */ + &src128[1], /* g */ + &src128[0], /* r */ + &src128[3], /* a */ + (__m128i *) (dst_row + 0 * dst_stride), + (__m128i *) (dst_row + 1 * dst_stride), + (__m128i *) (dst_row + 2 * dst_stride), + (__m128i *) (dst_row + 3 * dst_stride)); + + src128 += 4; + dst_row += sizeof(__m128i);; + } + + dst += 4 * dst_stride; + } +} + +#endif /* PIPE_ARCH_SSE */ +''' + + +def generate_swizzle(formats, dst_channel, dst_native_type, dst_suffix): + '''Generate the dispatch function to read pixels from any format''' + + for format in formats: + if is_format_supported(format): + generate_format_read(format, dst_channel, dst_native_type, dst_suffix) + + print 'void' + print 'lp_tile_swizzle_%s(enum pipe_format format, %s *dst, const void *src, unsigned src_stride, unsigned x, unsigned y)' % (dst_suffix, dst_native_type) + print '{' + print ' void (*func)(%s *dst, const uint8_t *src, unsigned src_stride, unsigned x0, unsigned y0);' % dst_native_type + print '#ifdef DEBUG' + print ' lp_tile_swizzle_count += 1;' + print '#endif' + print ' switch(format) {' + for format in formats: + if is_format_supported(format): + print ' case %s:' % format.name + func_name = 'lp_tile_%s_swizzle_%s' % (format.short_name(), dst_suffix) + if format.name == 'PIPE_FORMAT_B8G8R8A8_UNORM': + print '#ifdef PIPE_ARCH_SSE' + print ' func = util_cpu_caps.has_sse2 ? %s_sse2 : %s;' % (func_name, func_name) + print '#else' + print ' func = %s;' % (func_name,) + print '#endif' + else: + print ' func = %s;' % (func_name,) + print ' break;' + print ' default:' + print ' debug_printf("%s: unsupported format %s\\n", __FUNCTION__, util_format_name(format));' + print ' return;' + print ' }' + print ' func(dst, (const uint8_t *)src, src_stride, x, y);' + print '}' + print + + +def generate_unswizzle(formats, src_channel, src_native_type, src_suffix): + '''Generate the dispatch function to write pixels to any format''' + + for format in formats: + if is_format_supported(format): + generate_format_write(format, src_channel, src_native_type, src_suffix) + + print 'void' + print 'lp_tile_unswizzle_%s(enum pipe_format format, const %s *src, void *dst, unsigned dst_stride, unsigned x, unsigned y)' % (src_suffix, src_native_type) + + print '{' + print ' void (*func)(const %s *src, uint8_t *dst, unsigned dst_stride, unsigned x0, unsigned y0);' % src_native_type + print '#ifdef DEBUG' + print ' lp_tile_unswizzle_count += 1;' + print '#endif' + print ' switch(format) {' + for format in formats: + if is_format_supported(format): + print ' case %s:' % format.name + func_name = 'lp_tile_%s_unswizzle_%s' % (format.short_name(), src_suffix) + if format.name == 'PIPE_FORMAT_B8G8R8A8_UNORM': + print '#ifdef PIPE_ARCH_SSE' + print ' func = util_cpu_caps.has_sse2 ? %s_sse2 : %s;' % (func_name, func_name) + print '#else' + print ' func = %s;' % (func_name,) + print '#endif' + else: + print ' func = %s;' % (func_name,) + print ' break;' + print ' default:' + print ' debug_printf("%s: unsupported format %s\\n", __FUNCTION__, util_format_name(format));' + print ' return;' + print ' }' + print ' func(src, (uint8_t *)dst, dst_stride, x, y);' + print '}' + print + + +def main(): + formats = [] + for arg in sys.argv[1:]: + formats.extend(parse(arg)) + + print '/* This file is autogenerated by lp_tile_soa.py from u_format.csv. Do not edit directly. */' + print + # This will print the copyright message on the top of this file + print CopyRight.strip() + print + print '#include "pipe/p_compiler.h"' + print '#include "util/u_format.h"' + print '#include "util/u_math.h"' + print '#include "util/u_half.h"' + print '#include "util/u_cpu_detect.h"' + print '#include "lp_tile_soa.h"' + print + print '#ifdef DEBUG' + print 'unsigned lp_tile_unswizzle_count = 0;' + print 'unsigned lp_tile_swizzle_count = 0;' + print '#endif' + print + print 'const unsigned char' + print 'tile_offset[TILE_VECTOR_HEIGHT][TILE_VECTOR_WIDTH] = {' + print ' { 0, 1, 4, 5},' + print ' { 2, 3, 6, 7},' + print ' { 8, 9, 12, 13},' + print ' { 10, 11, 14, 15}' + print '};' + print + print '/* Note: these lookup tables could be replaced with some' + print ' * bit-twiddling code, but this is a little faster.' + print ' */' + print 'static unsigned tile_x_offset[TILE_VECTOR_WIDTH * TILE_VECTOR_HEIGHT] = {' + print ' 0, 1, 0, 1, 2, 3, 2, 3,' + print ' 0, 1, 0, 1, 2, 3, 2, 3' + print '};' + print + print 'static unsigned tile_y_offset[TILE_VECTOR_WIDTH * TILE_VECTOR_HEIGHT] = {' + print ' 0, 0, 1, 1, 0, 0, 1, 1,' + print ' 2, 2, 3, 3, 2, 2, 3, 3' + print '};' + print + + generate_sse2() + + channel = Channel(UNSIGNED, True, 8) + native_type = 'uint8_t' + suffix = '4ub' + + generate_swizzle(formats, channel, native_type, suffix) + generate_unswizzle(formats, channel, native_type, suffix) + + +if __name__ == '__main__': + main() diff --git a/src/gallium/drivers/llvmpipe/sse_mathfun.h b/src/gallium/drivers/llvmpipe/sse_mathfun.h new file mode 100644 index 0000000..0077f34 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/sse_mathfun.h @@ -0,0 +1,724 @@ +/* SIMD (SSE1+MMX or SSE2) implementation of sin, cos, exp and log + + Inspired by Intel Approximate Math library, and based on the + corresponding algorithms of the cephes math library + + The default is to use the SSE1 version. If you define USE_SSE2 the + the SSE2 intrinsics will be used in place of the MMX intrinsics. Do + not expect any significant performance improvement with SSE2. +*/ + +/* Copyright (C) 2007 Julien Pommier + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + (this is the zlib license) +*/ + +#include + +/* yes I know, the top of this file is quite ugly */ + +#ifdef _MSC_VER /* visual c++ */ +# define ALIGN16_BEG __declspec(align(16)) +# define ALIGN16_END +#else /* gcc or icc */ +# define ALIGN16_BEG +# define ALIGN16_END __attribute__((aligned(16))) +#endif + +/* __m128 is ugly to write */ +typedef __m128 v4sf; // vector of 4 float (sse1) + +#ifdef USE_SSE2 +# include +typedef __m128i v4si; // vector of 4 int (sse2) +#else +typedef __m64 v2si; // vector of 2 int (mmx) +#endif + +/* declare some SSE constants -- why can't I figure a better way to do that? */ +#define _PS_CONST(Name, Val) \ + static const ALIGN16_BEG float _ps_##Name[4] ALIGN16_END = { Val, Val, Val, Val } +#define _PI32_CONST(Name, Val) \ + static const ALIGN16_BEG int _pi32_##Name[4] ALIGN16_END = { Val, Val, Val, Val } +#define _PS_CONST_TYPE(Name, Type, Val) \ + static const ALIGN16_BEG Type _ps_##Name[4] ALIGN16_END = { Val, Val, Val, Val } + +_PS_CONST(1 , 1.0f); +_PS_CONST(0p5, 0.5f); +/* the smallest non denormalized float number */ +_PS_CONST_TYPE(min_norm_pos, int, 0x00800000); +_PS_CONST_TYPE(mant_mask, int, 0x7f800000); +_PS_CONST_TYPE(inv_mant_mask, int, ~0x7f800000); + +_PS_CONST_TYPE(sign_mask, int, 0x80000000); +_PS_CONST_TYPE(inv_sign_mask, int, ~0x80000000); + +_PI32_CONST(1, 1); +_PI32_CONST(inv1, ~1); +_PI32_CONST(2, 2); +_PI32_CONST(4, 4); +_PI32_CONST(0x7f, 0x7f); + +_PS_CONST(cephes_SQRTHF, 0.707106781186547524); +_PS_CONST(cephes_log_p0, 7.0376836292E-2); +_PS_CONST(cephes_log_p1, - 1.1514610310E-1); +_PS_CONST(cephes_log_p2, 1.1676998740E-1); +_PS_CONST(cephes_log_p3, - 1.2420140846E-1); +_PS_CONST(cephes_log_p4, + 1.4249322787E-1); +_PS_CONST(cephes_log_p5, - 1.6668057665E-1); +_PS_CONST(cephes_log_p6, + 2.0000714765E-1); +_PS_CONST(cephes_log_p7, - 2.4999993993E-1); +_PS_CONST(cephes_log_p8, + 3.3333331174E-1); +_PS_CONST(cephes_log_q1, -2.12194440e-4); +_PS_CONST(cephes_log_q2, 0.693359375); + +v4sf log_ps(v4sf x); +v4sf exp_ps(v4sf x); +v4sf sin_ps(v4sf x); +v4sf cos_ps(v4sf x); +void sincos_ps(v4sf x, v4sf *s, v4sf *c); + +#ifndef USE_SSE2 +typedef union xmm_mm_union { + __m128 xmm; + __m64 mm[2]; +} xmm_mm_union; + +#define COPY_XMM_TO_MM(xmm_, mm0_, mm1_) { \ + xmm_mm_union u; u.xmm = xmm_; \ + mm0_ = u.mm[0]; \ + mm1_ = u.mm[1]; \ +} + +#define COPY_MM_TO_XMM(mm0_, mm1_, xmm_) { \ + xmm_mm_union u; u.mm[0]=mm0_; u.mm[1]=mm1_; xmm_ = u.xmm; \ + } + +#endif // USE_SSE2 + +/* natural logarithm computed for 4 simultaneous float + return NaN for x <= 0 +*/ +v4sf log_ps(v4sf x) { +#ifdef USE_SSE2 + v4si emm0; +#else + v2si mm0, mm1; +#endif + v4sf one = *(v4sf*)_ps_1; + + v4sf invalid_mask = _mm_cmple_ps(x, _mm_setzero_ps()); + v4sf e, mask, tmp, z, y; + + x = _mm_max_ps(x, *(v4sf*)_ps_min_norm_pos); /* cut off denormalized stuff */ + +#ifndef USE_SSE2 + /* part 1: x = frexpf(x, &e); */ + COPY_XMM_TO_MM(x, mm0, mm1); + mm0 = _mm_srli_pi32(mm0, 23); + mm1 = _mm_srli_pi32(mm1, 23); +#else + emm0 = _mm_srli_epi32(_mm_castps_si128(x), 23); +#endif + /* keep only the fractional part */ + x = _mm_and_ps(x, *(v4sf*)_ps_inv_mant_mask); + x = _mm_or_ps(x, *(v4sf*)_ps_0p5); + +#ifndef USE_SSE2 + /* now e=mm0:mm1 contain the really base-2 exponent */ + mm0 = _mm_sub_pi32(mm0, *(v2si*)_pi32_0x7f); + mm1 = _mm_sub_pi32(mm1, *(v2si*)_pi32_0x7f); + e = _mm_cvtpi32x2_ps(mm0, mm1); + _mm_empty(); /* bye bye mmx */ +#else + emm0 = _mm_sub_epi32(emm0, *(v4si*)_pi32_0x7f); + e = _mm_cvtepi32_ps(emm0); +#endif + + e = _mm_add_ps(e, one); + + /* part2: + if( x < SQRTHF ) { + e -= 1; + x = x + x - 1.0; + } else { x = x - 1.0; } + */ + + mask = _mm_cmplt_ps(x, *(v4sf*)_ps_cephes_SQRTHF); + tmp = _mm_and_ps(x, mask); + x = _mm_sub_ps(x, one); + e = _mm_sub_ps(e, _mm_and_ps(one, mask)); + x = _mm_add_ps(x, tmp); + + + z = _mm_mul_ps(x,x); + + y = *(v4sf*)_ps_cephes_log_p0; + y = _mm_mul_ps(y, x); + y = _mm_add_ps(y, *(v4sf*)_ps_cephes_log_p1); + y = _mm_mul_ps(y, x); + y = _mm_add_ps(y, *(v4sf*)_ps_cephes_log_p2); + y = _mm_mul_ps(y, x); + y = _mm_add_ps(y, *(v4sf*)_ps_cephes_log_p3); + y = _mm_mul_ps(y, x); + y = _mm_add_ps(y, *(v4sf*)_ps_cephes_log_p4); + y = _mm_mul_ps(y, x); + y = _mm_add_ps(y, *(v4sf*)_ps_cephes_log_p5); + y = _mm_mul_ps(y, x); + y = _mm_add_ps(y, *(v4sf*)_ps_cephes_log_p6); + y = _mm_mul_ps(y, x); + y = _mm_add_ps(y, *(v4sf*)_ps_cephes_log_p7); + y = _mm_mul_ps(y, x); + y = _mm_add_ps(y, *(v4sf*)_ps_cephes_log_p8); + y = _mm_mul_ps(y, x); + + y = _mm_mul_ps(y, z); + + + tmp = _mm_mul_ps(e, *(v4sf*)_ps_cephes_log_q1); + y = _mm_add_ps(y, tmp); + + + tmp = _mm_mul_ps(z, *(v4sf*)_ps_0p5); + y = _mm_sub_ps(y, tmp); + + tmp = _mm_mul_ps(e, *(v4sf*)_ps_cephes_log_q2); + x = _mm_add_ps(x, y); + x = _mm_add_ps(x, tmp); + x = _mm_or_ps(x, invalid_mask); // negative arg will be NAN + return x; +} + +_PS_CONST(exp_hi, 88.3762626647949f); +_PS_CONST(exp_lo, -88.3762626647949f); + +_PS_CONST(cephes_LOG2EF, 1.44269504088896341); +_PS_CONST(cephes_exp_C1, 0.693359375); +_PS_CONST(cephes_exp_C2, -2.12194440e-4); + +_PS_CONST(cephes_exp_p0, 1.9875691500E-4); +_PS_CONST(cephes_exp_p1, 1.3981999507E-3); +_PS_CONST(cephes_exp_p2, 8.3334519073E-3); +_PS_CONST(cephes_exp_p3, 4.1665795894E-2); +_PS_CONST(cephes_exp_p4, 1.6666665459E-1); +_PS_CONST(cephes_exp_p5, 5.0000001201E-1); + +v4sf exp_ps(v4sf x) { + v4sf tmp = _mm_setzero_ps(), fx; +#ifdef USE_SSE2 + v4si emm0; +#else + v2si mm0, mm1; +#endif + v4sf one = *(v4sf*)_ps_1; + v4sf mask, z, y, pow2n; + + x = _mm_min_ps(x, *(v4sf*)_ps_exp_hi); + x = _mm_max_ps(x, *(v4sf*)_ps_exp_lo); + + /* express exp(x) as exp(g + n*log(2)) */ + fx = _mm_mul_ps(x, *(v4sf*)_ps_cephes_LOG2EF); + fx = _mm_add_ps(fx, *(v4sf*)_ps_0p5); + + /* how to perform a floorf with SSE: just below */ +#ifndef USE_SSE2 + /* step 1 : cast to int */ + tmp = _mm_movehl_ps(tmp, fx); + mm0 = _mm_cvttps_pi32(fx); + mm1 = _mm_cvttps_pi32(tmp); + /* step 2 : cast back to float */ + tmp = _mm_cvtpi32x2_ps(mm0, mm1); +#else + emm0 = _mm_cvttps_epi32(fx); + tmp = _mm_cvtepi32_ps(emm0); +#endif + /* if greater, substract 1 */ + mask = _mm_cmpgt_ps(tmp, fx); + mask = _mm_and_ps(mask, one); + fx = _mm_sub_ps(tmp, mask); + + tmp = _mm_mul_ps(fx, *(v4sf*)_ps_cephes_exp_C1); + z = _mm_mul_ps(fx, *(v4sf*)_ps_cephes_exp_C2); + x = _mm_sub_ps(x, tmp); + x = _mm_sub_ps(x, z); + + z = _mm_mul_ps(x,x); + + y = *(v4sf*)_ps_cephes_exp_p0; + y = _mm_mul_ps(y, x); + y = _mm_add_ps(y, *(v4sf*)_ps_cephes_exp_p1); + y = _mm_mul_ps(y, x); + y = _mm_add_ps(y, *(v4sf*)_ps_cephes_exp_p2); + y = _mm_mul_ps(y, x); + y = _mm_add_ps(y, *(v4sf*)_ps_cephes_exp_p3); + y = _mm_mul_ps(y, x); + y = _mm_add_ps(y, *(v4sf*)_ps_cephes_exp_p4); + y = _mm_mul_ps(y, x); + y = _mm_add_ps(y, *(v4sf*)_ps_cephes_exp_p5); + y = _mm_mul_ps(y, z); + y = _mm_add_ps(y, x); + y = _mm_add_ps(y, one); + + /* build 2^n */ +#ifndef USE_SSE2 + z = _mm_movehl_ps(z, fx); + mm0 = _mm_cvttps_pi32(fx); + mm1 = _mm_cvttps_pi32(z); + mm0 = _mm_add_pi32(mm0, *(v2si*)_pi32_0x7f); + mm1 = _mm_add_pi32(mm1, *(v2si*)_pi32_0x7f); + mm0 = _mm_slli_pi32(mm0, 23); + mm1 = _mm_slli_pi32(mm1, 23); + + COPY_MM_TO_XMM(mm0, mm1, pow2n); + _mm_empty(); +#else + emm0 = _mm_cvttps_epi32(fx); + emm0 = _mm_add_epi32(emm0, *(v4si*)_pi32_0x7f); + emm0 = _mm_slli_epi32(emm0, 23); + pow2n = _mm_castsi128_ps(emm0); +#endif + y = _mm_mul_ps(y, pow2n); + return y; +} + +_PS_CONST(minus_cephes_DP1, -0.78515625); +_PS_CONST(minus_cephes_DP2, -2.4187564849853515625e-4); +_PS_CONST(minus_cephes_DP3, -3.77489497744594108e-8); +_PS_CONST(sincof_p0, -1.9515295891E-4); +_PS_CONST(sincof_p1, 8.3321608736E-3); +_PS_CONST(sincof_p2, -1.6666654611E-1); +_PS_CONST(coscof_p0, 2.443315711809948E-005); +_PS_CONST(coscof_p1, -1.388731625493765E-003); +_PS_CONST(coscof_p2, 4.166664568298827E-002); +_PS_CONST(cephes_FOPI, 1.27323954473516); // 4 / M_PI + + +/* evaluation of 4 sines at onces, using only SSE1+MMX intrinsics so + it runs also on old athlons XPs and the pentium III of your grand + mother. + + The code is the exact rewriting of the cephes sinf function. + Precision is excellent as long as x < 8192 (I did not bother to + take into account the special handling they have for greater values + -- it does not return garbage for arguments over 8192, though, but + the extra precision is missing). + + Note that it is such that sinf((float)M_PI) = 8.74e-8, which is the + surprising but correct result. + + Performance is also surprisingly good, 1.33 times faster than the + macos vsinf SSE2 function, and 1.5 times faster than the + __vrs4_sinf of amd's ACML (which is only available in 64 bits). Not + too bad for an SSE1 function (with no special tuning) ! + However the latter libraries probably have a much better handling of NaN, + Inf, denormalized and other special arguments.. + + On my core 1 duo, the execution of this function takes approximately 95 cycles. + + From what I have observed on the experiments with Intel AMath lib, switching to an + SSE2 version would improve the perf by only 10%. + + Since it is based on SSE intrinsics, it has to be compiled at -O2 to + deliver full speed. +*/ +v4sf sin_ps(v4sf x) { // any x + v4sf xmm1, xmm2 = _mm_setzero_ps(), xmm3, sign_bit, y; + +#ifdef USE_SSE2 + v4si emm0, emm2; +#else + v2si mm0, mm1, mm2, mm3; +#endif + v4sf swap_sign_bit, poly_mask, z, tmp, y2; + + sign_bit = x; + /* take the absolute value */ + x = _mm_and_ps(x, *(v4sf*)_ps_inv_sign_mask); + /* extract the sign bit (upper one) */ + sign_bit = _mm_and_ps(sign_bit, *(v4sf*)_ps_sign_mask); + + /* scale by 4/Pi */ + y = _mm_mul_ps(x, *(v4sf*)_ps_cephes_FOPI); + + //printf("plop:"); print4(y); +#ifdef USE_SSE2 + /* store the integer part of y in mm0 */ + emm2 = _mm_cvttps_epi32(y); + /* j=(j+1) & (~1) (see the cephes sources) */ + emm2 = _mm_add_epi32(emm2, *(v4si*)_pi32_1); + emm2 = _mm_and_si128(emm2, *(v4si*)_pi32_inv1); + y = _mm_cvtepi32_ps(emm2); + /* get the swap sign flag */ + emm0 = _mm_and_si128(emm2, *(v4si*)_pi32_4); + emm0 = _mm_slli_epi32(emm0, 29); + /* get the polynom selection mask + there is one polynom for 0 <= x <= Pi/4 + and another one for Pi/4 +#include +#include +#include +#include +#include +#include +#include +#include +#include "noop_public.h" +#include "state_tracker/sw_winsys.h" + +void noop_init_state_functions(struct pipe_context *ctx); + +/* + * query + */ +struct noop_query { + unsigned query; +}; +static struct pipe_query *noop_create_query(struct pipe_context *ctx, unsigned query_type) +{ + struct noop_query *query = CALLOC_STRUCT(noop_query); + + return (struct pipe_query *)query; +} + +static void noop_destroy_query(struct pipe_context *ctx, struct pipe_query *query) +{ + FREE(query); +} + +static void noop_begin_query(struct pipe_context *ctx, struct pipe_query *query) +{ +} + +static void noop_end_query(struct pipe_context *ctx, struct pipe_query *query) +{ +} + +static boolean noop_get_query_result(struct pipe_context *ctx, + struct pipe_query *query, + boolean wait, void *vresult) +{ + uint64_t *result = (uint64_t*)vresult; + + *result = 0; + return TRUE; +} + + +/* + * resource + */ +struct noop_resource { + struct pipe_resource base; + unsigned size; + char *data; + struct sw_displaytarget *dt; +}; + +static unsigned noop_is_resource_referenced(struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, int layer) +{ + return PIPE_UNREFERENCED; +} + +static struct pipe_resource *noop_resource_create(struct pipe_screen *screen, + const struct pipe_resource *templ) +{ + struct noop_resource *nresource; + unsigned stride; + + nresource = CALLOC_STRUCT(noop_resource); + if (nresource == NULL) + return NULL; + + stride = util_format_get_stride(templ->format, templ->width0); + nresource->base = *templ; + nresource->base.screen = screen; + nresource->size = stride * templ->height0 * templ->depth0; + nresource->data = malloc(nresource->size); + pipe_reference_init(&nresource->base.reference, 1); + if (nresource->data == NULL) { + FREE(nresource); + return NULL; + } +#if 0 + if (nresource->base.bind & (PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SCANOUT | + PIPE_BIND_SHARED)) { + struct sw_winsys *winsys = (struct sw_winsys *)screen->winsys; + unsigned stride; + + nresource->dt = winsys->displaytarget_create(winsys, nresource->base.bind, + nresource->base.format, + nresource->base.width0, + nresource->base.height0, + 16, &stride); + } +#endif + return &nresource->base; +} + +static struct pipe_resource *noop_resource_from_handle(struct pipe_screen * screen, + const struct pipe_resource *templ, + struct winsys_handle *whandle) +{ + struct sw_winsys *winsys = (struct sw_winsys *)screen->winsys; + struct noop_resource *nresource; + struct sw_displaytarget *dt; + unsigned stride; + + dt = winsys->displaytarget_from_handle(winsys, templ, whandle, &stride); + if (dt == NULL) { + return NULL; + } + nresource = (struct noop_resource *)noop_resource_create(screen, templ); + nresource->dt = dt; + return &nresource->base; +} + +static boolean noop_resource_get_handle(struct pipe_screen *screen, + struct pipe_resource *resource, + struct winsys_handle *handle) +{ + struct sw_winsys *winsys = (struct sw_winsys *)screen->winsys; + struct noop_resource *nresource = (struct noop_resource *)resource; + + if (nresource->dt == NULL) + return FALSE; + + return winsys->displaytarget_get_handle(winsys, nresource->dt, handle); +} + +static void noop_resource_destroy(struct pipe_screen *screen, + struct pipe_resource *resource) +{ + struct noop_resource *nresource = (struct noop_resource *)resource; + + if (nresource->dt) { + /* display target */ + struct sw_winsys *winsys = (struct sw_winsys *)screen->winsys; + winsys->displaytarget_destroy(winsys, nresource->dt); + } + free(nresource->data); + FREE(resource); +} + +static struct pipe_resource *noop_user_buffer_create(struct pipe_screen *screen, + void *ptr, unsigned bytes, + unsigned bind) +{ + struct pipe_resource templ; + + templ.target = PIPE_BUFFER; + templ.format = PIPE_FORMAT_R8_UNORM; + templ.usage = PIPE_USAGE_IMMUTABLE; + templ.bind = bind; + templ.width0 = bytes; + templ.height0 = 1; + templ.depth0 = 1; + templ.flags = 0; + return noop_resource_create(screen, &templ); +} + + +/* + * transfer + */ +static struct pipe_transfer *noop_get_transfer(struct pipe_context *context, + struct pipe_resource *resource, + unsigned level, + enum pipe_transfer_usage usage, + const struct pipe_box *box) +{ + struct pipe_transfer *transfer; + + transfer = CALLOC_STRUCT(pipe_transfer); + if (transfer == NULL) + return NULL; + pipe_resource_reference(&transfer->resource, resource); + transfer->level = level; + transfer->usage = usage; + transfer->box = *box; + transfer->stride = 1; + transfer->layer_stride = 1; + return transfer; +} + +static void *noop_transfer_map(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct noop_resource *nresource = (struct noop_resource *)transfer->resource; + + return nresource->data; +} + +static void noop_transfer_flush_region(struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box) +{ +} + +static void noop_transfer_unmap(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ +} + +static void noop_transfer_destroy(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + pipe_resource_reference(&transfer->resource, NULL); + FREE(transfer); +} + +static void noop_transfer_inline_write(struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride) +{ +} + + +/* + * clear/copy + */ +static void noop_clear(struct pipe_context *ctx, unsigned buffers, + const float *rgba, double depth, unsigned stencil) +{ +} + +static void noop_clear_render_target(struct pipe_context *ctx, + struct pipe_surface *dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ +} + +static void noop_clear_depth_stencil(struct pipe_context *ctx, + struct pipe_surface *dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ +} + +static void noop_resource_copy_region(struct pipe_context *ctx, + struct pipe_resource *dst, + unsigned dst_level, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource *src, + unsigned src_level, + const struct pipe_box *src_box) +{ +} + + +/* + * context + */ +static void noop_flush(struct pipe_context *ctx, unsigned flags, + struct pipe_fence_handle **fence) +{ +} + +static void noop_destroy_context(struct pipe_context *ctx) +{ + FREE(ctx); +} + +static struct pipe_context *noop_create_context(struct pipe_screen *screen, void *priv) +{ + struct pipe_context *ctx = CALLOC_STRUCT(pipe_context); + + if (ctx == NULL) + return NULL; + ctx->winsys = screen->winsys; + ctx->screen = screen; + ctx->priv = priv; + ctx->destroy = noop_destroy_context; + ctx->flush = noop_flush; + ctx->clear = noop_clear; + ctx->clear_render_target = noop_clear_render_target; + ctx->clear_depth_stencil = noop_clear_depth_stencil; + ctx->resource_copy_region = noop_resource_copy_region; + ctx->create_query = noop_create_query; + ctx->destroy_query = noop_destroy_query; + ctx->begin_query = noop_begin_query; + ctx->end_query = noop_end_query; + ctx->get_query_result = noop_get_query_result; + ctx->get_transfer = noop_get_transfer; + ctx->transfer_map = noop_transfer_map; + ctx->transfer_flush_region = noop_transfer_flush_region; + ctx->transfer_unmap = noop_transfer_unmap; + ctx->transfer_destroy = noop_transfer_destroy; + ctx->transfer_inline_write = noop_transfer_inline_write; + ctx->is_resource_referenced = noop_is_resource_referenced; + noop_init_state_functions(ctx); + + return ctx; +} + + +/* + * pipe_screen + */ +static void noop_flush_frontbuffer(struct pipe_screen *_screen, + struct pipe_resource *resource, + unsigned level, unsigned layer, + void *context_private) +{ +} + +static const char *noop_get_vendor(struct pipe_screen* pscreen) +{ + return "X.Org"; +} + +static const char *noop_get_name(struct pipe_screen* pscreen) +{ + return "NOOP"; +} + +static int noop_get_param(struct pipe_screen* pscreen, enum pipe_cap param) +{ + switch (param) { + /* Supported features (boolean caps). */ + case PIPE_CAP_NPOT_TEXTURES: + case PIPE_CAP_TWO_SIDED_STENCIL: + case PIPE_CAP_GLSL: + case PIPE_CAP_OCCLUSION_QUERY: + case PIPE_CAP_POINT_SPRITE: + case PIPE_CAP_ANISOTROPIC_FILTER: + case PIPE_CAP_TEXTURE_MIRROR_CLAMP: + case PIPE_CAP_TEXTURE_MIRROR_REPEAT: + case PIPE_CAP_TEXTURE_SHADOW_MAP: + case PIPE_CAP_TEXTURE_SWIZZLE: + case PIPE_CAP_BLEND_EQUATION_SEPARATE: + + return 1; + case PIPE_CAP_DUAL_SOURCE_BLEND: + + case PIPE_CAP_SM3: + case PIPE_CAP_INDEP_BLEND_ENABLE: + case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: + case PIPE_CAP_DEPTH_CLAMP: + case PIPE_CAP_SHADER_STENCIL_EXPORT: + case PIPE_CAP_TIMER_QUERY: + case PIPE_CAP_STREAM_OUTPUT: + case PIPE_CAP_PRIMITIVE_RESTART: + case PIPE_CAP_INDEP_BLEND_FUNC: + return 0; + + /* Texturing. */ + case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: + case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: + case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: + return 14; + case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS: + return 16; + case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: + case PIPE_CAP_MAX_COMBINED_SAMPLERS: + return 16; + + /* Render targets. */ + case PIPE_CAP_MAX_RENDER_TARGETS: + return 8; + + /* Fragment coordinate conventions. */ + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: + return 1; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: + return 0; + + default: + return 0; + } +} + +static float noop_get_paramf(struct pipe_screen* pscreen, enum pipe_cap param) +{ + switch (param) { + case PIPE_CAP_MAX_LINE_WIDTH: + case PIPE_CAP_MAX_LINE_WIDTH_AA: + case PIPE_CAP_MAX_POINT_WIDTH: + case PIPE_CAP_MAX_POINT_WIDTH_AA: + return 8192.0f; + case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: + return 16.0f; + case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: + return 16.0f; + default: + return 0.0f; + } +} + +static int noop_get_shader_param(struct pipe_screen* pscreen, unsigned shader, enum pipe_shader_cap param) +{ + switch(shader) + { + case PIPE_SHADER_FRAGMENT: + case PIPE_SHADER_VERTEX: + case PIPE_SHADER_GEOMETRY: + break; + default: + return 0; + } + + switch (param) { + case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: + return 16384; + case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: + return 8; + case PIPE_SHADER_CAP_MAX_INPUTS: + return 16; + case PIPE_SHADER_CAP_MAX_TEMPS: + return 256; + case PIPE_SHADER_CAP_MAX_ADDRS: + return 1; + case PIPE_SHADER_CAP_MAX_CONSTS: + return 256; + case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: + return 1; + case PIPE_SHADER_CAP_MAX_PREDS: + return 0; + case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: + return 1; + case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: + case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: + return 1; + default: + return 0; + } +} + +static boolean noop_is_format_supported(struct pipe_screen* screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned usage, + unsigned geom_flags) +{ + return true; +} + +static void noop_destroy_screen(struct pipe_screen *screen) +{ + FREE(screen); +} + +struct pipe_screen *noop_screen_create(struct sw_winsys *winsys) +{ + struct pipe_screen *screen; + + screen = CALLOC_STRUCT(pipe_screen); + if (screen == NULL) { + return NULL; + } + + screen->winsys = (struct pipe_winsys*)winsys; + screen->destroy = noop_destroy_screen; + screen->get_name = noop_get_name; + screen->get_vendor = noop_get_vendor; + screen->get_param = noop_get_param; + screen->get_shader_param = noop_get_shader_param; + screen->get_paramf = noop_get_paramf; + screen->is_format_supported = noop_is_format_supported; + screen->context_create = noop_create_context; + screen->resource_create = noop_resource_create; + screen->resource_from_handle = noop_resource_from_handle; + screen->resource_get_handle = noop_resource_get_handle; + screen->resource_destroy = noop_resource_destroy; + screen->user_buffer_create = noop_user_buffer_create; + screen->flush_frontbuffer = noop_flush_frontbuffer; + + return screen; +} diff --git a/src/gallium/drivers/noop/noop_public.h b/src/gallium/drivers/noop/noop_public.h new file mode 100644 index 0000000..8ce82be --- /dev/null +++ b/src/gallium/drivers/noop/noop_public.h @@ -0,0 +1,30 @@ +/* + * Copyright 2010 Red Hat 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 + * 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 NOOP_PUBLIC_H +#define NOOP_PUBLIC_H + +struct sw_winsys; + +struct pipe_screen *noop_screen_create(struct sw_winsys *winsys); + +#endif diff --git a/src/gallium/drivers/noop/noop_state.c b/src/gallium/drivers/noop/noop_state.c new file mode 100644 index 0000000..ad32477 --- /dev/null +++ b/src/gallium/drivers/noop/noop_state.c @@ -0,0 +1,290 @@ +/* + * Copyright 2010 Red Hat 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 + * 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 +#include +#include +#include +#include +#include +#include +#include + +static void noop_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info) +{ +} + +static void noop_set_blend_color(struct pipe_context *ctx, + const struct pipe_blend_color *state) +{ +} + +static void *noop_create_blend_state(struct pipe_context *ctx, + const struct pipe_blend_state *state) +{ + struct pipe_blend_state *nstate = CALLOC_STRUCT(pipe_blend_state); + + if (nstate == NULL) { + return NULL; + } + *nstate = *state; + return nstate; +} + +static void *noop_create_dsa_state(struct pipe_context *ctx, + const struct pipe_depth_stencil_alpha_state *state) +{ + struct pipe_depth_stencil_alpha_state *nstate = CALLOC_STRUCT(pipe_depth_stencil_alpha_state); + + if (nstate == NULL) { + return NULL; + } + *nstate = *state; + return nstate; +} + +static void *noop_create_rs_state(struct pipe_context *ctx, + const struct pipe_rasterizer_state *state) +{ + struct pipe_rasterizer_state *nstate = CALLOC_STRUCT(pipe_rasterizer_state); + + if (nstate == NULL) { + return NULL; + } + *nstate = *state; + return nstate; +} + +static void *noop_create_sampler_state(struct pipe_context *ctx, + const struct pipe_sampler_state *state) +{ + struct pipe_sampler_state *nstate = CALLOC_STRUCT(pipe_sampler_state); + + if (nstate == NULL) { + return NULL; + } + *nstate = *state; + return nstate; +} + +static struct pipe_sampler_view *noop_create_sampler_view(struct pipe_context *ctx, + struct pipe_resource *texture, + const struct pipe_sampler_view *state) +{ + struct pipe_sampler_view *sampler_view = CALLOC_STRUCT(pipe_sampler_view); + + if (sampler_view == NULL) + return NULL; + /* initialize base object */ + pipe_resource_reference(&sampler_view->texture, texture); + pipe_reference_init(&sampler_view->reference, 1); + sampler_view->context = ctx; + return sampler_view; +} + +static struct pipe_surface *noop_create_surface(struct pipe_context *ctx, + struct pipe_resource *texture, + const struct pipe_surface *surf_tmpl) +{ + struct pipe_surface *surface = CALLOC_STRUCT(pipe_surface); + + if (surface == NULL) + return NULL; + pipe_reference_init(&surface->reference, 1); + pipe_resource_reference(&surface->texture, texture); + surface->context = ctx; + surface->format = surf_tmpl->format; + surface->width = texture->width0; + surface->height = texture->height0; + surface->usage = surf_tmpl->usage; + surface->texture = texture; + surface->u.tex.first_layer = surf_tmpl->u.tex.first_layer; + surface->u.tex.last_layer = surf_tmpl->u.tex.last_layer; + surface->u.tex.level = surf_tmpl->u.tex.level; + + return surface; +} +static void noop_set_vs_sampler_view(struct pipe_context *ctx, unsigned count, + struct pipe_sampler_view **views) +{ +} + +static void noop_set_ps_sampler_view(struct pipe_context *ctx, unsigned count, + struct pipe_sampler_view **views) +{ +} + +static void noop_bind_sampler(struct pipe_context *ctx, unsigned count, void **states) +{ +} + +static void noop_set_clip_state(struct pipe_context *ctx, + const struct pipe_clip_state *state) +{ +} + +static void noop_set_polygon_stipple(struct pipe_context *ctx, + const struct pipe_poly_stipple *state) +{ +} + +static void noop_set_sample_mask(struct pipe_context *pipe, unsigned sample_mask) +{ +} + +static void noop_set_scissor_state(struct pipe_context *ctx, + const struct pipe_scissor_state *state) +{ +} + +static void noop_set_stencil_ref(struct pipe_context *ctx, + const struct pipe_stencil_ref *state) +{ +} + +static void noop_set_viewport_state(struct pipe_context *ctx, + const struct pipe_viewport_state *state) +{ +} + +static void noop_set_framebuffer_state(struct pipe_context *ctx, + const struct pipe_framebuffer_state *state) +{ +} + +static void noop_set_constant_buffer(struct pipe_context *ctx, + uint shader, uint index, + struct pipe_resource *buffer) +{ +} + + +static void noop_sampler_view_destroy(struct pipe_context *ctx, + struct pipe_sampler_view *state) +{ + pipe_resource_reference(&state->texture, NULL); + FREE(state); +} + + +static void noop_surface_destroy(struct pipe_context *ctx, + struct pipe_surface *surface) +{ + pipe_resource_reference(&surface->texture, NULL); + FREE(surface); +} + +static void noop_bind_state(struct pipe_context *ctx, void *state) +{ +} + +static void noop_delete_state(struct pipe_context *ctx, void *state) +{ + FREE(state); +} + +static void noop_delete_vertex_element(struct pipe_context *ctx, void *state) +{ + FREE(state); +} + + +static void noop_set_index_buffer(struct pipe_context *ctx, + const struct pipe_index_buffer *ib) +{ +} + +static void noop_set_vertex_buffers(struct pipe_context *ctx, unsigned count, + const struct pipe_vertex_buffer *buffers) +{ +} + +static void *noop_create_vertex_elements(struct pipe_context *ctx, + unsigned count, + const struct pipe_vertex_element *state) +{ + struct pipe_vertex_element *nstate = CALLOC_STRUCT(pipe_vertex_element); + + if (nstate == NULL) { + return NULL; + } + *nstate = *state; + return nstate; +} + +static void *noop_create_shader_state(struct pipe_context *ctx, + const struct pipe_shader_state *state) +{ + struct pipe_shader_state *nstate = CALLOC_STRUCT(pipe_shader_state); + + if (nstate == NULL) { + return NULL; + } + *nstate = *state; + return nstate; +} + +void noop_init_state_functions(struct pipe_context *ctx); + +void noop_init_state_functions(struct pipe_context *ctx) +{ + ctx->create_blend_state = noop_create_blend_state; + ctx->create_depth_stencil_alpha_state = noop_create_dsa_state; + ctx->create_fs_state = noop_create_shader_state; + ctx->create_rasterizer_state = noop_create_rs_state; + ctx->create_sampler_state = noop_create_sampler_state; + ctx->create_sampler_view = noop_create_sampler_view; + ctx->create_surface = noop_create_surface; + ctx->create_vertex_elements_state = noop_create_vertex_elements; + ctx->create_vs_state = noop_create_shader_state; + ctx->bind_blend_state = noop_bind_state; + ctx->bind_depth_stencil_alpha_state = noop_bind_state; + ctx->bind_fragment_sampler_states = noop_bind_sampler; + ctx->bind_fs_state = noop_bind_state; + ctx->bind_rasterizer_state = noop_bind_state; + ctx->bind_vertex_elements_state = noop_bind_state; + ctx->bind_vertex_sampler_states = noop_bind_sampler; + ctx->bind_vs_state = noop_bind_state; + ctx->delete_blend_state = noop_delete_state; + ctx->delete_depth_stencil_alpha_state = noop_delete_state; + ctx->delete_fs_state = noop_delete_state; + ctx->delete_rasterizer_state = noop_delete_state; + ctx->delete_sampler_state = noop_delete_state; + ctx->delete_vertex_elements_state = noop_delete_vertex_element; + ctx->delete_vs_state = noop_delete_state; + ctx->set_blend_color = noop_set_blend_color; + ctx->set_clip_state = noop_set_clip_state; + ctx->set_constant_buffer = noop_set_constant_buffer; + ctx->set_fragment_sampler_views = noop_set_ps_sampler_view; + ctx->set_framebuffer_state = noop_set_framebuffer_state; + ctx->set_polygon_stipple = noop_set_polygon_stipple; + ctx->set_sample_mask = noop_set_sample_mask; + ctx->set_scissor_state = noop_set_scissor_state; + ctx->set_stencil_ref = noop_set_stencil_ref; + ctx->set_vertex_buffers = noop_set_vertex_buffers; + ctx->set_index_buffer = noop_set_index_buffer; + ctx->set_vertex_sampler_views = noop_set_vs_sampler_view; + ctx->set_viewport_state = noop_set_viewport_state; + ctx->sampler_view_destroy = noop_sampler_view_destroy; + ctx->surface_destroy = noop_surface_destroy; + ctx->draw_vbo = noop_draw_vbo; +} diff --git a/src/gallium/drivers/nouveau/Makefile b/src/gallium/drivers/nouveau/Makefile new file mode 100644 index 0000000..db591b7 --- /dev/null +++ b/src/gallium/drivers/nouveau/Makefile @@ -0,0 +1,11 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = nouveau + +LIBRARY_INCLUDES = \ + -I$(TOP)/src/gallium/drivers/nouveau/include + +C_SOURCES = nouveau_screen.c + +include ../../Makefile.template diff --git a/src/gallium/drivers/nouveau/SConscript b/src/gallium/drivers/nouveau/SConscript new file mode 100644 index 0000000..fe7af4d --- /dev/null +++ b/src/gallium/drivers/nouveau/SConscript @@ -0,0 +1,11 @@ +Import('*') + +env = env.Clone() + +nouveau = env.ConvenienceLibrary( + target = 'nouveau', + source = [ + 'nouveau_screen.c', + ]) + +Export('nouveau') diff --git a/src/gallium/drivers/nouveau/nouveau_gldefs.h b/src/gallium/drivers/nouveau/nouveau_gldefs.h new file mode 100644 index 0000000..ff97aaa --- /dev/null +++ b/src/gallium/drivers/nouveau/nouveau_gldefs.h @@ -0,0 +1,196 @@ +#ifndef __NOUVEAU_GLDEFS_H__ +#define __NOUVEAU_GLDEFS_H__ + +static INLINE unsigned +nvgl_blend_func(unsigned factor) +{ + switch (factor) { + case PIPE_BLENDFACTOR_ZERO: + return 0x0000; + case PIPE_BLENDFACTOR_ONE: + return 0x0001; + case PIPE_BLENDFACTOR_SRC_COLOR: + return 0x0300; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + return 0x0301; + case PIPE_BLENDFACTOR_SRC_ALPHA: + return 0x0302; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + return 0x0303; + case PIPE_BLENDFACTOR_DST_ALPHA: + return 0x0304; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + return 0x0305; + case PIPE_BLENDFACTOR_DST_COLOR: + return 0x0306; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + return 0x0307; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + return 0x0308; + case PIPE_BLENDFACTOR_CONST_COLOR: + return 0x8001; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + return 0x8002; + case PIPE_BLENDFACTOR_CONST_ALPHA: + return 0x8003; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + return 0x8004; + default: + return 0x0000; + } +} + +static INLINE unsigned +nvgl_blend_eqn(unsigned func) +{ + switch (func) { + case PIPE_BLEND_ADD: + return 0x8006; + case PIPE_BLEND_MIN: + return 0x8007; + case PIPE_BLEND_MAX: + return 0x8008; + case PIPE_BLEND_SUBTRACT: + return 0x800a; + case PIPE_BLEND_REVERSE_SUBTRACT: + return 0x800b; + default: + return 0x8006; + } +} + +static INLINE unsigned +nvgl_logicop_func(unsigned func) +{ + switch (func) { + case PIPE_LOGICOP_CLEAR: + return 0x1500; + case PIPE_LOGICOP_NOR: + return 0x1508; + case PIPE_LOGICOP_AND_INVERTED: + return 0x1504; + case PIPE_LOGICOP_COPY_INVERTED: + return 0x150c; + case PIPE_LOGICOP_AND_REVERSE: + return 0x1502; + case PIPE_LOGICOP_INVERT: + return 0x150a; + case PIPE_LOGICOP_XOR: + return 0x1506; + case PIPE_LOGICOP_NAND: + return 0x150e; + case PIPE_LOGICOP_AND: + return 0x1501; + case PIPE_LOGICOP_EQUIV: + return 0x1509; + case PIPE_LOGICOP_NOOP: + return 0x1505; + case PIPE_LOGICOP_OR_INVERTED: + return 0x150d; + case PIPE_LOGICOP_COPY: + return 0x1503; + case PIPE_LOGICOP_OR_REVERSE: + return 0x150b; + case PIPE_LOGICOP_OR: + return 0x1507; + case PIPE_LOGICOP_SET: + return 0x150f; + default: + return 0x1505; + } +} + +static INLINE unsigned +nvgl_comparison_op(unsigned op) +{ + switch (op) { + case PIPE_FUNC_NEVER: + return 0x0200; + case PIPE_FUNC_LESS: + return 0x0201; + case PIPE_FUNC_EQUAL: + return 0x0202; + case PIPE_FUNC_LEQUAL: + return 0x0203; + case PIPE_FUNC_GREATER: + return 0x0204; + case PIPE_FUNC_NOTEQUAL: + return 0x0205; + case PIPE_FUNC_GEQUAL: + return 0x0206; + case PIPE_FUNC_ALWAYS: + return 0x0207; + default: + return 0x0207; + } +} + +static INLINE unsigned +nvgl_polygon_mode(unsigned mode) +{ + switch (mode) { + case PIPE_POLYGON_MODE_POINT: + return 0x1b00; + case PIPE_POLYGON_MODE_LINE: + return 0x1b01; + case PIPE_POLYGON_MODE_FILL: + return 0x1b02; + default: + return 0x1b02; + } +} + +static INLINE unsigned +nvgl_stencil_op(unsigned op) +{ + switch (op) { + case PIPE_STENCIL_OP_ZERO: + return 0x0000; + case PIPE_STENCIL_OP_INVERT: + return 0x150a; + case PIPE_STENCIL_OP_KEEP: + return 0x1e00; + case PIPE_STENCIL_OP_REPLACE: + return 0x1e01; + case PIPE_STENCIL_OP_INCR: + return 0x1e02; + case PIPE_STENCIL_OP_DECR: + return 0x1e03; + case PIPE_STENCIL_OP_INCR_WRAP: + return 0x8507; + case PIPE_STENCIL_OP_DECR_WRAP: + return 0x8508; + default: + return 0x1e00; + } +} + +static INLINE unsigned +nvgl_primitive(unsigned prim) { + switch (prim) { + case PIPE_PRIM_POINTS: + return 0x0001; + case PIPE_PRIM_LINES: + return 0x0002; + case PIPE_PRIM_LINE_LOOP: + return 0x0003; + case PIPE_PRIM_LINE_STRIP: + return 0x0004; + case PIPE_PRIM_TRIANGLES: + return 0x0005; + case PIPE_PRIM_TRIANGLE_STRIP: + return 0x0006; + case PIPE_PRIM_TRIANGLE_FAN: + return 0x0007; + case PIPE_PRIM_QUADS: + return 0x0008; + case PIPE_PRIM_QUAD_STRIP: + return 0x0009; + case PIPE_PRIM_POLYGON: + return 0x000a; + default: + return 0; + } +} + +#endif diff --git a/src/gallium/drivers/nouveau/nouveau_screen.c b/src/gallium/drivers/nouveau/nouveau_screen.c new file mode 100644 index 0000000..a9426df --- /dev/null +++ b/src/gallium/drivers/nouveau/nouveau_screen.c @@ -0,0 +1,264 @@ +#include "pipe/p_defines.h" +#include "pipe/p_screen.h" +#include "pipe/p_state.h" + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_format_s3tc.h" +#include "util/u_string.h" + +#include +#include + +#include "nouveau/nouveau_bo.h" +#include "nouveau_winsys.h" +#include "nouveau_screen.h" + +/* XXX this should go away */ +#include "state_tracker/drm_driver.h" +#include "util/u_simple_screen.h" + +static const char * +nouveau_screen_get_name(struct pipe_screen *pscreen) +{ + struct nouveau_device *dev = nouveau_screen(pscreen)->device; + static char buffer[128]; + + util_snprintf(buffer, sizeof(buffer), "NV%02X", dev->chipset); + return buffer; +} + +static const char * +nouveau_screen_get_vendor(struct pipe_screen *pscreen) +{ + return "nouveau"; +} + + + +struct nouveau_bo * +nouveau_screen_bo_new(struct pipe_screen *pscreen, unsigned alignment, + unsigned usage, unsigned bind, unsigned size) +{ + struct nouveau_device *dev = nouveau_screen(pscreen)->device; + struct nouveau_bo *bo = NULL; + uint32_t flags = NOUVEAU_BO_MAP, tile_mode = 0, tile_flags = 0; + int ret; + + if (bind & PIPE_BIND_VERTEX_BUFFER) + flags |= nouveau_screen(pscreen)->vertex_buffer_flags; + else if (bind & PIPE_BIND_INDEX_BUFFER) + flags |= nouveau_screen(pscreen)->index_buffer_flags; + + if (bind & (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DEPTH_STENCIL | + PIPE_BIND_SCANOUT | + PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SAMPLER_VIEW)) + { + /* TODO: this may be incorrect or suboptimal */ + if (!(bind & PIPE_BIND_SCANOUT)) + flags |= NOUVEAU_BO_GART; + if (usage != PIPE_USAGE_DYNAMIC) + flags |= NOUVEAU_BO_VRAM; + + if (dev->chipset == 0x50 || dev->chipset >= 0x80) { + if (bind & PIPE_BIND_DEPTH_STENCIL) + tile_flags = 0x2800; + else + tile_flags = 0x7000; + } + } + + ret = nouveau_bo_new_tile(dev, flags, alignment, size, + tile_mode, tile_flags, &bo); + if (ret) + return NULL; + + return bo; +} + +struct nouveau_bo * +nouveau_screen_bo_user(struct pipe_screen *pscreen, void *ptr, unsigned bytes) +{ + struct nouveau_device *dev = nouveau_screen(pscreen)->device; + struct nouveau_bo *bo = NULL; + int ret; + + ret = nouveau_bo_user(dev, ptr, bytes, &bo); + if (ret) + return NULL; + + return bo; +} + +void * +nouveau_screen_bo_map(struct pipe_screen *pscreen, + struct nouveau_bo *bo, + unsigned map_flags) +{ + int ret; + + ret = nouveau_bo_map(bo, map_flags); + if (ret) { + debug_printf("map failed: %d\n", ret); + return NULL; + } + + return bo->map; +} + +void * +nouveau_screen_bo_map_range(struct pipe_screen *pscreen, struct nouveau_bo *bo, + unsigned offset, unsigned length, unsigned flags) +{ + int ret; + + ret = nouveau_bo_map_range(bo, offset, length, flags); + if (ret) { + nouveau_bo_unmap(bo); + if (!(flags & NOUVEAU_BO_NOWAIT) || ret != -EBUSY) + debug_printf("map_range failed: %d\n", ret); + return NULL; + } + + return (char *)bo->map - offset; /* why gallium? why? */ +} + +void +nouveau_screen_bo_map_flush_range(struct pipe_screen *pscreen, struct nouveau_bo *bo, + unsigned offset, unsigned length) +{ + nouveau_bo_map_flush(bo, offset, length); +} + +void +nouveau_screen_bo_unmap(struct pipe_screen *pscreen, struct nouveau_bo *bo) +{ + nouveau_bo_unmap(bo); +} + +void +nouveau_screen_bo_release(struct pipe_screen *pscreen, struct nouveau_bo *bo) +{ + nouveau_bo_ref(NULL, &bo); +} + +static void +nouveau_screen_fence_ref(struct pipe_screen *pscreen, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *pfence) +{ + *ptr = pfence; +} + +static int +nouveau_screen_fence_signalled(struct pipe_screen *screen, + struct pipe_fence_handle *pfence, + unsigned flags) +{ + return 0; +} + +static int +nouveau_screen_fence_finish(struct pipe_screen *screen, + struct pipe_fence_handle *pfence, + unsigned flags) +{ + return 0; +} + + +struct nouveau_bo * +nouveau_screen_bo_from_handle(struct pipe_screen *pscreen, + struct winsys_handle *whandle, + unsigned *out_stride) +{ + struct nouveau_device *dev = nouveau_screen(pscreen)->device; + struct nouveau_bo *bo = 0; + int ret; + + ret = nouveau_bo_handle_ref(dev, whandle->handle, &bo); + if (ret) { + debug_printf("%s: ref name 0x%08x failed with %d\n", + __FUNCTION__, whandle->handle, ret); + return NULL; + } + + *out_stride = whandle->stride; + return bo; +} + + +boolean +nouveau_screen_bo_get_handle(struct pipe_screen *pscreen, + struct nouveau_bo *bo, + unsigned stride, + struct winsys_handle *whandle) +{ + whandle->stride = stride; + + if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { + return nouveau_bo_handle_get(bo, &whandle->handle) == 0; + } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { + whandle->handle = bo->handle; + return TRUE; + } else { + return FALSE; + } +} + + +unsigned int +nouveau_reference_flags(struct nouveau_bo *bo) +{ + uint32_t bo_flags; + int flags = 0; + + bo_flags = nouveau_bo_pending(bo); + if (bo_flags & NOUVEAU_BO_RD) + flags |= PIPE_REFERENCED_FOR_READ; + if (bo_flags & NOUVEAU_BO_WR) + flags |= PIPE_REFERENCED_FOR_WRITE; + + return flags; +} + + + + + +int +nouveau_screen_init(struct nouveau_screen *screen, struct nouveau_device *dev) +{ + struct pipe_screen *pscreen = &screen->base; + int ret; + + ret = nouveau_channel_alloc(dev, 0xbeef0201, 0xbeef0202, + 512*1024, &screen->channel); + if (ret) + return ret; + screen->device = dev; + + pscreen->get_name = nouveau_screen_get_name; + pscreen->get_vendor = nouveau_screen_get_vendor; + + pscreen->fence_reference = nouveau_screen_fence_ref; + pscreen->fence_signalled = nouveau_screen_fence_signalled; + pscreen->fence_finish = nouveau_screen_fence_finish; + + util_format_s3tc_init(); + + return 0; +} + +void +nouveau_screen_fini(struct nouveau_screen *screen) +{ + struct pipe_winsys *ws = screen->base.winsys; + nouveau_channel_free(&screen->channel); + if (ws) + ws->destroy(ws); +} + diff --git a/src/gallium/drivers/nouveau/nouveau_screen.h b/src/gallium/drivers/nouveau/nouveau_screen.h new file mode 100644 index 0000000..8c29027 --- /dev/null +++ b/src/gallium/drivers/nouveau/nouveau_screen.h @@ -0,0 +1,82 @@ +#ifndef __NOUVEAU_SCREEN_H__ +#define __NOUVEAU_SCREEN_H__ + +#include "pipe/p_screen.h" + +struct nouveau_screen { + struct pipe_screen base; + struct nouveau_device *device; + struct nouveau_channel *channel; + + /* note that OpenGL doesn't distinguish between these, so + * these almost always should be set to the same value */ + unsigned vertex_buffer_flags; + unsigned index_buffer_flags; +}; + +static INLINE struct nouveau_screen * +nouveau_screen(struct pipe_screen *pscreen) +{ + return (struct nouveau_screen *)pscreen; +} + + + +/* Not really sure if this is needed, or whether the individual + * drivers are happy to talk to the bo functions themselves. In a way + * this is what we'd expect from a regular winsys interface. + */ +struct nouveau_bo * +nouveau_screen_bo_new(struct pipe_screen *pscreen, unsigned alignment, + unsigned usage, unsigned bind, unsigned size); +struct nouveau_bo * +nouveau_screen_bo_user(struct pipe_screen *pscreen, void *ptr, unsigned bytes); +void * +nouveau_screen_bo_map(struct pipe_screen *pscreen, + struct nouveau_bo *pb, + unsigned usage); +void * +nouveau_screen_bo_map_range(struct pipe_screen *pscreen, struct nouveau_bo *bo, + unsigned offset, unsigned length, unsigned usage); +void +nouveau_screen_bo_map_flush_range(struct pipe_screen *pscreen, struct nouveau_bo *bo, + unsigned offset, unsigned length); +void +nouveau_screen_bo_unmap(struct pipe_screen *pscreen, struct nouveau_bo *bo); +void +nouveau_screen_bo_release(struct pipe_screen *pscreen, struct nouveau_bo *bo); + +boolean +nouveau_screen_bo_get_handle(struct pipe_screen *pscreen, + struct nouveau_bo *bo, + unsigned stride, + struct winsys_handle *whandle); +struct nouveau_bo * +nouveau_screen_bo_from_handle(struct pipe_screen *pscreen, + struct winsys_handle *whandle, + unsigned *out_stride); + +unsigned int +nouveau_reference_flags(struct nouveau_bo *bo); + + + +int nouveau_screen_init(struct nouveau_screen *, struct nouveau_device *); +void nouveau_screen_fini(struct nouveau_screen *); + + + + +static INLINE unsigned +RING_3D(unsigned mthd, unsigned size) +{ + return (7 << 13) | (size << 18) | mthd; +} + +static INLINE unsigned +RING_3D_NI(unsigned mthd, unsigned size) +{ + return 0x40000000 | (7 << 13) | (size << 18) | mthd; +} + +#endif diff --git a/src/gallium/drivers/nouveau/nouveau_statebuf.h b/src/gallium/drivers/nouveau/nouveau_statebuf.h new file mode 100644 index 0000000..dcffdd9 --- /dev/null +++ b/src/gallium/drivers/nouveau/nouveau_statebuf.h @@ -0,0 +1,27 @@ +#ifndef __NOUVEAU_STATEBUF_H__ +#define __NOUVEAU_STATEBUF_H__ + +/* state buffers: lightweight state objects interface */ +/* relocations are not supported, but Gallium CSOs don't require them */ + +struct nouveau_statebuf_builder +{ + uint32_t* p; +#ifdef DEBUG + uint32_t* pend; +#endif +}; + +#ifdef DEBUG +#define sb_init(var) {var, var + sizeof(var) / sizeof((var)[0])} +#define sb_data(sb, v) do {assert((sb).p != (sb).pend); *(sb).p++ = (v);} while(0) +#else +#define sb_init(var) {var} +#define sb_data(sb, v) *(sb).p++ = (v) +#endif + +#define sb_method(sb, v, n) sb_data(sb, RING_3D(v, n)); + +#define sb_len(sb, var) ((sb).p - (var)) +#define sb_emit(chan, sb_buf, sb_len) do {WAIT_RING((chan), (sb_len)); OUT_RINGp((chan), (sb_buf), (sb_len)); } while(0) +#endif diff --git a/src/gallium/drivers/nouveau/nouveau_stateobj.h b/src/gallium/drivers/nouveau/nouveau_stateobj.h new file mode 100644 index 0000000..e920cf9 --- /dev/null +++ b/src/gallium/drivers/nouveau/nouveau_stateobj.h @@ -0,0 +1,316 @@ +#ifndef __NOUVEAU_STATEOBJ_H__ +#define __NOUVEAU_STATEOBJ_H__ + +#include "util/u_debug.h" + +#ifdef DEBUG +#define DEBUG_NOUVEAU_STATEOBJ +#endif /* DEBUG */ + +struct nouveau_stateobj_reloc { + struct nouveau_bo *bo; + + struct nouveau_grobj *gr; + uint32_t push_offset; + uint32_t mthd; + + uint32_t data; + unsigned flags; + unsigned vor; + unsigned tor; +}; + +struct nouveau_stateobj_start { + struct nouveau_grobj *gr; + uint32_t mthd; + uint32_t size; + unsigned offset; +}; + +struct nouveau_stateobj { + struct pipe_reference reference; + + struct nouveau_stateobj_start *start; + struct nouveau_stateobj_reloc *reloc; + + /* Common memory pool for data. */ + uint32_t *pool; + unsigned pool_cur; + +#ifdef DEBUG_NOUVEAU_STATEOBJ + unsigned start_alloc; + unsigned reloc_alloc; + unsigned pool_alloc; +#endif /* DEBUG_NOUVEAU_STATEOBJ */ + + unsigned total; /* includes begin_ring */ + unsigned cur; /* excludes begin_ring, offset from "cur_start" */ + unsigned cur_start; + unsigned cur_reloc; +}; + +static INLINE void +so_dump(struct nouveau_stateobj *so) +{ + unsigned i, nr, total = 0; + + for (i = 0; i < so->cur_start; i++) { + if (so->start[i].gr->subc > -1) + debug_printf("+0x%04x: 0x%08x\n", total++, + (so->start[i].size << 18) | (so->start[i].gr->subc << 13) + | so->start[i].mthd); + else + debug_printf("+0x%04x: 0x%08x\n", total++, + (so->start[i].size << 18) | so->start[i].mthd); + for (nr = 0; nr < so->start[i].size; nr++, total++) + debug_printf("+0x%04x: 0x%08x\n", total, + so->pool[so->start[i].offset + nr]); + } +} + +static INLINE struct nouveau_stateobj * +so_new(unsigned start, unsigned push, unsigned reloc) +{ + struct nouveau_stateobj *so; + + so = MALLOC(sizeof(struct nouveau_stateobj)); + pipe_reference_init(&so->reference, 1); + so->total = so->cur = so->cur_start = so->cur_reloc = 0; + +#ifdef DEBUG_NOUVEAU_STATEOBJ + so->start_alloc = start; + so->reloc_alloc = reloc; + so->pool_alloc = push; +#endif /* DEBUG_NOUVEAU_STATEOBJ */ + + so->start = MALLOC(start * sizeof(struct nouveau_stateobj_start)); + so->reloc = MALLOC(reloc * sizeof(struct nouveau_stateobj_reloc)); + so->pool = MALLOC(push * sizeof(uint32_t)); + so->pool_cur = 0; + + if (!so->start || !so->reloc || !so->pool) { + debug_printf("malloc failed\n"); + assert(0); + } + + return so; +} + +static INLINE void +so_ref(struct nouveau_stateobj *ref, struct nouveau_stateobj **pso) +{ + struct nouveau_stateobj *so = *pso; + int i; + + if (pipe_reference(&(*pso)->reference, &ref->reference)) { + FREE(so->start); + for (i = 0; i < so->cur_reloc; i++) + nouveau_bo_ref(NULL, &so->reloc[i].bo); + FREE(so->reloc); + FREE(so->pool); + FREE(so); + } + *pso = ref; +} + +static INLINE void +so_data(struct nouveau_stateobj *so, uint32_t data) +{ +#ifdef DEBUG_NOUVEAU_STATEOBJ + if (so->cur >= so->start[so->cur_start - 1].size) { + debug_printf("exceeding specified size\n"); + assert(0); + } +#endif /* DEBUG_NOUVEAU_STATEOBJ */ + + so->pool[so->start[so->cur_start - 1].offset + so->cur++] = data; +} + +static INLINE void +so_datap(struct nouveau_stateobj *so, uint32_t *data, unsigned size) +{ +#ifdef DEBUG_NOUVEAU_STATEOBJ + if ((so->cur + size) > so->start[so->cur_start - 1].size) { + debug_printf("exceeding specified size\n"); + assert(0); + } +#endif /* DEBUG_NOUVEAU_STATEOBJ */ + + while (size--) + so->pool[so->start[so->cur_start - 1].offset + so->cur++] = + *data++; +} + +static INLINE void +so_method(struct nouveau_stateobj *so, struct nouveau_grobj *gr, + unsigned mthd, unsigned size) +{ + struct nouveau_stateobj_start *start; + +#ifdef DEBUG_NOUVEAU_STATEOBJ + if (so->start_alloc <= so->cur_start) { + debug_printf("exceeding num_start size\n"); + assert(0); + } +#endif /* DEBUG_NOUVEAU_STATEOBJ */ + start = so->start; + +#ifdef DEBUG_NOUVEAU_STATEOBJ + if (so->cur_start > 0 && start[so->cur_start - 1].size > so->cur) { + debug_printf("previous so_method was not filled\n"); + assert(0); + } +#endif /* DEBUG_NOUVEAU_STATEOBJ */ + + start[so->cur_start].gr = gr; + start[so->cur_start].mthd = mthd; + start[so->cur_start].size = size; + +#ifdef DEBUG_NOUVEAU_STATEOBJ + if (so->pool_alloc < (size + so->pool_cur)) { + debug_printf("exceeding num_pool size\n"); + assert(0); + } +#endif /* DEBUG_NOUVEAU_STATEOBJ */ + + start[so->cur_start].offset = so->pool_cur; + so->pool_cur += size; + + so->cur_start++; + /* The 1 is for *this* begin_ring. */ + so->total += so->cur + 1; + so->cur = 0; +} + +static INLINE void +so_reloc(struct nouveau_stateobj *so, struct nouveau_bo *bo, + unsigned data, unsigned flags, unsigned vor, unsigned tor) +{ + struct nouveau_stateobj_reloc *r; + +#ifdef DEBUG_NOUVEAU_STATEOBJ + if (so->reloc_alloc <= so->cur_reloc) { + debug_printf("exceeding num_reloc size\n"); + assert(0); + } +#endif /* DEBUG_NOUVEAU_STATEOBJ */ + r = so->reloc; + + r[so->cur_reloc].bo = NULL; + nouveau_bo_ref(bo, &(r[so->cur_reloc].bo)); + r[so->cur_reloc].gr = so->start[so->cur_start-1].gr; + r[so->cur_reloc].push_offset = so->total + so->cur; + r[so->cur_reloc].data = data; + r[so->cur_reloc].flags = flags; + r[so->cur_reloc].mthd = so->start[so->cur_start-1].mthd + + (so->cur << 2); + r[so->cur_reloc].vor = vor; + r[so->cur_reloc].tor = tor; + + so_data(so, data); + so->cur_reloc++; +} + +/* Determine if this buffer object is referenced by this state object. */ +static INLINE boolean +so_bo_is_reloc(struct nouveau_stateobj *so, struct nouveau_bo *bo) +{ + int i; + + for (i = 0; i < so->cur_reloc; i++) + if (so->reloc[i].bo == bo) + return true; + + return false; +} + +static INLINE void +so_emit(struct nouveau_channel *chan, struct nouveau_stateobj *so) +{ + unsigned nr, i; + int ret = 0; + +#ifdef DEBUG_NOUVEAU_STATEOBJ + if (so->start[so->cur_start - 1].size > so->cur) { + debug_printf("emit: previous so_method was not filled\n"); + assert(0); + } +#endif /* DEBUG_NOUVEAU_STATEOBJ */ + + /* We cannot update total in case we so_emit again. */ + nr = so->total + so->cur; + + /* This will flush if we need space. + * We don't actually need the marker. + */ + if ((ret = nouveau_pushbuf_marker_emit(chan, nr, so->cur_reloc))) { + debug_printf("so_emit failed marker emit with error %d\n", ret); + assert(0); + } + + /* Submit data. This will ensure proper binding of objects. */ + for (i = 0; i < so->cur_start; i++) { + BEGIN_RING(chan, so->start[i].gr, so->start[i].mthd, so->start[i].size); + OUT_RINGp(chan, &(so->pool[so->start[i].offset]), so->start[i].size); + } + + for (i = 0; i < so->cur_reloc; i++) { + struct nouveau_stateobj_reloc *r = &so->reloc[i]; + + if ((ret = nouveau_pushbuf_emit_reloc(chan, chan->cur - nr + + r->push_offset, r->bo, r->data, + 0, r->flags, r->vor, r->tor))) { + debug_printf("so_emit failed reloc with error %d\n", ret); + assert(0); + } + } +} + +static INLINE void +so_emit_reloc_markers(struct nouveau_channel *chan, struct nouveau_stateobj *so) +{ + unsigned i; + int ret = 0; + + if (!so) + return; + + /* If we need to flush in flush notify, then we have a problem anyway. */ + for (i = 0; i < so->cur_reloc; i++) { + struct nouveau_stateobj_reloc *r = &so->reloc[i]; + +#ifdef DEBUG_NOUVEAU_STATEOBJ + if (r->mthd & 0x40000000) { + debug_printf("error: NI mthd 0x%08X\n", r->mthd); + continue; + } +#endif /* DEBUG_NOUVEAU_STATEOBJ */ + + /* We don't need to autobind, since there are enough subchannels + * for all objects we use. If this is changed, account for the extra + * space in callers of this function. + */ + assert(r->gr->bound != NOUVEAU_GROBJ_UNBOUND); + + /* Some relocs really don't like to be hammered, + * NOUVEAU_BO_DUMMY makes sure it only + * happens when needed. + */ + ret = OUT_RELOC(chan, r->bo, (r->gr->subc << 13) | (1<< 18) | + r->mthd, (r->flags & (NOUVEAU_BO_VRAM | NOUVEAU_BO_GART + | NOUVEAU_BO_RDWR)) | NOUVEAU_BO_DUMMY, 0, 0); + if (ret) { + debug_printf("OUT_RELOC failed %d\n", ret); + assert(0); + } + + ret = OUT_RELOC(chan, r->bo, r->data, r->flags | + NOUVEAU_BO_DUMMY, r->vor, r->tor); + if (ret) { + debug_printf("OUT_RELOC failed %d\n", ret); + assert(0); + } + } +} + +#endif diff --git a/src/gallium/drivers/nouveau/nouveau_winsys.h b/src/gallium/drivers/nouveau/nouveau_winsys.h new file mode 100644 index 0000000..ab480ca --- /dev/null +++ b/src/gallium/drivers/nouveau/nouveau_winsys.h @@ -0,0 +1,44 @@ +#ifndef NOUVEAU_WINSYS_H +#define NOUVEAU_WINSYS_H + +#include +#include "pipe/p_defines.h" + +#include "nouveau/nouveau_bo.h" +#include "nouveau/nouveau_channel.h" +#include "nouveau/nouveau_device.h" +#include "nouveau/nouveau_grobj.h" +#include "nouveau/nouveau_notifier.h" +#include "nouveau/nouveau_resource.h" +#include "nouveau/nouveau_pushbuf.h" + +#ifndef NV04_PFIFO_MAX_PACKET_LEN +#define NV04_PFIFO_MAX_PACKET_LEN 2047 +#endif + +static INLINE uint32_t +nouveau_screen_transfer_flags(unsigned pipe) +{ + uint32_t flags = 0; + + if (pipe & PIPE_TRANSFER_READ) + flags |= NOUVEAU_BO_RD; + if (pipe & PIPE_TRANSFER_WRITE) + flags |= NOUVEAU_BO_WR; + if (pipe & PIPE_TRANSFER_DISCARD) + flags |= NOUVEAU_BO_INVAL; + if (pipe & PIPE_TRANSFER_UNSYNCHRONIZED) + flags |= NOUVEAU_BO_NOSYNC; + else if (pipe & PIPE_TRANSFER_DONTBLOCK) + flags |= NOUVEAU_BO_NOWAIT; + + return flags; +} + +extern struct pipe_screen * +nvfx_screen_create(struct pipe_winsys *ws, struct nouveau_device *); + +extern struct pipe_screen * +nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *); + +#endif diff --git a/src/gallium/drivers/nouveau/nv_m2mf.xml.h b/src/gallium/drivers/nouveau/nv_m2mf.xml.h new file mode 100644 index 0000000..ffdaf95 --- /dev/null +++ b/src/gallium/drivers/nouveau/nv_m2mf.xml.h @@ -0,0 +1,155 @@ +#ifndef NV_M2MF_XML +#define NV_M2MF_XML + +/* Autogenerated file, DO NOT EDIT manually! + +This file was generated by the rules-ng-ng headergen tool in this git repository: +http://0x04.net/cgit/index.cgi/rules-ng-ng +git clone git://0x04.net/rules-ng-ng + +The rules-ng-ng source files this header was generated from are: +- nv_m2mf.xml ( 2710 bytes, from 2010-08-05 19:38:53) +- copyright.xml ( 6503 bytes, from 2010-04-10 23:15:50) +- nv_object.xml ( 10424 bytes, from 2010-08-05 19:38:53) +- nvchipsets.xml ( 2824 bytes, from 2010-08-05 19:38:53) +- nv_defs.xml ( 4437 bytes, from 2010-08-05 19:38:53) + +Copyright (C) 2006-2010 by the following authors: +- Artur Huillet (ahuillet) +- Ben Skeggs (darktama, darktama_) +- B. R. (koala_br) +- Carlos Martin (carlosmn) +- Christoph Bumiller (calim, chrisbmr) +- Dawid Gajownik (gajownik) +- Dmitry Baryshkov +- Dmitry Eremin-Solenikov (lumag) +- EdB (edb_) +- Erik Waling (erikwaling) +- Francisco Jerez (curro, curro_, currojerez) +- imirkin (imirkin) +- jb17bsome (jb17bsome) +- Jeremy Kolb (kjeremy) +- Laurent Carlier (lordheavy) +- Luca Barbieri (lb, lb1) +- Maarten Maathuis (stillunknown) +- Marcin Kościelnicki (mwk, koriakin) +- Mark Carey (careym) +- Matthieu Castet (mat-c) +- nvidiaman (nvidiaman) +- Patrice Mandin (pmandin, pmdata) +- Pekka Paalanen (pq, ppaalanen) +- Peter Popov (ironpeter) +- Richard Hughes (hughsient) +- Rudi Cilibrasi (cilibrar) +- Serge Martin +- Simon Raffeiner +- Stephane Loeuillet (leroutier) +- Stephane Marchesin (marcheu) +- sturmflut (sturmflut) +- Sylvain Munaut +- Victor Stinner (haypo) +- Wladmir van der Laan (miathan6) +- Younes Manton (ymanton) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + + + +#define NV04_M2MF_DMA_NOTIFY 0x00000180 + +#define NV04_M2MF_DMA_BUFFER_IN 0x00000184 + +#define NV04_M2MF_DMA_BUFFER_OUT 0x00000188 + + +#define NV50_M2MF_LINEAR_IN 0x00000200 + +#define NV50_M2MF_TILING_MODE_IN 0x00000204 + +#define NV50_M2MF_TILING_PITCH_IN 0x00000208 + +#define NV50_M2MF_TILING_HEIGHT_IN 0x0000020c + +#define NV50_M2MF_TILING_DEPTH_IN 0x00000210 + +#define NV50_M2MF_TILING_POSITION_IN_Z 0x00000214 + +#define NV50_M2MF_TILING_POSITION_IN 0x00000218 +#define NV50_M2MF_TILING_POSITION_IN_X__MASK 0x0000ffff +#define NV50_M2MF_TILING_POSITION_IN_X__SHIFT 0 +#define NV50_M2MF_TILING_POSITION_IN_Y__MASK 0xffff0000 +#define NV50_M2MF_TILING_POSITION_IN_Y__SHIFT 16 + +#define NV50_M2MF_LINEAR_OUT 0x0000021c + +#define NV50_M2MF_TILING_MODE_OUT 0x00000220 + +#define NV50_M2MF_TILING_PITCH_OUT 0x00000224 + +#define NV50_M2MF_TILING_HEIGHT_OUT 0x00000228 + +#define NV50_M2MF_TILING_DEPTH_OUT 0x0000022c + +#define NV50_M2MF_TILING_POSITION_OUT_Z 0x00000230 + +#define NV50_M2MF_TILING_POSITION_OUT 0x00000234 +#define NV50_M2MF_TILING_POSITION_OUT_X__MASK 0x0000ffff +#define NV50_M2MF_TILING_POSITION_OUT_X__SHIFT 0 +#define NV50_M2MF_TILING_POSITION_OUT_Y__MASK 0xffff0000 +#define NV50_M2MF_TILING_POSITION_OUT_Y__SHIFT 16 + +#define NV50_M2MF_OFFSET_IN_HIGH 0x00000238 + +#define NV50_M2MF_OFFSET_OUT_HIGH 0x0000023c + +#define NV04_M2MF_OFFSET_IN 0x0000030c + +#define NV04_M2MF_OFFSET_OUT 0x00000310 + +#define NV04_M2MF_PITCH_IN 0x00000314 + +#define NV04_M2MF_PITCH_OUT 0x00000318 + +#define NV04_M2MF_LINE_LENGTH_IN 0x0000031c + +#define NV04_M2MF_LINE_COUNT 0x00000320 + +#define NV04_M2MF_FORMAT 0x00000324 +#define NV04_M2MF_FORMAT_INPUT_INC__MASK 0x000000ff +#define NV04_M2MF_FORMAT_INPUT_INC__SHIFT 0 +#define NV04_M2MF_FORMAT_INPUT_INC_1 0x00000001 +#define NV04_M2MF_FORMAT_INPUT_INC_2 0x00000002 +#define NV04_M2MF_FORMAT_INPUT_INC_4 0x00000004 +#define NV50_M2MF_FORMAT_INPUT_INC_8 0x00000008 +#define NV50_M2MF_FORMAT_INPUT_INC_16 0x00000010 +#define NV04_M2MF_FORMAT_OUTPUT_INC__MASK 0x0000ff00 +#define NV04_M2MF_FORMAT_OUTPUT_INC__SHIFT 8 +#define NV04_M2MF_FORMAT_OUTPUT_INC_1 0x00000100 +#define NV04_M2MF_FORMAT_OUTPUT_INC_2 0x00000200 +#define NV04_M2MF_FORMAT_OUTPUT_INC_4 0x00000400 +#define NV50_M2MF_FORMAT_OUTPUT_INC_8 0x00000800 +#define NV50_M2MF_FORMAT_OUTPUT_INC_16 0x00001000 + +#define NV04_M2MF_BUF_NOTIFY 0x00000328 + + +#endif /* NV_M2MF_XML */ diff --git a/src/gallium/drivers/nouveau/nv_object.xml.h b/src/gallium/drivers/nouveau/nv_object.xml.h new file mode 100644 index 0000000..cb7653c --- /dev/null +++ b/src/gallium/drivers/nouveau/nv_object.xml.h @@ -0,0 +1,231 @@ +#ifndef NV_OBJECT_XML +#define NV_OBJECT_XML + +/* Autogenerated file, DO NOT EDIT manually! + +This file was generated by the rules-ng-ng headergen tool in this git repository: +http://0x04.net/cgit/index.cgi/rules-ng-ng +git clone git://0x04.net/rules-ng-ng + +The rules-ng-ng source files this header was generated from are: +- nv30-40_3d.xml ( 31709 bytes, from 2010-09-05 07:53:14) +- copyright.xml ( 6503 bytes, from 2010-04-10 23:15:50) +- nv_3ddefs.xml ( 15193 bytes, from 2010-09-05 07:50:15) +- nv_defs.xml ( 4437 bytes, from 2010-08-05 19:38:53) +- nv_object.xml ( 10424 bytes, from 2010-08-05 19:38:53) +- nvchipsets.xml ( 2824 bytes, from 2010-08-05 19:38:53) + +Copyright (C) 2006-2010 by the following authors: +- Artur Huillet (ahuillet) +- Ben Skeggs (darktama, darktama_) +- B. R. (koala_br) +- Carlos Martin (carlosmn) +- Christoph Bumiller (calim, chrisbmr) +- Dawid Gajownik (gajownik) +- Dmitry Baryshkov +- Dmitry Eremin-Solenikov (lumag) +- EdB (edb_) +- Erik Waling (erikwaling) +- Francisco Jerez (curro, curro_, currojerez) +- imirkin (imirkin) +- jb17bsome (jb17bsome) +- Jeremy Kolb (kjeremy) +- Laurent Carlier (lordheavy) +- Luca Barbieri (lb, lb1) +- Maarten Maathuis (stillunknown) +- Marcin Kościelnicki (mwk, koriakin) +- Mark Carey (careym) +- Matthieu Castet (mat-c) +- nvidiaman (nvidiaman) +- Patrice Mandin (pmandin, pmdata) +- Pekka Paalanen (pq, ppaalanen) +- Peter Popov (ironpeter) +- Richard Hughes (hughsient) +- Rudi Cilibrasi (cilibrar) +- Serge Martin +- Simon Raffeiner +- Stephane Loeuillet (leroutier) +- Stephane Marchesin (marcheu) +- sturmflut (sturmflut) +- Sylvain Munaut +- Victor Stinner (haypo) +- Wladmir van der Laan (miathan6) +- Younes Manton (ymanton) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + + +#define NV01_ROOT 0x00000001 +#define NV01_CONTEXT_DMA 0x00000002 +#define NV01_DEVICE 0x00000003 +#define NV01_TIMER 0x00000004 +#define NV01_NULL 0x00000030 +#define NV01_MEMORY_LOCAL_BANKED 0x0000003d +#define NV01_MAPPING_SYSTEM 0x0000003e +#define NV03_MEMORY_LOCAL_CURSOR 0x0000003f +#define NV01_MEMORY_LOCAL_LINEAR 0x00000040 +#define NV01_MAPPING_LOCAL 0x00000041 +#define NV03_VIDEO_LUT_CURSOR_DAC 0x00000046 +#define NV03_CHANNEL_PIO 0x0000006a +#define NV03_CHANNEL_DMA 0x0000006b +#define NV10_VIDEO_DISPLAY 0x0000007c +#define NV01_CONTEXT_BETA1 0x00000012 +#define NV04_BETA_SOLID 0x00000072 +#define NV01_CONTEXT_COLOR_KEY 0x00000017 +#define NV04_CONTEXT_COLOR_KEY 0x00000057 +#define NV01_CONTEXT_PATTERN 0x00000018 +#define NV01_CONTEXT_CLIP_RECTANGLE 0x00000019 +#define NV03_CONTEXT_ROP 0x00000043 +#define NV04_IMAGE_PATTERN 0x00000044 +#define NV01_RENDER_SOLID_LINE 0x0000001c +#define NV04_RENDER_SOLID_LINE 0x0000005c +#define NV30_RENDER_SOLID_LINE 0x0000035c +#define NV40_RENDER_SOLID_LINE 0x0000305c +#define NV01_RENDER_SOLID_TRIANGLE 0x0000001d +#define NV04_RENDER_SOLID_TRIANGLE 0x0000005d +#define NV01_RENDER_SOLID_RECTANGLE 0x0000001e +#define NV04_RENDER_SOLID_RECTANGLE 0x0000005e +#define NV01_IMAGE_BLIT 0x0000001f +#define NV04_IMAGE_BLIT 0x0000005f +#define NV11_IMAGE_BLIT 0x0000009f +#define NV01_IMAGE_FROM_CPU 0x00000021 +#define NV04_IMAGE_FROM_CPU 0x00000061 +#define NV05_IMAGE_FROM_CPU 0x00000065 +#define NV10_IMAGE_FROM_CPU 0x0000008a +#define NV30_IMAGE_FROM_CPU 0x0000038a +#define NV40_IMAGE_FROM_CPU 0x0000308a +#define NV03_STRETCHED_IMAGE_FROM_CPU 0x00000036 +#define NV04_STRETCHED_IMAGE_FROM_CPU 0x00000076 +#define NV05_STRETCHED_IMAGE_FROM_CPU 0x00000066 +#define NV30_STRETCHED_IMAGE_FROM_CPU 0x00000366 +#define NV40_STRETCHED_IMAGE_FROM_CPU 0x00003066 +#define NV03_SCALED_IMAGE_FROM_MEMORY 0x00000037 +#define NV04_SCALED_IMAGE_FROM_MEMORY 0x00000077 +#define NV05_SCALED_IMAGE_FROM_MEMORY 0x00000063 +#define NV10_SCALED_IMAGE_FROM_MEMORY 0x00000089 +#define NV30_SCALED_IMAGE_FROM_MEMORY 0x00000389 +#define NV40_SCALED_IMAGE_FROM_MEMORY 0x00003089 +#define NV50_SCALED_IMAGE_FROM_MEMORY 0x00005089 +#define NV04_DVD_SUBPICTURE 0x00000038 +#define NV10_DVD_SUBPICTURE 0x00000088 +#define NV03_GDI_RECTANGLE_TEXT 0x0000004b +#define NV04_GDI_RECTANGLE_TEXT 0x0000004a +#define NV04_SWIZZLED_SURFACE 0x00000052 +#define NV11_SWIZZLED_SURFACE 0x0000009e +#define NV30_SWIZZLED_SURFACE 0x0000039e +#define NV40_SWIZZLED_SURFACE 0x0000309e +#define NV03_CONTEXT_SURFACE_DST 0x00000058 +#define NV03_CONTEXT_SURFACE_SRC 0x00000059 +#define NV04_CONTEXT_SURFACES_2D 0x00000042 +#define NV10_CONTEXT_SURFACES_2D 0x00000062 +#define NV30_CONTEXT_SURFACES_2D 0x00000362 +#define NV40_CONTEXT_SURFACES_2D 0x00003062 +#define NV50_CONTEXT_SURFACES_2D 0x00005062 +#define NV04_INDEXED_IMAGE_FROM_CPU 0x00000060 +#define NV05_INDEXED_IMAGE_FROM_CPU 0x00000064 +#define NV30_INDEXED_IMAGE_FROM_CPU 0x00000364 +#define NV40_INDEXED_IMAGE_FROM_CPU 0x00003064 +#define NV10_TEXTURE_FROM_CPU 0x0000007b +#define NV30_TEXTURE_FROM_CPU 0x0000037b +#define NV40_TEXTURE_FROM_CPU 0x0000307b +#define NV04_M2MF 0x00000039 +#define NV50_M2MF 0x00005039 +#define NVC0_M2MF 0x00009039 +#define NV03_TEXTURED_TRIANGLE 0x00000048 +#define NV04_TEXTURED_TRIANGLE 0x00000054 +#define NV10_TEXTURED_TRIANGLE 0x00000094 +#define NV04_MULTITEX_TRIANGLE 0x00000055 +#define NV10_MULTITEX_TRIANGLE 0x00000095 +#define NV03_CONTEXT_SURFACE_COLOR 0x0000005a +#define NV03_CONTEXT_SURFACE_ZETA 0x0000005b +#define NV04_CONTEXT_SURFACES_3D 0x00000053 +#define NV10_CONTEXT_SURFACES_3D 0x00000093 +#define NV10_3D 0x00000056 +#define NV11_3D 0x00000096 +#define NV17_3D 0x00000099 +#define NV20_3D 0x00000097 +#define NV25_3D 0x00000597 +#define NV30_3D 0x00000397 +#define NV35_3D 0x00000497 +#define NV34_3D 0x00000697 +#define NV40_3D 0x00004097 +#define NV44_3D 0x00004497 +#define NV50_3D 0x00005097 +#define NV84_3D 0x00008297 +#define NVA0_3D 0x00008397 +#define NVA3_3D 0x00008597 +#define NVAF_3D 0x00008697 +#define NVC0_3D 0x00009097 +#define NV50_2D 0x0000502d +#define NVC0_2D 0x0000902d +#define NV50_COMPUTE 0x000050c0 +#define NVA3_COMPUTE 0x000085c0 +#define NVC0_COMPUTE 0x000090c0 +#define NV01_SUBCHAN__SIZE 0x00002000 +#define NV01_SUBCHAN 0x00000000 + +#define NV01_SUBCHAN_OBJECT 0x00000000 + + +#define NV84_SUBCHAN_QUERY_ADDRESS_HIGH 0x00000010 + +#define NV84_SUBCHAN_QUERY_ADDRESS_LOW 0x00000014 + +#define NV84_SUBCHAN_QUERY_COUNTER 0x00000018 + +#define NV84_SUBCHAN_QUERY_GET 0x0000001c + +#define NV84_SUBCHAN_UNK20 0x00000020 + +#define NV84_SUBCHAN_UNK24 0x00000024 + +#define NV10_SUBCHAN_REF_CNT 0x00000050 + + +#define NV11_SUBCHAN_DMA_SEMAPHORE 0x00000060 + +#define NV11_SUBCHAN_SEMAPHORE_OFFSET 0x00000064 + +#define NV11_SUBCHAN_SEMAPHORE_ACQUIRE 0x00000068 + +#define NV11_SUBCHAN_SEMAPHORE_RELEASE 0x0000006c + +#define NV50_SUBCHAN_UNK80 0x00000080 + +#define NV01_GRAPH 0x00000000 + +#define NV04_GRAPH_NOP 0x00000100 + +#define NV01_GRAPH_NOTIFY 0x00000104 +#define NV01_GRAPH_NOTIFY_WRITE 0x00000000 +#define NV01_GRAPH_NOTIFY_WRITE_AND_AWAKEN 0x00000001 + +#define NV50_GRAPH_WAIT_FOR_IDLE 0x00000110 + +#define NVA3_GRAPH_UNK0120 0x00000120 + +#define NVA3_GRAPH_UNK0124 0x00000124 + +#define NV40_GRAPH_PM_TRIGGER 0x00000140 + + +#endif /* NV_OBJECT_XML */ diff --git a/src/gallium/drivers/nv50/Makefile b/src/gallium/drivers/nv50/Makefile new file mode 100644 index 0000000..bf1e820 --- /dev/null +++ b/src/gallium/drivers/nv50/Makefile @@ -0,0 +1,32 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = nv50 + +C_SOURCES = \ + nv50_buffer.c \ + nv50_clear.c \ + nv50_context.c \ + nv50_draw.c \ + nv50_formats.c \ + nv50_miptree.c \ + nv50_query.c \ + nv50_resource.c \ + nv50_screen.c \ + nv50_state.c \ + nv50_state_validate.c \ + nv50_surface.c \ + nv50_tex.c \ + nv50_transfer.c \ + nv50_vbo.c \ + nv50_push.c \ + nv50_program.c \ + nv50_shader_state.c \ + nv50_pc.c \ + nv50_pc_print.c \ + nv50_pc_emit.c \ + nv50_tgsi_to_nc.c \ + nv50_pc_optimize.c \ + nv50_pc_regalloc.c + +include ../../Makefile.template diff --git a/src/gallium/drivers/nv50/SConscript b/src/gallium/drivers/nv50/SConscript new file mode 100644 index 0000000..8e7892a --- /dev/null +++ b/src/gallium/drivers/nv50/SConscript @@ -0,0 +1,34 @@ +Import('*') + +env = env.Clone() + +nv50 = env.ConvenienceLibrary( + target = 'nv50', + source = [ + 'nv50_buffer.c', + 'nv50_clear.c', + 'nv50_context.c', + 'nv50_draw.c', + 'nv50_formats.c', + 'nv50_miptree.c', + 'nv50_query.c', + 'nv50_resource.c', + 'nv50_screen.c', + 'nv50_state.c', + 'nv50_state_validate.c', + 'nv50_surface.c', + 'nv50_tex.c', + 'nv50_transfer.c', + 'nv50_vbo.c', + 'nv50_push.c', + 'nv50_program.c', + 'nv50_shader_state.c', + 'nv50_pc.c', + 'nv50_pc_print.c', + 'nv50_pc_emit.c', + 'nv50_tgsi_to_nc.c', + 'nv50_pc_optimize.c', + 'nv50_pc_regalloc.c', + ]) + +Export('nv50') diff --git a/src/gallium/drivers/nv50/nv50_buffer.c b/src/gallium/drivers/nv50/nv50_buffer.c new file mode 100644 index 0000000..45356f9 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_buffer.c @@ -0,0 +1,151 @@ + +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_math.h" + +#include "nouveau/nouveau_screen.h" +#include "nouveau/nouveau_winsys.h" +#include "nv50_resource.h" + + + +static void nv50_buffer_destroy(struct pipe_screen *pscreen, + struct pipe_resource *presource) +{ + struct nv50_resource *buffer = nv50_resource(presource); + + nouveau_screen_bo_release(pscreen, buffer->bo); + FREE(buffer); +} + + + + +/* Utility functions for transfer create/destroy are hooked in and + * just record the arguments to those functions. + */ +static void * +nv50_buffer_transfer_map( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct nv50_resource *buffer = nv50_resource(transfer->resource); + uint8_t *map; + + map = nouveau_screen_bo_map_range( pipe->screen, + buffer->bo, + transfer->box.x, + transfer->box.width, + nouveau_screen_transfer_flags(transfer->usage) ); + if (map == NULL) + return NULL; + + return map + transfer->box.x; +} + + + +static void nv50_buffer_transfer_flush_region( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box) +{ + struct nv50_resource *buffer = nv50_resource(transfer->resource); + + nouveau_screen_bo_map_flush_range(pipe->screen, + buffer->bo, + transfer->box.x + box->x, + box->width); +} + +static void nv50_buffer_transfer_unmap( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct nv50_resource *buffer = nv50_resource(transfer->resource); + + nouveau_screen_bo_unmap(pipe->screen, buffer->bo); +} + + + + +const struct u_resource_vtbl nv50_buffer_vtbl = +{ + u_default_resource_get_handle, /* get_handle */ + nv50_buffer_destroy, /* resource_destroy */ + NULL, /* is_resource_referenced */ + u_default_get_transfer, /* get_transfer */ + u_default_transfer_destroy, /* transfer_destroy */ + nv50_buffer_transfer_map, /* transfer_map */ + nv50_buffer_transfer_flush_region, /* transfer_flush_region */ + nv50_buffer_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; + + + + +struct pipe_resource * +nv50_buffer_create(struct pipe_screen *pscreen, + const struct pipe_resource *template) +{ + struct nv50_resource *buffer; + + buffer = CALLOC_STRUCT(nv50_resource); + if (!buffer) + return NULL; + + buffer->base = *template; + buffer->vtbl = &nv50_buffer_vtbl; + pipe_reference_init(&buffer->base.reference, 1); + buffer->base.screen = pscreen; + + buffer->bo = nouveau_screen_bo_new(pscreen, + 16, + buffer->base.usage, + buffer->base.bind, + buffer->base.width0); + + if (buffer->bo == NULL) + goto fail; + + return &buffer->base; + +fail: + FREE(buffer); + return NULL; +} + + +struct pipe_resource * +nv50_user_buffer_create(struct pipe_screen *pscreen, + void *ptr, + unsigned bytes, + unsigned bind) +{ + struct nv50_resource *buffer; + + buffer = CALLOC_STRUCT(nv50_resource); + if (!buffer) + return NULL; + + pipe_reference_init(&buffer->base.reference, 1); + buffer->vtbl = &nv50_buffer_vtbl; + buffer->base.screen = pscreen; + buffer->base.format = PIPE_FORMAT_R8_UNORM; + buffer->base.usage = PIPE_USAGE_IMMUTABLE; + buffer->base.bind = bind; + buffer->base.width0 = bytes; + buffer->base.height0 = 1; + buffer->base.depth0 = 1; + buffer->base.array_size = 1; + + buffer->bo = nouveau_screen_bo_user(pscreen, ptr, bytes); + if (!buffer->bo) + goto fail; + + return &buffer->base; + +fail: + FREE(buffer); + return NULL; +} + diff --git a/src/gallium/drivers/nv50/nv50_clear.c b/src/gallium/drivers/nv50/nv50_clear.c new file mode 100644 index 0000000..ee7cf28 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_clear.c @@ -0,0 +1,74 @@ +/* + * Copyright 2008 Ben Skeggs + * + * 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 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_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" + +#include "nv50_context.h" + +void +nv50_clear(struct pipe_context *pipe, unsigned buffers, + const float *rgba, double depth, unsigned stencil) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nouveau_channel *chan = nv50->screen->base.channel; + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct pipe_framebuffer_state *fb = &nv50->framebuffer; + unsigned mode = 0, i; + const unsigned dirty = nv50->dirty; + + /* don't need NEW_BLEND, NV50TCL_COLOR_MASK doesn't affect CLEAR_BUFFERS */ + nv50->dirty &= NV50_NEW_FRAMEBUFFER | NV50_NEW_SCISSOR; + if (!nv50_state_validate(nv50, 64)) + return; + + if (buffers & PIPE_CLEAR_COLOR && fb->nr_cbufs) { + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_COLOR(0), 4); + OUT_RING (chan, fui(rgba[0])); + OUT_RING (chan, fui(rgba[1])); + OUT_RING (chan, fui(rgba[2])); + OUT_RING (chan, fui(rgba[3])); + mode |= 0x3c; + } + + if (buffers & PIPE_CLEAR_DEPTH) { + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_DEPTH, 1); + OUT_RING (chan, fui(depth)); + mode |= NV50TCL_CLEAR_BUFFERS_Z; + } + if (buffers & PIPE_CLEAR_STENCIL) { + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_STENCIL, 1); + OUT_RING (chan, stencil & 0xff); + mode |= NV50TCL_CLEAR_BUFFERS_S; + } + + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_BUFFERS, 1); + OUT_RING (chan, mode); + + for (i = 1; i < fb->nr_cbufs; i++) { + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_BUFFERS, 1); + OUT_RING (chan, (i << 6) | 0x3c); + } + nv50->dirty = dirty; +} + diff --git a/src/gallium/drivers/nv50/nv50_context.c b/src/gallium/drivers/nv50/nv50_context.c new file mode 100644 index 0000000..0874cb5 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_context.c @@ -0,0 +1,102 @@ +/* + * Copyright 2008 Ben Skeggs + * + * 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 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 "draw/draw_context.h" +#include "pipe/p_defines.h" + +#include "nv50_context.h" +#include "nv50_screen.h" +#include "nv50_resource.h" + +static void +nv50_flush(struct pipe_context *pipe, unsigned flags, + struct pipe_fence_handle **fence) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nouveau_channel *chan = nv50->screen->base.channel; + + if (flags & PIPE_FLUSH_TEXTURE_CACHE) { + BEGIN_RING(chan, nv50->screen->tesla, 0x1338, 1); + OUT_RING (chan, 0x20); + } + + if (flags & PIPE_FLUSH_FRAME) + FIRE_RING(chan); +} + +static void +nv50_destroy(struct pipe_context *pipe) +{ + struct nv50_context *nv50 = nv50_context(pipe); + int i; + + for (i = 0; i < 64; i++) { + if (!nv50->state.hw[i]) + continue; + so_ref(NULL, &nv50->state.hw[i]); + } + + draw_destroy(nv50->draw); + + if (nv50->screen->cur_ctx == nv50) + nv50->screen->cur_ctx = NULL; + + FREE(nv50); +} + + +struct pipe_context * +nv50_create(struct pipe_screen *pscreen, void *priv) +{ + struct pipe_winsys *pipe_winsys = pscreen->winsys; + struct nv50_screen *screen = nv50_screen(pscreen); + struct nv50_context *nv50; + + nv50 = CALLOC_STRUCT(nv50_context); + if (!nv50) + return NULL; + nv50->screen = screen; + + nv50->pipe.winsys = pipe_winsys; + nv50->pipe.screen = pscreen; + nv50->pipe.priv = priv; + + nv50->pipe.destroy = nv50_destroy; + + nv50->pipe.draw_vbo = nv50_draw_vbo; + nv50->pipe.clear = nv50_clear; + + nv50->pipe.flush = nv50_flush; + + screen->base.channel->user_private = nv50; + + nv50_init_surface_functions(nv50); + nv50_init_state_functions(nv50); + nv50_init_query_functions(nv50); + nv50_init_resource_functions(&nv50->pipe); + + nv50->draw = draw_create(&nv50->pipe); + assert(nv50->draw); + draw_set_rasterize_stage(nv50->draw, nv50_draw_render_stage(nv50)); + + return &nv50->pipe; +} diff --git a/src/gallium/drivers/nv50/nv50_context.h b/src/gallium/drivers/nv50/nv50_context.h new file mode 100644 index 0000000..b2b0b72 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_context.h @@ -0,0 +1,269 @@ +#ifndef __NV50_CONTEXT_H__ +#define __NV50_CONTEXT_H__ + +#include +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" +#include "pipe/p_compiler.h" + +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_inlines.h" + +#include "draw/draw_vertex.h" + +#include "nouveau/nouveau_winsys.h" +#include "nouveau/nouveau_gldefs.h" +#include "nouveau/nouveau_stateobj.h" +#include "nv50_reg.h" + +#include "nv50_screen.h" +#include "nv50_program.h" + +#define NOUVEAU_ERR(fmt, args...) \ + fprintf(stderr, "%s:%d - "fmt, __FUNCTION__, __LINE__, ##args); +#define NOUVEAU_MSG(fmt, args...) \ + fprintf(stderr, "nouveau: "fmt, ##args); + +#define nouveau_bo_tile_layout(nvbo) \ + ((nvbo)->tile_flags & NOUVEAU_BO_TILE_LAYOUT_MASK) + +/* Constant buffer assignment */ +#define NV50_CB_PMISC 0 +#define NV50_CB_PVP 1 +#define NV50_CB_PFP 2 +#define NV50_CB_PGP 3 +#define NV50_CB_AUX 4 + +#define NV50_NEW_BLEND (1 << 0) +#define NV50_NEW_ZSA (1 << 1) +#define NV50_NEW_BLEND_COLOUR (1 << 2) +#define NV50_NEW_STIPPLE (1 << 3) +#define NV50_NEW_SCISSOR (1 << 4) +#define NV50_NEW_VIEWPORT (1 << 5) +#define NV50_NEW_RASTERIZER (1 << 6) +#define NV50_NEW_FRAMEBUFFER (1 << 7) +#define NV50_NEW_VERTPROG (1 << 8) +#define NV50_NEW_VERTPROG_CB (1 << 9) +#define NV50_NEW_FRAGPROG (1 << 10) +#define NV50_NEW_FRAGPROG_CB (1 << 11) +#define NV50_NEW_GEOMPROG (1 << 12) +#define NV50_NEW_GEOMPROG_CB (1 << 13) +#define NV50_NEW_ARRAYS (1 << 14) +#define NV50_NEW_SAMPLER (1 << 15) +#define NV50_NEW_TEXTURE (1 << 16) +#define NV50_NEW_STENCIL_REF (1 << 17) +#define NV50_NEW_CLIP (1 << 18) + +struct nv50_blend_stateobj { + struct pipe_blend_state pipe; + struct nouveau_stateobj *so; +}; + +struct nv50_zsa_stateobj { + struct pipe_depth_stencil_alpha_state pipe; + struct nouveau_stateobj *so; +}; + +struct nv50_rasterizer_stateobj { + struct pipe_rasterizer_state pipe; + struct nouveau_stateobj *so; +}; + +struct nv50_sampler_stateobj { + boolean normalized; + unsigned tsc[8]; +}; + +struct nv50_sampler_view { + struct pipe_sampler_view pipe; + uint32_t tic[8]; +}; + +struct nv50_vtxelt_stateobj { + struct pipe_vertex_element pipe[16]; + unsigned num_elements; + uint32_t hw[16]; +}; + +static INLINE struct nv50_sampler_view * +nv50_sampler_view(struct pipe_sampler_view *view) +{ + return (struct nv50_sampler_view *)view; +} + +static INLINE unsigned +get_tile_height(uint32_t tile_mode) +{ + return 1 << ((tile_mode & 0xf) + 2); +} + +static INLINE unsigned +get_tile_depth(uint32_t tile_mode) +{ + return 1 << (tile_mode >> 4); +} + + +struct nv50_surface { + struct pipe_surface base; + unsigned offset; +}; + +static INLINE struct nv50_surface * +nv50_surface(struct pipe_surface *pt) +{ + return (struct nv50_surface *)pt; +} + +struct nv50_state { + struct nouveau_stateobj *hw[64]; + uint64_t hw_dirty; + + unsigned sampler_view_nr[3]; + struct nouveau_stateobj *vtxbuf; + struct nouveau_stateobj *vtxattr; + unsigned vtxelt_nr; +}; + +struct nv50_context { + struct pipe_context pipe; + + struct nv50_screen *screen; + + struct draw_context *draw; + + struct nv50_state state; + + unsigned dirty; + struct nv50_blend_stateobj *blend; + struct nv50_zsa_stateobj *zsa; + struct nv50_rasterizer_stateobj *rasterizer; + struct pipe_blend_color blend_colour; + struct pipe_stencil_ref stencil_ref; + struct pipe_poly_stipple stipple; + struct pipe_scissor_state scissor; + struct pipe_viewport_state viewport; + struct pipe_framebuffer_state framebuffer; + struct pipe_clip_state clip; + struct nv50_program *vertprog; + struct nv50_program *fragprog; + struct nv50_program *geomprog; + struct pipe_resource *constbuf[PIPE_SHADER_TYPES]; + struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS]; + unsigned vtxbuf_nr; + struct pipe_index_buffer idxbuf; + struct nv50_vtxelt_stateobj *vtxelt; + struct nv50_sampler_stateobj *sampler[3][PIPE_MAX_SAMPLERS]; + unsigned sampler_nr[3]; + struct pipe_sampler_view *sampler_views[3][PIPE_MAX_SAMPLERS]; + unsigned sampler_view_nr[3]; + + unsigned vbo_fifo; + unsigned req_lmem; +}; + +static INLINE struct nv50_context * +nv50_context(struct pipe_context *pipe) +{ + return (struct nv50_context *)pipe; +} + +extern void nv50_init_surface_functions(struct nv50_context *nv50); +extern void nv50_init_state_functions(struct nv50_context *nv50); +extern void nv50_init_query_functions(struct nv50_context *nv50); +extern void nv50_init_transfer_functions(struct nv50_context *nv50); + +extern void nv50_screen_init_miptree_functions(struct pipe_screen *pscreen); + +extern int +nv50_surface_do_copy(struct nv50_screen *screen, struct pipe_surface *dst, + int dx, int dy, struct pipe_surface *src, int sx, int sy, + int w, int h); + +/* nv50_draw.c */ +extern struct draw_stage *nv50_draw_render_stage(struct nv50_context *nv50); + +/* nv50_vbo.c */ +extern void nv50_draw_vbo(struct pipe_context *pipe, + const struct pipe_draw_info *info); +extern void nv50_vtxelt_construct(struct nv50_vtxelt_stateobj *cso); +extern struct nouveau_stateobj *nv50_vbo_validate(struct nv50_context *nv50); + +/* nv50_push.c */ +extern void +nv50_push_elements_instanced(struct pipe_context *, struct pipe_resource *, + unsigned idxsize, int idxbias, + unsigned mode, unsigned start, + unsigned count, unsigned i_start, + unsigned i_count); + +/* nv50_clear.c */ +extern void nv50_clear(struct pipe_context *pipe, unsigned buffers, + const float *rgba, double depth, unsigned stencil); + +/* nv50_program.c */ +extern struct nouveau_stateobj * +nv50_vertprog_validate(struct nv50_context *nv50); +extern struct nouveau_stateobj * +nv50_fragprog_validate(struct nv50_context *nv50); +extern struct nouveau_stateobj * +nv50_geomprog_validate(struct nv50_context *nv50); +extern struct nouveau_stateobj * +nv50_fp_linkage_validate(struct nv50_context *nv50); +extern struct nouveau_stateobj * +nv50_gp_linkage_validate(struct nv50_context *nv50); +extern void nv50_program_destroy(struct nv50_context *nv50, + struct nv50_program *p); + +/* nv50_state_validate.c */ +extern boolean nv50_state_validate(struct nv50_context *nv50, unsigned dwords); + +extern void nv50_so_init_sifc(struct nv50_context *nv50, + struct nouveau_stateobj *so, + struct nouveau_bo *bo, unsigned reloc, + unsigned offset, unsigned size); + +/* nv50_tex.c */ +extern boolean nv50_tex_construct(struct nv50_sampler_view *view); +extern void nv50_tex_relocs(struct nv50_context *); +extern struct nouveau_stateobj *nv50_tex_validate(struct nv50_context *); + + +/* nv50_context.c */ +struct pipe_context * +nv50_create(struct pipe_screen *pscreen, void *priv); + +static INLINE unsigned +nv50_prim(unsigned mode) +{ + switch (mode) { + case PIPE_PRIM_POINTS: return NV50TCL_VERTEX_BEGIN_POINTS; + case PIPE_PRIM_LINES: return NV50TCL_VERTEX_BEGIN_LINES; + case PIPE_PRIM_LINE_LOOP: return NV50TCL_VERTEX_BEGIN_LINE_LOOP; + case PIPE_PRIM_LINE_STRIP: return NV50TCL_VERTEX_BEGIN_LINE_STRIP; + case PIPE_PRIM_TRIANGLES: return NV50TCL_VERTEX_BEGIN_TRIANGLES; + case PIPE_PRIM_TRIANGLE_STRIP: + return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP; + case PIPE_PRIM_TRIANGLE_FAN: return NV50TCL_VERTEX_BEGIN_TRIANGLE_FAN; + case PIPE_PRIM_QUADS: return NV50TCL_VERTEX_BEGIN_QUADS; + case PIPE_PRIM_QUAD_STRIP: return NV50TCL_VERTEX_BEGIN_QUAD_STRIP; + case PIPE_PRIM_POLYGON: return NV50TCL_VERTEX_BEGIN_POLYGON; + case PIPE_PRIM_LINES_ADJACENCY: + return NV50TCL_VERTEX_BEGIN_LINES_ADJACENCY; + case PIPE_PRIM_LINE_STRIP_ADJACENCY: + return NV50TCL_VERTEX_BEGIN_LINE_STRIP_ADJACENCY; + case PIPE_PRIM_TRIANGLES_ADJACENCY: + return NV50TCL_VERTEX_BEGIN_TRIANGLES_ADJACENCY; + case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY: + return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP_ADJACENCY; + default: + break; + } + + NOUVEAU_ERR("invalid primitive type %d\n", mode); + return NV50TCL_VERTEX_BEGIN_POINTS; +} + +#endif diff --git a/src/gallium/drivers/nv50/nv50_draw.c b/src/gallium/drivers/nv50/nv50_draw.c new file mode 100644 index 0000000..2f6f607 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_draw.c @@ -0,0 +1,89 @@ +/* + * Copyright 2008 Ben Skeggs + * + * 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 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 "draw/draw_pipe.h" + +#include "nv50_context.h" + +struct nv50_render_stage { + struct draw_stage stage; + struct nv50_context *nv50; +}; + +static INLINE struct nv50_render_stage * +nv50_render_stage(struct draw_stage *stage) +{ + return (struct nv50_render_stage *)stage; +} + +static void +nv50_render_point(struct draw_stage *stage, struct prim_header *prim) +{ + NOUVEAU_ERR("\n"); +} + +static void +nv50_render_line(struct draw_stage *stage, struct prim_header *prim) +{ + NOUVEAU_ERR("\n"); +} + +static void +nv50_render_tri(struct draw_stage *stage, struct prim_header *prim) +{ + NOUVEAU_ERR("\n"); +} + +static void +nv50_render_flush(struct draw_stage *stage, unsigned flags) +{ +} + +static void +nv50_render_reset_stipple_counter(struct draw_stage *stage) +{ + NOUVEAU_ERR("\n"); +} + +static void +nv50_render_destroy(struct draw_stage *stage) +{ + FREE(stage); +} + +struct draw_stage * +nv50_draw_render_stage(struct nv50_context *nv50) +{ + struct nv50_render_stage *rs = CALLOC_STRUCT(nv50_render_stage); + + rs->nv50 = nv50; + rs->stage.draw = nv50->draw; + rs->stage.destroy = nv50_render_destroy; + rs->stage.point = nv50_render_point; + rs->stage.line = nv50_render_line; + rs->stage.tri = nv50_render_tri; + rs->stage.flush = nv50_render_flush; + rs->stage.reset_stipple_counter = nv50_render_reset_stipple_counter; + + return &rs->stage; +} + diff --git a/src/gallium/drivers/nv50/nv50_formats.c b/src/gallium/drivers/nv50/nv50_formats.c new file mode 100644 index 0000000..4282809 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_formats.c @@ -0,0 +1,454 @@ +/* + * Copyright 2010 Christoph Bumiller + * + * 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 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 "nv50_screen.h" +#include "nv50_texture.h" +#include "nv50_reg.h" +#include "pipe/p_defines.h" + +#define A_(cr, cg, cb, ca, t0, t1, t2, t3, sz, r) \ + NV50TIC_0_0_MAPR_##cr | NV50TIC_0_0_TYPER_##t0 | \ + NV50TIC_0_0_MAPG_##cg | NV50TIC_0_0_TYPEG_##t1 | \ + NV50TIC_0_0_MAPB_##cb | NV50TIC_0_0_TYPEB_##t2 | \ + NV50TIC_0_0_MAPA_##ca | NV50TIC_0_0_TYPEA_##t3 | \ + NV50TIC_0_0_FMT_##sz, \ + NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_##sz | \ + NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_##t0 | \ + (NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_##t0 << 3) | (r << 31) + +#define B_(cr, cg, cb, ca, t0, t1, t2, t3, sz, r) \ + NV50TIC_0_0_MAPR_##cr | NV50TIC_0_0_TYPER_##t0 | \ + NV50TIC_0_0_MAPG_##cg | NV50TIC_0_0_TYPEG_##t1 | \ + NV50TIC_0_0_MAPB_##cb | NV50TIC_0_0_TYPEB_##t2 | \ + NV50TIC_0_0_MAPA_##ca | NV50TIC_0_0_TYPEA_##t3 | \ + NV50TIC_0_0_FMT_##sz, 0 + +#define VERTEX_BUFFER PIPE_BIND_VERTEX_BUFFER +#define SAMPLER_VIEW PIPE_BIND_SAMPLER_VIEW +#define RENDER_TARGET PIPE_BIND_RENDER_TARGET +#define DEPTH_STENCIL PIPE_BIND_DEPTH_STENCIL +#define SCANOUT PIPE_BIND_SCANOUT + +/* for vertex buffers: */ +#define NV50TIC_0_0_FMT_8_8_8 NV50TIC_0_0_FMT_8_8_8_8 +#define NV50TIC_0_0_FMT_16_16_16 NV50TIC_0_0_FMT_16_16_16_16 +#define NV50TIC_0_0_FMT_32_32_32 NV50TIC_0_0_FMT_32_32_32_32 + +/* NOTE: using NV50_2D_DST_FORMAT for substitute formats used with 2D engine */ + +const struct nv50_format nv50_format_table[PIPE_FORMAT_COUNT] = +{ + /* COMMON FORMATS */ + + [PIPE_FORMAT_B8G8R8A8_UNORM] = { NV50TCL_RT_FORMAT_A8R8G8B8_UNORM, + A_(C2, C1, C0, C3, UNORM, UNORM, UNORM, UNORM, 8_8_8_8, 1), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET | SCANOUT }, + + [PIPE_FORMAT_B8G8R8X8_UNORM] = { NV50TCL_RT_FORMAT_X8R8G8B8_UNORM, + A_(C2, C1, C0, ONE, UNORM, UNORM, UNORM, UNORM, 8_8_8_8, 1), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET | SCANOUT }, + + [PIPE_FORMAT_B8G8R8A8_SRGB] = { NV50TCL_RT_FORMAT_A8R8G8B8_SRGB, + A_(C2, C1, C0, C3, UNORM, UNORM, UNORM, UNORM, 8_8_8_8, 1), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_B8G8R8X8_SRGB] = { NV50TCL_RT_FORMAT_X8R8G8B8_SRGB, + A_(C2, C1, C0, ONE, UNORM, UNORM, UNORM, UNORM, 8_8_8_8, 1), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_B5G6R5_UNORM] = { NV50TCL_RT_FORMAT_R5G6B5_UNORM, + B_(C2, C1, C0, ONE, UNORM, UNORM, UNORM, UNORM, 5_6_5, 1), + SAMPLER_VIEW | RENDER_TARGET | SCANOUT }, + + [PIPE_FORMAT_B5G5R5A1_UNORM] = { NV50TCL_RT_FORMAT_A1R5G5B5_UNORM, + B_(C2, C1, C0, C3, UNORM, UNORM, UNORM, UNORM, 1_5_5_5, 1), + SAMPLER_VIEW | RENDER_TARGET | SCANOUT }, + + [PIPE_FORMAT_B4G4R4A4_UNORM] = { NV50_2D_DST_FORMAT_R16_UNORM, + B_(C2, C1, C0, C3, UNORM, UNORM, UNORM, UNORM, 4_4_4_4, 1), + SAMPLER_VIEW }, + + [PIPE_FORMAT_R10G10B10A2_UNORM] = { NV50TCL_RT_FORMAT_A2B10G10R10_UNORM, + A_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, 2_10_10_10, 0), + SAMPLER_VIEW | RENDER_TARGET | VERTEX_BUFFER | SCANOUT }, + + [PIPE_FORMAT_B10G10R10A2_UNORM] = { NV50TCL_RT_FORMAT_A2R10G10B10_UNORM, + A_(C2, C1, C0, C3, UNORM, UNORM, UNORM, UNORM, 2_10_10_10, 1), + SAMPLER_VIEW | RENDER_TARGET | VERTEX_BUFFER }, + + /* DEPTH/STENCIL FORMATS */ + + [PIPE_FORMAT_Z16_UNORM] = { NV50TCL_ZETA_FORMAT_Z16_UNORM, + B_(C0, C0, C0, ONE, UNORM, UINT, UINT, UINT, 16_DEPTH, 0), + SAMPLER_VIEW | DEPTH_STENCIL }, + + [PIPE_FORMAT_Z24_UNORM_S8_USCALED] = { NV50TCL_ZETA_FORMAT_S8Z24_UNORM, + B_(C0, C0, C0, ONE, UNORM, UINT, UINT, UINT, 8_24, 0), + SAMPLER_VIEW | DEPTH_STENCIL }, + + [PIPE_FORMAT_Z24X8_UNORM] = { NV50TCL_ZETA_FORMAT_X8Z24_UNORM, + B_(C0, C0, C0, ONE, UNORM, UINT, UINT, UINT, 8_24, 0), + SAMPLER_VIEW | DEPTH_STENCIL }, + + [PIPE_FORMAT_S8_USCALED_Z24_UNORM] = { NV50TCL_ZETA_FORMAT_S8Z24_UNORM, + B_(C1, C1, C1, ONE, UINT, UNORM, UINT, UINT, 24_8, 0), + SAMPLER_VIEW | DEPTH_STENCIL }, + + [PIPE_FORMAT_Z32_FLOAT] = { NV50TCL_ZETA_FORMAT_Z32_FLOAT, + B_(C0, C0, C0, ONE, FLOAT, UINT, UINT, UINT, 32_DEPTH, 0), + SAMPLER_VIEW | DEPTH_STENCIL }, + + [PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED] = { + NV50TCL_ZETA_FORMAT_Z32_FLOAT_X24S8_UNORM, + B_(C0, C0, C0, ONE, FLOAT, UINT, UINT, UINT, 32_8, 0), + SAMPLER_VIEW | DEPTH_STENCIL }, + + /* LUMINANCE, ALPHA, INTENSITY */ + + [PIPE_FORMAT_L8_UNORM] = { NV50_2D_DST_FORMAT_R8_UNORM, + A_(C0, C0, C0, ONE, UNORM, UNORM, UNORM, UNORM, 8, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_L8_SRGB] = { NV50_2D_DST_FORMAT_R8_UNORM, + A_(C0, C0, C0, ONE, UNORM, UNORM, UNORM, UNORM, 8, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_I8_UNORM] = { NV50_2D_DST_FORMAT_R8_UNORM, + A_(C0, C0, C0, C0, UNORM, UNORM, UNORM, UNORM, 8, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_A8_UNORM] = { NV50TCL_RT_FORMAT_A8_UNORM, + A_(ZERO, ZERO, ZERO, C0, UNORM, UNORM, UNORM, UNORM, 8, 0), + SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_L8A8_UNORM] = { NV50_2D_DST_FORMAT_R16_UNORM, + A_(C0, C0, C0, C1, UNORM, UNORM, UNORM, UNORM, 8_8, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_L8A8_SRGB] = { 0, + A_(C0, C0, C0, C1, UNORM, UNORM, UNORM, UNORM, 8_8, 0), + SAMPLER_VIEW }, + + /* DXT, RGTC */ + + [PIPE_FORMAT_DXT1_RGB] = { 0, + B_(C0, C1, C2, ONE, UNORM, UNORM, UNORM, UNORM, DXT1, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_DXT1_RGBA] = { 0, + B_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, DXT1, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_DXT3_RGBA] = { 0, + B_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, DXT3, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_DXT5_RGBA] = { 0, + B_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, DXT5, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_RGTC1_UNORM] = { 0, + B_(C0, ZERO, ZERO, ONE, UNORM, UNORM, UNORM, UNORM, RGTC1, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_RGTC1_SNORM] = { 0, + B_(C0, ZERO, ZERO, ONE, SNORM, SNORM, SNORM, SNORM, RGTC1, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_RGTC2_UNORM] = { 0, + B_(C0, C1, ZERO, ONE, UNORM, UNORM, UNORM, UNORM, RGTC2, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_RGTC2_SNORM] = { 0, + B_(C0, C1, ZERO, ONE, SNORM, SNORM, SNORM, SNORM, RGTC2, 0), + SAMPLER_VIEW }, + + /* FLOAT 16 */ + + [PIPE_FORMAT_R16G16B16A16_FLOAT] = { NV50TCL_RT_FORMAT_R16G16B16A16_FLOAT, + A_(C0, C1, C2, C3, FLOAT, FLOAT, FLOAT, FLOAT, 16_16_16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R16G16B16_FLOAT] = { NV50TCL_RT_FORMAT_R16G16B16X16_FLOAT, + A_(C0, C1, C2, ONE, FLOAT, FLOAT, FLOAT, FLOAT, 16_16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R16G16_FLOAT] = { NV50TCL_RT_FORMAT_R16G16_FLOAT, + A_(C0, C1, ZERO, ONE, FLOAT, FLOAT, FLOAT, FLOAT, 16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R16_FLOAT] = { NV50TCL_RT_FORMAT_R16_FLOAT, + A_(C0, ZERO, ZERO, ONE, FLOAT, FLOAT, FLOAT, FLOAT, 16, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + /* FLOAT 32 */ + + [PIPE_FORMAT_R32G32B32A32_FLOAT] = { NV50TCL_RT_FORMAT_R32G32B32A32_FLOAT, + A_(C0, C1, C2, C3, FLOAT, FLOAT, FLOAT, FLOAT, 32_32_32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R32G32B32_FLOAT] = { NV50TCL_RT_FORMAT_R32G32B32X32_FLOAT, + A_(C0, C1, C2, ONE, FLOAT, FLOAT, FLOAT, FLOAT, 32_32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R32G32_FLOAT] = { NV50TCL_RT_FORMAT_R32G32_FLOAT, + A_(C0, C1, ZERO, ONE, FLOAT, FLOAT, FLOAT, FLOAT, 32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R32_FLOAT] = { NV50TCL_RT_FORMAT_R32_FLOAT, + A_(C0, ZERO, ZERO, ONE, FLOAT, FLOAT, FLOAT, FLOAT, 32, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + /* ODD FORMATS */ + + [PIPE_FORMAT_R11G11B10_FLOAT] = { NV50TCL_RT_FORMAT_B10G11R11_FLOAT, + B_(C0, C1, C2, ONE, FLOAT, FLOAT, FLOAT, FLOAT, 10_11_11, 0), + SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R9G9B9E5_FLOAT] = { 0, + B_(C0, C1, C2, ONE, FLOAT, FLOAT, FLOAT, FLOAT, 5_9_9_9, 0), + SAMPLER_VIEW }, + + /* SNORM 32 */ + + [PIPE_FORMAT_R32G32B32A32_SNORM] = { 0, + A_(C0, C1, C2, C3, FLOAT, FLOAT, FLOAT, FLOAT, 32_32_32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R32G32B32_SNORM] = { 0, + A_(C0, C1, C2, ONE, SNORM, SNORM, SNORM, SNORM, 32_32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R32G32_SNORM] = { 0, + A_(C0, C1, ZERO, ONE, SNORM, SNORM, SNORM, SNORM, 32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R32_SNORM] = { 0, + A_(C0, ZERO, ZERO, ONE, SNORM, SNORM, SNORM, SNORM, 32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + /* UNORM 32 */ + + [PIPE_FORMAT_R32G32B32A32_UNORM] = { 0, + A_(C0, C1, C2, C3, FLOAT, FLOAT, FLOAT, FLOAT, 32_32_32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R32G32B32_UNORM] = { 0, + A_(C0, C1, C2, ONE, UNORM, UNORM, UNORM, UNORM, 32_32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R32G32_UNORM] = { 0, + A_(C0, C1, ZERO, ONE, UNORM, UNORM, UNORM, UNORM, 32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R32_UNORM] = { 0, + A_(C0, ZERO, ZERO, ONE, UNORM, UNORM, UNORM, UNORM, 32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + /* SNORM 16 */ + + [PIPE_FORMAT_R16G16B16A16_SNORM] = { NV50TCL_RT_FORMAT_R16G16B16A16_SNORM, + A_(C0, C1, C2, C3, SNORM, SNORM, SNORM, SNORM, 16_16_16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R16G16B16_SNORM] = { 0, + A_(C0, C1, C2, ONE, SNORM, SNORM, SNORM, SNORM, 16_16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R16G16_SNORM] = { NV50TCL_RT_FORMAT_R16G16_SNORM, + A_(C0, C1, C2, C3, SNORM, SNORM, SNORM, SNORM, 16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R16_SNORM] = { NV50TCL_RT_FORMAT_R16_SNORM, + A_(C0, ZERO, ZERO, ONE, SNORM, SNORM, SNORM, SNORM, 16, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + /* UNORM 16 */ + + [PIPE_FORMAT_R16G16B16A16_UNORM] = { NV50TCL_RT_FORMAT_R16G16B16A16_UNORM, + A_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, 16_16_16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R16G16B16_UNORM] = { 0, + A_(C0, C1, C2, ONE, UNORM, UNORM, UNORM, UNORM, 16_16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R16G16_UNORM] = { NV50TCL_RT_FORMAT_R16G16_UNORM, + A_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, 16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R16_UNORM] = { NV50TCL_RT_FORMAT_R16_UNORM, + A_(C0, ZERO, ZERO, ONE, UNORM, UNORM, UNORM, UNORM, 16, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + /* SNORM 8 */ + + [PIPE_FORMAT_R8G8B8A8_SNORM] = { NV50TCL_RT_FORMAT_A8B8G8R8_SNORM, + A_(C0, C1, C2, C3, SNORM, SNORM, SNORM, SNORM, 8_8_8_8, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R8G8B8_SNORM] = { 0, + A_(C0, C1, C2, ONE, SNORM, SNORM, SNORM, SNORM, 8_8_8, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R8G8_SNORM] = { NV50TCL_RT_FORMAT_R8G8_SNORM, + A_(C0, C1, ZERO, ONE, SNORM, SNORM, SNORM, SNORM, 8_8, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R8_SNORM] = { NV50TCL_RT_FORMAT_R8_SNORM, + A_(C0, ZERO, ZERO, ONE, SNORM, SNORM, SNORM, SNORM, 8, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + /* UNORM 8 */ + + [PIPE_FORMAT_R8G8B8A8_UNORM] = { NV50TCL_RT_FORMAT_A8B8G8R8_UNORM, + A_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, 8_8_8_8, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R8G8B8A8_SRGB] = { NV50TCL_RT_FORMAT_A8B8G8R8_SRGB, + A_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, 8_8_8_8, 0), + SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R8G8B8_UNORM] = { NV50TCL_RT_FORMAT_X8B8G8R8_UNORM, + A_(C0, C1, C2, ONE, UNORM, UNORM, UNORM, UNORM, 8_8_8, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R8G8B8_SRGB] = { NV50TCL_RT_FORMAT_X8B8G8R8_SRGB, + A_(C0, C1, C2, ONE, UNORM, UNORM, UNORM, UNORM, 8_8_8, 0), + SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R8G8_UNORM] = { NV50TCL_RT_FORMAT_R8G8_UNORM, + A_(C0, C1, ZERO, ONE, UNORM, UNORM, UNORM, UNORM, 8_8, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_R8_UNORM] = { NV50TCL_RT_FORMAT_R8_UNORM, + A_(C0, ZERO, ZERO, ONE, UNORM, UNORM, UNORM, UNORM, 8, 0), + VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, + + /* SSCALED 32 */ + + [PIPE_FORMAT_R32G32B32A32_SSCALED] = { 0, + A_(C0, C1, C2, C3, SSCALED, SSCALED, SSCALED, SSCALED, 32_32_32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R32G32B32_SSCALED] = { 0, + A_(C0, C1, C2, ONE, SSCALED, SSCALED, SSCALED, SSCALED, 32_32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R32G32_SSCALED] = { 0, + A_(C0, C1, ZERO, ONE, SSCALED, SSCALED, SSCALED, SSCALED, 32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R32_SSCALED] = { 0, + A_(C0, ZERO, ZERO, ONE, SSCALED, SSCALED, SSCALED, SSCALED, 32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + /* USCALED 32 */ + + [PIPE_FORMAT_R32G32B32A32_USCALED] = { 0, + A_(C0, C1, C2, C3, USCALED, USCALED, USCALED, USCALED, 32_32_32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R32G32B32_USCALED] = { 0, + A_(C0, C1, C2, ONE, USCALED, USCALED, USCALED, USCALED, 32_32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R32G32_USCALED] = { 0, + A_(C0, C1, ZERO, ONE, USCALED, USCALED, USCALED, USCALED, 32_32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R32_USCALED] = { 0, + A_(C0, ZERO, ZERO, ONE, USCALED, USCALED, USCALED, USCALED, 32, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + /* SSCALED 16 */ + + [PIPE_FORMAT_R16G16B16A16_SSCALED] = { 0, + A_(C0, C1, C2, C3, SSCALED, SSCALED, SSCALED, SSCALED, 16_16_16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R16G16B16_SSCALED] = { 0, + A_(C0, C1, C2, ONE, SSCALED, SSCALED, SSCALED, SSCALED, 16_16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R16G16_SSCALED] = { 0, + A_(C0, C1, ZERO, ONE, SSCALED, SSCALED, SSCALED, SSCALED, 16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R16_SSCALED] = { 0, + A_(C0, ZERO, ZERO, ONE, SSCALED, SSCALED, SSCALED, SSCALED, 16, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + /* USCALED 16 */ + + [PIPE_FORMAT_R16G16B16A16_USCALED] = { 0, + A_(C0, C1, C2, C3, USCALED, USCALED, USCALED, USCALED, 16_16_16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R16G16B16_USCALED] = { 0, + A_(C0, C1, C2, ONE, USCALED, USCALED, USCALED, USCALED, 16_16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R16G16_USCALED] = { 0, + A_(C0, C1, ZERO, ONE, USCALED, USCALED, USCALED, USCALED, 16_16, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R16_USCALED] = { 0, + A_(C0, ZERO, ZERO, ONE, USCALED, USCALED, USCALED, USCALED, 16, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + /* SSCALED 8 */ + + [PIPE_FORMAT_R8G8B8A8_SSCALED] = { 0, + A_(C0, C1, C2, C3, SSCALED, SSCALED, SSCALED, SSCALED, 8_8_8_8, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R8G8B8_SSCALED] = { 0, + A_(C0, C1, C2, ONE, SSCALED, SSCALED, SSCALED, SSCALED, 8_8_8, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R8G8_SSCALED] = { 0, + A_(C0, C1, ZERO, ONE, SSCALED, SSCALED, SSCALED, SSCALED, 8_8, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R8_SSCALED] = { 0, + A_(C0, ZERO, ZERO, ONE, SSCALED, SSCALED, SSCALED, SSCALED, 8, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + /* USCALED 8 */ + + [PIPE_FORMAT_R8G8B8A8_USCALED] = { 0, + A_(C0, C1, C2, C3, USCALED, USCALED, USCALED, USCALED, 8_8_8_8, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R8G8B8_USCALED] = { 0, + A_(C0, C1, C2, ONE, USCALED, USCALED, USCALED, USCALED, 8_8_8, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R8G8_USCALED] = { 0, + A_(C0, C1, ZERO, ONE, USCALED, USCALED, USCALED, USCALED, 8_8, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, + + [PIPE_FORMAT_R8_USCALED] = { 0, + A_(C0, ZERO, ZERO, ONE, USCALED, USCALED, USCALED, USCALED, 8, 0), + VERTEX_BUFFER | SAMPLER_VIEW }, +}; diff --git a/src/gallium/drivers/nv50/nv50_miptree.c b/src/gallium/drivers/nv50/nv50_miptree.c new file mode 100644 index 0000000..309b650 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_miptree.c @@ -0,0 +1,328 @@ +/* + * Copyright 2008 Ben Skeggs + * + * 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 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_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_format.h" + +#include "nv50_context.h" +#include "nv50_resource.h" +#include "nv50_transfer.h" + +/* The restrictions in tile mode selection probably aren't necessary. */ +static INLINE uint32_t +get_tile_mode(unsigned ny, unsigned d) +{ + uint32_t tile_mode = 0x00; + + if (ny > 32) tile_mode = 0x04; /* height 64 tiles */ + else + if (ny > 16) tile_mode = 0x03; /* height 32 tiles */ + else + if (ny > 8) tile_mode = 0x02; /* height 16 tiles */ + else + if (ny > 4) tile_mode = 0x01; /* height 8 tiles */ + + if (d == 1) + return tile_mode; + else + if (tile_mode > 0x02) + tile_mode = 0x02; + + if (d > 16 && tile_mode < 0x02) + return tile_mode | 0x50; /* depth 32 tiles */ + if (d > 8) return tile_mode | 0x40; /* depth 16 tiles */ + if (d > 4) return tile_mode | 0x30; /* depth 8 tiles */ + if (d > 2) return tile_mode | 0x20; /* depth 4 tiles */ + + return tile_mode | 0x10; +} + +static INLINE unsigned +get_zslice_offset(unsigned tile_mode, unsigned z, unsigned pitch, unsigned nb_h) +{ + unsigned tile_h = get_tile_height(tile_mode); + unsigned tile_d = get_tile_depth(tile_mode); + + /* pitch_2d == to next slice within this volume-tile */ + /* pitch_3d == size (in bytes) of a volume-tile */ + unsigned pitch_2d = tile_h * 64; + unsigned pitch_3d = tile_d * align(nb_h, tile_h) * pitch; + + return (z % tile_d) * pitch_2d + (z / tile_d) * pitch_3d; +} + + + + +static void +nv50_miptree_destroy(struct pipe_screen *pscreen, + struct pipe_resource *pt) +{ + struct nv50_miptree *mt = nv50_miptree(pt); + unsigned l; + + for (l = 0; l <= pt->last_level; ++l) + FREE(mt->level[l].image_offset); + + nouveau_screen_bo_release(pscreen, mt->base.bo); + FREE(mt); +} + +static boolean +nv50_miptree_get_handle(struct pipe_screen *pscreen, + struct pipe_resource *pt, + struct winsys_handle *whandle) +{ + struct nv50_miptree *mt = nv50_miptree(pt); + unsigned stride; + + + if (!mt || !mt->base.bo) + return FALSE; + + stride = util_format_get_stride(mt->base.base.format, + mt->base.base.width0); + + return nouveau_screen_bo_get_handle(pscreen, + mt->base.bo, + stride, + whandle); +} + + +const struct u_resource_vtbl nv50_miptree_vtbl = +{ + nv50_miptree_get_handle, /* get_handle */ + nv50_miptree_destroy, /* resource_destroy */ + NULL, /* is_resource_referenced */ + nv50_miptree_transfer_new, /* get_transfer */ + nv50_miptree_transfer_del, /* transfer_destroy */ + nv50_miptree_transfer_map, /* transfer_map */ + u_default_transfer_flush_region, /* transfer_flush_region */ + nv50_miptree_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; + + + +struct pipe_resource * +nv50_miptree_create(struct pipe_screen *pscreen, const struct pipe_resource *tmp) +{ + struct nouveau_device *dev = nouveau_screen(pscreen)->device; + struct nv50_miptree *mt = CALLOC_STRUCT(nv50_miptree); + struct pipe_resource *pt = &mt->base.base; + unsigned width = tmp->width0, height = tmp->height0; + unsigned depth = tmp->depth0, image_alignment; + uint32_t tile_flags; + int ret, i, l; + + if (!mt) + return NULL; + + *pt = *tmp; + mt->base.vtbl = &nv50_miptree_vtbl; + pipe_reference_init(&pt->reference, 1); + pt->screen = pscreen; + + switch (pt->format) { + case PIPE_FORMAT_Z32_FLOAT: + tile_flags = 0x4800; + break; + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + tile_flags = 0x1800; + break; + case PIPE_FORMAT_Z16_UNORM: + tile_flags = 0x6c00; + break; + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + tile_flags = 0x2800; + break; + case PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED: + tile_flags = 0xe000; + break; + case PIPE_FORMAT_R32G32B32A32_FLOAT: + case PIPE_FORMAT_R32G32B32_FLOAT: + tile_flags = 0x7400; + break; + default: + if ((pt->bind & PIPE_BIND_SCANOUT) && + util_format_get_blocksizebits(pt->format) == 32) + tile_flags = 0x7a00; + else + tile_flags = 0x7000; + break; + } + + /* XXX: texture arrays */ + mt->image_nr = (pt->target == PIPE_TEXTURE_CUBE) ? 6 : 1; + + for (l = 0; l <= pt->last_level; l++) { + struct nv50_miptree_level *lvl = &mt->level[l]; + unsigned nblocksy = util_format_get_nblocksy(pt->format, height); + + lvl->image_offset = CALLOC(mt->image_nr, sizeof(int)); + lvl->pitch = align(util_format_get_stride(pt->format, width), 64); + lvl->tile_mode = get_tile_mode(nblocksy, depth); + + width = u_minify(width, 1); + height = u_minify(height, 1); + depth = u_minify(depth, 1); + } + + image_alignment = get_tile_height(mt->level[0].tile_mode) * 64; + image_alignment *= get_tile_depth(mt->level[0].tile_mode); + + /* NOTE the distinction between arrays of mip-mapped 2D textures and + * mip-mapped 3D textures. We can't use image_nr == depth for 3D mip. + */ + for (i = 0; i < mt->image_nr; i++) { + for (l = 0; l <= pt->last_level; l++) { + struct nv50_miptree_level *lvl = &mt->level[l]; + int size; + unsigned tile_h = get_tile_height(lvl->tile_mode); + unsigned tile_d = get_tile_depth(lvl->tile_mode); + + size = lvl->pitch; + size *= align(util_format_get_nblocksy(pt->format, u_minify(pt->height0, l)), tile_h); + size *= align(u_minify(pt->depth0, l), tile_d); + + lvl->image_offset[i] = mt->total_size; + + mt->total_size += size; + } + mt->total_size = align(mt->total_size, image_alignment); + } + + ret = nouveau_bo_new_tile(dev, NOUVEAU_BO_VRAM, 256, mt->total_size, + mt->level[0].tile_mode, tile_flags, + &mt->base.bo); + if (ret) { + for (l = 0; l <= pt->last_level; ++l) + FREE(mt->level[l].image_offset); + FREE(mt); + return NULL; + } + + return pt; +} + + +struct pipe_resource * +nv50_miptree_from_handle(struct pipe_screen *pscreen, + const struct pipe_resource *template, + struct winsys_handle *whandle) +{ + struct nv50_miptree *mt; + unsigned stride; + + /* Only supports 2D, non-mipmapped textures for the moment */ + if ((template->target != PIPE_TEXTURE_2D && + template->target != PIPE_TEXTURE_RECT) || + template->last_level != 0 || + template->depth0 != 1) + return NULL; + + mt = CALLOC_STRUCT(nv50_miptree); + if (!mt) + return NULL; + + mt->base.bo = nouveau_screen_bo_from_handle(pscreen, whandle, &stride); + if (mt->base.bo == NULL) { + FREE(mt); + return NULL; + } + + + mt->base.base = *template; + mt->base.vtbl = &nv50_miptree_vtbl; + pipe_reference_init(&mt->base.base.reference, 1); + mt->base.base.screen = pscreen; + mt->image_nr = 1; + mt->level[0].pitch = stride; + mt->level[0].image_offset = CALLOC(1, sizeof(unsigned)); + mt->level[0].tile_mode = mt->base.bo->tile_mode; + + /* XXX: Need to adjust bo refcount?? + */ + /* nouveau_bo_ref(bo, &mt->base.bo); */ + return &mt->base.base; +} + + + +/* Surface functions + */ + +struct pipe_surface * +nv50_miptree_surface_new(struct pipe_context *pipe, struct pipe_resource *pt, + const struct pipe_surface *surf_tmpl) +{ + unsigned level = surf_tmpl->u.tex.level; + struct nv50_miptree *mt = nv50_miptree(pt); + struct nv50_miptree_level *lvl = &mt->level[level]; + struct nv50_surface *ns; + unsigned img = 0, zslice = 0; + + assert(surf_tmpl->u.tex.first_layer == surf_tmpl->u.tex.last_layer); + + /* XXX can't unify these here? */ + if (pt->target == PIPE_TEXTURE_CUBE) + img = surf_tmpl->u.tex.first_layer; + else if (pt->target == PIPE_TEXTURE_3D) + zslice = surf_tmpl->u.tex.first_layer; + + ns = CALLOC_STRUCT(nv50_surface); + if (!ns) + return NULL; + pipe_resource_reference(&ns->base.texture, pt); + ns->base.context = pipe; + ns->base.format = pt->format; + ns->base.width = u_minify(pt->width0, level); + ns->base.height = u_minify(pt->height0, level); + ns->base.usage = surf_tmpl->usage; + pipe_reference_init(&ns->base.reference, 1); + ns->base.u.tex.level = level; + ns->base.u.tex.first_layer = surf_tmpl->u.tex.first_layer; + ns->base.u.tex.last_layer = surf_tmpl->u.tex.last_layer; + ns->offset = lvl->image_offset[img]; + + if (pt->target == PIPE_TEXTURE_3D) { + unsigned nb_h = util_format_get_nblocksy(pt->format, ns->base.height); + ns->offset += get_zslice_offset(lvl->tile_mode, zslice, + lvl->pitch, nb_h); + } + + return &ns->base; +} + +void +nv50_miptree_surface_del(struct pipe_context *pipe, + struct pipe_surface *ps) +{ + struct nv50_surface *s = nv50_surface(ps); + + pipe_resource_reference(&s->base.texture, NULL); + FREE(s); +} diff --git a/src/gallium/drivers/nv50/nv50_pc.c b/src/gallium/drivers/nv50/nv50_pc.c new file mode 100644 index 0000000..c88e7ba --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_pc.c @@ -0,0 +1,808 @@ +/* + * Copyright 2010 Christoph Bumiller + * + * 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 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 NV50PC_DEBUG */ + +#include "nv50_pc.h" +#include "nv50_program.h" + +#include + +/* returns TRUE if operands 0 and 1 can be swapped */ +boolean +nv_op_commutative(uint opcode) +{ + switch (opcode) { + case NV_OP_ADD: + case NV_OP_MUL: + case NV_OP_MAD: + case NV_OP_AND: + case NV_OP_OR: + case NV_OP_XOR: + case NV_OP_MIN: + case NV_OP_MAX: + case NV_OP_SAD: + return TRUE; + default: + return FALSE; + } +} + +/* return operand to which the address register applies */ +int +nv50_indirect_opnd(struct nv_instruction *i) +{ + if (!i->src[4]) + return -1; + + switch (i->opcode) { + case NV_OP_MOV: + case NV_OP_LDA: + case NV_OP_STA: + return 0; + default: + return 1; + } +} + +boolean +nv50_nvi_can_use_imm(struct nv_instruction *nvi, int s) +{ + if (nvi->flags_src || nvi->flags_def) + return FALSE; + + switch (nvi->opcode) { + case NV_OP_ADD: + case NV_OP_MUL: + case NV_OP_AND: + case NV_OP_OR: + case NV_OP_XOR: + case NV_OP_SHL: + case NV_OP_SHR: + return (s == 1) && (nvi->src[0]->value->reg.file == NV_FILE_GPR) && + (nvi->def[0]->reg.file == NV_FILE_GPR); + case NV_OP_MOV: + assert(s == 0); + return (nvi->def[0]->reg.file == NV_FILE_GPR); + default: + return FALSE; + } +} + +boolean +nv50_nvi_can_load(struct nv_instruction *nvi, int s, struct nv_value *value) +{ + int i; + + for (i = 0; i < 3 && nvi->src[i]; ++i) + if (nvi->src[i]->value->reg.file == NV_FILE_IMM) + return FALSE; + + switch (nvi->opcode) { + case NV_OP_ABS: + case NV_OP_ADD: + case NV_OP_CEIL: + case NV_OP_FLOOR: + case NV_OP_TRUNC: + case NV_OP_CVT: + case NV_OP_NEG: + case NV_OP_MAD: + case NV_OP_MUL: + case NV_OP_SAT: + case NV_OP_SUB: + case NV_OP_MAX: + case NV_OP_MIN: + if (s == 0 && (value->reg.file == NV_FILE_MEM_S || + value->reg.file == NV_FILE_MEM_P)) + return TRUE; + if (value->reg.file < NV_FILE_MEM_C(0) || + value->reg.file > NV_FILE_MEM_C(15)) + return FALSE; + return (s == 1) || + ((s == 2) && (nvi->src[1]->value->reg.file == NV_FILE_GPR)); + case NV_OP_MOV: + assert(s == 0); + return /* TRUE */ FALSE; /* don't turn MOVs into loads */ + default: + return FALSE; + } +} + +/* Return whether this instruction can be executed conditionally. */ +boolean +nv50_nvi_can_predicate(struct nv_instruction *nvi) +{ + int i; + + if (nvi->flags_src) + return FALSE; + for (i = 0; i < 4 && nvi->src[i]; ++i) + if (nvi->src[i]->value->reg.file == NV_FILE_IMM) + return FALSE; + return TRUE; +} + +ubyte +nv50_supported_src_mods(uint opcode, int s) +{ + switch (opcode) { + case NV_OP_ABS: + return NV_MOD_NEG | NV_MOD_ABS; /* obviously */ + case NV_OP_ADD: + case NV_OP_MUL: + case NV_OP_MAD: + return NV_MOD_NEG; + case NV_OP_DFDX: + case NV_OP_DFDY: + assert(s == 0); + return NV_MOD_NEG; + case NV_OP_MAX: + case NV_OP_MIN: + return NV_MOD_ABS; + case NV_OP_CVT: + case NV_OP_LG2: + case NV_OP_NEG: + case NV_OP_PREEX2: + case NV_OP_PRESIN: + case NV_OP_RCP: + case NV_OP_RSQ: + return NV_MOD_ABS | NV_MOD_NEG; + default: + return 0; + } +} + +/* We may want an opcode table. */ +boolean +nv50_op_can_write_flags(uint opcode) +{ + if (nv_is_vector_op(opcode)) + return FALSE; + switch (opcode) { /* obvious ones like KIL, CALL, etc. not included */ + case NV_OP_PHI: + case NV_OP_MOV: + case NV_OP_LINTERP: + case NV_OP_PINTERP: + case NV_OP_LDA: + return FALSE; + default: + break; + } + if (opcode >= NV_OP_RCP && opcode <= NV_OP_PREEX2) + return FALSE; + return TRUE; +} + +int +nv_nvi_refcount(struct nv_instruction *nvi) +{ + int i, rc; + + rc = nvi->flags_def ? nvi->flags_def->refc : 0; + + for (i = 0; i < 4; ++i) { + if (!nvi->def[i]) + return rc; + rc += nvi->def[i]->refc; + } + return rc; +} + +int +nvcg_replace_value(struct nv_pc *pc, struct nv_value *old_val, + struct nv_value *new_val) +{ + int i, n; + + if (old_val == new_val) + return old_val->refc; + + for (i = 0, n = 0; i < pc->num_refs; ++i) { + if (pc->refs[i]->value == old_val) { + ++n; + nv_reference(pc, &pc->refs[i], new_val); + } + } + return n; +} + +struct nv_value * +nvcg_find_constant(struct nv_ref *ref) +{ + struct nv_value *src; + + if (!ref) + return NULL; + + src = ref->value; + while (src->insn && src->insn->opcode == NV_OP_MOV) { + assert(!src->insn->src[0]->mod); + src = src->insn->src[0]->value; + } + if ((src->reg.file == NV_FILE_IMM) || + (src->insn && src->insn->opcode == NV_OP_LDA && + src->insn->src[0]->value->reg.file >= NV_FILE_MEM_C(0) && + src->insn->src[0]->value->reg.file <= NV_FILE_MEM_C(15))) + return src; + return NULL; +} + +struct nv_value * +nvcg_find_immediate(struct nv_ref *ref) +{ + struct nv_value *src = nvcg_find_constant(ref); + + return (src && src->reg.file == NV_FILE_IMM) ? src : NULL; +} + +static void +nv_pc_free_refs(struct nv_pc *pc) +{ + int i; + for (i = 0; i < pc->num_refs; i += 64) + FREE(pc->refs[i]); + FREE(pc->refs); +} + +static const char * +edge_name(ubyte type) +{ + switch (type) { + case CFG_EDGE_FORWARD: return "forward"; + case CFG_EDGE_BACK: return "back"; + case CFG_EDGE_LOOP_ENTER: return "loop"; + case CFG_EDGE_LOOP_LEAVE: return "break"; + case CFG_EDGE_FAKE: return "fake"; + default: + return "?"; + } +} + +void +nv_pc_pass_in_order(struct nv_basic_block *root, nv_pc_pass_func f, void *priv) +{ + struct nv_basic_block *bb[64], *bbb[16], *b; + int j, p, pp; + + bb[0] = root; + p = 1; + pp = 0; + + while (p > 0) { + b = bb[--p]; + b->priv = 0; + + for (j = 1; j >= 0; --j) { + if (!b->out[j]) + continue; + + switch (b->out_kind[j]) { + case CFG_EDGE_BACK: + continue; + case CFG_EDGE_FORWARD: + case CFG_EDGE_FAKE: + if (++b->out[j]->priv == b->out[j]->num_in) + bb[p++] = b->out[j]; + break; + case CFG_EDGE_LOOP_ENTER: + bb[p++] = b->out[j]; + break; + case CFG_EDGE_LOOP_LEAVE: + bbb[pp++] = b->out[j]; + break; + default: + assert(0); + break; + } + } + + f(priv, b); + + if (!p) { + p = pp; + for (; pp > 0; --pp) + bb[pp - 1] = bbb[pp - 1]; + } + } +} + +static void +nv_do_print_function(void *priv, struct nv_basic_block *b) +{ + struct nv_instruction *i; + + debug_printf("=== BB %i ", b->id); + if (b->out[0]) + debug_printf("[%s -> %i] ", edge_name(b->out_kind[0]), b->out[0]->id); + if (b->out[1]) + debug_printf("[%s -> %i] ", edge_name(b->out_kind[1]), b->out[1]->id); + debug_printf("===\n"); + + i = b->phi; + if (!i) + i = b->entry; + for (; i; i = i->next) + nv_print_instruction(i); +} + +void +nv_print_function(struct nv_basic_block *root) +{ + if (root->subroutine) + debug_printf("SUBROUTINE %i\n", root->subroutine); + else + debug_printf("MAIN\n"); + + nv_pc_pass_in_order(root, nv_do_print_function, root); +} + +void +nv_print_program(struct nv_pc *pc) +{ + int i; + for (i = 0; i < pc->num_subroutines + 1; ++i) + if (pc->root[i]) + nv_print_function(pc->root[i]); +} + +#ifdef NV50PC_DEBUG +static void +nv_do_print_cfgraph(struct nv_pc *pc, FILE *f, struct nv_basic_block *b) +{ + int i; + + b->pass_seq = pc->pass_seq; + + fprintf(f, "\t%i [shape=box]\n", b->id); + + for (i = 0; i < 2; ++i) { + if (!b->out[i]) + continue; + switch (b->out_kind[i]) { + case CFG_EDGE_FORWARD: + fprintf(f, "\t%i -> %i;\n", b->id, b->out[i]->id); + break; + case CFG_EDGE_LOOP_ENTER: + fprintf(f, "\t%i -> %i [color=green];\n", b->id, b->out[i]->id); + break; + case CFG_EDGE_LOOP_LEAVE: + fprintf(f, "\t%i -> %i [color=red];\n", b->id, b->out[i]->id); + break; + case CFG_EDGE_BACK: + fprintf(f, "\t%i -> %i;\n", b->id, b->out[i]->id); + continue; + case CFG_EDGE_FAKE: + fprintf(f, "\t%i -> %i [style=dotted];\n", b->id, b->out[i]->id); + break; + default: + assert(0); + break; + } + if (b->out[i]->pass_seq < pc->pass_seq) + nv_do_print_cfgraph(pc, f, b->out[i]); + } +} + +/* Print the control flow graph of subroutine @subr (0 == MAIN) to a file. */ +static void +nv_print_cfgraph(struct nv_pc *pc, const char *filepath, int subr) +{ + FILE *f; + + f = fopen(filepath, "a"); + if (!f) + return; + + fprintf(f, "digraph G {\n"); + + ++pc->pass_seq; + + nv_do_print_cfgraph(pc, f, pc->root[subr]); + + fprintf(f, "}\n"); + + fclose(f); +} +#endif + +static INLINE void +nvcg_show_bincode(struct nv_pc *pc) +{ + unsigned i; + + for (i = 0; i < pc->bin_size / 4; ++i) { + debug_printf("0x%08x ", pc->emit[i]); + if ((i % 16) == 15) + debug_printf("\n"); + } + debug_printf("\n"); +} + +static int +nv50_emit_program(struct nv_pc *pc) +{ + uint32_t *code = pc->emit; + int n; + + NV50_DBGMSG("emitting program: size = %u\n", pc->bin_size); + + for (n = 0; n < pc->num_blocks; ++n) { + struct nv_instruction *i; + struct nv_basic_block *b = pc->bb_list[n]; + + for (i = b->entry; i; i = i->next) { + nv50_emit_instruction(pc, i); + + pc->bin_pos += 1 + (pc->emit[0] & 1); + pc->emit += 1 + (pc->emit[0] & 1); + } + } + assert(pc->emit == &code[pc->bin_size / 4]); + + /* XXX: we can do better than this ... */ + if (!pc->bin_size || + !(pc->emit[-2] & 1) || (pc->emit[-2] & 2) || (pc->emit[-1] & 3)) { + pc->emit[0] = 0xf0000001; + pc->emit[1] = 0xe0000000; + pc->bin_size += 8; + } + + pc->emit = code; + code[pc->bin_size / 4 - 1] |= 1; + +#ifdef NV50PC_DEBUG + nvcg_show_bincode(pc); +#endif + + return 0; +} + +int +nv50_generate_code(struct nv50_translation_info *ti) +{ + struct nv_pc *pc; + int ret; + int i; + + pc = CALLOC_STRUCT(nv_pc); + if (!pc) + return 1; + + pc->root = CALLOC(ti->subr_nr + 1, sizeof(pc->root[0])); + if (!pc->root) { + FREE(pc); + return 1; + } + pc->num_subroutines = ti->subr_nr; + + ret = nv50_tgsi_to_nc(pc, ti); + if (ret) + goto out; +#ifdef NV50PC_DEBUG + nv_print_program(pc); +#endif + + pc->opt_reload_elim = ti->store_to_memory ? FALSE : TRUE; + + /* optimization */ + ret = nv_pc_exec_pass0(pc); + if (ret) + goto out; +#ifdef NV50PC_DEBUG + nv_print_program(pc); +#endif + + /* register allocation */ + ret = nv_pc_exec_pass1(pc); + if (ret) + goto out; +#ifdef NV50PC_DEBUG + nv_print_program(pc); + nv_print_cfgraph(pc, "nv50_shader_cfgraph.dot", 0); +#endif + + /* prepare for emission */ + ret = nv_pc_exec_pass2(pc); + if (ret) + goto out; + assert(!(pc->bin_size % 8)); + + pc->emit = CALLOC(pc->bin_size / 4 + 2, 4); + if (!pc->emit) { + ret = 3; + goto out; + } + ret = nv50_emit_program(pc); + if (ret) + goto out; + + ti->p->code_size = pc->bin_size; + ti->p->code = pc->emit; + + ti->p->immd_size = pc->immd_count * 4; + ti->p->immd = pc->immd_buf; + + /* highest 16 bit reg to num of 32 bit regs, limit to >= 4 */ + ti->p->max_gpr = MAX2(4, (pc->max_reg[NV_FILE_GPR] >> 1) + 1); + + ti->p->fixups = pc->fixups; + ti->p->num_fixups = pc->num_fixups; + + ti->p->uses_lmem = ti->store_to_memory; + + NV50_DBGMSG("SHADER TRANSLATION - %s\n", ret ? "failure" : "success"); + +out: + nv_pc_free_refs(pc); + + for (i = 0; i < pc->num_blocks; ++i) + FREE(pc->bb_list[i]); + if (pc->root) + FREE(pc->root); + if (ret) { /* on success, these will be referenced by nv50_program */ + if (pc->emit) + FREE(pc->emit); + if (pc->immd_buf) + FREE(pc->immd_buf); + if (pc->fixups) + FREE(pc->fixups); + } + FREE(pc); + return ret; +} + +static void +nvbb_insert_phi(struct nv_basic_block *b, struct nv_instruction *i) +{ + if (!b->phi) { + i->prev = NULL; + b->phi = i; + i->next = b->entry; + if (b->entry) { + assert(!b->entry->prev && b->exit); + b->entry->prev = i; + } else { + b->entry = i; + b->exit = i; + } + } else { + assert(b->entry); + if (b->entry->opcode == NV_OP_PHI) { /* insert after entry */ + assert(b->entry == b->exit); + b->entry->next = i; + i->prev = b->entry; + b->entry = i; + b->exit = i; + } else { /* insert before entry */ + assert(b->entry->prev && b->exit); + i->next = b->entry; + i->prev = b->entry->prev; + b->entry->prev = i; + i->prev->next = i; + } + } +} + +void +nvbb_insert_tail(struct nv_basic_block *b, struct nv_instruction *i) +{ + if (i->opcode == NV_OP_PHI) { + nvbb_insert_phi(b, i); + } else { + i->prev = b->exit; + if (b->exit) + b->exit->next = i; + b->exit = i; + if (!b->entry) + b->entry = i; + else + if (i->prev && i->prev->opcode == NV_OP_PHI) + b->entry = i; + } + + i->bb = b; + b->num_instructions++; +} + +void +nvi_insert_after(struct nv_instruction *at, struct nv_instruction *ni) +{ + if (!at->next) { + nvbb_insert_tail(at->bb, ni); + return; + } + ni->next = at->next; + ni->prev = at; + ni->next->prev = ni; + ni->prev->next = ni; +} + +void +nv_nvi_delete(struct nv_instruction *nvi) +{ + struct nv_basic_block *b = nvi->bb; + int j; + + /* debug_printf("REM: "); nv_print_instruction(nvi); */ + + for (j = 0; j < 5; ++j) + nv_reference(NULL, &nvi->src[j], NULL); + nv_reference(NULL, &nvi->flags_src, NULL); + + if (nvi->next) + nvi->next->prev = nvi->prev; + else { + assert(nvi == b->exit); + b->exit = nvi->prev; + } + + if (nvi->prev) + nvi->prev->next = nvi->next; + + if (nvi == b->entry) { + /* PHIs don't get hooked to b->entry */ + b->entry = nvi->next; + assert(!nvi->prev || nvi->prev->opcode == NV_OP_PHI); + } + + if (nvi == b->phi) { + if (nvi->opcode != NV_OP_PHI) + NV50_DBGMSG("NOTE: b->phi points to non-PHI instruction\n"); + + assert(!nvi->prev); + if (!nvi->next || nvi->next->opcode != NV_OP_PHI) + b->phi = NULL; + else + b->phi = nvi->next; + } +} + +void +nv_nvi_permute(struct nv_instruction *i1, struct nv_instruction *i2) +{ + struct nv_basic_block *b = i1->bb; + + assert(i1->opcode != NV_OP_PHI && + i2->opcode != NV_OP_PHI); + assert(i1->next == i2); + + if (b->exit == i2) + b->exit = i1; + + if (b->entry == i1) + b->entry = i2; + + i2->prev = i1->prev; + i1->next = i2->next; + i2->next = i1; + i1->prev = i2; + + if (i2->prev) + i2->prev->next = i2; + if (i1->next) + i1->next->prev = i1; +} + +void +nvbb_attach_block(struct nv_basic_block *parent, + struct nv_basic_block *b, ubyte edge_kind) +{ + assert(b->num_in < 8); + + if (parent->out[0]) { + assert(!parent->out[1]); + parent->out[1] = b; + parent->out_kind[1] = edge_kind; + } else { + parent->out[0] = b; + parent->out_kind[0] = edge_kind; + } + + b->in[b->num_in] = parent; + b->in_kind[b->num_in++] = edge_kind; +} + +/* NOTE: all BRKs are treated as conditional, so there are 2 outgoing BBs */ + +boolean +nvbb_dominated_by(struct nv_basic_block *b, struct nv_basic_block *d) +{ + int j; + + if (b == d) + return TRUE; + + for (j = 0; j < b->num_in; ++j) + if ((b->in_kind[j] != CFG_EDGE_BACK) && !nvbb_dominated_by(b->in[j], d)) + return FALSE; + + return j ? TRUE : FALSE; +} + +/* check if @bf (future) can be reached from @bp (past), stop at @bt */ +boolean +nvbb_reachable_by(struct nv_basic_block *bf, struct nv_basic_block *bp, + struct nv_basic_block *bt) +{ + struct nv_basic_block *q[NV_PC_MAX_BASIC_BLOCKS], *b; + int i, p, n; + + p = 0; + n = 1; + q[0] = bp; + + while (p < n) { + b = q[p++]; + + if (b == bf) + break; + if (b == bt) + continue; + assert(n <= (1024 - 2)); + + for (i = 0; i < 2; ++i) { + if (b->out[i] && !IS_WALL_EDGE(b->out_kind[i]) && !b->out[i]->priv) { + q[n] = b->out[i]; + q[n++]->priv = 1; + } + } + } + for (--n; n >= 0; --n) + q[n]->priv = 0; + + return (b == bf); +} + +static struct nv_basic_block * +nvbb_find_dom_frontier(struct nv_basic_block *b, struct nv_basic_block *df) +{ + struct nv_basic_block *out; + int i; + + if (!nvbb_dominated_by(df, b)) { + for (i = 0; i < df->num_in; ++i) { + if (df->in_kind[i] == CFG_EDGE_BACK) + continue; + if (nvbb_dominated_by(df->in[i], b)) + return df; + } + } + for (i = 0; i < 2 && df->out[i]; ++i) { + if (df->out_kind[i] == CFG_EDGE_BACK) + continue; + if ((out = nvbb_find_dom_frontier(b, df->out[i]))) + return out; + } + return NULL; +} + +struct nv_basic_block * +nvbb_dom_frontier(struct nv_basic_block *b) +{ + struct nv_basic_block *df; + int i; + + for (i = 0; i < 2 && b->out[i]; ++i) + if ((df = nvbb_find_dom_frontier(b, b->out[i]))) + return df; + return NULL; +} diff --git a/src/gallium/drivers/nv50/nv50_pc.h b/src/gallium/drivers/nv50/nv50_pc.h new file mode 100644 index 0000000..2ead804 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_pc.h @@ -0,0 +1,494 @@ +/* + * Copyright 2010 Christoph Bumiller + * + * 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 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 __NV50_COMPILER_H__ +#define __NV50_COMPILER_H__ + +#ifdef NV50PC_DEBUG +# define NV50_DBGMSG(args...) debug_printf(args) +#else +# define NV50_DBGMSG(args...) +#endif + +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" + +#define NV_OP_PHI 0 +#define NV_OP_EXTRACT 1 +#define NV_OP_COMBINE 2 +#define NV_OP_LDA 3 +#define NV_OP_STA 4 +#define NV_OP_MOV 5 +#define NV_OP_ADD 6 +#define NV_OP_SUB 7 +#define NV_OP_NEG 8 +#define NV_OP_MUL 9 +#define NV_OP_MAD 10 +#define NV_OP_CVT 11 +#define NV_OP_SAT 12 +#define NV_OP_NOT 13 +#define NV_OP_AND 14 +#define NV_OP_OR 15 +#define NV_OP_XOR 16 +#define NV_OP_SHL 17 +#define NV_OP_SHR 18 +#define NV_OP_RCP 19 +#define NV_OP_UNDEF 20 +#define NV_OP_RSQ 21 +#define NV_OP_LG2 22 +#define NV_OP_SIN 23 +#define NV_OP_COS 24 +#define NV_OP_EX2 25 +#define NV_OP_PRESIN 26 +#define NV_OP_PREEX2 27 +#define NV_OP_MIN 28 +#define NV_OP_MAX 29 +#define NV_OP_SET 30 +#define NV_OP_SAD 31 +#define NV_OP_KIL 32 +#define NV_OP_BRA 33 +#define NV_OP_CALL 34 +#define NV_OP_RET 35 +#define NV_OP_BREAK 36 +#define NV_OP_BREAKADDR 37 +#define NV_OP_JOINAT 38 +#define NV_OP_TEX 39 +#define NV_OP_TXB 40 +#define NV_OP_TXL 41 +#define NV_OP_TXF 42 +#define NV_OP_TXQ 43 +#define NV_OP_DFDX 44 +#define NV_OP_DFDY 45 +#define NV_OP_QUADOP 46 +#define NV_OP_LINTERP 47 +#define NV_OP_PINTERP 48 +#define NV_OP_ABS 49 +#define NV_OP_CEIL 50 +#define NV_OP_FLOOR 51 +#define NV_OP_TRUNC 52 +#define NV_OP_NOP 53 +#define NV_OP_SELECT 54 +#define NV_OP_EXPORT 55 +#define NV_OP_JOIN 56 +#define NV_OP_COUNT 57 + +#define NV_FILE_GPR 0 +#define NV_FILE_OUT 1 +#define NV_FILE_ADDR 2 +#define NV_FILE_FLAGS 3 +#define NV_FILE_IMM 16 +#define NV_FILE_MEM_S 32 +#define NV_FILE_MEM_P 33 +#define NV_FILE_MEM_V 34 +#define NV_FILE_MEM_L 48 +#define NV_FILE_MEM_G(i) (64 + i) +#define NV_FILE_MEM_C(i) (80 + i) + +#define NV_MOD_NEG 1 +#define NV_MOD_ABS 2 +#define NV_MOD_NOT 4 +#define NV_MOD_SAT 8 + +#define NV_TYPE_U8 0x00 +#define NV_TYPE_S8 0x01 +#define NV_TYPE_U16 0x02 +#define NV_TYPE_S16 0x03 +#define NV_TYPE_U32 0x04 +#define NV_TYPE_S32 0x05 +#define NV_TYPE_P32 0x07 +#define NV_TYPE_F32 0x09 +#define NV_TYPE_F64 0x0b +#define NV_TYPE_VEC(x, n) (NV_TYPE_##x | (n << 4)) +#define NV_TYPE_LO 0x00 +#define NV_TYPE_HI 0x80 +#define NV_TYPE_ANY 0xff + +#define NV_TYPE_ISINT(t) ((t) <= 5) +#define NV_TYPE_ISFLT(t) ((t) & 0x08) + +/* $cX registers contain 4 bits: OCSZ (Z is bit 0) */ +#define NV_CC_FL 0x0 +#define NV_CC_LT 0x1 +#define NV_CC_EQ 0x2 +#define NV_CC_LE 0x3 +#define NV_CC_GT 0x4 +#define NV_CC_NE 0x5 +#define NV_CC_GE 0x6 +#define NV_CC_U 0x8 +#define NV_CC_TR 0xf +#define NV_CC_O 0x10 +#define NV_CC_C 0x11 +#define NV_CC_A 0x12 +#define NV_CC_S 0x13 + +#define NV_PC_MAX_INSTRUCTIONS 2048 +#define NV_PC_MAX_VALUES (NV_PC_MAX_INSTRUCTIONS * 4) + +#define NV_PC_MAX_BASIC_BLOCKS 1024 + +static INLINE boolean +nv_is_vector_op(uint opcode) +{ + return (opcode >= NV_OP_TEX) && (opcode <= NV_OP_TXQ); +} + +static INLINE uint +nv_type_order(ubyte type) +{ + switch (type & 0xf) { + case NV_TYPE_U8: + case NV_TYPE_S8: + return 0; + case NV_TYPE_U16: + case NV_TYPE_S16: + return 1; + case NV_TYPE_U32: + case NV_TYPE_F32: + case NV_TYPE_S32: + case NV_TYPE_P32: + return 2; + case NV_TYPE_F64: + return 3; + } + assert(0); + return 0; +} + +static INLINE uint +nv_type_sizeof(ubyte type) +{ + if (type & 0xf0) + return (1 << nv_type_order(type)) * (type >> 4); + return 1 << nv_type_order(type); +} + +static INLINE uint +nv_type_sizeof_base(ubyte type) +{ + return 1 << nv_type_order(type); +} + +struct nv_reg { + int id; + ubyte file; + ubyte type; /* type of generating instruction's result */ + ubyte as_type; /* default type for new references to this value */ + union { + float f32; + double f64; + int32_t s32; + uint32_t u32; + } imm; +}; + +struct nv_range { + struct nv_range *next; + int bgn; + int end; +}; + +struct nv_value { + struct nv_reg reg; + struct nv_instruction *insn; + struct nv_value *join; + int n; + struct nv_range *livei; + int refc; + + struct nv_value *next; + struct nv_value *prev; +}; + +struct nv_ref { + struct nv_value *value; + ubyte mod; + ubyte typecast; + ubyte flags; /* not used yet */ +}; + +struct nv_basic_block; + +struct nv_instruction { + struct nv_instruction *next; + struct nv_instruction *prev; + uint opcode; + int serial; + struct nv_value *def[4]; + struct nv_value *flags_def; + struct nv_ref *src[5]; + struct nv_ref *flags_src; + struct nv_basic_block *bb; + struct nv_basic_block *target; /* target block of control flow insn */ + ubyte cc; + unsigned set_cond : 4; + unsigned fixed : 1; /* don't optimize away */ + unsigned is_terminator : 1; + unsigned is_join : 1; + unsigned is_long : 1; /* for emission */ + /* */ + unsigned saturate : 1; + unsigned centroid : 1; + unsigned flat : 1; + unsigned lanes : 4; + unsigned tex_live : 1; + /* */ + ubyte tex_t; /* TIC binding */ + ubyte tex_s; /* TSC binding */ + unsigned tex_argc : 3; + unsigned tex_cube : 1; + unsigned tex_mask : 4; + /* */ + ubyte quadop; +}; + +#define CFG_EDGE_FORWARD 0 +#define CFG_EDGE_BACK 1 +#define CFG_EDGE_LOOP_ENTER 2 +#define CFG_EDGE_LOOP_LEAVE 4 +#define CFG_EDGE_FAKE 8 + +/* 'WALL' edge means where reachability check doesn't follow */ +/* 'LOOP' edge means just having to do with loops */ +#define IS_LOOP_EDGE(k) ((k) & 7) +#define IS_WALL_EDGE(k) ((k) & 9) + +struct nv_basic_block { + struct nv_instruction *entry; /* first non-phi instruction */ + struct nv_instruction *exit; + struct nv_instruction *phi; /* very first instruction */ + int num_instructions; + + struct nv_basic_block *out[2]; /* no indirect branches -> 2 */ + struct nv_basic_block *in[8]; /* hope that suffices */ + uint num_in; + ubyte out_kind[2]; + ubyte in_kind[8]; + + int id; + int subroutine; + uint priv; /* reset to 0 after you're done */ + uint pass_seq; + + uint32_t bin_pos; /* position, size in emitted code */ + uint32_t bin_size; + + uint32_t live_set[NV_PC_MAX_VALUES / 32]; +}; + +struct nv50_translation_info; + +struct nv_pc { + struct nv_basic_block **root; + struct nv_basic_block *current_block; + struct nv_basic_block *parent_block; + + int loop_nesting_bound; + uint pass_seq; + + struct nv_value values[NV_PC_MAX_VALUES]; + struct nv_instruction instructions[NV_PC_MAX_INSTRUCTIONS]; + struct nv_ref **refs; + struct nv_basic_block *bb_list[NV_PC_MAX_BASIC_BLOCKS]; + int num_values; + int num_instructions; + int num_refs; + int num_blocks; + int num_subroutines; + + int max_reg[4]; + + uint32_t *immd_buf; /* populated on emit */ + unsigned immd_count; + + uint32_t *emit; + unsigned bin_size; + unsigned bin_pos; + + void *fixups; + unsigned num_fixups; + + /* optimization enables */ + boolean opt_reload_elim; +}; + +void nvbb_insert_tail(struct nv_basic_block *, struct nv_instruction *); +void nvi_insert_after(struct nv_instruction *, struct nv_instruction *); + +static INLINE struct nv_instruction * +nv_alloc_instruction(struct nv_pc *pc, uint opcode) +{ + struct nv_instruction *insn; + + insn = &pc->instructions[pc->num_instructions++]; + assert(pc->num_instructions < NV_PC_MAX_INSTRUCTIONS); + + insn->cc = NV_CC_TR; + insn->opcode = opcode; + + return insn; +} + +static INLINE struct nv_instruction * +new_instruction(struct nv_pc *pc, uint opcode) +{ + struct nv_instruction *insn = nv_alloc_instruction(pc, opcode); + + nvbb_insert_tail(pc->current_block, insn); + return insn; +} + +static INLINE struct nv_instruction * +new_instruction_at(struct nv_pc *pc, struct nv_instruction *at, uint opcode) +{ + struct nv_instruction *insn = nv_alloc_instruction(pc, opcode); + + nvi_insert_after(at, insn); + return insn; +} + +static INLINE struct nv_value * +new_value(struct nv_pc *pc, ubyte file, ubyte type) +{ + struct nv_value *value = &pc->values[pc->num_values]; + + assert(pc->num_values < NV_PC_MAX_VALUES - 1); + + value->n = pc->num_values++; + value->join = value; + value->reg.id = -1; + value->reg.file = file; + value->reg.type = value->reg.as_type = type; + return value; +} + +static INLINE struct nv_value * +new_value_like(struct nv_pc *pc, struct nv_value *like) +{ + struct nv_value *val = new_value(pc, like->reg.file, like->reg.type); + val->reg.as_type = like->reg.as_type; + return val; +} + +static INLINE struct nv_ref * +new_ref(struct nv_pc *pc, struct nv_value *val) +{ + int i; + struct nv_ref *ref; + + if ((pc->num_refs % 64) == 0) { + const unsigned old_size = pc->num_refs * sizeof(struct nv_ref *); + const unsigned new_size = (pc->num_refs + 64) * sizeof(struct nv_ref *); + + pc->refs = REALLOC(pc->refs, old_size, new_size); + + ref = CALLOC(64, sizeof(struct nv_ref)); + for (i = 0; i < 64; ++i) + pc->refs[pc->num_refs + i] = &ref[i]; + } + + ref = pc->refs[pc->num_refs++]; + ref->value = val; + ref->typecast = val->reg.as_type; + + ++val->refc; + return ref; +} + +static INLINE struct nv_basic_block * +new_basic_block(struct nv_pc *pc) +{ + struct nv_basic_block *bb; + + if (pc->num_blocks >= NV_PC_MAX_BASIC_BLOCKS) + return NULL; + + bb = CALLOC_STRUCT(nv_basic_block); + + bb->id = pc->num_blocks; + pc->bb_list[pc->num_blocks++] = bb; + return bb; +} + +static INLINE void +nv_reference(struct nv_pc *pc, struct nv_ref **d, struct nv_value *s) +{ + if (*d) + --(*d)->value->refc; + + if (s) { + if (!*d) + *d = new_ref(pc, s); + else { + (*d)->value = s; + ++(s->refc); + } + } else { + *d = NULL; + } +} + +/* nv50_emit.c */ +void nv50_emit_instruction(struct nv_pc *, struct nv_instruction *); +unsigned nv50_inst_min_size(struct nv_instruction *); + +/* nv50_print.c */ +const char *nv_opcode_name(uint opcode); +void nv_print_instruction(struct nv_instruction *); + +/* nv50_pc.c */ + +void nv_print_function(struct nv_basic_block *root); +void nv_print_program(struct nv_pc *); + +boolean nv_op_commutative(uint opcode); +int nv50_indirect_opnd(struct nv_instruction *); +boolean nv50_nvi_can_use_imm(struct nv_instruction *, int s); +boolean nv50_nvi_can_predicate(struct nv_instruction *); +boolean nv50_nvi_can_load(struct nv_instruction *, int s, struct nv_value *); +boolean nv50_op_can_write_flags(uint opcode); +ubyte nv50_supported_src_mods(uint opcode, int s); +int nv_nvi_refcount(struct nv_instruction *); +void nv_nvi_delete(struct nv_instruction *); +void nv_nvi_permute(struct nv_instruction *, struct nv_instruction *); +void nvbb_attach_block(struct nv_basic_block *parent, + struct nv_basic_block *, ubyte edge_kind); +boolean nvbb_dominated_by(struct nv_basic_block *, struct nv_basic_block *); +boolean nvbb_reachable_by(struct nv_basic_block *, struct nv_basic_block *, + struct nv_basic_block *); +struct nv_basic_block *nvbb_dom_frontier(struct nv_basic_block *); +int nvcg_replace_value(struct nv_pc *pc, struct nv_value *old_val, + struct nv_value *new_val); +struct nv_value *nvcg_find_immediate(struct nv_ref *); +struct nv_value *nvcg_find_constant(struct nv_ref *); + +typedef void (*nv_pc_pass_func)(void *priv, struct nv_basic_block *b); + +void nv_pc_pass_in_order(struct nv_basic_block *, nv_pc_pass_func, void *); + +int nv_pc_exec_pass0(struct nv_pc *pc); +int nv_pc_exec_pass1(struct nv_pc *pc); +int nv_pc_exec_pass2(struct nv_pc *pc); + +int nv50_tgsi_to_nc(struct nv_pc *, struct nv50_translation_info *); + +#endif // NV50_COMPILER_H diff --git a/src/gallium/drivers/nv50/nv50_pc_emit.c b/src/gallium/drivers/nv50/nv50_pc_emit.c new file mode 100644 index 0000000..f37dc51 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_pc_emit.c @@ -0,0 +1,1254 @@ +/* + * Copyright 2010 Christoph Bumiller + * + * 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 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 "nv50_context.h" +#include "nv50_pc.h" + +#define FLAGS_CC_SHIFT 7 +#define FLAGS_ID_SHIFT 12 +#define FLAGS_WR_ID_SHIFT 4 +#define FLAGS_CC_MASK (0x1f << FLAGS_CC_SHIFT) +#define FLAGS_ID_MASK (0x03 << FLAGS_ID_SHIFT) +#define FLAGS_WR_EN (1 << 6) +#define FLAGS_WR_ID_MASK (0x3 << FLAGS_WR_ID_SHIFT) + +#define NV50_FIXUP_CODE_RELOC 0 +#define NV50_FIXUP_DATA_RELOC 1 + +struct nv50_fixup { + uint8_t type; + int8_t shift; + uint32_t mask; + uint32_t data; + uint32_t offset; +}; + +void +nv50_relocate_program(struct nv50_program *p, + uint32_t code_base, + uint32_t data_base) +{ + struct nv50_fixup *f = (struct nv50_fixup *)p->fixups; + unsigned i; + + for (i = 0; i < p->num_fixups; ++i) { + uint32_t data; + + switch (f[i].type) { + case NV50_FIXUP_CODE_RELOC: data = code_base + f[i].data; break; + case NV50_FIXUP_DATA_RELOC: data = data_base + f[i].data; break; + default: + data = f[i].data; + break; + } + data = (f[i].shift < 0) ? (data >> -f[i].shift) : (data << f[i].shift); + + p->code[f[i].offset / 4] &= ~f[i].mask; + p->code[f[i].offset / 4] |= data & f[i].mask; + } +} + +static void +new_fixup(struct nv_pc *pc, uint8_t ty, int w, uint32_t data, uint32_t m, int s) +{ + struct nv50_fixup *f; + + const unsigned size = sizeof(struct nv50_fixup); + const unsigned n = pc->num_fixups; + + if (!(n % 8)) + pc->fixups = REALLOC(pc->fixups, n * size, (n + 8) * size); + + f = (struct nv50_fixup *)pc->fixups; + + f[n].offset = (pc->bin_pos + w) * 4; + f[n].type = ty; + f[n].data = data; + f[n].mask = m; + f[n].shift = s; + + ++pc->num_fixups; +} + +const ubyte nv50_inst_min_size_tab[NV_OP_COUNT] = +{ + 0, 0, 0, 8, 8, 4, 4, 4, 8, 4, 4, 8, 8, 8, 8, 8, /* 15 */ + 8, 8, 8, 4, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 4, /* 31 */ + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 4, /* 47 */ + 4, 8, 8, 8, 8, 8, 0, 0, 8 +}; + +unsigned +nv50_inst_min_size(struct nv_instruction *i) +{ + int n; + + if (nv50_inst_min_size_tab[i->opcode] > 4) + return 8; + + if (i->def[0] && i->def[0]->reg.file != NV_FILE_GPR) + return 8; + if (i->def[0]->join->reg.id > 63) + return 8; + + for (n = 0; n < 3; ++n) { + if (!i->src[n]) + break; + if (i->src[n]->value->reg.file != NV_FILE_GPR && + i->src[n]->value->reg.file != NV_FILE_MEM_V) + return 8; + if (i->src[n]->value->reg.id > 63) + return 8; + } + + if (i->flags_def || i->flags_src || i->src[4]) + return 8; + + if (i->is_join) + return 8; + + if (i->src[2]) { + if (i->saturate || i->src[2]->mod) + return 8; + if (i->src[0]->mod ^ i->src[1]->mod) + return 8; + if ((i->src[0]->mod | i->src[1]->mod) & NV_MOD_ABS) + return 8; + if (i->def[0]->join->reg.id < 0 || + i->def[0]->join->reg.id != i->src[2]->value->join->reg.id) + return 8; + } + + return nv50_inst_min_size_tab[i->opcode]; +} + +static INLINE ubyte +STYPE(struct nv_instruction *nvi, int s) +{ + return nvi->src[s]->typecast; +} + +static INLINE ubyte +DTYPE(struct nv_instruction *nvi, int d) +{ + return nvi->def[d]->reg.type; +} + +static INLINE struct nv_reg * +SREG(struct nv_ref *ref) +{ + return &ref->value->join->reg; +} + +static INLINE struct nv_reg * +DREG(struct nv_value *val) +{ + return &val->join->reg; +} + +static INLINE ubyte +SFILE(struct nv_instruction *nvi, int s) +{ + return nvi->src[s]->value->reg.file; +} + +static INLINE ubyte +DFILE(struct nv_instruction *nvi, int d) +{ + return nvi->def[0]->reg.file; +} + +static INLINE void +SID(struct nv_pc *pc, struct nv_ref *ref, int pos) +{ + pc->emit[pos / 32] |= SREG(ref)->id << (pos % 32); +} + +static INLINE void +DID(struct nv_pc *pc, struct nv_value *val, int pos) +{ + pc->emit[pos / 32] |= DREG(val)->id << (pos % 32); +} + +static INLINE uint32_t +get_immd_u32(struct nv_ref *ref) +{ + assert(ref->value->reg.file == NV_FILE_IMM); + return ref->value->reg.imm.u32; +} + +static INLINE void +set_immd_u32(struct nv_pc *pc, uint32_t u32) +{ + pc->emit[1] |= 3; + pc->emit[0] |= (u32 & 0x3f) << 16; + pc->emit[1] |= (u32 >> 6) << 2; +} + +static INLINE void +set_immd(struct nv_pc *pc, struct nv_ref *ref) +{ + assert(ref->value->reg.file == NV_FILE_IMM); + set_immd_u32(pc, get_immd_u32(ref)); +} + +/* Allocate data in immediate buffer, if we want to load the immediate + * for a constant buffer instead of inlining it into the code. + */ +static void +nv_pc_alloc_immd(struct nv_pc *pc, struct nv_ref *ref) +{ + uint32_t i, val = get_immd_u32(ref); + + for (i = 0; i < pc->immd_count; ++i) + if (pc->immd_buf[i] == val) + break; + + if (i == pc->immd_count) { + if (!(pc->immd_count % 8)) + pc->immd_buf = REALLOC(pc->immd_buf, + pc->immd_count * 4, (pc->immd_count + 8) * 4); + pc->immd_buf[pc->immd_count++] = val; + } + + SREG(ref)->id = i; +} + +static INLINE void +set_pred(struct nv_pc *pc, struct nv_instruction *i) +{ + assert(!(pc->emit[1] & 0x00003f80)); + + pc->emit[1] |= i->cc << 7; + if (i->flags_src) + pc->emit[1] |= SREG(i->flags_src)->id << 12; +} + +static INLINE void +set_pred_wr(struct nv_pc *pc, struct nv_instruction *i) +{ + assert(!(pc->emit[1] & 0x00000070)); + + if (i->flags_def) + pc->emit[1] |= (DREG(i->flags_def)->id << 4) | 0x40; +} + +static INLINE void +set_a16_bits(struct nv_pc *pc, uint id) +{ + ++id; /* $a0 is always 0 */ + pc->emit[0] |= (id & 3) << 26; + pc->emit[1] |= id & 4; +} + +static INLINE void +set_addr(struct nv_pc *pc, struct nv_instruction *i) +{ + if (i->src[4]) + set_a16_bits(pc, SREG(i->src[4])->id); +} + +static void +set_dst(struct nv_pc *pc, struct nv_value *value) +{ + struct nv_reg *reg = &value->join->reg; + + if (reg->id < 0) { + pc->emit[0] |= (127 << 2) | 1; /* set 'long'-bit to catch bugs */ + pc->emit[1] |= 0x8; + return; + } + + if (reg->file == NV_FILE_OUT) + pc->emit[1] |= 0x8; + else + if (reg->file == NV_FILE_ADDR) + assert(0); + + pc->emit[0] |= reg->id << 2; +} + +static void +set_src_0(struct nv_pc *pc, struct nv_ref *ref) +{ + struct nv_reg *reg = SREG(ref); + + if (reg->file == NV_FILE_MEM_S) + pc->emit[1] |= 0x00200000; + else + if (reg->file == NV_FILE_MEM_P) + pc->emit[0] |= 0x01800000; + else + if (reg->file != NV_FILE_GPR) + NOUVEAU_ERR("invalid src0 register file: %d\n", reg->file); + + assert(reg->id < 128); + pc->emit[0] |= reg->id << 9; +} + +static void +set_src_1(struct nv_pc *pc, struct nv_ref *ref) +{ + struct nv_reg *reg = SREG(ref); + + if (reg->file >= NV_FILE_MEM_C(0) && + reg->file <= NV_FILE_MEM_C(15)) { + assert(!(pc->emit[1] & 0x01800000)); + + pc->emit[0] |= 0x00800000; + pc->emit[1] |= (reg->file - NV_FILE_MEM_C(0)) << 22; + } else + if (reg->file != NV_FILE_GPR) + NOUVEAU_ERR("invalid src1 register file: %d\n", reg->file); + + assert(reg->id < 128); + pc->emit[0] |= reg->id << 16; +} + +static void +set_src_2(struct nv_pc *pc, struct nv_ref *ref) +{ + struct nv_reg *reg = SREG(ref); + + if (reg->file >= NV_FILE_MEM_C(0) && + reg->file <= NV_FILE_MEM_C(15)) { + assert(!(pc->emit[1] & 0x01800000)); + + pc->emit[0] |= 0x01000000; + pc->emit[1] |= (reg->file - NV_FILE_MEM_C(0)) << 22; + } else + if (reg->file != NV_FILE_GPR) + NOUVEAU_ERR("invalid src2 register file: %d\n", reg->file); + + assert(reg->id < 128); + pc->emit[1] |= reg->id << 14; +} + +/* the default form: + * - long instruction + * - 1 to 3 sources in slots 0, 1, 2 + * - address & flags + */ +static void +emit_form_MAD(struct nv_pc *pc, struct nv_instruction *i) +{ + pc->emit[0] |= 1; + + set_pred(pc, i); + set_pred_wr(pc, i); + + if (i->def[0]) + set_dst(pc, i->def[0]); + else { + pc->emit[0] |= 0x01fc; + pc->emit[1] |= 0x0008; + } + + if (i->src[0]) + set_src_0(pc, i->src[0]); + + if (i->src[1]) + set_src_1(pc, i->src[1]); + + if (i->src[2]) + set_src_2(pc, i->src[2]); + + set_addr(pc, i); +} + +/* like default form, but 2nd source in slot 2, no 3rd source */ +static void +emit_form_ADD(struct nv_pc *pc, struct nv_instruction *i) +{ + pc->emit[0] |= 1; + + if (i->def[0]) + set_dst(pc, i->def[0]); + else { + pc->emit[0] |= 0x01fc; + pc->emit[1] |= 0x0008; + } + + set_pred(pc, i); + set_pred_wr(pc, i); + + if (i->src[0]) + set_src_0(pc, i->src[0]); + + if (i->src[1]) + set_src_2(pc, i->src[1]); + + set_addr(pc, i); +} + +/* short mul */ +static void +emit_form_MUL(struct nv_pc *pc, struct nv_instruction *i) +{ + assert(!i->is_long && !(pc->emit[0] & 1)); + + assert(i->def[0]); + set_dst(pc, i->def[0]); + + if (i->src[0]) + set_src_0(pc, i->src[0]); + + if (i->src[1]) + set_src_1(pc, i->src[1]); +} + +/* default immediate form + * - 1 to 3 sources where last is immediate + * - no address or predicate possible + */ +static void +emit_form_IMM(struct nv_pc *pc, struct nv_instruction *i, ubyte mod_mask) +{ + pc->emit[0] |= 1; + + assert(i->def[0]); + assert(i->src[0]); + set_dst(pc, i->def[0]); + + assert(!i->src[4] && !i->flags_src && !i->flags_def); + + if (i->src[2]) { + set_immd(pc, i->src[2]); + set_src_0(pc, i->src[1]); + set_src_1(pc, i->src[0]); + } else + if (i->src[1]) { + set_immd(pc, i->src[1]); + set_src_0(pc, i->src[0]); + } else + set_immd(pc, i->src[0]); + + assert(!mod_mask); +} + +static void +set_ld_st_size(struct nv_pc *pc, int s, ubyte type) +{ + switch (type) { + case NV_TYPE_F64: + pc->emit[1] |= 0x8000 << s; + break; + case NV_TYPE_F32: + case NV_TYPE_S32: + case NV_TYPE_U32: + pc->emit[1] |= 0xc000 << s; + break; + case NV_TYPE_S16: + pc->emit[1] |= 0x6000 << s; + break; + case NV_TYPE_U16: + pc->emit[1] |= 0x4000 << s; + break; + case NV_TYPE_S8: + pc->emit[1] |= 0x2000 << s; + break; + default: + break; + } +} + +static void +emit_ld(struct nv_pc *pc, struct nv_instruction *i) +{ + ubyte sf = SFILE(i, 0); + + if (sf == NV_FILE_IMM) { + sf = NV_FILE_MEM_C(0); + nv_pc_alloc_immd(pc, i->src[0]); + + new_fixup(pc, NV50_FIXUP_DATA_RELOC, 0, SREG(i->src[0])->id, 0xffff, 9); + } + + if (sf == NV_FILE_MEM_S || + sf == NV_FILE_MEM_P) { + pc->emit[0] = 0x10000001; + pc->emit[1] = 0x04200000 | (0x3c << 12); + if (sf == NV_FILE_MEM_P) + pc->emit[0] |= 0x01800000; + } else + if (sf >= NV_FILE_MEM_C(0) && + sf <= NV_FILE_MEM_C(15)) { + pc->emit[0] = 0x10000001; + pc->emit[1] = 0x24000000; + pc->emit[1] |= (sf - NV_FILE_MEM_C(0)) << 22; + } else + if (sf >= NV_FILE_MEM_G(0) && + sf <= NV_FILE_MEM_G(15)) { + pc->emit[0] = 0xd0000001 | ((sf - NV_FILE_MEM_G(0)) << 16); + pc->emit[1] = 0xa0000000; + + assert(i->src[4] && SREG(i->src[4])->file == NV_FILE_GPR); + SID(pc, i->src[4], 9); + } else + if (sf == NV_FILE_MEM_L) { + pc->emit[0] = 0xd0000001; + pc->emit[1] = 0x40000000; + + set_addr(pc, i); + } else { + NOUVEAU_ERR("invalid ld source file\n"); + abort(); + } + + set_ld_st_size(pc, (sf == NV_FILE_MEM_L) ? 8 : 0, STYPE(i, 0)); + + set_dst(pc, i->def[0]); + set_pred_wr(pc, i); + + set_pred(pc, i); + + if (sf < NV_FILE_MEM_G(0) || + sf > NV_FILE_MEM_G(15)) { + SID(pc, i->src[0], 9); + set_addr(pc, i); + } +} + +static void +emit_st(struct nv_pc *pc, struct nv_instruction *i) +{ + assert(SFILE(i, 1) == NV_FILE_GPR); + assert(SFILE(i, 0) == NV_FILE_MEM_L); + + pc->emit[0] = 0xd0000001; + pc->emit[1] = 0x60000000; + + SID(pc, i->src[1], 2); + SID(pc, i->src[0], 9); + + set_ld_st_size(pc, 8, STYPE(i, 1)); + + set_addr(pc, i); + set_pred(pc, i); +} + +static int +verify_mov(struct nv_instruction *i) +{ + ubyte sf = SFILE(i, 0); + ubyte df = DFILE(i, 0); + + if (df == NV_FILE_GPR) + return 0; + + if (df != NV_FILE_OUT && + df != NV_FILE_FLAGS && + df != NV_FILE_ADDR) + return 1; + + if (sf == NV_FILE_FLAGS) + return 2; + if (sf == NV_FILE_ADDR) + return 3; + if (sf == NV_FILE_IMM && df != NV_FILE_OUT) + return 4; + + return 0; +} + +static void +emit_mov(struct nv_pc *pc, struct nv_instruction *i) +{ + assert(!verify_mov(i)); + + if (SFILE(i, 0) >= NV_FILE_MEM_S) + emit_ld(pc, i); + else + if (SFILE(i, 0) == NV_FILE_FLAGS) { + pc->emit[0] = 0x00000001 | (DREG(i->def[0])->id << 2); + pc->emit[1] = 0x20000780 | (SREG(i->src[0])->id << 12); + } else + if (SFILE(i, 0) == NV_FILE_ADDR) { + pc->emit[0] = 0x00000001 | (DREG(i->def[0])->id << 2); + pc->emit[1] = 0x40000780; + set_a16_bits(pc, SREG(i->src[0])->id); + } else + if (DFILE(i, 0) == NV_FILE_FLAGS) { + pc->emit[0] = 0x00000001; + pc->emit[1] = 0xa0000000 | (1 << 6); + set_pred(pc, i); + pc->emit[0] |= SREG(i->src[0])->id << 9; + pc->emit[1] |= DREG(i->def[0])->id << 4; + } else + if (SFILE(i, 0) == NV_FILE_IMM) { + if (i->opcode == NV_OP_LDA) { + emit_ld(pc, i); + } else { + pc->emit[0] = 0x10008001; + pc->emit[1] = 0x00000003; + + emit_form_IMM(pc, i, 0); + } + } else { + pc->emit[0] = 0x10000000; + pc->emit[0] |= DREG(i->def[0])->id << 2; + pc->emit[0] |= SREG(i->src[0])->id << 9; + + if (!i->is_long) { + pc->emit[0] |= 0x8000; + } else { + pc->emit[0] |= 0x00000001; + pc->emit[1] = 0x0403c000; + + set_pred(pc, i); + } + } + + if (DFILE(i, 0) == NV_FILE_OUT) + pc->emit[1] |= 0x8; +} + +static void +emit_interp(struct nv_pc *pc, struct nv_instruction *i) +{ + pc->emit[0] = 0x80000000; + + assert(DFILE(i, 0) == NV_FILE_GPR); + assert(SFILE(i, 0) == NV_FILE_MEM_V); + + DID(pc, i->def[0], 2); + SID(pc, i->src[0], 16); + + if (i->flat) + pc->emit[0] |= 1 << 8; + else + if (i->opcode == NV_OP_PINTERP) { + pc->emit[0] |= 1 << 25; + pc->emit[0] |= SREG(i->src[1])->id << 9; + } + + if (i->centroid) + pc->emit[0] |= 1 << 24; + + assert(i->is_long || !i->flags_src); + + if (i->is_long) { + set_pred(pc, i); + + pc->emit[1] |= + (pc->emit[0] & (3 << 24)) >> (24 - 16) | + (pc->emit[0] & (1 << 8)) >> (18 - 8); + + pc->emit[0] |= 1; + pc->emit[0] &= ~0x03000100; + } +} + +static void +emit_minmax(struct nv_pc *pc, struct nv_instruction *i) +{ + pc->emit[0] = 0x30000000; + pc->emit[1] = (i->opcode == NV_OP_MIN) ? (2 << 28) : 0; + + switch (DTYPE(i, 0)) { + case NV_TYPE_F32: + pc->emit[0] |= 0x80000000; + pc->emit[1] |= 0x80000000; + break; + case NV_TYPE_S32: + pc->emit[1] |= 0x8c000000; + break; + case NV_TYPE_U32: + pc->emit[1] |= 0x84000000; + break; + } + + emit_form_MAD(pc, i); + + if (i->src[0]->mod & NV_MOD_ABS) pc->emit[1] |= 0x00100000; + if (i->src[1]->mod & NV_MOD_ABS) pc->emit[1] |= 0x00080000; +} + +static void +emit_add_f32(struct nv_pc *pc, struct nv_instruction *i) +{ + pc->emit[0] = 0xb0000000; + + assert(!((i->src[0]->mod | i->src[1]->mod) & NV_MOD_ABS)); + + if (SFILE(i, 1) == NV_FILE_IMM) { + emit_form_IMM(pc, i, 0); + + if (i->src[0]->mod & NV_MOD_NEG) pc->emit[0] |= 0x8000; + if (i->src[1]->mod & NV_MOD_NEG) pc->emit[0] |= 1 << 22; + } else + if (i->is_long) { + emit_form_ADD(pc, i); + + if (i->src[0]->mod & NV_MOD_NEG) pc->emit[1] |= 1 << 26; + if (i->src[1]->mod & NV_MOD_NEG) pc->emit[1] |= 1 << 27; + + if (i->saturate) + pc->emit[1] |= 0x20000000; + } else { + emit_form_MUL(pc, i); + + if (i->src[0]->mod & NV_MOD_NEG) pc->emit[0] |= 0x8000; + if (i->src[1]->mod & NV_MOD_NEG) pc->emit[0] |= 1 << 22; + } +} + +static void +emit_add_b32(struct nv_pc *pc, struct nv_instruction *i) +{ + pc->emit[0] = 0x20008000; + + if (SFILE(i, 1) == NV_FILE_IMM) { + emit_form_IMM(pc, i, 0); + } else + if (i->is_long) { + pc->emit[0] = 0x20000000; + pc->emit[1] = 0x04000000; + emit_form_ADD(pc, i); + } else { + emit_form_MUL(pc, i); + } + + if (i->src[0]->mod & NV_MOD_NEG) pc->emit[0] |= 1 << 28; + if (i->src[1]->mod & NV_MOD_NEG) pc->emit[0] |= 1 << 22; +} + +static void +emit_add_a16(struct nv_pc *pc, struct nv_instruction *i) +{ + int s = (i->opcode == NV_OP_MOV) ? 0 : 1; + + pc->emit[0] = 0xd0000001 | ((uint16_t)get_immd_u32(i->src[s]) << 9); + pc->emit[1] = 0x20000000; + + pc->emit[0] |= (DREG(i->def[0])->id + 1) << 2; + + set_pred(pc, i); + + if (i->src[1]) + set_a16_bits(pc, SREG(i->src[1])->id + 1); +} + +static void +emit_flow(struct nv_pc *pc, struct nv_instruction *i, ubyte flow_op) +{ + pc->emit[0] = 0x00000003 | (flow_op << 28); + pc->emit[1] = 0x00000000; + + set_pred(pc, i); + + if (i->target && (i->opcode != NV_OP_BREAK)) { + uint32_t pos = i->target->bin_pos; + + new_fixup(pc, NV50_FIXUP_CODE_RELOC, 0, pos, 0xffff << 11, 9); + new_fixup(pc, NV50_FIXUP_CODE_RELOC, 1, pos, 0x3f << 14, -4); + + pc->emit[0] |= (pos / 4) << 11; + } +} + +static INLINE void +emit_add(struct nv_pc *pc, struct nv_instruction *i) +{ + if (DFILE(i, 0) == NV_FILE_ADDR) + emit_add_a16(pc, i); + else { + switch (DTYPE(i, 0)) { + case NV_TYPE_F32: + emit_add_f32(pc, i); + break; + case NV_TYPE_U32: + case NV_TYPE_S32: + emit_add_b32(pc, i); + break; + } + } +} + +static void +emit_bitop2(struct nv_pc *pc, struct nv_instruction *i) +{ + pc->emit[0] = 0xd0000000; + + if (SFILE(i, 1) == NV_FILE_IMM) { + emit_form_IMM(pc, i, 0); + + if (i->opcode == NV_OP_OR) + pc->emit[0] |= 0x0100; + else + if (i->opcode == NV_OP_XOR) + pc->emit[0] |= 0x8000; + } else { + emit_form_MAD(pc, i); + + pc->emit[1] |= 0x04000000; + + if (i->opcode == NV_OP_OR) + pc->emit[1] |= 0x4000; + else + if (i->opcode == NV_OP_XOR) + pc->emit[1] |= 0x8000; + } +} + +static void +emit_arl(struct nv_pc *pc, struct nv_instruction *i) +{ + assert(SFILE(i, 0) == NV_FILE_GPR); + assert(SFILE(i, 1) == NV_FILE_IMM); + + assert(!i->flags_def); + + pc->emit[0] = 0x00000001; + pc->emit[1] = 0xc0000000; + + pc->emit[0] |= (i->def[0]->reg.id + 1) << 2; + set_pred(pc, i); + set_src_0(pc, i->src[0]); + pc->emit[0] |= (get_immd_u32(i->src[1]) & 0x3f) << 16; +} + +static void +emit_shift(struct nv_pc *pc, struct nv_instruction *i) +{ + if (DFILE(i, 0) == NV_FILE_ADDR) { + emit_arl(pc, i); + return; + } + + pc->emit[0] = 0x30000001; + pc->emit[1] = 0xc4000000; + + if (i->opcode == NV_OP_SHR) + pc->emit[1] |= 1 << 29; + + if (SFILE(i, 1) == NV_FILE_IMM) { + pc->emit[1] |= 1 << 20; + pc->emit[0] |= (get_immd_u32(i->src[1]) & 0x7f) << 16; + + set_pred(pc, i); + } else + emit_form_MAD(pc, i); + + if (STYPE(i, 0) == NV_TYPE_S32) + pc->emit[1] |= 1 << 27; +} + +static void +emit_flop(struct nv_pc *pc, struct nv_instruction *i) +{ + struct nv_ref *src0 = i->src[0]; + + pc->emit[0] = 0x90000000; + + assert(STYPE(i, 0) == NV_TYPE_F32); + assert(SFILE(i, 0) == NV_FILE_GPR); + + if (!i->is_long) { + emit_form_MUL(pc, i); + assert(i->opcode == NV_OP_RCP && !src0->mod); + return; + } + + pc->emit[1] = (i->opcode - NV_OP_RCP) << 29; + + emit_form_MAD(pc, i); + + if (src0->mod & NV_MOD_NEG) pc->emit[1] |= 0x04000000; + if (src0->mod & NV_MOD_ABS) pc->emit[1] |= 0x00100000; +} + +static void +emit_mad_f32(struct nv_pc *pc, struct nv_instruction *i) +{ + const boolean neg_mul = (i->src[0]->mod ^ i->src[1]->mod) & NV_MOD_NEG; + const boolean neg_add = (i->src[2]->mod & NV_MOD_NEG); + + pc->emit[0] = 0xe0000000; + + if (!i->is_long) { + emit_form_MUL(pc, i); + assert(!neg_mul && !neg_add); + return; + } + + emit_form_MAD(pc, i); + + if (neg_mul) pc->emit[1] |= 0x04000000; + if (neg_add) pc->emit[1] |= 0x08000000; + + if (i->saturate) + pc->emit[1] |= 0x20000000; +} + +static INLINE void +emit_mad(struct nv_pc *pc, struct nv_instruction *i) +{ + emit_mad_f32(pc, i); +} + +static void +emit_mul_f32(struct nv_pc *pc, struct nv_instruction *i) +{ + boolean neg = (i->src[0]->mod ^ i->src[1]->mod) & NV_MOD_NEG; + + pc->emit[0] = 0xc0000000; + + if (SFILE(i, 1) == NV_FILE_IMM) { + emit_form_IMM(pc, i, 0); + + if (neg) + pc->emit[0] |= 0x8000; + } else + if (i->is_long) { + emit_form_MAD(pc, i); + + if (neg) + pc->emit[1] |= 0x08 << 24; + } else { + emit_form_MUL(pc, i); + + if (neg) + pc->emit[0] |= 0x8000; + } +} + +static void +emit_set(struct nv_pc *pc, struct nv_instruction *nvi) +{ + assert(nvi->is_long); + + pc->emit[0] = 0x30000000; + pc->emit[1] = 0x60000000; + + pc->emit[1] |= nvi->set_cond << 14; + + switch (STYPE(nvi, 0)) { + case NV_TYPE_U32: pc->emit[1] |= 0x04000000; break; + case NV_TYPE_S32: pc->emit[1] |= 0x0c000000; break; + case NV_TYPE_F32: pc->emit[0] |= 0x80000000; break; + default: + assert(0); + break; + } + + emit_form_MAD(pc, nvi); +} + +#define CVT_RN (0x00 << 16) +#define CVT_FLOOR (0x02 << 16) +#define CVT_CEIL (0x04 << 16) +#define CVT_TRUNC (0x06 << 16) +#define CVT_SAT (0x08 << 16) +#define CVT_ABS (0x10 << 16) + +#define CVT_X32_X32 0x04004000 +#define CVT_X32_S32 0x04014000 +#define CVT_F32_F32 ((0xc0 << 24) | CVT_X32_X32) +#define CVT_S32_F32 ((0x88 << 24) | CVT_X32_X32) +#define CVT_U32_F32 ((0x80 << 24) | CVT_X32_X32) +#define CVT_F32_S32 ((0x40 << 24) | CVT_X32_S32) +#define CVT_F32_U32 ((0x40 << 24) | CVT_X32_X32) +#define CVT_S32_S32 ((0x08 << 24) | CVT_X32_S32) +#define CVT_S32_U32 ((0x08 << 24) | CVT_X32_X32) +#define CVT_U32_S32 ((0x00 << 24) | CVT_X32_S32) +#define CVT_U32_U32 ((0x00 << 24) | CVT_X32_X32) + +#define CVT_NEG 0x20000000 +#define CVT_RI 0x08000000 + +static void +emit_cvt(struct nv_pc *pc, struct nv_instruction *nvi) +{ + ubyte dst_type = nvi->def[0] ? DTYPE(nvi, 0) : STYPE(nvi, 0); + + pc->emit[0] = 0xa0000000; + + switch (dst_type) { + case NV_TYPE_F32: + switch (STYPE(nvi, 0)) { + case NV_TYPE_F32: pc->emit[1] = CVT_F32_F32; break; + case NV_TYPE_S32: pc->emit[1] = CVT_F32_S32; break; + case NV_TYPE_U32: pc->emit[1] = CVT_F32_U32; break; + } + break; + case NV_TYPE_S32: + switch (STYPE(nvi, 0)) { + case NV_TYPE_F32: pc->emit[1] = CVT_S32_F32; break; + case NV_TYPE_S32: pc->emit[1] = CVT_S32_S32; break; + case NV_TYPE_U32: pc->emit[1] = CVT_S32_U32; break; + } + break; + case NV_TYPE_U32: + switch (STYPE(nvi, 0)) { + case NV_TYPE_F32: pc->emit[1] = CVT_U32_F32; break; + case NV_TYPE_S32: pc->emit[1] = CVT_U32_S32; break; + case NV_TYPE_U32: pc->emit[1] = CVT_U32_U32; break; + } + break; + } + if (pc->emit[1] == CVT_F32_F32 && + (nvi->opcode == NV_OP_CEIL || nvi->opcode == NV_OP_FLOOR || + nvi->opcode == NV_OP_TRUNC)) + pc->emit[1] |= CVT_RI; + + switch (nvi->opcode) { + case NV_OP_CEIL: pc->emit[1] |= CVT_CEIL; break; + case NV_OP_FLOOR: pc->emit[1] |= CVT_FLOOR; break; + case NV_OP_TRUNC: pc->emit[1] |= CVT_TRUNC; break; + + case NV_OP_ABS: pc->emit[1] |= CVT_ABS; break; + case NV_OP_SAT: pc->emit[1] |= CVT_SAT; break; + case NV_OP_NEG: pc->emit[1] |= CVT_NEG; break; + default: + assert(nvi->opcode == NV_OP_CVT); + break; + } + assert(nvi->opcode != NV_OP_ABS || !(nvi->src[0]->mod & NV_MOD_NEG)); + + if (nvi->src[0]->mod & NV_MOD_NEG) pc->emit[1] ^= CVT_NEG; + if (nvi->src[0]->mod & NV_MOD_ABS) pc->emit[1] |= CVT_ABS; + + emit_form_MAD(pc, nvi); +} + +static void +emit_tex(struct nv_pc *pc, struct nv_instruction *i) +{ + pc->emit[0] = 0xf0000001; + pc->emit[1] = 0x00000000; + + DID(pc, i->def[0], 2); + + set_pred(pc, i); + + pc->emit[0] |= i->tex_t << 9; + pc->emit[0] |= i->tex_s << 17; + + pc->emit[0] |= (i->tex_argc - 1) << 22; + + pc->emit[0] |= (i->tex_mask & 0x3) << 25; + pc->emit[1] |= (i->tex_mask & 0xc) << 12; + + if (i->tex_live) + pc->emit[1] |= 4; + + if (i->tex_cube) + pc->emit[0] |= 0x08000000; + + if (i->opcode == NV_OP_TXB) + pc->emit[1] |= 0x20000000; + else + if (i->opcode == NV_OP_TXL) + pc->emit[1] |= 0x40000000; +} + +static void +emit_cvt2fixed(struct nv_pc *pc, struct nv_instruction *i) +{ + ubyte mod = i->src[0]->mod; + + pc->emit[0] = 0xb0000000; + pc->emit[1] = 0xc0000000; + + if (i->opcode == NV_OP_PREEX2) + pc->emit[1] |= 0x4000; + + emit_form_MAD(pc, i); + + if (mod & NV_MOD_NEG) pc->emit[1] |= 0x04000000; + if (mod & NV_MOD_ABS) pc->emit[1] |= 0x00100000; +} + +static void +emit_ddx(struct nv_pc *pc, struct nv_instruction *i) +{ + assert(i->is_long && SFILE(i, 0) == NV_FILE_GPR); + + pc->emit[0] = (i->src[0]->mod & NV_MOD_NEG) ? 0xc0240001 : 0xc0140001; + pc->emit[1] = (i->src[0]->mod & NV_MOD_NEG) ? 0x86400000 : 0x89800000; + + DID(pc, i->def[0], 2); + SID(pc, i->src[0], 9); + SID(pc, i->src[0], 32 + 14); + + set_pred(pc, i); + set_pred_wr(pc, i); +} + +static void +emit_ddy(struct nv_pc *pc, struct nv_instruction *i) +{ + assert(i->is_long && SFILE(i, 0) == NV_FILE_GPR); + + pc->emit[0] = (i->src[0]->mod & NV_MOD_NEG) ? 0xc0250001 : 0xc0150001; + pc->emit[1] = (i->src[0]->mod & NV_MOD_NEG) ? 0x85800000 : 0x8a400000; + + DID(pc, i->def[0], 2); + SID(pc, i->src[0], 9); + SID(pc, i->src[0], 32 + 14); + + set_pred(pc, i); + set_pred_wr(pc, i); +} + +static void +emit_quadop(struct nv_pc *pc, struct nv_instruction *i) +{ + pc->emit[0] = 0xc0000000; + pc->emit[1] = 0x80000000; + + emit_form_ADD(pc, i); + + pc->emit[0] |= i->lanes << 16; + + pc->emit[0] |= (i->quadop & 0x03) << 20; + pc->emit[1] |= (i->quadop & 0xfc) << 20; +} + +void +nv50_emit_instruction(struct nv_pc *pc, struct nv_instruction *i) +{ + /* nv_print_instruction(i); */ + + switch (i->opcode) { + case NV_OP_MOV: + if (DFILE(i, 0) == NV_FILE_ADDR) + emit_add_a16(pc, i); + else + emit_mov(pc, i); + break; + case NV_OP_LDA: + emit_mov(pc, i); + break; + case NV_OP_STA: + emit_st(pc, i); + break; + case NV_OP_LINTERP: + case NV_OP_PINTERP: + emit_interp(pc, i); + break; + case NV_OP_ADD: + emit_add(pc, i); + break; + case NV_OP_AND: + case NV_OP_OR: + case NV_OP_XOR: + emit_bitop2(pc, i); + break; + case NV_OP_CVT: + case NV_OP_ABS: + case NV_OP_NEG: + case NV_OP_SAT: + case NV_OP_CEIL: + case NV_OP_FLOOR: + case NV_OP_TRUNC: + emit_cvt(pc, i); + break; + case NV_OP_DFDX: + emit_ddx(pc, i); + break; + case NV_OP_DFDY: + emit_ddy(pc, i); + break; + case NV_OP_RCP: + case NV_OP_RSQ: + case NV_OP_LG2: + case NV_OP_SIN: + case NV_OP_COS: + case NV_OP_EX2: + emit_flop(pc, i); + break; + case NV_OP_PRESIN: + case NV_OP_PREEX2: + emit_cvt2fixed(pc, i); + break; + case NV_OP_MAD: + emit_mad(pc, i); + break; + case NV_OP_MAX: + case NV_OP_MIN: + emit_minmax(pc, i); + break; + case NV_OP_MUL: + emit_mul_f32(pc, i); + break; + case NV_OP_SET: + emit_set(pc, i); + break; + case NV_OP_SHL: + case NV_OP_SHR: + emit_shift(pc, i); + break; + case NV_OP_TEX: + case NV_OP_TXB: + case NV_OP_TXL: + emit_tex(pc, i); + break; + case NV_OP_QUADOP: + emit_quadop(pc, i); + break; + case NV_OP_KIL: + emit_flow(pc, i, 0x0); + break; + case NV_OP_BRA: + emit_flow(pc, i, 0x1); + break; + case NV_OP_CALL: + emit_flow(pc, i, 0x2); + break; + case NV_OP_RET: + emit_flow(pc, i, 0x3); + break; + case NV_OP_BREAKADDR: + emit_flow(pc, i, 0x4); + break; + case NV_OP_BREAK: + emit_flow(pc, i, 0x5); + break; + case NV_OP_JOINAT: + emit_flow(pc, i, 0xa); + break; + case NV_OP_NOP: + case NV_OP_JOIN: + pc->emit[0] = 0xf0000001; + pc->emit[1] = 0xe0000000; + break; + case NV_OP_PHI: + case NV_OP_UNDEF: + case NV_OP_SUB: + NOUVEAU_ERR("operation \"%s\" should have been eliminated\n", + nv_opcode_name(i->opcode)); + break; + default: + NOUVEAU_ERR("unhandled NV_OP: %d\n", i->opcode); + abort(); + break; + } + + if (i->is_join) { + assert(i->is_long && !(pc->emit[1] & 1)); + pc->emit[1] |= 2; + } + + assert((pc->emit[0] & 1) == i->is_long); +} diff --git a/src/gallium/drivers/nv50/nv50_pc_optimize.c b/src/gallium/drivers/nv50/nv50_pc_optimize.c new file mode 100644 index 0000000..27eb381 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_pc_optimize.c @@ -0,0 +1,1154 @@ +/* + * Copyright 2010 Christoph Bumiller + * + * 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 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 NV50PC_DEBUG */ + +#include "nv50_pc.h" + +#define DESCEND_ARBITRARY(j, f) \ +do { \ + b->pass_seq = ctx->pc->pass_seq; \ + \ + for (j = 0; j < 2; ++j) \ + if (b->out[j] && b->out[j]->pass_seq < ctx->pc->pass_seq) \ + f(ctx, b->out[j]); \ +} while (0) + +extern unsigned nv50_inst_min_size(struct nv_instruction *); + +struct nv_pc_pass { + struct nv_pc *pc; +}; + +static INLINE boolean +values_equal(struct nv_value *a, struct nv_value *b) +{ + /* XXX: sizes */ + return (a->reg.file == b->reg.file && a->join->reg.id == b->join->reg.id); +} + +static INLINE boolean +inst_commutation_check(struct nv_instruction *a, + struct nv_instruction *b) +{ + int si, di; + + for (di = 0; di < 4; ++di) { + if (!a->def[di]) + break; + for (si = 0; si < 5; ++si) { + if (!b->src[si]) + continue; + if (values_equal(a->def[di], b->src[si]->value)) + return FALSE; + } + } + + if (b->flags_src && b->flags_src->value == a->flags_def) + return FALSE; + + return TRUE; +} + +/* Check whether we can swap the order of the instructions, + * where a & b may be either the earlier or the later one. + */ +static boolean +inst_commutation_legal(struct nv_instruction *a, + struct nv_instruction *b) +{ + return inst_commutation_check(a, b) && inst_commutation_check(b, a); +} + +static INLINE boolean +inst_cullable(struct nv_instruction *nvi) +{ + if (nvi->opcode == NV_OP_STA) + return FALSE; + return (!(nvi->is_terminator || nvi->is_join || + nvi->target || + nvi->fixed || + nv_nvi_refcount(nvi))); +} + +static INLINE boolean +nvi_isnop(struct nv_instruction *nvi) +{ + if (nvi->opcode == NV_OP_EXPORT || nvi->opcode == NV_OP_UNDEF) + return TRUE; + + /* NOTE: 'fixed' now only means that it shouldn't be optimized away, + * but we can still remove it if it is a no-op move. + */ + if (/* nvi->fixed || */ + /* nvi->flags_src || */ /* cond. MOV to same register is still NOP */ + nvi->flags_def || + nvi->is_terminator || + nvi->is_join) + return FALSE; + + if (nvi->def[0] && nvi->def[0]->join->reg.id < 0) + return TRUE; + + if (nvi->opcode != NV_OP_MOV && nvi->opcode != NV_OP_SELECT) + return FALSE; + + if (nvi->def[0]->reg.file != nvi->src[0]->value->reg.file) + return FALSE; + + if (nvi->src[0]->value->join->reg.id < 0) { + NV50_DBGMSG("nvi_isnop: orphaned value detected\n"); + return TRUE; + } + + if (nvi->opcode == NV_OP_SELECT) + if (!values_equal(nvi->def[0], nvi->src[1]->value)) + return FALSE; + + return values_equal(nvi->def[0], nvi->src[0]->value); +} + +struct nv_pass { + struct nv_pc *pc; + int n; + void *priv; +}; + +static int +nv_pass_flatten(struct nv_pass *ctx, struct nv_basic_block *b); + +static void +nv_pc_pass_pre_emission(void *priv, struct nv_basic_block *b) +{ + struct nv_pc *pc = (struct nv_pc *)priv; + struct nv_basic_block *in; + struct nv_instruction *nvi, *next; + int j; + uint size, n32 = 0; + + for (j = pc->num_blocks - 1; j >= 0 && !pc->bb_list[j]->bin_size; --j); + if (j >= 0) { + in = pc->bb_list[j]; + + /* check for no-op branches (BRA $PC+8) */ + if (in->exit && in->exit->opcode == NV_OP_BRA && in->exit->target == b) { + in->bin_size -= 8; + pc->bin_size -= 8; + + for (++j; j < pc->num_blocks; ++j) + pc->bb_list[j]->bin_pos -= 8; + + nv_nvi_delete(in->exit); + } + b->bin_pos = in->bin_pos + in->bin_size; + } + + pc->bb_list[pc->num_blocks++] = b; + + /* visit node */ + + for (nvi = b->entry; nvi; nvi = next) { + next = nvi->next; + if (nvi_isnop(nvi)) + nv_nvi_delete(nvi); + } + + for (nvi = b->entry; nvi; nvi = next) { + next = nvi->next; + + size = nv50_inst_min_size(nvi); + if (nvi->next && size < 8) + ++n32; + else + if ((n32 & 1) && nvi->next && + nv50_inst_min_size(nvi->next) == 4 && + inst_commutation_legal(nvi, nvi->next)) { + ++n32; + nv_nvi_permute(nvi, nvi->next); + next = nvi; + } else { + nvi->is_long = 1; + + b->bin_size += n32 & 1; + if (n32 & 1) + nvi->prev->is_long = 1; + n32 = 0; + } + b->bin_size += 1 + nvi->is_long; + } + + if (!b->entry) { + NV50_DBGMSG("block %p is now empty\n", b); + } else + if (!b->exit->is_long) { + assert(n32); + b->exit->is_long = 1; + b->bin_size += 1; + + /* might have del'd a hole tail of instructions */ + if (!b->exit->prev->is_long && !(n32 & 1)) { + b->bin_size += 1; + b->exit->prev->is_long = 1; + } + } + assert(!b->entry || (b->exit && b->exit->is_long)); + + pc->bin_size += b->bin_size *= 4; +} + +static int +nv_pc_pass2(struct nv_pc *pc, struct nv_basic_block *root) +{ + struct nv_pass pass; + + pass.pc = pc; + + pc->pass_seq++; + + nv_pass_flatten(&pass, root); + + nv_pc_pass_in_order(root, nv_pc_pass_pre_emission, pc); + + return 0; +} + +int +nv_pc_exec_pass2(struct nv_pc *pc) +{ + int i, ret; + + NV50_DBGMSG("preparing %u blocks for emission\n", pc->num_blocks); + + pc->num_blocks = 0; /* will reorder bb_list */ + + for (i = 0; i < pc->num_subroutines + 1; ++i) + if (pc->root[i] && (ret = nv_pc_pass2(pc, pc->root[i]))) + return ret; + return 0; +} + +static INLINE boolean +is_cmem_load(struct nv_instruction *nvi) +{ + return (nvi->opcode == NV_OP_LDA && + nvi->src[0]->value->reg.file >= NV_FILE_MEM_C(0) && + nvi->src[0]->value->reg.file <= NV_FILE_MEM_C(15)); +} + +static INLINE boolean +is_smem_load(struct nv_instruction *nvi) +{ + return (nvi->opcode == NV_OP_LDA && + (nvi->src[0]->value->reg.file == NV_FILE_MEM_S || + nvi->src[0]->value->reg.file <= NV_FILE_MEM_P)); +} + +static INLINE boolean +is_immd_move(struct nv_instruction *nvi) +{ + return (nvi->opcode == NV_OP_MOV && + nvi->src[0]->value->reg.file == NV_FILE_IMM); +} + +static INLINE void +check_swap_src_0_1(struct nv_instruction *nvi) +{ + static const ubyte cc_swapped[8] = { 0, 4, 2, 6, 1, 5, 3, 7 }; + + struct nv_ref *src0 = nvi->src[0], *src1 = nvi->src[1]; + + if (!nv_op_commutative(nvi->opcode)) + return; + assert(src0 && src1); + + if (src1->value->reg.file == NV_FILE_IMM) + return; + + if (is_cmem_load(src0->value->insn)) { + if (!is_cmem_load(src1->value->insn)) { + nvi->src[0] = src1; + nvi->src[1] = src0; + /* debug_printf("swapping cmem load to 1\n"); */ + } + } else + if (is_smem_load(src1->value->insn)) { + if (!is_smem_load(src0->value->insn)) { + nvi->src[0] = src1; + nvi->src[1] = src0; + /* debug_printf("swapping smem load to 0\n"); */ + } + } + + if (nvi->opcode == NV_OP_SET && nvi->src[0] != src0) + nvi->set_cond = cc_swapped[nvi->set_cond]; +} + +static int +nv_pass_fold_stores(struct nv_pass *ctx, struct nv_basic_block *b) +{ + struct nv_instruction *nvi, *sti, *next; + int j; + + for (sti = b->entry; sti; sti = next) { + next = sti->next; + + /* only handling MOV to $oX here */ + if (!sti->def[0] || sti->def[0]->reg.file != NV_FILE_OUT) + continue; + if (sti->opcode != NV_OP_MOV && sti->opcode != NV_OP_STA) + continue; + + nvi = sti->src[0]->value->insn; + if (!nvi || nvi->opcode == NV_OP_PHI || nv_is_vector_op(nvi->opcode)) + continue; + assert(nvi->def[0] == sti->src[0]->value); + + if (nvi->opcode == NV_OP_SELECT) + continue; + if (nvi->def[0]->refc > 1) + continue; + + /* cannot write to $oX when using immediate */ + for (j = 0; j < 4 && nvi->src[j]; ++j) + if (nvi->src[j]->value->reg.file == NV_FILE_IMM || + nvi->src[j]->value->reg.file == NV_FILE_MEM_L) + break; + if (j < 4 && nvi->src[j]) + continue; + + nvi->def[0] = sti->def[0]; + nvi->def[0]->insn = nvi; + nvi->fixed = sti->fixed; + + nv_nvi_delete(sti); + } + DESCEND_ARBITRARY(j, nv_pass_fold_stores); + + return 0; +} + +static int +nv_pass_fold_loads(struct nv_pass *ctx, struct nv_basic_block *b) +{ + struct nv_instruction *nvi, *ld; + int j; + + for (nvi = b->entry; nvi; nvi = nvi->next) { + check_swap_src_0_1(nvi); + + for (j = 0; j < 3; ++j) { + if (!nvi->src[j]) + break; + ld = nvi->src[j]->value->insn; + if (!ld) + continue; + + if (is_immd_move(ld) && nv50_nvi_can_use_imm(nvi, j)) { + nv_reference(ctx->pc, &nvi->src[j], ld->src[0]->value); + continue; + } + + if (ld->opcode != NV_OP_LDA) + continue; + if (!nv50_nvi_can_load(nvi, j, ld->src[0]->value)) + continue; + + if (j == 0 && ld->src[4]) /* can't load shared mem */ + continue; + + /* fold it ! */ + nv_reference(ctx->pc, &nvi->src[j], ld->src[0]->value); + if (ld->src[4]) + nv_reference(ctx->pc, &nvi->src[4], ld->src[4]->value); + + if (!nv_nvi_refcount(ld)) + nv_nvi_delete(ld); + } + } + DESCEND_ARBITRARY(j, nv_pass_fold_loads); + + return 0; +} + +/* NOTE: Assumes loads have not yet been folded. */ +static int +nv_pass_lower_mods(struct nv_pass *ctx, struct nv_basic_block *b) +{ + int j; + struct nv_instruction *nvi, *mi, *next; + ubyte mod; + + for (nvi = b->entry; nvi; nvi = next) { + next = nvi->next; + if (nvi->opcode == NV_OP_SUB) { + nvi->opcode = NV_OP_ADD; + nvi->src[1]->mod ^= NV_MOD_NEG; + } + + for (j = 0; j < 4 && nvi->src[j]; ++j) { + mi = nvi->src[j]->value->insn; + if (!mi) + continue; + if (mi->def[0]->refc > 1) + continue; + + if (mi->opcode == NV_OP_NEG) mod = NV_MOD_NEG; + else + if (mi->opcode == NV_OP_ABS) mod = NV_MOD_ABS; + else + continue; + assert(!(mod & mi->src[0]->mod & NV_MOD_NEG)); + + mod |= mi->src[0]->mod; + + if (mi->flags_def || mi->flags_src) + continue; + + if ((nvi->opcode == NV_OP_ABS) || (nvi->src[j]->mod & NV_MOD_ABS)) { + /* abs neg [abs] = abs */ + mod &= ~(NV_MOD_NEG | NV_MOD_ABS); + } else + if ((nvi->opcode == NV_OP_NEG) && (mod & NV_MOD_NEG)) { + /* neg as opcode and modifier on same insn cannot occur */ + /* neg neg abs = abs, neg neg = identity */ + assert(j == 0); + if (mod & NV_MOD_ABS) + nvi->opcode = NV_OP_ABS; + else + if (nvi->flags_def) + nvi->opcode = NV_OP_CVT; + else + nvi->opcode = NV_OP_MOV; + mod = 0; + } + + if ((nv50_supported_src_mods(nvi->opcode, j) & mod) != mod) + continue; + + nv_reference(ctx->pc, &nvi->src[j], mi->src[0]->value); + + nvi->src[j]->mod ^= mod; + } + + if (nvi->opcode == NV_OP_SAT) { + mi = nvi->src[0]->value->insn; + + if (mi->opcode != NV_OP_ADD && mi->opcode != NV_OP_MAD) + continue; + if (mi->flags_def || mi->def[0]->refc > 1) + continue; + + mi->saturate = 1; + mi->def[0] = nvi->def[0]; + mi->def[0]->insn = mi; + nv_nvi_delete(nvi); + } + } + DESCEND_ARBITRARY(j, nv_pass_lower_mods); + + return 0; +} + +#define SRC_IS_MUL(s) ((s)->insn && (s)->insn->opcode == NV_OP_MUL) + +static void +modifiers_apply(uint32_t *val, ubyte type, ubyte mod) +{ + if (mod & NV_MOD_ABS) { + if (type == NV_TYPE_F32) + *val &= 0x7fffffff; + else + if ((*val) & (1 << 31)) + *val = ~(*val) + 1; + } + if (mod & NV_MOD_NEG) { + if (type == NV_TYPE_F32) + *val ^= 0x80000000; + else + *val = ~(*val) + 1; + } +} + +static INLINE uint +modifiers_opcode(ubyte mod) +{ + switch (mod) { + case NV_MOD_NEG: return NV_OP_NEG; + case NV_MOD_ABS: return NV_OP_ABS; + case 0: + return NV_OP_MOV; + default: + return NV_OP_NOP; + } +} + +static void +constant_expression(struct nv_pc *pc, struct nv_instruction *nvi, + struct nv_value *src0, struct nv_value *src1) +{ + struct nv_value *val; + union { + float f32; + uint32_t u32; + int32_t s32; + } u0, u1, u; + ubyte type; + + if (!nvi->def[0]) + return; + type = nvi->def[0]->reg.type; + + u.u32 = 0; + u0.u32 = src0->reg.imm.u32; + u1.u32 = src1->reg.imm.u32; + + modifiers_apply(&u0.u32, type, nvi->src[0]->mod); + modifiers_apply(&u1.u32, type, nvi->src[1]->mod); + + switch (nvi->opcode) { + case NV_OP_MAD: + if (nvi->src[2]->value->reg.file != NV_FILE_GPR) + return; + /* fall through */ + case NV_OP_MUL: + switch (type) { + case NV_TYPE_F32: u.f32 = u0.f32 * u1.f32; break; + case NV_TYPE_U32: u.u32 = u0.u32 * u1.u32; break; + case NV_TYPE_S32: u.s32 = u0.s32 * u1.s32; break; + default: + assert(0); + break; + } + break; + case NV_OP_ADD: + switch (type) { + case NV_TYPE_F32: u.f32 = u0.f32 + u1.f32; break; + case NV_TYPE_U32: u.u32 = u0.u32 + u1.u32; break; + case NV_TYPE_S32: u.s32 = u0.s32 + u1.s32; break; + default: + assert(0); + break; + } + break; + case NV_OP_SUB: + switch (type) { + case NV_TYPE_F32: u.f32 = u0.f32 - u1.f32; break; + case NV_TYPE_U32: u.u32 = u0.u32 - u1.u32; break; + case NV_TYPE_S32: u.s32 = u0.s32 - u1.s32; break; + default: + assert(0); + break; + } + break; + default: + return; + } + + nvi->opcode = NV_OP_MOV; + + val = new_value(pc, NV_FILE_IMM, type); + + val->reg.imm.u32 = u.u32; + + nv_reference(pc, &nvi->src[1], NULL); + nv_reference(pc, &nvi->src[0], val); + + if (nvi->src[2]) { /* from MAD */ + nvi->src[1] = nvi->src[0]; + nvi->src[0] = nvi->src[2]; + nvi->src[2] = NULL; + nvi->opcode = NV_OP_ADD; + + if (val->reg.imm.u32 == 0) { + nvi->src[1] = NULL; + nvi->opcode = NV_OP_MOV; + } + } +} + +static void +constant_operand(struct nv_pc *pc, + struct nv_instruction *nvi, struct nv_value *val, int s) +{ + union { + float f32; + uint32_t u32; + int32_t s32; + } u; + int t = s ? 0 : 1; + uint op; + ubyte type; + + if (!nvi->def[0]) + return; + type = nvi->def[0]->reg.type; + + u.u32 = val->reg.imm.u32; + modifiers_apply(&u.u32, type, nvi->src[s]->mod); + + switch (nvi->opcode) { + case NV_OP_MUL: + if ((type == NV_TYPE_F32 && u.f32 == 1.0f) || + (NV_TYPE_ISINT(type) && u.u32 == 1)) { + if ((op = modifiers_opcode(nvi->src[t]->mod)) == NV_OP_NOP) + break; + nvi->opcode = op; + nv_reference(pc, &nvi->src[s], NULL); + nvi->src[0] = nvi->src[t]; + nvi->src[1] = NULL; + } else + if ((type == NV_TYPE_F32 && u.f32 == 2.0f) || + (NV_TYPE_ISINT(type) && u.u32 == 2)) { + nvi->opcode = NV_OP_ADD; + nv_reference(pc, &nvi->src[s], nvi->src[t]->value); + nvi->src[s]->mod = nvi->src[t]->mod; + } else + if (type == NV_TYPE_F32 && u.f32 == -1.0f) { + if (nvi->src[t]->mod & NV_MOD_NEG) + nvi->opcode = NV_OP_MOV; + else + nvi->opcode = NV_OP_NEG; + nv_reference(pc, &nvi->src[s], NULL); + nvi->src[0] = nvi->src[t]; + nvi->src[1] = NULL; + } else + if (type == NV_TYPE_F32 && u.f32 == -2.0f) { + nvi->opcode = NV_OP_ADD; + nv_reference(pc, &nvi->src[s], nvi->src[t]->value); + nvi->src[s]->mod = (nvi->src[t]->mod ^= NV_MOD_NEG); + } else + if (u.u32 == 0) { + nvi->opcode = NV_OP_MOV; + nv_reference(pc, &nvi->src[t], NULL); + if (s) { + nvi->src[0] = nvi->src[1]; + nvi->src[1] = NULL; + } + } + break; + case NV_OP_ADD: + if (u.u32 == 0) { + if ((op = modifiers_opcode(nvi->src[t]->mod)) == NV_OP_NOP) + break; + nvi->opcode = op; + nv_reference(pc, &nvi->src[s], NULL); + nvi->src[0] = nvi->src[t]; + nvi->src[1] = NULL; + } + break; + case NV_OP_RCP: + u.f32 = 1.0f / u.f32; + (val = new_value(pc, NV_FILE_IMM, NV_TYPE_F32))->reg.imm.f32 = u.f32; + nvi->opcode = NV_OP_MOV; + assert(s == 0); + nv_reference(pc, &nvi->src[0], val); + break; + case NV_OP_RSQ: + u.f32 = 1.0f / sqrtf(u.f32); + (val = new_value(pc, NV_FILE_IMM, NV_TYPE_F32))->reg.imm.f32 = u.f32; + nvi->opcode = NV_OP_MOV; + assert(s == 0); + nv_reference(pc, &nvi->src[0], val); + break; + default: + break; + } + + if (nvi->opcode == NV_OP_MOV && nvi->flags_def) { + struct nv_instruction *cvt = new_instruction_at(pc, nvi, NV_OP_CVT); + + nv_reference(pc, &cvt->src[0], nvi->def[0]); + + cvt->flags_def = nvi->flags_def; + nvi->flags_def = NULL; + } +} + +static int +nv_pass_lower_arith(struct nv_pass *ctx, struct nv_basic_block *b) +{ + struct nv_instruction *nvi, *next; + int j; + + for (nvi = b->entry; nvi; nvi = next) { + struct nv_value *src0, *src1, *src; + int mod; + + next = nvi->next; + + src0 = nvcg_find_immediate(nvi->src[0]); + src1 = nvcg_find_immediate(nvi->src[1]); + + if (src0 && src1) + constant_expression(ctx->pc, nvi, src0, src1); + else { + if (src0) + constant_operand(ctx->pc, nvi, src0, 0); + else + if (src1) + constant_operand(ctx->pc, nvi, src1, 1); + } + + /* try to combine MUL, ADD into MAD */ + if (nvi->opcode != NV_OP_ADD) + continue; + + src0 = nvi->src[0]->value; + src1 = nvi->src[1]->value; + + if (SRC_IS_MUL(src0) && src0->refc == 1) + src = src0; + else + if (SRC_IS_MUL(src1) && src1->refc == 1) + src = src1; + else + continue; + + /* could have an immediate from above constant_* */ + if (src0->reg.file != NV_FILE_GPR || src1->reg.file != NV_FILE_GPR) + continue; + + nvi->opcode = NV_OP_MAD; + mod = nvi->src[(src == src0) ? 0 : 1]->mod; + nv_reference(ctx->pc, &nvi->src[(src == src0) ? 0 : 1], NULL); + nvi->src[2] = nvi->src[(src == src0) ? 1 : 0]; + + assert(!(mod & ~NV_MOD_NEG)); + nvi->src[0] = new_ref(ctx->pc, src->insn->src[0]->value); + nvi->src[1] = new_ref(ctx->pc, src->insn->src[1]->value); + nvi->src[0]->mod = src->insn->src[0]->mod ^ mod; + nvi->src[1]->mod = src->insn->src[1]->mod; + } + DESCEND_ARBITRARY(j, nv_pass_lower_arith); + + return 0; +} + +/* TODO: redundant store elimination */ + +struct load_record { + struct load_record *next; + uint64_t data[2]; + struct nv_value *value; +}; + +#define LOAD_RECORD_POOL_SIZE 1024 + +struct nv_pass_reld_elim { + struct nv_pc *pc; + + struct load_record *imm; + struct load_record *mem_s; + struct load_record *mem_v; + struct load_record *mem_c[16]; + struct load_record *mem_l; + + struct load_record pool[LOAD_RECORD_POOL_SIZE]; + int alloc; +}; + +/* TODO: properly handle loads from l[] memory in the presence of stores */ +static int +nv_pass_reload_elim(struct nv_pass_reld_elim *ctx, struct nv_basic_block *b) +{ + struct load_record **rec, *it; + struct nv_instruction *ld, *next; + uint64_t data[2]; + struct nv_value *val; + int j; + + for (ld = b->entry; ld; ld = next) { + next = ld->next; + if (!ld->src[0]) + continue; + val = ld->src[0]->value; + rec = NULL; + + if (ld->opcode == NV_OP_LINTERP || ld->opcode == NV_OP_PINTERP) { + data[0] = val->reg.id; + data[1] = 0; + rec = &ctx->mem_v; + } else + if (ld->opcode == NV_OP_LDA) { + data[0] = val->reg.id; + data[1] = ld->src[4] ? ld->src[4]->value->n : ~0ULL; + if (val->reg.file >= NV_FILE_MEM_C(0) && + val->reg.file <= NV_FILE_MEM_C(15)) + rec = &ctx->mem_c[val->reg.file - NV_FILE_MEM_C(0)]; + else + if (val->reg.file == NV_FILE_MEM_S) + rec = &ctx->mem_s; + else + if (val->reg.file == NV_FILE_MEM_L) + rec = &ctx->mem_l; + } else + if ((ld->opcode == NV_OP_MOV) && (val->reg.file == NV_FILE_IMM)) { + data[0] = val->reg.imm.u32; + data[1] = 0; + rec = &ctx->imm; + } + + if (!rec || !ld->def[0]->refc) + continue; + + for (it = *rec; it; it = it->next) + if (it->data[0] == data[0] && it->data[1] == data[1]) + break; + + if (it) { + if (ld->def[0]->reg.id >= 0) + it->value = ld->def[0]; + else + if (!ld->fixed) + nvcg_replace_value(ctx->pc, ld->def[0], it->value); + } else { + if (ctx->alloc == LOAD_RECORD_POOL_SIZE) + continue; + it = &ctx->pool[ctx->alloc++]; + it->next = *rec; + it->data[0] = data[0]; + it->data[1] = data[1]; + it->value = ld->def[0]; + *rec = it; + } + } + + ctx->imm = NULL; + ctx->mem_s = NULL; + ctx->mem_v = NULL; + for (j = 0; j < 16; ++j) + ctx->mem_c[j] = NULL; + ctx->mem_l = NULL; + ctx->alloc = 0; + + DESCEND_ARBITRARY(j, nv_pass_reload_elim); + + return 0; +} + +static int +nv_pass_tex_mask(struct nv_pass *ctx, struct nv_basic_block *b) +{ + int i, c, j; + + for (i = 0; i < ctx->pc->num_instructions; ++i) { + struct nv_instruction *nvi = &ctx->pc->instructions[i]; + struct nv_value *def[4]; + + if (!nv_is_vector_op(nvi->opcode)) + continue; + nvi->tex_mask = 0; + + for (c = 0; c < 4; ++c) { + if (nvi->def[c]->refc) + nvi->tex_mask |= 1 << c; + def[c] = nvi->def[c]; + } + + j = 0; + for (c = 0; c < 4; ++c) + if (nvi->tex_mask & (1 << c)) + nvi->def[j++] = def[c]; + for (c = 0; c < 4; ++c) + if (!(nvi->tex_mask & (1 << c))) + nvi->def[j++] = def[c]; + assert(j == 4); + } + return 0; +} + +struct nv_pass_dce { + struct nv_pc *pc; + uint removed; +}; + +static int +nv_pass_dce(struct nv_pass_dce *ctx, struct nv_basic_block *b) +{ + int j; + struct nv_instruction *nvi, *next; + + for (nvi = b->phi ? b->phi : b->entry; nvi; nvi = next) { + next = nvi->next; + + if (inst_cullable(nvi)) { + nv_nvi_delete(nvi); + + ++ctx->removed; + } + } + DESCEND_ARBITRARY(j, nv_pass_dce); + + return 0; +} + +/* Register allocation inserted ELSE blocks for all IF/ENDIF without ELSE. + * Returns TRUE if @bb initiates an IF/ELSE/ENDIF clause, or is an IF with + * BREAK and dummy ELSE block. + */ +static INLINE boolean +bb_is_if_else_endif(struct nv_basic_block *bb) +{ + if (!bb->out[0] || !bb->out[1]) + return FALSE; + + if (bb->out[0]->out_kind[0] == CFG_EDGE_LOOP_LEAVE) { + return (bb->out[0]->out[1] == bb->out[1]->out[0] && + !bb->out[1]->out[1]); + } else { + return (bb->out[0]->out[0] == bb->out[1]->out[0] && + !bb->out[0]->out[1] && + !bb->out[1]->out[1]); + } +} + +/* predicate instructions and remove branch at the end */ +static void +predicate_instructions(struct nv_pc *pc, struct nv_basic_block *b, + struct nv_value *p, ubyte cc) +{ + struct nv_instruction *nvi; + + if (!b->entry) + return; + for (nvi = b->entry; nvi->next; nvi = nvi->next) { + if (!nvi_isnop(nvi)) { + nvi->cc = cc; + nv_reference(pc, &nvi->flags_src, p); + } + } + + if (nvi->opcode == NV_OP_BRA) + nv_nvi_delete(nvi); + else + if (!nvi_isnop(nvi)) { + nvi->cc = cc; + nv_reference(pc, &nvi->flags_src, p); + } +} + +/* NOTE: Run this after register allocation, we can just cut out the cflow + * instructions and hook the predicates to the conditional OPs if they are + * not using immediates; better than inserting SELECT to join definitions. + * + * NOTE: Should adapt prior optimization to make this possible more often. + */ +static int +nv_pass_flatten(struct nv_pass *ctx, struct nv_basic_block *b) +{ + struct nv_instruction *nvi; + struct nv_value *pred; + int i; + int n0 = 0, n1 = 0; + + if (bb_is_if_else_endif(b)) { + + NV50_DBGMSG("pass_flatten: IF/ELSE/ENDIF construct at BB:%i\n", b->id); + + for (n0 = 0, nvi = b->out[0]->entry; nvi; nvi = nvi->next, ++n0) + if (!nv50_nvi_can_predicate(nvi)) + break; + if (!nvi) { + for (n1 = 0, nvi = b->out[1]->entry; nvi; nvi = nvi->next, ++n1) + if (!nv50_nvi_can_predicate(nvi)) + break; +#ifdef NV50PC_DEBUG + if (nvi) { + debug_printf("cannot predicate: "); nv_print_instruction(nvi); + } + } else { + debug_printf("cannot predicate: "); nv_print_instruction(nvi); +#endif + } + + if (!nvi && n0 < 12 && n1 < 12) { /* 12 as arbitrary limit */ + assert(b->exit && b->exit->flags_src); + pred = b->exit->flags_src->value; + + predicate_instructions(ctx->pc, b->out[0], pred, NV_CC_NE | NV_CC_U); + predicate_instructions(ctx->pc, b->out[1], pred, NV_CC_EQ); + + assert(b->exit && b->exit->opcode == NV_OP_BRA); + nv_nvi_delete(b->exit); + + if (b->exit && b->exit->opcode == NV_OP_JOINAT) + nv_nvi_delete(b->exit); + + i = (b->out[0]->out_kind[0] == CFG_EDGE_LOOP_LEAVE) ? 1 : 0; + + if ((nvi = b->out[0]->out[i]->entry)) { + nvi->is_join = 0; + if (nvi->opcode == NV_OP_JOIN) + nv_nvi_delete(nvi); + } + } + } + DESCEND_ARBITRARY(i, nv_pass_flatten); + + return 0; +} + +/* local common subexpression elimination, stupid O(n^2) implementation */ +static int +nv_pass_cse(struct nv_pass *ctx, struct nv_basic_block *b) +{ + struct nv_instruction *ir, *ik, *next; + struct nv_instruction *entry = b->phi ? b->phi : b->entry; + int s; + unsigned int reps; + + do { + reps = 0; + for (ir = entry; ir; ir = next) { + next = ir->next; + for (ik = entry; ik != ir; ik = ik->next) { + if (ir->opcode != ik->opcode || ir->fixed) + continue; + + if (!ir->def[0] || !ik->def[0] || + ik->opcode == NV_OP_LDA || + ik->opcode == NV_OP_STA || + ik->opcode == NV_OP_MOV || + nv_is_vector_op(ik->opcode)) + continue; /* ignore loads, stores & moves */ + + if (ik->src[4] || ir->src[4]) + continue; /* don't mess with address registers */ + + if (ik->flags_src || ir->flags_src || + ik->flags_def || ir->flags_def) + continue; /* and also not with flags, for now */ + + if (ik->def[0]->reg.file == NV_FILE_OUT || + ir->def[0]->reg.file == NV_FILE_OUT || + !values_equal(ik->def[0], ir->def[0])) + continue; + + for (s = 0; s < 3; ++s) { + struct nv_value *a, *b; + + if (!ik->src[s]) { + if (ir->src[s]) + break; + continue; + } + if (ik->src[s]->mod != ir->src[s]->mod) + break; + a = ik->src[s]->value; + b = ir->src[s]->value; + if (a == b) + continue; + if (a->reg.file != b->reg.file || + a->reg.id < 0 || + a->reg.id != b->reg.id) + break; + } + if (s == 3) { + nv_nvi_delete(ir); + ++reps; + nvcg_replace_value(ctx->pc, ir->def[0], ik->def[0]); + break; + } + } + } + } while(reps); + + DESCEND_ARBITRARY(s, nv_pass_cse); + + return 0; +} + +static int +nv_pc_pass0(struct nv_pc *pc, struct nv_basic_block *root) +{ + struct nv_pass_reld_elim *reldelim; + struct nv_pass pass; + struct nv_pass_dce dce; + int ret; + + pass.n = 0; + pass.pc = pc; + + /* Do this first, so we don't have to pay attention + * to whether sources are supported memory loads. + */ + pc->pass_seq++; + ret = nv_pass_lower_arith(&pass, root); + if (ret) + return ret; + + pc->pass_seq++; + ret = nv_pass_lower_mods(&pass, root); + if (ret) + return ret; + + pc->pass_seq++; + ret = nv_pass_fold_loads(&pass, root); + if (ret) + return ret; + + pc->pass_seq++; + ret = nv_pass_fold_stores(&pass, root); + if (ret) + return ret; + + if (pc->opt_reload_elim) { + reldelim = CALLOC_STRUCT(nv_pass_reld_elim); + reldelim->pc = pc; + pc->pass_seq++; + ret = nv_pass_reload_elim(reldelim, root); + FREE(reldelim); + if (ret) + return ret; + } + + pc->pass_seq++; + ret = nv_pass_cse(&pass, root); + if (ret) + return ret; + + dce.pc = pc; + do { + dce.removed = 0; + pc->pass_seq++; + ret = nv_pass_dce(&dce, root); + if (ret) + return ret; + } while (dce.removed); + + ret = nv_pass_tex_mask(&pass, root); + if (ret) + return ret; + + return ret; +} + +int +nv_pc_exec_pass0(struct nv_pc *pc) +{ + int i, ret; + + for (i = 0; i < pc->num_subroutines + 1; ++i) + if (pc->root[i] && (ret = nv_pc_pass0(pc, pc->root[i]))) + return ret; + return 0; +} diff --git a/src/gallium/drivers/nv50/nv50_pc_print.c b/src/gallium/drivers/nv50/nv50_pc_print.c new file mode 100644 index 0000000..984f6cb --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_pc_print.c @@ -0,0 +1,320 @@ +/* + * Copyright 2010 Christoph Bumiller + * + * 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 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 "nv50_context.h" +#include "nv50_pc.h" + +#define NVXX_DEBUG 0 + +#define PRINT(args...) debug_printf(args) + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) +#endif + +static const char *norm = "\x1b[00m"; +static const char *gree = "\x1b[32m"; +static const char *blue = "\x1b[34m"; +static const char *cyan = "\x1b[36m"; +static const char *orng = "\x1b[33m"; +static const char *mgta = "\x1b[35m"; + +static const char *nv_opcode_names[NV_OP_COUNT + 1] = { + "phi", + "extract", + "combine", + "lda", + "sta", + "mov", + "add", + "sub", + "neg", + "mul", + "mad", + "cvt", + "sat", + "not", + "and", + "or", + "xor", + "shl", + "shr", + "rcp", + "undef", + "rsqrt", + "lg2", + "sin", + "cos", + "ex2", + "presin", + "preex2", + "min", + "max", + "set", + "sad", + "kil", + "bra", + "call", + "ret", + "break", + "breakaddr", + "joinat", + "tex", + "texbias", + "texlod", + "texfetch", + "texsize", + "dfdx", + "dfdy", + "quadop", + "linterp", + "pinterp", + "abs", + "ceil", + "floor", + "trunc", + "nop", + "select", + "export", + "join", + "BAD_OP" +}; + +static const char *nv_cond_names[] = +{ + "never", "lt" , "eq" , "le" , "gt" , "ne" , "ge" , "", + "never", "ltu", "equ", "leu", "gtu", "neu", "geu", "", + "o", "c", "a", "s" +}; + +static const char *nv_modifier_strings[] = +{ + "", + "neg", + "abs", + "neg abs", + "not", + "not neg" + "not abs", + "not neg abs", + "sat", + "BAD_MOD" +}; + +const char * +nv_opcode_name(uint opcode) +{ + return nv_opcode_names[MIN2(opcode, ARRAY_SIZE(nv_opcode_names) - 1)]; +} + +static INLINE const char * +nv_type_name(ubyte type) +{ + switch (type) { + case NV_TYPE_U16: return "u16"; + case NV_TYPE_S16: return "s16"; + case NV_TYPE_F32: return "f32"; + case NV_TYPE_U32: return "u32"; + case NV_TYPE_S32: return "s32"; + case NV_TYPE_P32: return "p32"; + case NV_TYPE_F64: return "f64"; + default: + return "BAD_TYPE"; + } +} + +static INLINE const char * +nv_cond_name(ubyte cc) +{ + return nv_cond_names[MIN2(cc, 19)]; +} + +static INLINE const char * +nv_modifier_string(ubyte mod) +{ + return nv_modifier_strings[MIN2(mod, 9)]; +} + +static INLINE int +nv_value_id(struct nv_value *value) +{ + if (value->join->reg.id >= 0) + return value->join->reg.id; + return value->n; +} + +static INLINE boolean +nv_value_allocated(struct nv_value *value) +{ + return (value->reg.id >= 0) ? TRUE : FALSE; +} + +static INLINE void +nv_print_address(const char c, int buf, struct nv_value *a, int offset) +{ + const char ac = (a && nv_value_allocated(a)) ? '$' : '%'; + + if (buf >= 0) + PRINT(" %s%c%i[", cyan, c, buf); + else + PRINT(" %s%c[", cyan, c); + if (a) + PRINT("%s%ca%i%s+", mgta, ac, nv_value_id(a), cyan); + PRINT("%s0x%x%s]", orng, offset, cyan); +} + +static INLINE void +nv_print_cond(struct nv_instruction *nvi) +{ + char pfx = nv_value_allocated(nvi->flags_src->value->join) ? '$' : '%'; + + PRINT("%s%s %s%cc%i ", + gree, nv_cond_name(nvi->cc), + mgta, pfx, nv_value_id(nvi->flags_src->value)); +} + +static INLINE void +nv_print_value(struct nv_value *value, struct nv_value *ind, ubyte type) +{ + char reg_pfx = '$'; + + if (type == NV_TYPE_ANY) + type = value->reg.type; + + if (value->reg.file != NV_FILE_FLAGS) + PRINT(" %s%s", gree, nv_type_name(type)); + + if (!nv_value_allocated(value->join)) + reg_pfx = '%'; + + switch (value->reg.file) { + case NV_FILE_GPR: + PRINT(" %s%cr%i", blue, reg_pfx, nv_value_id(value)); + break; + case NV_FILE_OUT: + PRINT(" %s%co%i", mgta, reg_pfx, nv_value_id(value)); + break; + case NV_FILE_ADDR: + PRINT(" %s%ca%i", mgta, reg_pfx, nv_value_id(value)); + break; + case NV_FILE_FLAGS: + PRINT(" %s%cc%i", mgta, reg_pfx, nv_value_id(value)); + break; + case NV_FILE_MEM_L: + nv_print_address('l', -1, ind, nv_value_id(value)); + break; + case NV_FILE_MEM_S: + nv_print_address('s', -1, ind, 4 * nv_value_id(value)); + break; + case NV_FILE_MEM_P: + nv_print_address('p', -1, ind, 4 * nv_value_id(value)); + break; + case NV_FILE_MEM_V: + nv_print_address('v', -1, ind, 4 * nv_value_id(value)); + break; + case NV_FILE_IMM: + switch (type) { + case NV_TYPE_U16: + case NV_TYPE_S16: + PRINT(" %s0x%04x", orng, value->reg.imm.u32); + break; + case NV_TYPE_F32: + PRINT(" %s%f", orng, value->reg.imm.f32); + break; + case NV_TYPE_F64: + PRINT(" %s%f", orng, value->reg.imm.f64); + break; + case NV_TYPE_U32: + case NV_TYPE_S32: + case NV_TYPE_P32: + PRINT(" %s0x%08x", orng, value->reg.imm.u32); + break; + } + break; + default: + if (value->reg.file >= NV_FILE_MEM_G(0) && + value->reg.file <= NV_FILE_MEM_G(15)) + nv_print_address('g', value->reg.file - NV_FILE_MEM_G(0), ind, + nv_value_id(value) * 4); + else + if (value->reg.file >= NV_FILE_MEM_C(0) && + value->reg.file <= NV_FILE_MEM_C(15)) + nv_print_address('c', value->reg.file - NV_FILE_MEM_C(0), ind, + nv_value_id(value) * 4); + else + NOUVEAU_ERR(" BAD_FILE[%i]", nv_value_id(value)); + break; + } +} + +static INLINE void +nv_print_ref(struct nv_ref *ref, struct nv_value *ind) +{ + nv_print_value(ref->value, ind, ref->typecast); +} + +void +nv_print_instruction(struct nv_instruction *i) +{ + int j; + + PRINT("%i: ", i->serial); + + if (i->flags_src) + nv_print_cond(i); + + PRINT("%s", gree); + if (i->opcode == NV_OP_SET) + PRINT("set %s", nv_cond_name(i->set_cond)); + else + if (i->saturate) + PRINT("sat %s", nv_opcode_name(i->opcode)); + else + PRINT("%s", nv_opcode_name(i->opcode)); + + if (i->flags_def) + nv_print_value(i->flags_def, NULL, NV_TYPE_ANY); + + /* Only STORE & STA can write to MEM, and they do not def + * anything, so the address is thus part of the source. + */ + if (i->def[0]) + nv_print_value(i->def[0], NULL, NV_TYPE_ANY); + else + if (i->target) + PRINT(" %s(BB:%i)", orng, i->target->id); + else + PRINT(" #"); + + for (j = 0; j < 4; ++j) { + if (!i->src[j]) + continue; + + if (i->src[j]->mod) + PRINT(" %s%s", gree, nv_modifier_string(i->src[j]->mod)); + + nv_print_ref(i->src[j], + (j == nv50_indirect_opnd(i)) ? + i->src[4]->value : NULL); + } + PRINT(" %s%c\n", norm, i->is_long ? 'l' : 's'); +} diff --git a/src/gallium/drivers/nv50/nv50_pc_regalloc.c b/src/gallium/drivers/nv50/nv50_pc_regalloc.c new file mode 100644 index 0000000..39ae366 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_pc_regalloc.c @@ -0,0 +1,962 @@ +/* + * Copyright 2010 Christoph Bumiller + * + * 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 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 NV50PC_DEBUG */ + +/* #define NV50_RA_DEBUG_LIVEI */ +/* #define NV50_RA_DEBUG_LIVE_SETS */ +/* #define NV50_RA_DEBUG_JOIN */ + +#include "nv50_context.h" +#include "nv50_pc.h" + +#include "util/u_simple_list.h" + +#define NUM_REGISTER_FILES 4 + +struct register_set { + struct nv_pc *pc; + + uint32_t last[NUM_REGISTER_FILES]; + uint32_t bits[NUM_REGISTER_FILES][8]; +}; + +struct nv_pc_pass { + struct nv_pc *pc; + + struct nv_instruction **insns; + int num_insns; + + uint pass_seq; +}; + +static void +ranges_coalesce(struct nv_range *range) +{ + while (range->next && range->end >= range->next->bgn) { + struct nv_range *rnn = range->next->next; + assert(range->bgn <= range->next->bgn); + range->end = MAX2(range->end, range->next->end); + FREE(range->next); + range->next = rnn; + } +} + +static boolean +add_range_ex(struct nv_value *val, int bgn, int end, struct nv_range *new_range) +{ + struct nv_range *range, **nextp = &val->livei; + + for (range = val->livei; range; range = range->next) { + if (end < range->bgn) + break; /* insert before */ + + if (bgn > range->end) { + nextp = &range->next; + continue; /* insert after */ + } + + /* overlap */ + if (bgn < range->bgn) { + range->bgn = bgn; + if (end > range->end) + range->end = end; + ranges_coalesce(range); + return TRUE; + } + if (end > range->end) { + range->end = end; + ranges_coalesce(range); + return TRUE; + } + assert(bgn >= range->bgn); + assert(end <= range->end); + return TRUE; + } + + if (!new_range) + new_range = CALLOC_STRUCT(nv_range); + + new_range->bgn = bgn; + new_range->end = end; + new_range->next = range; + *(nextp) = new_range; + return FALSE; +} + +static void +add_range(struct nv_value *val, struct nv_basic_block *b, int end) +{ + int bgn; + + if (!val->insn) /* ignore non-def values */ + return; + assert(b->entry->serial <= b->exit->serial); + assert(b->phi->serial <= end); + assert(b->exit->serial + 1 >= end); + + bgn = val->insn->serial; + if (bgn < b->entry->serial || bgn > b->exit->serial) + bgn = b->entry->serial; + + assert(bgn <= end); + + add_range_ex(val, bgn, end, NULL); +} + +#if defined(NV50_RA_DEBUG_JOIN) || defined(NV50_RA_DEBUG_LIVEI) +static void +livei_print(struct nv_value *a) +{ + struct nv_range *r = a->livei; + + debug_printf("livei %i: ", a->n); + while (r) { + debug_printf("[%i, %i) ", r->bgn, r->end); + r = r->next; + } + debug_printf("\n"); +} +#endif + +static void +livei_unify(struct nv_value *dst, struct nv_value *src) +{ + struct nv_range *range, *next; + + for (range = src->livei; range; range = next) { + next = range->next; + if (add_range_ex(dst, range->bgn, range->end, range)) + FREE(range); + } + src->livei = NULL; +} + +static void +livei_release(struct nv_value *val) +{ + struct nv_range *range, *next; + + for (range = val->livei; range; range = next) { + next = range->next; + FREE(range); + } +} + +static boolean +livei_have_overlap(struct nv_value *a, struct nv_value *b) +{ + struct nv_range *r_a, *r_b; + + for (r_a = a->livei; r_a; r_a = r_a->next) { + for (r_b = b->livei; r_b; r_b = r_b->next) { + if (r_b->bgn < r_a->end && + r_b->end > r_a->bgn) + return TRUE; + } + } + return FALSE; +} + +static int +livei_end(struct nv_value *a) +{ + struct nv_range *r = a->livei; + + assert(r); + while (r->next) + r = r->next; + return r->end; +} + +static boolean +livei_contains(struct nv_value *a, int pos) +{ + struct nv_range *r; + + for (r = a->livei; r && r->bgn <= pos; r = r->next) + if (r->end > pos) + return TRUE; + return FALSE; +} + +static boolean +reg_assign(struct register_set *set, struct nv_value **def, int n) +{ + int i, id, s; + uint m; + int f = def[0]->reg.file; + + s = n << (nv_type_order(def[0]->reg.type) - 1); + m = (1 << s) - 1; + + id = set->last[f]; + + for (i = 0; i * 32 < set->last[f]; ++i) { + if (set->bits[f][i] == 0xffffffff) + continue; + + for (id = 0; id < 32; id += s) + if (!(set->bits[f][i] & (m << id))) + break; + if (id < 32) + break; + } + if (i * 32 + id > set->last[f]) + return FALSE; + + set->bits[f][i] |= m << id; + + id += i * 32; + + set->pc->max_reg[f] = MAX2(set->pc->max_reg[f], id + s - 1); + + id >>= nv_type_order(def[0]->reg.type) - 1; + + for (i = 0; i < n; ++i) + if (def[i]->livei) + def[i]->reg.id = id++; + + return TRUE; +} + +static INLINE void +reg_occupy(struct register_set *set, struct nv_value *val) +{ + int s, id = val->reg.id, f = val->reg.file; + uint m; + + if (id < 0) + return; + s = nv_type_order(val->reg.type) - 1; + id <<= s; + m = (1 << (1 << s)) - 1; + + set->bits[f][id / 32] |= m << (id % 32); + + if (set->pc->max_reg[f] < id) + set->pc->max_reg[f] = id; +} + +static INLINE void +reg_release(struct register_set *set, struct nv_value *val) +{ + int s, id = val->reg.id, f = val->reg.file; + uint m; + + if (id < 0) + return; + + s = nv_type_order(val->reg.type) - 1; + id <<= s; + m = (1 << (1 << s)) - 1; + + set->bits[f][id / 32] &= ~(m << (id % 32)); +} + +static INLINE boolean +join_allowed(struct nv_pc_pass *ctx, struct nv_value *a, struct nv_value *b) +{ + int i; + struct nv_value *val; + + if (a->reg.file != b->reg.file || + nv_type_sizeof(a->reg.type) != nv_type_sizeof(b->reg.type)) + return FALSE; + + if (a->join->reg.id == b->join->reg.id) + return TRUE; + +#if 1 + /* either a or b or both have been assigned */ + + if (a->join->reg.id >= 0 && b->join->reg.id >= 0) + return FALSE; + else + if (b->join->reg.id >= 0) { + if (a->join->reg.id >= 0) + return FALSE; + val = a; + a = b; + b = val; + } + + for (i = 0; i < ctx->pc->num_values; ++i) { + val = &ctx->pc->values[i]; + + if (val->join->reg.id != a->join->reg.id) + continue; + if (val->join != a->join && livei_have_overlap(val->join, b->join)) + return FALSE; + } + return TRUE; +#endif + return FALSE; +} + +static INLINE void +do_join_values(struct nv_pc_pass *ctx, struct nv_value *a, struct nv_value *b) +{ + int j; + struct nv_value *bjoin = b->join; + + if (b->join->reg.id >= 0) + a->join->reg.id = b->join->reg.id; + + livei_unify(a->join, b->join); + +#ifdef NV50_RA_DEBUG_JOIN + debug_printf("joining %i to %i\n", b->n, a->n); +#endif + + /* make a->join the new representative */ + for (j = 0; j < ctx->pc->num_values; ++j) + if (ctx->pc->values[j].join == bjoin) + ctx->pc->values[j].join = a->join; + + assert(b->join == a->join); +} + +static INLINE void +try_join_values(struct nv_pc_pass *ctx, struct nv_value *a, struct nv_value *b) +{ + if (!join_allowed(ctx, a, b)) { +#ifdef NV50_RA_DEBUG_JOIN + debug_printf("cannot join %i to %i: not allowed\n", b->n, a->n); +#endif + return; + } + if (livei_have_overlap(a->join, b->join)) { +#ifdef NV50_RA_DEBUG_JOIN + debug_printf("cannot join %i to %i: livei overlap\n", b->n, a->n); + livei_print(a); + livei_print(b); +#endif + return; + } + + do_join_values(ctx, a, b); +} + +static INLINE boolean +need_new_else_block(struct nv_basic_block *b, struct nv_basic_block *p) +{ + int i = 0, n = 0; + + for (; i < 2; ++i) + if (p->out[i] && !IS_LOOP_EDGE(p->out_kind[i])) + ++n; + + return (b->num_in > 1) && (n == 2); +} + +static int +phi_opnd_for_bb(struct nv_instruction *phi, struct nv_basic_block *b, + struct nv_basic_block *tb) +{ + int i, j; + + for (j = -1, i = 0; i < 4 && phi->src[i]; ++i) { + if (!nvbb_reachable_by(b, phi->src[i]->value->insn->bb, tb)) + continue; + /* NOTE: back-edges are ignored by the reachable-by check */ + if (j < 0 || !nvbb_reachable_by(phi->src[j]->value->insn->bb, + phi->src[i]->value->insn->bb, tb)) + j = i; + } + return j; +} + +/* For each operand of each PHI in b, generate a new value by inserting a MOV + * at the end of the block it is coming from and replace the operand with its + * result. This eliminates liveness conflicts and enables us to let values be + * copied to the right register if such a conflict exists nonetheless. + * + * These MOVs are also crucial in making sure the live intervals of phi srces + * are extended until the end of the loop, since they are not included in the + * live-in sets. + */ +static int +pass_generate_phi_movs(struct nv_pc_pass *ctx, struct nv_basic_block *b) +{ + struct nv_instruction *i, *ni; + struct nv_value *val; + struct nv_basic_block *p, *pn; + int n, j; + + b->pass_seq = ctx->pc->pass_seq; + + for (n = 0; n < b->num_in; ++n) { + p = pn = b->in[n]; + assert(p); + + if (need_new_else_block(b, p)) { + pn = new_basic_block(ctx->pc); + + if (p->out[0] == b) + p->out[0] = pn; + else + p->out[1] = pn; + + if (p->exit->target == b) /* target to new else-block */ + p->exit->target = pn; + + b->in[n] = pn; + + pn->out[0] = b; + pn->in[0] = p; + pn->num_in = 1; + } + ctx->pc->current_block = pn; + + for (i = b->phi; i && i->opcode == NV_OP_PHI; i = i->next) { + if ((j = phi_opnd_for_bb(i, p, b)) < 0) + continue; + val = i->src[j]->value; + + if (i->src[j]->flags) { + val = val->insn->src[0]->value; + while (j < 4 && i->src[j]) + ++j; + assert(j < 4); + } + + ni = new_instruction(ctx->pc, NV_OP_MOV); + + /* TODO: insert instruction at correct position in the first place */ + if (ni->prev && ni->prev->target) + nv_nvi_permute(ni->prev, ni); + + ni->def[0] = new_value(ctx->pc, val->reg.file, val->reg.type); + ni->def[0]->insn = ni; + ni->src[0] = new_ref(ctx->pc, val); + + nv_reference(ctx->pc, &i->src[j], ni->def[0]); + + i->src[j]->flags = 1; + } + + if (pn != p && pn->exit) { + ctx->pc->current_block = b->in[n ? 0 : 1]; + ni = new_instruction(ctx->pc, NV_OP_BRA); + ni->target = b; + ni->is_terminator = 1; + } + } + + for (j = 0; j < 2; ++j) + if (b->out[j] && b->out[j]->pass_seq < ctx->pc->pass_seq) + pass_generate_phi_movs(ctx, b->out[j]); + + return 0; +} + +static int +pass_join_values(struct nv_pc_pass *ctx, int iter) +{ + int c, n; + + for (n = 0; n < ctx->num_insns; ++n) { + struct nv_instruction *i = ctx->insns[n]; + + switch (i->opcode) { + case NV_OP_PHI: + if (iter != 2) + break; + for (c = 0; c < 4 && i->src[c]; ++c) + try_join_values(ctx, i->def[0], i->src[c]->value); + break; + case NV_OP_MOV: + if ((iter == 2) && i->src[0]->value->insn && + !nv_is_vector_op(i->src[0]->value->join->insn->opcode)) + try_join_values(ctx, i->def[0], i->src[0]->value); + break; + case NV_OP_SELECT: + if (iter != 1) + break; + for (c = 0; c < 4 && i->src[c]; ++c) { + assert(join_allowed(ctx, i->def[0], i->src[c]->value)); + do_join_values(ctx, i->def[0], i->src[c]->value); + } + break; + case NV_OP_TEX: + case NV_OP_TXB: + case NV_OP_TXL: + case NV_OP_TXQ: + if (iter) + break; + for (c = 0; c < 4; ++c) { + if (!i->src[c]) + break; + do_join_values(ctx, i->def[c], i->src[c]->value); + } + break; + default: + break; + } + } + return 0; +} + +/* Order the instructions so that live intervals can be expressed in numbers. */ +static void +pass_order_instructions(void *priv, struct nv_basic_block *b) +{ + struct nv_pc_pass *ctx = (struct nv_pc_pass *)priv; + struct nv_instruction *i; + + b->pass_seq = ctx->pc->pass_seq; + + assert(!b->exit || !b->exit->next); + for (i = b->phi; i; i = i->next) { + i->serial = ctx->num_insns; + ctx->insns[ctx->num_insns++] = i; + } +} + +static void +bb_live_set_print(struct nv_pc *pc, struct nv_basic_block *b) +{ +#ifdef NV50_RA_DEBUG_LIVE_SETS + int j; + struct nv_value *val; + + debug_printf("LIVE-INs of BB:%i: ", b->id); + + for (j = 0; j < pc->num_values; ++j) { + if (!(b->live_set[j / 32] & (1 << (j % 32)))) + continue; + val = &pc->values[j]; + if (!val->insn) + continue; + debug_printf("%i ", val->n); + } + debug_printf("\n"); +#endif +} + +static INLINE void +live_set_add(struct nv_basic_block *b, struct nv_value *val) +{ + if (!val->insn) /* don't add non-def values */ + return; + b->live_set[val->n / 32] |= 1 << (val->n % 32); +} + +static INLINE void +live_set_rem(struct nv_basic_block *b, struct nv_value *val) +{ + b->live_set[val->n / 32] &= ~(1 << (val->n % 32)); +} + +static INLINE boolean +live_set_test(struct nv_basic_block *b, struct nv_ref *ref) +{ + int n = ref->value->n; + return b->live_set[n / 32] & (1 << (n % 32)); +} + +/* The live set of a block contains those values that are live immediately + * before the beginning of the block, so do a backwards scan. + */ +static int +pass_build_live_sets(struct nv_pc_pass *ctx, struct nv_basic_block *b) +{ + struct nv_instruction *i; + int j, n, ret = 0; + + if (b->pass_seq >= ctx->pc->pass_seq) + return 0; + b->pass_seq = ctx->pc->pass_seq; + + /* slight hack for undecidedness: set phi = entry if it's undefined */ + if (!b->phi) + b->phi = b->entry; + + for (n = 0; n < 2; ++n) { + if (!b->out[n] || b->out[n] == b) + continue; + ret = pass_build_live_sets(ctx, b->out[n]); + if (ret) + return ret; + + if (n == 0) { + for (j = 0; j < (ctx->pc->num_values + 31) / 32; ++j) + b->live_set[j] = b->out[n]->live_set[j]; + } else { + for (j = 0; j < (ctx->pc->num_values + 31) / 32; ++j) + b->live_set[j] |= b->out[n]->live_set[j]; + } + } + + if (!b->entry) + return 0; + + bb_live_set_print(ctx->pc, b); + + for (i = b->exit; i != b->entry->prev; i = i->prev) { + for (j = 0; j < 4; j++) { + if (!i->def[j]) + break; + live_set_rem(b, i->def[j]); + } + for (j = 0; j < 4; j++) { + if (!i->src[j]) + break; + live_set_add(b, i->src[j]->value); + } + if (i->src[4]) + live_set_add(b, i->src[4]->value); + if (i->flags_def) + live_set_rem(b, i->flags_def); + if (i->flags_src) + live_set_add(b, i->flags_src->value); + } + for (i = b->phi; i && i->opcode == NV_OP_PHI; i = i->next) + live_set_rem(b, i->def[0]); + + bb_live_set_print(ctx->pc, b); + + return 0; +} + +static void collect_live_values(struct nv_basic_block *b, const int n) +{ + int i; + + if (b->out[0]) { + if (b->out[1]) { /* what to do about back-edges ? */ + for (i = 0; i < n; ++i) + b->live_set[i] = b->out[0]->live_set[i] | b->out[1]->live_set[i]; + } else { + memcpy(b->live_set, b->out[0]->live_set, n * sizeof(uint32_t)); + } + } else + if (b->out[1]) { + memcpy(b->live_set, b->out[1]->live_set, n * sizeof(uint32_t)); + } else { + memset(b->live_set, 0, n * sizeof(uint32_t)); + } +} + +/* NOTE: the live intervals of phi functions start at the first non-phi insn. */ +static int +pass_build_intervals(struct nv_pc_pass *ctx, struct nv_basic_block *b) +{ + struct nv_instruction *i, *i_stop; + int j, s; + const int n = (ctx->pc->num_values + 31) / 32; + + /* verify that first block does not have live-in values */ + if (b->num_in == 0) + for (j = 0; j < n; ++j) + assert(b->live_set[j] == 0); + + collect_live_values(b, n); + + /* remove live-outs def'd in a parallel block, hopefully they're all phi'd */ + for (j = 0; j < 2; ++j) { + if (!b->out[j] || !b->out[j]->phi) + continue; + for (i = b->out[j]->phi; i->opcode == NV_OP_PHI; i = i->next) { + live_set_rem(b, i->def[0]); + + for (s = 0; s < 4; ++s) { + if (!i->src[s]) + break; + assert(i->src[s]->value->insn); + if (nvbb_reachable_by(b, i->src[s]->value->insn->bb, b->out[j])) + live_set_add(b, i->src[s]->value); + else + live_set_rem(b, i->src[s]->value); + } + } + } + + /* remaining live-outs are live until the end */ + if (b->exit) { + for (j = 0; j < ctx->pc->num_values; ++j) { + if (!(b->live_set[j / 32] & (1 << (j % 32)))) + continue; + add_range(&ctx->pc->values[j], b, b->exit->serial + 1); +#ifdef NV50_RA_DEBUG_LIVEI + debug_printf("adding range for live value %i: ", j); + livei_print(&ctx->pc->values[j]); +#endif + + } + } + + i_stop = b->entry ? b->entry->prev : NULL; + + /* don't have to include phi functions here (will have 0 live range) */ + for (i = b->exit; i != i_stop; i = i->prev) { + assert(i->serial >= b->phi->serial && i->serial <= b->exit->serial); + for (j = 0; j < 4; ++j) { + if (i->def[j]) + live_set_rem(b, i->def[j]); + } + if (i->flags_def) + live_set_rem(b, i->flags_def); + + for (j = 0; j < 5; ++j) { + if (i->src[j] && !live_set_test(b, i->src[j])) { + live_set_add(b, i->src[j]->value); + add_range(i->src[j]->value, b, i->serial); +#ifdef NV50_RA_DEBUG_LIVEI + debug_printf("adding range for source %i (ends living): ", + i->src[j]->value->n); + livei_print(i->src[j]->value); +#endif + } + } + if (i->flags_src && !live_set_test(b, i->flags_src)) { + live_set_add(b, i->flags_src->value); + add_range(i->flags_src->value, b, i->serial); +#ifdef NV50_RA_DEBUG_LIVEI + debug_printf("adding range for source %i (ends living): ", + i->flags_src->value->n); + livei_print(i->flags_src->value); +#endif + } + } + + b->pass_seq = ctx->pc->pass_seq; + + if (b->out[0] && b->out[0]->pass_seq < ctx->pc->pass_seq) + pass_build_intervals(ctx, b->out[0]); + + if (b->out[1] && b->out[1]->pass_seq < ctx->pc->pass_seq) + pass_build_intervals(ctx, b->out[1]); + + return 0; +} + +static INLINE void +nv50_ctor_register_set(struct nv_pc *pc, struct register_set *set) +{ + memset(set, 0, sizeof(*set)); + + set->last[NV_FILE_GPR] = 255; + set->last[NV_FILE_OUT] = 127; + set->last[NV_FILE_FLAGS] = 4; + set->last[NV_FILE_ADDR] = 4; + + set->pc = pc; +} + +static void +insert_ordered_tail(struct nv_value *list, struct nv_value *nval) +{ + struct nv_value *elem; + + for (elem = list->prev; + elem != list && elem->livei->bgn > nval->livei->bgn; + elem = elem->prev); + /* now elem begins before or at the same time as val */ + + nval->prev = elem; + nval->next = elem->next; + elem->next->prev = nval; + elem->next = nval; +} + +static int +pass_linear_scan(struct nv_pc_pass *ctx, int iter) +{ + struct nv_instruction *i; + struct register_set f, free; + int k, n; + struct nv_value *cur, *val, *tmp[2]; + struct nv_value active, inactive, handled, unhandled; + + make_empty_list(&active); + make_empty_list(&inactive); + make_empty_list(&handled); + make_empty_list(&unhandled); + + nv50_ctor_register_set(ctx->pc, &free); + + /* joined values should have range = NULL and thus not be added; + * also, fixed memory values won't be added because they're not + * def'd, just used + */ + for (n = 0; n < ctx->num_insns; ++n) { + i = ctx->insns[n]; + + for (k = 0; k < 4; ++k) { + if (i->def[k] && i->def[k]->livei) + insert_ordered_tail(&unhandled, i->def[k]); + else + if (0 && i->def[k]) + debug_printf("skipping def'd value %i: no livei\n", i->def[k]->n); + } + if (i->flags_def && i->flags_def->livei) + insert_ordered_tail(&unhandled, i->flags_def); + } + + for (val = unhandled.next; val != unhandled.prev; val = val->next) { + assert(val->join == val); + assert(val->livei->bgn <= val->next->livei->bgn); + } + + foreach_s(cur, tmp[0], &unhandled) { + remove_from_list(cur); + + foreach_s(val, tmp[1], &active) { + if (livei_end(val) <= cur->livei->bgn) { + reg_release(&free, val); + move_to_head(&handled, val); + } else + if (!livei_contains(val, cur->livei->bgn)) { + reg_release(&free, val); + move_to_head(&inactive, val); + } + } + + foreach_s(val, tmp[1], &inactive) { + if (livei_end(val) <= cur->livei->bgn) + move_to_head(&handled, val); + else + if (livei_contains(val, cur->livei->bgn)) { + reg_occupy(&free, val); + move_to_head(&active, val); + } + } + + f = free; + + foreach(val, &inactive) + if (livei_have_overlap(val, cur)) + reg_occupy(&f, val); + + foreach(val, &unhandled) + if (val->reg.id >= 0 && livei_have_overlap(val, cur)) + reg_occupy(&f, val); + + if (cur->reg.id < 0) { + boolean mem = FALSE; + + if (nv_is_vector_op(cur->insn->opcode)) + mem = !reg_assign(&f, &cur->insn->def[0], 4); + else + if (iter) + mem = !reg_assign(&f, &cur, 1); + + if (mem) { + NOUVEAU_ERR("out of registers\n"); + abort(); + } + } + insert_at_head(&active, cur); + reg_occupy(&free, cur); + } + + return 0; +} + +static int +nv_pc_pass1(struct nv_pc *pc, struct nv_basic_block *root) +{ + struct nv_pc_pass *ctx; + int i, ret; + + NV50_DBGMSG("REGISTER ALLOCATION - entering\n"); + + ctx = CALLOC_STRUCT(nv_pc_pass); + if (!ctx) + return -1; + ctx->pc = pc; + + ctx->insns = CALLOC(NV_PC_MAX_INSTRUCTIONS, sizeof(struct nv_instruction *)); + if (!ctx->insns) { + FREE(ctx); + return -1; + } + + pc->pass_seq++; + ret = pass_generate_phi_movs(ctx, root); + assert(!ret); + + for (i = 0; i < pc->loop_nesting_bound; ++i) { + pc->pass_seq++; + ret = pass_build_live_sets(ctx, root); + assert(!ret && "live sets"); + if (ret) { + NOUVEAU_ERR("failed to build live sets (iteration %d)\n", i); + goto out; + } + } + + pc->pass_seq++; + nv_pc_pass_in_order(root, pass_order_instructions, ctx); + + pc->pass_seq++; + ret = pass_build_intervals(ctx, root); + assert(!ret && "build intervals"); + if (ret) { + NOUVEAU_ERR("failed to build live intervals\n"); + goto out; + } + +#ifdef NV50_RA_DEBUG_LIVEI + for (i = 0; i < pc->num_values; ++i) + livei_print(&pc->values[i]); +#endif + + ret = pass_join_values(ctx, 0); + if (ret) + goto out; + ret = pass_linear_scan(ctx, 0); + if (ret) + goto out; + ret = pass_join_values(ctx, 1); + if (ret) + goto out; + ret = pass_join_values(ctx, 2); + if (ret) + goto out; + ret = pass_linear_scan(ctx, 1); + if (ret) + goto out; + + for (i = 0; i < pc->num_values; ++i) + livei_release(&pc->values[i]); + + NV50_DBGMSG("REGISTER ALLOCATION - leaving\n"); + +out: + FREE(ctx->insns); + FREE(ctx); + return ret; +} + +int +nv_pc_exec_pass1(struct nv_pc *pc) +{ + int i, ret; + + for (i = 0; i < pc->num_subroutines + 1; ++i) + if (pc->root[i] && (ret = nv_pc_pass1(pc, pc->root[i]))) + return ret; + return 0; +} diff --git a/src/gallium/drivers/nv50/nv50_program.c b/src/gallium/drivers/nv50/nv50_program.c new file mode 100644 index 0000000..db68176 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_program.c @@ -0,0 +1,660 @@ +/* + * Copyright 2010 Chrsitoph Bumiller + * + * 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 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 NV50_PROGRAM_DEBUG */ + +#include "nv50_program.h" +#include "nv50_pc.h" +#include "nv50_context.h" + +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "tgsi/tgsi_dump.h" + +static INLINE unsigned +bitcount4(const uint32_t val) +{ + static const unsigned cnt[16] + = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; + return cnt[val & 0xf]; +} + +static unsigned +nv50_tgsi_src_mask(const struct tgsi_full_instruction *inst, int c) +{ + unsigned mask = inst->Dst[0].Register.WriteMask; + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_COS: + case TGSI_OPCODE_SIN: + return (mask & 0x8) | ((mask & 0x7) ? 0x1 : 0x0); + case TGSI_OPCODE_DP3: + return 0x7; + case TGSI_OPCODE_DP4: + case TGSI_OPCODE_DPH: + case TGSI_OPCODE_KIL: /* WriteMask ignored */ + return 0xf; + case TGSI_OPCODE_DST: + return mask & (c ? 0xa : 0x6); + case TGSI_OPCODE_EX2: + case TGSI_OPCODE_EXP: + case TGSI_OPCODE_LG2: + case TGSI_OPCODE_LOG: + case TGSI_OPCODE_POW: + case TGSI_OPCODE_RCP: + case TGSI_OPCODE_RSQ: + case TGSI_OPCODE_SCS: + return 0x1; + case TGSI_OPCODE_IF: + return 0x1; + case TGSI_OPCODE_LIT: + return 0xb; + case TGSI_OPCODE_TEX: + case TGSI_OPCODE_TXB: + case TGSI_OPCODE_TXL: + case TGSI_OPCODE_TXP: + { + const struct tgsi_instruction_texture *tex; + + assert(inst->Instruction.Texture); + tex = &inst->Texture; + + mask = 0x7; + if (inst->Instruction.Opcode != TGSI_OPCODE_TEX && + inst->Instruction.Opcode != TGSI_OPCODE_TXD) + mask |= 0x8; /* bias, lod or proj */ + + switch (tex->Texture) { + case TGSI_TEXTURE_1D: + mask &= 0x9; + break; + case TGSI_TEXTURE_SHADOW1D: + mask &= 0x5; + break; + case TGSI_TEXTURE_2D: + mask &= 0xb; + break; + default: + break; + } + } + return mask; + case TGSI_OPCODE_XPD: + { + unsigned x = 0; + if (mask & 1) x |= 0x6; + if (mask & 2) x |= 0x5; + if (mask & 4) x |= 0x3; + return x; + } + default: + break; + } + + return mask; +} + +static void +nv50_indirect_inputs(struct nv50_translation_info *ti, int id) +{ + int i, c; + + for (i = 0; i < PIPE_MAX_SHADER_INPUTS; ++i) + for (c = 0; c < 4; ++c) + ti->input_access[i][c] = id; + + ti->indirect_inputs = TRUE; +} + +static void +nv50_indirect_outputs(struct nv50_translation_info *ti, int id) +{ + int i, c; + + for (i = 0; i < PIPE_MAX_SHADER_OUTPUTS; ++i) + for (c = 0; c < 4; ++c) + ti->output_access[i][c] = id; + + ti->indirect_outputs = TRUE; +} + +static void +prog_inst(struct nv50_translation_info *ti, + const struct tgsi_full_instruction *inst, int id) +{ + const struct tgsi_dst_register *dst; + const struct tgsi_src_register *src; + int s, c, k; + unsigned mask; + + if (inst->Instruction.Opcode == TGSI_OPCODE_BGNSUB) { + ti->subr[ti->subr_nr].pos = id - 1; + ti->subr[ti->subr_nr].id = ti->subr_nr + 1; /* id 0 is main program */ + ++ti->subr_nr; + } + + if (inst->Dst[0].Register.File == TGSI_FILE_OUTPUT) { + dst = &inst->Dst[0].Register; + + for (c = 0; c < 4; ++c) { + if (dst->Indirect) + nv50_indirect_outputs(ti, id); + if (!(dst->WriteMask & (1 << c))) + continue; + ti->output_access[dst->Index][c] = id; + } + + if (inst->Instruction.Opcode == TGSI_OPCODE_MOV && + inst->Src[0].Register.File == TGSI_FILE_INPUT && + dst->Index == ti->edgeflag_out) + ti->p->vp.edgeflag = inst->Src[0].Register.Index; + } else + if (inst->Dst[0].Register.File == TGSI_FILE_TEMPORARY) { + if (inst->Dst[0].Register.Indirect) + ti->store_to_memory = TRUE; + } + + for (s = 0; s < inst->Instruction.NumSrcRegs; ++s) { + src = &inst->Src[s].Register; + if (src->File == TGSI_FILE_TEMPORARY) + if (inst->Src[s].Register.Indirect) + ti->store_to_memory = TRUE; + if (src->File != TGSI_FILE_INPUT) + continue; + mask = nv50_tgsi_src_mask(inst, s); + + if (inst->Src[s].Register.Indirect) + nv50_indirect_inputs(ti, id); + + for (c = 0; c < 4; ++c) { + if (!(mask & (1 << c))) + continue; + k = tgsi_util_get_full_src_register_swizzle(&inst->Src[s], c); + if (k <= TGSI_SWIZZLE_W) + ti->input_access[src->Index][k] = id; + } + } +} + +/* Probably should introduce something like struct tgsi_function_declaration + * instead of trying to guess inputs/outputs. + */ +static void +prog_subroutine_inst(struct nv50_subroutine *subr, + const struct tgsi_full_instruction *inst) +{ + const struct tgsi_dst_register *dst; + const struct tgsi_src_register *src; + int s, c, k; + unsigned mask; + + for (s = 0; s < inst->Instruction.NumSrcRegs; ++s) { + src = &inst->Src[s].Register; + if (src->File != TGSI_FILE_TEMPORARY) + continue; + mask = nv50_tgsi_src_mask(inst, s); + + assert(!inst->Src[s].Register.Indirect); + + for (c = 0; c < 4; ++c) { + k = tgsi_util_get_full_src_register_swizzle(&inst->Src[s], c); + + if ((mask & (1 << c)) && k < TGSI_SWIZZLE_W) + if (!(subr->retv[src->Index / 32][k] & (1 << (src->Index % 32)))) + subr->argv[src->Index / 32][k] |= 1 << (src->Index % 32); + } + } + + if (inst->Dst[0].Register.File == TGSI_FILE_TEMPORARY) { + dst = &inst->Dst[0].Register; + + for (c = 0; c < 4; ++c) + if (dst->WriteMask & (1 << c)) + subr->retv[dst->Index / 32][c] |= 1 << (dst->Index % 32); + } +} + +static void +prog_immediate(struct nv50_translation_info *ti, + const struct tgsi_full_immediate *imm) +{ + int c; + unsigned n = ti->immd32_nr++; + + assert(ti->immd32_nr <= ti->scan.immediate_count); + + for (c = 0; c < 4; ++c) + ti->immd32[n * 4 + c] = imm->u[c].Uint; + + ti->immd32_ty[n] = imm->Immediate.DataType; +} + +static INLINE unsigned +translate_interpolate(const struct tgsi_full_declaration *decl) +{ + unsigned mode; + + if (decl->Declaration.Interpolate == TGSI_INTERPOLATE_CONSTANT) + mode = NV50_INTERP_FLAT; + else + if (decl->Declaration.Interpolate == TGSI_INTERPOLATE_PERSPECTIVE) + mode = 0; + else + mode = NV50_INTERP_LINEAR; + + if (decl->Declaration.Centroid) + mode |= NV50_INTERP_CENTROID; + + return mode; +} + +static void +prog_decl(struct nv50_translation_info *ti, + const struct tgsi_full_declaration *decl) +{ + unsigned i, first, last, sn = 0, si = 0; + + first = decl->Range.First; + last = decl->Range.Last; + + if (decl->Declaration.Semantic) { + sn = decl->Semantic.Name; + si = decl->Semantic.Index; + } + + switch (decl->Declaration.File) { + case TGSI_FILE_INPUT: + for (i = first; i <= last; ++i) + ti->interp_mode[i] = translate_interpolate(decl); + + if (!decl->Declaration.Semantic) + break; + + for (i = first; i <= last; ++i) { + ti->p->in[i].sn = sn; + ti->p->in[i].si = si; + } + + switch (sn) { + case TGSI_SEMANTIC_FACE: + break; + case TGSI_SEMANTIC_COLOR: + if (ti->p->type == PIPE_SHADER_FRAGMENT) + ti->p->vp.bfc[si] = first; + break; + } + break; + case TGSI_FILE_OUTPUT: + if (!decl->Declaration.Semantic) + break; + + for (i = first; i <= last; ++i) { + ti->p->out[i].sn = sn; + ti->p->out[i].si = si; + } + + switch (sn) { + case TGSI_SEMANTIC_BCOLOR: + ti->p->vp.bfc[si] = first; + break; + case TGSI_SEMANTIC_PSIZE: + ti->p->vp.psiz = first; + break; + case TGSI_SEMANTIC_EDGEFLAG: + ti->edgeflag_out = first; + break; + default: + break; + } + break; + case TGSI_FILE_SYSTEM_VALUE: + switch (decl->Semantic.Name) { + case TGSI_SEMANTIC_FACE: + break; + case TGSI_SEMANTIC_INSTANCEID: + break; + case TGSI_SEMANTIC_PRIMID: + break; + /* + case TGSI_SEMANTIC_PRIMIDIN: + break; + case TGSI_SEMANTIC_VERTEXID: + break; + */ + default: + break; + } + break; + case TGSI_FILE_CONSTANT: + ti->p->parm_size = MAX2(ti->p->parm_size, (last + 1) * 16); + break; + case TGSI_FILE_ADDRESS: + case TGSI_FILE_SAMPLER: + case TGSI_FILE_TEMPORARY: + break; + default: + assert(0); + break; + } +} + +static int +nv50_vertprog_prepare(struct nv50_translation_info *ti) +{ + struct nv50_program *p = ti->p; + int i, c; + unsigned num_inputs = 0; + + ti->input_file = NV_FILE_MEM_S; + ti->output_file = NV_FILE_OUT; + + for (i = 0; i <= ti->scan.file_max[TGSI_FILE_INPUT]; ++i) { + p->in[i].id = i; + p->in[i].hw = num_inputs; + + for (c = 0; c < 4; ++c) { + if (!ti->input_access[i][c]) + continue; + ti->input_map[i][c] = num_inputs++; + p->vp.attrs[(4 * i + c) / 32] |= 1 << ((i * 4 + c) % 32); + } + } + + for (i = 0; i <= ti->scan.file_max[TGSI_FILE_OUTPUT]; ++i) { + p->out[i].id = i; + p->out[i].hw = p->max_out; + + for (c = 0; c < 4; ++c) { + if (!ti->output_access[i][c]) + continue; + ti->output_map[i][c] = p->max_out++; + p->out[i].mask |= 1 << c; + } + } + + if (p->vp.psiz < 0x40) + p->vp.psiz = p->out[p->vp.psiz].hw; + + return 0; +} + +static int +nv50_fragprog_prepare(struct nv50_translation_info *ti) +{ + struct nv50_program *p = ti->p; + int i, j, c; + unsigned nvary, nintp, depr; + unsigned n = 0, m = 0, skip = 0; + ubyte sn[16], si[16]; + + /* FP flags */ + + if (ti->scan.writes_z) { + p->fp.flags[1] = 0x11; + p->fp.flags[0] |= NV50TCL_FP_CONTROL_EXPORTS_Z; + } + + if (ti->scan.uses_kill) + p->fp.flags[0] |= NV50TCL_FP_CONTROL_USES_KIL; + + /* FP inputs */ + + ti->input_file = NV_FILE_MEM_V; + ti->output_file = NV_FILE_GPR; + + /* count non-flat inputs, save semantic info */ + for (i = 0; i < p->in_nr; ++i) { + m += (ti->interp_mode[i] & NV50_INTERP_FLAT) ? 0 : 1; + sn[i] = p->in[i].sn; + si[i] = p->in[i].si; + } + + /* reorder p->in[] so that non-flat inputs are first and + * kick out special inputs that don't use VP/GP_RESULT_MAP + */ + nintp = 0; + for (i = 0; i < p->in_nr; ++i) { + if (sn[i] == TGSI_SEMANTIC_POSITION) { + for (c = 0; c < 4; ++c) { + ti->input_map[i][c] = nintp; + if (ti->input_access[i][c]) { + p->fp.interp |= 1 << (24 + c); + ++nintp; + } + } + skip++; + continue; + } else + if (sn[i] == TGSI_SEMANTIC_FACE) { + ti->input_map[i][0] = 255; + skip++; + continue; + } + + j = (ti->interp_mode[i] & NV50_INTERP_FLAT) ? m++ : n++; + + if (sn[i] == TGSI_SEMANTIC_COLOR) + p->vp.bfc[si[i]] = j; + + p->in[j].linear = (ti->interp_mode[i] & NV50_INTERP_LINEAR) ? 1 : 0; + p->in[j].id = i; + p->in[j].sn = sn[i]; + p->in[j].si = si[i]; + } + assert(n <= m); + p->in_nr -= skip; + + if (!(p->fp.interp & (8 << 24))) { + p->fp.interp |= (8 << 24); + ++nintp; + } + + p->fp.colors = (1 << 24) | 4; /* CLAMP, FFC0_ID = 4 */ + + for (i = 0; i < p->in_nr; ++i) { + int j = p->in[i].id; + p->in[i].hw = nintp; + + for (c = 0; c < 4; ++c) { + if (!ti->input_access[j][c]) + continue; + p->in[i].mask |= 1 << c; + ti->input_map[j][c] = nintp++; + } + /* count color inputs */ + if (i == p->vp.bfc[0] || i == p->vp.bfc[1]) + p->fp.colors += bitcount4(p->in[i].mask) << 16; + } + nintp -= bitcount4(p->fp.interp >> 24); /* subtract position inputs */ + nvary = nintp; + if (n < m) + nvary -= p->in[n].hw; + + p->fp.interp |= nvary << NV50TCL_FP_INTERPOLANT_CTRL_COUNT_NONFLAT_SHIFT; + p->fp.interp |= nintp << NV50TCL_FP_INTERPOLANT_CTRL_COUNT_SHIFT; + + /* FP outputs */ + + if (p->out_nr > (1 + (ti->scan.writes_z ? 1 : 0))) + p->fp.flags[0] |= NV50TCL_FP_CONTROL_MULTIPLE_RESULTS; + + depr = p->out_nr; + for (i = 0; i < p->out_nr; ++i) { + p->out[i].id = i; + if (p->out[i].sn == TGSI_SEMANTIC_POSITION) { + depr = i; + continue; + } + p->out[i].hw = p->max_out; + p->out[i].mask = 0xf; + + for (c = 0; c < 4; ++c) + ti->output_map[i][c] = p->max_out++; + } + if (depr < p->out_nr) { + p->out[depr].mask = 0x4; + p->out[depr].hw = ti->output_map[depr][2] = p->max_out++; + } else { + /* allowed values are 1, 4, 5, 8, 9, ... */ + p->max_out = MAX2(4, p->max_out); + } + + return 0; +} + +static int +nv50_geomprog_prepare(struct nv50_translation_info *ti) +{ + ti->input_file = NV_FILE_MEM_S; + ti->output_file = NV_FILE_OUT; + + assert(0); + return 1; +} + +static int +nv50_prog_scan(struct nv50_translation_info *ti) +{ + struct nv50_program *p = ti->p; + struct tgsi_parse_context parse; + int ret, i; + + p->vp.edgeflag = 0x40; + p->vp.psiz = 0x40; + p->vp.bfc[0] = 0x40; + p->vp.bfc[1] = 0x40; + p->gp.primid = 0x80; + + tgsi_scan_shader(p->pipe.tokens, &ti->scan); + +#ifdef NV50_PROGRAM_DEBUG + tgsi_dump(p->pipe.tokens, 0); +#endif + + ti->subr = + CALLOC(ti->scan.opcode_count[TGSI_OPCODE_BGNSUB], sizeof(ti->subr[0])); + + ti->immd32 = (uint32_t *)MALLOC(ti->scan.immediate_count * 16); + ti->immd32_ty = (ubyte *)MALLOC(ti->scan.immediate_count * sizeof(ubyte)); + + ti->insns = MALLOC(ti->scan.num_instructions * sizeof(ti->insns[0])); + + tgsi_parse_init(&parse, p->pipe.tokens); + while (!tgsi_parse_end_of_tokens(&parse)) { + tgsi_parse_token(&parse); + + switch (parse.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_IMMEDIATE: + prog_immediate(ti, &parse.FullToken.FullImmediate); + break; + case TGSI_TOKEN_TYPE_DECLARATION: + prog_decl(ti, &parse.FullToken.FullDeclaration); + break; + case TGSI_TOKEN_TYPE_INSTRUCTION: + ti->insns[ti->inst_nr] = parse.FullToken.FullInstruction; + prog_inst(ti, &parse.FullToken.FullInstruction, ++ti->inst_nr); + break; + } + } + + /* Scan to determine which registers are inputs/outputs of a subroutine. */ + for (i = 0; i < ti->subr_nr; ++i) { + int pc = ti->subr[i].id; + while (ti->insns[pc].Instruction.Opcode != TGSI_OPCODE_ENDSUB) + prog_subroutine_inst(&ti->subr[i], &ti->insns[pc++]); + } + + p->in_nr = ti->scan.file_max[TGSI_FILE_INPUT] + 1; + p->out_nr = ti->scan.file_max[TGSI_FILE_OUTPUT] + 1; + + switch (p->type) { + case PIPE_SHADER_VERTEX: + ret = nv50_vertprog_prepare(ti); + break; + case PIPE_SHADER_FRAGMENT: + ret = nv50_fragprog_prepare(ti); + break; + case PIPE_SHADER_GEOMETRY: + ret = nv50_geomprog_prepare(ti); + break; + default: + assert(!"unsupported program type"); + ret = -1; + break; + } + + assert(!ret); + return ret; +} + +boolean +nv50_program_tx(struct nv50_program *p) +{ + struct nv50_translation_info *ti; + int ret; + + ti = CALLOC_STRUCT(nv50_translation_info); + ti->p = p; + + ti->edgeflag_out = PIPE_MAX_SHADER_OUTPUTS; + + ret = nv50_prog_scan(ti); + if (ret) { + NOUVEAU_ERR("unsupported shader program\n"); + goto out; + } + + ret = nv50_generate_code(ti); + if (ret) { + NOUVEAU_ERR("error during shader translation\n"); + goto out; + } + +out: + if (ti->immd32) + FREE(ti->immd32); + if (ti->immd32_ty) + FREE(ti->immd32_ty); + if (ti->insns) + FREE(ti->insns); + if (ti->subr) + FREE(ti->subr); + FREE(ti); + return ret ? FALSE : TRUE; +} + +void +nv50_program_destroy(struct nv50_context *nv50, struct nv50_program *p) +{ + nouveau_bo_ref(NULL, &p->bo); + + so_ref(NULL, &p->so); + + if (p->code) + FREE(p->code); + + if (p->fixups) + FREE(p->fixups); + + p->translated = FALSE; +} diff --git a/src/gallium/drivers/nv50/nv50_program.h b/src/gallium/drivers/nv50/nv50_program.h new file mode 100644 index 0000000..33c4c8c --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_program.h @@ -0,0 +1,137 @@ +/* + * Copyright 2010 Ben Skeggs + * + * 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 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 __NV50_PROG_H__ +#define __NV50_PROG_H__ + +#include "pipe/p_state.h" +#include "tgsi/tgsi_scan.h" + +#define NV50_CAP_MAX_PROGRAM_TEMPS 64 + +struct nv50_varying { + uint8_t id; /* tgsi index */ + uint8_t hw; /* hw index, nv50 wants flat FP inputs last */ + + unsigned mask : 4; + unsigned linear : 1; + unsigned pad : 3; + + ubyte sn; /* semantic name */ + ubyte si; /* semantic index */ +}; + +struct nv50_program { + struct pipe_shader_state pipe; + + ubyte type; + boolean translated; + boolean uses_lmem; + + struct nouveau_bo *bo; + struct nouveau_stateobj *so; + + uint32_t *code; + unsigned code_size; + unsigned code_start; /* offset inside bo */ + uint32_t *immd; + unsigned immd_size; + unsigned parm_size; /* size limit of uniform buffer */ + + ubyte max_gpr; /* REG_ALLOC_TEMP */ + ubyte max_out; /* REG_ALLOC_RESULT or FP_RESULT_COUNT */ + + ubyte in_nr; + ubyte out_nr; + struct nv50_varying in[16]; + struct nv50_varying out[16]; + + struct { + uint32_t attrs[3]; /* VP_ATTR_EN_0,1 and VP_GP_BUILTIN_ATTR_EN */ + ubyte psiz; + ubyte bfc[2]; + ubyte edgeflag; + ubyte clpd; + ubyte clpd_nr; + } vp; + + struct { + uint32_t flags[2]; /* 0x19a8, 196c */ + uint32_t interp; /* 0x1988 */ + uint32_t colors; /* 0x1904 */ + } fp; + + struct { + ubyte primid; /* primitive id output register */ + uint8_t vert_count; + uint8_t prim_type; /* point, line strip or tri strip */ + } gp; + + /* relocation records */ + void *fixups; + unsigned num_fixups; +}; + +#define NV50_INTERP_LINEAR (1 << 0) +#define NV50_INTERP_FLAT (1 << 1) +#define NV50_INTERP_CENTROID (1 << 2) + +/* analyze TGSI and see which TEMP[] are used as subroutine inputs/outputs */ +struct nv50_subroutine { + unsigned id; + unsigned pos; + /* function inputs and outputs */ + uint32_t argv[NV50_CAP_MAX_PROGRAM_TEMPS][4]; + uint32_t retv[NV50_CAP_MAX_PROGRAM_TEMPS][4]; +}; + +struct nv50_translation_info { + struct nv50_program *p; + unsigned inst_nr; + struct tgsi_full_instruction *insns; + ubyte input_file; + ubyte output_file; + ubyte input_map[PIPE_MAX_SHADER_INPUTS][4]; + ubyte output_map[PIPE_MAX_SHADER_OUTPUTS][4]; + ubyte interp_mode[PIPE_MAX_SHADER_INPUTS]; + int input_access[PIPE_MAX_SHADER_INPUTS][4]; + int output_access[PIPE_MAX_SHADER_OUTPUTS][4]; + boolean indirect_inputs; + boolean indirect_outputs; + boolean store_to_memory; + struct tgsi_shader_info scan; + uint32_t *immd32; + unsigned immd32_nr; + ubyte *immd32_ty; + ubyte edgeflag_out; + struct nv50_subroutine *subr; + unsigned subr_nr; +}; + +int nv50_generate_code(struct nv50_translation_info *ti); + +void nv50_relocate_program(struct nv50_program *p, + uint32_t code_base, uint32_t data_base); + +boolean nv50_program_tx(struct nv50_program *p); + +#endif /* __NV50_PROG_H__ */ diff --git a/src/gallium/drivers/nv50/nv50_push.c b/src/gallium/drivers/nv50/nv50_push.c new file mode 100644 index 0000000..380f694 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_push.c @@ -0,0 +1,362 @@ +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_split_prim.h" + +#include "nv50_context.h" +#include "nv50_resource.h" + +struct push_context { + struct nv50_context *nv50; + + unsigned vtx_size; + + void *idxbuf; + int32_t idxbias; + unsigned idxsize; + + float edgeflag; + int edgeflag_attr; + + struct { + void *map; + unsigned stride; + unsigned divisor; + unsigned step; + void (*push)(struct nouveau_channel *, void *); + } attr[16]; + unsigned attr_nr; +}; + +static void +emit_b32_1(struct nouveau_channel *chan, void *data) +{ + uint32_t *v = data; + + OUT_RING(chan, v[0]); +} + +static void +emit_b32_2(struct nouveau_channel *chan, void *data) +{ + uint32_t *v = data; + + OUT_RING(chan, v[0]); + OUT_RING(chan, v[1]); +} + +static void +emit_b32_3(struct nouveau_channel *chan, void *data) +{ + uint32_t *v = data; + + OUT_RING(chan, v[0]); + OUT_RING(chan, v[1]); + OUT_RING(chan, v[2]); +} + +static void +emit_b32_4(struct nouveau_channel *chan, void *data) +{ + uint32_t *v = data; + + OUT_RING(chan, v[0]); + OUT_RING(chan, v[1]); + OUT_RING(chan, v[2]); + OUT_RING(chan, v[3]); +} + +static void +emit_b16_1(struct nouveau_channel *chan, void *data) +{ + uint16_t *v = data; + + OUT_RING(chan, v[0]); +} + +static void +emit_b16_3(struct nouveau_channel *chan, void *data) +{ + uint16_t *v = data; + + OUT_RING(chan, (v[1] << 16) | v[0]); + OUT_RING(chan, v[2]); +} + +static void +emit_b08_1(struct nouveau_channel *chan, void *data) +{ + uint8_t *v = data; + + OUT_RING(chan, v[0]); +} + +static void +emit_b08_3(struct nouveau_channel *chan, void *data) +{ + uint8_t *v = data; + + OUT_RING(chan, (v[2] << 16) | (v[1] << 8) | v[0]); +} + +static INLINE void +emit_vertex(struct push_context *ctx, unsigned n) +{ + struct nouveau_grobj *tesla = ctx->nv50->screen->tesla; + struct nouveau_channel *chan = tesla->channel; + int i; + + if (ctx->edgeflag_attr < 16) { + float *edgeflag = (float *) + ((uint8_t *)ctx->attr[ctx->edgeflag_attr].map + + ctx->attr[ctx->edgeflag_attr].stride * n); + + if (*edgeflag != ctx->edgeflag) { + BEGIN_RING(chan, tesla, NV50TCL_EDGEFLAG_ENABLE, 1); + OUT_RING (chan, *edgeflag ? 1 : 0); + ctx->edgeflag = *edgeflag; + } + } + + BEGIN_RING_NI(chan, tesla, NV50TCL_VERTEX_DATA, ctx->vtx_size); + for (i = 0; i < ctx->attr_nr; i++) + ctx->attr[i].push(chan, + (uint8_t *)ctx->attr[i].map + ctx->attr[i].stride * n); +} + +static void +emit_edgeflag(void *priv, boolean enabled) +{ + struct push_context *ctx = priv; + struct nouveau_grobj *tesla = ctx->nv50->screen->tesla; + struct nouveau_channel *chan = tesla->channel; + + BEGIN_RING(chan, tesla, NV50TCL_EDGEFLAG_ENABLE, 1); + OUT_RING (chan, enabled ? 1 : 0); +} + +static void +emit_elt08(void *priv, unsigned start, unsigned count) +{ + struct push_context *ctx = priv; + uint8_t *idxbuf = ctx->idxbuf; + + while (count--) + emit_vertex(ctx, idxbuf[start++]); +} + +static void +emit_elt08_biased(void *priv, unsigned start, unsigned count) +{ + struct push_context *ctx = priv; + uint8_t *idxbuf = ctx->idxbuf; + + while (count--) + emit_vertex(ctx, idxbuf[start++] + ctx->idxbias); +} + +static void +emit_elt16(void *priv, unsigned start, unsigned count) +{ + struct push_context *ctx = priv; + uint16_t *idxbuf = ctx->idxbuf; + + while (count--) + emit_vertex(ctx, idxbuf[start++]); +} + +static void +emit_elt16_biased(void *priv, unsigned start, unsigned count) +{ + struct push_context *ctx = priv; + uint16_t *idxbuf = ctx->idxbuf; + + while (count--) + emit_vertex(ctx, idxbuf[start++] + ctx->idxbias); +} + +static void +emit_elt32(void *priv, unsigned start, unsigned count) +{ + struct push_context *ctx = priv; + uint32_t *idxbuf = ctx->idxbuf; + + while (count--) + emit_vertex(ctx, idxbuf[start++]); +} + +static void +emit_elt32_biased(void *priv, unsigned start, unsigned count) +{ + struct push_context *ctx = priv; + uint32_t *idxbuf = ctx->idxbuf; + + while (count--) + emit_vertex(ctx, idxbuf[start++] + ctx->idxbias); +} + +static void +emit_verts(void *priv, unsigned start, unsigned count) +{ + while (count--) + emit_vertex(priv, start++); +} + +void +nv50_push_elements_instanced(struct pipe_context *pipe, + struct pipe_resource *idxbuf, + unsigned idxsize, int idxbias, + unsigned mode, unsigned start, unsigned count, + unsigned i_start, unsigned i_count) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_channel *chan = tesla->channel; + struct push_context ctx; + const unsigned p_overhead = 4 + /* begin/end */ + 4; /* potential edgeflag enable/disable */ + const unsigned v_overhead = 1 + /* VERTEX_DATA packet header */ + 2; /* potential edgeflag modification */ + struct util_split_prim s; + unsigned vtx_size; + boolean nzi = FALSE; + int i; + + ctx.nv50 = nv50; + ctx.attr_nr = 0; + ctx.idxbuf = NULL; + ctx.vtx_size = 0; + ctx.edgeflag = 0.5f; + ctx.edgeflag_attr = nv50->vertprog->vp.edgeflag; + + /* map vertex buffers, determine vertex size */ + for (i = 0; i < nv50->vtxelt->num_elements; i++) { + struct pipe_vertex_element *ve = &nv50->vtxelt->pipe[i]; + struct pipe_vertex_buffer *vb = &nv50->vtxbuf[ve->vertex_buffer_index]; + struct nouveau_bo *bo = nv50_resource(vb->buffer)->bo; + unsigned size, nr_components, n; + + if (!(nv50->vbo_fifo & (1 << i))) + continue; + n = ctx.attr_nr++; + + if (nouveau_bo_map(bo, NOUVEAU_BO_RD)) { + assert(bo->map); + return; + } + ctx.attr[n].map = (uint8_t *)bo->map + vb->buffer_offset + ve->src_offset; + nouveau_bo_unmap(bo); + + ctx.attr[n].stride = vb->stride; + ctx.attr[n].divisor = ve->instance_divisor; + if (ctx.attr[n].divisor) { + ctx.attr[n].step = i_start % ve->instance_divisor; + ctx.attr[n].map = (uint8_t *)ctx.attr[n].map + i_start * vb->stride; + } + + size = util_format_get_component_bits(ve->src_format, + UTIL_FORMAT_COLORSPACE_RGB, 0); + nr_components = util_format_get_nr_components(ve->src_format); + switch (size) { + case 8: + switch (nr_components) { + case 1: ctx.attr[n].push = emit_b08_1; break; + case 2: ctx.attr[n].push = emit_b16_1; break; + case 3: ctx.attr[n].push = emit_b08_3; break; + case 4: ctx.attr[n].push = emit_b32_1; break; + } + ctx.vtx_size++; + break; + case 16: + switch (nr_components) { + case 1: ctx.attr[n].push = emit_b16_1; break; + case 2: ctx.attr[n].push = emit_b32_1; break; + case 3: ctx.attr[n].push = emit_b16_3; break; + case 4: ctx.attr[n].push = emit_b32_2; break; + } + ctx.vtx_size += (nr_components + 1) >> 1; + break; + case 32: + switch (nr_components) { + case 1: ctx.attr[n].push = emit_b32_1; break; + case 2: ctx.attr[n].push = emit_b32_2; break; + case 3: ctx.attr[n].push = emit_b32_3; break; + case 4: ctx.attr[n].push = emit_b32_4; break; + } + ctx.vtx_size += nr_components; + break; + default: + assert(0); + return; + } + } + vtx_size = ctx.vtx_size + v_overhead; + + /* map index buffer, if present */ + if (idxbuf) { + struct nouveau_bo *bo = nv50_resource(idxbuf)->bo; + + if (nouveau_bo_map(bo, NOUVEAU_BO_RD)) { + assert(bo->map); + return; + } + ctx.idxbuf = bo->map; + ctx.idxbias = idxbias; + ctx.idxsize = idxsize; + nouveau_bo_unmap(bo); + } + + s.priv = &ctx; + s.edge = emit_edgeflag; + if (idxbuf) { + if (idxsize == 1) + s.emit = idxbias ? emit_elt08_biased : emit_elt08; + else + if (idxsize == 2) + s.emit = idxbias ? emit_elt16_biased : emit_elt16; + else + s.emit = idxbias ? emit_elt32_biased : emit_elt32; + } else + s.emit = emit_verts; + + /* per-instance loop */ + BEGIN_RING(chan, tesla, NV50TCL_CB_ADDR, 2); + OUT_RING (chan, NV50_CB_AUX | (24 << 8)); + OUT_RING (chan, i_start); + while (i_count--) { + unsigned max_verts; + boolean done; + + for (i = 0; i < ctx.attr_nr; i++) { + if (!ctx.attr[i].divisor || + ctx.attr[i].divisor != ++ctx.attr[i].step) + continue; + ctx.attr[i].step = 0; + ctx.attr[i].map = (uint8_t *)ctx.attr[i].map + ctx.attr[i].stride; + } + + util_split_prim_init(&s, mode, start, count); + do { + if (AVAIL_RING(chan) < p_overhead + (6 * vtx_size)) { + FIRE_RING(chan); + if (!nv50_state_validate(nv50, p_overhead + (6 * vtx_size))) { + assert(0); + return; + } + } + + max_verts = AVAIL_RING(chan); + max_verts -= p_overhead; + max_verts /= vtx_size; + + BEGIN_RING(chan, tesla, NV50TCL_VERTEX_BEGIN, 1); + OUT_RING (chan, nv50_prim(s.mode) | (nzi ? (1 << 28) : 0)); + done = util_split_prim_next(&s, max_verts); + BEGIN_RING(chan, tesla, NV50TCL_VERTEX_END, 1); + OUT_RING (chan, 0); + } while (!done); + + nzi = TRUE; + } +} diff --git a/src/gallium/drivers/nv50/nv50_query.c b/src/gallium/drivers/nv50/nv50_query.c new file mode 100644 index 0000000..53f9482 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_query.c @@ -0,0 +1,167 @@ +/* + * Copyright 2008 Ben Skeggs + * + * 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 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_context.h" +#include "util/u_inlines.h" + +#include "nv50_context.h" + +struct nv50_query { + struct nouveau_bo *bo; + unsigned type; + boolean ready; + uint64_t result; +}; + +static INLINE struct nv50_query * +nv50_query(struct pipe_query *pipe) +{ + return (struct nv50_query *)pipe; +} + +static struct pipe_query * +nv50_query_create(struct pipe_context *pipe, unsigned type) +{ + struct nouveau_device *dev = nouveau_screen(pipe->screen)->device; + struct nv50_query *q = CALLOC_STRUCT(nv50_query); + int ret; + + assert (q->type == PIPE_QUERY_OCCLUSION_COUNTER); + q->type = type; + + ret = nouveau_bo_new(dev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 256, + 16, &q->bo); + if (ret) { + FREE(q); + return NULL; + } + + return (struct pipe_query *)q; +} + +static void +nv50_query_destroy(struct pipe_context *pipe, struct pipe_query *pq) +{ + struct nv50_query *q = nv50_query(pq); + + if (q) { + nouveau_bo_ref(NULL, &q->bo); + FREE(q); + } +} + +static void +nv50_query_begin(struct pipe_context *pipe, struct pipe_query *pq) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nouveau_channel *chan = nv50->screen->base.channel; + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nv50_query *q = nv50_query(pq); + + BEGIN_RING(chan, tesla, NV50TCL_SAMPLECNT_RESET, 1); + OUT_RING (chan, 1); + BEGIN_RING(chan, tesla, NV50TCL_SAMPLECNT_ENABLE, 1); + OUT_RING (chan, 1); + + q->ready = FALSE; +} + +static void +nv50_query_end(struct pipe_context *pipe, struct pipe_query *pq) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nouveau_channel *chan = nv50->screen->base.channel; + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nv50_query *q = nv50_query(pq); + + MARK_RING (chan, 5, 2); /* flush on lack of space or relocs */ + BEGIN_RING(chan, tesla, NV50TCL_QUERY_ADDRESS_HIGH, 4); + OUT_RELOCh(chan, q->bo, 0, NOUVEAU_BO_GART | NOUVEAU_BO_WR); + OUT_RELOCl(chan, q->bo, 0, NOUVEAU_BO_GART | NOUVEAU_BO_WR); + OUT_RING (chan, 0x00000000); + OUT_RING (chan, 0x0100f002); + + BEGIN_RING(chan, tesla, NV50TCL_SAMPLECNT_ENABLE, 1); + OUT_RING (chan, 0); +} + +static boolean +nv50_query_result(struct pipe_context *pipe, struct pipe_query *pq, + boolean wait, void *vresult) +{ + uint64_t *result = (uint64_t*)vresult; + struct nv50_query *q = nv50_query(pq); + int ret; + + if (!q->ready) { + ret = nouveau_bo_map(q->bo, NOUVEAU_BO_RD | + (wait ? 0 : NOUVEAU_BO_NOWAIT)); + if (ret) + return false; + q->result = ((uint32_t *)q->bo->map)[1]; + q->ready = TRUE; + nouveau_bo_unmap(q->bo); + } + + *result = q->result; + return q->ready; +} + +static void +nv50_render_condition(struct pipe_context *pipe, + struct pipe_query *pq, uint mode) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nouveau_channel *chan = nv50->screen->base.channel; + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nv50_query *q; + + if (!pq) { + BEGIN_RING(chan, tesla, NV50TCL_COND_MODE, 1); + OUT_RING (chan, NV50TCL_COND_MODE_ALWAYS); + return; + } + q = nv50_query(pq); + + if (mode == PIPE_RENDER_COND_WAIT || + mode == PIPE_RENDER_COND_BY_REGION_WAIT) { + /* XXX: big fence, FIFO semaphore might be better */ + BEGIN_RING(chan, tesla, 0x0110, 1); + OUT_RING (chan, 0); + } + + BEGIN_RING(chan, tesla, NV50TCL_COND_ADDRESS_HIGH, 3); + OUT_RELOCh(chan, q->bo, 0, NOUVEAU_BO_GART | NOUVEAU_BO_RD); + OUT_RELOCl(chan, q->bo, 0, NOUVEAU_BO_GART | NOUVEAU_BO_RD); + OUT_RING (chan, NV50TCL_COND_MODE_RES); +} + +void +nv50_init_query_functions(struct nv50_context *nv50) +{ + nv50->pipe.create_query = nv50_query_create; + nv50->pipe.destroy_query = nv50_query_destroy; + nv50->pipe.begin_query = nv50_query_begin; + nv50->pipe.end_query = nv50_query_end; + nv50->pipe.get_query_result = nv50_query_result; + nv50->pipe.render_condition = nv50_render_condition; +} diff --git a/src/gallium/drivers/nv50/nv50_reg.h b/src/gallium/drivers/nv50/nv50_reg.h new file mode 100644 index 0000000..949838b --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_reg.h @@ -0,0 +1,1827 @@ +/************************************************************************* + + Autogenerated file, do not edit ! + + This file was generated by renouveau-gen from renouveau.xml, the + XML database of nvidia objects and methods. renouveau-gen and + renouveau.xml can be found in CVS module renouveau of sourceforge.net + project nouveau: + +cvs -z3 -d:pserver:anonymous@nouveau.cvs.sourceforge.net:/cvsroot/nouveau co -P renouveau + +************************************************************************** + + Copyright (C) 2006-2008 : + Dmitry Baryshkov, + Laurent Carlier, + Matthieu Castet, + Dawid Gajownik, + Jeremy Kolb, + Stephane Loeuillet, + Patrice Mandin, + Stephane Marchesin, + Serge Martin, + Sylvain Munaut, + Simon Raffeiner, + Ben Skeggs, + Erik Waling, + koala_br, + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*************************************************************************/ + + +#ifndef NOUVEAU_REG_H +#define NOUVEAU_REG_H 1 + + +#define NV04_MEMORY_TO_MEMORY_FORMAT 0x00000039 + +#define NV04_MEMORY_TO_MEMORY_FORMAT_NOP 0x00000100 +#define NV04_MEMORY_TO_MEMORY_FORMAT_NOTIFY 0x00000104 +#define NV04_MEMORY_TO_MEMORY_FORMAT_DMA_NOTIFY 0x00000180 +#define NV04_MEMORY_TO_MEMORY_FORMAT_DMA_BUFFER_IN 0x00000184 +#define NV04_MEMORY_TO_MEMORY_FORMAT_DMA_BUFFER_OUT 0x00000188 +#define NV04_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN 0x0000030c +#define NV04_MEMORY_TO_MEMORY_FORMAT_OFFSET_OUT 0x00000310 +#define NV04_MEMORY_TO_MEMORY_FORMAT_PITCH_IN 0x00000314 +#define NV04_MEMORY_TO_MEMORY_FORMAT_PITCH_OUT 0x00000318 +#define NV04_MEMORY_TO_MEMORY_FORMAT_LINE_LENGTH_IN 0x0000031c +#define NV04_MEMORY_TO_MEMORY_FORMAT_LINE_COUNT 0x00000320 +#define NV04_MEMORY_TO_MEMORY_FORMAT_FORMAT 0x00000324 +#define NV04_MEMORY_TO_MEMORY_FORMAT_FORMAT_INPUT_INC_SHIFT 0 +#define NV04_MEMORY_TO_MEMORY_FORMAT_FORMAT_INPUT_INC_MASK 0x000000ff +#define NV04_MEMORY_TO_MEMORY_FORMAT_FORMAT_OUTPUT_INC_SHIFT 8 +#define NV04_MEMORY_TO_MEMORY_FORMAT_FORMAT_OUTPUT_INC_MASK 0x0000ff00 +#define NV04_MEMORY_TO_MEMORY_FORMAT_BUF_NOTIFY 0x00000328 + + +#define NV50_MEMORY_TO_MEMORY_FORMAT 0x00005039 + +#define NV50_MEMORY_TO_MEMORY_FORMAT_SERIALIZE 0x00000110 +#define NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_IN 0x00000200 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_MODE_IN 0x00000204 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_PITCH_IN 0x00000208 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_HEIGHT_IN 0x0000020c +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_DEPTH_IN 0x00000210 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_IN_Z 0x00000214 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_IN 0x00000218 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_IN_X_SHIFT 0 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_IN_X_MASK 0x0000ffff +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_IN_Y_SHIFT 16 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_IN_Y_MASK 0xffff0000 +#define NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_OUT 0x0000021c +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_MODE_OUT 0x00000220 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_PITCH_OUT 0x00000224 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_HEIGHT_OUT 0x00000228 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_DEPTH_OUT 0x0000022c +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_OUT_Z 0x00000230 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_OUT 0x00000234 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_OUT_X_SHIFT 0 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_OUT_X_MASK 0x0000ffff +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_OUT_Y_SHIFT 16 +#define NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_OUT_Y_MASK 0xffff0000 +#define NV50_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN_HIGH 0x00000238 +#define NV50_MEMORY_TO_MEMORY_FORMAT_OFFSET_OUT_HIGH 0x0000023c + + +#define NV50_2D 0x0000502d + +#define NV50_2D_NOP 0x00000100 +#define NV50_2D_NOTIFY 0x00000104 +#define NV50_2D_SERIALIZE 0x00000110 +#define NV50_2D_DMA_NOTIFY 0x00000180 +#define NV50_2D_DMA_DST 0x00000184 +#define NV50_2D_DMA_SRC 0x00000188 +#define NV50_2D_DMA_COND 0x0000018c +#define NV50_2D_DST_FORMAT 0x00000200 +#define NV50_2D_DST_FORMAT_R32G32B32A32_FLOAT 0x000000c0 +#define NV50_2D_DST_FORMAT_R32G32B32A32_SINT 0x000000c1 +#define NV50_2D_DST_FORMAT_R32G32B32A32_UINT 0x000000c2 +#define NV50_2D_DST_FORMAT_R32G32B32X32_FLOAT 0x000000c3 +#define NV50_2D_DST_FORMAT_R16G16B16A16_UNORM 0x000000c6 +#define NV50_2D_DST_FORMAT_R16G16B16A16_SNORM 0x000000c7 +#define NV50_2D_DST_FORMAT_R16G16B16A16_SINT 0x000000c8 +#define NV50_2D_DST_FORMAT_R16G16B16A16_UINT 0x000000c9 +#define NV50_2D_DST_FORMAT_R16G16B16A16_FLOAT 0x000000ca +#define NV50_2D_DST_FORMAT_R32G32_FLOAT 0x000000cb +#define NV50_2D_DST_FORMAT_R32G32_SINT 0x000000cc +#define NV50_2D_DST_FORMAT_R32G32_UINT 0x000000cd +#define NV50_2D_DST_FORMAT_R16G16B16X16_FLOAT 0x000000ce +#define NV50_2D_DST_FORMAT_A8R8G8B8_UNORM 0x000000cf +#define NV50_2D_DST_FORMAT_A8R8G8B8_SRGB 0x000000d0 +#define NV50_2D_DST_FORMAT_A2B10G10R10_UNORM 0x000000d1 +#define NV50_2D_DST_FORMAT_A2B10G10R10_UINT 0x000000d2 +#define NV50_2D_DST_FORMAT_A8B8G8R8_UNORM 0x000000d5 +#define NV50_2D_DST_FORMAT_A8B8G8R8_SRGB 0x000000d6 +#define NV50_2D_DST_FORMAT_A8B8G8R8_SNORM 0x000000d7 +#define NV50_2D_DST_FORMAT_A8B8G8R8_SINT 0x000000d8 +#define NV50_2D_DST_FORMAT_A8B8G8R8_UINT 0x000000d9 +#define NV50_2D_DST_FORMAT_R16G16_UNORM 0x000000da +#define NV50_2D_DST_FORMAT_R16G16_SNORM 0x000000db +#define NV50_2D_DST_FORMAT_R16G16_SINT 0x000000dc +#define NV50_2D_DST_FORMAT_R16G16_UINT 0x000000dd +#define NV50_2D_DST_FORMAT_R16G16_FLOAT 0x000000de +#define NV50_2D_DST_FORMAT_A2R10G10B10_UNORM 0x000000df +#define NV50_2D_DST_FORMAT_B10G11R11_FLOAT 0x000000e0 +#define NV50_2D_DST_FORMAT_R32_FLOAT 0x000000e5 +#define NV50_2D_DST_FORMAT_X8R8G8B8_UNORM 0x000000e6 +#define NV50_2D_DST_FORMAT_X8R8G8B8_SRGB 0x000000e7 +#define NV50_2D_DST_FORMAT_R5G6B5_UNORM 0x000000e8 +#define NV50_2D_DST_FORMAT_A1R5G5B5_UNORM 0x000000e9 +#define NV50_2D_DST_FORMAT_R8G8_UNORM 0x000000ea +#define NV50_2D_DST_FORMAT_R8G8_SNORM 0x000000eb +#define NV50_2D_DST_FORMAT_R8G8_SINT 0x000000ec +#define NV50_2D_DST_FORMAT_R8G8_UINT 0x000000ed +#define NV50_2D_DST_FORMAT_R16_UNORM 0x000000ee +#define NV50_2D_DST_FORMAT_R16_SNORM 0x000000ef +#define NV50_2D_DST_FORMAT_R16_SINT 0x000000f0 +#define NV50_2D_DST_FORMAT_R16_UINT 0x000000f1 +#define NV50_2D_DST_FORMAT_R16_FLOAT 0x000000f2 +#define NV50_2D_DST_FORMAT_R8_UNORM 0x000000f3 +#define NV50_2D_DST_FORMAT_R8_SNORM 0x000000f4 +#define NV50_2D_DST_FORMAT_R8_SINT 0x000000f5 +#define NV50_2D_DST_FORMAT_R8_UINT 0x000000f6 +#define NV50_2D_DST_FORMAT_A8_UNORM 0x000000f7 +#define NV50_2D_DST_FORMAT_X1R5G5B5_UNORM 0x000000f8 +#define NV50_2D_DST_FORMAT_X8B8G8R8_UNORM 0x000000f9 +#define NV50_2D_DST_FORMAT_X8B8G8R8_SRGB 0x000000fa +#define NV50_2D_DST_LINEAR 0x00000204 +#define NV50_2D_DST_TILE_MODE 0x00000208 +#define NV50_2D_DST_DEPTH 0x0000020c +#define NV50_2D_DST_LAYER 0x00000210 +#define NV50_2D_DST_PITCH 0x00000214 +#define NV50_2D_DST_WIDTH 0x00000218 +#define NV50_2D_DST_HEIGHT 0x0000021c +#define NV50_2D_DST_ADDRESS_HIGH 0x00000220 +#define NV50_2D_DST_ADDRESS_LOW 0x00000224 +#define NV50_2D_SRC_FORMAT 0x00000230 +#define NV50_2D_SRC_FORMAT_R32G32B32A32_FLOAT 0x000000c0 +#define NV50_2D_SRC_FORMAT_R32G32B32A32_SINT 0x000000c1 +#define NV50_2D_SRC_FORMAT_R32G32B32A32_UINT 0x000000c2 +#define NV50_2D_SRC_FORMAT_R32G32B32X32_FLOAT 0x000000c3 +#define NV50_2D_SRC_FORMAT_R16G16B16A16_UNORM 0x000000c6 +#define NV50_2D_SRC_FORMAT_R16G16B16A16_SNORM 0x000000c7 +#define NV50_2D_SRC_FORMAT_R16G16B16A16_SINT 0x000000c8 +#define NV50_2D_SRC_FORMAT_R16G16B16A16_UINT 0x000000c9 +#define NV50_2D_SRC_FORMAT_R16G16B16A16_FLOAT 0x000000ca +#define NV50_2D_SRC_FORMAT_R32G32_FLOAT 0x000000cb +#define NV50_2D_SRC_FORMAT_R32G32_SINT 0x000000cc +#define NV50_2D_SRC_FORMAT_R32G32_UINT 0x000000cd +#define NV50_2D_SRC_FORMAT_R16G16B16X16_FLOAT 0x000000ce +#define NV50_2D_SRC_FORMAT_A8R8G8B8_UNORM 0x000000cf +#define NV50_2D_SRC_FORMAT_A8R8G8B8_SRGB 0x000000d0 +#define NV50_2D_SRC_FORMAT_A2B10G10R10_UNORM 0x000000d1 +#define NV50_2D_SRC_FORMAT_A2B10G10R10_UINT 0x000000d2 +#define NV50_2D_SRC_FORMAT_A8B8G8R8_UNORM 0x000000d5 +#define NV50_2D_SRC_FORMAT_A8B8G8R8_SRGB 0x000000d6 +#define NV50_2D_SRC_FORMAT_A8B8G8R8_SNORM 0x000000d7 +#define NV50_2D_SRC_FORMAT_A8B8G8R8_SINT 0x000000d8 +#define NV50_2D_SRC_FORMAT_A8B8G8R8_UINT 0x000000d9 +#define NV50_2D_SRC_FORMAT_R16G16_UNORM 0x000000da +#define NV50_2D_SRC_FORMAT_R16G16_SNORM 0x000000db +#define NV50_2D_SRC_FORMAT_R16G16_SINT 0x000000dc +#define NV50_2D_SRC_FORMAT_R16G16_UINT 0x000000dd +#define NV50_2D_SRC_FORMAT_R16G16_FLOAT 0x000000de +#define NV50_2D_SRC_FORMAT_A2R10G10B10_UNORM 0x000000df +#define NV50_2D_SRC_FORMAT_B10G11R11_FLOAT 0x000000e0 +#define NV50_2D_SRC_FORMAT_R32_FLOAT 0x000000e5 +#define NV50_2D_SRC_FORMAT_X8R8G8B8_UNORM 0x000000e6 +#define NV50_2D_SRC_FORMAT_X8R8G8B8_SRGB 0x000000e7 +#define NV50_2D_SRC_FORMAT_R5G6B5_UNORM 0x000000e8 +#define NV50_2D_SRC_FORMAT_A1R5G5B5_UNORM 0x000000e9 +#define NV50_2D_SRC_FORMAT_R8G8_UNORM 0x000000ea +#define NV50_2D_SRC_FORMAT_R8G8_SNORM 0x000000eb +#define NV50_2D_SRC_FORMAT_R8G8_SINT 0x000000ec +#define NV50_2D_SRC_FORMAT_R8G8_UINT 0x000000ed +#define NV50_2D_SRC_FORMAT_R16_UNORM 0x000000ee +#define NV50_2D_SRC_FORMAT_R16_SNORM 0x000000ef +#define NV50_2D_SRC_FORMAT_R16_SINT 0x000000f0 +#define NV50_2D_SRC_FORMAT_R16_UINT 0x000000f1 +#define NV50_2D_SRC_FORMAT_R16_FLOAT 0x000000f2 +#define NV50_2D_SRC_FORMAT_R8_UNORM 0x000000f3 +#define NV50_2D_SRC_FORMAT_R8_SNORM 0x000000f4 +#define NV50_2D_SRC_FORMAT_R8_SINT 0x000000f5 +#define NV50_2D_SRC_FORMAT_R8_UINT 0x000000f6 +#define NV50_2D_SRC_FORMAT_A8_UNORM 0x000000f7 +#define NV50_2D_SRC_FORMAT_X1R5G5B5_UNORM 0x000000f8 +#define NV50_2D_SRC_FORMAT_X8B8G8R8_UNORM 0x000000f9 +#define NV50_2D_SRC_FORMAT_X8B8G8R8_SRGB 0x000000fa +#define NV50_2D_SRC_LINEAR 0x00000234 +#define NV50_2D_SRC_TILE_MODE 0x00000238 +#define NV50_2D_SRC_DEPTH 0x0000023c +#define NV50_2D_SRC_LAYER 0x00000240 +#define NV50_2D_SRC_PITCH 0x00000244 +#define NV50_2D_SRC_WIDTH 0x00000248 +#define NV50_2D_SRC_HEIGHT 0x0000024c +#define NV50_2D_SRC_ADDRESS_HIGH 0x00000250 +#define NV50_2D_SRC_ADDRESS_LOW 0x00000254 +#define NV50_2D_COND_ADDRESS_HIGH 0x00000264 +#define NV50_2D_COND_ADDRESS_LOW 0x00000268 +#define NV50_2D_COND_MODE 0x0000026c +#define NV50_2D_COND_MODE_NEVER 0x00000000 +#define NV50_2D_COND_MODE_ALWAYS 0x00000001 +#define NV50_2D_COND_MODE_RES 0x00000002 +#define NV50_2D_COND_MODE_NOT_RES_AND_NOT_ID 0x00000003 +#define NV50_2D_COND_MODE_RES_OR_ID 0x00000004 +#define NV50_2D_CLIP_X 0x00000280 +#define NV50_2D_CLIP_Y 0x00000284 +#define NV50_2D_CLIP_W 0x00000288 +#define NV50_2D_CLIP_H 0x0000028c +#define NV50_2D_CLIP_ENABLE 0x00000290 +#define NV50_2D_COLOR_KEY_FORMAT 0x00000294 +#define NV50_2D_COLOR_KEY_FORMAT_16BPP 0x00000000 +#define NV50_2D_COLOR_KEY_FORMAT_15BPP 0x00000001 +#define NV50_2D_COLOR_KEY_FORMAT_24BPP 0x00000002 +#define NV50_2D_COLOR_KEY_FORMAT_30BPP 0x00000003 +#define NV50_2D_COLOR_KEY_FORMAT_8BPP 0x00000004 +#define NV50_2D_COLOR_KEY_FORMAT_16BPP2 0x00000005 +#define NV50_2D_COLOR_KEY_FORMAT_32BPP 0x00000006 +#define NV50_2D_COLOR_KEY 0x00000298 +#define NV50_2D_COLOR_KEY_ENABLE 0x0000029c +#define NV50_2D_ROP 0x000002a0 +#define NV50_2D_OPERATION 0x000002ac +#define NV50_2D_OPERATION_SRCCOPY_AND 0x00000000 +#define NV50_2D_OPERATION_ROP_AND 0x00000001 +#define NV50_2D_OPERATION_BLEND_AND 0x00000002 +#define NV50_2D_OPERATION_SRCCOPY 0x00000003 +#define NV50_2D_OPERATION_SRCCOPY_PREMULT 0x00000004 +#define NV50_2D_OPERATION_BLEND_PREMULT 0x00000005 +#define NV50_2D_PATTERN_FORMAT 0x000002e8 +#define NV50_2D_PATTERN_FORMAT_16BPP 0x00000000 +#define NV50_2D_PATTERN_FORMAT_15BPP 0x00000001 +#define NV50_2D_PATTERN_FORMAT_32BPP 0x00000002 +#define NV50_2D_PATTERN_FORMAT_8BPP 0x00000003 +#define NV50_2D_PATTERN_COLOR(x) (0x000002f0+((x)*4)) +#define NV50_2D_PATTERN_COLOR__SIZE 0x00000002 +#define NV50_2D_PATTERN_BITMAP(x) (0x000002f8+((x)*4)) +#define NV50_2D_PATTERN_BITMAP__SIZE 0x00000002 +#define NV50_2D_DRAW_SHAPE 0x00000580 +#define NV50_2D_DRAW_SHAPE_POINTS 0x00000000 +#define NV50_2D_DRAW_SHAPE_LINES 0x00000001 +#define NV50_2D_DRAW_SHAPE_LINE_STRIP 0x00000002 +#define NV50_2D_DRAW_SHAPE_TRIANGLES 0x00000003 +#define NV50_2D_DRAW_SHAPE_RECTANGLES 0x00000004 +#define NV50_2D_DRAW_COLOR_FORMAT 0x00000584 +#define NV50_2D_DRAW_COLOR_FORMAT_R32G32B32A32_FLOAT 0x000000c0 +#define NV50_2D_DRAW_COLOR_FORMAT_R32G32B32A32_SINT 0x000000c1 +#define NV50_2D_DRAW_COLOR_FORMAT_R32G32B32A32_UINT 0x000000c2 +#define NV50_2D_DRAW_COLOR_FORMAT_R32G32B32X32_FLOAT 0x000000c3 +#define NV50_2D_DRAW_COLOR_FORMAT_R16G16B16A16_UNORM 0x000000c6 +#define NV50_2D_DRAW_COLOR_FORMAT_R16G16B16A16_SNORM 0x000000c7 +#define NV50_2D_DRAW_COLOR_FORMAT_R16G16B16A16_SINT 0x000000c8 +#define NV50_2D_DRAW_COLOR_FORMAT_R16G16B16A16_UINT 0x000000c9 +#define NV50_2D_DRAW_COLOR_FORMAT_R16G16B16A16_FLOAT 0x000000ca +#define NV50_2D_DRAW_COLOR_FORMAT_R32G32_FLOAT 0x000000cb +#define NV50_2D_DRAW_COLOR_FORMAT_R32G32_SINT 0x000000cc +#define NV50_2D_DRAW_COLOR_FORMAT_R32G32_UINT 0x000000cd +#define NV50_2D_DRAW_COLOR_FORMAT_R16G16B16X16_FLOAT 0x000000ce +#define NV50_2D_DRAW_COLOR_FORMAT_A8R8G8B8_UNORM 0x000000cf +#define NV50_2D_DRAW_COLOR_FORMAT_A8R8G8B8_SRGB 0x000000d0 +#define NV50_2D_DRAW_COLOR_FORMAT_A2B10G10R10_UNORM 0x000000d1 +#define NV50_2D_DRAW_COLOR_FORMAT_A2B10G10R10_UINT 0x000000d2 +#define NV50_2D_DRAW_COLOR_FORMAT_A8B8G8R8_UNORM 0x000000d5 +#define NV50_2D_DRAW_COLOR_FORMAT_A8B8G8R8_SRGB 0x000000d6 +#define NV50_2D_DRAW_COLOR_FORMAT_A8B8G8R8_SNORM 0x000000d7 +#define NV50_2D_DRAW_COLOR_FORMAT_A8B8G8R8_SINT 0x000000d8 +#define NV50_2D_DRAW_COLOR_FORMAT_A8B8G8R8_UINT 0x000000d9 +#define NV50_2D_DRAW_COLOR_FORMAT_R16G16_UNORM 0x000000da +#define NV50_2D_DRAW_COLOR_FORMAT_R16G16_SNORM 0x000000db +#define NV50_2D_DRAW_COLOR_FORMAT_R16G16_SINT 0x000000dc +#define NV50_2D_DRAW_COLOR_FORMAT_R16G16_UINT 0x000000dd +#define NV50_2D_DRAW_COLOR_FORMAT_R16G16_FLOAT 0x000000de +#define NV50_2D_DRAW_COLOR_FORMAT_A2R10G10B10_UNORM 0x000000df +#define NV50_2D_DRAW_COLOR_FORMAT_B10G11R11_FLOAT 0x000000e0 +#define NV50_2D_DRAW_COLOR_FORMAT_R32_FLOAT 0x000000e5 +#define NV50_2D_DRAW_COLOR_FORMAT_X8R8G8B8_UNORM 0x000000e6 +#define NV50_2D_DRAW_COLOR_FORMAT_X8R8G8B8_SRGB 0x000000e7 +#define NV50_2D_DRAW_COLOR_FORMAT_R5G6B5_UNORM 0x000000e8 +#define NV50_2D_DRAW_COLOR_FORMAT_A1R5G5B5_UNORM 0x000000e9 +#define NV50_2D_DRAW_COLOR_FORMAT_R8G8_UNORM 0x000000ea +#define NV50_2D_DRAW_COLOR_FORMAT_R8G8_SNORM 0x000000eb +#define NV50_2D_DRAW_COLOR_FORMAT_R8G8_SINT 0x000000ec +#define NV50_2D_DRAW_COLOR_FORMAT_R8G8_UINT 0x000000ed +#define NV50_2D_DRAW_COLOR_FORMAT_R16_UNORM 0x000000ee +#define NV50_2D_DRAW_COLOR_FORMAT_R16_SNORM 0x000000ef +#define NV50_2D_DRAW_COLOR_FORMAT_R16_SINT 0x000000f0 +#define NV50_2D_DRAW_COLOR_FORMAT_R16_UINT 0x000000f1 +#define NV50_2D_DRAW_COLOR_FORMAT_R16_FLOAT 0x000000f2 +#define NV50_2D_DRAW_COLOR_FORMAT_R8_UNORM 0x000000f3 +#define NV50_2D_DRAW_COLOR_FORMAT_R8_SNORM 0x000000f4 +#define NV50_2D_DRAW_COLOR_FORMAT_R8_SINT 0x000000f5 +#define NV50_2D_DRAW_COLOR_FORMAT_R8_UINT 0x000000f6 +#define NV50_2D_DRAW_COLOR_FORMAT_A8_UNORM 0x000000f7 +#define NV50_2D_DRAW_COLOR_FORMAT_X1R5G5B5_UNORM 0x000000f8 +#define NV50_2D_DRAW_COLOR_FORMAT_X8B8G8R8_UNORM 0x000000f9 +#define NV50_2D_DRAW_COLOR_FORMAT_X8B8G8R8_SRGB 0x000000fa +#define NV50_2D_DRAW_COLOR 0x00000588 +#define NV50_2D_DRAW_POINT16 0x000005e0 +#define NV50_2D_DRAW_POINT16_X_SHIFT 0 +#define NV50_2D_DRAW_POINT16_X_MASK 0x0000ffff +#define NV50_2D_DRAW_POINT16_Y_SHIFT 16 +#define NV50_2D_DRAW_POINT16_Y_MASK 0xffff0000 +#define NV50_2D_DRAW_POINT32_X(x) (0x00000600+((x)*8)) +#define NV50_2D_DRAW_POINT32_X__SIZE 0x00000040 +#define NV50_2D_DRAW_POINT32_Y(x) (0x00000604+((x)*8)) +#define NV50_2D_DRAW_POINT32_Y__SIZE 0x00000040 +#define NV50_2D_SIFC_BITMAP_ENABLE 0x00000800 +#define NV50_2D_SIFC_FORMAT 0x00000804 +#define NV50_2D_SIFC_FORMAT_R32G32B32A32_FLOAT 0x000000c0 +#define NV50_2D_SIFC_FORMAT_R32G32B32A32_SINT 0x000000c1 +#define NV50_2D_SIFC_FORMAT_R32G32B32A32_UINT 0x000000c2 +#define NV50_2D_SIFC_FORMAT_R32G32B32X32_FLOAT 0x000000c3 +#define NV50_2D_SIFC_FORMAT_R16G16B16A16_UNORM 0x000000c6 +#define NV50_2D_SIFC_FORMAT_R16G16B16A16_SNORM 0x000000c7 +#define NV50_2D_SIFC_FORMAT_R16G16B16A16_SINT 0x000000c8 +#define NV50_2D_SIFC_FORMAT_R16G16B16A16_UINT 0x000000c9 +#define NV50_2D_SIFC_FORMAT_R16G16B16A16_FLOAT 0x000000ca +#define NV50_2D_SIFC_FORMAT_R32G32_FLOAT 0x000000cb +#define NV50_2D_SIFC_FORMAT_R32G32_SINT 0x000000cc +#define NV50_2D_SIFC_FORMAT_R32G32_UINT 0x000000cd +#define NV50_2D_SIFC_FORMAT_R16G16B16X16_FLOAT 0x000000ce +#define NV50_2D_SIFC_FORMAT_A8R8G8B8_UNORM 0x000000cf +#define NV50_2D_SIFC_FORMAT_A8R8G8B8_SRGB 0x000000d0 +#define NV50_2D_SIFC_FORMAT_A2B10G10R10_UNORM 0x000000d1 +#define NV50_2D_SIFC_FORMAT_A2B10G10R10_UINT 0x000000d2 +#define NV50_2D_SIFC_FORMAT_A8B8G8R8_UNORM 0x000000d5 +#define NV50_2D_SIFC_FORMAT_A8B8G8R8_SRGB 0x000000d6 +#define NV50_2D_SIFC_FORMAT_A8B8G8R8_SNORM 0x000000d7 +#define NV50_2D_SIFC_FORMAT_A8B8G8R8_SINT 0x000000d8 +#define NV50_2D_SIFC_FORMAT_A8B8G8R8_UINT 0x000000d9 +#define NV50_2D_SIFC_FORMAT_R16G16_UNORM 0x000000da +#define NV50_2D_SIFC_FORMAT_R16G16_SNORM 0x000000db +#define NV50_2D_SIFC_FORMAT_R16G16_SINT 0x000000dc +#define NV50_2D_SIFC_FORMAT_R16G16_UINT 0x000000dd +#define NV50_2D_SIFC_FORMAT_R16G16_FLOAT 0x000000de +#define NV50_2D_SIFC_FORMAT_A2R10G10B10_UNORM 0x000000df +#define NV50_2D_SIFC_FORMAT_B10G11R11_FLOAT 0x000000e0 +#define NV50_2D_SIFC_FORMAT_R32_FLOAT 0x000000e5 +#define NV50_2D_SIFC_FORMAT_X8R8G8B8_UNORM 0x000000e6 +#define NV50_2D_SIFC_FORMAT_X8R8G8B8_SRGB 0x000000e7 +#define NV50_2D_SIFC_FORMAT_R5G6B5_UNORM 0x000000e8 +#define NV50_2D_SIFC_FORMAT_A1R5G5B5_UNORM 0x000000e9 +#define NV50_2D_SIFC_FORMAT_R8G8_UNORM 0x000000ea +#define NV50_2D_SIFC_FORMAT_R8G8_SNORM 0x000000eb +#define NV50_2D_SIFC_FORMAT_R8G8_SINT 0x000000ec +#define NV50_2D_SIFC_FORMAT_R8G8_UINT 0x000000ed +#define NV50_2D_SIFC_FORMAT_R16_UNORM 0x000000ee +#define NV50_2D_SIFC_FORMAT_R16_SNORM 0x000000ef +#define NV50_2D_SIFC_FORMAT_R16_SINT 0x000000f0 +#define NV50_2D_SIFC_FORMAT_R16_UINT 0x000000f1 +#define NV50_2D_SIFC_FORMAT_R16_FLOAT 0x000000f2 +#define NV50_2D_SIFC_FORMAT_R8_UNORM 0x000000f3 +#define NV50_2D_SIFC_FORMAT_R8_SNORM 0x000000f4 +#define NV50_2D_SIFC_FORMAT_R8_SINT 0x000000f5 +#define NV50_2D_SIFC_FORMAT_R8_UINT 0x000000f6 +#define NV50_2D_SIFC_FORMAT_A8_UNORM 0x000000f7 +#define NV50_2D_SIFC_FORMAT_X1R5G5B5_UNORM 0x000000f8 +#define NV50_2D_SIFC_FORMAT_X8B8G8R8_UNORM 0x000000f9 +#define NV50_2D_SIFC_FORMAT_X8B8G8R8_SRGB 0x000000fa +#define NV50_2D_SIFC_BITMAP_UNK808 0x00000808 +#define NV50_2D_SIFC_BITMAP_LSB_FIRST 0x0000080c +#define NV50_2D_SIFC_BITMAP_LINE_PACK_MODE 0x00000810 +#define NV50_2D_SIFC_BITMAP_LINE_PACK_MODE_PACKED 0x00000000 +#define NV50_2D_SIFC_BITMAP_LINE_PACK_MODE_ALIGN_BYTE 0x00000001 +#define NV50_2D_SIFC_BITMAP_LINE_PACK_MODE_ALIGN_WORD 0x00000002 +#define NV50_2D_SIFC_BITMAP_COLOR_BIT0 0x00000814 +#define NV50_2D_SIFC_BITMAP_COLOR_BIT1 0x00000818 +#define NV50_2D_SIFC_BITMAP_WRITE_BIT0_ENABLE 0x0000081c +#define NV50_2D_SIFC_WIDTH 0x00000838 +#define NV50_2D_SIFC_HEIGHT 0x0000083c +#define NV50_2D_SIFC_DX_DU_FRACT 0x00000840 +#define NV50_2D_SIFC_DX_DU_INT 0x00000844 +#define NV50_2D_SIFC_DY_DV_FRACT 0x00000848 +#define NV50_2D_SIFC_DY_DV_INT 0x0000084c +#define NV50_2D_SIFC_DST_X_FRACT 0x00000850 +#define NV50_2D_SIFC_DST_X_INT 0x00000854 +#define NV50_2D_SIFC_DST_Y_FRACT 0x00000858 +#define NV50_2D_SIFC_DST_Y_INT 0x0000085c +#define NV50_2D_SIFC_DATA 0x00000860 +#define NV50_2D_BLIT_DST_X 0x000008b0 +#define NV50_2D_BLIT_DST_Y 0x000008b4 +#define NV50_2D_BLIT_DST_W 0x000008b8 +#define NV50_2D_BLIT_DST_H 0x000008bc +#define NV50_2D_BLIT_DU_DX_FRACT 0x000008c0 +#define NV50_2D_BLIT_DU_DX_INT 0x000008c4 +#define NV50_2D_BLIT_DV_DY_FRACT 0x000008c8 +#define NV50_2D_BLIT_DV_DY_INT 0x000008cc +#define NV50_2D_BLIT_SRC_X_FRACT 0x000008d0 +#define NV50_2D_BLIT_SRC_X_INT 0x000008d4 +#define NV50_2D_BLIT_SRC_Y_FRACT 0x000008d8 +#define NV50_2D_BLIT_SRC_Y_INT 0x000008dc + + +#define NV50TCL 0x00005097 + +#define NV50TCL_NOP 0x00000100 +#define NV50TCL_NOTIFY 0x00000104 +#define NV50TCL_SERIALIZE 0x00000110 +#define NV50TCL_DMA_NOTIFY 0x00000180 +#define NV50TCL_DMA_ZETA 0x00000184 +#define NV50TCL_DMA_QUERY 0x00000188 +#define NV50TCL_DMA_VTXBUF0 0x0000018c +#define NV50TCL_DMA_LOCAL 0x00000190 +#define NV50TCL_DMA_STACK 0x00000194 +#define NV50TCL_DMA_CODE_CB 0x00000198 +#define NV50TCL_DMA_TSC 0x0000019c +#define NV50TCL_DMA_TIC 0x000001a0 +#define NV50TCL_DMA_TEXTURE 0x000001a4 +#define NV50TCL_DMA_STRMOUT 0x000001a8 +#define NV50TCL_DMA_CLIPID 0x000001ac +#define NV50TCL_DMA_COLOR(x) (0x000001c0+((x)*4)) +#define NV50TCL_DMA_COLOR__SIZE 0x00000008 +#define NV50TCL_RT_ADDRESS_HIGH(x) (0x00000200+((x)*32)) +#define NV50TCL_RT_ADDRESS_HIGH__SIZE 0x00000008 +#define NV50TCL_RT_ADDRESS_LOW(x) (0x00000204+((x)*32)) +#define NV50TCL_RT_ADDRESS_LOW__SIZE 0x00000008 +#define NV50TCL_RT_FORMAT(x) (0x00000208+((x)*32)) +#define NV50TCL_RT_FORMAT__SIZE 0x00000008 +#define NV50TCL_RT_FORMAT_R32G32B32A32_FLOAT 0x000000c0 +#define NV50TCL_RT_FORMAT_R32G32B32A32_SINT 0x000000c1 +#define NV50TCL_RT_FORMAT_R32G32B32A32_UINT 0x000000c2 +#define NV50TCL_RT_FORMAT_R32G32B32X32_FLOAT 0x000000c3 +#define NV50TCL_RT_FORMAT_R16G16B16A16_UNORM 0x000000c6 +#define NV50TCL_RT_FORMAT_R16G16B16A16_SNORM 0x000000c7 +#define NV50TCL_RT_FORMAT_R16G16B16A16_SINT 0x000000c8 +#define NV50TCL_RT_FORMAT_R16G16B16A16_UINT 0x000000c9 +#define NV50TCL_RT_FORMAT_R16G16B16A16_FLOAT 0x000000ca +#define NV50TCL_RT_FORMAT_R32G32_FLOAT 0x000000cb +#define NV50TCL_RT_FORMAT_R32G32_SINT 0x000000cc +#define NV50TCL_RT_FORMAT_R32G32_UINT 0x000000cd +#define NV50TCL_RT_FORMAT_R16G16B16X16_FLOAT 0x000000ce +#define NV50TCL_RT_FORMAT_A8R8G8B8_UNORM 0x000000cf +#define NV50TCL_RT_FORMAT_A8R8G8B8_SRGB 0x000000d0 +#define NV50TCL_RT_FORMAT_A2B10G10R10_UNORM 0x000000d1 +#define NV50TCL_RT_FORMAT_A2B10G10R10_UINT 0x000000d2 +#define NV50TCL_RT_FORMAT_A8B8G8R8_UNORM 0x000000d5 +#define NV50TCL_RT_FORMAT_A8B8G8R8_SRGB 0x000000d6 +#define NV50TCL_RT_FORMAT_A8B8G8R8_SNORM 0x000000d7 +#define NV50TCL_RT_FORMAT_A8B8G8R8_SINT 0x000000d8 +#define NV50TCL_RT_FORMAT_A8B8G8R8_UINT 0x000000d9 +#define NV50TCL_RT_FORMAT_R16G16_UNORM 0x000000da +#define NV50TCL_RT_FORMAT_R16G16_SNORM 0x000000db +#define NV50TCL_RT_FORMAT_R16G16_SINT 0x000000dc +#define NV50TCL_RT_FORMAT_R16G16_UINT 0x000000dd +#define NV50TCL_RT_FORMAT_R16G16_FLOAT 0x000000de +#define NV50TCL_RT_FORMAT_A2R10G10B10_UNORM 0x000000df +#define NV50TCL_RT_FORMAT_B10G11R11_FLOAT 0x000000e0 +#define NV50TCL_RT_FORMAT_R32_FLOAT 0x000000e5 +#define NV50TCL_RT_FORMAT_X8R8G8B8_UNORM 0x000000e6 +#define NV50TCL_RT_FORMAT_X8R8G8B8_SRGB 0x000000e7 +#define NV50TCL_RT_FORMAT_R5G6B5_UNORM 0x000000e8 +#define NV50TCL_RT_FORMAT_A1R5G5B5_UNORM 0x000000e9 +#define NV50TCL_RT_FORMAT_R8G8_UNORM 0x000000ea +#define NV50TCL_RT_FORMAT_R8G8_SNORM 0x000000eb +#define NV50TCL_RT_FORMAT_R8G8_SINT 0x000000ec +#define NV50TCL_RT_FORMAT_R8G8_UINT 0x000000ed +#define NV50TCL_RT_FORMAT_R16_UNORM 0x000000ee +#define NV50TCL_RT_FORMAT_R16_SNORM 0x000000ef +#define NV50TCL_RT_FORMAT_R16_SINT 0x000000f0 +#define NV50TCL_RT_FORMAT_R16_UINT 0x000000f1 +#define NV50TCL_RT_FORMAT_R16_FLOAT 0x000000f2 +#define NV50TCL_RT_FORMAT_R8_UNORM 0x000000f3 +#define NV50TCL_RT_FORMAT_R8_SNORM 0x000000f4 +#define NV50TCL_RT_FORMAT_R8_SINT 0x000000f5 +#define NV50TCL_RT_FORMAT_R8_UINT 0x000000f6 +#define NV50TCL_RT_FORMAT_A8_UNORM 0x000000f7 +#define NV50TCL_RT_FORMAT_X1R5G5B5_UNORM 0x000000f8 +#define NV50TCL_RT_FORMAT_X8B8G8R8_UNORM 0x000000f9 +#define NV50TCL_RT_FORMAT_X8B8G8R8_SRGB 0x000000fa +#define NV50TCL_RT_TILE_MODE(x) (0x0000020c+((x)*32)) +#define NV50TCL_RT_TILE_MODE__SIZE 0x00000008 +#define NV50TCL_RT_LAYER_STRIDE(x) (0x00000210+((x)*32)) +#define NV50TCL_RT_LAYER_STRIDE__SIZE 0x00000008 +#define NV50TCL_VTX_ATTR_1F(x) (0x00000300+((x)*4)) +#define NV50TCL_VTX_ATTR_1F__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_2H(x) (0x00000340+((x)*4)) +#define NV50TCL_VTX_ATTR_2H__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_2H_X_SHIFT 0 +#define NV50TCL_VTX_ATTR_2H_X_MASK 0x0000ffff +#define NV50TCL_VTX_ATTR_2H_Y_SHIFT 16 +#define NV50TCL_VTX_ATTR_2H_Y_MASK 0xffff0000 +#define NV50TCL_VTX_ATTR_2F_X(x) (0x00000380+((x)*8)) +#define NV50TCL_VTX_ATTR_2F_X__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_2F_Y(x) (0x00000384+((x)*8)) +#define NV50TCL_VTX_ATTR_2F_Y__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_3F_X(x) (0x00000400+((x)*16)) +#define NV50TCL_VTX_ATTR_3F_X__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_3F_Y(x) (0x00000404+((x)*16)) +#define NV50TCL_VTX_ATTR_3F_Y__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_3F_Z(x) (0x00000408+((x)*16)) +#define NV50TCL_VTX_ATTR_3F_Z__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4F_X(x) (0x00000500+((x)*16)) +#define NV50TCL_VTX_ATTR_4F_X__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4F_Y(x) (0x00000504+((x)*16)) +#define NV50TCL_VTX_ATTR_4F_Y__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4F_Z(x) (0x00000508+((x)*16)) +#define NV50TCL_VTX_ATTR_4F_Z__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4F_W(x) (0x0000050c+((x)*16)) +#define NV50TCL_VTX_ATTR_4F_W__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4H_0(x) (0x00000600+((x)*8)) +#define NV50TCL_VTX_ATTR_4H_0__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4H_0_X_SHIFT 0 +#define NV50TCL_VTX_ATTR_4H_0_X_MASK 0x0000ffff +#define NV50TCL_VTX_ATTR_4H_0_Y_SHIFT 16 +#define NV50TCL_VTX_ATTR_4H_0_Y_MASK 0xffff0000 +#define NV50TCL_VTX_ATTR_4H_1(x) (0x00000604+((x)*8)) +#define NV50TCL_VTX_ATTR_4H_1__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4H_1_Z_SHIFT 0 +#define NV50TCL_VTX_ATTR_4H_1_Z_MASK 0x0000ffff +#define NV50TCL_VTX_ATTR_4H_1_W_SHIFT 16 +#define NV50TCL_VTX_ATTR_4H_1_W_MASK 0xffff0000 +#define NV50TCL_VTX_ATTR_2I(x) (0x00000680+((x)*4)) +#define NV50TCL_VTX_ATTR_2I__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_2I_X_SHIFT 0 +#define NV50TCL_VTX_ATTR_2I_X_MASK 0x0000ffff +#define NV50TCL_VTX_ATTR_2I_Y_SHIFT 16 +#define NV50TCL_VTX_ATTR_2I_Y_MASK 0xffff0000 +#define NV50TCL_VTX_ATTR_2NI(x) (0x000006c0+((x)*4)) +#define NV50TCL_VTX_ATTR_2NI__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_2NI_X_SHIFT 0 +#define NV50TCL_VTX_ATTR_2NI_X_MASK 0x0000ffff +#define NV50TCL_VTX_ATTR_2NI_Y_SHIFT 16 +#define NV50TCL_VTX_ATTR_2NI_Y_MASK 0xffff0000 +#define NV50TCL_VTX_ATTR_4I_0(x) (0x00000700+((x)*8)) +#define NV50TCL_VTX_ATTR_4I_0__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4I_0_X_SHIFT 0 +#define NV50TCL_VTX_ATTR_4I_0_X_MASK 0x0000ffff +#define NV50TCL_VTX_ATTR_4I_0_Y_SHIFT 16 +#define NV50TCL_VTX_ATTR_4I_0_Y_MASK 0xffff0000 +#define NV50TCL_VTX_ATTR_4I_1(x) (0x00000704+((x)*8)) +#define NV50TCL_VTX_ATTR_4I_1__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4I_1_Z_SHIFT 0 +#define NV50TCL_VTX_ATTR_4I_1_Z_MASK 0x0000ffff +#define NV50TCL_VTX_ATTR_4I_1_W_SHIFT 16 +#define NV50TCL_VTX_ATTR_4I_1_W_MASK 0xffff0000 +#define NV50TCL_VTX_ATTR_4NI_0(x) (0x00000780+((x)*8)) +#define NV50TCL_VTX_ATTR_4NI_0__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4NI_0_X_SHIFT 0 +#define NV50TCL_VTX_ATTR_4NI_0_X_MASK 0x0000ffff +#define NV50TCL_VTX_ATTR_4NI_0_Y_SHIFT 16 +#define NV50TCL_VTX_ATTR_4NI_0_Y_MASK 0xffff0000 +#define NV50TCL_VTX_ATTR_4NI_1(x) (0x00000784+((x)*8)) +#define NV50TCL_VTX_ATTR_4NI_1__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4NI_1_Z_SHIFT 0 +#define NV50TCL_VTX_ATTR_4NI_1_Z_MASK 0x0000ffff +#define NV50TCL_VTX_ATTR_4NI_1_W_SHIFT 16 +#define NV50TCL_VTX_ATTR_4NI_1_W_MASK 0xffff0000 +#define NV50TCL_VTX_ATTR_4UB(x) (0x00000800+((x)*4)) +#define NV50TCL_VTX_ATTR_4UB__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4UB_X_SHIFT 0 +#define NV50TCL_VTX_ATTR_4UB_X_MASK 0x000000ff +#define NV50TCL_VTX_ATTR_4UB_Y_SHIFT 8 +#define NV50TCL_VTX_ATTR_4UB_Y_MASK 0x0000ff00 +#define NV50TCL_VTX_ATTR_4UB_Z_SHIFT 16 +#define NV50TCL_VTX_ATTR_4UB_Z_MASK 0x00ff0000 +#define NV50TCL_VTX_ATTR_4UB_W_SHIFT 24 +#define NV50TCL_VTX_ATTR_4UB_W_MASK 0xff000000 +#define NV50TCL_VTX_ATTR_4B(x) (0x00000840+((x)*4)) +#define NV50TCL_VTX_ATTR_4B__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4B_X_SHIFT 0 +#define NV50TCL_VTX_ATTR_4B_X_MASK 0x000000ff +#define NV50TCL_VTX_ATTR_4B_Y_SHIFT 8 +#define NV50TCL_VTX_ATTR_4B_Y_MASK 0x0000ff00 +#define NV50TCL_VTX_ATTR_4B_Z_SHIFT 16 +#define NV50TCL_VTX_ATTR_4B_Z_MASK 0x00ff0000 +#define NV50TCL_VTX_ATTR_4B_W_SHIFT 24 +#define NV50TCL_VTX_ATTR_4B_W_MASK 0xff000000 +#define NV50TCL_VTX_ATTR_4NUB(x) (0x00000880+((x)*4)) +#define NV50TCL_VTX_ATTR_4NUB__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4NUB_X_SHIFT 0 +#define NV50TCL_VTX_ATTR_4NUB_X_MASK 0x000000ff +#define NV50TCL_VTX_ATTR_4NUB_Y_SHIFT 8 +#define NV50TCL_VTX_ATTR_4NUB_Y_MASK 0x0000ff00 +#define NV50TCL_VTX_ATTR_4NUB_Z_SHIFT 16 +#define NV50TCL_VTX_ATTR_4NUB_Z_MASK 0x00ff0000 +#define NV50TCL_VTX_ATTR_4NUB_W_SHIFT 24 +#define NV50TCL_VTX_ATTR_4NUB_W_MASK 0xff000000 +#define NV50TCL_VTX_ATTR_4NB(x) (0x000008c0+((x)*4)) +#define NV50TCL_VTX_ATTR_4NB__SIZE 0x00000010 +#define NV50TCL_VTX_ATTR_4NB_X_SHIFT 0 +#define NV50TCL_VTX_ATTR_4NB_X_MASK 0x000000ff +#define NV50TCL_VTX_ATTR_4NB_Y_SHIFT 8 +#define NV50TCL_VTX_ATTR_4NB_Y_MASK 0x0000ff00 +#define NV50TCL_VTX_ATTR_4NB_Z_SHIFT 16 +#define NV50TCL_VTX_ATTR_4NB_Z_MASK 0x00ff0000 +#define NV50TCL_VTX_ATTR_4NB_W_SHIFT 24 +#define NV50TCL_VTX_ATTR_4NB_W_MASK 0xff000000 +#define NV50TCL_VERTEX_ARRAY_FORMAT(x) (0x00000900+((x)*16)) +#define NV50TCL_VERTEX_ARRAY_FORMAT__SIZE 0x00000010 +#define NV50TCL_VERTEX_ARRAY_FORMAT_STRIDE_SHIFT 0 +#define NV50TCL_VERTEX_ARRAY_FORMAT_STRIDE_MASK 0x00000fff +#define NV50TCL_VERTEX_ARRAY_FORMAT_ENABLE (1 << 29) +#define NV50TCL_VERTEX_ARRAY_START_HIGH(x) (0x00000904+((x)*16)) +#define NV50TCL_VERTEX_ARRAY_START_HIGH__SIZE 0x00000010 +#define NV50TCL_VERTEX_ARRAY_START_LOW(x) (0x00000908+((x)*16)) +#define NV50TCL_VERTEX_ARRAY_START_LOW__SIZE 0x00000010 +#define NV50TCL_VIEWPORT_SCALE_X(x) (0x00000a00+((x)*32)) +#define NV50TCL_VIEWPORT_SCALE_X__SIZE 0x00000010 +#define NV50TCL_VIEWPORT_SCALE_Y(x) (0x00000a04+((x)*32)) +#define NV50TCL_VIEWPORT_SCALE_Y__SIZE 0x00000010 +#define NV50TCL_VIEWPORT_SCALE_Z(x) (0x00000a08+((x)*32)) +#define NV50TCL_VIEWPORT_SCALE_Z__SIZE 0x00000010 +#define NV50TCL_VIEWPORT_TRANSLATE_X(x) (0x00000a0c+((x)*32)) +#define NV50TCL_VIEWPORT_TRANSLATE_X__SIZE 0x00000010 +#define NV50TCL_VIEWPORT_TRANSLATE_Y(x) (0x00000a10+((x)*32)) +#define NV50TCL_VIEWPORT_TRANSLATE_Y__SIZE 0x00000010 +#define NV50TCL_VIEWPORT_TRANSLATE_Z(x) (0x00000a14+((x)*32)) +#define NV50TCL_VIEWPORT_TRANSLATE_Z__SIZE 0x00000010 +#define NV50TCL_VIEWPORT_HORIZ(x) (0x00000c00+((x)*16)) +#define NV50TCL_VIEWPORT_HORIZ__SIZE 0x00000010 +#define NV50TCL_VIEWPORT_HORIZ_X_SHIFT 0 +#define NV50TCL_VIEWPORT_HORIZ_X_MASK 0x0000ffff +#define NV50TCL_VIEWPORT_HORIZ_W_SHIFT 16 +#define NV50TCL_VIEWPORT_HORIZ_W_MASK 0xffff0000 +#define NV50TCL_VIEWPORT_VERT(x) (0x00000c04+((x)*16)) +#define NV50TCL_VIEWPORT_VERT__SIZE 0x00000010 +#define NV50TCL_VIEWPORT_VERT_Y_SHIFT 0 +#define NV50TCL_VIEWPORT_VERT_Y_MASK 0x0000ffff +#define NV50TCL_VIEWPORT_VERT_H_SHIFT 16 +#define NV50TCL_VIEWPORT_VERT_H_MASK 0xffff0000 +#define NV50TCL_DEPTH_RANGE_NEAR(x) (0x00000c08+((x)*16)) +#define NV50TCL_DEPTH_RANGE_NEAR__SIZE 0x00000010 +#define NV50TCL_DEPTH_RANGE_FAR(x) (0x00000c0c+((x)*16)) +#define NV50TCL_DEPTH_RANGE_FAR__SIZE 0x00000010 +#define NV50TCL_VIEWPORT_CLIP_HORIZ(x) (0x00000d00+((x)*8)) +#define NV50TCL_VIEWPORT_CLIP_HORIZ__SIZE 0x00000008 +#define NV50TCL_VIEWPORT_CLIP_HORIZ_MIN_SHIFT 0 +#define NV50TCL_VIEWPORT_CLIP_HORIZ_MIN_MASK 0x0000ffff +#define NV50TCL_VIEWPORT_CLIP_HORIZ_MAX_SHIFT 16 +#define NV50TCL_VIEWPORT_CLIP_HORIZ_MAX_MASK 0xffff0000 +#define NV50TCL_VIEWPORT_CLIP_VERT(x) (0x00000d04+((x)*8)) +#define NV50TCL_VIEWPORT_CLIP_VERT__SIZE 0x00000008 +#define NV50TCL_VIEWPORT_CLIP_VERT_MIN_SHIFT 0 +#define NV50TCL_VIEWPORT_CLIP_VERT_MIN_MASK 0x0000ffff +#define NV50TCL_VIEWPORT_CLIP_VERT_MAX_SHIFT 16 +#define NV50TCL_VIEWPORT_CLIP_VERT_MAX_MASK 0xffff0000 +#define NV50TCL_CLIPID_REGION_HORIZ(x) (0x00000d40+((x)*8)) +#define NV50TCL_CLIPID_REGION_HORIZ__SIZE 0x00000004 +#define NV50TCL_CLIPID_REGION_VERT(x) (0x00000d44+((x)*8)) +#define NV50TCL_CLIPID_REGION_VERT__SIZE 0x00000004 +#define NV50TCL_VERTEX_BUFFER_FIRST 0x00000d74 +#define NV50TCL_VERTEX_BUFFER_COUNT 0x00000d78 +#define NV50TCL_CLEAR_COLOR(x) (0x00000d80+((x)*4)) +#define NV50TCL_CLEAR_COLOR__SIZE 0x00000004 +#define NV50TCL_CLEAR_DEPTH 0x00000d90 +#define NV50TCL_STACK_ADDRESS_HIGH 0x00000d94 +#define NV50TCL_STACK_ADDRESS_LOW 0x00000d98 +#define NV50TCL_STACK_SIZE_LOG 0x00000d9c +#define NV50TCL_CLEAR_STENCIL 0x00000da0 +#define NV50TCL_STRMOUT_PRIMITIVE_COUNT 0x00000da8 +#define NV50TCL_POLYGON_MODE_FRONT 0x00000dac +#define NV50TCL_POLYGON_MODE_FRONT_POINT 0x00001b00 +#define NV50TCL_POLYGON_MODE_FRONT_LINE 0x00001b01 +#define NV50TCL_POLYGON_MODE_FRONT_FILL 0x00001b02 +#define NV50TCL_POLYGON_MODE_BACK 0x00000db0 +#define NV50TCL_POLYGON_MODE_BACK_POINT 0x00001b00 +#define NV50TCL_POLYGON_MODE_BACK_LINE 0x00001b01 +#define NV50TCL_POLYGON_MODE_BACK_FILL 0x00001b02 +#define NV50TCL_POLYGON_SMOOTH_ENABLE 0x00000db4 +#define NV50TCL_POLYGON_OFFSET_POINT_ENABLE 0x00000dc0 +#define NV50TCL_POLYGON_OFFSET_LINE_ENABLE 0x00000dc4 +#define NV50TCL_POLYGON_OFFSET_FILL_ENABLE 0x00000dc8 +#define NV50TCL_WATCHDOG_TIMER 0x00000de4 +#define NV50TCL_WINDOW_OFFSET_X 0x00000df8 +#define NV50TCL_WINDOW_OFFSET_Y 0x00000dfc +#define NV50TCL_SCISSOR_ENABLE(x) (0x00000e00+((x)*16)) +#define NV50TCL_SCISSOR_ENABLE__SIZE 0x00000010 +#define NV50TCL_SCISSOR_HORIZ(x) (0x00000e04+((x)*16)) +#define NV50TCL_SCISSOR_HORIZ__SIZE 0x00000010 +#define NV50TCL_SCISSOR_HORIZ_MIN_SHIFT 0 +#define NV50TCL_SCISSOR_HORIZ_MIN_MASK 0x0000ffff +#define NV50TCL_SCISSOR_HORIZ_MAX_SHIFT 16 +#define NV50TCL_SCISSOR_HORIZ_MAX_MASK 0xffff0000 +#define NV50TCL_SCISSOR_VERT(x) (0x00000e08+((x)*16)) +#define NV50TCL_SCISSOR_VERT__SIZE 0x00000010 +#define NV50TCL_SCISSOR_VERT_MIN_SHIFT 0 +#define NV50TCL_SCISSOR_VERT_MIN_MASK 0x0000ffff +#define NV50TCL_SCISSOR_VERT_MAX_SHIFT 16 +#define NV50TCL_SCISSOR_VERT_MAX_MASK 0xffff0000 +#define NV50TCL_CB_ADDR 0x00000f00 +#define NV50TCL_CB_ADDR_ID_SHIFT 8 +#define NV50TCL_CB_ADDR_ID_MASK 0x003fff00 +#define NV50TCL_CB_ADDR_BUFFER_SHIFT 0 +#define NV50TCL_CB_ADDR_BUFFER_MASK 0x0000007f +#define NV50TCL_CB_DATA(x) (0x00000f04+((x)*4)) +#define NV50TCL_CB_DATA__SIZE 0x00000010 +#define NV50TCL_LOCAL_WARPS_LOG_ALLOC 0x00000f44 +#define NV50TCL_LOCAL_WARPS_NO_CLAMP 0x00000f48 +#define NV50TCL_STACK_WARPS_LOG_ALLOC 0x00000f4c +#define NV50TCL_STACK_WARPS_NO_CLAMP 0x00000f50 +#define NV50TCL_STENCIL_BACK_FUNC_REF 0x00000f54 +#define NV50TCL_STENCIL_BACK_MASK 0x00000f58 +#define NV50TCL_STENCIL_BACK_FUNC_MASK 0x00000f5c +#define NV50TCL_GP_ADDRESS_HIGH 0x00000f70 +#define NV50TCL_GP_ADDRESS_LOW 0x00000f74 +#define NV50TCL_VP_ADDRESS_HIGH 0x00000f7c +#define NV50TCL_VP_ADDRESS_LOW 0x00000f80 +#define NV50TCL_VERTEX_RUNOUT_HIGH 0x00000f84 +#define NV50TCL_VERTEX_RUNOUT_LOW 0x00000f88 +#define NV50TCL_DEPTH_BOUNDS(x) (0x00000f9c+((x)*4)) +#define NV50TCL_DEPTH_BOUNDS__SIZE 0x00000002 +#define NV50TCL_FP_ADDRESS_HIGH 0x00000fa4 +#define NV50TCL_FP_ADDRESS_LOW 0x00000fa8 +#define NV50TCL_MSAA_MASK(x) (0x00000fbc+((x)*4)) +#define NV50TCL_MSAA_MASK__SIZE 0x00000004 +#define NV50TCL_CLIPID_ADDRESS_HIGH 0x00000fcc +#define NV50TCL_CLIPID_ADDRESS_LOW 0x00000fd0 +#define NV50TCL_ZETA_ADDRESS_HIGH 0x00000fe0 +#define NV50TCL_ZETA_ADDRESS_LOW 0x00000fe4 +#define NV50TCL_ZETA_FORMAT 0x00000fe8 +#define NV50TCL_ZETA_FORMAT_Z32_FLOAT 0x0000000a +#define NV50TCL_ZETA_FORMAT_Z16_UNORM 0x00000013 +#define NV50TCL_ZETA_FORMAT_Z24S8_UNORM 0x00000014 +#define NV50TCL_ZETA_FORMAT_X8Z24_UNORM 0x00000015 +#define NV50TCL_ZETA_FORMAT_S8Z24_UNORM 0x00000016 +#define NV50TCL_ZETA_FORMAT_Z32_FLOAT_X24S8_UNORM 0x00000019 +#define NV50TCL_ZETA_TILE_MODE 0x00000fec +#define NV50TCL_ZETA_LAYER_STRIDE 0x00000ff0 +#define NV50TCL_SCREEN_SCISSOR_HORIZ 0x00000ff4 +#define NV50TCL_SCREEN_SCISSOR_HORIZ_W_SHIFT 16 +#define NV50TCL_SCREEN_SCISSOR_HORIZ_W_MASK 0xffff0000 +#define NV50TCL_SCREEN_SCISSOR_HORIZ_X_SHIFT 0 +#define NV50TCL_SCREEN_SCISSOR_HORIZ_X_MASK 0x0000ffff +#define NV50TCL_SCREEN_SCISSOR_VERT 0x00000ff8 +#define NV50TCL_SCREEN_SCISSOR_VERT_H_SHIFT 16 +#define NV50TCL_SCREEN_SCISSOR_VERT_H_MASK 0xffff0000 +#define NV50TCL_SCREEN_SCISSOR_VERT_Y_SHIFT 0 +#define NV50TCL_SCREEN_SCISSOR_VERT_Y_MASK 0x0000ffff +#define NV50TCL_VERTEX_ARRAY_LIMIT_HIGH(x) (0x00001080+((x)*8)) +#define NV50TCL_VERTEX_ARRAY_LIMIT_HIGH__SIZE 0x00000010 +#define NV50TCL_VERTEX_ARRAY_LIMIT_LOW(x) (0x00001084+((x)*8)) +#define NV50TCL_VERTEX_ARRAY_LIMIT_LOW__SIZE 0x00000010 +#define NV50TCL_RT_CONTROL 0x0000121c +#define NV50TCL_RT_CONTROL_COUNT_SHIFT 0 +#define NV50TCL_RT_CONTROL_COUNT_MASK 0x0000000f +#define NV50TCL_RT_CONTROL_MAP0_SHIFT 4 +#define NV50TCL_RT_CONTROL_MAP0_MASK 0x00000070 +#define NV50TCL_RT_CONTROL_MAP1_SHIFT 7 +#define NV50TCL_RT_CONTROL_MAP1_MASK 0x00000380 +#define NV50TCL_RT_CONTROL_MAP2_SHIFT 10 +#define NV50TCL_RT_CONTROL_MAP2_MASK 0x00001c00 +#define NV50TCL_RT_CONTROL_MAP3_SHIFT 13 +#define NV50TCL_RT_CONTROL_MAP3_MASK 0x0000e000 +#define NV50TCL_RT_CONTROL_MAP4_SHIFT 16 +#define NV50TCL_RT_CONTROL_MAP4_MASK 0x00070000 +#define NV50TCL_RT_CONTROL_MAP5_SHIFT 19 +#define NV50TCL_RT_CONTROL_MAP5_MASK 0x00380000 +#define NV50TCL_RT_CONTROL_MAP6_SHIFT 22 +#define NV50TCL_RT_CONTROL_MAP6_MASK 0x01c00000 +#define NV50TCL_RT_CONTROL_MAP7_SHIFT 25 +#define NV50TCL_RT_CONTROL_MAP7_MASK 0x0e000000 +#define NV50TCL_RT_ARRAY_MODE 0x00001224 +#define NV50TCL_RT_ARRAY_MODE_LAYERS_SHIFT 0 +#define NV50TCL_RT_ARRAY_MODE_LAYERS_MASK 0x0000ffff +#define NV50TCL_RT_ARRAY_MODE_VOLUME (1 << 16) +#define NV50TCL_ZETA_HORIZ 0x00001228 +#define NV50TCL_ZETA_VERT 0x0000122c +#define NV50TCL_ZETA_ARRAY_MODE 0x00001230 +#define NV50TCL_ZETA_ARRAY_MODE_LAYERS_SHIFT 0 +#define NV50TCL_ZETA_ARRAY_MODE_LAYERS_MASK 0x0000ffff +#define NV50TCL_ZETA_ARRAY_MODE_UNK (1 << 16) +#define NV50TCL_LINKED_TSC 0x00001234 +#define NV50TCL_RT_HORIZ(x) (0x00001240+((x)*8)) +#define NV50TCL_RT_HORIZ__SIZE 0x00000008 +#define NV50TCL_RT_VERT(x) (0x00001244+((x)*8)) +#define NV50TCL_RT_VERT__SIZE 0x00000008 +#define NV50TCL_CB_DEF_ADDRESS_HIGH 0x00001280 +#define NV50TCL_CB_DEF_ADDRESS_LOW 0x00001284 +#define NV50TCL_CB_DEF_SET 0x00001288 +#define NV50TCL_CB_DEF_SET_SIZE_SHIFT 0 +#define NV50TCL_CB_DEF_SET_SIZE_MASK 0x0000ffff +#define NV50TCL_CB_DEF_SET_BUFFER_SHIFT 16 +#define NV50TCL_CB_DEF_SET_BUFFER_MASK 0x007f0000 +#define NV50TCL_STRMOUT_BUFFERS_CTRL 0x00001294 +#define NV50TCL_STRMOUT_BUFFERS_CTRL_INTERLEAVED (1 << 0) +#define NV50TCL_STRMOUT_BUFFERS_CTRL_SEPARATE_SHIFT 4 +#define NV50TCL_STRMOUT_BUFFERS_CTRL_SEPARATE_MASK 0x000000f0 +#define NV50TCL_STRMOUT_BUFFERS_CTRL_STRIDE_SHIFT 8 +#define NV50TCL_STRMOUT_BUFFERS_CTRL_STRIDE_MASK 0x0000ff00 +#define NV50TCL_FP_RESULT_COUNT 0x00001298 +#define NV50TCL_DEPTH_TEST_ENABLE 0x000012cc +#define NV50TCL_SHADE_MODEL 0x000012d4 +#define NV50TCL_SHADE_MODEL_FLAT 0x00001d00 +#define NV50TCL_SHADE_MODEL_SMOOTH 0x00001d01 +#define NV50TCL_LOCAL_ADDRESS_HIGH 0x000012d8 +#define NV50TCL_LOCAL_ADDRESS_LOW 0x000012dc +#define NV50TCL_LOCAL_SIZE_LOG 0x000012e0 +#define NV50TCL_DEPTH_WRITE_ENABLE 0x000012e8 +#define NV50TCL_ALPHA_TEST_ENABLE 0x000012ec +#define NV50TCL_PM_SET(x) (0x000012f0+((x)*4)) +#define NV50TCL_PM_SET__SIZE 0x00000004 +#define NV50TCL_VB_ELEMENT_U8_SETUP 0x00001300 +#define NV50TCL_VB_ELEMENT_U8_SETUP_OFFSET_SHIFT 30 +#define NV50TCL_VB_ELEMENT_U8_SETUP_OFFSET_MASK 0xc0000000 +#define NV50TCL_VB_ELEMENT_U8_SETUP_COUNT_SHIFT 0 +#define NV50TCL_VB_ELEMENT_U8_SETUP_COUNT_MASK 0x3fffffff +#define NV50TCL_VB_ELEMENT_U8 0x00001304 +#define NV50TCL_VB_ELEMENT_U8_I0_SHIFT 0 +#define NV50TCL_VB_ELEMENT_U8_I0_MASK 0x000000ff +#define NV50TCL_VB_ELEMENT_U8_I1_SHIFT 8 +#define NV50TCL_VB_ELEMENT_U8_I1_MASK 0x0000ff00 +#define NV50TCL_VB_ELEMENT_U8_I2_SHIFT 16 +#define NV50TCL_VB_ELEMENT_U8_I2_MASK 0x00ff0000 +#define NV50TCL_VB_ELEMENT_U8_I3_SHIFT 24 +#define NV50TCL_VB_ELEMENT_U8_I3_MASK 0xff000000 +#define NV50TCL_DEPTH_TEST_FUNC 0x0000130c +#define NV50TCL_DEPTH_TEST_FUNC_NEVER 0x00000200 +#define NV50TCL_DEPTH_TEST_FUNC_LESS 0x00000201 +#define NV50TCL_DEPTH_TEST_FUNC_EQUAL 0x00000202 +#define NV50TCL_DEPTH_TEST_FUNC_LEQUAL 0x00000203 +#define NV50TCL_DEPTH_TEST_FUNC_GREATER 0x00000204 +#define NV50TCL_DEPTH_TEST_FUNC_NOTEQUAL 0x00000205 +#define NV50TCL_DEPTH_TEST_FUNC_GEQUAL 0x00000206 +#define NV50TCL_DEPTH_TEST_FUNC_ALWAYS 0x00000207 +#define NV50TCL_ALPHA_TEST_REF 0x00001310 +#define NV50TCL_ALPHA_TEST_FUNC 0x00001314 +#define NV50TCL_ALPHA_TEST_FUNC_NEVER 0x00000200 +#define NV50TCL_ALPHA_TEST_FUNC_LESS 0x00000201 +#define NV50TCL_ALPHA_TEST_FUNC_EQUAL 0x00000202 +#define NV50TCL_ALPHA_TEST_FUNC_LEQUAL 0x00000203 +#define NV50TCL_ALPHA_TEST_FUNC_GREATER 0x00000204 +#define NV50TCL_ALPHA_TEST_FUNC_NOTEQUAL 0x00000205 +#define NV50TCL_ALPHA_TEST_FUNC_GEQUAL 0x00000206 +#define NV50TCL_ALPHA_TEST_FUNC_ALWAYS 0x00000207 +#define NV50TCL_BLEND_COLOR(x) (0x0000131c+((x)*4)) +#define NV50TCL_BLEND_COLOR__SIZE 0x00000004 +#define NV50TCL_TIC_FLUSH 0x00001330 +#define NV50TCL_TSC_FLUSH 0x00001334 +#define NV50TCL_TEX_CACHE_CTL 0x00001338 +#define NV50TCL_BLEND_EQUATION_RGB 0x00001340 +#define NV50TCL_BLEND_EQUATION_RGB_FUNC_ADD 0x00008006 +#define NV50TCL_BLEND_EQUATION_RGB_MIN 0x00008007 +#define NV50TCL_BLEND_EQUATION_RGB_MAX 0x00008008 +#define NV50TCL_BLEND_EQUATION_RGB_FUNC_SUBTRACT 0x0000800a +#define NV50TCL_BLEND_EQUATION_RGB_FUNC_REVERSE_SUBTRACT 0x0000800b +#define NV50TCL_BLEND_FUNC_SRC_RGB 0x00001344 +#define NV50TCL_BLEND_FUNC_SRC_RGB_ZERO 0x00004000 +#define NV50TCL_BLEND_FUNC_SRC_RGB_ONE 0x00004001 +#define NV50TCL_BLEND_FUNC_SRC_RGB_SRC_COLOR 0x00004300 +#define NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_SRC_COLOR 0x00004301 +#define NV50TCL_BLEND_FUNC_SRC_RGB_SRC_ALPHA 0x00004302 +#define NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_SRC_ALPHA 0x00004303 +#define NV50TCL_BLEND_FUNC_SRC_RGB_DST_ALPHA 0x00004304 +#define NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_DST_ALPHA 0x00004305 +#define NV50TCL_BLEND_FUNC_SRC_RGB_DST_COLOR 0x00004306 +#define NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_DST_COLOR 0x00004307 +#define NV50TCL_BLEND_FUNC_SRC_RGB_SRC_ALPHA_SATURATE 0x00004308 +#define NV50TCL_BLEND_FUNC_SRC_RGB_CONSTANT_COLOR 0x0000c001 +#define NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_CONSTANT_COLOR 0x0000c002 +#define NV50TCL_BLEND_FUNC_SRC_RGB_CONSTANT_ALPHA 0x0000c003 +#define NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_CONSTANT_ALPHA 0x0000c004 +#define NV50TCL_BLEND_FUNC_SRC_RGB_SRC1_COLOR 0x0000c900 +#define NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_SRC1_COLOR 0x0000c901 +#define NV50TCL_BLEND_FUNC_SRC_RGB_SRC1_ALPHA 0x0000c902 +#define NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_SRC1_ALPHA 0x0000c903 +#define NV50TCL_BLEND_FUNC_DST_RGB 0x00001348 +#define NV50TCL_BLEND_FUNC_DST_RGB_ZERO 0x00004000 +#define NV50TCL_BLEND_FUNC_DST_RGB_ONE 0x00004001 +#define NV50TCL_BLEND_FUNC_DST_RGB_SRC_COLOR 0x00004300 +#define NV50TCL_BLEND_FUNC_DST_RGB_ONE_MINUS_SRC_COLOR 0x00004301 +#define NV50TCL_BLEND_FUNC_DST_RGB_SRC_ALPHA 0x00004302 +#define NV50TCL_BLEND_FUNC_DST_RGB_ONE_MINUS_SRC_ALPHA 0x00004303 +#define NV50TCL_BLEND_FUNC_DST_RGB_DST_ALPHA 0x00004304 +#define NV50TCL_BLEND_FUNC_DST_RGB_ONE_MINUS_DST_ALPHA 0x00004305 +#define NV50TCL_BLEND_FUNC_DST_RGB_DST_COLOR 0x00004306 +#define NV50TCL_BLEND_FUNC_DST_RGB_ONE_MINUS_DST_COLOR 0x00004307 +#define NV50TCL_BLEND_FUNC_DST_RGB_SRC_ALPHA_SATURATE 0x00004308 +#define NV50TCL_BLEND_FUNC_DST_RGB_CONSTANT_COLOR 0x0000c001 +#define NV50TCL_BLEND_FUNC_DST_RGB_ONE_MINUS_CONSTANT_COLOR 0x0000c002 +#define NV50TCL_BLEND_FUNC_DST_RGB_CONSTANT_ALPHA 0x0000c003 +#define NV50TCL_BLEND_FUNC_DST_RGB_ONE_MINUS_CONSTANT_ALPHA 0x0000c004 +#define NV50TCL_BLEND_FUNC_DST_RGB_SRC1_COLOR 0x0000c900 +#define NV50TCL_BLEND_FUNC_DST_RGB_ONE_MINUS_SRC1_COLOR 0x0000c901 +#define NV50TCL_BLEND_FUNC_DST_RGB_SRC1_ALPHA 0x0000c902 +#define NV50TCL_BLEND_FUNC_DST_RGB_ONE_MINUS_SRC1_ALPHA 0x0000c903 +#define NV50TCL_BLEND_EQUATION_ALPHA 0x0000134c +#define NV50TCL_BLEND_EQUATION_ALPHA_FUNC_ADD 0x00008006 +#define NV50TCL_BLEND_EQUATION_ALPHA_MIN 0x00008007 +#define NV50TCL_BLEND_EQUATION_ALPHA_MAX 0x00008008 +#define NV50TCL_BLEND_EQUATION_ALPHA_FUNC_SUBTRACT 0x0000800a +#define NV50TCL_BLEND_EQUATION_ALPHA_FUNC_REVERSE_SUBTRACT 0x0000800b +#define NV50TCL_BLEND_FUNC_SRC_ALPHA 0x00001350 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_ZERO 0x00004000 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_ONE 0x00004001 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_SRC_COLOR 0x00004300 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_ONE_MINUS_SRC_COLOR 0x00004301 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_SRC_ALPHA 0x00004302 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_ONE_MINUS_SRC_ALPHA 0x00004303 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_DST_ALPHA 0x00004304 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_ONE_MINUS_DST_ALPHA 0x00004305 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_DST_COLOR 0x00004306 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_ONE_MINUS_DST_COLOR 0x00004307 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_SRC_ALPHA_SATURATE 0x00004308 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_CONSTANT_COLOR 0x0000c001 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_ONE_MINUS_CONSTANT_COLOR 0x0000c002 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_CONSTANT_ALPHA 0x0000c003 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_ONE_MINUS_CONSTANT_ALPHA 0x0000c004 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_SRC1_COLOR 0x0000c900 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_ONE_MINUS_SRC1_COLOR 0x0000c901 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_SRC1_ALPHA 0x0000c902 +#define NV50TCL_BLEND_FUNC_SRC_ALPHA_ONE_MINUS_SRC1_ALPHA 0x0000c903 +#define NV50TCL_BLEND_FUNC_DST_ALPHA 0x00001358 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_ZERO 0x00004000 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_ONE 0x00004001 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_SRC_COLOR 0x00004300 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_ONE_MINUS_SRC_COLOR 0x00004301 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_SRC_ALPHA 0x00004302 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_ONE_MINUS_SRC_ALPHA 0x00004303 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_DST_ALPHA 0x00004304 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_ONE_MINUS_DST_ALPHA 0x00004305 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_DST_COLOR 0x00004306 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_ONE_MINUS_DST_COLOR 0x00004307 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_SRC_ALPHA_SATURATE 0x00004308 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_CONSTANT_COLOR 0x0000c001 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_ONE_MINUS_CONSTANT_COLOR 0x0000c002 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_CONSTANT_ALPHA 0x0000c003 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_ONE_MINUS_CONSTANT_ALPHA 0x0000c004 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_SRC1_COLOR 0x0000c900 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_ONE_MINUS_SRC1_COLOR 0x0000c901 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_SRC1_ALPHA 0x0000c902 +#define NV50TCL_BLEND_FUNC_DST_ALPHA_ONE_MINUS_SRC1_ALPHA 0x0000c903 +#define NV50TCL_BLEND_ENABLE(x) (0x00001360+((x)*4)) +#define NV50TCL_BLEND_ENABLE__SIZE 0x00000008 +#define NV50TCL_STENCIL_FRONT_ENABLE 0x00001380 +#define NV50TCL_STENCIL_FRONT_OP_FAIL 0x00001384 +#define NV50TCL_STENCIL_FRONT_OP_FAIL_ZERO 0x00000000 +#define NV50TCL_STENCIL_FRONT_OP_FAIL_INVERT 0x0000150a +#define NV50TCL_STENCIL_FRONT_OP_FAIL_KEEP 0x00001e00 +#define NV50TCL_STENCIL_FRONT_OP_FAIL_REPLACE 0x00001e01 +#define NV50TCL_STENCIL_FRONT_OP_FAIL_INCR 0x00001e02 +#define NV50TCL_STENCIL_FRONT_OP_FAIL_DECR 0x00001e03 +#define NV50TCL_STENCIL_FRONT_OP_FAIL_INCR_WRAP 0x00008507 +#define NV50TCL_STENCIL_FRONT_OP_FAIL_DECR_WRAP 0x00008508 +#define NV50TCL_STENCIL_FRONT_OP_ZFAIL 0x00001388 +#define NV50TCL_STENCIL_FRONT_OP_ZFAIL_ZERO 0x00000000 +#define NV50TCL_STENCIL_FRONT_OP_ZFAIL_INVERT 0x0000150a +#define NV50TCL_STENCIL_FRONT_OP_ZFAIL_KEEP 0x00001e00 +#define NV50TCL_STENCIL_FRONT_OP_ZFAIL_REPLACE 0x00001e01 +#define NV50TCL_STENCIL_FRONT_OP_ZFAIL_INCR 0x00001e02 +#define NV50TCL_STENCIL_FRONT_OP_ZFAIL_DECR 0x00001e03 +#define NV50TCL_STENCIL_FRONT_OP_ZFAIL_INCR_WRAP 0x00008507 +#define NV50TCL_STENCIL_FRONT_OP_ZFAIL_DECR_WRAP 0x00008508 +#define NV50TCL_STENCIL_FRONT_OP_ZPASS 0x0000138c +#define NV50TCL_STENCIL_FRONT_OP_ZPASS_ZERO 0x00000000 +#define NV50TCL_STENCIL_FRONT_OP_ZPASS_INVERT 0x0000150a +#define NV50TCL_STENCIL_FRONT_OP_ZPASS_KEEP 0x00001e00 +#define NV50TCL_STENCIL_FRONT_OP_ZPASS_REPLACE 0x00001e01 +#define NV50TCL_STENCIL_FRONT_OP_ZPASS_INCR 0x00001e02 +#define NV50TCL_STENCIL_FRONT_OP_ZPASS_DECR 0x00001e03 +#define NV50TCL_STENCIL_FRONT_OP_ZPASS_INCR_WRAP 0x00008507 +#define NV50TCL_STENCIL_FRONT_OP_ZPASS_DECR_WRAP 0x00008508 +#define NV50TCL_STENCIL_FRONT_FUNC_FUNC 0x00001390 +#define NV50TCL_STENCIL_FRONT_FUNC_FUNC_NEVER 0x00000200 +#define NV50TCL_STENCIL_FRONT_FUNC_FUNC_LESS 0x00000201 +#define NV50TCL_STENCIL_FRONT_FUNC_FUNC_EQUAL 0x00000202 +#define NV50TCL_STENCIL_FRONT_FUNC_FUNC_LEQUAL 0x00000203 +#define NV50TCL_STENCIL_FRONT_FUNC_FUNC_GREATER 0x00000204 +#define NV50TCL_STENCIL_FRONT_FUNC_FUNC_NOTEQUAL 0x00000205 +#define NV50TCL_STENCIL_FRONT_FUNC_FUNC_GEQUAL 0x00000206 +#define NV50TCL_STENCIL_FRONT_FUNC_FUNC_ALWAYS 0x00000207 +#define NV50TCL_STENCIL_FRONT_FUNC_REF 0x00001394 +#define NV50TCL_STENCIL_FRONT_MASK 0x00001398 +#define NV50TCL_STENCIL_FRONT_FUNC_MASK 0x0000139c +#define NV50TCL_FRAG_COLOR_CLAMP_EN 0x000013a8 +#define NV50TCL_Y_ORIGIN_BOTTOM 0x000013ac +#define NV50TCL_LINE_WIDTH 0x000013b0 +#define NV50TCL_TEX_LIMITS(x) (0x000013b4+((x)*4)) +#define NV50TCL_TEX_LIMITS__SIZE 0x00000003 +#define NV50TCL_TEX_LIMITS_SAMPLERS_LOG2_SHIFT 0 +#define NV50TCL_TEX_LIMITS_SAMPLERS_LOG2_MASK 0x0000000f +#define NV50TCL_TEX_LIMITS_TEXTURES_LOG2_SHIFT 4 +#define NV50TCL_TEX_LIMITS_TEXTURES_LOG2_MASK 0x000000f0 +#define NV50TCL_POINT_COORD_REPLACE_MAP(x) (0x000013c0+((x)*4)) +#define NV50TCL_POINT_COORD_REPLACE_MAP__SIZE 0x00000008 +#define NV50TCL_VP_START_ID 0x0000140c +#define NV50TCL_GP_START_ID 0x00001410 +#define NV50TCL_FP_START_ID 0x00001414 +#define NV50TCL_GP_VERTEX_OUTPUT_COUNT 0x00001420 +#define NV50TCL_VB_ELEMENT_BASE 0x00001434 +#define NV50TCL_CLEAR_FLAGS 0x0000143c +#define NV50TCL_CLEAR_FLAGS_OGL (1 << 0) +#define NV50TCL_CLEAR_FLAGS_D3D (1 << 4) +#define NV50TCL_INSTANCE_BASE 0x00001438 +#define NV50TCL_CODE_CB_FLUSH 0x00001440 +#define NV50TCL_BIND_TSC(x) (0x00001444+((x)*8)) +#define NV50TCL_BIND_TSC__SIZE 0x00000003 +#define NV50TCL_BIND_TSC_VALID (1 << 0) +#define NV50TCL_BIND_TSC_SAMPLER_SHIFT 4 +#define NV50TCL_BIND_TSC_SAMPLER_MASK 0x000000f0 +#define NV50TCL_BIND_TSC_TSC_SHIFT 12 +#define NV50TCL_BIND_TSC_TSC_MASK 0x001ff000 +#define NV50TCL_BIND_TIC(x) (0x00001448+((x)*8)) +#define NV50TCL_BIND_TIC__SIZE 0x00000003 +#define NV50TCL_BIND_TIC_VALID (1 << 0) +#define NV50TCL_BIND_TIC_TEXTURE_SHIFT 1 +#define NV50TCL_BIND_TIC_TEXTURE_MASK 0x000001fe +#define NV50TCL_BIND_TIC_TIC_SHIFT 9 +#define NV50TCL_BIND_TIC_TIC_MASK 0x7ffffe00 +#define NV50TCL_STRMOUT_MAP(x) (0x00001480+((x)*4)) +#define NV50TCL_STRMOUT_MAP__SIZE 0x00000020 +#define NV50TCL_CLIPID_HEIGHT 0x00001504 +#define NV50TCL_VP_CLIP_DISTANCE_ENABLE 0x00001510 +#define NV50TCL_VP_CLIP_DISTANCE_ENABLE_0 (1 << 0) +#define NV50TCL_VP_CLIP_DISTANCE_ENABLE_1 (1 << 1) +#define NV50TCL_VP_CLIP_DISTANCE_ENABLE_2 (1 << 2) +#define NV50TCL_VP_CLIP_DISTANCE_ENABLE_3 (1 << 3) +#define NV50TCL_VP_CLIP_DISTANCE_ENABLE_4 (1 << 4) +#define NV50TCL_VP_CLIP_DISTANCE_ENABLE_5 (1 << 5) +#define NV50TCL_VP_CLIP_DISTANCE_ENABLE_6 (1 << 6) +#define NV50TCL_VP_CLIP_DISTANCE_ENABLE_7 (1 << 7) +#define NV50TCL_SAMPLECNT_ENABLE 0x00001514 +#define NV50TCL_POINT_SIZE 0x00001518 +#define NV50TCL_POINT_SPRITE_ENABLE 0x00001520 +#define NV50TCL_SAMPLECNT_RESET 0x00001530 +#define NV50TCL_ZETA_ENABLE 0x00001538 +#define NV50TCL_MULTISAMPLE_CTRL 0x0000153c +#define NV50TCL_MULTISAMPLE_CTRL_ALPHA_TO_COVERAGE (1 << 0) +#define NV50TCL_MULTISAMPLE_CTRL_ALPHA_TO_ONE (1 << 4) +#define NV50TCL_NOPERSPECTIVE_BITMAP(x) (0x00001540+((x)*4)) +#define NV50TCL_NOPERSPECTIVE_BITMAP__SIZE 0x00000004 +#define NV50TCL_COND_ADDRESS_HIGH 0x00001550 +#define NV50TCL_COND_ADDRESS_LOW 0x00001554 +#define NV50TCL_COND_MODE 0x00001558 +#define NV50TCL_COND_MODE_NEVER 0x00000000 +#define NV50TCL_COND_MODE_ALWAYS 0x00000001 +#define NV50TCL_COND_MODE_RES 0x00000002 +#define NV50TCL_COND_MODE_NOT_RES_AND_NOT_ID 0x00000003 +#define NV50TCL_COND_MODE_RES_OR_ID 0x00000004 +#define NV50TCL_TSC_ADDRESS_HIGH 0x0000155c +#define NV50TCL_TSC_ADDRESS_LOW 0x00001560 +#define NV50TCL_TSC_LIMIT 0x00001564 +#define NV50TCL_POLYGON_OFFSET_FACTOR 0x0000156c +#define NV50TCL_LINE_SMOOTH_ENABLE 0x00001570 +#define NV50TCL_TIC_ADDRESS_HIGH 0x00001574 +#define NV50TCL_TIC_ADDRESS_LOW 0x00001578 +#define NV50TCL_TIC_LIMIT 0x0000157c +#define NV50TCL_PM_CONTROL(x) (0x00001580+((x)*4)) +#define NV50TCL_PM_CONTROL__SIZE 0x00000004 +#define NV50TCL_PM_CONTROL_UNK0 (1 << 0) +#define NV50TCL_PM_CONTROL_UNK1_SHIFT 4 +#define NV50TCL_PM_CONTROL_UNK1_MASK 0x00000070 +#define NV50TCL_PM_CONTROL_UNK2_SHIFT 8 +#define NV50TCL_PM_CONTROL_UNK2_MASK 0xffffff00 +#define NV50TCL_STENCIL_BACK_ENABLE 0x00001594 +#define NV50TCL_STENCIL_BACK_OP_FAIL 0x00001598 +#define NV50TCL_STENCIL_BACK_OP_FAIL_ZERO 0x00000000 +#define NV50TCL_STENCIL_BACK_OP_FAIL_INVERT 0x0000150a +#define NV50TCL_STENCIL_BACK_OP_FAIL_KEEP 0x00001e00 +#define NV50TCL_STENCIL_BACK_OP_FAIL_REPLACE 0x00001e01 +#define NV50TCL_STENCIL_BACK_OP_FAIL_INCR 0x00001e02 +#define NV50TCL_STENCIL_BACK_OP_FAIL_DECR 0x00001e03 +#define NV50TCL_STENCIL_BACK_OP_FAIL_INCR_WRAP 0x00008507 +#define NV50TCL_STENCIL_BACK_OP_FAIL_DECR_WRAP 0x00008508 +#define NV50TCL_STENCIL_BACK_OP_ZFAIL 0x0000159c +#define NV50TCL_STENCIL_BACK_OP_ZFAIL_ZERO 0x00000000 +#define NV50TCL_STENCIL_BACK_OP_ZFAIL_INVERT 0x0000150a +#define NV50TCL_STENCIL_BACK_OP_ZFAIL_KEEP 0x00001e00 +#define NV50TCL_STENCIL_BACK_OP_ZFAIL_REPLACE 0x00001e01 +#define NV50TCL_STENCIL_BACK_OP_ZFAIL_INCR 0x00001e02 +#define NV50TCL_STENCIL_BACK_OP_ZFAIL_DECR 0x00001e03 +#define NV50TCL_STENCIL_BACK_OP_ZFAIL_INCR_WRAP 0x00008507 +#define NV50TCL_STENCIL_BACK_OP_ZFAIL_DECR_WRAP 0x00008508 +#define NV50TCL_STENCIL_BACK_OP_ZPASS 0x000015a0 +#define NV50TCL_STENCIL_BACK_OP_ZPASS_ZERO 0x00000000 +#define NV50TCL_STENCIL_BACK_OP_ZPASS_INVERT 0x0000150a +#define NV50TCL_STENCIL_BACK_OP_ZPASS_KEEP 0x00001e00 +#define NV50TCL_STENCIL_BACK_OP_ZPASS_REPLACE 0x00001e01 +#define NV50TCL_STENCIL_BACK_OP_ZPASS_INCR 0x00001e02 +#define NV50TCL_STENCIL_BACK_OP_ZPASS_DECR 0x00001e03 +#define NV50TCL_STENCIL_BACK_OP_ZPASS_INCR_WRAP 0x00008507 +#define NV50TCL_STENCIL_BACK_OP_ZPASS_DECR_WRAP 0x00008508 +#define NV50TCL_STENCIL_BACK_FUNC_FUNC 0x000015a4 +#define NV50TCL_STENCIL_BACK_FUNC_FUNC_NEVER 0x00000200 +#define NV50TCL_STENCIL_BACK_FUNC_FUNC_LESS 0x00000201 +#define NV50TCL_STENCIL_BACK_FUNC_FUNC_EQUAL 0x00000202 +#define NV50TCL_STENCIL_BACK_FUNC_FUNC_LEQUAL 0x00000203 +#define NV50TCL_STENCIL_BACK_FUNC_FUNC_GREATER 0x00000204 +#define NV50TCL_STENCIL_BACK_FUNC_FUNC_NOTEQUAL 0x00000205 +#define NV50TCL_STENCIL_BACK_FUNC_FUNC_GEQUAL 0x00000206 +#define NV50TCL_STENCIL_BACK_FUNC_FUNC_ALWAYS 0x00000207 +#define NV50TCL_FRAMEBUFFER_SRGB 0x000015b8 +#define NV50TCL_POLYGON_OFFSET_UNITS 0x000015bc +#define NV50TCL_GP_BUILTIN_RESULT_EN 0x000015cc +#define NV50TCL_GP_BUILTIN_RESULT_EN_VPORT_IDX (1 << 0) +#define NV50TCL_GP_BUILTIN_RESULT_EN_LAYER_IDX (1 << 16) +#define NV50TCL_MULTISAMPLE_MODE 0x000015d0 +#define NV50TCL_MULTISAMPLE_MODE_1X 0x00000000 +#define NV50TCL_MULTISAMPLE_MODE_2XMS 0x00000001 +#define NV50TCL_MULTISAMPLE_MODE_4XMS 0x00000002 +#define NV50TCL_MULTISAMPLE_MODE_8XMS 0x00000004 +#define NV50TCL_MULTISAMPLE_MODE_4XMS_4XCS 0x00000008 +#define NV50TCL_MULTISAMPLE_MODE_4XMS_12XCS 0x00000009 +#define NV50TCL_MULTISAMPLE_MODE_8XMS_8XCS 0x0000000a +#define NV50TCL_VERTEX_BEGIN 0x000015dc +#define NV50TCL_VERTEX_BEGIN_POINTS 0x00000000 +#define NV50TCL_VERTEX_BEGIN_LINES 0x00000001 +#define NV50TCL_VERTEX_BEGIN_LINE_LOOP 0x00000002 +#define NV50TCL_VERTEX_BEGIN_LINE_STRIP 0x00000003 +#define NV50TCL_VERTEX_BEGIN_TRIANGLES 0x00000004 +#define NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP 0x00000005 +#define NV50TCL_VERTEX_BEGIN_TRIANGLE_FAN 0x00000006 +#define NV50TCL_VERTEX_BEGIN_QUADS 0x00000007 +#define NV50TCL_VERTEX_BEGIN_QUAD_STRIP 0x00000008 +#define NV50TCL_VERTEX_BEGIN_POLYGON 0x00000009 +#define NV50TCL_VERTEX_BEGIN_LINES_ADJACENCY 0x0000000a +#define NV50TCL_VERTEX_BEGIN_LINE_STRIP_ADJACENCY 0x0000000b +#define NV50TCL_VERTEX_BEGIN_TRIANGLES_ADJACENCY 0x0000000c +#define NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP_ADJACENCY 0x0000000d +#define NV50TCL_VERTEX_BEGIN_PATCHES 0x0000000e +#define NV50TCL_VERTEX_END 0x000015e0 +#define NV50TCL_EDGEFLAG_ENABLE 0x000015e4 +#define NV50TCL_VB_ELEMENT_U32 0x000015e8 +#define NV50TCL_VB_ELEMENT_U16_SETUP 0x000015ec +#define NV50TCL_VB_ELEMENT_U16_SETUP_OFFSET_SHIFT 30 +#define NV50TCL_VB_ELEMENT_U16_SETUP_OFFSET_MASK 0xc0000000 +#define NV50TCL_VB_ELEMENT_U16_SETUP_COUNT_SHIFT 0 +#define NV50TCL_VB_ELEMENT_U16_SETUP_COUNT_MASK 0x3fffffff +#define NV50TCL_VB_ELEMENT_U16 0x000015f0 +#define NV50TCL_VB_ELEMENT_U16_I0_SHIFT 0 +#define NV50TCL_VB_ELEMENT_U16_I0_MASK 0x0000ffff +#define NV50TCL_VB_ELEMENT_U16_I1_SHIFT 16 +#define NV50TCL_VB_ELEMENT_U16_I1_MASK 0xffff0000 +#define NV50TCL_VERTEX_BASE_HIGH 0x000015f4 +#define NV50TCL_VERTEX_BASE_LOW 0x000015f8 +#define NV50TCL_VERTEX_DATA 0x00001640 +#define NV50TCL_PRIM_RESTART_ENABLE 0x00001644 +#define NV50TCL_PRIM_RESTART_INDEX 0x00001648 +#define NV50TCL_VP_GP_BUILTIN_ATTR_EN 0x0000164c +#define NV50TCL_VP_GP_BUILTIN_ATTR_EN_VERTEX_ID (1 << 0) +#define NV50TCL_VP_GP_BUILTIN_ATTR_EN_INSTANCE_ID (1 << 4) +#define NV50TCL_VP_GP_BUILTIN_ATTR_EN_PRIMITIVE_ID (1 << 8) +#define NV50TCL_VP_GP_BUILTIN_ATTR_EN_UNK12 (1 << 12) +#define NV50TCL_VP_ATTR_EN_0 0x00001650 +#define NV50TCL_VP_ATTR_EN_0_7_SHIFT 28 +#define NV50TCL_VP_ATTR_EN_0_7_MASK 0xf0000000 +#define NV50TCL_VP_ATTR_EN_0_7_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_0_7_XNNN 0x10000000 +#define NV50TCL_VP_ATTR_EN_0_7_NYNN 0x20000000 +#define NV50TCL_VP_ATTR_EN_0_7_XYNN 0x30000000 +#define NV50TCL_VP_ATTR_EN_0_7_NNZN 0x40000000 +#define NV50TCL_VP_ATTR_EN_0_7_XNZN 0x50000000 +#define NV50TCL_VP_ATTR_EN_0_7_NYZN 0x60000000 +#define NV50TCL_VP_ATTR_EN_0_7_XYZN 0x70000000 +#define NV50TCL_VP_ATTR_EN_0_7_NNNW 0x80000000 +#define NV50TCL_VP_ATTR_EN_0_7_XNNW 0x90000000 +#define NV50TCL_VP_ATTR_EN_0_7_NYNW 0xa0000000 +#define NV50TCL_VP_ATTR_EN_0_7_XYNW 0xb0000000 +#define NV50TCL_VP_ATTR_EN_0_7_NNZW 0xc0000000 +#define NV50TCL_VP_ATTR_EN_0_7_XNZW 0xd0000000 +#define NV50TCL_VP_ATTR_EN_0_7_NYZW 0xe0000000 +#define NV50TCL_VP_ATTR_EN_0_7_XYZW 0xf0000000 +#define NV50TCL_VP_ATTR_EN_0_6_SHIFT 24 +#define NV50TCL_VP_ATTR_EN_0_6_MASK 0x0f000000 +#define NV50TCL_VP_ATTR_EN_0_6_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_0_6_XNNN 0x01000000 +#define NV50TCL_VP_ATTR_EN_0_6_NYNN 0x02000000 +#define NV50TCL_VP_ATTR_EN_0_6_XYNN 0x03000000 +#define NV50TCL_VP_ATTR_EN_0_6_NNZN 0x04000000 +#define NV50TCL_VP_ATTR_EN_0_6_XNZN 0x05000000 +#define NV50TCL_VP_ATTR_EN_0_6_NYZN 0x06000000 +#define NV50TCL_VP_ATTR_EN_0_6_XYZN 0x07000000 +#define NV50TCL_VP_ATTR_EN_0_6_NNNW 0x08000000 +#define NV50TCL_VP_ATTR_EN_0_6_XNNW 0x09000000 +#define NV50TCL_VP_ATTR_EN_0_6_NYNW 0x0a000000 +#define NV50TCL_VP_ATTR_EN_0_6_XYNW 0x0b000000 +#define NV50TCL_VP_ATTR_EN_0_6_NNZW 0x0c000000 +#define NV50TCL_VP_ATTR_EN_0_6_XNZW 0x0d000000 +#define NV50TCL_VP_ATTR_EN_0_6_NYZW 0x0e000000 +#define NV50TCL_VP_ATTR_EN_0_6_XYZW 0x0f000000 +#define NV50TCL_VP_ATTR_EN_0_5_SHIFT 20 +#define NV50TCL_VP_ATTR_EN_0_5_MASK 0x00f00000 +#define NV50TCL_VP_ATTR_EN_0_5_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_0_5_XNNN 0x00100000 +#define NV50TCL_VP_ATTR_EN_0_5_NYNN 0x00200000 +#define NV50TCL_VP_ATTR_EN_0_5_XYNN 0x00300000 +#define NV50TCL_VP_ATTR_EN_0_5_NNZN 0x00400000 +#define NV50TCL_VP_ATTR_EN_0_5_XNZN 0x00500000 +#define NV50TCL_VP_ATTR_EN_0_5_NYZN 0x00600000 +#define NV50TCL_VP_ATTR_EN_0_5_XYZN 0x00700000 +#define NV50TCL_VP_ATTR_EN_0_5_NNNW 0x00800000 +#define NV50TCL_VP_ATTR_EN_0_5_XNNW 0x00900000 +#define NV50TCL_VP_ATTR_EN_0_5_NYNW 0x00a00000 +#define NV50TCL_VP_ATTR_EN_0_5_XYNW 0x00b00000 +#define NV50TCL_VP_ATTR_EN_0_5_NNZW 0x00c00000 +#define NV50TCL_VP_ATTR_EN_0_5_XNZW 0x00d00000 +#define NV50TCL_VP_ATTR_EN_0_5_NYZW 0x00e00000 +#define NV50TCL_VP_ATTR_EN_0_5_XYZW 0x00f00000 +#define NV50TCL_VP_ATTR_EN_0_4_SHIFT 16 +#define NV50TCL_VP_ATTR_EN_0_4_MASK 0x000f0000 +#define NV50TCL_VP_ATTR_EN_0_4_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_0_4_XNNN 0x00010000 +#define NV50TCL_VP_ATTR_EN_0_4_NYNN 0x00020000 +#define NV50TCL_VP_ATTR_EN_0_4_XYNN 0x00030000 +#define NV50TCL_VP_ATTR_EN_0_4_NNZN 0x00040000 +#define NV50TCL_VP_ATTR_EN_0_4_XNZN 0x00050000 +#define NV50TCL_VP_ATTR_EN_0_4_NYZN 0x00060000 +#define NV50TCL_VP_ATTR_EN_0_4_XYZN 0x00070000 +#define NV50TCL_VP_ATTR_EN_0_4_NNNW 0x00080000 +#define NV50TCL_VP_ATTR_EN_0_4_XNNW 0x00090000 +#define NV50TCL_VP_ATTR_EN_0_4_NYNW 0x000a0000 +#define NV50TCL_VP_ATTR_EN_0_4_XYNW 0x000b0000 +#define NV50TCL_VP_ATTR_EN_0_4_NNZW 0x000c0000 +#define NV50TCL_VP_ATTR_EN_0_4_XNZW 0x000d0000 +#define NV50TCL_VP_ATTR_EN_0_4_NYZW 0x000e0000 +#define NV50TCL_VP_ATTR_EN_0_4_XYZW 0x000f0000 +#define NV50TCL_VP_ATTR_EN_0_3_SHIFT 12 +#define NV50TCL_VP_ATTR_EN_0_3_MASK 0x0000f000 +#define NV50TCL_VP_ATTR_EN_0_3_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_0_3_XNNN 0x00001000 +#define NV50TCL_VP_ATTR_EN_0_3_NYNN 0x00002000 +#define NV50TCL_VP_ATTR_EN_0_3_XYNN 0x00003000 +#define NV50TCL_VP_ATTR_EN_0_3_NNZN 0x00004000 +#define NV50TCL_VP_ATTR_EN_0_3_XNZN 0x00005000 +#define NV50TCL_VP_ATTR_EN_0_3_NYZN 0x00006000 +#define NV50TCL_VP_ATTR_EN_0_3_XYZN 0x00007000 +#define NV50TCL_VP_ATTR_EN_0_3_NNNW 0x00008000 +#define NV50TCL_VP_ATTR_EN_0_3_XNNW 0x00009000 +#define NV50TCL_VP_ATTR_EN_0_3_NYNW 0x0000a000 +#define NV50TCL_VP_ATTR_EN_0_3_XYNW 0x0000b000 +#define NV50TCL_VP_ATTR_EN_0_3_NNZW 0x0000c000 +#define NV50TCL_VP_ATTR_EN_0_3_XNZW 0x0000d000 +#define NV50TCL_VP_ATTR_EN_0_3_NYZW 0x0000e000 +#define NV50TCL_VP_ATTR_EN_0_3_XYZW 0x0000f000 +#define NV50TCL_VP_ATTR_EN_0_2_SHIFT 8 +#define NV50TCL_VP_ATTR_EN_0_2_MASK 0x00000f00 +#define NV50TCL_VP_ATTR_EN_0_2_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_0_2_XNNN 0x00000100 +#define NV50TCL_VP_ATTR_EN_0_2_NYNN 0x00000200 +#define NV50TCL_VP_ATTR_EN_0_2_XYNN 0x00000300 +#define NV50TCL_VP_ATTR_EN_0_2_NNZN 0x00000400 +#define NV50TCL_VP_ATTR_EN_0_2_XNZN 0x00000500 +#define NV50TCL_VP_ATTR_EN_0_2_NYZN 0x00000600 +#define NV50TCL_VP_ATTR_EN_0_2_XYZN 0x00000700 +#define NV50TCL_VP_ATTR_EN_0_2_NNNW 0x00000800 +#define NV50TCL_VP_ATTR_EN_0_2_XNNW 0x00000900 +#define NV50TCL_VP_ATTR_EN_0_2_NYNW 0x00000a00 +#define NV50TCL_VP_ATTR_EN_0_2_XYNW 0x00000b00 +#define NV50TCL_VP_ATTR_EN_0_2_NNZW 0x00000c00 +#define NV50TCL_VP_ATTR_EN_0_2_XNZW 0x00000d00 +#define NV50TCL_VP_ATTR_EN_0_2_NYZW 0x00000e00 +#define NV50TCL_VP_ATTR_EN_0_2_XYZW 0x00000f00 +#define NV50TCL_VP_ATTR_EN_0_1_SHIFT 4 +#define NV50TCL_VP_ATTR_EN_0_1_MASK 0x000000f0 +#define NV50TCL_VP_ATTR_EN_0_1_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_0_1_XNNN 0x00000010 +#define NV50TCL_VP_ATTR_EN_0_1_NYNN 0x00000020 +#define NV50TCL_VP_ATTR_EN_0_1_XYNN 0x00000030 +#define NV50TCL_VP_ATTR_EN_0_1_NNZN 0x00000040 +#define NV50TCL_VP_ATTR_EN_0_1_XNZN 0x00000050 +#define NV50TCL_VP_ATTR_EN_0_1_NYZN 0x00000060 +#define NV50TCL_VP_ATTR_EN_0_1_XYZN 0x00000070 +#define NV50TCL_VP_ATTR_EN_0_1_NNNW 0x00000080 +#define NV50TCL_VP_ATTR_EN_0_1_XNNW 0x00000090 +#define NV50TCL_VP_ATTR_EN_0_1_NYNW 0x000000a0 +#define NV50TCL_VP_ATTR_EN_0_1_XYNW 0x000000b0 +#define NV50TCL_VP_ATTR_EN_0_1_NNZW 0x000000c0 +#define NV50TCL_VP_ATTR_EN_0_1_XNZW 0x000000d0 +#define NV50TCL_VP_ATTR_EN_0_1_NYZW 0x000000e0 +#define NV50TCL_VP_ATTR_EN_0_1_XYZW 0x000000f0 +#define NV50TCL_VP_ATTR_EN_0_0_SHIFT 0 +#define NV50TCL_VP_ATTR_EN_0_0_MASK 0x0000000f +#define NV50TCL_VP_ATTR_EN_0_0_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_0_0_XNNN 0x00000001 +#define NV50TCL_VP_ATTR_EN_0_0_NYNN 0x00000002 +#define NV50TCL_VP_ATTR_EN_0_0_XYNN 0x00000003 +#define NV50TCL_VP_ATTR_EN_0_0_NNZN 0x00000004 +#define NV50TCL_VP_ATTR_EN_0_0_XNZN 0x00000005 +#define NV50TCL_VP_ATTR_EN_0_0_NYZN 0x00000006 +#define NV50TCL_VP_ATTR_EN_0_0_XYZN 0x00000007 +#define NV50TCL_VP_ATTR_EN_0_0_NNNW 0x00000008 +#define NV50TCL_VP_ATTR_EN_0_0_XNNW 0x00000009 +#define NV50TCL_VP_ATTR_EN_0_0_NYNW 0x0000000a +#define NV50TCL_VP_ATTR_EN_0_0_XYNW 0x0000000b +#define NV50TCL_VP_ATTR_EN_0_0_NNZW 0x0000000c +#define NV50TCL_VP_ATTR_EN_0_0_XNZW 0x0000000d +#define NV50TCL_VP_ATTR_EN_0_0_NYZW 0x0000000e +#define NV50TCL_VP_ATTR_EN_0_0_XYZW 0x0000000f +#define NV50TCL_VP_ATTR_EN_1 0x00001654 +#define NV50TCL_VP_ATTR_EN_1_15_SHIFT 28 +#define NV50TCL_VP_ATTR_EN_1_15_MASK 0xf0000000 +#define NV50TCL_VP_ATTR_EN_1_15_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_1_15_XNNN 0x10000000 +#define NV50TCL_VP_ATTR_EN_1_15_NYNN 0x20000000 +#define NV50TCL_VP_ATTR_EN_1_15_XYNN 0x30000000 +#define NV50TCL_VP_ATTR_EN_1_15_NNZN 0x40000000 +#define NV50TCL_VP_ATTR_EN_1_15_XNZN 0x50000000 +#define NV50TCL_VP_ATTR_EN_1_15_NYZN 0x60000000 +#define NV50TCL_VP_ATTR_EN_1_15_XYZN 0x70000000 +#define NV50TCL_VP_ATTR_EN_1_15_NNNW 0x80000000 +#define NV50TCL_VP_ATTR_EN_1_15_XNNW 0x90000000 +#define NV50TCL_VP_ATTR_EN_1_15_NYNW 0xa0000000 +#define NV50TCL_VP_ATTR_EN_1_15_XYNW 0xb0000000 +#define NV50TCL_VP_ATTR_EN_1_15_NNZW 0xc0000000 +#define NV50TCL_VP_ATTR_EN_1_15_XNZW 0xd0000000 +#define NV50TCL_VP_ATTR_EN_1_15_NYZW 0xe0000000 +#define NV50TCL_VP_ATTR_EN_1_15_XYZW 0xf0000000 +#define NV50TCL_VP_ATTR_EN_1_14_SHIFT 24 +#define NV50TCL_VP_ATTR_EN_1_14_MASK 0x0f000000 +#define NV50TCL_VP_ATTR_EN_1_14_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_1_14_XNNN 0x01000000 +#define NV50TCL_VP_ATTR_EN_1_14_NYNN 0x02000000 +#define NV50TCL_VP_ATTR_EN_1_14_XYNN 0x03000000 +#define NV50TCL_VP_ATTR_EN_1_14_NNZN 0x04000000 +#define NV50TCL_VP_ATTR_EN_1_14_XNZN 0x05000000 +#define NV50TCL_VP_ATTR_EN_1_14_NYZN 0x06000000 +#define NV50TCL_VP_ATTR_EN_1_14_XYZN 0x07000000 +#define NV50TCL_VP_ATTR_EN_1_14_NNNW 0x08000000 +#define NV50TCL_VP_ATTR_EN_1_14_XNNW 0x09000000 +#define NV50TCL_VP_ATTR_EN_1_14_NYNW 0x0a000000 +#define NV50TCL_VP_ATTR_EN_1_14_XYNW 0x0b000000 +#define NV50TCL_VP_ATTR_EN_1_14_NNZW 0x0c000000 +#define NV50TCL_VP_ATTR_EN_1_14_XNZW 0x0d000000 +#define NV50TCL_VP_ATTR_EN_1_14_NYZW 0x0e000000 +#define NV50TCL_VP_ATTR_EN_1_14_XYZW 0x0f000000 +#define NV50TCL_VP_ATTR_EN_1_13_SHIFT 20 +#define NV50TCL_VP_ATTR_EN_1_13_MASK 0x00f00000 +#define NV50TCL_VP_ATTR_EN_1_13_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_1_13_XNNN 0x00100000 +#define NV50TCL_VP_ATTR_EN_1_13_NYNN 0x00200000 +#define NV50TCL_VP_ATTR_EN_1_13_XYNN 0x00300000 +#define NV50TCL_VP_ATTR_EN_1_13_NNZN 0x00400000 +#define NV50TCL_VP_ATTR_EN_1_13_XNZN 0x00500000 +#define NV50TCL_VP_ATTR_EN_1_13_NYZN 0x00600000 +#define NV50TCL_VP_ATTR_EN_1_13_XYZN 0x00700000 +#define NV50TCL_VP_ATTR_EN_1_13_NNNW 0x00800000 +#define NV50TCL_VP_ATTR_EN_1_13_XNNW 0x00900000 +#define NV50TCL_VP_ATTR_EN_1_13_NYNW 0x00a00000 +#define NV50TCL_VP_ATTR_EN_1_13_XYNW 0x00b00000 +#define NV50TCL_VP_ATTR_EN_1_13_NNZW 0x00c00000 +#define NV50TCL_VP_ATTR_EN_1_13_XNZW 0x00d00000 +#define NV50TCL_VP_ATTR_EN_1_13_NYZW 0x00e00000 +#define NV50TCL_VP_ATTR_EN_1_13_XYZW 0x00f00000 +#define NV50TCL_VP_ATTR_EN_1_12_SHIFT 16 +#define NV50TCL_VP_ATTR_EN_1_12_MASK 0x000f0000 +#define NV50TCL_VP_ATTR_EN_1_12_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_1_12_XNNN 0x00010000 +#define NV50TCL_VP_ATTR_EN_1_12_NYNN 0x00020000 +#define NV50TCL_VP_ATTR_EN_1_12_XYNN 0x00030000 +#define NV50TCL_VP_ATTR_EN_1_12_NNZN 0x00040000 +#define NV50TCL_VP_ATTR_EN_1_12_XNZN 0x00050000 +#define NV50TCL_VP_ATTR_EN_1_12_NYZN 0x00060000 +#define NV50TCL_VP_ATTR_EN_1_12_XYZN 0x00070000 +#define NV50TCL_VP_ATTR_EN_1_12_NNNW 0x00080000 +#define NV50TCL_VP_ATTR_EN_1_12_XNNW 0x00090000 +#define NV50TCL_VP_ATTR_EN_1_12_NYNW 0x000a0000 +#define NV50TCL_VP_ATTR_EN_1_12_XYNW 0x000b0000 +#define NV50TCL_VP_ATTR_EN_1_12_NNZW 0x000c0000 +#define NV50TCL_VP_ATTR_EN_1_12_XNZW 0x000d0000 +#define NV50TCL_VP_ATTR_EN_1_12_NYZW 0x000e0000 +#define NV50TCL_VP_ATTR_EN_1_12_XYZW 0x000f0000 +#define NV50TCL_VP_ATTR_EN_1_11_SHIFT 12 +#define NV50TCL_VP_ATTR_EN_1_11_MASK 0x0000f000 +#define NV50TCL_VP_ATTR_EN_1_11_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_1_11_XNNN 0x00001000 +#define NV50TCL_VP_ATTR_EN_1_11_NYNN 0x00002000 +#define NV50TCL_VP_ATTR_EN_1_11_XYNN 0x00003000 +#define NV50TCL_VP_ATTR_EN_1_11_NNZN 0x00004000 +#define NV50TCL_VP_ATTR_EN_1_11_XNZN 0x00005000 +#define NV50TCL_VP_ATTR_EN_1_11_NYZN 0x00006000 +#define NV50TCL_VP_ATTR_EN_1_11_XYZN 0x00007000 +#define NV50TCL_VP_ATTR_EN_1_11_NNNW 0x00008000 +#define NV50TCL_VP_ATTR_EN_1_11_XNNW 0x00009000 +#define NV50TCL_VP_ATTR_EN_1_11_NYNW 0x0000a000 +#define NV50TCL_VP_ATTR_EN_1_11_XYNW 0x0000b000 +#define NV50TCL_VP_ATTR_EN_1_11_NNZW 0x0000c000 +#define NV50TCL_VP_ATTR_EN_1_11_XNZW 0x0000d000 +#define NV50TCL_VP_ATTR_EN_1_11_NYZW 0x0000e000 +#define NV50TCL_VP_ATTR_EN_1_11_XYZW 0x0000f000 +#define NV50TCL_VP_ATTR_EN_1_10_SHIFT 8 +#define NV50TCL_VP_ATTR_EN_1_10_MASK 0x00000f00 +#define NV50TCL_VP_ATTR_EN_1_10_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_1_10_XNNN 0x00000100 +#define NV50TCL_VP_ATTR_EN_1_10_NYNN 0x00000200 +#define NV50TCL_VP_ATTR_EN_1_10_XYNN 0x00000300 +#define NV50TCL_VP_ATTR_EN_1_10_NNZN 0x00000400 +#define NV50TCL_VP_ATTR_EN_1_10_XNZN 0x00000500 +#define NV50TCL_VP_ATTR_EN_1_10_NYZN 0x00000600 +#define NV50TCL_VP_ATTR_EN_1_10_XYZN 0x00000700 +#define NV50TCL_VP_ATTR_EN_1_10_NNNW 0x00000800 +#define NV50TCL_VP_ATTR_EN_1_10_XNNW 0x00000900 +#define NV50TCL_VP_ATTR_EN_1_10_NYNW 0x00000a00 +#define NV50TCL_VP_ATTR_EN_1_10_XYNW 0x00000b00 +#define NV50TCL_VP_ATTR_EN_1_10_NNZW 0x00000c00 +#define NV50TCL_VP_ATTR_EN_1_10_XNZW 0x00000d00 +#define NV50TCL_VP_ATTR_EN_1_10_NYZW 0x00000e00 +#define NV50TCL_VP_ATTR_EN_1_10_XYZW 0x00000f00 +#define NV50TCL_VP_ATTR_EN_1_9_SHIFT 4 +#define NV50TCL_VP_ATTR_EN_1_9_MASK 0x000000f0 +#define NV50TCL_VP_ATTR_EN_1_9_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_1_9_XNNN 0x00000010 +#define NV50TCL_VP_ATTR_EN_1_9_NYNN 0x00000020 +#define NV50TCL_VP_ATTR_EN_1_9_XYNN 0x00000030 +#define NV50TCL_VP_ATTR_EN_1_9_NNZN 0x00000040 +#define NV50TCL_VP_ATTR_EN_1_9_XNZN 0x00000050 +#define NV50TCL_VP_ATTR_EN_1_9_NYZN 0x00000060 +#define NV50TCL_VP_ATTR_EN_1_9_XYZN 0x00000070 +#define NV50TCL_VP_ATTR_EN_1_9_NNNW 0x00000080 +#define NV50TCL_VP_ATTR_EN_1_9_XNNW 0x00000090 +#define NV50TCL_VP_ATTR_EN_1_9_NYNW 0x000000a0 +#define NV50TCL_VP_ATTR_EN_1_9_XYNW 0x000000b0 +#define NV50TCL_VP_ATTR_EN_1_9_NNZW 0x000000c0 +#define NV50TCL_VP_ATTR_EN_1_9_XNZW 0x000000d0 +#define NV50TCL_VP_ATTR_EN_1_9_NYZW 0x000000e0 +#define NV50TCL_VP_ATTR_EN_1_9_XYZW 0x000000f0 +#define NV50TCL_VP_ATTR_EN_1_8_SHIFT 0 +#define NV50TCL_VP_ATTR_EN_1_8_MASK 0x0000000f +#define NV50TCL_VP_ATTR_EN_1_8_NONE 0x00000000 +#define NV50TCL_VP_ATTR_EN_1_8_XNNN 0x00000001 +#define NV50TCL_VP_ATTR_EN_1_8_NYNN 0x00000002 +#define NV50TCL_VP_ATTR_EN_1_8_XYNN 0x00000003 +#define NV50TCL_VP_ATTR_EN_1_8_NNZN 0x00000004 +#define NV50TCL_VP_ATTR_EN_1_8_XNZN 0x00000005 +#define NV50TCL_VP_ATTR_EN_1_8_NYZN 0x00000006 +#define NV50TCL_VP_ATTR_EN_1_8_XYZN 0x00000007 +#define NV50TCL_VP_ATTR_EN_1_8_NNNW 0x00000008 +#define NV50TCL_VP_ATTR_EN_1_8_XNNW 0x00000009 +#define NV50TCL_VP_ATTR_EN_1_8_NYNW 0x0000000a +#define NV50TCL_VP_ATTR_EN_1_8_XYNW 0x0000000b +#define NV50TCL_VP_ATTR_EN_1_8_NNZW 0x0000000c +#define NV50TCL_VP_ATTR_EN_1_8_XNZW 0x0000000d +#define NV50TCL_VP_ATTR_EN_1_8_NYZW 0x0000000e +#define NV50TCL_VP_ATTR_EN_1_8_XYZW 0x0000000f +#define NV50TCL_POINT_SPRITE_CTRL 0x00001660 +#define NV50TCL_LINE_STIPPLE_ENABLE 0x0000166c +#define NV50TCL_LINE_STIPPLE_PATTERN 0x00001680 +#define NV50TCL_PROVOKING_VERTEX_LAST 0x00001684 +#define NV50TCL_VERTEX_TWO_SIDE_ENABLE 0x00001688 +#define NV50TCL_POLYGON_STIPPLE_ENABLE 0x0000168c +#define NV50TCL_SET_PROGRAM_CB 0x00001694 +#define NV50TCL_SET_PROGRAM_CB_PROGRAM_SHIFT 4 +#define NV50TCL_SET_PROGRAM_CB_PROGRAM_MASK 0x000000f0 +#define NV50TCL_SET_PROGRAM_CB_PROGRAM_VERTEX 0x00000000 +#define NV50TCL_SET_PROGRAM_CB_PROGRAM_GEOMETRY 0x00000020 +#define NV50TCL_SET_PROGRAM_CB_PROGRAM_FRAGMENT 0x00000030 +#define NV50TCL_SET_PROGRAM_CB_INDEX_SHIFT 8 +#define NV50TCL_SET_PROGRAM_CB_INDEX_MASK 0x00000f00 +#define NV50TCL_SET_PROGRAM_CB_BUFFER_SHIFT 12 +#define NV50TCL_SET_PROGRAM_CB_BUFFER_MASK 0x0007f000 +#define NV50TCL_SET_PROGRAM_CB_VALID (1 << 0) +#define NV50TCL_VP_RESULT_MAP_SIZE 0x000016ac +#define NV50TCL_VP_REG_ALLOC_TEMP 0x000016b0 +#define NV50TCL_VP_REG_ALLOC_RESULT 0x000016b8 +#define NV50TCL_VP_RESULT_MAP(x) (0x000016bc+((x)*4)) +#define NV50TCL_VP_RESULT_MAP__SIZE 0x00000010 +#define NV50TCL_VP_RESULT_MAP_0_SHIFT 0 +#define NV50TCL_VP_RESULT_MAP_0_MASK 0x000000ff +#define NV50TCL_VP_RESULT_MAP_1_SHIFT 8 +#define NV50TCL_VP_RESULT_MAP_1_MASK 0x0000ff00 +#define NV50TCL_VP_RESULT_MAP_2_SHIFT 16 +#define NV50TCL_VP_RESULT_MAP_2_MASK 0x00ff0000 +#define NV50TCL_VP_RESULT_MAP_3_SHIFT 24 +#define NV50TCL_VP_RESULT_MAP_3_MASK 0xff000000 +#define NV50TCL_POLYGON_STIPPLE_PATTERN(x) (0x00001700+((x)*4)) +#define NV50TCL_POLYGON_STIPPLE_PATTERN__SIZE 0x00000020 +#define NV50TCL_GP_ENABLE 0x00001798 +#define NV50TCL_GP_REG_ALLOC_TEMP 0x000017a0 +#define NV50TCL_GP_REG_ALLOC_RESULT 0x000017a8 +#define NV50TCL_GP_RESULT_MAP_SIZE 0x000017ac +#define NV50TCL_GP_OUTPUT_PRIMITIVE_TYPE 0x000017b0 +#define NV50TCL_GP_OUTPUT_PRIMITIVE_TYPE_POINTS 0x00000001 +#define NV50TCL_GP_OUTPUT_PRIMITIVE_TYPE_LINE_STRIP 0x00000002 +#define NV50TCL_GP_OUTPUT_PRIMITIVE_TYPE_TRIANGLE_STRIP 0x00000003 +#define NV50TCL_RASTERIZE_ENABLE 0x000017b4 +#define NV50TCL_STRMOUT_ENABLE 0x000017b8 +#define NV50TCL_GP_RESULT_MAP(x) (0x000017fc+((x)*4)) +#define NV50TCL_GP_RESULT_MAP__SIZE 0x00000020 +#define NV50TCL_GP_RESULT_MAP_0_SHIFT 0 +#define NV50TCL_GP_RESULT_MAP_0_MASK 0x000000ff +#define NV50TCL_GP_RESULT_MAP_1_SHIFT 8 +#define NV50TCL_GP_RESULT_MAP_1_MASK 0x0000ff00 +#define NV50TCL_GP_RESULT_MAP_2_SHIFT 16 +#define NV50TCL_GP_RESULT_MAP_2_MASK 0x00ff0000 +#define NV50TCL_GP_RESULT_MAP_3_SHIFT 24 +#define NV50TCL_GP_RESULT_MAP_3_MASK 0xff000000 +#define NV50TCL_MAP_SEMANTIC_0 0x00001904 +#define NV50TCL_MAP_SEMANTIC_0_FFC0_ID_SHIFT 0 +#define NV50TCL_MAP_SEMANTIC_0_FFC0_ID_MASK 0x000000ff +#define NV50TCL_MAP_SEMANTIC_0_BFC0_ID_SHIFT 8 +#define NV50TCL_MAP_SEMANTIC_0_BFC0_ID_MASK 0x0000ff00 +#define NV50TCL_MAP_SEMANTIC_0_COLR_NR_SHIFT 16 +#define NV50TCL_MAP_SEMANTIC_0_COLR_NR_MASK 0x00ff0000 +#define NV50TCL_MAP_SEMANTIC_0_CLMP_EN_SHIFT 24 +#define NV50TCL_MAP_SEMANTIC_0_CLMP_EN_MASK 0xff000000 +#define NV50TCL_MAP_SEMANTIC_1 0x00001908 +#define NV50TCL_MAP_SEMANTIC_1_CLIP_LO_SHIFT 0 +#define NV50TCL_MAP_SEMANTIC_1_CLIP_LO_MASK 0x000000ff +#define NV50TCL_MAP_SEMANTIC_1_CLIP_HI_SHIFT 8 +#define NV50TCL_MAP_SEMANTIC_1_CLIP_HI_MASK 0x0000ff00 +#define NV50TCL_MAP_SEMANTIC_2 0x0000190c +#define NV50TCL_MAP_SEMANTIC_2_LAYER_ID_SHIFT 0 +#define NV50TCL_MAP_SEMANTIC_2_LAYER_ID_MASK 0x000000ff +#define NV50TCL_MAP_SEMANTIC_3 0x00001910 +#define NV50TCL_MAP_SEMANTIC_3_PTSZ_EN (1 << 0) +#define NV50TCL_MAP_SEMANTIC_3_PTSZ_ID_SHIFT 4 +#define NV50TCL_MAP_SEMANTIC_3_PTSZ_ID_MASK 0x00000ff0 +#define NV50TCL_MAP_SEMANTIC_4 0x00001914 +#define NV50TCL_MAP_SEMANTIC_4_PRIM_ID_SHIFT 0 +#define NV50TCL_MAP_SEMANTIC_4_PRIM_ID_MASK 0x000000ff +#define NV50TCL_CULL_FACE_ENABLE 0x00001918 +#define NV50TCL_FRONT_FACE 0x0000191c +#define NV50TCL_FRONT_FACE_CW 0x00000900 +#define NV50TCL_FRONT_FACE_CCW 0x00000901 +#define NV50TCL_CULL_FACE 0x00001920 +#define NV50TCL_CULL_FACE_FRONT 0x00000404 +#define NV50TCL_CULL_FACE_BACK 0x00000405 +#define NV50TCL_CULL_FACE_FRONT_AND_BACK 0x00000408 +#define NV50TCL_VIEWPORT_TRANSFORM_EN 0x0000192c +#define NV50TCL_VIEW_VOLUME_CLIP_CTRL 0x0000193c +#define NV50TCL_VIEWPORT_CLIP_RECTS_EN 0x0000194c +#define NV50TCL_VIEWPORT_CLIP_MODE 0x00001950 +#define NV50TCL_VIEWPORT_CLIP_MODE_INCLUDE 0x00000000 +#define NV50TCL_VIEWPORT_CLIP_MODE_EXCLUDE 0x00000001 +#define NV50TCL_VIEWPORT_CLIP_MODE_UNKNOWN 0x00000002 +#define NV50TCL_FP_CTRL_UNK196C 0x0000196c +#define NV50TCL_CLIPID_ENABLE 0x0000197c +#define NV50TCL_CLIPID_WIDTH 0x00001980 +#define NV50TCL_CLIPID_ID 0x00001984 +#define NV50TCL_FP_INTERPOLANT_CTRL 0x00001988 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_SHIFT 24 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_MASK 0xff000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_NONE 0x00000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_XNNN 0x01000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_NYNN 0x02000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_XYNN 0x03000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_NNZN 0x04000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_XNZN 0x05000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_NYZN 0x06000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_XYZN 0x07000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_NNNW 0x08000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_XNNW 0x09000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_NYNW 0x0a000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_XYNW 0x0b000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_NNZW 0x0c000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_XNZW 0x0d000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_NYZW 0x0e000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_UMASK_XYZW 0x0f000000 +#define NV50TCL_FP_INTERPOLANT_CTRL_COUNT_NONFLAT_SHIFT 16 +#define NV50TCL_FP_INTERPOLANT_CTRL_COUNT_NONFLAT_MASK 0x00ff0000 +#define NV50TCL_FP_INTERPOLANT_CTRL_OFFSET_SHIFT 8 +#define NV50TCL_FP_INTERPOLANT_CTRL_OFFSET_MASK 0x0000ff00 +#define NV50TCL_FP_INTERPOLANT_CTRL_COUNT_SHIFT 0 +#define NV50TCL_FP_INTERPOLANT_CTRL_COUNT_MASK 0x000000ff +#define NV50TCL_FP_REG_ALLOC_TEMP 0x0000198c +#define NV50TCL_REG_MODE 0x000019a0 +#define NV50TCL_REG_MODE_PACKED 0x00000001 +#define NV50TCL_REG_MODE_STRIPED 0x00000002 +#define NV50TCL_FP_CONTROL 0x000019a8 +#define NV50TCL_FP_CONTROL_MULTIPLE_RESULTS (1 << 0) +#define NV50TCL_FP_CONTROL_EXPORTS_Z (1 << 8) +#define NV50TCL_FP_CONTROL_USES_KIL (1 << 20) +#define NV50TCL_DEPTH_BOUNDS_EN 0x000019bc +#define NV50TCL_LOGIC_OP_ENABLE 0x000019c4 +#define NV50TCL_LOGIC_OP 0x000019c8 +#define NV50TCL_LOGIC_OP_CLEAR 0x00001500 +#define NV50TCL_LOGIC_OP_AND 0x00001501 +#define NV50TCL_LOGIC_OP_AND_REVERSE 0x00001502 +#define NV50TCL_LOGIC_OP_COPY 0x00001503 +#define NV50TCL_LOGIC_OP_AND_INVERTED 0x00001504 +#define NV50TCL_LOGIC_OP_NOOP 0x00001505 +#define NV50TCL_LOGIC_OP_XOR 0x00001506 +#define NV50TCL_LOGIC_OP_OR 0x00001507 +#define NV50TCL_LOGIC_OP_NOR 0x00001508 +#define NV50TCL_LOGIC_OP_EQUIV 0x00001509 +#define NV50TCL_LOGIC_OP_INVERT 0x0000150a +#define NV50TCL_LOGIC_OP_OR_REVERSE 0x0000150b +#define NV50TCL_LOGIC_OP_COPY_INVERTED 0x0000150c +#define NV50TCL_LOGIC_OP_OR_INVERTED 0x0000150d +#define NV50TCL_LOGIC_OP_NAND 0x0000150e +#define NV50TCL_LOGIC_OP_SET 0x0000150f +#define NV50TCL_CLEAR_BUFFERS 0x000019d0 +#define NV50TCL_CLEAR_BUFFERS_Z (1 << 0) +#define NV50TCL_CLEAR_BUFFERS_S (1 << 1) +#define NV50TCL_CLEAR_BUFFERS_R (1 << 2) +#define NV50TCL_CLEAR_BUFFERS_G (1 << 3) +#define NV50TCL_CLEAR_BUFFERS_B (1 << 4) +#define NV50TCL_CLEAR_BUFFERS_A (1 << 5) +#define NV50TCL_CLEAR_BUFFERS_RT_SHIFT 6 +#define NV50TCL_CLEAR_BUFFERS_RT_MASK 0x000003c0 +#define NV50TCL_CLEAR_BUFFERS_LAYER_SHIFT 10 +#define NV50TCL_CLEAR_BUFFERS_LAYER_MASK 0x0007fc00 +#define NV50TCL_COLOR_MASK(x) (0x00001a00+((x)*4)) +#define NV50TCL_COLOR_MASK__SIZE 0x00000008 +#define NV50TCL_COLOR_MASK_R_SHIFT 0 +#define NV50TCL_COLOR_MASK_R_MASK 0x0000000f +#define NV50TCL_COLOR_MASK_G_SHIFT 4 +#define NV50TCL_COLOR_MASK_G_MASK 0x000000f0 +#define NV50TCL_COLOR_MASK_B_SHIFT 8 +#define NV50TCL_COLOR_MASK_B_MASK 0x00000f00 +#define NV50TCL_COLOR_MASK_A_SHIFT 12 +#define NV50TCL_COLOR_MASK_A_MASK 0x0000f000 +#define NV50TCL_STRMOUT_ADDRESS_HIGH(x) (0x00001a80+((x)*16)) +#define NV50TCL_STRMOUT_ADDRESS_HIGH__SIZE 0x00000004 +#define NV50TCL_STRMOUT_ADDRESS_LOW(x) (0x00001a84+((x)*16)) +#define NV50TCL_STRMOUT_ADDRESS_LOW__SIZE 0x00000004 +#define NV50TCL_STRMOUT_NUM_ATTRIBS(x) (0x00001a88+((x)*16)) +#define NV50TCL_STRMOUT_NUM_ATTRIBS__SIZE 0x00000004 +#define NV50TCL_VERTEX_ARRAY_ATTRIB(x) (0x00001ac0+((x)*4)) +#define NV50TCL_VERTEX_ARRAY_ATTRIB__SIZE 0x00000010 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_BUFFER_SHIFT 0 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_BUFFER_MASK 0x0000000f +#define NV50TCL_VERTEX_ARRAY_ATTRIB_CONST (1 << 4) +#define NV50TCL_VERTEX_ARRAY_ATTRIB_OFFSET_SHIFT 5 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_OFFSET_MASK 0x0007ffe0 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_SHIFT 19 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_MASK 0x01f80000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_32_32_32_32 0x00080000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_32_32_32 0x00100000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_16_16_16_16 0x00180000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_32_32 0x00200000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_16_16_16 0x00280000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_8_8_8_8 0x00500000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_16_16 0x00780000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_32 0x00900000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_8_8_8 0x00980000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_8_8 0x00c00000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_16 0x00d80000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_8 0x00e80000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_2_10_10_10 0x01800000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_SHIFT 25 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_MASK 0x0e000000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_FLOAT 0x0e000000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_SNORM 0x02000000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_UNORM 0x04000000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_USCALED 0x0a000000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_SSCALED 0x0c000000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_UINT 0x08000000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_SINT 0x06000000 +#define NV50TCL_VERTEX_ARRAY_ATTRIB_BGRA (1 << 31) +#define NV50TCL_QUERY_ADDRESS_HIGH 0x00001b00 +#define NV50TCL_QUERY_ADDRESS_LOW 0x00001b04 +#define NV50TCL_QUERY_SEQUENCE 0x00001b08 +#define NV50TCL_QUERY_GET 0x00001b0c + + +#define NV84TCL 0x00008297 + + + +#define NVA0TCL 0x00008397 + + + +#define NVA8TCL 0x00008597 + + + +#define NV50_COMPUTE 0x000050c0 + +#define NV50_COMPUTE_NOP 0x00000100 +#define NV50_COMPUTE_NOTIFY 0x00000104 +#define NV50_COMPUTE_SERIALIZE 0x00000110 +#define NV50_COMPUTE_DMA_NOTIFY 0x00000180 +#define NV50_COMPUTE_DMA_GLOBAL 0x000001a0 +#define NV50_COMPUTE_DMA_QUERY 0x000001a4 +#define NV50_COMPUTE_DMA_LOCAL 0x000001b8 +#define NV50_COMPUTE_DMA_STACK 0x000001bc +#define NV50_COMPUTE_DMA_CODE_CB 0x000001c0 +#define NV50_COMPUTE_DMA_TSC 0x000001c4 +#define NV50_COMPUTE_DMA_TIC 0x000001c8 +#define NV50_COMPUTE_DMA_TEXTURE 0x000001cc +#define NV50_COMPUTE_CP_ADDRESS_HIGH 0x00000210 +#define NV50_COMPUTE_CP_ADDRESS_LOW 0x00000214 +#define NV50_COMPUTE_STACK_ADDRESS_HIGH 0x00000218 +#define NV50_COMPUTE_STACK_ADDRESS_LOW 0x0000021c +#define NV50_COMPUTE_STACK_SIZE_LOG 0x00000220 +#define NV50_COMPUTE_TSC_ADDRESS_HIGH 0x0000022c +#define NV50_COMPUTE_TSC_ADDRESS_LOW 0x00000230 +#define NV50_COMPUTE_TSC_LIMIT 0x00000234 +#define NV50_COMPUTE_CB_ADDR 0x00000238 +#define NV50_COMPUTE_CB_ADDR_ID_SHIFT 8 +#define NV50_COMPUTE_CB_ADDR_ID_MASK 0x003fff00 +#define NV50_COMPUTE_CB_ADDR_BUFFER_SHIFT 0 +#define NV50_COMPUTE_CB_ADDR_BUFFER_MASK 0x0000007f +#define NV50_COMPUTE_CB_DATA(x) (0x0000023c+((x)*4)) +#define NV50_COMPUTE_CB_DATA__SIZE 0x00000010 +#define NV50_COMPUTE_DELAY1 0x00000284 +#define NV50_COMPUTE_WATCHDOG_TIMER 0x00000288 +#define NV50_COMPUTE_DELAY2 0x0000028c +#define NV50_COMPUTE_LOCAL_ADDRESS_HIGH 0x00000294 +#define NV50_COMPUTE_LOCAL_ADDRESS_LOW 0x00000298 +#define NV50_COMPUTE_LOCAL_SIZE_LOG 0x0000029c +#define NV50_COMPUTE_CB_DEF_ADDRESS_HIGH 0x000002a4 +#define NV50_COMPUTE_CB_DEF_ADDRESS_LOW 0x000002a8 +#define NV50_COMPUTE_CB_DEF_SET 0x000002ac +#define NV50_COMPUTE_CB_DEF_SET_SIZE_SHIFT 0 +#define NV50_COMPUTE_CB_DEF_SET_SIZE_MASK 0x0000ffff +#define NV50_COMPUTE_CB_DEF_SET_BUFFER_SHIFT 16 +#define NV50_COMPUTE_CB_DEF_SET_BUFFER_MASK 0x007f0000 +#define NV50_COMPUTE_BLOCK_ALLOC 0x000002b4 +#define NV50_COMPUTE_BLOCK_ALLOC_THREADS_SHIFT 0 +#define NV50_COMPUTE_BLOCK_ALLOC_THREADS_MASK 0x0000ffff +#define NV50_COMPUTE_BLOCK_ALLOC_BARRIERS_SHIFT 16 +#define NV50_COMPUTE_BLOCK_ALLOC_BARRIERS_MASK 0xffff0000 +#define NV50_COMPUTE_LANES32_ENABLE 0x000002b8 +#define NV50_COMPUTE_CP_REG_ALLOC_TEMP 0x000002c0 +#define NV50_COMPUTE_TIC_ADDRESS_HIGH 0x000002c4 +#define NV50_COMPUTE_TIC_ADDRESS_LOW 0x000002c8 +#define NV50_COMPUTE_TIC_LIMIT 0x000002cc +#define NV50_COMPUTE_PM_SET(x) (0x000002d0+((x)*4)) +#define NV50_COMPUTE_PM_SET__SIZE 0x00000004 +#define NV50_COMPUTE_PM_CONTROL(x) (0x000002e0+((x)*4)) +#define NV50_COMPUTE_PM_CONTROL__SIZE 0x00000004 +#define NV50_COMPUTE_PM_CONTROL_UNK0 (1 << 0) +#define NV50_COMPUTE_PM_CONTROL_UNK1_SHIFT 4 +#define NV50_COMPUTE_PM_CONTROL_UNK1_MASK 0x00000070 +#define NV50_COMPUTE_PM_CONTROL_UNK2_SHIFT 8 +#define NV50_COMPUTE_PM_CONTROL_UNK2_MASK 0xffffff00 +#define NV50_COMPUTE_LOCAL_WARPS_LOG_ALLOC 0x000002fc +#define NV50_COMPUTE_LOCAL_WARPS_NO_CLAMP 0x00000300 +#define NV50_COMPUTE_STACK_WARPS_LOG_ALLOC 0x00000304 +#define NV50_COMPUTE_STACK_WARPS_NO_CLAMP 0x00000308 +#define NV50_COMPUTE_QUERY_ADDRESS_HIGH 0x00000310 +#define NV50_COMPUTE_QUERY_ADDRESS_LOW 0x00000314 +#define NV50_COMPUTE_QUERY_COUNTER 0x00000318 +#define NV50_COMPUTE_QUERY_GET 0x0000031c +#define NV50_COMPUTE_COND_ADDRESS_HIGH 0x00000320 +#define NV50_COMPUTE_COND_ADDRESS_LOW 0x00000324 +#define NV50_COMPUTE_COND_MODE 0x00000328 +#define NV50_COMPUTE_COND_MODE_NEVER 0x00000000 +#define NV50_COMPUTE_COND_MODE_ALWAYS 0x00000001 +#define NV50_COMPUTE_COND_MODE_RES 0x00000002 +#define NV50_COMPUTE_COND_MODE_NOT_RES_AND_NOT_ID 0x00000003 +#define NV50_COMPUTE_COND_MODE_RES_OR_ID 0x00000004 +#define NV50_COMPUTE_LAUNCH 0x00000368 +#define NV50_COMPUTE_USER_PARAM_COUNT 0x00000374 +#define NV50_COMPUTE_USER_PARAM_COUNT_COUNT_SHIFT 8 +#define NV50_COMPUTE_USER_PARAM_COUNT_COUNT_MASK 0x0000ff00 +#define NV50_COMPUTE_LINKED_TSC 0x00000378 +#define NV50_COMPUTE_CODE_CB_FLUSH 0x00000380 +#define NV50_COMPUTE_GRIDDIM 0x000003a4 +#define NV50_COMPUTE_GRIDDIM_X_SHIFT 0 +#define NV50_COMPUTE_GRIDDIM_X_MASK 0x0000ffff +#define NV50_COMPUTE_GRIDDIM_Y_SHIFT 16 +#define NV50_COMPUTE_GRIDDIM_Y_MASK 0xffff0000 +#define NV50_COMPUTE_SHARED_SIZE 0x000003a8 +#define NV50_COMPUTE_BLOCKDIM_YX 0x000003ac +#define NV50_COMPUTE_BLOCKDIM_YX_X_SHIFT 0 +#define NV50_COMPUTE_BLOCKDIM_YX_X_MASK 0x0000ffff +#define NV50_COMPUTE_BLOCKDIM_YX_Y_SHIFT 16 +#define NV50_COMPUTE_BLOCKDIM_YX_Y_MASK 0xffff0000 +#define NV50_COMPUTE_BLOCKDIM_Z 0x000003b0 +#define NV50_COMPUTE_CP_START_ID 0x000003b4 +#define NV50_COMPUTE_REG_MODE 0x000003b8 +#define NV50_COMPUTE_REG_MODE_PACKED 0x00000001 +#define NV50_COMPUTE_REG_MODE_STRIPED 0x00000002 +#define NV50_COMPUTE_TEX_LIMITS 0x000003bc +#define NV50_COMPUTE_TEX_LIMITS_SAMPLERS_LOG2_SHIFT 0 +#define NV50_COMPUTE_TEX_LIMITS_SAMPLERS_LOG2_MASK 0x0000000f +#define NV50_COMPUTE_TEX_LIMITS_TEXTURES_LOG2_SHIFT 4 +#define NV50_COMPUTE_TEX_LIMITS_TEXTURES_LOG2_MASK 0x000000f0 +#define NV50_COMPUTE_BIND_TSC 0x000003c0 +#define NV50_COMPUTE_BIND_TSC_VALID (1 << 0) +#define NV50_COMPUTE_BIND_TSC_SAMPLER_SHIFT 4 +#define NV50_COMPUTE_BIND_TSC_SAMPLER_MASK 0x000000f0 +#define NV50_COMPUTE_BIND_TSC_TSC_SHIFT 12 +#define NV50_COMPUTE_BIND_TSC_TSC_MASK 0x001ff000 +#define NV50_COMPUTE_BIND_TIC 0x000003c4 +#define NV50_COMPUTE_BIND_TIC_VALID (1 << 0) +#define NV50_COMPUTE_BIND_TIC_TEXTURE_SHIFT 1 +#define NV50_COMPUTE_BIND_TIC_TEXTURE_MASK 0x000001fe +#define NV50_COMPUTE_BIND_TIC_TIC_SHIFT 9 +#define NV50_COMPUTE_BIND_TIC_TIC_MASK 0x7ffffe00 +#define NV50_COMPUTE_SET_PROGRAM_CB 0x000003c8 +#define NV50_COMPUTE_SET_PROGRAM_CB_INDEX_SHIFT 8 +#define NV50_COMPUTE_SET_PROGRAM_CB_INDEX_MASK 0x00000f00 +#define NV50_COMPUTE_SET_PROGRAM_CB_BUFFER_SHIFT 12 +#define NV50_COMPUTE_SET_PROGRAM_CB_BUFFER_MASK 0x0007f000 +#define NV50_COMPUTE_SET_PROGRAM_CB_VALID (1 << 0) +#define NV50_COMPUTE_GLOBAL_ADDRESS_HIGH(x) (0x00000400+((x)*32)) +#define NV50_COMPUTE_GLOBAL_ADDRESS_HIGH__SIZE 0x00000010 +#define NV50_COMPUTE_GLOBAL_ADDRESS_LOW(x) (0x00000404+((x)*32)) +#define NV50_COMPUTE_GLOBAL_ADDRESS_LOW__SIZE 0x00000010 +#define NV50_COMPUTE_GLOBAL_PITCH(x) (0x00000408+((x)*32)) +#define NV50_COMPUTE_GLOBAL_PITCH__SIZE 0x00000010 +#define NV50_COMPUTE_GLOBAL_LIMIT(x) (0x0000040c+((x)*32)) +#define NV50_COMPUTE_GLOBAL_LIMIT__SIZE 0x00000010 +#define NV50_COMPUTE_GLOBAL_MODE(x) (0x00000410+((x)*32)) +#define NV50_COMPUTE_GLOBAL_MODE__SIZE 0x00000010 +#define NV50_COMPUTE_GLOBAL_MODE_LINEAR (1 << 0) +#define NV50_COMPUTE_GLOBAL_MODE_TILE_MODE_SHIFT 8 +#define NV50_COMPUTE_GLOBAL_MODE_TILE_MODE_MASK 0x00000f00 +#define NV50_COMPUTE_USER_PARAM(x) (0x00000600+((x)*4)) +#define NV50_COMPUTE_USER_PARAM__SIZE 0x00000040 + + +#endif /* NOUVEAU_REG_H */ diff --git a/src/gallium/drivers/nv50/nv50_resource.c b/src/gallium/drivers/nv50/nv50_resource.c new file mode 100644 index 0000000..6c0a969 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_resource.c @@ -0,0 +1,67 @@ + +#include "pipe/p_context.h" +#include "nv50_resource.h" +#include "nouveau/nouveau_screen.h" + + +/* This doesn't look quite right - this query is supposed to ask + * whether the particular context has references to the resource in + * any unflushed rendering command buffer, and hence requires a + * pipe->flush() for serializing some modification to that resource. + * + * This seems to be answering the question of whether the resource is + * currently on hardware. + */ +static unsigned int +nv50_resource_is_referenced(struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, int layer) +{ + return nouveau_reference_flags(nv50_resource(resource)->bo); +} + +static struct pipe_resource * +nv50_resource_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + if (template->target == PIPE_BUFFER) + return nv50_buffer_create(screen, template); + else + return nv50_miptree_create(screen, template); +} + +static struct pipe_resource * +nv50_resource_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle) +{ + if (template->target == PIPE_BUFFER) + return NULL; + else + return nv50_miptree_from_handle(screen, template, whandle); +} + +void +nv50_init_resource_functions(struct pipe_context *pcontext) +{ + pcontext->get_transfer = u_get_transfer_vtbl; + pcontext->transfer_map = u_transfer_map_vtbl; + pcontext->transfer_flush_region = u_transfer_flush_region_vtbl; + pcontext->transfer_unmap = u_transfer_unmap_vtbl; + pcontext->transfer_destroy = u_transfer_destroy_vtbl; + pcontext->transfer_inline_write = u_transfer_inline_write_vtbl; + pcontext->is_resource_referenced = nv50_resource_is_referenced; + + pcontext->create_surface = nv50_miptree_surface_new; + pcontext->surface_destroy = nv50_miptree_surface_del; +} + +void +nv50_screen_init_resource_functions(struct pipe_screen *pscreen) +{ + pscreen->resource_create = nv50_resource_create; + pscreen->resource_from_handle = nv50_resource_from_handle; + pscreen->resource_get_handle = u_resource_get_handle_vtbl; + pscreen->resource_destroy = u_resource_destroy_vtbl; + pscreen->user_buffer_create = nv50_user_buffer_create; +} diff --git a/src/gallium/drivers/nv50/nv50_resource.h b/src/gallium/drivers/nv50/nv50_resource.h new file mode 100644 index 0000000..4b2a75e --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_resource.h @@ -0,0 +1,97 @@ + +#ifndef NV50_RESOURCE_H +#define NV50_RESOURCE_H + +#include "util/u_transfer.h" + +#include "nouveau/nouveau_winsys.h" + +struct pipe_resource; +struct nouveau_bo; + + +/* This gets further specialized into either buffer or texture + * structures. In the future we'll want to remove much of that + * distinction, but for now try to keep as close to the existing code + * as possible and use the vtbl struct to choose between the two + * underlying implementations. + */ +struct nv50_resource { + struct pipe_resource base; + const struct u_resource_vtbl *vtbl; + struct nouveau_bo *bo; +}; + +struct nv50_miptree_level { + int *image_offset; + unsigned pitch; + unsigned tile_mode; +}; + +#define NV50_MAX_TEXTURE_LEVELS 16 + +struct nv50_miptree { + struct nv50_resource base; + + struct nv50_miptree_level level[NV50_MAX_TEXTURE_LEVELS]; + int image_nr; + int total_size; +}; + +static INLINE struct nv50_miptree * +nv50_miptree(struct pipe_resource *pt) +{ + return (struct nv50_miptree *)pt; +} + + +static INLINE +struct nv50_resource *nv50_resource(struct pipe_resource *resource) +{ + return (struct nv50_resource *)resource; +} + +/* is resource mapped into the GPU's address space (i.e. VRAM or GART) ? */ +static INLINE boolean +nv50_resource_mapped_by_gpu(struct pipe_resource *resource) +{ + return nv50_resource(resource)->bo->handle; +} + +void +nv50_init_resource_functions(struct pipe_context *pcontext); + +void +nv50_screen_init_resource_functions(struct pipe_screen *pscreen); + +/* Internal functions + */ +struct pipe_resource * +nv50_miptree_create(struct pipe_screen *pscreen, + const struct pipe_resource *tmp); + +struct pipe_resource * +nv50_miptree_from_handle(struct pipe_screen *pscreen, + const struct pipe_resource *template, + struct winsys_handle *whandle); + +struct pipe_resource * +nv50_buffer_create(struct pipe_screen *pscreen, + const struct pipe_resource *template); + +struct pipe_resource * +nv50_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage); + + +struct pipe_surface * +nv50_miptree_surface_new(struct pipe_context *pipe, struct pipe_resource *pt, + const struct pipe_surface *surf_tmpl); + +void +nv50_miptree_surface_del(struct pipe_context *pipe, struct pipe_surface *ps); + + +#endif diff --git a/src/gallium/drivers/nv50/nv50_screen.c b/src/gallium/drivers/nv50/nv50_screen.c new file mode 100644 index 0000000..edc3d54 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_screen.c @@ -0,0 +1,620 @@ +/* + * Copyright 2008 Ben Skeggs + * + * 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 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_format_s3tc.h" +#include "pipe/p_screen.h" + +#include "nv50_context.h" +#include "nv50_screen.h" +#include "nv50_resource.h" +#include "nv50_program.h" + +#include "nouveau/nouveau_stateobj.h" + +static boolean +nv50_screen_is_format_supported(struct pipe_screen *pscreen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned usage, unsigned geom_flags) +{ + if (sample_count > 1) + return FALSE; + + if (!util_format_s3tc_enabled) { + switch (format) { + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + case PIPE_FORMAT_DXT3_RGBA: + case PIPE_FORMAT_DXT5_RGBA: + return FALSE; + default: + break; + } + } + + switch (format) { + case PIPE_FORMAT_Z16_UNORM: + if ((nouveau_screen(pscreen)->device->chipset & 0xf0) != 0xa0) + return FALSE; + break; + default: + break; + } + + /* transfers & shared are always supported */ + usage &= ~(PIPE_BIND_TRANSFER_READ | + PIPE_BIND_TRANSFER_WRITE | + PIPE_BIND_SHARED); + + return (nv50_format_table[format].usage & usage) == usage; +} + +static int +nv50_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param) +{ + switch (param) { + case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: + return 32; + case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS: + return 32; + case PIPE_CAP_MAX_COMBINED_SAMPLERS: + return 64; + case PIPE_CAP_NPOT_TEXTURES: + return 1; + case PIPE_CAP_TWO_SIDED_STENCIL: + return 1; + case PIPE_CAP_GLSL: + case PIPE_CAP_SM3: + return 1; + case PIPE_CAP_ANISOTROPIC_FILTER: + return 1; + case PIPE_CAP_POINT_SPRITE: + return 1; + case PIPE_CAP_MAX_RENDER_TARGETS: + return 8; + case PIPE_CAP_OCCLUSION_QUERY: + return 1; + case PIPE_CAP_TIMER_QUERY: + return 0; + case PIPE_CAP_STREAM_OUTPUT: + return 0; + case PIPE_CAP_TEXTURE_SHADOW_MAP: + return 1; + case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: + return 13; + case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: + return 10; + case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: + return 13; + case PIPE_CAP_TEXTURE_MIRROR_CLAMP: + case PIPE_CAP_TEXTURE_MIRROR_REPEAT: + return 1; + case PIPE_CAP_TEXTURE_SWIZZLE: + return 1; + case PIPE_CAP_BLEND_EQUATION_SEPARATE: + return 1; + case PIPE_CAP_INDEP_BLEND_ENABLE: + return 1; + case PIPE_CAP_INDEP_BLEND_FUNC: + return 0; + case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: + return 1; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: + return 1; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: + return 0; + case PIPE_CAP_DEPTH_CLAMP: + return 1; + case PIPE_CAP_SHADER_STENCIL_EXPORT: + return 0; + case PIPE_CAP_PRIMITIVE_RESTART: + return 0; + default: + NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param); + return 0; + } +} + +static int +nv50_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader, + enum pipe_shader_cap param) +{ + switch(shader) { + case PIPE_SHADER_FRAGMENT: + case PIPE_SHADER_VERTEX: + break; + case PIPE_SHADER_GEOMETRY: + default: + return 0; + } + + switch(param) { + case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: /* arbitrary limit */ + return 16384; + case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: /* need stack bo */ + return 4; + case PIPE_SHADER_CAP_MAX_INPUTS: /* 128 / 4 with GP */ + if (shader == PIPE_SHADER_GEOMETRY) + return 128 / 4; + else + return 64 / 4; + case PIPE_SHADER_CAP_MAX_CONSTS: + return 65536 / 16; + case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: /* 16 - 1, but not implemented */ + return 1; + case PIPE_SHADER_CAP_MAX_ADDRS: /* no spilling atm */ + return 1; + case PIPE_SHADER_CAP_MAX_PREDS: /* not yet handled */ + return 0; + case PIPE_SHADER_CAP_MAX_TEMPS: /* no spilling atm */ + return NV50_CAP_MAX_PROGRAM_TEMPS; + case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: + return 1; + case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: + case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: + return 1; + case PIPE_SHADER_CAP_SUBROUTINES: + return 0; + default: + return 0; + } +} + +static float +nv50_screen_get_paramf(struct pipe_screen *pscreen, enum pipe_cap param) +{ + switch (param) { + case PIPE_CAP_MAX_LINE_WIDTH: + case PIPE_CAP_MAX_LINE_WIDTH_AA: + return 10.0; + case PIPE_CAP_MAX_POINT_WIDTH: + case PIPE_CAP_MAX_POINT_WIDTH_AA: + return 64.0; + case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: + return 16.0; + case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: + return 4.0; + default: + NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param); + return 0.0; + } +} + +static void +nv50_screen_destroy(struct pipe_screen *pscreen) +{ + struct nv50_screen *screen = nv50_screen(pscreen); + unsigned i; + + for (i = 0; i < 3; i++) { + if (screen->constbuf_parm[i]) + nouveau_bo_ref(NULL, &screen->constbuf_parm[i]); + } + + if (screen->constbuf_misc[0]) + nouveau_bo_ref(NULL, &screen->constbuf_misc[0]); + if (screen->tic) + nouveau_bo_ref(NULL, &screen->tic); + if (screen->tsc) + nouveau_bo_ref(NULL, &screen->tsc); + + nouveau_notifier_free(&screen->sync); + nouveau_grobj_free(&screen->tesla); + nouveau_grobj_free(&screen->eng2d); + nouveau_grobj_free(&screen->m2mf); + nouveau_resource_destroy(&screen->immd_heap); + nouveau_screen_fini(&screen->base); + FREE(screen); +} + +#define BGN_RELOC(ch, bo, gr, m, n, fl) \ + OUT_RELOC(ch, bo, (n << 18) | (gr->subc << 13) | m, fl, 0, 0) + +void +nv50_screen_reloc_constbuf(struct nv50_screen *screen, unsigned cbi) +{ + struct nouveau_bo *bo; + struct nouveau_channel *chan = screen->base.channel; + struct nouveau_grobj *tesla = screen->tesla; + unsigned size; + const unsigned rl = NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_DUMMY; + + switch (cbi) { + case NV50_CB_PMISC: + bo = screen->constbuf_misc[0]; + size = 0x200; + break; + case NV50_CB_PVP: + case NV50_CB_PFP: + case NV50_CB_PGP: + bo = screen->constbuf_parm[cbi - NV50_CB_PVP]; + size = 0; + break; + default: + return; + } + + BGN_RELOC (chan, bo, tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3, rl); + OUT_RELOCh(chan, bo, 0, rl); + OUT_RELOCl(chan, bo, 0, rl); + OUT_RELOC (chan, bo, (cbi << 16) | size, rl, 0, 0); +} + +void +nv50_screen_relocs(struct nv50_screen *screen) +{ + struct nouveau_channel *chan = screen->base.channel; + struct nouveau_grobj *tesla = screen->tesla; + unsigned i; + const unsigned rl = NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_DUMMY; + + MARK_RING (chan, 28, 26); + + /* cause grobj autobind */ + BEGIN_RING(chan, tesla, 0x0100, 1); + OUT_RING (chan, 0); + + BGN_RELOC (chan, screen->tic, tesla, NV50TCL_TIC_ADDRESS_HIGH, 2, rl); + OUT_RELOCh(chan, screen->tic, 0, rl); + OUT_RELOCl(chan, screen->tic, 0, rl); + + BGN_RELOC (chan, screen->tsc, tesla, NV50TCL_TSC_ADDRESS_HIGH, 2, rl); + OUT_RELOCh(chan, screen->tsc, 0, rl); + OUT_RELOCl(chan, screen->tsc, 0, rl); + + nv50_screen_reloc_constbuf(screen, NV50_CB_PMISC); + + BGN_RELOC (chan, screen->constbuf_misc[0], + tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3, rl); + OUT_RELOCh(chan, screen->constbuf_misc[0], 0x200, rl); + OUT_RELOCl(chan, screen->constbuf_misc[0], 0x200, rl); + OUT_RELOC (chan, screen->constbuf_misc[0], + (NV50_CB_AUX << 16) | 0x0200, rl, 0, 0); + + for (i = 0; i < 3; ++i) + nv50_screen_reloc_constbuf(screen, NV50_CB_PVP + i); + + BGN_RELOC (chan, screen->stack_bo, + tesla, NV50TCL_STACK_ADDRESS_HIGH, 2, rl); + OUT_RELOCh(chan, screen->stack_bo, 0, rl); + OUT_RELOCl(chan, screen->stack_bo, 0, rl); + + if (!screen->cur_ctx->req_lmem) + return; + + BGN_RELOC (chan, screen->local_bo, + tesla, NV50TCL_LOCAL_ADDRESS_HIGH, 2, rl); + OUT_RELOCh(chan, screen->local_bo, 0, rl); + OUT_RELOCl(chan, screen->local_bo, 0, rl); +} + +#ifndef NOUVEAU_GETPARAM_GRAPH_UNITS +# define NOUVEAU_GETPARAM_GRAPH_UNITS 13 +#endif + +extern int nouveau_device_get_param(struct nouveau_device *dev, + uint64_t param, uint64_t *value); + +struct pipe_screen * +nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) +{ + struct nv50_screen *screen = CALLOC_STRUCT(nv50_screen); + struct nouveau_channel *chan; + struct pipe_screen *pscreen; + uint64_t value; + unsigned chipset = dev->chipset; + unsigned tesla_class = 0; + unsigned stack_size, local_size, max_warps; + int ret, i; + const unsigned rl = NOUVEAU_BO_VRAM | NOUVEAU_BO_RD; + + if (!screen) + return NULL; + pscreen = &screen->base.base; + + ret = nouveau_screen_init(&screen->base, dev); + if (ret) { + nv50_screen_destroy(pscreen); + return NULL; + } + chan = screen->base.channel; + + pscreen->winsys = ws; + pscreen->destroy = nv50_screen_destroy; + pscreen->get_param = nv50_screen_get_param; + pscreen->get_shader_param = nv50_screen_get_shader_param; + pscreen->get_paramf = nv50_screen_get_paramf; + pscreen->is_format_supported = nv50_screen_is_format_supported; + pscreen->context_create = nv50_create; + + nv50_screen_init_resource_functions(pscreen); + + /* DMA engine object */ + ret = nouveau_grobj_alloc(chan, 0xbeef5039, + NV50_MEMORY_TO_MEMORY_FORMAT, &screen->m2mf); + if (ret) { + NOUVEAU_ERR("Error creating M2MF object: %d\n", ret); + nv50_screen_destroy(pscreen); + return NULL; + } + + /* 2D object */ + ret = nouveau_grobj_alloc(chan, 0xbeef502d, NV50_2D, &screen->eng2d); + if (ret) { + NOUVEAU_ERR("Error creating 2D object: %d\n", ret); + nv50_screen_destroy(pscreen); + return NULL; + } + + /* 3D object */ + switch (chipset & 0xf0) { + case 0x50: + tesla_class = NV50TCL; + break; + case 0x80: + case 0x90: + tesla_class = NV84TCL; + break; + case 0xa0: + switch (chipset) { + case 0xa0: + case 0xaa: + case 0xac: + tesla_class = NVA0TCL; + break; + default: + tesla_class = NVA8TCL; + break; + } + break; + default: + NOUVEAU_ERR("Not a known NV50 chipset: NV%02x\n", chipset); + nv50_screen_destroy(pscreen); + return NULL; + } + + ret = nouveau_grobj_alloc(chan, 0xbeef5097, tesla_class, + &screen->tesla); + if (ret) { + NOUVEAU_ERR("Error creating 3D object: %d\n", ret); + nv50_screen_destroy(pscreen); + return NULL; + } + + /* this is necessary for the new RING_3D / statebuffer code */ + BIND_RING(chan, screen->tesla, 7); + + /* Sync notifier */ + ret = nouveau_notifier_alloc(chan, 0xbeef0301, 1, &screen->sync); + if (ret) { + NOUVEAU_ERR("Error creating notifier object: %d\n", ret); + nv50_screen_destroy(pscreen); + return NULL; + } + + /* Static M2MF init */ + BEGIN_RING(chan, screen->m2mf, + NV04_MEMORY_TO_MEMORY_FORMAT_DMA_NOTIFY, 3); + OUT_RING (chan, screen->sync->handle); + OUT_RING (chan, chan->vram->handle); + OUT_RING (chan, chan->vram->handle); + + /* Static 2D init */ + BEGIN_RING(chan, screen->eng2d, NV50_2D_DMA_NOTIFY, 4); + OUT_RING (chan, screen->sync->handle); + OUT_RING (chan, chan->vram->handle); + OUT_RING (chan, chan->vram->handle); + OUT_RING (chan, chan->vram->handle); + BEGIN_RING(chan, screen->eng2d, NV50_2D_OPERATION, 1); + OUT_RING (chan, NV50_2D_OPERATION_SRCCOPY); + BEGIN_RING(chan, screen->eng2d, NV50_2D_CLIP_ENABLE, 1); + OUT_RING (chan, 0); + BEGIN_RING(chan, screen->eng2d, 0x0888, 1); + OUT_RING (chan, 1); + + /* Static tesla init */ + BEGIN_RING(chan, screen->tesla, NV50TCL_COND_MODE, 1); + OUT_RING (chan, NV50TCL_COND_MODE_ALWAYS); + BEGIN_RING(chan, screen->tesla, NV50TCL_DMA_NOTIFY, 1); + OUT_RING (chan, screen->sync->handle); + BEGIN_RING(chan, screen->tesla, NV50TCL_DMA_ZETA, 11); + for (i = 0; i < 11; i++) + OUT_RING (chan, chan->vram->handle); + BEGIN_RING(chan, screen->tesla, + NV50TCL_DMA_COLOR(0), NV50TCL_DMA_COLOR__SIZE); + for (i = 0; i < NV50TCL_DMA_COLOR__SIZE; i++) + OUT_RING (chan, chan->vram->handle); + + BEGIN_RING(chan, screen->tesla, NV50TCL_RT_CONTROL, 1); + OUT_RING (chan, 1); + + /* activate all 32 lanes (threads) in a warp */ + BEGIN_RING(chan, screen->tesla, NV50TCL_REG_MODE, 1); + OUT_RING (chan, NV50TCL_REG_MODE_STRIPED); + BEGIN_RING(chan, screen->tesla, 0x1400, 1); + OUT_RING (chan, 0xf); + + /* max TIC (bits 4:8) & TSC (ignored) bindings, per program type */ + for (i = 0; i < 3; ++i) { + BEGIN_RING(chan, screen->tesla, NV50TCL_TEX_LIMITS(i), 1); + OUT_RING (chan, 0x54); + } + + /* origin is top left (set to 1 for bottom left) */ + BEGIN_RING(chan, screen->tesla, NV50TCL_Y_ORIGIN_BOTTOM, 1); + OUT_RING (chan, 0); + BEGIN_RING(chan, screen->tesla, NV50TCL_VP_REG_ALLOC_RESULT, 1); + OUT_RING (chan, 8); + + BEGIN_RING(chan, screen->tesla, NV50TCL_CLEAR_FLAGS, 1); + OUT_RING (chan, NV50TCL_CLEAR_FLAGS_D3D); + + /* constant buffers for immediates and VP/FP parameters */ + ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, (32 * 4) * 4, + &screen->constbuf_misc[0]); + if (ret) { + nv50_screen_destroy(pscreen); + return NULL; + } + BEGIN_RING(chan, screen->tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3); + OUT_RELOCh(chan, screen->constbuf_misc[0], 0, rl); + OUT_RELOCl(chan, screen->constbuf_misc[0], 0, rl); + OUT_RING (chan, (NV50_CB_PMISC << 16) | 0x0200); + BEGIN_RING(chan, screen->tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3); + OUT_RELOCh(chan, screen->constbuf_misc[0], 0x200, rl); + OUT_RELOCl(chan, screen->constbuf_misc[0], 0x200, rl); + OUT_RING (chan, (NV50_CB_AUX << 16) | 0x0200); + + for (i = 0; i < 3; i++) { + ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, (4096 * 4) * 4, + &screen->constbuf_parm[i]); + if (ret) { + nv50_screen_destroy(pscreen); + return NULL; + } + BEGIN_RING(chan, screen->tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3); + OUT_RELOCh(chan, screen->constbuf_parm[i], 0, rl); + OUT_RELOCl(chan, screen->constbuf_parm[i], 0, rl); + /* CB_DEF_SET_SIZE value of 0x0000 means 65536 */ + OUT_RING (chan, ((NV50_CB_PVP + i) << 16) | 0x0000); + } + + if (nouveau_resource_init(&screen->immd_heap, 0, 128)) { + NOUVEAU_ERR("Error initialising shader immediates heap.\n"); + nv50_screen_destroy(pscreen); + return NULL; + } + + ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, 3 * 32 * (8 * 4), + &screen->tic); + if (ret) { + nv50_screen_destroy(pscreen); + return NULL; + } + BEGIN_RING(chan, screen->tesla, NV50TCL_TIC_ADDRESS_HIGH, 3); + OUT_RELOCh(chan, screen->tic, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RELOCl(chan, screen->tic, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RING (chan, 3 * 32 - 1); + + ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, 3 * 32 * (8 * 4), + &screen->tsc); + if (ret) { + nv50_screen_destroy(pscreen); + return NULL; + } + BEGIN_RING(chan, screen->tesla, NV50TCL_TSC_ADDRESS_HIGH, 3); + OUT_RELOCh(chan, screen->tsc, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RELOCl(chan, screen->tsc, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RING (chan, 0); /* ignored if TSC_LINKED (0x1234) == 1 */ + + /* map constant buffers: + * B = buffer ID (maybe more than 1 byte) + * N = CB index used in shader instruction + * P = program type (0 = VP, 2 = GP, 3 = FP) + * SET_PROGRAM_CB = 0x000BBNP1 + */ + BEGIN_RING_NI(chan, screen->tesla, NV50TCL_SET_PROGRAM_CB, 8); + /* bind immediate buffer */ + OUT_RING (chan, 0x001 | (NV50_CB_PMISC << 12)); + OUT_RING (chan, 0x021 | (NV50_CB_PMISC << 12)); + OUT_RING (chan, 0x031 | (NV50_CB_PMISC << 12)); + /* bind auxiliary constbuf to immediate data bo */ + OUT_RING (chan, 0x201 | (NV50_CB_AUX << 12)); + OUT_RING (chan, 0x221 | (NV50_CB_AUX << 12)); + /* bind parameter buffers */ + OUT_RING (chan, 0x101 | (NV50_CB_PVP << 12)); + OUT_RING (chan, 0x121 | (NV50_CB_PGP << 12)); + OUT_RING (chan, 0x131 | (NV50_CB_PFP << 12)); + + /* shader stack */ + nouveau_device_get_param(dev, NOUVEAU_GETPARAM_GRAPH_UNITS, &value); + + max_warps = util_bitcount(value & 0xffff); + max_warps *= util_bitcount((value >> 24) & 0xf) * 32; + + stack_size = max_warps * 64 * 8; + + ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, + stack_size, &screen->stack_bo); + if (ret) { + nv50_screen_destroy(pscreen); + return NULL; + } + BEGIN_RING(chan, screen->tesla, NV50TCL_STACK_ADDRESS_HIGH, 3); + OUT_RELOCh(chan, screen->stack_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCl(chan, screen->stack_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RING (chan, 4); + + local_size = (NV50_CAP_MAX_PROGRAM_TEMPS * 16) * max_warps * 32; + + ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, + local_size, &screen->local_bo); + if (ret) { + nv50_screen_destroy(pscreen); + return NULL; + } + + local_size = NV50_CAP_MAX_PROGRAM_TEMPS * 16; + + BEGIN_RING(chan, screen->tesla, NV50TCL_LOCAL_ADDRESS_HIGH, 3); + OUT_RELOCh(chan, screen->local_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCl(chan, screen->local_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RING (chan, util_unsigned_logbase2(local_size / 8)); + + /* Vertex array limits - max them out */ + for (i = 0; i < 16; i++) { + BEGIN_RING(chan, screen->tesla, + NV50TCL_VERTEX_ARRAY_LIMIT_HIGH(i), 2); + OUT_RING (chan, 0x000000ff); + OUT_RING (chan, 0xffffffff); + } + + BEGIN_RING(chan, screen->tesla, NV50TCL_DEPTH_RANGE_NEAR(0), 2); + OUT_RINGf (chan, 0.0f); + OUT_RINGf (chan, 1.0f); + + BEGIN_RING(chan, screen->tesla, NV50TCL_VIEWPORT_TRANSFORM_EN, 1); + OUT_RING (chan, 1); + + /* no dynamic combination of TIC & TSC entries => only BIND_TIC used */ + BEGIN_RING(chan, screen->tesla, NV50TCL_LINKED_TSC, 1); + OUT_RING (chan, 1); + + BEGIN_RING(chan, screen->tesla, NV50TCL_EDGEFLAG_ENABLE, 1); + OUT_RING (chan, 1); /* default edgeflag to TRUE */ + + FIRE_RING (chan); + + screen->force_push = debug_get_bool_option("NV50_ALWAYS_PUSH", FALSE); + if(!screen->force_push) + screen->base.vertex_buffer_flags = screen->base.index_buffer_flags = NOUVEAU_BO_GART; + return pscreen; +} + diff --git a/src/gallium/drivers/nv50/nv50_screen.h b/src/gallium/drivers/nv50/nv50_screen.h new file mode 100644 index 0000000..6e15230 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_screen.h @@ -0,0 +1,53 @@ +#ifndef __NV50_SCREEN_H__ +#define __NV50_SCREEN_H__ + +#include "nouveau/nouveau_screen.h" + +struct nv50_context; + +struct nv50_screen { + struct nouveau_screen base; + + struct nouveau_winsys *nvws; + + struct nv50_context *cur_ctx; + + struct nouveau_grobj *tesla; + struct nouveau_grobj *eng2d; + struct nouveau_grobj *m2mf; + struct nouveau_notifier *sync; + + struct nouveau_bo *constbuf_misc[1]; + struct nouveau_bo *constbuf_parm[PIPE_SHADER_TYPES]; + + struct nouveau_resource *immd_heap; + + struct nouveau_bo *tic; + struct nouveau_bo *tsc; + + struct nouveau_bo *stack_bo; /* control flow stack */ + struct nouveau_bo *local_bo; /* l[] memory */ + + boolean force_push; +}; + +static INLINE struct nv50_screen * +nv50_screen(struct pipe_screen *screen) +{ + return (struct nv50_screen *)screen; +} + +extern void nv50_screen_relocs(struct nv50_screen *); + +extern void nv50_screen_reloc_constbuf(struct nv50_screen *, unsigned cbi); + +struct nv50_format { + uint32_t rt; + uint32_t tic; + uint32_t vtx; + uint32_t usage; +}; + +extern const struct nv50_format nv50_format_table[]; + +#endif diff --git a/src/gallium/drivers/nv50/nv50_shader_state.c b/src/gallium/drivers/nv50/nv50_shader_state.c new file mode 100644 index 0000000..306aa81 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_shader_state.c @@ -0,0 +1,658 @@ +/* + * Copyright 2008 Ben Skeggs + * Copyright 2010 Christoph Bumiller + * + * 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 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_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" + +#include "nv50_context.h" + +static void +nv50_transfer_constbuf(struct nv50_context *nv50, + struct pipe_resource *buf, unsigned size, unsigned cbi) +{ + struct pipe_context *pipe = &nv50->pipe; + struct pipe_transfer *transfer; + struct nouveau_channel *chan = nv50->screen->base.channel; + struct nouveau_grobj *tesla = nv50->screen->tesla; + uint32_t *map; + unsigned count, start; + + if (buf == NULL) + return; + + map = pipe_buffer_map(pipe, buf, PIPE_TRANSFER_READ, &transfer); + if (!map) + return; + + count = (buf->width0 + 3) / 4; + start = 0; + + while (count) { + unsigned nr = AVAIL_RING(chan); + + if (nr < 8) { + FIRE_RING(chan); + continue; + } + nr = MIN2(count, nr - 7); + nr = MIN2(nr, NV04_PFIFO_MAX_PACKET_LEN); + + nv50_screen_reloc_constbuf(nv50->screen, cbi); + + BEGIN_RING(chan, tesla, NV50TCL_CB_ADDR, 1); + OUT_RING (chan, (start << 8) | cbi); + BEGIN_RING_NI(chan, tesla, NV50TCL_CB_DATA(0), nr); + OUT_RINGp (chan, map, nr); + + count -= nr; + start += nr; + map += nr; + } + + pipe_buffer_unmap(pipe, buf, transfer); +} + +static void +nv50_program_validate_data(struct nv50_context *nv50, struct nv50_program *p) +{ + struct nouveau_channel *chan = nv50->screen->base.channel; + struct nouveau_grobj *tesla = nv50->screen->tesla; + unsigned cbi; + + if (p->immd_size) { + uint32_t *data = p->immd; + unsigned count = p->immd_size / 4; + unsigned start = 0; + + while (count) { + unsigned nr = AVAIL_RING(chan); + + if (nr < 8) { + FIRE_RING(chan); + continue; + } + nr = MIN2(count, nr - 7); + nr = MIN2(nr, NV04_PFIFO_MAX_PACKET_LEN); + + nv50_screen_reloc_constbuf(nv50->screen, NV50_CB_PMISC); + + BEGIN_RING(chan, tesla, NV50TCL_CB_ADDR, 1); + OUT_RING (chan, (start << 8) | NV50_CB_PMISC); + BEGIN_RING_NI(chan, tesla, NV50TCL_CB_DATA(0), nr); + OUT_RINGp (chan, data, nr); + + count -= nr; + start += nr; + data += nr; + } + } + + /* If the state tracker doesn't change the constbuf, and it is first + * validated with a program that doesn't use it, this check prevents + * it from even being uploaded. */ + /* + if (p->parm_size == 0) + return; + */ + + switch (p->type) { + case PIPE_SHADER_VERTEX: + cbi = NV50_CB_PVP; + break; + case PIPE_SHADER_FRAGMENT: + cbi = NV50_CB_PFP; + break; + case PIPE_SHADER_GEOMETRY: + cbi = NV50_CB_PGP; + break; + default: + assert(0); + return; + } + + nv50_transfer_constbuf(nv50, nv50->constbuf[p->type], p->parm_size, cbi); +} + +static void +nv50_program_validate_code(struct nv50_context *nv50, struct nv50_program *p) +{ + struct nouveau_channel *chan = nv50->screen->base.channel; + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_grobj *eng2d = nv50->screen->eng2d; + int ret; + unsigned offset; + unsigned size = p->code_size; + uint32_t *data = p->code; + + assert(p->translated); + + /* TODO: use a single bo (for each type) for shader code */ + if (p->bo) + return; + ret = nouveau_bo_new(chan->device, NOUVEAU_BO_VRAM, 0x100, size, &p->bo); + assert(!ret); + + offset = p->code_start = 0; + + BEGIN_RING(chan, eng2d, NV50_2D_DST_FORMAT, 2); + OUT_RING (chan, NV50_2D_DST_FORMAT_R8_UNORM); + OUT_RING (chan, 1); + BEGIN_RING(chan, eng2d, NV50_2D_DST_PITCH, 1); + OUT_RING (chan, 0x40000); + BEGIN_RING(chan, eng2d, NV50_2D_DST_WIDTH, 2); + OUT_RING (chan, 0x10000); + OUT_RING (chan, 1); + + while (size) { + unsigned nr = size / 4; + + if (AVAIL_RING(chan) < 32) + FIRE_RING(chan); + + nr = MIN2(nr, AVAIL_RING(chan) - 18); + nr = MIN2(nr, 1792); + if (nr < (size / 4)) + nr &= ~0x3f; + assert(!(size & 3)); + + BEGIN_RING(chan, eng2d, NV50_2D_DST_ADDRESS_HIGH, 2); + OUT_RELOCh(chan, p->bo, offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCl(chan, p->bo, offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + BEGIN_RING(chan, eng2d, NV50_2D_SIFC_BITMAP_ENABLE, 2); + OUT_RING (chan, 0); + OUT_RING (chan, NV50_2D_SIFC_FORMAT_R8_UNORM); + BEGIN_RING(chan, eng2d, NV50_2D_SIFC_WIDTH, 10); + OUT_RING (chan, nr * 4); + OUT_RING (chan, 1); + OUT_RING (chan, 0); + OUT_RING (chan, 1); + OUT_RING (chan, 0); + OUT_RING (chan, 1); + OUT_RING (chan, 0); + OUT_RING (chan, 0); + OUT_RING (chan, 0); + OUT_RING (chan, 0); + + BEGIN_RING_NI(chan, eng2d, NV50_2D_SIFC_DATA, nr); + OUT_RINGp (chan, data, nr); + + data += nr; + offset += nr * 4; + size -= nr * 4; + } + + BEGIN_RING(chan, tesla, NV50TCL_CODE_CB_FLUSH, 1); + OUT_RING (chan, 0); +} + +static void +nv50_vp_update_stateobj(struct nv50_context *nv50, struct nv50_program *p) +{ + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_stateobj *so = so_new(5, 7, 2); + + nv50_program_validate_code(nv50, p); + + so_method(so, tesla, NV50TCL_VP_ADDRESS_HIGH, 2); + so_reloc (so, p->bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | + NOUVEAU_BO_HIGH, 0, 0); + so_reloc (so, p->bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | + NOUVEAU_BO_LOW, 0, 0); + so_method(so, tesla, NV50TCL_VP_ATTR_EN_0, 2); + so_data (so, p->vp.attrs[0]); + so_data (so, p->vp.attrs[1]); + so_method(so, tesla, NV50TCL_VP_REG_ALLOC_RESULT, 1); + so_data (so, p->max_out); + so_method(so, tesla, NV50TCL_VP_REG_ALLOC_TEMP, 1); + so_data (so, p->max_gpr); + so_method(so, tesla, NV50TCL_VP_START_ID, 1); + so_data (so, p->code_start); + + so_ref(so, &p->so); + so_ref(NULL, &so); +} + +static void +nv50_fp_update_stateobj(struct nv50_context *nv50, struct nv50_program *p) +{ + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_stateobj *so = so_new(6, 7, 2); + + nv50_program_validate_code(nv50, p); + + so_method(so, tesla, NV50TCL_FP_ADDRESS_HIGH, 2); + so_reloc (so, p->bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | + NOUVEAU_BO_HIGH, 0, 0); + so_reloc (so, p->bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | + NOUVEAU_BO_LOW, 0, 0); + so_method(so, tesla, NV50TCL_FP_REG_ALLOC_TEMP, 1); + so_data (so, p->max_gpr); + so_method(so, tesla, NV50TCL_FP_RESULT_COUNT, 1); + so_data (so, p->max_out); + so_method(so, tesla, NV50TCL_FP_CONTROL, 1); + so_data (so, p->fp.flags[0]); + so_method(so, tesla, NV50TCL_FP_CTRL_UNK196C, 1); + so_data (so, p->fp.flags[1]); + so_method(so, tesla, NV50TCL_FP_START_ID, 1); + so_data (so, p->code_start); + + so_ref(so, &p->so); + so_ref(NULL, &so); +} + +static void +nv50_gp_update_stateobj(struct nv50_context *nv50, struct nv50_program *p) +{ + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_stateobj *so = so_new(6, 7, 2); + + nv50_program_validate_code(nv50, p); + + so_method(so, tesla, NV50TCL_GP_ADDRESS_HIGH, 2); + so_reloc (so, p->bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | + NOUVEAU_BO_HIGH, 0, 0); + so_reloc (so, p->bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | + NOUVEAU_BO_LOW, 0, 0); + so_method(so, tesla, NV50TCL_GP_REG_ALLOC_TEMP, 1); + so_data (so, p->max_gpr); + so_method(so, tesla, NV50TCL_GP_REG_ALLOC_RESULT, 1); + so_data (so, p->max_out); + so_method(so, tesla, NV50TCL_GP_OUTPUT_PRIMITIVE_TYPE, 1); + so_data (so, p->gp.prim_type); + so_method(so, tesla, NV50TCL_GP_VERTEX_OUTPUT_COUNT, 1); + so_data (so, p->gp.vert_count); + so_method(so, tesla, NV50TCL_GP_START_ID, 1); + so_data (so, p->code_start); + + so_ref(so, &p->so); + so_ref(NULL, &so); +} + +static boolean +nv50_program_validate(struct nv50_program *p) +{ + p->translated = nv50_program_tx(p); + assert(p->translated); + return p->translated; +} + +static INLINE void +nv50_program_validate_common(struct nv50_context *nv50, struct nv50_program *p) +{ + nv50_program_validate_code(nv50, p); + + if (p->uses_lmem) + nv50->req_lmem |= 1 << p->type; + else + nv50->req_lmem &= ~(1 << p->type); +} + +struct nouveau_stateobj * +nv50_vertprog_validate(struct nv50_context *nv50) +{ + struct nv50_program *p = nv50->vertprog; + struct nouveau_stateobj *so = NULL; + + if (!p->translated) { + if (nv50_program_validate(p)) + nv50_vp_update_stateobj(nv50, p); + else + return NULL; + } + + if (nv50->dirty & NV50_NEW_VERTPROG_CB) + nv50_program_validate_data(nv50, p); + + if (!(nv50->dirty & NV50_NEW_VERTPROG)) + return NULL; + + nv50_program_validate_common(nv50, p); + + so_ref(p->so, &so); + return so; +} + +struct nouveau_stateobj * +nv50_fragprog_validate(struct nv50_context *nv50) +{ + struct nv50_program *p = nv50->fragprog; + struct nouveau_stateobj *so = NULL; + + if (!p->translated) { + if (nv50_program_validate(p)) + nv50_fp_update_stateobj(nv50, p); + else + return NULL; + } + + if (nv50->dirty & NV50_NEW_FRAGPROG_CB) + nv50_program_validate_data(nv50, p); + + if (!(nv50->dirty & NV50_NEW_FRAGPROG)) + return NULL; + + nv50_program_validate_common(nv50, p); + + so_ref(p->so, &so); + return so; +} + +struct nouveau_stateobj * +nv50_geomprog_validate(struct nv50_context *nv50) +{ + struct nv50_program *p = nv50->geomprog; + struct nouveau_stateobj *so = NULL; + + /* GP may be NULL, but VP and FP may not */ + if (!p) + return NULL; /* GP is deactivated in linkage validation */ + + if (!p->translated) { + if (nv50_program_validate(p)) + nv50_gp_update_stateobj(nv50, p); + else + return NULL; + } + + if (nv50->dirty & NV50_NEW_GEOMPROG_CB) + nv50_program_validate_data(nv50, p); + + if (!(nv50->dirty & NV50_NEW_GEOMPROG)) + return NULL; + + nv50_program_validate_common(nv50, p); + + so_ref(p->so, &so); + return so; +} + +/* XXX: this might not work correctly in all cases yet: we assume that + * an FP generic input that is not written in the VP is gl_PointCoord. + */ +static uint32_t +nv50_pntc_replace(struct nv50_context *nv50, uint32_t pntc[8], unsigned m) +{ + struct nv50_program *vp = nv50->vertprog; + struct nv50_program *fp = nv50->fragprog; + unsigned i, c; + + memset(pntc, 0, 8 * sizeof(uint32_t)); + + if (nv50->geomprog) + vp = nv50->geomprog; + + for (i = 0; i < fp->in_nr; i++) { + unsigned j, n = util_bitcount(fp->in[i].mask); + + if (fp->in[i].sn != TGSI_SEMANTIC_GENERIC) { + m += n; + continue; + } + + for (j = 0; j < vp->out_nr; ++j) + if (vp->out[j].sn == fp->in[i].sn && vp->out[j].si == fp->in[i].si) + break; + + if (j < vp->out_nr) { + uint32_t en = nv50->rasterizer->pipe.sprite_coord_enable; + + if (!(en & (1 << vp->out[j].si))) { + m += n; + continue; + } + } + + /* this is either PointCoord or replaced by sprite coords */ + for (c = 0; c < 4; c++) { + if (!(fp->in[i].mask & (1 << c))) + continue; + pntc[m / 8] |= (c + 1) << ((m % 8) * 4); + ++m; + } + } + if (nv50->rasterizer->pipe.sprite_coord_mode == PIPE_SPRITE_COORD_LOWER_LEFT) + return 0; + return (1 << 4); +} + +static int +nv50_vec4_map(uint32_t *map32, int mid, uint32_t lin[4], + struct nv50_varying *in, struct nv50_varying *out) +{ + int c; + uint8_t mv = out->mask, mf = in->mask, oid = out->hw; + uint8_t *map = (uint8_t *)map32; + + for (c = 0; c < 4; ++c) { + if (mf & 1) { + if (in->linear) + lin[mid / 32] |= 1 << (mid % 32); + if (mv & 1) + map[mid] = oid; + else + if (c == 3) + map[mid] |= 1; + ++mid; + } + + oid += mv & 1; + mf >>= 1; + mv >>= 1; + } + + return mid; +} + +struct nouveau_stateobj * +nv50_fp_linkage_validate(struct nv50_context *nv50) +{ + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nv50_program *vp; + struct nv50_program *fp = nv50->fragprog; + struct nouveau_stateobj *so; + struct nv50_varying dummy; + int i, n, c, m; + + uint32_t map[16], lin[4], pntc[8]; + + uint32_t interp = fp->fp.interp; + uint32_t colors = fp->fp.colors; + uint32_t clip = 0x04; + uint32_t psiz = 0x000; + uint32_t primid = 0; + uint32_t sysval = 0; + + if (nv50->geomprog) { + vp = nv50->geomprog; + memset(map, 0x80, sizeof(map)); + } else { + vp = nv50->vertprog; + memset(map, 0x40, sizeof(map)); + } + memset(lin, 0, sizeof(lin)); + + dummy.linear = 0; + dummy.mask = 0xf; /* map all components of HPOS */ + m = nv50_vec4_map(map, 0, lin, &dummy, &vp->out[0]); + + if (vp->vp.clpd < 0x40) { + for (c = 0; c < vp->vp.clpd_nr; ++c) { + map[m / 4] |= (vp->vp.clpd + c) << ((m % 4) * 8); + ++m; + } + clip |= vp->vp.clpd_nr << 8; + } + + colors |= m << 8; /* adjust BFC0 id */ + + /* if light_twoside is active, it seems FFC0_ID == BFC0_ID is bad */ + if (nv50->rasterizer->pipe.light_twoside) { + for (i = 0; i < 2; ++i) + m = nv50_vec4_map(map, m, lin, + &fp->in[fp->vp.bfc[i]], + &vp->out[vp->vp.bfc[i]]); + } + + colors += m - 4; /* adjust FFC0 id */ + interp |= m << 8; /* set mid where 'normal' FP inputs start */ + + dummy.mask = 0x0; + for (i = 0; i < fp->in_nr; i++) { + for (n = 0; n < vp->out_nr; ++n) + if (vp->out[n].sn == fp->in[i].sn && + vp->out[n].si == fp->in[i].si) + break; + + m = nv50_vec4_map(map, m, lin, + &fp->in[i], (n < vp->out_nr) ? &vp->out[n] : &dummy); + } + + /* PrimitiveID either is replaced by the system value, or + * written by the geometry shader into an output register + */ + if (fp->gp.primid < 0x40) { + i = (m % 4) * 8; + map[m / 4] = (map[m / 4] & ~(0xff << i)) | (vp->gp.primid << i); + primid = m++; + } + + if (nv50->rasterizer->pipe.point_size_per_vertex) { + i = (m % 4) * 8; + map[m / 4] = (map[m / 4] & ~(0xff << i)) | (vp->vp.psiz << i); + psiz = (m++ << 4) | 1; + } + + /* now fill the stateobj (at most 28 so_data) */ + so = so_new(10, 54, 0); + + n = (m + 3) / 4; + assert(m <= 64); + if (vp->type == PIPE_SHADER_GEOMETRY) { + so_method(so, tesla, NV50TCL_GP_RESULT_MAP_SIZE, 1); + so_data (so, m); + so_method(so, tesla, NV50TCL_GP_RESULT_MAP(0), n); + so_datap (so, map, n); + } else { + so_method(so, tesla, NV50TCL_VP_GP_BUILTIN_ATTR_EN, 1); + so_data (so, vp->vp.attrs[2]); + + so_method(so, tesla, NV50TCL_MAP_SEMANTIC_4, 1); + so_data (so, primid); + + so_method(so, tesla, NV50TCL_VP_RESULT_MAP_SIZE, 1); + so_data (so, m); + so_method(so, tesla, NV50TCL_VP_RESULT_MAP(0), n); + so_datap (so, map, n); + } + + so_method(so, tesla, NV50TCL_MAP_SEMANTIC_0, 4); + so_data (so, colors); + so_data (so, clip); + so_data (so, sysval); + so_data (so, psiz); + + so_method(so, tesla, NV50TCL_FP_INTERPOLANT_CTRL, 1); + so_data (so, interp); + + so_method(so, tesla, NV50TCL_NOPERSPECTIVE_BITMAP(0), 4); + so_datap (so, lin, 4); + + if (nv50->rasterizer->pipe.point_quad_rasterization) { + so_method(so, tesla, NV50TCL_POINT_SPRITE_CTRL, 1); + so_data (so, + nv50_pntc_replace(nv50, pntc, (interp >> 8) & 0xff)); + + so_method(so, tesla, NV50TCL_POINT_COORD_REPLACE_MAP(0), 8); + so_datap (so, pntc, 8); + } + + so_method(so, tesla, NV50TCL_GP_ENABLE, 1); + so_data (so, (vp->type == PIPE_SHADER_GEOMETRY) ? 1 : 0); + + return so; +} + +static int +nv50_vp_gp_mapping(uint32_t *map32, int m, + struct nv50_program *vp, struct nv50_program *gp) +{ + uint8_t *map = (uint8_t *)map32; + int i, j, c; + + for (i = 0; i < gp->in_nr; ++i) { + uint8_t oid = 0, mv = 0, mg = gp->in[i].mask; + + for (j = 0; j < vp->out_nr; ++j) { + if (vp->out[j].sn == gp->in[i].sn && + vp->out[j].si == gp->in[i].si) { + mv = vp->out[j].mask; + oid = vp->out[j].hw; + break; + } + } + + for (c = 0; c < 4; ++c, mv >>= 1, mg >>= 1) { + if (mg & mv & 1) + map[m++] = oid; + else + if (mg & 1) + map[m++] = (c == 3) ? 0x41 : 0x40; + oid += mv & 1; + } + } + return m; +} + +struct nouveau_stateobj * +nv50_gp_linkage_validate(struct nv50_context *nv50) +{ + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_stateobj *so; + struct nv50_program *vp = nv50->vertprog; + struct nv50_program *gp = nv50->geomprog; + uint32_t map[16]; + int m = 0; + + if (!gp) + return NULL; + memset(map, 0, sizeof(map)); + + m = nv50_vp_gp_mapping(map, m, vp, gp); + + so = so_new(3, 24 - 3, 0); + + so_method(so, tesla, NV50TCL_VP_GP_BUILTIN_ATTR_EN, 1); + so_data (so, vp->vp.attrs[2] | gp->vp.attrs[2]); + + assert(m <= 32); + so_method(so, tesla, NV50TCL_VP_RESULT_MAP_SIZE, 1); + so_data (so, m); + + m = (m + 3) / 4; + so_method(so, tesla, NV50TCL_VP_RESULT_MAP(0), m); + so_datap (so, map, m); + + return so; +} diff --git a/src/gallium/drivers/nv50/nv50_state.c b/src/gallium/drivers/nv50/nv50_state.c new file mode 100644 index 0000000..f42fa2d --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_state.c @@ -0,0 +1,890 @@ +/* + * Copyright 2008 Ben Skeggs + * + * 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 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_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" + +#include "tgsi/tgsi_parse.h" + +#include "nv50_context.h" +#include "nv50_texture.h" + +#include "nouveau/nouveau_stateobj.h" + +static INLINE uint32_t +nv50_colormask(unsigned mask) +{ + uint32_t cmask = 0; + + if (mask & PIPE_MASK_R) + cmask |= 0x0001; + if (mask & PIPE_MASK_G) + cmask |= 0x0010; + if (mask & PIPE_MASK_B) + cmask |= 0x0100; + if (mask & PIPE_MASK_A) + cmask |= 0x1000; + + return cmask; +} + +static INLINE uint32_t +nv50_blend_func(unsigned factor) +{ + switch (factor) { + case PIPE_BLENDFACTOR_ZERO: + return NV50TCL_BLEND_FUNC_SRC_RGB_ZERO; + case PIPE_BLENDFACTOR_ONE: + return NV50TCL_BLEND_FUNC_SRC_RGB_ONE; + case PIPE_BLENDFACTOR_SRC_COLOR: + return NV50TCL_BLEND_FUNC_SRC_RGB_SRC_COLOR; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_SRC_COLOR; + case PIPE_BLENDFACTOR_SRC_ALPHA: + return NV50TCL_BLEND_FUNC_SRC_RGB_SRC_ALPHA; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_SRC_ALPHA; + case PIPE_BLENDFACTOR_DST_ALPHA: + return NV50TCL_BLEND_FUNC_SRC_RGB_DST_ALPHA; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_DST_ALPHA; + case PIPE_BLENDFACTOR_DST_COLOR: + return NV50TCL_BLEND_FUNC_SRC_RGB_DST_COLOR; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_DST_COLOR; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + return NV50TCL_BLEND_FUNC_SRC_RGB_SRC_ALPHA_SATURATE; + case PIPE_BLENDFACTOR_CONST_COLOR: + return NV50TCL_BLEND_FUNC_SRC_RGB_CONSTANT_COLOR; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_CONSTANT_COLOR; + case PIPE_BLENDFACTOR_CONST_ALPHA: + return NV50TCL_BLEND_FUNC_SRC_RGB_CONSTANT_ALPHA; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_CONSTANT_ALPHA; + case PIPE_BLENDFACTOR_SRC1_COLOR: + return NV50TCL_BLEND_FUNC_SRC_RGB_SRC1_COLOR; + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_SRC1_COLOR; + case PIPE_BLENDFACTOR_SRC1_ALPHA: + return NV50TCL_BLEND_FUNC_SRC_RGB_SRC1_ALPHA; + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + return NV50TCL_BLEND_FUNC_SRC_RGB_ONE_MINUS_SRC1_ALPHA; + default: + return NV50TCL_BLEND_FUNC_SRC_RGB_ZERO; + } +} + +static void * +nv50_blend_state_create(struct pipe_context *pipe, + const struct pipe_blend_state *cso) +{ + struct nouveau_stateobj *so = so_new(5, 24, 0); + struct nouveau_grobj *tesla = nv50_context(pipe)->screen->tesla; + struct nv50_blend_stateobj *bso = CALLOC_STRUCT(nv50_blend_stateobj); + unsigned i, blend_enabled = 0; + + /*XXX ignored: + * - dither + */ + + so_method(so, tesla, NV50TCL_BLEND_ENABLE(0), 8); + if (cso->independent_blend_enable) { + for (i = 0; i < 8; ++i) { + so_data(so, cso->rt[i].blend_enable); + if (cso->rt[i].blend_enable) + blend_enabled = 1; + } + } else + if (cso->rt[0].blend_enable) { + blend_enabled = 1; + for (i = 0; i < 8; i++) + so_data(so, 1); + } else { + for (i = 0; i < 8; i++) + so_data(so, 0); + } + if (blend_enabled) { + so_method(so, tesla, NV50TCL_BLEND_EQUATION_RGB, 5); + so_data (so, nvgl_blend_eqn(cso->rt[0].rgb_func)); + so_data (so, nv50_blend_func(cso->rt[0].rgb_src_factor)); + so_data (so, nv50_blend_func(cso->rt[0].rgb_dst_factor)); + so_data (so, nvgl_blend_eqn(cso->rt[0].alpha_func)); + so_data (so, nv50_blend_func(cso->rt[0].alpha_src_factor)); + so_method(so, tesla, NV50TCL_BLEND_FUNC_DST_ALPHA, 1); + so_data (so, nv50_blend_func(cso->rt[0].alpha_dst_factor)); + } + + if (cso->logicop_enable == 0 ) { + so_method(so, tesla, NV50TCL_LOGIC_OP_ENABLE, 1); + so_data (so, 0); + } else { + so_method(so, tesla, NV50TCL_LOGIC_OP_ENABLE, 2); + so_data (so, 1); + so_data (so, nvgl_logicop_func(cso->logicop_func)); + } + + so_method(so, tesla, NV50TCL_COLOR_MASK(0), 8); + if (cso->independent_blend_enable) + for (i = 0; i < 8; ++i) + so_data(so, nv50_colormask(cso->rt[i].colormask)); + else { + uint32_t cmask = nv50_colormask(cso->rt[0].colormask); + for (i = 0; i < 8; i++) + so_data(so, cmask); + } + + bso->pipe = *cso; + so_ref(so, &bso->so); + so_ref(NULL, &so); + return (void *)bso; +} + +static void +nv50_blend_state_bind(struct pipe_context *pipe, void *hwcso) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + nv50->blend = hwcso; + nv50->dirty |= NV50_NEW_BLEND; +} + +static void +nv50_blend_state_delete(struct pipe_context *pipe, void *hwcso) +{ + struct nv50_blend_stateobj *bso = hwcso; + + so_ref(NULL, &bso->so); + FREE(bso); +} + +static INLINE unsigned +wrap_mode(unsigned wrap) +{ + switch (wrap) { + case PIPE_TEX_WRAP_REPEAT: + return NV50TSC_1_0_WRAPS_REPEAT; + case PIPE_TEX_WRAP_MIRROR_REPEAT: + return NV50TSC_1_0_WRAPS_MIRROR_REPEAT; + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return NV50TSC_1_0_WRAPS_CLAMP_TO_EDGE; + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + return NV50TSC_1_0_WRAPS_CLAMP_TO_BORDER; + case PIPE_TEX_WRAP_CLAMP: + return NV50TSC_1_0_WRAPS_CLAMP; + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + return NV50TSC_1_0_WRAPS_MIRROR_CLAMP_TO_EDGE; + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + return NV50TSC_1_0_WRAPS_MIRROR_CLAMP_TO_BORDER; + case PIPE_TEX_WRAP_MIRROR_CLAMP: + return NV50TSC_1_0_WRAPS_MIRROR_CLAMP; + default: + NOUVEAU_ERR("unknown wrap mode: %d\n", wrap); + return NV50TSC_1_0_WRAPS_REPEAT; + } +} +static void * +nv50_sampler_state_create(struct pipe_context *pipe, + const struct pipe_sampler_state *cso) +{ + struct nv50_sampler_stateobj *sso = CALLOC(1, sizeof(*sso)); + unsigned *tsc = sso->tsc; + float limit; + + tsc[0] = (0x00026000 | + (wrap_mode(cso->wrap_s) << 0) | + (wrap_mode(cso->wrap_t) << 3) | + (wrap_mode(cso->wrap_r) << 6)); + + switch (cso->mag_img_filter) { + case PIPE_TEX_FILTER_LINEAR: + tsc[1] |= NV50TSC_1_1_MAGF_LINEAR; + break; + case PIPE_TEX_FILTER_NEAREST: + default: + tsc[1] |= NV50TSC_1_1_MAGF_NEAREST; + break; + } + + switch (cso->min_img_filter) { + case PIPE_TEX_FILTER_LINEAR: + tsc[1] |= NV50TSC_1_1_MINF_LINEAR; + break; + case PIPE_TEX_FILTER_NEAREST: + default: + tsc[1] |= NV50TSC_1_1_MINF_NEAREST; + break; + } + + switch (cso->min_mip_filter) { + case PIPE_TEX_MIPFILTER_LINEAR: + tsc[1] |= NV50TSC_1_1_MIPF_LINEAR; + break; + case PIPE_TEX_MIPFILTER_NEAREST: + tsc[1] |= NV50TSC_1_1_MIPF_NEAREST; + break; + case PIPE_TEX_MIPFILTER_NONE: + default: + tsc[1] |= NV50TSC_1_1_MIPF_NONE; + break; + } + + if (cso->max_anisotropy >= 16) + tsc[0] |= (7 << 20); + else + if (cso->max_anisotropy >= 12) + tsc[0] |= (6 << 20); + else { + tsc[0] |= (cso->max_anisotropy >> 1) << 20; + + if (cso->max_anisotropy >= 4) + tsc[1] |= NV50TSC_1_1_UNKN_ANISO_35; + else + if (cso->max_anisotropy >= 2) + tsc[1] |= NV50TSC_1_1_UNKN_ANISO_15; + } + + if (cso->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) { + /* XXX: must be deactivated for non-shadow textures */ + tsc[0] |= (1 << 9); + tsc[0] |= (nvgl_comparison_op(cso->compare_func) & 0x7) << 10; + } + + limit = CLAMP(cso->lod_bias, -16.0, 15.0); + tsc[1] |= ((int)(limit * 256.0) & 0x1fff) << 12; + + tsc[2] |= ((int)CLAMP(cso->max_lod, 0.0, 15.0) << 20) | + ((int)CLAMP(cso->min_lod, 0.0, 15.0) << 8); + + tsc[4] = fui(cso->border_color[0]); + tsc[5] = fui(cso->border_color[1]); + tsc[6] = fui(cso->border_color[2]); + tsc[7] = fui(cso->border_color[3]); + + sso->normalized = cso->normalized_coords; + return (void *)sso; +} + +/* type == 0 for VPs, 1 for GPs, 2 for FPs, which is how the + * relevant tesla methods are indexed (NV50TCL_BIND_TSC etc.) + */ +static INLINE void +nv50_sampler_state_bind(struct pipe_context *pipe, unsigned type, + unsigned nr, void **sampler) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + memcpy(nv50->sampler[type], sampler, nr * sizeof(void *)); + + nv50->sampler_nr[type] = nr; + nv50->dirty |= NV50_NEW_SAMPLER; +} + +static void +nv50_vp_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **s) +{ + nv50_sampler_state_bind(pipe, 0, nr, s); +} + +static void +nv50_fp_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **s) +{ + nv50_sampler_state_bind(pipe, 2, nr, s); +} + +static void +nv50_sampler_state_delete(struct pipe_context *pipe, void *hwcso) +{ + FREE(hwcso); +} + +static INLINE void +nv50_set_sampler_views(struct pipe_context *pipe, unsigned p, + unsigned nr, + struct pipe_sampler_view **views) +{ + struct nv50_context *nv50 = nv50_context(pipe); + unsigned i; + + for (i = 0; i < nr; i++) + pipe_sampler_view_reference(&nv50->sampler_views[p][i], + views[i]); + + for (i = nr; i < nv50->sampler_view_nr[p]; i++) + pipe_sampler_view_reference(&nv50->sampler_views[p][i], NULL); + + nv50->sampler_view_nr[p] = nr; + nv50->dirty |= NV50_NEW_TEXTURE; +} + +static void +nv50_set_vp_sampler_views(struct pipe_context *pipe, + unsigned nr, + struct pipe_sampler_view **views) +{ + nv50_set_sampler_views(pipe, 0, nr, views); +} + +static void +nv50_set_fp_sampler_views(struct pipe_context *pipe, + unsigned nr, + struct pipe_sampler_view **views) +{ + nv50_set_sampler_views(pipe, 2, nr, views); +} + +static void +nv50_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_resource_reference(&view->texture, NULL); + FREE(nv50_sampler_view(view)); +} + +static struct pipe_sampler_view * +nv50_create_sampler_view(struct pipe_context *pipe, + struct pipe_resource *texture, + const struct pipe_sampler_view *templ) +{ + struct nv50_sampler_view *view = CALLOC_STRUCT(nv50_sampler_view); + + view->pipe = *templ; + view->pipe.reference.count = 1; + view->pipe.texture = NULL; + pipe_resource_reference(&view->pipe.texture, texture); + view->pipe.context = pipe; + + if (!nv50_tex_construct(view)) { + nv50_sampler_view_destroy(pipe, &view->pipe); + return NULL; + } + return &view->pipe; +} + + +static void * +nv50_rasterizer_state_create(struct pipe_context *pipe, + const struct pipe_rasterizer_state *cso) +{ + struct nouveau_stateobj *so = so_new(16, 22, 0); + struct nouveau_grobj *tesla = nv50_context(pipe)->screen->tesla; + struct nv50_rasterizer_stateobj *rso = + CALLOC_STRUCT(nv50_rasterizer_stateobj); + + /*XXX: ignored + * - light_twoside + * - point_smooth + * - multisample + * - point_sprite / sprite_coord_mode + */ + + so_method(so, tesla, NV50TCL_SCISSOR_ENABLE(0), 1); + so_data (so, cso->scissor); + + so_method(so, tesla, NV50TCL_SHADE_MODEL, 1); + so_data (so, cso->flatshade ? NV50TCL_SHADE_MODEL_FLAT : + NV50TCL_SHADE_MODEL_SMOOTH); + so_method(so, tesla, NV50TCL_PROVOKING_VERTEX_LAST, 1); + so_data (so, cso->flatshade_first ? 0 : 1); + + so_method(so, tesla, NV50TCL_VERTEX_TWO_SIDE_ENABLE, 1); + so_data (so, cso->light_twoside); + + so_method(so, tesla, NV50TCL_LINE_WIDTH, 1); + so_data (so, fui(cso->line_width)); + so_method(so, tesla, NV50TCL_LINE_SMOOTH_ENABLE, 1); + so_data (so, cso->line_smooth ? 1 : 0); + if (cso->line_stipple_enable) { + so_method(so, tesla, NV50TCL_LINE_STIPPLE_ENABLE, 1); + so_data (so, 1); + so_method(so, tesla, NV50TCL_LINE_STIPPLE_PATTERN, 1); + so_data (so, (cso->line_stipple_pattern << 8) | + cso->line_stipple_factor); + } else { + so_method(so, tesla, NV50TCL_LINE_STIPPLE_ENABLE, 1); + so_data (so, 0); + } + + so_method(so, tesla, NV50TCL_POINT_SIZE, 1); + so_data (so, fui(cso->point_size)); + + so_method(so, tesla, NV50TCL_POINT_SPRITE_ENABLE, 1); + so_data (so, cso->point_quad_rasterization ? 1 : 0); + + so_method(so, tesla, NV50TCL_POLYGON_MODE_FRONT, 3); + so_data(so, nvgl_polygon_mode(cso->fill_front)); + so_data(so, nvgl_polygon_mode(cso->fill_back)); + so_data(so, cso->poly_smooth ? 1 : 0); + + so_method(so, tesla, NV50TCL_CULL_FACE_ENABLE, 3); + so_data (so, cso->cull_face != PIPE_FACE_NONE); + if (cso->front_ccw) { + so_data(so, NV50TCL_FRONT_FACE_CCW); + } + else { + so_data(so, NV50TCL_FRONT_FACE_CW); + } + switch (cso->cull_face) { + case PIPE_FACE_FRONT: + so_data(so, NV50TCL_CULL_FACE_FRONT); + break; + case PIPE_FACE_BACK: + so_data(so, NV50TCL_CULL_FACE_BACK); + break; + case PIPE_FACE_FRONT_AND_BACK: + so_data(so, NV50TCL_CULL_FACE_FRONT_AND_BACK); + break; + default: + so_data(so, NV50TCL_CULL_FACE_BACK); + break; + } + + so_method(so, tesla, NV50TCL_POLYGON_STIPPLE_ENABLE, 1); + so_data (so, cso->poly_stipple_enable ? 1 : 0); + + so_method(so, tesla, NV50TCL_POLYGON_OFFSET_POINT_ENABLE, 3); + so_data(so, cso->offset_point); + so_data(so, cso->offset_line); + so_data(so, cso->offset_tri); + + if (cso->offset_point || + cso->offset_line || + cso->offset_tri) { + so_method(so, tesla, NV50TCL_POLYGON_OFFSET_FACTOR, 1); + so_data (so, fui(cso->offset_scale)); + so_method(so, tesla, NV50TCL_POLYGON_OFFSET_UNITS, 1); + so_data (so, fui(cso->offset_units * 2.0f)); + } + + rso->pipe = *cso; + so_ref(so, &rso->so); + so_ref(NULL, &so); + return (void *)rso; +} + +static void +nv50_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + nv50->rasterizer = hwcso; + nv50->dirty |= NV50_NEW_RASTERIZER; +} + +static void +nv50_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso) +{ + struct nv50_rasterizer_stateobj *rso = hwcso; + + so_ref(NULL, &rso->so); + FREE(rso); +} + +static void * +nv50_depth_stencil_alpha_state_create(struct pipe_context *pipe, + const struct pipe_depth_stencil_alpha_state *cso) +{ + struct nouveau_grobj *tesla = nv50_context(pipe)->screen->tesla; + struct nv50_zsa_stateobj *zsa = CALLOC_STRUCT(nv50_zsa_stateobj); + struct nouveau_stateobj *so = so_new(9, 21, 0); + + so_method(so, tesla, NV50TCL_DEPTH_WRITE_ENABLE, 1); + so_data (so, cso->depth.writemask ? 1 : 0); + if (cso->depth.enabled) { + so_method(so, tesla, NV50TCL_DEPTH_TEST_ENABLE, 1); + so_data (so, 1); + so_method(so, tesla, NV50TCL_DEPTH_TEST_FUNC, 1); + so_data (so, nvgl_comparison_op(cso->depth.func)); + } else { + so_method(so, tesla, NV50TCL_DEPTH_TEST_ENABLE, 1); + so_data (so, 0); + } + + if (cso->stencil[0].enabled) { + so_method(so, tesla, NV50TCL_STENCIL_FRONT_ENABLE, 5); + so_data (so, 1); + so_data (so, nvgl_stencil_op(cso->stencil[0].fail_op)); + so_data (so, nvgl_stencil_op(cso->stencil[0].zfail_op)); + so_data (so, nvgl_stencil_op(cso->stencil[0].zpass_op)); + so_data (so, nvgl_comparison_op(cso->stencil[0].func)); + so_method(so, tesla, NV50TCL_STENCIL_FRONT_MASK, 2); + so_data (so, cso->stencil[0].writemask); + so_data (so, cso->stencil[0].valuemask); + } else { + so_method(so, tesla, NV50TCL_STENCIL_FRONT_ENABLE, 1); + so_data (so, 0); + } + + if (cso->stencil[1].enabled) { + so_method(so, tesla, NV50TCL_STENCIL_BACK_ENABLE, 5); + so_data (so, 1); + so_data (so, nvgl_stencil_op(cso->stencil[1].fail_op)); + so_data (so, nvgl_stencil_op(cso->stencil[1].zfail_op)); + so_data (so, nvgl_stencil_op(cso->stencil[1].zpass_op)); + so_data (so, nvgl_comparison_op(cso->stencil[1].func)); + so_method(so, tesla, NV50TCL_STENCIL_BACK_MASK, 2); + so_data (so, cso->stencil[1].writemask); + so_data (so, cso->stencil[1].valuemask); + } else { + so_method(so, tesla, NV50TCL_STENCIL_BACK_ENABLE, 1); + so_data (so, 0); + } + + if (cso->alpha.enabled) { + so_method(so, tesla, NV50TCL_ALPHA_TEST_ENABLE, 1); + so_data (so, 1); + so_method(so, tesla, NV50TCL_ALPHA_TEST_REF, 2); + so_data (so, fui(cso->alpha.ref_value)); + so_data (so, nvgl_comparison_op(cso->alpha.func)); + } else { + so_method(so, tesla, NV50TCL_ALPHA_TEST_ENABLE, 1); + so_data (so, 0); + } + + zsa->pipe = *cso; + so_ref(so, &zsa->so); + so_ref(NULL, &so); + return (void *)zsa; +} + +static void +nv50_depth_stencil_alpha_state_bind(struct pipe_context *pipe, void *hwcso) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + nv50->zsa = hwcso; + nv50->dirty |= NV50_NEW_ZSA; +} + +static void +nv50_depth_stencil_alpha_state_delete(struct pipe_context *pipe, void *hwcso) +{ + struct nv50_zsa_stateobj *zsa = hwcso; + + so_ref(NULL, &zsa->so); + FREE(zsa); +} + +static void * +nv50_vp_state_create(struct pipe_context *pipe, + const struct pipe_shader_state *cso) +{ + struct nv50_program *p = CALLOC_STRUCT(nv50_program); + + p->pipe.tokens = tgsi_dup_tokens(cso->tokens); + p->type = PIPE_SHADER_VERTEX; + return (void *)p; +} + +static void +nv50_vp_state_bind(struct pipe_context *pipe, void *hwcso) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + nv50->vertprog = hwcso; + nv50->dirty |= NV50_NEW_VERTPROG; +} + +static void +nv50_vp_state_delete(struct pipe_context *pipe, void *hwcso) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nv50_program *p = hwcso; + + nv50_program_destroy(nv50, p); + FREE((void *)p->pipe.tokens); + FREE(p); +} + +static void * +nv50_fp_state_create(struct pipe_context *pipe, + const struct pipe_shader_state *cso) +{ + struct nv50_program *p = CALLOC_STRUCT(nv50_program); + + p->pipe.tokens = tgsi_dup_tokens(cso->tokens); + p->type = PIPE_SHADER_FRAGMENT; + return (void *)p; +} + +static void +nv50_fp_state_bind(struct pipe_context *pipe, void *hwcso) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + nv50->fragprog = hwcso; + nv50->dirty |= NV50_NEW_FRAGPROG; +} + +static void +nv50_fp_state_delete(struct pipe_context *pipe, void *hwcso) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nv50_program *p = hwcso; + + nv50_program_destroy(nv50, p); + FREE((void *)p->pipe.tokens); + FREE(p); +} + +static void * +nv50_gp_state_create(struct pipe_context *pipe, + const struct pipe_shader_state *cso) +{ + struct nv50_program *p = CALLOC_STRUCT(nv50_program); + + p->pipe.tokens = tgsi_dup_tokens(cso->tokens); + p->type = PIPE_SHADER_GEOMETRY; + return (void *)p; +} + +static void +nv50_gp_state_bind(struct pipe_context *pipe, void *hwcso) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + nv50->geomprog = hwcso; + nv50->dirty |= NV50_NEW_GEOMPROG; +} + +static void +nv50_gp_state_delete(struct pipe_context *pipe, void *hwcso) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nv50_program *p = hwcso; + + nv50_program_destroy(nv50, p); + FREE((void *)p->pipe.tokens); + FREE(p); +} + +static void +nv50_set_blend_color(struct pipe_context *pipe, + const struct pipe_blend_color *bcol) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + nv50->blend_colour = *bcol; + nv50->dirty |= NV50_NEW_BLEND_COLOUR; +} + + static void +nv50_set_stencil_ref(struct pipe_context *pipe, + const struct pipe_stencil_ref *sr) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + nv50->stencil_ref = *sr; + nv50->dirty |= NV50_NEW_STENCIL_REF; +} + +static void +nv50_set_clip_state(struct pipe_context *pipe, + const struct pipe_clip_state *clip) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + nv50->clip.depth_clamp = clip->depth_clamp; + nv50->dirty |= NV50_NEW_CLIP; +} + +static void +nv50_set_sample_mask(struct pipe_context *pipe, + unsigned sample_mask) +{ +} + +static void +nv50_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index, + struct pipe_resource *buf ) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + if (shader == PIPE_SHADER_VERTEX) { + nv50->constbuf[PIPE_SHADER_VERTEX] = buf; + nv50->dirty |= NV50_NEW_VERTPROG_CB; + } else + if (shader == PIPE_SHADER_FRAGMENT) { + nv50->constbuf[PIPE_SHADER_FRAGMENT] = buf; + nv50->dirty |= NV50_NEW_FRAGPROG_CB; + } else + if (shader == PIPE_SHADER_GEOMETRY) { + nv50->constbuf[PIPE_SHADER_GEOMETRY] = buf; + nv50->dirty |= NV50_NEW_GEOMPROG_CB; + } +} + +static void +nv50_set_framebuffer_state(struct pipe_context *pipe, + const struct pipe_framebuffer_state *fb) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + nv50->framebuffer = *fb; + nv50->dirty |= NV50_NEW_FRAMEBUFFER; +} + +static void +nv50_set_polygon_stipple(struct pipe_context *pipe, + const struct pipe_poly_stipple *stipple) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + nv50->stipple = *stipple; + nv50->dirty |= NV50_NEW_STIPPLE; +} + +static void +nv50_set_scissor_state(struct pipe_context *pipe, + const struct pipe_scissor_state *s) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + nv50->scissor = *s; + nv50->dirty |= NV50_NEW_SCISSOR; +} + +static void +nv50_set_viewport_state(struct pipe_context *pipe, + const struct pipe_viewport_state *vpt) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + nv50->viewport = *vpt; + nv50->dirty |= NV50_NEW_VIEWPORT; +} + +static void +nv50_set_vertex_buffers(struct pipe_context *pipe, unsigned count, + const struct pipe_vertex_buffer *vb) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + memcpy(nv50->vtxbuf, vb, sizeof(*vb) * count); + nv50->vtxbuf_nr = count; + + nv50->dirty |= NV50_NEW_ARRAYS; +} + +static void +nv50_set_index_buffer(struct pipe_context *pipe, + const struct pipe_index_buffer *ib) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + if (ib) + memcpy(&nv50->idxbuf, ib, sizeof(nv50->idxbuf)); + else + memset(&nv50->idxbuf, 0, sizeof(nv50->idxbuf)); + + /* TODO make this more like a state */ +} + +static void * +nv50_vtxelts_state_create(struct pipe_context *pipe, + unsigned num_elements, + const struct pipe_vertex_element *elements) +{ + struct nv50_vtxelt_stateobj *cso = CALLOC_STRUCT(nv50_vtxelt_stateobj); + + assert(num_elements < 16); /* not doing fallbacks yet */ + cso->num_elements = num_elements; + memcpy(cso->pipe, elements, num_elements * sizeof(*elements)); + + nv50_vtxelt_construct(cso); + + return (void *)cso; +} + +static void +nv50_vtxelts_state_delete(struct pipe_context *pipe, void *hwcso) +{ + FREE(hwcso); +} + +static void +nv50_vtxelts_state_bind(struct pipe_context *pipe, void *hwcso) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + nv50->vtxelt = hwcso; + nv50->dirty |= NV50_NEW_ARRAYS; +} + +void +nv50_init_state_functions(struct nv50_context *nv50) +{ + nv50->pipe.create_blend_state = nv50_blend_state_create; + nv50->pipe.bind_blend_state = nv50_blend_state_bind; + nv50->pipe.delete_blend_state = nv50_blend_state_delete; + + nv50->pipe.create_sampler_state = nv50_sampler_state_create; + nv50->pipe.delete_sampler_state = nv50_sampler_state_delete; + nv50->pipe.bind_fragment_sampler_states = nv50_fp_sampler_state_bind; + nv50->pipe.bind_vertex_sampler_states = nv50_vp_sampler_state_bind; + nv50->pipe.set_fragment_sampler_views = nv50_set_fp_sampler_views; + nv50->pipe.set_vertex_sampler_views = nv50_set_vp_sampler_views; + nv50->pipe.create_sampler_view = nv50_create_sampler_view; + nv50->pipe.sampler_view_destroy = nv50_sampler_view_destroy; + + nv50->pipe.create_rasterizer_state = nv50_rasterizer_state_create; + nv50->pipe.bind_rasterizer_state = nv50_rasterizer_state_bind; + nv50->pipe.delete_rasterizer_state = nv50_rasterizer_state_delete; + + nv50->pipe.create_depth_stencil_alpha_state = + nv50_depth_stencil_alpha_state_create; + nv50->pipe.bind_depth_stencil_alpha_state = + nv50_depth_stencil_alpha_state_bind; + nv50->pipe.delete_depth_stencil_alpha_state = + nv50_depth_stencil_alpha_state_delete; + + nv50->pipe.create_vs_state = nv50_vp_state_create; + nv50->pipe.bind_vs_state = nv50_vp_state_bind; + nv50->pipe.delete_vs_state = nv50_vp_state_delete; + + nv50->pipe.create_fs_state = nv50_fp_state_create; + nv50->pipe.bind_fs_state = nv50_fp_state_bind; + nv50->pipe.delete_fs_state = nv50_fp_state_delete; + + nv50->pipe.create_gs_state = nv50_gp_state_create; + nv50->pipe.bind_gs_state = nv50_gp_state_bind; + nv50->pipe.delete_gs_state = nv50_gp_state_delete; + + nv50->pipe.set_blend_color = nv50_set_blend_color; + nv50->pipe.set_stencil_ref = nv50_set_stencil_ref; + nv50->pipe.set_clip_state = nv50_set_clip_state; + nv50->pipe.set_sample_mask = nv50_set_sample_mask; + nv50->pipe.set_constant_buffer = nv50_set_constant_buffer; + nv50->pipe.set_framebuffer_state = nv50_set_framebuffer_state; + nv50->pipe.set_polygon_stipple = nv50_set_polygon_stipple; + nv50->pipe.set_scissor_state = nv50_set_scissor_state; + nv50->pipe.set_viewport_state = nv50_set_viewport_state; + + nv50->pipe.create_vertex_elements_state = nv50_vtxelts_state_create; + nv50->pipe.delete_vertex_elements_state = nv50_vtxelts_state_delete; + nv50->pipe.bind_vertex_elements_state = nv50_vtxelts_state_bind; + + nv50->pipe.set_vertex_buffers = nv50_set_vertex_buffers; + nv50->pipe.set_index_buffer = nv50_set_index_buffer; +} + diff --git a/src/gallium/drivers/nv50/nv50_state_validate.c b/src/gallium/drivers/nv50/nv50_state_validate.c new file mode 100644 index 0000000..ae02143 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_state_validate.c @@ -0,0 +1,449 @@ +/* + * Copyright 2008 Ben Skeggs + * + * 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 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_format.h" + +#include "nv50_context.h" +#include "nv50_resource.h" +#include "nouveau/nouveau_stateobj.h" + +static struct nouveau_stateobj * +validate_fb(struct nv50_context *nv50) +{ + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_stateobj *so = so_new(32, 79, 18); + struct pipe_framebuffer_state *fb = &nv50->framebuffer; + unsigned i, w = 0, h = 0, gw = 0; + + /* Set nr of active RTs and select RT for each colour output. + * FP result 0 always goes to RT[0], bits 4 - 6 are ignored. + * Ambiguous assignment results in no rendering (no DATA_ERROR). + */ + so_method(so, tesla, NV50TCL_RT_CONTROL, 1); + so_data (so, fb->nr_cbufs | + (0 << 4) | (1 << 7) | (2 << 10) | (3 << 13) | + (4 << 16) | (5 << 19) | (6 << 22) | (7 << 25)); + + for (i = 0; i < fb->nr_cbufs; i++) { + struct pipe_resource *pt = fb->cbufs[i]->texture; + struct nouveau_bo *bo = nv50_miptree(pt)->base.bo; + + if (!gw) { + w = fb->cbufs[i]->width; + h = fb->cbufs[i]->height; + gw = 1; + } else { + assert(w == fb->cbufs[i]->width); + assert(h == fb->cbufs[i]->height); + } + + assert(nv50_format_table[fb->cbufs[i]->format].rt); + + so_method(so, tesla, NV50TCL_RT_HORIZ(i), 2); + so_data (so, fb->cbufs[i]->width); + so_data (so, fb->cbufs[i]->height); + + so_method(so, tesla, NV50TCL_RT_ADDRESS_HIGH(i), 5); + so_reloc (so, bo, ((struct nv50_surface *)fb->cbufs[i])->offset, NOUVEAU_BO_VRAM | + NOUVEAU_BO_HIGH | NOUVEAU_BO_RDWR, 0, 0); + so_reloc (so, bo, ((struct nv50_surface *)fb->cbufs[i])->offset, NOUVEAU_BO_VRAM | + NOUVEAU_BO_LOW | NOUVEAU_BO_RDWR, 0, 0); + so_data (so, nv50_format_table[fb->cbufs[i]->format].rt); + so_data (so, nv50_miptree(pt)-> + level[fb->cbufs[i]->u.tex.level].tile_mode << 4); + so_data(so, 0x00000000); + + so_method(so, tesla, NV50TCL_RT_ARRAY_MODE, 1); + so_data (so, 1); + } + + if (fb->zsbuf) { + struct pipe_resource *pt = fb->zsbuf->texture; + struct nouveau_bo *bo = nv50_miptree(pt)->base.bo; + + if (!gw) { + w = fb->zsbuf->width; + h = fb->zsbuf->height; + gw = 1; + } else { + assert(w == fb->zsbuf->width); + assert(h == fb->zsbuf->height); + } + + assert(nv50_format_table[fb->zsbuf->format].rt); + + so_method(so, tesla, NV50TCL_ZETA_ADDRESS_HIGH, 5); + so_reloc (so, bo, ((struct nv50_surface *)(fb->zsbuf))->offset, NOUVEAU_BO_VRAM | + NOUVEAU_BO_HIGH | NOUVEAU_BO_RDWR, 0, 0); + so_reloc (so, bo, ((struct nv50_surface *)(fb->zsbuf))->offset, NOUVEAU_BO_VRAM | + NOUVEAU_BO_LOW | NOUVEAU_BO_RDWR, 0, 0); + so_data (so, nv50_format_table[fb->zsbuf->format].rt); + so_data (so, nv50_miptree(pt)-> + level[fb->zsbuf->u.tex.level].tile_mode << 4); + so_data (so, 0x00000000); + + so_method(so, tesla, NV50TCL_ZETA_ENABLE, 1); + so_data (so, 1); + so_method(so, tesla, NV50TCL_ZETA_HORIZ, 3); + so_data (so, fb->zsbuf->width); + so_data (so, fb->zsbuf->height); + so_data (so, 0x00010001); + } else { + so_method(so, tesla, NV50TCL_ZETA_ENABLE, 1); + so_data (so, 0); + } + + so_method(so, tesla, NV50TCL_VIEWPORT_HORIZ(0), 2); + so_data (so, w << 16); + so_data (so, h << 16); + /* set window lower left corner */ + so_method(so, tesla, NV50TCL_WINDOW_OFFSET_X, 2); + so_data (so, 0); + so_data (so, 0); + /* set screen scissor rectangle */ + so_method(so, tesla, NV50TCL_SCREEN_SCISSOR_HORIZ, 2); + so_data (so, w << 16); + so_data (so, h << 16); + + return so; +} + +static void +nv50_validate_samplers(struct nv50_context *nv50, struct nouveau_stateobj *so, + unsigned p) +{ + struct nouveau_grobj *eng2d = nv50->screen->eng2d; + unsigned i, j, dw = nv50->sampler_nr[p] * 8; + + if (!dw) + return; + nv50_so_init_sifc(nv50, so, nv50->screen->tsc, NOUVEAU_BO_VRAM, + p * (32 * 8 * 4), dw * 4); + + so_method(so, eng2d, NV50_2D_SIFC_DATA | (2 << 29), dw); + + for (i = 0; i < nv50->sampler_nr[p]; ++i) { + if (nv50->sampler[p][i]) + so_datap(so, nv50->sampler[p][i]->tsc, 8); + else { + for (j = 0; j < 8; ++j) /* you get punished */ + so_data(so, 0); /* ... for leaving holes */ + } + } +} + +static struct nouveau_stateobj * +validate_blend(struct nv50_context *nv50) +{ + struct nouveau_stateobj *so = NULL; + so_ref(nv50->blend->so, &so); + return so; +} + +static struct nouveau_stateobj * +validate_zsa(struct nv50_context *nv50) +{ + struct nouveau_stateobj *so = NULL; + so_ref(nv50->zsa->so, &so); + return so; +} + +static struct nouveau_stateobj * +validate_rast(struct nv50_context *nv50) +{ + struct nouveau_stateobj *so = NULL; + so_ref(nv50->rasterizer->so, &so); + return so; +} + +static struct nouveau_stateobj * +validate_blend_colour(struct nv50_context *nv50) +{ + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_stateobj *so = so_new(1, 4, 0); + + so_method(so, tesla, NV50TCL_BLEND_COLOR(0), 4); + so_data (so, fui(nv50->blend_colour.color[0])); + so_data (so, fui(nv50->blend_colour.color[1])); + so_data (so, fui(nv50->blend_colour.color[2])); + so_data (so, fui(nv50->blend_colour.color[3])); + return so; +} + +static struct nouveau_stateobj * +validate_stencil_ref(struct nv50_context *nv50) +{ + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_stateobj *so = so_new(2, 2, 0); + + so_method(so, tesla, NV50TCL_STENCIL_FRONT_FUNC_REF, 1); + so_data (so, nv50->stencil_ref.ref_value[0]); + so_method(so, tesla, NV50TCL_STENCIL_BACK_FUNC_REF, 1); + so_data (so, nv50->stencil_ref.ref_value[1]); + return so; +} + +static struct nouveau_stateobj * +validate_stipple(struct nv50_context *nv50) +{ + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_stateobj *so = so_new(1, 32, 0); + int i; + + so_method(so, tesla, NV50TCL_POLYGON_STIPPLE_PATTERN(0), 32); + for (i = 0; i < 32; i++) + so_data(so, util_bswap32(nv50->stipple.stipple[i])); + return so; +} + +static struct nouveau_stateobj * +validate_scissor(struct nv50_context *nv50) +{ + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct pipe_scissor_state *s = &nv50->scissor; + struct nouveau_stateobj *so; + + so = so_new(1, 2, 0); + so_method(so, tesla, NV50TCL_SCISSOR_HORIZ(0), 2); + so_data (so, (s->maxx << 16) | s->minx); + so_data (so, (s->maxy << 16) | s->miny); + return so; +} + +static struct nouveau_stateobj * +validate_viewport(struct nv50_context *nv50) +{ + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_stateobj *so = so_new(3, 7, 0); + + so_method(so, tesla, NV50TCL_VIEWPORT_TRANSLATE_X(0), 3); + so_data (so, fui(nv50->viewport.translate[0])); + so_data (so, fui(nv50->viewport.translate[1])); + so_data (so, fui(nv50->viewport.translate[2])); + so_method(so, tesla, NV50TCL_VIEWPORT_SCALE_X(0), 3); + so_data (so, fui(nv50->viewport.scale[0])); + so_data (so, fui(nv50->viewport.scale[1])); + so_data (so, fui(nv50->viewport.scale[2])); + + /* no idea what 0f90 does */ + so_method(so, tesla, 0x0f90, 1); + so_data (so, 0); + + return so; +} + +static struct nouveau_stateobj * +validate_sampler(struct nv50_context *nv50) +{ + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_stateobj *so; + unsigned nr = 0, i; + + for (i = 0; i < 3; ++i) + nr += nv50->sampler_nr[i]; + + so = so_new(1 + 5 * 3, 1 + 19 * 3 + nr * 8, 3 * 2); + + nv50_validate_samplers(nv50, so, 0); /* VP */ + nv50_validate_samplers(nv50, so, 2); /* FP */ + + so_method(so, tesla, 0x1334, 1); /* flush TSC */ + so_data (so, 0); + + return so; +} + +static struct nouveau_stateobj * +validate_vtxbuf(struct nv50_context *nv50) +{ + struct nouveau_stateobj *so = NULL; + so_ref(nv50->state.vtxbuf, &so); + return so; +} + +static struct nouveau_stateobj * +validate_vtxattr(struct nv50_context *nv50) +{ + struct nouveau_stateobj *so = NULL; + so_ref(nv50->state.vtxattr, &so); + return so; +} + +static struct nouveau_stateobj * +validate_clip(struct nv50_context *nv50) +{ + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_stateobj *so = so_new(1, 1, 0); + uint32_t vvcc; + + /* 0x0000 = remove whole primitive only (xyz) + * 0x1018 = remove whole primitive only (xy), clamp z + * 0x1080 = clip primitive (xyz) + * 0x1098 = clip primitive (xy), clamp z + */ + vvcc = nv50->clip.depth_clamp ? 0x1098 : 0x1080; + + so_method(so, tesla, NV50TCL_VIEW_VOLUME_CLIP_CTRL, 1); + so_data (so, vvcc); + + return so; +} + +struct state_validate { + struct nouveau_stateobj *(*func)(struct nv50_context *nv50); + unsigned states; +} validate_list[] = { + { validate_fb , NV50_NEW_FRAMEBUFFER }, + { validate_blend , NV50_NEW_BLEND }, + { validate_zsa , NV50_NEW_ZSA }, + { nv50_vertprog_validate , NV50_NEW_VERTPROG | NV50_NEW_VERTPROG_CB }, + { nv50_fragprog_validate , NV50_NEW_FRAGPROG | NV50_NEW_FRAGPROG_CB }, + { nv50_geomprog_validate , NV50_NEW_GEOMPROG | NV50_NEW_GEOMPROG_CB }, + { nv50_fp_linkage_validate, NV50_NEW_VERTPROG | NV50_NEW_GEOMPROG | + NV50_NEW_FRAGPROG | NV50_NEW_RASTERIZER }, + { nv50_gp_linkage_validate, NV50_NEW_VERTPROG | NV50_NEW_GEOMPROG }, + { validate_rast , NV50_NEW_RASTERIZER }, + { validate_blend_colour , NV50_NEW_BLEND_COLOUR }, + { validate_stencil_ref , NV50_NEW_STENCIL_REF }, + { validate_stipple , NV50_NEW_STIPPLE }, + { validate_scissor , NV50_NEW_SCISSOR }, + { validate_viewport , NV50_NEW_VIEWPORT }, + { validate_sampler , NV50_NEW_SAMPLER }, + { nv50_tex_validate , NV50_NEW_TEXTURE | NV50_NEW_SAMPLER }, + { nv50_vbo_validate , NV50_NEW_ARRAYS }, + { validate_vtxbuf , NV50_NEW_ARRAYS }, + { validate_vtxattr , NV50_NEW_ARRAYS }, + { validate_clip , NV50_NEW_CLIP }, + { NULL , 0 } +}; +#define validate_list_len (sizeof(validate_list) / sizeof(validate_list[0])) + +boolean +nv50_state_validate(struct nv50_context *nv50, unsigned wait_dwords) +{ + struct nouveau_channel *chan = nv50->screen->base.channel; + struct nouveau_grobj *tesla = nv50->screen->tesla; + unsigned nr_relocs = 128, nr_dwords = wait_dwords + 128 + 4; + int ret, i; + + for (i = 0; i < validate_list_len; i++) { + struct state_validate *validate = &validate_list[i]; + struct nouveau_stateobj *so; + + if (!(nv50->dirty & validate->states)) + continue; + + so = validate->func(nv50); + if (!so) + continue; + + nr_dwords += (so->total + so->cur); + nr_relocs += so->cur_reloc; + + so_ref(so, &nv50->state.hw[i]); + so_ref(NULL, &so); + nv50->state.hw_dirty |= (1 << i); + } + nv50->dirty = 0; + + if (nv50->screen->cur_ctx != nv50) { + for (i = 0; i < validate_list_len; i++) { + if (!nv50->state.hw[i] || + (nv50->state.hw_dirty & (1 << i))) + continue; + + nr_dwords += (nv50->state.hw[i]->total + + nv50->state.hw[i]->cur); + nr_relocs += nv50->state.hw[i]->cur_reloc; + nv50->state.hw_dirty |= (1 << i); + } + + nv50->screen->cur_ctx = nv50; + } + + ret = MARK_RING(chan, nr_dwords, nr_relocs); + if (ret) { + debug_printf("MARK_RING(%d, %d) failed: %d\n", + nr_dwords, nr_relocs, ret); + return FALSE; + } + + while (nv50->state.hw_dirty) { + i = ffs(nv50->state.hw_dirty) - 1; + nv50->state.hw_dirty &= ~(1 << i); + + so_emit(chan, nv50->state.hw[i]); + } + + /* Yes, really, we need to do this. If a buffer that is referenced + * on the hardware isn't part of changed state above, without doing + * this the kernel is given no clue that the buffer is being used + * still. This can cause all sorts of fun issues. + */ + nv50_tex_relocs(nv50); + so_emit_reloc_markers(chan, nv50->state.hw[0]); /* fb */ + so_emit_reloc_markers(chan, nv50->state.hw[3]); /* vp */ + so_emit_reloc_markers(chan, nv50->state.hw[4]); /* fp */ + so_emit_reloc_markers(chan, nv50->state.hw[17]); /* vb */ + nv50_screen_relocs(nv50->screen); + + /* No idea.. */ + BEGIN_RING(chan, tesla, 0x142c, 1); + OUT_RING (chan, 0); + BEGIN_RING(chan, tesla, 0x142c, 1); + OUT_RING (chan, 0); + return TRUE; +} + +void nv50_so_init_sifc(struct nv50_context *nv50, + struct nouveau_stateobj *so, + struct nouveau_bo *bo, unsigned reloc, + unsigned offset, unsigned size) +{ + struct nouveau_grobj *eng2d = nv50->screen->eng2d; + + reloc |= NOUVEAU_BO_WR; + + so_method(so, eng2d, NV50_2D_DST_FORMAT, 2); + so_data (so, NV50_2D_DST_FORMAT_R8_UNORM); + so_data (so, 1); + so_method(so, eng2d, NV50_2D_DST_PITCH, 5); + so_data (so, 262144); + so_data (so, 65536); + so_data (so, 1); + so_reloc (so, bo, offset, reloc | NOUVEAU_BO_HIGH, 0, 0); + so_reloc (so, bo, offset, reloc | NOUVEAU_BO_LOW, 0, 0); + so_method(so, eng2d, NV50_2D_SIFC_BITMAP_ENABLE, 2); + so_data (so, 0); + so_data (so, NV50_2D_SIFC_FORMAT_R8_UNORM); + so_method(so, eng2d, NV50_2D_SIFC_WIDTH, 10); + so_data (so, size); + so_data (so, 1); + so_data (so, 0); + so_data (so, 1); + so_data (so, 0); + so_data (so, 1); + so_data (so, 0); + so_data (so, 0); + so_data (so, 0); + so_data (so, 0); +} diff --git a/src/gallium/drivers/nv50/nv50_surface.c b/src/gallium/drivers/nv50/nv50_surface.c new file mode 100644 index 0000000..ce48022 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_surface.c @@ -0,0 +1,325 @@ +/* + * Copyright 2008 Ben Skeggs + * + * 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 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 __NOUVEAU_PUSH_H__ +#include +#include "nouveau/nouveau_pushbuf.h" +#include "nv50_context.h" +#include "nv50_resource.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_pack_color.h" + +#include "util/u_format.h" + +/* return TRUE for formats that can be converted among each other by NV50_2D */ +static INLINE boolean +nv50_2d_format_faithful(enum pipe_format format) +{ + switch (format) { + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_B8G8R8A8_SRGB: + case PIPE_FORMAT_B8G8R8X8_SRGB: + case PIPE_FORMAT_B5G6R5_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B10G10R10A2_UNORM: + case PIPE_FORMAT_R8_UNORM: + case PIPE_FORMAT_R32G32B32A32_FLOAT: + case PIPE_FORMAT_R32G32B32_FLOAT: + return TRUE; + default: + return FALSE; + } +} + +static INLINE uint8_t +nv50_2d_format(enum pipe_format format) +{ + uint8_t id = nv50_format_table[format].rt; + + /* Hardware values for color formats range from 0xc0 to 0xff, + * but the 2D engine doesn't support all of them. + */ + if ((id >= 0xc0) && (0xff0843e080608409ULL & (1ULL << (id - 0xc0)))) + return id; + + switch (util_format_get_blocksize(format)) { + case 1: + return NV50_2D_DST_FORMAT_R8_UNORM; + case 2: + return NV50_2D_DST_FORMAT_R16_UNORM; + case 4: + return NV50_2D_DST_FORMAT_A8R8G8B8_UNORM; + default: + return 0; + } +} + +static int +nv50_surface_set(struct nv50_screen *screen, struct pipe_surface *ps, int dst) +{ + struct nv50_miptree *mt = nv50_miptree(ps->texture); + struct nouveau_channel *chan = screen->eng2d->channel; + struct nouveau_grobj *eng2d = screen->eng2d; + struct nouveau_bo *bo = nv50_miptree(ps->texture)->base.bo; + int format, mthd = dst ? NV50_2D_DST_FORMAT : NV50_2D_SRC_FORMAT; + int flags = NOUVEAU_BO_VRAM | (dst ? NOUVEAU_BO_WR : NOUVEAU_BO_RD); + + format = nv50_2d_format(ps->format); + if (!format) { + NOUVEAU_ERR("invalid/unsupported surface format: %s\n", + util_format_name(ps->format)); + return 1; + } + + if (!nouveau_bo_tile_layout(bo)) { + BEGIN_RING(chan, eng2d, mthd, 2); + OUT_RING (chan, format); + OUT_RING (chan, 1); + BEGIN_RING(chan, eng2d, mthd + 0x14, 5); + OUT_RING (chan, mt->level[ps->u.tex.level].pitch); + OUT_RING (chan, ps->width); + OUT_RING (chan, ps->height); + OUT_RELOCh(chan, bo, ((struct nv50_surface *)ps)->offset, flags); + OUT_RELOCl(chan, bo, ((struct nv50_surface *)ps)->offset, flags); + } else { + BEGIN_RING(chan, eng2d, mthd, 5); + OUT_RING (chan, format); + OUT_RING (chan, 0); + OUT_RING (chan, mt->level[ps->u.tex.level].tile_mode << 4); + OUT_RING (chan, 1); + OUT_RING (chan, 0); + BEGIN_RING(chan, eng2d, mthd + 0x18, 4); + OUT_RING (chan, ps->width); + OUT_RING (chan, ps->height); + OUT_RELOCh(chan, bo, ((struct nv50_surface *)ps)->offset, flags); + OUT_RELOCl(chan, bo, ((struct nv50_surface *)ps)->offset, flags); + } + +#if 0 + if (dst) { + BEGIN_RING(chan, eng2d, NV50_2D_CLIP_X, 4); + OUT_RING (chan, 0); + OUT_RING (chan, 0); + OUT_RING (chan, surf->width); + OUT_RING (chan, surf->height); + } +#endif + + return 0; +} + +int +nv50_surface_do_copy(struct nv50_screen *screen, struct pipe_surface *dst, + int dx, int dy, struct pipe_surface *src, int sx, int sy, + int w, int h) +{ + struct nouveau_channel *chan = screen->eng2d->channel; + struct nouveau_grobj *eng2d = screen->eng2d; + int ret; + + ret = MARK_RING(chan, 2*16 + 32, 4); + if (ret) + return ret; + + ret = nv50_surface_set(screen, dst, 1); + if (ret) + return ret; + + ret = nv50_surface_set(screen, src, 0); + if (ret) + return ret; + + BEGIN_RING(chan, eng2d, 0x088c, 1); + OUT_RING (chan, 0); + BEGIN_RING(chan, eng2d, NV50_2D_BLIT_DST_X, 4); + OUT_RING (chan, dx); + OUT_RING (chan, dy); + OUT_RING (chan, w); + OUT_RING (chan, h); + BEGIN_RING(chan, eng2d, 0x08c0, 4); + OUT_RING (chan, 0); + OUT_RING (chan, 1); + OUT_RING (chan, 0); + OUT_RING (chan, 1); + BEGIN_RING(chan, eng2d, 0x08d0, 4); + OUT_RING (chan, 0); + OUT_RING (chan, sx); + OUT_RING (chan, 0); + OUT_RING (chan, sy); + + return 0; +} + +static void +nv50_surface_copy(struct pipe_context *pipe, + struct pipe_resource *dest, unsigned dst_level, + unsigned destx, unsigned desty, unsigned destz, + struct pipe_resource *src, unsigned src_level, + const struct pipe_box *src_box) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nv50_screen *screen = nv50->screen; + struct pipe_surface *ps_dst, *ps_src, surf_tmpl; + + + assert((src->format == dest->format) || + (nv50_2d_format_faithful(src->format) && + nv50_2d_format_faithful(dest->format))); + assert(src_box->depth == 1); + + memset(&surf_tmpl, 0, sizeof(surf_tmpl)); + surf_tmpl.format = src->format; + surf_tmpl.usage = 0; /* no bind flag - not a surface */ + surf_tmpl.u.tex.level = src_level; + surf_tmpl.u.tex.first_layer = src_box->z; + surf_tmpl.u.tex.last_layer = src_box->z; + /* XXX really need surfaces here? */ + ps_src = nv50_miptree_surface_new(pipe, src, &surf_tmpl); + surf_tmpl.format = dest->format; + surf_tmpl.usage = 0; /* no bind flag - not a surface */ + surf_tmpl.u.tex.level = dst_level; + surf_tmpl.u.tex.first_layer = destz; + surf_tmpl.u.tex.last_layer = destz; + ps_dst = nv50_miptree_surface_new(pipe, dest, &surf_tmpl); + + nv50_surface_do_copy(screen, ps_dst, destx, desty, ps_src, src_box->x, + src_box->y, src_box->width, src_box->height); + + nv50_miptree_surface_del(pipe, ps_src); + nv50_miptree_surface_del(pipe, ps_dst); +} + +static void +nv50_clear_render_target(struct pipe_context *pipe, + struct pipe_surface *dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nv50_screen *screen = nv50->screen; + struct nouveau_channel *chan = screen->base.channel; + struct nouveau_grobj *tesla = screen->tesla; + struct nv50_miptree *mt = nv50_miptree(dst->texture); + struct nouveau_bo *bo = mt->base.bo; + + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_COLOR(0), 4); + OUT_RINGf (chan, rgba[0]); + OUT_RINGf (chan, rgba[1]); + OUT_RINGf (chan, rgba[2]); + OUT_RINGf (chan, rgba[3]); + + if (MARK_RING(chan, 18, 2)) + return; + + BEGIN_RING(chan, tesla, NV50TCL_RT_CONTROL, 1); + OUT_RING (chan, 1); + BEGIN_RING(chan, tesla, NV50TCL_RT_ADDRESS_HIGH(0), 5); + OUT_RELOCh(chan, bo, ((struct nv50_surface *)dst)->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCl(chan, bo, ((struct nv50_surface *)dst)->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RING (chan, nv50_format_table[dst->format].rt); + OUT_RING (chan, mt->level[dst->u.tex.level].tile_mode << 4); + OUT_RING (chan, 0); + BEGIN_RING(chan, tesla, NV50TCL_RT_HORIZ(0), 2); + OUT_RING (chan, dst->width); + OUT_RING (chan, dst->height); + BEGIN_RING(chan, tesla, NV50TCL_RT_ARRAY_MODE, 1); + OUT_RING (chan, 1); + + /* NOTE: only works with D3D clear flag (5097/0x143c bit 4) */ + + BEGIN_RING(chan, tesla, NV50TCL_VIEWPORT_HORIZ(0), 2); + OUT_RING (chan, (width << 16) | dstx); + OUT_RING (chan, (height << 16) | dsty); + + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_BUFFERS, 1); + OUT_RING (chan, 0x3c); + + nv50->dirty |= NV50_NEW_FRAMEBUFFER; +} + +static void +nv50_clear_depth_stencil(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nv50_screen *screen = nv50->screen; + struct nouveau_channel *chan = screen->base.channel; + struct nouveau_grobj *tesla = screen->tesla; + struct nv50_miptree *mt = nv50_miptree(dst->texture); + struct nouveau_bo *bo = mt->base.bo; + uint32_t mode = 0; + + if (clear_flags & PIPE_CLEAR_DEPTH) { + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_DEPTH, 1); + OUT_RINGf (chan, depth); + mode |= NV50TCL_CLEAR_BUFFERS_Z; + } + + if (clear_flags & PIPE_CLEAR_STENCIL) { + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_STENCIL, 1); + OUT_RING (chan, stencil & 0xff); + mode |= NV50TCL_CLEAR_BUFFERS_S; + } + + if (MARK_RING(chan, 17, 2)) + return; + + BEGIN_RING(chan, tesla, NV50TCL_ZETA_ADDRESS_HIGH, 5); + OUT_RELOCh(chan, bo, ((struct nv50_surface *)dst)->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCl(chan, bo, ((struct nv50_surface *)dst)->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RING (chan, nv50_format_table[dst->format].rt); + OUT_RING (chan, mt->level[dst->u.tex.level].tile_mode << 4); + OUT_RING (chan, 0); + BEGIN_RING(chan, tesla, NV50TCL_ZETA_ENABLE, 1); + OUT_RING (chan, 1); + BEGIN_RING(chan, tesla, NV50TCL_ZETA_HORIZ, 3); + OUT_RING (chan, dst->width); + OUT_RING (chan, dst->height); + OUT_RING (chan, (1 << 16) | 1); + + BEGIN_RING(chan, tesla, NV50TCL_VIEWPORT_HORIZ(0), 2); + OUT_RING (chan, (width << 16) | dstx); + OUT_RING (chan, (height << 16) | dsty); + + BEGIN_RING(chan, tesla, NV50TCL_CLEAR_BUFFERS, 1); + OUT_RING (chan, mode); + + nv50->dirty |= NV50_NEW_FRAMEBUFFER; +} + +void +nv50_init_surface_functions(struct nv50_context *nv50) +{ + nv50->pipe.resource_copy_region = nv50_surface_copy; + nv50->pipe.clear_render_target = nv50_clear_render_target; + nv50->pipe.clear_depth_stencil = nv50_clear_depth_stencil; +} + + diff --git a/src/gallium/drivers/nv50/nv50_tex.c b/src/gallium/drivers/nv50/nv50_tex.c new file mode 100644 index 0000000..9243f9e --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_tex.c @@ -0,0 +1,237 @@ +/* + * Copyright 2008 Ben Skeggs + * + * 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 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 "nv50_context.h" +#include "nv50_texture.h" +#include "nv50_resource.h" + +#include "nouveau/nouveau_stateobj.h" +#include "nouveau/nouveau_reloc.h" + +#include "util/u_format.h" + +static INLINE uint32_t +nv50_tic_swizzle(uint32_t tc, unsigned swz) +{ + switch (swz) { + case PIPE_SWIZZLE_RED: + return (tc & NV50TIC_0_0_MAPR_MASK) >> NV50TIC_0_0_MAPR_SHIFT; + case PIPE_SWIZZLE_GREEN: + return (tc & NV50TIC_0_0_MAPG_MASK) >> NV50TIC_0_0_MAPG_SHIFT; + case PIPE_SWIZZLE_BLUE: + return (tc & NV50TIC_0_0_MAPB_MASK) >> NV50TIC_0_0_MAPB_SHIFT; + case PIPE_SWIZZLE_ALPHA: + return (tc & NV50TIC_0_0_MAPA_MASK) >> NV50TIC_0_0_MAPA_SHIFT; + case PIPE_SWIZZLE_ONE: + return 7; + case PIPE_SWIZZLE_ZERO: + default: + return 0; + } +} + +boolean +nv50_tex_construct(struct nv50_sampler_view *view) +{ + const struct util_format_description *desc; + struct nv50_miptree *mt = nv50_miptree(view->pipe.texture); + uint32_t swz[4], *tic = view->tic; + + tic[0] = nv50_format_table[view->pipe.format].tic; + + swz[0] = nv50_tic_swizzle(tic[0], view->pipe.swizzle_r); + swz[1] = nv50_tic_swizzle(tic[0], view->pipe.swizzle_g); + swz[2] = nv50_tic_swizzle(tic[0], view->pipe.swizzle_b); + swz[3] = nv50_tic_swizzle(tic[0], view->pipe.swizzle_a); + view->tic[0] = (tic[0] & ~NV50TIC_0_0_SWIZZLE_MASK) | + (swz[0] << NV50TIC_0_0_MAPR_SHIFT) | + (swz[1] << NV50TIC_0_0_MAPG_SHIFT) | + (swz[2] << NV50TIC_0_0_MAPB_SHIFT) | + (swz[3] << NV50TIC_0_0_MAPA_SHIFT); + + tic[2] = 0x50001000; + tic[2] |= ((mt->base.bo->tile_mode & 0x0f) << 22) | + ((mt->base.bo->tile_mode & 0xf0) << 21); + + desc = util_format_description(mt->base.base.format); + if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) + tic[2] |= NV50TIC_0_2_COLORSPACE_SRGB; + + switch (mt->base.base.target) { + case PIPE_TEXTURE_1D: + tic[2] |= NV50TIC_0_2_TARGET_1D; + break; + case PIPE_TEXTURE_2D: + tic[2] |= NV50TIC_0_2_TARGET_2D; + break; + case PIPE_TEXTURE_RECT: + tic[2] |= NV50TIC_0_2_TARGET_RECT; + break; + case PIPE_TEXTURE_3D: + tic[2] |= NV50TIC_0_2_TARGET_3D; + break; + case PIPE_TEXTURE_CUBE: + tic[2] |= NV50TIC_0_2_TARGET_CUBE; + break; + default: + NOUVEAU_ERR("invalid texture target: %d\n", + mt->base.base.target); + return FALSE; + } + + tic[3] = 0x00300000; + + tic[4] = (1 << 31) | mt->base.base.width0; + tic[5] = (mt->base.base.last_level << 28) | + (mt->base.base.depth0 << 16) | mt->base.base.height0; + + tic[6] = 0x03000000; + + tic[7] = (view->pipe.u.tex.last_level << 4) | view->pipe.u.tex.first_level; + + return TRUE; +} + +static int +nv50_validate_textures(struct nv50_context *nv50, struct nouveau_stateobj *so, + unsigned p) +{ + struct nouveau_grobj *eng2d = nv50->screen->eng2d; + struct nouveau_grobj *tesla = nv50->screen->tesla; + unsigned unit, j; + + const unsigned rll = NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_LOW; + const unsigned rlh = NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_HIGH + | NOUVEAU_BO_OR; + + nv50_so_init_sifc(nv50, so, nv50->screen->tic, NOUVEAU_BO_VRAM, + p * (32 * 8 * 4), nv50->sampler_view_nr[p] * 8 * 4); + + for (unit = 0; unit < nv50->sampler_view_nr[p]; ++unit) { + struct nv50_sampler_view *view = + nv50_sampler_view(nv50->sampler_views[p][unit]); + + so_method(so, eng2d, NV50_2D_SIFC_DATA | (2 << 29), 8); + if (view) { + uint32_t tic2 = view->tic[2]; + struct nv50_miptree *mt = + nv50_miptree(view->pipe.texture); + + tic2 &= ~NV50TIC_0_2_NORMALIZED_COORDS; + if (nv50->sampler[p][unit]->normalized) + tic2 |= NV50TIC_0_2_NORMALIZED_COORDS; + view->tic[2] = tic2; + + so_data (so, view->tic[0]); + so_reloc (so, mt->base.bo, 0, rll, 0, 0); + so_reloc (so, mt->base.bo, 0, rlh, tic2, tic2); + so_datap (so, &view->tic[3], 5); + + /* Set TEX insn $t src binding $unit in program type p + * to TIC, TSC entry (32 * p + unit), mark valid (1). + */ + so_method(so, tesla, NV50TCL_BIND_TIC(p), 1); + so_data (so, ((32 * p + unit) << 9) | (unit << 1) | 1); + } else { + for (j = 0; j < 8; ++j) + so_data(so, 0); + so_method(so, tesla, NV50TCL_BIND_TIC(p), 1); + so_data (so, (unit << 1) | 0); + } + } + + for (; unit < nv50->state.sampler_view_nr[p]; unit++) { + /* Make other bindings invalid. */ + so_method(so, tesla, NV50TCL_BIND_TIC(p), 1); + so_data (so, (unit << 1) | 0); + } + + nv50->state.sampler_view_nr[p] = nv50->sampler_view_nr[p]; + return TRUE; +} + +static void +nv50_emit_texture_relocs(struct nv50_context *nv50, int prog) +{ + struct nouveau_channel *chan = nv50->screen->base.channel; + struct nouveau_bo *tic = nv50->screen->tic; + int unit; + + for (unit = 0; unit < nv50->sampler_view_nr[prog]; unit++) { + struct nv50_sampler_view *view; + struct nv50_miptree *mt; + const unsigned base = ((prog * 32) + unit) * 32; + + view = nv50_sampler_view(nv50->sampler_views[prog][unit]); + if (!view) + continue; + mt = nv50_miptree(view->pipe.texture); + + nouveau_reloc_emit(chan, tic, base + 4, NULL, mt->base.bo, 0, 0, + NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | + NOUVEAU_BO_LOW, 0, 0); + nouveau_reloc_emit(chan, tic, base + 8, NULL, mt->base.bo, 0, 0, + NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | + NOUVEAU_BO_HIGH, view->tic[2], view->tic[2]); + } +} + +void +nv50_tex_relocs(struct nv50_context *nv50) +{ + nv50_emit_texture_relocs(nv50, 2); /* FP */ + nv50_emit_texture_relocs(nv50, 0); /* VP */ +} + +struct nouveau_stateobj * +nv50_tex_validate(struct nv50_context *nv50) +{ + struct nouveau_stateobj *so; + struct nouveau_grobj *tesla = nv50->screen->tesla; + unsigned p, m = 0, d = 0, r = 0; + + for (p = 0; p < 3; ++p) { + unsigned nr = MAX2(nv50->sampler_view_nr[p], + nv50->state.sampler_view_nr[p]); + m += nr; + d += nr; + r += nv50->sampler_view_nr[p]; + } + m = m * 2 + 3 * 4 + 1; + d = d * 9 + 3 * 19 + 1; + r = r * 2 + 3 * 2; + + so = so_new(m, d, r); + + if (nv50_validate_textures(nv50, so, 0) == FALSE || + nv50_validate_textures(nv50, so, 2) == FALSE) { + so_ref(NULL, &so); + + NOUVEAU_ERR("failed tex validate\n"); + return NULL; + } + + so_method(so, tesla, 0x1330, 1); /* flush TIC */ + so_data (so, 0); + + return so; +} diff --git a/src/gallium/drivers/nv50/nv50_texture.h b/src/gallium/drivers/nv50/nv50_texture.h new file mode 100644 index 0000000..b493994 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_texture.h @@ -0,0 +1,197 @@ +#ifndef __NV50_TEXTURE_H__ +#define __NV50_TEXTURE_H__ + +/* It'd be really nice to have these in nouveau_class.h generated by + * renouveau like the rest of the object header - but not sure it can + * handle non-object stuff nicely - need to look into it. + */ + +/* Texture image control block */ +#define NV50TIC_0_0_SWIZZLE_MASK 0x3ffc0000 +#define NV50TIC_0_0_MAPA_MASK 0x38000000 +#define NV50TIC_0_0_MAPA_SHIFT 27 +#define NV50TIC_0_0_MAPA_ZERO 0x00000000 +#define NV50TIC_0_0_MAPA_C0 0x10000000 +#define NV50TIC_0_0_MAPA_C1 0x18000000 +#define NV50TIC_0_0_MAPA_C2 0x20000000 +#define NV50TIC_0_0_MAPA_C3 0x28000000 +#define NV50TIC_0_0_MAPA_ONE 0x38000000 +#define NV50TIC_0_0_MAPB_MASK 0x07000000 +#define NV50TIC_0_0_MAPB_SHIFT 24 +#define NV50TIC_0_0_MAPB_ZERO 0x00000000 +#define NV50TIC_0_0_MAPB_C0 0x02000000 +#define NV50TIC_0_0_MAPB_C1 0x03000000 +#define NV50TIC_0_0_MAPB_C2 0x04000000 +#define NV50TIC_0_0_MAPB_C3 0x05000000 +#define NV50TIC_0_0_MAPB_ONE 0x07000000 +#define NV50TIC_0_0_MAPG_MASK 0x00e00000 +#define NV50TIC_0_0_MAPG_SHIFT 21 +#define NV50TIC_0_0_MAPG_ZERO 0x00000000 +#define NV50TIC_0_0_MAPG_C0 0x00400000 +#define NV50TIC_0_0_MAPG_C1 0x00600000 +#define NV50TIC_0_0_MAPG_C2 0x00800000 +#define NV50TIC_0_0_MAPG_C3 0x00a00000 +#define NV50TIC_0_0_MAPG_ONE 0x00e00000 +#define NV50TIC_0_0_MAPR_MASK 0x001c0000 +#define NV50TIC_0_0_MAPR_SHIFT 18 +#define NV50TIC_0_0_MAPR_ZERO 0x00000000 +#define NV50TIC_0_0_MAPR_C0 0x00080000 +#define NV50TIC_0_0_MAPR_C1 0x000c0000 +#define NV50TIC_0_0_MAPR_C2 0x00100000 +#define NV50TIC_0_0_MAPR_C3 0x00140000 +#define NV50TIC_0_0_MAPR_ONE 0x001c0000 +#define NV50TIC_0_0_TYPEA_MASK 0x00038000 +#define NV50TIC_0_0_TYPEA_UNORM 0x00010000 +#define NV50TIC_0_0_TYPEA_SNORM 0x00008000 +#define NV50TIC_0_0_TYPEA_SINT 0x00018000 +#define NV50TIC_0_0_TYPEA_UINT 0x00020000 +#define NV50TIC_0_0_TYPEA_SSCALED 0x00028000 +#define NV50TIC_0_0_TYPEA_USCALED 0x00030000 +#define NV50TIC_0_0_TYPEA_FLOAT 0x00038000 +#define NV50TIC_0_0_TYPEB_MASK 0x00007000 +#define NV50TIC_0_0_TYPEB_UNORM 0x00002000 +#define NV50TIC_0_0_TYPEB_SNORM 0x00001000 +#define NV50TIC_0_0_TYPEB_SINT 0x00003000 +#define NV50TIC_0_0_TYPEB_UINT 0x00004000 +#define NV50TIC_0_0_TYPEB_SSCALED 0x00005000 +#define NV50TIC_0_0_TYPEB_USCALED 0x00006000 +#define NV50TIC_0_0_TYPEB_FLOAT 0x00007000 +#define NV50TIC_0_0_TYPEG_MASK 0x00000e00 +#define NV50TIC_0_0_TYPEG_UNORM 0x00000400 +#define NV50TIC_0_0_TYPEG_SNORM 0x00000200 +#define NV50TIC_0_0_TYPEG_SINT 0x00000600 +#define NV50TIC_0_0_TYPEG_UINT 0x00000800 +#define NV50TIC_0_0_TYPEG_SSCALED 0x00000a00 +#define NV50TIC_0_0_TYPEG_USCALED 0x00000c00 +#define NV50TIC_0_0_TYPEG_FLOAT 0x00000e00 +#define NV50TIC_0_0_TYPER_MASK 0x000001c0 +#define NV50TIC_0_0_TYPER_UNORM 0x00000080 +#define NV50TIC_0_0_TYPER_SNORM 0x00000040 +#define NV50TIC_0_0_TYPER_SINT 0x000000c0 +#define NV50TIC_0_0_TYPER_UINT 0x00000100 +#define NV50TIC_0_0_TYPER_SSCALED 0x00000140 +#define NV50TIC_0_0_TYPER_USCALED 0x00000180 +#define NV50TIC_0_0_TYPER_FLOAT 0x000001c0 +#define NV50TIC_0_0_FMT_MASK 0x0000003f +#define NV50TIC_0_0_FMT_32_32_32_32 0x00000001 +#define NV50TIC_0_0_FMT_16_16_16_16 0x00000003 +#define NV50TIC_0_0_FMT_32_32 0x00000004 +#define NV50TIC_0_0_FMT_8_8_8_8 0x00000008 +#define NV50TIC_0_0_FMT_2_10_10_10 0x00000009 +#define NV50TIC_0_0_FMT_16_16 0x0000000c +#define NV50TIC_0_0_FMT_32 0x0000000f +#define NV50TIC_0_0_FMT_4_4_4_4 0x00000012 +/* #define NV50TIC_0_0_FMT_1_5_5_5 0x00000013 */ +#define NV50TIC_0_0_FMT_1_5_5_5 0x00000014 +#define NV50TIC_0_0_FMT_5_6_5 0x00000015 +#define NV50TIC_0_0_FMT_8_8 0x00000018 +#define NV50TIC_0_0_FMT_16 0x0000001b +#define NV50TIC_0_0_FMT_8 0x0000001d +#define NV50TIC_0_0_FMT_5_9_9_9 0x00000020 +#define NV50TIC_0_0_FMT_10_11_11 0x00000021 +#define NV50TIC_0_0_FMT_DXT1 0x00000024 +#define NV50TIC_0_0_FMT_DXT3 0x00000025 +#define NV50TIC_0_0_FMT_DXT5 0x00000026 +#define NV50TIC_0_0_FMT_RGTC1 0x00000027 +#define NV50TIC_0_0_FMT_RGTC2 0x00000028 +#define NV50TIC_0_0_FMT_24_8 0x00000029 +#define NV50TIC_0_0_FMT_8_24 0x0000002a +#define NV50TIC_0_0_FMT_32_DEPTH 0x0000002f +#define NV50TIC_0_0_FMT_32_8 0x00000030 +#define NV50TIC_0_0_FMT_16_DEPTH 0x0000003a + +#define NV50TIC_0_1_OFFSET_LOW_MASK 0xffffffff +#define NV50TIC_0_1_OFFSET_LOW_SHIFT 0 + +#define NV50TIC_0_2_COLORSPACE_SRGB 0x00000400 +#define NV50TIC_0_2_TARGET_1D 0x00000000 +#define NV50TIC_0_2_TARGET_2D 0x00004000 +#define NV50TIC_0_2_TARGET_3D 0x00008000 +#define NV50TIC_0_2_TARGET_CUBE 0x0000c000 +#define NV50TIC_0_2_TARGET_1D_ARRAY 0x00010000 +#define NV50TIC_0_2_TARGET_2D_ARRAY 0x00014000 +#define NV50TIC_0_2_TARGET_BUFFER 0x00018000 +#define NV50TIC_0_2_TARGET_RECT 0x0001c000 +/* #define NV50TIC_0_0_TILE_MODE_LINEAR 0x00040000 */ +#define NV50TIC_0_2_TILE_MODE_Y_MASK 0x01c00000 +#define NV50TIC_0_2_TILE_MODE_Y_SHIFT 22 +#define NV50TIC_0_2_TILE_MODE_Z_MASK 0x0e000000 +#define NV50TIC_0_2_TILE_MODE_Z_SHIFT 25 +#define NV50TIC_0_2_NORMALIZED_COORDS 0x80000000 + +#define NV50TIC_0_3_UNKNOWN_MASK 0xffffffff + +#define NV50TIC_0_4_WIDTH_MASK 0x0000ffff +#define NV50TIC_0_4_WIDTH_SHIFT 0 + +#define NV50TIC_0_5_LAST_LEVEL_MASK 0xf0000000 +#define NV50TIC_0_5_LAST_LEVEL_SHIFT 28 +#define NV50TIC_0_5_DEPTH_MASK 0x0fff0000 +#define NV50TIC_0_5_DEPTH_SHIFT 16 +#define NV50TIC_0_5_HEIGHT_MASK 0x0000ffff +#define NV50TIC_0_5_HEIGHT_SHIFT 0 +#define NV50TIC_0_6_UNKNOWN_MASK 0xffffffff + +#define NV50TIC_0_7_BASE_LEVEL_MASK 0x0000000f +#define NV50TIC_0_7_BASE_LEVEL_SHIFT 0 +#define NV50TIC_0_7_MAX_LEVEL_MASK 0x000000f0 +#define NV50TIC_0_7_MAX_LEVEL_SHIFT 4 + +/* Texture sampler control block */ +#define NV50TSC_1_0_WRAPS_MASK 0x00000007 +#define NV50TSC_1_0_WRAPS_REPEAT 0x00000000 +#define NV50TSC_1_0_WRAPS_MIRROR_REPEAT 0x00000001 +#define NV50TSC_1_0_WRAPS_CLAMP_TO_EDGE 0x00000002 +#define NV50TSC_1_0_WRAPS_CLAMP_TO_BORDER 0x00000003 +#define NV50TSC_1_0_WRAPS_CLAMP 0x00000004 +#define NV50TSC_1_0_WRAPS_MIRROR_CLAMP_TO_EDGE 0x00000005 +#define NV50TSC_1_0_WRAPS_MIRROR_CLAMP_TO_BORDER 0x00000006 +#define NV50TSC_1_0_WRAPS_MIRROR_CLAMP 0x00000007 +#define NV50TSC_1_0_WRAPT_MASK 0x00000038 +#define NV50TSC_1_0_WRAPT_REPEAT 0x00000000 +#define NV50TSC_1_0_WRAPT_MIRROR_REPEAT 0x00000008 +#define NV50TSC_1_0_WRAPT_CLAMP_TO_EDGE 0x00000010 +#define NV50TSC_1_0_WRAPT_CLAMP_TO_BORDER 0x00000018 +#define NV50TSC_1_0_WRAPT_CLAMP 0x00000020 +#define NV50TSC_1_0_WRAPT_MIRROR_CLAMP_TO_EDGE 0x00000028 +#define NV50TSC_1_0_WRAPT_MIRROR_CLAMP_TO_BORDER 0x00000030 +#define NV50TSC_1_0_WRAPT_MIRROR_CLAMP 0x00000038 +#define NV50TSC_1_0_WRAPR_MASK 0x000001c0 +#define NV50TSC_1_0_WRAPR_REPEAT 0x00000000 +#define NV50TSC_1_0_WRAPR_MIRROR_REPEAT 0x00000040 +#define NV50TSC_1_0_WRAPR_CLAMP_TO_EDGE 0x00000080 +#define NV50TSC_1_0_WRAPR_CLAMP_TO_BORDER 0x000000c0 +#define NV50TSC_1_0_WRAPR_CLAMP 0x00000100 +#define NV50TSC_1_0_WRAPR_MIRROR_CLAMP_TO_EDGE 0x00000140 +#define NV50TSC_1_0_WRAPR_MIRROR_CLAMP_TO_BORDER 0x00000180 +#define NV50TSC_1_0_WRAPR_MIRROR_CLAMP 0x000001c0 +#define NV50TSC_1_0_MAX_ANISOTROPY_MASK 0x00700000 + +#define NV50TSC_1_1_MAGF_MASK 0x00000003 +#define NV50TSC_1_1_MAGF_NEAREST 0x00000001 +#define NV50TSC_1_1_MAGF_LINEAR 0x00000002 +#define NV50TSC_1_1_MINF_MASK 0x00000030 +#define NV50TSC_1_1_MINF_NEAREST 0x00000010 +#define NV50TSC_1_1_MINF_LINEAR 0x00000020 +#define NV50TSC_1_1_MIPF_MASK 0x000000c0 +#define NV50TSC_1_1_MIPF_NONE 0x00000040 +#define NV50TSC_1_1_MIPF_NEAREST 0x00000080 +#define NV50TSC_1_1_MIPF_LINEAR 0x000000c0 +#define NV50TSC_1_1_LOD_BIAS_MASK 0x01fff000 +#define NV50TSC_1_1_UNKN_ANISO_15 0x10000000 +#define NV50TSC_1_1_UNKN_ANISO_35 0x18000000 + +#define NV50TSC_1_2_MIN_LOD_MASK 0x00000f00 +#define NV50TSC_1_2_MAX_LOD_MASK 0x00f00000 + +#define NV50TSC_1_3_UNKNOWN_MASK 0xffffffff + +#define NV50TSC_1_4_BORDER_COLOR_RED_MASK 0xffffffff + +#define NV50TSC_1_5_BORDER_COLOR_GREEN_MASK 0xffffffff + +#define NV50TSC_1_6_BORDER_COLOR_BLUE_MASK 0xffffffff + +#define NV50TSC_1_7_BORDER_COLOR_ALPHA_MASK 0xffffffff + +#endif diff --git a/src/gallium/drivers/nv50/nv50_tgsi_to_nc.c b/src/gallium/drivers/nv50/nv50_tgsi_to_nc.c new file mode 100644 index 0000000..ce9300a --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_tgsi_to_nc.c @@ -0,0 +1,2051 @@ +/* + * Copyright 2010 Christoph Bumiller + * + * 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 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 NV50_TGSI2NC_DEBUG */ + +#include + +#include "nv50_context.h" +#include "nv50_pc.h" + +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" + +#include "tgsi/tgsi_dump.h" + +#define BLD_MAX_TEMPS 64 +#define BLD_MAX_ADDRS 4 +#define BLD_MAX_PREDS 4 +#define BLD_MAX_IMMDS 128 + +#define BLD_MAX_COND_NESTING 8 +#define BLD_MAX_LOOP_NESTING 4 +#define BLD_MAX_CALL_NESTING 2 + +/* collects all values assigned to the same TGSI register */ +struct bld_value_stack { + struct nv_value *top; + struct nv_value **body; + unsigned size; + uint16_t loop_use; /* 1 bit per loop level, indicates if used/defd */ + uint16_t loop_def; +}; + +static INLINE void +bld_vals_push_val(struct bld_value_stack *stk, struct nv_value *val) +{ + assert(!stk->size || (stk->body[stk->size - 1] != val)); + + if (!(stk->size % 8)) { + unsigned old_sz = (stk->size + 0) * sizeof(struct nv_value *); + unsigned new_sz = (stk->size + 8) * sizeof(struct nv_value *); + stk->body = (struct nv_value **)REALLOC(stk->body, old_sz, new_sz); + } + stk->body[stk->size++] = val; +} + +static INLINE boolean +bld_vals_del_val(struct bld_value_stack *stk, struct nv_value *val) +{ + unsigned i; + + for (i = stk->size; i > 0; --i) + if (stk->body[i - 1] == val) + break; + if (!i) + return FALSE; + + if (i != stk->size) + stk->body[i - 1] = stk->body[stk->size - 1]; + + --stk->size; /* XXX: old size in REALLOC */ + return TRUE; +} + +static INLINE void +bld_vals_push(struct bld_value_stack *stk) +{ + bld_vals_push_val(stk, stk->top); + stk->top = NULL; +} + +static INLINE void +bld_push_values(struct bld_value_stack *stacks, int n) +{ + int i, c; + + for (i = 0; i < n; ++i) + for (c = 0; c < 4; ++c) + if (stacks[i * 4 + c].top) + bld_vals_push(&stacks[i * 4 + c]); +} + +struct bld_context { + struct nv50_translation_info *ti; + + struct nv_pc *pc; + struct nv_basic_block *b; + + struct tgsi_parse_context parse[BLD_MAX_CALL_NESTING]; + int call_lvl; + + struct nv_basic_block *cond_bb[BLD_MAX_COND_NESTING]; + struct nv_basic_block *join_bb[BLD_MAX_COND_NESTING]; + struct nv_basic_block *else_bb[BLD_MAX_COND_NESTING]; + int cond_lvl; + struct nv_basic_block *loop_bb[BLD_MAX_LOOP_NESTING]; + struct nv_basic_block *brkt_bb[BLD_MAX_LOOP_NESTING]; + int loop_lvl; + + ubyte out_kind; /* CFG_EDGE_FORWARD, or FAKE in case of BREAK/CONT */ + + struct bld_value_stack tvs[BLD_MAX_TEMPS][4]; /* TGSI_FILE_TEMPORARY */ + struct bld_value_stack avs[BLD_MAX_ADDRS][4]; /* TGSI_FILE_ADDRESS */ + struct bld_value_stack pvs[BLD_MAX_PREDS][4]; /* TGSI_FILE_PREDICATE */ + struct bld_value_stack ovs[PIPE_MAX_SHADER_OUTPUTS][4]; + + uint32_t outputs_written[(PIPE_MAX_SHADER_OUTPUTS + 7) / 8]; + + struct nv_value *frgcrd[4]; + struct nv_value *sysval[4]; + + /* wipe on new BB */ + struct nv_value *saved_addr[4][2]; + struct nv_value *saved_inputs[128]; + struct nv_value *saved_immd[BLD_MAX_IMMDS]; + uint num_immds; +}; + +static INLINE ubyte +bld_stack_file(struct bld_context *bld, struct bld_value_stack *stk) +{ + if (stk < &bld->avs[0][0]) + return NV_FILE_GPR; + else + if (stk < &bld->pvs[0][0]) + return NV_FILE_ADDR; + else + if (stk < &bld->ovs[0][0]) + return NV_FILE_FLAGS; + else + return NV_FILE_OUT; +} + +static INLINE struct nv_value * +bld_fetch(struct bld_context *bld, struct bld_value_stack *stk, int i, int c) +{ + stk[i * 4 + c].loop_use |= 1 << bld->loop_lvl; + + return stk[i * 4 + c].top; +} + +static struct nv_value * +bld_loop_phi(struct bld_context *, struct bld_value_stack *, struct nv_value *); + +/* If a variable is defined in a loop without prior use, we don't need + * a phi in the loop header to account for backwards flow. + * + * However, if this variable is then also used outside the loop, we do + * need a phi after all. But we must not use this phi's def inside the + * loop, so we can eliminate the phi if it is unused later. + */ +static INLINE void +bld_store(struct bld_context *bld, struct bld_value_stack *stk, int i, int c, + struct nv_value *val) +{ + const uint16_t m = 1 << bld->loop_lvl; + + stk = &stk[i * 4 + c]; + + if (bld->loop_lvl && !(m & (stk->loop_def | stk->loop_use))) + bld_loop_phi(bld, stk, val); + + stk->top = val; + stk->loop_def |= 1 << bld->loop_lvl; +} + +static INLINE void +bld_clear_def_use(struct bld_value_stack *stk, int n, int lvl) +{ + int i; + const uint16_t mask = ~(1 << lvl); + + for (i = 0; i < n * 4; ++i) { + stk[i].loop_def &= mask; + stk[i].loop_use &= mask; + } +} + +#define FETCH_TEMP(i, c) bld_fetch(bld, &bld->tvs[0][0], i, c) +#define STORE_TEMP(i, c, v) bld_store(bld, &bld->tvs[0][0], i, c, (v)) +#define FETCH_ADDR(i, c) bld_fetch(bld, &bld->avs[0][0], i, c) +#define STORE_ADDR(i, c, v) bld_store(bld, &bld->avs[0][0], i, c, (v)) +#define FETCH_PRED(i, c) bld_fetch(bld, &bld->pvs[0][0], i, c) +#define STORE_PRED(i, c, v) bld_store(bld, &bld->pvs[0][0], i, c, (v)) + +#define STORE_OUTR(i, c, v) \ + do { \ + bld->ovs[i][c].top = (v); \ + bld->outputs_written[(i) / 8] |= 1 << (((i) * 4 + (c)) % 32); \ + } while (0) + +static INLINE void +bld_warn_uninitialized(struct bld_context *bld, int kind, + struct bld_value_stack *stk, struct nv_basic_block *b) +{ +#ifdef NV50_TGSI2NC_DEBUG + long i = (stk - &bld->tvs[0][0]) / 4; + long c = (stk - &bld->tvs[0][0]) & 3; + + if (c == 3) + c = -1; + + debug_printf("WARNING: TEMP[%li].%c %s used uninitialized in BB:%i\n", + i, (int)('x' + c), kind ? "may be" : "is", b->id); +#endif +} + +static INLINE struct nv_value * +bld_def(struct nv_instruction *i, int c, struct nv_value *value) +{ + i->def[c] = value; + value->insn = i; + return value; +} + +static INLINE struct nv_value * +find_by_bb(struct bld_value_stack *stack, struct nv_basic_block *b) +{ + int i; + + if (stack->top && stack->top->insn->bb == b) + return stack->top; + + for (i = stack->size - 1; i >= 0; --i) + if (stack->body[i]->insn->bb == b) + return stack->body[i]; + return NULL; +} + +/* fetch value from stack that was defined in the specified basic block, + * or search for first definitions in all of its predecessors + */ +static void +fetch_by_bb(struct bld_value_stack *stack, + struct nv_value **vals, int *n, + struct nv_basic_block *b) +{ + int i; + struct nv_value *val; + + assert(*n < 16); /* MAX_COND_NESTING */ + + val = find_by_bb(stack, b); + if (val) { + for (i = 0; i < *n; ++i) + if (vals[i] == val) + return; + vals[(*n)++] = val; + return; + } + for (i = 0; i < b->num_in; ++i) + if (!IS_WALL_EDGE(b->in_kind[i])) + fetch_by_bb(stack, vals, n, b->in[i]); +} + +static INLINE struct nv_value * +bld_load_imm_u32(struct bld_context *bld, uint32_t u); + +static INLINE struct nv_value * +bld_undef(struct bld_context *bld, ubyte file) +{ + struct nv_instruction *nvi = new_instruction(bld->pc, NV_OP_UNDEF); + + return bld_def(nvi, 0, new_value(bld->pc, file, NV_TYPE_U32)); +} + +static struct nv_value * +bld_phi(struct bld_context *bld, struct nv_basic_block *b, + struct bld_value_stack *stack) +{ + struct nv_basic_block *in; + struct nv_value *vals[16] = { 0 }; + struct nv_value *val; + struct nv_instruction *phi; + int i, j, n; + + do { + i = n = 0; + fetch_by_bb(stack, vals, &n, b); + + if (!n) { + bld_warn_uninitialized(bld, 0, stack, b); + return NULL; + } + + if (n == 1) { + if (nvbb_dominated_by(b, vals[0]->insn->bb)) + break; + + bld_warn_uninitialized(bld, 1, stack, b); + + /* back-tracking to insert missing value of other path */ + in = b; + while (in->in[0]) { + if (in->num_in == 1) { + in = in->in[0]; + } else { + if (!nvbb_reachable_by(in->in[0], vals[0]->insn->bb, b)) + in = in->in[0]; + else + if (!nvbb_reachable_by(in->in[1], vals[0]->insn->bb, b)) + in = in->in[1]; + else + in = in->in[0]; + } + } + bld->pc->current_block = in; + + /* should make this a no-op */ + bld_vals_push_val(stack, bld_undef(bld, vals[0]->reg.file)); + continue; + } + + for (i = 0; i < n; ++i) { + /* if value dominates b, continue to the redefinitions */ + if (nvbb_dominated_by(b, vals[i]->insn->bb)) + continue; + + /* if value dominates any in-block, b should be the dom frontier */ + for (j = 0; j < b->num_in; ++j) + if (nvbb_dominated_by(b->in[j], vals[i]->insn->bb)) + break; + /* otherwise, find the dominance frontier and put the phi there */ + if (j == b->num_in) { + in = nvbb_dom_frontier(vals[i]->insn->bb); + val = bld_phi(bld, in, stack); + bld_vals_push_val(stack, val); + break; + } + } + } while(i < n); + + bld->pc->current_block = b; + + if (n == 1) + return vals[0]; + + phi = new_instruction(bld->pc, NV_OP_PHI); + + bld_def(phi, 0, new_value(bld->pc, vals[0]->reg.file, vals[0]->reg.type)); + for (i = 0; i < n; ++i) + phi->src[i] = new_ref(bld->pc, vals[i]); + + return phi->def[0]; +} + +/* Insert a phi function in the loop header. + * For nested loops, we need to insert phi functions in all the outer + * loop headers if they don't have one yet. + * + * @def: redefinition from inside loop, or NULL if to be replaced later + */ +static struct nv_value * +bld_loop_phi(struct bld_context *bld, struct bld_value_stack *stack, + struct nv_value *def) +{ + struct nv_instruction *phi; + struct nv_basic_block *bb = bld->pc->current_block; + struct nv_value *val = NULL; + + if (bld->loop_lvl > 1) { + --bld->loop_lvl; + if (!((stack->loop_def | stack->loop_use) & (1 << bld->loop_lvl))) + val = bld_loop_phi(bld, stack, NULL); + ++bld->loop_lvl; + } + + if (!val) + val = bld_phi(bld, bld->pc->current_block, stack); /* old definition */ + if (!val) { + bld->pc->current_block = bld->loop_bb[bld->loop_lvl - 1]->in[0]; + val = bld_undef(bld, bld_stack_file(bld, stack)); + } + + bld->pc->current_block = bld->loop_bb[bld->loop_lvl - 1]; + + phi = new_instruction(bld->pc, NV_OP_PHI); + + bld_def(phi, 0, new_value_like(bld->pc, val)); + if (!def) + def = phi->def[0]; + + bld_vals_push_val(stack, phi->def[0]); + + phi->target = (struct nv_basic_block *)stack; /* cheat */ + + nv_reference(bld->pc, &phi->src[0], val); + nv_reference(bld->pc, &phi->src[1], def); + + bld->pc->current_block = bb; + + return phi->def[0]; +} + +static INLINE struct nv_value * +bld_fetch_global(struct bld_context *bld, struct bld_value_stack *stack) +{ + const uint16_t m = 1 << bld->loop_lvl; + const uint16_t use = stack->loop_use; + + stack->loop_use |= m; + + /* If neither used nor def'd inside the loop, build a phi in foresight, + * so we don't have to replace stuff later on, which requires tracking. + */ + if (bld->loop_lvl && !((use | stack->loop_def) & m)) + return bld_loop_phi(bld, stack, NULL); + + return bld_phi(bld, bld->pc->current_block, stack); +} + +static INLINE struct nv_value * +bld_imm_u32(struct bld_context *bld, uint32_t u) +{ + int i; + unsigned n = bld->num_immds; + + for (i = 0; i < n; ++i) + if (bld->saved_immd[i]->reg.imm.u32 == u) + return bld->saved_immd[i]; + assert(n < BLD_MAX_IMMDS); + + bld->num_immds++; + + bld->saved_immd[n] = new_value(bld->pc, NV_FILE_IMM, NV_TYPE_U32); + bld->saved_immd[n]->reg.imm.u32 = u; + return bld->saved_immd[n]; +} + +static void +bld_replace_value(struct nv_pc *, struct nv_basic_block *, struct nv_value *, + struct nv_value *); + +/* Replace the source of the phi in the loop header by the last assignment, + * or eliminate the phi function if there is no assignment inside the loop. + * + * Redundancy situation 1 - (used) but (not redefined) value: + * %3 = phi %0, %3 = %3 is used + * %3 = phi %0, %4 = is new definition + * + * Redundancy situation 2 - (not used) but (redefined) value: + * %3 = phi %0, %2 = %2 is used, %3 could be used outside, deleted by DCE + */ +static void +bld_loop_end(struct bld_context *bld, struct nv_basic_block *bb) +{ + struct nv_basic_block *save = bld->pc->current_block; + struct nv_instruction *phi, *next; + struct nv_value *val; + struct bld_value_stack *stk; + int i, s, n; + + for (phi = bb->phi; phi && phi->opcode == NV_OP_PHI; phi = next) { + next = phi->next; + + stk = (struct bld_value_stack *)phi->target; + phi->target = NULL; + + for (s = 1, n = 0; n < bb->num_in; ++n) { + if (bb->in_kind[n] != CFG_EDGE_BACK) + continue; + + assert(s < 4); + bld->pc->current_block = bb->in[n]; + val = bld_fetch_global(bld, stk); + + for (i = 0; i < 4; ++i) + if (phi->src[i] && phi->src[i]->value == val) + break; + if (i == 4) + nv_reference(bld->pc, &phi->src[s++], val); + } + bld->pc->current_block = save; + + if (phi->src[0]->value == phi->def[0] || + phi->src[0]->value == phi->src[1]->value) + s = 1; + else + if (phi->src[1]->value == phi->def[0]) + s = 0; + else + continue; + + if (s >= 0) { + /* eliminate the phi */ + bld_vals_del_val(stk, phi->def[0]); + + ++bld->pc->pass_seq; + bld_replace_value(bld->pc, bb, phi->def[0], phi->src[s]->value); + + nv_nvi_delete(phi); + } + } +} + +static INLINE struct nv_value * +bld_imm_f32(struct bld_context *bld, float f) +{ + return bld_imm_u32(bld, fui(f)); +} + +#define SET_TYPE(v, t) ((v)->reg.type = (v)->reg.as_type = (t)) + +static struct nv_value * +bld_insn_1(struct bld_context *bld, uint opcode, struct nv_value *src0) +{ + struct nv_instruction *insn = new_instruction(bld->pc, opcode); + + nv_reference(bld->pc, &insn->src[0], src0); + + return bld_def(insn, 0, new_value(bld->pc, NV_FILE_GPR, src0->reg.as_type)); +} + +static struct nv_value * +bld_insn_2(struct bld_context *bld, uint opcode, + struct nv_value *src0, struct nv_value *src1) +{ + struct nv_instruction *insn = new_instruction(bld->pc, opcode); + + nv_reference(bld->pc, &insn->src[0], src0); + nv_reference(bld->pc, &insn->src[1], src1); + + return bld_def(insn, 0, new_value(bld->pc, NV_FILE_GPR, src0->reg.as_type)); +} + +static struct nv_value * +bld_insn_3(struct bld_context *bld, uint opcode, + struct nv_value *src0, struct nv_value *src1, + struct nv_value *src2) +{ + struct nv_instruction *insn = new_instruction(bld->pc, opcode); + + nv_reference(bld->pc, &insn->src[0], src0); + nv_reference(bld->pc, &insn->src[1], src1); + nv_reference(bld->pc, &insn->src[2], src2); + + return bld_def(insn, 0, new_value(bld->pc, NV_FILE_GPR, src0->reg.as_type)); +} + +static struct nv_value * +bld_duplicate_insn(struct bld_context *bld, struct nv_instruction *nvi) +{ + struct nv_instruction *dupi = new_instruction(bld->pc, nvi->opcode); + int c; + + if (nvi->def[0]) + bld_def(dupi, 0, new_value_like(bld->pc, nvi->def[0])); + + if (nvi->flags_def) { + dupi->flags_def = new_value_like(bld->pc, nvi->flags_def); + dupi->flags_def->insn = dupi; + } + + for (c = 0; c < 5; ++c) + if (nvi->src[c]) + nv_reference(bld->pc, &dupi->src[c], nvi->src[c]->value); + if (nvi->flags_src) + nv_reference(bld->pc, &dupi->flags_src, nvi->flags_src->value); + + dupi->cc = nvi->cc; + dupi->saturate = nvi->saturate; + dupi->centroid = nvi->centroid; + dupi->flat = nvi->flat; + + return dupi->def[0]; +} + +static void +bld_lmem_store(struct bld_context *bld, struct nv_value *ptr, int ofst, + struct nv_value *val) +{ + struct nv_instruction *insn = new_instruction(bld->pc, NV_OP_STA); + struct nv_value *loc; + + loc = new_value(bld->pc, NV_FILE_MEM_L, NV_TYPE_U32); + + loc->reg.id = ofst * 4; + + nv_reference(bld->pc, &insn->src[0], loc); + nv_reference(bld->pc, &insn->src[1], val); + nv_reference(bld->pc, &insn->src[4], ptr); +} + +static struct nv_value * +bld_lmem_load(struct bld_context *bld, struct nv_value *ptr, int ofst) +{ + struct nv_value *loc, *val; + + loc = new_value(bld->pc, NV_FILE_MEM_L, NV_TYPE_U32); + + loc->reg.id = ofst * 4; + + val = bld_insn_1(bld, NV_OP_LDA, loc); + + nv_reference(bld->pc, &val->insn->src[4], ptr); + + return val; +} + +#define BLD_INSN_1_EX(d, op, dt, s0, s0t) \ + do { \ + (d) = bld_insn_1(bld, (NV_OP_##op), (s0)); \ + SET_TYPE(d, NV_TYPE_##dt); \ + (d)->insn->src[0]->typecast = NV_TYPE_##s0t; \ + } while(0) + +#define BLD_INSN_2_EX(d, op, dt, s0, s0t, s1, s1t) \ + do { \ + (d) = bld_insn_2(bld, (NV_OP_##op), (s0), (s1)); \ + SET_TYPE(d, NV_TYPE_##dt); \ + (d)->insn->src[0]->typecast = NV_TYPE_##s0t; \ + (d)->insn->src[1]->typecast = NV_TYPE_##s1t; \ + } while(0) + +static struct nv_value * +bld_pow(struct bld_context *bld, struct nv_value *x, struct nv_value *e) +{ + struct nv_value *val; + + BLD_INSN_1_EX(val, LG2, F32, x, F32); + BLD_INSN_2_EX(val, MUL, F32, e, F32, val, F32); + val = bld_insn_1(bld, NV_OP_PREEX2, val); + val = bld_insn_1(bld, NV_OP_EX2, val); + + return val; +} + +static INLINE struct nv_value * +bld_load_imm_f32(struct bld_context *bld, float f) +{ + struct nv_value *imm = bld_insn_1(bld, NV_OP_MOV, bld_imm_f32(bld, f)); + + SET_TYPE(imm, NV_TYPE_F32); + return imm; +} + +static INLINE struct nv_value * +bld_load_imm_u32(struct bld_context *bld, uint32_t u) +{ + return bld_insn_1(bld, NV_OP_MOV, bld_imm_u32(bld, u)); +} + +static struct nv_value * +bld_get_address(struct bld_context *bld, int id, struct nv_value *indirect) +{ + int i; + struct nv_instruction *nvi; + struct nv_value *val; + + for (i = 0; i < 4; ++i) { + if (!bld->saved_addr[i][0]) + break; + if (bld->saved_addr[i][1] == indirect) { + nvi = bld->saved_addr[i][0]->insn; + if (nvi->src[0]->value->reg.imm.u32 == id) + return bld->saved_addr[i][0]; + } + } + i &= 3; + + val = bld_imm_u32(bld, id); + if (indirect) + val = bld_insn_2(bld, NV_OP_ADD, indirect, val); + else + val = bld_insn_1(bld, NV_OP_MOV, val); + + bld->saved_addr[i][0] = val; + bld->saved_addr[i][0]->reg.file = NV_FILE_ADDR; + bld->saved_addr[i][0]->reg.type = NV_TYPE_U16; + bld->saved_addr[i][1] = indirect; + return bld->saved_addr[i][0]; +} + + +static struct nv_value * +bld_predicate(struct bld_context *bld, struct nv_value *src, boolean bool_only) +{ + struct nv_instruction *s0i, *nvi = src->insn; + + if (!nvi) { + nvi = bld_insn_1(bld, + (src->reg.file == NV_FILE_IMM) ? NV_OP_MOV : NV_OP_LDA, + src)->insn; + src = nvi->def[0]; + } else + if (bool_only) { + while (nvi->opcode == NV_OP_ABS || nvi->opcode == NV_OP_NEG || + nvi->opcode == NV_OP_CVT) { + s0i = nvi->src[0]->value->insn; + if (!s0i || !nv50_op_can_write_flags(s0i->opcode)) + break; + nvi = s0i; + assert(!nvi->flags_src); + } + } + + if (!nv50_op_can_write_flags(nvi->opcode) || + nvi->bb != bld->pc->current_block) { + nvi = new_instruction(bld->pc, NV_OP_CVT); + nv_reference(bld->pc, &nvi->src[0], src); + } + + if (!nvi->flags_def) { + nvi->flags_def = new_value(bld->pc, NV_FILE_FLAGS, NV_TYPE_U16); + nvi->flags_def->insn = nvi; + } + return nvi->flags_def; +} + +static void +bld_kil(struct bld_context *bld, struct nv_value *src) +{ + struct nv_instruction *nvi; + + src = bld_predicate(bld, src, FALSE); + nvi = new_instruction(bld->pc, NV_OP_KIL); + nvi->fixed = 1; + nvi->flags_src = new_ref(bld->pc, src); + nvi->cc = NV_CC_LT; +} + +static void +bld_flow(struct bld_context *bld, uint opcode, ubyte cc, + struct nv_value *src, struct nv_basic_block *target, + boolean plan_reconverge) +{ + struct nv_instruction *nvi; + + if (plan_reconverge) + new_instruction(bld->pc, NV_OP_JOINAT)->fixed = 1; + + nvi = new_instruction(bld->pc, opcode); + nvi->is_terminator = 1; + nvi->cc = cc; + nvi->target = target; + if (src) + nvi->flags_src = new_ref(bld->pc, src); +} + +static ubyte +translate_setcc(unsigned opcode) +{ + switch (opcode) { + case TGSI_OPCODE_SLT: return NV_CC_LT; + case TGSI_OPCODE_SGE: return NV_CC_GE; + case TGSI_OPCODE_SEQ: return NV_CC_EQ; + case TGSI_OPCODE_SGT: return NV_CC_GT; + case TGSI_OPCODE_SLE: return NV_CC_LE; + case TGSI_OPCODE_SNE: return NV_CC_NE | NV_CC_U; + case TGSI_OPCODE_STR: return NV_CC_TR; + case TGSI_OPCODE_SFL: return NV_CC_FL; + + case TGSI_OPCODE_ISLT: return NV_CC_LT; + case TGSI_OPCODE_ISGE: return NV_CC_GE; + case TGSI_OPCODE_USEQ: return NV_CC_EQ; + case TGSI_OPCODE_USGE: return NV_CC_GE; + case TGSI_OPCODE_USLT: return NV_CC_LT; + case TGSI_OPCODE_USNE: return NV_CC_NE; + default: + assert(0); + return NV_CC_FL; + } +} + +static uint +translate_opcode(uint opcode) +{ + switch (opcode) { + case TGSI_OPCODE_ABS: return NV_OP_ABS; + case TGSI_OPCODE_ADD: + case TGSI_OPCODE_SUB: + case TGSI_OPCODE_UADD: return NV_OP_ADD; + case TGSI_OPCODE_AND: return NV_OP_AND; + case TGSI_OPCODE_EX2: return NV_OP_EX2; + case TGSI_OPCODE_CEIL: return NV_OP_CEIL; + case TGSI_OPCODE_FLR: return NV_OP_FLOOR; + case TGSI_OPCODE_TRUNC: return NV_OP_TRUNC; + case TGSI_OPCODE_COS: return NV_OP_COS; + case TGSI_OPCODE_SIN: return NV_OP_SIN; + case TGSI_OPCODE_DDX: return NV_OP_DFDX; + case TGSI_OPCODE_DDY: return NV_OP_DFDY; + case TGSI_OPCODE_F2I: + case TGSI_OPCODE_F2U: + case TGSI_OPCODE_I2F: + case TGSI_OPCODE_U2F: return NV_OP_CVT; + case TGSI_OPCODE_INEG: return NV_OP_NEG; + case TGSI_OPCODE_LG2: return NV_OP_LG2; + case TGSI_OPCODE_ISHR: + case TGSI_OPCODE_USHR: return NV_OP_SHR; + case TGSI_OPCODE_MAD: + case TGSI_OPCODE_UMAD: return NV_OP_MAD; + case TGSI_OPCODE_MAX: + case TGSI_OPCODE_IMAX: + case TGSI_OPCODE_UMAX: return NV_OP_MAX; + case TGSI_OPCODE_MIN: + case TGSI_OPCODE_IMIN: + case TGSI_OPCODE_UMIN: return NV_OP_MIN; + case TGSI_OPCODE_MUL: + case TGSI_OPCODE_UMUL: return NV_OP_MUL; + case TGSI_OPCODE_OR: return NV_OP_OR; + case TGSI_OPCODE_RCP: return NV_OP_RCP; + case TGSI_OPCODE_RSQ: return NV_OP_RSQ; + case TGSI_OPCODE_SAD: return NV_OP_SAD; + case TGSI_OPCODE_SHL: return NV_OP_SHL; + case TGSI_OPCODE_SLT: + case TGSI_OPCODE_SGE: + case TGSI_OPCODE_SEQ: + case TGSI_OPCODE_SGT: + case TGSI_OPCODE_SLE: + case TGSI_OPCODE_SNE: + case TGSI_OPCODE_ISLT: + case TGSI_OPCODE_ISGE: + case TGSI_OPCODE_USEQ: + case TGSI_OPCODE_USGE: + case TGSI_OPCODE_USLT: + case TGSI_OPCODE_USNE: return NV_OP_SET; + case TGSI_OPCODE_TEX: return NV_OP_TEX; + case TGSI_OPCODE_TXP: return NV_OP_TEX; + case TGSI_OPCODE_TXB: return NV_OP_TXB; + case TGSI_OPCODE_TXL: return NV_OP_TXL; + case TGSI_OPCODE_XOR: return NV_OP_XOR; + default: + return NV_OP_NOP; + } +} + +static ubyte +infer_src_type(unsigned opcode) +{ + switch (opcode) { + case TGSI_OPCODE_MOV: + case TGSI_OPCODE_AND: + case TGSI_OPCODE_OR: + case TGSI_OPCODE_XOR: + case TGSI_OPCODE_SAD: + case TGSI_OPCODE_U2F: + case TGSI_OPCODE_UADD: + case TGSI_OPCODE_UDIV: + case TGSI_OPCODE_UMOD: + case TGSI_OPCODE_UMAD: + case TGSI_OPCODE_UMUL: + case TGSI_OPCODE_UMAX: + case TGSI_OPCODE_UMIN: + case TGSI_OPCODE_USEQ: + case TGSI_OPCODE_USGE: + case TGSI_OPCODE_USLT: + case TGSI_OPCODE_USNE: + case TGSI_OPCODE_USHR: + return NV_TYPE_U32; + case TGSI_OPCODE_I2F: + case TGSI_OPCODE_IDIV: + case TGSI_OPCODE_IMAX: + case TGSI_OPCODE_IMIN: + case TGSI_OPCODE_INEG: + case TGSI_OPCODE_ISGE: + case TGSI_OPCODE_ISHR: + case TGSI_OPCODE_ISLT: + return NV_TYPE_S32; + default: + return NV_TYPE_F32; + } +} + +static ubyte +infer_dst_type(unsigned opcode) +{ + switch (opcode) { + case TGSI_OPCODE_MOV: + case TGSI_OPCODE_F2U: + case TGSI_OPCODE_AND: + case TGSI_OPCODE_OR: + case TGSI_OPCODE_XOR: + case TGSI_OPCODE_SAD: + case TGSI_OPCODE_UADD: + case TGSI_OPCODE_UDIV: + case TGSI_OPCODE_UMOD: + case TGSI_OPCODE_UMAD: + case TGSI_OPCODE_UMUL: + case TGSI_OPCODE_UMAX: + case TGSI_OPCODE_UMIN: + case TGSI_OPCODE_USEQ: + case TGSI_OPCODE_USGE: + case TGSI_OPCODE_USLT: + case TGSI_OPCODE_USNE: + case TGSI_OPCODE_USHR: + return NV_TYPE_U32; + case TGSI_OPCODE_F2I: + case TGSI_OPCODE_IDIV: + case TGSI_OPCODE_IMAX: + case TGSI_OPCODE_IMIN: + case TGSI_OPCODE_INEG: + case TGSI_OPCODE_ISGE: + case TGSI_OPCODE_ISHR: + case TGSI_OPCODE_ISLT: + return NV_TYPE_S32; + default: + return NV_TYPE_F32; + } +} + +static void +emit_store(struct bld_context *bld, const struct tgsi_full_instruction *inst, + unsigned chan, struct nv_value *value) +{ + struct nv_value *ptr; + const struct tgsi_full_dst_register *reg = &inst->Dst[0]; + + if (reg->Register.Indirect) { + ptr = FETCH_ADDR(reg->Indirect.Index, + tgsi_util_get_src_register_swizzle(®->Indirect, 0)); + } else { + ptr = NULL; + } + + assert(chan < 4); + + if (inst->Instruction.Opcode != TGSI_OPCODE_MOV) + value->reg.type = infer_dst_type(inst->Instruction.Opcode); + + switch (inst->Instruction.Saturate) { + case TGSI_SAT_NONE: + break; + case TGSI_SAT_ZERO_ONE: + BLD_INSN_1_EX(value, SAT, F32, value, F32); + break; + case TGSI_SAT_MINUS_PLUS_ONE: + value->reg.as_type = NV_TYPE_F32; + value = bld_insn_2(bld, NV_OP_MAX, value, bld_load_imm_f32(bld, -1.0f)); + value = bld_insn_2(bld, NV_OP_MIN, value, bld_load_imm_f32(bld, 1.0f)); + break; + } + + switch (reg->Register.File) { + case TGSI_FILE_OUTPUT: + if (!value->insn && (bld->ti->output_file == NV_FILE_OUT)) + value = bld_insn_1(bld, NV_OP_MOV, value); + value = bld_insn_1(bld, NV_OP_MOV, value); + value->reg.file = bld->ti->output_file; + + if (bld->ti->p->type == PIPE_SHADER_FRAGMENT) { + STORE_OUTR(reg->Register.Index, chan, value); + } else { + value->insn->fixed = 1; + value->reg.id = bld->ti->output_map[reg->Register.Index][chan]; + } + break; + case TGSI_FILE_TEMPORARY: + assert(reg->Register.Index < BLD_MAX_TEMPS); + if (!value->insn || (value->insn->bb != bld->pc->current_block)) + value = bld_insn_1(bld, NV_OP_MOV, value); + value->reg.file = NV_FILE_GPR; + + if (bld->ti->store_to_memory) + bld_lmem_store(bld, ptr, reg->Register.Index * 4 + chan, value); + else + STORE_TEMP(reg->Register.Index, chan, value); + break; + case TGSI_FILE_ADDRESS: + assert(reg->Register.Index < BLD_MAX_ADDRS); + value->reg.file = NV_FILE_ADDR; + value->reg.type = NV_TYPE_U16; + STORE_ADDR(reg->Register.Index, chan, value); + break; + } +} + +static INLINE uint32_t +bld_is_output_written(struct bld_context *bld, int i, int c) +{ + if (c < 0) + return bld->outputs_written[i / 8] & (0xf << ((i * 4) % 32)); + return bld->outputs_written[i / 8] & (1 << ((i * 4 + c) % 32)); +} + +static void +bld_export_outputs(struct bld_context *bld) +{ + struct nv_value *vals[4]; + struct nv_instruction *nvi; + int i, c, n; + + bld_push_values(&bld->ovs[0][0], PIPE_MAX_SHADER_OUTPUTS); + + for (i = 0; i < PIPE_MAX_SHADER_OUTPUTS; ++i) { + if (!bld_is_output_written(bld, i, -1)) + continue; + for (n = 0, c = 0; c < 4; ++c) { + if (!bld_is_output_written(bld, i, c)) + continue; + vals[n] = bld_fetch_global(bld, &bld->ovs[i][c]); + assert(vals[n]); + vals[n] = bld_insn_1(bld, NV_OP_MOV, vals[n]); + vals[n++]->reg.id = bld->ti->output_map[i][c]; + } + assert(n); + + (nvi = new_instruction(bld->pc, NV_OP_EXPORT))->fixed = 1; + + for (c = 0; c < n; ++c) + nvi->src[c] = new_ref(bld->pc, vals[c]); + } +} + +static void +bld_new_block(struct bld_context *bld, struct nv_basic_block *b) +{ + int i; + + bld_push_values(&bld->tvs[0][0], BLD_MAX_TEMPS); + bld_push_values(&bld->avs[0][0], BLD_MAX_ADDRS); + bld_push_values(&bld->pvs[0][0], BLD_MAX_PREDS); + bld_push_values(&bld->ovs[0][0], PIPE_MAX_SHADER_OUTPUTS); + + bld->pc->current_block = b; + + for (i = 0; i < 4; ++i) + bld->saved_addr[i][0] = NULL; + + for (i = 0; i < 128; ++i) + bld->saved_inputs[i] = NULL; + + bld->out_kind = CFG_EDGE_FORWARD; +} + +static struct nv_value * +bld_saved_input(struct bld_context *bld, unsigned i, unsigned c) +{ + unsigned idx = bld->ti->input_map[i][c]; + + if (bld->ti->p->type != PIPE_SHADER_FRAGMENT) + return NULL; + if (bld->saved_inputs[idx]) + return bld->saved_inputs[idx]; + return NULL; +} + +static struct nv_value * +bld_interpolate(struct bld_context *bld, unsigned mode, struct nv_value *val) +{ + if (val->reg.id == 255) { + /* gl_FrontFacing: 0/~0 to -1.0/+1.0 */ + val = bld_insn_1(bld, NV_OP_LINTERP, val); + val = bld_insn_2(bld, NV_OP_SHL, val, bld_imm_u32(bld, 31)); + val->insn->src[0]->typecast = NV_TYPE_U32; + val = bld_insn_2(bld, NV_OP_XOR, val, bld_imm_f32(bld, -1.0f)); + val->insn->src[0]->typecast = NV_TYPE_U32; + } else + if (mode & (NV50_INTERP_LINEAR | NV50_INTERP_FLAT)) + val = bld_insn_1(bld, NV_OP_LINTERP, val); + else + val = bld_insn_2(bld, NV_OP_PINTERP, val, bld->frgcrd[3]); + + val->insn->flat = (mode & NV50_INTERP_FLAT) ? 1 : 0; + val->insn->centroid = (mode & NV50_INTERP_CENTROID) ? 1 : 0; + return val; +} + +static struct nv_value * +emit_fetch(struct bld_context *bld, const struct tgsi_full_instruction *insn, + const unsigned s, const unsigned chan) +{ + const struct tgsi_full_src_register *src = &insn->Src[s]; + struct nv_value *res; + struct nv_value *ptr = NULL; + unsigned idx, swz, dim_idx, ind_idx, ind_swz, sgn; + ubyte type = infer_src_type(insn->Instruction.Opcode); + + idx = src->Register.Index; + swz = tgsi_util_get_full_src_register_swizzle(src, chan); + dim_idx = -1; + ind_idx = -1; + ind_swz = 0; + + if (src->Register.Indirect) { + ind_idx = src->Indirect.Index; + ind_swz = tgsi_util_get_src_register_swizzle(&src->Indirect, 0); + + ptr = FETCH_ADDR(ind_idx, ind_swz); + } + if (idx >= (128 / 4) && src->Register.File == TGSI_FILE_CONSTANT) + ptr = bld_get_address(bld, (idx * 16) & ~0x1ff, ptr); + + switch (src->Register.File) { + case TGSI_FILE_CONSTANT: + dim_idx = src->Dimension.Index ? src->Dimension.Index + 2 : 1; + assert(dim_idx < 14); + assert(dim_idx == 1); /* for now */ + + res = new_value(bld->pc, NV_FILE_MEM_C(dim_idx), type); + SET_TYPE(res, type); + res->reg.id = (idx * 4 + swz) & 127; + res = bld_insn_1(bld, NV_OP_LDA, res); + + if (ptr) + res->insn->src[4] = new_ref(bld->pc, ptr); + break; + case TGSI_FILE_IMMEDIATE: + assert(idx < bld->ti->immd32_nr); + res = bld_load_imm_u32(bld, bld->ti->immd32[idx * 4 + swz]); + + switch (bld->ti->immd32_ty[idx]) { + case TGSI_IMM_FLOAT32: SET_TYPE(res, NV_TYPE_F32); break; + case TGSI_IMM_UINT32: SET_TYPE(res, NV_TYPE_U32); break; + case TGSI_IMM_INT32: SET_TYPE(res, NV_TYPE_S32); break; + default: + SET_TYPE(res, type); + break; + } + break; + case TGSI_FILE_INPUT: + res = bld_saved_input(bld, idx, swz); + if (res && (insn->Instruction.Opcode != TGSI_OPCODE_TXP)) + break; + + res = new_value(bld->pc, bld->ti->input_file, type); + res->reg.id = bld->ti->input_map[idx][swz]; + + if (res->reg.file == NV_FILE_MEM_V) { + res = bld_interpolate(bld, bld->ti->interp_mode[idx], res); + } else { + assert(src->Dimension.Dimension == 0); + res = bld_insn_1(bld, NV_OP_LDA, res); + assert(res->reg.type == type); + } + bld->saved_inputs[bld->ti->input_map[idx][swz]] = res; + break; + case TGSI_FILE_TEMPORARY: + if (bld->ti->store_to_memory) + res = bld_lmem_load(bld, ptr, idx * 4 + swz); + else + res = bld_fetch_global(bld, &bld->tvs[idx][swz]); + break; + case TGSI_FILE_ADDRESS: + res = bld_fetch_global(bld, &bld->avs[idx][swz]); + break; + case TGSI_FILE_PREDICATE: + res = bld_fetch_global(bld, &bld->pvs[idx][swz]); + break; + default: + NOUVEAU_ERR("illegal/unhandled src reg file: %d\n", src->Register.File); + abort(); + break; + } + if (!res) + return bld_undef(bld, NV_FILE_GPR); + + sgn = tgsi_util_get_full_src_register_sign_mode(src, chan); + + if (insn->Instruction.Opcode != TGSI_OPCODE_MOV) + res->reg.as_type = type; + else + if (sgn != TGSI_UTIL_SIGN_KEEP) /* apparently "MOV A, -B" assumes float */ + res->reg.as_type = NV_TYPE_F32; + + switch (sgn) { + case TGSI_UTIL_SIGN_KEEP: + break; + case TGSI_UTIL_SIGN_CLEAR: + res = bld_insn_1(bld, NV_OP_ABS, res); + break; + case TGSI_UTIL_SIGN_TOGGLE: + res = bld_insn_1(bld, NV_OP_NEG, res); + break; + case TGSI_UTIL_SIGN_SET: + res = bld_insn_1(bld, NV_OP_ABS, res); + res = bld_insn_1(bld, NV_OP_NEG, res); + break; + default: + NOUVEAU_ERR("illegal/unhandled src reg sign mode\n"); + abort(); + break; + } + + return res; +} + +static void +bld_lit(struct bld_context *bld, struct nv_value *dst0[4], + const struct tgsi_full_instruction *insn) +{ + struct nv_value *val0 = NULL; + struct nv_value *zero = NULL; + unsigned mask = insn->Dst[0].Register.WriteMask; + + if (mask & ((1 << 0) | (1 << 3))) + dst0[3] = dst0[0] = bld_load_imm_f32(bld, 1.0f); + + if (mask & (3 << 1)) { + zero = bld_load_imm_f32(bld, 0.0f); + val0 = bld_insn_2(bld, NV_OP_MAX, emit_fetch(bld, insn, 0, 0), zero); + + if (mask & (1 << 1)) + dst0[1] = val0; + } + + if (mask & (1 << 2)) { + struct nv_value *val1, *val3, *src1, *src3; + struct nv_value *pos128 = bld_load_imm_f32(bld, 127.999999f); + struct nv_value *neg128 = bld_load_imm_f32(bld, -127.999999f); + + src1 = emit_fetch(bld, insn, 0, 1); + src3 = emit_fetch(bld, insn, 0, 3); + + val0->insn->flags_def = new_value(bld->pc, NV_FILE_FLAGS, NV_TYPE_U16); + val0->insn->flags_def->insn = val0->insn; + + val1 = bld_insn_2(bld, NV_OP_MAX, src1, zero); + val3 = bld_insn_2(bld, NV_OP_MAX, src3, neg128); + val3 = bld_insn_2(bld, NV_OP_MIN, val3, pos128); + val3 = bld_pow(bld, val1, val3); + + dst0[2] = bld_insn_1(bld, NV_OP_MOV, zero); + dst0[2]->insn->cc = NV_CC_LE; + dst0[2]->insn->flags_src = new_ref(bld->pc, val0->insn->flags_def); + + dst0[2] = bld_insn_2(bld, NV_OP_SELECT, val3, dst0[2]); + } +} + +static INLINE void +get_tex_dim(const struct tgsi_full_instruction *insn, int *dim, int *arg) +{ + switch (insn->Texture.Texture) { + case TGSI_TEXTURE_1D: + *arg = *dim = 1; + break; + case TGSI_TEXTURE_SHADOW1D: + *dim = 1; + *arg = 2; + break; + case TGSI_TEXTURE_UNKNOWN: + case TGSI_TEXTURE_2D: + case TGSI_TEXTURE_RECT: + *arg = *dim = 2; + break; + case TGSI_TEXTURE_SHADOW2D: + case TGSI_TEXTURE_SHADOWRECT: + *dim = 2; + *arg = 3; + break; + case TGSI_TEXTURE_3D: + case TGSI_TEXTURE_CUBE: + *dim = *arg = 3; + break; + default: + assert(0); + break; + } +} + +static void +load_proj_tex_coords(struct bld_context *bld, + struct nv_value *t[4], int dim, int arg, + const struct tgsi_full_instruction *insn) +{ + int c, mask; + + mask = (1 << dim) - 1; + if (arg != dim) + mask |= 4; /* depth comparison value */ + + t[3] = emit_fetch(bld, insn, 0, 3); + + if (t[3]->insn->opcode == NV_OP_PINTERP) { + t[3] = bld_duplicate_insn(bld, t[3]->insn); + t[3]->insn->opcode = NV_OP_LINTERP; + nv_reference(bld->pc, &t[3]->insn->src[1], NULL); + } + + t[3] = bld_insn_1(bld, NV_OP_RCP, t[3]); + + for (c = 0; c < 4; ++c) { + if (!(mask & (1 << c))) + continue; + t[c] = emit_fetch(bld, insn, 0, c); + + if (t[c]->insn->opcode != NV_OP_LINTERP && + t[c]->insn->opcode != NV_OP_PINTERP) + continue; + t[c] = bld_duplicate_insn(bld, t[c]->insn); + t[c]->insn->opcode = NV_OP_PINTERP; + nv_reference(bld->pc, &t[c]->insn->src[1], t[3]); + + mask &= ~(1 << c); + } + + for (c = 0; mask; ++c, mask >>= 1) { + if (!(mask & 1)) + continue; + t[c] = bld_insn_2(bld, NV_OP_MUL, t[c], t[3]); + } +} + +/* For a quad of threads / top left, top right, bottom left, bottom right + * pixels, do a different operation, and take src0 from a specific thread. + */ +#define QOP_ADD 0 +#define QOP_SUBR 1 +#define QOP_SUB 2 +#define QOP_MOV1 3 + +#define QOP(a, b, c, d) \ + ((QOP_##a << 0) | (QOP_##b << 2) | (QOP_##c << 4) | (QOP_##d << 6)) + +static INLINE struct nv_value * +bld_quadop(struct bld_context *bld, ubyte qop, struct nv_value *src0, int lane, + struct nv_value *src1, boolean wp) +{ + struct nv_value *val = bld_insn_2(bld, NV_OP_QUADOP, src0, src1); + val->insn->lanes = lane; + val->insn->quadop = qop; + if (wp) { + val->insn->flags_def = new_value(bld->pc, NV_FILE_FLAGS, NV_TYPE_U16); + val->insn->flags_def->insn = val->insn; + } + return val; +} + +static INLINE struct nv_value * +bld_cmov(struct bld_context *bld, + struct nv_value *src, ubyte cc, struct nv_value *cr) +{ + src = bld_insn_1(bld, NV_OP_MOV, src); + + src->insn->cc = cc; + src->insn->flags_src = new_ref(bld->pc, cr); + + return src; +} + +static struct nv_instruction * +emit_tex(struct bld_context *bld, uint opcode, + struct nv_value *dst[4], struct nv_value *t_in[4], + int argc, int tic, int tsc, int cube) +{ + struct nv_value *t[4]; + struct nv_instruction *nvi; + int c; + + /* the inputs to a tex instruction must be separate values */ + for (c = 0; c < argc; ++c) { + t[c] = bld_insn_1(bld, NV_OP_MOV, t_in[c]); + SET_TYPE(t[c], NV_TYPE_F32); + t[c]->insn->fixed = 1; + } + + nvi = new_instruction(bld->pc, opcode); + + for (c = 0; c < 4; ++c) + dst[c] = bld_def(nvi, c, new_value(bld->pc, NV_FILE_GPR, NV_TYPE_F32)); + + for (c = 0; c < argc; ++c) + nvi->src[c] = new_ref(bld->pc, t[c]); + + nvi->tex_t = tic; + nvi->tex_s = tsc; + nvi->tex_mask = 0xf; + nvi->tex_cube = cube; + nvi->tex_live = 0; + nvi->tex_argc = argc; + + return nvi; +} + +static void +bld_texlod_sequence(struct bld_context *bld, + struct nv_value *dst[4], struct nv_value *t[4], int arg, + int tic, int tsc, int cube) +{ + emit_tex(bld, NV_OP_TXL, dst, t, arg, tic, tsc, cube); /* TODO */ +} + + +/* The lanes of a quad are grouped by the bit in the condition register + * they have set, which is selected by differing bias values. + * Move the input values for TEX into a new register set for each group + * and execute TEX only for a specific group. + * We always need to use 4 new registers for the inputs/outputs because + * the implicitly calculated derivatives must be correct. + */ +static void +bld_texbias_sequence(struct bld_context *bld, + struct nv_value *dst[4], struct nv_value *t[4], int arg, + int tic, int tsc, int cube) +{ + struct nv_instruction *sel, *tex; + struct nv_value *bit[4], *cr[4], *res[4][4], *val; + int l, c; + + const ubyte cc[4] = { NV_CC_EQ, NV_CC_S, NV_CC_C, NV_CC_O }; + + for (l = 0; l < 4; ++l) { + bit[l] = bld_load_imm_u32(bld, 1 << l); + + val = bld_quadop(bld, QOP(SUBR, SUBR, SUBR, SUBR), + t[arg - 1], l, t[arg - 1], TRUE); + + cr[l] = bld_cmov(bld, bit[l], NV_CC_EQ, val->insn->flags_def); + + cr[l]->reg.file = NV_FILE_FLAGS; + SET_TYPE(cr[l], NV_TYPE_U16); + } + + sel = new_instruction(bld->pc, NV_OP_SELECT); + + for (l = 0; l < 4; ++l) + sel->src[l] = new_ref(bld->pc, cr[l]); + + bld_def(sel, 0, new_value(bld->pc, NV_FILE_FLAGS, NV_TYPE_U16)); + + for (l = 0; l < 4; ++l) { + tex = emit_tex(bld, NV_OP_TXB, dst, t, arg, tic, tsc, cube); + + tex->cc = cc[l]; + tex->flags_src = new_ref(bld->pc, sel->def[0]); + + for (c = 0; c < 4; ++c) + res[l][c] = tex->def[c]; + } + + for (l = 0; l < 4; ++l) + for (c = 0; c < 4; ++c) + res[l][c] = bld_cmov(bld, res[l][c], cc[l], sel->def[0]); + + for (c = 0; c < 4; ++c) { + sel = new_instruction(bld->pc, NV_OP_SELECT); + + for (l = 0; l < 4; ++l) + sel->src[l] = new_ref(bld->pc, res[l][c]); + + bld_def(sel, 0, (dst[c] = new_value(bld->pc, NV_FILE_GPR, NV_TYPE_F32))); + } +} + +static boolean +bld_is_constant(struct nv_value *val) +{ + if (val->reg.file == NV_FILE_IMM) + return TRUE; + return val->insn && nvcg_find_constant(val->insn->src[0]); +} + +static void +bld_tex(struct bld_context *bld, struct nv_value *dst0[4], + const struct tgsi_full_instruction *insn) +{ + struct nv_value *t[4], *s[3]; + uint opcode = translate_opcode(insn->Instruction.Opcode); + int arg, dim, c; + const int tic = insn->Src[1].Register.Index; + const int tsc = 0; + const int cube = (insn->Texture.Texture == TGSI_TEXTURE_CUBE) ? 1 : 0; + + get_tex_dim(insn, &dim, &arg); + + if (!cube && insn->Instruction.Opcode == TGSI_OPCODE_TXP) + load_proj_tex_coords(bld, t, dim, arg, insn); + else { + for (c = 0; c < dim; ++c) + t[c] = emit_fetch(bld, insn, 0, c); + if (arg != dim) + t[dim] = emit_fetch(bld, insn, 0, 2); + } + + if (cube) { + assert(dim >= 3); + for (c = 0; c < 3; ++c) + s[c] = bld_insn_1(bld, NV_OP_ABS, t[c]); + + s[0] = bld_insn_2(bld, NV_OP_MAX, s[0], s[1]); + s[0] = bld_insn_2(bld, NV_OP_MAX, s[0], s[2]); + s[0] = bld_insn_1(bld, NV_OP_RCP, s[0]); + + for (c = 0; c < 3; ++c) + t[c] = bld_insn_2(bld, NV_OP_MUL, t[c], s[0]); + } + + if (opcode == NV_OP_TXB || opcode == NV_OP_TXL) { + t[arg++] = emit_fetch(bld, insn, 0, 3); + + if ((bld->ti->p->type == PIPE_SHADER_FRAGMENT) && + !bld_is_constant(t[arg - 1])) { + if (opcode == NV_OP_TXB) + bld_texbias_sequence(bld, dst0, t, arg, tic, tsc, cube); + else + bld_texlod_sequence(bld, dst0, t, arg, tic, tsc, cube); + return; + } + } + + emit_tex(bld, opcode, dst0, t, arg, tic, tsc, cube); +} + +static INLINE struct nv_value * +bld_dot(struct bld_context *bld, const struct tgsi_full_instruction *insn, + int n) +{ + struct nv_value *dotp, *src0, *src1; + int c; + + src0 = emit_fetch(bld, insn, 0, 0); + src1 = emit_fetch(bld, insn, 1, 0); + dotp = bld_insn_2(bld, NV_OP_MUL, src0, src1); + + for (c = 1; c < n; ++c) { + src0 = emit_fetch(bld, insn, 0, c); + src1 = emit_fetch(bld, insn, 1, c); + dotp = bld_insn_3(bld, NV_OP_MAD, src0, src1, dotp); + } + return dotp; +} + +#define FOR_EACH_DST0_ENABLED_CHANNEL(chan, inst) \ + for (chan = 0; chan < 4; ++chan) \ + if ((inst)->Dst[0].Register.WriteMask & (1 << chan)) + +static void +bld_instruction(struct bld_context *bld, + const struct tgsi_full_instruction *insn) +{ + struct nv_value *src0; + struct nv_value *src1; + struct nv_value *src2; + struct nv_value *dst0[4] = { 0 }; + struct nv_value *temp; + int c; + uint opcode = translate_opcode(insn->Instruction.Opcode); + +#ifdef NV50_TGSI2NC_DEBUG + debug_printf("bld_instruction:"); tgsi_dump_instruction(insn, 1); +#endif + + switch (insn->Instruction.Opcode) { + case TGSI_OPCODE_ADD: + case TGSI_OPCODE_MAX: + case TGSI_OPCODE_MIN: + case TGSI_OPCODE_MUL: + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) { + src0 = emit_fetch(bld, insn, 0, c); + src1 = emit_fetch(bld, insn, 1, c); + dst0[c] = bld_insn_2(bld, opcode, src0, src1); + } + break; + case TGSI_OPCODE_ARL: + src1 = bld_imm_u32(bld, 4); + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) { + src0 = emit_fetch(bld, insn, 0, c); + temp = bld_insn_1(bld, NV_OP_FLOOR, src0); + SET_TYPE(temp, NV_TYPE_S32); + dst0[c] = bld_insn_2(bld, NV_OP_SHL, temp, src1); + } + break; + case TGSI_OPCODE_CMP: + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) { + src0 = emit_fetch(bld, insn, 0, c); + src1 = emit_fetch(bld, insn, 1, c); + src2 = emit_fetch(bld, insn, 2, c); + src0 = bld_predicate(bld, src0, FALSE); + + src1 = bld_insn_1(bld, NV_OP_MOV, src1); + src1->insn->flags_src = new_ref(bld->pc, src0); + src1->insn->cc = NV_CC_LT; + + src2 = bld_insn_1(bld, NV_OP_MOV, src2); + src2->insn->flags_src = new_ref(bld->pc, src0); + src2->insn->cc = NV_CC_GE; + + dst0[c] = bld_insn_2(bld, NV_OP_SELECT, src1, src2); + } + break; + case TGSI_OPCODE_COS: + case TGSI_OPCODE_SIN: + src0 = emit_fetch(bld, insn, 0, 0); + temp = bld_insn_1(bld, NV_OP_PRESIN, src0); + if (insn->Dst[0].Register.WriteMask & 7) + temp = bld_insn_1(bld, opcode, temp); + for (c = 0; c < 3; ++c) + if (insn->Dst[0].Register.WriteMask & (1 << c)) + dst0[c] = temp; + if (!(insn->Dst[0].Register.WriteMask & (1 << 3))) + break; + src0 = emit_fetch(bld, insn, 0, 3); + temp = bld_insn_1(bld, NV_OP_PRESIN, src0); + dst0[3] = bld_insn_1(bld, opcode, temp); + break; + case TGSI_OPCODE_DP2: + temp = bld_dot(bld, insn, 2); + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) + dst0[c] = temp; + break; + case TGSI_OPCODE_DP3: + temp = bld_dot(bld, insn, 3); + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) + dst0[c] = temp; + break; + case TGSI_OPCODE_DP4: + temp = bld_dot(bld, insn, 4); + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) + dst0[c] = temp; + break; + case TGSI_OPCODE_DPH: + src0 = bld_dot(bld, insn, 3); + src1 = emit_fetch(bld, insn, 1, 3); + temp = bld_insn_2(bld, NV_OP_ADD, src0, src1); + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) + dst0[c] = temp; + break; + case TGSI_OPCODE_DST: + if (insn->Dst[0].Register.WriteMask & 1) + dst0[0] = bld_imm_f32(bld, 1.0f); + if (insn->Dst[0].Register.WriteMask & 2) { + src0 = emit_fetch(bld, insn, 0, 1); + src1 = emit_fetch(bld, insn, 1, 1); + dst0[1] = bld_insn_2(bld, NV_OP_MUL, src0, src1); + } + if (insn->Dst[0].Register.WriteMask & 4) + dst0[2] = emit_fetch(bld, insn, 0, 2); + if (insn->Dst[0].Register.WriteMask & 8) + dst0[3] = emit_fetch(bld, insn, 1, 3); + break; + case TGSI_OPCODE_EXP: + src0 = emit_fetch(bld, insn, 0, 0); + temp = bld_insn_1(bld, NV_OP_FLOOR, src0); + + if (insn->Dst[0].Register.WriteMask & 2) + dst0[1] = bld_insn_2(bld, NV_OP_SUB, src0, temp); + if (insn->Dst[0].Register.WriteMask & 1) { + temp = bld_insn_1(bld, NV_OP_PREEX2, temp); + dst0[0] = bld_insn_1(bld, NV_OP_EX2, temp); + } + if (insn->Dst[0].Register.WriteMask & 4) { + temp = bld_insn_1(bld, NV_OP_PREEX2, src0); + dst0[2] = bld_insn_1(bld, NV_OP_EX2, temp); + } + if (insn->Dst[0].Register.WriteMask & 8) + dst0[3] = bld_imm_f32(bld, 1.0f); + break; + case TGSI_OPCODE_EX2: + src0 = emit_fetch(bld, insn, 0, 0); + temp = bld_insn_1(bld, NV_OP_PREEX2, src0); + temp = bld_insn_1(bld, NV_OP_EX2, temp); + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) + dst0[c] = temp; + break; + case TGSI_OPCODE_FRC: + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) { + src0 = emit_fetch(bld, insn, 0, c); + dst0[c] = bld_insn_1(bld, NV_OP_FLOOR, src0); + dst0[c] = bld_insn_2(bld, NV_OP_SUB, src0, dst0[c]); + } + break; + case TGSI_OPCODE_KIL: + for (c = 0; c < 4; ++c) { + src0 = emit_fetch(bld, insn, 0, c); + bld_kil(bld, src0); + } + break; + case TGSI_OPCODE_KILP: + (new_instruction(bld->pc, NV_OP_KIL))->fixed = 1; + break; + case TGSI_OPCODE_IF: + { + struct nv_basic_block *b = new_basic_block(bld->pc); + + assert(bld->cond_lvl < BLD_MAX_COND_NESTING); + + nvbb_attach_block(bld->pc->current_block, b, CFG_EDGE_FORWARD); + + bld->join_bb[bld->cond_lvl] = bld->pc->current_block; + bld->cond_bb[bld->cond_lvl] = bld->pc->current_block; + + src1 = bld_predicate(bld, emit_fetch(bld, insn, 0, 0), TRUE); + + bld_flow(bld, NV_OP_BRA, NV_CC_EQ, src1, NULL, (bld->cond_lvl == 0)); + + ++bld->cond_lvl; + bld_new_block(bld, b); + } + break; + case TGSI_OPCODE_ELSE: + { + struct nv_basic_block *b = new_basic_block(bld->pc); + + --bld->cond_lvl; + nvbb_attach_block(bld->join_bb[bld->cond_lvl], b, CFG_EDGE_FORWARD); + + bld->cond_bb[bld->cond_lvl]->exit->target = b; + bld->cond_bb[bld->cond_lvl] = bld->pc->current_block; + + new_instruction(bld->pc, NV_OP_BRA)->is_terminator = 1; + + ++bld->cond_lvl; + bld_new_block(bld, b); + } + break; + case TGSI_OPCODE_ENDIF: + { + struct nv_basic_block *b = new_basic_block(bld->pc); + + --bld->cond_lvl; + nvbb_attach_block(bld->pc->current_block, b, bld->out_kind); + nvbb_attach_block(bld->cond_bb[bld->cond_lvl], b, CFG_EDGE_FORWARD); + + bld->cond_bb[bld->cond_lvl]->exit->target = b; + + bld_new_block(bld, b); + + if (!bld->cond_lvl && bld->join_bb[bld->cond_lvl]) { + bld->join_bb[bld->cond_lvl]->exit->prev->target = b; + new_instruction(bld->pc, NV_OP_JOIN)->is_join = TRUE; + } + } + break; + case TGSI_OPCODE_BGNLOOP: + { + struct nv_basic_block *bl = new_basic_block(bld->pc); + struct nv_basic_block *bb = new_basic_block(bld->pc); + + assert(bld->loop_lvl < BLD_MAX_LOOP_NESTING); + + bld->loop_bb[bld->loop_lvl] = bl; + bld->brkt_bb[bld->loop_lvl] = bb; + + bld_flow(bld, NV_OP_BREAKADDR, NV_CC_TR, NULL, bb, FALSE); + + nvbb_attach_block(bld->pc->current_block, bl, CFG_EDGE_LOOP_ENTER); + + bld_new_block(bld, bld->loop_bb[bld->loop_lvl++]); + + if (bld->loop_lvl == bld->pc->loop_nesting_bound) + bld->pc->loop_nesting_bound++; + + bld_clear_def_use(&bld->tvs[0][0], BLD_MAX_TEMPS, bld->loop_lvl); + bld_clear_def_use(&bld->avs[0][0], BLD_MAX_ADDRS, bld->loop_lvl); + bld_clear_def_use(&bld->pvs[0][0], BLD_MAX_PREDS, bld->loop_lvl); + } + break; + case TGSI_OPCODE_BRK: + { + struct nv_basic_block *bb = bld->brkt_bb[bld->loop_lvl - 1]; + + bld_flow(bld, NV_OP_BREAK, NV_CC_TR, NULL, bb, FALSE); + + if (bld->out_kind == CFG_EDGE_FORWARD) /* else we already had BRK/CONT */ + nvbb_attach_block(bld->pc->current_block, bb, CFG_EDGE_LOOP_LEAVE); + + bld->out_kind = CFG_EDGE_FAKE; + } + break; + case TGSI_OPCODE_CONT: + { + struct nv_basic_block *bb = bld->loop_bb[bld->loop_lvl - 1]; + + bld_flow(bld, NV_OP_BRA, NV_CC_TR, NULL, bb, FALSE); + + nvbb_attach_block(bld->pc->current_block, bb, CFG_EDGE_BACK); + + if ((bb = bld->join_bb[bld->cond_lvl - 1])) { + bld->join_bb[bld->cond_lvl - 1] = NULL; + nv_nvi_delete(bb->exit->prev); + } + bld->out_kind = CFG_EDGE_FAKE; + } + break; + case TGSI_OPCODE_ENDLOOP: + { + struct nv_basic_block *bb = bld->loop_bb[bld->loop_lvl - 1]; + + bld_flow(bld, NV_OP_BRA, NV_CC_TR, NULL, bb, FALSE); + + nvbb_attach_block(bld->pc->current_block, bb, CFG_EDGE_BACK); + + bld_loop_end(bld, bb); /* replace loop-side operand of the phis */ + + bld_new_block(bld, bld->brkt_bb[--bld->loop_lvl]); + } + break; + case TGSI_OPCODE_ABS: + case TGSI_OPCODE_CEIL: + case TGSI_OPCODE_FLR: + case TGSI_OPCODE_TRUNC: + case TGSI_OPCODE_DDX: + case TGSI_OPCODE_DDY: + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) { + src0 = emit_fetch(bld, insn, 0, c); + dst0[c] = bld_insn_1(bld, opcode, src0); + } + break; + case TGSI_OPCODE_LIT: + bld_lit(bld, dst0, insn); + break; + case TGSI_OPCODE_LRP: + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) { + src0 = emit_fetch(bld, insn, 0, c); + src1 = emit_fetch(bld, insn, 1, c); + src2 = emit_fetch(bld, insn, 2, c); + dst0[c] = bld_insn_2(bld, NV_OP_SUB, src1, src2); + dst0[c] = bld_insn_3(bld, NV_OP_MAD, dst0[c], src0, src2); + } + break; + case TGSI_OPCODE_MOV: + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) + dst0[c] = emit_fetch(bld, insn, 0, c); + break; + case TGSI_OPCODE_MAD: + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) { + src0 = emit_fetch(bld, insn, 0, c); + src1 = emit_fetch(bld, insn, 1, c); + src2 = emit_fetch(bld, insn, 2, c); + dst0[c] = bld_insn_3(bld, opcode, src0, src1, src2); + } + break; + case TGSI_OPCODE_POW: + src0 = emit_fetch(bld, insn, 0, 0); + src1 = emit_fetch(bld, insn, 1, 0); + temp = bld_pow(bld, src0, src1); + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) + dst0[c] = temp; + break; + case TGSI_OPCODE_LOG: + src0 = emit_fetch(bld, insn, 0, 0); + src0 = bld_insn_1(bld, NV_OP_ABS, src0); + temp = bld_insn_1(bld, NV_OP_LG2, src0); + dst0[2] = temp; + if (insn->Dst[0].Register.WriteMask & 3) { + temp = bld_insn_1(bld, NV_OP_FLOOR, temp); + dst0[0] = temp; + } + if (insn->Dst[0].Register.WriteMask & 2) { + temp = bld_insn_1(bld, NV_OP_PREEX2, temp); + temp = bld_insn_1(bld, NV_OP_EX2, temp); + temp = bld_insn_1(bld, NV_OP_RCP, temp); + dst0[1] = bld_insn_2(bld, NV_OP_MUL, src0, temp); + } + if (insn->Dst[0].Register.WriteMask & 8) + dst0[3] = bld_imm_f32(bld, 1.0f); + break; + case TGSI_OPCODE_RCP: + case TGSI_OPCODE_LG2: + src0 = emit_fetch(bld, insn, 0, 0); + temp = bld_insn_1(bld, opcode, src0); + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) + dst0[c] = temp; + break; + case TGSI_OPCODE_RSQ: + src0 = emit_fetch(bld, insn, 0, 0); + temp = bld_insn_1(bld, NV_OP_ABS, src0); + temp = bld_insn_1(bld, NV_OP_RSQ, temp); + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) + dst0[c] = temp; + break; + case TGSI_OPCODE_SLT: + case TGSI_OPCODE_SGE: + case TGSI_OPCODE_SEQ: + case TGSI_OPCODE_SGT: + case TGSI_OPCODE_SLE: + case TGSI_OPCODE_SNE: + case TGSI_OPCODE_ISLT: + case TGSI_OPCODE_ISGE: + case TGSI_OPCODE_USEQ: + case TGSI_OPCODE_USGE: + case TGSI_OPCODE_USLT: + case TGSI_OPCODE_USNE: + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) { + src0 = emit_fetch(bld, insn, 0, c); + src1 = emit_fetch(bld, insn, 1, c); + dst0[c] = bld_insn_2(bld, NV_OP_SET, src0, src1); + dst0[c]->insn->set_cond = translate_setcc(insn->Instruction.Opcode); + SET_TYPE(dst0[c], infer_dst_type(insn->Instruction.Opcode)); + + dst0[c]->insn->src[0]->typecast = + dst0[c]->insn->src[1]->typecast = + infer_src_type(insn->Instruction.Opcode); + + if (dst0[c]->reg.type != NV_TYPE_F32) + break; + dst0[c]->reg.as_type = NV_TYPE_S32; + dst0[c] = bld_insn_1(bld, NV_OP_ABS, dst0[c]); + dst0[c] = bld_insn_1(bld, NV_OP_CVT, dst0[c]); + SET_TYPE(dst0[c], NV_TYPE_F32); + } + break; + case TGSI_OPCODE_SCS: + if (insn->Dst[0].Register.WriteMask & 0x3) { + src0 = emit_fetch(bld, insn, 0, 0); + temp = bld_insn_1(bld, NV_OP_PRESIN, src0); + if (insn->Dst[0].Register.WriteMask & 0x1) + dst0[0] = bld_insn_1(bld, NV_OP_COS, temp); + if (insn->Dst[0].Register.WriteMask & 0x2) + dst0[1] = bld_insn_1(bld, NV_OP_SIN, temp); + } + if (insn->Dst[0].Register.WriteMask & 0x4) + dst0[2] = bld_imm_f32(bld, 0.0f); + if (insn->Dst[0].Register.WriteMask & 0x8) + dst0[3] = bld_imm_f32(bld, 1.0f); + break; + case TGSI_OPCODE_SSG: + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) { + src0 = emit_fetch(bld, insn, 0, c); + src1 = bld_predicate(bld, src0, FALSE); + temp = bld_insn_2(bld, NV_OP_AND, src0, bld_imm_u32(bld, 0x80000000)); + temp = bld_insn_2(bld, NV_OP_OR, temp, bld_imm_f32(bld, 1.0f)); + dst0[c] = bld_insn_2(bld, NV_OP_XOR, temp, temp); + dst0[c]->insn->cc = NV_CC_EQ; + nv_reference(bld->pc, &dst0[c]->insn->flags_src, src1); + } + break; + case TGSI_OPCODE_SUB: + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) { + src0 = emit_fetch(bld, insn, 0, c); + src1 = emit_fetch(bld, insn, 1, c); + dst0[c] = bld_insn_2(bld, NV_OP_ADD, src0, src1); + dst0[c]->insn->src[1]->mod ^= NV_MOD_NEG; + } + break; + case TGSI_OPCODE_TEX: + case TGSI_OPCODE_TXB: + case TGSI_OPCODE_TXL: + case TGSI_OPCODE_TXP: + bld_tex(bld, dst0, insn); + break; + case TGSI_OPCODE_XPD: + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) { + if (c == 3) { + dst0[3] = bld_imm_f32(bld, 1.0f); + break; + } + src0 = emit_fetch(bld, insn, 1, (c + 1) % 3); + src1 = emit_fetch(bld, insn, 0, (c + 2) % 3); + dst0[c] = bld_insn_2(bld, NV_OP_MUL, src0, src1); + + src0 = emit_fetch(bld, insn, 0, (c + 1) % 3); + src1 = emit_fetch(bld, insn, 1, (c + 2) % 3); + dst0[c] = bld_insn_3(bld, NV_OP_MAD, src0, src1, dst0[c]); + + dst0[c]->insn->src[2]->mod ^= NV_MOD_NEG; + } + break; + case TGSI_OPCODE_RET: + (new_instruction(bld->pc, NV_OP_RET))->fixed = 1; + break; + case TGSI_OPCODE_END: + if (bld->ti->p->type == PIPE_SHADER_FRAGMENT) + bld_export_outputs(bld); + break; + default: + NOUVEAU_ERR("unhandled opcode %u\n", insn->Instruction.Opcode); + abort(); + break; + } + + FOR_EACH_DST0_ENABLED_CHANNEL(c, insn) + emit_store(bld, insn, c, dst0[c]); +} + +static INLINE void +bld_free_value_trackers(struct bld_value_stack *base, int n) +{ + int i, c; + + for (i = 0; i < n; ++i) + for (c = 0; c < 4; ++c) + if (base[i * 4 + c].body) + FREE(base[i * 4 + c].body); +} + +int +nv50_tgsi_to_nc(struct nv_pc *pc, struct nv50_translation_info *ti) +{ + struct bld_context *bld = CALLOC_STRUCT(bld_context); + int c; + unsigned ip; + + pc->root[0] = pc->current_block = new_basic_block(pc); + + bld->pc = pc; + bld->ti = ti; + + pc->loop_nesting_bound = 1; + + c = util_bitcount(bld->ti->p->fp.interp >> 24); + if (c && ti->p->type == PIPE_SHADER_FRAGMENT) { + bld->frgcrd[3] = new_value(pc, NV_FILE_MEM_V, NV_TYPE_F32); + bld->frgcrd[3]->reg.id = c - 1; + bld->frgcrd[3] = bld_insn_1(bld, NV_OP_LINTERP, bld->frgcrd[3]); + bld->frgcrd[3] = bld_insn_1(bld, NV_OP_RCP, bld->frgcrd[3]); + } + + for (ip = 0; ip < ti->inst_nr; ++ip) + bld_instruction(bld, &ti->insns[ip]); + + bld_free_value_trackers(&bld->tvs[0][0], BLD_MAX_TEMPS); + bld_free_value_trackers(&bld->avs[0][0], BLD_MAX_ADDRS); + bld_free_value_trackers(&bld->pvs[0][0], BLD_MAX_PREDS); + + bld_free_value_trackers(&bld->ovs[0][0], PIPE_MAX_SHADER_OUTPUTS); + + FREE(bld); + return 0; +} + +/* If a variable is assigned in a loop, replace all references to the value + * from outside the loop with a phi value. + */ +static void +bld_replace_value(struct nv_pc *pc, struct nv_basic_block *b, + struct nv_value *old_val, + struct nv_value *new_val) +{ + struct nv_instruction *nvi; + + for (nvi = b->phi ? b->phi : b->entry; nvi; nvi = nvi->next) { + int s; + for (s = 0; s < 5; ++s) { + if (!nvi->src[s]) + continue; + if (nvi->src[s]->value == old_val) + nv_reference(pc, &nvi->src[s], new_val); + } + if (nvi->flags_src && nvi->flags_src->value == old_val) + nv_reference(pc, &nvi->flags_src, new_val); + } + + b->pass_seq = pc->pass_seq; + + if (b->out[0] && b->out[0]->pass_seq < pc->pass_seq) + bld_replace_value(pc, b->out[0], old_val, new_val); + + if (b->out[1] && b->out[1]->pass_seq < pc->pass_seq) + bld_replace_value(pc, b->out[1], old_val, new_val); +} diff --git a/src/gallium/drivers/nv50/nv50_transfer.c b/src/gallium/drivers/nv50/nv50_transfer.c new file mode 100644 index 0000000..bf5af4d --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_transfer.c @@ -0,0 +1,351 @@ + +#include "pipe/p_context.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_math.h" + +#include "nv50_context.h" +#include "nv50_transfer.h" +#include "nv50_resource.h" + +struct nv50_transfer { + struct pipe_transfer base; + struct nouveau_bo *bo; + int map_refcnt; + unsigned level_offset; + unsigned level_tiling; + int level_pitch; + int level_width; + int level_height; + int level_depth; + int level_x; + int level_y; + int level_z; + unsigned nblocksx; + unsigned nblocksy; +}; + +static void +nv50_transfer_rect_m2mf(struct pipe_screen *pscreen, + struct nouveau_bo *src_bo, unsigned src_offset, + int src_pitch, unsigned src_tile_mode, + int sx, int sy, int sz, int sw, int sh, int sd, + struct nouveau_bo *dst_bo, unsigned dst_offset, + int dst_pitch, unsigned dst_tile_mode, + int dx, int dy, int dz, int dw, int dh, int dd, + int cpp, int width, int height, + unsigned src_reloc, unsigned dst_reloc) +{ + struct nv50_screen *screen = nv50_screen(pscreen); + struct nouveau_channel *chan = screen->m2mf->channel; + struct nouveau_grobj *m2mf = screen->m2mf; + + src_reloc |= NOUVEAU_BO_RD; + dst_reloc |= NOUVEAU_BO_WR; + + WAIT_RING (chan, 14); + + if (!nouveau_bo_tile_layout(src_bo)) { + BEGIN_RING(chan, m2mf, + NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_IN, 1); + OUT_RING (chan, 1); + BEGIN_RING(chan, m2mf, + NV04_MEMORY_TO_MEMORY_FORMAT_PITCH_IN, 1); + OUT_RING (chan, src_pitch); + src_offset += (sy * src_pitch) + (sx * cpp); + } else { + BEGIN_RING(chan, m2mf, + NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_IN, 6); + OUT_RING (chan, 0); + OUT_RING (chan, src_tile_mode << 4); + OUT_RING (chan, sw * cpp); + OUT_RING (chan, sh); + OUT_RING (chan, sd); + OUT_RING (chan, sz); /* copying only 1 zslice per call */ + } + + if (!nouveau_bo_tile_layout(dst_bo)) { + BEGIN_RING(chan, m2mf, + NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_OUT, 1); + OUT_RING (chan, 1); + BEGIN_RING(chan, m2mf, + NV04_MEMORY_TO_MEMORY_FORMAT_PITCH_OUT, 1); + OUT_RING (chan, dst_pitch); + dst_offset += (dy * dst_pitch) + (dx * cpp); + } else { + BEGIN_RING(chan, m2mf, + NV50_MEMORY_TO_MEMORY_FORMAT_LINEAR_OUT, 6); + OUT_RING (chan, 0); + OUT_RING (chan, dst_tile_mode << 4); + OUT_RING (chan, dw * cpp); + OUT_RING (chan, dh); + OUT_RING (chan, dd); + OUT_RING (chan, dz); /* copying only 1 zslice per call */ + } + + while (height) { + int line_count = height > 2047 ? 2047 : height; + + MARK_RING (chan, 15, 4); /* flush on lack of space or relocs */ + BEGIN_RING(chan, m2mf, + NV50_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN_HIGH, 2); + OUT_RELOCh(chan, src_bo, src_offset, src_reloc); + OUT_RELOCh(chan, dst_bo, dst_offset, dst_reloc); + BEGIN_RING(chan, m2mf, + NV04_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 2); + OUT_RELOCl(chan, src_bo, src_offset, src_reloc); + OUT_RELOCl(chan, dst_bo, dst_offset, dst_reloc); + if (nouveau_bo_tile_layout(src_bo)) { + BEGIN_RING(chan, m2mf, + NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_IN, 1); + OUT_RING (chan, (sy << 16) | (sx * cpp)); + } else { + src_offset += (line_count * src_pitch); + } + if (nouveau_bo_tile_layout(dst_bo)) { + BEGIN_RING(chan, m2mf, + NV50_MEMORY_TO_MEMORY_FORMAT_TILING_POSITION_OUT, 1); + OUT_RING (chan, (dy << 16) | (dx * cpp)); + } else { + dst_offset += (line_count * dst_pitch); + } + BEGIN_RING(chan, m2mf, + NV04_MEMORY_TO_MEMORY_FORMAT_LINE_LENGTH_IN, 4); + OUT_RING (chan, width * cpp); + OUT_RING (chan, line_count); + OUT_RING (chan, 0x00000101); + OUT_RING (chan, 0); + FIRE_RING (chan); + + height -= line_count; + sy += line_count; + dy += line_count; + } +} + +struct pipe_transfer * +nv50_miptree_transfer_new(struct pipe_context *pcontext, + struct pipe_resource *pt, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct pipe_screen *pscreen = pcontext->screen; + struct nouveau_device *dev = nouveau_screen(pscreen)->device; + struct nv50_miptree *mt = nv50_miptree(pt); + struct nv50_miptree_level *lvl = &mt->level[level]; + struct nv50_transfer *tx; + unsigned nx, ny, image = 0, boxz = 0; + int ret; + + /* XXX can't unify these here? */ + if (pt->target == PIPE_TEXTURE_CUBE) + image = box->z; + else if (pt->target == PIPE_TEXTURE_3D) + boxz = box->z; + + tx = CALLOC_STRUCT(nv50_transfer); + if (!tx) + return NULL; + + /* Don't handle 3D transfers yet. + */ + assert(box->depth == 1); + + + pipe_resource_reference(&tx->base.resource, pt); + tx->base.level = level; + tx->base.usage = usage; + tx->base.box = *box; + tx->nblocksx = util_format_get_nblocksx(pt->format, u_minify(pt->width0, level)); + tx->nblocksy = util_format_get_nblocksy(pt->format, u_minify(pt->height0, level)); + tx->base.stride = tx->nblocksx * util_format_get_blocksize(pt->format); + tx->base.usage = usage; + + tx->level_pitch = lvl->pitch; + tx->level_width = u_minify(mt->base.base.width0, level); + tx->level_height = u_minify(mt->base.base.height0, level); + tx->level_depth = u_minify(mt->base.base.depth0, level); + tx->level_offset = lvl->image_offset[image]; + tx->level_tiling = lvl->tile_mode; + tx->level_z = boxz; + tx->level_x = util_format_get_nblocksx(pt->format, box->x); + tx->level_y = util_format_get_nblocksy(pt->format, box->y); + ret = nouveau_bo_new(dev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0, + tx->nblocksy * tx->base.stride, &tx->bo); + if (ret) { + FREE(tx); + return NULL; + } + + if (usage & PIPE_TRANSFER_READ) { + nx = util_format_get_nblocksx(pt->format, box->width); + ny = util_format_get_nblocksy(pt->format, box->height); + + nv50_transfer_rect_m2mf(pscreen, mt->base.bo, tx->level_offset, + tx->level_pitch, tx->level_tiling, + box->x, box->y, boxz, + tx->nblocksx, tx->nblocksy, + tx->level_depth, + tx->bo, 0, + tx->base.stride, tx->bo->tile_mode, + 0, 0, 0, + tx->nblocksx, tx->nblocksy, 1, + util_format_get_blocksize(pt->format), nx, ny, + NOUVEAU_BO_VRAM | NOUVEAU_BO_GART, + NOUVEAU_BO_GART); + } + + return &tx->base; +} + +void +nv50_miptree_transfer_del(struct pipe_context *pcontext, + struct pipe_transfer *ptx) +{ + struct nv50_transfer *tx = (struct nv50_transfer *)ptx; + struct nv50_miptree *mt = nv50_miptree(ptx->resource); + struct pipe_resource *pt = ptx->resource; + + unsigned nx = util_format_get_nblocksx(pt->format, tx->base.box.width); + unsigned ny = util_format_get_nblocksy(pt->format, tx->base.box.height); + + if (ptx->usage & PIPE_TRANSFER_WRITE) { + struct pipe_screen *pscreen = pcontext->screen; + + nv50_transfer_rect_m2mf(pscreen, tx->bo, 0, + tx->base.stride, tx->bo->tile_mode, + 0, 0, 0, + tx->nblocksx, tx->nblocksy, 1, + mt->base.bo, tx->level_offset, + tx->level_pitch, tx->level_tiling, + tx->level_x, tx->level_y, tx->level_z, + tx->nblocksx, tx->nblocksy, + tx->level_depth, + util_format_get_blocksize(pt->format), nx, ny, + NOUVEAU_BO_GART, NOUVEAU_BO_VRAM | + NOUVEAU_BO_GART); + } + + nouveau_bo_ref(NULL, &tx->bo); + pipe_resource_reference(&ptx->resource, NULL); + FREE(ptx); +} + +void * +nv50_miptree_transfer_map(struct pipe_context *pcontext, + struct pipe_transfer *ptx) +{ + struct nv50_transfer *tx = (struct nv50_transfer *)ptx; + unsigned flags = 0; + int ret; + + if (tx->map_refcnt++) + return tx->bo->map; + + if (ptx->usage & PIPE_TRANSFER_WRITE) + flags |= NOUVEAU_BO_WR; + if (ptx->usage & PIPE_TRANSFER_READ) + flags |= NOUVEAU_BO_RD; + + ret = nouveau_bo_map(tx->bo, flags); + if (ret) { + tx->map_refcnt = 0; + return NULL; + } + return tx->bo->map; +} + +void +nv50_miptree_transfer_unmap(struct pipe_context *pcontext, + struct pipe_transfer *ptx) +{ + struct nv50_transfer *tx = (struct nv50_transfer *)ptx; + + if (--tx->map_refcnt) + return; + nouveau_bo_unmap(tx->bo); +} + + +void +nv50_upload_sifc(struct nv50_context *nv50, + struct nouveau_bo *bo, unsigned dst_offset, unsigned reloc, + unsigned dst_format, int dst_w, int dst_h, int dst_pitch, + void *src, unsigned src_format, int src_pitch, + int x, int y, int w, int h, int cpp) +{ + struct nouveau_channel *chan = nv50->screen->base.channel; + struct nouveau_grobj *eng2d = nv50->screen->eng2d; + unsigned line_dwords = (w * cpp + 3) / 4; + + reloc |= NOUVEAU_BO_WR; + + MARK_RING (chan, 32, 2); /* flush on lack of space or relocs */ + + if (nouveau_bo_tile_layout(bo)) { + BEGIN_RING(chan, eng2d, NV50_2D_DST_FORMAT, 5); + OUT_RING (chan, dst_format); + OUT_RING (chan, 0); + OUT_RING (chan, bo->tile_mode << 4); + OUT_RING (chan, 1); + OUT_RING (chan, 0); + } else { + BEGIN_RING(chan, eng2d, NV50_2D_DST_FORMAT, 2); + OUT_RING (chan, dst_format); + OUT_RING (chan, 1); + BEGIN_RING(chan, eng2d, NV50_2D_DST_PITCH, 1); + OUT_RING (chan, dst_pitch); + } + + BEGIN_RING(chan, eng2d, NV50_2D_DST_WIDTH, 4); + OUT_RING (chan, dst_w); + OUT_RING (chan, dst_h); + OUT_RELOCh(chan, bo, dst_offset, reloc); + OUT_RELOCl(chan, bo, dst_offset, reloc); + + /* NV50_2D_OPERATION_SRCCOPY assumed already set */ + + BEGIN_RING(chan, eng2d, NV50_2D_SIFC_BITMAP_ENABLE, 2); + OUT_RING (chan, 0); + OUT_RING (chan, src_format); + BEGIN_RING(chan, eng2d, NV50_2D_SIFC_WIDTH, 10); + OUT_RING (chan, w); + OUT_RING (chan, h); + OUT_RING (chan, 0); + OUT_RING (chan, 1); + OUT_RING (chan, 0); + OUT_RING (chan, 1); + OUT_RING (chan, 0); + OUT_RING (chan, x); + OUT_RING (chan, 0); + OUT_RING (chan, y); + + while (h--) { + const uint32_t *p = src; + unsigned count = line_dwords; + + while (count) { + unsigned nr = MIN2(count, 1792); + + if (AVAIL_RING(chan) <= nr) { + FIRE_RING (chan); + + BEGIN_RING(chan, eng2d, + NV50_2D_DST_ADDRESS_HIGH, 2); + OUT_RELOCh(chan, bo, dst_offset, reloc); + OUT_RELOCl(chan, bo, dst_offset, reloc); + } + assert(AVAIL_RING(chan) > nr); + + BEGIN_RING(chan, eng2d, + NV50_2D_SIFC_DATA | (2 << 29), nr); + OUT_RINGp (chan, p, nr); + + p += nr; + count -= nr; + } + + src = (uint8_t *) src + src_pitch; + } +} diff --git a/src/gallium/drivers/nv50/nv50_transfer.h b/src/gallium/drivers/nv50/nv50_transfer.h new file mode 100644 index 0000000..6699bf5 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_transfer.h @@ -0,0 +1,31 @@ + +#ifndef NV50_TRANSFER_H +#define NV50_TRANSFER_H + +#include "pipe/p_state.h" + + +struct pipe_transfer * +nv50_miptree_transfer_new(struct pipe_context *pcontext, + struct pipe_resource *pt, + unsigned level, + unsigned usage, + const struct pipe_box *box); +void +nv50_miptree_transfer_del(struct pipe_context *pcontext, + struct pipe_transfer *ptx); +void * +nv50_miptree_transfer_map(struct pipe_context *pcontext, + struct pipe_transfer *ptx); +void +nv50_miptree_transfer_unmap(struct pipe_context *pcontext, + struct pipe_transfer *ptx); + +extern void +nv50_upload_sifc(struct nv50_context *nv50, + struct nouveau_bo *bo, unsigned dst_offset, unsigned reloc, + unsigned dst_format, int dst_w, int dst_h, int dst_pitch, + void *src, unsigned src_format, int src_pitch, + int x, int y, int w, int h, int cpp); + +#endif diff --git a/src/gallium/drivers/nv50/nv50_vbo.c b/src/gallium/drivers/nv50/nv50_vbo.c new file mode 100644 index 0000000..d41a59d --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_vbo.c @@ -0,0 +1,563 @@ +/* + * Copyright 2008 Ben Skeggs + * + * 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 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_context.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_split_prim.h" + +#include "nv50_context.h" +#include "nv50_resource.h" + +struct instance { + struct nouveau_bo *bo; + unsigned delta; + unsigned stride; + unsigned step; + unsigned divisor; +}; + +static void +instance_init(struct nv50_context *nv50, struct instance *a, unsigned first) +{ + int i; + + for (i = 0; i < nv50->vtxelt->num_elements; i++) { + struct pipe_vertex_element *ve = &nv50->vtxelt->pipe[i]; + struct pipe_vertex_buffer *vb; + + a[i].divisor = ve->instance_divisor; + if (a[i].divisor) { + vb = &nv50->vtxbuf[ve->vertex_buffer_index]; + + a[i].bo = nv50_resource(vb->buffer)->bo; + a[i].stride = vb->stride; + a[i].step = first % a[i].divisor; + a[i].delta = vb->buffer_offset + ve->src_offset + + (first * a[i].stride); + } + } +} + +static void +instance_step(struct nv50_context *nv50, struct instance *a) +{ + struct nouveau_channel *chan = nv50->screen->tesla->channel; + struct nouveau_grobj *tesla = nv50->screen->tesla; + int i; + + for (i = 0; i < nv50->vtxelt->num_elements; i++) { + if (!a[i].divisor) + continue; + + BEGIN_RING(chan, tesla, + NV50TCL_VERTEX_ARRAY_START_HIGH(i), 2); + OUT_RELOCh(chan, a[i].bo, a[i].delta, NOUVEAU_BO_RD | + NOUVEAU_BO_VRAM | NOUVEAU_BO_GART); + OUT_RELOCl(chan, a[i].bo, a[i].delta, NOUVEAU_BO_RD | + NOUVEAU_BO_VRAM | NOUVEAU_BO_GART); + if (++a[i].step == a[i].divisor) { + a[i].step = 0; + a[i].delta += a[i].stride; + } + } +} + +static void +nv50_draw_arrays_instanced(struct pipe_context *pipe, + unsigned mode, unsigned start, unsigned count, + unsigned startInstance, unsigned instanceCount) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nouveau_channel *chan = nv50->screen->tesla->channel; + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct instance a[16]; + unsigned prim = nv50_prim(mode); + + instance_init(nv50, a, startInstance); + if (!nv50_state_validate(nv50, 10 + 16*3)) + return; + + if (nv50->vbo_fifo) { + nv50_push_elements_instanced(pipe, NULL, 0, 0, mode, start, + count, startInstance, + instanceCount); + return; + } + + BEGIN_RING(chan, tesla, NV50TCL_CB_ADDR, 2); + OUT_RING (chan, NV50_CB_AUX | (24 << 8)); + OUT_RING (chan, startInstance); + while (instanceCount--) { + if (AVAIL_RING(chan) < (7 + 16*3)) { + FIRE_RING(chan); + if (!nv50_state_validate(nv50, 7 + 16*3)) { + assert(0); + return; + } + } + instance_step(nv50, a); + + BEGIN_RING(chan, tesla, NV50TCL_VERTEX_BEGIN, 1); + OUT_RING (chan, prim); + BEGIN_RING(chan, tesla, NV50TCL_VERTEX_BUFFER_FIRST, 2); + OUT_RING (chan, start); + OUT_RING (chan, count); + BEGIN_RING(chan, tesla, NV50TCL_VERTEX_END, 1); + OUT_RING (chan, 0); + + prim |= (1 << 28); + } +} + +struct inline_ctx { + struct nv50_context *nv50; + void *map; +}; + +static void +inline_elt08(void *priv, unsigned start, unsigned count) +{ + struct inline_ctx *ctx = priv; + struct nouveau_grobj *tesla = ctx->nv50->screen->tesla; + struct nouveau_channel *chan = tesla->channel; + uint8_t *map = (uint8_t *)ctx->map + start; + + if (count & 1) { + BEGIN_RING(chan, tesla, NV50TCL_VB_ELEMENT_U32, 1); + OUT_RING (chan, map[0]); + map++; + count &= ~1; + } + + count >>= 1; + if (!count) + return; + + BEGIN_RING_NI(chan, tesla, NV50TCL_VB_ELEMENT_U16, count); + while (count--) { + OUT_RING(chan, (map[1] << 16) | map[0]); + map += 2; + } +} + +static void +inline_elt16(void *priv, unsigned start, unsigned count) +{ + struct inline_ctx *ctx = priv; + struct nouveau_grobj *tesla = ctx->nv50->screen->tesla; + struct nouveau_channel *chan = tesla->channel; + uint16_t *map = (uint16_t *)ctx->map + start; + + if (count & 1) { + BEGIN_RING(chan, tesla, NV50TCL_VB_ELEMENT_U32, 1); + OUT_RING (chan, map[0]); + count &= ~1; + map++; + } + + count >>= 1; + if (!count) + return; + + BEGIN_RING_NI(chan, tesla, NV50TCL_VB_ELEMENT_U16, count); + while (count--) { + OUT_RING(chan, (map[1] << 16) | map[0]); + map += 2; + } +} + +static void +inline_elt32(void *priv, unsigned start, unsigned count) +{ + struct inline_ctx *ctx = priv; + struct nouveau_grobj *tesla = ctx->nv50->screen->tesla; + struct nouveau_channel *chan = tesla->channel; + + BEGIN_RING_NI(chan, tesla, NV50TCL_VB_ELEMENT_U32, count); + OUT_RINGp (chan, (uint32_t *)ctx->map + start, count); +} + +static void +inline_edgeflag(void *priv, boolean enabled) +{ + struct inline_ctx *ctx = priv; + struct nouveau_grobj *tesla = ctx->nv50->screen->tesla; + struct nouveau_channel *chan = tesla->channel; + + BEGIN_RING(chan, tesla, NV50TCL_EDGEFLAG_ENABLE, 1); + OUT_RING (chan, enabled ? 1 : 0); +} + +static void +nv50_draw_elements_inline(struct pipe_context *pipe, + struct pipe_resource *indexBuffer, unsigned indexSize, + unsigned mode, unsigned start, unsigned count, + unsigned startInstance, unsigned instanceCount) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nouveau_channel *chan = nv50->screen->tesla->channel; + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct pipe_transfer *transfer; + struct instance a[16]; + struct inline_ctx ctx; + struct util_split_prim s; + boolean nzi = FALSE; + unsigned overhead; + + overhead = 16*3; /* potential instance adjustments */ + overhead += 4; /* Begin()/End() */ + overhead += 4; /* potential edgeflag disable/reenable */ + overhead += 3; /* potentially 3 VTX_ELT_U16/U32 packet headers */ + + s.priv = &ctx; + if (indexSize == 1) + s.emit = inline_elt08; + else + if (indexSize == 2) + s.emit = inline_elt16; + else + s.emit = inline_elt32; + s.edge = inline_edgeflag; + + ctx.nv50 = nv50; + ctx.map = pipe_buffer_map(pipe, indexBuffer, PIPE_TRANSFER_READ, &transfer); + assert(ctx.map); + if (!ctx.map) + return; + + instance_init(nv50, a, startInstance); + if (!nv50_state_validate(nv50, overhead + 6 + 3)) + return; + + BEGIN_RING(chan, tesla, NV50TCL_CB_ADDR, 2); + OUT_RING (chan, NV50_CB_AUX | (24 << 8)); + OUT_RING (chan, startInstance); + while (instanceCount--) { + unsigned max_verts; + boolean done; + + util_split_prim_init(&s, mode, start, count); + do { + if (AVAIL_RING(chan) < (overhead + 6)) { + FIRE_RING(chan); + if (!nv50_state_validate(nv50, (overhead + 6))) { + assert(0); + return; + } + } + + max_verts = AVAIL_RING(chan) - overhead; + if (max_verts > 2047) + max_verts = 2047; + if (indexSize != 4) + max_verts <<= 1; + instance_step(nv50, a); + + BEGIN_RING(chan, tesla, NV50TCL_VERTEX_BEGIN, 1); + OUT_RING (chan, nv50_prim(s.mode) | (nzi ? (1<<28) : 0)); + done = util_split_prim_next(&s, max_verts); + BEGIN_RING(chan, tesla, NV50TCL_VERTEX_END, 1); + OUT_RING (chan, 0); + } while (!done); + + nzi = TRUE; + } + + pipe_buffer_unmap(pipe, indexBuffer, transfer); +} + +static void +nv50_draw_elements_instanced(struct pipe_context *pipe, + struct pipe_resource *indexBuffer, + unsigned indexSize, int indexBias, + unsigned mode, unsigned start, unsigned count, + unsigned startInstance, unsigned instanceCount) +{ + struct nv50_context *nv50 = nv50_context(pipe); + struct nouveau_channel *chan = nv50->screen->tesla->channel; + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct instance a[16]; + unsigned prim = nv50_prim(mode); + + instance_init(nv50, a, startInstance); + if (!nv50_state_validate(nv50, 13 + 16*3)) + return; + + if (nv50->vbo_fifo) { + nv50_push_elements_instanced(pipe, indexBuffer, indexSize, + indexBias, mode, start, count, + startInstance, instanceCount); + return; + } + + /* indices are uint32 internally, so large indexBias means negative */ + BEGIN_RING(chan, tesla, NV50TCL_VB_ELEMENT_BASE, 1); + OUT_RING (chan, indexBias); + + if (!nv50_resource_mapped_by_gpu(indexBuffer) || indexSize == 1) { + nv50_draw_elements_inline(pipe, indexBuffer, indexSize, + mode, start, count, startInstance, + instanceCount); + return; + } + + BEGIN_RING(chan, tesla, NV50TCL_CB_ADDR, 2); + OUT_RING (chan, NV50_CB_AUX | (24 << 8)); + OUT_RING (chan, startInstance); + while (instanceCount--) { + if (AVAIL_RING(chan) < (7 + 16*3)) { + FIRE_RING(chan); + if (!nv50_state_validate(nv50, 10 + 16*3)) { + assert(0); + return; + } + } + instance_step(nv50, a); + + BEGIN_RING(chan, tesla, NV50TCL_VERTEX_BEGIN, 1); + OUT_RING (chan, prim); + if (indexSize == 4) { + BEGIN_RING(chan, tesla, NV50TCL_VB_ELEMENT_U32 | 0x30000, 0); + OUT_RING (chan, count); + nouveau_pushbuf_submit(chan, + nv50_resource(indexBuffer)->bo, + start << 2, count << 2); + } else + if (indexSize == 2) { + unsigned vb_start = (start & ~1); + unsigned vb_end = (start + count + 1) & ~1; + unsigned dwords = (vb_end - vb_start) >> 1; + + BEGIN_RING(chan, tesla, NV50TCL_VB_ELEMENT_U16_SETUP, 1); + OUT_RING (chan, ((start & 1) << 31) | count); + BEGIN_RING(chan, tesla, NV50TCL_VB_ELEMENT_U16 | 0x30000, 0); + OUT_RING (chan, dwords); + nouveau_pushbuf_submit(chan, + nv50_resource(indexBuffer)->bo, + vb_start << 1, dwords << 2); + BEGIN_RING(chan, tesla, NV50TCL_VB_ELEMENT_U16_SETUP, 1); + OUT_RING (chan, 0); + } + BEGIN_RING(chan, tesla, NV50TCL_VERTEX_END, 1); + OUT_RING (chan, 0); + + prim |= (1 << 28); + } +} + +void +nv50_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) +{ + struct nv50_context *nv50 = nv50_context(pipe); + + if (info->indexed && nv50->idxbuf.buffer) { + unsigned offset; + + assert(nv50->idxbuf.offset % nv50->idxbuf.index_size == 0); + offset = nv50->idxbuf.offset / nv50->idxbuf.index_size; + + nv50_draw_elements_instanced(pipe, + nv50->idxbuf.buffer, + nv50->idxbuf.index_size, + info->index_bias, + info->mode, + info->start + offset, + info->count, + info->start_instance, + info->instance_count); + } + else { + nv50_draw_arrays_instanced(pipe, + info->mode, + info->start, + info->count, + info->start_instance, + info->instance_count); + } +} + +static INLINE boolean +nv50_vbo_static_attrib(struct nv50_context *nv50, unsigned attrib, + struct nouveau_stateobj **pso, + struct pipe_vertex_element *ve, + struct pipe_vertex_buffer *vb) + +{ + struct nouveau_stateobj *so; + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_bo *bo = nv50_resource(vb->buffer)->bo; + float v[4]; + int ret; + unsigned nr_components = util_format_get_nr_components(ve->src_format); + + ret = nouveau_bo_map(bo, NOUVEAU_BO_RD); + if (ret) + return FALSE; + + util_format_read_4f(ve->src_format, v, 0, (uint8_t *)bo->map + + (vb->buffer_offset + ve->src_offset), 0, + 0, 0, 1, 1); + so = *pso; + if (!so) + *pso = so = so_new(nv50->vtxelt->num_elements, + nv50->vtxelt->num_elements * 4, 0); + + switch (nr_components) { + case 4: + so_method(so, tesla, NV50TCL_VTX_ATTR_4F_X(attrib), 4); + so_data (so, fui(v[0])); + so_data (so, fui(v[1])); + so_data (so, fui(v[2])); + so_data (so, fui(v[3])); + break; + case 3: + so_method(so, tesla, NV50TCL_VTX_ATTR_3F_X(attrib), 3); + so_data (so, fui(v[0])); + so_data (so, fui(v[1])); + so_data (so, fui(v[2])); + break; + case 2: + so_method(so, tesla, NV50TCL_VTX_ATTR_2F_X(attrib), 2); + so_data (so, fui(v[0])); + so_data (so, fui(v[1])); + break; + case 1: + if (attrib == nv50->vertprog->vp.edgeflag) { + so_method(so, tesla, NV50TCL_EDGEFLAG_ENABLE, 1); + so_data (so, v[0] ? 1 : 0); + } + so_method(so, tesla, NV50TCL_VTX_ATTR_1F(attrib), 1); + so_data (so, fui(v[0])); + break; + default: + nouveau_bo_unmap(bo); + return FALSE; + } + + nouveau_bo_unmap(bo); + return TRUE; +} + +void +nv50_vtxelt_construct(struct nv50_vtxelt_stateobj *cso) +{ + unsigned i; + + for (i = 0; i < cso->num_elements; ++i) + cso->hw[i] = nv50_format_table[cso->pipe[i].src_format].vtx; +} + +struct nouveau_stateobj * +nv50_vbo_validate(struct nv50_context *nv50) +{ + struct nouveau_grobj *tesla = nv50->screen->tesla; + struct nouveau_stateobj *vtxbuf, *vtxfmt, *vtxattr; + unsigned i, n_ve; + + /* don't validate if Gallium took away our buffers */ + if (nv50->vtxbuf_nr == 0) + return NULL; + + nv50->vbo_fifo = 0; + if (nv50->screen->force_push || + nv50->vertprog->vp.edgeflag < 16) + nv50->vbo_fifo = 0xffff; + + for (i = 0; i < nv50->vtxbuf_nr; i++) { + if (nv50->vtxbuf[i].stride && + !nv50_resource_mapped_by_gpu(nv50->vtxbuf[i].buffer)) + nv50->vbo_fifo = 0xffff; + } + + n_ve = MAX2(nv50->vtxelt->num_elements, nv50->state.vtxelt_nr); + + vtxattr = NULL; + vtxbuf = so_new(n_ve * 2, n_ve * 5, nv50->vtxelt->num_elements * 4); + vtxfmt = so_new(1, n_ve, 0); + so_method(vtxfmt, tesla, NV50TCL_VERTEX_ARRAY_ATTRIB(0), n_ve); + + for (i = 0; i < nv50->vtxelt->num_elements; i++) { + struct pipe_vertex_element *ve = &nv50->vtxelt->pipe[i]; + struct pipe_vertex_buffer *vb = + &nv50->vtxbuf[ve->vertex_buffer_index]; + struct nouveau_bo *bo = nv50_resource(vb->buffer)->bo; + uint32_t hw = nv50->vtxelt->hw[i]; + + if (!vb->stride && + nv50_vbo_static_attrib(nv50, i, &vtxattr, ve, vb)) { + so_data(vtxfmt, hw | (1 << 4)); + + so_method(vtxbuf, tesla, + NV50TCL_VERTEX_ARRAY_FORMAT(i), 1); + so_data (vtxbuf, 0); + + nv50->vbo_fifo &= ~(1 << i); + continue; + } + + if (nv50->vbo_fifo) { + so_data (vtxfmt, hw | (ve->instance_divisor ? (1 << 4) : i)); + so_method(vtxbuf, tesla, + NV50TCL_VERTEX_ARRAY_FORMAT(i), 1); + so_data (vtxbuf, 0); + continue; + } + + so_data(vtxfmt, hw | i); + + so_method(vtxbuf, tesla, NV50TCL_VERTEX_ARRAY_FORMAT(i), 3); + so_data (vtxbuf, 0x20000000 | + (ve->instance_divisor ? 0 : vb->stride)); + so_reloc (vtxbuf, bo, vb->buffer_offset + + ve->src_offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | + NOUVEAU_BO_RD | NOUVEAU_BO_HIGH, 0, 0); + so_reloc (vtxbuf, bo, vb->buffer_offset + + ve->src_offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | + NOUVEAU_BO_RD | NOUVEAU_BO_LOW, 0, 0); + + /* vertex array limits */ + so_method(vtxbuf, tesla, NV50TCL_VERTEX_ARRAY_LIMIT_HIGH(i), 2); + so_reloc (vtxbuf, bo, vb->buffer->width0 - 1, + NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD | + NOUVEAU_BO_HIGH, 0, 0); + so_reloc (vtxbuf, bo, vb->buffer->width0 - 1, + NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD | + NOUVEAU_BO_LOW, 0, 0); + } + for (; i < n_ve; ++i) { + so_data (vtxfmt, 0x7e080010); + + so_method(vtxbuf, tesla, NV50TCL_VERTEX_ARRAY_FORMAT(i), 1); + so_data (vtxbuf, 0); + } + nv50->state.vtxelt_nr = nv50->vtxelt->num_elements; + + so_ref (vtxbuf, &nv50->state.vtxbuf); + so_ref (vtxattr, &nv50->state.vtxattr); + so_ref (NULL, &vtxbuf); + so_ref (NULL, &vtxattr); + return vtxfmt; +} + + diff --git a/src/gallium/drivers/nvfx/Makefile b/src/gallium/drivers/nvfx/Makefile new file mode 100644 index 0000000..46bb082 --- /dev/null +++ b/src/gallium/drivers/nvfx/Makefile @@ -0,0 +1,32 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = nvfx + +C_SOURCES = \ + nv04_2d.c \ + nvfx_buffer.c \ + nvfx_context.c \ + nvfx_clear.c \ + nvfx_draw.c \ + nvfx_fragprog.c \ + nvfx_fragtex.c \ + nv30_fragtex.c \ + nv40_fragtex.c \ + nvfx_miptree.c \ + nvfx_push.c \ + nvfx_query.c \ + nvfx_resource.c \ + nvfx_screen.c \ + nvfx_state.c \ + nvfx_state_emit.c \ + nvfx_state_fb.c \ + nvfx_surface.c \ + nvfx_transfer.c \ + nvfx_vbo.c \ + nvfx_vertprog.c + +LIBRARY_INCLUDES = \ + -I$(TOP)/src/gallium/drivers/nouveau/include + +include ../../Makefile.template diff --git a/src/gallium/drivers/nvfx/SConscript b/src/gallium/drivers/nvfx/SConscript new file mode 100644 index 0000000..f1041e7 --- /dev/null +++ b/src/gallium/drivers/nvfx/SConscript @@ -0,0 +1,35 @@ +Import('*') + +env = env.Clone() + +env.PrependUnique(delete_existing=1, CPPPATH = [ + '#/src/gallium/drivers', +]) + +nvfx = env.ConvenienceLibrary( + target = 'nvfx', + source = [ + 'nv04_2d.c', + 'nvfx_buffer.c', + 'nvfx_context.c', + 'nvfx_clear.c', + 'nvfx_draw.c', + 'nvfx_fragprog.c', + 'nvfx_fragtex.c', + 'nv30_fragtex.c', + 'nv40_fragtex.c', + 'nvfx_miptree.c', + 'nvfx_push.c', + 'nvfx_query.c', + 'nvfx_resource.c', + 'nvfx_screen.c', + 'nvfx_state.c', + 'nvfx_state_emit.c', + 'nvfx_state_fb.c', + 'nvfx_surface.c', + 'nvfx_transfer.c', + 'nvfx_vbo.c', + 'nvfx_vertprog.c', + ]) + +Export('nvfx') diff --git a/src/gallium/drivers/nvfx/nv01_2d.xml.h b/src/gallium/drivers/nvfx/nv01_2d.xml.h new file mode 100644 index 0000000..b963eb7 --- /dev/null +++ b/src/gallium/drivers/nvfx/nv01_2d.xml.h @@ -0,0 +1,1343 @@ +#ifndef NV01_2D_XML +#define NV01_2D_XML + +/* Autogenerated file, DO NOT EDIT manually! + +This file was generated by the rules-ng-ng headergen tool in this git repository: +http://0x04.net/cgit/index.cgi/rules-ng-ng +git clone git://0x04.net/rules-ng-ng + +The rules-ng-ng source files this header was generated from are: +- nv01_2d.xml ( 33462 bytes, from 2010-08-05 19:38:53) +- copyright.xml ( 6503 bytes, from 2010-04-10 23:15:50) +- nv_defs.xml ( 4437 bytes, from 2010-08-05 19:38:53) +- nv_object.xml ( 10424 bytes, from 2010-08-05 19:38:53) +- nvchipsets.xml ( 2824 bytes, from 2010-08-05 19:38:53) + +Copyright (C) 2006-2010 by the following authors: +- Artur Huillet (ahuillet) +- Ben Skeggs (darktama, darktama_) +- B. R. (koala_br) +- Carlos Martin (carlosmn) +- Christoph Bumiller (calim, chrisbmr) +- Dawid Gajownik (gajownik) +- Dmitry Baryshkov +- Dmitry Eremin-Solenikov (lumag) +- EdB (edb_) +- Erik Waling (erikwaling) +- Francisco Jerez (curro, curro_, currojerez) +- imirkin (imirkin) +- jb17bsome (jb17bsome) +- Jeremy Kolb (kjeremy) +- Laurent Carlier (lordheavy) +- Luca Barbieri (lb, lb1) +- Maarten Maathuis (stillunknown) +- Marcin Kościelnicki (mwk, koriakin) +- Mark Carey (careym) +- Matthieu Castet (mat-c) +- nvidiaman (nvidiaman) +- Patrice Mandin (pmandin, pmdata) +- Pekka Paalanen (pq, ppaalanen) +- Peter Popov (ironpeter) +- Richard Hughes (hughsient) +- Rudi Cilibrasi (cilibrar) +- Serge Martin +- Simon Raffeiner +- Stephane Loeuillet (leroutier) +- Stephane Marchesin (marcheu) +- sturmflut (sturmflut) +- Sylvain Munaut +- Victor Stinner (haypo) +- Wladmir van der Laan (miathan6) +- Younes Manton (ymanton) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + + + +#define NV01_CONTEXT_BETA1_DMA_NOTIFY 0x00000180 + +#define NV01_CONTEXT_BETA1_BETA_1D31 0x00000300 + + +#define NV04_BETA_SOLID_DMA_NOTIFY 0x00000180 + +#define NV04_BETA_SOLID_BETA_FACTOR 0x00000300 + + +#define NV01_CONTEXT_COLOR_KEY_DMA_NOTIFY 0x00000180 + +#define NV01_CONTEXT_COLOR_KEY_COLOR_FORMAT 0x00000300 +#define NV01_CONTEXT_COLOR_KEY_COLOR_FORMAT_A16R5G6B5 0x00000001 +#define NV01_CONTEXT_COLOR_KEY_COLOR_FORMAT_X16A1R5G5B5 0x00000002 +#define NV01_CONTEXT_COLOR_KEY_COLOR_FORMAT_A8R8G8B8 0x00000003 + +#define NV01_CONTEXT_COLOR_KEY_COLOR 0x00000304 + + +#define NV01_CONTEXT_PATTERN_DMA_NOTIFY 0x00000180 + +#define NV01_CONTEXT_PATTERN_COLOR_FORMAT 0x00000300 + +#define NV01_CONTEXT_PATTERN_MONOCHROME_FORMAT 0x00000304 + +#define NV01_CONTEXT_PATTERN_SHAPE 0x00000308 + +#define NV01_CONTEXT_PATTERN_COLOR(i0) (0x00000310 + 0x4*(i0)) +#define NV01_CONTEXT_PATTERN_COLOR__ESIZE 0x00000004 +#define NV01_CONTEXT_PATTERN_COLOR__LEN 0x00000002 + +#define NV01_CONTEXT_PATTERN_PATTERN(i0) (0x00000318 + 0x4*(i0)) +#define NV01_CONTEXT_PATTERN_PATTERN__ESIZE 0x00000004 +#define NV01_CONTEXT_PATTERN_PATTERN__LEN 0x00000002 + + +#define NV01_CONTEXT_CLIP_RECTANGLE_DMA_NOTIFY 0x00000180 + +#define NV01_CONTEXT_CLIP_RECTANGLE_POINT 0x00000300 +#define NV01_CONTEXT_CLIP_RECTANGLE_POINT_X__MASK 0x0000ffff +#define NV01_CONTEXT_CLIP_RECTANGLE_POINT_X__SHIFT 0 +#define NV01_CONTEXT_CLIP_RECTANGLE_POINT_Y__MASK 0xffff0000 +#define NV01_CONTEXT_CLIP_RECTANGLE_POINT_Y__SHIFT 16 + +#define NV01_CONTEXT_CLIP_RECTANGLE_SIZE 0x00000304 +#define NV01_CONTEXT_CLIP_RECTANGLE_SIZE_W__MASK 0x0000ffff +#define NV01_CONTEXT_CLIP_RECTANGLE_SIZE_W__SHIFT 0 +#define NV01_CONTEXT_CLIP_RECTANGLE_SIZE_H__MASK 0xffff0000 +#define NV01_CONTEXT_CLIP_RECTANGLE_SIZE_H__SHIFT 16 + + +#define NV04_CONTEXT_SURFACES_2D_DMA_NOTIFY 0x00000180 + +#define NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE 0x00000184 + +#define NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_DESTIN 0x00000188 + + +#define NV50_CONTEXT_SURFACES_2D_SRC_LINEAR 0x00000200 + +#define NV50_CONTEXT_SURFACES_2D_SRC_TILE_MODE 0x00000204 + +#define NV50_CONTEXT_SURFACES_2D_SRC_WIDTH 0x00000208 + +#define NV50_CONTEXT_SURFACES_2D_SRC_HEIGHT 0x0000020c + +#define NV50_CONTEXT_SURFACES_2D_UNK0210 0x00000210 + +#define NV50_CONTEXT_SURFACES_2D_UNK0214 0x00000214 + +#define NV50_CONTEXT_SURFACES_2D_DST_LINEAR 0x00000218 + +#define NV50_CONTEXT_SURFACES_2D_DST_TILE_MODE 0x0000021c + +#define NV50_CONTEXT_SURFACES_2D_DST_WIDTH 0x00000220 + +#define NV50_CONTEXT_SURFACES_2D_DST_HEIGHT 0x00000224 + +#define NV50_CONTEXT_SURFACES_2D_UNK0228 0x00000228 + +#define NV50_CONTEXT_SURFACES_2D_UNK022C 0x0000022c + +#define NV50_CONTEXT_SURFACES_2D_OFFSET_SOURCE_HIGH 0x00000230 + +#define NV50_CONTEXT_SURFACES_2D_OFFSET_DESTIN_HIGH 0x00000234 + +#define NV04_CONTEXT_SURFACES_2D_FORMAT 0x00000300 +#define NV04_CONTEXT_SURFACES_2D_FORMAT_Y8 0x00000001 +#define NV04_CONTEXT_SURFACES_2D_FORMAT_X1R5G5B5_Z1R5G5B5 0x00000002 +#define NV04_CONTEXT_SURFACES_2D_FORMAT_X1R5G5B5_X1R5G5B5 0x00000003 +#define NV04_CONTEXT_SURFACES_2D_FORMAT_R5G6B5 0x00000004 +#define NV04_CONTEXT_SURFACES_2D_FORMAT_Y16 0x00000005 +#define NV04_CONTEXT_SURFACES_2D_FORMAT_X8R8G8B8_Z8R8G8B8 0x00000006 +#define NV04_CONTEXT_SURFACES_2D_FORMAT_X8R8G8B8_X8R8G8B8 0x00000007 +#define NV04_CONTEXT_SURFACES_2D_FORMAT_X1A7R8G8B8_Z1A7R8G8B8 0x00000008 +#define NV04_CONTEXT_SURFACES_2D_FORMAT_X1A7R8G8B8_X1A7R8G8B8 0x00000009 +#define NV04_CONTEXT_SURFACES_2D_FORMAT_A8R8G8B8 0x0000000a +#define NV04_CONTEXT_SURFACES_2D_FORMAT_Y32 0x0000000b + +#define NV04_CONTEXT_SURFACES_2D_PITCH 0x00000304 +#define NV04_CONTEXT_SURFACES_2D_PITCH_SOURCE__MASK 0x0000ffff +#define NV04_CONTEXT_SURFACES_2D_PITCH_SOURCE__SHIFT 0 +#define NV04_CONTEXT_SURFACES_2D_PITCH_DESTIN__MASK 0xffff0000 +#define NV04_CONTEXT_SURFACES_2D_PITCH_DESTIN__SHIFT 16 + +#define NV04_CONTEXT_SURFACES_2D_OFFSET_SOURCE 0x00000308 + +#define NV04_CONTEXT_SURFACES_2D_OFFSET_DESTIN 0x0000030c + + +#define NV04_SWIZZLED_SURFACE_DMA_NOTIFY 0x00000180 + +#define NV04_SWIZZLED_SURFACE_DMA_IMAGE 0x00000184 + +#define NV04_SWIZZLED_SURFACE_FORMAT 0x00000300 +#define NV04_SWIZZLED_SURFACE_FORMAT_COLOR__MASK 0x000000ff +#define NV04_SWIZZLED_SURFACE_FORMAT_COLOR__SHIFT 0 +#define NV04_SWIZZLED_SURFACE_FORMAT_COLOR_Y8 0x00000001 +#define NV04_SWIZZLED_SURFACE_FORMAT_COLOR_X1R5G5B5_Z1R5G5B5 0x00000002 +#define NV04_SWIZZLED_SURFACE_FORMAT_COLOR_X1R5G5B5_X1R5G5B5 0x00000003 +#define NV04_SWIZZLED_SURFACE_FORMAT_COLOR_R5G6B5 0x00000004 +#define NV04_SWIZZLED_SURFACE_FORMAT_COLOR_Y16 0x00000005 +#define NV04_SWIZZLED_SURFACE_FORMAT_COLOR_X8R8G8B8_Z8R8G8B8 0x00000006 +#define NV04_SWIZZLED_SURFACE_FORMAT_COLOR_X8R8G8B8_X8R8G8B8 0x00000007 +#define NV04_SWIZZLED_SURFACE_FORMAT_COLOR_X1A7R8G8B8_Z1A7R8G8B8 0x00000008 +#define NV04_SWIZZLED_SURFACE_FORMAT_COLOR_X1A7R8G8B8_X1A7R8G8B8 0x00000009 +#define NV04_SWIZZLED_SURFACE_FORMAT_COLOR_A8R8G8B8 0x0000000a +#define NV04_SWIZZLED_SURFACE_FORMAT_COLOR_Y32 0x0000000b +#define NV04_SWIZZLED_SURFACE_FORMAT_BASE_SIZE_U__MASK 0x00ff0000 +#define NV04_SWIZZLED_SURFACE_FORMAT_BASE_SIZE_U__SHIFT 16 +#define NV04_SWIZZLED_SURFACE_FORMAT_BASE_SIZE_V__MASK 0xff000000 +#define NV04_SWIZZLED_SURFACE_FORMAT_BASE_SIZE_V__SHIFT 24 + +#define NV04_SWIZZLED_SURFACE_OFFSET 0x00000304 + + +#define NV03_CONTEXT_ROP_DMA_NOTIFY 0x00000180 + +#define NV03_CONTEXT_ROP_ROP 0x00000300 + + +#define NV04_IMAGE_PATTERN_DMA_NOTIFY 0x00000180 + +#define NV04_IMAGE_PATTERN_COLOR_FORMAT 0x00000300 +#define NV04_IMAGE_PATTERN_COLOR_FORMAT_A16R5G6B5 0x00000001 +#define NV04_IMAGE_PATTERN_COLOR_FORMAT_X16A1R5G5B5 0x00000002 +#define NV04_IMAGE_PATTERN_COLOR_FORMAT_A8R8G8B8 0x00000003 + +#define NV04_IMAGE_PATTERN_MONOCHROME_FORMAT 0x00000304 +#define NV04_IMAGE_PATTERN_MONOCHROME_FORMAT_CGA6 0x00000001 +#define NV04_IMAGE_PATTERN_MONOCHROME_FORMAT_LE 0x00000002 + +#define NV04_IMAGE_PATTERN_MONOCHROME_SHAPE 0x00000308 +#define NV04_IMAGE_PATTERN_MONOCHROME_SHAPE_8X8 0x00000000 +#define NV04_IMAGE_PATTERN_MONOCHROME_SHAPE_64X1 0x00000001 +#define NV04_IMAGE_PATTERN_MONOCHROME_SHAPE_1X64 0x00000002 + +#define NV04_IMAGE_PATTERN_PATTERN_SELECT 0x0000030c +#define NV04_IMAGE_PATTERN_PATTERN_SELECT_MONO 0x00000001 +#define NV04_IMAGE_PATTERN_PATTERN_SELECT_COLOR 0x00000002 + +#define NV04_IMAGE_PATTERN_MONOCHROME_COLOR0 0x00000310 + +#define NV04_IMAGE_PATTERN_MONOCHROME_COLOR1 0x00000314 + +#define NV04_IMAGE_PATTERN_MONOCHROME_PATTERN0 0x00000318 + +#define NV04_IMAGE_PATTERN_MONOCHROME_PATTERN1 0x0000031c + +#define NV04_IMAGE_PATTERN_PATTERN_Y8(i0) (0x00000400 + 0x4*(i0)) +#define NV04_IMAGE_PATTERN_PATTERN_Y8__ESIZE 0x00000004 +#define NV04_IMAGE_PATTERN_PATTERN_Y8__LEN 0x00000010 +#define NV04_IMAGE_PATTERN_PATTERN_Y8_Y0__MASK 0x000000ff +#define NV04_IMAGE_PATTERN_PATTERN_Y8_Y0__SHIFT 0 +#define NV04_IMAGE_PATTERN_PATTERN_Y8_Y1__MASK 0x0000ff00 +#define NV04_IMAGE_PATTERN_PATTERN_Y8_Y1__SHIFT 8 +#define NV04_IMAGE_PATTERN_PATTERN_Y8_Y2__MASK 0x00ff0000 +#define NV04_IMAGE_PATTERN_PATTERN_Y8_Y2__SHIFT 16 +#define NV04_IMAGE_PATTERN_PATTERN_Y8_Y3__MASK 0xff000000 +#define NV04_IMAGE_PATTERN_PATTERN_Y8_Y3__SHIFT 24 + +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5(i0) (0x00000500 + 0x4*(i0)) +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5__ESIZE 0x00000004 +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5__LEN 0x00000020 +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5_B0__MASK 0x0000001f +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5_B0__SHIFT 0 +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5_G0__MASK 0x000007e0 +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5_G0__SHIFT 5 +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5_R0__MASK 0x0000f800 +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5_R0__SHIFT 11 +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5_B1__MASK 0x001f0000 +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5_B1__SHIFT 16 +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5_G1__MASK 0x07e00000 +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5_G1__SHIFT 21 +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5_R1__MASK 0xf8000000 +#define NV04_IMAGE_PATTERN_PATTERN_R5G6B5_R1__SHIFT 27 + +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5(i0) (0x00000600 + 0x4*(i0)) +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5__ESIZE 0x00000004 +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5__LEN 0x00000020 +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5_B0__MASK 0x0000001f +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5_B0__SHIFT 0 +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5_G0__MASK 0x000003e0 +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5_G0__SHIFT 5 +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5_R0__MASK 0x00007c00 +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5_R0__SHIFT 10 +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5_B1__MASK 0x001f0000 +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5_B1__SHIFT 16 +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5_G1__MASK 0x03e00000 +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5_G1__SHIFT 21 +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5_R1__MASK 0x7c000000 +#define NV04_IMAGE_PATTERN_PATTERN_X1R5G5B5_R1__SHIFT 26 + +#define NV04_IMAGE_PATTERN_PATTERN_X8R8G8B8(i0) (0x00000700 + 0x4*(i0)) +#define NV04_IMAGE_PATTERN_PATTERN_X8R8G8B8__ESIZE 0x00000004 +#define NV04_IMAGE_PATTERN_PATTERN_X8R8G8B8__LEN 0x00000040 +#define NV04_IMAGE_PATTERN_PATTERN_X8R8G8B8_B__MASK 0x000000ff +#define NV04_IMAGE_PATTERN_PATTERN_X8R8G8B8_B__SHIFT 0 +#define NV04_IMAGE_PATTERN_PATTERN_X8R8G8B8_G__MASK 0x0000ff00 +#define NV04_IMAGE_PATTERN_PATTERN_X8R8G8B8_G__SHIFT 8 +#define NV04_IMAGE_PATTERN_PATTERN_X8R8G8B8_R__MASK 0x00ff0000 +#define NV04_IMAGE_PATTERN_PATTERN_X8R8G8B8_R__SHIFT 16 + + +#define NV01_RENDER_SOLID_LINE_PATCH 0x0000010c + +#define NV01_RENDER_SOLID_LINE_DMA_NOTIFY 0x00000180 + +#define NV01_RENDER_SOLID_LINE_CLIP_RECTANGLE 0x00000184 + +#define NV01_RENDER_SOLID_LINE_PATTERN 0x00000188 + +#define NV04_RENDER_SOLID_LINE_PATTERN 0x00000188 + +#define NV01_RENDER_SOLID_LINE_ROP 0x0000018c + +#define NV01_RENDER_SOLID_LINE_BETA1 0x00000190 + +#define NV01_RENDER_SOLID_LINE_SURFACE_DST 0x00000194 + + +#define NV04_RENDER_SOLID_LINE_BETA4 0x00000194 + +#define NV04_RENDER_SOLID_LINE_SURFACE 0x00000198 + +#define NV01_RENDER_SOLID_LINE_OPERATION 0x000002fc +#define NV01_RENDER_SOLID_LINE_OPERATION_SRCCOPY_AND 0x00000000 +#define NV01_RENDER_SOLID_LINE_OPERATION_ROP_AND 0x00000001 +#define NV01_RENDER_SOLID_LINE_OPERATION_BLEND_AND 0x00000002 +#define NV01_RENDER_SOLID_LINE_OPERATION_SRCCOPY 0x00000003 +#define NV01_RENDER_SOLID_LINE_OPERATION_SRCCOPY_PREMULT 0x00000004 +#define NV01_RENDER_SOLID_LINE_OPERATION_BLEND_PREMULT 0x00000005 + +#define NV01_RENDER_SOLID_LINE_COLOR_FORMAT 0x00000300 +#define NV01_RENDER_SOLID_LINE_COLOR_FORMAT_A16R5G6B5 0x00000001 +#define NV01_RENDER_SOLID_LINE_COLOR_FORMAT_X16A1R5G5B5 0x00000002 +#define NV01_RENDER_SOLID_LINE_COLOR_FORMAT_A8R8G8B8 0x00000003 + +#define NV01_RENDER_SOLID_LINE_COLOR 0x00000304 + +#define NV01_RENDER_SOLID_LINE_LINE_POINT0(i0) (0x00000400 + 0x8*(i0)) +#define NV01_RENDER_SOLID_LINE_LINE_POINT0__ESIZE 0x00000008 +#define NV01_RENDER_SOLID_LINE_LINE_POINT0__LEN 0x00000010 +#define NV01_RENDER_SOLID_LINE_LINE_POINT0_X__MASK 0x0000ffff +#define NV01_RENDER_SOLID_LINE_LINE_POINT0_X__SHIFT 0 +#define NV01_RENDER_SOLID_LINE_LINE_POINT0_Y__MASK 0xffff0000 +#define NV01_RENDER_SOLID_LINE_LINE_POINT0_Y__SHIFT 16 + +#define NV01_RENDER_SOLID_LINE_LINE_POINT1(i0) (0x00000404 + 0x8*(i0)) +#define NV01_RENDER_SOLID_LINE_LINE_POINT1__ESIZE 0x00000008 +#define NV01_RENDER_SOLID_LINE_LINE_POINT1__LEN 0x00000010 +#define NV01_RENDER_SOLID_LINE_LINE_POINT1_X__MASK 0x0000ffff +#define NV01_RENDER_SOLID_LINE_LINE_POINT1_X__SHIFT 0 +#define NV01_RENDER_SOLID_LINE_LINE_POINT1_Y__MASK 0xffff0000 +#define NV01_RENDER_SOLID_LINE_LINE_POINT1_Y__SHIFT 16 + +#define NV01_RENDER_SOLID_LINE_LINE32_POINT0_X(i0) (0x00000480 + 0x10*(i0)) +#define NV01_RENDER_SOLID_LINE_LINE32_POINT0_X__ESIZE 0x00000010 +#define NV01_RENDER_SOLID_LINE_LINE32_POINT0_X__LEN 0x00000010 + +#define NV01_RENDER_SOLID_LINE_LINE32_POINT0_Y(i0) (0x00000484 + 0x10*(i0)) +#define NV01_RENDER_SOLID_LINE_LINE32_POINT0_Y__ESIZE 0x00000010 +#define NV01_RENDER_SOLID_LINE_LINE32_POINT0_Y__LEN 0x00000010 + +#define NV01_RENDER_SOLID_LINE_LINE32_POINT1_X(i0) (0x00000488 + 0x10*(i0)) +#define NV01_RENDER_SOLID_LINE_LINE32_POINT1_X__ESIZE 0x00000010 +#define NV01_RENDER_SOLID_LINE_LINE32_POINT1_X__LEN 0x00000010 + +#define NV01_RENDER_SOLID_LINE_LINE32_POINT1_Y(i0) (0x0000048c + 0x10*(i0)) +#define NV01_RENDER_SOLID_LINE_LINE32_POINT1_Y__ESIZE 0x00000010 +#define NV01_RENDER_SOLID_LINE_LINE32_POINT1_Y__LEN 0x00000010 + +#define NV01_RENDER_SOLID_LINE_POLYLINE(i0) (0x00000500 + 0x4*(i0)) +#define NV01_RENDER_SOLID_LINE_POLYLINE__ESIZE 0x00000004 +#define NV01_RENDER_SOLID_LINE_POLYLINE__LEN 0x00000020 +#define NV01_RENDER_SOLID_LINE_POLYLINE_X__MASK 0x0000ffff +#define NV01_RENDER_SOLID_LINE_POLYLINE_X__SHIFT 0 +#define NV01_RENDER_SOLID_LINE_POLYLINE_Y__MASK 0xffff0000 +#define NV01_RENDER_SOLID_LINE_POLYLINE_Y__SHIFT 16 + +#define NV01_RENDER_SOLID_LINE_POLYLINE32_POINT_X(i0) (0x00000580 + 0x8*(i0)) +#define NV01_RENDER_SOLID_LINE_POLYLINE32_POINT_X__ESIZE 0x00000008 +#define NV01_RENDER_SOLID_LINE_POLYLINE32_POINT_X__LEN 0x00000010 + +#define NV01_RENDER_SOLID_LINE_POLYLINE32_POINT_Y(i0) (0x00000584 + 0x8*(i0)) +#define NV01_RENDER_SOLID_LINE_POLYLINE32_POINT_Y__ESIZE 0x00000008 +#define NV01_RENDER_SOLID_LINE_POLYLINE32_POINT_Y__LEN 0x00000010 + +#define NV01_RENDER_SOLID_LINE_CPOLYLINE_COLOR(i0) (0x00000600 + 0x8*(i0)) +#define NV01_RENDER_SOLID_LINE_CPOLYLINE_COLOR__ESIZE 0x00000008 +#define NV01_RENDER_SOLID_LINE_CPOLYLINE_COLOR__LEN 0x00000010 + +#define NV01_RENDER_SOLID_LINE_CPOLYLINE_POINT(i0) (0x00000604 + 0x8*(i0)) +#define NV01_RENDER_SOLID_LINE_CPOLYLINE_POINT__ESIZE 0x00000008 +#define NV01_RENDER_SOLID_LINE_CPOLYLINE_POINT__LEN 0x00000010 +#define NV01_RENDER_SOLID_LINE_CPOLYLINE_POINT_X__MASK 0x0000ffff +#define NV01_RENDER_SOLID_LINE_CPOLYLINE_POINT_X__SHIFT 0 +#define NV01_RENDER_SOLID_LINE_CPOLYLINE_POINT_Y__MASK 0xffff0000 +#define NV01_RENDER_SOLID_LINE_CPOLYLINE_POINT_Y__SHIFT 16 + + +#define NV01_RENDER_SOLID_TRIANGLE_PATCH 0x0000010c + +#define NV01_RENDER_SOLID_TRIANGLE_DMA_NOTIFY 0x00000180 + +#define NV01_RENDER_SOLID_TRIANGLE_CLIP_RECTANGLE 0x00000184 + +#define NV01_RENDER_SOLID_TRIANGLE_PATTERN 0x00000188 + +#define NV04_RENDER_SOLID_TRIANGLE_PATTERN 0x00000188 + +#define NV01_RENDER_SOLID_TRIANGLE_ROP 0x0000018c + +#define NV01_RENDER_SOLID_TRIANGLE_BETA1 0x00000190 + +#define NV01_RENDER_SOLID_TRIANGLE_SURFACE_DST 0x00000194 + + +#define NV04_RENDER_SOLID_TRIANGLE_BETA4 0x00000194 + +#define NV04_RENDER_SOLID_TRIANGLE_SURFACE 0x00000198 + +#define NV01_RENDER_SOLID_TRIANGLE_OPERATION 0x000002fc +#define NV01_RENDER_SOLID_TRIANGLE_OPERATION_SRCCOPY_AND 0x00000000 +#define NV01_RENDER_SOLID_TRIANGLE_OPERATION_ROP_AND 0x00000001 +#define NV01_RENDER_SOLID_TRIANGLE_OPERATION_BLEND_AND 0x00000002 +#define NV01_RENDER_SOLID_TRIANGLE_OPERATION_SRCCOPY 0x00000003 +#define NV01_RENDER_SOLID_TRIANGLE_OPERATION_SRCCOPY_PREMULT 0x00000004 +#define NV01_RENDER_SOLID_TRIANGLE_OPERATION_BLEND_PREMULT 0x00000005 + +#define NV01_RENDER_SOLID_TRIANGLE_COLOR_FORMAT 0x00000300 +#define NV01_RENDER_SOLID_TRIANGLE_COLOR_FORMAT_A16R5G6B5 0x00000001 +#define NV01_RENDER_SOLID_TRIANGLE_COLOR_FORMAT_X16A1R5G5B5 0x00000002 +#define NV01_RENDER_SOLID_TRIANGLE_COLOR_FORMAT_A8R8G8B8 0x00000003 + +#define NV01_RENDER_SOLID_TRIANGLE_COLOR 0x00000304 + +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT0 0x00000310 +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT0_X__MASK 0x0000ffff +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT0_X__SHIFT 0 +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT0_Y__MASK 0xffff0000 +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT0_Y__SHIFT 16 + +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT1 0x00000314 +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT1_X__MASK 0x0000ffff +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT1_X__SHIFT 0 +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT1_Y__MASK 0xffff0000 +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT1_Y__SHIFT 16 + +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT2 0x00000318 +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT2_X__MASK 0x0000ffff +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT2_X__SHIFT 0 +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT2_Y__MASK 0xffff0000 +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE_POINT2_Y__SHIFT 16 + +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE32_POINT0_X 0x00000320 + +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE32_POINT0_Y 0x00000324 + +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE32_POINT1_X 0x00000328 + +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE32_POINT1_Y 0x0000032c + +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE32_POINT2_X 0x00000330 + +#define NV01_RENDER_SOLID_TRIANGLE_TRIANGLE32_POINT2_Y 0x00000334 + +#define NV01_RENDER_SOLID_TRIANGLE_TRIMESH(i0) (0x00000400 + 0x4*(i0)) +#define NV01_RENDER_SOLID_TRIANGLE_TRIMESH__ESIZE 0x00000004 +#define NV01_RENDER_SOLID_TRIANGLE_TRIMESH__LEN 0x00000020 +#define NV01_RENDER_SOLID_TRIANGLE_TRIMESH_X__MASK 0x0000ffff +#define NV01_RENDER_SOLID_TRIANGLE_TRIMESH_X__SHIFT 0 +#define NV01_RENDER_SOLID_TRIANGLE_TRIMESH_Y__MASK 0xffff0000 +#define NV01_RENDER_SOLID_TRIANGLE_TRIMESH_Y__SHIFT 16 + +#define NV01_RENDER_SOLID_TRIANGLE_TRIMESH32_POINT_X(i0) (0x00000480 + 0x8*(i0)) +#define NV01_RENDER_SOLID_TRIANGLE_TRIMESH32_POINT_X__ESIZE 0x00000008 +#define NV01_RENDER_SOLID_TRIANGLE_TRIMESH32_POINT_X__LEN 0x00000010 + +#define NV01_RENDER_SOLID_TRIANGLE_TRIMESH32_POINT_Y(i0) (0x00000484 + 0x8*(i0)) +#define NV01_RENDER_SOLID_TRIANGLE_TRIMESH32_POINT_Y__ESIZE 0x00000008 +#define NV01_RENDER_SOLID_TRIANGLE_TRIMESH32_POINT_Y__LEN 0x00000010 + +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_COLOR(i0) (0x00000500 + 0x10*(i0)) +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_COLOR__ESIZE 0x00000010 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_COLOR__LEN 0x00000008 + +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT0(i0) (0x00000504 + 0x10*(i0)) +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT0__ESIZE 0x00000010 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT0__LEN 0x00000008 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT0_X__MASK 0x0000ffff +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT0_X__SHIFT 0 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT0_Y__MASK 0xffff0000 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT0_Y__SHIFT 16 + +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT1(i0) (0x00000508 + 0x10*(i0)) +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT1__ESIZE 0x00000010 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT1__LEN 0x00000008 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT1_X__MASK 0x0000ffff +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT1_X__SHIFT 0 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT1_Y__MASK 0xffff0000 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT1_Y__SHIFT 16 + +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT2(i0) (0x0000050c + 0x10*(i0)) +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT2__ESIZE 0x00000010 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT2__LEN 0x00000008 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT2_X__MASK 0x0000ffff +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT2_X__SHIFT 0 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT2_Y__MASK 0xffff0000 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIANGLE_POINT2_Y__SHIFT 16 + +#define NV01_RENDER_SOLID_TRIANGLE_CTRIMESH_COLOR(i0) (0x00000580 + 0x8*(i0)) +#define NV01_RENDER_SOLID_TRIANGLE_CTRIMESH_COLOR__ESIZE 0x00000008 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIMESH_COLOR__LEN 0x00000010 + +#define NV01_RENDER_SOLID_TRIANGLE_CTRIMESH_POINT(i0) (0x00000584 + 0x8*(i0)) +#define NV01_RENDER_SOLID_TRIANGLE_CTRIMESH_POINT__ESIZE 0x00000008 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIMESH_POINT__LEN 0x00000010 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIMESH_POINT_X__MASK 0x0000ffff +#define NV01_RENDER_SOLID_TRIANGLE_CTRIMESH_POINT_X__SHIFT 0 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIMESH_POINT_Y__MASK 0xffff0000 +#define NV01_RENDER_SOLID_TRIANGLE_CTRIMESH_POINT_Y__SHIFT 16 + + +#define NV01_RENDER_SOLID_RECTANGLE_PATCH 0x0000010c + +#define NV01_RENDER_SOLID_RECTANGLE_DMA_NOTIFY 0x00000180 + +#define NV01_RENDER_SOLID_RECTANGLE_CLIP_RECTANGLE 0x00000184 + +#define NV01_RENDER_SOLID_RECTANGLE_PATTERN 0x00000188 + +#define NV04_RENDER_SOLID_RECTANGLE_PATTERN 0x00000188 + +#define NV01_RENDER_SOLID_RECTANGLE_ROP 0x0000018c + +#define NV01_RENDER_SOLID_RECTANGLE_BETA1 0x00000190 + +#define NV01_RENDER_SOLID_RECTANGLE_SURFACE_DST 0x00000194 + + +#define NV04_RENDER_SOLID_RECTANGLE_BETA4 0x00000194 + +#define NV04_RENDER_SOLID_RECTANGLE_SURFACE 0x00000198 + +#define NV01_RENDER_SOLID_RECTANGLE_OPERATION 0x000002fc +#define NV01_RENDER_SOLID_RECTANGLE_OPERATION_SRCCOPY_AND 0x00000000 +#define NV01_RENDER_SOLID_RECTANGLE_OPERATION_ROP_AND 0x00000001 +#define NV01_RENDER_SOLID_RECTANGLE_OPERATION_BLEND_AND 0x00000002 +#define NV01_RENDER_SOLID_RECTANGLE_OPERATION_SRCCOPY 0x00000003 +#define NV01_RENDER_SOLID_RECTANGLE_OPERATION_SRCCOPY_PREMULT 0x00000004 +#define NV01_RENDER_SOLID_RECTANGLE_OPERATION_BLEND_PREMULT 0x00000005 + +#define NV01_RENDER_SOLID_RECTANGLE_COLOR_FORMAT 0x00000300 +#define NV01_RENDER_SOLID_RECTANGLE_COLOR_FORMAT_A16R5G6B5 0x00000001 +#define NV01_RENDER_SOLID_RECTANGLE_COLOR_FORMAT_X16A1R5G5B5 0x00000002 +#define NV01_RENDER_SOLID_RECTANGLE_COLOR_FORMAT_A8R8G8B8 0x00000003 + +#define NV01_RENDER_SOLID_RECTANGLE_COLOR 0x00000304 + +#define NV01_RENDER_SOLID_RECTANGLE_RECTANGLE_POINT(i0) (0x00000400 + 0x8*(i0)) +#define NV01_RENDER_SOLID_RECTANGLE_RECTANGLE_POINT__ESIZE 0x00000008 +#define NV01_RENDER_SOLID_RECTANGLE_RECTANGLE_POINT__LEN 0x00000010 +#define NV01_RENDER_SOLID_RECTANGLE_RECTANGLE_POINT_X__MASK 0x0000ffff +#define NV01_RENDER_SOLID_RECTANGLE_RECTANGLE_POINT_X__SHIFT 0 +#define NV01_RENDER_SOLID_RECTANGLE_RECTANGLE_POINT_Y__MASK 0xffff0000 +#define NV01_RENDER_SOLID_RECTANGLE_RECTANGLE_POINT_Y__SHIFT 16 + +#define NV01_RENDER_SOLID_RECTANGLE_RECTANGLE_SIZE(i0) (0x00000404 + 0x8*(i0)) +#define NV01_RENDER_SOLID_RECTANGLE_RECTANGLE_SIZE__ESIZE 0x00000008 +#define NV01_RENDER_SOLID_RECTANGLE_RECTANGLE_SIZE__LEN 0x00000010 +#define NV01_RENDER_SOLID_RECTANGLE_RECTANGLE_SIZE_W__MASK 0x0000ffff +#define NV01_RENDER_SOLID_RECTANGLE_RECTANGLE_SIZE_W__SHIFT 0 +#define NV01_RENDER_SOLID_RECTANGLE_RECTANGLE_SIZE_H__MASK 0xffff0000 +#define NV01_RENDER_SOLID_RECTANGLE_RECTANGLE_SIZE_H__SHIFT 16 + + +#define NV01_IMAGE_BLIT_PATCH 0x0000010c + + +#define NV11_IMAGE_BLIT_WAIT_FOR_IDLE 0x00000108 + +#define NV11_IMAGE_BLIT_UNK120 0x00000120 + +#define NV11_IMAGE_BLIT_UNK124 0x00000124 + +#define NV11_IMAGE_BLIT_UNK128 0x00000128 + +#define NV11_IMAGE_BLIT_UNK12C 0x0000012c + +#define NV11_IMAGE_BLIT_UNK130 0x00000130 + +#define NV11_IMAGE_BLIT_UNK134 0x00000134 + +#define NV01_IMAGE_BLIT_DMA_NOTIFY 0x00000180 + +#define NV01_IMAGE_BLIT_COLOR_KEY 0x00000184 + +#define NV04_IMAGE_BLIT_COLOR_KEY 0x00000184 + +#define NV01_IMAGE_BLIT_CLIP_RECTANGLE 0x00000188 + +#define NV01_IMAGE_BLIT_PATTERN 0x0000018c + +#define NV04_IMAGE_BLIT_PATTERN 0x0000018c + +#define NV01_IMAGE_BLIT_ROP 0x00000190 + +#define NV01_IMAGE_BLIT_BETA1 0x00000194 + + +#define NV01_IMAGE_BLIT_SURFACE_SRC 0x00000198 + +#define NV01_IMAGE_BLIT_SURFACE_DST 0x0000019c + + +#define NV04_IMAGE_BLIT_BETA4 0x00000198 + +#define NV04_IMAGE_BLIT_SURFACES 0x0000019c + +#define NV01_IMAGE_BLIT_OPERATION 0x000002fc +#define NV01_IMAGE_BLIT_OPERATION_SRCCOPY_AND 0x00000000 +#define NV01_IMAGE_BLIT_OPERATION_ROP_AND 0x00000001 +#define NV01_IMAGE_BLIT_OPERATION_BLEND_AND 0x00000002 +#define NV01_IMAGE_BLIT_OPERATION_SRCCOPY 0x00000003 +#define NV01_IMAGE_BLIT_OPERATION_SRCCOPY_PREMULT 0x00000004 +#define NV01_IMAGE_BLIT_OPERATION_BLEND_PREMULT 0x00000005 + +#define NV01_IMAGE_BLIT_POINT_IN 0x00000300 +#define NV01_IMAGE_BLIT_POINT_IN_X__MASK 0x0000ffff +#define NV01_IMAGE_BLIT_POINT_IN_X__SHIFT 0 +#define NV01_IMAGE_BLIT_POINT_IN_Y__MASK 0xffff0000 +#define NV01_IMAGE_BLIT_POINT_IN_Y__SHIFT 16 + +#define NV01_IMAGE_BLIT_POINT_OUT 0x00000304 +#define NV01_IMAGE_BLIT_POINT_OUT_X__MASK 0x0000ffff +#define NV01_IMAGE_BLIT_POINT_OUT_X__SHIFT 0 +#define NV01_IMAGE_BLIT_POINT_OUT_Y__MASK 0xffff0000 +#define NV01_IMAGE_BLIT_POINT_OUT_Y__SHIFT 16 + +#define NV01_IMAGE_BLIT_SIZE 0x00000308 +#define NV01_IMAGE_BLIT_SIZE_W__MASK 0x0000ffff +#define NV01_IMAGE_BLIT_SIZE_W__SHIFT 0 +#define NV01_IMAGE_BLIT_SIZE_H__MASK 0xffff0000 +#define NV01_IMAGE_BLIT_SIZE_H__SHIFT 16 + + +#define NV04_INDEXED_IMAGE_FROM_CPU_PATCH 0x0000010c + +#define NV04_INDEXED_IMAGE_FROM_CPU_DMA_NOTIFY 0x00000180 + +#define NV04_INDEXED_IMAGE_FROM_CPU_DMA_LUT 0x00000184 + +#define NV04_INDEXED_IMAGE_FROM_CPU_COLOR_KEY 0x00000188 + +#define NV04_INDEXED_IMAGE_FROM_CPU_CLIP_RECTANGLE 0x0000018c + +#define NV04_INDEXED_IMAGE_FROM_CPU_PATTERN 0x00000190 + +#define NV04_INDEXED_IMAGE_FROM_CPU_ROP 0x00000194 + +#define NV04_INDEXED_IMAGE_FROM_CPU_BETA1 0x00000198 + +#define NV04_INDEXED_IMAGE_FROM_CPU_BETA4 0x0000019c + +#define NV04_INDEXED_IMAGE_FROM_CPU_SURFACE 0x000001a0 + +#define NV05_INDEXED_IMAGE_FROM_CPU_SURFACE 0x000001a0 + +#define NV05_INDEXED_IMAGE_FROM_CPU_COLOR_CONVERSION 0x000003e0 + +#define NV04_INDEXED_IMAGE_FROM_CPU_OPERATION 0x000003e4 + +#define NV04_INDEXED_IMAGE_FROM_CPU_COLOR_FORMAT 0x000003e8 + +#define NV04_INDEXED_IMAGE_FROM_CPU_INDEX_FORMAT 0x000003ec + +#define NV04_INDEXED_IMAGE_FROM_CPU_LUT_OFFSET 0x000003f0 + +#define NV04_INDEXED_IMAGE_FROM_CPU_POINT 0x000003f4 + +#define NV04_INDEXED_IMAGE_FROM_CPU_SIZE_OUT 0x000003f8 + +#define NV04_INDEXED_IMAGE_FROM_CPU_SIZE_IN 0x000003fc + +#define NV04_INDEXED_IMAGE_FROM_CPU_COLOR(i0) (0x00000400 + 0x4*(i0)) +#define NV04_INDEXED_IMAGE_FROM_CPU_COLOR__ESIZE 0x00000004 +#define NV04_INDEXED_IMAGE_FROM_CPU_COLOR__LEN 0x00000700 + + +#define NV10_IMAGE_FROM_CPU_WAIT_FOR_IDLE 0x00000108 + +#define NV01_IMAGE_FROM_CPU_PATCH 0x0000010c + +#define NV01_IMAGE_FROM_CPU_DMA_NOTIFY 0x00000180 + +#define NV01_IMAGE_FROM_CPU_COLOR_KEY 0x00000184 + +#define NV04_IMAGE_FROM_CPU_COLOR_KEY 0x00000184 + +#define NV01_IMAGE_FROM_CPU_CLIP_RECTANGLE 0x00000188 + +#define NV01_IMAGE_FROM_CPU_PATTERN 0x0000018c + +#define NV04_IMAGE_FROM_CPU_PATTERN 0x0000018c + +#define NV01_IMAGE_FROM_CPU_ROP 0x00000190 + +#define NV01_IMAGE_FROM_CPU_BETA1 0x00000194 + + +#define NV01_IMAGE_FROM_CPU_SURFACE_DST 0x00000198 + + +#define NV04_IMAGE_FROM_CPU_BETA4 0x00000198 + +#define NV04_IMAGE_FROM_CPU_SURFACE 0x0000019c + +#define NV05_IMAGE_FROM_CPU_COLOR_CONVERSION 0x000002f8 + +#define NV01_IMAGE_FROM_CPU_OPERATION 0x000002fc +#define NV01_IMAGE_FROM_CPU_OPERATION_SRCCOPY_AND 0x00000000 +#define NV01_IMAGE_FROM_CPU_OPERATION_ROP_AND 0x00000001 +#define NV01_IMAGE_FROM_CPU_OPERATION_BLEND_AND 0x00000002 +#define NV01_IMAGE_FROM_CPU_OPERATION_SRCCOPY 0x00000003 +#define NV01_IMAGE_FROM_CPU_OPERATION_SRCCOPY_PREMULT 0x00000004 +#define NV01_IMAGE_FROM_CPU_OPERATION_BLEND_PREMULT 0x00000005 + +#define NV01_IMAGE_FROM_CPU_COLOR_FORMAT 0x00000300 +#define NV01_IMAGE_FROM_CPU_COLOR_FORMAT_R5G6G5 0x00000001 +#define NV01_IMAGE_FROM_CPU_COLOR_FORMAT_A1R5G5B5 0x00000002 +#define NV01_IMAGE_FROM_CPU_COLOR_FORMAT_X1R5G5B5 0x00000003 +#define NV01_IMAGE_FROM_CPU_COLOR_FORMAT_A8R8G8B8 0x00000004 +#define NV01_IMAGE_FROM_CPU_COLOR_FORMAT_X8R8G8B8 0x00000005 + +#define NV01_IMAGE_FROM_CPU_POINT 0x00000304 +#define NV01_IMAGE_FROM_CPU_POINT_X__MASK 0x0000ffff +#define NV01_IMAGE_FROM_CPU_POINT_X__SHIFT 0 +#define NV01_IMAGE_FROM_CPU_POINT_Y__MASK 0xffff0000 +#define NV01_IMAGE_FROM_CPU_POINT_Y__SHIFT 16 + +#define NV01_IMAGE_FROM_CPU_SIZE_OUT 0x00000308 +#define NV01_IMAGE_FROM_CPU_SIZE_OUT_W__MASK 0x0000ffff +#define NV01_IMAGE_FROM_CPU_SIZE_OUT_W__SHIFT 0 +#define NV01_IMAGE_FROM_CPU_SIZE_OUT_H__MASK 0xffff0000 +#define NV01_IMAGE_FROM_CPU_SIZE_OUT_H__SHIFT 16 + +#define NV01_IMAGE_FROM_CPU_SIZE_IN 0x0000030c +#define NV01_IMAGE_FROM_CPU_SIZE_IN_W__MASK 0x0000ffff +#define NV01_IMAGE_FROM_CPU_SIZE_IN_W__SHIFT 0 +#define NV01_IMAGE_FROM_CPU_SIZE_IN_H__MASK 0xffff0000 +#define NV01_IMAGE_FROM_CPU_SIZE_IN_H__SHIFT 16 + +#define NV01_IMAGE_FROM_CPU_COLOR(i0) (0x00000400 + 0x4*(i0)) +#define NV01_IMAGE_FROM_CPU_COLOR__ESIZE 0x00000004 +#define NV01_IMAGE_FROM_CPU_COLOR__LEN 0x00000020 + +#define NV04_IMAGE_FROM_CPU_COLOR(i0) (0x00000400 + 0x4*(i0)) +#define NV04_IMAGE_FROM_CPU_COLOR__ESIZE 0x00000004 +#define NV04_IMAGE_FROM_CPU_COLOR__LEN 0x00000700 + + +#define NV03_STRETCHED_IMAGE_FROM_CPU_PATCH 0x0000010c + +#define NV03_STRETCHED_IMAGE_FROM_CPU_DMA_NOTIFY 0x00000180 + +#define NV03_STRETCHED_IMAGE_FROM_CPU_COLOR_KEY 0x00000184 + +#define NV04_STRETCHED_IMAGE_FROM_CPU_COLOR_KEY 0x00000184 + +#define NV03_STRETCHED_IMAGE_FROM_CPU_PATTERN 0x00000188 + +#define NV04_STRETCHED_IMAGE_FROM_CPU_PATTERN 0x00000188 + +#define NV03_STRETCHED_IMAGE_FROM_CPU_ROP 0x0000018c + +#define NV03_STRETCHED_IMAGE_FROM_CPU_BETA1 0x00000190 + + +#define NV03_STRETCHED_IMAGE_FROM_CPU_SURFACE_DST 0x00000194 + + +#define NV04_STRETCHED_IMAGE_FROM_CPU_BETA4 0x00000194 + +#define NV04_STRETCHED_IMAGE_FROM_CPU_SURFACE 0x00000198 + +#define NV05_STRETCHED_IMAGE_FROM_CPU_COLOR_CONVERSION 0x000002f8 + +#define NV03_STRETCHED_IMAGE_FROM_CPU_OPERATION 0x000002fc + +#define NV03_STRETCHED_IMAGE_FROM_CPU_COLOR_FORMAT 0x00000300 + +#define NV03_STRETCHED_IMAGE_FROM_CPU_SIZE_IN 0x00000304 +#define NV03_STRETCHED_IMAGE_FROM_CPU_SIZE_IN_W__MASK 0x0000ffff +#define NV03_STRETCHED_IMAGE_FROM_CPU_SIZE_IN_W__SHIFT 0 +#define NV03_STRETCHED_IMAGE_FROM_CPU_SIZE_IN_H__MASK 0xffff0000 +#define NV03_STRETCHED_IMAGE_FROM_CPU_SIZE_IN_H__SHIFT 16 + +#define NV03_STRETCHED_IMAGE_FROM_CPU_DX_DU 0x00000308 + +#define NV03_STRETCHED_IMAGE_FROM_CPU_DY_DV 0x0000030c + +#define NV03_STRETCHED_IMAGE_FROM_CPU_CLIP_POINT 0x00000310 +#define NV03_STRETCHED_IMAGE_FROM_CPU_CLIP_POINT_X__MASK 0x0000ffff +#define NV03_STRETCHED_IMAGE_FROM_CPU_CLIP_POINT_X__SHIFT 0 +#define NV03_STRETCHED_IMAGE_FROM_CPU_CLIP_POINT_Y__MASK 0xffff0000 +#define NV03_STRETCHED_IMAGE_FROM_CPU_CLIP_POINT_Y__SHIFT 16 + +#define NV03_STRETCHED_IMAGE_FROM_CPU_CLIP_SIZE 0x00000314 +#define NV03_STRETCHED_IMAGE_FROM_CPU_CLIP_SIZE_W__MASK 0x0000ffff +#define NV03_STRETCHED_IMAGE_FROM_CPU_CLIP_SIZE_W__SHIFT 0 +#define NV03_STRETCHED_IMAGE_FROM_CPU_CLIP_SIZE_H__MASK 0xffff0000 +#define NV03_STRETCHED_IMAGE_FROM_CPU_CLIP_SIZE_H__SHIFT 16 + +#define NV03_STRETCHED_IMAGE_FROM_CPU_POINT12D4 0x00000318 +#define NV03_STRETCHED_IMAGE_FROM_CPU_POINT12D4_X__MASK 0x0000ffff +#define NV03_STRETCHED_IMAGE_FROM_CPU_POINT12D4_X__SHIFT 0 +#define NV03_STRETCHED_IMAGE_FROM_CPU_POINT12D4_Y__MASK 0xffff0000 +#define NV03_STRETCHED_IMAGE_FROM_CPU_POINT12D4_Y__SHIFT 16 + +#define NV03_STRETCHED_IMAGE_FROM_CPU_COLOR(i0) (0x00000400 + 0x4*(i0)) +#define NV03_STRETCHED_IMAGE_FROM_CPU_COLOR__ESIZE 0x00000004 +#define NV03_STRETCHED_IMAGE_FROM_CPU_COLOR__LEN 0x00000700 + + +#define NV10_SCALED_IMAGE_FROM_MEMORY_WAIT_FOR_IDLE 0x00000108 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_DMA_NOTIFY 0x00000180 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_DMA_IMAGE 0x00000184 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_PATTERN 0x00000188 + +#define NV04_SCALED_IMAGE_FROM_MEMORY_PATTERN 0x00000188 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_ROP 0x0000018c + +#define NV03_SCALED_IMAGE_FROM_MEMORY_BETA1 0x00000190 + + +#define NV03_SCALED_IMAGE_FROM_MEMORY_SURFACE_DST 0x00000194 + + +#define NV04_SCALED_IMAGE_FROM_MEMORY_BETA4 0x00000194 + +#define NV04_SCALED_IMAGE_FROM_MEMORY_SURFACE 0x00000198 + +#define NV05_SCALED_IMAGE_FROM_MEMORY_SURFACE 0x00000198 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION 0x000002fc +#define NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION_DITHER 0x00000000 +#define NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION_TRUNCATE 0x00000001 +#define NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION_SUBTR_TRUNCATE 0x00000002 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT 0x00000300 +#define NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_A1R5G5B5 0x00000001 +#define NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_X1R5G5B5 0x00000002 +#define NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_A8R8G8B8 0x00000003 +#define NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_X8R8G8B8 0x00000004 +#define NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_V8YB8U8YA8 0x00000005 +#define NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_YB8V8YA8U8 0x00000006 +#define NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_R5G6B5 0x00000007 +#define NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_Y8 0x00000008 +#define NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_AY8 0x00000009 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_OPERATION 0x00000304 +#define NV03_SCALED_IMAGE_FROM_MEMORY_OPERATION_SRCCOPY_AND 0x00000000 +#define NV03_SCALED_IMAGE_FROM_MEMORY_OPERATION_ROP_AND 0x00000001 +#define NV03_SCALED_IMAGE_FROM_MEMORY_OPERATION_BLEND_AND 0x00000002 +#define NV03_SCALED_IMAGE_FROM_MEMORY_OPERATION_SRCCOPY 0x00000003 +#define NV03_SCALED_IMAGE_FROM_MEMORY_OPERATION_SRCCOPY_PREMULT 0x00000004 +#define NV03_SCALED_IMAGE_FROM_MEMORY_OPERATION_BLEND_PREMULT 0x00000005 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_CLIP_POINT 0x00000308 +#define NV03_SCALED_IMAGE_FROM_MEMORY_CLIP_POINT_X__MASK 0x0000ffff +#define NV03_SCALED_IMAGE_FROM_MEMORY_CLIP_POINT_X__SHIFT 0 +#define NV03_SCALED_IMAGE_FROM_MEMORY_CLIP_POINT_Y__MASK 0xffff0000 +#define NV03_SCALED_IMAGE_FROM_MEMORY_CLIP_POINT_Y__SHIFT 16 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_CLIP_SIZE 0x0000030c +#define NV03_SCALED_IMAGE_FROM_MEMORY_CLIP_SIZE_W__MASK 0x0000ffff +#define NV03_SCALED_IMAGE_FROM_MEMORY_CLIP_SIZE_W__SHIFT 0 +#define NV03_SCALED_IMAGE_FROM_MEMORY_CLIP_SIZE_H__MASK 0xffff0000 +#define NV03_SCALED_IMAGE_FROM_MEMORY_CLIP_SIZE_H__SHIFT 16 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_OUT_POINT 0x00000310 +#define NV03_SCALED_IMAGE_FROM_MEMORY_OUT_POINT_X__MASK 0x0000ffff +#define NV03_SCALED_IMAGE_FROM_MEMORY_OUT_POINT_X__SHIFT 0 +#define NV03_SCALED_IMAGE_FROM_MEMORY_OUT_POINT_Y__MASK 0xffff0000 +#define NV03_SCALED_IMAGE_FROM_MEMORY_OUT_POINT_Y__SHIFT 16 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_OUT_SIZE 0x00000314 +#define NV03_SCALED_IMAGE_FROM_MEMORY_OUT_SIZE_W__MASK 0x0000ffff +#define NV03_SCALED_IMAGE_FROM_MEMORY_OUT_SIZE_W__SHIFT 0 +#define NV03_SCALED_IMAGE_FROM_MEMORY_OUT_SIZE_H__MASK 0xffff0000 +#define NV03_SCALED_IMAGE_FROM_MEMORY_OUT_SIZE_H__SHIFT 16 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_DU_DX 0x00000318 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_DV_DY 0x0000031c + +#define NV03_SCALED_IMAGE_FROM_MEMORY_SIZE 0x00000400 +#define NV03_SCALED_IMAGE_FROM_MEMORY_SIZE_W__MASK 0x0000ffff +#define NV03_SCALED_IMAGE_FROM_MEMORY_SIZE_W__SHIFT 0 +#define NV03_SCALED_IMAGE_FROM_MEMORY_SIZE_H__MASK 0xffff0000 +#define NV03_SCALED_IMAGE_FROM_MEMORY_SIZE_H__SHIFT 16 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT 0x00000404 +#define NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_PITCH__MASK 0x0000ffff +#define NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_PITCH__SHIFT 0 +#define NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_ORIGIN__MASK 0x00ff0000 +#define NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_ORIGIN__SHIFT 16 +#define NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_ORIGIN_CENTER 0x00010000 +#define NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_ORIGIN_CORNER 0x00020000 +#define NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_FILTER__MASK 0xff000000 +#define NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_FILTER__SHIFT 24 +#define NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_FILTER_POINT_SAMPLE 0x00000000 +#define NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_FILTER_BILINEAR 0x01000000 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_OFFSET 0x00000408 + +#define NV03_SCALED_IMAGE_FROM_MEMORY_POINT 0x0000040c +#define NV03_SCALED_IMAGE_FROM_MEMORY_POINT_U__MASK 0x0000ffff +#define NV03_SCALED_IMAGE_FROM_MEMORY_POINT_U__SHIFT 0 +#define NV03_SCALED_IMAGE_FROM_MEMORY_POINT_V__MASK 0xffff0000 +#define NV03_SCALED_IMAGE_FROM_MEMORY_POINT_V__SHIFT 16 + + +#define NV50_SCALED_IMAGE_FROM_MEMORY_OFFSET_HIGH 0x00000410 + +#define NV50_SCALED_IMAGE_FROM_MEMORY_SRC_LINEAR 0x00000414 + +#define NV50_SCALED_IMAGE_FROM_MEMORY_SRC_TILE_MODE 0x00000418 + + +#define NV03_GDI_RECTANGLE_TEXT_DMA_NOTIFY 0x00000180 + +#define NV03_GDI_RECTANGLE_TEXT_PATTERN 0x00000184 + +#define NV03_GDI_RECTANGLE_TEXT_ROP 0x00000188 + +#define NV03_GDI_RECTANGLE_TEXT_BETA1 0x0000019c + +#define NV03_GDI_RECTANGLE_TEXT_SURFACE_DST 0x00000190 + +#define NV03_GDI_RECTANGLE_TEXT_OPERATION 0x000002fc + +#define NV03_GDI_RECTANGLE_TEXT_COLOR_FORMAT 0x00000300 + +#define NV03_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT 0x00000304 + +#define NV03_GDI_RECTANGLE_TEXT_COLOR1_A 0x000003fc + +#define NV03_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT 0x00000400 +#define NV03_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT_Y__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT_Y__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT_X__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT_X__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_SIZE 0x00000404 +#define NV03_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_SIZE_H__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_SIZE_H__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_SIZE_W__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_SIZE_W__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_CLIP_POINT0_B 0x000007f4 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_POINT0_B_L__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_CLIP_POINT0_B_L__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_POINT0_B_T__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_POINT0_B_T__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_CLIP_POINT1_B 0x000007f8 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_POINT1_B_R__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_CLIP_POINT1_B_R__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_POINT1_B_B__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_POINT1_B_B__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_COLOR1_B 0x000007fc + +#define NV03_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_0 0x00000800 +#define NV03_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_0_L__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_0_L__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_0_T__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_0_T__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_1 0x00000804 +#define NV03_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_1_R__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_1_R__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_1_B__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_1_B__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_CLIP_C_POINT0 0x00000bec +#define NV03_GDI_RECTANGLE_TEXT_CLIP_C_POINT0_L__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_CLIP_C_POINT0_L__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_C_POINT0_T__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_C_POINT0_T__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_CLIP_C_POINT1 0x00000bf0 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_C_POINT1_R__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_CLIP_C_POINT1_R__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_C_POINT1_B__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_C_POINT1_B__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_COLOR1_C 0x00000bf4 + +#define NV03_GDI_RECTANGLE_TEXT_SIZE_C 0x00000bf8 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_C_W__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_SIZE_C_W__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_C_H__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_C_H__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_POINT_C 0x00000bfc +#define NV03_GDI_RECTANGLE_TEXT_POINT_C_X__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_POINT_C_X__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_POINT_C_Y__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_POINT_C_Y__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR1_C(i0) (0x00000c00 + 0x4*(i0)) +#define NV03_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR1_C__ESIZE 0x00000004 +#define NV03_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR1_C__LEN 0x00000020 + +#define NV03_GDI_RECTANGLE_TEXT_CLIP_D_POINT0 0x00000fe8 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_D_POINT0_L__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_CLIP_D_POINT0_L__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_D_POINT0_T__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_D_POINT0_T__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_CLIP_D_POINT1 0x00000fec +#define NV03_GDI_RECTANGLE_TEXT_CLIP_D_POINT1_R__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_CLIP_D_POINT1_R__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_D_POINT1_B__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_D_POINT1_B__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_COLOR1_D 0x00000ff0 + +#define NV03_GDI_RECTANGLE_TEXT_SIZE_IN_D 0x00000ff4 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_IN_D_W__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_SIZE_IN_D_W__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_IN_D_H__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_IN_D_H__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_SIZE_OUT_D 0x00000ff8 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_OUT_D_W__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_SIZE_OUT_D_W__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_OUT_D_H__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_OUT_D_H__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_POINT_D 0x00000ffc +#define NV03_GDI_RECTANGLE_TEXT_POINT_D_X__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_POINT_D_X__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_POINT_D_Y__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_POINT_D_Y__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR1_D(i0) (0x00001000 + 0x4*(i0)) +#define NV03_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR1_D__ESIZE 0x00000004 +#define NV03_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR1_D__LEN 0x00000020 + +#define NV03_GDI_RECTANGLE_TEXT_CLIP_E_POINT0 0x000013e4 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_E_POINT0_L__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_CLIP_E_POINT0_L__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_E_POINT0_T__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_E_POINT0_T__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_CLIP_E_POINT1 0x000013e8 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_E_POINT1_R__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_CLIP_E_POINT1_R__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_E_POINT1_B__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_CLIP_E_POINT1_B__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_COLOR0_E 0x000013ec + +#define NV03_GDI_RECTANGLE_TEXT_COLOR1_E 0x000013f0 + +#define NV03_GDI_RECTANGLE_TEXT_SIZE_IN_E 0x000013f4 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_IN_E_W__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_SIZE_IN_E_W__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_IN_E_H__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_IN_E_H__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_SIZE_OUT_E 0x000013f8 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_OUT_E_W__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_SIZE_OUT_E_W__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_OUT_E_H__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_SIZE_OUT_E_H__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_POINT_E 0x000013fc +#define NV03_GDI_RECTANGLE_TEXT_POINT_E_X__MASK 0x0000ffff +#define NV03_GDI_RECTANGLE_TEXT_POINT_E_X__SHIFT 0 +#define NV03_GDI_RECTANGLE_TEXT_POINT_E_Y__MASK 0xffff0000 +#define NV03_GDI_RECTANGLE_TEXT_POINT_E_Y__SHIFT 16 + +#define NV03_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR01_E(i0) (0x00001400 + 0x4*(i0)) +#define NV03_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR01_E__ESIZE 0x00000004 +#define NV03_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR01_E__LEN 0x00000020 + + +#define NV04_GDI_RECTANGLE_TEXT_PATCH 0x0000010c + +#define NV04_GDI_RECTANGLE_TEXT_DMA_NOTIFY 0x00000180 + +#define NV04_GDI_RECTANGLE_TEXT_DMA_FONTS 0x00000184 + +#define NV04_GDI_RECTANGLE_TEXT_PATTERN 0x00000188 + +#define NV04_GDI_RECTANGLE_TEXT_ROP 0x0000018c + +#define NV04_GDI_RECTANGLE_TEXT_BETA1 0x00000190 + +#define NV04_GDI_RECTANGLE_TEXT_BETA4 0x00000194 + +#define NV04_GDI_RECTANGLE_TEXT_SURFACE 0x00000198 + +#define NV04_GDI_RECTANGLE_TEXT_OPERATION 0x000002fc +#define NV04_GDI_RECTANGLE_TEXT_OPERATION_SRCCOPY_AND 0x00000000 +#define NV04_GDI_RECTANGLE_TEXT_OPERATION_ROP_AND 0x00000001 +#define NV04_GDI_RECTANGLE_TEXT_OPERATION_BLEND_AND 0x00000002 +#define NV04_GDI_RECTANGLE_TEXT_OPERATION_SRCCOPY 0x00000003 +#define NV04_GDI_RECTANGLE_TEXT_OPERATION_SRCCOPY_PREMULT 0x00000004 +#define NV04_GDI_RECTANGLE_TEXT_OPERATION_BLEND_PREMULT 0x00000005 + +#define NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT 0x00000300 +#define NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A16R5G6B5 0x00000001 +#define NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_X16A1R5G5B5 0x00000002 +#define NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A8R8G8B8 0x00000003 + +#define NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT 0x00000304 +#define NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT_CGA6 0x00000001 +#define NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT_LE 0x00000002 + +#define NV04_GDI_RECTANGLE_TEXT_COLOR1_A 0x000003fc + +#define NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT(i0) (0x00000400 + 0x8*(i0)) +#define NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT__ESIZE 0x00000008 +#define NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT__LEN 0x00000020 +#define NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT_Y__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT_Y__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT_X__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT_X__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_SIZE(i0) (0x00000404 + 0x8*(i0)) +#define NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_SIZE__ESIZE 0x00000008 +#define NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_SIZE__LEN 0x00000020 +#define NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_SIZE_H__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_SIZE_H__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_SIZE_W__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_SIZE_W__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_CLIP_B_POINT0 0x000005f4 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_B_POINT0_L__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_CLIP_B_POINT0_L__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_B_POINT0_T__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_B_POINT0_T__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_CLIP_B_POINT1 0x000005f8 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_B_POINT1_R__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_CLIP_B_POINT1_R__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_B_POINT1_B__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_B_POINT1_B__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_COLOR1_B 0x000005fc + +#define NV04_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_0(i0) (0x00000600 + 0x8*(i0)) +#define NV04_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_0__ESIZE 0x00000008 +#define NV04_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_0__LEN 0x00000020 +#define NV04_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_0_L__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_0_L__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_0_T__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_0_T__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_1(i0) (0x00000604 + 0x8*(i0)) +#define NV04_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_1__ESIZE 0x00000008 +#define NV04_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_1__LEN 0x00000020 +#define NV04_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_1_R__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_1_R__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_1_B__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_CLIPPED_RECTANGLE_POINT_1_B__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_CLIP_C_POINT0 0x000007ec +#define NV04_GDI_RECTANGLE_TEXT_CLIP_C_POINT0_L__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_CLIP_C_POINT0_L__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_C_POINT0_T__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_C_POINT0_T__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_CLIP_C_POINT1 0x000007f0 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_C_POINT1_R__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_CLIP_C_POINT1_R__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_C_POINT1_B__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_C_POINT1_B__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_COLOR1_C 0x000007f4 + +#define NV04_GDI_RECTANGLE_TEXT_SIZE_C 0x000007f8 +#define NV04_GDI_RECTANGLE_TEXT_SIZE_C_W__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_SIZE_C_W__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_SIZE_C_H__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_SIZE_C_H__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_POINT_C 0x000007fc +#define NV04_GDI_RECTANGLE_TEXT_POINT_C_X__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_POINT_C_X__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_POINT_C_Y__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_POINT_C_Y__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR1_C(i0) (0x00000800 + 0x4*(i0)) +#define NV04_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR1_C__ESIZE 0x00000004 +#define NV04_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR1_C__LEN 0x00000080 + +#define NV04_GDI_RECTANGLE_TEXT_CLIP_E_POINT0 0x00000be4 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_E_POINT0_L__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_CLIP_E_POINT0_L__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_E_POINT0_T__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_E_POINT0_T__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_CLIP_E_POINT1 0x00000be8 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_E_POINT1_R__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_CLIP_E_POINT1_R__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_E_POINT1_B__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_E_POINT1_B__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_COLOR0_E 0x00000bec + +#define NV04_GDI_RECTANGLE_TEXT_COLOR1_E 0x00000bf0 + +#define NV04_GDI_RECTANGLE_TEXT_SIZE_IN_E 0x00000bf4 +#define NV04_GDI_RECTANGLE_TEXT_SIZE_IN_E_W__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_SIZE_IN_E_W__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_SIZE_IN_E_H__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_SIZE_IN_E_H__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_SIZE_OUT_E 0x00000bf8 +#define NV04_GDI_RECTANGLE_TEXT_SIZE_OUT_E_W__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_SIZE_OUT_E_W__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_SIZE_OUT_E_H__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_SIZE_OUT_E_H__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_POINT_E 0x00000bfc +#define NV04_GDI_RECTANGLE_TEXT_POINT_E_X__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_POINT_E_X__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_POINT_E_Y__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_POINT_E_Y__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR01_E(i0) (0x00000c00 + 0x4*(i0)) +#define NV04_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR01_E__ESIZE 0x00000004 +#define NV04_GDI_RECTANGLE_TEXT_MONOCHROME_COLOR01_E__LEN 0x00000080 + +#define NV04_GDI_RECTANGLE_TEXT_FONT_F 0x00000ff0 +#define NV04_GDI_RECTANGLE_TEXT_FONT_F_OFFSET__MASK 0x0fffffff +#define NV04_GDI_RECTANGLE_TEXT_FONT_F_OFFSET__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_FONT_F_PITCH__MASK 0xf0000000 +#define NV04_GDI_RECTANGLE_TEXT_FONT_F_PITCH__SHIFT 28 + +#define NV04_GDI_RECTANGLE_TEXT_CLIP_F_POINT0 0x00000ff4 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_F_POINT0_L__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_CLIP_F_POINT0_L__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_F_POINT0_T__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_F_POINT0_T__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_CLIP_F_POINT1 0x00000ff8 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_F_POINT1_R__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_CLIP_F_POINT1_R__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_F_POINT1_B__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_F_POINT1_B__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_COLOR1_F 0x00000ffc + +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_F(i0) (0x00001000 + 0x4*(i0)) +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_F__ESIZE 0x00000004 +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_F__LEN 0x00000100 +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_F_INDEX__MASK 0x000000ff +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_F_INDEX__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_F_X__MASK 0x000fff00 +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_F_X__SHIFT 8 +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_F_Y__MASK 0xfff00000 +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_F_Y__SHIFT 20 + +#define NV04_GDI_RECTANGLE_TEXT_FONT_G 0x000017f0 +#define NV04_GDI_RECTANGLE_TEXT_FONT_G_OFFSET__MASK 0x0fffffff +#define NV04_GDI_RECTANGLE_TEXT_FONT_G_OFFSET__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_FONT_G_PITCH__MASK 0xf0000000 +#define NV04_GDI_RECTANGLE_TEXT_FONT_G_PITCH__SHIFT 28 + +#define NV04_GDI_RECTANGLE_TEXT_CLIP_G_POINT0 0x000017f4 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_G_POINT0_L__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_CLIP_G_POINT0_L__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_G_POINT0_T__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_G_POINT0_T__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_CLIP_G_POINT1 0x000017f8 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_G_POINT1_R__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_CLIP_G_POINT1_R__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_G_POINT1_B__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_CLIP_G_POINT1_B__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_COLOR1_G 0x000017fc + +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_G_POINT(i0) (0x00001800 + 0x8*(i0)) +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_G_POINT__ESIZE 0x00000008 +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_G_POINT__LEN 0x00000100 +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_G_POINT_X__MASK 0x0000ffff +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_G_POINT_X__SHIFT 0 +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_G_POINT_Y__MASK 0xffff0000 +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_G_POINT_Y__SHIFT 16 + +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_G_INDEX(i0) (0x00001804 + 0x8*(i0)) +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_G_INDEX__ESIZE 0x00000008 +#define NV04_GDI_RECTANGLE_TEXT_CHARACTER_COLOR1_G_INDEX__LEN 0x00000100 + + +#define NV10_TEXTURE_FROM_CPU_WAIT_FOR_IDLE 0x00000108 + +#define NV10_TEXTURE_FROM_CPU_DMA_NOTIFY 0x00000180 + +#define NV10_TEXTURE_FROM_CPU_SURFACE 0x00000184 + +#define NV10_TEXTURE_FROM_CPU_COLOR_FORMAT 0x00000300 + +#define NV10_TEXTURE_FROM_CPU_POINT 0x00000304 +#define NV10_TEXTURE_FROM_CPU_POINT_X__MASK 0x0000ffff +#define NV10_TEXTURE_FROM_CPU_POINT_X__SHIFT 0 +#define NV10_TEXTURE_FROM_CPU_POINT_Y__MASK 0xffff0000 +#define NV10_TEXTURE_FROM_CPU_POINT_Y__SHIFT 16 + +#define NV10_TEXTURE_FROM_CPU_SIZE 0x00000308 +#define NV10_TEXTURE_FROM_CPU_SIZE_W__MASK 0x0000ffff +#define NV10_TEXTURE_FROM_CPU_SIZE_W__SHIFT 0 +#define NV10_TEXTURE_FROM_CPU_SIZE_H__MASK 0xffff0000 +#define NV10_TEXTURE_FROM_CPU_SIZE_H__SHIFT 16 + +#define NV10_TEXTURE_FROM_CPU_CLIP_HORIZONTAL 0x0000030c +#define NV10_TEXTURE_FROM_CPU_CLIP_HORIZONTAL_X__MASK 0x0000ffff +#define NV10_TEXTURE_FROM_CPU_CLIP_HORIZONTAL_X__SHIFT 0 +#define NV10_TEXTURE_FROM_CPU_CLIP_HORIZONTAL_W__MASK 0xffff0000 +#define NV10_TEXTURE_FROM_CPU_CLIP_HORIZONTAL_W__SHIFT 16 + +#define NV10_TEXTURE_FROM_CPU_CLIP_VERTICAL 0x00000310 +#define NV10_TEXTURE_FROM_CPU_CLIP_VERTICAL_Y__MASK 0x0000ffff +#define NV10_TEXTURE_FROM_CPU_CLIP_VERTICAL_Y__SHIFT 0 +#define NV10_TEXTURE_FROM_CPU_CLIP_VERTICAL_H__MASK 0xffff0000 +#define NV10_TEXTURE_FROM_CPU_CLIP_VERTICAL_H__SHIFT 16 + +#define NV10_TEXTURE_FROM_CPU_COLOR(i0) (0x00000400 + 0x4*(i0)) +#define NV10_TEXTURE_FROM_CPU_COLOR__ESIZE 0x00000004 +#define NV10_TEXTURE_FROM_CPU_COLOR__LEN 0x00000700 + + +#endif /* NV01_2D_XML */ diff --git a/src/gallium/drivers/nvfx/nv04_2d.c b/src/gallium/drivers/nvfx/nv04_2d.c new file mode 100644 index 0000000..e0e65e7 --- /dev/null +++ b/src/gallium/drivers/nvfx/nv04_2d.c @@ -0,0 +1,1393 @@ +/************************************************************************** + * + * Copyright 2009 Ben Skeggs + * Copyright 2009 Younes Manton + * Copyright 2010 Luca Barbieri + * 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. + * + **************************************************************************/ + +/* this code has no Mesa or Gallium dependency and can be reused in the classic Mesa driver or DDX */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "nv04_2d.h" + +#include "nouveau/nv_object.xml.h" +#include "nouveau/nv_m2mf.xml.h" +#include "nv01_2d.xml.h" + +/* avoid depending on Mesa/Gallium */ +#ifdef __GNUC__ +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) +#else +#define likely(x) !!(x) +#define unlikely(x) !!(x) +#endif + +#define MIN2( A, B ) ( (A)<(B) ? (A) : (B) ) +#define MAX2( A, B ) ( (A)>(B) ? (A) : (B) ) + +struct nv04_2d_context +{ + struct nouveau_notifier *ntfy; + struct nouveau_grobj *surf2d; + struct nouveau_grobj *swzsurf; + struct nouveau_grobj *m2mf; + struct nouveau_grobj *rect; + struct nouveau_grobj *sifm; + struct nouveau_grobj *blit; +}; + +static inline int +align(int value, int alignment) +{ + return (value + alignment - 1) & ~(alignment - 1); +} + +static inline int +util_is_pot(unsigned x) +{ + return (x & (x - 1)) == 0; +} + +/* Integer base-2 logarithm, rounded towards zero. */ +static inline unsigned log2i(unsigned i) +{ + unsigned r = 0; + + if (i & 0xffff0000) { + i >>= 16; + r += 16; + } + if (i & 0x0000ff00) { + i >>= 8; + r += 8; + } + if (i & 0x000000f0) { + i >>= 4; + r += 4; + } + if (i & 0x0000000c) { + i >>= 2; + r += 2; + } + if (i & 0x00000002) { + r += 1; + } + return r; +} + +//#define NV04_REGION_DEBUG + +// Yes, we really want to inline everything, since all the functions are used only once +#if defined(__GNUC__) && !defined(DEBUG) +#define inline __attribute__((always_inline)) inline +#endif + +static inline unsigned +nv04_swizzle_bits_square(unsigned x, unsigned y) +{ + unsigned u = (x & 0x001) << 0 | + (x & 0x002) << 1 | + (x & 0x004) << 2 | + (x & 0x008) << 3 | + (x & 0x010) << 4 | + (x & 0x020) << 5 | + (x & 0x040) << 6 | + (x & 0x080) << 7 | + (x & 0x100) << 8 | + (x & 0x200) << 9 | + (x & 0x400) << 10 | + (x & 0x800) << 11; + + unsigned v = (y & 0x001) << 1 | + (y & 0x002) << 2 | + (y & 0x004) << 3 | + (y & 0x008) << 4 | + (y & 0x010) << 5 | + (y & 0x020) << 6 | + (y & 0x040) << 7 | + (y & 0x080) << 8 | + (y & 0x100) << 9 | + (y & 0x200) << 10 | + (y & 0x400) << 11 | + (y & 0x800) << 12; + return v | u; +} + +/* rectangular swizzled textures are linear concatenations of swizzled square tiles */ +static inline unsigned +nv04_swizzle_bits_2d(unsigned x, unsigned y, unsigned w, unsigned h) +{ + if(h <= 1) + return x; + else + { + unsigned s = MIN2(w, h); + unsigned m = s - 1; + return (((x | y) & ~m) * s) | nv04_swizzle_bits_square(x & m, y & m); + } +} + +// general 3D texture case +static inline unsigned +nv04_swizzle_bits(unsigned x, unsigned y, unsigned z, unsigned w, unsigned h, unsigned d) +{ + if(d <= 1) + return nv04_swizzle_bits_2d(x, y, w, h); + else + { + // TODO: autogenerate code for all possible texture sizes (13 * 13 * 13 with dims <= 4096) and do a single indirect call + unsigned v = 0; + w >>= 1; + h >>= 1; + d >>= 1; + for(int i = 0;;) + { + int oldi = i; + if(likely(w)) + { + v |= (x & 1) << i; + x >>= 1; + w >>= 1; + ++i; + } + + if(likely(h)) + { + v |= (y & 1) << i; + y >>= 1; + h >>= 1; + ++i; + } + + if(likely(d)) + { + v |= (z & 1) << i; + z >>= 1; + d >>= 1; + ++i; + } + + if(i == oldi) + break; + } + return v; + } +} + +unsigned +nv04_region_begin(struct nv04_region* rgn, unsigned w, unsigned h) +{ + if(rgn->pitch) + return rgn->pitch * rgn->y + (rgn->x << rgn->bpps); + else + return nv04_swizzle_bits(rgn->x, rgn->y, rgn->z, rgn->w, rgn->h, rgn->d) << rgn->bpps; +} + +unsigned +nv04_region_end(struct nv04_region* rgn, unsigned w, unsigned h) +{ + if(rgn->pitch) + return rgn->pitch * (rgn->y + h - 1) + ((rgn->x + w) << rgn->bpps); + else + return (nv04_swizzle_bits(rgn->x + w - 1, rgn->y + h - 1, rgn->z, rgn->w, rgn->h, rgn->d) + 1) << rgn->bpps; +} + +// *pitch = -1 -> use 3D swizzling for (x, y), *pitch = 0 -> use 2D swizzling, other *pitch -> use linear calculations +// returns 2 if pixel order is 3D-swizzled and 1 if subrect is 2D-swizzled +/* *pitch == -1 ret = 0 -> 3D swizzled subrect + * *pitch == 0 ret = 0 -> 2D swizzled subrect + * *pitch > 0 ret = 0 -> linear subrect + * *pitch > 0 ret = 1 -> linear subrect, but with swizzled 3D data inside + */ + +static inline void +nv04_region_print(struct nv04_region* rgn) +{ + fprintf(stderr, "<%i[%i]> ", rgn->bo->handle, rgn->offset); + if(rgn->pitch) + fprintf(stderr, "lin %i", rgn->pitch); + else + fprintf(stderr, "swz %ix%ix%i", rgn->w, rgn->h, rgn->d); + fprintf(stderr, " (%i, %i, %i)", rgn->x, rgn->y, rgn->z); +} + +static inline void +nv04_region_assert(struct nv04_region* rgn, unsigned w, unsigned h) +{ + unsigned end = rgn->offset + nv04_region_end(rgn, w, h); + + assert(rgn->offset <= (int)rgn->bo->size); + assert(end <= rgn->bo->size); + (void) end; + if(!rgn->pitch) { + assert(util_is_pot(rgn->w)); + assert(util_is_pot(rgn->h)); + } +} + +/* determine if region can be linearized or fake-linearized */ +static inline int +nv04_region_is_contiguous(struct nv04_region* rgn, int w, int h) +{ + int surf_min; + int rect_min; + + if(rgn->pitch) + return rgn->pitch == w << rgn->bpps; + + // redundant, but this is the fast path for the common case + if(w == rgn->w && h == rgn->h && rgn->d <= 1) + return 1; + + // must be POT + if((w & (w - 1)) || (h & (h - 1))) + return 0; + + // must be aligned + if((rgn->x & (w - 1)) || (rgn->y & (h - 1))) + return 0; + + if(rgn->d > 1) + return 0; + + surf_min = MIN2(rgn->w, rgn->h); + rect_min = MIN2(w, h); + + if((rect_min == surf_min) || (w == h) || (w == 2 * h)) + return 1; + + return 0; +} + +// double the pitch until it is larger than the alignment, or the height becomes odd or 1 +static inline void +nv04_region_contiguous_shape(struct nv04_region* rgn, int* w, int* h, int align) +{ + while(!(*h & 1) && (*w << rgn->bpps) < (1 << align)) + { + *w <<= 1; + *h >>= 1; + } + + while((*w << rgn->bpps) > 16384 && !(*w & 1)) + { + *w >>= 1; + *h <<= 1; + } + +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\tCONTIGUOUS %ix%i\n", *w, *h); +#endif +} + +static inline void +nv04_region_linearize_contiguous(struct nv04_region* rgn, unsigned w, unsigned h) +{ + int pos; + if(rgn->pitch) + { + rgn->offset += rgn->y * rgn->pitch + (rgn->x << rgn->bpps); + rgn->x = 0; + rgn->y = 0; + } + else + { + rgn->offset += (rgn->w * rgn->h * rgn->z) << rgn->bpps; + pos = nv04_swizzle_bits(rgn->x, rgn->y, rgn->z, rgn->w, rgn->h, rgn->d); + rgn->x = pos & (w - 1); + rgn->y = pos / w; + } + rgn->pitch = w << rgn->bpps; + +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\tLINEARIZE "); + nv04_region_print(rgn); + fprintf(stderr, "\n"); +#endif +} + + /* preserve the offset! */ + /* + rgn->pitch = util_format_get_stride(rgn->format, w); + int pos = nv04_swizzle_bits(rgn->x, rgn->y, rgn->z, rgn->w, rgn->h, rgn->d); + rgn->x = pos & (w - 1); + rgn->y = pos & ~(w - 1); + */ + + /* + rgn->offset += + rgn->pitch = util_format_get_stride(rgn->format, w); + rgn->x = 0; + rgn->y = 0; + */ + +/* This code will get used for, and always succeed on: + * - 4x2 1bpp swizzled texture mipmap levels + * - linear regions created by linearization + * + * This code will get used for, and MAY work for: + * - misaligned texture blanket + * - linear surfaces created without wide_pitch (in this case, it will only work if we are lucky) + * + * The general case requires splitting the region in 2. + */ +static inline int +nv04_region_do_align_offset(struct nv04_region* rgn, unsigned w, unsigned h, int shift) +{ + if(rgn->pitch > 0) + { + assert(!(rgn->offset & ((1 << rgn->bpps) - 1))); // fatal! + + if(h <= 1) + { + int delta; + rgn->offset += rgn->y * rgn->pitch + (rgn->x << rgn->bpps); + delta = rgn->offset & ((1 << shift) - 1); + rgn->y = 0; + rgn->x = delta >> rgn->bpps; + rgn->offset -= delta; + rgn->pitch = align((rgn->x + w) << rgn->bpps, 1 << shift); + } + else + { + int delta = rgn->offset & ((1 << shift) - 1); + int newxo = (rgn->x << rgn->bpps) + delta; + int dy = newxo / rgn->pitch; + newxo -= dy * rgn->pitch; + if((newxo + (w << rgn->bpps)) > rgn->pitch) + { + // TODO: split the region into two rectangles (!) if *really* necessary, unless the hardware actually supports "wrapping" rectangles + // this does not happen if the surface is pitch-aligned, which it should always be + assert(0); + return -1; + } + rgn->x = newxo >> rgn->bpps; + rgn->y += dy; + } + } + else + { + int size; + int min; + int v; + + // we don't care about the alignment of 3D surfaces since the 2D engine can't use them + if(rgn->d < 0) + return -1; + + min = MIN2(rgn->w, rgn->h); + size = min * min << rgn->bpps; + + // this is unfixable, and should not be happening + if(rgn->offset & (size - 1)) + return -1; + + v = (rgn->offset & ((1 << shift) - 1)) / size; + rgn->offset -= v * size; + + if(rgn->h == min) + { + unsigned w; + rgn->x += rgn->h * v; + w = rgn->w + rgn->h * v; + + while(rgn->w < w) + rgn->w += rgn->w; + } + else + { + unsigned h; + rgn->y += rgn->w * v; + h = rgn->h + rgn->w * v; + + while(rgn->h < h) + rgn->h += rgn->h; + } + } + +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\tALIGNED "); + nv04_region_print(rgn); + fprintf(stderr, "\n"); +#endif + return 0; +} + +// both pitch and shift +// will leave the region unchanged if it fails +static inline int +nv04_region_align(struct nv04_region* rgn, unsigned w, unsigned h, int shift) +{ + if(rgn->pitch & ((1 << shift) - 1)) + { + if(h == 1) + goto do_align; /* this will fix pitch too in this case */ + else + return -1; + } + + if(rgn->offset & ((1 << shift) - 1)) + { + do_align: + if(nv04_region_do_align_offset(rgn, w, h, shift)) + return -1; + } + return 0; +} + +/* this contains 22 different copy loops after preprocessing. unfortunately, it's necessary */ +void +nv04_region_copy_cpu(struct nv04_region* dst, struct nv04_region* src, int w, int h) +{ + uint8_t* mdst; + uint8_t* msrc; + int size; + + if(dst->bo != src->bo) + { + nouveau_bo_map(dst->bo, NOUVEAU_BO_WR); + nouveau_bo_map(src->bo, NOUVEAU_BO_RD); + } + else + nouveau_bo_map(dst->bo, NOUVEAU_BO_WR | NOUVEAU_BO_RD); + + mdst = (uint8_t*)dst->bo->map + dst->offset; + msrc = (uint8_t*)src->bo->map + src->offset; + + size = w << dst->bpps; + + nv04_region_assert(dst, w, h); + nv04_region_assert(src, w, h); + +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\tRGN_COPY_CPU [%i, %i: %i] ", w, h, dst->bpps); + for(int i = 0; i < 2; ++i) + { + nv04_region_print(i ? src : dst); + fprintf(stderr, i ? "\n" : " <- "); + } + +// for(int i = 0; i < 16; ++i) +// fprintf(stderr, "%02x ", msrc[i]); +// fprintf(stderr, "\n"); +#endif + + // TODO: support overlapping copies! + if(src->pitch && dst->pitch) + { + mdst += dst->y * dst->pitch + (dst->x << dst->bpps); + msrc += src->y * src->pitch + (src->x << src->bpps); + if(dst->bo != src->bo) + goto simple; + else if(mdst < msrc) + { + if(mdst + size <= msrc) + { +simple: + for(int iy = 0; iy < h; ++iy) + { + assert(mdst + size <= (uint8_t*)dst->bo->map + dst->bo->size); + assert(msrc + size <= (uint8_t*)src->bo->map + src->bo->size); + memcpy(mdst, msrc, size); + msrc += src->pitch; mdst += dst->pitch; + } + } + else + { + for(int iy = 0; iy < h; ++iy) + { + assert(mdst + size <= (uint8_t*)dst->bo->map + dst->bo->size); + assert(msrc + size <= (uint8_t*)src->bo->map + src->bo->size); + memmove(mdst, msrc, size); + msrc += src->pitch; mdst += dst->pitch; + } + } + } + else + { + /* copy backwards so we don't destroy data we have to read yet */ + if(msrc + size <= mdst) + { + for(int iy = h - 1; iy >= 0; --iy) + { + assert(mdst + size <= (uint8_t*)dst->bo->map + dst->bo->size); + assert(msrc + size <= (uint8_t*)src->bo->map + src->bo->size); + memcpy(mdst, msrc, size); + msrc += src->pitch; mdst += dst->pitch; + } + } + else + { + for(int iy = h - 1; iy >= 0; --iy) + { + assert(mdst + size <= (uint8_t*)dst->bo->map + dst->bo->size); + assert(msrc + size <= (uint8_t*)src->bo->map + src->bo->size); + memmove(mdst, msrc, size); + msrc += src->pitch; mdst += dst->pitch; + } + } + } + } + else + { + int* dswx = NULL; + int* dswy = NULL; + int* sswx = NULL; + int* sswy = NULL; + int dir; + + if(!dst->pitch) + { + dswx = alloca(w * sizeof(int)); + for(int ix = 0; ix < w; ++ix) // we are adding, so z cannot be contributed by both + dswx[ix] = nv04_swizzle_bits(dst->x + ix, 0, 0, dst->w, dst->h, dst->d); + dswy = alloca(h * sizeof(int)); + for(int iy = 0; iy < h; ++iy) + dswy[iy] = nv04_swizzle_bits(0, dst->y + iy, dst->z, dst->w, dst->h, dst->d); + } + + if(!src->pitch) + { + sswx = alloca(w * sizeof(int)); + for(int ix = 0; ix < w; ++ix) + sswx[ix] = nv04_swizzle_bits(src->x + ix, 0, 0, src->w, src->h, src->d); + sswy = alloca(h * sizeof(int)); + for(int iy = 0; iy < h; ++iy) + sswy[iy] = nv04_swizzle_bits(0, src->y + iy, src->z, src->w, src->h, src->d); + } + + dir = 1; + /* do backwards copies for overlapping swizzled surfaces */ + if(dst->pitch == src->pitch && dst->offset == src->offset) + { + if(dst->y > src->y || (dst->y == src->y && dst->x > src->x)) + dir = -1; + } + +#define SWIZZLED_COPY_LOOPS + if(dir == 1) + { + int dir = 1; +#define LOOP_Y for(int iy = 0; iy < h; ++iy) +#define LOOP_X for(int ix = 0; ix < w; ++ix) +#include "nv04_2d_loops.h" +#undef LOOP_X +#undef LOOP_Y + } + else + { + int dir = -1; +#define LOOP_Y for(int iy = h - 1; iy >= 0; --iy) +#define LOOP_X for(int ix = w - 1; ix >= 0; --ix) +#include "nv04_2d_loops.h" +#undef LOOP_X +#undef LOOP_Y + } +#undef SWIZZLED_COPY_LOOP + } + + if(src->bo != dst->bo) + nouveau_bo_unmap(src->bo); + nouveau_bo_unmap(dst->bo); +} + +/* TODO: if the destination is swizzled, we are doing random writes, which causes write combining to fail + * the alternative is to read, modify and copy back, which may or may not be faster + * loading 3D textures is a common case that hits this and could probably benefit from the temporary + */ +void +nv04_region_fill_cpu(struct nv04_region* dst, int w, int h, unsigned value) +{ + uint8_t* mdst = (nouveau_bo_map(dst->bo, NOUVEAU_BO_WR), (uint8_t*)dst->bo->map + dst->offset); + +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\tRGN_FILL_CPU "); + nv04_region_print(dst); + fprintf(stderr, "\n"); +#endif + + nv04_region_assert(dst, w, h); + + if(dst->pitch) + { + unsigned size = w << dst->bpps; + +#define FILL(T) do { \ + for(int iy = 0; iy < h; ++iy) \ + { \ + assert((char*)((T*)mdst + w) <= (char*)dst->bo->map + dst->bo->size); \ + for(int ix = 0; ix < w; ++ix) \ + ((T*)mdst)[ix] = (T)value; \ + mdst += dst->pitch; \ + } \ + } while(0) + + mdst += dst->y * dst->pitch + (dst->x << dst->bpps); + + if(dst->bpps == 0) + { +ms: + assert(mdst + size * h <= (uint8_t*)dst->bo->map + dst->bo->size); + if(size == dst->pitch) + memset(mdst, (uint8_t)value, size * h); + else + { + for(int iy = 0; iy < h; ++iy) + { + assert(mdst + size <= (uint8_t*)dst->bo->map + dst->bo->size); + memset(mdst, (uint8_t)value, size); + mdst += dst->pitch; + } + } + } + else if(dst->bpps == 1) + { + if(!((uint8_t)value ^ (uint8_t)(value >> 8))) + goto ms; + + FILL(uint16_t); + } + else if(dst->bpps == 2) + { + if(value == (uint8_t)value * 0x1010101) + goto ms; + FILL(uint32_t); + } + else + assert(0); +#undef FILL + } + else + { + int* dswx; + int* dswy; + + dswx = alloca(w * sizeof(int)); + for(int ix = 0; ix < w; ++ix) + dswx[ix] = nv04_swizzle_bits(dst->x + ix, 0, dst->z, dst->w, dst->h, dst->d); + dswy = alloca(h * sizeof(int)); + for(int iy = 0; iy < h; ++iy) + dswy[iy] = nv04_swizzle_bits(0, dst->y + iy, dst->z, dst->w, dst->h, dst->d); + +#define FILL(T) do { \ + T tvalue = (T)value; \ + for(int iy = 0; iy < h; ++iy) \ + { \ + T* pdst = (T*)mdst + dswy[iy]; \ + for(int ix = 0; ix < w; ++ix) \ + { \ + assert((uint8_t*)&pdst[dswx[ix] + 1] <= (uint8_t*)dst->bo->map + dst->bo->size); \ + pdst[dswx[ix]] = tvalue; \ + } \ + } \ + } while(0) + + if(dst->bpps == 0) + FILL(uint8_t); + else if(dst->bpps == 1) + FILL(uint16_t); + else if(dst->bpps == 2) + FILL(uint32_t); + else + assert(0 && "unhandled bpp"); +#undef FILL + } + + nouveau_bo_unmap(dst->bo); +} + +static inline int +nv04_region_cs2d_format(struct nv04_region* rgn) +{ + switch(rgn->bpps) { + case 0: + return NV04_CONTEXT_SURFACES_2D_FORMAT_Y8; + case 1: + if(rgn->one_bits >= 1) + return NV04_CONTEXT_SURFACES_2D_FORMAT_X1R5G5B5_X1R5G5B5; + else + return NV04_CONTEXT_SURFACES_2D_FORMAT_R5G6B5; + case 2: + if(rgn->one_bits >= 8) + return NV04_CONTEXT_SURFACES_2D_FORMAT_X8R8G8B8_X8R8G8B8; + else + return NV04_CONTEXT_SURFACES_2D_FORMAT_A8R8G8B8; + default: + return -1; + } +} + +static inline int +nv04_region_sifm_format(struct nv04_region* rgn) +{ + switch(rgn->bpps) { + case 0: + return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_Y8; + case 1: + if(rgn->one_bits >= 1) + return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_X1R5G5B5; + else + return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_R5G6B5; + case 2: + if(rgn->one_bits >= 8) + return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_X8R8G8B8; + else + return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_A8R8G8B8; + default: + return -1; + } +} +static void +nv04_region_copy_swizzle(struct nv04_2d_context *ctx, + struct nv04_region* dst, + struct nv04_region* src, + int w, int h) +{ + struct nouveau_channel *chan = ctx->swzsurf->channel; + struct nouveau_grobj *swzsurf = ctx->swzsurf; + struct nouveau_grobj *sifm = ctx->sifm; + int cs2d_format = nv04_region_cs2d_format(dst); + int sifm_format = nv04_region_sifm_format(src); + /* Max width & height may not be the same on all HW, but must be POT */ + unsigned max_shift = 10; + unsigned cw = 1 << max_shift; + unsigned ch = 1 << max_shift; + unsigned sx = dst->x >> max_shift; + unsigned sy = dst->y >> max_shift; + unsigned ex = (dst->x + w - 1) >> max_shift; + unsigned ey = (dst->y + h - 1) >> max_shift; + unsigned chunks = (ex - sx + 1) * (ey - sy + 1); + unsigned chunk_size; + if(dst->w < cw) + cw = dst->w; + if(dst->h < ch) + ch = dst->h; + chunk_size = cw * ch << dst->bpps; + +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\tRGN_COPY_SWIZZLE [%i, %i: %i] ", w, h, dst->bpps); + for(int i = 0; i < 2; ++i) + { + nv04_region_print(i ? src : dst); + fprintf(stderr, i ? "\n" : " <- "); + } +#endif + + nv04_region_assert(dst, w, h); + nv04_region_assert(src, w, h); + + MARK_RING (chan, 8 + chunks * 17, 2 + chunks * 2); + + BEGIN_RING(chan, swzsurf, NV04_SWIZZLED_SURFACE_DMA_IMAGE, 1); + OUT_RELOCo(chan, dst->bo, + NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + + BEGIN_RING(chan, swzsurf, NV04_SWIZZLED_SURFACE_FORMAT, 1); + OUT_RING (chan, cs2d_format | + log2i(cw) << NV04_SWIZZLED_SURFACE_FORMAT_BASE_SIZE_U__SHIFT | + log2i(ch) << NV04_SWIZZLED_SURFACE_FORMAT_BASE_SIZE_V__SHIFT); + + BEGIN_RING(chan, sifm, NV03_SCALED_IMAGE_FROM_MEMORY_DMA_IMAGE, 1); + OUT_RELOCo(chan, src->bo, + NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + BEGIN_RING(chan, sifm, NV04_SCALED_IMAGE_FROM_MEMORY_SURFACE, 1); + OUT_RING (chan, swzsurf->handle); + + assert(!(dst->offset & 63)); + + for (int cy = sy; cy <= ey; ++cy) { + int ry = MAX2(0, (int)(dst->y - ch * cy)); + int rh = MIN2((int)ch, (int)(dst->y - ch * cy + h)) - ry; + for (int cx = sx; cx <= ex; ++cx) { + int rx = MAX2(0, (int)(dst->x - cw * cx)); + int rw = MIN2((int)cw, (int)(dst->x - cw * cx + w)) - rx; + unsigned dst_offset; + unsigned src_offset; + + BEGIN_RING(chan, swzsurf, NV04_SWIZZLED_SURFACE_OFFSET, 1); + + dst_offset = dst->offset + (nv04_swizzle_bits_2d(cx * cw, cy * ch, dst->w, dst->h) << dst->bpps); + assert(dst_offset <= dst->bo->size); + assert(dst_offset + chunk_size <= dst->bo->size); + OUT_RELOCl(chan, dst->bo, dst_offset, + NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + + BEGIN_RING(chan, sifm, NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION, 9); + OUT_RING (chan, NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION_TRUNCATE); + OUT_RING (chan, sifm_format); + OUT_RING (chan, NV03_SCALED_IMAGE_FROM_MEMORY_OPERATION_SRCCOPY); + OUT_RING (chan, rx | (ry << NV03_SCALED_IMAGE_FROM_MEMORY_CLIP_POINT_Y__SHIFT)); + OUT_RING (chan, rh << NV03_SCALED_IMAGE_FROM_MEMORY_CLIP_SIZE_H__SHIFT | rw); + OUT_RING (chan, rx | (ry << NV03_SCALED_IMAGE_FROM_MEMORY_OUT_POINT_Y__SHIFT)); + OUT_RING (chan, rh << NV03_SCALED_IMAGE_FROM_MEMORY_OUT_SIZE_H__SHIFT | rw); + OUT_RING (chan, 1 << 20); + OUT_RING (chan, 1 << 20); + + BEGIN_RING(chan, sifm, NV03_SCALED_IMAGE_FROM_MEMORY_SIZE, 4); + OUT_RING (chan, rh << NV03_SCALED_IMAGE_FROM_MEMORY_SIZE_H__SHIFT | align(rw, 8)); + OUT_RING (chan, src->pitch | + NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_ORIGIN_CENTER | + NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_FILTER_POINT_SAMPLE); + src_offset = src->offset + (cy * ch + ry + src->y - dst->y) * src->pitch + ((cx * cw + rx + src->x - dst->x) << src->bpps); + assert(src_offset <= src->bo->size); + assert(src_offset + (src->pitch * (rh - 1)) + (rw << src->bpps) <= src->bo->size); + OUT_RELOCl(chan, src->bo, src_offset, + NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RING (chan, 0); + } + } +} + +static inline void +nv04_copy_m2mf_begin(struct nv04_2d_context *ctx, struct nouveau_bo* dstbo, struct nouveau_bo* srcbo, unsigned commands) +{ + struct nouveau_channel *chan = ctx->m2mf->channel; + struct nouveau_grobj *m2mf = ctx->m2mf; + MARK_RING (chan, 3 + commands * 9, 2 + commands * 2); + BEGIN_RING(chan, m2mf, NV04_M2MF_DMA_BUFFER_IN, 2); + OUT_RELOCo(chan, srcbo, + NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RELOCo(chan, dstbo, + NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); +} + +static inline void +nv04_copy_m2mf_body(struct nv04_2d_context *ctx, struct nouveau_bo* dstbo, int* pdstoff, unsigned dstpitch, struct nouveau_bo* srcbo, int* psrcoff, unsigned srcpitch, unsigned size, unsigned lines) +{ + struct nouveau_channel *chan = ctx->m2mf->channel; + struct nouveau_grobj *m2mf = ctx->m2mf; + +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\t\t\tCOPY_M2MF_BODY [%i, %i] <%i[%u]> lin %u <- <%i[%u]> lin %u\n", size, lines, dstbo->handle, *pdstoff, dstpitch, srcbo->handle, *psrcoff, srcpitch); +#endif + + BEGIN_RING(chan, m2mf, NV04_M2MF_OFFSET_IN, 8); + OUT_RELOCl(chan, srcbo, *psrcoff, + NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD); + OUT_RELOCl(chan, dstbo, *pdstoff, + NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_WR); + OUT_RING (chan, srcpitch); + OUT_RING (chan, dstpitch); + OUT_RING (chan, size); + OUT_RING (chan, lines); + OUT_RING (chan, 0x0101); + OUT_RING (chan, 0); + + *psrcoff += srcpitch * lines; + *pdstoff += dstpitch * lines; +} + +static void +nv04_copy_m2mf(struct nv04_2d_context *ctx, + struct nouveau_bo* dstbo, int dstoff, unsigned dstpitch, + struct nouveau_bo* srcbo, int srcoff, unsigned srcpitch, + unsigned size, unsigned h) +{ + unsigned max_pitch = 32767; + unsigned max_lines = 2047; + +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\t\tCOPY_M2MF [%i, %i] <%i[%i]> lin %u <- <%i[%i]> lin %u\n", size, h, dstbo->handle, dstoff, dstpitch, srcbo->handle, srcoff, srcpitch); +#endif + + if(srcpitch <= max_pitch && dstpitch <= max_pitch) + { + unsigned full_pages = h / max_lines; + unsigned leftover_lines = h - full_pages * max_lines; + + nv04_copy_m2mf_begin(ctx, dstbo, srcbo, full_pages + !!leftover_lines); + + for(unsigned i = 0; i < full_pages; ++i) + nv04_copy_m2mf_body(ctx, dstbo, &dstoff, dstpitch, srcbo, &srcoff, srcpitch, size, max_lines); + + if(leftover_lines) + nv04_copy_m2mf_body(ctx, dstbo, &dstoff, dstpitch, srcbo, &srcoff, srcpitch, size, leftover_lines); + } + else + { + unsigned lines = size / max_pitch; + unsigned leftover = size - lines * max_pitch; + unsigned full_pages = lines / max_lines; + unsigned leftover_lines = lines - full_pages * max_lines; + unsigned srcgap = srcpitch - size; + unsigned dstgap = dstpitch - size; + + nv04_copy_m2mf_begin(ctx, dstbo, srcbo, h * (full_pages + !!leftover_lines + !!leftover)); + + for(unsigned i = 0; i < h; ++i) + { + for(unsigned j = 0; j < full_pages; ++j) + nv04_copy_m2mf_body(ctx, dstbo, &dstoff, max_pitch, srcbo, &srcoff, max_pitch, max_pitch, max_lines); + + if(leftover_lines) + nv04_copy_m2mf_body(ctx, dstbo, &dstoff, max_pitch, srcbo, &srcoff, max_pitch, max_pitch, leftover_lines); + + if(leftover) + nv04_copy_m2mf_body(ctx, dstbo, &dstoff, leftover, srcbo, &srcoff, leftover, leftover, 1); + + srcoff += srcgap; + dstoff += dstgap; + } + } +} + +void +nv04_memcpy(struct nv04_2d_context *ctx, struct nouveau_bo* dstbo, int dstoff, struct nouveau_bo* srcbo, int srcoff, unsigned size) +{ +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\tMEMCPY [%i] <%i[%i]> <- <%i[%i]>\n", size, dstbo->handle, dstoff, srcbo->handle, srcoff); +#endif + + nv04_copy_m2mf(ctx, dstbo, dstoff, size, srcbo, srcoff, size, size, 1); +} + +static void +nv04_region_copy_m2mf(struct nv04_2d_context *ctx, struct nv04_region *dst, struct nv04_region *src, int w, int h) +{ +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\tRGN_COPY_M2MF [%i, %i: %i] ", w, h, dst->bpps); + for(int i = 0; i < 2; ++i) + { + nv04_region_print(i ? src : dst); + fprintf(stderr, i ? "\n" : " <- "); + } +#endif + + nv04_region_assert(dst, w, h); + nv04_region_assert(src, w, h); + assert(src->pitch); + assert(dst->pitch); + + nv04_copy_m2mf(ctx, + dst->bo, dst->offset + dst->y * dst->pitch + (dst->x << dst->bpps), dst->pitch, + src->bo, src->offset + src->y * src->pitch + (src->x << src->bpps), src->pitch, + w << src->bpps, h); +} + +static inline void +nv04_region_copy_blit(struct nv04_2d_context *ctx, struct nv04_region* dst, struct nv04_region* src, int w, int h) +{ + struct nouveau_channel *chan = ctx->surf2d->channel; + struct nouveau_grobj *surf2d = ctx->surf2d; + struct nouveau_grobj *blit = ctx->blit; + int cs2d_format = nv04_region_cs2d_format(dst); + +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\tRGN_COPY_BLIT [%i, %i: %i] ", w, h, dst->bpps); + for(int i = 0; i < 2; ++i) + { + nv04_region_print(i ? src : dst); + fprintf(stderr, i ? "\n" : " <- "); + } +#endif + + assert(!(src->pitch & 63) && src->pitch); + assert(!(dst->pitch & 63) && dst->pitch); + nv04_region_assert(dst, w, h); + nv04_region_assert(src, w, h); + + MARK_RING (chan, 12, 4); + BEGIN_RING(chan, surf2d, NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE, 2); + OUT_RELOCo(chan, src->bo, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RELOCo(chan, dst->bo, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + BEGIN_RING(chan, surf2d, NV04_CONTEXT_SURFACES_2D_FORMAT, 4); + OUT_RING (chan, cs2d_format); + OUT_RING (chan, (dst->pitch << 16) | src->pitch); + OUT_RELOCl(chan, src->bo, src->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RELOCl(chan, dst->bo, dst->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + + BEGIN_RING(chan, blit, 0x0300, 3); + OUT_RING (chan, (src->y << 16) | src->x); + OUT_RING (chan, (dst->y << 16) | dst->x); + OUT_RING (chan, ( h << 16) | w); +} + +/* THEOREM: a non-linearizable swizzled destination is always 64 byte aligned, except for 4x2 mipmap levels of swizzled 1bpp surfaces + * HYPOTESIS: + * 1. The first mipmap level is 64-byte-aligned + * PROOF: + * 1. Thus, all mipmaps level with a parent which is 64-byte or more in size are. + * 2. At 1bpp, the smallest levels with a <= 32-byte parent are either Nx1 or 1xN or size <=8, thus 4x2, 2x2 or 2x4 + * 3. Nx1, 1xN, 2x4, 2x2 have all subrects linearizable. 4x2 does not. + * 4. At 2/4bpp or more, the smallest levels with a 32-byte parent are 1xN, Nx1 or 2x2 + * + * However, nv04_region_align handles that. + */ + +// 0 -> done, 1 -> do with 3D engine or CPU, -1 -> do with CPU +// dst and src may be modified, and the possibly modified version should be passed to nv04_region_cpu if necessary +int +nv04_region_copy_2d(struct nv04_2d_context *ctx, struct nv04_region* dst, struct nv04_region* src, + int w, int h, int dst_to_gpu, int src_on_gpu) +{ + assert(src->bpps == dst->bpps); + +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "RGN_COPY [%i, %i: %i] ", w, h, dst->bpps); + for(int i = 0; i < 2; ++i) + { + int gpu = i ? src_on_gpu : dst_to_gpu; + nv04_region_print(i ? src : dst); + fprintf(stderr, " %s", gpu ? "gpu" : "cpu"); + fprintf(stderr, i ? "\n" : " <- "); + } +#endif + + // if they are contiguous and either both swizzled or both linear, reshape + if(!dst->pitch == !src->pitch + && nv04_region_is_contiguous(dst, w, h) + && nv04_region_is_contiguous(src, w, h)) + { + nv04_region_contiguous_shape(dst, &w, &h, 6); + nv04_region_linearize_contiguous(dst, w, h); + nv04_region_linearize_contiguous(src, w, h); + } + +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\tOPT "); + for(int i = 0; i < 2; ++i) + { + nv04_region_print(i ? src : dst); + fprintf(stderr, i ? "\n" : " <- "); + } +#endif + + /* if the destination is not for GPU _and_ source is on CPU, use CPU */ + /* if the destination is not for GPU _or_ source is on CPU, use CPU only if we think it's faster than the GPU */ + /* TODO: benchmark to find out in which cases exactly we should prefer the CPU */ + if((!dst_to_gpu && !src_on_gpu) + || (!dst->pitch && dst->d > 1) + /* 3D swizzled destination are unwritable by the GPU, and 2D swizzled ones are readable only by the 3D engine */ + ) + return -1; + /* there is no known way to read 2D/3D-swizzled surfaces with the 2D engine + * ask the caller to use the 3D engine + * If a format cannot be sampled from the 3D engine there is no point in making it swizzled, so we must not do so + */ + else if(!src->pitch) + { +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\tCOPY_ENG3D\n"); +#endif + return 1; + } + /* Setup transfer to swizzle the texture to vram if needed */ + else + { + if (!dst->pitch) + { + if(!dst_to_gpu) + { +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\tCOPY_ENG3D\n"); +#endif + return 1; + } + else + { + assert(!nv04_region_align(dst, w, h, 6)); + + nv04_region_copy_swizzle(ctx, dst, src, w, h); + return 0; + } + } + else + { + /* NV_CONTEXT_SURFACES_2D has buffer alignment restrictions, fallback + * to NV_M2MF in this case. + * TODO: is this also true for the source? possibly not + * TODO: should we just always use m2mf? + * TODO: if not, add support for multiple operations to copy_blit + */ + + if (!dst_to_gpu + || w > 2047 + || h > 2047 + || (w & 1) + || nv04_region_align(src, w, h, 6) + || nv04_region_align(dst, w, h, 6) + ) + nv04_region_copy_m2mf(ctx, dst, src, w, h); + else + nv04_region_copy_blit(ctx, dst, src, w, h); + + return 0; + } + } +} + +static inline void +nv04_region_fill_gdirect(struct nv04_2d_context *ctx, struct nv04_region* dst, int w, int h, unsigned value) +{ + struct nouveau_channel *chan = ctx->surf2d->channel; + struct nouveau_grobj *surf2d = ctx->surf2d; + struct nouveau_grobj *rect = ctx->rect; + int cs2d_format, gdirect_format; + +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\tFILL_GDIRECT\n"); +#endif + + assert(!(dst->pitch & 63) && dst->pitch); + nv04_region_assert(dst, w, h); + + switch(dst->bpps) + { + case 0: + gdirect_format = NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A8R8G8B8; + cs2d_format = NV04_CONTEXT_SURFACES_2D_FORMAT_Y8; + break; + case 1: + gdirect_format = NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A16R5G6B5; + cs2d_format = NV04_CONTEXT_SURFACES_2D_FORMAT_Y16; + break; + case 2: + gdirect_format = NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A8R8G8B8; + cs2d_format = NV04_CONTEXT_SURFACES_2D_FORMAT_Y32; + break; + default: + assert(0); + gdirect_format = 0; + cs2d_format = 0; + break; + } + + MARK_RING (chan, 15, 4); + BEGIN_RING(chan, surf2d, NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE, 2); + OUT_RELOCo(chan, dst->bo, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCo(chan, dst->bo, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + BEGIN_RING(chan, surf2d, NV04_CONTEXT_SURFACES_2D_FORMAT, 4); + OUT_RING (chan, cs2d_format); + OUT_RING (chan, (dst->pitch << 16) | dst->pitch); + OUT_RELOCl(chan, dst->bo, dst->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + OUT_RELOCl(chan, dst->bo, dst->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); + + BEGIN_RING(chan, rect, NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT, 1); + OUT_RING (chan, gdirect_format); + BEGIN_RING(chan, rect, NV04_GDI_RECTANGLE_TEXT_COLOR1_A, 1); + OUT_RING (chan, value); + BEGIN_RING(chan, rect, NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT(0), 2); + OUT_RING (chan, (dst->x << 16) | dst->y); + OUT_RING (chan, ( w << 16) | h); +} + +int +nv04_region_fill_2d(struct nv04_2d_context *ctx, struct nv04_region *dst, + int w, int h, unsigned value) +{ + if(!w || !h) + return 0; + +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "FILL [%i, %i: %i] ", w, h, dst->bpps); + nv04_region_print(dst); + fprintf(stderr, " <- 0x%x\n", value); +#endif + + if(nv04_region_is_contiguous(dst, w, h)) + { + nv04_region_contiguous_shape(dst, &w, &h, 6); + nv04_region_linearize_contiguous(dst, w, h); + } + + // TODO: maybe do intermediate copies for some cases instead of using the 3D engine/CPU + /* GdiRect doesn't work together with swzsurf, so the 3D engine, or an intermediate copy, is the only option here */ + if(!dst->pitch) + { +#ifdef NV04_REGION_DEBUG + fprintf(stderr, "\tFILL_ENG3D\n"); +#endif + return 1; + } + else if(!nv04_region_align(dst, w, h, 6)) + { + nv04_region_fill_gdirect(ctx, dst, w, h, value); + return 0; + } + else + return -1; +} + + +void +nv04_2d_context_takedown(struct nv04_2d_context *ctx) +{ + nouveau_notifier_free(&ctx->ntfy); + nouveau_grobj_free(&ctx->m2mf); + nouveau_grobj_free(&ctx->surf2d); + nouveau_grobj_free(&ctx->swzsurf); + nouveau_grobj_free(&ctx->rect); + nouveau_grobj_free(&ctx->blit); + nouveau_grobj_free(&ctx->sifm); + + free(ctx); +} + +struct nv04_2d_context * +nv04_2d_context_init(struct nouveau_channel* chan) +{ + struct nv04_2d_context *ctx = calloc(1, sizeof(struct nv04_2d_context)); + unsigned handle = 0x88000000, class; + int ret; + + if (!ctx) + return NULL; + + ret = nouveau_notifier_alloc(chan, handle++, 1, &ctx->ntfy); + if (ret) { + nv04_2d_context_takedown(ctx); + return NULL; + } + + ret = nouveau_grobj_alloc(chan, handle++, 0x0039, &ctx->m2mf); + if (ret) { + nv04_2d_context_takedown(ctx); + return NULL; + } + + BEGIN_RING(chan, ctx->m2mf, NV04_M2MF_DMA_NOTIFY, 1); + OUT_RING (chan, ctx->ntfy->handle); + + if (chan->device->chipset < 0x10) + class = NV04_CONTEXT_SURFACES_2D; + else + class = NV10_CONTEXT_SURFACES_2D; + + ret = nouveau_grobj_alloc(chan, handle++, class, &ctx->surf2d); + if (ret) { + nv04_2d_context_takedown(ctx); + return NULL; + } + + BEGIN_RING(chan, ctx->surf2d, + NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE, 2); + OUT_RING (chan, chan->vram->handle); + OUT_RING (chan, chan->vram->handle); + + if (chan->device->chipset < 0x10) + class = NV04_IMAGE_BLIT; + else + class = NV11_IMAGE_BLIT; + + ret = nouveau_grobj_alloc(chan, handle++, class, &ctx->blit); + if (ret) { + nv04_2d_context_takedown(ctx); + return NULL; + } + + BEGIN_RING(chan, ctx->blit, NV01_IMAGE_BLIT_DMA_NOTIFY, 1); + OUT_RING (chan, ctx->ntfy->handle); + BEGIN_RING(chan, ctx->blit, NV04_IMAGE_BLIT_SURFACES, 1); + OUT_RING (chan, ctx->surf2d->handle); + BEGIN_RING(chan, ctx->blit, NV01_IMAGE_BLIT_OPERATION, 1); + OUT_RING (chan, NV01_IMAGE_BLIT_OPERATION_SRCCOPY); + + ret = nouveau_grobj_alloc(chan, handle++, NV04_GDI_RECTANGLE_TEXT, + &ctx->rect); + if (ret) { + nv04_2d_context_takedown(ctx); + return NULL; + } + + BEGIN_RING(chan, ctx->rect, NV04_GDI_RECTANGLE_TEXT_DMA_NOTIFY, 1); + OUT_RING (chan, ctx->ntfy->handle); + BEGIN_RING(chan, ctx->rect, NV04_GDI_RECTANGLE_TEXT_SURFACE, 1); + OUT_RING (chan, ctx->surf2d->handle); + BEGIN_RING(chan, ctx->rect, NV04_GDI_RECTANGLE_TEXT_OPERATION, 1); + OUT_RING (chan, NV04_GDI_RECTANGLE_TEXT_OPERATION_SRCCOPY); + BEGIN_RING(chan, ctx->rect, + NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT, 1); + OUT_RING (chan, NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT_LE); + + switch (chan->device->chipset & 0xf0) { + case 0x00: + case 0x10: + class = NV04_SWIZZLED_SURFACE; + break; + case 0x20: + class = NV11_SWIZZLED_SURFACE; + break; + case 0x30: + class = NV30_SWIZZLED_SURFACE; + break; + case 0x40: + case 0x60: + class = NV40_SWIZZLED_SURFACE; + break; + default: + /* Famous last words: this really can't happen.. */ + assert(0); + break; + } + + ret = nouveau_grobj_alloc(chan, handle++, class, &ctx->swzsurf); + if (ret) { + nv04_2d_context_takedown(ctx); + return NULL; + } + + /* all the Gallium MARK_RING calculations assume no autobinding, so do that now */ + if(ctx->swzsurf->bound == NOUVEAU_GROBJ_UNBOUND) + nouveau_grobj_autobind(ctx->swzsurf); + + switch (chan->device->chipset & 0xf0) { + case 0x10: + case 0x20: + class = NV10_SCALED_IMAGE_FROM_MEMORY; + break; + case 0x30: + class = NV30_SCALED_IMAGE_FROM_MEMORY; + break; + case 0x40: + case 0x60: + class = NV40_SCALED_IMAGE_FROM_MEMORY; + break; + default: + class = NV04_SCALED_IMAGE_FROM_MEMORY; + break; + } + + ret = nouveau_grobj_alloc(chan, handle++, class, &ctx->sifm); + if (ret) { + nv04_2d_context_takedown(ctx); + return NULL; + } + + /* all the Gallium MARK_RING calculations assume no autobinding, so do that now */ + if(ctx->sifm->bound == NOUVEAU_GROBJ_UNBOUND) + nouveau_grobj_autobind(ctx->sifm); + + return ctx; +} diff --git a/src/gallium/drivers/nvfx/nv04_2d.h b/src/gallium/drivers/nvfx/nv04_2d.h new file mode 100644 index 0000000..00ee5bc --- /dev/null +++ b/src/gallium/drivers/nvfx/nv04_2d.h @@ -0,0 +1,107 @@ +/************************************************************************** + * + * Copyright 2009 Ben Skeggs + * Copyright 2009 Younes Manton + * Copyright 2010 Luca Barbieri + * 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. + * + **************************************************************************/ + +/* this code has no Mesa or Gallium dependency and can be reused in the classic Mesa driver or DDX */ + +#ifndef __NV04_2D_H__ +#define __NV04_2D_H__ + +struct nv04_2d_context; +struct nouveau_channel; +struct nouveau_bo; + +// NOTE: all functions taking this as a parameter will CLOBBER it (except for ->bo) +struct nv04_region { + struct nouveau_bo* bo; + int offset; + unsigned pitch; // 0 -> swizzled + unsigned bpps; // bpp shift (0, 1, 2; 3, 4 for fp/compressed) + unsigned one_bits; // number of high bits read and written as ones (for "no-alpha" optimization) + unsigned x, y, z; + unsigned w, h, d; +}; + +static inline void +nv04_region_try_to_linearize(struct nv04_region* rgn) +{ + assert(!rgn->pitch); + + if(rgn->d <= 1) + { + if(rgn->h <= 1 || rgn->w <= 2) + rgn->pitch = rgn->w << rgn->bpps; + } + else + { + if(rgn->h <= 2 && rgn->w <= 2) + { + rgn->pitch = rgn->w << rgn->bpps; + rgn->offset += rgn->z * rgn->h * rgn->pitch; + } + } +} + +void +nv04_memcpy(struct nv04_2d_context *ctx, + struct nouveau_bo* dstbo, int dstoff, + struct nouveau_bo* srcbo, int srcoff, + unsigned size); + +unsigned +nv04_region_begin(struct nv04_region* rgn, unsigned w, unsigned h); + +unsigned +nv04_region_end(struct nv04_region* rgn, unsigned w, unsigned h); + +void +nv04_2d_context_takedown(struct nv04_2d_context *pctx); + +struct nv04_2d_context * +nv04_2d_context_init(struct nouveau_channel* chan); + +void +nv04_region_copy_cpu(struct nv04_region* dst, struct nv04_region* src, int w, int h); + +void +nv04_region_fill_cpu(struct nv04_region* dst, int w, int h, unsigned value); + +int +nv04_region_copy_2d(struct nv04_2d_context *ctx, + struct nv04_region* dst, struct nv04_region* src, + int w, int h, + int dst_to_gpu, int src_on_gpu); + +int +nv04_region_fill_2d(struct nv04_2d_context *ctx, + struct nv04_region *dst, + int w, int h, + unsigned value); + +#endif diff --git a/src/gallium/drivers/nvfx/nv04_2d_loops.h b/src/gallium/drivers/nvfx/nv04_2d_loops.h new file mode 100644 index 0000000..3a6787c --- /dev/null +++ b/src/gallium/drivers/nvfx/nv04_2d_loops.h @@ -0,0 +1,70 @@ +#ifndef T +{ + if(dst->bpps == 0) +#define T uint8_t +#include "nv04_2d_loops.h" +#undef T + else if(dst->bpps == 1) +#define T uint16_t +#include "nv04_2d_loops.h" +#undef T + else if(dst->bpps == 2) +#define T uint32_t +#include "nv04_2d_loops.h" +#undef T + else + assert(0); +} +#else +#ifdef SWIZZLED_COPY_LOOPS +{ + if(!dst->pitch) + { + if(!src->pitch) + { + LOOP_Y + { + T* pdst = (T*)mdst + dswy[iy]; + T* psrc = (T*)msrc + sswy[iy]; + LOOP_X + { + assert((char*)&psrc[sswx[ix] + 1] <= ((char*)src->bo->map + src->bo->size)); + assert((char*)&pdst[dswx[ix] + 1] <= ((char*)dst->bo->map + dst->bo->size)); + pdst[dswx[ix]] = psrc[sswx[ix]]; + } + } + } + else + { + T* psrc = (T*)(msrc + ((dir > 0) ? src->y : (src->y + h - 1)) * src->pitch) + src->x; + LOOP_Y + { + T* pdst = (T*)mdst + dswy[iy]; + LOOP_X + { + assert((char*)&psrc[ix + 1] <= ((char*)src->bo->map + src->bo->size)); + assert((char*)&pdst[dswx[ix] + 1] <= ((char*)dst->bo->map + dst->bo->size)); + pdst[dswx[ix]] = psrc[ix]; + } + psrc = (T*)((char*)psrc + dir * src->pitch); + } + } + } + else + { + T* pdst = (T*)(mdst + ((dir > 0) ? dst->y : (dst->y + h - 1)) * dst->pitch) + dst->x; + LOOP_Y + { + T* psrc = (T*)msrc + sswy[iy]; + LOOP_X + { + assert((char*)&psrc[sswx[ix] + 1] <= ((char*)src->bo->map + src->bo->size)); + assert((char*)&pdst[ix + 1] <= ((char*)dst->bo->map + dst->bo->size)); + pdst[ix] = psrc[sswx[ix]]; + } + pdst = (T*)((char*)pdst + dir * dst->pitch); + } + } +} +#endif +#endif diff --git a/src/gallium/drivers/nvfx/nv30-40_3d.xml.h b/src/gallium/drivers/nvfx/nv30-40_3d.xml.h new file mode 100644 index 0000000..a705a6b --- /dev/null +++ b/src/gallium/drivers/nvfx/nv30-40_3d.xml.h @@ -0,0 +1,2022 @@ +#ifndef NV30_40_3D_XML +#define NV30_40_3D_XML + +/* Autogenerated file, DO NOT EDIT manually! + +This file was generated by the rules-ng-ng headergen tool in this git repository: +http://0x04.net/cgit/index.cgi/rules-ng-ng +git clone git://0x04.net/rules-ng-ng + +The rules-ng-ng source files this header was generated from are: +- nv30-40_3d.xml ( 31709 bytes, from 2010-09-05 08:00:50) +- copyright.xml ( 6503 bytes, from 2010-04-10 23:15:50) +- nv_3ddefs.xml ( 15391 bytes, from 2010-09-05 08:00:46) +- nv_defs.xml ( 4437 bytes, from 2010-08-05 19:38:53) +- nv_object.xml ( 10424 bytes, from 2010-08-05 19:38:53) +- nvchipsets.xml ( 2824 bytes, from 2010-08-05 19:38:53) + +Copyright (C) 2006-2010 by the following authors: +- Artur Huillet (ahuillet) +- Ben Skeggs (darktama, darktama_) +- B. R. (koala_br) +- Carlos Martin (carlosmn) +- Christoph Bumiller (calim, chrisbmr) +- Dawid Gajownik (gajownik) +- Dmitry Baryshkov +- Dmitry Eremin-Solenikov (lumag) +- EdB (edb_) +- Erik Waling (erikwaling) +- Francisco Jerez (curro, curro_, currojerez) +- imirkin (imirkin) +- jb17bsome (jb17bsome) +- Jeremy Kolb (kjeremy) +- Laurent Carlier (lordheavy) +- Luca Barbieri (lb, lb1) +- Maarten Maathuis (stillunknown) +- Marcin Kościelnicki (mwk, koriakin) +- Mark Carey (careym) +- Matthieu Castet (mat-c) +- nvidiaman (nvidiaman) +- Patrice Mandin (pmandin, pmdata) +- Pekka Paalanen (pq, ppaalanen) +- Peter Popov (ironpeter) +- Richard Hughes (hughsient) +- Rudi Cilibrasi (cilibrar) +- Serge Martin +- Simon Raffeiner +- Stephane Loeuillet (leroutier) +- Stephane Marchesin (marcheu) +- sturmflut (sturmflut) +- Sylvain Munaut +- Victor Stinner (haypo) +- Wladmir van der Laan (miathan6) +- Younes Manton (ymanton) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + + + +#define NV30_3D_DMA_NOTIFY 0x00000180 + +#define NV30_3D_DMA_TEXTURE0 0x00000184 + +#define NV30_3D_DMA_TEXTURE1 0x00000188 + +#define NV30_3D_DMA_COLOR1 0x0000018c + +#define NV30_3D_DMA_UNK190 0x00000190 + +#define NV30_3D_DMA_COLOR0 0x00000194 + +#define NV30_3D_DMA_ZETA 0x00000198 + +#define NV30_3D_DMA_VTXBUF0 0x0000019c + +#define NV30_3D_DMA_VTXBUF1 0x000001a0 + +#define NV30_3D_DMA_FENCE 0x000001a4 + +#define NV30_3D_DMA_QUERY 0x000001a8 + +#define NV30_3D_DMA_UNK1AC 0x000001ac + +#define NV30_3D_DMA_UNK1B0 0x000001b0 + +#define NV40_3D_DMA_COLOR2 0x000001b4 + +#define NV40_3D_DMA_COLOR3 0x000001b8 + +#define NV30_3D_RT_HORIZ 0x00000200 +#define NV30_3D_RT_HORIZ_X__MASK 0x0000ffff +#define NV30_3D_RT_HORIZ_X__SHIFT 0 +#define NV30_3D_RT_HORIZ_W__MASK 0xffff0000 +#define NV30_3D_RT_HORIZ_W__SHIFT 16 + +#define NV30_3D_RT_VERT 0x00000204 +#define NV30_3D_RT_VERT_Y__MASK 0x0000ffff +#define NV30_3D_RT_VERT_Y__SHIFT 0 +#define NV30_3D_RT_VERT_H__MASK 0xffff0000 +#define NV30_3D_RT_VERT_H__SHIFT 16 + +#define NV30_3D_RT_FORMAT 0x00000208 +#define NV30_3D_RT_FORMAT_COLOR__MASK 0x0000001f +#define NV30_3D_RT_FORMAT_COLOR__SHIFT 0 +#define NV30_3D_RT_FORMAT_COLOR_R5G6B5 0x00000003 +#define NV30_3D_RT_FORMAT_COLOR_X8R8G8B8 0x00000005 +#define NV30_3D_RT_FORMAT_COLOR_A8R8G8B8 0x00000008 +#define NV30_3D_RT_FORMAT_COLOR_B8 0x00000009 +#define NV30_3D_RT_FORMAT_COLOR_A16B16G16R16_FLOAT 0x0000000b +#define NV30_3D_RT_FORMAT_COLOR_A32B32G32R32_FLOAT 0x0000000c +#define NV30_3D_RT_FORMAT_COLOR_R32_FLOAT 0x0000000d +#define NV30_3D_RT_FORMAT_COLOR_UNK0D 0x0000000d +#define NV30_3D_RT_FORMAT_COLOR_X8B8G8R8 0x0000000f +#define NV30_3D_RT_FORMAT_COLOR_A8B8G8R8 0x00000010 +#define NV30_3D_RT_FORMAT_ZETA__MASK 0x000000e0 +#define NV30_3D_RT_FORMAT_ZETA__SHIFT 5 +#define NV30_3D_RT_FORMAT_ZETA_Z16 0x00000020 +#define NV30_3D_RT_FORMAT_ZETA_Z24S8 0x00000040 +#define NV30_3D_RT_FORMAT_TYPE__MASK 0x00000f00 +#define NV30_3D_RT_FORMAT_TYPE__SHIFT 8 +#define NV30_3D_RT_FORMAT_TYPE_LINEAR 0x00000100 +#define NV30_3D_RT_FORMAT_TYPE_SWIZZLED 0x00000200 +#define NV30_3D_RT_FORMAT_LOG2_WIDTH__MASK 0x00ff0000 +#define NV30_3D_RT_FORMAT_LOG2_WIDTH__SHIFT 16 +#define NV30_3D_RT_FORMAT_LOG2_HEIGHT__MASK 0xff000000 +#define NV30_3D_RT_FORMAT_LOG2_HEIGHT__SHIFT 24 + +#define NV30_3D_COLOR0_PITCH 0x0000020c +#define NV30_3D_COLOR0_PITCH_COLOR0__MASK 0x0000ffff +#define NV30_3D_COLOR0_PITCH_COLOR0__SHIFT 0 +#define NV30_3D_COLOR0_PITCH_ZETA__MASK 0xffff0000 +#define NV30_3D_COLOR0_PITCH_ZETA__SHIFT 16 + +#define NV40_3D_COLOR0_PITCH 0x0000020c + +#define NV30_3D_COLOR0_OFFSET 0x00000210 + +#define NV30_3D_ZETA_OFFSET 0x00000214 + +#define NV30_3D_COLOR1_OFFSET 0x00000218 + +#define NV30_3D_COLOR1_PITCH 0x0000021c + +#define NV30_3D_RT_ENABLE 0x00000220 +#define NV30_3D_RT_ENABLE_COLOR0 0x00000001 +#define NV30_3D_RT_ENABLE_COLOR1 0x00000002 +#define NV40_3D_RT_ENABLE_COLOR2 0x00000004 +#define NV40_3D_RT_ENABLE_COLOR3 0x00000008 +#define NV30_3D_RT_ENABLE_MRT 0x00000010 + +#define NV40_3D_ZETA_PITCH 0x0000022c + +#define NV30_3D_LMA_DEPTH_PITCH 0x0000022c + +#define NV30_3D_LMA_DEPTH_OFFSET 0x00000230 + +#define NV30_3D_TEX_UNITS_ENABLE 0x0000023c +#define NV30_3D_TEX_UNITS_ENABLE_TX0 0x00000001 +#define NV30_3D_TEX_UNITS_ENABLE_TX1 0x00000002 +#define NV30_3D_TEX_UNITS_ENABLE_TX2 0x00000004 +#define NV30_3D_TEX_UNITS_ENABLE_TX3 0x00000008 +#define NV30_3D_TEX_UNITS_ENABLE_TX4 0x00000010 +#define NV30_3D_TEX_UNITS_ENABLE_TX5 0x00000020 +#define NV30_3D_TEX_UNITS_ENABLE_TX6 0x00000040 +#define NV30_3D_TEX_UNITS_ENABLE_TX7 0x00000080 + +#define NV30_3D_TEX_MATRIX_ENABLE(i0) (0x00000240 + 0x4*(i0)) +#define NV30_3D_TEX_MATRIX_ENABLE__ESIZE 0x00000004 +#define NV30_3D_TEX_MATRIX_ENABLE__LEN 0x00000008 + +#define NV40_3D_COLOR2_PITCH 0x00000280 + +#define NV40_3D_COLOR3_PITCH 0x00000284 + +#define NV40_3D_COLOR2_OFFSET 0x00000288 + +#define NV40_3D_COLOR3_OFFSET 0x0000028c + +#define NV30_3D_VIEWPORT_TX_ORIGIN 0x000002b8 +#define NV30_3D_VIEWPORT_TX_ORIGIN_X__MASK 0x0000ffff +#define NV30_3D_VIEWPORT_TX_ORIGIN_X__SHIFT 0 +#define NV30_3D_VIEWPORT_TX_ORIGIN_Y__MASK 0xffff0000 +#define NV30_3D_VIEWPORT_TX_ORIGIN_Y__SHIFT 16 + +#define NV30_3D_VIEWPORT_CLIP_MODE 0x000002bc + +#define NV30_3D_VIEWPORT_CLIP_HORIZ(i0) (0x000002c0 + 0x8*(i0)) +#define NV30_3D_VIEWPORT_CLIP_HORIZ__ESIZE 0x00000008 +#define NV30_3D_VIEWPORT_CLIP_HORIZ__LEN 0x00000008 +#define NV30_3D_VIEWPORT_CLIP_HORIZ_L__MASK 0x0000ffff +#define NV30_3D_VIEWPORT_CLIP_HORIZ_L__SHIFT 0 +#define NV30_3D_VIEWPORT_CLIP_HORIZ_R__MASK 0xffff0000 +#define NV30_3D_VIEWPORT_CLIP_HORIZ_R__SHIFT 16 + +#define NV30_3D_VIEWPORT_CLIP_VERT(i0) (0x000002c4 + 0x8*(i0)) +#define NV30_3D_VIEWPORT_CLIP_VERT__ESIZE 0x00000008 +#define NV30_3D_VIEWPORT_CLIP_VERT__LEN 0x00000008 +#define NV30_3D_VIEWPORT_CLIP_VERT_T__MASK 0x0000ffff +#define NV30_3D_VIEWPORT_CLIP_VERT_T__SHIFT 0 +#define NV30_3D_VIEWPORT_CLIP_VERT_D__MASK 0xffff0000 +#define NV30_3D_VIEWPORT_CLIP_VERT_D__SHIFT 16 + +#define NV30_3D_DITHER_ENABLE 0x00000300 + +#define NV30_3D_ALPHA_FUNC_ENABLE 0x00000304 + +#define NV30_3D_ALPHA_FUNC_FUNC 0x00000308 +#define NV30_3D_ALPHA_FUNC_FUNC_NEVER 0x00000200 +#define NV30_3D_ALPHA_FUNC_FUNC_LESS 0x00000201 +#define NV30_3D_ALPHA_FUNC_FUNC_EQUAL 0x00000202 +#define NV30_3D_ALPHA_FUNC_FUNC_LEQUAL 0x00000203 +#define NV30_3D_ALPHA_FUNC_FUNC_GREATER 0x00000204 +#define NV30_3D_ALPHA_FUNC_FUNC_NOTEQUAL 0x00000205 +#define NV30_3D_ALPHA_FUNC_FUNC_GEQUAL 0x00000206 +#define NV30_3D_ALPHA_FUNC_FUNC_ALWAYS 0x00000207 + +#define NV30_3D_ALPHA_FUNC_REF 0x0000030c + +#define NV30_3D_BLEND_FUNC_ENABLE 0x00000310 + +#define NV30_3D_BLEND_FUNC_SRC 0x00000314 +#define NV30_3D_BLEND_FUNC_SRC_RGB__MASK 0x0000ffff +#define NV30_3D_BLEND_FUNC_SRC_RGB__SHIFT 0 +#define NV30_3D_BLEND_FUNC_SRC_RGB_ZERO 0x00000000 +#define NV30_3D_BLEND_FUNC_SRC_RGB_ONE 0x00000001 +#define NV30_3D_BLEND_FUNC_SRC_RGB_SRC_COLOR 0x00000300 +#define NV30_3D_BLEND_FUNC_SRC_RGB_ONE_MINUS_SRC_COLOR 0x00000301 +#define NV30_3D_BLEND_FUNC_SRC_RGB_SRC_ALPHA 0x00000302 +#define NV30_3D_BLEND_FUNC_SRC_RGB_ONE_MINUS_SRC_ALPHA 0x00000303 +#define NV30_3D_BLEND_FUNC_SRC_RGB_DST_ALPHA 0x00000304 +#define NV30_3D_BLEND_FUNC_SRC_RGB_ONE_MINUS_DST_ALPHA 0x00000305 +#define NV30_3D_BLEND_FUNC_SRC_RGB_DST_COLOR 0x00000306 +#define NV30_3D_BLEND_FUNC_SRC_RGB_ONE_MINUS_DST_COLOR 0x00000307 +#define NV30_3D_BLEND_FUNC_SRC_RGB_SRC_ALPHA_SATURATE 0x00000308 +#define NV30_3D_BLEND_FUNC_SRC_RGB_CONSTANT_COLOR 0x00008001 +#define NV30_3D_BLEND_FUNC_SRC_RGB_ONE_MINUS_CONSTANT_COLOR 0x00008002 +#define NV30_3D_BLEND_FUNC_SRC_RGB_CONSTANT_ALPHA 0x00008003 +#define NV30_3D_BLEND_FUNC_SRC_RGB_ONE_MINUS_CONSTANT_ALPHA 0x00008004 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA__MASK 0xffff0000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA__SHIFT 16 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_ZERO 0x00000000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_ONE 0x00010000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_SRC_COLOR 0x03000000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_ONE_MINUS_SRC_COLOR 0x03010000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_SRC_ALPHA 0x03020000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_ONE_MINUS_SRC_ALPHA 0x03030000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_DST_ALPHA 0x03040000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_ONE_MINUS_DST_ALPHA 0x03050000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_DST_COLOR 0x03060000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_ONE_MINUS_DST_COLOR 0x03070000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_SRC_ALPHA_SATURATE 0x03080000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_CONSTANT_COLOR 0x80010000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_ONE_MINUS_CONSTANT_COLOR 0x80020000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_CONSTANT_ALPHA 0x80030000 +#define NV30_3D_BLEND_FUNC_SRC_ALPHA_ONE_MINUS_CONSTANT_ALPHA 0x80040000 + +#define NV30_3D_BLEND_FUNC_DST 0x00000318 +#define NV30_3D_BLEND_FUNC_DST_RGB__MASK 0x0000ffff +#define NV30_3D_BLEND_FUNC_DST_RGB__SHIFT 0 +#define NV30_3D_BLEND_FUNC_DST_RGB_ZERO 0x00000000 +#define NV30_3D_BLEND_FUNC_DST_RGB_ONE 0x00000001 +#define NV30_3D_BLEND_FUNC_DST_RGB_SRC_COLOR 0x00000300 +#define NV30_3D_BLEND_FUNC_DST_RGB_ONE_MINUS_SRC_COLOR 0x00000301 +#define NV30_3D_BLEND_FUNC_DST_RGB_SRC_ALPHA 0x00000302 +#define NV30_3D_BLEND_FUNC_DST_RGB_ONE_MINUS_SRC_ALPHA 0x00000303 +#define NV30_3D_BLEND_FUNC_DST_RGB_DST_ALPHA 0x00000304 +#define NV30_3D_BLEND_FUNC_DST_RGB_ONE_MINUS_DST_ALPHA 0x00000305 +#define NV30_3D_BLEND_FUNC_DST_RGB_DST_COLOR 0x00000306 +#define NV30_3D_BLEND_FUNC_DST_RGB_ONE_MINUS_DST_COLOR 0x00000307 +#define NV30_3D_BLEND_FUNC_DST_RGB_SRC_ALPHA_SATURATE 0x00000308 +#define NV30_3D_BLEND_FUNC_DST_RGB_CONSTANT_COLOR 0x00008001 +#define NV30_3D_BLEND_FUNC_DST_RGB_ONE_MINUS_CONSTANT_COLOR 0x00008002 +#define NV30_3D_BLEND_FUNC_DST_RGB_CONSTANT_ALPHA 0x00008003 +#define NV30_3D_BLEND_FUNC_DST_RGB_ONE_MINUS_CONSTANT_ALPHA 0x00008004 +#define NV30_3D_BLEND_FUNC_DST_ALPHA__MASK 0xffff0000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA__SHIFT 16 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_ZERO 0x00000000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_ONE 0x00010000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_SRC_COLOR 0x03000000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_ONE_MINUS_SRC_COLOR 0x03010000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_SRC_ALPHA 0x03020000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_ONE_MINUS_SRC_ALPHA 0x03030000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_DST_ALPHA 0x03040000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_ONE_MINUS_DST_ALPHA 0x03050000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_DST_COLOR 0x03060000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_ONE_MINUS_DST_COLOR 0x03070000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_SRC_ALPHA_SATURATE 0x03080000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_CONSTANT_COLOR 0x80010000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_ONE_MINUS_CONSTANT_COLOR 0x80020000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_CONSTANT_ALPHA 0x80030000 +#define NV30_3D_BLEND_FUNC_DST_ALPHA_ONE_MINUS_CONSTANT_ALPHA 0x80040000 + +#define NV30_3D_BLEND_COLOR 0x0000031c +#define NV30_3D_BLEND_COLOR_B__MASK 0x000000ff +#define NV30_3D_BLEND_COLOR_B__SHIFT 0 +#define NV30_3D_BLEND_COLOR_G__MASK 0x0000ff00 +#define NV30_3D_BLEND_COLOR_G__SHIFT 8 +#define NV30_3D_BLEND_COLOR_R__MASK 0x00ff0000 +#define NV30_3D_BLEND_COLOR_R__SHIFT 16 +#define NV30_3D_BLEND_COLOR_A__MASK 0xff000000 +#define NV30_3D_BLEND_COLOR_A__SHIFT 24 + +#define NV30_3D_BLEND_EQUATION 0x00000320 +#define NV30_3D_BLEND_EQUATION_FUNC_ADD 0x00008006 +#define NV30_3D_BLEND_EQUATION_MIN 0x00008007 +#define NV30_3D_BLEND_EQUATION_MAX 0x00008008 +#define NV30_3D_BLEND_EQUATION_FUNC_SUBTRACT 0x0000800a +#define NV30_3D_BLEND_EQUATION_FUNC_REVERSE_SUBTRACT 0x0000800b + +#define NV40_3D_BLEND_EQUATION 0x00000320 +#define NV40_3D_BLEND_EQUATION_RGB__MASK 0x0000ffff +#define NV40_3D_BLEND_EQUATION_RGB__SHIFT 0 +#define NV40_3D_BLEND_EQUATION_RGB_FUNC_ADD 0x00008006 +#define NV40_3D_BLEND_EQUATION_RGB_MIN 0x00008007 +#define NV40_3D_BLEND_EQUATION_RGB_MAX 0x00008008 +#define NV40_3D_BLEND_EQUATION_RGB_FUNC_SUBTRACT 0x0000800a +#define NV40_3D_BLEND_EQUATION_RGB_FUNC_REVERSE_SUBTRACT 0x0000800b +#define NV40_3D_BLEND_EQUATION_ALPHA__MASK 0xffff0000 +#define NV40_3D_BLEND_EQUATION_ALPHA__SHIFT 16 +#define NV40_3D_BLEND_EQUATION_ALPHA_FUNC_ADD 0x80060000 +#define NV40_3D_BLEND_EQUATION_ALPHA_MIN 0x80070000 +#define NV40_3D_BLEND_EQUATION_ALPHA_MAX 0x80080000 +#define NV40_3D_BLEND_EQUATION_ALPHA_FUNC_SUBTRACT 0x800a0000 +#define NV40_3D_BLEND_EQUATION_ALPHA_FUNC_REVERSE_SUBTRACT 0x800b0000 + +#define NV30_3D_COLOR_MASK 0x00000324 +#define NV30_3D_COLOR_MASK_B 0x000000ff +#define NV30_3D_COLOR_MASK_G 0x0000ff00 +#define NV30_3D_COLOR_MASK_R 0x00ff0000 +#define NV30_3D_COLOR_MASK_A 0xff000000 + +#define NV30_3D_STENCIL(i0) (0x00000328 + 0x20*(i0)) +#define NV30_3D_STENCIL__ESIZE 0x00000020 +#define NV30_3D_STENCIL__LEN 0x00000002 + +#define NV30_3D_STENCIL_ENABLE(i0) (0x00000328 + 0x20*(i0)) + +#define NV30_3D_STENCIL_MASK(i0) (0x0000032c + 0x20*(i0)) + +#define NV30_3D_STENCIL_FUNC_FUNC(i0) (0x00000330 + 0x20*(i0)) +#define NV30_3D_STENCIL_FUNC_FUNC_NEVER 0x00000200 +#define NV30_3D_STENCIL_FUNC_FUNC_LESS 0x00000201 +#define NV30_3D_STENCIL_FUNC_FUNC_EQUAL 0x00000202 +#define NV30_3D_STENCIL_FUNC_FUNC_LEQUAL 0x00000203 +#define NV30_3D_STENCIL_FUNC_FUNC_GREATER 0x00000204 +#define NV30_3D_STENCIL_FUNC_FUNC_NOTEQUAL 0x00000205 +#define NV30_3D_STENCIL_FUNC_FUNC_GEQUAL 0x00000206 +#define NV30_3D_STENCIL_FUNC_FUNC_ALWAYS 0x00000207 + +#define NV30_3D_STENCIL_FUNC_REF(i0) (0x00000334 + 0x20*(i0)) + +#define NV30_3D_STENCIL_FUNC_MASK(i0) (0x00000338 + 0x20*(i0)) + +#define NV30_3D_STENCIL_OP_FAIL(i0) (0x0000033c + 0x20*(i0)) +#define NV30_3D_STENCIL_OP_FAIL_ZERO 0x00000000 +#define NV30_3D_STENCIL_OP_FAIL_INVERT 0x0000150a +#define NV30_3D_STENCIL_OP_FAIL_KEEP 0x00001e00 +#define NV30_3D_STENCIL_OP_FAIL_REPLACE 0x00001e01 +#define NV30_3D_STENCIL_OP_FAIL_INCR 0x00001e02 +#define NV30_3D_STENCIL_OP_FAIL_DECR 0x00001e03 +#define NV30_3D_STENCIL_OP_FAIL_INCR_WRAP 0x00008507 +#define NV30_3D_STENCIL_OP_FAIL_DECR_WRAP 0x00008508 + +#define NV30_3D_STENCIL_OP_ZFAIL(i0) (0x00000340 + 0x20*(i0)) +#define NV30_3D_STENCIL_OP_ZFAIL_ZERO 0x00000000 +#define NV30_3D_STENCIL_OP_ZFAIL_INVERT 0x0000150a +#define NV30_3D_STENCIL_OP_ZFAIL_KEEP 0x00001e00 +#define NV30_3D_STENCIL_OP_ZFAIL_REPLACE 0x00001e01 +#define NV30_3D_STENCIL_OP_ZFAIL_INCR 0x00001e02 +#define NV30_3D_STENCIL_OP_ZFAIL_DECR 0x00001e03 +#define NV30_3D_STENCIL_OP_ZFAIL_INCR_WRAP 0x00008507 +#define NV30_3D_STENCIL_OP_ZFAIL_DECR_WRAP 0x00008508 + +#define NV30_3D_STENCIL_OP_ZPASS(i0) (0x00000344 + 0x20*(i0)) +#define NV30_3D_STENCIL_OP_ZPASS_ZERO 0x00000000 +#define NV30_3D_STENCIL_OP_ZPASS_INVERT 0x0000150a +#define NV30_3D_STENCIL_OP_ZPASS_KEEP 0x00001e00 +#define NV30_3D_STENCIL_OP_ZPASS_REPLACE 0x00001e01 +#define NV30_3D_STENCIL_OP_ZPASS_INCR 0x00001e02 +#define NV30_3D_STENCIL_OP_ZPASS_DECR 0x00001e03 +#define NV30_3D_STENCIL_OP_ZPASS_INCR_WRAP 0x00008507 +#define NV30_3D_STENCIL_OP_ZPASS_DECR_WRAP 0x00008508 + +#define NV30_3D_SHADE_MODEL 0x00000368 +#define NV30_3D_SHADE_MODEL_FLAT 0x00001d00 +#define NV30_3D_SHADE_MODEL_SMOOTH 0x00001d01 + +#define NV30_3D_FOG_ENABLE 0x0000036c + +#define NV30_3D_FOG_COLOR 0x00000370 +#define NV30_3D_FOG_COLOR_R__MASK 0x000000ff +#define NV30_3D_FOG_COLOR_R__SHIFT 0 +#define NV30_3D_FOG_COLOR_G__MASK 0x0000ff00 +#define NV30_3D_FOG_COLOR_G__SHIFT 8 +#define NV30_3D_FOG_COLOR_B__MASK 0x00ff0000 +#define NV30_3D_FOG_COLOR_B__SHIFT 16 +#define NV30_3D_FOG_COLOR_A__MASK 0xff000000 +#define NV30_3D_FOG_COLOR_A__SHIFT 24 + +#define NV40_3D_MRT_COLOR_MASK 0x00000370 +#define NV40_3D_MRT_COLOR_MASK_BUFFER1_A 0x00000010 +#define NV40_3D_MRT_COLOR_MASK_BUFFER1_R 0x00000020 +#define NV40_3D_MRT_COLOR_MASK_BUFFER1_G 0x00000040 +#define NV40_3D_MRT_COLOR_MASK_BUFFER1_B 0x00000080 +#define NV40_3D_MRT_COLOR_MASK_BUFFER2_A 0x00000100 +#define NV40_3D_MRT_COLOR_MASK_BUFFER2_R 0x00000200 +#define NV40_3D_MRT_COLOR_MASK_BUFFER2_G 0x00000400 +#define NV40_3D_MRT_COLOR_MASK_BUFFER2_B 0x00000800 +#define NV40_3D_MRT_COLOR_MASK_BUFFER3_A 0x00001000 +#define NV40_3D_MRT_COLOR_MASK_BUFFER3_R 0x00002000 +#define NV40_3D_MRT_COLOR_MASK_BUFFER3_G 0x00004000 +#define NV40_3D_MRT_COLOR_MASK_BUFFER3_B 0x00008000 + +#define NV30_3D_COLOR_LOGIC_OP_ENABLE 0x00000374 + +#define NV30_3D_COLOR_LOGIC_OP_OP 0x00000378 +#define NV30_3D_COLOR_LOGIC_OP_OP_CLEAR 0x00001500 +#define NV30_3D_COLOR_LOGIC_OP_OP_AND 0x00001501 +#define NV30_3D_COLOR_LOGIC_OP_OP_AND_REVERSE 0x00001502 +#define NV30_3D_COLOR_LOGIC_OP_OP_COPY 0x00001503 +#define NV30_3D_COLOR_LOGIC_OP_OP_AND_INVERTED 0x00001504 +#define NV30_3D_COLOR_LOGIC_OP_OP_NOOP 0x00001505 +#define NV30_3D_COLOR_LOGIC_OP_OP_XOR 0x00001506 +#define NV30_3D_COLOR_LOGIC_OP_OP_OR 0x00001507 +#define NV30_3D_COLOR_LOGIC_OP_OP_NOR 0x00001508 +#define NV30_3D_COLOR_LOGIC_OP_OP_EQUIV 0x00001509 +#define NV30_3D_COLOR_LOGIC_OP_OP_INVERT 0x0000150a +#define NV30_3D_COLOR_LOGIC_OP_OP_OR_REVERSE 0x0000150b +#define NV30_3D_COLOR_LOGIC_OP_OP_COPY_INVERTED 0x0000150c +#define NV30_3D_COLOR_LOGIC_OP_OP_OR_INVERTED 0x0000150d +#define NV30_3D_COLOR_LOGIC_OP_OP_NAND 0x0000150e +#define NV30_3D_COLOR_LOGIC_OP_OP_SET 0x0000150f + +#define NV30_3D_NORMALIZE_ENABLE 0x0000037c + +#define NV30_3D_COLOR_MATERIAL 0x00000390 +#define NV30_3D_COLOR_MATERIAL_FRONT_EMISSION_ENABLE 0x00000001 +#define NV30_3D_COLOR_MATERIAL_FRONT_AMBIENT_ENABLE 0x00000004 +#define NV30_3D_COLOR_MATERIAL_FRONT_DIFFUSE_ENABLE 0x00000010 +#define NV30_3D_COLOR_MATERIAL_FRONT_SPECULAR_ENABLE 0x00000040 +#define NV30_3D_COLOR_MATERIAL_BACK_EMISSION_ENABLE 0x00000100 +#define NV30_3D_COLOR_MATERIAL_BACK_AMBIENT_ENABLE 0x00000400 +#define NV30_3D_COLOR_MATERIAL_BACK_DIFFUSE_ENABLE 0x00001000 +#define NV30_3D_COLOR_MATERIAL_BACK_SPECULAR_ENABLE 0x00004000 + +#define NV30_3D_DEPTH_RANGE_NEAR 0x00000394 + +#define NV30_3D_DEPTH_RANGE_FAR 0x00000398 + +#define NV30_3D_COLOR_MATERIAL_FRONT 0x000003a0 + + +#define NV30_3D_COLOR_MATERIAL_FRONT_R 0x000003a0 + +#define NV30_3D_COLOR_MATERIAL_FRONT_G 0x000003a4 + +#define NV30_3D_COLOR_MATERIAL_FRONT_B 0x000003a8 + +#define NV30_3D_COLOR_MATERIAL_FRONT_A 0x000003ac + +#define NV40_3D_MIPMAP_ROUNDING 0x000003b0 +#define NV40_3D_MIPMAP_ROUNDING_MODE__MASK 0x00100000 +#define NV40_3D_MIPMAP_ROUNDING_MODE__SHIFT 20 +#define NV40_3D_MIPMAP_ROUNDING_MODE_UP 0x00000000 +#define NV40_3D_MIPMAP_ROUNDING_MODE_DOWN 0x00100000 + +#define NV30_3D_LINE_WIDTH 0x000003b8 + +#define NV30_3D_LINE_SMOOTH_ENABLE 0x000003bc + + + +#define NV30_3D_TEX_GEN_MODE(i0, i1) (0x00000400 + 0x10*(i0) + 0x4*(i1)) +#define NV30_3D_TEX_GEN_MODE__ESIZE 0x00000004 +#define NV30_3D_TEX_GEN_MODE__LEN 0x00000004 +#define NV30_3D_TEX_GEN_MODE_FALSE 0x00000000 +#define NV30_3D_TEX_GEN_MODE_EYE_LINEAR 0x00002400 +#define NV30_3D_TEX_GEN_MODE_OBJECT_LINEAR 0x00002401 +#define NV30_3D_TEX_GEN_MODE_SPHERE_MAP 0x00002402 +#define NV30_3D_TEX_GEN_MODE_NORMAL_MAP 0x00008511 +#define NV30_3D_TEX_GEN_MODE_REFLECTION_MAP 0x00008512 + +#define NV30_3D_MODELVIEW_MATRIX(i0) (0x00000480 + 0x4*(i0)) +#define NV30_3D_MODELVIEW_MATRIX__ESIZE 0x00000004 +#define NV30_3D_MODELVIEW_MATRIX__LEN 0x00000010 + +#define NV30_3D_INVERSE_MODELVIEW_MATRIX(i0) (0x00000580 + 0x4*(i0)) +#define NV30_3D_INVERSE_MODELVIEW_MATRIX__ESIZE 0x00000004 +#define NV30_3D_INVERSE_MODELVIEW_MATRIX__LEN 0x0000000c + +#define NV30_3D_PROJECTION_MATRIX(i0) (0x00000680 + 0x4*(i0)) +#define NV30_3D_PROJECTION_MATRIX__ESIZE 0x00000004 +#define NV30_3D_PROJECTION_MATRIX__LEN 0x00000010 + + +#define NV30_3D_TEX_MATRIX(i0, i1) (0x000006c0 + 0x40*(i0) + 0x4*(i1)) +#define NV30_3D_TEX_MATRIX__ESIZE 0x00000004 +#define NV30_3D_TEX_MATRIX__LEN 0x00000010 + +#define NV30_3D_SCISSOR_HORIZ 0x000008c0 +#define NV30_3D_SCISSOR_HORIZ_X__MASK 0x0000ffff +#define NV30_3D_SCISSOR_HORIZ_X__SHIFT 0 +#define NV30_3D_SCISSOR_HORIZ_W__MASK 0xffff0000 +#define NV30_3D_SCISSOR_HORIZ_W__SHIFT 16 + +#define NV30_3D_SCISSOR_VERT 0x000008c4 +#define NV30_3D_SCISSOR_VERT_Y__MASK 0x0000ffff +#define NV30_3D_SCISSOR_VERT_Y__SHIFT 0 +#define NV30_3D_SCISSOR_VERT_H__MASK 0xffff0000 +#define NV30_3D_SCISSOR_VERT_H__SHIFT 16 + +#define NV30_3D_FOG_COORD_DIST 0x000008c8 + +#define NV30_3D_FOG_MODE 0x000008cc + +#define NV30_3D_FOG_EQUATION_CONSTANT 0x000008d0 + +#define NV30_3D_FOG_EQUATION_LINEAR 0x000008d4 + +#define NV30_3D_FOG_EQUATION_QUADRATIC 0x000008d8 + +#define NV30_3D_FP_ACTIVE_PROGRAM 0x000008e4 +#define NV30_3D_FP_ACTIVE_PROGRAM_DMA0 0x00000001 +#define NV30_3D_FP_ACTIVE_PROGRAM_DMA1 0x00000002 +#define NV30_3D_FP_ACTIVE_PROGRAM_OFFSET__MASK 0xfffffffc +#define NV30_3D_FP_ACTIVE_PROGRAM_OFFSET__SHIFT 2 + + +#define NV30_3D_RC_COLOR0 0x000008ec +#define NV30_3D_RC_COLOR0_B__MASK 0x000000ff +#define NV30_3D_RC_COLOR0_B__SHIFT 0 +#define NV30_3D_RC_COLOR0_G__MASK 0x0000ff00 +#define NV30_3D_RC_COLOR0_G__SHIFT 8 +#define NV30_3D_RC_COLOR0_R__MASK 0x00ff0000 +#define NV30_3D_RC_COLOR0_R__SHIFT 16 +#define NV30_3D_RC_COLOR0_A__MASK 0xff000000 +#define NV30_3D_RC_COLOR0_A__SHIFT 24 + +#define NV30_3D_RC_COLOR1 0x000008f0 +#define NV30_3D_RC_COLOR1_B__MASK 0x000000ff +#define NV30_3D_RC_COLOR1_B__SHIFT 0 +#define NV30_3D_RC_COLOR1_G__MASK 0x0000ff00 +#define NV30_3D_RC_COLOR1_G__SHIFT 8 +#define NV30_3D_RC_COLOR1_R__MASK 0x00ff0000 +#define NV30_3D_RC_COLOR1_R__SHIFT 16 +#define NV30_3D_RC_COLOR1_A__MASK 0xff000000 +#define NV30_3D_RC_COLOR1_A__SHIFT 24 + +#define NV30_3D_RC_FINAL0 0x000008f4 +#define NV30_3D_RC_FINAL0_D_INPUT__MASK 0x0000000f +#define NV30_3D_RC_FINAL0_D_INPUT__SHIFT 0 +#define NV30_3D_RC_FINAL0_D_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_FINAL0_D_INPUT_CONSTANT_COLOR0 0x00000001 +#define NV30_3D_RC_FINAL0_D_INPUT_CONSTANT_COLOR1 0x00000002 +#define NV30_3D_RC_FINAL0_D_INPUT_FOG 0x00000003 +#define NV30_3D_RC_FINAL0_D_INPUT_PRIMARY_COLOR 0x00000004 +#define NV30_3D_RC_FINAL0_D_INPUT_SECONDARY_COLOR 0x00000005 +#define NV30_3D_RC_FINAL0_D_INPUT_TEXTURE0 0x00000008 +#define NV30_3D_RC_FINAL0_D_INPUT_TEXTURE1 0x00000009 +#define NV30_3D_RC_FINAL0_D_INPUT_TEXTURE2 0x0000000a +#define NV30_3D_RC_FINAL0_D_INPUT_TEXTURE3 0x0000000b +#define NV30_3D_RC_FINAL0_D_INPUT_SPARE0 0x0000000c +#define NV30_3D_RC_FINAL0_D_INPUT_SPARE1 0x0000000d +#define NV30_3D_RC_FINAL0_D_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x0000000e +#define NV30_3D_RC_FINAL0_D_INPUT_E_TIMES_F 0x0000000f +#define NV30_3D_RC_FINAL0_D_COMPONENT_USAGE__MASK 0x00000010 +#define NV30_3D_RC_FINAL0_D_COMPONENT_USAGE__SHIFT 4 +#define NV30_3D_RC_FINAL0_D_COMPONENT_USAGE_RGB 0x00000000 +#define NV30_3D_RC_FINAL0_D_COMPONENT_USAGE_ALPHA 0x00000010 +#define NV30_3D_RC_FINAL0_D_MAPPING__MASK 0x000000e0 +#define NV30_3D_RC_FINAL0_D_MAPPING__SHIFT 5 +#define NV30_3D_RC_FINAL0_D_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_FINAL0_D_MAPPING_UNSIGNED_INVERT 0x00000020 +#define NV30_3D_RC_FINAL0_D_MAPPING_EXPAND_NORMAL 0x00000040 +#define NV30_3D_RC_FINAL0_D_MAPPING_EXPAND_NEGATE 0x00000060 +#define NV30_3D_RC_FINAL0_D_MAPPING_HALF_BIAS_NORMAL 0x00000080 +#define NV30_3D_RC_FINAL0_D_MAPPING_HALF_BIAS_NEGATE 0x000000a0 +#define NV30_3D_RC_FINAL0_D_MAPPING_SIGNED_IDENTITY 0x000000c0 +#define NV30_3D_RC_FINAL0_D_MAPPING_SIGNED_NEGATE 0x000000e0 +#define NV30_3D_RC_FINAL0_C_INPUT__MASK 0x00000f00 +#define NV30_3D_RC_FINAL0_C_INPUT__SHIFT 8 +#define NV30_3D_RC_FINAL0_C_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_FINAL0_C_INPUT_CONSTANT_COLOR0 0x00000100 +#define NV30_3D_RC_FINAL0_C_INPUT_CONSTANT_COLOR1 0x00000200 +#define NV30_3D_RC_FINAL0_C_INPUT_FOG 0x00000300 +#define NV30_3D_RC_FINAL0_C_INPUT_PRIMARY_COLOR 0x00000400 +#define NV30_3D_RC_FINAL0_C_INPUT_SECONDARY_COLOR 0x00000500 +#define NV30_3D_RC_FINAL0_C_INPUT_TEXTURE0 0x00000800 +#define NV30_3D_RC_FINAL0_C_INPUT_TEXTURE1 0x00000900 +#define NV30_3D_RC_FINAL0_C_INPUT_TEXTURE2 0x00000a00 +#define NV30_3D_RC_FINAL0_C_INPUT_TEXTURE3 0x00000b00 +#define NV30_3D_RC_FINAL0_C_INPUT_SPARE0 0x00000c00 +#define NV30_3D_RC_FINAL0_C_INPUT_SPARE1 0x00000d00 +#define NV30_3D_RC_FINAL0_C_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x00000e00 +#define NV30_3D_RC_FINAL0_C_INPUT_E_TIMES_F 0x00000f00 +#define NV30_3D_RC_FINAL0_C_COMPONENT_USAGE__MASK 0x00001000 +#define NV30_3D_RC_FINAL0_C_COMPONENT_USAGE__SHIFT 12 +#define NV30_3D_RC_FINAL0_C_COMPONENT_USAGE_RGB 0x00000000 +#define NV30_3D_RC_FINAL0_C_COMPONENT_USAGE_ALPHA 0x00001000 +#define NV30_3D_RC_FINAL0_C_MAPPING__MASK 0x0000e000 +#define NV30_3D_RC_FINAL0_C_MAPPING__SHIFT 13 +#define NV30_3D_RC_FINAL0_C_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_FINAL0_C_MAPPING_UNSIGNED_INVERT 0x00002000 +#define NV30_3D_RC_FINAL0_C_MAPPING_EXPAND_NORMAL 0x00004000 +#define NV30_3D_RC_FINAL0_C_MAPPING_EXPAND_NEGATE 0x00006000 +#define NV30_3D_RC_FINAL0_C_MAPPING_HALF_BIAS_NORMAL 0x00008000 +#define NV30_3D_RC_FINAL0_C_MAPPING_HALF_BIAS_NEGATE 0x0000a000 +#define NV30_3D_RC_FINAL0_C_MAPPING_SIGNED_IDENTITY 0x0000c000 +#define NV30_3D_RC_FINAL0_C_MAPPING_SIGNED_NEGATE 0x0000e000 +#define NV30_3D_RC_FINAL0_B_INPUT__MASK 0x000f0000 +#define NV30_3D_RC_FINAL0_B_INPUT__SHIFT 16 +#define NV30_3D_RC_FINAL0_B_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_FINAL0_B_INPUT_CONSTANT_COLOR0 0x00010000 +#define NV30_3D_RC_FINAL0_B_INPUT_CONSTANT_COLOR1 0x00020000 +#define NV30_3D_RC_FINAL0_B_INPUT_FOG 0x00030000 +#define NV30_3D_RC_FINAL0_B_INPUT_PRIMARY_COLOR 0x00040000 +#define NV30_3D_RC_FINAL0_B_INPUT_SECONDARY_COLOR 0x00050000 +#define NV30_3D_RC_FINAL0_B_INPUT_TEXTURE0 0x00080000 +#define NV30_3D_RC_FINAL0_B_INPUT_TEXTURE1 0x00090000 +#define NV30_3D_RC_FINAL0_B_INPUT_TEXTURE2 0x000a0000 +#define NV30_3D_RC_FINAL0_B_INPUT_TEXTURE3 0x000b0000 +#define NV30_3D_RC_FINAL0_B_INPUT_SPARE0 0x000c0000 +#define NV30_3D_RC_FINAL0_B_INPUT_SPARE1 0x000d0000 +#define NV30_3D_RC_FINAL0_B_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x000e0000 +#define NV30_3D_RC_FINAL0_B_INPUT_E_TIMES_F 0x000f0000 +#define NV30_3D_RC_FINAL0_B_COMPONENT_USAGE__MASK 0x00100000 +#define NV30_3D_RC_FINAL0_B_COMPONENT_USAGE__SHIFT 20 +#define NV30_3D_RC_FINAL0_B_COMPONENT_USAGE_RGB 0x00000000 +#define NV30_3D_RC_FINAL0_B_COMPONENT_USAGE_ALPHA 0x00100000 +#define NV30_3D_RC_FINAL0_B_MAPPING__MASK 0x00e00000 +#define NV30_3D_RC_FINAL0_B_MAPPING__SHIFT 21 +#define NV30_3D_RC_FINAL0_B_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_FINAL0_B_MAPPING_UNSIGNED_INVERT 0x00200000 +#define NV30_3D_RC_FINAL0_B_MAPPING_EXPAND_NORMAL 0x00400000 +#define NV30_3D_RC_FINAL0_B_MAPPING_EXPAND_NEGATE 0x00600000 +#define NV30_3D_RC_FINAL0_B_MAPPING_HALF_BIAS_NORMAL 0x00800000 +#define NV30_3D_RC_FINAL0_B_MAPPING_HALF_BIAS_NEGATE 0x00a00000 +#define NV30_3D_RC_FINAL0_B_MAPPING_SIGNED_IDENTITY 0x00c00000 +#define NV30_3D_RC_FINAL0_B_MAPPING_SIGNED_NEGATE 0x00e00000 +#define NV30_3D_RC_FINAL0_A_INPUT__MASK 0x0f000000 +#define NV30_3D_RC_FINAL0_A_INPUT__SHIFT 24 +#define NV30_3D_RC_FINAL0_A_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_FINAL0_A_INPUT_CONSTANT_COLOR0 0x01000000 +#define NV30_3D_RC_FINAL0_A_INPUT_CONSTANT_COLOR1 0x02000000 +#define NV30_3D_RC_FINAL0_A_INPUT_FOG 0x03000000 +#define NV30_3D_RC_FINAL0_A_INPUT_PRIMARY_COLOR 0x04000000 +#define NV30_3D_RC_FINAL0_A_INPUT_SECONDARY_COLOR 0x05000000 +#define NV30_3D_RC_FINAL0_A_INPUT_TEXTURE0 0x08000000 +#define NV30_3D_RC_FINAL0_A_INPUT_TEXTURE1 0x09000000 +#define NV30_3D_RC_FINAL0_A_INPUT_TEXTURE2 0x0a000000 +#define NV30_3D_RC_FINAL0_A_INPUT_TEXTURE3 0x0b000000 +#define NV30_3D_RC_FINAL0_A_INPUT_SPARE0 0x0c000000 +#define NV30_3D_RC_FINAL0_A_INPUT_SPARE1 0x0d000000 +#define NV30_3D_RC_FINAL0_A_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x0e000000 +#define NV30_3D_RC_FINAL0_A_INPUT_E_TIMES_F 0x0f000000 +#define NV30_3D_RC_FINAL0_A_COMPONENT_USAGE__MASK 0x10000000 +#define NV30_3D_RC_FINAL0_A_COMPONENT_USAGE__SHIFT 28 +#define NV30_3D_RC_FINAL0_A_COMPONENT_USAGE_RGB 0x00000000 +#define NV30_3D_RC_FINAL0_A_COMPONENT_USAGE_ALPHA 0x10000000 +#define NV30_3D_RC_FINAL0_A_MAPPING__MASK 0xe0000000 +#define NV30_3D_RC_FINAL0_A_MAPPING__SHIFT 29 +#define NV30_3D_RC_FINAL0_A_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_FINAL0_A_MAPPING_UNSIGNED_INVERT 0x20000000 +#define NV30_3D_RC_FINAL0_A_MAPPING_EXPAND_NORMAL 0x40000000 +#define NV30_3D_RC_FINAL0_A_MAPPING_EXPAND_NEGATE 0x60000000 +#define NV30_3D_RC_FINAL0_A_MAPPING_HALF_BIAS_NORMAL 0x80000000 +#define NV30_3D_RC_FINAL0_A_MAPPING_HALF_BIAS_NEGATE 0xa0000000 +#define NV30_3D_RC_FINAL0_A_MAPPING_SIGNED_IDENTITY 0xc0000000 +#define NV30_3D_RC_FINAL0_A_MAPPING_SIGNED_NEGATE 0xe0000000 + +#define NV30_3D_RC_FINAL1 0x000008f8 +#define NV30_3D_RC_FINAL1_COLOR_SUM_CLAMP 0x00000080 +#define NV30_3D_RC_FINAL1_G_INPUT__MASK 0x00000f00 +#define NV30_3D_RC_FINAL1_G_INPUT__SHIFT 8 +#define NV30_3D_RC_FINAL1_G_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_FINAL1_G_INPUT_CONSTANT_COLOR0 0x00000100 +#define NV30_3D_RC_FINAL1_G_INPUT_CONSTANT_COLOR1 0x00000200 +#define NV30_3D_RC_FINAL1_G_INPUT_FOG 0x00000300 +#define NV30_3D_RC_FINAL1_G_INPUT_PRIMARY_COLOR 0x00000400 +#define NV30_3D_RC_FINAL1_G_INPUT_SECONDARY_COLOR 0x00000500 +#define NV30_3D_RC_FINAL1_G_INPUT_TEXTURE0 0x00000800 +#define NV30_3D_RC_FINAL1_G_INPUT_TEXTURE1 0x00000900 +#define NV30_3D_RC_FINAL1_G_INPUT_TEXTURE2 0x00000a00 +#define NV30_3D_RC_FINAL1_G_INPUT_TEXTURE3 0x00000b00 +#define NV30_3D_RC_FINAL1_G_INPUT_SPARE0 0x00000c00 +#define NV30_3D_RC_FINAL1_G_INPUT_SPARE1 0x00000d00 +#define NV30_3D_RC_FINAL1_G_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x00000e00 +#define NV30_3D_RC_FINAL1_G_INPUT_E_TIMES_F 0x00000f00 +#define NV30_3D_RC_FINAL1_G_COMPONENT_USAGE__MASK 0x00001000 +#define NV30_3D_RC_FINAL1_G_COMPONENT_USAGE__SHIFT 12 +#define NV30_3D_RC_FINAL1_G_COMPONENT_USAGE_RGB 0x00000000 +#define NV30_3D_RC_FINAL1_G_COMPONENT_USAGE_ALPHA 0x00001000 +#define NV30_3D_RC_FINAL1_G_MAPPING__MASK 0x0000e000 +#define NV30_3D_RC_FINAL1_G_MAPPING__SHIFT 13 +#define NV30_3D_RC_FINAL1_G_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_FINAL1_G_MAPPING_UNSIGNED_INVERT 0x00002000 +#define NV30_3D_RC_FINAL1_G_MAPPING_EXPAND_NORMAL 0x00004000 +#define NV30_3D_RC_FINAL1_G_MAPPING_EXPAND_NEGATE 0x00006000 +#define NV30_3D_RC_FINAL1_G_MAPPING_HALF_BIAS_NORMAL 0x00008000 +#define NV30_3D_RC_FINAL1_G_MAPPING_HALF_BIAS_NEGATE 0x0000a000 +#define NV30_3D_RC_FINAL1_G_MAPPING_SIGNED_IDENTITY 0x0000c000 +#define NV30_3D_RC_FINAL1_G_MAPPING_SIGNED_NEGATE 0x0000e000 +#define NV30_3D_RC_FINAL1_F_INPUT__MASK 0x000f0000 +#define NV30_3D_RC_FINAL1_F_INPUT__SHIFT 16 +#define NV30_3D_RC_FINAL1_F_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_FINAL1_F_INPUT_CONSTANT_COLOR0 0x00010000 +#define NV30_3D_RC_FINAL1_F_INPUT_CONSTANT_COLOR1 0x00020000 +#define NV30_3D_RC_FINAL1_F_INPUT_FOG 0x00030000 +#define NV30_3D_RC_FINAL1_F_INPUT_PRIMARY_COLOR 0x00040000 +#define NV30_3D_RC_FINAL1_F_INPUT_SECONDARY_COLOR 0x00050000 +#define NV30_3D_RC_FINAL1_F_INPUT_TEXTURE0 0x00080000 +#define NV30_3D_RC_FINAL1_F_INPUT_TEXTURE1 0x00090000 +#define NV30_3D_RC_FINAL1_F_INPUT_TEXTURE2 0x000a0000 +#define NV30_3D_RC_FINAL1_F_INPUT_TEXTURE3 0x000b0000 +#define NV30_3D_RC_FINAL1_F_INPUT_SPARE0 0x000c0000 +#define NV30_3D_RC_FINAL1_F_INPUT_SPARE1 0x000d0000 +#define NV30_3D_RC_FINAL1_F_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x000e0000 +#define NV30_3D_RC_FINAL1_F_INPUT_E_TIMES_F 0x000f0000 +#define NV30_3D_RC_FINAL1_F_COMPONENT_USAGE__MASK 0x00100000 +#define NV30_3D_RC_FINAL1_F_COMPONENT_USAGE__SHIFT 20 +#define NV30_3D_RC_FINAL1_F_COMPONENT_USAGE_RGB 0x00000000 +#define NV30_3D_RC_FINAL1_F_COMPONENT_USAGE_ALPHA 0x00100000 +#define NV30_3D_RC_FINAL1_F_MAPPING__MASK 0x00e00000 +#define NV30_3D_RC_FINAL1_F_MAPPING__SHIFT 21 +#define NV30_3D_RC_FINAL1_F_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_FINAL1_F_MAPPING_UNSIGNED_INVERT 0x00200000 +#define NV30_3D_RC_FINAL1_F_MAPPING_EXPAND_NORMAL 0x00400000 +#define NV30_3D_RC_FINAL1_F_MAPPING_EXPAND_NEGATE 0x00600000 +#define NV30_3D_RC_FINAL1_F_MAPPING_HALF_BIAS_NORMAL 0x00800000 +#define NV30_3D_RC_FINAL1_F_MAPPING_HALF_BIAS_NEGATE 0x00a00000 +#define NV30_3D_RC_FINAL1_F_MAPPING_SIGNED_IDENTITY 0x00c00000 +#define NV30_3D_RC_FINAL1_F_MAPPING_SIGNED_NEGATE 0x00e00000 +#define NV30_3D_RC_FINAL1_E_INPUT__MASK 0x0f000000 +#define NV30_3D_RC_FINAL1_E_INPUT__SHIFT 24 +#define NV30_3D_RC_FINAL1_E_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_FINAL1_E_INPUT_CONSTANT_COLOR0 0x01000000 +#define NV30_3D_RC_FINAL1_E_INPUT_CONSTANT_COLOR1 0x02000000 +#define NV30_3D_RC_FINAL1_E_INPUT_FOG 0x03000000 +#define NV30_3D_RC_FINAL1_E_INPUT_PRIMARY_COLOR 0x04000000 +#define NV30_3D_RC_FINAL1_E_INPUT_SECONDARY_COLOR 0x05000000 +#define NV30_3D_RC_FINAL1_E_INPUT_TEXTURE0 0x08000000 +#define NV30_3D_RC_FINAL1_E_INPUT_TEXTURE1 0x09000000 +#define NV30_3D_RC_FINAL1_E_INPUT_TEXTURE2 0x0a000000 +#define NV30_3D_RC_FINAL1_E_INPUT_TEXTURE3 0x0b000000 +#define NV30_3D_RC_FINAL1_E_INPUT_SPARE0 0x0c000000 +#define NV30_3D_RC_FINAL1_E_INPUT_SPARE1 0x0d000000 +#define NV30_3D_RC_FINAL1_E_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x0e000000 +#define NV30_3D_RC_FINAL1_E_INPUT_E_TIMES_F 0x0f000000 +#define NV30_3D_RC_FINAL1_E_COMPONENT_USAGE__MASK 0x10000000 +#define NV30_3D_RC_FINAL1_E_COMPONENT_USAGE__SHIFT 28 +#define NV30_3D_RC_FINAL1_E_COMPONENT_USAGE_RGB 0x00000000 +#define NV30_3D_RC_FINAL1_E_COMPONENT_USAGE_ALPHA 0x10000000 +#define NV30_3D_RC_FINAL1_E_MAPPING__MASK 0xe0000000 +#define NV30_3D_RC_FINAL1_E_MAPPING__SHIFT 29 +#define NV30_3D_RC_FINAL1_E_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_FINAL1_E_MAPPING_UNSIGNED_INVERT 0x20000000 +#define NV30_3D_RC_FINAL1_E_MAPPING_EXPAND_NORMAL 0x40000000 +#define NV30_3D_RC_FINAL1_E_MAPPING_EXPAND_NEGATE 0x60000000 +#define NV30_3D_RC_FINAL1_E_MAPPING_HALF_BIAS_NORMAL 0x80000000 +#define NV30_3D_RC_FINAL1_E_MAPPING_HALF_BIAS_NEGATE 0xa0000000 +#define NV30_3D_RC_FINAL1_E_MAPPING_SIGNED_IDENTITY 0xc0000000 +#define NV30_3D_RC_FINAL1_E_MAPPING_SIGNED_NEGATE 0xe0000000 + +#define NV30_3D_RC_ENABLE 0x000008fc +#define NV30_3D_RC_ENABLE_NUM_COMBINERS__MASK 0x0000000f +#define NV30_3D_RC_ENABLE_NUM_COMBINERS__SHIFT 0 +#define NV30_3D_RC_ENABLE_STAGE_CONSTANT_COLOR0 0x0000f000 +#define NV30_3D_RC_ENABLE_STAGE_CONSTANT_COLOR1 0x000f0000 + + +#define NV30_3D_RC_IN_ALPHA(i0) (0x00000900 + 0x20*(i0)) +#define NV30_3D_RC_IN_ALPHA_D_INPUT__MASK 0x0000000f +#define NV30_3D_RC_IN_ALPHA_D_INPUT__SHIFT 0 +#define NV30_3D_RC_IN_ALPHA_D_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_IN_ALPHA_D_INPUT_CONSTANT_COLOR0 0x00000001 +#define NV30_3D_RC_IN_ALPHA_D_INPUT_CONSTANT_COLOR1 0x00000002 +#define NV30_3D_RC_IN_ALPHA_D_INPUT_FOG 0x00000003 +#define NV30_3D_RC_IN_ALPHA_D_INPUT_PRIMARY_COLOR 0x00000004 +#define NV30_3D_RC_IN_ALPHA_D_INPUT_SECONDARY_COLOR 0x00000005 +#define NV30_3D_RC_IN_ALPHA_D_INPUT_TEXTURE0 0x00000008 +#define NV30_3D_RC_IN_ALPHA_D_INPUT_TEXTURE1 0x00000009 +#define NV30_3D_RC_IN_ALPHA_D_INPUT_TEXTURE2 0x0000000a +#define NV30_3D_RC_IN_ALPHA_D_INPUT_TEXTURE3 0x0000000b +#define NV30_3D_RC_IN_ALPHA_D_INPUT_SPARE0 0x0000000c +#define NV30_3D_RC_IN_ALPHA_D_INPUT_SPARE1 0x0000000d +#define NV30_3D_RC_IN_ALPHA_D_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x0000000e +#define NV30_3D_RC_IN_ALPHA_D_INPUT_E_TIMES_F 0x0000000f +#define NV30_3D_RC_IN_ALPHA_D_COMPONENT_USAGE__MASK 0x00000010 +#define NV30_3D_RC_IN_ALPHA_D_COMPONENT_USAGE__SHIFT 4 +#define NV30_3D_RC_IN_ALPHA_D_COMPONENT_USAGE_BLUE 0x00000000 +#define NV30_3D_RC_IN_ALPHA_D_COMPONENT_USAGE_ALPHA 0x00000010 +#define NV30_3D_RC_IN_ALPHA_D_MAPPING__MASK 0x000000e0 +#define NV30_3D_RC_IN_ALPHA_D_MAPPING__SHIFT 5 +#define NV30_3D_RC_IN_ALPHA_D_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_IN_ALPHA_D_MAPPING_UNSIGNED_INVERT 0x00000020 +#define NV30_3D_RC_IN_ALPHA_D_MAPPING_EXPAND_NORMAL 0x00000040 +#define NV30_3D_RC_IN_ALPHA_D_MAPPING_EXPAND_NEGATE 0x00000060 +#define NV30_3D_RC_IN_ALPHA_D_MAPPING_HALF_BIAS_NORMAL 0x00000080 +#define NV30_3D_RC_IN_ALPHA_D_MAPPING_HALF_BIAS_NEGATE 0x000000a0 +#define NV30_3D_RC_IN_ALPHA_D_MAPPING_SIGNED_IDENTITY 0x000000c0 +#define NV30_3D_RC_IN_ALPHA_D_MAPPING_SIGNED_NEGATE 0x000000e0 +#define NV30_3D_RC_IN_ALPHA_C_INPUT__MASK 0x00000f00 +#define NV30_3D_RC_IN_ALPHA_C_INPUT__SHIFT 8 +#define NV30_3D_RC_IN_ALPHA_C_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_IN_ALPHA_C_INPUT_CONSTANT_COLOR0 0x00000100 +#define NV30_3D_RC_IN_ALPHA_C_INPUT_CONSTANT_COLOR1 0x00000200 +#define NV30_3D_RC_IN_ALPHA_C_INPUT_FOG 0x00000300 +#define NV30_3D_RC_IN_ALPHA_C_INPUT_PRIMARY_COLOR 0x00000400 +#define NV30_3D_RC_IN_ALPHA_C_INPUT_SECONDARY_COLOR 0x00000500 +#define NV30_3D_RC_IN_ALPHA_C_INPUT_TEXTURE0 0x00000800 +#define NV30_3D_RC_IN_ALPHA_C_INPUT_TEXTURE1 0x00000900 +#define NV30_3D_RC_IN_ALPHA_C_INPUT_TEXTURE2 0x00000a00 +#define NV30_3D_RC_IN_ALPHA_C_INPUT_TEXTURE3 0x00000b00 +#define NV30_3D_RC_IN_ALPHA_C_INPUT_SPARE0 0x00000c00 +#define NV30_3D_RC_IN_ALPHA_C_INPUT_SPARE1 0x00000d00 +#define NV30_3D_RC_IN_ALPHA_C_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x00000e00 +#define NV30_3D_RC_IN_ALPHA_C_INPUT_E_TIMES_F 0x00000f00 +#define NV30_3D_RC_IN_ALPHA_C_COMPONENT_USAGE__MASK 0x00001000 +#define NV30_3D_RC_IN_ALPHA_C_COMPONENT_USAGE__SHIFT 12 +#define NV30_3D_RC_IN_ALPHA_C_COMPONENT_USAGE_BLUE 0x00000000 +#define NV30_3D_RC_IN_ALPHA_C_COMPONENT_USAGE_ALPHA 0x00001000 +#define NV30_3D_RC_IN_ALPHA_C_MAPPING__MASK 0x0000e000 +#define NV30_3D_RC_IN_ALPHA_C_MAPPING__SHIFT 13 +#define NV30_3D_RC_IN_ALPHA_C_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_IN_ALPHA_C_MAPPING_UNSIGNED_INVERT 0x00002000 +#define NV30_3D_RC_IN_ALPHA_C_MAPPING_EXPAND_NORMAL 0x00004000 +#define NV30_3D_RC_IN_ALPHA_C_MAPPING_EXPAND_NEGATE 0x00006000 +#define NV30_3D_RC_IN_ALPHA_C_MAPPING_HALF_BIAS_NORMAL 0x00008000 +#define NV30_3D_RC_IN_ALPHA_C_MAPPING_HALF_BIAS_NEGATE 0x0000a000 +#define NV30_3D_RC_IN_ALPHA_C_MAPPING_SIGNED_IDENTITY 0x0000c000 +#define NV30_3D_RC_IN_ALPHA_C_MAPPING_SIGNED_NEGATE 0x0000e000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT__MASK 0x000f0000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT__SHIFT 16 +#define NV30_3D_RC_IN_ALPHA_B_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT_CONSTANT_COLOR0 0x00010000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT_CONSTANT_COLOR1 0x00020000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT_FOG 0x00030000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT_PRIMARY_COLOR 0x00040000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT_SECONDARY_COLOR 0x00050000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT_TEXTURE0 0x00080000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT_TEXTURE1 0x00090000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT_TEXTURE2 0x000a0000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT_TEXTURE3 0x000b0000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT_SPARE0 0x000c0000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT_SPARE1 0x000d0000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x000e0000 +#define NV30_3D_RC_IN_ALPHA_B_INPUT_E_TIMES_F 0x000f0000 +#define NV30_3D_RC_IN_ALPHA_B_COMPONENT_USAGE__MASK 0x00100000 +#define NV30_3D_RC_IN_ALPHA_B_COMPONENT_USAGE__SHIFT 20 +#define NV30_3D_RC_IN_ALPHA_B_COMPONENT_USAGE_BLUE 0x00000000 +#define NV30_3D_RC_IN_ALPHA_B_COMPONENT_USAGE_ALPHA 0x00100000 +#define NV30_3D_RC_IN_ALPHA_B_MAPPING__MASK 0x00e00000 +#define NV30_3D_RC_IN_ALPHA_B_MAPPING__SHIFT 21 +#define NV30_3D_RC_IN_ALPHA_B_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_IN_ALPHA_B_MAPPING_UNSIGNED_INVERT 0x00200000 +#define NV30_3D_RC_IN_ALPHA_B_MAPPING_EXPAND_NORMAL 0x00400000 +#define NV30_3D_RC_IN_ALPHA_B_MAPPING_EXPAND_NEGATE 0x00600000 +#define NV30_3D_RC_IN_ALPHA_B_MAPPING_HALF_BIAS_NORMAL 0x00800000 +#define NV30_3D_RC_IN_ALPHA_B_MAPPING_HALF_BIAS_NEGATE 0x00a00000 +#define NV30_3D_RC_IN_ALPHA_B_MAPPING_SIGNED_IDENTITY 0x00c00000 +#define NV30_3D_RC_IN_ALPHA_B_MAPPING_SIGNED_NEGATE 0x00e00000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT__MASK 0x0f000000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT__SHIFT 24 +#define NV30_3D_RC_IN_ALPHA_A_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT_CONSTANT_COLOR0 0x01000000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT_CONSTANT_COLOR1 0x02000000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT_FOG 0x03000000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT_PRIMARY_COLOR 0x04000000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT_SECONDARY_COLOR 0x05000000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT_TEXTURE0 0x08000000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT_TEXTURE1 0x09000000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT_TEXTURE2 0x0a000000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT_TEXTURE3 0x0b000000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT_SPARE0 0x0c000000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT_SPARE1 0x0d000000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x0e000000 +#define NV30_3D_RC_IN_ALPHA_A_INPUT_E_TIMES_F 0x0f000000 +#define NV30_3D_RC_IN_ALPHA_A_COMPONENT_USAGE__MASK 0x10000000 +#define NV30_3D_RC_IN_ALPHA_A_COMPONENT_USAGE__SHIFT 28 +#define NV30_3D_RC_IN_ALPHA_A_COMPONENT_USAGE_BLUE 0x00000000 +#define NV30_3D_RC_IN_ALPHA_A_COMPONENT_USAGE_ALPHA 0x10000000 +#define NV30_3D_RC_IN_ALPHA_A_MAPPING__MASK 0xe0000000 +#define NV30_3D_RC_IN_ALPHA_A_MAPPING__SHIFT 29 +#define NV30_3D_RC_IN_ALPHA_A_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_IN_ALPHA_A_MAPPING_UNSIGNED_INVERT 0x20000000 +#define NV30_3D_RC_IN_ALPHA_A_MAPPING_EXPAND_NORMAL 0x40000000 +#define NV30_3D_RC_IN_ALPHA_A_MAPPING_EXPAND_NEGATE 0x60000000 +#define NV30_3D_RC_IN_ALPHA_A_MAPPING_HALF_BIAS_NORMAL 0x80000000 +#define NV30_3D_RC_IN_ALPHA_A_MAPPING_HALF_BIAS_NEGATE 0xa0000000 +#define NV30_3D_RC_IN_ALPHA_A_MAPPING_SIGNED_IDENTITY 0xc0000000 +#define NV30_3D_RC_IN_ALPHA_A_MAPPING_SIGNED_NEGATE 0xe0000000 + +#define NV30_3D_RC_IN_RGB(i0) (0x00000904 + 0x20*(i0)) +#define NV30_3D_RC_IN_RGB_D_INPUT__MASK 0x0000000f +#define NV30_3D_RC_IN_RGB_D_INPUT__SHIFT 0 +#define NV30_3D_RC_IN_RGB_D_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_IN_RGB_D_INPUT_CONSTANT_COLOR0 0x00000001 +#define NV30_3D_RC_IN_RGB_D_INPUT_CONSTANT_COLOR1 0x00000002 +#define NV30_3D_RC_IN_RGB_D_INPUT_FOG 0x00000003 +#define NV30_3D_RC_IN_RGB_D_INPUT_PRIMARY_COLOR 0x00000004 +#define NV30_3D_RC_IN_RGB_D_INPUT_SECONDARY_COLOR 0x00000005 +#define NV30_3D_RC_IN_RGB_D_INPUT_TEXTURE0 0x00000008 +#define NV30_3D_RC_IN_RGB_D_INPUT_TEXTURE1 0x00000009 +#define NV30_3D_RC_IN_RGB_D_INPUT_TEXTURE2 0x0000000a +#define NV30_3D_RC_IN_RGB_D_INPUT_TEXTURE3 0x0000000b +#define NV30_3D_RC_IN_RGB_D_INPUT_SPARE0 0x0000000c +#define NV30_3D_RC_IN_RGB_D_INPUT_SPARE1 0x0000000d +#define NV30_3D_RC_IN_RGB_D_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x0000000e +#define NV30_3D_RC_IN_RGB_D_INPUT_E_TIMES_F 0x0000000f +#define NV30_3D_RC_IN_RGB_D_COMPONENT_USAGE__MASK 0x00000010 +#define NV30_3D_RC_IN_RGB_D_COMPONENT_USAGE__SHIFT 4 +#define NV30_3D_RC_IN_RGB_D_COMPONENT_USAGE_RGB 0x00000000 +#define NV30_3D_RC_IN_RGB_D_COMPONENT_USAGE_ALPHA 0x00000010 +#define NV30_3D_RC_IN_RGB_D_MAPPING__MASK 0x000000e0 +#define NV30_3D_RC_IN_RGB_D_MAPPING__SHIFT 5 +#define NV30_3D_RC_IN_RGB_D_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_IN_RGB_D_MAPPING_UNSIGNED_INVERT 0x00000020 +#define NV30_3D_RC_IN_RGB_D_MAPPING_EXPAND_NORMAL 0x00000040 +#define NV30_3D_RC_IN_RGB_D_MAPPING_EXPAND_NEGATE 0x00000060 +#define NV30_3D_RC_IN_RGB_D_MAPPING_HALF_BIAS_NORMAL 0x00000080 +#define NV30_3D_RC_IN_RGB_D_MAPPING_HALF_BIAS_NEGATE 0x000000a0 +#define NV30_3D_RC_IN_RGB_D_MAPPING_SIGNED_IDENTITY 0x000000c0 +#define NV30_3D_RC_IN_RGB_D_MAPPING_SIGNED_NEGATE 0x000000e0 +#define NV30_3D_RC_IN_RGB_C_INPUT__MASK 0x00000f00 +#define NV30_3D_RC_IN_RGB_C_INPUT__SHIFT 8 +#define NV30_3D_RC_IN_RGB_C_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_IN_RGB_C_INPUT_CONSTANT_COLOR0 0x00000100 +#define NV30_3D_RC_IN_RGB_C_INPUT_CONSTANT_COLOR1 0x00000200 +#define NV30_3D_RC_IN_RGB_C_INPUT_FOG 0x00000300 +#define NV30_3D_RC_IN_RGB_C_INPUT_PRIMARY_COLOR 0x00000400 +#define NV30_3D_RC_IN_RGB_C_INPUT_SECONDARY_COLOR 0x00000500 +#define NV30_3D_RC_IN_RGB_C_INPUT_TEXTURE0 0x00000800 +#define NV30_3D_RC_IN_RGB_C_INPUT_TEXTURE1 0x00000900 +#define NV30_3D_RC_IN_RGB_C_INPUT_TEXTURE2 0x00000a00 +#define NV30_3D_RC_IN_RGB_C_INPUT_TEXTURE3 0x00000b00 +#define NV30_3D_RC_IN_RGB_C_INPUT_SPARE0 0x00000c00 +#define NV30_3D_RC_IN_RGB_C_INPUT_SPARE1 0x00000d00 +#define NV30_3D_RC_IN_RGB_C_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x00000e00 +#define NV30_3D_RC_IN_RGB_C_INPUT_E_TIMES_F 0x00000f00 +#define NV30_3D_RC_IN_RGB_C_COMPONENT_USAGE__MASK 0x00001000 +#define NV30_3D_RC_IN_RGB_C_COMPONENT_USAGE__SHIFT 12 +#define NV30_3D_RC_IN_RGB_C_COMPONENT_USAGE_RGB 0x00000000 +#define NV30_3D_RC_IN_RGB_C_COMPONENT_USAGE_ALPHA 0x00001000 +#define NV30_3D_RC_IN_RGB_C_MAPPING__MASK 0x0000e000 +#define NV30_3D_RC_IN_RGB_C_MAPPING__SHIFT 13 +#define NV30_3D_RC_IN_RGB_C_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_IN_RGB_C_MAPPING_UNSIGNED_INVERT 0x00002000 +#define NV30_3D_RC_IN_RGB_C_MAPPING_EXPAND_NORMAL 0x00004000 +#define NV30_3D_RC_IN_RGB_C_MAPPING_EXPAND_NEGATE 0x00006000 +#define NV30_3D_RC_IN_RGB_C_MAPPING_HALF_BIAS_NORMAL 0x00008000 +#define NV30_3D_RC_IN_RGB_C_MAPPING_HALF_BIAS_NEGATE 0x0000a000 +#define NV30_3D_RC_IN_RGB_C_MAPPING_SIGNED_IDENTITY 0x0000c000 +#define NV30_3D_RC_IN_RGB_C_MAPPING_SIGNED_NEGATE 0x0000e000 +#define NV30_3D_RC_IN_RGB_B_INPUT__MASK 0x000f0000 +#define NV30_3D_RC_IN_RGB_B_INPUT__SHIFT 16 +#define NV30_3D_RC_IN_RGB_B_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_IN_RGB_B_INPUT_CONSTANT_COLOR0 0x00010000 +#define NV30_3D_RC_IN_RGB_B_INPUT_CONSTANT_COLOR1 0x00020000 +#define NV30_3D_RC_IN_RGB_B_INPUT_FOG 0x00030000 +#define NV30_3D_RC_IN_RGB_B_INPUT_PRIMARY_COLOR 0x00040000 +#define NV30_3D_RC_IN_RGB_B_INPUT_SECONDARY_COLOR 0x00050000 +#define NV30_3D_RC_IN_RGB_B_INPUT_TEXTURE0 0x00080000 +#define NV30_3D_RC_IN_RGB_B_INPUT_TEXTURE1 0x00090000 +#define NV30_3D_RC_IN_RGB_B_INPUT_TEXTURE2 0x000a0000 +#define NV30_3D_RC_IN_RGB_B_INPUT_TEXTURE3 0x000b0000 +#define NV30_3D_RC_IN_RGB_B_INPUT_SPARE0 0x000c0000 +#define NV30_3D_RC_IN_RGB_B_INPUT_SPARE1 0x000d0000 +#define NV30_3D_RC_IN_RGB_B_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x000e0000 +#define NV30_3D_RC_IN_RGB_B_INPUT_E_TIMES_F 0x000f0000 +#define NV30_3D_RC_IN_RGB_B_COMPONENT_USAGE__MASK 0x00100000 +#define NV30_3D_RC_IN_RGB_B_COMPONENT_USAGE__SHIFT 20 +#define NV30_3D_RC_IN_RGB_B_COMPONENT_USAGE_RGB 0x00000000 +#define NV30_3D_RC_IN_RGB_B_COMPONENT_USAGE_ALPHA 0x00100000 +#define NV30_3D_RC_IN_RGB_B_MAPPING__MASK 0x00e00000 +#define NV30_3D_RC_IN_RGB_B_MAPPING__SHIFT 21 +#define NV30_3D_RC_IN_RGB_B_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_IN_RGB_B_MAPPING_UNSIGNED_INVERT 0x00200000 +#define NV30_3D_RC_IN_RGB_B_MAPPING_EXPAND_NORMAL 0x00400000 +#define NV30_3D_RC_IN_RGB_B_MAPPING_EXPAND_NEGATE 0x00600000 +#define NV30_3D_RC_IN_RGB_B_MAPPING_HALF_BIAS_NORMAL 0x00800000 +#define NV30_3D_RC_IN_RGB_B_MAPPING_HALF_BIAS_NEGATE 0x00a00000 +#define NV30_3D_RC_IN_RGB_B_MAPPING_SIGNED_IDENTITY 0x00c00000 +#define NV30_3D_RC_IN_RGB_B_MAPPING_SIGNED_NEGATE 0x00e00000 +#define NV30_3D_RC_IN_RGB_A_INPUT__MASK 0x0f000000 +#define NV30_3D_RC_IN_RGB_A_INPUT__SHIFT 24 +#define NV30_3D_RC_IN_RGB_A_INPUT_ZERO 0x00000000 +#define NV30_3D_RC_IN_RGB_A_INPUT_CONSTANT_COLOR0 0x01000000 +#define NV30_3D_RC_IN_RGB_A_INPUT_CONSTANT_COLOR1 0x02000000 +#define NV30_3D_RC_IN_RGB_A_INPUT_FOG 0x03000000 +#define NV30_3D_RC_IN_RGB_A_INPUT_PRIMARY_COLOR 0x04000000 +#define NV30_3D_RC_IN_RGB_A_INPUT_SECONDARY_COLOR 0x05000000 +#define NV30_3D_RC_IN_RGB_A_INPUT_TEXTURE0 0x08000000 +#define NV30_3D_RC_IN_RGB_A_INPUT_TEXTURE1 0x09000000 +#define NV30_3D_RC_IN_RGB_A_INPUT_TEXTURE2 0x0a000000 +#define NV30_3D_RC_IN_RGB_A_INPUT_TEXTURE3 0x0b000000 +#define NV30_3D_RC_IN_RGB_A_INPUT_SPARE0 0x0c000000 +#define NV30_3D_RC_IN_RGB_A_INPUT_SPARE1 0x0d000000 +#define NV30_3D_RC_IN_RGB_A_INPUT_SPARE0_PLUS_SECONDARY_COLOR 0x0e000000 +#define NV30_3D_RC_IN_RGB_A_INPUT_E_TIMES_F 0x0f000000 +#define NV30_3D_RC_IN_RGB_A_COMPONENT_USAGE__MASK 0x10000000 +#define NV30_3D_RC_IN_RGB_A_COMPONENT_USAGE__SHIFT 28 +#define NV30_3D_RC_IN_RGB_A_COMPONENT_USAGE_RGB 0x00000000 +#define NV30_3D_RC_IN_RGB_A_COMPONENT_USAGE_ALPHA 0x10000000 +#define NV30_3D_RC_IN_RGB_A_MAPPING__MASK 0xe0000000 +#define NV30_3D_RC_IN_RGB_A_MAPPING__SHIFT 29 +#define NV30_3D_RC_IN_RGB_A_MAPPING_UNSIGNED_IDENTITY 0x00000000 +#define NV30_3D_RC_IN_RGB_A_MAPPING_UNSIGNED_INVERT 0x20000000 +#define NV30_3D_RC_IN_RGB_A_MAPPING_EXPAND_NORMAL 0x40000000 +#define NV30_3D_RC_IN_RGB_A_MAPPING_EXPAND_NEGATE 0x60000000 +#define NV30_3D_RC_IN_RGB_A_MAPPING_HALF_BIAS_NORMAL 0x80000000 +#define NV30_3D_RC_IN_RGB_A_MAPPING_HALF_BIAS_NEGATE 0xa0000000 +#define NV30_3D_RC_IN_RGB_A_MAPPING_SIGNED_IDENTITY 0xc0000000 +#define NV30_3D_RC_IN_RGB_A_MAPPING_SIGNED_NEGATE 0xe0000000 + +#define NV30_3D_RC_CONSTANT_COLOR0(i0) (0x00000908 + 0x20*(i0)) +#define NV30_3D_RC_CONSTANT_COLOR0_B__MASK 0x000000ff +#define NV30_3D_RC_CONSTANT_COLOR0_B__SHIFT 0 +#define NV30_3D_RC_CONSTANT_COLOR0_G__MASK 0x0000ff00 +#define NV30_3D_RC_CONSTANT_COLOR0_G__SHIFT 8 +#define NV30_3D_RC_CONSTANT_COLOR0_R__MASK 0x00ff0000 +#define NV30_3D_RC_CONSTANT_COLOR0_R__SHIFT 16 +#define NV30_3D_RC_CONSTANT_COLOR0_A__MASK 0xff000000 +#define NV30_3D_RC_CONSTANT_COLOR0_A__SHIFT 24 + +#define NV30_3D_RC_CONSTANT_COLOR1(i0) (0x0000090c + 0x20*(i0)) +#define NV30_3D_RC_CONSTANT_COLOR1_B__MASK 0x000000ff +#define NV30_3D_RC_CONSTANT_COLOR1_B__SHIFT 0 +#define NV30_3D_RC_CONSTANT_COLOR1_G__MASK 0x0000ff00 +#define NV30_3D_RC_CONSTANT_COLOR1_G__SHIFT 8 +#define NV30_3D_RC_CONSTANT_COLOR1_R__MASK 0x00ff0000 +#define NV30_3D_RC_CONSTANT_COLOR1_R__SHIFT 16 +#define NV30_3D_RC_CONSTANT_COLOR1_A__MASK 0xff000000 +#define NV30_3D_RC_CONSTANT_COLOR1_A__SHIFT 24 + +#define NV30_3D_RC_OUT_ALPHA(i0) (0x00000910 + 0x20*(i0)) +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT__MASK 0x0000000f +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT__SHIFT 0 +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT_ZERO 0x00000000 +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT_CONSTANT_COLOR0 0x00000001 +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT_CONSTANT_COLOR1 0x00000002 +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT_FOG 0x00000003 +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT_PRIMARY_COLOR 0x00000004 +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT_SECONDARY_COLOR 0x00000005 +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT_TEXTURE0 0x00000008 +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT_TEXTURE1 0x00000009 +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT_TEXTURE2 0x0000000a +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT_TEXTURE3 0x0000000b +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT_SPARE0 0x0000000c +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT_SPARE1 0x0000000d +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT_SPARE0_PLUS_SECONDARY_COLOR 0x0000000e +#define NV30_3D_RC_OUT_ALPHA_CD_OUTPUT_E_TIMES_F 0x0000000f +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT__MASK 0x000000f0 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT__SHIFT 4 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT_ZERO 0x00000000 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT_CONSTANT_COLOR0 0x00000010 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT_CONSTANT_COLOR1 0x00000020 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT_FOG 0x00000030 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT_PRIMARY_COLOR 0x00000040 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT_SECONDARY_COLOR 0x00000050 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT_TEXTURE0 0x00000080 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT_TEXTURE1 0x00000090 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT_TEXTURE2 0x000000a0 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT_TEXTURE3 0x000000b0 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT_SPARE0 0x000000c0 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT_SPARE1 0x000000d0 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT_SPARE0_PLUS_SECONDARY_COLOR 0x000000e0 +#define NV30_3D_RC_OUT_ALPHA_AB_OUTPUT_E_TIMES_F 0x000000f0 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT__MASK 0x00000f00 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT__SHIFT 8 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT_ZERO 0x00000000 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT_CONSTANT_COLOR0 0x00000100 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT_CONSTANT_COLOR1 0x00000200 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT_FOG 0x00000300 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT_PRIMARY_COLOR 0x00000400 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT_SECONDARY_COLOR 0x00000500 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT_TEXTURE0 0x00000800 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT_TEXTURE1 0x00000900 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT_TEXTURE2 0x00000a00 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT_TEXTURE3 0x00000b00 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT_SPARE0 0x00000c00 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT_SPARE1 0x00000d00 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT_SPARE0_PLUS_SECONDARY_COLOR 0x00000e00 +#define NV30_3D_RC_OUT_ALPHA_SUM_OUTPUT_E_TIMES_F 0x00000f00 +#define NV30_3D_RC_OUT_ALPHA_CD_DOT_PRODUCT 0x00001000 +#define NV30_3D_RC_OUT_ALPHA_AB_DOT_PRODUCT 0x00002000 +#define NV30_3D_RC_OUT_ALPHA_MUX_SUM 0x00004000 +#define NV30_3D_RC_OUT_ALPHA_BIAS__MASK 0x00008000 +#define NV30_3D_RC_OUT_ALPHA_BIAS__SHIFT 15 +#define NV30_3D_RC_OUT_ALPHA_BIAS_NONE 0x00000000 +#define NV30_3D_RC_OUT_ALPHA_BIAS_BIAS_BY_NEGATIVE_ONE_HALF 0x00008000 +#define NV30_3D_RC_OUT_ALPHA_SCALE__MASK 0x00030000 +#define NV30_3D_RC_OUT_ALPHA_SCALE__SHIFT 16 +#define NV30_3D_RC_OUT_ALPHA_SCALE_NONE 0x00000000 +#define NV30_3D_RC_OUT_ALPHA_SCALE_SCALE_BY_TWO 0x00010000 +#define NV30_3D_RC_OUT_ALPHA_SCALE_SCALE_BY_FOUR 0x00020000 +#define NV30_3D_RC_OUT_ALPHA_SCALE_SCALE_BY_ONE_HALF 0x00030000 + +#define NV30_3D_RC_OUT_RGB(i0) (0x00000914 + 0x20*(i0)) +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT__MASK 0x0000000f +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT__SHIFT 0 +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT_ZERO 0x00000000 +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT_CONSTANT_COLOR0 0x00000001 +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT_CONSTANT_COLOR1 0x00000002 +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT_FOG 0x00000003 +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT_PRIMARY_COLOR 0x00000004 +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT_SECONDARY_COLOR 0x00000005 +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT_TEXTURE0 0x00000008 +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT_TEXTURE1 0x00000009 +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT_TEXTURE2 0x0000000a +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT_TEXTURE3 0x0000000b +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT_SPARE0 0x0000000c +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT_SPARE1 0x0000000d +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT_SPARE0_PLUS_SECONDARY_COLOR 0x0000000e +#define NV30_3D_RC_OUT_RGB_CD_OUTPUT_E_TIMES_F 0x0000000f +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT__MASK 0x000000f0 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT__SHIFT 4 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT_ZERO 0x00000000 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT_CONSTANT_COLOR0 0x00000010 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT_CONSTANT_COLOR1 0x00000020 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT_FOG 0x00000030 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT_PRIMARY_COLOR 0x00000040 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT_SECONDARY_COLOR 0x00000050 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT_TEXTURE0 0x00000080 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT_TEXTURE1 0x00000090 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT_TEXTURE2 0x000000a0 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT_TEXTURE3 0x000000b0 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT_SPARE0 0x000000c0 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT_SPARE1 0x000000d0 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT_SPARE0_PLUS_SECONDARY_COLOR 0x000000e0 +#define NV30_3D_RC_OUT_RGB_AB_OUTPUT_E_TIMES_F 0x000000f0 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT__MASK 0x00000f00 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT__SHIFT 8 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT_ZERO 0x00000000 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT_CONSTANT_COLOR0 0x00000100 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT_CONSTANT_COLOR1 0x00000200 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT_FOG 0x00000300 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT_PRIMARY_COLOR 0x00000400 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT_SECONDARY_COLOR 0x00000500 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT_TEXTURE0 0x00000800 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT_TEXTURE1 0x00000900 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT_TEXTURE2 0x00000a00 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT_TEXTURE3 0x00000b00 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT_SPARE0 0x00000c00 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT_SPARE1 0x00000d00 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT_SPARE0_PLUS_SECONDARY_COLOR 0x00000e00 +#define NV30_3D_RC_OUT_RGB_SUM_OUTPUT_E_TIMES_F 0x00000f00 +#define NV30_3D_RC_OUT_RGB_CD_DOT_PRODUCT 0x00001000 +#define NV30_3D_RC_OUT_RGB_AB_DOT_PRODUCT 0x00002000 +#define NV30_3D_RC_OUT_RGB_MUX_SUM 0x00004000 +#define NV30_3D_RC_OUT_RGB_BIAS__MASK 0x00008000 +#define NV30_3D_RC_OUT_RGB_BIAS__SHIFT 15 +#define NV30_3D_RC_OUT_RGB_BIAS_NONE 0x00000000 +#define NV30_3D_RC_OUT_RGB_BIAS_BIAS_BY_NEGATIVE_ONE_HALF 0x00008000 +#define NV30_3D_RC_OUT_RGB_SCALE__MASK 0x00030000 +#define NV30_3D_RC_OUT_RGB_SCALE__SHIFT 16 +#define NV30_3D_RC_OUT_RGB_SCALE_NONE 0x00000000 +#define NV30_3D_RC_OUT_RGB_SCALE_SCALE_BY_TWO 0x00010000 +#define NV30_3D_RC_OUT_RGB_SCALE_SCALE_BY_FOUR 0x00020000 +#define NV30_3D_RC_OUT_RGB_SCALE_SCALE_BY_ONE_HALF 0x00030000 + +#define NV30_3D_VIEWPORT_HORIZ 0x00000a00 +#define NV30_3D_VIEWPORT_HORIZ_X__MASK 0x0000ffff +#define NV30_3D_VIEWPORT_HORIZ_X__SHIFT 0 +#define NV30_3D_VIEWPORT_HORIZ_W__MASK 0xffff0000 +#define NV30_3D_VIEWPORT_HORIZ_W__SHIFT 16 + +#define NV30_3D_VIEWPORT_VERT 0x00000a04 +#define NV30_3D_VIEWPORT_VERT_Y__MASK 0x0000ffff +#define NV30_3D_VIEWPORT_VERT_Y__SHIFT 0 +#define NV30_3D_VIEWPORT_VERT_H__MASK 0xffff0000 +#define NV30_3D_VIEWPORT_VERT_H__SHIFT 16 + +#define NV30_3D_LIGHT_MODEL_FRONT_SIDE_PRODUCT_AMBIENT_PLUS_EMISSION 0x00000a10 + + +#define NV30_3D_LIGHT_MODEL_FRONT_SIDE_PRODUCT_AMBIENT_PLUS_EMISSION_R 0x00000a10 + +#define NV30_3D_LIGHT_MODEL_FRONT_SIDE_PRODUCT_AMBIENT_PLUS_EMISSION_G 0x00000a14 + +#define NV30_3D_LIGHT_MODEL_FRONT_SIDE_PRODUCT_AMBIENT_PLUS_EMISSION_B 0x00000a18 + +#define NV30_3D_VIEWPORT_TRANSLATE 0x00000a20 + + +#define NV30_3D_VIEWPORT_TRANSLATE_X 0x00000a20 + +#define NV30_3D_VIEWPORT_TRANSLATE_Y 0x00000a24 + +#define NV30_3D_VIEWPORT_TRANSLATE_Z 0x00000a28 + +#define NV30_3D_VIEWPORT_TRANSLATE_W 0x00000a2c + +#define NV30_3D_VIEWPORT_SCALE 0x00000a30 + + +#define NV30_3D_VIEWPORT_SCALE_X 0x00000a30 + +#define NV30_3D_VIEWPORT_SCALE_Y 0x00000a34 + +#define NV30_3D_VIEWPORT_SCALE_Z 0x00000a38 + +#define NV30_3D_VIEWPORT_SCALE_W 0x00000a3c + +#define NV30_3D_POLYGON_OFFSET_POINT_ENABLE 0x00000a60 + +#define NV30_3D_POLYGON_OFFSET_LINE_ENABLE 0x00000a64 + +#define NV30_3D_POLYGON_OFFSET_FILL_ENABLE 0x00000a68 + +#define NV30_3D_DEPTH_FUNC 0x00000a6c +#define NV30_3D_DEPTH_FUNC_NEVER 0x00000200 +#define NV30_3D_DEPTH_FUNC_LESS 0x00000201 +#define NV30_3D_DEPTH_FUNC_EQUAL 0x00000202 +#define NV30_3D_DEPTH_FUNC_LEQUAL 0x00000203 +#define NV30_3D_DEPTH_FUNC_GREATER 0x00000204 +#define NV30_3D_DEPTH_FUNC_NOTEQUAL 0x00000205 +#define NV30_3D_DEPTH_FUNC_GEQUAL 0x00000206 +#define NV30_3D_DEPTH_FUNC_ALWAYS 0x00000207 + +#define NV30_3D_DEPTH_WRITE_ENABLE 0x00000a70 + +#define NV30_3D_DEPTH_TEST_ENABLE 0x00000a74 + +#define NV30_3D_POLYGON_OFFSET_FACTOR 0x00000a78 + +#define NV30_3D_POLYGON_OFFSET_UNITS 0x00000a7c + +#define NV30_3D_VTX_ATTR_3I_XY(i0) (0x00000a80 + 0x8*(i0)) +#define NV30_3D_VTX_ATTR_3I_XY__ESIZE 0x00000008 +#define NV30_3D_VTX_ATTR_3I_XY__LEN 0x00000010 +#define NV30_3D_VTX_ATTR_3I_XY_X__MASK 0x0000ffff +#define NV30_3D_VTX_ATTR_3I_XY_X__SHIFT 0 +#define NV30_3D_VTX_ATTR_3I_XY_Y__MASK 0xffff0000 +#define NV30_3D_VTX_ATTR_3I_XY_Y__SHIFT 16 + +#define NV30_3D_VTX_ATTR_3I_Z(i0) (0x00000a84 + 0x8*(i0)) +#define NV30_3D_VTX_ATTR_3I_Z__ESIZE 0x00000008 +#define NV30_3D_VTX_ATTR_3I_Z__LEN 0x00000010 +#define NV30_3D_VTX_ATTR_3I_Z_Z__MASK 0x0000ffff +#define NV30_3D_VTX_ATTR_3I_Z_Z__SHIFT 0 + +#define NV30_3D_TEX_FILTER_OPTIMIZATION(i0) (0x00000b00 + 0x4*(i0)) +#define NV30_3D_TEX_FILTER_OPTIMIZATION__ESIZE 0x00000004 +#define NV30_3D_TEX_FILTER_OPTIMIZATION__LEN 0x00000004 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_TRILINEAR__MASK 0x0000001f +#define NV40_3D_TEX_FILTER_OPTIMIZATION_TRILINEAR__SHIFT 0 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_TRILINEAR_OFF 0x00000000 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_TRILINEAR_HIGH_QUALITY 0x00000004 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_TRILINEAR_QUALITY 0x00000006 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_TRILINEAR_PERFORMANCE 0x00000008 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_TRILINEAR_HIGH_PERFORMANCE 0x00000018 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_ANISO_SAMPLE__MASK 0x000001c0 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_ANISO_SAMPLE__SHIFT 6 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_ANISO_SAMPLE_OFF 0x00000000 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_ANISO_SAMPLE_HIGH_QUALITY 0x000000c0 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_ANISO_SAMPLE_QUALITY 0x000001c0 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_ANISO_SAMPLE_PERFORMANCE 0x00000140 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_UNKNOWN__MASK 0x00007c00 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_UNKNOWN__SHIFT 10 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_UNKNOWN_OFF 0x00000000 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_UNKNOWN_PARTIAL 0x00002c00 +#define NV40_3D_TEX_FILTER_OPTIMIZATION_UNKNOWN_FULL 0x00007c00 + +#define NV40_3D_UNK0B40(i0) (0x00000b40 + 0x4*(i0)) +#define NV40_3D_UNK0B40__ESIZE 0x00000004 +#define NV40_3D_UNK0B40__LEN 0x00000008 + +#define NV30_3D_VP_UPLOAD_INST(i0) (0x00000b80 + 0x4*(i0)) +#define NV30_3D_VP_UPLOAD_INST__ESIZE 0x00000004 +#define NV30_3D_VP_UPLOAD_INST__LEN 0x00000004 + + +#define NV30_3D_TEX_CLIP_PLANE(i0) (0x00000e00 + 0x10*(i0)) + + +#define NV30_3D_TEX_CLIP_PLANE_X(i0) (0x00000e00 + 0x10*(i0)) + +#define NV30_3D_TEX_CLIP_PLANE_Y(i0) (0x00000e04 + 0x10*(i0)) + +#define NV30_3D_TEX_CLIP_PLANE_Z(i0) (0x00000e08 + 0x10*(i0)) + +#define NV30_3D_TEX_CLIP_PLANE_W(i0) (0x00000e0c + 0x10*(i0)) + +#define NV30_3D_LIGHT 0x00001000 + + +#define NV30_3D_LIGHT_FRONT_SIDE_PRODUCT_AMBIENT(i0) (0x00001000 + 0x40*(i0)) + + +#define NV30_3D_LIGHT_FRONT_SIDE_PRODUCT_AMBIENT_R(i0) (0x00001000 + 0x40*(i0)) + +#define NV30_3D_LIGHT_FRONT_SIDE_PRODUCT_AMBIENT_G(i0) (0x00001004 + 0x40*(i0)) + +#define NV30_3D_LIGHT_FRONT_SIDE_PRODUCT_AMBIENT_B(i0) (0x00001008 + 0x40*(i0)) + +#define NV30_3D_LIGHT_FRONT_SIDE_PRODUCT_DIFFUSE(i0) (0x0000100c + 0x40*(i0)) + + +#define NV30_3D_LIGHT_FRONT_SIDE_PRODUCT_DIFFUSE_R(i0) (0x0000100c + 0x40*(i0)) + +#define NV30_3D_LIGHT_FRONT_SIDE_PRODUCT_DIFFUSE_G(i0) (0x00001010 + 0x40*(i0)) + +#define NV30_3D_LIGHT_FRONT_SIDE_PRODUCT_DIFFUSE_B(i0) (0x00001014 + 0x40*(i0)) + +#define NV30_3D_LIGHT_FRONT_SIDE_PRODUCT_SPECULAR(i0) (0x00001018 + 0x40*(i0)) + + +#define NV30_3D_LIGHT_FRONT_SIDE_PRODUCT_SPECULAR_R(i0) (0x00001018 + 0x40*(i0)) + +#define NV30_3D_LIGHT_FRONT_SIDE_PRODUCT_SPECULAR_G(i0) (0x0000101c + 0x40*(i0)) + +#define NV30_3D_LIGHT_FRONT_SIDE_PRODUCT_SPECULAR_B(i0) (0x00001020 + 0x40*(i0)) + +#define NV30_3D_LIGHT_UNK24(i0) (0x00001024 + 0x40*(i0)) + +#define NV30_3D_LIGHT_HALF_VECTOR(i0) (0x00001028 + 0x40*(i0)) + + +#define NV30_3D_LIGHT_HALF_VECTOR_X(i0) (0x00001028 + 0x40*(i0)) + +#define NV30_3D_LIGHT_HALF_VECTOR_Y(i0) (0x0000102c + 0x40*(i0)) + +#define NV30_3D_LIGHT_HALF_VECTOR_Z(i0) (0x00001030 + 0x40*(i0)) + +#define NV30_3D_LIGHT_DIRECTION(i0) (0x00001034 + 0x40*(i0)) + + +#define NV30_3D_LIGHT_DIRECTION_X(i0) (0x00001034 + 0x40*(i0)) + +#define NV30_3D_LIGHT_DIRECTION_Y(i0) (0x00001038 + 0x40*(i0)) + +#define NV30_3D_LIGHT_DIRECTION_Z(i0) (0x0000103c + 0x40*(i0)) + + +#define NV30_3D_LIGHT_SPOT_CUTOFF_A(i0) (0x00001200 + 0x40*(i0)) + +#define NV30_3D_LIGHT_SPOT_CUTOFF_B(i0) (0x00001204 + 0x40*(i0)) + +#define NV30_3D_LIGHT_SPOT_CUTOFF_C(i0) (0x00001208 + 0x40*(i0)) + +#define NV30_3D_LIGHT_SPOT_DIR(i0) (0x0000120c + 0x40*(i0)) + + +#define NV30_3D_LIGHT_SPOT_DIR_X(i0) (0x0000120c + 0x40*(i0)) + +#define NV30_3D_LIGHT_SPOT_DIR_Y(i0) (0x00001210 + 0x40*(i0)) + +#define NV30_3D_LIGHT_SPOT_DIR_Z(i0) (0x00001214 + 0x40*(i0)) + +#define NV30_3D_LIGHT_SPOT_CUTOFF_D(i0) (0x00001218 + 0x40*(i0)) + +#define NV30_3D_LIGHT_POSITION(i0) (0x0000121c + 0x40*(i0)) + + +#define NV30_3D_LIGHT_POSITION_X(i0) (0x0000121c + 0x40*(i0)) + +#define NV30_3D_LIGHT_POSITION_Y(i0) (0x00001220 + 0x40*(i0)) + +#define NV30_3D_LIGHT_POSITION_Z(i0) (0x00001224 + 0x40*(i0)) + +#define NV30_3D_LIGHT_ATTENUATION(i0) (0x00001228 + 0x40*(i0)) + +#define NV30_3D_LIGHT_ATTENUATION_CONSTANT(i0) (0x00001228 + 0x40*(i0)) + +#define NV30_3D_LIGHT_ATTENUATION_LINEAR(i0) (0x0000122c + 0x40*(i0)) + +#define NV30_3D_LIGHT_ATTENUATION_QUADRATIC(i0) (0x00001230 + 0x40*(i0)) + +#define NV30_3D_FRONT_MATERIAL_SHININESS(i0) (0x00001400 + 0x4*(i0)) +#define NV30_3D_FRONT_MATERIAL_SHININESS__ESIZE 0x00000004 +#define NV30_3D_FRONT_MATERIAL_SHININESS__LEN 0x00000006 + +#define NV30_3D_ENABLED_LIGHTS 0x00001420 + +#define NV30_3D_VERTEX_TWO_SIDE_ENABLE 0x0000142c + +#define NV30_3D_FP_REG_CONTROL 0x00001450 +#define NV30_3D_FP_REG_CONTROL_UNK0__MASK 0x0000ffff +#define NV30_3D_FP_REG_CONTROL_UNK0__SHIFT 0 +#define NV30_3D_FP_REG_CONTROL_UNK1__MASK 0xffff0000 +#define NV30_3D_FP_REG_CONTROL_UNK1__SHIFT 16 + +#define NV30_3D_FLATSHADE_FIRST 0x00001454 + +#define NV30_3D_EDGEFLAG 0x0000145c +#define NV30_3D_EDGEFLAG_ENABLE 0x00000001 + +#define NV30_3D_VP_CLIP_PLANES_ENABLE 0x00001478 +#define NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE0 0x00000002 +#define NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE1 0x00000020 +#define NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE2 0x00000200 +#define NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE3 0x00002000 +#define NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE4 0x00020000 +#define NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE5 0x00200000 + +#define NV30_3D_POLYGON_STIPPLE_ENABLE 0x0000147c + +#define NV30_3D_POLYGON_STIPPLE_PATTERN(i0) (0x00001480 + 0x4*(i0)) +#define NV30_3D_POLYGON_STIPPLE_PATTERN__ESIZE 0x00000004 +#define NV30_3D_POLYGON_STIPPLE_PATTERN__LEN 0x00000020 + +#define NV30_3D_VTX_ATTR_3F(i0) (0x00001500 + 0x10*(i0)) +#define NV30_3D_VTX_ATTR_3F__ESIZE 0x00000010 +#define NV30_3D_VTX_ATTR_3F__LEN 0x00000010 + + +#define NV30_3D_VTX_ATTR_3F_X(i0) (0x00001500 + 0x10*(i0)) + +#define NV30_3D_VTX_ATTR_3F_Y(i0) (0x00001504 + 0x10*(i0)) + +#define NV30_3D_VTX_ATTR_3F_Z(i0) (0x00001508 + 0x10*(i0)) + + +#define NV30_3D_VP_CLIP_PLANE(i0, i1) (0x00001600 + 0x10*(i0) + 0x4*(i1)) +#define NV30_3D_VP_CLIP_PLANE__ESIZE 0x00000004 +#define NV30_3D_VP_CLIP_PLANE__LEN 0x00000004 + +#define NV30_3D_VTXBUF(i0) (0x00001680 + 0x4*(i0)) +#define NV30_3D_VTXBUF__ESIZE 0x00000004 +#define NV30_3D_VTXBUF__LEN 0x00000010 +#define NV30_3D_VTXBUF_OFFSET__MASK 0x0fffffff +#define NV30_3D_VTXBUF_OFFSET__SHIFT 0 +#define NV30_3D_VTXBUF_DMA1 0x80000000 + +#define NV40_3D_VTX_CACHE_INVALIDATE 0x00001714 + +#define NV30_3D_VTXFMT(i0) (0x00001740 + 0x4*(i0)) +#define NV30_3D_VTXFMT__ESIZE 0x00000004 +#define NV30_3D_VTXFMT__LEN 0x00000010 +#define NV30_3D_VTXFMT_TYPE__MASK 0x0000000f +#define NV30_3D_VTXFMT_TYPE__SHIFT 0 +#define NV30_3D_VTXFMT_TYPE_B8G8R8A8_UNORM 0x00000000 +#define NV30_3D_VTXFMT_TYPE_V16_SNORM 0x00000001 +#define NV30_3D_VTXFMT_TYPE_V32_FLOAT 0x00000002 +#define NV30_3D_VTXFMT_TYPE_V16_FLOAT 0x00000003 +#define NV30_3D_VTXFMT_TYPE_U8_UNORM 0x00000004 +#define NV30_3D_VTXFMT_TYPE_V16_SSCALED 0x00000005 +#define NV30_3D_VTXFMT_TYPE_U8_USCALED 0x00000007 +#define NV30_3D_VTXFMT_SIZE__MASK 0x000000f0 +#define NV30_3D_VTXFMT_SIZE__SHIFT 4 +#define NV30_3D_VTXFMT_STRIDE__MASK 0x0000ff00 +#define NV30_3D_VTXFMT_STRIDE__SHIFT 8 + +#define NV30_3D_LIGHT_MODEL_BACK_SIDE_PRODUCT_AMBIENT_PLUS_EMISSION 0x000017a0 + + +#define NV30_3D_LIGHT_MODEL_BACK_SIDE_PRODUCT_AMBIENT_PLUS_EMISSION_R 0x000017a0 + +#define NV30_3D_LIGHT_MODEL_BACK_SIDE_PRODUCT_AMBIENT_PLUS_EMISSION_G 0x000017a4 + +#define NV30_3D_LIGHT_MODEL_BACK_SIDE_PRODUCT_AMBIENT_PLUS_EMISSION_B 0x000017a8 + +#define NV30_3D_COLOR_MATERIAL_BACK 0x000017b0 + + +#define NV30_3D_COLOR_MATERIAL_BACK_R 0x000017b0 + +#define NV30_3D_COLOR_MATERIAL_BACK_G 0x000017b4 + +#define NV30_3D_COLOR_MATERIAL_BACK_B 0x000017b8 + +#define NV30_3D_COLOR_MATERIAL_BACK_A 0x000017bc + +#define NV30_3D_QUERY_RESET 0x000017c8 + +#define NV30_3D_QUERY_ENABLE 0x000017cc + +#define NV30_3D_QUERY_GET 0x00001800 +#define NV30_3D_QUERY_GET_OFFSET__MASK 0x00ffffff +#define NV30_3D_QUERY_GET_OFFSET__SHIFT 0 +#define NV30_3D_QUERY_GET_UNK24__MASK 0xff000000 +#define NV30_3D_QUERY_GET_UNK24__SHIFT 24 + +#define NV30_3D_VERTEX_BEGIN_END 0x00001808 +#define NV30_3D_VERTEX_BEGIN_END_STOP 0x00000000 +#define NV30_3D_VERTEX_BEGIN_END_POINTS 0x00000001 +#define NV30_3D_VERTEX_BEGIN_END_LINES 0x00000002 +#define NV30_3D_VERTEX_BEGIN_END_LINE_LOOP 0x00000003 +#define NV30_3D_VERTEX_BEGIN_END_LINE_STRIP 0x00000004 +#define NV30_3D_VERTEX_BEGIN_END_TRIANGLES 0x00000005 +#define NV30_3D_VERTEX_BEGIN_END_TRIANGLE_STRIP 0x00000006 +#define NV30_3D_VERTEX_BEGIN_END_TRIANGLE_FAN 0x00000007 +#define NV30_3D_VERTEX_BEGIN_END_QUADS 0x00000008 +#define NV30_3D_VERTEX_BEGIN_END_QUAD_STRIP 0x00000009 +#define NV30_3D_VERTEX_BEGIN_END_POLYGON 0x0000000a + +#define NV30_3D_VB_ELEMENT_U16 0x0000180c +#define NV30_3D_VB_ELEMENT_U16_0__MASK 0x0000ffff +#define NV30_3D_VB_ELEMENT_U16_0__SHIFT 0 +#define NV30_3D_VB_ELEMENT_U16_1__MASK 0xffff0000 +#define NV30_3D_VB_ELEMENT_U16_1__SHIFT 16 + +#define NV30_3D_VB_ELEMENT_U32 0x00001810 + +#define NV30_3D_VB_VERTEX_BATCH 0x00001814 +#define NV30_3D_VB_VERTEX_BATCH_OFFSET__MASK 0x00ffffff +#define NV30_3D_VB_VERTEX_BATCH_OFFSET__SHIFT 0 +#define NV30_3D_VB_VERTEX_BATCH_COUNT__MASK 0xff000000 +#define NV30_3D_VB_VERTEX_BATCH_COUNT__SHIFT 24 + +#define NV30_3D_VERTEX_DATA 0x00001818 + +#define NV30_3D_IDXBUF_OFFSET 0x0000181c + +#define NV30_3D_IDXBUF_FORMAT 0x00001820 +#define NV30_3D_IDXBUF_FORMAT_DMA1 0x00000001 +#define NV30_3D_IDXBUF_FORMAT_TYPE__MASK 0x000000f0 +#define NV30_3D_IDXBUF_FORMAT_TYPE__SHIFT 4 +#define NV30_3D_IDXBUF_FORMAT_TYPE_U32 0x00000000 +#define NV30_3D_IDXBUF_FORMAT_TYPE_U16 0x00000010 + +#define NV30_3D_VB_INDEX_BATCH 0x00001824 +#define NV30_3D_VB_INDEX_BATCH_START__MASK 0x00ffffff +#define NV30_3D_VB_INDEX_BATCH_START__SHIFT 0 +#define NV30_3D_VB_INDEX_BATCH_COUNT__MASK 0xff000000 +#define NV30_3D_VB_INDEX_BATCH_COUNT__SHIFT 24 + +#define NV30_3D_POLYGON_MODE_FRONT 0x00001828 +#define NV30_3D_POLYGON_MODE_FRONT_POINT 0x00001b00 +#define NV30_3D_POLYGON_MODE_FRONT_LINE 0x00001b01 +#define NV30_3D_POLYGON_MODE_FRONT_FILL 0x00001b02 + +#define NV30_3D_POLYGON_MODE_BACK 0x0000182c +#define NV30_3D_POLYGON_MODE_BACK_POINT 0x00001b00 +#define NV30_3D_POLYGON_MODE_BACK_LINE 0x00001b01 +#define NV30_3D_POLYGON_MODE_BACK_FILL 0x00001b02 + +#define NV30_3D_CULL_FACE 0x00001830 +#define NV30_3D_CULL_FACE_FRONT 0x00000404 +#define NV30_3D_CULL_FACE_BACK 0x00000405 +#define NV30_3D_CULL_FACE_FRONT_AND_BACK 0x00000408 + +#define NV30_3D_FRONT_FACE 0x00001834 +#define NV30_3D_FRONT_FACE_CW 0x00000900 +#define NV30_3D_FRONT_FACE_CCW 0x00000901 + +#define NV30_3D_POLYGON_SMOOTH_ENABLE 0x00001838 + +#define NV30_3D_CULL_FACE_ENABLE 0x0000183c + +#define NV30_3D_TEX_PALETTE_OFFSET(i0) (0x00001840 + 0x4*(i0)) +#define NV30_3D_TEX_PALETTE_OFFSET__ESIZE 0x00000004 +#define NV30_3D_TEX_PALETTE_OFFSET__LEN 0x00000008 + +#define NV40_3D_TEX_SIZE1(i0) (0x00001840 + 0x4*(i0)) +#define NV40_3D_TEX_SIZE1__ESIZE 0x00000004 +#define NV40_3D_TEX_SIZE1__LEN 0x00000008 +#define NV40_3D_TEX_SIZE1_DEPTH__MASK 0xfff00000 +#define NV40_3D_TEX_SIZE1_DEPTH__SHIFT 20 +#define NV40_3D_TEX_SIZE1_PITCH__MASK 0x0000ffff +#define NV40_3D_TEX_SIZE1_PITCH__SHIFT 0 + +#define NV30_3D_VTX_ATTR_2F(i0) (0x00001880 + 0x8*(i0)) +#define NV30_3D_VTX_ATTR_2F__ESIZE 0x00000008 +#define NV30_3D_VTX_ATTR_2F__LEN 0x00000010 + + +#define NV30_3D_VTX_ATTR_2F_X(i0) (0x00001880 + 0x8*(i0)) + +#define NV30_3D_VTX_ATTR_2F_Y(i0) (0x00001884 + 0x8*(i0)) + +#define NV30_3D_VTX_ATTR_2I(i0) (0x00001900 + 0x4*(i0)) +#define NV30_3D_VTX_ATTR_2I__ESIZE 0x00000004 +#define NV30_3D_VTX_ATTR_2I__LEN 0x00000010 +#define NV30_3D_VTX_ATTR_2I_X__MASK 0x0000ffff +#define NV30_3D_VTX_ATTR_2I_X__SHIFT 0 +#define NV30_3D_VTX_ATTR_2I_Y__MASK 0xffff0000 +#define NV30_3D_VTX_ATTR_2I_Y__SHIFT 16 + +#define NV30_3D_VTX_ATTR_4UB(i0) (0x00001940 + 0x4*(i0)) +#define NV30_3D_VTX_ATTR_4UB__ESIZE 0x00000004 +#define NV30_3D_VTX_ATTR_4UB__LEN 0x00000010 +#define NV30_3D_VTX_ATTR_4UB_X__MASK 0x000000ff +#define NV30_3D_VTX_ATTR_4UB_X__SHIFT 0 +#define NV30_3D_VTX_ATTR_4UB_Y__MASK 0x0000ff00 +#define NV30_3D_VTX_ATTR_4UB_Y__SHIFT 8 +#define NV30_3D_VTX_ATTR_4UB_Z__MASK 0x00ff0000 +#define NV30_3D_VTX_ATTR_4UB_Z__SHIFT 16 +#define NV30_3D_VTX_ATTR_4UB_W__MASK 0xff000000 +#define NV30_3D_VTX_ATTR_4UB_W__SHIFT 24 + +#define NV30_3D_VTX_ATTR_4I(i0) (0x00001980 + 0x8*(i0)) +#define NV30_3D_VTX_ATTR_4I__ESIZE 0x00000008 +#define NV30_3D_VTX_ATTR_4I__LEN 0x00000010 + +#define NV30_3D_VTX_ATTR_4I_XY(i0) (0x00001980 + 0x8*(i0)) +#define NV30_3D_VTX_ATTR_4I_XY_X__MASK 0x0000ffff +#define NV30_3D_VTX_ATTR_4I_XY_X__SHIFT 0 +#define NV30_3D_VTX_ATTR_4I_XY_Y__MASK 0xffff0000 +#define NV30_3D_VTX_ATTR_4I_XY_Y__SHIFT 16 + +#define NV30_3D_VTX_ATTR_4I_ZW(i0) (0x00001984 + 0x8*(i0)) +#define NV30_3D_VTX_ATTR_4I_ZW_Z__MASK 0x0000ffff +#define NV30_3D_VTX_ATTR_4I_ZW_Z__SHIFT 0 +#define NV30_3D_VTX_ATTR_4I_ZW_W__MASK 0xffff0000 +#define NV30_3D_VTX_ATTR_4I_ZW_W__SHIFT 16 + +#define NV30_3D_TEX_OFFSET(i0) (0x00001a00 + 0x20*(i0)) +#define NV30_3D_TEX_OFFSET__ESIZE 0x00000020 +#define NV30_3D_TEX_OFFSET__LEN 0x00000008 + +#define NV30_3D_TEX_FORMAT(i0) (0x00001a04 + 0x20*(i0)) +#define NV30_3D_TEX_FORMAT__ESIZE 0x00000020 +#define NV30_3D_TEX_FORMAT__LEN 0x00000008 +#define NV30_3D_TEX_FORMAT_DMA0 0x00000001 +#define NV30_3D_TEX_FORMAT_DMA1 0x00000002 +#define NV30_3D_TEX_FORMAT_CUBIC 0x00000004 +#define NV30_3D_TEX_FORMAT_NO_BORDER 0x00000008 +#define NV30_3D_TEX_FORMAT_DIMS__MASK 0x000000f0 +#define NV30_3D_TEX_FORMAT_DIMS__SHIFT 4 +#define NV30_3D_TEX_FORMAT_DIMS_1D 0x00000010 +#define NV30_3D_TEX_FORMAT_DIMS_2D 0x00000020 +#define NV30_3D_TEX_FORMAT_DIMS_3D 0x00000030 +#define NV30_3D_TEX_FORMAT_FORMAT__MASK 0x0000ff00 +#define NV30_3D_TEX_FORMAT_FORMAT__SHIFT 8 +#define NV30_3D_TEX_FORMAT_FORMAT_L8 0x00000000 +#define NV30_3D_TEX_FORMAT_FORMAT_I8 0x00000100 +#define NV30_3D_TEX_FORMAT_FORMAT_A1R5G5B5 0x00000200 +#define NV30_3D_TEX_FORMAT_FORMAT_A4R4G4B4 0x00000400 +#define NV30_3D_TEX_FORMAT_FORMAT_R5G6B5 0x00000500 +#define NV30_3D_TEX_FORMAT_FORMAT_A8R8G8B8 0x00000600 +#define NV30_3D_TEX_FORMAT_FORMAT_X8R8G8B8 0x00000700 +#define NV30_3D_TEX_FORMAT_FORMAT_INDEX8 0x00000b00 +#define NV30_3D_TEX_FORMAT_FORMAT_DXT1 0x00000c00 +#define NV30_3D_TEX_FORMAT_FORMAT_DXT3 0x00000e00 +#define NV30_3D_TEX_FORMAT_FORMAT_DXT5 0x00000f00 +#define NV30_3D_TEX_FORMAT_FORMAT_A1R5G5B5_RECT 0x00001000 +#define NV30_3D_TEX_FORMAT_FORMAT_R5G6B5_RECT 0x00001100 +#define NV30_3D_TEX_FORMAT_FORMAT_A8R8G8B8_RECT 0x00001200 +#define NV30_3D_TEX_FORMAT_FORMAT_L8_RECT 0x00001300 +#define NV30_3D_TEX_FORMAT_FORMAT_DSDT8_RECT 0x00001700 +#define NV30_3D_TEX_FORMAT_FORMAT_A8L8 0x00001a00 +#define NV30_3D_TEX_FORMAT_FORMAT_I8_RECT 0x00001b00 +#define NV30_3D_TEX_FORMAT_FORMAT_A4R4G4B4_RECT 0x00001d00 +#define NV30_3D_TEX_FORMAT_FORMAT_R8G8B8_RECT 0x00001e00 +#define NV30_3D_TEX_FORMAT_FORMAT_A8L8_RECT 0x00002000 +#define NV30_3D_TEX_FORMAT_FORMAT_Z24 0x00002a00 +#define NV30_3D_TEX_FORMAT_FORMAT_Z24_RECT 0x00002b00 +#define NV30_3D_TEX_FORMAT_FORMAT_Z16 0x00002c00 +#define NV30_3D_TEX_FORMAT_FORMAT_Z16_RECT 0x00002d00 +#define NV30_3D_TEX_FORMAT_FORMAT_DSDT8 0x00002800 +#define NV30_3D_TEX_FORMAT_FORMAT_HILO16 0x00003300 +#define NV30_3D_TEX_FORMAT_FORMAT_HILO16_RECT 0x00003600 +#define NV30_3D_TEX_FORMAT_FORMAT_HILO8 0x00004400 +#define NV30_3D_TEX_FORMAT_FORMAT_SIGNED_HILO8 0x00004500 +#define NV30_3D_TEX_FORMAT_FORMAT_HILO8_RECT 0x00004600 +#define NV30_3D_TEX_FORMAT_FORMAT_SIGNED_HILO8_RECT 0x00004700 +#define NV30_3D_TEX_FORMAT_FORMAT_A16 0x00003200 +#define NV30_3D_TEX_FORMAT_FORMAT_A16_RECT 0x00003500 +#define NV30_3D_TEX_FORMAT_FORMAT_UNK3F 0x00003f00 +#define NV30_3D_TEX_FORMAT_FORMAT_FLOAT_RGBA16_NV 0x00004a00 +#define NV30_3D_TEX_FORMAT_FORMAT_FLOAT_RGBA32_NV 0x00004b00 +#define NV30_3D_TEX_FORMAT_FORMAT_FLOAT_R32_NV 0x00004c00 +#define NV40_3D_TEX_FORMAT_FORMAT__MASK 0x00001f00 +#define NV40_3D_TEX_FORMAT_FORMAT__SHIFT 8 +#define NV40_3D_TEX_FORMAT_FORMAT_L8 0x00000100 +#define NV40_3D_TEX_FORMAT_FORMAT_A1R5G5B5 0x00000200 +#define NV40_3D_TEX_FORMAT_FORMAT_A4R4G4B4 0x00000300 +#define NV40_3D_TEX_FORMAT_FORMAT_R5G6B5 0x00000400 +#define NV40_3D_TEX_FORMAT_FORMAT_A8R8G8B8 0x00000500 +#define NV40_3D_TEX_FORMAT_FORMAT_DXT1 0x00000600 +#define NV40_3D_TEX_FORMAT_FORMAT_DXT3 0x00000700 +#define NV40_3D_TEX_FORMAT_FORMAT_DXT5 0x00000800 +#define NV40_3D_TEX_FORMAT_FORMAT_A8L8 0x00000b00 +#define NV40_3D_TEX_FORMAT_FORMAT_Z24 0x00001000 +#define NV40_3D_TEX_FORMAT_FORMAT_Z16 0x00001200 +#define NV40_3D_TEX_FORMAT_FORMAT_A16 0x00001400 +#define NV40_3D_TEX_FORMAT_FORMAT_A16L16 0x00001500 +#define NV40_3D_TEX_FORMAT_FORMAT_HILO8 0x00001800 +#define NV40_3D_TEX_FORMAT_FORMAT_RGBA16F 0x00001a00 +#define NV40_3D_TEX_FORMAT_FORMAT_RGBA32F 0x00001b00 +#define NV40_3D_TEX_FORMAT_LINEAR 0x00002000 +#define NV40_3D_TEX_FORMAT_RECT 0x00004000 +#define NV40_3D_TEX_FORMAT_MIPMAP_COUNT__MASK 0x000f0000 +#define NV40_3D_TEX_FORMAT_MIPMAP_COUNT__SHIFT 16 +#define NV30_3D_TEX_FORMAT_MIPMAP 0x00080000 +#define NV30_3D_TEX_FORMAT_BASE_SIZE_U__MASK 0x00f00000 +#define NV30_3D_TEX_FORMAT_BASE_SIZE_U__SHIFT 20 +#define NV30_3D_TEX_FORMAT_BASE_SIZE_V__MASK 0x0f000000 +#define NV30_3D_TEX_FORMAT_BASE_SIZE_V__SHIFT 24 +#define NV30_3D_TEX_FORMAT_BASE_SIZE_W__MASK 0xf0000000 +#define NV30_3D_TEX_FORMAT_BASE_SIZE_W__SHIFT 28 + +#define NV30_3D_TEX_WRAP(i0) (0x00001a08 + 0x20*(i0)) +#define NV30_3D_TEX_WRAP__ESIZE 0x00000020 +#define NV30_3D_TEX_WRAP__LEN 0x00000008 +#define NV30_3D_TEX_WRAP_S__MASK 0x000000ff +#define NV30_3D_TEX_WRAP_S__SHIFT 0 +#define NV30_3D_TEX_WRAP_S_REPEAT 0x00000001 +#define NV30_3D_TEX_WRAP_S_MIRRORED_REPEAT 0x00000002 +#define NV30_3D_TEX_WRAP_S_CLAMP_TO_EDGE 0x00000003 +#define NV30_3D_TEX_WRAP_S_CLAMP_TO_BORDER 0x00000004 +#define NV30_3D_TEX_WRAP_S_CLAMP 0x00000005 +#define NV40_3D_TEX_WRAP_S_MIRROR_CLAMP_TO_EDGE 0x00000006 +#define NV40_3D_TEX_WRAP_S_MIRROR_CLAMP_TO_BORDER 0x00000007 +#define NV40_3D_TEX_WRAP_S_MIRROR_CLAMP 0x00000008 +#define NV40_3D_TEX_WRAP_ANISO_MIP_FILTER_OPTIMIZATION__MASK 0x00000070 +#define NV40_3D_TEX_WRAP_ANISO_MIP_FILTER_OPTIMIZATION__SHIFT 4 +#define NV40_3D_TEX_WRAP_ANISO_MIP_FILTER_OPTIMIZATION_OFF 0x00000000 +#define NV40_3D_TEX_WRAP_ANISO_MIP_FILTER_OPTIMIZATION_QUALITY 0x00000020 +#define NV40_3D_TEX_WRAP_ANISO_MIP_FILTER_OPTIMIZATION_PERFORMANCE 0x00000030 +#define NV40_3D_TEX_WRAP_ANISO_MIP_FILTER_OPTIMIZATION_HIGH_PERFORMANCE 0x00000070 +#define NV30_3D_TEX_WRAP_T__MASK 0x00000f00 +#define NV30_3D_TEX_WRAP_T__SHIFT 8 +#define NV30_3D_TEX_WRAP_T_REPEAT 0x00000100 +#define NV30_3D_TEX_WRAP_T_MIRRORED_REPEAT 0x00000200 +#define NV30_3D_TEX_WRAP_T_CLAMP_TO_EDGE 0x00000300 +#define NV30_3D_TEX_WRAP_T_CLAMP_TO_BORDER 0x00000400 +#define NV30_3D_TEX_WRAP_T_CLAMP 0x00000500 +#define NV40_3D_TEX_WRAP_T_MIRROR_CLAMP_TO_EDGE 0x00000600 +#define NV40_3D_TEX_WRAP_T_MIRROR_CLAMP_TO_BORDER 0x00000700 +#define NV40_3D_TEX_WRAP_T_MIRROR_CLAMP 0x00000800 +#define NV30_3D_TEX_WRAP_EXPAND_NORMAL 0x0000f000 +#define NV30_3D_TEX_WRAP_R__MASK 0x000f0000 +#define NV30_3D_TEX_WRAP_R__SHIFT 16 +#define NV30_3D_TEX_WRAP_R_REPEAT 0x00010000 +#define NV30_3D_TEX_WRAP_R_MIRRORED_REPEAT 0x00020000 +#define NV30_3D_TEX_WRAP_R_CLAMP_TO_EDGE 0x00030000 +#define NV30_3D_TEX_WRAP_R_CLAMP_TO_BORDER 0x00040000 +#define NV30_3D_TEX_WRAP_R_CLAMP 0x00050000 +#define NV40_3D_TEX_WRAP_R_MIRROR_CLAMP_TO_EDGE 0x00060000 +#define NV40_3D_TEX_WRAP_R_MIRROR_CLAMP_TO_BORDER 0x00070000 +#define NV40_3D_TEX_WRAP_R_MIRROR_CLAMP 0x00080000 +#define NV40_3D_TEX_WRAP_GAMMA_DECREASE_FILTER__MASK 0x00f00000 +#define NV40_3D_TEX_WRAP_GAMMA_DECREASE_FILTER__SHIFT 20 +#define NV40_3D_TEX_WRAP_GAMMA_DECREASE_FILTER_NONE 0x00000000 +#define NV40_3D_TEX_WRAP_GAMMA_DECREASE_FILTER_RED 0x00100000 +#define NV40_3D_TEX_WRAP_GAMMA_DECREASE_FILTER_GREEN 0x00200000 +#define NV40_3D_TEX_WRAP_GAMMA_DECREASE_FILTER_BLUE 0x00400000 +#define NV40_3D_TEX_WRAP_GAMMA_DECREASE_FILTER_ALL 0x00f00000 +#define NV30_3D_TEX_WRAP_RCOMP__MASK 0xf0000000 +#define NV30_3D_TEX_WRAP_RCOMP__SHIFT 28 +#define NV30_3D_TEX_WRAP_RCOMP_NEVER 0x00000000 +#define NV30_3D_TEX_WRAP_RCOMP_GREATER 0x10000000 +#define NV30_3D_TEX_WRAP_RCOMP_EQUAL 0x20000000 +#define NV30_3D_TEX_WRAP_RCOMP_GEQUAL 0x30000000 +#define NV30_3D_TEX_WRAP_RCOMP_LESS 0x40000000 +#define NV30_3D_TEX_WRAP_RCOMP_NOTEQUAL 0x50000000 +#define NV30_3D_TEX_WRAP_RCOMP_LEQUAL 0x60000000 +#define NV30_3D_TEX_WRAP_RCOMP_ALWAYS 0x70000000 + +#define NV30_3D_TEX_ENABLE(i0) (0x00001a0c + 0x20*(i0)) +#define NV30_3D_TEX_ENABLE__ESIZE 0x00000020 +#define NV30_3D_TEX_ENABLE__LEN 0x00000008 +#define NV30_3D_TEX_ENABLE_ANISO__MASK 0x00000030 +#define NV30_3D_TEX_ENABLE_ANISO__SHIFT 4 +#define NV30_3D_TEX_ENABLE_ANISO_NONE 0x00000000 +#define NV30_3D_TEX_ENABLE_ANISO_2X 0x00000010 +#define NV30_3D_TEX_ENABLE_ANISO_4X 0x00000020 +#define NV30_3D_TEX_ENABLE_ANISO_8X 0x00000030 +#define NV40_3D_TEX_ENABLE_ANISO__MASK 0x000000f0 +#define NV40_3D_TEX_ENABLE_ANISO__SHIFT 4 +#define NV40_3D_TEX_ENABLE_ANISO_NONE 0x00000000 +#define NV40_3D_TEX_ENABLE_ANISO_2X 0x00000010 +#define NV40_3D_TEX_ENABLE_ANISO_4X 0x00000020 +#define NV40_3D_TEX_ENABLE_ANISO_6X 0x00000030 +#define NV40_3D_TEX_ENABLE_ANISO_8X 0x00000040 +#define NV40_3D_TEX_ENABLE_ANISO_10X 0x00000050 +#define NV40_3D_TEX_ENABLE_ANISO_12X 0x00000060 +#define NV40_3D_TEX_ENABLE_ANISO_16X 0x00000070 +#define NV30_3D_TEX_ENABLE_MIPMAP_MAX_LOD__MASK 0x0003c000 +#define NV30_3D_TEX_ENABLE_MIPMAP_MAX_LOD__SHIFT 14 +#define NV40_3D_TEX_ENABLE_MIPMAP_MAX_LOD__MASK 0x00038000 +#define NV40_3D_TEX_ENABLE_MIPMAP_MAX_LOD__SHIFT 15 +#define NV30_3D_TEX_ENABLE_MIPMAP_MIN_LOD__MASK 0x3c000000 +#define NV30_3D_TEX_ENABLE_MIPMAP_MIN_LOD__SHIFT 26 +#define NV40_3D_TEX_ENABLE_MIPMAP_MIN_LOD__MASK 0x38000000 +#define NV40_3D_TEX_ENABLE_MIPMAP_MIN_LOD__SHIFT 27 +#define NV30_3D_TEX_ENABLE_ENABLE 0x40000000 +#define NV40_3D_TEX_ENABLE_ENABLE 0x80000000 + +#define NV30_3D_TEX_SWIZZLE(i0) (0x00001a10 + 0x20*(i0)) +#define NV30_3D_TEX_SWIZZLE__ESIZE 0x00000020 +#define NV30_3D_TEX_SWIZZLE__LEN 0x00000008 +#define NV30_3D_TEX_SWIZZLE_S1_W__MASK 0x00000003 +#define NV30_3D_TEX_SWIZZLE_S1_W__SHIFT 0 +#define NV30_3D_TEX_SWIZZLE_S1_W_W 0x00000000 +#define NV30_3D_TEX_SWIZZLE_S1_W_Z 0x00000001 +#define NV30_3D_TEX_SWIZZLE_S1_W_Y 0x00000002 +#define NV30_3D_TEX_SWIZZLE_S1_W_X 0x00000003 +#define NV30_3D_TEX_SWIZZLE_S1_Z__MASK 0x0000000c +#define NV30_3D_TEX_SWIZZLE_S1_Z__SHIFT 2 +#define NV30_3D_TEX_SWIZZLE_S1_Z_W 0x00000000 +#define NV30_3D_TEX_SWIZZLE_S1_Z_Z 0x00000004 +#define NV30_3D_TEX_SWIZZLE_S1_Z_Y 0x00000008 +#define NV30_3D_TEX_SWIZZLE_S1_Z_X 0x0000000c +#define NV30_3D_TEX_SWIZZLE_S1_Y__MASK 0x00000030 +#define NV30_3D_TEX_SWIZZLE_S1_Y__SHIFT 4 +#define NV30_3D_TEX_SWIZZLE_S1_Y_W 0x00000000 +#define NV30_3D_TEX_SWIZZLE_S1_Y_Z 0x00000010 +#define NV30_3D_TEX_SWIZZLE_S1_Y_Y 0x00000020 +#define NV30_3D_TEX_SWIZZLE_S1_Y_X 0x00000030 +#define NV30_3D_TEX_SWIZZLE_S1_X__MASK 0x000000c0 +#define NV30_3D_TEX_SWIZZLE_S1_X__SHIFT 6 +#define NV30_3D_TEX_SWIZZLE_S1_X_W 0x00000000 +#define NV30_3D_TEX_SWIZZLE_S1_X_Z 0x00000040 +#define NV30_3D_TEX_SWIZZLE_S1_X_Y 0x00000080 +#define NV30_3D_TEX_SWIZZLE_S1_X_X 0x000000c0 +#define NV30_3D_TEX_SWIZZLE_S0_W__MASK 0x00000300 +#define NV30_3D_TEX_SWIZZLE_S0_W__SHIFT 8 +#define NV30_3D_TEX_SWIZZLE_S0_W_ZERO 0x00000000 +#define NV30_3D_TEX_SWIZZLE_S0_W_ONE 0x00000100 +#define NV30_3D_TEX_SWIZZLE_S0_W_S1 0x00000200 +#define NV30_3D_TEX_SWIZZLE_S0_Z__MASK 0x00000c00 +#define NV30_3D_TEX_SWIZZLE_S0_Z__SHIFT 10 +#define NV30_3D_TEX_SWIZZLE_S0_Z_ZERO 0x00000000 +#define NV30_3D_TEX_SWIZZLE_S0_Z_ONE 0x00000400 +#define NV30_3D_TEX_SWIZZLE_S0_Z_S1 0x00000800 +#define NV30_3D_TEX_SWIZZLE_S0_Y__MASK 0x00003000 +#define NV30_3D_TEX_SWIZZLE_S0_Y__SHIFT 12 +#define NV30_3D_TEX_SWIZZLE_S0_Y_ZERO 0x00000000 +#define NV30_3D_TEX_SWIZZLE_S0_Y_ONE 0x00001000 +#define NV30_3D_TEX_SWIZZLE_S0_Y_S1 0x00002000 +#define NV30_3D_TEX_SWIZZLE_S0_X__MASK 0x0000c000 +#define NV30_3D_TEX_SWIZZLE_S0_X__SHIFT 14 +#define NV30_3D_TEX_SWIZZLE_S0_X_ZERO 0x00000000 +#define NV30_3D_TEX_SWIZZLE_S0_X_ONE 0x00004000 +#define NV30_3D_TEX_SWIZZLE_S0_X_S1 0x00008000 +#define NV30_3D_TEX_SWIZZLE_RECT_PITCH__MASK 0xffff0000 +#define NV30_3D_TEX_SWIZZLE_RECT_PITCH__SHIFT 16 + +#define NV30_3D_TEX_FILTER(i0) (0x00001a14 + 0x20*(i0)) +#define NV30_3D_TEX_FILTER__ESIZE 0x00000020 +#define NV30_3D_TEX_FILTER__LEN 0x00000008 +#define NV30_3D_TEX_FILTER_LOD_BIAS__MASK 0x00000f00 +#define NV30_3D_TEX_FILTER_LOD_BIAS__SHIFT 8 +#define NV30_3D_TEX_FILTER_MIN__MASK 0x000f0000 +#define NV30_3D_TEX_FILTER_MIN__SHIFT 16 +#define NV30_3D_TEX_FILTER_MIN_NEAREST 0x00010000 +#define NV30_3D_TEX_FILTER_MIN_LINEAR 0x00020000 +#define NV30_3D_TEX_FILTER_MIN_NEAREST_MIPMAP_NEAREST 0x00030000 +#define NV30_3D_TEX_FILTER_MIN_LINEAR_MIPMAP_NEAREST 0x00040000 +#define NV30_3D_TEX_FILTER_MIN_NEAREST_MIPMAP_LINEAR 0x00050000 +#define NV30_3D_TEX_FILTER_MIN_LINEAR_MIPMAP_LINEAR 0x00060000 +#define NV30_3D_TEX_FILTER_MAG__MASK 0x0f000000 +#define NV30_3D_TEX_FILTER_MAG__SHIFT 24 +#define NV30_3D_TEX_FILTER_MAG_NEAREST 0x01000000 +#define NV30_3D_TEX_FILTER_MAG_LINEAR 0x02000000 +#define NV30_3D_TEX_FILTER_SIGNED_BLUE 0x10000000 +#define NV30_3D_TEX_FILTER_SIGNED_GREEN 0x20000000 +#define NV30_3D_TEX_FILTER_SIGNED_RED 0x40000000 +#define NV30_3D_TEX_FILTER_SIGNED_ALPHA 0x80000000 + +#define NV30_3D_TEX_NPOT_SIZE(i0) (0x00001a18 + 0x20*(i0)) +#define NV30_3D_TEX_NPOT_SIZE__ESIZE 0x00000020 +#define NV30_3D_TEX_NPOT_SIZE__LEN 0x00000008 +#define NV30_3D_TEX_NPOT_SIZE_H__MASK 0x0000ffff +#define NV30_3D_TEX_NPOT_SIZE_H__SHIFT 0 +#define NV30_3D_TEX_NPOT_SIZE_W__MASK 0xffff0000 +#define NV30_3D_TEX_NPOT_SIZE_W__SHIFT 16 + +#define NV30_3D_TEX_BORDER_COLOR(i0) (0x00001a1c + 0x20*(i0)) +#define NV30_3D_TEX_BORDER_COLOR__ESIZE 0x00000020 +#define NV30_3D_TEX_BORDER_COLOR__LEN 0x00000008 +#define NV30_3D_TEX_BORDER_COLOR_B__MASK 0x000000ff +#define NV30_3D_TEX_BORDER_COLOR_B__SHIFT 0 +#define NV30_3D_TEX_BORDER_COLOR_G__MASK 0x0000ff00 +#define NV30_3D_TEX_BORDER_COLOR_G__SHIFT 8 +#define NV30_3D_TEX_BORDER_COLOR_R__MASK 0x00ff0000 +#define NV30_3D_TEX_BORDER_COLOR_R__SHIFT 16 +#define NV30_3D_TEX_BORDER_COLOR_A__MASK 0xff000000 +#define NV30_3D_TEX_BORDER_COLOR_A__SHIFT 24 + +#define NV30_3D_VTX_ATTR_4F(i0) (0x00001c00 + 0x10*(i0)) +#define NV30_3D_VTX_ATTR_4F__ESIZE 0x00000010 +#define NV30_3D_VTX_ATTR_4F__LEN 0x00000010 + + +#define NV30_3D_VTX_ATTR_4F_X(i0) (0x00001c00 + 0x10*(i0)) + +#define NV30_3D_VTX_ATTR_4F_Y(i0) (0x00001c04 + 0x10*(i0)) + +#define NV30_3D_VTX_ATTR_4F_Z(i0) (0x00001c08 + 0x10*(i0)) + +#define NV30_3D_VTX_ATTR_4F_W(i0) (0x00001c0c + 0x10*(i0)) + +#define NV30_3D_FP_CONTROL 0x00001d60 +#define NV30_3D_FP_CONTROL_USED_REGS_MINUS1_DIV2__MASK 0x0000000f +#define NV30_3D_FP_CONTROL_USED_REGS_MINUS1_DIV2__SHIFT 0 +#define NV30_3D_FP_CONTROL_USES_KIL 0x00000080 +#define NV40_3D_FP_CONTROL_KIL 0x00000080 +#define NV40_3D_FP_CONTROL_TEMP_COUNT__MASK 0xff000000 +#define NV40_3D_FP_CONTROL_TEMP_COUNT__SHIFT 24 + +#define NV30_3D_DEPTH_CONTROL 0x00001d78 +#define NV30_3D_DEPTH_CONTROL_CLAMP 0x000000f0 + +#define NV30_3D_MULTISAMPLE_CONTROL 0x00001d7c +#define NV30_3D_MULTISAMPLE_CONTROL_ENABLE 0x00000001 +#define NV30_3D_MULTISAMPLE_CONTROL_SAMPLE_ALPHA_TO_COVERAGE 0x00000010 +#define NV30_3D_MULTISAMPLE_CONTROL_SAMPLE_ALPHA_TO_ONE 0x00000100 +#define NV30_3D_MULTISAMPLE_CONTROL_SAMPLE_COVERAGE__MASK 0xffff0000 +#define NV30_3D_MULTISAMPLE_CONTROL_SAMPLE_COVERAGE__SHIFT 16 + +#define NV30_3D_COORD_CONVENTIONS 0x00001d88 +#define NV30_3D_COORD_CONVENTIONS_HEIGHT__MASK 0x00000fff +#define NV30_3D_COORD_CONVENTIONS_HEIGHT__SHIFT 0 +#define NV30_3D_COORD_CONVENTIONS_ORIGIN__MASK 0x00001000 +#define NV30_3D_COORD_CONVENTIONS_ORIGIN__SHIFT 12 +#define NV30_3D_COORD_CONVENTIONS_ORIGIN_NORMAL 0x00000000 +#define NV30_3D_COORD_CONVENTIONS_ORIGIN_INVERTED 0x00001000 +#define NV30_3D_COORD_CONVENTIONS_CENTER__MASK 0x00010000 +#define NV30_3D_COORD_CONVENTIONS_CENTER__SHIFT 16 +#define NV30_3D_COORD_CONVENTIONS_CENTER_HALF_INTEGER 0x00000000 +#define NV30_3D_COORD_CONVENTIONS_CENTER_INTEGER 0x00010000 + +#define NV30_3D_CLEAR_DEPTH_VALUE 0x00001d8c + +#define NV30_3D_CLEAR_COLOR_VALUE 0x00001d90 +#define NV30_3D_CLEAR_COLOR_VALUE_B__MASK 0x000000ff +#define NV30_3D_CLEAR_COLOR_VALUE_B__SHIFT 0 +#define NV30_3D_CLEAR_COLOR_VALUE_G__MASK 0x0000ff00 +#define NV30_3D_CLEAR_COLOR_VALUE_G__SHIFT 8 +#define NV30_3D_CLEAR_COLOR_VALUE_R__MASK 0x00ff0000 +#define NV30_3D_CLEAR_COLOR_VALUE_R__SHIFT 16 +#define NV30_3D_CLEAR_COLOR_VALUE_A__MASK 0xff000000 +#define NV30_3D_CLEAR_COLOR_VALUE_A__SHIFT 24 + +#define NV30_3D_CLEAR_BUFFERS 0x00001d94 +#define NV30_3D_CLEAR_BUFFERS_DEPTH 0x00000001 +#define NV30_3D_CLEAR_BUFFERS_STENCIL 0x00000002 +#define NV30_3D_CLEAR_BUFFERS_COLOR_R 0x00000010 +#define NV30_3D_CLEAR_BUFFERS_COLOR_G 0x00000020 +#define NV30_3D_CLEAR_BUFFERS_COLOR_B 0x00000040 +#define NV30_3D_CLEAR_BUFFERS_COLOR_A 0x00000080 + +#define NV30_3D_DO_VERTICES 0x00001dac + +#define NV30_3D_LINE_STIPPLE_ENABLE 0x00001db4 + +#define NV30_3D_LINE_STIPPLE_PATTERN 0x00001db8 +#define NV30_3D_LINE_STIPPLE_PATTERN_FACTOR__MASK 0x0000ffff +#define NV30_3D_LINE_STIPPLE_PATTERN_FACTOR__SHIFT 0 +#define NV30_3D_LINE_STIPPLE_PATTERN_PATTERN__MASK 0xffff0000 +#define NV30_3D_LINE_STIPPLE_PATTERN_PATTERN__SHIFT 16 + +#define NV30_3D_BACK_MATERIAL_SHININESS(i0) (0x00001e20 + 0x4*(i0)) +#define NV30_3D_BACK_MATERIAL_SHININESS__ESIZE 0x00000004 +#define NV30_3D_BACK_MATERIAL_SHININESS__LEN 0x00000006 + +#define NV30_3D_VTX_ATTR_1F(i0) (0x00001e40 + 0x4*(i0)) +#define NV30_3D_VTX_ATTR_1F__ESIZE 0x00000004 +#define NV30_3D_VTX_ATTR_1F__LEN 0x00000010 + +#define NV30_3D_ENGINE 0x00001e94 +#define NV30_3D_ENGINE_FP 0x00000001 +#define NV30_3D_ENGINE_VP 0x00000002 +#define NV30_3D_ENGINE_FIXED 0x00000004 + +#define NV30_3D_VP_UPLOAD_FROM_ID 0x00001e9c + +#define NV30_3D_VP_START_FROM_ID 0x00001ea0 + +#define NV30_3D_POINT_PARAMETERS(i0) (0x00001ec0 + 0x4*(i0)) +#define NV30_3D_POINT_PARAMETERS__ESIZE 0x00000004 +#define NV30_3D_POINT_PARAMETERS__LEN 0x00000008 + +#define NV30_3D_POINT_SIZE 0x00001ee0 + +#define NV30_3D_POINT_PARAMETERS_ENABLE 0x00001ee4 + +#define NV30_3D_POINT_SPRITE 0x00001ee8 +#define NV30_3D_POINT_SPRITE_ENABLE 0x00000001 +#define NV30_3D_POINT_SPRITE_R_MODE__MASK 0x00000006 +#define NV30_3D_POINT_SPRITE_R_MODE__SHIFT 1 +#define NV30_3D_POINT_SPRITE_R_MODE_ZERO 0x00000000 +#define NV30_3D_POINT_SPRITE_R_MODE_R 0x00000002 +#define NV30_3D_POINT_SPRITE_R_MODE_S 0x00000004 +#define NV30_3D_POINT_SPRITE_COORD_REPLACE_0 0x00000100 +#define NV30_3D_POINT_SPRITE_COORD_REPLACE_1 0x00000200 +#define NV30_3D_POINT_SPRITE_COORD_REPLACE_2 0x00000400 +#define NV30_3D_POINT_SPRITE_COORD_REPLACE_3 0x00000800 +#define NV30_3D_POINT_SPRITE_COORD_REPLACE_4 0x00001000 +#define NV30_3D_POINT_SPRITE_COORD_REPLACE_5 0x00002000 +#define NV30_3D_POINT_SPRITE_COORD_REPLACE_6 0x00004000 +#define NV30_3D_POINT_SPRITE_COORD_REPLACE_7 0x00008000 + +#define NV30_3D_VP_UPLOAD_CONST_ID 0x00001efc + +#define NV30_3D_VP_UPLOAD_CONST(i0) (0x00001f00 + 0x10*(i0)) +#define NV30_3D_VP_UPLOAD_CONST__ESIZE 0x00000010 +#define NV30_3D_VP_UPLOAD_CONST__LEN 0x00000004 + + +#define NV30_3D_VP_UPLOAD_CONST_X(i0) (0x00001f00 + 0x10*(i0)) + +#define NV30_3D_VP_UPLOAD_CONST_Y(i0) (0x00001f04 + 0x10*(i0)) + +#define NV30_3D_VP_UPLOAD_CONST_Z(i0) (0x00001f08 + 0x10*(i0)) + +#define NV30_3D_VP_UPLOAD_CONST_W(i0) (0x00001f0c + 0x10*(i0)) + +#define NV30_3D_UNK1F80(i0) (0x00001f80 + 0x4*(i0)) +#define NV30_3D_UNK1F80__ESIZE 0x00000004 +#define NV30_3D_UNK1F80__LEN 0x00000010 + +#define NV40_3D_TEX_CACHE_CTL 0x00001fd8 + +#define NV40_3D_VP_ATTRIB_EN 0x00001ff0 + +#define NV40_3D_VP_RESULT_EN 0x00001ff4 + + +#endif /* NV30_40_3D_XML */ diff --git a/src/gallium/drivers/nvfx/nv30_fragtex.c b/src/gallium/drivers/nvfx/nv30_fragtex.c new file mode 100644 index 0000000..951fb20 --- /dev/null +++ b/src/gallium/drivers/nvfx/nv30_fragtex.c @@ -0,0 +1,119 @@ +#include "util/u_format.h" + +#include "nvfx_context.h" +#include "nvfx_tex.h" +#include "nvfx_resource.h" + +void +nv30_sampler_state_init(struct pipe_context *pipe, + struct nvfx_sampler_state *ps, + const struct pipe_sampler_state *cso) +{ + float limit; + + if (cso->max_anisotropy >= 2) + { + if (cso->max_anisotropy >= 8) + ps->en |= NV30_3D_TEX_ENABLE_ANISO_8X; + else if (cso->max_anisotropy >= 4) + ps->en |= NV30_3D_TEX_ENABLE_ANISO_4X; + else if (cso->max_anisotropy >= 2) + ps->en |= NV30_3D_TEX_ENABLE_ANISO_2X; + } + + limit = CLAMP(cso->lod_bias, -16.0, 15.0 + (255.0 / 256.0)); + ps->filt |= (int)(cso->lod_bias * 256.0) & 0x1fff; + + ps->max_lod = (int)CLAMP(cso->max_lod, 0.0, 15.0); + ps->min_lod = (int)CLAMP(cso->min_lod, 0.0, 15.0); + + ps->en |= NV30_3D_TEX_ENABLE_ENABLE; +} + +void +nv30_sampler_view_init(struct pipe_context *pipe, + struct nvfx_sampler_view *sv) +{ + struct pipe_resource* pt = sv->base.texture; + struct nvfx_texture_format *tf = &nvfx_texture_formats[sv->base.format]; + unsigned txf; + unsigned level = pt->target == PIPE_TEXTURE_CUBE ? 0 : sv->base.u.tex.first_level; + + assert(tf->fmt[0] >= 0); + + txf = sv->u.init_fmt; + txf |= (level != sv->base.u.tex.last_level ? NV30_3D_TEX_FORMAT_MIPMAP : 0); + txf |= util_logbase2(u_minify(pt->width0, level)) << NV30_3D_TEX_FORMAT_BASE_SIZE_U__SHIFT; + txf |= util_logbase2(u_minify(pt->height0, level)) << NV30_3D_TEX_FORMAT_BASE_SIZE_V__SHIFT; + txf |= util_logbase2(u_minify(pt->depth0, level)) << NV30_3D_TEX_FORMAT_BASE_SIZE_W__SHIFT; + txf |= 0x10000; + + sv->u.nv30.fmt[0] = tf->fmt[0] | txf; + sv->u.nv30.fmt[1] = tf->fmt[1] | txf; + sv->u.nv30.fmt[2] = tf->fmt[2] | txf; + sv->u.nv30.fmt[3] = tf->fmt[3] | txf; + + sv->swizzle |= (nvfx_subresource_pitch(pt, 0) << NV30_3D_TEX_SWIZZLE_RECT_PITCH__SHIFT); + + if(pt->height0 <= 1 || util_format_is_compressed(sv->base.format)) + sv->u.nv30.rect = -1; + else + sv->u.nv30.rect = !!(pt->flags & NVFX_RESOURCE_FLAG_LINEAR); + + sv->lod_offset = sv->base.u.tex.first_level - level; + sv->max_lod_limit = sv->base.u.tex.last_level - level; +} + +void +nv30_fragtex_set(struct nvfx_context *nvfx, int unit) +{ + struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit]; + struct nvfx_sampler_view* sv = (struct nvfx_sampler_view*)nvfx->fragment_sampler_views[unit]; + struct nouveau_bo *bo = ((struct nvfx_miptree *)sv->base.texture)->base.bo; + struct nouveau_channel* chan = nvfx->screen->base.channel; + unsigned txf; + unsigned tex_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD; + unsigned use_rect; + unsigned max_lod = MIN2(ps->max_lod + sv->lod_offset, sv->max_lod_limit); + unsigned min_lod = MIN2(ps->min_lod + sv->lod_offset, max_lod) ; + + if(sv->u.nv30.rect < 0) + { + /* in the case of compressed or 1D textures, we can get away with this, + * since the layout is the same + */ + use_rect = ps->fmt; + } + else + { + static boolean warned = FALSE; + if( !!ps->fmt != sv->u.nv30.rect && !warned) { + warned = TRUE; + fprintf(stderr, + "Unimplemented: coordinate normalization mismatch. Possible reasons:\n" + "1. ARB_texture_non_power_of_two is being used despite the fact it isn't supported\n" + "2. The state tracker is not using the appropriate coordinate normalization\n" + "3. The state tracker is not supported\n"); + } + + use_rect = sv->u.nv30.rect; + } + + txf = sv->u.nv30.fmt[ps->compare + (use_rect ? 2 : 0)]; + + MARK_RING(chan, 9, 2); + OUT_RING(chan, RING_3D(NV30_3D_TEX_OFFSET(unit), 8)); + OUT_RELOC(chan, bo, sv->offset, tex_flags | NOUVEAU_BO_LOW, 0, 0); + OUT_RELOC(chan, bo, txf, + tex_flags | NOUVEAU_BO_OR, + NV30_3D_TEX_FORMAT_DMA0, NV30_3D_TEX_FORMAT_DMA1); + OUT_RING(chan, (ps->wrap & sv->wrap_mask) | sv->wrap); + OUT_RING(chan, ps->en | (min_lod << NV30_3D_TEX_ENABLE_MIPMAP_MIN_LOD__SHIFT) | (max_lod << NV30_3D_TEX_ENABLE_MIPMAP_MAX_LOD__SHIFT)); + OUT_RING(chan, sv->swizzle); + OUT_RING(chan, ps->filt | sv->filt); + OUT_RING(chan, sv->npot_size); + OUT_RING(chan, ps->bcol); + + nvfx->hw_txf[unit] = txf; + nvfx->hw_samplers |= (1 << unit); +} diff --git a/src/gallium/drivers/nvfx/nv30_vertprog.h b/src/gallium/drivers/nvfx/nv30_vertprog.h new file mode 100644 index 0000000..e8c16b0 --- /dev/null +++ b/src/gallium/drivers/nvfx/nv30_vertprog.h @@ -0,0 +1,176 @@ +#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 */ + +/* guess that this is the same as nv40 */ +#define NV30_VP_INST_INDEX_INPUT (1 << 27) + +#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 (0x1F << 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 (0x1FF << 2) /* 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 (0x1F << 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)) +# define NV30_VP_INST_DEST_CLP(n) (17 + (n)) + +/* guess that this is the same as nv40 */ +#define NV30_VP_INST_INDEX_CONST (1 << 1) + +/* 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 0000000..e8ab403 --- /dev/null +++ b/src/gallium/drivers/nvfx/nv40_fragtex.c @@ -0,0 +1,105 @@ +#include "util/u_format.h" +#include "nvfx_context.h" +#include "nvfx_tex.h" +#include "nvfx_resource.h" + +void +nv40_sampler_state_init(struct pipe_context *pipe, + struct nvfx_sampler_state *ps, + const struct pipe_sampler_state *cso) +{ + float limit; + 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 |= NV40_3D_TEX_ENABLE_ANISO_16X; + else if (cso->max_anisotropy >= 12) + ps->en |= NV40_3D_TEX_ENABLE_ANISO_12X; + else if (cso->max_anisotropy >= 10) + ps->en |= NV40_3D_TEX_ENABLE_ANISO_10X; + else if (cso->max_anisotropy >= 8) + ps->en |= NV40_3D_TEX_ENABLE_ANISO_8X; + else if (cso->max_anisotropy >= 6) + ps->en |= NV40_3D_TEX_ENABLE_ANISO_6X; + else if (cso->max_anisotropy >= 4) + ps->en |= NV40_3D_TEX_ENABLE_ANISO_4X; + else + ps->en |= NV40_3D_TEX_ENABLE_ANISO_2X; + } + + limit = CLAMP(cso->lod_bias, -16.0, 15.0 + (255.0 / 256.0)); + ps->filt |= (int)(cso->lod_bias * 256.0) & 0x1fff; + + ps->max_lod = (int)(CLAMP(cso->max_lod, 0.0, 15.0 + (255.0 / 256.0)) * 256.0); + ps->min_lod = (int)(CLAMP(cso->min_lod, 0.0, 15.0 + (255.0 / 256.0)) * 256.0); + + ps->en |= NV40_3D_TEX_ENABLE_ENABLE; +} + +void +nv40_sampler_view_init(struct pipe_context *pipe, + struct nvfx_sampler_view *sv) +{ + struct pipe_resource* pt = sv->base.texture; + struct nvfx_miptree* mt = (struct nvfx_miptree*)pt; + struct nvfx_texture_format *tf = &nvfx_texture_formats[sv->base.format]; + unsigned txf; + unsigned level = pt->target == PIPE_TEXTURE_CUBE ? 0 : sv->base.u.tex.first_level; + assert(tf->fmt[4] >= 0); + + txf = sv->u.init_fmt; + txf |= 0x8000; + if(pt->target == PIPE_TEXTURE_CUBE) + txf |= ((pt->last_level + 1) << NV40_3D_TEX_FORMAT_MIPMAP_COUNT__SHIFT); + else + txf |= (((sv->base.u.tex.last_level - sv->base.u.tex.first_level) + 1) << NV40_3D_TEX_FORMAT_MIPMAP_COUNT__SHIFT); + + if (!mt->linear_pitch) + sv->u.nv40.npot_size2 = 0; + else { + sv->u.nv40.npot_size2 = mt->linear_pitch; + txf |= NV40_3D_TEX_FORMAT_LINEAR; + } + + sv->u.nv40.fmt[0] = tf->fmt[4] | txf; + sv->u.nv40.fmt[1] = tf->fmt[5] | txf; + + sv->u.nv40.npot_size2 |= (u_minify(pt->depth0, level) << NV40_3D_TEX_SIZE1_DEPTH__SHIFT); + + sv->lod_offset = (sv->base.u.tex.first_level - level) * 256; + sv->max_lod_limit = (sv->base.u.tex.last_level - level) * 256; +} + +void +nv40_fragtex_set(struct nvfx_context *nvfx, int unit) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit]; + struct nvfx_sampler_view* sv = (struct nvfx_sampler_view*)nvfx->fragment_sampler_views[unit]; + struct nouveau_bo *bo = ((struct nvfx_miptree *)sv->base.texture)->base.bo; + unsigned tex_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD; + unsigned txf; + unsigned max_lod = MIN2(ps->max_lod + sv->lod_offset, sv->max_lod_limit); + unsigned min_lod = MIN2(ps->min_lod + sv->lod_offset, max_lod); + + txf = sv->u.nv40.fmt[ps->compare] | ps->fmt; + + MARK_RING(chan, 11, 2); + OUT_RING(chan, RING_3D(NV30_3D_TEX_OFFSET(unit), 8)); + OUT_RELOC(chan, bo, sv->offset, tex_flags | NOUVEAU_BO_LOW, 0, 0); + OUT_RELOC(chan, bo, txf, tex_flags | NOUVEAU_BO_OR, + NV30_3D_TEX_FORMAT_DMA0, NV30_3D_TEX_FORMAT_DMA1); + OUT_RING(chan, (ps->wrap & sv->wrap_mask) | sv->wrap); + OUT_RING(chan, ps->en | (min_lod << 19) | (max_lod << 7)); + OUT_RING(chan, sv->swizzle); + OUT_RING(chan, ps->filt | sv->filt); + OUT_RING(chan, sv->npot_size); + OUT_RING(chan, ps->bcol); + OUT_RING(chan, RING_3D(NV40_3D_TEX_SIZE1(unit), 1)); + OUT_RING(chan, sv->u.nv40.npot_size2); + + nvfx->hw_txf[unit] = txf; + nvfx->hw_samplers |= (1 << unit); +} diff --git a/src/gallium/drivers/nvfx/nv40_vertprog.h b/src/gallium/drivers/nvfx/nv40_vertprog.h new file mode 100644 index 0000000..c1f2208 --- /dev/null +++ b/src/gallium/drivers/nvfx/nv40_vertprog.h @@ -0,0 +1,178 @@ +#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_SATURATE (1 << 26) +#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 (0x3F << 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 (0x3F << 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_buffer.c b/src/gallium/drivers/nvfx/nvfx_buffer.c new file mode 100644 index 0000000..b407429 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_buffer.c @@ -0,0 +1,97 @@ + +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_math.h" + +#include "nouveau/nouveau_screen.h" +#include "nouveau/nouveau_winsys.h" +#include "nvfx_resource.h" +#include "nvfx_screen.h" + +void nvfx_buffer_destroy(struct pipe_screen *pscreen, + struct pipe_resource *presource) +{ + struct nvfx_buffer *buffer = nvfx_buffer(presource); + + if(!(buffer->base.base.flags & NVFX_RESOURCE_FLAG_USER)) + align_free(buffer->data); + nouveau_screen_bo_release(pscreen, buffer->base.bo); + FREE(buffer); +} + +struct pipe_resource * +nvfx_buffer_create(struct pipe_screen *pscreen, + const struct pipe_resource *template) +{ + struct nvfx_screen* screen = nvfx_screen(pscreen); + struct nvfx_buffer* buffer; + + buffer = CALLOC_STRUCT(nvfx_buffer); + if (!buffer) + return NULL; + + buffer->base.base = *template; + buffer->base.base.flags |= NVFX_RESOURCE_FLAG_LINEAR; + pipe_reference_init(&buffer->base.base.reference, 1); + buffer->base.base.screen = pscreen; + buffer->size = util_format_get_stride(template->format, template->width0); + buffer->bytes_to_draw_until_static = buffer->size * screen->static_reuse_threshold; + buffer->data = align_malloc(buffer->size, 16); + + return &buffer->base.base; +} + + +struct pipe_resource * +nvfx_user_buffer_create(struct pipe_screen *pscreen, + void *ptr, + unsigned bytes, + unsigned usage) +{ + struct nvfx_screen* screen = nvfx_screen(pscreen); + struct nvfx_buffer* buffer; + + buffer = CALLOC_STRUCT(nvfx_buffer); + if (!buffer) + return NULL; + + pipe_reference_init(&buffer->base.base.reference, 1); + buffer->base.base.flags = NVFX_RESOURCE_FLAG_LINEAR | NVFX_RESOURCE_FLAG_USER; + buffer->base.base.screen = pscreen; + buffer->base.base.format = PIPE_FORMAT_R8_UNORM; + buffer->base.base.usage = PIPE_USAGE_IMMUTABLE; + buffer->base.base.bind = usage; + buffer->base.base.width0 = bytes; + buffer->base.base.height0 = 1; + buffer->base.base.depth0 = 1; + buffer->base.base.array_size = 1; + buffer->data = ptr; + buffer->size = bytes; + buffer->bytes_to_draw_until_static = bytes * screen->static_reuse_threshold; + buffer->dirty_end = bytes; + + return &buffer->base.base; +} + +void nvfx_buffer_upload(struct nvfx_buffer* buffer) +{ + unsigned dirty = buffer->dirty_end - buffer->dirty_begin; + if(!buffer->base.bo) + { + buffer->base.bo = nouveau_screen_bo_new(buffer->base.base.screen, + 16, + buffer->base.base.usage, + buffer->base.base.bind, + buffer->base.base.width0); + } + + if(dirty) + { + // TODO: may want to use a temporary in some cases + nouveau_bo_map(buffer->base.bo, NOUVEAU_BO_WR + | (buffer->dirty_unsynchronized ? NOUVEAU_BO_NOSYNC : 0)); + memcpy((uint8_t*)buffer->base.bo->map + buffer->dirty_begin, buffer->data + buffer->dirty_begin, dirty); + nouveau_bo_unmap(buffer->base.bo); + buffer->dirty_begin = buffer->dirty_end = 0; + } +} diff --git a/src/gallium/drivers/nvfx/nvfx_clear.c b/src/gallium/drivers/nvfx/nvfx_clear.c new file mode 100644 index 0000000..2be70fc --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_clear.c @@ -0,0 +1,14 @@ +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" +#include "util/u_clear.h" + +#include "nvfx_context.h" + +void +nvfx_clear(struct pipe_context *pipe, unsigned buffers, + const float *rgba, double depth, unsigned stencil) +{ + util_clear(pipe, &nvfx_context(pipe)->framebuffer, buffers, rgba, depth, + stencil); +} diff --git a/src/gallium/drivers/nvfx/nvfx_context.c b/src/gallium/drivers/nvfx/nvfx_context.c new file mode 100644 index 0000000..95834d2 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_context.c @@ -0,0 +1,113 @@ +#include "draw/draw_context.h" +#include "pipe/p_defines.h" +#include "util/u_framebuffer.h" + +#include "nvfx_context.h" +#include "nvfx_screen.h" +#include "nvfx_resource.h" + +static void +nvfx_flush(struct pipe_context *pipe, unsigned flags, + struct pipe_fence_handle **fence) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + struct nvfx_screen *screen = nvfx->screen; + struct nouveau_channel *chan = screen->base.channel; + + /* XXX: we need to actually be intelligent here */ + if (flags & PIPE_FLUSH_TEXTURE_CACHE) { + WAIT_RING(chan, 4); + OUT_RING(chan, RING_3D(0x1fd8, 1)); + OUT_RING(chan, 2); + OUT_RING(chan, RING_3D(0x1fd8, 1)); + OUT_RING(chan, 1); + } + + FIRE_RING(chan); + if (fence) + *fence = NULL; +} + +static void +nvfx_destroy(struct pipe_context *pipe) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + if(nvfx->dummy_fs) + pipe->delete_fs_state(pipe, nvfx->dummy_fs); + + for(unsigned i = 0; i < nvfx->vtxbuf_nr; ++i) + pipe_resource_reference(&nvfx->vtxbuf[i].buffer, 0); + pipe_resource_reference(&nvfx->idxbuf.buffer, 0); + util_unreference_framebuffer_state(&nvfx->framebuffer); + for(unsigned i = 0; i < PIPE_MAX_SAMPLERS; ++i) + pipe_sampler_view_reference(&nvfx->fragment_sampler_views[i], 0); + + if (nvfx->draw) + draw_destroy(nvfx->draw); + + if(nvfx->screen->cur_ctx == nvfx) + nvfx->screen->cur_ctx = NULL; + + FREE(nvfx); +} + +struct pipe_context * +nvfx_create(struct pipe_screen *pscreen, void *priv) +{ + struct nvfx_screen *screen = nvfx_screen(pscreen); + struct pipe_winsys *ws = pscreen->winsys; + struct nvfx_context *nvfx; + struct nouveau_winsys *nvws = screen->nvws; + + nvfx = CALLOC(1, sizeof(struct nvfx_context)); + if (!nvfx) + return NULL; + nvfx->screen = screen; + + nvfx->nvws = nvws; + + nvfx->pipe.winsys = ws; + nvfx->pipe.screen = pscreen; + nvfx->pipe.priv = priv; + nvfx->pipe.destroy = nvfx_destroy; + nvfx->pipe.draw_vbo = nvfx_draw_vbo; + nvfx->pipe.clear = nvfx_clear; + nvfx->pipe.flush = nvfx_flush; + + nvfx->is_nv4x = screen->is_nv4x; + nvfx->use_nv4x = screen->use_nv4x; + /* TODO: it seems that nv30 might have fixed function clipping usable with vertex programs + * However, my code for that doesn't work, so use vp clipping for all cards, which works. + */ + nvfx->use_vp_clipping = TRUE; + + nvfx_init_query_functions(nvfx); + nvfx_init_surface_functions(nvfx); + nvfx_init_state_functions(nvfx); + nvfx_init_sampling_functions(nvfx); + nvfx_init_vbo_functions(nvfx); + nvfx_init_fragprog_functions(nvfx); + nvfx_init_vertprog_functions(nvfx); + nvfx_init_resource_functions(&nvfx->pipe); + nvfx_init_transfer_functions(&nvfx->pipe); + + /* Create, configure, and install fallback swtnl path */ + nvfx->draw = draw_create(&nvfx->pipe); + draw_wide_point_threshold(nvfx->draw, 9999999.0); + draw_wide_line_threshold(nvfx->draw, 9999999.0); + draw_enable_line_stipple(nvfx->draw, FALSE); + draw_enable_point_sprites(nvfx->draw, FALSE); + draw_set_rasterize_stage(nvfx->draw, nvfx_draw_render_stage(nvfx)); + + /* set these to that we init them on first validation */ + nvfx->state.scissor_enabled = ~0; + nvfx->hw_pointsprite_control = -1; + nvfx->hw_vp_output = -1; + nvfx->use_vertex_buffers = -1; + nvfx->relocs_needed = NVFX_RELOCATE_ALL; + + LIST_INITHEAD(&nvfx->render_cache); + + return &nvfx->pipe; +} diff --git a/src/gallium/drivers/nvfx/nvfx_context.h b/src/gallium/drivers/nvfx/nvfx_context.h new file mode 100644 index 0000000..6ef2a69 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_context.h @@ -0,0 +1,371 @@ +#ifndef __NVFX_CONTEXT_H__ +#define __NVFX_CONTEXT_H__ + +#include + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" +#include "pipe/p_compiler.h" + +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_inlines.h" +#include "util/u_double_list.h" + +#include "draw/draw_vertex.h" +#include "util/u_blitter.h" + +#include "nouveau/nouveau_winsys.h" +#include "nouveau/nouveau_gldefs.h" +#include "nv30-40_3d.xml.h" +#include "nvfx_state.h" + +#define NOUVEAU_ERR(fmt, args...) \ + fprintf(stderr, "%s:%d - "fmt, __func__, __LINE__, ##args); +#define NOUVEAU_MSG(fmt, args...) \ + fprintf(stderr, "nouveau: "fmt, ##args); + +#include "nvfx_screen.h" + +#define NVFX_NEW_BLEND (1 << 0) +#define NVFX_NEW_RAST (1 << 1) +#define NVFX_NEW_ZSA (1 << 2) +#define NVFX_NEW_SAMPLER (1 << 3) +#define NVFX_NEW_FB (1 << 4) +#define NVFX_NEW_STIPPLE (1 << 5) +#define NVFX_NEW_SCISSOR (1 << 6) +#define NVFX_NEW_VIEWPORT (1 << 7) +#define NVFX_NEW_BCOL (1 << 8) +#define NVFX_NEW_VERTPROG (1 << 9) +#define NVFX_NEW_FRAGPROG (1 << 10) +#define NVFX_NEW_ARRAYS (1 << 11) +#define NVFX_NEW_UCP (1 << 12) +#define NVFX_NEW_SR (1 << 13) +#define NVFX_NEW_VERTCONST (1 << 14) +#define NVFX_NEW_FRAGCONST (1 << 15) +#define NVFX_NEW_INDEX (1 << 16) +#define NVFX_NEW_SPRITE (1 << 17) + +#define NVFX_RELOCATE_FRAMEBUFFER (1 << 0) +#define NVFX_RELOCATE_FRAGTEX (1 << 1) +#define NVFX_RELOCATE_FRAGPROG (1 << 2) +#define NVFX_RELOCATE_VTXBUF (1 << 3) +#define NVFX_RELOCATE_IDXBUF (1 << 4) +#define NVFX_RELOCATE_ALL 0x1f + +struct nvfx_rasterizer_state { + struct pipe_rasterizer_state pipe; + unsigned sb_len; + uint32_t sb[34]; +}; + +struct nvfx_zsa_state { + struct pipe_depth_stencil_alpha_state pipe; + unsigned sb_len; + uint32_t sb[24]; +}; + +struct nvfx_blend_state { + struct pipe_blend_state pipe; + unsigned sb_len; + uint32_t sb[13]; +}; + + +struct nvfx_state { + unsigned scissor_enabled; + unsigned fp_samplers; + unsigned render_temps; +}; + +struct nvfx_per_vertex_element { + unsigned idx; + unsigned vertex_buffer_index; + unsigned src_offset; +}; + +struct nvfx_low_frequency_element { + unsigned idx; + unsigned vertex_buffer_index; + unsigned src_offset; + void (*fetch_rgba_float)(float *dst, const uint8_t *src, unsigned i, unsigned j); + unsigned ncomp; +}; + +struct nvfx_per_instance_element { + struct nvfx_low_frequency_element base; + unsigned instance_divisor; +}; + +struct nvfx_per_vertex_buffer_info +{ + unsigned vertex_buffer_index; + unsigned per_vertex_size; +}; + +struct nvfx_vtxelt_state { + struct pipe_vertex_element pipe[16]; + unsigned num_elements; + unsigned vtxfmt[16]; + + unsigned num_per_vertex_buffer_infos; + struct nvfx_per_vertex_buffer_info per_vertex_buffer_info[16]; + + unsigned num_per_vertex; + struct nvfx_per_vertex_element per_vertex[16]; + + unsigned num_per_instance; + struct nvfx_per_instance_element per_instance[16]; + + unsigned num_constant; + struct nvfx_low_frequency_element constant[16]; + + boolean needs_translate; + struct translate* translate; + + unsigned vertex_length; + unsigned max_vertices_per_packet; +}; + +struct nvfx_render_target { + struct nouveau_bo* bo; + unsigned offset; + unsigned pitch; +}; + +struct nvfx_context { + struct pipe_context pipe; + + struct nouveau_winsys *nvws; + struct nvfx_screen *screen; + + unsigned is_nv4x; /* either 0 or ~0 */ + unsigned use_nv4x; /* either 0 or ~0 */ + boolean use_vp_clipping; + + struct draw_context *draw; + /* one is for user-requested operations, the other is for temporary copying inside them */ + struct blitter_context* blitter[2]; + unsigned blitters_in_use; + struct list_head render_cache; + + /* HW state derived from pipe states */ + struct nvfx_state state; + + enum { + HW, SWTNL, SWRAST + } render_mode; + unsigned fallback_swtnl; + + /* Context state */ + unsigned dirty, draw_dirty; + struct pipe_scissor_state scissor; + unsigned stipple[32]; + struct pipe_clip_state clip; + struct nvfx_pipe_vertex_program *vertprog; + struct nvfx_pipe_fragment_program *fragprog; + struct pipe_resource *constbuf[PIPE_SHADER_TYPES]; + unsigned constbuf_nr[PIPE_SHADER_TYPES]; + struct nvfx_rasterizer_state *rasterizer; + struct nvfx_zsa_state *zsa; + struct nvfx_blend_state *blend; + struct pipe_blend_color blend_colour; + struct pipe_stencil_ref stencil_ref; + struct pipe_viewport_state viewport; + struct pipe_framebuffer_state framebuffer; + struct pipe_index_buffer idxbuf; + struct nvfx_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; + struct nvfx_pipe_fragment_program* dummy_fs; + struct pipe_query* query; + + unsigned nr_samplers; + unsigned nr_textures; + unsigned dirty_samplers; + struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS]; + unsigned vtxbuf_nr; + struct nvfx_vtxelt_state *vtxelt; + int base_vertex; + boolean use_index_buffer; + /* -1 = hardware input setup is outdated + * 0 = hardware input setup is for inline vertices + * 1 = hardware input setup is for hardware vertices + */ + int use_vertex_buffers; + + unsigned hw_vtxelt_nr; + unsigned hw_samplers; + uint32_t hw_txf[16]; + struct nvfx_render_target hw_rt[4]; + struct nvfx_render_target hw_zeta; + int hw_pointsprite_control; + int hw_vp_output; + struct nvfx_fragment_program* hw_fragprog; + struct nvfx_vertex_program* hw_vertprog; + + unsigned relocs_needed; +}; + +static INLINE struct nvfx_context * +nvfx_context(struct pipe_context *pipe) +{ + return (struct nvfx_context *)pipe; +} + +extern struct nvfx_state_entry nvfx_state_blend; +extern struct nvfx_state_entry nvfx_state_blend_colour; +extern struct nvfx_state_entry nvfx_state_fragprog; +extern struct nvfx_state_entry nvfx_state_fragtex; +extern struct nvfx_state_entry nvfx_state_framebuffer; +extern struct nvfx_state_entry nvfx_state_rasterizer; +extern struct nvfx_state_entry nvfx_state_scissor; +extern struct nvfx_state_entry nvfx_state_sr; +extern struct nvfx_state_entry nvfx_state_stipple; +extern struct nvfx_state_entry nvfx_state_vbo; +extern struct nvfx_state_entry nvfx_state_vertprog; +extern struct nvfx_state_entry nvfx_state_viewport; +extern struct nvfx_state_entry nvfx_state_vtxfmt; +extern struct nvfx_state_entry nvfx_state_zsa; + +extern void nvfx_init_query_functions(struct nvfx_context *nvfx); +extern void nvfx_init_surface_functions(struct nvfx_context *nvfx); + +/* nvfx_context.c */ +struct pipe_context * +nvfx_create(struct pipe_screen *pscreen, void *priv); + +/* nvfx_clear.c */ +extern void nvfx_clear(struct pipe_context *pipe, unsigned buffers, + const float *rgba, double depth, unsigned stencil); + +/* nvfx_draw.c */ +extern struct draw_stage *nvfx_draw_render_stage(struct nvfx_context *nvfx); +extern void nvfx_draw_vbo_swtnl(struct pipe_context *pipe, const struct pipe_draw_info* info); +extern void nvfx_vtxfmt_validate(struct nvfx_context *nvfx); + +/* nvfx_fb.c */ +extern int nvfx_framebuffer_prepare(struct nvfx_context *nvfx); +extern void nvfx_framebuffer_validate(struct nvfx_context *nvfx, unsigned prepare_result); +void +nvfx_framebuffer_relocate(struct nvfx_context *nvfx); + +/* nvfx_fragprog.c */ +extern void nvfx_fragprog_destroy(struct nvfx_context *, + struct nvfx_fragment_program *); +extern void nvfx_fragprog_validate(struct nvfx_context *nvfx); +extern void nvfx_fragprog_relocate(struct nvfx_context *nvfx); +extern void nvfx_init_fragprog_functions(struct nvfx_context *nvfx); + +/* nvfx_fragtex.c */ +extern void nvfx_init_sampling_functions(struct nvfx_context *nvfx); +extern void nvfx_fragtex_validate(struct nvfx_context *nvfx); +extern void nvfx_fragtex_relocate(struct nvfx_context *nvfx); + +struct nvfx_sampler_view; + +/* nv30_fragtex.c */ +extern void +nv30_sampler_state_init(struct pipe_context *pipe, + struct nvfx_sampler_state *ps, + const struct pipe_sampler_state *cso); +extern void +nv30_sampler_view_init(struct pipe_context *pipe, + struct nvfx_sampler_view *sv); +extern void nv30_fragtex_set(struct nvfx_context *nvfx, int unit); + +/* nv40_fragtex.c */ +extern void +nv40_sampler_state_init(struct pipe_context *pipe, + struct nvfx_sampler_state *ps, + const struct pipe_sampler_state *cso); +extern void +nv40_sampler_view_init(struct pipe_context *pipe, + struct nvfx_sampler_view *sv); +extern void nv40_fragtex_set(struct nvfx_context *nvfx, int unit); + +/* nvfx_state.c */ +extern void nvfx_init_state_functions(struct nvfx_context *nvfx); +extern void nvfx_state_scissor_validate(struct nvfx_context *nvfx); +extern void nvfx_state_stipple_validate(struct nvfx_context *nvfx); +extern void nvfx_state_blend_validate(struct nvfx_context *nvfx); +extern void nvfx_state_blend_colour_validate(struct nvfx_context *nvfx); +extern void nvfx_state_viewport_validate(struct nvfx_context *nvfx); +extern void nvfx_state_rasterizer_validate(struct nvfx_context *nvfx); +extern void nvfx_state_sr_validate(struct nvfx_context *nvfx); +extern void nvfx_state_zsa_validate(struct nvfx_context *nvfx); + +/* nvfx_state_emit.c */ +extern void nvfx_state_relocate(struct nvfx_context *nvfx, unsigned relocs); +extern boolean nvfx_state_validate(struct nvfx_context *nvfx); +extern boolean nvfx_state_validate_swtnl(struct nvfx_context *nvfx); + +static inline void +nvfx_state_emit(struct nvfx_context *nvfx) +{ + unsigned relocs = NVFX_RELOCATE_FRAMEBUFFER | NVFX_RELOCATE_FRAGTEX | NVFX_RELOCATE_FRAGPROG; + if (nvfx->render_mode == HW) + { + relocs |= NVFX_RELOCATE_VTXBUF; + if(nvfx->use_index_buffer) + relocs |= NVFX_RELOCATE_IDXBUF; + } + + relocs &= nvfx->relocs_needed; + if(relocs) + nvfx_state_relocate(nvfx, relocs); +} + +/* nvfx_transfer.c */ +extern void nvfx_init_transfer_functions(struct pipe_context *pipe); + +/* nvfx_vbo.c */ +extern boolean nvfx_vbo_validate(struct nvfx_context *nvfx); +extern void nvfx_vbo_swtnl_validate(struct nvfx_context *nvfx); +extern void nvfx_vbo_relocate(struct nvfx_context *nvfx); +extern void nvfx_idxbuf_validate(struct nvfx_context* nvfx); +extern void nvfx_idxbuf_relocate(struct nvfx_context* nvfx); +extern void nvfx_draw_vbo(struct pipe_context *pipe, + const struct pipe_draw_info *info); +extern void nvfx_init_vbo_functions(struct nvfx_context *nvfx); +extern unsigned nvfx_vertex_formats[]; + +/* nvfx_vertprog.c */ +extern boolean nvfx_vertprog_validate(struct nvfx_context *nvfx); +extern void nvfx_vertprog_destroy(struct nvfx_context *, + struct nvfx_vertex_program *); +extern void nvfx_init_vertprog_functions(struct nvfx_context *nvfx); + +/* nvfx_push.c */ +extern void nvfx_push_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info); + +/* must WAIT_RING(chan, ncomp + 1) or equivalent beforehand! */ +static inline void nvfx_emit_vtx_attr(struct nouveau_channel* chan, unsigned attrib, const float* v, unsigned ncomp) +{ + switch (ncomp) { + case 4: + OUT_RING(chan, RING_3D(NV30_3D_VTX_ATTR_4F_X(attrib), 4)); + OUT_RING(chan, fui(v[0])); + OUT_RING(chan, fui(v[1])); + OUT_RING(chan, fui(v[2])); + OUT_RING(chan, fui(v[3])); + break; + case 3: + OUT_RING(chan, RING_3D(NV30_3D_VTX_ATTR_3F_X(attrib), 3)); + OUT_RING(chan, fui(v[0])); + OUT_RING(chan, fui(v[1])); + OUT_RING(chan, fui(v[2])); + break; + case 2: + OUT_RING(chan, RING_3D(NV30_3D_VTX_ATTR_2F_X(attrib), 2)); + OUT_RING(chan, fui(v[0])); + OUT_RING(chan, fui(v[1])); + break; + case 1: + OUT_RING(chan, RING_3D(NV30_3D_VTX_ATTR_1F(attrib), 1)); + OUT_RING(chan, fui(v[0])); + break; + } +} + +#endif diff --git a/src/gallium/drivers/nvfx/nvfx_draw.c b/src/gallium/drivers/nvfx/nvfx_draw.c new file mode 100644 index 0000000..61f888a --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_draw.c @@ -0,0 +1,189 @@ +#include "pipe/p_shader_tokens.h" +#include "util/u_inlines.h" + +#include "util/u_pack_color.h" + +#include "draw/draw_context.h" +#include "draw/draw_vertex.h" +#include "draw/draw_pipe.h" + +#include "nvfx_context.h" +#include "nvfx_resource.h" + +struct nvfx_render_stage { + struct draw_stage stage; + struct nvfx_context *nvfx; + unsigned prim; +}; + +static INLINE struct nvfx_render_stage * +nvfx_render_stage(struct draw_stage *stage) +{ + return (struct nvfx_render_stage *)stage; +} + +static void +nvfx_render_flush(struct draw_stage *stage, unsigned flags) +{ + struct nvfx_render_stage *rs = nvfx_render_stage(stage); + struct nvfx_context *nvfx = rs->nvfx; + struct nouveau_channel *chan = nvfx->screen->base.channel; + + if (rs->prim != NV30_3D_VERTEX_BEGIN_END_STOP) { + assert(AVAIL_RING(chan) >= 2); + OUT_RING(chan, RING_3D(NV30_3D_VERTEX_BEGIN_END, 1)); + OUT_RING(chan, NV30_3D_VERTEX_BEGIN_END_STOP); + rs->prim = NV30_3D_VERTEX_BEGIN_END_STOP; + } +} + +static INLINE void +nvfx_render_prim(struct draw_stage *stage, struct prim_header *prim, + unsigned mode, unsigned count) +{ + struct nvfx_render_stage *rs = nvfx_render_stage(stage); + struct nvfx_context *nvfx = rs->nvfx; + + struct nvfx_screen *screen = nvfx->screen; + struct nouveau_channel *chan = screen->base.channel; + boolean no_elements = nvfx->vertprog->draw_no_elements; + unsigned num_attribs = nvfx->vertprog->draw_elements; + + /* we need to account the flush as well here even if it is done afterthis + * function + */ + if (AVAIL_RING(chan) < ((1 + count * num_attribs * 4) + 6 + 64)) { + nvfx_render_flush(stage, 0); + FIRE_RING(chan); + nvfx_state_emit(nvfx); + + assert(AVAIL_RING(chan) >= ((1 + count * num_attribs * 4) + 6 + 64)); + } + + /* Switch primitive modes if necessary */ + if (rs->prim != mode) { + if (rs->prim != NV30_3D_VERTEX_BEGIN_END_STOP) { + OUT_RING(chan, RING_3D(NV30_3D_VERTEX_BEGIN_END, 1)); + OUT_RING(chan, NV30_3D_VERTEX_BEGIN_END_STOP); + } + + /* XXX: any command a lot of times seems to (mostly) fix corruption that would otherwise happen */ + /* this seems to cause issues on nv3x, and also be unneeded there */ + if(nvfx->is_nv4x) + { + int i; + for(i = 0; i < 32; ++i) + { + OUT_RING(chan, RING_3D(0x1dac, 1)); + OUT_RING(chan, 0); + } + } + + OUT_RING(chan, RING_3D(NV30_3D_VERTEX_BEGIN_END, 1)); + OUT_RING (chan, mode); + rs->prim = mode; + } + + OUT_RING(chan, RING_3D_NI(NV30_3D_VERTEX_DATA, num_attribs * 4 * count)); + if(no_elements) { + OUT_RING(chan, 0); + OUT_RING(chan, 0); + OUT_RING(chan, 0); + OUT_RING(chan, 0); + } else { + for (unsigned i = 0; i < count; ++i) + { + struct vertex_header* v = prim->v[i]; + /* TODO: disable divide where it's causing the problem, and remove this hack */ + OUT_RING(chan, fui(v->data[0][0] / v->data[0][3])); + OUT_RING(chan, fui(v->data[0][1] / v->data[0][3])); + OUT_RING(chan, fui(v->data[0][2] / v->data[0][3])); + OUT_RING(chan, fui(1.0f / v->data[0][3])); + OUT_RINGp(chan, &v->data[1][0], 4 * (num_attribs - 1)); + } + } +} + +static void +nvfx_render_point(struct draw_stage *draw, struct prim_header *prim) +{ + nvfx_render_prim(draw, prim, NV30_3D_VERTEX_BEGIN_END_POINTS, 1); +} + +static void +nvfx_render_line(struct draw_stage *draw, struct prim_header *prim) +{ + nvfx_render_prim(draw, prim, NV30_3D_VERTEX_BEGIN_END_LINES, 2); +} + +static void +nvfx_render_tri(struct draw_stage *draw, struct prim_header *prim) +{ + nvfx_render_prim(draw, prim, NV30_3D_VERTEX_BEGIN_END_TRIANGLES, 3); +} + +static void +nvfx_render_reset_stipple_counter(struct draw_stage *draw) +{ + /* this doesn't really seem to work, but it matters rather little */ + nvfx_render_flush(draw, 0); +} + +static void +nvfx_render_destroy(struct draw_stage *draw) +{ + FREE(draw); +} + +struct draw_stage * +nvfx_draw_render_stage(struct nvfx_context *nvfx) +{ + struct nvfx_render_stage *render = CALLOC_STRUCT(nvfx_render_stage); + + render->nvfx = nvfx; + render->stage.draw = nvfx->draw; + render->stage.point = nvfx_render_point; + render->stage.line = nvfx_render_line; + render->stage.tri = nvfx_render_tri; + render->stage.flush = nvfx_render_flush; + render->stage.reset_stipple_counter = nvfx_render_reset_stipple_counter; + render->stage.destroy = nvfx_render_destroy; + + return &render->stage; +} + +void +nvfx_draw_vbo_swtnl(struct pipe_context *pipe, const struct pipe_draw_info* info) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + unsigned i; + void *map; + + if (!nvfx_state_validate_swtnl(nvfx)) + return; + + nvfx_state_emit(nvfx); + + /* these must be passed without adding the offsets */ + for (i = 0; i < nvfx->vtxbuf_nr; i++) { + map = nvfx_buffer(nvfx->vtxbuf[i].buffer)->data; + draw_set_mapped_vertex_buffer(nvfx->draw, i, map); + } + + map = NULL; + if (info->indexed && nvfx->idxbuf.buffer) + map = nvfx_buffer(nvfx->idxbuf.buffer)->data; + draw_set_mapped_index_buffer(nvfx->draw, map); + + if (nvfx->constbuf[PIPE_SHADER_VERTEX]) { + const unsigned nr = nvfx->constbuf_nr[PIPE_SHADER_VERTEX]; + + map = nvfx_buffer(nvfx->constbuf[PIPE_SHADER_VERTEX])->data; + draw_set_mapped_constant_buffer(nvfx->draw, PIPE_SHADER_VERTEX, 0, + map, nr); + } + + draw_vbo(nvfx->draw, info); + + draw_flush(nvfx->draw); +} diff --git a/src/gallium/drivers/nvfx/nvfx_fragprog.c b/src/gallium/drivers/nvfx/nvfx_fragprog.c new file mode 100644 index 0000000..13e8bee --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_fragprog.c @@ -0,0 +1,1623 @@ +#include +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "util/u_debug.h" + +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_ureg.h" + +#include "nvfx_context.h" +#include "nvfx_shader.h" +#include "nvfx_resource.h" + +struct nvfx_fpc { + struct nvfx_pipe_fragment_program* pfp; + struct nvfx_fragment_program *fp; + + unsigned max_temps; + unsigned long long r_temps; + unsigned long long r_temps_discard; + struct nvfx_reg r_result[PIPE_MAX_SHADER_OUTPUTS]; + struct nvfx_reg *r_temp; + unsigned sprite_coord_temp; + + int num_regs; + + unsigned inst_offset; + unsigned have_const; + + struct util_dynarray imm_data; + + struct nvfx_reg* r_imm; + unsigned nr_imm; + + unsigned char generic_to_slot[256]; /* semantic idx for each input semantic */ + + struct util_dynarray if_stack; + //struct util_dynarray loop_stack; + struct util_dynarray label_relocs; +}; + +static INLINE struct nvfx_reg +temp(struct nvfx_fpc *fpc) +{ + int idx = __builtin_ctzll(~fpc->r_temps); + + if (idx >= fpc->max_temps) { + NOUVEAU_ERR("out of temps!!\n"); + assert(0); + return nvfx_reg(NVFXSR_TEMP, 0); + } + + fpc->r_temps |= (1ULL << idx); + fpc->r_temps_discard |= (1ULL << idx); + return nvfx_reg(NVFXSR_TEMP, idx); +} + +static INLINE void +release_temps(struct nvfx_fpc *fpc) +{ + fpc->r_temps &= ~fpc->r_temps_discard; + fpc->r_temps_discard = 0ULL; +} + +static inline struct nvfx_reg +nvfx_fp_imm(struct nvfx_fpc *fpc, float a, float b, float c, float d) +{ + float v[4] = {a, b, c, d}; + int idx = fpc->imm_data.size >> 4; + + memcpy(util_dynarray_grow(&fpc->imm_data, sizeof(float) * 4), v, 4 * sizeof(float)); + return nvfx_reg(NVFXSR_IMM, idx); +} + +static void +grow_insns(struct nvfx_fpc *fpc, int size) +{ + struct nvfx_fragment_program *fp = fpc->fp; + + fp->insn_len += size; + fp->insn = realloc(fp->insn, sizeof(uint32_t) * fp->insn_len); +} + +static void +emit_src(struct nvfx_fpc *fpc, int pos, struct nvfx_src src) +{ + struct nvfx_fragment_program *fp = fpc->fp; + uint32_t *hw = &fp->insn[fpc->inst_offset]; + uint32_t sr = 0; + + switch (src.reg.type) { + case NVFXSR_INPUT: + sr |= (NVFX_FP_REG_TYPE_INPUT << NVFX_FP_REG_TYPE_SHIFT); + hw[0] |= (src.reg.index << NVFX_FP_OP_INPUT_SRC_SHIFT); + break; + case NVFXSR_OUTPUT: + sr |= NVFX_FP_REG_SRC_HALF; + /* fall-through */ + case NVFXSR_TEMP: + sr |= (NVFX_FP_REG_TYPE_TEMP << NVFX_FP_REG_TYPE_SHIFT); + sr |= (src.reg.index << NVFX_FP_REG_SRC_SHIFT); + break; + case NVFXSR_RELOCATED: + sr |= (NVFX_FP_REG_TYPE_TEMP << NVFX_FP_REG_TYPE_SHIFT); + sr |= (fpc->sprite_coord_temp << NVFX_FP_REG_SRC_SHIFT); + //printf("adding relocation at %x for %x\n", fpc->inst_offset, src.index); + util_dynarray_append(&fpc->fp->slot_relocations[src.reg.index], unsigned, fpc->inst_offset + pos + 1); + break; + case NVFXSR_IMM: + if (!fpc->have_const) { + grow_insns(fpc, 4); + hw = &fp->insn[fpc->inst_offset]; + fpc->have_const = 1; + } + + memcpy(&fp->insn[fpc->inst_offset + 4], + (float*)fpc->imm_data.data + src.reg.index * 4, + sizeof(uint32_t) * 4); + + sr |= (NVFX_FP_REG_TYPE_CONST << NVFX_FP_REG_TYPE_SHIFT); + break; + case NVFXSR_CONST: + if (!fpc->have_const) { + grow_insns(fpc, 4); + hw = &fp->insn[fpc->inst_offset]; + fpc->have_const = 1; + } + + { + struct nvfx_fragment_program_data *fpd; + + fp->consts = realloc(fp->consts, ++fp->nr_consts * + sizeof(*fpd)); + fpd = &fp->consts[fp->nr_consts - 1]; + fpd->offset = fpc->inst_offset + 4; + fpd->index = src.reg.index; + memset(&fp->insn[fpd->offset], 0, sizeof(uint32_t) * 4); + } + + sr |= (NVFX_FP_REG_TYPE_CONST << NVFX_FP_REG_TYPE_SHIFT); + break; + case NVFXSR_NONE: + sr |= (NVFX_FP_REG_TYPE_INPUT << NVFX_FP_REG_TYPE_SHIFT); + break; + default: + assert(0); + } + + if (src.negate) + sr |= NVFX_FP_REG_NEGATE; + + if (src.abs) + hw[1] |= (1 << (29 + pos)); + + sr |= ((src.swz[0] << NVFX_FP_REG_SWZ_X_SHIFT) | + (src.swz[1] << NVFX_FP_REG_SWZ_Y_SHIFT) | + (src.swz[2] << NVFX_FP_REG_SWZ_Z_SHIFT) | + (src.swz[3] << NVFX_FP_REG_SWZ_W_SHIFT)); + + hw[pos + 1] |= sr; +} + +static void +emit_dst(struct nvfx_fpc *fpc, struct nvfx_reg dst) +{ + struct nvfx_fragment_program *fp = fpc->fp; + uint32_t *hw = &fp->insn[fpc->inst_offset]; + + switch (dst.type) { + case NVFXSR_TEMP: + if (fpc->num_regs < (dst.index + 1)) + fpc->num_regs = dst.index + 1; + break; + case NVFXSR_OUTPUT: + if (dst.index == 1) { + fp->fp_control |= 0xe; + } else { + hw[0] |= NVFX_FP_OP_OUT_REG_HALF; + } + break; + case NVFXSR_NONE: + hw[0] |= (1 << 30); + break; + default: + assert(0); + } + + hw[0] |= (dst.index << NVFX_FP_OP_OUT_REG_SHIFT); +} + +static void +nvfx_fp_emit(struct nvfx_fpc *fpc, struct nvfx_insn insn) +{ + struct nvfx_fragment_program *fp = fpc->fp; + uint32_t *hw; + + fpc->inst_offset = fp->insn_len; + fpc->have_const = 0; + grow_insns(fpc, 4); + hw = &fp->insn[fpc->inst_offset]; + memset(hw, 0, sizeof(uint32_t) * 4); + + if (insn.op == NVFX_FP_OP_OPCODE_KIL) + fp->fp_control |= NV30_3D_FP_CONTROL_USES_KIL; + hw[0] |= (insn.op << NVFX_FP_OP_OPCODE_SHIFT); + hw[0] |= (insn.mask << NVFX_FP_OP_OUTMASK_SHIFT); + hw[2] |= (insn.scale << NVFX_FP_OP_DST_SCALE_SHIFT); + + if (insn.sat) + hw[0] |= NVFX_FP_OP_OUT_SAT; + + if (insn.cc_update) + hw[0] |= NVFX_FP_OP_COND_WRITE_ENABLE; + hw[1] |= (insn.cc_test << NVFX_FP_OP_COND_SHIFT); + hw[1] |= ((insn.cc_swz[0] << NVFX_FP_OP_COND_SWZ_X_SHIFT) | + (insn.cc_swz[1] << NVFX_FP_OP_COND_SWZ_Y_SHIFT) | + (insn.cc_swz[2] << NVFX_FP_OP_COND_SWZ_Z_SHIFT) | + (insn.cc_swz[3] << NVFX_FP_OP_COND_SWZ_W_SHIFT)); + + if(insn.unit >= 0) + { + hw[0] |= (insn.unit << NVFX_FP_OP_TEX_UNIT_SHIFT); + fp->samplers |= (1 << insn.unit); + } + + emit_dst(fpc, insn.dst); + emit_src(fpc, 0, insn.src[0]); + emit_src(fpc, 1, insn.src[1]); + emit_src(fpc, 2, insn.src[2]); +} + +#define arith(s,o,d,m,s0,s1,s2) \ + nvfx_insn((s), NVFX_FP_OP_OPCODE_##o, -1, \ + (d), (m), (s0), (s1), (s2)) + +#define tex(s,o,u,d,m,s0,s1,s2) \ + nvfx_insn((s), NVFX_FP_OP_OPCODE_##o, (u), \ + (d), (m), (s0), none, none) + +/* IF src.x != 0, as TGSI specifies */ +static void +nv40_fp_if(struct nvfx_fpc *fpc, struct nvfx_src src) +{ + const struct nvfx_src none = nvfx_src(nvfx_reg(NVFXSR_NONE, 0)); + struct nvfx_insn insn = arith(0, MOV, none.reg, NVFX_FP_MASK_X, src, none, none); + uint32_t *hw; + insn.cc_update = 1; + nvfx_fp_emit(fpc, insn); + + fpc->inst_offset = fpc->fp->insn_len; + grow_insns(fpc, 4); + hw = &fpc->fp->insn[fpc->inst_offset]; + /* I really wonder why fp16 precision is used. Presumably the hardware ignores it? */ + hw[0] = (NV40_FP_OP_BRA_OPCODE_IF << NVFX_FP_OP_OPCODE_SHIFT) | + NV40_FP_OP_OUT_NONE | + (NVFX_FP_PRECISION_FP16 << NVFX_FP_OP_PRECISION_SHIFT); + /* Use .xxxx swizzle so that we check only src[0].x*/ + hw[1] = (0 << NVFX_FP_OP_COND_SWZ_X_SHIFT) | + (0 << NVFX_FP_OP_COND_SWZ_Y_SHIFT) | + (0 << NVFX_FP_OP_COND_SWZ_Z_SHIFT) | + (0 << NVFX_FP_OP_COND_SWZ_W_SHIFT) | + (NVFX_FP_OP_COND_NE << NVFX_FP_OP_COND_SHIFT); + hw[2] = 0; /* | NV40_FP_OP_OPCODE_IS_BRANCH | else_offset */ + hw[3] = 0; /* | endif_offset */ + util_dynarray_append(&fpc->if_stack, unsigned, fpc->inst_offset); +} + +/* IF src.x != 0, as TGSI specifies */ +static void +nv40_fp_cal(struct nvfx_fpc *fpc, unsigned target) +{ + struct nvfx_relocation reloc; + uint32_t *hw; + fpc->inst_offset = fpc->fp->insn_len; + grow_insns(fpc, 4); + hw = &fpc->fp->insn[fpc->inst_offset]; + /* I really wonder why fp16 precision is used. Presumably the hardware ignores it? */ + hw[0] = (NV40_FP_OP_BRA_OPCODE_CAL << NVFX_FP_OP_OPCODE_SHIFT); + /* Use .xxxx swizzle so that we check only src[0].x*/ + hw[1] = (NVFX_SWZ_IDENTITY << NVFX_FP_OP_COND_SWZ_ALL_SHIFT) | + (NVFX_FP_OP_COND_TR << NVFX_FP_OP_COND_SHIFT); + hw[2] = NV40_FP_OP_OPCODE_IS_BRANCH; /* | call_offset */ + hw[3] = 0; + reloc.target = target; + reloc.location = fpc->inst_offset + 2; + util_dynarray_append(&fpc->label_relocs, struct nvfx_relocation, reloc); +} + +static void +nv40_fp_ret(struct nvfx_fpc *fpc) +{ + uint32_t *hw; + fpc->inst_offset = fpc->fp->insn_len; + grow_insns(fpc, 4); + hw = &fpc->fp->insn[fpc->inst_offset]; + /* I really wonder why fp16 precision is used. Presumably the hardware ignores it? */ + hw[0] = (NV40_FP_OP_BRA_OPCODE_RET << NVFX_FP_OP_OPCODE_SHIFT); + /* Use .xxxx swizzle so that we check only src[0].x*/ + hw[1] = (NVFX_SWZ_IDENTITY << NVFX_FP_OP_COND_SWZ_ALL_SHIFT) | + (NVFX_FP_OP_COND_TR << NVFX_FP_OP_COND_SHIFT); + hw[2] = NV40_FP_OP_OPCODE_IS_BRANCH; /* | call_offset */ + hw[3] = 0; +} + +static void +nv40_fp_rep(struct nvfx_fpc *fpc, unsigned count, unsigned target) +{ + struct nvfx_relocation reloc; + uint32_t *hw; + fpc->inst_offset = fpc->fp->insn_len; + grow_insns(fpc, 4); + hw = &fpc->fp->insn[fpc->inst_offset]; + /* I really wonder why fp16 precision is used. Presumably the hardware ignores it? */ + hw[0] = (NV40_FP_OP_BRA_OPCODE_REP << NVFX_FP_OP_OPCODE_SHIFT) | + NV40_FP_OP_OUT_NONE | + (NVFX_FP_PRECISION_FP16 << NVFX_FP_OP_PRECISION_SHIFT); + /* Use .xxxx swizzle so that we check only src[0].x*/ + hw[1] = (NVFX_SWZ_IDENTITY << NVFX_FP_OP_COND_SWZ_ALL_SHIFT) | + (NVFX_FP_OP_COND_TR << NVFX_FP_OP_COND_SHIFT); + hw[2] = NV40_FP_OP_OPCODE_IS_BRANCH | + (count << NV40_FP_OP_REP_COUNT1_SHIFT) | + (count << NV40_FP_OP_REP_COUNT2_SHIFT) | + (count << NV40_FP_OP_REP_COUNT3_SHIFT); + hw[3] = 0; /* | end_offset */ + reloc.target = target; + reloc.location = fpc->inst_offset + 3; + util_dynarray_append(&fpc->label_relocs, struct nvfx_relocation, reloc); + //util_dynarray_append(&fpc->loop_stack, unsigned, target); +} + +/* warning: this only works forward, and probably only if not inside any IF */ +static void +nv40_fp_bra(struct nvfx_fpc *fpc, unsigned target) +{ + struct nvfx_relocation reloc; + uint32_t *hw; + fpc->inst_offset = fpc->fp->insn_len; + grow_insns(fpc, 4); + hw = &fpc->fp->insn[fpc->inst_offset]; + /* I really wonder why fp16 precision is used. Presumably the hardware ignores it? */ + hw[0] = (NV40_FP_OP_BRA_OPCODE_IF << NVFX_FP_OP_OPCODE_SHIFT) | + NV40_FP_OP_OUT_NONE | + (NVFX_FP_PRECISION_FP16 << NVFX_FP_OP_PRECISION_SHIFT); + /* Use .xxxx swizzle so that we check only src[0].x*/ + hw[1] = (NVFX_SWZ_IDENTITY << NVFX_FP_OP_COND_SWZ_X_SHIFT) | + (NVFX_FP_OP_COND_FL << NVFX_FP_OP_COND_SHIFT); + hw[2] = NV40_FP_OP_OPCODE_IS_BRANCH; /* | else_offset */ + hw[3] = 0; /* | endif_offset */ + reloc.target = target; + reloc.location = fpc->inst_offset + 2; + util_dynarray_append(&fpc->label_relocs, struct nvfx_relocation, reloc); + reloc.target = target; + reloc.location = fpc->inst_offset + 3; + util_dynarray_append(&fpc->label_relocs, struct nvfx_relocation, reloc); +} + +static void +nv40_fp_brk(struct nvfx_fpc *fpc) +{ + uint32_t *hw; + fpc->inst_offset = fpc->fp->insn_len; + grow_insns(fpc, 4); + hw = &fpc->fp->insn[fpc->inst_offset]; + /* I really wonder why fp16 precision is used. Presumably the hardware ignores it? */ + hw[0] = (NV40_FP_OP_BRA_OPCODE_BRK << NVFX_FP_OP_OPCODE_SHIFT) | + NV40_FP_OP_OUT_NONE; + /* Use .xxxx swizzle so that we check only src[0].x*/ + hw[1] = (NVFX_SWZ_IDENTITY << NVFX_FP_OP_COND_SWZ_X_SHIFT) | + (NVFX_FP_OP_COND_TR << NVFX_FP_OP_COND_SHIFT); + hw[2] = NV40_FP_OP_OPCODE_IS_BRANCH; + hw[3] = 0; +} + +static INLINE struct nvfx_src +tgsi_src(struct nvfx_fpc *fpc, const struct tgsi_full_src_register *fsrc) +{ + struct nvfx_src src; + + switch (fsrc->Register.File) { + case TGSI_FILE_INPUT: + if(fpc->pfp->info.input_semantic_name[fsrc->Register.Index] == TGSI_SEMANTIC_POSITION) { + assert(fpc->pfp->info.input_semantic_index[fsrc->Register.Index] == 0); + src.reg = nvfx_reg(NVFXSR_INPUT, NVFX_FP_OP_INPUT_SRC_POSITION); + } else if(fpc->pfp->info.input_semantic_name[fsrc->Register.Index] == TGSI_SEMANTIC_COLOR) { + if(fpc->pfp->info.input_semantic_index[fsrc->Register.Index] == 0) + src.reg = nvfx_reg(NVFXSR_INPUT, NVFX_FP_OP_INPUT_SRC_COL0); + else if(fpc->pfp->info.input_semantic_index[fsrc->Register.Index] == 1) + src.reg = nvfx_reg(NVFXSR_INPUT, NVFX_FP_OP_INPUT_SRC_COL1); + else + assert(0); + } else if(fpc->pfp->info.input_semantic_name[fsrc->Register.Index] == TGSI_SEMANTIC_FOG) { + assert(fpc->pfp->info.input_semantic_index[fsrc->Register.Index] == 0); + src.reg = nvfx_reg(NVFXSR_INPUT, NVFX_FP_OP_INPUT_SRC_FOGC); + } else if(fpc->pfp->info.input_semantic_name[fsrc->Register.Index] == TGSI_SEMANTIC_FACE) { + /* TODO: check this has the correct values */ + /* XXX: what do we do for nv30 here (assuming it lacks facing)?! */ + assert(fpc->pfp->info.input_semantic_index[fsrc->Register.Index] == 0); + src.reg = nvfx_reg(NVFXSR_INPUT, NV40_FP_OP_INPUT_SRC_FACING); + } else { + assert(fpc->pfp->info.input_semantic_name[fsrc->Register.Index] == TGSI_SEMANTIC_GENERIC); + src.reg = nvfx_reg(NVFXSR_RELOCATED, fpc->generic_to_slot[fpc->pfp->info.input_semantic_index[fsrc->Register.Index]]); + } + break; + case TGSI_FILE_CONSTANT: + src.reg = nvfx_reg(NVFXSR_CONST, fsrc->Register.Index); + break; + case TGSI_FILE_IMMEDIATE: + assert(fsrc->Register.Index < fpc->nr_imm); + src.reg = fpc->r_imm[fsrc->Register.Index]; + break; + case TGSI_FILE_TEMPORARY: + src.reg = fpc->r_temp[fsrc->Register.Index]; + break; + /* NV40 fragprog result regs are just temps, so this is simple */ + case TGSI_FILE_OUTPUT: + src.reg = fpc->r_result[fsrc->Register.Index]; + break; + default: + NOUVEAU_ERR("bad src file\n"); + src.reg.index = 0; + src.reg.type = 0; + break; + } + + src.abs = fsrc->Register.Absolute; + src.negate = fsrc->Register.Negate; + src.swz[0] = fsrc->Register.SwizzleX; + src.swz[1] = fsrc->Register.SwizzleY; + src.swz[2] = fsrc->Register.SwizzleZ; + src.swz[3] = fsrc->Register.SwizzleW; + src.indirect = 0; + src.indirect_reg = 0; + src.indirect_swz = 0; + return src; +} + +static INLINE struct nvfx_reg +tgsi_dst(struct nvfx_fpc *fpc, const struct tgsi_full_dst_register *fdst) { + switch (fdst->Register.File) { + case TGSI_FILE_OUTPUT: + return fpc->r_result[fdst->Register.Index]; + case TGSI_FILE_TEMPORARY: + return fpc->r_temp[fdst->Register.Index]; + case TGSI_FILE_NULL: + return nvfx_reg(NVFXSR_NONE, 0); + default: + NOUVEAU_ERR("bad dst file %d\n", fdst->Register.File); + return nvfx_reg(NVFXSR_NONE, 0); + } +} + +static INLINE int +tgsi_mask(uint tgsi) +{ + int mask = 0; + + if (tgsi & TGSI_WRITEMASK_X) mask |= NVFX_FP_MASK_X; + if (tgsi & TGSI_WRITEMASK_Y) mask |= NVFX_FP_MASK_Y; + if (tgsi & TGSI_WRITEMASK_Z) mask |= NVFX_FP_MASK_Z; + if (tgsi & TGSI_WRITEMASK_W) mask |= NVFX_FP_MASK_W; + return mask; +} + +static boolean +nvfx_fragprog_parse_instruction(struct nvfx_context* nvfx, struct nvfx_fpc *fpc, + const struct tgsi_full_instruction *finst) +{ + const struct nvfx_src none = nvfx_src(nvfx_reg(NVFXSR_NONE, 0)); + struct nvfx_insn insn; + struct nvfx_src src[3], tmp; + struct nvfx_reg dst; + int mask, sat, unit = 0; + int ai = -1, ci = -1, ii = -1; + int i; + + if (finst->Instruction.Opcode == TGSI_OPCODE_END) + return TRUE; + + for (i = 0; i < finst->Instruction.NumSrcRegs; i++) { + const struct tgsi_full_src_register *fsrc; + + fsrc = &finst->Src[i]; + if (fsrc->Register.File == TGSI_FILE_TEMPORARY) { + src[i] = tgsi_src(fpc, fsrc); + } + } + + for (i = 0; i < finst->Instruction.NumSrcRegs; i++) { + const struct tgsi_full_src_register *fsrc; + + fsrc = &finst->Src[i]; + + switch (fsrc->Register.File) { + case TGSI_FILE_INPUT: + if(fpc->pfp->info.input_semantic_name[fsrc->Register.Index] == TGSI_SEMANTIC_FOG && (0 + || fsrc->Register.SwizzleX == PIPE_SWIZZLE_ALPHA + || fsrc->Register.SwizzleY == PIPE_SWIZZLE_ALPHA + || fsrc->Register.SwizzleZ == PIPE_SWIZZLE_ALPHA + || fsrc->Register.SwizzleW == PIPE_SWIZZLE_ALPHA + )) { + /* hardware puts 0 in fogcoord.w, but GL/Gallium want 1 there */ + struct nvfx_src addend = nvfx_src(nvfx_fp_imm(fpc, 0, 0, 0, 1)); + addend.swz[0] = fsrc->Register.SwizzleX; + addend.swz[1] = fsrc->Register.SwizzleY; + addend.swz[2] = fsrc->Register.SwizzleZ; + addend.swz[3] = fsrc->Register.SwizzleW; + src[i] = nvfx_src(temp(fpc)); + nvfx_fp_emit(fpc, arith(0, ADD, src[i].reg, NVFX_FP_MASK_ALL, tgsi_src(fpc, fsrc), addend, none)); + } else if (ai == -1 || ai == fsrc->Register.Index) { + ai = fsrc->Register.Index; + src[i] = tgsi_src(fpc, fsrc); + } else { + src[i] = nvfx_src(temp(fpc)); + nvfx_fp_emit(fpc, arith(0, MOV, src[i].reg, NVFX_FP_MASK_ALL, tgsi_src(fpc, fsrc), none, none)); + } + break; + case TGSI_FILE_CONSTANT: + if ((ci == -1 && ii == -1) || + ci == fsrc->Register.Index) { + ci = fsrc->Register.Index; + src[i] = tgsi_src(fpc, fsrc); + } else { + src[i] = nvfx_src(temp(fpc)); + nvfx_fp_emit(fpc, arith(0, MOV, src[i].reg, NVFX_FP_MASK_ALL, tgsi_src(fpc, fsrc), none, none)); + } + break; + case TGSI_FILE_IMMEDIATE: + if ((ci == -1 && ii == -1) || + ii == fsrc->Register.Index) { + ii = fsrc->Register.Index; + src[i] = tgsi_src(fpc, fsrc); + } else { + src[i] = nvfx_src(temp(fpc)); + nvfx_fp_emit(fpc, arith(0, MOV, src[i].reg, NVFX_FP_MASK_ALL, tgsi_src(fpc, fsrc), none, none)); + } + break; + case TGSI_FILE_TEMPORARY: + /* handled above */ + break; + case TGSI_FILE_SAMPLER: + unit = fsrc->Register.Index; + break; + case TGSI_FILE_OUTPUT: + break; + default: + NOUVEAU_ERR("bad src file\n"); + return FALSE; + } + } + + dst = tgsi_dst(fpc, &finst->Dst[0]); + mask = tgsi_mask(finst->Dst[0].Register.WriteMask); + sat = (finst->Instruction.Saturate == TGSI_SAT_ZERO_ONE); + + switch (finst->Instruction.Opcode) { + case TGSI_OPCODE_ABS: + nvfx_fp_emit(fpc, arith(sat, MOV, dst, mask, abs(src[0]), none, none)); + break; + case TGSI_OPCODE_ADD: + nvfx_fp_emit(fpc, arith(sat, ADD, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_CMP: + insn = arith(0, MOV, none.reg, mask, src[0], none, none); + insn.cc_update = 1; + nvfx_fp_emit(fpc, insn); + + insn = arith(sat, MOV, dst, mask, src[2], none, none); + insn.cc_test = NVFX_COND_GE; + nvfx_fp_emit(fpc, insn); + + insn = arith(sat, MOV, dst, mask, src[1], none, none); + insn.cc_test = NVFX_COND_LT; + nvfx_fp_emit(fpc, insn); + break; + case TGSI_OPCODE_COS: + nvfx_fp_emit(fpc, arith(sat, COS, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_DDX: + if (mask & (NVFX_FP_MASK_Z | NVFX_FP_MASK_W)) { + tmp = nvfx_src(temp(fpc)); + nvfx_fp_emit(fpc, arith(sat, DDX, tmp.reg, NVFX_FP_MASK_X | NVFX_FP_MASK_Y, swz(src[0], Z, W, Z, W), none, none)); + nvfx_fp_emit(fpc, arith(0, MOV, tmp.reg, NVFX_FP_MASK_Z | NVFX_FP_MASK_W, swz(tmp, X, Y, X, Y), none, none)); + nvfx_fp_emit(fpc, arith(sat, DDX, tmp.reg, NVFX_FP_MASK_X | NVFX_FP_MASK_Y, src[0], none, none)); + nvfx_fp_emit(fpc, arith(0, MOV, dst, mask, tmp, none, none)); + } else { + nvfx_fp_emit(fpc, arith(sat, DDX, dst, mask, src[0], none, none)); + } + break; + case TGSI_OPCODE_DDY: + if (mask & (NVFX_FP_MASK_Z | NVFX_FP_MASK_W)) { + tmp = nvfx_src(temp(fpc)); + nvfx_fp_emit(fpc, arith(sat, DDY, tmp.reg, NVFX_FP_MASK_X | NVFX_FP_MASK_Y, swz(src[0], Z, W, Z, W), none, none)); + nvfx_fp_emit(fpc, arith(0, MOV, tmp.reg, NVFX_FP_MASK_Z | NVFX_FP_MASK_W, swz(tmp, X, Y, X, Y), none, none)); + nvfx_fp_emit(fpc, arith(sat, DDY, tmp.reg, NVFX_FP_MASK_X | NVFX_FP_MASK_Y, src[0], none, none)); + nvfx_fp_emit(fpc, arith(0, MOV, dst, mask, tmp, none, none)); + } else { + nvfx_fp_emit(fpc, arith(sat, DDY, dst, mask, src[0], none, none)); + } + break; + case TGSI_OPCODE_DP2: + tmp = nvfx_src(temp(fpc)); + nvfx_fp_emit(fpc, arith(0, MUL, tmp.reg, NVFX_FP_MASK_X | NVFX_FP_MASK_Y, src[0], src[1], none)); + nvfx_fp_emit(fpc, arith(0, ADD, dst, mask, swz(tmp, X, X, X, X), swz(tmp, Y, Y, Y, Y), none)); + break; + case TGSI_OPCODE_DP3: + nvfx_fp_emit(fpc, arith(sat, DP3, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_DP4: + nvfx_fp_emit(fpc, arith(sat, DP4, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_DPH: + tmp = nvfx_src(temp(fpc)); + nvfx_fp_emit(fpc, arith(0, DP3, tmp.reg, NVFX_FP_MASK_X, src[0], src[1], none)); + nvfx_fp_emit(fpc, arith(sat, ADD, dst, mask, swz(tmp, X, X, X, X), swz(src[1], W, W, W, W), none)); + break; + case TGSI_OPCODE_DST: + nvfx_fp_emit(fpc, arith(sat, DST, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_EX2: + nvfx_fp_emit(fpc, arith(sat, EX2, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_FLR: + nvfx_fp_emit(fpc, arith(sat, FLR, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_FRC: + nvfx_fp_emit(fpc, arith(sat, FRC, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_KILP: + nvfx_fp_emit(fpc, arith(0, KIL, none.reg, 0, none, none, none)); + break; + case TGSI_OPCODE_KIL: + insn = arith(0, MOV, none.reg, NVFX_FP_MASK_ALL, src[0], none, none); + insn.cc_update = 1; + nvfx_fp_emit(fpc, insn); + + insn = arith(0, KIL, none.reg, 0, none, none, none); + insn.cc_test = NVFX_COND_LT; + nvfx_fp_emit(fpc, insn); + break; + case TGSI_OPCODE_LG2: + nvfx_fp_emit(fpc, arith(sat, LG2, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_LIT: + if(!nvfx->is_nv4x) + nvfx_fp_emit(fpc, arith(sat, LIT_NV30, dst, mask, src[0], src[1], src[2])); + else { + /* we use FLT_MIN, so that log2 never gives -infinity, and thus multiplication by + * specular 0 always gives 0, so that ex2 gives 1, to satisfy the 0^0 = 1 requirement + * + * NOTE: if we start using half precision, we might need an fp16 FLT_MIN here instead + */ + struct nvfx_src maxs = nvfx_src(nvfx_fp_imm(fpc, 0, FLT_MIN, 0, 0)); + tmp = nvfx_src(temp(fpc)); + if (ci>= 0 || ii >= 0) { + nvfx_fp_emit(fpc, arith(0, MOV, tmp.reg, NVFX_FP_MASK_X | NVFX_FP_MASK_Y, maxs, none, none)); + maxs = tmp; + } + nvfx_fp_emit(fpc, arith(0, MAX, tmp.reg, NVFX_FP_MASK_Y | NVFX_FP_MASK_W, swz(src[0], X, X, X, Y), swz(maxs, X, X, Y, Y), none)); + nvfx_fp_emit(fpc, arith(0, LG2, tmp.reg, NVFX_FP_MASK_W, swz(tmp, W, W, W, W), none, none)); + nvfx_fp_emit(fpc, arith(0, MUL, tmp.reg, NVFX_FP_MASK_W, swz(tmp, W, W, W, W), swz(src[0], W, W, W, W), none)); + nvfx_fp_emit(fpc, arith(sat, LITEX2_NV40, dst, mask, swz(tmp, Y, Y, W, W), none, none)); + } + break; + case TGSI_OPCODE_LRP: + if(!nvfx->is_nv4x) + nvfx_fp_emit(fpc, arith(sat, LRP_NV30, dst, mask, src[0], src[1], src[2])); + else { + tmp = nvfx_src(temp(fpc)); + nvfx_fp_emit(fpc, arith(0, MAD, tmp.reg, mask, neg(src[0]), src[2], src[2])); + nvfx_fp_emit(fpc, arith(sat, MAD, dst, mask, src[0], src[1], tmp)); + } + break; + case TGSI_OPCODE_MAD: + nvfx_fp_emit(fpc, arith(sat, MAD, dst, mask, src[0], src[1], src[2])); + break; + case TGSI_OPCODE_MAX: + nvfx_fp_emit(fpc, arith(sat, MAX, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_MIN: + nvfx_fp_emit(fpc, arith(sat, MIN, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_MOV: + nvfx_fp_emit(fpc, arith(sat, MOV, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_MUL: + nvfx_fp_emit(fpc, arith(sat, MUL, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_NOP: + break; + case TGSI_OPCODE_POW: + if(!nvfx->is_nv4x) + nvfx_fp_emit(fpc, arith(sat, POW_NV30, dst, mask, src[0], src[1], none)); + else { + tmp = nvfx_src(temp(fpc)); + nvfx_fp_emit(fpc, arith(0, LG2, tmp.reg, NVFX_FP_MASK_X, swz(src[0], X, X, X, X), none, none)); + nvfx_fp_emit(fpc, arith(0, MUL, tmp.reg, NVFX_FP_MASK_X, swz(tmp, X, X, X, X), swz(src[1], X, X, X, X), none)); + nvfx_fp_emit(fpc, arith(sat, EX2, dst, mask, swz(tmp, X, X, X, X), none, none)); + } + break; + case TGSI_OPCODE_RCP: + nvfx_fp_emit(fpc, arith(sat, RCP, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_RFL: + if(!nvfx->is_nv4x) + nvfx_fp_emit(fpc, arith(0, RFL_NV30, dst, mask, src[0], src[1], none)); + else { + tmp = nvfx_src(temp(fpc)); + nvfx_fp_emit(fpc, arith(0, DP3, tmp.reg, NVFX_FP_MASK_X, src[0], src[0], none)); + nvfx_fp_emit(fpc, arith(0, DP3, tmp.reg, NVFX_FP_MASK_Y, src[0], src[1], none)); + insn = arith(0, DIV, tmp.reg, NVFX_FP_MASK_Z, swz(tmp, Y, Y, Y, Y), swz(tmp, X, X, X, X), none); + insn.scale = NVFX_FP_OP_DST_SCALE_2X; + nvfx_fp_emit(fpc, insn); + nvfx_fp_emit(fpc, arith(sat, MAD, dst, mask, swz(tmp, Z, Z, Z, Z), src[0], neg(src[1]))); + } + break; + case TGSI_OPCODE_RSQ: + if(!nvfx->is_nv4x) + nvfx_fp_emit(fpc, arith(sat, RSQ_NV30, dst, mask, abs(swz(src[0], X, X, X, X)), none, none)); + else { + tmp = nvfx_src(temp(fpc)); + insn = arith(0, LG2, tmp.reg, NVFX_FP_MASK_X, abs(swz(src[0], X, X, X, X)), none, none); + insn.scale = NVFX_FP_OP_DST_SCALE_INV_2X; + nvfx_fp_emit(fpc, insn); + nvfx_fp_emit(fpc, arith(sat, EX2, dst, mask, neg(swz(tmp, X, X, X, X)), none, none)); + } + break; + case TGSI_OPCODE_SCS: + /* avoid overwriting the source */ + if(src[0].swz[NVFX_SWZ_X] != NVFX_SWZ_X) + { + if (mask & NVFX_FP_MASK_X) + nvfx_fp_emit(fpc, arith(sat, COS, dst, NVFX_FP_MASK_X, swz(src[0], X, X, X, X), none, none)); + if (mask & NVFX_FP_MASK_Y) + nvfx_fp_emit(fpc, arith(sat, SIN, dst, NVFX_FP_MASK_Y, swz(src[0], X, X, X, X), none, none)); + } + else + { + if (mask & NVFX_FP_MASK_Y) + nvfx_fp_emit(fpc, arith(sat, SIN, dst, NVFX_FP_MASK_Y, swz(src[0], X, X, X, X), none, none)); + if (mask & NVFX_FP_MASK_X) + nvfx_fp_emit(fpc, arith(sat, COS, dst, NVFX_FP_MASK_X, swz(src[0], X, X, X, X), none, none)); + } + break; + case TGSI_OPCODE_SEQ: + nvfx_fp_emit(fpc, arith(sat, SEQ, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SFL: + nvfx_fp_emit(fpc, arith(sat, SFL, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SGE: + nvfx_fp_emit(fpc, arith(sat, SGE, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SGT: + nvfx_fp_emit(fpc, arith(sat, SGT, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SIN: + nvfx_fp_emit(fpc, arith(sat, SIN, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_SLE: + nvfx_fp_emit(fpc, arith(sat, SLE, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SLT: + nvfx_fp_emit(fpc, arith(sat, SLT, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SNE: + nvfx_fp_emit(fpc, arith(sat, SNE, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SSG: + { + struct nvfx_src minones = swz(nvfx_src(nvfx_fp_imm(fpc, -1, -1, -1, -1)), X, X, X, X); + + insn = arith(sat, MOV, dst, mask, src[0], none, none); + insn.cc_update = 1; + nvfx_fp_emit(fpc, insn); + + insn = arith(0, STR, dst, mask, none, none, none); + insn.cc_test = NVFX_COND_GT; + nvfx_fp_emit(fpc, insn); + + if(!sat) { + insn = arith(0, MOV, dst, mask, minones, none, none); + insn.cc_test = NVFX_COND_LT; + nvfx_fp_emit(fpc, insn); + } + break; + } + case TGSI_OPCODE_STR: + nvfx_fp_emit(fpc, arith(sat, STR, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SUB: + nvfx_fp_emit(fpc, arith(sat, ADD, dst, mask, src[0], neg(src[1]), none)); + break; + case TGSI_OPCODE_TEX: + nvfx_fp_emit(fpc, tex(sat, TEX, unit, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_TRUNC: + tmp = nvfx_src(temp(fpc)); + insn = arith(0, MOV, none.reg, mask, src[0], none, none); + insn.cc_update = 1; + nvfx_fp_emit(fpc, insn); + + nvfx_fp_emit(fpc, arith(0, FLR, tmp.reg, mask, abs(src[0]), none, none)); + nvfx_fp_emit(fpc, arith(sat, MOV, dst, mask, tmp, none, none)); + + insn = arith(sat, MOV, dst, mask, neg(tmp), none, none); + insn.cc_test = NVFX_COND_LT; + nvfx_fp_emit(fpc, insn); + break; + case TGSI_OPCODE_TXB: + nvfx_fp_emit(fpc, tex(sat, TXB, unit, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_TXL: + if(nvfx->is_nv4x) + nvfx_fp_emit(fpc, tex(sat, TXL_NV40, unit, dst, mask, src[0], none, none)); + else /* unsupported on nv30, use TEX and hope they like it */ + nvfx_fp_emit(fpc, tex(sat, TEX, unit, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_TXP: + nvfx_fp_emit(fpc, tex(sat, TXP, unit, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_XPD: + tmp = nvfx_src(temp(fpc)); + nvfx_fp_emit(fpc, arith(0, MUL, tmp.reg, mask, swz(src[0], Z, X, Y, Y), swz(src[1], Y, Z, X, X), none)); + nvfx_fp_emit(fpc, arith(sat, MAD, dst, (mask & ~NVFX_FP_MASK_W), swz(src[0], Y, Z, X, X), swz(src[1], Z, X, Y, Y), neg(tmp))); + break; + + case TGSI_OPCODE_IF: + // MOVRC0 R31 (TR0.xyzw), R: + // IF (NE.xxxx) ELSE END + if(!nvfx->use_nv4x) + goto nv3x_cflow; + nv40_fp_if(fpc, src[0]); + break; + + case TGSI_OPCODE_ELSE: + { + uint32_t *hw; + if(!nvfx->use_nv4x) + goto nv3x_cflow; + assert(util_dynarray_contains(&fpc->if_stack, unsigned)); + hw = &fpc->fp->insn[util_dynarray_top(&fpc->if_stack, unsigned)]; + hw[2] = NV40_FP_OP_OPCODE_IS_BRANCH | fpc->fp->insn_len; + break; + } + + case TGSI_OPCODE_ENDIF: + { + uint32_t *hw; + if(!nvfx->use_nv4x) + goto nv3x_cflow; + assert(util_dynarray_contains(&fpc->if_stack, unsigned)); + hw = &fpc->fp->insn[util_dynarray_pop(&fpc->if_stack, unsigned)]; + if(!hw[2]) + hw[2] = NV40_FP_OP_OPCODE_IS_BRANCH | fpc->fp->insn_len; + hw[3] = fpc->fp->insn_len; + break; + } + + case TGSI_OPCODE_BRA: + /* This can in limited cases be implemented with an IF with the else and endif labels pointing to the target */ + /* no state tracker uses this, so don't implement this for now */ + assert(0); + nv40_fp_bra(fpc, finst->Label.Label); + break; + + case TGSI_OPCODE_BGNSUB: + case TGSI_OPCODE_ENDSUB: + /* nothing to do here */ + break; + + case TGSI_OPCODE_CAL: + if(!nvfx->use_nv4x) + goto nv3x_cflow; + nv40_fp_cal(fpc, finst->Label.Label); + break; + + case TGSI_OPCODE_RET: + if(!nvfx->use_nv4x) + goto nv3x_cflow; + nv40_fp_ret(fpc); + break; + + case TGSI_OPCODE_BGNLOOP: + if(!nvfx->use_nv4x) + goto nv3x_cflow; + /* TODO: we should support using two nested REPs to allow a > 255 iteration count */ + nv40_fp_rep(fpc, 255, finst->Label.Label); + break; + + case TGSI_OPCODE_ENDLOOP: + break; + + case TGSI_OPCODE_BRK: + if(!nvfx->use_nv4x) + goto nv3x_cflow; + nv40_fp_brk(fpc); + break; + + case TGSI_OPCODE_CONT: + { + static int warned = 0; + if(!warned) { + NOUVEAU_ERR("Sorry, the continue keyword is not implemented: ignoring it.\n"); + warned = 1; + } + break; + } + + default: + NOUVEAU_ERR("invalid opcode %d\n", finst->Instruction.Opcode); + return FALSE; + } + +out: + release_temps(fpc); + return TRUE; +nv3x_cflow: + { + static int warned = 0; + if(!warned) { + NOUVEAU_ERR( + "Sorry, control flow instructions are not supported in hardware on nv3x: ignoring them\n" + "If rendering is incorrect, try to disable GLSL support in the application.\n"); + warned = 1; + } + } + goto out; +} + +static boolean +nvfx_fragprog_parse_decl_output(struct nvfx_context* nvfx, struct nvfx_fpc *fpc, + const struct tgsi_full_declaration *fdec) +{ + unsigned idx = fdec->Range.First; + unsigned hw; + + switch (fdec->Semantic.Name) { + case TGSI_SEMANTIC_POSITION: + hw = 1; + break; + case TGSI_SEMANTIC_COLOR: + hw = ~0; + switch (fdec->Semantic.Index) { + case 0: hw = 0; break; + case 1: hw = 2; break; + case 2: hw = 3; break; + case 3: hw = 4; break; + } + if(hw > ((nvfx->use_nv4x) ? 4 : 2)) { + NOUVEAU_ERR("bad rcol index\n"); + return FALSE; + } + break; + default: + NOUVEAU_ERR("bad output semantic\n"); + return FALSE; + } + + fpc->r_result[idx] = nvfx_reg(NVFXSR_OUTPUT, hw); + fpc->r_temps |= (1ULL << hw); + return TRUE; +} + +static boolean +nvfx_fragprog_prepare(struct nvfx_context* nvfx, struct nvfx_fpc *fpc) +{ + struct tgsi_parse_context p; + int high_temp = -1, i; + struct util_semantic_set set; + unsigned num_texcoords = nvfx->use_nv4x ? 10 : 8; + + fpc->fp->num_slots = util_semantic_set_from_program_file(&set, fpc->pfp->pipe.tokens, TGSI_FILE_INPUT); + if(fpc->fp->num_slots > num_texcoords) + return FALSE; + util_semantic_layout_from_set(fpc->fp->slot_to_generic, &set, 0, num_texcoords); + util_semantic_table_from_layout(fpc->generic_to_slot, fpc->fp->slot_to_generic, 0, num_texcoords); + + memset(fpc->fp->slot_to_fp_input, 0xff, sizeof(fpc->fp->slot_to_fp_input)); + + fpc->r_imm = CALLOC(fpc->pfp->info.immediate_count, sizeof(struct nvfx_reg)); + + tgsi_parse_init(&p, fpc->pfp->pipe.tokens); + while (!tgsi_parse_end_of_tokens(&p)) { + const union tgsi_full_token *tok = &p.FullToken; + + tgsi_parse_token(&p); + switch(tok->Token.Type) { + case TGSI_TOKEN_TYPE_DECLARATION: + { + const struct tgsi_full_declaration *fdec; + fdec = &p.FullToken.FullDeclaration; + switch (fdec->Declaration.File) { + case TGSI_FILE_OUTPUT: + if (!nvfx_fragprog_parse_decl_output(nvfx, fpc, fdec)) + goto out_err; + break; + case TGSI_FILE_TEMPORARY: + if (fdec->Range.Last > high_temp) { + high_temp = + fdec->Range.Last; + } + break; + default: + break; + } + } + break; + case TGSI_TOKEN_TYPE_IMMEDIATE: + { + struct tgsi_full_immediate *imm; + + imm = &p.FullToken.FullImmediate; + assert(imm->Immediate.DataType == TGSI_IMM_FLOAT32); + assert(fpc->nr_imm < fpc->pfp->info.immediate_count); + + fpc->r_imm[fpc->nr_imm++] = nvfx_fp_imm(fpc, imm->u[0].Float, imm->u[1].Float, imm->u[2].Float, imm->u[3].Float); + break; + } + default: + break; + } + } + tgsi_parse_free(&p); + + if (++high_temp) { + fpc->r_temp = CALLOC(high_temp, sizeof(struct nvfx_reg)); + for (i = 0; i < high_temp; i++) + fpc->r_temp[i] = temp(fpc); + fpc->r_temps_discard = 0ULL; + } + + return TRUE; + +out_err: + if (fpc->r_temp) { + FREE(fpc->r_temp); + fpc->r_temp = NULL; + } + tgsi_parse_free(&p); + return FALSE; +} + +DEBUG_GET_ONCE_BOOL_OPTION(nvfx_dump_fp, "NVFX_DUMP_FP", FALSE) + +static struct nvfx_fragment_program* +nvfx_fragprog_translate(struct nvfx_context *nvfx, + struct nvfx_pipe_fragment_program *pfp, + boolean emulate_sprite_flipping) +{ + struct tgsi_parse_context parse; + struct nvfx_fpc *fpc = NULL; + struct util_dynarray insns; + struct nvfx_fragment_program* fp = NULL; + const int min_size = 4096; + + fp = CALLOC_STRUCT(nvfx_fragment_program); + if(!fp) + goto out_err; + + fpc = CALLOC_STRUCT(nvfx_fpc); + if (!fpc) + goto out_err; + + fpc->max_temps = nvfx->use_nv4x ? 48 : 32; + fpc->pfp = pfp; + fpc->fp = fp; + fpc->num_regs = 2; + + for (unsigned i = 0; i < pfp->info.num_properties; ++i) { + if (pfp->info.properties[i].name == TGSI_PROPERTY_FS_COORD_ORIGIN) { + if(pfp->info.properties[i].data[0]) + fp->coord_conventions |= NV30_3D_COORD_CONVENTIONS_ORIGIN_INVERTED; + } else if (pfp->info.properties[i].name == TGSI_PROPERTY_FS_COORD_PIXEL_CENTER) { + if(pfp->info.properties[i].data[0]) + fp->coord_conventions |= NV30_3D_COORD_CONVENTIONS_CENTER_INTEGER; + } + } + + if (!nvfx_fragprog_prepare(nvfx, fpc)) + goto out_err; + + tgsi_parse_init(&parse, pfp->pipe.tokens); + util_dynarray_init(&insns); + + if(emulate_sprite_flipping) + { + struct nvfx_reg reg = temp(fpc); + struct nvfx_src sprite_input = nvfx_src(nvfx_reg(NVFXSR_RELOCATED, fp->num_slots)); + struct nvfx_src imm = nvfx_src(nvfx_fp_imm(fpc, 1, -1, 0, 0)); + + fpc->sprite_coord_temp = reg.index; + fpc->r_temps_discard = 0ULL; + nvfx_fp_emit(fpc, arith(0, MAD, reg, NVFX_FP_MASK_ALL, sprite_input, swz(imm, X, Y, X, X), swz(imm, Z, X, Z, Z))); + } + + while (!tgsi_parse_end_of_tokens(&parse)) { + tgsi_parse_token(&parse); + + switch (parse.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_INSTRUCTION: + { + const struct tgsi_full_instruction *finst; + + util_dynarray_append(&insns, unsigned, fp->insn_len); + finst = &parse.FullToken.FullInstruction; + if (!nvfx_fragprog_parse_instruction(nvfx, fpc, finst)) + goto out_err; + } + break; + default: + break; + } + } + util_dynarray_append(&insns, unsigned, fp->insn_len); + + for(unsigned i = 0; i < fpc->label_relocs.size; i += sizeof(struct nvfx_relocation)) + { + struct nvfx_relocation* label_reloc = (struct nvfx_relocation*)((char*)fpc->label_relocs.data + i); + fp->insn[label_reloc->location] |= ((unsigned*)insns.data)[label_reloc->target]; + } + util_dynarray_fini(&insns); + + if(!nvfx->is_nv4x) + fp->fp_control |= (fpc->num_regs-1)/2; + else + fp->fp_control |= fpc->num_regs << NV40_3D_FP_CONTROL_TEMP_COUNT__SHIFT; + + /* Terminate final instruction */ + if(fp->insn) + fp->insn[fpc->inst_offset] |= 0x00000001; + + /* Append NOP + END instruction for branches to the end of the program */ + fpc->inst_offset = fp->insn_len; + grow_insns(fpc, 4); + fp->insn[fpc->inst_offset + 0] = 0x00000001; + fp->insn[fpc->inst_offset + 1] = 0x00000000; + fp->insn[fpc->inst_offset + 2] = 0x00000000; + fp->insn[fpc->inst_offset + 3] = 0x00000000; + + if(debug_get_option_nvfx_dump_fp()) + { + debug_printf("\n"); + tgsi_dump(pfp->pipe.tokens, 0); + + debug_printf("\n%s fragment program:\n", nvfx->is_nv4x ? "nv4x" : "nv3x"); + for (unsigned i = 0; i < fp->insn_len; i += 4) + debug_printf("%3u: %08x %08x %08x %08x\n", i >> 2, fp->insn[i], fp->insn[i + 1], fp->insn[i + 2], fp->insn[i + 3]); + debug_printf("\n"); + } + + fp->prog_size = (fp->insn_len * 4 + 63) & ~63; + + if(fp->prog_size >= min_size) + fp->progs_per_bo = 1; + else + fp->progs_per_bo = min_size / fp->prog_size; + fp->bo_prog_idx = fp->progs_per_bo - 1; + +out: + tgsi_parse_free(&parse); + if(fpc) + { + if (fpc->r_temp) + FREE(fpc->r_temp); + util_dynarray_fini(&fpc->if_stack); + util_dynarray_fini(&fpc->label_relocs); + util_dynarray_fini(&fpc->imm_data); + //util_dynarray_fini(&fpc->loop_stack); + FREE(fpc); + } + return fp; + +out_err: + _debug_printf("Error: failed to compile this fragment program:\n"); + tgsi_dump(pfp->pipe.tokens, 0); + + if(fp) + { + FREE(fp); + fp = NULL; + } + goto out; +} + +static inline void +nvfx_fp_memcpy(void* dst, const void* src, size_t len) +{ +#ifndef WORDS_BIGENDIAN + memcpy(dst, src, len); +#else + size_t i; + for(i = 0; i < len; i += 4) { + uint32_t v = (uint32_t*)((char*)src + i); + *(uint32_t*)((char*)dst + i) = (v >> 16) | (v << 16); + } +#endif +} + +/* The hardware only supports immediate constants inside the fragment program, + * and at least on nv30 doesn't support an indirect linkage table. + * + * Hence, we need to patch the fragment program itself both to update constants + * and update linkage. + * + * Using a single fragment program would entail unacceptable stalls if the GPU is + * already rendering with that fragment program. + * Thus, we instead use a "rotating queue" of buffer objects, each of which is + * packed with multiple versions of the same program. + * + * Whenever we need to patch something, we move to the next program and + * patch it. If all buffer objects are in use by the GPU, we allocate another one, + * expanding the queue. + * + * As an additional optimization, we record when all the programs have the + * current input slot configuration, and at that point we stop patching inputs. + * This happens, for instance, if a given fragment program is always used with + * the same vertex program (i.e. always with GLSL), or if the layouts match + * enough (non-GLSL). + * + * Note that instead of using multiple programs, we could push commands + * on the FIFO to patch a single program: it's not fully clear which option is + * faster, but my guess is that the current way is faster. + * + * We also track the previous slot assignments for each version and don't + * patch if they are the same (this could perhaps be removed). + */ + +void +nvfx_fragprog_validate(struct nvfx_context *nvfx) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + struct nvfx_pipe_fragment_program *pfp = nvfx->fragprog; + struct nvfx_vertex_program* vp; + + // TODO: the multiplication by point_quad_rasterization is probably superfluous + unsigned sprite_coord_enable = nvfx->rasterizer->pipe.point_quad_rasterization * nvfx->rasterizer->pipe.sprite_coord_enable; + + boolean emulate_sprite_flipping = sprite_coord_enable && nvfx->rasterizer->pipe.sprite_coord_mode; + unsigned key = emulate_sprite_flipping; + struct nvfx_fragment_program* fp; + + fp = pfp->fps[key]; + if (!fp) + { + fp = nvfx_fragprog_translate(nvfx, pfp, emulate_sprite_flipping); + + if(!fp) + { + if(!nvfx->dummy_fs) + { + struct ureg_program *ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT ); + if (ureg) + { + ureg_END( ureg ); + nvfx->dummy_fs = ureg_create_shader_and_destroy( ureg, &nvfx->pipe ); + } + + if(!nvfx->dummy_fs) + { + _debug_printf("Error: unable to create a dummy fragment shader: aborting."); + abort(); + } + } + + fp = nvfx_fragprog_translate(nvfx, nvfx->dummy_fs, FALSE); + emulate_sprite_flipping = FALSE; + + if(!fp) + { + _debug_printf("Error: unable to compile even a dummy fragment shader: aborting."); + abort(); + } + } + + pfp->fps[key] = fp; + } + + vp = nvfx->hw_vertprog; + + if (fp->last_vp_id != vp->id || fp->last_sprite_coord_enable != sprite_coord_enable) { + int sprite_real_input = -1; + int sprite_reloc_input; + unsigned i; + fp->last_vp_id = vp->id; + fp->last_sprite_coord_enable = sprite_coord_enable; + + if(sprite_coord_enable) + { + sprite_real_input = vp->sprite_fp_input; + if(sprite_real_input < 0) + { + unsigned used_texcoords = 0; + for(unsigned i = 0; i < fp->num_slots; ++i) { + unsigned generic = fp->slot_to_generic[i]; + if((generic < 32) && !((1 << generic) & sprite_coord_enable)) + { + unsigned char slot_mask = vp->generic_to_fp_input[generic]; + if(slot_mask >= 0xf0) + used_texcoords |= 1 << ((slot_mask & 0xf) - NVFX_FP_OP_INPUT_SRC_TC0); + } + } + + sprite_real_input = NVFX_FP_OP_INPUT_SRC_TC(__builtin_ctz(~used_texcoords)); + } + + fp->point_sprite_control |= (1 << (sprite_real_input - NVFX_FP_OP_INPUT_SRC_TC0 + 8)); + } + else + fp->point_sprite_control = 0; + + if(emulate_sprite_flipping) + sprite_reloc_input = 0; + else + sprite_reloc_input = sprite_real_input; + + for(i = 0; i < fp->num_slots; ++i) { + unsigned generic = fp->slot_to_generic[i]; + if((generic < 32) && ((1 << generic) & sprite_coord_enable)) + { + if(fp->slot_to_fp_input[i] != sprite_reloc_input) + goto update_slots; + } + else + { + unsigned char slot_mask = vp->generic_to_fp_input[generic]; + if((slot_mask >> 4) & (slot_mask ^ fp->slot_to_fp_input[i])) + goto update_slots; + } + } + + if(emulate_sprite_flipping) + { + if(fp->slot_to_fp_input[fp->num_slots] != sprite_real_input) + goto update_slots; + } + + if(0) + { +update_slots: + /* optimization: we start updating from the slot we found the first difference in */ + for(; i < fp->num_slots; ++i) + { + unsigned generic = fp->slot_to_generic[i]; + if((generic < 32) && ((1 << generic) & sprite_coord_enable)) + fp->slot_to_fp_input[i] = sprite_reloc_input; + else + fp->slot_to_fp_input[i] = vp->generic_to_fp_input[generic] & 0xf; + } + + fp->slot_to_fp_input[fp->num_slots] = sprite_real_input; + + if(nvfx->is_nv4x) + { + fp->or = 0; + for(i = 0; i <= fp->num_slots; ++i) { + unsigned fp_input = fp->slot_to_fp_input[i]; + if(fp_input == NVFX_FP_OP_INPUT_SRC_TC(8)) + fp->or |= (1 << 12); + else if(fp_input == NVFX_FP_OP_INPUT_SRC_TC(9)) + fp->or |= (1 << 13); + else if(fp_input >= NVFX_FP_OP_INPUT_SRC_TC(0) && fp_input <= NVFX_FP_OP_INPUT_SRC_TC(7)) + fp->or |= (1 << (fp_input - NVFX_FP_OP_INPUT_SRC_TC0 + 14)); + } + } + + fp->progs_left_with_obsolete_slot_assignments = fp->progs; + goto update; + } + } + + /* We must update constants even on "just" fragprog changes, because + * we don't check whether the current constant buffer matches the latest + * one bound to this fragment program. + * Doing such a check would likely be a pessimization. + */ + if ((nvfx->hw_fragprog != fp) || (nvfx->dirty & (NVFX_NEW_FRAGPROG | NVFX_NEW_FRAGCONST))) { + int offset; + uint32_t* fpmap; + +update: + ++fp->bo_prog_idx; + if(fp->bo_prog_idx >= fp->progs_per_bo) + { + if(fp->fpbo && !nouveau_bo_busy(fp->fpbo->next->bo, NOUVEAU_BO_WR)) + { + fp->fpbo = fp->fpbo->next; + } + else + { + struct nvfx_fragment_program_bo* fpbo = os_malloc_aligned(sizeof(struct nvfx_fragment_program) + (fp->prog_size + 8) * fp->progs_per_bo, 16); + uint8_t* map; + uint8_t* buf; + + fpbo->slots = (unsigned char*)&fpbo->insn[(fp->prog_size) * fp->progs_per_bo]; + memset(fpbo->slots, 0, 8 * fp->progs_per_bo); + if(fp->fpbo) + { + fpbo->next = fp->fpbo->next; + fp->fpbo->next = fpbo; + } + else + fpbo->next = fpbo; + fp->fpbo = fpbo; + fpbo->bo = 0; + fp->progs += fp->progs_per_bo; + fp->progs_left_with_obsolete_slot_assignments += fp->progs_per_bo; + nouveau_bo_new(nvfx->screen->base.device, NOUVEAU_BO_VRAM | NOUVEAU_BO_MAP, 64, fp->prog_size * fp->progs_per_bo, &fpbo->bo); + nouveau_bo_map(fpbo->bo, NOUVEAU_BO_NOSYNC); + + map = fpbo->bo->map; + buf = (uint8_t*)fpbo->insn; + for(unsigned i = 0; i < fp->progs_per_bo; ++i) + { + memcpy(buf, fp->insn, fp->insn_len * 4); + nvfx_fp_memcpy(map, fp->insn, fp->insn_len * 4); + map += fp->prog_size; + buf += fp->prog_size; + } + } + fp->bo_prog_idx = 0; + } + + offset = fp->bo_prog_idx * fp->prog_size; + fpmap = (uint32_t*)((char*)fp->fpbo->bo->map + offset); + + if(nvfx->constbuf[PIPE_SHADER_FRAGMENT]) { + struct pipe_resource* constbuf = nvfx->constbuf[PIPE_SHADER_FRAGMENT]; + uint32_t* map = (uint32_t*)nvfx_buffer(constbuf)->data; + uint32_t* fpmap = (uint32_t*)((char*)fp->fpbo->bo->map + offset); + uint32_t* buf = (uint32_t*)((char*)fp->fpbo->insn + offset); + int i; + for (i = 0; i < fp->nr_consts; ++i) { + unsigned off = fp->consts[i].offset; + unsigned idx = fp->consts[i].index * 4; + + /* TODO: is checking a good idea? */ + if(memcmp(&buf[off], &map[idx], 4 * sizeof(uint32_t))) { + memcpy(&buf[off], &map[idx], 4 * sizeof(uint32_t)); + nvfx_fp_memcpy(&fpmap[off], &map[idx], 4 * sizeof(uint32_t)); + } + } + } + + /* we only do this if we aren't sure that all program versions have the + * current slot assignments, otherwise we just update constants for speed + */ + if(fp->progs_left_with_obsolete_slot_assignments) { + unsigned char* fpbo_slots = &fp->fpbo->slots[fp->bo_prog_idx * 8]; + /* also relocate sprite coord slot, if any */ + for(unsigned i = 0; i <= fp->num_slots; ++i) { + unsigned value = fp->slot_to_fp_input[i];; + if(value != fpbo_slots[i]) { + unsigned* p; + unsigned* begin = (unsigned*)fp->slot_relocations[i].data; + unsigned* end = (unsigned*)((char*)fp->slot_relocations[i].data + fp->slot_relocations[i].size); + //printf("fp %p reloc slot %u/%u: %u -> %u\n", fp, i, fp->num_slots, fpbo_slots[i], value); + if(value == 0) + { + /* was relocated to an input, switch type to temporary */ + for(p = begin; p != end; ++p) { + unsigned off = *p; + unsigned dw = fp->insn[off]; + dw &=~ NVFX_FP_REG_TYPE_MASK; + //printf("reloc_tmp at %x\n", off); + nvfx_fp_memcpy(&fpmap[off], &dw, sizeof(dw)); + } + } else { + if(!fpbo_slots[i]) + { + /* was relocated to a temporary, switch type to input */ + for(p= begin; p != end; ++p) { + unsigned off = *p; + unsigned dw = fp->insn[off]; + //printf("reloc_in at %x\n", off); + dw |= NVFX_FP_REG_TYPE_INPUT << NVFX_FP_REG_TYPE_SHIFT; + nvfx_fp_memcpy(&fpmap[off], &dw, sizeof(dw)); + } + } + + /* set the correct input index */ + for(p = begin; p != end; ++p) { + unsigned off = *p & ~3; + unsigned dw = fp->insn[off]; + //printf("reloc&~3 at %x\n", off); + dw = (dw & ~NVFX_FP_OP_INPUT_SRC_MASK) | (value << NVFX_FP_OP_INPUT_SRC_SHIFT); + nvfx_fp_memcpy(&fpmap[off], &dw, sizeof(dw)); + } + } + fpbo_slots[i] = value; + } + } + --fp->progs_left_with_obsolete_slot_assignments; + } + + nvfx->hw_fragprog = fp; + + MARK_RING(chan, 8, 1); + OUT_RING(chan, RING_3D(NV30_3D_FP_ACTIVE_PROGRAM, 1)); + OUT_RELOC(chan, fp->fpbo->bo, offset, NOUVEAU_BO_VRAM | + NOUVEAU_BO_GART | NOUVEAU_BO_RD | NOUVEAU_BO_LOW | + NOUVEAU_BO_OR, NV30_3D_FP_ACTIVE_PROGRAM_DMA0, + NV30_3D_FP_ACTIVE_PROGRAM_DMA1); + OUT_RING(chan, RING_3D(NV30_3D_FP_CONTROL, 1)); + OUT_RING(chan, fp->fp_control); + if(!nvfx->is_nv4x) { + OUT_RING(chan, RING_3D(NV30_3D_FP_REG_CONTROL, 1)); + OUT_RING(chan, (1<<16)|0x4); + OUT_RING(chan, RING_3D(NV30_3D_TEX_UNITS_ENABLE, 1)); + OUT_RING(chan, fp->samplers); + } + } + + { + unsigned pointsprite_control = fp->point_sprite_control | nvfx->rasterizer->pipe.point_quad_rasterization; + if(pointsprite_control != nvfx->hw_pointsprite_control) + { + WAIT_RING(chan, 2); + OUT_RING(chan, RING_3D(NV30_3D_POINT_SPRITE, 1)); + OUT_RING(chan, pointsprite_control); + nvfx->hw_pointsprite_control = pointsprite_control; + } + } + + nvfx->relocs_needed &=~ NVFX_RELOCATE_FRAGPROG; +} + +void +nvfx_fragprog_relocate(struct nvfx_context *nvfx) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + struct nvfx_fragment_program *fp = nvfx->hw_fragprog; + struct nouveau_bo* bo = fp->fpbo->bo; + int offset = fp->bo_prog_idx * fp->prog_size; + unsigned fp_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_RD; // TODO: GART? + fp_flags |= NOUVEAU_BO_DUMMY; + MARK_RING(chan, 2, 2); + OUT_RELOC(chan, bo, RING_3D(NV30_3D_FP_ACTIVE_PROGRAM, 1), fp_flags, 0, 0); + OUT_RELOC(chan, bo, offset, fp_flags | NOUVEAU_BO_LOW | + NOUVEAU_BO_OR, NV30_3D_FP_ACTIVE_PROGRAM_DMA0, + NV30_3D_FP_ACTIVE_PROGRAM_DMA1); + nvfx->relocs_needed &=~ NVFX_RELOCATE_FRAGPROG; +} + +void +nvfx_fragprog_destroy(struct nvfx_context *nvfx, + struct nvfx_fragment_program *fp) +{ + unsigned i; + struct nvfx_fragment_program_bo* fpbo = fp->fpbo; + if(fpbo) + { + do + { + struct nvfx_fragment_program_bo* next = fpbo->next; + nouveau_bo_unmap(fpbo->bo); + nouveau_bo_ref(0, &fpbo->bo); + os_free_aligned(fpbo); + fpbo = next; + } + while(fpbo != fp->fpbo); + } + + for(i = 0; i < Elements(fp->slot_relocations); ++i) + util_dynarray_fini(&fp->slot_relocations[i]); + + if (fp->insn_len) + FREE(fp->insn); +} + +static void * +nvfx_fp_state_create(struct pipe_context *pipe, + const struct pipe_shader_state *cso) +{ + struct nvfx_pipe_fragment_program *pfp; + + pfp = CALLOC(1, sizeof(struct nvfx_pipe_fragment_program)); + pfp->pipe.tokens = tgsi_dup_tokens(cso->tokens); + + tgsi_scan_shader(pfp->pipe.tokens, &pfp->info); + + return (void *)pfp; +} + +static void +nvfx_fp_state_bind(struct pipe_context *pipe, void *hwcso) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + nvfx->fragprog = hwcso; + nvfx->dirty |= NVFX_NEW_FRAGPROG; +} + +static void +nvfx_fp_state_delete(struct pipe_context *pipe, void *hwcso) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + struct nvfx_pipe_fragment_program *pfp = hwcso; + unsigned i; + + for(i = 0; i < Elements(pfp->fps); ++i) + { + if(pfp->fps[i]) + { + nvfx_fragprog_destroy(nvfx, pfp->fps[i]); + FREE(pfp->fps[i]); + } + } + + FREE((void*)pfp->pipe.tokens); + FREE(pfp); +} + +void +nvfx_init_fragprog_functions(struct nvfx_context *nvfx) +{ + nvfx->pipe.create_fs_state = nvfx_fp_state_create; + nvfx->pipe.bind_fs_state = nvfx_fp_state_bind; + nvfx->pipe.delete_fs_state = nvfx_fp_state_delete; +} diff --git a/src/gallium/drivers/nvfx/nvfx_fragtex.c b/src/gallium/drivers/nvfx/nvfx_fragtex.c new file mode 100644 index 0000000..fd0aff6 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_fragtex.c @@ -0,0 +1,359 @@ +#include "nvfx_context.h" +#include "nvfx_resource.h" +#include "nvfx_tex.h" + +static void * +nvfx_sampler_state_create(struct pipe_context *pipe, + const struct pipe_sampler_state *cso) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + struct nvfx_sampler_state *ps; + + ps = MALLOC(sizeof(struct nvfx_sampler_state)); + + /* on nv30, we use this as an internal flag */ + ps->fmt = cso->normalized_coords ? 0 : NV40_3D_TEX_FORMAT_RECT; + ps->en = 0; + ps->filt = nvfx_tex_filter(cso) | 0x2000; /*voodoo*/ + ps->wrap = (nvfx_tex_wrap_mode(cso->wrap_s) << NV30_3D_TEX_WRAP_S__SHIFT) | + (nvfx_tex_wrap_mode(cso->wrap_t) << NV30_3D_TEX_WRAP_T__SHIFT) | + (nvfx_tex_wrap_mode(cso->wrap_r) << NV30_3D_TEX_WRAP_R__SHIFT); + ps->compare = FALSE; + + if(cso->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) + { + ps->wrap |= nvfx_tex_wrap_compare_mode(cso->compare_func); + ps->compare = TRUE; + } + ps->bcol = nvfx_tex_border_color(cso->border_color); + + if(nvfx->is_nv4x) + nv40_sampler_state_init(pipe, ps, cso); + else + nv30_sampler_state_init(pipe, ps, cso); + + return (void *)ps; +} + +static void +nvfx_sampler_state_delete(struct pipe_context *pipe, void *hwcso) +{ + FREE(hwcso); +} + +static void +nvfx_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **sampler) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + unsigned unit; + + for (unit = 0; unit < nr; unit++) { + nvfx->tex_sampler[unit] = sampler[unit]; + nvfx->dirty_samplers |= (1 << unit); + } + + for (unit = nr; unit < nvfx->nr_samplers; unit++) { + nvfx->tex_sampler[unit] = NULL; + nvfx->dirty_samplers |= (1 << unit); + } + + nvfx->nr_samplers = nr; + nvfx->dirty |= NVFX_NEW_SAMPLER; +} + +static struct pipe_sampler_view * +nvfx_create_sampler_view(struct pipe_context *pipe, + struct pipe_resource *pt, + const struct pipe_sampler_view *templ) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + struct nvfx_sampler_view *sv = CALLOC_STRUCT(nvfx_sampler_view); + struct nvfx_texture_format *tf = &nvfx_texture_formats[templ->format]; + unsigned txf; + + if (!sv) + return NULL; + + sv->base = *templ; + sv->base.reference.count = 1; + sv->base.texture = NULL; + pipe_resource_reference(&sv->base.texture, pt); + sv->base.context = pipe; + + txf = NV30_3D_TEX_FORMAT_NO_BORDER; + + switch (pt->target) { + case PIPE_TEXTURE_CUBE: + txf |= NV30_3D_TEX_FORMAT_CUBIC; + /* fall-through */ + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + txf |= NV30_3D_TEX_FORMAT_DIMS_2D; + break; + case PIPE_TEXTURE_3D: + txf |= NV30_3D_TEX_FORMAT_DIMS_3D; + break; + case PIPE_TEXTURE_1D: + txf |= NV30_3D_TEX_FORMAT_DIMS_1D; + break; + default: + assert(0); + } + sv->u.init_fmt = txf; + + sv->swizzle = 0 + | (tf->src[sv->base.swizzle_r] << NV30_3D_TEX_SWIZZLE_S0_Z__SHIFT) + | (tf->src[sv->base.swizzle_g] << NV30_3D_TEX_SWIZZLE_S0_Y__SHIFT) + | (tf->src[sv->base.swizzle_b] << NV30_3D_TEX_SWIZZLE_S0_X__SHIFT) + | (tf->src[sv->base.swizzle_a] << NV30_3D_TEX_SWIZZLE_S0_W__SHIFT) + | (tf->comp[sv->base.swizzle_r] << NV30_3D_TEX_SWIZZLE_S1_Z__SHIFT) + | (tf->comp[sv->base.swizzle_g] << NV30_3D_TEX_SWIZZLE_S1_Y__SHIFT) + | (tf->comp[sv->base.swizzle_b] << NV30_3D_TEX_SWIZZLE_S1_X__SHIFT) + | (tf->comp[sv->base.swizzle_a] << NV30_3D_TEX_SWIZZLE_S1_W__SHIFT); + + sv->filt = tf->sign; + sv->wrap = tf->wrap; + sv->wrap_mask = ~0; + + if (pt->target == PIPE_TEXTURE_CUBE) + { + sv->offset = 0; + sv->npot_size = (pt->width0 << NV30_3D_TEX_NPOT_SIZE_W__SHIFT) | pt->height0; + } + else + { + sv->offset = nvfx_subresource_offset(pt, 0, sv->base.u.tex.first_level, 0); + sv->npot_size = (u_minify(pt->width0, sv->base.u.tex.first_level) << NV30_3D_TEX_NPOT_SIZE_W__SHIFT) | u_minify(pt->height0, sv->base.u.tex.first_level); + + /* apparently, we need to ignore the t coordinate for 1D textures to fix piglit tex1d-2dborder */ + if(pt->target == PIPE_TEXTURE_1D) + { + sv->wrap_mask &=~ NV30_3D_TEX_WRAP_T__MASK; + sv->wrap |= NV30_3D_TEX_WRAP_T_REPEAT; + } + } + + if(nvfx->is_nv4x) + nv40_sampler_view_init(pipe, sv); + else + nv30_sampler_view_init(pipe, sv); + + return &sv->base; +} + +static void +nvfx_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_resource_reference(&view->texture, NULL); + FREE(view); +} + +static void +nvfx_set_fragment_sampler_views(struct pipe_context *pipe, + unsigned nr, + struct pipe_sampler_view **views) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + unsigned unit; + + for (unit = 0; unit < nr; unit++) { + pipe_sampler_view_reference(&nvfx->fragment_sampler_views[unit], + views[unit]); + nvfx->dirty_samplers |= (1 << unit); + } + + for (unit = nr; unit < nvfx->nr_textures; unit++) { + pipe_sampler_view_reference(&nvfx->fragment_sampler_views[unit], + NULL); + nvfx->dirty_samplers |= (1 << unit); + } + + nvfx->nr_textures = nr; + nvfx->dirty |= NVFX_NEW_SAMPLER; +} + +void +nvfx_fragtex_validate(struct nvfx_context *nvfx) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + unsigned samplers, unit; + + samplers = nvfx->dirty_samplers; + if(!samplers) + return; + + while (samplers) { + unit = ffs(samplers) - 1; + samplers &= ~(1 << unit); + + if(nvfx->fragment_sampler_views[unit] && nvfx->tex_sampler[unit]) { + util_dirty_surfaces_use_for_sampling(&nvfx->pipe, + &((struct nvfx_miptree*)nvfx->fragment_sampler_views[unit]->texture)->dirty_surfaces, + nvfx_surface_flush); + + if(!nvfx->is_nv4x) + nv30_fragtex_set(nvfx, unit); + else + nv40_fragtex_set(nvfx, unit); + } else { + WAIT_RING(chan, 2); + /* this is OK for nv40 too */ + OUT_RING(chan, RING_3D(NV30_3D_TEX_ENABLE(unit), 1)); + OUT_RING(chan, 0); + nvfx->hw_samplers &= ~(1 << unit); + } + } + nvfx->dirty_samplers = 0; + nvfx->relocs_needed &=~ NVFX_RELOCATE_FRAGTEX; +} + +void +nvfx_fragtex_relocate(struct nvfx_context *nvfx) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + unsigned samplers, unit; + unsigned tex_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD; + + samplers = nvfx->hw_samplers; + while (samplers) { + struct nvfx_miptree* mt; + struct nouveau_bo *bo; + + unit = ffs(samplers) - 1; + samplers &= ~(1 << unit); + + mt = (struct nvfx_miptree*)nvfx->fragment_sampler_views[unit]->texture; + bo = mt->base.bo; + + MARK_RING(chan, 3, 3); + OUT_RELOC(chan, bo, RING_3D(NV30_3D_TEX_OFFSET(unit), 2), tex_flags | NOUVEAU_BO_DUMMY, 0, 0); + OUT_RELOC(chan, bo, 0, tex_flags | NOUVEAU_BO_LOW | NOUVEAU_BO_DUMMY, 0, 0); + OUT_RELOC(chan, bo, nvfx->hw_txf[unit], tex_flags | NOUVEAU_BO_OR | NOUVEAU_BO_DUMMY, + NV30_3D_TEX_FORMAT_DMA0, NV30_3D_TEX_FORMAT_DMA1); + } + nvfx->relocs_needed &=~ NVFX_RELOCATE_FRAGTEX; +} + +void +nvfx_init_sampling_functions(struct nvfx_context *nvfx) +{ + nvfx->pipe.create_sampler_state = nvfx_sampler_state_create; + nvfx->pipe.bind_fragment_sampler_states = nvfx_sampler_state_bind; + nvfx->pipe.delete_sampler_state = nvfx_sampler_state_delete; + nvfx->pipe.set_fragment_sampler_views = nvfx_set_fragment_sampler_views; + nvfx->pipe.create_sampler_view = nvfx_create_sampler_view; + nvfx->pipe.sampler_view_destroy = nvfx_sampler_view_destroy; +} + +#define NV30_3D_TEX_FORMAT_FORMAT_DXT1_RECT NV30_3D_TEX_FORMAT_FORMAT_DXT1 +#define NV30_3D_TEX_FORMAT_FORMAT_DXT3_RECT NV30_3D_TEX_FORMAT_FORMAT_DXT3 +#define NV30_3D_TEX_FORMAT_FORMAT_DXT5_RECT NV30_3D_TEX_FORMAT_FORMAT_DXT5 + +#define NV40_3D_TEX_FORMAT_FORMAT_HILO16 NV40_3D_TEX_FORMAT_FORMAT_A16L16 + +#define NV30_3D_TEX_FORMAT_FORMAT_RGBA16F 0x00004a00 +#define NV30_3D_TEX_FORMAT_FORMAT_RGBA16F_RECT NV30_3D_TEX_FORMAT_FORMAT_RGBA16F +#define NV30_3D_TEX_FORMAT_FORMAT_RGBA32F 0x00004b00 +#define NV30_3D_TEX_FORMAT_FORMAT_RGBA32F_RECT NV30_3D_TEX_FORMAT_FORMAT_RGBA32F +#define NV30_3D_TEX_FORMAT_FORMAT_R32F 0x00004c00 +#define NV30_3D_TEX_FORMAT_FORMAT_R32F_RECT NV30_3D_TEX_FORMAT_FORMAT_R32F + +// TODO: guess! +#define NV40_3D_TEX_FORMAT_FORMAT_R32F 0x00001c00 + +#define SRGB 0x00700000 + +#define __(m,tf,tfc,ts0x,ts0y,ts0z,ts0w,ts1x,ts1y,ts1z,ts1w,sign,wrap) \ +[PIPE_FORMAT_##m] = { \ + {NV30_3D_TEX_FORMAT_FORMAT_##tf, \ + NV30_3D_TEX_FORMAT_FORMAT_##tfc, \ + NV30_3D_TEX_FORMAT_FORMAT_##tf##_RECT, \ + NV30_3D_TEX_FORMAT_FORMAT_##tfc##_RECT, \ + NV40_3D_TEX_FORMAT_FORMAT_##tf, \ + NV40_3D_TEX_FORMAT_FORMAT_##tfc}, \ + sign, wrap, \ + {ts0z, ts0y, ts0x, ts0w, 0, 1}, {ts1z, ts1y, ts1x, ts1w, 0, 0} \ +} + +#define _(m,tf,ts0x,ts0y,ts0z,ts0w,ts1x,ts1y,ts1z,ts1w,sign, wrap) \ + __(m,tf,tf,ts0x,ts0y,ts0z,ts0w,ts1x,ts1y,ts1z,ts1w,sign, wrap) + +/* Depth formats works by reading the depth value most significant 8/16 bits. + * We are losing precision, but nVidia loses even more by using A8R8G8B8 instead of HILO16 + * There is no 32-bit integer texture support, so other things are infeasible. + * + * TODO: is it possible to read 16 bits for Z16? A16 doesn't seem to work, either due to normalization or endianness issues + */ + +#define T 2 + +#define X 3 +#define Y 2 +#define Z 1 +#define W 0 + +#define SNORM ((NV30_3D_TEX_FILTER_SIGNED_RED) | (NV30_3D_TEX_FILTER_SIGNED_GREEN) | (NV30_3D_TEX_FILTER_SIGNED_BLUE) | (NV30_3D_TEX_FILTER_SIGNED_ALPHA)) +#define UNORM 0 + +struct nvfx_texture_format +nvfx_texture_formats[PIPE_FORMAT_COUNT] = { + [0 ... PIPE_FORMAT_COUNT - 1] = {{-1, -1, -1, -1, -1, -1}}, + _(B8G8R8X8_UNORM, A8R8G8B8, T, T, T, 1, X, Y, Z, W, UNORM, 0), + _(B8G8R8X8_SRGB, A8R8G8B8, T, T, T, 1, X, Y, Z, W, UNORM, SRGB), + _(B8G8R8A8_UNORM, A8R8G8B8, T, T, T, T, X, Y, Z, W, UNORM, 0), + _(B8G8R8A8_SRGB, A8R8G8B8, T, T, T, T, X, Y, Z, W, UNORM, SRGB), + + _(R8G8B8A8_UNORM, A8R8G8B8, T, T, T, T, Z, Y, X, W, UNORM, 0), + _(R8G8B8A8_SRGB, A8R8G8B8, T, T, T, T, Z, Y, X, W, UNORM, SRGB), + _(R8G8B8X8_UNORM, A8R8G8B8, T, T, T, 1, Z, Y, X, W, UNORM, 0), + + _(A8R8G8B8_UNORM, A8R8G8B8, T, T, T, T, W, Z, Y, X, UNORM, 0), + _(A8R8G8B8_SRGB, A8R8G8B8, T, T, T, T, W, Z, Y, X, UNORM, SRGB), + _(A8B8G8R8_UNORM, A8R8G8B8, T, T, T, T, W, X, Y, Z, UNORM, 0), + _(A8B8G8R8_SRGB, A8R8G8B8, T, T, T, T, W, X, Y, Z, UNORM, SRGB), + _(X8R8G8B8_UNORM, A8R8G8B8, T, T, T, 1, W, Z, Y, X, UNORM, 0), + _(X8R8G8B8_SRGB, A8R8G8B8, T, T, T, 1, W, Z, Y, X, UNORM, SRGB), + + _(B5G5R5A1_UNORM, A1R5G5B5, T, T, T, T, X, Y, Z, W, UNORM, 0), + _(B5G5R5X1_UNORM, A1R5G5B5, T, T, T, 1, X, Y, Z, W, UNORM, 0), + + _(B4G4R4A4_UNORM, A4R4G4B4, T, T, T, T, X, Y, Z, W, UNORM, 0), + _(B4G4R4X4_UNORM, A4R4G4B4, T, T, T, 1, X, Y, Z, W, UNORM, 0), + + _(B5G6R5_UNORM, R5G6B5, T, T, T, 1, X, Y, Z, W, UNORM, 0), + + _(R8_UNORM, L8, T, 0, 0, 1, X, X, X, X, UNORM, 0), + _(R8_SNORM, L8, T, 0, 0, 1, X, X, X, X, SNORM, 0), + _(L8_UNORM, L8, T, T, T, 1, X, X, X, X, UNORM, 0), + _(L8_SRGB, L8, T, T, T, 1, X, X, X, X, UNORM, SRGB), + _(A8_UNORM, L8, 0, 0, 0, T, X, X, X, X, UNORM, 0), + _(I8_UNORM, L8, T, T, T, T, X, X, X, X, UNORM, 0), + + _(R8G8_UNORM, A8L8, T, T, T, T, X, X, X, W, UNORM, 0), + _(R8G8_SNORM, A8L8, T, T, T, T, X, X, X, W, SNORM, 0), + _(L8A8_UNORM, A8L8, T, T, T, T, X, X, X, W, UNORM, 0), + _(L8A8_SRGB, A8L8, T, T, T, T, X, X, X, W, UNORM, SRGB), + + _(DXT1_RGB, DXT1, T, T, T, 1, X, Y, Z, W, UNORM, 0), + _(DXT1_SRGB, DXT1, T, T, T, 1, X, Y, Z, W, UNORM, SRGB), + _(DXT1_RGBA, DXT1, T, T, T, T, X, Y, Z, W, UNORM, 0), + _(DXT1_SRGBA, DXT1, T, T, T, T, X, Y, Z, W, UNORM, SRGB), + _(DXT3_RGBA, DXT3, T, T, T, T, X, Y, Z, W, UNORM, 0), + _(DXT3_SRGBA, DXT3, T, T, T, T, X, Y, Z, W, UNORM, SRGB), + _(DXT5_RGBA, DXT5, T, T, T, T, X, Y, Z, W, UNORM, 0), + _(DXT5_SRGBA, DXT5, T, T, T, T, X, Y, Z, W, UNORM, SRGB), + + __(Z16_UNORM, A8L8, Z16, T, T, T, 1, W, W, W, W, UNORM, 0), + __(S8_USCALED_Z24_UNORM,HILO16,Z24, T, T, T, 1, W, W, W, W, UNORM, 0), + __(X8Z24_UNORM, HILO16,Z24, T, T, T, 1, W, W, W, W, UNORM, 0), + + _(R16_UNORM, A16, T, 0, 0, 1, X, X, X, X, UNORM, 0), + _(R16_SNORM, A16, T, 0, 0, 1, X, X, X, X, SNORM, 0), + _(R16G16_UNORM, HILO16, T, T, 0, 1, X, Y, X, X, UNORM, 0), + _(R16G16_SNORM, HILO16, T, T, 0, 1, X, Y, X, X, SNORM, 0), + + _(R16G16B16A16_FLOAT, RGBA16F, T, T, T, T, X, Y, Z, W, UNORM, 0), + _(R32G32B32A32_FLOAT, RGBA32F, T, T, T, T, X, Y, Z, W, UNORM, 0), + _(R32_FLOAT, R32F, T, 0, 0, 1, X, X, X, X, UNORM, 0) +}; diff --git a/src/gallium/drivers/nvfx/nvfx_miptree.c b/src/gallium/drivers/nvfx/nvfx_miptree.c new file mode 100644 index 0000000..8c043b8 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_miptree.c @@ -0,0 +1,224 @@ +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_staging.h" +#include "state_tracker/drm_driver.h" +#include "nouveau/nouveau_winsys.h" +#include "nouveau/nouveau_screen.h" +#include "nvfx_screen.h" +#include "nvfx_resource.h" + +static void +nvfx_miptree_choose_format(struct nvfx_miptree *mt) +{ + struct pipe_resource *pt = &mt->base.base; + unsigned uniform_pitch = 0; + static int no_swizzle = -1; + if(no_swizzle < 0) + no_swizzle = debug_get_bool_option("NV40_NO_SWIZZLE", FALSE); /* this will break things on nv30 */ + + if (!util_is_power_of_two(pt->width0) || + !util_is_power_of_two(pt->height0) || + !util_is_power_of_two(pt->depth0) || + (!nvfx_screen(pt->screen)->is_nv4x && pt->target == PIPE_TEXTURE_RECT) + ) + uniform_pitch = 1; + + if ( + (pt->bind & (PIPE_BIND_SCANOUT | PIPE_BIND_DISPLAY_TARGET)) + || (pt->usage & PIPE_USAGE_DYNAMIC) || (pt->usage & PIPE_USAGE_STAGING) + || util_format_is_compressed(pt->format) + || no_swizzle + ) + mt->base.base.flags |= NVFX_RESOURCE_FLAG_LINEAR; + + /* non compressed formats with uniform pitch must be linear, and vice versa */ + if(!util_format_is_s3tc(pt->format) + && (uniform_pitch || mt->base.base.flags & NVFX_RESOURCE_FLAG_LINEAR)) + { + mt->base.base.flags |= NVFX_RESOURCE_FLAG_LINEAR; + uniform_pitch = 1; + } + + if(uniform_pitch) + { + mt->linear_pitch = util_format_get_stride(pt->format, pt->width0); + + // TODO: this is only a constraint for rendering and not sampling, apparently + // we may also want this unconditionally + if(pt->bind & (PIPE_BIND_SAMPLER_VIEW | + PIPE_BIND_DEPTH_STENCIL | + PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SCANOUT)) + mt->linear_pitch = align(mt->linear_pitch, 64); + } + else + mt->linear_pitch = 0; +} + +static unsigned +nvfx_miptree_layout(struct nvfx_miptree *mt) +{ + struct pipe_resource* pt = &mt->base.base; + uint offset = 0; + + if(!nvfx_screen(pt->screen)->is_nv4x) + { + assert(pt->target == PIPE_TEXTURE_RECT + || (util_is_power_of_two(pt->width0) && util_is_power_of_two(pt->height0))); + } + + for (unsigned l = 0; l <= pt->last_level; l++) + { + unsigned size; + mt->level_offset[l] = offset; + + if(mt->linear_pitch) + size = mt->linear_pitch; + else + size = util_format_get_stride(pt->format, u_minify(pt->width0, l)); + size = util_format_get_2d_size(pt->format, size, u_minify(pt->height0, l)); + + if(pt->target == PIPE_TEXTURE_3D) + size *= u_minify(pt->depth0, l); + + offset += size; + } + + offset = align(offset, 128); + mt->face_size = offset; + if(mt->base.base.target == PIPE_TEXTURE_CUBE) + offset += 5 * mt->face_size; + return offset; +} + +static void +nvfx_miptree_surface_final_destroy(struct pipe_surface* ps) +{ + struct nvfx_surface* ns = (struct nvfx_surface*)ps; + pipe_resource_reference(&ps->texture, 0); + pipe_resource_reference((struct pipe_resource**)&ns->temp, 0); + FREE(ps); +} + +void +nvfx_miptree_destroy(struct pipe_screen *screen, struct pipe_resource *pt) +{ + struct nvfx_miptree *mt = (struct nvfx_miptree *)pt; + util_surfaces_destroy(&mt->surfaces, pt, nvfx_miptree_surface_final_destroy); + nouveau_screen_bo_release(screen, mt->base.bo); + FREE(mt); +} + +static struct nvfx_miptree* +nvfx_miptree_create_skeleton(struct pipe_screen *pscreen, const struct pipe_resource *pt) +{ + struct nvfx_miptree *mt; + + if(pt->width0 > 4096 || pt->height0 > 4096) + return NULL; + + mt = CALLOC_STRUCT(nvfx_miptree); + if (!mt) + return NULL; + + mt->base.base = *pt; + util_dirty_surfaces_init(&mt->dirty_surfaces); + + pipe_reference_init(&mt->base.base.reference, 1); + mt->base.base.screen = pscreen; + + // set this to the actual capabilities, we use it to decide whether to use the 3D engine for copies + // TODO: is this the correct way to use Gallium? + mt->base.base.bind = pt->bind | PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_DEPTH_STENCIL; + + // on our current driver (and the driver too), format support does not depend on geometry, so don't bother computing it + // TODO: may want to revisit this + if(!pscreen->is_format_supported(pscreen, pt->format, pt->target, 0, PIPE_BIND_RENDER_TARGET, 0)) + mt->base.base.bind &=~ PIPE_BIND_RENDER_TARGET; + if(!pscreen->is_format_supported(pscreen, pt->format, pt->target, 0, PIPE_BIND_SAMPLER_VIEW, 0)) + mt->base.base.bind &=~ PIPE_BIND_SAMPLER_VIEW; + if(!pscreen->is_format_supported(pscreen, pt->format, pt->target, 0, PIPE_BIND_DEPTH_STENCIL, 0)) + mt->base.base.bind &=~ PIPE_BIND_DEPTH_STENCIL; + + return mt; +} + + +struct pipe_resource * +nvfx_miptree_create(struct pipe_screen *pscreen, const struct pipe_resource *pt) +{ + struct nvfx_miptree* mt = nvfx_miptree_create_skeleton(pscreen, pt); + unsigned size; + nvfx_miptree_choose_format(mt); + + size = nvfx_miptree_layout(mt); + + mt->base.bo = nouveau_screen_bo_new(pscreen, 256, pt->usage, pt->bind, size); + + if (!mt->base.bo) { + FREE(mt); + return NULL; + } + return &mt->base.base; +} + +// TODO: redo this, just calling miptree_layout +struct pipe_resource * +nvfx_miptree_from_handle(struct pipe_screen *pscreen, const struct pipe_resource *template, struct winsys_handle *whandle) +{ + struct nvfx_miptree* mt = nvfx_miptree_create_skeleton(pscreen, template); + unsigned stride; + if(whandle->stride) { + mt->linear_pitch = whandle->stride; + mt->base.base.flags |= NVFX_RESOURCE_FLAG_LINEAR; + } else + nvfx_miptree_choose_format(mt); + + nvfx_miptree_layout(mt); + + mt->base.bo = nouveau_screen_bo_from_handle(pscreen, whandle, &stride); + if (mt->base.bo == NULL) { + FREE(mt); + return NULL; + } + return &mt->base.base; +} + +struct pipe_surface * +nvfx_miptree_surface_new(struct pipe_context *pipe, struct pipe_resource *pt, + const struct pipe_surface *surf_tmpl) +{ + struct nvfx_miptree *mt = (struct nvfx_miptree *)pt; + unsigned level = surf_tmpl->u.tex.level; + struct nvfx_surface *ns = NULL; + + assert(surf_tmpl->u.tex.first_layer == surf_tmpl->u.tex.last_layer); + if(util_surfaces_get(&mt->surfaces, sizeof(struct nvfx_surface), pipe, + pt, level, surf_tmpl->u.tex.first_layer, + surf_tmpl->usage, (struct pipe_surface **)&ns)) { + util_dirty_surface_init(&ns->base); + ns->pitch = nvfx_subresource_pitch(pt, level); + ns->offset = nvfx_subresource_offset(pt, surf_tmpl->u.tex.first_layer, level, surf_tmpl->u.tex.first_layer); + } + + return &ns->base.base; +} + +void +nvfx_miptree_surface_del(struct pipe_context *pipe, struct pipe_surface *ps) +{ + struct nvfx_surface* ns = (struct nvfx_surface*)ps; + + if(!ns->temp) + { + assert(!util_dirty_surface_is_dirty(&ns->base)); + util_surfaces_detach(&((struct nvfx_miptree*)ps->texture)->surfaces, ps); + pipe_resource_reference(&ps->texture, 0); + FREE(ps); + } +} diff --git a/src/gallium/drivers/nvfx/nvfx_push.c b/src/gallium/drivers/nvfx/nvfx_push.c new file mode 100644 index 0000000..ebf47e6 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_push.c @@ -0,0 +1,414 @@ +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_split_prim.h" +#include "translate/translate.h" + +#include "nvfx_context.h" +#include "nvfx_resource.h" + +struct push_context { + struct nouveau_channel* chan; + + void *idxbuf; + int32_t idxbias; + + float edgeflag; + int edgeflag_attr; + + unsigned vertex_length; + unsigned max_vertices_per_packet; + + struct translate* translate; +}; + +static void +emit_edgeflag(void *priv, boolean enabled) +{ + struct push_context* ctx = priv; + struct nouveau_channel *chan = ctx->chan; + + OUT_RING(chan, RING_3D(NV30_3D_EDGEFLAG, 1)); + OUT_RING(chan, enabled ? 1 : 0); +} + +static void +emit_vertices_lookup8(void *priv, unsigned start, unsigned count) +{ + struct push_context *ctx = priv; + uint8_t* elts = (uint8_t*)ctx->idxbuf + start; + + while(count) + { + unsigned push = MIN2(count, ctx->max_vertices_per_packet); + unsigned length = push * ctx->vertex_length; + + OUT_RING(ctx->chan, RING_3D_NI(NV30_3D_VERTEX_DATA, length)); + ctx->translate->run_elts8(ctx->translate, elts, push, 0, ctx->chan->cur); + ctx->chan->cur += length; + + count -= push; + elts += push; + } +} + +static void +emit_vertices_lookup16(void *priv, unsigned start, unsigned count) +{ + struct push_context *ctx = priv; + uint16_t* elts = (uint16_t*)ctx->idxbuf + start; + + while(count) + { + unsigned push = MIN2(count, ctx->max_vertices_per_packet); + unsigned length = push * ctx->vertex_length; + + OUT_RING(ctx->chan, RING_3D_NI(NV30_3D_VERTEX_DATA, length)); + ctx->translate->run_elts16(ctx->translate, elts, push, 0, ctx->chan->cur); + ctx->chan->cur += length; + + count -= push; + elts += push; + } +} + +static void +emit_vertices_lookup32(void *priv, unsigned start, unsigned count) +{ + struct push_context *ctx = priv; + uint32_t* elts = (uint32_t*)ctx->idxbuf + start; + + while(count) + { + unsigned push = MIN2(count, ctx->max_vertices_per_packet); + unsigned length = push * ctx->vertex_length; + + OUT_RING(ctx->chan, RING_3D_NI(NV30_3D_VERTEX_DATA, length)); + ctx->translate->run_elts(ctx->translate, elts, push, 0, ctx->chan->cur); + ctx->chan->cur += length; + + count -= push; + elts += push; + } +} + +static void +emit_vertices(void *priv, unsigned start, unsigned count) +{ + struct push_context *ctx = priv; + + while(count) + { + unsigned push = MIN2(count, ctx->max_vertices_per_packet); + unsigned length = push * ctx->vertex_length; + + OUT_RING(ctx->chan, RING_3D_NI(NV30_3D_VERTEX_DATA, length)); + ctx->translate->run(ctx->translate, start, push, 0, ctx->chan->cur); + ctx->chan->cur += length; + + count -= push; + start += push; + } +} + +static void +emit_ranges(void* priv, unsigned start, unsigned vc, unsigned reg) +{ + struct push_context* ctx = priv; + struct nouveau_channel *chan = ctx->chan; + unsigned nr = (vc & 0xff); + if (nr) { + OUT_RING(chan, RING_3D(reg, 1)); + OUT_RING (chan, ((nr - 1) << 24) | start); + start += nr; + } + + nr = vc >> 8; + while (nr) { + unsigned push = nr > 2047 ? 2047 : nr; + + nr -= push; + + OUT_RING(chan, RING_3D_NI(reg, push)); + while (push--) { + OUT_RING(chan, ((0x100 - 1) << 24) | start); + start += 0x100; + } + } +} + +static void +emit_ib_ranges(void* priv, unsigned start, unsigned vc) +{ + emit_ranges(priv, start, vc, NV30_3D_VB_INDEX_BATCH); +} + +static void +emit_vb_ranges(void* priv, unsigned start, unsigned vc) +{ + emit_ranges(priv, start, vc, NV30_3D_VB_VERTEX_BATCH); +} + +static INLINE void +emit_elt8(void* priv, unsigned start, unsigned vc) +{ + struct push_context* ctx = priv; + struct nouveau_channel *chan = ctx->chan; + uint8_t *elts = (uint8_t *)ctx->idxbuf + start; + int idxbias = ctx->idxbias; + + if (vc & 1) { + OUT_RING(chan, RING_3D(NV30_3D_VB_ELEMENT_U32, 1)); + OUT_RING (chan, elts[0]); + elts++; vc--; + } + + while (vc) { + unsigned i; + unsigned push = MIN2(vc, 2047 * 2); + + OUT_RING(chan, RING_3D_NI(NV30_3D_VB_ELEMENT_U16, push >> 1)); + for (i = 0; i < push; i+=2) + OUT_RING(chan, ((elts[i+1] + idxbias) << 16) | (elts[i] + idxbias)); + + vc -= push; + elts += push; + } +} + +static INLINE void +emit_elt16(void* priv, unsigned start, unsigned vc) +{ + struct push_context* ctx = priv; + struct nouveau_channel *chan = ctx->chan; + uint16_t *elts = (uint16_t *)ctx->idxbuf + start; + int idxbias = ctx->idxbias; + + if (vc & 1) { + OUT_RING(chan, RING_3D(NV30_3D_VB_ELEMENT_U32, 1)); + OUT_RING (chan, elts[0]); + elts++; vc--; + } + + while (vc) { + unsigned i; + unsigned push = MIN2(vc, 2047 * 2); + + OUT_RING(chan, RING_3D_NI(NV30_3D_VB_ELEMENT_U16, push >> 1)); + for (i = 0; i < push; i+=2) + OUT_RING(chan, ((elts[i+1] + idxbias) << 16) | (elts[i] + idxbias)); + + vc -= push; + elts += push; + } +} + +static INLINE void +emit_elt32(void* priv, unsigned start, unsigned vc) +{ + struct push_context* ctx = priv; + struct nouveau_channel *chan = ctx->chan; + uint32_t *elts = (uint32_t *)ctx->idxbuf + start; + int idxbias = ctx->idxbias; + + while (vc) { + unsigned push = MIN2(vc, 2047); + + OUT_RING(chan, RING_3D_NI(NV30_3D_VB_ELEMENT_U32, push)); + assert(AVAIL_RING(chan) >= push); + if(idxbias) + { + for(unsigned i = 0; i < push; ++i) + OUT_RING(chan, elts[i] + idxbias); + } + else + OUT_RINGp(chan, elts, push); + + vc -= push; + elts += push; + } +} + +void +nvfx_push_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + struct nouveau_channel *chan = nvfx->screen->base.channel; + struct push_context ctx; + struct util_split_prim s; + unsigned instances_left = info->instance_count; + int vtx_value; + unsigned hw_mode = nvgl_primitive(info->mode); + int i; + struct + { + uint8_t* map; + unsigned step; + } per_instance[16]; + unsigned p_overhead = 64 /* magic fix */ + + 4 /* begin/end */ + + 4; /* potential edgeflag enable/disable */ + + ctx.chan = nvfx->screen->base.channel; + ctx.translate = nvfx->vtxelt->translate; + ctx.idxbuf = NULL; + ctx.vertex_length = nvfx->vtxelt->vertex_length; + ctx.max_vertices_per_packet = nvfx->vtxelt->max_vertices_per_packet; + ctx.edgeflag = 0.5f; + // TODO: figure out if we really want to handle this, and do so in that case + ctx.edgeflag_attr = 0xff; // nvfx->vertprog->cfg.edgeflag_in; + + if(!nvfx->use_vertex_buffers) + { + for(i = 0; i < nvfx->vtxelt->num_per_vertex_buffer_infos; ++i) + { + struct nvfx_per_vertex_buffer_info* vbi = &nvfx->vtxelt->per_vertex_buffer_info[i]; + struct pipe_vertex_buffer *vb = &nvfx->vtxbuf[vbi->vertex_buffer_index]; + uint8_t* data = nvfx_buffer(vb->buffer)->data + vb->buffer_offset; + if(info->indexed) + data += info->index_bias * vb->stride; + ctx.translate->set_buffer(ctx.translate, i, data, vb->stride, ~0); + } + + if(ctx.edgeflag_attr < 16) + vtx_value = -(ctx.vertex_length + 3); /* vertex data and edgeflag header and value */ + else + { + p_overhead += 1; /* initial vertex_data header */ + vtx_value = -ctx.vertex_length; /* vertex data and edgeflag header and value */ + } + + if (info->indexed) { + // XXX: this case and is broken and probably need a new VTX_ATTR push path + if (nvfx->idxbuf.index_size == 1) + s.emit = emit_vertices_lookup8; + else if (nvfx->idxbuf.index_size == 2) + s.emit = emit_vertices_lookup16; + else + s.emit = emit_vertices_lookup32; + } else + s.emit = emit_vertices; + } + else + { + if(!info->indexed || nvfx->use_index_buffer) + { + s.emit = info->indexed ? emit_ib_ranges : emit_vb_ranges; + p_overhead += 3; + vtx_value = 0; + } + else if (nvfx->idxbuf.index_size == 4) + { + s.emit = emit_elt32; + p_overhead += 1; + vtx_value = 8; + } + else + { + s.emit = (nvfx->idxbuf.index_size == 2) ? emit_elt16 : emit_elt8; + p_overhead += 3; + vtx_value = 7; + } + } + + ctx.idxbias = info->index_bias; + if(nvfx->use_vertex_buffers) + ctx.idxbias -= nvfx->base_vertex; + + /* map index buffer, if present */ + if (info->indexed && !nvfx->use_index_buffer) + ctx.idxbuf = nvfx_buffer(nvfx->idxbuf.buffer)->data + nvfx->idxbuf.offset; + + s.priv = &ctx; + s.edge = emit_edgeflag; + + for (i = 0; i < nvfx->vtxelt->num_per_instance; ++i) + { + struct nvfx_per_instance_element *ve = &nvfx->vtxelt->per_instance[i]; + struct pipe_vertex_buffer *vb = &nvfx->vtxbuf[ve->base.vertex_buffer_index]; + float v[4]; + per_instance[i].step = info->start_instance % ve->instance_divisor; + per_instance[i].map = nvfx_buffer(vb->buffer)->data + vb->buffer_offset + ve->base.src_offset; + + nvfx->vtxelt->per_instance[i].base.fetch_rgba_float(v, per_instance[i].map, 0, 0); + + WAIT_RING(chan, 5); + nvfx_emit_vtx_attr(chan, nvfx->vtxelt->per_instance[i].base.idx, v, nvfx->vtxelt->per_instance[i].base.ncomp); + } + + /* per-instance loop */ + while (instances_left--) { + int max_verts; + boolean done; + + util_split_prim_init(&s, info->mode, info->start, info->count); + nvfx_state_emit(nvfx); + for(;;) { + max_verts = AVAIL_RING(chan); + max_verts -= p_overhead; + + /* if vtx_value < 0, each vertex is -vtx_value words long + * otherwise, each vertex is 2^(vtx_value) / 255 words long (this is an approximation) + */ + if(vtx_value < 0) + { + max_verts /= -vtx_value; + max_verts -= (max_verts >> 10); /* vertex data headers */ + } + else + { + if(max_verts >= (1 << 23)) /* avoid overflow here */ + max_verts = (1 << 23); + max_verts = (max_verts * 255) >> vtx_value; + } + + //printf("avail %u max_verts %u\n", AVAIL_RING(chan), max_verts); + + if(max_verts >= 16) + { + /* XXX: any command a lot of times seems to (mostly) fix corruption that would otherwise happen */ + /* this seems to cause issues on nv3x, and also be unneeded there */ + if(nvfx->is_nv4x) + { + int i; + for(i = 0; i < 32; ++i) + { + OUT_RING(chan, RING_3D(0x1dac, 1)); + OUT_RING(chan, 0); + } + } + + OUT_RING(chan, RING_3D(NV30_3D_VERTEX_BEGIN_END, 1)); + OUT_RING(chan, hw_mode); + done = util_split_prim_next(&s, max_verts); + OUT_RING(chan, RING_3D(NV30_3D_VERTEX_BEGIN_END, 1)); + OUT_RING(chan, 0); + + if(done) + break; + } + + FIRE_RING(chan); + nvfx_state_emit(nvfx); + } + + /* set data for the next instance, if any changed */ + for (i = 0; i < nvfx->vtxelt->num_per_instance; ++i) + { + struct nvfx_per_instance_element *ve = &nvfx->vtxelt->per_instance[i]; + struct pipe_vertex_buffer *vb = &nvfx->vtxbuf[ve->base.vertex_buffer_index]; + + if(++per_instance[i].step == ve->instance_divisor) + { + float v[4]; + per_instance[i].map += vb->stride; + per_instance[i].step = 0; + + nvfx->vtxelt->per_instance[i].base.fetch_rgba_float(v, per_instance[i].map, 0, 0); + WAIT_RING(chan, 5); + nvfx_emit_vtx_attr(chan, nvfx->vtxelt->per_instance[i].base.idx, v, nvfx->vtxelt->per_instance[i].base.ncomp); + } + } + } +} diff --git a/src/gallium/drivers/nvfx/nvfx_query.c b/src/gallium/drivers/nvfx/nvfx_query.c new file mode 100644 index 0000000..3935ffd --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_query.c @@ -0,0 +1,147 @@ +#include "pipe/p_context.h" + +#include "nvfx_context.h" + +struct nvfx_query { + struct list_head list; + struct nouveau_resource *object; + unsigned type; + boolean ready; + uint64_t result; +}; + +static INLINE struct nvfx_query * +nvfx_query(struct pipe_query *pipe) +{ + return (struct nvfx_query *)pipe; +} + +static struct pipe_query * +nvfx_query_create(struct pipe_context *pipe, unsigned query_type) +{ + struct nvfx_query *q; + + q = CALLOC(1, sizeof(struct nvfx_query)); + q->type = query_type; + + assert(q->type == PIPE_QUERY_OCCLUSION_COUNTER); + + return (struct pipe_query *)q; +} + +static void +nvfx_query_destroy(struct pipe_context *pipe, struct pipe_query *pq) +{ + struct nvfx_query *q = nvfx_query(pq); + + if (q->object) + { + nouveau_resource_free(&q->object); + LIST_DEL(&q->list); + } + FREE(q); +} + +static void +nvfx_query_begin(struct pipe_context *pipe, struct pipe_query *pq) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + struct nvfx_query *q = nvfx_query(pq); + struct nvfx_screen *screen = nvfx->screen; + struct nouveau_channel *chan = screen->base.channel; + uint64_t tmp; + + assert(!nvfx->query); + + /* Happens when end_query() is called, then another begin_query() + * without querying the result in-between. For now we'll wait for + * the existing query to notify completion, but it could be better. + */ + if (q->object) + pipe->get_query_result(pipe, pq, 1, &tmp); + + while (nouveau_resource_alloc(nvfx->screen->query_heap, 1, NULL, &q->object)) + { + struct nvfx_query* oldestq; + assert(!LIST_IS_EMPTY(&nvfx->screen->query_list)); + oldestq = LIST_ENTRY(struct nvfx_query, nvfx->screen->query_list.next, list); + pipe->get_query_result(pipe, (struct pipe_query*)oldestq, 1, &tmp); + } + + LIST_ADDTAIL(&q->list, &nvfx->screen->query_list); + + nouveau_notifier_reset(nvfx->screen->query, q->object->start); + + WAIT_RING(chan, 4); + OUT_RING(chan, RING_3D(NV30_3D_QUERY_RESET, 1)); + OUT_RING(chan, 1); + OUT_RING(chan, RING_3D(NV30_3D_QUERY_ENABLE, 1)); + OUT_RING(chan, 1); + + q->ready = FALSE; + + nvfx->query = pq; +} + +static void +nvfx_query_end(struct pipe_context *pipe, struct pipe_query *pq) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + struct nouveau_channel *chan = nvfx->screen->base.channel; + struct nvfx_query *q = nvfx_query(pq); + + assert(nvfx->query == pq); + + WAIT_RING(chan, 4); + OUT_RING(chan, RING_3D(NV30_3D_QUERY_GET, 1)); + OUT_RING (chan, (0x01 << NV30_3D_QUERY_GET_UNK24__SHIFT) | + ((q->object->start * 32) << NV30_3D_QUERY_GET_OFFSET__SHIFT)); + OUT_RING(chan, RING_3D(NV30_3D_QUERY_ENABLE, 1)); + OUT_RING(chan, 0); + FIRE_RING(chan); + + nvfx->query = 0; +} + +static boolean +nvfx_query_result(struct pipe_context *pipe, struct pipe_query *pq, + boolean wait, void *vresult) +{ + uint64_t *result = (uint64_t *)vresult; + struct nvfx_context *nvfx = nvfx_context(pipe); + struct nvfx_query *q = nvfx_query(pq); + + if (!q->ready) { + unsigned status; + + status = nouveau_notifier_status(nvfx->screen->query, + q->object->start); + if (status != NV_NOTIFY_STATE_STATUS_COMPLETED) { + if (wait == FALSE) + return FALSE; + + nouveau_notifier_wait_status(nvfx->screen->query, + q->object->start, + NV_NOTIFY_STATE_STATUS_COMPLETED, 0); + } + + q->result = nouveau_notifier_return_val(nvfx->screen->query, + q->object->start); + q->ready = TRUE; + nouveau_resource_free(&q->object); + LIST_DEL(&q->list); + } + + *result = q->result; + return TRUE; +} + +void +nvfx_init_query_functions(struct nvfx_context *nvfx) +{ + nvfx->pipe.create_query = nvfx_query_create; + nvfx->pipe.destroy_query = nvfx_query_destroy; + nvfx->pipe.begin_query = nvfx_query_begin; + nvfx->pipe.end_query = nvfx_query_end; + nvfx->pipe.get_query_result = nvfx_query_result; +} diff --git a/src/gallium/drivers/nvfx/nvfx_resource.c b/src/gallium/drivers/nvfx/nvfx_resource.c new file mode 100644 index 0000000..c60a7bb --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_resource.c @@ -0,0 +1,75 @@ + +#include "pipe/p_context.h" +#include "util/u_staging.h" +#include "nvfx_resource.h" +#include "nouveau/nouveau_screen.h" + +static unsigned int +nvfx_resource_is_referenced(struct pipe_context *pipe, + struct pipe_resource *pr, + unsigned level, int layer) +{ + return !!nouveau_reference_flags(nvfx_resource(pr)->bo); +} + +static struct pipe_resource * +nvfx_resource_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + if (template->target == PIPE_BUFFER) + return nvfx_buffer_create(screen, template); + else + return nvfx_miptree_create(screen, template); +} + +static void +nvfx_resource_destroy(struct pipe_screen *screen, struct pipe_resource *pr) +{ + if (pr->target == PIPE_BUFFER) + return nvfx_buffer_destroy(screen, pr); + else + return nvfx_miptree_destroy(screen, pr); +} + +static struct pipe_resource * +nvfx_resource_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle) +{ + if (template->target == PIPE_BUFFER) + return NULL; + else + return nvfx_miptree_from_handle(screen, template, whandle); +} + +static boolean +nvfx_resource_get_handle(struct pipe_screen *pscreen, + struct pipe_resource *pr, + struct winsys_handle *whandle) +{ + struct nvfx_resource* res = (struct nvfx_resource*)pr; + + if (!res || !res->bo) + return FALSE; + + return nouveau_screen_bo_get_handle(pscreen, res->bo, nvfx_subresource_pitch(pr, 0), whandle); +} + +void +nvfx_init_resource_functions(struct pipe_context *pipe) +{ + pipe->is_resource_referenced = nvfx_resource_is_referenced; + + pipe->create_surface = nvfx_miptree_surface_new; + pipe->surface_destroy = nvfx_miptree_surface_del; +} + +void +nvfx_screen_init_resource_functions(struct pipe_screen *pscreen) +{ + pscreen->resource_create = nvfx_resource_create; + pscreen->resource_from_handle = nvfx_resource_from_handle; + pscreen->resource_get_handle = nvfx_resource_get_handle; + pscreen->resource_destroy = nvfx_resource_destroy; + pscreen->user_buffer_create = nvfx_user_buffer_create; +} diff --git a/src/gallium/drivers/nvfx/nvfx_resource.h b/src/gallium/drivers/nvfx/nvfx_resource.h new file mode 100644 index 0000000..070f897 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_resource.h @@ -0,0 +1,223 @@ +#ifndef NVFX_RESOURCE_H +#define NVFX_RESOURCE_H + +#include "util/u_transfer.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_double_list.h" +#include "util/u_surfaces.h" +#include "util/u_dirty_surfaces.h" +#include + +struct pipe_resource; +struct nv04_region; + +struct nvfx_resource { + struct pipe_resource base; + struct nouveau_bo *bo; +}; + +static INLINE +struct nvfx_resource *nvfx_resource(struct pipe_resource *resource) +{ + return (struct nvfx_resource *)resource; +} + +#define NVFX_RESOURCE_FLAG_LINEAR (PIPE_RESOURCE_FLAG_DRV_PRIV << 0) +#define NVFX_RESOURCE_FLAG_USER (PIPE_RESOURCE_FLAG_DRV_PRIV << 1) + +/* is resource mapped into the GPU's address space (i.e. VRAM or GART) ? */ +static INLINE boolean +nvfx_resource_mapped_by_gpu(struct pipe_resource *resource) +{ + return nvfx_resource(resource)->bo->handle; +} + +/* is resource in VRAM? */ +static inline int +nvfx_resource_on_gpu(struct pipe_resource* pr) +{ +#if 0 + // a compiler error here means you need to apply libdrm-nouveau-add-domain.patch to libdrm + // TODO: return FALSE if not VRAM and on a PCI-E system + return ((struct nvfx_resource*)pr)->bo->domain & (NOUVEAU_BO_VRAM | NOUVEAU_BO_GART); +#else + return TRUE; +#endif +} + +#define NVFX_MAX_TEXTURE_LEVELS 16 + +/* We have the following invariants for render temporaries + * + * 1. Render temporaries are always linear + * 2. Render temporaries are always up to date + * 3. Currently, render temporaries are destroyed when the resource is used for sampling, but kept for any other use + * + * Also, we do NOT flush temporaries on any pipe->flush(). + * This is fine, as long as scanout targets and shared resources never need temps. + * + * TODO: we may want to also support swizzled temporaries to improve performance in some cases. + */ + +struct nvfx_miptree { + struct nvfx_resource base; + + unsigned linear_pitch; /* for linear textures, 0 for swizzled and compressed textures with level-dependent minimal pitch */ + unsigned face_size; /* 128-byte aligned face/total size */ + unsigned level_offset[NVFX_MAX_TEXTURE_LEVELS]; + + struct util_surfaces surfaces; + struct util_dirty_surfaces dirty_surfaces; +}; + +struct nvfx_surface { + struct util_dirty_surface base; + unsigned pitch; + unsigned offset; + + struct nvfx_miptree* temp; +}; + +static INLINE struct nouveau_bo * +nvfx_surface_buffer(struct pipe_surface *surf) +{ + struct nvfx_resource *mt = nvfx_resource(surf->texture); + + return mt->bo; +} + +static INLINE struct util_dirty_surfaces* +nvfx_surface_get_dirty_surfaces(struct pipe_surface* surf) +{ + struct nvfx_miptree *mt = (struct nvfx_miptree *)surf->texture; + return &mt->dirty_surfaces; +} + +void +nvfx_init_resource_functions(struct pipe_context *pipe); + +void +nvfx_screen_init_resource_functions(struct pipe_screen *pscreen); + + +/* Internal: + */ + +struct pipe_resource * +nvfx_miptree_create(struct pipe_screen *pscreen, const struct pipe_resource *pt); + +void +nvfx_miptree_destroy(struct pipe_screen *pscreen, + struct pipe_resource *presource); + +struct pipe_resource * +nvfx_miptree_from_handle(struct pipe_screen *pscreen, + const struct pipe_resource *template, + struct winsys_handle *whandle); + +void +nvfx_miptree_surface_del(struct pipe_context *pipe, struct pipe_surface *ps); + +struct pipe_surface * +nvfx_miptree_surface_new(struct pipe_context *pipe, struct pipe_resource *pt, + const struct pipe_surface *surf_tmpl); + +/* only for miptrees, don't use for buffers */ + +/* NOTE: for swizzled 3D textures, this just returns the offset of the mipmap level */ +static inline unsigned +nvfx_subresource_offset(struct pipe_resource* pt, unsigned face, unsigned level, unsigned zslice) +{ + if(pt->target == PIPE_BUFFER) + return 0; + else + { + struct nvfx_miptree *mt = (struct nvfx_miptree *)pt; + + unsigned offset = mt->level_offset[level]; + if (pt->target == PIPE_TEXTURE_CUBE) + offset += mt->face_size * face; + else if (pt->target == PIPE_TEXTURE_3D && mt->linear_pitch) + offset += zslice * util_format_get_2d_size(pt->format, (mt->linear_pitch ? mt->linear_pitch : util_format_get_stride(pt->format, u_minify(pt->width0, level))), u_minify(pt->height0, level)); + return offset; + } +} + +static inline unsigned +nvfx_subresource_pitch(struct pipe_resource* pt, unsigned level) +{ + if(pt->target == PIPE_BUFFER) + return ((struct nvfx_resource*)pt)->bo->size; + else + { + struct nvfx_miptree *mt = (struct nvfx_miptree *)pt; + + if(mt->linear_pitch) + return mt->linear_pitch; + else + return util_format_get_stride(pt->format, u_minify(pt->width0, level)); + } +} + +void +nvfx_surface_create_temp(struct pipe_context* pipe, struct pipe_surface* surf); + +void +nvfx_surface_flush(struct pipe_context* pipe, struct pipe_surface* surf); + +struct nvfx_buffer +{ + struct nvfx_resource base; + uint8_t* data; + unsigned size; + + /* the range of data not yet uploaded to the GPU bo */ + unsigned dirty_begin; + unsigned dirty_end; + + /* whether all transfers were unsynchronized */ + boolean dirty_unsynchronized; + + /* whether it would have been profitable to upload + * the latest updated data to the GPU immediately */ + boolean last_update_static; + + /* how many bytes we need to draw before we deem + * the buffer to be static + */ + long long bytes_to_draw_until_static; +}; + +static inline struct nvfx_buffer* nvfx_buffer(struct pipe_resource* pr) +{ + return (struct nvfx_buffer*)pr; +} + +/* this is an heuristic to determine whether we are better off uploading the + * buffer to the GPU, or just continuing pushing it on the FIFO + */ +static inline boolean nvfx_buffer_seems_static(struct nvfx_buffer* buffer) +{ + return buffer->last_update_static + || buffer->bytes_to_draw_until_static < 0; +} + +struct pipe_resource * +nvfx_buffer_create(struct pipe_screen *pscreen, + const struct pipe_resource *template); + +void +nvfx_buffer_destroy(struct pipe_screen *pscreen, + struct pipe_resource *presource); + +struct pipe_resource * +nvfx_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage); + +void +nvfx_buffer_upload(struct nvfx_buffer* buffer); + +#endif diff --git a/src/gallium/drivers/nvfx/nvfx_screen.c b/src/gallium/drivers/nvfx/nvfx_screen.c new file mode 100644 index 0000000..92e1d33 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_screen.c @@ -0,0 +1,602 @@ +#include "pipe/p_screen.h" +#include "pipe/p_state.h" +#include "util/u_format_s3tc.h" +#include "util/u_simple_screen.h" + +#include "nouveau/nouveau_screen.h" +#include "nouveau/nv_object.xml.h" +#include "nvfx_context.h" +#include "nvfx_screen.h" +#include "nvfx_resource.h" +#include "nvfx_tex.h" + +#define NV30_3D_CHIPSET_3X_MASK 0x00000003 +#define NV34_3D_CHIPSET_3X_MASK 0x00000010 +#define NV35_3D_CHIPSET_3X_MASK 0x000001e0 + +#define NV4X_GRCLASS4097_CHIPSETS 0x00000baf +#define NV4X_GRCLASS4497_CHIPSETS 0x00005450 +#define NV6X_GRCLASS4497_CHIPSETS 0x00000088 + +static int +nvfx_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param) +{ + struct nvfx_screen *screen = nvfx_screen(pscreen); + + switch (param) { + case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: + return 16; + case PIPE_CAP_NPOT_TEXTURES: + return screen->advertise_npot; + case PIPE_CAP_TWO_SIDED_STENCIL: + return 1; + case PIPE_CAP_GLSL: + return 1; + case PIPE_CAP_ANISOTROPIC_FILTER: + return 1; + case PIPE_CAP_POINT_SPRITE: + return 1; + case PIPE_CAP_MAX_RENDER_TARGETS: + return screen->use_nv4x ? 4 : 1; + case PIPE_CAP_OCCLUSION_QUERY: + return 1; + case PIPE_CAP_TIMER_QUERY: + return 0; + case PIPE_CAP_TEXTURE_SHADOW_MAP: + return 1; + case PIPE_CAP_TEXTURE_SWIZZLE: + return 1; + case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: + return 13; + case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: + return 10; + case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: + return 13; + case PIPE_CAP_TEXTURE_MIRROR_CLAMP: + return !!screen->use_nv4x; + case PIPE_CAP_TEXTURE_MIRROR_REPEAT: + return 1; + case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS: + return 0; /* We have 4 on nv40 - but unsupported currently */ + case PIPE_CAP_BLEND_EQUATION_SEPARATE: + return screen->advertise_blend_equation_separate; + case PIPE_CAP_MAX_COMBINED_SAMPLERS: + return 16; + case PIPE_CAP_INDEP_BLEND_ENABLE: + /* TODO: on nv40 we have separate color masks */ + /* TODO: nv40 mrt blending is probably broken */ + return 0; + case PIPE_CAP_INDEP_BLEND_FUNC: + return 0; + case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: + return 0; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: + return 1; + case PIPE_CAP_DEPTH_CLAMP: + return 0; // TODO: implement depth clamp + case PIPE_CAP_PRIMITIVE_RESTART: + return 0; // TODO: implement primitive restart + case PIPE_CAP_SHADER_STENCIL_EXPORT: + return 0; + default: + NOUVEAU_ERR("Warning: unknown PIPE_CAP %d\n", param); + return 0; + } +} + +static int +nvfx_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader, enum pipe_shader_cap param) +{ + struct nvfx_screen *screen = nvfx_screen(pscreen); + + switch(shader) { + case PIPE_SHADER_FRAGMENT: + switch(param) { + case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: + return 4096; + case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: + /* FIXME: is it the dynamic (nv30:0/nv40:24) or the static + value (nv30:0/nv40:4) ? */ + return screen->use_nv4x ? 4 : 0; + case PIPE_SHADER_CAP_MAX_INPUTS: + return screen->use_nv4x ? 12 : 10; + case PIPE_SHADER_CAP_MAX_CONSTS: + return screen->use_nv4x ? 224 : 32; + case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: + return 1; + case PIPE_SHADER_CAP_MAX_TEMPS: + return 32; + case PIPE_SHADER_CAP_MAX_ADDRS: + return screen->use_nv4x ? 1 : 0; + case PIPE_SHADER_CAP_MAX_PREDS: + return 0; /* we could expose these, but nothing uses them */ + case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: + return 0; + case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: + case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: + return 0; + case PIPE_SHADER_CAP_SUBROUTINES: + return screen->use_nv4x ? 1 : 0; + default: + break; + } + break; + case PIPE_SHADER_VERTEX: + switch(param) { + case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: + return screen->use_nv4x ? 512 : 256; + case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: + return screen->use_nv4x ? 512 : 0; + case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: + /* FIXME: is it the dynamic (nv30:24/nv40:24) or the static + value (nv30:1/nv40:4) ? */ + return screen->use_nv4x ? 4 : 1; + case PIPE_SHADER_CAP_MAX_INPUTS: + return 16; + case PIPE_SHADER_CAP_MAX_CONSTS: + /* - 6 is for clip planes; Gallium should be fixed to put + * them in the vertex shader itself, so we don't need to reserve these */ + return (screen->use_nv4x ? 468 : 256) - 6; + case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: + return 1; + case PIPE_SHADER_CAP_MAX_TEMPS: + return screen->use_nv4x ? 32 : 13; + case PIPE_SHADER_CAP_MAX_ADDRS: + return 2; + case PIPE_SHADER_CAP_MAX_PREDS: + return 0; /* we could expose these, but nothing uses them */ + case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: + return 1; + case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: + return 0; + case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: + return 1; + case PIPE_SHADER_CAP_SUBROUTINES: + return 1; + default: + break; + } + break; + default: + break; + } + return 0; +} + +static float +nvfx_screen_get_paramf(struct pipe_screen *pscreen, enum pipe_cap param) +{ + struct nvfx_screen *screen = nvfx_screen(pscreen); + + switch (param) { + case PIPE_CAP_MAX_LINE_WIDTH: + case PIPE_CAP_MAX_LINE_WIDTH_AA: + return 10.0; + case PIPE_CAP_MAX_POINT_WIDTH: + case PIPE_CAP_MAX_POINT_WIDTH_AA: + return 64.0; + case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: + return screen->use_nv4x ? 16.0 : 8.0; + case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: + return 15.0; + default: + NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param); + return 0.0; + } +} + +static boolean +nvfx_screen_is_format_supported(struct pipe_screen *pscreen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned bind, unsigned geom_flags) +{ + struct nvfx_screen *screen = nvfx_screen(pscreen); + + if (sample_count > 1) + return FALSE; + + if (bind & PIPE_BIND_RENDER_TARGET) { + switch (format) { + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_R8G8B8A8_UNORM: + case PIPE_FORMAT_R8G8B8X8_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: + break; + case PIPE_FORMAT_R16G16B16A16_FLOAT: + if(!screen->advertise_fp16) + return FALSE; + break; + case PIPE_FORMAT_R32G32B32A32_FLOAT: + if(!screen->advertise_fp32) + return FALSE; + break; + default: + return FALSE; + } + } + + if (bind & PIPE_BIND_DEPTH_STENCIL) { + switch (format) { + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_Z16_UNORM: + break; + default: + return FALSE; + } + } + + if (bind & PIPE_BIND_SAMPLER_VIEW) { + struct nvfx_texture_format* tf = &nvfx_texture_formats[format]; + if(util_format_is_s3tc(format) && !util_format_s3tc_enabled) + return FALSE; + if(format == PIPE_FORMAT_R16G16B16A16_FLOAT && !screen->advertise_fp16) + return FALSE; + if(format == PIPE_FORMAT_R32G32B32A32_FLOAT && !screen->advertise_fp32) + return FALSE; + if(screen->use_nv4x) + { + if(tf->fmt[4] < 0) + return FALSE; + } + else + { + if(tf->fmt[0] < 0) + return FALSE; + } + } + + // note that we do actually support everything through translate + if (bind & PIPE_BIND_VERTEX_BUFFER) { + unsigned type = nvfx_vertex_formats[format]; + if(!type) + return FALSE; + } + + if (bind & PIPE_BIND_INDEX_BUFFER) { + // 8-bit indices supported, but not in hardware index buffer + if(format != PIPE_FORMAT_R16_USCALED && format != PIPE_FORMAT_R32_USCALED) + return FALSE; + } + + if(bind & PIPE_BIND_STREAM_OUTPUT) + return FALSE; + + return TRUE; +} + +static void +nvfx_screen_destroy(struct pipe_screen *pscreen) +{ + struct nvfx_screen *screen = nvfx_screen(pscreen); + + nouveau_resource_destroy(&screen->vp_exec_heap); + nouveau_resource_destroy(&screen->vp_data_heap); + nouveau_resource_destroy(&screen->query_heap); + nouveau_notifier_free(&screen->query); + nouveau_notifier_free(&screen->sync); + nouveau_grobj_free(&screen->eng3d); + nvfx_screen_surface_takedown(pscreen); + + nouveau_screen_fini(&screen->base); + + FREE(pscreen); +} + +static void nv30_screen_init(struct nvfx_screen *screen) +{ + struct nouveau_channel *chan = screen->base.channel; + int i; + + /* TODO: perhaps we should do some of this on nv40 too? */ + for (i=1; i<8; i++) { + OUT_RING(chan, RING_3D(NV30_3D_VIEWPORT_CLIP_HORIZ(i), 1)); + OUT_RING(chan, 0); + OUT_RING(chan, RING_3D(NV30_3D_VIEWPORT_CLIP_VERT(i), 1)); + OUT_RING(chan, 0); + } + + OUT_RING(chan, RING_3D(0x220, 1)); + OUT_RING(chan, 1); + + OUT_RING(chan, RING_3D(0x03b0, 1)); + OUT_RING(chan, 0x00100000); + OUT_RING(chan, RING_3D(0x1454, 1)); + OUT_RING(chan, 0); + OUT_RING(chan, RING_3D(0x1d80, 1)); + OUT_RING(chan, 3); + OUT_RING(chan, RING_3D(0x1450, 1)); + OUT_RING(chan, 0x00030004); + + /* NEW */ + OUT_RING(chan, RING_3D(0x1e98, 1)); + OUT_RING(chan, 0); + OUT_RING(chan, RING_3D(0x17e0, 3)); + OUT_RING(chan, fui(0.0)); + OUT_RING(chan, fui(0.0)); + OUT_RING(chan, fui(1.0)); + OUT_RING(chan, RING_3D(0x1f80, 16)); + for (i=0; i<16; i++) { + OUT_RING(chan, (i==8) ? 0x0000ffff : 0); + } + + OUT_RING(chan, RING_3D(0x120, 3)); + OUT_RING(chan, 0); + OUT_RING(chan, 1); + OUT_RING(chan, 2); + + OUT_RING(chan, RING_3D(0x1d88, 1)); + OUT_RING(chan, 0x00001200); + + OUT_RING(chan, RING_3D(NV30_3D_RC_ENABLE, 1)); + OUT_RING(chan, 0); + + OUT_RING(chan, RING_3D(NV30_3D_DEPTH_RANGE_NEAR, 2)); + OUT_RING(chan, fui(0.0)); + OUT_RING(chan, fui(1.0)); + + OUT_RING(chan, RING_3D(NV30_3D_MULTISAMPLE_CONTROL, 1)); + OUT_RING(chan, 0xffff0000); + + /* enables use of vp rather than fixed-function somehow */ + OUT_RING(chan, RING_3D(0x1e94, 1)); + OUT_RING(chan, 0x13); +} + +static void nv40_screen_init(struct nvfx_screen *screen) +{ + struct nouveau_channel *chan = screen->base.channel; + + OUT_RING(chan, RING_3D(NV40_3D_DMA_COLOR2, 2)); + OUT_RING(chan, screen->base.channel->vram->handle); + OUT_RING(chan, screen->base.channel->vram->handle); + + OUT_RING(chan, RING_3D(0x1450, 1)); + OUT_RING(chan, 0x00000004); + + OUT_RING(chan, RING_3D(0x1ea4, 3)); + OUT_RING(chan, 0x00000010); + OUT_RING(chan, 0x01000100); + OUT_RING(chan, 0xff800006); + + /* vtxprog output routing */ + OUT_RING(chan, RING_3D(0x1fc4, 1)); + OUT_RING(chan, 0x06144321); + OUT_RING(chan, RING_3D(0x1fc8, 2)); + OUT_RING(chan, 0xedcba987); + OUT_RING(chan, 0x0000006f); + OUT_RING(chan, RING_3D(0x1fd0, 1)); + OUT_RING(chan, 0x00171615); + OUT_RING(chan, RING_3D(0x1fd4, 1)); + OUT_RING(chan, 0x001b1a19); + + OUT_RING(chan, RING_3D(0x1ef8, 1)); + OUT_RING(chan, 0x0020ffff); + OUT_RING(chan, RING_3D(0x1d64, 1)); + OUT_RING(chan, 0x01d300d4); + OUT_RING(chan, RING_3D(0x1e94, 1)); + OUT_RING(chan, 0x00000001); + + OUT_RING(chan, RING_3D(NV40_3D_MIPMAP_ROUNDING, 1)); + OUT_RING(chan, NV40_3D_MIPMAP_ROUNDING_MODE_DOWN); +} + +static unsigned +nvfx_screen_get_vertex_buffer_flags(struct nvfx_screen* screen) +{ + int vram_hack_default = 0; + int vram_hack; + // TODO: this is a bit of a guess; also add other cards that may need this hack. + // It may also depend on the specific card or the AGP/PCIe chipset. + if(screen->base.device->chipset == 0x47 /* G70 */ + || screen->base.device->chipset == 0x49 /* G71 */ + || screen->base.device->chipset == 0x46 /* G72 */ + ) + vram_hack_default = 1; + vram_hack = debug_get_bool_option("NOUVEAU_VTXIDX_IN_VRAM", vram_hack_default); + + return vram_hack ? NOUVEAU_BO_VRAM : NOUVEAU_BO_GART; +} + +static void nvfx_channel_flush_notify(struct nouveau_channel* chan) +{ + struct nvfx_screen* screen = chan->user_private; + struct nvfx_context* nvfx = screen->cur_ctx; + if(nvfx) + nvfx->relocs_needed = NVFX_RELOCATE_ALL; +} + +struct pipe_screen * +nvfx_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) +{ + static const unsigned query_sizes[] = {(4096 - 4 * 32) / 32, 3 * 1024 / 32, 2 * 1024 / 32, 1024 / 32}; + struct nvfx_screen *screen = CALLOC_STRUCT(nvfx_screen); + struct nouveau_channel *chan; + struct pipe_screen *pscreen; + unsigned eng3d_class = 0; + int ret, i; + + if (!screen) + return NULL; + + pscreen = &screen->base.base; + + ret = nouveau_screen_init(&screen->base, dev); + if (ret) { + nvfx_screen_destroy(pscreen); + return NULL; + } + chan = screen->base.channel; + screen->cur_ctx = NULL; + chan->user_private = screen; + chan->flush_notify = nvfx_channel_flush_notify; + + pscreen->winsys = ws; + pscreen->destroy = nvfx_screen_destroy; + pscreen->get_param = nvfx_screen_get_param; + pscreen->get_shader_param = nvfx_screen_get_shader_param; + pscreen->get_paramf = nvfx_screen_get_paramf; + pscreen->is_format_supported = nvfx_screen_is_format_supported; + pscreen->context_create = nvfx_create; + + switch (dev->chipset & 0xf0) { + case 0x30: + if (NV30_3D_CHIPSET_3X_MASK & (1 << (dev->chipset & 0x0f))) + eng3d_class = NV30_3D; + else if (NV34_3D_CHIPSET_3X_MASK & (1 << (dev->chipset & 0x0f))) + eng3d_class = NV34_3D; + else if (NV35_3D_CHIPSET_3X_MASK & (1 << (dev->chipset & 0x0f))) + eng3d_class = NV35_3D; + break; + case 0x40: + if (NV4X_GRCLASS4097_CHIPSETS & (1 << (dev->chipset & 0x0f))) + eng3d_class = NV40_3D; + else if (NV4X_GRCLASS4497_CHIPSETS & (1 << (dev->chipset & 0x0f))) + eng3d_class = NV44_3D; + screen->is_nv4x = ~0; + break; + case 0x60: + if (NV6X_GRCLASS4497_CHIPSETS & (1 << (dev->chipset & 0x0f))) + eng3d_class = NV44_3D; + screen->is_nv4x = ~0; + break; + } + + if (!eng3d_class) { + NOUVEAU_ERR("Unknown nv3x/nv4x chipset: nv%02x\n", dev->chipset); + return NULL; + } + + screen->advertise_npot = !!screen->is_nv4x; + screen->advertise_blend_equation_separate = !!screen->is_nv4x; + screen->use_nv4x = screen->is_nv4x; + + if(screen->is_nv4x) { + if(debug_get_bool_option("NVFX_SIMULATE_NV30", FALSE)) + screen->use_nv4x = 0; + if(!debug_get_bool_option("NVFX_NPOT", TRUE)) + screen->advertise_npot = 0; + if(!debug_get_bool_option("NVFX_BLEND_EQ_SEP", TRUE)) + screen->advertise_blend_equation_separate = 0; + } + + screen->force_swtnl = debug_get_bool_option("NVFX_SWTNL", FALSE); + screen->trace_draw = debug_get_bool_option("NVFX_TRACE_DRAW", FALSE); + + screen->buffer_allocation_cost = debug_get_num_option("NVFX_BUFFER_ALLOCATION_COST", 16384); + screen->inline_cost_per_hardware_cost = atof(debug_get_option("NVFX_INLINE_COST_PER_HARDWARE_COST", "1.0")); + screen->static_reuse_threshold = atof(debug_get_option("NVFX_STATIC_REUSE_THRESHOLD", "2.0")); + + /* We don't advertise these by default because filtering and blending doesn't work as + * it should, due to several restrictions. + * The only exception is fp16 on nv40. + */ + screen->advertise_fp16 = debug_get_bool_option("NVFX_FP16", !!screen->use_nv4x); + screen->advertise_fp32 = debug_get_bool_option("NVFX_FP32", 0); + + screen->vertex_buffer_reloc_flags = nvfx_screen_get_vertex_buffer_flags(screen); + + /* surely both nv3x and nv44 support index buffers too: find out how and test that */ + if(eng3d_class == NV40_3D) + screen->index_buffer_reloc_flags = screen->vertex_buffer_reloc_flags; + + if(!screen->force_swtnl && screen->vertex_buffer_reloc_flags == screen->index_buffer_reloc_flags) + screen->base.vertex_buffer_flags = screen->base.index_buffer_flags = screen->vertex_buffer_reloc_flags; + + nvfx_screen_init_resource_functions(pscreen); + + ret = nouveau_grobj_alloc(chan, 0xbeef3097, eng3d_class, &screen->eng3d); + if (ret) { + NOUVEAU_ERR("Error creating 3D object: %d\n", ret); + return FALSE; + } + + /* 2D engine setup */ + nvfx_screen_surface_init(pscreen); + + /* Notifier for sync purposes */ + ret = nouveau_notifier_alloc(chan, 0xbeef0301, 1, &screen->sync); + if (ret) { + NOUVEAU_ERR("Error creating notifier object: %d\n", ret); + nvfx_screen_destroy(pscreen); + return NULL; + } + + /* Query objects */ + for(i = 0; i < sizeof(query_sizes) / sizeof(query_sizes[0]); ++i) + { + ret = nouveau_notifier_alloc(chan, 0xbeef0302, query_sizes[i], &screen->query); + if(!ret) + break; + } + + if (ret) { + NOUVEAU_ERR("Error initialising query objects: %d\n", ret); + nvfx_screen_destroy(pscreen); + return NULL; + } + + ret = nouveau_resource_init(&screen->query_heap, 0, query_sizes[i]); + if (ret) { + NOUVEAU_ERR("Error initialising query object heap: %d\n", ret); + nvfx_screen_destroy(pscreen); + return NULL; + } + + LIST_INITHEAD(&screen->query_list); + + /* Vtxprog resources */ + if (nouveau_resource_init(&screen->vp_exec_heap, 0, screen->use_nv4x ? 512 : 256) || + nouveau_resource_init(&screen->vp_data_heap, 0, screen->use_nv4x ? 468 : 256)) { + nvfx_screen_destroy(pscreen); + return NULL; + } + + BIND_RING(chan, screen->eng3d, 7); + + /* Static eng3d initialisation */ + /* note that we just started using the channel, so we must have space in the pushbuffer */ + OUT_RING(chan, RING_3D(NV30_3D_DMA_NOTIFY, 1)); + OUT_RING(chan, screen->sync->handle); + OUT_RING(chan, RING_3D(NV30_3D_DMA_TEXTURE0, 2)); + OUT_RING(chan, chan->vram->handle); + OUT_RING(chan, chan->gart->handle); + OUT_RING(chan, RING_3D(NV30_3D_DMA_COLOR1, 1)); + OUT_RING(chan, chan->vram->handle); + OUT_RING(chan, RING_3D(NV30_3D_DMA_COLOR0, 2)); + OUT_RING(chan, chan->vram->handle); + OUT_RING(chan, chan->vram->handle); + OUT_RING(chan, RING_3D(NV30_3D_DMA_VTXBUF0, 2)); + OUT_RING(chan, chan->vram->handle); + OUT_RING(chan, chan->gart->handle); + + OUT_RING(chan, RING_3D(NV30_3D_DMA_FENCE, 2)); + OUT_RING(chan, 0); + OUT_RING(chan, screen->query->handle); + + OUT_RING(chan, RING_3D(NV30_3D_DMA_UNK1AC, 2)); + OUT_RING(chan, chan->vram->handle); + OUT_RING(chan, chan->vram->handle); + + if(!screen->is_nv4x) + nv30_screen_init(screen); + else + nv40_screen_init(screen); + + return pscreen; +} diff --git a/src/gallium/drivers/nvfx/nvfx_screen.h b/src/gallium/drivers/nvfx/nvfx_screen.h new file mode 100644 index 0000000..b1f0718 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_screen.h @@ -0,0 +1,65 @@ +#ifndef __NVFX_SCREEN_H__ +#define __NVFX_SCREEN_H__ + +#include "pipe/p_compiler.h" +#include "util/u_double_list.h" +#include "nouveau/nouveau_screen.h" + +struct pipe_screen; + +struct nvfx_screen { + struct nouveau_screen base; + + struct nouveau_winsys *nvws; + + struct nvfx_context *cur_ctx; + + unsigned is_nv4x; /* either 0 or ~0 */ + unsigned use_nv4x; /* either 0 or ~0 */ + boolean force_swtnl; + boolean trace_draw; + unsigned vertex_buffer_reloc_flags; + unsigned index_buffer_reloc_flags; + unsigned advertise_fp16; + unsigned advertise_fp32; + unsigned advertise_npot; + unsigned advertise_blend_equation_separate; + + /* HW graphics objects */ + struct nouveau_grobj *eng3d; + struct nouveau_notifier *sync; + + /* Query object resources */ + struct nouveau_notifier *query; + struct nouveau_resource *query_heap; + struct list_head query_list; + + /* Vtxprog resources */ + struct nouveau_resource *vp_exec_heap; + struct nouveau_resource *vp_data_heap; + + struct nv04_2d_context* eng2d; + + /* Once the amount of bytes drawn from the buffer reaches the updated size times this value, + * we will assume that the buffer will be drawn an huge number of times before the + * next modification + */ + float static_reuse_threshold; + + /* Cost of allocating a buffer in terms of the cost of copying a byte to an hardware buffer */ + unsigned buffer_allocation_cost; + + /* inline_cost/hardware_cost conversion ration */ + float inline_cost_per_hardware_cost; +}; + +static INLINE struct nvfx_screen * +nvfx_screen(struct pipe_screen *screen) +{ + return (struct nvfx_screen *)screen; +} + +int nvfx_screen_surface_init(struct pipe_screen *pscreen); +void nvfx_screen_surface_takedown(struct pipe_screen *pscreen); + +#endif diff --git a/src/gallium/drivers/nvfx/nvfx_shader.h b/src/gallium/drivers/nvfx/nvfx_shader.h new file mode 100644 index 0000000..46406b2 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_shader.h @@ -0,0 +1,526 @@ +#ifndef __NVFX_SHADER_H__ +#define __NVFX_SHADER_H__ + +#include + +#include "pipe/p_compiler.h" + +#define NVFX_SWZ_IDENTITY ((3 << 6) | (2 << 4) | (1 << 2) | (0 << 0)) + +/* this will resolve to either the NV30 or the NV40 version + * depending on the current hardware */ +/* unusual, but very fast and compact method */ +#define NVFX_VP(c) ((NV30_VP_##c) + (nvfx->is_nv4x & ((NV40_VP_##c) - (NV30_VP_##c)))) + +#define NVFX_VP_INST_SLOT_VEC 0 +#define NVFX_VP_INST_SLOT_SCA 1 + +#define NVFX_VP_INST_IN_POS 0 /* These seem to match the bindings specified in */ +#define NVFX_VP_INST_IN_WEIGHT 1 /* the ARB_v_p spec (2.14.3.1) */ +#define NVFX_VP_INST_IN_NORMAL 2 +#define NVFX_VP_INST_IN_COL0 3 /* Should probably confirm them all though */ +#define NVFX_VP_INST_IN_COL1 4 +#define NVFX_VP_INST_IN_FOGC 5 +#define NVFX_VP_INST_IN_TC0 8 +#define NVFX_VP_INST_IN_TC(n) (8+n) + +#define NVFX_VP_INST_SCA_OP_NOP 0x00 +#define NVFX_VP_INST_SCA_OP_MOV 0x01 +#define NVFX_VP_INST_SCA_OP_RCP 0x02 +#define NVFX_VP_INST_SCA_OP_RCC 0x03 +#define NVFX_VP_INST_SCA_OP_RSQ 0x04 +#define NVFX_VP_INST_SCA_OP_EXP 0x05 +#define NVFX_VP_INST_SCA_OP_LOG 0x06 +#define NVFX_VP_INST_SCA_OP_LIT 0x07 +#define NVFX_VP_INST_SCA_OP_BRA 0x09 +#define NVFX_VP_INST_SCA_OP_CAL 0x0B +#define NVFX_VP_INST_SCA_OP_RET 0x0C +#define NVFX_VP_INST_SCA_OP_LG2 0x0D +#define NVFX_VP_INST_SCA_OP_EX2 0x0E +#define NVFX_VP_INST_SCA_OP_SIN 0x0F +#define NVFX_VP_INST_SCA_OP_COS 0x10 + +#define NV40_VP_INST_SCA_OP_PUSHA 0x13 +#define NV40_VP_INST_SCA_OP_POPA 0x14 + +#define NVFX_VP_INST_VEC_OP_NOP 0x00 +#define NVFX_VP_INST_VEC_OP_MOV 0x01 +#define NVFX_VP_INST_VEC_OP_MUL 0x02 +#define NVFX_VP_INST_VEC_OP_ADD 0x03 +#define NVFX_VP_INST_VEC_OP_MAD 0x04 +#define NVFX_VP_INST_VEC_OP_DP3 0x05 +#define NVFX_VP_INST_VEC_OP_DPH 0x06 +#define NVFX_VP_INST_VEC_OP_DP4 0x07 +#define NVFX_VP_INST_VEC_OP_DST 0x08 +#define NVFX_VP_INST_VEC_OP_MIN 0x09 +#define NVFX_VP_INST_VEC_OP_MAX 0x0A +#define NVFX_VP_INST_VEC_OP_SLT 0x0B +#define NVFX_VP_INST_VEC_OP_SGE 0x0C +#define NVFX_VP_INST_VEC_OP_ARL 0x0D +#define NVFX_VP_INST_VEC_OP_FRC 0x0E +#define NVFX_VP_INST_VEC_OP_FLR 0x0F +#define NVFX_VP_INST_VEC_OP_SEQ 0x10 +#define NVFX_VP_INST_VEC_OP_SFL 0x11 +#define NVFX_VP_INST_VEC_OP_SGT 0x12 +#define NVFX_VP_INST_VEC_OP_SLE 0x13 +#define NVFX_VP_INST_VEC_OP_SNE 0x14 +#define NVFX_VP_INST_VEC_OP_STR 0x15 +#define NVFX_VP_INST_VEC_OP_SSG 0x16 +#define NVFX_VP_INST_VEC_OP_ARR 0x17 +#define NVFX_VP_INST_VEC_OP_ARA 0x18 + +#define NV40_VP_INST_VEC_OP_TXL 0x19 + +/* DWORD 3 */ +#define NVFX_VP_INST_LAST (1 << 0) + +/* + * Each fragment program opcode appears to be comprised of 4 32-bit values. + * + * 0: OPDEST + * 0: program end + * 1-6: destination register + * 7: destination register is fp16?? (use for outputs) + * 8: set condition code + * 9: writemask x + * 10: writemask y + * 11: writemask z + * 12: writemask w + * 13-16: source attribute register number (e.g. COL0) + * 17-20: texture unit number + * 21: expand value on texture operation (x -> 2x - 1) + * 22-23: precision 0 = fp32, 1 = fp16, 2 = s1.10 fixed, 3 = s0.8 fixed (nv40-only)) + * 24-29: opcode + * 30: no destination + * 31: saturate + * 1 - SRC0 + * 0-17: see common source fields + * 18: execute if condition code less + * 19: execute if condition code equal + * 20: execute if condition code greater + * 21-22: condition code swizzle x source component + * 23-24: condition code swizzle y source component + * 25-26: condition code swizzle z source component + * 27-28: condition code swizzle w source component + * 29: source 0 absolute + * 30: always 0 in renouveau tests + * 31: always 0 in renouveau tests + * 2 - SRC1 + * 0-17: see common source fields + * 18: source 1 absolute + * 19-20: input precision 0 = fp32, 1 = fp16, 2 = s1.10 fixed, 3 = ??? + * 21-27: always 0 in renouveau tests + * 28-30: scale (0 = 1x, 1 = 2x, 2 = 4x, 3 = 8x, 4 = ???, 5, = 1/2, 6 = 1/4, 7 = 1/8) + * 31: opcode is branch + * 3 - SRC2 + * 0-17: see common source fields + * 18: source 2 absolute + * 19-29: address register displacement + * 30: use index register + * 31: disable perspective-correct interpolation? + * +* Common fields of 0, 1, 2 - SRC + * 0-1: source register type (0 = temp, 1 = input, 2 = immediate, 3 = ???) + * 2-7: source temp register index + * 8: source register is fp16?? + * 9-10: source swizzle x source component + * 11-12: source swizzle y source component + * 13-14: source swizzle z source component + * 15-16: source swizzle w source component + * 17: negate + + * There appears to be no special difference between result regs and temp regs. + * result.color == R0.xyzw + * result.depth == R1.z + * When the fragprog contains instructions to write depth, NV30_TCL_PRIMITIVE_3D_UNK1D78=0 + * otherwise it is set to 1. + * + * Constants are inserted directly after the instruction that uses them. + * + * It appears that it's not possible to use two input registers in one + * instruction as the input sourcing is done in the instruction dword + * and not the source selection dwords. As such instructions such as: + * + * ADD result.color, fragment.color, fragment.texcoord[0]; + * + * must be split into two MOV's and then an ADD (nvidia does this) but + * I'm not sure why it's not just one MOV and then source the second input + * in the ADD instruction.. + * + * Negation of the full source is done with NV30_FP_REG_NEGATE, arbitrary + * negation requires multiplication with a const. + * + * Arbitrary swizzling is supported with the exception of SWIZZLE_ZERO/SWIZZLE_ONE + * The temp/result regs appear to be initialised to (0.0, 0.0, 0.0, 0.0) as SWIZZLE_ZERO + * is implemented simply by not writing to the relevant components of the destination. + * + * Conditional execution + * TODO + * + * Non-native instructions: + * LIT + * LRP - MAD+MAD + * SUB - ADD, negate second source + * RSQ - LG2 + EX2 + * POW - LG2 + MUL + EX2 + * SCS - COS + SIN + * XPD + * + * NV40 Looping + * Loops appear to be fairly expensive on NV40 at least, the proprietary + * driver goes to a lot of effort to avoid using the native looping + * instructions. If the total number of *executed* instructions between + * REP/ENDREP or LOOP/ENDLOOP is <=500, the driver will unroll the loop. + * The maximum loop count is 255. + * + */ + +//== Opcode / Destination selection == +#define NVFX_FP_OP_PROGRAM_END (1 << 0) +#define NVFX_FP_OP_OUT_REG_SHIFT 1 +#define NV30_FP_OP_OUT_REG_MASK (31 << 1) /* uncertain */ +#define NV40_FP_OP_OUT_REG_MASK (63 << 1) +/* Needs to be set when writing outputs to get expected result.. */ +#define NVFX_FP_OP_OUT_REG_HALF (1 << 7) +#define NVFX_FP_OP_COND_WRITE_ENABLE (1 << 8) +#define NVFX_FP_OP_OUTMASK_SHIFT 9 +#define NVFX_FP_OP_OUTMASK_MASK (0xF << 9) +# define NVFX_FP_OP_OUT_X (1<<9) +# define NVFX_FP_OP_OUT_Y (1<<10) +# define NVFX_FP_OP_OUT_Z (1<<11) +# define NVFX_FP_OP_OUT_W (1<<12) +/* Uncertain about these, especially the input_src values.. it's possible that + * they can be dynamically changed. + */ +#define NVFX_FP_OP_INPUT_SRC_SHIFT 13 +#define NVFX_FP_OP_INPUT_SRC_MASK (15 << 13) +# define NVFX_FP_OP_INPUT_SRC_POSITION 0x0 +# define NVFX_FP_OP_INPUT_SRC_COL0 0x1 +# define NVFX_FP_OP_INPUT_SRC_COL1 0x2 +# define NVFX_FP_OP_INPUT_SRC_FOGC 0x3 +# define NVFX_FP_OP_INPUT_SRC_TC0 0x4 +# define NVFX_FP_OP_INPUT_SRC_TC(n) (0x4 + n) +# define NV40_FP_OP_INPUT_SRC_FACING 0xE +#define NVFX_FP_OP_TEX_UNIT_SHIFT 17 +#define NVFX_FP_OP_TEX_UNIT_MASK (0xF << 17) /* guess */ +#define NVFX_FP_OP_PRECISION_SHIFT 22 +#define NVFX_FP_OP_PRECISION_MASK (3 << 22) +# define NVFX_FP_PRECISION_FP32 0 +# define NVFX_FP_PRECISION_FP16 1 +# define NVFX_FP_PRECISION_FX12 2 +#define NVFX_FP_OP_OPCODE_SHIFT 24 +#define NVFX_FP_OP_OPCODE_MASK (0x3F << 24) +/* NV30/NV40 fragment program opcodes */ +#define NVFX_FP_OP_OPCODE_NOP 0x00 +#define NVFX_FP_OP_OPCODE_MOV 0x01 +#define NVFX_FP_OP_OPCODE_MUL 0x02 +#define NVFX_FP_OP_OPCODE_ADD 0x03 +#define NVFX_FP_OP_OPCODE_MAD 0x04 +#define NVFX_FP_OP_OPCODE_DP3 0x05 +#define NVFX_FP_OP_OPCODE_DP4 0x06 +#define NVFX_FP_OP_OPCODE_DST 0x07 +#define NVFX_FP_OP_OPCODE_MIN 0x08 +#define NVFX_FP_OP_OPCODE_MAX 0x09 +#define NVFX_FP_OP_OPCODE_SLT 0x0A +#define NVFX_FP_OP_OPCODE_SGE 0x0B +#define NVFX_FP_OP_OPCODE_SLE 0x0C +#define NVFX_FP_OP_OPCODE_SGT 0x0D +#define NVFX_FP_OP_OPCODE_SNE 0x0E +#define NVFX_FP_OP_OPCODE_SEQ 0x0F +#define NVFX_FP_OP_OPCODE_FRC 0x10 +#define NVFX_FP_OP_OPCODE_FLR 0x11 +#define NVFX_FP_OP_OPCODE_KIL 0x12 +#define NVFX_FP_OP_OPCODE_PK4B 0x13 +#define NVFX_FP_OP_OPCODE_UP4B 0x14 +#define NVFX_FP_OP_OPCODE_DDX 0x15 /* can only write XY */ +#define NVFX_FP_OP_OPCODE_DDY 0x16 /* can only write XY */ +#define NVFX_FP_OP_OPCODE_TEX 0x17 +#define NVFX_FP_OP_OPCODE_TXP 0x18 +#define NVFX_FP_OP_OPCODE_TXD 0x19 +#define NVFX_FP_OP_OPCODE_RCP 0x1A +#define NVFX_FP_OP_OPCODE_EX2 0x1C +#define NVFX_FP_OP_OPCODE_LG2 0x1D +#define NVFX_FP_OP_OPCODE_STR 0x20 +#define NVFX_FP_OP_OPCODE_SFL 0x21 +#define NVFX_FP_OP_OPCODE_COS 0x22 +#define NVFX_FP_OP_OPCODE_SIN 0x23 +#define NVFX_FP_OP_OPCODE_PK2H 0x24 +#define NVFX_FP_OP_OPCODE_UP2H 0x25 +#define NVFX_FP_OP_OPCODE_PK4UB 0x27 +#define NVFX_FP_OP_OPCODE_UP4UB 0x28 +#define NVFX_FP_OP_OPCODE_PK2US 0x29 +#define NVFX_FP_OP_OPCODE_UP2US 0x2A +#define NVFX_FP_OP_OPCODE_DP2A 0x2E +#define NVFX_FP_OP_OPCODE_TXB 0x31 +#define NVFX_FP_OP_OPCODE_DIV 0x3A + +/* NV30 only fragment program opcodes */ +#define NVFX_FP_OP_OPCODE_RSQ_NV30 0x1B +#define NVFX_FP_OP_OPCODE_LIT_NV30 0x1E +#define NVFX_FP_OP_OPCODE_LRP_NV30 0x1F +#define NVFX_FP_OP_OPCODE_POW_NV30 0x26 +#define NVFX_FP_OP_OPCODE_RFL_NV30 0x36 + +/* NV40 only fragment program opcodes */ +#define NVFX_FP_OP_OPCODE_TXL_NV40 0x2F +#define NVFX_FP_OP_OPCODE_LITEX2_NV40 0x3C + +/* The use of these instructions appears to be indicated by bit 31 of DWORD 2.*/ +#define NV40_FP_OP_BRA_OPCODE_BRK 0x0 +#define NV40_FP_OP_BRA_OPCODE_CAL 0x1 +#define NV40_FP_OP_BRA_OPCODE_IF 0x2 +#define NV40_FP_OP_BRA_OPCODE_LOOP 0x3 +#define NV40_FP_OP_BRA_OPCODE_REP 0x4 +#define NV40_FP_OP_BRA_OPCODE_RET 0x5 + +#define NV40_FP_OP_OUT_NONE (1 << 30) +#define NVFX_FP_OP_OUT_SAT (1 << 31) + +/* high order bits of SRC0 */ +#define NVFX_FP_OP_SRC0_ABS (1 << 29) +#define NVFX_FP_OP_COND_SWZ_W_SHIFT 27 +#define NVFX_FP_OP_COND_SWZ_W_MASK (3 << 27) +#define NVFX_FP_OP_COND_SWZ_Z_SHIFT 25 +#define NVFX_FP_OP_COND_SWZ_Z_MASK (3 << 25) +#define NVFX_FP_OP_COND_SWZ_Y_SHIFT 23 +#define NVFX_FP_OP_COND_SWZ_Y_MASK (3 << 23) +#define NVFX_FP_OP_COND_SWZ_X_SHIFT 21 +#define NVFX_FP_OP_COND_SWZ_X_MASK (3 << 21) +#define NVFX_FP_OP_COND_SWZ_ALL_SHIFT 21 +#define NVFX_FP_OP_COND_SWZ_ALL_MASK (0xFF << 21) +#define NVFX_FP_OP_COND_SHIFT 18 +#define NVFX_FP_OP_COND_MASK (0x07 << 18) +# define NVFX_FP_OP_COND_FL 0 +# define NVFX_FP_OP_COND_LT 1 +# define NVFX_FP_OP_COND_EQ 2 +# define NVFX_FP_OP_COND_LE 3 +# define NVFX_FP_OP_COND_GT 4 +# define NVFX_FP_OP_COND_NE 5 +# define NVFX_FP_OP_COND_GE 6 +# define NVFX_FP_OP_COND_TR 7 + +/* high order bits of SRC1 */ +#define NV40_FP_OP_OPCODE_IS_BRANCH (1<<31) +#define NVFX_FP_OP_DST_SCALE_SHIFT 28 +#define NVFX_FP_OP_DST_SCALE_MASK (3 << 28) +#define NVFX_FP_OP_DST_SCALE_1X 0 +#define NVFX_FP_OP_DST_SCALE_2X 1 +#define NVFX_FP_OP_DST_SCALE_4X 2 +#define NVFX_FP_OP_DST_SCALE_8X 3 +#define NVFX_FP_OP_DST_SCALE_INV_2X 5 +#define NVFX_FP_OP_DST_SCALE_INV_4X 6 +#define NVFX_FP_OP_DST_SCALE_INV_8X 7 +#define NVFX_FP_OP_SRC1_ABS (1 << 18) + +/* SRC1 LOOP */ +#define NV40_FP_OP_LOOP_INCR_SHIFT 19 +#define NV40_FP_OP_LOOP_INCR_MASK (0xFF << 19) +#define NV40_FP_OP_LOOP_INDEX_SHIFT 10 +#define NV40_FP_OP_LOOP_INDEX_MASK (0xFF << 10) +#define NV40_FP_OP_LOOP_COUNT_SHIFT 2 +#define NV40_FP_OP_LOOP_COUNT_MASK (0xFF << 2) + +/* SRC1 IF: absolute offset in dwords */ +#define NV40_FP_OP_ELSE_OFFSET_SHIFT 0 +#define NV40_FP_OP_ELSE_OFFSET_MASK (0x7FFFFFFF << 0) + +/* SRC1 CAL */ +#define NV40_FP_OP_SUB_OFFSET_SHIFT 0 +#define NV40_FP_OP_SUB_OFFSET_MASK (0x7FFFFFFF << 0) + +/* SRC1 REP + * I have no idea why there are 3 count values here.. but they + * have always been filled with the same value in my tests so + * far.. + */ +#define NV40_FP_OP_REP_COUNT1_SHIFT 2 +#define NV40_FP_OP_REP_COUNT1_MASK (0xFF << 2) +#define NV40_FP_OP_REP_COUNT2_SHIFT 10 +#define NV40_FP_OP_REP_COUNT2_MASK (0xFF << 10) +#define NV40_FP_OP_REP_COUNT3_SHIFT 19 +#define NV40_FP_OP_REP_COUNT3_MASK (0xFF << 19) + +/* SRC2 REP/IF: absolute offset in dwords */ +#define NV40_FP_OP_END_OFFSET_SHIFT 0 +#define NV40_FP_OP_END_OFFSET_MASK (0x7FFFFFFF << 0) + +/* high order bits of SRC2 */ +#define NVFX_FP_OP_INDEX_INPUT (1 << 30) +#define NV40_FP_OP_ADDR_INDEX_SHIFT 19 +#define NV40_FP_OP_ADDR_INDEX_MASK (0xF << 19) + +//== Register selection == +#define NVFX_FP_REG_TYPE_SHIFT 0 +#define NVFX_FP_REG_TYPE_MASK (3 << 0) +# define NVFX_FP_REG_TYPE_TEMP 0 +# define NVFX_FP_REG_TYPE_INPUT 1 +# define NVFX_FP_REG_TYPE_CONST 2 +#define NVFX_FP_REG_SRC_SHIFT 2 +#define NV30_FP_REG_SRC_MASK (31 << 2) +#define NV40_FP_REG_SRC_MASK (63 << 2) +#define NVFX_FP_REG_SRC_HALF (1 << 8) +#define NVFX_FP_REG_SWZ_ALL_SHIFT 9 +#define NVFX_FP_REG_SWZ_ALL_MASK (255 << 9) +#define NVFX_FP_REG_SWZ_X_SHIFT 9 +#define NVFX_FP_REG_SWZ_X_MASK (3 << 9) +#define NVFX_FP_REG_SWZ_Y_SHIFT 11 +#define NVFX_FP_REG_SWZ_Y_MASK (3 << 11) +#define NVFX_FP_REG_SWZ_Z_SHIFT 13 +#define NVFX_FP_REG_SWZ_Z_MASK (3 << 13) +#define NVFX_FP_REG_SWZ_W_SHIFT 15 +#define NVFX_FP_REG_SWZ_W_MASK (3 << 15) +# define NVFX_FP_SWIZZLE_X 0 +# define NVFX_FP_SWIZZLE_Y 1 +# define NVFX_FP_SWIZZLE_Z 2 +# define NVFX_FP_SWIZZLE_W 3 +#define NVFX_FP_REG_NEGATE (1 << 17) + +#define NVFXSR_NONE 0 +#define NVFXSR_OUTPUT 1 +#define NVFXSR_INPUT 2 +#define NVFXSR_TEMP 3 +#define NVFXSR_CONST 5 +#define NVFXSR_IMM 6 +#define NVFXSR_RELOCATED 7 + +#define NVFX_COND_FL 0 +#define NVFX_COND_LT 1 +#define NVFX_COND_EQ 2 +#define NVFX_COND_LE 3 +#define NVFX_COND_GT 4 +#define NVFX_COND_NE 5 +#define NVFX_COND_GE 6 +#define NVFX_COND_TR 7 + +/* Yes, this are ordered differently... */ + +#define NVFX_VP_MASK_X 8 +#define NVFX_VP_MASK_Y 4 +#define NVFX_VP_MASK_Z 2 +#define NVFX_VP_MASK_W 1 +#define NVFX_VP_MASK_ALL 0xf + +#define NVFX_FP_MASK_X 1 +#define NVFX_FP_MASK_Y 2 +#define NVFX_FP_MASK_Z 4 +#define NVFX_FP_MASK_W 8 +#define NVFX_FP_MASK_ALL 0xf + +#define NVFX_SWZ_X 0 +#define NVFX_SWZ_Y 1 +#define NVFX_SWZ_Z 2 +#define NVFX_SWZ_W 3 + +#define swz(s,x,y,z,w) nvfx_src_swz((s), NVFX_SWZ_##x, NVFX_SWZ_##y, NVFX_SWZ_##z, NVFX_SWZ_##w) +#define neg(s) nvfx_src_neg((s)) +#define abs(s) nvfx_src_abs((s)) + +struct nvfx_reg { + int8_t type; + uint32_t index; +}; + +struct nvfx_src { + struct nvfx_reg reg; + + uint8_t indirect : 1; + uint8_t indirect_reg : 1; + uint8_t indirect_swz : 2; + uint8_t negate : 1; + uint8_t abs : 1; + uint8_t swz[4]; +}; + +struct nvfx_insn +{ + uint8_t op; + char scale; + int8_t unit; + uint8_t mask; + uint8_t cc_swz[4]; + + uint8_t sat : 1; + uint8_t cc_update : 1; + uint8_t cc_update_reg : 1; + uint8_t cc_test : 3; + uint8_t cc_test_reg : 1; + + struct nvfx_reg dst; + struct nvfx_src src[3]; +}; + +static INLINE struct nvfx_insn +nvfx_insn(boolean sat, unsigned op, int unit, struct nvfx_reg dst, unsigned mask, struct nvfx_src s0, struct nvfx_src s1, struct nvfx_src s2) +{ + struct nvfx_insn insn = { + .op = op, + .scale = 0, + .unit = unit, + .sat = sat, + .mask = mask, + .cc_update = 0, + .cc_update_reg = 0, + .cc_test = NVFX_COND_TR, + .cc_test_reg = 0, + .cc_swz = { 0, 1, 2, 3 }, + .dst = dst, + .src = {s0, s1, s2} + }; + return insn; +} + +static INLINE struct nvfx_reg +nvfx_reg(int type, int index) +{ + struct nvfx_reg temp = { + .type = type, + .index = index, + }; + return temp; +} + +static INLINE struct nvfx_src +nvfx_src(struct nvfx_reg reg) +{ + struct nvfx_src temp = { + .reg = reg, + .abs = 0, + .negate = 0, + .swz = { 0, 1, 2, 3 }, + .indirect = 0, + }; + return temp; +} + +static INLINE struct nvfx_src +nvfx_src_swz(struct nvfx_src src, int x, int y, int z, int w) +{ + struct nvfx_src dst = src; + + dst.swz[NVFX_SWZ_X] = src.swz[x]; + dst.swz[NVFX_SWZ_Y] = src.swz[y]; + dst.swz[NVFX_SWZ_Z] = src.swz[z]; + dst.swz[NVFX_SWZ_W] = src.swz[w]; + return dst; +} + +static INLINE struct nvfx_src +nvfx_src_neg(struct nvfx_src src) +{ + src.negate = !src.negate; + return src; +} + +static INLINE struct nvfx_src +nvfx_src_abs(struct nvfx_src src) +{ + src.abs = 1; + return src; +} + +struct nvfx_relocation { + unsigned location; + unsigned target; +}; + +#endif diff --git a/src/gallium/drivers/nvfx/nvfx_state.c b/src/gallium/drivers/nvfx/nvfx_state.c new file mode 100644 index 0000000..5461903 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_state.c @@ -0,0 +1,389 @@ +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_framebuffer.h" + +#include "draw/draw_context.h" + +#include "tgsi/tgsi_parse.h" + +#include "nvfx_context.h" +#include "nvfx_state.h" +#include "nvfx_tex.h" + +static void * +nvfx_blend_state_create(struct pipe_context *pipe, + const struct pipe_blend_state *cso) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + struct nvfx_blend_state *bso = CALLOC(1, sizeof(*bso)); + struct nouveau_statebuf_builder sb = sb_init(bso->sb); + + if (cso->rt[0].blend_enable) { + sb_method(sb, NV30_3D_BLEND_FUNC_ENABLE, 3); + sb_data(sb, 1); + sb_data(sb, (nvgl_blend_func(cso->rt[0].alpha_src_factor) << 16) | + nvgl_blend_func(cso->rt[0].rgb_src_factor)); + sb_data(sb, nvgl_blend_func(cso->rt[0].alpha_dst_factor) << 16 | + nvgl_blend_func(cso->rt[0].rgb_dst_factor)); + if(nvfx->screen->base.device->chipset < 0x40) { + sb_method(sb, NV30_3D_BLEND_EQUATION, 1); + sb_data(sb, nvgl_blend_eqn(cso->rt[0].rgb_func)); + } else { + sb_method(sb, NV40_3D_BLEND_EQUATION, 1); + sb_data(sb, nvgl_blend_eqn(cso->rt[0].alpha_func) << 16 | + nvgl_blend_eqn(cso->rt[0].rgb_func)); + } + } else { + sb_method(sb, NV30_3D_BLEND_FUNC_ENABLE, 1); + sb_data(sb, 0); + } + + sb_method(sb, NV30_3D_COLOR_MASK, 1); + sb_data(sb, (((cso->rt[0].colormask & PIPE_MASK_A) ? (0x01 << 24) : 0) | + ((cso->rt[0].colormask & PIPE_MASK_R) ? (0x01 << 16) : 0) | + ((cso->rt[0].colormask & PIPE_MASK_G) ? (0x01 << 8) : 0) | + ((cso->rt[0].colormask & PIPE_MASK_B) ? (0x01 << 0) : 0))); + + /* TODO: add NV40 MRT color mask */ + + if (cso->logicop_enable) { + sb_method(sb, NV30_3D_COLOR_LOGIC_OP_ENABLE, 2); + sb_data(sb, 1); + sb_data(sb, nvgl_logicop_func(cso->logicop_func)); + } else { + sb_method(sb, NV30_3D_COLOR_LOGIC_OP_ENABLE, 1); + sb_data(sb, 0); + } + + sb_method(sb, NV30_3D_DITHER_ENABLE, 1); + sb_data(sb, cso->dither ? 1 : 0); + + bso->sb_len = sb_len(sb, bso->sb); + bso->pipe = *cso; + return (void *)bso; +} + +static void +nvfx_blend_state_bind(struct pipe_context *pipe, void *hwcso) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + nvfx->blend = hwcso; + nvfx->dirty |= NVFX_NEW_BLEND; +} + +static void +nvfx_blend_state_delete(struct pipe_context *pipe, void *hwcso) +{ + struct nvfx_blend_state *bso = hwcso; + + FREE(bso); +} + +static void * +nvfx_rasterizer_state_create(struct pipe_context *pipe, + const struct pipe_rasterizer_state *cso) +{ + struct nvfx_rasterizer_state *rsso = CALLOC(1, sizeof(*rsso)); + struct nouveau_statebuf_builder sb = sb_init(rsso->sb); + + /*XXX: ignored: + * point_smooth -nohw + * multisample + * sprite_coord_origin + */ + + sb_method(sb, NV30_3D_SHADE_MODEL, 1); + sb_data(sb, cso->flatshade ? NV30_3D_SHADE_MODEL_FLAT : + NV30_3D_SHADE_MODEL_SMOOTH); + + sb_method(sb, NV30_3D_VERTEX_TWO_SIDE_ENABLE, 1); + sb_data(sb, cso->light_twoside); + + sb_method(sb, NV30_3D_LINE_WIDTH, 2); + sb_data(sb, (unsigned char)(cso->line_width * 8.0) & 0xff); + sb_data(sb, cso->line_smooth ? 1 : 0); + sb_method(sb, NV30_3D_LINE_STIPPLE_ENABLE, 2); + sb_data(sb, cso->line_stipple_enable ? 1 : 0); + sb_data(sb, (cso->line_stipple_pattern << 16) | + cso->line_stipple_factor); + + sb_method(sb, NV30_3D_POINT_SIZE, 1); + sb_data(sb, fui(cso->point_size)); + + sb_method(sb, NV30_3D_POLYGON_MODE_FRONT, 6); + sb_data(sb, nvgl_polygon_mode(cso->fill_front)); + sb_data(sb, nvgl_polygon_mode(cso->fill_back)); + switch (cso->cull_face) { + case PIPE_FACE_FRONT: + sb_data(sb, NV30_3D_CULL_FACE_FRONT); + break; + case PIPE_FACE_BACK: + sb_data(sb, NV30_3D_CULL_FACE_BACK); + break; + case PIPE_FACE_FRONT_AND_BACK: + sb_data(sb, NV30_3D_CULL_FACE_FRONT_AND_BACK); + break; + default: + sb_data(sb, NV30_3D_CULL_FACE_BACK); + break; + } + if (cso->front_ccw) { + sb_data(sb, NV30_3D_FRONT_FACE_CCW); + } else { + sb_data(sb, NV30_3D_FRONT_FACE_CW); + } + sb_data(sb, cso->poly_smooth ? 1 : 0); + sb_data(sb, (cso->cull_face != PIPE_FACE_NONE) ? 1 : 0); + + sb_method(sb, NV30_3D_POLYGON_STIPPLE_ENABLE, 1); + sb_data(sb, cso->poly_stipple_enable ? 1 : 0); + + sb_method(sb, NV30_3D_POLYGON_OFFSET_POINT_ENABLE, 3); + sb_data(sb, cso->offset_point); + sb_data(sb, cso->offset_line); + sb_data(sb, cso->offset_tri); + + if (cso->offset_point || cso->offset_line || cso->offset_tri) { + sb_method(sb, NV30_3D_POLYGON_OFFSET_FACTOR, 2); + sb_data(sb, fui(cso->offset_scale)); + sb_data(sb, fui(cso->offset_units * 2)); + } + + sb_method(sb, NV30_3D_FLATSHADE_FIRST, 1); + sb_data(sb, cso->flatshade_first); + + rsso->pipe = *cso; + rsso->sb_len = sb_len(sb, rsso->sb); + return (void *)rsso; +} + +static void +nvfx_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + if(nvfx->rasterizer && hwcso) + { + if(!nvfx->rasterizer || ((struct nvfx_rasterizer_state*)hwcso)->pipe.scissor + != nvfx->rasterizer->pipe.scissor) + { + nvfx->dirty |= NVFX_NEW_SCISSOR; + nvfx->draw_dirty |= NVFX_NEW_SCISSOR; + } + + if(((struct nvfx_rasterizer_state*)hwcso)->pipe.point_quad_rasterization != nvfx->rasterizer->pipe.point_quad_rasterization + || ((struct nvfx_rasterizer_state*)hwcso)->pipe.sprite_coord_enable != nvfx->rasterizer->pipe.sprite_coord_enable + || ((struct nvfx_rasterizer_state*)hwcso)->pipe.sprite_coord_mode != nvfx->rasterizer->pipe.sprite_coord_mode) + { + nvfx->dirty |= NVFX_NEW_SPRITE; + } + } + + nvfx->rasterizer = hwcso; + nvfx->dirty |= NVFX_NEW_RAST; + nvfx->draw_dirty |= NVFX_NEW_RAST; +} + +static void +nvfx_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso) +{ + struct nvfx_rasterizer_state *rsso = hwcso; + + FREE(rsso); +} + +static void * +nvfx_depth_stencil_alpha_state_create(struct pipe_context *pipe, + const struct pipe_depth_stencil_alpha_state *cso) +{ + struct nvfx_zsa_state *zsaso = CALLOC(1, sizeof(*zsaso)); + struct nouveau_statebuf_builder sb = sb_init(zsaso->sb); + + sb_method(sb, NV30_3D_DEPTH_FUNC, 1); + sb_data (sb, nvgl_comparison_op(cso->depth.func)); + + sb_method(sb, NV30_3D_ALPHA_FUNC_ENABLE, 3); + sb_data (sb, cso->alpha.enabled ? 1 : 0); + sb_data (sb, nvgl_comparison_op(cso->alpha.func)); + sb_data (sb, float_to_ubyte(cso->alpha.ref_value)); + + if (cso->stencil[0].enabled) { + sb_method(sb, NV30_3D_STENCIL_ENABLE(0), 3); + sb_data (sb, cso->stencil[0].enabled ? 1 : 0); + sb_data (sb, cso->stencil[0].writemask); + sb_data (sb, nvgl_comparison_op(cso->stencil[0].func)); + sb_method(sb, NV30_3D_STENCIL_FUNC_MASK(0), 4); + sb_data (sb, cso->stencil[0].valuemask); + sb_data (sb, nvgl_stencil_op(cso->stencil[0].fail_op)); + sb_data (sb, nvgl_stencil_op(cso->stencil[0].zfail_op)); + sb_data (sb, nvgl_stencil_op(cso->stencil[0].zpass_op)); + } else { + sb_method(sb, NV30_3D_STENCIL_ENABLE(0), 1); + sb_data (sb, 0); + } + + if (cso->stencil[1].enabled) { + sb_method(sb, NV30_3D_STENCIL_ENABLE(1), 3); + sb_data (sb, cso->stencil[1].enabled ? 1 : 0); + sb_data (sb, cso->stencil[1].writemask); + sb_data (sb, nvgl_comparison_op(cso->stencil[1].func)); + sb_method(sb, NV30_3D_STENCIL_FUNC_MASK(1), 4); + sb_data (sb, cso->stencil[1].valuemask); + sb_data (sb, nvgl_stencil_op(cso->stencil[1].fail_op)); + sb_data (sb, nvgl_stencil_op(cso->stencil[1].zfail_op)); + sb_data (sb, nvgl_stencil_op(cso->stencil[1].zpass_op)); + } else { + sb_method(sb, NV30_3D_STENCIL_ENABLE(1), 1); + sb_data (sb, 0); + } + + zsaso->pipe = *cso; + zsaso->sb_len = sb_len(sb, zsaso->sb); + return (void *)zsaso; +} + +static void +nvfx_depth_stencil_alpha_state_bind(struct pipe_context *pipe, void *hwcso) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + nvfx->zsa = hwcso; + nvfx->dirty |= NVFX_NEW_ZSA; +} + +static void +nvfx_depth_stencil_alpha_state_delete(struct pipe_context *pipe, void *hwcso) +{ + struct nvfx_zsa_state *zsaso = hwcso; + + FREE(zsaso); +} + +static void +nvfx_set_blend_color(struct pipe_context *pipe, + const struct pipe_blend_color *bcol) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + nvfx->blend_colour = *bcol; + nvfx->dirty |= NVFX_NEW_BCOL; +} + +static void +nvfx_set_stencil_ref(struct pipe_context *pipe, + const struct pipe_stencil_ref *sr) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + nvfx->stencil_ref = *sr; + nvfx->dirty |= NVFX_NEW_SR; +} + +static void +nvfx_set_clip_state(struct pipe_context *pipe, + const struct pipe_clip_state *clip) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + nvfx->clip = *clip; + nvfx->dirty |= NVFX_NEW_UCP; + nvfx->draw_dirty |= NVFX_NEW_UCP; +} + +static void +nvfx_set_sample_mask(struct pipe_context *pipe, + unsigned sample_mask) +{ +} + +static void +nvfx_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index, + struct pipe_resource *buf ) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + nvfx->constbuf[shader] = buf; + nvfx->constbuf_nr[shader] = buf ? (buf->width0 / (4 * sizeof(float))) : 0; + + if (shader == PIPE_SHADER_VERTEX) { + nvfx->dirty |= NVFX_NEW_VERTCONST; + } else + if (shader == PIPE_SHADER_FRAGMENT) { + nvfx->dirty |= NVFX_NEW_FRAGCONST; + } +} + +static void +nvfx_set_framebuffer_state(struct pipe_context *pipe, + const struct pipe_framebuffer_state *fb) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + if(fb) + util_copy_framebuffer_state(&nvfx->framebuffer, fb); + else + util_unreference_framebuffer_state(&nvfx->framebuffer); + nvfx->dirty |= NVFX_NEW_FB; +} + +static void +nvfx_set_polygon_stipple(struct pipe_context *pipe, + const struct pipe_poly_stipple *stipple) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + memcpy(nvfx->stipple, stipple->stipple, 4 * 32); + nvfx->dirty |= NVFX_NEW_STIPPLE; +} + +static void +nvfx_set_scissor_state(struct pipe_context *pipe, + const struct pipe_scissor_state *s) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + nvfx->scissor = *s; + nvfx->dirty |= NVFX_NEW_SCISSOR; +} + +static void +nvfx_set_viewport_state(struct pipe_context *pipe, + const struct pipe_viewport_state *vpt) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + nvfx->viewport = *vpt; + nvfx->dirty |= NVFX_NEW_VIEWPORT; + nvfx->draw_dirty |= NVFX_NEW_VIEWPORT; +} + +void +nvfx_init_state_functions(struct nvfx_context *nvfx) +{ + nvfx->pipe.create_blend_state = nvfx_blend_state_create; + nvfx->pipe.bind_blend_state = nvfx_blend_state_bind; + nvfx->pipe.delete_blend_state = nvfx_blend_state_delete; + + nvfx->pipe.create_rasterizer_state = nvfx_rasterizer_state_create; + nvfx->pipe.bind_rasterizer_state = nvfx_rasterizer_state_bind; + nvfx->pipe.delete_rasterizer_state = nvfx_rasterizer_state_delete; + + nvfx->pipe.create_depth_stencil_alpha_state = + nvfx_depth_stencil_alpha_state_create; + nvfx->pipe.bind_depth_stencil_alpha_state = + nvfx_depth_stencil_alpha_state_bind; + nvfx->pipe.delete_depth_stencil_alpha_state = + nvfx_depth_stencil_alpha_state_delete; + + nvfx->pipe.set_blend_color = nvfx_set_blend_color; + nvfx->pipe.set_stencil_ref = nvfx_set_stencil_ref; + nvfx->pipe.set_clip_state = nvfx_set_clip_state; + nvfx->pipe.set_sample_mask = nvfx_set_sample_mask; + nvfx->pipe.set_constant_buffer = nvfx_set_constant_buffer; + nvfx->pipe.set_framebuffer_state = nvfx_set_framebuffer_state; + nvfx->pipe.set_polygon_stipple = nvfx_set_polygon_stipple; + nvfx->pipe.set_scissor_state = nvfx_set_scissor_state; + nvfx->pipe.set_viewport_state = nvfx_set_viewport_state; +} diff --git a/src/gallium/drivers/nvfx/nvfx_state.h b/src/gallium/drivers/nvfx/nvfx_state.h new file mode 100644 index 0000000..8fafca1 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_state.h @@ -0,0 +1,114 @@ +#ifndef __NVFX_STATE_H__ +#define __NVFX_STATE_H__ + +#include "pipe/p_state.h" +#include "tgsi/tgsi_scan.h" +#include "nouveau/nouveau_statebuf.h" +#include "util/u_dynarray.h" +#include "util/u_linkage.h" + +struct nvfx_vertex_program_exec { + uint32_t data[4]; +}; + +struct nvfx_vertex_program_data { + int index; /* immediates == -1 */ + float value[4]; +}; + +struct nvfx_vertex_program { + unsigned long long id; + + struct nvfx_vertex_program_exec *insns; + unsigned nr_insns; + struct nvfx_vertex_program_data *consts; + unsigned nr_consts; + + char generic_to_fp_input[256]; + int sprite_fp_input; + + struct nouveau_resource *exec; + unsigned exec_start; + struct nouveau_resource *data; + unsigned data_start; + unsigned data_start_min; + + uint32_t ir; + uint32_t or; + int clip_nr; + + struct util_dynarray branch_relocs; + struct util_dynarray const_relocs; +}; + +#define NVFX_VP_FAILED ((struct nvfx_vertex_program*)-1) + +struct nvfx_pipe_vertex_program { + struct pipe_shader_state pipe; + struct tgsi_shader_info info; + + unsigned draw_elements; + boolean draw_no_elements; + struct draw_vertex_shader *draw_vs; + struct nvfx_vertex_program* draw_vp; + + struct nvfx_vertex_program* vp; +}; + +struct nvfx_fragment_program_data { + unsigned offset; + unsigned index; +}; + +struct nvfx_fragment_program_bo { + struct nvfx_fragment_program_bo* next; + struct nouveau_bo* bo; + unsigned char* slots; + char insn[] __attribute__((aligned(16))); +}; + +struct nvfx_fragment_program { + unsigned samplers; + unsigned point_sprite_control; + unsigned or; + unsigned coord_conventions; + + uint32_t *insn; + int insn_len; + + struct nvfx_fragment_program_data *consts; + unsigned nr_consts; + + /* the slot at num_slots is for the sprite coordinate, if any */ + unsigned num_slots; /* how many input semantics? */ + unsigned char slot_to_generic[10]; /* semantics */ + unsigned char slot_to_fp_input[11]; /* current assignment of slots for each used semantic */ + struct util_dynarray slot_relocations[11]; + + /* This is reset to progs on any relocation update, and decreases every time we + * move to a new prog due to a constant update + * When this is the same as progs, applying relocations is no longer necessary. + */ + unsigned progs_left_with_obsolete_slot_assignments; + + unsigned long long last_vp_id; + unsigned last_sprite_coord_enable; + + uint32_t fp_control; + + unsigned bo_prog_idx; + unsigned prog_size; + unsigned progs_per_bo; + unsigned progs; + + struct nvfx_fragment_program_bo* fpbo; +}; + +struct nvfx_pipe_fragment_program { + struct pipe_shader_state pipe; + struct tgsi_shader_info info; + + struct nvfx_fragment_program* fps[2]; +}; + +#endif diff --git a/src/gallium/drivers/nvfx/nvfx_state_emit.c b/src/gallium/drivers/nvfx/nvfx_state_emit.c new file mode 100644 index 0000000..501fdd4 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_state_emit.c @@ -0,0 +1,468 @@ +#include "nvfx_context.h" +#include "nvfx_state.h" +#include "nvfx_resource.h" +#include "draw/draw_context.h" + +void +nvfx_state_viewport_validate(struct nvfx_context *nvfx) +{ + struct nouveau_channel *chan = nvfx->screen->base.channel; + struct pipe_viewport_state *vpt = &nvfx->viewport; + + WAIT_RING(chan, 11); + if(nvfx->render_mode == HW) { + OUT_RING(chan, RING_3D(NV30_3D_VIEWPORT_TRANSLATE_X, 8)); + OUT_RINGf(chan, vpt->translate[0]); + OUT_RINGf(chan, vpt->translate[1]); + OUT_RINGf(chan, vpt->translate[2]); + OUT_RINGf(chan, vpt->translate[3]); + OUT_RINGf(chan, vpt->scale[0]); + OUT_RINGf(chan, vpt->scale[1]); + OUT_RINGf(chan, vpt->scale[2]); + OUT_RINGf(chan, vpt->scale[3]); + OUT_RING(chan, RING_3D(0x1d78, 1)); + OUT_RING(chan, 1); + } else { + OUT_RING(chan, RING_3D(NV30_3D_VIEWPORT_TRANSLATE_X, 8)); + OUT_RINGf(chan, 0.0f); + OUT_RINGf(chan, 0.0f); + OUT_RINGf(chan, 0.0f); + OUT_RINGf(chan, 0.0f); + OUT_RINGf(chan, 1.0f); + OUT_RINGf(chan, 1.0f); + OUT_RINGf(chan, 1.0f); + OUT_RINGf(chan, 1.0f); + OUT_RING(chan, RING_3D(0x1d78, 1)); + OUT_RING(chan, nvfx->is_nv4x ? 0x110 : 1); + } +} + +void +nvfx_state_scissor_validate(struct nvfx_context *nvfx) +{ + struct nouveau_channel *chan = nvfx->screen->base.channel; + struct pipe_rasterizer_state *rast = &nvfx->rasterizer->pipe; + struct pipe_scissor_state *s = &nvfx->scissor; + + if ((rast->scissor == 0 && nvfx->state.scissor_enabled == 0)) + return; + nvfx->state.scissor_enabled = rast->scissor; + + WAIT_RING(chan, 3); + OUT_RING(chan, RING_3D(NV30_3D_SCISSOR_HORIZ, 2)); + if (nvfx->state.scissor_enabled) { + OUT_RING(chan, ((s->maxx - s->minx) << 16) | s->minx); + OUT_RING(chan, ((s->maxy - s->miny) << 16) | s->miny); + } else { + OUT_RING(chan, 4096 << 16); + OUT_RING(chan, 4096 << 16); + } +} + +void +nvfx_state_sr_validate(struct nvfx_context *nvfx) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + struct pipe_stencil_ref *sr = &nvfx->stencil_ref; + + WAIT_RING(chan, 4); + OUT_RING(chan, RING_3D(NV30_3D_STENCIL_FUNC_REF(0), 1)); + OUT_RING(chan, sr->ref_value[0]); + OUT_RING(chan, RING_3D(NV30_3D_STENCIL_FUNC_REF(1), 1)); + OUT_RING(chan, sr->ref_value[1]); +} + +void +nvfx_state_blend_colour_validate(struct nvfx_context *nvfx) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + struct pipe_blend_color *bcol = &nvfx->blend_colour; + + WAIT_RING(chan, 2); + OUT_RING(chan, RING_3D(NV30_3D_BLEND_COLOR, 1)); + OUT_RING(chan, ((float_to_ubyte(bcol->color[3]) << 24) | + (float_to_ubyte(bcol->color[0]) << 16) | + (float_to_ubyte(bcol->color[1]) << 8) | + (float_to_ubyte(bcol->color[2]) << 0))); +} + +void +nvfx_state_stipple_validate(struct nvfx_context *nvfx) +{ + struct nouveau_channel *chan = nvfx->screen->base.channel; + + WAIT_RING(chan, 33); + OUT_RING(chan, RING_3D(NV30_3D_POLYGON_STIPPLE_PATTERN(0), 32)); + OUT_RINGp(chan, nvfx->stipple, 32); +} + +static void +nvfx_coord_conventions_validate(struct nvfx_context* nvfx) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + unsigned value = nvfx->hw_fragprog->coord_conventions; + if(value & NV30_3D_COORD_CONVENTIONS_ORIGIN_INVERTED) + value |= nvfx->framebuffer.height << NV30_3D_COORD_CONVENTIONS_HEIGHT__SHIFT; + + WAIT_RING(chan, 2); + OUT_RING(chan, RING_3D(NV30_3D_COORD_CONVENTIONS, 1)); + OUT_RING(chan, value); +} + +static void +nvfx_ucp_validate(struct nvfx_context* nvfx) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + unsigned enables[7] = + { + 0, + NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE0, + NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE0 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE1, + NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE0 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE1 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE2, + NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE0 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE1 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE2 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE3, + NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE0 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE1 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE2 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE3 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE4, + NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE0 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE1 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE2 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE3 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE4 | NV30_3D_VP_CLIP_PLANES_ENABLE_PLANE5, + }; + + if(!nvfx->use_vp_clipping) + { + WAIT_RING(chan, 2); + OUT_RING(chan, RING_3D(NV30_3D_VP_CLIP_PLANES_ENABLE, 1)); + OUT_RING(chan, 0); + + WAIT_RING(chan, 6 * 4 + 1); + OUT_RING(chan, RING_3D(NV30_3D_VP_CLIP_PLANE(0, 0), nvfx->clip.nr * 4)); + OUT_RINGp(chan, &nvfx->clip.ucp[0][0], nvfx->clip.nr * 4); + } + + WAIT_RING(chan, 2); + OUT_RING(chan, RING_3D(NV30_3D_VP_CLIP_PLANES_ENABLE, 1)); + OUT_RING(chan, enables[nvfx->clip.nr]); +} + +static void +nvfx_vertprog_ucp_validate(struct nvfx_context* nvfx) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + unsigned i; + struct nvfx_vertex_program* vp = nvfx->hw_vertprog; + if(nvfx->clip.nr != vp->clip_nr) + { + unsigned idx; + WAIT_RING(chan, 14); + + /* remove last instruction bit */ + if(vp->clip_nr >= 0) + { + idx = vp->nr_insns - 7 + vp->clip_nr; + OUT_RING(chan, RING_3D(NV30_3D_VP_UPLOAD_FROM_ID, 1)); + OUT_RING(chan, vp->exec->start + idx); + OUT_RING(chan, RING_3D(NV30_3D_VP_UPLOAD_INST(0), 4)); + OUT_RINGp (chan, vp->insns[idx].data, 4); + } + + /* set last instruction bit */ + idx = vp->nr_insns - 7 + nvfx->clip.nr; + OUT_RING(chan, RING_3D(NV30_3D_VP_UPLOAD_FROM_ID, 1)); + OUT_RING(chan, vp->exec->start + idx); + OUT_RING(chan, RING_3D(NV30_3D_VP_UPLOAD_INST(0), 4)); + OUT_RINGp(chan, vp->insns[idx].data, 3); + OUT_RING(chan, vp->insns[idx].data[3] | 1); + vp->clip_nr = nvfx->clip.nr; + } + + // TODO: only do this for the ones changed + WAIT_RING(chan, 6 * 6); + for(i = 0; i < nvfx->clip.nr; ++i) + { + OUT_RING(chan, RING_3D(NV30_3D_VP_UPLOAD_CONST_ID, 5)); + OUT_RING(chan, vp->data->start + i); + OUT_RINGp (chan, nvfx->clip.ucp[i], 4); + } +} + +static boolean +nvfx_state_validate_common(struct nvfx_context *nvfx) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + unsigned dirty; + unsigned still_dirty = 0; + int new_fb_mode = -1; /* 1 = all swizzled, 0 = make all linear */ + boolean flush_tex_cache = FALSE; + unsigned render_temps; + + if(nvfx != nvfx->screen->cur_ctx) + { + nvfx->dirty = ~0; + nvfx->hw_vtxelt_nr = 16; + nvfx->hw_pointsprite_control = -1; + nvfx->hw_vp_output = -1; + nvfx->screen->cur_ctx = nvfx; + nvfx->relocs_needed = NVFX_RELOCATE_ALL; + } + + /* These can trigger use the of 3D engine to copy temporaries. + * That will recurse here and thus dirty all 3D state, so we need to this before anything else, and in a loop.. + * This converges to having clean temps, then binding both fragtexes and framebuffers. + */ + while(nvfx->dirty & (NVFX_NEW_FB | NVFX_NEW_SAMPLER)) + { + if(nvfx->dirty & NVFX_NEW_SAMPLER) + { + nvfx->dirty &=~ NVFX_NEW_SAMPLER; + nvfx_fragtex_validate(nvfx); + + // TODO: only set this if really necessary + flush_tex_cache = TRUE; + } + + if(nvfx->dirty & NVFX_NEW_FB) + { + nvfx->dirty &=~ NVFX_NEW_FB; + new_fb_mode = nvfx_framebuffer_prepare(nvfx); + + // TODO: make sure this doesn't happen, i.e. fbs have matching formats + assert(new_fb_mode >= 0); + } + } + + dirty = nvfx->dirty; + + if(nvfx->render_mode == HW) + { + if(dirty & (NVFX_NEW_VERTPROG | NVFX_NEW_VERTCONST)) + { + if(!nvfx_vertprog_validate(nvfx)) + return FALSE; + } + + if(dirty & NVFX_NEW_ARRAYS) + { + if(!nvfx_vbo_validate(nvfx)) + return FALSE; + } + + if(dirty & NVFX_NEW_INDEX) + { + if(nvfx->use_index_buffer) + nvfx_idxbuf_validate(nvfx); + else + still_dirty = NVFX_NEW_INDEX; + } + } + else + { + if(dirty & NVFX_NEW_VERTPROG) { + assert(nvfx_vertprog_validate(nvfx)); + nvfx_vbo_swtnl_validate(nvfx); + } + } + + if(dirty & NVFX_NEW_RAST) + sb_emit(chan, nvfx->rasterizer->sb, nvfx->rasterizer->sb_len); + + if(dirty & NVFX_NEW_SCISSOR) + nvfx_state_scissor_validate(nvfx); + + if(dirty & NVFX_NEW_STIPPLE) + nvfx_state_stipple_validate(nvfx); + + if(nvfx->dirty & NVFX_NEW_UCP) + nvfx_ucp_validate(nvfx); + + if(nvfx->use_vp_clipping && (nvfx->dirty & (NVFX_NEW_UCP | NVFX_NEW_VERTPROG))) + nvfx_vertprog_ucp_validate(nvfx); + + if(dirty & (NVFX_NEW_FRAGPROG | NVFX_NEW_FRAGCONST | NVFX_NEW_VERTPROG | NVFX_NEW_SPRITE)) + { + nvfx_fragprog_validate(nvfx); + if(dirty & NVFX_NEW_FRAGPROG) + flush_tex_cache = TRUE; // TODO: do we need this? + } + + if(nvfx->is_nv4x) + { + unsigned vp_output = nvfx->hw_vertprog->or | nvfx->hw_fragprog->or; + vp_output |= (1 << (nvfx->clip.nr + 6)) - (1 << 6); + + if(vp_output != nvfx->hw_vp_output) + { + WAIT_RING(chan, 2); + OUT_RING(chan, RING_3D(NV40_3D_VP_RESULT_EN, 1)); + OUT_RING(chan, vp_output); + nvfx->hw_vp_output = vp_output; + } + } + + if(new_fb_mode >= 0) + nvfx_framebuffer_validate(nvfx, new_fb_mode); + + if(dirty & NVFX_NEW_BLEND) + sb_emit(chan, nvfx->blend->sb, nvfx->blend->sb_len); + + if(dirty & NVFX_NEW_BCOL) + nvfx_state_blend_colour_validate(nvfx); + + if(dirty & NVFX_NEW_ZSA) + sb_emit(chan, nvfx->zsa->sb, nvfx->zsa->sb_len); + + if(dirty & NVFX_NEW_SR) + nvfx_state_sr_validate(nvfx); + +/* All these dependencies are wrong, but otherwise + etracer, neverball, foobillard, glest totally misrender + TODO: find the right fix +*/ + if(dirty & (NVFX_NEW_VIEWPORT | NVFX_NEW_RAST | NVFX_NEW_ZSA) || (new_fb_mode >= 0)) + { + nvfx_state_viewport_validate(nvfx); + } + + if(dirty & NVFX_NEW_ZSA || (new_fb_mode >= 0)) + { + WAIT_RING(chan, 3); + OUT_RING(chan, RING_3D(NV30_3D_DEPTH_WRITE_ENABLE, 2)); + OUT_RING(chan, nvfx->framebuffer.zsbuf && nvfx->zsa->pipe.depth.writemask); + OUT_RING(chan, nvfx->framebuffer.zsbuf && nvfx->zsa->pipe.depth.enabled); + } + + if((new_fb_mode >= 0) || (dirty & NVFX_NEW_FRAGPROG)) + nvfx_coord_conventions_validate(nvfx); + + if(flush_tex_cache) + { + // TODO: what about nv30? + if(nvfx->is_nv4x) + { + WAIT_RING(chan, 4); + OUT_RING(chan, RING_3D(NV40_3D_TEX_CACHE_CTL, 1)); + OUT_RING(chan, 2); + OUT_RING(chan, RING_3D(NV40_3D_TEX_CACHE_CTL, 1)); + OUT_RING(chan, 1); + } + } + + nvfx->dirty = dirty & still_dirty; + + render_temps = nvfx->state.render_temps; + if(render_temps) + { + for(int i = 0; i < nvfx->framebuffer.nr_cbufs; ++i) + { + if(render_temps & (1 << i)) { + assert(((struct nvfx_surface*)nvfx->framebuffer.cbufs[i])->temp); + util_dirty_surface_set_dirty(nvfx_surface_get_dirty_surfaces(nvfx->framebuffer.cbufs[i]), + (struct util_dirty_surface*)nvfx->framebuffer.cbufs[i]); + } + } + + if(render_temps & 0x80) { + assert(((struct nvfx_surface*)nvfx->framebuffer.zsbuf)->temp); + util_dirty_surface_set_dirty(nvfx_surface_get_dirty_surfaces(nvfx->framebuffer.zsbuf), + (struct util_dirty_surface*)nvfx->framebuffer.zsbuf); + } + } + + return TRUE; +} + +inline void +nvfx_state_relocate(struct nvfx_context *nvfx, unsigned relocs) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + /* we need to ensure there is enough space to output relocations in one go */ + const unsigned max_relocs = 0 + + 16 /* vertex buffers, incl. dma flag */ + + 2 /* index buffer plus format+dma flag */ + + 2 * 5 /* 4 cbufs + zsbuf, plus dma objects */ + + 2 * 16 /* fragment textures plus format+dma flag */ + + 2 * 4 /* vertex textures plus format+dma flag */ + + 1 /* fragprog incl dma flag */ + ; + + MARK_RING(chan, max_relocs * 2, max_relocs * 2); + + if(relocs & NVFX_RELOCATE_FRAMEBUFFER) + nvfx_framebuffer_relocate(nvfx); + if(relocs & NVFX_RELOCATE_FRAGTEX) + nvfx_fragtex_relocate(nvfx); + if(relocs & NVFX_RELOCATE_FRAGPROG) + nvfx_fragprog_relocate(nvfx); + if(relocs & NVFX_RELOCATE_VTXBUF) + nvfx_vbo_relocate(nvfx); + if(relocs & NVFX_RELOCATE_IDXBUF) + nvfx_idxbuf_relocate(nvfx); +} + +boolean +nvfx_state_validate(struct nvfx_context *nvfx) +{ + if (nvfx->render_mode != HW) { + /* Don't even bother trying to go back to hw if none + * of the states that caused swtnl previously have changed. + */ + if ((nvfx->fallback_swtnl & nvfx->dirty) + != nvfx->fallback_swtnl) + return FALSE; + + /* Attempt to go to hwtnl again */ + nvfx->dirty |= (NVFX_NEW_VIEWPORT | + NVFX_NEW_VERTPROG | + NVFX_NEW_ARRAYS); + nvfx->render_mode = HW; + } + + if(!nvfx_state_validate_common(nvfx)) + return FALSE; + + return TRUE; +} + +boolean +nvfx_state_validate_swtnl(struct nvfx_context *nvfx) +{ + struct draw_context *draw = nvfx->draw; + + /* Setup for swtnl */ + if (nvfx->render_mode == HW) { + static boolean warned = FALSE; + if(!warned) { + NOUVEAU_ERR("hw->swtnl 0x%08x\n", nvfx->fallback_swtnl); + warned = TRUE; + } + nvfx->pipe.flush(&nvfx->pipe, 0, NULL); + nvfx->dirty |= (NVFX_NEW_VIEWPORT | + NVFX_NEW_VERTPROG | + NVFX_NEW_ARRAYS); + nvfx->render_mode = SWTNL; + } + + if (nvfx->draw_dirty & NVFX_NEW_VERTPROG) { + if(!nvfx->vertprog->draw_vs) + nvfx->vertprog->draw_vs = draw_create_vertex_shader(draw, &nvfx->vertprog->pipe); + draw_bind_vertex_shader(draw, nvfx->vertprog->draw_vs); + } + + if (nvfx->draw_dirty & NVFX_NEW_RAST) + draw_set_rasterizer_state(draw, &nvfx->rasterizer->pipe, + nvfx->rasterizer); + + if (nvfx->draw_dirty & NVFX_NEW_UCP) + draw_set_clip_state(draw, &nvfx->clip); + + if (nvfx->draw_dirty & NVFX_NEW_VIEWPORT) + draw_set_viewport_state(draw, &nvfx->viewport); + + if (nvfx->draw_dirty & NVFX_NEW_ARRAYS) { + draw_set_vertex_buffers(draw, nvfx->vtxbuf_nr, nvfx->vtxbuf); + draw_set_vertex_elements(draw, nvfx->vtxelt->num_elements, nvfx->vtxelt->pipe); + } + + if (nvfx->draw_dirty & NVFX_NEW_INDEX) + draw_set_index_buffer(draw, &nvfx->idxbuf); + + nvfx_state_validate_common(nvfx); + + nvfx->draw_dirty = 0; + return TRUE; +} diff --git a/src/gallium/drivers/nvfx/nvfx_state_fb.c b/src/gallium/drivers/nvfx/nvfx_state_fb.c new file mode 100644 index 0000000..816bb89 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_state_fb.c @@ -0,0 +1,328 @@ +#include "nvfx_context.h" +#include "nvfx_resource.h" +#include "util/u_format.h" + +static inline boolean +nvfx_surface_linear_renderable(struct pipe_surface* surf) +{ + /* TODO: precompute this in nvfx_surface creation */ + return (surf->texture->flags & NVFX_RESOURCE_FLAG_LINEAR) + && !(((struct nvfx_surface*)surf)->offset & 63) + && !(((struct nvfx_surface*)surf)->pitch & 63); +} + +static inline boolean +nvfx_surface_swizzled_renderable(struct pipe_framebuffer_state* fb, struct pipe_surface* surf) +{ + /* TODO: precompute this in nvfx_surface creation */ + return !((struct nvfx_miptree*)surf->texture)->linear_pitch + && (surf->texture->target != PIPE_TEXTURE_3D || u_minify(surf->texture->depth0, surf->u.tex.level) <= 1) + && !(((struct nvfx_surface*)surf)->offset & 127) + && (surf->width == fb->width) + && (surf->height == fb->height) + && !((struct nvfx_surface*)surf)->temp + && (surf->format == PIPE_FORMAT_B8G8R8A8_UNORM || surf->format == PIPE_FORMAT_B8G8R8X8_UNORM || surf->format == PIPE_FORMAT_B5G6R5_UNORM); +} + +static boolean +nvfx_surface_get_render_target(struct pipe_surface* surf, int all_swizzled, struct nvfx_render_target* target) +{ + struct nvfx_surface* ns = (struct nvfx_surface*)surf; + if(!ns->temp) + { + target->bo = ((struct nvfx_miptree*)surf->texture)->base.bo; + target->offset = ns->offset; + target->pitch = align(ns->pitch, 64); + assert(target->pitch); + return FALSE; + } + else + { + target->offset = 0; + target->pitch = ns->temp->linear_pitch; + target->bo = ns->temp->base.bo; + assert(target->pitch); + return TRUE; + } +} + +int +nvfx_framebuffer_prepare(struct nvfx_context *nvfx) +{ + struct pipe_framebuffer_state *fb = &nvfx->framebuffer; + int i, color_format = 0, zeta_format = 0; + int all_swizzled = 1; + + if(!nvfx->is_nv4x) + assert(fb->nr_cbufs <= 1); + else + assert(fb->nr_cbufs <= 4); + + for (i = 0; i < fb->nr_cbufs; i++) { + if (color_format) { + if(color_format != fb->cbufs[i]->format) + return -1; + } else + color_format = fb->cbufs[i]->format; + + if(!nvfx_surface_swizzled_renderable(fb, fb->cbufs[i])) + all_swizzled = 0; + } + + if (fb->zsbuf) { + /* TODO: return FALSE if we have a format not supporting a depth buffer (e.g. r8); currently those are not supported at all */ + if(!nvfx_surface_swizzled_renderable(fb, fb->zsbuf)) + all_swizzled = 0; + + if(all_swizzled && util_format_get_blocksize(color_format) != util_format_get_blocksize(zeta_format)) + all_swizzled = 0; + } + + for (i = 0; i < fb->nr_cbufs; i++) { + if(!((struct nvfx_surface*)fb->cbufs[i])->temp && !all_swizzled && !nvfx_surface_linear_renderable(fb->cbufs[i])) + nvfx_surface_create_temp(&nvfx->pipe, fb->cbufs[i]); + } + + if(fb->zsbuf) { + if(!((struct nvfx_surface*)fb->zsbuf)->temp && !all_swizzled && !nvfx_surface_linear_renderable(fb->zsbuf)) + nvfx_surface_create_temp(&nvfx->pipe, fb->zsbuf); + } + + return all_swizzled; +} + +void +nvfx_framebuffer_validate(struct nvfx_context *nvfx, unsigned prepare_result) +{ + struct pipe_framebuffer_state *fb = &nvfx->framebuffer; + struct nouveau_channel *chan = nvfx->screen->base.channel; + uint32_t rt_enable, rt_format; + int i; + unsigned rt_flags = NOUVEAU_BO_RDWR | NOUVEAU_BO_VRAM; + unsigned w = fb->width; + unsigned h = fb->height; + + rt_enable = (NV30_3D_RT_ENABLE_COLOR0 << fb->nr_cbufs) - 1; + if (rt_enable & (NV30_3D_RT_ENABLE_COLOR1 | + NV40_3D_RT_ENABLE_COLOR2 | NV40_3D_RT_ENABLE_COLOR3)) + rt_enable |= NV30_3D_RT_ENABLE_MRT; + + nvfx->state.render_temps = 0; + + for (i = 0; i < fb->nr_cbufs; i++) + nvfx->state.render_temps |= nvfx_surface_get_render_target(fb->cbufs[i], prepare_result, &nvfx->hw_rt[i]) << i; + + for(; i < 4; ++i) + nvfx->hw_rt[i].bo = NULL; + + nvfx->hw_zeta.bo = NULL; + + if (fb->zsbuf) { + nvfx->state.render_temps |= nvfx_surface_get_render_target(fb->zsbuf, prepare_result, &nvfx->hw_zeta) << 7; + + assert(util_format_get_stride(fb->zsbuf->format, fb->width) <= nvfx->hw_zeta.pitch); + assert(nvfx->hw_zeta.offset + nvfx->hw_zeta.pitch * fb->height <= nvfx->hw_zeta.bo->size); + } + + if (prepare_result) { + assert(!(fb->width & (fb->width - 1)) && !(fb->height & (fb->height - 1))); + + rt_format = NV30_3D_RT_FORMAT_TYPE_SWIZZLED | + (util_logbase2(fb->width) << NV30_3D_RT_FORMAT_LOG2_WIDTH__SHIFT) | + (util_logbase2(fb->height) << NV30_3D_RT_FORMAT_LOG2_HEIGHT__SHIFT); + } else + rt_format = NV30_3D_RT_FORMAT_TYPE_LINEAR; + + if(fb->nr_cbufs > 0) { + switch (fb->cbufs[0]->format) { + case PIPE_FORMAT_B8G8R8X8_UNORM: + rt_format |= NV30_3D_RT_FORMAT_COLOR_X8R8G8B8; + break; + case PIPE_FORMAT_B8G8R8A8_UNORM: + case 0: + rt_format |= NV30_3D_RT_FORMAT_COLOR_A8R8G8B8; + break; + case PIPE_FORMAT_R8G8B8X8_UNORM: + rt_format |= NV30_3D_RT_FORMAT_COLOR_X8B8G8R8; + break; + case PIPE_FORMAT_R8G8B8A8_UNORM: + rt_format |= NV30_3D_RT_FORMAT_COLOR_A8B8G8R8; + break; + case PIPE_FORMAT_B5G6R5_UNORM: + rt_format |= NV30_3D_RT_FORMAT_COLOR_R5G6B5; + break; + case PIPE_FORMAT_R32G32B32A32_FLOAT: + rt_format |= NV30_3D_RT_FORMAT_COLOR_A32B32G32R32_FLOAT; + break; + case PIPE_FORMAT_R16G16B16A16_FLOAT: + rt_format |= NV30_3D_RT_FORMAT_COLOR_A16B16G16R16_FLOAT; + break; + default: + assert(0); + } + } else if(fb->zsbuf && util_format_get_blocksize(fb->zsbuf->format) == 2) + rt_format |= NV30_3D_RT_FORMAT_COLOR_R5G6B5; + else + rt_format |= NV30_3D_RT_FORMAT_COLOR_A8R8G8B8; + + if(fb->zsbuf) { + switch (fb->zsbuf->format) { + case PIPE_FORMAT_Z16_UNORM: + rt_format |= NV30_3D_RT_FORMAT_ZETA_Z16; + break; + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: + case 0: + rt_format |= NV30_3D_RT_FORMAT_ZETA_Z24S8; + break; + default: + assert(0); + } + } else if(fb->nr_cbufs && util_format_get_blocksize(fb->cbufs[0]->format) == 2) + rt_format |= NV30_3D_RT_FORMAT_ZETA_Z16; + else + rt_format |= NV30_3D_RT_FORMAT_ZETA_Z24S8; + + MARK_RING(chan, 42, 10); + + if ((rt_enable & NV30_3D_RT_ENABLE_COLOR0) || fb->zsbuf) { + struct nvfx_render_target *rt0 = &nvfx->hw_rt[0]; + uint32_t pitch; + + if(!(rt_enable & NV30_3D_RT_ENABLE_COLOR0)) + rt0 = &nvfx->hw_zeta; + + pitch = rt0->pitch; + + if(!nvfx->is_nv4x) + { + if (nvfx->hw_zeta.bo) + pitch |= (nvfx->hw_zeta.pitch << 16); + else + pitch |= (pitch << 16); + } + + //printf("rendering to bo %p [%i] at offset %i with pitch %i\n", rt0->bo, rt0->bo->handle, rt0->offset, pitch); + + OUT_RING(chan, RING_3D(NV30_3D_DMA_COLOR0, 1)); + OUT_RELOC(chan, rt0->bo, 0, + rt_flags | NOUVEAU_BO_OR, + chan->vram->handle, chan->gart->handle); + OUT_RING(chan, RING_3D(NV30_3D_COLOR0_PITCH, 2)); + OUT_RING(chan, pitch); + OUT_RELOC(chan, rt0->bo, + rt0->offset, rt_flags | NOUVEAU_BO_LOW, + 0, 0); + } + + if (rt_enable & NV30_3D_RT_ENABLE_COLOR1) { + OUT_RING(chan, RING_3D(NV30_3D_DMA_COLOR1, 1)); + OUT_RELOC(chan, nvfx->hw_rt[1].bo, 0, + rt_flags | NOUVEAU_BO_OR, + chan->vram->handle, chan->gart->handle); + OUT_RING(chan, RING_3D(NV30_3D_COLOR1_OFFSET, 2)); + OUT_RELOC(chan, nvfx->hw_rt[1].bo, + nvfx->hw_rt[1].offset, rt_flags | NOUVEAU_BO_LOW, + 0, 0); + OUT_RING(chan, nvfx->hw_rt[1].pitch); + } + + if(nvfx->is_nv4x) + { + if (rt_enable & NV40_3D_RT_ENABLE_COLOR2) { + OUT_RING(chan, RING_3D(NV40_3D_DMA_COLOR2, 1)); + OUT_RELOC(chan, nvfx->hw_rt[2].bo, 0, + rt_flags | NOUVEAU_BO_OR, + chan->vram->handle, chan->gart->handle); + OUT_RING(chan, RING_3D(NV40_3D_COLOR2_OFFSET, 1)); + OUT_RELOC(chan, nvfx->hw_rt[2].bo, + nvfx->hw_rt[2].offset, rt_flags | NOUVEAU_BO_LOW, + 0, 0); + OUT_RING(chan, RING_3D(NV40_3D_COLOR2_PITCH, 1)); + OUT_RING(chan, nvfx->hw_rt[2].pitch); + } + + if (rt_enable & NV40_3D_RT_ENABLE_COLOR3) { + OUT_RING(chan, RING_3D(NV40_3D_DMA_COLOR3, 1)); + OUT_RELOC(chan, nvfx->hw_rt[3].bo, 0, + rt_flags | NOUVEAU_BO_OR, + chan->vram->handle, chan->gart->handle); + OUT_RING(chan, RING_3D(NV40_3D_COLOR3_OFFSET, 1)); + OUT_RELOC(chan, nvfx->hw_rt[3].bo, + nvfx->hw_rt[3].offset, rt_flags | NOUVEAU_BO_LOW, + 0, 0); + OUT_RING(chan, RING_3D(NV40_3D_COLOR3_PITCH, 1)); + OUT_RING(chan, nvfx->hw_rt[3].pitch); + } + } + + if (fb->zsbuf) { + OUT_RING(chan, RING_3D(NV30_3D_DMA_ZETA, 1)); + OUT_RELOC(chan, nvfx->hw_zeta.bo, 0, + rt_flags | NOUVEAU_BO_OR, + chan->vram->handle, chan->gart->handle); + OUT_RING(chan, RING_3D(NV30_3D_ZETA_OFFSET, 1)); + /* TODO: reverse engineer LMA */ + OUT_RELOC(chan, nvfx->hw_zeta.bo, + nvfx->hw_zeta.offset, rt_flags | NOUVEAU_BO_LOW, 0, 0); + if(nvfx->is_nv4x) { + OUT_RING(chan, RING_3D(NV40_3D_ZETA_PITCH, 1)); + OUT_RING(chan, nvfx->hw_zeta.pitch); + } + } + else if(nvfx->is_nv4x) { + OUT_RING(chan, RING_3D(NV40_3D_ZETA_PITCH, 1)); + OUT_RING(chan, 64); + } + + OUT_RING(chan, RING_3D(NV30_3D_RT_ENABLE, 1)); + OUT_RING(chan, rt_enable); + OUT_RING(chan, RING_3D(NV30_3D_RT_HORIZ, 3)); + OUT_RING(chan, (w << 16) | 0); + OUT_RING(chan, (h << 16) | 0); + OUT_RING(chan, rt_format); + OUT_RING(chan, RING_3D(NV30_3D_VIEWPORT_HORIZ, 2)); + OUT_RING(chan, (w << 16) | 0); + OUT_RING(chan, (h << 16) | 0); + OUT_RING(chan, RING_3D(NV30_3D_VIEWPORT_CLIP_HORIZ(0), 2)); + OUT_RING(chan, ((w - 1) << 16) | 0); + OUT_RING(chan, ((h - 1) << 16) | 0); + + if(!nvfx->is_nv4x) { + /* Wonder why this is needed, context should all be set to zero on init */ + /* TODO: we can most likely remove this, after putting it in context init */ + OUT_RING(chan, RING_3D(NV30_3D_VIEWPORT_TX_ORIGIN, 1)); + OUT_RING(chan, 0); + } + nvfx->relocs_needed &=~ NVFX_RELOCATE_FRAMEBUFFER; +} + +void +nvfx_framebuffer_relocate(struct nvfx_context *nvfx) +{ + struct nouveau_channel *chan = nvfx->screen->base.channel; + unsigned rt_flags = NOUVEAU_BO_RDWR | NOUVEAU_BO_VRAM; + rt_flags |= NOUVEAU_BO_DUMMY; + MARK_RING(chan, 20, 20); + +#define DO_(var, pfx, name) \ + if(var.bo) { \ + OUT_RELOC(chan, var.bo, RING_3D(pfx##_3D_DMA_##name, 1), rt_flags, 0, 0); \ + OUT_RELOC(chan, var.bo, 0, \ + rt_flags | NOUVEAU_BO_OR, \ + chan->vram->handle, chan->gart->handle); \ + OUT_RELOC(chan, var.bo, RING_3D(pfx##_3D_##name##_OFFSET, 1), rt_flags, 0, 0); \ + OUT_RELOC(chan, var.bo, \ + var.offset, rt_flags | NOUVEAU_BO_LOW, \ + 0, 0); \ + } + +#define DO(pfx, num) DO_(nvfx->hw_rt[num], pfx, COLOR##num) + DO(NV30, 0); + DO(NV30, 1); + DO(NV40, 2); + DO(NV40, 3); + + DO_(nvfx->hw_zeta, NV30, ZETA); + nvfx->relocs_needed &=~ NVFX_RELOCATE_FRAMEBUFFER; +} diff --git a/src/gallium/drivers/nvfx/nvfx_surface.c b/src/gallium/drivers/nvfx/nvfx_surface.c new file mode 100644 index 0000000..6fd6c47 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_surface.c @@ -0,0 +1,516 @@ + +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + +#include "pipe/p_context.h" +#include "pipe/p_format.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_pack_color.h" +#include "util/u_blitter.h" + +#include "nouveau/nouveau_winsys.h" +#include "nouveau/nouveau_screen.h" +#include "nvfx_context.h" +#include "nvfx_screen.h" +#include "nvfx_resource.h" +#include "nv04_2d.h" + +#include + +static INLINE void +nvfx_region_set_format(struct nv04_region* rgn, enum pipe_format format) +{ + unsigned bits = util_format_get_blocksizebits(format); + unsigned shift = 0; + rgn->one_bits = 0; + + switch(bits) + { + case 8: + rgn->bpps = 0; + break; + case 16: + rgn->bpps = 1; + if(format == PIPE_FORMAT_B5G5R5X1_UNORM) + rgn->one_bits = 1; + break; + case 32: + rgn->bpps = 2; + if(format == PIPE_FORMAT_R8G8B8X8_UNORM || format == PIPE_FORMAT_B8G8R8X8_UNORM) + rgn->one_bits = 8; + break; + case 64: + rgn->bpps = 2; + shift = 1; + break; + case 128: + rgn->bpps = 2; + shift = 2; + break; + } + + if(shift) { + rgn->x = util_format_get_nblocksx(format, rgn->x) << shift; + rgn->y = util_format_get_nblocksy(format, rgn->y); + rgn->w <<= shift; + } +} + +static INLINE void +nvfx_region_init_for_surface(struct nv04_region* rgn, struct nvfx_surface* surf, unsigned x, unsigned y, bool for_write) +{ + rgn->x = x; + rgn->y = y; + rgn->z = 0; + + if(surf->temp) + { + rgn->bo = surf->temp->base.bo; + rgn->offset = 0; + rgn->pitch = surf->temp->linear_pitch; + + if(for_write) + util_dirty_surface_set_dirty(nvfx_surface_get_dirty_surfaces(&surf->base.base), &surf->base); + } else { + rgn->bo = ((struct nvfx_resource*)surf->base.base.texture)->bo; + rgn->offset = surf->offset; + + if(surf->base.base.texture->flags & NVFX_RESOURCE_FLAG_LINEAR) + rgn->pitch = surf->pitch; + else + { + rgn->pitch = 0; + rgn->z = surf->base.base.u.tex.first_layer; + rgn->w = surf->base.base.width; + rgn->h = surf->base.base.height; + rgn->d = u_minify(surf->base.base.texture->depth0, surf->base.base.u.tex.level); + } + } + + nvfx_region_set_format(rgn, surf->base.base.format); + if(!rgn->pitch) + nv04_region_try_to_linearize(rgn); +} + +static INLINE void +nvfx_region_init_for_subresource(struct nv04_region* rgn, struct pipe_resource* pt, unsigned level, unsigned x, unsigned y, unsigned z, bool for_write) +{ + if(pt->target != PIPE_BUFFER) + { + struct nvfx_surface* ns = (struct nvfx_surface*)util_surfaces_peek(&((struct nvfx_miptree*)pt)->surfaces, pt, level, z); + if(ns && util_dirty_surface_is_dirty(&ns->base)) + { + nvfx_region_init_for_surface(rgn, ns, x, y, for_write); + return; + } + } + + rgn->bo = ((struct nvfx_resource*)pt)->bo; + rgn->offset = nvfx_subresource_offset(pt, z, level, z); + rgn->x = x; + rgn->y = y; + + if(pt->flags & NVFX_RESOURCE_FLAG_LINEAR) + { + rgn->pitch = nvfx_subresource_pitch(pt, level); + rgn->z = 0; + } + else + { + rgn->pitch = 0; + rgn->z = z; + rgn->w = u_minify(pt->width0, level); + rgn->h = u_minify(pt->height0, level); + rgn->d = u_minify(pt->depth0, level); + } + + nvfx_region_set_format(rgn, pt->format); + if(!rgn->pitch) + nv04_region_try_to_linearize(rgn); +} + +// don't save index buffer because blitter doesn't setit +static struct blitter_context* +nvfx_get_blitter(struct pipe_context* pipe, int copy) +{ + struct nvfx_context* nvfx = nvfx_context(pipe); + struct blitter_context** pblitter; + struct blitter_context* blitter; + + assert(nvfx->blitters_in_use < Elements(nvfx->blitter)); + + if(nvfx->query && !nvfx->blitters_in_use) + { + struct nouveau_channel* chan = nvfx->screen->base.channel; + WAIT_RING(chan, 2); + OUT_RING(chan, RING_3D(NV30_3D_QUERY_ENABLE, 1)); + OUT_RING(chan, 0); + } + + pblitter = &nvfx->blitter[nvfx->blitters_in_use++]; + if(!*pblitter) + *pblitter = util_blitter_create(pipe); + blitter = *pblitter; + + util_blitter_save_blend(blitter, nvfx->blend); + util_blitter_save_depth_stencil_alpha(blitter, nvfx->zsa); + util_blitter_save_stencil_ref(blitter, &nvfx->stencil_ref); + util_blitter_save_rasterizer(blitter, nvfx->rasterizer); + util_blitter_save_fragment_shader(blitter, nvfx->fragprog); + util_blitter_save_vertex_shader(blitter, nvfx->vertprog); + util_blitter_save_viewport(blitter, &nvfx->viewport); + util_blitter_save_framebuffer(blitter, &nvfx->framebuffer); + util_blitter_save_clip(blitter, &nvfx->clip); + util_blitter_save_vertex_elements(blitter, nvfx->vtxelt); + util_blitter_save_vertex_buffers(blitter, nvfx->vtxbuf_nr, nvfx->vtxbuf); + + if(copy) + { + util_blitter_save_fragment_sampler_states(blitter, nvfx->nr_samplers, (void**)nvfx->tex_sampler); + util_blitter_save_fragment_sampler_views(blitter, nvfx->nr_textures, nvfx->fragment_sampler_views); + } + + return blitter; +} + +static inline void +nvfx_put_blitter(struct pipe_context* pipe, struct blitter_context* blitter) +{ + struct nvfx_context* nvfx = nvfx_context(pipe); + --nvfx->blitters_in_use; + assert(nvfx->blitters_in_use >= 0); + + if(nvfx->query && !nvfx->blitters_in_use) + { + struct nouveau_channel* chan = nvfx->screen->base.channel; + WAIT_RING(chan, 2); + OUT_RING(chan, RING_3D(NV30_3D_QUERY_ENABLE, 1)); + OUT_RING(chan, 1); + } +} + +static unsigned +nvfx_region_clone(struct nv04_2d_context* ctx, struct nv04_region* rgn, unsigned w, unsigned h, boolean for_read) +{ + unsigned begin = nv04_region_begin(rgn, w, h); + unsigned end = nv04_region_end(rgn, w, h); + unsigned size = end - begin; + struct nouveau_bo* bo = 0; + nouveau_bo_new(rgn->bo->device, NOUVEAU_BO_MAP | NOUVEAU_BO_GART, 256, size, &bo); + + if(for_read || (size > ((w * h) << rgn->bpps))) + nv04_memcpy(ctx, bo, 0, rgn->bo, rgn->offset + begin, size); + + rgn->bo = bo; + rgn->offset = -begin; + return begin; +} + +static void +nvfx_resource_copy_region(struct pipe_context *pipe, + struct pipe_resource *dstr, unsigned dst_level, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource *srcr, unsigned src_level, + const struct pipe_box *src_box) +{ + static int copy_threshold = -1; + struct nv04_2d_context *ctx = nvfx_screen(pipe->screen)->eng2d; + struct nv04_region dst, src; + int dst_to_gpu; + int src_on_gpu; + boolean small; + int ret; + unsigned w = src_box->width; + unsigned h = src_box->height; + + if(!w || !h) + return; + + if(copy_threshold < 0) + copy_threshold = debug_get_num_option("NOUVEAU_COPY_THRESHOLD", 4); + + dst_to_gpu = dstr->usage != PIPE_USAGE_DYNAMIC && dstr->usage != PIPE_USAGE_STAGING; + src_on_gpu = nvfx_resource_on_gpu(srcr); + + nvfx_region_init_for_subresource(&dst, dstr, dst_level, dstx, dsty, dstz, TRUE); + nvfx_region_init_for_subresource(&src, srcr, src_level, src_box->x, src_box->y, src_box->z, FALSE); + w = util_format_get_stride(dstr->format, w) >> dst.bpps; + h = util_format_get_nblocksy(dstr->format, h); + + small = (w * h <= copy_threshold); + if((!dst_to_gpu || !src_on_gpu) && small) + ret = -1; /* use the CPU */ + else + ret = nv04_region_copy_2d(ctx, &dst, &src, w, h, dst_to_gpu, src_on_gpu); + if(!ret) + {} + else if(ret > 0 + && dstr->bind & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL) + && srcr->bind & PIPE_BIND_SAMPLER_VIEW) + { + /* this currently works because we hack the bind flags on resource creation to be + * the maximum set that the resource type actually supports + * + * TODO: perhaps support reinterpreting the formats + */ + struct blitter_context* blitter = nvfx_get_blitter(pipe, 1); + util_blitter_copy_region(blitter, dstr, dst_level, dstx, dsty, dstz, srcr, src_level, src_box, TRUE); + nvfx_put_blitter(pipe, blitter); + } + else + { + struct nv04_region dstt = dst; + struct nv04_region srct = src; + unsigned dstbegin = 0; + + if(!small) + { + if(src_on_gpu) + nvfx_region_clone(ctx, &srct, w, h, TRUE); + + if(dst_to_gpu) + dstbegin = nvfx_region_clone(ctx, &dstt, w, h, FALSE); + } + + nv04_region_copy_cpu(&dstt, &srct, w, h); + + if(srct.bo != src.bo) + nouveau_screen_bo_release(pipe->screen, srct.bo); + + if(dstt.bo != dst.bo) + { + nv04_memcpy(ctx, dst.bo, dst.offset + dstbegin, dstt.bo, 0, dstt.bo->size); + nouveau_screen_bo_release(pipe->screen, dstt.bo); + } + } +} + +static int +nvfx_surface_fill(struct pipe_context* pipe, struct pipe_surface *dsts, + unsigned dx, unsigned dy, unsigned w, unsigned h, unsigned value) +{ + struct nv04_2d_context *ctx = nvfx_screen(pipe->screen)->eng2d; + struct nv04_region dst; + int ret; + /* Always try to use the GPU right now, if possible + * If the user wanted the surface data on the CPU, he would have cleared with memset (hopefully) */ + + // we don't care about interior pixel order since we set all them to the same value + nvfx_region_init_for_surface(&dst, (struct nvfx_surface*)dsts, dx, dy, TRUE); + + w = util_format_get_stride(dsts->format, w) >> dst.bpps; + h = util_format_get_nblocksy(dsts->format, h); + + ret = nv04_region_fill_2d(ctx, &dst, w, h, value); + if(ret > 0 && dsts->texture->bind & PIPE_BIND_RENDER_TARGET) + return 1; + else if(ret) + { + struct nv04_region dstt = dst; + unsigned dstbegin = 0; + + if(nvfx_resource_on_gpu(dsts->texture)) + dstbegin = nvfx_region_clone(ctx, &dstt, w, h, FALSE); + + nv04_region_fill_cpu(&dstt, w, h, value); + + if(dstt.bo != dst.bo) + { + nv04_memcpy(ctx, dst.bo, dst.offset + dstbegin, dstt.bo, 0, dstt.bo->size); + nouveau_screen_bo_release(pipe->screen, dstt.bo); + } + } + + return 0; +} + + +void +nvfx_screen_surface_takedown(struct pipe_screen *pscreen) +{ + nv04_2d_context_takedown(nvfx_screen(pscreen)->eng2d); + nvfx_screen(pscreen)->eng2d = 0; +} + +int +nvfx_screen_surface_init(struct pipe_screen *pscreen) +{ + struct nv04_2d_context* ctx = nv04_2d_context_init(nouveau_screen(pscreen)->channel); + if(!ctx) + return -1; + nvfx_screen(pscreen)->eng2d = ctx; + return 0; +} + +static void +nvfx_surface_copy_temp(struct pipe_context* pipe, struct pipe_surface* surf, int to_temp) +{ + struct nvfx_surface* ns = (struct nvfx_surface*)surf; + struct pipe_box box; + struct nvfx_context* nvfx = nvfx_context(pipe); + struct nvfx_miptree* temp; + unsigned use_vertex_buffers; + boolean use_index_buffer; + unsigned base_vertex; + + /* temporarily detach the temp, so it isn't used in place of the actual resource */ + temp = ns->temp; + ns->temp = 0; + + // TODO: we really should do this validation before setting these variable in draw calls + use_vertex_buffers = nvfx->use_vertex_buffers; + use_index_buffer = nvfx->use_index_buffer; + base_vertex = nvfx->base_vertex; + + box.x = box.y = 0; + assert(surf->u.tex.first_layer == surf->u.tex.last_layer); + box.width = surf->width; + box.height = surf->height; + box.depth = 1; + + if(to_temp) { + box.z = surf->u.tex.first_layer; + nvfx_resource_copy_region(pipe, &temp->base.base, 0, 0, 0, 0, surf->texture, surf->u.tex.level, &box); + } + else { + box.z = 0; + nvfx_resource_copy_region(pipe, surf->texture, surf->u.tex.level, 0, 0, surf->u.tex.first_layer, &temp->base.base, 0, &box); + } + + /* If this triggers, it probably means we attempted to use the blitter + * but failed due to non-renderability of the target. + * Obviously, this would lead to infinite recursion if supported. */ + assert(!ns->temp); + + ns->temp = temp; + + nvfx->use_vertex_buffers = use_vertex_buffers; + nvfx->use_index_buffer = use_index_buffer; + nvfx->base_vertex = base_vertex; + + nvfx->dirty |= NVFX_NEW_ARRAYS; + nvfx->draw_dirty |= NVFX_NEW_ARRAYS; +} + +void +nvfx_surface_create_temp(struct pipe_context* pipe, struct pipe_surface* surf) +{ + struct nvfx_surface* ns = (struct nvfx_surface*)surf; + struct pipe_resource template; + memset(&template, 0, sizeof(struct pipe_resource)); + template.target = PIPE_TEXTURE_2D; + template.format = surf->format; + template.width0 = surf->width; + template.height0 = surf->height; + template.depth0 = 1; + template.nr_samples = surf->texture->nr_samples; + template.flags = NVFX_RESOURCE_FLAG_LINEAR; + + assert(!ns->temp && !util_dirty_surface_is_dirty(&ns->base)); + + ns->temp = (struct nvfx_miptree*)nvfx_miptree_create(pipe->screen, &template); + nvfx_surface_copy_temp(pipe, surf, 1); +} + +void +nvfx_surface_flush(struct pipe_context* pipe, struct pipe_surface* surf) +{ + struct nvfx_context* nvfx = (struct nvfx_context*)pipe; + struct nvfx_surface* ns = (struct nvfx_surface*)surf; + boolean bound = FALSE; + + nvfx_surface_copy_temp(pipe, surf, 0); + + util_dirty_surface_set_clean(nvfx_surface_get_dirty_surfaces(surf), &ns->base); + + if(nvfx->framebuffer.zsbuf == surf) + bound = TRUE; + else + { + for(unsigned i = 0; i < nvfx->framebuffer.nr_cbufs; ++i) + { + if(nvfx->framebuffer.cbufs[i] == surf) + { + bound = TRUE; + break; + } + } + } + + if(!bound) + pipe_resource_reference((struct pipe_resource**)&ns->temp, 0); +} + +static void +nvfx_clear_render_target(struct pipe_context *pipe, + struct pipe_surface *dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + union util_color uc; + util_pack_color(rgba, dst->format, &uc); + + if(util_format_get_blocksizebits(dst->format) > 32 + || nvfx_surface_fill(pipe, dst, dstx, dsty, width, height, uc.ui)) + { + // TODO: probably should use hardware clear here instead if possible + struct blitter_context* blitter = nvfx_get_blitter(pipe, 0); + util_blitter_clear_render_target(blitter, dst, rgba, dstx, dsty, width, height); + nvfx_put_blitter(pipe, blitter); + } +} + +static void +nvfx_clear_depth_stencil(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + if(util_format_get_blocksizebits(dst->format) > 32 + || nvfx_surface_fill(pipe, dst, dstx, dsty, width, height, util_pack_z_stencil(dst->format, depth, stencil))) + { + // TODO: probably should use hardware clear here instead if possible + struct blitter_context* blitter = nvfx_get_blitter(pipe, 0); + util_blitter_clear_depth_stencil(blitter, dst, clear_flags, depth, stencil, dstx, dsty, width, height); + nvfx_put_blitter(pipe, blitter); + } +} + + +void +nvfx_init_surface_functions(struct nvfx_context *nvfx) +{ + nvfx->pipe.resource_copy_region = nvfx_resource_copy_region; + nvfx->pipe.clear_render_target = nvfx_clear_render_target; + nvfx->pipe.clear_depth_stencil = nvfx_clear_depth_stencil; +} diff --git a/src/gallium/drivers/nvfx/nvfx_surface.h b/src/gallium/drivers/nvfx/nvfx_surface.h new file mode 100644 index 0000000..e69de29 diff --git a/src/gallium/drivers/nvfx/nvfx_tex.h b/src/gallium/drivers/nvfx/nvfx_tex.h new file mode 100644 index 0000000..2f2d737 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_tex.h @@ -0,0 +1,175 @@ +#ifndef NVFX_TEX_H_ +#define NVFX_TEX_H_ + +#include "util/u_math.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" + + +static inline unsigned +nvfx_tex_wrap_mode(unsigned wrap) { + unsigned ret; + + switch (wrap) { + case PIPE_TEX_WRAP_REPEAT: + ret = NV30_3D_TEX_WRAP_S_REPEAT; + break; + case PIPE_TEX_WRAP_MIRROR_REPEAT: + ret = NV30_3D_TEX_WRAP_S_MIRRORED_REPEAT; + break; + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + ret = NV30_3D_TEX_WRAP_S_CLAMP_TO_EDGE; + break; + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + ret = NV30_3D_TEX_WRAP_S_CLAMP_TO_BORDER; + break; + case PIPE_TEX_WRAP_CLAMP: + ret = NV30_3D_TEX_WRAP_S_CLAMP; + break; + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + ret = NV40_3D_TEX_WRAP_S_MIRROR_CLAMP_TO_EDGE; + break; + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + ret = NV40_3D_TEX_WRAP_S_MIRROR_CLAMP_TO_BORDER; + break; + case PIPE_TEX_WRAP_MIRROR_CLAMP: + ret = NV40_3D_TEX_WRAP_S_MIRROR_CLAMP; + break; + default: + assert(0); + ret = NV30_3D_TEX_WRAP_S_REPEAT; + break; + } + + return ret >> NV30_3D_TEX_WRAP_S__SHIFT; +} + +static inline unsigned +nvfx_tex_wrap_compare_mode(unsigned func) +{ + switch (func) { + case PIPE_FUNC_NEVER: + return NV30_3D_TEX_WRAP_RCOMP_NEVER; + case PIPE_FUNC_GREATER: + return NV30_3D_TEX_WRAP_RCOMP_GREATER; + case PIPE_FUNC_EQUAL: + return NV30_3D_TEX_WRAP_RCOMP_EQUAL; + case PIPE_FUNC_GEQUAL: + return NV30_3D_TEX_WRAP_RCOMP_GEQUAL; + case PIPE_FUNC_LESS: + return NV30_3D_TEX_WRAP_RCOMP_LESS; + case PIPE_FUNC_NOTEQUAL: + return NV30_3D_TEX_WRAP_RCOMP_NOTEQUAL; + case PIPE_FUNC_LEQUAL: + return NV30_3D_TEX_WRAP_RCOMP_LEQUAL; + case PIPE_FUNC_ALWAYS: + return NV30_3D_TEX_WRAP_RCOMP_ALWAYS; + default: + assert(0); + return 0; + } +} + +static inline unsigned nvfx_tex_filter(const struct pipe_sampler_state* cso) +{ + unsigned filter = 0; + switch (cso->mag_img_filter) { + case PIPE_TEX_FILTER_LINEAR: + filter |= NV30_3D_TEX_FILTER_MAG_LINEAR; + break; + case PIPE_TEX_FILTER_NEAREST: + default: + filter |= NV30_3D_TEX_FILTER_MAG_NEAREST; + break; + } + + switch (cso->min_img_filter) { + case PIPE_TEX_FILTER_LINEAR: + switch (cso->min_mip_filter) { + case PIPE_TEX_MIPFILTER_NEAREST: + filter |= NV30_3D_TEX_FILTER_MIN_LINEAR_MIPMAP_NEAREST; + break; + case PIPE_TEX_MIPFILTER_LINEAR: + filter |= NV30_3D_TEX_FILTER_MIN_LINEAR_MIPMAP_LINEAR; + break; + case PIPE_TEX_MIPFILTER_NONE: + default: + filter |= NV30_3D_TEX_FILTER_MIN_LINEAR; + break; + } + break; + case PIPE_TEX_FILTER_NEAREST: + default: + switch (cso->min_mip_filter) { + case PIPE_TEX_MIPFILTER_NEAREST: + filter |= NV30_3D_TEX_FILTER_MIN_NEAREST_MIPMAP_NEAREST; + break; + case PIPE_TEX_MIPFILTER_LINEAR: + filter |= NV30_3D_TEX_FILTER_MIN_NEAREST_MIPMAP_LINEAR; + break; + case PIPE_TEX_MIPFILTER_NONE: + default: + filter |= NV30_3D_TEX_FILTER_MIN_NEAREST; + break; + } + break; + } + return filter; +} + +static inline unsigned nvfx_tex_border_color(const float* border_color) +{ + return ((float_to_ubyte(border_color[3]) << 24) | + (float_to_ubyte(border_color[0]) << 16) | + (float_to_ubyte(border_color[1]) << 8) | + (float_to_ubyte(border_color[2]) << 0)); +} + +struct nvfx_sampler_state { + uint32_t fmt; + uint32_t wrap; + uint32_t en; + uint32_t filt; + uint32_t bcol; + uint32_t min_lod; + uint32_t max_lod; + boolean compare; +}; + +struct nvfx_sampler_view { + struct pipe_sampler_view base; + int offset; + uint32_t swizzle; + uint32_t npot_size; + uint32_t filt; + uint32_t wrap_mask; + uint32_t wrap; + uint32_t lod_offset; + uint32_t max_lod_limit; + union + { + struct + { + uint32_t fmt[4]; /* nv30 has 4 entries, nv40 one */ + int rect; + } nv30; + struct + { + uint32_t fmt[2]; /* nv30 has 4 entries, nv40 one */ + uint32_t npot_size2; /* nv40 only */ + } nv40; + uint32_t init_fmt; + } u; +}; + +struct nvfx_texture_format { + int fmt[6]; + unsigned sign; + unsigned wrap; + unsigned char src[6]; + unsigned char comp[6]; +}; + +extern struct nvfx_texture_format nvfx_texture_formats[PIPE_FORMAT_COUNT]; + +#endif /* NVFX_TEX_H_ */ diff --git a/src/gallium/drivers/nvfx/nvfx_transfer.c b/src/gallium/drivers/nvfx/nvfx_transfer.c new file mode 100644 index 0000000..2debcb6 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_transfer.c @@ -0,0 +1,221 @@ +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_staging.h" +#include "nvfx_context.h" +#include "nvfx_screen.h" +#include "nvfx_state.h" +#include "nvfx_resource.h" +#include "nvfx_transfer.h" + +struct nvfx_staging_transfer +{ + struct util_staging_transfer base; + + unsigned offset; + unsigned map_count; +}; + +struct pipe_transfer * +nvfx_transfer_new(struct pipe_context *pipe, + struct pipe_resource *pt, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + if((usage & (PIPE_TRANSFER_UNSYNCHRONIZED | PIPE_TRANSFER_DONTBLOCK)) == PIPE_TRANSFER_DONTBLOCK) + { + struct nouveau_bo* bo = ((struct nvfx_resource*)pt)->bo; + if(bo && nouveau_bo_busy(bo, NOUVEAU_BO_WR)) + return NULL; + } + + if(pt->target == PIPE_BUFFER) + { + // it would be nice if we could avoid all this ridiculous overhead... + struct pipe_transfer* tx; + struct nvfx_buffer* buffer = nvfx_buffer(pt); + + tx = CALLOC_STRUCT(pipe_transfer); + if (!tx) + return NULL; + + pipe_resource_reference(&tx->resource, pt); + tx->level = level; + tx->usage = usage; + tx->box = *box; + + tx->layer_stride = tx->stride = util_format_get_stride(pt->format, box->width); + tx->data = buffer->data + util_format_get_stride(pt->format, box->x); + + return tx; + } + else + { + struct nvfx_staging_transfer* tx; + bool direct = !nvfx_resource_on_gpu(pt) && pt->flags & NVFX_RESOURCE_FLAG_LINEAR; + + tx = CALLOC_STRUCT(nvfx_staging_transfer); + if(!tx) + return NULL; + + util_staging_transfer_init(pipe, pt, level, usage, box, direct, &tx->base); + + if(direct) + { + tx->base.base.stride = nvfx_subresource_pitch(pt, level); + tx->base.base.layer_stride = tx->base.base.stride * u_minify(pt->height0, level); + tx->offset = nvfx_subresource_offset(pt, box->z, level, box->z) + + util_format_get_2d_size(pt->format, tx->base.base.stride, box->y) + + util_format_get_stride(pt->format, box->x); + } + else + { + tx->base.base.stride = nvfx_subresource_pitch(tx->base.staging_resource, 0); + tx->base.base.layer_stride = tx->base.base.stride * tx->base.staging_resource->height0; + tx->offset = 0; + } + + assert(tx->base.base.stride); + + return &tx->base.base; + } +} + +static void nvfx_buffer_dirty_interval(struct nvfx_buffer* buffer, unsigned begin, unsigned size, boolean unsynchronized) +{ + struct nvfx_screen* screen = nvfx_screen(buffer->base.base.screen); + buffer->last_update_static = buffer->bytes_to_draw_until_static < 0; + if(buffer->dirty_begin == buffer->dirty_end) + { + buffer->dirty_begin = begin; + buffer->dirty_end = begin + size; + buffer->dirty_unsynchronized = unsynchronized; + } + else + { + buffer->dirty_begin = MIN2(buffer->dirty_begin, begin); + buffer->dirty_end = MAX2(buffer->dirty_end, begin + size); + buffer->dirty_unsynchronized &= unsynchronized; + } + + if(unsynchronized) + { + // TODO: revisit this, it doesn't seem quite right + //printf("UNSYNC UPDATE %p %u %u\n", buffer, begin, size); + buffer->bytes_to_draw_until_static += size * screen->static_reuse_threshold; + } + else + buffer->bytes_to_draw_until_static = buffer->size * screen->static_reuse_threshold; +} + +static void nvfx_transfer_flush_region( struct pipe_context *pipe, + struct pipe_transfer *ptx, + const struct pipe_box *box) +{ + if(ptx->resource->target == PIPE_BUFFER && (ptx->usage & PIPE_TRANSFER_FLUSH_EXPLICIT)) + { + struct nvfx_buffer* buffer = nvfx_buffer(ptx->resource); + nvfx_buffer_dirty_interval(buffer, + (uint8_t*)ptx->data - buffer->data + util_format_get_stride(buffer->base.base.format, box->x), + util_format_get_stride(buffer->base.base.format, box->width), + !!(ptx->usage & PIPE_TRANSFER_UNSYNCHRONIZED)); + } +} + +static void +nvfx_transfer_destroy(struct pipe_context *pipe, struct pipe_transfer *ptx) +{ + if(ptx->resource->target == PIPE_BUFFER) + { + struct nvfx_buffer* buffer = nvfx_buffer(ptx->resource); + if((ptx->usage & (PIPE_TRANSFER_WRITE | PIPE_TRANSFER_FLUSH_EXPLICIT)) == PIPE_TRANSFER_WRITE) + nvfx_buffer_dirty_interval(buffer, + (uint8_t*)ptx->data - buffer->data, + ptx->stride, + !!(ptx->usage & PIPE_TRANSFER_UNSYNCHRONIZED)); + pipe_resource_reference(&ptx->resource, 0); + FREE(ptx); + } + else + { + struct nouveau_channel* chan = nvfx_context(pipe)->screen->base.channel; + util_staging_transfer_destroy(pipe, ptx); + + FIRE_RING(chan); + } +} + +void * +nvfx_transfer_map(struct pipe_context *pipe, struct pipe_transfer *ptx) +{ + if(ptx->resource->target == PIPE_BUFFER) + return ptx->data; + else + { + struct nvfx_staging_transfer *tx = (struct nvfx_staging_transfer *)ptx; + if(!ptx->data) + { + struct nvfx_miptree *mt = (struct nvfx_miptree *)tx->base.staging_resource; + uint8_t *map = nouveau_screen_bo_map(pipe->screen, mt->base.bo, nouveau_screen_transfer_flags(ptx->usage)); + ptx->data = map + tx->offset; + } + + ++tx->map_count; + return ptx->data; + } +} + +void +nvfx_transfer_unmap(struct pipe_context *pipe, struct pipe_transfer *ptx) +{ + if(ptx->resource->target != PIPE_BUFFER) + { + struct nvfx_staging_transfer *tx = (struct nvfx_staging_transfer *)ptx; + struct nvfx_miptree *mt = (struct nvfx_miptree *)tx->base.staging_resource; + + if(!--tx->map_count) + { + nouveau_screen_bo_unmap(pipe->screen, mt->base.bo); + ptx->data = 0; + } + } +} + +static void nvfx_transfer_inline_write( struct pipe_context *pipe, + struct pipe_resource *pr, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned slice_stride) +{ + if(pr->target != PIPE_BUFFER) + { + u_default_transfer_inline_write(pipe, pr, level, usage, box, data, stride, slice_stride); + } + else + { + struct nvfx_buffer* buffer = nvfx_buffer(pr); + unsigned begin = util_format_get_stride(pr->format, box->x); + unsigned size = util_format_get_stride(pr->format, box->width); + memcpy(buffer->data + begin, data, size); + nvfx_buffer_dirty_interval(buffer, begin, size, + !!(pr->flags & PIPE_TRANSFER_UNSYNCHRONIZED)); + } +} + +void +nvfx_init_transfer_functions(struct pipe_context *pipe) +{ + pipe->get_transfer = nvfx_transfer_new; + pipe->transfer_map = nvfx_transfer_map; + pipe->transfer_flush_region = nvfx_transfer_flush_region; + pipe->transfer_unmap = nvfx_transfer_unmap; + pipe->transfer_destroy = nvfx_transfer_destroy; + pipe->transfer_inline_write = nvfx_transfer_inline_write; +} diff --git a/src/gallium/drivers/nvfx/nvfx_transfer.h b/src/gallium/drivers/nvfx/nvfx_transfer.h new file mode 100644 index 0000000..682f428 --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_transfer.h @@ -0,0 +1,24 @@ + +#ifndef NVFX_TRANSFER_H +#define NVFX_TRANSFER_H + +#include "util/u_transfer.h" +#include "pipe/p_state.h" + + +struct pipe_transfer * +nvfx_transfer_new(struct pipe_context *pcontext, + struct pipe_resource *pt, + unsigned level, + unsigned usage, + const struct pipe_box *box); + +void * +nvfx_transfer_map(struct pipe_context *pcontext, + struct pipe_transfer *ptx); +void +nvfx_transfer_unmap(struct pipe_context *pcontext, + struct pipe_transfer *ptx); + + +#endif diff --git a/src/gallium/drivers/nvfx/nvfx_vbo.c b/src/gallium/drivers/nvfx/nvfx_vbo.c new file mode 100644 index 0000000..597664e --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_vbo.c @@ -0,0 +1,643 @@ +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "translate/translate.h" + +#include "nvfx_context.h" +#include "nvfx_state.h" +#include "nvfx_resource.h" + +#include "nouveau/nouveau_channel.h" + +#include "nouveau/nouveau_pushbuf.h" + +static inline unsigned +util_guess_unique_indices_count(unsigned mode, unsigned indices) +{ + /* Euler's formula gives V = + * = E - F + 2 = + * = F * (polygon_edges / 2 - 1) + 2 = + * = F * (polygon_edges - 2) / 2 + 2 = + * = indices * (polygon_edges - 2) / (2 * indices_per_face) + 2 + * = indices * (1 / 2 - 1 / polygon_edges) + 2 + */ + switch(mode) + { + case PIPE_PRIM_LINES: + return indices >> 1; + case PIPE_PRIM_TRIANGLES: + { + // avoid an expensive division by 3 using the multiplicative inverse mod 2^32 + unsigned q; + unsigned inv3 = 2863311531; + indices >>= 1; + q = indices * inv3; + if(unlikely(q >= indices)) + { + q += inv3; + if(q >= indices) + q += inv3; + } + return indices + 2; + //return indices / 6 + 2; + } + // guess that indexed quads are created by successive connections, since a closed mesh seems unlikely + case PIPE_PRIM_QUADS: + return (indices >> 1) + 2; + // return (indices >> 2) + 2; // if it is a closed mesh + default: + return indices; + } +} + +static unsigned nvfx_decide_upload_mode(struct pipe_context *pipe, const struct pipe_draw_info *info) +{ + struct nvfx_context* nvfx = nvfx_context(pipe); + unsigned hardware_cost = 0; + unsigned inline_cost = 0; + unsigned unique_vertices; + unsigned upload_mode; + float best_index_cost_for_hardware_vertices_as_inline_cost; + boolean prefer_hardware_indices; + unsigned index_inline_cost; + unsigned index_hardware_cost; + if (info->indexed) + unique_vertices = util_guess_unique_indices_count(info->mode, info->count); + else + unique_vertices = info->count; + + /* Here we try to figure out if we are better off writing vertex data directly on the FIFO, + * or create hardware buffer objects and pointing the hardware to them. + * + * This is done by computing the total memcpy cost of each option, ignoring uploads + * if we think that the buffer is static and thus the upload cost will be amortized over + * future draw calls. + * + * For instance, if everything looks static, we will always create buffer objects, while if + * everything is a user buffer and we are not doing indexed drawing, we never do. + * + * Other interesting cases are where a small user vertex buffer, but a huge user index buffer, + * where we will upload the vertex buffer, so that we can use hardware index lookup, and + * the opposite case, where we instead do index lookup in software to avoid uploading + * a huge amount of vertex data that is not going to be used. + * + * Otherwise, we generally move to the GPU the after it has been pushed + * NVFX_STATIC_BUFFER_MIN_REUSE_TIMES times to the GPU without having + * been updated with a transfer (or just the buffer having been destroyed). + * + * There is no special handling for user buffers, since applications can use + * OpenGL VBOs in a one-shot fashion. OpenGL 3/4 core profile forces this + * by the way. + * + * Note that currently we don't support only putting some data on the FIFO, and + * some on vertex buffers (constant and instanced data is independent from this). + * + * nVidia doesn't seem to do this either, even though it should be at least + * doable with VTX_ATTR and possibly with VERTEX_DATA too if not indexed. + */ + + for (unsigned i = 0; i < nvfx->vtxelt->num_per_vertex_buffer_infos; i++) + { + struct nvfx_per_vertex_buffer_info* vbi = &nvfx->vtxelt->per_vertex_buffer_info[i]; + struct pipe_vertex_buffer *vb = &nvfx->vtxbuf[vbi->vertex_buffer_index]; + struct nvfx_buffer* buffer = nvfx_buffer(vb->buffer); + buffer->bytes_to_draw_until_static -= vbi->per_vertex_size * unique_vertices; + if (!nvfx_buffer_seems_static(buffer)) + { + hardware_cost += buffer->dirty_end - buffer->dirty_begin; + if (!buffer->base.bo) + hardware_cost += nvfx->screen->buffer_allocation_cost; + } + inline_cost += vbi->per_vertex_size * info->count; + } + + best_index_cost_for_hardware_vertices_as_inline_cost = 0.0f; + prefer_hardware_indices = FALSE; + index_inline_cost = 0; + index_hardware_cost = 0; + + if (info->indexed) + { + index_inline_cost = nvfx->idxbuf.index_size * info->count; + if (nvfx->screen->index_buffer_reloc_flags + && (nvfx->idxbuf.index_size == 2 || nvfx->idxbuf.index_size == 4) + && !(nvfx->idxbuf.offset & (nvfx->idxbuf.index_size - 1))) + { + struct nvfx_buffer* buffer = nvfx_buffer(nvfx->idxbuf.buffer); + buffer->bytes_to_draw_until_static -= index_inline_cost; + + prefer_hardware_indices = TRUE; + + if (!nvfx_buffer_seems_static(buffer)) + { + index_hardware_cost = buffer->dirty_end - buffer->dirty_begin; + if (!buffer->base.bo) + index_hardware_cost += nvfx->screen->buffer_allocation_cost; + } + + if ((float) index_inline_cost < (float) index_hardware_cost * nvfx->screen->inline_cost_per_hardware_cost) + { + best_index_cost_for_hardware_vertices_as_inline_cost = (float) index_inline_cost; + } + else + { + best_index_cost_for_hardware_vertices_as_inline_cost = (float) index_hardware_cost * nvfx->screen->inline_cost_per_hardware_cost; + prefer_hardware_indices = TRUE; + } + } + } + + /* let's finally figure out which of the 3 paths we want to take */ + if ((float) (inline_cost + index_inline_cost) > ((float) hardware_cost * nvfx->screen->inline_cost_per_hardware_cost + best_index_cost_for_hardware_vertices_as_inline_cost)) + upload_mode = 1 + prefer_hardware_indices; + else + upload_mode = 0; + +#ifdef DEBUG + if (unlikely(nvfx->screen->trace_draw)) + { + fprintf(stderr, "DRAW"); + if (info->indexed) + { + fprintf(stderr, "_IDX%u", nvfx->idxbuf.index_size); + if (info->index_bias) + fprintf(stderr, " biased %u", info->index_bias); + fprintf(stderr, " idxrange %u -> %u", info->min_index, info->max_index); + } + if (info->instance_count > 1) + fprintf(stderr, " %u instances from %u", info->instance_count, info->indexed); + fprintf(stderr, " start %u count %u prim %u", info->start, info->count, info->mode); + if (!upload_mode) + fprintf(stderr, " -> inline vertex data"); + else if (upload_mode == 2 || !info->indexed) + fprintf(stderr, " -> buffer range"); + else + fprintf(stderr, " -> inline indices"); + fprintf(stderr, " [ivtx %u hvtx %u iidx %u hidx %u bidx %f] <", inline_cost, hardware_cost, index_inline_cost, index_hardware_cost, best_index_cost_for_hardware_vertices_as_inline_cost); + for (unsigned i = 0; i < nvfx->vtxelt->num_per_vertex_buffer_infos; ++i) + { + struct nvfx_per_vertex_buffer_info* vbi = &nvfx->vtxelt->per_vertex_buffer_info[i]; + struct pipe_vertex_buffer *vb = &nvfx->vtxbuf[vbi->vertex_buffer_index]; + struct nvfx_buffer* buffer = nvfx_buffer(vb->buffer); + if (i) + fprintf(stderr, ", "); + fprintf(stderr, "%p%s left %Li", buffer, buffer->last_update_static ? " static" : "", buffer->bytes_to_draw_until_static); + } + fprintf(stderr, ">\n"); + } +#endif + + return upload_mode; +} + +void nvfx_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + unsigned upload_mode = 0; + + if (!nvfx->vtxelt->needs_translate) + upload_mode = nvfx_decide_upload_mode(pipe, info); + + nvfx->use_index_buffer = upload_mode > 1; + + if ((upload_mode > 0) != nvfx->use_vertex_buffers) + { + nvfx->use_vertex_buffers = (upload_mode > 0); + nvfx->dirty |= NVFX_NEW_ARRAYS; + nvfx->draw_dirty |= NVFX_NEW_ARRAYS; + } + + if (upload_mode > 0) + { + for (unsigned i = 0; i < nvfx->vtxelt->num_per_vertex_buffer_infos; i++) + { + struct nvfx_per_vertex_buffer_info* vbi = &nvfx->vtxelt->per_vertex_buffer_info[i]; + struct pipe_vertex_buffer *vb = &nvfx->vtxbuf[vbi->vertex_buffer_index]; + nvfx_buffer_upload(nvfx_buffer(vb->buffer)); + } + + if (upload_mode > 1) + { + nvfx_buffer_upload(nvfx_buffer(nvfx->idxbuf.buffer)); + + if (unlikely(info->index_bias != nvfx->base_vertex)) + { + nvfx->base_vertex = info->index_bias; + nvfx->dirty |= NVFX_NEW_ARRAYS; + } + } + else + { + if (unlikely(info->start < nvfx->base_vertex && nvfx->base_vertex)) + { + nvfx->base_vertex = 0; + nvfx->dirty |= NVFX_NEW_ARRAYS; + } + } + } + + if (nvfx->screen->force_swtnl || !nvfx_state_validate(nvfx)) + nvfx_draw_vbo_swtnl(pipe, info); + else + nvfx_push_vbo(pipe, info); +} + +boolean +nvfx_vbo_validate(struct nvfx_context *nvfx) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + int i; + int elements = MAX2(nvfx->vtxelt->num_elements, nvfx->hw_vtxelt_nr); + unsigned vb_flags = nvfx->screen->vertex_buffer_reloc_flags | NOUVEAU_BO_RD; + + if (!elements) + return TRUE; + + MARK_RING(chan, (5 + 2) * 16 + 2 + 11, 16 + 2); + for(unsigned i = 0; i < nvfx->vtxelt->num_constant; ++i) + { + struct nvfx_low_frequency_element *ve = &nvfx->vtxelt->constant[i]; + struct pipe_vertex_buffer *vb = &nvfx->vtxbuf[ve->vertex_buffer_index]; + struct nvfx_buffer* buffer = nvfx_buffer(vb->buffer); + float v[4]; + ve->fetch_rgba_float(v, buffer->data + vb->buffer_offset + ve->src_offset, 0, 0); + nvfx_emit_vtx_attr(chan, ve->idx, v, ve->ncomp); + } + + + OUT_RING(chan, RING_3D(NV30_3D_VTXFMT(0), elements)); + if(nvfx->use_vertex_buffers) + { + unsigned idx = 0; + for (i = 0; i < nvfx->vtxelt->num_per_vertex; i++) { + struct nvfx_per_vertex_element *ve = &nvfx->vtxelt->per_vertex[i]; + struct pipe_vertex_buffer *vb = &nvfx->vtxbuf[ve->vertex_buffer_index]; + + if(idx != ve->idx) + { + assert(idx < ve->idx); + OUT_RINGp(chan, &nvfx->vtxelt->vtxfmt[idx], ve->idx - idx); + idx = ve->idx; + } + + OUT_RING(chan, nvfx->vtxelt->vtxfmt[idx] | (vb->stride << NV30_3D_VTXFMT_STRIDE__SHIFT)); + ++idx; + } + if(idx != nvfx->vtxelt->num_elements) + OUT_RINGp(chan, &nvfx->vtxelt->vtxfmt[idx], nvfx->vtxelt->num_elements - idx); + } + else + OUT_RINGp(chan, nvfx->vtxelt->vtxfmt, nvfx->vtxelt->num_elements); + + for(i = nvfx->vtxelt->num_elements; i < elements; ++i) + OUT_RING(chan, NV30_3D_VTXFMT_TYPE_V32_FLOAT); + + if(nvfx->is_nv4x) { + unsigned i; + /* seems to be some kind of cache flushing */ + for(i = 0; i < 3; ++i) { + OUT_RING(chan, RING_3D(0x1718, 1)); + OUT_RING(chan, 0); + } + } + + OUT_RING(chan, RING_3D(NV30_3D_VTXBUF(0), elements)); + if(nvfx->use_vertex_buffers) + { + unsigned idx = 0; + for (i = 0; i < nvfx->vtxelt->num_per_vertex; i++) { + struct nvfx_per_vertex_element *ve = &nvfx->vtxelt->per_vertex[i]; + struct pipe_vertex_buffer *vb = &nvfx->vtxbuf[ve->vertex_buffer_index]; + struct nouveau_bo* bo = nvfx_resource(vb->buffer)->bo; + + for(; idx < ve->idx; ++idx) + OUT_RING(chan, 0); + + OUT_RELOC(chan, bo, + vb->buffer_offset + ve->src_offset + nvfx->base_vertex * vb->stride, + vb_flags | NOUVEAU_BO_LOW | NOUVEAU_BO_OR, + 0, NV30_3D_VTXBUF_DMA1); + ++idx; + } + + for(; idx < elements; ++idx) + OUT_RING(chan, 0); + } + else + { + for (i = 0; i < elements; i++) + OUT_RING(chan, 0); + } + + OUT_RING(chan, RING_3D(0x1710, 1)); + OUT_RING(chan, 0); + + nvfx->hw_vtxelt_nr = nvfx->vtxelt->num_elements; + nvfx->relocs_needed &=~ NVFX_RELOCATE_VTXBUF; + return TRUE; +} + +void +nvfx_vbo_swtnl_validate(struct nvfx_context *nvfx) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + unsigned num_outputs = nvfx->vertprog->draw_elements; + int elements = MAX2(num_outputs, nvfx->hw_vtxelt_nr); + + if (!elements) + return; + + WAIT_RING(chan, (1 + 6 + 1 + 2) + elements * 2); + + OUT_RING(chan, RING_3D(NV30_3D_VTXFMT(0), elements)); + for(unsigned i = 0; i < num_outputs; ++i) + OUT_RING(chan, (4 << NV30_3D_VTXFMT_SIZE__SHIFT) | NV30_3D_VTXFMT_TYPE_V32_FLOAT); + for(unsigned i = num_outputs; i < elements; ++i) + OUT_RING(chan, NV30_3D_VTXFMT_TYPE_V32_FLOAT); + + if(nvfx->is_nv4x) { + unsigned i; + /* seems to be some kind of cache flushing */ + for(i = 0; i < 3; ++i) { + OUT_RING(chan, RING_3D(0x1718, 1)); + OUT_RING(chan, 0); + } + } + + OUT_RING(chan, RING_3D(NV30_3D_VTXBUF(0), elements)); + for (unsigned i = 0; i < elements; i++) + OUT_RING(chan, 0); + + OUT_RING(chan, RING_3D(0x1710, 1)); + OUT_RING(chan, 0); + + nvfx->hw_vtxelt_nr = num_outputs; + nvfx->relocs_needed &=~ NVFX_RELOCATE_VTXBUF; +} + +void +nvfx_vbo_relocate(struct nvfx_context *nvfx) +{ + struct nouveau_channel* chan; + unsigned vb_flags; + int i; + + if(!nvfx->use_vertex_buffers) + return; + + chan = nvfx->screen->base.channel; + vb_flags = nvfx->screen->vertex_buffer_reloc_flags | NOUVEAU_BO_RD | NOUVEAU_BO_DUMMY; + + MARK_RING(chan, 2 * 16 + 3, 2 * 16 + 3); + for (i = 0; i < nvfx->vtxelt->num_per_vertex; i++) { + struct nvfx_per_vertex_element *ve = &nvfx->vtxelt->per_vertex[i]; + struct pipe_vertex_buffer *vb = &nvfx->vtxbuf[ve->vertex_buffer_index]; + struct nouveau_bo* bo = nvfx_resource(vb->buffer)->bo; + + OUT_RELOC(chan, bo, RING_3D(NV30_3D_VTXBUF(ve->idx), 1), + vb_flags, 0, 0); + OUT_RELOC(chan, bo, vb->buffer_offset + ve->src_offset + nvfx->base_vertex * vb->stride, + vb_flags | NOUVEAU_BO_LOW | NOUVEAU_BO_OR, + 0, NV30_3D_VTXBUF_DMA1); + } + nvfx->relocs_needed &=~ NVFX_RELOCATE_VTXBUF; +} + +static void +nvfx_idxbuf_emit(struct nvfx_context* nvfx, unsigned ib_flags) +{ + struct nouveau_channel* chan = nvfx->screen->base.channel; + unsigned ib_format = (nvfx->idxbuf.index_size == 2) ? NV30_3D_IDXBUF_FORMAT_TYPE_U16 : NV30_3D_IDXBUF_FORMAT_TYPE_U32; + struct nouveau_bo* bo = nvfx_resource(nvfx->idxbuf.buffer)->bo; + ib_flags |= nvfx->screen->index_buffer_reloc_flags | NOUVEAU_BO_RD; + + assert(nvfx->screen->index_buffer_reloc_flags); + + MARK_RING(chan, 3, 3); + if(ib_flags & NOUVEAU_BO_DUMMY) + OUT_RELOC(chan, bo, RING_3D(NV30_3D_IDXBUF_OFFSET, 2), ib_flags, 0, 0); + else + OUT_RING(chan, RING_3D(NV30_3D_IDXBUF_OFFSET, 2)); + OUT_RELOC(chan, bo, nvfx->idxbuf.offset + 1, ib_flags | NOUVEAU_BO_LOW, 0, 0); + OUT_RELOC(chan, bo, ib_format, ib_flags | NOUVEAU_BO_OR, + 0, NV30_3D_IDXBUF_FORMAT_DMA1); + nvfx->relocs_needed &=~ NVFX_RELOCATE_IDXBUF; +} + +void +nvfx_idxbuf_validate(struct nvfx_context* nvfx) +{ + nvfx_idxbuf_emit(nvfx, 0); +} + +void +nvfx_idxbuf_relocate(struct nvfx_context* nvfx) +{ + nvfx_idxbuf_emit(nvfx, NOUVEAU_BO_DUMMY); +} + +unsigned nvfx_vertex_formats[PIPE_FORMAT_COUNT] = +{ + [PIPE_FORMAT_R32_FLOAT] = NV30_3D_VTXFMT_TYPE_V32_FLOAT, + [PIPE_FORMAT_R32G32_FLOAT] = NV30_3D_VTXFMT_TYPE_V32_FLOAT, + [PIPE_FORMAT_R32G32B32_FLOAT] = NV30_3D_VTXFMT_TYPE_V32_FLOAT, + [PIPE_FORMAT_R32G32B32A32_FLOAT] = NV30_3D_VTXFMT_TYPE_V32_FLOAT, + [PIPE_FORMAT_R16_FLOAT] = NV30_3D_VTXFMT_TYPE_V16_FLOAT, + [PIPE_FORMAT_R16G16_FLOAT] = NV30_3D_VTXFMT_TYPE_V16_FLOAT, + [PIPE_FORMAT_R16G16B16_FLOAT] = NV30_3D_VTXFMT_TYPE_V16_FLOAT, + [PIPE_FORMAT_R16G16B16A16_FLOAT] = NV30_3D_VTXFMT_TYPE_V16_FLOAT, + [PIPE_FORMAT_R8_UNORM] = NV30_3D_VTXFMT_TYPE_U8_UNORM, + [PIPE_FORMAT_R8G8_UNORM] = NV30_3D_VTXFMT_TYPE_U8_UNORM, + [PIPE_FORMAT_R8G8B8_UNORM] = NV30_3D_VTXFMT_TYPE_U8_UNORM, + [PIPE_FORMAT_R8G8B8A8_UNORM] = NV30_3D_VTXFMT_TYPE_U8_UNORM, + [PIPE_FORMAT_R8G8B8A8_USCALED] = NV30_3D_VTXFMT_TYPE_U8_USCALED, + [PIPE_FORMAT_R16_SNORM] = NV30_3D_VTXFMT_TYPE_V16_SNORM, + [PIPE_FORMAT_R16G16_SNORM] = NV30_3D_VTXFMT_TYPE_V16_SNORM, + [PIPE_FORMAT_R16G16B16_SNORM] = NV30_3D_VTXFMT_TYPE_V16_SNORM, + [PIPE_FORMAT_R16G16B16A16_SNORM] = NV30_3D_VTXFMT_TYPE_V16_SNORM, + [PIPE_FORMAT_R16_SSCALED] = NV30_3D_VTXFMT_TYPE_V16_SSCALED, + [PIPE_FORMAT_R16G16_SSCALED] = NV30_3D_VTXFMT_TYPE_V16_SSCALED, + [PIPE_FORMAT_R16G16B16_SSCALED] = NV30_3D_VTXFMT_TYPE_V16_SSCALED, + [PIPE_FORMAT_R16G16B16A16_SSCALED] = NV30_3D_VTXFMT_TYPE_V16_SSCALED, +}; + +static void * +nvfx_vtxelts_state_create(struct pipe_context *pipe, + unsigned num_elements, + const struct pipe_vertex_element *elements) +{ + struct nvfx_vtxelt_state *cso = CALLOC_STRUCT(nvfx_vtxelt_state); + struct translate_key transkey; + unsigned per_vertex_size[16]; + unsigned vb_compacted_index[16]; + + if(num_elements > 16) + { + _debug_printf("Error: application attempted to use %u vertex elements, but only 16 are supported: ignoring the rest\n", num_elements); + num_elements = 16; + } + + memset(per_vertex_size, 0, sizeof(per_vertex_size)); + memcpy(cso->pipe, elements, num_elements * sizeof(elements[0])); + cso->num_elements = num_elements; + cso->needs_translate = FALSE; + + transkey.nr_elements = 0; + transkey.output_stride = 0; + + for(unsigned i = 0; i < num_elements; ++i) + { + const struct pipe_vertex_element* ve = &elements[i]; + if(!ve->instance_divisor) + per_vertex_size[ve->vertex_buffer_index] += util_format_get_stride(ve->src_format, 1); + } + + for(unsigned i = 0; i < 16; ++i) + { + if(per_vertex_size[i]) + { + unsigned idx = cso->num_per_vertex_buffer_infos++; + cso->per_vertex_buffer_info[idx].vertex_buffer_index = i; + cso->per_vertex_buffer_info[idx].per_vertex_size = per_vertex_size[i]; + vb_compacted_index[i] = idx; + } + } + + for(unsigned i = 0; i < num_elements; ++i) + { + const struct pipe_vertex_element* ve = &elements[i]; + unsigned type = nvfx_vertex_formats[ve->src_format]; + unsigned ncomp = util_format_get_nr_components(ve->src_format); + + //if(ve->frequency != PIPE_ELEMENT_FREQUENCY_PER_VERTEX) + if(ve->instance_divisor) + { + struct nvfx_low_frequency_element* lfve; + cso->vtxfmt[i] = NV30_3D_VTXFMT_TYPE_V32_FLOAT; + + //if(ve->frequency == PIPE_ELEMENT_FREQUENCY_CONSTANT) + if(0) + lfve = &cso->constant[cso->num_constant++]; + else + { + lfve = &cso->per_instance[cso->num_per_instance++].base; + ((struct nvfx_per_instance_element*)lfve)->instance_divisor = ve->instance_divisor; + } + + lfve->idx = i; + lfve->vertex_buffer_index = ve->vertex_buffer_index; + lfve->src_offset = ve->src_offset; + lfve->fetch_rgba_float = util_format_description(ve->src_format)->fetch_rgba_float; + lfve->ncomp = ncomp; + } + else + { + unsigned idx; + + idx = cso->num_per_vertex++; + cso->per_vertex[idx].idx = i; + cso->per_vertex[idx].vertex_buffer_index = ve->vertex_buffer_index; + cso->per_vertex[idx].src_offset = ve->src_offset; + + idx = transkey.nr_elements++; + transkey.element[idx].input_format = ve->src_format; + transkey.element[idx].input_buffer = vb_compacted_index[ve->vertex_buffer_index]; + transkey.element[idx].input_offset = ve->src_offset; + transkey.element[idx].instance_divisor = 0; + transkey.element[idx].type = TRANSLATE_ELEMENT_NORMAL; + if(type) + { + transkey.element[idx].output_format = ve->src_format; + cso->vtxfmt[i] = (ncomp << NV30_3D_VTXFMT_SIZE__SHIFT) | type; + } + else + { + unsigned float32[4] = {PIPE_FORMAT_R32_FLOAT, PIPE_FORMAT_R32G32_FLOAT, PIPE_FORMAT_R32G32B32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT}; + transkey.element[idx].output_format = float32[ncomp - 1]; + cso->needs_translate = TRUE; + cso->vtxfmt[i] = (ncomp << NV30_3D_VTXFMT_SIZE__SHIFT) | NV30_3D_VTXFMT_TYPE_V32_FLOAT; + } + transkey.element[idx].output_offset = transkey.output_stride; + transkey.output_stride += (util_format_get_stride(transkey.element[idx].output_format, 1) + 3) & ~3; + } + } + + cso->translate = translate_create(&transkey); + cso->vertex_length = transkey.output_stride >> 2; + cso->max_vertices_per_packet = 2047 / MAX2(cso->vertex_length, 1); + + return (void *)cso; +} + +static void +nvfx_vtxelts_state_delete(struct pipe_context *pipe, void *hwcso) +{ + FREE(hwcso); +} + +static void +nvfx_vtxelts_state_bind(struct pipe_context *pipe, void *hwcso) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + nvfx->vtxelt = hwcso; + nvfx->use_vertex_buffers = -1; + nvfx->draw_dirty |= NVFX_NEW_ARRAYS; +} + +static void +nvfx_set_vertex_buffers(struct pipe_context *pipe, unsigned count, + const struct pipe_vertex_buffer *vb) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + for(unsigned i = 0; i < count; ++i) + { + pipe_resource_reference(&nvfx->vtxbuf[i].buffer, vb[i].buffer); + nvfx->vtxbuf[i].buffer_offset = vb[i].buffer_offset; + nvfx->vtxbuf[i].max_index = vb[i].max_index; + nvfx->vtxbuf[i].stride = vb[i].stride; + } + + for(unsigned i = count; i < nvfx->vtxbuf_nr; ++i) + pipe_resource_reference(&nvfx->vtxbuf[i].buffer, 0); + + nvfx->vtxbuf_nr = count; + nvfx->use_vertex_buffers = -1; + nvfx->draw_dirty |= NVFX_NEW_ARRAYS; +} + +static void +nvfx_set_index_buffer(struct pipe_context *pipe, + const struct pipe_index_buffer *ib) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + if(ib) + { + pipe_resource_reference(&nvfx->idxbuf.buffer, ib->buffer); + nvfx->idxbuf.index_size = ib->index_size; + nvfx->idxbuf.offset = ib->offset; + } + else + { + pipe_resource_reference(&nvfx->idxbuf.buffer, 0); + nvfx->idxbuf.index_size = 0; + nvfx->idxbuf.offset = 0; + } + + nvfx->dirty |= NVFX_NEW_INDEX; + nvfx->draw_dirty |= NVFX_NEW_INDEX; +} + +void +nvfx_init_vbo_functions(struct nvfx_context *nvfx) +{ + nvfx->pipe.set_vertex_buffers = nvfx_set_vertex_buffers; + nvfx->pipe.set_index_buffer = nvfx_set_index_buffer; + + nvfx->pipe.create_vertex_elements_state = nvfx_vtxelts_state_create; + nvfx->pipe.delete_vertex_elements_state = nvfx_vtxelts_state_delete; + nvfx->pipe.bind_vertex_elements_state = nvfx_vtxelts_state_bind; +} diff --git a/src/gallium/drivers/nvfx/nvfx_vertprog.c b/src/gallium/drivers/nvfx/nvfx_vertprog.c new file mode 100644 index 0000000..e543fda --- /dev/null +++ b/src/gallium/drivers/nvfx/nvfx_vertprog.c @@ -0,0 +1,1455 @@ +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" +#include "util/u_linkage.h" +#include "util/u_debug.h" + +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_util.h" +#include "tgsi/tgsi_ureg.h" + +#include "draw/draw_context.h" + +#include "nvfx_context.h" +#include "nvfx_state.h" +#include "nvfx_resource.h" + +/* TODO (at least...): + * 1. Indexed consts + ARL + * 3. NV_vp11, NV_vp2, NV_vp3 features + * - extra arith opcodes + * - branching + * - texture sampling + * - indexed attribs + * - indexed results + * 4. bugs + */ + +#include "nv30_vertprog.h" +#include "nv40_vertprog.h" + +struct nvfx_loop_entry +{ + unsigned brk_target; + unsigned cont_target; +}; + +struct nvfx_vpc { + struct nvfx_context* nvfx; + struct pipe_shader_state pipe; + struct nvfx_vertex_program *vp; + struct tgsi_shader_info* info; + + struct nvfx_vertex_program_exec *vpi; + + unsigned r_temps; + unsigned r_temps_discard; + struct nvfx_reg r_result[PIPE_MAX_SHADER_OUTPUTS]; + struct nvfx_reg *r_address; + struct nvfx_reg *r_temp; + struct nvfx_reg *r_const; + struct nvfx_reg r_0_1; + + struct nvfx_reg *imm; + unsigned nr_imm; + + unsigned hpos_idx; + + struct util_dynarray label_relocs; + struct util_dynarray loop_stack; +}; + +static struct nvfx_reg +temp(struct nvfx_vpc *vpc) +{ + int idx = ffs(~vpc->r_temps) - 1; + + if (idx < 0) { + NOUVEAU_ERR("out of temps!!\n"); + assert(0); + return nvfx_reg(NVFXSR_TEMP, 0); + } + + vpc->r_temps |= (1 << idx); + vpc->r_temps_discard |= (1 << idx); + return nvfx_reg(NVFXSR_TEMP, idx); +} + +static inline void +release_temps(struct nvfx_vpc *vpc) +{ + vpc->r_temps &= ~vpc->r_temps_discard; + vpc->r_temps_discard = 0; +} + +static struct nvfx_reg +constant(struct nvfx_vpc *vpc, int pipe, float x, float y, float z, float w) +{ + struct nvfx_vertex_program *vp = vpc->vp; + struct nvfx_vertex_program_data *vpd; + int idx; + + if (pipe >= 0) { + for (idx = 0; idx < vp->nr_consts; idx++) { + if (vp->consts[idx].index == pipe) + return nvfx_reg(NVFXSR_CONST, idx); + } + } + + idx = vp->nr_consts++; + vp->consts = realloc(vp->consts, sizeof(*vpd) * vp->nr_consts); + vpd = &vp->consts[idx]; + + vpd->index = pipe; + vpd->value[0] = x; + vpd->value[1] = y; + vpd->value[2] = z; + vpd->value[3] = w; + return nvfx_reg(NVFXSR_CONST, idx); +} + +#define arith(s,t,o,d,m,s0,s1,s2) \ + nvfx_insn((s), (NVFX_VP_INST_SLOT_##t << 7) | NVFX_VP_INST_##t##_OP_##o, -1, (d), (m), (s0), (s1), (s2)) + +static void +emit_src(struct nvfx_context* nvfx, struct nvfx_vpc *vpc, uint32_t *hw, int pos, struct nvfx_src src) +{ + struct nvfx_vertex_program *vp = vpc->vp; + uint32_t sr = 0; + struct nvfx_relocation reloc; + + switch (src.reg.type) { + case NVFXSR_TEMP: + sr |= (NVFX_VP(SRC_REG_TYPE_TEMP) << NVFX_VP(SRC_REG_TYPE_SHIFT)); + sr |= (src.reg.index << NVFX_VP(SRC_TEMP_SRC_SHIFT)); + break; + case NVFXSR_INPUT: + sr |= (NVFX_VP(SRC_REG_TYPE_INPUT) << + NVFX_VP(SRC_REG_TYPE_SHIFT)); + vp->ir |= (1 << src.reg.index); + hw[1] |= (src.reg.index << NVFX_VP(INST_INPUT_SRC_SHIFT)); + break; + case NVFXSR_CONST: + sr |= (NVFX_VP(SRC_REG_TYPE_CONST) << + NVFX_VP(SRC_REG_TYPE_SHIFT)); + reloc.location = vp->nr_insns - 1; + reloc.target = src.reg.index; + util_dynarray_append(&vp->const_relocs, struct nvfx_relocation, reloc); + break; + case NVFXSR_NONE: + sr |= (NVFX_VP(SRC_REG_TYPE_INPUT) << + NVFX_VP(SRC_REG_TYPE_SHIFT)); + break; + default: + assert(0); + } + + if (src.negate) + sr |= NVFX_VP(SRC_NEGATE); + + if (src.abs) + hw[0] |= (1 << (21 + pos)); + + sr |= ((src.swz[0] << NVFX_VP(SRC_SWZ_X_SHIFT)) | + (src.swz[1] << NVFX_VP(SRC_SWZ_Y_SHIFT)) | + (src.swz[2] << NVFX_VP(SRC_SWZ_Z_SHIFT)) | + (src.swz[3] << NVFX_VP(SRC_SWZ_W_SHIFT))); + + if(src.indirect) { + if(src.reg.type == NVFXSR_CONST) + hw[3] |= NVFX_VP(INST_INDEX_CONST); + else if(src.reg.type == NVFXSR_INPUT) + hw[0] |= NVFX_VP(INST_INDEX_INPUT); + else + assert(0); + if(src.indirect_reg) + hw[0] |= NVFX_VP(INST_ADDR_REG_SELECT_1); + hw[0] |= src.indirect_swz << NVFX_VP(INST_ADDR_SWZ_SHIFT); + } + + switch (pos) { + case 0: + hw[1] |= ((sr & NVFX_VP(SRC0_HIGH_MASK)) >> + NVFX_VP(SRC0_HIGH_SHIFT)) << NVFX_VP(INST_SRC0H_SHIFT); + hw[2] |= (sr & NVFX_VP(SRC0_LOW_MASK)) << + NVFX_VP(INST_SRC0L_SHIFT); + break; + case 1: + hw[2] |= sr << NVFX_VP(INST_SRC1_SHIFT); + break; + case 2: + hw[2] |= ((sr & NVFX_VP(SRC2_HIGH_MASK)) >> + NVFX_VP(SRC2_HIGH_SHIFT)) << NVFX_VP(INST_SRC2H_SHIFT); + hw[3] |= (sr & NVFX_VP(SRC2_LOW_MASK)) << + NVFX_VP(INST_SRC2L_SHIFT); + break; + default: + assert(0); + } +} + +static void +emit_dst(struct nvfx_context* nvfx, struct nvfx_vpc *vpc, uint32_t *hw, int slot, struct nvfx_reg dst) +{ + struct nvfx_vertex_program *vp = vpc->vp; + + switch (dst.type) { + case NVFXSR_NONE: + if(!nvfx->is_nv4x) + hw[0] |= NV30_VP_INST_DEST_TEMP_ID_MASK; + else { + hw[3] |= NV40_VP_INST_DEST_MASK; + if (slot == 0) + hw[0] |= NV40_VP_INST_VEC_DEST_TEMP_MASK; + else + hw[3] |= NV40_VP_INST_SCA_DEST_TEMP_MASK; + } + break; + case NVFXSR_TEMP: + if(!nvfx->is_nv4x) + hw[0] |= (dst.index << NV30_VP_INST_DEST_TEMP_ID_SHIFT); + else { + hw[3] |= NV40_VP_INST_DEST_MASK; + if (slot == 0) + hw[0] |= (dst.index << NV40_VP_INST_VEC_DEST_TEMP_SHIFT); + else + hw[3] |= (dst.index << NV40_VP_INST_SCA_DEST_TEMP_SHIFT); + } + break; + case NVFXSR_OUTPUT: + /* TODO: this may be wrong because on nv30 COL0 and BFC0 are swapped */ + if(nvfx->is_nv4x) { + switch (dst.index) { + case NV30_VP_INST_DEST_CLP(0): + dst.index = NVFX_VP(INST_DEST_FOGC); + break; + case NV30_VP_INST_DEST_CLP(1): + dst.index = NVFX_VP(INST_DEST_FOGC); + break; + case NV30_VP_INST_DEST_CLP(2): + dst.index = NVFX_VP(INST_DEST_FOGC); + break; + case NV30_VP_INST_DEST_CLP(3): + dst.index = NVFX_VP(INST_DEST_PSZ); + break; + case NV30_VP_INST_DEST_CLP(4): + dst.index = NVFX_VP(INST_DEST_PSZ); + break; + case NV30_VP_INST_DEST_CLP(5): + dst.index = NVFX_VP(INST_DEST_PSZ); + break; + case NV40_VP_INST_DEST_COL0 : vp->or |= (1 << 0); break; + case NV40_VP_INST_DEST_COL1 : vp->or |= (1 << 1); break; + case NV40_VP_INST_DEST_BFC0 : vp->or |= (1 << 2); break; + case NV40_VP_INST_DEST_BFC1 : vp->or |= (1 << 3); break; + case NV40_VP_INST_DEST_FOGC: vp->or |= (1 << 4); break; + case NV40_VP_INST_DEST_PSZ : vp->or |= (1 << 5); break; + } + } + + if(!nvfx->is_nv4x) { + hw[3] |= (dst.index << NV30_VP_INST_DEST_SHIFT); + hw[0] |= NV30_VP_INST_VEC_DEST_TEMP_MASK; + + /*XXX: no way this is entirely correct, someone needs to + * figure out what exactly it is. + */ + hw[3] |= 0x800; + } else { + hw[3] |= (dst.index << NV40_VP_INST_DEST_SHIFT); + if (slot == 0) { + hw[0] |= NV40_VP_INST_VEC_RESULT; + hw[0] |= NV40_VP_INST_VEC_DEST_TEMP_MASK; + } else { + hw[3] |= NV40_VP_INST_SCA_RESULT; + hw[3] |= NV40_VP_INST_SCA_DEST_TEMP_MASK; + } + } + break; + default: + assert(0); + } +} + +static void +nvfx_vp_emit(struct nvfx_vpc *vpc, struct nvfx_insn insn) +{ + struct nvfx_context* nvfx = vpc->nvfx; + struct nvfx_vertex_program *vp = vpc->vp; + unsigned slot = insn.op >> 7; + unsigned op = insn.op & 0x7f; + uint32_t *hw; + + vp->insns = realloc(vp->insns, ++vp->nr_insns * sizeof(*vpc->vpi)); + vpc->vpi = &vp->insns[vp->nr_insns - 1]; + memset(vpc->vpi, 0, sizeof(*vpc->vpi)); + + hw = vpc->vpi->data; + + hw[0] |= (insn.cc_test << NVFX_VP(INST_COND_SHIFT)); + hw[0] |= ((insn.cc_swz[0] << NVFX_VP(INST_COND_SWZ_X_SHIFT)) | + (insn.cc_swz[1] << NVFX_VP(INST_COND_SWZ_Y_SHIFT)) | + (insn.cc_swz[2] << NVFX_VP(INST_COND_SWZ_Z_SHIFT)) | + (insn.cc_swz[3] << NVFX_VP(INST_COND_SWZ_W_SHIFT))); + if(insn.cc_update) + hw[0] |= NVFX_VP(INST_COND_UPDATE_ENABLE); + + if(insn.sat) + { + assert(nvfx->use_nv4x); + if(nvfx->use_nv4x) + hw[0] |= NV40_VP_INST_SATURATE; + } + + if(!nvfx->is_nv4x) { + if(slot == 0) + hw[1] |= (op << NV30_VP_INST_VEC_OPCODE_SHIFT); + else + { + hw[0] |= ((op >> 4) << NV30_VP_INST_SCA_OPCODEH_SHIFT); + hw[1] |= ((op & 0xf) << NV30_VP_INST_SCA_OPCODEL_SHIFT); + } +// hw[3] |= NVFX_VP(INST_SCA_DEST_TEMP_MASK); +// hw[3] |= (mask << NVFX_VP(INST_VEC_WRITEMASK_SHIFT)); + + if (insn.dst.type == NVFXSR_OUTPUT) { + if (slot) + hw[3] |= (insn.mask << NV30_VP_INST_SDEST_WRITEMASK_SHIFT); + else + hw[3] |= (insn.mask << NV30_VP_INST_VDEST_WRITEMASK_SHIFT); + } else { + if (slot) + hw[3] |= (insn.mask << NV30_VP_INST_STEMP_WRITEMASK_SHIFT); + else + hw[3] |= (insn.mask << NV30_VP_INST_VTEMP_WRITEMASK_SHIFT); + } + } else { + if (slot == 0) { + hw[1] |= (op << NV40_VP_INST_VEC_OPCODE_SHIFT); + hw[3] |= NV40_VP_INST_SCA_DEST_TEMP_MASK; + hw[3] |= (insn.mask << NV40_VP_INST_VEC_WRITEMASK_SHIFT); + } else { + hw[1] |= (op << NV40_VP_INST_SCA_OPCODE_SHIFT); + hw[0] |= NV40_VP_INST_VEC_DEST_TEMP_MASK ; + hw[3] |= (insn.mask << NV40_VP_INST_SCA_WRITEMASK_SHIFT); + } + } + + emit_dst(nvfx, vpc, hw, slot, insn.dst); + emit_src(nvfx, vpc, hw, 0, insn.src[0]); + emit_src(nvfx, vpc, hw, 1, insn.src[1]); + emit_src(nvfx, vpc, hw, 2, insn.src[2]); + +// if(insn.src[0].indirect || op == NVFX_VP_INST_VEC_OP_ARL) +// hw[3] |= NV40_VP_INST_SCA_RESULT; +} + +static inline struct nvfx_src +tgsi_src(struct nvfx_vpc *vpc, const struct tgsi_full_src_register *fsrc) { + struct nvfx_src src; + + switch (fsrc->Register.File) { + case TGSI_FILE_INPUT: + src.reg = nvfx_reg(NVFXSR_INPUT, fsrc->Register.Index); + break; + case TGSI_FILE_CONSTANT: + src.reg = vpc->r_const[fsrc->Register.Index]; + break; + case TGSI_FILE_IMMEDIATE: + src.reg = vpc->imm[fsrc->Register.Index]; + break; + case TGSI_FILE_TEMPORARY: + src.reg = vpc->r_temp[fsrc->Register.Index]; + break; + default: + NOUVEAU_ERR("bad src file\n"); + src.reg.index = 0; + src.reg.type = -1; + break; + } + + src.abs = fsrc->Register.Absolute; + src.negate = fsrc->Register.Negate; + src.swz[0] = fsrc->Register.SwizzleX; + src.swz[1] = fsrc->Register.SwizzleY; + src.swz[2] = fsrc->Register.SwizzleZ; + src.swz[3] = fsrc->Register.SwizzleW; + src.indirect = 0; + src.indirect_reg = 0; + src.indirect_swz = 0; + + if(fsrc->Register.Indirect) { + if(fsrc->Indirect.File == TGSI_FILE_ADDRESS && + (fsrc->Register.File == TGSI_FILE_CONSTANT || fsrc->Register.File == TGSI_FILE_INPUT)) + { + src.indirect = 1; + src.indirect_reg = fsrc->Indirect.Index; + src.indirect_swz = fsrc->Indirect.SwizzleX; + } + else + { + src.reg.index = 0; + src.reg.type = -1; + } + } + return src; +} + +static INLINE struct nvfx_reg +tgsi_dst(struct nvfx_vpc *vpc, const struct tgsi_full_dst_register *fdst) { + struct nvfx_reg dst; + + switch (fdst->Register.File) { + case TGSI_FILE_NULL: + dst = nvfx_reg(NVFXSR_NONE, 0); + break; + case TGSI_FILE_OUTPUT: + dst = vpc->r_result[fdst->Register.Index]; + break; + case TGSI_FILE_TEMPORARY: + dst = vpc->r_temp[fdst->Register.Index]; + break; + case TGSI_FILE_ADDRESS: + dst = vpc->r_address[fdst->Register.Index]; + break; + default: + NOUVEAU_ERR("bad dst file %i\n", fdst->Register.File); + dst.index = 0; + dst.type = 0; + break; + } + + return dst; +} + +static inline int +tgsi_mask(uint tgsi) +{ + int mask = 0; + + if (tgsi & TGSI_WRITEMASK_X) mask |= NVFX_VP_MASK_X; + if (tgsi & TGSI_WRITEMASK_Y) mask |= NVFX_VP_MASK_Y; + if (tgsi & TGSI_WRITEMASK_Z) mask |= NVFX_VP_MASK_Z; + if (tgsi & TGSI_WRITEMASK_W) mask |= NVFX_VP_MASK_W; + return mask; +} + +static boolean +nvfx_vertprog_parse_instruction(struct nvfx_context* nvfx, struct nvfx_vpc *vpc, + unsigned idx, const struct tgsi_full_instruction *finst) +{ + struct nvfx_src src[3], tmp; + struct nvfx_reg dst; + struct nvfx_reg final_dst; + struct nvfx_src none = nvfx_src(nvfx_reg(NVFXSR_NONE, 0)); + struct nvfx_insn insn; + struct nvfx_relocation reloc; + struct nvfx_loop_entry loop; + boolean sat = FALSE; + int mask; + int ai = -1, ci = -1, ii = -1; + int i; + unsigned sub_depth = 0; + + for (i = 0; i < finst->Instruction.NumSrcRegs; i++) { + const struct tgsi_full_src_register *fsrc; + + fsrc = &finst->Src[i]; + if (fsrc->Register.File == TGSI_FILE_TEMPORARY) { + src[i] = tgsi_src(vpc, fsrc); + } + } + + for (i = 0; i < finst->Instruction.NumSrcRegs; i++) { + const struct tgsi_full_src_register *fsrc; + + fsrc = &finst->Src[i]; + + switch (fsrc->Register.File) { + case TGSI_FILE_INPUT: + if (ai == -1 || ai == fsrc->Register.Index) { + ai = fsrc->Register.Index; + src[i] = tgsi_src(vpc, fsrc); + } else { + src[i] = nvfx_src(temp(vpc)); + nvfx_vp_emit(vpc, arith(0, VEC, MOV, src[i].reg, NVFX_VP_MASK_ALL, tgsi_src(vpc, fsrc), none, none)); + } + break; + case TGSI_FILE_CONSTANT: + if ((ci == -1 && ii == -1) || + ci == fsrc->Register.Index) { + ci = fsrc->Register.Index; + src[i] = tgsi_src(vpc, fsrc); + } else { + src[i] = nvfx_src(temp(vpc)); + nvfx_vp_emit(vpc, arith(0, VEC, MOV, src[i].reg, NVFX_VP_MASK_ALL, tgsi_src(vpc, fsrc), none, none)); + } + break; + case TGSI_FILE_IMMEDIATE: + if ((ci == -1 && ii == -1) || + ii == fsrc->Register.Index) { + ii = fsrc->Register.Index; + src[i] = tgsi_src(vpc, fsrc); + } else { + src[i] = nvfx_src(temp(vpc)); + nvfx_vp_emit(vpc, arith(0, VEC, MOV, src[i].reg, NVFX_VP_MASK_ALL, tgsi_src(vpc, fsrc), none, none)); + } + break; + case TGSI_FILE_TEMPORARY: + /* handled above */ + break; + default: + NOUVEAU_ERR("bad src file\n"); + return FALSE; + } + } + + for (i = 0; i < finst->Instruction.NumSrcRegs; i++) { + if(src[i].reg.type < 0) + return FALSE; + } + + if(finst->Dst[0].Register.File == TGSI_FILE_ADDRESS && + finst->Instruction.Opcode != TGSI_OPCODE_ARL) + return FALSE; + + final_dst = dst = tgsi_dst(vpc, &finst->Dst[0]); + mask = tgsi_mask(finst->Dst[0].Register.WriteMask); + if(finst->Instruction.Saturate == TGSI_SAT_ZERO_ONE) + { + assert(finst->Instruction.Opcode != TGSI_OPCODE_ARL); + if(nvfx->use_nv4x) + sat = TRUE; + else if(dst.type != NVFXSR_TEMP) + dst = temp(vpc); + } + + switch (finst->Instruction.Opcode) { + case TGSI_OPCODE_ABS: + nvfx_vp_emit(vpc, arith(sat, VEC, MOV, dst, mask, abs(src[0]), none, none)); + break; + case TGSI_OPCODE_ADD: + nvfx_vp_emit(vpc, arith(sat, VEC, ADD, dst, mask, src[0], none, src[1])); + break; + case TGSI_OPCODE_ARL: + nvfx_vp_emit(vpc, arith(0, VEC, ARL, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_CMP: + insn = arith(0, VEC, MOV, none.reg, mask, src[0], none, none); + insn.cc_update = 1; + nvfx_vp_emit(vpc, insn); + + insn = arith(sat, VEC, MOV, dst, mask, src[2], none, none); + insn.cc_test = NVFX_COND_GE; + nvfx_vp_emit(vpc, insn); + + insn = arith(sat, VEC, MOV, dst, mask, src[1], none, none); + insn.cc_test = NVFX_COND_LT; + nvfx_vp_emit(vpc, insn); + break; + case TGSI_OPCODE_COS: + nvfx_vp_emit(vpc, arith(sat, SCA, COS, dst, mask, none, none, src[0])); + break; + case TGSI_OPCODE_DP2: + tmp = nvfx_src(temp(vpc)); + nvfx_vp_emit(vpc, arith(0, VEC, MUL, tmp.reg, NVFX_VP_MASK_X | NVFX_VP_MASK_Y, src[0], src[1], none)); + nvfx_vp_emit(vpc, arith(sat, VEC, ADD, dst, mask, swz(tmp, X, X, X, X), none, swz(tmp, Y, Y, Y, Y))); + break; + case TGSI_OPCODE_DP3: + nvfx_vp_emit(vpc, arith(sat, VEC, DP3, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_DP4: + nvfx_vp_emit(vpc, arith(sat, VEC, DP4, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_DPH: + nvfx_vp_emit(vpc, arith(sat, VEC, DPH, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_DST: + nvfx_vp_emit(vpc, arith(sat, VEC, DST, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_EX2: + nvfx_vp_emit(vpc, arith(sat, SCA, EX2, dst, mask, none, none, src[0])); + break; + case TGSI_OPCODE_EXP: + nvfx_vp_emit(vpc, arith(sat, SCA, EXP, dst, mask, none, none, src[0])); + break; + case TGSI_OPCODE_FLR: + nvfx_vp_emit(vpc, arith(sat, VEC, FLR, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_FRC: + nvfx_vp_emit(vpc, arith(sat, VEC, FRC, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_LG2: + nvfx_vp_emit(vpc, arith(sat, SCA, LG2, dst, mask, none, none, src[0])); + break; + case TGSI_OPCODE_LIT: + nvfx_vp_emit(vpc, arith(sat, SCA, LIT, dst, mask, none, none, src[0])); + break; + case TGSI_OPCODE_LOG: + nvfx_vp_emit(vpc, arith(sat, SCA, LOG, dst, mask, none, none, src[0])); + break; + case TGSI_OPCODE_LRP: + tmp = nvfx_src(temp(vpc)); + nvfx_vp_emit(vpc, arith(0, VEC, MAD, tmp.reg, mask, neg(src[0]), src[2], src[2])); + nvfx_vp_emit(vpc, arith(sat, VEC, MAD, dst, mask, src[0], src[1], tmp)); + break; + case TGSI_OPCODE_MAD: + nvfx_vp_emit(vpc, arith(sat, VEC, MAD, dst, mask, src[0], src[1], src[2])); + break; + case TGSI_OPCODE_MAX: + nvfx_vp_emit(vpc, arith(sat, VEC, MAX, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_MIN: + nvfx_vp_emit(vpc, arith(sat, VEC, MIN, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_MOV: + nvfx_vp_emit(vpc, arith(sat, VEC, MOV, dst, mask, src[0], none, none)); + break; + case TGSI_OPCODE_MUL: + nvfx_vp_emit(vpc, arith(sat, VEC, MUL, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_NOP: + break; + case TGSI_OPCODE_POW: + tmp = nvfx_src(temp(vpc)); + nvfx_vp_emit(vpc, arith(0, SCA, LG2, tmp.reg, NVFX_VP_MASK_X, none, none, swz(src[0], X, X, X, X))); + nvfx_vp_emit(vpc, arith(0, VEC, MUL, tmp.reg, NVFX_VP_MASK_X, swz(tmp, X, X, X, X), swz(src[1], X, X, X, X), none)); + nvfx_vp_emit(vpc, arith(sat, SCA, EX2, dst, mask, none, none, swz(tmp, X, X, X, X))); + break; + case TGSI_OPCODE_RCP: + nvfx_vp_emit(vpc, arith(sat, SCA, RCP, dst, mask, none, none, src[0])); + break; + case TGSI_OPCODE_RSQ: + nvfx_vp_emit(vpc, arith(sat, SCA, RSQ, dst, mask, none, none, abs(src[0]))); + break; + case TGSI_OPCODE_SEQ: + nvfx_vp_emit(vpc, arith(sat, VEC, SEQ, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SFL: + nvfx_vp_emit(vpc, arith(sat, VEC, SFL, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SGE: + nvfx_vp_emit(vpc, arith(sat, VEC, SGE, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SGT: + nvfx_vp_emit(vpc, arith(sat, VEC, SGT, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SIN: + nvfx_vp_emit(vpc, arith(sat, SCA, SIN, dst, mask, none, none, src[0])); + break; + case TGSI_OPCODE_SLE: + nvfx_vp_emit(vpc, arith(sat, VEC, SLE, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SLT: + nvfx_vp_emit(vpc, arith(sat, VEC, SLT, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SNE: + nvfx_vp_emit(vpc, arith(sat, VEC, SNE, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SSG: + nvfx_vp_emit(vpc, arith(sat, VEC, SSG, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_STR: + nvfx_vp_emit(vpc, arith(sat, VEC, STR, dst, mask, src[0], src[1], none)); + break; + case TGSI_OPCODE_SUB: + nvfx_vp_emit(vpc, arith(sat, VEC, ADD, dst, mask, src[0], none, neg(src[1]))); + break; + case TGSI_OPCODE_TRUNC: + tmp = nvfx_src(temp(vpc)); + insn = arith(0, VEC, MOV, none.reg, mask, src[0], none, none); + insn.cc_update = 1; + nvfx_vp_emit(vpc, insn); + + nvfx_vp_emit(vpc, arith(0, VEC, FLR, tmp.reg, mask, abs(src[0]), none, none)); + nvfx_vp_emit(vpc, arith(sat, VEC, MOV, dst, mask, tmp, none, none)); + + insn = arith(sat, VEC, MOV, dst, mask, neg(tmp), none, none); + insn.cc_test = NVFX_COND_LT; + nvfx_vp_emit(vpc, insn); + break; + case TGSI_OPCODE_XPD: + tmp = nvfx_src(temp(vpc)); + nvfx_vp_emit(vpc, arith(0, VEC, MUL, tmp.reg, mask, swz(src[0], Z, X, Y, Y), swz(src[1], Y, Z, X, X), none)); + nvfx_vp_emit(vpc, arith(sat, VEC, MAD, dst, (mask & ~NVFX_VP_MASK_W), swz(src[0], Y, Z, X, X), swz(src[1], Z, X, Y, Y), neg(tmp))); + break; + + case TGSI_OPCODE_IF: + insn = arith(0, VEC, MOV, none.reg, NVFX_VP_MASK_X, src[0], none, none); + insn.cc_update = 1; + nvfx_vp_emit(vpc, insn); + + reloc.location = vpc->vp->nr_insns; + reloc.target = finst->Label.Label + 1; + util_dynarray_append(&vpc->label_relocs, struct nvfx_relocation, reloc); + + insn = arith(0, SCA, BRA, none.reg, 0, none, none, none); + insn.cc_test = NVFX_COND_EQ; + insn.cc_swz[0] = insn.cc_swz[1] = insn.cc_swz[2] = insn.cc_swz[3] = 0; + nvfx_vp_emit(vpc, insn); + break; + + case TGSI_OPCODE_ELSE: + case TGSI_OPCODE_BRA: + case TGSI_OPCODE_CAL: + reloc.location = vpc->vp->nr_insns; + reloc.target = finst->Label.Label; + util_dynarray_append(&vpc->label_relocs, struct nvfx_relocation, reloc); + + if(finst->Instruction.Opcode == TGSI_OPCODE_CAL) + insn = arith(0, SCA, CAL, none.reg, 0, none, none, none); + else + insn = arith(0, SCA, BRA, none.reg, 0, none, none, none); + nvfx_vp_emit(vpc, insn); + break; + + case TGSI_OPCODE_RET: + if(sub_depth || !nvfx->use_vp_clipping) { + tmp = none; + tmp.swz[0] = tmp.swz[1] = tmp.swz[2] = tmp.swz[3] = 0; + nvfx_vp_emit(vpc, arith(0, SCA, RET, none.reg, 0, none, none, tmp)); + } else { + reloc.location = vpc->vp->nr_insns; + reloc.target = vpc->info->num_instructions; + util_dynarray_append(&vpc->label_relocs, struct nvfx_relocation, reloc); + nvfx_vp_emit(vpc, arith(0, SCA, BRA, none.reg, 0, none, none, none)); + } + break; + + case TGSI_OPCODE_BGNSUB: + ++sub_depth; + break; + case TGSI_OPCODE_ENDSUB: + --sub_depth; + break; + case TGSI_OPCODE_ENDIF: + /* nothing to do here */ + break; + + case TGSI_OPCODE_BGNLOOP: + loop.cont_target = idx; + loop.brk_target = finst->Label.Label + 1; + util_dynarray_append(&vpc->loop_stack, struct nvfx_loop_entry, loop); + break; + + case TGSI_OPCODE_ENDLOOP: + loop = util_dynarray_pop(&vpc->loop_stack, struct nvfx_loop_entry); + + reloc.location = vpc->vp->nr_insns; + reloc.target = loop.cont_target; + util_dynarray_append(&vpc->label_relocs, struct nvfx_relocation, reloc); + + nvfx_vp_emit(vpc, arith(0, SCA, BRA, none.reg, 0, none, none, none)); + break; + + case TGSI_OPCODE_CONT: + loop = util_dynarray_top(&vpc->loop_stack, struct nvfx_loop_entry); + + reloc.location = vpc->vp->nr_insns; + reloc.target = loop.cont_target; + util_dynarray_append(&vpc->label_relocs, struct nvfx_relocation, reloc); + + nvfx_vp_emit(vpc, arith(0, SCA, BRA, none.reg, 0, none, none, none)); + break; + + case TGSI_OPCODE_BRK: + loop = util_dynarray_top(&vpc->loop_stack, struct nvfx_loop_entry); + + reloc.location = vpc->vp->nr_insns; + reloc.target = loop.brk_target; + util_dynarray_append(&vpc->label_relocs, struct nvfx_relocation, reloc); + + nvfx_vp_emit(vpc, arith(0, SCA, BRA, none.reg, 0, none, none, none)); + break; + + case TGSI_OPCODE_END: + assert(!sub_depth); + if(nvfx->use_vp_clipping) { + if(idx != (vpc->info->num_instructions - 1)) { + reloc.location = vpc->vp->nr_insns; + reloc.target = vpc->info->num_instructions; + util_dynarray_append(&vpc->label_relocs, struct nvfx_relocation, reloc); + nvfx_vp_emit(vpc, arith(0, SCA, BRA, none.reg, 0, none, none, none)); + } + } else { + if(vpc->vp->nr_insns) + vpc->vp->insns[vpc->vp->nr_insns - 1].data[3] |= NVFX_VP_INST_LAST; + nvfx_vp_emit(vpc, arith(0, VEC, NOP, none.reg, 0, none, none, none)); + vpc->vp->insns[vpc->vp->nr_insns - 1].data[3] |= NVFX_VP_INST_LAST; + } + break; + + default: + NOUVEAU_ERR("invalid opcode %d\n", finst->Instruction.Opcode); + return FALSE; + } + + if(finst->Instruction.Saturate == TGSI_SAT_ZERO_ONE && !nvfx->use_nv4x) + { + if(!vpc->r_0_1.type) + vpc->r_0_1 = constant(vpc, -1, 0, 1, 0, 0); + nvfx_vp_emit(vpc, arith(0, VEC, MAX, dst, mask, nvfx_src(dst), swz(nvfx_src(vpc->r_0_1), X, X, X, X), none)); + nvfx_vp_emit(vpc, arith(0, VEC, MIN, final_dst, mask, nvfx_src(dst), swz(nvfx_src(vpc->r_0_1), Y, Y, Y, Y), none)); + } + + release_temps(vpc); + return TRUE; +} + +static boolean +nvfx_vertprog_parse_decl_output(struct nvfx_context* nvfx, struct nvfx_vpc *vpc, + const struct tgsi_full_declaration *fdec) +{ + unsigned idx = fdec->Range.First; + int hw; + + switch (fdec->Semantic.Name) { + case TGSI_SEMANTIC_POSITION: + hw = NVFX_VP(INST_DEST_POS); + vpc->hpos_idx = idx; + break; + case TGSI_SEMANTIC_COLOR: + if (fdec->Semantic.Index == 0) { + hw = NVFX_VP(INST_DEST_COL0); + } else + if (fdec->Semantic.Index == 1) { + hw = NVFX_VP(INST_DEST_COL1); + } else { + NOUVEAU_ERR("bad colour semantic index\n"); + return FALSE; + } + break; + case TGSI_SEMANTIC_BCOLOR: + if (fdec->Semantic.Index == 0) { + hw = NVFX_VP(INST_DEST_BFC0); + } else + if (fdec->Semantic.Index == 1) { + hw = NVFX_VP(INST_DEST_BFC1); + } else { + NOUVEAU_ERR("bad bcolour semantic index\n"); + return FALSE; + } + break; + case TGSI_SEMANTIC_FOG: + hw = NVFX_VP(INST_DEST_FOGC); + break; + case TGSI_SEMANTIC_PSIZE: + hw = NVFX_VP(INST_DEST_PSZ); + break; + case TGSI_SEMANTIC_GENERIC: + hw = (vpc->vp->generic_to_fp_input[fdec->Semantic.Index] & 0xf) - NVFX_FP_OP_INPUT_SRC_TC(0); + if(hw <= 8) + hw = NVFX_VP(INST_DEST_TC(hw)); + else if(hw == 9) /* TODO: this is correct, but how does this overlapping work exactly? */ + hw = NV40_VP_INST_DEST_PSZ; + else + assert(0); + break; + case TGSI_SEMANTIC_EDGEFLAG: + /* not really an error just a fallback */ + NOUVEAU_ERR("cannot handle edgeflag output\n"); + return FALSE; + default: + NOUVEAU_ERR("bad output semantic\n"); + return FALSE; + } + + vpc->r_result[idx] = nvfx_reg(NVFXSR_OUTPUT, hw); + return TRUE; +} + +static boolean +nvfx_vertprog_prepare(struct nvfx_context* nvfx, struct nvfx_vpc *vpc) +{ + struct tgsi_parse_context p; + int high_const = -1, high_temp = -1, high_addr = -1, nr_imm = 0, i; + struct util_semantic_set set; + unsigned char sem_layout[10]; + unsigned num_outputs; + unsigned num_texcoords = nvfx->is_nv4x ? 10 : 8; + + num_outputs = util_semantic_set_from_program_file(&set, vpc->pipe.tokens, TGSI_FILE_OUTPUT); + + if(num_outputs > num_texcoords) { + NOUVEAU_ERR("too many vertex program outputs: %i\n", num_outputs); + return FALSE; + } + util_semantic_layout_from_set(sem_layout, &set, num_texcoords, num_texcoords); + + /* hope 0xf is (0, 0, 0, 1) initialized; otherwise, we are _probably_ not required to do this */ + memset(vpc->vp->generic_to_fp_input, 0x0f, sizeof(vpc->vp->generic_to_fp_input)); + for(int i = 0; i < num_texcoords; ++i) { + if(sem_layout[i] == 0xff) + continue; + //printf("vp: GENERIC[%i] to fpreg %i\n", sem_layout[i], NVFX_FP_OP_INPUT_SRC_TC(0) + i); + vpc->vp->generic_to_fp_input[sem_layout[i]] = 0xf0 | NVFX_FP_OP_INPUT_SRC_TC(i); + } + + vpc->vp->sprite_fp_input = -1; + for(int i = 0; i < num_texcoords; ++i) + { + if(sem_layout[i] == 0xff) + { + vpc->vp->sprite_fp_input = NVFX_FP_OP_INPUT_SRC_TC(i); + break; + } + } + + tgsi_parse_init(&p, vpc->pipe.tokens); + while (!tgsi_parse_end_of_tokens(&p)) { + const union tgsi_full_token *tok = &p.FullToken; + + tgsi_parse_token(&p); + switch(tok->Token.Type) { + case TGSI_TOKEN_TYPE_IMMEDIATE: + nr_imm++; + break; + case TGSI_TOKEN_TYPE_DECLARATION: + { + const struct tgsi_full_declaration *fdec; + + fdec = &p.FullToken.FullDeclaration; + switch (fdec->Declaration.File) { + case TGSI_FILE_TEMPORARY: + if (fdec->Range.Last > high_temp) { + high_temp = + fdec->Range.Last; + } + break; + case TGSI_FILE_ADDRESS: + if (fdec->Range.Last > high_addr) { + high_addr = + fdec->Range.Last; + } + break; + case TGSI_FILE_CONSTANT: + if (fdec->Range.Last > high_const) { + high_const = + fdec->Range.Last; + } + break; + case TGSI_FILE_OUTPUT: + if (!nvfx_vertprog_parse_decl_output(nvfx, vpc, fdec)) + return FALSE; + break; + default: + break; + } + } + break; + default: + break; + } + } + tgsi_parse_free(&p); + + if (nr_imm) { + vpc->imm = CALLOC(nr_imm, sizeof(struct nvfx_reg)); + assert(vpc->imm); + } + + if (++high_temp) { + vpc->r_temp = CALLOC(high_temp, sizeof(struct nvfx_reg)); + for (i = 0; i < high_temp; i++) + vpc->r_temp[i] = temp(vpc); + } + + if (++high_addr) { + vpc->r_address = CALLOC(high_addr, sizeof(struct nvfx_reg)); + for (i = 0; i < high_addr; i++) + vpc->r_address[i] = nvfx_reg(NVFXSR_TEMP, i); + } + + if(++high_const) { + vpc->r_const = CALLOC(high_const, sizeof(struct nvfx_reg)); + for (i = 0; i < high_const; i++) + vpc->r_const[i] = constant(vpc, i, 0, 0, 0, 0); + } + + vpc->r_temps_discard = 0; + return TRUE; +} + +DEBUG_GET_ONCE_BOOL_OPTION(nvfx_dump_vp, "NVFX_DUMP_VP", FALSE) + +static struct nvfx_vertex_program* +nvfx_vertprog_translate(struct nvfx_context *nvfx, const struct pipe_shader_state* vps, struct tgsi_shader_info* info) +{ + struct tgsi_parse_context parse; + struct nvfx_vertex_program* vp = NULL; + struct nvfx_vpc *vpc = NULL; + struct nvfx_src none = nvfx_src(nvfx_reg(NVFXSR_NONE, 0)); + struct util_dynarray insns; + int i; + + tgsi_parse_init(&parse, vps->tokens); + + vp = CALLOC_STRUCT(nvfx_vertex_program); + if(!vp) + goto out_err; + + vpc = CALLOC_STRUCT(nvfx_vpc); + if (!vpc) + goto out_err; + + vpc->nvfx = nvfx; + vpc->vp = vp; + vpc->pipe = *vps; + vpc->info = info; + + { + // TODO: use a 64-bit atomic here! + static unsigned long long id = 0; + vp->id = ++id; + } + + /* reserve space for ucps */ + if(nvfx->use_vp_clipping) + { + for(i = 0; i < 6; ++i) + constant(vpc, -1, 0, 0, 0, 0); + } + + if (!nvfx_vertprog_prepare(nvfx, vpc)) { + FREE(vpc); + return NULL; + } + + /* Redirect post-transform vertex position to a temp if user clip + * planes are enabled. We need to append code to the vtxprog + * to handle clip planes later. + */ + /* TODO: maybe support patching this depending on whether there are ucps: not sure if it is really matters much */ + if (nvfx->use_vp_clipping) { + vpc->r_result[vpc->hpos_idx] = temp(vpc); + vpc->r_temps_discard = 0; + } + + util_dynarray_init(&insns); + while (!tgsi_parse_end_of_tokens(&parse)) { + tgsi_parse_token(&parse); + + switch (parse.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_IMMEDIATE: + { + const struct tgsi_full_immediate *imm; + + imm = &parse.FullToken.FullImmediate; + assert(imm->Immediate.DataType == TGSI_IMM_FLOAT32); + assert(imm->Immediate.NrTokens == 4 + 1); + vpc->imm[vpc->nr_imm++] = + constant(vpc, -1, + imm->u[0].Float, + imm->u[1].Float, + imm->u[2].Float, + imm->u[3].Float); + } + break; + case TGSI_TOKEN_TYPE_INSTRUCTION: + { + const struct tgsi_full_instruction *finst; + unsigned idx = insns.size >> 2; + util_dynarray_append(&insns, unsigned, vp->nr_insns); + finst = &parse.FullToken.FullInstruction; + if (!nvfx_vertprog_parse_instruction(nvfx, vpc, idx, finst)) + goto out_err; + } + break; + default: + break; + } + } + + util_dynarray_append(&insns, unsigned, vp->nr_insns); + + for(unsigned i = 0; i < vpc->label_relocs.size; i += sizeof(struct nvfx_relocation)) + { + struct nvfx_relocation* label_reloc = (struct nvfx_relocation*)((char*)vpc->label_relocs.data + i); + struct nvfx_relocation hw_reloc; + + hw_reloc.location = label_reloc->location; + hw_reloc.target = ((unsigned*)insns.data)[label_reloc->target]; + + //debug_printf("hw %u -> tgsi %u = hw %u\n", hw_reloc.location, label_reloc->target, hw_reloc.target); + + util_dynarray_append(&vp->branch_relocs, struct nvfx_relocation, hw_reloc); + } + util_dynarray_fini(&insns); + util_dynarray_trim(&vp->branch_relocs); + + /* XXX: what if we add a RET before?! make sure we jump here...*/ + + /* Write out HPOS if it was redirected to a temp earlier */ + if (vpc->r_result[vpc->hpos_idx].type != NVFXSR_OUTPUT) { + struct nvfx_reg hpos = nvfx_reg(NVFXSR_OUTPUT, + NVFX_VP(INST_DEST_POS)); + struct nvfx_src htmp = nvfx_src(vpc->r_result[vpc->hpos_idx]); + + nvfx_vp_emit(vpc, arith(0, VEC, MOV, hpos, NVFX_VP_MASK_ALL, htmp, none, none)); + } + + /* Insert code to handle user clip planes */ + if(nvfx->use_vp_clipping) + { + for (i = 0; i < 6; i++) { + struct nvfx_reg cdst = nvfx_reg(NVFXSR_OUTPUT, NV30_VP_INST_DEST_CLP(i)); + struct nvfx_src ceqn = nvfx_src(nvfx_reg(NVFXSR_CONST, i)); + struct nvfx_src htmp = nvfx_src(vpc->r_result[vpc->hpos_idx]); + unsigned mask; + + if(nvfx->is_nv4x) + { + switch (i) { + case 0: case 3: mask = NVFX_VP_MASK_Y; break; + case 1: case 4: mask = NVFX_VP_MASK_Z; break; + case 2: case 5: mask = NVFX_VP_MASK_W; break; + default: + NOUVEAU_ERR("invalid clip dist #%d\n", i); + goto out_err; + } + } + else + mask = NVFX_VP_MASK_X; + + nvfx_vp_emit(vpc, arith(0, VEC, DP4, cdst, mask, htmp, ceqn, none)); + } + } + + if(debug_get_option_nvfx_dump_vp()) + { + debug_printf("\n"); + tgsi_dump(vpc->pipe.tokens, 0); + + debug_printf("\n%s vertex program:\n", nvfx->is_nv4x ? "nv4x" : "nv3x"); + for (i = 0; i < vp->nr_insns; i++) + debug_printf("%3u: %08x %08x %08x %08x\n", i, vp->insns[i].data[0], vp->insns[i].data[1], vp->insns[i].data[2], vp->insns[i].data[3]); + debug_printf("\n"); + } + + vp->clip_nr = -1; + vp->exec_start = -1; + +out: + tgsi_parse_free(&parse); + if(vpc) { + util_dynarray_fini(&vpc->label_relocs); + util_dynarray_fini(&vpc->loop_stack); + FREE(vpc->r_temp); + FREE(vpc->r_address); + FREE(vpc->r_const); + FREE(vpc->imm); + FREE(vpc); + } + return vp; + +out_err: + FREE(vp); + vp = NULL; + goto out; +} + +static struct nvfx_vertex_program* +nvfx_vertprog_translate_draw_vp(struct nvfx_context *nvfx, struct nvfx_pipe_vertex_program* pvp) +{ + struct nvfx_vertex_program* vp = NULL; + struct pipe_shader_state vps; + struct tgsi_shader_info info; + struct ureg_program *ureg = NULL; + unsigned num_outputs = MIN2(pvp->info.num_outputs, 16); + + ureg = ureg_create( TGSI_PROCESSOR_VERTEX ); + if(ureg == NULL) + return 0; + + for (unsigned i = 0; i < num_outputs; i++) + ureg_MOV(ureg, ureg_DECL_output(ureg, pvp->info.output_semantic_name[i], pvp->info.output_semantic_index[i]), ureg_DECL_vs_input(ureg, i)); + + ureg_END( ureg ); + + vps.tokens = ureg_get_tokens(ureg, 0); + tgsi_scan_shader(vps.tokens, &info); + vp = nvfx_vertprog_translate(nvfx, &vps, &info); + ureg_free_tokens(vps.tokens); + ureg_destroy(ureg); + + return vp; +} + +boolean +nvfx_vertprog_validate(struct nvfx_context *nvfx) +{ + struct nvfx_screen *screen = nvfx->screen; + struct nouveau_channel *chan = screen->base.channel; + struct nvfx_pipe_vertex_program *pvp = nvfx->vertprog; + struct nvfx_vertex_program* vp; + struct pipe_resource *constbuf; + boolean upload_code = FALSE, upload_data = FALSE; + int i; + + if (nvfx->render_mode == HW) { + nvfx->fallback_swtnl &= ~NVFX_NEW_VERTPROG; + vp = pvp->vp; + + if(!vp) { + vp = nvfx_vertprog_translate(nvfx, &pvp->pipe, &pvp->info); + if(!vp) + vp = NVFX_VP_FAILED; + pvp->vp = vp; + } + + if(vp == NVFX_VP_FAILED) { + nvfx->fallback_swtnl |= NVFX_NEW_VERTPROG; + return FALSE; + } + + constbuf = nvfx->constbuf[PIPE_SHADER_VERTEX]; + } else { + vp = pvp->draw_vp; + if(!vp) + { + pvp->draw_vp = vp = nvfx_vertprog_translate_draw_vp(nvfx, pvp); + if(!vp) { + _debug_printf("Error: unable to create a swtnl passthrough vertex shader: aborting."); + abort(); + } + } + constbuf = NULL; + } + + nvfx->hw_vertprog = vp; + + /* Allocate hw vtxprog exec slots */ + if (!vp->exec) { + struct nouveau_resource *heap = nvfx->screen->vp_exec_heap; + uint vplen = vp->nr_insns; + + if (nouveau_resource_alloc(heap, vplen, vp, &vp->exec)) { + while (heap->next && heap->size < vplen) { + struct nvfx_vertex_program *evict; + + evict = heap->next->priv; + nouveau_resource_free(&evict->exec); + } + + if (nouveau_resource_alloc(heap, vplen, vp, &vp->exec)) + { + debug_printf("Vertex shader too long: %u instructions\n", vplen); + nvfx->fallback_swtnl |= NVFX_NEW_VERTPROG; + return FALSE; + } + } + + upload_code = TRUE; + } + + /* Allocate hw vtxprog const slots */ + if (vp->nr_consts && !vp->data) { + struct nouveau_resource *heap = nvfx->screen->vp_data_heap; + + if (nouveau_resource_alloc(heap, vp->nr_consts, vp, &vp->data)) { + while (heap->next && heap->size < vp->nr_consts) { + struct nvfx_vertex_program *evict; + + evict = heap->next->priv; + nouveau_resource_free(&evict->data); + } + + if (nouveau_resource_alloc(heap, vp->nr_consts, vp, &vp->data)) + { + debug_printf("Vertex shader uses too many constants: %u constants\n", vp->nr_consts); + nvfx->fallback_swtnl |= NVFX_NEW_VERTPROG; + return FALSE; + } + } + + //printf("start at %u nc %u\n", vp->data->start, vp->nr_consts); + + /*XXX: handle this some day */ + assert(vp->data->start >= vp->data_start_min); + + upload_data = TRUE; + if (vp->data_start != vp->data->start) + upload_code = TRUE; + } + + /* If exec or data segments moved we need to patch the program to + * fixup offsets and register IDs. + */ + if (vp->exec_start != vp->exec->start) { + //printf("vp_relocs %u -> %u\n", vp->exec_start, vp->exec->start); + for(unsigned i = 0; i < vp->branch_relocs.size; i += sizeof(struct nvfx_relocation)) + { + struct nvfx_relocation* reloc = (struct nvfx_relocation*)((char*)vp->branch_relocs.data + i); + uint32_t* hw = vp->insns[reloc->location].data; + unsigned target = vp->exec->start + reloc->target; + + //debug_printf("vp_reloc hw %u -> hw %u\n", reloc->location, target); + + if(!nvfx->is_nv4x) + { + hw[2] &=~ NV30_VP_INST_IADDR_MASK; + hw[2] |= (target & 0x1ff) << NV30_VP_INST_IADDR_SHIFT; + } + else + { + hw[3] &=~ NV40_VP_INST_IADDRL_MASK; + hw[3] |= (target & 7) << NV40_VP_INST_IADDRL_SHIFT; + + hw[2] &=~ NV40_VP_INST_IADDRH_MASK; + hw[2] |= ((target >> 3) & 0x3f) << NV40_VP_INST_IADDRH_SHIFT; + } + } + + vp->exec_start = vp->exec->start; + } + + if (vp->data_start != vp->data->start) { + for(unsigned i = 0; i < vp->const_relocs.size; i += sizeof(struct nvfx_relocation)) + { + struct nvfx_relocation* reloc = (struct nvfx_relocation*)((char*)vp->const_relocs.data + i); + struct nvfx_vertex_program_exec *vpi = &vp->insns[reloc->location]; + + //printf("reloc %i to %i + %i\n", reloc->location, vp->data->start, reloc->target); + + vpi->data[1] &= ~NVFX_VP(INST_CONST_SRC_MASK); + vpi->data[1] |= + (reloc->target + vp->data->start) << + NVFX_VP(INST_CONST_SRC_SHIFT); + } + + vp->data_start = vp->data->start; + upload_code = TRUE; + } + + /* Update + Upload constant values */ + if (vp->nr_consts) { + float *map = NULL; + + if (constbuf) + map = (float*)nvfx_buffer(constbuf)->data; + + /* + * WAIT_RING(chan, 512 * 6); + for (i = 0; i < 512; i++) { + float v[4] = {0.1, 0,2, 0.3, 0.4}; + OUT_RING(chan, RING_3D(NV30_3D_VP_UPLOAD_CONST_ID, 5)); + OUT_RING(chan, i); + OUT_RINGp(chan, (uint32_t *)v, 4); + printf("frob %i\n", i); + } + */ + + WAIT_RING(chan, 6 * vp->nr_consts); + for (i = nvfx->use_vp_clipping ? 6 : 0; i < vp->nr_consts; i++) { + struct nvfx_vertex_program_data *vpd = &vp->consts[i]; + + if (vpd->index >= 0) { + if (!upload_data && + !memcmp(vpd->value, &map[vpd->index * 4], + 4 * sizeof(float))) + continue; + memcpy(vpd->value, &map[vpd->index * 4], + 4 * sizeof(float)); + } + + //printf("upload into %i + %i: %f %f %f %f\n", vp->data->start, i, vpd->value[0], vpd->value[1], vpd->value[2], vpd->value[3]); + + OUT_RING(chan, RING_3D(NV30_3D_VP_UPLOAD_CONST_ID, 5)); + OUT_RING(chan, i + vp->data->start); + OUT_RINGp(chan, (uint32_t *)vpd->value, 4); + } + } + + /* Upload vtxprog */ + if (upload_code) { + WAIT_RING(chan, 2 + 5 * vp->nr_insns); + OUT_RING(chan, RING_3D(NV30_3D_VP_UPLOAD_FROM_ID, 1)); + OUT_RING(chan, vp->exec->start); + for (i = 0; i < vp->nr_insns; i++) { + OUT_RING(chan, RING_3D(NV30_3D_VP_UPLOAD_INST(0), 4)); + //printf("%08x %08x %08x %08x\n", vp->insns[i].data[0], vp->insns[i].data[1], vp->insns[i].data[2], vp->insns[i].data[3]); + OUT_RINGp(chan, vp->insns[i].data, 4); + } + vp->clip_nr = -1; + } + + if(nvfx->dirty & (NVFX_NEW_VERTPROG)) + { + WAIT_RING(chan, 6); + OUT_RING(chan, RING_3D(NV30_3D_VP_START_FROM_ID, 1)); + OUT_RING(chan, vp->exec->start); + if(nvfx->is_nv4x) { + OUT_RING(chan, RING_3D(NV40_3D_VP_ATTRIB_EN, 1)); + OUT_RING(chan, vp->ir); + } + } + + return TRUE; +} + +void +nvfx_vertprog_destroy(struct nvfx_context *nvfx, struct nvfx_vertex_program *vp) +{ + if (vp->nr_insns) + FREE(vp->insns); + + if (vp->nr_consts) + FREE(vp->consts); + + nouveau_resource_free(&vp->exec); + nouveau_resource_free(&vp->data); + + util_dynarray_fini(&vp->branch_relocs); + util_dynarray_fini(&vp->const_relocs); + FREE(vp); +} + +static void * +nvfx_vp_state_create(struct pipe_context *pipe, const struct pipe_shader_state *cso) +{ + struct nvfx_pipe_vertex_program *pvp; + + pvp = CALLOC(1, sizeof(struct nvfx_pipe_vertex_program)); + pvp->pipe.tokens = tgsi_dup_tokens(cso->tokens); + tgsi_scan_shader(pvp->pipe.tokens, &pvp->info); + pvp->draw_elements = MAX2(1, MIN2(pvp->info.num_outputs, 16)); + pvp->draw_no_elements = pvp->info.num_outputs == 0; + + return (void *)pvp; +} + +static void +nvfx_vp_state_bind(struct pipe_context *pipe, void *hwcso) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + + nvfx->vertprog = hwcso; + nvfx->dirty |= NVFX_NEW_VERTPROG; + nvfx->draw_dirty |= NVFX_NEW_VERTPROG; +} + +static void +nvfx_vp_state_delete(struct pipe_context *pipe, void *hwcso) +{ + struct nvfx_context *nvfx = nvfx_context(pipe); + struct nvfx_pipe_vertex_program *pvp = hwcso; + + if(pvp->draw_vs) + draw_delete_vertex_shader(nvfx->draw, pvp->draw_vs); + if(pvp->vp && pvp->vp != NVFX_VP_FAILED) + nvfx_vertprog_destroy(nvfx, pvp->vp); + if(pvp->draw_vp) + nvfx_vertprog_destroy(nvfx, pvp->draw_vp); + FREE((void*)pvp->pipe.tokens); + FREE(pvp); +} + +void +nvfx_init_vertprog_functions(struct nvfx_context *nvfx) +{ + nvfx->pipe.create_vs_state = nvfx_vp_state_create; + nvfx->pipe.bind_vs_state = nvfx_vp_state_bind; + nvfx->pipe.delete_vs_state = nvfx_vp_state_delete; +} diff --git a/src/gallium/drivers/r300/Makefile b/src/gallium/drivers/r300/Makefile new file mode 100644 index 0000000..66d900e --- /dev/null +++ b/src/gallium/drivers/r300/Makefile @@ -0,0 +1,44 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = r300 + +C_SOURCES = \ + r300_blit.c \ + r300_chipset.c \ + r300_context.c \ + r300_debug.c \ + r300_emit.c \ + r300_flush.c \ + r300_fs.c \ + r300_hyperz.c \ + r300_query.c \ + r300_render.c \ + r300_render_stencilref.c \ + r300_render_translate.c \ + r300_resource.c \ + r300_screen.c \ + r300_screen_buffer.c \ + r300_state.c \ + r300_state_derived.c \ + r300_vs.c \ + r300_vs_draw.c \ + r300_texture.c \ + r300_texture_desc.c \ + r300_tgsi_to_rc.c \ + r300_transfer.c + +LIBRARY_INCLUDES = \ + -I$(TOP)/src/mesa/drivers/dri/r300/compiler \ + -I$(TOP)/src/gallium/winsys/drm/radeon/core + +COMPILER_ARCHIVE = $(TOP)/src/mesa/drivers/dri/r300/compiler/libr300compiler.a + +EXTRA_OBJECTS = \ + $(COMPILER_ARCHIVE) + +include ../../Makefile.template + +.PHONY: $(COMPILER_ARCHIVE) +$(COMPILER_ARCHIVE): + $(MAKE) -C $(TOP)/src/mesa/drivers/dri/r300/compiler diff --git a/src/gallium/drivers/r300/SConscript b/src/gallium/drivers/r300/SConscript new file mode 100644 index 0000000..b49db93 --- /dev/null +++ b/src/gallium/drivers/r300/SConscript @@ -0,0 +1,45 @@ +Import('*') + +r300compiler = SConscript('#/src/mesa/drivers/dri/r300/compiler/SConscript') + +env = env.Clone() +# add the paths for r300compiler +env.Append(CPPPATH = [ + '#/src/mesa/drivers/dri/r300/compiler', + '#/src/gallium/winsys/drm/radeon/core', + '#/include', + '#/src/mesa', +]) + +r300 = env.ConvenienceLibrary( + target = 'r300', + source = [ + 'r300_blit.c', + 'r300_chipset.c', + 'r300_context.c', + 'r300_debug.c', + 'r300_emit.c', + 'r300_flush.c', + 'r300_fs.c', + 'r300_hyperz.c', + 'r300_query.c', + 'r300_render.c', + 'r300_render_stencilref.c', + 'r300_render_translate.c', + 'r300_resource.c', + 'r300_screen.c', + 'r300_screen_buffer.c', + 'r300_state.c', + 'r300_state_derived.c', + 'r300_vs.c', + 'r300_vs_draw.c', + 'r300_texture.c', + 'r300_texture_desc.c', + 'r300_tgsi_to_rc.c', + 'r300_transfer.c', + ] + r300compiler) + r300compiler + +env.Alias('r300', r300) + +Export('r300') + diff --git a/src/gallium/drivers/r300/r300_blit.c b/src/gallium/drivers/r300/r300_blit.c new file mode 100644 index 0000000..6e88643 --- /dev/null +++ b/src/gallium/drivers/r300/r300_blit.c @@ -0,0 +1,416 @@ +/* + * Copyright 2009 Marek Olšák + * + * 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 "r300_context.h" +#include "r300_emit.h" +#include "r300_hyperz.h" +#include "r300_texture.h" +#include "r300_winsys.h" + +#include "util/u_format.h" +#include "util/u_pack_color.h" + +enum r300_blitter_op /* bitmask */ +{ + R300_CLEAR = 1, + R300_CLEAR_SURFACE = 2, + R300_COPY = 4 +}; + +static void r300_blitter_begin(struct r300_context* r300, enum r300_blitter_op op) +{ + if (r300->query_current) { + r300->blitter_saved_query = r300->query_current; + r300_stop_query(r300); + } + + /* Yeah we have to save all those states to ensure the blitter operation + * is really transparent. The states will be restored by the blitter once + * copying is done. */ + util_blitter_save_blend(r300->blitter, r300->blend_state.state); + util_blitter_save_depth_stencil_alpha(r300->blitter, r300->dsa_state.state); + util_blitter_save_stencil_ref(r300->blitter, &(r300->stencil_ref)); + util_blitter_save_rasterizer(r300->blitter, r300->rs_state.state); + util_blitter_save_fragment_shader(r300->blitter, r300->fs.state); + util_blitter_save_vertex_shader(r300->blitter, r300->vs_state.state); + util_blitter_save_viewport(r300->blitter, &r300->viewport); + util_blitter_save_clip(r300->blitter, (struct pipe_clip_state*)r300->clip_state.state); + util_blitter_save_vertex_elements(r300->blitter, r300->velems); + util_blitter_save_vertex_buffers(r300->blitter, r300->vertex_buffer_count, + r300->vertex_buffer); + + if (op & (R300_CLEAR_SURFACE | R300_COPY)) + util_blitter_save_framebuffer(r300->blitter, r300->fb_state.state); + + if (op & R300_COPY) { + struct r300_textures_state* state = + (struct r300_textures_state*)r300->textures_state.state; + + util_blitter_save_fragment_sampler_states( + r300->blitter, state->sampler_state_count, + (void**)state->sampler_states); + + util_blitter_save_fragment_sampler_views( + r300->blitter, state->sampler_view_count, + (struct pipe_sampler_view**)state->sampler_views); + } +} + +static void r300_blitter_end(struct r300_context *r300) +{ + if (r300->blitter_saved_query) { + r300_resume_query(r300, r300->blitter_saved_query); + r300->blitter_saved_query = NULL; + } +} + +static uint32_t r300_depth_clear_cb_value(enum pipe_format format, + const float* rgba) +{ + union util_color uc; + util_pack_color(rgba, format, &uc); + + if (util_format_get_blocksizebits(format) == 32) + return uc.ui; + else + return uc.us | (uc.us << 16); +} + +static boolean r300_cbzb_clear_allowed(struct r300_context *r300, + unsigned clear_buffers) +{ + struct pipe_framebuffer_state *fb = + (struct pipe_framebuffer_state*)r300->fb_state.state; + + /* Only color clear allowed, and only one colorbuffer. */ + if (clear_buffers != PIPE_CLEAR_COLOR || fb->nr_cbufs != 1) + return FALSE; + + return r300_surface(fb->cbufs[0])->cbzb_allowed; +} + +static uint32_t r300_depth_clear_value(enum pipe_format format, + double depth, unsigned stencil) +{ + switch (format) { + case PIPE_FORMAT_Z16_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: + return util_pack_z(format, depth); + + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + return util_pack_z_stencil(format, depth, stencil); + + default: + assert(0); + return 0; + } +} + +/* Clear currently bound buffers. */ +static void r300_clear(struct pipe_context* pipe, + unsigned buffers, + const float* rgba, + double depth, + unsigned stencil) +{ + /* My notes about fastfill: + * + * 1) Only the zbuffer is cleared. + * + * 2) The zbuffer must be micro-tiled and whole microtiles must be + * written. If microtiling is disabled, it locks up. + * + * 3) There is Z Mask RAM which contains a compressed zbuffer and + * it interacts with fastfill. We should figure out how to use it + * to get more performance. + * This is what we know about the Z Mask: + * + * Each dword of the Z Mask contains compression information + * for 16 4x4 pixel blocks, that is 2 bits for each block. + * On chips with 2 Z pipes, every other dword maps to a different + * pipe. + * + * 4) ZB_DEPTHCLEARVALUE is used to clear the zbuffer and the Z Mask must + * be equal to 0. (clear the Z Mask RAM with zeros) + * + * 5) For 16-bit zbuffer, compression causes a hung with one or + * two samples and should not be used. + * + * 6) FORCE_COMPRESSED_STENCIL_VALUE should be enabled for stencil clears + * to avoid needless decompression. + * + * 7) Fastfill must not be used if reading of compressed Z data is disabled + * and writing of compressed Z data is enabled (RD/WR_COMP_ENABLE), + * i.e. it cannot be used to compress the zbuffer. + * + * 8) ZB_CB_CLEAR does not interact with fastfill in any way. + * + * - Marek + */ + + struct r300_context* r300 = r300_context(pipe); + struct pipe_framebuffer_state *fb = + (struct pipe_framebuffer_state*)r300->fb_state.state; + struct r300_hyperz_state *hyperz = + (struct r300_hyperz_state*)r300->hyperz_state.state; + struct r300_texture *zstex = + fb->zsbuf ? r300_texture(fb->zsbuf->texture) : NULL; + uint32_t width = fb->width; + uint32_t height = fb->height; + boolean can_hyperz = r300->rws->get_value(r300->rws, R300_CAN_HYPERZ); + uint32_t hyperz_dcv = hyperz->zb_depthclearvalue; + + /* Enable fast Z clear. + * The zbuffer must be in micro-tiled mode, otherwise it locks up. */ + if ((buffers & PIPE_CLEAR_DEPTHSTENCIL) && can_hyperz) { + hyperz_dcv = hyperz->zb_depthclearvalue = + r300_depth_clear_value(fb->zsbuf->format, depth, stencil); + + r300_mark_fb_state_dirty(r300, R300_CHANGED_ZCLEAR_FLAG); + if (zstex->zmask_mem[fb->zsbuf->u.tex.level]) { + r300_mark_atom_dirty(r300, &r300->zmask_clear); + buffers &= ~PIPE_CLEAR_DEPTHSTENCIL; + } + if (zstex->hiz_mem[fb->zsbuf->u.tex.level]) + r300_mark_atom_dirty(r300, &r300->hiz_clear); + } + + /* Enable CBZB clear. */ + if (r300_cbzb_clear_allowed(r300, buffers)) { + struct r300_surface *surf = r300_surface(fb->cbufs[0]); + + hyperz->zb_depthclearvalue = + r300_depth_clear_cb_value(surf->base.format, rgba); + + width = surf->cbzb_width; + height = surf->cbzb_height; + + r300->cbzb_clear = TRUE; + r300_mark_fb_state_dirty(r300, R300_CHANGED_CBZB_FLAG); + } + + /* Clear. */ + if (buffers) { + /* Clear using the blitter. */ + r300_blitter_begin(r300, R300_CLEAR); + util_blitter_clear(r300->blitter, + width, + height, + fb->nr_cbufs, + buffers, rgba, depth, stencil); + r300_blitter_end(r300); + } else if (r300->zmask_clear.dirty) { + /* Just clear zmask and hiz now, this does not use a standard draw + * procedure. */ + unsigned dwords; + + /* Calculate zmask_clear and hiz_clear atom sizes. */ + r300_update_hyperz_state(r300); + dwords = r300->zmask_clear.size + + (r300->hiz_clear.dirty ? r300->hiz_clear.size : 0) + + r300_get_num_cs_end_dwords(r300); + + /* Reserve CS space. */ + if (dwords > (R300_MAX_CMDBUF_DWORDS - r300->cs->cdw)) { + r300->context.flush(&r300->context, 0, NULL); + } + + /* Emit clear packets. */ + r300_emit_zmask_clear(r300, r300->zmask_clear.size, + r300->zmask_clear.state); + r300->zmask_clear.dirty = FALSE; + if (r300->hiz_clear.dirty) { + r300_emit_hiz_clear(r300, r300->hiz_clear.size, + r300->hiz_clear.state); + r300->hiz_clear.dirty = FALSE; + } + } else { + assert(0); + } + + /* Disable CBZB clear. */ + if (r300->cbzb_clear) { + r300->cbzb_clear = FALSE; + hyperz->zb_depthclearvalue = hyperz_dcv; + r300_mark_fb_state_dirty(r300, R300_CHANGED_CBZB_FLAG); + } + + /* Enable fastfill and/or hiz. + * + * If we cleared zmask/hiz, it's in use now. The Hyper-Z state update + * looks if zmask/hiz is in use and enables fastfill accordingly. */ + if (zstex && + (zstex->zmask_in_use[fb->zsbuf->u.tex.level] || + zstex->hiz_in_use[fb->zsbuf->u.tex.level])) { + r300_mark_atom_dirty(r300, &r300->hyperz_state); + } +} + +/* Clear a region of a color surface to a constant value. */ +static void r300_clear_render_target(struct pipe_context *pipe, + struct pipe_surface *dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct r300_context *r300 = r300_context(pipe); + + r300_blitter_begin(r300, R300_CLEAR_SURFACE); + util_blitter_clear_render_target(r300->blitter, dst, rgba, + dstx, dsty, width, height); + r300_blitter_end(r300); +} + +/* Clear a region of a depth stencil surface. */ +static void r300_clear_depth_stencil(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct r300_context *r300 = r300_context(pipe); + + r300_blitter_begin(r300, R300_CLEAR_SURFACE); + util_blitter_clear_depth_stencil(r300->blitter, dst, clear_flags, depth, stencil, + dstx, dsty, width, height); + r300_blitter_end(r300); +} + +/* Flush a depth stencil buffer. */ +void r300_flush_depth_stencil(struct pipe_context *pipe, + struct pipe_resource *dst, + unsigned level, + unsigned layer) +{ + struct r300_context *r300 = r300_context(pipe); + struct pipe_surface *dstsurf, surf_tmpl; + struct r300_texture *tex = r300_texture(dst); + + if (!tex->zmask_mem[level]) + return; + if (!tex->zmask_in_use[level]) + return; + + surf_tmpl.format = dst->format; + surf_tmpl.usage = PIPE_BIND_DEPTH_STENCIL; + surf_tmpl.u.tex.level = level; + surf_tmpl.u.tex.first_layer = layer; + surf_tmpl.u.tex.last_layer = layer; + dstsurf = pipe->create_surface(pipe, dst, &surf_tmpl); + + r300->z_decomp_rd = TRUE; + r300_blitter_begin(r300, R300_CLEAR_SURFACE); + util_blitter_flush_depth_stencil(r300->blitter, dstsurf); + r300_blitter_end(r300); + r300->z_decomp_rd = FALSE; + + tex->zmask_in_use[level] = FALSE; +} + +/* Copy a block of pixels from one surface to another using HW. */ +static void r300_hw_copy_region(struct pipe_context* pipe, + struct pipe_resource *dst, + unsigned dst_level, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource *src, + unsigned src_level, + const struct pipe_box *src_box) +{ + struct r300_context* r300 = r300_context(pipe); + + r300_blitter_begin(r300, R300_COPY); + + /* Do a copy */ + util_blitter_copy_region(r300->blitter, dst, dst_level, dstx, dsty, dstz, + src, src_level, src_box, TRUE); + r300_blitter_end(r300); +} + +/* Copy a block of pixels from one surface to another. */ +static void r300_resource_copy_region(struct pipe_context *pipe, + struct pipe_resource *dst, + unsigned dst_level, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource *src, + unsigned src_level, + const struct pipe_box *src_box) +{ + enum pipe_format old_format = dst->format; + enum pipe_format new_format = old_format; + boolean is_depth; + if (!pipe->screen->is_format_supported(pipe->screen, + old_format, src->target, + src->nr_samples, + PIPE_BIND_RENDER_TARGET | + PIPE_BIND_SAMPLER_VIEW, 0) && + util_format_is_plain(old_format)) { + switch (util_format_get_blocksize(old_format)) { + case 1: + new_format = PIPE_FORMAT_I8_UNORM; + break; + case 2: + new_format = PIPE_FORMAT_B4G4R4A4_UNORM; + break; + case 4: + new_format = PIPE_FORMAT_B8G8R8A8_UNORM; + break; + case 8: + new_format = PIPE_FORMAT_R16G16B16A16_UNORM; + break; + default: + debug_printf("r300: surface_copy: Unhandled format: %s. Falling back to software.\n" + "r300: surface_copy: Software fallback doesn't work for tiled textures.\n", + util_format_short_name(old_format)); + } + } + + is_depth = util_format_get_component_bits(src->format, UTIL_FORMAT_COLORSPACE_ZS, 0) != 0; + if (is_depth) { + r300_flush_depth_stencil(pipe, src, src_level, src_box->z); + } + if (old_format != new_format) { + r300_texture_reinterpret_format(pipe->screen, + dst, new_format); + r300_texture_reinterpret_format(pipe->screen, + src, new_format); + } + + r300_hw_copy_region(pipe, dst, dst_level, dstx, dsty, dstz, + src, src_level, src_box); + + if (old_format != new_format) { + r300_texture_reinterpret_format(pipe->screen, + dst, old_format); + r300_texture_reinterpret_format(pipe->screen, + src, old_format); + } +} + +void r300_init_blit_functions(struct r300_context *r300) +{ + r300->context.clear = r300_clear; + r300->context.clear_render_target = r300_clear_render_target; + r300->context.clear_depth_stencil = r300_clear_depth_stencil; + r300->context.resource_copy_region = r300_resource_copy_region; +} diff --git a/src/gallium/drivers/r300/r300_cb.h b/src/gallium/drivers/r300/r300_cb.h new file mode 100644 index 0000000..9d3d4fc --- /dev/null +++ b/src/gallium/drivers/r300/r300_cb.h @@ -0,0 +1,139 @@ +/* + * Copyright 2008 Corbin Simpson + * Copyright 2010 Marek Olšák + * + * 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. */ + +/** + * This file contains macros for building command buffers in memory. + * + * Use NEW_CB for buffers with a varying size and it will also allocate + * the buffer. + * Use BEGIN_CB for arrays with a static size. + * + * Example: + * + * uint32_t cb[3]; + * CB_LOCALS; + * + * BEGIN_CB(cb, 3); + * OUT_CB_REG_SEQ(R500_RB3D_CONSTANT_COLOR_AR, 2); + * OUT_CB(blend_color_red_alpha); + * OUT_CB(blend_color_green_blue); + * END_CB; + * + * And later: + * + * CS_LOCALS; + * WRITE_CS_TABLE(cb, 3); + * + * Or using a little slower variant: + * + * CS_LOCALS; + * BEGIN_CS(cb, 3); + * OUT_CS_TABLE(cb, 3); + * END_CS; + */ + +#ifndef R300_CB_H +#define R300_CB_H + +#include "r300_reg.h" + +/* Yes, I know macros are ugly. However, they are much prettier than the code + * that they neatly hide away, and don't have the cost of function setup, so + * we're going to use them. */ + +#ifdef DEBUG +#define CB_DEBUG(x) x +#else +#define CB_DEBUG(x) +#endif + + +/** + * Command buffer setup. + */ + +#define CB_LOCALS \ + CB_DEBUG(int cs_count = 0;) \ + uint32_t *cs_ptr = NULL; \ + CB_DEBUG((void) cs_count;) (void) cs_ptr; + +#define NEW_CB(ptr, size) do { \ + assert(sizeof(*ptr) == sizeof(uint32_t)); \ + cs_ptr = (ptr) = (uint32_t*)malloc((size) * sizeof(uint32_t)); \ + CB_DEBUG(cs_count = size;) \ +} while (0) + +#define BEGIN_CB(ptr, size) do { \ + assert(sizeof(*ptr) == sizeof(uint32_t)); \ + cs_ptr = ptr; \ + CB_DEBUG(cs_count = size;) \ +} while (0) + +#define END_CB do { \ + CB_DEBUG(if (cs_count != 0) \ + debug_printf("r300: Warning: cs_count off by %d at (%s, %s:%i)\n", \ + cs_count, __FUNCTION__, __FILE__, __LINE__);) \ +} while (0) + + +/** + * Storing pure DWORDs. + */ + +#define OUT_CB(value) do { \ + *cs_ptr = (value); \ + cs_ptr++; \ + CB_DEBUG(cs_count--;) \ +} while (0) + +#define OUT_CB_TABLE(values, count) do { \ + memcpy(cs_ptr, values, count * sizeof(uint32_t)); \ + cs_ptr += count; \ + CB_DEBUG(cs_count -= count;) \ +} while (0) + +#define OUT_CB_32F(value) \ + OUT_CB(fui(value)); + +#define OUT_CB_REG(register, value) do { \ + assert(register); \ + OUT_CB(CP_PACKET0(register, 0)); \ + OUT_CB(value); \ +} while (0) + +/* Note: This expects count to be the number of registers, + * not the actual packet0 count! */ +#define OUT_CB_REG_SEQ(register, count) do { \ + assert(register); \ + OUT_CB(CP_PACKET0(register, (count) - 1)); \ +} while (0) + +#define OUT_CB_ONE_REG(register, count) do { \ + assert(register); \ + OUT_CB(CP_PACKET0(register, (count) - 1) | RADEON_ONE_REG_WR); \ +} while (0) + +#define OUT_CB_PKT3(op, count) \ + OUT_CB(CP_PACKET3(op, count)) + +#endif /* R300_CB_H */ diff --git a/src/gallium/drivers/r300/r300_chipset.c b/src/gallium/drivers/r300/r300_chipset.c new file mode 100644 index 0000000..583e981 --- /dev/null +++ b/src/gallium/drivers/r300/r300_chipset.c @@ -0,0 +1,428 @@ +/* + * 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 "r300_chipset.h" + +#include "util/u_debug.h" + +#include + +/* r300_chipset: A file all to itself for deducing the various properties of + * Radeons. */ + +/* Parse a PCI ID and fill an r300_capabilities struct with information. */ +void r300_parse_chipset(struct r300_capabilities* caps) +{ + /* Reasonable defaults */ + caps->num_vert_fpus = 2; + caps->num_tex_units = 16; + caps->has_tcl = debug_get_bool_option("RADEON_NO_TCL", FALSE) ? FALSE : TRUE; + caps->hiz_ram = 0; + caps->is_r400 = FALSE; + caps->is_r500 = FALSE; + caps->high_second_pipe = FALSE; + + /* Note: These are not ordered by PCI ID. I leave that task to GCC, + * which will perform the ordering while collating jump tables. Instead, + * I've tried to group them according to capabilities and age. */ + switch (caps->pci_id) { + case 0x4144: + caps->family = CHIP_FAMILY_R300; + caps->high_second_pipe = TRUE; + caps->num_vert_fpus = 4; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x4145: + case 0x4146: + case 0x4147: + case 0x4E44: + case 0x4E45: + case 0x4E46: + case 0x4E47: + caps->family = CHIP_FAMILY_R300; + caps->high_second_pipe = TRUE; + caps->num_vert_fpus = 4; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x4150: + case 0x4151: + case 0x4152: + case 0x4153: + case 0x4154: + case 0x4155: + case 0x4156: + case 0x4E50: + case 0x4E51: + case 0x4E52: + case 0x4E53: + case 0x4E54: + case 0x4E56: + caps->family = CHIP_FAMILY_RV350; + caps->high_second_pipe = TRUE; + caps->zmask_ram = RV3xx_ZMASK_SIZE; + break; + + case 0x4148: + case 0x4149: + case 0x414A: + case 0x414B: + case 0x4E48: + case 0x4E49: + case 0x4E4B: + caps->family = CHIP_FAMILY_R350; + caps->high_second_pipe = TRUE; + caps->num_vert_fpus = 4; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x4E4A: + caps->family = CHIP_FAMILY_R360; + caps->high_second_pipe = TRUE; + caps->num_vert_fpus = 4; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x5460: + case 0x5462: + case 0x5464: + case 0x5B60: + case 0x5B62: + case 0x5B63: + case 0x5B64: + case 0x5B65: + caps->family = CHIP_FAMILY_RV370; + caps->high_second_pipe = TRUE; + caps->zmask_ram = RV3xx_ZMASK_SIZE; + break; + + case 0x3150: + case 0x3152: + case 0x3154: + case 0x3155: + case 0x3E50: + case 0x3E54: + caps->family = CHIP_FAMILY_RV380; + caps->high_second_pipe = TRUE; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = RV3xx_ZMASK_SIZE; + break; + + case 0x4A48: + case 0x4A49: + case 0x4A4A: + case 0x4A4B: + case 0x4A4C: + case 0x4A4D: + case 0x4A4E: + case 0x4A4F: + case 0x4A50: + case 0x4A54: + caps->family = CHIP_FAMILY_R420; + caps->num_vert_fpus = 6; + caps->is_r400 = TRUE; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x5548: + case 0x5549: + case 0x554A: + case 0x554B: + case 0x5550: + case 0x5551: + case 0x5552: + case 0x5554: + case 0x5D57: + caps->family = CHIP_FAMILY_R423; + caps->num_vert_fpus = 6; + caps->is_r400 = TRUE; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x554C: + case 0x554D: + case 0x554E: + case 0x554F: + case 0x5D48: + case 0x5D49: + case 0x5D4A: + caps->family = CHIP_FAMILY_R430; + caps->num_vert_fpus = 6; + caps->is_r400 = TRUE; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x5D4C: + case 0x5D4D: + case 0x5D4E: + case 0x5D4F: + case 0x5D50: + case 0x5D52: + caps->family = CHIP_FAMILY_R480; + caps->num_vert_fpus = 6; + caps->is_r400 = TRUE; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x4B48: + case 0x4B49: + case 0x4B4A: + case 0x4B4B: + case 0x4B4C: + caps->family = CHIP_FAMILY_R481; + caps->num_vert_fpus = 6; + caps->is_r400 = TRUE; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x5E4C: + case 0x5E4F: + case 0x564A: + case 0x564B: + case 0x564F: + case 0x5652: + case 0x5653: + case 0x5657: + case 0x5E48: + case 0x5E4A: + case 0x5E4B: + case 0x5E4D: + caps->family = CHIP_FAMILY_RV410; + caps->num_vert_fpus = 6; + caps->is_r400 = TRUE; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x5954: + case 0x5955: + caps->family = CHIP_FAMILY_RS480; + caps->has_tcl = FALSE; + caps->zmask_ram = RV3xx_ZMASK_SIZE; + break; + + case 0x5974: + case 0x5975: + caps->family = CHIP_FAMILY_RS482; + caps->has_tcl = FALSE; + caps->zmask_ram = RV3xx_ZMASK_SIZE; + break; + + case 0x5A41: + case 0x5A42: + caps->family = CHIP_FAMILY_RS400; + caps->has_tcl = FALSE; + caps->zmask_ram = RV3xx_ZMASK_SIZE; + break; + + case 0x5A61: + case 0x5A62: + caps->family = CHIP_FAMILY_RC410; + caps->has_tcl = FALSE; + caps->zmask_ram = RV3xx_ZMASK_SIZE; + break; + + case 0x791E: + case 0x791F: + caps->family = CHIP_FAMILY_RS690; + caps->has_tcl = FALSE; + caps->is_r400 = TRUE; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x793F: + case 0x7941: + case 0x7942: + caps->family = CHIP_FAMILY_RS600; + caps->has_tcl = FALSE; + caps->is_r400 = TRUE; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x796C: + case 0x796D: + case 0x796E: + case 0x796F: + caps->family = CHIP_FAMILY_RS740; + caps->has_tcl = FALSE; + caps->is_r400 = TRUE; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x7100: + case 0x7101: + case 0x7102: + case 0x7103: + case 0x7104: + case 0x7105: + case 0x7106: + case 0x7108: + case 0x7109: + case 0x710A: + case 0x710B: + case 0x710C: + case 0x710E: + case 0x710F: + caps->family = CHIP_FAMILY_R520; + caps->num_vert_fpus = 8; + caps->is_r500 = TRUE; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x7140: + case 0x7141: + case 0x7142: + case 0x7143: + case 0x7144: + case 0x7145: + case 0x7146: + case 0x7147: + case 0x7149: + case 0x714A: + case 0x714B: + case 0x714C: + case 0x714D: + case 0x714E: + case 0x714F: + case 0x7151: + case 0x7152: + case 0x7153: + case 0x715E: + case 0x715F: + case 0x7180: + case 0x7181: + case 0x7183: + case 0x7186: + case 0x7187: + case 0x7188: + case 0x718A: + case 0x718B: + case 0x718C: + case 0x718D: + case 0x718F: + case 0x7193: + case 0x7196: + case 0x719B: + case 0x719F: + case 0x7200: + case 0x7210: + case 0x7211: + caps->family = CHIP_FAMILY_RV515; + caps->num_vert_fpus = 2; + caps->is_r500 = TRUE; + caps->hiz_ram = R300_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x71C0: + case 0x71C1: + case 0x71C2: + case 0x71C3: + case 0x71C4: + case 0x71C5: + case 0x71C6: + case 0x71C7: + case 0x71CD: + case 0x71CE: + case 0x71D2: + case 0x71D4: + case 0x71D5: + case 0x71D6: + case 0x71DA: + case 0x71DE: + caps->family = CHIP_FAMILY_RV530; + caps->num_vert_fpus = 5; + caps->is_r500 = TRUE; + /*caps->hiz_ram = RV530_HIZ_LIMIT;*/ + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x7240: + case 0x7243: + case 0x7244: + case 0x7245: + case 0x7246: + case 0x7247: + case 0x7248: + case 0x7249: + case 0x724A: + case 0x724B: + case 0x724C: + case 0x724D: + case 0x724E: + case 0x724F: + case 0x7284: + caps->family = CHIP_FAMILY_R580; + caps->num_vert_fpus = 8; + caps->is_r500 = TRUE; + caps->hiz_ram = RV530_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x7280: + caps->family = CHIP_FAMILY_RV570; + caps->num_vert_fpus = 8; + caps->is_r500 = TRUE; + caps->hiz_ram = RV530_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + case 0x7281: + case 0x7283: + case 0x7287: + case 0x7288: + case 0x7289: + case 0x728B: + case 0x728C: + case 0x7290: + case 0x7291: + case 0x7293: + case 0x7297: + caps->family = CHIP_FAMILY_RV560; + caps->num_vert_fpus = 8; + caps->is_r500 = TRUE; + caps->hiz_ram = RV530_HIZ_LIMIT; + caps->zmask_ram = PIPE_ZMASK_SIZE; + break; + + default: + fprintf(stderr, "r300: Warning: Unknown chipset 0x%x\n", + caps->pci_id); + } + + caps->is_rv350 = caps->family >= CHIP_FAMILY_RV350; + caps->dxtc_swizzle = caps->is_r400 || caps->is_r500; +} diff --git a/src/gallium/drivers/r300/r300_chipset.h b/src/gallium/drivers/r300/r300_chipset.h new file mode 100644 index 0000000..f2035d2 --- /dev/null +++ b/src/gallium/drivers/r300/r300_chipset.h @@ -0,0 +1,119 @@ +/* + * 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 R300_CHIPSET_H +#define R300_CHIPSET_H + +#include "pipe/p_compiler.h" + +/* these are sizes in dwords */ +#define R300_HIZ_LIMIT 10240 +#define RV530_HIZ_LIMIT 15360 + +/* rv3xx have only one pipe */ +#define PIPE_ZMASK_SIZE 4096 +#define RV3xx_ZMASK_SIZE 5120 + +/* Structure containing all the possible information about a specific Radeon + * in the R3xx, R4xx, and R5xx families. */ +struct r300_capabilities { + /* PCI ID */ + uint32_t pci_id; + /* Chipset family */ + int family; + /* The number of vertex floating-point units */ + unsigned num_vert_fpus; + /* The number of fragment pipes */ + unsigned num_frag_pipes; + /* The number of z pipes */ + unsigned num_z_pipes; + /* The number of texture units. */ + unsigned num_tex_units; + /* Whether or not TCL is physically present */ + boolean has_tcl; + /* Some chipsets do not have HiZ RAM - other have varying amounts . */ + int hiz_ram; + /* some chipsets have zmask ram per pipe some don't */ + int zmask_ram; + /* Whether or not this is RV350 or newer, including all r400 and r500 + * chipsets. The differences compared to the oldest r300 chips are: + * - Blend LTE/GTE thresholds + * - Better MACRO_SWITCH in texture tiling + * - Half float vertex + * - More HyperZ optimizations */ + boolean is_rv350; + /* Whether or not this is R400. The differences compared their rv350 + * cousins are: + * - Extended fragment shader registers + * - 3DC texture compression (RGTC2) */ + boolean is_r400; + /* Whether or not this is an RV515 or newer; R500s have many differences + * that require extra consideration, compared to their rv350 cousins: + * - Extra bit of width and height on texture sizes + * - Blend color is split across two registers + * - Universal Shader (US) block used for fragment shaders + * - FP16 blending and multisampling + * - Full RGTC texture compression + * - 24-bit depth textures + * - Stencil back-face reference value + * - Ability to render up to 2^24 - 1 vertices with signed index offset */ + boolean is_r500; + /* Whether or not the second pixel pipe is accessed with the high bit */ + boolean high_second_pipe; + /* DXTC texture swizzling. */ + boolean dxtc_swizzle; + /* Index bias (AKA index offset). */ + boolean index_bias_supported; +}; + +/* Enumerations for legibility and telling which card we're running on. */ +enum { + CHIP_FAMILY_R300 = 0, + CHIP_FAMILY_R350, + CHIP_FAMILY_R360, + CHIP_FAMILY_RV350, + CHIP_FAMILY_RV370, + CHIP_FAMILY_RV380, + CHIP_FAMILY_R420, + CHIP_FAMILY_R423, + CHIP_FAMILY_R430, + CHIP_FAMILY_R480, + CHIP_FAMILY_R481, + CHIP_FAMILY_RV410, + CHIP_FAMILY_RS400, + CHIP_FAMILY_RC410, + CHIP_FAMILY_RS480, + CHIP_FAMILY_RS482, + CHIP_FAMILY_RS600, + CHIP_FAMILY_RS690, + CHIP_FAMILY_RS740, + CHIP_FAMILY_RV515, + CHIP_FAMILY_R520, + CHIP_FAMILY_RV530, + CHIP_FAMILY_R580, + CHIP_FAMILY_RV560, + CHIP_FAMILY_RV570 +}; + +void r300_parse_chipset(struct r300_capabilities* caps); + +#endif /* R300_CHIPSET_H */ diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c new file mode 100644 index 0000000..848020c --- /dev/null +++ b/src/gallium/drivers/r300/r300_context.c @@ -0,0 +1,561 @@ +/* + * 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 "draw/draw_context.h" + +#include "util/u_memory.h" +#include "util/u_sampler.h" +#include "util/u_simple_list.h" +#include "util/u_upload_mgr.h" + +#include "r300_cb.h" +#include "r300_context.h" +#include "r300_emit.h" +#include "r300_hyperz.h" +#include "r300_screen.h" +#include "r300_screen_buffer.h" +#include "r300_winsys.h" + +#ifdef HAVE_LLVM +#include "gallivm/lp_bld_init.h" +#endif + +static void r300_update_num_contexts(struct r300_screen *r300screen, + int diff) +{ + if (diff > 0) { + p_atomic_inc(&r300screen->num_contexts); + + if (r300screen->num_contexts > 1) + util_slab_set_thread_safety(&r300screen->pool_buffers, + UTIL_SLAB_MULTITHREADED); + } else { + p_atomic_dec(&r300screen->num_contexts); + + if (r300screen->num_contexts <= 1) + util_slab_set_thread_safety(&r300screen->pool_buffers, + UTIL_SLAB_SINGLETHREADED); + } +} + +static void r300_release_referenced_objects(struct r300_context *r300) +{ + struct pipe_framebuffer_state *fb = + (struct pipe_framebuffer_state*)r300->fb_state.state; + struct r300_textures_state *textures = + (struct r300_textures_state*)r300->textures_state.state; + struct r300_query *query, *temp; + unsigned i; + + /* Framebuffer state. */ + util_unreference_framebuffer_state(fb); + + /* Textures. */ + for (i = 0; i < textures->sampler_view_count; i++) + pipe_sampler_view_reference( + (struct pipe_sampler_view**)&textures->sampler_views[i], NULL); + + /* The special dummy texture for texkill. */ + if (r300->texkill_sampler) { + pipe_sampler_view_reference( + (struct pipe_sampler_view**)&r300->texkill_sampler, + NULL); + } + + /* The dummy VBO. */ + pipe_resource_reference(&r300->dummy_vb, NULL); + + /* The SWTCL VBO. */ + pipe_resource_reference(&r300->vbo, NULL); + + /* Vertex buffers. */ + for (i = 0; i < r300->vertex_buffer_count; i++) { + pipe_resource_reference(&r300->vertex_buffer[i].buffer, NULL); + } + + /* If there are any queries pending or not destroyed, remove them now. */ + foreach_s(query, temp, &r300->query_list) { + remove_from_list(query); + FREE(query); + } +} + +static void r300_destroy_context(struct pipe_context* context) +{ + struct r300_context* r300 = r300_context(context); + + if (r300->blitter) + util_blitter_destroy(r300->blitter); + if (r300->draw) { + draw_destroy(r300->draw); + +#ifdef HAVE_LLVM + gallivm_destroy(r300->gallivm); +#endif + } + + if (r300->upload_vb) + u_upload_destroy(r300->upload_vb); + if (r300->upload_ib) + u_upload_destroy(r300->upload_ib); + + if (r300->tran.translate_cache) + translate_cache_destroy(r300->tran.translate_cache); + + /* XXX: This function assumes r300->query_list was initialized */ + r300_release_referenced_objects(r300); + + if (r300->zmask_mm) + r300_hyperz_destroy_mm(r300); + + if (r300->cs) + r300->rws->cs_destroy(r300->cs); + + /* XXX: No way to tell if this was initialized or not? */ + util_slab_destroy(&r300->pool_transfers); + + r300_update_num_contexts(r300->screen, -1); + + /* Free the structs allocated in r300_setup_atoms() */ + if (r300->aa_state.state) { + FREE(r300->aa_state.state); + FREE(r300->blend_color_state.state); + FREE(r300->clip_state.state); + FREE(r300->fb_state.state); + FREE(r300->gpu_flush.state); + FREE(r300->hyperz_state.state); + FREE(r300->invariant_state.state); + FREE(r300->rs_block_state.state); + FREE(r300->scissor_state.state); + FREE(r300->textures_state.state); + FREE(r300->vap_invariant_state.state); + FREE(r300->viewport_state.state); + FREE(r300->ztop_state.state); + FREE(r300->fs_constants.state); + FREE(r300->vs_constants.state); + if (!r300->screen->caps.has_tcl) { + FREE(r300->vertex_stream_state.state); + } + } + FREE(r300); +} + +void r300_flush_cb(void *data) +{ + struct r300_context* const cs_context_copy = data; + + cs_context_copy->context.flush(&cs_context_copy->context, 0, NULL); +} + +#define R300_INIT_ATOM(atomname, atomsize) \ + do { \ + r300->atomname.name = #atomname; \ + r300->atomname.state = NULL; \ + r300->atomname.size = atomsize; \ + r300->atomname.emit = r300_emit_##atomname; \ + r300->atomname.dirty = FALSE; \ + } while (0) + +#define R300_ALLOC_ATOM(atomname, statetype) \ +do { \ + r300->atomname.state = CALLOC_STRUCT(statetype); \ + if (r300->atomname.state == NULL) \ + return FALSE; \ +} while (0) + +static boolean r300_setup_atoms(struct r300_context* r300) +{ + boolean is_rv350 = r300->screen->caps.is_rv350; + boolean is_r500 = r300->screen->caps.is_r500; + boolean has_tcl = r300->screen->caps.has_tcl; + boolean drm_2_3_0 = r300->rws->get_value(r300->rws, R300_VID_DRM_2_3_0); + boolean drm_2_6_0 = r300->rws->get_value(r300->rws, R300_VID_DRM_2_6_0); + boolean can_hyperz = r300->rws->get_value(r300->rws, R300_CAN_HYPERZ); + boolean has_hiz_ram = r300->screen->caps.hiz_ram > 0; + + /* Create the actual atom list. + * + * Some atoms never change size, others change every emit - those have + * the size of 0 here. + * + * NOTE: The framebuffer state is split into these atoms: + * - gpu_flush (unpipelined regs) + * - aa_state (unpipelined regs) + * - fb_state (unpipelined regs) + * - hyperz_state (unpipelined regs followed by pipelined ones) + * - fb_state_pipelined (pipelined regs) + * The motivation behind this is to be able to emit a strict + * subset of the regs, and to have reasonable register ordering. */ + /* SC, GB (unpipelined), RB3D (unpipelined), ZB (unpipelined). */ + R300_INIT_ATOM(gpu_flush, 9); + R300_INIT_ATOM(aa_state, 4); + R300_INIT_ATOM(fb_state, 0); + R300_INIT_ATOM(hyperz_state, is_r500 || (is_rv350 && drm_2_6_0) ? 10 : 8); + /* ZB (unpipelined), SC. */ + R300_INIT_ATOM(ztop_state, 2); + /* ZB, FG. */ + R300_INIT_ATOM(dsa_state, is_r500 ? 8 : 6); + /* RB3D. */ + R300_INIT_ATOM(blend_state, 8); + R300_INIT_ATOM(blend_color_state, is_r500 ? 3 : 2); + /* SC. */ + R300_INIT_ATOM(scissor_state, 3); + /* GB, FG, GA, SU, SC, RB3D. */ + R300_INIT_ATOM(invariant_state, 16 + (is_rv350 ? 4 : 0)); + /* VAP. */ + R300_INIT_ATOM(viewport_state, 9); + R300_INIT_ATOM(pvs_flush, 2); + R300_INIT_ATOM(vap_invariant_state, 9); + R300_INIT_ATOM(vertex_stream_state, 0); + R300_INIT_ATOM(vs_state, 0); + R300_INIT_ATOM(vs_constants, 0); + R300_INIT_ATOM(clip_state, has_tcl ? 5 + (6 * 4) : 2); + /* VAP, RS, GA, GB, SU, SC. */ + R300_INIT_ATOM(rs_block_state, 0); + R300_INIT_ATOM(rs_state, 0); + /* SC, US. */ + R300_INIT_ATOM(fb_state_pipelined, 5 + (drm_2_3_0 ? 3 : 0)); + /* US. */ + R300_INIT_ATOM(fs, 0); + R300_INIT_ATOM(fs_rc_constant_state, 0); + R300_INIT_ATOM(fs_constants, 0); + /* TX. */ + R300_INIT_ATOM(texture_cache_inval, 2); + R300_INIT_ATOM(textures_state, 0); + if (can_hyperz) { + /* HiZ Clear */ + if (has_hiz_ram) + R300_INIT_ATOM(hiz_clear, 0); + /* zmask clear */ + R300_INIT_ATOM(zmask_clear, 0); + } + /* ZB (unpipelined), SU. */ + R300_INIT_ATOM(query_start, 4); + + /* Replace emission functions for r500. */ + if (is_r500) { + r300->fs.emit = r500_emit_fs; + r300->fs_rc_constant_state.emit = r500_emit_fs_rc_constant_state; + r300->fs_constants.emit = r500_emit_fs_constants; + } + + /* Some non-CSO atoms need explicit space to store the state locally. */ + R300_ALLOC_ATOM(aa_state, r300_aa_state); + R300_ALLOC_ATOM(blend_color_state, r300_blend_color_state); + R300_ALLOC_ATOM(clip_state, r300_clip_state); + R300_ALLOC_ATOM(hyperz_state, r300_hyperz_state); + R300_ALLOC_ATOM(invariant_state, r300_invariant_state); + R300_ALLOC_ATOM(textures_state, r300_textures_state); + R300_ALLOC_ATOM(vap_invariant_state, r300_vap_invariant_state); + R300_ALLOC_ATOM(viewport_state, r300_viewport_state); + R300_ALLOC_ATOM(ztop_state, r300_ztop_state); + R300_ALLOC_ATOM(fb_state, pipe_framebuffer_state); + R300_ALLOC_ATOM(gpu_flush, pipe_framebuffer_state); + R300_ALLOC_ATOM(scissor_state, pipe_scissor_state); + R300_ALLOC_ATOM(rs_block_state, r300_rs_block); + R300_ALLOC_ATOM(fs_constants, r300_constant_buffer); + R300_ALLOC_ATOM(vs_constants, r300_constant_buffer); + if (!r300->screen->caps.has_tcl) { + R300_ALLOC_ATOM(vertex_stream_state, r300_vertex_stream_state); + } + + /* Some non-CSO atoms don't use the state pointer. */ + r300->fb_state_pipelined.allow_null_state = TRUE; + r300->fs_rc_constant_state.allow_null_state = TRUE; + r300->pvs_flush.allow_null_state = TRUE; + r300->query_start.allow_null_state = TRUE; + r300->texture_cache_inval.allow_null_state = TRUE; + + /* Some states must be marked as dirty here to properly set up + * hardware in the first command stream. */ + r300_mark_atom_dirty(r300, &r300->invariant_state); + r300_mark_atom_dirty(r300, &r300->pvs_flush); + r300_mark_atom_dirty(r300, &r300->vap_invariant_state); + r300_mark_atom_dirty(r300, &r300->texture_cache_inval); + r300_mark_atom_dirty(r300, &r300->textures_state); + + return TRUE; +} + +/* Not every state tracker calls every driver function before the first draw + * call and we must initialize the command buffers somehow. */ +static void r300_init_states(struct pipe_context *pipe) +{ + struct r300_context *r300 = r300_context(pipe); + struct pipe_blend_color bc = {{0}}; + struct pipe_clip_state cs = {{{0}}}; + struct pipe_scissor_state ss = {0}; + struct r300_clip_state *clip = + (struct r300_clip_state*)r300->clip_state.state; + struct r300_gpu_flush *gpuflush = + (struct r300_gpu_flush*)r300->gpu_flush.state; + struct r300_vap_invariant_state *vap_invariant = + (struct r300_vap_invariant_state*)r300->vap_invariant_state.state; + struct r300_invariant_state *invariant = + (struct r300_invariant_state*)r300->invariant_state.state; + + CB_LOCALS; + + pipe->set_blend_color(pipe, &bc); + pipe->set_scissor_state(pipe, &ss); + + /* Initialize the clip state. */ + if (r300->screen->caps.has_tcl) { + pipe->set_clip_state(pipe, &cs); + } else { + BEGIN_CB(clip->cb, 2); + OUT_CB_REG(R300_VAP_CLIP_CNTL, R300_CLIP_DISABLE); + END_CB; + } + + /* Initialize the GPU flush. */ + { + BEGIN_CB(gpuflush->cb_flush_clean, 6); + + /* Flush and free renderbuffer caches. */ + OUT_CB_REG(R300_RB3D_DSTCACHE_CTLSTAT, + R300_RB3D_DSTCACHE_CTLSTAT_DC_FREE_FREE_3D_TAGS | + R300_RB3D_DSTCACHE_CTLSTAT_DC_FLUSH_FLUSH_DIRTY_3D); + OUT_CB_REG(R300_ZB_ZCACHE_CTLSTAT, + R300_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_FLUSH_AND_FREE | + R300_ZB_ZCACHE_CTLSTAT_ZC_FREE_FREE); + + /* Wait until the GPU is idle. + * This fixes random pixels sometimes appearing probably caused + * by incomplete rendering. */ + OUT_CB_REG(RADEON_WAIT_UNTIL, RADEON_WAIT_3D_IDLECLEAN); + END_CB; + } + + /* Initialize the VAP invariant state. */ + { + BEGIN_CB(vap_invariant->cb, 9); + OUT_CB_REG(VAP_PVS_VTX_TIMEOUT_REG, 0xffff); + OUT_CB_REG_SEQ(R300_VAP_GB_VERT_CLIP_ADJ, 4); + OUT_CB_32F(1.0); + OUT_CB_32F(1.0); + OUT_CB_32F(1.0); + OUT_CB_32F(1.0); + OUT_CB_REG(R300_VAP_PSC_SGN_NORM_CNTL, R300_SGN_NORM_NO_ZERO); + END_CB; + } + + /* Initialize the invariant state. */ + { + BEGIN_CB(invariant->cb, r300->invariant_state.size); + OUT_CB_REG(R300_GB_SELECT, 0); + OUT_CB_REG(R300_FG_FOG_BLEND, 0); + OUT_CB_REG(R300_GA_ROUND_MODE, 1); + OUT_CB_REG(R300_GA_OFFSET, 0); + OUT_CB_REG(R300_SU_TEX_WRAP, 0); + OUT_CB_REG(R300_SU_DEPTH_SCALE, 0x4B7FFFFF); + OUT_CB_REG(R300_SU_DEPTH_OFFSET, 0); + OUT_CB_REG(R300_SC_EDGERULE, 0x2DA49525); + + if (r300->screen->caps.is_rv350) { + OUT_CB_REG(R500_RB3D_DISCARD_SRC_PIXEL_LTE_THRESHOLD, 0x01010101); + OUT_CB_REG(R500_RB3D_DISCARD_SRC_PIXEL_GTE_THRESHOLD, 0xFEFEFEFE); + } + END_CB; + } + + /* Initialize the hyperz state. */ + { + struct r300_hyperz_state *hyperz = + (struct r300_hyperz_state*)r300->hyperz_state.state; + BEGIN_CB(&hyperz->cb_flush_begin, r300->hyperz_state.size); + OUT_CB_REG(R300_ZB_ZCACHE_CTLSTAT, + R300_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_FLUSH_AND_FREE); + OUT_CB_REG(R300_ZB_BW_CNTL, 0); + OUT_CB_REG(R300_ZB_DEPTHCLEARVALUE, 0); + OUT_CB_REG(R300_SC_HYPERZ, R300_SC_HYPERZ_ADJ_2); + + if (r300->screen->caps.is_r500 || + (r300->screen->caps.is_rv350 && + r300->rws->get_value(r300->rws, R300_VID_DRM_2_6_0))) { + OUT_CB_REG(R300_GB_Z_PEQ_CONFIG, 0); + } + END_CB; + } +} + +struct pipe_context* r300_create_context(struct pipe_screen* screen, + void *priv) +{ + struct r300_context* r300 = CALLOC_STRUCT(r300_context); + struct r300_screen* r300screen = r300_screen(screen); + struct r300_winsys_screen *rws = r300screen->rws; + + if (!r300) + return NULL; + + r300_update_num_contexts(r300screen, 1); + + r300->rws = rws; + r300->screen = r300screen; + + r300->context.winsys = (struct pipe_winsys*)rws; + r300->context.screen = screen; + r300->context.priv = priv; + + r300->context.destroy = r300_destroy_context; + + make_empty_list(&r300->query_list); + + util_slab_create(&r300->pool_transfers, + sizeof(struct pipe_transfer), 64, + UTIL_SLAB_SINGLETHREADED); + + r300->cs = rws->cs_create(rws); + if (r300->cs == NULL) + goto fail; + + if (!r300screen->caps.has_tcl) { + /* Create a Draw. This is used for SW TCL. */ +#ifdef HAVE_LLVM + r300->gallivm = gallivm_create(); + r300->draw = draw_create_gallivm(&r300->context, r300->gallivm); +#else + r300->draw = draw_create(&r300->context); +#endif + if (r300->draw == NULL) + goto fail; + /* Enable our renderer. */ + draw_set_rasterize_stage(r300->draw, r300_draw_stage(r300)); + /* Disable converting points/lines to triangles. */ + draw_wide_line_threshold(r300->draw, 10000000.f); + draw_wide_point_threshold(r300->draw, 10000000.f); + } + + if (!r300_setup_atoms(r300)) + goto fail; + + r300_init_blit_functions(r300); + r300_init_flush_functions(r300); + r300_init_query_functions(r300); + r300_init_state_functions(r300); + r300_init_resource_functions(r300); + + r300->blitter = util_blitter_create(&r300->context); + if (r300->blitter == NULL) + goto fail; + + /* Render functions must be initialized after blitter. */ + r300_init_render_functions(r300); + + rws->cs_set_flush(r300->cs, r300_flush_cb, r300); + + /* setup hyper-z mm */ + if (r300->rws->get_value(r300->rws, R300_CAN_HYPERZ)) + if (!r300_hyperz_init_mm(r300)) + goto fail; + + r300->upload_ib = u_upload_create(&r300->context, + 32 * 1024, 16, + PIPE_BIND_INDEX_BUFFER); + + if (r300->upload_ib == NULL) + goto fail; + + r300->upload_vb = u_upload_create(&r300->context, + 128 * 1024, 16, + PIPE_BIND_VERTEX_BUFFER); + if (r300->upload_vb == NULL) + goto fail; + + r300->tran.translate_cache = translate_cache_create(); + if (r300->tran.translate_cache == NULL) + goto fail; + + r300_init_states(&r300->context); + + /* The KIL opcode needs the first texture unit to be enabled + * on r3xx-r4xx. In order to calm down the CS checker, we bind this + * dummy texture there. */ + if (!r300->screen->caps.is_r500) { + struct pipe_resource *tex; + struct pipe_resource rtempl = {{0}}; + struct pipe_sampler_view vtempl = {{0}}; + + rtempl.target = PIPE_TEXTURE_2D; + rtempl.format = PIPE_FORMAT_I8_UNORM; + rtempl.bind = PIPE_BIND_SAMPLER_VIEW; + rtempl.usage = PIPE_USAGE_IMMUTABLE; + rtempl.width0 = 1; + rtempl.height0 = 1; + rtempl.depth0 = 1; + tex = screen->resource_create(screen, &rtempl); + + u_sampler_view_default_template(&vtempl, tex, tex->format); + + r300->texkill_sampler = (struct r300_sampler_view*) + r300->context.create_sampler_view(&r300->context, tex, &vtempl); + + pipe_resource_reference(&tex, NULL); + } + + { + struct pipe_resource vb = {}; + vb.target = PIPE_BUFFER; + vb.format = PIPE_FORMAT_R8_UNORM; + vb.bind = PIPE_BIND_VERTEX_BUFFER; + vb.usage = PIPE_USAGE_IMMUTABLE; + vb.width0 = sizeof(float) * 16; + vb.height0 = 1; + vb.depth0 = 1; + + r300->dummy_vb = screen->resource_create(screen, &vb); + } + + return &r300->context; + + fail: + r300_destroy_context(&r300->context); + return NULL; +} + +void r300_finish(struct r300_context *r300) +{ + struct pipe_framebuffer_state *fb; + unsigned i; + + /* This is a preliminary implementation of glFinish. + * + * The ideal implementation should use something like EmitIrqLocked and + * WaitIrq, or better, real fences. + */ + if (r300->fb_state.state) { + fb = r300->fb_state.state; + + for (i = 0; i < fb->nr_cbufs; i++) { + if (fb->cbufs[i]->texture) { + r300->rws->buffer_wait(r300->rws, + r300_texture(fb->cbufs[i]->texture)->buffer); + return; + } + } + if (fb->zsbuf && fb->zsbuf->texture) { + r300->rws->buffer_wait(r300->rws, + r300_texture(fb->zsbuf->texture)->buffer); + } + } +} diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h new file mode 100644 index 0000000..c719c02 --- /dev/null +++ b/src/gallium/drivers/r300/r300_context.h @@ -0,0 +1,747 @@ +/* + * 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 R300_CONTEXT_H +#define R300_CONTEXT_H + +#include "draw/draw_vertex.h" + +#include "util/u_blitter.h" + +#include "pipe/p_context.h" +#include "util/u_inlines.h" +#include "util/u_transfer.h" + +#include "translate/translate_cache.h" + +#include "r300_defines.h" +#include "r300_screen.h" + +struct u_upload_mgr; +struct r300_context; +struct r300_fragment_shader; +struct r300_vertex_shader; +struct r300_stencilref_context; + +struct r300_atom { + /* Name, for debugging. */ + const char* name; + /* Opaque state. */ + void* state; + /* Emit the state to the context. */ + void (*emit)(struct r300_context*, unsigned, void*); + /* Upper bound on number of dwords to emit. */ + unsigned size; + /* Whether this atom should be emitted. */ + boolean dirty; + /* Whether this atom may be emitted with state == NULL. */ + boolean allow_null_state; +}; + +struct r300_aa_state { + struct r300_surface *dest; + + uint32_t aa_config; + uint32_t aaresolve_ctl; +}; + +struct r300_blend_state { + uint32_t cb[8]; + uint32_t cb_no_readwrite[8]; +}; + +struct r300_blend_color_state { + uint32_t cb[3]; +}; + +struct r300_clip_state { + struct pipe_clip_state clip; + + uint32_t cb[29]; +}; + +struct r300_dsa_state { + struct pipe_depth_stencil_alpha_state dsa; + + /* This is actually a command buffer with named dwords. */ + uint32_t cb_begin; + uint32_t alpha_function; /* R300_FG_ALPHA_FUNC: 0x4bd4 */ + uint32_t cb_reg_seq; + uint32_t z_buffer_control; /* R300_ZB_CNTL: 0x4f00 */ + uint32_t z_stencil_control; /* R300_ZB_ZSTENCILCNTL: 0x4f04 */ + uint32_t stencil_ref_mask; /* R300_ZB_STENCILREFMASK: 0x4f08 */ + uint32_t cb_reg; + uint32_t stencil_ref_bf; /* R500_ZB_STENCILREFMASK_BF: 0x4fd4 */ + + /* The second command buffer disables zbuffer reads and writes. */ + uint32_t cb_no_readwrite[8]; + + /* Whether a two-sided stencil is enabled. */ + boolean two_sided; + /* Whether a fallback should be used for a two-sided stencil ref value. */ + boolean two_sided_stencil_ref; +}; + +struct r300_hyperz_state { + int current_func; /* -1 after a clear before first op */ + int flush; + /* This is actually a command buffer with named dwords. */ + uint32_t cb_flush_begin; + uint32_t zb_zcache_ctlstat; /* R300_ZB_CACHE_CNTL */ + uint32_t cb_begin; + uint32_t zb_bw_cntl; /* R300_ZB_BW_CNTL */ + uint32_t cb_reg1; + uint32_t zb_depthclearvalue; /* R300_ZB_DEPTHCLEARVALUE */ + uint32_t cb_reg2; + uint32_t sc_hyperz; /* R300_SC_HYPERZ */ + uint32_t cb_reg3; + uint32_t gb_z_peq_config; /* R300_GB_Z_PEQ_CONFIG: 0x4028 */ +}; + +struct r300_gpu_flush { + uint32_t cb_flush_clean[6]; +}; + +#define RS_STATE_MAIN_SIZE 23 + +struct r300_rs_state { + /* Original rasterizer state. */ + struct pipe_rasterizer_state rs; + /* Draw-specific rasterizer state. */ + struct pipe_rasterizer_state rs_draw; + + /* Command buffers. */ + uint32_t cb_main[RS_STATE_MAIN_SIZE]; + uint32_t cb_poly_offset_zb16[5]; + uint32_t cb_poly_offset_zb24[5]; + + /* The index to cb_main where the cull_mode register value resides. */ + unsigned cull_mode_index; + + /* Whether polygon offset is enabled. */ + boolean polygon_offset_enable; + + /* This is emitted in the draw function. */ + uint32_t color_control; /* R300_GA_COLOR_CONTROL: 0x4278 */ +}; + +struct r300_rs_block { + uint32_t vap_vtx_state_cntl; /* R300_VAP_VTX_STATE_CNTL: 0x2180 */ + uint32_t vap_vsm_vtx_assm; /* R300_VAP_VSM_VTX_ASSM: 0x2184 */ + uint32_t vap_out_vtx_fmt[2]; /* R300_VAP_OUTPUT_VTX_FMT_[0-1]: 0x2090 */ + uint32_t gb_enable; + + uint32_t ip[8]; /* R300_RS_IP_[0-7], R500_RS_IP_[0-7] */ + uint32_t count; /* R300_RS_COUNT */ + uint32_t inst_count; /* R300_RS_INST_COUNT */ + uint32_t inst[8]; /* R300_RS_INST_[0-7] */ +}; + +struct r300_sampler_state { + struct pipe_sampler_state state; + + uint32_t filter0; /* R300_TX_FILTER0: 0x4400 */ + uint32_t filter1; /* R300_TX_FILTER1: 0x4440 */ + + /* Min/max LOD must be clamped to [0, last_level], thus + * it's dependent on a currently bound texture */ + unsigned min_lod, max_lod; +}; + +struct r300_texture_format_state { + uint32_t format0; /* R300_TX_FORMAT0: 0x4480 */ + uint32_t format1; /* R300_TX_FORMAT1: 0x44c0 */ + uint32_t format2; /* R300_TX_FORMAT2: 0x4500 */ + uint32_t tile_config; /* R300_TX_OFFSET (subset thereof) */ +}; + +struct r300_sampler_view { + struct pipe_sampler_view base; + + /* Swizzles in the UTIL_FORMAT_SWIZZLE_* representation, + * derived from base. */ + unsigned char swizzle[4]; + + /* Copy of r300_texture::texture_format_state with format-specific bits + * added. */ + struct r300_texture_format_state format; + + /* The texture cache region for this texture. */ + uint32_t texcache_region; +}; + +struct r300_texture_fb_state { + uint32_t pitch[R300_MAX_TEXTURE_LEVELS]; /* COLORPITCH or DEPTHPITCH. */ + uint32_t format; /* US_OUT_FMT or R300_ZB_FORMAT */ +}; + +struct r300_texture_sampler_state { + struct r300_texture_format_state format; + uint32_t filter0; /* R300_TX_FILTER0: 0x4400 */ + uint32_t filter1; /* R300_TX_FILTER1: 0x4440 */ + uint32_t border_color; /* R300_TX_BORDER_COLOR: 0x45c0 */ +}; + +struct r300_textures_state { + /* Textures. */ + struct r300_sampler_view *sampler_views[16]; + int sampler_view_count; + /* Sampler states. */ + struct r300_sampler_state *sampler_states[16]; + int sampler_state_count; + + /* This is the merge of the texture and sampler states. */ + unsigned count; + uint32_t tx_enable; /* R300_TX_ENABLE: 0x4101 */ + struct r300_texture_sampler_state regs[16]; +}; + +struct r300_vertex_stream_state { + /* R300_VAP_PROG_STREAK_CNTL_[0-7] */ + uint32_t vap_prog_stream_cntl[8]; + /* R300_VAP_PROG_STREAK_CNTL_EXT_[0-7] */ + uint32_t vap_prog_stream_cntl_ext[8]; + + unsigned count; +}; + +struct r300_invariant_state { + uint32_t cb[20]; +}; + +struct r300_vap_invariant_state { + uint32_t cb[9]; +}; + +struct r300_viewport_state { + float xscale; /* R300_VAP_VPORT_XSCALE: 0x2098 */ + float xoffset; /* R300_VAP_VPORT_XOFFSET: 0x209c */ + float yscale; /* R300_VAP_VPORT_YSCALE: 0x20a0 */ + float yoffset; /* R300_VAP_VPORT_YOFFSET: 0x20a4 */ + float zscale; /* R300_VAP_VPORT_ZSCALE: 0x20a8 */ + float zoffset; /* R300_VAP_VPORT_ZOFFSET: 0x20ac */ + uint32_t vte_control; /* R300_VAP_VTE_CNTL: 0x20b0 */ +}; + +struct r300_ztop_state { + uint32_t z_buffer_top; /* R300_ZB_ZTOP: 0x4f14 */ +}; + +/* The next several objects are not pure Radeon state; they inherit from + * various Gallium classes. */ + +struct r300_constant_buffer { + /* Buffer of constants */ + uint32_t *ptr; + /* Remapping table. */ + unsigned *remap_table; + /* const buffer base */ + uint32_t buffer_base; +}; + +/* Query object. + * + * This is not a subclass of pipe_query because pipe_query is never + * actually fully defined. So, rather than have it as a member, and do + * subclass-style casting, we treat pipe_query as an opaque, and just + * trust that our state tracker does not ever mess up query objects. + */ +struct r300_query { + /* The kind of query. Currently only OQ is supported. */ + unsigned type; + /* The number of pipes where query results are stored. */ + unsigned num_pipes; + /* How many results have been written, in dwords. It's incremented + * after end_query and flush. */ + unsigned num_results; + /* if we've flushed the query */ + boolean flushed; + /* if begin has been emitted */ + boolean begin_emitted; + + /* The buffer where query results are stored. */ + struct r300_winsys_buffer *buffer; + struct r300_winsys_cs_buffer *cs_buffer; + /* The size of the buffer. */ + unsigned buffer_size; + /* The domain of the buffer. */ + enum r300_buffer_domain domain; + + /* Linked list members. */ + struct r300_query* prev; + struct r300_query* next; +}; + +/* Fence object. + * + * This is a fake fence. Instead of syncing with the fence, we sync + * with the context, which is inefficient but compliant. + * + * This is not a subclass of pipe_fence_handle because pipe_fence_handle is + * never actually fully defined. So, rather than have it as a member, and do + * subclass-style casting, we treat pipe_fence_handle as an opaque, and just + * trust that our state tracker does not ever mess up fence objects. + */ +struct r300_fence { + struct pipe_reference reference; + struct r300_context *ctx; + boolean signalled; +}; + +struct r300_surface { + struct pipe_surface base; + + /* Winsys buffer backing the texture. */ + struct r300_winsys_buffer *buffer; + struct r300_winsys_cs_buffer *cs_buffer; + + enum r300_buffer_domain domain; + + uint32_t offset; /* COLOROFFSET or DEPTHOFFSET. */ + uint32_t pitch; /* COLORPITCH or DEPTHPITCH. */ + uint32_t format; /* US_OUT_FMT or ZB_FORMAT. */ + + /* Parameters dedicated to the CBZB clear. */ + uint32_t cbzb_width; /* Aligned width. */ + uint32_t cbzb_height; /* Half of the height. */ + uint32_t cbzb_midpoint_offset; /* DEPTHOFFSET. */ + uint32_t cbzb_pitch; /* DEPTHPITCH. */ + uint32_t cbzb_format; /* ZB_FORMAT. */ + + /* Whether the CBZB clear is allowed on the surface. */ + boolean cbzb_allowed; + +}; + +struct r300_texture_desc { + /* Parent class. */ + struct u_resource b; + + /* Width, height, and depth. + * Most of the time, these are equal to pipe_texture::width0, height0, + * and depth0. However, NPOT 3D textures must have dimensions aligned + * to POT, and this is the only case when these variables differ from + * pipe_texture. */ + unsigned width0, height0, depth0; + + /* Buffer tiling. + * Macrotiling is specified per-level because small mipmaps cannot + * be macrotiled. */ + enum r300_buffer_tiling microtile; + enum r300_buffer_tiling macrotile[R300_MAX_TEXTURE_LEVELS]; + + /* Offsets into the buffer. */ + unsigned offset_in_bytes[R300_MAX_TEXTURE_LEVELS]; + + /* Strides for each mip-level. */ + unsigned stride_in_pixels[R300_MAX_TEXTURE_LEVELS]; + unsigned stride_in_bytes[R300_MAX_TEXTURE_LEVELS]; + + /* Size of one zslice or face or 2D image based on the texture target. */ + unsigned layer_size_in_bytes[R300_MAX_TEXTURE_LEVELS]; + + /* Total size of this texture, in bytes, + * derived from the texture properties. */ + unsigned size_in_bytes; + + /* Total size of the buffer backing this texture, in bytes. + * It must be >= size. */ + unsigned buffer_size_in_bytes; + + /** + * If non-zero, override the natural texture layout with + * a custom stride (in bytes). + * + * \note Mipmapping fails for textures with a non-natural layout! + * + * \sa r300_texture_get_stride + */ + unsigned stride_in_bytes_override; + + /* Whether this texture has non-power-of-two dimensions. + * It can be either a regular texture or a rectangle one. */ + boolean is_npot; + + /* This flag says that hardware must use the stride for addressing + * instead of the width. */ + boolean uses_stride_addressing; + + /* Whether CBZB fast color clear is allowed on the miplevel. */ + boolean cbzb_allowed[R300_MAX_TEXTURE_LEVELS]; +}; + +struct r300_texture { + struct r300_texture_desc desc; + + enum r300_buffer_domain domain; + + /* Pipe buffer backing this texture. */ + struct r300_winsys_buffer *buffer; + struct r300_winsys_cs_buffer *cs_buffer; + + /* Registers carrying texture format data. */ + /* Only format-independent bits should be filled in. */ + struct r300_texture_format_state tx_format; + /* All bits should be filled in. */ + struct r300_texture_fb_state fb_state; + + /* hyper-z memory allocs */ + struct mem_block *hiz_mem[R300_MAX_TEXTURE_LEVELS]; + struct mem_block *zmask_mem[R300_MAX_TEXTURE_LEVELS]; + boolean zmask_in_use[R300_MAX_TEXTURE_LEVELS]; + boolean hiz_in_use[R300_MAX_TEXTURE_LEVELS]; + + /* This is the level tiling flags were last time set for. + * It's used to prevent redundant tiling-flags changes from happening.*/ + unsigned surface_level; +}; + +struct r300_vertex_element_state { + unsigned count; + struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS]; + + /* If (velem[i].src_format != hw_format[i]), the vertex buffer + * referenced by this vertex element cannot be used for rendering and + * its vertex data must be translated to hw_format[i]. */ + enum pipe_format hw_format[PIPE_MAX_ATTRIBS]; + unsigned hw_format_size[PIPE_MAX_ATTRIBS]; + + /* The size of the vertex, in dwords. */ + unsigned vertex_size_dwords; + + /* This might mean two things: + * - src_format != hw_format, as discussed above. + * - src_offset % 4 != 0. */ + boolean incompatible_layout; + + struct r300_vertex_stream_state vertex_stream; +}; + +struct r300_translate_context { + /* Translate cache for incompatible vertex offset/stride/format fallback. */ + struct translate_cache *translate_cache; + + /* The vertex buffer slot containing the translated buffer. */ + unsigned vb_slot; + + /* Saved and new vertex element state. */ + void *saved_velems, *new_velems; +}; + +struct r300_context { + /* Parent class */ + struct pipe_context context; + + /* The interface to the windowing system, etc. */ + struct r300_winsys_screen *rws; + /* The command stream. */ + struct r300_winsys_cs *cs; + /* Screen. */ + struct r300_screen *screen; + + /* Draw module. Used mostly for SW TCL. */ + struct gallivm_state *gallivm; + struct draw_context* draw; + /* Vertex buffer for SW TCL. */ + struct pipe_resource* vbo; + /* Offset and size into the SW TCL VBO. */ + size_t draw_vbo_offset; + size_t draw_vbo_size; + /* Whether the VBO must not be flushed. */ + boolean draw_vbo_locked; + boolean draw_first_emitted; + + /* Accelerated blit support. */ + struct blitter_context* blitter; + /* Stencil two-sided reference value fallback. */ + struct r300_stencilref_context *stencilref_fallback; + /* For translating vertex buffers having incompatible vertex layout. */ + struct r300_translate_context tran; + + /* The KIL opcode needs the first texture unit to be enabled + * on r3xx-r4xx. In order to calm down the CS checker, we bind this + * dummy texture there. */ + struct r300_sampler_view *texkill_sampler; + + /* When no vertex buffer is set, this one is used instead to prevent + * hardlocks. */ + struct pipe_resource *dummy_vb; + + /* The currently active query. */ + struct r300_query *query_current; + /* The saved query for blitter operations. */ + struct r300_query *blitter_saved_query; + /* Query list. */ + struct r300_query query_list; + + /* Various CSO state objects. */ + + /* Each atom is emitted in the order it appears here, which can affect + * performance and stability if not handled with care. */ + /* GPU flush. */ + struct r300_atom gpu_flush; + /* Anti-aliasing (MSAA) state. */ + struct r300_atom aa_state; + /* Framebuffer state. */ + struct r300_atom fb_state; + /* HyperZ state (various SC/ZB bits). */ + struct r300_atom hyperz_state; + /* ZTOP state. */ + struct r300_atom ztop_state; + /* Depth, stencil, and alpha state. */ + struct r300_atom dsa_state; + /* Blend state. */ + struct r300_atom blend_state; + /* Blend color state. */ + struct r300_atom blend_color_state; + /* Scissor state. */ + struct r300_atom scissor_state; + /* Invariant state. This must be emitted to get the engine started. */ + struct r300_atom invariant_state; + /* Viewport state. */ + struct r300_atom viewport_state; + /* PVS flush. */ + struct r300_atom pvs_flush; + /* VAP invariant state. */ + struct r300_atom vap_invariant_state; + /* Vertex stream formatting state. */ + struct r300_atom vertex_stream_state; + /* Vertex shader. */ + struct r300_atom vs_state; + /* User clip planes. */ + struct r300_atom clip_state; + /* RS block state + VAP (vertex shader) output mapping state. */ + struct r300_atom rs_block_state; + /* Rasterizer state. */ + struct r300_atom rs_state; + /* Framebuffer state (pipelined regs). */ + struct r300_atom fb_state_pipelined; + /* Fragment shader. */ + struct r300_atom fs; + /* Fragment shader RC_CONSTANT_STATE variables. */ + struct r300_atom fs_rc_constant_state; + /* Fragment shader constant buffer. */ + struct r300_atom fs_constants; + /* Vertex shader constant buffer. */ + struct r300_atom vs_constants; + /* Texture cache invalidate. */ + struct r300_atom texture_cache_inval; + /* Textures state. */ + struct r300_atom textures_state; + /* HiZ clear */ + struct r300_atom hiz_clear; + /* zmask clear */ + struct r300_atom zmask_clear; + /* Occlusion query. */ + struct r300_atom query_start; + + /* The pointers to the first and the last atom. */ + struct r300_atom *first_dirty, *last_dirty; + + /* Vertex buffers for Gallium. */ + struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; + int vertex_buffer_count; + int vertex_buffer_max_index; + /* Vertex elements for Gallium. */ + struct r300_vertex_element_state *velems; + bool any_user_vbs; + + struct pipe_index_buffer index_buffer; + + /* Vertex info for Draw. */ + struct vertex_info vertex_info; + + struct pipe_stencil_ref stencil_ref; + struct pipe_viewport_state viewport; + + /* Stream locations for SWTCL. */ + int stream_loc_notcl[16]; + + /* Flag indicating whether or not the HW is dirty. */ + uint32_t dirty_hw; + /* Whether polygon offset is enabled. */ + boolean polygon_offset_enabled; + /* Z buffer bit depth. */ + uint32_t zbuffer_bpp; + /* Whether rendering is conditional and should be skipped. */ + boolean skip_rendering; + /* Point sprites texcoord index, 1 bit per texcoord */ + int sprite_coord_enable; + /* Whether two-sided color selection is enabled (AKA light_twoside). */ + boolean two_sided_color; + /* Incompatible vertex buffer layout? (misaligned stride or buffer_offset) */ + boolean incompatible_vb_layout; +#define R300_Z_COMPRESS_44 1 +#define RV350_Z_COMPRESS_88 2 + int z_compression; + boolean cbzb_clear; + boolean z_decomp_rd; + + /* two mem block managers for hiz/zmask ram space */ + struct mem_block *hiz_mm; + struct mem_block *zmask_mm; + + /* upload managers */ + struct u_upload_mgr *upload_vb; + struct u_upload_mgr *upload_ib; + + struct util_slab_mempool pool_transfers; + + /* Stat counter. */ + uint64_t flush_counter; + + /* const tracking for VS */ + int vs_const_base; + + /* AOS (PACKET3_3D_LOAD_VBPNTR) command buffer for the case offset=0. */ + uint32_t aos_cb[(16 * 3 + 1) / 2]; + boolean aos_dirty; + + /* Whether any buffer (FB, textures, VBOs) has been set, but buffers + * haven't been validated yet. */ + boolean validate_buffers; +}; + +#define foreach_atom(r300, atom) \ + for (atom = &r300->gpu_flush; atom != (&r300->query_start)+1; atom++) + +#define foreach_dirty_atom(r300, atom) \ + for (atom = r300->first_dirty; atom != r300->last_dirty; atom++) + +/* Convenience cast wrappers. */ +static INLINE struct r300_query* r300_query(struct pipe_query* q) +{ + return (struct r300_query*)q; +} + +static INLINE struct r300_surface* r300_surface(struct pipe_surface* surf) +{ + return (struct r300_surface*)surf; +} + +static INLINE struct r300_texture* r300_texture(struct pipe_resource* tex) +{ + return (struct r300_texture*)tex; +} + +static INLINE struct r300_context* r300_context(struct pipe_context* context) +{ + return (struct r300_context*)context; +} + +static INLINE struct r300_fragment_shader *r300_fs(struct r300_context *r300) +{ + return (struct r300_fragment_shader*)r300->fs.state; +} + +struct pipe_context* r300_create_context(struct pipe_screen* screen, + void *priv); + +void r300_finish(struct r300_context *r300); +void r300_flush_cb(void *data); + +/* Context initialization. */ +struct draw_stage* r300_draw_stage(struct r300_context* r300); +void r300_init_blit_functions(struct r300_context *r300); +void r300_init_flush_functions(struct r300_context* r300); +void r300_init_query_functions(struct r300_context* r300); +void r300_init_render_functions(struct r300_context *r300); +void r300_init_state_functions(struct r300_context* r300); +void r300_init_resource_functions(struct r300_context* r300); + +/* r300_blit.c */ +void r300_flush_depth_stencil(struct pipe_context *pipe, + struct pipe_resource *dst, + unsigned level, + unsigned layer); + +/* r300_query.c */ +void r300_resume_query(struct r300_context *r300, + struct r300_query *query); +void r300_stop_query(struct r300_context *r300); + +/* r300_render_translate.c */ +void r300_begin_vertex_translate(struct r300_context *r300); +void r300_end_vertex_translate(struct r300_context *r300); +void r300_translate_index_buffer(struct r300_context *r300, + struct pipe_resource **index_buffer, + unsigned *index_size, unsigned index_offset, + unsigned *start, unsigned count); + +/* r300_render_stencilref.c */ +void r300_plug_in_stencil_ref_fallback(struct r300_context *r300); + +/* r300_render.c */ +void r300_draw_flush_vbuf(struct r300_context *r300); +void r500_emit_index_bias(struct r300_context *r300, int index_bias); + +/* r300_state.c */ +enum r300_fb_state_change { + R300_CHANGED_FB_STATE = 0, + R300_CHANGED_CBZB_FLAG, + R300_CHANGED_ZCLEAR_FLAG +}; + +void r300_mark_fb_state_dirty(struct r300_context *r300, + enum r300_fb_state_change change); +void r300_mark_fs_code_dirty(struct r300_context *r300); + +static INLINE void r300_mark_atom_dirty(struct r300_context *r300, + struct r300_atom *atom) +{ + atom->dirty = TRUE; + + if (!r300->first_dirty) { + r300->first_dirty = atom; + r300->last_dirty = atom+1; + } else { + if (atom < r300->first_dirty) + r300->first_dirty = atom; + if (atom+1 > r300->last_dirty) + r300->last_dirty = atom+1; + } +} + +/* r300_debug.c */ +void r500_dump_rs_block(struct r300_rs_block *rs); + + +static INLINE boolean CTX_DBG_ON(struct r300_context * ctx, unsigned flags) +{ + return SCREEN_DBG_ON(ctx->screen, flags); +} + +static INLINE void CTX_DBG(struct r300_context * ctx, unsigned flags, + const char * fmt, ...) +{ + if (CTX_DBG_ON(ctx, flags)) { + va_list va; + va_start(va, fmt); + vfprintf(stderr, fmt, va); + va_end(va); + } +} + +#define DBG_ON CTX_DBG_ON +#define DBG CTX_DBG + +#endif /* R300_CONTEXT_H */ diff --git a/src/gallium/drivers/r300/r300_cs.h b/src/gallium/drivers/r300/r300_cs.h new file mode 100644 index 0000000..67fb009 --- /dev/null +++ b/src/gallium/drivers/r300/r300_cs.h @@ -0,0 +1,143 @@ +/* + * 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. */ + +/** + * This file contains macros for immediate command submission. + */ + +#ifndef R300_CS_H +#define R300_CS_H + +#include "r300_reg.h" +#include "r300_context.h" +#include "r300_winsys.h" + +/* Yes, I know macros are ugly. However, they are much prettier than the code + * that they neatly hide away, and don't have the cost of function setup,so + * we're going to use them. */ + +#ifdef DEBUG +#define CS_DEBUG(x) x +#else +#define CS_DEBUG(x) +#endif + +/** + * Command submission setup. + */ + +#define CS_LOCALS(context) \ + struct r300_winsys_cs *cs_copy = (context)->cs; \ + struct r300_winsys_screen *cs_winsys = (context)->rws; \ + int cs_count = 0; (void) cs_count; (void) cs_winsys; + +#define BEGIN_CS(size) do { \ + assert(size <= (R300_MAX_CMDBUF_DWORDS - cs_copy->cdw)); \ + CS_DEBUG(cs_count = size;) \ +} while (0) + +#ifdef DEBUG +#define END_CS do { \ + if (cs_count != 0) \ + debug_printf("r300: Warning: cs_count off by %d at (%s, %s:%i)\n", \ + cs_count, __FUNCTION__, __FILE__, __LINE__); \ + cs_count = 0; \ +} while (0) +#else +#define END_CS +#endif + + +/** + * Writing pure DWORDs. + */ + +#define OUT_CS(value) do { \ + cs_copy->buf[cs_copy->cdw++] = (value); \ + CS_DEBUG(cs_count--;) \ +} while (0) + +#define OUT_CS_32F(value) \ + OUT_CS(fui(value)) + +#define OUT_CS_REG(register, value) do { \ + OUT_CS(CP_PACKET0(register, 0)); \ + OUT_CS(value); \ +} while (0) + +/* Note: This expects count to be the number of registers, + * not the actual packet0 count! */ +#define OUT_CS_REG_SEQ(register, count) \ + OUT_CS(CP_PACKET0((register), ((count) - 1))) + +#define OUT_CS_ONE_REG(register, count) \ + OUT_CS(CP_PACKET0((register), ((count) - 1)) | RADEON_ONE_REG_WR) + +#define OUT_CS_PKT3(op, count) \ + OUT_CS(CP_PACKET3(op, count)) + +#define OUT_CS_TABLE(values, count) do { \ + memcpy(cs_copy->buf + cs_copy->cdw, values, count * 4); \ + cs_copy->cdw += count; \ + CS_DEBUG(cs_count -= count;) \ +} while (0) + + +/** + * Writing relocations. + */ + +#define OUT_CS_RELOC(bo, offset, rd, wd) do { \ + assert(bo); \ + OUT_CS(offset); \ + cs_winsys->cs_write_reloc(cs_copy, bo, rd, wd); \ + CS_DEBUG(cs_count -= 2;) \ +} while (0) + +#define OUT_CS_BUF_RELOC(bo, offset, rd, wd) do { \ + assert(bo); \ + OUT_CS_RELOC(r300_buffer(bo)->cs_buf, offset, rd, wd); \ +} while (0) + +#define OUT_CS_TEX_RELOC(tex, offset, rd, wd) do { \ + assert(tex); \ + OUT_CS_RELOC(tex->cs_buffer, offset, rd, wd); \ +} while (0) + +#define OUT_CS_BUF_RELOC_NO_OFFSET(bo, rd, wd) do { \ + assert(bo); \ + cs_winsys->cs_write_reloc(cs_copy, r300_buffer(bo)->cs_buf, rd, wd); \ + CS_DEBUG(cs_count -= 2;) \ +} while (0) + + +/** + * Command buffer emission. + */ + +#define WRITE_CS_TABLE(values, count) do { \ + CS_DEBUG(assert(cs_count == 0);) \ + memcpy(cs_copy->buf + cs_copy->cdw, (values), (count) * 4); \ + cs_copy->cdw += (count); \ +} while (0) + +#endif /* R300_CS_H */ diff --git a/src/gallium/drivers/r300/r300_debug.c b/src/gallium/drivers/r300/r300_debug.c new file mode 100644 index 0000000..52031dd --- /dev/null +++ b/src/gallium/drivers/r300/r300_debug.c @@ -0,0 +1,140 @@ +/* + * Copyright 2009 Nicolai Haehnle + * + * 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 "r300_context.h" + +#include "util/u_debug.h" + +#include + +static const struct debug_named_value debug_options[] = { + { "fp", DBG_FP, "Log fragment program compilation" }, + { "vp", DBG_VP, "Log vertex program compilation" }, + { "pstat", DBG_P_STAT, "Log vertex/fragment program stats" }, + { "draw", DBG_DRAW, "Log draw calls" }, + { "swtcl", DBG_SWTCL, "Log SWTCL-specific info" }, + { "rsblock", DBG_RS_BLOCK, "Log rasterizer registers" }, + { "psc", DBG_PSC, "Log vertex stream registers" }, + { "tex", DBG_TEX, "Log basic info about textures" }, + { "texalloc", DBG_TEXALLOC, "Log texture mipmap tree info" }, + { "fall", DBG_FALL, "Log fallbacks" }, + { "rs", DBG_RS, "Log rasterizer" }, + { "fb", DBG_FB, "Log framebuffer" }, + { "cbzb", DBG_CBZB, "Log fast color clear info" }, + { "hyperz", DBG_HYPERZ, "Log HyperZ info" }, + { "scissor", DBG_SCISSOR, "Log scissor info" }, + { "fakeocc", DBG_FAKE_OCC, "Use fake occlusion queries" }, + { "anisohq", DBG_ANISOHQ, "Use high quality anisotropic filtering" }, + { "notiling", DBG_NO_TILING, "Disable tiling" }, + { "noimmd", DBG_NO_IMMD, "Disable immediate mode" }, + { "noopt", DBG_NO_OPT, "Disable shader optimizations" }, + { "nocbzb", DBG_NO_CBZB, "Disable fast color clear" }, + + /* must be last */ + DEBUG_NAMED_VALUE_END +}; + +void r300_init_debug(struct r300_screen * screen) +{ + screen->debug = debug_get_flags_option("RADEON_DEBUG", debug_options, 0); +} + +void r500_dump_rs_block(struct r300_rs_block *rs) +{ + unsigned count, ip, it_count, ic_count, i, j; + unsigned tex_ptr; + unsigned col_ptr, col_fmt; + + count = rs->inst_count & 0xf; + count++; + + it_count = rs->count & 0x7f; + ic_count = (rs->count >> 7) & 0xf; + + fprintf(stderr, "RS Block: %d texcoords (linear), %d colors (perspective)\n", + it_count, ic_count); + fprintf(stderr, "%d instructions\n", count); + + for (i = 0; i < count; i++) { + if (rs->inst[i] & 0x10) { + ip = rs->inst[i] & 0xf; + fprintf(stderr, "texture: ip %d to psf %d\n", + ip, (rs->inst[i] >> 5) & 0x7f); + + tex_ptr = rs->ip[ip] & 0xffffff; + fprintf(stderr, " : "); + + j = 3; + do { + if ((tex_ptr & 0x3f) == 63) { + fprintf(stderr, "1.0"); + } else if ((tex_ptr & 0x3f) == 62) { + fprintf(stderr, "0.0"); + } else { + fprintf(stderr, "[%d]", tex_ptr & 0x3f); + } + } while (j-- && fprintf(stderr, "/")); + fprintf(stderr, "\n"); + } + + if (rs->inst[i] & 0x10000) { + ip = (rs->inst[i] >> 12) & 0xf; + fprintf(stderr, "color: ip %d to psf %d\n", + ip, (rs->inst[i] >> 18) & 0x7f); + + col_ptr = (rs->ip[ip] >> 24) & 0x7; + col_fmt = (rs->ip[ip] >> 27) & 0xf; + fprintf(stderr, " : offset %d ", col_ptr); + + switch (col_fmt) { + case 0: + fprintf(stderr, "(R/G/B/A)"); + break; + case 1: + fprintf(stderr, "(R/G/B/0)"); + break; + case 2: + fprintf(stderr, "(R/G/B/1)"); + break; + case 4: + fprintf(stderr, "(0/0/0/A)"); + break; + case 5: + fprintf(stderr, "(0/0/0/0)"); + break; + case 6: + fprintf(stderr, "(0/0/0/1)"); + break; + case 8: + fprintf(stderr, "(1/1/1/A)"); + break; + case 9: + fprintf(stderr, "(1/1/1/0)"); + break; + case 10: + fprintf(stderr, "(1/1/1/1)"); + break; + } + fprintf(stderr, "\n"); + } + } +} diff --git a/src/gallium/drivers/r300/r300_defines.h b/src/gallium/drivers/r300/r300_defines.h new file mode 100644 index 0000000..2d111f9 --- /dev/null +++ b/src/gallium/drivers/r300/r300_defines.h @@ -0,0 +1,50 @@ +/* + * Copyright 2010 Marek Olšák + * + * 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 R300_DEFINES_H +#define R300_DEFINES_H + +#include "pipe/p_defines.h" + +#define R300_MAX_TEXTURE_LEVELS 13 +#define R300_MAX_DRAW_VBO_SIZE (1024 * 1024) + +#define R300_RESOURCE_FLAG_TRANSFER PIPE_RESOURCE_FLAG_DRV_PRIV + +#define R300_INVALID_FORMAT 0xffff + +/* Tiling flags. */ +enum r300_buffer_tiling { + R300_BUFFER_LINEAR = 0, + R300_BUFFER_TILED, + R300_BUFFER_SQUARETILED, + + R300_BUFFER_UNKNOWN, + R300_BUFFER_SELECT_LAYOUT = R300_BUFFER_UNKNOWN +}; + +enum r300_buffer_domain { /* bitfield */ + R300_DOMAIN_GTT = 2, + R300_DOMAIN_VRAM = 4 +}; + +#endif diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c new file mode 100644 index 0000000..972f58f --- /dev/null +++ b/src/gallium/drivers/r300/r300_emit.c @@ -0,0 +1,1329 @@ +/* + * Copyright 2008 Corbin Simpson + * Copyright 2009 Marek Olšák + * + * 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. */ + +/* r300_emit: Functions for emitting state. */ + +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_mm.h" +#include "util/u_simple_list.h" + +#include "r300_context.h" +#include "r300_cb.h" +#include "r300_cs.h" +#include "r300_emit.h" +#include "r300_fs.h" +#include "r300_screen.h" +#include "r300_screen_buffer.h" +#include "r300_vs.h" + +void r300_emit_blend_state(struct r300_context* r300, + unsigned size, void* state) +{ + struct r300_blend_state* blend = (struct r300_blend_state*)state; + struct pipe_framebuffer_state* fb = + (struct pipe_framebuffer_state*)r300->fb_state.state; + CS_LOCALS(r300); + + if (fb->nr_cbufs) { + WRITE_CS_TABLE(blend->cb, size); + } else { + WRITE_CS_TABLE(blend->cb_no_readwrite, size); + } +} + +void r300_emit_blend_color_state(struct r300_context* r300, + unsigned size, void* state) +{ + struct r300_blend_color_state* bc = (struct r300_blend_color_state*)state; + CS_LOCALS(r300); + + WRITE_CS_TABLE(bc->cb, size); +} + +void r300_emit_clip_state(struct r300_context* r300, + unsigned size, void* state) +{ + struct r300_clip_state* clip = (struct r300_clip_state*)state; + CS_LOCALS(r300); + + WRITE_CS_TABLE(clip->cb, size); +} + +void r300_emit_dsa_state(struct r300_context* r300, unsigned size, void* state) +{ + struct r300_dsa_state* dsa = (struct r300_dsa_state*)state; + struct pipe_framebuffer_state* fb = + (struct pipe_framebuffer_state*)r300->fb_state.state; + CS_LOCALS(r300); + + if (fb->zsbuf) { + WRITE_CS_TABLE(&dsa->cb_begin, size); + } else { + WRITE_CS_TABLE(dsa->cb_no_readwrite, size); + } +} + +static void get_rc_constant_state( + float vec[4], + struct r300_context * r300, + struct rc_constant * constant) +{ + struct r300_textures_state* texstate = r300->textures_state.state; + struct r300_texture *tex; + + assert(constant->Type == RC_CONSTANT_STATE); + + /* vec should either be (0, 0, 0, 1), which should be a relatively safe + * RGBA or STRQ value, or it could be one of the RC_CONSTANT_STATE + * state factors. */ + + switch (constant->u.State[0]) { + /* Factor for converting rectangle coords to + * normalized coords. Should only show up on non-r500. */ + case RC_STATE_R300_TEXRECT_FACTOR: + tex = r300_texture(texstate->sampler_views[constant->u.State[1]]->base.texture); + vec[0] = 1.0 / tex->desc.width0; + vec[1] = 1.0 / tex->desc.height0; + vec[2] = 0; + vec[3] = 1; + break; + + case RC_STATE_R300_TEXSCALE_FACTOR: + tex = r300_texture(texstate->sampler_views[constant->u.State[1]]->base.texture); + /* Add a small number to the texture size to work around rounding errors in hw. */ + vec[0] = tex->desc.b.b.width0 / (tex->desc.width0 + 0.001f); + vec[1] = tex->desc.b.b.height0 / (tex->desc.height0 + 0.001f); + vec[2] = tex->desc.b.b.depth0 / (tex->desc.depth0 + 0.001f); + vec[3] = 1; + break; + + case RC_STATE_R300_VIEWPORT_SCALE: + vec[0] = r300->viewport.scale[0]; + vec[1] = r300->viewport.scale[1]; + vec[2] = r300->viewport.scale[2]; + vec[3] = 1; + break; + + case RC_STATE_R300_VIEWPORT_OFFSET: + vec[0] = r300->viewport.translate[0]; + vec[1] = r300->viewport.translate[1]; + vec[2] = r300->viewport.translate[2]; + vec[3] = 1; + break; + + default: + fprintf(stderr, "r300: Implementation error: " + "Unknown RC_CONSTANT type %d\n", constant->u.State[0]); + vec[0] = 0; + vec[1] = 0; + vec[2] = 0; + vec[3] = 1; + } +} + +/* Convert a normal single-precision float into the 7.16 format + * used by the R300 fragment shader. + */ +uint32_t pack_float24(float f) +{ + union { + float fl; + uint32_t u; + } u; + float mantissa; + int exponent; + uint32_t float24 = 0; + + if (f == 0.0) + return 0; + + u.fl = f; + + mantissa = frexpf(f, &exponent); + + /* Handle -ve */ + if (mantissa < 0) { + float24 |= (1 << 23); + mantissa = mantissa * -1.0; + } + /* Handle exponent, bias of 63 */ + exponent += 62; + float24 |= (exponent << 16); + /* Kill 7 LSB of mantissa */ + float24 |= (u.u & 0x7FFFFF) >> 7; + + return float24; +} + +void r300_emit_fs(struct r300_context* r300, unsigned size, void *state) +{ + struct r300_fragment_shader *fs = r300_fs(r300); + CS_LOCALS(r300); + + WRITE_CS_TABLE(fs->shader->cb_code, fs->shader->cb_code_size); +} + +void r300_emit_fs_constants(struct r300_context* r300, unsigned size, void *state) +{ + struct r300_fragment_shader *fs = r300_fs(r300); + struct r300_constant_buffer *buf = (struct r300_constant_buffer*)state; + unsigned count = fs->shader->externals_count; + unsigned i, j; + CS_LOCALS(r300); + + if (count == 0) + return; + + BEGIN_CS(size); + OUT_CS_REG_SEQ(R300_PFS_PARAM_0_X, count * 4); + if (buf->remap_table){ + for (i = 0; i < count; i++) { + float *data = (float*)&buf->ptr[buf->remap_table[i]*4]; + for (j = 0; j < 4; j++) + OUT_CS(pack_float24(data[j])); + } + } else { + for (i = 0; i < count; i++) + for (j = 0; j < 4; j++) + OUT_CS(pack_float24(*(float*)&buf->ptr[i*4+j])); + } + + END_CS; +} + +void r300_emit_fs_rc_constant_state(struct r300_context* r300, unsigned size, void *state) +{ + struct r300_fragment_shader *fs = r300_fs(r300); + struct rc_constant_list *constants = &fs->shader->code.constants; + unsigned i; + unsigned count = fs->shader->rc_state_count; + unsigned first = fs->shader->externals_count; + unsigned end = constants->Count; + unsigned j; + CS_LOCALS(r300); + + if (count == 0) + return; + + BEGIN_CS(size); + for(i = first; i < end; ++i) { + if (constants->Constants[i].Type == RC_CONSTANT_STATE) { + float data[4]; + + get_rc_constant_state(data, r300, &constants->Constants[i]); + + OUT_CS_REG_SEQ(R300_PFS_PARAM_0_X + i * 16, 4); + for (j = 0; j < 4; j++) + OUT_CS(pack_float24(data[j])); + } + } + END_CS; +} + +void r500_emit_fs(struct r300_context* r300, unsigned size, void *state) +{ + struct r300_fragment_shader *fs = r300_fs(r300); + CS_LOCALS(r300); + + WRITE_CS_TABLE(fs->shader->cb_code, fs->shader->cb_code_size); +} + +void r500_emit_fs_constants(struct r300_context* r300, unsigned size, void *state) +{ + struct r300_fragment_shader *fs = r300_fs(r300); + struct r300_constant_buffer *buf = (struct r300_constant_buffer*)state; + unsigned count = fs->shader->externals_count; + CS_LOCALS(r300); + + if (count == 0) + return; + + BEGIN_CS(size); + OUT_CS_REG(R500_GA_US_VECTOR_INDEX, R500_GA_US_VECTOR_INDEX_TYPE_CONST); + OUT_CS_ONE_REG(R500_GA_US_VECTOR_DATA, count * 4); + if (buf->remap_table){ + for (unsigned i = 0; i < count; i++) { + uint32_t *data = &buf->ptr[buf->remap_table[i]*4]; + OUT_CS_TABLE(data, 4); + } + } else { + OUT_CS_TABLE(buf->ptr, count * 4); + } + END_CS; +} + +void r500_emit_fs_rc_constant_state(struct r300_context* r300, unsigned size, void *state) +{ + struct r300_fragment_shader *fs = r300_fs(r300); + struct rc_constant_list *constants = &fs->shader->code.constants; + unsigned i; + unsigned count = fs->shader->rc_state_count; + unsigned first = fs->shader->externals_count; + unsigned end = constants->Count; + CS_LOCALS(r300); + + if (count == 0) + return; + + BEGIN_CS(size); + for(i = first; i < end; ++i) { + if (constants->Constants[i].Type == RC_CONSTANT_STATE) { + float data[4]; + + get_rc_constant_state(data, r300, &constants->Constants[i]); + + OUT_CS_REG(R500_GA_US_VECTOR_INDEX, + R500_GA_US_VECTOR_INDEX_TYPE_CONST | + (i & R500_GA_US_VECTOR_INDEX_MASK)); + OUT_CS_ONE_REG(R500_GA_US_VECTOR_DATA, 4); + OUT_CS_TABLE(data, 4); + } + } + END_CS; +} + +void r300_emit_gpu_flush(struct r300_context *r300, unsigned size, void *state) +{ + struct r300_gpu_flush *gpuflush = (struct r300_gpu_flush*)state; + struct pipe_framebuffer_state* fb = + (struct pipe_framebuffer_state*)r300->fb_state.state; + uint32_t height = fb->height; + uint32_t width = fb->width; + CS_LOCALS(r300); + + if (r300->cbzb_clear) { + struct r300_surface *surf = r300_surface(fb->cbufs[0]); + + height = surf->cbzb_height; + width = surf->cbzb_width; + } + + DBG(r300, DBG_SCISSOR, + "r300: Scissor width: %i, height: %i, CBZB clear: %s\n", + width, height, r300->cbzb_clear ? "YES" : "NO"); + + BEGIN_CS(size); + + /* Set up scissors. + * By writing to the SC registers, SC & US assert idle. */ + OUT_CS_REG_SEQ(R300_SC_SCISSORS_TL, 2); + if (r300->screen->caps.is_r500) { + OUT_CS(0); + OUT_CS(((width - 1) << R300_SCISSORS_X_SHIFT) | + ((height - 1) << R300_SCISSORS_Y_SHIFT)); + } else { + OUT_CS((1440 << R300_SCISSORS_X_SHIFT) | + (1440 << R300_SCISSORS_Y_SHIFT)); + OUT_CS(((width + 1440-1) << R300_SCISSORS_X_SHIFT) | + ((height + 1440-1) << R300_SCISSORS_Y_SHIFT)); + } + + /* Flush CB & ZB caches and wait until the 3D engine is idle and clean. */ + OUT_CS_TABLE(gpuflush->cb_flush_clean, 6); + END_CS; +} + +void r300_emit_aa_state(struct r300_context *r300, unsigned size, void *state) +{ + struct r300_aa_state *aa = (struct r300_aa_state*)state; + CS_LOCALS(r300); + + BEGIN_CS(size); + OUT_CS_REG(R300_GB_AA_CONFIG, aa->aa_config); + + if (aa->dest) { + OUT_CS_REG_SEQ(R300_RB3D_AARESOLVE_OFFSET, 1); + OUT_CS_RELOC(aa->dest->cs_buffer, aa->dest->offset, 0, aa->dest->domain); + + OUT_CS_REG_SEQ(R300_RB3D_AARESOLVE_PITCH, 1); + OUT_CS_RELOC(aa->dest->cs_buffer, aa->dest->pitch, 0, aa->dest->domain); + } + + OUT_CS_REG(R300_RB3D_AARESOLVE_CTL, aa->aaresolve_ctl); + END_CS; +} + +void r300_emit_fb_state(struct r300_context* r300, unsigned size, void* state) +{ + struct pipe_framebuffer_state* fb = (struct pipe_framebuffer_state*)state; + struct r300_surface* surf; + unsigned i; + boolean can_hyperz = r300->rws->get_value(r300->rws, R300_CAN_HYPERZ); + CS_LOCALS(r300); + + BEGIN_CS(size); + + /* NUM_MULTIWRITES replicates COLOR[0] to all colorbuffers, which is not + * what we usually want. */ + if (r300->screen->caps.is_r500) { + OUT_CS_REG(R300_RB3D_CCTL, + R300_RB3D_CCTL_INDEPENDENT_COLORFORMAT_ENABLE_ENABLE); + } else { + OUT_CS_REG(R300_RB3D_CCTL, 0); + } + + /* Set up colorbuffers. */ + for (i = 0; i < fb->nr_cbufs; i++) { + surf = r300_surface(fb->cbufs[i]); + + OUT_CS_REG_SEQ(R300_RB3D_COLOROFFSET0 + (4 * i), 1); + OUT_CS_RELOC(surf->cs_buffer, surf->offset, 0, surf->domain); + + OUT_CS_REG_SEQ(R300_RB3D_COLORPITCH0 + (4 * i), 1); + OUT_CS_RELOC(surf->cs_buffer, surf->pitch, 0, surf->domain); + } + + /* Set up the ZB part of the CBZB clear. */ + if (r300->cbzb_clear) { + surf = r300_surface(fb->cbufs[0]); + + OUT_CS_REG(R300_ZB_FORMAT, surf->cbzb_format); + + OUT_CS_REG_SEQ(R300_ZB_DEPTHOFFSET, 1); + OUT_CS_RELOC(surf->cs_buffer, surf->cbzb_midpoint_offset, 0, surf->domain); + + OUT_CS_REG_SEQ(R300_ZB_DEPTHPITCH, 1); + OUT_CS_RELOC(surf->cs_buffer, surf->cbzb_pitch, 0, surf->domain); + + DBG(r300, DBG_CBZB, + "CBZB clearing cbuf %08x %08x\n", surf->cbzb_format, + surf->cbzb_pitch); + } + /* Set up a zbuffer. */ + else if (fb->zsbuf) { + surf = r300_surface(fb->zsbuf); + + OUT_CS_REG(R300_ZB_FORMAT, surf->format); + + OUT_CS_REG_SEQ(R300_ZB_DEPTHOFFSET, 1); + OUT_CS_RELOC(surf->cs_buffer, surf->offset, 0, surf->domain); + + OUT_CS_REG_SEQ(R300_ZB_DEPTHPITCH, 1); + OUT_CS_RELOC(surf->cs_buffer, surf->pitch, 0, surf->domain); + + if (can_hyperz) { + uint32_t surf_pitch; + struct r300_texture *tex; + int level = surf->base.u.tex.level; + tex = r300_texture(surf->base.texture); + + surf_pitch = surf->pitch & R300_DEPTHPITCH_MASK; + /* HiZ RAM. */ + if (r300->screen->caps.hiz_ram) { + if (tex->hiz_mem[level]) { + OUT_CS_REG(R300_ZB_HIZ_OFFSET, tex->hiz_mem[level]->ofs << 2); + OUT_CS_REG(R300_ZB_HIZ_PITCH, surf_pitch); + } else { + OUT_CS_REG(R300_ZB_HIZ_OFFSET, 0); + OUT_CS_REG(R300_ZB_HIZ_PITCH, 0); + } + } + /* Z Mask RAM. (compressed zbuffer) */ + if (tex->zmask_mem[level]) { + OUT_CS_REG(R300_ZB_ZMASK_OFFSET, tex->zmask_mem[level]->ofs << 2); + OUT_CS_REG(R300_ZB_ZMASK_PITCH, surf_pitch); + } else { + OUT_CS_REG(R300_ZB_ZMASK_OFFSET, 0); + OUT_CS_REG(R300_ZB_ZMASK_PITCH, 0); + } + } + } + + END_CS; +} + +void r300_emit_hyperz_state(struct r300_context *r300, + unsigned size, void *state) +{ + struct r300_hyperz_state *z = state; + CS_LOCALS(r300); + if (z->flush) + WRITE_CS_TABLE(&z->cb_flush_begin, size); + else + WRITE_CS_TABLE(&z->cb_begin, size - 2); +} + +void r300_emit_hyperz_end(struct r300_context *r300) +{ + struct r300_hyperz_state z = + *(struct r300_hyperz_state*)r300->hyperz_state.state; + + z.flush = 1; + z.zb_bw_cntl = 0; + z.zb_depthclearvalue = 0; + z.sc_hyperz = R300_SC_HYPERZ_ADJ_2; + z.gb_z_peq_config = 0; + + r300_emit_hyperz_state(r300, r300->hyperz_state.size, &z); +} + +void r300_emit_fb_state_pipelined(struct r300_context *r300, + unsigned size, void *state) +{ + struct pipe_framebuffer_state* fb = + (struct pipe_framebuffer_state*)r300->fb_state.state; + unsigned i; + CS_LOCALS(r300); + + BEGIN_CS(size); + + /* Colorbuffer format in the US block. + * (must be written after unpipelined regs) */ + OUT_CS_REG_SEQ(R300_US_OUT_FMT_0, 4); + for (i = 0; i < fb->nr_cbufs; i++) { + OUT_CS(r300_surface(fb->cbufs[i])->format); + } + for (; i < 1; i++) { + OUT_CS(R300_US_OUT_FMT_C4_8 | + R300_C0_SEL_B | R300_C1_SEL_G | + R300_C2_SEL_R | R300_C3_SEL_A); + } + for (; i < 4; i++) { + OUT_CS(R300_US_OUT_FMT_UNUSED); + } + + /* Multisampling. Depends on framebuffer sample count. + * These are pipelined regs and as such cannot be moved + * to the AA state. */ + if (r300->rws->get_value(r300->rws, R300_VID_DRM_2_3_0)) { + unsigned mspos0 = 0x66666666; + unsigned mspos1 = 0x6666666; + + if (fb->nr_cbufs && fb->cbufs[0]->texture->nr_samples > 1) { + /* Subsample placement. These may not be optimal. */ + switch (fb->cbufs[0]->texture->nr_samples) { + case 2: + mspos0 = 0x33996633; + mspos1 = 0x6666663; + break; + case 3: + mspos0 = 0x33936933; + mspos1 = 0x6666663; + break; + case 4: + mspos0 = 0x33939933; + mspos1 = 0x3966663; + break; + case 6: + mspos0 = 0x22a2aa22; + mspos1 = 0x2a65672; + break; + default: + debug_printf("r300: Bad number of multisamples!\n"); + } + } + + OUT_CS_REG_SEQ(R300_GB_MSPOS0, 2); + OUT_CS(mspos0); + OUT_CS(mspos1); + } + END_CS; +} + +void r300_emit_query_start(struct r300_context *r300, unsigned size, void*state) +{ + struct r300_query *query = r300->query_current; + CS_LOCALS(r300); + + if (!query) + return; + + BEGIN_CS(size); + if (r300->screen->caps.family == CHIP_FAMILY_RV530) { + OUT_CS_REG(RV530_FG_ZBREG_DEST, RV530_FG_ZBREG_DEST_PIPE_SELECT_ALL); + } else { + OUT_CS_REG(R300_SU_REG_DEST, R300_RASTER_PIPE_SELECT_ALL); + } + OUT_CS_REG(R300_ZB_ZPASS_DATA, 0); + END_CS; + query->begin_emitted = TRUE; + query->flushed = FALSE; +} + +static void r300_emit_query_end_frag_pipes(struct r300_context *r300, + struct r300_query *query) +{ + struct r300_capabilities* caps = &r300->screen->caps; + struct r300_winsys_cs_buffer *buf = r300->query_current->cs_buffer; + CS_LOCALS(r300); + + assert(caps->num_frag_pipes); + + BEGIN_CS(6 * caps->num_frag_pipes + 2); + /* I'm not so sure I like this switch, but it's hard to be elegant + * when there's so many special cases... + * + * So here's the basic idea. For each pipe, enable writes to it only, + * then put out the relocation for ZPASS_ADDR, taking into account a + * 4-byte offset for each pipe. RV380 and older are special; they have + * only two pipes, and the second pipe's enable is on bit 3, not bit 1, + * so there's a chipset cap for that. */ + switch (caps->num_frag_pipes) { + case 4: + /* pipe 3 only */ + OUT_CS_REG(R300_SU_REG_DEST, 1 << 3); + OUT_CS_REG_SEQ(R300_ZB_ZPASS_ADDR, 1); + OUT_CS_RELOC(buf, (query->num_results + 3) * 4, + 0, query->domain); + case 3: + /* pipe 2 only */ + OUT_CS_REG(R300_SU_REG_DEST, 1 << 2); + OUT_CS_REG_SEQ(R300_ZB_ZPASS_ADDR, 1); + OUT_CS_RELOC(buf, (query->num_results + 2) * 4, + 0, query->domain); + case 2: + /* pipe 1 only */ + /* As mentioned above, accomodate RV380 and older. */ + OUT_CS_REG(R300_SU_REG_DEST, + 1 << (caps->high_second_pipe ? 3 : 1)); + OUT_CS_REG_SEQ(R300_ZB_ZPASS_ADDR, 1); + OUT_CS_RELOC(buf, (query->num_results + 1) * 4, + 0, query->domain); + case 1: + /* pipe 0 only */ + OUT_CS_REG(R300_SU_REG_DEST, 1 << 0); + OUT_CS_REG_SEQ(R300_ZB_ZPASS_ADDR, 1); + OUT_CS_RELOC(buf, (query->num_results + 0) * 4, + 0, query->domain); + break; + default: + fprintf(stderr, "r300: Implementation error: Chipset reports %d" + " pixel pipes!\n", caps->num_frag_pipes); + abort(); + } + + /* And, finally, reset it to normal... */ + OUT_CS_REG(R300_SU_REG_DEST, 0xF); + END_CS; +} + +static void rv530_emit_query_end_single_z(struct r300_context *r300, + struct r300_query *query) +{ + struct r300_winsys_cs_buffer *buf = r300->query_current->cs_buffer; + CS_LOCALS(r300); + + BEGIN_CS(8); + OUT_CS_REG(RV530_FG_ZBREG_DEST, RV530_FG_ZBREG_DEST_PIPE_SELECT_0); + OUT_CS_REG_SEQ(R300_ZB_ZPASS_ADDR, 1); + OUT_CS_RELOC(buf, query->num_results * 4, 0, query->domain); + OUT_CS_REG(RV530_FG_ZBREG_DEST, RV530_FG_ZBREG_DEST_PIPE_SELECT_ALL); + END_CS; +} + +static void rv530_emit_query_end_double_z(struct r300_context *r300, + struct r300_query *query) +{ + struct r300_winsys_cs_buffer *buf = r300->query_current->cs_buffer; + CS_LOCALS(r300); + + BEGIN_CS(14); + OUT_CS_REG(RV530_FG_ZBREG_DEST, RV530_FG_ZBREG_DEST_PIPE_SELECT_0); + OUT_CS_REG_SEQ(R300_ZB_ZPASS_ADDR, 1); + OUT_CS_RELOC(buf, (query->num_results + 0) * 4, 0, query->domain); + OUT_CS_REG(RV530_FG_ZBREG_DEST, RV530_FG_ZBREG_DEST_PIPE_SELECT_1); + OUT_CS_REG_SEQ(R300_ZB_ZPASS_ADDR, 1); + OUT_CS_RELOC(buf, (query->num_results + 1) * 4, 0, query->domain); + OUT_CS_REG(RV530_FG_ZBREG_DEST, RV530_FG_ZBREG_DEST_PIPE_SELECT_ALL); + END_CS; +} + +void r300_emit_query_end(struct r300_context* r300) +{ + struct r300_capabilities *caps = &r300->screen->caps; + struct r300_query *query = r300->query_current; + + if (!query) + return; + + if (query->begin_emitted == FALSE) + return; + + if (caps->family == CHIP_FAMILY_RV530) { + if (caps->num_z_pipes == 2) + rv530_emit_query_end_double_z(r300, query); + else + rv530_emit_query_end_single_z(r300, query); + } else + r300_emit_query_end_frag_pipes(r300, query); + + query->begin_emitted = FALSE; + query->num_results += query->num_pipes; + + /* XXX grab all the results and reset the counter. */ + if (query->num_results >= query->buffer_size / 4 - 4) { + query->num_results = (query->buffer_size / 4) / 2; + fprintf(stderr, "r300: Rewinding OQBO...\n"); + } +} + +void r300_emit_invariant_state(struct r300_context *r300, + unsigned size, void *state) +{ + CS_LOCALS(r300); + WRITE_CS_TABLE(state, size); +} + +void r300_emit_rs_state(struct r300_context* r300, unsigned size, void* state) +{ + struct r300_rs_state* rs = state; + CS_LOCALS(r300); + + BEGIN_CS(size); + OUT_CS_TABLE(rs->cb_main, RS_STATE_MAIN_SIZE); + if (rs->polygon_offset_enable) { + if (r300->zbuffer_bpp == 16) { + OUT_CS_TABLE(rs->cb_poly_offset_zb16, 5); + } else { + OUT_CS_TABLE(rs->cb_poly_offset_zb24, 5); + } + } + END_CS; +} + +void r300_emit_rs_block_state(struct r300_context* r300, + unsigned size, void* state) +{ + struct r300_rs_block* rs = (struct r300_rs_block*)state; + unsigned i; + /* It's the same for both INST and IP tables */ + unsigned count = (rs->inst_count & R300_RS_INST_COUNT_MASK) + 1; + CS_LOCALS(r300); + + if (DBG_ON(r300, DBG_RS_BLOCK)) { + r500_dump_rs_block(rs); + + fprintf(stderr, "r300: RS emit:\n"); + + for (i = 0; i < count; i++) + fprintf(stderr, " : ip %d: 0x%08x\n", i, rs->ip[i]); + + for (i = 0; i < count; i++) + fprintf(stderr, " : inst %d: 0x%08x\n", i, rs->inst[i]); + + fprintf(stderr, " : count: 0x%08x inst_count: 0x%08x\n", + rs->count, rs->inst_count); + } + + BEGIN_CS(size); + OUT_CS_REG_SEQ(R300_VAP_VTX_STATE_CNTL, 2); + OUT_CS(rs->vap_vtx_state_cntl); + OUT_CS(rs->vap_vsm_vtx_assm); + OUT_CS_REG_SEQ(R300_VAP_OUTPUT_VTX_FMT_0, 2); + OUT_CS(rs->vap_out_vtx_fmt[0]); + OUT_CS(rs->vap_out_vtx_fmt[1]); + OUT_CS_REG_SEQ(R300_GB_ENABLE, 1); + OUT_CS(rs->gb_enable); + + if (r300->screen->caps.is_r500) { + OUT_CS_REG_SEQ(R500_RS_IP_0, count); + } else { + OUT_CS_REG_SEQ(R300_RS_IP_0, count); + } + OUT_CS_TABLE(rs->ip, count); + + OUT_CS_REG_SEQ(R300_RS_COUNT, 2); + OUT_CS(rs->count); + OUT_CS(rs->inst_count); + + if (r300->screen->caps.is_r500) { + OUT_CS_REG_SEQ(R500_RS_INST_0, count); + } else { + OUT_CS_REG_SEQ(R300_RS_INST_0, count); + } + OUT_CS_TABLE(rs->inst, count); + END_CS; +} + +void r300_emit_scissor_state(struct r300_context* r300, + unsigned size, void* state) +{ + struct pipe_scissor_state* scissor = (struct pipe_scissor_state*)state; + CS_LOCALS(r300); + + BEGIN_CS(size); + OUT_CS_REG_SEQ(R300_SC_CLIPRECT_TL_0, 2); + if (r300->screen->caps.is_r500) { + OUT_CS((scissor->minx << R300_CLIPRECT_X_SHIFT) | + (scissor->miny << R300_CLIPRECT_Y_SHIFT)); + OUT_CS(((scissor->maxx - 1) << R300_CLIPRECT_X_SHIFT) | + ((scissor->maxy - 1) << R300_CLIPRECT_Y_SHIFT)); + } else { + OUT_CS(((scissor->minx + 1440) << R300_CLIPRECT_X_SHIFT) | + ((scissor->miny + 1440) << R300_CLIPRECT_Y_SHIFT)); + OUT_CS(((scissor->maxx + 1440-1) << R300_CLIPRECT_X_SHIFT) | + ((scissor->maxy + 1440-1) << R300_CLIPRECT_Y_SHIFT)); + } + END_CS; +} + +void r300_emit_textures_state(struct r300_context *r300, + unsigned size, void *state) +{ + struct r300_textures_state *allstate = (struct r300_textures_state*)state; + struct r300_texture_sampler_state *texstate; + struct r300_texture *tex; + unsigned i; + CS_LOCALS(r300); + + BEGIN_CS(size); + OUT_CS_REG(R300_TX_ENABLE, allstate->tx_enable); + + for (i = 0; i < allstate->count; i++) { + if ((1 << i) & allstate->tx_enable) { + texstate = &allstate->regs[i]; + tex = r300_texture(allstate->sampler_views[i]->base.texture); + + OUT_CS_REG(R300_TX_FILTER0_0 + (i * 4), texstate->filter0); + OUT_CS_REG(R300_TX_FILTER1_0 + (i * 4), texstate->filter1); + OUT_CS_REG(R300_TX_BORDER_COLOR_0 + (i * 4), + texstate->border_color); + + OUT_CS_REG(R300_TX_FORMAT0_0 + (i * 4), texstate->format.format0); + OUT_CS_REG(R300_TX_FORMAT1_0 + (i * 4), texstate->format.format1); + OUT_CS_REG(R300_TX_FORMAT2_0 + (i * 4), texstate->format.format2); + + OUT_CS_REG_SEQ(R300_TX_OFFSET_0 + (i * 4), 1); + OUT_CS_TEX_RELOC(tex, texstate->format.tile_config, tex->domain, + 0); + } + } + END_CS; +} + +static void r300_update_aos_cb(struct r300_context *r300, unsigned packet_size) +{ + struct pipe_vertex_buffer *vb1, *vb2, *vbuf = r300->vertex_buffer; + struct pipe_vertex_element *velem = r300->velems->velem; + unsigned *hw_format_size = r300->velems->hw_format_size; + unsigned size1, size2, aos_count = r300->velems->count; + int i; + CB_LOCALS; + + BEGIN_CB(r300->aos_cb, packet_size); + for (i = 0; i < aos_count - 1; i += 2) { + vb1 = &vbuf[velem[i].vertex_buffer_index]; + vb2 = &vbuf[velem[i+1].vertex_buffer_index]; + size1 = hw_format_size[i]; + size2 = hw_format_size[i+1]; + + OUT_CB(R300_VBPNTR_SIZE0(size1) | R300_VBPNTR_STRIDE0(vb1->stride) | + R300_VBPNTR_SIZE1(size2) | R300_VBPNTR_STRIDE1(vb2->stride)); + OUT_CB(vb1->buffer_offset + velem[i].src_offset); + OUT_CB(vb2->buffer_offset + velem[i+1].src_offset); + } + + if (aos_count & 1) { + vb1 = &vbuf[velem[i].vertex_buffer_index]; + size1 = hw_format_size[i]; + + OUT_CB(R300_VBPNTR_SIZE0(size1) | R300_VBPNTR_STRIDE0(vb1->stride)); + OUT_CB(vb1->buffer_offset + velem[i].src_offset); + } + END_CB; + + r300->aos_dirty = FALSE; +} + +void r300_emit_aos(struct r300_context* r300, int offset, boolean indexed) +{ + struct pipe_vertex_buffer *vbuf = r300->vertex_buffer; + struct pipe_vertex_element *velem = r300->velems->velem; + struct r300_buffer *buf; + int i; + unsigned aos_count = r300->velems->count; + unsigned packet_size = (aos_count * 3 + 1) / 2; + CS_LOCALS(r300); + + BEGIN_CS(2 + packet_size + aos_count * 2); + OUT_CS_PKT3(R300_PACKET3_3D_LOAD_VBPNTR, packet_size); + OUT_CS(aos_count | (!indexed ? R300_VC_FORCE_PREFETCH : 0)); + + if (!offset) { + if (r300->aos_dirty) { + r300_update_aos_cb(r300, packet_size); + } + OUT_CS_TABLE(r300->aos_cb, packet_size); + } else { + struct pipe_vertex_buffer *vb1, *vb2; + unsigned *hw_format_size = r300->velems->hw_format_size; + unsigned size1, size2; + + for (i = 0; i < aos_count - 1; i += 2) { + vb1 = &vbuf[velem[i].vertex_buffer_index]; + vb2 = &vbuf[velem[i+1].vertex_buffer_index]; + size1 = hw_format_size[i]; + size2 = hw_format_size[i+1]; + + OUT_CS(R300_VBPNTR_SIZE0(size1) | R300_VBPNTR_STRIDE0(vb1->stride) | + R300_VBPNTR_SIZE1(size2) | R300_VBPNTR_STRIDE1(vb2->stride)); + OUT_CS(vb1->buffer_offset + velem[i].src_offset + offset * vb1->stride); + OUT_CS(vb2->buffer_offset + velem[i+1].src_offset + offset * vb2->stride); + } + + if (aos_count & 1) { + vb1 = &vbuf[velem[i].vertex_buffer_index]; + size1 = hw_format_size[i]; + + OUT_CS(R300_VBPNTR_SIZE0(size1) | R300_VBPNTR_STRIDE0(vb1->stride)); + OUT_CS(vb1->buffer_offset + velem[i].src_offset + offset * vb1->stride); + } + } + + for (i = 0; i < aos_count; i++) { + buf = r300_buffer(vbuf[velem[i].vertex_buffer_index].buffer); + OUT_CS_BUF_RELOC_NO_OFFSET(&buf->b.b, buf->domain, 0); + } + END_CS; +} + +void r300_emit_aos_swtcl(struct r300_context *r300, boolean indexed) +{ + CS_LOCALS(r300); + + DBG(r300, DBG_SWTCL, "r300: Preparing vertex buffer %p for render, " + "vertex size %d\n", r300->vbo, + r300->vertex_info.size); + /* Set the pointer to our vertex buffer. The emitted values are this: + * PACKET3 [3D_LOAD_VBPNTR] + * COUNT [1] + * FORMAT [size | stride << 8] + * OFFSET [offset into BO] + * VBPNTR [relocated BO] + */ + BEGIN_CS(7); + OUT_CS_PKT3(R300_PACKET3_3D_LOAD_VBPNTR, 3); + OUT_CS(1 | (!indexed ? R300_VC_FORCE_PREFETCH : 0)); + OUT_CS(r300->vertex_info.size | + (r300->vertex_info.size << 8)); + OUT_CS(r300->draw_vbo_offset); + OUT_CS_BUF_RELOC(r300->vbo, 0, r300_buffer(r300->vbo)->domain, 0); + END_CS; +} + +void r300_emit_vertex_stream_state(struct r300_context* r300, + unsigned size, void* state) +{ + struct r300_vertex_stream_state *streams = + (struct r300_vertex_stream_state*)state; + unsigned i; + CS_LOCALS(r300); + + if (DBG_ON(r300, DBG_PSC)) { + fprintf(stderr, "r300: PSC emit:\n"); + + for (i = 0; i < streams->count; i++) { + fprintf(stderr, " : prog_stream_cntl%d: 0x%08x\n", i, + streams->vap_prog_stream_cntl[i]); + } + + for (i = 0; i < streams->count; i++) { + fprintf(stderr, " : prog_stream_cntl_ext%d: 0x%08x\n", i, + streams->vap_prog_stream_cntl_ext[i]); + } + } + + BEGIN_CS(size); + OUT_CS_REG_SEQ(R300_VAP_PROG_STREAM_CNTL_0, streams->count); + OUT_CS_TABLE(streams->vap_prog_stream_cntl, streams->count); + OUT_CS_REG_SEQ(R300_VAP_PROG_STREAM_CNTL_EXT_0, streams->count); + OUT_CS_TABLE(streams->vap_prog_stream_cntl_ext, streams->count); + END_CS; +} + +void r300_emit_pvs_flush(struct r300_context* r300, unsigned size, void* state) +{ + CS_LOCALS(r300); + + BEGIN_CS(size); + OUT_CS_REG(R300_VAP_PVS_STATE_FLUSH_REG, 0x0); + END_CS; +} + +void r300_emit_vap_invariant_state(struct r300_context *r300, + unsigned size, void *state) +{ + CS_LOCALS(r300); + WRITE_CS_TABLE(state, size); +} + +void r300_emit_vs_state(struct r300_context* r300, unsigned size, void* state) +{ + struct r300_vertex_shader* vs = (struct r300_vertex_shader*)state; + struct r300_vertex_program_code* code = &vs->code; + struct r300_screen* r300screen = r300->screen; + unsigned instruction_count = code->length / 4; + + unsigned vtx_mem_size = r300screen->caps.is_r500 ? 128 : 72; + unsigned input_count = MAX2(util_bitcount(code->InputsRead), 1); + unsigned output_count = MAX2(util_bitcount(code->OutputsWritten), 1); + unsigned temp_count = MAX2(code->num_temporaries, 1); + + unsigned pvs_num_slots = MIN3(vtx_mem_size / input_count, + vtx_mem_size / output_count, 10); + unsigned pvs_num_controllers = MIN2(vtx_mem_size / temp_count, 5); + + CS_LOCALS(r300); + + BEGIN_CS(size); + + /* R300_VAP_PVS_CODE_CNTL_0 + * R300_VAP_PVS_CONST_CNTL + * R300_VAP_PVS_CODE_CNTL_1 + * See the r5xx docs for instructions on how to use these. */ + OUT_CS_REG(R300_VAP_PVS_CODE_CNTL_0, R300_PVS_FIRST_INST(0) | + R300_PVS_XYZW_VALID_INST(instruction_count - 1) | + R300_PVS_LAST_INST(instruction_count - 1)); + OUT_CS_REG(R300_VAP_PVS_CODE_CNTL_1, instruction_count - 1); + + OUT_CS_REG(R300_VAP_PVS_VECTOR_INDX_REG, 0); + OUT_CS_ONE_REG(R300_VAP_PVS_UPLOAD_DATA, code->length); + OUT_CS_TABLE(code->body.d, code->length); + + OUT_CS_REG(R300_VAP_CNTL, R300_PVS_NUM_SLOTS(pvs_num_slots) | + R300_PVS_NUM_CNTLRS(pvs_num_controllers) | + R300_PVS_NUM_FPUS(r300screen->caps.num_vert_fpus) | + R300_PVS_VF_MAX_VTX_NUM(12) | + (r300screen->caps.is_r500 ? R500_TCL_STATE_OPTIMIZATION : 0)); + + /* Emit flow control instructions. */ + if (code->num_fc_ops) { + + OUT_CS_REG(R300_VAP_PVS_FLOW_CNTL_OPC, code->fc_ops); + if (r300screen->caps.is_r500) { + OUT_CS_REG_SEQ(R500_VAP_PVS_FLOW_CNTL_ADDRS_LW_0, code->num_fc_ops * 2); + OUT_CS_TABLE(code->fc_op_addrs.r500, code->num_fc_ops * 2); + } else { + OUT_CS_REG_SEQ(R300_VAP_PVS_FLOW_CNTL_ADDRS_0, code->num_fc_ops); + OUT_CS_TABLE(code->fc_op_addrs.r300, code->num_fc_ops); + } + OUT_CS_REG_SEQ(R300_VAP_PVS_FLOW_CNTL_LOOP_INDEX_0, code->num_fc_ops); + OUT_CS_TABLE(code->fc_loop_index, code->num_fc_ops); + } + + END_CS; +} + +void r300_emit_vs_constants(struct r300_context* r300, + unsigned size, void *state) +{ + unsigned count = + ((struct r300_vertex_shader*)r300->vs_state.state)->externals_count; + struct r300_constant_buffer *buf = (struct r300_constant_buffer*)state; + struct r300_vertex_shader *vs = (struct r300_vertex_shader*)r300->vs_state.state; + unsigned i; + int imm_first = vs->externals_count; + int imm_end = vs->code.constants.Count; + int imm_count = vs->immediates_count; + CS_LOCALS(r300); + + BEGIN_CS(size); + OUT_CS_REG(R300_VAP_PVS_CONST_CNTL, + R300_PVS_CONST_BASE_OFFSET(buf->buffer_base) | + R300_PVS_MAX_CONST_ADDR(MAX2(imm_end - 1, 0))); + if (vs->externals_count) { + OUT_CS_REG(R300_VAP_PVS_VECTOR_INDX_REG, + (r300->screen->caps.is_r500 ? + R500_PVS_CONST_START : R300_PVS_CONST_START) + buf->buffer_base); + OUT_CS_ONE_REG(R300_VAP_PVS_UPLOAD_DATA, count * 4); + if (buf->remap_table){ + for (i = 0; i < count; i++) { + uint32_t *data = &buf->ptr[buf->remap_table[i]*4]; + OUT_CS_TABLE(data, 4); + } + } else { + OUT_CS_TABLE(buf->ptr, count * 4); + } + } + + /* Emit immediates. */ + if (imm_count) { + OUT_CS_REG(R300_VAP_PVS_VECTOR_INDX_REG, + (r300->screen->caps.is_r500 ? + R500_PVS_CONST_START : R300_PVS_CONST_START) + + buf->buffer_base + imm_first); + OUT_CS_ONE_REG(R300_VAP_PVS_UPLOAD_DATA, imm_count * 4); + for (i = imm_first; i < imm_end; i++) { + const float *data = vs->code.constants.Constants[i].u.Immediate; + OUT_CS_TABLE(data, 4); + } + } + END_CS; +} + +void r300_emit_viewport_state(struct r300_context* r300, + unsigned size, void* state) +{ + struct r300_viewport_state* viewport = (struct r300_viewport_state*)state; + CS_LOCALS(r300); + + BEGIN_CS(size); + OUT_CS_REG_SEQ(R300_SE_VPORT_XSCALE, 6); + OUT_CS_TABLE(&viewport->xscale, 6); + OUT_CS_REG(R300_VAP_VTE_CNTL, viewport->vte_control); + END_CS; +} + +static void r300_emit_hiz_line_clear(struct r300_context *r300, int start, uint16_t count, uint32_t val) +{ + CS_LOCALS(r300); + BEGIN_CS(4); + OUT_CS_PKT3(R300_PACKET3_3D_CLEAR_HIZ, 2); + OUT_CS(start); + OUT_CS(count); + OUT_CS(val); + END_CS; +} + +static void r300_emit_zmask_line_clear(struct r300_context *r300, int start, uint16_t count, uint32_t val) +{ + CS_LOCALS(r300); + BEGIN_CS(4); + OUT_CS_PKT3(R300_PACKET3_3D_CLEAR_ZMASK, 2); + OUT_CS(start); + OUT_CS(count); + OUT_CS(val); + END_CS; +} + +#define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y)) + +void r300_emit_hiz_clear(struct r300_context *r300, unsigned size, void *state) +{ + struct pipe_framebuffer_state *fb = + (struct pipe_framebuffer_state*)r300->fb_state.state; + struct r300_hyperz_state *z = + (struct r300_hyperz_state*)r300->hyperz_state.state; + struct r300_screen* r300screen = r300->screen; + uint32_t stride, offset = 0, height, offset_shift; + struct r300_texture* tex; + int i; + + tex = r300_texture(fb->zsbuf->texture); + + offset = tex->hiz_mem[fb->zsbuf->u.tex.level]->ofs; + stride = tex->desc.stride_in_pixels[fb->zsbuf->u.tex.level]; + + /* convert from pixels to 4x4 blocks */ + stride = ALIGN_DIVUP(stride, 4); + + stride = ALIGN_DIVUP(stride, r300screen->caps.num_frag_pipes); + /* there are 4 blocks per dwords */ + stride = ALIGN_DIVUP(stride, 4); + + height = ALIGN_DIVUP(fb->zsbuf->height, 4); + + offset_shift = 2; + offset_shift += (r300screen->caps.num_frag_pipes / 2); + + for (i = 0; i < height; i++) { + offset = i * stride; + offset <<= offset_shift; + r300_emit_hiz_line_clear(r300, offset, stride, 0xffffffff); + } + z->current_func = -1; + + /* Mark the current zbuffer's hiz ram as in use. */ + tex->hiz_in_use[fb->zsbuf->u.tex.level] = TRUE; +} + +void r300_emit_zmask_clear(struct r300_context *r300, unsigned size, void *state) +{ + struct pipe_framebuffer_state *fb = + (struct pipe_framebuffer_state*)r300->fb_state.state; + struct r300_screen* r300screen = r300->screen; + uint32_t stride, offset = 0; + struct r300_texture* tex; + uint32_t i, height; + int mult, offset_shift; + + tex = r300_texture(fb->zsbuf->texture); + stride = tex->desc.stride_in_pixels[fb->zsbuf->u.tex.level]; + + offset = tex->zmask_mem[fb->zsbuf->u.tex.level]->ofs; + + if (r300->z_compression == RV350_Z_COMPRESS_88) + mult = 8; + else + mult = 4; + + height = ALIGN_DIVUP(fb->zsbuf->height, mult); + + offset_shift = 4; + offset_shift += (r300screen->caps.num_frag_pipes / 2); + stride = ALIGN_DIVUP(stride, r300screen->caps.num_frag_pipes); + + /* okay have width in pixels - divide by block width */ + stride = ALIGN_DIVUP(stride, mult); + /* have width in blocks - divide by number of fragment pipes screen width */ + /* 16 blocks per dword */ + stride = ALIGN_DIVUP(stride, 16); + + for (i = 0; i < height; i++) { + offset = i * stride; + offset <<= offset_shift; + r300_emit_zmask_line_clear(r300, offset, stride, 0x0);//0xffffffff); + } + + /* Mark the current zbuffer's zmask as in use. */ + tex->zmask_in_use[fb->zsbuf->u.tex.level] = TRUE; +} + +void r300_emit_ztop_state(struct r300_context* r300, + unsigned size, void* state) +{ + struct r300_ztop_state* ztop = (struct r300_ztop_state*)state; + CS_LOCALS(r300); + + BEGIN_CS(size); + OUT_CS_REG(R300_ZB_ZTOP, ztop->z_buffer_top); + END_CS; +} + +void r300_emit_texture_cache_inval(struct r300_context* r300, unsigned size, void* state) +{ + CS_LOCALS(r300); + + BEGIN_CS(size); + OUT_CS_REG(R300_TX_INVALTAGS, 0); + END_CS; +} + +boolean r300_emit_buffer_validate(struct r300_context *r300, + boolean do_validate_vertex_buffers, + struct pipe_resource *index_buffer) +{ + struct pipe_framebuffer_state* fb = + (struct pipe_framebuffer_state*)r300->fb_state.state; + struct r300_textures_state *texstate = + (struct r300_textures_state*)r300->textures_state.state; + struct r300_texture* tex; + struct pipe_vertex_buffer *vbuf = r300->vertex_buffer; + struct pipe_vertex_element *velem = r300->velems->velem; + struct pipe_resource *pbuf; + unsigned i; + + /* Clean out BOs. */ + r300->rws->cs_reset_buffers(r300->cs); + + /* Color buffers... */ + for (i = 0; i < fb->nr_cbufs; i++) { + tex = r300_texture(fb->cbufs[i]->texture); + assert(tex && tex->buffer && "cbuf is marked, but NULL!"); + r300->rws->cs_add_buffer(r300->cs, tex->cs_buffer, 0, + r300_surface(fb->cbufs[i])->domain); + } + /* ...depth buffer... */ + if (fb->zsbuf) { + tex = r300_texture(fb->zsbuf->texture); + assert(tex && tex->buffer && "zsbuf is marked, but NULL!"); + r300->rws->cs_add_buffer(r300->cs, tex->cs_buffer, 0, + r300_surface(fb->zsbuf)->domain); + } + /* ...textures... */ + for (i = 0; i < texstate->count; i++) { + if (!(texstate->tx_enable & (1 << i))) { + continue; + } + + tex = r300_texture(texstate->sampler_views[i]->base.texture); + r300->rws->cs_add_buffer(r300->cs, tex->cs_buffer, tex->domain, 0); + } + /* ...occlusion query buffer... */ + if (r300->query_current) + r300->rws->cs_add_buffer(r300->cs, r300->query_current->cs_buffer, + 0, r300->query_current->domain); + /* ...vertex buffer for SWTCL path... */ + if (r300->vbo) + r300->rws->cs_add_buffer(r300->cs, r300_buffer(r300->vbo)->cs_buf, + r300_buffer(r300->vbo)->domain, 0); + /* ...vertex buffers for HWTCL path... */ + if (do_validate_vertex_buffers) { + for (i = 0; i < r300->velems->count; i++) { + pbuf = vbuf[velem[i].vertex_buffer_index].buffer; + if (!pbuf) + continue; + + r300->rws->cs_add_buffer(r300->cs, r300_buffer(pbuf)->cs_buf, + r300_buffer(pbuf)->domain, 0); + } + } + /* ...and index buffer for HWTCL path. */ + if (index_buffer) + r300->rws->cs_add_buffer(r300->cs, r300_buffer(index_buffer)->cs_buf, + r300_buffer(index_buffer)->domain, 0); + + if (!r300->rws->cs_validate(r300->cs)) { + return FALSE; + } + + return TRUE; +} + +unsigned r300_get_num_dirty_dwords(struct r300_context *r300) +{ + struct r300_atom* atom; + unsigned dwords = 0; + + foreach_dirty_atom(r300, atom) { + if (atom->dirty) { + dwords += atom->size; + } + } + + /* let's reserve some more, just in case */ + dwords += 32; + + return dwords; +} + +unsigned r300_get_num_cs_end_dwords(struct r300_context *r300) +{ + unsigned dwords = 0; + + /* Emitted in flush. */ + dwords += 26; /* emit_query_end */ + dwords += r300->hyperz_state.size + 2; /* emit_hyperz_end + zcache flush */ + if (r300->screen->caps.index_bias_supported) + dwords += 2; + + return dwords; +} + +/* Emit all dirty state. */ +void r300_emit_dirty_state(struct r300_context* r300) +{ + struct r300_atom *atom; + + foreach_dirty_atom(r300, atom) { + if (atom->dirty) { + atom->emit(r300, atom->size, atom->state); + atom->dirty = FALSE; + } + } + + r300->first_dirty = NULL; + r300->last_dirty = NULL; + r300->dirty_hw++; +} diff --git a/src/gallium/drivers/r300/r300_emit.h b/src/gallium/drivers/r300/r300_emit.h new file mode 100644 index 0000000..278dbcb --- /dev/null +++ b/src/gallium/drivers/r300/r300_emit.h @@ -0,0 +1,128 @@ +/* + * 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 R300_EMIT_H +#define R300_EMIT_H + +#include "r300_context.h" +#include "radeon_code.h" + +struct rX00_fragment_program_code; +struct r300_vertex_program_code; + +uint32_t pack_float24(float f); + +void r300_emit_aos(struct r300_context* r300, int offset, boolean indexed); + +void r300_emit_blend_state(struct r300_context* r300, + unsigned size, void* state); + +void r300_emit_blend_color_state(struct r300_context* r300, + unsigned size, void* state); + +void r300_emit_clip_state(struct r300_context* r300, + unsigned size, void* state); + +void r300_emit_dsa_state(struct r300_context* r300, + unsigned size, void* state); + +void r300_emit_hyperz_state(struct r300_context *r300, + unsigned size, void *state); + +void r300_emit_hyperz_end(struct r300_context *r300); + +void r300_emit_fs(struct r300_context* r300, unsigned size, void *state); + +void r300_emit_fs_constants(struct r300_context* r300, unsigned size, void *state); + +void r300_emit_fs_rc_constant_state(struct r300_context* r300, unsigned size, void *state); + +void r500_emit_fs(struct r300_context* r300, unsigned size, void *state); + +void r500_emit_fs_constants(struct r300_context* r300, unsigned size, void *state); + +void r500_emit_fs_rc_constant_state(struct r300_context* r300, unsigned size, void *state); + +void r300_emit_fb_state(struct r300_context* r300, unsigned size, void* state); + +void r300_emit_fb_state_pipelined(struct r300_context *r300, + unsigned size, void *state); + +void r300_emit_gpu_flush(struct r300_context *r300, unsigned size, void *state); + +void r300_emit_aa_state(struct r300_context *r300, unsigned size, void *state); + +void r300_emit_query_start(struct r300_context *r300, unsigned size, void *state); + +void r300_emit_query_end(struct r300_context* r300); + +void r300_emit_rs_state(struct r300_context* r300, unsigned size, void* state); + +void r300_emit_rs_block_state(struct r300_context* r300, + unsigned size, void* state); + +void r300_emit_scissor_state(struct r300_context* r300, + unsigned size, void* state); + +void r300_emit_textures_state(struct r300_context *r300, + unsigned size, void *state); + +void r300_emit_aos_swtcl(struct r300_context *r300, boolean indexed); + +void r300_emit_vap_invariant_state(struct r300_context *r300, + unsigned size, void *state); + +void r300_emit_vertex_stream_state(struct r300_context* r300, + unsigned size, void* state); + +void r300_emit_vs_constants(struct r300_context* r300, + unsigned size, void *state); + +void r300_emit_vs_state(struct r300_context* r300, unsigned size, void* state); + +void r300_emit_viewport_state(struct r300_context* r300, + unsigned size, void* state); + +void r300_emit_ztop_state(struct r300_context* r300, + unsigned size, void* state); + +void r300_emit_pvs_flush(struct r300_context* r300, unsigned size, void* state); + +void r300_emit_texture_cache_inval(struct r300_context* r300, unsigned size, void* state); + +void r300_emit_invariant_state(struct r300_context *r300, + unsigned size, void *state); + +void r300_emit_hiz_clear(struct r300_context *r300, unsigned size, void *state); +void r300_emit_zmask_clear(struct r300_context *r300, unsigned size, void *state); + +unsigned r300_get_num_dirty_dwords(struct r300_context *r300); +unsigned r300_get_num_cs_end_dwords(struct r300_context *r300); + +/* Emit all dirty state. */ +void r300_emit_dirty_state(struct r300_context* r300); + +boolean r300_emit_buffer_validate(struct r300_context *r300, + boolean do_validate_vertex_buffers, + struct pipe_resource *index_buffer); + +#endif /* R300_EMIT_H */ diff --git a/src/gallium/drivers/r300/r300_flush.c b/src/gallium/drivers/r300/r300_flush.c new file mode 100644 index 0000000..451fe52 --- /dev/null +++ b/src/gallium/drivers/r300/r300_flush.c @@ -0,0 +1,91 @@ +/* + * Copyright 2008 Corbin Simpson + * Copyright 2010 Marek Olšák + * + * 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 "draw/draw_context.h" +#include "draw/draw_private.h" + +#include "util/u_simple_list.h" +#include "util/u_upload_mgr.h" + +#include "r300_context.h" +#include "r300_cs.h" +#include "r300_emit.h" + +static void r300_flush(struct pipe_context* pipe, + unsigned flags, + struct pipe_fence_handle** fence) +{ + struct r300_context *r300 = r300_context(pipe); + struct r300_query *query; + struct r300_atom *atom; + struct r300_fence **rfence = (struct r300_fence**)fence; + + u_upload_flush(r300->upload_vb); + u_upload_flush(r300->upload_ib); + + if (r300->draw && !r300->draw_vbo_locked) + r300_draw_flush_vbuf(r300); + + if (r300->dirty_hw) { + r300_emit_hyperz_end(r300); + r300_emit_query_end(r300); + if (r300->screen->caps.index_bias_supported) + r500_emit_index_bias(r300, 0); + + r300->flush_counter++; + r300->rws->cs_flush(r300->cs); + r300->dirty_hw = 0; + + /* New kitchen sink, baby. */ + foreach_atom(r300, atom) { + if (atom->state || atom->allow_null_state) { + r300_mark_atom_dirty(r300, atom); + } + } + + /* Unmark HWTCL state for SWTCL. */ + if (!r300->screen->caps.has_tcl) { + r300->vs_state.dirty = FALSE; + r300->vs_constants.dirty = FALSE; + } + + r300->validate_buffers = TRUE; + } + + /* reset flushed query */ + foreach(query, &r300->query_list) { + query->flushed = TRUE; + } + + /* Create a new fence. */ + if (rfence) { + *rfence = CALLOC_STRUCT(r300_fence); + pipe_reference_init(&(*rfence)->reference, 1); + (*rfence)->ctx = r300; + } +} + +void r300_init_flush_functions(struct r300_context* r300) +{ + r300->context.flush = r300_flush; +} diff --git a/src/gallium/drivers/r300/r300_fs.c b/src/gallium/drivers/r300/r300_fs.c new file mode 100644 index 0000000..2936c34 --- /dev/null +++ b/src/gallium/drivers/r300/r300_fs.c @@ -0,0 +1,543 @@ +/* + * Copyright 2008 Corbin Simpson + * Joakim Sindholt + * Copyright 2009 Marek Olšák + * + * 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 "util/u_math.h" +#include "util/u_memory.h" + +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_ureg.h" + +#include "r300_cb.h" +#include "r300_context.h" +#include "r300_emit.h" +#include "r300_screen.h" +#include "r300_fs.h" +#include "r300_reg.h" +#include "r300_tgsi_to_rc.h" + +#include "radeon_code.h" +#include "radeon_compiler.h" + +/* Convert info about FS input semantics to r300_shader_semantics. */ +void r300_shader_read_fs_inputs(struct tgsi_shader_info* info, + struct r300_shader_semantics* fs_inputs) +{ + int i; + unsigned index; + + r300_shader_semantics_reset(fs_inputs); + + for (i = 0; i < info->num_inputs; i++) { + index = info->input_semantic_index[i]; + + switch (info->input_semantic_name[i]) { + case TGSI_SEMANTIC_COLOR: + assert(index < ATTR_COLOR_COUNT); + fs_inputs->color[index] = i; + break; + + case TGSI_SEMANTIC_GENERIC: + assert(index < ATTR_GENERIC_COUNT); + fs_inputs->generic[index] = i; + break; + + case TGSI_SEMANTIC_FOG: + assert(index == 0); + fs_inputs->fog = i; + break; + + case TGSI_SEMANTIC_POSITION: + assert(index == 0); + fs_inputs->wpos = i; + break; + + case TGSI_SEMANTIC_FACE: + assert(index == 0); + fs_inputs->face = i; + break; + + default: + fprintf(stderr, "r300: FP: Unknown input semantic: %i\n", + info->input_semantic_name[i]); + } + } +} + +static void find_output_registers(struct r300_fragment_program_compiler * compiler, + struct r300_fragment_shader_code *shader) +{ + unsigned i, colorbuf_count = 0; + + /* Mark the outputs as not present initially */ + compiler->OutputColor[0] = shader->info.num_outputs; + compiler->OutputColor[1] = shader->info.num_outputs; + compiler->OutputColor[2] = shader->info.num_outputs; + compiler->OutputColor[3] = shader->info.num_outputs; + compiler->OutputDepth = shader->info.num_outputs; + + /* Now see where they really are. */ + for(i = 0; i < shader->info.num_outputs; ++i) { + switch(shader->info.output_semantic_name[i]) { + case TGSI_SEMANTIC_COLOR: + compiler->OutputColor[colorbuf_count] = i; + colorbuf_count++; + break; + case TGSI_SEMANTIC_POSITION: + compiler->OutputDepth = i; + break; + } + } +} + +static void allocate_hardware_inputs( + struct r300_fragment_program_compiler * c, + void (*allocate)(void * data, unsigned input, unsigned hwreg), + void * mydata) +{ + struct r300_shader_semantics* inputs = + (struct r300_shader_semantics*)c->UserData; + int i, reg = 0; + + /* Allocate input registers. */ + for (i = 0; i < ATTR_COLOR_COUNT; i++) { + if (inputs->color[i] != ATTR_UNUSED) { + allocate(mydata, inputs->color[i], reg++); + } + } + if (inputs->face != ATTR_UNUSED) { + allocate(mydata, inputs->face, reg++); + } + for (i = 0; i < ATTR_GENERIC_COUNT; i++) { + if (inputs->generic[i] != ATTR_UNUSED) { + allocate(mydata, inputs->generic[i], reg++); + } + } + if (inputs->fog != ATTR_UNUSED) { + allocate(mydata, inputs->fog, reg++); + } + if (inputs->wpos != ATTR_UNUSED) { + allocate(mydata, inputs->wpos, reg++); + } +} + +static void get_external_state( + struct r300_context* r300, + struct r300_fragment_program_external_state* state) +{ + struct r300_textures_state *texstate = r300->textures_state.state; + unsigned i; + unsigned char *swizzle; + + for (i = 0; i < texstate->sampler_state_count; i++) { + struct r300_sampler_state *s = texstate->sampler_states[i]; + struct r300_sampler_view *v = texstate->sampler_views[i]; + struct r300_texture *t; + + if (!s || !v) { + continue; + } + + t = r300_texture(texstate->sampler_views[i]->base.texture); + + if (s->state.compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) { + state->unit[i].compare_mode_enabled = 1; + + /* Pass depth texture swizzling to the compiler. */ + if (texstate->sampler_views[i]) { + swizzle = texstate->sampler_views[i]->swizzle; + + state->unit[i].depth_texture_swizzle = + RC_MAKE_SWIZZLE(swizzle[0], swizzle[1], + swizzle[2], swizzle[3]); + } else { + state->unit[i].depth_texture_swizzle = RC_SWIZZLE_XYZW; + } + + /* Fortunately, no need to translate this. */ + state->unit[i].texture_compare_func = s->state.compare_func; + } + + state->unit[i].non_normalized_coords = !s->state.normalized_coords; + + /* XXX this should probably take into account STR, not just S. */ + if (t->desc.is_npot) { + switch (s->state.wrap_s) { + case PIPE_TEX_WRAP_REPEAT: + state->unit[i].wrap_mode = RC_WRAP_REPEAT; + break; + + case PIPE_TEX_WRAP_MIRROR_REPEAT: + state->unit[i].wrap_mode = RC_WRAP_MIRRORED_REPEAT; + break; + + case PIPE_TEX_WRAP_MIRROR_CLAMP: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + state->unit[i].wrap_mode = RC_WRAP_MIRRORED_CLAMP; + break; + + default: + state->unit[i].wrap_mode = RC_WRAP_NONE; + } + + if (t->desc.b.b.target == PIPE_TEXTURE_3D) + state->unit[i].clamp_and_scale_before_fetch = TRUE; + } + } +} + +static void r300_translate_fragment_shader( + struct r300_context* r300, + struct r300_fragment_shader_code* shader, + const struct tgsi_token *tokens); + +static void r300_dummy_fragment_shader( + struct r300_context* r300, + struct r300_fragment_shader_code* shader) +{ + struct pipe_shader_state state; + struct ureg_program *ureg; + struct ureg_dst out; + struct ureg_src imm; + + /* Make a simple fragment shader which outputs (0, 0, 0, 1) */ + ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT); + out = ureg_DECL_output(ureg, TGSI_SEMANTIC_COLOR, 0); + imm = ureg_imm4f(ureg, 0, 0, 0, 1); + + ureg_MOV(ureg, out, imm); + ureg_END(ureg); + + state.tokens = ureg_finalize(ureg); + + shader->dummy = TRUE; + r300_translate_fragment_shader(r300, shader, state.tokens); + + ureg_destroy(ureg); +} + +static void r300_emit_fs_code_to_buffer( + struct r300_context *r300, + struct r300_fragment_shader_code *shader) +{ + struct rX00_fragment_program_code *generic_code = &shader->code; + unsigned imm_count = shader->immediates_count; + unsigned imm_first = shader->externals_count; + unsigned imm_end = generic_code->constants.Count; + struct rc_constant *constants = generic_code->constants.Constants; + unsigned i; + CB_LOCALS; + + if (r300->screen->caps.is_r500) { + struct r500_fragment_program_code *code = &generic_code->code.r500; + + shader->cb_code_size = 19 + + ((code->inst_end + 1) * 6) + + imm_count * 7 + + code->int_constant_count * 2; + + NEW_CB(shader->cb_code, shader->cb_code_size); + OUT_CB_REG(R500_US_CONFIG, R500_ZERO_TIMES_ANYTHING_EQUALS_ZERO); + OUT_CB_REG(R500_US_PIXSIZE, code->max_temp_idx); + OUT_CB_REG(R500_US_FC_CTRL, code->us_fc_ctrl); + for(i = 0; i < code->int_constant_count; i++){ + OUT_CB_REG(R500_US_FC_INT_CONST_0 + (i * 4), + code->int_constants[i]); + } + OUT_CB_REG(R500_US_CODE_RANGE, + R500_US_CODE_RANGE_ADDR(0) | R500_US_CODE_RANGE_SIZE(code->inst_end)); + OUT_CB_REG(R500_US_CODE_OFFSET, 0); + OUT_CB_REG(R500_US_CODE_ADDR, + R500_US_CODE_START_ADDR(0) | R500_US_CODE_END_ADDR(code->inst_end)); + + OUT_CB_REG(R500_GA_US_VECTOR_INDEX, R500_GA_US_VECTOR_INDEX_TYPE_INSTR); + OUT_CB_ONE_REG(R500_GA_US_VECTOR_DATA, (code->inst_end + 1) * 6); + for (i = 0; i <= code->inst_end; i++) { + OUT_CB(code->inst[i].inst0); + OUT_CB(code->inst[i].inst1); + OUT_CB(code->inst[i].inst2); + OUT_CB(code->inst[i].inst3); + OUT_CB(code->inst[i].inst4); + OUT_CB(code->inst[i].inst5); + } + + /* Emit immediates. */ + if (imm_count) { + for(i = imm_first; i < imm_end; ++i) { + if (constants[i].Type == RC_CONSTANT_IMMEDIATE) { + const float *data = constants[i].u.Immediate; + + OUT_CB_REG(R500_GA_US_VECTOR_INDEX, + R500_GA_US_VECTOR_INDEX_TYPE_CONST | + (i & R500_GA_US_VECTOR_INDEX_MASK)); + OUT_CB_ONE_REG(R500_GA_US_VECTOR_DATA, 4); + OUT_CB_TABLE(data, 4); + } + } + } + } else { /* r300 */ + struct r300_fragment_program_code *code = &generic_code->code.r300; + + shader->cb_code_size = 19 + + (r300->screen->caps.is_r400 ? 2 : 0) + + code->alu.length * 4 + + (code->tex.length ? (1 + code->tex.length) : 0) + + imm_count * 5; + + NEW_CB(shader->cb_code, shader->cb_code_size); + + if (r300->screen->caps.is_r400) + OUT_CB_REG(R400_US_CODE_BANK, 0); + + OUT_CB_REG(R300_US_CONFIG, code->config); + OUT_CB_REG(R300_US_PIXSIZE, code->pixsize); + OUT_CB_REG(R300_US_CODE_OFFSET, code->code_offset); + + OUT_CB_REG_SEQ(R300_US_CODE_ADDR_0, 4); + OUT_CB_TABLE(code->code_addr, 4); + + OUT_CB_REG_SEQ(R300_US_ALU_RGB_INST_0, code->alu.length); + for (i = 0; i < code->alu.length; i++) + OUT_CB(code->alu.inst[i].rgb_inst); + + OUT_CB_REG_SEQ(R300_US_ALU_RGB_ADDR_0, code->alu.length); + for (i = 0; i < code->alu.length; i++) + OUT_CB(code->alu.inst[i].rgb_addr); + + OUT_CB_REG_SEQ(R300_US_ALU_ALPHA_INST_0, code->alu.length); + for (i = 0; i < code->alu.length; i++) + OUT_CB(code->alu.inst[i].alpha_inst); + + OUT_CB_REG_SEQ(R300_US_ALU_ALPHA_ADDR_0, code->alu.length); + for (i = 0; i < code->alu.length; i++) + OUT_CB(code->alu.inst[i].alpha_addr); + + if (code->tex.length) { + OUT_CB_REG_SEQ(R300_US_TEX_INST_0, code->tex.length); + OUT_CB_TABLE(code->tex.inst, code->tex.length); + } + + /* Emit immediates. */ + if (imm_count) { + for(i = imm_first; i < imm_end; ++i) { + if (constants[i].Type == RC_CONSTANT_IMMEDIATE) { + const float *data = constants[i].u.Immediate; + + OUT_CB_REG_SEQ(R300_PFS_PARAM_0_X + i * 16, 4); + OUT_CB(pack_float24(data[0])); + OUT_CB(pack_float24(data[1])); + OUT_CB(pack_float24(data[2])); + OUT_CB(pack_float24(data[3])); + } + } + } + } + + OUT_CB_REG(R300_FG_DEPTH_SRC, shader->fg_depth_src); + OUT_CB_REG(R300_US_W_FMT, shader->us_out_w); + END_CB; +} + +static void r300_translate_fragment_shader( + struct r300_context* r300, + struct r300_fragment_shader_code* shader, + const struct tgsi_token *tokens) +{ + struct r300_fragment_program_compiler compiler; + struct tgsi_to_rc ttr; + int wpos, face; + unsigned i; + + tgsi_scan_shader(tokens, &shader->info); + r300_shader_read_fs_inputs(&shader->info, &shader->inputs); + + wpos = shader->inputs.wpos; + face = shader->inputs.face; + + /* Setup the compiler. */ + memset(&compiler, 0, sizeof(compiler)); + rc_init(&compiler.Base); + DBG_ON(r300, DBG_FP) ? compiler.Base.Debug |= RC_DBG_LOG : 0; + DBG_ON(r300, DBG_P_STAT) ? compiler.Base.Debug |= RC_DBG_STATS : 0; + + compiler.code = &shader->code; + compiler.state = shader->compare_state; + compiler.Base.is_r500 = r300->screen->caps.is_r500; + compiler.Base.disable_optimizations = DBG_ON(r300, DBG_NO_OPT); + compiler.Base.has_half_swizzles = TRUE; + compiler.Base.has_presub = TRUE; + compiler.Base.max_temp_regs = compiler.Base.is_r500 ? 128 : 32; + compiler.Base.max_constants = compiler.Base.is_r500 ? 256 : 32; + compiler.Base.max_alu_insts = compiler.Base.is_r500 ? 512 : 64; + compiler.AllocateHwInputs = &allocate_hardware_inputs; + compiler.UserData = &shader->inputs; + + find_output_registers(&compiler, shader); + + if (compiler.Base.Debug & RC_DBG_LOG) { + DBG(r300, DBG_FP, "r300: Initial fragment program\n"); + tgsi_dump(tokens, 0); + } + + /* Translate TGSI to our internal representation */ + ttr.compiler = &compiler.Base; + ttr.info = &shader->info; + ttr.use_half_swizzles = TRUE; + + r300_tgsi_to_rc(&ttr, tokens); + + if (!r300->screen->caps.is_r500 || + compiler.Base.Program.Constants.Count > 200) { + compiler.Base.remove_unused_constants = TRUE; + } + + /** + * Transform the program to support WPOS. + * + * Introduce a small fragment at the start of the program that will be + * the only code that directly reads the WPOS input. + * All other code pieces that reference that input will be rewritten + * to read from a newly allocated temporary. */ + if (wpos != ATTR_UNUSED) { + /* Moving the input to some other reg is not really necessary. */ + rc_transform_fragment_wpos(&compiler.Base, wpos, wpos, TRUE); + } + + if (face != ATTR_UNUSED) { + rc_transform_fragment_face(&compiler.Base, face); + } + + /* Invoke the compiler */ + r3xx_compile_fragment_program(&compiler); + + if (compiler.Base.Error) { + fprintf(stderr, "r300 FP: Compiler Error:\n%sUsing a dummy shader" + " instead.\n", compiler.Base.ErrorMsg); + + if (shader->dummy) { + fprintf(stderr, "r300 FP: Cannot compile the dummy shader! " + "Giving up...\n"); + abort(); + } + + rc_destroy(&compiler.Base); + r300_dummy_fragment_shader(r300, shader); + return; + } + + /* Shaders with zero instructions are invalid, + * use the dummy shader instead. */ + if (shader->code.code.r500.inst_end == -1) { + rc_destroy(&compiler.Base); + r300_dummy_fragment_shader(r300, shader); + return; + } + + /* Initialize numbers of constants for each type. */ + shader->externals_count = 0; + for (i = 0; + i < shader->code.constants.Count && + shader->code.constants.Constants[i].Type == RC_CONSTANT_EXTERNAL; i++) { + shader->externals_count = i+1; + } + shader->immediates_count = 0; + shader->rc_state_count = 0; + + for (i = shader->externals_count; i < shader->code.constants.Count; i++) { + switch (shader->code.constants.Constants[i].Type) { + case RC_CONSTANT_IMMEDIATE: + ++shader->immediates_count; + break; + case RC_CONSTANT_STATE: + ++shader->rc_state_count; + break; + default: + assert(0); + } + } + + /* Setup shader depth output. */ + if (shader->code.writes_depth) { + shader->fg_depth_src = R300_FG_DEPTH_SRC_SHADER; + shader->us_out_w = R300_W_FMT_W24 | R300_W_SRC_US; + } else { + shader->fg_depth_src = R300_FG_DEPTH_SRC_SCAN; + shader->us_out_w = R300_W_FMT_W0 | R300_W_SRC_US; + } + + /* And, finally... */ + rc_destroy(&compiler.Base); + + /* Build the command buffer. */ + r300_emit_fs_code_to_buffer(r300, shader); +} + +boolean r300_pick_fragment_shader(struct r300_context* r300) +{ + struct r300_fragment_shader* fs = r300_fs(r300); + struct r300_fragment_program_external_state state = {{{ 0 }}}; + struct r300_fragment_shader_code* ptr; + + get_external_state(r300, &state); + + if (!fs->first) { + /* Build the fragment shader for the first time. */ + fs->first = fs->shader = CALLOC_STRUCT(r300_fragment_shader_code); + + memcpy(&fs->shader->compare_state, &state, + sizeof(struct r300_fragment_program_external_state)); + r300_translate_fragment_shader(r300, fs->shader, fs->state.tokens); + return TRUE; + + } else { + /* Check if the currently-bound shader has been compiled + * with the texture-compare state we need. */ + if (memcmp(&fs->shader->compare_state, &state, sizeof(state)) != 0) { + /* Search for the right shader. */ + ptr = fs->first; + while (ptr) { + if (memcmp(&ptr->compare_state, &state, sizeof(state)) == 0) { + if (fs->shader != ptr) { + fs->shader = ptr; + return TRUE; + } + /* The currently-bound one is OK. */ + return FALSE; + } + ptr = ptr->next; + } + + /* Not found, gotta compile a new one. */ + ptr = CALLOC_STRUCT(r300_fragment_shader_code); + ptr->next = fs->first; + fs->first = fs->shader = ptr; + + ptr->compare_state = state; + r300_translate_fragment_shader(r300, ptr, fs->state.tokens); + return TRUE; + } + } + + return FALSE; +} diff --git a/src/gallium/drivers/r300/r300_fs.h b/src/gallium/drivers/r300/r300_fs.h new file mode 100644 index 0000000..51bfa88 --- /dev/null +++ b/src/gallium/drivers/r300/r300_fs.h @@ -0,0 +1,84 @@ +/* + * Copyright 2008 Corbin Simpson + * Joakim Sindholt + * Copyright 2009 Marek Olšák + * + * 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 R300_FS_H +#define R300_FS_H + +#include "pipe/p_state.h" +#include "tgsi/tgsi_scan.h" +#include "radeon_code.h" +#include "r300_shader_semantics.h" + +struct r300_fragment_shader_code { + struct tgsi_shader_info info; + struct r300_shader_semantics inputs; + + /* Whether the shader was replaced by a dummy one due to a shader + * compilation failure. */ + boolean dummy; + + /* Numbers of constants for each type. */ + unsigned externals_count; + unsigned immediates_count; + unsigned rc_state_count; + + /* Registers for fragment depth output setup. */ + uint32_t fg_depth_src; /* R300_FG_DEPTH_SRC: 0x4bd8 */ + uint32_t us_out_w; /* R300_US_W_FMT: 0x46b4 */ + + struct r300_fragment_program_external_state compare_state; + struct rX00_fragment_program_code code; + + unsigned cb_code_size; + uint32_t *cb_code; + + struct r300_fragment_shader_code* next; +}; + +struct r300_fragment_shader { + /* Parent class */ + struct pipe_shader_state state; + + /* Currently-bound fragment shader. */ + struct r300_fragment_shader_code* shader; + + /* List of the same shaders compiled with different texture-compare + * states. */ + struct r300_fragment_shader_code* first; +}; + +void r300_shader_read_fs_inputs(struct tgsi_shader_info* info, + struct r300_shader_semantics* fs_inputs); + +/* Return TRUE if the shader was switched and should be re-emitted. */ +boolean r300_pick_fragment_shader(struct r300_context* r300); + +static INLINE boolean r300_fragment_shader_writes_depth(struct r300_fragment_shader *fs) +{ + if (!fs) + return FALSE; + return (fs->shader->code.writes_depth) ? TRUE : FALSE; +} + +#endif /* R300_FS_H */ diff --git a/src/gallium/drivers/r300/r300_hyperz.c b/src/gallium/drivers/r300/r300_hyperz.c new file mode 100644 index 0000000..c22e307 --- /dev/null +++ b/src/gallium/drivers/r300/r300_hyperz.c @@ -0,0 +1,419 @@ +/* + * Copyright 2008 Corbin Simpson + * Copyright 2009 Marek Olšák + * + * 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 "r300_context.h" +#include "r300_hyperz.h" +#include "r300_reg.h" +#include "r300_fs.h" +#include "r300_winsys.h" + +#include "util/u_format.h" +#include "util/u_mm.h" + +/* + HiZ rules - taken from various docs + 1. HiZ only works on depth values + 2. Cannot HiZ if stencil fail or zfail is !KEEP + 3. on R300/400, HiZ is disabled if depth test is EQUAL + 4. comparison changes without clears usually mean disabling HiZ +*/ +/*****************************************************************************/ +/* The HyperZ setup */ +/*****************************************************************************/ + +static bool r300_get_sc_hz_max(struct r300_context *r300) +{ + struct r300_dsa_state *dsa_state = r300->dsa_state.state; + int func = dsa_state->z_stencil_control & R300_ZS_MASK; + int ret = R300_SC_HYPERZ_MIN; + + if (func >= R300_ZS_GEQUAL && func <= R300_ZS_ALWAYS) + ret = R300_SC_HYPERZ_MAX; + return ret; +} + +static bool r300_zfunc_same_direction(int func1, int func2) +{ + /* func1 is less/lessthan */ + if ((func1 == R300_ZS_LESS || func1 == R300_ZS_LEQUAL) && + (func2 == R300_ZS_EQUAL || func2 == R300_ZS_GEQUAL || + func2 == R300_ZS_GREATER)) + return FALSE; + + /* func1 is greater/greaterthan */ + if ((func1 == R300_ZS_GEQUAL || func1 == R300_ZS_GREATER) && + (func2 == R300_ZS_LESS || func2 == R300_ZS_LEQUAL)) + return FALSE; + + return TRUE; +} + +static int r300_get_hiz_min(struct r300_context *r300) +{ + struct r300_dsa_state *dsa_state = r300->dsa_state.state; + int func = dsa_state->z_stencil_control & R300_ZS_MASK; + int ret = R300_HIZ_MIN; + + if (func == R300_ZS_LESS || func == R300_ZS_LEQUAL) + ret = R300_HIZ_MAX; + return ret; +} + +static boolean r300_dsa_stencil_op_not_keep(struct pipe_stencil_state *s) +{ + if (s->enabled && (s->fail_op != PIPE_STENCIL_OP_KEEP || + s->zfail_op != PIPE_STENCIL_OP_KEEP)) + return TRUE; + return FALSE; +} + +static boolean r300_can_hiz(struct r300_context *r300) +{ + struct r300_dsa_state *dsa_state = r300->dsa_state.state; + struct pipe_depth_stencil_alpha_state *dsa = &dsa_state->dsa; + struct r300_screen* r300screen = r300->screen; + struct r300_hyperz_state *z = r300->hyperz_state.state; + + /* shader writes depth - no HiZ */ + if (r300_fragment_shader_writes_depth(r300_fs(r300))) /* (5) */ + return FALSE; + + if (r300->query_current) + return FALSE; + /* if stencil fail/zfail op is not KEEP */ + if (r300_dsa_stencil_op_not_keep(&dsa->stencil[0]) || + r300_dsa_stencil_op_not_keep(&dsa->stencil[1])) + return FALSE; + + if (dsa->depth.enabled) { + /* if depth func is EQUAL pre-r500 */ + if (dsa->depth.func == PIPE_FUNC_EQUAL && !r300screen->caps.is_r500) + return FALSE; + /* if depth func is NOTEQUAL */ + if (dsa->depth.func == PIPE_FUNC_NOTEQUAL) + return FALSE; + } + /* depth comparison function - if just cleared save and return okay */ + if (z->current_func == -1) { + int func = dsa_state->z_stencil_control & R300_ZS_MASK; + if (func != 0 && func != 7) + z->current_func = dsa_state->z_stencil_control & R300_ZS_MASK; + } else { + /* simple don't change */ + if (!r300_zfunc_same_direction(z->current_func, + (dsa_state->z_stencil_control & R300_ZS_MASK))) { + DBG(r300, DBG_HYPERZ, + "z func changed direction - disabling hyper-z %d -> %d\n", + z->current_func, dsa_state->z_stencil_control); + return FALSE; + } + } + return TRUE; +} + +static void r300_update_hyperz(struct r300_context* r300) +{ + struct r300_hyperz_state *z = + (struct r300_hyperz_state*)r300->hyperz_state.state; + struct pipe_framebuffer_state *fb = + (struct pipe_framebuffer_state*)r300->fb_state.state; + struct r300_texture *zstex = + fb->zsbuf ? r300_texture(fb->zsbuf->texture) : NULL; + boolean zmask_in_use = FALSE; + boolean hiz_in_use = FALSE; + + z->gb_z_peq_config = 0; + z->zb_bw_cntl = 0; + z->sc_hyperz = R300_SC_HYPERZ_ADJ_2; + z->flush = 0; + + if (r300->cbzb_clear) { + z->zb_bw_cntl |= R300_ZB_CB_CLEAR_CACHE_LINE_WRITE_ONLY; + return; + } + + if (!zstex) + return; + + if (!r300->rws->get_value(r300->rws, R300_CAN_HYPERZ)) + return; + + zmask_in_use = zstex->zmask_in_use[fb->zsbuf->u.tex.level]; + hiz_in_use = zstex->hiz_in_use[fb->zsbuf->u.tex.level]; + + /* Z fastfill. */ + if (zmask_in_use) { + z->zb_bw_cntl |= R300_FAST_FILL_ENABLE; /* | R300_FORCE_COMPRESSED_STENCIL_VALUE_ENABLE;*/ + } + + /* Zbuffer compression. */ + if (zmask_in_use && r300->z_compression) { + z->zb_bw_cntl |= R300_RD_COMP_ENABLE; + if (r300->z_decomp_rd == false) + z->zb_bw_cntl |= R300_WR_COMP_ENABLE; + } + /* RV350 and up optimizations. */ + /* The section 10.4.9 in the docs is a lie. */ + if (r300->z_compression == RV350_Z_COMPRESS_88) + z->gb_z_peq_config |= R300_GB_Z_PEQ_CONFIG_Z_PEQ_SIZE_8_8; + + if (hiz_in_use) { + bool can_hiz = r300_can_hiz(r300); + if (can_hiz) { + z->zb_bw_cntl |= R300_HIZ_ENABLE; + z->sc_hyperz |= R300_SC_HYPERZ_ENABLE; + z->sc_hyperz |= r300_get_sc_hz_max(r300); + z->zb_bw_cntl |= r300_get_hiz_min(r300); + } + } + + /* R500-specific features and optimizations. */ + if (r300->screen->caps.is_r500) { + z->zb_bw_cntl |= R500_HIZ_FP_EXP_BITS_3; + z->zb_bw_cntl |= + R500_HIZ_EQUAL_REJECT_ENABLE | + R500_PEQ_PACKING_ENABLE | + R500_COVERED_PTR_MASKING_ENABLE; + } +} + +/*****************************************************************************/ +/* The ZTOP state */ +/*****************************************************************************/ + +static boolean r300_dsa_writes_stencil( + struct pipe_stencil_state *s) +{ + return s->enabled && s->writemask && + (s->fail_op != PIPE_STENCIL_OP_KEEP || + s->zfail_op != PIPE_STENCIL_OP_KEEP || + s->zpass_op != PIPE_STENCIL_OP_KEEP); +} + +static boolean r300_dsa_writes_depth_stencil( + struct pipe_depth_stencil_alpha_state *dsa) +{ + /* We are interested only in the cases when a depth or stencil value + * can be changed. */ + + if (dsa->depth.enabled && dsa->depth.writemask && + dsa->depth.func != PIPE_FUNC_NEVER) + return TRUE; + + if (r300_dsa_writes_stencil(&dsa->stencil[0]) || + r300_dsa_writes_stencil(&dsa->stencil[1])) + return TRUE; + + return FALSE; +} + +static boolean r300_dsa_alpha_test_enabled( + struct pipe_depth_stencil_alpha_state *dsa) +{ + /* We are interested only in the cases when alpha testing can kill + * a fragment. */ + + return dsa->alpha.enabled && dsa->alpha.func != PIPE_FUNC_ALWAYS; +} + +static void r300_update_ztop(struct r300_context* r300) +{ + struct r300_ztop_state* ztop_state = + (struct r300_ztop_state*)r300->ztop_state.state; + uint32_t old_ztop = ztop_state->z_buffer_top; + + /* This is important enough that I felt it warranted a comment. + * + * According to the docs, these are the conditions where ZTOP must be + * disabled: + * 1) Alpha testing enabled + * 2) Texture kill instructions in fragment shader + * 3) Chroma key culling enabled + * 4) W-buffering enabled + * + * The docs claim that for the first three cases, if no ZS writes happen, + * then ZTOP can be used. + * + * (3) will never apply since we do not support chroma-keyed operations. + * (4) will need to be re-examined (and this comment updated) if/when + * Hyper-Z becomes supported. + * + * Additionally, the following conditions require disabled ZTOP: + * 5) Depth writes in fragment shader + * 6) Outstanding occlusion queries + * + * This register causes stalls all the way from SC to CB when changed, + * but it is buffered on-chip so it does not hurt to write it if it has + * not changed. + * + * ~C. + */ + + /* ZS writes */ + if (r300_dsa_writes_depth_stencil(r300->dsa_state.state) && + (r300_dsa_alpha_test_enabled(r300->dsa_state.state) || /* (1) */ + r300_fs(r300)->shader->info.uses_kill)) { /* (2) */ + ztop_state->z_buffer_top = R300_ZTOP_DISABLE; + } else if (r300_fragment_shader_writes_depth(r300_fs(r300))) { /* (5) */ + ztop_state->z_buffer_top = R300_ZTOP_DISABLE; + } else if (r300->query_current) { /* (6) */ + ztop_state->z_buffer_top = R300_ZTOP_DISABLE; + } else { + ztop_state->z_buffer_top = R300_ZTOP_ENABLE; + } + if (ztop_state->z_buffer_top != old_ztop) + r300_mark_atom_dirty(r300, &r300->ztop_state); +} + +#define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y)) + +static void r300_update_hiz_clear(struct r300_context *r300) +{ + struct pipe_framebuffer_state *fb = + (struct pipe_framebuffer_state*)r300->fb_state.state; + uint32_t height; + + height = ALIGN_DIVUP(fb->zsbuf->height, 4); + r300->hiz_clear.size = height * 4; +} + +static void r300_update_zmask_clear(struct r300_context *r300) +{ + struct pipe_framebuffer_state *fb = + (struct pipe_framebuffer_state*)r300->fb_state.state; + uint32_t height; + int mult; + + if (r300->z_compression == RV350_Z_COMPRESS_88) + mult = 8; + else + mult = 4; + + height = ALIGN_DIVUP(fb->zsbuf->height, mult); + + r300->zmask_clear.size = height * 4; +} + +void r300_update_hyperz_state(struct r300_context* r300) +{ + r300_update_ztop(r300); + if (r300->hyperz_state.dirty) { + r300_update_hyperz(r300); + } + + if (r300->hiz_clear.dirty) { + r300_update_hiz_clear(r300); + } + if (r300->zmask_clear.dirty) { + r300_update_zmask_clear(r300); + } +} + +void r300_hiz_alloc_block(struct r300_context *r300, struct r300_surface *surf) +{ + struct r300_texture *tex; + uint32_t zsize, ndw; + int level = surf->base.u.tex.level; + + tex = r300_texture(surf->base.texture); + + if (tex->hiz_mem[level]) + return; + + zsize = tex->desc.layer_size_in_bytes[level]; + zsize /= util_format_get_blocksize(tex->desc.b.b.format); + ndw = ALIGN_DIVUP(zsize, 64); + + tex->hiz_mem[level] = u_mmAllocMem(r300->hiz_mm, ndw, 0, 0); + return; +} + +void r300_zmask_alloc_block(struct r300_context *r300, struct r300_surface *surf, int compress) +{ + int bsize = 256; + uint32_t zsize, ndw; + int level = surf->base.u.tex.level; + struct r300_texture *tex; + + tex = r300_texture(surf->base.texture); + + /* We currently don't handle decompression for 3D textures and cubemaps + * correctly. */ + if (tex->desc.b.b.target != PIPE_TEXTURE_1D && + tex->desc.b.b.target != PIPE_TEXTURE_2D && + tex->desc.b.b.target != PIPE_TEXTURE_RECT) + return; + + /* Cannot flush zmask of 16-bit zbuffers. */ + if (util_format_get_blocksizebits(tex->desc.b.b.format) == 16) + return; + + if (tex->zmask_mem[level]) + return; + + zsize = tex->desc.layer_size_in_bytes[level]; + zsize /= util_format_get_blocksize(tex->desc.b.b.format); + + /* each zmask dword represents 16 4x4 blocks - which is 256 pixels + or 16 8x8 depending on the gb peq flag = 1024 pixels */ + if (compress == RV350_Z_COMPRESS_88) + bsize = 1024; + + ndw = ALIGN_DIVUP(zsize, bsize); + tex->zmask_mem[level] = u_mmAllocMem(r300->zmask_mm, ndw, 0, 0); + return; +} + +boolean r300_hyperz_init_mm(struct r300_context *r300) +{ + struct r300_screen* r300screen = r300->screen; + int frag_pipes = r300screen->caps.num_frag_pipes; + + r300->zmask_mm = u_mmInit(0, r300screen->caps.zmask_ram * frag_pipes); + if (!r300->zmask_mm) + return FALSE; + + if (r300screen->caps.hiz_ram) { + r300->hiz_mm = u_mmInit(0, r300screen->caps.hiz_ram * frag_pipes); + if (!r300->hiz_mm) { + u_mmDestroy(r300->zmask_mm); + r300->zmask_mm = NULL; + return FALSE; + } + } + + return TRUE; +} + +void r300_hyperz_destroy_mm(struct r300_context *r300) +{ + struct r300_screen* r300screen = r300->screen; + + if (r300screen->caps.hiz_ram) { + u_mmDestroy(r300->hiz_mm); + r300->hiz_mm = NULL; + } + + u_mmDestroy(r300->zmask_mm); + r300->zmask_mm = NULL; +} diff --git a/src/gallium/drivers/r300/r300_hyperz.h b/src/gallium/drivers/r300/r300_hyperz.h new file mode 100644 index 0000000..30a23ec --- /dev/null +++ b/src/gallium/drivers/r300/r300_hyperz.h @@ -0,0 +1,35 @@ +/* + * Copyright 2010 Marek Olšák + * + * 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 R300_HYPERZ_H +#define R300_HYPERZ_H + +struct r300_context; + +void r300_update_hyperz_state(struct r300_context* r300); + +void r300_hiz_alloc_block(struct r300_context *r300, struct r300_surface *surf); +void r300_zmask_alloc_block(struct r300_context *r300, struct r300_surface *surf, int compress); + +boolean r300_hyperz_init_mm(struct r300_context *r300); +void r300_hyperz_destroy_mm(struct r300_context *r300); +#endif diff --git a/src/gallium/drivers/r300/r300_public.h b/src/gallium/drivers/r300/r300_public.h new file mode 100644 index 0000000..8e7a963 --- /dev/null +++ b/src/gallium/drivers/r300/r300_public.h @@ -0,0 +1,9 @@ + +#ifndef R300_PUBLIC_H +#define R300_PUBLIC_H + +struct r300_winsys_screen; + +struct pipe_screen* r300_screen_create(struct r300_winsys_screen *rws); + +#endif diff --git a/src/gallium/drivers/r300/r300_query.c b/src/gallium/drivers/r300/r300_query.c new file mode 100644 index 0000000..6223e04 --- /dev/null +++ b/src/gallium/drivers/r300/r300_query.c @@ -0,0 +1,236 @@ +/* + * Copyright 2009 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 "util/u_memory.h" +#include "util/u_simple_list.h" + +#include "r300_context.h" +#include "r300_screen.h" +#include "r300_emit.h" +#include "r300_winsys.h" + +#include + +static struct pipe_query *r300_create_query(struct pipe_context *pipe, + unsigned query_type) +{ + struct r300_context *r300 = r300_context(pipe); + struct r300_screen *r300screen = r300->screen; + struct r300_query *q; + + if (query_type != PIPE_QUERY_OCCLUSION_COUNTER) { + return NULL; + } + + q = CALLOC_STRUCT(r300_query); + if (!q) + return NULL; + + q->type = query_type; + q->domain = R300_DOMAIN_GTT; + q->buffer_size = 4096; + + if (r300screen->caps.family == CHIP_FAMILY_RV530) + q->num_pipes = r300screen->caps.num_z_pipes; + else + q->num_pipes = r300screen->caps.num_frag_pipes; + + insert_at_tail(&r300->query_list, q); + + /* Open up the occlusion query buffer. */ + q->buffer = r300->rws->buffer_create(r300->rws, q->buffer_size, 4096, + PIPE_BIND_CUSTOM, PIPE_USAGE_STREAM, + q->domain); + q->cs_buffer = r300->rws->buffer_get_cs_handle(r300->rws, q->buffer); + + return (struct pipe_query*)q; +} + +static void r300_destroy_query(struct pipe_context* pipe, + struct pipe_query* query) +{ + struct r300_context *r300 = r300_context(pipe); + struct r300_query* q = r300_query(query); + + r300->rws->buffer_reference(r300->rws, &q->buffer, NULL); + remove_from_list(q); + FREE(query); +} + +void r300_resume_query(struct r300_context *r300, + struct r300_query *query) +{ + r300->query_current = query; + r300_mark_atom_dirty(r300, &r300->query_start); +} + +static void r300_begin_query(struct pipe_context* pipe, + struct pipe_query* query) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_query* q = r300_query(query); + + if (r300->query_current != NULL) { + fprintf(stderr, "r300: begin_query: " + "Some other query has already been started.\n"); + assert(0); + return; + } + + q->num_results = 0; + r300_resume_query(r300, q); +} + +void r300_stop_query(struct r300_context *r300) +{ + r300_emit_query_end(r300); + r300->query_current = NULL; +} + +static void r300_end_query(struct pipe_context* pipe, + struct pipe_query* query) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_query *q = r300_query(query); + + if (q != r300->query_current) { + fprintf(stderr, "r300: end_query: Got invalid query.\n"); + assert(0); + return; + } + + r300_stop_query(r300); +} + +static boolean r300_get_query_result(struct pipe_context* pipe, + struct pipe_query* query, + boolean wait, + void* vresult) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_query *q = r300_query(query); + unsigned flags, i; + uint32_t temp, *map; + uint64_t *result = (uint64_t*)vresult; + + if (!q->flushed) + pipe->flush(pipe, 0, NULL); + + flags = PIPE_TRANSFER_READ | (!wait ? PIPE_TRANSFER_DONTBLOCK : 0); + + map = r300->rws->buffer_map(r300->rws, q->buffer, r300->cs, flags); + if (!map) + return FALSE; + + /* Sum up the results. */ + temp = 0; + for (i = 0; i < q->num_results; i++) { + temp += *map; + map++; + } + + r300->rws->buffer_unmap(r300->rws, q->buffer); + + *result = temp; + return TRUE; +} + +static void r300_render_condition(struct pipe_context *pipe, + struct pipe_query *query, + uint mode) +{ + struct r300_context *r300 = r300_context(pipe); + uint64_t result = 0; + boolean wait; + + if (query) { + wait = mode == PIPE_RENDER_COND_WAIT || + mode == PIPE_RENDER_COND_BY_REGION_WAIT; + + if (!r300_get_query_result(pipe, query, wait, &result)) { + r300->skip_rendering = FALSE; + } else { + r300->skip_rendering = result == 0; + } + } else { + r300->skip_rendering = FALSE; + } +} + +/*************************************************************************** + * Fake occlusion queries (for debugging) + ***************************************************************************/ + +static unsigned r300_fake_query; + +static struct pipe_query *r300_fake_create_query(struct pipe_context *pipe, + unsigned query_type) +{ + return (struct pipe_query*)&r300_fake_query; +} + +static void r300_fake_destroy_query(struct pipe_context* pipe, + struct pipe_query* query) +{ +} + +static void r300_fake_begin_query(struct pipe_context* pipe, + struct pipe_query* query) +{ +} + +static void r300_fake_end_query(struct pipe_context* pipe, + struct pipe_query* query) +{ +} + +static boolean r300_fake_get_query_result(struct pipe_context* pipe, + struct pipe_query* query, + boolean wait, void* vresult) +{ + uint64_t *result = (uint64_t*)vresult; + *result = 1000000; + return TRUE; +} + +static void r300_fake_render_condition(struct pipe_context *pipe, + struct pipe_query *query, uint mode) +{ +} + +void r300_init_query_functions(struct r300_context* r300) { + if (DBG_ON(r300, DBG_FAKE_OCC)) { + r300->context.create_query = r300_fake_create_query; + r300->context.destroy_query = r300_fake_destroy_query; + r300->context.begin_query = r300_fake_begin_query; + r300->context.end_query = r300_fake_end_query; + r300->context.get_query_result = r300_fake_get_query_result; + r300->context.render_condition = r300_fake_render_condition; + } else { + r300->context.create_query = r300_create_query; + r300->context.destroy_query = r300_destroy_query; + r300->context.begin_query = r300_begin_query; + r300->context.end_query = r300_end_query; + r300->context.get_query_result = r300_get_query_result; + r300->context.render_condition = r300_render_condition; + } +} diff --git a/src/gallium/drivers/r300/r300_reg.h b/src/gallium/drivers/r300/r300_reg.h new file mode 100644 index 0000000..613186e --- /dev/null +++ b/src/gallium/drivers/r300/r300_reg.h @@ -0,0 +1,3533 @@ +/************************************************************************** + +Copyright (C) 2004-2005 Nicolai Haehnle et al. + +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. + +**************************************************************************/ + +/* *INDENT-OFF* */ + +#ifndef _R300_REG_H +#define _R300_REG_H + +#define R300_MC_INIT_MISC_LAT_TIMER 0x180 +# define R300_MC_MISC__MC_CPR_INIT_LAT_SHIFT 0 +# define R300_MC_MISC__MC_VF_INIT_LAT_SHIFT 4 +# define R300_MC_MISC__MC_DISP0R_INIT_LAT_SHIFT 8 +# define R300_MC_MISC__MC_DISP1R_INIT_LAT_SHIFT 12 +# define R300_MC_MISC__MC_FIXED_INIT_LAT_SHIFT 16 +# define R300_MC_MISC__MC_E2R_INIT_LAT_SHIFT 20 +# define R300_MC_MISC__MC_SAME_PAGE_PRIO_SHIFT 24 +# define R300_MC_MISC__MC_GLOBW_INIT_LAT_SHIFT 28 + + +#define R300_MC_INIT_GFX_LAT_TIMER 0x154 +# define R300_MC_MISC__MC_G3D0R_INIT_LAT_SHIFT 0 +# define R300_MC_MISC__MC_G3D1R_INIT_LAT_SHIFT 4 +# define R300_MC_MISC__MC_G3D2R_INIT_LAT_SHIFT 8 +# define R300_MC_MISC__MC_G3D3R_INIT_LAT_SHIFT 12 +# define R300_MC_MISC__MC_TX0R_INIT_LAT_SHIFT 16 +# define R300_MC_MISC__MC_TX1R_INIT_LAT_SHIFT 20 +# define R300_MC_MISC__MC_GLOBR_INIT_LAT_SHIFT 24 +# define R300_MC_MISC__MC_GLOBW_FULL_LAT_SHIFT 28 + +/* + * This file contains registers and constants for the R300. They have been + * found mostly by examining command buffers captured using glxtest, as well + * as by extrapolating some known registers and constants from the R200. + * I am fairly certain that they are correct unless stated otherwise + * in comments. + */ + +#define R300_SE_VPORT_XSCALE 0x1D98 +#define R300_SE_VPORT_XOFFSET 0x1D9C +#define R300_SE_VPORT_YSCALE 0x1DA0 +#define R300_SE_VPORT_YOFFSET 0x1DA4 +#define R300_SE_VPORT_ZSCALE 0x1DA8 +#define R300_SE_VPORT_ZOFFSET 0x1DAC + +#define R300_VAP_PORT_IDX0 0x2040 +/* + * Vertex Array Processing (VAP) Control + */ +#define R300_VAP_CNTL 0x2080 +# define R300_PVS_NUM_SLOTS_SHIFT 0 +# define R300_PVS_NUM_CNTLRS_SHIFT 4 +# define R300_PVS_NUM_FPUS_SHIFT 8 +# define R300_VF_MAX_VTX_NUM_SHIFT 18 +# define R300_PVS_NUM_SLOTS(x) ((x) << 0) +# define R300_PVS_NUM_CNTLRS(x) ((x) << 4) +# define R300_PVS_NUM_FPUS(x) ((x) << 8) +# define R300_PVS_VF_MAX_VTX_NUM(x) ((x) << 18) +# define R300_GL_CLIP_SPACE_DEF (0 << 22) +# define R300_DX_CLIP_SPACE_DEF (1 << 22) +# define R500_TCL_STATE_OPTIMIZATION (1 << 23) + +/* This register is written directly and also starts data section + * in many 3d CP_PACKET3's + */ +#define R300_VAP_VF_CNTL 0x2084 +# define R300_VAP_VF_CNTL__PRIM_TYPE__SHIFT 0 +# define R300_VAP_VF_CNTL__PRIM_NONE (0<<0) +# define R300_VAP_VF_CNTL__PRIM_POINTS (1<<0) +# define R300_VAP_VF_CNTL__PRIM_LINES (2<<0) +# define R300_VAP_VF_CNTL__PRIM_LINE_STRIP (3<<0) +# define R300_VAP_VF_CNTL__PRIM_TRIANGLES (4<<0) +# define R300_VAP_VF_CNTL__PRIM_TRIANGLE_FAN (5<<0) +# define R300_VAP_VF_CNTL__PRIM_TRIANGLE_STRIP (6<<0) +# define R300_VAP_VF_CNTL__PRIM_LINE_LOOP (12<<0) +# define R300_VAP_VF_CNTL__PRIM_QUADS (13<<0) +# define R300_VAP_VF_CNTL__PRIM_QUAD_STRIP (14<<0) +# define R300_VAP_VF_CNTL__PRIM_POLYGON (15<<0) + +# define R300_VAP_VF_CNTL__PRIM_WALK__SHIFT 4 + /* State based - direct writes to registers trigger vertex + generation */ +# define R300_VAP_VF_CNTL__PRIM_WALK_STATE_BASED (0<<4) +# define R300_VAP_VF_CNTL__PRIM_WALK_INDICES (1<<4) +# define R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST (2<<4) +# define R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_EMBEDDED (3<<4) + + /* I don't think I saw these three used.. */ +# define R300_VAP_VF_CNTL__COLOR_ORDER__SHIFT 6 +# define R300_VAP_VF_CNTL__TCL_OUTPUT_CTL_ENA__SHIFT 9 +# define R300_VAP_VF_CNTL__PROG_STREAM_ENA__SHIFT 10 + + /* index size - when not set the indices are assumed to be 16 bit */ +# define R300_VAP_VF_CNTL__INDEX_SIZE_32bit (1<<11) +# define R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS (1<<14) + /* number of vertices */ +# define R300_VAP_VF_CNTL__NUM_VERTICES__SHIFT 16 + +#define R500_VAP_INDEX_OFFSET 0x208c + +#define R500_VAP_ALT_NUM_VERTICES 0x2088 + +#define R300_VAP_OUTPUT_VTX_FMT_0 0x2090 +# define R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT (1<<0) +# define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT (1<<1) +# define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_1_PRESENT (1<<2) +# define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_2_PRESENT (1<<3) +# define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_3_PRESENT (1<<4) +# define R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT (1<<16) + +#define R300_VAP_OUTPUT_VTX_FMT_1 0x2094 + /* each of the following is 3 bits wide, specifies number + of components */ +# define R300_VAP_OUTPUT_VTX_FMT_1__TEX_0_COMP_CNT_SHIFT 0 +# define R300_VAP_OUTPUT_VTX_FMT_1__TEX_1_COMP_CNT_SHIFT 3 +# define R300_VAP_OUTPUT_VTX_FMT_1__TEX_2_COMP_CNT_SHIFT 6 +# define R300_VAP_OUTPUT_VTX_FMT_1__TEX_3_COMP_CNT_SHIFT 9 +# define R300_VAP_OUTPUT_VTX_FMT_1__TEX_4_COMP_CNT_SHIFT 12 +# define R300_VAP_OUTPUT_VTX_FMT_1__TEX_5_COMP_CNT_SHIFT 15 +# define R300_VAP_OUTPUT_VTX_FMT_1__TEX_6_COMP_CNT_SHIFT 18 +# define R300_VAP_OUTPUT_VTX_FMT_1__TEX_7_COMP_CNT_SHIFT 21 +# define R300_VAP_OUTPUT_VTX_FMT_1__NOT_PRESENT 0 +# define R300_VAP_OUTPUT_VTX_FMT_1__1_COMPONENT 1 +# define R300_VAP_OUTPUT_VTX_FMT_1__2_COMPONENTS 2 +# define R300_VAP_OUTPUT_VTX_FMT_1__3_COMPONENTS 3 +# define R300_VAP_OUTPUT_VTX_FMT_1__4_COMPONENTS 4 + +#define R300_VAP_VPORT_XSCALE 0x2098 +#define R300_VAP_VPORT_XOFFSET 0x209c +#define R300_VAP_VPORT_YSCALE 0x20a0 +#define R300_VAP_VPORT_YOFFSET 0x20a4 +#define R300_VAP_VPORT_ZSCALE 0x20a8 +#define R300_VAP_VPORT_ZOFFSET 0x20ac + +#define R300_VAP_VTE_CNTL 0x20b0 +#define R300_SE_VTE_CNTL R300_VAP_VTE_CNTL +# define R300_VPORT_X_SCALE_ENA (1 << 0) +# define R300_VPORT_X_OFFSET_ENA (1 << 1) +# define R300_VPORT_Y_SCALE_ENA (1 << 2) +# define R300_VPORT_Y_OFFSET_ENA (1 << 3) +# define R300_VPORT_Z_SCALE_ENA (1 << 4) +# define R300_VPORT_Z_OFFSET_ENA (1 << 5) +# define R300_VTX_XY_FMT (1 << 8) +# define R300_VTX_Z_FMT (1 << 9) +# define R300_VTX_W0_FMT (1 << 10) +# define R300_SERIAL_PROC_ENA (1 << 11) + +#define R300_VAP_VTX_SIZE 0x20b4 + +/* BEGIN: Vertex data assembly - lots of uncertainties */ + +/* gap */ + +/* Maximum Vertex Indx Clamp */ +#define R300_VAP_VF_MAX_VTX_INDX 0x2134 +/* Minimum Vertex Indx Clamp */ +#define R300_VAP_VF_MIN_VTX_INDX 0x2138 + +/** Vertex assembler/processor control status */ +#define R300_VAP_CNTL_STATUS 0x2140 +/* No swap at all (default) */ +# define R300_VC_NO_SWAP (0 << 0) +/* 16-bit swap: 0xAABBCCDD becomes 0xBBAADDCC */ +# define R300_VC_16BIT_SWAP (1 << 0) +/* 32-bit swap: 0xAABBCCDD becomes 0xDDCCBBAA */ +# define R300_VC_32BIT_SWAP (2 << 0) +/* Half-dword swap: 0xAABBCCDD becomes 0xCCDDAABB */ +# define R300_VC_HALF_DWORD_SWAP (3 << 0) +/* The TCL engine will not be used (as it is logically or even physically removed) */ +# define R300_VAP_TCL_BYPASS (1 << 8) +/* Read only flag if TCL engine is busy. */ +# define R300_VAP_PVS_BUSY (1 << 11) +/* TODO: gap for MAX_MPS */ +/* Read only flag if the vertex store is busy. */ +# define R300_VAP_VS_BUSY (1 << 24) +/* Read only flag if the reciprocal engine is busy. */ +# define R300_VAP_RCP_BUSY (1 << 25) +/* Read only flag if the viewport transform engine is busy. */ +# define R300_VAP_VTE_BUSY (1 << 26) +/* Read only flag if the memory interface unit is busy. */ +# define R300_VAP_MUI_BUSY (1 << 27) +/* Read only flag if the vertex cache is busy. */ +# define R300_VAP_VC_BUSY (1 << 28) +/* Read only flag if the vertex fetcher is busy. */ +# define R300_VAP_VF_BUSY (1 << 29) +/* Read only flag if the register pipeline is busy. */ +# define R300_VAP_REGPIPE_BUSY (1 << 30) +/* Read only flag if the VAP engine is busy. */ +# define R300_VAP_VAP_BUSY (1 << 31) + +/* gap */ + +/* Where do we get our vertex data? + * + * Vertex data either comes either from immediate mode registers or from + * vertex arrays. + * There appears to be no mixed mode (though we can force the pitch of + * vertex arrays to 0, effectively reusing the same element over and over + * again). + * + * Immediate mode is controlled by the INPUT_CNTL registers. I am not sure + * if these registers influence vertex array processing. + * + * Vertex arrays are controlled via the 3D_LOAD_VBPNTR packet3. + * + * In both cases, vertex attributes are then passed through INPUT_ROUTE. + * + * Beginning with INPUT_ROUTE_0_0 is a list of WORDs that route vertex data + * into the vertex processor's input registers. + * The first word routes the first input, the second word the second, etc. + * The corresponding input is routed into the register with the given index. + * The list is ended by a word with INPUT_ROUTE_END set. + * + * Always set COMPONENTS_4 in immediate mode. + */ + +#define R300_VAP_PROG_STREAM_CNTL_0 0x2150 +# define R300_DATA_TYPE_0_SHIFT 0 +# define R300_DATA_TYPE_FLOAT_1 0 +# define R300_DATA_TYPE_FLOAT_2 1 +# define R300_DATA_TYPE_FLOAT_3 2 +# define R300_DATA_TYPE_FLOAT_4 3 +# define R300_DATA_TYPE_BYTE 4 +# define R300_DATA_TYPE_D3DCOLOR 5 +# define R300_DATA_TYPE_SHORT_2 6 +# define R300_DATA_TYPE_SHORT_4 7 +# define R300_DATA_TYPE_VECTOR_3_TTT 8 +# define R300_DATA_TYPE_VECTOR_3_EET 9 +# define R300_DATA_TYPE_FLOAT_8 10 +# define R300_DATA_TYPE_FLT16_2 11 +# define R300_DATA_TYPE_FLT16_4 12 +# define R300_SKIP_DWORDS_SHIFT 4 +# define R300_DST_VEC_LOC_SHIFT 8 +# define R300_LAST_VEC (1 << 13) +# define R300_SIGNED (1 << 14) +# define R300_NORMALIZE (1 << 15) +# define R300_DATA_TYPE_1_SHIFT 16 +#define R300_VAP_PROG_STREAM_CNTL_1 0x2154 +#define R300_VAP_PROG_STREAM_CNTL_2 0x2158 +#define R300_VAP_PROG_STREAM_CNTL_3 0x215C +#define R300_VAP_PROG_STREAM_CNTL_4 0x2160 +#define R300_VAP_PROG_STREAM_CNTL_5 0x2164 +#define R300_VAP_PROG_STREAM_CNTL_6 0x2168 +#define R300_VAP_PROG_STREAM_CNTL_7 0x216C +/* gap */ + +/* Notes: + * - always set up to produce at least two attributes: + * if vertex program uses only position, fglrx will set normal, too + * - INPUT_CNTL_0_COLOR and INPUT_CNTL_COLOR bits are always equal. + */ +#define R300_VAP_VTX_STATE_CNTL 0x2180 +# define R300_COLOR_0_ASSEMBLY_SHIFT 0 +# define R300_SEL_COLOR 0 +# define R300_SEL_USER_COLOR_0 1 +# define R300_SEL_USER_COLOR_1 2 +# define R300_COLOR_1_ASSEMBLY_SHIFT 2 +# define R300_COLOR_2_ASSEMBLY_SHIFT 4 +# define R300_COLOR_3_ASSEMBLY_SHIFT 6 +# define R300_COLOR_4_ASSEMBLY_SHIFT 8 +# define R300_COLOR_5_ASSEMBLY_SHIFT 10 +# define R300_COLOR_6_ASSEMBLY_SHIFT 12 +# define R300_COLOR_7_ASSEMBLY_SHIFT 14 +# define R300_UPDATE_USER_COLOR_0_ENA (1 << 16) + +/* + * Each bit in this field applies to the corresponding vector in the VSM + * memory (i.e. Bit 0 applies to VECTOR_0 (POSITION), etc.). If the bit + * is set, then the corresponding 4-Dword Vector is output into the Vertex Stream. + */ +#define R300_VAP_VSM_VTX_ASSM 0x2184 +# define R300_INPUT_CNTL_POS 0x00000001 +# define R300_INPUT_CNTL_NORMAL 0x00000002 +# define R300_INPUT_CNTL_COLOR 0x00000004 +# define R300_INPUT_CNTL_TC0 0x00000400 +# define R300_INPUT_CNTL_TC1 0x00000800 +# define R300_INPUT_CNTL_TC2 0x00001000 /* GUESS */ +# define R300_INPUT_CNTL_TC3 0x00002000 /* GUESS */ +# define R300_INPUT_CNTL_TC4 0x00004000 /* GUESS */ +# define R300_INPUT_CNTL_TC5 0x00008000 /* GUESS */ +# define R300_INPUT_CNTL_TC6 0x00010000 /* GUESS */ +# define R300_INPUT_CNTL_TC7 0x00020000 /* GUESS */ + +/* Programmable Stream Control Signed Normalize Control */ +#define R300_VAP_PSC_SGN_NORM_CNTL 0x21dc +# define SGN_NORM_ZERO 0 +# define SGN_NORM_ZERO_CLAMP_MINUS_ONE 1 +# define SGN_NORM_NO_ZERO 2 +# define R300_SGN_NORM_NO_ZERO (SGN_NORM_NO_ZERO | \ + (SGN_NORM_NO_ZERO << 2) | (SGN_NORM_NO_ZERO << 4) | \ + (SGN_NORM_NO_ZERO << 6) | (SGN_NORM_NO_ZERO << 8) | \ + (SGN_NORM_NO_ZERO << 10) | (SGN_NORM_NO_ZERO << 12) | \ + (SGN_NORM_NO_ZERO << 14) | (SGN_NORM_NO_ZERO << 16) | \ + (SGN_NORM_NO_ZERO << 18) | (SGN_NORM_NO_ZERO << 20) | \ + (SGN_NORM_NO_ZERO << 22) | (SGN_NORM_NO_ZERO << 24) | \ + (SGN_NORM_NO_ZERO << 26) | (SGN_NORM_NO_ZERO << 28) | \ + (SGN_NORM_NO_ZERO << 30)) + +/* gap */ + +/* Words parallel to INPUT_ROUTE_0; All words that are active in INPUT_ROUTE_0 + * are set to a swizzling bit pattern, other words are 0. + * + * In immediate mode, the pattern is always set to xyzw. In vertex array + * mode, the swizzling pattern is e.g. used to set zw components in texture + * coordinates with only tweo components. + */ +#define R300_VAP_PROG_STREAM_CNTL_EXT_0 0x21e0 +# define R300_SWIZZLE0_SHIFT 0 +# define R300_SWIZZLE_SELECT_X_SHIFT 0 +# define R300_SWIZZLE_SELECT_Y_SHIFT 3 +# define R300_SWIZZLE_SELECT_Z_SHIFT 6 +# define R300_SWIZZLE_SELECT_W_SHIFT 9 + +# define R300_SWIZZLE_SELECT_X 0 +# define R300_SWIZZLE_SELECT_Y 1 +# define R300_SWIZZLE_SELECT_Z 2 +# define R300_SWIZZLE_SELECT_W 3 +# define R300_SWIZZLE_SELECT_FP_ZERO 4 +# define R300_SWIZZLE_SELECT_FP_ONE 5 +/* alternate forms for r300_emit.c */ +# define R300_INPUT_ROUTE_SELECT_X 0 +# define R300_INPUT_ROUTE_SELECT_Y 1 +# define R300_INPUT_ROUTE_SELECT_Z 2 +# define R300_INPUT_ROUTE_SELECT_W 3 +# define R300_INPUT_ROUTE_SELECT_ZERO 4 +# define R300_INPUT_ROUTE_SELECT_ONE 5 + +# define R300_WRITE_ENA_SHIFT 12 +# define R300_WRITE_ENA_X 1 +# define R300_WRITE_ENA_Y 2 +# define R300_WRITE_ENA_Z 4 +# define R300_WRITE_ENA_W 8 +# define R300_SWIZZLE1_SHIFT 16 + +# define R300_VAP_SWIZZLE_X001 \ + ((R300_SWIZZLE_SELECT_X << R300_SWIZZLE_SELECT_X_SHIFT) | \ + (R300_SWIZZLE_SELECT_FP_ZERO << R300_SWIZZLE_SELECT_Y_SHIFT) | \ + (R300_SWIZZLE_SELECT_FP_ZERO << R300_SWIZZLE_SELECT_Z_SHIFT) | \ + (R300_SWIZZLE_SELECT_FP_ONE << R300_SWIZZLE_SELECT_W_SHIFT) | \ + (0xf << R300_WRITE_ENA_SHIFT)) + +# define R300_VAP_SWIZZLE_XY01 \ + ((R300_SWIZZLE_SELECT_X << R300_SWIZZLE_SELECT_X_SHIFT) | \ + (R300_SWIZZLE_SELECT_Y << R300_SWIZZLE_SELECT_Y_SHIFT) | \ + (R300_SWIZZLE_SELECT_FP_ZERO << R300_SWIZZLE_SELECT_Z_SHIFT) | \ + (R300_SWIZZLE_SELECT_FP_ONE << R300_SWIZZLE_SELECT_W_SHIFT) | \ + (0xf << R300_WRITE_ENA_SHIFT)) + +# define R300_VAP_SWIZZLE_XYZ1 \ + ((R300_SWIZZLE_SELECT_X << R300_SWIZZLE_SELECT_X_SHIFT) | \ + (R300_SWIZZLE_SELECT_Y << R300_SWIZZLE_SELECT_Y_SHIFT) | \ + (R300_SWIZZLE_SELECT_Z << R300_SWIZZLE_SELECT_Z_SHIFT) | \ + (R300_SWIZZLE_SELECT_FP_ONE << R300_SWIZZLE_SELECT_W_SHIFT) | \ + (0xf << R300_WRITE_ENA_SHIFT)) + +# define R300_VAP_SWIZZLE_XYZW \ + ((R300_SWIZZLE_SELECT_X << R300_SWIZZLE_SELECT_X_SHIFT) | \ + (R300_SWIZZLE_SELECT_Y << R300_SWIZZLE_SELECT_Y_SHIFT) | \ + (R300_SWIZZLE_SELECT_Z << R300_SWIZZLE_SELECT_Z_SHIFT) | \ + (R300_SWIZZLE_SELECT_W << R300_SWIZZLE_SELECT_W_SHIFT) | \ + (0xf << R300_WRITE_ENA_SHIFT)) + +#define R300_VAP_PROG_STREAM_CNTL_EXT_1 0x21e4 +#define R300_VAP_PROG_STREAM_CNTL_EXT_2 0x21e8 +#define R300_VAP_PROG_STREAM_CNTL_EXT_3 0x21ec +#define R300_VAP_PROG_STREAM_CNTL_EXT_4 0x21f0 +#define R300_VAP_PROG_STREAM_CNTL_EXT_5 0x21f4 +#define R300_VAP_PROG_STREAM_CNTL_EXT_6 0x21f8 +#define R300_VAP_PROG_STREAM_CNTL_EXT_7 0x21fc + +/* END: Vertex data assembly */ + +/* gap */ + +/* BEGIN: Upload vertex program and data */ + +/* + * The programmable vertex shader unit has a memory bank of unknown size + * that can be written to in 16 byte units by writing the address into + * UPLOAD_ADDRESS, followed by data in UPLOAD_DATA (multiples of 4 DWORDs). + * + * Pointers into the memory bank are always in multiples of 16 bytes. + * + * The memory bank is divided into areas with fixed meaning. + * + * Starting at address UPLOAD_PROGRAM: Vertex program instructions. + * Native limits reported by drivers from ATI suggest size 256 (i.e. 4KB), + * whereas the difference between known addresses suggests size 512. + * + * Starting at address UPLOAD_PARAMETERS: Vertex program parameters. + * Native reported limits and the VPI layout suggest size 256, whereas + * difference between known addresses suggests size 512. + * + * At address UPLOAD_POINTSIZE is a vector (0, 0, ps, 0), where ps is the + * floating point pointsize. The exact purpose of this state is uncertain, + * as there is also the R300_RE_POINTSIZE register. + * + * Multiple vertex programs and parameter sets can be loaded at once, + * which could explain the size discrepancy. + */ +#define R300_VAP_PVS_VECTOR_INDX_REG 0x2200 +# define R300_PVS_CODE_START 0 +# define R300_MAX_PVS_CODE_LINES 256 +# define R500_MAX_PVS_CODE_LINES 1024 +# define R300_PVS_CONST_START 512 +# define R500_PVS_CONST_START 1024 +# define R300_MAX_PVS_CONST_VECS 256 +# define R500_MAX_PVS_CONST_VECS 256 +# define R300_PVS_UCP_START 1024 +# define R500_PVS_UCP_START 1536 +# define R300_POINT_VPORT_SCALE_OFFSET 1030 +# define R500_POINT_VPORT_SCALE_OFFSET 1542 +# define R300_POINT_GEN_TEX_OFFSET 1031 +# define R500_POINT_GEN_TEX_OFFSET 1543 + +/* + * These are obsolete defines form r300_context.h, but they might give some + * clues when investigating the addresses further... + */ +#if 0 +#define VSF_DEST_PROGRAM 0x0 +#define VSF_DEST_MATRIX0 0x200 +#define VSF_DEST_MATRIX1 0x204 +#define VSF_DEST_MATRIX2 0x208 +#define VSF_DEST_VECTOR0 0x20c +#define VSF_DEST_VECTOR1 0x20d +#define VSF_DEST_UNKNOWN1 0x400 +#define VSF_DEST_UNKNOWN2 0x406 +#endif + +/* gap */ + +#define R300_VAP_PVS_UPLOAD_DATA 0x2208 + +/* END: Upload vertex program and data */ + +/* gap */ + +/* I do not know the purpose of this register. However, I do know that + * it is set to 221C_CLEAR for clear operations and to 221C_NORMAL + * for normal rendering. + * + * 2007-11-05: This register is the user clip plane control register, but there + * also seems to be a rendering mode control; the NORMAL/CLEAR defines. + * + * See bug #9871. http://bugs.freedesktop.org/attachment.cgi?id=10672&action=view + */ +#define R300_VAP_CLIP_CNTL 0x221C +# define R300_VAP_UCP_ENABLE_0 (1 << 0) +# define R300_VAP_UCP_ENABLE_1 (1 << 1) +# define R300_VAP_UCP_ENABLE_2 (1 << 2) +# define R300_VAP_UCP_ENABLE_3 (1 << 3) +# define R300_VAP_UCP_ENABLE_4 (1 << 4) +# define R300_VAP_UCP_ENABLE_5 (1 << 5) +# define R300_PS_UCP_MODE_DIST_COP (0 << 14) +# define R300_PS_UCP_MODE_RADIUS_COP (1 << 14) +# define R300_PS_UCP_MODE_RADIUS_COP_CLIP (2 << 14) +# define R300_PS_UCP_MODE_CLIP_AS_TRIFAN (3 << 14) +# define R300_CLIP_DISABLE (1 << 16) +# define R300_UCP_CULL_ONLY_ENABLE (1 << 17) +# define R300_BOUNDARY_EDGE_FLAG_ENABLE (1 << 18) +# define R500_COLOR2_IS_TEXTURE (1 << 20) +# define R500_COLOR3_IS_TEXTURE (1 << 21) + +/* These seem to be per-pixel and per-vertex X and Y clipping planes. The first + * plane is per-pixel and the second plane is per-vertex. + * + * This was determined by experimentation alone but I believe it is correct. + * + * These registers are called X_QUAD0_1_FL to X_QUAD0_4_FL by glxtest. + */ +#define R300_VAP_GB_VERT_CLIP_ADJ 0x2220 +#define R300_VAP_GB_VERT_DISC_ADJ 0x2224 +#define R300_VAP_GB_HORZ_CLIP_ADJ 0x2228 +#define R300_VAP_GB_HORZ_DISC_ADJ 0x222c + +#define R300_VAP_PVS_FLOW_CNTL_ADDRS_0 0x2230 +#define R300_PVS_FC_ACT_ADRS(x) ((x) << 0) +#define R300_PVS_FC_LOOP_CNT_JMP_INST(x) ((x) << 8) +#define R300_PVS_FC_LAST_INST(x) ((x) << 16) +#define R300_PVS_FC_RTN_INST(x) ((x) << 24) + +/* gap */ + +/* Sometimes, END_OF_PKT and 0x2284=0 are the only commands sent between + * rendering commands and overwriting vertex program parameters. + * Therefore, I suspect writing zero to 0x2284 synchronizes the engine and + * avoids bugs caused by still running shaders reading bad data from memory. + */ +#define R300_VAP_PVS_STATE_FLUSH_REG 0x2284 + +/* This register is used to define the number of core clocks to wait for a + * vertex to be received by the VAP input controller (while the primitive + * path is backed up) before forcing any accumulated vertices to be submitted + * to the vertex processing path. + */ +#define VAP_PVS_VTX_TIMEOUT_REG 0x2288 +# define R300_2288_R300 0x00750000 /* -- nh */ +# define R300_2288_RV350 0x0000FFFF /* -- Vladimir */ + +#define R300_VAP_PVS_FLOW_CNTL_LOOP_INDEX_0 0x2290 +#define R300_PVS_FC_LOOP_INIT_VAL(x) ((x) << 0) +#define R300_PVS_FC_LOOP_STEP_VAL(x) ((x) << 8) + +/* gap */ + +/* Addresses are relative to the vertex program instruction area of the + * memory bank. PROGRAM_END points to the last instruction of the active + * program + * + * The meaning of the two UNKNOWN fields is obviously not known. However, + * experiments so far have shown that both *must* point to an instruction + * inside the vertex program, otherwise the GPU locks up. + * + * fglrx usually sets CNTL_3_UNKNOWN to the end of the program and + * R300_PVS_CNTL_1_POS_END_SHIFT points to instruction where last write to + * position takes place. + * + * Most likely this is used to ignore rest of the program in cases + * where group of verts arent visible. For some reason this "section" + * is sometimes accepted other instruction that have no relationship with + * position calculations. + */ +#define R300_VAP_PVS_CODE_CNTL_0 0x22D0 +# define R300_PVS_FIRST_INST_SHIFT 0 +# define R300_PVS_XYZW_VALID_INST_SHIFT 10 +# define R300_PVS_LAST_INST_SHIFT 20 +# define R300_PVS_FIRST_INST(x) ((x) << 0) +# define R300_PVS_XYZW_VALID_INST(x) ((x) << 10) +# define R300_PVS_LAST_INST(x) ((x) << 20) +/* Addresses are relative to the vertex program parameters area. */ +#define R300_VAP_PVS_CONST_CNTL 0x22D4 +# define R300_PVS_CONST_BASE_OFFSET_SHIFT 0 +# define R300_PVS_CONST_BASE_OFFSET(x) (x) +# define R300_PVS_MAX_CONST_ADDR_SHIFT 16 +# define R300_PVS_MAX_CONST_ADDR(x) ((x) << 16) +#define R300_VAP_PVS_CODE_CNTL_1 0x22D8 +# define R300_PVS_LAST_VTX_SRC_INST_SHIFT 0 +#define R300_VAP_PVS_FLOW_CNTL_OPC 0x22DC +#define R300_VAP_PVS_FC_OPC_JUMP(x) (1 << (2 * (x))) +#define R300_VAP_PVS_FC_OPC_LOOP(x) (2 << (2 * (x))) +#define R300_VAP_PVS_FC_OPC_JSR(x) (3 << (2 * (x))) + +/* The entire range from 0x2300 to 0x2AC inclusive seems to be used for + * immediate vertices + */ +#define R300_VAP_VTX_COLOR_R 0x2464 +#define R300_VAP_VTX_COLOR_G 0x2468 +#define R300_VAP_VTX_COLOR_B 0x246C +#define R300_VAP_VTX_POS_0_X_1 0x2490 /* used for glVertex2*() */ +#define R300_VAP_VTX_POS_0_Y_1 0x2494 +#define R300_VAP_VTX_COLOR_PKD 0x249C /* RGBA */ +#define R300_VAP_VTX_POS_0_X_2 0x24A0 /* used for glVertex3*() */ +#define R300_VAP_VTX_POS_0_Y_2 0x24A4 +#define R300_VAP_VTX_POS_0_Z_2 0x24A8 +/* write 0 to indicate end of packet? */ +#define R300_VAP_VTX_END_OF_PKT 0x24AC + +#define R500_VAP_PVS_FLOW_CNTL_ADDRS_LW_0 0x2500 +#define R500_PVS_FC_ACT_ADRS(x) ((x) << 0) +#define R500_PVS_FC_LOOP_CNT_JMP_INST(x) ((x) << 16) + +#define R500_VAP_PVS_FLOW_CNTL_ADDRS_UW_0 0x2504 +#define R500_PVS_FC_LAST_INST(x) ((x) << 0) +#define R500_PVS_FC_RTN_INST(x) ((x) << 16) + +/* gap */ + +/* These are values from r300_reg/r300_reg.h - they are known to be correct + * and are here so we can use one register file instead of several + * - Vladimir + */ +#define R300_GB_VAP_RASTER_VTX_FMT_0 0x4000 +# define R300_GB_VAP_RASTER_VTX_FMT_0__POS_PRESENT (1<<0) +# define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_0_PRESENT (1<<1) +# define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_1_PRESENT (1<<2) +# define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_2_PRESENT (1<<3) +# define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_3_PRESENT (1<<4) +# define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_SPACE (0xf<<5) +# define R300_GB_VAP_RASTER_VTX_FMT_0__PT_SIZE_PRESENT (0x1<<16) + +#define R300_GB_VAP_RASTER_VTX_FMT_1 0x4004 + /* each of the following is 3 bits wide, specifies number + of components */ +# define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_0_COMP_CNT_SHIFT 0 +# define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_1_COMP_CNT_SHIFT 3 +# define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_2_COMP_CNT_SHIFT 6 +# define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_3_COMP_CNT_SHIFT 9 +# define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_4_COMP_CNT_SHIFT 12 +# define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_5_COMP_CNT_SHIFT 15 +# define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_6_COMP_CNT_SHIFT 18 +# define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_7_COMP_CNT_SHIFT 21 + +/* UNK30 seems to enables point to quad transformation on textures + * (or something closely related to that). + * This bit is rather fatal at the time being due to lackings at pixel + * shader side + * Specifies top of Raster pipe specific enable controls. + */ +#define R300_GB_ENABLE 0x4008 +# define R300_GB_POINT_STUFF_DISABLE (0 << 0) +# define R300_GB_POINT_STUFF_ENABLE (1 << 0) /* Specifies if points will have stuffed texture coordinates. */ +# define R300_GB_LINE_STUFF_DISABLE (0 << 1) +# define R300_GB_LINE_STUFF_ENABLE (1 << 1) /* Specifies if lines will have stuffed texture coordinates. */ +# define R300_GB_TRIANGLE_STUFF_DISABLE (0 << 2) +# define R300_GB_TRIANGLE_STUFF_ENABLE (1 << 2) /* Specifies if triangles will have stuffed texture coordinates. */ +# define R300_GB_STENCIL_AUTO_DISABLE (0 << 4) +# define R300_GB_STENCIL_AUTO_ENABLE (1 << 4) /* Enable stencil auto inc/dec based on triangle cw/ccw, force into dzy low bit. */ +# define R300_GB_STENCIL_AUTO_FORCE (2 << 4) /* Force 0 into dzy low bit. */ + + /* each of the following is 2 bits wide */ +#define R300_GB_TEX_REPLICATE 0 /* Replicate VAP source texture coordinates (S,T,[R,Q]). */ +#define R300_GB_TEX_ST 1 /* Stuff with source texture coordinates (S,T). */ +#define R300_GB_TEX_STR 2 /* Stuff with source texture coordinates (S,T,R). */ +# define R300_GB_TEX0_SOURCE_SHIFT 16 +# define R300_GB_TEX1_SOURCE_SHIFT 18 +# define R300_GB_TEX2_SOURCE_SHIFT 20 +# define R300_GB_TEX3_SOURCE_SHIFT 22 +# define R300_GB_TEX4_SOURCE_SHIFT 24 +# define R300_GB_TEX5_SOURCE_SHIFT 26 +# define R300_GB_TEX6_SOURCE_SHIFT 28 +# define R300_GB_TEX7_SOURCE_SHIFT 30 + +/* MSPOS - positions for multisample antialiasing (?) */ +#define R300_GB_MSPOS0 0x4010 + /* shifts - each of the fields is 4 bits */ +# define R300_GB_MSPOS0__MS_X0_SHIFT 0 +# define R300_GB_MSPOS0__MS_Y0_SHIFT 4 +# define R300_GB_MSPOS0__MS_X1_SHIFT 8 +# define R300_GB_MSPOS0__MS_Y1_SHIFT 12 +# define R300_GB_MSPOS0__MS_X2_SHIFT 16 +# define R300_GB_MSPOS0__MS_Y2_SHIFT 20 +# define R300_GB_MSPOS0__MSBD0_Y 24 +# define R300_GB_MSPOS0__MSBD0_X 28 + +#define R300_GB_MSPOS1 0x4014 +# define R300_GB_MSPOS1__MS_X3_SHIFT 0 +# define R300_GB_MSPOS1__MS_Y3_SHIFT 4 +# define R300_GB_MSPOS1__MS_X4_SHIFT 8 +# define R300_GB_MSPOS1__MS_Y4_SHIFT 12 +# define R300_GB_MSPOS1__MS_X5_SHIFT 16 +# define R300_GB_MSPOS1__MS_Y5_SHIFT 20 +# define R300_GB_MSPOS1__MSBD1 24 + +/* Specifies the graphics pipeline configuration for rasterization. */ +#define R300_GB_TILE_CONFIG 0x4018 +# define R300_GB_TILE_DISABLE (0 << 0) +# define R300_GB_TILE_ENABLE (1 << 0) +# define R300_GB_TILE_PIPE_COUNT_RV300 (0 << 1) /* RV350 (1 pipe, 1 ctx) */ +# define R300_GB_TILE_PIPE_COUNT_R300 (3 << 1) /* R300 (2 pipes, 1 ctx) */ +# define R300_GB_TILE_PIPE_COUNT_R420_3P (6 << 1) /* R420-3P (3 pipes, 1 ctx) */ +# define R300_GB_TILE_PIPE_COUNT_R420 (7 << 1) /* R420 (4 pipes, 1 ctx) */ +# define R300_GB_TILE_SIZE_8 (0 << 4) +# define R300_GB_TILE_SIZE_16 (1 << 4) +# define R300_GB_TILE_SIZE_32 (2 << 4) +# define R300_GB_SUPER_SIZE_1 (0 << 6) +# define R300_GB_SUPER_SIZE_2 (1 << 6) +# define R300_GB_SUPER_SIZE_4 (2 << 6) +# define R300_GB_SUPER_SIZE_8 (3 << 6) +# define R300_GB_SUPER_SIZE_16 (4 << 6) +# define R300_GB_SUPER_SIZE_32 (5 << 6) +# define R300_GB_SUPER_SIZE_64 (6 << 6) +# define R300_GB_SUPER_SIZE_128 (7 << 6) +# define R300_GB_SUPER_X_SHIFT 9 /* 3 bits wide */ +# define R300_GB_SUPER_Y_SHIFT 12 /* 3 bits wide */ +# define R300_GB_SUPER_TILE_A (0 << 15) +# define R300_GB_SUPER_TILE_B (1 << 15) +# define R300_GB_SUBPIXEL_1_12 (0 << 16) +# define R300_GB_SUBPIXEL_1_16 (1 << 16) +# define R300_GB_TILE_CONFIG_QUADS_PER_RAS_4 (0 << 17) +# define R300_GB_TILE_CONFIG_QUADS_PER_RAS_8 (1 << 17) +# define R300_GB_TILE_CONFIG_QUADS_PER_RAS_16 (2 << 17) +# define R300_GB_TILE_CONFIG_QUADS_PER_RAS_32 (3 << 17) +# define R300_GB_TILE_CONFIG_BB_SCAN_INTERCEPT (0 << 19) +# define R300_GB_TILE_CONFIG_BB_SCAN_BOUND_BOX (1 << 19) +# define R300_GB_TILE_CONFIG_ALT_SCAN_EN_LR (0 << 20) +# define R300_GB_TILE_CONFIG_ALT_SCAN_EN_LRL (1 << 20) +# define R300_GB_TILE_CONFIG_ALT_OFFSET (0 << 21) +# define R300_GB_TILE_CONFIG_SUBPRECISION (0 << 22) +# define R300_GB_TILE_CONFIG_ALT_TILING_DEF (0 << 23) +# define R300_GB_TILE_CONFIG_ALT_TILING_3_2 (1 << 23) +# define R300_GB_TILE_CONFIG_Z_EXTENDED_24_1 (0 << 24) +# define R300_GB_TILE_CONFIG_Z_EXTENDED_S25_1 (1 << 24) + +/* Specifies the sizes of the various FIFO`s in the sc/rs/us. This register must be the first one written */ +#define R300_GB_FIFO_SIZE 0x4024 + /* each of the following is 2 bits wide */ +#define R300_GB_FIFO_SIZE_32 0 +#define R300_GB_FIFO_SIZE_64 1 +#define R300_GB_FIFO_SIZE_128 2 +#define R300_GB_FIFO_SIZE_256 3 +# define R300_SC_IFIFO_SIZE_SHIFT 0 +# define R300_SC_TZFIFO_SIZE_SHIFT 2 +# define R300_SC_BFIFO_SIZE_SHIFT 4 + +# define R300_US_OFIFO_SIZE_SHIFT 12 +# define R300_US_WFIFO_SIZE_SHIFT 14 + /* the following use the same constants as above, but meaning is + is times 2 (i.e. instead of 32 words it means 64 */ +# define R300_RS_TFIFO_SIZE_SHIFT 6 +# define R300_RS_CFIFO_SIZE_SHIFT 8 +# define R300_US_RAM_SIZE_SHIFT 10 + /* watermarks, 3 bits wide */ +# define R300_RS_HIGHWATER_COL_SHIFT 16 +# define R300_RS_HIGHWATER_TEX_SHIFT 19 +# define R300_OFIFO_HIGHWATER_SHIFT 22 /* two bits only */ +# define R300_CUBE_FIFO_HIGHWATER_COL_SHIFT 24 + +#define R300_GB_Z_PEQ_CONFIG 0x4028 +# define R300_GB_Z_PEQ_CONFIG_Z_PEQ_SIZE_4_4 (0 << 0) +# define R300_GB_Z_PEQ_CONFIG_Z_PEQ_SIZE_8_8 (1 << 0) + +/* Specifies various polygon specific selects (fog, depth, perspective). */ +#define R300_GB_SELECT 0x401c +# define R300_GB_FOG_SELECT_C0A (0 << 0) +# define R300_GB_FOG_SELECT_C1A (1 << 0) +# define R300_GB_FOG_SELECT_C2A (2 << 0) +# define R300_GB_FOG_SELECT_C3A (3 << 0) +# define R300_GB_FOG_SELECT_1_1_W (4 << 0) +# define R300_GB_FOG_SELECT_Z (5 << 0) +# define R300_GB_DEPTH_SELECT_Z (0 << 3) +# define R300_GB_DEPTH_SELECT_1_1_W (1 << 3) +# define R300_GB_W_SELECT_1_W (0 << 4) +# define R300_GB_W_SELECT_1 (1 << 4) +# define R300_GB_FOG_STUFF_DISABLE (0 << 5) +# define R300_GB_FOG_STUFF_ENABLE (1 << 5) +# define R300_GB_FOG_STUFF_TEX_SHIFT 6 +# define R300_GB_FOG_STUFF_TEX_MASK 0x000003c0 +# define R300_GB_FOG_STUFF_COMP_SHIFT 10 +# define R300_GB_FOG_STUFF_COMP_MASK 0x00000c00 + +/* Specifies the graphics pipeline configuration for antialiasing. */ +#define R300_GB_AA_CONFIG 0x4020 +# define R300_GB_AA_CONFIG_AA_DISABLE (0 << 0) +# define R300_GB_AA_CONFIG_AA_ENABLE (1 << 0) +# define R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_2 (0 << 1) +# define R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_3 (1 << 1) +# define R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_4 (2 << 1) +# define R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_6 (3 << 1) + +/* Selects which of 4 pipes are active. */ +#define R300_GB_PIPE_SELECT 0x402c +# define R300_GB_PIPE_SELECT_PIPE0_ID_SHIFT 0 +# define R300_GB_PIPE_SELECT_PIPE1_ID_SHIFT 2 +# define R300_GB_PIPE_SELECT_PIPE2_ID_SHIFT 4 +# define R300_GB_PIPE_SELECT_PIPE3_ID_SHIFT 6 +# define R300_GB_PIPE_SELECT_PIPE_MASK_SHIFT 8 +# define R300_GB_PIPE_SELECT_MAX_PIPE 12 +# define R300_GB_PIPE_SELECT_BAD_PIPES 14 +# define R300_GB_PIPE_SELECT_CONFIG_PIPES 18 + + +/* Specifies the sizes of the various FIFO`s in the sc/rs. */ +#define R300_GB_FIFO_SIZE1 0x4070 +/* High water mark for SC input fifo */ +# define R300_GB_FIFO_SIZE1_SC_HIGHWATER_IFIFO_SHIFT 0 +# define R300_GB_FIFO_SIZE1_SC_HIGHWATER_IFIFO_MASK 0x0000003f +/* High water mark for SC input fifo (B) */ +# define R300_GB_FIFO_SIZE1_SC_HIGHWATER_BFIFO_SHIFT 6 +# define R300_GB_FIFO_SIZE1_SC_HIGHWATER_BFIFO_MASK 0x00000fc0 +/* High water mark for RS colors' fifo */ +# define R300_GB_FIFO_SIZE1_SC_HIGHWATER_COL_SHIFT 12 +# define R300_GB_FIFO_SIZE1_SC_HIGHWATER_COL_MASK 0x0003f000 +/* High water mark for RS textures' fifo */ +# define R300_GB_FIFO_SIZE1_SC_HIGHWATER_TEX_SHIFT 18 +# define R300_GB_FIFO_SIZE1_SC_HIGHWATER_TEX_MASK 0x00fc0000 + +/* This table specifies the source location and format for up to 16 texture + * addresses (i[0]:i[15]) and four colors (c[0]:c[3]) + */ +#define R500_RS_IP_0 0x4074 +#define R500_RS_IP_1 0x4078 +#define R500_RS_IP_2 0x407C +#define R500_RS_IP_3 0x4080 +#define R500_RS_IP_4 0x4084 +#define R500_RS_IP_5 0x4088 +#define R500_RS_IP_6 0x408C +#define R500_RS_IP_7 0x4090 +#define R500_RS_IP_8 0x4094 +#define R500_RS_IP_9 0x4098 +#define R500_RS_IP_10 0x409C +#define R500_RS_IP_11 0x40A0 +#define R500_RS_IP_12 0x40A4 +#define R500_RS_IP_13 0x40A8 +#define R500_RS_IP_14 0x40AC +#define R500_RS_IP_15 0x40B0 +#define R500_RS_IP_PTR_K0 62 +#define R500_RS_IP_PTR_K1 63 +#define R500_RS_IP_TEX_PTR_S_SHIFT 0 +#define R500_RS_IP_TEX_PTR_T_SHIFT 6 +#define R500_RS_IP_TEX_PTR_R_SHIFT 12 +#define R500_RS_IP_TEX_PTR_Q_SHIFT 18 +#define R500_RS_IP_COL_PTR_SHIFT 24 +#define R500_RS_IP_COL_FMT_SHIFT 27 +# define R500_RS_SEL_S(x) ((x) << 0) +# define R500_RS_SEL_T(x) ((x) << 6) +# define R500_RS_SEL_R(x) ((x) << 12) +# define R500_RS_SEL_Q(x) ((x) << 18) +# define R500_RS_COL_PTR(x) ((x) << 24) +# define R500_RS_COL_FMT(x) ((x) << 27) +/* gap */ +#define R500_RS_IP_OFFSET_DIS (0 << 31) +#define R500_RS_IP_OFFSET_EN (1 << 31) + +/* gap */ + +/* Zero to flush caches. */ +#define R300_TX_INVALTAGS 0x4100 +#define R300_TX_FLUSH 0x0 + +/* The upper enable bits are guessed, based on fglrx reported limits. */ +#define R300_TX_ENABLE 0x4104 +# define R300_TX_ENABLE_0 (1 << 0) +# define R300_TX_ENABLE_1 (1 << 1) +# define R300_TX_ENABLE_2 (1 << 2) +# define R300_TX_ENABLE_3 (1 << 3) +# define R300_TX_ENABLE_4 (1 << 4) +# define R300_TX_ENABLE_5 (1 << 5) +# define R300_TX_ENABLE_6 (1 << 6) +# define R300_TX_ENABLE_7 (1 << 7) +# define R300_TX_ENABLE_8 (1 << 8) +# define R300_TX_ENABLE_9 (1 << 9) +# define R300_TX_ENABLE_10 (1 << 10) +# define R300_TX_ENABLE_11 (1 << 11) +# define R300_TX_ENABLE_12 (1 << 12) +# define R300_TX_ENABLE_13 (1 << 13) +# define R300_TX_ENABLE_14 (1 << 14) +# define R300_TX_ENABLE_15 (1 << 15) + +#define R500_TX_FILTER_4 0x4110 +# define R500_TX_WEIGHT_1_SHIFT (0) +# define R500_TX_WEIGHT_0_SHIFT (11) +# define R500_TX_WEIGHT_PAIR (1<<22) +# define R500_TX_PHASE_SHIFT (23) +# define R500_TX_DIRECTION_HORIZONTAL (0<<27) +# define R500_TX_DIRECTION_VERITCAL (1<<27) + +/* S Texture Coordinate of Vertex 0 for Point texture stuffing (LLC) */ +#define R300_GA_POINT_S0 0x4200 + +/* T Texture Coordinate of Vertex 0 for Point texture stuffing (LLC) */ +#define R300_GA_POINT_T0 0x4204 + +/* S Texture Coordinate of Vertex 2 for Point texture stuffing (URC) */ +#define R300_GA_POINT_S1 0x4208 + +/* T Texture Coordinate of Vertex 2 for Point texture stuffing (URC) */ +#define R300_GA_POINT_T1 0x420c + +/* Specifies amount to shift integer position of vertex (screen space) before + * converting to float for triangle stipple. + */ +#define R300_GA_TRIANGLE_STIPPLE 0x4214 +# define R300_GA_TRIANGLE_STIPPLE_X_SHIFT_SHIFT 0 +# define R300_GA_TRIANGLE_STIPPLE_X_SHIFT_MASK 0x0000000f +# define R300_GA_TRIANGLE_STIPPLE_Y_SHIFT_SHIFT 16 +# define R300_GA_TRIANGLE_STIPPLE_Y_SHIFT_MASK 0x000f0000 + +/* The pointsize is given in multiples of 6. The pointsize can be enormous: + * Clear() renders a single point that fills the entire framebuffer. + * 1/2 Height of point; fixed (16.0), subpixel format (1/12 or 1/16, even if in + * 8b precision). + */ +#define R300_GA_POINT_SIZE 0x421C +# define R300_POINTSIZE_Y_SHIFT 0 +# define R300_POINTSIZE_Y_MASK 0x0000ffff +# define R300_POINTSIZE_X_SHIFT 16 +# define R300_POINTSIZE_X_MASK 0xffff0000 +# define R300_POINTSIZE_MAX (R300_POINTSIZE_Y_MASK / 6) + +/* Red fill color */ +#define R500_GA_FILL_R 0x4220 + +/* Green fill color */ +#define R500_GA_FILL_G 0x4224 + +/* Blue fill color */ +#define R500_GA_FILL_B 0x4228 + +/* Alpha fill color */ +#define R500_GA_FILL_A 0x422c + + +/* Specifies maximum and minimum point & sprite sizes for per vertex size + * specification. The lower part (15:0) is MIN and (31:16) is max. + */ +#define R300_GA_POINT_MINMAX 0x4230 +# define R300_GA_POINT_MINMAX_MIN_SHIFT 0 +# define R300_GA_POINT_MINMAX_MIN_MASK (0xFFFF << 0) +# define R300_GA_POINT_MINMAX_MAX_SHIFT 16 +# define R300_GA_POINT_MINMAX_MAX_MASK (0xFFFF << 16) + +/* 1/2 width of line, in subpixels (1/12 or 1/16 only, even in 8b + * subprecision); (16.0) fixed format. + * + * The line width is given in multiples of 6. + * In default mode lines are classified as vertical lines. + * HO: horizontal + * VE: vertical or horizontal + * HO & VE: no classification + */ +#define R300_GA_LINE_CNTL 0x4234 +# define R300_GA_LINE_CNTL_WIDTH_SHIFT 0 +# define R300_GA_LINE_CNTL_WIDTH_MASK 0x0000ffff +# define R300_GA_LINE_CNTL_END_TYPE_HOR (0 << 16) +# define R300_GA_LINE_CNTL_END_TYPE_VER (1 << 16) +# define R300_GA_LINE_CNTL_END_TYPE_SQR (2 << 16) /* horizontal or vertical depending upon slope */ +# define R300_GA_LINE_CNTL_END_TYPE_COMP (3 << 16) /* Computed (perpendicular to slope) */ +# define R500_GA_LINE_CNTL_SORT_NO (0 << 18) +# define R500_GA_LINE_CNTL_SORT_MINX_MINY (1 << 18) +/** TODO: looks wrong */ +# define R300_LINESIZE_MAX (R300_GA_LINE_CNTL_WIDTH_MASK / 6) +/** TODO: looks wrong */ +# define R300_LINE_CNT_HO (1 << 16) +/** TODO: looks wrong */ +# define R300_LINE_CNT_VE (1 << 17) + +/* Line Stipple configuration information. */ +#define R300_GA_LINE_STIPPLE_CONFIG 0x4238 +# define R300_GA_LINE_STIPPLE_CONFIG_LINE_RESET_NO (0 << 0) +# define R300_GA_LINE_STIPPLE_CONFIG_LINE_RESET_LINE (1 << 0) +# define R300_GA_LINE_STIPPLE_CONFIG_LINE_RESET_PACKET (2 << 0) +# define R300_GA_LINE_STIPPLE_CONFIG_STIPPLE_SCALE_SHIFT 2 +# define R300_GA_LINE_STIPPLE_CONFIG_STIPPLE_SCALE_MASK 0xfffffffc + +/* Used to load US instructions and constants */ +#define R500_GA_US_VECTOR_INDEX 0x4250 +# define R500_GA_US_VECTOR_INDEX_SHIFT 0 +# define R500_GA_US_VECTOR_INDEX_MASK 0x000000ff +# define R500_GA_US_VECTOR_INDEX_TYPE_INSTR (0 << 16) +# define R500_GA_US_VECTOR_INDEX_TYPE_CONST (1 << 16) +# define R500_GA_US_VECTOR_INDEX_CLAMP_NO (0 << 17) +# define R500_GA_US_VECTOR_INDEX_CLAMP_CONST (1 << 17) + +/* Data register for loading US instructions and constants */ +#define R500_GA_US_VECTOR_DATA 0x4254 + +/* Specifies color properties and mappings of textures. */ +#define R500_GA_COLOR_CONTROL_PS3 0x4258 +# define R500_TEX0_SHADING_PS3_SOLID (0 << 0) +# define R500_TEX0_SHADING_PS3_FLAT (1 << 0) +# define R500_TEX0_SHADING_PS3_GOURAUD (2 << 0) +# define R500_TEX1_SHADING_PS3_SOLID (0 << 2) +# define R500_TEX1_SHADING_PS3_FLAT (1 << 2) +# define R500_TEX1_SHADING_PS3_GOURAUD (2 << 2) +# define R500_TEX2_SHADING_PS3_SOLID (0 << 4) +# define R500_TEX2_SHADING_PS3_FLAT (1 << 4) +# define R500_TEX2_SHADING_PS3_GOURAUD (2 << 4) +# define R500_TEX3_SHADING_PS3_SOLID (0 << 6) +# define R500_TEX3_SHADING_PS3_FLAT (1 << 6) +# define R500_TEX3_SHADING_PS3_GOURAUD (2 << 6) +# define R500_TEX4_SHADING_PS3_SOLID (0 << 8) +# define R500_TEX4_SHADING_PS3_FLAT (1 << 8) +# define R500_TEX4_SHADING_PS3_GOURAUD (2 << 8) +# define R500_TEX5_SHADING_PS3_SOLID (0 << 10) +# define R500_TEX5_SHADING_PS3_FLAT (1 << 10) +# define R500_TEX5_SHADING_PS3_GOURAUD (2 << 10) +# define R500_TEX6_SHADING_PS3_SOLID (0 << 12) +# define R500_TEX6_SHADING_PS3_FLAT (1 << 12) +# define R500_TEX6_SHADING_PS3_GOURAUD (2 << 12) +# define R500_TEX7_SHADING_PS3_SOLID (0 << 14) +# define R500_TEX7_SHADING_PS3_FLAT (1 << 14) +# define R500_TEX7_SHADING_PS3_GOURAUD (2 << 14) +# define R500_TEX8_SHADING_PS3_SOLID (0 << 16) +# define R500_TEX8_SHADING_PS3_FLAT (1 << 16) +# define R500_TEX8_SHADING_PS3_GOURAUD (2 << 16) +# define R500_TEX9_SHADING_PS3_SOLID (0 << 18) +# define R500_TEX9_SHADING_PS3_FLAT (1 << 18) +# define R500_TEX9_SHADING_PS3_GOURAUD (2 << 18) +# define R500_TEX10_SHADING_PS3_SOLID (0 << 20) +# define R500_TEX10_SHADING_PS3_FLAT (1 << 20) +# define R500_TEX10_SHADING_PS3_GOURAUD (2 << 20) +# define R500_COLOR0_TEX_OVERRIDE_NO (0 << 22) +# define R500_COLOR0_TEX_OVERRIDE_TEX_0 (1 << 22) +# define R500_COLOR0_TEX_OVERRIDE_TEX_1 (2 << 22) +# define R500_COLOR0_TEX_OVERRIDE_TEX_2 (3 << 22) +# define R500_COLOR0_TEX_OVERRIDE_TEX_3 (4 << 22) +# define R500_COLOR0_TEX_OVERRIDE_TEX_4 (5 << 22) +# define R500_COLOR0_TEX_OVERRIDE_TEX_5 (6 << 22) +# define R500_COLOR0_TEX_OVERRIDE_TEX_6 (7 << 22) +# define R500_COLOR0_TEX_OVERRIDE_TEX_7 (8 << 22) +# define R500_COLOR0_TEX_OVERRIDE_TEX_8_C2 (9 << 22) +# define R500_COLOR0_TEX_OVERRIDE_TEX_9_C3 (10 << 22) +# define R500_COLOR1_TEX_OVERRIDE_NO (0 << 26) +# define R500_COLOR1_TEX_OVERRIDE_TEX_0 (1 << 26) +# define R500_COLOR1_TEX_OVERRIDE_TEX_1 (2 << 26) +# define R500_COLOR1_TEX_OVERRIDE_TEX_2 (3 << 26) +# define R500_COLOR1_TEX_OVERRIDE_TEX_3 (4 << 26) +# define R500_COLOR1_TEX_OVERRIDE_TEX_4 (5 << 26) +# define R500_COLOR1_TEX_OVERRIDE_TEX_5 (6 << 26) +# define R500_COLOR1_TEX_OVERRIDE_TEX_6 (7 << 26) +# define R500_COLOR1_TEX_OVERRIDE_TEX_7 (8 << 26) +# define R500_COLOR1_TEX_OVERRIDE_TEX_8_C2 (9 << 26) +# define R500_COLOR1_TEX_OVERRIDE_TEX_9_C3 (10 << 26) + +/* Returns idle status of various G3D block, captured when GA_IDLE written or + * when hard or soft reset asserted. + */ +#define R500_GA_IDLE 0x425c +# define R500_GA_IDLE_PIPE3_Z_IDLE (0 << 0) +# define R500_GA_IDLE_PIPE2_Z_IDLE (0 << 1) +# define R500_GA_IDLE_PIPE3_CD_IDLE (0 << 2) +# define R500_GA_IDLE_PIPE2_CD_IDLE (0 << 3) +# define R500_GA_IDLE_PIPE3_FG_IDLE (0 << 4) +# define R500_GA_IDLE_PIPE2_FG_IDLE (0 << 5) +# define R500_GA_IDLE_PIPE3_US_IDLE (0 << 6) +# define R500_GA_IDLE_PIPE2_US_IDLE (0 << 7) +# define R500_GA_IDLE_PIPE3_SC_IDLE (0 << 8) +# define R500_GA_IDLE_PIPE2_SC_IDLE (0 << 9) +# define R500_GA_IDLE_PIPE3_RS_IDLE (0 << 10) +# define R500_GA_IDLE_PIPE2_RS_IDLE (0 << 11) +# define R500_GA_IDLE_PIPE1_Z_IDLE (0 << 12) +# define R500_GA_IDLE_PIPE0_Z_IDLE (0 << 13) +# define R500_GA_IDLE_PIPE1_CD_IDLE (0 << 14) +# define R500_GA_IDLE_PIPE0_CD_IDLE (0 << 15) +# define R500_GA_IDLE_PIPE1_FG_IDLE (0 << 16) +# define R500_GA_IDLE_PIPE0_FG_IDLE (0 << 17) +# define R500_GA_IDLE_PIPE1_US_IDLE (0 << 18) +# define R500_GA_IDLE_PIPE0_US_IDLE (0 << 19) +# define R500_GA_IDLE_PIPE1_SC_IDLE (0 << 20) +# define R500_GA_IDLE_PIPE0_SC_IDLE (0 << 21) +# define R500_GA_IDLE_PIPE1_RS_IDLE (0 << 22) +# define R500_GA_IDLE_PIPE0_RS_IDLE (0 << 23) +# define R500_GA_IDLE_SU_IDLE (0 << 24) +# define R500_GA_IDLE_GA_IDLE (0 << 25) +# define R500_GA_IDLE_GA_UNIT2_IDLE (0 << 26) + +/* Current value of stipple accumulator. */ +#define R300_GA_LINE_STIPPLE_VALUE 0x4260 + +/* S Texture Coordinate Value for Vertex 0 of Line (stuff textures -- i.e. AA) */ +#define R300_GA_LINE_S0 0x4264 +/* S Texture Coordinate Value for Vertex 1 of Lines (V2 of parallelogram -- stuff textures -- i.e. AA) */ +#define R300_GA_LINE_S1 0x4268 + +/* GA Input fifo high water marks */ +#define R500_GA_FIFO_CNTL 0x4270 +# define R500_GA_FIFO_CNTL_VERTEX_FIFO_MASK 0x00000007 +# define R500_GA_FIFO_CNTL_VERTEX_FIFO_SHIFT 0 +# define R500_GA_FIFO_CNTL_VERTEX_INDEX_MASK 0x00000038 +# define R500_GA_FIFO_CNTL_VERTEX_INDEX_SHIFT 3 +# define R500_GA_FIFO_CNTL_VERTEX_REG_MASK 0x00003fc0 +# define R500_GA_FIFO_CNTL_VERTEX_REG_SHIFT 6 + +/* GA enhance/tweaks */ +#define R300_GA_ENHANCE 0x4274 +# define R300_GA_ENHANCE_DEADLOCK_CNTL_NO_EFFECT (0 << 0) +# define R300_GA_ENHANCE_DEADLOCK_CNTL_PREVENT_TCL (1 << 0) /* Prevents TCL interface from deadlocking on GA side. */ +# define R300_GA_ENHANCE_FASTSYNC_CNTL_NO_EFFECT (0 << 1) +# define R300_GA_ENHANCE_FASTSYNC_CNTL_ENABLE (1 << 1) /* Enables high-performance register/primitive switching. */ +# define R500_GA_ENHANCE_REG_READWRITE_NO_EFFECT (0 << 2) /* R520+ only */ +# define R500_GA_ENHANCE_REG_READWRITE_ENABLE (1 << 2) /* R520+ only, Enables GA support of simultaneous register reads and writes. */ +# define R500_GA_ENHANCE_REG_NOSTALL_NO_EFFECT (0 << 3) +# define R500_GA_ENHANCE_REG_NOSTALL_ENABLE (1 << 3) /* Enables GA support of no-stall reads for register read back. */ + +#define R300_GA_COLOR_CONTROL 0x4278 +# define R300_GA_COLOR_CONTROL_RGB0_SHADING_SOLID (0 << 0) +# define R300_GA_COLOR_CONTROL_RGB0_SHADING_FLAT (1 << 0) +# define R300_GA_COLOR_CONTROL_RGB0_SHADING_GOURAUD (2 << 0) +# define R300_GA_COLOR_CONTROL_ALPHA0_SHADING_SOLID (0 << 2) +# define R300_GA_COLOR_CONTROL_ALPHA0_SHADING_FLAT (1 << 2) +# define R300_GA_COLOR_CONTROL_ALPHA0_SHADING_GOURAUD (2 << 2) +# define R300_GA_COLOR_CONTROL_RGB1_SHADING_SOLID (0 << 4) +# define R300_GA_COLOR_CONTROL_RGB1_SHADING_FLAT (1 << 4) +# define R300_GA_COLOR_CONTROL_RGB1_SHADING_GOURAUD (2 << 4) +# define R300_GA_COLOR_CONTROL_ALPHA1_SHADING_SOLID (0 << 6) +# define R300_GA_COLOR_CONTROL_ALPHA1_SHADING_FLAT (1 << 6) +# define R300_GA_COLOR_CONTROL_ALPHA1_SHADING_GOURAUD (2 << 6) +# define R300_GA_COLOR_CONTROL_RGB2_SHADING_SOLID (0 << 8) +# define R300_GA_COLOR_CONTROL_RGB2_SHADING_FLAT (1 << 8) +# define R300_GA_COLOR_CONTROL_RGB2_SHADING_GOURAUD (2 << 8) +# define R300_GA_COLOR_CONTROL_ALPHA2_SHADING_SOLID (0 << 10) +# define R300_GA_COLOR_CONTROL_ALPHA2_SHADING_FLAT (1 << 10) +# define R300_GA_COLOR_CONTROL_ALPHA2_SHADING_GOURAUD (2 << 10) +# define R300_GA_COLOR_CONTROL_RGB3_SHADING_SOLID (0 << 12) +# define R300_GA_COLOR_CONTROL_RGB3_SHADING_FLAT (1 << 12) +# define R300_GA_COLOR_CONTROL_RGB3_SHADING_GOURAUD (2 << 12) +# define R300_GA_COLOR_CONTROL_ALPHA3_SHADING_SOLID (0 << 14) +# define R300_GA_COLOR_CONTROL_ALPHA3_SHADING_FLAT (1 << 14) +# define R300_GA_COLOR_CONTROL_ALPHA3_SHADING_GOURAUD (2 << 14) +# define R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_FIRST (0 << 16) +# define R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_SECOND (1 << 16) +# define R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_THIRD (2 << 16) +# define R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_LAST (3 << 16) + +# define R300_SHADE_MODEL_FLAT ( \ + R300_GA_COLOR_CONTROL_RGB0_SHADING_FLAT | \ + R300_GA_COLOR_CONTROL_ALPHA0_SHADING_FLAT | \ + R300_GA_COLOR_CONTROL_RGB1_SHADING_FLAT | \ + R300_GA_COLOR_CONTROL_ALPHA1_SHADING_FLAT | \ + R300_GA_COLOR_CONTROL_RGB2_SHADING_FLAT | \ + R300_GA_COLOR_CONTROL_ALPHA2_SHADING_FLAT | \ + R300_GA_COLOR_CONTROL_RGB3_SHADING_FLAT | \ + R300_GA_COLOR_CONTROL_ALPHA3_SHADING_FLAT ) + +# define R300_SHADE_MODEL_SMOOTH ( \ + R300_GA_COLOR_CONTROL_RGB0_SHADING_GOURAUD | \ + R300_GA_COLOR_CONTROL_ALPHA0_SHADING_GOURAUD | \ + R300_GA_COLOR_CONTROL_RGB1_SHADING_GOURAUD | \ + R300_GA_COLOR_CONTROL_ALPHA1_SHADING_GOURAUD | \ + R300_GA_COLOR_CONTROL_RGB2_SHADING_GOURAUD | \ + R300_GA_COLOR_CONTROL_ALPHA2_SHADING_GOURAUD | \ + R300_GA_COLOR_CONTROL_RGB3_SHADING_GOURAUD | \ + R300_GA_COLOR_CONTROL_ALPHA3_SHADING_GOURAUD ) + +/* Specifies red & green components of fill color -- S312 format -- Backwards comp. */ +#define R300_GA_SOLID_RG 0x427c +# define GA_SOLID_RG_COLOR_GREEN_SHIFT 0 +# define GA_SOLID_RG_COLOR_GREEN_MASK 0x0000ffff +# define GA_SOLID_RG_COLOR_RED_SHIFT 16 +# define GA_SOLID_RG_COLOR_RED_MASK 0xffff0000 +/* Specifies blue & alpha components of fill color -- S312 format -- Backwards comp. */ +#define R300_GA_SOLID_BA 0x4280 +# define GA_SOLID_BA_COLOR_ALPHA_SHIFT 0 +# define GA_SOLID_BA_COLOR_ALPHA_MASK 0x0000ffff +# define GA_SOLID_BA_COLOR_BLUE_SHIFT 16 +# define GA_SOLID_BA_COLOR_BLUE_MASK 0xffff0000 + +/* Polygon Mode + * Dangerous + */ +#define R300_GA_POLY_MODE 0x4288 +# define R300_GA_POLY_MODE_DISABLE (0 << 0) +# define R300_GA_POLY_MODE_DUAL (1 << 0) /* send 2 sets of 3 polys with specified poly type */ +/* reserved */ +# define R300_GA_POLY_MODE_FRONT_PTYPE_POINT (0 << 4) +# define R300_GA_POLY_MODE_FRONT_PTYPE_LINE (1 << 4) +# define R300_GA_POLY_MODE_FRONT_PTYPE_TRI (2 << 4) +/* reserved */ +# define R300_GA_POLY_MODE_BACK_PTYPE_POINT (0 << 7) +# define R300_GA_POLY_MODE_BACK_PTYPE_LINE (1 << 7) +# define R300_GA_POLY_MODE_BACK_PTYPE_TRI (2 << 7) +/* reserved */ + +/* Specifies the rouding mode for geometry & color SPFP to FP conversions. */ +#define R300_GA_ROUND_MODE 0x428c +# define R300_GA_ROUND_MODE_GEOMETRY_ROUND_TRUNC (0 << 0) +# define R300_GA_ROUND_MODE_GEOMETRY_ROUND_NEAREST (1 << 0) +# define R300_GA_ROUND_MODE_COLOR_ROUND_TRUNC (0 << 2) +# define R300_GA_ROUND_MODE_COLOR_ROUND_NEAREST (1 << 2) +# define R300_GA_ROUND_MODE_RGB_CLAMP_RGB (0 << 4) +# define R300_GA_ROUND_MODE_RGB_CLAMP_FP20 (1 << 4) +# define R300_GA_ROUND_MODE_ALPHA_CLAMP_RGB (0 << 5) +# define R300_GA_ROUND_MODE_ALPHA_CLAMP_FP20 (1 << 5) +# define R500_GA_ROUND_MODE_GEOMETRY_MASK_SHIFT 6 +# define R500_GA_ROUND_MODE_GEOMETRY_MASK_MASK 0x000003c0 + +/* Specifies x & y offsets for vertex data after conversion to FP. + * Offsets are in S15 format (subpixels -- 1/12 or 1/16, even in 8b + * subprecision). + */ +#define R300_GA_OFFSET 0x4290 +# define R300_GA_OFFSET_X_OFFSET_SHIFT 0 +# define R300_GA_OFFSET_X_OFFSET_MASK 0x0000ffff +# define R300_GA_OFFSET_Y_OFFSET_SHIFT 16 +# define R300_GA_OFFSET_Y_OFFSET_MASK 0xffff0000 + +/* Specifies the scale to apply to fog. */ +#define R300_GA_FOG_SCALE 0x4294 +/* Specifies the offset to apply to fog. */ +#define R300_GA_FOG_OFFSET 0x4298 +/* Specifies number of cycles to assert reset, and also causes RB3D soft reset to assert. */ +#define R300_GA_SOFT_RESET 0x429c + +/* Not sure why there are duplicate of factor and constant values. + * My best guess so far is that there are seperate zbiases for test and write. + * Ordering might be wrong. + * Some of the tests indicate that fgl has a fallback implementation of zbias + * via pixel shaders. + */ +#define R300_SU_TEX_WRAP 0x42A0 +#define R300_SU_POLY_OFFSET_FRONT_SCALE 0x42A4 +#define R300_SU_POLY_OFFSET_FRONT_OFFSET 0x42A8 +#define R300_SU_POLY_OFFSET_BACK_SCALE 0x42AC +#define R300_SU_POLY_OFFSET_BACK_OFFSET 0x42B0 + +/* This register needs to be set to (1<<1) for RV350 to correctly + * perform depth test (see --vb-triangles in r300_demo) + * Don't know about other chips. - Vladimir + * This is set to 3 when GL_POLYGON_OFFSET_FILL is on. + * My guess is that there are two bits for each zbias primitive + * (FILL, LINE, POINT). + * One to enable depth test and one for depth write. + * Yet this doesnt explain why depth writes work ... + */ +#define R300_SU_POLY_OFFSET_ENABLE 0x42B4 +# define R300_FRONT_ENABLE (1 << 0) +# define R300_BACK_ENABLE (1 << 1) +# define R300_PARA_ENABLE (1 << 2) + +#define R300_SU_CULL_MODE 0x42B8 +# define R300_CULL_FRONT (1 << 0) +# define R300_CULL_BACK (1 << 1) +# define R300_FRONT_FACE_CCW (0 << 2) +# define R300_FRONT_FACE_CW (1 << 2) + +/* SU Depth Scale value */ +#define R300_SU_DEPTH_SCALE 0x42c0 +/* SU Depth Offset value */ +#define R300_SU_DEPTH_OFFSET 0x42c4 + +#define R300_SU_REG_DEST 0x42c8 +# define R300_RASTER_PIPE_SELECT_0 (1 << 0) +# define R300_RASTER_PIPE_SELECT_1 (1 << 1) +# define R300_RASTER_PIPE_SELECT_2 (1 << 2) +# define R300_RASTER_PIPE_SELECT_3 (1 << 3) +# define R300_RASTER_PIPE_SELECT_ALL 0xf + + +/* BEGIN: Rasterization / Interpolators - many guesses */ + +/* + * TC_CNT is the number of incoming texture coordinate sets (i.e. it depends + * on the vertex program, *not* the fragment program) + */ +#define R300_RS_COUNT 0x4300 +# define R300_IT_COUNT_SHIFT 0 +# define R300_IT_COUNT_MASK 0x0000007f +# define R300_IC_COUNT_SHIFT 7 +# define R300_IC_COUNT_MASK 0x00000780 +# define R300_W_ADDR_SHIFT 12 +# define R300_W_ADDR_MASK 0x0003f000 +# define R300_HIRES_DIS (0 << 18) +# define R300_HIRES_EN (1 << 18) +# define R300_IT_COUNT(x) ((x) << 0) +# define R300_IC_COUNT(x) ((x) << 7) +# define R300_W_COUNT(x) ((x) << 12) + +#define R300_RS_INST_COUNT 0x4304 +# define R300_RS_INST_COUNT_SHIFT 0 +# define R300_RS_INST_COUNT_MASK 0x0000000f +# define R300_RS_TX_OFFSET_SHIFT 5 +# define R300_RS_TX_OFFSET_MASK 0x000000e0 +# define R300_RS_TX_OFFSET(x) ((x) << 5) + +/* gap */ + +/* Only used for texture coordinates. + * Use the source field to route texture coordinate input from the + * vertex program to the desired interpolator. Note that the source + * field is relative to the outputs the vertex program *actually* + * writes. If a vertex program only writes texcoord[1], this will + * be source index 0. + * Set INTERP_USED on all interpolators that produce data used by + * the fragment program. INTERP_USED looks like a swizzling mask, + * but I haven't seen it used that way. + * + * Note: The _UNKNOWN constants are always set in their respective + * register. I don't know if this is necessary. + */ +#define R300_RS_IP_0 0x4310 +#define R300_RS_IP_1 0x4314 +#define R300_RS_IP_2 0x4318 +#define R300_RS_IP_3 0x431C +# define R300_RS_INTERP_SRC_SHIFT 2 /* TODO: check for removal */ +# define R300_RS_INTERP_SRC_MASK (7 << 2) /* TODO: check for removal */ +# define R300_RS_TEX_PTR(x) (x << 0) +# define R300_RS_COL_PTR(x) ((x) << 6) +# define R300_RS_COL_FMT(x) ((x) << 9) +# define R300_RS_COL_FMT_RGBA 0 +# define R300_RS_COL_FMT_RGB0 1 +# define R300_RS_COL_FMT_RGB1 2 +# define R300_RS_COL_FMT_000A 4 +# define R300_RS_COL_FMT_0000 5 +# define R300_RS_COL_FMT_0001 6 +# define R300_RS_COL_FMT_111A 8 +# define R300_RS_COL_FMT_1110 9 +# define R300_RS_COL_FMT_1111 10 +# define R300_RS_SEL_S(x) ((x) << 13) +# define R300_RS_SEL_T(x) ((x) << 16) +# define R300_RS_SEL_R(x) ((x) << 19) +# define R300_RS_SEL_Q(x) ((x) << 22) +# define R300_RS_SEL_C0 0 +# define R300_RS_SEL_C1 1 +# define R300_RS_SEL_C2 2 +# define R300_RS_SEL_C3 3 +# define R300_RS_SEL_K0 4 +# define R300_RS_SEL_K1 5 + + +/* */ +#define R500_RS_INST_0 0x4320 +#define R500_RS_INST_1 0x4324 +#define R500_RS_INST_2 0x4328 +#define R500_RS_INST_3 0x432c +#define R500_RS_INST_4 0x4330 +#define R500_RS_INST_5 0x4334 +#define R500_RS_INST_6 0x4338 +#define R500_RS_INST_7 0x433c +#define R500_RS_INST_8 0x4340 +#define R500_RS_INST_9 0x4344 +#define R500_RS_INST_10 0x4348 +#define R500_RS_INST_11 0x434c +#define R500_RS_INST_12 0x4350 +#define R500_RS_INST_13 0x4354 +#define R500_RS_INST_14 0x4358 +#define R500_RS_INST_15 0x435c +#define R500_RS_INST_TEX_ID_SHIFT 0 +# define R500_RS_INST_TEX_ID(x) ((x) << 0) +#define R500_RS_INST_TEX_CN_WRITE (1 << 4) +#define R500_RS_INST_TEX_ADDR_SHIFT 5 +# define R500_RS_INST_TEX_ADDR(x) ((x) << 5) +#define R500_RS_INST_COL_ID_SHIFT 12 +# define R500_RS_INST_COL_ID(x) ((x) << 12) +#define R500_RS_INST_COL_CN_NO_WRITE (0 << 16) +#define R500_RS_INST_COL_CN_WRITE (1 << 16) +#define R500_RS_INST_COL_CN_WRITE_FBUFFER (2 << 16) +#define R500_RS_INST_COL_CN_WRITE_BACKFACE (3 << 16) +#define R500_RS_INST_COL_ADDR_SHIFT 18 +# define R500_RS_INST_COL_ADDR(x) ((x) << 18) +#define R500_RS_INST_TEX_ADJ (1 << 25) +#define R500_RS_INST_W_CN (1 << 26) + +/* These DWORDs control how vertex data is routed into fragment program + * registers, after interpolators. + */ +#define R300_RS_INST_0 0x4330 +#define R300_RS_INST_1 0x4334 +#define R300_RS_INST_2 0x4338 +#define R300_RS_INST_3 0x433C +#define R300_RS_INST_4 0x4340 +#define R300_RS_INST_5 0x4344 +#define R300_RS_INST_6 0x4348 +#define R300_RS_INST_7 0x434C +# define R300_RS_INST_TEX_ID(x) ((x) << 0) +# define R300_RS_INST_TEX_CN_WRITE (1 << 3) +# define R300_RS_INST_TEX_ADDR(x) ((x) << 6) +# define R300_RS_INST_TEX_ADDR_SHIFT 6 +# define R300_RS_INST_COL_ID(x) ((x) << 11) +# define R300_RS_INST_COL_CN_WRITE (1 << 14) +# define R300_RS_INST_COL_ADDR(x) ((x) << 17) +# define R300_RS_INST_COL_ADDR_SHIFT 17 +# define R300_RS_INST_TEX_ADJ (1 << 22) +# define R300_RS_COL_BIAS_UNUSED_SHIFT 23 + +/* END: Rasterization / Interpolators - many guesses */ + +/* Hierarchical Z Enable */ +#define R300_SC_HYPERZ 0x43a4 +# define R300_SC_HYPERZ_DISABLE (0 << 0) +# define R300_SC_HYPERZ_ENABLE (1 << 0) +# define R300_SC_HYPERZ_MIN (0 << 1) +# define R300_SC_HYPERZ_MAX (1 << 1) +# define R300_SC_HYPERZ_ADJ_256 (0 << 2) +# define R300_SC_HYPERZ_ADJ_128 (1 << 2) +# define R300_SC_HYPERZ_ADJ_64 (2 << 2) +# define R300_SC_HYPERZ_ADJ_32 (3 << 2) +# define R300_SC_HYPERZ_ADJ_16 (4 << 2) +# define R300_SC_HYPERZ_ADJ_8 (5 << 2) +# define R300_SC_HYPERZ_ADJ_4 (6 << 2) +# define R300_SC_HYPERZ_ADJ_2 (7 << 2) +# define R300_SC_HYPERZ_HZ_Z0MIN_NO (0 << 5) +# define R300_SC_HYPERZ_HZ_Z0MIN (1 << 5) +# define R300_SC_HYPERZ_HZ_Z0MAX_NO (0 << 6) +# define R300_SC_HYPERZ_HZ_Z0MAX (1 << 6) + +#define R300_SC_EDGERULE 0x43a8 + +/* BEGIN: Scissors and cliprects */ + +/* There are four clipping rectangles. Their corner coordinates are inclusive. + * Every pixel is assigned a number from 0 and 15 by setting bits 0-3 depending + * on whether the pixel is inside cliprects 0-3, respectively. For example, + * if a pixel is inside cliprects 0 and 1, but outside 2 and 3, it is assigned + * the number 3 (binary 0011). + * Iff the bit corresponding to the pixel's number in RE_CLIPRECT_CNTL is set, + * the pixel is rasterized. + * + * In addition to this, there is a scissors rectangle. Only pixels inside the + * scissors rectangle are drawn. (coordinates are inclusive) + * + * For some reason, the top-left corner of the framebuffer is at (1440, 1440) + * for the purpose of clipping and scissors. + */ +#define R300_SC_CLIPRECT_TL_0 0x43B0 +#define R300_SC_CLIPRECT_BR_0 0x43B4 +#define R300_SC_CLIPRECT_TL_1 0x43B8 +#define R300_SC_CLIPRECT_BR_1 0x43BC +#define R300_SC_CLIPRECT_TL_2 0x43C0 +#define R300_SC_CLIPRECT_BR_2 0x43C4 +#define R300_SC_CLIPRECT_TL_3 0x43C8 +#define R300_SC_CLIPRECT_BR_3 0x43CC +# define R300_CLIPRECT_OFFSET 1440 +# define R300_CLIPRECT_MASK 0x1FFF +# define R300_CLIPRECT_X_SHIFT 0 +# define R300_CLIPRECT_X_MASK (0x1FFF << 0) +# define R300_CLIPRECT_Y_SHIFT 13 +# define R300_CLIPRECT_Y_MASK (0x1FFF << 13) +#define R300_SC_CLIP_RULE 0x43D0 +# define R300_CLIP_OUT (1 << 0) +# define R300_CLIP_0 (1 << 1) +# define R300_CLIP_1 (1 << 2) +# define R300_CLIP_10 (1 << 3) +# define R300_CLIP_2 (1 << 4) +# define R300_CLIP_20 (1 << 5) +# define R300_CLIP_21 (1 << 6) +# define R300_CLIP_210 (1 << 7) +# define R300_CLIP_3 (1 << 8) +# define R300_CLIP_30 (1 << 9) +# define R300_CLIP_31 (1 << 10) +# define R300_CLIP_310 (1 << 11) +# define R300_CLIP_32 (1 << 12) +# define R300_CLIP_320 (1 << 13) +# define R300_CLIP_321 (1 << 14) +# define R300_CLIP_3210 (1 << 15) + +/* gap */ + +#define R300_SC_SCISSORS_TL 0x43E0 +#define R300_SC_SCISSORS_BR 0x43E4 +# define R300_SCISSORS_OFFSET 1440 +# define R300_SCISSORS_X_SHIFT 0 +# define R300_SCISSORS_X_MASK (0x1FFF << 0) +# define R300_SCISSORS_Y_SHIFT 13 +# define R300_SCISSORS_Y_MASK (0x1FFF << 13) + +/* Screen door sample mask */ +#define R300_SC_SCREENDOOR 0x43e8 + +/* END: Scissors and cliprects */ + +/* BEGIN: Texture specification */ + +/* + * The texture specification dwords are grouped by meaning and not by texture + * unit. This means that e.g. the offset for texture image unit N is found in + * register TX_OFFSET_0 + (4*N) + */ +#define R300_TX_FILTER0_0 0x4400 +#define R300_TX_FILTER0_1 0x4404 +#define R300_TX_FILTER0_2 0x4408 +#define R300_TX_FILTER0_3 0x440c +#define R300_TX_FILTER0_4 0x4410 +#define R300_TX_FILTER0_5 0x4414 +#define R300_TX_FILTER0_6 0x4418 +#define R300_TX_FILTER0_7 0x441c +#define R300_TX_FILTER0_8 0x4420 +#define R300_TX_FILTER0_9 0x4424 +#define R300_TX_FILTER0_10 0x4428 +#define R300_TX_FILTER0_11 0x442c +#define R300_TX_FILTER0_12 0x4430 +#define R300_TX_FILTER0_13 0x4434 +#define R300_TX_FILTER0_14 0x4438 +#define R300_TX_FILTER0_15 0x443c +# define R300_TX_REPEAT 0 +# define R300_TX_MIRRORED 1 +# define R300_TX_CLAMP_TO_EDGE 2 +# define R300_TX_MIRROR_ONCE_TO_EDGE 3 +# define R300_TX_CLAMP 4 +# define R300_TX_MIRROR_ONCE 5 +# define R300_TX_CLAMP_TO_BORDER 6 +# define R300_TX_MIRROR_ONCE_TO_BORDER 7 +# define R300_TX_WRAP_S_SHIFT 0 +# define R300_TX_WRAP_S_MASK (7 << 0) +# define R300_TX_WRAP_T_SHIFT 3 +# define R300_TX_WRAP_T_MASK (7 << 3) +# define R300_TX_WRAP_R_SHIFT 6 +# define R300_TX_WRAP_R_MASK (7 << 6) +# define R300_TX_MAG_FILTER_4 (0 << 9) +# define R300_TX_MAG_FILTER_NEAREST (1 << 9) +# define R300_TX_MAG_FILTER_LINEAR (2 << 9) +# define R300_TX_MAG_FILTER_ANISO (3 << 9) +# define R300_TX_MAG_FILTER_MASK (3 << 9) +# define R300_TX_MIN_FILTER_NEAREST (1 << 11) +# define R300_TX_MIN_FILTER_LINEAR (2 << 11) +# define R300_TX_MIN_FILTER_ANISO (3 << 11) +# define R300_TX_MIN_FILTER_MASK (3 << 11) +# define R300_TX_MIN_FILTER_MIP_NONE (0 << 13) +# define R300_TX_MIN_FILTER_MIP_NEAREST (1 << 13) +# define R300_TX_MIN_FILTER_MIP_LINEAR (2 << 13) +# define R300_TX_MIN_FILTER_MIP_MASK (3 << 13) +# define R300_TX_MAX_MIP_LEVEL_SHIFT 17 +# define R300_TX_MAX_MIP_LEVEL_MASK (0xf << 17) +# define R300_TX_MAX_ANISO_1_TO_1 (0 << 21) +# define R300_TX_MAX_ANISO_2_TO_1 (1 << 21) +# define R300_TX_MAX_ANISO_4_TO_1 (2 << 21) +# define R300_TX_MAX_ANISO_8_TO_1 (3 << 21) +# define R300_TX_MAX_ANISO_16_TO_1 (4 << 21) +# define R300_TX_MAX_ANISO_MASK (7 << 21) +# define R300_TX_WRAP_S(x) ((x) << 0) +# define R300_TX_WRAP_T(x) ((x) << 3) +# define R300_TX_MAX_MIP_LEVEL(x) ((x) << 17) + +#define R300_TX_FILTER1_0 0x4440 +# define R300_CHROMA_KEY_MODE_DISABLE 0 +# define R300_CHROMA_KEY_FORCE 1 +# define R300_CHROMA_KEY_BLEND 2 +# define R300_MC_ROUND_NORMAL (0<<2) +# define R300_MC_ROUND_MPEG4 (1<<2) +# define R300_LOD_BIAS_SHIFT 3 +# define R300_LOD_BIAS_MASK 0x1ff8 +# define R300_EDGE_ANISO_EDGE_DIAG (0<<13) +# define R300_EDGE_ANISO_EDGE_ONLY (1<<13) +# define R300_MC_COORD_TRUNCATE_DISABLE (0<<14) +# define R300_MC_COORD_TRUNCATE_MPEG (1<<14) +# define R300_TX_TRI_PERF_0_8 (0<<15) +# define R300_TX_TRI_PERF_1_8 (1<<15) +# define R300_TX_TRI_PERF_1_4 (2<<15) +# define R300_TX_TRI_PERF_3_8 (3<<15) +# define R300_ANISO_THRESHOLD_MASK (7<<17) + +# define R400_DXTC_SWIZZLE_ENABLE (1<<21) +# define R500_MACRO_SWITCH (1<<22) +# define R500_TX_MAX_ANISO(x) ((x) << 23) +# define R500_TX_MAX_ANISO_MASK (63 << 23) +# define R500_TX_ANISO_HIGH_QUALITY (1 << 30) +# define R500_BORDER_FIX (1<<31) + +#define R300_TX_FORMAT0_0 0x4480 +# define R300_TX_WIDTHMASK_SHIFT 0 +# define R300_TX_WIDTHMASK_MASK (2047 << 0) +# define R300_TX_HEIGHTMASK_SHIFT 11 +# define R300_TX_HEIGHTMASK_MASK (2047 << 11) +# define R300_TX_DEPTHMASK_SHIFT 22 +# define R300_TX_DEPTHMASK_MASK (0xf << 22) +# define R300_TX_SIZE_PROJECTED (1 << 30) +# define R300_TX_PITCH_EN (1 << 31) +# define R300_TX_WIDTH(x) ((x) << 0) +# define R300_TX_HEIGHT(x) ((x) << 11) +# define R300_TX_DEPTH(x) ((x) << 22) +# define R300_TX_NUM_LEVELS(x) ((x) << 26) + +#define R300_TX_FORMAT1_0 0x44C0 + /* The interpretation of the format word by Wladimir van der Laan */ + /* The X, Y, Z and W refer to the layout of the components. + They are given meanings as R, G, B and Alpha by the swizzle + specification */ +# define R300_TX_FORMAT_X8 0x0 +# define R300_TX_FORMAT_X16 0x1 +# define R300_TX_FORMAT_Y4X4 0x2 +# define R300_TX_FORMAT_Y8X8 0x3 +# define R300_TX_FORMAT_Y16X16 0x4 +# define R300_TX_FORMAT_Z3Y3X2 0x5 +# define R300_TX_FORMAT_Z5Y6X5 0x6 +# define R300_TX_FORMAT_Z6Y5X5 0x7 +# define R300_TX_FORMAT_Z11Y11X10 0x8 +# define R300_TX_FORMAT_Z10Y11X11 0x9 +# define R300_TX_FORMAT_W4Z4Y4X4 0xA +# define R300_TX_FORMAT_W1Z5Y5X5 0xB +# define R300_TX_FORMAT_W8Z8Y8X8 0xC +# define R300_TX_FORMAT_W2Z10Y10X10 0xD +# define R300_TX_FORMAT_W16Z16Y16X16 0xE +# define R300_TX_FORMAT_DXT1 0xF +# define R300_TX_FORMAT_DXT3 0x10 +# define R300_TX_FORMAT_DXT5 0x11 +# define R300_TX_FORMAT_CxV8U8 0x12 +# define R300_TX_FORMAT_AVYU444 0x13 +# define R300_TX_FORMAT_VYUY422 0x14 +# define R300_TX_FORMAT_YVYU422 0x15 +# define R300_TX_FORMAT_16_MPEG 0x16 +# define R300_TX_FORMAT_16_16_MPEG 0x17 +# define R300_TX_FORMAT_16F 0x18 +# define R300_TX_FORMAT_16F_16F 0x19 +# define R300_TX_FORMAT_16F_16F_16F_16F 0x1A +# define R300_TX_FORMAT_32F 0x1B +# define R300_TX_FORMAT_32F_32F 0x1C +# define R300_TX_FORMAT_32F_32F_32F_32F 0x1D +# define R300_TX_FORMAT_W24_FP 0x1E +# define R400_TX_FORMAT_ATI2N 0x1F + +/* These need TX_FORMAT2_[0-15].TXFORMAT_MSB set. + + My guess is the 10-bit formats are the 8-bit ones but with filtering being + performed with the precision of 10 bits per channel. This makes sense + with sRGB textures since the conversion to linear space reduces the precision + significantly so the shader gets approximately the 8-bit precision + in the end. It might also improve the quality of HDR rendering where + high-precision filtering is desirable. + + Again, this is guessed, the formats might mean something entirely else. + The others should be fine. */ +# define R500_TX_FORMAT_X1 0x0 +# define R500_TX_FORMAT_X1_REV 0x1 +# define R500_TX_FORMAT_X10 0x2 +# define R500_TX_FORMAT_Y10X10 0x3 +# define R500_TX_FORMAT_W10Z10Y10X10 0x4 +# define R500_TX_FORMAT_ATI1N 0x5 +# define R500_TX_FORMAT_Y8X24 0x6 + + +# define R300_TX_FORMAT_SIGNED_W (1 << 5) +# define R300_TX_FORMAT_SIGNED_Z (1 << 6) +# define R300_TX_FORMAT_SIGNED_Y (1 << 7) +# define R300_TX_FORMAT_SIGNED_X (1 << 8) +# define R300_TX_FORMAT_SIGNED (0xf << 5) + +# define R300_TX_FORMAT_3D (1 << 25) +# define R300_TX_FORMAT_CUBIC_MAP (2 << 25) +# define R300_TX_FORMAT_TEX_COORD_TYPE_MASK (0x3 << 25) + + /* alpha modes, convenience mostly */ + /* if you have alpha, pick constant appropriate to the + number of channels (1 for I8, 2 for I8A8, 4 for R8G8B8A8, etc */ +# define R300_TX_FORMAT_ALPHA_1CH 0x000 +# define R300_TX_FORMAT_ALPHA_2CH 0x200 +# define R300_TX_FORMAT_ALPHA_4CH 0x600 +# define R300_TX_FORMAT_ALPHA_NONE 0xA00 + /* Swizzling */ + /* constants */ +# define R300_TX_FORMAT_X 0 +# define R300_TX_FORMAT_Y 1 +# define R300_TX_FORMAT_Z 2 +# define R300_TX_FORMAT_W 3 +# define R300_TX_FORMAT_ZERO 4 +# define R300_TX_FORMAT_ONE 5 + /* 2.0*Z, everything above 1.0 is set to 0.0 */ +# define R300_TX_FORMAT_CUT_Z 6 + /* 2.0*W, everything above 1.0 is set to 0.0 */ +# define R300_TX_FORMAT_CUT_W 7 + +# define R300_TX_FORMAT_B_SHIFT 18 +# define R300_TX_FORMAT_G_SHIFT 15 +# define R300_TX_FORMAT_R_SHIFT 12 +# define R300_TX_FORMAT_A_SHIFT 9 + /* Convenience macro to take care of layout and swizzling */ +# define R300_EASY_TX_FORMAT(B, G, R, A, FMT) ( \ + ((R300_TX_FORMAT_##B)< 0.5, return ARG0, else return ARG1 + * - CMP: If ARG2 < 0, return ARG1, else return ARG0 + * - FLR: use FRC+MAD + * - XPD: use MAD+MAD + * - SGE, SLT: use MAD+CMP + * - RSQ: use ABS modifier for argument + * - Use OUTC_REPL_ALPHA to write results of an alpha-only operation + * (e.g. RCP) into color register + * - apparently, there's no quick DST operation + * - fglrx set FPI2_UNKNOWN_31 on a "MAD fragment.color, tmp0, tmp1, tmp2" + * - fglrx set FPI2_UNKNOWN_31 on a "MAX r2, r1, c0" + * - fglrx once set FPI0_UNKNOWN_31 on a "FRC r1, r1" + * + * Operand selection + * First stage selects three sources from the available registers and + * constant parameters. This is defined in INSTR1 (color) and INSTR3 (alpha). + * fglrx sorts the three source fields: Registers before constants, + * lower indices before higher indices; I do not know whether this is + * necessary. + * + * fglrx fills unused sources with "read constant 0" + * According to specs, you cannot select more than two different constants. + * + * Second stage selects the operands from the sources. This is defined in + * INSTR0 (color) and INSTR2 (alpha). You can also select the special constants + * zero and one. + * Swizzling and negation happens in this stage, as well. + * + * Important: Color and alpha seem to be mostly separate, i.e. their sources + * selection appears to be fully independent (the register storage is probably + * physically split into a color and an alpha section). + * However (because of the apparent physical split), there is some interaction + * WRT swizzling. If, for example, you want to load an R component into an + * Alpha operand, this R component is taken from a *color* source, not from + * an alpha source. The corresponding register doesn't even have to appear in + * the alpha sources list. (I hope this all makes sense to you) + * + * Destination selection + * The destination register index is in FPI1 (color) and FPI3 (alpha) + * together with enable bits. + * There are separate enable bits for writing into temporary registers + * (DSTC_REG_* /DSTA_REG) and program output registers (DSTC_OUTPUT_* + * /DSTA_OUTPUT). You can write to both at once, or not write at all (the + * same index must be used for both). + * + * Note: There is a special form for LRP + * - Argument order is the same as in ARB_fragment_program. + * - Operation is MAD + * - ARG1 is set to ARGC_SRC1C_LRP/ARGC_SRC1A_LRP + * - Set FPI0/FPI2_SPECIAL_LRP + * Arbitrary LRP (including support for swizzling) requires vanilla MAD+MAD + */ +#define R300_US_ALU_RGB_ADDR_0 0x46C0 +# define R300_ALU_SRC0C_SHIFT 0 +# define R300_ALU_SRC0C_MASK (31 << 0) +# define R300_ALU_SRC0C_CONST (1 << 5) +# define R300_ALU_SRC1C_SHIFT 6 +# define R300_ALU_SRC1C_MASK (31 << 6) +# define R300_ALU_SRC1C_CONST (1 << 11) +# define R300_ALU_SRC2C_SHIFT 12 +# define R300_ALU_SRC2C_MASK (31 << 12) +# define R300_ALU_SRC2C_CONST (1 << 17) +# define R300_ALU_SRC_MASK 0x0003ffff +# define R300_ALU_DSTC_SHIFT 18 +# define R300_ALU_DSTC_MASK (31 << 18) +# define R300_ALU_DSTC_REG_MASK_SHIFT 23 +# define R300_ALU_DSTC_REG_X (1 << 23) +# define R300_ALU_DSTC_REG_Y (1 << 24) +# define R300_ALU_DSTC_REG_Z (1 << 25) +# define R300_ALU_DSTC_OUTPUT_MASK_SHIFT 26 +# define R300_ALU_DSTC_OUTPUT_X (1 << 26) +# define R300_ALU_DSTC_OUTPUT_Y (1 << 27) +# define R300_ALU_DSTC_OUTPUT_Z (1 << 28) +# define R300_ALU_DSTC_OUTPUT_XYZ (7 << 26) +# define R300_RGB_ADDR0(x) ((x) << 0) +# define R300_RGB_ADDR1(x) ((x) << 6) +# define R300_RGB_ADDR2(x) ((x) << 12) +# define R300_RGB_TARGET(x) ((x) << 29) + +#define R300_US_ALU_ALPHA_ADDR_0 0x47C0 +# define R300_ALU_SRC0A_SHIFT 0 +# define R300_ALU_SRC0A_MASK (31 << 0) +# define R300_ALU_SRC0A_CONST (1 << 5) +# define R300_ALU_SRC1A_SHIFT 6 +# define R300_ALU_SRC1A_MASK (31 << 6) +# define R300_ALU_SRC1A_CONST (1 << 11) +# define R300_ALU_SRC2A_SHIFT 12 +# define R300_ALU_SRC2A_MASK (31 << 12) +# define R300_ALU_SRC2A_CONST (1 << 17) +# define R300_ALU_SRC_MASK 0x0003ffff +# define R300_ALU_DSTA_SHIFT 18 +# define R300_ALU_DSTA_MASK (31 << 18) +# define R300_ALU_DSTA_REG (1 << 23) +# define R300_ALU_DSTA_OUTPUT (1 << 24) +# define R300_ALU_DSTA_DEPTH (1 << 27) +# define R300_ALPHA_ADDR0(x) ((x) << 0) +# define R300_ALPHA_ADDR1(x) ((x) << 6) +# define R300_ALPHA_ADDR2(x) ((x) << 12) +# define R300_ALPHA_TARGET(x) ((x) << 25) + +#define R300_US_ALU_RGB_INST_0 0x48C0 +# define R300_ALU_ARGC_SRC0C_XYZ 0 +# define R300_ALU_ARGC_SRC0C_XXX 1 +# define R300_ALU_ARGC_SRC0C_YYY 2 +# define R300_ALU_ARGC_SRC0C_ZZZ 3 +# define R300_ALU_ARGC_SRC1C_XYZ 4 +# define R300_ALU_ARGC_SRC1C_XXX 5 +# define R300_ALU_ARGC_SRC1C_YYY 6 +# define R300_ALU_ARGC_SRC1C_ZZZ 7 +# define R300_ALU_ARGC_SRC2C_XYZ 8 +# define R300_ALU_ARGC_SRC2C_XXX 9 +# define R300_ALU_ARGC_SRC2C_YYY 10 +# define R300_ALU_ARGC_SRC2C_ZZZ 11 +# define R300_ALU_ARGC_SRC0A 12 +# define R300_ALU_ARGC_SRC1A 13 +# define R300_ALU_ARGC_SRC2A 14 +# define R300_ALU_ARGC_SRCP_XYZ 15 +# define R300_ALU_ARGC_SRCP_XXX 16 +# define R300_ALU_ARGC_SRCP_YYY 17 +# define R300_ALU_ARGC_SRCP_ZZZ 18 +# define R300_ALU_ARGC_SRCP_WWW 19 +# define R300_ALU_ARGC_ZERO 20 +# define R300_ALU_ARGC_ONE 21 +# define R300_ALU_ARGC_HALF 22 +# define R300_ALU_ARGC_SRC0C_YZX 23 +# define R300_ALU_ARGC_SRC1C_YZX 24 +# define R300_ALU_ARGC_SRC2C_YZX 25 +# define R300_ALU_ARGC_SRC0C_ZXY 26 +# define R300_ALU_ARGC_SRC1C_ZXY 27 +# define R300_ALU_ARGC_SRC2C_ZXY 28 +# define R300_ALU_ARGC_SRC0CA_WZY 29 +# define R300_ALU_ARGC_SRC1CA_WZY 30 +# define R300_ALU_ARGC_SRC2CA_WZY 31 +# define R300_RGB_SWIZA(x) ((x) << 0) +# define R300_RGB_SWIZB(x) ((x) << 7) +# define R300_RGB_SWIZC(x) ((x) << 14) + +# define R300_ALU_ARG0C_SHIFT 0 +# define R300_ALU_ARG0C_MASK (31 << 0) +# define R300_ALU_ARG0C_NOP (0 << 5) +# define R300_ALU_ARG0C_NEG (1 << 5) +# define R300_ALU_ARG0C_ABS (2 << 5) +# define R300_ALU_ARG0C_NAB (3 << 5) +# define R300_ALU_ARG1C_SHIFT 7 +# define R300_ALU_ARG1C_MASK (31 << 7) +# define R300_ALU_ARG1C_NOP (0 << 12) +# define R300_ALU_ARG1C_NEG (1 << 12) +# define R300_ALU_ARG1C_ABS (2 << 12) +# define R300_ALU_ARG1C_NAB (3 << 12) +# define R300_ALU_ARG2C_SHIFT 14 +# define R300_ALU_ARG2C_MASK (31 << 14) +# define R300_ALU_ARG2C_NOP (0 << 19) +# define R300_ALU_ARG2C_NEG (1 << 19) +# define R300_ALU_ARG2C_ABS (2 << 19) +# define R300_ALU_ARG2C_NAB (3 << 19) +# define R300_ALU_SRCP_1_MINUS_2_SRC0 (0 << 21) +# define R300_ALU_SRCP_SRC1_MINUS_SRC0 (1 << 21) +# define R300_ALU_SRCP_SRC1_PLUS_SRC0 (2 << 21) +# define R300_ALU_SRCP_1_MINUS_SRC0 (3 << 21) + +# define R300_ALU_OUTC_MAD (0 << 23) +# define R300_ALU_OUTC_DP3 (1 << 23) +# define R300_ALU_OUTC_DP4 (2 << 23) +# define R300_ALU_OUTC_D2A (3 << 23) +# define R300_ALU_OUTC_MIN (4 << 23) +# define R300_ALU_OUTC_MAX (5 << 23) +# define R300_ALU_OUTC_CMPH (7 << 23) +# define R300_ALU_OUTC_CMP (8 << 23) +# define R300_ALU_OUTC_FRC (9 << 23) +# define R300_ALU_OUTC_REPL_ALPHA (10 << 23) + +# define R300_ALU_OUTC_MOD_NOP (0 << 27) +# define R300_ALU_OUTC_MOD_MUL2 (1 << 27) +# define R300_ALU_OUTC_MOD_MUL4 (2 << 27) +# define R300_ALU_OUTC_MOD_MUL8 (3 << 27) +# define R300_ALU_OUTC_MOD_DIV2 (4 << 27) +# define R300_ALU_OUTC_MOD_DIV4 (5 << 27) +# define R300_ALU_OUTC_MOD_DIV8 (6 << 27) + +# define R300_ALU_OUTC_CLAMP (1 << 30) +# define R300_ALU_INSERT_NOP (1 << 31) + +#define R300_US_ALU_ALPHA_INST_0 0x49C0 +# define R300_ALU_ARGA_SRC0C_X 0 +# define R300_ALU_ARGA_SRC0C_Y 1 +# define R300_ALU_ARGA_SRC0C_Z 2 +# define R300_ALU_ARGA_SRC1C_X 3 +# define R300_ALU_ARGA_SRC1C_Y 4 +# define R300_ALU_ARGA_SRC1C_Z 5 +# define R300_ALU_ARGA_SRC2C_X 6 +# define R300_ALU_ARGA_SRC2C_Y 7 +# define R300_ALU_ARGA_SRC2C_Z 8 +# define R300_ALU_ARGA_SRC0A 9 +# define R300_ALU_ARGA_SRC1A 10 +# define R300_ALU_ARGA_SRC2A 11 +# define R300_ALU_ARGA_SRCP_X 12 +# define R300_ALU_ARGA_SRCP_Y 13 +# define R300_ALU_ARGA_SRCP_Z 14 +# define R300_ALU_ARGA_SRCP_W 15 +# define R300_ALU_ARGA_ZERO 16 +# define R300_ALU_ARGA_ONE 17 +# define R300_ALU_ARGA_HALF 18 +# define R300_ALPHA_SWIZA(x) ((x) << 0) +# define R300_ALPHA_SWIZB(x) ((x) << 7) +# define R300_ALPHA_SWIZC(x) ((x) << 14) + +# define R300_ALU_ARG0A_SHIFT 0 +# define R300_ALU_ARG0A_MASK (31 << 0) +# define R300_ALU_ARG0A_NOP (0 << 5) +# define R300_ALU_ARG0A_NEG (1 << 5) +# define R300_ALU_ARG0A_ABS (2 << 5) +# define R300_ALU_ARG0A_NAB (3 << 5) +# define R300_ALU_ARG1A_SHIFT 7 +# define R300_ALU_ARG1A_MASK (31 << 7) +# define R300_ALU_ARG1A_NOP (0 << 12) +# define R300_ALU_ARG1A_NEG (1 << 12) +# define R300_ALU_ARG1A_ABS (2 << 12) +# define R300_ALU_ARG1A_NAB (3 << 12) +# define R300_ALU_ARG2A_SHIFT 14 +# define R300_ALU_ARG2A_MASK (31 << 14) +# define R300_ALU_ARG2A_NOP (0 << 19) +# define R300_ALU_ARG2A_NEG (1 << 19) +# define R300_ALU_ARG2A_ABS (2 << 19) +# define R300_ALU_ARG2A_NAB (3 << 19) +# define R300_ALU_SRCP_1_MINUS_2_SRC0 (0 << 21) +# define R300_ALU_SRCP_SRC1_MINUS_SRC0 (1 << 21) +# define R300_ALU_SRCP_SRC1_PLUS_SRC0 (2 << 21) +# define R300_ALU_SRCP_1_MINUS_SRC0 (3 << 21) + +# define R300_ALU_OUTA_MAD (0 << 23) +# define R300_ALU_OUTA_DP4 (1 << 23) +# define R300_ALU_OUTA_MIN (2 << 23) +# define R300_ALU_OUTA_MAX (3 << 23) +# define R300_ALU_OUTA_CND (5 << 23) +# define R300_ALU_OUTA_CMP (6 << 23) +# define R300_ALU_OUTA_FRC (7 << 23) +# define R300_ALU_OUTA_EX2 (8 << 23) +# define R300_ALU_OUTA_LG2 (9 << 23) +# define R300_ALU_OUTA_RCP (10 << 23) +# define R300_ALU_OUTA_RSQ (11 << 23) + +# define R300_ALU_OUTA_MOD_NOP (0 << 27) +# define R300_ALU_OUTA_MOD_MUL2 (1 << 27) +# define R300_ALU_OUTA_MOD_MUL4 (2 << 27) +# define R300_ALU_OUTA_MOD_MUL8 (3 << 27) +# define R300_ALU_OUTA_MOD_DIV2 (4 << 27) +# define R300_ALU_OUTA_MOD_DIV4 (5 << 27) +# define R300_ALU_OUTA_MOD_DIV8 (6 << 27) + +# define R300_ALU_OUTA_CLAMP (1 << 30) +/* END: Fragment program instruction set */ + +/* R4xx extended fragment shader registers. */ +#define R400_US_ALU_EXT_ADDR_0 0x4ac0 /* up to 63 (0x4bbc) */ +# define R400_ADDR0_EXT_RGB_MSB_BIT 0x01 +# define R400_ADDR1_EXT_RGB_MSB_BIT 0x02 +# define R400_ADDR2_EXT_RGB_MSB_BIT 0x04 +# define R400_ADDRD_EXT_RGB_MSB_BIT 0x08 +# define R400_ADDR0_EXT_A_MSB_BIT 0x10 +# define R400_ADDR1_EXT_A_MSB_BIT 0x20 +# define R400_ADDR2_EXT_A_MSB_BIT 0x40 +# define R400_ADDRD_EXT_A_MSB_BIT 0x80 +#define R400_US_CODE_BANK 0x46b8 +# define R400_BANK_SHIFT 0 +# define R400_BANK_MASK 0xf +# define R400_R390_MODE_ENABLE (1 << 4) +#define R400_US_CODE_EXT 0x46bc +# define R400_ALU_OFFSET_MSB_SHIFT 0 +# define R400_ALU_OFFSET_MSB_MASK (0x7 << 0) +# define R400_ALU_SIZE_MSB_SHIFT 3 +# define R400_ALU_SIZE_MSB_MASK (0x7 << 3) +# define R400_ALU_START0_MSB_SHIFT 6 +# define R400_ALU_START0_MSB_MASK (0x7 << 6) +# define R400_ALU_SIZE0_MSB_SHIFT 9 +# define R400_ALU_SIZE0_MSB_MASK (0x7 << 9) +# define R400_ALU_START1_MSB_SHIFT 12 +# define R400_ALU_START1_MSB_MASK (0x7 << 12) +# define R400_ALU_SIZE1_MSB_SHIFT 15 +# define R400_ALU_SIZE1_MSB_MASK (0x7 << 15) +# define R400_ALU_START2_MSB_SHIFT 18 +# define R400_ALU_START2_MSB_MASK (0x7 << 18) +# define R400_ALU_SIZE2_MSB_SHIFT 21 +# define R400_ALU_SIZE2_MSB_MASK (0x7 << 21) +# define R400_ALU_START3_MSB_SHIFT 24 +# define R400_ALU_START3_MSB_MASK (0x7 << 24) +# define R400_ALU_SIZE3_MSB_SHIFT 27 +# define R400_ALU_SIZE3_MSB_MASK (0x7 << 27) +/* END: R4xx extended fragment shader registers. */ + +/* Fog: Fog Blending Enable */ +#define R300_FG_FOG_BLEND 0x4bc0 +# define R300_FG_FOG_BLEND_DISABLE (0 << 0) +# define R300_FG_FOG_BLEND_ENABLE (1 << 0) +# define R300_FG_FOG_BLEND_FN_LINEAR (0 << 1) +# define R300_FG_FOG_BLEND_FN_EXP (1 << 1) +# define R300_FG_FOG_BLEND_FN_EXP2 (2 << 1) +# define R300_FG_FOG_BLEND_FN_CONSTANT (3 << 1) +# define R300_FG_FOG_BLEND_FN_MASK (3 << 1) + +/* Fog: Red Component of Fog Color */ +#define R300_FG_FOG_COLOR_R 0x4bc8 +/* Fog: Green Component of Fog Color */ +#define R300_FG_FOG_COLOR_G 0x4bcc +/* Fog: Blue Component of Fog Color */ +#define R300_FG_FOG_COLOR_B 0x4bd0 +# define R300_FG_FOG_COLOR_MASK 0x000003ff + +/* Fog: Constant Factor for Fog Blending */ +#define R300_FG_FOG_FACTOR 0x4bc4 +# define FG_FOG_FACTOR_MASK 0x000003ff + +/* Fog: Alpha function */ +#define R300_FG_ALPHA_FUNC 0x4bd4 +# define R300_FG_ALPHA_FUNC_VAL_MASK 0x000000ff +# define R300_FG_ALPHA_FUNC_NEVER (0 << 8) +# define R300_FG_ALPHA_FUNC_LESS (1 << 8) +# define R300_FG_ALPHA_FUNC_EQUAL (2 << 8) +# define R300_FG_ALPHA_FUNC_LE (3 << 8) +# define R300_FG_ALPHA_FUNC_GREATER (4 << 8) +# define R300_FG_ALPHA_FUNC_NOTEQUAL (5 << 8) +# define R300_FG_ALPHA_FUNC_GE (6 << 8) +# define R300_FG_ALPHA_FUNC_ALWAYS (7 << 8) +# define R300_ALPHA_TEST_OP_MASK (7 << 8) +# define R300_FG_ALPHA_FUNC_DISABLE (0 << 11) +# define R300_FG_ALPHA_FUNC_ENABLE (1 << 11) + +# define R500_FG_ALPHA_FUNC_10BIT (0 << 12) +# define R500_FG_ALPHA_FUNC_8BIT (1 << 12) + +# define R300_FG_ALPHA_FUNC_MASK_DISABLE (0 << 16) +# define R300_FG_ALPHA_FUNC_MASK_ENABLE (1 << 16) +# define R300_FG_ALPHA_FUNC_CFG_2_OF_4 (0 << 17) +# define R300_FG_ALPHA_FUNC_CFG_3_OF_6 (1 << 17) + +# define R300_FG_ALPHA_FUNC_DITH_DISABLE (0 << 20) +# define R300_FG_ALPHA_FUNC_DITH_ENABLE (1 << 20) + +# define R500_FG_ALPHA_FUNC_OFFSET_DISABLE (0 << 24) +# define R500_FG_ALPHA_FUNC_OFFSET_ENABLE (1 << 24) /* Not supported in R520 */ +# define R500_FG_ALPHA_FUNC_DISC_ZERO_MASK_DISABLE (0 << 25) +# define R500_FG_ALPHA_FUNC_DISC_ZERO_MASK_ENABLE (1 << 25) + +# define R500_FG_ALPHA_FUNC_FP16_DISABLE (0 << 28) +# define R500_FG_ALPHA_FUNC_FP16_ENABLE (1 << 28) + + +/* Fog: Where does the depth come from? */ +#define R300_FG_DEPTH_SRC 0x4bd8 +# define R300_FG_DEPTH_SRC_SCAN (0 << 0) +# define R300_FG_DEPTH_SRC_SHADER (1 << 0) + +/* Fog: Alpha Compare Value */ +#define R500_FG_ALPHA_VALUE 0x4be0 +# define R500_FG_ALPHA_VALUE_MASK 0x0000ffff + +#define RV530_FG_ZBREG_DEST 0x4be8 +# define RV530_FG_ZBREG_DEST_PIPE_SELECT_0 (1 << 0) +# define RV530_FG_ZBREG_DEST_PIPE_SELECT_1 (1 << 1) +# define RV530_FG_ZBREG_DEST_PIPE_SELECT_ALL (3 << 0) +/* gap */ + +/* Fragment program parameters in 7.16 floating point */ +#define R300_PFS_PARAM_0_X 0x4C00 +#define R300_PFS_PARAM_0_Y 0x4C04 +#define R300_PFS_PARAM_0_Z 0x4C08 +#define R300_PFS_PARAM_0_W 0x4C0C +/* last consts */ +#define R300_PFS_PARAM_31_X 0x4DF0 +#define R300_PFS_PARAM_31_Y 0x4DF4 +#define R300_PFS_PARAM_31_Z 0x4DF8 +#define R300_PFS_PARAM_31_W 0x4DFC + +/* Unpipelined. */ +#define R300_RB3D_CCTL 0x4e00 +# define R300_RB3D_CCTL_NUM_MULTIWRITES(x) (MAX2(((x)-1), 0) << 5) +# define R300_RB3D_CCTL_NUM_MULTIWRITES_1_BUFFER (0 << 5) +# define R300_RB3D_CCTL_NUM_MULTIWRITES_2_BUFFERS (1 << 5) +# define R300_RB3D_CCTL_NUM_MULTIWRITES_3_BUFFERS (2 << 5) +# define R300_RB3D_CCTL_NUM_MULTIWRITES_4_BUFFERS (3 << 5) +# define R300_RB3D_CCTL_CLRCMP_FLIPE_DISABLE (0 << 7) +# define R300_RB3D_CCTL_CLRCMP_FLIPE_ENABLE (1 << 7) +# define R300_RB3D_CCTL_AA_COMPRESSION_DISABLE (0 << 9) +# define R300_RB3D_CCTL_AA_COMPRESSION_ENABLE (1 << 9) +# define R300_RB3D_CCTL_CMASK_DISABLE (0 << 10) +# define R300_RB3D_CCTL_CMASK_ENABLE (1 << 10) +/* reserved */ +# define R300_RB3D_CCTL_INDEPENDENT_COLOR_CHANNEL_MASK_DISABLE (0 << 12) +# define R300_RB3D_CCTL_INDEPENDENT_COLOR_CHANNEL_MASK_ENABLE (1 << 12) +# define R300_RB3D_CCTL_WRITE_COMPRESSION_ENABLE (0 << 13) +# define R300_RB3D_CCTL_WRITE_COMPRESSION_DISABLE (1 << 13) +# define R300_RB3D_CCTL_INDEPENDENT_COLORFORMAT_ENABLE_DISABLE (0 << 14) +# define R300_RB3D_CCTL_INDEPENDENT_COLORFORMAT_ENABLE_ENABLE (1 << 14) + + +/* Notes: + * - AFAIK fglrx always sets BLEND_UNKNOWN when blending is used in + * the application + * - AFAIK fglrx always sets BLEND_NO_SEPARATE when CBLEND and ABLEND + * are set to the same + * function (both registers are always set up completely in any case) + * - Most blend flags are simply copied from R200 and not tested yet + */ +#define R300_RB3D_CBLEND 0x4E04 +#define R300_RB3D_ABLEND 0x4E08 +/* the following only appear in CBLEND */ +# define R300_ALPHA_BLEND_ENABLE (1 << 0) +# define R300_SEPARATE_ALPHA_ENABLE (1 << 1) +# define R300_READ_ENABLE (1 << 2) +# define R300_DISCARD_SRC_PIXELS_DIS (0 << 3) +# define R300_DISCARD_SRC_PIXELS_SRC_ALPHA_0 (1 << 3) +# define R300_DISCARD_SRC_PIXELS_SRC_COLOR_0 (2 << 3) +# define R300_DISCARD_SRC_PIXELS_SRC_ALPHA_COLOR_0 (3 << 3) +# define R300_DISCARD_SRC_PIXELS_SRC_ALPHA_1 (4 << 3) +# define R300_DISCARD_SRC_PIXELS_SRC_COLOR_1 (5 << 3) +# define R300_DISCARD_SRC_PIXELS_SRC_ALPHA_COLOR_1 (6 << 3) +# define R500_SRC_ALPHA_0_NO_READ (1 << 30) +# define R500_SRC_ALPHA_1_NO_READ (1 << 31) + +/* the following are shared between CBLEND and ABLEND */ +# define R300_FCN_MASK (3 << 12) +# define R300_COMB_FCN_ADD_CLAMP (0 << 12) +# define R300_COMB_FCN_ADD_NOCLAMP (1 << 12) +# define R300_COMB_FCN_SUB_CLAMP (2 << 12) +# define R300_COMB_FCN_SUB_NOCLAMP (3 << 12) +# define R300_COMB_FCN_MIN (4 << 12) +# define R300_COMB_FCN_MAX (5 << 12) +# define R300_COMB_FCN_RSUB_CLAMP (6 << 12) +# define R300_COMB_FCN_RSUB_NOCLAMP (7 << 12) +# define R300_BLEND_GL_ZERO (32) +# define R300_BLEND_GL_ONE (33) +# define R300_BLEND_GL_SRC_COLOR (34) +# define R300_BLEND_GL_ONE_MINUS_SRC_COLOR (35) +# define R300_BLEND_GL_DST_COLOR (36) +# define R300_BLEND_GL_ONE_MINUS_DST_COLOR (37) +# define R300_BLEND_GL_SRC_ALPHA (38) +# define R300_BLEND_GL_ONE_MINUS_SRC_ALPHA (39) +# define R300_BLEND_GL_DST_ALPHA (40) +# define R300_BLEND_GL_ONE_MINUS_DST_ALPHA (41) +# define R300_BLEND_GL_SRC_ALPHA_SATURATE (42) +# define R300_BLEND_GL_CONST_COLOR (43) +# define R300_BLEND_GL_ONE_MINUS_CONST_COLOR (44) +# define R300_BLEND_GL_CONST_ALPHA (45) +# define R300_BLEND_GL_ONE_MINUS_CONST_ALPHA (46) +# define R300_BLEND_MASK (63) +# define R300_SRC_BLEND_SHIFT (16) +# define R300_DST_BLEND_SHIFT (24) + +/* Constant color used by the blender. Pipelined through the blender. + * Note: For R520, this field is ignored, use RB3D_CONSTANT_COLOR_GB__BLUE, + * RB3D_CONSTANT_COLOR_GB__GREEN, etc. instead. + */ +#define R300_RB3D_BLEND_COLOR 0x4E10 + + +/* 3D Color Channel Mask. If all the channels used in the current color format + * are disabled, then the cb will discard all the incoming quads. Pipelined + * through the blender. + */ +#define RB3D_COLOR_CHANNEL_MASK 0x4E0C +# define RB3D_COLOR_CHANNEL_MASK_BLUE_MASK0 (1 << 0) +# define RB3D_COLOR_CHANNEL_MASK_GREEN_MASK0 (1 << 1) +# define RB3D_COLOR_CHANNEL_MASK_RED_MASK0 (1 << 2) +# define RB3D_COLOR_CHANNEL_MASK_ALPHA_MASK0 (1 << 3) +# define RB3D_COLOR_CHANNEL_MASK_BLUE_MASK1 (1 << 4) +# define RB3D_COLOR_CHANNEL_MASK_GREEN_MASK1 (1 << 5) +# define RB3D_COLOR_CHANNEL_MASK_RED_MASK1 (1 << 6) +# define RB3D_COLOR_CHANNEL_MASK_ALPHA_MASK1 (1 << 7) +# define RB3D_COLOR_CHANNEL_MASK_BLUE_MASK2 (1 << 8) +# define RB3D_COLOR_CHANNEL_MASK_GREEN_MASK2 (1 << 9) +# define RB3D_COLOR_CHANNEL_MASK_RED_MASK2 (1 << 10) +# define RB3D_COLOR_CHANNEL_MASK_ALPHA_MASK2 (1 << 11) +# define RB3D_COLOR_CHANNEL_MASK_BLUE_MASK3 (1 << 12) +# define RB3D_COLOR_CHANNEL_MASK_GREEN_MASK3 (1 << 13) +# define RB3D_COLOR_CHANNEL_MASK_RED_MASK3 (1 << 14) +# define RB3D_COLOR_CHANNEL_MASK_ALPHA_MASK3 (1 << 15) + +/* Clear color that is used when the color mask is set to 00. Unpipelined. + * Program this register with a 32-bit value in ARGB8888 or ARGB2101010 + * formats, ignoring the fields. + */ +#define RB3D_COLOR_CLEAR_VALUE 0x4e14 + +/* gap */ + +/* Color Compare Color. Stalls the 2d/3d datapath until it is idle. */ +#define RB3D_CLRCMP_CLR 0x4e20 + +/* Color Compare Mask. Stalls the 2d/3d datapath until it is idle. */ +#define RB3D_CLRCMP_MSK 0x4e24 + +/* Color Buffer Address Offset of multibuffer 0. Unpipelined. */ +#define R300_RB3D_COLOROFFSET0 0x4E28 +# define R300_COLOROFFSET_MASK 0xFFFFFFE0 +/* Color Buffer Address Offset of multibuffer 1. Unpipelined. */ +#define R300_RB3D_COLOROFFSET1 0x4E2C +/* Color Buffer Address Offset of multibuffer 2. Unpipelined. */ +#define R300_RB3D_COLOROFFSET2 0x4E30 +/* Color Buffer Address Offset of multibuffer 3. Unpipelined. */ +#define R300_RB3D_COLOROFFSET3 0x4E34 + +/* Color buffer format and tiling control for all the multibuffers and the + * pitch of multibuffer 0 to 3. Unpipelined. The cache must be empty before any + * of the registers are changed. + * + * Bit 16: Larger tiles + * Bit 17: 4x2 tiles + * Bit 18: Extremely weird tile like, but some pixels duplicated? + */ +#define R300_RB3D_COLORPITCH0 0x4E38 +# define R300_COLORPITCH_MASK 0x00003FFE +# define R300_COLOR_TILE_DISABLE (0 << 16) +# define R300_COLOR_TILE_ENABLE (1 << 16) +# define R300_COLOR_TILE(x) ((x) << 16) +# define R300_COLOR_MICROTILE_DISABLE (0 << 17) +# define R300_COLOR_MICROTILE_ENABLE (1 << 17) +# define R300_COLOR_MICROTILE_ENABLE_SQUARE (2 << 17) /* Only available in 16-bit */ +# define R300_COLOR_MICROTILE(x) ((x) << 17) +# define R300_COLOR_ENDIAN_NO_SWAP (0 << 19) +# define R300_COLOR_ENDIAN_WORD_SWAP (1 << 19) +# define R300_COLOR_ENDIAN_DWORD_SWAP (2 << 19) +# define R300_COLOR_ENDIAN_HALF_DWORD_SWAP (3 << 19) +# define R500_COLOR_FORMAT_ARGB10101010 (0 << 21) +# define R500_COLOR_FORMAT_UV1010 (1 << 21) +# define R500_COLOR_FORMAT_CI8 (2 << 21) /* 2D only */ +# define R300_COLOR_FORMAT_ARGB1555 (3 << 21) +# define R300_COLOR_FORMAT_RGB565 (4 << 21) +# define R500_COLOR_FORMAT_ARGB2101010 (5 << 21) +# define R300_COLOR_FORMAT_ARGB8888 (6 << 21) +# define R300_COLOR_FORMAT_ARGB32323232 (7 << 21) +/* reserved */ +# define R300_COLOR_FORMAT_I8 (9 << 21) +# define R300_COLOR_FORMAT_ARGB16161616 (10 << 21) +# define R300_COLOR_FORMAT_VYUY (11 << 21) +# define R300_COLOR_FORMAT_YVYU (12 << 21) +# define R300_COLOR_FORMAT_UV88 (13 << 21) +# define R500_COLOR_FORMAT_I10 (14 << 21) +# define R300_COLOR_FORMAT_ARGB4444 (15 << 21) +#define R300_RB3D_COLORPITCH1 0x4E3C +#define R300_RB3D_COLORPITCH2 0x4E40 +#define R300_RB3D_COLORPITCH3 0x4E44 + +/* gap */ + +/* Destination Color Buffer Cache Control/Status. If the cb is in e2 mode, then + * a flush or free will not occur upon a write to this register, but a sync + * will be immediately sent if one is requested. If both DC_FLUSH and DC_FREE + * are zero but DC_FINISH is one, then a sync will be sent immediately -- the + * cb will not wait for all the previous operations to complete before sending + * the sync. Unpipelined except when DC_FINISH and DC_FREE are both set to + * zero. + * + * Set to 0A before 3D operations, set to 02 afterwards. + */ +#define R300_RB3D_DSTCACHE_CTLSTAT 0x4e4c +# define R300_RB3D_DSTCACHE_CTLSTAT_DC_FLUSH_NO_EFFECT (0 << 0) +# define R300_RB3D_DSTCACHE_CTLSTAT_DC_FLUSH_NO_EFFECT_1 (1 << 0) +# define R300_RB3D_DSTCACHE_CTLSTAT_DC_FLUSH_FLUSH_DIRTY_3D (2 << 0) +# define R300_RB3D_DSTCACHE_CTLSTAT_DC_FLUSH_FLUSH_DIRTY_3D_1 (3 << 0) +# define R300_RB3D_DSTCACHE_CTLSTAT_DC_FREE_NO_EFFECT (0 << 2) +# define R300_RB3D_DSTCACHE_CTLSTAT_DC_FREE_NO_EFFECT_1 (1 << 2) +# define R300_RB3D_DSTCACHE_CTLSTAT_DC_FREE_FREE_3D_TAGS (2 << 2) +# define R300_RB3D_DSTCACHE_CTLSTAT_DC_FREE_FREE_3D_TAGS_1 (3 << 2) +# define R300_RB3D_DSTCACHE_CTLSTAT_DC_FINISH_NO_SIGNAL (0 << 4) +# define R300_RB3D_DSTCACHE_CTLSTAT_DC_FINISH_SIGNAL (1 << 4) + +#define R300_RB3D_DITHER_CTL 0x4E50 +# define R300_RB3D_DITHER_CTL_DITHER_MODE_TRUNCATE (0 << 0) +# define R300_RB3D_DITHER_CTL_DITHER_MODE_ROUND (1 << 0) +# define R300_RB3D_DITHER_CTL_DITHER_MODE_LUT (2 << 0) +/* reserved */ +# define R300_RB3D_DITHER_CTL_ALPHA_DITHER_MODE_TRUNCATE (0 << 2) +# define R300_RB3D_DITHER_CTL_ALPHA_DITHER_MODE_ROUND (1 << 2) +# define R300_RB3D_DITHER_CTL_ALPHA_DITHER_MODE_LUT (2 << 2) +/* reserved */ + +/* Resolve buffer destination address. The cache must be empty before changing + * this register if the cb is in resolve mode. Unpipelined + */ +#define R300_RB3D_AARESOLVE_OFFSET 0x4e80 +# define R300_RB3D_AARESOLVE_OFFSET_SHIFT 5 +# define R300_RB3D_AARESOLVE_OFFSET_MASK 0xffffffe0 /* At least according to the calculations of Christoph Brill */ + +/* Resolve Buffer Pitch and Tiling Control. The cache must be empty before + * changing this register if the cb is in resolve mode. Unpipelined + */ +#define R300_RB3D_AARESOLVE_PITCH 0x4e84 +# define R300_RB3D_AARESOLVE_PITCH_SHIFT 1 +# define R300_RB3D_AARESOLVE_PITCH_MASK 0x00003ffe /* At least according to the calculations of Christoph Brill */ + +/* Resolve Buffer Control. Unpipelined */ +#define R300_RB3D_AARESOLVE_CTL 0x4e88 +# define R300_RB3D_AARESOLVE_CTL_AARESOLVE_MODE_NORMAL (0 << 0) +# define R300_RB3D_AARESOLVE_CTL_AARESOLVE_MODE_RESOLVE (1 << 0) +# define R300_RB3D_AARESOLVE_CTL_AARESOLVE_GAMMA_10 (0 << 1) +# define R300_RB3D_AARESOLVE_CTL_AARESOLVE_GAMMA_22 (1 << 1) +# define R300_RB3D_AARESOLVE_CTL_AARESOLVE_ALPHA_SAMPLE0 (0 << 2) +# define R300_RB3D_AARESOLVE_CTL_AARESOLVE_ALPHA_AVERAGE (1 << 2) + + +/* Discard src pixels less than or equal to threshold. */ +#define R500_RB3D_DISCARD_SRC_PIXEL_LTE_THRESHOLD 0x4ea0 +/* Discard src pixels greater than or equal to threshold. */ +#define R500_RB3D_DISCARD_SRC_PIXEL_GTE_THRESHOLD 0x4ea4 +# define R500_RB3D_DISCARD_SRC_PIXEL_THRESHOLD_BLUE_SHIFT 0 +# define R500_RB3D_DISCARD_SRC_PIXEL_THRESHOLD_BLUE_MASK 0x000000ff +# define R500_RB3D_DISCARD_SRC_PIXEL_THRESHOLD_GREEN_SHIFT 8 +# define R500_RB3D_DISCARD_SRC_PIXEL_THRESHOLD_GREEN_MASK 0x0000ff00 +# define R500_RB3D_DISCARD_SRC_PIXEL_THRESHOLD_RED_SHIFT 16 +# define R500_RB3D_DISCARD_SRC_PIXEL_THRESHOLD_RED_MASK 0x00ff0000 +# define R500_RB3D_DISCARD_SRC_PIXEL_THRESHOLD_ALPHA_SHIFT 24 +# define R500_RB3D_DISCARD_SRC_PIXEL_THRESHOLD_ALPHA_MASK 0xff000000 + +/* 3D ROP Control. Stalls the 2d/3d datapath until it is idle. */ +#define R300_RB3D_ROPCNTL 0x4e18 +# define R300_RB3D_ROPCNTL_ROP_ENABLE 0x00000004 +# define R300_RB3D_ROPCNTL_ROP_MASK (15 << 8) +# define R300_RB3D_ROPCNTL_ROP_SHIFT 8 + +/* Color Compare Flip. Stalls the 2d/3d datapath until it is idle. */ +#define R300_RB3D_CLRCMP_FLIPE 0x4e1c + +/* Sets the fifo sizes */ +#define R500_RB3D_FIFO_SIZE 0x4ef4 +# define R500_RB3D_FIFO_SIZE_OP_FIFO_SIZE_FULL (0 << 0) +# define R500_RB3D_FIFO_SIZE_OP_FIFO_SIZE_HALF (1 << 0) +# define R500_RB3D_FIFO_SIZE_OP_FIFO_SIZE_QUATER (2 << 0) +# define R500_RB3D_FIFO_SIZE_OP_FIFO_SIZE_EIGTHS (3 << 0) + +/* Constant color used by the blender. Pipelined through the blender. */ +#define R500_RB3D_CONSTANT_COLOR_AR 0x4ef8 +# define R500_RB3D_CONSTANT_COLOR_AR_RED_MASK 0x0000ffff +# define R500_RB3D_CONSTANT_COLOR_AR_RED_SHIFT 0 +# define R500_RB3D_CONSTANT_COLOR_AR_ALPHA_MASK 0xffff0000 +# define R500_RB3D_CONSTANT_COLOR_AR_ALPHA_SHIFT 16 + +/* Constant color used by the blender. Pipelined through the blender. */ +#define R500_RB3D_CONSTANT_COLOR_GB 0x4efc +# define R500_RB3D_CONSTANT_COLOR_AR_BLUE_MASK 0x0000ffff +# define R500_RB3D_CONSTANT_COLOR_AR_BLUE_SHIFT 0 +# define R500_RB3D_CONSTANT_COLOR_AR_GREEN_MASK 0xffff0000 +# define R500_RB3D_CONSTANT_COLOR_AR_GREEN_SHIFT 16 + +/* gap */ +/* There seems to be no "write only" setting, so use Z-test = ALWAYS + * for this. + * Bit (1<<8) is the "test" bit. so plain write is 6 - vd + */ +#define R300_ZB_CNTL 0x4F00 +# define R300_STENCIL_ENABLE (1 << 0) +# define R300_Z_ENABLE (1 << 1) +# define R300_Z_WRITE_ENABLE (1 << 2) +# define R300_Z_SIGNED_COMPARE (1 << 3) +# define R300_STENCIL_FRONT_BACK (1 << 4) +# define R500_STENCIL_ZSIGNED_MAGNITUDE (1 << 5) +# define R500_STENCIL_REFMASK_FRONT_BACK (1 << 6) + +#define R300_ZB_ZSTENCILCNTL 0x4f04 + /* functions */ +# define R300_ZS_NEVER 0 +# define R300_ZS_LESS 1 +# define R300_ZS_LEQUAL 2 +# define R300_ZS_EQUAL 3 +# define R300_ZS_GEQUAL 4 +# define R300_ZS_GREATER 5 +# define R300_ZS_NOTEQUAL 6 +# define R300_ZS_ALWAYS 7 +# define R300_ZS_MASK 7 + /* operations */ +# define R300_ZS_KEEP 0 +# define R300_ZS_ZERO 1 +# define R300_ZS_REPLACE 2 +# define R300_ZS_INCR 3 +# define R300_ZS_DECR 4 +# define R300_ZS_INVERT 5 +# define R300_ZS_INCR_WRAP 6 +# define R300_ZS_DECR_WRAP 7 +# define R300_Z_FUNC_SHIFT 0 + /* front and back refer to operations done for front + and back faces, i.e. separate stencil function support */ +# define R300_S_FRONT_FUNC_SHIFT 3 +# define R300_S_FRONT_SFAIL_OP_SHIFT 6 +# define R300_S_FRONT_ZPASS_OP_SHIFT 9 +# define R300_S_FRONT_ZFAIL_OP_SHIFT 12 +# define R300_S_BACK_FUNC_SHIFT 15 +# define R300_S_BACK_SFAIL_OP_SHIFT 18 +# define R300_S_BACK_ZPASS_OP_SHIFT 21 +# define R300_S_BACK_ZFAIL_OP_SHIFT 24 + +#define R300_ZB_STENCILREFMASK 0x4f08 +# define R300_STENCILREF_SHIFT 0 +# define R300_STENCILREF_MASK 0x000000ff +# define R300_STENCILMASK_SHIFT 8 +# define R300_STENCILMASK_MASK 0x0000ff00 +# define R300_STENCILWRITEMASK_SHIFT 16 +# define R300_STENCILWRITEMASK_MASK 0x00ff0000 + +/* gap */ + +#define R300_ZB_FORMAT 0x4f10 +# define R300_DEPTHFORMAT_16BIT_INT_Z (0 << 0) +# define R300_DEPTHFORMAT_16BIT_13E3 (1 << 0) +# define R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL (2 << 0) +/* reserved up to (15 << 0) */ +# define R300_INVERT_13E3_LEADING_ONES (0 << 4) +# define R300_INVERT_13E3_LEADING_ZEROS (1 << 4) + +#define R300_ZB_ZTOP 0x4F14 +# define R300_ZTOP_DISABLE (0 << 0) +# define R300_ZTOP_ENABLE (1 << 0) + +/* gap */ + +#define R300_ZB_ZCACHE_CTLSTAT 0x4f18 +# define R300_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_NO_EFFECT (0 << 0) +# define R300_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_FLUSH_AND_FREE (1 << 0) +# define R300_ZB_ZCACHE_CTLSTAT_ZC_FREE_NO_EFFECT (0 << 1) +# define R300_ZB_ZCACHE_CTLSTAT_ZC_FREE_FREE (1 << 1) +# define R300_ZB_ZCACHE_CTLSTAT_ZC_BUSY_IDLE (0 << 31) +# define R300_ZB_ZCACHE_CTLSTAT_ZC_BUSY_BUSY (1 << 31) + +#define R300_ZB_BW_CNTL 0x4f1c +# define R300_HIZ_DISABLE (0 << 0) +# define R300_HIZ_ENABLE (1 << 0) +# define R300_HIZ_MIN (0 << 1) +# define R300_HIZ_MAX (1 << 1) +# define R300_FAST_FILL_DISABLE (0 << 2) +# define R300_FAST_FILL_ENABLE (1 << 2) +# define R300_RD_COMP_DISABLE (0 << 3) +# define R300_RD_COMP_ENABLE (1 << 3) +# define R300_WR_COMP_DISABLE (0 << 4) +# define R300_WR_COMP_ENABLE (1 << 4) +# define R300_ZB_CB_CLEAR_RMW (0 << 5) +# define R300_ZB_CB_CLEAR_CACHE_LINE_WRITE_ONLY (1 << 5) +# define R300_FORCE_COMPRESSED_STENCIL_VALUE_DISABLE (0 << 6) +# define R300_FORCE_COMPRESSED_STENCIL_VALUE_ENABLE (1 << 6) + +# define R500_ZEQUAL_OPTIMIZE_ENABLE (0 << 7) +# define R500_ZEQUAL_OPTIMIZE_DISABLE (1 << 7) +# define R500_SEQUAL_OPTIMIZE_ENABLE (0 << 8) +# define R500_SEQUAL_OPTIMIZE_DISABLE (1 << 8) + +# define R500_BMASK_ENABLE (0 << 10) +# define R500_BMASK_DISABLE (1 << 10) +# define R500_HIZ_EQUAL_REJECT_DISABLE (0 << 11) +# define R500_HIZ_EQUAL_REJECT_ENABLE (1 << 11) +# define R500_HIZ_FP_EXP_BITS_DISABLE (0 << 12) +# define R500_HIZ_FP_EXP_BITS_1 (1 << 12) +# define R500_HIZ_FP_EXP_BITS_2 (2 << 12) +# define R500_HIZ_FP_EXP_BITS_3 (3 << 12) +# define R500_HIZ_FP_EXP_BITS_4 (4 << 12) +# define R500_HIZ_FP_EXP_BITS_5 (5 << 12) +# define R500_HIZ_FP_INVERT_LEADING_ONES (0 << 15) +# define R500_HIZ_FP_INVERT_LEADING_ZEROS (1 << 15) +# define R500_TILE_OVERWRITE_RECOMPRESSION_ENABLE (0 << 16) +# define R500_TILE_OVERWRITE_RECOMPRESSION_DISABLE (1 << 16) +# define R500_CONTIGUOUS_6XAA_SAMPLES_ENABLE (0 << 17) +# define R500_CONTIGUOUS_6XAA_SAMPLES_DISABLE (1 << 17) +# define R500_PEQ_PACKING_DISABLE (0 << 18) +# define R500_PEQ_PACKING_ENABLE (1 << 18) +# define R500_COVERED_PTR_MASKING_DISABLE (0 << 18) +# define R500_COVERED_PTR_MASKING_ENABLE (1 << 18) + + +/* gap */ + +/* Z Buffer Address Offset. + * Bits 31 to 5 are used for aligned Z buffer address offset for macro tiles. + */ +#define R300_ZB_DEPTHOFFSET 0x4f20 + +/* Z Buffer Pitch and Endian Control */ +#define R300_ZB_DEPTHPITCH 0x4f24 +# define R300_DEPTHPITCH_MASK 0x00003FFC +# define R300_DEPTHMACROTILE_DISABLE (0 << 16) +# define R300_DEPTHMACROTILE_ENABLE (1 << 16) +# define R300_DEPTHMACROTILE(x) ((x) << 16) +# define R300_DEPTHMICROTILE_LINEAR (0 << 17) +# define R300_DEPTHMICROTILE_TILED (1 << 17) +# define R300_DEPTHMICROTILE_TILED_SQUARE (2 << 17) +# define R300_DEPTHMICROTILE(x) ((x) << 17) +# define R300_DEPTHENDIAN_NO_SWAP (0 << 18) +# define R300_DEPTHENDIAN_WORD_SWAP (1 << 18) +# define R300_DEPTHENDIAN_DWORD_SWAP (2 << 18) +# define R300_DEPTHENDIAN_HALF_DWORD_SWAP (3 << 18) + +/* Z Buffer Clear Value */ +#define R300_ZB_DEPTHCLEARVALUE 0x4f28 + +/* Z Mask RAM is a Z compression buffer. + * Each dword of the Z Mask contains compression info for 16 4x4 pixel blocks, + * that is 2 bits for each block. + * On chips with 2 Z pipes, every other dword maps to a different pipe. + */ + +/* The dword offset into Z mask RAM (bits 18:4) */ +#define R300_ZB_ZMASK_OFFSET 0x4f30 + +/* Z Mask Pitch. */ +#define R300_ZB_ZMASK_PITCH 0x4f34 + +/* Access to Z Mask RAM in a manner similar to HiZ RAM. + * The indices are autoincrementing. */ +#define R300_ZB_ZMASK_WRINDEX 0x4f38 +#define R300_ZB_ZMASK_DWORD 0x4f3c +#define R300_ZB_ZMASK_RDINDEX 0x4f40 + +/* Hierarchical Z Memory Offset */ +#define R300_ZB_HIZ_OFFSET 0x4f44 + +/* Hierarchical Z Write Index */ +#define R300_ZB_HIZ_WRINDEX 0x4f48 + +/* Hierarchical Z Data */ +#define R300_ZB_HIZ_DWORD 0x4f4c + +/* Hierarchical Z Read Index */ +#define R300_ZB_HIZ_RDINDEX 0x4f50 + +/* Hierarchical Z Pitch */ +#define R300_ZB_HIZ_PITCH 0x4f54 + +/* Z Buffer Z Pass Counter Data */ +#define R300_ZB_ZPASS_DATA 0x4f58 + +/* Z Buffer Z Pass Counter Address */ +#define R300_ZB_ZPASS_ADDR 0x4f5c + +/* Depth buffer X and Y coordinate offset */ +#define R300_ZB_DEPTHXY_OFFSET 0x4f60 +# define R300_DEPTHX_OFFSET_SHIFT 1 +# define R300_DEPTHX_OFFSET_MASK 0x000007FE +# define R300_DEPTHY_OFFSET_SHIFT 17 +# define R300_DEPTHY_OFFSET_MASK 0x07FE0000 + +/* Sets the fifo sizes */ +#define R500_ZB_FIFO_SIZE 0x4fd0 +# define R500_OP_FIFO_SIZE_FULL (0 << 0) +# define R500_OP_FIFO_SIZE_HALF (1 << 0) +# define R500_OP_FIFO_SIZE_QUATER (2 << 0) +# define R500_OP_FIFO_SIZE_EIGTHS (4 << 0) + +/* Stencil Reference Value and Mask for backfacing quads */ +/* R300_ZB_STENCILREFMASK handles front face */ +#define R500_ZB_STENCILREFMASK_BF 0x4fd4 +# define R500_STENCILREF_SHIFT 0 +# define R500_STENCILREF_MASK 0x000000ff +# define R500_STENCILMASK_SHIFT 8 +# define R500_STENCILMASK_MASK 0x0000ff00 +# define R500_STENCILWRITEMASK_SHIFT 16 +# define R500_STENCILWRITEMASK_MASK 0x00ff0000 + +/** + * \defgroup R3XX_R5XX_PROGRAMMABLE_VERTEX_SHADER_DESCRIPTION R3XX-R5XX PROGRAMMABLE VERTEX SHADER DESCRIPTION + * + * The PVS_DST_MATH_INST is used to identify whether the instruction is a Vector + * Engine instruction or a Math Engine instruction. + */ + +/*\{*/ + +enum { + /* R3XX */ + VECTOR_NO_OP = 0, + VE_DOT_PRODUCT = 1, + VE_MULTIPLY = 2, + VE_ADD = 3, + VE_MULTIPLY_ADD = 4, + VE_DISTANCE_VECTOR = 5, + VE_FRACTION = 6, + VE_MAXIMUM = 7, + VE_MINIMUM = 8, + VE_SET_GREATER_THAN_EQUAL = 9, + VE_SET_LESS_THAN = 10, + VE_MULTIPLYX2_ADD = 11, + VE_MULTIPLY_CLAMP = 12, + VE_FLT2FIX_DX = 13, + VE_FLT2FIX_DX_RND = 14, + /* R5XX */ + VE_PRED_SET_EQ_PUSH = 15, + VE_PRED_SET_GT_PUSH = 16, + VE_PRED_SET_GTE_PUSH = 17, + VE_PRED_SET_NEQ_PUSH = 18, + VE_COND_WRITE_EQ = 19, + VE_COND_WRITE_GT = 20, + VE_COND_WRITE_GTE = 21, + VE_COND_WRITE_NEQ = 22, + VE_COND_MUX_EQ = 23, + VE_COND_MUX_GT = 24, + VE_COND_MUX_GTE = 25, + VE_SET_GREATER_THAN = 26, + VE_SET_EQUAL = 27, + VE_SET_NOT_EQUAL = 28 +}; + +enum { + /* R3XX */ + MATH_NO_OP = 0, + ME_EXP_BASE2_DX = 1, + ME_LOG_BASE2_DX = 2, + ME_EXP_BASEE_FF = 3, + ME_LIGHT_COEFF_DX = 4, + ME_POWER_FUNC_FF = 5, + ME_RECIP_DX = 6, + ME_RECIP_FF = 7, + ME_RECIP_SQRT_DX = 8, + ME_RECIP_SQRT_FF = 9, + ME_MULTIPLY = 10, + ME_EXP_BASE2_FULL_DX = 11, + ME_LOG_BASE2_FULL_DX = 12, + ME_POWER_FUNC_FF_CLAMP_B = 13, + ME_POWER_FUNC_FF_CLAMP_B1 = 14, + ME_POWER_FUNC_FF_CLAMP_01 = 15, + ME_SIN = 16, + ME_COS = 17, + /* R5XX */ + ME_LOG_BASE2_IEEE = 18, + ME_RECIP_IEEE = 19, + ME_RECIP_SQRT_IEEE = 20, + ME_PRED_SET_EQ = 21, + ME_PRED_SET_GT = 22, + ME_PRED_SET_GTE = 23, + ME_PRED_SET_NEQ = 24, + ME_PRED_SET_CLR = 25, + ME_PRED_SET_INV = 26, + ME_PRED_SET_POP = 27, + ME_PRED_SET_RESTORE = 28 +}; + +enum { + /* R3XX */ + PVS_MACRO_OP_2CLK_MADD = 0, + PVS_MACRO_OP_2CLK_M2X_ADD = 1 +}; + +enum { + PVS_SRC_REG_TEMPORARY = 0, /* Intermediate Storage */ + PVS_SRC_REG_INPUT = 1, /* Input Vertex Storage */ + PVS_SRC_REG_CONSTANT = 2, /* Constant State Storage */ + PVS_SRC_REG_ALT_TEMPORARY = 3 /* Alternate Intermediate Storage */ +}; + +enum { + PVS_DST_REG_TEMPORARY = 0, /* Intermediate Storage */ + PVS_DST_REG_A0 = 1, /* Address Register Storage */ + PVS_DST_REG_OUT = 2, /* Output Memory. Used for all outputs */ + PVS_DST_REG_OUT_REPL_X = 3, /* Output Memory & Replicate X to all channels */ + PVS_DST_REG_ALT_TEMPORARY = 4, /* Alternate Intermediate Storage */ + PVS_DST_REG_INPUT = 5 /* Output Memory & Replicate X to all channels */ +}; + +enum { + PVS_SRC_SELECT_X = 0, /* Select X Component */ + PVS_SRC_SELECT_Y = 1, /* Select Y Component */ + PVS_SRC_SELECT_Z = 2, /* Select Z Component */ + PVS_SRC_SELECT_W = 3, /* Select W Component */ + PVS_SRC_SELECT_FORCE_0 = 4, /* Force Component to 0.0 */ + PVS_SRC_SELECT_FORCE_1 = 5 /* Force Component to 1.0 */ +}; + +/* PVS Opcode & Destination Operand Description */ + +enum { + PVS_DST_OPCODE_MASK = 0x3f, + PVS_DST_OPCODE_SHIFT = 0, + PVS_DST_MATH_INST_MASK = 0x1, + PVS_DST_MATH_INST_SHIFT = 6, + PVS_DST_MACRO_INST_MASK = 0x1, + PVS_DST_MACRO_INST_SHIFT = 7, + PVS_DST_REG_TYPE_MASK = 0xf, + PVS_DST_REG_TYPE_SHIFT = 8, + PVS_DST_ADDR_MODE_1_MASK = 0x1, + PVS_DST_ADDR_MODE_1_SHIFT = 12, + PVS_DST_OFFSET_MASK = 0x7f, + PVS_DST_OFFSET_SHIFT = 13, + PVS_DST_WE_X_MASK = 0x1, + PVS_DST_WE_X_SHIFT = 20, + PVS_DST_WE_Y_MASK = 0x1, + PVS_DST_WE_Y_SHIFT = 21, + PVS_DST_WE_Z_MASK = 0x1, + PVS_DST_WE_Z_SHIFT = 22, + PVS_DST_WE_W_MASK = 0x1, + PVS_DST_WE_W_SHIFT = 23, + PVS_DST_VE_SAT_MASK = 0x1, + PVS_DST_VE_SAT_SHIFT = 24, + PVS_DST_ME_SAT_MASK = 0x1, + PVS_DST_ME_SAT_SHIFT = 25, + PVS_DST_PRED_ENABLE_MASK = 0x1, + PVS_DST_PRED_ENABLE_SHIFT = 26, + PVS_DST_PRED_SENSE_MASK = 0x1, + PVS_DST_PRED_SENSE_SHIFT = 27, + PVS_DST_DUAL_MATH_OP_MASK = 0x3, + PVS_DST_DUAL_MATH_OP_SHIFT = 27, + PVS_DST_ADDR_SEL_MASK = 0x3, + PVS_DST_ADDR_SEL_SHIFT = 29, + PVS_DST_ADDR_MODE_0_MASK = 0x1, + PVS_DST_ADDR_MODE_0_SHIFT = 31 +}; + +/* PVS Source Operand Description */ + +enum { + PVS_SRC_REG_TYPE_MASK = 0x3, + PVS_SRC_REG_TYPE_SHIFT = 0, + SPARE_0_MASK = 0x1, + SPARE_0_SHIFT = 2, + PVS_SRC_ABS_XYZW_MASK = 0x1, + PVS_SRC_ABS_XYZW_SHIFT = 3, + PVS_SRC_ADDR_MODE_0_MASK = 0x1, + PVS_SRC_ADDR_MODE_0_SHIFT = 4, + PVS_SRC_OFFSET_MASK = 0xff, + PVS_SRC_OFFSET_SHIFT = 5, + PVS_SRC_SWIZZLE_X_MASK = 0x7, + PVS_SRC_SWIZZLE_X_SHIFT = 13, + PVS_SRC_SWIZZLE_Y_MASK = 0x7, + PVS_SRC_SWIZZLE_Y_SHIFT = 16, + PVS_SRC_SWIZZLE_Z_MASK = 0x7, + PVS_SRC_SWIZZLE_Z_SHIFT = 19, + PVS_SRC_SWIZZLE_W_MASK = 0x7, + PVS_SRC_SWIZZLE_W_SHIFT = 22, + PVS_SRC_MODIFIER_X_MASK = 0x1, + PVS_SRC_MODIFIER_X_SHIFT = 25, + PVS_SRC_MODIFIER_Y_MASK = 0x1, + PVS_SRC_MODIFIER_Y_SHIFT = 26, + PVS_SRC_MODIFIER_Z_MASK = 0x1, + PVS_SRC_MODIFIER_Z_SHIFT = 27, + PVS_SRC_MODIFIER_W_MASK = 0x1, + PVS_SRC_MODIFIER_W_SHIFT = 28, + PVS_SRC_ADDR_SEL_MASK = 0x3, + PVS_SRC_ADDR_SEL_SHIFT = 29, + PVS_SRC_ADDR_MODE_1_MASK = 0x0, + PVS_SRC_ADDR_MODE_1_SHIFT = 32 +}; + +/*\}*/ + +/* BEGIN: Packet 3 commands */ + +/* A primitive emission dword. */ +#define R300_PRIM_TYPE_NONE (0 << 0) +#define R300_PRIM_TYPE_POINT (1 << 0) +#define R300_PRIM_TYPE_LINE (2 << 0) +#define R300_PRIM_TYPE_LINE_STRIP (3 << 0) +#define R300_PRIM_TYPE_TRI_LIST (4 << 0) +#define R300_PRIM_TYPE_TRI_FAN (5 << 0) +#define R300_PRIM_TYPE_TRI_STRIP (6 << 0) +#define R300_PRIM_TYPE_TRI_TYPE2 (7 << 0) +#define R300_PRIM_TYPE_RECT_LIST (8 << 0) +#define R300_PRIM_TYPE_3VRT_POINT_LIST (9 << 0) +#define R300_PRIM_TYPE_3VRT_LINE_LIST (10 << 0) + /* GUESS (based on r200) */ +#define R300_PRIM_TYPE_POINT_SPRITES (11 << 0) +#define R300_PRIM_TYPE_LINE_LOOP (12 << 0) +#define R300_PRIM_TYPE_QUADS (13 << 0) +#define R300_PRIM_TYPE_QUAD_STRIP (14 << 0) +#define R300_PRIM_TYPE_POLYGON (15 << 0) +#define R300_PRIM_TYPE_MASK 0xF +#define R300_PRIM_WALK_IND (1 << 4) +#define R300_PRIM_WALK_LIST (2 << 4) +#define R300_PRIM_WALK_RING (3 << 4) +#define R300_PRIM_WALK_MASK (3 << 4) + /* GUESS (based on r200) */ +#define R300_PRIM_COLOR_ORDER_BGRA (0 << 6) +#define R300_PRIM_COLOR_ORDER_RGBA (1 << 6) +#define R300_PRIM_NUM_VERTICES_SHIFT 16 +#define R300_PRIM_NUM_VERTICES_MASK 0xffff + + + +/* + * The R500 unified shader (US) registers come in banks of 512 each, one + * for each instruction slot in the shader. You can't touch them directly. + * R500_US_VECTOR_INDEX() sets the base instruction to modify; successive + * writes to R500_GA_US_VECTOR_DATA autoincrement the index after the + * instruction is fully specified. + */ +#define R500_US_ALU_ALPHA_INST_0 0xa800 +# define R500_ALPHA_OP_MAD 0 +# define R500_ALPHA_OP_DP 1 +# define R500_ALPHA_OP_MIN 2 +# define R500_ALPHA_OP_MAX 3 +/* #define R500_ALPHA_OP_RESERVED 4 */ +# define R500_ALPHA_OP_CND 5 +# define R500_ALPHA_OP_CMP 6 +# define R500_ALPHA_OP_FRC 7 +# define R500_ALPHA_OP_EX2 8 +# define R500_ALPHA_OP_LN2 9 +# define R500_ALPHA_OP_RCP 10 +# define R500_ALPHA_OP_RSQ 11 +# define R500_ALPHA_OP_SIN 12 +# define R500_ALPHA_OP_COS 13 +# define R500_ALPHA_OP_MDH 14 +# define R500_ALPHA_OP_MDV 15 +# define R500_ALPHA_ADDRD(x) ((x) << 4) +# define R500_ALPHA_ADDRD_REL (1 << 11) +# define R500_ALPHA_SEL_A_SHIFT 12 +# define R500_ALPHA_SEL_A_SRC0 (0 << 12) +# define R500_ALPHA_SEL_A_SRC1 (1 << 12) +# define R500_ALPHA_SEL_A_SRC2 (2 << 12) +# define R500_ALPHA_SEL_A_SRCP (3 << 12) +# define R500_ALPHA_SWIZ_A_R (0 << 14) +# define R500_ALPHA_SWIZ_A_G (1 << 14) +# define R500_ALPHA_SWIZ_A_B (2 << 14) +# define R500_ALPHA_SWIZ_A_A (3 << 14) +# define R500_ALPHA_SWIZ_A_0 (4 << 14) +# define R500_ALPHA_SWIZ_A_HALF (5 << 14) +# define R500_ALPHA_SWIZ_A_1 (6 << 14) +/* #define R500_ALPHA_SWIZ_A_UNUSED (7 << 14) */ +# define R500_ALPHA_MOD_A_NOP (0 << 17) +# define R500_ALPHA_MOD_A_NEG (1 << 17) +# define R500_ALPHA_MOD_A_ABS (2 << 17) +# define R500_ALPHA_MOD_A_NAB (3 << 17) +# define R500_ALPHA_SEL_B_SHIFT 19 +# define R500_ALPHA_SEL_B_SRC0 (0 << 19) +# define R500_ALPHA_SEL_B_SRC1 (1 << 19) +# define R500_ALPHA_SEL_B_SRC2 (2 << 19) +# define R500_ALPHA_SEL_B_SRCP (3 << 19) +# define R500_ALPHA_SWIZ_B_R (0 << 21) +# define R500_ALPHA_SWIZ_B_G (1 << 21) +# define R500_ALPHA_SWIZ_B_B (2 << 21) +# define R500_ALPHA_SWIZ_B_A (3 << 21) +# define R500_ALPHA_SWIZ_B_0 (4 << 21) +# define R500_ALPHA_SWIZ_B_HALF (5 << 21) +# define R500_ALPHA_SWIZ_B_1 (6 << 21) +/* #define R500_ALPHA_SWIZ_B_UNUSED (7 << 21) */ +# define R500_ALPHA_MOD_B_NOP (0 << 24) +# define R500_ALPHA_MOD_B_NEG (1 << 24) +# define R500_ALPHA_MOD_B_ABS (2 << 24) +# define R500_ALPHA_MOD_B_NAB (3 << 24) +# define R500_ALPHA_OMOD_IDENTITY (0 << 26) +# define R500_ALPHA_OMOD_MUL_2 (1 << 26) +# define R500_ALPHA_OMOD_MUL_4 (2 << 26) +# define R500_ALPHA_OMOD_MUL_8 (3 << 26) +# define R500_ALPHA_OMOD_DIV_2 (4 << 26) +# define R500_ALPHA_OMOD_DIV_4 (5 << 26) +# define R500_ALPHA_OMOD_DIV_8 (6 << 26) +# define R500_ALPHA_OMOD_DISABLE (7 << 26) +# define R500_ALPHA_TARGET(x) ((x) << 29) +# define R500_ALPHA_W_OMASK (1 << 31) +#define R500_US_ALU_ALPHA_ADDR_0 0x9800 +# define R500_ALPHA_ADDR0(x) ((x) << 0) +# define R500_ALPHA_ADDR0_CONST (1 << 8) +# define R500_ALPHA_ADDR0_REL (1 << 9) +# define R500_ALPHA_ADDR1(x) ((x) << 10) +# define R500_ALPHA_ADDR1_CONST (1 << 18) +# define R500_ALPHA_ADDR1_REL (1 << 19) +# define R500_ALPHA_ADDR2(x) ((x) << 20) +# define R500_ALPHA_ADDR2_CONST (1 << 28) +# define R500_ALPHA_ADDR2_REL (1 << 29) +# define R500_ALPHA_SRCP_OP_1_MINUS_2A0 (0 << 30) +# define R500_ALPHA_SRCP_OP_A1_MINUS_A0 (1 << 30) +# define R500_ALPHA_SRCP_OP_A1_PLUS_A0 (2 << 30) +# define R500_ALPHA_SRCP_OP_1_MINUS_A0 (3 << 30) +#define R500_US_ALU_RGBA_INST_0 0xb000 +# define R500_ALU_RGBA_OP_MAD (0 << 0) +# define R500_ALU_RGBA_OP_DP3 (1 << 0) +# define R500_ALU_RGBA_OP_DP4 (2 << 0) +# define R500_ALU_RGBA_OP_D2A (3 << 0) +# define R500_ALU_RGBA_OP_MIN (4 << 0) +# define R500_ALU_RGBA_OP_MAX (5 << 0) +/* #define R500_ALU_RGBA_OP_RESERVED (6 << 0) */ +# define R500_ALU_RGBA_OP_CND (7 << 0) +# define R500_ALU_RGBA_OP_CMP (8 << 0) +# define R500_ALU_RGBA_OP_FRC (9 << 0) +# define R500_ALU_RGBA_OP_SOP (10 << 0) +# define R500_ALU_RGBA_OP_MDH (11 << 0) +# define R500_ALU_RGBA_OP_MDV (12 << 0) +# define R500_ALU_RGBA_ADDRD(x) ((x) << 4) +# define R500_ALU_RGBA_ADDRD_REL (1 << 11) +# define R500_ALU_RGBA_SEL_C_SHIFT 12 +# define R500_ALU_RGBA_SEL_C_SRC0 (0 << 12) +# define R500_ALU_RGBA_SEL_C_SRC1 (1 << 12) +# define R500_ALU_RGBA_SEL_C_SRC2 (2 << 12) +# define R500_ALU_RGBA_SEL_C_SRCP (3 << 12) +# define R500_ALU_RGBA_R_SWIZ_R (0 << 14) +# define R500_ALU_RGBA_R_SWIZ_G (1 << 14) +# define R500_ALU_RGBA_R_SWIZ_B (2 << 14) +# define R500_ALU_RGBA_R_SWIZ_A (3 << 14) +# define R500_ALU_RGBA_R_SWIZ_0 (4 << 14) +# define R500_ALU_RGBA_R_SWIZ_HALF (5 << 14) +# define R500_ALU_RGBA_R_SWIZ_1 (6 << 14) +/* #define R500_ALU_RGBA_R_SWIZ_UNUSED (7 << 14) */ +# define R500_ALU_RGBA_G_SWIZ_R (0 << 17) +# define R500_ALU_RGBA_G_SWIZ_G (1 << 17) +# define R500_ALU_RGBA_G_SWIZ_B (2 << 17) +# define R500_ALU_RGBA_G_SWIZ_A (3 << 17) +# define R500_ALU_RGBA_G_SWIZ_0 (4 << 17) +# define R500_ALU_RGBA_G_SWIZ_HALF (5 << 17) +# define R500_ALU_RGBA_G_SWIZ_1 (6 << 17) +/* #define R500_ALU_RGBA_G_SWIZ_UNUSED (7 << 17) */ +# define R500_ALU_RGBA_B_SWIZ_R (0 << 20) +# define R500_ALU_RGBA_B_SWIZ_G (1 << 20) +# define R500_ALU_RGBA_B_SWIZ_B (2 << 20) +# define R500_ALU_RGBA_B_SWIZ_A (3 << 20) +# define R500_ALU_RGBA_B_SWIZ_0 (4 << 20) +# define R500_ALU_RGBA_B_SWIZ_HALF (5 << 20) +# define R500_ALU_RGBA_B_SWIZ_1 (6 << 20) +/* #define R500_ALU_RGBA_B_SWIZ_UNUSED (7 << 20) */ +# define R500_ALU_RGBA_MOD_C_NOP (0 << 23) +# define R500_ALU_RGBA_MOD_C_NEG (1 << 23) +# define R500_ALU_RGBA_MOD_C_ABS (2 << 23) +# define R500_ALU_RGBA_MOD_C_NAB (3 << 23) +# define R500_ALU_RGBA_ALPHA_SEL_C_SHIFT 25 +# define R500_ALU_RGBA_ALPHA_SEL_C_SRC0 (0 << 25) +# define R500_ALU_RGBA_ALPHA_SEL_C_SRC1 (1 << 25) +# define R500_ALU_RGBA_ALPHA_SEL_C_SRC2 (2 << 25) +# define R500_ALU_RGBA_ALPHA_SEL_C_SRCP (3 << 25) +# define R500_ALU_RGBA_A_SWIZ_R (0 << 27) +# define R500_ALU_RGBA_A_SWIZ_G (1 << 27) +# define R500_ALU_RGBA_A_SWIZ_B (2 << 27) +# define R500_ALU_RGBA_A_SWIZ_A (3 << 27) +# define R500_ALU_RGBA_A_SWIZ_0 (4 << 27) +# define R500_ALU_RGBA_A_SWIZ_HALF (5 << 27) +# define R500_ALU_RGBA_A_SWIZ_1 (6 << 27) +/* #define R500_ALU_RGBA_A_SWIZ_UNUSED (7 << 27) */ +# define R500_ALU_RGBA_ALPHA_MOD_C_NOP (0 << 30) +# define R500_ALU_RGBA_ALPHA_MOD_C_NEG (1 << 30) +# define R500_ALU_RGBA_ALPHA_MOD_C_ABS (2 << 30) +# define R500_ALU_RGBA_ALPHA_MOD_C_NAB (3 << 30) +#define R500_US_ALU_RGB_INST_0 0xa000 +# define R500_ALU_RGB_SEL_A_SHIFT 0 +# define R500_ALU_RGB_SEL_A_SRC0 (0 << 0) +# define R500_ALU_RGB_SEL_A_SRC1 (1 << 0) +# define R500_ALU_RGB_SEL_A_SRC2 (2 << 0) +# define R500_ALU_RGB_SEL_A_SRCP (3 << 0) +# define R500_ALU_RGB_R_SWIZ_A_R (0 << 2) +# define R500_ALU_RGB_R_SWIZ_A_G (1 << 2) +# define R500_ALU_RGB_R_SWIZ_A_B (2 << 2) +# define R500_ALU_RGB_R_SWIZ_A_A (3 << 2) +# define R500_ALU_RGB_R_SWIZ_A_0 (4 << 2) +# define R500_ALU_RGB_R_SWIZ_A_HALF (5 << 2) +# define R500_ALU_RGB_R_SWIZ_A_1 (6 << 2) +/* #define R500_ALU_RGB_R_SWIZ_A_UNUSED (7 << 2) */ +# define R500_ALU_RGB_G_SWIZ_A_R (0 << 5) +# define R500_ALU_RGB_G_SWIZ_A_G (1 << 5) +# define R500_ALU_RGB_G_SWIZ_A_B (2 << 5) +# define R500_ALU_RGB_G_SWIZ_A_A (3 << 5) +# define R500_ALU_RGB_G_SWIZ_A_0 (4 << 5) +# define R500_ALU_RGB_G_SWIZ_A_HALF (5 << 5) +# define R500_ALU_RGB_G_SWIZ_A_1 (6 << 5) +/* #define R500_ALU_RGB_G_SWIZ_A_UNUSED (7 << 5) */ +# define R500_ALU_RGB_B_SWIZ_A_R (0 << 8) +# define R500_ALU_RGB_B_SWIZ_A_G (1 << 8) +# define R500_ALU_RGB_B_SWIZ_A_B (2 << 8) +# define R500_ALU_RGB_B_SWIZ_A_A (3 << 8) +# define R500_ALU_RGB_B_SWIZ_A_0 (4 << 8) +# define R500_ALU_RGB_B_SWIZ_A_HALF (5 << 8) +# define R500_ALU_RGB_B_SWIZ_A_1 (6 << 8) +/* #define R500_ALU_RGB_B_SWIZ_A_UNUSED (7 << 8) */ +# define R500_ALU_RGB_MOD_A_NOP (0 << 11) +# define R500_ALU_RGB_MOD_A_NEG (1 << 11) +# define R500_ALU_RGB_MOD_A_ABS (2 << 11) +# define R500_ALU_RGB_MOD_A_NAB (3 << 11) +# define R500_ALU_RGB_SEL_B_SHIFT 13 +# define R500_ALU_RGB_SEL_B_SRC0 (0 << 13) +# define R500_ALU_RGB_SEL_B_SRC1 (1 << 13) +# define R500_ALU_RGB_SEL_B_SRC2 (2 << 13) +# define R500_ALU_RGB_SEL_B_SRCP (3 << 13) +# define R500_ALU_RGB_R_SWIZ_B_R (0 << 15) +# define R500_ALU_RGB_R_SWIZ_B_G (1 << 15) +# define R500_ALU_RGB_R_SWIZ_B_B (2 << 15) +# define R500_ALU_RGB_R_SWIZ_B_A (3 << 15) +# define R500_ALU_RGB_R_SWIZ_B_0 (4 << 15) +# define R500_ALU_RGB_R_SWIZ_B_HALF (5 << 15) +# define R500_ALU_RGB_R_SWIZ_B_1 (6 << 15) +/* #define R500_ALU_RGB_R_SWIZ_B_UNUSED (7 << 15) */ +# define R500_ALU_RGB_G_SWIZ_B_R (0 << 18) +# define R500_ALU_RGB_G_SWIZ_B_G (1 << 18) +# define R500_ALU_RGB_G_SWIZ_B_B (2 << 18) +# define R500_ALU_RGB_G_SWIZ_B_A (3 << 18) +# define R500_ALU_RGB_G_SWIZ_B_0 (4 << 18) +# define R500_ALU_RGB_G_SWIZ_B_HALF (5 << 18) +# define R500_ALU_RGB_G_SWIZ_B_1 (6 << 18) +/* #define R500_ALU_RGB_G_SWIZ_B_UNUSED (7 << 18) */ +# define R500_ALU_RGB_B_SWIZ_B_R (0 << 21) +# define R500_ALU_RGB_B_SWIZ_B_G (1 << 21) +# define R500_ALU_RGB_B_SWIZ_B_B (2 << 21) +# define R500_ALU_RGB_B_SWIZ_B_A (3 << 21) +# define R500_ALU_RGB_B_SWIZ_B_0 (4 << 21) +# define R500_ALU_RGB_B_SWIZ_B_HALF (5 << 21) +# define R500_ALU_RGB_B_SWIZ_B_1 (6 << 21) +/* #define R500_ALU_RGB_B_SWIZ_B_UNUSED (7 << 21) */ +# define R500_ALU_RGB_MOD_B_NOP (0 << 24) +# define R500_ALU_RGB_MOD_B_NEG (1 << 24) +# define R500_ALU_RGB_MOD_B_ABS (2 << 24) +# define R500_ALU_RGB_MOD_B_NAB (3 << 24) +# define R500_ALU_RGB_OMOD_IDENTITY (0 << 26) +# define R500_ALU_RGB_OMOD_MUL_2 (1 << 26) +# define R500_ALU_RGB_OMOD_MUL_4 (2 << 26) +# define R500_ALU_RGB_OMOD_MUL_8 (3 << 26) +# define R500_ALU_RGB_OMOD_DIV_2 (4 << 26) +# define R500_ALU_RGB_OMOD_DIV_4 (5 << 26) +# define R500_ALU_RGB_OMOD_DIV_8 (6 << 26) +# define R500_ALU_RGB_OMOD_DISABLE (7 << 26) +# define R500_ALU_RGB_TARGET(x) ((x) << 29) +# define R500_ALU_RGB_WMASK (1 << 31) +#define R500_US_ALU_RGB_ADDR_0 0x9000 +# define R500_RGB_ADDR0(x) ((x) << 0) +# define R500_RGB_ADDR0_CONST (1 << 8) +# define R500_RGB_ADDR0_REL (1 << 9) +# define R500_RGB_ADDR1(x) ((x) << 10) +# define R500_RGB_ADDR1_CONST (1 << 18) +# define R500_RGB_ADDR1_REL (1 << 19) +# define R500_RGB_ADDR2(x) ((x) << 20) +# define R500_RGB_ADDR2_CONST (1 << 28) +# define R500_RGB_ADDR2_REL (1 << 29) +# define R500_RGB_SRCP_OP_1_MINUS_2RGB0 (0 << 30) +# define R500_RGB_SRCP_OP_RGB1_MINUS_RGB0 (1 << 30) +# define R500_RGB_SRCP_OP_RGB1_PLUS_RGB0 (2 << 30) +# define R500_RGB_SRCP_OP_1_MINUS_RGB0 (3 << 30) +#define R500_US_CMN_INST_0 0xb800 +# define R500_INST_TYPE_MASK (3 << 0) +# define R500_INST_TYPE_ALU (0 << 0) +# define R500_INST_TYPE_OUT (1 << 0) +# define R500_INST_TYPE_FC (2 << 0) +# define R500_INST_TYPE_TEX (3 << 0) +# define R500_INST_TEX_SEM_WAIT (1 << 2) +# define R500_INST_RGB_PRED_SEL_NONE (0 << 3) +# define R500_INST_RGB_PRED_SEL_RGBA (1 << 3) +# define R500_INST_RGB_PRED_SEL_RRRR (2 << 3) +# define R500_INST_RGB_PRED_SEL_GGGG (3 << 3) +# define R500_INST_RGB_PRED_SEL_BBBB (4 << 3) +# define R500_INST_RGB_PRED_SEL_AAAA (5 << 3) +# define R500_INST_RGB_PRED_INV (1 << 6) +# define R500_INST_WRITE_INACTIVE (1 << 7) +# define R500_INST_LAST (1 << 8) +# define R500_INST_NOP (1 << 9) +# define R500_INST_ALU_WAIT (1 << 10) +# define R500_INST_RGB_WMASK_R (1 << 11) +# define R500_INST_RGB_WMASK_G (1 << 12) +# define R500_INST_RGB_WMASK_B (1 << 13) +# define R500_INST_RGB_WMASK_RGB (7 << 11) +# define R500_INST_ALPHA_WMASK (1 << 14) +# define R500_INST_RGB_OMASK_R (1 << 15) +# define R500_INST_RGB_OMASK_G (1 << 16) +# define R500_INST_RGB_OMASK_B (1 << 17) +# define R500_INST_RGB_OMASK_RGB (7 << 15) +# define R500_INST_ALPHA_OMASK (1 << 18) +# define R500_INST_RGB_CLAMP (1 << 19) +# define R500_INST_ALPHA_CLAMP (1 << 20) +# define R500_INST_ALU_RESULT_SEL (1 << 21) +# define R500_INST_ALPHA_PRED_INV (1 << 22) +# define R500_INST_ALU_RESULT_OP_EQ (0 << 23) +# define R500_INST_ALU_RESULT_OP_LT (1 << 23) +# define R500_INST_ALU_RESULT_OP_GE (2 << 23) +# define R500_INST_ALU_RESULT_OP_NE (3 << 23) +# define R500_INST_ALPHA_PRED_SEL_NONE (0 << 25) +# define R500_INST_ALPHA_PRED_SEL_RGBA (1 << 25) +# define R500_INST_ALPHA_PRED_SEL_RRRR (2 << 25) +# define R500_INST_ALPHA_PRED_SEL_GGGG (3 << 25) +# define R500_INST_ALPHA_PRED_SEL_BBBB (4 << 25) +# define R500_INST_ALPHA_PRED_SEL_AAAA (5 << 25) +/* XXX next four are kind of guessed */ +# define R500_INST_STAT_WE_R (1 << 28) +# define R500_INST_STAT_WE_G (1 << 29) +# define R500_INST_STAT_WE_B (1 << 30) +# define R500_INST_STAT_WE_A (1 << 31) + +/* note that these are 8 bit lengths, despite the offsets, at least for R500 */ +#define R500_US_CODE_ADDR 0x4630 +# define R500_US_CODE_START_ADDR(x) ((x) << 0) +# define R500_US_CODE_END_ADDR(x) ((x) << 16) +#define R500_US_CODE_OFFSET 0x4638 +# define R500_US_CODE_OFFSET_ADDR(x) ((x) << 0) +#define R500_US_CODE_RANGE 0x4634 +# define R500_US_CODE_RANGE_ADDR(x) ((x) << 0) +# define R500_US_CODE_RANGE_SIZE(x) ((x) << 16) +#define R500_US_CONFIG 0x4600 +# define R500_ZERO_TIMES_ANYTHING_EQUALS_ZERO (1 << 1) +#define R500_US_FC_ADDR_0 0xa000 +# define R500_FC_BOOL_ADDR(x) ((x) << 0) +# define R500_FC_INT_ADDR(x) ((x) << 8) +# define R500_FC_JUMP_ADDR(x) ((x) << 16) +# define R500_FC_JUMP_GLOBAL (1 << 31) +#define R500_US_FC_BOOL_CONST 0x4620 +# define R500_FC_KBOOL(x) (x) +#define R500_US_FC_CTRL 0x4624 +# define R500_FC_TEST_EN (1 << 30) +# define R500_FC_FULL_FC_EN (1 << 31) +#define R500_US_FC_INST_0 0x9800 +# define R500_FC_OP_JUMP (0 << 0) +# define R500_FC_OP_LOOP (1 << 0) +# define R500_FC_OP_ENDLOOP (2 << 0) +# define R500_FC_OP_REP (3 << 0) +# define R500_FC_OP_ENDREP (4 << 0) +# define R500_FC_OP_BREAKLOOP (5 << 0) +# define R500_FC_OP_BREAKREP (6 << 0) +# define R500_FC_OP_CONTINUE (7 << 0) +# define R500_FC_B_ELSE (1 << 4) +# define R500_FC_JUMP_ANY (1 << 5) +# define R500_FC_A_OP_NONE (0 << 6) +# define R500_FC_A_OP_POP (1 << 6) +# define R500_FC_A_OP_PUSH (2 << 6) +# define R500_FC_JUMP_FUNC(x) ((x) << 8) +# define R500_FC_B_POP_CNT(x) ((x) << 16) +# define R500_FC_B_OP0_NONE (0 << 24) +# define R500_FC_B_OP0_DECR (1 << 24) +# define R500_FC_B_OP0_INCR (2 << 24) +# define R500_FC_B_OP1_NONE (0 << 26) +# define R500_FC_B_OP1_DECR (1 << 26) +# define R500_FC_B_OP1_INCR (2 << 26) +# define R500_FC_IGNORE_UNCOVERED (1 << 28) +#define R500_US_FC_INT_CONST_0 0x4c00 +# define R500_FC_INT_CONST_KR(x) ((x) << 0) +# define R500_FC_INT_CONST_KG(x) ((x) << 8) +# define R500_FC_INT_CONST_KB(x) ((x) << 16) +/* _0 through _15 */ +#define R500_US_FORMAT0_0 0x4640 +# define R500_FORMAT_TXWIDTH(x) ((x) << 0) +# define R500_FORMAT_TXHEIGHT(x) ((x) << 11) +# define R500_FORMAT_TXDEPTH(x) ((x) << 22) +#define R500_US_PIXSIZE 0x4604 +# define R500_PIX_SIZE(x) (x) +#define R500_US_TEX_ADDR_0 0x9800 +# define R500_TEX_SRC_ADDR(x) ((x) << 0) +# define R500_TEX_SRC_ADDR_REL (1 << 7) +# define R500_TEX_SRC_S_SWIZ_R (0 << 8) +# define R500_TEX_SRC_S_SWIZ_G (1 << 8) +# define R500_TEX_SRC_S_SWIZ_B (2 << 8) +# define R500_TEX_SRC_S_SWIZ_A (3 << 8) +# define R500_TEX_SRC_T_SWIZ_R (0 << 10) +# define R500_TEX_SRC_T_SWIZ_G (1 << 10) +# define R500_TEX_SRC_T_SWIZ_B (2 << 10) +# define R500_TEX_SRC_T_SWIZ_A (3 << 10) +# define R500_TEX_SRC_R_SWIZ_R (0 << 12) +# define R500_TEX_SRC_R_SWIZ_G (1 << 12) +# define R500_TEX_SRC_R_SWIZ_B (2 << 12) +# define R500_TEX_SRC_R_SWIZ_A (3 << 12) +# define R500_TEX_SRC_Q_SWIZ_R (0 << 14) +# define R500_TEX_SRC_Q_SWIZ_G (1 << 14) +# define R500_TEX_SRC_Q_SWIZ_B (2 << 14) +# define R500_TEX_SRC_Q_SWIZ_A (3 << 14) +# define R500_TEX_DST_ADDR(x) ((x) << 16) +# define R500_TEX_DST_ADDR_REL (1 << 23) +# define R500_TEX_DST_R_SWIZ_R (0 << 24) +# define R500_TEX_DST_R_SWIZ_G (1 << 24) +# define R500_TEX_DST_R_SWIZ_B (2 << 24) +# define R500_TEX_DST_R_SWIZ_A (3 << 24) +# define R500_TEX_DST_G_SWIZ_R (0 << 26) +# define R500_TEX_DST_G_SWIZ_G (1 << 26) +# define R500_TEX_DST_G_SWIZ_B (2 << 26) +# define R500_TEX_DST_G_SWIZ_A (3 << 26) +# define R500_TEX_DST_B_SWIZ_R (0 << 28) +# define R500_TEX_DST_B_SWIZ_G (1 << 28) +# define R500_TEX_DST_B_SWIZ_B (2 << 28) +# define R500_TEX_DST_B_SWIZ_A (3 << 28) +# define R500_TEX_DST_A_SWIZ_R (0 << 30) +# define R500_TEX_DST_A_SWIZ_G (1 << 30) +# define R500_TEX_DST_A_SWIZ_B (2 << 30) +# define R500_TEX_DST_A_SWIZ_A (3 << 30) +#define R500_US_TEX_ADDR_DXDY_0 0xa000 +# define R500_DX_ADDR(x) ((x) << 0) +# define R500_DX_ADDR_REL (1 << 7) +# define R500_DX_S_SWIZ_R (0 << 8) +# define R500_DX_S_SWIZ_G (1 << 8) +# define R500_DX_S_SWIZ_B (2 << 8) +# define R500_DX_S_SWIZ_A (3 << 8) +# define R500_DX_T_SWIZ_R (0 << 10) +# define R500_DX_T_SWIZ_G (1 << 10) +# define R500_DX_T_SWIZ_B (2 << 10) +# define R500_DX_T_SWIZ_A (3 << 10) +# define R500_DX_R_SWIZ_R (0 << 12) +# define R500_DX_R_SWIZ_G (1 << 12) +# define R500_DX_R_SWIZ_B (2 << 12) +# define R500_DX_R_SWIZ_A (3 << 12) +# define R500_DX_Q_SWIZ_R (0 << 14) +# define R500_DX_Q_SWIZ_G (1 << 14) +# define R500_DX_Q_SWIZ_B (2 << 14) +# define R500_DX_Q_SWIZ_A (3 << 14) +# define R500_DY_ADDR(x) ((x) << 16) +# define R500_DY_ADDR_REL (1 << 17) +# define R500_DY_S_SWIZ_R (0 << 24) +# define R500_DY_S_SWIZ_G (1 << 24) +# define R500_DY_S_SWIZ_B (2 << 24) +# define R500_DY_S_SWIZ_A (3 << 24) +# define R500_DY_T_SWIZ_R (0 << 26) +# define R500_DY_T_SWIZ_G (1 << 26) +# define R500_DY_T_SWIZ_B (2 << 26) +# define R500_DY_T_SWIZ_A (3 << 26) +# define R500_DY_R_SWIZ_R (0 << 28) +# define R500_DY_R_SWIZ_G (1 << 28) +# define R500_DY_R_SWIZ_B (2 << 28) +# define R500_DY_R_SWIZ_A (3 << 28) +# define R500_DY_Q_SWIZ_R (0 << 30) +# define R500_DY_Q_SWIZ_G (1 << 30) +# define R500_DY_Q_SWIZ_B (2 << 30) +# define R500_DY_Q_SWIZ_A (3 << 30) +#define R500_US_TEX_INST_0 0x9000 +# define R500_TEX_ID(x) ((x) << 16) +# define R500_TEX_INST_NOP (0 << 22) +# define R500_TEX_INST_LD (1 << 22) +# define R500_TEX_INST_TEXKILL (2 << 22) +# define R500_TEX_INST_PROJ (3 << 22) +# define R500_TEX_INST_LODBIAS (4 << 22) +# define R500_TEX_INST_LOD (5 << 22) +# define R500_TEX_INST_DXDY (6 << 22) +# define R500_TEX_SEM_ACQUIRE (1 << 25) +# define R500_TEX_IGNORE_UNCOVERED (1 << 26) +# define R500_TEX_UNSCALED (1 << 27) +#define R300_US_W_FMT 0x46b4 +# define R300_W_FMT_W0 (0 << 0) +# define R300_W_FMT_W24 (1 << 0) +# define R300_W_FMT_W24FP (2 << 0) +# define R300_W_SRC_US (0 << 2) +# define R300_W_SRC_RAS (1 << 2) + +/* Draw a primitive from vertex data in arrays loaded via 3D_LOAD_VBPNTR. + * Two parameter dwords: + * 0. VAP_VTX_FMT: The first parameter is not written to hardware + * 1. VAP_VF_CTL: The second parameter is a standard primitive emission dword. + */ +#define R300_PACKET3_3D_DRAW_VBUF 0x00002800 + +/* Draw a primitive from immediate vertices in this packet + * Up to 16382 dwords: + * 0. VAP_VTX_FMT: The first parameter is not written to hardware + * 1. VAP_VF_CTL: The second parameter is a standard primitive emission dword. + * 2 to end: Up to 16380 dwords of vertex data. + */ +#define R300_PACKET3_3D_DRAW_IMMD 0x00002900 + +/* Draw a primitive from vertex data in arrays loaded via 3D_LOAD_VBPNTR and + * immediate vertices in this packet + * Up to 16382 dwords: + * 0. VAP_VTX_FMT: The first parameter is not written to hardware + * 1. VAP_VF_CTL: The second parameter is a standard primitive emission dword. + * 2 to end: Up to 16380 dwords of vertex data. + */ +#define R300_PACKET3_3D_DRAW_INDX 0x00002A00 + + +/* Specify the full set of vertex arrays as (address, stride). + * The first parameter is the number of vertex arrays specified. + * The rest of the command is a variable length list of blocks, where + * each block is three dwords long and specifies two arrays. + * The first dword of a block is split into two words, the lower significant + * word refers to the first array, the more significant word to the second + * array in the block. + * The low byte of each word contains the size of an array entry in dwords, + * the high byte contains the stride of the array. + * The second dword of a block contains the pointer to the first array, + * the third dword of a block contains the pointer to the second array. + * Note that if the total number of arrays is odd, the third dword of + * the last block is omitted. + */ +#define R300_PACKET3_3D_LOAD_VBPNTR 0x00002F00 +# define R300_VC_FORCE_PREFETCH (1 << 5) +# define R300_VBPNTR_SIZE0(x) ((x) >> 2) +# define R300_VBPNTR_STRIDE0(x) (((x) >> 2) << 8) +# define R300_VBPNTR_SIZE1(x) (((x) >> 2) << 16) +# define R300_VBPNTR_STRIDE1(x) (((x) >> 2) << 24) + +#define R300_PACKET3_3D_CLEAR_ZMASK 0x00003200 +#define R300_PACKET3_INDX_BUFFER 0x00003300 +# define R300_INDX_BUFFER_DST_SHIFT 0 +# define R300_INDX_BUFFER_SKIP_SHIFT 16 +# define R300_INDX_BUFFER_ONE_REG_WR (1<<31) + +/* Same as R300_PACKET3_3D_DRAW_VBUF but without VAP_VTX_FMT */ +#define R300_PACKET3_3D_DRAW_VBUF_2 0x00003400 +/* Same as R300_PACKET3_3D_DRAW_IMMD but without VAP_VTX_FMT */ +#define R300_PACKET3_3D_DRAW_IMMD_2 0x00003500 +/* Same as R300_PACKET3_3D_DRAW_INDX but without VAP_VTX_FMT */ +#define R300_PACKET3_3D_DRAW_INDX_2 0x00003600 + +/* Clears a portion of hierachical Z RAM + * 3 dword parameters + * 0. START + * 1. COUNT: 13:0 (max is 0x3FFF) + * 2. CLEAR_VALUE: Value to write into HIZ RAM. + */ +#define R300_PACKET3_3D_CLEAR_HIZ 0x00003700 + +/* Draws a set of primitives using vertex buffers pointed by the state data. + * At least 2 Parameters: + * 0. VAP_VF_CNTL: The first parameter is a standard primitive emission dword. + * 2 to end: Data or indices (see other 3D_DRAW_* packets for details) + */ +#define R300_PACKET3_3D_DRAW_128 0x00003900 + +/* END: Packet 3 commands */ + + +/* Color formats for 2d packets + */ +#define R300_CP_COLOR_FORMAT_CI8 2 +#define R300_CP_COLOR_FORMAT_ARGB1555 3 +#define R300_CP_COLOR_FORMAT_RGB565 4 +#define R300_CP_COLOR_FORMAT_ARGB8888 6 +#define R300_CP_COLOR_FORMAT_RGB332 7 +#define R300_CP_COLOR_FORMAT_RGB8 9 +#define R300_CP_COLOR_FORMAT_ARGB4444 15 + +/* + * CP type-3 packets + */ +#define R300_CP_CMD_BITBLT_MULTI 0xC0009B00 + +/* XXX Corbin's stuff from radeon and r200 */ + +#define RADEON_WAIT_UNTIL 0x1720 +# define RADEON_WAIT_CRTC_PFLIP (1 << 0) +# define RADEON_WAIT_2D_IDLECLEAN (1 << 16) +# define RADEON_WAIT_3D_IDLECLEAN (1 << 17) +# define RADEON_WAIT_HOST_IDLECLEAN (1 << 18) + +#define R200_3D_DRAW_IMMD_2 0xC0003500 + +#define RADEON_CP_PACKET0 0x0 /* XXX stolen from radeon_reg.h */ +#define RADEON_CP_PACKET3 0xC0000000 + +#define RADEON_ONE_REG_WR (1 << 15) + +#define CP_PACKET0(register, count) \ + (RADEON_CP_PACKET0 | ((count) << 16) | ((register) >> 2)) + +#define CP_PACKET3(op, count) \ + (RADEON_CP_PACKET3 | (op) | ((count) << 16)) + +#endif /* _R300_REG_H */ + +/* *INDENT-ON* */ + +/* vim: set foldenable foldmarker=\\{,\\} foldmethod=marker : */ diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c new file mode 100644 index 0000000..b4197e0 --- /dev/null +++ b/src/gallium/drivers/r300/r300_render.c @@ -0,0 +1,1224 @@ +/* + * Copyright 2009 Corbin Simpson + * Copyright 2010 Marek Olšák + * + * 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. */ + +/* r300_render: Vertex and index buffer primitive emission. Contains both + * HW TCL fastpath rendering, and SW TCL Draw-assisted rendering. */ + +#include "draw/draw_context.h" +#include "draw/draw_vbuf.h" + +#include "util/u_inlines.h" + +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_upload_mgr.h" +#include "util/u_prim.h" + +#include "r300_cs.h" +#include "r300_context.h" +#include "r300_screen_buffer.h" +#include "r300_emit.h" +#include "r300_reg.h" +#include "r300_state_derived.h" + +#include + +#define IMMD_DWORDS 32 + +static uint32_t r300_translate_primitive(unsigned prim) +{ + switch (prim) { + case PIPE_PRIM_POINTS: + return R300_VAP_VF_CNTL__PRIM_POINTS; + case PIPE_PRIM_LINES: + return R300_VAP_VF_CNTL__PRIM_LINES; + case PIPE_PRIM_LINE_LOOP: + return R300_VAP_VF_CNTL__PRIM_LINE_LOOP; + case PIPE_PRIM_LINE_STRIP: + return R300_VAP_VF_CNTL__PRIM_LINE_STRIP; + case PIPE_PRIM_TRIANGLES: + return R300_VAP_VF_CNTL__PRIM_TRIANGLES; + case PIPE_PRIM_TRIANGLE_STRIP: + return R300_VAP_VF_CNTL__PRIM_TRIANGLE_STRIP; + case PIPE_PRIM_TRIANGLE_FAN: + return R300_VAP_VF_CNTL__PRIM_TRIANGLE_FAN; + case PIPE_PRIM_QUADS: + return R300_VAP_VF_CNTL__PRIM_QUADS; + case PIPE_PRIM_QUAD_STRIP: + return R300_VAP_VF_CNTL__PRIM_QUAD_STRIP; + case PIPE_PRIM_POLYGON: + return R300_VAP_VF_CNTL__PRIM_POLYGON; + default: + return 0; + } +} + +static uint32_t r300_provoking_vertex_fixes(struct r300_context *r300, + unsigned mode) +{ + struct r300_rs_state* rs = (struct r300_rs_state*)r300->rs_state.state; + uint32_t color_control = rs->color_control; + + /* By default (see r300_state.c:r300_create_rs_state) color_control is + * initialized to provoking the first vertex. + * + * Triangle fans must be reduced to the second vertex, not the first, in + * Gallium flatshade-first mode, as per the GL spec. + * (http://www.opengl.org/registry/specs/ARB/provoking_vertex.txt) + * + * Quads never provoke correctly in flatshade-first mode. The first + * vertex is never considered as provoking, so only the second, third, + * and fourth vertices can be selected, and both "third" and "last" modes + * select the fourth vertex. This is probably due to D3D lacking quads. + * + * Similarly, polygons reduce to the first, not the last, vertex, when in + * "last" mode, and all other modes start from the second vertex. + * + * ~ C. + */ + + if (rs->rs.flatshade_first) { + switch (mode) { + case PIPE_PRIM_TRIANGLE_FAN: + color_control |= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_SECOND; + break; + case PIPE_PRIM_QUADS: + case PIPE_PRIM_QUAD_STRIP: + case PIPE_PRIM_POLYGON: + color_control |= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_LAST; + break; + default: + color_control |= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_FIRST; + break; + } + } else { + color_control |= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_LAST; + } + + return color_control; +} + +void r500_emit_index_bias(struct r300_context *r300, int index_bias) +{ + CS_LOCALS(r300); + + BEGIN_CS(2); + OUT_CS_REG(R500_VAP_INDEX_OFFSET, + (index_bias & 0xFFFFFF) | (index_bias < 0 ? 1<<24 : 0)); + END_CS; +} + +/* This function splits the index bias value into two parts: + * - buffer_offset: the value that can be safely added to buffer offsets + * in r300_emit_aos (it must yield a positive offset when added to + * a vertex buffer offset) + * - index_offset: the value that must be manually subtracted from indices + * in an index buffer to achieve negative offsets. */ +static void r300_split_index_bias(struct r300_context *r300, int index_bias, + int *buffer_offset, int *index_offset) +{ + struct pipe_vertex_buffer *vb, *vbufs = r300->vertex_buffer; + struct pipe_vertex_element *velem = r300->velems->velem; + unsigned i, size; + int max_neg_bias; + + if (index_bias < 0) { + /* See how large index bias we may subtract. We must be careful + * here because negative buffer offsets are not allowed + * by the DRM API. */ + max_neg_bias = INT_MAX; + for (i = 0; i < r300->velems->count; i++) { + vb = &vbufs[velem[i].vertex_buffer_index]; + size = (vb->buffer_offset + velem[i].src_offset) / vb->stride; + max_neg_bias = MIN2(max_neg_bias, size); + } + + /* Now set the minimum allowed value. */ + *buffer_offset = MAX2(-max_neg_bias, index_bias); + } else { + /* A positive index bias is OK. */ + *buffer_offset = index_bias; + } + + *index_offset = index_bias - *buffer_offset; +} + +enum r300_prepare_flags { + PREP_FIRST_DRAW = (1 << 0), /* call emit_dirty_state and friends? */ + PREP_VALIDATE_VBOS = (1 << 1), /* validate VBOs? */ + PREP_EMIT_AOS = (1 << 2), /* call emit_aos? */ + PREP_EMIT_AOS_SWTCL = (1 << 3), /* call emit_aos_swtcl? */ + PREP_INDEXED = (1 << 4) /* is this draw_elements? */ +}; + +/** + * Check if the requested number of dwords is available in the CS and + * if not, flush. + * \param r300 The context. + * \param flags See r300_prepare_flags. + * \param cs_dwords The number of dwords to reserve in CS. + * \return TRUE if the CS was flushed + */ +static boolean r300_reserve_cs_dwords(struct r300_context *r300, + enum r300_prepare_flags flags, + unsigned cs_dwords) +{ + boolean flushed = FALSE; + boolean first_draw = flags & PREP_FIRST_DRAW; + boolean emit_aos = flags & PREP_EMIT_AOS; + boolean emit_aos_swtcl = flags & PREP_EMIT_AOS_SWTCL; + + /* Add dirty state, index offset, and AOS. */ + if (first_draw) { + cs_dwords += r300_get_num_dirty_dwords(r300); + + if (r300->screen->caps.index_bias_supported) + cs_dwords += 2; /* emit_index_offset */ + + if (emit_aos) + cs_dwords += 55; /* emit_aos */ + + if (emit_aos_swtcl) + cs_dwords += 7; /* emit_aos_swtcl */ + } + + cs_dwords += r300_get_num_cs_end_dwords(r300); + + /* Reserve requested CS space. */ + if (cs_dwords > (R300_MAX_CMDBUF_DWORDS - r300->cs->cdw)) { + r300->context.flush(&r300->context, 0, NULL); + flushed = TRUE; + } + + return flushed; +} + +/** + * Validate buffers and emit dirty state. + * \param r300 The context. + * \param flags See r300_prepare_flags. + * \param index_buffer The index buffer to validate. The parameter may be NULL. + * \param aos_offset The offset passed to emit_aos. + * \param index_bias The index bias to emit. + * \return TRUE if rendering should be skipped + */ +static boolean r300_emit_states(struct r300_context *r300, + enum r300_prepare_flags flags, + struct pipe_resource *index_buffer, + int aos_offset, + int index_bias) +{ + boolean first_draw = flags & PREP_FIRST_DRAW; + boolean emit_aos = flags & PREP_EMIT_AOS; + boolean emit_aos_swtcl = flags & PREP_EMIT_AOS_SWTCL; + boolean indexed = flags & PREP_INDEXED; + boolean validate_vbos = flags & PREP_VALIDATE_VBOS; + + /* Validate buffers and emit dirty state if needed. */ + if (first_draw) { + /* upload buffers first */ + if (r300->screen->caps.has_tcl && r300->any_user_vbs) { + r300_upload_user_buffers(r300); + r300->any_user_vbs = false; + } + + if (r300->validate_buffers) { + if (!r300_emit_buffer_validate(r300, validate_vbos, + index_buffer)) { + fprintf(stderr, "r300: CS space validation failed. " + "(not enough memory?) Skipping rendering.\n"); + return FALSE; + } + + /* Consider the validation done only if everything was validated. */ + if (validate_vbos) { + r300->validate_buffers = FALSE; + } + } + + r300_emit_dirty_state(r300); + if (r300->screen->caps.index_bias_supported) { + if (r300->screen->caps.has_tcl) + r500_emit_index_bias(r300, index_bias); + else + r500_emit_index_bias(r300, 0); + } + + if (emit_aos) + r300_emit_aos(r300, aos_offset, indexed); + + if (emit_aos_swtcl) + r300_emit_aos_swtcl(r300, indexed); + } + + return TRUE; +} + +/** + * Check if the requested number of dwords is available in the CS and + * if not, flush. Then validate buffers and emit dirty state. + * \param r300 The context. + * \param flags See r300_prepare_flags. + * \param index_buffer The index buffer to validate. The parameter may be NULL. + * \param cs_dwords The number of dwords to reserve in CS. + * \param aos_offset The offset passed to emit_aos. + * \param index_bias The index bias to emit. + * \return TRUE if rendering should be skipped + */ +static boolean r300_prepare_for_rendering(struct r300_context *r300, + enum r300_prepare_flags flags, + struct pipe_resource *index_buffer, + unsigned cs_dwords, + int aos_offset, + int index_bias) +{ + if (r300_reserve_cs_dwords(r300, flags, cs_dwords)) + flags |= PREP_FIRST_DRAW; + + return r300_emit_states(r300, flags, index_buffer, aos_offset, index_bias); +} + +static boolean immd_is_good_idea(struct r300_context *r300, + unsigned count) +{ + struct pipe_vertex_element* velem; + struct pipe_vertex_buffer* vbuf; + boolean checked[PIPE_MAX_ATTRIBS] = {0}; + unsigned vertex_element_count = r300->velems->count; + unsigned i, vbi; + + if (DBG_ON(r300, DBG_NO_IMMD)) { + return FALSE; + } + + if (r300->draw) { + return FALSE; + } + + if (count * r300->velems->vertex_size_dwords > IMMD_DWORDS) { + return FALSE; + } + + /* We shouldn't map buffers referenced by CS, busy buffers, + * and ones placed in VRAM. */ + for (i = 0; i < vertex_element_count; i++) { + velem = &r300->velems->velem[i]; + vbi = velem->vertex_buffer_index; + + if (!checked[vbi]) { + vbuf = &r300->vertex_buffer[vbi]; + + if (!(r300_buffer(vbuf->buffer)->domain & R300_DOMAIN_GTT)) { + return FALSE; + } + + if (r300_buffer_is_referenced(&r300->context, + vbuf->buffer, + R300_REF_CS | R300_REF_HW)) { + /* It's a very bad idea to map it... */ + return FALSE; + } + checked[vbi] = TRUE; + } + } + return TRUE; +} + +/***************************************************************************** + * The HWTCL draw functions. * + ****************************************************************************/ + +static void r300_emit_draw_arrays_immediate(struct r300_context *r300, + unsigned mode, + unsigned start, + unsigned count) +{ + struct pipe_vertex_element* velem; + struct pipe_vertex_buffer* vbuf; + unsigned vertex_element_count = r300->velems->count; + unsigned i, v, vbi; + + /* Size of the vertex, in dwords. */ + unsigned vertex_size = r300->velems->vertex_size_dwords; + + /* The number of dwords for this draw operation. */ + unsigned dwords = 9 + count * vertex_size; + + /* Size of the vertex element, in dwords. */ + unsigned size[PIPE_MAX_ATTRIBS]; + + /* Stride to the same attrib in the next vertex in the vertex buffer, + * in dwords. */ + unsigned stride[PIPE_MAX_ATTRIBS]; + + /* Mapped vertex buffers. */ + uint32_t* map[PIPE_MAX_ATTRIBS]; + uint32_t* mapelem[PIPE_MAX_ATTRIBS]; + struct pipe_transfer* transfer[PIPE_MAX_ATTRIBS] = {0}; + + CS_LOCALS(r300); + + if (!r300_prepare_for_rendering(r300, PREP_FIRST_DRAW, NULL, dwords, 0, 0)) + return; + + /* Calculate the vertex size, offsets, strides etc. and map the buffers. */ + for (i = 0; i < vertex_element_count; i++) { + velem = &r300->velems->velem[i]; + size[i] = r300->velems->hw_format_size[i] / 4; + vbi = velem->vertex_buffer_index; + vbuf = &r300->vertex_buffer[vbi]; + stride[i] = vbuf->stride / 4; + + /* Map the buffer. */ + if (!transfer[vbi]) { + map[vbi] = (uint32_t*)pipe_buffer_map(&r300->context, + vbuf->buffer, + PIPE_TRANSFER_READ, + &transfer[vbi]); + map[vbi] += (vbuf->buffer_offset / 4) + stride[i] * start; + } + mapelem[i] = map[vbi] + (velem->src_offset / 4); + } + + BEGIN_CS(dwords); + OUT_CS_REG(R300_GA_COLOR_CONTROL, + r300_provoking_vertex_fixes(r300, mode)); + OUT_CS_REG(R300_VAP_VTX_SIZE, vertex_size); + OUT_CS_REG_SEQ(R300_VAP_VF_MAX_VTX_INDX, 2); + OUT_CS(count - 1); + OUT_CS(0); + OUT_CS_PKT3(R300_PACKET3_3D_DRAW_IMMD_2, count * vertex_size); + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_EMBEDDED | (count << 16) | + r300_translate_primitive(mode)); + + /* Emit vertices. */ + for (v = 0; v < count; v++) { + for (i = 0; i < vertex_element_count; i++) { + OUT_CS_TABLE(&mapelem[i][stride[i] * v], size[i]); + } + } + END_CS; + + /* Unmap buffers. */ + for (i = 0; i < vertex_element_count; i++) { + vbi = r300->velems->velem[i].vertex_buffer_index; + + if (transfer[vbi]) { + vbuf = &r300->vertex_buffer[vbi]; + pipe_buffer_unmap(&r300->context, vbuf->buffer, transfer[vbi]); + transfer[vbi] = NULL; + } + } +} + +static void r300_emit_draw_arrays(struct r300_context *r300, + unsigned mode, + unsigned count) +{ + boolean alt_num_verts = count > 65535; + CS_LOCALS(r300); + + if (count >= (1 << 24)) { + fprintf(stderr, "r300: Got a huge number of vertices: %i, " + "refusing to render.\n", count); + return; + } + + BEGIN_CS(7 + (alt_num_verts ? 2 : 0)); + if (alt_num_verts) { + OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES, count); + } + OUT_CS_REG(R300_GA_COLOR_CONTROL, + r300_provoking_vertex_fixes(r300, mode)); + OUT_CS_REG_SEQ(R300_VAP_VF_MAX_VTX_INDX, 2); + OUT_CS(count - 1); + OUT_CS(0); + OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0); + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) | + r300_translate_primitive(mode) | + (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0)); + END_CS; +} + +static void r300_emit_draw_elements(struct r300_context *r300, + struct pipe_resource* indexBuffer, + unsigned indexSize, + unsigned minIndex, + unsigned maxIndex, + unsigned mode, + unsigned start, + unsigned count) +{ + uint32_t count_dwords; + uint32_t offset_dwords = indexSize * start / sizeof(uint32_t); + boolean alt_num_verts = count > 65535; + CS_LOCALS(r300); + + if (count >= (1 << 24)) { + fprintf(stderr, "r300: Got a huge number of vertices: %i, " + "refusing to render.\n", count); + return; + } + + maxIndex = MIN2(maxIndex, r300->vertex_buffer_max_index); + + DBG(r300, DBG_DRAW, "r300: Indexbuf of %u indices, min %u max %u\n", + count, minIndex, maxIndex); + + BEGIN_CS(13 + (alt_num_verts ? 2 : 0)); + if (alt_num_verts) { + OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES, count); + } + OUT_CS_REG(R300_GA_COLOR_CONTROL, + r300_provoking_vertex_fixes(r300, mode)); + OUT_CS_REG_SEQ(R300_VAP_VF_MAX_VTX_INDX, 2); + OUT_CS(maxIndex); + OUT_CS(minIndex); + OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, 0); + if (indexSize == 4) { + count_dwords = count; + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | + R300_VAP_VF_CNTL__INDEX_SIZE_32bit | + r300_translate_primitive(mode) | + (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0)); + } else { + count_dwords = (count + 1) / 2; + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | + r300_translate_primitive(mode) | + (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0)); + } + + /* INDX_BUFFER is a truly special packet3. + * Unlike most other packet3, where the offset is after the count, + * the order is reversed, so the relocation ends up carrying the + * size of the indexbuf instead of the offset. + */ + OUT_CS_PKT3(R300_PACKET3_INDX_BUFFER, 2); + OUT_CS(R300_INDX_BUFFER_ONE_REG_WR | (R300_VAP_PORT_IDX0 >> 2) | + (0 << R300_INDX_BUFFER_SKIP_SHIFT)); + OUT_CS(offset_dwords << 2); + OUT_CS_BUF_RELOC(indexBuffer, count_dwords, + r300_buffer(indexBuffer)->domain, 0); + + END_CS; +} + +/* This is the fast-path drawing & emission for HW TCL. */ +static void r300_draw_range_elements(struct pipe_context* pipe, + struct pipe_resource* indexBuffer, + unsigned indexSize, + int indexBias, + unsigned minIndex, + unsigned maxIndex, + unsigned mode, + unsigned start, + unsigned count) +{ + struct r300_context* r300 = r300_context(pipe); + struct pipe_resource* orgIndexBuffer = indexBuffer; + boolean alt_num_verts = r300->screen->caps.is_r500 && + count > 65536 && + r300->rws->get_value(r300->rws, R300_VID_DRM_2_3_0); + unsigned short_count; + int buffer_offset = 0, index_offset = 0; /* for index bias emulation */ + unsigned new_offset; + + if (indexBias && !r300->screen->caps.index_bias_supported) { + r300_split_index_bias(r300, indexBias, &buffer_offset, &index_offset); + } + + r300_translate_index_buffer(r300, &indexBuffer, &indexSize, index_offset, + &start, count); + + r300_update_derived_state(r300); + r300_upload_index_buffer(r300, &indexBuffer, indexSize, start, count, &new_offset); + + start = new_offset; + + /* 15 dwords for emit_draw_elements. Give up if the function fails. */ + if (!r300_prepare_for_rendering(r300, + PREP_FIRST_DRAW | PREP_VALIDATE_VBOS | PREP_EMIT_AOS | + PREP_INDEXED, indexBuffer, 15, buffer_offset, indexBias)) + goto done; + + if (alt_num_verts || count <= 65535) { + r300_emit_draw_elements(r300, indexBuffer, indexSize, + minIndex, maxIndex, mode, start, count); + } else { + do { + short_count = MIN2(count, 65534); + r300_emit_draw_elements(r300, indexBuffer, indexSize, + minIndex, maxIndex, + mode, start, short_count); + + start += short_count; + count -= short_count; + + /* 15 dwords for emit_draw_elements */ + if (count) { + if (!r300_prepare_for_rendering(r300, + PREP_VALIDATE_VBOS | PREP_EMIT_AOS | PREP_INDEXED, + indexBuffer, 15, buffer_offset, indexBias)) + goto done; + } + } while (count); + } + +done: + if (indexBuffer != orgIndexBuffer) { + pipe_resource_reference( &indexBuffer, NULL ); + } +} + +static void r300_draw_arrays(struct pipe_context* pipe, unsigned mode, + unsigned start, unsigned count) +{ + struct r300_context* r300 = r300_context(pipe); + boolean alt_num_verts = r300->screen->caps.is_r500 && + count > 65536 && + r300->rws->get_value(r300->rws, R300_VID_DRM_2_3_0); + unsigned short_count; + + r300_update_derived_state(r300); + + if (immd_is_good_idea(r300, count)) { + r300_emit_draw_arrays_immediate(r300, mode, start, count); + } else { + /* 9 spare dwords for emit_draw_arrays. Give up if the function fails. */ + if (!r300_prepare_for_rendering(r300, + PREP_FIRST_DRAW | PREP_VALIDATE_VBOS | PREP_EMIT_AOS, + NULL, 9, start, 0)) + return; + + if (alt_num_verts || count <= 65535) { + r300_emit_draw_arrays(r300, mode, count); + } else { + do { + short_count = MIN2(count, 65535); + r300_emit_draw_arrays(r300, mode, short_count); + + start += short_count; + count -= short_count; + + /* 9 spare dwords for emit_draw_arrays. Give up if the function fails. */ + if (count) { + if (!r300_prepare_for_rendering(r300, + PREP_VALIDATE_VBOS | PREP_EMIT_AOS, NULL, 9, + start, 0)) + return; + } + } while (count); + } + } +} + +static void r300_draw_vbo(struct pipe_context* pipe, + const struct pipe_draw_info *info) +{ + struct r300_context* r300 = r300_context(pipe); + unsigned count = info->count; + boolean translate = FALSE; + boolean indexed = info->indexed && r300->index_buffer.buffer; + unsigned start_indexed = 0; + + if (r300->skip_rendering) { + return; + } + + if (!u_trim_pipe_prim(info->mode, &count)) { + return; + } + + /* Index buffer range checking. */ + if (indexed) { + assert(r300->index_buffer.offset % r300->index_buffer.index_size == 0); + + /* Compute start for draw_elements, taking the offset into account. */ + start_indexed = + info->start + + (r300->index_buffer.offset / r300->index_buffer.index_size); + + if ((start_indexed + count) * r300->index_buffer.index_size > + r300->index_buffer.buffer->width0) { + fprintf(stderr, "r300: Invalid index buffer range. Skipping rendering.\n"); + return; + } + } + + /* Set up fallback for incompatible vertex layout if needed. */ + if (r300->incompatible_vb_layout || r300->velems->incompatible_layout) { + r300_begin_vertex_translate(r300); + translate = TRUE; + } + + if (indexed) { + r300_draw_range_elements(pipe, + r300->index_buffer.buffer, + r300->index_buffer.index_size, + info->index_bias, + info->min_index, + info->max_index, + info->mode, + start_indexed, + count); + } else { + r300_draw_arrays(pipe, + info->mode, + info->start, + count); + } + + if (translate) { + r300_end_vertex_translate(r300); + } +} + +/**************************************************************************** + * The rest of this file is for SW TCL rendering only. Please be polite and * + * keep these functions separated so that they are easier to locate. ~C. * + ***************************************************************************/ + +/* SW TCL elements, using Draw. */ +static void r300_swtcl_draw_vbo(struct pipe_context* pipe, + const struct pipe_draw_info *info) +{ + struct r300_context* r300 = r300_context(pipe); + struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS]; + struct pipe_transfer *ib_transfer = NULL; + unsigned count = info->count; + int i; + void *indices = NULL; + boolean indexed = info->indexed && r300->index_buffer.buffer; + + if (r300->skip_rendering) { + return; + } + + if (!u_trim_pipe_prim(info->mode, &count)) { + return; + } + + r300_update_derived_state(r300); + + r300_reserve_cs_dwords(r300, + PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL | + (indexed ? PREP_INDEXED : 0), + indexed ? 256 : 6); + + for (i = 0; i < r300->vertex_buffer_count; i++) { + if (r300->vertex_buffer[i].buffer) { + void *buf = pipe_buffer_map(pipe, + r300->vertex_buffer[i].buffer, + PIPE_TRANSFER_READ, + &vb_transfer[i]); + draw_set_mapped_vertex_buffer(r300->draw, i, buf); + } + } + + if (indexed) { + indices = pipe_buffer_map(pipe, r300->index_buffer.buffer, + PIPE_TRANSFER_READ, &ib_transfer); + } + + draw_set_mapped_index_buffer(r300->draw, indices); + + r300->draw_vbo_locked = TRUE; + r300->draw_first_emitted = FALSE; + draw_vbo(r300->draw, info); + draw_flush(r300->draw); + r300->draw_vbo_locked = FALSE; + + for (i = 0; i < r300->vertex_buffer_count; i++) { + if (r300->vertex_buffer[i].buffer) { + pipe_buffer_unmap(pipe, r300->vertex_buffer[i].buffer, + vb_transfer[i]); + draw_set_mapped_vertex_buffer(r300->draw, i, NULL); + } + } + + if (indexed) { + pipe_buffer_unmap(pipe, r300->index_buffer.buffer, ib_transfer); + draw_set_mapped_index_buffer(r300->draw, NULL); + } +} + +/* Object for rendering using Draw. */ +struct r300_render { + /* Parent class */ + struct vbuf_render base; + + /* Pipe context */ + struct r300_context* r300; + + /* Vertex information */ + size_t vertex_size; + unsigned prim; + unsigned hwprim; + + /* VBO */ + size_t vbo_max_used; + void * vbo_ptr; + + struct pipe_transfer *vbo_transfer; +}; + +static INLINE struct r300_render* +r300_render(struct vbuf_render* render) +{ + return (struct r300_render*)render; +} + +static const struct vertex_info* +r300_render_get_vertex_info(struct vbuf_render* render) +{ + struct r300_render* r300render = r300_render(render); + struct r300_context* r300 = r300render->r300; + + return &r300->vertex_info; +} + +static boolean r300_render_allocate_vertices(struct vbuf_render* render, + ushort vertex_size, + ushort count) +{ + struct r300_render* r300render = r300_render(render); + struct r300_context* r300 = r300render->r300; + struct pipe_screen* screen = r300->context.screen; + size_t size = (size_t)vertex_size * (size_t)count; + + DBG(r300, DBG_DRAW, "r300: render_allocate_vertices (size: %d)\n", size); + + if (size + r300->draw_vbo_offset > r300->draw_vbo_size) + { + pipe_resource_reference(&r300->vbo, NULL); + r300->vbo = pipe_buffer_create(screen, + PIPE_BIND_VERTEX_BUFFER, + R300_MAX_DRAW_VBO_SIZE); + r300->draw_vbo_offset = 0; + r300->draw_vbo_size = R300_MAX_DRAW_VBO_SIZE; + r300->validate_buffers = TRUE; + } + + r300render->vertex_size = vertex_size; + + return (r300->vbo) ? TRUE : FALSE; +} + +static void* r300_render_map_vertices(struct vbuf_render* render) +{ + struct r300_render* r300render = r300_render(render); + struct r300_context* r300 = r300render->r300; + + assert(!r300render->vbo_transfer); + + DBG(r300, DBG_DRAW, "r300: render_map_vertices\n"); + + r300render->vbo_ptr = pipe_buffer_map(&r300render->r300->context, + r300->vbo, + PIPE_TRANSFER_WRITE, + &r300render->vbo_transfer); + + assert(r300render->vbo_ptr); + + return ((uint8_t*)r300render->vbo_ptr + r300->draw_vbo_offset); +} + +static void r300_render_unmap_vertices(struct vbuf_render* render, + ushort min, + ushort max) +{ + struct r300_render* r300render = r300_render(render); + struct pipe_context* context = &r300render->r300->context; + struct r300_context* r300 = r300render->r300; + + assert(r300render->vbo_transfer); + + DBG(r300, DBG_DRAW, "r300: render_unmap_vertices\n"); + + r300render->vbo_max_used = MAX2(r300render->vbo_max_used, + r300render->vertex_size * (max + 1)); + pipe_buffer_unmap(context, r300->vbo, r300render->vbo_transfer); + + r300render->vbo_transfer = NULL; +} + +static void r300_render_release_vertices(struct vbuf_render* render) +{ + struct r300_render* r300render = r300_render(render); + struct r300_context* r300 = r300render->r300; + + DBG(r300, DBG_DRAW, "r300: render_release_vertices\n"); + + r300->draw_vbo_offset += r300render->vbo_max_used; + r300render->vbo_max_used = 0; +} + +static boolean r300_render_set_primitive(struct vbuf_render* render, + unsigned prim) +{ + struct r300_render* r300render = r300_render(render); + + r300render->prim = prim; + r300render->hwprim = r300_translate_primitive(prim); + + return TRUE; +} + +static void r300_render_draw_arrays(struct vbuf_render* render, + unsigned start, + unsigned count) +{ + struct r300_render* r300render = r300_render(render); + struct r300_context* r300 = r300render->r300; + uint8_t* ptr; + unsigned i; + unsigned dwords = 6; + + CS_LOCALS(r300); + (void) i; (void) ptr; + + DBG(r300, DBG_DRAW, "r300: render_draw_arrays (count: %d)\n", count); + + if (r300->draw_first_emitted) { + if (!r300_prepare_for_rendering(r300, + PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL, + NULL, 6, 0, 0)) + return; + } else { + if (!r300_emit_states(r300, + PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL, + NULL, 0, 0)) + return; + } + + /* Uncomment to dump all VBOs rendered through this interface. + * Slow and noisy! + ptr = pipe_buffer_map(&r300render->r300->context, + r300render->vbo, PIPE_TRANSFER_READ, + &r300render->vbo_transfer); + + for (i = 0; i < count; i++) { + printf("r300: Vertex %d\n", i); + draw_dump_emitted_vertex(&r300->vertex_info, ptr); + ptr += r300->vertex_info.size * 4; + printf("\n"); + } + + pipe_buffer_unmap(&r300render->r300->context, r300render->vbo, + r300render->vbo_transfer); + */ + + BEGIN_CS(dwords); + OUT_CS_REG(R300_GA_COLOR_CONTROL, + r300_provoking_vertex_fixes(r300, r300render->prim)); + OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, count - 1); + OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0); + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) | + r300render->hwprim); + END_CS; + + r300->draw_first_emitted = TRUE; +} + +static void r300_render_draw_elements(struct vbuf_render* render, + const ushort* indices, + uint count) +{ + struct r300_render* r300render = r300_render(render); + struct r300_context* r300 = r300render->r300; + int i; + unsigned end_cs_dwords; + unsigned max_index = (r300->draw_vbo_size - r300->draw_vbo_offset) / + (r300render->r300->vertex_info.size * 4) - 1; + unsigned short_count; + unsigned free_dwords; + + CS_LOCALS(r300); + DBG(r300, DBG_DRAW, "r300: render_draw_elements (count: %d)\n", count); + + if (r300->draw_first_emitted) { + if (!r300_prepare_for_rendering(r300, + PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL | PREP_INDEXED, + NULL, 256, 0, 0)) + return; + } else { + if (!r300_emit_states(r300, + PREP_FIRST_DRAW | PREP_EMIT_AOS_SWTCL | PREP_INDEXED, + NULL, 0, 0)) + return; + } + + /* Below we manage the CS space manually because there may be more + * indices than it can fit in CS. */ + + end_cs_dwords = r300_get_num_cs_end_dwords(r300); + + while (count) { + free_dwords = R300_MAX_CMDBUF_DWORDS - r300->cs->cdw; + + short_count = MIN2(count, (free_dwords - end_cs_dwords - 6) * 2); + + BEGIN_CS(6 + (short_count+1)/2); + OUT_CS_REG(R300_GA_COLOR_CONTROL, + r300_provoking_vertex_fixes(r300, r300render->prim)); + OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, max_index); + OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, (short_count+1)/2); + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (short_count << 16) | + r300render->hwprim); + for (i = 0; i < short_count-1; i += 2) { + OUT_CS(indices[i+1] << 16 | indices[i]); + } + if (short_count % 2) { + OUT_CS(indices[short_count-1]); + } + END_CS; + + /* OK now subtract the emitted indices and see if we need to emit + * another draw packet. */ + indices += short_count; + count -= short_count; + + if (count) { + if (!r300_prepare_for_rendering(r300, + PREP_EMIT_AOS_SWTCL | PREP_INDEXED, + NULL, 256, 0, 0)) + return; + + end_cs_dwords = r300_get_num_cs_end_dwords(r300); + } + } + + r300->draw_first_emitted = TRUE; +} + +static void r300_render_destroy(struct vbuf_render* render) +{ + FREE(render); +} + +static struct vbuf_render* r300_render_create(struct r300_context* r300) +{ + struct r300_render* r300render = CALLOC_STRUCT(r300_render); + + r300render->r300 = r300; + + /* XXX find real numbers plz */ + r300render->base.max_vertex_buffer_bytes = 128 * 1024; + r300render->base.max_indices = 16 * 1024; + + r300render->base.get_vertex_info = r300_render_get_vertex_info; + r300render->base.allocate_vertices = r300_render_allocate_vertices; + r300render->base.map_vertices = r300_render_map_vertices; + r300render->base.unmap_vertices = r300_render_unmap_vertices; + r300render->base.set_primitive = r300_render_set_primitive; + r300render->base.draw_elements = r300_render_draw_elements; + r300render->base.draw_arrays = r300_render_draw_arrays; + r300render->base.release_vertices = r300_render_release_vertices; + r300render->base.destroy = r300_render_destroy; + + return &r300render->base; +} + +struct draw_stage* r300_draw_stage(struct r300_context* r300) +{ + struct vbuf_render* render; + struct draw_stage* stage; + + render = r300_render_create(r300); + + if (!render) { + return NULL; + } + + stage = draw_vbuf_stage(r300->draw, render); + + if (!stage) { + render->destroy(render); + return NULL; + } + + draw_set_render(r300->draw, render); + + return stage; +} + +void r300_draw_flush_vbuf(struct r300_context *r300) +{ + pipe_resource_reference(&r300->vbo, NULL); + r300->draw_vbo_size = 0; +} + +/**************************************************************************** + * End of SW TCL functions * + ***************************************************************************/ + +/* This functions is used to draw a rectangle for the blitter module. + * + * If we rendered a quad, the pixels on the main diagonal + * would be computed and stored twice, which makes the clear/copy codepaths + * somewhat inefficient. Instead we use a rectangular point sprite. */ +static void r300_blitter_draw_rectangle(struct blitter_context *blitter, + unsigned x1, unsigned y1, + unsigned x2, unsigned y2, + float depth, + enum blitter_attrib_type type, + const float attrib[4]) +{ + struct r300_context *r300 = r300_context(util_blitter_get_pipe(blitter)); + unsigned last_sprite_coord_enable = r300->sprite_coord_enable; + unsigned width = x2 - x1; + unsigned height = y2 - y1; + unsigned vertex_size = + type == UTIL_BLITTER_ATTRIB_COLOR || !r300->draw ? 8 : 4; + unsigned dwords = 13 + vertex_size + + (type == UTIL_BLITTER_ATTRIB_TEXCOORD ? 7 : 0); + const float zeros[4] = {0, 0, 0, 0}; + CS_LOCALS(r300); + + r300->context.set_vertex_buffers(&r300->context, 0, NULL); + + if (type == UTIL_BLITTER_ATTRIB_TEXCOORD) + r300->sprite_coord_enable = 1; + + r300_update_derived_state(r300); + + /* Mark some states we don't care about as non-dirty. */ + r300->clip_state.dirty = FALSE; + r300->viewport_state.dirty = FALSE; + + if (!r300_prepare_for_rendering(r300, PREP_FIRST_DRAW, NULL, dwords, 0, 0)) + goto done; + + DBG(r300, DBG_DRAW, "r300: draw_rectangle\n"); + + BEGIN_CS(dwords); + /* Set up GA. */ + OUT_CS_REG(R300_GA_POINT_SIZE, (height * 6) | ((width * 6) << 16)); + + if (type == UTIL_BLITTER_ATTRIB_TEXCOORD) { + /* Set up the GA to generate texcoords. */ + OUT_CS_REG(R300_GB_ENABLE, R300_GB_POINT_STUFF_ENABLE | + (R300_GB_TEX_STR << R300_GB_TEX0_SOURCE_SHIFT)); + OUT_CS_REG_SEQ(R300_GA_POINT_S0, 4); + OUT_CS_32F(attrib[0]); + OUT_CS_32F(attrib[3]); + OUT_CS_32F(attrib[2]); + OUT_CS_32F(attrib[1]); + } + + /* Set up VAP controls. */ + OUT_CS_REG(R300_VAP_CLIP_CNTL, R300_CLIP_DISABLE); + OUT_CS_REG(R300_VAP_VTE_CNTL, R300_VTX_XY_FMT | R300_VTX_Z_FMT); + OUT_CS_REG(R300_VAP_VTX_SIZE, vertex_size); + OUT_CS_REG_SEQ(R300_VAP_VF_MAX_VTX_INDX, 2); + OUT_CS(1); + OUT_CS(0); + + /* Draw. */ + OUT_CS_PKT3(R300_PACKET3_3D_DRAW_IMMD_2, vertex_size); + OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_EMBEDDED | (1 << 16) | + R300_VAP_VF_CNTL__PRIM_POINTS); + + OUT_CS_32F(x1 + width * 0.5f); + OUT_CS_32F(y1 + height * 0.5f); + OUT_CS_32F(depth); + OUT_CS_32F(1); + + if (vertex_size == 8) { + if (!attrib) + attrib = zeros; + OUT_CS_TABLE(attrib, 4); + } + END_CS; + +done: + /* Restore the state. */ + r300_mark_atom_dirty(r300, &r300->clip_state); + r300_mark_atom_dirty(r300, &r300->rs_state); + r300_mark_atom_dirty(r300, &r300->viewport_state); + + r300->sprite_coord_enable = last_sprite_coord_enable; +} + +static void r300_resource_resolve(struct pipe_context* pipe, + struct pipe_resource* dest, + unsigned dst_layer, + struct pipe_resource* src, + unsigned src_layer) +{ + struct r300_context* r300 = r300_context(pipe); + struct pipe_surface* srcsurf, surf_tmpl; + struct r300_aa_state *aa = (struct r300_aa_state*)r300->aa_state.state; + float color[] = {0, 0, 0, 0}; + + memset(&surf_tmpl, 0, sizeof(surf_tmpl)); + surf_tmpl.format = src->format; + surf_tmpl.usage = 0; /* not really a surface hence no bind flags */ + surf_tmpl.u.tex.level = 0; /* msaa resources cannot have mipmaps */ + surf_tmpl.u.tex.first_layer = src_layer; + surf_tmpl.u.tex.last_layer = src_layer; + srcsurf = pipe->create_surface(pipe, src, &surf_tmpl); + surf_tmpl.format = dest->format; + surf_tmpl.u.tex.first_layer = dst_layer; + surf_tmpl.u.tex.last_layer = dst_layer; + + DBG(r300, DBG_DRAW, "r300: Resolving resource...\n"); + + /* Enable AA resolve. */ + aa->dest = r300_surface(pipe->create_surface(pipe, dest, &surf_tmpl)); + + aa->aaresolve_ctl = + R300_RB3D_AARESOLVE_CTL_AARESOLVE_MODE_RESOLVE | + R300_RB3D_AARESOLVE_CTL_AARESOLVE_ALPHA_AVERAGE; + r300->aa_state.size = 12; + r300_mark_atom_dirty(r300, &r300->aa_state); + + /* Resolve the surface. */ + r300->context.clear_render_target(pipe, + srcsurf, color, 0, 0, src->width0, src->height0); + + /* Disable AA resolve. */ + aa->aaresolve_ctl = 0; + r300->aa_state.size = 4; + r300_mark_atom_dirty(r300, &r300->aa_state); + + pipe_surface_reference((struct pipe_surface**)&srcsurf, NULL); + pipe_surface_reference((struct pipe_surface**)&aa->dest, NULL); +} + +void r300_init_render_functions(struct r300_context *r300) +{ + /* Set draw functions based on presence of HW TCL. */ + if (r300->screen->caps.has_tcl) { + r300->context.draw_vbo = r300_draw_vbo; + } else { + r300->context.draw_vbo = r300_swtcl_draw_vbo; + } + + r300->context.resource_resolve = r300_resource_resolve; + r300->blitter->draw_rectangle = r300_blitter_draw_rectangle; + + /* Plug in the two-sided stencil reference value fallback if needed. */ + if (!r300->screen->caps.is_r500) + r300_plug_in_stencil_ref_fallback(r300); +} diff --git a/src/gallium/drivers/r300/r300_render_stencilref.c b/src/gallium/drivers/r300/r300_render_stencilref.c new file mode 100644 index 0000000..747594a --- /dev/null +++ b/src/gallium/drivers/r300/r300_render_stencilref.c @@ -0,0 +1,129 @@ +/* + * Copyright 2010 Marek Olšák + * + * 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. */ + +/** + * The two-sided stencil reference value fallback for r3xx-r4xx chips. + * These chips support two-sided stencil functions but they do not support + * a two-sided reference value. + * + * The functions below split every draw call which uses the two-sided + * reference value into two draw calls -- the first one renders front faces + * and the second renders back faces with the other reference value. + */ + +#include "r300_context.h" +#include "r300_reg.h" + +struct r300_stencilref_context { + void (*draw_vbo)(struct pipe_context *pipe, + const struct pipe_draw_info *info); + + uint32_t rs_cull_mode; + uint32_t zb_stencilrefmask; + ubyte ref_value_front; +}; + +static boolean r300_stencilref_needed(struct r300_context *r300) +{ + struct r300_dsa_state *dsa = (struct r300_dsa_state*)r300->dsa_state.state; + + return dsa->two_sided_stencil_ref || + (dsa->two_sided && + r300->stencil_ref.ref_value[0] != r300->stencil_ref.ref_value[1]); +} + +/* Set drawing for front faces. */ +static void r300_stencilref_begin(struct r300_context *r300) +{ + struct r300_stencilref_context *sr = r300->stencilref_fallback; + struct r300_rs_state *rs = (struct r300_rs_state*)r300->rs_state.state; + struct r300_dsa_state *dsa = (struct r300_dsa_state*)r300->dsa_state.state; + + /* Save state. */ + sr->rs_cull_mode = rs->cb_main[rs->cull_mode_index]; + sr->zb_stencilrefmask = dsa->stencil_ref_mask; + sr->ref_value_front = r300->stencil_ref.ref_value[0]; + + /* We *cull* pixels, therefore no need to mask out the bits. */ + rs->cb_main[rs->cull_mode_index] |= R300_CULL_BACK; + + r300_mark_atom_dirty(r300, &r300->rs_state); +} + +/* Set drawing for back faces. */ +static void r300_stencilref_switch_side(struct r300_context *r300) +{ + struct r300_stencilref_context *sr = r300->stencilref_fallback; + struct r300_rs_state *rs = (struct r300_rs_state*)r300->rs_state.state; + struct r300_dsa_state *dsa = (struct r300_dsa_state*)r300->dsa_state.state; + + rs->cb_main[rs->cull_mode_index] = sr->rs_cull_mode | R300_CULL_FRONT; + dsa->stencil_ref_mask = dsa->stencil_ref_bf; + r300->stencil_ref.ref_value[0] = r300->stencil_ref.ref_value[1]; + + r300_mark_atom_dirty(r300, &r300->rs_state); + r300_mark_atom_dirty(r300, &r300->dsa_state); +} + +/* Restore the original state. */ +static void r300_stencilref_end(struct r300_context *r300) +{ + struct r300_stencilref_context *sr = r300->stencilref_fallback; + struct r300_rs_state *rs = (struct r300_rs_state*)r300->rs_state.state; + struct r300_dsa_state *dsa = (struct r300_dsa_state*)r300->dsa_state.state; + + /* Restore state. */ + rs->cb_main[rs->cull_mode_index] = sr->rs_cull_mode; + dsa->stencil_ref_mask = sr->zb_stencilrefmask; + r300->stencil_ref.ref_value[0] = sr->ref_value_front; + + r300_mark_atom_dirty(r300, &r300->rs_state); + r300_mark_atom_dirty(r300, &r300->dsa_state); +} + +static void r300_stencilref_draw_vbo(struct pipe_context *pipe, + const struct pipe_draw_info *info) +{ + struct r300_context *r300 = r300_context(pipe); + struct r300_stencilref_context *sr = r300->stencilref_fallback; + + if (!r300_stencilref_needed(r300)) { + sr->draw_vbo(pipe, info); + } else { + r300_stencilref_begin(r300); + sr->draw_vbo(pipe, info); + r300_stencilref_switch_side(r300); + sr->draw_vbo(pipe, info); + r300_stencilref_end(r300); + } +} + +void r300_plug_in_stencil_ref_fallback(struct r300_context *r300) +{ + r300->stencilref_fallback = CALLOC_STRUCT(r300_stencilref_context); + + /* Save original draw function. */ + r300->stencilref_fallback->draw_vbo = r300->context.draw_vbo; + + /* Override the draw function. */ + r300->context.draw_vbo = r300_stencilref_draw_vbo; +} diff --git a/src/gallium/drivers/r300/r300_render_translate.c b/src/gallium/drivers/r300/r300_render_translate.c new file mode 100644 index 0000000..41a43b0 --- /dev/null +++ b/src/gallium/drivers/r300/r300_render_translate.c @@ -0,0 +1,222 @@ +/* + * Copyright 2010 Marek Olšák + * + * 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. */ + +/** + * The functions below translate vertex and index buffers to the layout + * compatible with the hardware, so that all vertex and index fetches are + * DWORD-aligned and all used vertex and index formats are supported. + * For indices, an optional index offset is added to each index. + */ + +#include "r300_context.h" +#include "translate/translate.h" +#include "util/u_index_modify.h" + +void r300_begin_vertex_translate(struct r300_context *r300) +{ + struct pipe_context *pipe = &r300->context; + struct translate_key key = {0}; + struct translate_element *te; + unsigned tr_elem_index[PIPE_MAX_ATTRIBS] = {0}; + struct translate *tr; + struct r300_vertex_element_state *ve = r300->velems; + boolean vb_translated[PIPE_MAX_ATTRIBS] = {0}; + void *vb_map[PIPE_MAX_ATTRIBS] = {0}, *out_map; + struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS] = {0}, *out_transfer; + struct pipe_resource *out_buffer; + unsigned i, num_verts; + + /* Initialize the translate key, i.e. the recipe how vertices should be + * translated. */ + for (i = 0; i < ve->count; i++) { + struct pipe_vertex_buffer *vb = + &r300->vertex_buffer[ve->velem[i].vertex_buffer_index]; + enum pipe_format output_format = ve->hw_format[i]; + unsigned output_format_size = ve->hw_format_size[i]; + + /* Check for support. */ + if (ve->velem[i].src_format == ve->hw_format[i] && + (vb->buffer_offset + ve->velem[i].src_offset) % 4 == 0 && + vb->stride % 4 == 0) { + continue; + } + + /* Workaround for translate: output floats instead of halfs. */ + switch (output_format) { + case PIPE_FORMAT_R16_FLOAT: + output_format = PIPE_FORMAT_R32_FLOAT; + output_format_size = 4; + break; + case PIPE_FORMAT_R16G16_FLOAT: + output_format = PIPE_FORMAT_R32G32_FLOAT; + output_format_size = 8; + break; + case PIPE_FORMAT_R16G16B16_FLOAT: + output_format = PIPE_FORMAT_R32G32B32_FLOAT; + output_format_size = 12; + break; + case PIPE_FORMAT_R16G16B16A16_FLOAT: + output_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + output_format_size = 16; + break; + default:; + } + + /* Add this vertex element. */ + te = &key.element[key.nr_elements]; + /*te->type; + te->instance_divisor;*/ + te->input_buffer = ve->velem[i].vertex_buffer_index; + te->input_format = ve->velem[i].src_format; + te->input_offset = vb->buffer_offset + ve->velem[i].src_offset; + te->output_format = output_format; + te->output_offset = key.output_stride; + + key.output_stride += output_format_size; + vb_translated[ve->velem[i].vertex_buffer_index] = TRUE; + tr_elem_index[i] = key.nr_elements; + key.nr_elements++; + } + + /* Get a translate object. */ + tr = translate_cache_find(r300->tran.translate_cache, &key); + + /* Map buffers we want to translate. */ + for (i = 0; i < r300->vertex_buffer_count; i++) { + if (vb_translated[i]) { + struct pipe_vertex_buffer *vb = &r300->vertex_buffer[i]; + + vb_map[i] = pipe_buffer_map(pipe, vb->buffer, + PIPE_TRANSFER_READ, &vb_transfer[i]); + + tr->set_buffer(tr, i, vb_map[i], vb->stride, vb->max_index); + } + } + + /* Create and map the output buffer. */ + num_verts = r300->vertex_buffer_max_index + 1; + + out_buffer = pipe_buffer_create(&r300->screen->screen, + PIPE_BIND_VERTEX_BUFFER, + key.output_stride * num_verts); + + out_map = pipe_buffer_map(pipe, out_buffer, PIPE_TRANSFER_WRITE, + &out_transfer); + + /* Translate. */ + tr->run(tr, 0, num_verts, 0, out_map); + + /* Unmap all buffers. */ + for (i = 0; i < r300->vertex_buffer_count; i++) { + if (vb_translated[i]) { + pipe_buffer_unmap(pipe, r300->vertex_buffer[i].buffer, + vb_transfer[i]); + } + } + + pipe_buffer_unmap(pipe, out_buffer, out_transfer); + + /* Setup the new vertex buffer in the first free slot. */ + for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { + struct pipe_vertex_buffer *vb = &r300->vertex_buffer[i]; + + if (!vb->buffer) { + pipe_resource_reference(&vb->buffer, out_buffer); + vb->buffer_offset = 0; + vb->max_index = num_verts - 1; + vb->stride = key.output_stride; + r300->tran.vb_slot = i; + r300->validate_buffers = TRUE; + break; + } + } + + /* Save and replace vertex elements. */ + { + struct pipe_vertex_element new_velems[PIPE_MAX_ATTRIBS]; + + r300->tran.saved_velems = r300->velems; + + for (i = 0; i < ve->count; i++) { + if (vb_translated[ve->velem[i].vertex_buffer_index]) { + te = &key.element[tr_elem_index[i]]; + new_velems[i].instance_divisor = ve->velem[i].instance_divisor; + new_velems[i].src_format = te->output_format; + new_velems[i].src_offset = te->output_offset; + new_velems[i].vertex_buffer_index = r300->tran.vb_slot; + } else { + memcpy(&new_velems[i], &ve->velem[i], + sizeof(struct pipe_vertex_element)); + } + } + + r300->tran.new_velems = + pipe->create_vertex_elements_state(pipe, ve->count, new_velems); + pipe->bind_vertex_elements_state(pipe, r300->tran.new_velems); + } + + pipe_resource_reference(&out_buffer, NULL); +} + +void r300_end_vertex_translate(struct r300_context *r300) +{ + struct pipe_context *pipe = &r300->context; + + /* Restore vertex elements. */ + pipe->bind_vertex_elements_state(pipe, r300->tran.saved_velems); + pipe->delete_vertex_elements_state(pipe, r300->tran.new_velems); + + /* Delete the now-unused VBO. */ + pipe_resource_reference(&r300->vertex_buffer[r300->tran.vb_slot].buffer, + NULL); +} + +void r300_translate_index_buffer(struct r300_context *r300, + struct pipe_resource **index_buffer, + unsigned *index_size, unsigned index_offset, + unsigned *start, unsigned count) +{ + switch (*index_size) { + case 1: + util_shorten_ubyte_elts(&r300->context, index_buffer, index_offset, *start, count); + *index_size = 2; + *start = 0; + r300->validate_buffers = TRUE; + break; + + case 2: + if (*start % 2 != 0 || index_offset) { + util_rebuild_ushort_elts(&r300->context, index_buffer, index_offset, *start, count); + *start = 0; + r300->validate_buffers = TRUE; + } + break; + + case 4: + if (index_offset) { + util_rebuild_uint_elts(&r300->context, index_buffer, index_offset, *start, count); + *start = 0; + r300->validate_buffers = TRUE; + } + break; + } +} diff --git a/src/gallium/drivers/r300/r300_resource.c b/src/gallium/drivers/r300/r300_resource.c new file mode 100644 index 0000000..dd1df97 --- /dev/null +++ b/src/gallium/drivers/r300/r300_resource.c @@ -0,0 +1,72 @@ +/* + * Copyright 2010 Red Hat 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 + * 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. + * + * Authors: Dave Airlie + */ + +#include "r300_context.h" +#include "r300_texture.h" +#include "r300_screen_buffer.h" + +static struct pipe_resource * +r300_resource_create(struct pipe_screen *screen, + const struct pipe_resource *templ) +{ + if (templ->target == PIPE_BUFFER) + return r300_buffer_create(screen, templ); + else + return r300_texture_create(screen, templ); + +} + +static struct pipe_resource * +r300_resource_from_handle(struct pipe_screen * screen, + const struct pipe_resource *templ, + struct winsys_handle *whandle) +{ + if (templ->target == PIPE_BUFFER) + return NULL; + else + return r300_texture_from_handle(screen, templ, whandle); +} + +void r300_init_resource_functions(struct r300_context *r300) +{ + r300->context.get_transfer = u_get_transfer_vtbl; + r300->context.transfer_map = u_transfer_map_vtbl; + r300->context.transfer_flush_region = u_transfer_flush_region_vtbl; + r300->context.transfer_unmap = u_transfer_unmap_vtbl; + r300->context.transfer_destroy = u_transfer_destroy_vtbl; + r300->context.transfer_inline_write = u_transfer_inline_write_vtbl; + r300->context.is_resource_referenced = u_is_resource_referenced_vtbl; + r300->context.create_surface = r300_create_surface; + r300->context.surface_destroy = r300_surface_destroy; +} + +void r300_init_screen_resource_functions(struct r300_screen *r300screen) +{ + r300screen->screen.resource_create = r300_resource_create; + r300screen->screen.resource_from_handle = r300_resource_from_handle; + r300screen->screen.resource_get_handle = u_resource_get_handle_vtbl; + r300screen->screen.resource_destroy = u_resource_destroy_vtbl; + r300screen->screen.user_buffer_create = r300_user_buffer_create; +} diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c new file mode 100644 index 0000000..93d0c62 --- /dev/null +++ b/src/gallium/drivers/r300/r300_screen.c @@ -0,0 +1,496 @@ +/* + * Copyright 2008 Corbin Simpson + * Copyright 2010 Marek Olšák + * + * 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 "util/u_format.h" +#include "util/u_format_s3tc.h" +#include "util/u_memory.h" + +#include "r300_context.h" +#include "r300_texture.h" +#include "r300_screen_buffer.h" +#include "r300_state_inlines.h" +#include "r300_winsys.h" +#include "r300_public.h" + +#include "draw/draw_context.h" + +#ifdef HAVE_LLVM +#include "gallivm/lp_bld_init.h" +#endif + +/* Return the identifier behind whom the brave coders responsible for this + * amalgamation of code, sweat, and duct tape, routinely obscure their names. + * + * ...I should have just put "Corbin Simpson", but I'm not that cool. + * + * (Or egotistical. Yet.) */ +static const char* r300_get_vendor(struct pipe_screen* pscreen) +{ + return "X.Org R300 Project"; +} + +static const char* chip_families[] = { + "ATI R300", + "ATI R350", + "ATI R360", + "ATI RV350", + "ATI RV370", + "ATI RV380", + "ATI R420", + "ATI R423", + "ATI R430", + "ATI R480", + "ATI R481", + "ATI RV410", + "ATI RS400", + "ATI RC410", + "ATI RS480", + "ATI RS482", + "ATI RS600", + "ATI RS690", + "ATI RS740", + "ATI RV515", + "ATI R520", + "ATI RV530", + "ATI R580", + "ATI RV560", + "ATI RV570" +}; + +static const char* r300_get_name(struct pipe_screen* pscreen) +{ + struct r300_screen* r300screen = r300_screen(pscreen); + + return chip_families[r300screen->caps.family]; +} + +static int r300_get_param(struct pipe_screen* pscreen, enum pipe_cap param) +{ + struct r300_screen* r300screen = r300_screen(pscreen); + boolean is_r400 = r300screen->caps.is_r400; + boolean is_r500 = r300screen->caps.is_r500; + + /* XXX extended shader capabilities of r400 unimplemented */ + is_r400 = FALSE; + + switch (param) { + /* Supported features (boolean caps). */ + case PIPE_CAP_NPOT_TEXTURES: + case PIPE_CAP_TWO_SIDED_STENCIL: + case PIPE_CAP_GLSL: + /* I'll be frank. This is a lie. + * + * We don't truly support GLSL on any of this driver's chipsets. + * To be fair, no chipset supports the full GLSL specification + * to the best of our knowledge, but some of the less esoteric + * features are still missing here. + * + * Rather than cripple ourselves intentionally, I'm going to set + * this flag, and as Gallium's interface continues to change, I + * hope that this single monolithic GLSL enable can slowly get + * split down into many different pieces and the state tracker + * will handle fallbacks transparently, like it should. + * + * ~ C. + */ + case PIPE_CAP_ANISOTROPIC_FILTER: + case PIPE_CAP_POINT_SPRITE: + case PIPE_CAP_OCCLUSION_QUERY: + case PIPE_CAP_TEXTURE_SHADOW_MAP: + case PIPE_CAP_TEXTURE_MIRROR_CLAMP: + case PIPE_CAP_TEXTURE_MIRROR_REPEAT: + case PIPE_CAP_BLEND_EQUATION_SEPARATE: + return 1; + case PIPE_CAP_TEXTURE_SWIZZLE: + return util_format_s3tc_enabled ? r300screen->caps.dxtc_swizzle : 1; + + /* Unsupported features (boolean caps). */ + case PIPE_CAP_TIMER_QUERY: + case PIPE_CAP_DUAL_SOURCE_BLEND: + case PIPE_CAP_INDEP_BLEND_ENABLE: + case PIPE_CAP_INDEP_BLEND_FUNC: + case PIPE_CAP_DEPTH_CLAMP: /* XXX implemented, but breaks Regnum Online */ + case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: + case PIPE_CAP_SHADER_STENCIL_EXPORT: + case PIPE_CAP_STREAM_OUTPUT: + case PIPE_CAP_PRIMITIVE_RESTART: + return 0; + + /* Texturing. */ + case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: + case PIPE_CAP_MAX_COMBINED_SAMPLERS: + return r300screen->caps.num_tex_units; + case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS: + return 0; + case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: + case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: + case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: + /* 13 == 4096, 12 == 2048 */ + return is_r500 ? 13 : 12; + + /* Render targets. */ + case PIPE_CAP_MAX_RENDER_TARGETS: + return 4; + + /* General shader limits and features. */ + case PIPE_CAP_SM3: + return is_r500 ? 1 : 0; + /* Fragment coordinate conventions. */ + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: + return 1; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: + return 0; + default: + debug_printf("r300: Warning: Unknown CAP %d in get_param.\n", + param); + return 0; + } +} + +static int r300_get_shader_param(struct pipe_screen *pscreen, unsigned shader, enum pipe_shader_cap param) +{ + struct r300_screen* r300screen = r300_screen(pscreen); + boolean is_r400 = r300screen->caps.is_r400; + boolean is_r500 = r300screen->caps.is_r500; + + /* XXX extended shader capabilities of r400 unimplemented */ + is_r400 = FALSE; + + switch (shader) + { + case PIPE_SHADER_FRAGMENT: + switch (param) + { + case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: + return is_r500 || is_r400 ? 512 : 96; + case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: + return is_r500 || is_r400 ? 512 : 64; + case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: + return is_r500 || is_r400 ? 512 : 32; + case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: + return is_r500 ? 511 : 4; + case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: + return is_r500 ? 64 : 0; /* Actually unlimited on r500. */ + /* Fragment shader limits. */ + case PIPE_SHADER_CAP_MAX_INPUTS: + /* 2 colors + 8 texcoords are always supported + * (minus fog and wpos). + * + * R500 has the ability to turn 3rd and 4th color into + * additional texcoords but there is no two-sided color + * selection then. However the facing bit can be used instead. */ + return 10; + case PIPE_SHADER_CAP_MAX_CONSTS: + return is_r500 ? 256 : 32; + case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: + return 1; + case PIPE_SHADER_CAP_MAX_TEMPS: + return is_r500 ? 128 : is_r400 ? 64 : 32; + case PIPE_SHADER_CAP_MAX_ADDRS: + return 0; + case PIPE_SHADER_CAP_MAX_PREDS: + return is_r500 ? 1 : 0; + case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: + return 0; + case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: + case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: + return 0; + case PIPE_SHADER_CAP_SUBROUTINES: + return 0; + } + break; + case PIPE_SHADER_VERTEX: + if (!r300screen->caps.has_tcl) { + return draw_get_shader_param(shader, param); + } + + switch (param) + { + case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: + return is_r500 ? 1024 : 256; + case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: + return 0; + case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: + return is_r500 ? 4 : 0; /* For loops; not sure about conditionals. */ + case PIPE_SHADER_CAP_MAX_INPUTS: + return 16; + case PIPE_SHADER_CAP_MAX_CONSTS: + return 256; + case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: + return 1; + case PIPE_SHADER_CAP_MAX_TEMPS: + return 32; + case PIPE_SHADER_CAP_MAX_ADDRS: + return 1; /* XXX guessed */ + case PIPE_SHADER_CAP_MAX_PREDS: + return is_r500 ? 4 : 0; /* XXX guessed. */ + case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: + return 0; + case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: + return 0; + case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: + return 1; + case PIPE_SHADER_CAP_SUBROUTINES: + return 0; + default: + break; + } + break; + default: + break; + } + return 0; +} + +static float r300_get_paramf(struct pipe_screen* pscreen, enum pipe_cap param) +{ + struct r300_screen* r300screen = r300_screen(pscreen); + + switch (param) { + case PIPE_CAP_MAX_LINE_WIDTH: + case PIPE_CAP_MAX_LINE_WIDTH_AA: + case PIPE_CAP_MAX_POINT_WIDTH: + case PIPE_CAP_MAX_POINT_WIDTH_AA: + /* The maximum dimensions of the colorbuffer are our practical + * rendering limits. 2048 pixels should be enough for anybody. */ + if (r300screen->caps.is_r500) { + return 4096.0f; + } else if (r300screen->caps.is_r400) { + return 4021.0f; + } else { + return 2560.0f; + } + case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: + return 16.0f; + case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: + return 16.0f; + case PIPE_CAP_GUARD_BAND_LEFT: + case PIPE_CAP_GUARD_BAND_TOP: + case PIPE_CAP_GUARD_BAND_RIGHT: + case PIPE_CAP_GUARD_BAND_BOTTOM: + /* XXX I don't know what these should be but the least we can do is + * silence the potential error message */ + return 0.0f; + default: + debug_printf("r300: Warning: Unknown CAP %d in get_paramf.\n", + param); + return 0.0f; + } +} + +static boolean r300_is_format_supported(struct pipe_screen* screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned usage, + unsigned geom_flags) +{ + uint32_t retval = 0; + boolean is_r500 = r300_screen(screen)->caps.is_r500; + boolean is_r400 = r300_screen(screen)->caps.is_r400; + boolean is_color2101010 = format == PIPE_FORMAT_R10G10B10A2_UNORM || + format == PIPE_FORMAT_R10G10B10X2_SNORM || + format == PIPE_FORMAT_B10G10R10A2_UNORM || + format == PIPE_FORMAT_R10SG10SB10SA2U_NORM; + boolean is_ati1n = format == PIPE_FORMAT_RGTC1_UNORM || + format == PIPE_FORMAT_RGTC1_SNORM; + boolean is_ati2n = format == PIPE_FORMAT_RGTC2_UNORM || + format == PIPE_FORMAT_RGTC2_SNORM; + boolean is_half_float = format == PIPE_FORMAT_R16_FLOAT || + format == PIPE_FORMAT_R16G16_FLOAT || + format == PIPE_FORMAT_R16G16B16_FLOAT || + format == PIPE_FORMAT_R16G16B16A16_FLOAT; + + /* Check multisampling support. */ + switch (sample_count) { + case 0: + case 1: + break; + case 2: + case 3: + case 4: + case 6: + return FALSE; +#if 0 + if (usage != PIPE_BIND_RENDER_TARGET || + !util_format_is_rgba8_variant( + util_format_description(format))) { + return FALSE; + } +#endif + break; + default: + return FALSE; + } + + /* Check sampler format support. */ + if ((usage & PIPE_BIND_SAMPLER_VIEW) && + /* ATI1N is r5xx-only. */ + (is_r500 || !is_ati1n) && + /* ATI2N is supported on r4xx-r5xx. */ + (is_r400 || is_r500 || !is_ati2n) && + r300_is_sampler_format_supported(format)) { + retval |= PIPE_BIND_SAMPLER_VIEW; + } + + /* Check colorbuffer format support. */ + if ((usage & (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SCANOUT | + PIPE_BIND_SHARED)) && + /* 2101010 cannot be rendered to on non-r5xx. */ + (is_r500 || !is_color2101010) && + r300_is_colorbuffer_format_supported(format)) { + retval |= usage & + (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SCANOUT | + PIPE_BIND_SHARED); + } + + /* Check depth-stencil format support. */ + if (usage & PIPE_BIND_DEPTH_STENCIL && + r300_is_zs_format_supported(format)) { + retval |= PIPE_BIND_DEPTH_STENCIL; + } + + /* Check vertex buffer format support. */ + if (usage & PIPE_BIND_VERTEX_BUFFER && + /* Half float is supported on >= RV350. */ + (is_r400 || is_r500 || !is_half_float) && + r300_translate_vertex_data_type(format) != R300_INVALID_FORMAT) { + retval |= PIPE_BIND_VERTEX_BUFFER; + } + + /* Transfers are always supported. */ + if (usage & PIPE_BIND_TRANSFER_READ) + retval |= PIPE_BIND_TRANSFER_READ; + if (usage & PIPE_BIND_TRANSFER_WRITE) + retval |= PIPE_BIND_TRANSFER_WRITE; + + return retval == usage; +} + +static void r300_destroy_screen(struct pipe_screen* pscreen) +{ + struct r300_screen* r300screen = r300_screen(pscreen); + struct r300_winsys_screen *rws = r300_winsys_screen(pscreen); + + util_slab_destroy(&r300screen->pool_buffers); + + if (rws) + rws->destroy(rws); + + FREE(r300screen); +} + +static void r300_fence_reference(struct pipe_screen *screen, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + struct r300_fence **oldf = (struct r300_fence**)ptr; + struct r300_fence *newf = (struct r300_fence*)fence; + + if (pipe_reference(&(*oldf)->reference, &newf->reference)) + FREE(*oldf); + + *ptr = fence; +} + +static int r300_fence_signalled(struct pipe_screen *screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + struct r300_fence *rfence = (struct r300_fence*)fence; + + return rfence->signalled ? 0 : 1; /* 0 == success */ +} + +static int r300_fence_finish(struct pipe_screen *screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + struct r300_fence *rfence = (struct r300_fence*)fence; + + r300_finish(rfence->ctx); + rfence->signalled = TRUE; + return 0; /* 0 == success */ +} + +struct pipe_screen* r300_screen_create(struct r300_winsys_screen *rws) +{ + struct r300_screen *r300screen = CALLOC_STRUCT(r300_screen); + + if (!r300screen) { + FREE(r300screen); + return NULL; + } + + r300screen->caps.pci_id = rws->get_value(rws, R300_VID_PCI_ID); + r300screen->caps.num_frag_pipes = rws->get_value(rws, R300_VID_GB_PIPES); + r300screen->caps.num_z_pipes = rws->get_value(rws, R300_VID_Z_PIPES); + + r300_init_debug(r300screen); + r300_parse_chipset(&r300screen->caps); + + r300screen->caps.index_bias_supported = + r300screen->caps.is_r500 && + rws->get_value(rws, R300_VID_DRM_2_3_0); + + util_slab_create(&r300screen->pool_buffers, + sizeof(struct r300_buffer), 64, + UTIL_SLAB_SINGLETHREADED); + + r300screen->rws = rws; + r300screen->screen.winsys = (struct pipe_winsys*)rws; + r300screen->screen.destroy = r300_destroy_screen; + r300screen->screen.get_name = r300_get_name; + r300screen->screen.get_vendor = r300_get_vendor; + r300screen->screen.get_param = r300_get_param; + r300screen->screen.get_shader_param = r300_get_shader_param; + r300screen->screen.get_paramf = r300_get_paramf; + r300screen->screen.is_format_supported = r300_is_format_supported; + r300screen->screen.context_create = r300_create_context; + + r300screen->screen.fence_reference = r300_fence_reference; + r300screen->screen.fence_signalled = r300_fence_signalled; + r300screen->screen.fence_finish = r300_fence_finish; + + r300_init_screen_resource_functions(r300screen); + + util_format_s3tc_init(); + +#ifdef HAVE_LLVM + lp_build_init(); +#endif + + return &r300screen->screen; +} diff --git a/src/gallium/drivers/r300/r300_screen.h b/src/gallium/drivers/r300/r300_screen.h new file mode 100644 index 0000000..5847fe1 --- /dev/null +++ b/src/gallium/drivers/r300/r300_screen.h @@ -0,0 +1,127 @@ +/* + * Copyright 2008 Corbin Simpson + * Copyright 2010 Marek Olšák + * + * 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 R300_SCREEN_H +#define R300_SCREEN_H + +#include "pipe/p_screen.h" + +#include "r300_chipset.h" + +#include "util/u_slab.h" + +#include + +struct r300_winsys_screen; + +struct r300_screen { + /* Parent class */ + struct pipe_screen screen; + + struct r300_winsys_screen *rws; + + /* Chipset capabilities */ + struct r300_capabilities caps; + + /* Memory pools. */ + struct util_slab_mempool pool_buffers; + + /** Combination of DBG_xxx flags */ + unsigned debug; + + /* The number of created contexts to know whether we have multiple + * contexts or not. */ + int num_contexts; +}; + + +/* Convenience cast wrappers. */ +static INLINE struct r300_screen* r300_screen(struct pipe_screen* screen) { + return (struct r300_screen*)screen; +} + +static INLINE struct r300_winsys_screen * +r300_winsys_screen(struct pipe_screen *screen) { + return r300_screen(screen)->rws; +} + +/* Debug functionality. */ + +/** + * Debug flags to disable/enable certain groups of debugging outputs. + * + * \note These may be rather coarse, and the grouping may be impractical. + * If you find, while debugging the driver, that a different grouping + * of these flags would be beneficial, just feel free to change them + * but make sure to update the documentation in r300_debug.c to reflect + * those changes. + */ +/*@{*/ + +/* Logging. */ +#define DBG_PSC (1 << 0) +#define DBG_FP (1 << 1) +#define DBG_VP (1 << 2) +#define DBG_SWTCL (1 << 3) +#define DBG_DRAW (1 << 4) +#define DBG_TEX (1 << 5) +#define DBG_TEXALLOC (1 << 6) +#define DBG_RS (1 << 7) +#define DBG_FALL (1 << 8) +#define DBG_FB (1 << 9) +#define DBG_RS_BLOCK (1 << 10) +#define DBG_CBZB (1 << 11) +#define DBG_HYPERZ (1 << 12) +#define DBG_SCISSOR (1 << 13) +/* Features. */ +#define DBG_ANISOHQ (1 << 16) +#define DBG_NO_TILING (1 << 17) +#define DBG_NO_IMMD (1 << 18) +#define DBG_FAKE_OCC (1 << 19) +#define DBG_NO_OPT (1 << 20) +#define DBG_NO_CBZB (1 << 21) +/* Statistics. */ +#define DBG_P_STAT (1 << 25) +/*@}*/ + +static INLINE boolean SCREEN_DBG_ON(struct r300_screen * screen, unsigned flags) +{ + return (screen->debug & flags) ? TRUE : FALSE; +} + +static INLINE void SCREEN_DBG(struct r300_screen * screen, unsigned flags, + const char * fmt, ...) +{ + if (SCREEN_DBG_ON(screen, flags)) { + va_list va; + va_start(va, fmt); + vfprintf(stderr, fmt, va); + va_end(va); + } +} + +void r300_init_debug(struct r300_screen* ctx); + +void r300_init_screen_resource_functions(struct r300_screen *r300screen); + +#endif /* R300_SCREEN_H */ diff --git a/src/gallium/drivers/r300/r300_screen_buffer.c b/src/gallium/drivers/r300/r300_screen_buffer.c new file mode 100644 index 0000000..0d52da9 --- /dev/null +++ b/src/gallium/drivers/r300/r300_screen_buffer.c @@ -0,0 +1,387 @@ +/* + * Copyright 2010 Red Hat 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 + * 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. + * + * Authors: Dave Airlie + */ + +#include + +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_upload_mgr.h" +#include "util/u_math.h" + +#include "r300_screen_buffer.h" +#include "r300_winsys.h" + +unsigned r300_buffer_is_referenced(struct pipe_context *context, + struct pipe_resource *buf, + enum r300_reference_domain domain) +{ + struct r300_context *r300 = r300_context(context); + struct r300_buffer *rbuf = r300_buffer(buf); + + if (r300_buffer_is_user_buffer(buf)) + return PIPE_UNREFERENCED; + + if (r300->rws->cs_is_buffer_referenced(r300->cs, rbuf->cs_buf, domain)) + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; + + return PIPE_UNREFERENCED; +} + +static unsigned r300_buffer_is_referenced_by_cs(struct pipe_context *context, + struct pipe_resource *buf, + unsigned level, int layer) +{ + return r300_buffer_is_referenced(context, buf, R300_REF_CS); +} + +/* External helper, not required to implent u_resource_vtbl: + */ +int r300_upload_index_buffer(struct r300_context *r300, + struct pipe_resource **index_buffer, + unsigned index_size, + unsigned start, + unsigned count, + unsigned *out_offset) +{ + struct pipe_resource *upload_buffer = NULL; + unsigned index_offset = start * index_size; + int ret = 0; + + if (r300_buffer_is_user_buffer(*index_buffer)) { + ret = u_upload_buffer(r300->upload_ib, + index_offset, + count * index_size, + *index_buffer, + &index_offset, + &upload_buffer); + if (ret) { + goto done; + } + *index_buffer = upload_buffer; + *out_offset = index_offset / index_size; + } else + *out_offset = start; + + done: + // if (upload_buffer) + // pipe_resource_reference(&upload_buffer, NULL); + return ret; +} + +/* External helper, not required to implement u_resource_vtbl: + */ +int r300_upload_user_buffers(struct r300_context *r300) +{ + enum pipe_error ret = PIPE_OK; + int i, nr; + + nr = r300->velems->count; + + for (i = 0; i < nr; i++) { + struct pipe_vertex_buffer *vb = + &r300->vertex_buffer[r300->velems->velem[i].vertex_buffer_index]; + + if (r300_buffer_is_user_buffer(vb->buffer)) { + struct pipe_resource *upload_buffer = NULL; + unsigned offset = 0; /*vb->buffer_offset * 4;*/ + unsigned size = vb->buffer->width0; + unsigned upload_offset; + ret = u_upload_buffer(r300->upload_vb, + offset, size, + vb->buffer, + &upload_offset, &upload_buffer); + if (ret) + return ret; + + pipe_resource_reference(&vb->buffer, NULL); + vb->buffer = upload_buffer; + vb->buffer_offset = upload_offset; + r300->validate_buffers = TRUE; + r300->aos_dirty = TRUE; + } + } + return ret; +} + +static void r300_buffer_destroy(struct pipe_screen *screen, + struct pipe_resource *buf) +{ + struct r300_screen *r300screen = r300_screen(screen); + struct r300_buffer *rbuf = r300_buffer(buf); + struct r300_winsys_screen *rws = r300screen->rws; + + if (rbuf->constant_buffer) + FREE(rbuf->constant_buffer); + + if (rbuf->buf) + rws->buffer_reference(rws, &rbuf->buf, NULL); + + util_slab_free(&r300screen->pool_buffers, rbuf); +} + +static struct pipe_transfer* +r300_buffer_get_transfer(struct pipe_context *context, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct r300_context *r300 = r300_context(context); + struct pipe_transfer *transfer = + util_slab_alloc(&r300->pool_transfers); + + transfer->resource = resource; + transfer->level = level; + transfer->usage = usage; + transfer->box = *box; + transfer->stride = 0; + transfer->layer_stride = 0; + transfer->data = NULL; + + /* Note strides are zero, this is ok for buffers, but not for + * textures 2d & higher at least. + */ + return transfer; +} + +static void r300_buffer_transfer_destroy(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct r300_context *r300 = r300_context(pipe); + util_slab_free(&r300->pool_transfers, transfer); +} + +static void * +r300_buffer_transfer_map( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct r300_context *r300 = r300_context(pipe); + struct r300_screen *r300screen = r300_screen(pipe->screen); + struct r300_winsys_screen *rws = r300screen->rws; + struct r300_buffer *rbuf = r300_buffer(transfer->resource); + uint8_t *map; + boolean flush = FALSE; + unsigned i; + + if (rbuf->user_buffer) + return (uint8_t *) rbuf->user_buffer + transfer->box.x; + if (rbuf->constant_buffer) + return (uint8_t *) rbuf->constant_buffer + transfer->box.x; + + /* check if the mapping is to a range we already flushed */ + if (transfer->usage & PIPE_TRANSFER_DISCARD) { + for (i = 0; i < rbuf->num_ranges; i++) { + if ((transfer->box.x >= rbuf->ranges[i].start) && + (transfer->box.x < rbuf->ranges[i].end)) + flush = TRUE; + + if (flush) { + /* unreference this hw buffer and allocate a new one */ + rws->buffer_reference(rws, &rbuf->buf, NULL); + + rbuf->num_ranges = 0; + rbuf->buf = + r300screen->rws->buffer_create(r300screen->rws, + rbuf->b.b.width0, 16, + rbuf->b.b.bind, + rbuf->b.b.usage, + rbuf->domain); + rbuf->cs_buf = + r300screen->rws->buffer_get_cs_handle(r300screen->rws, + rbuf->buf); + break; + } + } + } + + map = rws->buffer_map(rws, rbuf->buf, r300->cs, transfer->usage); + + if (map == NULL) + return NULL; + + /* map_buffer() returned a pointer to the beginning of the buffer, + * but transfers are expected to return a pointer to just the + * region specified in the box. + */ + return map + transfer->box.x; +} + +static void r300_buffer_transfer_flush_region( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box) +{ + struct r300_buffer *rbuf = r300_buffer(transfer->resource); + unsigned i; + unsigned offset = transfer->box.x + box->x; + unsigned length = box->width; + + assert(box->x + box->width <= transfer->box.width); + + if (rbuf->user_buffer) + return; + if (rbuf->constant_buffer) + return; + + /* mark the range as used */ + for(i = 0; i < rbuf->num_ranges; ++i) { + if(offset <= rbuf->ranges[i].end && rbuf->ranges[i].start <= (offset+box->width)) { + rbuf->ranges[i].start = MIN2(rbuf->ranges[i].start, offset); + rbuf->ranges[i].end = MAX2(rbuf->ranges[i].end, (offset+length)); + return; + } + } + + rbuf->ranges[rbuf->num_ranges].start = offset; + rbuf->ranges[rbuf->num_ranges].end = offset+length; + rbuf->num_ranges++; +} + +static void r300_buffer_transfer_unmap( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct r300_screen *r300screen = r300_screen(pipe->screen); + struct r300_winsys_screen *rws = r300screen->rws; + struct r300_buffer *rbuf = r300_buffer(transfer->resource); + + if (rbuf->buf) { + rws->buffer_unmap(rws, rbuf->buf); + } +} + +static void r300_buffer_transfer_inline_write(struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride) +{ + struct r300_buffer *rbuf = r300_buffer(resource); + struct pipe_transfer *transfer = NULL; + uint8_t *map = NULL; + + if (rbuf->constant_buffer) { + memcpy(rbuf->constant_buffer + box->x, data, box->width); + return; + } + + transfer = r300_buffer_get_transfer(pipe, resource, 0, + PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD, box); + map = r300_buffer_transfer_map(pipe, transfer); + + memcpy(map, data, box->width); + + r300_buffer_transfer_unmap(pipe, transfer); + r300_buffer_transfer_destroy(pipe, transfer); +} + +struct u_resource_vtbl r300_buffer_vtbl = +{ + u_default_resource_get_handle, /* get_handle */ + r300_buffer_destroy, /* resource_destroy */ + r300_buffer_is_referenced_by_cs, /* is_buffer_referenced */ + r300_buffer_get_transfer, /* get_transfer */ + r300_buffer_transfer_destroy, /* transfer_destroy */ + r300_buffer_transfer_map, /* transfer_map */ + r300_buffer_transfer_flush_region, /* transfer_flush_region */ + r300_buffer_transfer_unmap, /* transfer_unmap */ + r300_buffer_transfer_inline_write /* transfer_inline_write */ +}; + +struct pipe_resource *r300_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *templ) +{ + struct r300_screen *r300screen = r300_screen(screen); + struct r300_buffer *rbuf; + unsigned alignment = 16; + + rbuf = util_slab_alloc(&r300screen->pool_buffers); + + rbuf->magic = R300_BUFFER_MAGIC; + + rbuf->b.b = *templ; + rbuf->b.vtbl = &r300_buffer_vtbl; + pipe_reference_init(&rbuf->b.b.reference, 1); + rbuf->b.b.screen = screen; + rbuf->domain = R300_DOMAIN_GTT; + rbuf->num_ranges = 0; + rbuf->buf = NULL; + rbuf->constant_buffer = NULL; + rbuf->user_buffer = NULL; + + /* Alloc constant buffers in RAM. */ + if (templ->bind & PIPE_BIND_CONSTANT_BUFFER) { + rbuf->constant_buffer = MALLOC(templ->width0); + return &rbuf->b.b; + } + + rbuf->buf = + r300screen->rws->buffer_create(r300screen->rws, + rbuf->b.b.width0, alignment, + rbuf->b.b.bind, rbuf->b.b.usage, + rbuf->domain); + rbuf->cs_buf = + r300screen->rws->buffer_get_cs_handle(r300screen->rws, rbuf->buf); + + if (!rbuf->buf) { + util_slab_free(&r300screen->pool_buffers, rbuf); + return NULL; + } + + return &rbuf->b.b; +} + +struct pipe_resource *r300_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned bind) +{ + struct r300_screen *r300screen = r300_screen(screen); + struct r300_buffer *rbuf; + + rbuf = util_slab_alloc(&r300screen->pool_buffers); + + rbuf->magic = R300_BUFFER_MAGIC; + + pipe_reference_init(&rbuf->b.b.reference, 1); + rbuf->b.vtbl = &r300_buffer_vtbl; + rbuf->b.b.screen = screen; + rbuf->b.b.target = PIPE_BUFFER; + rbuf->b.b.format = PIPE_FORMAT_R8_UNORM; + rbuf->b.b.usage = PIPE_USAGE_IMMUTABLE; + rbuf->b.b.bind = bind; + rbuf->b.b.width0 = bytes; + rbuf->b.b.height0 = 1; + rbuf->b.b.depth0 = 1; + rbuf->b.b.array_size = 1; + rbuf->b.b.flags = 0; + rbuf->domain = R300_DOMAIN_GTT; + rbuf->num_ranges = 0; + rbuf->buf = NULL; + rbuf->constant_buffer = NULL; + rbuf->user_buffer = ptr; + return &rbuf->b.b; +} diff --git a/src/gallium/drivers/r300/r300_screen_buffer.h b/src/gallium/drivers/r300/r300_screen_buffer.h new file mode 100644 index 0000000..0b3555d --- /dev/null +++ b/src/gallium/drivers/r300/r300_screen_buffer.h @@ -0,0 +1,98 @@ +/* + * Copyright 2010 Red Hat 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 + * 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. + * + * Authors: Dave Airlie + */ + +#ifndef R300_SCREEN_BUFFER_H +#define R300_SCREEN_BUFFER_H + +#include +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "util/u_transfer.h" + +#include "r300_screen.h" +#include "r300_winsys.h" +#include "r300_context.h" + +#define R300_BUFFER_MAGIC 0xabcd1234 +#define R300_BUFFER_MAX_RANGES 32 + +struct r300_buffer_range { + uint32_t start; + uint32_t end; +}; + +/* Vertex buffer. */ +struct r300_buffer +{ + struct u_resource b; + + uint32_t magic; + + struct r300_winsys_buffer *buf; + struct r300_winsys_cs_buffer *cs_buf; + + enum r300_buffer_domain domain; + + uint8_t *user_buffer; + uint8_t *constant_buffer; + struct r300_buffer_range ranges[R300_BUFFER_MAX_RANGES]; + unsigned num_ranges; +}; + +/* Functions. */ + +int r300_upload_user_buffers(struct r300_context *r300); + +int r300_upload_index_buffer(struct r300_context *r300, + struct pipe_resource **index_buffer, + unsigned index_size, + unsigned start, + unsigned count, unsigned *out_offset); + +struct pipe_resource *r300_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *templ); + +struct pipe_resource *r300_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage); + +unsigned r300_buffer_is_referenced(struct pipe_context *context, + struct pipe_resource *buf, + enum r300_reference_domain domain); + +/* Inline functions. */ + +static INLINE struct r300_buffer *r300_buffer(struct pipe_resource *buffer) +{ + return (struct r300_buffer *)buffer; +} + +static INLINE boolean r300_buffer_is_user_buffer(struct pipe_resource *buffer) +{ + return r300_buffer(buffer)->user_buffer ? true : false; +} + +#endif diff --git a/src/gallium/drivers/r300/r300_shader_semantics.h b/src/gallium/drivers/r300/r300_shader_semantics.h new file mode 100644 index 0000000..4be23e6 --- /dev/null +++ b/src/gallium/drivers/r300/r300_shader_semantics.h @@ -0,0 +1,68 @@ +/* + * Copyright 2009 Marek Olšák + * + * 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 R300_SHADER_SEMANTICS_H +#define R300_SHADER_SEMANTICS_H + +#define ATTR_UNUSED (-1) +#define ATTR_COLOR_COUNT 2 +#define ATTR_GENERIC_COUNT 32 + +/* This structure contains information about what attributes are written by VS + * or read by FS. (but not both) It's much easier to work with than + * tgsi_shader_info. + * + * The variables contain indices to tgsi_shader_info semantics and those + * indices are nothing else than input/output register numbers. */ +struct r300_shader_semantics { + int pos; + int psize; + int color[ATTR_COLOR_COUNT]; + int bcolor[ATTR_COLOR_COUNT]; + int face; + int generic[ATTR_GENERIC_COUNT]; + int fog; + int wpos; +}; + +static INLINE void r300_shader_semantics_reset( + struct r300_shader_semantics* info) +{ + int i; + + info->pos = ATTR_UNUSED; + info->psize = ATTR_UNUSED; + info->face = ATTR_UNUSED; + info->fog = ATTR_UNUSED; + info->wpos = ATTR_UNUSED; + + for (i = 0; i < ATTR_COLOR_COUNT; i++) { + info->color[i] = ATTR_UNUSED; + info->bcolor[i] = ATTR_UNUSED; + } + + for (i = 0; i < ATTR_GENERIC_COUNT; i++) { + info->generic[i] = ATTR_UNUSED; + } +} + +#endif diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c new file mode 100644 index 0000000..f902db5 --- /dev/null +++ b/src/gallium/drivers/r300/r300_state.c @@ -0,0 +1,1917 @@ +/* + * Copyright 2008 Corbin Simpson + * Copyright 2009 Marek Olšák + * + * 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 "draw/draw_context.h" + +#include "util/u_framebuffer.h" +#include "util/u_math.h" +#include "util/u_mm.h" +#include "util/u_memory.h" +#include "util/u_pack_color.h" + +#include "tgsi/tgsi_parse.h" + +#include "pipe/p_config.h" + +#include "r300_cb.h" +#include "r300_context.h" +#include "r300_emit.h" +#include "r300_reg.h" +#include "r300_screen.h" +#include "r300_screen_buffer.h" +#include "r300_state_inlines.h" +#include "r300_fs.h" +#include "r300_texture.h" +#include "r300_vs.h" +#include "r300_winsys.h" +#include "r300_hyperz.h" + +/* r300_state: Functions used to intialize state context by translating + * Gallium state objects into semi-native r300 state objects. */ + +#define UPDATE_STATE(cso, atom) \ + if (cso != atom.state) { \ + atom.state = cso; \ + r300_mark_atom_dirty(r300, &(atom)); \ + } + +static boolean blend_discard_if_src_alpha_0(unsigned srcRGB, unsigned srcA, + unsigned dstRGB, unsigned dstA) +{ + /* If the blend equation is ADD or REVERSE_SUBTRACT, + * SRC_ALPHA == 0, and the following state is set, the colorbuffer + * will not be changed. + * Notice that the dst factors are the src factors inverted. */ + return (srcRGB == PIPE_BLENDFACTOR_SRC_ALPHA || + srcRGB == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE || + srcRGB == PIPE_BLENDFACTOR_ZERO) && + (srcA == PIPE_BLENDFACTOR_SRC_COLOR || + srcA == PIPE_BLENDFACTOR_SRC_ALPHA || + srcA == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE || + srcA == PIPE_BLENDFACTOR_ZERO) && + (dstRGB == PIPE_BLENDFACTOR_INV_SRC_ALPHA || + dstRGB == PIPE_BLENDFACTOR_ONE) && + (dstA == PIPE_BLENDFACTOR_INV_SRC_COLOR || + dstA == PIPE_BLENDFACTOR_INV_SRC_ALPHA || + dstA == PIPE_BLENDFACTOR_ONE); +} + +static boolean blend_discard_if_src_alpha_1(unsigned srcRGB, unsigned srcA, + unsigned dstRGB, unsigned dstA) +{ + /* If the blend equation is ADD or REVERSE_SUBTRACT, + * SRC_ALPHA == 1, and the following state is set, the colorbuffer + * will not be changed. + * Notice that the dst factors are the src factors inverted. */ + return (srcRGB == PIPE_BLENDFACTOR_INV_SRC_ALPHA || + srcRGB == PIPE_BLENDFACTOR_ZERO) && + (srcA == PIPE_BLENDFACTOR_INV_SRC_COLOR || + srcA == PIPE_BLENDFACTOR_INV_SRC_ALPHA || + srcA == PIPE_BLENDFACTOR_ZERO) && + (dstRGB == PIPE_BLENDFACTOR_SRC_ALPHA || + dstRGB == PIPE_BLENDFACTOR_ONE) && + (dstA == PIPE_BLENDFACTOR_SRC_COLOR || + dstA == PIPE_BLENDFACTOR_SRC_ALPHA || + dstA == PIPE_BLENDFACTOR_ONE); +} + +static boolean blend_discard_if_src_color_0(unsigned srcRGB, unsigned srcA, + unsigned dstRGB, unsigned dstA) +{ + /* If the blend equation is ADD or REVERSE_SUBTRACT, + * SRC_COLOR == (0,0,0), and the following state is set, the colorbuffer + * will not be changed. + * Notice that the dst factors are the src factors inverted. */ + return (srcRGB == PIPE_BLENDFACTOR_SRC_COLOR || + srcRGB == PIPE_BLENDFACTOR_ZERO) && + (srcA == PIPE_BLENDFACTOR_ZERO) && + (dstRGB == PIPE_BLENDFACTOR_INV_SRC_COLOR || + dstRGB == PIPE_BLENDFACTOR_ONE) && + (dstA == PIPE_BLENDFACTOR_ONE); +} + +static boolean blend_discard_if_src_color_1(unsigned srcRGB, unsigned srcA, + unsigned dstRGB, unsigned dstA) +{ + /* If the blend equation is ADD or REVERSE_SUBTRACT, + * SRC_COLOR == (1,1,1), and the following state is set, the colorbuffer + * will not be changed. + * Notice that the dst factors are the src factors inverted. */ + return (srcRGB == PIPE_BLENDFACTOR_INV_SRC_COLOR || + srcRGB == PIPE_BLENDFACTOR_ZERO) && + (srcA == PIPE_BLENDFACTOR_ZERO) && + (dstRGB == PIPE_BLENDFACTOR_SRC_COLOR || + dstRGB == PIPE_BLENDFACTOR_ONE) && + (dstA == PIPE_BLENDFACTOR_ONE); +} + +static boolean blend_discard_if_src_alpha_color_0(unsigned srcRGB, unsigned srcA, + unsigned dstRGB, unsigned dstA) +{ + /* If the blend equation is ADD or REVERSE_SUBTRACT, + * SRC_ALPHA_COLOR == (0,0,0,0), and the following state is set, + * the colorbuffer will not be changed. + * Notice that the dst factors are the src factors inverted. */ + return (srcRGB == PIPE_BLENDFACTOR_SRC_COLOR || + srcRGB == PIPE_BLENDFACTOR_SRC_ALPHA || + srcRGB == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE || + srcRGB == PIPE_BLENDFACTOR_ZERO) && + (srcA == PIPE_BLENDFACTOR_SRC_COLOR || + srcA == PIPE_BLENDFACTOR_SRC_ALPHA || + srcA == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE || + srcA == PIPE_BLENDFACTOR_ZERO) && + (dstRGB == PIPE_BLENDFACTOR_INV_SRC_COLOR || + dstRGB == PIPE_BLENDFACTOR_INV_SRC_ALPHA || + dstRGB == PIPE_BLENDFACTOR_ONE) && + (dstA == PIPE_BLENDFACTOR_INV_SRC_COLOR || + dstA == PIPE_BLENDFACTOR_INV_SRC_ALPHA || + dstA == PIPE_BLENDFACTOR_ONE); +} + +static boolean blend_discard_if_src_alpha_color_1(unsigned srcRGB, unsigned srcA, + unsigned dstRGB, unsigned dstA) +{ + /* If the blend equation is ADD or REVERSE_SUBTRACT, + * SRC_ALPHA_COLOR == (1,1,1,1), and the following state is set, + * the colorbuffer will not be changed. + * Notice that the dst factors are the src factors inverted. */ + return (srcRGB == PIPE_BLENDFACTOR_INV_SRC_COLOR || + srcRGB == PIPE_BLENDFACTOR_INV_SRC_ALPHA || + srcRGB == PIPE_BLENDFACTOR_ZERO) && + (srcA == PIPE_BLENDFACTOR_INV_SRC_COLOR || + srcA == PIPE_BLENDFACTOR_INV_SRC_ALPHA || + srcA == PIPE_BLENDFACTOR_ZERO) && + (dstRGB == PIPE_BLENDFACTOR_SRC_COLOR || + dstRGB == PIPE_BLENDFACTOR_SRC_ALPHA || + dstRGB == PIPE_BLENDFACTOR_ONE) && + (dstA == PIPE_BLENDFACTOR_SRC_COLOR || + dstA == PIPE_BLENDFACTOR_SRC_ALPHA || + dstA == PIPE_BLENDFACTOR_ONE); +} + +static unsigned bgra_cmask(unsigned mask) +{ + /* Gallium uses RGBA color ordering while R300 expects BGRA. */ + + return ((mask & PIPE_MASK_R) << 2) | + ((mask & PIPE_MASK_B) >> 2) | + (mask & (PIPE_MASK_G | PIPE_MASK_A)); +} + +/* Create a new blend state based on the CSO blend state. + * + * This encompasses alpha blending, logic/raster ops, and blend dithering. */ +static void* r300_create_blend_state(struct pipe_context* pipe, + const struct pipe_blend_state* state) +{ + struct r300_screen* r300screen = r300_screen(pipe->screen); + struct r300_blend_state* blend = CALLOC_STRUCT(r300_blend_state); + uint32_t blend_control = 0; /* R300_RB3D_CBLEND: 0x4e04 */ + uint32_t alpha_blend_control = 0; /* R300_RB3D_ABLEND: 0x4e08 */ + uint32_t color_channel_mask = 0; /* R300_RB3D_COLOR_CHANNEL_MASK: 0x4e0c */ + uint32_t rop = 0; /* R300_RB3D_ROPCNTL: 0x4e18 */ + uint32_t dither = 0; /* R300_RB3D_DITHER_CTL: 0x4e50 */ + CB_LOCALS; + + if (state->rt[0].blend_enable) + { + unsigned eqRGB = state->rt[0].rgb_func; + unsigned srcRGB = state->rt[0].rgb_src_factor; + unsigned dstRGB = state->rt[0].rgb_dst_factor; + + unsigned eqA = state->rt[0].alpha_func; + unsigned srcA = state->rt[0].alpha_src_factor; + unsigned dstA = state->rt[0].alpha_dst_factor; + + /* despite the name, ALPHA_BLEND_ENABLE has nothing to do with alpha, + * this is just the crappy D3D naming */ + blend_control = R300_ALPHA_BLEND_ENABLE | + r300_translate_blend_function(eqRGB) | + ( r300_translate_blend_factor(srcRGB) << R300_SRC_BLEND_SHIFT) | + ( r300_translate_blend_factor(dstRGB) << R300_DST_BLEND_SHIFT); + + /* Optimization: some operations do not require the destination color. + * + * When SRC_ALPHA_SATURATE is used, colorbuffer reads must be enabled, + * otherwise blending gives incorrect results. It seems to be + * a hardware bug. */ + if (eqRGB == PIPE_BLEND_MIN || eqA == PIPE_BLEND_MIN || + eqRGB == PIPE_BLEND_MAX || eqA == PIPE_BLEND_MAX || + dstRGB != PIPE_BLENDFACTOR_ZERO || + dstA != PIPE_BLENDFACTOR_ZERO || + srcRGB == PIPE_BLENDFACTOR_DST_COLOR || + srcRGB == PIPE_BLENDFACTOR_DST_ALPHA || + srcRGB == PIPE_BLENDFACTOR_INV_DST_COLOR || + srcRGB == PIPE_BLENDFACTOR_INV_DST_ALPHA || + srcA == PIPE_BLENDFACTOR_DST_COLOR || + srcA == PIPE_BLENDFACTOR_DST_ALPHA || + srcA == PIPE_BLENDFACTOR_INV_DST_COLOR || + srcA == PIPE_BLENDFACTOR_INV_DST_ALPHA || + srcRGB == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE) { + /* Enable reading from the colorbuffer. */ + blend_control |= R300_READ_ENABLE; + + if (r300screen->caps.is_r500) { + /* Optimization: Depending on incoming pixels, we can + * conditionally disable the reading in hardware... */ + if (eqRGB != PIPE_BLEND_MIN && eqA != PIPE_BLEND_MIN && + eqRGB != PIPE_BLEND_MAX && eqA != PIPE_BLEND_MAX) { + /* Disable reading if SRC_ALPHA == 0. */ + if ((dstRGB == PIPE_BLENDFACTOR_SRC_ALPHA || + dstRGB == PIPE_BLENDFACTOR_ZERO) && + (dstA == PIPE_BLENDFACTOR_SRC_COLOR || + dstA == PIPE_BLENDFACTOR_SRC_ALPHA || + dstA == PIPE_BLENDFACTOR_ZERO)) { + blend_control |= R500_SRC_ALPHA_0_NO_READ; + } + + /* Disable reading if SRC_ALPHA == 1. */ + if ((dstRGB == PIPE_BLENDFACTOR_INV_SRC_ALPHA || + dstRGB == PIPE_BLENDFACTOR_ZERO) && + (dstA == PIPE_BLENDFACTOR_INV_SRC_COLOR || + dstA == PIPE_BLENDFACTOR_INV_SRC_ALPHA || + dstA == PIPE_BLENDFACTOR_ZERO)) { + blend_control |= R500_SRC_ALPHA_1_NO_READ; + } + } + } + } + + /* Optimization: discard pixels which don't change the colorbuffer. + * + * The code below is non-trivial and some math is involved. + * + * Discarding pixels must be disabled when FP16 AA is enabled. + * This is a hardware bug. Also, this implementation wouldn't work + * with FP blending enabled and equation clamping disabled. + * + * Equations other than ADD are rarely used and therefore won't be + * optimized. */ + if ((eqRGB == PIPE_BLEND_ADD || eqRGB == PIPE_BLEND_REVERSE_SUBTRACT) && + (eqA == PIPE_BLEND_ADD || eqA == PIPE_BLEND_REVERSE_SUBTRACT)) { + /* ADD: X+Y + * REVERSE_SUBTRACT: Y-X + * + * The idea is: + * If X = src*srcFactor = 0 and Y = dst*dstFactor = 1, + * then CB will not be changed. + * + * Given the srcFactor and dstFactor variables, we can derive + * what src and dst should be equal to and discard appropriate + * pixels. + */ + if (blend_discard_if_src_alpha_0(srcRGB, srcA, dstRGB, dstA)) { + blend_control |= R300_DISCARD_SRC_PIXELS_SRC_ALPHA_0; + } else if (blend_discard_if_src_alpha_1(srcRGB, srcA, + dstRGB, dstA)) { + blend_control |= R300_DISCARD_SRC_PIXELS_SRC_ALPHA_1; + } else if (blend_discard_if_src_color_0(srcRGB, srcA, + dstRGB, dstA)) { + blend_control |= R300_DISCARD_SRC_PIXELS_SRC_COLOR_0; + } else if (blend_discard_if_src_color_1(srcRGB, srcA, + dstRGB, dstA)) { + blend_control |= R300_DISCARD_SRC_PIXELS_SRC_COLOR_1; + } else if (blend_discard_if_src_alpha_color_0(srcRGB, srcA, + dstRGB, dstA)) { + blend_control |= + R300_DISCARD_SRC_PIXELS_SRC_ALPHA_COLOR_0; + } else if (blend_discard_if_src_alpha_color_1(srcRGB, srcA, + dstRGB, dstA)) { + blend_control |= + R300_DISCARD_SRC_PIXELS_SRC_ALPHA_COLOR_1; + } + } + + /* separate alpha */ + if (srcA != srcRGB || dstA != dstRGB || eqA != eqRGB) { + blend_control |= R300_SEPARATE_ALPHA_ENABLE; + alpha_blend_control = + r300_translate_blend_function(eqA) | + (r300_translate_blend_factor(srcA) << R300_SRC_BLEND_SHIFT) | + (r300_translate_blend_factor(dstA) << R300_DST_BLEND_SHIFT); + } + } + + /* PIPE_LOGICOP_* don't need to be translated, fortunately. */ + if (state->logicop_enable) { + rop = R300_RB3D_ROPCNTL_ROP_ENABLE | + (state->logicop_func) << R300_RB3D_ROPCNTL_ROP_SHIFT; + } + + /* Color channel masks for all MRTs. */ + color_channel_mask = bgra_cmask(state->rt[0].colormask); + if (r300screen->caps.is_r500 && state->independent_blend_enable) { + if (state->rt[1].blend_enable) { + color_channel_mask |= bgra_cmask(state->rt[1].colormask) << 4; + } + if (state->rt[2].blend_enable) { + color_channel_mask |= bgra_cmask(state->rt[2].colormask) << 8; + } + if (state->rt[3].blend_enable) { + color_channel_mask |= bgra_cmask(state->rt[3].colormask) << 12; + } + } + + /* Neither fglrx nor classic r300 ever set this, regardless of dithering + * state. Since it's an optional implementation detail, we can leave it + * out and never dither. + * + * This could be revisited if we ever get quality or conformance hints. + * + if (state->dither) { + dither = R300_RB3D_DITHER_CTL_DITHER_MODE_LUT | + R300_RB3D_DITHER_CTL_ALPHA_DITHER_MODE_LUT; + } + */ + + /* Build a command buffer. */ + BEGIN_CB(blend->cb, 8); + OUT_CB_REG(R300_RB3D_ROPCNTL, rop); + OUT_CB_REG_SEQ(R300_RB3D_CBLEND, 3); + OUT_CB(blend_control); + OUT_CB(alpha_blend_control); + OUT_CB(color_channel_mask); + OUT_CB_REG(R300_RB3D_DITHER_CTL, dither); + END_CB; + + /* The same as above, but with no colorbuffer reads and writes. */ + BEGIN_CB(blend->cb_no_readwrite, 8); + OUT_CB_REG(R300_RB3D_ROPCNTL, rop); + OUT_CB_REG_SEQ(R300_RB3D_CBLEND, 3); + OUT_CB(0); + OUT_CB(0); + OUT_CB(0); + OUT_CB_REG(R300_RB3D_DITHER_CTL, dither); + END_CB; + + return (void*)blend; +} + +/* Bind blend state. */ +static void r300_bind_blend_state(struct pipe_context* pipe, + void* state) +{ + struct r300_context* r300 = r300_context(pipe); + + UPDATE_STATE(state, r300->blend_state); +} + +/* Free blend state. */ +static void r300_delete_blend_state(struct pipe_context* pipe, + void* state) +{ + FREE(state); +} + +/* Convert float to 10bit integer */ +static unsigned float_to_fixed10(float f) +{ + return CLAMP((unsigned)(f * 1023.9f), 0, 1023); +} + +/* Set blend color. + * Setup both R300 and R500 registers, figure out later which one to write. */ +static void r300_set_blend_color(struct pipe_context* pipe, + const struct pipe_blend_color* color) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_blend_color_state* state = + (struct r300_blend_color_state*)r300->blend_color_state.state; + CB_LOCALS; + + if (r300->screen->caps.is_r500) { + /* XXX if FP16 blending is enabled, we should use the FP16 format */ + BEGIN_CB(state->cb, 3); + OUT_CB_REG_SEQ(R500_RB3D_CONSTANT_COLOR_AR, 2); + OUT_CB(float_to_fixed10(color->color[0]) | + (float_to_fixed10(color->color[3]) << 16)); + OUT_CB(float_to_fixed10(color->color[2]) | + (float_to_fixed10(color->color[1]) << 16)); + END_CB; + } else { + union util_color uc; + util_pack_color(color->color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); + + BEGIN_CB(state->cb, 2); + OUT_CB_REG(R300_RB3D_BLEND_COLOR, uc.ui); + END_CB; + } + + r300_mark_atom_dirty(r300, &r300->blend_color_state); +} + +static void r300_set_clip_state(struct pipe_context* pipe, + const struct pipe_clip_state* state) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_clip_state *clip = + (struct r300_clip_state*)r300->clip_state.state; + CB_LOCALS; + + clip->clip = *state; + + if (r300->screen->caps.has_tcl) { + r300->clip_state.size = 2 + !!state->nr * 3 + state->nr * 4; + + BEGIN_CB(clip->cb, r300->clip_state.size); + if (state->nr) { + OUT_CB_REG(R300_VAP_PVS_VECTOR_INDX_REG, + (r300->screen->caps.is_r500 ? + R500_PVS_UCP_START : R300_PVS_UCP_START)); + OUT_CB_ONE_REG(R300_VAP_PVS_UPLOAD_DATA, state->nr * 4); + OUT_CB_TABLE(state->ucp, state->nr * 4); + } + OUT_CB_REG(R300_VAP_CLIP_CNTL, ((1 << state->nr) - 1) | + R300_PS_UCP_MODE_CLIP_AS_TRIFAN | + (state->depth_clamp ? R300_CLIP_DISABLE : 0)); + END_CB; + + r300_mark_atom_dirty(r300, &r300->clip_state); + } else { + draw_set_clip_state(r300->draw, state); + } +} + +static void +r300_set_sample_mask(struct pipe_context *pipe, + unsigned sample_mask) +{ +} + + +/* Create a new depth, stencil, and alpha state based on the CSO dsa state. + * + * This contains the depth buffer, stencil buffer, alpha test, and such. + * On the Radeon, depth and stencil buffer setup are intertwined, which is + * the reason for some of the strange-looking assignments across registers. */ +static void* + r300_create_dsa_state(struct pipe_context* pipe, + const struct pipe_depth_stencil_alpha_state* state) +{ + struct r300_capabilities *caps = &r300_screen(pipe->screen)->caps; + struct r300_dsa_state* dsa = CALLOC_STRUCT(r300_dsa_state); + CB_LOCALS; + + dsa->dsa = *state; + + /* Depth test setup. - separate write mask depth for decomp flush */ + if (state->depth.writemask) { + dsa->z_buffer_control |= R300_Z_WRITE_ENABLE; + } + + if (state->depth.enabled) { + dsa->z_buffer_control |= R300_Z_ENABLE; + + dsa->z_stencil_control |= + (r300_translate_depth_stencil_function(state->depth.func) << + R300_Z_FUNC_SHIFT); + } + + /* Stencil buffer setup. */ + if (state->stencil[0].enabled) { + dsa->z_buffer_control |= R300_STENCIL_ENABLE; + dsa->z_stencil_control |= + (r300_translate_depth_stencil_function(state->stencil[0].func) << + R300_S_FRONT_FUNC_SHIFT) | + (r300_translate_stencil_op(state->stencil[0].fail_op) << + R300_S_FRONT_SFAIL_OP_SHIFT) | + (r300_translate_stencil_op(state->stencil[0].zpass_op) << + R300_S_FRONT_ZPASS_OP_SHIFT) | + (r300_translate_stencil_op(state->stencil[0].zfail_op) << + R300_S_FRONT_ZFAIL_OP_SHIFT); + + dsa->stencil_ref_mask = + (state->stencil[0].valuemask << R300_STENCILMASK_SHIFT) | + (state->stencil[0].writemask << R300_STENCILWRITEMASK_SHIFT); + + if (state->stencil[1].enabled) { + dsa->two_sided = TRUE; + + dsa->z_buffer_control |= R300_STENCIL_FRONT_BACK; + dsa->z_stencil_control |= + (r300_translate_depth_stencil_function(state->stencil[1].func) << + R300_S_BACK_FUNC_SHIFT) | + (r300_translate_stencil_op(state->stencil[1].fail_op) << + R300_S_BACK_SFAIL_OP_SHIFT) | + (r300_translate_stencil_op(state->stencil[1].zpass_op) << + R300_S_BACK_ZPASS_OP_SHIFT) | + (r300_translate_stencil_op(state->stencil[1].zfail_op) << + R300_S_BACK_ZFAIL_OP_SHIFT); + + dsa->stencil_ref_bf = + (state->stencil[1].valuemask << R300_STENCILMASK_SHIFT) | + (state->stencil[1].writemask << R300_STENCILWRITEMASK_SHIFT); + + if (caps->is_r500) { + dsa->z_buffer_control |= R500_STENCIL_REFMASK_FRONT_BACK; + } else { + dsa->two_sided_stencil_ref = + (state->stencil[0].valuemask != state->stencil[1].valuemask || + state->stencil[0].writemask != state->stencil[1].writemask); + } + } + } + + /* Alpha test setup. */ + if (state->alpha.enabled) { + dsa->alpha_function = + r300_translate_alpha_function(state->alpha.func) | + R300_FG_ALPHA_FUNC_ENABLE; + + /* We could use 10bit alpha ref but who needs that? */ + dsa->alpha_function |= float_to_ubyte(state->alpha.ref_value); + + if (caps->is_r500) + dsa->alpha_function |= R500_FG_ALPHA_FUNC_8BIT; + } + + BEGIN_CB(&dsa->cb_begin, 8); + OUT_CB_REG(R300_FG_ALPHA_FUNC, dsa->alpha_function); + OUT_CB_REG_SEQ(R300_ZB_CNTL, 3); + OUT_CB(dsa->z_buffer_control); + OUT_CB(dsa->z_stencil_control); + OUT_CB(dsa->stencil_ref_mask); + OUT_CB_REG(R500_ZB_STENCILREFMASK_BF, dsa->stencil_ref_bf); + END_CB; + + BEGIN_CB(dsa->cb_no_readwrite, 8); + OUT_CB_REG(R300_FG_ALPHA_FUNC, dsa->alpha_function); + OUT_CB_REG_SEQ(R300_ZB_CNTL, 3); + OUT_CB(0); + OUT_CB(0); + OUT_CB(0); + OUT_CB_REG(R500_ZB_STENCILREFMASK_BF, 0); + END_CB; + + return (void*)dsa; +} + +static void r300_dsa_inject_stencilref(struct r300_context *r300) +{ + struct r300_dsa_state *dsa = + (struct r300_dsa_state*)r300->dsa_state.state; + + if (!dsa) + return; + + dsa->stencil_ref_mask = + (dsa->stencil_ref_mask & ~R300_STENCILREF_MASK) | + r300->stencil_ref.ref_value[0]; + dsa->stencil_ref_bf = + (dsa->stencil_ref_bf & ~R300_STENCILREF_MASK) | + r300->stencil_ref.ref_value[1]; +} + +/* Bind DSA state. */ +static void r300_bind_dsa_state(struct pipe_context* pipe, + void* state) +{ + struct r300_context* r300 = r300_context(pipe); + + if (!state) { + return; + } + + UPDATE_STATE(state, r300->dsa_state); + + r300_mark_atom_dirty(r300, &r300->hyperz_state); /* Will be updated before the emission. */ + r300_dsa_inject_stencilref(r300); +} + +/* Free DSA state. */ +static void r300_delete_dsa_state(struct pipe_context* pipe, + void* state) +{ + FREE(state); +} + +static void r300_set_stencil_ref(struct pipe_context* pipe, + const struct pipe_stencil_ref* sr) +{ + struct r300_context* r300 = r300_context(pipe); + + r300->stencil_ref = *sr; + + r300_dsa_inject_stencilref(r300); + r300_mark_atom_dirty(r300, &r300->dsa_state); +} + +static void r300_tex_set_tiling_flags(struct r300_context *r300, + struct r300_texture *tex, unsigned level) +{ + /* Check if the macrotile flag needs to be changed. + * Skip changing the flags otherwise. */ + if (tex->desc.macrotile[tex->surface_level] != + tex->desc.macrotile[level]) { + /* Tiling determines how DRM treats the buffer data. + * We must flush CS when changing it if the buffer is referenced. */ + if (r300->rws->cs_is_buffer_referenced(r300->cs, + tex->cs_buffer, R300_REF_CS)) + r300->context.flush(&r300->context, 0, NULL); + + r300->rws->buffer_set_tiling(r300->rws, tex->buffer, + tex->desc.microtile, tex->desc.macrotile[level], + tex->desc.stride_in_bytes[0]); + + tex->surface_level = level; + } +} + +/* This switcheroo is needed just because of goddamned MACRO_SWITCH. */ +static void r300_fb_set_tiling_flags(struct r300_context *r300, + const struct pipe_framebuffer_state *state) +{ + unsigned i; + + /* Set tiling flags for new surfaces. */ + for (i = 0; i < state->nr_cbufs; i++) { + r300_tex_set_tiling_flags(r300, + r300_texture(state->cbufs[i]->texture), + state->cbufs[i]->u.tex.level); + } + if (state->zsbuf) { + r300_tex_set_tiling_flags(r300, + r300_texture(state->zsbuf->texture), + state->zsbuf->u.tex.level); + } +} + +static void r300_print_fb_surf_info(struct pipe_surface *surf, unsigned index, + const char *binding) +{ + struct pipe_resource *tex = surf->texture; + struct r300_texture *rtex = r300_texture(tex); + + fprintf(stderr, + "r300: %s[%i] Dim: %ix%i, Firstlayer: %i, " + "Lastlayer: %i, Level: %i, Format: %s\n" + + "r300: TEX: Macro: %s, Micro: %s, Pitch: %i, " + "Dim: %ix%ix%i, LastLevel: %i, Format: %s\n", + + binding, index, surf->width, surf->height, + surf->u.tex.first_layer, surf->u.tex.last_layer, surf->u.tex.level, + util_format_short_name(surf->format), + + rtex->desc.macrotile[0] ? "YES" : " NO", + rtex->desc.microtile ? "YES" : " NO", + rtex->desc.stride_in_pixels[0], + tex->width0, tex->height0, tex->depth0, + tex->last_level, util_format_short_name(tex->format)); +} + +void r300_mark_fb_state_dirty(struct r300_context *r300, + enum r300_fb_state_change change) +{ + struct pipe_framebuffer_state *state = r300->fb_state.state; + boolean can_hyperz = r300->rws->get_value(r300->rws, R300_CAN_HYPERZ); + + /* What is marked as dirty depends on the enum r300_fb_state_change. */ + r300_mark_atom_dirty(r300, &r300->gpu_flush); + r300_mark_atom_dirty(r300, &r300->fb_state); + r300_mark_atom_dirty(r300, &r300->hyperz_state); + + if (change == R300_CHANGED_FB_STATE) { + r300_mark_atom_dirty(r300, &r300->aa_state); + r300_mark_atom_dirty(r300, &r300->fb_state_pipelined); + } + + /* Now compute the fb_state atom size. */ + r300->fb_state.size = 2 + (8 * state->nr_cbufs); + + if (r300->cbzb_clear) + r300->fb_state.size += 10; + else if (state->zsbuf) { + r300->fb_state.size += 10; + if (can_hyperz) + r300->fb_state.size += r300->screen->caps.hiz_ram ? 8 : 4; + } + + /* The size of the rest of atoms stays the same. */ +} + +static void + r300_set_framebuffer_state(struct pipe_context* pipe, + const struct pipe_framebuffer_state* state) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_aa_state *aa = (struct r300_aa_state*)r300->aa_state.state; + struct pipe_framebuffer_state *old_state = r300->fb_state.state; + boolean can_hyperz = r300->rws->get_value(r300->rws, R300_CAN_HYPERZ); + unsigned max_width, max_height, i; + uint32_t zbuffer_bpp = 0; + int blocksize; + + if (r300->screen->caps.is_r500) { + max_width = max_height = 4096; + } else if (r300->screen->caps.is_r400) { + max_width = max_height = 4021; + } else { + max_width = max_height = 2560; + } + + if (state->width > max_width || state->height > max_height) { + fprintf(stderr, "r300: Implementation error: Render targets are too " + "big in %s, refusing to bind framebuffer state!\n", __FUNCTION__); + return; + } + + /* If nr_cbufs is changed from zero to non-zero or vice versa... */ + if (!!old_state->nr_cbufs != !!state->nr_cbufs) { + r300_mark_atom_dirty(r300, &r300->blend_state); + } + /* If zsbuf is set from NULL to non-NULL or vice versa.. */ + if (!!old_state->zsbuf != !!state->zsbuf) { + r300_mark_atom_dirty(r300, &r300->dsa_state); + } + + /* The tiling flags are dependent on the surface miplevel, unfortunately. */ + r300_fb_set_tiling_flags(r300, state); + + util_copy_framebuffer_state(r300->fb_state.state, state); + + r300_mark_fb_state_dirty(r300, R300_CHANGED_FB_STATE); + r300->validate_buffers = TRUE; + + r300->z_compression = false; + + if (state->zsbuf) { + blocksize = util_format_get_blocksize(state->zsbuf->texture->format); + switch (blocksize) { + case 2: + zbuffer_bpp = 16; + break; + case 4: + zbuffer_bpp = 24; + break; + } + if (can_hyperz) { + struct r300_surface *zs_surf = r300_surface(state->zsbuf); + struct r300_texture *tex; + int compress = r300->screen->caps.is_rv350 ? RV350_Z_COMPRESS_88 : R300_Z_COMPRESS_44; + int level = zs_surf->base.u.tex.level; + + tex = r300_texture(zs_surf->base.texture); + + /* work out whether we can support hiz on this buffer */ + r300_hiz_alloc_block(r300, zs_surf); + + /* work out whether we can support zmask features on this buffer */ + r300_zmask_alloc_block(r300, zs_surf, compress); + + if (tex->zmask_mem[level]) { + /* compression causes hangs on 16-bit */ + if (zbuffer_bpp == 24) + r300->z_compression = compress; + } + DBG(r300, DBG_HYPERZ, + "hyper-z features: hiz: %d @ %08x z-compression: %d z-fastfill: %d @ %08x\n", tex->hiz_mem[level] ? 1 : 0, + tex->hiz_mem[level] ? tex->hiz_mem[level]->ofs : 0xdeadbeef, + r300->z_compression, tex->zmask_mem[level] ? 1 : 0, + tex->zmask_mem[level] ? tex->zmask_mem[level]->ofs : 0xdeadbeef); + } + + /* Polygon offset depends on the zbuffer bit depth. */ + if (r300->zbuffer_bpp != zbuffer_bpp) { + r300->zbuffer_bpp = zbuffer_bpp; + + if (r300->polygon_offset_enabled) + r300_mark_atom_dirty(r300, &r300->rs_state); + } + } + + /* Set up AA config. */ + if (r300->rws->get_value(r300->rws, R300_VID_DRM_2_3_0)) { + if (state->nr_cbufs && state->cbufs[0]->texture->nr_samples > 1) { + aa->aa_config = R300_GB_AA_CONFIG_AA_ENABLE; + + switch (state->cbufs[0]->texture->nr_samples) { + case 2: + aa->aa_config |= R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_2; + break; + case 3: + aa->aa_config |= R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_3; + break; + case 4: + aa->aa_config |= R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_4; + break; + case 6: + aa->aa_config |= R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_6; + break; + } + } else { + aa->aa_config = 0; + } + } + + if (DBG_ON(r300, DBG_FB)) { + fprintf(stderr, "r300: set_framebuffer_state:\n"); + for (i = 0; i < state->nr_cbufs; i++) { + r300_print_fb_surf_info(state->cbufs[i], i, "CB"); + } + if (state->zsbuf) { + r300_print_fb_surf_info(state->zsbuf, 0, "ZB"); + } + } +} + +/* Create fragment shader state. */ +static void* r300_create_fs_state(struct pipe_context* pipe, + const struct pipe_shader_state* shader) +{ + struct r300_fragment_shader* fs = NULL; + + fs = (struct r300_fragment_shader*)CALLOC_STRUCT(r300_fragment_shader); + + /* Copy state directly into shader. */ + fs->state = *shader; + fs->state.tokens = tgsi_dup_tokens(shader->tokens); + + return (void*)fs; +} + +void r300_mark_fs_code_dirty(struct r300_context *r300) +{ + struct r300_fragment_shader* fs = r300_fs(r300); + + r300_mark_atom_dirty(r300, &r300->fs); + r300_mark_atom_dirty(r300, &r300->fs_rc_constant_state); + r300_mark_atom_dirty(r300, &r300->fs_constants); + r300->fs.size = fs->shader->cb_code_size; + + if (r300->screen->caps.is_r500) { + r300->fs_rc_constant_state.size = fs->shader->rc_state_count * 7; + r300->fs_constants.size = fs->shader->externals_count * 4 + 3; + } else { + r300->fs_rc_constant_state.size = fs->shader->rc_state_count * 5; + r300->fs_constants.size = fs->shader->externals_count * 4 + 1; + } + + ((struct r300_constant_buffer*)r300->fs_constants.state)->remap_table = + fs->shader->code.constants_remap_table; +} + +/* Bind fragment shader state. */ +static void r300_bind_fs_state(struct pipe_context* pipe, void* shader) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_fragment_shader* fs = (struct r300_fragment_shader*)shader; + + if (fs == NULL) { + r300->fs.state = NULL; + return; + } + + r300->fs.state = fs; + r300_pick_fragment_shader(r300); + r300_mark_fs_code_dirty(r300); + + r300_mark_atom_dirty(r300, &r300->rs_block_state); /* Will be updated before the emission. */ +} + +/* Delete fragment shader state. */ +static void r300_delete_fs_state(struct pipe_context* pipe, void* shader) +{ + struct r300_fragment_shader* fs = (struct r300_fragment_shader*)shader; + struct r300_fragment_shader_code *tmp, *ptr = fs->first; + + while (ptr) { + tmp = ptr; + ptr = ptr->next; + rc_constants_destroy(&tmp->code.constants); + FREE(tmp->cb_code); + FREE(tmp); + } + FREE((void*)fs->state.tokens); + FREE(shader); +} + +static void r300_set_polygon_stipple(struct pipe_context* pipe, + const struct pipe_poly_stipple* state) +{ + /* XXX no idea how to set this up, but not terribly important */ +} + +/* Create a new rasterizer state based on the CSO rasterizer state. + * + * This is a very large chunk of state, and covers most of the graphics + * backend (GB), geometry assembly (GA), and setup unit (SU) blocks. + * + * In a not entirely unironic sidenote, this state has nearly nothing to do + * with the actual block on the Radeon called the rasterizer (RS). */ +static void* r300_create_rs_state(struct pipe_context* pipe, + const struct pipe_rasterizer_state* state) +{ + struct r300_rs_state* rs = CALLOC_STRUCT(r300_rs_state); + float psiz; + uint32_t vap_control_status; /* R300_VAP_CNTL_STATUS: 0x2140 */ + uint32_t point_size; /* R300_GA_POINT_SIZE: 0x421c */ + uint32_t point_minmax; /* R300_GA_POINT_MINMAX: 0x4230 */ + uint32_t line_control; /* R300_GA_LINE_CNTL: 0x4234 */ + uint32_t polygon_offset_enable; /* R300_SU_POLY_OFFSET_ENABLE: 0x42b4 */ + uint32_t cull_mode; /* R300_SU_CULL_MODE: 0x42b8 */ + uint32_t line_stipple_config; /* R300_GA_LINE_STIPPLE_CONFIG: 0x4328 */ + uint32_t line_stipple_value; /* R300_GA_LINE_STIPPLE_VALUE: 0x4260 */ + uint32_t polygon_mode; /* R300_GA_POLY_MODE: 0x4288 */ + uint32_t clip_rule; /* R300_SC_CLIP_RULE: 0x43D0 */ + + /* Point sprites texture coordinates, 0: lower left, 1: upper right */ + float point_texcoord_left = 0; /* R300_GA_POINT_S0: 0x4200 */ + float point_texcoord_bottom = 0;/* R300_GA_POINT_T0: 0x4204 */ + float point_texcoord_right = 1; /* R300_GA_POINT_S1: 0x4208 */ + float point_texcoord_top = 0; /* R300_GA_POINT_T1: 0x420c */ + CB_LOCALS; + + /* Copy rasterizer state. */ + rs->rs = *state; + rs->rs_draw = *state; + + rs->rs.sprite_coord_enable = state->point_quad_rasterization * + state->sprite_coord_enable; + + /* Override some states for Draw. */ + rs->rs_draw.sprite_coord_enable = 0; /* We can do this in HW. */ + +#ifdef PIPE_ARCH_LITTLE_ENDIAN + vap_control_status = R300_VC_NO_SWAP; +#else + vap_control_status = R300_VC_32BIT_SWAP; +#endif + + /* If no TCL engine is present, turn off the HW TCL. */ + if (!r300_screen(pipe->screen)->caps.has_tcl) { + vap_control_status |= R300_VAP_TCL_BYPASS; + } + + /* Point size width and height. */ + point_size = + pack_float_16_6x(state->point_size) | + (pack_float_16_6x(state->point_size) << R300_POINTSIZE_X_SHIFT); + + /* Point size clamping. */ + if (state->point_size_per_vertex) { + /* Per-vertex point size. + * Clamp to [0, max FB size] */ + psiz = pipe->screen->get_paramf(pipe->screen, + PIPE_CAP_MAX_POINT_WIDTH); + point_minmax = + pack_float_16_6x(psiz) << R300_GA_POINT_MINMAX_MAX_SHIFT; + } else { + /* We cannot disable the point-size vertex output, + * so clamp it. */ + psiz = state->point_size; + point_minmax = + (pack_float_16_6x(psiz) << R300_GA_POINT_MINMAX_MIN_SHIFT) | + (pack_float_16_6x(psiz) << R300_GA_POINT_MINMAX_MAX_SHIFT); + } + + /* Line control. */ + line_control = pack_float_16_6x(state->line_width) | + R300_GA_LINE_CNTL_END_TYPE_COMP; + + /* Enable polygon mode */ + polygon_mode = 0; + if (state->fill_front != PIPE_POLYGON_MODE_FILL || + state->fill_back != PIPE_POLYGON_MODE_FILL) { + polygon_mode = R300_GA_POLY_MODE_DUAL; + } + + /* Front face */ + if (state->front_ccw) + cull_mode = R300_FRONT_FACE_CCW; + else + cull_mode = R300_FRONT_FACE_CW; + + /* Polygon offset */ + polygon_offset_enable = 0; + if (util_get_offset(state, state->fill_front)) { + polygon_offset_enable |= R300_FRONT_ENABLE; + } + if (util_get_offset(state, state->fill_back)) { + polygon_offset_enable |= R300_BACK_ENABLE; + } + + rs->polygon_offset_enable = polygon_offset_enable != 0; + + /* Polygon mode */ + if (polygon_mode) { + polygon_mode |= + r300_translate_polygon_mode_front(state->fill_front); + polygon_mode |= + r300_translate_polygon_mode_back(state->fill_back); + } + + if (state->cull_face & PIPE_FACE_FRONT) { + cull_mode |= R300_CULL_FRONT; + } + if (state->cull_face & PIPE_FACE_BACK) { + cull_mode |= R300_CULL_BACK; + } + + if (state->line_stipple_enable) { + line_stipple_config = + R300_GA_LINE_STIPPLE_CONFIG_LINE_RESET_LINE | + (fui((float)state->line_stipple_factor) & + R300_GA_LINE_STIPPLE_CONFIG_STIPPLE_SCALE_MASK); + /* XXX this might need to be scaled up */ + line_stipple_value = state->line_stipple_pattern; + } else { + line_stipple_config = 0; + line_stipple_value = 0; + } + + if (state->flatshade) { + rs->color_control = R300_SHADE_MODEL_FLAT; + } else { + rs->color_control = R300_SHADE_MODEL_SMOOTH; + } + + clip_rule = state->scissor ? 0xAAAA : 0xFFFF; + + /* Point sprites coord mode */ + if (rs->rs.sprite_coord_enable) { + switch (state->sprite_coord_mode) { + case PIPE_SPRITE_COORD_UPPER_LEFT: + point_texcoord_top = 0.0f; + point_texcoord_bottom = 1.0f; + break; + case PIPE_SPRITE_COORD_LOWER_LEFT: + point_texcoord_top = 1.0f; + point_texcoord_bottom = 0.0f; + break; + } + } + + /* Build the main command buffer. */ + BEGIN_CB(rs->cb_main, RS_STATE_MAIN_SIZE); + OUT_CB_REG(R300_VAP_CNTL_STATUS, vap_control_status); + OUT_CB_REG(R300_GA_POINT_SIZE, point_size); + OUT_CB_REG_SEQ(R300_GA_POINT_MINMAX, 2); + OUT_CB(point_minmax); + OUT_CB(line_control); + OUT_CB_REG_SEQ(R300_SU_POLY_OFFSET_ENABLE, 2); + OUT_CB(polygon_offset_enable); + rs->cull_mode_index = 9; + OUT_CB(cull_mode); + OUT_CB_REG(R300_GA_LINE_STIPPLE_CONFIG, line_stipple_config); + OUT_CB_REG(R300_GA_LINE_STIPPLE_VALUE, line_stipple_value); + OUT_CB_REG(R300_GA_POLY_MODE, polygon_mode); + OUT_CB_REG(R300_SC_CLIP_RULE, clip_rule); + OUT_CB_REG_SEQ(R300_GA_POINT_S0, 4); + OUT_CB_32F(point_texcoord_left); + OUT_CB_32F(point_texcoord_bottom); + OUT_CB_32F(point_texcoord_right); + OUT_CB_32F(point_texcoord_top); + END_CB; + + /* Build the two command buffers for polygon offset setup. */ + if (polygon_offset_enable) { + float scale = state->offset_scale * 12; + float offset = state->offset_units * 4; + + BEGIN_CB(rs->cb_poly_offset_zb16, 5); + OUT_CB_REG_SEQ(R300_SU_POLY_OFFSET_FRONT_SCALE, 4); + OUT_CB_32F(scale); + OUT_CB_32F(offset); + OUT_CB_32F(scale); + OUT_CB_32F(offset); + END_CB; + + offset = state->offset_units * 2; + + BEGIN_CB(rs->cb_poly_offset_zb24, 5); + OUT_CB_REG_SEQ(R300_SU_POLY_OFFSET_FRONT_SCALE, 4); + OUT_CB_32F(scale); + OUT_CB_32F(offset); + OUT_CB_32F(scale); + OUT_CB_32F(offset); + END_CB; + } + + return (void*)rs; +} + +/* Bind rasterizer state. */ +static void r300_bind_rs_state(struct pipe_context* pipe, void* state) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_rs_state* rs = (struct r300_rs_state*)state; + int last_sprite_coord_enable = r300->sprite_coord_enable; + boolean last_two_sided_color = r300->two_sided_color; + + if (r300->draw && rs) { + draw_set_rasterizer_state(r300->draw, &rs->rs_draw, state); + } + + if (rs) { + r300->polygon_offset_enabled = rs->polygon_offset_enable; + r300->sprite_coord_enable = rs->rs.sprite_coord_enable; + r300->two_sided_color = rs->rs.light_twoside; + } else { + r300->polygon_offset_enabled = FALSE; + r300->sprite_coord_enable = 0; + r300->two_sided_color = FALSE; + } + + UPDATE_STATE(state, r300->rs_state); + r300->rs_state.size = RS_STATE_MAIN_SIZE + (r300->polygon_offset_enabled ? 5 : 0); + + if (last_sprite_coord_enable != r300->sprite_coord_enable || + last_two_sided_color != r300->two_sided_color) { + r300_mark_atom_dirty(r300, &r300->rs_block_state); + } +} + +/* Free rasterizer state. */ +static void r300_delete_rs_state(struct pipe_context* pipe, void* state) +{ + FREE(state); +} + +static void* + r300_create_sampler_state(struct pipe_context* pipe, + const struct pipe_sampler_state* state) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_sampler_state* sampler = CALLOC_STRUCT(r300_sampler_state); + boolean is_r500 = r300->screen->caps.is_r500; + int lod_bias; + + sampler->state = *state; + + /* r300 doesn't handle CLAMP and MIRROR_CLAMP correctly when either MAG + * or MIN filter is NEAREST. Since texwrap produces same results + * for CLAMP and CLAMP_TO_EDGE, we use them instead. */ + if (sampler->state.min_img_filter == PIPE_TEX_FILTER_NEAREST || + sampler->state.mag_img_filter == PIPE_TEX_FILTER_NEAREST) { + /* Wrap S. */ + if (sampler->state.wrap_s == PIPE_TEX_WRAP_CLAMP) + sampler->state.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + else if (sampler->state.wrap_s == PIPE_TEX_WRAP_MIRROR_CLAMP) + sampler->state.wrap_s = PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE; + + /* Wrap T. */ + if (sampler->state.wrap_t == PIPE_TEX_WRAP_CLAMP) + sampler->state.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + else if (sampler->state.wrap_t == PIPE_TEX_WRAP_MIRROR_CLAMP) + sampler->state.wrap_t = PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE; + + /* Wrap R. */ + if (sampler->state.wrap_r == PIPE_TEX_WRAP_CLAMP) + sampler->state.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + else if (sampler->state.wrap_r == PIPE_TEX_WRAP_MIRROR_CLAMP) + sampler->state.wrap_r = PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE; + } + + sampler->filter0 |= + (r300_translate_wrap(sampler->state.wrap_s) << R300_TX_WRAP_S_SHIFT) | + (r300_translate_wrap(sampler->state.wrap_t) << R300_TX_WRAP_T_SHIFT) | + (r300_translate_wrap(sampler->state.wrap_r) << R300_TX_WRAP_R_SHIFT); + + sampler->filter0 |= r300_translate_tex_filters(state->min_img_filter, + state->mag_img_filter, + state->min_mip_filter, + state->max_anisotropy > 0); + + sampler->filter0 |= r300_anisotropy(state->max_anisotropy); + + /* Unfortunately, r300-r500 don't support floating-point mipmap lods. */ + /* We must pass these to the merge function to clamp them properly. */ + sampler->min_lod = (unsigned)MAX2(state->min_lod, 0); + sampler->max_lod = (unsigned)MAX2(ceilf(state->max_lod), 0); + + lod_bias = CLAMP((int)(state->lod_bias * 32 + 1), -(1 << 9), (1 << 9) - 1); + + sampler->filter1 |= (lod_bias << R300_LOD_BIAS_SHIFT) & R300_LOD_BIAS_MASK; + + /* This is very high quality anisotropic filtering for R5xx. + * It's good for benchmarking the performance of texturing but + * in practice we don't want to slow down the driver because it's + * a pretty good performance killer. Feel free to play with it. */ + if (DBG_ON(r300, DBG_ANISOHQ) && is_r500) { + sampler->filter1 |= r500_anisotropy(state->max_anisotropy); + } + + /* R500-specific fixups and optimizations */ + if (r300->screen->caps.is_r500) { + sampler->filter1 |= R500_BORDER_FIX; + } + + return (void*)sampler; +} + +static void r300_bind_sampler_states(struct pipe_context* pipe, + unsigned count, + void** states) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_textures_state* state = + (struct r300_textures_state*)r300->textures_state.state; + unsigned tex_units = r300->screen->caps.num_tex_units; + + if (count > tex_units) { + return; + } + + memcpy(state->sampler_states, states, sizeof(void*) * count); + state->sampler_state_count = count; + + r300_mark_atom_dirty(r300, &r300->textures_state); +} + +static void r300_lacks_vertex_textures(struct pipe_context* pipe, + unsigned count, + void** states) +{ +} + +static void r300_delete_sampler_state(struct pipe_context* pipe, void* state) +{ + FREE(state); +} + +static uint32_t r300_assign_texture_cache_region(unsigned index, unsigned num) +{ + /* This looks like a hack, but I believe it's suppose to work like + * that. To illustrate how this works, let's assume you have 5 textures. + * From docs, 5 and the successive numbers are: + * + * FOURTH_1 = 5 + * FOURTH_2 = 6 + * FOURTH_3 = 7 + * EIGHTH_0 = 8 + * EIGHTH_1 = 9 + * + * First 3 textures will get 3/4 of size of the cache, divived evenly + * between them. The last 1/4 of the cache must be divided between + * the last 2 textures, each will therefore get 1/8 of the cache. + * Why not just to use "5 + texture_index" ? + * + * This simple trick works for all "num" <= 16. + */ + if (num <= 1) + return R300_TX_CACHE(R300_TX_CACHE_WHOLE); + else + return R300_TX_CACHE(num + index); +} + +static void r300_set_fragment_sampler_views(struct pipe_context* pipe, + unsigned count, + struct pipe_sampler_view** views) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_textures_state* state = + (struct r300_textures_state*)r300->textures_state.state; + struct r300_texture *texture; + unsigned i, real_num_views = 0, view_index = 0; + unsigned tex_units = r300->screen->caps.num_tex_units; + boolean dirty_tex = FALSE; + + if (count > tex_units) { + return; + } + + /* Calculate the real number of views. */ + for (i = 0; i < count; i++) { + if (views[i]) + real_num_views++; + } + + for (i = 0; i < count; i++) { + pipe_sampler_view_reference( + (struct pipe_sampler_view**)&state->sampler_views[i], + views[i]); + + if (!views[i]) { + continue; + } + + /* A new sampler view (= texture)... */ + dirty_tex = TRUE; + + /* Set the texrect factor in the fragment shader. + * Needed for RECT and NPOT fallback. */ + texture = r300_texture(views[i]->texture); + if (texture->desc.is_npot) { + r300_mark_atom_dirty(r300, &r300->fs_rc_constant_state); + } + + state->sampler_views[i]->texcache_region = + r300_assign_texture_cache_region(view_index, real_num_views); + view_index++; + } + + for (i = count; i < tex_units; i++) { + if (state->sampler_views[i]) { + pipe_sampler_view_reference( + (struct pipe_sampler_view**)&state->sampler_views[i], + NULL); + } + } + + state->sampler_view_count = count; + + r300_mark_atom_dirty(r300, &r300->textures_state); + r300->validate_buffers = TRUE; + + if (dirty_tex) { + r300_mark_atom_dirty(r300, &r300->texture_cache_inval); + } +} + +static struct pipe_sampler_view * +r300_create_sampler_view(struct pipe_context *pipe, + struct pipe_resource *texture, + const struct pipe_sampler_view *templ) +{ + struct r300_sampler_view *view = CALLOC_STRUCT(r300_sampler_view); + struct r300_texture *tex = r300_texture(texture); + boolean is_r500 = r300_screen(pipe->screen)->caps.is_r500; + boolean dxtc_swizzle = r300_screen(pipe->screen)->caps.dxtc_swizzle; + + if (view) { + view->base = *templ; + view->base.reference.count = 1; + view->base.context = pipe; + view->base.texture = NULL; + pipe_resource_reference(&view->base.texture, texture); + + view->swizzle[0] = templ->swizzle_r; + view->swizzle[1] = templ->swizzle_g; + view->swizzle[2] = templ->swizzle_b; + view->swizzle[3] = templ->swizzle_a; + + view->format = tex->tx_format; + view->format.format1 |= r300_translate_texformat(templ->format, + view->swizzle, + is_r500, + dxtc_swizzle); + if (is_r500) { + view->format.format2 |= r500_tx_format_msb_bit(templ->format); + } + } + + return (struct pipe_sampler_view*)view; +} + +static void +r300_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_resource_reference(&view->texture, NULL); + FREE(view); +} + +static void r300_set_scissor_state(struct pipe_context* pipe, + const struct pipe_scissor_state* state) +{ + struct r300_context* r300 = r300_context(pipe); + + memcpy(r300->scissor_state.state, state, + sizeof(struct pipe_scissor_state)); + + r300_mark_atom_dirty(r300, &r300->scissor_state); +} + +static void r300_set_viewport_state(struct pipe_context* pipe, + const struct pipe_viewport_state* state) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_viewport_state* viewport = + (struct r300_viewport_state*)r300->viewport_state.state; + + r300->viewport = *state; + + if (r300->draw) { + draw_set_viewport_state(r300->draw, state); + viewport->vte_control = R300_VTX_XY_FMT | R300_VTX_Z_FMT; + return; + } + + /* Do the transform in HW. */ + viewport->vte_control = R300_VTX_W0_FMT; + + if (state->scale[0] != 1.0f) { + viewport->xscale = state->scale[0]; + viewport->vte_control |= R300_VPORT_X_SCALE_ENA; + } + if (state->scale[1] != 1.0f) { + viewport->yscale = state->scale[1]; + viewport->vte_control |= R300_VPORT_Y_SCALE_ENA; + } + if (state->scale[2] != 1.0f) { + viewport->zscale = state->scale[2]; + viewport->vte_control |= R300_VPORT_Z_SCALE_ENA; + } + if (state->translate[0] != 0.0f) { + viewport->xoffset = state->translate[0]; + viewport->vte_control |= R300_VPORT_X_OFFSET_ENA; + } + if (state->translate[1] != 0.0f) { + viewport->yoffset = state->translate[1]; + viewport->vte_control |= R300_VPORT_Y_OFFSET_ENA; + } + if (state->translate[2] != 0.0f) { + viewport->zoffset = state->translate[2]; + viewport->vte_control |= R300_VPORT_Z_OFFSET_ENA; + } + + r300_mark_atom_dirty(r300, &r300->viewport_state); + if (r300->fs.state && r300_fs(r300)->shader->inputs.wpos != ATTR_UNUSED) { + r300_mark_atom_dirty(r300, &r300->fs_rc_constant_state); + } +} + +static void r300_set_vertex_buffers(struct pipe_context* pipe, + unsigned count, + const struct pipe_vertex_buffer* buffers) +{ + struct r300_context* r300 = r300_context(pipe); + struct pipe_vertex_buffer *vbo; + unsigned i, max_index = (1 << 24) - 1; + boolean any_user_buffer = FALSE; + struct pipe_vertex_buffer dummy_vb = {0}; + + /* There must be at least one vertex buffer set, otherwise it locks up. */ + if (!count) { + dummy_vb.buffer = r300->dummy_vb; + dummy_vb.max_index = r300->dummy_vb->width0 / 4; + buffers = &dummy_vb; + count = 1; + } + + if (count == r300->vertex_buffer_count && + memcmp(r300->vertex_buffer, buffers, + sizeof(struct pipe_vertex_buffer) * count) == 0) { + return; + } + + if (r300->screen->caps.has_tcl) { + /* HW TCL. */ + r300->incompatible_vb_layout = FALSE; + + /* Check if the strides and offsets are aligned to the size of DWORD. */ + for (i = 0; i < count; i++) { + if (buffers[i].buffer) { + if (buffers[i].stride % 4 != 0 || + buffers[i].buffer_offset % 4 != 0) { + r300->incompatible_vb_layout = TRUE; + break; + } + } + } + + for (i = 0; i < count; i++) { + /* Why, yes, I AM casting away constness. How did you know? */ + vbo = (struct pipe_vertex_buffer*)&buffers[i]; + + /* Skip NULL buffers */ + if (!buffers[i].buffer) { + continue; + } + + if (r300_buffer_is_user_buffer(vbo->buffer)) { + any_user_buffer = TRUE; + } + + /* The stride of zero means we will be fetching only the first + * vertex, so don't care about max_index. */ + if (!vbo->stride) + continue; + + if (vbo->max_index == ~0) { + vbo->max_index = + (vbo->buffer->width0 - vbo->buffer_offset) / vbo->stride; + } + + max_index = MIN2(vbo->max_index, max_index); + } + + r300->any_user_vbs = any_user_buffer; + r300->vertex_buffer_max_index = max_index; + r300->aos_dirty = TRUE; + r300->validate_buffers = TRUE; + } else { + /* SW TCL. */ + draw_set_vertex_buffers(r300->draw, count, buffers); + } + + /* Common code. */ + for (i = 0; i < count; i++) { + /* Reference our buffer. */ + pipe_resource_reference(&r300->vertex_buffer[i].buffer, buffers[i].buffer); + } + for (; i < r300->vertex_buffer_count; i++) { + /* Dereference any old buffers. */ + pipe_resource_reference(&r300->vertex_buffer[i].buffer, NULL); + } + + memcpy(r300->vertex_buffer, buffers, + sizeof(struct pipe_vertex_buffer) * count); + r300->vertex_buffer_count = count; +} + +static void r300_set_index_buffer(struct pipe_context* pipe, + const struct pipe_index_buffer *ib) +{ + struct r300_context* r300 = r300_context(pipe); + + if (ib) { + pipe_resource_reference(&r300->index_buffer.buffer, ib->buffer); + memcpy(&r300->index_buffer, ib, sizeof(r300->index_buffer)); + } + else { + pipe_resource_reference(&r300->index_buffer.buffer, NULL); + memset(&r300->index_buffer, 0, sizeof(r300->index_buffer)); + } + + if (r300->screen->caps.has_tcl) { + r300->validate_buffers = TRUE; + } + else { + draw_set_index_buffer(r300->draw, ib); + } +} + +/* Initialize the PSC tables. */ +static void r300_vertex_psc(struct r300_vertex_element_state *velems) +{ + struct r300_vertex_stream_state *vstream = &velems->vertex_stream; + uint16_t type, swizzle; + enum pipe_format format; + unsigned i; + + if (velems->count > 16) { + fprintf(stderr, "r300: More than 16 vertex elements are not supported," + " requested %i, using 16.\n", velems->count); + velems->count = 16; + } + + /* Vertex shaders have no semantics on their inputs, + * so PSC should just route stuff based on the vertex elements, + * and not on attrib information. */ + for (i = 0; i < velems->count; i++) { + format = velems->hw_format[i]; + + type = r300_translate_vertex_data_type(format); + if (type == R300_INVALID_FORMAT) { + fprintf(stderr, "r300: Bad vertex format %s.\n", + util_format_short_name(format)); + assert(0); + abort(); + } + + type |= i << R300_DST_VEC_LOC_SHIFT; + swizzle = r300_translate_vertex_data_swizzle(format); + + if (i & 1) { + vstream->vap_prog_stream_cntl[i >> 1] |= type << 16; + vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle << 16; + } else { + vstream->vap_prog_stream_cntl[i >> 1] |= type; + vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle; + } + } + + /* Set the last vector in the PSC. */ + if (i) { + i -= 1; + } + vstream->vap_prog_stream_cntl[i >> 1] |= + (R300_LAST_VEC << (i & 1 ? 16 : 0)); + + vstream->count = (i >> 1) + 1; +} + +#define FORMAT_REPLACE(what, withwhat) \ + case PIPE_FORMAT_##what: *format = PIPE_FORMAT_##withwhat; break + +static void* r300_create_vertex_elements_state(struct pipe_context* pipe, + unsigned count, + const struct pipe_vertex_element* attribs) +{ + struct r300_vertex_element_state *velems; + unsigned i; + enum pipe_format *format; + struct pipe_vertex_element dummy_attrib = {0}; + + /* R300 Programmable Stream Control (PSC) doesn't support 0 vertex elements. */ + if (!count) { + dummy_attrib.src_format = PIPE_FORMAT_R8G8B8A8_UNORM; + attribs = &dummy_attrib; + count = 1; + } + + assert(count <= PIPE_MAX_ATTRIBS); + velems = CALLOC_STRUCT(r300_vertex_element_state); + if (velems != NULL) { + velems->count = count; + memcpy(velems->velem, attribs, sizeof(struct pipe_vertex_element) * count); + + if (r300_screen(pipe->screen)->caps.has_tcl) { + /* Set the best hw format in case the original format is not + * supported by hw. */ + for (i = 0; i < count; i++) { + velems->hw_format[i] = velems->velem[i].src_format; + format = &velems->hw_format[i]; + + /* This is basically the list of unsupported formats. + * For now we don't care about the alignment, that's going to + * be sorted out after the PSC setup. */ + switch (*format) { + FORMAT_REPLACE(R64_FLOAT, R32_FLOAT); + FORMAT_REPLACE(R64G64_FLOAT, R32G32_FLOAT); + FORMAT_REPLACE(R64G64B64_FLOAT, R32G32B32_FLOAT); + FORMAT_REPLACE(R64G64B64A64_FLOAT, R32G32B32A32_FLOAT); + + FORMAT_REPLACE(R32_UNORM, R32_FLOAT); + FORMAT_REPLACE(R32G32_UNORM, R32G32_FLOAT); + FORMAT_REPLACE(R32G32B32_UNORM, R32G32B32_FLOAT); + FORMAT_REPLACE(R32G32B32A32_UNORM, R32G32B32A32_FLOAT); + + FORMAT_REPLACE(R32_USCALED, R32_FLOAT); + FORMAT_REPLACE(R32G32_USCALED, R32G32_FLOAT); + FORMAT_REPLACE(R32G32B32_USCALED, R32G32B32_FLOAT); + FORMAT_REPLACE(R32G32B32A32_USCALED,R32G32B32A32_FLOAT); + + FORMAT_REPLACE(R32_SNORM, R32_FLOAT); + FORMAT_REPLACE(R32G32_SNORM, R32G32_FLOAT); + FORMAT_REPLACE(R32G32B32_SNORM, R32G32B32_FLOAT); + FORMAT_REPLACE(R32G32B32A32_SNORM, R32G32B32A32_FLOAT); + + FORMAT_REPLACE(R32_SSCALED, R32_FLOAT); + FORMAT_REPLACE(R32G32_SSCALED, R32G32_FLOAT); + FORMAT_REPLACE(R32G32B32_SSCALED, R32G32B32_FLOAT); + FORMAT_REPLACE(R32G32B32A32_SSCALED,R32G32B32A32_FLOAT); + + FORMAT_REPLACE(R32_FIXED, R32_FLOAT); + FORMAT_REPLACE(R32G32_FIXED, R32G32_FLOAT); + FORMAT_REPLACE(R32G32B32_FIXED, R32G32B32_FLOAT); + FORMAT_REPLACE(R32G32B32A32_FIXED, R32G32B32A32_FLOAT); + + default:; + } + + velems->incompatible_layout = + velems->incompatible_layout || + velems->velem[i].src_format != velems->hw_format[i] || + velems->velem[i].src_offset % 4 != 0; + } + + /* Now setup PSC. + * The unused components will be replaced by (..., 0, 1). */ + r300_vertex_psc(velems); + + /* Align the formats to the size of DWORD. + * We only care about the blocksizes of the formats since + * swizzles are already set up. + * Also compute the vertex size. */ + for (i = 0; i < count; i++) { + /* This is OK because we check for aligned strides too + * elsewhere. */ + velems->hw_format_size[i] = + align(util_format_get_blocksize(velems->hw_format[i]), 4); + velems->vertex_size_dwords += velems->hw_format_size[i] / 4; + } + } + } + return velems; +} + +static void r300_bind_vertex_elements_state(struct pipe_context *pipe, + void *state) +{ + struct r300_context *r300 = r300_context(pipe); + struct r300_vertex_element_state *velems = state; + + if (velems == NULL) { + return; + } + + r300->velems = velems; + + if (r300->draw) { + draw_set_vertex_elements(r300->draw, velems->count, velems->velem); + return; + } + + UPDATE_STATE(&velems->vertex_stream, r300->vertex_stream_state); + r300->vertex_stream_state.size = (1 + velems->vertex_stream.count) * 2; + r300->aos_dirty = TRUE; +} + +static void r300_delete_vertex_elements_state(struct pipe_context *pipe, void *state) +{ + FREE(state); +} + +static void* r300_create_vs_state(struct pipe_context* pipe, + const struct pipe_shader_state* shader) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_vertex_shader* vs = CALLOC_STRUCT(r300_vertex_shader); + + /* Copy state directly into shader. */ + vs->state = *shader; + vs->state.tokens = tgsi_dup_tokens(shader->tokens); + + if (r300->screen->caps.has_tcl) { + r300_init_vs_outputs(vs); + r300_translate_vertex_shader(r300, vs); + } else { + r300_draw_init_vertex_shader(r300->draw, vs); + } + + return vs; +} + +static void r300_bind_vs_state(struct pipe_context* pipe, void* shader) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader; + + if (vs == NULL) { + r300->vs_state.state = NULL; + return; + } + if (vs == r300->vs_state.state) { + return; + } + r300->vs_state.state = vs; + + /* The majority of the RS block bits is dependent on the vertex shader. */ + r300_mark_atom_dirty(r300, &r300->rs_block_state); /* Will be updated before the emission. */ + + if (r300->screen->caps.has_tcl) { + unsigned fc_op_dwords = r300->screen->caps.is_r500 ? 3 : 2; + r300_mark_atom_dirty(r300, &r300->vs_state); + r300->vs_state.size = + vs->code.length + 9 + + (vs->code.num_fc_ops ? vs->code.num_fc_ops * fc_op_dwords + 4 : 0); + + r300_mark_atom_dirty(r300, &r300->vs_constants); + r300->vs_constants.size = + 2 + + (vs->externals_count ? vs->externals_count * 4 + 3 : 0) + + (vs->immediates_count ? vs->immediates_count * 4 + 3 : 0); + + ((struct r300_constant_buffer*)r300->vs_constants.state)->remap_table = + vs->code.constants_remap_table; + + r300_mark_atom_dirty(r300, &r300->pvs_flush); + } else { + draw_bind_vertex_shader(r300->draw, + (struct draw_vertex_shader*)vs->draw_vs); + } +} + +static void r300_delete_vs_state(struct pipe_context* pipe, void* shader) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader; + + if (r300->screen->caps.has_tcl) { + rc_constants_destroy(&vs->code.constants); + if (vs->code.constants_remap_table) + FREE(vs->code.constants_remap_table); + } else { + draw_delete_vertex_shader(r300->draw, + (struct draw_vertex_shader*)vs->draw_vs); + } + + FREE((void*)vs->state.tokens); + FREE(shader); +} + +static void r300_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + struct pipe_resource *buf) +{ + struct r300_context* r300 = r300_context(pipe); + struct r300_constant_buffer *cbuf; + uint32_t *mapped; + + switch (shader) { + case PIPE_SHADER_VERTEX: + cbuf = (struct r300_constant_buffer*)r300->vs_constants.state; + break; + case PIPE_SHADER_FRAGMENT: + cbuf = (struct r300_constant_buffer*)r300->fs_constants.state; + break; + default: + return; + } + + if (buf == NULL || buf->width0 == 0 || + (mapped = (uint32_t*)r300_buffer(buf)->constant_buffer) == NULL) { + return; + } + + if (shader == PIPE_SHADER_FRAGMENT || + (shader == PIPE_SHADER_VERTEX && r300->screen->caps.has_tcl)) { + assert((buf->width0 % (4 * sizeof(float))) == 0); + cbuf->ptr = mapped; + } + + if (shader == PIPE_SHADER_VERTEX) { + if (r300->screen->caps.has_tcl) { + struct r300_vertex_shader *vs = + (struct r300_vertex_shader*)r300->vs_state.state; + + if (!vs) { + cbuf->buffer_base = 0; + return; + } + + cbuf->buffer_base = r300->vs_const_base; + r300->vs_const_base += vs->code.constants.Count; + if (r300->vs_const_base > R500_MAX_PVS_CONST_VECS) { + r300->vs_const_base = vs->code.constants.Count; + cbuf->buffer_base = 0; + r300_mark_atom_dirty(r300, &r300->pvs_flush); + } + r300_mark_atom_dirty(r300, &r300->vs_constants); + } else if (r300->draw) { + draw_set_mapped_constant_buffer(r300->draw, PIPE_SHADER_VERTEX, + 0, mapped, buf->width0); + } + } else if (shader == PIPE_SHADER_FRAGMENT) { + r300_mark_atom_dirty(r300, &r300->fs_constants); + } +} + +void r300_init_state_functions(struct r300_context* r300) +{ + r300->context.create_blend_state = r300_create_blend_state; + r300->context.bind_blend_state = r300_bind_blend_state; + r300->context.delete_blend_state = r300_delete_blend_state; + + r300->context.set_blend_color = r300_set_blend_color; + + r300->context.set_clip_state = r300_set_clip_state; + r300->context.set_sample_mask = r300_set_sample_mask; + + r300->context.set_constant_buffer = r300_set_constant_buffer; + + r300->context.create_depth_stencil_alpha_state = r300_create_dsa_state; + r300->context.bind_depth_stencil_alpha_state = r300_bind_dsa_state; + r300->context.delete_depth_stencil_alpha_state = r300_delete_dsa_state; + + r300->context.set_stencil_ref = r300_set_stencil_ref; + + r300->context.set_framebuffer_state = r300_set_framebuffer_state; + + r300->context.create_fs_state = r300_create_fs_state; + r300->context.bind_fs_state = r300_bind_fs_state; + r300->context.delete_fs_state = r300_delete_fs_state; + + r300->context.set_polygon_stipple = r300_set_polygon_stipple; + + r300->context.create_rasterizer_state = r300_create_rs_state; + r300->context.bind_rasterizer_state = r300_bind_rs_state; + r300->context.delete_rasterizer_state = r300_delete_rs_state; + + r300->context.create_sampler_state = r300_create_sampler_state; + r300->context.bind_fragment_sampler_states = r300_bind_sampler_states; + r300->context.bind_vertex_sampler_states = r300_lacks_vertex_textures; + r300->context.delete_sampler_state = r300_delete_sampler_state; + + r300->context.set_fragment_sampler_views = r300_set_fragment_sampler_views; + r300->context.create_sampler_view = r300_create_sampler_view; + r300->context.sampler_view_destroy = r300_sampler_view_destroy; + + r300->context.set_scissor_state = r300_set_scissor_state; + + r300->context.set_viewport_state = r300_set_viewport_state; + + r300->context.set_vertex_buffers = r300_set_vertex_buffers; + r300->context.set_index_buffer = r300_set_index_buffer; + + r300->context.create_vertex_elements_state = r300_create_vertex_elements_state; + r300->context.bind_vertex_elements_state = r300_bind_vertex_elements_state; + r300->context.delete_vertex_elements_state = r300_delete_vertex_elements_state; + + r300->context.create_vs_state = r300_create_vs_state; + r300->context.bind_vs_state = r300_bind_vs_state; + r300->context.delete_vs_state = r300_delete_vs_state; +} diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c new file mode 100644 index 0000000..d5fc8ec --- /dev/null +++ b/src/gallium/drivers/r300/r300_state_derived.c @@ -0,0 +1,915 @@ +/* + * Copyright 2008 Corbin Simpson + * Copyright 2009 Marek Olšák + * + * 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 "draw/draw_context.h" + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_pack_color.h" + +#include "r300_context.h" +#include "r300_fs.h" +#include "r300_hyperz.h" +#include "r300_screen.h" +#include "r300_shader_semantics.h" +#include "r300_state_derived.h" +#include "r300_state_inlines.h" +#include "r300_texture.h" +#include "r300_vs.h" + +/* r300_state_derived: Various bits of state which are dependent upon + * currently bound CSO data. */ + +enum r300_rs_swizzle { + SWIZ_XYZW = 0, + SWIZ_X001, + SWIZ_XY01, + SWIZ_0001, +}; + +enum r300_rs_col_write_type { + WRITE_COLOR = 0, + WRITE_FACE +}; + +static void r300_draw_emit_attrib(struct r300_context* r300, + enum attrib_emit emit, + enum interp_mode interp, + int index) +{ + struct r300_vertex_shader* vs = r300->vs_state.state; + struct tgsi_shader_info* info = &vs->info; + int output; + + output = draw_find_shader_output(r300->draw, + info->output_semantic_name[index], + info->output_semantic_index[index]); + draw_emit_vertex_attr(&r300->vertex_info, emit, interp, output); +} + +static void r300_draw_emit_all_attribs(struct r300_context* r300) +{ + struct r300_vertex_shader* vs = r300->vs_state.state; + struct r300_shader_semantics* vs_outputs = &vs->outputs; + int i, gen_count; + + /* Position. */ + if (vs_outputs->pos != ATTR_UNUSED) { + r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE, + vs_outputs->pos); + } else { + assert(0); + } + + /* Point size. */ + if (vs_outputs->psize != ATTR_UNUSED) { + r300_draw_emit_attrib(r300, EMIT_1F_PSIZE, INTERP_POS, + vs_outputs->psize); + } + + /* Colors. */ + for (i = 0; i < ATTR_COLOR_COUNT; i++) { + if (vs_outputs->color[i] != ATTR_UNUSED) { + r300_draw_emit_attrib(r300, EMIT_4F, INTERP_LINEAR, + vs_outputs->color[i]); + } + } + + /* Back-face colors. */ + for (i = 0; i < ATTR_COLOR_COUNT; i++) { + if (vs_outputs->bcolor[i] != ATTR_UNUSED) { + r300_draw_emit_attrib(r300, EMIT_4F, INTERP_LINEAR, + vs_outputs->bcolor[i]); + } + } + + /* Texture coordinates. */ + /* Only 8 generic vertex attributes can be used. If there are more, + * they won't be rasterized. */ + gen_count = 0; + for (i = 0; i < ATTR_GENERIC_COUNT && gen_count < 8; i++) { + if (vs_outputs->generic[i] != ATTR_UNUSED && + !(r300->sprite_coord_enable & (1 << i))) { + r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE, + vs_outputs->generic[i]); + gen_count++; + } + } + + /* Fog coordinates. */ + if (gen_count < 8 && vs_outputs->fog != ATTR_UNUSED) { + r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE, + vs_outputs->fog); + gen_count++; + } + + /* WPOS. */ + if (r300_fs(r300)->shader->inputs.wpos != ATTR_UNUSED && gen_count < 8) { + DBG(r300, DBG_SWTCL, "draw_emit_attrib: WPOS, index: %i\n", + vs_outputs->wpos); + r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE, + vs_outputs->wpos); + } +} + +/* Update the PSC tables for SW TCL, using Draw. */ +static void r300_swtcl_vertex_psc(struct r300_context *r300) +{ + struct r300_vertex_stream_state *vstream = r300->vertex_stream_state.state; + struct vertex_info *vinfo = &r300->vertex_info; + uint16_t type, swizzle; + enum pipe_format format; + unsigned i, attrib_count; + int* vs_output_tab = r300->stream_loc_notcl; + + memset(vstream, 0, sizeof(struct r300_vertex_stream_state)); + + /* For each Draw attribute, route it to the fragment shader according + * to the vs_output_tab. */ + attrib_count = vinfo->num_attribs; + DBG(r300, DBG_SWTCL, "r300: attrib count: %d\n", attrib_count); + for (i = 0; i < attrib_count; i++) { + if (vs_output_tab[i] == -1) { + assert(0); + abort(); + } + + format = draw_translate_vinfo_format(vinfo->attrib[i].emit); + + DBG(r300, DBG_SWTCL, + "r300: swtcl_vertex_psc [%i] <- %s\n", + vs_output_tab[i], util_format_short_name(format)); + + /* Obtain the type of data in this attribute. */ + type = r300_translate_vertex_data_type(format); + if (type == R300_INVALID_FORMAT) { + fprintf(stderr, "r300: Bad vertex format %s.\n", + util_format_short_name(format)); + assert(0); + abort(); + } + + type |= vs_output_tab[i] << R300_DST_VEC_LOC_SHIFT; + + /* Obtain the swizzle for this attribute. Note that the default + * swizzle in the hardware is not XYZW! */ + swizzle = r300_translate_vertex_data_swizzle(format); + + /* Add the attribute to the PSC table. */ + if (i & 1) { + vstream->vap_prog_stream_cntl[i >> 1] |= type << 16; + vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle << 16; + } else { + vstream->vap_prog_stream_cntl[i >> 1] |= type; + vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle; + } + } + + /* Set the last vector in the PSC. */ + if (i) { + i -= 1; + } + vstream->vap_prog_stream_cntl[i >> 1] |= + (R300_LAST_VEC << (i & 1 ? 16 : 0)); + + vstream->count = (i >> 1) + 1; + r300_mark_atom_dirty(r300, &r300->vertex_stream_state); + r300->vertex_stream_state.size = (1 + vstream->count) * 2; +} + +static void r300_rs_col(struct r300_rs_block* rs, int id, int ptr, + enum r300_rs_swizzle swiz) +{ + rs->ip[id] |= R300_RS_COL_PTR(ptr); + if (swiz == SWIZ_0001) { + rs->ip[id] |= R300_RS_COL_FMT(R300_RS_COL_FMT_0001); + } else { + rs->ip[id] |= R300_RS_COL_FMT(R300_RS_COL_FMT_RGBA); + } + rs->inst[id] |= R300_RS_INST_COL_ID(id); +} + +static void r300_rs_col_write(struct r300_rs_block* rs, int id, int fp_offset, + enum r300_rs_col_write_type type) +{ + assert(type == WRITE_COLOR); + rs->inst[id] |= R300_RS_INST_COL_CN_WRITE | + R300_RS_INST_COL_ADDR(fp_offset); +} + +static void r300_rs_tex(struct r300_rs_block* rs, int id, int ptr, + enum r300_rs_swizzle swiz) +{ + if (swiz == SWIZ_X001) { + rs->ip[id] |= R300_RS_TEX_PTR(ptr) | + R300_RS_SEL_S(R300_RS_SEL_C0) | + R300_RS_SEL_T(R300_RS_SEL_K0) | + R300_RS_SEL_R(R300_RS_SEL_K0) | + R300_RS_SEL_Q(R300_RS_SEL_K1); + } else if (swiz == SWIZ_XY01) { + rs->ip[id] |= R300_RS_TEX_PTR(ptr) | + R300_RS_SEL_S(R300_RS_SEL_C0) | + R300_RS_SEL_T(R300_RS_SEL_C1) | + R300_RS_SEL_R(R300_RS_SEL_K0) | + R300_RS_SEL_Q(R300_RS_SEL_K1); + } else { + rs->ip[id] |= R300_RS_TEX_PTR(ptr) | + R300_RS_SEL_S(R300_RS_SEL_C0) | + R300_RS_SEL_T(R300_RS_SEL_C1) | + R300_RS_SEL_R(R300_RS_SEL_C2) | + R300_RS_SEL_Q(R300_RS_SEL_C3); + } + rs->inst[id] |= R300_RS_INST_TEX_ID(id); +} + +static void r300_rs_tex_write(struct r300_rs_block* rs, int id, int fp_offset) +{ + rs->inst[id] |= R300_RS_INST_TEX_CN_WRITE | + R300_RS_INST_TEX_ADDR(fp_offset); +} + +static void r500_rs_col(struct r300_rs_block* rs, int id, int ptr, + enum r300_rs_swizzle swiz) +{ + rs->ip[id] |= R500_RS_COL_PTR(ptr); + if (swiz == SWIZ_0001) { + rs->ip[id] |= R500_RS_COL_FMT(R300_RS_COL_FMT_0001); + } else { + rs->ip[id] |= R500_RS_COL_FMT(R300_RS_COL_FMT_RGBA); + } + rs->inst[id] |= R500_RS_INST_COL_ID(id); +} + +static void r500_rs_col_write(struct r300_rs_block* rs, int id, int fp_offset, + enum r300_rs_col_write_type type) +{ + if (type == WRITE_FACE) + rs->inst[id] |= R500_RS_INST_COL_CN_WRITE_BACKFACE | + R500_RS_INST_COL_ADDR(fp_offset); + else + rs->inst[id] |= R500_RS_INST_COL_CN_WRITE | + R500_RS_INST_COL_ADDR(fp_offset); + +} + +static void r500_rs_tex(struct r300_rs_block* rs, int id, int ptr, + enum r300_rs_swizzle swiz) +{ + if (swiz == SWIZ_X001) { + rs->ip[id] |= R500_RS_SEL_S(ptr) | + R500_RS_SEL_T(R500_RS_IP_PTR_K0) | + R500_RS_SEL_R(R500_RS_IP_PTR_K0) | + R500_RS_SEL_Q(R500_RS_IP_PTR_K1); + } else if (swiz == SWIZ_XY01) { + rs->ip[id] |= R500_RS_SEL_S(ptr) | + R500_RS_SEL_T(ptr + 1) | + R500_RS_SEL_R(R500_RS_IP_PTR_K0) | + R500_RS_SEL_Q(R500_RS_IP_PTR_K1); + } else { + rs->ip[id] |= R500_RS_SEL_S(ptr) | + R500_RS_SEL_T(ptr + 1) | + R500_RS_SEL_R(ptr + 2) | + R500_RS_SEL_Q(ptr + 3); + } + rs->inst[id] |= R500_RS_INST_TEX_ID(id); +} + +static void r500_rs_tex_write(struct r300_rs_block* rs, int id, int fp_offset) +{ + rs->inst[id] |= R500_RS_INST_TEX_CN_WRITE | + R500_RS_INST_TEX_ADDR(fp_offset); +} + +/* Set up the RS block. + * + * This is the part of the chipset that is responsible for linking vertex + * and fragment shaders and stuffed texture coordinates. + * + * The rasterizer reads data from VAP, which produces vertex shader outputs, + * and GA, which produces stuffed texture coordinates. VAP outputs have + * precedence over GA. All outputs must be rasterized otherwise it locks up. + * If there are more outputs rasterized than is set in VAP/GA, it locks up + * too. The funky part is that this info has been pretty much obtained by trial + * and error. */ +static void r300_update_rs_block(struct r300_context *r300) +{ + struct r300_vertex_shader *vs = r300->vs_state.state; + struct r300_shader_semantics *vs_outputs = &vs->outputs; + struct r300_shader_semantics *fs_inputs = &r300_fs(r300)->shader->inputs; + struct r300_rs_block rs = {0}; + int i, col_count = 0, tex_count = 0, fp_offset = 0, count, loc = 0, tex_ptr = 0; + void (*rX00_rs_col)(struct r300_rs_block*, int, int, enum r300_rs_swizzle); + void (*rX00_rs_col_write)(struct r300_rs_block*, int, int, enum r300_rs_col_write_type); + void (*rX00_rs_tex)(struct r300_rs_block*, int, int, enum r300_rs_swizzle); + void (*rX00_rs_tex_write)(struct r300_rs_block*, int, int); + boolean any_bcolor_used = vs_outputs->bcolor[0] != ATTR_UNUSED || + vs_outputs->bcolor[1] != ATTR_UNUSED; + int *stream_loc_notcl = r300->stream_loc_notcl; + uint32_t stuffing_enable = 0; + + if (r300->screen->caps.is_r500) { + rX00_rs_col = r500_rs_col; + rX00_rs_col_write = r500_rs_col_write; + rX00_rs_tex = r500_rs_tex; + rX00_rs_tex_write = r500_rs_tex_write; + } else { + rX00_rs_col = r300_rs_col; + rX00_rs_col_write = r300_rs_col_write; + rX00_rs_tex = r300_rs_tex; + rX00_rs_tex_write = r300_rs_tex_write; + } + + /* 0x5555 copied from classic, which means: + * Select user color 0 for COLOR0 up to COLOR7. + * What the hell does that mean? */ + rs.vap_vtx_state_cntl = 0x5555; + + /* The position is always present in VAP. */ + rs.vap_vsm_vtx_assm |= R300_INPUT_CNTL_POS; + rs.vap_out_vtx_fmt[0] |= R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT; + stream_loc_notcl[loc++] = 0; + + /* Set up the point size in VAP. */ + if (vs_outputs->psize != ATTR_UNUSED) { + rs.vap_out_vtx_fmt[0] |= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT; + stream_loc_notcl[loc++] = 1; + } + + /* Set up and rasterize colors. */ + for (i = 0; i < ATTR_COLOR_COUNT; i++) { + if (vs_outputs->color[i] != ATTR_UNUSED || any_bcolor_used || + vs_outputs->color[1] != ATTR_UNUSED) { + /* Set up the color in VAP. */ + rs.vap_vsm_vtx_assm |= R300_INPUT_CNTL_COLOR; + rs.vap_out_vtx_fmt[0] |= + R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << i; + stream_loc_notcl[loc++] = 2 + i; + + /* Rasterize it. */ + rX00_rs_col(&rs, col_count, col_count, SWIZ_XYZW); + + /* Write it to the FS input register if it's needed by the FS. */ + if (fs_inputs->color[i] != ATTR_UNUSED) { + rX00_rs_col_write(&rs, col_count, fp_offset, WRITE_COLOR); + fp_offset++; + + DBG(r300, DBG_RS, + "r300: Rasterized color %i written to FS.\n", i); + } else { + DBG(r300, DBG_RS, "r300: Rasterized color %i unused.\n", i); + } + col_count++; + } else { + /* Skip the FS input register, leave it uninitialized. */ + /* If we try to set it to (0,0,0,1), it will lock up. */ + if (fs_inputs->color[i] != ATTR_UNUSED) { + fp_offset++; + + DBG(r300, DBG_RS, "r300: FS input color %i unassigned%s.\n", + i); + } + } + } + + /* Set up back-face colors. The rasterizer will do the color selection + * automatically. */ + if (any_bcolor_used) { + if (r300->two_sided_color) { + /* Rasterize as back-face colors. */ + for (i = 0; i < ATTR_COLOR_COUNT; i++) { + rs.vap_vsm_vtx_assm |= R300_INPUT_CNTL_COLOR; + rs.vap_out_vtx_fmt[0] |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << (2+i); + stream_loc_notcl[loc++] = 4 + i; + } + } else { + /* Rasterize two fake texcoords to prevent from the two-sided color + * selection. */ + /* XXX Consider recompiling the vertex shader to save 2 RS units. */ + for (i = 0; i < 2; i++) { + rs.vap_vsm_vtx_assm |= (R300_INPUT_CNTL_TC0 << tex_count); + rs.vap_out_vtx_fmt[1] |= (4 << (3 * tex_count)); + stream_loc_notcl[loc++] = 6 + tex_count; + + /* Rasterize it. */ + rX00_rs_tex(&rs, tex_count, tex_ptr, SWIZ_XYZW); + tex_count++; + tex_ptr += 4; + } + } + } + + /* gl_FrontFacing. + * Note that we can use either the two-sided color selection based on + * the front and back vertex shader colors, or gl_FrontFacing, + * but not both! It locks up otherwise. + * + * In Direct3D 9, the two-sided color selection can be used + * with shaders 2.0 only, while gl_FrontFacing can be used + * with shaders 3.0 only. The hardware apparently hasn't been designed + * to support both at the same time. */ + if (r300->screen->caps.is_r500 && fs_inputs->face != ATTR_UNUSED && + !(any_bcolor_used && r300->two_sided_color)) { + rX00_rs_col(&rs, col_count, col_count, SWIZ_XYZW); + rX00_rs_col_write(&rs, col_count, fp_offset, WRITE_FACE); + fp_offset++; + col_count++; + DBG(r300, DBG_RS, "r300: Rasterized FACE written to FS.\n"); + } else if (fs_inputs->face != ATTR_UNUSED) { + fprintf(stderr, "r300: ERROR: FS input FACE unassigned.\n"); + } + + /* Rasterize texture coordinates. */ + for (i = 0; i < ATTR_GENERIC_COUNT && tex_count < 8; i++) { + bool sprite_coord = false; + + if (fs_inputs->generic[i] != ATTR_UNUSED) { + sprite_coord = !!(r300->sprite_coord_enable & (1 << i)); + } + + if (vs_outputs->generic[i] != ATTR_UNUSED || sprite_coord) { + if (!sprite_coord) { + /* Set up the texture coordinates in VAP. */ + rs.vap_vsm_vtx_assm |= (R300_INPUT_CNTL_TC0 << tex_count); + rs.vap_out_vtx_fmt[1] |= (4 << (3 * tex_count)); + stream_loc_notcl[loc++] = 6 + tex_count; + } else + stuffing_enable |= + R300_GB_TEX_ST << (R300_GB_TEX0_SOURCE_SHIFT + (tex_count*2)); + + /* Rasterize it. */ + rX00_rs_tex(&rs, tex_count, tex_ptr, + sprite_coord ? SWIZ_XY01 : SWIZ_XYZW); + + /* Write it to the FS input register if it's needed by the FS. */ + if (fs_inputs->generic[i] != ATTR_UNUSED) { + rX00_rs_tex_write(&rs, tex_count, fp_offset); + fp_offset++; + + DBG(r300, DBG_RS, + "r300: Rasterized generic %i written to FS%s in texcoord %d.\n", + i, sprite_coord ? " (sprite coord)" : "", tex_count); + } else { + DBG(r300, DBG_RS, + "r300: Rasterized generic %i unused%s.\n", + i, sprite_coord ? " (sprite coord)" : ""); + } + tex_count++; + tex_ptr += sprite_coord ? 2 : 4; + } else { + /* Skip the FS input register, leave it uninitialized. */ + /* If we try to set it to (0,0,0,1), it will lock up. */ + if (fs_inputs->generic[i] != ATTR_UNUSED) { + fp_offset++; + + DBG(r300, DBG_RS, "r300: FS input generic %i unassigned%s.\n", + i, sprite_coord ? " (sprite coord)" : ""); + } + } + } + + for (; i < ATTR_GENERIC_COUNT; i++) { + if (fs_inputs->generic[i] != ATTR_UNUSED) { + fprintf(stderr, "r300: ERROR: FS input generic %i unassigned, " + "not enough hardware slots.\n", i); + } + } + + /* Rasterize fog coordinates. */ + if (vs_outputs->fog != ATTR_UNUSED && tex_count < 8) { + /* Set up the fog coordinates in VAP. */ + rs.vap_vsm_vtx_assm |= (R300_INPUT_CNTL_TC0 << tex_count); + rs.vap_out_vtx_fmt[1] |= (4 << (3 * tex_count)); + stream_loc_notcl[loc++] = 6 + tex_count; + + /* Rasterize it. */ + rX00_rs_tex(&rs, tex_count, tex_ptr, SWIZ_X001); + + /* Write it to the FS input register if it's needed by the FS. */ + if (fs_inputs->fog != ATTR_UNUSED) { + rX00_rs_tex_write(&rs, tex_count, fp_offset); + fp_offset++; + + DBG(r300, DBG_RS, "r300: Rasterized fog written to FS.\n"); + } else { + DBG(r300, DBG_RS, "r300: Rasterized fog unused.\n"); + } + tex_count++; + tex_ptr += 4; + } else { + /* Skip the FS input register, leave it uninitialized. */ + /* If we try to set it to (0,0,0,1), it will lock up. */ + if (fs_inputs->fog != ATTR_UNUSED) { + fp_offset++; + + if (tex_count < 8) { + DBG(r300, DBG_RS, "r300: FS input fog unassigned.\n"); + } else { + fprintf(stderr, "r300: ERROR: FS input fog unassigned, " + "not enough hardware slots.\n"); + } + } + } + + /* Rasterize WPOS. */ + /* Don't set it in VAP if the FS doesn't need it. */ + if (fs_inputs->wpos != ATTR_UNUSED && tex_count < 8) { + /* Set up the WPOS coordinates in VAP. */ + rs.vap_vsm_vtx_assm |= (R300_INPUT_CNTL_TC0 << tex_count); + rs.vap_out_vtx_fmt[1] |= (4 << (3 * tex_count)); + stream_loc_notcl[loc++] = 6 + tex_count; + + /* Rasterize it. */ + rX00_rs_tex(&rs, tex_count, tex_ptr, SWIZ_XYZW); + + /* Write it to the FS input register. */ + rX00_rs_tex_write(&rs, tex_count, fp_offset); + + DBG(r300, DBG_RS, "r300: Rasterized WPOS written to FS.\n"); + + fp_offset++; + tex_count++; + tex_ptr += 4; + } else { + if (fs_inputs->wpos != ATTR_UNUSED && tex_count >= 8) { + fprintf(stderr, "r300: ERROR: FS input WPOS unassigned, " + "not enough hardware slots.\n"); + } + } + + /* Invalidate the rest of the no-TCL (GA) stream locations. */ + for (; loc < 16;) { + stream_loc_notcl[loc++] = -1; + } + + /* Rasterize at least one color, or bad things happen. */ + if (col_count == 0 && tex_count == 0) { + rX00_rs_col(&rs, 0, 0, SWIZ_0001); + col_count++; + + DBG(r300, DBG_RS, "r300: Rasterized color 0 to prevent lockups.\n"); + } + + DBG(r300, DBG_RS, "r300: --- Rasterizer status ---: colors: %i, " + "generics: %i.\n", col_count, tex_count); + + rs.count = MIN2(tex_ptr, 32) | (col_count << R300_IC_COUNT_SHIFT) | + R300_HIRES_EN; + + count = MAX3(col_count, tex_count, 1); + rs.inst_count = count - 1; + + /* set the GB enable flags */ + if (r300->sprite_coord_enable) + stuffing_enable |= R300_GB_POINT_STUFF_ENABLE; + + rs.gb_enable = stuffing_enable; + + /* Now, after all that, see if we actually need to update the state. */ + if (memcmp(r300->rs_block_state.state, &rs, sizeof(struct r300_rs_block))) { + memcpy(r300->rs_block_state.state, &rs, sizeof(struct r300_rs_block)); + r300->rs_block_state.size = 13 + count*2; + } +} + +static uint32_t r300_get_border_color(enum pipe_format format, + const float border[4], + boolean is_r500) +{ + const struct util_format_description *desc; + float border_swizzled[4] = {0}; + unsigned i; + union util_color uc = {0}; + + desc = util_format_description(format); + + /* Do depth formats first. */ + if (util_format_is_depth_or_stencil(format)) { + switch (format) { + case PIPE_FORMAT_Z16_UNORM: + return util_pack_z(PIPE_FORMAT_Z16_UNORM, border[0]); + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + if (is_r500) { + return util_pack_z(PIPE_FORMAT_X8Z24_UNORM, border[0]); + } else { + return util_pack_z(PIPE_FORMAT_Z16_UNORM, border[0]) << 16; + } + default: + assert(0); + return 0; + } + } + + /* Apply inverse swizzle of the format. */ + for (i = 0; i < 4; i++) { + switch (desc->swizzle[i]) { + case UTIL_FORMAT_SWIZZLE_X: + border_swizzled[2] = border[i]; + break; + case UTIL_FORMAT_SWIZZLE_Y: + border_swizzled[1] = border[i]; + break; + case UTIL_FORMAT_SWIZZLE_Z: + border_swizzled[0] = border[i]; + break; + case UTIL_FORMAT_SWIZZLE_W: + border_swizzled[3] = border[i]; + break; + } + } + + /* Compressed formats. */ + if (util_format_is_compressed(format)) { + util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc); + return uc.ui; + } + + switch (desc->channel[0].size) { + case 4: + util_pack_color(border_swizzled, PIPE_FORMAT_B4G4R4A4_UNORM, &uc); + break; + + case 5: + if (desc->channel[1].size == 5) { + util_pack_color(border_swizzled, PIPE_FORMAT_B5G5R5A1_UNORM, &uc); + } else if (desc->channel[1].size == 6) { + util_pack_color(border_swizzled, PIPE_FORMAT_B5G6R5_UNORM, &uc); + } else { + assert(0); + } + break; + + default: + case 8: + util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); + break; + + case 10: + util_pack_color(border_swizzled, PIPE_FORMAT_B10G10R10A2_UNORM, &uc); + break; + + case 16: + if (desc->nr_channels <= 2) { + border_swizzled[0] = border_swizzled[2]; + util_pack_color(border_swizzled, PIPE_FORMAT_R16G16_UNORM, &uc); + } else { + util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); + } + break; + } + + return uc.ui; +} + +static void r300_merge_textures_and_samplers(struct r300_context* r300) +{ + struct r300_textures_state *state = + (struct r300_textures_state*)r300->textures_state.state; + struct r300_texture_sampler_state *texstate; + struct r300_sampler_state *sampler; + struct r300_sampler_view *view; + struct r300_texture *tex; + unsigned min_level, max_level, i, j, size; + unsigned count = MIN2(state->sampler_view_count, + state->sampler_state_count); + + /* The KIL opcode fix, see below. */ + if (!count && !r300->screen->caps.is_r500) + count = 1; + + state->tx_enable = 0; + state->count = 0; + size = 2; + + for (i = 0; i < count; i++) { + if (state->sampler_views[i] && state->sampler_states[i]) { + state->tx_enable |= 1 << i; + + view = state->sampler_views[i]; + tex = r300_texture(view->base.texture); + sampler = state->sampler_states[i]; + + texstate = &state->regs[i]; + texstate->format = view->format; + texstate->filter0 = sampler->filter0; + texstate->filter1 = sampler->filter1; + + /* Set the border color. */ + texstate->border_color = + r300_get_border_color(view->base.format, + sampler->state.border_color, + r300->screen->caps.is_r500); + + /* determine min/max levels */ + max_level = MIN3(sampler->max_lod + view->base.u.tex.first_level, + tex->desc.b.b.last_level, view->base.u.tex.last_level); + min_level = MIN2(sampler->min_lod + view->base.u.tex.first_level, + max_level); + + if (tex->desc.is_npot && min_level > 0) { + /* Even though we do not implement mipmapping for NPOT + * textures, we should at least honor the minimum level + * which is allowed to be displayed. We do this by setting up + * an i-th mipmap level as the zero level. */ + r300_texture_setup_format_state(r300->screen, &tex->desc, + min_level, + &texstate->format); + texstate->format.tile_config |= + tex->desc.offset_in_bytes[min_level] & 0xffffffe0; + assert((tex->desc.offset_in_bytes[min_level] & 0x1f) == 0); + } + + /* Assign a texture cache region. */ + texstate->format.format1 |= view->texcache_region; + + /* Depth textures are kinda special. */ + if (util_format_is_depth_or_stencil(tex->desc.b.b.format)) { + unsigned char depth_swizzle[4]; + + if (!r300->screen->caps.is_r500 && + util_format_get_blocksizebits(tex->desc.b.b.format) == 32) { + /* X24x8 is sampled as Y16X16 on r3xx-r4xx. + * The depth here is at the Y component. */ + for (j = 0; j < 4; j++) + depth_swizzle[j] = UTIL_FORMAT_SWIZZLE_Y; + } else { + for (j = 0; j < 4; j++) + depth_swizzle[j] = UTIL_FORMAT_SWIZZLE_X; + } + + /* If compare mode is disabled, sampler view swizzles + * are stored in the format. + * Otherwise, the swizzles must be applied after the compare + * mode in the fragment shader. */ + if (sampler->state.compare_mode == PIPE_TEX_COMPARE_NONE) { + texstate->format.format1 |= + r300_get_swizzle_combined(depth_swizzle, + view->swizzle, FALSE); + } else { + texstate->format.format1 |= + r300_get_swizzle_combined(depth_swizzle, 0, FALSE); + } + } + + if (r300->screen->caps.dxtc_swizzle && + util_format_is_compressed(tex->desc.b.b.format)) { + texstate->filter1 |= R400_DXTC_SWIZZLE_ENABLE; + } + + /* to emulate 1D textures through 2D ones correctly */ + if (tex->desc.b.b.target == PIPE_TEXTURE_1D) { + texstate->filter0 &= ~R300_TX_WRAP_T_MASK; + texstate->filter0 |= R300_TX_WRAP_T(R300_TX_CLAMP_TO_EDGE); + } + + if (tex->desc.is_npot) { + /* NPOT textures don't support mip filter, unfortunately. + * This prevents incorrect rendering. */ + texstate->filter0 &= ~R300_TX_MIN_FILTER_MIP_MASK; + + /* Mask out the mirrored flag. */ + if (texstate->filter0 & R300_TX_WRAP_S(R300_TX_MIRRORED)) { + texstate->filter0 &= ~R300_TX_WRAP_S(R300_TX_MIRRORED); + } + if (texstate->filter0 & R300_TX_WRAP_T(R300_TX_MIRRORED)) { + texstate->filter0 &= ~R300_TX_WRAP_T(R300_TX_MIRRORED); + } + + /* Change repeat to clamp-to-edge. + * (the repeat bit has a value of 0, no masking needed). */ + if ((texstate->filter0 & R300_TX_WRAP_S_MASK) == + R300_TX_WRAP_S(R300_TX_REPEAT)) { + texstate->filter0 |= R300_TX_WRAP_S(R300_TX_CLAMP_TO_EDGE); + } + if ((texstate->filter0 & R300_TX_WRAP_T_MASK) == + R300_TX_WRAP_T(R300_TX_REPEAT)) { + texstate->filter0 |= R300_TX_WRAP_T(R300_TX_CLAMP_TO_EDGE); + } + } else { + /* the MAX_MIP level is the largest (finest) one */ + texstate->format.format0 |= R300_TX_NUM_LEVELS(max_level); + texstate->filter0 |= R300_TX_MAX_MIP_LEVEL(min_level); + } + + texstate->filter0 |= i << 28; + + size += 16; + state->count = i+1; + } else { + /* For the KIL opcode to work on r3xx-r4xx, the texture unit + * assigned to this opcode (it's always the first one) must be + * enabled. Otherwise the opcode doesn't work. + * + * In order to not depend on the fragment shader, we just make + * the first unit enabled all the time. */ + if (i == 0 && !r300->screen->caps.is_r500) { + pipe_sampler_view_reference( + (struct pipe_sampler_view**)&state->sampler_views[i], + &r300->texkill_sampler->base); + + state->tx_enable |= 1 << i; + + texstate = &state->regs[i]; + + /* Just set some valid state. */ + texstate->format = r300->texkill_sampler->format; + texstate->filter0 = + r300_translate_tex_filters(PIPE_TEX_FILTER_NEAREST, + PIPE_TEX_FILTER_NEAREST, + PIPE_TEX_FILTER_NEAREST, + FALSE); + texstate->filter1 = 0; + texstate->border_color = 0; + + texstate->filter0 |= i << 28; + size += 16; + state->count = i+1; + } + } + } + + r300->textures_state.size = size; + + /* Pick a fragment shader based on either the texture compare state + * or the uses_pitch flag. */ + if (r300->fs.state && count) { + if (r300_pick_fragment_shader(r300)) { + r300_mark_fs_code_dirty(r300); + } + } +} + +/* We can't use compressed zbuffers as samplers. */ +static void r300_flush_depth_textures(struct r300_context *r300) +{ + struct r300_textures_state *state = + (struct r300_textures_state*)r300->textures_state.state; + unsigned i, level; + unsigned count = MIN2(state->sampler_view_count, + state->sampler_state_count); + + if (r300->z_decomp_rd) + return; + + for (i = 0; i < count; i++) + if (state->sampler_views[i] && state->sampler_states[i]) { + struct pipe_resource *tex = state->sampler_views[i]->base.texture; + + if (tex->target == PIPE_TEXTURE_3D || + tex->target == PIPE_TEXTURE_CUBE) + continue; + + /* Ignore non-depth textures. + * Also ignore reinterpreted depth textures, e.g. resource_copy. */ + if (!util_format_is_depth_or_stencil(tex->format)) + continue; + + for (level = 0; level <= tex->last_level; level++) + if (r300_texture(tex)->zmask_in_use[level]) { + /* We don't handle 3D textures and cubemaps yet. */ + r300_flush_depth_stencil(&r300->context, tex, level, 0); + } + } +} + +void r300_update_derived_state(struct r300_context* r300) +{ + r300_flush_depth_textures(r300); + + if (r300->textures_state.dirty) { + r300_merge_textures_and_samplers(r300); + } + + if (r300->rs_block_state.dirty) { + r300_update_rs_block(r300); + + if (r300->draw) { + memset(&r300->vertex_info, 0, sizeof(struct vertex_info)); + r300_draw_emit_all_attribs(r300); + draw_compute_vertex_size(&r300->vertex_info); + r300_swtcl_vertex_psc(r300); + } + } + + r300_update_hyperz_state(r300); +} diff --git a/src/gallium/drivers/r300/r300_state_derived.h b/src/gallium/drivers/r300/r300_state_derived.h new file mode 100644 index 0000000..71a4a47 --- /dev/null +++ b/src/gallium/drivers/r300/r300_state_derived.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 R300_STATE_DERIVED_H +#define R300_STATE_DERIVED_H + +struct r300_context; + +void r300_update_derived_state(struct r300_context* r300); + +#endif /* R300_STATE_DERIVED_H */ diff --git a/src/gallium/drivers/r300/r300_state_inlines.h b/src/gallium/drivers/r300/r300_state_inlines.h new file mode 100644 index 0000000..7e50122 --- /dev/null +++ b/src/gallium/drivers/r300/r300_state_inlines.h @@ -0,0 +1,462 @@ +/* + * Copyright 2009 Joakim Sindholt + * 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 R300_STATE_INLINES_H +#define R300_STATE_INLINES_H + +#include "draw/draw_vertex.h" + +#include "pipe/p_format.h" + +#include "util/u_format.h" + +#include "r300_reg.h" + +#include + +/* Some maths. These should probably find their way to u_math, if needed. */ + +static INLINE int pack_float_16_6x(float f) { + return ((int)(f * 6.0) & 0xffff); +} + +/* Blend state. */ + +static INLINE uint32_t r300_translate_blend_function(int blend_func) +{ + switch (blend_func) { + case PIPE_BLEND_ADD: + return R300_COMB_FCN_ADD_CLAMP; + case PIPE_BLEND_SUBTRACT: + return R300_COMB_FCN_SUB_CLAMP; + case PIPE_BLEND_REVERSE_SUBTRACT: + return R300_COMB_FCN_RSUB_CLAMP; + case PIPE_BLEND_MIN: + return R300_COMB_FCN_MIN; + case PIPE_BLEND_MAX: + return R300_COMB_FCN_MAX; + default: + fprintf(stderr, "r300: Unknown blend function %d\n", blend_func); + assert(0); + break; + } + return 0; +} + +/* XXX we can also offer the D3D versions of some of these... */ +static INLINE uint32_t r300_translate_blend_factor(int blend_fact) +{ + switch (blend_fact) { + case PIPE_BLENDFACTOR_ONE: + return R300_BLEND_GL_ONE; + case PIPE_BLENDFACTOR_SRC_COLOR: + return R300_BLEND_GL_SRC_COLOR; + case PIPE_BLENDFACTOR_SRC_ALPHA: + return R300_BLEND_GL_SRC_ALPHA; + case PIPE_BLENDFACTOR_DST_ALPHA: + return R300_BLEND_GL_DST_ALPHA; + case PIPE_BLENDFACTOR_DST_COLOR: + return R300_BLEND_GL_DST_COLOR; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + return R300_BLEND_GL_SRC_ALPHA_SATURATE; + case PIPE_BLENDFACTOR_CONST_COLOR: + return R300_BLEND_GL_CONST_COLOR; + case PIPE_BLENDFACTOR_CONST_ALPHA: + return R300_BLEND_GL_CONST_ALPHA; + case PIPE_BLENDFACTOR_ZERO: + return R300_BLEND_GL_ZERO; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + return R300_BLEND_GL_ONE_MINUS_SRC_COLOR; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + return R300_BLEND_GL_ONE_MINUS_SRC_ALPHA; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + return R300_BLEND_GL_ONE_MINUS_DST_ALPHA; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + return R300_BLEND_GL_ONE_MINUS_DST_COLOR; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + return R300_BLEND_GL_ONE_MINUS_CONST_COLOR; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + return R300_BLEND_GL_ONE_MINUS_CONST_ALPHA; + + case PIPE_BLENDFACTOR_SRC1_COLOR: + case PIPE_BLENDFACTOR_SRC1_ALPHA: + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + fprintf(stderr, "r300: Implementation error: " + "Bad blend factor %d not supported!\n", blend_fact); + assert(0); + break; + + default: + fprintf(stderr, "r300: Unknown blend factor %d\n", blend_fact); + assert(0); + break; + } + return 0; +} + +/* DSA state. */ + +static INLINE uint32_t r300_translate_depth_stencil_function(int zs_func) +{ + switch (zs_func) { + case PIPE_FUNC_NEVER: + return R300_ZS_NEVER; + case PIPE_FUNC_LESS: + return R300_ZS_LESS; + case PIPE_FUNC_EQUAL: + return R300_ZS_EQUAL; + case PIPE_FUNC_LEQUAL: + return R300_ZS_LEQUAL; + case PIPE_FUNC_GREATER: + return R300_ZS_GREATER; + case PIPE_FUNC_NOTEQUAL: + return R300_ZS_NOTEQUAL; + case PIPE_FUNC_GEQUAL: + return R300_ZS_GEQUAL; + case PIPE_FUNC_ALWAYS: + return R300_ZS_ALWAYS; + default: + fprintf(stderr, "r300: Unknown depth/stencil function %d\n", + zs_func); + assert(0); + break; + } + return 0; +} + +static INLINE uint32_t r300_translate_stencil_op(int s_op) +{ + switch (s_op) { + case PIPE_STENCIL_OP_KEEP: + return R300_ZS_KEEP; + case PIPE_STENCIL_OP_ZERO: + return R300_ZS_ZERO; + case PIPE_STENCIL_OP_REPLACE: + return R300_ZS_REPLACE; + case PIPE_STENCIL_OP_INCR: + return R300_ZS_INCR; + case PIPE_STENCIL_OP_DECR: + return R300_ZS_DECR; + case PIPE_STENCIL_OP_INCR_WRAP: + return R300_ZS_INCR_WRAP; + case PIPE_STENCIL_OP_DECR_WRAP: + return R300_ZS_DECR_WRAP; + case PIPE_STENCIL_OP_INVERT: + return R300_ZS_INVERT; + default: + fprintf(stderr, "r300: Unknown stencil op %d", s_op); + assert(0); + break; + } + return 0; +} + +static INLINE uint32_t r300_translate_alpha_function(int alpha_func) +{ + switch (alpha_func) { + case PIPE_FUNC_NEVER: + return R300_FG_ALPHA_FUNC_NEVER; + case PIPE_FUNC_LESS: + return R300_FG_ALPHA_FUNC_LESS; + case PIPE_FUNC_EQUAL: + return R300_FG_ALPHA_FUNC_EQUAL; + case PIPE_FUNC_LEQUAL: + return R300_FG_ALPHA_FUNC_LE; + case PIPE_FUNC_GREATER: + return R300_FG_ALPHA_FUNC_GREATER; + case PIPE_FUNC_NOTEQUAL: + return R300_FG_ALPHA_FUNC_NOTEQUAL; + case PIPE_FUNC_GEQUAL: + return R300_FG_ALPHA_FUNC_GE; + case PIPE_FUNC_ALWAYS: + return R300_FG_ALPHA_FUNC_ALWAYS; + default: + fprintf(stderr, "r300: Unknown alpha function %d", alpha_func); + assert(0); + break; + } + return 0; +} + +static INLINE uint32_t +r300_translate_polygon_mode_front(unsigned mode) { + switch (mode) + { + case PIPE_POLYGON_MODE_FILL: + return R300_GA_POLY_MODE_FRONT_PTYPE_TRI; + case PIPE_POLYGON_MODE_LINE: + return R300_GA_POLY_MODE_FRONT_PTYPE_LINE; + case PIPE_POLYGON_MODE_POINT: + return R300_GA_POLY_MODE_FRONT_PTYPE_POINT; + + default: + fprintf(stderr, "r300: Bad polygon mode %i in %s\n", mode, + __FUNCTION__); + return R300_GA_POLY_MODE_FRONT_PTYPE_TRI; + } +} + +static INLINE uint32_t +r300_translate_polygon_mode_back(unsigned mode) { + switch (mode) + { + case PIPE_POLYGON_MODE_FILL: + return R300_GA_POLY_MODE_BACK_PTYPE_TRI; + case PIPE_POLYGON_MODE_LINE: + return R300_GA_POLY_MODE_BACK_PTYPE_LINE; + case PIPE_POLYGON_MODE_POINT: + return R300_GA_POLY_MODE_BACK_PTYPE_POINT; + + default: + fprintf(stderr, "r300: Bad polygon mode %i in %s\n", mode, + __FUNCTION__); + return R300_GA_POLY_MODE_BACK_PTYPE_TRI; + } +} + +/* Texture sampler state. */ + +static INLINE uint32_t r300_translate_wrap(int wrap) +{ + switch (wrap) { + case PIPE_TEX_WRAP_REPEAT: + return R300_TX_REPEAT; + case PIPE_TEX_WRAP_CLAMP: + return R300_TX_CLAMP; + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return R300_TX_CLAMP_TO_EDGE; + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + return R300_TX_CLAMP_TO_BORDER; + case PIPE_TEX_WRAP_MIRROR_REPEAT: + return R300_TX_REPEAT | R300_TX_MIRRORED; + case PIPE_TEX_WRAP_MIRROR_CLAMP: + return R300_TX_CLAMP | R300_TX_MIRRORED; + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + return R300_TX_CLAMP_TO_EDGE | R300_TX_MIRRORED; + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + return R300_TX_CLAMP_TO_BORDER | R300_TX_MIRRORED; + default: + fprintf(stderr, "r300: Unknown texture wrap %d", wrap); + assert(0); + return 0; + } +} + +static INLINE uint32_t r300_translate_tex_filters(int min, int mag, int mip, + int is_anisotropic) +{ + uint32_t retval = 0; + if (is_anisotropic) + retval |= R300_TX_MIN_FILTER_ANISO | R300_TX_MAG_FILTER_ANISO; + else { + switch (min) { + case PIPE_TEX_FILTER_NEAREST: + retval |= R300_TX_MIN_FILTER_NEAREST; + break; + case PIPE_TEX_FILTER_LINEAR: + retval |= R300_TX_MIN_FILTER_LINEAR; + break; + default: + fprintf(stderr, "r300: Unknown texture filter %d\n", min); + assert(0); + break; + } + switch (mag) { + case PIPE_TEX_FILTER_NEAREST: + retval |= R300_TX_MAG_FILTER_NEAREST; + break; + case PIPE_TEX_FILTER_LINEAR: + retval |= R300_TX_MAG_FILTER_LINEAR; + break; + default: + fprintf(stderr, "r300: Unknown texture filter %d\n", mag); + assert(0); + break; + } + } + switch (mip) { + case PIPE_TEX_MIPFILTER_NONE: + retval |= R300_TX_MIN_FILTER_MIP_NONE; + break; + case PIPE_TEX_MIPFILTER_NEAREST: + retval |= R300_TX_MIN_FILTER_MIP_NEAREST; + break; + case PIPE_TEX_MIPFILTER_LINEAR: + retval |= R300_TX_MIN_FILTER_MIP_LINEAR; + break; + default: + fprintf(stderr, "r300: Unknown texture filter %d\n", mip); + assert(0); + break; + } + + return retval; +} + +static INLINE uint32_t r300_anisotropy(unsigned max_aniso) +{ + if (max_aniso >= 16) { + return R300_TX_MAX_ANISO_16_TO_1; + } else if (max_aniso >= 8) { + return R300_TX_MAX_ANISO_8_TO_1; + } else if (max_aniso >= 4) { + return R300_TX_MAX_ANISO_4_TO_1; + } else if (max_aniso >= 2) { + return R300_TX_MAX_ANISO_2_TO_1; + } else { + return R300_TX_MAX_ANISO_1_TO_1; + } +} + +static INLINE uint32_t r500_anisotropy(unsigned max_aniso) +{ + if (!max_aniso) { + return 0; + } + max_aniso -= 1; + + // Map the range [0, 15] to [0, 63]. + return R500_TX_MAX_ANISO(MIN2((unsigned)(max_aniso*4.2001), 63)) | + R500_TX_ANISO_HIGH_QUALITY; +} + +/* Non-CSO state. (For now.) */ + +static INLINE uint32_t r300_translate_gb_pipes(int pipe_count) +{ + switch (pipe_count) { + case 1: + return R300_GB_TILE_PIPE_COUNT_RV300; + case 2: + return R300_GB_TILE_PIPE_COUNT_R300; + case 3: + return R300_GB_TILE_PIPE_COUNT_R420_3P; + case 4: + return R300_GB_TILE_PIPE_COUNT_R420; + } + return 0; +} + + +/* Translate pipe_formats into PSC vertex types. */ +static INLINE uint16_t +r300_translate_vertex_data_type(enum pipe_format format) { + uint32_t result = 0; + const struct util_format_description *desc; + unsigned i; + + desc = util_format_description(format); + + if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { + return R300_INVALID_FORMAT; + } + + /* Find the first non-VOID channel. */ + for (i = 0; i < 4; i++) { + if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { + break; + } + } + + switch (desc->channel[i].type) { + /* Half-floats, floats, doubles */ + case UTIL_FORMAT_TYPE_FLOAT: + switch (desc->channel[i].size) { + case 16: + /* Supported only on RV350 and later. */ + if (desc->nr_channels > 2) { + result = R300_DATA_TYPE_FLT16_4; + } else { + result = R300_DATA_TYPE_FLT16_2; + } + break; + case 32: + result = R300_DATA_TYPE_FLOAT_1 + (desc->nr_channels - 1); + break; + default: + return R300_INVALID_FORMAT; + } + break; + /* Unsigned ints */ + case UTIL_FORMAT_TYPE_UNSIGNED: + /* Signed ints */ + case UTIL_FORMAT_TYPE_SIGNED: + switch (desc->channel[i].size) { + case 8: + result = R300_DATA_TYPE_BYTE; + break; + case 16: + if (desc->nr_channels > 2) { + result = R300_DATA_TYPE_SHORT_4; + } else { + result = R300_DATA_TYPE_SHORT_2; + } + break; + default: + return R300_INVALID_FORMAT; + } + break; + default: + return R300_INVALID_FORMAT; + } + + if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) { + result |= R300_SIGNED; + } + if (desc->channel[i].normalized) { + result |= R300_NORMALIZE; + } + + return result; +} + +static INLINE uint16_t +r300_translate_vertex_data_swizzle(enum pipe_format format) { + const struct util_format_description *desc = util_format_description(format); + unsigned i, swizzle = 0; + + assert(format); + + if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { + fprintf(stderr, "r300: Bad format %s in %s:%d\n", + util_format_short_name(format), __FUNCTION__, __LINE__); + return 0; + } + + for (i = 0; i < desc->nr_channels; i++) { + swizzle |= + MIN2(desc->swizzle[i], R300_SWIZZLE_SELECT_FP_ONE) << (3*i); + } + /* Set (0,0,0,1) in unused components. */ + for (; i < 3; i++) { + swizzle |= R300_SWIZZLE_SELECT_FP_ZERO << (3*i); + } + for (; i < 4; i++) { + swizzle |= R300_SWIZZLE_SELECT_FP_ONE << (3*i); + } + + return swizzle | (0xf << R300_WRITE_ENA_SHIFT); +} + +#endif /* R300_STATE_INLINES_H */ diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c new file mode 100644 index 0000000..6d86bc2 --- /dev/null +++ b/src/gallium/drivers/r300/r300_texture.c @@ -0,0 +1,938 @@ +/* + * Copyright 2008 Corbin Simpson + * Copyright 2010 Marek Olšák + * + * 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. */ + +/* Always include headers in the reverse order!! ~ M. */ +#include "r300_texture.h" + +#include "r300_context.h" +#include "r300_reg.h" +#include "r300_texture_desc.h" +#include "r300_transfer.h" +#include "r300_screen.h" +#include "r300_winsys.h" + +#include "util/u_format.h" +#include "util/u_format_s3tc.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_mm.h" + +#include "pipe/p_screen.h" + +unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format, + const unsigned char *swizzle_view, + boolean dxtc_swizzle) +{ + unsigned i; + unsigned char swizzle[4]; + unsigned result = 0; + const uint32_t swizzle_shift[4] = { + R300_TX_FORMAT_R_SHIFT, + R300_TX_FORMAT_G_SHIFT, + R300_TX_FORMAT_B_SHIFT, + R300_TX_FORMAT_A_SHIFT + }; + uint32_t swizzle_bit[4] = { + dxtc_swizzle ? R300_TX_FORMAT_Z : R300_TX_FORMAT_X, + R300_TX_FORMAT_Y, + dxtc_swizzle ? R300_TX_FORMAT_X : R300_TX_FORMAT_Z, + R300_TX_FORMAT_W + }; + + if (swizzle_view) { + /* Combine two sets of swizzles. */ + for (i = 0; i < 4; i++) { + swizzle[i] = swizzle_view[i] <= UTIL_FORMAT_SWIZZLE_W ? + swizzle_format[swizzle_view[i]] : swizzle_view[i]; + } + } else { + memcpy(swizzle, swizzle_format, 4); + } + + /* Get swizzle. */ + for (i = 0; i < 4; i++) { + switch (swizzle[i]) { + case UTIL_FORMAT_SWIZZLE_Y: + result |= swizzle_bit[1] << swizzle_shift[i]; + break; + case UTIL_FORMAT_SWIZZLE_Z: + result |= swizzle_bit[2] << swizzle_shift[i]; + break; + case UTIL_FORMAT_SWIZZLE_W: + result |= swizzle_bit[3] << swizzle_shift[i]; + break; + case UTIL_FORMAT_SWIZZLE_0: + result |= R300_TX_FORMAT_ZERO << swizzle_shift[i]; + break; + case UTIL_FORMAT_SWIZZLE_1: + result |= R300_TX_FORMAT_ONE << swizzle_shift[i]; + break; + default: /* UTIL_FORMAT_SWIZZLE_X */ + result |= swizzle_bit[0] << swizzle_shift[i]; + } + } + return result; +} + +/* Translate a pipe_format into a useful texture format for sampling. + * + * Some special formats are translated directly using R300_EASY_TX_FORMAT, + * but the majority of them is translated in a generic way, automatically + * supporting all the formats hw can support. + * + * R300_EASY_TX_FORMAT swizzles the texture. + * Note the signature of R300_EASY_TX_FORMAT: + * R300_EASY_TX_FORMAT(B, G, R, A, FORMAT); + * + * The FORMAT specifies how the texture sampler will treat the texture, and + * makes available X, Y, Z, W, ZERO, and ONE for swizzling. */ +uint32_t r300_translate_texformat(enum pipe_format format, + const unsigned char *swizzle_view, + boolean is_r500, + boolean dxtc_swizzle) +{ + uint32_t result = 0; + const struct util_format_description *desc; + unsigned i; + boolean uniform = TRUE; + const uint32_t sign_bit[4] = { + R300_TX_FORMAT_SIGNED_X, + R300_TX_FORMAT_SIGNED_Y, + R300_TX_FORMAT_SIGNED_Z, + R300_TX_FORMAT_SIGNED_W, + }; + + desc = util_format_description(format); + + /* Colorspace (return non-RGB formats directly). */ + switch (desc->colorspace) { + /* Depth stencil formats. + * Swizzles are added in r300_merge_textures_and_samplers. */ + case UTIL_FORMAT_COLORSPACE_ZS: + switch (format) { + case PIPE_FORMAT_Z16_UNORM: + return R300_TX_FORMAT_X16; + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + if (is_r500) + return R500_TX_FORMAT_Y8X24; + else + return R300_TX_FORMAT_Y16X16; + default: + return ~0; /* Unsupported. */ + } + + /* YUV formats. */ + case UTIL_FORMAT_COLORSPACE_YUV: + result |= R300_TX_FORMAT_YUV_TO_RGB; + + switch (format) { + case PIPE_FORMAT_UYVY: + return R300_EASY_TX_FORMAT(X, Y, Z, ONE, YVYU422) | result; + case PIPE_FORMAT_YUYV: + return R300_EASY_TX_FORMAT(X, Y, Z, ONE, VYUY422) | result; + default: + return ~0; /* Unsupported/unknown. */ + } + + /* Add gamma correction. */ + case UTIL_FORMAT_COLORSPACE_SRGB: + result |= R300_TX_FORMAT_GAMMA; + break; + + default: + switch (format) { + /* Same as YUV but without the YUR->RGB conversion. */ + case PIPE_FORMAT_R8G8_B8G8_UNORM: + return R300_EASY_TX_FORMAT(X, Y, Z, ONE, YVYU422) | result; + case PIPE_FORMAT_G8R8_G8B8_UNORM: + return R300_EASY_TX_FORMAT(X, Y, Z, ONE, VYUY422) | result; + default:; + } + } + + result |= r300_get_swizzle_combined(desc->swizzle, swizzle_view, + util_format_is_compressed(format) && dxtc_swizzle); + + /* S3TC formats. */ + if (desc->layout == UTIL_FORMAT_LAYOUT_S3TC) { + if (!util_format_s3tc_enabled) { + return ~0; /* Unsupported. */ + } + + switch (format) { + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + case PIPE_FORMAT_DXT1_SRGB: + case PIPE_FORMAT_DXT1_SRGBA: + return R300_TX_FORMAT_DXT1 | result; + case PIPE_FORMAT_DXT3_RGBA: + case PIPE_FORMAT_DXT3_SRGBA: + return R300_TX_FORMAT_DXT3 | result; + case PIPE_FORMAT_DXT5_RGBA: + case PIPE_FORMAT_DXT5_SRGBA: + return R300_TX_FORMAT_DXT5 | result; + default: + return ~0; /* Unsupported/unknown. */ + } + } + + /* Add sign. */ + for (i = 0; i < desc->nr_channels; i++) { + if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) { + result |= sign_bit[i]; + } + } + + /* This is truly a special format. + * It stores R8G8 and B is computed using sqrt(1 - R^2 - G^2) + * in the sampler unit. Also known as D3DFMT_CxV8U8. */ + if (format == PIPE_FORMAT_R8G8Bx_SNORM) { + return R300_TX_FORMAT_CxV8U8 | result; + } + + /* RGTC formats. */ + if (desc->layout == UTIL_FORMAT_LAYOUT_RGTC) { + switch (format) { + case PIPE_FORMAT_RGTC1_UNORM: + case PIPE_FORMAT_RGTC1_SNORM: + return R500_TX_FORMAT_ATI1N | result; + case PIPE_FORMAT_RGTC2_UNORM: + case PIPE_FORMAT_RGTC2_SNORM: + return R400_TX_FORMAT_ATI2N | result; + default: + return ~0; /* Unsupported/unknown. */ + } + } + + /* See whether the components are of the same size. */ + for (i = 1; i < desc->nr_channels; i++) { + uniform = uniform && desc->channel[0].size == desc->channel[i].size; + } + + /* Non-uniform formats. */ + if (!uniform) { + switch (desc->nr_channels) { + case 3: + if (desc->channel[0].size == 5 && + desc->channel[1].size == 6 && + desc->channel[2].size == 5) { + return R300_TX_FORMAT_Z5Y6X5 | result; + } + if (desc->channel[0].size == 5 && + desc->channel[1].size == 5 && + desc->channel[2].size == 6) { + return R300_TX_FORMAT_Z6Y5X5 | result; + } + return ~0; /* Unsupported/unknown. */ + + case 4: + if (desc->channel[0].size == 5 && + desc->channel[1].size == 5 && + desc->channel[2].size == 5 && + desc->channel[3].size == 1) { + return R300_TX_FORMAT_W1Z5Y5X5 | result; + } + if (desc->channel[0].size == 10 && + desc->channel[1].size == 10 && + desc->channel[2].size == 10 && + desc->channel[3].size == 2) { + return R300_TX_FORMAT_W2Z10Y10X10 | result; + } + } + return ~0; /* Unsupported/unknown. */ + } + + /* Find the first non-VOID channel. */ + for (i = 0; i < 4; i++) { + if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { + break; + } + } + + if (i == 4) + return ~0; /* Unsupported/unknown. */ + + /* And finally, uniform formats. */ + switch (desc->channel[i].type) { + case UTIL_FORMAT_TYPE_UNSIGNED: + case UTIL_FORMAT_TYPE_SIGNED: + if (!desc->channel[i].normalized && + desc->colorspace != UTIL_FORMAT_COLORSPACE_SRGB) { + return ~0; + } + + switch (desc->channel[i].size) { + case 4: + switch (desc->nr_channels) { + case 2: + return R300_TX_FORMAT_Y4X4 | result; + case 4: + return R300_TX_FORMAT_W4Z4Y4X4 | result; + } + return ~0; + + case 8: + switch (desc->nr_channels) { + case 1: + return R300_TX_FORMAT_X8 | result; + case 2: + return R300_TX_FORMAT_Y8X8 | result; + case 4: + return R300_TX_FORMAT_W8Z8Y8X8 | result; + } + return ~0; + + case 16: + switch (desc->nr_channels) { + case 1: + return R300_TX_FORMAT_X16 | result; + case 2: + return R300_TX_FORMAT_Y16X16 | result; + case 4: + return R300_TX_FORMAT_W16Z16Y16X16 | result; + } + } + return ~0; + + case UTIL_FORMAT_TYPE_FLOAT: + switch (desc->channel[i].size) { + case 16: + switch (desc->nr_channels) { + case 1: + return R300_TX_FORMAT_16F | result; + case 2: + return R300_TX_FORMAT_16F_16F | result; + case 4: + return R300_TX_FORMAT_16F_16F_16F_16F | result; + } + return ~0; + + case 32: + switch (desc->nr_channels) { + case 1: + return R300_TX_FORMAT_32F | result; + case 2: + return R300_TX_FORMAT_32F_32F | result; + case 4: + return R300_TX_FORMAT_32F_32F_32F_32F | result; + } + } + } + + return ~0; /* Unsupported/unknown. */ +} + +uint32_t r500_tx_format_msb_bit(enum pipe_format format) +{ + switch (format) { + case PIPE_FORMAT_RGTC1_UNORM: + case PIPE_FORMAT_RGTC1_SNORM: + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + return R500_TXFORMAT_MSB; + default: + return 0; + } +} + +/* Buffer formats. */ + +/* Colorbuffer formats. This is the unswizzled format of the RB3D block's + * output. For the swizzling of the targets, check the shader's format. */ +static uint32_t r300_translate_colorformat(enum pipe_format format) +{ + switch (format) { + /* 8-bit buffers. */ + case PIPE_FORMAT_A8_UNORM: + case PIPE_FORMAT_I8_UNORM: + case PIPE_FORMAT_L8_UNORM: + case PIPE_FORMAT_R8_UNORM: + case PIPE_FORMAT_R8_SNORM: + return R300_COLOR_FORMAT_I8; + + /* 16-bit buffers. */ + case PIPE_FORMAT_L8A8_UNORM: + case PIPE_FORMAT_R8G8_UNORM: + case PIPE_FORMAT_R8G8_SNORM: + return R300_COLOR_FORMAT_UV88; + + case PIPE_FORMAT_B5G6R5_UNORM: + return R300_COLOR_FORMAT_RGB565; + + case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B5G5R5X1_UNORM: + return R300_COLOR_FORMAT_ARGB1555; + + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B4G4R4X4_UNORM: + return R300_COLOR_FORMAT_ARGB4444; + + /* 32-bit buffers. */ + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_A8B8G8R8_UNORM: + case PIPE_FORMAT_R8G8B8A8_SNORM: + case PIPE_FORMAT_X8B8G8R8_UNORM: + case PIPE_FORMAT_R8G8B8X8_UNORM: + case PIPE_FORMAT_R8SG8SB8UX8U_NORM: + return R300_COLOR_FORMAT_ARGB8888; + + case PIPE_FORMAT_R10G10B10A2_UNORM: + case PIPE_FORMAT_R10G10B10X2_SNORM: + case PIPE_FORMAT_B10G10R10A2_UNORM: + case PIPE_FORMAT_R10SG10SB10SA2U_NORM: + return R500_COLOR_FORMAT_ARGB2101010; /* R5xx-only? */ + + /* 64-bit buffers. */ + case PIPE_FORMAT_R16G16B16A16_UNORM: + case PIPE_FORMAT_R16G16B16A16_SNORM: + case PIPE_FORMAT_R16G16B16A16_FLOAT: + return R300_COLOR_FORMAT_ARGB16161616; + + /* 128-bit buffers. */ + case PIPE_FORMAT_R32G32B32A32_FLOAT: + return R300_COLOR_FORMAT_ARGB32323232; + + /* YUV buffers. */ + case PIPE_FORMAT_UYVY: + return R300_COLOR_FORMAT_YVYU; + case PIPE_FORMAT_YUYV: + return R300_COLOR_FORMAT_VYUY; + default: + return ~0; /* Unsupported. */ + } +} + +/* Depthbuffer and stencilbuffer. Thankfully, we only support two flavors. */ +static uint32_t r300_translate_zsformat(enum pipe_format format) +{ + switch (format) { + /* 16-bit depth, no stencil */ + case PIPE_FORMAT_Z16_UNORM: + return R300_DEPTHFORMAT_16BIT_INT_Z; + /* 24-bit depth, ignored stencil */ + case PIPE_FORMAT_X8Z24_UNORM: + /* 24-bit depth, 8-bit stencil */ + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + return R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL; + default: + return ~0; /* Unsupported. */ + } +} + +/* Shader output formats. This is essentially the swizzle from the shader + * to the RB3D block. + * + * Note that formats are stored from C3 to C0. */ +static uint32_t r300_translate_out_fmt(enum pipe_format format) +{ + uint32_t modifier = 0; + unsigned i; + const struct util_format_description *desc; + static const uint32_t sign_bit[4] = { + R300_OUT_SIGN(0x1), + R300_OUT_SIGN(0x2), + R300_OUT_SIGN(0x4), + R300_OUT_SIGN(0x8), + }; + + desc = util_format_description(format); + + /* Find the first non-VOID channel. */ + for (i = 0; i < 4; i++) { + if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { + break; + } + } + + if (i == 4) + return ~0; /* Unsupported/unknown. */ + + /* Specifies how the shader output is written to the fog unit. */ + if (desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT) { + if (desc->channel[i].size == 32) { + modifier |= R300_US_OUT_FMT_C4_32_FP; + } else { + modifier |= R300_US_OUT_FMT_C4_16_FP; + } + } else { + if (desc->channel[i].size == 16) { + modifier |= R300_US_OUT_FMT_C4_16; + } else { + /* C4_8 seems to be used for the formats whose pixel size + * is <= 32 bits. */ + modifier |= R300_US_OUT_FMT_C4_8; + } + } + + /* Add sign. */ + for (i = 0; i < 4; i++) + if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) { + modifier |= sign_bit[i]; + } + + /* Add swizzles and return. */ + switch (format) { + /* 8-bit outputs, one channel. + * COLORFORMAT_I8 stores the C2 component. */ + case PIPE_FORMAT_A8_UNORM: + return modifier | R300_C2_SEL_A; + case PIPE_FORMAT_I8_UNORM: + case PIPE_FORMAT_L8_UNORM: + case PIPE_FORMAT_R8_UNORM: + case PIPE_FORMAT_R8_SNORM: + return modifier | R300_C2_SEL_R; + + /* 16-bit outputs, two channels. + * COLORFORMAT_UV88 stores C2 and C0. */ + case PIPE_FORMAT_L8A8_UNORM: + return modifier | R300_C0_SEL_A | R300_C2_SEL_R; + case PIPE_FORMAT_R8G8_UNORM: + case PIPE_FORMAT_R8G8_SNORM: + return modifier | R300_C0_SEL_G | R300_C2_SEL_R; + + /* BGRA outputs. */ + case PIPE_FORMAT_B5G6R5_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B5G5R5X1_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B4G4R4X4_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_B10G10R10A2_UNORM: + return modifier | + R300_C0_SEL_B | R300_C1_SEL_G | + R300_C2_SEL_R | R300_C3_SEL_A; + + /* ARGB outputs. */ + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_X8R8G8B8_UNORM: + return modifier | + R300_C0_SEL_A | R300_C1_SEL_R | + R300_C2_SEL_G | R300_C3_SEL_B; + + /* ABGR outputs. */ + case PIPE_FORMAT_A8B8G8R8_UNORM: + case PIPE_FORMAT_X8B8G8R8_UNORM: + return modifier | + R300_C0_SEL_A | R300_C1_SEL_B | + R300_C2_SEL_G | R300_C3_SEL_R; + + /* RGBA outputs. */ + case PIPE_FORMAT_R8G8B8X8_UNORM: + case PIPE_FORMAT_R8G8B8A8_SNORM: + case PIPE_FORMAT_R8SG8SB8UX8U_NORM: + case PIPE_FORMAT_R10G10B10A2_UNORM: + case PIPE_FORMAT_R10G10B10X2_SNORM: + case PIPE_FORMAT_R10SG10SB10SA2U_NORM: + case PIPE_FORMAT_R16G16B16A16_UNORM: + case PIPE_FORMAT_R16G16B16A16_SNORM: + case PIPE_FORMAT_R16G16B16A16_FLOAT: + case PIPE_FORMAT_R32G32B32A32_FLOAT: + return modifier | + R300_C0_SEL_R | R300_C1_SEL_G | + R300_C2_SEL_B | R300_C3_SEL_A; + + default: + return ~0; /* Unsupported. */ + } +} + +boolean r300_is_colorbuffer_format_supported(enum pipe_format format) +{ + return r300_translate_colorformat(format) != ~0 && + r300_translate_out_fmt(format) != ~0; +} + +boolean r300_is_zs_format_supported(enum pipe_format format) +{ + return r300_translate_zsformat(format) != ~0; +} + +boolean r300_is_sampler_format_supported(enum pipe_format format) +{ + return r300_translate_texformat(format, 0, TRUE, FALSE) != ~0; +} + +void r300_texture_setup_format_state(struct r300_screen *screen, + struct r300_texture_desc *desc, + unsigned level, + struct r300_texture_format_state *out) +{ + struct pipe_resource *pt = &desc->b.b; + boolean is_r500 = screen->caps.is_r500; + + /* Mask out all the fields we change. */ + out->format0 = 0; + out->format1 &= ~R300_TX_FORMAT_TEX_COORD_TYPE_MASK; + out->format2 &= R500_TXFORMAT_MSB; + out->tile_config = 0; + + /* Set sampler state. */ + out->format0 = + R300_TX_WIDTH((u_minify(desc->width0, level) - 1) & 0x7ff) | + R300_TX_HEIGHT((u_minify(desc->height0, level) - 1) & 0x7ff) | + R300_TX_DEPTH(util_logbase2(u_minify(desc->depth0, level)) & 0xf); + + if (desc->uses_stride_addressing) { + /* rectangles love this */ + out->format0 |= R300_TX_PITCH_EN; + out->format2 = (desc->stride_in_pixels[level] - 1) & 0x1fff; + } + + if (pt->target == PIPE_TEXTURE_CUBE) { + out->format1 |= R300_TX_FORMAT_CUBIC_MAP; + } + if (pt->target == PIPE_TEXTURE_3D) { + out->format1 |= R300_TX_FORMAT_3D; + } + + /* large textures on r500 */ + if (is_r500) + { + if (desc->width0 > 2048) { + out->format2 |= R500_TXWIDTH_BIT11; + } + if (desc->height0 > 2048) { + out->format2 |= R500_TXHEIGHT_BIT11; + } + } + + out->tile_config = R300_TXO_MACRO_TILE(desc->macrotile[level]) | + R300_TXO_MICRO_TILE(desc->microtile); +} + +static void r300_texture_setup_fb_state(struct r300_screen* screen, + struct r300_texture* tex) +{ + unsigned i; + + /* Set framebuffer state. */ + if (util_format_is_depth_or_stencil(tex->desc.b.b.format)) { + for (i = 0; i <= tex->desc.b.b.last_level; i++) { + tex->fb_state.pitch[i] = + tex->desc.stride_in_pixels[i] | + R300_DEPTHMACROTILE(tex->desc.macrotile[i]) | + R300_DEPTHMICROTILE(tex->desc.microtile); + } + tex->fb_state.format = r300_translate_zsformat(tex->desc.b.b.format); + } else { + for (i = 0; i <= tex->desc.b.b.last_level; i++) { + tex->fb_state.pitch[i] = + tex->desc.stride_in_pixels[i] | + r300_translate_colorformat(tex->desc.b.b.format) | + R300_COLOR_TILE(tex->desc.macrotile[i]) | + R300_COLOR_MICROTILE(tex->desc.microtile); + } + tex->fb_state.format = r300_translate_out_fmt(tex->desc.b.b.format); + } +} + +void r300_texture_reinterpret_format(struct pipe_screen *screen, + struct pipe_resource *tex, + enum pipe_format new_format) +{ + struct r300_screen *r300screen = r300_screen(screen); + + SCREEN_DBG(r300screen, DBG_TEX, + "r300: texture_reinterpret_format: %s -> %s\n", + util_format_short_name(tex->format), + util_format_short_name(new_format)); + + tex->format = new_format; + + r300_texture_setup_fb_state(r300_screen(screen), r300_texture(tex)); +} + +static unsigned r300_texture_is_referenced(struct pipe_context *context, + struct pipe_resource *texture, + unsigned level, int layer) +{ + struct r300_context *r300 = r300_context(context); + struct r300_texture *rtex = (struct r300_texture *)texture; + + if (r300->rws->cs_is_buffer_referenced(r300->cs, + rtex->cs_buffer, R300_REF_CS)) + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; + + return PIPE_UNREFERENCED; +} + +static void r300_texture_destroy(struct pipe_screen *screen, + struct pipe_resource* texture) +{ + struct r300_texture* tex = (struct r300_texture*)texture; + struct r300_winsys_screen *rws = (struct r300_winsys_screen *)texture->screen->winsys; + int i; + + rws->buffer_reference(rws, &tex->buffer, NULL); + for (i = 0; i < R300_MAX_TEXTURE_LEVELS; i++) { + if (tex->hiz_mem[i]) + u_mmFreeMem(tex->hiz_mem[i]); + if (tex->zmask_mem[i]) + u_mmFreeMem(tex->zmask_mem[i]); + } + + FREE(tex); +} + +static boolean r300_texture_get_handle(struct pipe_screen* screen, + struct pipe_resource *texture, + struct winsys_handle *whandle) +{ + struct r300_winsys_screen *rws = (struct r300_winsys_screen *)screen->winsys; + struct r300_texture* tex = (struct r300_texture*)texture; + + if (!tex) { + return FALSE; + } + + return rws->buffer_get_handle(rws, tex->buffer, + tex->desc.stride_in_bytes[0], whandle); +} + +struct u_resource_vtbl r300_texture_vtbl = +{ + r300_texture_get_handle, /* get_handle */ + r300_texture_destroy, /* resource_destroy */ + r300_texture_is_referenced, /* is_resource_referenced */ + r300_texture_get_transfer, /* get_transfer */ + r300_texture_transfer_destroy, /* transfer_destroy */ + r300_texture_transfer_map, /* transfer_map */ + u_default_transfer_flush_region, /* transfer_flush_region */ + r300_texture_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; + +/* The common texture constructor. */ +static struct r300_texture* +r300_texture_create_object(struct r300_screen *rscreen, + const struct pipe_resource *base, + enum r300_buffer_tiling microtile, + enum r300_buffer_tiling macrotile, + unsigned stride_in_bytes_override, + unsigned max_buffer_size, + struct r300_winsys_buffer *buffer) +{ + struct r300_winsys_screen *rws = rscreen->rws; + struct r300_texture *tex = CALLOC_STRUCT(r300_texture); + if (!tex) { + if (buffer) + rws->buffer_reference(rws, &buffer, NULL); + return NULL; + } + + /* Initialize the descriptor. */ + if (!r300_texture_desc_init(rscreen, &tex->desc, base, + microtile, macrotile, + stride_in_bytes_override, + max_buffer_size)) { + if (buffer) + rws->buffer_reference(rws, &buffer, NULL); + FREE(tex); + return NULL; + } + /* Initialize the hardware state. */ + r300_texture_setup_format_state(rscreen, &tex->desc, 0, &tex->tx_format); + r300_texture_setup_fb_state(rscreen, tex); + + tex->desc.b.vtbl = &r300_texture_vtbl; + pipe_reference_init(&tex->desc.b.b.reference, 1); + tex->domain = base->flags & R300_RESOURCE_FLAG_TRANSFER ? + R300_DOMAIN_GTT : + R300_DOMAIN_VRAM | R300_DOMAIN_GTT; + tex->buffer = buffer; + + /* Create the backing buffer if needed. */ + if (!tex->buffer) { + tex->buffer = rws->buffer_create(rws, tex->desc.size_in_bytes, 2048, + base->bind, base->usage, tex->domain); + + if (!tex->buffer) { + FREE(tex); + return NULL; + } + } + + tex->cs_buffer = rws->buffer_get_cs_handle(rws, tex->buffer); + + rws->buffer_set_tiling(rws, tex->buffer, + tex->desc.microtile, tex->desc.macrotile[0], + tex->desc.stride_in_bytes[0]); + + return tex; +} + +/* Create a new texture. */ +struct pipe_resource *r300_texture_create(struct pipe_screen *screen, + const struct pipe_resource *base) +{ + struct r300_screen *rscreen = r300_screen(screen); + enum r300_buffer_tiling microtile, macrotile; + + if ((base->flags & R300_RESOURCE_FLAG_TRANSFER) || + (base->bind & PIPE_BIND_SCANOUT)) { + microtile = R300_BUFFER_LINEAR; + macrotile = R300_BUFFER_LINEAR; + } else { + microtile = R300_BUFFER_SELECT_LAYOUT; + macrotile = R300_BUFFER_SELECT_LAYOUT; + } + + return (struct pipe_resource*) + r300_texture_create_object(rscreen, base, microtile, macrotile, + 0, 0, NULL); +} + +struct pipe_resource *r300_texture_from_handle(struct pipe_screen *screen, + const struct pipe_resource *base, + struct winsys_handle *whandle) +{ + struct r300_winsys_screen *rws = (struct r300_winsys_screen*)screen->winsys; + struct r300_screen *rscreen = r300_screen(screen); + struct r300_winsys_buffer *buffer; + enum r300_buffer_tiling microtile, macrotile; + unsigned stride, size; + + /* Support only 2D textures without mipmaps */ + if ((base->target != PIPE_TEXTURE_2D && + base->target != PIPE_TEXTURE_RECT) || + base->depth0 != 1 || + base->last_level != 0) { + return NULL; + } + + buffer = rws->buffer_from_handle(rws, whandle, &stride, &size); + if (!buffer) + return NULL; + + rws->buffer_get_tiling(rws, buffer, µtile, ¯otile); + + /* Enforce a microtiled zbuffer. */ + if (util_format_is_depth_or_stencil(base->format) && + microtile == R300_BUFFER_LINEAR) { + switch (util_format_get_blocksize(base->format)) { + case 4: + microtile = R300_BUFFER_TILED; + break; + + case 2: + if (rws->get_value(rws, R300_VID_SQUARE_TILING_SUPPORT)) + microtile = R300_BUFFER_SQUARETILED; + break; + } + } + + return (struct pipe_resource*) + r300_texture_create_object(rscreen, base, microtile, macrotile, + stride, size, buffer); +} + +/* Not required to implement u_resource_vtbl, consider moving to another file: + */ +struct pipe_surface* r300_create_surface(struct pipe_context * ctx, + struct pipe_resource* texture, + const struct pipe_surface *surf_tmpl) +{ + struct r300_texture* tex = r300_texture(texture); + struct r300_surface* surface = CALLOC_STRUCT(r300_surface); + unsigned level = surf_tmpl->u.tex.level; + + assert(surf_tmpl->u.tex.first_layer == surf_tmpl->u.tex.last_layer); + + if (surface) { + uint32_t offset, tile_height; + + pipe_reference_init(&surface->base.reference, 1); + pipe_resource_reference(&surface->base.texture, texture); + surface->base.context = ctx; + surface->base.format = surf_tmpl->format; + surface->base.width = u_minify(texture->width0, level); + surface->base.height = u_minify(texture->height0, level); + surface->base.usage = surf_tmpl->usage; + surface->base.u.tex.level = level; + surface->base.u.tex.first_layer = surf_tmpl->u.tex.first_layer; + surface->base.u.tex.last_layer = surf_tmpl->u.tex.last_layer; + + surface->buffer = tex->buffer; + surface->cs_buffer = tex->cs_buffer; + + /* Prefer VRAM if there are multiple domains to choose from. */ + surface->domain = tex->domain; + if (surface->domain & R300_DOMAIN_VRAM) + surface->domain &= ~R300_DOMAIN_GTT; + + surface->offset = r300_texture_get_offset(&tex->desc, level, + surf_tmpl->u.tex.first_layer); + surface->pitch = tex->fb_state.pitch[level]; + surface->format = tex->fb_state.format; + + /* Parameters for the CBZB clear. */ + surface->cbzb_allowed = tex->desc.cbzb_allowed[level]; + surface->cbzb_width = align(surface->base.width, 64); + + /* Height must be aligned to the size of a tile. */ + tile_height = r300_get_pixel_alignment(tex->desc.b.b.format, + tex->desc.b.b.nr_samples, + tex->desc.microtile, + tex->desc.macrotile[level], + DIM_HEIGHT, 0); + + surface->cbzb_height = align((surface->base.height + 1) / 2, + tile_height); + + /* Offset must be aligned to 2K and must point at the beginning + * of a scanline. */ + offset = surface->offset + + tex->desc.stride_in_bytes[level] * surface->cbzb_height; + surface->cbzb_midpoint_offset = offset & ~2047; + + surface->cbzb_pitch = surface->pitch & 0x1ffffc; + + if (util_format_get_blocksizebits(surface->base.format) == 32) + surface->cbzb_format = R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL; + else + surface->cbzb_format = R300_DEPTHFORMAT_16BIT_INT_Z; + + DBG(r300_context(ctx), DBG_CBZB, + "CBZB Allowed: %s, Dim: %ix%i, Misalignment: %i, Micro: %s, Macro: %s\n", + surface->cbzb_allowed ? "YES" : " NO", + surface->cbzb_width, surface->cbzb_height, + offset & 2047, + tex->desc.microtile ? "YES" : " NO", + tex->desc.macrotile[level] ? "YES" : " NO"); + } + + return &surface->base; +} + +/* Not required to implement u_resource_vtbl, consider moving to another file: + */ +void r300_surface_destroy(struct pipe_context *ctx, struct pipe_surface* s) +{ + pipe_resource_reference(&s->texture, NULL); + FREE(s); +} diff --git a/src/gallium/drivers/r300/r300_texture.h b/src/gallium/drivers/r300/r300_texture.h new file mode 100644 index 0000000..0ab22f7 --- /dev/null +++ b/src/gallium/drivers/r300/r300_texture.h @@ -0,0 +1,80 @@ +/* + * 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 R300_TEXTURE_H +#define R300_TEXTURE_H + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" + +struct pipe_screen; +struct pipe_context; +struct pipe_resource; +struct winsys_handle; +struct r300_texture_format_state; +struct r300_texture_desc; +struct r300_texture; +struct r300_screen; + +unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format, + const unsigned char *swizzle_view, + boolean dxtc_swizzle); + +uint32_t r300_translate_texformat(enum pipe_format format, + const unsigned char *swizzle_view, + boolean is_r500, + boolean dxtc_swizzle); + +uint32_t r500_tx_format_msb_bit(enum pipe_format format); + +void r300_texture_reinterpret_format(struct pipe_screen *screen, + struct pipe_resource *tex, + enum pipe_format new_format); + +boolean r300_is_colorbuffer_format_supported(enum pipe_format format); + +boolean r300_is_zs_format_supported(enum pipe_format format); + +boolean r300_is_sampler_format_supported(enum pipe_format format); + +void r300_texture_setup_format_state(struct r300_screen *screen, + struct r300_texture_desc *desc, + unsigned level, + struct r300_texture_format_state *out); + +struct pipe_resource* +r300_texture_from_handle(struct pipe_screen* screen, + const struct pipe_resource* base, + struct winsys_handle *whandle); + +struct pipe_resource* +r300_texture_create(struct pipe_screen* screen, + const struct pipe_resource* templ); + + +struct pipe_surface* r300_create_surface(struct pipe_context *ctx, + struct pipe_resource* texture, + const struct pipe_surface *surf_tmpl); + +void r300_surface_destroy(struct pipe_context *ctx, struct pipe_surface* s); + +#endif /* R300_TEXTURE_H */ diff --git a/src/gallium/drivers/r300/r300_texture_desc.c b/src/gallium/drivers/r300/r300_texture_desc.c new file mode 100644 index 0000000..7b17391 --- /dev/null +++ b/src/gallium/drivers/r300/r300_texture_desc.c @@ -0,0 +1,478 @@ +/* + * Copyright 2008 Corbin Simpson + * Copyright 2010 Marek Olšák + * + * 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 "r300_texture_desc.h" + +#include "r300_context.h" +#include "r300_winsys.h" + +#include "util/u_format.h" + +/* Returns the number of pixels that the texture should be aligned to + * in the given dimension. */ +unsigned r300_get_pixel_alignment(enum pipe_format format, + unsigned num_samples, + enum r300_buffer_tiling microtile, + enum r300_buffer_tiling macrotile, + enum r300_dim dim, boolean is_rs690) +{ + static const unsigned table[2][5][3][2] = + { + { + /* Macro: linear linear linear + Micro: linear tiled square-tiled */ + {{ 32, 1}, { 8, 4}, { 0, 0}}, /* 8 bits per pixel */ + {{ 16, 1}, { 8, 2}, { 4, 4}}, /* 16 bits per pixel */ + {{ 8, 1}, { 4, 2}, { 0, 0}}, /* 32 bits per pixel */ + {{ 4, 1}, { 2, 2}, { 0, 0}}, /* 64 bits per pixel */ + {{ 2, 1}, { 0, 0}, { 0, 0}} /* 128 bits per pixel */ + }, + { + /* Macro: tiled tiled tiled + Micro: linear tiled square-tiled */ + {{256, 8}, {64, 32}, { 0, 0}}, /* 8 bits per pixel */ + {{128, 8}, {64, 16}, {32, 32}}, /* 16 bits per pixel */ + {{ 64, 8}, {32, 16}, { 0, 0}}, /* 32 bits per pixel */ + {{ 32, 8}, {16, 16}, { 0, 0}}, /* 64 bits per pixel */ + {{ 16, 8}, { 0, 0}, { 0, 0}} /* 128 bits per pixel */ + } + }; + + static const unsigned aa_block[2] = {4, 8}; + unsigned tile = 0; + unsigned pixsize = util_format_get_blocksize(format); + + assert(macrotile <= R300_BUFFER_TILED); + assert(microtile <= R300_BUFFER_SQUARETILED); + assert(pixsize <= 16); + assert(dim <= DIM_HEIGHT); + + if (num_samples > 1) { + /* Multisampled textures have their own alignment scheme. */ + if (pixsize == 4) + tile = aa_block[dim]; + /* XXX FP16 AA. */ + } else { + /* Standard alignment. */ + tile = table[macrotile][util_logbase2(pixsize)][microtile][dim]; + if (macrotile == 0 && is_rs690 && dim == DIM_WIDTH) { + int align; + int h_tile; + h_tile = table[macrotile][util_logbase2(pixsize)][microtile][DIM_HEIGHT]; + align = 64 / (pixsize * h_tile); + if (tile < align) + tile = align; + } + } + + assert(tile); + return tile; +} + +/* Return true if macrotiling should be enabled on the miplevel. */ +static boolean r300_texture_macro_switch(struct r300_texture_desc *desc, + unsigned level, + boolean rv350_mode, + enum r300_dim dim) +{ + unsigned tile, texdim; + + tile = r300_get_pixel_alignment(desc->b.b.format, desc->b.b.nr_samples, + desc->microtile, R300_BUFFER_TILED, dim, 0); + if (dim == DIM_WIDTH) { + texdim = u_minify(desc->width0, level); + } else { + texdim = u_minify(desc->height0, level); + } + + /* See TX_FILTER1_n.MACRO_SWITCH. */ + if (rv350_mode) { + return texdim >= tile; + } else { + return texdim > tile; + } +} + +/** + * Return the stride, in bytes, of the texture image of the given texture + * at the given level. + */ +static unsigned r300_texture_get_stride(struct r300_screen *screen, + struct r300_texture_desc *desc, + unsigned level) +{ + unsigned tile_width, width, stride; + boolean is_rs690 = (screen->caps.family == CHIP_FAMILY_RS600 || + screen->caps.family == CHIP_FAMILY_RS690 || + screen->caps.family == CHIP_FAMILY_RS740); + + if (desc->stride_in_bytes_override) + return desc->stride_in_bytes_override; + + /* Check the level. */ + if (level > desc->b.b.last_level) { + SCREEN_DBG(screen, DBG_TEX, "%s: level (%u) > last_level (%u)\n", + __FUNCTION__, level, desc->b.b.last_level); + return 0; + } + + width = u_minify(desc->width0, level); + + if (util_format_is_plain(desc->b.b.format)) { + tile_width = r300_get_pixel_alignment(desc->b.b.format, + desc->b.b.nr_samples, + desc->microtile, + desc->macrotile[level], + DIM_WIDTH, is_rs690); + width = align(width, tile_width); + + stride = util_format_get_stride(desc->b.b.format, width); + /* The alignment to 32 bytes is sort of implied by the layout... */ + return stride; + } else { + return align(util_format_get_stride(desc->b.b.format, width), is_rs690 ? 64 : 32); + } +} + +static unsigned r300_texture_get_nblocksy(struct r300_texture_desc *desc, + unsigned level, + boolean *out_aligned_for_cbzb) +{ + unsigned height, tile_height; + + height = u_minify(desc->height0, level); + + if (util_format_is_plain(desc->b.b.format)) { + tile_height = r300_get_pixel_alignment(desc->b.b.format, + desc->b.b.nr_samples, + desc->microtile, + desc->macrotile[level], + DIM_HEIGHT, 0); + height = align(height, tile_height); + + /* This is needed for the kernel checker, unfortunately. */ + if ((desc->b.b.target != PIPE_TEXTURE_1D && + desc->b.b.target != PIPE_TEXTURE_2D && + desc->b.b.target != PIPE_TEXTURE_RECT) || + desc->b.b.last_level != 0) { + height = util_next_power_of_two(height); + } + + /* See if the CBZB clear can be used on the buffer, + * taking the texture size into account. */ + if (out_aligned_for_cbzb) { + if (desc->macrotile[level]) { + /* When clearing, the layer (width*height) is horizontally split + * into two, and the upper and lower halves are cleared by the CB + * and ZB units, respectively. Therefore, the number of macrotiles + * in the Y direction must be even. */ + + /* Align the height so that there is an even number of macrotiles. + * Do so for 3 or more macrotiles in the Y direction. */ + if (level == 0 && desc->b.b.last_level == 0 && + (desc->b.b.target == PIPE_TEXTURE_1D || + desc->b.b.target == PIPE_TEXTURE_2D || + desc->b.b.target == PIPE_TEXTURE_RECT) && + height >= tile_height * 3) { + height = align(height, tile_height * 2); + } + + *out_aligned_for_cbzb = height % (tile_height * 2) == 0; + } else { + *out_aligned_for_cbzb = FALSE; + } + } + } + + return util_format_get_nblocksy(desc->b.b.format, height); +} + +static void r300_texture_3d_fix_mipmapping(struct r300_screen *screen, + struct r300_texture_desc *desc) +{ + /* The kernels <= 2.6.34-rc4 compute the size of mipmapped 3D textures + * incorrectly. This is a workaround to prevent CS from being rejected. */ + + unsigned i, size; + + if (!screen->rws->get_value(screen->rws, R300_VID_DRM_2_3_0) && + desc->b.b.target == PIPE_TEXTURE_3D && + desc->b.b.last_level > 0) { + size = 0; + + for (i = 0; i <= desc->b.b.last_level; i++) { + size += desc->stride_in_bytes[i] * + r300_texture_get_nblocksy(desc, i, FALSE); + } + + size *= desc->depth0; + desc->size_in_bytes = size; + } +} + +/* Get a width in pixels from a stride in bytes. */ +static unsigned stride_to_width(enum pipe_format format, + unsigned stride_in_bytes) +{ + return (stride_in_bytes / util_format_get_blocksize(format)) * + util_format_get_blockwidth(format); +} + +static void r300_setup_miptree(struct r300_screen *screen, + struct r300_texture_desc *desc, + boolean align_for_cbzb) +{ + struct pipe_resource *base = &desc->b.b; + unsigned stride, size, layer_size, nblocksy, i; + boolean rv350_mode = screen->caps.family >= CHIP_FAMILY_R350; + boolean aligned_for_cbzb; + + desc->size_in_bytes = 0; + + SCREEN_DBG(screen, DBG_TEXALLOC, + "r300: Making miptree for texture, format %s\n", + util_format_short_name(base->format)); + + for (i = 0; i <= base->last_level; i++) { + /* Let's see if this miplevel can be macrotiled. */ + desc->macrotile[i] = + (desc->macrotile[0] == R300_BUFFER_TILED && + r300_texture_macro_switch(desc, i, rv350_mode, DIM_WIDTH) && + r300_texture_macro_switch(desc, i, rv350_mode, DIM_HEIGHT)) ? + R300_BUFFER_TILED : R300_BUFFER_LINEAR; + + stride = r300_texture_get_stride(screen, desc, i); + + /* Compute the number of blocks in Y, see if the CBZB clear can be + * used on the texture. */ + aligned_for_cbzb = FALSE; + if (align_for_cbzb && desc->cbzb_allowed[i]) + nblocksy = r300_texture_get_nblocksy(desc, i, &aligned_for_cbzb); + else + nblocksy = r300_texture_get_nblocksy(desc, i, NULL); + + layer_size = stride * nblocksy; + + if (base->nr_samples) { + layer_size *= base->nr_samples; + } + + if (base->target == PIPE_TEXTURE_CUBE) + size = layer_size * 6; + else + size = layer_size * u_minify(desc->depth0, i); + + desc->offset_in_bytes[i] = desc->size_in_bytes; + desc->size_in_bytes = desc->offset_in_bytes[i] + size; + desc->layer_size_in_bytes[i] = layer_size; + desc->stride_in_bytes[i] = stride; + desc->stride_in_pixels[i] = stride_to_width(desc->b.b.format, stride); + desc->cbzb_allowed[i] = desc->cbzb_allowed[i] && aligned_for_cbzb; + + SCREEN_DBG(screen, DBG_TEXALLOC, "r300: Texture miptree: Level %d " + "(%dx%dx%d px, pitch %d bytes) %d bytes total, macrotiled %s\n", + i, u_minify(desc->width0, i), u_minify(desc->height0, i), + u_minify(desc->depth0, i), stride, desc->size_in_bytes, + desc->macrotile[i] ? "TRUE" : "FALSE"); + } +} + +static void r300_setup_flags(struct r300_texture_desc *desc) +{ + desc->uses_stride_addressing = + !util_is_power_of_two(desc->b.b.width0) || + (desc->stride_in_bytes_override && + stride_to_width(desc->b.b.format, + desc->stride_in_bytes_override) != desc->b.b.width0); + + desc->is_npot = + desc->uses_stride_addressing || + !util_is_power_of_two(desc->b.b.height0) || + !util_is_power_of_two(desc->b.b.depth0); +} + +static void r300_setup_cbzb_flags(struct r300_screen *rscreen, + struct r300_texture_desc *desc) +{ + unsigned i, bpp; + boolean first_level_valid; + + bpp = util_format_get_blocksizebits(desc->b.b.format); + + /* 1) The texture must be point-sampled, + * 2) The depth must be 16 or 32 bits. + * 3) If the midpoint ZB offset is not aligned to 2048, it returns garbage + * with certain texture sizes. Macrotiling ensures the alignment. */ + first_level_valid = desc->b.b.nr_samples <= 1 && + (bpp == 16 || bpp == 32) && + desc->macrotile[0]; + + if (SCREEN_DBG_ON(rscreen, DBG_NO_CBZB)) + first_level_valid = FALSE; + + for (i = 0; i <= desc->b.b.last_level; i++) + desc->cbzb_allowed[i] = first_level_valid && desc->macrotile[i]; +} + +static void r300_setup_tiling(struct r300_screen *screen, + struct r300_texture_desc *desc) +{ + struct r300_winsys_screen *rws = screen->rws; + enum pipe_format format = desc->b.b.format; + boolean rv350_mode = screen->caps.family >= CHIP_FAMILY_R350; + boolean is_zb = util_format_is_depth_or_stencil(format); + boolean dbg_no_tiling = SCREEN_DBG_ON(screen, DBG_NO_TILING); + + if (!util_format_is_plain(format)) { + return; + } + + /* If height == 1, disable microtiling except for zbuffer. */ + if (!is_zb && (desc->b.b.height0 == 1 || dbg_no_tiling)) { + return; + } + + /* Set microtiling. */ + switch (util_format_get_blocksize(format)) { + case 1: + case 4: + case 8: + desc->microtile = R300_BUFFER_TILED; + break; + + case 2: + if (rws->get_value(rws, R300_VID_SQUARE_TILING_SUPPORT)) { + desc->microtile = R300_BUFFER_SQUARETILED; + } + break; + } + + if (dbg_no_tiling) { + return; + } + + /* Set macrotiling. */ + if (r300_texture_macro_switch(desc, 0, rv350_mode, DIM_WIDTH) && + r300_texture_macro_switch(desc, 0, rv350_mode, DIM_HEIGHT)) { + desc->macrotile[0] = R300_BUFFER_TILED; + } +} + +static void r300_tex_print_info(struct r300_screen *rscreen, + struct r300_texture_desc *desc, + const char *func) +{ + fprintf(stderr, + "r300: %s: Macro: %s, Micro: %s, Pitch: %i, Dim: %ix%ix%i, " + "LastLevel: %i, Size: %i, Format: %s\n", + func, + desc->macrotile[0] ? "YES" : " NO", + desc->microtile ? "YES" : " NO", + desc->stride_in_pixels[0], + desc->b.b.width0, desc->b.b.height0, desc->b.b.depth0, + desc->b.b.last_level, desc->size_in_bytes, + util_format_short_name(desc->b.b.format)); +} + +boolean r300_texture_desc_init(struct r300_screen *rscreen, + struct r300_texture_desc *desc, + const struct pipe_resource *base, + enum r300_buffer_tiling microtile, + enum r300_buffer_tiling macrotile, + unsigned stride_in_bytes_override, + unsigned max_buffer_size) +{ + desc->b.b = *base; + desc->b.b.screen = &rscreen->screen; + desc->stride_in_bytes_override = stride_in_bytes_override; + desc->width0 = base->width0; + desc->height0 = base->height0; + desc->depth0 = base->depth0; + + r300_setup_flags(desc); + + /* Align a 3D NPOT texture to POT. */ + if (base->target == PIPE_TEXTURE_3D && desc->is_npot) { + desc->width0 = util_next_power_of_two(desc->width0); + desc->height0 = util_next_power_of_two(desc->height0); + desc->depth0 = util_next_power_of_two(desc->depth0); + } + + /* Setup tiling. */ + if (microtile == R300_BUFFER_SELECT_LAYOUT || + macrotile == R300_BUFFER_SELECT_LAYOUT) { + r300_setup_tiling(rscreen, desc); + } else { + desc->microtile = microtile; + desc->macrotile[0] = macrotile; + assert(desc->b.b.last_level == 0); + } + + r300_setup_cbzb_flags(rscreen, desc); + + /* Setup the miptree description. */ + r300_setup_miptree(rscreen, desc, TRUE); + /* If the required buffer size is larger the given max size, + * try again without the alignment for the CBZB clear. */ + if (max_buffer_size && desc->size_in_bytes > max_buffer_size) { + r300_setup_miptree(rscreen, desc, FALSE); + } + + r300_texture_3d_fix_mipmapping(rscreen, desc); + + if (max_buffer_size) { + /* Make sure the buffer we got is large enough. */ + if (desc->size_in_bytes > max_buffer_size) { + fprintf(stderr, "r300: texture_desc_init: The buffer is not " + "large enough. Got: %i, Need: %i, Info:\n", + max_buffer_size, desc->size_in_bytes); + r300_tex_print_info(rscreen, desc, "texture_desc_init"); + return FALSE; + } + + desc->buffer_size_in_bytes = max_buffer_size; + } else { + desc->buffer_size_in_bytes = desc->size_in_bytes; + } + + if (SCREEN_DBG_ON(rscreen, DBG_TEX)) + r300_tex_print_info(rscreen, desc, "texture_desc_init"); + + return TRUE; +} + +unsigned r300_texture_get_offset(struct r300_texture_desc *desc, + unsigned level, unsigned layer) +{ + unsigned offset = desc->offset_in_bytes[level]; + + switch (desc->b.b.target) { + case PIPE_TEXTURE_3D: + case PIPE_TEXTURE_CUBE: + return offset + layer * desc->layer_size_in_bytes[level]; + + default: + assert(layer == 0); + return offset; + } +} diff --git a/src/gallium/drivers/r300/r300_texture_desc.h b/src/gallium/drivers/r300/r300_texture_desc.h new file mode 100644 index 0000000..121d215 --- /dev/null +++ b/src/gallium/drivers/r300/r300_texture_desc.h @@ -0,0 +1,57 @@ +/* + * Copyright 2008 Corbin Simpson + * Copyright 2010 Marek Olšák + * + * 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 R300_TEXTURE_DESC_H +#define R300_TEXTURE_DESC_H + +#include "pipe/p_format.h" +#include "r300_defines.h" + +struct pipe_resource; +struct r300_screen; +struct r300_texture_desc; +struct r300_texture; + +enum r300_dim { + DIM_WIDTH = 0, + DIM_HEIGHT = 1 +}; + +unsigned r300_get_pixel_alignment(enum pipe_format format, + unsigned num_samples, + enum r300_buffer_tiling microtile, + enum r300_buffer_tiling macrotile, + enum r300_dim dim, boolean is_rs690); + +boolean r300_texture_desc_init(struct r300_screen *rscreen, + struct r300_texture_desc *desc, + const struct pipe_resource *base, + enum r300_buffer_tiling microtile, + enum r300_buffer_tiling macrotile, + unsigned stride_in_bytes_override, + unsigned max_buffer_size); + +unsigned r300_texture_get_offset(struct r300_texture_desc *desc, + unsigned level, unsigned layer); + +#endif diff --git a/src/gallium/drivers/r300/r300_tgsi_to_rc.c b/src/gallium/drivers/r300/r300_tgsi_to_rc.c new file mode 100644 index 0000000..15a3239 --- /dev/null +++ b/src/gallium/drivers/r300/r300_tgsi_to_rc.c @@ -0,0 +1,380 @@ +/* + * Copyright 2009 Nicolai Hähnle + * + * 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 COPYRIGHT HOLDER(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 "r300_tgsi_to_rc.h" + +#include "radeon_compiler.h" +#include "radeon_program.h" + +#include "tgsi/tgsi_info.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_scan.h" +#include "tgsi/tgsi_util.h" + +static unsigned translate_opcode(unsigned opcode) +{ + switch(opcode) { + case TGSI_OPCODE_ARL: return RC_OPCODE_ARL; + case TGSI_OPCODE_MOV: return RC_OPCODE_MOV; + case TGSI_OPCODE_LIT: return RC_OPCODE_LIT; + case TGSI_OPCODE_RCP: return RC_OPCODE_RCP; + case TGSI_OPCODE_RSQ: return RC_OPCODE_RSQ; + case TGSI_OPCODE_EXP: return RC_OPCODE_EXP; + case TGSI_OPCODE_LOG: return RC_OPCODE_LOG; + case TGSI_OPCODE_MUL: return RC_OPCODE_MUL; + case TGSI_OPCODE_ADD: return RC_OPCODE_ADD; + case TGSI_OPCODE_DP3: return RC_OPCODE_DP3; + case TGSI_OPCODE_DP4: return RC_OPCODE_DP4; + case TGSI_OPCODE_DST: return RC_OPCODE_DST; + case TGSI_OPCODE_MIN: return RC_OPCODE_MIN; + case TGSI_OPCODE_MAX: return RC_OPCODE_MAX; + case TGSI_OPCODE_SLT: return RC_OPCODE_SLT; + case TGSI_OPCODE_SGE: return RC_OPCODE_SGE; + case TGSI_OPCODE_MAD: return RC_OPCODE_MAD; + case TGSI_OPCODE_SUB: return RC_OPCODE_SUB; + case TGSI_OPCODE_LRP: return RC_OPCODE_LRP; + /* case TGSI_OPCODE_CND: return RC_OPCODE_CND; */ + /* case TGSI_OPCODE_CND0: return RC_OPCODE_CND0; */ + /* case TGSI_OPCODE_DP2A: return RC_OPCODE_DP2A; */ + /* gap */ + case TGSI_OPCODE_FRC: return RC_OPCODE_FRC; + case TGSI_OPCODE_CLAMP: return RC_OPCODE_CLAMP; + case TGSI_OPCODE_FLR: return RC_OPCODE_FLR; + /* case TGSI_OPCODE_ROUND: return RC_OPCODE_ROUND; */ + case TGSI_OPCODE_EX2: return RC_OPCODE_EX2; + case TGSI_OPCODE_LG2: return RC_OPCODE_LG2; + case TGSI_OPCODE_POW: return RC_OPCODE_POW; + case TGSI_OPCODE_XPD: return RC_OPCODE_XPD; + /* gap */ + case TGSI_OPCODE_ABS: return RC_OPCODE_ABS; + /* case TGSI_OPCODE_RCC: return RC_OPCODE_RCC; */ + case TGSI_OPCODE_DPH: return RC_OPCODE_DPH; + case TGSI_OPCODE_COS: return RC_OPCODE_COS; + case TGSI_OPCODE_DDX: return RC_OPCODE_DDX; + case TGSI_OPCODE_DDY: return RC_OPCODE_DDY; + case TGSI_OPCODE_KILP: return RC_OPCODE_KILP; + /* case TGSI_OPCODE_PK2H: return RC_OPCODE_PK2H; */ + /* case TGSI_OPCODE_PK2US: return RC_OPCODE_PK2US; */ + /* case TGSI_OPCODE_PK4B: return RC_OPCODE_PK4B; */ + /* case TGSI_OPCODE_PK4UB: return RC_OPCODE_PK4UB; */ + /* case TGSI_OPCODE_RFL: return RC_OPCODE_RFL; */ + case TGSI_OPCODE_SEQ: return RC_OPCODE_SEQ; + case TGSI_OPCODE_SFL: return RC_OPCODE_SFL; + case TGSI_OPCODE_SGT: return RC_OPCODE_SGT; + case TGSI_OPCODE_SIN: return RC_OPCODE_SIN; + case TGSI_OPCODE_SLE: return RC_OPCODE_SLE; + case TGSI_OPCODE_SNE: return RC_OPCODE_SNE; + /* case TGSI_OPCODE_STR: return RC_OPCODE_STR; */ + case TGSI_OPCODE_TEX: return RC_OPCODE_TEX; + case TGSI_OPCODE_TXD: return RC_OPCODE_TXD; + case TGSI_OPCODE_TXP: return RC_OPCODE_TXP; + /* case TGSI_OPCODE_UP2H: return RC_OPCODE_UP2H; */ + /* case TGSI_OPCODE_UP2US: return RC_OPCODE_UP2US; */ + /* case TGSI_OPCODE_UP4B: return RC_OPCODE_UP4B; */ + /* case TGSI_OPCODE_UP4UB: return RC_OPCODE_UP4UB; */ + /* case TGSI_OPCODE_X2D: return RC_OPCODE_X2D; */ + /* case TGSI_OPCODE_ARA: return RC_OPCODE_ARA; */ + /* case TGSI_OPCODE_ARR: return RC_OPCODE_ARR; */ + /* case TGSI_OPCODE_BRA: return RC_OPCODE_BRA; */ + /* case TGSI_OPCODE_CAL: return RC_OPCODE_CAL; */ + /* case TGSI_OPCODE_RET: return RC_OPCODE_RET; */ + case TGSI_OPCODE_SSG: return RC_OPCODE_SSG; + case TGSI_OPCODE_CMP: return RC_OPCODE_CMP; + case TGSI_OPCODE_SCS: return RC_OPCODE_SCS; + case TGSI_OPCODE_TXB: return RC_OPCODE_TXB; + /* case TGSI_OPCODE_NRM: return RC_OPCODE_NRM; */ + /* case TGSI_OPCODE_DIV: return RC_OPCODE_DIV; */ + case TGSI_OPCODE_DP2: return RC_OPCODE_DP2; + case TGSI_OPCODE_TXL: return RC_OPCODE_TXL; + case TGSI_OPCODE_BRK: return RC_OPCODE_BRK; + case TGSI_OPCODE_IF: return RC_OPCODE_IF; + case TGSI_OPCODE_BGNLOOP: return RC_OPCODE_BGNLOOP; + case TGSI_OPCODE_ELSE: return RC_OPCODE_ELSE; + case TGSI_OPCODE_ENDIF: return RC_OPCODE_ENDIF; + case TGSI_OPCODE_ENDLOOP: return RC_OPCODE_ENDLOOP; + /* case TGSI_OPCODE_PUSHA: return RC_OPCODE_PUSHA; */ + /* case TGSI_OPCODE_POPA: return RC_OPCODE_POPA; */ + case TGSI_OPCODE_CEIL: return RC_OPCODE_CEIL; + /* case TGSI_OPCODE_I2F: return RC_OPCODE_I2F; */ + /* case TGSI_OPCODE_NOT: return RC_OPCODE_NOT; */ + case TGSI_OPCODE_TRUNC: return RC_OPCODE_FLR; + /* case TGSI_OPCODE_SHL: return RC_OPCODE_SHL; */ + /* case TGSI_OPCODE_ISHR: return RC_OPCODE_SHR; */ + /* case TGSI_OPCODE_AND: return RC_OPCODE_AND; */ + /* case TGSI_OPCODE_OR: return RC_OPCODE_OR; */ + /* case TGSI_OPCODE_MOD: return RC_OPCODE_MOD; */ + /* case TGSI_OPCODE_XOR: return RC_OPCODE_XOR; */ + /* case TGSI_OPCODE_SAD: return RC_OPCODE_SAD; */ + /* case TGSI_OPCODE_TXF: return RC_OPCODE_TXF; */ + /* case TGSI_OPCODE_TXQ: return RC_OPCODE_TXQ; */ + case TGSI_OPCODE_CONT: return RC_OPCODE_CONT; + /* case TGSI_OPCODE_EMIT: return RC_OPCODE_EMIT; */ + /* case TGSI_OPCODE_ENDPRIM: return RC_OPCODE_ENDPRIM; */ + /* case TGSI_OPCODE_BGNLOOP2: return RC_OPCODE_BGNLOOP2; */ + /* case TGSI_OPCODE_BGNSUB: return RC_OPCODE_BGNSUB; */ + /* case TGSI_OPCODE_ENDLOOP2: return RC_OPCODE_ENDLOOP2; */ + /* case TGSI_OPCODE_ENDSUB: return RC_OPCODE_ENDSUB; */ + case TGSI_OPCODE_NOP: return RC_OPCODE_NOP; + /* gap */ + /* case TGSI_OPCODE_NRM4: return RC_OPCODE_NRM4; */ + /* case TGSI_OPCODE_CALLNZ: return RC_OPCODE_CALLNZ; */ + /* case TGSI_OPCODE_IFC: return RC_OPCODE_IFC; */ + /* case TGSI_OPCODE_BREAKC: return RC_OPCODE_BREAKC; */ + case TGSI_OPCODE_KIL: return RC_OPCODE_KIL; + } + + fprintf(stderr, "r300: Unknown TGSI/RC opcode: %s\n", tgsi_get_opcode_name(opcode)); + return RC_OPCODE_ILLEGAL_OPCODE; +} + +static unsigned translate_saturate(unsigned saturate) +{ + switch(saturate) { + default: + fprintf(stderr, "Unknown saturate mode: %i\n", saturate); + /* fall-through */ + case TGSI_SAT_NONE: return RC_SATURATE_NONE; + case TGSI_SAT_ZERO_ONE: return RC_SATURATE_ZERO_ONE; + } +} + +static unsigned translate_register_file(unsigned file) +{ + switch(file) { + case TGSI_FILE_CONSTANT: return RC_FILE_CONSTANT; + case TGSI_FILE_IMMEDIATE: return RC_FILE_CONSTANT; + case TGSI_FILE_INPUT: return RC_FILE_INPUT; + case TGSI_FILE_OUTPUT: return RC_FILE_OUTPUT; + default: + fprintf(stderr, "Unhandled register file: %i\n", file); + /* fall-through */ + case TGSI_FILE_TEMPORARY: return RC_FILE_TEMPORARY; + case TGSI_FILE_ADDRESS: return RC_FILE_ADDRESS; + } +} + +static int translate_register_index( + struct tgsi_to_rc * ttr, + unsigned file, + int index) +{ + if (file == TGSI_FILE_IMMEDIATE) + return ttr->immediate_offset + index; + + return index; +} + +static void transform_dstreg( + struct tgsi_to_rc * ttr, + struct rc_dst_register * dst, + struct tgsi_full_dst_register * src) +{ + dst->File = translate_register_file(src->Register.File); + dst->Index = translate_register_index(ttr, src->Register.File, src->Register.Index); + dst->WriteMask = src->Register.WriteMask; + dst->RelAddr = src->Register.Indirect; +} + +static void transform_srcreg( + struct tgsi_to_rc * ttr, + struct rc_src_register * dst, + struct tgsi_full_src_register * src) +{ + unsigned i, j; + + dst->File = translate_register_file(src->Register.File); + dst->Index = translate_register_index(ttr, src->Register.File, src->Register.Index); + dst->RelAddr = src->Register.Indirect; + dst->Swizzle = tgsi_util_get_full_src_register_swizzle(src, 0); + dst->Swizzle |= tgsi_util_get_full_src_register_swizzle(src, 1) << 3; + dst->Swizzle |= tgsi_util_get_full_src_register_swizzle(src, 2) << 6; + dst->Swizzle |= tgsi_util_get_full_src_register_swizzle(src, 3) << 9; + dst->Abs = src->Register.Absolute; + dst->Negate = src->Register.Negate ? RC_MASK_XYZW : 0; + + if (src->Register.File == TGSI_FILE_IMMEDIATE) { + for (i = 0; i < ttr->imms_to_swizzle_count; i++) { + if (ttr->imms_to_swizzle[i].index == src->Register.Index) { + dst->File = RC_FILE_TEMPORARY; + dst->Index = 0; + dst->Swizzle = 0; + for (j = 0; j < 4; j++) { + dst->Swizzle |= GET_SWZ(ttr->imms_to_swizzle[i].swizzle, + tgsi_util_get_full_src_register_swizzle(src, j)) << (j * 3); + } + break; + } + } + } +} + +static void transform_texture(struct rc_instruction * dst, struct tgsi_instruction_texture src, + uint32_t *shadowSamplers) +{ + switch(src.Texture) { + case TGSI_TEXTURE_1D: + dst->U.I.TexSrcTarget = RC_TEXTURE_1D; + break; + case TGSI_TEXTURE_2D: + dst->U.I.TexSrcTarget = RC_TEXTURE_2D; + break; + case TGSI_TEXTURE_3D: + dst->U.I.TexSrcTarget = RC_TEXTURE_3D; + break; + case TGSI_TEXTURE_CUBE: + dst->U.I.TexSrcTarget = RC_TEXTURE_CUBE; + break; + case TGSI_TEXTURE_RECT: + dst->U.I.TexSrcTarget = RC_TEXTURE_RECT; + break; + case TGSI_TEXTURE_SHADOW1D: + dst->U.I.TexSrcTarget = RC_TEXTURE_1D; + dst->U.I.TexShadow = 1; + *shadowSamplers |= 1 << dst->U.I.TexSrcUnit; + break; + case TGSI_TEXTURE_SHADOW2D: + dst->U.I.TexSrcTarget = RC_TEXTURE_2D; + dst->U.I.TexShadow = 1; + *shadowSamplers |= 1 << dst->U.I.TexSrcUnit; + break; + case TGSI_TEXTURE_SHADOWRECT: + dst->U.I.TexSrcTarget = RC_TEXTURE_RECT; + dst->U.I.TexShadow = 1; + *shadowSamplers |= 1 << dst->U.I.TexSrcUnit; + break; + } +} + +static void transform_instruction(struct tgsi_to_rc * ttr, struct tgsi_full_instruction * src) +{ + struct rc_instruction * dst; + int i; + + dst = rc_insert_new_instruction(ttr->compiler, ttr->compiler->Program.Instructions.Prev); + dst->U.I.Opcode = translate_opcode(src->Instruction.Opcode); + dst->U.I.SaturateMode = translate_saturate(src->Instruction.Saturate); + + if (src->Instruction.NumDstRegs) + transform_dstreg(ttr, &dst->U.I.DstReg, &src->Dst[0]); + + for(i = 0; i < src->Instruction.NumSrcRegs; ++i) { + if (src->Src[i].Register.File == TGSI_FILE_SAMPLER) + dst->U.I.TexSrcUnit = src->Src[i].Register.Index; + else + transform_srcreg(ttr, &dst->U.I.SrcReg[i], &src->Src[i]); + } + + /* Texturing. */ + if (src->Instruction.Texture) + transform_texture(dst, src->Texture, + &ttr->compiler->Program.ShadowSamplers); +} + +static void handle_immediate(struct tgsi_to_rc * ttr, + struct tgsi_full_immediate * imm, + unsigned index) +{ + struct rc_constant constant; + unsigned swizzle = 0; + boolean can_swizzle = TRUE; + unsigned i; + + for (i = 0; i < 4; i++) { + if (imm->u[i].Float == 0.0f) { + swizzle |= RC_SWIZZLE_ZERO << (i * 3); + } else if (imm->u[i].Float == 0.5f && ttr->use_half_swizzles) { + swizzle |= RC_SWIZZLE_HALF << (i * 3); + } else if (imm->u[i].Float == 1.0f) { + swizzle |= RC_SWIZZLE_ONE << (i * 3); + } else { + can_swizzle = FALSE; + break; + } + } + + if (can_swizzle) { + ttr->imms_to_swizzle[ttr->imms_to_swizzle_count].index = index; + ttr->imms_to_swizzle[ttr->imms_to_swizzle_count].swizzle = swizzle; + ttr->imms_to_swizzle_count++; + } else { + constant.Type = RC_CONSTANT_IMMEDIATE; + constant.Size = 4; + for(i = 0; i < 4; ++i) + constant.u.Immediate[i] = imm->u[i].Float; + rc_constants_add(&ttr->compiler->Program.Constants, &constant); + } +} + +void r300_tgsi_to_rc(struct tgsi_to_rc * ttr, + const struct tgsi_token * tokens) +{ + struct tgsi_full_instruction *inst; + struct tgsi_parse_context parser; + unsigned imm_index = 0; + int i; + + /* Allocate constants placeholders. + * + * Note: What if declared constants are not contiguous? */ + for(i = 0; i <= ttr->info->file_max[TGSI_FILE_CONSTANT]; ++i) { + struct rc_constant constant; + memset(&constant, 0, sizeof(constant)); + constant.Type = RC_CONSTANT_EXTERNAL; + constant.Size = 4; + constant.u.External = i; + rc_constants_add(&ttr->compiler->Program.Constants, &constant); + } + + ttr->immediate_offset = ttr->compiler->Program.Constants.Count; + + ttr->imms_to_swizzle = malloc(ttr->info->immediate_count * sizeof(struct swizzled_imms)); + ttr->imms_to_swizzle_count = 0; + + tgsi_parse_init(&parser, tokens); + + while (!tgsi_parse_end_of_tokens(&parser)) { + tgsi_parse_token(&parser); + + switch (parser.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_DECLARATION: + break; + case TGSI_TOKEN_TYPE_IMMEDIATE: + handle_immediate(ttr, &parser.FullToken.FullImmediate, imm_index); + imm_index++; + break; + case TGSI_TOKEN_TYPE_INSTRUCTION: + inst = &parser.FullToken.FullInstruction; + if (inst->Instruction.Opcode == TGSI_OPCODE_END) { + break; + } + + transform_instruction(ttr, inst); + break; + } + } + + tgsi_parse_free(&parser); + + free(ttr->imms_to_swizzle); + + rc_calculate_inputs_outputs(ttr->compiler); +} diff --git a/src/gallium/drivers/r300/r300_tgsi_to_rc.h b/src/gallium/drivers/r300/r300_tgsi_to_rc.h new file mode 100644 index 0000000..97641a9 --- /dev/null +++ b/src/gallium/drivers/r300/r300_tgsi_to_rc.h @@ -0,0 +1,54 @@ +/* + * Copyright 2009 Nicolai Hähnle + * + * 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 COPYRIGHT HOLDER(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 R300_TGSI_TO_RC_H +#define R300_TGSI_TO_RC_H + +#include "pipe/p_compiler.h" + +struct radeon_compiler; + +struct tgsi_full_declaration; +struct tgsi_shader_info; +struct tgsi_token; + +struct swizzled_imms { + unsigned index; + unsigned swizzle; +}; + +struct tgsi_to_rc { + struct radeon_compiler * compiler; + const struct tgsi_shader_info * info; + + int immediate_offset; + struct swizzled_imms * imms_to_swizzle; + unsigned imms_to_swizzle_count; + + /* Vertex shaders have no half swizzles, and no way to handle them, so + * until rc grows proper support, indicate if they're safe to use. */ + boolean use_half_swizzles; +}; + +void r300_tgsi_to_rc(struct tgsi_to_rc * ttr, const struct tgsi_token * tokens); + +#endif /* R300_TGSI_TO_RC_H */ diff --git a/src/gallium/drivers/r300/r300_transfer.c b/src/gallium/drivers/r300/r300_transfer.c new file mode 100644 index 0000000..3b95af7 --- /dev/null +++ b/src/gallium/drivers/r300/r300_transfer.c @@ -0,0 +1,269 @@ +/* + * Copyright 2008 Corbin Simpson + * Copyright 2010 Marek Olšák + * + * 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 "r300_transfer.h" +#include "r300_texture_desc.h" +#include "r300_screen_buffer.h" + +#include "util/u_memory.h" +#include "util/u_format.h" +#include "util/u_box.h" + +struct r300_transfer { + /* Parent class */ + struct pipe_transfer transfer; + + /* Offset from start of buffer. */ + unsigned offset; + + /* Linear texture. */ + struct r300_texture *linear_texture; +}; + +/* Convenience cast wrapper. */ +static INLINE struct r300_transfer* +r300_transfer(struct pipe_transfer* transfer) +{ + return (struct r300_transfer*)transfer; +} + +/* Copy from a tiled texture to a detiled one. */ +static void r300_copy_from_tiled_texture(struct pipe_context *ctx, + struct r300_transfer *r300transfer) +{ + struct pipe_transfer *transfer = (struct pipe_transfer*)r300transfer; + struct pipe_resource *tex = transfer->resource; + + ctx->resource_copy_region(ctx, &r300transfer->linear_texture->desc.b.b, 0, + 0, 0, 0, + tex, transfer->level, &transfer->box); +} + +/* Copy a detiled texture to a tiled one. */ +static void r300_copy_into_tiled_texture(struct pipe_context *ctx, + struct r300_transfer *r300transfer) +{ + struct pipe_transfer *transfer = (struct pipe_transfer*)r300transfer; + struct pipe_resource *tex = transfer->resource; + struct pipe_box src_box; + u_box_origin_2d(transfer->box.width, transfer->box.height, &src_box); + + ctx->resource_copy_region(ctx, tex, transfer->level, + transfer->box.x, transfer->box.y, transfer->box.z, + &r300transfer->linear_texture->desc.b.b, 0, &src_box); + + ctx->flush(ctx, 0, NULL); +} + +struct pipe_transfer* +r300_texture_get_transfer(struct pipe_context *ctx, + struct pipe_resource *texture, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct r300_context *r300 = r300_context(ctx); + struct r300_texture *tex = r300_texture(texture); + struct r300_transfer *trans; + struct pipe_resource base; + boolean referenced_cs, referenced_hw, blittable; + + referenced_cs = + r300->rws->cs_is_buffer_referenced(r300->cs, + tex->cs_buffer, R300_REF_CS); + if (referenced_cs) { + referenced_hw = TRUE; + } else { + referenced_hw = + r300->rws->cs_is_buffer_referenced(r300->cs, + tex->cs_buffer, R300_REF_HW); + } + + blittable = ctx->screen->is_format_supported( + ctx->screen, texture->format, texture->target, 0, + PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET, 0); + + trans = CALLOC_STRUCT(r300_transfer); + if (trans) { + /* Initialize the transfer object. */ + pipe_resource_reference(&trans->transfer.resource, texture); + trans->transfer.level = level; + trans->transfer.usage = usage; + trans->transfer.box = *box; + + /* If the texture is tiled, we must create a temporary detiled texture + * for this transfer. + * Also make write transfers pipelined. */ + if (tex->desc.microtile || tex->desc.macrotile[level] || + ((referenced_hw & !(usage & PIPE_TRANSFER_READ)) && blittable)) { + base.target = PIPE_TEXTURE_2D; + base.format = texture->format; + base.width0 = box->width; + base.height0 = box->height; + /* XXX: was depth0 = 0 */ + base.depth0 = 1; + base.array_size = 1; + base.last_level = 0; + base.nr_samples = 0; + base.usage = PIPE_USAGE_DYNAMIC; + base.bind = 0; + base.flags = R300_RESOURCE_FLAG_TRANSFER; + + /* For texture reading, the temporary (detiled) texture is used as + * a render target when blitting from a tiled texture. */ + if (usage & PIPE_TRANSFER_READ) { + base.bind |= PIPE_BIND_RENDER_TARGET; + } + /* For texture writing, the temporary texture is used as a sampler + * when blitting into a tiled texture. */ + if (usage & PIPE_TRANSFER_WRITE) { + base.bind |= PIPE_BIND_SAMPLER_VIEW; + } + + /* Create the temporary texture. */ + trans->linear_texture = r300_texture( + ctx->screen->resource_create(ctx->screen, + &base)); + + if (!trans->linear_texture) { + /* Oh crap, the thing can't create the texture. + * Let's flush and try again. */ + ctx->flush(ctx, 0, NULL); + + trans->linear_texture = r300_texture( + ctx->screen->resource_create(ctx->screen, + &base)); + + if (!trans->linear_texture) { + /* For linear textures, it's safe to fallback to + * an unpipelined transfer. */ + if (!tex->desc.microtile && !tex->desc.macrotile[level]) { + goto unpipelined; + } + + /* Otherwise, go to hell. */ + fprintf(stderr, + "r300: Failed to create a transfer object, praise.\n"); + FREE(trans); + return NULL; + } + } + + assert(!trans->linear_texture->desc.microtile && + !trans->linear_texture->desc.macrotile[0]); + + /* Set the stride. + * + * Even though we are using an internal texture for this, + * the transfer level, box and usage parameters still reflect + * the arguments received to get_transfer. We just do the + * right thing internally. + */ + trans->transfer.stride = + trans->linear_texture->desc.stride_in_bytes[0]; + + if (usage & PIPE_TRANSFER_READ) { + /* We cannot map a tiled texture directly because the data is + * in a different order, therefore we do detiling using a blit. */ + r300_copy_from_tiled_texture(ctx, trans); + + /* Always referenced in the blit. */ + ctx->flush(ctx, 0, NULL); + } + return &trans->transfer; + } + + unpipelined: + /* Unpipelined transfer. */ + trans->transfer.stride = tex->desc.stride_in_bytes[level]; + trans->offset = r300_texture_get_offset(&tex->desc, level, box->z); + + if (referenced_cs) + ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL); + return &trans->transfer; + } + return NULL; +} + +void r300_texture_transfer_destroy(struct pipe_context *ctx, + struct pipe_transfer *trans) +{ + struct r300_transfer *r300transfer = r300_transfer(trans); + + if (r300transfer->linear_texture) { + if (trans->usage & PIPE_TRANSFER_WRITE) { + r300_copy_into_tiled_texture(ctx, r300transfer); + } + + pipe_resource_reference( + (struct pipe_resource**)&r300transfer->linear_texture, NULL); + } + pipe_resource_reference(&trans->resource, NULL); + FREE(trans); +} + +void* r300_texture_transfer_map(struct pipe_context *ctx, + struct pipe_transfer *transfer) +{ + struct r300_context *r300 = r300_context(ctx); + struct r300_winsys_screen *rws = (struct r300_winsys_screen *)ctx->winsys; + struct r300_transfer *r300transfer = r300_transfer(transfer); + struct r300_texture *tex = r300_texture(transfer->resource); + char *map; + enum pipe_format format = tex->desc.b.b.format; + + if (r300transfer->linear_texture) { + /* The detiled texture is of the same size as the region being mapped + * (no offset needed). */ + return rws->buffer_map(rws, + r300transfer->linear_texture->buffer, + r300->cs, + transfer->usage); + } else { + /* Tiling is disabled. */ + map = rws->buffer_map(rws, tex->buffer, r300->cs, + transfer->usage); + + if (!map) { + return NULL; + } + + return map + r300_transfer(transfer)->offset + + transfer->box.y / util_format_get_blockheight(format) * transfer->stride + + transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); + } +} + +void r300_texture_transfer_unmap(struct pipe_context *ctx, + struct pipe_transfer *transfer) +{ + struct r300_winsys_screen *rws = (struct r300_winsys_screen *)ctx->winsys; + struct r300_transfer *r300transfer = r300_transfer(transfer); + struct r300_texture *tex = r300_texture(transfer->resource); + + if (r300transfer->linear_texture) { + rws->buffer_unmap(rws, r300transfer->linear_texture->buffer); + } else { + rws->buffer_unmap(rws, tex->buffer); + } +} diff --git a/src/gallium/drivers/r300/r300_transfer.h b/src/gallium/drivers/r300/r300_transfer.h new file mode 100644 index 0000000..7977ef5 --- /dev/null +++ b/src/gallium/drivers/r300/r300_transfer.h @@ -0,0 +1,51 @@ +/* + * Copyright 2008 Corbin Simpson + * Copyright 2010 Marek Olšák + * + * 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 R300_TRANSFER +#define R300_TRANSFER + +#include "pipe/p_context.h" + +struct r300_context; + +struct pipe_transfer* +r300_texture_get_transfer(struct pipe_context *ctx, + struct pipe_resource *texture, + unsigned level, + unsigned usage, + const struct pipe_box *box); + +void +r300_texture_transfer_destroy(struct pipe_context *ctx, + struct pipe_transfer *trans); + +void* +r300_texture_transfer_map(struct pipe_context *ctx, + struct pipe_transfer *transfer); + +void +r300_texture_transfer_unmap(struct pipe_context *ctx, + struct pipe_transfer *transfer); + + +#endif diff --git a/src/gallium/drivers/r300/r300_vs.c b/src/gallium/drivers/r300/r300_vs.c new file mode 100644 index 0000000..78021e2 --- /dev/null +++ b/src/gallium/drivers/r300/r300_vs.c @@ -0,0 +1,270 @@ +/* + * Copyright 2009 Corbin Simpson + * Copyright 2009 Marek Olšák + * + * 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 "r300_vs.h" + +#include "r300_context.h" +#include "r300_screen.h" +#include "r300_tgsi_to_rc.h" +#include "r300_reg.h" + +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_ureg.h" + +#include "radeon_compiler.h" + +/* Convert info about VS output semantics into r300_shader_semantics. */ +static void r300_shader_read_vs_outputs( + struct tgsi_shader_info* info, + struct r300_shader_semantics* vs_outputs) +{ + int i; + unsigned index; + + r300_shader_semantics_reset(vs_outputs); + + for (i = 0; i < info->num_outputs; i++) { + index = info->output_semantic_index[i]; + + switch (info->output_semantic_name[i]) { + case TGSI_SEMANTIC_POSITION: + assert(index == 0); + vs_outputs->pos = i; + break; + + case TGSI_SEMANTIC_PSIZE: + assert(index == 0); + vs_outputs->psize = i; + break; + + case TGSI_SEMANTIC_COLOR: + assert(index < ATTR_COLOR_COUNT); + vs_outputs->color[index] = i; + break; + + case TGSI_SEMANTIC_BCOLOR: + assert(index < ATTR_COLOR_COUNT); + vs_outputs->bcolor[index] = i; + break; + + case TGSI_SEMANTIC_GENERIC: + assert(index < ATTR_GENERIC_COUNT); + vs_outputs->generic[index] = i; + break; + + case TGSI_SEMANTIC_FOG: + assert(index == 0); + vs_outputs->fog = i; + break; + + case TGSI_SEMANTIC_EDGEFLAG: + assert(index == 0); + fprintf(stderr, "r300 VP: cannot handle edgeflag output.\n"); + break; + + default: + fprintf(stderr, "r300 VP: unknown vertex output semantic: %i.\n", + info->output_semantic_name[i]); + } + } + + /* WPOS is a straight copy of POSITION and it's always emitted. */ + vs_outputs->wpos = i; +} + +static void set_vertex_inputs_outputs(struct r300_vertex_program_compiler * c) +{ + struct r300_vertex_shader * vs = c->UserData; + struct r300_shader_semantics* outputs = &vs->outputs; + struct tgsi_shader_info* info = &vs->info; + int i, reg = 0; + boolean any_bcolor_used = outputs->bcolor[0] != ATTR_UNUSED || + outputs->bcolor[1] != ATTR_UNUSED; + + /* Fill in the input mapping */ + for (i = 0; i < info->num_inputs; i++) + c->code->inputs[i] = i; + + /* Position. */ + if (outputs->pos != ATTR_UNUSED) { + c->code->outputs[outputs->pos] = reg++; + } else { + assert(0); + } + + /* Point size. */ + if (outputs->psize != ATTR_UNUSED) { + c->code->outputs[outputs->psize] = reg++; + } + + /* If we're writing back facing colors we need to send + * four colors to make front/back face colors selection work. + * If the vertex program doesn't write all 4 colors, lets + * pretend it does by skipping output index reg so the colors + * get written into appropriate output vectors. + */ + + /* Colors. */ + for (i = 0; i < ATTR_COLOR_COUNT; i++) { + if (outputs->color[i] != ATTR_UNUSED) { + c->code->outputs[outputs->color[i]] = reg++; + } else if (any_bcolor_used || + outputs->color[1] != ATTR_UNUSED) { + reg++; + } + } + + /* Back-face colors. */ + for (i = 0; i < ATTR_COLOR_COUNT; i++) { + if (outputs->bcolor[i] != ATTR_UNUSED) { + c->code->outputs[outputs->bcolor[i]] = reg++; + } else if (any_bcolor_used) { + reg++; + } + } + + /* Texture coordinates. */ + for (i = 0; i < ATTR_GENERIC_COUNT; i++) { + if (outputs->generic[i] != ATTR_UNUSED) { + c->code->outputs[outputs->generic[i]] = reg++; + } + } + + /* Fog coordinates. */ + if (outputs->fog != ATTR_UNUSED) { + c->code->outputs[outputs->fog] = reg++; + } + + /* WPOS. */ + c->code->outputs[outputs->wpos] = reg++; +} + +void r300_init_vs_outputs(struct r300_vertex_shader *vs) +{ + tgsi_scan_shader(vs->state.tokens, &vs->info); + r300_shader_read_vs_outputs(&vs->info, &vs->outputs); +} + +static void r300_dummy_vertex_shader( + struct r300_context* r300, + struct r300_vertex_shader* shader) +{ + struct ureg_program *ureg; + struct ureg_dst dst; + struct ureg_src imm; + + /* Make a simple vertex shader which outputs (0, 0, 0, 1), + * effectively rendering nothing. */ + ureg = ureg_create(TGSI_PROCESSOR_VERTEX); + dst = ureg_DECL_output(ureg, TGSI_SEMANTIC_POSITION, 0); + imm = ureg_imm4f(ureg, 0, 0, 0, 1); + + ureg_MOV(ureg, dst, imm); + ureg_END(ureg); + + shader->state.tokens = tgsi_dup_tokens(ureg_finalize(ureg)); + ureg_destroy(ureg); + + shader->dummy = TRUE; + r300_init_vs_outputs(shader); + r300_translate_vertex_shader(r300, shader); +} + +void r300_translate_vertex_shader(struct r300_context *r300, + struct r300_vertex_shader *vs) +{ + struct r300_vertex_program_compiler compiler; + struct tgsi_to_rc ttr; + unsigned i; + + /* Setup the compiler */ + memset(&compiler, 0, sizeof(compiler)); + rc_init(&compiler.Base); + + DBG_ON(r300, DBG_VP) ? compiler.Base.Debug |= RC_DBG_LOG : 0; + DBG_ON(r300, DBG_P_STAT) ? compiler.Base.Debug |= RC_DBG_STATS : 0; + compiler.code = &vs->code; + compiler.UserData = vs; + compiler.Base.is_r500 = r300->screen->caps.is_r500; + compiler.Base.disable_optimizations = DBG_ON(r300, DBG_NO_OPT); + compiler.Base.has_half_swizzles = FALSE; + compiler.Base.has_presub = FALSE; + compiler.Base.max_temp_regs = 32; + compiler.Base.max_constants = 256; + compiler.Base.max_alu_insts = r300->screen->caps.is_r500 ? 1024 : 256; + + if (compiler.Base.Debug & RC_DBG_LOG) { + DBG(r300, DBG_VP, "r300: Initial vertex program\n"); + tgsi_dump(vs->state.tokens, 0); + } + + /* Translate TGSI to our internal representation */ + ttr.compiler = &compiler.Base; + ttr.info = &vs->info; + ttr.use_half_swizzles = FALSE; + + r300_tgsi_to_rc(&ttr, vs->state.tokens); + + if (compiler.Base.Program.Constants.Count > 200) { + compiler.Base.remove_unused_constants = TRUE; + } + + compiler.RequiredOutputs = ~(~0 << (vs->info.num_outputs + 1)); + compiler.SetHwInputOutput = &set_vertex_inputs_outputs; + + /* Insert the WPOS output. */ + rc_copy_output(&compiler.Base, 0, vs->outputs.wpos); + + /* Invoke the compiler */ + r3xx_compile_vertex_program(&compiler); + if (compiler.Base.Error) { + fprintf(stderr, "r300 VP: Compiler error:\n%sUsing a dummy shader" + " instead.\n", compiler.Base.ErrorMsg); + + if (vs->dummy) { + fprintf(stderr, "r300 VP: Cannot compile the dummy shader! " + "Giving up...\n"); + abort(); + } + + rc_destroy(&compiler.Base); + r300_dummy_vertex_shader(r300, vs); + return; + } + + /* Initialize numbers of constants for each type. */ + vs->externals_count = 0; + for (i = 0; + i < vs->code.constants.Count && + vs->code.constants.Constants[i].Type == RC_CONSTANT_EXTERNAL; i++) { + vs->externals_count = i+1; + } + for (; i < vs->code.constants.Count; i++) { + assert(vs->code.constants.Constants[i].Type == RC_CONSTANT_IMMEDIATE); + } + vs->immediates_count = vs->code.constants.Count - vs->externals_count; + + /* And, finally... */ + rc_destroy(&compiler.Base); +} diff --git a/src/gallium/drivers/r300/r300_vs.h b/src/gallium/drivers/r300/r300_vs.h new file mode 100644 index 0000000..170de6c --- /dev/null +++ b/src/gallium/drivers/r300/r300_vs.h @@ -0,0 +1,67 @@ +/* + * Copyright 2009 Corbin Simpson + * Copyright 2009 Marek Olšák + * + * 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 R300_VS_H +#define R300_VS_H + +#include "pipe/p_state.h" +#include "tgsi/tgsi_scan.h" +#include "radeon_code.h" + +#include "r300_context.h" +#include "r300_shader_semantics.h" + +struct r300_context; + +struct r300_vertex_shader { + /* Parent class */ + struct pipe_shader_state state; + + struct tgsi_shader_info info; + struct r300_shader_semantics outputs; + + /* Whether the shader was replaced by a dummy one due to a shader + * compilation failure. */ + boolean dummy; + + /* Numbers of constants for each type. */ + unsigned externals_count; + unsigned immediates_count; + + /* HWTCL-specific. */ + /* Machine code (if translated) */ + struct r300_vertex_program_code code; + + /* SWTCL-specific. */ + void *draw_vs; +}; + +void r300_init_vs_outputs(struct r300_vertex_shader *vs); + +void r300_translate_vertex_shader(struct r300_context *r300, + struct r300_vertex_shader *vs); + +void r300_draw_init_vertex_shader(struct draw_context *draw, + struct r300_vertex_shader *vs); + +#endif /* R300_VS_H */ diff --git a/src/gallium/drivers/r300/r300_vs_draw.c b/src/gallium/drivers/r300/r300_vs_draw.c new file mode 100644 index 0000000..2939963 --- /dev/null +++ b/src/gallium/drivers/r300/r300_vs_draw.c @@ -0,0 +1,358 @@ +/************************************************************************** + * + * Copyright 2009 Marek Olšák + * + * 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. + * + **************************************************************************/ + +/* This file contains the vertex shader tranformations for SW TCL needed + * to overcome the limitations of the r300 rasterizer. + * + * Transformations: + * 1) If the secondary color output is present, the primary color must be + * inserted before it. + * 2) If any back-face color output is present, there must be all 4 color + * outputs and missing ones must be inserted. + * 3) Insert a trailing texcoord output containing a copy of POS, for WPOS. + * + * I know this code is cumbersome, but I don't know of any nicer way + * of transforming TGSI shaders. ~ M. + */ + +#include "r300_vs.h" + +#include + +#include "tgsi/tgsi_transform.h" +#include "tgsi/tgsi_dump.h" + +#include "draw/draw_context.h" + +struct vs_transform_context { + struct tgsi_transform_context base; + + boolean color_used[2]; + boolean bcolor_used[2]; + boolean temp_used[128]; + + /* Index of the pos output, typically 0. */ + unsigned pos_output; + /* Index of the pos temp where all writes of pos are redirected to. */ + unsigned pos_temp; + /* The index of the last generic output, after which we insert a new + * output for WPOS. */ + int last_generic; + + unsigned num_outputs; + /* Used to shift output decl. indices when inserting new ones. */ + unsigned decl_shift; + /* Used to remap writes to output decls if their indices changed. */ + unsigned out_remap[32]; + + /* First instruction processed? */ + boolean first_instruction; + /* End instruction processed? */ + boolean end_instruction; +}; + +static void emit_temp(struct tgsi_transform_context *ctx, unsigned reg) +{ + struct tgsi_full_declaration decl; + + decl = tgsi_default_full_declaration(); + decl.Declaration.File = TGSI_FILE_TEMPORARY; + decl.Range.First = decl.Range.Last = reg; + ctx->emit_declaration(ctx, &decl); +} + +static void emit_output(struct tgsi_transform_context *ctx, + unsigned name, unsigned index, unsigned interp, + unsigned reg) +{ + struct vs_transform_context *vsctx = (struct vs_transform_context *)ctx; + struct tgsi_full_declaration decl; + + decl = tgsi_default_full_declaration(); + decl.Declaration.File = TGSI_FILE_OUTPUT; + decl.Declaration.Interpolate = interp; + decl.Declaration.Semantic = TRUE; + decl.Semantic.Name = name; + decl.Semantic.Index = index; + decl.Range.First = decl.Range.Last = reg; + ctx->emit_declaration(ctx, &decl); + ++vsctx->num_outputs; +} + +static void insert_output(struct tgsi_transform_context *ctx, + struct tgsi_full_declaration *before, + unsigned name, unsigned index, unsigned interp) +{ + struct vs_transform_context *vsctx = (struct vs_transform_context *)ctx; + unsigned i; + + /* Make a place for the new output. */ + for (i = before->Range.First; i < Elements(vsctx->out_remap); i++) { + ++vsctx->out_remap[i]; + } + + /* Insert the new output. */ + emit_output(ctx, name, index, interp, before->Range.First); + + ++vsctx->decl_shift; +} + +static void insert_trailing_bcolor(struct tgsi_transform_context *ctx, + struct tgsi_full_declaration *before) +{ + struct vs_transform_context *vsctx = (struct vs_transform_context *)ctx; + + /* If BCOLOR0 is used, make sure BCOLOR1 is present too. Otherwise + * the rasterizer doesn't do the color selection correctly. */ + if (vsctx->bcolor_used[0] && !vsctx->bcolor_used[1]) { + if (before) { + insert_output(ctx, before, TGSI_SEMANTIC_BCOLOR, 1, + TGSI_INTERPOLATE_LINEAR); + } else { + emit_output(ctx, TGSI_SEMANTIC_BCOLOR, 1, + TGSI_INTERPOLATE_LINEAR, vsctx->num_outputs); + } + vsctx->bcolor_used[1] = TRUE; + } +} + +static void transform_decl(struct tgsi_transform_context *ctx, + struct tgsi_full_declaration *decl) +{ + struct vs_transform_context *vsctx = (struct vs_transform_context *)ctx; + unsigned i; + + if (decl->Declaration.File == TGSI_FILE_OUTPUT) { + switch (decl->Semantic.Name) { + case TGSI_SEMANTIC_POSITION: + vsctx->pos_output = decl->Range.First; + break; + + case TGSI_SEMANTIC_COLOR: + assert(decl->Semantic.Index < 2); + vsctx->color_used[decl->Semantic.Index] = TRUE; + + /* We must rasterize the first color if the second one is + * used, otherwise the rasterizer doesn't do the color + * selection correctly. Declare it, but don't write to it. */ + if (decl->Semantic.Index == 1 && !vsctx->color_used[0]) { + insert_output(ctx, decl, TGSI_SEMANTIC_COLOR, 0, + TGSI_INTERPOLATE_LINEAR); + vsctx->color_used[0] = TRUE; + } + break; + + case TGSI_SEMANTIC_BCOLOR: + assert(decl->Semantic.Index < 2); + vsctx->bcolor_used[decl->Semantic.Index] = TRUE; + + /* We must rasterize all 4 colors if back-face colors are + * used, otherwise the rasterizer doesn't do the color + * selection correctly. Declare it, but don't write to it. */ + if (!vsctx->color_used[0]) { + insert_output(ctx, decl, TGSI_SEMANTIC_COLOR, 0, + TGSI_INTERPOLATE_LINEAR); + vsctx->color_used[0] = TRUE; + } + if (!vsctx->color_used[1]) { + insert_output(ctx, decl, TGSI_SEMANTIC_COLOR, 1, + TGSI_INTERPOLATE_LINEAR); + vsctx->color_used[1] = TRUE; + } + if (decl->Semantic.Index == 1 && !vsctx->bcolor_used[0]) { + insert_output(ctx, decl, TGSI_SEMANTIC_BCOLOR, 0, + TGSI_INTERPOLATE_LINEAR); + vsctx->bcolor_used[0] = TRUE; + } + /* One more case is handled in insert_trailing_bcolor. */ + break; + + case TGSI_SEMANTIC_GENERIC: + vsctx->last_generic = MAX2(vsctx->last_generic, decl->Semantic.Index); + break; + } + + if (decl->Semantic.Name != TGSI_SEMANTIC_BCOLOR) { + /* Insert it as soon as possible. */ + insert_trailing_bcolor(ctx, decl); + } + + /* Since we're inserting new outputs in between, the following outputs + * should be moved to the right so that they don't overlap with + * the newly added ones. */ + decl->Range.First += vsctx->decl_shift; + decl->Range.Last += vsctx->decl_shift; + + ++vsctx->num_outputs; + } else if (decl->Declaration.File == TGSI_FILE_TEMPORARY) { + for (i = decl->Range.First; i <= decl->Range.Last; i++) { + vsctx->temp_used[i] = TRUE; + } + } + + ctx->emit_declaration(ctx, decl); +} + +static void transform_inst(struct tgsi_transform_context *ctx, + struct tgsi_full_instruction *inst) +{ + struct vs_transform_context *vsctx = (struct vs_transform_context *) ctx; + struct tgsi_full_instruction new_inst; + unsigned i; + + if (!vsctx->first_instruction) { + vsctx->first_instruction = TRUE; + + /* The trailing BCOLOR should be inserted before the code + * if it hasn't already been done so. */ + insert_trailing_bcolor(ctx, NULL); + + /* Insert the generic output for WPOS. */ + emit_output(ctx, TGSI_SEMANTIC_GENERIC, vsctx->last_generic + 1, + TGSI_INTERPOLATE_PERSPECTIVE, vsctx->num_outputs); + + /* Find a free temp for POSITION. */ + for (i = 0; i < Elements(vsctx->temp_used); i++) { + if (!vsctx->temp_used[i]) { + emit_temp(ctx, i); + vsctx->pos_temp = i; + break; + } + } + } + + if (inst->Instruction.Opcode == TGSI_OPCODE_END) { + /* MOV OUT[pos_output], TEMP[pos_temp]; */ + new_inst = tgsi_default_full_instruction(); + new_inst.Instruction.Opcode = TGSI_OPCODE_MOV; + new_inst.Instruction.NumDstRegs = 1; + new_inst.Dst[0].Register.File = TGSI_FILE_OUTPUT; + new_inst.Dst[0].Register.Index = vsctx->pos_output; + new_inst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_XYZW; + new_inst.Instruction.NumSrcRegs = 1; + new_inst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + new_inst.Src[0].Register.Index = vsctx->pos_temp; + ctx->emit_instruction(ctx, &new_inst); + + /* MOV OUT[n-1], TEMP[pos_temp]; */ + new_inst = tgsi_default_full_instruction(); + new_inst.Instruction.Opcode = TGSI_OPCODE_MOV; + new_inst.Instruction.NumDstRegs = 1; + new_inst.Dst[0].Register.File = TGSI_FILE_OUTPUT; + new_inst.Dst[0].Register.Index = vsctx->num_outputs - 1; + new_inst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_XYZW; + new_inst.Instruction.NumSrcRegs = 1; + new_inst.Src[0].Register.File = TGSI_FILE_TEMPORARY; + new_inst.Src[0].Register.Index = vsctx->pos_temp; + ctx->emit_instruction(ctx, &new_inst); + + vsctx->end_instruction = TRUE; + } else { + /* Not an END instruction. */ + /* Fix writes to outputs. */ + for (i = 0; i < inst->Instruction.NumDstRegs; i++) { + struct tgsi_full_dst_register *dst = &inst->Dst[i]; + if (dst->Register.File == TGSI_FILE_OUTPUT) { + if (dst->Register.Index == vsctx->pos_output) { + /* Replace writes to OUT[pos_output] with TEMP[pos_temp]. */ + dst->Register.File = TGSI_FILE_TEMPORARY; + dst->Register.Index = vsctx->pos_temp; + } else { + /* Not a position, good... + * Since we were changing the indices of output decls, + * we must redirect writes into them too. */ + dst->Register.Index = vsctx->out_remap[dst->Register.Index]; + } + } + } + + /* Inserting 2 instructions before the END opcode moves all following + * labels by 2. Subroutines are always after the END opcode so + * they're always moved. */ + if (inst->Instruction.Opcode == TGSI_OPCODE_CAL) { + inst->Label.Label += 2; + } + /* The labels of the following opcodes are moved only after + * the END opcode. */ + if (vsctx->end_instruction && + (inst->Instruction.Opcode == TGSI_OPCODE_IF || + inst->Instruction.Opcode == TGSI_OPCODE_ELSE || + inst->Instruction.Opcode == TGSI_OPCODE_BGNLOOP || + inst->Instruction.Opcode == TGSI_OPCODE_ENDLOOP)) { + inst->Label.Label += 2; + } + } + + ctx->emit_instruction(ctx, inst); +} + +void r300_draw_init_vertex_shader(struct draw_context *draw, + struct r300_vertex_shader *vs) +{ + struct pipe_shader_state new_vs; + struct vs_transform_context transform; + const uint newLen = tgsi_num_tokens(vs->state.tokens) + 100 /* XXX */; + unsigned i; + + new_vs.tokens = tgsi_alloc_tokens(newLen); + if (new_vs.tokens == NULL) + return; + + memset(&transform, 0, sizeof(transform)); + for (i = 0; i < Elements(transform.out_remap); i++) { + transform.out_remap[i] = i; + } + transform.last_generic = -1; + transform.base.transform_instruction = transform_inst; + transform.base.transform_declaration = transform_decl; + + tgsi_transform_shader(vs->state.tokens, + (struct tgsi_token*)new_vs.tokens, + newLen, &transform.base); + +#if 0 + printf("----------------------------------------------\norig shader:\n"); + tgsi_dump(vs->state.tokens, 0); + printf("----------------------------------------------\nnew shader:\n"); + tgsi_dump(new_vs.tokens, 0); + printf("----------------------------------------------\n"); +#endif + + /* Free old tokens. */ + FREE((void*)vs->state.tokens); + + vs->draw_vs = draw_create_vertex_shader(draw, &new_vs); + + /* Instead of duplicating and freeing the tokens, copy the pointer directly. */ + vs->state.tokens = new_vs.tokens; + + /* Init the VS output table for the rasterizer. */ + r300_init_vs_outputs(vs); + + /* Make the last generic be WPOS. */ + vs->outputs.wpos = vs->outputs.generic[transform.last_generic + 1]; + vs->outputs.generic[transform.last_generic + 1] = ATTR_UNUSED; +} diff --git a/src/gallium/drivers/r300/r300_winsys.h b/src/gallium/drivers/r300/r300_winsys.h new file mode 100644 index 0000000..0dd330d --- /dev/null +++ b/src/gallium/drivers/r300/r300_winsys.h @@ -0,0 +1,316 @@ +/* + * Copyright 2008 Corbin Simpson + * Copyright 2010 Marek Olšák + * + * 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 R300_WINSYS_H +#define R300_WINSYS_H + +/* The public winsys interface header for the r300 pipe driver. + * Any winsys hosting this pipe needs to implement r300_winsys_screen and then + * call r300_screen_create to start things. */ + +#include "pipe/p_defines.h" +#include "pipe/p_state.h" + +#include "r300_defines.h" + +#define R300_MAX_CMDBUF_DWORDS (16 * 1024) + +struct winsys_handle; +struct r300_winsys_screen; + +struct r300_winsys_buffer; /* for map/unmap etc. */ +struct r300_winsys_cs_buffer; /* for write_reloc etc. */ + +struct r300_winsys_cs { + unsigned cdw; /* Number of used dwords. */ + uint32_t *buf; /* The command buffer. */ +}; + +enum r300_value_id { + R300_VID_PCI_ID, + R300_VID_GB_PIPES, + R300_VID_Z_PIPES, + R300_VID_SQUARE_TILING_SUPPORT, + R300_VID_DRM_2_3_0, + R300_VID_DRM_2_6_0, + R300_CAN_HYPERZ, +}; + +enum r300_reference_domain { /* bitfield */ + R300_REF_CS = 1, + R300_REF_HW = 2 +}; + +struct r300_winsys_screen { + /** + * Destroy this winsys. + * + * \param ws The winsys this function is called from. + */ + void (*destroy)(struct r300_winsys_screen *ws); + + /** + * Query a system value from a winsys. + * + * \param ws The winsys this function is called from. + * \param vid One of the R300_VID_* enums. + */ + uint32_t (*get_value)(struct r300_winsys_screen *ws, + enum r300_value_id vid); + + /************************************************************************** + * Buffer management. Buffer attributes are mostly fixed over its lifetime. + * + * Remember that gallium gets to choose the interface it needs, and the + * window systems must then implement that interface (rather than the + * other way around...). + *************************************************************************/ + + /** + * Create a buffer object. + * + * \param ws The winsys this function is called from. + * \param size The size to allocate. + * \param alignment An alignment of the buffer in memory. + * \param bind A bitmask of the PIPE_BIND_* flags. + * \param usage A bitmask of the PIPE_USAGE_* flags. + * \param domain A bitmask of the R300_DOMAIN_* flags. + * \return The created buffer object. + */ + struct r300_winsys_buffer *(*buffer_create)(struct r300_winsys_screen *ws, + unsigned size, + unsigned alignment, + unsigned bind, + unsigned usage, + enum r300_buffer_domain domain); + + struct r300_winsys_cs_buffer *(*buffer_get_cs_handle)( + struct r300_winsys_screen *ws, + struct r300_winsys_buffer *buf); + + /** + * Reference a buffer object (assign with reference counting). + * + * \param ws The winsys this function is called from. + * \param pdst A destination pointer to set the source buffer to. + * \param src A source buffer object. + */ + void (*buffer_reference)(struct r300_winsys_screen *ws, + struct r300_winsys_buffer **pdst, + struct r300_winsys_buffer *src); + + /** + * Map the entire data store of a buffer object into the client's address + * space. + * + * \param ws The winsys this function is called from. + * \param buf A winsys buffer object to map. + * \param cs A command stream to flush if the buffer is referenced by it. + * \param usage A bitmask of the PIPE_TRANSFER_* flags. + * \return The pointer at the beginning of the buffer. + */ + void *(*buffer_map)(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *buf, + struct r300_winsys_cs *cs, + enum pipe_transfer_usage usage); + + /** + * Unmap a buffer object from the client's address space. + * + * \param ws The winsys this function is called from. + * \param buf A winsys buffer object to unmap. + */ + void (*buffer_unmap)(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *buf); + + /** + * Wait for a buffer object until it is not used by a GPU. This is + * equivalent to a fence placed after the last command using the buffer, + * and synchronizing to the fence. + * + * \param ws The winsys this function is called from. + * \param buf A winsys buffer object to wait for. + */ + void (*buffer_wait)(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *buf); + + /** + * Return tiling flags describing a memory layout of a buffer object. + * + * \param ws The winsys this function is called from. + * \param buf A winsys buffer object to get the flags from. + * \param macrotile A pointer to the return value of the microtile flag. + * \param microtile A pointer to the return value of the macrotile flag. + * + * \note microtile and macrotile are not bitmasks! + */ + void (*buffer_get_tiling)(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *buf, + enum r300_buffer_tiling *microtile, + enum r300_buffer_tiling *macrotile); + + /** + * Set tiling flags describing a memory layout of a buffer object. + * + * \param ws The winsys this function is called from. + * \param buf A winsys buffer object to set the flags for. + * \param macrotile A macrotile flag. + * \param microtile A microtile flag. + * \param stride A stride of the buffer in bytes, for texturing. + * + * \note microtile and macrotile are not bitmasks! + */ + void (*buffer_set_tiling)(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *buf, + enum r300_buffer_tiling microtile, + enum r300_buffer_tiling macrotile, + unsigned stride); + + /** + * Get a winsys buffer from a winsys handle. The internal structure + * of the handle is platform-specific and only a winsys should access it. + * + * \param ws The winsys this function is called from. + * \param whandle A winsys handle pointer as was received from a state + * tracker. + * \param stride The returned buffer stride in bytes. + * \param size The returned buffer size. + */ + struct r300_winsys_buffer *(*buffer_from_handle)(struct r300_winsys_screen *ws, + struct winsys_handle *whandle, + unsigned *stride, + unsigned *size); + + /** + * Get a winsys handle from a winsys buffer. The internal structure + * of the handle is platform-specific and only a winsys should access it. + * + * \param ws The winsys this function is called from. + * \param buf A winsys buffer object to get the handle from. + * \param whandle A winsys handle pointer. + * \param stride A stride of the buffer in bytes, for texturing. + * \return TRUE on success. + */ + boolean (*buffer_get_handle)(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *buf, + unsigned stride, + struct winsys_handle *whandle); + + /************************************************************************** + * Command submission. + * + * Each pipe context should create its own command stream and submit + * commands independently of other contexts. + *************************************************************************/ + + /** + * Create a command stream. + * + * \param ws The winsys this function is called from. + */ + struct r300_winsys_cs *(*cs_create)(struct r300_winsys_screen *ws); + + /** + * Destroy a command stream. + * + * \param cs A command stream to destroy. + */ + void (*cs_destroy)(struct r300_winsys_cs *cs); + + /** + * Add a buffer object to the list of buffers to validate. + * + * \param cs A command stream to add buffer for validation against. + * \param buf A winsys buffer to validate. + * \param rd A read domain containing a bitmask + * of the R300_DOMAIN_* flags. + * \param wd A write domain containing a bitmask + * of the R300_DOMAIN_* flags. + */ + void (*cs_add_buffer)(struct r300_winsys_cs *cs, + struct r300_winsys_cs_buffer *buf, + enum r300_buffer_domain rd, + enum r300_buffer_domain wd); + + /** + * Revalidate all currently set up winsys buffers. + * Returns TRUE if a flush is required. + * + * \param cs A command stream to validate. + */ + boolean (*cs_validate)(struct r300_winsys_cs *cs); + + /** + * Write a relocated dword to a command buffer. + * + * \param cs A command stream the relocation is written to. + * \param buf A winsys buffer to write the relocation for. + * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags. + * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags. + */ + void (*cs_write_reloc)(struct r300_winsys_cs *cs, + struct r300_winsys_cs_buffer *buf, + enum r300_buffer_domain rd, + enum r300_buffer_domain wd); + + /** + * Flush a command stream. + * + * \param cs A command stream to flush. + */ + void (*cs_flush)(struct r300_winsys_cs *cs); + + /** + * Set a flush callback which is called from winsys when flush is + * required. + * + * \param cs A command stream to set the callback for. + * \param flush A flush callback function associated with the command stream. + * \param user A user pointer that will be passed to the flush callback. + */ + void (*cs_set_flush)(struct r300_winsys_cs *cs, + void (*flush)(void *), + void *user); + + /** + * Reset the list of buffer objects to validate, usually called + * prior to adding buffer objects for validation. + * + * \param cs A command stream to reset buffers for. + */ + void (*cs_reset_buffers)(struct r300_winsys_cs *cs); + + /** + * Return TRUE if a buffer is referenced by a command stream or by hardware + * (i.e. is busy), based on the domain parameter. + * + * \param cs A command stream. + * \param buf A winsys buffer. + * \param domain A bitmask of the R300_REF_* enums. + */ + boolean (*cs_is_buffer_referenced)(struct r300_winsys_cs *cs, + struct r300_winsys_cs_buffer *buf, + enum r300_reference_domain domain); +}; + +#endif /* R300_WINSYS_H */ diff --git a/src/gallium/drivers/r600/Makefile b/src/gallium/drivers/r600/Makefile new file mode 100644 index 0000000..b476b9a --- /dev/null +++ b/src/gallium/drivers/r600/Makefile @@ -0,0 +1,27 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = r600 + +LIBRARY_INCLUDES = \ + $(shell pkg-config libdrm --cflags-only-I) + +C_SOURCES = \ + r600_asm.c \ + r600_blit.c \ + r600_buffer.c \ + r600_helper.c \ + r600_pipe.c \ + r600_query.c \ + r600_resource.c \ + r600_shader.c \ + r600_state.c \ + r600_texture.c \ + r700_asm.c \ + evergreen_state.c \ + eg_asm.c \ + r600_translate.c \ + r600_state_common.c \ + r600_upload.c + +include ../../Makefile.template diff --git a/src/gallium/drivers/r600/SConscript b/src/gallium/drivers/r600/SConscript new file mode 100644 index 0000000..6498014 --- /dev/null +++ b/src/gallium/drivers/r600/SConscript @@ -0,0 +1,39 @@ +Import('*') + +env = env.Clone() + +try: + env.ParseConfig('pkg-config --cflags libdrm_radeon') +except OSError: + print 'warning: not building r600' + Return() + +env.Append(CPPPATH = [ + '#/include', + '#/src/mesa', +]) + +r600 = env.ConvenienceLibrary( + target = 'r600', + source = [ + 'r600_asm.c', + 'r600_buffer.c', + 'r600_blit.c', + 'r600_helper.c', + 'r600_pipe.c', + 'r600_query.c', + 'r600_resource.c', + 'r600_shader.c', + 'r600_state.c', + 'r600_state_common.c', + 'r600_texture.c', + 'r600_translate.c', + 'r600_upload.c', + 'r700_asm.c', + 'evergreen_state.c', + 'eg_asm.c', + ]) + +env.Alias('r600', r600) + +Export('r600') diff --git a/src/gallium/drivers/r600/eg_asm.c b/src/gallium/drivers/r600/eg_asm.c new file mode 100644 index 0000000..b79875c --- /dev/null +++ b/src/gallium/drivers/r600/eg_asm.c @@ -0,0 +1,126 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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 +#include +#include "util/u_memory.h" +#include "r600_pipe.h" +#include "r600_asm.h" +#include "eg_sq.h" +#include "r600_opcodes.h" +#include "evergreend.h" + +int eg_bc_cf_build(struct r600_bc *bc, struct r600_bc_cf *cf) +{ + unsigned id = cf->id; + + switch (cf->inst) { + case (EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3): + case (EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3): + bc->bytecode[id++] = S_SQ_CF_ALU_WORD0_ADDR(cf->addr >> 1) | + S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf->kcache0_mode) | + S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf->kcache0_bank) | + S_SQ_CF_ALU_WORD0_KCACHE_BANK1(cf->kcache1_bank); + bc->bytecode[id++] = S_SQ_CF_ALU_WORD1_CF_INST(cf->inst >> 3) | + S_SQ_CF_ALU_WORD1_KCACHE_MODE1(cf->kcache1_mode) | + S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(cf->kcache0_addr) | + S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(cf->kcache1_addr) | + S_SQ_CF_ALU_WORD1_BARRIER(1) | + S_SQ_CF_ALU_WORD1_COUNT((cf->ndw / 2) - 1); + break; + case EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX: + case EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX: + bc->bytecode[id++] = S_SQ_CF_WORD0_ADDR(cf->addr >> 1); + bc->bytecode[id++] = S_SQ_CF_WORD1_CF_INST(cf->inst) | + S_SQ_CF_WORD1_BARRIER(1) | + S_SQ_CF_WORD1_COUNT((cf->ndw / 4) - 1); + break; + case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT: + case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE: + bc->bytecode[id++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf->output.gpr) | + S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf->output.elem_size) | + S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf->output.array_base) | + S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf->output.type); + bc->bytecode[id++] = S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf->output.swizzle_x) | + S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf->output.swizzle_y) | + S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf->output.swizzle_z) | + S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf->output.swizzle_w) | + S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf->output.barrier) | + S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf->output.inst) | + S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf->output.end_of_program); + break; + case EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMP: + case EG_V_SQ_CF_WORD1_SQ_CF_INST_ELSE: + case EG_V_SQ_CF_WORD1_SQ_CF_INST_POP: + case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL: + case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END: + case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE: + case EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK: + case EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS: + case EG_V_SQ_CF_WORD1_SQ_CF_INST_RETURN: + bc->bytecode[id++] = S_SQ_CF_WORD0_ADDR(cf->cf_addr >> 1); + bc->bytecode[id++] = S_SQ_CF_WORD1_CF_INST(cf->inst) | + S_SQ_CF_WORD1_BARRIER(1) | + S_SQ_CF_WORD1_COND(cf->cond) | + S_SQ_CF_WORD1_POP_COUNT(cf->pop_count); + + break; + default: + R600_ERR("unsupported CF instruction (0x%X)\n", cf->inst); + return -EINVAL; + } + return 0; +} + +void eg_cf_vtx(struct r600_vertex_element *ve, u32 *bytecode, unsigned count) +{ + struct r600_pipe_state *rstate; + unsigned i = 0; + + if (count > 8) { + bytecode[i++] = S_SQ_CF_WORD0_ADDR(8 >> 1); + bytecode[i++] = S_SQ_CF_WORD1_CF_INST(EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX) | + S_SQ_CF_WORD1_BARRIER(1) | + S_SQ_CF_WORD1_COUNT(8 - 1); + bytecode[i++] = S_SQ_CF_WORD0_ADDR(40 >> 1); + bytecode[i++] = S_SQ_CF_WORD1_CF_INST(EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX) | + S_SQ_CF_WORD1_BARRIER(1) | + S_SQ_CF_WORD1_COUNT(count - 8 - 1); + } else { + bytecode[i++] = S_SQ_CF_WORD0_ADDR(8 >> 1); + bytecode[i++] = S_SQ_CF_WORD1_CF_INST(EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX) | + S_SQ_CF_WORD1_BARRIER(1) | + S_SQ_CF_WORD1_COUNT(count - 1); + } + bytecode[i++] = S_SQ_CF_WORD0_ADDR(0); + bytecode[i++] = S_SQ_CF_WORD1_CF_INST(EG_V_SQ_CF_WORD1_SQ_CF_INST_RETURN) | + S_SQ_CF_WORD1_BARRIER(1); + + rstate = &ve->rstate; + rstate->id = R600_PIPE_STATE_FETCH_SHADER; + rstate->nregs = 0; + r600_pipe_state_add_reg(rstate, R_0288A8_SQ_PGM_RESOURCES_FS, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0288A4_SQ_PGM_START_FS, + (r600_bo_offset(ve->fetch_shader)) >> 8, + 0xFFFFFFFF, ve->fetch_shader); +} diff --git a/src/gallium/drivers/r600/eg_sq.h b/src/gallium/drivers/r600/eg_sq.h new file mode 100644 index 0000000..f80e8bd --- /dev/null +++ b/src/gallium/drivers/r600/eg_sq.h @@ -0,0 +1,485 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#ifndef EG_SQ_H +#define EG_SQ_H + +#define P_SQ_CF_WORD0 +#define S_SQ_CF_WORD0_ADDR(x) (((x) & 0xFFFFFF) << 0) +#define G_SQ_CF_WORD0_ADDR(x) (((x) >> 0) & 0xFFFFFF) +#define C_SQ_CF_WORD0_ADDR 0x00000000 +#define S_SQ_CF_WORD0_JUMPTABLE_SEL(x) (((x) & 0x7) << 24) +#define G_SQ_CF_WORD0_JUMPTABLE_SEL(x) (((x) >> 24) & 0x7) +#define C_SQ_CF_WORD0_JUMPTABLE_SEL 0xF8FFFFFF +#define P_SQ_CF_WORD1 +#define S_SQ_CF_WORD1_POP_COUNT(x) (((x) & 0x7) << 0) +#define G_SQ_CF_WORD1_POP_COUNT(x) (((x) >> 0) & 0x7) +#define C_SQ_CF_WORD1_POP_COUNT 0xFFFFFFF8 +#define S_SQ_CF_WORD1_CF_CONST(x) (((x) & 0x1F) << 3) +#define G_SQ_CF_WORD1_CF_CONST(x) (((x) >> 3) & 0x1F) +#define C_SQ_CF_WORD1_CF_CONST 0xFFFFFF07 +#define S_SQ_CF_WORD1_COND(x) (((x) & 0x3) << 8) +#define G_SQ_CF_WORD1_COND(x) (((x) >> 8) & 0x3) +#define C_SQ_CF_WORD1_COND 0xFFFFFCFF +#define S_SQ_CF_WORD1_COUNT(x) (((x) & 0x3f) << 10) +#define G_SQ_CF_WORD1_COUNT(x) (((x) >> 10) & 0x3f) +#define C_SQ_CF_WORD1_COUNT 0xFFFF03FF +#define S_SQ_CF_WORD1_VALID_PIXEL_MODE(x) (((x) & 0x1) << 20) +#define G_SQ_CF_WORD1_VALID_PIXEL_MODE(x) (((x) >> 20) & 0x1) +#define C_SQ_CF_WORD1_VALID_PIXEL_MODE 0xFFEFFFFF +#define S_SQ_CF_WORD1_END_OF_PROGRAM(x) (((x) & 0x1) << 21) +#define G_SQ_CF_WORD1_END_OF_PROGRAM(x) (((x) >> 21) & 0x1) +#define C_SQ_CF_WORD1_END_OF_PROGRAM 0xFFDFFFFF + +#define S_SQ_CF_WORD1_CF_INST(x) (((x) & 0xFF) << 22) +#define G_SQ_CF_WORD1_CF_INST(x) (((x) >> 22) & 0xFF) +#define C_SQ_CF_WORD1_CF_INST 0xC03FFFFF + +#define S_SQ_CF_WORD1_WHOLE_QUAD_MODE(x) (((x) & 0x1) << 30) +#define G_SQ_CF_WORD1_WHOLE_QUAD_MODE(x) (((x) >> 30) & 0x1) +#define C_SQ_CF_WORD1_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_SQ_CF_WORD1_BARRIER(x) (((x) & 0x1) << 31) +#define G_SQ_CF_WORD1_BARRIER(x) (((x) >> 31) & 0x1) +#define C_SQ_CF_WORD1_BARRIER 0x7FFFFFFF + +/* done */ +#define P_SQ_CF_ALU_WORD0 +#define S_SQ_CF_ALU_WORD0_ADDR(x) (((x) & 0x3FFFFF) << 0) +#define G_SQ_CF_ALU_WORD0_ADDR(x) (((x) >> 0) & 0x3FFFFF) +#define C_SQ_CF_ALU_WORD0_ADDR 0xFFC00000 +#define S_SQ_CF_ALU_WORD0_KCACHE_BANK0(x) (((x) & 0xF) << 22) +#define G_SQ_CF_ALU_WORD0_KCACHE_BANK0(x) (((x) >> 22) & 0xF) +#define C_SQ_CF_ALU_WORD0_KCACHE_BANK0 0xFC3FFFFF +#define S_SQ_CF_ALU_WORD0_KCACHE_BANK1(x) (((x) & 0xF) << 26) +#define G_SQ_CF_ALU_WORD0_KCACHE_BANK1(x) (((x) >> 26) & 0xF) +#define C_SQ_CF_ALU_WORD0_KCACHE_BANK1 0xC3FFFFFF +#define S_SQ_CF_ALU_WORD0_KCACHE_MODE0(x) (((x) & 0x3) << 30) +#define G_SQ_CF_ALU_WORD0_KCACHE_MODE0(x) (((x) >> 30) & 0x3) +#define C_SQ_CF_ALU_WORD0_KCACHE_MODE0 0x3FFFFFFF +#define P_SQ_CF_ALU_WORD1 +#define S_SQ_CF_ALU_WORD1_KCACHE_MODE1(x) (((x) & 0x3) << 0) +#define G_SQ_CF_ALU_WORD1_KCACHE_MODE1(x) (((x) >> 0) & 0x3) +#define C_SQ_CF_ALU_WORD1_KCACHE_MODE1 0xFFFFFFFC +#define S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(x) (((x) & 0xFF) << 2) +#define G_SQ_CF_ALU_WORD1_KCACHE_ADDR0(x) (((x) >> 2) & 0xFF) +#define C_SQ_CF_ALU_WORD1_KCACHE_ADDR0 0xFFFFFC03 +#define S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(x) (((x) & 0xFF) << 10) +#define G_SQ_CF_ALU_WORD1_KCACHE_ADDR1(x) (((x) >> 10) & 0xFF) +#define C_SQ_CF_ALU_WORD1_KCACHE_ADDR1 0xFFFC03FF +#define S_SQ_CF_ALU_WORD1_COUNT(x) (((x) & 0x7F) << 18) +#define G_SQ_CF_ALU_WORD1_COUNT(x) (((x) >> 18) & 0x7F) +#define C_SQ_CF_ALU_WORD1_COUNT 0xFE03FFFF +#define S_SQ_CF_ALU_WORD1_ALT_CONST(x) (((x) & 0x1) << 25) +#define G_SQ_CF_ALU_WORD1_ALT_CONST(x) (((x) >> 25) & 0x1) +#define C_SQ_CF_ALU_WORD1_ALT_CONST 0xFDFFFFFF +#define S_SQ_CF_ALU_WORD1_CF_INST(x) (((x) & 0xF) << 26) +#define G_SQ_CF_ALU_WORD1_CF_INST(x) (((x) >> 26) & 0xF) +#define C_SQ_CF_ALU_WORD1_CF_INST 0xC3FFFFFF +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU 0x00000008 +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE 0x00000009 +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER 0x0000000A +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER 0x0000000B +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_EXTENDED 0x0000000C +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_CONTINUE 0x0000000D +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_BREAK 0x0000000E +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_ELSE_AFTER 0x0000000F +#define S_SQ_CF_ALU_WORD1_WHOLE_QUAD_MODE(x) (((x) & 0x1) << 30) +#define G_SQ_CF_ALU_WORD1_WHOLE_QUAD_MODE(x) (((x) >> 30) & 0x1) +#define C_SQ_CF_ALU_WORD1_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_SQ_CF_ALU_WORD1_BARRIER(x) (((x) & 0x1) << 31) +#define G_SQ_CF_ALU_WORD1_BARRIER(x) (((x) >> 31) & 0x1) +#define C_SQ_CF_ALU_WORD1_BARRIER 0x7FFFFFFF +/* extended TODO */ +/* done */ +#define P_SQ_CF_ALLOC_EXPORT_WORD0 +#define S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(x) (((x) & 0x1FFF) << 0) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(x) (((x) >> 0) & 0x1FFF) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE 0xFFFFE000 +#define S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(x) (((x) & 0x3) << 13) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(x) (((x) >> 13) & 0x3) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_TYPE 0xFFFF9FFF +#define V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL 0x00000000 +#define V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS 0x00000001 +#define V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM 0x00000002 +#define V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_WRITE_IND_ACK 0x00000003 +#define S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(x) (((x) & 0x7F) << 15) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(x) (((x) >> 15) & 0x7F) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR 0xFFC07FFF +#define S_SQ_CF_ALLOC_EXPORT_WORD0_RW_REL(x) (((x) & 0x1) << 22) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_RW_REL(x) (((x) >> 22) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_RW_REL 0xFFBFFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD0_INDEX_GPR(x) (((x) & 0x7F) << 23) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_INDEX_GPR(x) (((x) >> 23) & 0x7F) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_INDEX_GPR 0xC07FFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(x) (((x) & 0x3) << 30) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(x) (((x) >> 30) & 0x3) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE 0x3FFFFFFF +/* done */ +#define P_SQ_CF_ALLOC_EXPORT_WORD1 +#define S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(x) (((x) & 0xF) << 16) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(x) (((x) >> 16) & 0xF) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT 0xFFF0FFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_VALID_PIXEL_MODE(x) (((x) & 0x1) << 20) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_VALID_PIXEL_MODE(x) (((x) >> 20) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_VALID_PIXEL_MODE 0xFFEFFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(x) (((x) & 0x1) << 21) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(x) (((x) >> 21) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM 0xFFDFFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(x) (((x) & 0xFF) << 22) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(x) (((x) >> 22) & 0xFF) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST 0xC03FFFFF + +#define S_SQ_CF_ALLOC_EXPORT_WORD1_MARK(x) (((x) & 0x1) << 30) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_MARK(x) (((x) >> 30) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(x) (((x) & 0x1) << 31) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(x) (((x) >> 31) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER 0x7FFFFFFF + +/* done */ +#define P_SQ_CF_ALLOC_EXPORT_WORD1_BUF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(x) (((x) & 0xFFF) << 0) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(x) (((x) >> 0) & 0xFFF) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE 0xFFFFF000 +#define S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(x) (((x) & 0xF) << 12) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(x) (((x) >> 12) & 0xF) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK 0xFFFF0FFF +#define P_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ +#define S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(x) (((x) & 0x7) << 0) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(x) (((x) >> 0) & 0x7) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X 0xFFFFFFF8 +#define S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(x) (((x) & 0x7) << 3) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(x) (((x) >> 3) & 0x7) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y 0xFFFFFFC7 +#define S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(x) (((x) & 0x7) << 6) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(x) (((x) >> 6) & 0x7) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z 0xFFFFFE3F +#define S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(x) (((x) & 0x7) << 9) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(x) (((x) >> 9) & 0x7) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W 0xFFFFF1FF + +/* done */ +#define P_SQ_ALU_WORD0 +#define S_SQ_ALU_WORD0_SRC0_SEL(x) (((x) & 0x1FF) << 0) +#define G_SQ_ALU_WORD0_SRC0_SEL(x) (((x) >> 0) & 0x1FF) +#define C_SQ_ALU_WORD0_SRC0_SEL 0xFFFFFE00 + +/* + * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+) + * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+) + * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+) + * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+) + * 248 SQ_ALU_SRC_0: special constant 0.0. + * 249 SQ_ALU_SRC_1: special constant 1.0 float. + * 250 SQ_ALU_SRC_1_INT: special constant 1 integer. + * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer. + * 252 SQ_ALU_SRC_0_5: special constant 0.5 float. + * 253 SQ_ALU_SRC_LITERAL: literal constant. + * 254 SQ_ALU_SRC_PV: previous vector result. + * 255 SQ_ALU_SRC_PS: previous scalar result. + */ +#define V_SQ_ALU_SRC_0 0x000000F8 +#define V_SQ_ALU_SRC_1 0x000000F9 +#define V_SQ_ALU_SRC_1_INT 0x000000FA +#define V_SQ_ALU_SRC_M_1_INT 0x000000FB +#define V_SQ_ALU_SRC_0_5 0x000000FC +#define V_SQ_ALU_SRC_LITERAL 0x000000FD +#define S_SQ_ALU_WORD0_SRC0_REL(x) (((x) & 0x1) << 9) +#define G_SQ_ALU_WORD0_SRC0_REL(x) (((x) >> 9) & 0x1) +#define C_SQ_ALU_WORD0_SRC0_REL 0xFFFFFDFF +#define S_SQ_ALU_WORD0_SRC0_CHAN(x) (((x) & 0x3) << 10) +#define G_SQ_ALU_WORD0_SRC0_CHAN(x) (((x) >> 10) & 0x3) +#define C_SQ_ALU_WORD0_SRC0_CHAN 0xFFFFF3FF +#define S_SQ_ALU_WORD0_SRC0_NEG(x) (((x) & 0x1) << 12) +#define G_SQ_ALU_WORD0_SRC0_NEG(x) (((x) >> 12) & 0x1) +#define C_SQ_ALU_WORD0_SRC0_NEG 0xFFFFEFFF +#define S_SQ_ALU_WORD0_SRC1_SEL(x) (((x) & 0x1FF) << 13) +#define G_SQ_ALU_WORD0_SRC1_SEL(x) (((x) >> 13) & 0x1FF) +#define C_SQ_ALU_WORD0_SRC1_SEL 0xFFC01FFF +#define S_SQ_ALU_WORD0_SRC1_REL(x) (((x) & 0x1) << 22) +#define G_SQ_ALU_WORD0_SRC1_REL(x) (((x) >> 22) & 0x1) +#define C_SQ_ALU_WORD0_SRC1_REL 0xFFBFFFFF +#define S_SQ_ALU_WORD0_SRC1_CHAN(x) (((x) & 0x3) << 23) +#define G_SQ_ALU_WORD0_SRC1_CHAN(x) (((x) >> 23) & 0x3) +#define C_SQ_ALU_WORD0_SRC1_CHAN 0xFE7FFFFF +#define S_SQ_ALU_WORD0_SRC1_NEG(x) (((x) & 0x1) << 25) +#define G_SQ_ALU_WORD0_SRC1_NEG(x) (((x) >> 25) & 0x1) +#define C_SQ_ALU_WORD0_SRC1_NEG 0xFDFFFFFF +#define S_SQ_ALU_WORD0_INDEX_MODE(x) (((x) & 0x7) << 26) +#define G_SQ_ALU_WORD0_INDEX_MODE(x) (((x) >> 26) & 0x7) +#define C_SQ_ALU_WORD0_INDEX_MODE 0xE3FFFFFF +#define S_SQ_ALU_WORD0_PRED_SEL(x) (((x) & 0x3) << 29) +#define G_SQ_ALU_WORD0_PRED_SEL(x) (((x) >> 29) & 0x3) +#define C_SQ_ALU_WORD0_PRED_SEL 0x9FFFFFFF +#define S_SQ_ALU_WORD0_LAST(x) (((x) & 0x1) << 31) +#define G_SQ_ALU_WORD0_LAST(x) (((x) >> 31) & 0x1) +#define C_SQ_ALU_WORD0_LAST 0x7FFFFFFF +/* same */ +#define P_SQ_ALU_WORD1 +#define S_SQ_ALU_WORD1_ENCODING(x) (((x) & 0x7) << 15) +#define G_SQ_ALU_WORD1_ENCODING(x) (((x) >> 15) & 0x7) +#define C_SQ_ALU_WORD1_ENCODING 0xFFFC7FFF +#define S_SQ_ALU_WORD1_BANK_SWIZZLE(x) (((x) & 0x7) << 18) +#define G_SQ_ALU_WORD1_BANK_SWIZZLE(x) (((x) >> 18) & 0x7) +#define C_SQ_ALU_WORD1_BANK_SWIZZLE 0xFFE3FFFF +#define S_SQ_ALU_WORD1_DST_GPR(x) (((x) & 0x7F) << 21) +#define G_SQ_ALU_WORD1_DST_GPR(x) (((x) >> 21) & 0x7F) +#define C_SQ_ALU_WORD1_DST_GPR 0xF01FFFFF +#define S_SQ_ALU_WORD1_DST_REL(x) (((x) & 0x1) << 28) +#define G_SQ_ALU_WORD1_DST_REL(x) (((x) >> 28) & 0x1) +#define C_SQ_ALU_WORD1_DST_REL 0xEFFFFFFF +#define S_SQ_ALU_WORD1_DST_CHAN(x) (((x) & 0x3) << 29) +#define G_SQ_ALU_WORD1_DST_CHAN(x) (((x) >> 29) & 0x3) +#define C_SQ_ALU_WORD1_DST_CHAN 0x9FFFFFFF +#define S_SQ_ALU_WORD1_CLAMP(x) (((x) & 0x1) << 31) +#define G_SQ_ALU_WORD1_CLAMP(x) (((x) >> 31) & 0x1) +#define C_SQ_ALU_WORD1_CLAMP 0x7FFFFFFF +/* same except maybe encoding */ +#define P_SQ_ALU_WORD1_OP2 +#define S_SQ_ALU_WORD1_OP2_SRC0_ABS(x) (((x) & 0x1) << 0) +#define G_SQ_ALU_WORD1_OP2_SRC0_ABS(x) (((x) >> 0) & 0x1) +#define C_SQ_ALU_WORD1_OP2_SRC0_ABS 0xFFFFFFFE +#define S_SQ_ALU_WORD1_OP2_SRC1_ABS(x) (((x) & 0x1) << 1) +#define G_SQ_ALU_WORD1_OP2_SRC1_ABS(x) (((x) >> 1) & 0x1) +#define C_SQ_ALU_WORD1_OP2_SRC1_ABS 0xFFFFFFFD +#define S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(x) (((x) & 0x1) << 2) +#define G_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(x) (((x) >> 2) & 0x1) +#define C_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK 0xFFFFFFFB +#define S_SQ_ALU_WORD1_OP2_UPDATE_PRED(x) (((x) & 0x1) << 3) +#define G_SQ_ALU_WORD1_OP2_UPDATE_PRED(x) (((x) >> 3) & 0x1) +#define C_SQ_ALU_WORD1_OP2_UPDATE_PRED 0xFFFFFFF7 +#define S_SQ_ALU_WORD1_OP2_WRITE_MASK(x) (((x) & 0x1) << 4) +#define G_SQ_ALU_WORD1_OP2_WRITE_MASK(x) (((x) >> 4) & 0x1) +#define C_SQ_ALU_WORD1_OP2_WRITE_MASK 0xFFFFFFEF +#define S_SQ_ALU_WORD1_OP2_OMOD(x) (((x) & 0x3) << 5) +#define G_SQ_ALU_WORD1_OP2_OMOD(x) (((x) >> 5) & 0x3) +#define C_SQ_ALU_WORD1_OP2_OMOD 0xFFFFFF9F +#define S_SQ_ALU_WORD1_OP2_ALU_INST(x) (((x) & 0x7FF) << 7) +#define G_SQ_ALU_WORD1_OP2_ALU_INST(x) (((x) >> 7) & 0x7FF) +#define C_SQ_ALU_WORD1_OP2_ALU_INST 0xFFFC007F + +#define P_SQ_ALU_WORD1_OP3 +#define S_SQ_ALU_WORD1_OP3_SRC2_SEL(x) (((x) & 0x1FF) << 0) +#define G_SQ_ALU_WORD1_OP3_SRC2_SEL(x) (((x) >> 0) & 0x1FF) +#define C_SQ_ALU_WORD1_OP3_SRC2_SEL 0xFFFFFE00 +#define S_SQ_ALU_WORD1_OP3_SRC2_REL(x) (((x) & 0x1) << 9) +#define G_SQ_ALU_WORD1_OP3_SRC2_REL(x) (((x) >> 9) & 0x1) +#define C_SQ_ALU_WORD1_OP3_SRC2_REL 0xFFFFFDFF +#define S_SQ_ALU_WORD1_OP3_SRC2_CHAN(x) (((x) & 0x3) << 10) +#define G_SQ_ALU_WORD1_OP3_SRC2_CHAN(x) (((x) >> 10) & 0x3) +#define C_SQ_ALU_WORD1_OP3_SRC2_CHAN 0xFFFFF3FF +#define S_SQ_ALU_WORD1_OP3_SRC2_NEG(x) (((x) & 0x1) << 12) +#define G_SQ_ALU_WORD1_OP3_SRC2_NEG(x) (((x) >> 12) & 0x1) +#define C_SQ_ALU_WORD1_OP3_SRC2_NEG 0xFFFFEFFF +#define S_SQ_ALU_WORD1_OP3_ALU_INST(x) (((x) & 0x1F) << 13) +#define G_SQ_ALU_WORD1_OP3_ALU_INST(x) (((x) >> 13) & 0x1F) +#define C_SQ_ALU_WORD1_OP3_ALU_INST 0xFFFC1FFF +/* TODO ADD OTHER OP3 */ +/* done */ +#define P_SQ_VTX_WORD0 +#define S_SQ_VTX_WORD0_VTX_INST(x) (((x) & 0x1F) << 0) +#define G_SQ_VTX_WORD0_VTX_INST(x) (((x) >> 0) & 0x1F) +#define C_SQ_VTX_WORD0_VTX_INST 0xFFFFFFE0 +#define S_SQ_VTX_WORD0_FETCH_TYPE(x) (((x) & 0x3) << 5) +#define G_SQ_VTX_WORD0_FETCH_TYPE(x) (((x) >> 5) & 0x3) +#define C_SQ_VTX_WORD0_FETCH_TYPE 0xFFFFFF9F +#define S_SQ_VTX_WORD0_FETCH_WHOLE_QUAD(x) (((x) & 0x1) << 7) +#define G_SQ_VTX_WORD0_FETCH_WHOLE_QUAD(x) (((x) >> 7) & 0x1) +#define C_SQ_VTX_WORD0_FETCH_WHOLE_QUAD 0xFFFFFF7F +#define S_SQ_VTX_WORD0_BUFFER_ID(x) (((x) & 0xFF) << 8) +#define G_SQ_VTX_WORD0_BUFFER_ID(x) (((x) >> 8) & 0xFF) +#define C_SQ_VTX_WORD0_BUFFER_ID 0xFFFF00FF +#define S_SQ_VTX_WORD0_SRC_GPR(x) (((x) & 0x7F) << 16) +#define G_SQ_VTX_WORD0_SRC_GPR(x) (((x) >> 16) & 0x7F) +#define C_SQ_VTX_WORD0_SRC_GPR 0xFF80FFFF +#define S_SQ_VTX_WORD0_SRC_REL(x) (((x) & 0x1) << 23) +#define G_SQ_VTX_WORD0_SRC_REL(x) (((x) >> 23) & 0x1) +#define C_SQ_VTX_WORD0_SRC_REL 0xFF7FFFFF +#define S_SQ_VTX_WORD0_SRC_SEL_X(x) (((x) & 0x3) << 24) +#define G_SQ_VTX_WORD0_SRC_SEL_X(x) (((x) >> 24) & 0x3) +#define C_SQ_VTX_WORD0_SRC_SEL_X 0xFCFFFFFF +#define S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(x) (((x) & 0x3F) << 26) +#define G_SQ_VTX_WORD0_MEGA_FETCH_COUNT(x) (((x) >> 26) & 0x3F) +#define C_SQ_VTX_WORD0_MEGA_FETCH_COUNT 0x03FFFFFF +/* same WORD 0 */ +#define P_SQ_VTX_WORD1 +#define S_SQ_VTX_WORD1_DST_SEL_X(x) (((x) & 0x7) << 9) +#define G_SQ_VTX_WORD1_DST_SEL_X(x) (((x) >> 9) & 0x7) +#define C_SQ_VTX_WORD1_DST_SEL_X 0xFFFFF1FF +#define S_SQ_VTX_WORD1_DST_SEL_Y(x) (((x) & 0x7) << 12) +#define G_SQ_VTX_WORD1_DST_SEL_Y(x) (((x) >> 12) & 0x7) +#define C_SQ_VTX_WORD1_DST_SEL_Y 0xFFFF8FFF +#define S_SQ_VTX_WORD1_DST_SEL_Z(x) (((x) & 0x7) << 15) +#define G_SQ_VTX_WORD1_DST_SEL_Z(x) (((x) >> 15) & 0x7) +#define C_SQ_VTX_WORD1_DST_SEL_Z 0xFFFC7FFF +#define S_SQ_VTX_WORD1_DST_SEL_W(x) (((x) & 0x7) << 18) +#define G_SQ_VTX_WORD1_DST_SEL_W(x) (((x) >> 18) & 0x7) +#define C_SQ_VTX_WORD1_DST_SEL_W 0xFFE3FFFF +#define S_SQ_VTX_WORD1_USE_CONST_FIELDS(x) (((x) & 0x1) << 21) +#define G_SQ_VTX_WORD1_USE_CONST_FIELDS(x) (((x) >> 21) & 0x1) +#define C_SQ_VTX_WORD1_USE_CONST_FIELDS 0xFFDFFFFF +#define S_SQ_VTX_WORD1_DATA_FORMAT(x) (((x) & 0x3F) << 22) +#define G_SQ_VTX_WORD1_DATA_FORMAT(x) (((x) >> 22) & 0x3F) +#define C_SQ_VTX_WORD1_DATA_FORMAT 0xF03FFFFF +#define S_SQ_VTX_WORD1_NUM_FORMAT_ALL(x) (((x) & 0x3) << 28) +#define G_SQ_VTX_WORD1_NUM_FORMAT_ALL(x) (((x) >> 28) & 0x3) +#define C_SQ_VTX_WORD1_NUM_FORMAT_ALL 0xCFFFFFFF +#define S_SQ_VTX_WORD1_FORMAT_COMP_ALL(x) (((x) & 0x1) << 30) +#define G_SQ_VTX_WORD1_FORMAT_COMP_ALL(x) (((x) >> 30) & 0x1) +#define C_SQ_VTX_WORD1_FORMAT_COMP_ALL 0xBFFFFFFF +#define S_SQ_VTX_WORD1_SRF_MODE_ALL(x) (((x) & 0x1) << 31) +#define G_SQ_VTX_WORD1_SRF_MODE_ALL(x) (((x) >> 31) & 0x1) +#define C_SQ_VTX_WORD1_SRF_MODE_ALL 0x7FFFFFFF +/* same WORD1 generic */ +#define P_SQ_VTX_WORD1_GPR +#define S_SQ_VTX_WORD1_GPR_DST_GPR(x) (((x) & 0x7F) << 0) +#define G_SQ_VTX_WORD1_GPR_DST_GPR(x) (((x) >> 0) & 0x7F) +#define C_SQ_VTX_WORD1_GPR_DST_GPR 0xFFFFFF80 +#define S_SQ_VTX_WORD1_GPR_DST_REL(x) (((x) & 0x1) << 7) +#define G_SQ_VTX_WORD1_GPR_DST_REL(x) (((x) >> 7) & 0x1) +#define C_SQ_VTX_WORD1_GPR_DST_REL 0xFFFFFF7F +#define P_SQ_VTX_WORD1_SEM +#define S_SQ_VTX_WORD1_SEM_SEMANTIC_ID(x) (((x) & 0xFF) << 0) +#define G_SQ_VTX_WORD1_SEM_SEMANTIC_ID(x) (((x) >> 0) & 0xFF) +#define C_SQ_VTX_WORD1_SEM_SEMANTIC_ID 0xFFFFFF00 +#define P_SQ_VTX_WORD2 +#define S_SQ_VTX_WORD2_OFFSET(x) (((x) & 0xFFFF) << 0) +#define G_SQ_VTX_WORD2_OFFSET(x) (((x) >> 0) & 0xFFFF) +#define C_SQ_VTX_WORD2_OFFSET 0xFFFF0000 +#define S_SQ_VTX_WORD2_ENDIAN_SWAP(x) (((x) & 0x3) << 16) +#define G_SQ_VTX_WORD2_ENDIAN_SWAP(x) (((x) >> 16) & 0x3) +#define C_SQ_VTX_WORD2_ENDIAN_SWAP 0xFFFCFFFF +#define S_SQ_VTX_WORD2_CONST_BUF_NO_STRIDE(x) (((x) & 0x1) << 18) +#define G_SQ_VTX_WORD2_CONST_BUF_NO_STRIDE(x) (((x) >> 18) & 0x1) +#define C_SQ_VTX_WORD2_CONST_BUF_NO_STRIDE 0xFFFBFFFF +#define S_SQ_VTX_WORD2_MEGA_FETCH(x) (((x) & 0x1) << 19) +#define G_SQ_VTX_WORD2_MEGA_FETCH(x) (((x) >> 19) & 0x1) +#define C_SQ_VTX_WORD2_MEGA_FETCH 0xFFF7FFFF +#define S_SQ_VTX_WORD2_ALT_CONST(x) (((x) & 0x1) << 20) +#define G_SQ_VTX_WORD2_ALT_CONST(x) (((x) >> 20) & 0x1) +#define C_SQ_VTX_WORD2_ALT_CONST 0xFFEFFFFF +#define S_SQ_VTX_WORD2_BIM(x) (((x) & 0x3) << 21) +#define G_SQ_VTX_WORD2_BIM(x) (((x) >> 21) & 0x3) +#define C_SQ_VTX_WORD2_BIM 0xFF9FFFFF +/* done */ + +#define P_SQ_TEX_WORD0 +#define S_SQ_TEX_WORD0_TEX_INST(x) (((x) & 0x1F) << 0) +#define G_SQ_TEX_WORD0_TEX_INST(x) (((x) >> 0) & 0x1F) +#define C_SQ_TEX_WORD0_TEX_INST 0xFFFFFFE0 +#define S_SQ_TEX_WORD0_INST_MOD(x) (((x) & 0x3) << 5) +#define G_SQ_TEX_WORD0_INST_MOD(x) (((x) >> 5) & 0x3) +#define C_SQ_TEX_WORD0_INST_MOD 0xFFFFFF9F +#define S_SQ_TEX_WORD0_FETCH_WHOLE_QUAD(x) (((x) & 0x1) << 7) +#define G_SQ_TEX_WORD0_FETCH_WHOLE_QUAD(x) (((x) >> 7) & 0x1) +#define C_SQ_TEX_WORD0_FETCH_WHOLE_QUAD 0xFFFFFF7F +#define S_SQ_TEX_WORD0_RESOURCE_ID(x) (((x) & 0xFF) << 8) +#define G_SQ_TEX_WORD0_RESOURCE_ID(x) (((x) >> 8) & 0xFF) +#define C_SQ_TEX_WORD0_RESOURCE_ID 0xFFFF00FF +#define S_SQ_TEX_WORD0_SRC_GPR(x) (((x) & 0x7F) << 16) +#define G_SQ_TEX_WORD0_SRC_GPR(x) (((x) >> 16) & 0x7F) +#define C_SQ_TEX_WORD0_SRC_GPR 0xFF80FFFF +#define S_SQ_TEX_WORD0_SRC_REL(x) (((x) & 0x1) << 23) +#define G_SQ_TEX_WORD0_SRC_REL(x) (((x) >> 23) & 0x1) +#define C_SQ_TEX_WORD0_SRC_REL 0xFF7FFFFF +#define S_SQ_TEX_WORD0_ALT_CONST(x) (((x) & 0x1) << 24) +#define G_SQ_TEX_WORD0_ALT_CONST(x) (((x) >> 24) & 0x1) +#define C_SQ_TEX_WORD0_ALT_CONST 0xFEFFFFFF +#define S_SQ_TEX_WORD0_RIM(x) (((x) & 0x3) << 25) +#define G_SQ_TEX_WORD0_RIM(x) (((x) >> 25) & 0x3) +#define C_SQ_TEX_WORD0_RIM 0xF9FFFFFF +#define S_SQ_TEX_WORD0_SIM(x) (((x) & 0x3) << 27) +#define G_SQ_TEX_WORD0_SIM(x) (((x) >> 27) & 0x3) +#define C_SQ_TEX_WORD0_SIM 0xE7FFFFFF +#define P_SQ_TEX_WORD1 +#define S_SQ_TEX_WORD1_DST_GPR(x) (((x) & 0x7F) << 0) +#define G_SQ_TEX_WORD1_DST_GPR(x) (((x) >> 0) & 0x7F) +#define C_SQ_TEX_WORD1_DST_GPR 0xFFFFFF80 +#define S_SQ_TEX_WORD1_DST_REL(x) (((x) & 0x1) << 7) +#define G_SQ_TEX_WORD1_DST_REL(x) (((x) >> 7) & 0x1) +#define C_SQ_TEX_WORD1_DST_REL 0xFFFFFF7F +#define S_SQ_TEX_WORD1_DST_SEL_X(x) (((x) & 0x7) << 9) +#define G_SQ_TEX_WORD1_DST_SEL_X(x) (((x) >> 9) & 0x7) +#define C_SQ_TEX_WORD1_DST_SEL_X 0xFFFFF1FF +#define S_SQ_TEX_WORD1_DST_SEL_Y(x) (((x) & 0x7) << 12) +#define G_SQ_TEX_WORD1_DST_SEL_Y(x) (((x) >> 12) & 0x7) +#define C_SQ_TEX_WORD1_DST_SEL_Y 0xFFFF8FFF +#define S_SQ_TEX_WORD1_DST_SEL_Z(x) (((x) & 0x7) << 15) +#define G_SQ_TEX_WORD1_DST_SEL_Z(x) (((x) >> 15) & 0x7) +#define C_SQ_TEX_WORD1_DST_SEL_Z 0xFFFC7FFF +#define S_SQ_TEX_WORD1_DST_SEL_W(x) (((x) & 0x7) << 18) +#define G_SQ_TEX_WORD1_DST_SEL_W(x) (((x) >> 18) & 0x7) +#define C_SQ_TEX_WORD1_DST_SEL_W 0xFFE3FFFF +#define S_SQ_TEX_WORD1_LOD_BIAS(x) (((x) & 0x7F) << 21) +#define G_SQ_TEX_WORD1_LOD_BIAS(x) (((x) >> 21) & 0x7F) +#define C_SQ_TEX_WORD1_LOD_BIAS 0xF01FFFFF +#define S_SQ_TEX_WORD1_COORD_TYPE_X(x) (((x) & 0x1) << 28) +#define G_SQ_TEX_WORD1_COORD_TYPE_X(x) (((x) >> 28) & 0x1) +#define C_SQ_TEX_WORD1_COORD_TYPE_X 0xEFFFFFFF +#define V_SQ_TEX_WORD1_COORD_UNNORMALIZED 0x00000000 +#define V_SQ_TEX_WORD1_COORD_NORMALIZED 0x00000001 +#define S_SQ_TEX_WORD1_COORD_TYPE_Y(x) (((x) & 0x1) << 29) +#define G_SQ_TEX_WORD1_COORD_TYPE_Y(x) (((x) >> 29) & 0x1) +#define C_SQ_TEX_WORD1_COORD_TYPE_Y 0xDFFFFFFF +#define S_SQ_TEX_WORD1_COORD_TYPE_Z(x) (((x) & 0x1) << 30) +#define G_SQ_TEX_WORD1_COORD_TYPE_Z(x) (((x) >> 30) & 0x1) +#define C_SQ_TEX_WORD1_COORD_TYPE_Z 0xBFFFFFFF +#define S_SQ_TEX_WORD1_COORD_TYPE_W(x) (((x) & 0x1) << 31) +#define G_SQ_TEX_WORD1_COORD_TYPE_W(x) (((x) >> 31) & 0x1) +#define C_SQ_TEX_WORD1_COORD_TYPE_W 0x7FFFFFFF +#define P_SQ_TEX_WORD2 +#define S_SQ_TEX_WORD2_OFFSET_X(x) (((x) & 0x1F) << 0) +#define G_SQ_TEX_WORD2_OFFSET_X(x) (((x) >> 0) & 0x1F) +#define C_SQ_TEX_WORD2_OFFSET_X 0xFFFFFFE0 +#define S_SQ_TEX_WORD2_OFFSET_Y(x) (((x) & 0x1F) << 5) +#define G_SQ_TEX_WORD2_OFFSET_Y(x) (((x) >> 5) & 0x1F) +#define C_SQ_TEX_WORD2_OFFSET_Y 0xFFFFFC1F +#define S_SQ_TEX_WORD2_OFFSET_Z(x) (((x) & 0x1F) << 10) +#define G_SQ_TEX_WORD2_OFFSET_Z(x) (((x) >> 10) & 0x1F) +#define C_SQ_TEX_WORD2_OFFSET_Z 0xFFFF83FF +#define S_SQ_TEX_WORD2_SAMPLER_ID(x) (((x) & 0x1F) << 15) +#define G_SQ_TEX_WORD2_SAMPLER_ID(x) (((x) >> 15) & 0x1F) +#define C_SQ_TEX_WORD2_SAMPLER_ID 0xFFF07FFF +#define S_SQ_TEX_WORD2_SRC_SEL_X(x) (((x) & 0x7) << 20) +#define G_SQ_TEX_WORD2_SRC_SEL_X(x) (((x) >> 20) & 0x7) +#define C_SQ_TEX_WORD2_SRC_SEL_X 0xFF8FFFFF +#define S_SQ_TEX_WORD2_SRC_SEL_Y(x) (((x) & 0x7) << 23) +#define G_SQ_TEX_WORD2_SRC_SEL_Y(x) (((x) >> 23) & 0x7) +#define C_SQ_TEX_WORD2_SRC_SEL_Y 0xFC7FFFFF +#define S_SQ_TEX_WORD2_SRC_SEL_Z(x) (((x) & 0x7) << 26) +#define G_SQ_TEX_WORD2_SRC_SEL_Z(x) (((x) >> 26) & 0x7) +#define C_SQ_TEX_WORD2_SRC_SEL_Z 0xE3FFFFFF +#define S_SQ_TEX_WORD2_SRC_SEL_W(x) (((x) & 0x7) << 29) +#define G_SQ_TEX_WORD2_SRC_SEL_W(x) (((x) >> 29) & 0x7) +#define C_SQ_TEX_WORD2_SRC_SEL_W 0x1FFFFFFF + +#define V_SQ_CF_COND_ACTIVE 0x00 +#define V_SQ_CF_COND_FALSE 0x01 +#define V_SQ_CF_COND_BOOL 0x02 +#define V_SQ_CF_COND_NOT_BOOL 0x03 + +#define V_SQ_REL_ABSOLUTE 0 +#define V_SQ_REL_RELATIVE 1 +#endif diff --git a/src/gallium/drivers/r600/eg_state_inlines.h b/src/gallium/drivers/r600/eg_state_inlines.h new file mode 100644 index 0000000..ecea1db --- /dev/null +++ b/src/gallium/drivers/r600/eg_state_inlines.h @@ -0,0 +1,644 @@ +/* + * Copyright 2010 Red Hat 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 + * 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 EG_STATE_INLINES_H +#define EG_STATE_INLINES_H + +#include "util/u_format.h" +#include "evergreend.h" +#include "r600_formats.h" + +static INLINE uint32_t r600_translate_blend_function(int blend_func) +{ + switch (blend_func) { + case PIPE_BLEND_ADD: + return V_028780_COMB_DST_PLUS_SRC; + case PIPE_BLEND_SUBTRACT: + return V_028780_COMB_SRC_MINUS_DST; + case PIPE_BLEND_REVERSE_SUBTRACT: + return V_028780_COMB_DST_MINUS_SRC; + case PIPE_BLEND_MIN: + return V_028780_COMB_MIN_DST_SRC; + case PIPE_BLEND_MAX: + return V_028780_COMB_MAX_DST_SRC; + default: + R600_ERR("Unknown blend function %d\n", blend_func); + assert(0); + break; + } + return 0; +} + +static INLINE uint32_t r600_translate_blend_factor(int blend_fact) +{ + switch (blend_fact) { + case PIPE_BLENDFACTOR_ONE: + return V_028780_BLEND_ONE; + case PIPE_BLENDFACTOR_SRC_COLOR: + return V_028780_BLEND_SRC_COLOR; + case PIPE_BLENDFACTOR_SRC_ALPHA: + return V_028780_BLEND_SRC_ALPHA; + case PIPE_BLENDFACTOR_DST_ALPHA: + return V_028780_BLEND_DST_ALPHA; + case PIPE_BLENDFACTOR_DST_COLOR: + return V_028780_BLEND_DST_COLOR; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + return V_028780_BLEND_SRC_ALPHA_SATURATE; + case PIPE_BLENDFACTOR_CONST_COLOR: + return V_028780_BLEND_CONST_COLOR; + case PIPE_BLENDFACTOR_CONST_ALPHA: + return V_028780_BLEND_CONST_ALPHA; + case PIPE_BLENDFACTOR_ZERO: + return V_028780_BLEND_ZERO; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + return V_028780_BLEND_ONE_MINUS_SRC_COLOR; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + return V_028780_BLEND_ONE_MINUS_SRC_ALPHA; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + return V_028780_BLEND_ONE_MINUS_DST_ALPHA; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + return V_028780_BLEND_ONE_MINUS_DST_COLOR; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + return V_028780_BLEND_ONE_MINUS_CONST_COLOR; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + return V_028780_BLEND_ONE_MINUS_CONST_ALPHA; + case PIPE_BLENDFACTOR_SRC1_COLOR: + return V_028780_BLEND_SRC1_COLOR; + case PIPE_BLENDFACTOR_SRC1_ALPHA: + return V_028780_BLEND_SRC1_ALPHA; + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + return V_028780_BLEND_INV_SRC1_COLOR; + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + return V_028780_BLEND_INV_SRC1_ALPHA; + default: + R600_ERR("Bad blend factor %d not supported!\n", blend_fact); + assert(0); + break; + } + return 0; +} + +static INLINE uint32_t r600_translate_stencil_op(int s_op) +{ + switch (s_op) { + case PIPE_STENCIL_OP_KEEP: + return V_028800_STENCIL_KEEP; + case PIPE_STENCIL_OP_ZERO: + return V_028800_STENCIL_ZERO; + case PIPE_STENCIL_OP_REPLACE: + return V_028800_STENCIL_REPLACE; + case PIPE_STENCIL_OP_INCR: + return V_028800_STENCIL_INCR; + case PIPE_STENCIL_OP_DECR: + return V_028800_STENCIL_DECR; + case PIPE_STENCIL_OP_INCR_WRAP: + return V_028800_STENCIL_INCR_WRAP; + case PIPE_STENCIL_OP_DECR_WRAP: + return V_028800_STENCIL_DECR_WRAP; + case PIPE_STENCIL_OP_INVERT: + return V_028800_STENCIL_INVERT; + default: + R600_ERR("Unknown stencil op %d", s_op); + assert(0); + break; + } + return 0; +} + +static INLINE uint32_t r600_translate_fill(uint32_t func) +{ + switch(func) { + case PIPE_POLYGON_MODE_FILL: + return 2; + case PIPE_POLYGON_MODE_LINE: + return 1; + case PIPE_POLYGON_MODE_POINT: + return 0; + default: + assert(0); + return 0; + } +} + +/* translates straight */ +static INLINE uint32_t r600_translate_ds_func(int func) +{ + return func; +} + +static inline unsigned r600_tex_wrap(unsigned wrap) +{ + switch (wrap) { + default: + case PIPE_TEX_WRAP_REPEAT: + return V_03C000_SQ_TEX_WRAP; + case PIPE_TEX_WRAP_CLAMP: + return V_03C000_SQ_TEX_CLAMP_HALF_BORDER; + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return V_03C000_SQ_TEX_CLAMP_LAST_TEXEL; + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + return V_03C000_SQ_TEX_CLAMP_BORDER; + case PIPE_TEX_WRAP_MIRROR_REPEAT: + return V_03C000_SQ_TEX_MIRROR; + case PIPE_TEX_WRAP_MIRROR_CLAMP: + return V_03C000_SQ_TEX_MIRROR_ONCE_HALF_BORDER; + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + return V_03C000_SQ_TEX_MIRROR_ONCE_LAST_TEXEL; + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + return V_03C000_SQ_TEX_MIRROR_ONCE_BORDER; + } +} + +static inline unsigned r600_tex_filter(unsigned filter) +{ + switch (filter) { + default: + case PIPE_TEX_FILTER_NEAREST: + return V_03C000_SQ_TEX_XY_FILTER_POINT; + case PIPE_TEX_FILTER_LINEAR: + return V_03C000_SQ_TEX_XY_FILTER_BILINEAR; + } +} + +static inline unsigned r600_tex_mipfilter(unsigned filter) +{ + switch (filter) { + case PIPE_TEX_MIPFILTER_NEAREST: + return V_03C000_SQ_TEX_Z_FILTER_POINT; + case PIPE_TEX_MIPFILTER_LINEAR: + return V_03C000_SQ_TEX_Z_FILTER_LINEAR; + default: + case PIPE_TEX_MIPFILTER_NONE: + return V_03C000_SQ_TEX_Z_FILTER_NONE; + } +} + +static inline unsigned r600_tex_compare(unsigned compare) +{ + switch (compare) { + default: + case PIPE_FUNC_NEVER: + return V_03C000_SQ_TEX_DEPTH_COMPARE_NEVER; + case PIPE_FUNC_LESS: + return V_03C000_SQ_TEX_DEPTH_COMPARE_LESS; + case PIPE_FUNC_EQUAL: + return V_03C000_SQ_TEX_DEPTH_COMPARE_EQUAL; + case PIPE_FUNC_LEQUAL: + return V_03C000_SQ_TEX_DEPTH_COMPARE_LESSEQUAL; + case PIPE_FUNC_GREATER: + return V_03C000_SQ_TEX_DEPTH_COMPARE_GREATER; + case PIPE_FUNC_NOTEQUAL: + return V_03C000_SQ_TEX_DEPTH_COMPARE_NOTEQUAL; + case PIPE_FUNC_GEQUAL: + return V_03C000_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL; + case PIPE_FUNC_ALWAYS: + return V_03C000_SQ_TEX_DEPTH_COMPARE_ALWAYS; + } +} + +static inline unsigned r600_tex_swizzle(unsigned swizzle) +{ + switch (swizzle) { + case PIPE_SWIZZLE_RED: + return V_030010_SQ_SEL_X; + case PIPE_SWIZZLE_GREEN: + return V_030010_SQ_SEL_Y; + case PIPE_SWIZZLE_BLUE: + return V_030010_SQ_SEL_Z; + case PIPE_SWIZZLE_ALPHA: + return V_030010_SQ_SEL_W; + case PIPE_SWIZZLE_ZERO: + return V_030010_SQ_SEL_0; + default: + case PIPE_SWIZZLE_ONE: + return V_030010_SQ_SEL_1; + } +} + +static inline unsigned r600_format_type(unsigned format_type) +{ + switch (format_type) { + default: + case UTIL_FORMAT_TYPE_UNSIGNED: + return V_030010_SQ_FORMAT_COMP_UNSIGNED; + case UTIL_FORMAT_TYPE_SIGNED: + return V_030010_SQ_FORMAT_COMP_SIGNED; + case UTIL_FORMAT_TYPE_FIXED: + return V_030010_SQ_FORMAT_COMP_UNSIGNED_BIASED; + } +} + +static inline unsigned r600_tex_dim(unsigned dim) +{ + switch (dim) { + default: + case PIPE_TEXTURE_1D: + return V_030000_SQ_TEX_DIM_1D; + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + return V_030000_SQ_TEX_DIM_2D; + case PIPE_TEXTURE_3D: + return V_030000_SQ_TEX_DIM_3D; + case PIPE_TEXTURE_CUBE: + return V_030000_SQ_TEX_DIM_CUBEMAP; + } +} + +static inline uint32_t r600_translate_dbformat(enum pipe_format format) +{ + switch (format) { + case PIPE_FORMAT_Z16_UNORM: + return V_028040_Z_16; + case PIPE_FORMAT_Z24X8_UNORM: + return V_028040_Z_24; + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + return V_028040_Z_24; + default: + return ~0; + } +} + +static inline uint32_t r600_translate_stencilformat(enum pipe_format format) +{ + if (format == PIPE_FORMAT_Z24_UNORM_S8_USCALED) + return 1; + else + return 0; +} + +static inline uint32_t r600_translate_colorswap(enum pipe_format format) +{ + switch (format) { + /* 8-bit buffers. */ + case PIPE_FORMAT_A8_UNORM: + return V_028C70_SWAP_ALT_REV; + case PIPE_FORMAT_I8_UNORM: + case PIPE_FORMAT_L8_UNORM: + case PIPE_FORMAT_R8_UNORM: + case PIPE_FORMAT_R8_SNORM: + return V_028C70_SWAP_STD; + + /* 16-bit buffers. */ + case PIPE_FORMAT_B5G6R5_UNORM: + return V_028C70_SWAP_STD_REV; + + case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B5G5R5X1_UNORM: + return V_028C70_SWAP_ALT; + + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B4G4R4X4_UNORM: + return V_028C70_SWAP_ALT; + + case PIPE_FORMAT_Z16_UNORM: + return V_028C70_SWAP_STD; + + case PIPE_FORMAT_L8A8_UNORM: + return V_028C70_SWAP_ALT; + case PIPE_FORMAT_R8G8_UNORM: + return V_028C70_SWAP_STD; + + case PIPE_FORMAT_R16_UNORM: + return V_028C70_SWAP_STD; + /* 32-bit buffers. */ + + case PIPE_FORMAT_A8B8G8R8_SRGB: + return V_028C70_SWAP_STD_REV; + case PIPE_FORMAT_B8G8R8A8_SRGB: + return V_028C70_SWAP_ALT; + + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + return V_028C70_SWAP_ALT; + + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_X8R8G8B8_UNORM: + return V_028C70_SWAP_ALT_REV; + case PIPE_FORMAT_R8G8B8A8_SNORM: + case PIPE_FORMAT_R8G8B8X8_UNORM: + return V_028C70_SWAP_STD; + + case PIPE_FORMAT_A8B8G8R8_UNORM: + case PIPE_FORMAT_X8B8G8R8_UNORM: + // case PIPE_FORMAT_R8SG8SB8UX8U_NORM: + return V_028C70_SWAP_STD_REV; + + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + return V_028C70_SWAP_STD; + + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + return V_028C70_SWAP_STD; + + case PIPE_FORMAT_R10G10B10A2_UNORM: + case PIPE_FORMAT_R10G10B10X2_SNORM: + case PIPE_FORMAT_B10G10R10A2_UNORM: + case PIPE_FORMAT_R10SG10SB10SA2U_NORM: + return V_028C70_SWAP_STD_REV; + + case PIPE_FORMAT_R16G16_UNORM: + return V_028C70_SWAP_STD; + + /* 64-bit buffers. */ + case PIPE_FORMAT_R16G16B16A16_UNORM: + case PIPE_FORMAT_R16G16B16A16_SNORM: + // return V_028C70_COLOR_16_16_16_16; + case PIPE_FORMAT_R16G16B16A16_FLOAT: + // return V_028C70_COLOR_16_16_16_16_FLOAT; + + /* 128-bit buffers. */ + case PIPE_FORMAT_R32G32B32A32_FLOAT: + // return V_028C70_COLOR_32_32_32_32_FLOAT; + return 0; + default: + R600_ERR("unsupported colorswap format %d\n", format); + return ~0; + } + return ~0; +} + +static INLINE uint32_t r600_translate_colorformat(enum pipe_format format) +{ + switch (format) { + /* 8-bit buffers. */ + case PIPE_FORMAT_A8_UNORM: + case PIPE_FORMAT_I8_UNORM: + case PIPE_FORMAT_L8_UNORM: + case PIPE_FORMAT_R8_UNORM: + case PIPE_FORMAT_R8_SNORM: + return V_028C70_COLOR_8; + + /* 16-bit buffers. */ + case PIPE_FORMAT_B5G6R5_UNORM: + return V_028C70_COLOR_5_6_5; + + case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B5G5R5X1_UNORM: + return V_028C70_COLOR_1_5_5_5; + + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B4G4R4X4_UNORM: + return V_028C70_COLOR_4_4_4_4; + + case PIPE_FORMAT_Z16_UNORM: + return V_028C70_COLOR_16; + + case PIPE_FORMAT_L8A8_UNORM: + case PIPE_FORMAT_R8G8_UNORM: + return V_028C70_COLOR_8_8; + + case PIPE_FORMAT_R16_UNORM: + return V_028C70_COLOR_16; + + /* 32-bit buffers. */ + case PIPE_FORMAT_A8B8G8R8_SRGB: + case PIPE_FORMAT_A8B8G8R8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_SRGB: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_R8G8B8A8_SNORM: + case PIPE_FORMAT_R8G8B8A8_UNORM: + case PIPE_FORMAT_R8G8B8X8_UNORM: + case PIPE_FORMAT_R8SG8SB8UX8U_NORM: + case PIPE_FORMAT_X8B8G8R8_UNORM: + case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_R8G8B8_UNORM: + return V_028C70_COLOR_8_8_8_8; + + case PIPE_FORMAT_R10G10B10A2_UNORM: + case PIPE_FORMAT_R10G10B10X2_SNORM: + case PIPE_FORMAT_B10G10R10A2_UNORM: + case PIPE_FORMAT_R10SG10SB10SA2U_NORM: + return V_028C70_COLOR_10_10_10_2; + + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + return V_028C70_COLOR_8_24; + + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + return V_028C70_COLOR_24_8; + + case PIPE_FORMAT_R32_FLOAT: + return V_028C70_COLOR_32_FLOAT; + + case PIPE_FORMAT_R16G16_FLOAT: + return V_028C70_COLOR_16_16_FLOAT; + + case PIPE_FORMAT_R16G16_SSCALED: + case PIPE_FORMAT_R16G16_UNORM: + return V_028C70_COLOR_16_16; + + /* 64-bit buffers. */ + case PIPE_FORMAT_R16G16B16_USCALED: + case PIPE_FORMAT_R16G16B16A16_USCALED: + case PIPE_FORMAT_R16G16B16_SSCALED: + case PIPE_FORMAT_R16G16B16A16_SSCALED: + case PIPE_FORMAT_R16G16B16A16_UNORM: + case PIPE_FORMAT_R16G16B16A16_SNORM: + return V_028C70_COLOR_16_16_16_16; + + case PIPE_FORMAT_R16G16B16_FLOAT: + case PIPE_FORMAT_R16G16B16A16_FLOAT: + return V_028C70_COLOR_16_16_16_16_FLOAT; + + case PIPE_FORMAT_R32G32_FLOAT: + return V_028C70_COLOR_32_32_FLOAT; + + case PIPE_FORMAT_R32G32_USCALED: + case PIPE_FORMAT_R32G32_SSCALED: + return V_028C70_COLOR_32_32; + + /* 128-bit buffers. */ + case PIPE_FORMAT_R32G32B32_FLOAT: + return V_028C70_COLOR_32_32_32_FLOAT; + case PIPE_FORMAT_R32G32B32A32_FLOAT: + return V_028C70_COLOR_32_32_32_32_FLOAT; + + /* YUV buffers. */ + case PIPE_FORMAT_UYVY: + case PIPE_FORMAT_YUYV: + default: + //R600_ERR("unsupported color format %d\n", format); + return ~0; /* Unsupported. */ + } +} + +static INLINE boolean r600_is_sampler_format_supported(enum pipe_format format) +{ + return r600_translate_texformat(format, NULL, NULL, NULL) != ~0; +} + +static INLINE boolean r600_is_colorbuffer_format_supported(enum pipe_format format) +{ + return r600_translate_colorformat(format) != ~0 && + r600_translate_colorswap(format) != ~0; +} + +static INLINE boolean r600_is_zs_format_supported(enum pipe_format format) +{ + return r600_translate_dbformat(format) != ~0; +} + +static INLINE boolean r600_is_vertex_format_supported(enum pipe_format format) +{ + return r600_translate_colorformat(format) != ~0; +} + +static INLINE uint32_t r600_translate_vertex_data_type(enum pipe_format format) +{ + uint32_t result = 0; + const struct util_format_description *desc; + unsigned i; + + desc = util_format_description(format); + if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { + goto out_unknown; + } + + /* Find the first non-VOID channel. */ + for (i = 0; i < 4; i++) { + if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { + break; + } + } + + switch (desc->channel[i].type) { + /* Half-floats, floats, doubles */ + case UTIL_FORMAT_TYPE_FLOAT: + switch (desc->channel[i].size) { + case 16: + switch (desc->nr_channels) { + case 1: + result = FMT_16_FLOAT; + break; + case 2: + result = FMT_16_16_FLOAT; + break; + case 3: + result = FMT_16_16_16_FLOAT; + break; + case 4: + result = FMT_16_16_16_16_FLOAT; + break; + } + break; + case 32: + switch (desc->nr_channels) { + case 1: + result = FMT_32_FLOAT; + break; + case 2: + result = FMT_32_32_FLOAT; + break; + case 3: + result = FMT_32_32_32_FLOAT; + break; + case 4: + result = FMT_32_32_32_32_FLOAT; + break; + } + break; + default: + goto out_unknown; + } + break; + /* Unsigned ints */ + case UTIL_FORMAT_TYPE_UNSIGNED: + /* Signed ints */ + case UTIL_FORMAT_TYPE_SIGNED: + switch (desc->channel[i].size) { + case 8: + switch (desc->nr_channels) { + case 1: + result = FMT_8; + break; + case 2: + result = FMT_8_8; + break; + case 3: +// result = V_038008_FMT_8_8_8; /* fails piglit draw-vertices test */ +// break; + case 4: + result = FMT_8_8_8_8; + break; + } + break; + case 16: + switch (desc->nr_channels) { + case 1: + result = FMT_16; + break; + case 2: + result = FMT_16_16; + break; + case 3: +// result = V_038008_FMT_16_16_16; /* fails piglit draw-vertices test */ +// break; + case 4: + result = FMT_16_16_16_16; + break; + } + break; + case 32: + switch (desc->nr_channels) { + case 1: + result = FMT_32; + break; + case 2: + result = FMT_32_32; + break; + case 3: + result = FMT_32_32_32; + break; + case 4: + result = FMT_32_32_32_32; + break; + } + break; + default: + goto out_unknown; + } + break; + default: + goto out_unknown; + } + + result = S_030008_DATA_FORMAT(result); + + if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) { + result |= S_030008_FORMAT_COMP_ALL(1); + } + if (desc->channel[i].normalized) { + result |= S_030008_NUM_FORMAT_ALL(0); + } else { + result |= S_030008_NUM_FORMAT_ALL(2); + } + return result; +out_unknown: + R600_ERR("unsupported vertex format %s\n", util_format_name(format)); + return ~0; +} + +#endif diff --git a/src/gallium/drivers/r600/eg_states_inc.h b/src/gallium/drivers/r600/eg_states_inc.h new file mode 100644 index 0000000..1379c11 --- /dev/null +++ b/src/gallium/drivers/r600/eg_states_inc.h @@ -0,0 +1,458 @@ +/* This file is autogenerated from eg_states.h - do not edit directly */ +/* autogenerating script is gen_eg_states.py */ + +/* EG_CONFIG */ +#define EG_CONFIG__SQ_CONFIG 0 +#define EG_CONFIG__SPI_CONFIG_CNTL 1 +#define EG_CONFIG__SPI_CONFIG_CNTL_1 2 +#define EG_CONFIG__SQ_GPR_RESOURCE_MGMT_1 3 +#define EG_CONFIG__SQ_GPR_RESOURCE_MGMT_2 4 +#define EG_CONFIG__SQ_GPR_RESOURCE_MGMT_3 5 +#define EG_CONFIG__SQ_THREAD_RESOURCE_MGMT_1 6 +#define EG_CONFIG__SQ_THREAD_RESOURCE_MGMT_2 7 +#define EG_CONFIG__SQ_STACK_RESOURCE_MGMT_1 8 +#define EG_CONFIG__SQ_STACK_RESOURCE_MGMT_2 9 +#define EG_CONFIG__SQ_STACK_RESOURCE_MGMT_3 10 +#define EG_CONFIG__SQ_DYN_GPR_CNTL_PS_FLUSH_REQ 11 +#define EG_CONFIG__PA_CL_ENHANCE 12 +#define EG_CONFIG__SQ_DYN_GPR_RESOURCE_LIMIT_1 13 +#define EG_CONFIG__SQ_LDS_ALLOC_PS 14 +#define EG_CONFIG__SX_MISC 15 +#define EG_CONFIG__SQ_ESGS_RING_ITEMSIZE 16 +#define EG_CONFIG__SQ_GSVS_RING_ITEMSIZE 17 +#define EG_CONFIG__SQ_ESTMP_RING_ITEMSIZE 18 +#define EG_CONFIG__SQ_GSTMP_RING_ITEMSIZE 19 +#define EG_CONFIG__SQ_VSTMP_RING_ITEMSIZE 20 +#define EG_CONFIG__SQ_PSTMP_RING_ITEMSIZE 21 +#define EG_CONFIG__SQ_GS_VERT_ITEMSIZE 22 +#define EG_CONFIG__SQ_GS_VERT_ITEMSIZE_1 23 +#define EG_CONFIG__SQ_GS_VERT_ITEMSIZE_2 24 +#define EG_CONFIG__SQ_GS_VERT_ITEMSIZE_3 25 +#define EG_CONFIG__VGT_OUTPUT_PATH_CNTL 26 +#define EG_CONFIG__VGT_HOS_CNTL 27 +#define EG_CONFIG__VGT_HOS_MAX_TESS_LEVEL 28 +#define EG_CONFIG__VGT_HOS_MIN_TESS_LEVEL 29 +#define EG_CONFIG__VGT_HOS_REUSE_DEPTH 30 +#define EG_CONFIG__VGT_GROUP_PRIM_TYPE 31 +#define EG_CONFIG__VGT_GROUP_FIRST_DECR 32 +#define EG_CONFIG__VGT_GROUP_DECR 33 +#define EG_CONFIG__VGT_GROUP_VECT_0_CNTL 34 +#define EG_CONFIG__VGT_GROUP_VECT_1_CNTL 35 +#define EG_CONFIG__VGT_GROUP_VECT_0_FMT_CNTL 36 +#define EG_CONFIG__VGT_GROUP_VECT_1_FMT_CNTL 37 +#define EG_CONFIG__VGT_GS_MODE 38 +#define EG_CONFIG__PA_SC_MODE_CNTL_0 39 +#define EG_CONFIG__PA_SC_MODE_CNTL_1 40 +#define EG_CONFIG__VGT_REUSE_OFF 41 +#define EG_CONFIG__VGT_VTX_CNT_EN 42 +#define EG_CONFIG__VGT_SHADER_STAGES_EN 43 +#define EG_CONFIG__VGT_STRMOUT_CONFIG 44 +#define EG_CONFIG__VGT_STRMOUT_BUFFER_CONFIG 45 +#define EG_CONFIG_SIZE 46 +#define EG_CONFIG_PM4 128 + +/* EG_CB_CNTL */ +#define EG_CB_CNTL__CB_TARGET_MASK 0 +#define EG_CB_CNTL__CB_SHADER_MASK 1 +#define EG_CB_CNTL__CB_COLOR_CONTROL 2 +#define EG_CB_CNTL__PA_SC_AA_CONFIG 3 +#define EG_CB_CNTL__PA_SC_AA_SAMPLE_LOCS_MCTX 4 +#define EG_CB_CNTL__PA_SC_AA_MASK 5 +#define EG_CB_CNTL_SIZE 6 +#define EG_CB_CNTL_PM4 128 + +/* EG_RASTERIZER */ +#define EG_RASTERIZER__SPI_INTERP_CONTROL_0 0 +#define EG_RASTERIZER__PA_CL_CLIP_CNTL 1 +#define EG_RASTERIZER__PA_SU_SC_MODE_CNTL 2 +#define EG_RASTERIZER__PA_CL_VS_OUT_CNTL 3 +#define EG_RASTERIZER__PA_CL_NANINF_CNTL 4 +#define EG_RASTERIZER__PA_SU_POINT_SIZE 5 +#define EG_RASTERIZER__PA_SU_POINT_MINMAX 6 +#define EG_RASTERIZER__PA_SU_LINE_CNTL 7 +#define EG_RASTERIZER__PA_SC_MPASS_PS_CNTL 8 +#define EG_RASTERIZER__PA_SC_LINE_CNTL 9 +#define EG_RASTERIZER__PA_SU_VTX_CNTL 10 +#define EG_RASTERIZER__PA_CL_GB_VERT_CLIP_ADJ 11 +#define EG_RASTERIZER__PA_CL_GB_VERT_DISC_ADJ 12 +#define EG_RASTERIZER__PA_CL_GB_HORZ_CLIP_ADJ 13 +#define EG_RASTERIZER__PA_CL_GB_HORZ_DISC_ADJ 14 +#define EG_RASTERIZER__PA_SU_POLY_OFFSET_DB_FMT_CNTL 15 +#define EG_RASTERIZER__PA_SU_POLY_OFFSET_CLAMP 16 +#define EG_RASTERIZER__PA_SU_POLY_OFFSET_FRONT_SCALE 17 +#define EG_RASTERIZER__PA_SU_POLY_OFFSET_FRONT_OFFSET 18 +#define EG_RASTERIZER__PA_SU_POLY_OFFSET_BACK_SCALE 19 +#define EG_RASTERIZER__PA_SU_POLY_OFFSET_BACK_OFFSET 20 +#define EG_RASTERIZER_SIZE 21 +#define EG_RASTERIZER_PM4 128 + +/* EG_VIEWPORT */ +#define EG_VIEWPORT__PA_SC_VPORT_ZMIN_0 0 +#define EG_VIEWPORT__PA_SC_VPORT_ZMAX_0 1 +#define EG_VIEWPORT__PA_CL_VPORT_XSCALE_0 2 +#define EG_VIEWPORT__PA_CL_VPORT_YSCALE_0 3 +#define EG_VIEWPORT__PA_CL_VPORT_ZSCALE_0 4 +#define EG_VIEWPORT__PA_CL_VPORT_XOFFSET_0 5 +#define EG_VIEWPORT__PA_CL_VPORT_YOFFSET_0 6 +#define EG_VIEWPORT__PA_CL_VPORT_ZOFFSET_0 7 +#define EG_VIEWPORT__PA_CL_VTE_CNTL 8 +#define EG_VIEWPORT_SIZE 9 +#define EG_VIEWPORT_PM4 128 + +/* EG_SCISSOR */ +#define EG_SCISSOR__PA_SC_SCREEN_SCISSOR_TL 0 +#define EG_SCISSOR__PA_SC_SCREEN_SCISSOR_BR 1 +#define EG_SCISSOR__PA_SC_WINDOW_OFFSET 2 +#define EG_SCISSOR__PA_SC_WINDOW_SCISSOR_TL 3 +#define EG_SCISSOR__PA_SC_WINDOW_SCISSOR_BR 4 +#define EG_SCISSOR__PA_SC_CLIPRECT_RULE 5 +#define EG_SCISSOR__PA_SC_CLIPRECT_0_TL 6 +#define EG_SCISSOR__PA_SC_CLIPRECT_0_BR 7 +#define EG_SCISSOR__PA_SC_CLIPRECT_1_TL 8 +#define EG_SCISSOR__PA_SC_CLIPRECT_1_BR 9 +#define EG_SCISSOR__PA_SC_CLIPRECT_2_TL 10 +#define EG_SCISSOR__PA_SC_CLIPRECT_2_BR 11 +#define EG_SCISSOR__PA_SC_CLIPRECT_3_TL 12 +#define EG_SCISSOR__PA_SC_CLIPRECT_3_BR 13 +#define EG_SCISSOR__PA_SC_EDGERULE 14 +#define EG_SCISSOR__PA_SC_GENERIC_SCISSOR_TL 15 +#define EG_SCISSOR__PA_SC_GENERIC_SCISSOR_BR 16 +#define EG_SCISSOR__PA_SC_VPORT_SCISSOR_0_TL 17 +#define EG_SCISSOR__PA_SC_VPORT_SCISSOR_0_BR 18 +#define EG_SCISSOR__PA_SU_HARDWARE_SCREEN_OFFSET 19 +#define EG_SCISSOR_SIZE 20 +#define EG_SCISSOR_PM4 128 + +/* EG_BLEND */ +#define EG_BLEND__CB_BLEND_RED 0 +#define EG_BLEND__CB_BLEND_GREEN 1 +#define EG_BLEND__CB_BLEND_BLUE 2 +#define EG_BLEND__CB_BLEND_ALPHA 3 +#define EG_BLEND__CB_BLEND0_CONTROL 4 +#define EG_BLEND__CB_BLEND1_CONTROL 5 +#define EG_BLEND__CB_BLEND2_CONTROL 6 +#define EG_BLEND__CB_BLEND3_CONTROL 7 +#define EG_BLEND__CB_BLEND4_CONTROL 8 +#define EG_BLEND__CB_BLEND5_CONTROL 9 +#define EG_BLEND__CB_BLEND6_CONTROL 10 +#define EG_BLEND__CB_BLEND7_CONTROL 11 +#define EG_BLEND_SIZE 12 +#define EG_BLEND_PM4 128 + +/* EG_DSA */ +#define EG_DSA__DB_STENCIL_CLEAR 0 +#define EG_DSA__DB_DEPTH_CLEAR 1 +#define EG_DSA__SX_ALPHA_TEST_CONTROL 2 +#define EG_DSA__DB_STENCILREFMASK 3 +#define EG_DSA__DB_STENCILREFMASK_BF 4 +#define EG_DSA__SX_ALPHA_REF 5 +#define EG_DSA__SPI_FOG_CNTL 6 +#define EG_DSA__DB_DEPTH_CONTROL 7 +#define EG_DSA__DB_SHADER_CONTROL 8 +#define EG_DSA__DB_RENDER_CONTROL 9 +#define EG_DSA__DB_COUNT_CONTROL 10 +#define EG_DSA__DB_RENDER_OVERRIDE 11 +#define EG_DSA__DB_RENDER_OVERRIDE2 12 +#define EG_DSA__DB_SRESULTS_COMPARE_STATE0 13 +#define EG_DSA__DB_SRESULTS_COMPARE_STATE1 14 +#define EG_DSA__DB_PRELOAD_CONTROL 15 +#define EG_DSA__DB_ALPHA_TO_MASK 16 +#define EG_DSA_SIZE 17 +#define EG_DSA_PM4 128 + +/* EG_VS_SHADER */ +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_0 0 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_1 1 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_2 2 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_3 3 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_4 4 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_5 5 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_6 6 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_7 7 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_8 8 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_9 9 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_10 10 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_11 11 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_12 12 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_13 13 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_14 14 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_15 15 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_16 16 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_17 17 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_18 18 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_19 19 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_20 20 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_21 21 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_22 22 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_23 23 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_24 24 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_25 25 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_26 26 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_27 27 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_28 28 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_29 29 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_30 30 +#define EG_VS_SHADER__SQ_VTX_SEMANTIC_31 31 +#define EG_VS_SHADER__SPI_VS_OUT_ID_0 32 +#define EG_VS_SHADER__SPI_VS_OUT_ID_1 33 +#define EG_VS_SHADER__SPI_VS_OUT_ID_2 34 +#define EG_VS_SHADER__SPI_VS_OUT_ID_3 35 +#define EG_VS_SHADER__SPI_VS_OUT_ID_4 36 +#define EG_VS_SHADER__SPI_VS_OUT_ID_5 37 +#define EG_VS_SHADER__SPI_VS_OUT_ID_6 38 +#define EG_VS_SHADER__SPI_VS_OUT_ID_7 39 +#define EG_VS_SHADER__SPI_VS_OUT_ID_8 40 +#define EG_VS_SHADER__SPI_VS_OUT_ID_9 41 +#define EG_VS_SHADER__SPI_VS_OUT_CONFIG 42 +#define EG_VS_SHADER__SQ_PGM_START_VS 43 +#define EG_VS_SHADER__SQ_PGM_RESOURCES_VS 44 +#define EG_VS_SHADER__SQ_PGM_RESOURCES_2_VS 45 +#define EG_VS_SHADER__SQ_PGM_START_FS 46 +#define EG_VS_SHADER__SQ_PGM_RESOURCES_FS 47 +#define EG_VS_SHADER_SIZE 48 +#define EG_VS_SHADER_PM4 128 + +/* EG_PS_SHADER */ +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_0 0 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_1 1 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_2 2 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_3 3 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_4 4 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_5 5 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_6 6 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_7 7 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_8 8 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_9 9 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_10 10 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_11 11 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_12 12 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_13 13 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_14 14 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_15 15 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_16 16 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_17 17 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_18 18 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_19 19 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_20 20 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_21 21 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_22 22 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_23 23 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_24 24 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_25 25 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_26 26 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_27 27 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_28 28 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_29 29 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_30 30 +#define EG_PS_SHADER__SPI_PS_INPUT_CNTL_31 31 +#define EG_PS_SHADER__SPI_THREAD_GROUPING 32 +#define EG_PS_SHADER__SPI_PS_IN_CONTROL_0 33 +#define EG_PS_SHADER__SPI_PS_IN_CONTROL_1 34 +#define EG_PS_SHADER__SPI_INPUT_Z 35 +#define EG_PS_SHADER__SPI_BARYC_CNTL 36 +#define EG_PS_SHADER__SPI_PS_IN_CONTROL_2 37 +#define EG_PS_SHADER__SPI_COMPUTE_INPUT_CNTL 38 +#define EG_PS_SHADER__SQ_PGM_START_PS 39 +#define EG_PS_SHADER__SQ_PGM_RESOURCES_PS 40 +#define EG_PS_SHADER__SQ_PGM_RESOURCES_2_PS 41 +#define EG_PS_SHADER__SQ_PGM_EXPORTS_PS 42 +#define EG_PS_SHADER_SIZE 43 +#define EG_PS_SHADER_PM4 128 + +/* EG_UCP */ +#define EG_UCP__PA_CL_UCP0_X 0 +#define EG_UCP__PA_CL_UCP0_Y 1 +#define EG_UCP__PA_CL_UCP0_Z 2 +#define EG_UCP__PA_CL_UCP0_W 3 +#define EG_UCP__PA_CL_UCP1_X 4 +#define EG_UCP__PA_CL_UCP1_Y 5 +#define EG_UCP__PA_CL_UCP1_Z 6 +#define EG_UCP__PA_CL_UCP1_W 7 +#define EG_UCP__PA_CL_UCP2_X 8 +#define EG_UCP__PA_CL_UCP2_Y 9 +#define EG_UCP__PA_CL_UCP2_Z 10 +#define EG_UCP__PA_CL_UCP2_W 11 +#define EG_UCP__PA_CL_UCP3_X 12 +#define EG_UCP__PA_CL_UCP3_Y 13 +#define EG_UCP__PA_CL_UCP3_Z 14 +#define EG_UCP__PA_CL_UCP3_W 15 +#define EG_UCP__PA_CL_UCP4_X 16 +#define EG_UCP__PA_CL_UCP4_Y 17 +#define EG_UCP__PA_CL_UCP4_Z 18 +#define EG_UCP__PA_CL_UCP4_W 19 +#define EG_UCP__PA_CL_UCP5_X 20 +#define EG_UCP__PA_CL_UCP5_Y 21 +#define EG_UCP__PA_CL_UCP5_Z 22 +#define EG_UCP__PA_CL_UCP5_W 23 +#define EG_UCP_SIZE 24 +#define EG_UCP_PM4 128 + +/* EG_VS_CBUF */ +#define EG_VS_CBUF__ALU_CONST_BUFFER_SIZE_VS_0 0 +#define EG_VS_CBUF__ALU_CONST_CACHE_VS_0 1 +#define EG_VS_CBUF_SIZE 2 +#define EG_VS_CBUF_PM4 128 + +/* EG_PS_CBUF */ +#define EG_PS_CBUF__ALU_CONST_BUFFER_SIZE_PS_0 0 +#define EG_PS_CBUF__ALU_CONST_CACHE_PS_0 1 +#define EG_PS_CBUF_SIZE 2 +#define EG_PS_CBUF_PM4 128 + +/* EG_PS_RESOURCE */ +#define EG_PS_RESOURCE__RESOURCE0_WORD0 0 +#define EG_PS_RESOURCE__RESOURCE0_WORD1 1 +#define EG_PS_RESOURCE__RESOURCE0_WORD2 2 +#define EG_PS_RESOURCE__RESOURCE0_WORD3 3 +#define EG_PS_RESOURCE__RESOURCE0_WORD4 4 +#define EG_PS_RESOURCE__RESOURCE0_WORD5 5 +#define EG_PS_RESOURCE__RESOURCE0_WORD6 6 +#define EG_PS_RESOURCE__RESOURCE0_WORD7 7 +#define EG_PS_RESOURCE_SIZE 8 +#define EG_PS_RESOURCE_PM4 128 + +/* EG_VS_RESOURCE */ +#define EG_VS_RESOURCE__RESOURCE160_WORD0 0 +#define EG_VS_RESOURCE__RESOURCE160_WORD1 1 +#define EG_VS_RESOURCE__RESOURCE160_WORD2 2 +#define EG_VS_RESOURCE__RESOURCE160_WORD3 3 +#define EG_VS_RESOURCE__RESOURCE160_WORD4 4 +#define EG_VS_RESOURCE__RESOURCE160_WORD5 5 +#define EG_VS_RESOURCE__RESOURCE160_WORD6 6 +#define EG_VS_RESOURCE__RESOURCE160_WORD7 7 +#define EG_VS_RESOURCE_SIZE 8 +#define EG_VS_RESOURCE_PM4 128 + +/* EG_FS_RESOURCE */ +#define EG_FS_RESOURCE__RESOURCE320_WORD0 0 +#define EG_FS_RESOURCE__RESOURCE320_WORD1 1 +#define EG_FS_RESOURCE__RESOURCE320_WORD2 2 +#define EG_FS_RESOURCE__RESOURCE320_WORD3 3 +#define EG_FS_RESOURCE__RESOURCE320_WORD4 4 +#define EG_FS_RESOURCE__RESOURCE320_WORD5 5 +#define EG_FS_RESOURCE__RESOURCE320_WORD6 6 +#define EG_FS_RESOURCE__RESOURCE320_WORD7 7 +#define EG_FS_RESOURCE_SIZE 8 +#define EG_FS_RESOURCE_PM4 128 + +/* EG_GS_RESOURCE */ +#define EG_GS_RESOURCE__RESOURCE336_WORD0 0 +#define EG_GS_RESOURCE__RESOURCE336_WORD1 1 +#define EG_GS_RESOURCE__RESOURCE336_WORD2 2 +#define EG_GS_RESOURCE__RESOURCE336_WORD3 3 +#define EG_GS_RESOURCE__RESOURCE336_WORD4 4 +#define EG_GS_RESOURCE__RESOURCE336_WORD5 5 +#define EG_GS_RESOURCE__RESOURCE336_WORD6 6 +#define EG_GS_RESOURCE__RESOURCE336_WORD7 7 +#define EG_GS_RESOURCE_SIZE 8 +#define EG_GS_RESOURCE_PM4 128 + +/* EG_PS_SAMPLER */ +#define EG_PS_SAMPLER__SQ_TEX_SAMPLER_WORD0_0 0 +#define EG_PS_SAMPLER__SQ_TEX_SAMPLER_WORD1_0 1 +#define EG_PS_SAMPLER__SQ_TEX_SAMPLER_WORD2_0 2 +#define EG_PS_SAMPLER_SIZE 3 +#define EG_PS_SAMPLER_PM4 128 + +/* EG_VS_SAMPLER */ +#define EG_VS_SAMPLER__SQ_TEX_SAMPLER_WORD0_18 0 +#define EG_VS_SAMPLER__SQ_TEX_SAMPLER_WORD1_18 1 +#define EG_VS_SAMPLER__SQ_TEX_SAMPLER_WORD2_18 2 +#define EG_VS_SAMPLER_SIZE 3 +#define EG_VS_SAMPLER_PM4 128 + +/* EG_GS_SAMPLER */ +#define EG_GS_SAMPLER__SQ_TEX_SAMPLER_WORD0_36 0 +#define EG_GS_SAMPLER__SQ_TEX_SAMPLER_WORD1_36 1 +#define EG_GS_SAMPLER__SQ_TEX_SAMPLER_WORD2_36 2 +#define EG_GS_SAMPLER_SIZE 3 +#define EG_GS_SAMPLER_PM4 128 + +/* EG_PS_SAMPLER_BORDER */ +#define EG_PS_SAMPLER_BORDER__TD_PS_SAMPLER0_BORDER_INDEX 0 +#define EG_PS_SAMPLER_BORDER__TD_PS_SAMPLER0_BORDER_RED 1 +#define EG_PS_SAMPLER_BORDER__TD_PS_SAMPLER0_BORDER_GREEN 2 +#define EG_PS_SAMPLER_BORDER__TD_PS_SAMPLER0_BORDER_BLUE 3 +#define EG_PS_SAMPLER_BORDER__TD_PS_SAMPLER0_BORDER_ALPHA 4 +#define EG_PS_SAMPLER_BORDER_SIZE 5 +#define EG_PS_SAMPLER_BORDER_PM4 128 + +/* EG_VS_SAMPLER_BORDER */ +#define EG_VS_SAMPLER_BORDER__TD_VS_SAMPLER0_BORDER_INDEX 0 +#define EG_VS_SAMPLER_BORDER__TD_VS_SAMPLER0_BORDER_RED 1 +#define EG_VS_SAMPLER_BORDER__TD_VS_SAMPLER0_BORDER_GREEN 2 +#define EG_VS_SAMPLER_BORDER__TD_VS_SAMPLER0_BORDER_BLUE 3 +#define EG_VS_SAMPLER_BORDER__TD_VS_SAMPLER0_BORDER_ALPHA 4 +#define EG_VS_SAMPLER_BORDER_SIZE 5 +#define EG_VS_SAMPLER_BORDER_PM4 128 + +/* EG_GS_SAMPLER_BORDER */ +#define EG_GS_SAMPLER_BORDER__TD_GS_SAMPLER0_BORDER_INDEX 0 +#define EG_GS_SAMPLER_BORDER__TD_GS_SAMPLER0_BORDER_RED 1 +#define EG_GS_SAMPLER_BORDER__TD_GS_SAMPLER0_BORDER_GREEN 2 +#define EG_GS_SAMPLER_BORDER__TD_GS_SAMPLER0_BORDER_BLUE 3 +#define EG_GS_SAMPLER_BORDER__TD_GS_SAMPLER0_BORDER_ALPHA 4 +#define EG_GS_SAMPLER_BORDER_SIZE 5 +#define EG_GS_SAMPLER_BORDER_PM4 128 + +/* EG_CB */ +#define EG_CB__CB_COLOR0_BASE 0 +#define EG_CB__CB_COLOR0_PITCH 1 +#define EG_CB__CB_COLOR0_SLICE 2 +#define EG_CB__CB_COLOR0_VIEW 3 +#define EG_CB__CB_COLOR0_INFO 4 +#define EG_CB__CB_COLOR0_ATTRIB 5 +#define EG_CB__CB_COLOR0_DIM 6 +#define EG_CB_SIZE 7 +#define EG_CB_PM4 128 + +/* EG_DB */ +#define EG_DB__DB_HTILE_DATA_BASE 0 +#define EG_DB__DB_Z_INFO 1 +#define EG_DB__DB_STENCIL_INFO 2 +#define EG_DB__DB_DEPTH_SIZE 3 +#define EG_DB__DB_DEPTH_SLICE 4 +#define EG_DB__DB_DEPTH_VIEW 5 +#define EG_DB__DB_HTILE_SURFACE 6 +#define EG_DB__DB_Z_READ_BASE 7 +#define EG_DB__DB_STENCIL_READ_BASE 8 +#define EG_DB__DB_Z_WRITE_BASE 9 +#define EG_DB__DB_STENCIL_WRITE_BASE 10 +#define EG_DB_SIZE 11 +#define EG_DB_PM4 128 + +/* EG_VGT */ +#define EG_VGT__VGT_PRIMITIVE_TYPE 0 +#define EG_VGT__VGT_MAX_VTX_INDX 1 +#define EG_VGT__VGT_MIN_VTX_INDX 2 +#define EG_VGT__VGT_INDX_OFFSET 3 +#define EG_VGT__VGT_DMA_INDEX_TYPE 4 +#define EG_VGT__VGT_PRIMITIVEID_EN 5 +#define EG_VGT__VGT_DMA_NUM_INSTANCES 6 +#define EG_VGT__VGT_MULTI_PRIM_IB_RESET_EN 7 +#define EG_VGT__VGT_INSTANCE_STEP_RATE_0 8 +#define EG_VGT__VGT_INSTANCE_STEP_RATE_1 9 +#define EG_VGT_SIZE 10 +#define EG_VGT_PM4 128 + +/* EG_DRAW */ +#define EG_DRAW__VGT_NUM_INDICES 0 +#define EG_DRAW__VGT_DMA_BASE_HI 1 +#define EG_DRAW__VGT_DMA_BASE 2 +#define EG_DRAW__VGT_DRAW_INITIATOR 3 +#define EG_DRAW_SIZE 4 +#define EG_DRAW_PM4 128 + +/* EG_VGT_EVENT */ +#define EG_VGT_EVENT__VGT_EVENT_INITIATOR 0 +#define EG_VGT_EVENT_SIZE 1 +#define EG_VGT_EVENT_PM4 128 + +/* EG_CB_FLUSH */ +#define EG_CB_FLUSH_SIZE 0 +#define EG_CB_FLUSH_PM4 128 + +/* EG_DB_FLUSH */ +#define EG_DB_FLUSH_SIZE 0 +#define EG_DB_FLUSH_PM4 128 + diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c new file mode 100644 index 0000000..4d5ba9e --- /dev/null +++ b/src/gallium/drivers/r600/evergreen_state.c @@ -0,0 +1,1734 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + */ + +/* TODO: + * - fix mask for depth control & cull for query + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "r600.h" +#include "evergreend.h" +#include "r600_resource.h" +#include "r600_shader.h" +#include "r600_pipe.h" +#include "eg_state_inlines.h" + +static void evergreen_set_blend_color(struct pipe_context *ctx, + const struct pipe_blend_color *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + + if (rstate == NULL) + return; + + rstate->id = R600_PIPE_STATE_BLEND_COLOR; + r600_pipe_state_add_reg(rstate, R_028414_CB_BLEND_RED, fui(state->color[0]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028418_CB_BLEND_GREEN, fui(state->color[1]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02841C_CB_BLEND_BLUE, fui(state->color[2]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028420_CB_BLEND_ALPHA, fui(state->color[3]), 0xFFFFFFFF, NULL); + + free(rctx->states[R600_PIPE_STATE_BLEND_COLOR]); + rctx->states[R600_PIPE_STATE_BLEND_COLOR] = rstate; + r600_context_pipe_state_set(&rctx->ctx, rstate); +} + +static void *evergreen_create_blend_state(struct pipe_context *ctx, + const struct pipe_blend_state *state) +{ + struct r600_pipe_blend *blend = CALLOC_STRUCT(r600_pipe_blend); + struct r600_pipe_state *rstate; + u32 color_control, target_mask; + /* FIXME there is more then 8 framebuffer */ + unsigned blend_cntl[8]; + + if (blend == NULL) { + return NULL; + } + rstate = &blend->rstate; + + rstate->id = R600_PIPE_STATE_BLEND; + + target_mask = 0; + color_control = S_028808_MODE(1); + if (state->logicop_enable) { + color_control |= (state->logicop_func << 16) | (state->logicop_func << 20); + } else { + color_control |= (0xcc << 16); + } + /* we pretend 8 buffer are used, CB_SHADER_MASK will disable unused one */ + if (state->independent_blend_enable) { + for (int i = 0; i < 8; i++) { + target_mask |= (state->rt[i].colormask << (4 * i)); + } + } else { + for (int i = 0; i < 8; i++) { + target_mask |= (state->rt[0].colormask << (4 * i)); + } + } + blend->cb_target_mask = target_mask; + r600_pipe_state_add_reg(rstate, R_028808_CB_COLOR_CONTROL, + color_control, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C3C_PA_SC_AA_MASK, 0xFFFFFFFF, 0xFFFFFFFF, NULL); + + for (int i = 0; i < 8; i++) { + unsigned eqRGB = state->rt[i].rgb_func; + unsigned srcRGB = state->rt[i].rgb_src_factor; + unsigned dstRGB = state->rt[i].rgb_dst_factor; + unsigned eqA = state->rt[i].alpha_func; + unsigned srcA = state->rt[i].alpha_src_factor; + unsigned dstA = state->rt[i].alpha_dst_factor; + + blend_cntl[i] = 0; + if (!state->rt[i].blend_enable) + continue; + + blend_cntl[i] |= S_028780_BLEND_CONTROL_ENABLE(1); + blend_cntl[i] |= S_028780_COLOR_COMB_FCN(r600_translate_blend_function(eqRGB)); + blend_cntl[i] |= S_028780_COLOR_SRCBLEND(r600_translate_blend_factor(srcRGB)); + blend_cntl[i] |= S_028780_COLOR_DESTBLEND(r600_translate_blend_factor(dstRGB)); + + if (srcA != srcRGB || dstA != dstRGB || eqA != eqRGB) { + blend_cntl[i] |= S_028780_SEPARATE_ALPHA_BLEND(1); + blend_cntl[i] |= S_028780_ALPHA_COMB_FCN(r600_translate_blend_function(eqA)); + blend_cntl[i] |= S_028780_ALPHA_SRCBLEND(r600_translate_blend_factor(srcA)); + blend_cntl[i] |= S_028780_ALPHA_DESTBLEND(r600_translate_blend_factor(dstA)); + } + } + for (int i = 0; i < 8; i++) { + r600_pipe_state_add_reg(rstate, R_028780_CB_BLEND0_CONTROL + i * 4, blend_cntl[i], 0xFFFFFFFF, NULL); + } + + return rstate; +} + +static void *evergreen_create_dsa_state(struct pipe_context *ctx, + const struct pipe_depth_stencil_alpha_state *state) +{ + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + unsigned db_depth_control, alpha_test_control, alpha_ref, db_shader_control; + unsigned stencil_ref_mask, stencil_ref_mask_bf, db_render_override, db_render_control; + + if (rstate == NULL) { + return NULL; + } + + rstate->id = R600_PIPE_STATE_DSA; + /* depth TODO some of those db_shader_control field depend on shader adjust mask & add it to shader */ + /* db_shader_control is 0xFFFFFFBE as Z_EXPORT_ENABLE (bit 0) will be + * set by fragment shader if it export Z and KILL_ENABLE (bit 6) will + * be set if shader use texkill instruction + */ + db_shader_control = S_02880C_Z_ORDER(V_02880C_EARLY_Z_THEN_LATE_Z); + stencil_ref_mask = 0; + stencil_ref_mask_bf = 0; + db_depth_control = S_028800_Z_ENABLE(state->depth.enabled) | + S_028800_Z_WRITE_ENABLE(state->depth.writemask) | + S_028800_ZFUNC(state->depth.func); + + /* stencil */ + if (state->stencil[0].enabled) { + db_depth_control |= S_028800_STENCIL_ENABLE(1); + db_depth_control |= S_028800_STENCILFUNC(r600_translate_ds_func(state->stencil[0].func)); + db_depth_control |= S_028800_STENCILFAIL(r600_translate_stencil_op(state->stencil[0].fail_op)); + db_depth_control |= S_028800_STENCILZPASS(r600_translate_stencil_op(state->stencil[0].zpass_op)); + db_depth_control |= S_028800_STENCILZFAIL(r600_translate_stencil_op(state->stencil[0].zfail_op)); + + + stencil_ref_mask = S_028430_STENCILMASK(state->stencil[0].valuemask) | + S_028430_STENCILWRITEMASK(state->stencil[0].writemask); + if (state->stencil[1].enabled) { + db_depth_control |= S_028800_BACKFACE_ENABLE(1); + db_depth_control |= S_028800_STENCILFUNC_BF(r600_translate_ds_func(state->stencil[1].func)); + db_depth_control |= S_028800_STENCILFAIL_BF(r600_translate_stencil_op(state->stencil[1].fail_op)); + db_depth_control |= S_028800_STENCILZPASS_BF(r600_translate_stencil_op(state->stencil[1].zpass_op)); + db_depth_control |= S_028800_STENCILZFAIL_BF(r600_translate_stencil_op(state->stencil[1].zfail_op)); + stencil_ref_mask_bf = S_028434_STENCILMASK_BF(state->stencil[1].valuemask) | + S_028434_STENCILWRITEMASK_BF(state->stencil[1].writemask); + } + } + + /* alpha */ + alpha_test_control = 0; + alpha_ref = 0; + if (state->alpha.enabled) { + alpha_test_control = S_028410_ALPHA_FUNC(state->alpha.func); + alpha_test_control |= S_028410_ALPHA_TEST_ENABLE(1); + alpha_ref = fui(state->alpha.ref_value); + } + + /* misc */ + db_render_control = 0; + db_render_override = S_02800C_FORCE_HIZ_ENABLE(V_02800C_FORCE_DISABLE) | + S_02800C_FORCE_HIS_ENABLE0(V_02800C_FORCE_DISABLE) | + S_02800C_FORCE_HIS_ENABLE1(V_02800C_FORCE_DISABLE); + /* TODO db_render_override depends on query */ + r600_pipe_state_add_reg(rstate, R_028028_DB_STENCIL_CLEAR, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02802C_DB_DEPTH_CLEAR, 0x3F800000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028410_SX_ALPHA_TEST_CONTROL, alpha_test_control, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028430_DB_STENCILREFMASK, stencil_ref_mask, + 0xFFFFFFFF & C_028430_STENCILREF, NULL); + r600_pipe_state_add_reg(rstate, + R_028434_DB_STENCILREFMASK_BF, stencil_ref_mask_bf, + 0xFFFFFFFF & C_028434_STENCILREF_BF, NULL); + r600_pipe_state_add_reg(rstate, R_028438_SX_ALPHA_REF, alpha_ref, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0286DC_SPI_FOG_CNTL, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028800_DB_DEPTH_CONTROL, db_depth_control, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02880C_DB_SHADER_CONTROL, db_shader_control, 0xFFFFFFBE, NULL); + r600_pipe_state_add_reg(rstate, R_028000_DB_RENDER_CONTROL, db_render_control, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02800C_DB_RENDER_OVERRIDE, db_render_override, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028AC0_DB_SRESULTS_COMPARE_STATE0, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028AC4_DB_SRESULTS_COMPARE_STATE1, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028AC8_DB_PRELOAD_CONTROL, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028B70_DB_ALPHA_TO_MASK, 0x0000AA00, 0xFFFFFFFF, NULL); + + return rstate; +} + +static void *evergreen_create_rs_state(struct pipe_context *ctx, + const struct pipe_rasterizer_state *state) +{ + struct r600_pipe_rasterizer *rs = CALLOC_STRUCT(r600_pipe_rasterizer); + struct r600_pipe_state *rstate; + unsigned tmp; + unsigned prov_vtx = 1, polygon_dual_mode; + unsigned clip_rule; + + if (rs == NULL) { + return NULL; + } + + rstate = &rs->rstate; + rs->flatshade = state->flatshade; + rs->sprite_coord_enable = state->sprite_coord_enable; + + clip_rule = state->scissor ? 0xAAAA : 0xFFFF; + + /* offset */ + rs->offset_units = state->offset_units; + rs->offset_scale = state->offset_scale * 12.0f; + + rstate->id = R600_PIPE_STATE_RASTERIZER; + if (state->flatshade_first) + prov_vtx = 0; + tmp = S_0286D4_FLAT_SHADE_ENA(1); + if (state->sprite_coord_enable) { + tmp |= S_0286D4_PNT_SPRITE_ENA(1) | + S_0286D4_PNT_SPRITE_OVRD_X(2) | + S_0286D4_PNT_SPRITE_OVRD_Y(3) | + S_0286D4_PNT_SPRITE_OVRD_Z(0) | + S_0286D4_PNT_SPRITE_OVRD_W(1); + if (state->sprite_coord_mode != PIPE_SPRITE_COORD_UPPER_LEFT) { + tmp |= S_0286D4_PNT_SPRITE_TOP_1(1); + } + } + r600_pipe_state_add_reg(rstate, R_0286D4_SPI_INTERP_CONTROL_0, tmp, 0xFFFFFFFF, NULL); + + polygon_dual_mode = (state->fill_front != PIPE_POLYGON_MODE_FILL || + state->fill_back != PIPE_POLYGON_MODE_FILL); + r600_pipe_state_add_reg(rstate, R_028814_PA_SU_SC_MODE_CNTL, + S_028814_PROVOKING_VTX_LAST(prov_vtx) | + S_028814_CULL_FRONT((state->cull_face & PIPE_FACE_FRONT) ? 1 : 0) | + S_028814_CULL_BACK((state->cull_face & PIPE_FACE_BACK) ? 1 : 0) | + S_028814_FACE(!state->front_ccw) | + S_028814_POLY_OFFSET_FRONT_ENABLE(state->offset_tri) | + S_028814_POLY_OFFSET_BACK_ENABLE(state->offset_tri) | + S_028814_POLY_OFFSET_PARA_ENABLE(state->offset_tri) | + S_028814_POLY_MODE(polygon_dual_mode) | + S_028814_POLYMODE_FRONT_PTYPE(r600_translate_fill(state->fill_front)) | + S_028814_POLYMODE_BACK_PTYPE(r600_translate_fill(state->fill_back)), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02881C_PA_CL_VS_OUT_CNTL, + S_02881C_USE_VTX_POINT_SIZE(state->point_size_per_vertex) | + S_02881C_VS_OUT_MISC_VEC_ENA(state->point_size_per_vertex), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028820_PA_CL_NANINF_CNTL, 0x00000000, 0xFFFFFFFF, NULL); + /* point size 12.4 fixed point */ + tmp = (unsigned)(state->point_size * 8.0); + r600_pipe_state_add_reg(rstate, R_028A00_PA_SU_POINT_SIZE, S_028A00_HEIGHT(tmp) | S_028A00_WIDTH(tmp), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A04_PA_SU_POINT_MINMAX, 0x80000000, 0xFFFFFFFF, NULL); + + tmp = (unsigned)state->line_width * 8; + r600_pipe_state_add_reg(rstate, R_028A08_PA_SU_LINE_CNTL, S_028A08_WIDTH(tmp), 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_028C00_PA_SC_LINE_CNTL, 0x00000400, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C0C_PA_CL_GB_VERT_CLIP_ADJ, 0x3F800000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C10_PA_CL_GB_VERT_DISC_ADJ, 0x3F800000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C14_PA_CL_GB_HORZ_CLIP_ADJ, 0x3F800000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C18_PA_CL_GB_HORZ_DISC_ADJ, 0x3F800000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028B7C_PA_SU_POLY_OFFSET_CLAMP, 0x0, 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_028C08_PA_SU_VTX_CNTL, + S_028C08_PIX_CENTER_HALF(state->gl_rasterization_rules), + 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_02820C_PA_SC_CLIPRECT_RULE, clip_rule, 0xFFFFFFFF, NULL); + return rstate; +} + +static void *evergreen_create_sampler_state(struct pipe_context *ctx, + const struct pipe_sampler_state *state) +{ + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + union util_color uc; + + if (rstate == NULL) { + return NULL; + } + + rstate->id = R600_PIPE_STATE_SAMPLER; + util_pack_color(state->border_color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); + r600_pipe_state_add_reg(rstate, R_03C000_SQ_TEX_SAMPLER_WORD0_0, + S_03C000_CLAMP_X(r600_tex_wrap(state->wrap_s)) | + S_03C000_CLAMP_Y(r600_tex_wrap(state->wrap_t)) | + S_03C000_CLAMP_Z(r600_tex_wrap(state->wrap_r)) | + S_03C000_XY_MAG_FILTER(r600_tex_filter(state->mag_img_filter)) | + S_03C000_XY_MIN_FILTER(r600_tex_filter(state->min_img_filter)) | + S_03C000_MIP_FILTER(r600_tex_mipfilter(state->min_mip_filter)) | + S_03C000_DEPTH_COMPARE_FUNCTION(r600_tex_compare(state->compare_func)) | + S_03C000_BORDER_COLOR_TYPE(uc.ui ? V_03C000_SQ_TEX_BORDER_COLOR_REGISTER : 0), 0xFFFFFFFF, NULL); + /* FIXME LOD it depends on texture base level ... */ + r600_pipe_state_add_reg(rstate, R_03C004_SQ_TEX_SAMPLER_WORD1_0, + S_03C004_MIN_LOD(S_FIXED(CLAMP(state->min_lod, 0, 15), 8)) | + S_03C004_MAX_LOD(S_FIXED(CLAMP(state->max_lod, 0, 15), 8)), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_03C008_SQ_TEX_SAMPLER_WORD2_0, + S_03C008_LOD_BIAS(S_FIXED(CLAMP(state->lod_bias, -16, 16), 8)) | + S_03C008_TYPE(1), + 0xFFFFFFFF, NULL); + + if (uc.ui) { + r600_pipe_state_add_reg(rstate, R_00A404_TD_PS_SAMPLER0_BORDER_RED, fui(state->border_color[0]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_00A408_TD_PS_SAMPLER0_BORDER_GREEN, fui(state->border_color[1]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_00A40C_TD_PS_SAMPLER0_BORDER_BLUE, fui(state->border_color[2]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_00A410_TD_PS_SAMPLER0_BORDER_ALPHA, fui(state->border_color[3]), 0xFFFFFFFF, NULL); + } + return rstate; +} + +static struct pipe_sampler_view *evergreen_create_sampler_view(struct pipe_context *ctx, + struct pipe_resource *texture, + const struct pipe_sampler_view *state) +{ + struct r600_pipe_sampler_view *resource = CALLOC_STRUCT(r600_pipe_sampler_view); + struct r600_pipe_state *rstate; + const struct util_format_description *desc; + struct r600_resource_texture *tmp; + struct r600_resource *rbuffer; + unsigned format; + uint32_t word4 = 0, yuv_format = 0, pitch = 0; + unsigned char swizzle[4]; + struct r600_bo *bo[2]; + + if (resource == NULL) + return NULL; + rstate = &resource->state; + + /* initialize base object */ + resource->base = *state; + resource->base.texture = NULL; + pipe_reference(NULL, &texture->reference); + resource->base.texture = texture; + resource->base.reference.count = 1; + resource->base.context = ctx; + + swizzle[0] = state->swizzle_r; + swizzle[1] = state->swizzle_g; + swizzle[2] = state->swizzle_b; + swizzle[3] = state->swizzle_a; + format = r600_translate_texformat(state->format, + swizzle, + &word4, &yuv_format); + if (format == ~0) { + format = 0; + } + desc = util_format_description(state->format); + if (desc == NULL) { + R600_ERR("unknow format %d\n", state->format); + } + tmp = (struct r600_resource_texture*)texture; + rbuffer = &tmp->resource; + bo[0] = rbuffer->bo; + bo[1] = rbuffer->bo; + /* FIXME depth texture decompression */ + if (tmp->depth) { + r600_texture_depth_flush(ctx, texture); + tmp = (struct r600_resource_texture*)texture; + rbuffer = &tmp->flushed_depth_texture->resource; + bo[0] = rbuffer->bo; + bo[1] = rbuffer->bo; + } + pitch = align(tmp->pitch_in_pixels[0], 8); + + /* FIXME properly handle first level != 0 */ + r600_pipe_state_add_reg(rstate, R_030000_RESOURCE0_WORD0, + S_030000_DIM(r600_tex_dim(texture->target)) | + S_030000_PITCH((pitch / 8) - 1) | + S_030000_TEX_WIDTH(texture->width0 - 1), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_030004_RESOURCE0_WORD1, + S_030004_TEX_HEIGHT(texture->height0 - 1) | + S_030004_TEX_DEPTH(texture->depth0 - 1), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_030008_RESOURCE0_WORD2, + (tmp->offset[0] + r600_bo_offset(bo[0])) >> 8, 0xFFFFFFFF, bo[0]); + r600_pipe_state_add_reg(rstate, R_03000C_RESOURCE0_WORD3, + (tmp->offset[1] + r600_bo_offset(bo[1])) >> 8, 0xFFFFFFFF, bo[1]); + r600_pipe_state_add_reg(rstate, R_030010_RESOURCE0_WORD4, + word4 | S_030010_NUM_FORMAT_ALL(V_030010_SQ_NUM_FORMAT_NORM) | + S_030010_SRF_MODE_ALL(V_030010_SFR_MODE_NO_ZERO) | + S_030010_BASE_LEVEL(state->u.tex.first_level), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_030014_RESOURCE0_WORD5, + S_030014_LAST_LEVEL(state->u.tex.last_level) | + S_030014_BASE_ARRAY(0) | + S_030014_LAST_ARRAY(0), 0xffffffff, NULL); + r600_pipe_state_add_reg(rstate, R_030018_RESOURCE0_WORD6, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_03001C_RESOURCE0_WORD7, + S_03001C_DATA_FORMAT(format) | + S_03001C_TYPE(V_03001C_SQ_TEX_VTX_VALID_TEXTURE), 0xFFFFFFFF, NULL); + + return &resource->base; +} + +static void evergreen_set_vs_sampler_view(struct pipe_context *ctx, unsigned count, + struct pipe_sampler_view **views) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_sampler_view **resource = (struct r600_pipe_sampler_view **)views; + + for (int i = 0; i < count; i++) { + if (resource[i]) { + evergreen_context_pipe_state_set_vs_resource(&rctx->ctx, &resource[i]->state, i); + } + } +} + +static void evergreen_set_ps_sampler_view(struct pipe_context *ctx, unsigned count, + struct pipe_sampler_view **views) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_sampler_view **resource = (struct r600_pipe_sampler_view **)views; + int i; + + for (i = 0; i < count; i++) { + if (&rctx->ps_samplers.views[i]->base != views[i]) { + if (resource[i]) + evergreen_context_pipe_state_set_ps_resource(&rctx->ctx, &resource[i]->state, i); + else + evergreen_context_pipe_state_set_ps_resource(&rctx->ctx, NULL, i); + + pipe_sampler_view_reference( + (struct pipe_sampler_view **)&rctx->ps_samplers.views[i], + views[i]); + } + } + for (i = count; i < NUM_TEX_UNITS; i++) { + if (rctx->ps_samplers.views[i]) { + evergreen_context_pipe_state_set_ps_resource(&rctx->ctx, NULL, i); + pipe_sampler_view_reference((struct pipe_sampler_view **)&rctx->ps_samplers.views[i], NULL); + } + } + rctx->ps_samplers.n_views = count; +} + +static void evergreen_bind_ps_sampler(struct pipe_context *ctx, unsigned count, void **states) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state **rstates = (struct r600_pipe_state **)states; + + + memcpy(rctx->ps_samplers.samplers, states, sizeof(void*) * count); + rctx->ps_samplers.n_samplers = count; + + for (int i = 0; i < count; i++) { + evergreen_context_pipe_state_set_ps_sampler(&rctx->ctx, rstates[i], i); + } +} + +static void evergreen_bind_vs_sampler(struct pipe_context *ctx, unsigned count, void **states) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state **rstates = (struct r600_pipe_state **)states; + + for (int i = 0; i < count; i++) { + evergreen_context_pipe_state_set_vs_sampler(&rctx->ctx, rstates[i], i); + } +} + +static void evergreen_set_clip_state(struct pipe_context *ctx, + const struct pipe_clip_state *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + + if (rstate == NULL) + return; + + rctx->clip = *state; + rstate->id = R600_PIPE_STATE_CLIP; + for (int i = 0; i < state->nr; i++) { + r600_pipe_state_add_reg(rstate, + R_0285BC_PA_CL_UCP0_X + i * 16, + fui(state->ucp[i][0]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_0285C0_PA_CL_UCP0_Y + i * 16, + fui(state->ucp[i][1]) , 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_0285C4_PA_CL_UCP0_Z + i * 16, + fui(state->ucp[i][2]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_0285C8_PA_CL_UCP0_W + i * 16, + fui(state->ucp[i][3]), 0xFFFFFFFF, NULL); + } + r600_pipe_state_add_reg(rstate, R_028810_PA_CL_CLIP_CNTL, + S_028810_PS_UCP_MODE(3) | ((1 << state->nr) - 1) | + S_028810_ZCLIP_NEAR_DISABLE(state->depth_clamp) | + S_028810_ZCLIP_FAR_DISABLE(state->depth_clamp), 0xFFFFFFFF, NULL); + + free(rctx->states[R600_PIPE_STATE_CLIP]); + rctx->states[R600_PIPE_STATE_CLIP] = rstate; + r600_context_pipe_state_set(&rctx->ctx, rstate); +} + +static void evergreen_set_polygon_stipple(struct pipe_context *ctx, + const struct pipe_poly_stipple *state) +{ +} + +static void evergreen_set_sample_mask(struct pipe_context *pipe, unsigned sample_mask) +{ +} + +static void evergreen_set_scissor_state(struct pipe_context *ctx, + const struct pipe_scissor_state *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + u32 tl, br; + + if (rstate == NULL) + return; + + rstate->id = R600_PIPE_STATE_SCISSOR; + tl = S_028240_TL_X(state->minx) | S_028240_TL_Y(state->miny); + br = S_028244_BR_X(state->maxx) | S_028244_BR_Y(state->maxy); + r600_pipe_state_add_reg(rstate, + R_028210_PA_SC_CLIPRECT_0_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028214_PA_SC_CLIPRECT_0_BR, br, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028218_PA_SC_CLIPRECT_1_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_02821C_PA_SC_CLIPRECT_1_BR, br, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028220_PA_SC_CLIPRECT_2_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028224_PA_SC_CLIPRECT_2_BR, br, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028228_PA_SC_CLIPRECT_3_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_02822C_PA_SC_CLIPRECT_3_BR, br, + 0xFFFFFFFF, NULL); + + free(rctx->states[R600_PIPE_STATE_SCISSOR]); + rctx->states[R600_PIPE_STATE_SCISSOR] = rstate; + r600_context_pipe_state_set(&rctx->ctx, rstate); +} + +static void evergreen_set_stencil_ref(struct pipe_context *ctx, + const struct pipe_stencil_ref *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + u32 tmp; + + if (rstate == NULL) + return; + + rctx->stencil_ref = *state; + rstate->id = R600_PIPE_STATE_STENCIL_REF; + tmp = S_028430_STENCILREF(state->ref_value[0]); + r600_pipe_state_add_reg(rstate, + R_028430_DB_STENCILREFMASK, tmp, + ~C_028430_STENCILREF, NULL); + tmp = S_028434_STENCILREF_BF(state->ref_value[1]); + r600_pipe_state_add_reg(rstate, + R_028434_DB_STENCILREFMASK_BF, tmp, + ~C_028434_STENCILREF_BF, NULL); + + free(rctx->states[R600_PIPE_STATE_STENCIL_REF]); + rctx->states[R600_PIPE_STATE_STENCIL_REF] = rstate; + r600_context_pipe_state_set(&rctx->ctx, rstate); +} + +static void evergreen_set_viewport_state(struct pipe_context *ctx, + const struct pipe_viewport_state *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + + if (rstate == NULL) + return; + + rctx->viewport = *state; + rstate->id = R600_PIPE_STATE_VIEWPORT; + r600_pipe_state_add_reg(rstate, R_0282D0_PA_SC_VPORT_ZMIN_0, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0282D4_PA_SC_VPORT_ZMAX_0, 0x3F800000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02843C_PA_CL_VPORT_XSCALE_0, fui(state->scale[0]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028444_PA_CL_VPORT_YSCALE_0, fui(state->scale[1]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02844C_PA_CL_VPORT_ZSCALE_0, fui(state->scale[2]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028440_PA_CL_VPORT_XOFFSET_0, fui(state->translate[0]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028448_PA_CL_VPORT_YOFFSET_0, fui(state->translate[1]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028450_PA_CL_VPORT_ZOFFSET_0, fui(state->translate[2]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028818_PA_CL_VTE_CNTL, 0x0000043F, 0xFFFFFFFF, NULL); + + free(rctx->states[R600_PIPE_STATE_VIEWPORT]); + rctx->states[R600_PIPE_STATE_VIEWPORT] = rstate; + r600_context_pipe_state_set(&rctx->ctx, rstate); +} + +static void evergreen_cb(struct r600_pipe_context *rctx, struct r600_pipe_state *rstate, + const struct pipe_framebuffer_state *state, int cb) +{ + struct r600_resource_texture *rtex; + struct r600_resource *rbuffer; + struct r600_surface *surf; + unsigned level = state->cbufs[cb]->u.tex.level; + unsigned pitch, slice; + unsigned color_info; + unsigned format, swap, ntype; + unsigned offset; + const struct util_format_description *desc; + struct r600_bo *bo[3]; + + surf = (struct r600_surface *)state->cbufs[cb]; + rtex = (struct r600_resource_texture*)state->cbufs[cb]->texture; + rbuffer = &rtex->resource; + bo[0] = rbuffer->bo; + bo[1] = rbuffer->bo; + bo[2] = rbuffer->bo; + + /* XXX quite sure for dx10+ hw don't need any offset hacks */ + offset = r600_texture_get_offset((struct r600_resource_texture *)state->cbufs[cb]->texture, + level, state->cbufs[cb]->u.tex.first_layer); + pitch = rtex->pitch_in_pixels[level] / 8 - 1; + slice = rtex->pitch_in_pixels[level] * surf->aligned_height / 64 - 1; + ntype = 0; + desc = util_format_description(rtex->resource.base.b.format); + if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) + ntype = V_028C70_NUMBER_SRGB; + + format = r600_translate_colorformat(rtex->resource.base.b.format); + swap = r600_translate_colorswap(rtex->resource.base.b.format); + color_info = S_028C70_FORMAT(format) | + S_028C70_COMP_SWAP(swap) | + S_028C70_BLEND_CLAMP(1) | + S_028C70_NUMBER_TYPE(ntype); + if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS) + color_info |= S_028C70_SOURCE_FORMAT(1); + + /* FIXME handle enabling of CB beyond BASE8 which has different offset */ + r600_pipe_state_add_reg(rstate, + R_028C60_CB_COLOR0_BASE + cb * 0x3C, + (offset + r600_bo_offset(bo[0])) >> 8, 0xFFFFFFFF, bo[0]); + r600_pipe_state_add_reg(rstate, + R_028C78_CB_COLOR0_DIM + cb * 0x3C, + 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028C70_CB_COLOR0_INFO + cb * 0x3C, + color_info, 0xFFFFFFFF, bo[0]); + r600_pipe_state_add_reg(rstate, + R_028C64_CB_COLOR0_PITCH + cb * 0x3C, + S_028C64_PITCH_TILE_MAX(pitch), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028C68_CB_COLOR0_SLICE + cb * 0x3C, + S_028C68_SLICE_TILE_MAX(slice), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028C6C_CB_COLOR0_VIEW + cb * 0x3C, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028C74_CB_COLOR0_ATTRIB + cb * 0x3C, + S_028C74_NON_DISP_TILING_ORDER(1), + 0xFFFFFFFF, bo[0]); +} + +static void evergreen_db(struct r600_pipe_context *rctx, struct r600_pipe_state *rstate, + const struct pipe_framebuffer_state *state) +{ + struct r600_resource_texture *rtex; + struct r600_resource *rbuffer; + struct r600_surface *surf; + unsigned level; + unsigned pitch, slice, format, stencil_format; + unsigned offset; + + if (state->zsbuf == NULL) + return; + + level = state->zsbuf->u.tex.level; + + surf = (struct r600_surface *)state->zsbuf; + rtex = (struct r600_resource_texture*)state->zsbuf->texture; + rtex->tiled = 1; + rtex->array_mode[level] = 2; + rtex->tile_type = 1; + rtex->depth = 1; + rbuffer = &rtex->resource; + + /* XXX quite sure for dx10+ hw don't need any offset hacks */ + offset = r600_texture_get_offset((struct r600_resource_texture *)state->zsbuf->texture, + level, state->zsbuf->u.tex.first_layer); + pitch = rtex->pitch_in_pixels[level] / 8 - 1; + slice = rtex->pitch_in_pixels[level] * surf->aligned_height / 64 - 1; + format = r600_translate_dbformat(state->zsbuf->texture->format); + stencil_format = r600_translate_stencilformat(state->zsbuf->texture->format); + + r600_pipe_state_add_reg(rstate, R_028048_DB_Z_READ_BASE, + (offset + r600_bo_offset(rbuffer->bo)) >> 8, 0xFFFFFFFF, rbuffer->bo); + r600_pipe_state_add_reg(rstate, R_028050_DB_Z_WRITE_BASE, + (offset + r600_bo_offset(rbuffer->bo)) >> 8, 0xFFFFFFFF, rbuffer->bo); + + if (stencil_format) { + uint32_t stencil_offset; + + stencil_offset = ((surf->aligned_height * rtex->pitch_in_bytes[level]) + 255) & ~255; + r600_pipe_state_add_reg(rstate, R_02804C_DB_STENCIL_READ_BASE, + (offset + stencil_offset + r600_bo_offset(rbuffer->bo)) >> 8, 0xFFFFFFFF, rbuffer->bo); + r600_pipe_state_add_reg(rstate, R_028054_DB_STENCIL_WRITE_BASE, + (offset + stencil_offset + r600_bo_offset(rbuffer->bo)) >> 8, 0xFFFFFFFF, rbuffer->bo); + } + + r600_pipe_state_add_reg(rstate, R_028008_DB_DEPTH_VIEW, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028044_DB_STENCIL_INFO, + S_028044_FORMAT(stencil_format), 0xFFFFFFFF, rbuffer->bo); + + r600_pipe_state_add_reg(rstate, R_028040_DB_Z_INFO, + S_028040_ARRAY_MODE(rtex->array_mode[level]) | S_028040_FORMAT(format), + 0xFFFFFFFF, rbuffer->bo); + r600_pipe_state_add_reg(rstate, R_028058_DB_DEPTH_SIZE, + S_028058_PITCH_TILE_MAX(pitch), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02805C_DB_DEPTH_SLICE, + S_02805C_SLICE_TILE_MAX(slice), + 0xFFFFFFFF, NULL); +} + +static void evergreen_set_framebuffer_state(struct pipe_context *ctx, + const struct pipe_framebuffer_state *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + u32 shader_mask, tl, br, target_mask; + + if (rstate == NULL) + return; + + /* unreference old buffer and reference new one */ + rstate->id = R600_PIPE_STATE_FRAMEBUFFER; + + util_copy_framebuffer_state(&rctx->framebuffer, state); + + rctx->pframebuffer = &rctx->framebuffer; + + /* build states */ + for (int i = 0; i < state->nr_cbufs; i++) { + evergreen_cb(rctx, rstate, state, i); + } + if (state->zsbuf) { + evergreen_db(rctx, rstate, state); + } + + target_mask = 0x00000000; + target_mask = 0xFFFFFFFF; + shader_mask = 0; + for (int i = 0; i < state->nr_cbufs; i++) { + target_mask ^= 0xf << (i * 4); + shader_mask |= 0xf << (i * 4); + } + tl = S_028240_TL_X(0) | S_028240_TL_Y(0); + br = S_028244_BR_X(state->width) | S_028244_BR_Y(state->height); + + r600_pipe_state_add_reg(rstate, + R_028240_PA_SC_GENERIC_SCISSOR_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028244_PA_SC_GENERIC_SCISSOR_BR, br, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028250_PA_SC_VPORT_SCISSOR_0_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028254_PA_SC_VPORT_SCISSOR_0_BR, br, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028030_PA_SC_SCREEN_SCISSOR_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028034_PA_SC_SCREEN_SCISSOR_BR, br, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028204_PA_SC_WINDOW_SCISSOR_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028208_PA_SC_WINDOW_SCISSOR_BR, br, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028200_PA_SC_WINDOW_OFFSET, 0x00000000, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028230_PA_SC_EDGERULE, 0xAAAAAAAA, + 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_028238_CB_TARGET_MASK, + 0x00000000, target_mask, NULL); + r600_pipe_state_add_reg(rstate, R_02823C_CB_SHADER_MASK, + shader_mask, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C04_PA_SC_AA_CONFIG, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C1C_PA_SC_AA_SAMPLE_LOCS_MCTX, + 0x00000000, 0xFFFFFFFF, NULL); + + free(rctx->states[R600_PIPE_STATE_FRAMEBUFFER]); + rctx->states[R600_PIPE_STATE_FRAMEBUFFER] = rstate; + r600_context_pipe_state_set(&rctx->ctx, rstate); + + if (state->zsbuf) { + evergreen_polygon_offset_update(rctx); + } +} + +static void evergreen_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index, + struct pipe_resource *buffer) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_resource *rbuffer = (struct r600_resource*)buffer; + + /* Note that the state tracker can unbind constant buffers by + * passing NULL here. + */ + if (buffer == NULL) { + return; + } + + switch (shader) { + case PIPE_SHADER_VERTEX: + rctx->vs_const_buffer.nregs = 0; + r600_pipe_state_add_reg(&rctx->vs_const_buffer, + R_028180_ALU_CONST_BUFFER_SIZE_VS_0, + ALIGN_DIVUP(buffer->width0 >> 4, 16), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&rctx->vs_const_buffer, + R_028980_ALU_CONST_CACHE_VS_0, + (r600_bo_offset(rbuffer->bo)) >> 8, 0xFFFFFFFF, rbuffer->bo); + r600_context_pipe_state_set(&rctx->ctx, &rctx->vs_const_buffer); + break; + case PIPE_SHADER_FRAGMENT: + rctx->ps_const_buffer.nregs = 0; + r600_pipe_state_add_reg(&rctx->ps_const_buffer, + R_028140_ALU_CONST_BUFFER_SIZE_PS_0, + ALIGN_DIVUP(buffer->width0 >> 4, 16), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&rctx->ps_const_buffer, + R_028940_ALU_CONST_CACHE_PS_0, + (r600_bo_offset(rbuffer->bo)) >> 8, 0xFFFFFFFF, rbuffer->bo); + r600_context_pipe_state_set(&rctx->ctx, &rctx->ps_const_buffer); + break; + default: + R600_ERR("unsupported %d\n", shader); + return; + } +} + +void evergreen_init_state_functions(struct r600_pipe_context *rctx) +{ + rctx->context.create_blend_state = evergreen_create_blend_state; + rctx->context.create_depth_stencil_alpha_state = evergreen_create_dsa_state; + rctx->context.create_fs_state = r600_create_shader_state; + rctx->context.create_rasterizer_state = evergreen_create_rs_state; + rctx->context.create_sampler_state = evergreen_create_sampler_state; + rctx->context.create_sampler_view = evergreen_create_sampler_view; + rctx->context.create_vertex_elements_state = r600_create_vertex_elements; + rctx->context.create_vs_state = r600_create_shader_state; + rctx->context.bind_blend_state = r600_bind_blend_state; + rctx->context.bind_depth_stencil_alpha_state = r600_bind_state; + rctx->context.bind_fragment_sampler_states = evergreen_bind_ps_sampler; + rctx->context.bind_fs_state = r600_bind_ps_shader; + rctx->context.bind_rasterizer_state = r600_bind_rs_state; + rctx->context.bind_vertex_elements_state = r600_bind_vertex_elements; + rctx->context.bind_vertex_sampler_states = evergreen_bind_vs_sampler; + rctx->context.bind_vs_state = r600_bind_vs_shader; + rctx->context.delete_blend_state = r600_delete_state; + rctx->context.delete_depth_stencil_alpha_state = r600_delete_state; + rctx->context.delete_fs_state = r600_delete_ps_shader; + rctx->context.delete_rasterizer_state = r600_delete_rs_state; + rctx->context.delete_sampler_state = r600_delete_state; + rctx->context.delete_vertex_elements_state = r600_delete_vertex_element; + rctx->context.delete_vs_state = r600_delete_vs_shader; + rctx->context.set_blend_color = evergreen_set_blend_color; + rctx->context.set_clip_state = evergreen_set_clip_state; + rctx->context.set_constant_buffer = evergreen_set_constant_buffer; + rctx->context.set_fragment_sampler_views = evergreen_set_ps_sampler_view; + rctx->context.set_framebuffer_state = evergreen_set_framebuffer_state; + rctx->context.set_polygon_stipple = evergreen_set_polygon_stipple; + rctx->context.set_sample_mask = evergreen_set_sample_mask; + rctx->context.set_scissor_state = evergreen_set_scissor_state; + rctx->context.set_stencil_ref = evergreen_set_stencil_ref; + rctx->context.set_vertex_buffers = r600_set_vertex_buffers; + rctx->context.set_index_buffer = r600_set_index_buffer; + rctx->context.set_vertex_sampler_views = evergreen_set_vs_sampler_view; + rctx->context.set_viewport_state = evergreen_set_viewport_state; + rctx->context.sampler_view_destroy = r600_sampler_view_destroy; +} + +void evergreen_init_config(struct r600_pipe_context *rctx) +{ + struct r600_pipe_state *rstate = &rctx->config; + int ps_prio; + int vs_prio; + int gs_prio; + int es_prio; + int hs_prio, cs_prio, ls_prio; + int num_ps_gprs; + int num_vs_gprs; + int num_gs_gprs; + int num_es_gprs; + int num_hs_gprs; + int num_ls_gprs; + int num_temp_gprs; + int num_ps_threads; + int num_vs_threads; + int num_gs_threads; + int num_es_threads; + int num_hs_threads; + int num_ls_threads; + int num_ps_stack_entries; + int num_vs_stack_entries; + int num_gs_stack_entries; + int num_es_stack_entries; + int num_hs_stack_entries; + int num_ls_stack_entries; + enum radeon_family family; + unsigned tmp; + + family = r600_get_family(rctx->radeon); + ps_prio = 0; + vs_prio = 1; + gs_prio = 2; + es_prio = 3; + hs_prio = 0; + ls_prio = 0; + cs_prio = 0; + + switch (family) { + case CHIP_CEDAR: + default: + num_ps_gprs = 93; + num_vs_gprs = 46; + num_temp_gprs = 4; + num_gs_gprs = 31; + num_es_gprs = 31; + num_hs_gprs = 23; + num_ls_gprs = 23; + num_ps_threads = 96; + num_vs_threads = 16; + num_gs_threads = 16; + num_es_threads = 16; + num_hs_threads = 16; + num_ls_threads = 16; + num_ps_stack_entries = 42; + num_vs_stack_entries = 42; + num_gs_stack_entries = 42; + num_es_stack_entries = 42; + num_hs_stack_entries = 42; + num_ls_stack_entries = 42; + break; + case CHIP_REDWOOD: + num_ps_gprs = 93; + num_vs_gprs = 46; + num_temp_gprs = 4; + num_gs_gprs = 31; + num_es_gprs = 31; + num_hs_gprs = 23; + num_ls_gprs = 23; + num_ps_threads = 128; + num_vs_threads = 20; + num_gs_threads = 20; + num_es_threads = 20; + num_hs_threads = 20; + num_ls_threads = 20; + num_ps_stack_entries = 42; + num_vs_stack_entries = 42; + num_gs_stack_entries = 42; + num_es_stack_entries = 42; + num_hs_stack_entries = 42; + num_ls_stack_entries = 42; + break; + case CHIP_JUNIPER: + num_ps_gprs = 93; + num_vs_gprs = 46; + num_temp_gprs = 4; + num_gs_gprs = 31; + num_es_gprs = 31; + num_hs_gprs = 23; + num_ls_gprs = 23; + num_ps_threads = 128; + num_vs_threads = 20; + num_gs_threads = 20; + num_es_threads = 20; + num_hs_threads = 20; + num_ls_threads = 20; + num_ps_stack_entries = 85; + num_vs_stack_entries = 85; + num_gs_stack_entries = 85; + num_es_stack_entries = 85; + num_hs_stack_entries = 85; + num_ls_stack_entries = 85; + break; + case CHIP_CYPRESS: + case CHIP_HEMLOCK: + num_ps_gprs = 93; + num_vs_gprs = 46; + num_temp_gprs = 4; + num_gs_gprs = 31; + num_es_gprs = 31; + num_hs_gprs = 23; + num_ls_gprs = 23; + num_ps_threads = 128; + num_vs_threads = 20; + num_gs_threads = 20; + num_es_threads = 20; + num_hs_threads = 20; + num_ls_threads = 20; + num_ps_stack_entries = 85; + num_vs_stack_entries = 85; + num_gs_stack_entries = 85; + num_es_stack_entries = 85; + num_hs_stack_entries = 85; + num_ls_stack_entries = 85; + break; + case CHIP_PALM: + num_ps_gprs = 93; + num_vs_gprs = 46; + num_temp_gprs = 4; + num_gs_gprs = 31; + num_es_gprs = 31; + num_hs_gprs = 23; + num_ls_gprs = 23; + num_ps_threads = 96; + num_vs_threads = 16; + num_gs_threads = 16; + num_es_threads = 16; + num_hs_threads = 16; + num_ls_threads = 16; + num_ps_stack_entries = 42; + num_vs_stack_entries = 42; + num_gs_stack_entries = 42; + num_es_stack_entries = 42; + num_hs_stack_entries = 42; + num_ls_stack_entries = 42; + break; + case CHIP_BARTS: + num_ps_gprs = 93; + num_vs_gprs = 46; + num_temp_gprs = 4; + num_gs_gprs = 31; + num_es_gprs = 31; + num_hs_gprs = 23; + num_ls_gprs = 23; + num_ps_threads = 128; + num_vs_threads = 20; + num_gs_threads = 20; + num_es_threads = 20; + num_hs_threads = 20; + num_ls_threads = 20; + num_ps_stack_entries = 85; + num_vs_stack_entries = 85; + num_gs_stack_entries = 85; + num_es_stack_entries = 85; + num_hs_stack_entries = 85; + num_ls_stack_entries = 85; + break; + case CHIP_TURKS: + num_ps_gprs = 93; + num_vs_gprs = 46; + num_temp_gprs = 4; + num_gs_gprs = 31; + num_es_gprs = 31; + num_hs_gprs = 23; + num_ls_gprs = 23; + num_ps_threads = 128; + num_vs_threads = 20; + num_gs_threads = 20; + num_es_threads = 20; + num_hs_threads = 20; + num_ls_threads = 20; + num_ps_stack_entries = 42; + num_vs_stack_entries = 42; + num_gs_stack_entries = 42; + num_es_stack_entries = 42; + num_hs_stack_entries = 42; + num_ls_stack_entries = 42; + break; + case CHIP_CAICOS: + num_ps_gprs = 93; + num_vs_gprs = 46; + num_temp_gprs = 4; + num_gs_gprs = 31; + num_es_gprs = 31; + num_hs_gprs = 23; + num_ls_gprs = 23; + num_ps_threads = 128; + num_vs_threads = 10; + num_gs_threads = 10; + num_es_threads = 10; + num_hs_threads = 10; + num_ls_threads = 10; + num_ps_stack_entries = 42; + num_vs_stack_entries = 42; + num_gs_stack_entries = 42; + num_es_stack_entries = 42; + num_hs_stack_entries = 42; + num_ls_stack_entries = 42; + break; + } + + tmp = 0x00000000; + switch (family) { + case CHIP_CEDAR: + case CHIP_PALM: + case CHIP_CAICOS: + break; + default: + tmp |= S_008C00_VC_ENABLE(1); + break; + } + tmp |= S_008C00_EXPORT_SRC_C(1); + tmp |= S_008C00_CS_PRIO(cs_prio); + tmp |= S_008C00_LS_PRIO(ls_prio); + tmp |= S_008C00_HS_PRIO(hs_prio); + tmp |= S_008C00_PS_PRIO(ps_prio); + tmp |= S_008C00_VS_PRIO(vs_prio); + tmp |= S_008C00_GS_PRIO(gs_prio); + tmp |= S_008C00_ES_PRIO(es_prio); + r600_pipe_state_add_reg(rstate, R_008C00_SQ_CONFIG, tmp, 0xFFFFFFFF, NULL); + + tmp = 0; + tmp |= S_008C04_NUM_PS_GPRS(num_ps_gprs); + tmp |= S_008C04_NUM_VS_GPRS(num_vs_gprs); + tmp |= S_008C04_NUM_CLAUSE_TEMP_GPRS(num_temp_gprs); + r600_pipe_state_add_reg(rstate, R_008C04_SQ_GPR_RESOURCE_MGMT_1, tmp, 0xFFFFFFFF, NULL); + + tmp = 0; + tmp |= S_008C08_NUM_GS_GPRS(num_gs_gprs); + tmp |= S_008C08_NUM_ES_GPRS(num_es_gprs); + r600_pipe_state_add_reg(rstate, R_008C08_SQ_GPR_RESOURCE_MGMT_2, tmp, 0xFFFFFFFF, NULL); + + tmp = 0; + tmp |= S_008C0C_NUM_HS_GPRS(num_hs_gprs); + tmp |= S_008C0C_NUM_LS_GPRS(num_ls_gprs); + r600_pipe_state_add_reg(rstate, R_008C0C_SQ_GPR_RESOURCE_MGMT_3, tmp, 0xFFFFFFFF, NULL); + + tmp = 0; + tmp |= S_008C18_NUM_PS_THREADS(num_ps_threads); + tmp |= S_008C18_NUM_VS_THREADS(num_vs_threads); + tmp |= S_008C18_NUM_GS_THREADS(num_gs_threads); + tmp |= S_008C18_NUM_ES_THREADS(num_es_threads); + r600_pipe_state_add_reg(rstate, R_008C18_SQ_THREAD_RESOURCE_MGMT_1, tmp, 0xFFFFFFFF, NULL); + + tmp = 0; + tmp |= S_008C1C_NUM_HS_THREADS(num_hs_threads); + tmp |= S_008C1C_NUM_LS_THREADS(num_ls_threads); + r600_pipe_state_add_reg(rstate, R_008C1C_SQ_THREAD_RESOURCE_MGMT_2, tmp, 0xFFFFFFFF, NULL); + + tmp = 0; + tmp |= S_008C20_NUM_PS_STACK_ENTRIES(num_ps_stack_entries); + tmp |= S_008C20_NUM_VS_STACK_ENTRIES(num_vs_stack_entries); + r600_pipe_state_add_reg(rstate, R_008C20_SQ_STACK_RESOURCE_MGMT_1, tmp, 0xFFFFFFFF, NULL); + + tmp = 0; + tmp |= S_008C24_NUM_GS_STACK_ENTRIES(num_gs_stack_entries); + tmp |= S_008C24_NUM_ES_STACK_ENTRIES(num_es_stack_entries); + r600_pipe_state_add_reg(rstate, R_008C24_SQ_STACK_RESOURCE_MGMT_2, tmp, 0xFFFFFFFF, NULL); + + tmp = 0; + tmp |= S_008C28_NUM_HS_STACK_ENTRIES(num_hs_stack_entries); + tmp |= S_008C28_NUM_LS_STACK_ENTRIES(num_ls_stack_entries); + r600_pipe_state_add_reg(rstate, R_008C28_SQ_STACK_RESOURCE_MGMT_3, tmp, 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_009100_SPI_CONFIG_CNTL, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_00913C_SPI_CONFIG_CNTL_1, S_00913C_VTX_DONE_DELAY(4), 0xFFFFFFFF, NULL); + +// r600_pipe_state_add_reg(rstate, R_028350_SX_MISC, 0x0, 0xFFFFFFFF, NULL); + +// r600_pipe_state_add_reg(rstate, R_008D8C_SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A48_PA_SC_MODE_CNTL_0, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A4C_PA_SC_MODE_CNTL_1, 0x0, 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_028900_SQ_ESGS_RING_ITEMSIZE, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028904_SQ_GSVS_RING_ITEMSIZE, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028908_SQ_ESTMP_RING_ITEMSIZE, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02890C_SQ_GSTMP_RING_ITEMSIZE, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028910_SQ_VSTMP_RING_ITEMSIZE, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028914_SQ_PSTMP_RING_ITEMSIZE, 0x0, 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_02891C_SQ_GS_VERT_ITEMSIZE, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028920_SQ_GS_VERT_ITEMSIZE_1, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028924_SQ_GS_VERT_ITEMSIZE_2, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028928_SQ_GS_VERT_ITEMSIZE_3, 0x0, 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_028A10_VGT_OUTPUT_PATH_CNTL, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A14_VGT_HOS_CNTL, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A18_VGT_HOS_MAX_TESS_LEVEL, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A1C_VGT_HOS_MIN_TESS_LEVEL, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A20_VGT_HOS_REUSE_DEPTH, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A24_VGT_GROUP_PRIM_TYPE, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A28_VGT_GROUP_FIRST_DECR, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A2C_VGT_GROUP_DECR, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A30_VGT_GROUP_VECT_0_CNTL, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A34_VGT_GROUP_VECT_1_CNTL, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A38_VGT_GROUP_VECT_0_FMT_CNTL, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A3C_VGT_GROUP_VECT_1_FMT_CNTL, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A40_VGT_GS_MODE, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028B94_VGT_STRMOUT_CONFIG, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028B98_VGT_STRMOUT_BUFFER_CONFIG, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028AB4_VGT_REUSE_OFF, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028AB8_VGT_VTX_CNT_EN, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_008A14_PA_CL_ENHANCE, (3 << 1) | 1, 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_028380_SQ_VTX_SEMANTIC_0, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028384_SQ_VTX_SEMANTIC_1, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028388_SQ_VTX_SEMANTIC_2, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02838C_SQ_VTX_SEMANTIC_3, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028390_SQ_VTX_SEMANTIC_4, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028394_SQ_VTX_SEMANTIC_5, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028398_SQ_VTX_SEMANTIC_6, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02839C_SQ_VTX_SEMANTIC_7, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283A0_SQ_VTX_SEMANTIC_8, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283A4_SQ_VTX_SEMANTIC_9, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283A8_SQ_VTX_SEMANTIC_10, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283AC_SQ_VTX_SEMANTIC_11, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283B0_SQ_VTX_SEMANTIC_12, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283B4_SQ_VTX_SEMANTIC_13, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283B8_SQ_VTX_SEMANTIC_14, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283BC_SQ_VTX_SEMANTIC_15, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283C0_SQ_VTX_SEMANTIC_16, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283C4_SQ_VTX_SEMANTIC_17, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283C8_SQ_VTX_SEMANTIC_18, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283CC_SQ_VTX_SEMANTIC_19, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283D0_SQ_VTX_SEMANTIC_20, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283D4_SQ_VTX_SEMANTIC_21, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283D8_SQ_VTX_SEMANTIC_22, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283DC_SQ_VTX_SEMANTIC_23, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283E0_SQ_VTX_SEMANTIC_24, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283E4_SQ_VTX_SEMANTIC_25, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283E8_SQ_VTX_SEMANTIC_26, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283EC_SQ_VTX_SEMANTIC_27, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283F0_SQ_VTX_SEMANTIC_28, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283F4_SQ_VTX_SEMANTIC_29, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283F8_SQ_VTX_SEMANTIC_30, 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0283FC_SQ_VTX_SEMANTIC_31, 0x0, 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_028810_PA_CL_CLIP_CNTL, 0x0, 0xFFFFFFFF, NULL); + + r600_context_pipe_state_set(&rctx->ctx, rstate); +} + +void evergreen_polygon_offset_update(struct r600_pipe_context *rctx) +{ + struct r600_pipe_state state; + + state.id = R600_PIPE_STATE_POLYGON_OFFSET; + state.nregs = 0; + if (rctx->rasterizer && rctx->framebuffer.zsbuf) { + float offset_units = rctx->rasterizer->offset_units; + unsigned offset_db_fmt_cntl = 0, depth; + + switch (rctx->framebuffer.zsbuf->texture->format) { + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + depth = -24; + offset_units *= 2.0f; + break; + case PIPE_FORMAT_Z32_FLOAT: + depth = -23; + offset_units *= 1.0f; + offset_db_fmt_cntl |= S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1); + break; + case PIPE_FORMAT_Z16_UNORM: + depth = -16; + offset_units *= 4.0f; + break; + default: + return; + } + /* FIXME some of those reg can be computed with cso */ + offset_db_fmt_cntl |= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(depth); + r600_pipe_state_add_reg(&state, + R_028B80_PA_SU_POLY_OFFSET_FRONT_SCALE, + fui(rctx->rasterizer->offset_scale), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&state, + R_028B84_PA_SU_POLY_OFFSET_FRONT_OFFSET, + fui(offset_units), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&state, + R_028B88_PA_SU_POLY_OFFSET_BACK_SCALE, + fui(rctx->rasterizer->offset_scale), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&state, + R_028B8C_PA_SU_POLY_OFFSET_BACK_OFFSET, + fui(offset_units), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&state, + R_028B78_PA_SU_POLY_OFFSET_DB_FMT_CNTL, + offset_db_fmt_cntl, 0xFFFFFFFF, NULL); + r600_context_pipe_state_set(&rctx->ctx, &state); + } +} + +static void evergreen_spi_update(struct r600_pipe_context *rctx) +{ + struct r600_pipe_shader *shader = rctx->ps_shader; + struct r600_pipe_state rstate; + struct r600_shader *rshader = &shader->shader; + unsigned i, tmp; + + rstate.nregs = 0; + for (i = 0; i < rshader->ninput; i++) { + tmp = S_028644_SEMANTIC(r600_find_vs_semantic_index(&rctx->vs_shader->shader, rshader, i)); + if (rshader->input[i].name == TGSI_SEMANTIC_COLOR || + rshader->input[i].name == TGSI_SEMANTIC_BCOLOR || + rshader->input[i].name == TGSI_SEMANTIC_POSITION) { + tmp |= S_028644_FLAT_SHADE(rctx->flatshade); + } + if (rshader->input[i].name == TGSI_SEMANTIC_GENERIC && + rctx->sprite_coord_enable & (1 << rshader->input[i].sid)) { + tmp |= S_028644_PT_SPRITE_TEX(1); + } + r600_pipe_state_add_reg(&rstate, R_028644_SPI_PS_INPUT_CNTL_0 + i * 4, tmp, 0xFFFFFFFF, NULL); + } + r600_context_pipe_state_set(&rctx->ctx, &rstate); +} + +void evergreen_vertex_buffer_update(struct r600_pipe_context *rctx) +{ + struct r600_pipe_state *rstate; + struct r600_resource *rbuffer; + struct pipe_vertex_buffer *vertex_buffer; + unsigned i, offset; + + /* we don't update until we know vertex elements */ + if (rctx->vertex_elements == NULL || !rctx->nvertex_buffer) + return; + + if (rctx->vertex_elements->incompatible_layout) { + /* translate rebind new vertex elements so + * return once translated + */ + r600_begin_vertex_translate(rctx); + return; + } + + if (rctx->any_user_vbs) { + r600_upload_user_buffers(rctx); + rctx->any_user_vbs = FALSE; + } + + if (rctx->vertex_elements->vbuffer_need_offset) { + /* one resource per vertex elements */ + rctx->nvs_resource = rctx->vertex_elements->count; + } else { + /* bind vertex buffer once */ + rctx->nvs_resource = rctx->nvertex_buffer; + } + + for (i = 0 ; i < rctx->nvs_resource; i++) { + rstate = &rctx->vs_resource[i]; + rstate->id = R600_PIPE_STATE_RESOURCE; + rstate->nregs = 0; + + if (rctx->vertex_elements->vbuffer_need_offset) { + /* one resource per vertex elements */ + unsigned vbuffer_index; + vbuffer_index = rctx->vertex_elements->elements[i].vertex_buffer_index; + vertex_buffer = &rctx->vertex_buffer[vbuffer_index]; + rbuffer = (struct r600_resource*)vertex_buffer->buffer; + offset = rctx->vertex_elements->vbuffer_offset[i]; + } else { + /* bind vertex buffer once */ + vertex_buffer = &rctx->vertex_buffer[i]; + rbuffer = (struct r600_resource*)vertex_buffer->buffer; + offset = 0; + } + if (vertex_buffer == NULL || rbuffer == NULL) + continue; + offset += vertex_buffer->buffer_offset + r600_bo_offset(rbuffer->bo); + + r600_pipe_state_add_reg(rstate, R_030000_RESOURCE0_WORD0, + offset, 0xFFFFFFFF, rbuffer->bo); + r600_pipe_state_add_reg(rstate, R_030004_RESOURCE0_WORD1, + rbuffer->bo_size - offset - 1, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_030008_RESOURCE0_WORD2, + S_030008_STRIDE(vertex_buffer->stride), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_03000C_RESOURCE0_WORD3, + S_03000C_DST_SEL_X(V_03000C_SQ_SEL_X) | + S_03000C_DST_SEL_Y(V_03000C_SQ_SEL_Y) | + S_03000C_DST_SEL_Z(V_03000C_SQ_SEL_Z) | + S_03000C_DST_SEL_W(V_03000C_SQ_SEL_W), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_030010_RESOURCE0_WORD4, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_030014_RESOURCE0_WORD5, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_030018_RESOURCE0_WORD6, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_03001C_RESOURCE0_WORD7, + 0xC0000000, 0xFFFFFFFF, NULL); + evergreen_fs_resource_set(&rctx->ctx, rstate, i); + } +} + +int r600_conv_pipe_prim(unsigned pprim, unsigned *prim); +void evergreen_draw(struct pipe_context *ctx, const struct pipe_draw_info *info) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_resource *rbuffer; + u32 vgt_dma_index_type, vgt_draw_initiator, mask; + struct r600_draw rdraw; + struct r600_pipe_state vgt; + struct r600_drawl draw; + unsigned prim; + + memset(&draw, 0, sizeof(struct r600_drawl)); + draw.ctx = ctx; + draw.mode = info->mode; + draw.start = info->start; + draw.count = info->count; + if (info->indexed && rctx->index_buffer.buffer) { + draw.start += rctx->index_buffer.offset / rctx->index_buffer.index_size; + draw.min_index = info->min_index; + draw.max_index = info->max_index; + draw.index_bias = info->index_bias; + + r600_translate_index_buffer(rctx, &rctx->index_buffer.buffer, + &rctx->index_buffer.index_size, + &draw.start, + info->count); + + draw.index_size = rctx->index_buffer.index_size; + pipe_resource_reference(&draw.index_buffer, rctx->index_buffer.buffer); + draw.index_buffer_offset = draw.start * draw.index_size; + draw.start = 0; + r600_upload_index_buffer(rctx, &draw); + } else { + draw.index_size = 0; + draw.index_buffer = NULL; + draw.min_index = info->min_index; + draw.max_index = info->max_index; + draw.index_bias = info->start; + } + + switch (draw.index_size) { + case 2: + vgt_draw_initiator = 0; + vgt_dma_index_type = 0; + break; + case 4: + vgt_draw_initiator = 0; + vgt_dma_index_type = 1; + break; + case 0: + vgt_draw_initiator = 2; + vgt_dma_index_type = 0; + break; + default: + R600_ERR("unsupported index size %d\n", draw.index_size); + return; + } + if (r600_conv_pipe_prim(draw.mode, &prim)) + return; + if (unlikely(rctx->ps_shader == NULL)) { + R600_ERR("missing vertex shader\n"); + return; + } + if (unlikely(rctx->vs_shader == NULL)) { + R600_ERR("missing vertex shader\n"); + return; + } + /* there should be enough input */ + if (rctx->vertex_elements->count < rctx->vs_shader->shader.bc.nresource) { + R600_ERR("%d resources provided, expecting %d\n", + rctx->vertex_elements->count, rctx->vs_shader->shader.bc.nresource); + return; + } + + evergreen_spi_update(rctx); + + mask = 0; + for (int i = 0; i < rctx->framebuffer.nr_cbufs; i++) { + mask |= (0xF << (i * 4)); + } + + vgt.id = R600_PIPE_STATE_VGT; + vgt.nregs = 0; + r600_pipe_state_add_reg(&vgt, R_008958_VGT_PRIMITIVE_TYPE, prim, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&vgt, R_028408_VGT_INDX_OFFSET, draw.index_bias, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&vgt, R_028238_CB_TARGET_MASK, rctx->cb_target_mask & mask, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&vgt, R_028400_VGT_MAX_VTX_INDX, draw.max_index, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&vgt, R_028404_VGT_MIN_VTX_INDX, draw.min_index, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&vgt, R_03CFF0_SQ_VTX_BASE_VTX_LOC, 0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&vgt, R_03CFF4_SQ_VTX_START_INST_LOC, 0, 0xFFFFFFFF, NULL); + r600_context_pipe_state_set(&rctx->ctx, &vgt); + + rdraw.vgt_num_indices = draw.count; + rdraw.vgt_num_instances = 1; + rdraw.vgt_index_type = vgt_dma_index_type; + rdraw.vgt_draw_initiator = vgt_draw_initiator; + rdraw.indices = NULL; + if (draw.index_buffer) { + rbuffer = (struct r600_resource*)draw.index_buffer; + rdraw.indices = rbuffer->bo; + rdraw.indices_bo_offset = draw.index_buffer_offset; + } + evergreen_context_draw(&rctx->ctx, &rdraw); + + pipe_resource_reference(&draw.index_buffer, NULL); +} + +void evergreen_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shader) +{ + struct r600_pipe_state *rstate = &shader->rstate; + struct r600_shader *rshader = &shader->shader; + unsigned i, exports_ps, num_cout, spi_ps_in_control_0, spi_input_z, spi_ps_in_control_1; + int pos_index = -1, face_index = -1; + int ninterp = 0; + boolean have_linear = FALSE, have_centroid = FALSE, have_perspective = FALSE; + unsigned spi_baryc_cntl; + + rstate->nregs = 0; + + for (i = 0; i < rshader->ninput; i++) { + /* evergreen NUM_INTERP only contains values interpolated into the LDS, + POSITION goes via GPRs from the SC so isn't counted */ + if (rshader->input[i].name == TGSI_SEMANTIC_POSITION) + pos_index = i; + else if (rshader->input[i].name == TGSI_SEMANTIC_FACE) + face_index = i; + else { + if (rshader->input[i].interpolate == TGSI_INTERPOLATE_LINEAR || + rshader->input[i].interpolate == TGSI_INTERPOLATE_PERSPECTIVE) + ninterp++; + if (rshader->input[i].interpolate == TGSI_INTERPOLATE_LINEAR) + have_linear = TRUE; + if (rshader->input[i].interpolate == TGSI_INTERPOLATE_PERSPECTIVE) + have_perspective = TRUE; + if (rshader->input[i].centroid) + have_centroid = TRUE; + } + } + for (i = 0; i < rshader->noutput; i++) { + if (rshader->output[i].name == TGSI_SEMANTIC_POSITION) + r600_pipe_state_add_reg(rstate, + R_02880C_DB_SHADER_CONTROL, + S_02880C_Z_EXPORT_ENABLE(1), + S_02880C_Z_EXPORT_ENABLE(1), NULL); + if (rshader->output[i].name == TGSI_SEMANTIC_STENCIL) + r600_pipe_state_add_reg(rstate, + R_02880C_DB_SHADER_CONTROL, + S_02880C_STENCIL_EXPORT_ENABLE(1), + S_02880C_STENCIL_EXPORT_ENABLE(1), NULL); + } + + exports_ps = 0; + num_cout = 0; + for (i = 0; i < rshader->noutput; i++) { + if (rshader->output[i].name == TGSI_SEMANTIC_POSITION || + rshader->output[i].name == TGSI_SEMANTIC_STENCIL) + exports_ps |= 1; + else if (rshader->output[i].name == TGSI_SEMANTIC_COLOR) { + num_cout++; + } + } + exports_ps |= S_02884C_EXPORT_COLORS(num_cout); + if (!exports_ps) { + /* always at least export 1 component per pixel */ + exports_ps = 2; + } + + if (ninterp == 0) { + ninterp = 1; + have_perspective = TRUE; + } + + spi_ps_in_control_0 = S_0286CC_NUM_INTERP(ninterp) | + S_0286CC_PERSP_GRADIENT_ENA(have_perspective) | + S_0286CC_LINEAR_GRADIENT_ENA(have_linear); + spi_input_z = 0; + if (pos_index != -1) { + spi_ps_in_control_0 |= S_0286CC_POSITION_ENA(1) | + S_0286CC_POSITION_CENTROID(rshader->input[pos_index].centroid) | + S_0286CC_POSITION_ADDR(rshader->input[pos_index].gpr); + spi_input_z |= 1; + } + + spi_ps_in_control_1 = 0; + if (face_index != -1) { + spi_ps_in_control_1 |= S_0286D0_FRONT_FACE_ENA(1) | + S_0286D0_FRONT_FACE_ADDR(rshader->input[face_index].gpr); + } + + spi_baryc_cntl = 0; + if (have_perspective) + spi_baryc_cntl |= S_0286E0_PERSP_CENTER_ENA(1) | + S_0286E0_PERSP_CENTROID_ENA(have_centroid); + if (have_linear) + spi_baryc_cntl |= S_0286E0_LINEAR_CENTER_ENA(1) | + S_0286E0_LINEAR_CENTROID_ENA(have_centroid); + + r600_pipe_state_add_reg(rstate, R_0286CC_SPI_PS_IN_CONTROL_0, + spi_ps_in_control_0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0286D0_SPI_PS_IN_CONTROL_1, + spi_ps_in_control_1, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0286E4_SPI_PS_IN_CONTROL_2, + 0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0286D8_SPI_INPUT_Z, spi_input_z, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_0286E0_SPI_BARYC_CNTL, + spi_baryc_cntl, + 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, + R_028840_SQ_PGM_START_PS, + (r600_bo_offset(shader->bo)) >> 8, 0xFFFFFFFF, shader->bo); + r600_pipe_state_add_reg(rstate, + R_028844_SQ_PGM_RESOURCES_PS, + S_028844_NUM_GPRS(rshader->bc.ngpr) | + S_028844_PRIME_CACHE_ON_DRAW(1) | + S_028844_STACK_SIZE(rshader->bc.nstack), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028848_SQ_PGM_RESOURCES_2_PS, + 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_02884C_SQ_PGM_EXPORTS_PS, + exports_ps, 0xFFFFFFFF, NULL); + + if (rshader->uses_kill) { + /* only set some bits here, the other bits are set in the dsa state */ + r600_pipe_state_add_reg(rstate, + R_02880C_DB_SHADER_CONTROL, + S_02880C_KILL_ENABLE(1), + S_02880C_KILL_ENABLE(1), NULL); + } + + r600_pipe_state_add_reg(rstate, + R_03A200_SQ_LOOP_CONST_0, 0x01000FFF, + 0xFFFFFFFF, NULL); +} + +void evergreen_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader *shader) +{ + struct r600_pipe_state *rstate = &shader->rstate; + struct r600_shader *rshader = &shader->shader; + unsigned spi_vs_out_id[10]; + unsigned i, tmp; + + /* clear previous register */ + rstate->nregs = 0; + + /* so far never got proper semantic id from tgsi */ + for (i = 0; i < 10; i++) { + spi_vs_out_id[i] = 0; + } + for (i = 0; i < 32; i++) { + tmp = i << ((i & 3) * 8); + spi_vs_out_id[i / 4] |= tmp; + } + for (i = 0; i < 10; i++) { + r600_pipe_state_add_reg(rstate, + R_02861C_SPI_VS_OUT_ID_0 + i * 4, + spi_vs_out_id[i], 0xFFFFFFFF, NULL); + } + + r600_pipe_state_add_reg(rstate, + R_0286C4_SPI_VS_OUT_CONFIG, + S_0286C4_VS_EXPORT_COUNT(rshader->noutput - 2), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028860_SQ_PGM_RESOURCES_VS, + S_028860_NUM_GPRS(rshader->bc.ngpr) | + S_028860_STACK_SIZE(rshader->bc.nstack), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028864_SQ_PGM_RESOURCES_2_VS, + 0x0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_02885C_SQ_PGM_START_VS, + (r600_bo_offset(shader->bo)) >> 8, 0xFFFFFFFF, shader->bo); + + r600_pipe_state_add_reg(rstate, + R_03A200_SQ_LOOP_CONST_0 + (32 * 4), 0x01000FFF, + 0xFFFFFFFF, NULL); +} + +void *evergreen_create_db_flush_dsa(struct r600_pipe_context *rctx) +{ + struct pipe_depth_stencil_alpha_state dsa; + struct r600_pipe_state *rstate; + + memset(&dsa, 0, sizeof(dsa)); + + rstate = rctx->context.create_depth_stencil_alpha_state(&rctx->context, &dsa); + r600_pipe_state_add_reg(rstate, + R_02880C_DB_SHADER_CONTROL, + 0x0, + S_02880C_DUAL_EXPORT_ENABLE(1), NULL); + r600_pipe_state_add_reg(rstate, + R_028000_DB_RENDER_CONTROL, + S_028000_DEPTH_COPY_ENABLE(1) | + S_028000_STENCIL_COPY_ENABLE(1) | + S_028000_COPY_CENTROID(1), + S_028000_DEPTH_COPY_ENABLE(1) | + S_028000_STENCIL_COPY_ENABLE(1) | + S_028000_COPY_CENTROID(1), NULL); + return rstate; +} diff --git a/src/gallium/drivers/r600/evergreend.h b/src/gallium/drivers/r600/evergreend.h new file mode 100644 index 0000000..e67254b --- /dev/null +++ b/src/gallium/drivers/r600/evergreend.h @@ -0,0 +1,1890 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#ifndef EVERGREEND_H +#define EVERGREEND_H + +/* evergreen values */ +#define EVERGREEN_CONFIG_REG_OFFSET 0X00008000 +#define EVERGREEN_CONFIG_REG_END 0X0000AC00 +#define EVERGREEN_CONTEXT_REG_OFFSET 0X00028000 +#define EVERGREEN_CONTEXT_REG_END 0X00029000 +#define EVERGREEN_RESOURCE_OFFSET 0x00030000 +#define EVERGREEN_RESOURCE_END 0x00034000 +#define EVERGREEN_LOOP_CONST_OFFSET 0x0003A200 +#define EVERGREEN_LOOP_CONST_END 0x0003A26C +#define EVERGREEN_BOOL_CONST_OFFSET 0x0003A500 +#define EVERGREEN_BOOL_CONST_END 0x0003A506 +#define EVERGREEN_SAMPLER_OFFSET 0X0003C000 +#define EVERGREEN_SAMPLER_END 0X0003CFF0 + +#define EVERGREEN_CTL_CONST_OFFSET 0x0003CFF0 +#define EVERGREEN_CTL_CONST_END 0x0003E200 + +#define EVENT_TYPE_ZPASS_DONE 0x15 +#define EVENT_TYPE_CACHE_FLUSH_AND_INV_EVENT 0x16 +#define EVENT_TYPE(x) ((x) << 0) +#define EVENT_INDEX(x) ((x) << 8) + /* 0 - any non-TS event + * 1 - ZPASS_DONE + * 2 - SAMPLE_PIPELINESTAT + * 3 - SAMPLE_STREAMOUTSTAT* + * 4 - *S_PARTIAL_FLUSH + * 5 - TS events + */ + +#define R600_TEXEL_PITCH_ALIGNMENT_MASK 0x7 + +#define PKT3_NOP 0x10 +#define PKT3_INDIRECT_BUFFER_END 0x17 +#define PKT3_SET_PREDICATION 0x20 +#define PKT3_REG_RMW 0x21 +#define PKT3_COND_EXEC 0x22 +#define PKT3_PRED_EXEC 0x23 +#define PKT3_START_3D_CMDBUF 0x24 +#define PKT3_DRAW_INDEX_2 0x27 +#define PKT3_CONTEXT_CONTROL 0x28 +#define PKT3_DRAW_INDEX_IMMD_BE 0x29 +#define PKT3_INDEX_TYPE 0x2A +#define PKT3_DRAW_INDEX 0x2B +#define PKT3_DRAW_INDEX_AUTO 0x2D +#define PKT3_DRAW_INDEX_IMMD 0x2E +#define PKT3_NUM_INSTANCES 0x2F +#define PKT3_STRMOUT_BUFFER_UPDATE 0x34 +#define PKT3_INDIRECT_BUFFER_MP 0x38 +#define PKT3_MEM_SEMAPHORE 0x39 +#define PKT3_MPEG_INDEX 0x3A +#define PKT3_WAIT_REG_MEM 0x3C +#define PKT3_MEM_WRITE 0x3D +#define PKT3_INDIRECT_BUFFER 0x32 +#define PKT3_CP_INTERRUPT 0x40 +#define PKT3_SURFACE_SYNC 0x43 +#define PKT3_ME_INITIALIZE 0x44 +#define PKT3_COND_WRITE 0x45 +#define PKT3_EVENT_WRITE 0x46 +#define PKT3_EVENT_WRITE_EOP 0x47 +#define PKT3_ONE_REG_WRITE 0x57 +#define PKT3_SET_CONFIG_REG 0x68 +#define PKT3_SET_CONTEXT_REG 0x69 +#define PKT3_SET_ALU_CONST 0x6A +#define PKT3_SET_BOOL_CONST 0x6B +#define PKT3_SET_LOOP_CONST 0x6C +#define PKT3_SET_RESOURCE 0x6D +#define PKT3_SET_SAMPLER 0x6E +#define PKT3_SET_CTL_CONST 0x6F +#define PKT3_SURFACE_BASE_UPDATE 0x73 + +#define PKT_TYPE_S(x) (((x) & 0x3) << 30) +#define PKT_TYPE_G(x) (((x) >> 30) & 0x3) +#define PKT_TYPE_C 0x3FFFFFFF +#define PKT_COUNT_S(x) (((x) & 0x3FFF) << 16) +#define PKT_COUNT_G(x) (((x) >> 16) & 0x3FFF) +#define PKT_COUNT_C 0xC000FFFF +#define PKT0_BASE_INDEX_S(x) (((x) & 0xFFFF) << 0) +#define PKT0_BASE_INDEX_G(x) (((x) >> 0) & 0xFFFF) +#define PKT0_BASE_INDEX_C 0xFFFF0000 +#define PKT3_IT_OPCODE_S(x) (((x) & 0xFF) << 8) +#define PKT3_IT_OPCODE_G(x) (((x) >> 8) & 0xFF) +#define PKT3_IT_OPCODE_C 0xFFFF00FF +#define PKT0(index, count) (PKT_TYPE_S(0) | PKT0_BASE_INDEX_S(index) | PKT_COUNT_S(count)) +#define PKT3(op, count) (PKT_TYPE_S(3) | PKT3_IT_OPCODE_S(op) | PKT_COUNT_S(count)) + +/* Registers */ +#define R_008C00_SQ_CONFIG 0x00008C00 +#define S_008C00_VC_ENABLE(x) (((x) & 0x1) << 0) +#define G_008C00_VC_ENABLE(x) (((x) >> 0) & 0x1) +#define C_008C00_VC_ENABLE(x) 0xFFFFFFFE +#define S_008C00_EXPORT_SRC_C(x) (((x) & 0x1) << 1) +#define G_008C00_EXPORT_SRC_C(x) (((x) >> 1) & 0x1) +#define C_008C00_EXPORT_SRC_C(x) 0xFFFFFFFD +/* different */ +#define S_008C00_CS_PRIO(x) (((x) & 0x3) << 18) +#define G_008C00_CS_PRIO(x) (((x) >> 18) & 0x3) +#define C_008C00_CS_PRIO(x) 0xFFF3FFFF +#define S_008C00_LS_PRIO(x) (((x) & 0x3) << 20) +#define G_008C00_LS_PRIO(x) (((x) >> 20) & 0x3) +#define C_008C00_LS_PRIO(x) 0xFFCFFFFF +#define S_008C00_HS_PRIO(x) (((x) & 0x3) << 22) +#define G_008C00_HS_PRIO(x) (((x) >> 22) & 0x3) +#define C_008C00_HS_PRIO(x) 0xFF3FFFFF +#define S_008C00_PS_PRIO(x) (((x) & 0x3) << 24) +#define G_008C00_PS_PRIO(x) (((x) >> 24) & 0x3) +#define C_008C00_PS_PRIO(x) 0xFCFFFFFF +#define S_008C00_VS_PRIO(x) (((x) & 0x3) << 26) +#define G_008C00_VS_PRIO(x) (((x) >> 26) & 0x3) +#define C_008C00_VS_PRIO(x) 0xF3FFFFFF +#define S_008C00_GS_PRIO(x) (((x) & 0x3) << 28) +#define G_008C00_GS_PRIO(x) (((x) >> 28) & 0x3) +#define C_008C00_GS_PRIO(x) 0xCFFFFFFF +#define S_008C00_ES_PRIO(x) (((x) & 0x3) << 30) +#define G_008C00_ES_PRIO(x) (((x) >> 30) & 0x3) +#define C_008C00_ES_PRIO(x) 0x3FFFFFFF +#define R_008C04_SQ_GPR_RESOURCE_MGMT_1 0x00008C04 +#define S_008C04_NUM_PS_GPRS(x) (((x) & 0xFF) << 0) +#define G_008C04_NUM_PS_GPRS(x) (((x) >> 0) & 0xFF) +#define C_008C04_NUM_PS_GPRS(x) 0xFFFFFF00 +#define S_008C04_NUM_VS_GPRS(x) (((x) & 0xFF) << 16) +#define G_008C04_NUM_VS_GPRS(x) (((x) >> 16) & 0xFF) +#define C_008C04_NUM_VS_GPRS(x) 0xFF00FFFF +#define S_008C04_NUM_CLAUSE_TEMP_GPRS(x) (((x) & 0xF) << 28) +#define G_008C04_NUM_CLAUSE_TEMP_GPRS(x) (((x) >> 28) & 0xF) +#define C_008C04_NUM_CLAUSE_TEMP_GPRS(x) 0x0FFFFFFF +#define R_008C08_SQ_GPR_RESOURCE_MGMT_2 0x00008C08 +#define S_008C08_NUM_GS_GPRS(x) (((x) & 0xFF) << 0) +#define G_008C08_NUM_GS_GPRS(x) (((x) >> 0) & 0xFF) +#define C_008C08_NUM_GS_GPRS(x) 0xFFFFFF00 +#define S_008C08_NUM_ES_GPRS(x) (((x) & 0xFF) << 16) +#define G_008C08_NUM_ES_GPRS(x) (((x) >> 16) & 0xFF) +#define C_008C08_NUM_ES_GPRS(x) 0xFF00FFFF +#define R_008C0C_SQ_GPR_RESOURCE_MGMT_3 0x00008C0C +#define S_008C0C_NUM_HS_GPRS(x) (((x) & 0xFF) << 0) +#define G_008C0C_NUM_HS_GPRS(x) (((x) >> 0) & 0xFF) +#define C_008C0C_NUM_HS_GPRS(x) 0xFFFFFF00 +#define S_008C0C_NUM_LS_GPRS(x) (((x) & 0xFF) << 16) +#define G_008C0C_NUM_LS_GPRS(x) (((x) >> 16) & 0xFF) +#define C_008C0C_NUM_LS_GPRS(x) 0xFF00FFFF +#define R_008C18_SQ_THREAD_RESOURCE_MGMT_1 0x00008C18 +#define S_008C18_NUM_PS_THREADS(x) (((x) & 0xFF) << 0) +#define G_008C18_NUM_PS_THREADS(x) (((x) >> 0) & 0xFF) +#define C_008C18_NUM_PS_THREADS(x) 0xFFFFFF00 +#define S_008C18_NUM_VS_THREADS(x) (((x) & 0xFF) << 8) +#define G_008C18_NUM_VS_THREADS(x) (((x) >> 8) & 0xFF) +#define C_008C18_NUM_VS_THREADS(x) 0xFFFF00FF +#define S_008C18_NUM_GS_THREADS(x) (((x) & 0xFF) << 16) +#define G_008C18_NUM_GS_THREADS(x) (((x) >> 16) & 0xFF) +#define C_008C18_NUM_GS_THREADS(x) 0xFF00FFFF +#define S_008C18_NUM_ES_THREADS(x) (((x) & 0xFF) << 24) +#define G_008C18_NUM_ES_THREADS(x) (((x) >> 24) & 0xFF) +#define C_008C18_NUM_ES_THREADS(x) 0x00FFFFFF +#define R_008C1C_SQ_THREAD_RESOURCE_MGMT_2 0x00008C1C +#define S_008C1C_NUM_HS_THREADS(x) (((x) & 0xFF) << 0) +#define G_008C1C_NUM_HS_THREADS(x) (((x) >> 0) & 0xFF) +#define C_008C1C_NUM_HS_THREADS(x) 0xFFFFFF00 +#define S_008C1C_NUM_LS_THREADS(x) (((x) & 0xFF) << 8) +#define G_008C1C_NUM_LS_THREADS(x) (((x) >> 8) & 0xFF) +#define C_008C1C_NUM_LS_THREADS(x) 0xFFFF00FF +#define R_008C20_SQ_STACK_RESOURCE_MGMT_1 0x00008C20 +#define S_008C20_NUM_PS_STACK_ENTRIES(x) (((x) & 0xFFF) << 0) +#define G_008C20_NUM_PS_STACK_ENTRIES(x) (((x) >> 0) & 0xFFF) +#define C_008C20_NUM_PS_STACK_ENTRIES(x) 0xFFFFF000 +#define S_008C20_NUM_VS_STACK_ENTRIES(x) (((x) & 0xFFF) << 16) +#define G_008C20_NUM_VS_STACK_ENTRIES(x) (((x) >> 16) & 0xFFF) +#define C_008C20_NUM_VS_STACK_ENTRIES(x) 0xF000FFFF +#define R_008C24_SQ_STACK_RESOURCE_MGMT_2 0x00008C24 +#define S_008C24_NUM_GS_STACK_ENTRIES(x) (((x) & 0xFFF) << 0) +#define G_008C24_NUM_GS_STACK_ENTRIES(x) (((x) >> 0) & 0xFFF) +#define C_008C24_NUM_GS_STACK_ENTRIES(x) 0xFFFFF000 +#define S_008C24_NUM_ES_STACK_ENTRIES(x) (((x) & 0xFFF) << 16) +#define G_008C24_NUM_ES_STACK_ENTRIES(x) (((x) >> 16) & 0xFFF) +#define C_008C24_NUM_ES_STACK_ENTRIES(x) 0xF000FFFF +#define R_008C28_SQ_STACK_RESOURCE_MGMT_3 0x00008C28 +#define S_008C28_NUM_HS_STACK_ENTRIES(x) (((x) & 0xFFF) << 0) +#define G_008C28_NUM_HS_STACK_ENTRIES(x) (((x) >> 0) & 0xFFF) +#define C_008C28_NUM_HS_STACK_ENTRIES(x) 0xFFFFF000 +#define S_008C28_NUM_LS_STACK_ENTRIES(x) (((x) & 0xFFF) << 16) +#define G_008C28_NUM_LS_STACK_ENTRIES(x) (((x) >> 16) & 0xFFF) +#define C_008C28_NUM_LS_STACK_ENTRIES(x) 0xF000FFFF + +#define R_008CF0_SQ_MS_FIFO_SIZES 0x00008CF0 +#define S_008CF0_CACHE_FIFO_SIZE(x) (((x) & 0xFF) << 0) +#define G_008CF0_CACHE_FIFO_SIZE(x) (((x) >> 0) & 0xFF) +#define C_008CF0_CACHE_FIFO_SIZE(x) 0xFFFFFF00 +#define S_008CF0_FETCH_FIFO_HIWATER(x) (((x) & 0x1F) << 8) +#define G_008CF0_FETCH_FIFO_HIWATER(x) (((x) >> 8) & 0x1F) +#define C_008CF0_FETCH_FIFO_HIWATER(x) 0xFFFFE0FF +#define S_008CF0_DONE_FIFO_HIWATER(x) (((x) & 0xFF) << 16) +#define G_008CF0_DONE_FIFO_HIWATER(x) (((x) >> 16) & 0xFF) +#define C_008CF0_DONE_FIFO_HIWATER(x) 0xFF00FFFF +#define S_008CF0_ALU_UPDATE_FIFO_HIWATER(x) (((x) & 0x1F) << 24) +#define G_008CF0_ALU_UPDATE_FIFO_HIWATER(x) (((x) >> 24) & 0x1F) +#define C_008CF0_ALU_UPDATE_FIFO_HIWATER(x) 0xE0FFFFFF + +#define R_009100_SPI_CONFIG_CNTL 0x00009100 +#define R_00913C_SPI_CONFIG_CNTL_1 0x0000913C +#define S_00913C_VTX_DONE_DELAY(x) (((x) & 0xF) << 0) +#define G_00913C_VTX_DONE_DELAY(x) (((x) >> 0) & 0xF ) +#define C_00913C_VTX_DONE_DELAY(x) 0xFFFFFFF0 + + +#define R_028C64_CB_COLOR0_PITCH 0x028C64 +#define S_028C64_PITCH_TILE_MAX(x) (((x) & 0x7FF) << 0) +#define G_028C64_PITCH_TILE_MAX(x) (((x) >> 0) & 0x7FF) +#define C_028C64_PITCH_TILE_MAX 0xFFFFF800 +#define R_028C68_CB_COLOR0_SLICE 0x028C68 +#define S_028C68_SLICE_TILE_MAX(x) (((x) & 0x3FFFFF) << 0) +#define G_028C68_SLICE_TILE_MAX(x) (((x) >> 0) & 0x3FFFFF) +#define C_028C68_SLICE_TILE_MAX 0xFFC00000 +#define R_028C70_CB_COLOR0_INFO 0x028C70 +#define S_028C70_ENDIAN(x) (((x) & 0x3) << 0) +#define G_028C70_ENDIAN(x) (((x) >> 0) & 0x3) +#define C_028C70_ENDIAN 0xFFFFFFFC +#define S_028C70_FORMAT(x) (((x) & 0x3F) << 2) +#define G_028C70_FORMAT(x) (((x) >> 2) & 0x3F) +#define C_028C70_FORMAT 0xFFFFFF03 +#define V_028C70_COLOR_INVALID 0x00000000 +#define V_028C70_COLOR_8 0x00000001 +#define V_028C70_COLOR_4_4 0x00000002 +#define V_028C70_COLOR_3_3_2 0x00000003 +#define V_028C70_COLOR_16 0x00000005 +#define V_028C70_COLOR_16_FLOAT 0x00000006 +#define V_028C70_COLOR_8_8 0x00000007 +#define V_028C70_COLOR_5_6_5 0x00000008 +#define V_028C70_COLOR_6_5_5 0x00000009 +#define V_028C70_COLOR_1_5_5_5 0x0000000A +#define V_028C70_COLOR_4_4_4_4 0x0000000B +#define V_028C70_COLOR_5_5_5_1 0x0000000C +#define V_028C70_COLOR_32 0x0000000D +#define V_028C70_COLOR_32_FLOAT 0x0000000E +#define V_028C70_COLOR_16_16 0x0000000F +#define V_028C70_COLOR_16_16_FLOAT 0x00000010 +#define V_028C70_COLOR_8_24 0x00000011 +#define V_028C70_COLOR_8_24_FLOAT 0x00000012 +#define V_028C70_COLOR_24_8 0x00000013 +#define V_028C70_COLOR_24_8_FLOAT 0x00000014 +#define V_028C70_COLOR_10_11_11 0x00000015 +#define V_028C70_COLOR_10_11_11_FLOAT 0x00000016 +#define V_028C70_COLOR_11_11_10 0x00000017 +#define V_028C70_COLOR_11_11_10_FLOAT 0x00000018 +#define V_028C70_COLOR_2_10_10_10 0x00000019 +#define V_028C70_COLOR_8_8_8_8 0x0000001A +#define V_028C70_COLOR_10_10_10_2 0x0000001B +#define V_028C70_COLOR_X24_8_32_FLOAT 0x0000001C +#define V_028C70_COLOR_32_32 0x0000001D +#define V_028C70_COLOR_32_32_FLOAT 0x0000001E +#define V_028C70_COLOR_16_16_16_16 0x0000001F +#define V_028C70_COLOR_16_16_16_16_FLOAT 0x00000020 +#define V_028C70_COLOR_32_32_32_32 0x00000022 +#define V_028C70_COLOR_32_32_32_32_FLOAT 0x00000023 +#define V_028C70_COLOR_32_32_32_FLOAT 0x00000030 +#define S_028C70_ARRAY_MODE(x) (((x) & 0xF) << 8) +#define G_028C70_ARRAY_MODE(x) (((x) >> 8) & 0xF) +#define C_028C70_ARRAY_MODE 0xFFFFF0FF +#define V_028C70_ARRAY_LINEAR_GENERAL 0x00000000 +#define V_028C70_ARRAY_LINEAR_ALIGNED 0x00000001 +#define V_028C70_ARRAY_1D_TILED_THIN1 0x00000002 +#define V_028C70_ARRAY_2D_TILED_THIN1 0x00000004 +#define S_028C70_NUMBER_TYPE(x) (((x) & 0x7) << 12) +#define G_028C70_NUMBER_TYPE(x) (((x) >> 12) & 0x7) +#define C_028C70_NUMBER_TYPE 0xFFFF8FFF +#define V_028C70_NUMBER_UNORM 0x00000000 +#define V_028C70_NUMBER_SNORM 0x00000001 +#define V_028C70_NUMBER_USCALED 0x00000002 +#define V_028C70_NUMBER_SSCALED 0x00000003 +#define V_028C70_NUMBER_UINT 0x00000004 +#define V_028C70_NUMBER_SINT 0x00000005 +#define V_028C70_NUMBER_SRGB 0x00000006 +#define V_028C70_NUMBER_FLOAT 0x00000007 +#define S_028C70_COMP_SWAP(x) (((x) & 0x3) << 15) +#define G_028C70_COMP_SWAP(x) (((x) >> 15) & 0x3) +#define C_028C70_COMP_SWAP 0xFFFE7FFF +#define V_028C70_SWAP_STD 0x00000000 +#define V_028C70_SWAP_ALT 0x00000001 +#define V_028C70_SWAP_STD_REV 0x00000002 +#define V_028C70_SWAP_ALT_REV 0x00000003 +#define S_028C70_FAST_CLEAR(x) (((x) & 0x1) << 17) +#define G_028C70_FAST_CLEAR(x) (((x) >> 17) & 0x1) +#define C_028C70_FAST_CLEAR 0xFFFDFFFF +#define S_028C70_COMPRESSION(x) (((x) & 0x3) << 18) +#define G_028C70_COMPRESSION(x) (((x) >> 18) & 0x3) +#define C_028C70_COMPRESSION 0xFFF3FFFF +#define S_028C70_BLEND_CLAMP(x) (((x) & 0x1) << 19) +#define G_028C70_BLEND_CLAMP(x) (((x) >> 19) & 0x1) +#define C_028C70_BLEND_CLAMP 0xFFF7FFFF +#define S_028C70_BLEND_BYPASS(x) (((x) & 0x1) << 20) +#define G_028C70_BLEND_BYPASS(x) (((x) >> 20) & 0x1) +#define C_028C70_BLEND_BYPASS 0xFFEFFFFF +#define S_028C70_SIMPLE_FLOAT(x) (((x) & 0x1) << 21) +#define G_028C70_SIMPLE_FLOAT(x) (((x) >> 21) & 0x1) +#define C_028C70_SIMPLE_FLOAT 0xFFDFFFFF +#define S_028C70_ROUND_MODE(x) (((x) & 0x1) << 22) +#define G_028C70_ROUND_MODE(x) (((x) >> 22) & 0x1) +#define C_028C70_ROUND_MODE 0xFFBFFFFF +#define S_028C70_TILE_COMPACT(x) (((x) & 0x1) << 23) +#define G_028C70_TILE_COMPACT(x) (((x) >> 23) & 0x1) +#define C_028C70_TILE_COMPACT 0xFF7FFFFF +#define S_028C70_SOURCE_FORMAT(x) (((x) & 0x3) << 24) +#define G_028C70_SOURCE_FORMAT(x) (((x) >> 24) & 0x3) +#define C_028C70_SOURCE_FORMAT 0xFCFFFFFF +#define S_028C70_RAT(x) (((x) & 0x1) << 26) +#define G_028C70_RAT(x) (((x) >> 26) & 0x1) +#define C_028C70_RAT 0xFBFFFFFF +#define S_028C70_RESOURCE_TYPE(x) (((x) & 0x7) << 27) +#define G_028C70_RESOURCE_TYPE(x) (((x) >> 27) & 0x7) +#define C_028C70_RESOURCE_TYPE 0xC7FFFFFF + +#define R_028C74_CB_COLOR0_ATTRIB 0x028C74 +#define S_028C74_NON_DISP_TILING_ORDER(x) (((x) & 0x1) << 4) +#define G_028C74_NON_DISP_TILING_ORDER(x) (((x) >> 4) & 0x1) +#define C_028C74_NON_DISP_TILING_ORDER 0xFFFFFFEF + +#define R_028C78_CB_COLOR0_DIM 0x028C78 +#define S_028C78_WIDTH_MAX(x) (((x) & 0xFFFF) << 0) +#define G_028C78_WIDTH_MAX(x) (((x) >> 0) & 0xFFFF) +#define C_028C78_WIDTH_MAX 0xFFFF0000 +#define S_028C78_HEIGHT_MAX(x) (((x) & 0xFFFF) << 16) +#define G_028C78_HEIGHT_MAX(x) (((x) >> 16) & 0xFFFF) +#define C_028C78_HEIGHT_MAX 0x0000FFFF + +#define R_028C7C_CB_COLOR0_CMASK 0x028C7C +#define R_028C80_CB_COLOR0_CMASK_SLICE 0x028C80 +#define R_028C84_CB_COLOR0_FMASK 0x028C84 +#define R_028C88_CB_COLOR0_FMASK_SLICE 0x028C88 + +#define R_028C8C_CB_COLOR0_CLEAR_WORD0 0x028C8C +#define R_028C90_CB_COLOR0_CLEAR_WORD1 0x028C90 +#define R_028C94_CB_COLOR0_CLEAR_WORD2 0x028C94 +#define R_028C98_CB_COLOR0_CLEAR_WORD3 0x028C98 + +/* alpha same */ +#define R_028410_SX_ALPHA_TEST_CONTROL 0x028410 +#define S_028410_ALPHA_FUNC(x) (((x) & 0x7) << 0) +#define G_028410_ALPHA_FUNC(x) (((x) >> 0) & 0x7) +#define C_028410_ALPHA_FUNC 0xFFFFFFF8 +#define S_028410_ALPHA_TEST_ENABLE(x) (((x) & 0x1) << 3) +#define G_028410_ALPHA_TEST_ENABLE(x) (((x) >> 3) & 0x1) +#define C_028410_ALPHA_TEST_ENABLE 0xFFFFFFF7 +#define S_028410_ALPHA_TEST_BYPASS(x) (((x) & 0x1) << 8) +#define G_028410_ALPHA_TEST_BYPASS(x) (((x) >> 8) & 0x1) +#define C_028410_ALPHA_TEST_BYPASS 0xFFFFFEFF + +#define R_028800_DB_DEPTH_CONTROL 0x028800 +#define S_028800_STENCIL_ENABLE(x) (((x) & 0x1) << 0) +#define G_028800_STENCIL_ENABLE(x) (((x) >> 0) & 0x1) +#define C_028800_STENCIL_ENABLE 0xFFFFFFFE +#define S_028800_Z_ENABLE(x) (((x) & 0x1) << 1) +#define G_028800_Z_ENABLE(x) (((x) >> 1) & 0x1) +#define C_028800_Z_ENABLE 0xFFFFFFFD +#define S_028800_Z_WRITE_ENABLE(x) (((x) & 0x1) << 2) +#define G_028800_Z_WRITE_ENABLE(x) (((x) >> 2) & 0x1) +#define C_028800_Z_WRITE_ENABLE 0xFFFFFFFB +#define S_028800_ZFUNC(x) (((x) & 0x7) << 4) +#define G_028800_ZFUNC(x) (((x) >> 4) & 0x7) +#define C_028800_ZFUNC 0xFFFFFF8F +#define S_028800_BACKFACE_ENABLE(x) (((x) & 0x1) << 7) +#define G_028800_BACKFACE_ENABLE(x) (((x) >> 7) & 0x1) +#define C_028800_BACKFACE_ENABLE 0xFFFFFF7F +#define S_028800_STENCILFUNC(x) (((x) & 0x7) << 8) +#define G_028800_STENCILFUNC(x) (((x) >> 8) & 0x7) +#define C_028800_STENCILFUNC 0xFFFFF8FF +#define V_028800_STENCILFUNC_NEVER 0x00000000 +#define V_028800_STENCILFUNC_LESS 0x00000001 +#define V_028800_STENCILFUNC_EQUAL 0x00000002 +#define V_028800_STENCILFUNC_LEQUAL 0x00000003 +#define V_028800_STENCILFUNC_GREATER 0x00000004 +#define V_028800_STENCILFUNC_NOTEQUAL 0x00000005 +#define V_028800_STENCILFUNC_GEQUAL 0x00000006 +#define V_028800_STENCILFUNC_ALWAYS 0x00000007 +#define S_028800_STENCILFAIL(x) (((x) & 0x7) << 11) +#define G_028800_STENCILFAIL(x) (((x) >> 11) & 0x7) +#define C_028800_STENCILFAIL 0xFFFFC7FF +#define V_028800_STENCIL_KEEP 0x00000000 +#define V_028800_STENCIL_ZERO 0x00000001 +#define V_028800_STENCIL_REPLACE 0x00000002 +#define V_028800_STENCIL_INCR 0x00000003 +#define V_028800_STENCIL_DECR 0x00000004 +#define V_028800_STENCIL_INVERT 0x00000005 +#define V_028800_STENCIL_INCR_WRAP 0x00000006 +#define V_028800_STENCIL_DECR_WRAP 0x00000007 +#define S_028800_STENCILZPASS(x) (((x) & 0x7) << 14) +#define G_028800_STENCILZPASS(x) (((x) >> 14) & 0x7) +#define C_028800_STENCILZPASS 0xFFFE3FFF +#define S_028800_STENCILZFAIL(x) (((x) & 0x7) << 17) +#define G_028800_STENCILZFAIL(x) (((x) >> 17) & 0x7) +#define C_028800_STENCILZFAIL 0xFFF1FFFF +#define S_028800_STENCILFUNC_BF(x) (((x) & 0x7) << 20) +#define G_028800_STENCILFUNC_BF(x) (((x) >> 20) & 0x7) +#define C_028800_STENCILFUNC_BF 0xFF8FFFFF +#define S_028800_STENCILFAIL_BF(x) (((x) & 0x7) << 23) +#define G_028800_STENCILFAIL_BF(x) (((x) >> 23) & 0x7) +#define C_028800_STENCILFAIL_BF 0xFC7FFFFF +#define S_028800_STENCILZPASS_BF(x) (((x) & 0x7) << 26) +#define G_028800_STENCILZPASS_BF(x) (((x) >> 26) & 0x7) +#define C_028800_STENCILZPASS_BF 0xE3FFFFFF +#define S_028800_STENCILZFAIL_BF(x) (((x) & 0x7) << 29) +#define G_028800_STENCILZFAIL_BF(x) (((x) >> 29) & 0x7) +#define C_028800_STENCILZFAIL_BF 0x1FFFFFFF + +#define R_028808_CB_COLOR_CONTROL 0x028808 +#define S_028808_FOG_ENABLE(x) (((x) & 0x1) << 0) +#define G_028808_FOG_ENABLE(x) (((x) >> 0) & 0x1) +#define C_028808_FOG_ENABLE 0xFFFFFFFE +#define S_028808_MULTIWRITE_ENABLE(x) (((x) & 0x1) << 1) +#define G_028808_MULTIWRITE_ENABLE(x) (((x) >> 1) & 0x1) +#define C_028808_MULTIWRITE_ENABLE 0xFFFFFFFD +#define S_028808_DITHER_ENABLE(x) (((x) & 0x1) << 2) +#define G_028808_DITHER_ENABLE(x) (((x) >> 2) & 0x1) +#define C_028808_DITHER_ENABLE 0xFFFFFFFB +#define S_028808_DEGAMMA_ENABLE(x) (((x) & 0x1) << 3) +#define G_028808_DEGAMMA_ENABLE(x) (((x) >> 3) & 0x1) +#define C_028808_DEGAMMA_ENABLE 0xFFFFFFF7 +#define S_028808_MODE(x) (((x) & 0x7) << 4) +#define G_028808_MODE(x) (((x) >> 4) & 0x7) +#define C_028808_MODE 0xFFFFFF8F +#define S_028808_ROP3(x) (((x) & 0xFF) << 16) +#define G_028808_ROP3(x) (((x) >> 16) & 0xFF) +#define C_028808_ROP3 0xFF00FFFF +#define R_028810_PA_CL_CLIP_CNTL 0x028810 +#define S_028810_UCP_ENA_0(x) (((x) & 0x1) << 0) +#define G_028810_UCP_ENA_0(x) (((x) >> 0) & 0x1) +#define C_028810_UCP_ENA_0 0xFFFFFFFE +#define S_028810_UCP_ENA_1(x) (((x) & 0x1) << 1) +#define G_028810_UCP_ENA_1(x) (((x) >> 1) & 0x1) +#define C_028810_UCP_ENA_1 0xFFFFFFFD +#define S_028810_UCP_ENA_2(x) (((x) & 0x1) << 2) +#define G_028810_UCP_ENA_2(x) (((x) >> 2) & 0x1) +#define C_028810_UCP_ENA_2 0xFFFFFFFB +#define S_028810_UCP_ENA_3(x) (((x) & 0x1) << 3) +#define G_028810_UCP_ENA_3(x) (((x) >> 3) & 0x1) +#define C_028810_UCP_ENA_3 0xFFFFFFF7 +#define S_028810_UCP_ENA_4(x) (((x) & 0x1) << 4) +#define G_028810_UCP_ENA_4(x) (((x) >> 4) & 0x1) +#define C_028810_UCP_ENA_4 0xFFFFFFEF +#define S_028810_UCP_ENA_5(x) (((x) & 0x1) << 5) +#define G_028810_UCP_ENA_5(x) (((x) >> 5) & 0x1) +#define C_028810_UCP_ENA_5 0xFFFFFFDF +#define S_028810_PS_UCP_Y_SCALE_NEG(x) (((x) & 0x1) << 13) +#define G_028810_PS_UCP_Y_SCALE_NEG(x) (((x) >> 13) & 0x1) +#define C_028810_PS_UCP_Y_SCALE_NEG 0xFFFFDFFF +#define S_028810_PS_UCP_MODE(x) (((x) & 0x3) << 14) +#define G_028810_PS_UCP_MODE(x) (((x) >> 14) & 0x3) +#define C_028810_PS_UCP_MODE 0xFFFF3FFF +#define S_028810_CLIP_DISABLE(x) (((x) & 0x1) << 16) +#define G_028810_CLIP_DISABLE(x) (((x) >> 16) & 0x1) +#define C_028810_CLIP_DISABLE 0xFFFEFFFF +#define S_028810_UCP_CULL_ONLY_ENA(x) (((x) & 0x1) << 17) +#define G_028810_UCP_CULL_ONLY_ENA(x) (((x) >> 17) & 0x1) +#define C_028810_UCP_CULL_ONLY_ENA 0xFFFDFFFF +#define S_028810_BOUNDARY_EDGE_FLAG_ENA(x) (((x) & 0x1) << 18) +#define G_028810_BOUNDARY_EDGE_FLAG_ENA(x) (((x) >> 18) & 0x1) +#define C_028810_BOUNDARY_EDGE_FLAG_ENA 0xFFFBFFFF +#define S_028810_DX_CLIP_SPACE_DEF(x) (((x) & 0x1) << 19) +#define G_028810_DX_CLIP_SPACE_DEF(x) (((x) >> 19) & 0x1) +#define C_028810_DX_CLIP_SPACE_DEF 0xFFF7FFFF +#define S_028810_DIS_CLIP_ERR_DETECT(x) (((x) & 0x1) << 20) +#define G_028810_DIS_CLIP_ERR_DETECT(x) (((x) >> 20) & 0x1) +#define C_028810_DIS_CLIP_ERR_DETECT 0xFFEFFFFF +#define S_028810_VTX_KILL_OR(x) (((x) & 0x1) << 21) +#define G_028810_VTX_KILL_OR(x) (((x) >> 21) & 0x1) +#define C_028810_VTX_KILL_OR 0xFFDFFFFF +#define S_028810_DX_LINEAR_ATTR_CLIP_ENA(x) (((x) & 0x1) << 24) +#define G_028810_DX_LINEAR_ATTR_CLIP_ENA(x) (((x) >> 24) & 0x1) +#define C_028810_DX_LINEAR_ATTR_CLIP_ENA 0xFEFFFFFF +#define S_028810_VTE_VPORT_PROVOKE_DISABLE(x) (((x) & 0x1) << 25) +#define G_028810_VTE_VPORT_PROVOKE_DISABLE(x) (((x) >> 25) & 0x1) +#define C_028810_VTE_VPORT_PROVOKE_DISABLE 0xFDFFFFFF +#define S_028810_ZCLIP_NEAR_DISABLE(x) (((x) & 0x1) << 26) +#define G_028810_ZCLIP_NEAR_DISABLE(x) (((x) >> 26) & 0x1) +#define C_028810_ZCLIP_NEAR_DISABLE 0xFBFFFFFF +#define S_028810_ZCLIP_FAR_DISABLE(x) (((x) & 0x1) << 27) +#define G_028810_ZCLIP_FAR_DISABLE(x) (((x) >> 27) & 0x1) +#define C_028810_ZCLIP_FAR_DISABLE 0xF7FFFFFF + +#define R_028040_DB_Z_INFO 0x028040 +#define S_028040_FORMAT(x) (((x) & 0x3) << 0) +#define G_028040_FORMAT(x) (((x) >> 0) & 0x3) +#define C_028040_FORMAT 0xFFFFFFFC +#define V_028040_Z_INVALID 0x00000000 +#define V_028040_Z_16 0x00000001 +#define V_028040_Z_24 0x00000002 +#define V_028040_Z_32_FLOAT 0x00000003 +#define S_028040_ARRAY_MODE(x) (((x) & 0xF) << 4) +#define G_028040_ARRAY_MODE(x) (((x) >> 4) & 0xF) +#define C_028040_ARRAY_MODE 0xFFFFFF0F +#define S_028040_READ_SIZE(x) (((x) & 0x1) << 28) +#define G_028040_READ_SIZE(x) (((x) >> 28) & 0x1) +#define C_028040_READ_SIZE 0xEFFFFFFF +#define S_028040_TILE_SURFACE_ENABLE(x) (((x) & 0x1) << 29) +#define G_028040_TILE_SURFACE_ENABLE(x) (((x) >> 29) & 0x1) +#define C_028040_TILE_SURFACE_ENABLE 0xDFFFFFFF +#define S_028040_ZRANGE_PRECISION(x) (((x) & 0x1) << 31) +#define G_028040_ZRANGE_PRECISION(x) (((x) >> 31) & 0x1) +#define C_028040_ZRANGE_PRECISION 0x7FFFFFFF + +#define R_028044_DB_STENCIL_INFO 0x028044 +#define S_028044_FORMAT(x) (((x) & 0x1) << 0) +#define G_028044_FORMAT(x) (((x) >> 0) & 0x1) +#define C_028044_FORMAT 0xFFFFFFFE + +#define R_028058_DB_DEPTH_SIZE 0x028058 +#define S_028058_PITCH_TILE_MAX(x) (((x) & 0x7FF) << 0) +#define G_028058_PITCH_TILE_MAX(x) (((x) >> 0) & 0x7FF) +#define C_028058_PITCH_TILE_MAX 0xFFFFF800 +#define S_028058_HEIGHT_TILE_MAX(x) (((x) & 0x7FF) << 11) +#define G_028058_HEIGHT_TILE_MAX(x) (((x) >> 11) & 0x7FF) +#define C_028058_HEIGHT_TILE_MAX 0xFFC007FF + +#define R_02805C_DB_DEPTH_SLICE 0x02805C +#define S_02805C_SLICE_TILE_MAX(x) (((x) & 0x3FFFFF) << 0) +#define G_02805C_SLICE_TILE_MAX(x) (((x) >> 0) & 0x3FFFFF) +#define C_02805C_SLICE_TILE_MAX 0xFFC00000 + +#define R_028430_DB_STENCILREFMASK 0x028430 +#define S_028430_STENCILREF(x) (((x) & 0xFF) << 0) +#define G_028430_STENCILREF(x) (((x) >> 0) & 0xFF) +#define C_028430_STENCILREF 0xFFFFFF00 +#define S_028430_STENCILMASK(x) (((x) & 0xFF) << 8) +#define G_028430_STENCILMASK(x) (((x) >> 8) & 0xFF) +#define C_028430_STENCILMASK 0xFFFF00FF +#define S_028430_STENCILWRITEMASK(x) (((x) & 0xFF) << 16) +#define G_028430_STENCILWRITEMASK(x) (((x) >> 16) & 0xFF) +#define C_028430_STENCILWRITEMASK 0xFF00FFFF +#define R_028434_DB_STENCILREFMASK_BF 0x028434 +#define S_028434_STENCILREF_BF(x) (((x) & 0xFF) << 0) +#define G_028434_STENCILREF_BF(x) (((x) >> 0) & 0xFF) +#define C_028434_STENCILREF_BF 0xFFFFFF00 +#define S_028434_STENCILMASK_BF(x) (((x) & 0xFF) << 8) +#define G_028434_STENCILMASK_BF(x) (((x) >> 8) & 0xFF) +#define C_028434_STENCILMASK_BF 0xFFFF00FF +#define S_028434_STENCILWRITEMASK_BF(x) (((x) & 0xFF) << 16) +#define G_028434_STENCILWRITEMASK_BF(x) (((x) >> 16) & 0xFF) +#define C_028434_STENCILWRITEMASK_BF 0xFF00FFFF +#define R_028780_CB_BLEND_CONTROL 0x028780 +#define S_028780_COLOR_SRCBLEND(x) (((x) & 0x1F) << 0) +#define G_028780_COLOR_SRCBLEND(x) (((x) >> 0) & 0x1F) +#define C_028780_COLOR_SRCBLEND 0xFFFFFFE0 +#define V_028780_BLEND_ZERO 0x00000000 +#define V_028780_BLEND_ONE 0x00000001 +#define V_028780_BLEND_SRC_COLOR 0x00000002 +#define V_028780_BLEND_ONE_MINUS_SRC_COLOR 0x00000003 +#define V_028780_BLEND_SRC_ALPHA 0x00000004 +#define V_028780_BLEND_ONE_MINUS_SRC_ALPHA 0x00000005 +#define V_028780_BLEND_DST_ALPHA 0x00000006 +#define V_028780_BLEND_ONE_MINUS_DST_ALPHA 0x00000007 +#define V_028780_BLEND_DST_COLOR 0x00000008 +#define V_028780_BLEND_ONE_MINUS_DST_COLOR 0x00000009 +#define V_028780_BLEND_SRC_ALPHA_SATURATE 0x0000000A +#define V_028780_BLEND_BOTH_SRC_ALPHA 0x0000000B +#define V_028780_BLEND_BOTH_INV_SRC_ALPHA 0x0000000C +#define V_028780_BLEND_CONST_COLOR 0x0000000D +#define V_028780_BLEND_ONE_MINUS_CONST_COLOR 0x0000000E +#define V_028780_BLEND_SRC1_COLOR 0x0000000F +#define V_028780_BLEND_INV_SRC1_COLOR 0x00000010 +#define V_028780_BLEND_SRC1_ALPHA 0x00000011 +#define V_028780_BLEND_INV_SRC1_ALPHA 0x00000012 +#define V_028780_BLEND_CONST_ALPHA 0x00000013 +#define V_028780_BLEND_ONE_MINUS_CONST_ALPHA 0x00000014 +#define S_028780_COLOR_COMB_FCN(x) (((x) & 0x7) << 5) +#define G_028780_COLOR_COMB_FCN(x) (((x) >> 5) & 0x7) +#define C_028780_COLOR_COMB_FCN 0xFFFFFF1F +#define V_028780_COMB_DST_PLUS_SRC 0x00000000 +#define V_028780_COMB_SRC_MINUS_DST 0x00000001 +#define V_028780_COMB_MIN_DST_SRC 0x00000002 +#define V_028780_COMB_MAX_DST_SRC 0x00000003 +#define V_028780_COMB_DST_MINUS_SRC 0x00000004 +#define S_028780_COLOR_DESTBLEND(x) (((x) & 0x1F) << 8) +#define G_028780_COLOR_DESTBLEND(x) (((x) >> 8) & 0x1F) +#define C_028780_COLOR_DESTBLEND 0xFFFFE0FF +#define S_028780_OPACITY_WEIGHT(x) (((x) & 0x1) << 13) +#define G_028780_OPACITY_WEIGHT(x) (((x) >> 13) & 0x1) +#define C_028780_OPACITY_WEIGHT 0xFFFFDFFF +#define S_028780_ALPHA_SRCBLEND(x) (((x) & 0x1F) << 16) +#define G_028780_ALPHA_SRCBLEND(x) (((x) >> 16) & 0x1F) +#define C_028780_ALPHA_SRCBLEND 0xFFE0FFFF +#define S_028780_ALPHA_COMB_FCN(x) (((x) & 0x7) << 21) +#define G_028780_ALPHA_COMB_FCN(x) (((x) >> 21) & 0x7) +#define C_028780_ALPHA_COMB_FCN 0xFF1FFFFF +#define S_028780_ALPHA_DESTBLEND(x) (((x) & 0x1F) << 24) +#define G_028780_ALPHA_DESTBLEND(x) (((x) >> 24) & 0x1F) +#define C_028780_ALPHA_DESTBLEND 0xE0FFFFFF +#define S_028780_SEPARATE_ALPHA_BLEND(x) (((x) & 0x1) << 29) +#define G_028780_SEPARATE_ALPHA_BLEND(x) (((x) >> 29) & 0x1) +#define C_028780_SEPARATE_ALPHA_BLEND 0xDFFFFFFF +#define S_028780_BLEND_CONTROL_ENABLE(x) (((x) & 0x1) << 30) +#define G_028780_BLEND_CONTROL_ENABLE(x) (((x) >> 30) & 0x1) +#define C_028780_BLEND_CONTROL_ENABLE 0xEFFFFFFF +#define R_028814_PA_SU_SC_MODE_CNTL 0x028814 +#define S_028814_CULL_FRONT(x) (((x) & 0x1) << 0) +#define G_028814_CULL_FRONT(x) (((x) >> 0) & 0x1) +#define C_028814_CULL_FRONT 0xFFFFFFFE +#define S_028814_CULL_BACK(x) (((x) & 0x1) << 1) +#define G_028814_CULL_BACK(x) (((x) >> 1) & 0x1) +#define C_028814_CULL_BACK 0xFFFFFFFD +#define S_028814_FACE(x) (((x) & 0x1) << 2) +#define G_028814_FACE(x) (((x) >> 2) & 0x1) +#define C_028814_FACE 0xFFFFFFFB +#define S_028814_POLY_MODE(x) (((x) & 0x3) << 3) +#define G_028814_POLY_MODE(x) (((x) >> 3) & 0x3) +#define C_028814_POLY_MODE 0xFFFFFFE7 +#define S_028814_POLYMODE_FRONT_PTYPE(x) (((x) & 0x7) << 5) +#define G_028814_POLYMODE_FRONT_PTYPE(x) (((x) >> 5) & 0x7) +#define C_028814_POLYMODE_FRONT_PTYPE 0xFFFFFF1F +#define S_028814_POLYMODE_BACK_PTYPE(x) (((x) & 0x7) << 8) +#define G_028814_POLYMODE_BACK_PTYPE(x) (((x) >> 8) & 0x7) +#define C_028814_POLYMODE_BACK_PTYPE 0xFFFFF8FF +#define S_028814_POLY_OFFSET_FRONT_ENABLE(x) (((x) & 0x1) << 11) +#define G_028814_POLY_OFFSET_FRONT_ENABLE(x) (((x) >> 11) & 0x1) +#define C_028814_POLY_OFFSET_FRONT_ENABLE 0xFFFFF7FF +#define S_028814_POLY_OFFSET_BACK_ENABLE(x) (((x) & 0x1) << 12) +#define G_028814_POLY_OFFSET_BACK_ENABLE(x) (((x) >> 12) & 0x1) +#define C_028814_POLY_OFFSET_BACK_ENABLE 0xFFFFEFFF +#define S_028814_POLY_OFFSET_PARA_ENABLE(x) (((x) & 0x1) << 13) +#define G_028814_POLY_OFFSET_PARA_ENABLE(x) (((x) >> 13) & 0x1) +#define C_028814_POLY_OFFSET_PARA_ENABLE 0xFFFFDFFF +#define S_028814_VTX_WINDOW_OFFSET_ENABLE(x) (((x) & 0x1) << 16) +#define G_028814_VTX_WINDOW_OFFSET_ENABLE(x) (((x) >> 16) & 0x1) +#define C_028814_VTX_WINDOW_OFFSET_ENABLE 0xFFFEFFFF +#define S_028814_PROVOKING_VTX_LAST(x) (((x) & 0x1) << 19) +#define G_028814_PROVOKING_VTX_LAST(x) (((x) >> 19) & 0x1) +#define C_028814_PROVOKING_VTX_LAST 0xFFF7FFFF +#define S_028814_PERSP_CORR_DIS(x) (((x) & 0x1) << 20) +#define G_028814_PERSP_CORR_DIS(x) (((x) >> 20) & 0x1) +#define C_028814_PERSP_CORR_DIS 0xFFEFFFFF +#define S_028814_MULTI_PRIM_IB_ENA(x) (((x) & 0x1) << 21) +#define G_028814_MULTI_PRIM_IB_ENA(x) (((x) >> 21) & 0x1) +#define C_028814_MULTI_PRIM_IB_ENA 0xFFDFFFFF + +#define R_028004_DB_DEPTH_VIEW 0x028004 +#define S_028004_SLICE_START(x) (((x) & 0x7FF) << 0) +#define G_028004_SLICE_START(x) (((x) >> 0) & 0x7FF) +#define C_028004_SLICE_START 0xFFFFF800 +#define S_028004_SLICE_MAX(x) (((x) & 0x7FF) << 13) +#define G_028004_SLICE_MAX(x) (((x) >> 13) & 0x7FF) +#define C_028004_SLICE_MAX 0xFF001FFF +#define R_028D24_DB_HTILE_SURFACE 0x028D24 +#define S_028D24_HTILE_WIDTH(x) (((x) & 0x1) << 0) +#define G_028D24_HTILE_WIDTH(x) (((x) >> 0) & 0x1) +#define C_028D24_HTILE_WIDTH 0xFFFFFFFE +#define S_028D24_HTILE_HEIGHT(x) (((x) & 0x1) << 1) +#define G_028D24_HTILE_HEIGHT(x) (((x) >> 1) & 0x1) +#define C_028D24_HTILE_HEIGHT 0xFFFFFFFD +#define S_028D24_LINEAR(x) (((x) & 0x1) << 2) +#define G_028D24_LINEAR(x) (((x) >> 2) & 0x1) +#define C_028D24_LINEAR 0xFFFFFFFB +#define S_028D24_FULL_CACHE(x) (((x) & 0x1) << 3) +#define G_028D24_FULL_CACHE(x) (((x) >> 3) & 0x1) +#define C_028D24_FULL_CACHE 0xFFFFFFF7 +#define S_028D24_HTILE_USES_PRELOAD_WIN(x) (((x) & 0x1) << 4) +#define G_028D24_HTILE_USES_PRELOAD_WIN(x) (((x) >> 4) & 0x1) +#define C_028D24_HTILE_USES_PRELOAD_WIN 0xFFFFFFEF +#define S_028D24_PRELOAD(x) (((x) & 0x1) << 5) +#define G_028D24_PRELOAD(x) (((x) >> 5) & 0x1) +#define C_028D24_PRELOAD 0xFFFFFFDF +#define S_028D24_PREFETCH_WIDTH(x) (((x) & 0x3F) << 6) +#define G_028D24_PREFETCH_WIDTH(x) (((x) >> 6) & 0x3F) +#define C_028D24_PREFETCH_WIDTH 0xFFFFF03F +#define S_028D24_PREFETCH_HEIGHT(x) (((x) & 0x3F) << 12) +#define G_028D24_PREFETCH_HEIGHT(x) (((x) >> 12) & 0x3F) +#define C_028D24_PREFETCH_HEIGHT 0xFFFC0FFF +#define R_028D34_DB_PREFETCH_LIMIT 0x028D34 +#define S_028D34_DEPTH_HEIGHT_TILE_MAX(x) (((x) & 0x3FF) << 0) +#define G_028D34_DEPTH_HEIGHT_TILE_MAX(x) (((x) >> 0) & 0x3FF) +#define C_028D34_DEPTH_HEIGHT_TILE_MAX 0xFFFFFC00 +#define R_02880C_DB_SHADER_CONTROL 0x02880C +#define S_02880C_Z_EXPORT_ENABLE(x) (((x) & 0x1) << 0) +#define G_02880C_Z_EXPORT_ENABLE(x) (((x) >> 0) & 0x1) +#define C_02880C_Z_EXPORT_ENABLE 0xFFFFFFFE +#define S_02880C_STENCIL_EXPORT_ENABLE(x) (((x) & 0x1) << 1) +#define G_02880C_STENCIL_EXPORT_ENABLE(x) (((x) >> 1) & 0x1) +#define C_02880C_STENCIL_EXPORT_ENABLE 0xFFFFFFFD +#define S_02880C_Z_ORDER(x) (((x) & 0x3) << 4) +#define G_02880C_Z_ORDER(x) (((x) >> 4) & 0x3) +#define C_02880C_Z_ORDER 0xFFFFFCFF +#define V_02880C_LATE_Z 0 +#define V_02880C_EARLY_Z_THEN_LATE_Z 1 +#define V_02880C_RE_Z 2 +#define V_02880C_EARLY_Z_THEN_RE_Z 3 +#define S_02880C_KILL_ENABLE(x) (((x) & 0x1) << 6) +#define G_02880C_KILL_ENABLE(x) (((x) >> 6) & 0x1) +#define C_02880C_KILL_ENABLE 0xFFFFFFBF +#define S_02880C_DUAL_EXPORT_ENABLE(x) (((x) & 0x1) << 9) +#define G_02880C_DUAL_EXPORT_ENABLE(x) (((x) >> 9) & 0x1) +#define C_02880C_DUAL_EXPORT_ENABLE 0xFFFFFDFF +#define R_028A00_PA_SU_POINT_SIZE 0x028A00 +#define S_028A00_HEIGHT(x) (((x) & 0xFFFF) << 0) +#define G_028A00_HEIGHT(x) (((x) >> 0) & 0xFFFF) +#define C_028A00_HEIGHT 0xFFFF0000 +#define S_028A00_WIDTH(x) (((x) & 0xFFFF) << 16) +#define G_028A00_WIDTH(x) (((x) >> 16) & 0xFFFF) +#define C_028A00_WIDTH 0x0000FFFF +#define R_028A40_VGT_GS_MODE 0x028A40 +#define S_028A40_MODE(x) (((x) & 0x3) << 0) +#define G_028A40_MODE(x) (((x) >> 0) & 0x3) +#define C_028A40_MODE 0xFFFFFFFC +#define S_028A40_ES_PASSTHRU(x) (((x) & 0x1) << 2) +#define G_028A40_ES_PASSTHRU(x) (((x) >> 2) & 0x1) +#define C_028A40_ES_PASSTHRU 0xFFFFFFFB +#define S_028A40_CUT_MODE(x) (((x) & 0x3) << 3) +#define G_028A40_CUT_MODE(x) (((x) >> 3) & 0x3) +#define C_028A40_CUT_MODE 0xFFFFFFE7 +#define R_008040_WAIT_UNTIL 0x008040 +#define S_008040_WAIT_CP_DMA_IDLE(x) (((x) & 0x1) << 8) +#define G_008040_WAIT_CP_DMA_IDLE(x) (((x) >> 8) & 0x1) +#define C_008040_WAIT_CP_DMA_IDLE 0xFFFFFEFF +#define S_008040_WAIT_CMDFIFO(x) (((x) & 0x1) << 10) +#define G_008040_WAIT_CMDFIFO(x) (((x) >> 10) & 0x1) +#define C_008040_WAIT_CMDFIFO 0xFFFFFBFF +#define S_008040_WAIT_2D_IDLE(x) (((x) & 0x1) << 14) +#define G_008040_WAIT_2D_IDLE(x) (((x) >> 14) & 0x1) +#define C_008040_WAIT_2D_IDLE 0xFFFFBFFF +#define S_008040_WAIT_3D_IDLE(x) (((x) & 0x1) << 15) +#define G_008040_WAIT_3D_IDLE(x) (((x) >> 15) & 0x1) +#define C_008040_WAIT_3D_IDLE 0xFFFF7FFF +#define S_008040_WAIT_2D_IDLECLEAN(x) (((x) & 0x1) << 16) +#define G_008040_WAIT_2D_IDLECLEAN(x) (((x) >> 16) & 0x1) +#define C_008040_WAIT_2D_IDLECLEAN 0xFFFEFFFF +#define S_008040_WAIT_3D_IDLECLEAN(x) (((x) & 0x1) << 17) +#define G_008040_WAIT_3D_IDLECLEAN(x) (((x) >> 17) & 0x1) +#define C_008040_WAIT_3D_IDLECLEAN 0xFFFDFFFF +#define S_008040_WAIT_EXTERN_SIG(x) (((x) & 0x1) << 19) +#define G_008040_WAIT_EXTERN_SIG(x) (((x) >> 19) & 0x1) +#define C_008040_WAIT_EXTERN_SIG 0xFFF7FFFF +#define S_008040_CMDFIFO_ENTRIES(x) (((x) & 0x1F) << 20) +#define G_008040_CMDFIFO_ENTRIES(x) (((x) >> 20) & 0x1F) +#define C_008040_CMDFIFO_ENTRIES 0xFE0FFFFF + +/* diff */ +#define R_0286CC_SPI_PS_IN_CONTROL_0 0x0286CC +#define S_0286CC_NUM_INTERP(x) (((x) & 0x3F) << 0) +#define G_0286CC_NUM_INTERP(x) (((x) >> 0) & 0x3F) +#define C_0286CC_NUM_INTERP 0xFFFFFFC0 +#define S_0286CC_POSITION_ENA(x) (((x) & 0x1) << 8) +#define G_0286CC_POSITION_ENA(x) (((x) >> 8) & 0x1) +#define C_0286CC_POSITION_ENA 0xFFFFFEFF +#define S_0286CC_POSITION_CENTROID(x) (((x) & 0x1) << 9) +#define G_0286CC_POSITION_CENTROID(x) (((x) >> 9) & 0x1) +#define C_0286CC_POSITION_CENTROID 0xFFFFFDFF +#define S_0286CC_POSITION_ADDR(x) (((x) & 0x1F) << 10) +#define G_0286CC_POSITION_ADDR(x) (((x) >> 10) & 0x1F) +#define C_0286CC_POSITION_ADDR 0xFFFF83FF +#define S_0286CC_PARAM_GEN(x) (((x) & 0xF) << 15) +#define G_0286CC_PARAM_GEN(x) (((x) >> 15) & 0xF) +#define C_0286CC_PARAM_GEN 0xFFF87FFF +#define S_0286CC_PERSP_GRADIENT_ENA(x) (((x) & 0x1) << 28) +#define G_0286CC_PERSP_GRADIENT_ENA(x) (((x) >> 28) & 0x1) +#define C_0286CC_PERSP_GRADIENT_ENA 0xEFFFFFFF +#define S_0286CC_LINEAR_GRADIENT_ENA(x) (((x) & 0x1) << 29) +#define G_0286CC_LINEAR_GRADIENT_ENA(x) (((x) >> 29) & 0x1) +#define C_0286CC_LINEAR_GRADIENT_ENA 0xDFFFFFFF +#define S_0286CC_POSITION_SAMPLE(x) (((x) & 0x1) << 30) +#define G_0286CC_POSITION_SAMPLE(x) (((x) >> 30) & 0x1) +#define C_0286CC_POSITION_SAMPLE 0xBFFFFFFF +#define R_0286D0_SPI_PS_IN_CONTROL_1 0x0286D0 +#define S_0286D0_FRONT_FACE_ENA(x) (((x) & 0x1) << 8) +#define G_0286D0_FRONT_FACE_ENA(x) (((x) >> 8) & 0x1) +#define C_0286D0_FRONT_FACE_ENA 0xFFFFFEFF +#define S_0286D0_FRONT_FACE_CHAN(x) (((x) & 0x3) << 9) +#define G_0286D0_FRONT_FACE_CHAN(x) (((x) >> 9) & 0x3) +#define C_0286D0_FRONT_FACE_CHAN 0xFFFFF9FF +#define S_0286D0_FRONT_FACE_ALL_BITS(x) (((x) & 0x1) << 11) +#define G_0286D0_FRONT_FACE_ALL_BITS(x) (((x) >> 11) & 0x1) +#define C_0286D0_FRONT_FACE_ALL_BITS 0xFFFFF7FF +#define S_0286D0_FRONT_FACE_ADDR(x) (((x) & 0x1F) << 12) +#define G_0286D0_FRONT_FACE_ADDR(x) (((x) >> 12) & 0x1F) +#define C_0286D0_FRONT_FACE_ADDR 0xFFFE0FFF +#define S_0286D0_FOG_ADDR(x) (((x) & 0x7F) << 17) +#define G_0286D0_FOG_ADDR(x) (((x) >> 17) & 0x7F) +#define C_0286D0_FOG_ADDR 0xFF01FFFF +#define S_0286D0_FIXED_PT_POSITION_ENA(x) (((x) & 0x1) << 24) +#define G_0286D0_FIXED_PT_POSITION_ENA(x) (((x) >> 24) & 0x1) +#define C_0286D0_FIXED_PT_POSITION_ENA 0xFEFFFFFF +#define S_0286D0_FIXED_PT_POSITION_ADDR(x) (((x) & 0x1F) << 25) +#define G_0286D0_FIXED_PT_POSITION_ADDR(x) (((x) >> 25) & 0x1F) +#define C_0286D0_FIXED_PT_POSITION_ADDR 0xC1FFFFFF +#define R_0286C4_SPI_VS_OUT_CONFIG 0x0286C4 +#define S_0286C4_VS_PER_COMPONENT(x) (((x) & 0x1) << 0) +#define G_0286C4_VS_PER_COMPONENT(x) (((x) >> 0) & 0x1) +#define C_0286C4_VS_PER_COMPONENT 0xFFFFFFFE +#define S_0286C4_VS_EXPORT_COUNT(x) (((x) & 0x1F) << 1) +#define G_0286C4_VS_EXPORT_COUNT(x) (((x) >> 1) & 0x1F) +#define C_0286C4_VS_EXPORT_COUNT 0xFFFFFFC1 +#define S_0286C4_VS_EXPORTS_FOG(x) (((x) & 0x1) << 8) +#define G_0286C4_VS_EXPORTS_FOG(x) (((x) >> 8) & 0x1) +#define C_0286C4_VS_EXPORTS_FOG 0xFFFFFEFF +#define S_0286C4_VS_OUT_FOG_VEC_ADDR(x) (((x) & 0x1F) << 9) +#define G_0286C4_VS_OUT_FOG_VEC_ADDR(x) (((x) >> 9) & 0x1F) +#define C_0286C4_VS_OUT_FOG_VEC_ADDR 0xFFFFC1FF + +#define R_0286E0_SPI_BARYC_CNTL 0x0286E0 +#define S_0286E0_PERSP_CENTER_ENA(x) (((x) & 0x3) << 0) +#define G_0286E0_PERSP_CENTER_ENA(x) (((x) >> 0) & 0x3) +#define C_0286E0_PERSP_CENTER_ENA 0xFFFFFFFC +#define S_0286E0_PERSP_CENTROID_ENA(x) (((x) & 0x3) << 4) +#define G_0286E0_PERSP_CENTROID_ENA(x) (((x) >> 4) & 0x3) +#define C_0286E0_PERSP_CENTROID_ENA 0xFFFFFFCF +#define S_0286E0_PERSP_SAMPLE_ENA(x) (((x) & 0x3) << 8) +#define G_0286E0_PERSP_SAMPLE_ENA(x) (((x) >> 8) & 0x3) +#define C_0286E0_PERSP_SAMPLE_ENA 0xFFFFFCFF +#define S_0286E0_PERSP_PULL_MODEL_ENA(x) (((x) & 0x3) << 12) +#define G_0286E0_PERSP_PULL_MODEL_ENA(x) (((x) >> 12) & 0x3) +#define C_0286E0_PERSP_PULL_MODEL_ENA 0xFFFFCFFF +#define S_0286E0_LINEAR_CENTER_ENA(x) (((x) & 0x3) << 16) +#define G_0286E0_LINEAR_CENTER_ENA(x) (((x) >> 16) & 0x3) +#define C_0286E0_LINEAR_CENTER_ENA 0xFFFCFFFF +#define S_0286E0_LINEAR_CENTROID_ENA(x) (((x) & 0x3) << 20) +#define G_0286E0_LINEAR_CENTROID_ENA(x) (((x) >> 20) & 0x3) +#define C_0286E0_LINEAR_CENTROID_ENA 0xFFCFFFFF +#define S_0286E0_LINEAR_SAMPLE_ENA(x) (((x) & 0x3) << 24) +#define G_0286E0_LINEAR_SAMPLE_ENA(x) (((x) >> 24) & 0x3) +#define C_0286E0_LINEAR_SAMPLE_ENA 0xFCFFFFFF + + +/* new - diff */ +#define R_028250_PA_SC_VPORT_SCISSOR_TL 0x028250 +#define S_028250_TL_X(x) (((x) & 0x7FFF) << 0) +#define G_028250_TL_X(x) (((x) >> 0) & 0x7FFF) +#define C_028250_TL_X 0xFFFF8000 +#define S_028250_TL_Y(x) (((x) & 0x7FFF) << 16) +#define G_028250_TL_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028250_TL_Y 0x8000FFFF +#define S_028250_WINDOW_OFFSET_DISABLE(x) (((x) & 0x1) << 31) +#define G_028250_WINDOW_OFFSET_DISABLE(x) (((x) >> 31) & 0x1) +#define C_028250_WINDOW_OFFSET_DISABLE 0x7FFFFFFF +#define R_028254_PA_SC_VPORT_SCISSOR_BR 0x028254 +#define S_028254_BR_X(x) (((x) & 0x7FFF) << 0) +#define G_028254_BR_X(x) (((x) >> 0) & 0x7FFF) +#define C_028254_BR_X 0xFFFF8000 +#define S_028254_BR_Y(x) (((x) & 0x7FFF) << 16) +#define G_028254_BR_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028254_BR_Y 0x8000FFFF +/* diff */ +#define R_028240_PA_SC_GENERIC_SCISSOR_TL 0x028240 +#define S_028240_TL_X(x) (((x) & 0x7FFF) << 0) +#define G_028240_TL_X(x) (((x) >> 0) & 0x7FFF) +#define C_028240_TL_X 0xFFFF8000 +#define S_028240_TL_Y(x) (((x) & 0x7FFF) << 16) +#define G_028240_TL_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028240_TL_Y 0x8000FFFF +#define S_028240_WINDOW_OFFSET_DISABLE(x) (((x) & 0x1) << 31) +#define G_028240_WINDOW_OFFSET_DISABLE(x) (((x) >> 31) & 0x1) +#define C_028240_WINDOW_OFFSET_DISABLE 0x7FFFFFFF +#define R_028244_PA_SC_GENERIC_SCISSOR_BR 0x028244 +#define S_028244_BR_X(x) (((x) & 0x7FFF) << 0) +#define G_028244_BR_X(x) (((x) >> 0) & 0x7FFF) +#define C_028244_BR_X 0xFFFF8000 +#define S_028244_BR_Y(x) (((x) & 0x7FFF) << 16) +#define G_028244_BR_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028244_BR_Y 0x8000FFFF +/* diff */ +#define R_028030_PA_SC_SCREEN_SCISSOR_TL 0x028030 +#define S_028030_TL_X(x) (((x) & 0xFFFF) << 0) +#define G_028030_TL_X(x) (((x) >> 0) & 0xFFFF) +#define C_028030_TL_X 0xFFFF0000 +#define S_028030_TL_Y(x) (((x) & 0xFFFF) << 16) +#define G_028030_TL_Y(x) (((x) >> 16) & 0xFFFF) +#define C_028030_TL_Y 0x0000FFFF +#define R_028034_PA_SC_SCREEN_SCISSOR_BR 0x028034 +#define S_028034_BR_X(x) (((x) & 0xFFFF) << 0) +#define G_028034_BR_X(x) (((x) >> 0) & 0xFFFF) +#define C_028034_BR_X 0xFFFF0000 +#define S_028034_BR_Y(x) (((x) & 0xFFFF) << 16) +#define G_028034_BR_Y(x) (((x) >> 16) & 0xFFFF) +#define C_028034_BR_Y 0x0000FFFF +/* diff */ +#define R_028204_PA_SC_WINDOW_SCISSOR_TL 0x028204 +#define S_028204_TL_X(x) (((x) & 0x7FFF) << 0) +#define G_028204_TL_X(x) (((x) >> 0) & 0x7FFF) +#define C_028204_TL_X 0xFFFF8000 +#define S_028204_TL_Y(x) (((x) & 0x7FFF) << 16) +#define G_028204_TL_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028204_TL_Y 0x8000FFFF +#define S_028204_WINDOW_OFFSET_DISABLE(x) (((x) & 0x1) << 31) +#define G_028204_WINDOW_OFFSET_DISABLE(x) (((x) >> 31) & 0x1) +#define C_028204_WINDOW_OFFSET_DISABLE 0x7FFFFFFF +#define R_028208_PA_SC_WINDOW_SCISSOR_BR 0x028208 +#define S_028208_BR_X(x) (((x) & 0x7FFF) << 0) +#define G_028208_BR_X(x) (((x) >> 0) & 0x7FFF) +#define C_028208_BR_X 0xFFFF8000 +#define S_028208_BR_Y(x) (((x) & 0x7FFF) << 16) +#define G_028208_BR_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028208_BR_Y 0x8000FFFF + +#define R_0287F0_VGT_DRAW_INITIATOR 0x0287F0 +#define S_0287F0_SOURCE_SELECT(x) (((x) & 0x3) << 0) +#define G_0287F0_SOURCE_SELECT(x) (((x) >> 0) & 0x3) +#define C_0287F0_SOURCE_SELECT 0xFFFFFFFC +#define S_0287F0_MAJOR_MODE(x) (((x) & 0x3) << 2) +#define G_0287F0_MAJOR_MODE(x) (((x) >> 2) & 0x3) +#define C_0287F0_MAJOR_MODE 0xFFFFFFF3 +#define S_0287F0_SPRITE_EN(x) (((x) & 0x1) << 4) +#define G_0287F0_SPRITE_EN(x) (((x) >> 4) & 0x1) +#define C_0287F0_SPRITE_EN 0xFFFFFFEF +#define S_0287F0_NOT_EOP(x) (((x) & 0x1) << 5) +#define G_0287F0_NOT_EOP(x) (((x) >> 5) & 0x1) +#define C_0287F0_NOT_EOP 0xFFFFFFDF +#define S_0287F0_USE_OPAQUE(x) (((x) & 0x1) << 6) +#define G_0287F0_USE_OPAQUE(x) (((x) >> 6) & 0x1) +#define C_0287F0_USE_OPAQUE 0xFFFFFFBF + +#define R_030000_SQ_TEX_RESOURCE_WORD0_0 0x030000 +#define S_030000_DIM(x) (((x) & 0x7) << 0) +#define G_030000_DIM(x) (((x) >> 0) & 0x7) +#define C_030000_DIM 0xFFFFFFF8 +#define V_030000_SQ_TEX_DIM_1D 0x00000000 +#define V_030000_SQ_TEX_DIM_2D 0x00000001 +#define V_030000_SQ_TEX_DIM_3D 0x00000002 +#define V_030000_SQ_TEX_DIM_CUBEMAP 0x00000003 +#define V_030000_SQ_TEX_DIM_1D_ARRAY 0x00000004 +#define V_030000_SQ_TEX_DIM_2D_ARRAY 0x00000005 +#define V_030000_SQ_TEX_DIM_2D_MSAA 0x00000006 +#define V_030000_SQ_TEX_DIM_2D_ARRAY_MSAA 0x00000007 +#define S_030000_PITCH(x) (((x) & 0xFFF) << 6) +#define G_030000_PITCH(x) (((x) >> 6) & 0xFFF) +#define C_030000_PITCH 0xFFFC003F +#define S_030000_TEX_WIDTH(x) (((x) & 0x3FFF) << 18) +#define G_030000_TEX_WIDTH(x) (((x) >> 18) & 0x3FFF) +#define C_030000_TEX_WIDTH 0x0003FFFF +#define R_030004_SQ_TEX_RESOURCE_WORD1_0 0x030004 +#define S_030004_TEX_HEIGHT(x) (((x) & 0x3FFF) << 0) +#define G_030004_TEX_HEIGHT(x) (((x) >> 0) & 0x3FFF) +#define C_030004_TEX_HEIGHT 0xFFFFC000 +#define S_030004_TEX_DEPTH(x) (((x) & 0x1FFF) << 14) +#define G_030004_TEX_DEPTH(x) (((x) >> 14) & 0x1FFF) +#define C_030004_TEX_DEPTH 0xF8003FFF +#define S_030004_ARRAY_MODE(x) (((x) & 0xF) << 28) +#define G_030004_ARRAY_MODE(x) (((x) >> 28) & 0xF) +#define C_030004_ARRAY_MODE 0x0FFFFFFF +#define R_030008_SQ_TEX_RESOURCE_WORD2_0 0x030008 +#define S_030008_BASE_ADDRESS(x) (((x) & 0xFFFFFFFF) << 0) +#define G_030008_BASE_ADDRESS(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_030008_BASE_ADDRESS 0x00000000 +#define R_03000C_SQ_TEX_RESOURCE_WORD3_0 0x03000C +#define S_03000C_MIP_ADDRESS(x) (((x) & 0xFFFFFFFF) << 0) +#define G_03000C_MIP_ADDRESS(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_03000C_MIP_ADDRESS 0x00000000 +#define R_030010_SQ_TEX_RESOURCE_WORD4_0 0x030010 +#define S_030010_FORMAT_COMP_X(x) (((x) & 0x3) << 0) +#define G_030010_FORMAT_COMP_X(x) (((x) >> 0) & 0x3) +#define C_030010_FORMAT_COMP_X 0xFFFFFFFC +#define V_030010_SQ_FORMAT_COMP_UNSIGNED 0x00000000 +#define V_030010_SQ_FORMAT_COMP_SIGNED 0x00000001 +#define V_030010_SQ_FORMAT_COMP_UNSIGNED_BIASED 0x00000002 +#define S_030010_FORMAT_COMP_Y(x) (((x) & 0x3) << 2) +#define G_030010_FORMAT_COMP_Y(x) (((x) >> 2) & 0x3) +#define C_030010_FORMAT_COMP_Y 0xFFFFFFF3 +#define S_030010_FORMAT_COMP_Z(x) (((x) & 0x3) << 4) +#define G_030010_FORMAT_COMP_Z(x) (((x) >> 4) & 0x3) +#define C_030010_FORMAT_COMP_Z 0xFFFFFFCF +#define S_030010_FORMAT_COMP_W(x) (((x) & 0x3) << 6) +#define G_030010_FORMAT_COMP_W(x) (((x) >> 6) & 0x3) +#define C_030010_FORMAT_COMP_W 0xFFFFFF3F +#define S_030010_NUM_FORMAT_ALL(x) (((x) & 0x3) << 8) +#define G_030010_NUM_FORMAT_ALL(x) (((x) >> 8) & 0x3) +#define C_030010_NUM_FORMAT_ALL 0xFFFFFCFF +#define V_030010_SQ_NUM_FORMAT_NORM 0x00000000 +#define V_030010_SQ_NUM_FORMAT_INT 0x00000001 +#define V_030010_SQ_NUM_FORMAT_SCALED 0x00000002 +#define S_030010_SRF_MODE_ALL(x) (((x) & 0x1) << 10) +#define G_030010_SRF_MODE_ALL(x) (((x) >> 10) & 0x1) +#define C_030010_SRF_MODE_ALL 0xFFFFFBFF +#define V_030010_SFR_MODE_ZERO_CLAMP_MINUS_ONE 0x00000000 +#define V_030010_SFR_MODE_NO_ZERO 0x00000001 +#define S_030010_FORCE_DEGAMMA(x) (((x) & 0x1) << 11) +#define G_030010_FORCE_DEGAMMA(x) (((x) >> 11) & 0x1) +#define C_030010_FORCE_DEGAMMA 0xFFFFF7FF +#define S_030010_ENDIAN_SWAP(x) (((x) & 0x3) << 12) +#define G_030010_ENDIAN_SWAP(x) (((x) >> 12) & 0x3) +#define C_030010_ENDIAN_SWAP 0xFFFFCFFF +#define S_030010_DST_SEL_X(x) (((x) & 0x7) << 16) +#define G_030010_DST_SEL_X(x) (((x) >> 16) & 0x7) +#define C_030010_DST_SEL_X 0xFFF8FFFF +#define V_030010_SQ_SEL_X 0x00000000 +#define V_030010_SQ_SEL_Y 0x00000001 +#define V_030010_SQ_SEL_Z 0x00000002 +#define V_030010_SQ_SEL_W 0x00000003 +#define V_030010_SQ_SEL_0 0x00000004 +#define V_030010_SQ_SEL_1 0x00000005 +#define S_030010_DST_SEL_Y(x) (((x) & 0x7) << 19) +#define G_030010_DST_SEL_Y(x) (((x) >> 19) & 0x7) +#define C_030010_DST_SEL_Y 0xFFC7FFFF +#define S_030010_DST_SEL_Z(x) (((x) & 0x7) << 22) +#define G_030010_DST_SEL_Z(x) (((x) >> 22) & 0x7) +#define C_030010_DST_SEL_Z 0xFE3FFFFF +#define S_030010_DST_SEL_W(x) (((x) & 0x7) << 25) +#define G_030010_DST_SEL_W(x) (((x) >> 25) & 0x7) +#define C_030010_DST_SEL_W 0xF1FFFFFF +#define S_030010_BASE_LEVEL(x) (((x) & 0xF) << 28) +#define G_030010_BASE_LEVEL(x) (((x) >> 28) & 0xF) +#define C_030010_BASE_LEVEL 0x0FFFFFFF +#define R_030014_SQ_TEX_RESOURCE_WORD5_0 0x030014 +#define S_030014_LAST_LEVEL(x) (((x) & 0xF) << 0) +#define G_030014_LAST_LEVEL(x) (((x) >> 0) & 0xF) +#define C_030014_LAST_LEVEL 0xFFFFFFF0 +#define S_030014_BASE_ARRAY(x) (((x) & 0x1FFF) << 4) +#define G_030014_BASE_ARRAY(x) (((x) >> 4) & 0x1FFF) +#define C_030014_BASE_ARRAY 0xFFFE000F +#define S_030014_LAST_ARRAY(x) (((x) & 0x1FFF) << 17) +#define G_030014_LAST_ARRAY(x) (((x) >> 17) & 0x1FFF) +#define C_030014_LAST_ARRAY 0xC001FFFF +#define R_030018_SQ_TEX_RESOURCE_WORD6_0 0x030018 +#define S_030018_PERF_MODULATION(x) (((x) & 0x7) << 3) +#define G_030018_PERF_MODULATION(x) (((x) >> 3) & 0x7) +#define C_030018_PERF_MODULATION 0xFFFFFFC7 +#define S_030018_INTERLACED(x) (((x) & 0x1) << 6) +#define G_030018_INTERLACED(x) (((x) >> 6) & 0x1) +#define C_030018_INTERLACED 0xFFFFFFBF +#define R_03001C_SQ_TEX_RESOURCE_WORD7_0 0x03001C +#define S_03001C_TYPE(x) (((x) & 0x3) << 30) +#define G_03001C_TYPE(x) (((x) >> 30) & 0x3) +#define C_03001C_TYPE 0x3FFFFFFF +#define V_03001C_SQ_TEX_VTX_INVALID_TEXTURE 0x00000000 +#define V_03001C_SQ_TEX_VTX_INVALID_BUFFER 0x00000001 +#define V_03001C_SQ_TEX_VTX_VALID_TEXTURE 0x00000002 +#define V_03001C_SQ_TEX_VTX_VALID_BUFFER 0x00000003 +#define S_03001C_DATA_FORMAT(x) (((x) & 0x3F) << 0) +#define G_03001C_DATA_FORMAT(x) (((x) >> 0) & 0x3F) +#define C_03001C_DATA_FORMAT 0xFFFFFFC0 + +#define R_030008_SQ_VTX_CONSTANT_WORD2_0 0x030008 +#define S_030008_BASE_ADDRESS_HI(x) (((x) & 0xFF) << 0) +#define G_030008_BASE_ADDRESS_HI(x) (((x) >> 0) & 0xFF) +#define C_030008_BASE_ADDRESS_HI 0xFFFFFF00 +#define S_030008_STRIDE(x) (((x) & 0x7FF) << 8) +#define G_030008_STRIDE(x) (((x) >> 8) & 0x7FF) +#define C_030008_STRIDE 0xFFF800FF +#define S_030008_CLAMP_X(x) (((x) & 0x1) << 19) +#define G_030008_CLAMP_X(x) (((x) >> 19) & 0x1) +#define C_030008_CLAMP_X 0xFFF7FFFF +#define S_030008_DATA_FORMAT(x) (((x) & 0x3F) << 20) +#define G_030008_DATA_FORMAT(x) (((x) >> 20) & 0x3F) +#define C_030008_DATA_FORMAT 0xFC0FFFFF +#define S_030008_NUM_FORMAT_ALL(x) (((x) & 0x3) << 26) +#define G_030008_NUM_FORMAT_ALL(x) (((x) >> 26) & 0x3) +#define C_030008_NUM_FORMAT_ALL 0xF3FFFFFF +#define V_030008_SQ_NUM_FORMAT_NORM 0x00000000 +#define V_030008_SQ_NUM_FORMAT_INT 0x00000001 +#define V_030008_SQ_NUM_FORMAT_SCALED 0x00000002 +#define S_030008_FORMAT_COMP_ALL(x) (((x) & 0x1) << 28) +#define G_030008_FORMAT_COMP_ALL(x) (((x) >> 28) & 0x1) +#define C_030008_FORMAT_COMP_ALL 0xEFFFFFFF +#define S_030008_SRF_MODE_ALL(x) (((x) & 0x1) << 29) +#define G_030008_SRF_MODE_ALL(x) (((x) >> 29) & 0x1) +#define C_030008_SRF_MODE_ALL 0xDFFFFFFF +#define S_030008_ENDIAN_SWAP(x) (((x) & 0x3) << 30) +#define G_030008_ENDIAN_SWAP(x) (((x) >> 30) & 0x3) +#define C_030008_ENDIAN_SWAP 0x3FFFFFFF + +#define R_03000C_SQ_VTX_CONSTANT_WORD3_0 0x03000C +#define S_03000C_DST_SEL_X(x) (((x) & 0x7) << 3) +#define G_03000C_DST_SEL_X(x) (((x) >> 3) & 0x7) +#define V_03000C_SQ_SEL_X 0x00000000 +#define V_03000C_SQ_SEL_Y 0x00000001 +#define V_03000C_SQ_SEL_Z 0x00000002 +#define V_03000C_SQ_SEL_W 0x00000003 +#define V_03000C_SQ_SEL_0 0x00000004 +#define V_03000C_SQ_SEL_1 0x00000005 +#define S_03000C_DST_SEL_Y(x) (((x) & 0x7) << 6) +#define G_03000C_DST_SEL_Y(x) (((x) >> 6) & 0x7) +#define S_03000C_DST_SEL_Z(x) (((x) & 0x7) << 9) +#define G_03000C_DST_SEL_Z(x) (((x) >> 9) & 0x7) +#define S_03000C_DST_SEL_W(x) (((x) & 0x7) << 12) +#define G_03000C_DST_SEL_W(x) (((x) >> 12) & 0x7) + +#define R_00A400_TD_PS_SAMPLER0_BORDER_INDEX 0x00A400 +#define R_00A404_TD_PS_SAMPLER0_BORDER_RED 0x00A404 +#define R_00A408_TD_PS_SAMPLER0_BORDER_GREEN 0x00A408 +#define R_00A40C_TD_PS_SAMPLER0_BORDER_BLUE 0x00A40C +#define R_00A410_TD_PS_SAMPLER0_BORDER_ALPHA 0x00A410 +#define R_00A414_TD_VS_SAMPLER0_BORDER_INDEX 0x00A414 +#define R_00A418_TD_VS_SAMPLER0_BORDER_RED 0x00A418 +#define R_00A41C_TD_VS_SAMPLER0_BORDER_GREEN 0x00A41C +#define R_00A420_TD_VS_SAMPLER0_BORDER_BLUE 0x00A420 +#define R_00A424_TD_VS_SAMPLER0_BORDER_ALPHA 0x00A424 +#define R_00A428_TD_GS_SAMPLER0_BORDER_INDEX 0x00A428 +#define R_00A42C_TD_GS_SAMPLER0_BORDER_RED 0x00A42C +#define R_00A430_TD_GS_SAMPLER0_BORDER_GREEN 0x00A430 +#define R_00A434_TD_GS_SAMPLER0_BORDER_BLUE 0x00A434 +#define R_00A438_TD_GS_SAMPLER0_BORDER_ALPHA 0x00A438 + +#define R_03C000_SQ_TEX_SAMPLER_WORD0_0 0x03C000 +#define S_03C000_CLAMP_X(x) (((x) & 0x7) << 0) +#define G_03C000_CLAMP_X(x) (((x) >> 0) & 0x7) +#define C_03C000_CLAMP_X 0xFFFFFFF8 +#define V_03C000_SQ_TEX_WRAP 0x00000000 +#define V_03C000_SQ_TEX_MIRROR 0x00000001 +#define V_03C000_SQ_TEX_CLAMP_LAST_TEXEL 0x00000002 +#define V_03C000_SQ_TEX_MIRROR_ONCE_LAST_TEXEL 0x00000003 +#define V_03C000_SQ_TEX_CLAMP_HALF_BORDER 0x00000004 +#define V_03C000_SQ_TEX_MIRROR_ONCE_HALF_BORDER 0x00000005 +#define V_03C000_SQ_TEX_CLAMP_BORDER 0x00000006 +#define V_03C000_SQ_TEX_MIRROR_ONCE_BORDER 0x00000007 +#define S_03C000_CLAMP_Y(x) (((x) & 0x7) << 3) +#define G_03C000_CLAMP_Y(x) (((x) >> 3) & 0x7) +#define C_03C000_CLAMP_Y 0xFFFFFFC7 +#define S_03C000_CLAMP_Z(x) (((x) & 0x7) << 6) +#define G_03C000_CLAMP_Z(x) (((x) >> 6) & 0x7) +#define C_03C000_CLAMP_Z 0xFFFFFE3F +#define S_03C000_XY_MAG_FILTER(x) (((x) & 0x3) << 9) +#define G_03C000_XY_MAG_FILTER(x) (((x) >> 9) & 0x3) +#define C_03C000_XY_MAG_FILTER 0xFFFFF9FF +#define V_03C000_SQ_TEX_XY_FILTER_POINT 0x00000000 +#define V_03C000_SQ_TEX_XY_FILTER_BILINEAR 0x00000001 +#define S_03C000_XY_MIN_FILTER(x) (((x) & 0x3) << 11) +#define G_03C000_XY_MIN_FILTER(x) (((x) >> 11) & 0x3) +#define C_03C000_XY_MIN_FILTER 0xFFFFE7FF +#define S_03C000_Z_FILTER(x) (((x) & 0x3) << 13) +#define G_03C000_Z_FILTER(x) (((x) >> 13) & 0x3) +#define C_03C000_Z_FILTER 0xFFFF9FFF +#define V_03C000_SQ_TEX_Z_FILTER_NONE 0x00000000 +#define V_03C000_SQ_TEX_Z_FILTER_POINT 0x00000001 +#define V_03C000_SQ_TEX_Z_FILTER_LINEAR 0x00000002 +#define S_03C000_MIP_FILTER(x) (((x) & 0x3) << 15) +#define G_03C000_MIP_FILTER(x) (((x) >> 15) & 0x3) +#define C_03C000_MIP_FILTER 0xFFFE7FFF +#define S_03C000_BORDER_COLOR_TYPE(x) (((x) & 0x3) << 20) +#define G_03C000_BORDER_COLOR_TYPE(x) (((x) >> 20) & 0x3) +#define C_03C000_BORDER_COLOR_TYPE 0xFFCFFFFF +#define V_03C000_SQ_TEX_BORDER_COLOR_TRANS_BLACK 0x00000000 +#define V_03C000_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK 0x00000001 +#define V_03C000_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE 0x00000002 +#define V_03C000_SQ_TEX_BORDER_COLOR_REGISTER 0x00000003 +#define S_03C000_DEPTH_COMPARE_FUNCTION(x) (((x) & 0x7) << 22) +#define G_03C000_DEPTH_COMPARE_FUNCTION(x) (((x) >> 22) & 0x7) +#define C_03C000_DEPTH_COMPARE_FUNCTION 0xFE3FFFFF +#define V_03C000_SQ_TEX_DEPTH_COMPARE_NEVER 0x00000000 +#define V_03C000_SQ_TEX_DEPTH_COMPARE_LESS 0x00000001 +#define V_03C000_SQ_TEX_DEPTH_COMPARE_EQUAL 0x00000002 +#define V_03C000_SQ_TEX_DEPTH_COMPARE_LESSEQUAL 0x00000003 +#define V_03C000_SQ_TEX_DEPTH_COMPARE_GREATER 0x00000004 +#define V_03C000_SQ_TEX_DEPTH_COMPARE_NOTEQUAL 0x00000005 +#define V_03C000_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL 0x00000006 +#define V_03C000_SQ_TEX_DEPTH_COMPARE_ALWAYS 0x00000007 +#define S_03C000_CHROMA_KEY(x) (((x) & 0x3) << 25) +#define G_03C000_CHROMA_KEY(x) (((x) >> 25) & 0x3) +#define C_03C000_CHROMA_KEY 0xF9FFFFFF +#define V_03C000_SQ_TEX_CHROMA_KEY_DISABLE 0x00000000 +#define V_03C000_SQ_TEX_CHROMA_KEY_KILL 0x00000001 +#define V_03C000_SQ_TEX_CHROMA_KEY_BLEND 0x00000002 + +#define R_03C004_SQ_TEX_SAMPLER_WORD1_0 0x03C004 +#define S_03C004_MIN_LOD(x) (((x) & 0xFFF) << 0) +#define G_03C004_MIN_LOD(x) (((x) >> 0) & 0xFFF) +#define C_03C004_MIN_LOD 0xFFFFF000 +#define S_03C004_MAX_LOD(x) (((x) & 0xFFF) << 12) +#define G_03C004_MAX_LOD(x) (((x) >> 12) & 0xFFF) +#define C_03C004_MAX_LOD 0xFF000FFF + +#define S_03C004_PERF_MIP(x) (((x) & 0xF) << 24) +#define G_03C004_PERF_MIP(x) (((x) >> 24) & 0xF) +#define C_03C004_PERF_MIP 0xF0FFFFFF +#define S_03C004_PERF_Z(x) (((x) & 0xF) << 28) +#define G_03C004_PERF_Z(x) (((x) >> 24) & 0xF) +#define C_03C004_PERF_Z 0x0FFFFFFF + +#define R_03C008_SQ_TEX_SAMPLER_WORD2_0 0x03C008 +#define S_03C008_LOD_BIAS(x) (((x) & 0x3FFF) << 0) +#define G_03C008_LOD_BIAS(x) (((x) >> 0) & 0x3FFF) +#define C_03C008_LOD_BIAS 0xFFFFC000 +#define S_03C008_LOD_BIAS_SEC(x) (((x) & 0x3F) << 14) +#define G_03C008_LOD_BIAS_SEC(x) (((x) >> 14) & 0x3F) +#define C_03C008_LOD_BIAS_SEC 0xFFF03FFF +#define S_03C008_MC_COORD_TRUNCATE(x) (((x) & 0x1) << 20) +#define G_03C008_MC_COORD_TRUNCATE(x) (((x) >> 20) & 0x1) +#define C_03C008_MC_COORD_TRUNCATE 0xFFEFFFFF +#define S_03C008_FORCE_DEGAMMA(x) (((x) & 0x1) << 21) +#define G_03C008_FORCE_DEGAMMA(x) (((x) >> 21) & 0x1) +#define C_03C008_FORCE_DEGAMMA 0xFFDFFFFF +#define S_03C008_TYPE(x) (((x) & 0x1) << 31) +#define G_03C008_TYPE(x) (((x) >> 31) & 0x1) +#define C_03C008_TYPE 0x7FFFFFFF + +#define R_008958_VGT_PRIMITIVE_TYPE 0x008958 +#define S_008958_PRIM_TYPE(x) (((x) & 0x3F) << 0) +#define G_008958_PRIM_TYPE(x) (((x) >> 0) & 0x3F) +#define C_008958_PRIM_TYPE 0xFFFFFFC0 +#define V_008958_DI_PT_NONE 0x00000000 +#define V_008958_DI_PT_POINTLIST 0x00000001 +#define V_008958_DI_PT_LINELIST 0x00000002 +#define V_008958_DI_PT_LINESTRIP 0x00000003 +#define V_008958_DI_PT_TRILIST 0x00000004 +#define V_008958_DI_PT_TRIFAN 0x00000005 +#define V_008958_DI_PT_TRISTRIP 0x00000006 +#define V_008958_DI_PT_UNUSED_0 0x00000007 +#define V_008958_DI_PT_UNUSED_1 0x00000008 +#define V_008958_DI_PT_UNUSED_2 0x00000009 +#define V_008958_DI_PT_LINELIST_ADJ 0x0000000A +#define V_008958_DI_PT_LINESTRIP_ADJ 0x0000000B +#define V_008958_DI_PT_TRILIST_ADJ 0x0000000C +#define V_008958_DI_PT_TRISTRIP_ADJ 0x0000000D +#define V_008958_DI_PT_UNUSED_3 0x0000000E +#define V_008958_DI_PT_UNUSED_4 0x0000000F +#define V_008958_DI_PT_TRI_WITH_WFLAGS 0x00000010 +#define V_008958_DI_PT_RECTLIST 0x00000011 +#define V_008958_DI_PT_LINELOOP 0x00000012 +#define V_008958_DI_PT_QUADLIST 0x00000013 +#define V_008958_DI_PT_QUADSTRIP 0x00000014 +#define V_008958_DI_PT_POLYGON 0x00000015 +#define V_008958_DI_PT_2D_COPY_RECT_LIST_V0 0x00000016 +#define V_008958_DI_PT_2D_COPY_RECT_LIST_V1 0x00000017 +#define V_008958_DI_PT_2D_COPY_RECT_LIST_V2 0x00000018 +#define V_008958_DI_PT_2D_COPY_RECT_LIST_V3 0x00000019 +#define V_008958_DI_PT_2D_FILL_RECT_LIST 0x0000001A +#define V_008958_DI_PT_2D_LINE_STRIP 0x0000001B +#define V_008958_DI_PT_2D_TRI_STRIP 0x0000001C +#define R_02881C_PA_CL_VS_OUT_CNTL 0x02881C +#define S_02881C_CLIP_DIST_ENA_0(x) (((x) & 0x1) << 0) +#define G_02881C_CLIP_DIST_ENA_0(x) (((x) >> 0) & 0x1) +#define C_02881C_CLIP_DIST_ENA_0 0xFFFFFFFE +#define S_02881C_CLIP_DIST_ENA_1(x) (((x) & 0x1) << 1) +#define G_02881C_CLIP_DIST_ENA_1(x) (((x) >> 1) & 0x1) +#define C_02881C_CLIP_DIST_ENA_1 0xFFFFFFFD +#define S_02881C_CLIP_DIST_ENA_2(x) (((x) & 0x1) << 2) +#define G_02881C_CLIP_DIST_ENA_2(x) (((x) >> 2) & 0x1) +#define C_02881C_CLIP_DIST_ENA_2 0xFFFFFFFB +#define S_02881C_CLIP_DIST_ENA_3(x) (((x) & 0x1) << 3) +#define G_02881C_CLIP_DIST_ENA_3(x) (((x) >> 3) & 0x1) +#define C_02881C_CLIP_DIST_ENA_3 0xFFFFFFF7 +#define S_02881C_CLIP_DIST_ENA_4(x) (((x) & 0x1) << 4) +#define G_02881C_CLIP_DIST_ENA_4(x) (((x) >> 4) & 0x1) +#define C_02881C_CLIP_DIST_ENA_4 0xFFFFFFEF +#define S_02881C_CLIP_DIST_ENA_5(x) (((x) & 0x1) << 5) +#define G_02881C_CLIP_DIST_ENA_5(x) (((x) >> 5) & 0x1) +#define C_02881C_CLIP_DIST_ENA_5 0xFFFFFFDF +#define S_02881C_CLIP_DIST_ENA_6(x) (((x) & 0x1) << 6) +#define G_02881C_CLIP_DIST_ENA_6(x) (((x) >> 6) & 0x1) +#define C_02881C_CLIP_DIST_ENA_6 0xFFFFFFBF +#define S_02881C_CLIP_DIST_ENA_7(x) (((x) & 0x1) << 7) +#define G_02881C_CLIP_DIST_ENA_7(x) (((x) >> 7) & 0x1) +#define C_02881C_CLIP_DIST_ENA_7 0xFFFFFF7F +#define S_02881C_CULL_DIST_ENA_0(x) (((x) & 0x1) << 8) +#define G_02881C_CULL_DIST_ENA_0(x) (((x) >> 8) & 0x1) +#define C_02881C_CULL_DIST_ENA_0 0xFFFFFEFF +#define S_02881C_CULL_DIST_ENA_1(x) (((x) & 0x1) << 9) +#define G_02881C_CULL_DIST_ENA_1(x) (((x) >> 9) & 0x1) +#define C_02881C_CULL_DIST_ENA_1 0xFFFFFDFF +#define S_02881C_CULL_DIST_ENA_2(x) (((x) & 0x1) << 10) +#define G_02881C_CULL_DIST_ENA_2(x) (((x) >> 10) & 0x1) +#define C_02881C_CULL_DIST_ENA_2 0xFFFFFBFF +#define S_02881C_CULL_DIST_ENA_3(x) (((x) & 0x1) << 11) +#define G_02881C_CULL_DIST_ENA_3(x) (((x) >> 11) & 0x1) +#define C_02881C_CULL_DIST_ENA_3 0xFFFFF7FF +#define S_02881C_CULL_DIST_ENA_4(x) (((x) & 0x1) << 12) +#define G_02881C_CULL_DIST_ENA_4(x) (((x) >> 12) & 0x1) +#define C_02881C_CULL_DIST_ENA_4 0xFFFFEFFF +#define S_02881C_CULL_DIST_ENA_5(x) (((x) & 0x1) << 13) +#define G_02881C_CULL_DIST_ENA_5(x) (((x) >> 13) & 0x1) +#define C_02881C_CULL_DIST_ENA_5 0xFFFFDFFF +#define S_02881C_CULL_DIST_ENA_6(x) (((x) & 0x1) << 14) +#define G_02881C_CULL_DIST_ENA_6(x) (((x) >> 14) & 0x1) +#define C_02881C_CULL_DIST_ENA_6 0xFFFFBFFF +#define S_02881C_CULL_DIST_ENA_7(x) (((x) & 0x1) << 15) +#define G_02881C_CULL_DIST_ENA_7(x) (((x) >> 15) & 0x1) +#define C_02881C_CULL_DIST_ENA_7 0xFFFF7FFF +#define S_02881C_USE_VTX_POINT_SIZE(x) (((x) & 0x1) << 16) +#define G_02881C_USE_VTX_POINT_SIZE(x) (((x) >> 16) & 0x1) +#define C_02881C_USE_VTX_POINT_SIZE 0xFFFEFFFF +#define S_02881C_USE_VTX_EDGE_FLAG(x) (((x) & 0x1) << 17) +#define G_02881C_USE_VTX_EDGE_FLAG(x) (((x) >> 17) & 0x1) +#define C_02881C_USE_VTX_EDGE_FLAG 0xFFFDFFFF +#define S_02881C_USE_VTX_RENDER_TARGET_INDX(x) (((x) & 0x1) << 18) +#define G_02881C_USE_VTX_RENDER_TARGET_INDX(x) (((x) >> 18) & 0x1) +#define C_02881C_USE_VTX_RENDER_TARGET_INDX 0xFFFBFFFF +#define S_02881C_USE_VTX_VIEWPORT_INDX(x) (((x) & 0x1) << 19) +#define G_02881C_USE_VTX_VIEWPORT_INDX(x) (((x) >> 19) & 0x1) +#define C_02881C_USE_VTX_VIEWPORT_INDX 0xFFF7FFFF +#define S_02881C_USE_VTX_KILL_FLAG(x) (((x) & 0x1) << 20) +#define G_02881C_USE_VTX_KILL_FLAG(x) (((x) >> 20) & 0x1) +#define C_02881C_USE_VTX_KILL_FLAG 0xFFEFFFFF +#define S_02881C_VS_OUT_MISC_VEC_ENA(x) (((x) & 0x1) << 21) +#define G_02881C_VS_OUT_MISC_VEC_ENA(x) (((x) >> 21) & 0x1) +#define C_02881C_VS_OUT_MISC_VEC_ENA 0xFFDFFFFF +#define S_02881C_VS_OUT_CCDIST0_VEC_ENA(x) (((x) & 0x1) << 22) +#define G_02881C_VS_OUT_CCDIST0_VEC_ENA(x) (((x) >> 22) & 0x1) +#define C_02881C_VS_OUT_CCDIST0_VEC_ENA 0xFFBFFFFF +#define S_02881C_VS_OUT_CCDIST1_VEC_ENA(x) (((x) & 0x1) << 23) +#define G_02881C_VS_OUT_CCDIST1_VEC_ENA(x) (((x) >> 23) & 0x1) +#define C_02881C_VS_OUT_CCDIST1_VEC_ENA 0xFF7FFFFF +/* diff */ +#define R_028860_SQ_PGM_RESOURCES_VS 0x028860 +#define S_028860_NUM_GPRS(x) (((x) & 0xFF) << 0) +#define G_028860_NUM_GPRS(x) (((x) >> 0) & 0xFF) +#define C_028860_NUM_GPRS 0xFFFFFF00 +#define S_028860_STACK_SIZE(x) (((x) & 0xFF) << 8) +#define G_028860_STACK_SIZE(x) (((x) >> 8) & 0xFF) +#define C_028860_STACK_SIZE 0xFFFF00FF +#define S_028860_DX10_CLAMP(x) (((x) & 0x1) << 21) +#define G_028860_DX10_CLAMP(x) (((x) >> 21) & 0x1) +#define C_028860_DX10_CLAMP 0xFFDFFFFF +#define S_028860_UNCACHED_FIRST_INST(x) (((x) & 0x1) << 28) +#define G_028860_UNCACHED_FIRST_INST(x) (((x) >> 28) & 0x1) +#define C_028860_UNCACHED_FIRST_INST 0xEFFFFFFF +#define R_028864_SQ_PGM_RESOURCES_2_VS 0x028864 + +#define R_028844_SQ_PGM_RESOURCES_PS 0x028844 +#define S_028844_NUM_GPRS(x) (((x) & 0xFF) << 0) +#define G_028844_NUM_GPRS(x) (((x) >> 0) & 0xFF) +#define C_028844_NUM_GPRS 0xFFFFFF00 +#define S_028844_STACK_SIZE(x) (((x) & 0xFF) << 8) +#define G_028844_STACK_SIZE(x) (((x) >> 8) & 0xFF) +#define C_028844_STACK_SIZE 0xFFFF00FF +#define S_028844_DX10_CLAMP(x) (((x) & 0x1) << 21) +#define G_028844_DX10_CLAMP(x) (((x) >> 21) & 0x1) +#define C_028844_DX10_CLAMP 0xFFDFFFFF +#define S_028844_PRIME_CACHE_ON_DRAW(x) (((x) & 0x1) << 23) +#define G_028844_PRIME_CACHE_ON_DRAW(x) (((x) >> 23) & 0x1) + +#define S_028844_UNCACHED_FIRST_INST(x) (((x) & 0x1) << 28) +#define G_028844_UNCACHED_FIRST_INST(x) (((x) >> 28) & 0x1) +#define C_028844_UNCACHED_FIRST_INST 0xEFFFFFFF +#define S_028844_CLAMP_CONSTS(x) (((x) & 0x1) << 31) +#define G_028844_CLAMP_CONSTS(x) (((x) >> 31) & 0x1) +#define C_028844_CLAMP_CONSTS 0x7FFFFFFF +#define R_028848_SQ_PGM_RESOURCES_2_PS 0x028848 + +#define R_028644_SPI_PS_INPUT_CNTL_0 0x028644 +#define S_028644_SEMANTIC(x) (((x) & 0xFF) << 0) +#define G_028644_SEMANTIC(x) (((x) >> 0) & 0xFF) +#define C_028644_SEMANTIC 0xFFFFFF00 +#define S_028644_DEFAULT_VAL(x) (((x) & 0x3) << 8) +#define G_028644_DEFAULT_VAL(x) (((x) >> 8) & 0x3) +#define C_028644_DEFAULT_VAL 0xFFFFFCFF +#define S_028644_FLAT_SHADE(x) (((x) & 0x1) << 10) +#define G_028644_FLAT_SHADE(x) (((x) >> 10) & 0x1) +#define C_028644_FLAT_SHADE 0xFFFFFBFF +#define S_028644_SEL_CENTROID(x) (((x) & 0x1) << 11) +#define G_028644_SEL_CENTROID(x) (((x) >> 11) & 0x1) +#define C_028644_SEL_CENTROID 0xFFFFF7FF +#define S_028644_SEL_LINEAR(x) (((x) & 0x1) << 12) +#define G_028644_SEL_LINEAR(x) (((x) >> 12) & 0x1) +#define C_028644_SEL_LINEAR 0xFFFFEFFF +#define S_028644_CYL_WRAP(x) (((x) & 0xF) << 13) +#define G_028644_CYL_WRAP(x) (((x) >> 13) & 0xF) +#define C_028644_CYL_WRAP 0xFFFE1FFF +#define S_028644_PT_SPRITE_TEX(x) (((x) & 0x1) << 17) +#define G_028644_PT_SPRITE_TEX(x) (((x) >> 17) & 0x1) +#define C_028644_PT_SPRITE_TEX 0xFFFDFFFF +#define S_028644_SEL_SAMPLE(x) (((x) & 0x1) << 18) +#define G_028644_SEL_SAMPLE(x) (((x) >> 18) & 0x1) +#define C_028644_SEL_SAMPLE 0xFFFBFFFF +#define R_0286D4_SPI_INTERP_CONTROL_0 0x0286D4 +#define S_0286D4_FLAT_SHADE_ENA(x) (((x) & 0x1) << 0) +#define G_0286D4_FLAT_SHADE_ENA(x) (((x) >> 0) & 0x1) +#define C_0286D4_FLAT_SHADE_ENA 0xFFFFFFFE +#define S_0286D4_PNT_SPRITE_ENA(x) (((x) & 0x1) << 1) +#define G_0286D4_PNT_SPRITE_ENA(x) (((x) >> 1) & 0x1) +#define C_0286D4_PNT_SPRITE_ENA 0xFFFFFFFD +#define S_0286D4_PNT_SPRITE_OVRD_X(x) (((x) & 0x7) << 2) +#define G_0286D4_PNT_SPRITE_OVRD_X(x) (((x) >> 2) & 0x7) +#define C_0286D4_PNT_SPRITE_OVRD_X 0xFFFFFFE3 +#define S_0286D4_PNT_SPRITE_OVRD_Y(x) (((x) & 0x7) << 5) +#define G_0286D4_PNT_SPRITE_OVRD_Y(x) (((x) >> 5) & 0x7) +#define C_0286D4_PNT_SPRITE_OVRD_Y 0xFFFFFF1F +#define S_0286D4_PNT_SPRITE_OVRD_Z(x) (((x) & 0x7) << 8) +#define G_0286D4_PNT_SPRITE_OVRD_Z(x) (((x) >> 8) & 0x7) +#define C_0286D4_PNT_SPRITE_OVRD_Z 0xFFFFF8FF +#define S_0286D4_PNT_SPRITE_OVRD_W(x) (((x) & 0x7) << 11) +#define G_0286D4_PNT_SPRITE_OVRD_W(x) (((x) >> 11) & 0x7) +#define C_0286D4_PNT_SPRITE_OVRD_W 0xFFFFC7FF +#define S_0286D4_PNT_SPRITE_TOP_1(x) (((x) & 0x1) << 14) +#define G_0286D4_PNT_SPRITE_TOP_1(x) (((x) >> 14) & 0x1) +#define C_0286D4_PNT_SPRITE_TOP_1 0xFFFFBFFF + +#define SQ_TEX_INST_LD 0x03 +#define SQ_TEX_INST_GET_GRADIENTS_H 0x7 +#define SQ_TEX_INST_GET_GRADIENTS_V 0x8 + +#define SQ_TEX_INST_SAMPLE 0x10 +#define SQ_TEX_INST_SAMPLE_L 0x11 +#define SQ_TEX_INST_SAMPLE_C 0x18 + +#define R_008A14_PA_CL_ENHANCE 0x00008A14 +#define R_008C0C_SQ_THREAD_RESOURCE_MGMT 0x00008C0C +#define R_008D8C_SQ_DYN_GPR_CNTL_PS_FLUSH_REQ 0x00008D8C +#define R_028000_DB_RENDER_CONTROL 0x00028000 +#define S_028000_DEPTH_CLEAR_ENABLE(x) (((x) & 0x1) << 0) +#define S_028000_STENCIL_CLEAR_ENABLE(x) (((x) & 0x1) << 1) +#define S_028000_DEPTH_COPY_ENABLE(x) (((x) & 0x1) << 2) +#define S_028000_STENCIL_COPY_ENABLE(x) (((x) & 0x1) << 3) +#define S_028000_RESUMMARIZE_ENABLE(x) (((x) & 0x1) << 4) +#define S_028000_STENCIL_COMPRESS_DISABLE(x) (((x) & 0x1) << 5) +#define S_028000_DEPTH_COMPRESS_DISABLE(x) (((x) & 0x1) << 6) +#define S_028000_COPY_CENTROID(x) (((x) & 0x1) << 7) +#define S_028000_COPY_SAMPLE(x) (((x) & 0x7) << 8) +#define S_028000_COLOR_DISABLE(x) (((x) & 0x1) << 12) +#define R_028004_DB_COUNT_CONTROL 0x00028004 +#define S_028004_ZPASS_INCREMENT_DISABLE (((x) & 0x1) << 0) +#define S_028004_PERFECT_ZPASS_COUNTS(x) (((x) & 0x1) << 1) +#define R_028008_DB_DEPTH_VIEW 0x00028008 +#define R_02800C_DB_RENDER_OVERRIDE 0x0002800C +#define V_02800C_FORCE_OFF 0 +#define V_02800C_FORCE_ENABLE 1 +#define V_02800C_FORCE_DISABLE 2 +#define S_02800C_FORCE_HIZ_ENABLE(x) (((x) & 0x3) << 0) +#define G_02800C_FORCE_HIZ_ENABLE(x) (((x) >> 0) & 0x3) +#define C_02800C_FORCE_HIZ_ENABLE 0xFFFFFFFC +#define S_02800C_FORCE_HIS_ENABLE0(x) (((x) & 0x3) << 2) +#define G_02800C_FORCE_HIS_ENABLE0(x) (((x) >> 2) & 0x3) +#define C_02800C_FORCE_HIS_ENABLE0 0xFFFFFFF3 +#define S_02800C_FORCE_HIS_ENABLE1(x) (((x) & 0x3) << 4) +#define G_02800C_FORCE_HIS_ENABLE1(x) (((x) >> 4) & 0x3) +#define C_02800C_FORCE_HIS_ENABLE1 0xFFFFFFCF +#define S_02800C_FORCE_SHADER_Z_ORDER(x) (((x) & 0x1) << 6) +#define G_02800C_FORCE_SHADER_Z_ORDER(x) (((x) >> 6) & 0x1) +#define C_02800C_FORCE_SHADER_Z_ORDER 0xFFFFFFBF +#define S_02800C_FAST_Z_DISABLE(x) (((x) & 0x1) << 7) +#define G_02800C_FAST_Z_DISABLE(x) (((x) >> 7) & 0x1) +#define C_02800C_FAST_Z_DISABLE 0xFFFFFF7F +#define S_02800C_FAST_STENCIL_DISABLE(x) (((x) & 0x1) << 8) +#define G_02800C_FAST_STENCIL_DISABLE(x) (((x) >> 8) & 0x1) +#define C_02800C_FAST_STENCIL_DISABLE 0xFFFFFEFF +#define S_02800C_NOOP_CULL_DISABLE(x) (((x) & 0x1) << 9) +#define G_02800C_NOOP_CULL_DISABLE(x) (((x) >> 9) & 0x1) +#define C_02800C_NOOP_CULL_DISABLE 0xFFFFFDFF +#define S_02800C_FORCE_COLOR_KILL(x) (((x) & 0x1) << 10) +#define G_02800C_FORCE_COLOR_KILL(x) (((x) >> 10) & 0x1) +#define C_02800C_FORCE_COLOR_KILL 0xFFFFFBFF +#define S_02800C_FORCE_Z_READ(x) (((x) & 0x1) << 11) +#define G_02800C_FORCE_Z_READ(x) (((x) >> 11) & 0x1) +#define C_02800C_FORCE_Z_READ 0xFFFFF7FF +#define S_02800C_FORCE_STENCIL_READ(x) (((x) & 0x1) << 12) +#define G_02800C_FORCE_STENCIL_READ(x) (((x) >> 12) & 0x1) +#define C_02800C_FORCE_STENCIL_READ 0xFFFFEFFF +#define S_02800C_FORCE_FULL_Z_RANGE(x) (((x) & 0x3) << 13) +#define G_02800C_FORCE_FULL_Z_RANGE(x) (((x) >> 13) & 0x3) +#define C_02800C_FORCE_FULL_Z_RANGE 0xFFFF9FFF +#define S_02800C_FORCE_QC_SMASK_CONFLICT(x) (((x) & 0x1) << 15) +#define G_02800C_FORCE_QC_SMASK_CONFLICT(x) (((x) >> 15) & 0x1) +#define C_02800C_FORCE_QC_SMASK_CONFLICT 0xFFFF7FFF +#define S_02800C_DISABLE_VIEWPORT_CLAMP(x) (((x) & 0x1) << 16) +#define G_02800C_DISABLE_VIEWPORT_CLAMP(x) (((x) >> 16) & 0x1) +#define C_02800C_DISABLE_VIEWPORT_CLAMP 0xFFFEFFFF +#define S_02800C_IGNORE_SC_ZRANGE(x) (((x) & 0x1) << 17) +#define G_02800C_IGNORE_SC_ZRANGE(x) (((x) >> 17) & 0x1) +#define C_02800C_IGNORE_SC_ZRANGE 0xFFFDFFFF +#define R_028010_DB_RENDER_OVERRIDE2 0x00028010 +#define R_028014_DB_HTILE_DATA_BASE 0x00028014 +#define R_028028_DB_STENCIL_CLEAR 0x00028028 +#define R_02802C_DB_DEPTH_CLEAR 0x0002802C +#define R_028048_DB_Z_READ_BASE 0x00028048 +#define R_02804C_DB_STENCIL_READ_BASE 0x0002804C +#define R_028050_DB_Z_WRITE_BASE 0x00028050 +#define R_028054_DB_STENCIL_WRITE_BASE 0x00028054 +#define R_028140_ALU_CONST_BUFFER_SIZE_PS_0 0x00028140 +#define R_028180_ALU_CONST_BUFFER_SIZE_VS_0 0x00028180 +#define R_028200_PA_SC_WINDOW_OFFSET 0x00028200 +#define R_02820C_PA_SC_CLIPRECT_RULE 0x0002820C +#define R_028210_PA_SC_CLIPRECT_0_TL 0x00028210 +#define R_028214_PA_SC_CLIPRECT_0_BR 0x00028214 +#define R_028218_PA_SC_CLIPRECT_1_TL 0x00028218 +#define R_02821C_PA_SC_CLIPRECT_1_BR 0x0002821C +#define R_028220_PA_SC_CLIPRECT_2_TL 0x00028220 +#define R_028224_PA_SC_CLIPRECT_2_BR 0x00028224 +#define R_028228_PA_SC_CLIPRECT_3_TL 0x00028228 +#define R_02822C_PA_SC_CLIPRECT_3_BR 0x0002822C +#define R_028230_PA_SC_EDGERULE 0x00028230 +#define R_028234_PA_SU_HARDWARE_SCREEN_OFFSET 0x00028234 +#define R_028238_CB_TARGET_MASK 0x00028238 +#define R_02823C_CB_SHADER_MASK 0x0002823C +#define R_028250_PA_SC_VPORT_SCISSOR_0_TL 0x00028250 +#define R_028254_PA_SC_VPORT_SCISSOR_0_BR 0x00028254 +#define R_028350_SX_MISC 0x00028350 +#define R_028380_SQ_VTX_SEMANTIC_0 0x00028380 +#define R_028384_SQ_VTX_SEMANTIC_1 0x00028384 +#define R_028388_SQ_VTX_SEMANTIC_2 0x00028388 +#define R_02838C_SQ_VTX_SEMANTIC_3 0x0002838C +#define R_028390_SQ_VTX_SEMANTIC_4 0x00028390 +#define R_028394_SQ_VTX_SEMANTIC_5 0x00028394 +#define R_028398_SQ_VTX_SEMANTIC_6 0x00028398 +#define R_02839C_SQ_VTX_SEMANTIC_7 0x0002839C +#define R_0283A0_SQ_VTX_SEMANTIC_8 0x000283A0 +#define R_0283A4_SQ_VTX_SEMANTIC_9 0x000283A4 +#define R_0283A8_SQ_VTX_SEMANTIC_10 0x000283A8 +#define R_0283AC_SQ_VTX_SEMANTIC_11 0x000283AC +#define R_0283B0_SQ_VTX_SEMANTIC_12 0x000283B0 +#define R_0283B4_SQ_VTX_SEMANTIC_13 0x000283B4 +#define R_0283B8_SQ_VTX_SEMANTIC_14 0x000283B8 +#define R_0283BC_SQ_VTX_SEMANTIC_15 0x000283BC +#define R_0283C0_SQ_VTX_SEMANTIC_16 0x000283C0 +#define R_0283C4_SQ_VTX_SEMANTIC_17 0x000283C4 +#define R_0283C8_SQ_VTX_SEMANTIC_18 0x000283C8 +#define R_0283CC_SQ_VTX_SEMANTIC_19 0x000283CC +#define R_0283D0_SQ_VTX_SEMANTIC_20 0x000283D0 +#define R_0283D4_SQ_VTX_SEMANTIC_21 0x000283D4 +#define R_0283D8_SQ_VTX_SEMANTIC_22 0x000283D8 +#define R_0283DC_SQ_VTX_SEMANTIC_23 0x000283DC +#define R_0283E0_SQ_VTX_SEMANTIC_24 0x000283E0 +#define R_0283E4_SQ_VTX_SEMANTIC_25 0x000283E4 +#define R_0283E8_SQ_VTX_SEMANTIC_26 0x000283E8 +#define R_0283EC_SQ_VTX_SEMANTIC_27 0x000283EC +#define R_0283F0_SQ_VTX_SEMANTIC_28 0x000283F0 +#define R_0283F4_SQ_VTX_SEMANTIC_29 0x000283F4 +#define R_0283F8_SQ_VTX_SEMANTIC_30 0x000283F8 +#define R_0283FC_SQ_VTX_SEMANTIC_31 0x000283FC +#define R_0282D0_PA_SC_VPORT_ZMIN_0 0x000282D0 +#define R_0282D4_PA_SC_VPORT_ZMAX_0 0x000282D4 +#define R_028400_VGT_MAX_VTX_INDX 0x00028400 +#define R_028404_VGT_MIN_VTX_INDX 0x00028404 +#define R_028408_VGT_INDX_OFFSET 0x00028408 +#define R_02840C_VGT_MULTI_PRIM_IB_RESET_INDX 0x0002840C +#define R_028414_CB_BLEND_RED 0x00028414 +#define R_028418_CB_BLEND_GREEN 0x00028418 +#define R_02841C_CB_BLEND_BLUE 0x0002841C +#define R_028420_CB_BLEND_ALPHA 0x00028420 +#define R_028438_SX_ALPHA_REF 0x00028438 +#define R_02843C_PA_CL_VPORT_XSCALE_0 0x0002843C +#define R_028440_PA_CL_VPORT_XOFFSET_0 0x00028440 +#define R_028444_PA_CL_VPORT_YSCALE_0 0x00028444 +#define R_028448_PA_CL_VPORT_YOFFSET_0 0x00028448 +#define R_02844C_PA_CL_VPORT_ZSCALE_0 0x0002844C +#define R_028450_PA_CL_VPORT_ZOFFSET_0 0x00028450 +#define R_0285BC_PA_CL_UCP0_X 0x000285BC +#define R_0285C0_PA_CL_UCP0_Y 0x000285C0 +#define R_0285C4_PA_CL_UCP0_Z 0x000285C4 +#define R_0285C8_PA_CL_UCP0_W 0x000285C8 +#define R_0285CC_PA_CL_UCP1_X 0x000285CC +#define R_0285D0_PA_CL_UCP1_Y 0x000285D0 +#define R_0285D4_PA_CL_UCP1_Z 0x000285D4 +#define R_0285D8_PA_CL_UCP1_W 0x000285D8 +#define R_0285DC_PA_CL_UCP2_X 0x000285DC +#define R_0285E0_PA_CL_UCP2_Y 0x000285E0 +#define R_0285E4_PA_CL_UCP2_Z 0x000285E4 +#define R_0285E8_PA_CL_UCP2_W 0x000285E8 +#define R_0285EC_PA_CL_UCP3_X 0x000285EC +#define R_0285F0_PA_CL_UCP3_Y 0x000285F0 +#define R_0285F4_PA_CL_UCP3_Z 0x000285F4 +#define R_0285F8_PA_CL_UCP3_W 0x000285F8 +#define R_0285FC_PA_CL_UCP4_X 0x000285FC +#define R_028600_PA_CL_UCP4_Y 0x00028600 +#define R_028604_PA_CL_UCP4_Z 0x00028604 +#define R_028608_PA_CL_UCP4_W 0x00028608 +#define R_02860C_PA_CL_UCP5_X 0x0002860C +#define R_028610_PA_CL_UCP5_Y 0x00028610 +#define R_028614_PA_CL_UCP5_Z 0x00028614 +#define R_028618_PA_CL_UCP5_W 0x00028618 +#define R_02861C_SPI_VS_OUT_ID_0 0x0002861C +#define R_028620_SPI_VS_OUT_ID_1 0x00028620 +#define R_028624_SPI_VS_OUT_ID_2 0x00028624 +#define R_028628_SPI_VS_OUT_ID_3 0x00028628 +#define R_02862C_SPI_VS_OUT_ID_4 0x0002862C +#define R_028630_SPI_VS_OUT_ID_5 0x00028630 +#define R_028634_SPI_VS_OUT_ID_6 0x00028634 +#define R_028638_SPI_VS_OUT_ID_7 0x00028638 +#define R_02863C_SPI_VS_OUT_ID_8 0x0002863C +#define R_028640_SPI_VS_OUT_ID_9 0x00028640 +#define R_028648_SPI_PS_INPUT_CNTL_1 0x00028648 +#define R_02864C_SPI_PS_INPUT_CNTL_2 0x0002864C +#define R_028650_SPI_PS_INPUT_CNTL_3 0x00028650 +#define R_028654_SPI_PS_INPUT_CNTL_4 0x00028654 +#define R_028658_SPI_PS_INPUT_CNTL_5 0x00028658 +#define R_02865C_SPI_PS_INPUT_CNTL_6 0x0002865C +#define R_028660_SPI_PS_INPUT_CNTL_7 0x00028660 +#define R_028664_SPI_PS_INPUT_CNTL_8 0x00028664 +#define R_028668_SPI_PS_INPUT_CNTL_9 0x00028668 +#define R_02866C_SPI_PS_INPUT_CNTL_10 0x0002866C +#define R_028670_SPI_PS_INPUT_CNTL_11 0x00028670 +#define R_028674_SPI_PS_INPUT_CNTL_12 0x00028674 +#define R_028678_SPI_PS_INPUT_CNTL_13 0x00028678 +#define R_02867C_SPI_PS_INPUT_CNTL_14 0x0002867C +#define R_028680_SPI_PS_INPUT_CNTL_15 0x00028680 +#define R_028684_SPI_PS_INPUT_CNTL_16 0x00028684 +#define R_028688_SPI_PS_INPUT_CNTL_17 0x00028688 +#define R_02868C_SPI_PS_INPUT_CNTL_18 0x0002868C +#define R_028690_SPI_PS_INPUT_CNTL_19 0x00028690 +#define R_028694_SPI_PS_INPUT_CNTL_20 0x00028694 +#define R_028698_SPI_PS_INPUT_CNTL_21 0x00028698 +#define R_02869C_SPI_PS_INPUT_CNTL_22 0x0002869C +#define R_0286A0_SPI_PS_INPUT_CNTL_23 0x000286A0 +#define R_0286A4_SPI_PS_INPUT_CNTL_24 0x000286A4 +#define R_0286A8_SPI_PS_INPUT_CNTL_25 0x000286A8 +#define R_0286AC_SPI_PS_INPUT_CNTL_26 0x000286AC +#define R_0286B0_SPI_PS_INPUT_CNTL_27 0x000286B0 +#define R_0286B4_SPI_PS_INPUT_CNTL_28 0x000286B4 +#define R_0286B8_SPI_PS_INPUT_CNTL_29 0x000286B8 +#define R_0286BC_SPI_PS_INPUT_CNTL_30 0x000286BC +#define R_0286C0_SPI_PS_INPUT_CNTL_31 0x000286C0 +#define R_0286C8_SPI_THREAD_GROUPING 0x000286C8 +#define R_0286D8_SPI_INPUT_Z 0x000286D8 +#define R_0286DC_SPI_FOG_CNTL 0x000286DC +#define R_0286E4_SPI_PS_IN_CONTROL_2 0x000286E4 +#define R_0286E8_SPI_COMPUTE_INPUT_CNTL 0x000286E8 +#define R_028780_CB_BLEND0_CONTROL 0x00028780 +#define R_028784_CB_BLEND1_CONTROL 0x00028784 +#define R_028788_CB_BLEND2_CONTROL 0x00028788 +#define R_02878C_CB_BLEND3_CONTROL 0x0002878C +#define R_028790_CB_BLEND4_CONTROL 0x00028790 +#define R_028794_CB_BLEND5_CONTROL 0x00028794 +#define R_028798_CB_BLEND6_CONTROL 0x00028798 +#define R_02879C_CB_BLEND7_CONTROL 0x0002879C +#define R_028818_PA_CL_VTE_CNTL 0x00028818 +#define R_028820_PA_CL_NANINF_CNTL 0x00028820 +#define R_028838_SQ_DYN_GPR_RESOURCE_LIMIT_1 0x00028838 +#define R_028840_SQ_PGM_START_PS 0x00028840 +#define R_02884C_SQ_PGM_EXPORTS_PS 0x0002884C +#define S_02884C_EXPORT_COLORS(x) (((x) & 0xF) << 1) +#define G_02884C_EXPORT_COLORS(x) (((x) >> 1) & 0xF) +#define C_02884C_EXPORT_COLORS 0xFFFFFFE1 +#define S_02884C_EXPORT_Z(x) (((x) & 0x1) << 0) +#define G_02884C_EXPORT_Z(x) (((x) >> 0) & 0x1) +#define C_02884C_EXPORT_Z 0xFFFFFFFE +#define R_02885C_SQ_PGM_START_VS 0x0002885C +#define R_0288A4_SQ_PGM_START_FS 0x000288A4 +#define R_0288A8_SQ_PGM_RESOURCES_FS 0x000288A8 +#define R_0288EC_SQ_LDS_ALLOC_PS 0x000288EC +#define R_028900_SQ_ESGS_RING_ITEMSIZE 0x00028900 +#define R_028904_SQ_GSVS_RING_ITEMSIZE 0x00028904 +#define R_028908_SQ_ESTMP_RING_ITEMSIZE 0x00028908 +#define R_02890C_SQ_GSTMP_RING_ITEMSIZE 0x0002890C +#define R_028910_SQ_VSTMP_RING_ITEMSIZE 0x00028910 +#define R_028914_SQ_PSTMP_RING_ITEMSIZE 0x00028914 +#define R_02891C_SQ_GS_VERT_ITEMSIZE 0x0002891C +#define R_028920_SQ_GS_VERT_ITEMSIZE_1 0x00028920 +#define R_028924_SQ_GS_VERT_ITEMSIZE_2 0x00028924 +#define R_028928_SQ_GS_VERT_ITEMSIZE_3 0x00028928 +#define R_028940_ALU_CONST_CACHE_PS_0 0x00028940 +#define R_028980_ALU_CONST_CACHE_VS_0 0x00028980 +#define R_028A04_PA_SU_POINT_MINMAX 0x00028A04 +#define R_028A08_PA_SU_LINE_CNTL 0x00028A08 +#define S_028A08_WIDTH(x) (((x) & 0xFFFF) << 0) +#define G_028A08_WIDTH(x) (((x) >> 0) & 0xFFFF) +#define C_028A08_WIDTH 0xFFFF0000 +#define R_028A10_VGT_OUTPUT_PATH_CNTL 0x00028A10 +#define R_028A14_VGT_HOS_CNTL 0x00028A14 +#define R_028A18_VGT_HOS_MAX_TESS_LEVEL 0x00028A18 +#define R_028A1C_VGT_HOS_MIN_TESS_LEVEL 0x00028A1C +#define R_028A20_VGT_HOS_REUSE_DEPTH 0x00028A20 +#define R_028A24_VGT_GROUP_PRIM_TYPE 0x00028A24 +#define R_028A28_VGT_GROUP_FIRST_DECR 0x00028A28 +#define R_028A2C_VGT_GROUP_DECR 0x00028A2C +#define R_028A30_VGT_GROUP_VECT_0_CNTL 0x00028A30 +#define R_028A34_VGT_GROUP_VECT_1_CNTL 0x00028A34 +#define R_028A38_VGT_GROUP_VECT_0_FMT_CNTL 0x00028A38 +#define R_028A3C_VGT_GROUP_VECT_1_FMT_CNTL 0x00028A3C +#define R_028A48_PA_SC_MODE_CNTL_0 0x00028A48 +#define R_028A4C_PA_SC_MODE_CNTL_1 0x00028A4C +#define R_028AB4_VGT_REUSE_OFF 0x00028AB4 +#define R_028AB8_VGT_VTX_CNT_EN 0x00028AB8 +#define R_028ABC_DB_HTILE_SURFACE 0x00028ABC +#define R_028AC0_DB_SRESULTS_COMPARE_STATE0 0x00028AC0 +#define R_028AC4_DB_SRESULTS_COMPARE_STATE1 0x00028AC4 +#define R_028AC8_DB_PRELOAD_CONTROL 0x00028AC8 +#define R_028B54_VGT_SHADER_STAGES_EN 0x00028B54 +#define R_028B70_DB_ALPHA_TO_MASK 0x00028B70 +#define R_028B78_PA_SU_POLY_OFFSET_DB_FMT_CNTL 0x00028B78 +#define S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(x) (((x) & 0xFF) << 0) +#define G_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(x) (((x) >> 0) & 0xFF) +#define C_028B78_POLY_OFFSET_NEG_NUM_DB_BITS 0xFFFFFF00 +#define S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(x) (((x) & 0x1) << 8) +#define G_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(x) (((x) >> 8) & 0x1) +#define C_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT 0xFFFFFEFF +#define R_028B7C_PA_SU_POLY_OFFSET_CLAMP 0x00028B7C +#define R_028B80_PA_SU_POLY_OFFSET_FRONT_SCALE 0x00028B80 +#define S_028B80_SCALE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028B80_SCALE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028B80_SCALE 0x00000000 +#define R_028B84_PA_SU_POLY_OFFSET_FRONT_OFFSET 0x00028B84 +#define S_028B84_OFFSET(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028B84_OFFSET(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028B84_OFFSET 0x00000000 +#define R_028B88_PA_SU_POLY_OFFSET_BACK_SCALE 0x00028B88 +#define S_028B88_SCALE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028B88_SCALE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028B88_SCALE 0x00000000 +#define R_028B8C_PA_SU_POLY_OFFSET_BACK_OFFSET 0x00028B8C +#define S_028B8C_OFFSET(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028B8C_OFFSET(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028B8C_OFFSET 0x00000000 +#define R_028B94_VGT_STRMOUT_CONFIG 0x00028B94 +#define R_028B98_VGT_STRMOUT_BUFFER_CONFIG 0x00028B98 +#define R_028C00_PA_SC_LINE_CNTL 0x00028C00 +#define R_028C04_PA_SC_AA_CONFIG 0x00028C04 +#define R_028C08_PA_SU_VTX_CNTL 0x00028C08 +#define S_028C08_PIX_CENTER_HALF(x) (((x) & 0x1) << 0) +#define G_028C08_PIX_CENTER_HALF(x) (((x) >> 0) & 0x1) +#define C_028C08_PIX_CENTER_HALF 0xFFFFFFFE +#define R_028C0C_PA_CL_GB_VERT_CLIP_ADJ 0x00028C0C +#define R_028C10_PA_CL_GB_VERT_DISC_ADJ 0x00028C10 +#define R_028C14_PA_CL_GB_HORZ_CLIP_ADJ 0x00028C14 +#define R_028C18_PA_CL_GB_HORZ_DISC_ADJ 0x00028C18 +#define R_028C1C_PA_SC_AA_SAMPLE_LOCS_MCTX 0x00028C1C +#define R_028C3C_PA_SC_AA_MASK 0x00028C3C +#define R_028C60_CB_COLOR0_BASE 0x00028C60 +#define R_028C6C_CB_COLOR0_VIEW 0x00028C6C +#define R_028C9C_CB_COLOR1_BASE 0x00028C9C +#define R_028CA0_CB_COLOR1_PITCH 0x00028CA0 +#define R_028CA4_CB_COLOR1_SLICE 0x00028CA4 +#define R_028CA8_CB_COLOR1_VIEW 0x00028CA8 +#define R_028CAC_CB_COLOR1_INFO 0x00028CAC +#define R_028CB0_CB_COLOR1_ATTRIB 0x00028CB0 +#define R_028CB4_CB_COLOR1_DIM 0x00028CB4 +#define R_028CD8_CB_COLOR2_BASE 0x00028CD8 +#define R_028CDC_CB_COLOR2_PITCH 0x00028CDC +#define R_028CE0_CB_COLOR2_SLICE 0x00028CE0 +#define R_028CE4_CB_COLOR2_VIEW 0x00028CE4 +#define R_028CE8_CB_COLOR2_INFO 0x00028CE8 +#define R_028CEC_CB_COLOR2_ATTRIB 0x00028CEC +#define R_028CF0_CB_COLOR2_DIM 0x00028CF0 +#define R_028D14_CB_COLOR3_BASE 0x00028D14 +#define R_028D18_CB_COLOR3_PITCH 0x00028D18 +#define R_028D1C_CB_COLOR3_SLICE 0x00028D1C +#define R_028D20_CB_COLOR3_VIEW 0x00028D20 +#define R_028D24_CB_COLOR3_INFO 0x00028D24 +#define R_028D28_CB_COLOR3_ATTRIB 0x00028D28 +#define R_028D2C_CB_COLOR3_DIM 0x00028D2C +#define R_028D50_CB_COLOR4_BASE 0x00028D50 +#define R_028D54_CB_COLOR4_PITCH 0x00028D54 +#define R_028D58_CB_COLOR4_SLICE 0x00028D58 +#define R_028D5C_CB_COLOR4_VIEW 0x00028D5C +#define R_028D60_CB_COLOR4_INFO 0x00028D60 +#define R_028D64_CB_COLOR4_ATTRIB 0x00028D64 +#define R_028D68_CB_COLOR4_DIM 0x00028D68 +#define R_028D8C_CB_COLOR5_BASE 0x00028D8C +#define R_028D90_CB_COLOR5_PITCH 0x00028D90 +#define R_028D94_CB_COLOR5_SLICE 0x00028D94 +#define R_028D98_CB_COLOR5_VIEW 0x00028D98 +#define R_028D9C_CB_COLOR5_INFO 0x00028D9C +#define R_028DA0_CB_COLOR5_ATTRIB 0x00028DA0 +#define R_028DA4_CB_COLOR5_DIM 0x00028DA4 +#define R_028DC8_CB_COLOR6_BASE 0x00028DC8 +#define R_028DCC_CB_COLOR6_PITCH 0x00028DCC +#define R_028DD0_CB_COLOR6_SLICE 0x00028DD0 +#define R_028DD4_CB_COLOR6_VIEW 0x00028DD4 +#define R_028DD8_CB_COLOR6_INFO 0x00028DD8 +#define R_028DDC_CB_COLOR6_ATTRIB 0x00028DDC +#define R_028DE0_CB_COLOR6_DIM 0x00028DE0 +#define R_028E04_CB_COLOR7_BASE 0x00028E04 +#define R_028E08_CB_COLOR7_PITCH 0x00028E08 +#define R_028E0C_CB_COLOR7_SLICE 0x00028E0C +#define R_028E10_CB_COLOR7_VIEW 0x00028E10 +#define R_028E14_CB_COLOR7_INFO 0x00028E14 +#define R_028E18_CB_COLOR7_ATTRIB 0x00028E18 +#define R_028E1C_CB_COLOR7_DIM 0x00028E1C +#define R_028E40_CB_COLOR8_BASE 0x00028E40 +#define R_028E44_CB_COLOR8_PITCH 0x00028E44 +#define R_028E48_CB_COLOR8_SLICE 0x00028E48 +#define R_028E4C_CB_COLOR8_VIEW 0x00028E4C +#define R_028E50_CB_COLOR8_INFO 0x00028E50 +#define R_028E54_CB_COLOR8_ATTRIB 0x00028E54 +#define R_028E58_CB_COLOR8_DIM 0x00028E58 +#define R_028E5C_CB_COLOR9_BASE 0x00028E5C +#define R_028E60_CB_COLOR9_PITCH 0x00028E60 +#define R_028E64_CB_COLOR9_SLICE 0x00028E64 +#define R_028E68_CB_COLOR9_VIEW 0x00028E68 +#define R_028E6C_CB_COLOR9_INFO 0x00028E6C +#define R_028E70_CB_COLOR9_ATTRIB 0x00028E70 +#define R_028E74_CB_COLOR9_DIM 0x00028E74 +#define R_028E78_CB_COLOR10_BASE 0x00028E78 +#define R_028E7C_CB_COLOR10_PITCH 0x00028E7C +#define R_028E80_CB_COLOR10_SLICE 0x00028E80 +#define R_028E84_CB_COLOR10_VIEW 0x00028E84 +#define R_028E88_CB_COLOR10_INFO 0x00028E88 +#define R_028E8C_CB_COLOR10_ATTRIB 0x00028E8C +#define R_028E90_CB_COLOR10_DIM 0x00028E90 +#define R_028E94_CB_COLOR11_BASE 0x00028E94 +#define R_028E98_CB_COLOR11_PITCH 0x00028E98 +#define R_028E9C_CB_COLOR11_SLICE 0x00028E9C +#define R_028EA0_CB_COLOR11_VIEW 0x00028EA0 +#define R_028EA4_CB_COLOR11_INFO 0x00028EA4 +#define R_028EA8_CB_COLOR11_ATTRIB 0x00028EA8 +#define R_028EAC_CB_COLOR11_DIM 0x00028EAC +#define R_030000_RESOURCE0_WORD0 0x00030000 +#define R_030004_RESOURCE0_WORD1 0x00030004 +#define R_030008_RESOURCE0_WORD2 0x00030008 +#define R_03000C_RESOURCE0_WORD3 0x0003000C +#define R_030010_RESOURCE0_WORD4 0x00030010 +#define R_030014_RESOURCE0_WORD5 0x00030014 +#define R_030018_RESOURCE0_WORD6 0x00030018 +#define R_03001C_RESOURCE0_WORD7 0x0003001C +#define R_0085F0_CP_COHER_CNTL 0x0085F0 +#define S_0085F0_DEST_BASE_0_ENA(x) (((x) & 0x1) << 0) +#define G_0085F0_DEST_BASE_0_ENA(x) (((x) >> 0) & 0x1) +#define C_0085F0_DEST_BASE_0_ENA 0xFFFFFFFE +#define S_0085F0_DEST_BASE_1_ENA(x) (((x) & 0x1) << 1) +#define G_0085F0_DEST_BASE_1_ENA(x) (((x) >> 1) & 0x1) +#define C_0085F0_DEST_BASE_1_ENA 0xFFFFFFFD +#define S_0085F0_SO0_DEST_BASE_ENA(x) (((x) & 0x1) << 2) +#define G_0085F0_SO0_DEST_BASE_ENA(x) (((x) >> 2) & 0x1) +#define C_0085F0_SO0_DEST_BASE_ENA 0xFFFFFFFB +#define S_0085F0_SO1_DEST_BASE_ENA(x) (((x) & 0x1) << 3) +#define G_0085F0_SO1_DEST_BASE_ENA(x) (((x) >> 3) & 0x1) +#define C_0085F0_SO1_DEST_BASE_ENA 0xFFFFFFF7 +#define S_0085F0_SO2_DEST_BASE_ENA(x) (((x) & 0x1) << 4) +#define G_0085F0_SO2_DEST_BASE_ENA(x) (((x) >> 4) & 0x1) +#define C_0085F0_SO2_DEST_BASE_ENA 0xFFFFFFEF +#define S_0085F0_SO3_DEST_BASE_ENA(x) (((x) & 0x1) << 5) +#define G_0085F0_SO3_DEST_BASE_ENA(x) (((x) >> 5) & 0x1) +#define C_0085F0_SO3_DEST_BASE_ENA 0xFFFFFFDF +#define S_0085F0_CB0_DEST_BASE_ENA(x) (((x) & 0x1) << 6) +#define G_0085F0_CB0_DEST_BASE_ENA(x) (((x) >> 6) & 0x1) +#define C_0085F0_CB0_DEST_BASE_ENA 0xFFFFFFBF +#define S_0085F0_CB1_DEST_BASE_ENA(x) (((x) & 0x1) << 7) +#define G_0085F0_CB1_DEST_BASE_ENA(x) (((x) >> 7) & 0x1) +#define C_0085F0_CB1_DEST_BASE_ENA 0xFFFFFF7F +#define S_0085F0_CB2_DEST_BASE_ENA(x) (((x) & 0x1) << 8) +#define G_0085F0_CB2_DEST_BASE_ENA(x) (((x) >> 8) & 0x1) +#define C_0085F0_CB2_DEST_BASE_ENA 0xFFFFFEFF +#define S_0085F0_CB3_DEST_BASE_ENA(x) (((x) & 0x1) << 9) +#define G_0085F0_CB3_DEST_BASE_ENA(x) (((x) >> 9) & 0x1) +#define C_0085F0_CB3_DEST_BASE_ENA 0xFFFFFDFF +#define S_0085F0_CB4_DEST_BASE_ENA(x) (((x) & 0x1) << 10) +#define G_0085F0_CB4_DEST_BASE_ENA(x) (((x) >> 10) & 0x1) +#define C_0085F0_CB4_DEST_BASE_ENA 0xFFFFFBFF +#define S_0085F0_CB5_DEST_BASE_ENA(x) (((x) & 0x1) << 11) +#define G_0085F0_CB5_DEST_BASE_ENA(x) (((x) >> 11) & 0x1) +#define C_0085F0_CB5_DEST_BASE_ENA 0xFFFFF7FF +#define S_0085F0_CB6_DEST_BASE_ENA(x) (((x) & 0x1) << 12) +#define G_0085F0_CB6_DEST_BASE_ENA(x) (((x) >> 12) & 0x1) +#define C_0085F0_CB6_DEST_BASE_ENA 0xFFFFEFFF +#define S_0085F0_CB7_DEST_BASE_ENA(x) (((x) & 0x1) << 13) +#define G_0085F0_CB7_DEST_BASE_ENA(x) (((x) >> 13) & 0x1) +#define C_0085F0_CB7_DEST_BASE_ENA 0xFFFFDFFF +#define S_0085F0_DB_DEST_BASE_ENA(x) (((x) & 0x1) << 14) +#define G_0085F0_DB_DEST_BASE_ENA(x) (((x) >> 14) & 0x1) +#define C_0085F0_DB_DEST_BASE_ENA 0xFFFFBFFF +#define S_0085F0_CB8_DEST_BASE_ENA(x) (((x) & 0x1) << 15) +#define G_0085F0_CB8_DEST_BASE_ENA(x) (((x) >> 15) & 0x1) + +#define S_0085F0_CB9_DEST_BASE_ENA(x) (((x) & 0x1) << 16) +#define G_0085F0_CB9_DEST_BASE_ENA(x) (((x) >> 16) & 0x1) + +#define S_0085F0_CB10_DEST_BASE_ENA(x) (((x) & 0x1) << 17) +#define G_0085F0_CB10_DEST_BASE_ENA(x) (((x) >> 17) & 0x1) + +#define S_0085F0_CB11_DEST_BASE_ENA(x) (((x) & 0x1) << 18) +#define G_0085F0_CB11_DEST_BASE_ENA(x) (((x) >> 18) & 0x1) + +#define S_0085F0_TC_ACTION_ENA(x) (((x) & 0x1) << 23) +#define G_0085F0_TC_ACTION_ENA(x) (((x) >> 23) & 0x1) +#define C_0085F0_TC_ACTION_ENA 0xFF7FFFFF +#define S_0085F0_VC_ACTION_ENA(x) (((x) & 0x1) << 24) +#define G_0085F0_VC_ACTION_ENA(x) (((x) >> 24) & 0x1) +#define C_0085F0_VC_ACTION_ENA 0xFEFFFFFF +#define S_0085F0_CB_ACTION_ENA(x) (((x) & 0x1) << 25) +#define G_0085F0_CB_ACTION_ENA(x) (((x) >> 25) & 0x1) +#define C_0085F0_CB_ACTION_ENA 0xFDFFFFFF +#define S_0085F0_DB_ACTION_ENA(x) (((x) & 0x1) << 26) +#define G_0085F0_DB_ACTION_ENA(x) (((x) >> 26) & 0x1) +#define C_0085F0_DB_ACTION_ENA 0xFBFFFFFF +#define S_0085F0_SH_ACTION_ENA(x) (((x) & 0x1) << 27) +#define G_0085F0_SH_ACTION_ENA(x) (((x) >> 27) & 0x1) +#define C_0085F0_SH_ACTION_ENA 0xF7FFFFFF +#define S_0085F0_SMX_ACTION_ENA(x) (((x) & 0x1) << 28) +#define G_0085F0_SMX_ACTION_ENA(x) (((x) >> 28) & 0x1) +#define C_0085F0_SMX_ACTION_ENA 0xEFFFFFFF +#define S_0085F0_CR0_ACTION_ENA(x) (((x) & 0x1) << 29) +#define G_0085F0_CR0_ACTION_ENA(x) (((x) >> 29) & 0x1) +#define C_0085F0_CR0_ACTION_ENA 0xDFFFFFFF +#define S_0085F0_CR1_ACTION_ENA(x) (((x) & 0x1) << 30) +#define G_0085F0_CR1_ACTION_ENA(x) (((x) >> 30) & 0x1) +#define C_0085F0_CR1_ACTION_ENA 0xBFFFFFFF +#define S_0085F0_CR2_ACTION_ENA(x) (((x) & 0x1) << 31) +#define G_0085F0_CR2_ACTION_ENA(x) (((x) >> 31) & 0x1) +#define C_0085F0_CR2_ACTION_ENA 0x7FFFFFFF +#define R_008970_VGT_NUM_INDICES 0x008970 +#define R_0287F0_VGT_DRAW_INITIATOR 0x0287F0 + +#define R_03CFF0_SQ_VTX_BASE_VTX_LOC 0x03CFF0 +#define R_03CFF4_SQ_VTX_START_INST_LOC 0x03CFF4 + +#define R_03A200_SQ_LOOP_CONST_0 0x3A200 +#endif diff --git a/src/gallium/drivers/r600/r600.h b/src/gallium/drivers/r600/r600.h new file mode 100644 index 0000000..ff00682 --- /dev/null +++ b/src/gallium/drivers/r600/r600.h @@ -0,0 +1,299 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#ifndef R600_H +#define R600_H + +#include +#include +#include +#include +#include + +#define RADEON_CTX_MAX_PM4 (64 * 1024 / 4) + +#define R600_ERR(fmt, args...) \ + fprintf(stderr, "EE %s/%s:%d - "fmt, __FILE__, __func__, __LINE__, ##args) + +typedef uint64_t u64; +typedef uint32_t u32; +typedef uint16_t u16; +typedef uint8_t u8; + +struct radeon; +struct winsys_handle; + +enum radeon_family { + CHIP_UNKNOWN, + CHIP_R100, + CHIP_RV100, + CHIP_RS100, + CHIP_RV200, + CHIP_RS200, + CHIP_R200, + CHIP_RV250, + CHIP_RS300, + CHIP_RV280, + CHIP_R300, + CHIP_R350, + CHIP_RV350, + CHIP_RV380, + CHIP_R420, + CHIP_R423, + CHIP_RV410, + CHIP_RS400, + CHIP_RS480, + CHIP_RS600, + CHIP_RS690, + CHIP_RS740, + CHIP_RV515, + CHIP_R520, + CHIP_RV530, + CHIP_RV560, + CHIP_RV570, + CHIP_R580, + CHIP_R600, + CHIP_RV610, + CHIP_RV630, + CHIP_RV670, + CHIP_RV620, + CHIP_RV635, + CHIP_RS780, + CHIP_RS880, + CHIP_RV770, + CHIP_RV730, + CHIP_RV710, + CHIP_RV740, + CHIP_CEDAR, + CHIP_REDWOOD, + CHIP_JUNIPER, + CHIP_CYPRESS, + CHIP_HEMLOCK, + CHIP_PALM, + CHIP_BARTS, + CHIP_TURKS, + CHIP_CAICOS, + CHIP_LAST, +}; + +enum chip_class { + R600, + R700, + EVERGREEN, +}; + +struct r600_tiling_info { + unsigned num_channels; + unsigned num_banks; + unsigned group_bytes; +}; + +enum radeon_family r600_get_family(struct radeon *rw); +enum chip_class r600_get_family_class(struct radeon *radeon); +struct r600_tiling_info *r600_get_tiling_info(struct radeon *radeon); + +/* r600_bo.c */ +struct r600_bo; +struct r600_bo *r600_bo(struct radeon *radeon, + unsigned size, unsigned alignment, + unsigned binding, unsigned usage); +struct r600_bo *r600_bo_handle(struct radeon *radeon, + unsigned handle, unsigned *array_mode); +void *r600_bo_map(struct radeon *radeon, struct r600_bo *bo, unsigned usage, void *ctx); +void r600_bo_unmap(struct radeon *radeon, struct r600_bo *bo); +void r600_bo_reference(struct radeon *radeon, struct r600_bo **dst, + struct r600_bo *src); +boolean r600_bo_get_winsys_handle(struct radeon *radeon, struct r600_bo *pb_bo, + unsigned stride, struct winsys_handle *whandle); +static INLINE unsigned r600_bo_offset(struct r600_bo *bo) +{ + return 0; +} + + +/* R600/R700 STATES */ +#define R600_GROUP_MAX 16 +#define R600_BLOCK_MAX_BO 32 +#define R600_BLOCK_MAX_REG 128 + +struct r600_pipe_reg { + u32 offset; + u32 mask; + u32 value; + struct r600_bo *bo; +}; + +struct r600_pipe_state { + unsigned id; + unsigned nregs; + struct r600_pipe_reg regs[R600_BLOCK_MAX_REG]; +}; + +static inline void r600_pipe_state_add_reg(struct r600_pipe_state *state, + u32 offset, u32 value, u32 mask, + struct r600_bo *bo) +{ + state->regs[state->nregs].offset = offset; + state->regs[state->nregs].value = value; + state->regs[state->nregs].mask = mask; + state->regs[state->nregs].bo = bo; + state->nregs++; + assert(state->nregs < R600_BLOCK_MAX_REG); +} + +#define R600_BLOCK_STATUS_ENABLED (1 << 0) +#define R600_BLOCK_STATUS_DIRTY (1 << 1) + +struct r600_block_reloc { + struct r600_bo *bo; + unsigned flush_flags; + unsigned flush_mask; + unsigned bo_pm4_index; +}; + +struct r600_block { + struct list_head list; + unsigned status; + unsigned start_offset; + unsigned pm4_ndwords; + unsigned pm4_flush_ndwords; + unsigned nbo; + unsigned nreg; + u32 *reg; + u32 pm4[R600_BLOCK_MAX_REG]; + unsigned pm4_bo_index[R600_BLOCK_MAX_REG]; + struct r600_block_reloc reloc[R600_BLOCK_MAX_BO]; +}; + +struct r600_range { + unsigned start_offset; + unsigned end_offset; + struct r600_block **blocks; +}; + +/* + * relocation + */ +#pragma pack(1) +struct r600_reloc { + uint32_t handle; + uint32_t read_domain; + uint32_t write_domain; + uint32_t flags; +}; +#pragma pack() + +/* + * query + */ +struct r600_query { + u64 result; + /* The kind of query. Currently only OQ is supported. */ + unsigned type; + /* How many results have been written, in dwords. It's incremented + * after end_query and flush. */ + unsigned num_results; + /* if we've flushed the query */ + unsigned state; + /* The buffer where query results are stored. */ + struct r600_bo *buffer; + unsigned buffer_size; + /* linked list of queries */ + struct list_head list; +}; + +#define R600_QUERY_STATE_STARTED (1 << 0) +#define R600_QUERY_STATE_ENDED (1 << 1) +#define R600_QUERY_STATE_SUSPENDED (1 << 2) + + +struct r600_context { + struct radeon *radeon; + unsigned hash_size; + unsigned hash_shift; + struct r600_range range[256]; + unsigned nblocks; + struct r600_block **blocks; + struct list_head dirty; + unsigned pm4_ndwords; + unsigned pm4_cdwords; + unsigned pm4_dirty_cdwords; + unsigned ctx_pm4_ndwords; + unsigned nreloc; + unsigned creloc; + struct r600_reloc *reloc; + struct radeon_bo **bo; + u32 *pm4; + struct list_head query_list; + unsigned num_query_running; + struct list_head fenced_bo; +}; + +struct r600_draw { + u32 vgt_num_indices; + u32 vgt_num_instances; + u32 vgt_index_type; + u32 vgt_draw_initiator; + u32 indices_bo_offset; + struct r600_bo *indices; +}; + +int r600_context_init(struct r600_context *ctx, struct radeon *radeon); +void r600_context_fini(struct r600_context *ctx); +void r600_context_pipe_state_set(struct r600_context *ctx, struct r600_pipe_state *state); +void r600_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); +void r600_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); +void r600_context_pipe_state_set_fs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); +void r600_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id); +void r600_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id); +void r600_context_flush(struct r600_context *ctx); +void r600_context_dump_bof(struct r600_context *ctx, const char *file); +void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw); + +struct r600_query *r600_context_query_create(struct r600_context *ctx, unsigned query_type); +void r600_context_query_destroy(struct r600_context *ctx, struct r600_query *query); +boolean r600_context_query_result(struct r600_context *ctx, + struct r600_query *query, + boolean wait, void *vresult); +void r600_query_begin(struct r600_context *ctx, struct r600_query *query); +void r600_query_end(struct r600_context *ctx, struct r600_query *query); +void r600_context_queries_suspend(struct r600_context *ctx); +void r600_context_queries_resume(struct r600_context *ctx); + +int evergreen_context_init(struct r600_context *ctx, struct radeon *radeon); +void evergreen_context_draw(struct r600_context *ctx, const struct r600_draw *draw); +void evergreen_ps_resource_set(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); +void evergreen_vs_resource_set(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); +void evergreen_fs_resource_set(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); + +void evergreen_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); +void evergreen_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); +void evergreen_context_pipe_state_set_fs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); +void evergreen_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id); +void evergreen_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id); + +struct radeon *radeon_decref(struct radeon *radeon); + +#endif diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c new file mode 100644 index 0000000..9b9f033 --- /dev/null +++ b/src/gallium/drivers/r600/r600_asm.c @@ -0,0 +1,1309 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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 +#include +#include "util/u_format.h" +#include "util/u_memory.h" +#include "pipe/p_shader_tokens.h" +#include "r600_pipe.h" +#include "r600_sq.h" +#include "r600_opcodes.h" +#include "r600_asm.h" +#include "r600_formats.h" +#include "r600d.h" + +static inline unsigned int r600_bc_get_num_operands(struct r600_bc_alu *alu) +{ + if(alu->is_op3) + return 3; + + switch (alu->inst) { + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP: + return 0; + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE: + return 2; + + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN: + case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS: + return 1; + default: R600_ERR( + "Need instruction operand number for 0x%x.\n", alu->inst); + }; + + return 3; +} + +int r700_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsigned id); + +static struct r600_bc_cf *r600_bc_cf(void) +{ + struct r600_bc_cf *cf = CALLOC_STRUCT(r600_bc_cf); + + if (cf == NULL) + return NULL; + LIST_INITHEAD(&cf->list); + LIST_INITHEAD(&cf->alu); + LIST_INITHEAD(&cf->vtx); + LIST_INITHEAD(&cf->tex); + return cf; +} + +static struct r600_bc_alu *r600_bc_alu(void) +{ + struct r600_bc_alu *alu = CALLOC_STRUCT(r600_bc_alu); + + if (alu == NULL) + return NULL; + LIST_INITHEAD(&alu->list); + LIST_INITHEAD(&alu->bs_list); + return alu; +} + +static struct r600_bc_vtx *r600_bc_vtx(void) +{ + struct r600_bc_vtx *vtx = CALLOC_STRUCT(r600_bc_vtx); + + if (vtx == NULL) + return NULL; + LIST_INITHEAD(&vtx->list); + return vtx; +} + +static struct r600_bc_tex *r600_bc_tex(void) +{ + struct r600_bc_tex *tex = CALLOC_STRUCT(r600_bc_tex); + + if (tex == NULL) + return NULL; + LIST_INITHEAD(&tex->list); + return tex; +} + +int r600_bc_init(struct r600_bc *bc, enum radeon_family family) +{ + LIST_INITHEAD(&bc->cf); + bc->family = family; + switch (bc->family) { + case CHIP_R600: + case CHIP_RV610: + case CHIP_RV630: + case CHIP_RV670: + case CHIP_RV620: + case CHIP_RV635: + case CHIP_RS780: + case CHIP_RS880: + bc->chiprev = CHIPREV_R600; + break; + case CHIP_RV770: + case CHIP_RV730: + case CHIP_RV710: + case CHIP_RV740: + bc->chiprev = CHIPREV_R700; + break; + case CHIP_CEDAR: + case CHIP_REDWOOD: + case CHIP_JUNIPER: + case CHIP_CYPRESS: + case CHIP_HEMLOCK: + case CHIP_PALM: + case CHIP_BARTS: + case CHIP_TURKS: + case CHIP_CAICOS: + bc->chiprev = CHIPREV_EVERGREEN; + break; + default: + R600_ERR("unknown family %d\n", bc->family); + return -EINVAL; + } + return 0; +} + +static int r600_bc_add_cf(struct r600_bc *bc) +{ + struct r600_bc_cf *cf = r600_bc_cf(); + + if (cf == NULL) + return -ENOMEM; + LIST_ADDTAIL(&cf->list, &bc->cf); + if (bc->cf_last) + cf->id = bc->cf_last->id + 2; + bc->cf_last = cf; + bc->ncf++; + bc->ndw += 2; + bc->force_add_cf = 0; + return 0; +} + +int r600_bc_add_output(struct r600_bc *bc, const struct r600_bc_output *output) +{ + int r; + + r = r600_bc_add_cf(bc); + if (r) + return r; + bc->cf_last->inst = output->inst; + memcpy(&bc->cf_last->output, output, sizeof(struct r600_bc_output)); + return 0; +} + +const unsigned bank_swizzle_vec[8] = {SQ_ALU_VEC_210, //000 + SQ_ALU_VEC_120, //001 + SQ_ALU_VEC_102, //010 + + SQ_ALU_VEC_201, //011 + SQ_ALU_VEC_012, //100 + SQ_ALU_VEC_021, //101 + + SQ_ALU_VEC_012, //110 + SQ_ALU_VEC_012}; //111 + +const unsigned bank_swizzle_scl[8] = {SQ_ALU_SCL_210, //000 + SQ_ALU_SCL_122, //001 + SQ_ALU_SCL_122, //010 + + SQ_ALU_SCL_221, //011 + SQ_ALU_SCL_212, //100 + SQ_ALU_SCL_122, //101 + + SQ_ALU_SCL_122, //110 + SQ_ALU_SCL_122}; //111 + +static int init_gpr(struct r600_bc_alu *alu) +{ + int cycle, component; + /* set up gpr use */ + for (cycle = 0; cycle < NUM_OF_CYCLES; cycle++) + for (component = 0; component < NUM_OF_COMPONENTS; component++) + alu->hw_gpr[cycle][component] = -1; + return 0; +} + +#if 0 +static int reserve_gpr(struct r600_bc_alu *alu, unsigned sel, unsigned chan, unsigned cycle) +{ + if (alu->hw_gpr[cycle][chan] < 0) + alu->hw_gpr[cycle][chan] = sel; + else if (alu->hw_gpr[cycle][chan] != (int)sel) { + R600_ERR("Another scalar operation has already used GPR read port for channel\n"); + return -1; + } + return 0; +} + +static int cycle_for_scalar_bank_swizzle(const int swiz, const int sel, unsigned *p_cycle) +{ + int table[3]; + int ret = 0; + switch (swiz) { + case SQ_ALU_SCL_210: + table[0] = 2; table[1] = 1; table[2] = 0; + *p_cycle = table[sel]; + break; + case SQ_ALU_SCL_122: + table[0] = 1; table[1] = 2; table[2] = 2; + *p_cycle = table[sel]; + break; + case SQ_ALU_SCL_212: + table[0] = 2; table[1] = 1; table[2] = 2; + *p_cycle = table[sel]; + break; + case SQ_ALU_SCL_221: + table[0] = 2; table[1] = 2; table[2] = 1; + *p_cycle = table[sel]; + break; + break; + default: + R600_ERR("bad scalar bank swizzle value\n"); + ret = -1; + break; + } + return ret; +} + +static int cycle_for_vector_bank_swizzle(const int swiz, const int sel, unsigned *p_cycle) +{ + int table[3]; + int ret; + + switch (swiz) { + case SQ_ALU_VEC_012: + table[0] = 0; table[1] = 1; table[2] = 2; + *p_cycle = table[sel]; + break; + case SQ_ALU_VEC_021: + table[0] = 0; table[1] = 2; table[2] = 1; + *p_cycle = table[sel]; + break; + case SQ_ALU_VEC_120: + table[0] = 1; table[1] = 2; table[2] = 0; + *p_cycle = table[sel]; + break; + case SQ_ALU_VEC_102: + table[0] = 1; table[1] = 0; table[2] = 2; + *p_cycle = table[sel]; + break; + case SQ_ALU_VEC_201: + table[0] = 2; table[1] = 0; table[2] = 1; + *p_cycle = table[sel]; + break; + case SQ_ALU_VEC_210: + table[0] = 2; table[1] = 1; table[2] = 0; + *p_cycle = table[sel]; + break; + default: + R600_ERR("bad vector bank swizzle value\n"); + ret = -1; + break; + } + return ret; +} + + + +static void update_chan_counter(struct r600_bc_alu *alu, int *chan_counter) +{ + int num_src; + int i; + int channel_swizzle; + + num_src = r600_bc_get_num_operands(alu); + + for (i = 0; i < num_src; i++) { + channel_swizzle = alu->src[i].chan; + if ((alu->src[i].sel > 0 && alu->src[i].sel < 128) && channel_swizzle <= 3) + chan_counter[channel_swizzle]++; + } +} + +/* we need something like this I think - but this is bogus */ +int check_read_slots(struct r600_bc *bc, struct r600_bc_alu *alu_first) +{ + struct r600_bc_alu *alu; + int chan_counter[4] = { 0 }; + + update_chan_counter(alu_first, chan_counter); + + LIST_FOR_EACH_ENTRY(alu, &alu_first->bs_list, bs_list) { + update_chan_counter(alu, chan_counter); + } + + if (chan_counter[0] > 3 || + chan_counter[1] > 3 || + chan_counter[2] > 3 || + chan_counter[3] > 3) { + R600_ERR("needed to split instruction for input ran out of banks %x %d %d %d %d\n", + alu_first->inst, chan_counter[0], chan_counter[1], chan_counter[2], chan_counter[3]); + return -1; + } + return 0; +} +#endif + +static int is_const(int sel) +{ + if (sel > 255 && sel < 512) + return 1; + if (sel >= V_SQ_ALU_SRC_0 && sel <= V_SQ_ALU_SRC_LITERAL) + return 1; + return 0; +} + +static int check_scalar(struct r600_bc *bc, struct r600_bc_alu *alu) +{ + unsigned swizzle_key; + + if (alu->bank_swizzle_force) { + alu->bank_swizzle = alu->bank_swizzle_force; + return 0; + } + swizzle_key = (is_const(alu->src[0].sel) ? 4 : 0 ) + + (is_const(alu->src[1].sel) ? 2 : 0 ) + + (is_const(alu->src[2].sel) ? 1 : 0 ); + + alu->bank_swizzle = bank_swizzle_scl[swizzle_key]; + return 0; +} + +static int check_vector(struct r600_bc *bc, struct r600_bc_alu *alu) +{ + unsigned swizzle_key; + + if (alu->bank_swizzle_force) { + alu->bank_swizzle = alu->bank_swizzle_force; + return 0; + } + swizzle_key = (is_const(alu->src[0].sel) ? 4 : 0 ) + + (is_const(alu->src[1].sel) ? 2 : 0 ) + + (is_const(alu->src[2].sel) ? 1 : 0 ); + + alu->bank_swizzle = bank_swizzle_vec[swizzle_key]; + return 0; +} + +static int check_and_set_bank_swizzle(struct r600_bc *bc, struct r600_bc_alu *alu_first) +{ + struct r600_bc_alu *alu = NULL; + int num_instr = 1; + + init_gpr(alu_first); + + LIST_FOR_EACH_ENTRY(alu, &alu_first->bs_list, bs_list) { + num_instr++; + } + + if (num_instr == 1) { + check_scalar(bc, alu_first); + + } else { +/* check_read_slots(bc, bc->cf_last->curr_bs_head);*/ + check_vector(bc, alu_first); + LIST_FOR_EACH_ENTRY(alu, &alu_first->bs_list, bs_list) { + check_vector(bc, alu); + } + } + return 0; +} + +int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int type) +{ + struct r600_bc_alu *nalu = r600_bc_alu(); + struct r600_bc_alu *lalu; + int i, r; + + if (nalu == NULL) + return -ENOMEM; + memcpy(nalu, alu, sizeof(struct r600_bc_alu)); + nalu->nliteral = 0; + + /* cf can contains only alu or only vtx or only tex */ + if (bc->cf_last == NULL || bc->cf_last->inst != (type << 3) || + bc->force_add_cf) { + r = r600_bc_add_cf(bc); + if (r) { + free(nalu); + return r; + } + bc->cf_last->inst = (type << 3); + } + if (!bc->cf_last->curr_bs_head) { + bc->cf_last->curr_bs_head = nalu; + LIST_INITHEAD(&nalu->bs_list); + } else { + LIST_ADDTAIL(&nalu->bs_list, &bc->cf_last->curr_bs_head->bs_list); + } + /* at most 128 slots, one add alu can add 4 slots + 4 constants(2 slots) + * worst case */ + if (alu->last && (bc->cf_last->ndw >> 1) >= 120) { + bc->force_add_cf = 1; + } + /* number of gpr == the last gpr used in any alu */ + for (i = 0; i < 3; i++) { + if (alu->src[i].sel >= bc->ngpr && alu->src[i].sel < 128) { + bc->ngpr = alu->src[i].sel + 1; + } + /* compute how many literal are needed + * either 2 or 4 literals + */ + if (alu->src[i].sel == 253) { + if (((alu->src[i].chan + 2) & 0x6) > nalu->nliteral) { + nalu->nliteral = (alu->src[i].chan + 2) & 0x6; + } + } + } + if (!LIST_IS_EMPTY(&bc->cf_last->alu)) { + lalu = LIST_ENTRY(struct r600_bc_alu, bc->cf_last->alu.prev, list); + if (!lalu->last && lalu->nliteral > nalu->nliteral) { + nalu->nliteral = lalu->nliteral; + } + } + if (alu->dst.sel >= bc->ngpr) { + bc->ngpr = alu->dst.sel + 1; + } + LIST_ADDTAIL(&nalu->list, &bc->cf_last->alu); + /* each alu use 2 dwords */ + bc->cf_last->ndw += 2; + bc->ndw += 2; + + /* The following configuration provides 64 128-bit constants. + * Each cacheline holds 16 128-bit constants and each + * kcache can lock 2 cachelines and there are 2 kcaches per + * ALU clause for a max of 64 constants. + * For supporting more than 64 constants, the code needs + * to be broken down into multiple ALU clauses. + */ + /* select the constant buffer (0-15) for each kcache */ + bc->cf_last->kcache0_bank = 0; + bc->cf_last->kcache1_bank = 0; + /* lock 2 cachelines per kcache; 4 total */ + bc->cf_last->kcache0_mode = V_SQ_CF_KCACHE_LOCK_2; + bc->cf_last->kcache1_mode = V_SQ_CF_KCACHE_LOCK_2; + /* set the cacheline offsets for each kcache */ + bc->cf_last->kcache0_addr = 0; + bc->cf_last->kcache1_addr = 2; + + /* process cur ALU instructions for bank swizzle */ + if (alu->last) { + check_and_set_bank_swizzle(bc, bc->cf_last->curr_bs_head); + bc->cf_last->curr_bs_head = NULL; + } + return 0; +} + +int r600_bc_add_alu(struct r600_bc *bc, const struct r600_bc_alu *alu) +{ + return r600_bc_add_alu_type(bc, alu, BC_INST(bc, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU)); +} + +int r600_bc_add_literal(struct r600_bc *bc, const u32 *value) +{ + struct r600_bc_alu *alu; + + if (bc->cf_last == NULL) { + return 0; + } + if (bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_TEX) { + return 0; + } + /* all same on EG */ + if (bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_JUMP || + bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_ELSE || + bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL || + bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK || + bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE || + bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END || + bc->cf_last->inst == V_SQ_CF_WORD1_SQ_CF_INST_POP) { + return 0; + } + /* same on EG */ + if (((bc->cf_last->inst != (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3)) && + (bc->cf_last->inst != (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3))) || + LIST_IS_EMPTY(&bc->cf_last->alu)) { + R600_ERR("last CF is not ALU (%p)\n", bc->cf_last); + return -EINVAL; + } + alu = LIST_ENTRY(struct r600_bc_alu, bc->cf_last->alu.prev, list); + if (!alu->last || !alu->nliteral || alu->literal_added) { + return 0; + } + memcpy(alu->value, value, 4 * 4); + bc->cf_last->ndw += alu->nliteral; + bc->ndw += alu->nliteral; + alu->literal_added = 1; + return 0; +} + +int r600_bc_add_vtx(struct r600_bc *bc, const struct r600_bc_vtx *vtx) +{ + struct r600_bc_vtx *nvtx = r600_bc_vtx(); + int r; + + if (nvtx == NULL) + return -ENOMEM; + memcpy(nvtx, vtx, sizeof(struct r600_bc_vtx)); + + /* cf can contains only alu or only vtx or only tex */ + if (bc->cf_last == NULL || + (bc->cf_last->inst != V_SQ_CF_WORD1_SQ_CF_INST_VTX && + bc->cf_last->inst != V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC) || + bc->force_add_cf) { + r = r600_bc_add_cf(bc); + if (r) { + free(nvtx); + return r; + } + bc->cf_last->inst = V_SQ_CF_WORD1_SQ_CF_INST_VTX; + } + LIST_ADDTAIL(&nvtx->list, &bc->cf_last->vtx); + /* each fetch use 4 dwords */ + bc->cf_last->ndw += 4; + bc->ndw += 4; + if ((bc->ndw / 4) > 7) + bc->force_add_cf = 1; + return 0; +} + +int r600_bc_add_tex(struct r600_bc *bc, const struct r600_bc_tex *tex) +{ + struct r600_bc_tex *ntex = r600_bc_tex(); + int r; + + if (ntex == NULL) + return -ENOMEM; + memcpy(ntex, tex, sizeof(struct r600_bc_tex)); + + /* cf can contains only alu or only vtx or only tex */ + if (bc->cf_last == NULL || + bc->cf_last->inst != V_SQ_CF_WORD1_SQ_CF_INST_TEX || + bc->force_add_cf) { + r = r600_bc_add_cf(bc); + if (r) { + free(ntex); + return r; + } + bc->cf_last->inst = V_SQ_CF_WORD1_SQ_CF_INST_TEX; + } + LIST_ADDTAIL(&ntex->list, &bc->cf_last->tex); + /* each texture fetch use 4 dwords */ + bc->cf_last->ndw += 4; + bc->ndw += 4; + if ((bc->ndw / 4) > 7) + bc->force_add_cf = 1; + return 0; +} + +int r600_bc_add_cfinst(struct r600_bc *bc, int inst) +{ + int r; + r = r600_bc_add_cf(bc); + if (r) + return r; + + bc->cf_last->cond = V_SQ_CF_COND_ACTIVE; + bc->cf_last->inst = inst; + return 0; +} + +/* common to all 3 families */ +static int r600_bc_vtx_build(struct r600_bc *bc, struct r600_bc_vtx *vtx, unsigned id) +{ + unsigned fetch_resource_start = 0; + + /* check if we are fetch shader */ + /* fetch shader can also access vertex resource, + * first fetch shader resource is at 160 + */ + if (bc->type == -1) { + switch (bc->chiprev) { + /* r600 */ + case CHIPREV_R600: + /* r700 */ + case CHIPREV_R700: + fetch_resource_start = 160; + break; + /* evergreen */ + case CHIPREV_EVERGREEN: + fetch_resource_start = 0; + break; + default: + fprintf(stderr, "%s:%s:%d unknown chiprev %d\n", + __FILE__, __func__, __LINE__, bc->chiprev); + break; + } + } + bc->bytecode[id++] = S_SQ_VTX_WORD0_BUFFER_ID(vtx->buffer_id + fetch_resource_start) | + S_SQ_VTX_WORD0_SRC_GPR(vtx->src_gpr) | + S_SQ_VTX_WORD0_SRC_SEL_X(vtx->src_sel_x) | + S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(vtx->mega_fetch_count); + bc->bytecode[id++] = S_SQ_VTX_WORD1_DST_SEL_X(vtx->dst_sel_x) | + S_SQ_VTX_WORD1_DST_SEL_Y(vtx->dst_sel_y) | + S_SQ_VTX_WORD1_DST_SEL_Z(vtx->dst_sel_z) | + S_SQ_VTX_WORD1_DST_SEL_W(vtx->dst_sel_w) | + S_SQ_VTX_WORD1_USE_CONST_FIELDS(vtx->use_const_fields) | + S_SQ_VTX_WORD1_DATA_FORMAT(vtx->data_format) | + S_SQ_VTX_WORD1_NUM_FORMAT_ALL(vtx->num_format_all) | + S_SQ_VTX_WORD1_FORMAT_COMP_ALL(vtx->format_comp_all) | + S_SQ_VTX_WORD1_SRF_MODE_ALL(vtx->srf_mode_all) | + S_SQ_VTX_WORD1_GPR_DST_GPR(vtx->dst_gpr); + bc->bytecode[id++] = S_SQ_VTX_WORD2_MEGA_FETCH(1); + bc->bytecode[id++] = 0; + return 0; +} + +/* common to all 3 families */ +static int r600_bc_tex_build(struct r600_bc *bc, struct r600_bc_tex *tex, unsigned id) +{ + bc->bytecode[id++] = S_SQ_TEX_WORD0_TEX_INST(tex->inst) | + S_SQ_TEX_WORD0_RESOURCE_ID(tex->resource_id) | + S_SQ_TEX_WORD0_SRC_GPR(tex->src_gpr) | + S_SQ_TEX_WORD0_SRC_REL(tex->src_rel); + bc->bytecode[id++] = S_SQ_TEX_WORD1_DST_GPR(tex->dst_gpr) | + S_SQ_TEX_WORD1_DST_REL(tex->dst_rel) | + S_SQ_TEX_WORD1_DST_SEL_X(tex->dst_sel_x) | + S_SQ_TEX_WORD1_DST_SEL_Y(tex->dst_sel_y) | + S_SQ_TEX_WORD1_DST_SEL_Z(tex->dst_sel_z) | + S_SQ_TEX_WORD1_DST_SEL_W(tex->dst_sel_w) | + S_SQ_TEX_WORD1_LOD_BIAS(tex->lod_bias) | + S_SQ_TEX_WORD1_COORD_TYPE_X(tex->coord_type_x) | + S_SQ_TEX_WORD1_COORD_TYPE_Y(tex->coord_type_y) | + S_SQ_TEX_WORD1_COORD_TYPE_Z(tex->coord_type_z) | + S_SQ_TEX_WORD1_COORD_TYPE_W(tex->coord_type_w); + bc->bytecode[id++] = S_SQ_TEX_WORD2_OFFSET_X(tex->offset_x) | + S_SQ_TEX_WORD2_OFFSET_Y(tex->offset_y) | + S_SQ_TEX_WORD2_OFFSET_Z(tex->offset_z) | + S_SQ_TEX_WORD2_SAMPLER_ID(tex->sampler_id) | + S_SQ_TEX_WORD2_SRC_SEL_X(tex->src_sel_x) | + S_SQ_TEX_WORD2_SRC_SEL_Y(tex->src_sel_y) | + S_SQ_TEX_WORD2_SRC_SEL_Z(tex->src_sel_z) | + S_SQ_TEX_WORD2_SRC_SEL_W(tex->src_sel_w); + bc->bytecode[id++] = 0; + return 0; +} + +/* r600 only, r700/eg bits in r700_asm.c */ +static int r600_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsigned id) +{ + unsigned i; + + /* don't replace gpr by pv or ps for destination register */ + bc->bytecode[id++] = S_SQ_ALU_WORD0_SRC0_SEL(alu->src[0].sel) | + S_SQ_ALU_WORD0_SRC0_REL(alu->src[0].rel) | + S_SQ_ALU_WORD0_SRC0_CHAN(alu->src[0].chan) | + S_SQ_ALU_WORD0_SRC0_NEG(alu->src[0].neg) | + S_SQ_ALU_WORD0_SRC1_SEL(alu->src[1].sel) | + S_SQ_ALU_WORD0_SRC1_REL(alu->src[1].rel) | + S_SQ_ALU_WORD0_SRC1_CHAN(alu->src[1].chan) | + S_SQ_ALU_WORD0_SRC1_NEG(alu->src[1].neg) | + S_SQ_ALU_WORD0_LAST(alu->last); + + if (alu->is_op3) { + bc->bytecode[id++] = S_SQ_ALU_WORD1_DST_GPR(alu->dst.sel) | + S_SQ_ALU_WORD1_DST_CHAN(alu->dst.chan) | + S_SQ_ALU_WORD1_DST_REL(alu->dst.rel) | + S_SQ_ALU_WORD1_CLAMP(alu->dst.clamp) | + S_SQ_ALU_WORD1_OP3_SRC2_SEL(alu->src[2].sel) | + S_SQ_ALU_WORD1_OP3_SRC2_REL(alu->src[2].rel) | + S_SQ_ALU_WORD1_OP3_SRC2_CHAN(alu->src[2].chan) | + S_SQ_ALU_WORD1_OP3_SRC2_NEG(alu->src[2].neg) | + S_SQ_ALU_WORD1_OP3_ALU_INST(alu->inst) | + S_SQ_ALU_WORD1_BANK_SWIZZLE(alu->bank_swizzle); + } else { + bc->bytecode[id++] = S_SQ_ALU_WORD1_DST_GPR(alu->dst.sel) | + S_SQ_ALU_WORD1_DST_CHAN(alu->dst.chan) | + S_SQ_ALU_WORD1_DST_REL(alu->dst.rel) | + S_SQ_ALU_WORD1_CLAMP(alu->dst.clamp) | + S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu->src[0].abs) | + S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu->src[1].abs) | + S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu->dst.write) | + S_SQ_ALU_WORD1_OP2_ALU_INST(alu->inst) | + S_SQ_ALU_WORD1_BANK_SWIZZLE(alu->bank_swizzle) | + S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu->predicate) | + S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu->predicate); + } + if (alu->last) { + if (alu->nliteral && !alu->literal_added) { + R600_ERR("Bug in ALU processing for instruction 0x%08x, literal not added correctly\n", alu->inst); + } + for (i = 0; i < alu->nliteral; i++) { + bc->bytecode[id++] = alu->value[i]; + } + } + return 0; +} + +/* common for r600/r700 - eg in eg_asm.c */ +static int r600_bc_cf_build(struct r600_bc *bc, struct r600_bc_cf *cf) +{ + unsigned id = cf->id; + + switch (cf->inst) { + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3): + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3): + bc->bytecode[id++] = S_SQ_CF_ALU_WORD0_ADDR(cf->addr >> 1) | + S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf->kcache0_mode) | + S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf->kcache0_bank) | + S_SQ_CF_ALU_WORD0_KCACHE_BANK1(cf->kcache1_bank); + + bc->bytecode[id++] = S_SQ_CF_ALU_WORD1_CF_INST(cf->inst >> 3) | + S_SQ_CF_ALU_WORD1_KCACHE_MODE1(cf->kcache1_mode) | + S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(cf->kcache0_addr) | + S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(cf->kcache1_addr) | + S_SQ_CF_ALU_WORD1_BARRIER(1) | + S_SQ_CF_ALU_WORD1_USES_WATERFALL(bc->chiprev == CHIPREV_R600 ? cf->r6xx_uses_waterfall : 0) | + S_SQ_CF_ALU_WORD1_COUNT((cf->ndw / 2) - 1); + break; + case V_SQ_CF_WORD1_SQ_CF_INST_TEX: + case V_SQ_CF_WORD1_SQ_CF_INST_VTX: + case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC: + bc->bytecode[id++] = S_SQ_CF_WORD0_ADDR(cf->addr >> 1); + bc->bytecode[id++] = S_SQ_CF_WORD1_CF_INST(cf->inst) | + S_SQ_CF_WORD1_BARRIER(1) | + S_SQ_CF_WORD1_COUNT((cf->ndw / 4) - 1); + break; + case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT: + case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE: + bc->bytecode[id++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf->output.gpr) | + S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf->output.elem_size) | + S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf->output.array_base) | + S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf->output.type); + bc->bytecode[id++] = S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf->output.swizzle_x) | + S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf->output.swizzle_y) | + S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf->output.swizzle_z) | + S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf->output.swizzle_w) | + S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf->output.barrier) | + S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf->output.inst) | + S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf->output.end_of_program); + break; + case V_SQ_CF_WORD1_SQ_CF_INST_JUMP: + case V_SQ_CF_WORD1_SQ_CF_INST_ELSE: + case V_SQ_CF_WORD1_SQ_CF_INST_POP: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK: + case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS: + case V_SQ_CF_WORD1_SQ_CF_INST_RETURN: + bc->bytecode[id++] = S_SQ_CF_WORD0_ADDR(cf->cf_addr >> 1); + bc->bytecode[id++] = S_SQ_CF_WORD1_CF_INST(cf->inst) | + S_SQ_CF_WORD1_BARRIER(1) | + S_SQ_CF_WORD1_COND(cf->cond) | + S_SQ_CF_WORD1_POP_COUNT(cf->pop_count); + + break; + default: + R600_ERR("unsupported CF instruction (0x%X)\n", cf->inst); + return -EINVAL; + } + return 0; +} + +int r600_bc_build(struct r600_bc *bc) +{ + struct r600_bc_cf *cf; + struct r600_bc_alu *alu; + struct r600_bc_vtx *vtx; + struct r600_bc_tex *tex; + unsigned addr; + int r; + + if (bc->callstack[0].max > 0) + bc->nstack = ((bc->callstack[0].max + 3) >> 2) + 2; + if (bc->type == TGSI_PROCESSOR_VERTEX && !bc->nstack) { + bc->nstack = 1; + } + + /* first path compute addr of each CF block */ + /* addr start after all the CF instructions */ + addr = bc->cf_last->id + 2; + LIST_FOR_EACH_ENTRY(cf, &bc->cf, list) { + switch (cf->inst) { + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3): + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3): + break; + case V_SQ_CF_WORD1_SQ_CF_INST_TEX: + case V_SQ_CF_WORD1_SQ_CF_INST_VTX: + case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC: + /* fetch node need to be 16 bytes aligned*/ + addr += 3; + addr &= 0xFFFFFFFCUL; + break; + case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT: + case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE: + case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT: + case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE: + break; + case V_SQ_CF_WORD1_SQ_CF_INST_JUMP: + case V_SQ_CF_WORD1_SQ_CF_INST_ELSE: + case V_SQ_CF_WORD1_SQ_CF_INST_POP: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK: + case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS: + case V_SQ_CF_WORD1_SQ_CF_INST_RETURN: + break; + default: + R600_ERR("unsupported CF instruction (0x%X)\n", cf->inst); + return -EINVAL; + } + cf->addr = addr; + addr += cf->ndw; + bc->ndw = cf->addr + cf->ndw; + } + free(bc->bytecode); + bc->bytecode = calloc(1, bc->ndw * 4); + if (bc->bytecode == NULL) + return -ENOMEM; + LIST_FOR_EACH_ENTRY(cf, &bc->cf, list) { + addr = cf->addr; + if (bc->chiprev == CHIPREV_EVERGREEN) + r = eg_bc_cf_build(bc, cf); + else + r = r600_bc_cf_build(bc, cf); + if (r) + return r; + switch (cf->inst) { + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU << 3): + case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE << 3): + LIST_FOR_EACH_ENTRY(alu, &cf->alu, list) { + switch(bc->chiprev) { + case CHIPREV_R600: + r = r600_bc_alu_build(bc, alu, addr); + break; + case CHIPREV_R700: + case CHIPREV_EVERGREEN: /* eg alu is same encoding as r700 */ + r = r700_bc_alu_build(bc, alu, addr); + break; + default: + R600_ERR("unknown family %d\n", bc->family); + return -EINVAL; + } + if (r) + return r; + addr += 2; + if (alu->last) { + addr += alu->nliteral; + } + } + break; + case V_SQ_CF_WORD1_SQ_CF_INST_VTX: + case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC: + LIST_FOR_EACH_ENTRY(vtx, &cf->vtx, list) { + r = r600_bc_vtx_build(bc, vtx, addr); + if (r) + return r; + addr += 4; + } + break; + case V_SQ_CF_WORD1_SQ_CF_INST_TEX: + LIST_FOR_EACH_ENTRY(tex, &cf->tex, list) { + r = r600_bc_tex_build(bc, tex, addr); + if (r) + return r; + addr += 4; + } + break; + case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT: + case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE: + case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT: + case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE: + case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK: + case V_SQ_CF_WORD1_SQ_CF_INST_JUMP: + case V_SQ_CF_WORD1_SQ_CF_INST_ELSE: + case V_SQ_CF_WORD1_SQ_CF_INST_POP: + case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS: + case V_SQ_CF_WORD1_SQ_CF_INST_RETURN: + break; + default: + R600_ERR("unsupported CF instruction (0x%X)\n", cf->inst); + return -EINVAL; + } + } + return 0; +} + +void r600_bc_clear(struct r600_bc *bc) +{ + struct r600_bc_cf *cf = NULL, *next_cf; + + free(bc->bytecode); + bc->bytecode = NULL; + + LIST_FOR_EACH_ENTRY_SAFE(cf, next_cf, &bc->cf, list) { + struct r600_bc_alu *alu = NULL, *next_alu; + struct r600_bc_tex *tex = NULL, *next_tex; + struct r600_bc_tex *vtx = NULL, *next_vtx; + + LIST_FOR_EACH_ENTRY_SAFE(alu, next_alu, &cf->alu, list) { + free(alu); + } + + LIST_INITHEAD(&cf->alu); + + LIST_FOR_EACH_ENTRY_SAFE(tex, next_tex, &cf->tex, list) { + free(tex); + } + + LIST_INITHEAD(&cf->tex); + + LIST_FOR_EACH_ENTRY_SAFE(vtx, next_vtx, &cf->vtx, list) { + free(vtx); + } + + LIST_INITHEAD(&cf->vtx); + + free(cf); + } + + LIST_INITHEAD(&cf->list); +} + +void r600_bc_dump(struct r600_bc *bc) +{ + unsigned i; + char chip = '6'; + + switch (bc->chiprev) { + case 1: + chip = '7'; + break; + case 2: + chip = 'E'; + break; + case 0: + default: + chip = '6'; + break; + } + fprintf(stderr, "bytecode %d dw -----------------------\n", bc->ndw); + fprintf(stderr, " %c\n", chip); + for (i = 0; i < bc->ndw; i++) { + fprintf(stderr, "0x%08X\n", bc->bytecode[i]); + } + fprintf(stderr, "--------------------------------------\n"); +} + +void r600_cf_vtx(struct r600_vertex_element *ve, u32 *bytecode, unsigned count) +{ + struct r600_pipe_state *rstate; + unsigned i = 0; + + if (count > 8) { + bytecode[i++] = S_SQ_CF_WORD0_ADDR(8 >> 1); + bytecode[i++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX) | + S_SQ_CF_WORD1_BARRIER(1) | + S_SQ_CF_WORD1_COUNT(8 - 1); + bytecode[i++] = S_SQ_CF_WORD0_ADDR(40 >> 1); + bytecode[i++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX) | + S_SQ_CF_WORD1_BARRIER(1) | + S_SQ_CF_WORD1_COUNT(count - 8 - 1); + } else { + bytecode[i++] = S_SQ_CF_WORD0_ADDR(8 >> 1); + bytecode[i++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX) | + S_SQ_CF_WORD1_BARRIER(1) | + S_SQ_CF_WORD1_COUNT(count - 1); + } + bytecode[i++] = S_SQ_CF_WORD0_ADDR(0); + bytecode[i++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_RETURN) | + S_SQ_CF_WORD1_BARRIER(1); + + rstate = &ve->rstate; + rstate->id = R600_PIPE_STATE_FETCH_SHADER; + rstate->nregs = 0; + r600_pipe_state_add_reg(rstate, R_0288A4_SQ_PGM_RESOURCES_FS, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0288DC_SQ_PGM_CF_OFFSET_FS, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028894_SQ_PGM_START_FS, + r600_bo_offset(ve->fetch_shader) >> 8, + 0xFFFFFFFF, ve->fetch_shader); +} + +void r600_cf_vtx_tc(struct r600_vertex_element *ve, u32 *bytecode, unsigned count) +{ + struct r600_pipe_state *rstate; + unsigned i = 0; + + if (count > 8) { + bytecode[i++] = S_SQ_CF_WORD0_ADDR(8 >> 1); + bytecode[i++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC) | + S_SQ_CF_WORD1_BARRIER(1) | + S_SQ_CF_WORD1_COUNT(8 - 1); + bytecode[i++] = S_SQ_CF_WORD0_ADDR(40 >> 1); + bytecode[i++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC) | + S_SQ_CF_WORD1_BARRIER(1) | + S_SQ_CF_WORD1_COUNT((count - 8) - 1); + } else { + bytecode[i++] = S_SQ_CF_WORD0_ADDR(8 >> 1); + bytecode[i++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC) | + S_SQ_CF_WORD1_BARRIER(1) | + S_SQ_CF_WORD1_COUNT(count - 1); + } + bytecode[i++] = S_SQ_CF_WORD0_ADDR(0); + bytecode[i++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_RETURN) | + S_SQ_CF_WORD1_BARRIER(1); + + rstate = &ve->rstate; + rstate->id = R600_PIPE_STATE_FETCH_SHADER; + rstate->nregs = 0; + r600_pipe_state_add_reg(rstate, R_0288A4_SQ_PGM_RESOURCES_FS, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0288DC_SQ_PGM_CF_OFFSET_FS, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028894_SQ_PGM_START_FS, + r600_bo_offset(ve->fetch_shader) >> 8, + 0xFFFFFFFF, ve->fetch_shader); +} + +static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format, + unsigned *num_format, unsigned *format_comp) +{ + const struct util_format_description *desc; + unsigned i; + + *format = 0; + *num_format = 0; + *format_comp = 0; + + desc = util_format_description(pformat); + if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { + goto out_unknown; + } + + /* Find the first non-VOID channel. */ + for (i = 0; i < 4; i++) { + if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { + break; + } + } + + switch (desc->channel[i].type) { + /* Half-floats, floats, doubles */ + case UTIL_FORMAT_TYPE_FLOAT: + switch (desc->channel[i].size) { + case 16: + switch (desc->nr_channels) { + case 1: + *format = FMT_16_FLOAT; + break; + case 2: + *format = FMT_16_16_FLOAT; + break; + case 3: + *format = FMT_16_16_16_FLOAT; + break; + case 4: + *format = FMT_16_16_16_16_FLOAT; + break; + } + break; + case 32: + switch (desc->nr_channels) { + case 1: + *format = FMT_32_FLOAT; + break; + case 2: + *format = FMT_32_32_FLOAT; + break; + case 3: + *format = FMT_32_32_32_FLOAT; + break; + case 4: + *format = FMT_32_32_32_32_FLOAT; + break; + } + break; + default: + goto out_unknown; + } + break; + /* Unsigned ints */ + case UTIL_FORMAT_TYPE_UNSIGNED: + /* Signed ints */ + case UTIL_FORMAT_TYPE_SIGNED: + switch (desc->channel[i].size) { + case 8: + switch (desc->nr_channels) { + case 1: + *format = FMT_8; + break; + case 2: + *format = FMT_8_8; + break; + case 3: + // *format = FMT_8_8_8; /* fails piglit draw-vertices test */ + // break; + case 4: + *format = FMT_8_8_8_8; + break; + } + break; + case 16: + switch (desc->nr_channels) { + case 1: + *format = FMT_16; + break; + case 2: + *format = FMT_16_16; + break; + case 3: + // *format = FMT_16_16_16; /* fails piglit draw-vertices test */ + // break; + case 4: + *format = FMT_16_16_16_16; + break; + } + break; + case 32: + switch (desc->nr_channels) { + case 1: + *format = FMT_32; + break; + case 2: + *format = FMT_32_32; + break; + case 3: + *format = FMT_32_32_32; + break; + case 4: + *format = FMT_32_32_32_32; + break; + } + break; + default: + goto out_unknown; + } + break; + default: + goto out_unknown; + } + + if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) { + *format_comp = 1; + } + if (desc->channel[i].normalized) { + *num_format = 0; + } else { + *num_format = 2; + } + return; +out_unknown: + R600_ERR("unsupported vertex format %s\n", util_format_name(pformat)); +} + +static void r600_bc(unsigned ndw, unsigned chiprev, u32 *bytecode) +{ + unsigned i; + char chip = '6'; + + switch (chiprev) { + case 1: + chip = '7'; + break; + case 2: + chip = 'E'; + break; + case 0: + default: + chip = '6'; + break; + } + fprintf(stderr, "bytecode %d dw -----------------------\n", ndw); + fprintf(stderr, " %c\n", chip); + for (i = 0; i < ndw; i++) { + fprintf(stderr, "0x%08X\n", bytecode[i]); + } + fprintf(stderr, "--------------------------------------\n"); +} + +int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context *rctx, struct r600_vertex_element *ve) +{ + unsigned ndw, i; + u32 *bytecode; + unsigned fetch_resource_start = 0, format, num_format, format_comp; + struct pipe_vertex_element *elements = ve->elements; + const struct util_format_description *desc; + + /* 2 dwords for cf aligned to 4 + 4 dwords per input */ + ndw = 8 + ve->count * 4; + ve->fs_size = ndw * 4; + + /* use PIPE_BIND_VERTEX_BUFFER so we use the cache buffer manager */ + ve->fetch_shader = r600_bo(rctx->radeon, ndw*4, 256, PIPE_BIND_VERTEX_BUFFER, 0); + if (ve->fetch_shader == NULL) { + return -ENOMEM; + } + + bytecode = r600_bo_map(rctx->radeon, ve->fetch_shader, 0, NULL); + if (bytecode == NULL) { + r600_bo_reference(rctx->radeon, &ve->fetch_shader, NULL); + return -ENOMEM; + } + + if (rctx->family >= CHIP_CEDAR) { + eg_cf_vtx(ve, &bytecode[0], (ndw - 8) / 4); + } else { + r600_cf_vtx(ve, &bytecode[0], (ndw - 8) / 4); + fetch_resource_start = 160; + } + + /* vertex elements offset need special handling, if offset is bigger + * than what we can put in fetch instruction then we need to alterate + * the vertex resource offset. In such case in order to simplify code + * we will bound one resource per elements. It's a worst case scenario. + */ + for (i = 0; i < ve->count; i++) { + ve->vbuffer_offset[i] = C_SQ_VTX_WORD2_OFFSET & elements[i].src_offset; + if (ve->vbuffer_offset[i]) { + ve->vbuffer_need_offset = 1; + } + } + + for (i = 0; i < ve->count; i++) { + unsigned vbuffer_index; + r600_vertex_data_type(ve->hw_format[i], &format, &num_format, &format_comp); + desc = util_format_description(ve->hw_format[i]); + if (desc == NULL) { + R600_ERR("unknown format %d\n", ve->hw_format[i]); + r600_bo_reference(rctx->radeon, &ve->fetch_shader, NULL); + return -EINVAL; + } + + /* see above for vbuffer_need_offset explanation */ + vbuffer_index = elements[i].vertex_buffer_index; + if (ve->vbuffer_need_offset) { + bytecode[8 + i * 4 + 0] = S_SQ_VTX_WORD0_BUFFER_ID(i + fetch_resource_start); + } else { + bytecode[8 + i * 4 + 0] = S_SQ_VTX_WORD0_BUFFER_ID(vbuffer_index + fetch_resource_start); + } + bytecode[8 + i * 4 + 0] |= S_SQ_VTX_WORD0_SRC_GPR(0) | + S_SQ_VTX_WORD0_SRC_SEL_X(0) | + S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(0x1F); + bytecode[8 + i * 4 + 1] = S_SQ_VTX_WORD1_DST_SEL_X(desc->swizzle[0]) | + S_SQ_VTX_WORD1_DST_SEL_Y(desc->swizzle[1]) | + S_SQ_VTX_WORD1_DST_SEL_Z(desc->swizzle[2]) | + S_SQ_VTX_WORD1_DST_SEL_W(desc->swizzle[3]) | + S_SQ_VTX_WORD1_USE_CONST_FIELDS(0) | + S_SQ_VTX_WORD1_DATA_FORMAT(format) | + S_SQ_VTX_WORD1_NUM_FORMAT_ALL(num_format) | + S_SQ_VTX_WORD1_FORMAT_COMP_ALL(format_comp) | + S_SQ_VTX_WORD1_SRF_MODE_ALL(1) | + S_SQ_VTX_WORD1_GPR_DST_GPR(i + 1); + bytecode[8 + i * 4 + 2] = S_SQ_VTX_WORD2_OFFSET(elements[i].src_offset) | + S_SQ_VTX_WORD2_MEGA_FETCH(1); + bytecode[8 + i * 4 + 3] = 0; + } + r600_bo_unmap(rctx->radeon, ve->fetch_shader); + return 0; +} diff --git a/src/gallium/drivers/r600/r600_asm.h b/src/gallium/drivers/r600/r600_asm.h new file mode 100644 index 0000000..b147f0f --- /dev/null +++ b/src/gallium/drivers/r600/r600_asm.h @@ -0,0 +1,216 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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 R600_ASM_H +#define R600_ASM_H + +#include "util/u_double_list.h" + +#define NUM_OF_CYCLES 3 +#define NUM_OF_COMPONENTS 4 + +struct r600_vertex_element; +struct r600_pipe_context; + +struct r600_bc_alu_src { + unsigned sel; + unsigned chan; + unsigned neg; + unsigned abs; + unsigned rel; +}; + +struct r600_bc_alu_dst { + unsigned sel; + unsigned chan; + unsigned clamp; + unsigned write; + unsigned rel; +}; + +struct r600_bc_alu { + struct list_head list; + struct list_head bs_list; /* bank swizzle list */ + struct r600_bc_alu_src src[3]; + struct r600_bc_alu_dst dst; + unsigned inst; + unsigned last; + unsigned is_op3; + unsigned predicate; + unsigned nliteral; + unsigned literal_added; + unsigned bank_swizzle; + unsigned bank_swizzle_force; + u32 value[4]; + int hw_gpr[NUM_OF_CYCLES][NUM_OF_COMPONENTS]; +}; + +struct r600_bc_tex { + struct list_head list; + unsigned inst; + unsigned resource_id; + unsigned src_gpr; + unsigned src_rel; + unsigned dst_gpr; + unsigned dst_rel; + unsigned dst_sel_x; + unsigned dst_sel_y; + unsigned dst_sel_z; + unsigned dst_sel_w; + unsigned lod_bias; + unsigned coord_type_x; + unsigned coord_type_y; + unsigned coord_type_z; + unsigned coord_type_w; + unsigned offset_x; + unsigned offset_y; + unsigned offset_z; + unsigned sampler_id; + unsigned src_sel_x; + unsigned src_sel_y; + unsigned src_sel_z; + unsigned src_sel_w; +}; + +struct r600_bc_vtx { + struct list_head list; + unsigned inst; + unsigned fetch_type; + unsigned buffer_id; + unsigned src_gpr; + unsigned src_sel_x; + unsigned mega_fetch_count; + unsigned dst_gpr; + unsigned dst_sel_x; + unsigned dst_sel_y; + unsigned dst_sel_z; + unsigned dst_sel_w; + unsigned use_const_fields; + unsigned data_format; + unsigned num_format_all; + unsigned format_comp_all; + unsigned srf_mode_all; +}; + +struct r600_bc_output { + unsigned array_base; + unsigned type; + unsigned end_of_program; + unsigned inst; + unsigned elem_size; + unsigned gpr; + unsigned swizzle_x; + unsigned swizzle_y; + unsigned swizzle_z; + unsigned swizzle_w; + unsigned barrier; +}; + +struct r600_bc_cf { + struct list_head list; + unsigned inst; + unsigned addr; + unsigned ndw; + unsigned id; + unsigned cond; + unsigned pop_count; + unsigned cf_addr; /* control flow addr */ + unsigned kcache0_mode; + unsigned kcache1_mode; + unsigned kcache0_addr; + unsigned kcache1_addr; + unsigned kcache0_bank; + unsigned kcache1_bank; + unsigned r6xx_uses_waterfall; + struct list_head alu; + struct list_head tex; + struct list_head vtx; + struct r600_bc_output output; + struct r600_bc_alu *curr_bs_head; +}; + +#define FC_NONE 0 +#define FC_IF 1 +#define FC_LOOP 2 +#define FC_REP 3 +#define FC_PUSH_VPM 4 +#define FC_PUSH_WQM 5 + +struct r600_cf_stack_entry { + int type; + struct r600_bc_cf *start; + struct r600_bc_cf **mid; /* used to store the else point */ + int num_mid; +}; + +#define SQ_MAX_CALL_DEPTH 0x00000020 +struct r600_cf_callstack { + unsigned fc_sp_before_entry; + int sub_desc_index; + int current; + int max; +}; + +struct r600_bc { + enum radeon_family family; + int chiprev; /* 0 - r600, 1 - r700, 2 - evergreen */ + int type; + struct list_head cf; + struct r600_bc_cf *cf_last; + unsigned ndw; + unsigned ncf; + unsigned ngpr; + unsigned nstack; + unsigned nresource; + unsigned force_add_cf; + u32 *bytecode; + u32 fc_sp; + struct r600_cf_stack_entry fc_stack[32]; + unsigned call_sp; + struct r600_cf_callstack callstack[SQ_MAX_CALL_DEPTH]; +}; + +/* eg_asm.c */ +int eg_bc_cf_build(struct r600_bc *bc, struct r600_bc_cf *cf); +void eg_cf_vtx(struct r600_vertex_element *ve, u32 *bytecode, unsigned count); + +/* r600_asm.c */ +int r600_bc_init(struct r600_bc *bc, enum radeon_family family); +void r600_bc_clear(struct r600_bc *bc); +int r600_bc_add_alu(struct r600_bc *bc, const struct r600_bc_alu *alu); +int r600_bc_add_literal(struct r600_bc *bc, const u32 *value); +int r600_bc_add_vtx(struct r600_bc *bc, const struct r600_bc_vtx *vtx); +int r600_bc_add_tex(struct r600_bc *bc, const struct r600_bc_tex *tex); +int r600_bc_add_output(struct r600_bc *bc, const struct r600_bc_output *output); +int r600_bc_build(struct r600_bc *bc); +int r600_bc_add_cfinst(struct r600_bc *bc, int inst); +int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int type); +void r600_bc_dump(struct r600_bc *bc); +void r600_cf_vtx(struct r600_vertex_element *ve, u32 *bytecode, unsigned count); +void r600_cf_vtx_tc(struct r600_vertex_element *ve, u32 *bytecode, unsigned count); + +int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context *rctx, struct r600_vertex_element *ve); + +/* r700_asm.c */ +int r700_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsigned id); + +#endif diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c new file mode 100644 index 0000000..0f04136 --- /dev/null +++ b/src/gallium/drivers/r600/r600_blit.c @@ -0,0 +1,202 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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 +#include +#include +#include "r600_pipe.h" + +enum r600_blitter_op /* bitmask */ +{ + R600_CLEAR = 1, + R600_CLEAR_SURFACE = 2, + R600_COPY = 4 +}; + +static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + + r600_context_queries_suspend(&rctx->ctx); + + util_blitter_save_blend(rctx->blitter, rctx->states[R600_PIPE_STATE_BLEND]); + util_blitter_save_depth_stencil_alpha(rctx->blitter, rctx->states[R600_PIPE_STATE_DSA]); + if (rctx->states[R600_PIPE_STATE_STENCIL_REF]) { + util_blitter_save_stencil_ref(rctx->blitter, &rctx->stencil_ref); + } + util_blitter_save_rasterizer(rctx->blitter, rctx->states[R600_PIPE_STATE_RASTERIZER]); + util_blitter_save_fragment_shader(rctx->blitter, rctx->ps_shader); + util_blitter_save_vertex_shader(rctx->blitter, rctx->vs_shader); + util_blitter_save_vertex_elements(rctx->blitter, rctx->vertex_elements); + if (rctx->states[R600_PIPE_STATE_VIEWPORT]) { + util_blitter_save_viewport(rctx->blitter, &rctx->viewport); + } + if (rctx->states[R600_PIPE_STATE_CLIP]) { + util_blitter_save_clip(rctx->blitter, &rctx->clip); + } + util_blitter_save_vertex_buffers(rctx->blitter, rctx->nvertex_buffer, rctx->vertex_buffer); + + rctx->vertex_elements = NULL; + + if (op & (R600_CLEAR_SURFACE | R600_COPY)) + util_blitter_save_framebuffer(rctx->blitter, &rctx->framebuffer); + + if (op & R600_COPY) { + util_blitter_save_fragment_sampler_states( + rctx->blitter, rctx->ps_samplers.n_samplers, + (void**)rctx->ps_samplers.samplers); + + util_blitter_save_fragment_sampler_views( + rctx->blitter, rctx->ps_samplers.n_views, + (struct pipe_sampler_view**)rctx->ps_samplers.views); + } + +} + +static void r600_blitter_end(struct pipe_context *ctx) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + r600_context_queries_resume(&rctx->ctx); +} + +int r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_texture *texture) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct pipe_surface *zsurf, *cbsurf, surf_tmpl; + int level = 0; + float depth = 1.0f; + surf_tmpl.format = texture->resource.base.b.format; + surf_tmpl.u.tex.level = level; + surf_tmpl.u.tex.first_layer = 0; + surf_tmpl.u.tex.last_layer = 0; + surf_tmpl.usage = PIPE_BIND_DEPTH_STENCIL; + + zsurf = ctx->create_surface(ctx, &texture->resource.base.b, &surf_tmpl); + + surf_tmpl.format = ((struct pipe_resource*)texture->flushed_depth_texture)->format; + surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; + cbsurf = ctx->create_surface(ctx, + (struct pipe_resource*)texture->flushed_depth_texture, &surf_tmpl); + + if (rctx->family == CHIP_RV610 || rctx->family == CHIP_RV630 || + rctx->family == CHIP_RV620 || rctx->family == CHIP_RV635) + depth = 0.0f; + + r600_blitter_begin(ctx, R600_CLEAR_SURFACE); + util_blitter_custom_depth_stencil(rctx->blitter, zsurf, cbsurf, rctx->custom_dsa_flush, depth); + r600_blitter_end(ctx); + + pipe_surface_reference(&zsurf, NULL); + pipe_surface_reference(&cbsurf, NULL); + + + return 0; +} + +static void r600_clear(struct pipe_context *ctx, unsigned buffers, + const float *rgba, double depth, unsigned stencil) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct pipe_framebuffer_state *fb = &rctx->framebuffer; + + r600_blitter_begin(ctx, R600_CLEAR); + util_blitter_clear(rctx->blitter, fb->width, fb->height, + fb->nr_cbufs, buffers, rgba, depth, + stencil); + r600_blitter_end(ctx); +} + +static void r600_clear_render_target(struct pipe_context *ctx, + struct pipe_surface *dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + + r600_blitter_begin(ctx, R600_CLEAR_SURFACE); + util_blitter_clear_render_target(rctx->blitter, dst, rgba, + dstx, dsty, width, height); + r600_blitter_end(ctx); +} + +static void r600_clear_depth_stencil(struct pipe_context *ctx, + struct pipe_surface *dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + + r600_blitter_begin(ctx, R600_CLEAR_SURFACE); + util_blitter_clear_depth_stencil(rctx->blitter, dst, clear_flags, depth, stencil, + dstx, dsty, width, height); + r600_blitter_end(ctx); +} + + + +/* Copy a block of pixels from one surface to another using HW. */ +static void r600_hw_copy_region(struct pipe_context *ctx, + struct pipe_resource *dst, + unsigned dst_level, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource *src, + unsigned src_level, + const struct pipe_box *src_box) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + + r600_blitter_begin(ctx, R600_COPY); + util_blitter_copy_region(rctx->blitter, dst, dst_level, dstx, dsty, dstz, + src, src_level, src_box, TRUE); + r600_blitter_end(ctx); +} + +static void r600_resource_copy_region(struct pipe_context *ctx, + struct pipe_resource *dst, + unsigned dst_level, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource *src, + unsigned src_level, + const struct pipe_box *src_box) +{ + boolean is_depth; + /* there is something wrong with depth resource copies at the moment so avoid them for now */ + is_depth = util_format_get_component_bits(src->format, UTIL_FORMAT_COLORSPACE_ZS, 0) != 0; + if (is_depth) + util_resource_copy_region(ctx, dst, dst_level, dstx, dsty, dstz, + src, src_level, src_box); + else + r600_hw_copy_region(ctx, dst, dst_level, dstx, dsty, dstz, + src, src_level, src_box); +} + +void r600_init_blit_functions(struct r600_pipe_context *rctx) +{ + rctx->context.clear = r600_clear; + rctx->context.clear_render_target = r600_clear_render_target; + rctx->context.clear_depth_stencil = r600_clear_depth_stencil; + rctx->context.resource_copy_region = r600_resource_copy_region; +} diff --git a/src/gallium/drivers/r600/r600_buffer.c b/src/gallium/drivers/r600/r600_buffer.c new file mode 100644 index 0000000..a17c54d --- /dev/null +++ b/src/gallium/drivers/r600/r600_buffer.c @@ -0,0 +1,252 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + * Corbin Simpson + */ +#include +#include +#include +#include +#include +#include "state_tracker/drm_driver.h" +#include +#include "radeon_drm.h" +#include "r600.h" +#include "r600_pipe.h" + +extern struct u_resource_vtbl r600_buffer_vtbl; + + +struct pipe_resource *r600_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *templ) +{ + struct r600_resource_buffer *rbuffer; + struct r600_bo *bo; + /* XXX We probably want a different alignment for buffers and textures. */ + unsigned alignment = 4096; + + rbuffer = CALLOC_STRUCT(r600_resource_buffer); + if (rbuffer == NULL) + return NULL; + + rbuffer->magic = R600_BUFFER_MAGIC; + rbuffer->user_buffer = NULL; + rbuffer->r.base.b = *templ; + pipe_reference_init(&rbuffer->r.base.b.reference, 1); + rbuffer->r.base.b.screen = screen; + rbuffer->r.base.vtbl = &r600_buffer_vtbl; + rbuffer->r.size = rbuffer->r.base.b.width0; + rbuffer->r.bo_size = rbuffer->r.size; + rbuffer->uploaded = FALSE; + bo = r600_bo((struct radeon*)screen->winsys, rbuffer->r.base.b.width0, alignment, rbuffer->r.base.b.bind, rbuffer->r.base.b.usage); + if (bo == NULL) { + FREE(rbuffer); + return NULL; + } + rbuffer->r.bo = bo; + return &rbuffer->r.base.b; +} + +struct pipe_resource *r600_user_buffer_create(struct pipe_screen *screen, + void *ptr, unsigned bytes, + unsigned bind) +{ + struct r600_resource_buffer *rbuffer; + + rbuffer = CALLOC_STRUCT(r600_resource_buffer); + if (rbuffer == NULL) + return NULL; + + rbuffer->magic = R600_BUFFER_MAGIC; + pipe_reference_init(&rbuffer->r.base.b.reference, 1); + rbuffer->r.base.vtbl = &r600_buffer_vtbl; + rbuffer->r.base.b.screen = screen; + rbuffer->r.base.b.target = PIPE_BUFFER; + rbuffer->r.base.b.format = PIPE_FORMAT_R8_UNORM; + rbuffer->r.base.b.usage = PIPE_USAGE_IMMUTABLE; + rbuffer->r.base.b.bind = bind; + rbuffer->r.base.b.width0 = bytes; + rbuffer->r.base.b.height0 = 1; + rbuffer->r.base.b.depth0 = 1; + rbuffer->r.base.b.array_size = 1; + rbuffer->r.base.b.flags = 0; + rbuffer->r.bo = NULL; + rbuffer->r.bo_size = 0; + rbuffer->user_buffer = ptr; + rbuffer->uploaded = FALSE; + return &rbuffer->r.base.b; +} + +static void r600_buffer_destroy(struct pipe_screen *screen, + struct pipe_resource *buf) +{ + struct r600_resource_buffer *rbuffer = r600_buffer(buf); + + if (rbuffer->r.bo) { + r600_bo_reference((struct radeon*)screen->winsys, &rbuffer->r.bo, NULL); + } + rbuffer->r.bo = NULL; + FREE(rbuffer); +} + +static void *r600_buffer_transfer_map(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct r600_resource_buffer *rbuffer = r600_buffer(transfer->resource); + int write = 0; + uint8_t *data; + + if (rbuffer->user_buffer) + return (uint8_t*)rbuffer->user_buffer + transfer->box.x; + + if (transfer->usage & PIPE_TRANSFER_DONTBLOCK) { + /* FIXME */ + } + if (transfer->usage & PIPE_TRANSFER_WRITE) { + write = 1; + } + data = r600_bo_map((struct radeon*)pipe->winsys, rbuffer->r.bo, transfer->usage, pipe); + if (!data) + return NULL; + + return (uint8_t*)data + transfer->box.x; +} + +static void r600_buffer_transfer_unmap(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct r600_resource_buffer *rbuffer = r600_buffer(transfer->resource); + + if (rbuffer->user_buffer) + return; + + if (rbuffer->r.bo) + r600_bo_unmap((struct radeon*)pipe->winsys, rbuffer->r.bo); +} + +static void r600_buffer_transfer_flush_region(struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box) +{ +} + +unsigned r600_buffer_is_referenced_by_cs(struct pipe_context *context, + struct pipe_resource *buf, + unsigned level, int layer) +{ + /* FIXME */ + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +struct pipe_resource *r600_buffer_from_handle(struct pipe_screen *screen, + struct winsys_handle *whandle) +{ + struct radeon *rw = (struct radeon*)screen->winsys; + struct r600_resource *rbuffer; + struct r600_bo *bo = NULL; + + bo = r600_bo_handle(rw, whandle->handle, NULL); + if (bo == NULL) { + return NULL; + } + + rbuffer = CALLOC_STRUCT(r600_resource); + if (rbuffer == NULL) { + r600_bo_reference(rw, &bo, NULL); + return NULL; + } + + pipe_reference_init(&rbuffer->base.b.reference, 1); + rbuffer->base.b.target = PIPE_BUFFER; + rbuffer->base.b.screen = screen; + rbuffer->base.vtbl = &r600_buffer_vtbl; + rbuffer->bo = bo; + return &rbuffer->base.b; +} + +struct u_resource_vtbl r600_buffer_vtbl = +{ + u_default_resource_get_handle, /* get_handle */ + r600_buffer_destroy, /* resource_destroy */ + r600_buffer_is_referenced_by_cs, /* is_buffer_referenced */ + u_default_get_transfer, /* get_transfer */ + u_default_transfer_destroy, /* transfer_destroy */ + r600_buffer_transfer_map, /* transfer_map */ + r600_buffer_transfer_flush_region, /* transfer_flush_region */ + r600_buffer_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; + +int r600_upload_index_buffer(struct r600_pipe_context *rctx, struct r600_drawl *draw) +{ + if (r600_buffer_is_user_buffer(draw->index_buffer)) { + struct r600_resource_buffer *rbuffer = r600_buffer(draw->index_buffer); + unsigned upload_offset; + int ret = 0; + + ret = r600_upload_buffer(rctx->rupload_vb, + draw->index_buffer_offset, + draw->count * draw->index_size, + rbuffer, + &upload_offset, + &rbuffer->r.bo_size, + &rbuffer->r.bo); + if (ret) + return ret; + rbuffer->uploaded = TRUE; + draw->index_buffer_offset = upload_offset; + } + + return 0; +} + +int r600_upload_user_buffers(struct r600_pipe_context *rctx) +{ + enum pipe_error ret = PIPE_OK; + int i, nr; + + nr = rctx->vertex_elements->count; + nr = rctx->nvertex_buffer; + + for (i = 0; i < nr; i++) { + struct pipe_vertex_buffer *vb = &rctx->vertex_buffer[i]; + + if (r600_buffer_is_user_buffer(vb->buffer)) { + struct r600_resource_buffer *rbuffer = r600_buffer(vb->buffer); + unsigned upload_offset; + + ret = r600_upload_buffer(rctx->rupload_vb, + 0, vb->buffer->width0, + rbuffer, + &upload_offset, + &rbuffer->r.bo_size, + &rbuffer->r.bo); + if (ret) + return ret; + rbuffer->uploaded = TRUE; + vb->buffer_offset = upload_offset; + } + } + return ret; +} diff --git a/src/gallium/drivers/r600/r600_formats.h b/src/gallium/drivers/r600/r600_formats.h new file mode 100644 index 0000000..0c91a21 --- /dev/null +++ b/src/gallium/drivers/r600/r600_formats.h @@ -0,0 +1,56 @@ +#ifndef R600_FORMATS_H +#define R600_FORMATS_H + +/* list of formats from R700 ISA document - apply across GPUs in different registers */ +#define FMT_INVALID 0x00000000 +#define FMT_8 0x00000001 +#define FMT_4_4 0x00000002 +#define FMT_3_3_2 0x00000003 +#define FMT_16 0x00000005 +#define FMT_16_FLOAT 0x00000006 +#define FMT_8_8 0x00000007 +#define FMT_5_6_5 0x00000008 +#define FMT_6_5_5 0x00000009 +#define FMT_1_5_5_5 0x0000000A +#define FMT_4_4_4_4 0x0000000B +#define FMT_5_5_5_1 0x0000000C +#define FMT_32 0x0000000D +#define FMT_32_FLOAT 0x0000000E +#define FMT_16_16 0x0000000F +#define FMT_16_16_FLOAT 0x00000010 +#define FMT_8_24 0x00000011 +#define FMT_8_24_FLOAT 0x00000012 +#define FMT_24_8 0x00000013 +#define FMT_24_8_FLOAT 0x00000014 +#define FMT_10_11_11 0x00000015 +#define FMT_10_11_11_FLOAT 0x00000016 +#define FMT_11_11_10 0x00000017 +#define FMT_11_11_10_FLOAT 0x00000018 +#define FMT_2_10_10_10 0x00000019 +#define FMT_8_8_8_8 0x0000001A +#define FMT_10_10_10_2 0x0000001B +#define FMT_X24_8_32_FLOAT 0x0000001C +#define FMT_32_32 0x0000001D +#define FMT_32_32_FLOAT 0x0000001E +#define FMT_16_16_16_16 0x0000001F +#define FMT_16_16_16_16_FLOAT 0x00000020 +#define FMT_32_32_32_32 0x00000022 +#define FMT_32_32_32_32_FLOAT 0x00000023 +#define FMT_1 0x00000025 +#define FMT_GB_GR 0x00000027 +#define FMT_BG_RG 0x00000028 +#define FMT_32_AS_8 0x00000029 +#define FMT_32_AS_8_8 0x0000002a +#define FMT_5_9_9_9_SHAREDEXP 0x0000002b +#define FMT_8_8_8 0x0000002c +#define FMT_16_16_16 0x0000002d +#define FMT_16_16_16_FLOAT 0x0000002e +#define FMT_32_32_32 0x0000002f +#define FMT_32_32_32_FLOAT 0x00000030 +#define FMT_BC1 0x00000031 +#define FMT_BC2 0x00000032 +#define FMT_BC3 0x00000033 +#define FMT_BC4 0x00000034 +#define FMT_BC5 0x00000035 + +#endif diff --git a/src/gallium/drivers/r600/r600_helper.c b/src/gallium/drivers/r600/r600_helper.c new file mode 100644 index 0000000..7e13109 --- /dev/null +++ b/src/gallium/drivers/r600/r600_helper.c @@ -0,0 +1,69 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#include +#include +#include +#include "r600_pipe.h" +#include "r600d.h" + +int r600_conv_pipe_prim(unsigned pprim, unsigned *prim) +{ + switch (pprim) { + case PIPE_PRIM_POINTS: + *prim = V_008958_DI_PT_POINTLIST; + return 0; + case PIPE_PRIM_LINES: + *prim = V_008958_DI_PT_LINELIST; + return 0; + case PIPE_PRIM_LINE_STRIP: + *prim = V_008958_DI_PT_LINESTRIP; + return 0; + case PIPE_PRIM_LINE_LOOP: + *prim = V_008958_DI_PT_LINELOOP; + return 0; + case PIPE_PRIM_TRIANGLES: + *prim = V_008958_DI_PT_TRILIST; + return 0; + case PIPE_PRIM_TRIANGLE_STRIP: + *prim = V_008958_DI_PT_TRISTRIP; + return 0; + case PIPE_PRIM_TRIANGLE_FAN: + *prim = V_008958_DI_PT_TRIFAN; + return 0; + case PIPE_PRIM_POLYGON: + *prim = V_008958_DI_PT_POLYGON; + return 0; + case PIPE_PRIM_QUADS: + *prim = V_008958_DI_PT_QUADLIST; + return 0; + case PIPE_PRIM_QUAD_STRIP: + *prim = V_008958_DI_PT_QUADSTRIP; + return 0; + default: + fprintf(stderr, "%s:%d unsupported %d\n", __func__, __LINE__, pprim); + return -EINVAL; + } +} diff --git a/src/gallium/drivers/r600/r600_opcodes.h b/src/gallium/drivers/r600/r600_opcodes.h new file mode 100644 index 0000000..2ee0c83 --- /dev/null +++ b/src/gallium/drivers/r600/r600_opcodes.h @@ -0,0 +1,397 @@ + +#ifndef R600_OPCODES_H +#define R600_OPCODES_H + +#define V_SQ_CF_WORD1_SQ_CF_INST_NOP 0x00000000 +#define V_SQ_CF_WORD1_SQ_CF_INST_TEX 0x00000001 +#define V_SQ_CF_WORD1_SQ_CF_INST_VTX 0x00000002 +#define V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC 0x00000003 +#define V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START 0x00000004 +#define V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END 0x00000005 +#define V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10 0x00000006 +#define V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL 0x00000007 +#define V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE 0x00000008 +#define V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK 0x00000009 +#define V_SQ_CF_WORD1_SQ_CF_INST_JUMP 0x0000000A +#define V_SQ_CF_WORD1_SQ_CF_INST_PUSH 0x0000000B +#define V_SQ_CF_WORD1_SQ_CF_INST_PUSH_ELSE 0x0000000C +#define V_SQ_CF_WORD1_SQ_CF_INST_ELSE 0x0000000D +#define V_SQ_CF_WORD1_SQ_CF_INST_POP 0x0000000E +#define V_SQ_CF_WORD1_SQ_CF_INST_POP_JUMP 0x0000000F +#define V_SQ_CF_WORD1_SQ_CF_INST_POP_PUSH 0x00000010 +#define V_SQ_CF_WORD1_SQ_CF_INST_POP_PUSH_ELSE 0x00000011 +#define V_SQ_CF_WORD1_SQ_CF_INST_CALL 0x00000012 +#define V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS 0x00000013 +#define V_SQ_CF_WORD1_SQ_CF_INST_RETURN 0x00000014 +#define V_SQ_CF_WORD1_SQ_CF_INST_EMIT_VERTEX 0x00000015 +#define V_SQ_CF_WORD1_SQ_CF_INST_EMIT_CUT_VERTEX 0x00000016 +#define V_SQ_CF_WORD1_SQ_CF_INST_CUT_VERTEX 0x00000017 +#define V_SQ_CF_WORD1_SQ_CF_INST_KILL 0x00000018 + +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU 0x00000008 +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE 0x00000009 +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER 0x0000000A +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER 0x0000000B +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_CONTINUE 0x0000000D +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_BREAK 0x0000000E +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_ELSE_AFTER 0x0000000F + +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD 0x00000000 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL 0x00000001 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL_IEEE 0x00000002 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX 0x00000003 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN 0x00000004 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_DX10 0x00000005 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_DX10 0x00000006 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE 0x00000008 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT 0x00000009 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE 0x0000000A +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE 0x0000000B +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE_DX10 0x0000000C +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_DX10 0x0000000D +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_DX10 0x0000000E +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE_DX10 0x0000000F +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT 0x00000010 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC 0x00000011 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CEIL 0x00000012 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RNDNE 0x00000013 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR 0x00000014 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA 0x00000015 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR 0x00000016 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT 0x00000018 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV 0x00000019 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP 0x0000001A +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_UINT 0x0000001E +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_UINT 0x0000001F +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE 0x00000020 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT 0x00000021 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE 0x00000022 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE 0x00000023 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_INV 0x00000024 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_POP 0x00000025 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_CLR 0x00000026 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_RESTORE 0x00000027 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH 0x00000028 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH 0x00000029 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH 0x0000002A +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH 0x0000002B +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE 0x0000002C +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT 0x0000002D +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE 0x0000002E +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE 0x0000002F +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_AND_INT 0x00000030 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_OR_INT 0x00000031 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_XOR_INT 0x00000032 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOT_INT 0x00000033 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT 0x00000034 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT 0x00000035 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_INT 0x00000036 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_INT 0x00000037 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_UINT 0x00000038 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_UINT 0x00000039 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE_INT 0x0000003A +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_INT 0x0000003B +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_INT 0x0000003C +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE_INT 0x0000003D +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_UINT 0x0000003E +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_UINT 0x0000003F +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_UINT 0x00000040 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_UINT 0x00000041 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT 0x00000042 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_INT 0x00000043 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_INT 0x00000044 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT 0x00000045 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE_INT 0x00000046 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_INT 0x00000047 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_INT 0x00000048 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE_INT 0x00000049 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH_INT 0x0000004A +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH_INT 0x0000004B +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH_INT 0x0000004C +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH_INT 0x0000004D +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLT_PUSH_INT 0x0000004E +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLE_PUSH_INT 0x0000004F +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4 0x00000050 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE 0x00000051 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE 0x00000052 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX4 0x00000053 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT 0x00000060 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE 0x00000061 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED 0x00000062 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE 0x00000063 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED 0x00000064 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_FF 0x00000065 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE 0x00000066 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED 0x00000067 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_FF 0x00000068 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE 0x00000069 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SQRT_IEEE 0x0000006A +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT 0x0000006B +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT 0x0000006C +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT 0x0000006D +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN 0x0000006E +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS 0x0000006F +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT 0x00000070 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT 0x00000071 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT 0x00000072 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT 0x00000073 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_INT 0x00000074 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT 0x00000075 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT 0x00000076 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_INT 0x00000077 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_UINT 0x00000078 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT 0x00000079 + +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT 0x0000000C +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_M2 0x0000000D +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_M4 0x0000000E +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_D2 0x0000000F +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD 0x00000010 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_M2 0x00000011 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_M4 0x00000012 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_D2 0x00000013 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_IEEE 0x00000014 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_IEEE_M2 0x00000015 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_IEEE_M4 0x00000016 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_IEEE_D2 0x00000017 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDE 0x00000018 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT 0x00000019 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE 0x0000001A +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDE_INT 0x0000001C +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT_INT 0x0000001D +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE_INT 0x0000001E + +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0 0x00000020 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1 0x00000021 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2 0x00000022 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3 0x00000023 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_SCRATCH 0x00000024 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_REDUCTION 0x00000025 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_RING 0x00000026 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT 0x00000027 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE 0x00000028 + +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_NOP 0x00000000 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_TEX 0x00000001 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_VTX 0x00000002 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_GDS 0x00000003 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START 0x00000004 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END 0x00000005 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10 0x00000006 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL 0x00000007 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE 0x00000008 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK 0x00000009 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMP 0x0000000A +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_PUSH 0x0000000B +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_RSVD_12 0x0000000C /* resvd */ +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_ELSE 0x0000000D +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_POP 0x0000000E +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_RSVD_15 0x0000000F +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_RSVD_16 0x00000010 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_RSVD_17 0x00000011 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL 0x00000012 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS 0x00000013 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_RETURN 0x00000014 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_EMIT_VERTEX 0x00000015 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_EMIT_CUT_VERTEX 0x00000016 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_CUT_VERTEX 0x00000017 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_KILL 0x00000018 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_RSVD_25 0x00000019 +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_WAIT_ACK 0x0000001a +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_TC_ACK 0x0000001b +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_VC_ACK 0x0000001c +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_JUMPTABLE 0x0000001d +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_GLOBAL_WAVE_SYNC 0x0000001e +#define EG_V_SQ_CF_WORD1_SQ_CF_INST_HALT 0x0000001f + +#define EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU 0x00000008 +#define EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE 0x00000009 +#define EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER 0x0000000A +#define EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER 0x0000000B +#define EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_EXTENDED 0x0000000C +#define EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_CONTINUE 0x0000000D +#define EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_BREAK 0x0000000E +#define EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_ELSE_AFTER 0x0000000F + +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD 0x00000000 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL 0x00000001 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL_IEEE 0x00000002 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX 0x00000003 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN 0x00000004 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_DX10 0x00000005 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_DX10 0x00000006 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE 0x00000008 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT 0x00000009 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE 0x0000000A +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE 0x0000000B +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE_DX10 0x0000000C +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_DX10 0x0000000D +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_DX10 0x0000000E +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE_DX10 0x0000000F +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT 0x00000010 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC 0x00000011 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CEIL 0x00000012 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RNDNE 0x00000013 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR 0x00000014 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT 0x00000015 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT 0x00000016 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT 0x00000017 +/* same again from here */ +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV 0x00000019 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP 0x0000001A +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL_64 0x0000001B /* new EG */ +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT64_TO_FLT32 0x0000001C /* new EG */ +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT32_TO_FLT64 0x0000001D /* new EG */ +/* same */ +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_UINT 0x0000001E +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_UINT 0x0000001F +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE 0x00000020 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT 0x00000021 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE 0x00000022 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE 0x00000023 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_INV 0x00000024 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_POP 0x00000025 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_CLR 0x00000026 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_RESTORE 0x00000027 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH 0x00000028 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH 0x00000029 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH 0x0000002A +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH 0x0000002B +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE 0x0000002C +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT 0x0000002D +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE 0x0000002E +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE 0x0000002F +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_AND_INT 0x00000030 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_OR_INT 0x00000031 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_XOR_INT 0x00000032 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOT_INT 0x00000033 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT 0x00000034 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT 0x00000035 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_INT 0x00000036 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_INT 0x00000037 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_UINT 0x00000038 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_UINT 0x00000039 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE_INT 0x0000003A +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_INT 0x0000003B +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_INT 0x0000003C +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE_INT 0x0000003D +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_UINT 0x0000003E +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_UINT 0x0000003F +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_UINT 0x00000040 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_UINT 0x00000041 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT 0x00000042 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_INT 0x00000043 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_INT 0x00000044 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT 0x00000045 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE_INT 0x00000046 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_INT 0x00000047 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_INT 0x00000048 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE_INT 0x00000049 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH_INT 0x0000004A +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH_INT 0x0000004B +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH_INT 0x0000004C +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH_INT 0x0000004D +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLT_PUSH_INT 0x0000004E +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLE_PUSH_INT 0x0000004F +/* same up to here */ +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT 0x00000050 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_BFREV_INT 0x00000051 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADDC_UINT 0x00000052 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUBB_UINT 0x00000053 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_GROUP_BARRIER 0x00000054 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_GROUP_SEQ_BEGIN 0x00000055 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_GROUP_SEQ_END 0x00000056 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SET_MODE 0x00000057 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SET_CF_IDX0 0x00000058 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SET_CF_IDX1 0x00000059 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SET_LDS_SIZE 0x0000005A + +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE 0x00000081 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED 0x00000082 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE 0x00000083 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED 0x00000084 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_FF 0x00000085 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE 0x00000086 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED 0x00000087 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_FF 0x00000088 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE 0x00000089 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SQRT_IEEE 0x0000008A +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN 0x0000008D +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS 0x0000008E +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT 0x0000008F +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_INT 0x00000090 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT 0x00000091 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT 0x00000092 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_INT 0x00000093 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_UINT 0x00000094 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_64 0x00000095 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED_64 0x00000096 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_64 0x00000097 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED_64 0x00000098 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SQRT_64 0x00000099 +/* TODO Fill in more ALU */ +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT_FLOOR 0x000000B1 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4 0x000000BE +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE 0x000000BF +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE 0x000000C0 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT 0x000000CC + +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_XY 0x000000D6 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_ZW 0x000000D7 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_X 0x000000D8 +#define EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_Z 0x000000D9 + + +/* TODO ADD OTHER OP3 */ +#define EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD 0x00000014 +#define EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_M2 0x00000015 +#define EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_M4 0x00000016 +#define EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_D2 0x00000017 +#define EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_IEEE 0x00000018 +#define EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDE 0x00000019 +#define EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT 0x0000001A +#define EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE 0x0000001B +#define EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDE_INT 0x0000001C +#define EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT_INT 0x0000001D +#define EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE_INT 0x0000001E +#define EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT 0x0000001F + +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF0 0x00000040 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF1 0x00000041 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF2 0x00000042 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0_BUF3 0x00000043 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF0 0x00000044 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF1 0x00000045 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF2 0x00000046 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1_BUF3 0x00000047 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF0 0x00000048 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF1 0x00000049 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF2 0x0000004A +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2_BUF3 0x0000004B +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF0 0x0000004C +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF1 0x0000004D +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF2 0x0000004E +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3_BUF3 0x0000004F +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_SCRATCH 0x00000050 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_RING 0x00000052 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT 0x00000053 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE 0x00000054 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_EXPORT 0x00000055 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_RAT 0x00000056 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_RAT_CACHELESS 0x00000057 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_RING1 0x00000058 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_RING2 0x00000059 +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_RING3 0x0000005A +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_EXPORT_COMBINED 0x0000005B +#define EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_RAT_COMBINED_CACHELESS 0x0000005C + + +#define CHIPREV_R600 0 +#define CHIPREV_R700 1 +#define CHIPREV_EVERGREEN 2 + +#define BC_INST(bc, x) ((bc)->chiprev == CHIPREV_EVERGREEN ? EG_##x : x) + +#define CTX_INST(x) (ctx->bc->chiprev == CHIPREV_EVERGREEN ? EG_##x : x) + +#endif diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c new file mode 100644 index 0000000..3298ccd --- /dev/null +++ b/src/gallium/drivers/r600/r600_pipe.c @@ -0,0 +1,485 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "r600.h" +#include "r600d.h" +#include "r600_resource.h" +#include "r600_shader.h" +#include "r600_pipe.h" +#include "r600_state_inlines.h" + +/* + * pipe_context + */ +static void r600_flush(struct pipe_context *ctx, unsigned flags, + struct pipe_fence_handle **fence) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; +#if 0 + static int dc = 0; + char dname[256]; +#endif + + if (!rctx->ctx.pm4_cdwords) + return; + +#if 0 + sprintf(dname, "gallium-%08d.bof", dc); + if (dc < 20) { + r600_context_dump_bof(&rctx->ctx, dname); + R600_ERR("dumped %s\n", dname); + } + dc++; +#endif + r600_context_flush(&rctx->ctx); + + r600_upload_flush(rctx->rupload_vb); +} + +static void r600_destroy_context(struct pipe_context *context) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)context; + + rctx->context.delete_depth_stencil_alpha_state(&rctx->context, rctx->custom_dsa_flush); + + r600_end_vertex_translate(rctx); + + r600_context_fini(&rctx->ctx); + + util_blitter_destroy(rctx->blitter); + + for (int i = 0; i < R600_PIPE_NSTATES; i++) { + free(rctx->states[i]); + } + + r600_upload_destroy(rctx->rupload_vb); + + if (rctx->tran.translate_cache) + translate_cache_destroy(rctx->tran.translate_cache); + + FREE(rctx->ps_resource); + FREE(rctx->vs_resource); + FREE(rctx); +} + +static struct pipe_context *r600_create_context(struct pipe_screen *screen, void *priv) +{ + struct r600_pipe_context *rctx = CALLOC_STRUCT(r600_pipe_context); + struct r600_screen* rscreen = (struct r600_screen *)screen; + enum chip_class class; + + if (rctx == NULL) + return NULL; + rctx->context.winsys = rscreen->screen.winsys; + rctx->context.screen = screen; + rctx->context.priv = priv; + rctx->context.destroy = r600_destroy_context; + rctx->context.flush = r600_flush; + + /* Easy accessing of screen/winsys. */ + rctx->screen = rscreen; + rctx->radeon = rscreen->radeon; + rctx->family = r600_get_family(rctx->radeon); + + r600_init_blit_functions(rctx); + r600_init_query_functions(rctx); + r600_init_context_resource_functions(rctx); + r600_init_surface_functions(rctx); + + switch (r600_get_family(rctx->radeon)) { + case CHIP_R600: + case CHIP_RV610: + case CHIP_RV630: + case CHIP_RV670: + case CHIP_RV620: + case CHIP_RV635: + case CHIP_RS780: + case CHIP_RS880: + case CHIP_RV770: + case CHIP_RV730: + case CHIP_RV710: + case CHIP_RV740: + rctx->context.draw_vbo = r600_draw_vbo; + r600_init_state_functions(rctx); + if (r600_context_init(&rctx->ctx, rctx->radeon)) { + r600_destroy_context(&rctx->context); + return NULL; + } + r600_init_config(rctx); + break; + case CHIP_CEDAR: + case CHIP_REDWOOD: + case CHIP_JUNIPER: + case CHIP_CYPRESS: + case CHIP_HEMLOCK: + case CHIP_PALM: + case CHIP_BARTS: + case CHIP_TURKS: + case CHIP_CAICOS: + rctx->context.draw_vbo = evergreen_draw; + evergreen_init_state_functions(rctx); + if (evergreen_context_init(&rctx->ctx, rctx->radeon)) { + r600_destroy_context(&rctx->context); + return NULL; + } + evergreen_init_config(rctx); + break; + default: + R600_ERR("unsupported family %d\n", r600_get_family(rctx->radeon)); + r600_destroy_context(&rctx->context); + return NULL; + } + + rctx->rupload_vb = r600_upload_create(rctx, 128 * 1024, 16); + if (rctx->rupload_vb == NULL) { + r600_destroy_context(&rctx->context); + return NULL; + } + + rctx->blitter = util_blitter_create(&rctx->context); + if (rctx->blitter == NULL) { + FREE(rctx); + return NULL; + } + + rctx->tran.translate_cache = translate_cache_create(); + if (rctx->tran.translate_cache == NULL) { + FREE(rctx); + return NULL; + } + + rctx->vs_resource = CALLOC(R600_RESOURCE_ARRAY_SIZE, sizeof(struct r600_pipe_state)); + if (!rctx->vs_resource) { + FREE(rctx); + return NULL; + } + + rctx->ps_resource = CALLOC(R600_RESOURCE_ARRAY_SIZE, sizeof(struct r600_pipe_state)); + if (!rctx->ps_resource) { + FREE(rctx); + return NULL; + } + + class = r600_get_family_class(rctx->radeon); + if (class == R600 || class == R700) + rctx->custom_dsa_flush = r600_create_db_flush_dsa(rctx); + else + rctx->custom_dsa_flush = evergreen_create_db_flush_dsa(rctx); + + r600_blit_uncompress_depth_ptr = r600_blit_uncompress_depth; + + return &rctx->context; +} + +/* + * pipe_screen + */ +static const char* r600_get_vendor(struct pipe_screen* pscreen) +{ + return "X.Org"; +} + +static const char *r600_get_family_name(enum radeon_family family) +{ + switch(family) { + case CHIP_R600: return "AMD R600"; + case CHIP_RV610: return "AMD RV610"; + case CHIP_RV630: return "AMD RV630"; + case CHIP_RV670: return "AMD RV670"; + case CHIP_RV620: return "AMD RV620"; + case CHIP_RV635: return "AMD RV635"; + case CHIP_RS780: return "AMD RS780"; + case CHIP_RS880: return "AMD RS880"; + case CHIP_RV770: return "AMD RV770"; + case CHIP_RV730: return "AMD RV730"; + case CHIP_RV710: return "AMD RV710"; + case CHIP_RV740: return "AMD RV740"; + case CHIP_CEDAR: return "AMD CEDAR"; + case CHIP_REDWOOD: return "AMD REDWOOD"; + case CHIP_JUNIPER: return "AMD JUNIPER"; + case CHIP_CYPRESS: return "AMD CYPRESS"; + case CHIP_HEMLOCK: return "AMD HEMLOCK"; + case CHIP_PALM: return "AMD PALM"; + case CHIP_BARTS: return "AMD BARTS"; + case CHIP_TURKS: return "AMD TURKS"; + case CHIP_CAICOS: return "AMD CAICOS"; + default: return "AMD unknown"; + } +} + +static const char* r600_get_name(struct pipe_screen* pscreen) +{ + struct r600_screen *rscreen = (struct r600_screen *)pscreen; + enum radeon_family family = r600_get_family(rscreen->radeon); + + return r600_get_family_name(family); +} + +static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param) +{ + struct r600_screen *rscreen = (struct r600_screen *)pscreen; + enum radeon_family family = r600_get_family(rscreen->radeon); + + switch (param) { + /* Supported features (boolean caps). */ + case PIPE_CAP_NPOT_TEXTURES: + case PIPE_CAP_TWO_SIDED_STENCIL: + case PIPE_CAP_GLSL: + case PIPE_CAP_DUAL_SOURCE_BLEND: + case PIPE_CAP_ANISOTROPIC_FILTER: + case PIPE_CAP_POINT_SPRITE: + case PIPE_CAP_OCCLUSION_QUERY: + case PIPE_CAP_TEXTURE_SHADOW_MAP: + case PIPE_CAP_TEXTURE_MIRROR_CLAMP: + case PIPE_CAP_TEXTURE_MIRROR_REPEAT: + case PIPE_CAP_BLEND_EQUATION_SEPARATE: + case PIPE_CAP_SM3: + case PIPE_CAP_TEXTURE_SWIZZLE: + case PIPE_CAP_INDEP_BLEND_ENABLE: + case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: + case PIPE_CAP_DEPTH_CLAMP: + case PIPE_CAP_SHADER_STENCIL_EXPORT: + return 1; + + /* Unsupported features (boolean caps). */ + case PIPE_CAP_TIMER_QUERY: + case PIPE_CAP_STREAM_OUTPUT: + case PIPE_CAP_PRIMITIVE_RESTART: + case PIPE_CAP_INDEP_BLEND_FUNC: /* FIXME allow this */ + return 0; + + /* Texturing. */ + case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: + case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: + case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: + if (family >= CHIP_CEDAR) + return 15; + else + return 14; + case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS: + /* FIXME allow this once infrastructure is there */ + return 16; + case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: + case PIPE_CAP_MAX_COMBINED_SAMPLERS: + return 16; + + /* Render targets. */ + case PIPE_CAP_MAX_RENDER_TARGETS: + /* FIXME some r6xx are buggy and can only do 4 */ + return 8; + + /* Fragment coordinate conventions. */ + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: + return 1; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: + return 0; + + default: + R600_ERR("r600: unknown param %d\n", param); + return 0; + } +} + +static float r600_get_paramf(struct pipe_screen* pscreen, enum pipe_cap param) +{ + struct r600_screen *rscreen = (struct r600_screen *)pscreen; + enum radeon_family family = r600_get_family(rscreen->radeon); + + switch (param) { + case PIPE_CAP_MAX_LINE_WIDTH: + case PIPE_CAP_MAX_LINE_WIDTH_AA: + case PIPE_CAP_MAX_POINT_WIDTH: + case PIPE_CAP_MAX_POINT_WIDTH_AA: + if (family >= CHIP_CEDAR) + return 16384.0f; + else + return 8192.0f; + case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: + return 16.0f; + case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: + return 16.0f; + default: + R600_ERR("r600: unsupported paramf %d\n", param); + return 0.0f; + } +} + +static int r600_get_shader_param(struct pipe_screen* pscreen, unsigned shader, enum pipe_shader_cap param) +{ + switch(shader) + { + case PIPE_SHADER_FRAGMENT: + case PIPE_SHADER_VERTEX: + break; + case PIPE_SHADER_GEOMETRY: + /* TODO: support and enable geometry programs */ + return 0; + default: + /* TODO: support tessellation on Evergreen */ + return 0; + } + + /* TODO: all these should be fixed, since r600 surely supports much more! */ + switch (param) { + case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: + return 16384; + case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: + return 8; /* FIXME */ + case PIPE_SHADER_CAP_MAX_INPUTS: + if(shader == PIPE_SHADER_FRAGMENT) + return 10; + else + return 16; + case PIPE_SHADER_CAP_MAX_TEMPS: + return 256; //max native temporaries + case PIPE_SHADER_CAP_MAX_ADDRS: + return 1; //max native address registers/* FIXME Isn't this equal to TEMPS? */ + case PIPE_SHADER_CAP_MAX_CONSTS: + return 256; //max native parameters + case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: + return 1; + case PIPE_SHADER_CAP_MAX_PREDS: + return 0; /* FIXME */ + case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: + return 1; + case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: + case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: + return 1; + case PIPE_SHADER_CAP_SUBROUTINES: + return 0; + default: + return 0; + } +} + +static boolean r600_is_format_supported(struct pipe_screen* screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned usage, + unsigned geom_flags) +{ + unsigned retval = 0; + if (target >= PIPE_MAX_TEXTURE_TYPES) { + R600_ERR("r600: unsupported texture type %d\n", target); + return FALSE; + } + + /* Multisample */ + if (sample_count > 1) + return FALSE; + + if ((usage & PIPE_BIND_SAMPLER_VIEW) && + r600_is_sampler_format_supported(format)) { + retval |= PIPE_BIND_SAMPLER_VIEW; + } + + if ((usage & (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SCANOUT | + PIPE_BIND_SHARED)) && + r600_is_colorbuffer_format_supported(format)) { + retval |= usage & + (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SCANOUT | + PIPE_BIND_SHARED); + } + + if ((usage & PIPE_BIND_DEPTH_STENCIL) && + r600_is_zs_format_supported(format)) { + retval |= PIPE_BIND_DEPTH_STENCIL; + } + + if ((usage & PIPE_BIND_VERTEX_BUFFER) && + r600_is_vertex_format_supported(format)) + retval |= PIPE_BIND_VERTEX_BUFFER; + + if (usage & PIPE_BIND_TRANSFER_READ) + retval |= PIPE_BIND_TRANSFER_READ; + if (usage & PIPE_BIND_TRANSFER_WRITE) + retval |= PIPE_BIND_TRANSFER_WRITE; + + return retval == usage; +} + +static void r600_destroy_screen(struct pipe_screen* pscreen) +{ + struct r600_screen *rscreen = (struct r600_screen *)pscreen; + + if (rscreen == NULL) + return; + + radeon_decref(rscreen->radeon); + + FREE(rscreen); +} + + +struct pipe_screen *r600_screen_create(struct radeon *radeon) +{ + struct r600_screen *rscreen; + + rscreen = CALLOC_STRUCT(r600_screen); + if (rscreen == NULL) { + return NULL; + } + + rscreen->radeon = radeon; + rscreen->screen.winsys = (struct pipe_winsys*)radeon; + rscreen->screen.destroy = r600_destroy_screen; + rscreen->screen.get_name = r600_get_name; + rscreen->screen.get_vendor = r600_get_vendor; + rscreen->screen.get_param = r600_get_param; + rscreen->screen.get_shader_param = r600_get_shader_param; + rscreen->screen.get_paramf = r600_get_paramf; + rscreen->screen.is_format_supported = r600_is_format_supported; + rscreen->screen.context_create = r600_create_context; + r600_init_screen_resource_functions(&rscreen->screen); + + rscreen->tiling_info = r600_get_tiling_info(radeon); + + return &rscreen->screen; +} diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h new file mode 100644 index 0000000..43dbee9 --- /dev/null +++ b/src/gallium/drivers/r600/r600_pipe.h @@ -0,0 +1,290 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#ifndef R600_PIPE_H +#define R600_PIPE_H + +#include +#include +#include +#include +#include "translate/translate_cache.h" +#include "r600.h" +#include "r600_public.h" +#include "r600_shader.h" +#include "r600_resource.h" + +enum r600_pipe_state_id { + R600_PIPE_STATE_BLEND = 0, + R600_PIPE_STATE_BLEND_COLOR, + R600_PIPE_STATE_CONFIG, + R600_PIPE_STATE_CLIP, + R600_PIPE_STATE_SCISSOR, + R600_PIPE_STATE_VIEWPORT, + R600_PIPE_STATE_RASTERIZER, + R600_PIPE_STATE_VGT, + R600_PIPE_STATE_FRAMEBUFFER, + R600_PIPE_STATE_DSA, + R600_PIPE_STATE_STENCIL_REF, + R600_PIPE_STATE_PS_SHADER, + R600_PIPE_STATE_VS_SHADER, + R600_PIPE_STATE_CONSTANT, + R600_PIPE_STATE_SAMPLER, + R600_PIPE_STATE_RESOURCE, + R600_PIPE_STATE_POLYGON_OFFSET, + R600_PIPE_STATE_FETCH_SHADER, + R600_PIPE_NSTATES +}; + +struct r600_screen { + struct pipe_screen screen; + struct radeon *radeon; + struct r600_tiling_info *tiling_info; +}; + +struct r600_pipe_sampler_view { + struct pipe_sampler_view base; + struct r600_pipe_state state; +}; + +struct r600_pipe_rasterizer { + struct r600_pipe_state rstate; + bool flatshade; + unsigned sprite_coord_enable; + float offset_units; + float offset_scale; +}; + +struct r600_pipe_blend { + struct r600_pipe_state rstate; + unsigned cb_target_mask; +}; + +struct r600_vertex_element +{ + unsigned count; + struct pipe_vertex_element elements[PIPE_MAX_ATTRIBS]; + enum pipe_format hw_format[PIPE_MAX_ATTRIBS]; + unsigned hw_format_size[PIPE_MAX_ATTRIBS]; + boolean incompatible_layout; + struct r600_bo *fetch_shader; + unsigned fs_size; + struct r600_pipe_state rstate; + /* if offset is to big for fetch instructio we need to alterate + * offset of vertex buffer, record here the offset need to add + */ + unsigned vbuffer_need_offset; + unsigned vbuffer_offset[PIPE_MAX_ATTRIBS]; +}; + +struct r600_pipe_shader { + struct r600_shader shader; + struct r600_pipe_state rstate; + struct r600_bo *bo; + struct r600_bo *bo_fetch; + struct r600_vertex_element vertex_elements; +}; + +/* needed for blitter save */ +#define NUM_TEX_UNITS 16 + +struct r600_textures_info { + struct r600_pipe_sampler_view *views[NUM_TEX_UNITS]; + unsigned n_views; + void *samplers[NUM_TEX_UNITS]; + unsigned n_samplers; +}; + +/* vertex buffer translation context, used to translate vertex input that + * hw doesn't natively support, so far only FLOAT64 is unsupported. + */ +struct r600_translate_context { + /* Translate cache for incompatible vertex offset/stride/format fallback. */ + struct translate_cache *translate_cache; + /* The vertex buffer slot containing the translated buffer. */ + unsigned vb_slot; + void *new_velems; +}; + +#define R600_CONSTANT_ARRAY_SIZE 256 +#define R600_RESOURCE_ARRAY_SIZE 160 + +struct r600_upload; + +struct r600_pipe_context { + struct pipe_context context; + struct blitter_context *blitter; + struct pipe_framebuffer_state *pframebuffer; + unsigned family; + void *custom_dsa_flush; + struct r600_screen *screen; + struct radeon *radeon; + struct r600_pipe_state *states[R600_PIPE_NSTATES]; + struct r600_context ctx; + struct r600_vertex_element *vertex_elements; + struct pipe_framebuffer_state framebuffer; + struct pipe_index_buffer index_buffer; + struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; + unsigned nvertex_buffer; + unsigned cb_target_mask; + /* for saving when using blitter */ + struct pipe_stencil_ref stencil_ref; + struct pipe_viewport_state viewport; + struct pipe_clip_state clip; + unsigned nvs_resource; + struct r600_pipe_state *vs_resource; + struct r600_pipe_state *ps_resource; + struct r600_pipe_state config; + struct r600_pipe_shader *ps_shader; + struct r600_pipe_shader *vs_shader; + struct r600_pipe_state vs_const_buffer; + struct r600_pipe_state ps_const_buffer; + struct r600_pipe_rasterizer *rasterizer; + /* shader information */ + unsigned sprite_coord_enable; + bool flatshade; + struct r600_upload *rupload_vb; + unsigned any_user_vbs; + struct r600_textures_info ps_samplers; + unsigned vb_max_index; + struct r600_translate_context tran; +}; + +struct r600_drawl { + struct pipe_context *ctx; + unsigned mode; + unsigned min_index; + unsigned max_index; + unsigned index_bias; + unsigned start; + unsigned count; + unsigned index_size; + unsigned index_buffer_offset; + struct pipe_resource *index_buffer; +}; + +/* evergreen_state.c */ +void evergreen_init_state_functions(struct r600_pipe_context *rctx); +void evergreen_init_config(struct r600_pipe_context *rctx); +void evergreen_draw(struct pipe_context *ctx, const struct pipe_draw_info *info); +void evergreen_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shader); +void evergreen_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader *shader); +void *evergreen_create_db_flush_dsa(struct r600_pipe_context *rctx); +void evergreen_polygon_offset_update(struct r600_pipe_context *rctx); +void evergreen_vertex_buffer_update(struct r600_pipe_context *rctx); + +/* r600_blit.c */ +void r600_init_blit_functions(struct r600_pipe_context *rctx); +int r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_texture *texture); + +/* r600_buffer.c */ +struct pipe_resource *r600_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *templ); +struct pipe_resource *r600_user_buffer_create(struct pipe_screen *screen, + void *ptr, unsigned bytes, + unsigned bind); +unsigned r600_buffer_is_referenced_by_cs(struct pipe_context *context, + struct pipe_resource *buf, + unsigned level, int layer); +struct pipe_resource *r600_buffer_from_handle(struct pipe_screen *screen, + struct winsys_handle *whandle); +int r600_upload_index_buffer(struct r600_pipe_context *rctx, struct r600_drawl *draw); +int r600_upload_user_buffers(struct r600_pipe_context *rctx); + +/* r600_query.c */ +void r600_init_query_functions(struct r600_pipe_context *rctx); + +/* r600_resource.c */ +void r600_init_context_resource_functions(struct r600_pipe_context *r600); + +/* r600_shader.c */ +int r600_pipe_shader(struct pipe_context *ctx, struct r600_pipe_shader *shader); +int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader, const struct tgsi_token *tokens); +void r600_pipe_shader_destroy(struct pipe_context *ctx, struct r600_pipe_shader *shader); +int r600_find_vs_semantic_index(struct r600_shader *vs, + struct r600_shader *ps, int id); + +/* r600_state.c */ +void r600_init_state_functions(struct r600_pipe_context *rctx); +void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info); +void r600_init_config(struct r600_pipe_context *rctx); +void *r600_create_db_flush_dsa(struct r600_pipe_context *rctx); +void r600_polygon_offset_update(struct r600_pipe_context *rctx); +void r600_vertex_buffer_update(struct r600_pipe_context *rctx); + +/* r600_helper.h */ +int r600_conv_pipe_prim(unsigned pprim, unsigned *prim); + +/* r600_texture.c */ +void r600_init_screen_texture_functions(struct pipe_screen *screen); +void r600_init_surface_functions(struct r600_pipe_context *r600); +uint32_t r600_translate_texformat(enum pipe_format format, + const unsigned char *swizzle_view, + uint32_t *word4_p, uint32_t *yuv_format_p); +unsigned r600_texture_get_offset(struct r600_resource_texture *rtex, + unsigned level, unsigned layer); + +/* r600_translate.c */ +void r600_begin_vertex_translate(struct r600_pipe_context *rctx); +void r600_end_vertex_translate(struct r600_pipe_context *rctx); +void r600_translate_index_buffer(struct r600_pipe_context *r600, + struct pipe_resource **index_buffer, + unsigned *index_size, + unsigned *start, unsigned count); + +/* r600_state_common.c */ +void r600_set_index_buffer(struct pipe_context *ctx, + const struct pipe_index_buffer *ib); +void r600_set_vertex_buffers(struct pipe_context *ctx, unsigned count, + const struct pipe_vertex_buffer *buffers); +void *r600_create_vertex_elements(struct pipe_context *ctx, + unsigned count, + const struct pipe_vertex_element *elements); +void r600_delete_vertex_element(struct pipe_context *ctx, void *state); +void r600_bind_blend_state(struct pipe_context *ctx, void *state); +void r600_bind_rs_state(struct pipe_context *ctx, void *state); +void r600_delete_rs_state(struct pipe_context *ctx, void *state); +void r600_sampler_view_destroy(struct pipe_context *ctx, + struct pipe_sampler_view *state); +void r600_bind_state(struct pipe_context *ctx, void *state); +void r600_delete_state(struct pipe_context *ctx, void *state); +void r600_bind_vertex_elements(struct pipe_context *ctx, void *state); +void *r600_create_shader_state(struct pipe_context *ctx, + const struct pipe_shader_state *state); +void r600_bind_ps_shader(struct pipe_context *ctx, void *state); +void r600_bind_vs_shader(struct pipe_context *ctx, void *state); +void r600_delete_ps_shader(struct pipe_context *ctx, void *state); +void r600_delete_vs_shader(struct pipe_context *ctx, void *state); + +/* + * common helpers + */ +static INLINE u32 S_FIXED(float value, u32 frac_bits) +{ + return value * (1 << frac_bits); +} +#define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y)) + +#endif diff --git a/src/gallium/drivers/r600/r600_public.h b/src/gallium/drivers/r600/r600_public.h new file mode 100644 index 0000000..f197020 --- /dev/null +++ b/src/gallium/drivers/r600/r600_public.h @@ -0,0 +1,28 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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 R600_PUBLIC_H +#define R600_PUBLIC_H + +struct pipe_screen *r600_screen_create(struct radeon *radeon); + +#endif diff --git a/src/gallium/drivers/r600/r600_query.c b/src/gallium/drivers/r600/r600_query.c new file mode 100644 index 0000000..7266682 --- /dev/null +++ b/src/gallium/drivers/r600/r600_query.c @@ -0,0 +1,76 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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 "r600_pipe.h" + +static struct pipe_query *r600_create_query(struct pipe_context *ctx, unsigned query_type) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + + return (struct pipe_query*)r600_context_query_create(&rctx->ctx, query_type); +} + +static void r600_destroy_query(struct pipe_context *ctx, struct pipe_query *query) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + + r600_context_query_destroy(&rctx->ctx, (struct r600_query *)query); +} + +static void r600_begin_query(struct pipe_context *ctx, struct pipe_query *query) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_query *rquery = (struct r600_query *)query; + + rquery->result = 0; + rquery->num_results = 0; + r600_query_begin(&rctx->ctx, (struct r600_query *)query); +} + +static void r600_end_query(struct pipe_context *ctx, struct pipe_query *query) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + + r600_query_end(&rctx->ctx, (struct r600_query *)query); +} + +static boolean r600_get_query_result(struct pipe_context *ctx, + struct pipe_query *query, + boolean wait, void *vresult) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_query *rquery = (struct r600_query *)query; + + if (rquery->num_results) { + ctx->flush(ctx, 0, NULL); + } + return r600_context_query_result(&rctx->ctx, (struct r600_query *)query, wait, vresult); +} + +void r600_init_query_functions(struct r600_pipe_context *rctx) +{ + rctx->context.create_query = r600_create_query; + rctx->context.destroy_query = r600_destroy_query; + rctx->context.begin_query = r600_begin_query; + rctx->context.end_query = r600_end_query; + rctx->context.get_query_result = r600_get_query_result; +} diff --git a/src/gallium/drivers/r600/r600_resource.c b/src/gallium/drivers/r600/r600_resource.c new file mode 100644 index 0000000..207642c --- /dev/null +++ b/src/gallium/drivers/r600/r600_resource.c @@ -0,0 +1,65 @@ +/* + * Copyright 2010 Marek Olšák target == PIPE_BUFFER) { + return r600_buffer_create(screen, templ); + } else { + return r600_texture_create(screen, templ); + } +} + +static struct pipe_resource *r600_resource_from_handle(struct pipe_screen * screen, + const struct pipe_resource *templ, + struct winsys_handle *whandle) +{ + if (templ->target == PIPE_BUFFER) { + return NULL; + } else { + return r600_texture_from_handle(screen, templ, whandle); + } +} + +void r600_init_screen_resource_functions(struct pipe_screen *screen) +{ + screen->resource_create = r600_resource_create; + screen->resource_from_handle = r600_resource_from_handle; + screen->resource_get_handle = u_resource_get_handle_vtbl; + screen->resource_destroy = u_resource_destroy_vtbl; + screen->user_buffer_create = r600_user_buffer_create; +} + +void r600_init_context_resource_functions(struct r600_pipe_context *r600) +{ + r600->context.get_transfer = u_get_transfer_vtbl; + r600->context.transfer_map = u_transfer_map_vtbl; + r600->context.transfer_flush_region = u_transfer_flush_region_vtbl; + r600->context.transfer_unmap = u_transfer_unmap_vtbl; + r600->context.transfer_destroy = u_transfer_destroy_vtbl; + r600->context.transfer_inline_write = u_transfer_inline_write_vtbl; + r600->context.is_resource_referenced = u_is_resource_referenced_vtbl; +} diff --git a/src/gallium/drivers/r600/r600_resource.h b/src/gallium/drivers/r600/r600_resource.h new file mode 100644 index 0000000..8ca2769 --- /dev/null +++ b/src/gallium/drivers/r600/r600_resource.h @@ -0,0 +1,135 @@ +/* + * Copyright 2010 Marek Olšák magic == R600_BUFFER_MAGIC); + return (struct r600_resource_buffer *)buffer; + } + return NULL; +} + +static INLINE boolean r600_buffer_is_user_buffer(struct pipe_resource *buffer) +{ + if (r600_buffer(buffer)->uploaded) + return FALSE; + return r600_buffer(buffer)->user_buffer ? TRUE : FALSE; +} + +int r600_texture_depth_flush(struct pipe_context *ctx, struct pipe_resource *texture); +int (*r600_blit_uncompress_depth_ptr)(struct pipe_context *ctx, struct r600_resource_texture *texture); + +/* r600_texture.c texture transfer functions. */ +struct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx, + struct pipe_resource *texture, + unsigned level, + unsigned usage, + const struct pipe_box *box); +void r600_texture_transfer_destroy(struct pipe_context *ctx, + struct pipe_transfer *trans); +void* r600_texture_transfer_map(struct pipe_context *ctx, + struct pipe_transfer* transfer); +void r600_texture_transfer_unmap(struct pipe_context *ctx, + struct pipe_transfer* transfer); + +struct r600_pipe_context; +struct r600_upload *r600_upload_create(struct r600_pipe_context *rctx, + unsigned default_size, + unsigned alignment); +void r600_upload_flush(struct r600_upload *upload); +void r600_upload_destroy(struct r600_upload *upload); +int r600_upload_buffer(struct r600_upload *upload, unsigned offset, + unsigned size, struct r600_resource_buffer *in_buffer, + unsigned *out_offset, unsigned *out_size, + struct r600_bo **out_buffer); + +#endif diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c new file mode 100644 index 0000000..bb5038c --- /dev/null +++ b/src/gallium/drivers/r600/r600_shader.c @@ -0,0 +1,3229 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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 "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_scan.h" +#include "tgsi/tgsi_dump.h" +#include "util/u_format.h" +#include "r600_pipe.h" +#include "r600_asm.h" +#include "r600_sq.h" +#include "r600_opcodes.h" +#include "r600d.h" +#include +#include + +static void r600_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader *shader) +{ + struct r600_pipe_state *rstate = &shader->rstate; + struct r600_shader *rshader = &shader->shader; + unsigned spi_vs_out_id[10]; + unsigned i, tmp; + + /* clear previous register */ + rstate->nregs = 0; + + /* so far never got proper semantic id from tgsi */ + /* FIXME better to move this in config things so they get emited + * only one time per cs + */ + for (i = 0; i < 10; i++) { + spi_vs_out_id[i] = 0; + } + for (i = 0; i < 32; i++) { + tmp = i << ((i & 3) * 8); + spi_vs_out_id[i / 4] |= tmp; + } + for (i = 0; i < 10; i++) { + r600_pipe_state_add_reg(rstate, + R_028614_SPI_VS_OUT_ID_0 + i * 4, + spi_vs_out_id[i], 0xFFFFFFFF, NULL); + } + + r600_pipe_state_add_reg(rstate, + R_0286C4_SPI_VS_OUT_CONFIG, + S_0286C4_VS_EXPORT_COUNT(rshader->noutput - 2), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028868_SQ_PGM_RESOURCES_VS, + S_028868_NUM_GPRS(rshader->bc.ngpr) | + S_028868_STACK_SIZE(rshader->bc.nstack), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_0288D0_SQ_PGM_CF_OFFSET_VS, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028858_SQ_PGM_START_VS, + r600_bo_offset(shader->bo) >> 8, 0xFFFFFFFF, shader->bo); + + r600_pipe_state_add_reg(rstate, + R_03E200_SQ_LOOP_CONST_0 + (32 * 4), 0x01000FFF, + 0xFFFFFFFF, NULL); + +} + +int r600_find_vs_semantic_index(struct r600_shader *vs, + struct r600_shader *ps, int id) +{ + struct r600_shader_io *input = &ps->input[id]; + + for (int i = 0; i < vs->noutput; i++) { + if (input->name == vs->output[i].name && + input->sid == vs->output[i].sid) { + return i - 1; + } + } + return 0; +} + +static void r600_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shader) +{ + struct r600_pipe_state *rstate = &shader->rstate; + struct r600_shader *rshader = &shader->shader; + unsigned i, exports_ps, num_cout, spi_ps_in_control_0, spi_input_z, spi_ps_in_control_1; + int pos_index = -1, face_index = -1; + + rstate->nregs = 0; + + for (i = 0; i < rshader->ninput; i++) { + if (rshader->input[i].name == TGSI_SEMANTIC_POSITION) + pos_index = i; + if (rshader->input[i].name == TGSI_SEMANTIC_FACE) + face_index = i; + } + + for (i = 0; i < rshader->noutput; i++) { + if (rshader->output[i].name == TGSI_SEMANTIC_POSITION) + r600_pipe_state_add_reg(rstate, + R_02880C_DB_SHADER_CONTROL, + S_02880C_Z_EXPORT_ENABLE(1), + S_02880C_Z_EXPORT_ENABLE(1), NULL); + if (rshader->output[i].name == TGSI_SEMANTIC_STENCIL) + r600_pipe_state_add_reg(rstate, + R_02880C_DB_SHADER_CONTROL, + S_02880C_STENCIL_REF_EXPORT_ENABLE(1), + S_02880C_STENCIL_REF_EXPORT_ENABLE(1), NULL); + } + + exports_ps = 0; + num_cout = 0; + for (i = 0; i < rshader->noutput; i++) { + if (rshader->output[i].name == TGSI_SEMANTIC_POSITION || rshader->output[i].name == TGSI_SEMANTIC_STENCIL) + exports_ps |= 1; + else if (rshader->output[i].name == TGSI_SEMANTIC_COLOR) { + num_cout++; + } + } + exports_ps |= S_028854_EXPORT_COLORS(num_cout); + if (!exports_ps) { + /* always at least export 1 component per pixel */ + exports_ps = 2; + } + + spi_ps_in_control_0 = S_0286CC_NUM_INTERP(rshader->ninput) | + S_0286CC_PERSP_GRADIENT_ENA(1); + spi_input_z = 0; + if (pos_index != -1) { + spi_ps_in_control_0 |= (S_0286CC_POSITION_ENA(1) | + S_0286CC_POSITION_CENTROID(rshader->input[pos_index].centroid) | + S_0286CC_POSITION_ADDR(rshader->input[pos_index].gpr) | + S_0286CC_BARYC_SAMPLE_CNTL(1)); + spi_input_z |= 1; + } + + spi_ps_in_control_1 = 0; + if (face_index != -1) { + spi_ps_in_control_1 |= S_0286D0_FRONT_FACE_ENA(1) | + S_0286D0_FRONT_FACE_ADDR(rshader->input[face_index].gpr); + } + + r600_pipe_state_add_reg(rstate, R_0286CC_SPI_PS_IN_CONTROL_0, spi_ps_in_control_0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0286D0_SPI_PS_IN_CONTROL_1, spi_ps_in_control_1, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0286D8_SPI_INPUT_Z, spi_input_z, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028840_SQ_PGM_START_PS, + r600_bo_offset(shader->bo) >> 8, 0xFFFFFFFF, shader->bo); + r600_pipe_state_add_reg(rstate, + R_028850_SQ_PGM_RESOURCES_PS, + S_028868_NUM_GPRS(rshader->bc.ngpr) | + S_028868_STACK_SIZE(rshader->bc.nstack), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028854_SQ_PGM_EXPORTS_PS, + exports_ps, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_0288CC_SQ_PGM_CF_OFFSET_PS, + 0x00000000, 0xFFFFFFFF, NULL); + + if (rshader->uses_kill) { + /* only set some bits here, the other bits are set in the dsa state */ + r600_pipe_state_add_reg(rstate, + R_02880C_DB_SHADER_CONTROL, + S_02880C_KILL_ENABLE(1), + S_02880C_KILL_ENABLE(1), NULL); + } + r600_pipe_state_add_reg(rstate, + R_03E200_SQ_LOOP_CONST_0, 0x01000FFF, + 0xFFFFFFFF, NULL); +} + +int r600_pipe_shader(struct pipe_context *ctx, struct r600_pipe_shader *shader) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_shader *rshader = &shader->shader; + void *ptr; + + /* copy new shader */ + if (shader->bo == NULL) { + shader->bo = r600_bo(rctx->radeon, rshader->bc.ndw * 4, 4096, 0, 0); + if (shader->bo == NULL) { + return -ENOMEM; + } + ptr = r600_bo_map(rctx->radeon, shader->bo, 0, NULL); + memcpy(ptr, rshader->bc.bytecode, rshader->bc.ndw * 4); + r600_bo_unmap(rctx->radeon, shader->bo); + } + /* build state */ + switch (rshader->processor_type) { + case TGSI_PROCESSOR_VERTEX: + if (rshader->family >= CHIP_CEDAR) { + evergreen_pipe_shader_vs(ctx, shader); + } else { + r600_pipe_shader_vs(ctx, shader); + } + break; + case TGSI_PROCESSOR_FRAGMENT: + if (rshader->family >= CHIP_CEDAR) { + evergreen_pipe_shader_ps(ctx, shader); + } else { + r600_pipe_shader_ps(ctx, shader); + } + break; + default: + return -EINVAL; + } + return 0; +} + +int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *shader); +int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader, const struct tgsi_token *tokens) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + int r; + +//fprintf(stderr, "--------------------------------------------------------------\n"); +//tgsi_dump(tokens, 0); + shader->shader.family = r600_get_family(rctx->radeon); + r = r600_shader_from_tgsi(tokens, &shader->shader); + if (r) { + R600_ERR("translation from TGSI failed !\n"); + return r; + } + r = r600_bc_build(&shader->shader.bc); + if (r) { + R600_ERR("building bytecode failed !\n"); + return r; + } +//r600_bc_dump(&shader->shader.bc); +//fprintf(stderr, "______________________________________________________________\n"); + return r600_pipe_shader(ctx, shader); +} + +void r600_pipe_shader_destroy(struct pipe_context *ctx, struct r600_pipe_shader *shader) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + + r600_bo_reference(rctx->radeon, &shader->bo, NULL); + r600_bc_clear(&shader->shader.bc); +} + +/* + * tgsi -> r600 shader + */ +struct r600_shader_tgsi_instruction; + +struct r600_shader_ctx { + struct tgsi_shader_info info; + struct tgsi_parse_context parse; + const struct tgsi_token *tokens; + unsigned type; + unsigned file_offset[TGSI_FILE_COUNT]; + unsigned temp_reg; + struct r600_shader_tgsi_instruction *inst_info; + struct r600_bc *bc; + struct r600_shader *shader; + u32 value[4]; + u32 *literals; + u32 nliterals; + u32 max_driver_temp_used; + /* needed for evergreen interpolation */ + boolean input_centroid; + boolean input_linear; + boolean input_perspective; + int num_interp_gpr; +}; + +struct r600_shader_tgsi_instruction { + unsigned tgsi_opcode; + unsigned is_op3; + unsigned r600_opcode; + int (*process)(struct r600_shader_ctx *ctx); +}; + +static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction[], eg_shader_tgsi_instruction[]; +static int tgsi_helper_tempx_replicate(struct r600_shader_ctx *ctx); + +static int tgsi_is_supported(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *i = &ctx->parse.FullToken.FullInstruction; + int j; + + if (i->Instruction.NumDstRegs > 1) { + R600_ERR("too many dst (%d)\n", i->Instruction.NumDstRegs); + return -EINVAL; + } + if (i->Instruction.Predicate) { + R600_ERR("predicate unsupported\n"); + return -EINVAL; + } +#if 0 + if (i->Instruction.Label) { + R600_ERR("label unsupported\n"); + return -EINVAL; + } +#endif + for (j = 0; j < i->Instruction.NumSrcRegs; j++) { + if (i->Src[j].Register.Dimension) { + R600_ERR("unsupported src %d (dimension %d)\n", j, + i->Src[j].Register.Dimension); + return -EINVAL; + } + } + for (j = 0; j < i->Instruction.NumDstRegs; j++) { + if (i->Dst[j].Register.Dimension) { + R600_ERR("unsupported dst (dimension)\n"); + return -EINVAL; + } + } + return 0; +} + +static int evergreen_interp_alu(struct r600_shader_ctx *ctx, int input) +{ + int i, r; + struct r600_bc_alu alu; + int gpr = 0, base_chan = 0; + int ij_index = 0; + + if (ctx->shader->input[input].interpolate == TGSI_INTERPOLATE_PERSPECTIVE) { + ij_index = 0; + if (ctx->shader->input[input].centroid) + ij_index++; + } else if (ctx->shader->input[input].interpolate == TGSI_INTERPOLATE_LINEAR) { + ij_index = 0; + /* if we have perspective add one */ + if (ctx->input_perspective) { + ij_index++; + /* if we have perspective centroid */ + if (ctx->input_centroid) + ij_index++; + } + if (ctx->shader->input[input].centroid) + ij_index++; + } + + /* work out gpr and base_chan from index */ + gpr = ij_index / 2; + base_chan = (2 * (ij_index % 2)) + 1; + + for (i = 0; i < 8; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + if (i < 4) + alu.inst = EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_ZW; + else + alu.inst = EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_XY; + + if ((i > 1) && (i < 6)) { + alu.dst.sel = ctx->shader->input[input].gpr; + alu.dst.write = 1; + } + + alu.dst.chan = i % 4; + + alu.src[0].sel = gpr; + alu.src[0].chan = (base_chan - (i % 2)); + + alu.src[1].sel = V_SQ_ALU_SRC_PARAM_BASE + ctx->shader->input[input].lds_pos; + + alu.bank_swizzle_force = SQ_ALU_VEC_210; + if ((i % 4) == 3) + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + return 0; +} + + +static int tgsi_declaration(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_declaration *d = &ctx->parse.FullToken.FullDeclaration; + unsigned i; + + switch (d->Declaration.File) { + case TGSI_FILE_INPUT: + i = ctx->shader->ninput++; + ctx->shader->input[i].name = d->Semantic.Name; + ctx->shader->input[i].sid = d->Semantic.Index; + ctx->shader->input[i].interpolate = d->Declaration.Interpolate; + ctx->shader->input[i].centroid = d->Declaration.Centroid; + ctx->shader->input[i].gpr = ctx->file_offset[TGSI_FILE_INPUT] + i; + if (ctx->type == TGSI_PROCESSOR_FRAGMENT && ctx->bc->chiprev == CHIPREV_EVERGREEN) { + /* turn input into interpolate on EG */ + if (ctx->shader->input[i].name != TGSI_SEMANTIC_POSITION) { + if (ctx->shader->input[i].interpolate > 0) { + ctx->shader->input[i].lds_pos = ctx->shader->nlds++; + evergreen_interp_alu(ctx, i); + } + } + } + break; + case TGSI_FILE_OUTPUT: + i = ctx->shader->noutput++; + ctx->shader->output[i].name = d->Semantic.Name; + ctx->shader->output[i].sid = d->Semantic.Index; + ctx->shader->output[i].gpr = ctx->file_offset[TGSI_FILE_OUTPUT] + i; + ctx->shader->output[i].interpolate = d->Declaration.Interpolate; + break; + case TGSI_FILE_CONSTANT: + case TGSI_FILE_TEMPORARY: + case TGSI_FILE_SAMPLER: + case TGSI_FILE_ADDRESS: + break; + default: + R600_ERR("unsupported file %d declaration\n", d->Declaration.File); + return -EINVAL; + } + return 0; +} + +static int r600_get_temp(struct r600_shader_ctx *ctx) +{ + return ctx->temp_reg + ctx->max_driver_temp_used++; +} + +/* + * for evergreen we need to scan the shader to find the number of GPRs we need to + * reserve for interpolation. + * + * we need to know if we are going to emit + * any centroid inputs + * if perspective and linear are required +*/ +static int evergreen_gpr_count(struct r600_shader_ctx *ctx) +{ + int i; + int num_baryc; + + ctx->input_linear = FALSE; + ctx->input_perspective = FALSE; + ctx->input_centroid = FALSE; + ctx->num_interp_gpr = 1; + + /* any centroid inputs */ + for (i = 0; i < ctx->info.num_inputs; i++) { + /* skip position/face */ + if (ctx->info.input_semantic_name[i] == TGSI_SEMANTIC_POSITION || + ctx->info.input_semantic_name[i] == TGSI_SEMANTIC_FACE) + continue; + if (ctx->info.input_interpolate[i] == TGSI_INTERPOLATE_LINEAR) + ctx->input_linear = TRUE; + if (ctx->info.input_interpolate[i] == TGSI_INTERPOLATE_PERSPECTIVE) + ctx->input_perspective = TRUE; + if (ctx->info.input_centroid[i]) + ctx->input_centroid = TRUE; + } + + num_baryc = 0; + /* ignoring sample for now */ + if (ctx->input_perspective) + num_baryc++; + if (ctx->input_linear) + num_baryc++; + if (ctx->input_centroid) + num_baryc *= 2; + + ctx->num_interp_gpr += (num_baryc + 1) >> 1; + + /* TODO PULL MODEL and LINE STIPPLE, FIXED PT POS */ + return ctx->num_interp_gpr; +} + +int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *shader) +{ + struct tgsi_full_immediate *immediate; + struct r600_shader_ctx ctx; + struct r600_bc_output output[32]; + unsigned output_done, noutput; + unsigned opcode; + int i, r = 0, pos0; + + ctx.bc = &shader->bc; + ctx.shader = shader; + r = r600_bc_init(ctx.bc, shader->family); + if (r) + return r; + ctx.tokens = tokens; + tgsi_scan_shader(tokens, &ctx.info); + tgsi_parse_init(&ctx.parse, tokens); + ctx.type = ctx.parse.FullHeader.Processor.Processor; + shader->processor_type = ctx.type; + ctx.bc->type = shader->processor_type; + + /* register allocations */ + /* Values [0,127] correspond to GPR[0..127]. + * Values [128,159] correspond to constant buffer bank 0 + * Values [160,191] correspond to constant buffer bank 1 + * Values [256,511] correspond to cfile constants c[0..255]. + * Other special values are shown in the list below. + * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+) + * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+) + * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+) + * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+) + * 248 SQ_ALU_SRC_0: special constant 0.0. + * 249 SQ_ALU_SRC_1: special constant 1.0 float. + * 250 SQ_ALU_SRC_1_INT: special constant 1 integer. + * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer. + * 252 SQ_ALU_SRC_0_5: special constant 0.5 float. + * 253 SQ_ALU_SRC_LITERAL: literal constant. + * 254 SQ_ALU_SRC_PV: previous vector result. + * 255 SQ_ALU_SRC_PS: previous scalar result. + */ + for (i = 0; i < TGSI_FILE_COUNT; i++) { + ctx.file_offset[i] = 0; + } + if (ctx.type == TGSI_PROCESSOR_VERTEX) { + ctx.file_offset[TGSI_FILE_INPUT] = 1; + if (ctx.bc->chiprev == CHIPREV_EVERGREEN) { + r600_bc_add_cfinst(ctx.bc, EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS); + } else { + r600_bc_add_cfinst(ctx.bc, V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS); + } + } + if (ctx.type == TGSI_PROCESSOR_FRAGMENT && ctx.bc->chiprev == CHIPREV_EVERGREEN) { + ctx.file_offset[TGSI_FILE_INPUT] = evergreen_gpr_count(&ctx); + } + ctx.file_offset[TGSI_FILE_OUTPUT] = ctx.file_offset[TGSI_FILE_INPUT] + + ctx.info.file_count[TGSI_FILE_INPUT]; + ctx.file_offset[TGSI_FILE_TEMPORARY] = ctx.file_offset[TGSI_FILE_OUTPUT] + + ctx.info.file_count[TGSI_FILE_OUTPUT]; + + ctx.file_offset[TGSI_FILE_CONSTANT] = 128; + + ctx.file_offset[TGSI_FILE_IMMEDIATE] = 253; + ctx.temp_reg = ctx.file_offset[TGSI_FILE_TEMPORARY] + + ctx.info.file_count[TGSI_FILE_TEMPORARY]; + + ctx.nliterals = 0; + ctx.literals = NULL; + + while (!tgsi_parse_end_of_tokens(&ctx.parse)) { + tgsi_parse_token(&ctx.parse); + switch (ctx.parse.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_IMMEDIATE: + immediate = &ctx.parse.FullToken.FullImmediate; + ctx.literals = realloc(ctx.literals, (ctx.nliterals + 1) * 16); + if(ctx.literals == NULL) { + r = -ENOMEM; + goto out_err; + } + ctx.literals[ctx.nliterals * 4 + 0] = immediate->u[0].Uint; + ctx.literals[ctx.nliterals * 4 + 1] = immediate->u[1].Uint; + ctx.literals[ctx.nliterals * 4 + 2] = immediate->u[2].Uint; + ctx.literals[ctx.nliterals * 4 + 3] = immediate->u[3].Uint; + ctx.nliterals++; + break; + case TGSI_TOKEN_TYPE_DECLARATION: + r = tgsi_declaration(&ctx); + if (r) + goto out_err; + break; + case TGSI_TOKEN_TYPE_INSTRUCTION: + r = tgsi_is_supported(&ctx); + if (r) + goto out_err; + ctx.max_driver_temp_used = 0; + /* reserve first tmp for everyone */ + r600_get_temp(&ctx); + opcode = ctx.parse.FullToken.FullInstruction.Instruction.Opcode; + if (ctx.bc->chiprev == CHIPREV_EVERGREEN) + ctx.inst_info = &eg_shader_tgsi_instruction[opcode]; + else + ctx.inst_info = &r600_shader_tgsi_instruction[opcode]; + r = ctx.inst_info->process(&ctx); + if (r) + goto out_err; + r = r600_bc_add_literal(ctx.bc, ctx.value); + if (r) + goto out_err; + break; + case TGSI_TOKEN_TYPE_PROPERTY: + break; + default: + R600_ERR("unsupported token type %d\n", ctx.parse.FullToken.Token.Type); + r = -EINVAL; + goto out_err; + } + } + /* export output */ + noutput = shader->noutput; + for (i = 0, pos0 = 0; i < noutput; i++) { + memset(&output[i], 0, sizeof(struct r600_bc_output)); + output[i].gpr = shader->output[i].gpr; + output[i].elem_size = 3; + output[i].swizzle_x = 0; + output[i].swizzle_y = 1; + output[i].swizzle_z = 2; + output[i].swizzle_w = 3; + output[i].barrier = 1; + output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM; + output[i].array_base = i - pos0; + output[i].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT); + switch (ctx.type) { + case TGSI_PROCESSOR_VERTEX: + if (shader->output[i].name == TGSI_SEMANTIC_POSITION) { + output[i].array_base = 60; + output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS; + /* position doesn't count in array_base */ + pos0++; + } + if (shader->output[i].name == TGSI_SEMANTIC_PSIZE) { + output[i].array_base = 61; + output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS; + /* position doesn't count in array_base */ + pos0++; + } + break; + case TGSI_PROCESSOR_FRAGMENT: + if (shader->output[i].name == TGSI_SEMANTIC_COLOR) { + output[i].array_base = shader->output[i].sid; + output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL; + } else if (shader->output[i].name == TGSI_SEMANTIC_POSITION) { + output[i].array_base = 61; + output[i].swizzle_x = 2; + output[i].swizzle_y = 7; + output[i].swizzle_z = output[i].swizzle_w = 7; + output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL; + } else if (shader->output[i].name == TGSI_SEMANTIC_STENCIL) { + output[i].array_base = 61; + output[i].swizzle_x = 7; + output[i].swizzle_y = 1; + output[i].swizzle_z = output[i].swizzle_w = 7; + output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL; + } else { + R600_ERR("unsupported fragment output name %d\n", shader->output[i].name); + r = -EINVAL; + goto out_err; + } + break; + default: + R600_ERR("unsupported processor type %d\n", ctx.type); + r = -EINVAL; + goto out_err; + } + } + /* add fake param output for vertex shader if no param is exported */ + if (ctx.type == TGSI_PROCESSOR_VERTEX) { + for (i = 0, pos0 = 0; i < noutput; i++) { + if (output[i].type == V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM) { + pos0 = 1; + break; + } + } + if (!pos0) { + memset(&output[i], 0, sizeof(struct r600_bc_output)); + output[i].gpr = 0; + output[i].elem_size = 3; + output[i].swizzle_x = 0; + output[i].swizzle_y = 1; + output[i].swizzle_z = 2; + output[i].swizzle_w = 3; + output[i].barrier = 1; + output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM; + output[i].array_base = 0; + output[i].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT); + noutput++; + } + } + /* add fake pixel export */ + if (ctx.type == TGSI_PROCESSOR_FRAGMENT && !noutput) { + memset(&output[0], 0, sizeof(struct r600_bc_output)); + output[0].gpr = 0; + output[0].elem_size = 3; + output[0].swizzle_x = 7; + output[0].swizzle_y = 7; + output[0].swizzle_z = 7; + output[0].swizzle_w = 7; + output[0].barrier = 1; + output[0].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL; + output[0].array_base = 0; + output[0].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT); + noutput++; + } + /* set export done on last export of each type */ + for (i = noutput - 1, output_done = 0; i >= 0; i--) { + if (i == (noutput - 1)) { + output[i].end_of_program = 1; + } + if (!(output_done & (1 << output[i].type))) { + output_done |= (1 << output[i].type); + output[i].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE); + } + } + /* add output to bytecode */ + for (i = 0; i < noutput; i++) { + r = r600_bc_add_output(ctx.bc, &output[i]); + if (r) + goto out_err; + } + free(ctx.literals); + tgsi_parse_free(&ctx.parse); + return 0; +out_err: + free(ctx.literals); + tgsi_parse_free(&ctx.parse); + return r; +} + +static int tgsi_unsupported(struct r600_shader_ctx *ctx) +{ + R600_ERR("%d tgsi opcode unsupported\n", ctx->inst_info->tgsi_opcode); + return -EINVAL; +} + +static int tgsi_end(struct r600_shader_ctx *ctx) +{ + return 0; +} + +static int tgsi_src(struct r600_shader_ctx *ctx, + const struct tgsi_full_src_register *tgsi_src, + struct r600_bc_alu_src *r600_src) +{ + int index; + memset(r600_src, 0, sizeof(struct r600_bc_alu_src)); + r600_src->sel = tgsi_src->Register.Index; + if (tgsi_src->Register.File == TGSI_FILE_IMMEDIATE) { + r600_src->sel = 0; + index = tgsi_src->Register.Index; + ctx->value[0] = ctx->literals[index * 4 + 0]; + ctx->value[1] = ctx->literals[index * 4 + 1]; + ctx->value[2] = ctx->literals[index * 4 + 2]; + ctx->value[3] = ctx->literals[index * 4 + 3]; + } + if (tgsi_src->Register.Indirect) + r600_src->rel = V_SQ_REL_RELATIVE; + r600_src->neg = tgsi_src->Register.Negate; + r600_src->abs = tgsi_src->Register.Absolute; + r600_src->sel += ctx->file_offset[tgsi_src->Register.File]; + return 0; +} + +static int tgsi_dst(struct r600_shader_ctx *ctx, + const struct tgsi_full_dst_register *tgsi_dst, + unsigned swizzle, + struct r600_bc_alu_dst *r600_dst) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + + r600_dst->sel = tgsi_dst->Register.Index; + r600_dst->sel += ctx->file_offset[tgsi_dst->Register.File]; + r600_dst->chan = swizzle; + r600_dst->write = 1; + if (tgsi_dst->Register.Indirect) + r600_dst->rel = V_SQ_REL_RELATIVE; + if (inst->Instruction.Saturate) { + r600_dst->clamp = 1; + } + return 0; +} + +static unsigned tgsi_chan(const struct tgsi_full_src_register *tgsi_src, unsigned swizzle) +{ + switch (swizzle) { + case 0: + return tgsi_src->Register.SwizzleX; + case 1: + return tgsi_src->Register.SwizzleY; + case 2: + return tgsi_src->Register.SwizzleZ; + case 3: + return tgsi_src->Register.SwizzleW; + default: + return 0; + } +} + +static int tgsi_split_constant(struct r600_shader_ctx *ctx, struct r600_bc_alu_src r600_src[3]) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu alu; + int i, j, k, nconst, r; + + for (i = 0, nconst = 0; i < inst->Instruction.NumSrcRegs; i++) { + if (inst->Src[i].Register.File == TGSI_FILE_CONSTANT) { + nconst++; + } + r = tgsi_src(ctx, &inst->Src[i], &r600_src[i]); + if (r) { + return r; + } + } + for (i = 0, j = nconst - 1; i < inst->Instruction.NumSrcRegs; i++) { + if (j > 0 && inst->Src[i].Register.File == TGSI_FILE_CONSTANT) { + int treg = r600_get_temp(ctx); + for (k = 0; k < 4; k++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); + alu.src[0].sel = r600_src[i].sel; + alu.src[0].chan = k; + alu.src[0].rel = r600_src[i].rel; + alu.dst.sel = treg; + alu.dst.chan = k; + alu.dst.write = 1; + if (k == 3) + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + r600_src[i].sel = treg; + r600_src[i].rel =0; + j--; + } + } + return 0; +} + +/* need to move any immediate into a temp - for trig functions which use literal for PI stuff */ +static int tgsi_split_literal_constant(struct r600_shader_ctx *ctx, struct r600_bc_alu_src r600_src[3]) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu alu; + int i, j, k, nliteral, r; + + for (i = 0, nliteral = 0; i < inst->Instruction.NumSrcRegs; i++) { + if (inst->Src[i].Register.File == TGSI_FILE_IMMEDIATE) { + nliteral++; + } + } + for (i = 0, j = nliteral - 1; i < inst->Instruction.NumSrcRegs; i++) { + if (j > 0 && inst->Src[i].Register.File == TGSI_FILE_IMMEDIATE) { + int treg = r600_get_temp(ctx); + for (k = 0; k < 4; k++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); + alu.src[0].sel = r600_src[i].sel; + alu.src[0].chan = k; + alu.dst.sel = treg; + alu.dst.chan = k; + alu.dst.write = 1; + if (k == 3) + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + r = r600_bc_add_literal(ctx->bc, &ctx->literals[inst->Src[i].Register.Index * 4]); + if (r) + return r; + r600_src[i].sel = treg; + j--; + } + } + return 0; +} + +static int tgsi_op2_s(struct r600_shader_ctx *ctx, int swap) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu_src r600_src[3]; + struct r600_bc_alu alu; + int i, j, r; + int lasti = 0; + + for (i = 0; i < 4; i++) { + if (inst->Dst[0].Register.WriteMask & (1 << i)) { + lasti = i; + } + } + + r = tgsi_split_constant(ctx, r600_src); + if (r) + return r; + r = tgsi_split_literal_constant(ctx, r600_src); + if (r) + return r; + for (i = 0; i < lasti + 1; i++) { + if (!(inst->Dst[0].Register.WriteMask & (1 << i))) + continue; + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst); + if (r) + return r; + + alu.inst = ctx->inst_info->r600_opcode; + if (!swap) { + for (j = 0; j < inst->Instruction.NumSrcRegs; j++) { + alu.src[j] = r600_src[j]; + alu.src[j].chan = tgsi_chan(&inst->Src[j], i); + } + } else { + alu.src[0] = r600_src[1]; + alu.src[0].chan = tgsi_chan(&inst->Src[1], i); + + alu.src[1] = r600_src[0]; + alu.src[1].chan = tgsi_chan(&inst->Src[0], i); + } + /* handle some special cases */ + switch (ctx->inst_info->tgsi_opcode) { + case TGSI_OPCODE_SUB: + alu.src[1].neg = 1; + break; + case TGSI_OPCODE_ABS: + alu.src[0].abs = 1; + break; + default: + break; + } + if (i == lasti) { + alu.last = 1; + } + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + return 0; +} + +static int tgsi_op2(struct r600_shader_ctx *ctx) +{ + return tgsi_op2_s(ctx, 0); +} + +static int tgsi_op2_swap(struct r600_shader_ctx *ctx) +{ + return tgsi_op2_s(ctx, 1); +} + +/* + * r600 - trunc to -PI..PI range + * r700 - normalize by dividing by 2PI + * see fdo bug 27901 + */ +static int tgsi_setup_trig(struct r600_shader_ctx *ctx, + struct r600_bc_alu_src r600_src[3]) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + int r; + uint32_t lit_vals[4]; + struct r600_bc_alu alu; + + memset(lit_vals, 0, 4*4); + r = tgsi_split_constant(ctx, r600_src); + if (r) + return r; + r = tgsi_split_literal_constant(ctx, r600_src); + if (r) + return r; + + lit_vals[0] = fui(1.0 /(3.1415926535 * 2)); + lit_vals[1] = fui(0.5f); + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD); + alu.is_op3 = 1; + + alu.dst.chan = 0; + alu.dst.sel = ctx->temp_reg; + alu.dst.write = 1; + + alu.src[0] = r600_src[0]; + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); + + alu.src[1].sel = V_SQ_ALU_SRC_LITERAL; + alu.src[1].chan = 0; + alu.src[2].sel = V_SQ_ALU_SRC_LITERAL; + alu.src[2].chan = 1; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + r = r600_bc_add_literal(ctx->bc, lit_vals); + if (r) + return r; + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT); + + alu.dst.chan = 0; + alu.dst.sel = ctx->temp_reg; + alu.dst.write = 1; + + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 0; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + if (ctx->bc->chiprev == CHIPREV_R600) { + lit_vals[0] = fui(3.1415926535897f * 2.0f); + lit_vals[1] = fui(-3.1415926535897f); + } else { + lit_vals[0] = fui(1.0f); + lit_vals[1] = fui(-0.5f); + } + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD); + alu.is_op3 = 1; + + alu.dst.chan = 0; + alu.dst.sel = ctx->temp_reg; + alu.dst.write = 1; + + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 0; + + alu.src[1].sel = V_SQ_ALU_SRC_LITERAL; + alu.src[1].chan = 0; + alu.src[2].sel = V_SQ_ALU_SRC_LITERAL; + alu.src[2].chan = 1; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + r = r600_bc_add_literal(ctx->bc, lit_vals); + if (r) + return r; + return 0; +} + +static int tgsi_trig(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu_src r600_src[3]; + struct r600_bc_alu alu; + int i, r; + int lasti = 0; + + r = tgsi_setup_trig(ctx, r600_src); + if (r) + return r; + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = ctx->inst_info->r600_opcode; + alu.dst.chan = 0; + alu.dst.sel = ctx->temp_reg; + alu.dst.write = 1; + + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 0; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + /* replicate result */ + for (i = 0; i < 4; i++) { + if (inst->Dst[0].Register.WriteMask & (1 << i)) + lasti = i; + } + for (i = 0; i < lasti + 1; i++) { + if (!(inst->Dst[0].Register.WriteMask & (1 << i))) + continue; + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); + + alu.src[0].sel = ctx->temp_reg; + r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst); + if (r) + return r; + if (i == lasti) + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + return 0; +} + +static int tgsi_scs(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu_src r600_src[3]; + struct r600_bc_alu alu; + int r; + + /* We'll only need the trig stuff if we are going to write to the + * X or Y components of the destination vector. + */ + if (likely(inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XY)) { + r = tgsi_setup_trig(ctx, r600_src); + if (r) + return r; + } + + /* dst.x = COS */ + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS); + r = tgsi_dst(ctx, &inst->Dst[0], 0, &alu.dst); + if (r) + return r; + + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 0; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + + /* dst.y = SIN */ + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN); + r = tgsi_dst(ctx, &inst->Dst[0], 1, &alu.dst); + if (r) + return r; + + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 0; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + + /* dst.z = 0.0; */ + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); + + r = tgsi_dst(ctx, &inst->Dst[0], 2, &alu.dst); + if (r) + return r; + + alu.src[0].sel = V_SQ_ALU_SRC_0; + alu.src[0].chan = 0; + + alu.last = 1; + + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + } + + /* dst.w = 1.0; */ + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); + + r = tgsi_dst(ctx, &inst->Dst[0], 3, &alu.dst); + if (r) + return r; + + alu.src[0].sel = V_SQ_ALU_SRC_1; + alu.src[0].chan = 0; + + alu.last = 1; + + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + } + + return 0; +} + +static int tgsi_kill(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu alu; + int i, r; + + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = ctx->inst_info->r600_opcode; + + alu.dst.chan = i; + + alu.src[0].sel = V_SQ_ALU_SRC_0; + + if (ctx->inst_info->tgsi_opcode == TGSI_OPCODE_KILP) { + alu.src[1].sel = V_SQ_ALU_SRC_1; + alu.src[1].neg = 1; + } else { + r = tgsi_src(ctx, &inst->Src[0], &alu.src[1]); + if (r) + return r; + alu.src[1].chan = tgsi_chan(&inst->Src[0], i); + } + if (i == 3) { + alu.last = 1; + } + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + + /* kill must be last in ALU */ + ctx->bc->force_add_cf = 1; + ctx->shader->uses_kill = TRUE; + return 0; +} + +static int tgsi_lit(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu alu; + struct r600_bc_alu_src r600_src[3]; + int r; + + r = tgsi_split_constant(ctx, r600_src); + if (r) + return r; + r = tgsi_split_literal_constant(ctx, r600_src); + if (r) + return r; + + /* dst.x, <- 1.0 */ + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); + alu.src[0].sel = V_SQ_ALU_SRC_1; /*1.0*/ + alu.src[0].chan = 0; + r = tgsi_dst(ctx, &inst->Dst[0], 0, &alu.dst); + if (r) + return r; + alu.dst.write = (inst->Dst[0].Register.WriteMask >> 0) & 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + /* dst.y = max(src.x, 0.0) */ + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX); + alu.src[0] = r600_src[0]; + alu.src[1].sel = V_SQ_ALU_SRC_0; /*0.0*/ + alu.src[1].chan = 0; + r = tgsi_dst(ctx, &inst->Dst[0], 1, &alu.dst); + if (r) + return r; + alu.dst.write = (inst->Dst[0].Register.WriteMask >> 1) & 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + /* dst.w, <- 1.0 */ + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); + alu.src[0].sel = V_SQ_ALU_SRC_1; + alu.src[0].chan = 0; + r = tgsi_dst(ctx, &inst->Dst[0], 3, &alu.dst); + if (r) + return r; + alu.dst.write = (inst->Dst[0].Register.WriteMask >> 3) & 1; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + + if (inst->Dst[0].Register.WriteMask & (1 << 2)) + { + int chan; + int sel; + + /* dst.z = log(src.y) */ + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED); + alu.src[0] = r600_src[0]; + alu.src[0].chan = tgsi_chan(&inst->Src[0], 1); + r = tgsi_dst(ctx, &inst->Dst[0], 2, &alu.dst); + if (r) + return r; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + + chan = alu.dst.chan; + sel = alu.dst.sel; + + /* tmp.x = amd MUL_LIT(src.w, dst.z, src.x ) */ + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT); + alu.src[0] = r600_src[0]; + alu.src[0].chan = tgsi_chan(&inst->Src[0], 3); + alu.src[1].sel = sel; + alu.src[1].chan = chan; + + alu.src[2] = r600_src[0]; + alu.src[2].chan = tgsi_chan(&inst->Src[0], 0); + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 0; + alu.dst.write = 1; + alu.is_op3 = 1; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + /* dst.z = exp(tmp.x) */ + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE); + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 0; + r = tgsi_dst(ctx, &inst->Dst[0], 2, &alu.dst); + if (r) + return r; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + return 0; +} + +static int tgsi_rsq(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu alu; + int i, r; + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + /* FIXME: + * For state trackers other than OpenGL, we'll want to use + * _RECIPSQRT_IEEE instead. + */ + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED); + + for (i = 0; i < inst->Instruction.NumSrcRegs; i++) { + r = tgsi_src(ctx, &inst->Src[i], &alu.src[i]); + if (r) + return r; + alu.src[i].chan = tgsi_chan(&inst->Src[i], 0); + alu.src[i].abs = 1; + } + alu.dst.sel = ctx->temp_reg; + alu.dst.write = 1; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + /* replicate result */ + return tgsi_helper_tempx_replicate(ctx); +} + +static int tgsi_helper_tempx_replicate(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu alu; + int i, r; + + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.src[0].sel = ctx->temp_reg; + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); + alu.dst.chan = i; + r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst); + if (r) + return r; + alu.dst.write = (inst->Dst[0].Register.WriteMask >> i) & 1; + if (i == 3) + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + return 0; +} + +static int tgsi_trans_srcx_replicate(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu alu; + int i, r; + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = ctx->inst_info->r600_opcode; + for (i = 0; i < inst->Instruction.NumSrcRegs; i++) { + r = tgsi_src(ctx, &inst->Src[i], &alu.src[i]); + if (r) + return r; + alu.src[i].chan = tgsi_chan(&inst->Src[i], 0); + } + alu.dst.sel = ctx->temp_reg; + alu.dst.write = 1; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + /* replicate result */ + return tgsi_helper_tempx_replicate(ctx); +} + +static int tgsi_pow(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu alu; + int r; + + /* LOG2(a) */ + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE); + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); + alu.dst.sel = ctx->temp_reg; + alu.dst.write = 1; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + r = r600_bc_add_literal(ctx->bc,ctx->value); + if (r) + return r; + /* b * LOG2(a) */ + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL); + r = tgsi_src(ctx, &inst->Src[1], &alu.src[0]); + if (r) + return r; + alu.src[0].chan = tgsi_chan(&inst->Src[1], 0); + alu.src[1].sel = ctx->temp_reg; + alu.dst.sel = ctx->temp_reg; + alu.dst.write = 1; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + r = r600_bc_add_literal(ctx->bc,ctx->value); + if (r) + return r; + /* POW(a,b) = EXP2(b * LOG2(a))*/ + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE); + alu.src[0].sel = ctx->temp_reg; + alu.dst.sel = ctx->temp_reg; + alu.dst.write = 1; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + r = r600_bc_add_literal(ctx->bc,ctx->value); + if (r) + return r; + return tgsi_helper_tempx_replicate(ctx); +} + +static int tgsi_ssg(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu alu; + struct r600_bc_alu_src r600_src[3]; + int i, r; + + r = tgsi_split_constant(ctx, r600_src); + if (r) + return r; + r = tgsi_split_literal_constant(ctx, r600_src); + if (r) + return r; + + /* tmp = (src > 0 ? 1 : src) */ + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT); + alu.is_op3 = 1; + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = i; + + alu.src[0] = r600_src[0]; + alu.src[0].chan = tgsi_chan(&inst->Src[0], i); + + alu.src[1].sel = V_SQ_ALU_SRC_1; + + alu.src[2] = r600_src[0]; + alu.src[2].chan = tgsi_chan(&inst->Src[0], i); + if (i == 3) + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + + /* dst = (-tmp > 0 ? -1 : tmp) */ + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT); + alu.is_op3 = 1; + r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst); + if (r) + return r; + + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = i; + alu.src[0].neg = 1; + + alu.src[1].sel = V_SQ_ALU_SRC_1; + alu.src[1].neg = 1; + + alu.src[2].sel = ctx->temp_reg; + alu.src[2].chan = i; + + if (i == 3) + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + return 0; +} + +static int tgsi_helper_copy(struct r600_shader_ctx *ctx, struct tgsi_full_instruction *inst) +{ + struct r600_bc_alu alu; + int i, r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + if (!(inst->Dst[0].Register.WriteMask & (1 << i))) { + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP); + alu.dst.chan = i; + } else { + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); + r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst); + if (r) + return r; + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = i; + } + if (i == 3) { + alu.last = 1; + } + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + return 0; +} + +static int tgsi_op3(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu_src r600_src[3]; + struct r600_bc_alu alu; + int i, j, r; + + r = tgsi_split_constant(ctx, r600_src); + if (r) + return r; + r = tgsi_split_literal_constant(ctx, r600_src); + if (r) + return r; + /* do it in 2 step as op3 doesn't support writemask */ + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = ctx->inst_info->r600_opcode; + for (j = 0; j < inst->Instruction.NumSrcRegs; j++) { + alu.src[j] = r600_src[j]; + alu.src[j].chan = tgsi_chan(&inst->Src[j], i); + } + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = i; + alu.dst.write = 1; + alu.is_op3 = 1; + if (i == 3) { + alu.last = 1; + } + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + return tgsi_helper_copy(ctx, inst); +} + +static int tgsi_dp(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu_src r600_src[3]; + struct r600_bc_alu alu; + int i, j, r; + + r = tgsi_split_constant(ctx, r600_src); + if (r) + return r; + r = tgsi_split_literal_constant(ctx, r600_src); + if (r) + return r; + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = ctx->inst_info->r600_opcode; + for (j = 0; j < inst->Instruction.NumSrcRegs; j++) { + alu.src[j] = r600_src[j]; + alu.src[j].chan = tgsi_chan(&inst->Src[j], i); + } + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = i; + alu.dst.write = 1; + /* handle some special cases */ + switch (ctx->inst_info->tgsi_opcode) { + case TGSI_OPCODE_DP2: + if (i > 1) { + alu.src[0].sel = alu.src[1].sel = V_SQ_ALU_SRC_0; + alu.src[0].chan = alu.src[1].chan = 0; + } + break; + case TGSI_OPCODE_DP3: + if (i > 2) { + alu.src[0].sel = alu.src[1].sel = V_SQ_ALU_SRC_0; + alu.src[0].chan = alu.src[1].chan = 0; + } + break; + case TGSI_OPCODE_DPH: + if (i == 3) { + alu.src[0].sel = V_SQ_ALU_SRC_1; + alu.src[0].chan = 0; + alu.src[0].neg = 0; + } + break; + default: + break; + } + if (i == 3) { + alu.last = 1; + } + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + return tgsi_helper_copy(ctx, inst); +} + +static int tgsi_tex(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_tex tex; + struct r600_bc_alu alu; + unsigned src_gpr; + int r, i; + int opcode; + boolean src_not_temp = inst->Src[0].Register.File != TGSI_FILE_TEMPORARY; + uint32_t lit_vals[4]; + + src_gpr = ctx->file_offset[inst->Src[0].Register.File] + inst->Src[0].Register.Index; + + if (inst->Instruction.Opcode == TGSI_OPCODE_TXP) { + /* Add perspective divide */ + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE); + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + + alu.src[0].chan = tgsi_chan(&inst->Src[0], 3); + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 3; + alu.last = 1; + alu.dst.write = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + for (i = 0; i < 3; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL); + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 3; + r = tgsi_src(ctx, &inst->Src[0], &alu.src[1]); + if (r) + return r; + alu.src[1].chan = tgsi_chan(&inst->Src[0], i); + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = i; + alu.dst.write = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); + alu.src[0].sel = V_SQ_ALU_SRC_1; + alu.src[0].chan = 0; + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 3; + alu.last = 1; + alu.dst.write = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + src_not_temp = FALSE; + src_gpr = ctx->temp_reg; + } + + if (inst->Texture.Texture == TGSI_TEXTURE_CUBE) { + int src_chan, src2_chan; + + /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */ + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE); + switch (i) { + case 0: + src_chan = 2; + src2_chan = 1; + break; + case 1: + src_chan = 2; + src2_chan = 0; + break; + case 2: + src_chan = 0; + src2_chan = 2; + break; + case 3: + src_chan = 1; + src2_chan = 2; + break; + default: + assert(0); + src_chan = 0; + src2_chan = 0; + break; + } + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + alu.src[0].chan = tgsi_chan(&inst->Src[0], src_chan); + r = tgsi_src(ctx, &inst->Src[0], &alu.src[1]); + if (r) + return r; + alu.src[1].chan = tgsi_chan(&inst->Src[0], src2_chan); + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = i; + if (i == 3) + alu.last = 1; + alu.dst.write = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + + /* tmp1.z = RCP_e(|tmp1.z|) */ + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE); + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 2; + alu.src[0].abs = 1; + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 2; + alu.dst.write = 1; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x + * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x + * muladd has no writemask, have to use another temp + */ + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD); + alu.is_op3 = 1; + + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 0; + alu.src[1].sel = ctx->temp_reg; + alu.src[1].chan = 2; + + alu.src[2].sel = V_SQ_ALU_SRC_LITERAL; + alu.src[2].chan = 0; + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 0; + alu.dst.write = 1; + + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD); + alu.is_op3 = 1; + + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 1; + alu.src[1].sel = ctx->temp_reg; + alu.src[1].chan = 2; + + alu.src[2].sel = V_SQ_ALU_SRC_LITERAL; + alu.src[2].chan = 0; + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 1; + alu.dst.write = 1; + + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + lit_vals[0] = fui(1.5f); + + r = r600_bc_add_literal(ctx->bc, lit_vals); + if (r) + return r; + src_not_temp = FALSE; + src_gpr = ctx->temp_reg; + } + + if (src_not_temp) { + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); + alu.src[0].sel = src_gpr; + alu.src[0].chan = tgsi_chan(&inst->Src[0], i); + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = i; + if (i == 3) + alu.last = 1; + alu.dst.write = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + src_gpr = ctx->temp_reg; + } + + opcode = ctx->inst_info->r600_opcode; + if (opcode == SQ_TEX_INST_SAMPLE && + (inst->Texture.Texture == TGSI_TEXTURE_SHADOW1D || inst->Texture.Texture == TGSI_TEXTURE_SHADOW2D)) + opcode = SQ_TEX_INST_SAMPLE_C; + + memset(&tex, 0, sizeof(struct r600_bc_tex)); + tex.inst = opcode; + tex.sampler_id = ctx->file_offset[inst->Src[1].Register.File] + inst->Src[1].Register.Index; + tex.resource_id = tex.sampler_id; + tex.src_gpr = src_gpr; + tex.dst_gpr = ctx->file_offset[inst->Dst[0].Register.File] + inst->Dst[0].Register.Index; + tex.dst_sel_x = (inst->Dst[0].Register.WriteMask & 1) ? 0 : 7; + tex.dst_sel_y = (inst->Dst[0].Register.WriteMask & 2) ? 1 : 7; + tex.dst_sel_z = (inst->Dst[0].Register.WriteMask & 4) ? 2 : 7; + tex.dst_sel_w = (inst->Dst[0].Register.WriteMask & 8) ? 3 : 7; + tex.src_sel_x = 0; + tex.src_sel_y = 1; + tex.src_sel_z = 2; + tex.src_sel_w = 3; + + if (inst->Texture.Texture == TGSI_TEXTURE_CUBE) { + tex.src_sel_x = 1; + tex.src_sel_y = 0; + tex.src_sel_z = 3; + tex.src_sel_w = 1; + } + + if (inst->Texture.Texture != TGSI_TEXTURE_RECT) { + tex.coord_type_x = 1; + tex.coord_type_y = 1; + tex.coord_type_z = 1; + tex.coord_type_w = 1; + } + + if (inst->Texture.Texture == TGSI_TEXTURE_SHADOW1D || inst->Texture.Texture == TGSI_TEXTURE_SHADOW2D) + tex.src_sel_w = 2; + + r = r600_bc_add_tex(ctx->bc, &tex); + if (r) + return r; + + /* add shadow ambient support - gallium doesn't do it yet */ + return 0; +} + +static int tgsi_lrp(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu_src r600_src[3]; + struct r600_bc_alu alu; + unsigned i; + int r; + + r = tgsi_split_constant(ctx, r600_src); + if (r) + return r; + r = tgsi_split_literal_constant(ctx, r600_src); + if (r) + return r; + /* 1 - src0 */ + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD); + alu.src[0].sel = V_SQ_ALU_SRC_1; + alu.src[0].chan = 0; + alu.src[1] = r600_src[0]; + alu.src[1].chan = tgsi_chan(&inst->Src[0], i); + alu.src[1].neg = 1; + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = i; + if (i == 3) { + alu.last = 1; + } + alu.dst.write = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + + /* (1 - src0) * src2 */ + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL); + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = i; + alu.src[1] = r600_src[2]; + alu.src[1].chan = tgsi_chan(&inst->Src[2], i); + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = i; + if (i == 3) { + alu.last = 1; + } + alu.dst.write = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + + /* src0 * src1 + (1 - src0) * src2 */ + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD); + alu.is_op3 = 1; + alu.src[0] = r600_src[0]; + alu.src[0].chan = tgsi_chan(&inst->Src[0], i); + alu.src[1] = r600_src[1]; + alu.src[1].chan = tgsi_chan(&inst->Src[1], i); + alu.src[2].sel = ctx->temp_reg; + alu.src[2].chan = i; + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = i; + if (i == 3) { + alu.last = 1; + } + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + return tgsi_helper_copy(ctx, inst); +} + +static int tgsi_cmp(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu_src r600_src[3]; + struct r600_bc_alu alu; + int use_temp = 0; + int i, r; + + r = tgsi_split_constant(ctx, r600_src); + if (r) + return r; + r = tgsi_split_literal_constant(ctx, r600_src); + if (r) + return r; + + if (inst->Dst[0].Register.WriteMask != 0xf) + use_temp = 1; + + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE); + alu.src[0] = r600_src[0]; + alu.src[0].chan = tgsi_chan(&inst->Src[0], i); + + alu.src[1] = r600_src[2]; + alu.src[1].chan = tgsi_chan(&inst->Src[2], i); + + alu.src[2] = r600_src[1]; + alu.src[2].chan = tgsi_chan(&inst->Src[1], i); + + if (use_temp) + alu.dst.sel = ctx->temp_reg; + else { + r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst); + if (r) + return r; + } + alu.dst.chan = i; + alu.dst.write = 1; + alu.is_op3 = 1; + if (i == 3) + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + if (use_temp) + return tgsi_helper_copy(ctx, inst); + return 0; +} + +static int tgsi_xpd(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu_src r600_src[3]; + struct r600_bc_alu alu; + uint32_t use_temp = 0; + int i, r; + + if (inst->Dst[0].Register.WriteMask != 0xf) + use_temp = 1; + + r = tgsi_split_constant(ctx, r600_src); + if (r) + return r; + r = tgsi_split_literal_constant(ctx, r600_src); + if (r) + return r; + + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL); + + alu.src[0] = r600_src[0]; + switch (i) { + case 0: + alu.src[0].chan = tgsi_chan(&inst->Src[0], 2); + break; + case 1: + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); + break; + case 2: + alu.src[0].chan = tgsi_chan(&inst->Src[0], 1); + break; + case 3: + alu.src[0].sel = V_SQ_ALU_SRC_0; + alu.src[0].chan = i; + } + + alu.src[1] = r600_src[1]; + switch (i) { + case 0: + alu.src[1].chan = tgsi_chan(&inst->Src[1], 1); + break; + case 1: + alu.src[1].chan = tgsi_chan(&inst->Src[1], 2); + break; + case 2: + alu.src[1].chan = tgsi_chan(&inst->Src[1], 0); + break; + case 3: + alu.src[1].sel = V_SQ_ALU_SRC_0; + alu.src[1].chan = i; + } + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = i; + alu.dst.write = 1; + + if (i == 3) + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + } + + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD); + + alu.src[0] = r600_src[0]; + switch (i) { + case 0: + alu.src[0].chan = tgsi_chan(&inst->Src[0], 1); + break; + case 1: + alu.src[0].chan = tgsi_chan(&inst->Src[0], 2); + break; + case 2: + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); + break; + case 3: + alu.src[0].sel = V_SQ_ALU_SRC_0; + alu.src[0].chan = i; + } + + alu.src[1] = r600_src[1]; + switch (i) { + case 0: + alu.src[1].chan = tgsi_chan(&inst->Src[1], 2); + break; + case 1: + alu.src[1].chan = tgsi_chan(&inst->Src[1], 0); + break; + case 2: + alu.src[1].chan = tgsi_chan(&inst->Src[1], 1); + break; + case 3: + alu.src[1].sel = V_SQ_ALU_SRC_0; + alu.src[1].chan = i; + } + + alu.src[2].sel = ctx->temp_reg; + alu.src[2].neg = 1; + alu.src[2].chan = i; + + if (use_temp) + alu.dst.sel = ctx->temp_reg; + else { + r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst); + if (r) + return r; + } + alu.dst.chan = i; + alu.dst.write = 1; + alu.is_op3 = 1; + if (i == 3) + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + } + if (use_temp) + return tgsi_helper_copy(ctx, inst); + return 0; +} + +static int tgsi_exp(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu_src r600_src[3] = { { 0 } }; + struct r600_bc_alu alu; + int r; + + /* result.x = 2^floor(src); */ + if (inst->Dst[0].Register.WriteMask & 1) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR); + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 0; + alu.dst.write = 1; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE); + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 0; + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 0; + alu.dst.write = 1; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + } + + /* result.y = tmp - floor(tmp); */ + if ((inst->Dst[0].Register.WriteMask >> 1) & 1) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT); + alu.src[0] = r600_src[0]; + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); + + alu.dst.sel = ctx->temp_reg; +// r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst); +// if (r) +// return r; + alu.dst.write = 1; + alu.dst.chan = 1; + + alu.last = 1; + + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + } + + /* result.z = RoughApprox2ToX(tmp);*/ + if ((inst->Dst[0].Register.WriteMask >> 2) & 0x1) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE); + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); + + alu.dst.sel = ctx->temp_reg; + alu.dst.write = 1; + alu.dst.chan = 2; + + alu.last = 1; + + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + } + + /* result.w = 1.0;*/ + if ((inst->Dst[0].Register.WriteMask >> 3) & 0x1) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); + alu.src[0].sel = V_SQ_ALU_SRC_1; + alu.src[0].chan = 0; + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 3; + alu.dst.write = 1; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + } + return tgsi_helper_copy(ctx, inst); +} + +static int tgsi_log(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu alu; + int r; + + /* result.x = floor(log2(src)); */ + if (inst->Dst[0].Register.WriteMask & 1) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE); + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 0; + alu.dst.write = 1; + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR); + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 0; + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 0; + alu.dst.write = 1; + alu.last = 1; + + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + } + + /* result.y = src.x / (2 ^ floor(log2(src.x))); */ + if ((inst->Dst[0].Register.WriteMask >> 1) & 1) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE); + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 1; + alu.dst.write = 1; + alu.last = 1; + + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR); + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 1; + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 1; + alu.dst.write = 1; + alu.last = 1; + + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE); + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 1; + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 1; + alu.dst.write = 1; + alu.last = 1; + + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE); + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 1; + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 1; + alu.dst.write = 1; + alu.last = 1; + + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL); + + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); + + alu.src[1].sel = ctx->temp_reg; + alu.src[1].chan = 1; + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 1; + alu.dst.write = 1; + alu.last = 1; + + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + } + + /* result.z = log2(src);*/ + if ((inst->Dst[0].Register.WriteMask >> 2) & 1) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE); + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); + + alu.dst.sel = ctx->temp_reg; + alu.dst.write = 1; + alu.dst.chan = 2; + alu.last = 1; + + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + } + + /* result.w = 1.0; */ + if ((inst->Dst[0].Register.WriteMask >> 3) & 1) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); + alu.src[0].sel = V_SQ_ALU_SRC_1; + alu.src[0].chan = 0; + + alu.dst.sel = ctx->temp_reg; + alu.dst.chan = 3; + alu.dst.write = 1; + alu.last = 1; + + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + + r = r600_bc_add_literal(ctx->bc, ctx->value); + if (r) + return r; + } + + return tgsi_helper_copy(ctx, inst); +} + +static int tgsi_eg_arl(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu alu; + int r; + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_ARL: + alu.inst = EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT_FLOOR; + break; + case TGSI_OPCODE_ARR: + alu.inst = EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT; + break; + default: + assert(0); + return -1; + } + + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); + alu.last = 1; + alu.dst.chan = 0; + alu.dst.sel = ctx->temp_reg; + alu.dst.write = 1; + r = r600_bc_add_alu_type(ctx->bc, &alu, CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU)); + if (r) + return r; + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT; + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + alu.src[0].sel = ctx->temp_reg; + alu.src[0].chan = 0; + alu.last = 1; + r = r600_bc_add_alu_type(ctx->bc, &alu, CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU)); + if (r) + return r; + return 0; +} +static int tgsi_r600_arl(struct r600_shader_ctx *ctx) +{ + /* TODO from r600c, ar values don't persist between clauses */ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu alu; + int r; + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + switch (inst->Instruction.Opcode) { + case TGSI_OPCODE_ARL: + alu.inst = V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR; + break; + case TGSI_OPCODE_ARR: + alu.inst = V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA; + break; + default: + assert(0); + return -1; + } + + + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); + + alu.last = 1; + + r = r600_bc_add_alu_type(ctx->bc, &alu, CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU)); + if (r) + return r; + ctx->bc->cf_last->r6xx_uses_waterfall = 1; + return 0; +} + +static int tgsi_opdst(struct r600_shader_ctx *ctx) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu alu; + int i, r = 0; + + for (i = 0; i < 4; i++) { + memset(&alu, 0, sizeof(struct r600_bc_alu)); + + alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL); + r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst); + if (r) + return r; + + if (i == 0 || i == 3) { + alu.src[0].sel = V_SQ_ALU_SRC_1; + } else { + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + alu.src[0].chan = tgsi_chan(&inst->Src[0], i); + } + + if (i == 0 || i == 2) { + alu.src[1].sel = V_SQ_ALU_SRC_1; + } else { + r = tgsi_src(ctx, &inst->Src[1], &alu.src[1]); + if (r) + return r; + alu.src[1].chan = tgsi_chan(&inst->Src[1], i); + } + if (i == 3) + alu.last = 1; + r = r600_bc_add_alu(ctx->bc, &alu); + if (r) + return r; + } + return 0; +} + +static int emit_logic_pred(struct r600_shader_ctx *ctx, int opcode) +{ + struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction; + struct r600_bc_alu alu; + int r; + + memset(&alu, 0, sizeof(struct r600_bc_alu)); + alu.inst = opcode; + alu.predicate = 1; + + alu.dst.sel = ctx->temp_reg; + alu.dst.write = 1; + alu.dst.chan = 0; + + r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]); + if (r) + return r; + alu.src[0].chan = tgsi_chan(&inst->Src[0], 0); + alu.src[1].sel = V_SQ_ALU_SRC_0; + alu.src[1].chan = 0; + + alu.last = 1; + + r = r600_bc_add_alu_type(ctx->bc, &alu, CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE)); + if (r) + return r; + return 0; +} + +static int pops(struct r600_shader_ctx *ctx, int pops) +{ + r600_bc_add_cfinst(ctx->bc, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_POP)); + ctx->bc->cf_last->pop_count = pops; + ctx->bc->cf_last->cf_addr = ctx->bc->cf_last->id + 2; + return 0; +} + +static inline void callstack_decrease_current(struct r600_shader_ctx *ctx, unsigned reason) +{ + switch(reason) { + case FC_PUSH_VPM: + ctx->bc->callstack[ctx->bc->call_sp].current--; + break; + case FC_PUSH_WQM: + case FC_LOOP: + ctx->bc->callstack[ctx->bc->call_sp].current -= 4; + break; + case FC_REP: + /* TOODO : for 16 vp asic should -= 2; */ + ctx->bc->callstack[ctx->bc->call_sp].current --; + break; + } +} + +static inline void callstack_check_depth(struct r600_shader_ctx *ctx, unsigned reason, unsigned check_max_only) +{ + if (check_max_only) { + int diff; + switch (reason) { + case FC_PUSH_VPM: + diff = 1; + break; + case FC_PUSH_WQM: + diff = 4; + break; + default: + assert(0); + diff = 0; + } + if ((ctx->bc->callstack[ctx->bc->call_sp].current + diff) > + ctx->bc->callstack[ctx->bc->call_sp].max) { + ctx->bc->callstack[ctx->bc->call_sp].max = + ctx->bc->callstack[ctx->bc->call_sp].current + diff; + } + return; + } + switch (reason) { + case FC_PUSH_VPM: + ctx->bc->callstack[ctx->bc->call_sp].current++; + break; + case FC_PUSH_WQM: + case FC_LOOP: + ctx->bc->callstack[ctx->bc->call_sp].current += 4; + break; + case FC_REP: + ctx->bc->callstack[ctx->bc->call_sp].current++; + break; + } + + if ((ctx->bc->callstack[ctx->bc->call_sp].current) > + ctx->bc->callstack[ctx->bc->call_sp].max) { + ctx->bc->callstack[ctx->bc->call_sp].max = + ctx->bc->callstack[ctx->bc->call_sp].current; + } +} + +static void fc_set_mid(struct r600_shader_ctx *ctx, int fc_sp) +{ + struct r600_cf_stack_entry *sp = &ctx->bc->fc_stack[fc_sp]; + + sp->mid = (struct r600_bc_cf **)realloc((void *)sp->mid, + sizeof(struct r600_bc_cf *) * (sp->num_mid + 1)); + sp->mid[sp->num_mid] = ctx->bc->cf_last; + sp->num_mid++; +} + +static void fc_pushlevel(struct r600_shader_ctx *ctx, int type) +{ + ctx->bc->fc_sp++; + ctx->bc->fc_stack[ctx->bc->fc_sp].type = type; + ctx->bc->fc_stack[ctx->bc->fc_sp].start = ctx->bc->cf_last; +} + +static void fc_poplevel(struct r600_shader_ctx *ctx) +{ + struct r600_cf_stack_entry *sp = &ctx->bc->fc_stack[ctx->bc->fc_sp]; + if (sp->mid) { + free(sp->mid); + sp->mid = NULL; + } + sp->num_mid = 0; + sp->start = NULL; + sp->type = 0; + ctx->bc->fc_sp--; +} + +#if 0 +static int emit_return(struct r600_shader_ctx *ctx) +{ + r600_bc_add_cfinst(ctx->bc, V_SQ_CF_WORD1_SQ_CF_INST_RETURN); + return 0; +} + +static int emit_jump_to_offset(struct r600_shader_ctx *ctx, int pops, int offset) +{ + + r600_bc_add_cfinst(ctx->bc, V_SQ_CF_WORD1_SQ_CF_INST_JUMP); + ctx->bc->cf_last->pop_count = pops; + /* TODO work out offset */ + return 0; +} + +static int emit_setret_in_loop_flag(struct r600_shader_ctx *ctx, unsigned flag_value) +{ + return 0; +} + +static void emit_testflag(struct r600_shader_ctx *ctx) +{ + +} + +static void emit_return_on_flag(struct r600_shader_ctx *ctx, unsigned ifidx) +{ + emit_testflag(ctx); + emit_jump_to_offset(ctx, 1, 4); + emit_setret_in_loop_flag(ctx, V_SQ_ALU_SRC_0); + pops(ctx, ifidx + 1); + emit_return(ctx); +} + +static void break_loop_on_flag(struct r600_shader_ctx *ctx, unsigned fc_sp) +{ + emit_testflag(ctx); + + r600_bc_add_cfinst(ctx->bc, ctx->inst_info->r600_opcode); + ctx->bc->cf_last->pop_count = 1; + + fc_set_mid(ctx, fc_sp); + + pops(ctx, 1); +} +#endif + +static int tgsi_if(struct r600_shader_ctx *ctx) +{ + emit_logic_pred(ctx, CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE)); + + r600_bc_add_cfinst(ctx->bc, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_JUMP)); + + fc_pushlevel(ctx, FC_IF); + + callstack_check_depth(ctx, FC_PUSH_VPM, 0); + return 0; +} + +static int tgsi_else(struct r600_shader_ctx *ctx) +{ + r600_bc_add_cfinst(ctx->bc, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_ELSE)); + ctx->bc->cf_last->pop_count = 1; + + fc_set_mid(ctx, ctx->bc->fc_sp); + ctx->bc->fc_stack[ctx->bc->fc_sp].start->cf_addr = ctx->bc->cf_last->id; + return 0; +} + +static int tgsi_endif(struct r600_shader_ctx *ctx) +{ + pops(ctx, 1); + if (ctx->bc->fc_stack[ctx->bc->fc_sp].type != FC_IF) { + R600_ERR("if/endif unbalanced in shader\n"); + return -1; + } + + if (ctx->bc->fc_stack[ctx->bc->fc_sp].mid == NULL) { + ctx->bc->fc_stack[ctx->bc->fc_sp].start->cf_addr = ctx->bc->cf_last->id + 2; + ctx->bc->fc_stack[ctx->bc->fc_sp].start->pop_count = 1; + } else { + ctx->bc->fc_stack[ctx->bc->fc_sp].mid[0]->cf_addr = ctx->bc->cf_last->id + 2; + } + fc_poplevel(ctx); + + callstack_decrease_current(ctx, FC_PUSH_VPM); + return 0; +} + +static int tgsi_bgnloop(struct r600_shader_ctx *ctx) +{ + r600_bc_add_cfinst(ctx->bc, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL)); + + fc_pushlevel(ctx, FC_LOOP); + + /* check stack depth */ + callstack_check_depth(ctx, FC_LOOP, 0); + return 0; +} + +static int tgsi_endloop(struct r600_shader_ctx *ctx) +{ + int i; + + r600_bc_add_cfinst(ctx->bc, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END)); + + if (ctx->bc->fc_stack[ctx->bc->fc_sp].type != FC_LOOP) { + R600_ERR("loop/endloop in shader code are not paired.\n"); + return -EINVAL; + } + + /* fixup loop pointers - from r600isa + LOOP END points to CF after LOOP START, + LOOP START point to CF after LOOP END + BRK/CONT point to LOOP END CF + */ + ctx->bc->cf_last->cf_addr = ctx->bc->fc_stack[ctx->bc->fc_sp].start->id + 2; + + ctx->bc->fc_stack[ctx->bc->fc_sp].start->cf_addr = ctx->bc->cf_last->id + 2; + + for (i = 0; i < ctx->bc->fc_stack[ctx->bc->fc_sp].num_mid; i++) { + ctx->bc->fc_stack[ctx->bc->fc_sp].mid[i]->cf_addr = ctx->bc->cf_last->id; + } + /* TODO add LOOPRET support */ + fc_poplevel(ctx); + callstack_decrease_current(ctx, FC_LOOP); + return 0; +} + +static int tgsi_loop_brk_cont(struct r600_shader_ctx *ctx) +{ + unsigned int fscp; + + for (fscp = ctx->bc->fc_sp; fscp > 0; fscp--) + { + if (FC_LOOP == ctx->bc->fc_stack[fscp].type) + break; + } + + if (fscp == 0) { + R600_ERR("Break not inside loop/endloop pair\n"); + return -EINVAL; + } + + r600_bc_add_cfinst(ctx->bc, ctx->inst_info->r600_opcode); + ctx->bc->cf_last->pop_count = 1; + + fc_set_mid(ctx, fscp); + + pops(ctx, 1); + callstack_check_depth(ctx, FC_PUSH_VPM, 1); + return 0; +} + +static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction[] = { + {TGSI_OPCODE_ARL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_r600_arl}, + {TGSI_OPCODE_MOV, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV, tgsi_op2}, + {TGSI_OPCODE_LIT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_lit}, + + /* FIXME: + * For state trackers other than OpenGL, we'll want to use + * _RECIP_IEEE instead. + */ + {TGSI_OPCODE_RCP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED, tgsi_trans_srcx_replicate}, + + {TGSI_OPCODE_RSQ, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_rsq}, + {TGSI_OPCODE_EXP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_exp}, + {TGSI_OPCODE_LOG, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_log}, + {TGSI_OPCODE_MUL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL, tgsi_op2}, + {TGSI_OPCODE_ADD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD, tgsi_op2}, + {TGSI_OPCODE_DP3, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp}, + {TGSI_OPCODE_DP4, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp}, + {TGSI_OPCODE_DST, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_opdst}, + {TGSI_OPCODE_MIN, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN, tgsi_op2}, + {TGSI_OPCODE_MAX, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX, tgsi_op2}, + {TGSI_OPCODE_SLT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT, tgsi_op2_swap}, + {TGSI_OPCODE_SGE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE, tgsi_op2}, + {TGSI_OPCODE_MAD, 1, V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD, tgsi_op3}, + {TGSI_OPCODE_SUB, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD, tgsi_op2}, + {TGSI_OPCODE_LRP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_lrp}, + {TGSI_OPCODE_CND, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + /* gap */ + {20, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_DP2A, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + /* gap */ + {22, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {23, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_FRC, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT, tgsi_op2}, + {TGSI_OPCODE_CLAMP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_FLR, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR, tgsi_op2}, + {TGSI_OPCODE_ROUND, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_EX2, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE, tgsi_trans_srcx_replicate}, + {TGSI_OPCODE_LG2, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE, tgsi_trans_srcx_replicate}, + {TGSI_OPCODE_POW, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_pow}, + {TGSI_OPCODE_XPD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_xpd}, + /* gap */ + {32, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ABS, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV, tgsi_op2}, + {TGSI_OPCODE_RCC, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_DPH, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp}, + {TGSI_OPCODE_COS, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS, tgsi_trig}, + {TGSI_OPCODE_DDX, 0, SQ_TEX_INST_GET_GRADIENTS_H, tgsi_tex}, + {TGSI_OPCODE_DDY, 0, SQ_TEX_INST_GET_GRADIENTS_V, tgsi_tex}, + {TGSI_OPCODE_KILP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT, tgsi_kill}, /* predicated kill */ + {TGSI_OPCODE_PK2H, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_PK2US, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_PK4B, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_PK4UB, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_RFL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_SEQ, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE, tgsi_op2}, + {TGSI_OPCODE_SFL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_SGT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT, tgsi_op2}, + {TGSI_OPCODE_SIN, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN, tgsi_trig}, + {TGSI_OPCODE_SLE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE, tgsi_op2_swap}, + {TGSI_OPCODE_SNE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE, tgsi_op2}, + {TGSI_OPCODE_STR, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_TEX, 0, SQ_TEX_INST_SAMPLE, tgsi_tex}, + {TGSI_OPCODE_TXD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_TXP, 0, SQ_TEX_INST_SAMPLE, tgsi_tex}, + {TGSI_OPCODE_UP2H, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UP2US, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UP4B, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UP4UB, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_X2D, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ARA, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ARR, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_r600_arl}, + {TGSI_OPCODE_BRA, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_CAL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_RET, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_SSG, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_ssg}, + {TGSI_OPCODE_CMP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_cmp}, + {TGSI_OPCODE_SCS, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_scs}, + {TGSI_OPCODE_TXB, 0, SQ_TEX_INST_SAMPLE_L, tgsi_tex}, + {TGSI_OPCODE_NRM, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_DIV, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_DP2, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp}, + {TGSI_OPCODE_TXL, 0, SQ_TEX_INST_SAMPLE_L, tgsi_tex}, + {TGSI_OPCODE_BRK, 0, V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK, tgsi_loop_brk_cont}, + {TGSI_OPCODE_IF, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_if}, + /* gap */ + {75, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {76, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ELSE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_else}, + {TGSI_OPCODE_ENDIF, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_endif}, + /* gap */ + {79, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {80, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_PUSHA, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_POPA, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_CEIL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_I2F, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_NOT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_TRUNC, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC, tgsi_trans_srcx_replicate}, + {TGSI_OPCODE_SHL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + /* gap */ + {88, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_AND, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_OR, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_MOD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_XOR, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_SAD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_TXF, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_TXQ, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_CONT, 0, V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE, tgsi_loop_brk_cont}, + {TGSI_OPCODE_EMIT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ENDPRIM, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_BGNLOOP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_bgnloop}, + {TGSI_OPCODE_BGNSUB, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ENDLOOP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_endloop}, + {TGSI_OPCODE_ENDSUB, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + /* gap */ + {103, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {104, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {105, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {106, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_NOP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + /* gap */ + {108, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {109, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {110, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {111, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_NRM4, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_CALLNZ, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_IFC, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_BREAKC, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_KIL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT, tgsi_kill}, /* conditional kill */ + {TGSI_OPCODE_END, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_end}, /* aka HALT */ + /* gap */ + {118, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_F2I, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_IDIV, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_IMAX, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_IMIN, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_INEG, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ISGE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ISHR, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ISLT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_F2U, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_U2F, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UADD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UDIV, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UMAD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UMAX, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UMIN, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UMOD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UMUL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_USEQ, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_USGE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_USHR, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_USLT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_USNE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_SWITCH, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_CASE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_DEFAULT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ENDSWITCH, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_LAST, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, +}; + +static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction[] = { + {TGSI_OPCODE_ARL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_eg_arl}, + {TGSI_OPCODE_MOV, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV, tgsi_op2}, + {TGSI_OPCODE_LIT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_lit}, + {TGSI_OPCODE_RCP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE, tgsi_trans_srcx_replicate}, + {TGSI_OPCODE_RSQ, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE, tgsi_trans_srcx_replicate}, + {TGSI_OPCODE_EXP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_exp}, + {TGSI_OPCODE_LOG, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_MUL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL, tgsi_op2}, + {TGSI_OPCODE_ADD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD, tgsi_op2}, + {TGSI_OPCODE_DP3, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp}, + {TGSI_OPCODE_DP4, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp}, + {TGSI_OPCODE_DST, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_opdst}, + {TGSI_OPCODE_MIN, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN, tgsi_op2}, + {TGSI_OPCODE_MAX, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX, tgsi_op2}, + {TGSI_OPCODE_SLT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT, tgsi_op2_swap}, + {TGSI_OPCODE_SGE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE, tgsi_op2}, + {TGSI_OPCODE_MAD, 1, EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD, tgsi_op3}, + {TGSI_OPCODE_SUB, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD, tgsi_op2}, + {TGSI_OPCODE_LRP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_lrp}, + {TGSI_OPCODE_CND, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + /* gap */ + {20, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_DP2A, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + /* gap */ + {22, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {23, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_FRC, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT, tgsi_op2}, + {TGSI_OPCODE_CLAMP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_FLR, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR, tgsi_op2}, + {TGSI_OPCODE_ROUND, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_EX2, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE, tgsi_trans_srcx_replicate}, + {TGSI_OPCODE_LG2, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE, tgsi_trans_srcx_replicate}, + {TGSI_OPCODE_POW, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_pow}, + {TGSI_OPCODE_XPD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_xpd}, + /* gap */ + {32, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ABS, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV, tgsi_op2}, + {TGSI_OPCODE_RCC, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_DPH, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp}, + {TGSI_OPCODE_COS, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS, tgsi_trig}, + {TGSI_OPCODE_DDX, 0, SQ_TEX_INST_GET_GRADIENTS_H, tgsi_tex}, + {TGSI_OPCODE_DDY, 0, SQ_TEX_INST_GET_GRADIENTS_V, tgsi_tex}, + {TGSI_OPCODE_KILP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT, tgsi_kill}, /* predicated kill */ + {TGSI_OPCODE_PK2H, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_PK2US, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_PK4B, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_PK4UB, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_RFL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_SEQ, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE, tgsi_op2}, + {TGSI_OPCODE_SFL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_SGT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT, tgsi_op2}, + {TGSI_OPCODE_SIN, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN, tgsi_trig}, + {TGSI_OPCODE_SLE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE, tgsi_op2_swap}, + {TGSI_OPCODE_SNE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE, tgsi_op2}, + {TGSI_OPCODE_STR, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_TEX, 0, SQ_TEX_INST_SAMPLE, tgsi_tex}, + {TGSI_OPCODE_TXD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_TXP, 0, SQ_TEX_INST_SAMPLE, tgsi_tex}, + {TGSI_OPCODE_UP2H, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UP2US, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UP4B, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UP4UB, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_X2D, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ARA, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ARR, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_eg_arl}, + {TGSI_OPCODE_BRA, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_CAL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_RET, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_SSG, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_ssg}, + {TGSI_OPCODE_CMP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_cmp}, + {TGSI_OPCODE_SCS, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_scs}, + {TGSI_OPCODE_TXB, 0, SQ_TEX_INST_SAMPLE_L, tgsi_tex}, + {TGSI_OPCODE_NRM, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_DIV, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_DP2, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp}, + {TGSI_OPCODE_TXL, 0, SQ_TEX_INST_SAMPLE_L, tgsi_tex}, + {TGSI_OPCODE_BRK, 0, EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK, tgsi_loop_brk_cont}, + {TGSI_OPCODE_IF, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_if}, + /* gap */ + {75, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {76, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ELSE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_else}, + {TGSI_OPCODE_ENDIF, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_endif}, + /* gap */ + {79, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {80, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_PUSHA, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_POPA, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_CEIL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_I2F, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_NOT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_TRUNC, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC, tgsi_trans_srcx_replicate}, + {TGSI_OPCODE_SHL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + /* gap */ + {88, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_AND, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_OR, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_MOD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_XOR, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_SAD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_TXF, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_TXQ, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_CONT, 0, EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE, tgsi_loop_brk_cont}, + {TGSI_OPCODE_EMIT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ENDPRIM, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_BGNLOOP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_bgnloop}, + {TGSI_OPCODE_BGNSUB, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ENDLOOP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_endloop}, + {TGSI_OPCODE_ENDSUB, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + /* gap */ + {103, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {104, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {105, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {106, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_NOP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + /* gap */ + {108, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {109, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {110, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {111, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_NRM4, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_CALLNZ, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_IFC, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_BREAKC, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_KIL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT, tgsi_kill}, /* conditional kill */ + {TGSI_OPCODE_END, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_end}, /* aka HALT */ + /* gap */ + {118, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_F2I, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_IDIV, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_IMAX, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_IMIN, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_INEG, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ISGE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ISHR, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ISLT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_F2U, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_U2F, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UADD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UDIV, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UMAD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UMAX, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UMIN, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UMOD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_UMUL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_USEQ, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_USGE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_USHR, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_USLT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_USNE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_SWITCH, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_CASE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_DEFAULT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_ENDSWITCH, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, + {TGSI_OPCODE_LAST, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported}, +}; diff --git a/src/gallium/drivers/r600/r600_shader.h b/src/gallium/drivers/r600/r600_shader.h new file mode 100644 index 0000000..35b0331 --- /dev/null +++ b/src/gallium/drivers/r600/r600_shader.h @@ -0,0 +1,52 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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 R600_SHADER_H +#define R600_SHADER_H + +#include "r600_asm.h" + +struct r600_shader_io { + unsigned name; + unsigned gpr; + unsigned done; + int sid; + unsigned interpolate; + boolean centroid; + unsigned lds_pos; /* for evergreen */ +}; + +struct r600_shader { + unsigned processor_type; + struct r600_bc bc; + unsigned ninput; + unsigned noutput; + unsigned nlds; + struct r600_shader_io input[32]; + struct r600_shader_io output[32]; + enum radeon_family family; + boolean uses_kill; +}; + +int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *shader); + +#endif diff --git a/src/gallium/drivers/r600/r600_sq.h b/src/gallium/drivers/r600/r600_sq.h new file mode 100644 index 0000000..d812bfd --- /dev/null +++ b/src/gallium/drivers/r600/r600_sq.h @@ -0,0 +1,468 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#ifndef R600_SQ_H +#define R600_SQ_H + +#define P_SQ_CF_WORD0 +#define S_SQ_CF_WORD0_ADDR(x) (((x) & 0xFFFFFFFF) << 0) +#define G_SQ_CF_WORD0_ADDR(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_SQ_CF_WORD0_ADDR 0x00000000 +#define P_SQ_CF_WORD1 +#define S_SQ_CF_WORD1_POP_COUNT(x) (((x) & 0x7) << 0) +#define G_SQ_CF_WORD1_POP_COUNT(x) (((x) >> 0) & 0x7) +#define C_SQ_CF_WORD1_POP_COUNT 0xFFFFFFF8 +#define S_SQ_CF_WORD1_CF_CONST(x) (((x) & 0x1F) << 3) +#define G_SQ_CF_WORD1_CF_CONST(x) (((x) >> 3) & 0x1F) +#define C_SQ_CF_WORD1_CF_CONST 0xFFFFFF07 +#define S_SQ_CF_WORD1_COND(x) (((x) & 0x3) << 8) +#define G_SQ_CF_WORD1_COND(x) (((x) >> 8) & 0x3) +#define C_SQ_CF_WORD1_COND 0xFFFFFCFF +#define S_SQ_CF_WORD1_COUNT(x) (((x) & 0x7) << 10) +#define G_SQ_CF_WORD1_COUNT(x) (((x) >> 10) & 0x7) +#define C_SQ_CF_WORD1_COUNT 0xFFFFE3FF +#define S_SQ_CF_WORD1_CALL_COUNT(x) (((x) & 0x3F) << 13) +#define G_SQ_CF_WORD1_CALL_COUNT(x) (((x) >> 13) & 0x3F) +#define C_SQ_CF_WORD1_CALL_COUNT 0xFFF81FFF +#define S_SQ_CF_WORD1_END_OF_PROGRAM(x) (((x) & 0x1) << 21) +#define G_SQ_CF_WORD1_END_OF_PROGRAM(x) (((x) >> 21) & 0x1) +#define C_SQ_CF_WORD1_END_OF_PROGRAM 0xFFDFFFFF +#define S_SQ_CF_WORD1_VALID_PIXEL_MODE(x) (((x) & 0x1) << 22) +#define G_SQ_CF_WORD1_VALID_PIXEL_MODE(x) (((x) >> 22) & 0x1) +#define C_SQ_CF_WORD1_VALID_PIXEL_MODE 0xFFBFFFFF +#define S_SQ_CF_WORD1_CF_INST(x) (((x) & 0x7F) << 23) +#define G_SQ_CF_WORD1_CF_INST(x) (((x) >> 23) & 0x7F) +#define C_SQ_CF_WORD1_CF_INST 0xC07FFFFF +#define S_SQ_CF_WORD1_WHOLE_QUAD_MODE(x) (((x) & 0x1) << 30) +#define G_SQ_CF_WORD1_WHOLE_QUAD_MODE(x) (((x) >> 30) & 0x1) +#define C_SQ_CF_WORD1_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_SQ_CF_WORD1_BARRIER(x) (((x) & 0x1) << 31) +#define G_SQ_CF_WORD1_BARRIER(x) (((x) >> 31) & 0x1) +#define C_SQ_CF_WORD1_BARRIER 0x7FFFFFFF +#define P_SQ_CF_ALU_WORD0 +#define S_SQ_CF_ALU_WORD0_ADDR(x) (((x) & 0x3FFFFF) << 0) +#define G_SQ_CF_ALU_WORD0_ADDR(x) (((x) >> 0) & 0x3FFFFF) +#define C_SQ_CF_ALU_WORD0_ADDR 0xFFC00000 +#define S_SQ_CF_ALU_WORD0_KCACHE_BANK0(x) (((x) & 0xF) << 22) +#define G_SQ_CF_ALU_WORD0_KCACHE_BANK0(x) (((x) >> 22) & 0xF) +#define C_SQ_CF_ALU_WORD0_KCACHE_BANK0 0xFC3FFFFF +#define S_SQ_CF_ALU_WORD0_KCACHE_BANK1(x) (((x) & 0xF) << 26) +#define G_SQ_CF_ALU_WORD0_KCACHE_BANK1(x) (((x) >> 26) & 0xF) +#define C_SQ_CF_ALU_WORD0_KCACHE_BANK1 0xC3FFFFFF +#define S_SQ_CF_ALU_WORD0_KCACHE_MODE0(x) (((x) & 0x3) << 30) +#define G_SQ_CF_ALU_WORD0_KCACHE_MODE0(x) (((x) >> 30) & 0x3) +#define C_SQ_CF_ALU_WORD0_KCACHE_MODE0 0x3FFFFFFF +#define V_SQ_CF_KCACHE_NOP 0x00000000 +#define V_SQ_CF_KCACHE_LOCK_1 0x00000001 +#define V_SQ_CF_KCACHE_LOCK_2 0x00000002 +#define V_SQ_CF_KCACHE_LOCK_LOOP_INDEX 0x00000003 +#define P_SQ_CF_ALU_WORD1 +#define S_SQ_CF_ALU_WORD1_KCACHE_MODE1(x) (((x) & 0x3) << 0) +#define G_SQ_CF_ALU_WORD1_KCACHE_MODE1(x) (((x) >> 0) & 0x3) +#define C_SQ_CF_ALU_WORD1_KCACHE_MODE1 0xFFFFFFFC +#define S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(x) (((x) & 0xFF) << 2) +#define G_SQ_CF_ALU_WORD1_KCACHE_ADDR0(x) (((x) >> 2) & 0xFF) +#define C_SQ_CF_ALU_WORD1_KCACHE_ADDR0 0xFFFFFC03 +#define S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(x) (((x) & 0xFF) << 10) +#define G_SQ_CF_ALU_WORD1_KCACHE_ADDR1(x) (((x) >> 10) & 0xFF) +#define C_SQ_CF_ALU_WORD1_KCACHE_ADDR1 0xFFFC03FF +#define S_SQ_CF_ALU_WORD1_COUNT(x) (((x) & 0x7F) << 18) +#define G_SQ_CF_ALU_WORD1_COUNT(x) (((x) >> 18) & 0x7F) +#define C_SQ_CF_ALU_WORD1_COUNT 0xFE03FFFF +#define S_SQ_CF_ALU_WORD1_USES_WATERFALL(x) (((x) & 0x1) << 25) +#define G_SQ_CF_ALU_WORD1_USES_WATERFALL(x) (((x) >> 25) & 0x1) +#define C_SQ_CF_ALU_WORD1_USES_WATERFALL 0xFDFFFFFF +#define S_SQ_CF_ALU_WORD1_CF_INST(x) (((x) & 0xF) << 26) +#define G_SQ_CF_ALU_WORD1_CF_INST(x) (((x) >> 26) & 0xF) +#define C_SQ_CF_ALU_WORD1_CF_INST 0xC3FFFFFF +#define S_SQ_CF_ALU_WORD1_WHOLE_QUAD_MODE(x) (((x) & 0x1) << 30) +#define G_SQ_CF_ALU_WORD1_WHOLE_QUAD_MODE(x) (((x) >> 30) & 0x1) +#define C_SQ_CF_ALU_WORD1_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_SQ_CF_ALU_WORD1_BARRIER(x) (((x) & 0x1) << 31) +#define G_SQ_CF_ALU_WORD1_BARRIER(x) (((x) >> 31) & 0x1) +#define C_SQ_CF_ALU_WORD1_BARRIER 0x7FFFFFFF +#define P_SQ_CF_ALLOC_EXPORT_WORD0 +#define S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(x) (((x) & 0x1FFF) << 0) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(x) (((x) >> 0) & 0x1FFF) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE 0xFFFFE000 +#define S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(x) (((x) & 0x3) << 13) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(x) (((x) >> 13) & 0x3) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_TYPE 0xFFFF9FFF +#define V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL 0x00000000 +#define V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS 0x00000001 +#define V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM 0x00000002 +#define V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_SX 0x00000003 +#define S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(x) (((x) & 0x7F) << 15) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(x) (((x) >> 15) & 0x7F) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR 0xFFC07FFF +#define S_SQ_CF_ALLOC_EXPORT_WORD0_RW_REL(x) (((x) & 0x1) << 22) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_RW_REL(x) (((x) >> 22) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_RW_REL 0xFFBFFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD0_INDEX_GPR(x) (((x) & 0x7F) << 23) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_INDEX_GPR(x) (((x) >> 23) & 0x7F) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_INDEX_GPR 0xC07FFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(x) (((x) & 0x3) << 30) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(x) (((x) >> 30) & 0x3) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE 0x3FFFFFFF +#define P_SQ_CF_ALLOC_EXPORT_WORD1 +#define S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(x) (((x) & 0xF) << 17) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(x) (((x) >> 17) & 0xF) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT 0xFFE1FFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(x) (((x) & 0x1) << 21) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(x) (((x) >> 21) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM 0xFFDFFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_VALID_PIXEL_MODE(x) (((x) & 0x1) << 22) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_VALID_PIXEL_MODE(x) (((x) >> 22) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_VALID_PIXEL_MODE 0xFFBFFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(x) (((x) & 0x7F) << 23) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(x) (((x) >> 23) & 0x7F) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST 0xC07FFFFF + +#define S_SQ_CF_ALLOC_EXPORT_WORD1_WHOLE_QUAD_MODE(x) (((x) & 0x1) << 30) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_WHOLE_QUAD_MODE(x) (((x) >> 30) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(x) (((x) & 0x1) << 31) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(x) (((x) >> 31) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER 0x7FFFFFFF +#define P_SQ_CF_ALLOC_EXPORT_WORD1_BUF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(x) (((x) & 0xFFF) << 0) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(x) (((x) >> 0) & 0xFFF) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE 0xFFFFF000 +#define S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(x) (((x) & 0xF) << 12) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(x) (((x) >> 12) & 0xF) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK 0xFFFF0FFF +#define P_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ +#define S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(x) (((x) & 0x7) << 0) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(x) (((x) >> 0) & 0x7) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X 0xFFFFFFF8 +#define S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(x) (((x) & 0x7) << 3) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(x) (((x) >> 3) & 0x7) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y 0xFFFFFFC7 +#define S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(x) (((x) & 0x7) << 6) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(x) (((x) >> 6) & 0x7) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z 0xFFFFFE3F +#define S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(x) (((x) & 0x7) << 9) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(x) (((x) >> 9) & 0x7) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W 0xFFFFF1FF +#define P_SQ_ALU_WORD0 +#define S_SQ_ALU_WORD0_SRC0_SEL(x) (((x) & 0x1FF) << 0) +#define G_SQ_ALU_WORD0_SRC0_SEL(x) (((x) >> 0) & 0x1FF) +#define C_SQ_ALU_WORD0_SRC0_SEL 0xFFFFFE00 +/* + * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+) + * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+) + * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+) + * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+) + * 248 SQ_ALU_SRC_0: special constant 0.0. + * 249 SQ_ALU_SRC_1: special constant 1.0 float. + * 250 SQ_ALU_SRC_1_INT: special constant 1 integer. + * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer. + * 252 SQ_ALU_SRC_0_5: special constant 0.5 float. + * 253 SQ_ALU_SRC_LITERAL: literal constant. + * 254 SQ_ALU_SRC_PV: previous vector result. + * 255 SQ_ALU_SRC_PS: previous scalar result. + * 448 EG - INTERP SRC BASE + */ +#define V_SQ_ALU_SRC_0 0x000000F8 +#define V_SQ_ALU_SRC_1 0x000000F9 +#define V_SQ_ALU_SRC_1_INT 0x000000FA +#define V_SQ_ALU_SRC_M_1_INT 0x000000FB +#define V_SQ_ALU_SRC_0_5 0x000000FC +#define V_SQ_ALU_SRC_LITERAL 0x000000FD +#define V_SQ_ALU_SRC_PARAM_BASE 0x000001C0 +#define S_SQ_ALU_WORD0_SRC0_REL(x) (((x) & 0x1) << 9) +#define G_SQ_ALU_WORD0_SRC0_REL(x) (((x) >> 9) & 0x1) +#define C_SQ_ALU_WORD0_SRC0_REL 0xFFFFFDFF +#define S_SQ_ALU_WORD0_SRC0_CHAN(x) (((x) & 0x3) << 10) +#define G_SQ_ALU_WORD0_SRC0_CHAN(x) (((x) >> 10) & 0x3) +#define C_SQ_ALU_WORD0_SRC0_CHAN 0xFFFFF3FF +#define S_SQ_ALU_WORD0_SRC0_NEG(x) (((x) & 0x1) << 12) +#define G_SQ_ALU_WORD0_SRC0_NEG(x) (((x) >> 12) & 0x1) +#define C_SQ_ALU_WORD0_SRC0_NEG 0xFFFFEFFF +#define S_SQ_ALU_WORD0_SRC1_SEL(x) (((x) & 0x1FF) << 13) +#define G_SQ_ALU_WORD0_SRC1_SEL(x) (((x) >> 13) & 0x1FF) +#define C_SQ_ALU_WORD0_SRC1_SEL 0xFFC01FFF +#define S_SQ_ALU_WORD0_SRC1_REL(x) (((x) & 0x1) << 22) +#define G_SQ_ALU_WORD0_SRC1_REL(x) (((x) >> 22) & 0x1) +#define C_SQ_ALU_WORD0_SRC1_REL 0xFFBFFFFF +#define S_SQ_ALU_WORD0_SRC1_CHAN(x) (((x) & 0x3) << 23) +#define G_SQ_ALU_WORD0_SRC1_CHAN(x) (((x) >> 23) & 0x3) +#define C_SQ_ALU_WORD0_SRC1_CHAN 0xFE7FFFFF +#define S_SQ_ALU_WORD0_SRC1_NEG(x) (((x) & 0x1) << 25) +#define G_SQ_ALU_WORD0_SRC1_NEG(x) (((x) >> 25) & 0x1) +#define C_SQ_ALU_WORD0_SRC1_NEG 0xFDFFFFFF +#define S_SQ_ALU_WORD0_INDEX_MODE(x) (((x) & 0x7) << 26) +#define G_SQ_ALU_WORD0_INDEX_MODE(x) (((x) >> 26) & 0x7) +#define C_SQ_ALU_WORD0_INDEX_MODE 0xE3FFFFFF +#define S_SQ_ALU_WORD0_PRED_SEL(x) (((x) & 0x3) << 29) +#define G_SQ_ALU_WORD0_PRED_SEL(x) (((x) >> 29) & 0x3) +#define C_SQ_ALU_WORD0_PRED_SEL 0x9FFFFFFF +#define S_SQ_ALU_WORD0_LAST(x) (((x) & 0x1) << 31) +#define G_SQ_ALU_WORD0_LAST(x) (((x) >> 31) & 0x1) +#define C_SQ_ALU_WORD0_LAST 0x7FFFFFFF +#define P_SQ_ALU_WORD1 +#define S_SQ_ALU_WORD1_ENCODING(x) (((x) & 0x7) << 15) +#define G_SQ_ALU_WORD1_ENCODING(x) (((x) >> 15) & 0x7) +#define C_SQ_ALU_WORD1_ENCODING 0xFFFC7FFF +#define S_SQ_ALU_WORD1_BANK_SWIZZLE(x) (((x) & 0x7) << 18) +#define G_SQ_ALU_WORD1_BANK_SWIZZLE(x) (((x) >> 18) & 0x7) +#define C_SQ_ALU_WORD1_BANK_SWIZZLE 0xFFE3FFFF +#define S_SQ_ALU_WORD1_DST_GPR(x) (((x) & 0x7F) << 21) +#define G_SQ_ALU_WORD1_DST_GPR(x) (((x) >> 21) & 0x7F) +#define C_SQ_ALU_WORD1_DST_GPR 0xF01FFFFF +#define S_SQ_ALU_WORD1_DST_REL(x) (((x) & 0x1) << 28) +#define G_SQ_ALU_WORD1_DST_REL(x) (((x) >> 28) & 0x1) +#define C_SQ_ALU_WORD1_DST_REL 0xEFFFFFFF +#define S_SQ_ALU_WORD1_DST_CHAN(x) (((x) & 0x3) << 29) +#define G_SQ_ALU_WORD1_DST_CHAN(x) (((x) >> 29) & 0x3) +#define C_SQ_ALU_WORD1_DST_CHAN 0x9FFFFFFF +#define S_SQ_ALU_WORD1_CLAMP(x) (((x) & 0x1) << 31) +#define G_SQ_ALU_WORD1_CLAMP(x) (((x) >> 31) & 0x1) +#define C_SQ_ALU_WORD1_CLAMP 0x7FFFFFFF +#define P_SQ_ALU_WORD1_OP2 +#define S_SQ_ALU_WORD1_OP2_SRC0_ABS(x) (((x) & 0x1) << 0) +#define G_SQ_ALU_WORD1_OP2_SRC0_ABS(x) (((x) >> 0) & 0x1) +#define C_SQ_ALU_WORD1_OP2_SRC0_ABS 0xFFFFFFFE +#define S_SQ_ALU_WORD1_OP2_SRC1_ABS(x) (((x) & 0x1) << 1) +#define G_SQ_ALU_WORD1_OP2_SRC1_ABS(x) (((x) >> 1) & 0x1) +#define C_SQ_ALU_WORD1_OP2_SRC1_ABS 0xFFFFFFFD +#define S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(x) (((x) & 0x1) << 2) +#define G_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(x) (((x) >> 2) & 0x1) +#define C_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK 0xFFFFFFFB +#define S_SQ_ALU_WORD1_OP2_UPDATE_PRED(x) (((x) & 0x1) << 3) +#define G_SQ_ALU_WORD1_OP2_UPDATE_PRED(x) (((x) >> 3) & 0x1) +#define C_SQ_ALU_WORD1_OP2_UPDATE_PRED 0xFFFFFFF7 +#define S_SQ_ALU_WORD1_OP2_WRITE_MASK(x) (((x) & 0x1) << 4) +#define G_SQ_ALU_WORD1_OP2_WRITE_MASK(x) (((x) >> 4) & 0x1) +#define C_SQ_ALU_WORD1_OP2_WRITE_MASK 0xFFFFFFEF +#define S_SQ_ALU_WORD1_OP2_FOG_MERGE(x) (((x) & 0x1) << 5) +#define G_SQ_ALU_WORD1_OP2_FOG_MERGE(x) (((x) >> 5) & 0x1) +#define C_SQ_ALU_WORD1_OP2_FOG_MERGE 0xFFFFFFDF +#define S_SQ_ALU_WORD1_OP2_OMOD(x) (((x) & 0x3) << 6) +#define G_SQ_ALU_WORD1_OP2_OMOD(x) (((x) >> 6) & 0x3) +#define C_SQ_ALU_WORD1_OP2_OMOD 0xFFFFFF3F +#define S_SQ_ALU_WORD1_OP2_ALU_INST(x) (((x) & 0x3FF) << 8) +#define G_SQ_ALU_WORD1_OP2_ALU_INST(x) (((x) >> 8) & 0x3FF) +#define C_SQ_ALU_WORD1_OP2_ALU_INST 0xFFFC00FF +#define P_SQ_ALU_WORD1_OP3 +#define S_SQ_ALU_WORD1_OP3_SRC2_SEL(x) (((x) & 0x1FF) << 0) +#define G_SQ_ALU_WORD1_OP3_SRC2_SEL(x) (((x) >> 0) & 0x1FF) +#define C_SQ_ALU_WORD1_OP3_SRC2_SEL 0xFFFFFE00 +#define S_SQ_ALU_WORD1_OP3_SRC2_REL(x) (((x) & 0x1) << 9) +#define G_SQ_ALU_WORD1_OP3_SRC2_REL(x) (((x) >> 9) & 0x1) +#define C_SQ_ALU_WORD1_OP3_SRC2_REL 0xFFFFFDFF +#define S_SQ_ALU_WORD1_OP3_SRC2_CHAN(x) (((x) & 0x3) << 10) +#define G_SQ_ALU_WORD1_OP3_SRC2_CHAN(x) (((x) >> 10) & 0x3) +#define C_SQ_ALU_WORD1_OP3_SRC2_CHAN 0xFFFFF3FF +#define S_SQ_ALU_WORD1_OP3_SRC2_NEG(x) (((x) & 0x1) << 12) +#define G_SQ_ALU_WORD1_OP3_SRC2_NEG(x) (((x) >> 12) & 0x1) +#define C_SQ_ALU_WORD1_OP3_SRC2_NEG 0xFFFFEFFF +#define S_SQ_ALU_WORD1_OP3_ALU_INST(x) (((x) & 0x1F) << 13) +#define G_SQ_ALU_WORD1_OP3_ALU_INST(x) (((x) >> 13) & 0x1F) +#define C_SQ_ALU_WORD1_OP3_ALU_INST 0xFFFC1FFF +#define P_SQ_VTX_WORD0 +#define S_SQ_VTX_WORD0_VTX_INST(x) (((x) & 0x1F) << 0) +#define G_SQ_VTX_WORD0_VTX_INST(x) (((x) >> 0) & 0x1F) +#define C_SQ_VTX_WORD0_VTX_INST 0xFFFFFFE0 +#define S_SQ_VTX_WORD0_FETCH_TYPE(x) (((x) & 0x3) << 5) +#define G_SQ_VTX_WORD0_FETCH_TYPE(x) (((x) >> 5) & 0x3) +#define C_SQ_VTX_WORD0_FETCH_TYPE 0xFFFFFF9F +#define S_SQ_VTX_WORD0_FETCH_WHOLE_QUAD(x) (((x) & 0x1) << 7) +#define G_SQ_VTX_WORD0_FETCH_WHOLE_QUAD(x) (((x) >> 7) & 0x1) +#define C_SQ_VTX_WORD0_FETCH_WHOLE_QUAD 0xFFFFFF7F +#define S_SQ_VTX_WORD0_BUFFER_ID(x) (((x) & 0xFF) << 8) +#define G_SQ_VTX_WORD0_BUFFER_ID(x) (((x) >> 8) & 0xFF) +#define C_SQ_VTX_WORD0_BUFFER_ID 0xFFFF00FF +#define S_SQ_VTX_WORD0_SRC_GPR(x) (((x) & 0x7F) << 16) +#define G_SQ_VTX_WORD0_SRC_GPR(x) (((x) >> 16) & 0x7F) +#define C_SQ_VTX_WORD0_SRC_GPR 0xFF80FFFF +#define S_SQ_VTX_WORD0_SRC_REL(x) (((x) & 0x1) << 23) +#define G_SQ_VTX_WORD0_SRC_REL(x) (((x) >> 23) & 0x1) +#define C_SQ_VTX_WORD0_SRC_REL 0xFF7FFFFF +#define S_SQ_VTX_WORD0_SRC_SEL_X(x) (((x) & 0x3) << 24) +#define G_SQ_VTX_WORD0_SRC_SEL_X(x) (((x) >> 24) & 0x3) +#define C_SQ_VTX_WORD0_SRC_SEL_X 0xFCFFFFFF +#define S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(x) (((x) & 0x3F) << 26) +#define G_SQ_VTX_WORD0_MEGA_FETCH_COUNT(x) (((x) >> 26) & 0x3F) +#define C_SQ_VTX_WORD0_MEGA_FETCH_COUNT 0x03FFFFFF +#define P_SQ_VTX_WORD1 +#define S_SQ_VTX_WORD1_DST_SEL_X(x) (((x) & 0x7) << 9) +#define G_SQ_VTX_WORD1_DST_SEL_X(x) (((x) >> 9) & 0x7) +#define C_SQ_VTX_WORD1_DST_SEL_X 0xFFFFF1FF +#define S_SQ_VTX_WORD1_DST_SEL_Y(x) (((x) & 0x7) << 12) +#define G_SQ_VTX_WORD1_DST_SEL_Y(x) (((x) >> 12) & 0x7) +#define C_SQ_VTX_WORD1_DST_SEL_Y 0xFFFF8FFF +#define S_SQ_VTX_WORD1_DST_SEL_Z(x) (((x) & 0x7) << 15) +#define G_SQ_VTX_WORD1_DST_SEL_Z(x) (((x) >> 15) & 0x7) +#define C_SQ_VTX_WORD1_DST_SEL_Z 0xFFFC7FFF +#define S_SQ_VTX_WORD1_DST_SEL_W(x) (((x) & 0x7) << 18) +#define G_SQ_VTX_WORD1_DST_SEL_W(x) (((x) >> 18) & 0x7) +#define C_SQ_VTX_WORD1_DST_SEL_W 0xFFE3FFFF +#define S_SQ_VTX_WORD1_USE_CONST_FIELDS(x) (((x) & 0x1) << 21) +#define G_SQ_VTX_WORD1_USE_CONST_FIELDS(x) (((x) >> 21) & 0x1) +#define C_SQ_VTX_WORD1_USE_CONST_FIELDS 0xFFDFFFFF +#define S_SQ_VTX_WORD1_DATA_FORMAT(x) (((x) & 0x3F) << 22) +#define G_SQ_VTX_WORD1_DATA_FORMAT(x) (((x) >> 22) & 0x3F) +#define C_SQ_VTX_WORD1_DATA_FORMAT 0xF03FFFFF +#define S_SQ_VTX_WORD1_NUM_FORMAT_ALL(x) (((x) & 0x3) << 28) +#define G_SQ_VTX_WORD1_NUM_FORMAT_ALL(x) (((x) >> 28) & 0x3) +#define C_SQ_VTX_WORD1_NUM_FORMAT_ALL 0xCFFFFFFF +#define S_SQ_VTX_WORD1_FORMAT_COMP_ALL(x) (((x) & 0x1) << 30) +#define G_SQ_VTX_WORD1_FORMAT_COMP_ALL(x) (((x) >> 30) & 0x1) +#define C_SQ_VTX_WORD1_FORMAT_COMP_ALL 0xBFFFFFFF +#define S_SQ_VTX_WORD1_SRF_MODE_ALL(x) (((x) & 0x1) << 31) +#define G_SQ_VTX_WORD1_SRF_MODE_ALL(x) (((x) >> 31) & 0x1) +#define C_SQ_VTX_WORD1_SRF_MODE_ALL 0x7FFFFFFF +#define P_SQ_VTX_WORD1_GPR +#define S_SQ_VTX_WORD1_GPR_DST_GPR(x) (((x) & 0x7F) << 0) +#define G_SQ_VTX_WORD1_GPR_DST_GPR(x) (((x) >> 0) & 0x7F) +#define C_SQ_VTX_WORD1_GPR_DST_GPR 0xFFFFFF80 +#define S_SQ_VTX_WORD1_GPR_DST_REL(x) (((x) & 0x1) << 7) +#define G_SQ_VTX_WORD1_GPR_DST_REL(x) (((x) >> 7) & 0x1) +#define C_SQ_VTX_WORD1_GPR_DST_REL 0xFFFFFF7F +#define P_SQ_VTX_WORD1_SEM +#define S_SQ_VTX_WORD1_SEM_SEMANTIC_ID(x) (((x) & 0xFF) << 0) +#define G_SQ_VTX_WORD1_SEM_SEMANTIC_ID(x) (((x) >> 0) & 0xFF) +#define C_SQ_VTX_WORD1_SEM_SEMANTIC_ID 0xFFFFFF00 +#define P_SQ_VTX_WORD2 +#define S_SQ_VTX_WORD2_OFFSET(x) (((x) & 0xFFFF) << 0) +#define G_SQ_VTX_WORD2_OFFSET(x) (((x) >> 0) & 0xFFFF) +#define C_SQ_VTX_WORD2_OFFSET 0xFFFF0000 +#define S_SQ_VTX_WORD2_ENDIAN_SWAP(x) (((x) & 0x3) << 16) +#define G_SQ_VTX_WORD2_ENDIAN_SWAP(x) (((x) >> 16) & 0x3) +#define C_SQ_VTX_WORD2_ENDIAN_SWAP 0xFFFCFFFF +#define S_SQ_VTX_WORD2_CONST_BUF_NO_STRIDE(x) (((x) & 0x1) << 18) +#define G_SQ_VTX_WORD2_CONST_BUF_NO_STRIDE(x) (((x) >> 18) & 0x1) +#define C_SQ_VTX_WORD2_CONST_BUF_NO_STRIDE 0xFFFBFFFF +#define S_SQ_VTX_WORD2_MEGA_FETCH(x) (((x) & 0x1) << 19) +#define G_SQ_VTX_WORD2_MEGA_FETCH(x) (((x) >> 19) & 0x1) +#define C_SQ_VTX_WORD2_MEGA_FETCH 0xFFF7FFFF +#define S_SQ_VTX_WORD2_ALT_CONST(x) (((x) & 0x1) << 20) +#define G_SQ_VTX_WORD2_ALT_CONST(x) (((x) >> 20) & 0x1) +#define C_SQ_VTX_WORD2_ALT_CONST 0xFFEFFFFF +#define P_SQ_TEX_WORD0 +#define S_SQ_TEX_WORD0_TEX_INST(x) (((x) & 0x1F) << 0) +#define G_SQ_TEX_WORD0_TEX_INST(x) (((x) >> 0) & 0x1F) +#define C_SQ_TEX_WORD0_TEX_INST 0xFFFFFFE0 +#define S_SQ_TEX_WORD0_BC_FRAC_MODE(x) (((x) & 0x1) << 5) +#define G_SQ_TEX_WORD0_BC_FRAC_MODE(x) (((x) >> 5) & 0x1) +#define C_SQ_TEX_WORD0_BC_FRAC_MODE 0xFFFFFFDF +#define S_SQ_TEX_WORD0_FETCH_WHOLE_QUAD(x) (((x) & 0x1) << 7) +#define G_SQ_TEX_WORD0_FETCH_WHOLE_QUAD(x) (((x) >> 7) & 0x1) +#define C_SQ_TEX_WORD0_FETCH_WHOLE_QUAD 0xFFFFFF7F +#define S_SQ_TEX_WORD0_RESOURCE_ID(x) (((x) & 0xFF) << 8) +#define G_SQ_TEX_WORD0_RESOURCE_ID(x) (((x) >> 8) & 0xFF) +#define C_SQ_TEX_WORD0_RESOURCE_ID 0xFFFF00FF +#define S_SQ_TEX_WORD0_SRC_GPR(x) (((x) & 0x7F) << 16) +#define G_SQ_TEX_WORD0_SRC_GPR(x) (((x) >> 16) & 0x7F) +#define C_SQ_TEX_WORD0_SRC_GPR 0xFF80FFFF +#define S_SQ_TEX_WORD0_SRC_REL(x) (((x) & 0x1) << 23) +#define G_SQ_TEX_WORD0_SRC_REL(x) (((x) >> 23) & 0x1) +#define C_SQ_TEX_WORD0_SRC_REL 0xFF7FFFFF +#define S_SQ_TEX_WORD0_ALT_CONST(x) (((x) & 0x1) << 24) +#define G_SQ_TEX_WORD0_ALT_CONST(x) (((x) >> 24) & 0x1) +#define C_SQ_TEX_WORD0_ALT_CONST 0xFEFFFFFF +#define P_SQ_TEX_WORD1 +#define S_SQ_TEX_WORD1_DST_GPR(x) (((x) & 0x7F) << 0) +#define G_SQ_TEX_WORD1_DST_GPR(x) (((x) >> 0) & 0x7F) +#define C_SQ_TEX_WORD1_DST_GPR 0xFFFFFF80 +#define S_SQ_TEX_WORD1_DST_REL(x) (((x) & 0x1) << 7) +#define G_SQ_TEX_WORD1_DST_REL(x) (((x) >> 7) & 0x1) +#define C_SQ_TEX_WORD1_DST_REL 0xFFFFFF7F +#define S_SQ_TEX_WORD1_DST_SEL_X(x) (((x) & 0x7) << 9) +#define G_SQ_TEX_WORD1_DST_SEL_X(x) (((x) >> 9) & 0x7) +#define C_SQ_TEX_WORD1_DST_SEL_X 0xFFFFF1FF +#define S_SQ_TEX_WORD1_DST_SEL_Y(x) (((x) & 0x7) << 12) +#define G_SQ_TEX_WORD1_DST_SEL_Y(x) (((x) >> 12) & 0x7) +#define C_SQ_TEX_WORD1_DST_SEL_Y 0xFFFF8FFF +#define S_SQ_TEX_WORD1_DST_SEL_Z(x) (((x) & 0x7) << 15) +#define G_SQ_TEX_WORD1_DST_SEL_Z(x) (((x) >> 15) & 0x7) +#define C_SQ_TEX_WORD1_DST_SEL_Z 0xFFFC7FFF +#define S_SQ_TEX_WORD1_DST_SEL_W(x) (((x) & 0x7) << 18) +#define G_SQ_TEX_WORD1_DST_SEL_W(x) (((x) >> 18) & 0x7) +#define C_SQ_TEX_WORD1_DST_SEL_W 0xFFE3FFFF +#define S_SQ_TEX_WORD1_LOD_BIAS(x) (((x) & 0x7F) << 21) +#define G_SQ_TEX_WORD1_LOD_BIAS(x) (((x) >> 21) & 0x7F) +#define C_SQ_TEX_WORD1_LOD_BIAS 0xF01FFFFF +#define S_SQ_TEX_WORD1_COORD_TYPE_X(x) (((x) & 0x1) << 28) +#define G_SQ_TEX_WORD1_COORD_TYPE_X(x) (((x) >> 28) & 0x1) +#define C_SQ_TEX_WORD1_COORD_TYPE_X 0xEFFFFFFF +#define V_SQ_TEX_WORD1_COORD_UNNORMALIZED 0x00000000 +#define V_SQ_TEX_WORD1_COORD_NORMALIZED 0x00000001 +#define S_SQ_TEX_WORD1_COORD_TYPE_Y(x) (((x) & 0x1) << 29) +#define G_SQ_TEX_WORD1_COORD_TYPE_Y(x) (((x) >> 29) & 0x1) +#define C_SQ_TEX_WORD1_COORD_TYPE_Y 0xDFFFFFFF +#define S_SQ_TEX_WORD1_COORD_TYPE_Z(x) (((x) & 0x1) << 30) +#define G_SQ_TEX_WORD1_COORD_TYPE_Z(x) (((x) >> 30) & 0x1) +#define C_SQ_TEX_WORD1_COORD_TYPE_Z 0xBFFFFFFF +#define S_SQ_TEX_WORD1_COORD_TYPE_W(x) (((x) & 0x1) << 31) +#define G_SQ_TEX_WORD1_COORD_TYPE_W(x) (((x) >> 31) & 0x1) +#define C_SQ_TEX_WORD1_COORD_TYPE_W 0x7FFFFFFF +#define P_SQ_TEX_WORD2 +#define S_SQ_TEX_WORD2_OFFSET_X(x) (((x) & 0x1F) << 0) +#define G_SQ_TEX_WORD2_OFFSET_X(x) (((x) >> 0) & 0x1F) +#define C_SQ_TEX_WORD2_OFFSET_X 0xFFFFFFE0 +#define S_SQ_TEX_WORD2_OFFSET_Y(x) (((x) & 0x1F) << 5) +#define G_SQ_TEX_WORD2_OFFSET_Y(x) (((x) >> 5) & 0x1F) +#define C_SQ_TEX_WORD2_OFFSET_Y 0xFFFFFC1F +#define S_SQ_TEX_WORD2_OFFSET_Z(x) (((x) & 0x1F) << 10) +#define G_SQ_TEX_WORD2_OFFSET_Z(x) (((x) >> 10) & 0x1F) +#define C_SQ_TEX_WORD2_OFFSET_Z 0xFFFF83FF +#define S_SQ_TEX_WORD2_SAMPLER_ID(x) (((x) & 0x1F) << 15) +#define G_SQ_TEX_WORD2_SAMPLER_ID(x) (((x) >> 15) & 0x1F) +#define C_SQ_TEX_WORD2_SAMPLER_ID 0xFFF07FFF +#define S_SQ_TEX_WORD2_SRC_SEL_X(x) (((x) & 0x7) << 20) +#define G_SQ_TEX_WORD2_SRC_SEL_X(x) (((x) >> 20) & 0x7) +#define C_SQ_TEX_WORD2_SRC_SEL_X 0xFF8FFFFF +#define S_SQ_TEX_WORD2_SRC_SEL_Y(x) (((x) & 0x7) << 23) +#define G_SQ_TEX_WORD2_SRC_SEL_Y(x) (((x) >> 23) & 0x7) +#define C_SQ_TEX_WORD2_SRC_SEL_Y 0xFC7FFFFF +#define S_SQ_TEX_WORD2_SRC_SEL_Z(x) (((x) & 0x7) << 26) +#define G_SQ_TEX_WORD2_SRC_SEL_Z(x) (((x) >> 26) & 0x7) +#define C_SQ_TEX_WORD2_SRC_SEL_Z 0xE3FFFFFF +#define S_SQ_TEX_WORD2_SRC_SEL_W(x) (((x) & 0x7) << 29) +#define G_SQ_TEX_WORD2_SRC_SEL_W(x) (((x) >> 29) & 0x7) +#define C_SQ_TEX_WORD2_SRC_SEL_W 0x1FFFFFFF + +#define V_SQ_CF_COND_ACTIVE 0x00 +#define V_SQ_CF_COND_FALSE 0x01 +#define V_SQ_CF_COND_BOOL 0x02 +#define V_SQ_CF_COND_NOT_BOOL 0x03 + +#define V_SQ_REL_ABSOLUTE 0 +#define V_SQ_REL_RELATIVE 1 + +#define SQ_ALU_VEC_012 0x00 +#define SQ_ALU_VEC_021 0x01 +#define SQ_ALU_VEC_120 0x02 +#define SQ_ALU_VEC_102 0x03 +#define SQ_ALU_VEC_201 0x04 +#define SQ_ALU_VEC_210 0x05 + +#define SQ_ALU_SCL_210 0x00000000 +#define SQ_ALU_SCL_122 0x00000001 +#define SQ_ALU_SCL_212 0x00000002 +#define SQ_ALU_SCL_221 0x00000003 +#endif diff --git a/src/gallium/drivers/r600/r600_state.c b/src/gallium/drivers/r600/r600_state.c new file mode 100644 index 0000000..9b099df --- /dev/null +++ b/src/gallium/drivers/r600/r600_state.c @@ -0,0 +1,1479 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + */ + +/* TODO: + * - fix mask for depth control & cull for query + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "r600.h" +#include "r600d.h" +#include "r600_resource.h" +#include "r600_shader.h" +#include "r600_pipe.h" +#include "r600_state_inlines.h" + +void r600_polygon_offset_update(struct r600_pipe_context *rctx) +{ + struct r600_pipe_state state; + + state.id = R600_PIPE_STATE_POLYGON_OFFSET; + state.nregs = 0; + if (rctx->rasterizer && rctx->framebuffer.zsbuf) { + float offset_units = rctx->rasterizer->offset_units; + unsigned offset_db_fmt_cntl = 0, depth; + + switch (rctx->framebuffer.zsbuf->texture->format) { + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + depth = -24; + offset_units *= 2.0f; + break; + case PIPE_FORMAT_Z32_FLOAT: + depth = -23; + offset_units *= 1.0f; + offset_db_fmt_cntl |= S_028DF8_POLY_OFFSET_DB_IS_FLOAT_FMT(1); + break; + case PIPE_FORMAT_Z16_UNORM: + depth = -16; + offset_units *= 4.0f; + break; + default: + return; + } + /* FIXME some of those reg can be computed with cso */ + offset_db_fmt_cntl |= S_028DF8_POLY_OFFSET_NEG_NUM_DB_BITS(depth); + r600_pipe_state_add_reg(&state, + R_028E00_PA_SU_POLY_OFFSET_FRONT_SCALE, + fui(rctx->rasterizer->offset_scale), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&state, + R_028E04_PA_SU_POLY_OFFSET_FRONT_OFFSET, + fui(offset_units), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&state, + R_028E08_PA_SU_POLY_OFFSET_BACK_SCALE, + fui(rctx->rasterizer->offset_scale), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&state, + R_028E0C_PA_SU_POLY_OFFSET_BACK_OFFSET, + fui(offset_units), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&state, + R_028DF8_PA_SU_POLY_OFFSET_DB_FMT_CNTL, + offset_db_fmt_cntl, 0xFFFFFFFF, NULL); + r600_context_pipe_state_set(&rctx->ctx, &state); + } +} + +/* FIXME optimize away spi update when it's not needed */ +static void r600_spi_update(struct r600_pipe_context *rctx) +{ + struct r600_pipe_shader *shader = rctx->ps_shader; + struct r600_pipe_state rstate; + struct r600_shader *rshader = &shader->shader; + unsigned i, tmp; + + rstate.nregs = 0; + for (i = 0; i < rshader->ninput; i++) { + tmp = S_028644_SEMANTIC(r600_find_vs_semantic_index(&rctx->vs_shader->shader, rshader, i)); + if (rshader->input[i].centroid) + tmp |= S_028644_SEL_CENTROID(1); + if (rshader->input[i].interpolate == TGSI_INTERPOLATE_LINEAR) + tmp |= S_028644_SEL_LINEAR(1); + + if (rshader->input[i].name == TGSI_SEMANTIC_COLOR || + rshader->input[i].name == TGSI_SEMANTIC_BCOLOR || + rshader->input[i].name == TGSI_SEMANTIC_POSITION) { + tmp |= S_028644_FLAT_SHADE(rctx->flatshade); + } + if (rshader->input[i].name == TGSI_SEMANTIC_GENERIC && + rctx->sprite_coord_enable & (1 << rshader->input[i].sid)) { + tmp |= S_028644_PT_SPRITE_TEX(1); + } + r600_pipe_state_add_reg(&rstate, R_028644_SPI_PS_INPUT_CNTL_0 + i * 4, tmp, 0xFFFFFFFF, NULL); + } + r600_context_pipe_state_set(&rctx->ctx, &rstate); +} + +void r600_vertex_buffer_update(struct r600_pipe_context *rctx) +{ + struct r600_pipe_state *rstate; + struct r600_resource *rbuffer; + struct pipe_vertex_buffer *vertex_buffer; + unsigned i, offset; + + /* we don't update until we know vertex elements */ + if (rctx->vertex_elements == NULL || !rctx->nvertex_buffer) + return; + + if (rctx->vertex_elements->incompatible_layout) { + /* translate rebind new vertex elements so + * return once translated + */ + r600_begin_vertex_translate(rctx); + return; + } + + if (rctx->any_user_vbs) { + r600_upload_user_buffers(rctx); + rctx->any_user_vbs = FALSE; + } + + if (rctx->vertex_elements->vbuffer_need_offset) { + /* one resource per vertex elements */ + rctx->nvs_resource = rctx->vertex_elements->count; + } else { + /* bind vertex buffer once */ + rctx->nvs_resource = rctx->nvertex_buffer; + } + + for (i = 0 ; i < rctx->nvs_resource; i++) { + rstate = &rctx->vs_resource[i]; + rstate->id = R600_PIPE_STATE_RESOURCE; + rstate->nregs = 0; + + if (rctx->vertex_elements->vbuffer_need_offset) { + /* one resource per vertex elements */ + unsigned vbuffer_index; + vbuffer_index = rctx->vertex_elements->elements[i].vertex_buffer_index; + vertex_buffer = &rctx->vertex_buffer[vbuffer_index]; + rbuffer = (struct r600_resource*)vertex_buffer->buffer; + offset = rctx->vertex_elements->vbuffer_offset[i]; + } else { + /* bind vertex buffer once */ + vertex_buffer = &rctx->vertex_buffer[i]; + rbuffer = (struct r600_resource*)vertex_buffer->buffer; + offset = 0; + } + if (vertex_buffer == NULL || rbuffer == NULL) + continue; + offset += vertex_buffer->buffer_offset + r600_bo_offset(rbuffer->bo); + + r600_pipe_state_add_reg(rstate, R_038000_RESOURCE0_WORD0, + offset, 0xFFFFFFFF, rbuffer->bo); + r600_pipe_state_add_reg(rstate, R_038004_RESOURCE0_WORD1, + rbuffer->bo_size - offset - 1, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_038008_RESOURCE0_WORD2, + S_038008_STRIDE(vertex_buffer->stride), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_03800C_RESOURCE0_WORD3, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_038010_RESOURCE0_WORD4, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_038014_RESOURCE0_WORD5, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_038018_RESOURCE0_WORD6, + 0xC0000000, 0xFFFFFFFF, NULL); + r600_context_pipe_state_set_fs_resource(&rctx->ctx, rstate, i); + } +} + +static void r600_draw_common(struct r600_drawl *draw) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)draw->ctx; + struct r600_resource *rbuffer; + unsigned prim; + u32 vgt_dma_index_type, vgt_draw_initiator, mask; + struct r600_draw rdraw; + struct r600_pipe_state vgt; + + switch (draw->index_size) { + case 2: + vgt_draw_initiator = 0; + vgt_dma_index_type = 0; + break; + case 4: + vgt_draw_initiator = 0; + vgt_dma_index_type = 1; + break; + case 0: + vgt_draw_initiator = 2; + vgt_dma_index_type = 0; + break; + default: + R600_ERR("unsupported index size %d\n", draw->index_size); + return; + } + if (r600_conv_pipe_prim(draw->mode, &prim)) + return; + if (unlikely(rctx->ps_shader == NULL)) { + R600_ERR("missing vertex shader\n"); + return; + } + if (unlikely(rctx->vs_shader == NULL)) { + R600_ERR("missing vertex shader\n"); + return; + } + /* there should be enough input */ + if (rctx->vertex_elements->count < rctx->vs_shader->shader.bc.nresource) { + R600_ERR("%d resources provided, expecting %d\n", + rctx->vertex_elements->count, rctx->vs_shader->shader.bc.nresource); + return; + } + + r600_spi_update(rctx); + + mask = 0; + for (int i = 0; i < rctx->framebuffer.nr_cbufs; i++) { + mask |= (0xF << (i * 4)); + } + + vgt.id = R600_PIPE_STATE_VGT; + vgt.nregs = 0; + r600_pipe_state_add_reg(&vgt, R_008958_VGT_PRIMITIVE_TYPE, prim, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&vgt, R_028408_VGT_INDX_OFFSET, draw->index_bias, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&vgt, R_028400_VGT_MAX_VTX_INDX, draw->max_index, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&vgt, R_028404_VGT_MIN_VTX_INDX, draw->min_index, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&vgt, R_028238_CB_TARGET_MASK, rctx->cb_target_mask & mask, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&vgt, R_03CFF0_SQ_VTX_BASE_VTX_LOC, 0, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&vgt, R_03CFF4_SQ_VTX_START_INST_LOC, 0, 0xFFFFFFFF, NULL); + r600_context_pipe_state_set(&rctx->ctx, &vgt); + + rdraw.vgt_num_indices = draw->count; + rdraw.vgt_num_instances = 1; + rdraw.vgt_index_type = vgt_dma_index_type; + rdraw.vgt_draw_initiator = vgt_draw_initiator; + rdraw.indices = NULL; + if (draw->index_buffer) { + rbuffer = (struct r600_resource*)draw->index_buffer; + rdraw.indices = rbuffer->bo; + rdraw.indices_bo_offset = draw->index_buffer_offset; + } + r600_context_draw(&rctx->ctx, &rdraw); +} + +void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_drawl draw; + + memset(&draw, 0, sizeof(struct r600_drawl)); + draw.ctx = ctx; + draw.mode = info->mode; + draw.start = info->start; + draw.count = info->count; + if (info->indexed && rctx->index_buffer.buffer) { + draw.start += rctx->index_buffer.offset / rctx->index_buffer.index_size; + draw.min_index = info->min_index; + draw.max_index = info->max_index; + draw.index_bias = info->index_bias; + + r600_translate_index_buffer(rctx, &rctx->index_buffer.buffer, + &rctx->index_buffer.index_size, + &draw.start, + info->count); + + draw.index_size = rctx->index_buffer.index_size; + pipe_resource_reference(&draw.index_buffer, rctx->index_buffer.buffer); + draw.index_buffer_offset = draw.start * draw.index_size; + draw.start = 0; + r600_upload_index_buffer(rctx, &draw); + } else { + draw.index_size = 0; + draw.index_buffer = NULL; + draw.min_index = info->min_index; + draw.max_index = info->max_index; + draw.index_bias = info->start; + } + r600_draw_common(&draw); + + pipe_resource_reference(&draw.index_buffer, NULL); +} + +static void r600_set_blend_color(struct pipe_context *ctx, + const struct pipe_blend_color *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + + if (rstate == NULL) + return; + + rstate->id = R600_PIPE_STATE_BLEND_COLOR; + r600_pipe_state_add_reg(rstate, R_028414_CB_BLEND_RED, fui(state->color[0]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028418_CB_BLEND_GREEN, fui(state->color[1]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02841C_CB_BLEND_BLUE, fui(state->color[2]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028420_CB_BLEND_ALPHA, fui(state->color[3]), 0xFFFFFFFF, NULL); + free(rctx->states[R600_PIPE_STATE_BLEND_COLOR]); + rctx->states[R600_PIPE_STATE_BLEND_COLOR] = rstate; + r600_context_pipe_state_set(&rctx->ctx, rstate); +} + +static void *r600_create_blend_state(struct pipe_context *ctx, + const struct pipe_blend_state *state) +{ + struct r600_pipe_blend *blend = CALLOC_STRUCT(r600_pipe_blend); + struct r600_pipe_state *rstate; + u32 color_control, target_mask; + + if (blend == NULL) { + return NULL; + } + rstate = &blend->rstate; + + rstate->id = R600_PIPE_STATE_BLEND; + + target_mask = 0; + color_control = S_028808_PER_MRT_BLEND(1); + if (state->logicop_enable) { + color_control |= (state->logicop_func << 16) | (state->logicop_func << 20); + } else { + color_control |= (0xcc << 16); + } + /* we pretend 8 buffer are used, CB_SHADER_MASK will disable unused one */ + if (state->independent_blend_enable) { + for (int i = 0; i < 8; i++) { + if (state->rt[i].blend_enable) { + color_control |= S_028808_TARGET_BLEND_ENABLE(1 << i); + } + target_mask |= (state->rt[i].colormask << (4 * i)); + } + } else { + for (int i = 0; i < 8; i++) { + if (state->rt[0].blend_enable) { + color_control |= S_028808_TARGET_BLEND_ENABLE(1 << i); + } + target_mask |= (state->rt[0].colormask << (4 * i)); + } + } + blend->cb_target_mask = target_mask; + r600_pipe_state_add_reg(rstate, R_028808_CB_COLOR_CONTROL, + color_control, 0xFFFFFFFF, NULL); + + for (int i = 0; i < 8; i++) { + unsigned eqRGB = state->rt[i].rgb_func; + unsigned srcRGB = state->rt[i].rgb_src_factor; + unsigned dstRGB = state->rt[i].rgb_dst_factor; + + unsigned eqA = state->rt[i].alpha_func; + unsigned srcA = state->rt[i].alpha_src_factor; + unsigned dstA = state->rt[i].alpha_dst_factor; + uint32_t bc = 0; + + if (!state->rt[i].blend_enable) + continue; + + bc |= S_028804_COLOR_COMB_FCN(r600_translate_blend_function(eqRGB)); + bc |= S_028804_COLOR_SRCBLEND(r600_translate_blend_factor(srcRGB)); + bc |= S_028804_COLOR_DESTBLEND(r600_translate_blend_factor(dstRGB)); + + if (srcA != srcRGB || dstA != dstRGB || eqA != eqRGB) { + bc |= S_028804_SEPARATE_ALPHA_BLEND(1); + bc |= S_028804_ALPHA_COMB_FCN(r600_translate_blend_function(eqA)); + bc |= S_028804_ALPHA_SRCBLEND(r600_translate_blend_factor(srcA)); + bc |= S_028804_ALPHA_DESTBLEND(r600_translate_blend_factor(dstA)); + } + + r600_pipe_state_add_reg(rstate, R_028780_CB_BLEND0_CONTROL + i * 4, bc, 0xFFFFFFFF, NULL); + if (i == 0) { + r600_pipe_state_add_reg(rstate, R_028804_CB_BLEND_CONTROL, bc, 0xFFFFFFFF, NULL); + } + } + return rstate; +} + +static void *r600_create_dsa_state(struct pipe_context *ctx, + const struct pipe_depth_stencil_alpha_state *state) +{ + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + unsigned db_depth_control, alpha_test_control, alpha_ref, db_shader_control; + unsigned stencil_ref_mask, stencil_ref_mask_bf, db_render_override, db_render_control; + + if (rstate == NULL) { + return NULL; + } + + rstate->id = R600_PIPE_STATE_DSA; + /* depth TODO some of those db_shader_control field depend on shader adjust mask & add it to shader */ + /* db_shader_control is 0xFFFFFFBE as Z_EXPORT_ENABLE (bit 0) will be + * set by fragment shader if it export Z and KILL_ENABLE (bit 6) will + * be set if shader use texkill instruction + */ + db_shader_control = S_02880C_Z_ORDER(V_02880C_EARLY_Z_THEN_LATE_Z); + stencil_ref_mask = 0; + stencil_ref_mask_bf = 0; + db_depth_control = S_028800_Z_ENABLE(state->depth.enabled) | + S_028800_Z_WRITE_ENABLE(state->depth.writemask) | + S_028800_ZFUNC(state->depth.func); + + /* stencil */ + if (state->stencil[0].enabled) { + db_depth_control |= S_028800_STENCIL_ENABLE(1); + db_depth_control |= S_028800_STENCILFUNC(r600_translate_ds_func(state->stencil[0].func)); + db_depth_control |= S_028800_STENCILFAIL(r600_translate_stencil_op(state->stencil[0].fail_op)); + db_depth_control |= S_028800_STENCILZPASS(r600_translate_stencil_op(state->stencil[0].zpass_op)); + db_depth_control |= S_028800_STENCILZFAIL(r600_translate_stencil_op(state->stencil[0].zfail_op)); + + + stencil_ref_mask = S_028430_STENCILMASK(state->stencil[0].valuemask) | + S_028430_STENCILWRITEMASK(state->stencil[0].writemask); + if (state->stencil[1].enabled) { + db_depth_control |= S_028800_BACKFACE_ENABLE(1); + db_depth_control |= S_028800_STENCILFUNC_BF(r600_translate_ds_func(state->stencil[1].func)); + db_depth_control |= S_028800_STENCILFAIL_BF(r600_translate_stencil_op(state->stencil[1].fail_op)); + db_depth_control |= S_028800_STENCILZPASS_BF(r600_translate_stencil_op(state->stencil[1].zpass_op)); + db_depth_control |= S_028800_STENCILZFAIL_BF(r600_translate_stencil_op(state->stencil[1].zfail_op)); + stencil_ref_mask_bf = S_028434_STENCILMASK_BF(state->stencil[1].valuemask) | + S_028434_STENCILWRITEMASK_BF(state->stencil[1].writemask); + } + } + + /* alpha */ + alpha_test_control = 0; + alpha_ref = 0; + if (state->alpha.enabled) { + alpha_test_control = S_028410_ALPHA_FUNC(state->alpha.func); + alpha_test_control |= S_028410_ALPHA_TEST_ENABLE(1); + alpha_ref = fui(state->alpha.ref_value); + } + + /* misc */ + db_render_control = 0; + db_render_override = S_028D10_FORCE_HIZ_ENABLE(V_028D10_FORCE_DISABLE) | + S_028D10_FORCE_HIS_ENABLE0(V_028D10_FORCE_DISABLE) | + S_028D10_FORCE_HIS_ENABLE1(V_028D10_FORCE_DISABLE); + /* TODO db_render_override depends on query */ + r600_pipe_state_add_reg(rstate, R_028028_DB_STENCIL_CLEAR, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02802C_DB_DEPTH_CLEAR, 0x3F800000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028410_SX_ALPHA_TEST_CONTROL, alpha_test_control, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028430_DB_STENCILREFMASK, stencil_ref_mask, + 0xFFFFFFFF & C_028430_STENCILREF, NULL); + r600_pipe_state_add_reg(rstate, + R_028434_DB_STENCILREFMASK_BF, stencil_ref_mask_bf, + 0xFFFFFFFF & C_028434_STENCILREF_BF, NULL); + r600_pipe_state_add_reg(rstate, R_028438_SX_ALPHA_REF, alpha_ref, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0286E0_SPI_FOG_FUNC_SCALE, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0286E4_SPI_FOG_FUNC_BIAS, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0286DC_SPI_FOG_CNTL, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028800_DB_DEPTH_CONTROL, db_depth_control, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02880C_DB_SHADER_CONTROL, db_shader_control, 0xFFFFFFBE, NULL); + r600_pipe_state_add_reg(rstate, R_028D0C_DB_RENDER_CONTROL, db_render_control, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028D10_DB_RENDER_OVERRIDE, db_render_override, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028D2C_DB_SRESULTS_COMPARE_STATE1, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028D30_DB_PRELOAD_CONTROL, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028D44_DB_ALPHA_TO_MASK, 0x0000AA00, 0xFFFFFFFF, NULL); + + return rstate; +} + +static void *r600_create_rs_state(struct pipe_context *ctx, + const struct pipe_rasterizer_state *state) +{ + struct r600_pipe_rasterizer *rs = CALLOC_STRUCT(r600_pipe_rasterizer); + struct r600_pipe_state *rstate; + unsigned tmp; + unsigned prov_vtx = 1, polygon_dual_mode; + unsigned clip_rule; + + if (rs == NULL) { + return NULL; + } + + rstate = &rs->rstate; + rs->flatshade = state->flatshade; + rs->sprite_coord_enable = state->sprite_coord_enable; + + clip_rule = state->scissor ? 0xAAAA : 0xFFFF; + /* offset */ + rs->offset_units = state->offset_units; + rs->offset_scale = state->offset_scale * 12.0f; + + rstate->id = R600_PIPE_STATE_RASTERIZER; + if (state->flatshade_first) + prov_vtx = 0; + tmp = S_0286D4_FLAT_SHADE_ENA(1); + if (state->sprite_coord_enable) { + tmp |= S_0286D4_PNT_SPRITE_ENA(1) | + S_0286D4_PNT_SPRITE_OVRD_X(2) | + S_0286D4_PNT_SPRITE_OVRD_Y(3) | + S_0286D4_PNT_SPRITE_OVRD_Z(0) | + S_0286D4_PNT_SPRITE_OVRD_W(1); + if (state->sprite_coord_mode != PIPE_SPRITE_COORD_UPPER_LEFT) { + tmp |= S_0286D4_PNT_SPRITE_TOP_1(1); + } + } + r600_pipe_state_add_reg(rstate, R_0286D4_SPI_INTERP_CONTROL_0, tmp, 0xFFFFFFFF, NULL); + + polygon_dual_mode = (state->fill_front != PIPE_POLYGON_MODE_FILL || + state->fill_back != PIPE_POLYGON_MODE_FILL); + r600_pipe_state_add_reg(rstate, R_028814_PA_SU_SC_MODE_CNTL, + S_028814_PROVOKING_VTX_LAST(prov_vtx) | + S_028814_CULL_FRONT((state->cull_face & PIPE_FACE_FRONT) ? 1 : 0) | + S_028814_CULL_BACK((state->cull_face & PIPE_FACE_BACK) ? 1 : 0) | + S_028814_FACE(!state->front_ccw) | + S_028814_POLY_OFFSET_FRONT_ENABLE(state->offset_tri) | + S_028814_POLY_OFFSET_BACK_ENABLE(state->offset_tri) | + S_028814_POLY_OFFSET_PARA_ENABLE(state->offset_tri) | + S_028814_POLY_MODE(polygon_dual_mode) | + S_028814_POLYMODE_FRONT_PTYPE(r600_translate_fill(state->fill_front)) | + S_028814_POLYMODE_BACK_PTYPE(r600_translate_fill(state->fill_back)), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02881C_PA_CL_VS_OUT_CNTL, + S_02881C_USE_VTX_POINT_SIZE(state->point_size_per_vertex) | + S_02881C_VS_OUT_MISC_VEC_ENA(state->point_size_per_vertex), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028820_PA_CL_NANINF_CNTL, 0x00000000, 0xFFFFFFFF, NULL); + /* point size 12.4 fixed point */ + tmp = (unsigned)(state->point_size * 8.0); + r600_pipe_state_add_reg(rstate, R_028A00_PA_SU_POINT_SIZE, S_028A00_HEIGHT(tmp) | S_028A00_WIDTH(tmp), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A04_PA_SU_POINT_MINMAX, 0x80000000, 0xFFFFFFFF, NULL); + + tmp = (unsigned)state->line_width * 8; + r600_pipe_state_add_reg(rstate, R_028A08_PA_SU_LINE_CNTL, S_028A08_WIDTH(tmp), 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_028A0C_PA_SC_LINE_STIPPLE, 0x00000005, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A48_PA_SC_MPASS_PS_CNTL, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C00_PA_SC_LINE_CNTL, 0x00000400, 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_028C08_PA_SU_VTX_CNTL, + S_028C08_PIX_CENTER_HALF(state->gl_rasterization_rules), + 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_028C0C_PA_CL_GB_VERT_CLIP_ADJ, 0x3F800000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C10_PA_CL_GB_VERT_DISC_ADJ, 0x3F800000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C14_PA_CL_GB_HORZ_CLIP_ADJ, 0x3F800000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C18_PA_CL_GB_HORZ_DISC_ADJ, 0x3F800000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028DFC_PA_SU_POLY_OFFSET_CLAMP, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02820C_PA_SC_CLIPRECT_RULE, clip_rule, 0xFFFFFFFF, NULL); + + return rstate; +} + +static void *r600_create_sampler_state(struct pipe_context *ctx, + const struct pipe_sampler_state *state) +{ + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + union util_color uc; + + if (rstate == NULL) { + return NULL; + } + + rstate->id = R600_PIPE_STATE_SAMPLER; + util_pack_color(state->border_color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); + r600_pipe_state_add_reg(rstate, R_03C000_SQ_TEX_SAMPLER_WORD0_0, + S_03C000_CLAMP_X(r600_tex_wrap(state->wrap_s)) | + S_03C000_CLAMP_Y(r600_tex_wrap(state->wrap_t)) | + S_03C000_CLAMP_Z(r600_tex_wrap(state->wrap_r)) | + S_03C000_XY_MAG_FILTER(r600_tex_filter(state->mag_img_filter)) | + S_03C000_XY_MIN_FILTER(r600_tex_filter(state->min_img_filter)) | + S_03C000_MIP_FILTER(r600_tex_mipfilter(state->min_mip_filter)) | + S_03C000_DEPTH_COMPARE_FUNCTION(r600_tex_compare(state->compare_func)) | + S_03C000_BORDER_COLOR_TYPE(uc.ui ? V_03C000_SQ_TEX_BORDER_COLOR_REGISTER : 0), 0xFFFFFFFF, NULL); + /* FIXME LOD it depends on texture base level ... */ + r600_pipe_state_add_reg(rstate, R_03C004_SQ_TEX_SAMPLER_WORD1_0, + S_03C004_MIN_LOD(S_FIXED(CLAMP(state->min_lod, 0, 15), 6)) | + S_03C004_MAX_LOD(S_FIXED(CLAMP(state->max_lod, 0, 15), 6)) | + S_03C004_LOD_BIAS(S_FIXED(CLAMP(state->lod_bias, -16, 16), 6)), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_03C008_SQ_TEX_SAMPLER_WORD2_0, S_03C008_TYPE(1), 0xFFFFFFFF, NULL); + if (uc.ui) { + r600_pipe_state_add_reg(rstate, R_00A400_TD_PS_SAMPLER0_BORDER_RED, fui(state->border_color[0]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_00A404_TD_PS_SAMPLER0_BORDER_GREEN, fui(state->border_color[1]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_00A408_TD_PS_SAMPLER0_BORDER_BLUE, fui(state->border_color[2]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_00A40C_TD_PS_SAMPLER0_BORDER_ALPHA, fui(state->border_color[3]), 0xFFFFFFFF, NULL); + } + return rstate; +} + +static struct pipe_sampler_view *r600_create_sampler_view(struct pipe_context *ctx, + struct pipe_resource *texture, + const struct pipe_sampler_view *state) +{ + struct r600_pipe_sampler_view *resource = CALLOC_STRUCT(r600_pipe_sampler_view); + struct r600_pipe_state *rstate; + const struct util_format_description *desc; + struct r600_resource_texture *tmp; + struct r600_resource *rbuffer; + unsigned format; + uint32_t word4 = 0, yuv_format = 0, pitch = 0; + unsigned char swizzle[4], array_mode = 0, tile_type = 0; + struct r600_bo *bo[2]; + + if (resource == NULL) + return NULL; + rstate = &resource->state; + + /* initialize base object */ + resource->base = *state; + resource->base.texture = NULL; + pipe_reference(NULL, &texture->reference); + resource->base.texture = texture; + resource->base.reference.count = 1; + resource->base.context = ctx; + + swizzle[0] = state->swizzle_r; + swizzle[1] = state->swizzle_g; + swizzle[2] = state->swizzle_b; + swizzle[3] = state->swizzle_a; + format = r600_translate_texformat(state->format, + swizzle, + &word4, &yuv_format); + if (format == ~0) { + format = 0; + } + desc = util_format_description(state->format); + if (desc == NULL) { + R600_ERR("unknow format %d\n", state->format); + } + tmp = (struct r600_resource_texture*)texture; + rbuffer = &tmp->resource; + bo[0] = rbuffer->bo; + bo[1] = rbuffer->bo; + /* FIXME depth texture decompression */ + if (tmp->depth) { + r600_texture_depth_flush(ctx, texture); + tmp = (struct r600_resource_texture*)texture; + rbuffer = &tmp->flushed_depth_texture->resource; + bo[0] = rbuffer->bo; + bo[1] = rbuffer->bo; + } + pitch = align(tmp->pitch_in_pixels[0], 8); + if (tmp->tiled) { + array_mode = tmp->array_mode[0]; + tile_type = tmp->tile_type; + } + + /* FIXME properly handle first level != 0 */ + r600_pipe_state_add_reg(rstate, R_038000_RESOURCE0_WORD0, + S_038000_DIM(r600_tex_dim(texture->target)) | + S_038000_TILE_MODE(array_mode) | + S_038000_TILE_TYPE(tile_type) | + S_038000_PITCH((pitch / 8) - 1) | + S_038000_TEX_WIDTH(texture->width0 - 1), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_038004_RESOURCE0_WORD1, + S_038004_TEX_HEIGHT(texture->height0 - 1) | + S_038004_TEX_DEPTH(texture->depth0 - 1) | + S_038004_DATA_FORMAT(format), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_038008_RESOURCE0_WORD2, + (tmp->offset[0] + r600_bo_offset(bo[0])) >> 8, 0xFFFFFFFF, bo[0]); + r600_pipe_state_add_reg(rstate, R_03800C_RESOURCE0_WORD3, + (tmp->offset[1] + r600_bo_offset(bo[1])) >> 8, 0xFFFFFFFF, bo[1]); + r600_pipe_state_add_reg(rstate, R_038010_RESOURCE0_WORD4, + word4 | S_038010_NUM_FORMAT_ALL(V_038010_SQ_NUM_FORMAT_NORM) | + S_038010_SRF_MODE_ALL(V_038010_SFR_MODE_NO_ZERO) | + S_038010_REQUEST_SIZE(1) | + S_038010_BASE_LEVEL(state->u.tex.first_level), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_038014_RESOURCE0_WORD5, + S_038014_LAST_LEVEL(state->u.tex.last_level) | + S_038014_BASE_ARRAY(0) | + S_038014_LAST_ARRAY(0), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_038018_RESOURCE0_WORD6, + S_038018_TYPE(V_038010_SQ_TEX_VTX_VALID_TEXTURE), 0xFFFFFFFF, NULL); + + return &resource->base; +} + +static void r600_set_vs_sampler_view(struct pipe_context *ctx, unsigned count, + struct pipe_sampler_view **views) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_sampler_view **resource = (struct r600_pipe_sampler_view **)views; + + for (int i = 0; i < count; i++) { + if (resource[i]) { + r600_context_pipe_state_set_vs_resource(&rctx->ctx, &resource[i]->state, i); + } + } +} + +static void r600_set_ps_sampler_view(struct pipe_context *ctx, unsigned count, + struct pipe_sampler_view **views) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_sampler_view **resource = (struct r600_pipe_sampler_view **)views; + int i; + + for (i = 0; i < count; i++) { + if (&rctx->ps_samplers.views[i]->base != views[i]) { + if (resource[i]) + r600_context_pipe_state_set_ps_resource(&rctx->ctx, &resource[i]->state, i); + else + r600_context_pipe_state_set_ps_resource(&rctx->ctx, NULL, i); + + pipe_sampler_view_reference( + (struct pipe_sampler_view **)&rctx->ps_samplers.views[i], + views[i]); + + } + } + for (i = count; i < NUM_TEX_UNITS; i++) { + if (rctx->ps_samplers.views[i]) { + r600_context_pipe_state_set_ps_resource(&rctx->ctx, NULL, i); + pipe_sampler_view_reference((struct pipe_sampler_view **)&rctx->ps_samplers.views[i], NULL); + } + } + rctx->ps_samplers.n_views = count; +} + +static void r600_bind_ps_sampler(struct pipe_context *ctx, unsigned count, void **states) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state **rstates = (struct r600_pipe_state **)states; + + memcpy(rctx->ps_samplers.samplers, states, sizeof(void*) * count); + rctx->ps_samplers.n_samplers = count; + + for (int i = 0; i < count; i++) { + r600_context_pipe_state_set_ps_sampler(&rctx->ctx, rstates[i], i); + } +} + +static void r600_bind_vs_sampler(struct pipe_context *ctx, unsigned count, void **states) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state **rstates = (struct r600_pipe_state **)states; + + for (int i = 0; i < count; i++) { + r600_context_pipe_state_set_vs_sampler(&rctx->ctx, rstates[i], i); + } +} + +static void r600_set_clip_state(struct pipe_context *ctx, + const struct pipe_clip_state *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + + if (rstate == NULL) + return; + + rctx->clip = *state; + rstate->id = R600_PIPE_STATE_CLIP; + for (int i = 0; i < state->nr; i++) { + r600_pipe_state_add_reg(rstate, + R_028E20_PA_CL_UCP0_X + i * 16, + fui(state->ucp[i][0]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028E24_PA_CL_UCP0_Y + i * 16, + fui(state->ucp[i][1]) , 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028E28_PA_CL_UCP0_Z + i * 16, + fui(state->ucp[i][2]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028E2C_PA_CL_UCP0_W + i * 16, + fui(state->ucp[i][3]), 0xFFFFFFFF, NULL); + } + r600_pipe_state_add_reg(rstate, R_028810_PA_CL_CLIP_CNTL, + S_028810_PS_UCP_MODE(3) | ((1 << state->nr) - 1) | + S_028810_ZCLIP_NEAR_DISABLE(state->depth_clamp) | + S_028810_ZCLIP_FAR_DISABLE(state->depth_clamp), 0xFFFFFFFF, NULL); + + free(rctx->states[R600_PIPE_STATE_CLIP]); + rctx->states[R600_PIPE_STATE_CLIP] = rstate; + r600_context_pipe_state_set(&rctx->ctx, rstate); +} + +static void r600_set_polygon_stipple(struct pipe_context *ctx, + const struct pipe_poly_stipple *state) +{ +} + +static void r600_set_sample_mask(struct pipe_context *pipe, unsigned sample_mask) +{ +} + +static void r600_set_scissor_state(struct pipe_context *ctx, + const struct pipe_scissor_state *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + u32 tl, br; + + if (rstate == NULL) + return; + + rstate->id = R600_PIPE_STATE_SCISSOR; + tl = S_028240_TL_X(state->minx) | S_028240_TL_Y(state->miny) | S_028240_WINDOW_OFFSET_DISABLE(1); + br = S_028244_BR_X(state->maxx) | S_028244_BR_Y(state->maxy); + r600_pipe_state_add_reg(rstate, + R_028210_PA_SC_CLIPRECT_0_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028214_PA_SC_CLIPRECT_0_BR, br, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028218_PA_SC_CLIPRECT_1_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_02821C_PA_SC_CLIPRECT_1_BR, br, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028220_PA_SC_CLIPRECT_2_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028224_PA_SC_CLIPRECT_2_BR, br, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028228_PA_SC_CLIPRECT_3_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_02822C_PA_SC_CLIPRECT_3_BR, br, + 0xFFFFFFFF, NULL); + + free(rctx->states[R600_PIPE_STATE_SCISSOR]); + rctx->states[R600_PIPE_STATE_SCISSOR] = rstate; + r600_context_pipe_state_set(&rctx->ctx, rstate); +} + +static void r600_set_stencil_ref(struct pipe_context *ctx, + const struct pipe_stencil_ref *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + u32 tmp; + + if (rstate == NULL) + return; + + rctx->stencil_ref = *state; + rstate->id = R600_PIPE_STATE_STENCIL_REF; + tmp = S_028430_STENCILREF(state->ref_value[0]); + r600_pipe_state_add_reg(rstate, + R_028430_DB_STENCILREFMASK, tmp, + ~C_028430_STENCILREF, NULL); + tmp = S_028434_STENCILREF_BF(state->ref_value[1]); + r600_pipe_state_add_reg(rstate, + R_028434_DB_STENCILREFMASK_BF, tmp, + ~C_028434_STENCILREF_BF, NULL); + + free(rctx->states[R600_PIPE_STATE_STENCIL_REF]); + rctx->states[R600_PIPE_STATE_STENCIL_REF] = rstate; + r600_context_pipe_state_set(&rctx->ctx, rstate); +} + +static void r600_set_viewport_state(struct pipe_context *ctx, + const struct pipe_viewport_state *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + + if (rstate == NULL) + return; + + rctx->viewport = *state; + rstate->id = R600_PIPE_STATE_VIEWPORT; + r600_pipe_state_add_reg(rstate, R_0282D0_PA_SC_VPORT_ZMIN_0, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0282D4_PA_SC_VPORT_ZMAX_0, 0x3F800000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02843C_PA_CL_VPORT_XSCALE_0, fui(state->scale[0]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028444_PA_CL_VPORT_YSCALE_0, fui(state->scale[1]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_02844C_PA_CL_VPORT_ZSCALE_0, fui(state->scale[2]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028440_PA_CL_VPORT_XOFFSET_0, fui(state->translate[0]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028448_PA_CL_VPORT_YOFFSET_0, fui(state->translate[1]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028450_PA_CL_VPORT_ZOFFSET_0, fui(state->translate[2]), 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028818_PA_CL_VTE_CNTL, 0x0000043F, 0xFFFFFFFF, NULL); + + free(rctx->states[R600_PIPE_STATE_VIEWPORT]); + rctx->states[R600_PIPE_STATE_VIEWPORT] = rstate; + r600_context_pipe_state_set(&rctx->ctx, rstate); +} + +static void r600_cb(struct r600_pipe_context *rctx, struct r600_pipe_state *rstate, + const struct pipe_framebuffer_state *state, int cb) +{ + struct r600_resource_texture *rtex; + struct r600_resource *rbuffer; + struct r600_surface *surf; + unsigned level = state->cbufs[cb]->u.tex.level; + unsigned pitch, slice; + unsigned color_info; + unsigned format, swap, ntype; + unsigned offset; + const struct util_format_description *desc; + struct r600_bo *bo[3]; + + surf = (struct r600_surface *)state->cbufs[cb]; + rtex = (struct r600_resource_texture*)state->cbufs[cb]->texture; + rbuffer = &rtex->resource; + bo[0] = rbuffer->bo; + bo[1] = rbuffer->bo; + bo[2] = rbuffer->bo; + + /* XXX quite sure for dx10+ hw don't need any offset hacks */ + offset = r600_texture_get_offset((struct r600_resource_texture *)state->cbufs[cb]->texture, + level, state->cbufs[cb]->u.tex.first_layer); + pitch = rtex->pitch_in_pixels[level] / 8 - 1; + slice = rtex->pitch_in_pixels[level] * surf->aligned_height / 64 - 1; + ntype = 0; + desc = util_format_description(rtex->resource.base.b.format); + if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) + ntype = V_0280A0_NUMBER_SRGB; + + format = r600_translate_colorformat(rtex->resource.base.b.format); + swap = r600_translate_colorswap(rtex->resource.base.b.format); + color_info = S_0280A0_FORMAT(format) | + S_0280A0_COMP_SWAP(swap) | + S_0280A0_ARRAY_MODE(rtex->array_mode[level]) | + S_0280A0_BLEND_CLAMP(1) | + S_0280A0_NUMBER_TYPE(ntype); + if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS) + color_info |= S_0280A0_SOURCE_FORMAT(1); + + r600_pipe_state_add_reg(rstate, + R_028040_CB_COLOR0_BASE + cb * 4, + (offset + r600_bo_offset(bo[0])) >> 8, 0xFFFFFFFF, bo[0]); + r600_pipe_state_add_reg(rstate, + R_0280A0_CB_COLOR0_INFO + cb * 4, + color_info, 0xFFFFFFFF, bo[0]); + r600_pipe_state_add_reg(rstate, + R_028060_CB_COLOR0_SIZE + cb * 4, + S_028060_PITCH_TILE_MAX(pitch) | + S_028060_SLICE_TILE_MAX(slice), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028080_CB_COLOR0_VIEW + cb * 4, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_0280E0_CB_COLOR0_FRAG + cb * 4, + r600_bo_offset(bo[1]) >> 8, 0xFFFFFFFF, bo[1]); + r600_pipe_state_add_reg(rstate, + R_0280C0_CB_COLOR0_TILE + cb * 4, + r600_bo_offset(bo[2]) >> 8, 0xFFFFFFFF, bo[2]); + r600_pipe_state_add_reg(rstate, + R_028100_CB_COLOR0_MASK + cb * 4, + 0x00000000, 0xFFFFFFFF, NULL); +} + +static void r600_db(struct r600_pipe_context *rctx, struct r600_pipe_state *rstate, + const struct pipe_framebuffer_state *state) +{ + struct r600_resource_texture *rtex; + struct r600_resource *rbuffer; + struct r600_surface *surf; + unsigned level; + unsigned pitch, slice, format; + unsigned offset; + + if (state->zsbuf == NULL) + return; + + level = state->zsbuf->u.tex.level; + + surf = (struct r600_surface *)state->zsbuf; + rtex = (struct r600_resource_texture*)state->zsbuf->texture; + rtex->tiled = 1; + rtex->array_mode[level] = 2; + rtex->tile_type = 1; + rtex->depth = 1; + rbuffer = &rtex->resource; + + /* XXX quite sure for dx10+ hw don't need any offset hacks */ + offset = r600_texture_get_offset((struct r600_resource_texture *)state->zsbuf->texture, + level, state->zsbuf->u.tex.first_layer); + pitch = rtex->pitch_in_pixels[level] / 8 - 1; + slice = rtex->pitch_in_pixels[level] * surf->aligned_height / 64 - 1; + format = r600_translate_dbformat(state->zsbuf->texture->format); + + r600_pipe_state_add_reg(rstate, R_02800C_DB_DEPTH_BASE, + (offset + r600_bo_offset(rbuffer->bo)) >> 8, 0xFFFFFFFF, rbuffer->bo); + r600_pipe_state_add_reg(rstate, R_028000_DB_DEPTH_SIZE, + S_028000_PITCH_TILE_MAX(pitch) | S_028000_SLICE_TILE_MAX(slice), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028004_DB_DEPTH_VIEW, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028010_DB_DEPTH_INFO, + S_028010_ARRAY_MODE(rtex->array_mode[level]) | S_028010_FORMAT(format), + 0xFFFFFFFF, rbuffer->bo); + r600_pipe_state_add_reg(rstate, R_028D34_DB_PREFETCH_LIMIT, + (surf->aligned_height / 8) - 1, 0xFFFFFFFF, NULL); +} + +static void r600_set_framebuffer_state(struct pipe_context *ctx, + const struct pipe_framebuffer_state *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state); + u32 shader_mask, tl, br, shader_control, target_mask; + + if (rstate == NULL) + return; + + /* unreference old buffer and reference new one */ + rstate->id = R600_PIPE_STATE_FRAMEBUFFER; + + util_copy_framebuffer_state(&rctx->framebuffer, state); + + rctx->pframebuffer = &rctx->framebuffer; + + /* build states */ + for (int i = 0; i < state->nr_cbufs; i++) { + r600_cb(rctx, rstate, state, i); + } + if (state->zsbuf) { + r600_db(rctx, rstate, state); + } + + target_mask = 0x00000000; + target_mask = 0xFFFFFFFF; + shader_mask = 0; + shader_control = 0; + for (int i = 0; i < state->nr_cbufs; i++) { + target_mask ^= 0xf << (i * 4); + shader_mask |= 0xf << (i * 4); + shader_control |= 1 << i; + } + tl = S_028240_TL_X(0) | S_028240_TL_Y(0) | S_028240_WINDOW_OFFSET_DISABLE(1); + br = S_028244_BR_X(state->width) | S_028244_BR_Y(state->height); + + r600_pipe_state_add_reg(rstate, + R_028030_PA_SC_SCREEN_SCISSOR_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028034_PA_SC_SCREEN_SCISSOR_BR, br, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028204_PA_SC_WINDOW_SCISSOR_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028208_PA_SC_WINDOW_SCISSOR_BR, br, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028240_PA_SC_GENERIC_SCISSOR_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028244_PA_SC_GENERIC_SCISSOR_BR, br, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028250_PA_SC_VPORT_SCISSOR_0_TL, tl, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028254_PA_SC_VPORT_SCISSOR_0_BR, br, + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, + R_028200_PA_SC_WINDOW_OFFSET, 0x00000000, + 0xFFFFFFFF, NULL); + if (rctx->family >= CHIP_RV770) { + r600_pipe_state_add_reg(rstate, + R_028230_PA_SC_EDGERULE, 0xAAAAAAAA, + 0xFFFFFFFF, NULL); + } + + r600_pipe_state_add_reg(rstate, R_0287A0_CB_SHADER_CONTROL, + shader_control, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028238_CB_TARGET_MASK, + 0x00000000, target_mask, NULL); + r600_pipe_state_add_reg(rstate, R_02823C_CB_SHADER_MASK, + shader_mask, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C04_PA_SC_AA_CONFIG, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C1C_PA_SC_AA_SAMPLE_LOCS_MCTX, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C20_PA_SC_AA_SAMPLE_LOCS_8S_WD1_MCTX, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C30_CB_CLRCMP_CONTROL, + 0x01000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C34_CB_CLRCMP_SRC, + 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C38_CB_CLRCMP_DST, + 0x000000FF, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C3C_CB_CLRCMP_MSK, + 0xFFFFFFFF, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028C48_PA_SC_AA_MASK, + 0xFFFFFFFF, 0xFFFFFFFF, NULL); + + free(rctx->states[R600_PIPE_STATE_FRAMEBUFFER]); + rctx->states[R600_PIPE_STATE_FRAMEBUFFER] = rstate; + r600_context_pipe_state_set(&rctx->ctx, rstate); + + if (state->zsbuf) { + r600_polygon_offset_update(rctx); + } +} + +static void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index, + struct pipe_resource *buffer) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_resource *rbuffer = (struct r600_resource*)buffer; + + /* Note that the state tracker can unbind constant buffers by + * passing NULL here. + */ + if (buffer == NULL) { + return; + } + + switch (shader) { + case PIPE_SHADER_VERTEX: + rctx->vs_const_buffer.nregs = 0; + r600_pipe_state_add_reg(&rctx->vs_const_buffer, + R_028180_ALU_CONST_BUFFER_SIZE_VS_0, + ALIGN_DIVUP(buffer->width0 >> 4, 16), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&rctx->vs_const_buffer, + R_028980_ALU_CONST_CACHE_VS_0, + r600_bo_offset(rbuffer->bo) >> 8, 0xFFFFFFFF, rbuffer->bo); + r600_context_pipe_state_set(&rctx->ctx, &rctx->vs_const_buffer); + break; + case PIPE_SHADER_FRAGMENT: + rctx->ps_const_buffer.nregs = 0; + r600_pipe_state_add_reg(&rctx->ps_const_buffer, + R_028140_ALU_CONST_BUFFER_SIZE_PS_0, + ALIGN_DIVUP(buffer->width0 >> 4, 16), + 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(&rctx->ps_const_buffer, + R_028940_ALU_CONST_CACHE_PS_0, + r600_bo_offset(rbuffer->bo) >> 8, 0xFFFFFFFF, rbuffer->bo); + r600_context_pipe_state_set(&rctx->ctx, &rctx->ps_const_buffer); + break; + default: + R600_ERR("unsupported %d\n", shader); + return; + } +} + +void r600_init_state_functions(struct r600_pipe_context *rctx) +{ + rctx->context.create_blend_state = r600_create_blend_state; + rctx->context.create_depth_stencil_alpha_state = r600_create_dsa_state; + rctx->context.create_fs_state = r600_create_shader_state; + rctx->context.create_rasterizer_state = r600_create_rs_state; + rctx->context.create_sampler_state = r600_create_sampler_state; + rctx->context.create_sampler_view = r600_create_sampler_view; + rctx->context.create_vertex_elements_state = r600_create_vertex_elements; + rctx->context.create_vs_state = r600_create_shader_state; + rctx->context.bind_blend_state = r600_bind_blend_state; + rctx->context.bind_depth_stencil_alpha_state = r600_bind_state; + rctx->context.bind_fragment_sampler_states = r600_bind_ps_sampler; + rctx->context.bind_fs_state = r600_bind_ps_shader; + rctx->context.bind_rasterizer_state = r600_bind_rs_state; + rctx->context.bind_vertex_elements_state = r600_bind_vertex_elements; + rctx->context.bind_vertex_sampler_states = r600_bind_vs_sampler; + rctx->context.bind_vs_state = r600_bind_vs_shader; + rctx->context.delete_blend_state = r600_delete_state; + rctx->context.delete_depth_stencil_alpha_state = r600_delete_state; + rctx->context.delete_fs_state = r600_delete_ps_shader; + rctx->context.delete_rasterizer_state = r600_delete_rs_state; + rctx->context.delete_sampler_state = r600_delete_state; + rctx->context.delete_vertex_elements_state = r600_delete_vertex_element; + rctx->context.delete_vs_state = r600_delete_vs_shader; + rctx->context.set_blend_color = r600_set_blend_color; + rctx->context.set_clip_state = r600_set_clip_state; + rctx->context.set_constant_buffer = r600_set_constant_buffer; + rctx->context.set_fragment_sampler_views = r600_set_ps_sampler_view; + rctx->context.set_framebuffer_state = r600_set_framebuffer_state; + rctx->context.set_polygon_stipple = r600_set_polygon_stipple; + rctx->context.set_sample_mask = r600_set_sample_mask; + rctx->context.set_scissor_state = r600_set_scissor_state; + rctx->context.set_stencil_ref = r600_set_stencil_ref; + rctx->context.set_vertex_buffers = r600_set_vertex_buffers; + rctx->context.set_index_buffer = r600_set_index_buffer; + rctx->context.set_vertex_sampler_views = r600_set_vs_sampler_view; + rctx->context.set_viewport_state = r600_set_viewport_state; + rctx->context.sampler_view_destroy = r600_sampler_view_destroy; +} + +void r600_init_config(struct r600_pipe_context *rctx) +{ + int ps_prio; + int vs_prio; + int gs_prio; + int es_prio; + int num_ps_gprs; + int num_vs_gprs; + int num_gs_gprs; + int num_es_gprs; + int num_temp_gprs; + int num_ps_threads; + int num_vs_threads; + int num_gs_threads; + int num_es_threads; + int num_ps_stack_entries; + int num_vs_stack_entries; + int num_gs_stack_entries; + int num_es_stack_entries; + enum radeon_family family; + struct r600_pipe_state *rstate = &rctx->config; + u32 tmp; + + family = r600_get_family(rctx->radeon); + ps_prio = 0; + vs_prio = 1; + gs_prio = 2; + es_prio = 3; + switch (family) { + case CHIP_R600: + num_ps_gprs = 192; + num_vs_gprs = 56; + num_temp_gprs = 4; + num_gs_gprs = 0; + num_es_gprs = 0; + num_ps_threads = 136; + num_vs_threads = 48; + num_gs_threads = 4; + num_es_threads = 4; + num_ps_stack_entries = 128; + num_vs_stack_entries = 128; + num_gs_stack_entries = 0; + num_es_stack_entries = 0; + break; + case CHIP_RV630: + case CHIP_RV635: + num_ps_gprs = 84; + num_vs_gprs = 36; + num_temp_gprs = 4; + num_gs_gprs = 0; + num_es_gprs = 0; + num_ps_threads = 144; + num_vs_threads = 40; + num_gs_threads = 4; + num_es_threads = 4; + num_ps_stack_entries = 40; + num_vs_stack_entries = 40; + num_gs_stack_entries = 32; + num_es_stack_entries = 16; + break; + case CHIP_RV610: + case CHIP_RV620: + case CHIP_RS780: + case CHIP_RS880: + default: + num_ps_gprs = 84; + num_vs_gprs = 36; + num_temp_gprs = 4; + num_gs_gprs = 0; + num_es_gprs = 0; + num_ps_threads = 136; + num_vs_threads = 48; + num_gs_threads = 4; + num_es_threads = 4; + num_ps_stack_entries = 40; + num_vs_stack_entries = 40; + num_gs_stack_entries = 32; + num_es_stack_entries = 16; + break; + case CHIP_RV670: + num_ps_gprs = 144; + num_vs_gprs = 40; + num_temp_gprs = 4; + num_gs_gprs = 0; + num_es_gprs = 0; + num_ps_threads = 136; + num_vs_threads = 48; + num_gs_threads = 4; + num_es_threads = 4; + num_ps_stack_entries = 40; + num_vs_stack_entries = 40; + num_gs_stack_entries = 32; + num_es_stack_entries = 16; + break; + case CHIP_RV770: + num_ps_gprs = 192; + num_vs_gprs = 56; + num_temp_gprs = 4; + num_gs_gprs = 0; + num_es_gprs = 0; + num_ps_threads = 188; + num_vs_threads = 60; + num_gs_threads = 0; + num_es_threads = 0; + num_ps_stack_entries = 256; + num_vs_stack_entries = 256; + num_gs_stack_entries = 0; + num_es_stack_entries = 0; + break; + case CHIP_RV730: + case CHIP_RV740: + num_ps_gprs = 84; + num_vs_gprs = 36; + num_temp_gprs = 4; + num_gs_gprs = 0; + num_es_gprs = 0; + num_ps_threads = 188; + num_vs_threads = 60; + num_gs_threads = 0; + num_es_threads = 0; + num_ps_stack_entries = 128; + num_vs_stack_entries = 128; + num_gs_stack_entries = 0; + num_es_stack_entries = 0; + break; + case CHIP_RV710: + num_ps_gprs = 192; + num_vs_gprs = 56; + num_temp_gprs = 4; + num_gs_gprs = 0; + num_es_gprs = 0; + num_ps_threads = 144; + num_vs_threads = 48; + num_gs_threads = 0; + num_es_threads = 0; + num_ps_stack_entries = 128; + num_vs_stack_entries = 128; + num_gs_stack_entries = 0; + num_es_stack_entries = 0; + break; + } + + rstate->id = R600_PIPE_STATE_CONFIG; + + /* SQ_CONFIG */ + tmp = 0; + switch (family) { + case CHIP_RV610: + case CHIP_RV620: + case CHIP_RS780: + case CHIP_RS880: + case CHIP_RV710: + break; + default: + tmp |= S_008C00_VC_ENABLE(1); + break; + } + tmp |= S_008C00_DX9_CONSTS(0); + tmp |= S_008C00_ALU_INST_PREFER_VECTOR(1); + tmp |= S_008C00_PS_PRIO(ps_prio); + tmp |= S_008C00_VS_PRIO(vs_prio); + tmp |= S_008C00_GS_PRIO(gs_prio); + tmp |= S_008C00_ES_PRIO(es_prio); + r600_pipe_state_add_reg(rstate, R_008C00_SQ_CONFIG, tmp, 0xFFFFFFFF, NULL); + + /* SQ_GPR_RESOURCE_MGMT_1 */ + tmp = 0; + tmp |= S_008C04_NUM_PS_GPRS(num_ps_gprs); + tmp |= S_008C04_NUM_VS_GPRS(num_vs_gprs); + tmp |= S_008C04_NUM_CLAUSE_TEMP_GPRS(num_temp_gprs); + r600_pipe_state_add_reg(rstate, R_008C04_SQ_GPR_RESOURCE_MGMT_1, tmp, 0xFFFFFFFF, NULL); + + /* SQ_GPR_RESOURCE_MGMT_2 */ + tmp = 0; + tmp |= S_008C08_NUM_GS_GPRS(num_gs_gprs); + tmp |= S_008C08_NUM_GS_GPRS(num_es_gprs); + r600_pipe_state_add_reg(rstate, R_008C08_SQ_GPR_RESOURCE_MGMT_2, tmp, 0xFFFFFFFF, NULL); + + /* SQ_THREAD_RESOURCE_MGMT */ + tmp = 0; + tmp |= S_008C0C_NUM_PS_THREADS(num_ps_threads); + tmp |= S_008C0C_NUM_VS_THREADS(num_vs_threads); + tmp |= S_008C0C_NUM_GS_THREADS(num_gs_threads); + tmp |= S_008C0C_NUM_ES_THREADS(num_es_threads); + r600_pipe_state_add_reg(rstate, R_008C0C_SQ_THREAD_RESOURCE_MGMT, tmp, 0xFFFFFFFF, NULL); + + /* SQ_STACK_RESOURCE_MGMT_1 */ + tmp = 0; + tmp |= S_008C10_NUM_PS_STACK_ENTRIES(num_ps_stack_entries); + tmp |= S_008C10_NUM_VS_STACK_ENTRIES(num_vs_stack_entries); + r600_pipe_state_add_reg(rstate, R_008C10_SQ_STACK_RESOURCE_MGMT_1, tmp, 0xFFFFFFFF, NULL); + + /* SQ_STACK_RESOURCE_MGMT_2 */ + tmp = 0; + tmp |= S_008C14_NUM_GS_STACK_ENTRIES(num_gs_stack_entries); + tmp |= S_008C14_NUM_ES_STACK_ENTRIES(num_es_stack_entries); + r600_pipe_state_add_reg(rstate, R_008C14_SQ_STACK_RESOURCE_MGMT_2, tmp, 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_009714_VC_ENHANCE, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028350_SX_MISC, 0x00000000, 0xFFFFFFFF, NULL); + + if (family >= CHIP_RV770) { + r600_pipe_state_add_reg(rstate, R_008D8C_SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0x00004000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_009508_TA_CNTL_AUX, 0x07000002, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_009830_DB_DEBUG, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_009838_DB_WATERMARKS, 0x00420204, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0286C8_SPI_THREAD_GROUPING, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A4C_PA_SC_MODE_CNTL, 0x00514002, 0xFFFFFFFF, NULL); + } else { + r600_pipe_state_add_reg(rstate, R_008D8C_SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_009508_TA_CNTL_AUX, 0x07000003, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_009830_DB_DEBUG, 0x82000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_009838_DB_WATERMARKS, 0x01020204, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0286C8_SPI_THREAD_GROUPING, 0x00000001, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A4C_PA_SC_MODE_CNTL, 0x00004012, 0xFFFFFFFF, NULL); + } + r600_pipe_state_add_reg(rstate, R_0288A8_SQ_ESGS_RING_ITEMSIZE, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0288AC_SQ_GSVS_RING_ITEMSIZE, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0288B0_SQ_ESTMP_RING_ITEMSIZE, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0288B4_SQ_GSTMP_RING_ITEMSIZE, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0288B8_SQ_VSTMP_RING_ITEMSIZE, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0288BC_SQ_PSTMP_RING_ITEMSIZE, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0288C0_SQ_FBUF_RING_ITEMSIZE, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0288C4_SQ_REDUC_RING_ITEMSIZE, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_0288C8_SQ_GS_VERT_ITEMSIZE, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A10_VGT_OUTPUT_PATH_CNTL, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A14_VGT_HOS_CNTL, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A18_VGT_HOS_MAX_TESS_LEVEL, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A1C_VGT_HOS_MIN_TESS_LEVEL, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A20_VGT_HOS_REUSE_DEPTH, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A24_VGT_GROUP_PRIM_TYPE, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A28_VGT_GROUP_FIRST_DECR, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A2C_VGT_GROUP_DECR, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A30_VGT_GROUP_VECT_0_CNTL, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A34_VGT_GROUP_VECT_1_CNTL, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A38_VGT_GROUP_VECT_0_FMT_CNTL, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A3C_VGT_GROUP_VECT_1_FMT_CNTL, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A40_VGT_GS_MODE, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028AB0_VGT_STRMOUT_EN, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028AB4_VGT_REUSE_OFF, 0x00000001, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028AB8_VGT_VTX_CNT_EN, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028B20_VGT_STRMOUT_BUFFER_EN, 0x00000000, 0xFFFFFFFF, NULL); + + r600_pipe_state_add_reg(rstate, R_02840C_VGT_MULTI_PRIM_IB_RESET_INDX, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A84_VGT_PRIMITIVEID_EN, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028A94_VGT_MULTI_PRIM_IB_RESET_EN, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028AA0_VGT_INSTANCE_STEP_RATE_0, 0x00000000, 0xFFFFFFFF, NULL); + r600_pipe_state_add_reg(rstate, R_028AA4_VGT_INSTANCE_STEP_RATE_1, 0x00000000, 0xFFFFFFFF, NULL); + r600_context_pipe_state_set(&rctx->ctx, rstate); +} + +void *r600_create_db_flush_dsa(struct r600_pipe_context *rctx) +{ + struct pipe_depth_stencil_alpha_state dsa; + struct r600_pipe_state *rstate; + boolean quirk = false; + + if (rctx->family == CHIP_RV610 || rctx->family == CHIP_RV630 || + rctx->family == CHIP_RV620 || rctx->family == CHIP_RV635) + quirk = true; + + memset(&dsa, 0, sizeof(dsa)); + + if (quirk) { + dsa.depth.enabled = 1; + dsa.depth.func = PIPE_FUNC_LEQUAL; + dsa.stencil[0].enabled = 1; + dsa.stencil[0].func = PIPE_FUNC_ALWAYS; + dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_KEEP; + dsa.stencil[0].zfail_op = PIPE_STENCIL_OP_INCR; + dsa.stencil[0].writemask = 0xff; + } + + rstate = rctx->context.create_depth_stencil_alpha_state(&rctx->context, &dsa); + r600_pipe_state_add_reg(rstate, + R_02880C_DB_SHADER_CONTROL, + 0x0, + S_02880C_DUAL_EXPORT_ENABLE(1), NULL); + r600_pipe_state_add_reg(rstate, + R_028D0C_DB_RENDER_CONTROL, + S_028D0C_DEPTH_COPY_ENABLE(1) | + S_028D0C_STENCIL_COPY_ENABLE(1) | + S_028D0C_COPY_CENTROID(1), + S_028D0C_DEPTH_COPY_ENABLE(1) | + S_028D0C_STENCIL_COPY_ENABLE(1) | + S_028D0C_COPY_CENTROID(1), NULL); + return rstate; +} diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c new file mode 100644 index 0000000..3603376 --- /dev/null +++ b/src/gallium/drivers/r600/r600_state_common.c @@ -0,0 +1,329 @@ +/* + * Copyright 2010 Red Hat Inc. + * 2010 Jerome Glisse + * + * 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. + * + * Authors: Dave Airlie + * Jerome Glisse + */ +#include +#include +#include +#include "r600_pipe.h" + +/* common state between evergreen and r600 */ +void r600_bind_blend_state(struct pipe_context *ctx, void *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_blend *blend = (struct r600_pipe_blend *)state; + struct r600_pipe_state *rstate; + + if (state == NULL) + return; + rstate = &blend->rstate; + rctx->states[rstate->id] = rstate; + rctx->cb_target_mask = blend->cb_target_mask; + r600_context_pipe_state_set(&rctx->ctx, rstate); +} + +void r600_bind_rs_state(struct pipe_context *ctx, void *state) +{ + struct r600_pipe_rasterizer *rs = (struct r600_pipe_rasterizer *)state; + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + + if (state == NULL) + return; + + rctx->flatshade = rs->flatshade; + rctx->sprite_coord_enable = rs->sprite_coord_enable; + rctx->rasterizer = rs; + + rctx->states[rs->rstate.id] = &rs->rstate; + r600_context_pipe_state_set(&rctx->ctx, &rs->rstate); + + if (rctx->family >= CHIP_CEDAR) { + evergreen_polygon_offset_update(rctx); + } else { + r600_polygon_offset_update(rctx); + } +} + +void r600_delete_rs_state(struct pipe_context *ctx, void *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_rasterizer *rs = (struct r600_pipe_rasterizer *)state; + + if (rctx->rasterizer == rs) { + rctx->rasterizer = NULL; + } + if (rctx->states[rs->rstate.id] == &rs->rstate) { + rctx->states[rs->rstate.id] = NULL; + } + free(rs); +} + +void r600_sampler_view_destroy(struct pipe_context *ctx, + struct pipe_sampler_view *state) +{ + struct r600_pipe_sampler_view *resource = (struct r600_pipe_sampler_view *)state; + + pipe_resource_reference(&state->texture, NULL); + FREE(resource); +} + +void r600_bind_state(struct pipe_context *ctx, void *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state *rstate = (struct r600_pipe_state *)state; + + if (state == NULL) + return; + rctx->states[rstate->id] = rstate; + r600_context_pipe_state_set(&rctx->ctx, rstate); +} + +void r600_delete_state(struct pipe_context *ctx, void *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_state *rstate = (struct r600_pipe_state *)state; + + if (rctx->states[rstate->id] == rstate) { + rctx->states[rstate->id] = NULL; + } + for (int i = 0; i < rstate->nregs; i++) { + r600_bo_reference(rctx->radeon, &rstate->regs[i].bo, NULL); + } + free(rstate); +} + +void r600_bind_vertex_elements(struct pipe_context *ctx, void *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_vertex_element *v = (struct r600_vertex_element*)state; + + /* delete previous translated vertex elements */ + if (rctx->tran.new_velems) { + r600_end_vertex_translate(rctx); + } + + rctx->vertex_elements = v; + if (v) { + rctx->states[v->rstate.id] = &v->rstate; + r600_context_pipe_state_set(&rctx->ctx, &v->rstate); + if (rctx->family >= CHIP_CEDAR) { + evergreen_vertex_buffer_update(rctx); + } else { + r600_vertex_buffer_update(rctx); + } + } + + if (v) { +// rctx->vs_rebuild = TRUE; + } +} + +void r600_delete_vertex_element(struct pipe_context *ctx, void *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_vertex_element *v = (struct r600_vertex_element*)state; + + if (rctx->states[v->rstate.id] == &v->rstate) { + rctx->states[v->rstate.id] = NULL; + } + if (rctx->vertex_elements == state) + rctx->vertex_elements = NULL; + + r600_bo_reference(rctx->radeon, &v->fetch_shader, NULL); + FREE(state); +} + + +void r600_set_index_buffer(struct pipe_context *ctx, + const struct pipe_index_buffer *ib) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + + if (ib) { + pipe_resource_reference(&rctx->index_buffer.buffer, ib->buffer); + memcpy(&rctx->index_buffer, ib, sizeof(rctx->index_buffer)); + } else { + pipe_resource_reference(&rctx->index_buffer.buffer, NULL); + memset(&rctx->index_buffer, 0, sizeof(rctx->index_buffer)); + } + + /* TODO make this more like a state */ +} + +void r600_set_vertex_buffers(struct pipe_context *ctx, unsigned count, + const struct pipe_vertex_buffer *buffers) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct pipe_vertex_buffer *vbo; + unsigned max_index = (unsigned)-1; + + if (rctx->family >= CHIP_CEDAR) { + for (int i = 0; i < rctx->nvertex_buffer; i++) { + pipe_resource_reference(&rctx->vertex_buffer[i].buffer, NULL); + evergreen_context_pipe_state_set_fs_resource(&rctx->ctx, NULL, i); + } + } else { + for (int i = 0; i < rctx->nvertex_buffer; i++) { + pipe_resource_reference(&rctx->vertex_buffer[i].buffer, NULL); + r600_context_pipe_state_set_fs_resource(&rctx->ctx, NULL, i); + } + } + memcpy(rctx->vertex_buffer, buffers, sizeof(struct pipe_vertex_buffer) * count); + + for (int i = 0; i < count; i++) { + vbo = (struct pipe_vertex_buffer*)&buffers[i]; + + rctx->vertex_buffer[i].buffer = NULL; + if (buffers[i].buffer == NULL) + continue; + if (r600_buffer_is_user_buffer(buffers[i].buffer)) + rctx->any_user_vbs = TRUE; + pipe_resource_reference(&rctx->vertex_buffer[i].buffer, buffers[i].buffer); + + /* The stride of zero means we will be fetching only the first + * vertex, so don't care about max_index. */ + if (!vbo->stride) + continue; + + if (vbo->max_index == ~0) { + vbo->max_index = (vbo->buffer->width0 - vbo->buffer_offset) / vbo->stride; + } + max_index = MIN2(vbo->max_index, max_index); + } + rctx->nvertex_buffer = count; + rctx->vb_max_index = max_index; + if (rctx->family >= CHIP_CEDAR) { + evergreen_vertex_buffer_update(rctx); + } else { + r600_vertex_buffer_update(rctx); + } +} + + +#define FORMAT_REPLACE(what, withwhat) \ + case PIPE_FORMAT_##what: *format = PIPE_FORMAT_##withwhat; break + +void *r600_create_vertex_elements(struct pipe_context *ctx, + unsigned count, + const struct pipe_vertex_element *elements) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_vertex_element *v = CALLOC_STRUCT(r600_vertex_element); + enum pipe_format *format; + int i; + + assert(count < 32); + if (!v) + return NULL; + + v->count = count; + memcpy(v->elements, elements, count * sizeof(struct pipe_vertex_element)); + + for (i = 0; i < count; i++) { + v->hw_format[i] = v->elements[i].src_format; + format = &v->hw_format[i]; + + switch (*format) { + FORMAT_REPLACE(R64_FLOAT, R32_FLOAT); + FORMAT_REPLACE(R64G64_FLOAT, R32G32_FLOAT); + FORMAT_REPLACE(R64G64B64_FLOAT, R32G32B32_FLOAT); + FORMAT_REPLACE(R64G64B64A64_FLOAT, R32G32B32A32_FLOAT); + default:; + } + v->incompatible_layout = + v->incompatible_layout || + v->elements[i].src_format != v->hw_format[i]; + + v->hw_format_size[i] = align(util_format_get_blocksize(v->hw_format[i]), 4); + } + + if (r600_vertex_elements_build_fetch_shader(rctx, v)) { + FREE(v); + return NULL; + } + + return v; +} + +void *r600_create_shader_state(struct pipe_context *ctx, + const struct pipe_shader_state *state) +{ + struct r600_pipe_shader *shader = CALLOC_STRUCT(r600_pipe_shader); + int r; + + r = r600_pipe_shader_create(ctx, shader, state->tokens); + if (r) { + return NULL; + } + return shader; +} + +void r600_bind_ps_shader(struct pipe_context *ctx, void *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + + /* TODO delete old shader */ + rctx->ps_shader = (struct r600_pipe_shader *)state; + if (state) { + r600_context_pipe_state_set(&rctx->ctx, &rctx->ps_shader->rstate); + } +} + +void r600_bind_vs_shader(struct pipe_context *ctx, void *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + + /* TODO delete old shader */ + rctx->vs_shader = (struct r600_pipe_shader *)state; + if (state) { + r600_context_pipe_state_set(&rctx->ctx, &rctx->vs_shader->rstate); + } +} + +void r600_delete_ps_shader(struct pipe_context *ctx, void *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_shader *shader = (struct r600_pipe_shader *)state; + + if (rctx->ps_shader == shader) { + rctx->ps_shader = NULL; + } + + r600_pipe_shader_destroy(ctx, shader); + free(shader); +} + +void r600_delete_vs_shader(struct pipe_context *ctx, void *state) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_pipe_shader *shader = (struct r600_pipe_shader *)state; + + if (rctx->vs_shader == shader) { + rctx->vs_shader = NULL; + } + + r600_pipe_shader_destroy(ctx, shader); + free(shader); +} diff --git a/src/gallium/drivers/r600/r600_state_inlines.h b/src/gallium/drivers/r600/r600_state_inlines.h new file mode 100644 index 0000000..d994196 --- /dev/null +++ b/src/gallium/drivers/r600/r600_state_inlines.h @@ -0,0 +1,638 @@ +/* + * Copyright 2010 Red Hat 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 + * 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 R600_STATE_INLINES_H +#define R600_STATE_INLINES_H + +#include "util/u_format.h" +#include "r600d.h" +#include "r600_formats.h" + +static INLINE uint32_t r600_translate_blend_function(int blend_func) +{ + switch (blend_func) { + case PIPE_BLEND_ADD: + return V_028804_COMB_DST_PLUS_SRC; + case PIPE_BLEND_SUBTRACT: + return V_028804_COMB_SRC_MINUS_DST; + case PIPE_BLEND_REVERSE_SUBTRACT: + return V_028804_COMB_DST_MINUS_SRC; + case PIPE_BLEND_MIN: + return V_028804_COMB_MIN_DST_SRC; + case PIPE_BLEND_MAX: + return V_028804_COMB_MAX_DST_SRC; + default: + R600_ERR("Unknown blend function %d\n", blend_func); + assert(0); + break; + } + return 0; +} + +static INLINE uint32_t r600_translate_blend_factor(int blend_fact) +{ + switch (blend_fact) { + case PIPE_BLENDFACTOR_ONE: + return V_028804_BLEND_ONE; + case PIPE_BLENDFACTOR_SRC_COLOR: + return V_028804_BLEND_SRC_COLOR; + case PIPE_BLENDFACTOR_SRC_ALPHA: + return V_028804_BLEND_SRC_ALPHA; + case PIPE_BLENDFACTOR_DST_ALPHA: + return V_028804_BLEND_DST_ALPHA; + case PIPE_BLENDFACTOR_DST_COLOR: + return V_028804_BLEND_DST_COLOR; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + return V_028804_BLEND_SRC_ALPHA_SATURATE; + case PIPE_BLENDFACTOR_CONST_COLOR: + return V_028804_BLEND_CONST_COLOR; + case PIPE_BLENDFACTOR_CONST_ALPHA: + return V_028804_BLEND_CONST_ALPHA; + case PIPE_BLENDFACTOR_ZERO: + return V_028804_BLEND_ZERO; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + return V_028804_BLEND_ONE_MINUS_SRC_COLOR; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + return V_028804_BLEND_ONE_MINUS_SRC_ALPHA; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + return V_028804_BLEND_ONE_MINUS_DST_ALPHA; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + return V_028804_BLEND_ONE_MINUS_DST_COLOR; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + return V_028804_BLEND_ONE_MINUS_CONST_COLOR; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + return V_028804_BLEND_ONE_MINUS_CONST_ALPHA; + case PIPE_BLENDFACTOR_SRC1_COLOR: + return V_028804_BLEND_SRC1_COLOR; + case PIPE_BLENDFACTOR_SRC1_ALPHA: + return V_028804_BLEND_SRC1_ALPHA; + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + return V_028804_BLEND_INV_SRC1_COLOR; + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + return V_028804_BLEND_INV_SRC1_ALPHA; + default: + R600_ERR("Bad blend factor %d not supported!\n", blend_fact); + assert(0); + break; + } + return 0; +} + +static INLINE uint32_t r600_translate_stencil_op(int s_op) +{ + switch (s_op) { + case PIPE_STENCIL_OP_KEEP: + return V_028800_STENCIL_KEEP; + case PIPE_STENCIL_OP_ZERO: + return V_028800_STENCIL_ZERO; + case PIPE_STENCIL_OP_REPLACE: + return V_028800_STENCIL_REPLACE; + case PIPE_STENCIL_OP_INCR: + return V_028800_STENCIL_INCR; + case PIPE_STENCIL_OP_DECR: + return V_028800_STENCIL_DECR; + case PIPE_STENCIL_OP_INCR_WRAP: + return V_028800_STENCIL_INCR_WRAP; + case PIPE_STENCIL_OP_DECR_WRAP: + return V_028800_STENCIL_DECR_WRAP; + case PIPE_STENCIL_OP_INVERT: + return V_028800_STENCIL_INVERT; + default: + R600_ERR("Unknown stencil op %d", s_op); + assert(0); + break; + } + return 0; +} + +static INLINE uint32_t r600_translate_fill(uint32_t func) +{ + switch(func) { + case PIPE_POLYGON_MODE_FILL: + return 2; + case PIPE_POLYGON_MODE_LINE: + return 1; + case PIPE_POLYGON_MODE_POINT: + return 0; + default: + assert(0); + return 0; + } +} + +/* translates straight */ +static INLINE uint32_t r600_translate_ds_func(int func) +{ + return func; +} + +static inline unsigned r600_tex_wrap(unsigned wrap) +{ + switch (wrap) { + default: + case PIPE_TEX_WRAP_REPEAT: + return V_03C000_SQ_TEX_WRAP; + case PIPE_TEX_WRAP_CLAMP: + return V_03C000_SQ_TEX_CLAMP_HALF_BORDER; + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return V_03C000_SQ_TEX_CLAMP_LAST_TEXEL; + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + return V_03C000_SQ_TEX_CLAMP_BORDER; + case PIPE_TEX_WRAP_MIRROR_REPEAT: + return V_03C000_SQ_TEX_MIRROR; + case PIPE_TEX_WRAP_MIRROR_CLAMP: + return V_03C000_SQ_TEX_MIRROR_ONCE_HALF_BORDER; + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + return V_03C000_SQ_TEX_MIRROR_ONCE_LAST_TEXEL; + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + return V_03C000_SQ_TEX_MIRROR_ONCE_BORDER; + } +} + +static inline unsigned r600_tex_filter(unsigned filter) +{ + switch (filter) { + default: + case PIPE_TEX_FILTER_NEAREST: + return V_03C000_SQ_TEX_XY_FILTER_POINT; + case PIPE_TEX_FILTER_LINEAR: + return V_03C000_SQ_TEX_XY_FILTER_BILINEAR; + } +} + +static inline unsigned r600_tex_mipfilter(unsigned filter) +{ + switch (filter) { + case PIPE_TEX_MIPFILTER_NEAREST: + return V_03C000_SQ_TEX_Z_FILTER_POINT; + case PIPE_TEX_MIPFILTER_LINEAR: + return V_03C000_SQ_TEX_Z_FILTER_LINEAR; + default: + case PIPE_TEX_MIPFILTER_NONE: + return V_03C000_SQ_TEX_Z_FILTER_NONE; + } +} + +static inline unsigned r600_tex_compare(unsigned compare) +{ + switch (compare) { + default: + case PIPE_FUNC_NEVER: + return V_03C000_SQ_TEX_DEPTH_COMPARE_NEVER; + case PIPE_FUNC_LESS: + return V_03C000_SQ_TEX_DEPTH_COMPARE_LESS; + case PIPE_FUNC_EQUAL: + return V_03C000_SQ_TEX_DEPTH_COMPARE_EQUAL; + case PIPE_FUNC_LEQUAL: + return V_03C000_SQ_TEX_DEPTH_COMPARE_LESSEQUAL; + case PIPE_FUNC_GREATER: + return V_03C000_SQ_TEX_DEPTH_COMPARE_GREATER; + case PIPE_FUNC_NOTEQUAL: + return V_03C000_SQ_TEX_DEPTH_COMPARE_NOTEQUAL; + case PIPE_FUNC_GEQUAL: + return V_03C000_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL; + case PIPE_FUNC_ALWAYS: + return V_03C000_SQ_TEX_DEPTH_COMPARE_ALWAYS; + } +} + +static inline unsigned r600_tex_swizzle(unsigned swizzle) +{ + switch (swizzle) { + case PIPE_SWIZZLE_RED: + return V_038010_SQ_SEL_X; + case PIPE_SWIZZLE_GREEN: + return V_038010_SQ_SEL_Y; + case PIPE_SWIZZLE_BLUE: + return V_038010_SQ_SEL_Z; + case PIPE_SWIZZLE_ALPHA: + return V_038010_SQ_SEL_W; + case PIPE_SWIZZLE_ZERO: + return V_038010_SQ_SEL_0; + default: + case PIPE_SWIZZLE_ONE: + return V_038010_SQ_SEL_1; + } +} + +static inline unsigned r600_format_type(unsigned format_type) +{ + switch (format_type) { + default: + case UTIL_FORMAT_TYPE_UNSIGNED: + return V_038010_SQ_FORMAT_COMP_UNSIGNED; + case UTIL_FORMAT_TYPE_SIGNED: + return V_038010_SQ_FORMAT_COMP_SIGNED; + case UTIL_FORMAT_TYPE_FIXED: + return V_038010_SQ_FORMAT_COMP_UNSIGNED_BIASED; + } +} + +static inline unsigned r600_tex_dim(unsigned dim) +{ + switch (dim) { + default: + case PIPE_TEXTURE_1D: + return V_038000_SQ_TEX_DIM_1D; + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + return V_038000_SQ_TEX_DIM_2D; + case PIPE_TEXTURE_3D: + return V_038000_SQ_TEX_DIM_3D; + case PIPE_TEXTURE_CUBE: + return V_038000_SQ_TEX_DIM_CUBEMAP; + } +} + +static inline uint32_t r600_translate_dbformat(enum pipe_format format) +{ + switch (format) { + case PIPE_FORMAT_Z16_UNORM: + return V_028010_DEPTH_16; + case PIPE_FORMAT_Z24X8_UNORM: + return V_028010_DEPTH_X8_24; + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + return V_028010_DEPTH_8_24; + default: + return ~0; + } +} + +static inline uint32_t r600_translate_colorswap(enum pipe_format format) +{ + switch (format) { + /* 8-bit buffers. */ + case PIPE_FORMAT_A8_UNORM: + return V_0280A0_SWAP_ALT_REV; + case PIPE_FORMAT_I8_UNORM: + case PIPE_FORMAT_L8_UNORM: + case PIPE_FORMAT_R8_UNORM: + case PIPE_FORMAT_R8_SNORM: + return V_0280A0_SWAP_STD; + + /* 16-bit buffers. */ + case PIPE_FORMAT_B5G6R5_UNORM: + return V_0280A0_SWAP_STD_REV; + + case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B5G5R5X1_UNORM: + return V_0280A0_SWAP_ALT; + + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B4G4R4X4_UNORM: + return V_0280A0_SWAP_ALT; + + case PIPE_FORMAT_Z16_UNORM: + return V_0280A0_SWAP_STD; + + case PIPE_FORMAT_L8A8_UNORM: + return V_0280A0_SWAP_ALT; + case PIPE_FORMAT_R8G8_UNORM: + return V_0280A0_SWAP_STD; + + case PIPE_FORMAT_R16_UNORM: + return V_0280A0_SWAP_STD; + + /* 32-bit buffers. */ + + case PIPE_FORMAT_A8B8G8R8_SRGB: + return V_0280A0_SWAP_STD_REV; + case PIPE_FORMAT_B8G8R8A8_SRGB: + return V_0280A0_SWAP_ALT; + + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + return V_0280A0_SWAP_ALT; + + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_X8R8G8B8_UNORM: + return V_0280A0_SWAP_ALT_REV; + case PIPE_FORMAT_R8G8B8A8_SNORM: + case PIPE_FORMAT_R8G8B8X8_UNORM: + return V_0280A0_SWAP_STD; + + case PIPE_FORMAT_A8B8G8R8_UNORM: + case PIPE_FORMAT_X8B8G8R8_UNORM: + // case PIPE_FORMAT_R8SG8SB8UX8U_NORM: + return V_0280A0_SWAP_STD_REV; + + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + return V_0280A0_SWAP_STD; + + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + return V_0280A0_SWAP_STD; + + case PIPE_FORMAT_R10G10B10A2_UNORM: + case PIPE_FORMAT_R10G10B10X2_SNORM: + case PIPE_FORMAT_B10G10R10A2_UNORM: + case PIPE_FORMAT_R10SG10SB10SA2U_NORM: + return V_0280A0_SWAP_STD_REV; + + case PIPE_FORMAT_R16G16_UNORM: + return V_0280A0_SWAP_STD; + + /* 64-bit buffers. */ + case PIPE_FORMAT_R16G16B16A16_UNORM: + case PIPE_FORMAT_R16G16B16A16_SNORM: + // return FMT_16_16_16_16; + case PIPE_FORMAT_R16G16B16A16_FLOAT: + // return FMT_16_16_16_16_FLOAT; + + /* 128-bit buffers. */ + case PIPE_FORMAT_R32G32B32A32_FLOAT: + // return FMT_32_32_32_32_FLOAT; + return 0; + default: + R600_ERR("unsupported colorswap format %d\n", format); + return ~0; + } + return ~0; +} + +static INLINE uint32_t r600_translate_colorformat(enum pipe_format format) +{ + switch (format) { + /* 8-bit buffers. */ + case PIPE_FORMAT_A8_UNORM: + case PIPE_FORMAT_I8_UNORM: + case PIPE_FORMAT_L8_UNORM: + case PIPE_FORMAT_R8_UNORM: + case PIPE_FORMAT_R8_SNORM: + return V_0280A0_COLOR_8; + + /* 16-bit buffers. */ + case PIPE_FORMAT_B5G6R5_UNORM: + return V_0280A0_COLOR_5_6_5; + + case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B5G5R5X1_UNORM: + return V_0280A0_COLOR_1_5_5_5; + + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B4G4R4X4_UNORM: + return V_0280A0_COLOR_4_4_4_4; + + case PIPE_FORMAT_Z16_UNORM: + return V_0280A0_COLOR_16; + + case PIPE_FORMAT_L8A8_UNORM: + case PIPE_FORMAT_R8G8_UNORM: + return V_0280A0_COLOR_8_8; + + case PIPE_FORMAT_R16_UNORM: + return V_0280A0_COLOR_16; + + /* 32-bit buffers. */ + case PIPE_FORMAT_A8B8G8R8_SRGB: + case PIPE_FORMAT_A8B8G8R8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_SRGB: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_R8G8B8A8_SNORM: + case PIPE_FORMAT_R8G8B8A8_UNORM: + case PIPE_FORMAT_R8G8B8X8_UNORM: + case PIPE_FORMAT_R8SG8SB8UX8U_NORM: + case PIPE_FORMAT_X8B8G8R8_UNORM: + case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_R8G8B8_UNORM: + return V_0280A0_COLOR_8_8_8_8; + + case PIPE_FORMAT_R10G10B10A2_UNORM: + case PIPE_FORMAT_R10G10B10X2_SNORM: + case PIPE_FORMAT_B10G10R10A2_UNORM: + case PIPE_FORMAT_R10SG10SB10SA2U_NORM: + return V_0280A0_COLOR_10_10_10_2; + + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + return V_0280A0_COLOR_8_24; + + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + return V_0280A0_COLOR_24_8; + + case PIPE_FORMAT_R32_FLOAT: + return V_0280A0_COLOR_32_FLOAT; + + case PIPE_FORMAT_R16G16_FLOAT: + return V_0280A0_COLOR_16_16_FLOAT; + + case PIPE_FORMAT_R16G16_SSCALED: + case PIPE_FORMAT_R16G16_UNORM: + return V_0280A0_COLOR_16_16; + + + /* 64-bit buffers. */ + case PIPE_FORMAT_R16G16B16_USCALED: + case PIPE_FORMAT_R16G16B16A16_USCALED: + case PIPE_FORMAT_R16G16B16_SSCALED: + case PIPE_FORMAT_R16G16B16A16_SSCALED: + case PIPE_FORMAT_R16G16B16A16_UNORM: + case PIPE_FORMAT_R16G16B16A16_SNORM: + return V_0280A0_COLOR_16_16_16_16; + + case PIPE_FORMAT_R16G16B16_FLOAT: + case PIPE_FORMAT_R16G16B16A16_FLOAT: + return V_0280A0_COLOR_16_16_16_16_FLOAT; + + case PIPE_FORMAT_R32G32_FLOAT: + return V_0280A0_COLOR_32_32_FLOAT; + + case PIPE_FORMAT_R32G32_USCALED: + case PIPE_FORMAT_R32G32_SSCALED: + return V_0280A0_COLOR_32_32; + + /* 128-bit buffers. */ + case PIPE_FORMAT_R32G32B32_FLOAT: + return V_0280A0_COLOR_32_32_32_FLOAT; + case PIPE_FORMAT_R32G32B32A32_FLOAT: + return V_0280A0_COLOR_32_32_32_32_FLOAT; + + /* YUV buffers. */ + case PIPE_FORMAT_UYVY: + case PIPE_FORMAT_YUYV: + default: + //R600_ERR("unsupported color format %d %s\n", format, util_format_name(format)); + return ~0; /* Unsupported. */ + } +} + +static INLINE boolean r600_is_sampler_format_supported(enum pipe_format format) +{ + return r600_translate_texformat(format, NULL, NULL, NULL) != ~0; +} + +static INLINE boolean r600_is_colorbuffer_format_supported(enum pipe_format format) +{ + return r600_translate_colorformat(format) != ~0 && + r600_translate_colorswap(format) != ~0; +} + +static INLINE boolean r600_is_zs_format_supported(enum pipe_format format) +{ + return r600_translate_dbformat(format) != ~0; +} + +static INLINE boolean r600_is_vertex_format_supported(enum pipe_format format) +{ + return r600_translate_colorformat(format) != ~0; +} + +static INLINE uint32_t r600_translate_vertex_data_type(enum pipe_format format) +{ + uint32_t result = 0; + const struct util_format_description *desc; + unsigned i; + + desc = util_format_description(format); + if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { + goto out_unknown; + } + + /* Find the first non-VOID channel. */ + for (i = 0; i < 4; i++) { + if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { + break; + } + } + + switch (desc->channel[i].type) { + /* Half-floats, floats, doubles */ + case UTIL_FORMAT_TYPE_FLOAT: + switch (desc->channel[i].size) { + case 16: + switch (desc->nr_channels) { + case 1: + result = FMT_16_FLOAT; + break; + case 2: + result = FMT_16_16_FLOAT; + break; + case 3: + result = FMT_16_16_16_FLOAT; + break; + case 4: + result = FMT_16_16_16_16_FLOAT; + break; + } + break; + case 32: + switch (desc->nr_channels) { + case 1: + result = FMT_32_FLOAT; + break; + case 2: + result = FMT_32_32_FLOAT; + break; + case 3: + result = FMT_32_32_32_FLOAT; + break; + case 4: + result = FMT_32_32_32_32_FLOAT; + break; + } + break; + default: + goto out_unknown; + } + break; + /* Unsigned ints */ + case UTIL_FORMAT_TYPE_UNSIGNED: + /* Signed ints */ + case UTIL_FORMAT_TYPE_SIGNED: + switch (desc->channel[i].size) { + case 8: + switch (desc->nr_channels) { + case 1: + result = FMT_8; + break; + case 2: + result = FMT_8_8; + break; + case 3: + // result = FMT_8_8_8; /* fails piglit draw-vertices test */ + // break; + case 4: + result = FMT_8_8_8_8; + break; + } + break; + case 16: + switch (desc->nr_channels) { + case 1: + result = FMT_16; + break; + case 2: + result = FMT_16_16; + break; + case 3: + // result = FMT_16_16_16; /* fails piglit draw-vertices test */ + // break; + case 4: + result = FMT_16_16_16_16; + break; + } + break; + case 32: + switch (desc->nr_channels) { + case 1: + result = FMT_32; + break; + case 2: + result = FMT_32_32; + break; + case 3: + result = FMT_32_32_32; + break; + case 4: + result = FMT_32_32_32_32; + break; + } + break; + default: + goto out_unknown; + } + break; + default: + goto out_unknown; + } + + result = S_038008_DATA_FORMAT(result); + + if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) { + result |= S_038008_FORMAT_COMP_ALL(1); + } + if (desc->channel[i].normalized) { + result |= S_038008_NUM_FORMAT_ALL(0); + } else { + result |= S_038008_NUM_FORMAT_ALL(2); + } + return result; +out_unknown: + R600_ERR("unsupported vertex format %s\n", util_format_name(format)); + return ~0; +} + +#endif diff --git a/src/gallium/drivers/r600/r600_states_inc.h b/src/gallium/drivers/r600/r600_states_inc.h new file mode 100644 index 0000000..1c8075e --- /dev/null +++ b/src/gallium/drivers/r600/r600_states_inc.h @@ -0,0 +1,543 @@ +/* This file is autogenerated from r600_states.h - do not edit directly */ +/* autogenerating script is gen_r600_states.py */ + +/* R600_CONFIG */ +#define R600_CONFIG__SQ_CONFIG 0 +#define R600_CONFIG__SQ_GPR_RESOURCE_MGMT_1 1 +#define R600_CONFIG__SQ_GPR_RESOURCE_MGMT_2 2 +#define R600_CONFIG__SQ_THREAD_RESOURCE_MGMT 3 +#define R600_CONFIG__SQ_STACK_RESOURCE_MGMT_1 4 +#define R600_CONFIG__SQ_STACK_RESOURCE_MGMT_2 5 +#define R600_CONFIG__SQ_DYN_GPR_CNTL_PS_FLUSH_REQ 6 +#define R600_CONFIG__TA_CNTL_AUX 7 +#define R600_CONFIG__VC_ENHANCE 8 +#define R600_CONFIG__DB_DEBUG 9 +#define R600_CONFIG__DB_WATERMARKS 10 +#define R600_CONFIG__SX_MISC 11 +#define R600_CONFIG__SPI_THREAD_GROUPING 12 +#define R600_CONFIG__SQ_ESGS_RING_ITEMSIZE 13 +#define R600_CONFIG__SQ_GSVS_RING_ITEMSIZE 14 +#define R600_CONFIG__SQ_ESTMP_RING_ITEMSIZE 15 +#define R600_CONFIG__SQ_GSTMP_RING_ITEMSIZE 16 +#define R600_CONFIG__SQ_VSTMP_RING_ITEMSIZE 17 +#define R600_CONFIG__SQ_PSTMP_RING_ITEMSIZE 18 +#define R600_CONFIG__SQ_FBUF_RING_ITEMSIZE 19 +#define R600_CONFIG__SQ_REDUC_RING_ITEMSIZE 20 +#define R600_CONFIG__SQ_GS_VERT_ITEMSIZE 21 +#define R600_CONFIG__VGT_OUTPUT_PATH_CNTL 22 +#define R600_CONFIG__VGT_HOS_CNTL 23 +#define R600_CONFIG__VGT_HOS_MAX_TESS_LEVEL 24 +#define R600_CONFIG__VGT_HOS_MIN_TESS_LEVEL 25 +#define R600_CONFIG__VGT_HOS_REUSE_DEPTH 26 +#define R600_CONFIG__VGT_GROUP_PRIM_TYPE 27 +#define R600_CONFIG__VGT_GROUP_FIRST_DECR 28 +#define R600_CONFIG__VGT_GROUP_DECR 29 +#define R600_CONFIG__VGT_GROUP_VECT_0_CNTL 30 +#define R600_CONFIG__VGT_GROUP_VECT_1_CNTL 31 +#define R600_CONFIG__VGT_GROUP_VECT_0_FMT_CNTL 32 +#define R600_CONFIG__VGT_GROUP_VECT_1_FMT_CNTL 33 +#define R600_CONFIG__VGT_GS_MODE 34 +#define R600_CONFIG__PA_SC_MODE_CNTL 35 +#define R600_CONFIG__VGT_STRMOUT_EN 36 +#define R600_CONFIG__VGT_REUSE_OFF 37 +#define R600_CONFIG__VGT_VTX_CNT_EN 38 +#define R600_CONFIG__VGT_STRMOUT_BUFFER_EN 39 +#define R600_CONFIG_SIZE 40 +#define R600_CONFIG_PM4 128 + +/* R600_CB_CNTL */ +#define R600_CB_CNTL__CB_CLEAR_RED 0 +#define R600_CB_CNTL__CB_CLEAR_GREEN 1 +#define R600_CB_CNTL__CB_CLEAR_BLUE 2 +#define R600_CB_CNTL__CB_CLEAR_ALPHA 3 +#define R600_CB_CNTL__CB_SHADER_MASK 4 +#define R600_CB_CNTL__CB_TARGET_MASK 5 +#define R600_CB_CNTL__CB_FOG_RED 6 +#define R600_CB_CNTL__CB_FOG_GREEN 7 +#define R600_CB_CNTL__CB_FOG_BLUE 8 +#define R600_CB_CNTL__CB_COLOR_CONTROL 9 +#define R600_CB_CNTL__PA_SC_AA_CONFIG 10 +#define R600_CB_CNTL__PA_SC_AA_SAMPLE_LOCS_MCTX 11 +#define R600_CB_CNTL__PA_SC_AA_SAMPLE_LOCS_8S_WD1_MCTX 12 +#define R600_CB_CNTL__CB_CLRCMP_CONTROL 13 +#define R600_CB_CNTL__CB_CLRCMP_SRC 14 +#define R600_CB_CNTL__CB_CLRCMP_DST 15 +#define R600_CB_CNTL__CB_CLRCMP_MSK 16 +#define R600_CB_CNTL__PA_SC_AA_MASK 17 +#define R600_CB_CNTL__CB_SHADER_CONTROL 18 +#define R600_CB_CNTL_SIZE 19 +#define R600_CB_CNTL_PM4 128 + +/* R600_RASTERIZER */ +#define R600_RASTERIZER__SPI_INTERP_CONTROL_0 0 +#define R600_RASTERIZER__PA_CL_CLIP_CNTL 1 +#define R600_RASTERIZER__PA_SU_SC_MODE_CNTL 2 +#define R600_RASTERIZER__PA_CL_VS_OUT_CNTL 3 +#define R600_RASTERIZER__PA_CL_NANINF_CNTL 4 +#define R600_RASTERIZER__PA_SU_POINT_SIZE 5 +#define R600_RASTERIZER__PA_SU_POINT_MINMAX 6 +#define R600_RASTERIZER__PA_SU_LINE_CNTL 7 +#define R600_RASTERIZER__PA_SC_LINE_STIPPLE 8 +#define R600_RASTERIZER__PA_SC_MPASS_PS_CNTL 9 +#define R600_RASTERIZER__PA_SC_LINE_CNTL 10 +#define R600_RASTERIZER__PA_CL_GB_VERT_CLIP_ADJ 11 +#define R600_RASTERIZER__PA_CL_GB_VERT_DISC_ADJ 12 +#define R600_RASTERIZER__PA_CL_GB_HORZ_CLIP_ADJ 13 +#define R600_RASTERIZER__PA_CL_GB_HORZ_DISC_ADJ 14 +#define R600_RASTERIZER__PA_SU_POLY_OFFSET_DB_FMT_CNTL 15 +#define R600_RASTERIZER__PA_SU_POLY_OFFSET_CLAMP 16 +#define R600_RASTERIZER__PA_SU_POLY_OFFSET_FRONT_SCALE 17 +#define R600_RASTERIZER__PA_SU_POLY_OFFSET_FRONT_OFFSET 18 +#define R600_RASTERIZER__PA_SU_POLY_OFFSET_BACK_SCALE 19 +#define R600_RASTERIZER__PA_SU_POLY_OFFSET_BACK_OFFSET 20 +#define R600_RASTERIZER_SIZE 21 +#define R600_RASTERIZER_PM4 128 + +/* R600_VIEWPORT */ +#define R600_VIEWPORT__PA_SC_VPORT_ZMIN_0 0 +#define R600_VIEWPORT__PA_SC_VPORT_ZMAX_0 1 +#define R600_VIEWPORT__PA_CL_VPORT_XSCALE_0 2 +#define R600_VIEWPORT__PA_CL_VPORT_YSCALE_0 3 +#define R600_VIEWPORT__PA_CL_VPORT_ZSCALE_0 4 +#define R600_VIEWPORT__PA_CL_VPORT_XOFFSET_0 5 +#define R600_VIEWPORT__PA_CL_VPORT_YOFFSET_0 6 +#define R600_VIEWPORT__PA_CL_VPORT_ZOFFSET_0 7 +#define R600_VIEWPORT__PA_CL_VTE_CNTL 8 +#define R600_VIEWPORT_SIZE 9 +#define R600_VIEWPORT_PM4 128 + +/* R600_SCISSOR */ +#define R600_SCISSOR__PA_SC_SCREEN_SCISSOR_TL 0 +#define R600_SCISSOR__PA_SC_SCREEN_SCISSOR_BR 1 +#define R600_SCISSOR__PA_SC_WINDOW_OFFSET 2 +#define R600_SCISSOR__PA_SC_WINDOW_SCISSOR_TL 3 +#define R600_SCISSOR__PA_SC_WINDOW_SCISSOR_BR 4 +#define R600_SCISSOR__PA_SC_CLIPRECT_RULE 5 +#define R600_SCISSOR__PA_SC_CLIPRECT_0_TL 6 +#define R600_SCISSOR__PA_SC_CLIPRECT_0_BR 7 +#define R600_SCISSOR__PA_SC_CLIPRECT_1_TL 8 +#define R600_SCISSOR__PA_SC_CLIPRECT_1_BR 9 +#define R600_SCISSOR__PA_SC_CLIPRECT_2_TL 10 +#define R600_SCISSOR__PA_SC_CLIPRECT_2_BR 11 +#define R600_SCISSOR__PA_SC_CLIPRECT_3_TL 12 +#define R600_SCISSOR__PA_SC_CLIPRECT_3_BR 13 +#define R600_SCISSOR__PA_SC_EDGERULE 14 +#define R600_SCISSOR__PA_SC_GENERIC_SCISSOR_TL 15 +#define R600_SCISSOR__PA_SC_GENERIC_SCISSOR_BR 16 +#define R600_SCISSOR__PA_SC_VPORT_SCISSOR_0_TL 17 +#define R600_SCISSOR__PA_SC_VPORT_SCISSOR_0_BR 18 +#define R600_SCISSOR_SIZE 19 +#define R600_SCISSOR_PM4 128 + +/* R600_BLEND */ +#define R600_BLEND__CB_BLEND_RED 0 +#define R600_BLEND__CB_BLEND_GREEN 1 +#define R600_BLEND__CB_BLEND_BLUE 2 +#define R600_BLEND__CB_BLEND_ALPHA 3 +#define R600_BLEND__CB_BLEND0_CONTROL 4 +#define R600_BLEND__CB_BLEND1_CONTROL 5 +#define R600_BLEND__CB_BLEND2_CONTROL 6 +#define R600_BLEND__CB_BLEND3_CONTROL 7 +#define R600_BLEND__CB_BLEND4_CONTROL 8 +#define R600_BLEND__CB_BLEND5_CONTROL 9 +#define R600_BLEND__CB_BLEND6_CONTROL 10 +#define R600_BLEND__CB_BLEND7_CONTROL 11 +#define R600_BLEND__CB_BLEND_CONTROL 12 +#define R600_BLEND_SIZE 13 +#define R600_BLEND_PM4 128 + +/* R600_DSA */ +#define R600_DSA__DB_STENCIL_CLEAR 0 +#define R600_DSA__DB_DEPTH_CLEAR 1 +#define R600_DSA__SX_ALPHA_TEST_CONTROL 2 +#define R600_DSA__DB_STENCILREFMASK 3 +#define R600_DSA__DB_STENCILREFMASK_BF 4 +#define R600_DSA__SX_ALPHA_REF 5 +#define R600_DSA__SPI_FOG_FUNC_SCALE 6 +#define R600_DSA__SPI_FOG_FUNC_BIAS 7 +#define R600_DSA__SPI_FOG_CNTL 8 +#define R600_DSA__DB_DEPTH_CONTROL 9 +#define R600_DSA__DB_SHADER_CONTROL 10 +#define R600_DSA__DB_RENDER_CONTROL 11 +#define R600_DSA__DB_RENDER_OVERRIDE 12 +#define R600_DSA__DB_SRESULTS_COMPARE_STATE1 13 +#define R600_DSA__DB_PRELOAD_CONTROL 14 +#define R600_DSA__DB_ALPHA_TO_MASK 15 +#define R600_DSA_SIZE 16 +#define R600_DSA_PM4 128 + +/* R600_VS_SHADER */ +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_0 0 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_1 1 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_2 2 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_3 3 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_4 4 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_5 5 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_6 6 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_7 7 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_8 8 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_9 9 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_10 10 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_11 11 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_12 12 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_13 13 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_14 14 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_15 15 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_16 16 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_17 17 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_18 18 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_19 19 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_20 20 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_21 21 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_22 22 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_23 23 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_24 24 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_25 25 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_26 26 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_27 27 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_28 28 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_29 29 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_30 30 +#define R600_VS_SHADER__SQ_VTX_SEMANTIC_31 31 +#define R600_VS_SHADER__SPI_VS_OUT_ID_0 32 +#define R600_VS_SHADER__SPI_VS_OUT_ID_1 33 +#define R600_VS_SHADER__SPI_VS_OUT_ID_2 34 +#define R600_VS_SHADER__SPI_VS_OUT_ID_3 35 +#define R600_VS_SHADER__SPI_VS_OUT_ID_4 36 +#define R600_VS_SHADER__SPI_VS_OUT_ID_5 37 +#define R600_VS_SHADER__SPI_VS_OUT_ID_6 38 +#define R600_VS_SHADER__SPI_VS_OUT_ID_7 39 +#define R600_VS_SHADER__SPI_VS_OUT_ID_8 40 +#define R600_VS_SHADER__SPI_VS_OUT_ID_9 41 +#define R600_VS_SHADER__SPI_VS_OUT_CONFIG 42 +#define R600_VS_SHADER__SQ_PGM_START_VS 43 +#define R600_VS_SHADER__SQ_PGM_RESOURCES_VS 44 +#define R600_VS_SHADER__SQ_PGM_START_FS 45 +#define R600_VS_SHADER__SQ_PGM_RESOURCES_FS 46 +#define R600_VS_SHADER__SQ_PGM_CF_OFFSET_VS 47 +#define R600_VS_SHADER__SQ_PGM_CF_OFFSET_FS 48 +#define R600_VS_SHADER_SIZE 49 +#define R600_VS_SHADER_PM4 128 + +/* R600_PS_SHADER */ +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_0 0 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_1 1 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_2 2 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_3 3 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_4 4 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_5 5 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_6 6 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_7 7 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_8 8 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_9 9 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_10 10 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_11 11 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_12 12 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_13 13 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_14 14 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_15 15 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_16 16 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_17 17 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_18 18 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_19 19 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_20 20 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_21 21 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_22 22 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_23 23 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_24 24 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_25 25 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_26 26 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_27 27 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_28 28 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_29 29 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_30 30 +#define R600_PS_SHADER__SPI_PS_INPUT_CNTL_31 31 +#define R600_PS_SHADER__SPI_PS_IN_CONTROL_0 32 +#define R600_PS_SHADER__SPI_PS_IN_CONTROL_1 33 +#define R600_PS_SHADER__SPI_INPUT_Z 34 +#define R600_PS_SHADER__SQ_PGM_START_PS 35 +#define R600_PS_SHADER__SQ_PGM_RESOURCES_PS 36 +#define R600_PS_SHADER__SQ_PGM_EXPORTS_PS 37 +#define R600_PS_SHADER__SQ_PGM_CF_OFFSET_PS 38 +#define R600_PS_SHADER_SIZE 39 +#define R600_PS_SHADER_PM4 128 + +/* R600_VS_CBUF */ +#define R600_VS_CBUF__ALU_CONST_BUFFER_SIZE_VS_0 0 +#define R600_VS_CBUF__ALU_CONST_CACHE_VS_0 1 +#define R600_VS_CBUF_SIZE 2 +#define R600_VS_CBUF_PM4 128 + +/* R600_PS_CBUF */ +#define R600_PS_CBUF__ALU_CONST_BUFFER_SIZE_PS_0 0 +#define R600_PS_CBUF__ALU_CONST_CACHE_PS_0 1 +#define R600_PS_CBUF_SIZE 2 +#define R600_PS_CBUF_PM4 128 + +/* R600_PS_CONSTANT */ +#define R600_PS_CONSTANT__SQ_ALU_CONSTANT0_0 0 +#define R600_PS_CONSTANT__SQ_ALU_CONSTANT1_0 1 +#define R600_PS_CONSTANT__SQ_ALU_CONSTANT2_0 2 +#define R600_PS_CONSTANT__SQ_ALU_CONSTANT3_0 3 +#define R600_PS_CONSTANT_SIZE 4 +#define R600_PS_CONSTANT_PM4 128 + +/* R600_VS_CONSTANT */ +#define R600_VS_CONSTANT__SQ_ALU_CONSTANT0_256 0 +#define R600_VS_CONSTANT__SQ_ALU_CONSTANT1_256 1 +#define R600_VS_CONSTANT__SQ_ALU_CONSTANT2_256 2 +#define R600_VS_CONSTANT__SQ_ALU_CONSTANT3_256 3 +#define R600_VS_CONSTANT_SIZE 4 +#define R600_VS_CONSTANT_PM4 128 + +/* R600_UCP */ +#define R600_UCP__PA_CL_UCP0_X 0 +#define R600_UCP__PA_CL_UCP0_Y 1 +#define R600_UCP__PA_CL_UCP0_Z 2 +#define R600_UCP__PA_CL_UCP0_W 3 +#define R600_UCP__PA_CL_UCP1_X 4 +#define R600_UCP__PA_CL_UCP1_Y 5 +#define R600_UCP__PA_CL_UCP1_Z 6 +#define R600_UCP__PA_CL_UCP1_W 7 +#define R600_UCP__PA_CL_UCP2_X 8 +#define R600_UCP__PA_CL_UCP2_Y 9 +#define R600_UCP__PA_CL_UCP2_Z 10 +#define R600_UCP__PA_CL_UCP2_W 11 +#define R600_UCP__PA_CL_UCP3_X 12 +#define R600_UCP__PA_CL_UCP3_Y 13 +#define R600_UCP__PA_CL_UCP3_Z 14 +#define R600_UCP__PA_CL_UCP3_W 15 +#define R600_UCP__PA_CL_UCP4_X 16 +#define R600_UCP__PA_CL_UCP4_Y 17 +#define R600_UCP__PA_CL_UCP4_Z 18 +#define R600_UCP__PA_CL_UCP4_W 19 +#define R600_UCP__PA_CL_UCP5_X 20 +#define R600_UCP__PA_CL_UCP5_Y 21 +#define R600_UCP__PA_CL_UCP5_Z 22 +#define R600_UCP__PA_CL_UCP5_W 23 +#define R600_UCP_SIZE 24 +#define R600_UCP_PM4 128 + +/* R600_PS_RESOURCE */ +#define R600_PS_RESOURCE__RESOURCE0_WORD0 0 +#define R600_PS_RESOURCE__RESOURCE0_WORD1 1 +#define R600_PS_RESOURCE__RESOURCE0_WORD2 2 +#define R600_PS_RESOURCE__RESOURCE0_WORD3 3 +#define R600_PS_RESOURCE__RESOURCE0_WORD4 4 +#define R600_PS_RESOURCE__RESOURCE0_WORD5 5 +#define R600_PS_RESOURCE__RESOURCE0_WORD6 6 +#define R600_PS_RESOURCE_SIZE 7 +#define R600_PS_RESOURCE_PM4 128 + +/* R600_VS_RESOURCE */ +#define R600_VS_RESOURCE__RESOURCE160_WORD0 0 +#define R600_VS_RESOURCE__RESOURCE160_WORD1 1 +#define R600_VS_RESOURCE__RESOURCE160_WORD2 2 +#define R600_VS_RESOURCE__RESOURCE160_WORD3 3 +#define R600_VS_RESOURCE__RESOURCE160_WORD4 4 +#define R600_VS_RESOURCE__RESOURCE160_WORD5 5 +#define R600_VS_RESOURCE__RESOURCE160_WORD6 6 +#define R600_VS_RESOURCE_SIZE 7 +#define R600_VS_RESOURCE_PM4 128 + +/* R600_FS_RESOURCE */ +#define R600_FS_RESOURCE__RESOURCE320_WORD0 0 +#define R600_FS_RESOURCE__RESOURCE320_WORD1 1 +#define R600_FS_RESOURCE__RESOURCE320_WORD2 2 +#define R600_FS_RESOURCE__RESOURCE320_WORD3 3 +#define R600_FS_RESOURCE__RESOURCE320_WORD4 4 +#define R600_FS_RESOURCE__RESOURCE320_WORD5 5 +#define R600_FS_RESOURCE__RESOURCE320_WORD6 6 +#define R600_FS_RESOURCE_SIZE 7 +#define R600_FS_RESOURCE_PM4 128 + +/* R600_GS_RESOURCE */ +#define R600_GS_RESOURCE__RESOURCE336_WORD0 0 +#define R600_GS_RESOURCE__RESOURCE336_WORD1 1 +#define R600_GS_RESOURCE__RESOURCE336_WORD2 2 +#define R600_GS_RESOURCE__RESOURCE336_WORD3 3 +#define R600_GS_RESOURCE__RESOURCE336_WORD4 4 +#define R600_GS_RESOURCE__RESOURCE336_WORD5 5 +#define R600_GS_RESOURCE__RESOURCE336_WORD6 6 +#define R600_GS_RESOURCE_SIZE 7 +#define R600_GS_RESOURCE_PM4 128 + +/* R600_PS_SAMPLER */ +#define R600_PS_SAMPLER__SQ_TEX_SAMPLER_WORD0_0 0 +#define R600_PS_SAMPLER__SQ_TEX_SAMPLER_WORD1_0 1 +#define R600_PS_SAMPLER__SQ_TEX_SAMPLER_WORD2_0 2 +#define R600_PS_SAMPLER_SIZE 3 +#define R600_PS_SAMPLER_PM4 128 + +/* R600_VS_SAMPLER */ +#define R600_VS_SAMPLER__SQ_TEX_SAMPLER_WORD0_18 0 +#define R600_VS_SAMPLER__SQ_TEX_SAMPLER_WORD1_18 1 +#define R600_VS_SAMPLER__SQ_TEX_SAMPLER_WORD2_18 2 +#define R600_VS_SAMPLER_SIZE 3 +#define R600_VS_SAMPLER_PM4 128 + +/* R600_GS_SAMPLER */ +#define R600_GS_SAMPLER__SQ_TEX_SAMPLER_WORD0_36 0 +#define R600_GS_SAMPLER__SQ_TEX_SAMPLER_WORD1_36 1 +#define R600_GS_SAMPLER__SQ_TEX_SAMPLER_WORD2_36 2 +#define R600_GS_SAMPLER_SIZE 3 +#define R600_GS_SAMPLER_PM4 128 + +/* R600_PS_SAMPLER_BORDER */ +#define R600_PS_SAMPLER_BORDER__TD_PS_SAMPLER0_BORDER_RED 0 +#define R600_PS_SAMPLER_BORDER__TD_PS_SAMPLER0_BORDER_GREEN 1 +#define R600_PS_SAMPLER_BORDER__TD_PS_SAMPLER0_BORDER_BLUE 2 +#define R600_PS_SAMPLER_BORDER__TD_PS_SAMPLER0_BORDER_ALPHA 3 +#define R600_PS_SAMPLER_BORDER_SIZE 4 +#define R600_PS_SAMPLER_BORDER_PM4 128 + +/* R600_VS_SAMPLER_BORDER */ +#define R600_VS_SAMPLER_BORDER__TD_VS_SAMPLER0_BORDER_RED 0 +#define R600_VS_SAMPLER_BORDER__TD_VS_SAMPLER0_BORDER_GREEN 1 +#define R600_VS_SAMPLER_BORDER__TD_VS_SAMPLER0_BORDER_BLUE 2 +#define R600_VS_SAMPLER_BORDER__TD_VS_SAMPLER0_BORDER_ALPHA 3 +#define R600_VS_SAMPLER_BORDER_SIZE 4 +#define R600_VS_SAMPLER_BORDER_PM4 128 + +/* R600_GS_SAMPLER_BORDER */ +#define R600_GS_SAMPLER_BORDER__TD_GS_SAMPLER0_BORDER_RED 0 +#define R600_GS_SAMPLER_BORDER__TD_GS_SAMPLER0_BORDER_GREEN 1 +#define R600_GS_SAMPLER_BORDER__TD_GS_SAMPLER0_BORDER_BLUE 2 +#define R600_GS_SAMPLER_BORDER__TD_GS_SAMPLER0_BORDER_ALPHA 3 +#define R600_GS_SAMPLER_BORDER_SIZE 4 +#define R600_GS_SAMPLER_BORDER_PM4 128 + +/* R600_CB0 */ +#define R600_CB0__CB_COLOR0_BASE 0 +#define R600_CB0__CB_COLOR0_INFO 1 +#define R600_CB0__CB_COLOR0_SIZE 2 +#define R600_CB0__CB_COLOR0_VIEW 3 +#define R600_CB0__CB_COLOR0_FRAG 4 +#define R600_CB0__CB_COLOR0_TILE 5 +#define R600_CB0__CB_COLOR0_MASK 6 +#define R600_CB0_SIZE 7 +#define R600_CB0_PM4 128 + +/* R600_CB1 */ +#define R600_CB1__CB_COLOR1_BASE 0 +#define R600_CB1__CB_COLOR1_INFO 1 +#define R600_CB1__CB_COLOR1_SIZE 2 +#define R600_CB1__CB_COLOR1_VIEW 3 +#define R600_CB1__CB_COLOR1_FRAG 4 +#define R600_CB1__CB_COLOR1_TILE 5 +#define R600_CB1__CB_COLOR1_MASK 6 +#define R600_CB1_SIZE 7 +#define R600_CB1_PM4 128 + +/* R600_CB2 */ +#define R600_CB2__CB_COLOR2_BASE 0 +#define R600_CB2__CB_COLOR2_INFO 1 +#define R600_CB2__CB_COLOR2_SIZE 2 +#define R600_CB2__CB_COLOR2_VIEW 3 +#define R600_CB2__CB_COLOR2_FRAG 4 +#define R600_CB2__CB_COLOR2_TILE 5 +#define R600_CB2__CB_COLOR2_MASK 6 +#define R600_CB2_SIZE 7 +#define R600_CB2_PM4 128 + +/* R600_CB3 */ +#define R600_CB3__CB_COLOR3_BASE 0 +#define R600_CB3__CB_COLOR3_INFO 1 +#define R600_CB3__CB_COLOR3_SIZE 2 +#define R600_CB3__CB_COLOR3_VIEW 3 +#define R600_CB3__CB_COLOR3_FRAG 4 +#define R600_CB3__CB_COLOR3_TILE 5 +#define R600_CB3__CB_COLOR3_MASK 6 +#define R600_CB3_SIZE 7 +#define R600_CB3_PM4 128 + +/* R600_CB4 */ +#define R600_CB4__CB_COLOR4_BASE 0 +#define R600_CB4__CB_COLOR4_INFO 1 +#define R600_CB4__CB_COLOR4_SIZE 2 +#define R600_CB4__CB_COLOR4_VIEW 3 +#define R600_CB4__CB_COLOR4_FRAG 4 +#define R600_CB4__CB_COLOR4_TILE 5 +#define R600_CB4__CB_COLOR4_MASK 6 +#define R600_CB4_SIZE 7 +#define R600_CB4_PM4 128 + +/* R600_CB5 */ +#define R600_CB5__CB_COLOR5_BASE 0 +#define R600_CB5__CB_COLOR5_INFO 1 +#define R600_CB5__CB_COLOR5_SIZE 2 +#define R600_CB5__CB_COLOR5_VIEW 3 +#define R600_CB5__CB_COLOR5_FRAG 4 +#define R600_CB5__CB_COLOR5_TILE 5 +#define R600_CB5__CB_COLOR5_MASK 6 +#define R600_CB5_SIZE 7 +#define R600_CB5_PM4 128 + +/* R600_CB6 */ +#define R600_CB6__CB_COLOR6_BASE 0 +#define R600_CB6__CB_COLOR6_INFO 1 +#define R600_CB6__CB_COLOR6_SIZE 2 +#define R600_CB6__CB_COLOR6_VIEW 3 +#define R600_CB6__CB_COLOR6_FRAG 4 +#define R600_CB6__CB_COLOR6_TILE 5 +#define R600_CB6__CB_COLOR6_MASK 6 +#define R600_CB6_SIZE 7 +#define R600_CB6_PM4 128 + +/* R600_CB7 */ +#define R600_CB7__CB_COLOR7_BASE 0 +#define R600_CB7__CB_COLOR7_INFO 1 +#define R600_CB7__CB_COLOR7_SIZE 2 +#define R600_CB7__CB_COLOR7_VIEW 3 +#define R600_CB7__CB_COLOR7_FRAG 4 +#define R600_CB7__CB_COLOR7_TILE 5 +#define R600_CB7__CB_COLOR7_MASK 6 +#define R600_CB7_SIZE 7 +#define R600_CB7_PM4 128 + +/* R600_DB */ +#define R600_DB__DB_DEPTH_BASE 0 +#define R600_DB__DB_DEPTH_SIZE 1 +#define R600_DB__DB_DEPTH_VIEW 2 +#define R600_DB__DB_DEPTH_INFO 3 +#define R600_DB__DB_HTILE_SURFACE 4 +#define R600_DB__DB_PREFETCH_LIMIT 5 +#define R600_DB_SIZE 6 +#define R600_DB_PM4 128 + +/* R600_VGT */ +#define R600_VGT__VGT_PRIMITIVE_TYPE 0 +#define R600_VGT__VGT_MAX_VTX_INDX 1 +#define R600_VGT__VGT_MIN_VTX_INDX 2 +#define R600_VGT__VGT_INDX_OFFSET 3 +#define R600_VGT__VGT_MULTI_PRIM_IB_RESET_INDX 4 +#define R600_VGT__VGT_DMA_INDEX_TYPE 5 +#define R600_VGT__VGT_PRIMITIVEID_EN 6 +#define R600_VGT__VGT_DMA_NUM_INSTANCES 7 +#define R600_VGT__VGT_MULTI_PRIM_IB_RESET_EN 8 +#define R600_VGT__VGT_INSTANCE_STEP_RATE_0 9 +#define R600_VGT__VGT_INSTANCE_STEP_RATE_1 10 +#define R600_VGT_SIZE 11 +#define R600_VGT_PM4 128 + +/* R600_DRAW */ +#define R600_DRAW__VGT_NUM_INDICES 0 +#define R600_DRAW__VGT_DMA_BASE_HI 1 +#define R600_DRAW__VGT_DMA_BASE 2 +#define R600_DRAW__VGT_DRAW_INITIATOR 3 +#define R600_DRAW_SIZE 4 +#define R600_DRAW_PM4 128 + +/* R600_VGT_EVENT */ +#define R600_VGT_EVENT__VGT_EVENT_INITIATOR 0 +#define R600_VGT_EVENT_SIZE 1 +#define R600_VGT_EVENT_PM4 128 + +/* R600_CB_FLUSH */ +#define R600_CB_FLUSH_SIZE 0 +#define R600_CB_FLUSH_PM4 128 + +/* R600_DB_FLUSH */ +#define R600_DB_FLUSH_SIZE 0 +#define R600_DB_FLUSH_PM4 128 + diff --git a/src/gallium/drivers/r600/r600_texture.c b/src/gallium/drivers/r600/r600_texture.c new file mode 100644 index 0000000..d4d9b07 --- /dev/null +++ b/src/gallium/drivers/r600/r600_texture.c @@ -0,0 +1,1035 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + * Corbin Simpson + */ +#include +#include +#include +#include +#include +#include +#include "state_tracker/drm_driver.h" +#include "pipebuffer/pb_buffer.h" +#include "r600_pipe.h" +#include "r600_resource.h" +#include "r600_state_inlines.h" +#include "r600d.h" +#include "r600_formats.h" + +extern struct u_resource_vtbl r600_texture_vtbl; + +/* Copy from a full GPU texture to a transfer's staging one. */ +static void r600_copy_to_staging_texture(struct pipe_context *ctx, struct r600_transfer *rtransfer) +{ + struct pipe_transfer *transfer = (struct pipe_transfer*)rtransfer; + struct pipe_resource *texture = transfer->resource; + + ctx->resource_copy_region(ctx, rtransfer->staging_texture, + 0, 0, 0, 0, texture, transfer->level, + &transfer->box); +} + + +/* Copy from a transfer's staging texture to a full GPU one. */ +static void r600_copy_from_staging_texture(struct pipe_context *ctx, struct r600_transfer *rtransfer) +{ + struct pipe_transfer *transfer = (struct pipe_transfer*)rtransfer; + struct pipe_resource *texture = transfer->resource; + struct pipe_box sbox; + + sbox.x = sbox.y = sbox.z = 0; + sbox.width = transfer->box.width; + sbox.height = transfer->box.height; + /* XXX that might be wrong */ + sbox.depth = 1; + ctx->resource_copy_region(ctx, texture, transfer->level, + transfer->box.x, transfer->box.y, transfer->box.z, + rtransfer->staging_texture, + 0, &sbox); + + ctx->flush(ctx, 0, NULL); +} + +unsigned r600_texture_get_offset(struct r600_resource_texture *rtex, + unsigned level, unsigned layer) +{ + unsigned offset = rtex->offset[level]; + + switch (rtex->resource.base.b.target) { + case PIPE_TEXTURE_3D: + case PIPE_TEXTURE_CUBE: + return offset + layer * rtex->layer_size[level]; + default: + assert(layer == 0); + return offset; + } +} + +static unsigned r600_get_pixel_alignment(struct pipe_screen *screen, + enum pipe_format format, + unsigned array_mode) +{ + struct r600_screen* rscreen = (struct r600_screen *)screen; + unsigned pixsize = util_format_get_blocksize(format); + int p_align; + + switch(array_mode) { + case V_038000_ARRAY_1D_TILED_THIN1: + p_align = MAX2(8, + ((rscreen->tiling_info->group_bytes / 8 / pixsize))); + break; + case V_038000_ARRAY_2D_TILED_THIN1: + p_align = MAX2(rscreen->tiling_info->num_banks, + (((rscreen->tiling_info->group_bytes / 8 / pixsize)) * + rscreen->tiling_info->num_banks)) * 8; + break; + case V_038000_ARRAY_LINEAR_GENERAL: + default: + p_align = rscreen->tiling_info->group_bytes / pixsize; + break; + } + return p_align; +} + +static unsigned r600_get_height_alignment(struct pipe_screen *screen, + unsigned array_mode) +{ + struct r600_screen* rscreen = (struct r600_screen *)screen; + int h_align; + + switch (array_mode) { + case V_038000_ARRAY_2D_TILED_THIN1: + h_align = rscreen->tiling_info->num_channels * 8; + break; + case V_038000_ARRAY_1D_TILED_THIN1: + h_align = 8; + break; + default: + h_align = 1; + break; + } + return h_align; +} + +static unsigned r600_get_base_alignment(struct pipe_screen *screen, + enum pipe_format format, + unsigned array_mode) +{ + struct r600_screen* rscreen = (struct r600_screen *)screen; + unsigned pixsize = util_format_get_blocksize(format); + int p_align = r600_get_pixel_alignment(screen, format, array_mode); + int h_align = r600_get_height_alignment(screen, array_mode); + int b_align; + + switch (array_mode) { + case V_038000_ARRAY_2D_TILED_THIN1: + b_align = MAX2(rscreen->tiling_info->num_banks * rscreen->tiling_info->num_channels * 8 * 8 * pixsize, + p_align * pixsize * h_align); + break; + case V_038000_ARRAY_1D_TILED_THIN1: + default: + b_align = rscreen->tiling_info->group_bytes; + break; + } + return b_align; +} + +static unsigned mip_minify(unsigned size, unsigned level) +{ + unsigned val; + val = u_minify(size, level); + if (level > 0) + val = util_next_power_of_two(val); + return val; +} + +static unsigned r600_texture_get_stride(struct pipe_screen *screen, + struct r600_resource_texture *rtex, + unsigned level) +{ + struct pipe_resource *ptex = &rtex->resource.base.b; + unsigned width, stride, tile_width; + + if (rtex->pitch_override) + return rtex->pitch_override; + + width = mip_minify(ptex->width0, level); + if (util_format_is_plain(ptex->format)) { + tile_width = r600_get_pixel_alignment(screen, ptex->format, + rtex->array_mode[level]); + width = align(width, tile_width); + } + stride = util_format_get_stride(ptex->format, width); + + return stride; +} + +static unsigned r600_texture_get_nblocksy(struct pipe_screen *screen, + struct r600_resource_texture *rtex, + unsigned level) +{ + struct pipe_resource *ptex = &rtex->resource.base.b; + unsigned height, tile_height; + + height = mip_minify(ptex->height0, level); + if (util_format_is_plain(ptex->format)) { + tile_height = r600_get_height_alignment(screen, + rtex->array_mode[level]); + height = align(height, tile_height); + } + return util_format_get_nblocksy(ptex->format, height); +} + +/* Get a width in pixels from a stride in bytes. */ +static unsigned pitch_to_width(enum pipe_format format, unsigned pitch_in_bytes) +{ + return (pitch_in_bytes / util_format_get_blocksize(format)) * + util_format_get_blockwidth(format); +} + +static void r600_texture_set_array_mode(struct pipe_screen *screen, + struct r600_resource_texture *rtex, + unsigned level, unsigned array_mode) +{ + struct pipe_resource *ptex = &rtex->resource.base.b; + + switch (array_mode) { + case V_0280A0_ARRAY_LINEAR_GENERAL: + case V_0280A0_ARRAY_LINEAR_ALIGNED: + case V_0280A0_ARRAY_1D_TILED_THIN1: + default: + rtex->array_mode[level] = array_mode; + break; + case V_0280A0_ARRAY_2D_TILED_THIN1: + { + unsigned w, h, tile_height, tile_width; + + tile_height = r600_get_height_alignment(screen, array_mode); + tile_width = r600_get_pixel_alignment(screen, ptex->format, array_mode); + + w = mip_minify(ptex->width0, level); + h = mip_minify(ptex->height0, level); + if (w < tile_width || h < tile_height) + rtex->array_mode[level] = V_0280A0_ARRAY_1D_TILED_THIN1; + else + rtex->array_mode[level] = array_mode; + } + break; + } +} + +static void r600_setup_miptree(struct pipe_screen *screen, + struct r600_resource_texture *rtex, + unsigned array_mode) +{ + struct pipe_resource *ptex = &rtex->resource.base.b; + struct radeon *radeon = (struct radeon *)screen->winsys; + enum chip_class chipc = r600_get_family_class(radeon); + unsigned pitch, size, layer_size, i, offset; + unsigned nblocksy; + + for (i = 0, offset = 0; i <= ptex->last_level; i++) { + r600_texture_set_array_mode(screen, rtex, i, array_mode); + + pitch = r600_texture_get_stride(screen, rtex, i); + nblocksy = r600_texture_get_nblocksy(screen, rtex, i); + + layer_size = pitch * nblocksy; + + if (ptex->target == PIPE_TEXTURE_CUBE) { + if (chipc >= R700) + size = layer_size * 8; + else + size = layer_size * 6; + } + else + size = layer_size * u_minify(ptex->depth0, i); + /* align base image and start of miptree */ + if ((i == 0) || (i == 1)) + offset = align(offset, r600_get_base_alignment(screen, ptex->format, array_mode)); + rtex->offset[i] = offset; + rtex->layer_size[i] = layer_size; + rtex->pitch_in_bytes[i] = pitch; + rtex->pitch_in_pixels[i] = pitch_to_width(ptex->format, pitch); + offset += size; + } + rtex->size = offset; +} + +static struct r600_resource_texture * +r600_texture_create_object(struct pipe_screen *screen, + const struct pipe_resource *base, + unsigned array_mode, + unsigned pitch_in_bytes_override, + unsigned max_buffer_size, + struct r600_bo *bo) +{ + struct r600_resource_texture *rtex; + struct r600_resource *resource; + struct radeon *radeon = (struct radeon *)screen->winsys; + + rtex = CALLOC_STRUCT(r600_resource_texture); + if (rtex == NULL) + return NULL; + + resource = &rtex->resource; + resource->base.b = *base; + resource->base.vtbl = &r600_texture_vtbl; + pipe_reference_init(&resource->base.b.reference, 1); + resource->base.b.screen = screen; + resource->bo = bo; + rtex->pitch_override = pitch_in_bytes_override; + + if (array_mode) + rtex->tiled = 1; + r600_setup_miptree(screen, rtex, array_mode); + + resource->size = rtex->size; + + if (!resource->bo) { + struct pipe_resource *ptex = &rtex->resource.base.b; + int base_align = r600_get_base_alignment(screen, ptex->format, array_mode); + + resource->bo = r600_bo(radeon, rtex->size, base_align, base->bind, base->usage); + if (!resource->bo) { + FREE(rtex); + return NULL; + } + } + return rtex; +} + +struct pipe_resource *r600_texture_create(struct pipe_screen *screen, + const struct pipe_resource *templ) +{ + unsigned array_mode = 0; + static int force_tiling = -1; + + /* Would like some magic "get_bool_option_once" routine. + */ + if (force_tiling == -1) + force_tiling = debug_get_bool_option("R600_FORCE_TILING", FALSE); + + if (force_tiling) { + if (!(templ->flags & R600_RESOURCE_FLAG_TRANSFER) && + !(templ->bind & PIPE_BIND_SCANOUT)) { + array_mode = V_038000_ARRAY_2D_TILED_THIN1; + } + } + + return (struct pipe_resource *)r600_texture_create_object(screen, templ, array_mode, + 0, 0, NULL); + +} + +static void r600_texture_destroy(struct pipe_screen *screen, + struct pipe_resource *ptex) +{ + struct r600_resource_texture *rtex = (struct r600_resource_texture*)ptex; + struct r600_resource *resource = &rtex->resource; + struct radeon *radeon = (struct radeon *)screen->winsys; + + if (rtex->flushed_depth_texture) + pipe_resource_reference((struct pipe_resource **)&rtex->flushed_depth_texture, NULL); + + if (resource->bo) { + r600_bo_reference(radeon, &resource->bo, NULL); + } + FREE(rtex); +} + +static boolean r600_texture_get_handle(struct pipe_screen* screen, + struct pipe_resource *ptex, + struct winsys_handle *whandle) +{ + struct r600_resource_texture *rtex = (struct r600_resource_texture*)ptex; + struct r600_resource *resource = &rtex->resource; + struct radeon *radeon = (struct radeon *)screen->winsys; + + return r600_bo_get_winsys_handle(radeon, resource->bo, + rtex->pitch_in_bytes[0], whandle); +} + +static struct pipe_surface *r600_create_surface(struct pipe_context *pipe, + struct pipe_resource *texture, + const struct pipe_surface *surf_tmpl) +{ + struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture; + struct r600_surface *surface = CALLOC_STRUCT(r600_surface); + unsigned tile_height; + unsigned level = surf_tmpl->u.tex.level; + + assert(surf_tmpl->u.tex.first_layer == surf_tmpl->u.tex.last_layer); + if (surface == NULL) + return NULL; + /* XXX no offset */ +/* offset = r600_texture_get_offset(rtex, level, surf_tmpl->u.tex.first_layer);*/ + pipe_reference_init(&surface->base.reference, 1); + pipe_resource_reference(&surface->base.texture, texture); + surface->base.context = pipe; + surface->base.format = surf_tmpl->format; + surface->base.width = mip_minify(texture->width0, level); + surface->base.height = mip_minify(texture->height0, level); + surface->base.usage = surf_tmpl->usage; + surface->base.texture = texture; + surface->base.u.tex.first_layer = surf_tmpl->u.tex.first_layer; + surface->base.u.tex.last_layer = surf_tmpl->u.tex.last_layer; + surface->base.u.tex.level = level; + + tile_height = r600_get_height_alignment(pipe->screen, rtex->array_mode[level]); + surface->aligned_height = align(surface->base.height, tile_height); + return &surface->base; +} + +static void r600_surface_destroy(struct pipe_context *pipe, + struct pipe_surface *surface) +{ + pipe_resource_reference(&surface->texture, NULL); + FREE(surface); +} + + +struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen, + const struct pipe_resource *templ, + struct winsys_handle *whandle) +{ + struct radeon *rw = (struct radeon*)screen->winsys; + struct r600_bo *bo = NULL; + unsigned array_mode = 0; + + /* Support only 2D textures without mipmaps */ + if ((templ->target != PIPE_TEXTURE_2D && templ->target != PIPE_TEXTURE_RECT) || + templ->depth0 != 1 || templ->last_level != 0) + return NULL; + + bo = r600_bo_handle(rw, whandle->handle, &array_mode); + if (bo == NULL) { + return NULL; + } + + return (struct pipe_resource *)r600_texture_create_object(screen, templ, array_mode, + whandle->stride, + 0, + bo); +} + +static unsigned int r600_texture_is_referenced(struct pipe_context *context, + struct pipe_resource *texture, + unsigned level, int layer) +{ + /* FIXME */ + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +int (*r600_blit_uncompress_depth_ptr)(struct pipe_context *ctx, struct r600_resource_texture *texture); + +int r600_texture_depth_flush(struct pipe_context *ctx, + struct pipe_resource *texture) +{ + struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture; + struct pipe_resource resource; + + if (rtex->flushed_depth_texture) + goto out; + + resource.target = PIPE_TEXTURE_2D; + resource.format = texture->format; + resource.width0 = texture->width0; + resource.height0 = texture->height0; + resource.depth0 = 1; + resource.last_level = 0; + resource.nr_samples = 0; + resource.usage = PIPE_USAGE_DYNAMIC; + resource.bind = 0; + resource.flags = R600_RESOURCE_FLAG_TRANSFER; + + resource.bind |= PIPE_BIND_DEPTH_STENCIL; + + rtex->flushed_depth_texture = (struct r600_resource_texture *)ctx->screen->resource_create(ctx->screen, &resource); + if (rtex->flushed_depth_texture == NULL) { + R600_ERR("failed to create temporary texture to hold untiled copy\n"); + return -ENOMEM; + } + +out: + /* XXX: only do this if the depth texture has actually changed: + */ + r600_blit_uncompress_depth_ptr(ctx, rtex); + return 0; +} + +/* Needs adjustment for pixelformat: + */ +static INLINE unsigned u_box_volume( const struct pipe_box *box ) +{ + return box->width * box->depth * box->height; +}; + + +/* Figure out whether u_blitter will fallback to a transfer operation. + * If so, don't use a staging resource. + */ +static boolean permit_hardware_blit(struct pipe_screen *screen, + struct pipe_resource *res) +{ + unsigned bind; + + if (util_format_is_depth_or_stencil(res->format)) + bind = PIPE_BIND_DEPTH_STENCIL; + else + bind = PIPE_BIND_RENDER_TARGET; + + /* See r600_resource_copy_region: there is something wrong + * with depth resource copies at the moment so avoid them for + * now. + */ + if (util_format_get_component_bits(res->format, + UTIL_FORMAT_COLORSPACE_ZS, + 0) != 0) + return FALSE; + + if (!screen->is_format_supported(screen, + res->format, + res->target, + res->nr_samples, + bind, 0)) + return FALSE; + + if (!screen->is_format_supported(screen, + res->format, + res->target, + res->nr_samples, + PIPE_BIND_SAMPLER_VIEW, 0)) + return FALSE; + + return TRUE; +} + +struct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx, + struct pipe_resource *texture, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture; + struct pipe_resource resource; + struct r600_transfer *trans; + int r; + boolean use_staging_texture = FALSE; + + /* We cannot map a tiled texture directly because the data is + * in a different order, therefore we do detiling using a blit. + * + * Also, use a temporary in GTT memory for read transfers, as + * the CPU is much happier reading out of cached system memory + * than uncached VRAM. + */ + if (rtex->tiled) + use_staging_texture = TRUE; + + if ((usage & PIPE_TRANSFER_READ) && u_box_volume(box) > 1024) + use_staging_texture = TRUE; + + /* XXX: Use a staging texture for uploads if the underlying BO + * is busy. No interface for checking that currently? so do + * it eagerly whenever the transfer doesn't require a readback + * and might block. + */ + if ((usage & PIPE_TRANSFER_WRITE) && + !(usage & (PIPE_TRANSFER_READ | + PIPE_TRANSFER_DONTBLOCK | + PIPE_TRANSFER_UNSYNCHRONIZED))) + use_staging_texture = TRUE; + + if (!permit_hardware_blit(ctx->screen, texture) || + (texture->flags & R600_RESOURCE_FLAG_TRANSFER)) + use_staging_texture = FALSE; + + trans = CALLOC_STRUCT(r600_transfer); + if (trans == NULL) + return NULL; + pipe_resource_reference(&trans->transfer.resource, texture); + trans->transfer.level = level; + trans->transfer.usage = usage; + trans->transfer.box = *box; + if (rtex->depth) { + /* XXX: only readback the rectangle which is being mapped? + */ + /* XXX: when discard is true, no need to read back from depth texture + */ + r = r600_texture_depth_flush(ctx, texture); + if (r < 0) { + R600_ERR("failed to create temporary texture to hold untiled copy\n"); + pipe_resource_reference(&trans->transfer.resource, NULL); + FREE(trans); + return NULL; + } + } else if (use_staging_texture) { + resource.target = PIPE_TEXTURE_2D; + resource.format = texture->format; + resource.width0 = box->width; + resource.height0 = box->height; + resource.depth0 = 1; + resource.array_size = 1; + resource.last_level = 0; + resource.nr_samples = 0; + resource.usage = PIPE_USAGE_STAGING; + resource.bind = 0; + resource.flags = R600_RESOURCE_FLAG_TRANSFER; + /* For texture reading, the temporary (detiled) texture is used as + * a render target when blitting from a tiled texture. */ + if (usage & PIPE_TRANSFER_READ) { + resource.bind |= PIPE_BIND_RENDER_TARGET; + } + /* For texture writing, the temporary texture is used as a sampler + * when blitting into a tiled texture. */ + if (usage & PIPE_TRANSFER_WRITE) { + resource.bind |= PIPE_BIND_SAMPLER_VIEW; + } + /* Create the temporary texture. */ + trans->staging_texture = ctx->screen->resource_create(ctx->screen, &resource); + if (trans->staging_texture == NULL) { + R600_ERR("failed to create temporary texture to hold untiled copy\n"); + pipe_resource_reference(&trans->transfer.resource, NULL); + FREE(trans); + return NULL; + } + + trans->transfer.stride = + ((struct r600_resource_texture *)trans->staging_texture)->pitch_in_bytes[0]; + if (usage & PIPE_TRANSFER_READ) { + r600_copy_to_staging_texture(ctx, trans); + /* Always referenced in the blit. */ + ctx->flush(ctx, 0, NULL); + } + return &trans->transfer; + } + trans->transfer.stride = rtex->pitch_in_bytes[level]; + trans->offset = r600_texture_get_offset(rtex, level, box->z); + return &trans->transfer; +} + +void r600_texture_transfer_destroy(struct pipe_context *ctx, + struct pipe_transfer *transfer) +{ + struct r600_transfer *rtransfer = (struct r600_transfer*)transfer; + struct r600_resource_texture *rtex = (struct r600_resource_texture*)transfer->resource; + + if (rtransfer->staging_texture) { + if (transfer->usage & PIPE_TRANSFER_WRITE) { + r600_copy_from_staging_texture(ctx, rtransfer); + } + pipe_resource_reference(&rtransfer->staging_texture, NULL); + } + if (rtex->flushed_depth_texture) { + pipe_resource_reference((struct pipe_resource **)&rtex->flushed_depth_texture, NULL); + } + pipe_resource_reference(&transfer->resource, NULL); + FREE(transfer); +} + +void* r600_texture_transfer_map(struct pipe_context *ctx, + struct pipe_transfer* transfer) +{ + struct r600_transfer *rtransfer = (struct r600_transfer*)transfer; + struct r600_bo *bo; + enum pipe_format format = transfer->resource->format; + struct radeon *radeon = (struct radeon *)ctx->screen->winsys; + unsigned offset = 0; + unsigned usage = 0; + char *map; + + if (rtransfer->staging_texture) { + bo = ((struct r600_resource *)rtransfer->staging_texture)->bo; + } else { + struct r600_resource_texture *rtex = (struct r600_resource_texture*)transfer->resource; + + if (rtex->flushed_depth_texture) + bo = ((struct r600_resource *)rtex->flushed_depth_texture)->bo; + else + bo = ((struct r600_resource *)transfer->resource)->bo; + + offset = rtransfer->offset + + transfer->box.y / util_format_get_blockheight(format) * transfer->stride + + transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); + } + + if (transfer->usage & PIPE_TRANSFER_WRITE) { + usage |= PB_USAGE_CPU_WRITE; + + if (transfer->usage & PIPE_TRANSFER_DISCARD) { + } + + if (transfer->usage & PIPE_TRANSFER_FLUSH_EXPLICIT) { + } + } + + if (transfer->usage & PIPE_TRANSFER_READ) { + usage |= PB_USAGE_CPU_READ; + } + + if (transfer->usage & PIPE_TRANSFER_DONTBLOCK) { + usage |= PB_USAGE_DONTBLOCK; + } + + if (transfer->usage & PIPE_TRANSFER_UNSYNCHRONIZED) { + usage |= PB_USAGE_UNSYNCHRONIZED; + } + + map = r600_bo_map(radeon, bo, usage, ctx); + if (!map) { + return NULL; + } + + return map + offset; +} + +void r600_texture_transfer_unmap(struct pipe_context *ctx, + struct pipe_transfer* transfer) +{ + struct r600_transfer *rtransfer = (struct r600_transfer*)transfer; + struct radeon *radeon = (struct radeon *)ctx->screen->winsys; + struct r600_bo *bo; + + if (rtransfer->staging_texture) { + bo = ((struct r600_resource *)rtransfer->staging_texture)->bo; + } else { + struct r600_resource_texture *rtex = (struct r600_resource_texture*)transfer->resource; + + if (rtex->flushed_depth_texture) { + bo = ((struct r600_resource *)rtex->flushed_depth_texture)->bo; + } else { + bo = ((struct r600_resource *)transfer->resource)->bo; + } + } + r600_bo_unmap(radeon, bo); +} + +struct u_resource_vtbl r600_texture_vtbl = +{ + r600_texture_get_handle, /* get_handle */ + r600_texture_destroy, /* resource_destroy */ + r600_texture_is_referenced, /* is_resource_referenced */ + r600_texture_get_transfer, /* get_transfer */ + r600_texture_transfer_destroy, /* transfer_destroy */ + r600_texture_transfer_map, /* transfer_map */ + u_default_transfer_flush_region,/* transfer_flush_region */ + r600_texture_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; + +void r600_init_surface_functions(struct r600_pipe_context *r600) +{ + r600->context.create_surface = r600_create_surface; + r600->context.surface_destroy = r600_surface_destroy; +} + +static unsigned r600_get_swizzle_combined(const unsigned char *swizzle_format, + const unsigned char *swizzle_view) +{ + unsigned i; + unsigned char swizzle[4]; + unsigned result = 0; + const uint32_t swizzle_shift[4] = { + 16, 19, 22, 25, + }; + const uint32_t swizzle_bit[4] = { + 0, 1, 2, 3, + }; + + if (swizzle_view) { + /* Combine two sets of swizzles. */ + for (i = 0; i < 4; i++) { + swizzle[i] = swizzle_view[i] <= UTIL_FORMAT_SWIZZLE_W ? + swizzle_format[swizzle_view[i]] : swizzle_view[i]; + } + } else { + memcpy(swizzle, swizzle_format, 4); + } + + /* Get swizzle. */ + for (i = 0; i < 4; i++) { + switch (swizzle[i]) { + case UTIL_FORMAT_SWIZZLE_Y: + result |= swizzle_bit[1] << swizzle_shift[i]; + break; + case UTIL_FORMAT_SWIZZLE_Z: + result |= swizzle_bit[2] << swizzle_shift[i]; + break; + case UTIL_FORMAT_SWIZZLE_W: + result |= swizzle_bit[3] << swizzle_shift[i]; + break; + case UTIL_FORMAT_SWIZZLE_0: + result |= V_038010_SQ_SEL_0 << swizzle_shift[i]; + break; + case UTIL_FORMAT_SWIZZLE_1: + result |= V_038010_SQ_SEL_1 << swizzle_shift[i]; + break; + default: /* UTIL_FORMAT_SWIZZLE_X */ + result |= swizzle_bit[0] << swizzle_shift[i]; + } + } + return result; +} + +/* texture format translate */ +uint32_t r600_translate_texformat(enum pipe_format format, + const unsigned char *swizzle_view, + uint32_t *word4_p, uint32_t *yuv_format_p) +{ + uint32_t result = 0, word4 = 0, yuv_format = 0; + const struct util_format_description *desc; + boolean uniform = TRUE; + int i; + const uint32_t sign_bit[4] = { + S_038010_FORMAT_COMP_X(V_038010_SQ_FORMAT_COMP_SIGNED), + S_038010_FORMAT_COMP_Y(V_038010_SQ_FORMAT_COMP_SIGNED), + S_038010_FORMAT_COMP_Z(V_038010_SQ_FORMAT_COMP_SIGNED), + S_038010_FORMAT_COMP_W(V_038010_SQ_FORMAT_COMP_SIGNED) + }; + desc = util_format_description(format); + + word4 |= r600_get_swizzle_combined(desc->swizzle, swizzle_view); + + /* Colorspace (return non-RGB formats directly). */ + switch (desc->colorspace) { + /* Depth stencil formats */ + case UTIL_FORMAT_COLORSPACE_ZS: + switch (format) { + case PIPE_FORMAT_Z16_UNORM: + result = FMT_16; + goto out_word4; + case PIPE_FORMAT_X24S8_USCALED: + word4 |= S_038010_NUM_FORMAT_ALL(V_038010_SQ_NUM_FORMAT_INT); + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + result = FMT_8_24; + goto out_word4; + case PIPE_FORMAT_S8X24_USCALED: + word4 |= S_038010_NUM_FORMAT_ALL(V_038010_SQ_NUM_FORMAT_INT); + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + result = FMT_24_8; + goto out_word4; + case PIPE_FORMAT_S8_USCALED: + result = FMT_8; + word4 |= S_038010_NUM_FORMAT_ALL(V_038010_SQ_NUM_FORMAT_INT); + goto out_word4; + default: + goto out_unknown; + } + + case UTIL_FORMAT_COLORSPACE_YUV: + yuv_format |= (1 << 30); + switch (format) { + case PIPE_FORMAT_UYVY: + case PIPE_FORMAT_YUYV: + default: + break; + } + goto out_unknown; /* TODO */ + + case UTIL_FORMAT_COLORSPACE_SRGB: + word4 |= S_038010_FORCE_DEGAMMA(1); + if (format == PIPE_FORMAT_L8A8_SRGB || format == PIPE_FORMAT_L8_SRGB) + goto out_unknown; /* fails for some reason - TODO */ + break; + + default: + break; + } + + /* S3TC formats. TODO */ + if (desc->layout == UTIL_FORMAT_LAYOUT_S3TC) { + static int r600_enable_s3tc = -1; + + if (r600_enable_s3tc == -1) + r600_enable_s3tc = + debug_get_bool_option("R600_ENABLE_S3TC", FALSE); + + if (!r600_enable_s3tc) + goto out_unknown; + + switch (format) { + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + result = FMT_BC1; + goto out_word4; + case PIPE_FORMAT_DXT3_RGBA: + result = FMT_BC2; + goto out_word4; + case PIPE_FORMAT_DXT5_RGBA: + result = FMT_BC3; + goto out_word4; + default: + goto out_unknown; + } + } + + + for (i = 0; i < desc->nr_channels; i++) { + if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) { + word4 |= sign_bit[i]; + } + } + + /* R8G8Bx_SNORM - TODO CxV8U8 */ + + /* RGTC - TODO */ + + /* See whether the components are of the same size. */ + for (i = 1; i < desc->nr_channels; i++) { + uniform = uniform && desc->channel[0].size == desc->channel[i].size; + } + + /* Non-uniform formats. */ + if (!uniform) { + switch(desc->nr_channels) { + case 3: + if (desc->channel[0].size == 5 && + desc->channel[1].size == 6 && + desc->channel[2].size == 5) { + result = FMT_5_6_5; + goto out_word4; + } + goto out_unknown; + case 4: + if (desc->channel[0].size == 5 && + desc->channel[1].size == 5 && + desc->channel[2].size == 5 && + desc->channel[3].size == 1) { + result = FMT_1_5_5_5; + goto out_word4; + } + if (desc->channel[0].size == 10 && + desc->channel[1].size == 10 && + desc->channel[2].size == 10 && + desc->channel[3].size == 2) { + result = FMT_10_10_10_2; + goto out_word4; + } + goto out_unknown; + } + goto out_unknown; + } + + /* Find the first non-VOID channel. */ + for (i = 0; i < 4; i++) { + if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { + break; + } + } + + if (i == 4) + goto out_unknown; + + /* uniform formats */ + switch (desc->channel[i].type) { + case UTIL_FORMAT_TYPE_UNSIGNED: + case UTIL_FORMAT_TYPE_SIGNED: + if (!desc->channel[i].normalized && + desc->colorspace != UTIL_FORMAT_COLORSPACE_SRGB) { + goto out_unknown; + } + + switch (desc->channel[i].size) { + case 4: + switch (desc->nr_channels) { + case 2: + result = FMT_4_4; + goto out_word4; + case 4: + result = FMT_4_4_4_4; + goto out_word4; + } + goto out_unknown; + case 8: + switch (desc->nr_channels) { + case 1: + result = FMT_8; + goto out_word4; + case 2: + result = FMT_8_8; + goto out_word4; + case 4: + result = FMT_8_8_8_8; + goto out_word4; + } + goto out_unknown; + case 16: + switch (desc->nr_channels) { + case 1: + result = FMT_16; + goto out_word4; + case 2: + result = FMT_16_16; + goto out_word4; + case 4: + result = FMT_16_16_16_16; + goto out_word4; + } + } + goto out_unknown; + + case UTIL_FORMAT_TYPE_FLOAT: + switch (desc->channel[i].size) { + case 16: + switch (desc->nr_channels) { + case 1: + result = FMT_16_FLOAT; + goto out_word4; + case 2: + result = FMT_16_16_FLOAT; + goto out_word4; + case 4: + result = FMT_16_16_16_16_FLOAT; + goto out_word4; + } + goto out_unknown; + case 32: + switch (desc->nr_channels) { + case 1: + result = FMT_32_FLOAT; + goto out_word4; + case 2: + result = FMT_32_32_FLOAT; + goto out_word4; + case 4: + result = FMT_32_32_32_32_FLOAT; + goto out_word4; + } + } + + } +out_word4: + if (word4_p) + *word4_p = word4; + if (yuv_format_p) + *yuv_format_p = yuv_format; + return result; +out_unknown: +// R600_ERR("Unable to handle texformat %d %s\n", format, util_format_name(format)); + return ~0; +} diff --git a/src/gallium/drivers/r600/r600_translate.c b/src/gallium/drivers/r600/r600_translate.c new file mode 100644 index 0000000..ba12eee --- /dev/null +++ b/src/gallium/drivers/r600/r600_translate.c @@ -0,0 +1,200 @@ +/* + * Copyright 2010 Red Hat 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 + * 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. + * + * Authors: Dave Airlie + */ +#include "translate/translate_cache.h" +#include "translate/translate.h" +#include +#include +#include "r600_pipe.h" + +void r600_begin_vertex_translate(struct r600_pipe_context *rctx) +{ + struct pipe_context *pipe = &rctx->context; + struct translate_key key = {0}; + struct translate_element *te; + unsigned tr_elem_index[PIPE_MAX_ATTRIBS] = {0}; + struct translate *tr; + struct r600_vertex_element *ve = rctx->vertex_elements; + boolean vb_translated[PIPE_MAX_ATTRIBS] = {0}; + void *vb_map[PIPE_MAX_ATTRIBS] = {0}, *out_map; + struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS] = {0}, *out_transfer; + struct pipe_resource *out_buffer; + unsigned i, num_verts; + struct pipe_vertex_element new_velems[PIPE_MAX_ATTRIBS]; + void *tmp; + + /* Initialize the translate key, i.e. the recipe how vertices should be + * translated. */ + for (i = 0; i < ve->count; i++) { + struct pipe_vertex_buffer *vb = + &rctx->vertex_buffer[ve->elements[i].vertex_buffer_index]; + enum pipe_format output_format = ve->hw_format[i]; + unsigned output_format_size = ve->hw_format_size[i]; + + /* Check for support. */ + if (ve->elements[i].src_format == ve->hw_format[i]) { + continue; + } + + /* Workaround for translate: output floats instead of halfs. */ + switch (output_format) { + case PIPE_FORMAT_R16_FLOAT: + output_format = PIPE_FORMAT_R32_FLOAT; + output_format_size = 4; + break; + case PIPE_FORMAT_R16G16_FLOAT: + output_format = PIPE_FORMAT_R32G32_FLOAT; + output_format_size = 8; + break; + case PIPE_FORMAT_R16G16B16_FLOAT: + output_format = PIPE_FORMAT_R32G32B32_FLOAT; + output_format_size = 12; + break; + case PIPE_FORMAT_R16G16B16A16_FLOAT: + output_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + output_format_size = 16; + break; + default:; + } + + /* Add this vertex element. */ + te = &key.element[key.nr_elements]; + /*te->type; + te->instance_divisor;*/ + te->input_buffer = ve->elements[i].vertex_buffer_index; + te->input_format = ve->elements[i].src_format; + te->input_offset = vb->buffer_offset + ve->elements[i].src_offset; + te->output_format = output_format; + te->output_offset = key.output_stride; + + key.output_stride += output_format_size; + vb_translated[ve->elements[i].vertex_buffer_index] = TRUE; + tr_elem_index[i] = key.nr_elements; + key.nr_elements++; + } + + /* Get a translate object. */ + tr = translate_cache_find(rctx->tran.translate_cache, &key); + + /* Map buffers we want to translate. */ + for (i = 0; i < rctx->nvertex_buffer; i++) { + if (vb_translated[i]) { + struct pipe_vertex_buffer *vb = &rctx->vertex_buffer[i]; + + vb_map[i] = pipe_buffer_map(pipe, vb->buffer, + PIPE_TRANSFER_READ, &vb_transfer[i]); + + tr->set_buffer(tr, i, vb_map[i], vb->stride, vb->max_index); + } + } + + /* Create and map the output buffer. */ + num_verts = rctx->vb_max_index + 1; + + out_buffer = pipe_buffer_create(&rctx->screen->screen, + PIPE_BIND_VERTEX_BUFFER, + key.output_stride * num_verts); + + out_map = pipe_buffer_map(pipe, out_buffer, PIPE_TRANSFER_WRITE, + &out_transfer); + + /* Translate. */ + tr->run(tr, 0, num_verts, 0, out_map); + + /* Unmap all buffers. */ + for (i = 0; i < rctx->nvertex_buffer; i++) { + if (vb_translated[i]) { + pipe_buffer_unmap(pipe, rctx->vertex_buffer[i].buffer, + vb_transfer[i]); + } + } + + pipe_buffer_unmap(pipe, out_buffer, out_transfer); + + /* Setup the new vertex buffer in the first free slot. */ + for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { + struct pipe_vertex_buffer *vb = &rctx->vertex_buffer[i]; + + if (!vb->buffer) { + pipe_resource_reference(&vb->buffer, out_buffer); + vb->buffer_offset = 0; + vb->max_index = num_verts - 1; + vb->stride = key.output_stride; + rctx->tran.vb_slot = i; + break; + } + } + + /* Save and replace vertex elements. */ + for (i = 0; i < ve->count; i++) { + if (vb_translated[ve->elements[i].vertex_buffer_index]) { + te = &key.element[tr_elem_index[i]]; + new_velems[i].instance_divisor = ve->elements[i].instance_divisor; + new_velems[i].src_format = te->output_format; + new_velems[i].src_offset = te->output_offset; + new_velems[i].vertex_buffer_index = rctx->tran.vb_slot; + } else { + memcpy(&new_velems[i], &ve->elements[i], + sizeof(struct pipe_vertex_element)); + } + } + + tmp = pipe->create_vertex_elements_state(pipe, ve->count, new_velems); + pipe->bind_vertex_elements_state(pipe, tmp); + rctx->tran.new_velems = tmp; + + pipe_resource_reference(&out_buffer, NULL); +} + +void r600_end_vertex_translate(struct r600_pipe_context *rctx) +{ + struct pipe_context *pipe = &rctx->context; + + if (rctx->tran.new_velems == NULL) { + return; + } + /* Restore vertex elements. */ + pipe->delete_vertex_elements_state(pipe, rctx->tran.new_velems); + rctx->tran.new_velems = NULL; + + /* Delete the now-unused VBO. */ + pipe_resource_reference(&rctx->vertex_buffer[rctx->tran.vb_slot].buffer, NULL); +} + +void r600_translate_index_buffer(struct r600_pipe_context *r600, + struct pipe_resource **index_buffer, + unsigned *index_size, + unsigned *start, unsigned count) +{ + switch (*index_size) { + case 1: + util_shorten_ubyte_elts(&r600->context, index_buffer, 0, *start, count); + *index_size = 2; + *start = 0; + break; + case 2: + case 4: + break; + } +} diff --git a/src/gallium/drivers/r600/r600_upload.c b/src/gallium/drivers/r600/r600_upload.c new file mode 100644 index 0000000..44102ff --- /dev/null +++ b/src/gallium/drivers/r600/r600_upload.c @@ -0,0 +1,114 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#include +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "r600.h" +#include "r600_pipe.h" +#include "r600_resource.h" + +struct r600_upload { + struct r600_pipe_context *rctx; + struct r600_bo *buffer; + char *ptr; + unsigned size; + unsigned default_size; + unsigned total_alloc_size; + unsigned offset; + unsigned alignment; +}; + +struct r600_upload *r600_upload_create(struct r600_pipe_context *rctx, + unsigned default_size, + unsigned alignment) +{ + struct r600_upload *upload = CALLOC_STRUCT(r600_upload); + + if (upload == NULL) + return NULL; + + upload->rctx = rctx; + upload->size = 0; + upload->default_size = default_size; + upload->alignment = alignment; + upload->ptr = NULL; + upload->buffer = NULL; + upload->total_alloc_size = 0; + + return upload; +} + +void r600_upload_flush(struct r600_upload *upload) +{ + if (upload->buffer) { + r600_bo_reference(upload->rctx->radeon, &upload->buffer, NULL); + } + upload->default_size = MAX2(upload->total_alloc_size, upload->default_size); + upload->total_alloc_size = 0; + upload->size = 0; + upload->offset = 0; + upload->ptr = NULL; + upload->buffer = NULL; +} + +void r600_upload_destroy(struct r600_upload *upload) +{ + r600_upload_flush(upload); + FREE(upload); +} + +int r600_upload_buffer(struct r600_upload *upload, unsigned offset, + unsigned size, struct r600_resource_buffer *in_buffer, + unsigned *out_offset, unsigned *out_size, + struct r600_bo **out_buffer) +{ + unsigned alloc_size = align(size, upload->alignment); + const void *in_ptr = NULL; + + if (upload->offset + alloc_size > upload->size) { + if (upload->size) { + r600_bo_reference(upload->rctx->radeon, &upload->buffer, NULL); + } + upload->size = align(MAX2(upload->default_size, alloc_size), 4096); + upload->total_alloc_size += upload->size; + upload->offset = 0; + upload->buffer = r600_bo(upload->rctx->radeon, upload->size, 4096, PIPE_BIND_VERTEX_BUFFER, 0); + if (upload->buffer == NULL) { + return -ENOMEM; + } + upload->ptr = r600_bo_map(upload->rctx->radeon, upload->buffer, 0, NULL); + } + + in_ptr = in_buffer->user_buffer; + memcpy(upload->ptr + upload->offset, (uint8_t *) in_ptr + offset, size); + *out_offset = upload->offset; + *out_size = upload->size; + *out_buffer = NULL; + r600_bo_reference(upload->rctx->radeon, out_buffer, upload->buffer); + upload->offset += alloc_size; + + return 0; +} diff --git a/src/gallium/drivers/r600/r600d.h b/src/gallium/drivers/r600/r600d.h new file mode 100644 index 0000000..ae19bfb --- /dev/null +++ b/src/gallium/drivers/r600/r600d.h @@ -0,0 +1,3482 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#ifndef R600D_H +#define R600D_H + +#define R600_TEXEL_PITCH_ALIGNMENT_MASK 0x7 + +#define PKT3_NOP 0x10 +#define PKT3_INDIRECT_BUFFER_END 0x17 +#define PKT3_SET_PREDICATION 0x20 +#define PKT3_REG_RMW 0x21 +#define PKT3_COND_EXEC 0x22 +#define PKT3_PRED_EXEC 0x23 +#define PKT3_START_3D_CMDBUF 0x24 +#define PKT3_DRAW_INDEX_2 0x27 +#define PKT3_CONTEXT_CONTROL 0x28 +#define PKT3_DRAW_INDEX_IMMD_BE 0x29 +#define PKT3_INDEX_TYPE 0x2A +#define PKT3_DRAW_INDEX 0x2B +#define PKT3_DRAW_INDEX_AUTO 0x2D +#define PKT3_DRAW_INDEX_IMMD 0x2E +#define PKT3_NUM_INSTANCES 0x2F +#define PKT3_STRMOUT_BUFFER_UPDATE 0x34 +#define PKT3_INDIRECT_BUFFER_MP 0x38 +#define PKT3_MEM_SEMAPHORE 0x39 +#define PKT3_MPEG_INDEX 0x3A +#define PKT3_WAIT_REG_MEM 0x3C +#define PKT3_MEM_WRITE 0x3D +#define PKT3_INDIRECT_BUFFER 0x32 +#define PKT3_CP_INTERRUPT 0x40 +#define PKT3_SURFACE_SYNC 0x43 +#define PKT3_ME_INITIALIZE 0x44 +#define PKT3_COND_WRITE 0x45 +#define PKT3_EVENT_WRITE 0x46 +#define PKT3_EVENT_WRITE_EOP 0x47 +#define PKT3_ONE_REG_WRITE 0x57 +#define PKT3_SET_CONFIG_REG 0x68 +#define PKT3_SET_CONTEXT_REG 0x69 +#define PKT3_SET_ALU_CONST 0x6A +#define PKT3_SET_BOOL_CONST 0x6B +#define PKT3_SET_LOOP_CONST 0x6C +#define PKT3_SET_RESOURCE 0x6D +#define PKT3_SET_SAMPLER 0x6E +#define PKT3_SET_CTL_CONST 0x6F +#define PKT3_SURFACE_BASE_UPDATE 0x73 + +#define PKT_TYPE_S(x) (((x) & 0x3) << 30) +#define PKT_TYPE_G(x) (((x) >> 30) & 0x3) +#define PKT_TYPE_C 0x3FFFFFFF +#define PKT_COUNT_S(x) (((x) & 0x3FFF) << 16) +#define PKT_COUNT_G(x) (((x) >> 16) & 0x3FFF) +#define PKT_COUNT_C 0xC000FFFF +#define PKT0_BASE_INDEX_S(x) (((x) & 0xFFFF) << 0) +#define PKT0_BASE_INDEX_G(x) (((x) >> 0) & 0xFFFF) +#define PKT0_BASE_INDEX_C 0xFFFF0000 +#define PKT3_IT_OPCODE_S(x) (((x) & 0xFF) << 8) +#define PKT3_IT_OPCODE_G(x) (((x) >> 8) & 0xFF) +#define PKT3_IT_OPCODE_C 0xFFFF00FF +#define PKT0(index, count) (PKT_TYPE_S(0) | PKT0_BASE_INDEX_S(index) | PKT_COUNT_S(count)) +#define PKT3(op, count) (PKT_TYPE_S(3) | PKT3_IT_OPCODE_S(op) | PKT_COUNT_S(count)) + +/* Registers */ +#define R_008C00_SQ_CONFIG 0x00008C00 +#define S_008C00_VC_ENABLE(x) (((x) & 0x1) << 0) +#define G_008C00_VC_ENABLE(x) (((x) >> 0) & 0x1) +#define C_008C00_VC_ENABLE(x) 0xFFFFFFFE +#define S_008C00_EXPORT_SRC_C(x) (((x) & 0x1) << 1) +#define G_008C00_EXPORT_SRC_C(x) (((x) >> 1) & 0x1) +#define C_008C00_EXPORT_SRC_C(x) 0xFFFFFFFD +#define S_008C00_DX9_CONSTS(x) (((x) & 0x1) << 2) +#define G_008C00_DX9_CONSTS(x) (((x) >> 2) & 0x1) +#define C_008C00_DX9_CONSTS(x) 0xFFFFFFFB +#define S_008C00_ALU_INST_PREFER_VECTOR(x) (((x) & 0x1) << 3) +#define G_008C00_ALU_INST_PREFER_VECTOR(x) (((x) >> 3) & 0x1) +#define C_008C00_ALU_INST_PREFER_VECTOR(x) 0xFFFFFFF7 +#define S_008C00_DX10_CLAMP(x) (((x) & 0x1) << 4) +#define G_008C00_DX10_CLAMP(x) (((x) >> 4) & 0x1) +#define C_008C00_DX10_CLAMP(x) 0xFFFFFFEF +#define S_008C00_CLAUSE_SEQ_PRIO(x) (((x) & 0x3) << 8) +#define G_008C00_CLAUSE_SEQ_PRIO(x) (((x) >> 8) & 0x3) +#define C_008C00_CLAUSE_SEQ_PRIO(x) 0xFFFFFCFF +#define S_008C00_PS_PRIO(x) (((x) & 0x3) << 24) +#define G_008C00_PS_PRIO(x) (((x) >> 24) & 0x3) +#define C_008C00_PS_PRIO(x) 0xFCFFFFFF +#define S_008C00_VS_PRIO(x) (((x) & 0x3) << 26) +#define G_008C00_VS_PRIO(x) (((x) >> 26) & 0x3) +#define C_008C00_VS_PRIO(x) 0xF3FFFFFF +#define S_008C00_GS_PRIO(x) (((x) & 0x3) << 28) +#define G_008C00_GS_PRIO(x) (((x) >> 28) & 0x3) +#define C_008C00_GS_PRIO(x) 0xCFFFFFFF +#define S_008C00_ES_PRIO(x) (((x) & 0x3) << 30) +#define G_008C00_ES_PRIO(x) (((x) >> 30) & 0x3) +#define C_008C00_ES_PRIO(x) 0x3FFFFFFF +#define R_008C04_SQ_GPR_RESOURCE_MGMT_1 0x00008C04 +#define S_008C04_NUM_PS_GPRS(x) (((x) & 0xFF) << 0) +#define G_008C04_NUM_PS_GPRS(x) (((x) >> 0) & 0xFF) +#define C_008C04_NUM_PS_GPRS(x) 0xFFFFFF00 +#define S_008C04_NUM_VS_GPRS(x) (((x) & 0xFF) << 16) +#define G_008C04_NUM_VS_GPRS(x) (((x) >> 16) & 0xFF) +#define C_008C04_NUM_VS_GPRS(x) 0xFF00FFFF +#define S_008C04_NUM_CLAUSE_TEMP_GPRS(x) (((x) & 0xF) << 28) +#define G_008C04_NUM_CLAUSE_TEMP_GPRS(x) (((x) >> 28) & 0xF) +#define C_008C04_NUM_CLAUSE_TEMP_GPRS(x) 0x0FFFFFFF +#define R_008C0C_SQ_THREAD_RESOURCE_MGMT 0x00008C0C +#define S_008C0C_NUM_PS_THREADS(x) (((x) & 0xFF) << 0) +#define G_008C0C_NUM_PS_THREADS(x) (((x) >> 0) & 0xFF) +#define C_008C0C_NUM_PS_THREADS(x) 0xFFFFFF00 +#define S_008C0C_NUM_VS_THREADS(x) (((x) & 0xFF) << 8) +#define G_008C0C_NUM_VS_THREADS(x) (((x) >> 8) & 0xFF) +#define C_008C0C_NUM_VS_THREADS(x) 0xFFFF00FF +#define S_008C0C_NUM_GS_THREADS(x) (((x) & 0xFF) << 16) +#define G_008C0C_NUM_GS_THREADS(x) (((x) >> 16) & 0xFF) +#define C_008C0C_NUM_GS_THREADS(x) 0xFF00FFFF +#define S_008C0C_NUM_ES_THREADS(x) (((x) & 0xFF) << 24) +#define G_008C0C_NUM_ES_THREADS(x) (((x) >> 24) & 0xFF) +#define C_008C0C_NUM_ES_THREADS(x) 0x00FFFFFF +#define R_008C10_SQ_STACK_RESOURCE_MGMT_1 0x00008C10 +#define S_008C10_NUM_PS_STACK_ENTRIES(x) (((x) & 0xFFF) << 0) +#define G_008C10_NUM_PS_STACK_ENTRIES(x) (((x) >> 0) & 0xFFF) +#define C_008C10_NUM_PS_STACK_ENTRIES(x) 0xFFFFF000 +#define S_008C10_NUM_VS_STACK_ENTRIES(x) (((x) & 0xFFF) << 16) +#define G_008C10_NUM_VS_STACK_ENTRIES(x) (((x) >> 16) & 0xFFF) +#define C_008C10_NUM_VS_STACK_ENTRIES(x) 0xF000FFFF +#define R_008C14_SQ_STACK_RESOURCE_MGMT_2 0x00008C14 +#define S_008C14_NUM_GS_STACK_ENTRIES(x) (((x) & 0xFFF) << 0) +#define G_008C14_NUM_GS_STACK_ENTRIES(x) (((x) >> 0) & 0xFFF) +#define C_008C14_NUM_GS_STACK_ENTRIES(x) 0xFFFFF000 +#define S_008C14_NUM_ES_STACK_ENTRIES(x) (((x) & 0xFFF) << 16) +#define G_008C14_NUM_ES_STACK_ENTRIES(x) (((x) >> 16) & 0xFFF) +#define C_008C14_NUM_ES_STACK_ENTRIES(x) 0xF000FFFF +#define R_0280A0_CB_COLOR0_INFO 0x0280A0 +#define S_0280A0_ENDIAN(x) (((x) & 0x3) << 0) +#define G_0280A0_ENDIAN(x) (((x) >> 0) & 0x3) +#define C_0280A0_ENDIAN 0xFFFFFFFC +#define S_0280A0_FORMAT(x) (((x) & 0x3F) << 2) +#define G_0280A0_FORMAT(x) (((x) >> 2) & 0x3F) +#define C_0280A0_FORMAT 0xFFFFFF03 +#define V_0280A0_COLOR_INVALID 0x00000000 +#define V_0280A0_COLOR_8 0x00000001 +#define V_0280A0_COLOR_4_4 0x00000002 +#define V_0280A0_COLOR_3_3_2 0x00000003 +#define V_0280A0_COLOR_16 0x00000005 +#define V_0280A0_COLOR_16_FLOAT 0x00000006 +#define V_0280A0_COLOR_8_8 0x00000007 +#define V_0280A0_COLOR_5_6_5 0x00000008 +#define V_0280A0_COLOR_6_5_5 0x00000009 +#define V_0280A0_COLOR_1_5_5_5 0x0000000A +#define V_0280A0_COLOR_4_4_4_4 0x0000000B +#define V_0280A0_COLOR_5_5_5_1 0x0000000C +#define V_0280A0_COLOR_32 0x0000000D +#define V_0280A0_COLOR_32_FLOAT 0x0000000E +#define V_0280A0_COLOR_16_16 0x0000000F +#define V_0280A0_COLOR_16_16_FLOAT 0x00000010 +#define V_0280A0_COLOR_8_24 0x00000011 +#define V_0280A0_COLOR_8_24_FLOAT 0x00000012 +#define V_0280A0_COLOR_24_8 0x00000013 +#define V_0280A0_COLOR_24_8_FLOAT 0x00000014 +#define V_0280A0_COLOR_10_11_11 0x00000015 +#define V_0280A0_COLOR_10_11_11_FLOAT 0x00000016 +#define V_0280A0_COLOR_11_11_10 0x00000017 +#define V_0280A0_COLOR_11_11_10_FLOAT 0x00000018 +#define V_0280A0_COLOR_2_10_10_10 0x00000019 +#define V_0280A0_COLOR_8_8_8_8 0x0000001A +#define V_0280A0_COLOR_10_10_10_2 0x0000001B +#define V_0280A0_COLOR_X24_8_32_FLOAT 0x0000001C +#define V_0280A0_COLOR_32_32 0x0000001D +#define V_0280A0_COLOR_32_32_FLOAT 0x0000001E +#define V_0280A0_COLOR_16_16_16_16 0x0000001F +#define V_0280A0_COLOR_16_16_16_16_FLOAT 0x00000020 +#define V_0280A0_COLOR_32_32_32_32 0x00000022 +#define V_0280A0_COLOR_32_32_32_32_FLOAT 0x00000023 +#define V_0280A0_COLOR_32_32_32_FLOAT 0x00000030 +#define S_0280A0_ARRAY_MODE(x) (((x) & 0xF) << 8) +#define G_0280A0_ARRAY_MODE(x) (((x) >> 8) & 0xF) +#define C_0280A0_ARRAY_MODE 0xFFFFF0FF +#define V_0280A0_ARRAY_LINEAR_GENERAL 0x00000000 +#define V_0280A0_ARRAY_LINEAR_ALIGNED 0x00000001 +#define V_0280A0_ARRAY_1D_TILED_THIN1 0x00000002 +#define V_0280A0_ARRAY_2D_TILED_THIN1 0x00000004 +#define S_0280A0_NUMBER_TYPE(x) (((x) & 0x7) << 12) +#define G_0280A0_NUMBER_TYPE(x) (((x) >> 12) & 0x7) +#define C_0280A0_NUMBER_TYPE 0xFFFF8FFF +#define V_0280A0_NUMBER_UNORM 0x00000000 +#define V_0280A0_NUMBER_SNORM 0x00000001 +#define V_0280A0_NUMBER_USCALED 0x00000002 +#define V_0280A0_NUMBER_SSCALED 0x00000003 +#define V_0280A0_NUMBER_UINT 0x00000004 +#define V_0280A0_NUMBER_SINT 0x00000005 +#define V_0280A0_NUMBER_SRGB 0x00000006 +#define V_0280A0_NUMBER_FLOAT 0x00000007 +#define S_0280A0_READ_SIZE(x) (((x) & 0x1) << 15) +#define G_0280A0_READ_SIZE(x) (((x) >> 15) & 0x1) +#define C_0280A0_READ_SIZE 0xFFFF7FFF +#define S_0280A0_COMP_SWAP(x) (((x) & 0x3) << 16) +#define G_0280A0_COMP_SWAP(x) (((x) >> 16) & 0x3) +#define C_0280A0_COMP_SWAP 0xFFFCFFFF +#define V_0280A0_SWAP_STD 0x00000000 +#define V_0280A0_SWAP_ALT 0x00000001 +#define V_0280A0_SWAP_STD_REV 0x00000002 +#define V_0280A0_SWAP_ALT_REV 0x00000003 +#define S_0280A0_TILE_MODE(x) (((x) & 0x3) << 18) +#define G_0280A0_TILE_MODE(x) (((x) >> 18) & 0x3) +#define C_0280A0_TILE_MODE 0xFFF3FFFF +#define S_0280A0_BLEND_CLAMP(x) (((x) & 0x1) << 20) +#define G_0280A0_BLEND_CLAMP(x) (((x) >> 20) & 0x1) +#define C_0280A0_BLEND_CLAMP 0xFFEFFFFF +#define S_0280A0_CLEAR_COLOR(x) (((x) & 0x1) << 21) +#define G_0280A0_CLEAR_COLOR(x) (((x) >> 21) & 0x1) +#define C_0280A0_CLEAR_COLOR 0xFFDFFFFF +#define S_0280A0_BLEND_BYPASS(x) (((x) & 0x1) << 22) +#define G_0280A0_BLEND_BYPASS(x) (((x) >> 22) & 0x1) +#define C_0280A0_BLEND_BYPASS 0xFFBFFFFF +#define S_0280A0_BLEND_FLOAT32(x) (((x) & 0x1) << 23) +#define G_0280A0_BLEND_FLOAT32(x) (((x) >> 23) & 0x1) +#define C_0280A0_BLEND_FLOAT32 0xFF7FFFFF +#define S_0280A0_SIMPLE_FLOAT(x) (((x) & 0x1) << 24) +#define G_0280A0_SIMPLE_FLOAT(x) (((x) >> 24) & 0x1) +#define C_0280A0_SIMPLE_FLOAT 0xFEFFFFFF +#define S_0280A0_ROUND_MODE(x) (((x) & 0x1) << 25) +#define G_0280A0_ROUND_MODE(x) (((x) >> 25) & 0x1) +#define C_0280A0_ROUND_MODE 0xFDFFFFFF +#define S_0280A0_TILE_COMPACT(x) (((x) & 0x1) << 26) +#define G_0280A0_TILE_COMPACT(x) (((x) >> 26) & 0x1) +#define C_0280A0_TILE_COMPACT 0xFBFFFFFF +#define S_0280A0_SOURCE_FORMAT(x) (((x) & 0x1) << 27) +#define G_0280A0_SOURCE_FORMAT(x) (((x) >> 27) & 0x1) +#define C_0280A0_SOURCE_FORMAT 0xF7FFFFFF +#define R_028060_CB_COLOR0_SIZE 0x028060 +#define S_028060_PITCH_TILE_MAX(x) (((x) & 0x3FF) << 0) +#define G_028060_PITCH_TILE_MAX(x) (((x) >> 0) & 0x3FF) +#define C_028060_PITCH_TILE_MAX 0xFFFFFC00 +#define S_028060_SLICE_TILE_MAX(x) (((x) & 0xFFFFF) << 10) +#define G_028060_SLICE_TILE_MAX(x) (((x) >> 10) & 0xFFFFF) +#define C_028060_SLICE_TILE_MAX 0xC00003FF +#define R_028410_SX_ALPHA_TEST_CONTROL 0x028410 +#define S_028410_ALPHA_FUNC(x) (((x) & 0x7) << 0) +#define G_028410_ALPHA_FUNC(x) (((x) >> 0) & 0x7) +#define C_028410_ALPHA_FUNC 0xFFFFFFF8 +#define S_028410_ALPHA_TEST_ENABLE(x) (((x) & 0x1) << 3) +#define G_028410_ALPHA_TEST_ENABLE(x) (((x) >> 3) & 0x1) +#define C_028410_ALPHA_TEST_ENABLE 0xFFFFFFF7 +#define S_028410_ALPHA_TEST_BYPASS(x) (((x) & 0x1) << 8) +#define G_028410_ALPHA_TEST_BYPASS(x) (((x) >> 8) & 0x1) +#define C_028410_ALPHA_TEST_BYPASS 0xFFFFFEFF +#define R_028800_DB_DEPTH_CONTROL 0x028800 +#define S_028800_STENCIL_ENABLE(x) (((x) & 0x1) << 0) +#define G_028800_STENCIL_ENABLE(x) (((x) >> 0) & 0x1) +#define C_028800_STENCIL_ENABLE 0xFFFFFFFE +#define S_028800_Z_ENABLE(x) (((x) & 0x1) << 1) +#define G_028800_Z_ENABLE(x) (((x) >> 1) & 0x1) +#define C_028800_Z_ENABLE 0xFFFFFFFD +#define S_028800_Z_WRITE_ENABLE(x) (((x) & 0x1) << 2) +#define G_028800_Z_WRITE_ENABLE(x) (((x) >> 2) & 0x1) +#define C_028800_Z_WRITE_ENABLE 0xFFFFFFFB +#define S_028800_ZFUNC(x) (((x) & 0x7) << 4) +#define G_028800_ZFUNC(x) (((x) >> 4) & 0x7) +#define C_028800_ZFUNC 0xFFFFFF8F +#define S_028800_BACKFACE_ENABLE(x) (((x) & 0x1) << 7) +#define G_028800_BACKFACE_ENABLE(x) (((x) >> 7) & 0x1) +#define C_028800_BACKFACE_ENABLE 0xFFFFFF7F +#define S_028800_STENCILFUNC(x) (((x) & 0x7) << 8) +#define G_028800_STENCILFUNC(x) (((x) >> 8) & 0x7) +#define C_028800_STENCILFUNC 0xFFFFF8FF +#define V_028800_STENCILFUNC_NEVER 0x00000000 +#define V_028800_STENCILFUNC_LESS 0x00000001 +#define V_028800_STENCILFUNC_EQUAL 0x00000002 +#define V_028800_STENCILFUNC_LEQUAL 0x00000003 +#define V_028800_STENCILFUNC_GREATER 0x00000004 +#define V_028800_STENCILFUNC_NOTEQUAL 0x00000005 +#define V_028800_STENCILFUNC_GEQUAL 0x00000006 +#define V_028800_STENCILFUNC_ALWAYS 0x00000007 +#define S_028800_STENCILFAIL(x) (((x) & 0x7) << 11) +#define G_028800_STENCILFAIL(x) (((x) >> 11) & 0x7) +#define C_028800_STENCILFAIL 0xFFFFC7FF +#define V_028800_STENCIL_KEEP 0x00000000 +#define V_028800_STENCIL_ZERO 0x00000001 +#define V_028800_STENCIL_REPLACE 0x00000002 +#define V_028800_STENCIL_INCR 0x00000003 +#define V_028800_STENCIL_DECR 0x00000004 +#define V_028800_STENCIL_INVERT 0x00000005 +#define V_028800_STENCIL_INCR_WRAP 0x00000006 +#define V_028800_STENCIL_DECR_WRAP 0x00000007 +#define S_028800_STENCILZPASS(x) (((x) & 0x7) << 14) +#define G_028800_STENCILZPASS(x) (((x) >> 14) & 0x7) +#define C_028800_STENCILZPASS 0xFFFE3FFF +#define S_028800_STENCILZFAIL(x) (((x) & 0x7) << 17) +#define G_028800_STENCILZFAIL(x) (((x) >> 17) & 0x7) +#define C_028800_STENCILZFAIL 0xFFF1FFFF +#define S_028800_STENCILFUNC_BF(x) (((x) & 0x7) << 20) +#define G_028800_STENCILFUNC_BF(x) (((x) >> 20) & 0x7) +#define C_028800_STENCILFUNC_BF 0xFF8FFFFF +#define S_028800_STENCILFAIL_BF(x) (((x) & 0x7) << 23) +#define G_028800_STENCILFAIL_BF(x) (((x) >> 23) & 0x7) +#define C_028800_STENCILFAIL_BF 0xFC7FFFFF +#define S_028800_STENCILZPASS_BF(x) (((x) & 0x7) << 26) +#define G_028800_STENCILZPASS_BF(x) (((x) >> 26) & 0x7) +#define C_028800_STENCILZPASS_BF 0xE3FFFFFF +#define S_028800_STENCILZFAIL_BF(x) (((x) & 0x7) << 29) +#define G_028800_STENCILZFAIL_BF(x) (((x) >> 29) & 0x7) +#define C_028800_STENCILZFAIL_BF 0x1FFFFFFF +#define R_028808_CB_COLOR_CONTROL 0x028808 +#define S_028808_FOG_ENABLE(x) (((x) & 0x1) << 0) +#define G_028808_FOG_ENABLE(x) (((x) >> 0) & 0x1) +#define C_028808_FOG_ENABLE 0xFFFFFFFE +#define S_028808_MULTIWRITE_ENABLE(x) (((x) & 0x1) << 1) +#define G_028808_MULTIWRITE_ENABLE(x) (((x) >> 1) & 0x1) +#define C_028808_MULTIWRITE_ENABLE 0xFFFFFFFD +#define S_028808_DITHER_ENABLE(x) (((x) & 0x1) << 2) +#define G_028808_DITHER_ENABLE(x) (((x) >> 2) & 0x1) +#define C_028808_DITHER_ENABLE 0xFFFFFFFB +#define S_028808_DEGAMMA_ENABLE(x) (((x) & 0x1) << 3) +#define G_028808_DEGAMMA_ENABLE(x) (((x) >> 3) & 0x1) +#define C_028808_DEGAMMA_ENABLE 0xFFFFFFF7 +#define S_028808_SPECIAL_OP(x) (((x) & 0x7) << 4) +#define G_028808_SPECIAL_OP(x) (((x) >> 4) & 0x7) +#define C_028808_SPECIAL_OP 0xFFFFFF8F +#define S_028808_PER_MRT_BLEND(x) (((x) & 0x1) << 7) +#define G_028808_PER_MRT_BLEND(x) (((x) >> 7) & 0x1) +#define C_028808_PER_MRT_BLEND 0xFFFFFF7F +#define S_028808_TARGET_BLEND_ENABLE(x) (((x) & 0xFF) << 8) +#define G_028808_TARGET_BLEND_ENABLE(x) (((x) >> 8) & 0xFF) +#define C_028808_TARGET_BLEND_ENABLE 0xFFFF00FF +#define S_028808_ROP3(x) (((x) & 0xFF) << 16) +#define G_028808_ROP3(x) (((x) >> 16) & 0xFF) +#define C_028808_ROP3 0xFF00FFFF +#define R_028810_PA_CL_CLIP_CNTL 0x028810 +#define S_028810_UCP_ENA_0(x) (((x) & 0x1) << 0) +#define G_028810_UCP_ENA_0(x) (((x) >> 0) & 0x1) +#define C_028810_UCP_ENA_0 0xFFFFFFFE +#define S_028810_UCP_ENA_1(x) (((x) & 0x1) << 1) +#define G_028810_UCP_ENA_1(x) (((x) >> 1) & 0x1) +#define C_028810_UCP_ENA_1 0xFFFFFFFD +#define S_028810_UCP_ENA_2(x) (((x) & 0x1) << 2) +#define G_028810_UCP_ENA_2(x) (((x) >> 2) & 0x1) +#define C_028810_UCP_ENA_2 0xFFFFFFFB +#define S_028810_UCP_ENA_3(x) (((x) & 0x1) << 3) +#define G_028810_UCP_ENA_3(x) (((x) >> 3) & 0x1) +#define C_028810_UCP_ENA_3 0xFFFFFFF7 +#define S_028810_UCP_ENA_4(x) (((x) & 0x1) << 4) +#define G_028810_UCP_ENA_4(x) (((x) >> 4) & 0x1) +#define C_028810_UCP_ENA_4 0xFFFFFFEF +#define S_028810_UCP_ENA_5(x) (((x) & 0x1) << 5) +#define G_028810_UCP_ENA_5(x) (((x) >> 5) & 0x1) +#define C_028810_UCP_ENA_5 0xFFFFFFDF +#define S_028810_PS_UCP_Y_SCALE_NEG(x) (((x) & 0x1) << 13) +#define G_028810_PS_UCP_Y_SCALE_NEG(x) (((x) >> 13) & 0x1) +#define C_028810_PS_UCP_Y_SCALE_NEG 0xFFFFDFFF +#define S_028810_PS_UCP_MODE(x) (((x) & 0x3) << 14) +#define G_028810_PS_UCP_MODE(x) (((x) >> 14) & 0x3) +#define C_028810_PS_UCP_MODE 0xFFFF3FFF +#define S_028810_CLIP_DISABLE(x) (((x) & 0x1) << 16) +#define G_028810_CLIP_DISABLE(x) (((x) >> 16) & 0x1) +#define C_028810_CLIP_DISABLE 0xFFFEFFFF +#define S_028810_UCP_CULL_ONLY_ENA(x) (((x) & 0x1) << 17) +#define G_028810_UCP_CULL_ONLY_ENA(x) (((x) >> 17) & 0x1) +#define C_028810_UCP_CULL_ONLY_ENA 0xFFFDFFFF +#define S_028810_BOUNDARY_EDGE_FLAG_ENA(x) (((x) & 0x1) << 18) +#define G_028810_BOUNDARY_EDGE_FLAG_ENA(x) (((x) >> 18) & 0x1) +#define C_028810_BOUNDARY_EDGE_FLAG_ENA 0xFFFBFFFF +#define S_028810_DX_CLIP_SPACE_DEF(x) (((x) & 0x1) << 19) +#define G_028810_DX_CLIP_SPACE_DEF(x) (((x) >> 19) & 0x1) +#define C_028810_DX_CLIP_SPACE_DEF 0xFFF7FFFF +#define S_028810_DIS_CLIP_ERR_DETECT(x) (((x) & 0x1) << 20) +#define G_028810_DIS_CLIP_ERR_DETECT(x) (((x) >> 20) & 0x1) +#define C_028810_DIS_CLIP_ERR_DETECT 0xFFEFFFFF +#define S_028810_VTX_KILL_OR(x) (((x) & 0x1) << 21) +#define G_028810_VTX_KILL_OR(x) (((x) >> 21) & 0x1) +#define C_028810_VTX_KILL_OR 0xFFDFFFFF +#define S_028810_DX_LINEAR_ATTR_CLIP_ENA(x) (((x) & 0x1) << 24) +#define G_028810_DX_LINEAR_ATTR_CLIP_ENA(x) (((x) >> 24) & 0x1) +#define C_028810_DX_LINEAR_ATTR_CLIP_ENA 0xFEFFFFFF +#define S_028810_VTE_VPORT_PROVOKE_DISABLE(x) (((x) & 0x1) << 25) +#define G_028810_VTE_VPORT_PROVOKE_DISABLE(x) (((x) >> 25) & 0x1) +#define C_028810_VTE_VPORT_PROVOKE_DISABLE 0xFDFFFFFF +#define S_028810_ZCLIP_NEAR_DISABLE(x) (((x) & 0x1) << 26) +#define G_028810_ZCLIP_NEAR_DISABLE(x) (((x) >> 26) & 0x1) +#define C_028810_ZCLIP_NEAR_DISABLE 0xFBFFFFFF +#define S_028810_ZCLIP_FAR_DISABLE(x) (((x) & 0x1) << 27) +#define G_028810_ZCLIP_FAR_DISABLE(x) (((x) >> 27) & 0x1) +#define C_028810_ZCLIP_FAR_DISABLE 0xF7FFFFFF +#define R_028010_DB_DEPTH_INFO 0x028010 +#define S_028010_FORMAT(x) (((x) & 0x7) << 0) +#define G_028010_FORMAT(x) (((x) >> 0) & 0x7) +#define C_028010_FORMAT 0xFFFFFFF8 +#define V_028010_DEPTH_INVALID 0x00000000 +#define V_028010_DEPTH_16 0x00000001 +#define V_028010_DEPTH_X8_24 0x00000002 +#define V_028010_DEPTH_8_24 0x00000003 +#define V_028010_DEPTH_X8_24_FLOAT 0x00000004 +#define V_028010_DEPTH_8_24_FLOAT 0x00000005 +#define V_028010_DEPTH_32_FLOAT 0x00000006 +#define V_028010_DEPTH_X24_8_32_FLOAT 0x00000007 +#define S_028010_READ_SIZE(x) (((x) & 0x1) << 3) +#define G_028010_READ_SIZE(x) (((x) >> 3) & 0x1) +#define C_028010_READ_SIZE 0xFFFFFFF7 +#define S_028010_ARRAY_MODE(x) (((x) & 0xF) << 15) +#define G_028010_ARRAY_MODE(x) (((x) >> 15) & 0xF) +#define C_028010_ARRAY_MODE 0xFFF87FFF +#define S_028010_TILE_SURFACE_ENABLE(x) (((x) & 0x1) << 25) +#define G_028010_TILE_SURFACE_ENABLE(x) (((x) >> 25) & 0x1) +#define C_028010_TILE_SURFACE_ENABLE 0xFDFFFFFF +#define S_028010_TILE_COMPACT(x) (((x) & 0x1) << 26) +#define G_028010_TILE_COMPACT(x) (((x) >> 26) & 0x1) +#define C_028010_TILE_COMPACT 0xFBFFFFFF +#define S_028010_ZRANGE_PRECISION(x) (((x) & 0x1) << 31) +#define G_028010_ZRANGE_PRECISION(x) (((x) >> 31) & 0x1) +#define C_028010_ZRANGE_PRECISION 0x7FFFFFFF +#define R_028414_CB_BLEND_RED 0x028414 +#define S_028414_BLEND_RED(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028414_BLEND_RED(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028414_BLEND_RED 0x00000000 +#define R_028418_CB_BLEND_GREEN 0x028418 +#define S_028418_BLEND_GREEN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028418_BLEND_GREEN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028418_BLEND_GREEN 0x00000000 +#define R_02841C_CB_BLEND_BLUE 0x02841C +#define S_02841C_BLEND_BLUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_02841C_BLEND_BLUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_02841C_BLEND_BLUE 0x00000000 +#define R_028420_CB_BLEND_ALPHA 0x028420 +#define S_028420_BLEND_ALPHA(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028420_BLEND_ALPHA(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028420_BLEND_ALPHA 0x00000000 +#define R_028430_DB_STENCILREFMASK 0x028430 +#define S_028430_STENCILREF(x) (((x) & 0xFF) << 0) +#define G_028430_STENCILREF(x) (((x) >> 0) & 0xFF) +#define C_028430_STENCILREF 0xFFFFFF00 +#define S_028430_STENCILMASK(x) (((x) & 0xFF) << 8) +#define G_028430_STENCILMASK(x) (((x) >> 8) & 0xFF) +#define C_028430_STENCILMASK 0xFFFF00FF +#define S_028430_STENCILWRITEMASK(x) (((x) & 0xFF) << 16) +#define G_028430_STENCILWRITEMASK(x) (((x) >> 16) & 0xFF) +#define C_028430_STENCILWRITEMASK 0xFF00FFFF +#define R_028434_DB_STENCILREFMASK_BF 0x028434 +#define S_028434_STENCILREF_BF(x) (((x) & 0xFF) << 0) +#define G_028434_STENCILREF_BF(x) (((x) >> 0) & 0xFF) +#define C_028434_STENCILREF_BF 0xFFFFFF00 +#define S_028434_STENCILMASK_BF(x) (((x) & 0xFF) << 8) +#define G_028434_STENCILMASK_BF(x) (((x) >> 8) & 0xFF) +#define C_028434_STENCILMASK_BF 0xFFFF00FF +#define S_028434_STENCILWRITEMASK_BF(x) (((x) & 0xFF) << 16) +#define G_028434_STENCILWRITEMASK_BF(x) (((x) >> 16) & 0xFF) +#define C_028434_STENCILWRITEMASK_BF 0xFF00FFFF +#define R_028780_CB_BLEND0_CONTROL 0x028780 +#define R_028784_CB_BLEND1_CONTROL 0x028784 +#define R_028788_CB_BLEND2_CONTROL 0x028788 +#define R_02878C_CB_BLEND3_CONTROL 0x02878C +#define R_028790_CB_BLEND4_CONTROL 0x028790 +#define R_028794_CB_BLEND5_CONTROL 0x028794 +#define R_028798_CB_BLEND6_CONTROL 0x028798 +#define R_02879C_CB_BLEND7_CONTROL 0x02879C +#define R_028804_CB_BLEND_CONTROL 0x028804 +#define S_028804_COLOR_SRCBLEND(x) (((x) & 0x1F) << 0) +#define G_028804_COLOR_SRCBLEND(x) (((x) >> 0) & 0x1F) +#define C_028804_COLOR_SRCBLEND 0xFFFFFFE0 +#define V_028804_BLEND_ZERO 0x00000000 +#define V_028804_BLEND_ONE 0x00000001 +#define V_028804_BLEND_SRC_COLOR 0x00000002 +#define V_028804_BLEND_ONE_MINUS_SRC_COLOR 0x00000003 +#define V_028804_BLEND_SRC_ALPHA 0x00000004 +#define V_028804_BLEND_ONE_MINUS_SRC_ALPHA 0x00000005 +#define V_028804_BLEND_DST_ALPHA 0x00000006 +#define V_028804_BLEND_ONE_MINUS_DST_ALPHA 0x00000007 +#define V_028804_BLEND_DST_COLOR 0x00000008 +#define V_028804_BLEND_ONE_MINUS_DST_COLOR 0x00000009 +#define V_028804_BLEND_SRC_ALPHA_SATURATE 0x0000000A +#define V_028804_BLEND_BOTH_SRC_ALPHA 0x0000000B +#define V_028804_BLEND_BOTH_INV_SRC_ALPHA 0x0000000C +#define V_028804_BLEND_CONST_COLOR 0x0000000D +#define V_028804_BLEND_ONE_MINUS_CONST_COLOR 0x0000000E +#define V_028804_BLEND_SRC1_COLOR 0x0000000F +#define V_028804_BLEND_INV_SRC1_COLOR 0x00000010 +#define V_028804_BLEND_SRC1_ALPHA 0x00000011 +#define V_028804_BLEND_INV_SRC1_ALPHA 0x00000012 +#define V_028804_BLEND_CONST_ALPHA 0x00000013 +#define V_028804_BLEND_ONE_MINUS_CONST_ALPHA 0x00000014 +#define S_028804_COLOR_COMB_FCN(x) (((x) & 0x7) << 5) +#define G_028804_COLOR_COMB_FCN(x) (((x) >> 5) & 0x7) +#define C_028804_COLOR_COMB_FCN 0xFFFFFF1F +#define V_028804_COMB_DST_PLUS_SRC 0x00000000 +#define V_028804_COMB_SRC_MINUS_DST 0x00000001 +#define V_028804_COMB_MIN_DST_SRC 0x00000002 +#define V_028804_COMB_MAX_DST_SRC 0x00000003 +#define V_028804_COMB_DST_MINUS_SRC 0x00000004 +#define S_028804_COLOR_DESTBLEND(x) (((x) & 0x1F) << 8) +#define G_028804_COLOR_DESTBLEND(x) (((x) >> 8) & 0x1F) +#define C_028804_COLOR_DESTBLEND 0xFFFFE0FF +#define S_028804_OPACITY_WEIGHT(x) (((x) & 0x1) << 13) +#define G_028804_OPACITY_WEIGHT(x) (((x) >> 13) & 0x1) +#define C_028804_OPACITY_WEIGHT 0xFFFFDFFF +#define S_028804_ALPHA_SRCBLEND(x) (((x) & 0x1F) << 16) +#define G_028804_ALPHA_SRCBLEND(x) (((x) >> 16) & 0x1F) +#define C_028804_ALPHA_SRCBLEND 0xFFE0FFFF +#define S_028804_ALPHA_COMB_FCN(x) (((x) & 0x7) << 21) +#define G_028804_ALPHA_COMB_FCN(x) (((x) >> 21) & 0x7) +#define C_028804_ALPHA_COMB_FCN 0xFF1FFFFF +#define S_028804_ALPHA_DESTBLEND(x) (((x) & 0x1F) << 24) +#define G_028804_ALPHA_DESTBLEND(x) (((x) >> 24) & 0x1F) +#define C_028804_ALPHA_DESTBLEND 0xE0FFFFFF +#define S_028804_SEPARATE_ALPHA_BLEND(x) (((x) & 0x1) << 29) +#define G_028804_SEPARATE_ALPHA_BLEND(x) (((x) >> 29) & 0x1) +#define C_028804_SEPARATE_ALPHA_BLEND 0xDFFFFFFF +#define R_028814_PA_SU_SC_MODE_CNTL 0x028814 +#define S_028814_CULL_FRONT(x) (((x) & 0x1) << 0) +#define G_028814_CULL_FRONT(x) (((x) >> 0) & 0x1) +#define C_028814_CULL_FRONT 0xFFFFFFFE +#define S_028814_CULL_BACK(x) (((x) & 0x1) << 1) +#define G_028814_CULL_BACK(x) (((x) >> 1) & 0x1) +#define C_028814_CULL_BACK 0xFFFFFFFD +#define S_028814_FACE(x) (((x) & 0x1) << 2) +#define G_028814_FACE(x) (((x) >> 2) & 0x1) +#define C_028814_FACE 0xFFFFFFFB +#define S_028814_POLY_MODE(x) (((x) & 0x3) << 3) +#define G_028814_POLY_MODE(x) (((x) >> 3) & 0x3) +#define C_028814_POLY_MODE 0xFFFFFFE7 +#define S_028814_POLYMODE_FRONT_PTYPE(x) (((x) & 0x7) << 5) +#define G_028814_POLYMODE_FRONT_PTYPE(x) (((x) >> 5) & 0x7) +#define C_028814_POLYMODE_FRONT_PTYPE 0xFFFFFF1F +#define S_028814_POLYMODE_BACK_PTYPE(x) (((x) & 0x7) << 8) +#define G_028814_POLYMODE_BACK_PTYPE(x) (((x) >> 8) & 0x7) +#define C_028814_POLYMODE_BACK_PTYPE 0xFFFFF8FF +#define S_028814_POLY_OFFSET_FRONT_ENABLE(x) (((x) & 0x1) << 11) +#define G_028814_POLY_OFFSET_FRONT_ENABLE(x) (((x) >> 11) & 0x1) +#define C_028814_POLY_OFFSET_FRONT_ENABLE 0xFFFFF7FF +#define S_028814_POLY_OFFSET_BACK_ENABLE(x) (((x) & 0x1) << 12) +#define G_028814_POLY_OFFSET_BACK_ENABLE(x) (((x) >> 12) & 0x1) +#define C_028814_POLY_OFFSET_BACK_ENABLE 0xFFFFEFFF +#define S_028814_POLY_OFFSET_PARA_ENABLE(x) (((x) & 0x1) << 13) +#define G_028814_POLY_OFFSET_PARA_ENABLE(x) (((x) >> 13) & 0x1) +#define C_028814_POLY_OFFSET_PARA_ENABLE 0xFFFFDFFF +#define S_028814_VTX_WINDOW_OFFSET_ENABLE(x) (((x) & 0x1) << 16) +#define G_028814_VTX_WINDOW_OFFSET_ENABLE(x) (((x) >> 16) & 0x1) +#define C_028814_VTX_WINDOW_OFFSET_ENABLE 0xFFFEFFFF +#define S_028814_PROVOKING_VTX_LAST(x) (((x) & 0x1) << 19) +#define G_028814_PROVOKING_VTX_LAST(x) (((x) >> 19) & 0x1) +#define C_028814_PROVOKING_VTX_LAST 0xFFF7FFFF +#define S_028814_PERSP_CORR_DIS(x) (((x) & 0x1) << 20) +#define G_028814_PERSP_CORR_DIS(x) (((x) >> 20) & 0x1) +#define C_028814_PERSP_CORR_DIS 0xFFEFFFFF +#define S_028814_MULTI_PRIM_IB_ENA(x) (((x) & 0x1) << 21) +#define G_028814_MULTI_PRIM_IB_ENA(x) (((x) >> 21) & 0x1) +#define C_028814_MULTI_PRIM_IB_ENA 0xFFDFFFFF +#define R_028000_DB_DEPTH_SIZE 0x028000 +#define S_028000_PITCH_TILE_MAX(x) (((x) & 0x3FF) << 0) +#define G_028000_PITCH_TILE_MAX(x) (((x) >> 0) & 0x3FF) +#define C_028000_PITCH_TILE_MAX 0xFFFFFC00 +#define S_028000_SLICE_TILE_MAX(x) (((x) & 0xFFFFF) << 10) +#define G_028000_SLICE_TILE_MAX(x) (((x) >> 10) & 0xFFFFF) +#define C_028000_SLICE_TILE_MAX 0xC00003FF +#define R_028004_DB_DEPTH_VIEW 0x028004 +#define S_028004_SLICE_START(x) (((x) & 0x7FF) << 0) +#define G_028004_SLICE_START(x) (((x) >> 0) & 0x7FF) +#define C_028004_SLICE_START 0xFFFFF800 +#define S_028004_SLICE_MAX(x) (((x) & 0x7FF) << 13) +#define G_028004_SLICE_MAX(x) (((x) >> 13) & 0x7FF) +#define C_028004_SLICE_MAX 0xFF001FFF +#define R_028D24_DB_HTILE_SURFACE 0x028D24 +#define S_028D24_HTILE_WIDTH(x) (((x) & 0x1) << 0) +#define G_028D24_HTILE_WIDTH(x) (((x) >> 0) & 0x1) +#define C_028D24_HTILE_WIDTH 0xFFFFFFFE +#define S_028D24_HTILE_HEIGHT(x) (((x) & 0x1) << 1) +#define G_028D24_HTILE_HEIGHT(x) (((x) >> 1) & 0x1) +#define C_028D24_HTILE_HEIGHT 0xFFFFFFFD +#define S_028D24_LINEAR(x) (((x) & 0x1) << 2) +#define G_028D24_LINEAR(x) (((x) >> 2) & 0x1) +#define C_028D24_LINEAR 0xFFFFFFFB +#define S_028D24_FULL_CACHE(x) (((x) & 0x1) << 3) +#define G_028D24_FULL_CACHE(x) (((x) >> 3) & 0x1) +#define C_028D24_FULL_CACHE 0xFFFFFFF7 +#define S_028D24_HTILE_USES_PRELOAD_WIN(x) (((x) & 0x1) << 4) +#define G_028D24_HTILE_USES_PRELOAD_WIN(x) (((x) >> 4) & 0x1) +#define C_028D24_HTILE_USES_PRELOAD_WIN 0xFFFFFFEF +#define S_028D24_PRELOAD(x) (((x) & 0x1) << 5) +#define G_028D24_PRELOAD(x) (((x) >> 5) & 0x1) +#define C_028D24_PRELOAD 0xFFFFFFDF +#define S_028D24_PREFETCH_WIDTH(x) (((x) & 0x3F) << 6) +#define G_028D24_PREFETCH_WIDTH(x) (((x) >> 6) & 0x3F) +#define C_028D24_PREFETCH_WIDTH 0xFFFFF03F +#define S_028D24_PREFETCH_HEIGHT(x) (((x) & 0x3F) << 12) +#define G_028D24_PREFETCH_HEIGHT(x) (((x) >> 12) & 0x3F) +#define C_028D24_PREFETCH_HEIGHT 0xFFFC0FFF +#define R_028D34_DB_PREFETCH_LIMIT 0x028D34 +#define S_028D34_DEPTH_HEIGHT_TILE_MAX(x) (((x) & 0x3FF) << 0) +#define G_028D34_DEPTH_HEIGHT_TILE_MAX(x) (((x) >> 0) & 0x3FF) +#define C_028D34_DEPTH_HEIGHT_TILE_MAX 0xFFFFFC00 +#define R_028D0C_DB_RENDER_CONTROL 0x028D0C +#define S_028D0C_DEPTH_CLEAR_ENABLE(x) (((x) & 0x1) << 0) +#define S_028D0C_STENCIL_CLEAR_ENABLE(x) (((x) & 0x1) << 1) +#define S_028D0C_DEPTH_COPY_ENABLE(x) (((x) & 0x1) << 2) +#define S_028D0C_STENCIL_COPY_ENABLE(x) (((x) & 0x1) << 3) +#define S_028D0C_RESUMMARIZE_ENABLE(x) (((x) & 0x1) << 4) +#define S_028D0C_STENCIL_COMPRESS_DISABLE(x) (((x) & 0x1) << 5) +#define S_028D0C_DEPTH_COMPRESS_DISABLE(x) (((x) & 0x1) << 6) +#define S_028D0C_COPY_CENTROID(x) (((x) & 0x1) << 7) +#define S_028D0C_COPY_SAMPLE(x) (((x) & 0x1) << 8) +#define S_028D0C_R700_PERFECT_ZPASS_COUNTS(x) (((x) & 0x1) << 15) +#define R_028D10_DB_RENDER_OVERRIDE 0x028D10 +#define V_028D10_FORCE_OFF 0 +#define V_028D10_FORCE_ENABLE 1 +#define V_028D10_FORCE_DISABLE 2 +#define S_028D10_FORCE_HIZ_ENABLE(x) (((x) & 0x3) << 0) +#define G_028D10_FORCE_HIZ_ENABLE(x) (((x) >> 0) & 0x3) +#define C_028D10_FORCE_HIZ_ENABLE 0xFFFFFFFC +#define S_028D10_FORCE_HIS_ENABLE0(x) (((x) & 0x3) << 2) +#define G_028D10_FORCE_HIS_ENABLE0(x) (((x) >> 2) & 0x3) +#define C_028D10_FORCE_HIS_ENABLE0 0xFFFFFFF3 +#define S_028D10_FORCE_HIS_ENABLE1(x) (((x) & 0x3) << 4) +#define G_028D10_FORCE_HIS_ENABLE1(x) (((x) >> 4) & 0x3) +#define C_028D10_FORCE_HIS_ENABLE1 0xFFFFFFCF +#define S_028D10_FORCE_SHADER_Z_ORDER(x) (((x) & 0x1) << 6) +#define G_028D10_FORCE_SHADER_Z_ORDER(x) (((x) >> 6) & 0x1) +#define C_028D10_FORCE_SHADER_Z_ORDER 0xFFFFFFBF +#define S_028D10_FAST_Z_DISABLE(x) (((x) & 0x1) << 7) +#define G_028D10_FAST_Z_DISABLE(x) (((x) >> 7) & 0x1) +#define C_028D10_FAST_Z_DISABLE 0xFFFFFF7F +#define S_028D10_FAST_STENCIL_DISABLE(x) (((x) & 0x1) << 8) +#define G_028D10_FAST_STENCIL_DISABLE(x) (((x) >> 8) & 0x1) +#define C_028D10_FAST_STENCIL_DISABLE 0xFFFFFEFF +#define S_028D10_NOOP_CULL_DISABLE(x) (((x) & 0x1) << 9) +#define G_028D10_NOOP_CULL_DISABLE(x) (((x) >> 9) & 0x1) +#define C_028D10_NOOP_CULL_DISABLE 0xFFFFFDFF +#define S_028D10_FORCE_COLOR_KILL(x) (((x) & 0x1) << 10) +#define G_028D10_FORCE_COLOR_KILL(x) (((x) >> 10) & 0x1) +#define C_028D10_FORCE_COLOR_KILL 0xFFFFFBFF +#define S_028D10_FORCE_Z_READ(x) (((x) & 0x1) << 11) +#define G_028D10_FORCE_Z_READ(x) (((x) >> 11) & 0x1) +#define C_028D10_FORCE_Z_READ 0xFFFFF7FF +#define S_028D10_FORCE_STENCIL_READ(x) (((x) & 0x1) << 12) +#define G_028D10_FORCE_STENCIL_READ(x) (((x) >> 12) & 0x1) +#define C_028D10_FORCE_STENCIL_READ 0xFFFFEFFF +#define S_028D10_FORCE_FULL_Z_RANGE(x) (((x) & 0x3) << 13) +#define G_028D10_FORCE_FULL_Z_RANGE(x) (((x) >> 13) & 0x3) +#define C_028D10_FORCE_FULL_Z_RANGE 0xFFFF9FFF +#define S_028D10_FORCE_QC_SMASK_CONFLICT(x) (((x) & 0x1) << 15) +#define G_028D10_FORCE_QC_SMASK_CONFLICT(x) (((x) >> 15) & 0x1) +#define C_028D10_FORCE_QC_SMASK_CONFLICT 0xFFFF7FFF +#define S_028D10_DISABLE_VIEWPORT_CLAMP(x) (((x) & 0x1) << 16) +#define G_028D10_DISABLE_VIEWPORT_CLAMP(x) (((x) >> 16) & 0x1) +#define C_028D10_DISABLE_VIEWPORT_CLAMP 0xFFFEFFFF +#define S_028D10_IGNORE_SC_ZRANGE(x) (((x) & 0x1) << 17) +#define G_028D10_IGNORE_SC_ZRANGE(x) (((x) >> 17) & 0x1) +#define C_028D10_IGNORE_SC_ZRANGE 0xFFFDFFFF +#define R_02880C_DB_SHADER_CONTROL 0x02880C +#define S_02880C_Z_EXPORT_ENABLE(x) (((x) & 0x1) << 0) +#define G_02880C_Z_EXPORT_ENABLE(x) (((x) >> 0) & 0x1) +#define C_02880C_Z_EXPORT_ENABLE 0xFFFFFFFE +#define S_02880C_STENCIL_REF_EXPORT_ENABLE(x) (((x) & 0x1) << 1) +#define G_02880C_STENCIL_REF_EXPORT_ENABLE(x) (((x) >> 1) & 0x1) +#define C_02880C_STENCIL_REF_EXPORT_ENABLE 0xFFFFFFFD +#define S_02880C_Z_ORDER(x) (((x) & 0x3) << 4) +#define G_02880C_Z_ORDER(x) (((x) >> 4) & 0x3) +#define C_02880C_Z_ORDER 0xFFFFFCFF +#define V_02880C_LATE_Z 0 +#define V_02880C_EARLY_Z_THEN_LATE_Z 1 +#define V_02880C_RE_Z 2 +#define V_02880C_EARLY_Z_THEN_RE_Z 3 +#define S_02880C_KILL_ENABLE(x) (((x) & 0x1) << 6) +#define G_02880C_KILL_ENABLE(x) (((x) >> 6) & 0x1) +#define C_02880C_KILL_ENABLE 0xFFFFFFBF +#define S_02880C_DUAL_EXPORT_ENABLE(x) (((x) & 0x1) << 9) +#define G_02880C_DUAL_EXPORT_ENABLE(x) (((x) >> 9) & 0x1) +#define C_02880C_DUAL_EXPORT_ENABLE 0xFFFFFDFF +#define R_028DF8_PA_SU_POLY_OFFSET_DB_FMT_CNTL 0x028DF8 +#define S_028DF8_POLY_OFFSET_NEG_NUM_DB_BITS(x) (((x) & 0xFF) << 0) +#define G_028DF8_POLY_OFFSET_NEG_NUM_DB_BITS(x) (((x) >> 0) & 0xFF) +#define C_028DF8_POLY_OFFSET_NEG_NUM_DB_BITS 0xFFFFFF00 +#define S_028DF8_POLY_OFFSET_DB_IS_FLOAT_FMT(x) (((x) & 0x1) << 8) +#define G_028DF8_POLY_OFFSET_DB_IS_FLOAT_FMT(x) (((x) >> 8) & 0x1) +#define C_028DF8_POLY_OFFSET_DB_IS_FLOAT_FMT 0xFFFFFEFF +#define R_028E00_PA_SU_POLY_OFFSET_FRONT_SCALE 0x028E00 +#define S_028E00_SCALE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028E00_SCALE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028E00_SCALE 0x00000000 +#define R_028E04_PA_SU_POLY_OFFSET_FRONT_OFFSET 0x028E04 +#define S_028E04_OFFSET(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028E04_OFFSET(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028E04_OFFSET 0x00000000 +#define R_028E08_PA_SU_POLY_OFFSET_BACK_SCALE 0x028E08 +#define S_028E08_SCALE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028E08_SCALE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028E08_SCALE 0x00000000 +#define R_028E0C_PA_SU_POLY_OFFSET_BACK_OFFSET 0x028E0C +#define S_028E0C_OFFSET(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028E0C_OFFSET(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028E0C_OFFSET 0x00000000 +#define R_028A00_PA_SU_POINT_SIZE 0x028A00 +#define S_028A00_HEIGHT(x) (((x) & 0xFFFF) << 0) +#define G_028A00_HEIGHT(x) (((x) >> 0) & 0xFFFF) +#define C_028A00_HEIGHT 0xFFFF0000 +#define S_028A00_WIDTH(x) (((x) & 0xFFFF) << 16) +#define G_028A00_WIDTH(x) (((x) >> 16) & 0xFFFF) +#define C_028A00_WIDTH 0x0000FFFF +#define R_028A40_VGT_GS_MODE 0x028A40 +#define S_028A40_MODE(x) (((x) & 0x3) << 0) +#define G_028A40_MODE(x) (((x) >> 0) & 0x3) +#define C_028A40_MODE 0xFFFFFFFC +#define S_028A40_ES_PASSTHRU(x) (((x) & 0x1) << 2) +#define G_028A40_ES_PASSTHRU(x) (((x) >> 2) & 0x1) +#define C_028A40_ES_PASSTHRU 0xFFFFFFFB +#define S_028A40_CUT_MODE(x) (((x) & 0x3) << 3) +#define G_028A40_CUT_MODE(x) (((x) >> 3) & 0x3) +#define C_028A40_CUT_MODE 0xFFFFFFE7 +#define R_008040_WAIT_UNTIL 0x008040 +#define S_008040_WAIT_CP_DMA_IDLE(x) (((x) & 0x1) << 8) +#define G_008040_WAIT_CP_DMA_IDLE(x) (((x) >> 8) & 0x1) +#define C_008040_WAIT_CP_DMA_IDLE 0xFFFFFEFF +#define S_008040_WAIT_CMDFIFO(x) (((x) & 0x1) << 10) +#define G_008040_WAIT_CMDFIFO(x) (((x) >> 10) & 0x1) +#define C_008040_WAIT_CMDFIFO 0xFFFFFBFF +#define S_008040_WAIT_2D_IDLE(x) (((x) & 0x1) << 14) +#define G_008040_WAIT_2D_IDLE(x) (((x) >> 14) & 0x1) +#define C_008040_WAIT_2D_IDLE 0xFFFFBFFF +#define S_008040_WAIT_3D_IDLE(x) (((x) & 0x1) << 15) +#define G_008040_WAIT_3D_IDLE(x) (((x) >> 15) & 0x1) +#define C_008040_WAIT_3D_IDLE 0xFFFF7FFF +#define S_008040_WAIT_2D_IDLECLEAN(x) (((x) & 0x1) << 16) +#define G_008040_WAIT_2D_IDLECLEAN(x) (((x) >> 16) & 0x1) +#define C_008040_WAIT_2D_IDLECLEAN 0xFFFEFFFF +#define S_008040_WAIT_3D_IDLECLEAN(x) (((x) & 0x1) << 17) +#define G_008040_WAIT_3D_IDLECLEAN(x) (((x) >> 17) & 0x1) +#define C_008040_WAIT_3D_IDLECLEAN 0xFFFDFFFF +#define S_008040_WAIT_EXTERN_SIG(x) (((x) & 0x1) << 19) +#define G_008040_WAIT_EXTERN_SIG(x) (((x) >> 19) & 0x1) +#define C_008040_WAIT_EXTERN_SIG 0xFFF7FFFF +#define S_008040_CMDFIFO_ENTRIES(x) (((x) & 0x1F) << 20) +#define G_008040_CMDFIFO_ENTRIES(x) (((x) >> 20) & 0x1F) +#define C_008040_CMDFIFO_ENTRIES 0xFE0FFFFF +#define R_0286CC_SPI_PS_IN_CONTROL_0 0x0286CC +#define S_0286CC_NUM_INTERP(x) (((x) & 0x3F) << 0) +#define G_0286CC_NUM_INTERP(x) (((x) >> 0) & 0x3F) +#define C_0286CC_NUM_INTERP 0xFFFFFFC0 +#define S_0286CC_POSITION_ENA(x) (((x) & 0x1) << 8) +#define G_0286CC_POSITION_ENA(x) (((x) >> 8) & 0x1) +#define C_0286CC_POSITION_ENA 0xFFFFFEFF +#define S_0286CC_POSITION_CENTROID(x) (((x) & 0x1) << 9) +#define G_0286CC_POSITION_CENTROID(x) (((x) >> 9) & 0x1) +#define C_0286CC_POSITION_CENTROID 0xFFFFFDFF +#define S_0286CC_POSITION_ADDR(x) (((x) & 0x1F) << 10) +#define G_0286CC_POSITION_ADDR(x) (((x) >> 10) & 0x1F) +#define C_0286CC_POSITION_ADDR 0xFFFF83FF +#define S_0286CC_PARAM_GEN(x) (((x) & 0xF) << 15) +#define G_0286CC_PARAM_GEN(x) (((x) >> 15) & 0xF) +#define C_0286CC_PARAM_GEN 0xFFF87FFF +#define S_0286CC_PARAM_GEN_ADDR(x) (((x) & 0x7F) << 19) +#define G_0286CC_PARAM_GEN_ADDR(x) (((x) >> 19) & 0x7F) +#define C_0286CC_PARAM_GEN_ADDR 0xFC07FFFF +#define S_0286CC_BARYC_SAMPLE_CNTL(x) (((x) & 0x3) << 26) +#define G_0286CC_BARYC_SAMPLE_CNTL(x) (((x) >> 26) & 0x3) +#define C_0286CC_BARYC_SAMPLE_CNTL 0xF3FFFFFF +#define S_0286CC_PERSP_GRADIENT_ENA(x) (((x) & 0x1) << 28) +#define G_0286CC_PERSP_GRADIENT_ENA(x) (((x) >> 28) & 0x1) +#define C_0286CC_PERSP_GRADIENT_ENA 0xEFFFFFFF +#define S_0286CC_LINEAR_GRADIENT_ENA(x) (((x) & 0x1) << 29) +#define G_0286CC_LINEAR_GRADIENT_ENA(x) (((x) >> 29) & 0x1) +#define C_0286CC_LINEAR_GRADIENT_ENA 0xDFFFFFFF +#define S_0286CC_POSITION_SAMPLE(x) (((x) & 0x1) << 30) +#define G_0286CC_POSITION_SAMPLE(x) (((x) >> 30) & 0x1) +#define C_0286CC_POSITION_SAMPLE 0xBFFFFFFF +#define S_0286CC_BARYC_AT_SAMPLE_ENA(x) (((x) & 0x1) << 31) +#define G_0286CC_BARYC_AT_SAMPLE_ENA(x) (((x) >> 31) & 0x1) +#define C_0286CC_BARYC_AT_SAMPLE_ENA 0x7FFFFFFF +#define R_0286D0_SPI_PS_IN_CONTROL_1 0x0286D0 +#define S_0286D0_GEN_INDEX_PIX(x) (((x) & 0x1) << 0) +#define G_0286D0_GEN_INDEX_PIX(x) (((x) >> 0) & 0x1) +#define C_0286D0_GEN_INDEX_PIX 0xFFFFFFFE +#define S_0286D0_GEN_INDEX_PIX_ADDR(x) (((x) & 0x7F) << 1) +#define G_0286D0_GEN_INDEX_PIX_ADDR(x) (((x) >> 1) & 0x7F) +#define C_0286D0_GEN_INDEX_PIX_ADDR 0xFFFFFF01 +#define S_0286D0_FRONT_FACE_ENA(x) (((x) & 0x1) << 8) +#define G_0286D0_FRONT_FACE_ENA(x) (((x) >> 8) & 0x1) +#define C_0286D0_FRONT_FACE_ENA 0xFFFFFEFF +#define S_0286D0_FRONT_FACE_CHAN(x) (((x) & 0x3) << 9) +#define G_0286D0_FRONT_FACE_CHAN(x) (((x) >> 9) & 0x3) +#define C_0286D0_FRONT_FACE_CHAN 0xFFFFF9FF +#define S_0286D0_FRONT_FACE_ALL_BITS(x) (((x) & 0x1) << 11) +#define G_0286D0_FRONT_FACE_ALL_BITS(x) (((x) >> 11) & 0x1) +#define C_0286D0_FRONT_FACE_ALL_BITS 0xFFFFF7FF +#define S_0286D0_FRONT_FACE_ADDR(x) (((x) & 0x1F) << 12) +#define G_0286D0_FRONT_FACE_ADDR(x) (((x) >> 12) & 0x1F) +#define C_0286D0_FRONT_FACE_ADDR 0xFFFE0FFF +#define S_0286D0_FOG_ADDR(x) (((x) & 0x7F) << 17) +#define G_0286D0_FOG_ADDR(x) (((x) >> 17) & 0x7F) +#define C_0286D0_FOG_ADDR 0xFF01FFFF +#define S_0286D0_FIXED_PT_POSITION_ENA(x) (((x) & 0x1) << 24) +#define G_0286D0_FIXED_PT_POSITION_ENA(x) (((x) >> 24) & 0x1) +#define C_0286D0_FIXED_PT_POSITION_ENA 0xFEFFFFFF +#define S_0286D0_FIXED_PT_POSITION_ADDR(x) (((x) & 0x1F) << 25) +#define G_0286D0_FIXED_PT_POSITION_ADDR(x) (((x) >> 25) & 0x1F) +#define C_0286D0_FIXED_PT_POSITION_ADDR 0xC1FFFFFF +#define R_0286C4_SPI_VS_OUT_CONFIG 0x0286C4 +#define S_0286C4_VS_PER_COMPONENT(x) (((x) & 0x1) << 0) +#define G_0286C4_VS_PER_COMPONENT(x) (((x) >> 0) & 0x1) +#define C_0286C4_VS_PER_COMPONENT 0xFFFFFFFE +#define S_0286C4_VS_EXPORT_COUNT(x) (((x) & 0x1F) << 1) +#define G_0286C4_VS_EXPORT_COUNT(x) (((x) >> 1) & 0x1F) +#define C_0286C4_VS_EXPORT_COUNT 0xFFFFFFC1 +#define S_0286C4_VS_EXPORTS_FOG(x) (((x) & 0x1) << 8) +#define G_0286C4_VS_EXPORTS_FOG(x) (((x) >> 8) & 0x1) +#define C_0286C4_VS_EXPORTS_FOG 0xFFFFFEFF +#define S_0286C4_VS_OUT_FOG_VEC_ADDR(x) (((x) & 0x1F) << 9) +#define G_0286C4_VS_OUT_FOG_VEC_ADDR(x) (((x) >> 9) & 0x1F) +#define C_0286C4_VS_OUT_FOG_VEC_ADDR 0xFFFFC1FF +#define R_028240_PA_SC_GENERIC_SCISSOR_TL 0x028240 +#define S_028240_TL_X(x) (((x) & 0x3FFF) << 0) +#define G_028240_TL_X(x) (((x) >> 0) & 0x3FFF) +#define C_028240_TL_X 0xFFFFC000 +#define S_028240_TL_Y(x) (((x) & 0x3FFF) << 16) +#define G_028240_TL_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028240_TL_Y 0xC000FFFF +#define S_028240_WINDOW_OFFSET_DISABLE(x) (((x) & 0x1) << 31) +#define G_028240_WINDOW_OFFSET_DISABLE(x) (((x) >> 31) & 0x1) +#define C_028240_WINDOW_OFFSET_DISABLE 0x7FFFFFFF +#define R_028244_PA_SC_GENERIC_SCISSOR_BR 0x028244 +#define S_028244_BR_X(x) (((x) & 0x3FFF) << 0) +#define G_028244_BR_X(x) (((x) >> 0) & 0x3FFF) +#define C_028244_BR_X 0xFFFFC000 +#define S_028244_BR_Y(x) (((x) & 0x3FFF) << 16) +#define G_028244_BR_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028244_BR_Y 0xC000FFFF +#define R_028030_PA_SC_SCREEN_SCISSOR_TL 0x028030 +#define S_028030_TL_X(x) (((x) & 0x7FFF) << 0) +#define G_028030_TL_X(x) (((x) >> 0) & 0x7FFF) +#define C_028030_TL_X 0xFFFF8000 +#define S_028030_TL_Y(x) (((x) & 0x7FFF) << 16) +#define G_028030_TL_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028030_TL_Y 0x8000FFFF +#define R_028034_PA_SC_SCREEN_SCISSOR_BR 0x028034 +#define S_028034_BR_X(x) (((x) & 0x7FFF) << 0) +#define G_028034_BR_X(x) (((x) >> 0) & 0x7FFF) +#define C_028034_BR_X 0xFFFF8000 +#define S_028034_BR_Y(x) (((x) & 0x7FFF) << 16) +#define G_028034_BR_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028034_BR_Y 0x8000FFFF +#define R_028204_PA_SC_WINDOW_SCISSOR_TL 0x028204 +#define S_028204_TL_X(x) (((x) & 0x3FFF) << 0) +#define G_028204_TL_X(x) (((x) >> 0) & 0x3FFF) +#define C_028204_TL_X 0xFFFFC000 +#define S_028204_TL_Y(x) (((x) & 0x3FFF) << 16) +#define G_028204_TL_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028204_TL_Y 0xC000FFFF +#define S_028204_WINDOW_OFFSET_DISABLE(x) (((x) & 0x1) << 31) +#define G_028204_WINDOW_OFFSET_DISABLE(x) (((x) >> 31) & 0x1) +#define C_028204_WINDOW_OFFSET_DISABLE 0x7FFFFFFF +#define R_028208_PA_SC_WINDOW_SCISSOR_BR 0x028208 +#define S_028208_BR_X(x) (((x) & 0x3FFF) << 0) +#define G_028208_BR_X(x) (((x) >> 0) & 0x3FFF) +#define C_028208_BR_X 0xFFFFC000 +#define S_028208_BR_Y(x) (((x) & 0x3FFF) << 16) +#define G_028208_BR_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028208_BR_Y 0xC000FFFF +#define R_0287F0_VGT_DRAW_INITIATOR 0x0287F0 +#define S_0287F0_SOURCE_SELECT(x) (((x) & 0x3) << 0) +#define G_0287F0_SOURCE_SELECT(x) (((x) >> 0) & 0x3) +#define C_0287F0_SOURCE_SELECT 0xFFFFFFFC +#define V_0287F0_DI_SRC_SEL_DMA 0 +#define V_0287F0_DI_SRC_SEL_AUTO_INDEX 2 +#define S_0287F0_MAJOR_MODE(x) (((x) & 0x3) << 2) +#define G_0287F0_MAJOR_MODE(x) (((x) >> 2) & 0x3) +#define C_0287F0_MAJOR_MODE 0xFFFFFFF3 +#define S_0287F0_SPRITE_EN(x) (((x) & 0x1) << 4) +#define G_0287F0_SPRITE_EN(x) (((x) >> 4) & 0x1) +#define C_0287F0_SPRITE_EN 0xFFFFFFEF +#define S_0287F0_NOT_EOP(x) (((x) & 0x1) << 5) +#define G_0287F0_NOT_EOP(x) (((x) >> 5) & 0x1) +#define C_0287F0_NOT_EOP 0xFFFFFFDF +#define S_0287F0_USE_OPAQUE(x) (((x) & 0x1) << 6) +#define G_0287F0_USE_OPAQUE(x) (((x) >> 6) & 0x1) +#define C_0287F0_USE_OPAQUE 0xFFFFFFBF +#define R_038000_SQ_TEX_RESOURCE_WORD0_0 0x038000 +#define S_038000_DIM(x) (((x) & 0x7) << 0) +#define G_038000_DIM(x) (((x) >> 0) & 0x7) +#define C_038000_DIM 0xFFFFFFF8 +#define V_038000_SQ_TEX_DIM_1D 0x00000000 +#define V_038000_SQ_TEX_DIM_2D 0x00000001 +#define V_038000_SQ_TEX_DIM_3D 0x00000002 +#define V_038000_SQ_TEX_DIM_CUBEMAP 0x00000003 +#define V_038000_SQ_TEX_DIM_1D_ARRAY 0x00000004 +#define V_038000_SQ_TEX_DIM_2D_ARRAY 0x00000005 +#define V_038000_SQ_TEX_DIM_2D_MSAA 0x00000006 +#define V_038000_SQ_TEX_DIM_2D_ARRAY_MSAA 0x00000007 +#define S_038000_TILE_MODE(x) (((x) & 0xF) << 3) +#define G_038000_TILE_MODE(x) (((x) >> 3) & 0xF) +#define C_038000_TILE_MODE 0xFFFFFF87 +#define V_038000_ARRAY_LINEAR_GENERAL 0x00000000 +#define V_038000_ARRAY_LINEAR_ALIGNED 0x00000001 +#define V_038000_ARRAY_1D_TILED_THIN1 0x00000002 +#define V_038000_ARRAY_2D_TILED_THIN1 0x00000004 +#define S_038000_TILE_TYPE(x) (((x) & 0x1) << 7) +#define G_038000_TILE_TYPE(x) (((x) >> 7) & 0x1) +#define C_038000_TILE_TYPE 0xFFFFFF7F +#define S_038000_PITCH(x) (((x) & 0x7FF) << 8) +#define G_038000_PITCH(x) (((x) >> 8) & 0x7FF) +#define C_038000_PITCH 0xFFF800FF +#define S_038000_TEX_WIDTH(x) (((x) & 0x1FFF) << 19) +#define G_038000_TEX_WIDTH(x) (((x) >> 19) & 0x1FFF) +#define C_038000_TEX_WIDTH 0x0007FFFF +#define R_038004_SQ_TEX_RESOURCE_WORD1_0 0x038004 +#define S_038004_TEX_HEIGHT(x) (((x) & 0x1FFF) << 0) +#define G_038004_TEX_HEIGHT(x) (((x) >> 0) & 0x1FFF) +#define C_038004_TEX_HEIGHT 0xFFFFE000 +#define S_038004_TEX_DEPTH(x) (((x) & 0x1FFF) << 13) +#define G_038004_TEX_DEPTH(x) (((x) >> 13) & 0x1FFF) +#define C_038004_TEX_DEPTH 0xFC001FFF +#define S_038004_DATA_FORMAT(x) (((x) & 0x3F) << 26) +#define G_038004_DATA_FORMAT(x) (((x) >> 26) & 0x3F) +#define C_038004_DATA_FORMAT 0x03FFFFFF +#define R_038008_SQ_TEX_RESOURCE_WORD2_0 0x038008 +#define S_038008_BASE_ADDRESS(x) (((x) & 0xFFFFFFFF) << 0) +#define G_038008_BASE_ADDRESS(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_038008_BASE_ADDRESS 0x00000000 +#define R_03800C_SQ_TEX_RESOURCE_WORD3_0 0x03800C +#define S_03800C_MIP_ADDRESS(x) (((x) & 0xFFFFFFFF) << 0) +#define G_03800C_MIP_ADDRESS(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_03800C_MIP_ADDRESS 0x00000000 +#define R_038010_SQ_TEX_RESOURCE_WORD4_0 0x038010 +#define S_038010_FORMAT_COMP_X(x) (((x) & 0x3) << 0) +#define G_038010_FORMAT_COMP_X(x) (((x) >> 0) & 0x3) +#define C_038010_FORMAT_COMP_X 0xFFFFFFFC +#define V_038010_SQ_FORMAT_COMP_UNSIGNED 0x00000000 +#define V_038010_SQ_FORMAT_COMP_SIGNED 0x00000001 +#define V_038010_SQ_FORMAT_COMP_UNSIGNED_BIASED 0x00000002 +#define S_038010_FORMAT_COMP_Y(x) (((x) & 0x3) << 2) +#define G_038010_FORMAT_COMP_Y(x) (((x) >> 2) & 0x3) +#define C_038010_FORMAT_COMP_Y 0xFFFFFFF3 +#define S_038010_FORMAT_COMP_Z(x) (((x) & 0x3) << 4) +#define G_038010_FORMAT_COMP_Z(x) (((x) >> 4) & 0x3) +#define C_038010_FORMAT_COMP_Z 0xFFFFFFCF +#define S_038010_FORMAT_COMP_W(x) (((x) & 0x3) << 6) +#define G_038010_FORMAT_COMP_W(x) (((x) >> 6) & 0x3) +#define C_038010_FORMAT_COMP_W 0xFFFFFF3F +#define S_038010_NUM_FORMAT_ALL(x) (((x) & 0x3) << 8) +#define G_038010_NUM_FORMAT_ALL(x) (((x) >> 8) & 0x3) +#define C_038010_NUM_FORMAT_ALL 0xFFFFFCFF +#define V_038010_SQ_NUM_FORMAT_NORM 0x00000000 +#define V_038010_SQ_NUM_FORMAT_INT 0x00000001 +#define V_038010_SQ_NUM_FORMAT_SCALED 0x00000002 +#define S_038010_SRF_MODE_ALL(x) (((x) & 0x1) << 10) +#define G_038010_SRF_MODE_ALL(x) (((x) >> 10) & 0x1) +#define C_038010_SRF_MODE_ALL 0xFFFFFBFF +#define V_038010_SFR_MODE_ZERO_CLAMP_MINUS_ONE 0x00000000 +#define V_038010_SFR_MODE_NO_ZERO 0x00000001 +#define S_038010_FORCE_DEGAMMA(x) (((x) & 0x1) << 11) +#define G_038010_FORCE_DEGAMMA(x) (((x) >> 11) & 0x1) +#define C_038010_FORCE_DEGAMMA 0xFFFFF7FF +#define S_038010_ENDIAN_SWAP(x) (((x) & 0x3) << 12) +#define G_038010_ENDIAN_SWAP(x) (((x) >> 12) & 0x3) +#define C_038010_ENDIAN_SWAP 0xFFFFCFFF +#define S_038010_REQUEST_SIZE(x) (((x) & 0x3) << 14) +#define G_038010_REQUEST_SIZE(x) (((x) >> 14) & 0x3) +#define C_038010_REQUEST_SIZE 0xFFFF3FFF +#define S_038010_DST_SEL_X(x) (((x) & 0x7) << 16) +#define G_038010_DST_SEL_X(x) (((x) >> 16) & 0x7) +#define C_038010_DST_SEL_X 0xFFF8FFFF +#define V_038010_SQ_SEL_X 0x00000000 +#define V_038010_SQ_SEL_Y 0x00000001 +#define V_038010_SQ_SEL_Z 0x00000002 +#define V_038010_SQ_SEL_W 0x00000003 +#define V_038010_SQ_SEL_0 0x00000004 +#define V_038010_SQ_SEL_1 0x00000005 +#define S_038010_DST_SEL_Y(x) (((x) & 0x7) << 19) +#define G_038010_DST_SEL_Y(x) (((x) >> 19) & 0x7) +#define C_038010_DST_SEL_Y 0xFFC7FFFF +#define S_038010_DST_SEL_Z(x) (((x) & 0x7) << 22) +#define G_038010_DST_SEL_Z(x) (((x) >> 22) & 0x7) +#define C_038010_DST_SEL_Z 0xFE3FFFFF +#define S_038010_DST_SEL_W(x) (((x) & 0x7) << 25) +#define G_038010_DST_SEL_W(x) (((x) >> 25) & 0x7) +#define C_038010_DST_SEL_W 0xF1FFFFFF +#define S_038010_BASE_LEVEL(x) (((x) & 0xF) << 28) +#define G_038010_BASE_LEVEL(x) (((x) >> 28) & 0xF) +#define C_038010_BASE_LEVEL 0x0FFFFFFF +#define R_038014_SQ_TEX_RESOURCE_WORD5_0 0x038014 +#define S_038014_LAST_LEVEL(x) (((x) & 0xF) << 0) +#define G_038014_LAST_LEVEL(x) (((x) >> 0) & 0xF) +#define C_038014_LAST_LEVEL 0xFFFFFFF0 +#define S_038014_BASE_ARRAY(x) (((x) & 0x1FFF) << 4) +#define G_038014_BASE_ARRAY(x) (((x) >> 4) & 0x1FFF) +#define C_038014_BASE_ARRAY 0xFFFE000F +#define S_038014_LAST_ARRAY(x) (((x) & 0x1FFF) << 17) +#define G_038014_LAST_ARRAY(x) (((x) >> 17) & 0x1FFF) +#define C_038014_LAST_ARRAY 0xC001FFFF +#define R_038018_SQ_TEX_RESOURCE_WORD6_0 0x038018 +#define S_038018_MPEG_CLAMP(x) (((x) & 0x3) << 0) +#define G_038018_MPEG_CLAMP(x) (((x) >> 0) & 0x3) +#define C_038018_MPEG_CLAMP 0xFFFFFFFC +#define S_038018_PERF_MODULATION(x) (((x) & 0x7) << 5) +#define G_038018_PERF_MODULATION(x) (((x) >> 5) & 0x7) +#define C_038018_PERF_MODULATION 0xFFFFFF1F +#define S_038018_INTERLACED(x) (((x) & 0x1) << 8) +#define G_038018_INTERLACED(x) (((x) >> 8) & 0x1) +#define C_038018_INTERLACED 0xFFFFFEFF +#define S_038018_TYPE(x) (((x) & 0x3) << 30) +#define G_038018_TYPE(x) (((x) >> 30) & 0x3) +#define C_038018_TYPE 0x3FFFFFFF +#define V_038010_SQ_TEX_VTX_INVALID_TEXTURE 0x00000000 +#define V_038010_SQ_TEX_VTX_INVALID_BUFFER 0x00000001 +#define V_038010_SQ_TEX_VTX_VALID_TEXTURE 0x00000002 +#define V_038010_SQ_TEX_VTX_VALID_BUFFER 0x00000003 +#define R_038008_SQ_VTX_CONSTANT_WORD2_0 0x038008 +#define S_038008_BASE_ADDRESS_HI(x) (((x) & 0xFF) << 0) +#define G_038008_BASE_ADDRESS_HI(x) (((x) >> 0) & 0xFF) +#define C_038008_BASE_ADDRESS_HI 0xFFFFFF00 +#define S_038008_STRIDE(x) (((x) & 0x7FF) << 8) +#define G_038008_STRIDE(x) (((x) >> 8) & 0x7FF) +#define C_038008_STRIDE 0xFFF800FF +#define S_038008_CLAMP_X(x) (((x) & 0x1) << 19) +#define G_038008_CLAMP_X(x) (((x) >> 19) & 0x1) +#define C_038008_CLAMP_X 0xFFF7FFFF +#define S_038008_DATA_FORMAT(x) (((x) & 0x3F) << 20) +#define G_038008_DATA_FORMAT(x) (((x) >> 20) & 0x3F) +#define C_038008_DATA_FORMAT 0xFC0FFFFF + +#define S_038008_NUM_FORMAT_ALL(x) (((x) & 0x3) << 26) +#define G_038008_NUM_FORMAT_ALL(x) (((x) >> 26) & 0x3) +#define C_038008_NUM_FORMAT_ALL 0xF3FFFFFF +#define V_038008_SQ_NUM_FORMAT_NORM 0x00000000 +#define V_038008_SQ_NUM_FORMAT_INT 0x00000001 +#define V_038008_SQ_NUM_FORMAT_SCALED 0x00000002 +#define S_038008_FORMAT_COMP_ALL(x) (((x) & 0x1) << 28) +#define G_038008_FORMAT_COMP_ALL(x) (((x) >> 28) & 0x1) +#define C_038008_FORMAT_COMP_ALL 0xEFFFFFFF +#define S_038008_SRF_MODE_ALL(x) (((x) & 0x1) << 29) +#define G_038008_SRF_MODE_ALL(x) (((x) >> 29) & 0x1) +#define C_038008_SRF_MODE_ALL 0xDFFFFFFF +#define S_038008_ENDIAN_SWAP(x) (((x) & 0x3) << 30) +#define G_038008_ENDIAN_SWAP(x) (((x) >> 30) & 0x3) +#define C_038008_ENDIAN_SWAP 0x3FFFFFFF +#define R_03C000_SQ_TEX_SAMPLER_WORD0_0 0x03C000 +#define S_03C000_CLAMP_X(x) (((x) & 0x7) << 0) +#define G_03C000_CLAMP_X(x) (((x) >> 0) & 0x7) +#define C_03C000_CLAMP_X 0xFFFFFFF8 +#define V_03C000_SQ_TEX_WRAP 0x00000000 +#define V_03C000_SQ_TEX_MIRROR 0x00000001 +#define V_03C000_SQ_TEX_CLAMP_LAST_TEXEL 0x00000002 +#define V_03C000_SQ_TEX_MIRROR_ONCE_LAST_TEXEL 0x00000003 +#define V_03C000_SQ_TEX_CLAMP_HALF_BORDER 0x00000004 +#define V_03C000_SQ_TEX_MIRROR_ONCE_HALF_BORDER 0x00000005 +#define V_03C000_SQ_TEX_CLAMP_BORDER 0x00000006 +#define V_03C000_SQ_TEX_MIRROR_ONCE_BORDER 0x00000007 +#define S_03C000_CLAMP_Y(x) (((x) & 0x7) << 3) +#define G_03C000_CLAMP_Y(x) (((x) >> 3) & 0x7) +#define C_03C000_CLAMP_Y 0xFFFFFFC7 +#define S_03C000_CLAMP_Z(x) (((x) & 0x7) << 6) +#define G_03C000_CLAMP_Z(x) (((x) >> 6) & 0x7) +#define C_03C000_CLAMP_Z 0xFFFFFE3F +#define S_03C000_XY_MAG_FILTER(x) (((x) & 0x7) << 9) +#define G_03C000_XY_MAG_FILTER(x) (((x) >> 9) & 0x7) +#define C_03C000_XY_MAG_FILTER 0xFFFFF1FF +#define V_03C000_SQ_TEX_XY_FILTER_POINT 0x00000000 +#define V_03C000_SQ_TEX_XY_FILTER_BILINEAR 0x00000001 +#define V_03C000_SQ_TEX_XY_FILTER_BICUBIC 0x00000002 +#define S_03C000_XY_MIN_FILTER(x) (((x) & 0x7) << 12) +#define G_03C000_XY_MIN_FILTER(x) (((x) >> 12) & 0x7) +#define C_03C000_XY_MIN_FILTER 0xFFFF8FFF +#define S_03C000_Z_FILTER(x) (((x) & 0x3) << 15) +#define G_03C000_Z_FILTER(x) (((x) >> 15) & 0x3) +#define C_03C000_Z_FILTER 0xFFFE7FFF +#define V_03C000_SQ_TEX_Z_FILTER_NONE 0x00000000 +#define V_03C000_SQ_TEX_Z_FILTER_POINT 0x00000001 +#define V_03C000_SQ_TEX_Z_FILTER_LINEAR 0x00000002 +#define S_03C000_MIP_FILTER(x) (((x) & 0x3) << 17) +#define G_03C000_MIP_FILTER(x) (((x) >> 17) & 0x3) +#define C_03C000_MIP_FILTER 0xFFF9FFFF +#define S_03C000_BORDER_COLOR_TYPE(x) (((x) & 0x3) << 22) +#define G_03C000_BORDER_COLOR_TYPE(x) (((x) >> 22) & 0x3) +#define C_03C000_BORDER_COLOR_TYPE 0xFF3FFFFF +#define V_03C000_SQ_TEX_BORDER_COLOR_TRANS_BLACK 0x00000000 +#define V_03C000_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK 0x00000001 +#define V_03C000_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE 0x00000002 +#define V_03C000_SQ_TEX_BORDER_COLOR_REGISTER 0x00000003 +#define S_03C000_POINT_SAMPLING_CLAMP(x) (((x) & 0x1) << 24) +#define G_03C000_POINT_SAMPLING_CLAMP(x) (((x) >> 24) & 0x1) +#define C_03C000_POINT_SAMPLING_CLAMP 0xFEFFFFFF +#define S_03C000_TEX_ARRAY_OVERRIDE(x) (((x) & 0x1) << 25) +#define G_03C000_TEX_ARRAY_OVERRIDE(x) (((x) >> 25) & 0x1) +#define C_03C000_TEX_ARRAY_OVERRIDE 0xFDFFFFFF +#define S_03C000_DEPTH_COMPARE_FUNCTION(x) (((x) & 0x7) << 26) +#define G_03C000_DEPTH_COMPARE_FUNCTION(x) (((x) >> 26) & 0x7) +#define C_03C000_DEPTH_COMPARE_FUNCTION 0xE3FFFFFF +#define V_03C000_SQ_TEX_DEPTH_COMPARE_NEVER 0x00000000 +#define V_03C000_SQ_TEX_DEPTH_COMPARE_LESS 0x00000001 +#define V_03C000_SQ_TEX_DEPTH_COMPARE_EQUAL 0x00000002 +#define V_03C000_SQ_TEX_DEPTH_COMPARE_LESSEQUAL 0x00000003 +#define V_03C000_SQ_TEX_DEPTH_COMPARE_GREATER 0x00000004 +#define V_03C000_SQ_TEX_DEPTH_COMPARE_NOTEQUAL 0x00000005 +#define V_03C000_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL 0x00000006 +#define V_03C000_SQ_TEX_DEPTH_COMPARE_ALWAYS 0x00000007 +#define S_03C000_CHROMA_KEY(x) (((x) & 0x3) << 29) +#define G_03C000_CHROMA_KEY(x) (((x) >> 29) & 0x3) +#define C_03C000_CHROMA_KEY 0x9FFFFFFF +#define V_03C000_SQ_TEX_CHROMA_KEY_DISABLE 0x00000000 +#define V_03C000_SQ_TEX_CHROMA_KEY_KILL 0x00000001 +#define V_03C000_SQ_TEX_CHROMA_KEY_BLEND 0x00000002 +#define S_03C000_LOD_USES_MINOR_AXIS(x) (((x) & 0x1) << 31) +#define G_03C000_LOD_USES_MINOR_AXIS(x) (((x) >> 31) & 0x1) +#define C_03C000_LOD_USES_MINOR_AXIS 0x7FFFFFFF +#define R_03C004_SQ_TEX_SAMPLER_WORD1_0 0x03C004 +#define S_03C004_MIN_LOD(x) (((x) & 0x3FF) << 0) +#define G_03C004_MIN_LOD(x) (((x) >> 0) & 0x3FF) +#define C_03C004_MIN_LOD 0xFFFFFC00 +#define S_03C004_MAX_LOD(x) (((x) & 0x3FF) << 10) +#define G_03C004_MAX_LOD(x) (((x) >> 10) & 0x3FF) +#define C_03C004_MAX_LOD 0xFFF003FF +#define S_03C004_LOD_BIAS(x) (((x) & 0xFFF) << 20) +#define G_03C004_LOD_BIAS(x) (((x) >> 20) & 0xFFF) +#define C_03C004_LOD_BIAS 0x000FFFFF +#define R_03C008_SQ_TEX_SAMPLER_WORD2_0 0x03C008 +#define S_03C008_LOD_BIAS_SEC(x) (((x) & 0xFFF) << 0) +#define G_03C008_LOD_BIAS_SEC(x) (((x) >> 0) & 0xFFF) +#define C_03C008_LOD_BIAS_SEC 0xFFFFF000 +#define S_03C008_MC_COORD_TRUNCATE(x) (((x) & 0x1) << 12) +#define G_03C008_MC_COORD_TRUNCATE(x) (((x) >> 12) & 0x1) +#define C_03C008_MC_COORD_TRUNCATE 0xFFFFEFFF +#define S_03C008_FORCE_DEGAMMA(x) (((x) & 0x1) << 13) +#define G_03C008_FORCE_DEGAMMA(x) (((x) >> 13) & 0x1) +#define C_03C008_FORCE_DEGAMMA 0xFFFFDFFF +#define S_03C008_HIGH_PRECISION_FILTER(x) (((x) & 0x1) << 14) +#define G_03C008_HIGH_PRECISION_FILTER(x) (((x) >> 14) & 0x1) +#define C_03C008_HIGH_PRECISION_FILTER 0xFFFFBFFF +#define S_03C008_PERF_MIP(x) (((x) & 0x7) << 15) +#define G_03C008_PERF_MIP(x) (((x) >> 15) & 0x7) +#define C_03C008_PERF_MIP 0xFFFC7FFF +#define S_03C008_PERF_Z(x) (((x) & 0x3) << 18) +#define G_03C008_PERF_Z(x) (((x) >> 18) & 0x3) +#define C_03C008_PERF_Z 0xFFF3FFFF +#define S_03C008_FETCH_4(x) (((x) & 0x1) << 26) +#define G_03C008_FETCH_4(x) (((x) >> 26) & 0x1) +#define C_03C008_FETCH_4 0xFBFFFFFF +#define S_03C008_SAMPLE_IS_PCF(x) (((x) & 0x1) << 27) +#define G_03C008_SAMPLE_IS_PCF(x) (((x) >> 27) & 0x1) +#define C_03C008_SAMPLE_IS_PCF 0xF7FFFFFF +#define S_03C008_TYPE(x) (((x) & 0x1) << 31) +#define G_03C008_TYPE(x) (((x) >> 31) & 0x1) +#define C_03C008_TYPE 0x7FFFFFFF +#define R_008958_VGT_PRIMITIVE_TYPE 0x008958 +#define S_008958_PRIM_TYPE(x) (((x) & 0x3F) << 0) +#define G_008958_PRIM_TYPE(x) (((x) >> 0) & 0x3F) +#define C_008958_PRIM_TYPE 0xFFFFFFC0 +#define V_008958_DI_PT_NONE 0x00000000 +#define V_008958_DI_PT_POINTLIST 0x00000001 +#define V_008958_DI_PT_LINELIST 0x00000002 +#define V_008958_DI_PT_LINESTRIP 0x00000003 +#define V_008958_DI_PT_TRILIST 0x00000004 +#define V_008958_DI_PT_TRIFAN 0x00000005 +#define V_008958_DI_PT_TRISTRIP 0x00000006 +#define V_008958_DI_PT_UNUSED_0 0x00000007 +#define V_008958_DI_PT_UNUSED_1 0x00000008 +#define V_008958_DI_PT_UNUSED_2 0x00000009 +#define V_008958_DI_PT_LINELIST_ADJ 0x0000000A +#define V_008958_DI_PT_LINESTRIP_ADJ 0x0000000B +#define V_008958_DI_PT_TRILIST_ADJ 0x0000000C +#define V_008958_DI_PT_TRISTRIP_ADJ 0x0000000D +#define V_008958_DI_PT_UNUSED_3 0x0000000E +#define V_008958_DI_PT_UNUSED_4 0x0000000F +#define V_008958_DI_PT_TRI_WITH_WFLAGS 0x00000010 +#define V_008958_DI_PT_RECTLIST 0x00000011 +#define V_008958_DI_PT_LINELOOP 0x00000012 +#define V_008958_DI_PT_QUADLIST 0x00000013 +#define V_008958_DI_PT_QUADSTRIP 0x00000014 +#define V_008958_DI_PT_POLYGON 0x00000015 +#define V_008958_DI_PT_2D_COPY_RECT_LIST_V0 0x00000016 +#define V_008958_DI_PT_2D_COPY_RECT_LIST_V1 0x00000017 +#define V_008958_DI_PT_2D_COPY_RECT_LIST_V2 0x00000018 +#define V_008958_DI_PT_2D_COPY_RECT_LIST_V3 0x00000019 +#define V_008958_DI_PT_2D_FILL_RECT_LIST 0x0000001A +#define V_008958_DI_PT_2D_LINE_STRIP 0x0000001B +#define V_008958_DI_PT_2D_TRI_STRIP 0x0000001C +#define R_02881C_PA_CL_VS_OUT_CNTL 0x02881C +#define S_02881C_CLIP_DIST_ENA_0(x) (((x) & 0x1) << 0) +#define G_02881C_CLIP_DIST_ENA_0(x) (((x) >> 0) & 0x1) +#define C_02881C_CLIP_DIST_ENA_0 0xFFFFFFFE +#define S_02881C_CLIP_DIST_ENA_1(x) (((x) & 0x1) << 1) +#define G_02881C_CLIP_DIST_ENA_1(x) (((x) >> 1) & 0x1) +#define C_02881C_CLIP_DIST_ENA_1 0xFFFFFFFD +#define S_02881C_CLIP_DIST_ENA_2(x) (((x) & 0x1) << 2) +#define G_02881C_CLIP_DIST_ENA_2(x) (((x) >> 2) & 0x1) +#define C_02881C_CLIP_DIST_ENA_2 0xFFFFFFFB +#define S_02881C_CLIP_DIST_ENA_3(x) (((x) & 0x1) << 3) +#define G_02881C_CLIP_DIST_ENA_3(x) (((x) >> 3) & 0x1) +#define C_02881C_CLIP_DIST_ENA_3 0xFFFFFFF7 +#define S_02881C_CLIP_DIST_ENA_4(x) (((x) & 0x1) << 4) +#define G_02881C_CLIP_DIST_ENA_4(x) (((x) >> 4) & 0x1) +#define C_02881C_CLIP_DIST_ENA_4 0xFFFFFFEF +#define S_02881C_CLIP_DIST_ENA_5(x) (((x) & 0x1) << 5) +#define G_02881C_CLIP_DIST_ENA_5(x) (((x) >> 5) & 0x1) +#define C_02881C_CLIP_DIST_ENA_5 0xFFFFFFDF +#define S_02881C_CLIP_DIST_ENA_6(x) (((x) & 0x1) << 6) +#define G_02881C_CLIP_DIST_ENA_6(x) (((x) >> 6) & 0x1) +#define C_02881C_CLIP_DIST_ENA_6 0xFFFFFFBF +#define S_02881C_CLIP_DIST_ENA_7(x) (((x) & 0x1) << 7) +#define G_02881C_CLIP_DIST_ENA_7(x) (((x) >> 7) & 0x1) +#define C_02881C_CLIP_DIST_ENA_7 0xFFFFFF7F +#define S_02881C_CULL_DIST_ENA_0(x) (((x) & 0x1) << 8) +#define G_02881C_CULL_DIST_ENA_0(x) (((x) >> 8) & 0x1) +#define C_02881C_CULL_DIST_ENA_0 0xFFFFFEFF +#define S_02881C_CULL_DIST_ENA_1(x) (((x) & 0x1) << 9) +#define G_02881C_CULL_DIST_ENA_1(x) (((x) >> 9) & 0x1) +#define C_02881C_CULL_DIST_ENA_1 0xFFFFFDFF +#define S_02881C_CULL_DIST_ENA_2(x) (((x) & 0x1) << 10) +#define G_02881C_CULL_DIST_ENA_2(x) (((x) >> 10) & 0x1) +#define C_02881C_CULL_DIST_ENA_2 0xFFFFFBFF +#define S_02881C_CULL_DIST_ENA_3(x) (((x) & 0x1) << 11) +#define G_02881C_CULL_DIST_ENA_3(x) (((x) >> 11) & 0x1) +#define C_02881C_CULL_DIST_ENA_3 0xFFFFF7FF +#define S_02881C_CULL_DIST_ENA_4(x) (((x) & 0x1) << 12) +#define G_02881C_CULL_DIST_ENA_4(x) (((x) >> 12) & 0x1) +#define C_02881C_CULL_DIST_ENA_4 0xFFFFEFFF +#define S_02881C_CULL_DIST_ENA_5(x) (((x) & 0x1) << 13) +#define G_02881C_CULL_DIST_ENA_5(x) (((x) >> 13) & 0x1) +#define C_02881C_CULL_DIST_ENA_5 0xFFFFDFFF +#define S_02881C_CULL_DIST_ENA_6(x) (((x) & 0x1) << 14) +#define G_02881C_CULL_DIST_ENA_6(x) (((x) >> 14) & 0x1) +#define C_02881C_CULL_DIST_ENA_6 0xFFFFBFFF +#define S_02881C_CULL_DIST_ENA_7(x) (((x) & 0x1) << 15) +#define G_02881C_CULL_DIST_ENA_7(x) (((x) >> 15) & 0x1) +#define C_02881C_CULL_DIST_ENA_7 0xFFFF7FFF +#define S_02881C_USE_VTX_POINT_SIZE(x) (((x) & 0x1) << 16) +#define G_02881C_USE_VTX_POINT_SIZE(x) (((x) >> 16) & 0x1) +#define C_02881C_USE_VTX_POINT_SIZE 0xFFFEFFFF +#define S_02881C_USE_VTX_EDGE_FLAG(x) (((x) & 0x1) << 17) +#define G_02881C_USE_VTX_EDGE_FLAG(x) (((x) >> 17) & 0x1) +#define C_02881C_USE_VTX_EDGE_FLAG 0xFFFDFFFF +#define S_02881C_USE_VTX_RENDER_TARGET_INDX(x) (((x) & 0x1) << 18) +#define G_02881C_USE_VTX_RENDER_TARGET_INDX(x) (((x) >> 18) & 0x1) +#define C_02881C_USE_VTX_RENDER_TARGET_INDX 0xFFFBFFFF +#define S_02881C_USE_VTX_VIEWPORT_INDX(x) (((x) & 0x1) << 19) +#define G_02881C_USE_VTX_VIEWPORT_INDX(x) (((x) >> 19) & 0x1) +#define C_02881C_USE_VTX_VIEWPORT_INDX 0xFFF7FFFF +#define S_02881C_USE_VTX_KILL_FLAG(x) (((x) & 0x1) << 20) +#define G_02881C_USE_VTX_KILL_FLAG(x) (((x) >> 20) & 0x1) +#define C_02881C_USE_VTX_KILL_FLAG 0xFFEFFFFF +#define S_02881C_VS_OUT_MISC_VEC_ENA(x) (((x) & 0x1) << 21) +#define G_02881C_VS_OUT_MISC_VEC_ENA(x) (((x) >> 21) & 0x1) +#define C_02881C_VS_OUT_MISC_VEC_ENA 0xFFDFFFFF +#define S_02881C_VS_OUT_CCDIST0_VEC_ENA(x) (((x) & 0x1) << 22) +#define G_02881C_VS_OUT_CCDIST0_VEC_ENA(x) (((x) >> 22) & 0x1) +#define C_02881C_VS_OUT_CCDIST0_VEC_ENA 0xFFBFFFFF +#define S_02881C_VS_OUT_CCDIST1_VEC_ENA(x) (((x) & 0x1) << 23) +#define G_02881C_VS_OUT_CCDIST1_VEC_ENA(x) (((x) >> 23) & 0x1) +#define C_02881C_VS_OUT_CCDIST1_VEC_ENA 0xFF7FFFFF +#define R_028868_SQ_PGM_RESOURCES_VS 0x028868 +#define S_028868_NUM_GPRS(x) (((x) & 0xFF) << 0) +#define G_028868_NUM_GPRS(x) (((x) >> 0) & 0xFF) +#define C_028868_NUM_GPRS 0xFFFFFF00 +#define S_028868_STACK_SIZE(x) (((x) & 0xFF) << 8) +#define G_028868_STACK_SIZE(x) (((x) >> 8) & 0xFF) +#define C_028868_STACK_SIZE 0xFFFF00FF +#define S_028868_DX10_CLAMP(x) (((x) & 0x1) << 21) +#define G_028868_DX10_CLAMP(x) (((x) >> 21) & 0x1) +#define C_028868_DX10_CLAMP 0xFFDFFFFF +#define S_028868_FETCH_CACHE_LINES(x) (((x) & 0x7) << 24) +#define G_028868_FETCH_CACHE_LINES(x) (((x) >> 24) & 0x7) +#define C_028868_FETCH_CACHE_LINES 0xF8FFFFFF +#define S_028868_UNCACHED_FIRST_INST(x) (((x) & 0x1) << 28) +#define G_028868_UNCACHED_FIRST_INST(x) (((x) >> 28) & 0x1) +#define C_028868_UNCACHED_FIRST_INST 0xEFFFFFFF +#define R_028850_SQ_PGM_RESOURCES_PS 0x028850 +#define S_028850_NUM_GPRS(x) (((x) & 0xFF) << 0) +#define G_028850_NUM_GPRS(x) (((x) >> 0) & 0xFF) +#define C_028850_NUM_GPRS 0xFFFFFF00 +#define S_028850_STACK_SIZE(x) (((x) & 0xFF) << 8) +#define G_028850_STACK_SIZE(x) (((x) >> 8) & 0xFF) +#define C_028850_STACK_SIZE 0xFFFF00FF +#define S_028850_DX10_CLAMP(x) (((x) & 0x1) << 21) +#define G_028850_DX10_CLAMP(x) (((x) >> 21) & 0x1) +#define C_028850_DX10_CLAMP 0xFFDFFFFF +#define S_028850_FETCH_CACHE_LINES(x) (((x) & 0x7) << 24) +#define G_028850_FETCH_CACHE_LINES(x) (((x) >> 24) & 0x7) +#define C_028850_FETCH_CACHE_LINES 0xF8FFFFFF +#define S_028850_UNCACHED_FIRST_INST(x) (((x) & 0x1) << 28) +#define G_028850_UNCACHED_FIRST_INST(x) (((x) >> 28) & 0x1) +#define C_028850_UNCACHED_FIRST_INST 0xEFFFFFFF +#define S_028850_CLAMP_CONSTS(x) (((x) & 0x1) << 31) +#define G_028850_CLAMP_CONSTS(x) (((x) >> 31) & 0x1) +#define C_028850_CLAMP_CONSTS 0x7FFFFFFF +#define R_028644_SPI_PS_INPUT_CNTL_0 0x028644 +#define S_028644_SEMANTIC(x) (((x) & 0xFF) << 0) +#define G_028644_SEMANTIC(x) (((x) >> 0) & 0xFF) +#define C_028644_SEMANTIC 0xFFFFFF00 +#define S_028644_DEFAULT_VAL(x) (((x) & 0x3) << 8) +#define G_028644_DEFAULT_VAL(x) (((x) >> 8) & 0x3) +#define C_028644_DEFAULT_VAL 0xFFFFFCFF +#define S_028644_FLAT_SHADE(x) (((x) & 0x1) << 10) +#define G_028644_FLAT_SHADE(x) (((x) >> 10) & 0x1) +#define C_028644_FLAT_SHADE 0xFFFFFBFF +#define S_028644_SEL_CENTROID(x) (((x) & 0x1) << 11) +#define G_028644_SEL_CENTROID(x) (((x) >> 11) & 0x1) +#define C_028644_SEL_CENTROID 0xFFFFF7FF +#define S_028644_SEL_LINEAR(x) (((x) & 0x1) << 12) +#define G_028644_SEL_LINEAR(x) (((x) >> 12) & 0x1) +#define C_028644_SEL_LINEAR 0xFFFFEFFF +#define S_028644_CYL_WRAP(x) (((x) & 0xF) << 13) +#define G_028644_CYL_WRAP(x) (((x) >> 13) & 0xF) +#define C_028644_CYL_WRAP 0xFFFE1FFF +#define S_028644_PT_SPRITE_TEX(x) (((x) & 0x1) << 17) +#define G_028644_PT_SPRITE_TEX(x) (((x) >> 17) & 0x1) +#define C_028644_PT_SPRITE_TEX 0xFFFDFFFF +#define S_028644_SEL_SAMPLE(x) (((x) & 0x1) << 18) +#define G_028644_SEL_SAMPLE(x) (((x) >> 18) & 0x1) +#define C_028644_SEL_SAMPLE 0xFFFBFFFF +#define R_0286D4_SPI_INTERP_CONTROL_0 0x0286D4 +#define S_0286D4_FLAT_SHADE_ENA(x) (((x) & 0x1) << 0) +#define G_0286D4_FLAT_SHADE_ENA(x) (((x) >> 0) & 0x1) +#define C_0286D4_FLAT_SHADE_ENA 0xFFFFFFFE +#define S_0286D4_PNT_SPRITE_ENA(x) (((x) & 0x1) << 1) +#define G_0286D4_PNT_SPRITE_ENA(x) (((x) >> 1) & 0x1) +#define C_0286D4_PNT_SPRITE_ENA 0xFFFFFFFD +#define S_0286D4_PNT_SPRITE_OVRD_X(x) (((x) & 0x7) << 2) +#define G_0286D4_PNT_SPRITE_OVRD_X(x) (((x) >> 2) & 0x7) +#define C_0286D4_PNT_SPRITE_OVRD_X 0xFFFFFFE3 +#define S_0286D4_PNT_SPRITE_OVRD_Y(x) (((x) & 0x7) << 5) +#define G_0286D4_PNT_SPRITE_OVRD_Y(x) (((x) >> 5) & 0x7) +#define C_0286D4_PNT_SPRITE_OVRD_Y 0xFFFFFF1F +#define S_0286D4_PNT_SPRITE_OVRD_Z(x) (((x) & 0x7) << 8) +#define G_0286D4_PNT_SPRITE_OVRD_Z(x) (((x) >> 8) & 0x7) +#define C_0286D4_PNT_SPRITE_OVRD_Z 0xFFFFF8FF +#define S_0286D4_PNT_SPRITE_OVRD_W(x) (((x) & 0x7) << 11) +#define G_0286D4_PNT_SPRITE_OVRD_W(x) (((x) >> 11) & 0x7) +#define C_0286D4_PNT_SPRITE_OVRD_W 0xFFFFC7FF +#define S_0286D4_PNT_SPRITE_TOP_1(x) (((x) & 0x1) << 14) +#define G_0286D4_PNT_SPRITE_TOP_1(x) (((x) >> 14) & 0x1) +#define C_0286D4_PNT_SPRITE_TOP_1 0xFFFFBFFF +#define R_028084_CB_COLOR1_VIEW 0x028084 +#define R_028088_CB_COLOR2_VIEW 0x028088 +#define R_02808C_CB_COLOR3_VIEW 0x02808C +#define R_028090_CB_COLOR4_VIEW 0x028090 +#define R_028094_CB_COLOR5_VIEW 0x028094 +#define R_028098_CB_COLOR6_VIEW 0x028098 +#define R_02809C_CB_COLOR7_VIEW 0x02809C +#define R_028104_CB_COLOR1_MASK 0x028104 +#define R_028108_CB_COLOR2_MASK 0x028108 +#define R_02810C_CB_COLOR3_MASK 0x02810C +#define R_028110_CB_COLOR4_MASK 0x028110 +#define R_028114_CB_COLOR5_MASK 0x028114 +#define R_028118_CB_COLOR6_MASK 0x028118 +#define R_02811C_CB_COLOR7_MASK 0x02811C +#define R_0280E4_CB_COLOR1_FRAG 0x0280E4 +#define R_0280E8_CB_COLOR2_FRAG 0x0280E8 +#define R_0280EC_CB_COLOR3_FRAG 0x0280EC +#define R_0280F0_CB_COLOR4_FRAG 0x0280F0 +#define R_0280F4_CB_COLOR5_FRAG 0x0280F4 +#define R_0280F8_CB_COLOR6_FRAG 0x0280F8 +#define R_0280FC_CB_COLOR7_FRAG 0x0280FC +#define R_0280C4_CB_COLOR1_TILE 0x0280C4 +#define R_0280C8_CB_COLOR2_TILE 0x0280C8 +#define R_0280CC_CB_COLOR3_TILE 0x0280CC +#define R_0280D0_CB_COLOR4_TILE 0x0280D0 +#define R_0280D4_CB_COLOR5_TILE 0x0280D4 +#define R_0280D8_CB_COLOR6_TILE 0x0280D8 +#define R_0280DC_CB_COLOR7_TILE 0x0280DC +#define R_0280A4_CB_COLOR1_INFO 0x0280A4 +#define R_0280A8_CB_COLOR2_INFO 0x0280A8 +#define R_0280AC_CB_COLOR3_INFO 0x0280AC +#define R_0280B0_CB_COLOR4_INFO 0x0280B0 +#define R_0280B4_CB_COLOR5_INFO 0x0280B4 +#define R_0280B8_CB_COLOR6_INFO 0x0280B8 +#define R_0280BC_CB_COLOR7_INFO 0x0280BC +#define R_028C30_CB_CLRCMP_CONTROL 0x028C30 +#define S_028C30_CLRCMP_FCN_SRC(x) (((x) & 0x7) << 0) +#define G_028C30_CLRCMP_FCN_SRC(x) (((x) >> 0) & 0x7) +#define C_028C30_CLRCMP_FCN_SRC 0xFFFFFFF8 +#define S_028C30_CLRCMP_FCN_DST(x) (((x) & 0x7) << 8) +#define G_028C30_CLRCMP_FCN_DST(x) (((x) >> 8) & 0x7) +#define C_028C30_CLRCMP_FCN_DST 0xFFFFF8FF +#define S_028C30_CLRCMP_FCN_SEL(x) (((x) & 0x3) << 24) +#define G_028C30_CLRCMP_FCN_SEL(x) (((x) >> 24) & 0x3) +#define C_028C30_CLRCMP_FCN_SEL 0xFCFFFFFF +#define R_028C20_PA_SC_AA_SAMPLE_LOCS_8S_WD1_MCTX 0x028C20 +#define S_028C20_S4_X(x) (((x) & 0xF) << 0) +#define G_028C20_S4_X(x) (((x) >> 0) & 0xF) +#define C_028C20_S4_X 0xFFFFFFF0 +#define S_028C20_S4_Y(x) (((x) & 0xF) << 4) +#define G_028C20_S4_Y(x) (((x) >> 4) & 0xF) +#define C_028C20_S4_Y 0xFFFFFF0F +#define S_028C20_S5_X(x) (((x) & 0xF) << 8) +#define G_028C20_S5_X(x) (((x) >> 8) & 0xF) +#define C_028C20_S5_X 0xFFFFF0FF +#define S_028C20_S5_Y(x) (((x) & 0xF) << 12) +#define G_028C20_S5_Y(x) (((x) >> 12) & 0xF) +#define C_028C20_S5_Y 0xFFFF0FFF +#define S_028C20_S6_X(x) (((x) & 0xF) << 16) +#define G_028C20_S6_X(x) (((x) >> 16) & 0xF) +#define C_028C20_S6_X 0xFFF0FFFF +#define S_028C20_S6_Y(x) (((x) & 0xF) << 20) +#define G_028C20_S6_Y(x) (((x) >> 20) & 0xF) +#define C_028C20_S6_Y 0xFF0FFFFF +#define S_028C20_S7_X(x) (((x) & 0xF) << 24) +#define G_028C20_S7_X(x) (((x) >> 24) & 0xF) +#define C_028C20_S7_X 0xF0FFFFFF +#define S_028C20_S7_Y(x) (((x) & 0xF) << 28) +#define G_028C20_S7_Y(x) (((x) >> 28) & 0xF) +#define C_028C20_S7_Y 0x0FFFFFFF +#define R_0280A0_CB_COLOR0_INFO 0x0280A0 +#define S_0280A0_ENDIAN(x) (((x) & 0x3) << 0) +#define G_0280A0_ENDIAN(x) (((x) >> 0) & 0x3) +#define C_0280A0_ENDIAN 0xFFFFFFFC +#define S_0280A0_FORMAT(x) (((x) & 0x3F) << 2) +#define G_0280A0_FORMAT(x) (((x) >> 2) & 0x3F) +#define C_0280A0_FORMAT 0xFFFFFF03 +#define V_0280A0_COLOR_INVALID 0x00000000 +#define V_0280A0_COLOR_8 0x00000001 +#define V_0280A0_COLOR_4_4 0x00000002 +#define V_0280A0_COLOR_3_3_2 0x00000003 +#define V_0280A0_COLOR_16 0x00000005 +#define V_0280A0_COLOR_16_FLOAT 0x00000006 +#define V_0280A0_COLOR_8_8 0x00000007 +#define V_0280A0_COLOR_5_6_5 0x00000008 +#define V_0280A0_COLOR_6_5_5 0x00000009 +#define V_0280A0_COLOR_1_5_5_5 0x0000000A +#define V_0280A0_COLOR_4_4_4_4 0x0000000B +#define V_0280A0_COLOR_5_5_5_1 0x0000000C +#define V_0280A0_COLOR_32 0x0000000D +#define V_0280A0_COLOR_32_FLOAT 0x0000000E +#define V_0280A0_COLOR_16_16 0x0000000F +#define V_0280A0_COLOR_16_16_FLOAT 0x00000010 +#define V_0280A0_COLOR_8_24 0x00000011 +#define V_0280A0_COLOR_8_24_FLOAT 0x00000012 +#define V_0280A0_COLOR_24_8 0x00000013 +#define V_0280A0_COLOR_24_8_FLOAT 0x00000014 +#define V_0280A0_COLOR_10_11_11 0x00000015 +#define V_0280A0_COLOR_10_11_11_FLOAT 0x00000016 +#define V_0280A0_COLOR_11_11_10 0x00000017 +#define V_0280A0_COLOR_11_11_10_FLOAT 0x00000018 +#define V_0280A0_COLOR_2_10_10_10 0x00000019 +#define V_0280A0_COLOR_8_8_8_8 0x0000001A +#define V_0280A0_COLOR_10_10_10_2 0x0000001B +#define V_0280A0_COLOR_X24_8_32_FLOAT 0x0000001C +#define V_0280A0_COLOR_32_32 0x0000001D +#define V_0280A0_COLOR_32_32_FLOAT 0x0000001E +#define V_0280A0_COLOR_16_16_16_16 0x0000001F +#define V_0280A0_COLOR_16_16_16_16_FLOAT 0x00000020 +#define V_0280A0_COLOR_32_32_32_32 0x00000022 +#define V_0280A0_COLOR_32_32_32_32_FLOAT 0x00000023 +#define S_0280A0_ARRAY_MODE(x) (((x) & 0xF) << 8) +#define G_0280A0_ARRAY_MODE(x) (((x) >> 8) & 0xF) +#define C_0280A0_ARRAY_MODE 0xFFFFF0FF +#define V_0280A0_ARRAY_LINEAR_GENERAL 0x00000000 +#define V_0280A0_ARRAY_LINEAR_ALIGNED 0x00000001 +#define V_0280A0_ARRAY_1D_TILED_THIN1 0x00000002 +#define V_0280A0_ARRAY_2D_TILED_THIN1 0x00000004 +#define S_0280A0_NUMBER_TYPE(x) (((x) & 0x7) << 12) +#define G_0280A0_NUMBER_TYPE(x) (((x) >> 12) & 0x7) +#define C_0280A0_NUMBER_TYPE 0xFFFF8FFF +#define S_0280A0_READ_SIZE(x) (((x) & 0x1) << 15) +#define G_0280A0_READ_SIZE(x) (((x) >> 15) & 0x1) +#define C_0280A0_READ_SIZE 0xFFFF7FFF +#define S_0280A0_COMP_SWAP(x) (((x) & 0x3) << 16) +#define G_0280A0_COMP_SWAP(x) (((x) >> 16) & 0x3) +#define C_0280A0_COMP_SWAP 0xFFFCFFFF +#define S_0280A0_TILE_MODE(x) (((x) & 0x3) << 18) +#define G_0280A0_TILE_MODE(x) (((x) >> 18) & 0x3) +#define C_0280A0_TILE_MODE 0xFFF3FFFF +#define S_0280A0_BLEND_CLAMP(x) (((x) & 0x1) << 20) +#define G_0280A0_BLEND_CLAMP(x) (((x) >> 20) & 0x1) +#define C_0280A0_BLEND_CLAMP 0xFFEFFFFF +#define S_0280A0_CLEAR_COLOR(x) (((x) & 0x1) << 21) +#define G_0280A0_CLEAR_COLOR(x) (((x) >> 21) & 0x1) +#define C_0280A0_CLEAR_COLOR 0xFFDFFFFF +#define S_0280A0_BLEND_BYPASS(x) (((x) & 0x1) << 22) +#define G_0280A0_BLEND_BYPASS(x) (((x) >> 22) & 0x1) +#define C_0280A0_BLEND_BYPASS 0xFFBFFFFF +#define S_0280A0_BLEND_FLOAT32(x) (((x) & 0x1) << 23) +#define G_0280A0_BLEND_FLOAT32(x) (((x) >> 23) & 0x1) +#define C_0280A0_BLEND_FLOAT32 0xFF7FFFFF +#define S_0280A0_SIMPLE_FLOAT(x) (((x) & 0x1) << 24) +#define G_0280A0_SIMPLE_FLOAT(x) (((x) >> 24) & 0x1) +#define C_0280A0_SIMPLE_FLOAT 0xFEFFFFFF +#define S_0280A0_ROUND_MODE(x) (((x) & 0x1) << 25) +#define G_0280A0_ROUND_MODE(x) (((x) >> 25) & 0x1) +#define C_0280A0_ROUND_MODE 0xFDFFFFFF +#define S_0280A0_TILE_COMPACT(x) (((x) & 0x1) << 26) +#define G_0280A0_TILE_COMPACT(x) (((x) >> 26) & 0x1) +#define C_0280A0_TILE_COMPACT 0xFBFFFFFF +#define S_0280A0_SOURCE_FORMAT(x) (((x) & 0x1) << 27) +#define G_0280A0_SOURCE_FORMAT(x) (((x) >> 27) & 0x1) +#define C_0280A0_SOURCE_FORMAT 0xF7FFFFFF +#define R_028060_CB_COLOR0_SIZE 0x028060 +#define S_028060_PITCH_TILE_MAX(x) (((x) & 0x3FF) << 0) +#define G_028060_PITCH_TILE_MAX(x) (((x) >> 0) & 0x3FF) +#define C_028060_PITCH_TILE_MAX 0xFFFFFC00 +#define S_028060_SLICE_TILE_MAX(x) (((x) & 0xFFFFF) << 10) +#define G_028060_SLICE_TILE_MAX(x) (((x) >> 10) & 0xFFFFF) +#define C_028060_SLICE_TILE_MAX 0xC00003FF +#define R_028800_DB_DEPTH_CONTROL 0x028800 +#define S_028800_STENCIL_ENABLE(x) (((x) & 0x1) << 0) +#define G_028800_STENCIL_ENABLE(x) (((x) >> 0) & 0x1) +#define C_028800_STENCIL_ENABLE 0xFFFFFFFE +#define S_028800_Z_ENABLE(x) (((x) & 0x1) << 1) +#define G_028800_Z_ENABLE(x) (((x) >> 1) & 0x1) +#define C_028800_Z_ENABLE 0xFFFFFFFD +#define S_028800_Z_WRITE_ENABLE(x) (((x) & 0x1) << 2) +#define G_028800_Z_WRITE_ENABLE(x) (((x) >> 2) & 0x1) +#define C_028800_Z_WRITE_ENABLE 0xFFFFFFFB +#define S_028800_ZFUNC(x) (((x) & 0x7) << 4) +#define G_028800_ZFUNC(x) (((x) >> 4) & 0x7) +#define C_028800_ZFUNC 0xFFFFFF8F +#define S_028800_BACKFACE_ENABLE(x) (((x) & 0x1) << 7) +#define G_028800_BACKFACE_ENABLE(x) (((x) >> 7) & 0x1) +#define C_028800_BACKFACE_ENABLE 0xFFFFFF7F +#define S_028800_STENCILFUNC(x) (((x) & 0x7) << 8) +#define G_028800_STENCILFUNC(x) (((x) >> 8) & 0x7) +#define C_028800_STENCILFUNC 0xFFFFF8FF +#define S_028800_STENCILFAIL(x) (((x) & 0x7) << 11) +#define G_028800_STENCILFAIL(x) (((x) >> 11) & 0x7) +#define C_028800_STENCILFAIL 0xFFFFC7FF +#define S_028800_STENCILZPASS(x) (((x) & 0x7) << 14) +#define G_028800_STENCILZPASS(x) (((x) >> 14) & 0x7) +#define C_028800_STENCILZPASS 0xFFFE3FFF +#define S_028800_STENCILZFAIL(x) (((x) & 0x7) << 17) +#define G_028800_STENCILZFAIL(x) (((x) >> 17) & 0x7) +#define C_028800_STENCILZFAIL 0xFFF1FFFF +#define S_028800_STENCILFUNC_BF(x) (((x) & 0x7) << 20) +#define G_028800_STENCILFUNC_BF(x) (((x) >> 20) & 0x7) +#define C_028800_STENCILFUNC_BF 0xFF8FFFFF +#define S_028800_STENCILFAIL_BF(x) (((x) & 0x7) << 23) +#define G_028800_STENCILFAIL_BF(x) (((x) >> 23) & 0x7) +#define C_028800_STENCILFAIL_BF 0xFC7FFFFF +#define S_028800_STENCILZPASS_BF(x) (((x) & 0x7) << 26) +#define G_028800_STENCILZPASS_BF(x) (((x) >> 26) & 0x7) +#define C_028800_STENCILZPASS_BF 0xE3FFFFFF +#define S_028800_STENCILZFAIL_BF(x) (((x) & 0x7) << 29) +#define G_028800_STENCILZFAIL_BF(x) (((x) >> 29) & 0x7) +#define C_028800_STENCILZFAIL_BF 0x1FFFFFFF +#define R_028010_DB_DEPTH_INFO 0x028010 +#define S_028010_FORMAT(x) (((x) & 0x7) << 0) +#define G_028010_FORMAT(x) (((x) >> 0) & 0x7) +#define C_028010_FORMAT 0xFFFFFFF8 +#define V_028010_DEPTH_INVALID 0x00000000 +#define V_028010_DEPTH_16 0x00000001 +#define V_028010_DEPTH_X8_24 0x00000002 +#define V_028010_DEPTH_8_24 0x00000003 +#define V_028010_DEPTH_X8_24_FLOAT 0x00000004 +#define V_028010_DEPTH_8_24_FLOAT 0x00000005 +#define V_028010_DEPTH_32_FLOAT 0x00000006 +#define V_028010_DEPTH_X24_8_32_FLOAT 0x00000007 +#define S_028010_READ_SIZE(x) (((x) & 0x1) << 3) +#define G_028010_READ_SIZE(x) (((x) >> 3) & 0x1) +#define C_028010_READ_SIZE 0xFFFFFFF7 +#define S_028010_ARRAY_MODE(x) (((x) & 0xF) << 15) +#define G_028010_ARRAY_MODE(x) (((x) >> 15) & 0xF) +#define C_028010_ARRAY_MODE 0xFFF87FFF +#define S_028010_TILE_SURFACE_ENABLE(x) (((x) & 0x1) << 25) +#define G_028010_TILE_SURFACE_ENABLE(x) (((x) >> 25) & 0x1) +#define C_028010_TILE_SURFACE_ENABLE 0xFDFFFFFF +#define S_028010_TILE_COMPACT(x) (((x) & 0x1) << 26) +#define G_028010_TILE_COMPACT(x) (((x) >> 26) & 0x1) +#define C_028010_TILE_COMPACT 0xFBFFFFFF +#define S_028010_ZRANGE_PRECISION(x) (((x) & 0x1) << 31) +#define G_028010_ZRANGE_PRECISION(x) (((x) >> 31) & 0x1) +#define C_028010_ZRANGE_PRECISION 0x7FFFFFFF +#define R_028000_DB_DEPTH_SIZE 0x028000 +#define S_028000_PITCH_TILE_MAX(x) (((x) & 0x3FF) << 0) +#define G_028000_PITCH_TILE_MAX(x) (((x) >> 0) & 0x3FF) +#define C_028000_PITCH_TILE_MAX 0xFFFFFC00 +#define S_028000_SLICE_TILE_MAX(x) (((x) & 0xFFFFF) << 10) +#define G_028000_SLICE_TILE_MAX(x) (((x) >> 10) & 0xFFFFF) +#define C_028000_SLICE_TILE_MAX 0xC00003FF +#define R_028004_DB_DEPTH_VIEW 0x028004 +#define S_028004_SLICE_START(x) (((x) & 0x7FF) << 0) +#define G_028004_SLICE_START(x) (((x) >> 0) & 0x7FF) +#define C_028004_SLICE_START 0xFFFFF800 +#define S_028004_SLICE_MAX(x) (((x) & 0x7FF) << 13) +#define G_028004_SLICE_MAX(x) (((x) >> 13) & 0x7FF) +#define C_028004_SLICE_MAX 0xFF001FFF +#define R_028D24_DB_HTILE_SURFACE 0x028D24 +#define S_028D24_HTILE_WIDTH(x) (((x) & 0x1) << 0) +#define G_028D24_HTILE_WIDTH(x) (((x) >> 0) & 0x1) +#define C_028D24_HTILE_WIDTH 0xFFFFFFFE +#define S_028D24_HTILE_HEIGHT(x) (((x) & 0x1) << 1) +#define G_028D24_HTILE_HEIGHT(x) (((x) >> 1) & 0x1) +#define C_028D24_HTILE_HEIGHT 0xFFFFFFFD +#define S_028D24_LINEAR(x) (((x) & 0x1) << 2) +#define G_028D24_LINEAR(x) (((x) >> 2) & 0x1) +#define C_028D24_LINEAR 0xFFFFFFFB +#define S_028D24_FULL_CACHE(x) (((x) & 0x1) << 3) +#define G_028D24_FULL_CACHE(x) (((x) >> 3) & 0x1) +#define C_028D24_FULL_CACHE 0xFFFFFFF7 +#define S_028D24_HTILE_USES_PRELOAD_WIN(x) (((x) & 0x1) << 4) +#define G_028D24_HTILE_USES_PRELOAD_WIN(x) (((x) >> 4) & 0x1) +#define C_028D24_HTILE_USES_PRELOAD_WIN 0xFFFFFFEF +#define S_028D24_PRELOAD(x) (((x) & 0x1) << 5) +#define G_028D24_PRELOAD(x) (((x) >> 5) & 0x1) +#define C_028D24_PRELOAD 0xFFFFFFDF +#define S_028D24_PREFETCH_WIDTH(x) (((x) & 0x3F) << 6) +#define G_028D24_PREFETCH_WIDTH(x) (((x) >> 6) & 0x3F) +#define C_028D24_PREFETCH_WIDTH 0xFFFFF03F +#define S_028D24_PREFETCH_HEIGHT(x) (((x) & 0x3F) << 12) +#define G_028D24_PREFETCH_HEIGHT(x) (((x) >> 12) & 0x3F) +#define C_028D24_PREFETCH_HEIGHT 0xFFFC0FFF +#define R_028D34_DB_PREFETCH_LIMIT 0x028D34 +#define S_028D34_DEPTH_HEIGHT_TILE_MAX(x) (((x) & 0x3FF) << 0) +#define G_028D34_DEPTH_HEIGHT_TILE_MAX(x) (((x) >> 0) & 0x3FF) +#define C_028D34_DEPTH_HEIGHT_TILE_MAX 0xFFFFFC00 +#define R_028D10_DB_RENDER_OVERRIDE 0x028D10 +#define S_028D10_FORCE_HIZ_ENABLE(x) (((x) & 0x3) << 0) +#define G_028D10_FORCE_HIZ_ENABLE(x) (((x) >> 0) & 0x3) +#define C_028D10_FORCE_HIZ_ENABLE 0xFFFFFFFC +#define S_028D10_FORCE_HIS_ENABLE0(x) (((x) & 0x3) << 2) +#define G_028D10_FORCE_HIS_ENABLE0(x) (((x) >> 2) & 0x3) +#define C_028D10_FORCE_HIS_ENABLE0 0xFFFFFFF3 +#define S_028D10_FORCE_HIS_ENABLE1(x) (((x) & 0x3) << 4) +#define G_028D10_FORCE_HIS_ENABLE1(x) (((x) >> 4) & 0x3) +#define C_028D10_FORCE_HIS_ENABLE1 0xFFFFFFCF +#define S_028D10_FORCE_SHADER_Z_ORDER(x) (((x) & 0x1) << 6) +#define G_028D10_FORCE_SHADER_Z_ORDER(x) (((x) >> 6) & 0x1) +#define C_028D10_FORCE_SHADER_Z_ORDER 0xFFFFFFBF +#define S_028D10_FAST_Z_DISABLE(x) (((x) & 0x1) << 7) +#define G_028D10_FAST_Z_DISABLE(x) (((x) >> 7) & 0x1) +#define C_028D10_FAST_Z_DISABLE 0xFFFFFF7F +#define S_028D10_FAST_STENCIL_DISABLE(x) (((x) & 0x1) << 8) +#define G_028D10_FAST_STENCIL_DISABLE(x) (((x) >> 8) & 0x1) +#define C_028D10_FAST_STENCIL_DISABLE 0xFFFFFEFF +#define S_028D10_NOOP_CULL_DISABLE(x) (((x) & 0x1) << 9) +#define G_028D10_NOOP_CULL_DISABLE(x) (((x) >> 9) & 0x1) +#define C_028D10_NOOP_CULL_DISABLE 0xFFFFFDFF +#define S_028D10_FORCE_COLOR_KILL(x) (((x) & 0x1) << 10) +#define G_028D10_FORCE_COLOR_KILL(x) (((x) >> 10) & 0x1) +#define C_028D10_FORCE_COLOR_KILL 0xFFFFFBFF +#define S_028D10_FORCE_Z_READ(x) (((x) & 0x1) << 11) +#define G_028D10_FORCE_Z_READ(x) (((x) >> 11) & 0x1) +#define C_028D10_FORCE_Z_READ 0xFFFFF7FF +#define S_028D10_FORCE_STENCIL_READ(x) (((x) & 0x1) << 12) +#define G_028D10_FORCE_STENCIL_READ(x) (((x) >> 12) & 0x1) +#define C_028D10_FORCE_STENCIL_READ 0xFFFFEFFF +#define S_028D10_FORCE_FULL_Z_RANGE(x) (((x) & 0x3) << 13) +#define G_028D10_FORCE_FULL_Z_RANGE(x) (((x) >> 13) & 0x3) +#define C_028D10_FORCE_FULL_Z_RANGE 0xFFFF9FFF +#define S_028D10_FORCE_QC_SMASK_CONFLICT(x) (((x) & 0x1) << 15) +#define G_028D10_FORCE_QC_SMASK_CONFLICT(x) (((x) >> 15) & 0x1) +#define C_028D10_FORCE_QC_SMASK_CONFLICT 0xFFFF7FFF +#define S_028D10_DISABLE_VIEWPORT_CLAMP(x) (((x) & 0x1) << 16) +#define G_028D10_DISABLE_VIEWPORT_CLAMP(x) (((x) >> 16) & 0x1) +#define C_028D10_DISABLE_VIEWPORT_CLAMP 0xFFFEFFFF +#define S_028D10_IGNORE_SC_ZRANGE(x) (((x) & 0x1) << 17) +#define G_028D10_IGNORE_SC_ZRANGE(x) (((x) >> 17) & 0x1) +#define C_028D10_IGNORE_SC_ZRANGE 0xFFFDFFFF +#define R_028A40_VGT_GS_MODE 0x028A40 +#define S_028A40_MODE(x) (((x) & 0x3) << 0) +#define G_028A40_MODE(x) (((x) >> 0) & 0x3) +#define C_028A40_MODE 0xFFFFFFFC +#define S_028A40_ES_PASSTHRU(x) (((x) & 0x1) << 2) +#define G_028A40_ES_PASSTHRU(x) (((x) >> 2) & 0x1) +#define C_028A40_ES_PASSTHRU 0xFFFFFFFB +#define S_028A40_CUT_MODE(x) (((x) & 0x3) << 3) +#define G_028A40_CUT_MODE(x) (((x) >> 3) & 0x3) +#define C_028A40_CUT_MODE 0xFFFFFFE7 +#define R_008DFC_SQ_CF_WORD0 0x008DFC +#define S_008DFC_ADDR(x) (((x) & 0xFFFFFFFF) << 0) +#define G_008DFC_ADDR(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_008DFC_ADDR 0x00000000 +#define R_008DFC_SQ_CF_WORD1 0x008DFC +#define S_008DFC_POP_COUNT(x) (((x) & 0x7) << 0) +#define G_008DFC_POP_COUNT(x) (((x) >> 0) & 0x7) +#define C_008DFC_POP_COUNT 0xFFFFFFF8 +#define S_008DFC_CF_CONST(x) (((x) & 0x1F) << 3) +#define G_008DFC_CF_CONST(x) (((x) >> 3) & 0x1F) +#define C_008DFC_CF_CONST 0xFFFFFF07 +#define S_008DFC_COND(x) (((x) & 0x3) << 8) +#define G_008DFC_COND(x) (((x) >> 8) & 0x3) +#define C_008DFC_COND 0xFFFFFCFF +#define S_008DFC_COUNT(x) (((x) & 0x7) << 10) +#define G_008DFC_COUNT(x) (((x) >> 10) & 0x7) +#define C_008DFC_COUNT 0xFFFFE3FF +#define S_008DFC_CALL_COUNT(x) (((x) & 0x3F) << 13) +#define G_008DFC_CALL_COUNT(x) (((x) >> 13) & 0x3F) +#define C_008DFC_CALL_COUNT 0xFFF81FFF +#define S_008DFC_END_OF_PROGRAM(x) (((x) & 0x1) << 21) +#define G_008DFC_END_OF_PROGRAM(x) (((x) >> 21) & 0x1) +#define C_008DFC_END_OF_PROGRAM 0xFFDFFFFF +#define S_008DFC_VALID_PIXEL_MODE(x) (((x) & 0x1) << 22) +#define G_008DFC_VALID_PIXEL_MODE(x) (((x) >> 22) & 0x1) +#define C_008DFC_VALID_PIXEL_MODE 0xFFBFFFFF +#define S_008DFC_CF_INST(x) (((x) & 0x7F) << 23) +#define G_008DFC_CF_INST(x) (((x) >> 23) & 0x7F) +#define C_008DFC_CF_INST 0xC07FFFFF +#define V_008DFC_SQ_CF_INST_NOP 0x00000000 +#define V_008DFC_SQ_CF_INST_TEX 0x00000001 +#define V_008DFC_SQ_CF_INST_VTX 0x00000002 +#define V_008DFC_SQ_CF_INST_VTX_TC 0x00000003 +#define V_008DFC_SQ_CF_INST_LOOP_START 0x00000004 +#define V_008DFC_SQ_CF_INST_LOOP_END 0x00000005 +#define V_008DFC_SQ_CF_INST_LOOP_START_DX10 0x00000006 +#define V_008DFC_SQ_CF_INST_LOOP_START_NO_AL 0x00000007 +#define V_008DFC_SQ_CF_INST_LOOP_CONTINUE 0x00000008 +#define V_008DFC_SQ_CF_INST_LOOP_BREAK 0x00000009 +#define V_008DFC_SQ_CF_INST_JUMP 0x0000000A +#define V_008DFC_SQ_CF_INST_PUSH 0x0000000B +#define V_008DFC_SQ_CF_INST_PUSH_ELSE 0x0000000C +#define V_008DFC_SQ_CF_INST_ELSE 0x0000000D +#define V_008DFC_SQ_CF_INST_POP 0x0000000E +#define V_008DFC_SQ_CF_INST_POP_JUMP 0x0000000F +#define V_008DFC_SQ_CF_INST_POP_PUSH 0x00000010 +#define V_008DFC_SQ_CF_INST_POP_PUSH_ELSE 0x00000011 +#define V_008DFC_SQ_CF_INST_CALL 0x00000012 +#define V_008DFC_SQ_CF_INST_CALL_FS 0x00000013 +#define V_008DFC_SQ_CF_INST_RETURN 0x00000014 +#define V_008DFC_SQ_CF_INST_EMIT_VERTEX 0x00000015 +#define V_008DFC_SQ_CF_INST_EMIT_CUT_VERTEX 0x00000016 +#define V_008DFC_SQ_CF_INST_CUT_VERTEX 0x00000017 +#define V_008DFC_SQ_CF_INST_KILL 0x00000018 +#define S_008DFC_WHOLE_QUAD_MODE(x) (((x) & 0x1) << 30) +#define G_008DFC_WHOLE_QUAD_MODE(x) (((x) >> 30) & 0x1) +#define C_008DFC_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_008DFC_BARRIER(x) (((x) & 0x1) << 31) +#define G_008DFC_BARRIER(x) (((x) >> 31) & 0x1) +#define C_008DFC_BARRIER 0x7FFFFFFF +#define R_008DFC_SQ_CF_ALU_WORD0 0x008DFC +#define S_008DFC_ALU_ADDR(x) (((x) & 0x3FFFFF) << 0) +#define G_008DFC_ALU_ADDR(x) (((x) >> 0) & 0x3FFFFF) +#define C_008DFC_ALU_ADDR 0xFFC00000 +#define S_008DFC_KCACHE_BANK0(x) (((x) & 0xF) << 22) +#define G_008DFC_KCACHE_BANK0(x) (((x) >> 22) & 0xF) +#define C_008DFC_KCACHE_BANK0 0xFC3FFFFF +#define S_008DFC_KCACHE_BANK1(x) (((x) & 0xF) << 26) +#define G_008DFC_KCACHE_BANK1(x) (((x) >> 26) & 0xF) +#define C_008DFC_KCACHE_BANK1 0xC3FFFFFF +#define S_008DFC_KCACHE_MODE0(x) (((x) & 0x3) << 30) +#define G_008DFC_KCACHE_MODE0(x) (((x) >> 30) & 0x3) +#define C_008DFC_KCACHE_MODE0 0x3FFFFFFF +#define R_008DFC_SQ_CF_ALU_WORD1 0x008DFC +#define S_008DFC_KCACHE_MODE1(x) (((x) & 0x3) << 0) +#define G_008DFC_KCACHE_MODE1(x) (((x) >> 0) & 0x3) +#define C_008DFC_KCACHE_MODE1 0xFFFFFFFC +#define S_008DFC_KCACHE_ADDR0(x) (((x) & 0xFF) << 2) +#define G_008DFC_KCACHE_ADDR0(x) (((x) >> 2) & 0xFF) +#define C_008DFC_KCACHE_ADDR0 0xFFFFFC03 +#define S_008DFC_KCACHE_ADDR1(x) (((x) & 0xFF) << 10) +#define G_008DFC_KCACHE_ADDR1(x) (((x) >> 10) & 0xFF) +#define C_008DFC_KCACHE_ADDR1 0xFFFC03FF +#define S_008DFC_ALU_COUNT(x) (((x) & 0x7F) << 18) +#define G_008DFC_ALU_COUNT(x) (((x) >> 18) & 0x7F) +#define C_008DFC_ALU_COUNT 0xFE03FFFF +#define S_008DFC_USES_WATERFALL(x) (((x) & 0x1) << 25) +#define G_008DFC_USES_WATERFALL(x) (((x) >> 25) & 0x1) +#define C_008DFC_USES_WATERFALL 0xFDFFFFFF +#define S_008DFC_CF_ALU_INST(x) (((x) & 0xF) << 26) +#define G_008DFC_CF_ALU_INST(x) (((x) >> 26) & 0xF) +#define C_008DFC_CF_ALU_INST 0xC3FFFFFF +#define V_008DFC_SQ_CF_INST_ALU 0x00000008 +#define V_008DFC_SQ_CF_INST_ALU_PUSH_BEFORE 0x00000009 +#define V_008DFC_SQ_CF_INST_ALU_POP_AFTER 0x0000000A +#define V_008DFC_SQ_CF_INST_ALU_POP2_AFTER 0x0000000B +#define V_008DFC_SQ_CF_INST_ALU_CONTINUE 0x0000000D +#define V_008DFC_SQ_CF_INST_ALU_BREAK 0x0000000E +#define V_008DFC_SQ_CF_INST_ALU_ELSE_AFTER 0x0000000F +#define S_008DFC_WHOLE_QUAD_MODE(x) (((x) & 0x1) << 30) +#define G_008DFC_WHOLE_QUAD_MODE(x) (((x) >> 30) & 0x1) +#define C_008DFC_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_008DFC_BARRIER(x) (((x) & 0x1) << 31) +#define G_008DFC_BARRIER(x) (((x) >> 31) & 0x1) +#define C_008DFC_BARRIER 0x7FFFFFFF +#define R_008DFC_SQ_CF_ALLOC_EXPORT_WORD0 0x008DFC +#define S_008DFC_ARRAY_BASE(x) (((x) & 0x1FFF) << 0) +#define G_008DFC_ARRAY_BASE(x) (((x) >> 0) & 0x1FFF) +#define C_008DFC_ARRAY_BASE 0xFFFFE000 +#define S_008DFC_TYPE(x) (((x) & 0x3) << 13) +#define G_008DFC_TYPE(x) (((x) >> 13) & 0x3) +#define C_008DFC_TYPE 0xFFFF9FFF +#define S_008DFC_RW_GPR(x) (((x) & 0x7F) << 15) +#define G_008DFC_RW_GPR(x) (((x) >> 15) & 0x7F) +#define C_008DFC_RW_GPR 0xFFC07FFF +#define S_008DFC_RW_REL(x) (((x) & 0x1) << 22) +#define G_008DFC_RW_REL(x) (((x) >> 22) & 0x1) +#define C_008DFC_RW_REL 0xFFBFFFFF +#define S_008DFC_INDEX_GPR(x) (((x) & 0x7F) << 23) +#define G_008DFC_INDEX_GPR(x) (((x) >> 23) & 0x7F) +#define C_008DFC_INDEX_GPR 0xC07FFFFF +#define S_008DFC_ELEM_SIZE(x) (((x) & 0x3) << 30) +#define G_008DFC_ELEM_SIZE(x) (((x) >> 30) & 0x3) +#define C_008DFC_ELEM_SIZE 0x3FFFFFFF +#define R_008DFC_SQ_CF_ALLOC_EXPORT_WORD1 0x008DFC +#define S_008DFC_BURST_COUNT(x) (((x) & 0xF) << 17) +#define G_008DFC_BURST_COUNT(x) (((x) >> 17) & 0xF) +#define C_008DFC_BURST_COUNT 0xFFE1FFFF +#define S_008DFC_END_OF_PROGRAM(x) (((x) & 0x1) << 21) +#define G_008DFC_END_OF_PROGRAM(x) (((x) >> 21) & 0x1) +#define C_008DFC_END_OF_PROGRAM 0xFFDFFFFF +#define S_008DFC_VALID_PIXEL_MODE(x) (((x) & 0x1) << 22) +#define G_008DFC_VALID_PIXEL_MODE(x) (((x) >> 22) & 0x1) +#define C_008DFC_VALID_PIXEL_MODE 0xFFBFFFFF +#define S_008DFC_CF_INST(x) (((x) & 0x7F) << 23) +#define G_008DFC_CF_INST(x) (((x) >> 23) & 0x7F) +#define C_008DFC_CF_INST 0xC07FFFFF +#define V_008DFC_SQ_CF_INST_MEM_STREAM0 0x00000020 +#define V_008DFC_SQ_CF_INST_MEM_STREAM1 0x00000021 +#define V_008DFC_SQ_CF_INST_MEM_STREAM2 0x00000022 +#define V_008DFC_SQ_CF_INST_MEM_STREAM3 0x00000023 +#define V_008DFC_SQ_CF_INST_MEM_SCRATCH 0x00000024 +#define V_008DFC_SQ_CF_INST_MEM_REDUCTION 0x00000025 +#define V_008DFC_SQ_CF_INST_MEM_RING 0x00000026 +#define V_008DFC_SQ_CF_INST_EXPORT 0x00000027 +#define V_008DFC_SQ_CF_INST_EXPORT_DONE 0x00000028 +#define S_008DFC_WHOLE_QUAD_MODE(x) (((x) & 0x1) << 30) +#define G_008DFC_WHOLE_QUAD_MODE(x) (((x) >> 30) & 0x1) +#define C_008DFC_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_008DFC_BARRIER(x) (((x) & 0x1) << 31) +#define G_008DFC_BARRIER(x) (((x) >> 31) & 0x1) +#define C_008DFC_BARRIER 0x7FFFFFFF +#define R_008DFC_SQ_CF_ALLOC_EXPORT_WORD1_BUF 0x008DFC +#define S_008DFC_ARRAY_SIZE(x) (((x) & 0xFFF) << 0) +#define G_008DFC_ARRAY_SIZE(x) (((x) >> 0) & 0xFFF) +#define C_008DFC_ARRAY_SIZE 0xFFFFF000 +#define S_008DFC_COMP_MASK(x) (((x) & 0xF) << 12) +#define G_008DFC_COMP_MASK(x) (((x) >> 12) & 0xF) +#define C_008DFC_COMP_MASK 0xFFFF0FFF +#define R_008DFC_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ 0x008DFC +#define S_008DFC_SEL_X(x) (((x) & 0x7) << 0) +#define G_008DFC_SEL_X(x) (((x) >> 0) & 0x7) +#define C_008DFC_SEL_X 0xFFFFFFF8 +#define S_008DFC_SEL_Y(x) (((x) & 0x7) << 3) +#define G_008DFC_SEL_Y(x) (((x) >> 3) & 0x7) +#define C_008DFC_SEL_Y 0xFFFFFFC7 +#define S_008DFC_SEL_Z(x) (((x) & 0x7) << 6) +#define G_008DFC_SEL_Z(x) (((x) >> 6) & 0x7) +#define C_008DFC_SEL_Z 0xFFFFFE3F +#define S_008DFC_SEL_W(x) (((x) & 0x7) << 9) +#define G_008DFC_SEL_W(x) (((x) >> 9) & 0x7) +#define C_008DFC_SEL_W 0xFFFFF1FF +#define R_008DFC_SQ_VTX_WORD0 0x008DFC +#define S_008DFC_VTX_INST(x) (((x) & 0x1F) << 0) +#define G_008DFC_VTX_INST(x) (((x) >> 0) & 0x1F) +#define C_008DFC_VTX_INST 0xFFFFFFE0 +#define S_008DFC_FETCH_TYPE(x) (((x) & 0x3) << 5) +#define G_008DFC_FETCH_TYPE(x) (((x) >> 5) & 0x3) +#define C_008DFC_FETCH_TYPE 0xFFFFFF9F +#define S_008DFC_FETCH_WHOLE_QUAD(x) (((x) & 0x1) << 7) +#define G_008DFC_FETCH_WHOLE_QUAD(x) (((x) >> 7) & 0x1) +#define C_008DFC_FETCH_WHOLE_QUAD 0xFFFFFF7F +#define S_008DFC_BUFFER_ID(x) (((x) & 0xFF) << 8) +#define G_008DFC_BUFFER_ID(x) (((x) >> 8) & 0xFF) +#define C_008DFC_BUFFER_ID 0xFFFF00FF +#define S_008DFC_SRC_GPR(x) (((x) & 0x7F) << 16) +#define G_008DFC_SRC_GPR(x) (((x) >> 16) & 0x7F) +#define C_008DFC_SRC_GPR 0xFF80FFFF +#define S_008DFC_SRC_REL(x) (((x) & 0x1) << 23) +#define G_008DFC_SRC_REL(x) (((x) >> 23) & 0x1) +#define C_008DFC_SRC_REL 0xFF7FFFFF +#define S_008DFC_SRC_SEL_X(x) (((x) & 0x3) << 24) +#define G_008DFC_SRC_SEL_X(x) (((x) >> 24) & 0x3) +#define C_008DFC_SRC_SEL_X 0xFCFFFFFF +#define S_008DFC_MEGA_FETCH_COUNT(x) (((x) & 0x3F) << 26) +#define G_008DFC_MEGA_FETCH_COUNT(x) (((x) >> 26) & 0x3F) +#define C_008DFC_MEGA_FETCH_COUNT 0x03FFFFFF +#define R_008DFC_SQ_VTX_WORD1 0x008DFC +#define S_008DFC_DST_SEL_X(x) (((x) & 0x7) << 9) +#define G_008DFC_DST_SEL_X(x) (((x) >> 9) & 0x7) +#define C_008DFC_DST_SEL_X 0xFFFFF1FF +#define S_008DFC_DST_SEL_Y(x) (((x) & 0x7) << 12) +#define G_008DFC_DST_SEL_Y(x) (((x) >> 12) & 0x7) +#define C_008DFC_DST_SEL_Y 0xFFFF8FFF +#define S_008DFC_DST_SEL_Z(x) (((x) & 0x7) << 15) +#define G_008DFC_DST_SEL_Z(x) (((x) >> 15) & 0x7) +#define C_008DFC_DST_SEL_Z 0xFFFC7FFF +#define S_008DFC_DST_SEL_W(x) (((x) & 0x7) << 18) +#define G_008DFC_DST_SEL_W(x) (((x) >> 18) & 0x7) +#define C_008DFC_DST_SEL_W 0xFFE3FFFF +#define S_008DFC_USE_CONST_FIELDS(x) (((x) & 0x1) << 21) +#define G_008DFC_USE_CONST_FIELDS(x) (((x) >> 21) & 0x1) +#define C_008DFC_USE_CONST_FIELDS 0xFFDFFFFF +#define S_008DFC_DATA_FORMAT(x) (((x) & 0x3F) << 22) +#define G_008DFC_DATA_FORMAT(x) (((x) >> 22) & 0x3F) +#define C_008DFC_DATA_FORMAT 0xF03FFFFF +#define S_008DFC_NUM_FORMAT_ALL(x) (((x) & 0x3) << 28) +#define G_008DFC_NUM_FORMAT_ALL(x) (((x) >> 28) & 0x3) +#define C_008DFC_NUM_FORMAT_ALL 0xCFFFFFFF +#define S_008DFC_FORMAT_COMP_ALL(x) (((x) & 0x1) << 30) +#define G_008DFC_FORMAT_COMP_ALL(x) (((x) >> 30) & 0x1) +#define C_008DFC_FORMAT_COMP_ALL 0xBFFFFFFF +#define S_008DFC_SRF_MODE_ALL(x) (((x) & 0x1) << 31) +#define G_008DFC_SRF_MODE_ALL(x) (((x) >> 31) & 0x1) +#define C_008DFC_SRF_MODE_ALL 0x7FFFFFFF +#define R_008DFC_SQ_VTX_WORD1_GPR 0x008DFC +#define S_008DFC_DST_GPR(x) (((x) & 0x7F) << 0) +#define G_008DFC_DST_GPR(x) (((x) >> 0) & 0x7F) +#define C_008DFC_DST_GPR 0xFFFFFF80 +#define S_008DFC_DST_REL(x) (((x) & 0x1) << 7) +#define G_008DFC_DST_REL(x) (((x) >> 7) & 0x1) +#define C_008DFC_DST_REL 0xFFFFFF7F +#define R_008DFC_SQ_VTX_WORD2 0x008DFC +#define S_008DFC_OFFSET(x) (((x) & 0xFFFF) << 0) +#define G_008DFC_OFFSET(x) (((x) >> 0) & 0xFFFF) +#define C_008DFC_OFFSET 0xFFFF0000 +#define S_008DFC_ENDIAN_SWAP(x) (((x) & 0x3) << 16) +#define G_008DFC_ENDIAN_SWAP(x) (((x) >> 16) & 0x3) +#define C_008DFC_ENDIAN_SWAP 0xFFFCFFFF +#define S_008DFC_CONST_BUF_NO_STRIDE(x) (((x) & 0x1) << 18) +#define G_008DFC_CONST_BUF_NO_STRIDE(x) (((x) >> 18) & 0x1) +#define C_008DFC_CONST_BUF_NO_STRIDE 0xFFFBFFFF +#define S_008DFC_MEGA_FETCH(x) (((x) & 0x1) << 19) +#define G_008DFC_MEGA_FETCH(x) (((x) >> 19) & 0x1) +#define C_008DFC_MEGA_FETCH 0xFFF7FFFF +#define S_008DFC_ALT_CONST(x) (((x) & 0x1) << 20) +#define G_008DFC_ALT_CONST(x) (((x) >> 20) & 0x1) +#define C_008DFC_ALT_CONST 0xFFEFFFFF +#define R_008040_WAIT_UNTIL 0x008040 +#define S_008040_WAIT_CP_DMA_IDLE(x) (((x) & 0x1) << 8) +#define G_008040_WAIT_CP_DMA_IDLE(x) (((x) >> 8) & 0x1) +#define C_008040_WAIT_CP_DMA_IDLE 0xFFFFFEFF +#define S_008040_WAIT_CMDFIFO(x) (((x) & 0x1) << 10) +#define G_008040_WAIT_CMDFIFO(x) (((x) >> 10) & 0x1) +#define C_008040_WAIT_CMDFIFO 0xFFFFFBFF +#define S_008040_WAIT_2D_IDLE(x) (((x) & 0x1) << 14) +#define G_008040_WAIT_2D_IDLE(x) (((x) >> 14) & 0x1) +#define C_008040_WAIT_2D_IDLE 0xFFFFBFFF +#define S_008040_WAIT_3D_IDLE(x) (((x) & 0x1) << 15) +#define G_008040_WAIT_3D_IDLE(x) (((x) >> 15) & 0x1) +#define C_008040_WAIT_3D_IDLE 0xFFFF7FFF +#define S_008040_WAIT_2D_IDLECLEAN(x) (((x) & 0x1) << 16) +#define G_008040_WAIT_2D_IDLECLEAN(x) (((x) >> 16) & 0x1) +#define C_008040_WAIT_2D_IDLECLEAN 0xFFFEFFFF +#define S_008040_WAIT_3D_IDLECLEAN(x) (((x) & 0x1) << 17) +#define G_008040_WAIT_3D_IDLECLEAN(x) (((x) >> 17) & 0x1) +#define C_008040_WAIT_3D_IDLECLEAN 0xFFFDFFFF +#define S_008040_WAIT_EXTERN_SIG(x) (((x) & 0x1) << 19) +#define G_008040_WAIT_EXTERN_SIG(x) (((x) >> 19) & 0x1) +#define C_008040_WAIT_EXTERN_SIG 0xFFF7FFFF +#define S_008040_CMDFIFO_ENTRIES(x) (((x) & 0x1F) << 20) +#define G_008040_CMDFIFO_ENTRIES(x) (((x) >> 20) & 0x1F) +#define C_008040_CMDFIFO_ENTRIES 0xFE0FFFFF +#define R_0286CC_SPI_PS_IN_CONTROL_0 0x0286CC +#define S_0286CC_NUM_INTERP(x) (((x) & 0x3F) << 0) +#define G_0286CC_NUM_INTERP(x) (((x) >> 0) & 0x3F) +#define C_0286CC_NUM_INTERP 0xFFFFFFC0 +#define S_0286CC_POSITION_ENA(x) (((x) & 0x1) << 8) +#define G_0286CC_POSITION_ENA(x) (((x) >> 8) & 0x1) +#define C_0286CC_POSITION_ENA 0xFFFFFEFF +#define S_0286CC_POSITION_CENTROID(x) (((x) & 0x1) << 9) +#define G_0286CC_POSITION_CENTROID(x) (((x) >> 9) & 0x1) +#define C_0286CC_POSITION_CENTROID 0xFFFFFDFF +#define S_0286CC_POSITION_ADDR(x) (((x) & 0x1F) << 10) +#define G_0286CC_POSITION_ADDR(x) (((x) >> 10) & 0x1F) +#define C_0286CC_POSITION_ADDR 0xFFFF83FF +#define S_0286CC_PARAM_GEN(x) (((x) & 0xF) << 15) +#define G_0286CC_PARAM_GEN(x) (((x) >> 15) & 0xF) +#define C_0286CC_PARAM_GEN 0xFFF87FFF +#define S_0286CC_PARAM_GEN_ADDR(x) (((x) & 0x7F) << 19) +#define G_0286CC_PARAM_GEN_ADDR(x) (((x) >> 19) & 0x7F) +#define C_0286CC_PARAM_GEN_ADDR 0xFC07FFFF +#define S_0286CC_BARYC_SAMPLE_CNTL(x) (((x) & 0x3) << 26) +#define G_0286CC_BARYC_SAMPLE_CNTL(x) (((x) >> 26) & 0x3) +#define C_0286CC_BARYC_SAMPLE_CNTL 0xF3FFFFFF +#define S_0286CC_PERSP_GRADIENT_ENA(x) (((x) & 0x1) << 28) +#define G_0286CC_PERSP_GRADIENT_ENA(x) (((x) >> 28) & 0x1) +#define C_0286CC_PERSP_GRADIENT_ENA 0xEFFFFFFF +#define S_0286CC_LINEAR_GRADIENT_ENA(x) (((x) & 0x1) << 29) +#define G_0286CC_LINEAR_GRADIENT_ENA(x) (((x) >> 29) & 0x1) +#define C_0286CC_LINEAR_GRADIENT_ENA 0xDFFFFFFF +#define S_0286CC_POSITION_SAMPLE(x) (((x) & 0x1) << 30) +#define G_0286CC_POSITION_SAMPLE(x) (((x) >> 30) & 0x1) +#define C_0286CC_POSITION_SAMPLE 0xBFFFFFFF +#define S_0286CC_BARYC_AT_SAMPLE_ENA(x) (((x) & 0x1) << 31) +#define G_0286CC_BARYC_AT_SAMPLE_ENA(x) (((x) >> 31) & 0x1) +#define C_0286CC_BARYC_AT_SAMPLE_ENA 0x7FFFFFFF +#define R_0286D0_SPI_PS_IN_CONTROL_1 0x0286D0 +#define S_0286D0_GEN_INDEX_PIX(x) (((x) & 0x1) << 0) +#define G_0286D0_GEN_INDEX_PIX(x) (((x) >> 0) & 0x1) +#define C_0286D0_GEN_INDEX_PIX 0xFFFFFFFE +#define S_0286D0_GEN_INDEX_PIX_ADDR(x) (((x) & 0x7F) << 1) +#define G_0286D0_GEN_INDEX_PIX_ADDR(x) (((x) >> 1) & 0x7F) +#define C_0286D0_GEN_INDEX_PIX_ADDR 0xFFFFFF01 +#define S_0286D0_FRONT_FACE_ENA(x) (((x) & 0x1) << 8) +#define G_0286D0_FRONT_FACE_ENA(x) (((x) >> 8) & 0x1) +#define C_0286D0_FRONT_FACE_ENA 0xFFFFFEFF +#define S_0286D0_FRONT_FACE_CHAN(x) (((x) & 0x3) << 9) +#define G_0286D0_FRONT_FACE_CHAN(x) (((x) >> 9) & 0x3) +#define C_0286D0_FRONT_FACE_CHAN 0xFFFFF9FF +#define S_0286D0_FRONT_FACE_ALL_BITS(x) (((x) & 0x1) << 11) +#define G_0286D0_FRONT_FACE_ALL_BITS(x) (((x) >> 11) & 0x1) +#define C_0286D0_FRONT_FACE_ALL_BITS 0xFFFFF7FF +#define S_0286D0_FRONT_FACE_ADDR(x) (((x) & 0x1F) << 12) +#define G_0286D0_FRONT_FACE_ADDR(x) (((x) >> 12) & 0x1F) +#define C_0286D0_FRONT_FACE_ADDR 0xFFFE0FFF +#define S_0286D0_FOG_ADDR(x) (((x) & 0x7F) << 17) +#define G_0286D0_FOG_ADDR(x) (((x) >> 17) & 0x7F) +#define C_0286D0_FOG_ADDR 0xFF01FFFF +#define S_0286D0_FIXED_PT_POSITION_ENA(x) (((x) & 0x1) << 24) +#define G_0286D0_FIXED_PT_POSITION_ENA(x) (((x) >> 24) & 0x1) +#define C_0286D0_FIXED_PT_POSITION_ENA 0xFEFFFFFF +#define S_0286D0_FIXED_PT_POSITION_ADDR(x) (((x) & 0x1F) << 25) +#define G_0286D0_FIXED_PT_POSITION_ADDR(x) (((x) >> 25) & 0x1F) +#define C_0286D0_FIXED_PT_POSITION_ADDR 0xC1FFFFFF +#define R_0286C4_SPI_VS_OUT_CONFIG 0x0286C4 +#define S_0286C4_VS_PER_COMPONENT(x) (((x) & 0x1) << 0) +#define G_0286C4_VS_PER_COMPONENT(x) (((x) >> 0) & 0x1) +#define C_0286C4_VS_PER_COMPONENT 0xFFFFFFFE +#define S_0286C4_VS_EXPORT_COUNT(x) (((x) & 0x1F) << 1) +#define G_0286C4_VS_EXPORT_COUNT(x) (((x) >> 1) & 0x1F) +#define C_0286C4_VS_EXPORT_COUNT 0xFFFFFFC1 +#define S_0286C4_VS_EXPORTS_FOG(x) (((x) & 0x1) << 8) +#define G_0286C4_VS_EXPORTS_FOG(x) (((x) >> 8) & 0x1) +#define C_0286C4_VS_EXPORTS_FOG 0xFFFFFEFF +#define S_0286C4_VS_OUT_FOG_VEC_ADDR(x) (((x) & 0x1F) << 9) +#define G_0286C4_VS_OUT_FOG_VEC_ADDR(x) (((x) >> 9) & 0x1F) +#define C_0286C4_VS_OUT_FOG_VEC_ADDR 0xFFFFC1FF +#define R_028240_PA_SC_GENERIC_SCISSOR_TL 0x028240 +#define S_028240_TL_X(x) (((x) & 0x3FFF) << 0) +#define G_028240_TL_X(x) (((x) >> 0) & 0x3FFF) +#define C_028240_TL_X 0xFFFFC000 +#define S_028240_TL_Y(x) (((x) & 0x3FFF) << 16) +#define G_028240_TL_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028240_TL_Y 0xC000FFFF +#define S_028240_WINDOW_OFFSET_DISABLE(x) (((x) & 0x1) << 31) +#define G_028240_WINDOW_OFFSET_DISABLE(x) (((x) >> 31) & 0x1) +#define C_028240_WINDOW_OFFSET_DISABLE 0x7FFFFFFF +#define R_028244_PA_SC_GENERIC_SCISSOR_BR 0x028244 +#define S_028244_BR_X(x) (((x) & 0x3FFF) << 0) +#define G_028244_BR_X(x) (((x) >> 0) & 0x3FFF) +#define C_028244_BR_X 0xFFFFC000 +#define S_028244_BR_Y(x) (((x) & 0x3FFF) << 16) +#define G_028244_BR_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028244_BR_Y 0xC000FFFF +#define R_028030_PA_SC_SCREEN_SCISSOR_TL 0x028030 +#define S_028030_TL_X(x) (((x) & 0x7FFF) << 0) +#define G_028030_TL_X(x) (((x) >> 0) & 0x7FFF) +#define C_028030_TL_X 0xFFFF8000 +#define S_028030_TL_Y(x) (((x) & 0x7FFF) << 16) +#define G_028030_TL_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028030_TL_Y 0x8000FFFF +#define R_028034_PA_SC_SCREEN_SCISSOR_BR 0x028034 +#define S_028034_BR_X(x) (((x) & 0x7FFF) << 0) +#define G_028034_BR_X(x) (((x) >> 0) & 0x7FFF) +#define C_028034_BR_X 0xFFFF8000 +#define S_028034_BR_Y(x) (((x) & 0x7FFF) << 16) +#define G_028034_BR_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028034_BR_Y 0x8000FFFF +#define R_028204_PA_SC_WINDOW_SCISSOR_TL 0x028204 +#define S_028204_TL_X(x) (((x) & 0x3FFF) << 0) +#define G_028204_TL_X(x) (((x) >> 0) & 0x3FFF) +#define C_028204_TL_X 0xFFFFC000 +#define S_028204_TL_Y(x) (((x) & 0x3FFF) << 16) +#define G_028204_TL_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028204_TL_Y 0xC000FFFF +#define S_028204_WINDOW_OFFSET_DISABLE(x) (((x) & 0x1) << 31) +#define G_028204_WINDOW_OFFSET_DISABLE(x) (((x) >> 31) & 0x1) +#define C_028204_WINDOW_OFFSET_DISABLE 0x7FFFFFFF +#define R_028208_PA_SC_WINDOW_SCISSOR_BR 0x028208 +#define S_028208_BR_X(x) (((x) & 0x3FFF) << 0) +#define G_028208_BR_X(x) (((x) >> 0) & 0x3FFF) +#define C_028208_BR_X 0xFFFFC000 +#define S_028208_BR_Y(x) (((x) & 0x3FFF) << 16) +#define G_028208_BR_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028208_BR_Y 0xC000FFFF +#define R_0287F0_VGT_DRAW_INITIATOR 0x0287F0 +#define S_0287F0_SOURCE_SELECT(x) (((x) & 0x3) << 0) +#define G_0287F0_SOURCE_SELECT(x) (((x) >> 0) & 0x3) +#define C_0287F0_SOURCE_SELECT 0xFFFFFFFC +#define S_0287F0_MAJOR_MODE(x) (((x) & 0x3) << 2) +#define G_0287F0_MAJOR_MODE(x) (((x) >> 2) & 0x3) +#define C_0287F0_MAJOR_MODE 0xFFFFFFF3 +#define S_0287F0_SPRITE_EN(x) (((x) & 0x1) << 4) +#define G_0287F0_SPRITE_EN(x) (((x) >> 4) & 0x1) +#define C_0287F0_SPRITE_EN 0xFFFFFFEF +#define S_0287F0_NOT_EOP(x) (((x) & 0x1) << 5) +#define G_0287F0_NOT_EOP(x) (((x) >> 5) & 0x1) +#define C_0287F0_NOT_EOP 0xFFFFFFDF +#define S_0287F0_USE_OPAQUE(x) (((x) & 0x1) << 6) +#define G_0287F0_USE_OPAQUE(x) (((x) >> 6) & 0x1) +#define C_0287F0_USE_OPAQUE 0xFFFFFFBF +#define R_0280A0_CB_COLOR0_INFO 0x0280A0 +#define R_0280A4_CB_COLOR1_INFO 0x0280A4 +#define R_0280A8_CB_COLOR2_INFO 0x0280A8 +#define R_0280AC_CB_COLOR3_INFO 0x0280AC +#define R_0280B0_CB_COLOR4_INFO 0x0280B0 +#define R_0280B4_CB_COLOR5_INFO 0x0280B4 +#define R_0280B8_CB_COLOR6_INFO 0x0280B8 +#define R_0280BC_CB_COLOR7_INFO 0x0280BC +#define R_02800C_DB_DEPTH_BASE 0x02800C +#define R_028000_DB_DEPTH_SIZE 0x028000 +#define R_028004_DB_DEPTH_VIEW 0x028004 +#define R_028010_DB_DEPTH_INFO 0x028010 +#define R_028D24_DB_HTILE_SURFACE 0x028D24 +#define R_028D34_DB_PREFETCH_LIMIT 0x028D34 +#define R_0286D4_SPI_INTERP_CONTROL_0 0x0286D4 +#define R_028A48_PA_SC_MPASS_PS_CNTL 0x028A48 +#define R_028C00_PA_SC_LINE_CNTL 0x028C00 +#define S_028C00_LAST_PIXEL(x) (((x) & 0x1) << 10) +#define G_028C00_LAST_PIXEL(x) (((x) >> 10) & 0x1) +#define C_028C00_LAST_PIXEL 0xFFFFFBFF +#define R_028C04_PA_SC_AA_CONFIG 0x028C04 +#define R_028C08_PA_SU_VTX_CNTL 0x028C08 +#define S_028C08_PIX_CENTER_HALF(x) (((x) & 0x1) << 0) +#define G_028C08_PIX_CENTER_HALF(x) (((x) >> 0) & 0x1) +#define C_028C08_PIX_CENTER_HALF 0xFFFFFFFE +#define R_028C1C_PA_SC_AA_SAMPLE_LOCS_MCTX 0x028C1C +#define R_028C48_PA_SC_AA_MASK 0x028C48 +#define R_028810_PA_CL_CLIP_CNTL 0x028810 +#define R_02881C_PA_CL_VS_OUT_CNTL 0x02881C +#define R_028820_PA_CL_NANINF_CNTL 0x028820 +#define R_028C0C_PA_CL_GB_VERT_CLIP_ADJ 0x028C0C +#define R_028C10_PA_CL_GB_VERT_DISC_ADJ 0x028C10 +#define R_028C14_PA_CL_GB_HORZ_CLIP_ADJ 0x028C14 +#define R_028C18_PA_CL_GB_HORZ_DISC_ADJ 0x028C18 +#define R_028814_PA_SU_SC_MODE_CNTL 0x028814 +#define R_028A00_PA_SU_POINT_SIZE 0x028A00 +#define R_028A04_PA_SU_POINT_MINMAX 0x028A04 +#define S_028A04_MIN_SIZE(x) (((x) & 0xFFFF) << 0) +#define G_028A04_MIN_SIZE(x) (((x) >> 0) & 0xFFFF) +#define C_028A04_MIN_SIZE 0xFFFF0000 +#define S_028A04_MAX_SIZE(x) (((x) & 0xFFFF) << 16) +#define G_028A04_MAX_SIZE(x) (((x) >> 16) & 0xFFFF) +#define C_028A04_MAX_SIZE 0x0000FFFF +#define R_028A08_PA_SU_LINE_CNTL 0x028A08 +#define S_028A08_WIDTH(x) (((x) & 0xFFFF) << 0) +#define G_028A08_WIDTH(x) (((x) >> 0) & 0xFFFF) +#define C_028A08_WIDTH 0xFFFF0000 +#define R_028A0C_PA_SC_LINE_STIPPLE 0x028A0C +#define R_028DF8_PA_SU_POLY_OFFSET_DB_FMT_CNTL 0x028DF8 +#define R_028DFC_PA_SU_POLY_OFFSET_CLAMP 0x028DFC +#define R_028E00_PA_SU_POLY_OFFSET_FRONT_SCALE 0x028E00 +#define R_028E04_PA_SU_POLY_OFFSET_FRONT_OFFSET 0x028E04 +#define R_028E08_PA_SU_POLY_OFFSET_BACK_SCALE 0x028E08 +#define R_028E0C_PA_SU_POLY_OFFSET_BACK_OFFSET 0x028E0C +#define R_028818_PA_CL_VTE_CNTL 0x028818 +#define S_028818_VPORT_X_SCALE_ENA(x) (((x) & 0x1) << 0) +#define G_028818_VPORT_X_SCALE_ENA(x) (((x) >> 0 & 0x1) +#define C_028818_VPORT_X_SCALE_ENA 0xFFFFFFFE +#define S_028818_VPORT_X_OFFSET_ENA(x) (((x) & 0x1) << 1) +#define G_028818_VPORT_X_OFFSET_ENA(x) (((x) >> 1 & 0x1) +#define C_028818_VPORT_X_OFFSET_ENA 0xFFFFFFFD +#define S_028818_VPORT_Y_SCALE_ENA(x) (((x) & 0x1) << 2) +#define G_028818_VPORT_Y_SCALE_ENA(x) (((x) >> 2 & 0x1) +#define C_028818_VPORT_Y_SCALE_ENA 0xFFFFFFFB +#define S_028818_VPORT_Y_OFFSET_ENA(x) (((x) & 0x1) << 3) +#define G_028818_VPORT_Y_OFFSET_ENA(x) (((x) >> 3 & 0x1) +#define C_028818_VPORT_Y_OFFSET_ENA 0xFFFFFFF7 +#define S_028818_VPORT_Z_SCALE_ENA(x) (((x) & 0x1) << 4) +#define G_028818_VPORT_Z_SCALE_ENA(x) (((x) >> 4 & 0x1) +#define C_028818_VPORT_Z_SCALE_ENA 0xFFFFFFEF +#define S_028818_VPORT_Z_OFFSET_ENA(x) (((x) & 0x1) << 5) +#define G_028818_VPORT_Z_OFFSET_ENA(x) (((x) >> 5 & 0x1) +#define C_028818_VPORT_Z_OFFSET_ENA 0xFFFFFFDF +#define S_028818_VTX_W0_FMT(x) (((x) & 0x1) << 10) +#define G_028818_VTX_W0_FMT(x) (((x) >> 10) & 0x1) +#define C_028818_VTX_W0_FMT 0xFFFFFBFF +#define R_02843C_PA_CL_VPORT_XSCALE_0 0x02843C +#define R_028444_PA_CL_VPORT_YSCALE_0 0x028444 +#define R_02844C_PA_CL_VPORT_ZSCALE_0 0x02844C +#define R_028440_PA_CL_VPORT_XOFFSET_0 0x028440 +#define R_028448_PA_CL_VPORT_YOFFSET_0 0x028448 +#define R_028450_PA_CL_VPORT_ZOFFSET_0 0x028450 +#define R_028250_PA_SC_VPORT_SCISSOR_0_TL 0x028250 +#define R_028254_PA_SC_VPORT_SCISSOR_0_BR 0x028254 +#define R_028780_CB_BLEND0_CONTROL 0x028780 +#define R_028784_CB_BLEND1_CONTROL 0x028784 +#define R_028788_CB_BLEND2_CONTROL 0x028788 +#define R_02878C_CB_BLEND3_CONTROL 0x02878C +#define R_028790_CB_BLEND4_CONTROL 0x028790 +#define R_028794_CB_BLEND5_CONTROL 0x028794 +#define R_028798_CB_BLEND6_CONTROL 0x028798 +#define R_02879C_CB_BLEND7_CONTROL 0x02879C +#define R_028804_CB_BLEND_CONTROL 0x028804 +#define R_028028_DB_STENCIL_CLEAR 0x028028 +#define R_02802C_DB_DEPTH_CLEAR 0x02802C +#define R_028430_DB_STENCILREFMASK 0x028430 +#define R_028434_DB_STENCILREFMASK_BF 0x028434 +#define R_028800_DB_DEPTH_CONTROL 0x028800 +#define R_02880C_DB_SHADER_CONTROL 0x02880C +#define R_028D0C_DB_RENDER_CONTROL 0x028D0C +#define R_028D10_DB_RENDER_OVERRIDE 0x028D10 +#define R_028D2C_DB_SRESULTS_COMPARE_STATE1 0x028D2C +#define R_028D30_DB_PRELOAD_CONTROL 0x028D30 +#define R_028D44_DB_ALPHA_TO_MASK 0x028D44 +#define R_028868_SQ_PGM_RESOURCES_VS 0x028868 +#define R_0286CC_SPI_PS_IN_CONTROL_0 0x0286CC +#define R_0286D0_SPI_PS_IN_CONTROL_1 0x0286D0 +#define R_028644_SPI_PS_INPUT_CNTL_0 0x028644 +#define R_028648_SPI_PS_INPUT_CNTL_1 0x028648 +#define R_02864C_SPI_PS_INPUT_CNTL_2 0x02864C +#define R_028650_SPI_PS_INPUT_CNTL_3 0x028650 +#define R_028654_SPI_PS_INPUT_CNTL_4 0x028654 +#define R_028658_SPI_PS_INPUT_CNTL_5 0x028658 +#define R_02865C_SPI_PS_INPUT_CNTL_6 0x02865C +#define R_028660_SPI_PS_INPUT_CNTL_7 0x028660 +#define R_028664_SPI_PS_INPUT_CNTL_8 0x028664 +#define R_028668_SPI_PS_INPUT_CNTL_9 0x028668 +#define R_02866C_SPI_PS_INPUT_CNTL_10 0x02866C +#define R_028670_SPI_PS_INPUT_CNTL_11 0x028670 +#define R_028674_SPI_PS_INPUT_CNTL_12 0x028674 +#define R_028678_SPI_PS_INPUT_CNTL_13 0x028678 +#define R_02867C_SPI_PS_INPUT_CNTL_14 0x02867C +#define R_028680_SPI_PS_INPUT_CNTL_15 0x028680 +#define R_028684_SPI_PS_INPUT_CNTL_16 0x028684 +#define R_028688_SPI_PS_INPUT_CNTL_17 0x028688 +#define R_02868C_SPI_PS_INPUT_CNTL_18 0x02868C +#define R_028690_SPI_PS_INPUT_CNTL_19 0x028690 +#define R_028694_SPI_PS_INPUT_CNTL_20 0x028694 +#define R_028698_SPI_PS_INPUT_CNTL_21 0x028698 +#define R_02869C_SPI_PS_INPUT_CNTL_22 0x02869C +#define R_0286A0_SPI_PS_INPUT_CNTL_23 0x0286A0 +#define R_0286A4_SPI_PS_INPUT_CNTL_24 0x0286A4 +#define R_0286A8_SPI_PS_INPUT_CNTL_25 0x0286A8 +#define R_0286AC_SPI_PS_INPUT_CNTL_26 0x0286AC +#define R_0286B0_SPI_PS_INPUT_CNTL_27 0x0286B0 +#define R_0286B4_SPI_PS_INPUT_CNTL_28 0x0286B4 +#define R_0286B8_SPI_PS_INPUT_CNTL_29 0x0286B8 +#define R_0286BC_SPI_PS_INPUT_CNTL_30 0x0286BC +#define R_0286C0_SPI_PS_INPUT_CNTL_31 0x0286C0 +#define R_028850_SQ_PGM_RESOURCES_PS 0x028850 +#define R_028854_SQ_PGM_EXPORTS_PS 0x028854 +#define S_028854_EXPORT_COLORS(x) (((x) & 0xF) << 1) +#define G_028854_EXPORT_COLORS(x) (((x) >> 1) & 0xF) +#define C_028854_EXPORT_COLORS 0xFFFFFFE1 +#define S_028854_EXPORT_Z(x) (((x) & 0x1) << 0) +#define G_028854_EXPORT_Z(x) (((x) >> 0) & 0x1) +#define C_028854_EXPORT_Z 0xFFFFFFFE +#define R_008958_VGT_PRIMITIVE_TYPE 0x008958 +#define R_028A7C_VGT_DMA_INDEX_TYPE 0x028A7C +#define R_028A88_VGT_DMA_NUM_INSTANCES 0x028A88 +#define R_008970_VGT_NUM_INDICES 0x008970 +#define R_0287F0_VGT_DRAW_INITIATOR 0x0287F0 +#define R_028238_CB_TARGET_MASK 0x028238 +#define R_02823C_CB_SHADER_MASK 0x02823C +#define R_028060_CB_COLOR0_SIZE 0x028060 +#define S_028060_PITCH_TILE_MAX(x) (((x) & 0x3FF) << 0) +#define G_028060_PITCH_TILE_MAX(x) (((x) >> 0) & 0x3FF) +#define C_028060_PITCH_TILE_MAX 0xFFFFFC00 +#define S_028060_SLICE_TILE_MAX(x) (((x) & 0xFFFFF) << 10) +#define G_028060_SLICE_TILE_MAX(x) (((x) >> 10) & 0xFFFFF) +#define C_028060_SLICE_TILE_MAX 0xC00003FF +#define R_028064_CB_COLOR1_SIZE 0x028064 +#define R_028068_CB_COLOR2_SIZE 0x028068 +#define R_02806C_CB_COLOR3_SIZE 0x02806C +#define R_028070_CB_COLOR4_SIZE 0x028070 +#define R_028074_CB_COLOR5_SIZE 0x028074 +#define R_028078_CB_COLOR6_SIZE 0x028078 +#define R_02807C_CB_COLOR7_SIZE 0x02807C +#define R_028040_CB_COLOR0_BASE 0x028040 +#define R_028044_CB_COLOR1_BASE 0x028044 +#define R_028048_CB_COLOR2_BASE 0x028048 +#define R_02804C_CB_COLOR3_BASE 0x02804C +#define R_028050_CB_COLOR4_BASE 0x028050 +#define R_028054_CB_COLOR5_BASE 0x028054 +#define R_028058_CB_COLOR6_BASE 0x028058 +#define R_02805C_CB_COLOR7_BASE 0x02805C +#define R_028240_PA_SC_GENERIC_SCISSOR_TL 0x028240 +#define S_028240_TL_X(x) (((x) & 0x3FFF) << 0) +#define G_028240_TL_X(x) (((x) >> 0) & 0x3FFF) +#define C_028240_TL_X 0xFFFFC000 +#define S_028240_TL_Y(x) (((x) & 0x3FFF) << 16) +#define G_028240_TL_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028240_TL_Y 0xC000FFFF +#define R_028C04_PA_SC_AA_CONFIG 0x028C04 +#define S_028C04_MSAA_NUM_SAMPLES(x) (((x) & 0x3) << 0) +#define G_028C04_MSAA_NUM_SAMPLES(x) (((x) >> 0) & 0x3) +#define C_028C04_MSAA_NUM_SAMPLES 0xFFFFFFFC +#define S_028C04_AA_MASK_CENTROID_DTMN(x) (((x) & 0x1) << 4) +#define G_028C04_AA_MASK_CENTROID_DTMN(x) (((x) >> 4) & 0x1) +#define C_028C04_AA_MASK_CENTROID_DTMN 0xFFFFFFEF +#define S_028C04_MAX_SAMPLE_DIST(x) (((x) & 0xF) << 13) +#define G_028C04_MAX_SAMPLE_DIST(x) (((x) >> 13) & 0xF) +#define C_028C04_MAX_SAMPLE_DIST 0xFFFE1FFF +#define R_0288CC_SQ_PGM_CF_OFFSET_PS 0x0288CC +#define R_0288DC_SQ_PGM_CF_OFFSET_FS 0x0288DC +#define R_0288D0_SQ_PGM_CF_OFFSET_VS 0x0288D0 +#define R_028840_SQ_PGM_START_PS 0x028840 +#define R_028894_SQ_PGM_START_FS 0x028894 +#define R_028858_SQ_PGM_START_VS 0x028858 +#define R_028080_CB_COLOR0_VIEW 0x028080 +#define S_028080_SLICE_START(x) (((x) & 0x7FF) << 0) +#define G_028080_SLICE_START(x) (((x) >> 0) & 0x7FF) +#define C_028080_SLICE_START 0xFFFFF800 +#define S_028080_SLICE_MAX(x) (((x) & 0x7FF) << 13) +#define G_028080_SLICE_MAX(x) (((x) >> 13) & 0x7FF) +#define C_028080_SLICE_MAX 0xFF001FFF +#define R_028084_CB_COLOR1_VIEW 0x028084 +#define R_028088_CB_COLOR2_VIEW 0x028088 +#define R_02808C_CB_COLOR3_VIEW 0x02808C +#define R_028090_CB_COLOR4_VIEW 0x028090 +#define R_028094_CB_COLOR5_VIEW 0x028094 +#define R_028098_CB_COLOR6_VIEW 0x028098 +#define R_02809C_CB_COLOR7_VIEW 0x02809C +#define R_028100_CB_COLOR0_MASK 0x028100 +#define S_028100_CMASK_BLOCK_MAX(x) (((x) & 0xFFF) << 0) +#define G_028100_CMASK_BLOCK_MAX(x) (((x) >> 0) & 0xFFF) +#define C_028100_CMASK_BLOCK_MAX 0xFFFFF000 +#define S_028100_FMASK_TILE_MAX(x) (((x) & 0xFFFFF) << 12) +#define G_028100_FMASK_TILE_MAX(x) (((x) >> 12) & 0xFFFFF) +#define C_028100_FMASK_TILE_MAX 0x00000FFF +#define R_028104_CB_COLOR1_MASK 0x028104 +#define R_028108_CB_COLOR2_MASK 0x028108 +#define R_02810C_CB_COLOR3_MASK 0x02810C +#define R_028110_CB_COLOR4_MASK 0x028110 +#define R_028114_CB_COLOR5_MASK 0x028114 +#define R_028118_CB_COLOR6_MASK 0x028118 +#define R_02811C_CB_COLOR7_MASK 0x02811C +#define R_028040_CB_COLOR0_BASE 0x028040 +#define S_028040_BASE_256B(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028040_BASE_256B(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028040_BASE_256B 0x00000000 +#define R_0280E0_CB_COLOR0_FRAG 0x0280E0 +#define S_0280E0_BASE_256B(x) (((x) & 0xFFFFFFFF) << 0) +#define G_0280E0_BASE_256B(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_0280E0_BASE_256B 0x00000000 +#define R_0280E4_CB_COLOR1_FRAG 0x0280E4 +#define R_0280E8_CB_COLOR2_FRAG 0x0280E8 +#define R_0280EC_CB_COLOR3_FRAG 0x0280EC +#define R_0280F0_CB_COLOR4_FRAG 0x0280F0 +#define R_0280F4_CB_COLOR5_FRAG 0x0280F4 +#define R_0280F8_CB_COLOR6_FRAG 0x0280F8 +#define R_0280FC_CB_COLOR7_FRAG 0x0280FC +#define R_0280C0_CB_COLOR0_TILE 0x0280C0 +#define S_0280C0_BASE_256B(x) (((x) & 0xFFFFFFFF) << 0) +#define G_0280C0_BASE_256B(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_0280C0_BASE_256B 0x00000000 +#define R_0280C4_CB_COLOR1_TILE 0x0280C4 +#define R_0280C8_CB_COLOR2_TILE 0x0280C8 +#define R_0280CC_CB_COLOR3_TILE 0x0280CC +#define R_0280D0_CB_COLOR4_TILE 0x0280D0 +#define R_0280D4_CB_COLOR5_TILE 0x0280D4 +#define R_0280D8_CB_COLOR6_TILE 0x0280D8 +#define R_0280DC_CB_COLOR7_TILE 0x0280DC +#define R_028808_CB_COLOR_CONTROL 0x028808 +#define S_028808_FOG_ENABLE(x) (((x) & 0x1) << 0) +#define G_028808_FOG_ENABLE(x) (((x) >> 0) & 0x1) +#define C_028808_FOG_ENABLE 0xFFFFFFFE +#define S_028808_MULTIWRITE_ENABLE(x) (((x) & 0x1) << 1) +#define G_028808_MULTIWRITE_ENABLE(x) (((x) >> 1) & 0x1) +#define C_028808_MULTIWRITE_ENABLE 0xFFFFFFFD +#define S_028808_DITHER_ENABLE(x) (((x) & 0x1) << 2) +#define G_028808_DITHER_ENABLE(x) (((x) >> 2) & 0x1) +#define C_028808_DITHER_ENABLE 0xFFFFFFFB +#define S_028808_DEGAMMA_ENABLE(x) (((x) & 0x1) << 3) +#define G_028808_DEGAMMA_ENABLE(x) (((x) >> 3) & 0x1) +#define C_028808_DEGAMMA_ENABLE 0xFFFFFFF7 +#define S_028808_SPECIAL_OP(x) (((x) & 0x7) << 4) +#define G_028808_SPECIAL_OP(x) (((x) >> 4) & 0x7) +#define C_028808_SPECIAL_OP 0xFFFFFF8F +#define S_028808_PER_MRT_BLEND(x) (((x) & 0x1) << 7) +#define G_028808_PER_MRT_BLEND(x) (((x) >> 7) & 0x1) +#define C_028808_PER_MRT_BLEND 0xFFFFFF7F +#define S_028808_TARGET_BLEND_ENABLE(x) (((x) & 0xFF) << 8) +#define G_028808_TARGET_BLEND_ENABLE(x) (((x) >> 8) & 0xFF) +#define C_028808_TARGET_BLEND_ENABLE 0xFFFF00FF +#define S_028808_ROP3(x) (((x) & 0xFF) << 16) +#define G_028808_ROP3(x) (((x) >> 16) & 0xFF) +#define C_028808_ROP3 0xFF00FFFF +#define R_028614_SPI_VS_OUT_ID_0 0x028614 +#define S_028614_SEMANTIC_0(x) (((x) & 0xFF) << 0) +#define G_028614_SEMANTIC_0(x) (((x) >> 0) & 0xFF) +#define C_028614_SEMANTIC_0 0xFFFFFF00 +#define S_028614_SEMANTIC_1(x) (((x) & 0xFF) << 8) +#define G_028614_SEMANTIC_1(x) (((x) >> 8) & 0xFF) +#define C_028614_SEMANTIC_1 0xFFFF00FF +#define S_028614_SEMANTIC_2(x) (((x) & 0xFF) << 16) +#define G_028614_SEMANTIC_2(x) (((x) >> 16) & 0xFF) +#define C_028614_SEMANTIC_2 0xFF00FFFF +#define S_028614_SEMANTIC_3(x) (((x) & 0xFF) << 24) +#define G_028614_SEMANTIC_3(x) (((x) >> 24) & 0xFF) +#define C_028614_SEMANTIC_3 0x00FFFFFF +#define R_028618_SPI_VS_OUT_ID_1 0x028618 +#define R_02861C_SPI_VS_OUT_ID_2 0x02861C +#define R_028620_SPI_VS_OUT_ID_3 0x028620 +#define R_028624_SPI_VS_OUT_ID_4 0x028624 +#define R_028628_SPI_VS_OUT_ID_5 0x028628 +#define R_02862C_SPI_VS_OUT_ID_6 0x02862C +#define R_028630_SPI_VS_OUT_ID_7 0x028630 +#define R_028634_SPI_VS_OUT_ID_8 0x028634 +#define R_028638_SPI_VS_OUT_ID_9 0x028638 +#define R_038000_SQ_TEX_RESOURCE_WORD0_0 0x038000 +#define S_038000_DIM(x) (((x) & 0x7) << 0) +#define G_038000_DIM(x) (((x) >> 0) & 0x7) +#define C_038000_DIM 0xFFFFFFF8 +#define S_038000_TILE_MODE(x) (((x) & 0xF) << 3) +#define G_038000_TILE_MODE(x) (((x) >> 3) & 0xF) +#define C_038000_TILE_MODE 0xFFFFFF87 +#define S_038000_TILE_TYPE(x) (((x) & 0x1) << 7) +#define G_038000_TILE_TYPE(x) (((x) >> 7) & 0x1) +#define C_038000_TILE_TYPE 0xFFFFFF7F +#define S_038000_PITCH(x) (((x) & 0x7FF) << 8) +#define G_038000_PITCH(x) (((x) >> 8) & 0x7FF) +#define C_038000_PITCH 0xFFF800FF +#define S_038000_TEX_WIDTH(x) (((x) & 0x1FFF) << 19) +#define G_038000_TEX_WIDTH(x) (((x) >> 19) & 0x1FFF) +#define C_038000_TEX_WIDTH 0x0007FFFF +#define R_038004_SQ_TEX_RESOURCE_WORD1_0 0x038004 +#define S_038004_TEX_HEIGHT(x) (((x) & 0x1FFF) << 0) +#define G_038004_TEX_HEIGHT(x) (((x) >> 0) & 0x1FFF) +#define C_038004_TEX_HEIGHT 0xFFFFE000 +#define S_038004_TEX_DEPTH(x) (((x) & 0x1FFF) << 13) +#define G_038004_TEX_DEPTH(x) (((x) >> 13) & 0x1FFF) +#define C_038004_TEX_DEPTH 0xFC001FFF +#define S_038004_DATA_FORMAT(x) (((x) & 0x3F) << 26) +#define G_038004_DATA_FORMAT(x) (((x) >> 26) & 0x3F) +#define C_038004_DATA_FORMAT 0x03FFFFFF +#define V_038004_COLOR_INVALID 0x00000000 +#define V_038004_COLOR_8 0x00000001 +#define V_038004_COLOR_4_4 0x00000002 +#define V_038004_COLOR_3_3_2 0x00000003 +#define V_038004_COLOR_16 0x00000005 +#define V_038004_COLOR_16_FLOAT 0x00000006 +#define V_038004_COLOR_8_8 0x00000007 +#define V_038004_COLOR_5_6_5 0x00000008 +#define V_038004_COLOR_6_5_5 0x00000009 +#define V_038004_COLOR_1_5_5_5 0x0000000A +#define V_038004_COLOR_4_4_4_4 0x0000000B +#define V_038004_COLOR_5_5_5_1 0x0000000C +#define V_038004_COLOR_32 0x0000000D +#define V_038004_COLOR_32_FLOAT 0x0000000E +#define V_038004_COLOR_16_16 0x0000000F +#define V_038004_COLOR_16_16_FLOAT 0x00000010 +#define V_038004_COLOR_8_24 0x00000011 +#define V_038004_COLOR_8_24_FLOAT 0x00000012 +#define V_038004_COLOR_24_8 0x00000013 +#define V_038004_COLOR_24_8_FLOAT 0x00000014 +#define V_038004_COLOR_10_11_11 0x00000015 +#define V_038004_COLOR_10_11_11_FLOAT 0x00000016 +#define V_038004_COLOR_11_11_10 0x00000017 +#define V_038004_COLOR_11_11_10_FLOAT 0x00000018 +#define V_038004_COLOR_2_10_10_10 0x00000019 +#define V_038004_COLOR_8_8_8_8 0x0000001A +#define V_038004_COLOR_10_10_10_2 0x0000001B +#define V_038004_COLOR_X24_8_32_FLOAT 0x0000001C +#define V_038004_COLOR_32_32 0x0000001D +#define V_038004_COLOR_32_32_FLOAT 0x0000001E +#define V_038004_COLOR_16_16_16_16 0x0000001F +#define V_038004_COLOR_16_16_16_16_FLOAT 0x00000020 +#define V_038004_COLOR_32_32_32_32 0x00000022 +#define V_038004_COLOR_32_32_32_32_FLOAT 0x00000023 +#define R_038008_SQ_TEX_RESOURCE_WORD2_0 0x038008 +#define S_038008_BASE_ADDRESS(x) (((x) & 0xFFFFFFFF) << 0) +#define G_038008_BASE_ADDRESS(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_038008_BASE_ADDRESS 0x00000000 +#define R_03800C_SQ_TEX_RESOURCE_WORD3_0 0x03800C +#define S_03800C_MIP_ADDRESS(x) (((x) & 0xFFFFFFFF) << 0) +#define G_03800C_MIP_ADDRESS(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_03800C_MIP_ADDRESS 0x00000000 +#define R_038010_SQ_TEX_RESOURCE_WORD4_0 0x038010 +#define S_038010_FORMAT_COMP_X(x) (((x) & 0x3) << 0) +#define G_038010_FORMAT_COMP_X(x) (((x) >> 0) & 0x3) +#define C_038010_FORMAT_COMP_X 0xFFFFFFFC +#define S_038010_FORMAT_COMP_Y(x) (((x) & 0x3) << 2) +#define G_038010_FORMAT_COMP_Y(x) (((x) >> 2) & 0x3) +#define C_038010_FORMAT_COMP_Y 0xFFFFFFF3 +#define S_038010_FORMAT_COMP_Z(x) (((x) & 0x3) << 4) +#define G_038010_FORMAT_COMP_Z(x) (((x) >> 4) & 0x3) +#define C_038010_FORMAT_COMP_Z 0xFFFFFFCF +#define S_038010_FORMAT_COMP_W(x) (((x) & 0x3) << 6) +#define G_038010_FORMAT_COMP_W(x) (((x) >> 6) & 0x3) +#define C_038010_FORMAT_COMP_W 0xFFFFFF3F +#define S_038010_NUM_FORMAT_ALL(x) (((x) & 0x3) << 8) +#define G_038010_NUM_FORMAT_ALL(x) (((x) >> 8) & 0x3) +#define C_038010_NUM_FORMAT_ALL 0xFFFFFCFF +#define S_038010_SRF_MODE_ALL(x) (((x) & 0x1) << 10) +#define G_038010_SRF_MODE_ALL(x) (((x) >> 10) & 0x1) +#define C_038010_SRF_MODE_ALL 0xFFFFFBFF +#define S_038010_FORCE_DEGAMMA(x) (((x) & 0x1) << 11) +#define G_038010_FORCE_DEGAMMA(x) (((x) >> 11) & 0x1) +#define C_038010_FORCE_DEGAMMA 0xFFFFF7FF +#define S_038010_ENDIAN_SWAP(x) (((x) & 0x3) << 12) +#define G_038010_ENDIAN_SWAP(x) (((x) >> 12) & 0x3) +#define C_038010_ENDIAN_SWAP 0xFFFFCFFF +#define S_038010_REQUEST_SIZE(x) (((x) & 0x3) << 14) +#define G_038010_REQUEST_SIZE(x) (((x) >> 14) & 0x3) +#define C_038010_REQUEST_SIZE 0xFFFF3FFF +#define S_038010_DST_SEL_X(x) (((x) & 0x7) << 16) +#define G_038010_DST_SEL_X(x) (((x) >> 16) & 0x7) +#define C_038010_DST_SEL_X 0xFFF8FFFF +#define S_038010_DST_SEL_Y(x) (((x) & 0x7) << 19) +#define G_038010_DST_SEL_Y(x) (((x) >> 19) & 0x7) +#define C_038010_DST_SEL_Y 0xFFC7FFFF +#define S_038010_DST_SEL_Z(x) (((x) & 0x7) << 22) +#define G_038010_DST_SEL_Z(x) (((x) >> 22) & 0x7) +#define C_038010_DST_SEL_Z 0xFE3FFFFF +#define S_038010_DST_SEL_W(x) (((x) & 0x7) << 25) +#define G_038010_DST_SEL_W(x) (((x) >> 25) & 0x7) +#define C_038010_DST_SEL_W 0xF1FFFFFF +#define S_038010_BASE_LEVEL(x) (((x) & 0xF) << 28) +#define G_038010_BASE_LEVEL(x) (((x) >> 28) & 0xF) +#define C_038010_BASE_LEVEL 0x0FFFFFFF +#define R_038014_SQ_TEX_RESOURCE_WORD5_0 0x038014 +#define S_038014_LAST_LEVEL(x) (((x) & 0xF) << 0) +#define G_038014_LAST_LEVEL(x) (((x) >> 0) & 0xF) +#define C_038014_LAST_LEVEL 0xFFFFFFF0 +#define S_038014_BASE_ARRAY(x) (((x) & 0x1FFF) << 4) +#define G_038014_BASE_ARRAY(x) (((x) >> 4) & 0x1FFF) +#define C_038014_BASE_ARRAY 0xFFFE000F +#define S_038014_LAST_ARRAY(x) (((x) & 0x1FFF) << 17) +#define G_038014_LAST_ARRAY(x) (((x) >> 17) & 0x1FFF) +#define C_038014_LAST_ARRAY 0xC001FFFF +#define R_038018_SQ_TEX_RESOURCE_WORD6_0 0x038018 +#define S_038018_MPEG_CLAMP(x) (((x) & 0x3) << 0) +#define G_038018_MPEG_CLAMP(x) (((x) >> 0) & 0x3) +#define C_038018_MPEG_CLAMP 0xFFFFFFFC +#define S_038018_PERF_MODULATION(x) (((x) & 0x7) << 5) +#define G_038018_PERF_MODULATION(x) (((x) >> 5) & 0x7) +#define C_038018_PERF_MODULATION 0xFFFFFF1F +#define S_038018_INTERLACED(x) (((x) & 0x1) << 8) +#define G_038018_INTERLACED(x) (((x) >> 8) & 0x1) +#define C_038018_INTERLACED 0xFFFFFEFF +#define S_038018_TYPE(x) (((x) & 0x3) << 30) +#define G_038018_TYPE(x) (((x) >> 30) & 0x3) +#define C_038018_TYPE 0x3FFFFFFF +#define R_008040_WAIT_UNTIL 0x008040 +#define S_008040_WAIT_CP_DMA_IDLE(x) (((x) & 0x1) << 8) +#define G_008040_WAIT_CP_DMA_IDLE(x) (((x) >> 8) & 0x1) +#define C_008040_WAIT_CP_DMA_IDLE 0xFFFFFEFF +#define S_008040_WAIT_CMDFIFO(x) (((x) & 0x1) << 10) +#define G_008040_WAIT_CMDFIFO(x) (((x) >> 10) & 0x1) +#define C_008040_WAIT_CMDFIFO 0xFFFFFBFF +#define S_008040_WAIT_2D_IDLE(x) (((x) & 0x1) << 14) +#define G_008040_WAIT_2D_IDLE(x) (((x) >> 14) & 0x1) +#define C_008040_WAIT_2D_IDLE 0xFFFFBFFF +#define S_008040_WAIT_3D_IDLE(x) (((x) & 0x1) << 15) +#define G_008040_WAIT_3D_IDLE(x) (((x) >> 15) & 0x1) +#define C_008040_WAIT_3D_IDLE 0xFFFF7FFF +#define S_008040_WAIT_2D_IDLECLEAN(x) (((x) & 0x1) << 16) +#define G_008040_WAIT_2D_IDLECLEAN(x) (((x) >> 16) & 0x1) +#define C_008040_WAIT_2D_IDLECLEAN 0xFFFEFFFF +#define S_008040_WAIT_3D_IDLECLEAN(x) (((x) & 0x1) << 17) +#define G_008040_WAIT_3D_IDLECLEAN(x) (((x) >> 17) & 0x1) +#define C_008040_WAIT_3D_IDLECLEAN 0xFFFDFFFF +#define S_008040_WAIT_EXTERN_SIG(x) (((x) & 0x1) << 19) +#define G_008040_WAIT_EXTERN_SIG(x) (((x) >> 19) & 0x1) +#define C_008040_WAIT_EXTERN_SIG 0xFFF7FFFF +#define S_008040_CMDFIFO_ENTRIES(x) (((x) & 0x1F) << 20) +#define G_008040_CMDFIFO_ENTRIES(x) (((x) >> 20) & 0x1F) +#define C_008040_CMDFIFO_ENTRIES 0xFE0FFFFF +#define R_008958_VGT_PRIMITIVE_TYPE 0x008958 +#define S_008958_PRIM_TYPE(x) (((x) & 0x3F) << 0) +#define G_008958_PRIM_TYPE(x) (((x) >> 0) & 0x3F) +#define C_008958_PRIM_TYPE 0xFFFFFFC0 +#define R_008C08_SQ_GPR_RESOURCE_MGMT_2 0x008C08 +#define S_008C08_NUM_GS_GPRS(x) (((x) & 0xFF) << 0) +#define G_008C08_NUM_GS_GPRS(x) (((x) >> 0) & 0xFF) +#define C_008C08_NUM_GS_GPRS 0xFFFFFF00 +#define S_008C08_NUM_ES_GPRS(x) (((x) & 0xFF) << 16) +#define G_008C08_NUM_ES_GPRS(x) (((x) >> 16) & 0xFF) +#define C_008C08_NUM_ES_GPRS 0xFF00FFFF +#define R_008D8C_SQ_DYN_GPR_CNTL_PS_FLUSH_REQ 0x008D8C +#define S_008D8C_RING0_OFFSET(x) (((x) & 0xFF) << 0) +#define G_008D8C_RING0_OFFSET(x) (((x) >> 0) & 0xFF) +#define C_008D8C_RING0_OFFSET 0xFFFFFF00 +#define S_008D8C_ISOLATE_ES_ENABLE(x) (((x) & 0x1) << 12) +#define G_008D8C_ISOLATE_ES_ENABLE(x) (((x) >> 12) & 0x1) +#define C_008D8C_ISOLATE_ES_ENABLE 0xFFFFEFFF +#define S_008D8C_ISOLATE_GS_ENABLE(x) (((x) & 0x1) << 13) +#define G_008D8C_ISOLATE_GS_ENABLE(x) (((x) >> 13) & 0x1) +#define C_008D8C_ISOLATE_GS_ENABLE 0xFFFFDFFF +#define S_008D8C_VS_PC_LIMIT_ENABLE(x) (((x) & 0x1) << 14) +#define G_008D8C_VS_PC_LIMIT_ENABLE(x) (((x) >> 14) & 0x1) +#define C_008D8C_VS_PC_LIMIT_ENABLE 0xFFFFBFFF +#define R_009508_TA_CNTL_AUX 0x009508 +#define S_009508_DISABLE_CUBE_WRAP(x) (((x) & 0x1) << 0) +#define G_009508_DISABLE_CUBE_WRAP(x) (((x) >> 0) & 0x1) +#define C_009508_DISABLE_CUBE_WRAP 0xFFFFFFFE +#define S_009508_SYNC_GRADIENT(x) (((x) & 0x1) << 24) +#define G_009508_SYNC_GRADIENT(x) (((x) >> 24) & 0x1) +#define C_009508_SYNC_GRADIENT 0xFEFFFFFF +#define S_009508_SYNC_WALKER(x) (((x) & 0x1) << 25) +#define G_009508_SYNC_WALKER(x) (((x) >> 25) & 0x1) +#define C_009508_SYNC_WALKER 0xFDFFFFFF +#define S_009508_SYNC_ALIGNER(x) (((x) & 0x1) << 26) +#define G_009508_SYNC_ALIGNER(x) (((x) >> 26) & 0x1) +#define C_009508_SYNC_ALIGNER 0xFBFFFFFF +#define S_009508_BILINEAR_PRECISION(x) (((x) & 0x1) << 31) +#define G_009508_BILINEAR_PRECISION(x) (((x) >> 31) & 0x1) +#define C_009508_BILINEAR_PRECISION 0x7FFFFFFF +#define R_009714_VC_ENHANCE 0x009714 +#define R_009830_DB_DEBUG 0x009830 +#define R_009838_DB_WATERMARKS 0x009838 +#define S_009838_DEPTH_FREE(x) (((x) & 0x1F) << 0) +#define G_009838_DEPTH_FREE(x) (((x) >> 0) & 0x1F) +#define C_009838_DEPTH_FREE 0xFFFFFFE0 +#define S_009838_DEPTH_FLUSH(x) (((x) & 0x3F) << 5) +#define G_009838_DEPTH_FLUSH(x) (((x) >> 5) & 0x3F) +#define C_009838_DEPTH_FLUSH 0xFFFFF81F +#define S_009838_FORCE_SUMMARIZE(x) (((x) & 0xF) << 11) +#define G_009838_FORCE_SUMMARIZE(x) (((x) >> 11) & 0xF) +#define C_009838_FORCE_SUMMARIZE 0xFFFF87FF +#define S_009838_DEPTH_PENDING_FREE(x) (((x) & 0x1F) << 15) +#define G_009838_DEPTH_PENDING_FREE(x) (((x) >> 15) & 0x1F) +#define C_009838_DEPTH_PENDING_FREE 0xFFF07FFF +#define S_009838_DEPTH_CACHELINE_FREE(x) (((x) & 0x1F) << 20) +#define G_009838_DEPTH_CACHELINE_FREE(x) (((x) >> 20) & 0x1F) +#define C_009838_DEPTH_CACHELINE_FREE 0xFE0FFFFF +#define S_009838_EARLY_Z_PANIC_DISABLE(x) (((x) & 0x1) << 25) +#define G_009838_EARLY_Z_PANIC_DISABLE(x) (((x) >> 25) & 0x1) +#define C_009838_EARLY_Z_PANIC_DISABLE 0xFDFFFFFF +#define S_009838_LATE_Z_PANIC_DISABLE(x) (((x) & 0x1) << 26) +#define G_009838_LATE_Z_PANIC_DISABLE(x) (((x) >> 26) & 0x1) +#define C_009838_LATE_Z_PANIC_DISABLE 0xFBFFFFFF +#define S_009838_RE_Z_PANIC_DISABLE(x) (((x) & 0x1) << 27) +#define G_009838_RE_Z_PANIC_DISABLE(x) (((x) >> 27) & 0x1) +#define C_009838_RE_Z_PANIC_DISABLE 0xF7FFFFFF +#define S_009838_DB_EXTRA_DEBUG(x) (((x) & 0xF) << 28) +#define G_009838_DB_EXTRA_DEBUG(x) (((x) >> 28) & 0xF) +#define C_009838_DB_EXTRA_DEBUG 0x0FFFFFFF +#define R_028030_PA_SC_SCREEN_SCISSOR_TL 0x028030 +#define S_028030_TL_X(x) (((x) & 0x7FFF) << 0) +#define G_028030_TL_X(x) (((x) >> 0) & 0x7FFF) +#define C_028030_TL_X 0xFFFF8000 +#define S_028030_TL_Y(x) (((x) & 0x7FFF) << 16) +#define G_028030_TL_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028030_TL_Y 0x8000FFFF +#define R_028034_PA_SC_SCREEN_SCISSOR_BR 0x028034 +#define S_028034_BR_X(x) (((x) & 0x7FFF) << 0) +#define G_028034_BR_X(x) (((x) >> 0) & 0x7FFF) +#define C_028034_BR_X 0xFFFF8000 +#define S_028034_BR_Y(x) (((x) & 0x7FFF) << 16) +#define G_028034_BR_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028034_BR_Y 0x8000FFFF +#define R_028200_PA_SC_WINDOW_OFFSET 0x028200 +#define S_028200_WINDOW_X_OFFSET(x) (((x) & 0x7FFF) << 0) +#define G_028200_WINDOW_X_OFFSET(x) (((x) >> 0) & 0x7FFF) +#define C_028200_WINDOW_X_OFFSET 0xFFFF8000 +#define S_028200_WINDOW_Y_OFFSET(x) (((x) & 0x7FFF) << 16) +#define G_028200_WINDOW_Y_OFFSET(x) (((x) >> 16) & 0x7FFF) +#define C_028200_WINDOW_Y_OFFSET 0x8000FFFF +#define R_028204_PA_SC_WINDOW_SCISSOR_TL 0x028204 +#define S_028204_TL_X(x) (((x) & 0x3FFF) << 0) +#define G_028204_TL_X(x) (((x) >> 0) & 0x3FFF) +#define C_028204_TL_X 0xFFFFC000 +#define S_028204_TL_Y(x) (((x) & 0x3FFF) << 16) +#define G_028204_TL_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028204_TL_Y 0xC000FFFF +#define S_028204_WINDOW_OFFSET_DISABLE(x) (((x) & 0x1) << 31) +#define G_028204_WINDOW_OFFSET_DISABLE(x) (((x) >> 31) & 0x1) +#define C_028204_WINDOW_OFFSET_DISABLE 0x7FFFFFFF +#define R_028208_PA_SC_WINDOW_SCISSOR_BR 0x028208 +#define S_028208_BR_X(x) (((x) & 0x3FFF) << 0) +#define G_028208_BR_X(x) (((x) >> 0) & 0x3FFF) +#define C_028208_BR_X 0xFFFFC000 +#define S_028208_BR_Y(x) (((x) & 0x3FFF) << 16) +#define G_028208_BR_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028208_BR_Y 0xC000FFFF +#define R_02820C_PA_SC_CLIPRECT_RULE 0x02820C +#define S_02820C_CLIP_RULE(x) (((x) & 0xFFFF) << 0) +#define G_02820C_CLIP_RULE(x) (((x) >> 0) & 0xFFFF) +#define C_02820C_CLIP_RULE 0xFFFF0000 +#define R_028210_PA_SC_CLIPRECT_0_TL 0x028210 +#define S_028210_TL_X(x) (((x) & 0x3FFF) << 0) +#define G_028210_TL_X(x) (((x) >> 0) & 0x3FFF) +#define C_028210_TL_X 0xFFFFC000 +#define S_028210_TL_Y(x) (((x) & 0x3FFF) << 16) +#define G_028210_TL_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028210_TL_Y 0xC000FFFF +#define R_028214_PA_SC_CLIPRECT_0_BR 0x028214 +#define S_028214_BR_X(x) (((x) & 0x3FFF) << 0) +#define G_028214_BR_X(x) (((x) >> 0) & 0x3FFF) +#define C_028214_BR_X 0xFFFFC000 +#define S_028214_BR_Y(x) (((x) & 0x3FFF) << 16) +#define G_028214_BR_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028214_BR_Y 0xC000FFFF +#define R_028218_PA_SC_CLIPRECT_1_TL 0x028218 +#define R_02821C_PA_SC_CLIPRECT_1_BR 0x02821C +#define R_028220_PA_SC_CLIPRECT_2_TL 0x028220 +#define R_028224_PA_SC_CLIPRECT_2_BR 0x028224 +#define R_028228_PA_SC_CLIPRECT_3_TL 0x028228 +#define R_02822C_PA_SC_CLIPRECT_3_BR 0x02822C +#define R_028230_PA_SC_EDGERULE 0x028230 +#define R_028240_PA_SC_GENERIC_SCISSOR_TL 0x028240 +#define S_028240_TL_X(x) (((x) & 0x3FFF) << 0) +#define G_028240_TL_X(x) (((x) >> 0) & 0x3FFF) +#define C_028240_TL_X 0xFFFFC000 +#define S_028240_TL_Y(x) (((x) & 0x3FFF) << 16) +#define G_028240_TL_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028240_TL_Y 0xC000FFFF +#define S_028240_WINDOW_OFFSET_DISABLE(x) (((x) & 0x1) << 31) +#define G_028240_WINDOW_OFFSET_DISABLE(x) (((x) >> 31) & 0x1) +#define C_028240_WINDOW_OFFSET_DISABLE 0x7FFFFFFF +#define R_028244_PA_SC_GENERIC_SCISSOR_BR 0x028244 +#define S_028244_BR_X(x) (((x) & 0x3FFF) << 0) +#define G_028244_BR_X(x) (((x) >> 0) & 0x3FFF) +#define C_028244_BR_X 0xFFFFC000 +#define S_028244_BR_Y(x) (((x) & 0x3FFF) << 16) +#define G_028244_BR_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028244_BR_Y 0xC000FFFF +#define R_0282D0_PA_SC_VPORT_ZMIN_0 0x0282D0 +#define S_0282D0_VPORT_ZMIN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_0282D0_VPORT_ZMIN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_0282D0_VPORT_ZMIN 0x00000000 +#define R_0282D4_PA_SC_VPORT_ZMAX_0 0x0282D4 +#define S_0282D4_VPORT_ZMAX(x) (((x) & 0xFFFFFFFF) << 0) +#define G_0282D4_VPORT_ZMAX(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_0282D4_VPORT_ZMAX 0x00000000 +#define R_028350_SX_MISC 0x028350 +#define S_028350_MULTIPASS(x) (((x) & 0x1) << 0) +#define G_028350_MULTIPASS(x) (((x) >> 0) & 0x1) +#define C_028350_MULTIPASS 0xFFFFFFFE +#define R_028380_SQ_VTX_SEMANTIC_0 0x028380 +#define S_028380_SEMANTIC_ID(x) (((x) & 0xFF) << 0) +#define G_028380_SEMANTIC_ID(x) (((x) >> 0) & 0xFF) +#define C_028380_SEMANTIC_ID 0xFFFFFF00 +#define R_028384_SQ_VTX_SEMANTIC_1 0x028384 +#define R_028388_SQ_VTX_SEMANTIC_2 0x028388 +#define R_02838C_SQ_VTX_SEMANTIC_3 0x02838C +#define R_028390_SQ_VTX_SEMANTIC_4 0x028390 +#define R_028394_SQ_VTX_SEMANTIC_5 0x028394 +#define R_028398_SQ_VTX_SEMANTIC_6 0x028398 +#define R_02839C_SQ_VTX_SEMANTIC_7 0x02839C +#define R_0283A0_SQ_VTX_SEMANTIC_8 0x0283A0 +#define R_0283A4_SQ_VTX_SEMANTIC_9 0x0283A4 +#define R_0283A8_SQ_VTX_SEMANTIC_10 0x0283A8 +#define R_0283AC_SQ_VTX_SEMANTIC_11 0x0283AC +#define R_0283B0_SQ_VTX_SEMANTIC_12 0x0283B0 +#define R_0283B4_SQ_VTX_SEMANTIC_13 0x0283B4 +#define R_0283B8_SQ_VTX_SEMANTIC_14 0x0283B8 +#define R_0283BC_SQ_VTX_SEMANTIC_15 0x0283BC +#define R_0283C0_SQ_VTX_SEMANTIC_16 0x0283C0 +#define R_0283C4_SQ_VTX_SEMANTIC_17 0x0283C4 +#define R_0283C8_SQ_VTX_SEMANTIC_18 0x0283C8 +#define R_0283CC_SQ_VTX_SEMANTIC_19 0x0283CC +#define R_0283D0_SQ_VTX_SEMANTIC_20 0x0283D0 +#define R_0283D4_SQ_VTX_SEMANTIC_21 0x0283D4 +#define R_0283D8_SQ_VTX_SEMANTIC_22 0x0283D8 +#define R_0283DC_SQ_VTX_SEMANTIC_23 0x0283DC +#define R_0283E0_SQ_VTX_SEMANTIC_24 0x0283E0 +#define R_0283E4_SQ_VTX_SEMANTIC_25 0x0283E4 +#define R_0283E8_SQ_VTX_SEMANTIC_26 0x0283E8 +#define R_0283EC_SQ_VTX_SEMANTIC_27 0x0283EC +#define R_0283F0_SQ_VTX_SEMANTIC_28 0x0283F0 +#define R_0283F4_SQ_VTX_SEMANTIC_29 0x0283F4 +#define R_0283F8_SQ_VTX_SEMANTIC_30 0x0283F8 +#define R_0283FC_SQ_VTX_SEMANTIC_31 0x0283FC +#define R_028400_VGT_MAX_VTX_INDX 0x028400 +#define S_028400_MAX_INDX(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028400_MAX_INDX(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028400_MAX_INDX 0x00000000 +#define R_028404_VGT_MIN_VTX_INDX 0x028404 +#define S_028404_MIN_INDX(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028404_MIN_INDX(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028404_MIN_INDX 0x00000000 +#define R_028408_VGT_INDX_OFFSET 0x028408 +#define S_028408_INDX_OFFSET(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028408_INDX_OFFSET(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028408_INDX_OFFSET 0x00000000 +#define R_02840C_VGT_MULTI_PRIM_IB_RESET_INDX 0x02840C +#define S_02840C_RESET_INDX(x) (((x) & 0xFFFFFFFF) << 0) +#define G_02840C_RESET_INDX(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_02840C_RESET_INDX 0x00000000 +#define R_028410_SX_ALPHA_TEST_CONTROL 0x028410 +#define S_028410_ALPHA_FUNC(x) (((x) & 0x7) << 0) +#define G_028410_ALPHA_FUNC(x) (((x) >> 0) & 0x7) +#define C_028410_ALPHA_FUNC 0xFFFFFFF8 +#define S_028410_ALPHA_TEST_ENABLE(x) (((x) & 0x1) << 3) +#define G_028410_ALPHA_TEST_ENABLE(x) (((x) >> 3) & 0x1) +#define C_028410_ALPHA_TEST_ENABLE 0xFFFFFFF7 +#define S_028410_ALPHA_TEST_BYPASS(x) (((x) & 0x1) << 8) +#define G_028410_ALPHA_TEST_BYPASS(x) (((x) >> 8) & 0x1) +#define C_028410_ALPHA_TEST_BYPASS 0xFFFFFEFF +#define R_028414_CB_BLEND_RED 0x028414 +#define S_028414_BLEND_RED(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028414_BLEND_RED(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028414_BLEND_RED 0x00000000 +#define R_028418_CB_BLEND_GREEN 0x028418 +#define S_028418_BLEND_GREEN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028418_BLEND_GREEN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028418_BLEND_GREEN 0x00000000 +#define R_02841C_CB_BLEND_BLUE 0x02841C +#define S_02841C_BLEND_BLUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_02841C_BLEND_BLUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_02841C_BLEND_BLUE 0x00000000 +#define R_028420_CB_BLEND_ALPHA 0x028420 +#define S_028420_BLEND_ALPHA(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028420_BLEND_ALPHA(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028420_BLEND_ALPHA 0x00000000 +#define R_028438_SX_ALPHA_REF 0x028438 +#define S_028438_ALPHA_REF(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028438_ALPHA_REF(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028438_ALPHA_REF 0x00000000 +#define R_0286C8_SPI_THREAD_GROUPING 0x0286C8 +#define S_0286C8_PS_GROUPING(x) (((x) & 0x1F) << 0) +#define G_0286C8_PS_GROUPING(x) (((x) >> 0) & 0x1F) +#define C_0286C8_PS_GROUPING 0xFFFFFFE0 +#define S_0286C8_VS_GROUPING(x) (((x) & 0x1F) << 8) +#define G_0286C8_VS_GROUPING(x) (((x) >> 8) & 0x1F) +#define C_0286C8_VS_GROUPING 0xFFFFE0FF +#define S_0286C8_GS_GROUPING(x) (((x) & 0x1F) << 16) +#define G_0286C8_GS_GROUPING(x) (((x) >> 16) & 0x1F) +#define C_0286C8_GS_GROUPING 0xFFE0FFFF +#define S_0286C8_ES_GROUPING(x) (((x) & 0x1F) << 24) +#define G_0286C8_ES_GROUPING(x) (((x) >> 24) & 0x1F) +#define C_0286C8_ES_GROUPING 0xE0FFFFFF +#define R_0286D8_SPI_INPUT_Z 0x0286D8 +#define S_0286D8_PROVIDE_Z_TO_SPI(x) (((x) & 0x1) << 0) +#define G_0286D8_PROVIDE_Z_TO_SPI(x) (((x) >> 0) & 0x1) +#define C_0286D8_PROVIDE_Z_TO_SPI 0xFFFFFFFE +#define R_0286DC_SPI_FOG_CNTL 0x0286DC +#define S_0286DC_PASS_FOG_THROUGH_PS(x) (((x) & 0x1) << 0) +#define G_0286DC_PASS_FOG_THROUGH_PS(x) (((x) >> 0) & 0x1) +#define C_0286DC_PASS_FOG_THROUGH_PS 0xFFFFFFFE +#define S_0286DC_PIXEL_FOG_FUNC(x) (((x) & 0x3) << 1) +#define G_0286DC_PIXEL_FOG_FUNC(x) (((x) >> 1) & 0x3) +#define C_0286DC_PIXEL_FOG_FUNC 0xFFFFFFF9 +#define S_0286DC_PIXEL_FOG_SRC_SEL(x) (((x) & 0x1) << 3) +#define G_0286DC_PIXEL_FOG_SRC_SEL(x) (((x) >> 3) & 0x1) +#define C_0286DC_PIXEL_FOG_SRC_SEL 0xFFFFFFF7 +#define S_0286DC_VS_FOG_CLAMP_DISABLE(x) (((x) & 0x1) << 4) +#define G_0286DC_VS_FOG_CLAMP_DISABLE(x) (((x) >> 4) & 0x1) +#define C_0286DC_VS_FOG_CLAMP_DISABLE 0xFFFFFFEF +#define R_0286E0_SPI_FOG_FUNC_SCALE 0x0286E0 +#define S_0286E0_VALUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_0286E0_VALUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_0286E0_VALUE 0x00000000 +#define R_0286E4_SPI_FOG_FUNC_BIAS 0x0286E4 +#define S_0286E4_VALUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_0286E4_VALUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_0286E4_VALUE 0x00000000 +#define R_0287A0_CB_SHADER_CONTROL 0x0287A0 +#define S_0287A0_RT0_ENABLE(x) (((x) & 0x1) << 0) +#define G_0287A0_RT0_ENABLE(x) (((x) >> 0) & 0x1) +#define C_0287A0_RT0_ENABLE 0xFFFFFFFE +#define S_0287A0_RT1_ENABLE(x) (((x) & 0x1) << 1) +#define G_0287A0_RT1_ENABLE(x) (((x) >> 1) & 0x1) +#define C_0287A0_RT1_ENABLE 0xFFFFFFFD +#define S_0287A0_RT2_ENABLE(x) (((x) & 0x1) << 2) +#define G_0287A0_RT2_ENABLE(x) (((x) >> 2) & 0x1) +#define C_0287A0_RT2_ENABLE 0xFFFFFFFB +#define S_0287A0_RT3_ENABLE(x) (((x) & 0x1) << 3) +#define G_0287A0_RT3_ENABLE(x) (((x) >> 3) & 0x1) +#define C_0287A0_RT3_ENABLE 0xFFFFFFF7 +#define S_0287A0_RT4_ENABLE(x) (((x) & 0x1) << 4) +#define G_0287A0_RT4_ENABLE(x) (((x) >> 4) & 0x1) +#define C_0287A0_RT4_ENABLE 0xFFFFFFEF +#define S_0287A0_RT5_ENABLE(x) (((x) & 0x1) << 5) +#define G_0287A0_RT5_ENABLE(x) (((x) >> 5) & 0x1) +#define C_0287A0_RT5_ENABLE 0xFFFFFFDF +#define S_0287A0_RT6_ENABLE(x) (((x) & 0x1) << 6) +#define G_0287A0_RT6_ENABLE(x) (((x) >> 6) & 0x1) +#define C_0287A0_RT6_ENABLE 0xFFFFFFBF +#define S_0287A0_RT7_ENABLE(x) (((x) & 0x1) << 7) +#define G_0287A0_RT7_ENABLE(x) (((x) >> 7) & 0x1) +#define C_0287A0_RT7_ENABLE 0xFFFFFF7F +#define R_028894_SQ_PGM_START_FS 0x028894 +#define S_028894_PGM_START(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028894_PGM_START(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028894_PGM_START 0x00000000 +#define R_0288A4_SQ_PGM_RESOURCES_FS 0x0288A4 +#define S_0288A4_NUM_GPRS(x) (((x) & 0xFF) << 0) +#define G_0288A4_NUM_GPRS(x) (((x) >> 0) & 0xFF) +#define C_0288A4_NUM_GPRS 0xFFFFFF00 +#define S_0288A4_STACK_SIZE(x) (((x) & 0xFF) << 8) +#define G_0288A4_STACK_SIZE(x) (((x) >> 8) & 0xFF) +#define C_0288A4_STACK_SIZE 0xFFFF00FF +#define S_0288A4_DX10_CLAMP(x) (((x) & 0x1) << 21) +#define G_0288A4_DX10_CLAMP(x) (((x) >> 21) & 0x1) +#define C_0288A4_DX10_CLAMP 0xFFDFFFFF +#define R_0288A8_SQ_ESGS_RING_ITEMSIZE 0x0288A8 +#define S_0288A8_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288A8_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288A8_ITEMSIZE 0xFFFF8000 +#define R_0288AC_SQ_GSVS_RING_ITEMSIZE 0x0288AC +#define S_0288AC_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288AC_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288AC_ITEMSIZE 0xFFFF8000 +#define R_0288B0_SQ_ESTMP_RING_ITEMSIZE 0x0288B0 +#define S_0288B0_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288B0_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288B0_ITEMSIZE 0xFFFF8000 +#define R_0288B4_SQ_GSTMP_RING_ITEMSIZE 0x0288B4 +#define S_0288B4_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288B4_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288B4_ITEMSIZE 0xFFFF8000 +#define R_0288B8_SQ_VSTMP_RING_ITEMSIZE 0x0288B8 +#define S_0288B8_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288B8_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288B8_ITEMSIZE 0xFFFF8000 +#define R_0288BC_SQ_PSTMP_RING_ITEMSIZE 0x0288BC +#define S_0288BC_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288BC_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288BC_ITEMSIZE 0xFFFF8000 +#define R_0288C0_SQ_FBUF_RING_ITEMSIZE 0x0288C0 +#define S_0288C0_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288C0_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288C0_ITEMSIZE 0xFFFF8000 +#define R_0288C4_SQ_REDUC_RING_ITEMSIZE 0x0288C4 +#define S_0288C4_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288C4_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288C4_ITEMSIZE 0xFFFF8000 +#define R_0288C8_SQ_GS_VERT_ITEMSIZE 0x0288C8 +#define S_0288C8_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288C8_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288C8_ITEMSIZE 0xFFFF8000 +#define R_0288DC_SQ_PGM_CF_OFFSET_FS 0x0288DC +#define S_0288DC_PGM_CF_OFFSET(x) (((x) & 0xFFFFF) << 0) +#define G_0288DC_PGM_CF_OFFSET(x) (((x) >> 0) & 0xFFFFF) +#define C_0288DC_PGM_CF_OFFSET 0xFFF00000 +#define R_028A10_VGT_OUTPUT_PATH_CNTL 0x028A10 +#define S_028A10_PATH_SELECT(x) (((x) & 0x3) << 0) +#define G_028A10_PATH_SELECT(x) (((x) >> 0) & 0x3) +#define C_028A10_PATH_SELECT 0xFFFFFFFC +#define R_028A14_VGT_HOS_CNTL 0x028A14 +#define S_028A14_TESS_MODE(x) (((x) & 0x3) << 0) +#define G_028A14_TESS_MODE(x) (((x) >> 0) & 0x3) +#define C_028A14_TESS_MODE 0xFFFFFFFC +#define R_028A18_VGT_HOS_MAX_TESS_LEVEL 0x028A18 +#define S_028A18_MAX_TESS(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028A18_MAX_TESS(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028A18_MAX_TESS 0x00000000 +#define R_028A1C_VGT_HOS_MIN_TESS_LEVEL 0x028A1C +#define S_028A1C_MIN_TESS(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028A1C_MIN_TESS(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028A1C_MIN_TESS 0x00000000 +#define R_028A20_VGT_HOS_REUSE_DEPTH 0x028A20 +#define S_028A20_REUSE_DEPTH(x) (((x) & 0xFF) << 0) +#define G_028A20_REUSE_DEPTH(x) (((x) >> 0) & 0xFF) +#define C_028A20_REUSE_DEPTH 0xFFFFFF00 +#define R_028A24_VGT_GROUP_PRIM_TYPE 0x028A24 +#define S_028A24_PRIM_TYPE(x) (((x) & 0x1F) << 0) +#define G_028A24_PRIM_TYPE(x) (((x) >> 0) & 0x1F) +#define C_028A24_PRIM_TYPE 0xFFFFFFE0 +#define S_028A24_RETAIN_ORDER(x) (((x) & 0x1) << 14) +#define G_028A24_RETAIN_ORDER(x) (((x) >> 14) & 0x1) +#define C_028A24_RETAIN_ORDER 0xFFFFBFFF +#define S_028A24_RETAIN_QUADS(x) (((x) & 0x1) << 15) +#define G_028A24_RETAIN_QUADS(x) (((x) >> 15) & 0x1) +#define C_028A24_RETAIN_QUADS 0xFFFF7FFF +#define S_028A24_PRIM_ORDER(x) (((x) & 0x7) << 16) +#define G_028A24_PRIM_ORDER(x) (((x) >> 16) & 0x7) +#define C_028A24_PRIM_ORDER 0xFFF8FFFF +#define R_028A28_VGT_GROUP_FIRST_DECR 0x028A28 +#define S_028A28_FIRST_DECR(x) (((x) & 0xF) << 0) +#define G_028A28_FIRST_DECR(x) (((x) >> 0) & 0xF) +#define C_028A28_FIRST_DECR 0xFFFFFFF0 +#define R_028A2C_VGT_GROUP_DECR 0x028A2C +#define S_028A2C_DECR(x) (((x) & 0xF) << 0) +#define G_028A2C_DECR(x) (((x) >> 0) & 0xF) +#define C_028A2C_DECR 0xFFFFFFF0 +#define R_028A30_VGT_GROUP_VECT_0_CNTL 0x028A30 +#define S_028A30_COMP_X_EN(x) (((x) & 0x1) << 0) +#define G_028A30_COMP_X_EN(x) (((x) >> 0) & 0x1) +#define C_028A30_COMP_X_EN 0xFFFFFFFE +#define S_028A30_COMP_Y_EN(x) (((x) & 0x1) << 1) +#define G_028A30_COMP_Y_EN(x) (((x) >> 1) & 0x1) +#define C_028A30_COMP_Y_EN 0xFFFFFFFD +#define S_028A30_COMP_Z_EN(x) (((x) & 0x1) << 2) +#define G_028A30_COMP_Z_EN(x) (((x) >> 2) & 0x1) +#define C_028A30_COMP_Z_EN 0xFFFFFFFB +#define S_028A30_COMP_W_EN(x) (((x) & 0x1) << 3) +#define G_028A30_COMP_W_EN(x) (((x) >> 3) & 0x1) +#define C_028A30_COMP_W_EN 0xFFFFFFF7 +#define S_028A30_STRIDE(x) (((x) & 0xFF) << 8) +#define G_028A30_STRIDE(x) (((x) >> 8) & 0xFF) +#define C_028A30_STRIDE 0xFFFF00FF +#define S_028A30_SHIFT(x) (((x) & 0xFF) << 16) +#define G_028A30_SHIFT(x) (((x) >> 16) & 0xFF) +#define C_028A30_SHIFT 0xFF00FFFF +#define R_028A34_VGT_GROUP_VECT_1_CNTL 0x028A34 +#define S_028A34_COMP_X_EN(x) (((x) & 0x1) << 0) +#define G_028A34_COMP_X_EN(x) (((x) >> 0) & 0x1) +#define C_028A34_COMP_X_EN 0xFFFFFFFE +#define S_028A34_COMP_Y_EN(x) (((x) & 0x1) << 1) +#define G_028A34_COMP_Y_EN(x) (((x) >> 1) & 0x1) +#define C_028A34_COMP_Y_EN 0xFFFFFFFD +#define S_028A34_COMP_Z_EN(x) (((x) & 0x1) << 2) +#define G_028A34_COMP_Z_EN(x) (((x) >> 2) & 0x1) +#define C_028A34_COMP_Z_EN 0xFFFFFFFB +#define S_028A34_COMP_W_EN(x) (((x) & 0x1) << 3) +#define G_028A34_COMP_W_EN(x) (((x) >> 3) & 0x1) +#define C_028A34_COMP_W_EN 0xFFFFFFF7 +#define S_028A34_STRIDE(x) (((x) & 0xFF) << 8) +#define G_028A34_STRIDE(x) (((x) >> 8) & 0xFF) +#define C_028A34_STRIDE 0xFFFF00FF +#define S_028A34_SHIFT(x) (((x) & 0xFF) << 16) +#define G_028A34_SHIFT(x) (((x) >> 16) & 0xFF) +#define C_028A34_SHIFT 0xFF00FFFF +#define R_028A38_VGT_GROUP_VECT_0_FMT_CNTL 0x028A38 +#define S_028A38_X_CONV(x) (((x) & 0xF) << 0) +#define G_028A38_X_CONV(x) (((x) >> 0) & 0xF) +#define C_028A38_X_CONV 0xFFFFFFF0 +#define S_028A38_X_OFFSET(x) (((x) & 0xF) << 4) +#define G_028A38_X_OFFSET(x) (((x) >> 4) & 0xF) +#define C_028A38_X_OFFSET 0xFFFFFF0F +#define S_028A38_Y_CONV(x) (((x) & 0xF) << 8) +#define G_028A38_Y_CONV(x) (((x) >> 8) & 0xF) +#define C_028A38_Y_CONV 0xFFFFF0FF +#define S_028A38_Y_OFFSET(x) (((x) & 0xF) << 12) +#define G_028A38_Y_OFFSET(x) (((x) >> 12) & 0xF) +#define C_028A38_Y_OFFSET 0xFFFF0FFF +#define S_028A38_Z_CONV(x) (((x) & 0xF) << 16) +#define G_028A38_Z_CONV(x) (((x) >> 16) & 0xF) +#define C_028A38_Z_CONV 0xFFF0FFFF +#define S_028A38_Z_OFFSET(x) (((x) & 0xF) << 20) +#define G_028A38_Z_OFFSET(x) (((x) >> 20) & 0xF) +#define C_028A38_Z_OFFSET 0xFF0FFFFF +#define S_028A38_W_CONV(x) (((x) & 0xF) << 24) +#define G_028A38_W_CONV(x) (((x) >> 24) & 0xF) +#define C_028A38_W_CONV 0xF0FFFFFF +#define S_028A38_W_OFFSET(x) (((x) & 0xF) << 28) +#define G_028A38_W_OFFSET(x) (((x) >> 28) & 0xF) +#define C_028A38_W_OFFSET 0x0FFFFFFF +#define R_028A3C_VGT_GROUP_VECT_1_FMT_CNTL 0x028A3C +#define S_028A3C_X_CONV(x) (((x) & 0xF) << 0) +#define G_028A3C_X_CONV(x) (((x) >> 0) & 0xF) +#define C_028A3C_X_CONV 0xFFFFFFF0 +#define S_028A3C_X_OFFSET(x) (((x) & 0xF) << 4) +#define G_028A3C_X_OFFSET(x) (((x) >> 4) & 0xF) +#define C_028A3C_X_OFFSET 0xFFFFFF0F +#define S_028A3C_Y_CONV(x) (((x) & 0xF) << 8) +#define G_028A3C_Y_CONV(x) (((x) >> 8) & 0xF) +#define C_028A3C_Y_CONV 0xFFFFF0FF +#define S_028A3C_Y_OFFSET(x) (((x) & 0xF) << 12) +#define G_028A3C_Y_OFFSET(x) (((x) >> 12) & 0xF) +#define C_028A3C_Y_OFFSET 0xFFFF0FFF +#define S_028A3C_Z_CONV(x) (((x) & 0xF) << 16) +#define G_028A3C_Z_CONV(x) (((x) >> 16) & 0xF) +#define C_028A3C_Z_CONV 0xFFF0FFFF +#define S_028A3C_Z_OFFSET(x) (((x) & 0xF) << 20) +#define G_028A3C_Z_OFFSET(x) (((x) >> 20) & 0xF) +#define C_028A3C_Z_OFFSET 0xFF0FFFFF +#define S_028A3C_W_CONV(x) (((x) & 0xF) << 24) +#define G_028A3C_W_CONV(x) (((x) >> 24) & 0xF) +#define C_028A3C_W_CONV 0xF0FFFFFF +#define S_028A3C_W_OFFSET(x) (((x) & 0xF) << 28) +#define G_028A3C_W_OFFSET(x) (((x) >> 28) & 0xF) +#define C_028A3C_W_OFFSET 0x0FFFFFFF +#define R_028A40_VGT_GS_MODE 0x028A40 +#define S_028A40_MODE(x) (((x) & 0x3) << 0) +#define G_028A40_MODE(x) (((x) >> 0) & 0x3) +#define C_028A40_MODE 0xFFFFFFFC +#define S_028A40_ES_PASSTHRU(x) (((x) & 0x1) << 2) +#define G_028A40_ES_PASSTHRU(x) (((x) >> 2) & 0x1) +#define C_028A40_ES_PASSTHRU 0xFFFFFFFB +#define S_028A40_CUT_MODE(x) (((x) & 0x3) << 3) +#define G_028A40_CUT_MODE(x) (((x) >> 3) & 0x3) +#define C_028A40_CUT_MODE 0xFFFFFFE7 +#define R_028A4C_PA_SC_MODE_CNTL 0x028A4C +#define S_028A4C_MSAA_ENABLE(x) (((x) & 0x1) << 0) +#define G_028A4C_MSAA_ENABLE(x) (((x) >> 0) & 0x1) +#define C_028A4C_MSAA_ENABLE 0xFFFFFFFE +#define S_028A4C_CLIPRECT_ENABLE(x) (((x) & 0x1) << 1) +#define G_028A4C_CLIPRECT_ENABLE(x) (((x) >> 1) & 0x1) +#define C_028A4C_CLIPRECT_ENABLE 0xFFFFFFFD +#define S_028A4C_LINE_STIPPLE_ENABLE(x) (((x) & 0x1) << 2) +#define G_028A4C_LINE_STIPPLE_ENABLE(x) (((x) >> 2) & 0x1) +#define C_028A4C_LINE_STIPPLE_ENABLE 0xFFFFFFFB +#define S_028A4C_MULTI_CHIP_PRIM_DISCARD_ENAB(x) (((x) & 0x1) << 3) +#define G_028A4C_MULTI_CHIP_PRIM_DISCARD_ENAB(x) (((x) >> 3) & 0x1) +#define C_028A4C_MULTI_CHIP_PRIM_DISCARD_ENAB 0xFFFFFFF7 +#define S_028A4C_WALK_ORDER_ENABLE(x) (((x) & 0x1) << 4) +#define G_028A4C_WALK_ORDER_ENABLE(x) (((x) >> 4) & 0x1) +#define C_028A4C_WALK_ORDER_ENABLE 0xFFFFFFEF +#define S_028A4C_HALVE_DETAIL_SAMPLE_PERF(x) (((x) & 0x1) << 5) +#define G_028A4C_HALVE_DETAIL_SAMPLE_PERF(x) (((x) >> 5) & 0x1) +#define C_028A4C_HALVE_DETAIL_SAMPLE_PERF 0xFFFFFFDF +#define S_028A4C_WALK_SIZE(x) (((x) & 0x1) << 6) +#define G_028A4C_WALK_SIZE(x) (((x) >> 6) & 0x1) +#define C_028A4C_WALK_SIZE 0xFFFFFFBF +#define S_028A4C_WALK_ALIGNMENT(x) (((x) & 0x1) << 7) +#define G_028A4C_WALK_ALIGNMENT(x) (((x) >> 7) & 0x1) +#define C_028A4C_WALK_ALIGNMENT 0xFFFFFF7F +#define S_028A4C_WALK_ALIGN8_PRIM_FITS_ST(x) (((x) & 0x1) << 8) +#define G_028A4C_WALK_ALIGN8_PRIM_FITS_ST(x) (((x) >> 8) & 0x1) +#define C_028A4C_WALK_ALIGN8_PRIM_FITS_ST 0xFFFFFEFF +#define S_028A4C_TILE_COVER_NO_SCISSOR(x) (((x) & 0x1) << 9) +#define G_028A4C_TILE_COVER_NO_SCISSOR(x) (((x) >> 9) & 0x1) +#define C_028A4C_TILE_COVER_NO_SCISSOR 0xFFFFFDFF +#define S_028A4C_KILL_PIX_POST_HI_Z(x) (((x) & 0x1) << 10) +#define G_028A4C_KILL_PIX_POST_HI_Z(x) (((x) >> 10) & 0x1) +#define C_028A4C_KILL_PIX_POST_HI_Z 0xFFFFFBFF +#define S_028A4C_KILL_PIX_POST_DETAIL_MASK(x) (((x) & 0x1) << 11) +#define G_028A4C_KILL_PIX_POST_DETAIL_MASK(x) (((x) >> 11) & 0x1) +#define C_028A4C_KILL_PIX_POST_DETAIL_MASK 0xFFFFF7FF +#define S_028A4C_MULTI_CHIP_SUPERTILE_ENABLE(x) (((x) & 0x1) << 12) +#define G_028A4C_MULTI_CHIP_SUPERTILE_ENABLE(x) (((x) >> 12) & 0x1) +#define C_028A4C_MULTI_CHIP_SUPERTILE_ENABLE 0xFFFFEFFF +#define S_028A4C_TILE_COVER_DISABLE(x) (((x) & 0x1) << 13) +#define G_028A4C_TILE_COVER_DISABLE(x) (((x) >> 13) & 0x1) +#define C_028A4C_TILE_COVER_DISABLE 0xFFFFDFFF +#define S_028A4C_FORCE_EOV_CNTDWN_ENABLE(x) (((x) & 0x1) << 14) +#define G_028A4C_FORCE_EOV_CNTDWN_ENABLE(x) (((x) >> 14) & 0x1) +#define C_028A4C_FORCE_EOV_CNTDWN_ENABLE 0xFFFFBFFF +#define S_028A4C_FORCE_EOV_TILE_ENABLE(x) (((x) & 0x1) << 15) +#define G_028A4C_FORCE_EOV_TILE_ENABLE(x) (((x) >> 15) & 0x1) +#define C_028A4C_FORCE_EOV_TILE_ENABLE 0xFFFF7FFF +#define S_028A4C_FORCE_EOV_REZ_ENABLE(x) (((x) & 0x1) << 16) +#define G_028A4C_FORCE_EOV_REZ_ENABLE(x) (((x) >> 16) & 0x1) +#define C_028A4C_FORCE_EOV_REZ_ENABLE 0xFFFEFFFF +#define S_028A4C_PS_ITER_SAMPLE(x) (((x) & 0x1) << 17) +#define G_028A4C_PS_ITER_SAMPLE(x) (((x) >> 17) & 0x1) +#define C_028A4C_PS_ITER_SAMPLE 0xFFFDFFFF +#define R_028A84_VGT_PRIMITIVEID_EN 0x028A84 +#define S_028A84_PRIMITIVEID_EN(x) (((x) & 0x1) << 0) +#define G_028A84_PRIMITIVEID_EN(x) (((x) >> 0) & 0x1) +#define C_028A84_PRIMITIVEID_EN 0xFFFFFFFE +#define R_028A94_VGT_MULTI_PRIM_IB_RESET_EN 0x028A94 +#define S_028A94_RESET_EN(x) (((x) & 0x1) << 0) +#define G_028A94_RESET_EN(x) (((x) >> 0) & 0x1) +#define C_028A94_RESET_EN 0xFFFFFFFE +#define R_028AA0_VGT_INSTANCE_STEP_RATE_0 0x028AA0 +#define S_028AA0_STEP_RATE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028AA0_STEP_RATE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028AA0_STEP_RATE 0x00000000 +#define R_028AA4_VGT_INSTANCE_STEP_RATE_1 0x028AA4 +#define S_028AA4_STEP_RATE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028AA4_STEP_RATE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028AA4_STEP_RATE 0x00000000 +#define R_028AB0_VGT_STRMOUT_EN 0x028AB0 +#define S_028AB0_STREAMOUT(x) (((x) & 0x1) << 0) +#define G_028AB0_STREAMOUT(x) (((x) >> 0) & 0x1) +#define C_028AB0_STREAMOUT 0xFFFFFFFE +#define R_028AB4_VGT_REUSE_OFF 0x028AB4 +#define S_028AB4_REUSE_OFF(x) (((x) & 0x1) << 0) +#define G_028AB4_REUSE_OFF(x) (((x) >> 0) & 0x1) +#define C_028AB4_REUSE_OFF 0xFFFFFFFE +#define R_028AB8_VGT_VTX_CNT_EN 0x028AB8 +#define S_028AB8_VTX_CNT_EN(x) (((x) & 0x1) << 0) +#define G_028AB8_VTX_CNT_EN(x) (((x) >> 0) & 0x1) +#define C_028AB8_VTX_CNT_EN 0xFFFFFFFE +#define R_028B20_VGT_STRMOUT_BUFFER_EN 0x028B20 +#define S_028B20_BUFFER_0_EN(x) (((x) & 0x1) << 0) +#define G_028B20_BUFFER_0_EN(x) (((x) >> 0) & 0x1) +#define C_028B20_BUFFER_0_EN 0xFFFFFFFE +#define S_028B20_BUFFER_1_EN(x) (((x) & 0x1) << 1) +#define G_028B20_BUFFER_1_EN(x) (((x) >> 1) & 0x1) +#define C_028B20_BUFFER_1_EN 0xFFFFFFFD +#define S_028B20_BUFFER_2_EN(x) (((x) & 0x1) << 2) +#define G_028B20_BUFFER_2_EN(x) (((x) >> 2) & 0x1) +#define C_028B20_BUFFER_2_EN 0xFFFFFFFB +#define S_028B20_BUFFER_3_EN(x) (((x) & 0x1) << 3) +#define G_028B20_BUFFER_3_EN(x) (((x) >> 3) & 0x1) +#define C_028B20_BUFFER_3_EN 0xFFFFFFF7 +#define R_028C20_PA_SC_AA_SAMPLE_LOCS_8S_WD1_MCTX 0x028C20 +#define S_028C20_S4_X(x) (((x) & 0xF) << 0) +#define G_028C20_S4_X(x) (((x) >> 0) & 0xF) +#define C_028C20_S4_X 0xFFFFFFF0 +#define S_028C20_S4_Y(x) (((x) & 0xF) << 4) +#define G_028C20_S4_Y(x) (((x) >> 4) & 0xF) +#define C_028C20_S4_Y 0xFFFFFF0F +#define S_028C20_S5_X(x) (((x) & 0xF) << 8) +#define G_028C20_S5_X(x) (((x) >> 8) & 0xF) +#define C_028C20_S5_X 0xFFFFF0FF +#define S_028C20_S5_Y(x) (((x) & 0xF) << 12) +#define G_028C20_S5_Y(x) (((x) >> 12) & 0xF) +#define C_028C20_S5_Y 0xFFFF0FFF +#define S_028C20_S6_X(x) (((x) & 0xF) << 16) +#define G_028C20_S6_X(x) (((x) >> 16) & 0xF) +#define C_028C20_S6_X 0xFFF0FFFF +#define S_028C20_S6_Y(x) (((x) & 0xF) << 20) +#define G_028C20_S6_Y(x) (((x) >> 20) & 0xF) +#define C_028C20_S6_Y 0xFF0FFFFF +#define S_028C20_S7_X(x) (((x) & 0xF) << 24) +#define G_028C20_S7_X(x) (((x) >> 24) & 0xF) +#define C_028C20_S7_X 0xF0FFFFFF +#define S_028C20_S7_Y(x) (((x) & 0xF) << 28) +#define G_028C20_S7_Y(x) (((x) >> 28) & 0xF) +#define C_028C20_S7_Y 0x0FFFFFFF +#define R_028C30_CB_CLRCMP_CONTROL 0x028C30 +#define S_028C30_CLRCMP_FCN_SRC(x) (((x) & 0x7) << 0) +#define G_028C30_CLRCMP_FCN_SRC(x) (((x) >> 0) & 0x7) +#define C_028C30_CLRCMP_FCN_SRC 0xFFFFFFF8 +#define S_028C30_CLRCMP_FCN_DST(x) (((x) & 0x7) << 8) +#define G_028C30_CLRCMP_FCN_DST(x) (((x) >> 8) & 0x7) +#define C_028C30_CLRCMP_FCN_DST 0xFFFFF8FF +#define S_028C30_CLRCMP_FCN_SEL(x) (((x) & 0x3) << 24) +#define G_028C30_CLRCMP_FCN_SEL(x) (((x) >> 24) & 0x3) +#define C_028C30_CLRCMP_FCN_SEL 0xFCFFFFFF +#define R_028C34_CB_CLRCMP_SRC 0x028C34 +#define S_028C34_CLRCMP_SRC(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028C34_CLRCMP_SRC(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028C34_CLRCMP_SRC 0x00000000 +#define R_028C38_CB_CLRCMP_DST 0x028C38 +#define S_028C38_CLRCMP_DST(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028C38_CLRCMP_DST(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028C38_CLRCMP_DST 0x00000000 +#define R_028C3C_CB_CLRCMP_MSK 0x028C3C +#define S_028C3C_CLRCMP_MSK(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028C3C_CLRCMP_MSK(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028C3C_CLRCMP_MSK 0x00000000 +#define R_0085F0_CP_COHER_CNTL 0x0085F0 +#define S_0085F0_DEST_BASE_0_ENA(x) (((x) & 0x1) << 0) +#define G_0085F0_DEST_BASE_0_ENA(x) (((x) >> 0) & 0x1) +#define C_0085F0_DEST_BASE_0_ENA 0xFFFFFFFE +#define S_0085F0_DEST_BASE_1_ENA(x) (((x) & 0x1) << 1) +#define G_0085F0_DEST_BASE_1_ENA(x) (((x) >> 1) & 0x1) +#define C_0085F0_DEST_BASE_1_ENA 0xFFFFFFFD +#define S_0085F0_SO0_DEST_BASE_ENA(x) (((x) & 0x1) << 2) +#define G_0085F0_SO0_DEST_BASE_ENA(x) (((x) >> 2) & 0x1) +#define C_0085F0_SO0_DEST_BASE_ENA 0xFFFFFFFB +#define S_0085F0_SO1_DEST_BASE_ENA(x) (((x) & 0x1) << 3) +#define G_0085F0_SO1_DEST_BASE_ENA(x) (((x) >> 3) & 0x1) +#define C_0085F0_SO1_DEST_BASE_ENA 0xFFFFFFF7 +#define S_0085F0_SO2_DEST_BASE_ENA(x) (((x) & 0x1) << 4) +#define G_0085F0_SO2_DEST_BASE_ENA(x) (((x) >> 4) & 0x1) +#define C_0085F0_SO2_DEST_BASE_ENA 0xFFFFFFEF +#define S_0085F0_SO3_DEST_BASE_ENA(x) (((x) & 0x1) << 5) +#define G_0085F0_SO3_DEST_BASE_ENA(x) (((x) >> 5) & 0x1) +#define C_0085F0_SO3_DEST_BASE_ENA 0xFFFFFFDF +#define S_0085F0_CB0_DEST_BASE_ENA(x) (((x) & 0x1) << 6) +#define G_0085F0_CB0_DEST_BASE_ENA(x) (((x) >> 6) & 0x1) +#define C_0085F0_CB0_DEST_BASE_ENA 0xFFFFFFBF +#define S_0085F0_CB1_DEST_BASE_ENA(x) (((x) & 0x1) << 7) +#define G_0085F0_CB1_DEST_BASE_ENA(x) (((x) >> 7) & 0x1) +#define C_0085F0_CB1_DEST_BASE_ENA 0xFFFFFF7F +#define S_0085F0_CB2_DEST_BASE_ENA(x) (((x) & 0x1) << 8) +#define G_0085F0_CB2_DEST_BASE_ENA(x) (((x) >> 8) & 0x1) +#define C_0085F0_CB2_DEST_BASE_ENA 0xFFFFFEFF +#define S_0085F0_CB3_DEST_BASE_ENA(x) (((x) & 0x1) << 9) +#define G_0085F0_CB3_DEST_BASE_ENA(x) (((x) >> 9) & 0x1) +#define C_0085F0_CB3_DEST_BASE_ENA 0xFFFFFDFF +#define S_0085F0_CB4_DEST_BASE_ENA(x) (((x) & 0x1) << 10) +#define G_0085F0_CB4_DEST_BASE_ENA(x) (((x) >> 10) & 0x1) +#define C_0085F0_CB4_DEST_BASE_ENA 0xFFFFFBFF +#define S_0085F0_CB5_DEST_BASE_ENA(x) (((x) & 0x1) << 11) +#define G_0085F0_CB5_DEST_BASE_ENA(x) (((x) >> 11) & 0x1) +#define C_0085F0_CB5_DEST_BASE_ENA 0xFFFFF7FF +#define S_0085F0_CB6_DEST_BASE_ENA(x) (((x) & 0x1) << 12) +#define G_0085F0_CB6_DEST_BASE_ENA(x) (((x) >> 12) & 0x1) +#define C_0085F0_CB6_DEST_BASE_ENA 0xFFFFEFFF +#define S_0085F0_CB7_DEST_BASE_ENA(x) (((x) & 0x1) << 13) +#define G_0085F0_CB7_DEST_BASE_ENA(x) (((x) >> 13) & 0x1) +#define C_0085F0_CB7_DEST_BASE_ENA 0xFFFFDFFF +#define S_0085F0_DB_DEST_BASE_ENA(x) (((x) & 0x1) << 14) +#define G_0085F0_DB_DEST_BASE_ENA(x) (((x) >> 14) & 0x1) +#define C_0085F0_DB_DEST_BASE_ENA 0xFFFFBFFF +#define S_0085F0_CR_DEST_BASE_ENA(x) (((x) & 0x1) << 15) +#define G_0085F0_CR_DEST_BASE_ENA(x) (((x) >> 15) & 0x1) +#define C_0085F0_CR_DEST_BASE_ENA 0xFFFF7FFF +#define S_0085F0_TC_ACTION_ENA(x) (((x) & 0x1) << 23) +#define G_0085F0_TC_ACTION_ENA(x) (((x) >> 23) & 0x1) +#define C_0085F0_TC_ACTION_ENA 0xFF7FFFFF +#define S_0085F0_VC_ACTION_ENA(x) (((x) & 0x1) << 24) +#define G_0085F0_VC_ACTION_ENA(x) (((x) >> 24) & 0x1) +#define C_0085F0_VC_ACTION_ENA 0xFEFFFFFF +#define S_0085F0_CB_ACTION_ENA(x) (((x) & 0x1) << 25) +#define G_0085F0_CB_ACTION_ENA(x) (((x) >> 25) & 0x1) +#define C_0085F0_CB_ACTION_ENA 0xFDFFFFFF +#define S_0085F0_DB_ACTION_ENA(x) (((x) & 0x1) << 26) +#define G_0085F0_DB_ACTION_ENA(x) (((x) >> 26) & 0x1) +#define C_0085F0_DB_ACTION_ENA 0xFBFFFFFF +#define S_0085F0_SH_ACTION_ENA(x) (((x) & 0x1) << 27) +#define G_0085F0_SH_ACTION_ENA(x) (((x) >> 27) & 0x1) +#define C_0085F0_SH_ACTION_ENA 0xF7FFFFFF +#define S_0085F0_SMX_ACTION_ENA(x) (((x) & 0x1) << 28) +#define G_0085F0_SMX_ACTION_ENA(x) (((x) >> 28) & 0x1) +#define C_0085F0_SMX_ACTION_ENA 0xEFFFFFFF +#define S_0085F0_CR0_ACTION_ENA(x) (((x) & 0x1) << 29) +#define G_0085F0_CR0_ACTION_ENA(x) (((x) >> 29) & 0x1) +#define C_0085F0_CR0_ACTION_ENA 0xDFFFFFFF +#define S_0085F0_CR1_ACTION_ENA(x) (((x) & 0x1) << 30) +#define G_0085F0_CR1_ACTION_ENA(x) (((x) >> 30) & 0x1) +#define C_0085F0_CR1_ACTION_ENA 0xBFFFFFFF +#define S_0085F0_CR2_ACTION_ENA(x) (((x) & 0x1) << 31) +#define G_0085F0_CR2_ACTION_ENA(x) (((x) >> 31) & 0x1) +#define C_0085F0_CR2_ACTION_ENA 0x7FFFFFFF + + +#define R_02812C_CB_CLEAR_ALPHA 0x02812C +#define S_02812C_CLEAR_ALPHA(x) (((x) & 0xFFFFFFFF) << 0) +#define G_02812C_CLEAR_ALPHA(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_02812C_CLEAR_ALPHA 0x00000000 +#define R_028128_CB_CLEAR_BLUE 0x028128 +#define S_028128_CLEAR_BLUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028128_CLEAR_BLUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028128_CLEAR_BLUE 0x00000000 +#define R_028124_CB_CLEAR_GREEN 0x028124 +#define S_028124_CLEAR_GREEN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028124_CLEAR_GREEN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028124_CLEAR_GREEN 0x00000000 +#define R_028120_CB_CLEAR_RED 0x028120 +#define S_028120_CLEAR_RED(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028120_CLEAR_RED(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028120_CLEAR_RED 0x00000000 +#define R_02842C_CB_FOG_BLUE 0x02842C +#define S_02842C_FOG_BLUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_02842C_FOG_BLUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_02842C_FOG_BLUE 0x00000000 +#define R_028428_CB_FOG_GREEN 0x028428 +#define S_028428_FOG_GREEN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028428_FOG_GREEN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028428_FOG_GREEN 0x00000000 +#define R_028424_CB_FOG_RED 0x028424 +#define S_028424_FOG_RED(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028424_FOG_RED(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028424_FOG_RED 0x00000000 +#define R_03C000_SQ_TEX_SAMPLER_WORD0_0 0x03C000 +#define S_03C000_CLAMP_X(x) (((x) & 0x7) << 0) +#define G_03C000_CLAMP_X(x) (((x) >> 0) & 0x7) +#define C_03C000_CLAMP_X 0xFFFFFFF8 +#define S_03C000_CLAMP_Y(x) (((x) & 0x7) << 3) +#define G_03C000_CLAMP_Y(x) (((x) >> 3) & 0x7) +#define C_03C000_CLAMP_Y 0xFFFFFFC7 +#define S_03C000_CLAMP_Z(x) (((x) & 0x7) << 6) +#define G_03C000_CLAMP_Z(x) (((x) >> 6) & 0x7) +#define C_03C000_CLAMP_Z 0xFFFFFE3F +#define S_03C000_XY_MAG_FILTER(x) (((x) & 0x7) << 9) +#define G_03C000_XY_MAG_FILTER(x) (((x) >> 9) & 0x7) +#define C_03C000_XY_MAG_FILTER 0xFFFFF1FF +#define S_03C000_XY_MIN_FILTER(x) (((x) & 0x7) << 12) +#define G_03C000_XY_MIN_FILTER(x) (((x) >> 12) & 0x7) +#define C_03C000_XY_MIN_FILTER 0xFFFF8FFF +#define S_03C000_Z_FILTER(x) (((x) & 0x3) << 15) +#define G_03C000_Z_FILTER(x) (((x) >> 15) & 0x3) +#define C_03C000_Z_FILTER 0xFFFE7FFF +#define S_03C000_MIP_FILTER(x) (((x) & 0x3) << 17) +#define G_03C000_MIP_FILTER(x) (((x) >> 17) & 0x3) +#define C_03C000_MIP_FILTER 0xFFF9FFFF +#define S_03C000_BORDER_COLOR_TYPE(x) (((x) & 0x3) << 22) +#define G_03C000_BORDER_COLOR_TYPE(x) (((x) >> 22) & 0x3) +#define C_03C000_BORDER_COLOR_TYPE 0xFF3FFFFF +#define S_03C000_POINT_SAMPLING_CLAMP(x) (((x) & 0x1) << 24) +#define G_03C000_POINT_SAMPLING_CLAMP(x) (((x) >> 24) & 0x1) +#define C_03C000_POINT_SAMPLING_CLAMP 0xFEFFFFFF +#define S_03C000_TEX_ARRAY_OVERRIDE(x) (((x) & 0x1) << 25) +#define G_03C000_TEX_ARRAY_OVERRIDE(x) (((x) >> 25) & 0x1) +#define C_03C000_TEX_ARRAY_OVERRIDE 0xFDFFFFFF +#define S_03C000_DEPTH_COMPARE_FUNCTION(x) (((x) & 0x7) << 26) +#define G_03C000_DEPTH_COMPARE_FUNCTION(x) (((x) >> 26) & 0x7) +#define C_03C000_DEPTH_COMPARE_FUNCTION 0xE3FFFFFF +#define S_03C000_CHROMA_KEY(x) (((x) & 0x3) << 29) +#define G_03C000_CHROMA_KEY(x) (((x) >> 29) & 0x3) +#define C_03C000_CHROMA_KEY 0x9FFFFFFF +#define S_03C000_LOD_USES_MINOR_AXIS(x) (((x) & 0x1) << 31) +#define G_03C000_LOD_USES_MINOR_AXIS(x) (((x) >> 31) & 0x1) +#define C_03C000_LOD_USES_MINOR_AXIS 0x7FFFFFFF +#define R_03C004_SQ_TEX_SAMPLER_WORD1_0 0x03C004 +#define S_03C004_MIN_LOD(x) (((x) & 0x3FF) << 0) +#define G_03C004_MIN_LOD(x) (((x) >> 0) & 0x3FF) +#define C_03C004_MIN_LOD 0xFFFFFC00 +#define S_03C004_MAX_LOD(x) (((x) & 0x3FF) << 10) +#define G_03C004_MAX_LOD(x) (((x) >> 10) & 0x3FF) +#define C_03C004_MAX_LOD 0xFFF003FF +#define S_03C004_LOD_BIAS(x) (((x) & 0xFFF) << 20) +#define G_03C004_LOD_BIAS(x) (((x) >> 20) & 0xFFF) +#define C_03C004_LOD_BIAS 0x000FFFFF +#define R_03C008_SQ_TEX_SAMPLER_WORD2_0 0x03C008 +#define S_03C008_LOD_BIAS_SEC(x) (((x) & 0xFFF) << 0) +#define G_03C008_LOD_BIAS_SEC(x) (((x) >> 0) & 0xFFF) +#define C_03C008_LOD_BIAS_SEC 0xFFFFF000 +#define S_03C008_MC_COORD_TRUNCATE(x) (((x) & 0x1) << 12) +#define G_03C008_MC_COORD_TRUNCATE(x) (((x) >> 12) & 0x1) +#define C_03C008_MC_COORD_TRUNCATE 0xFFFFEFFF +#define S_03C008_FORCE_DEGAMMA(x) (((x) & 0x1) << 13) +#define G_03C008_FORCE_DEGAMMA(x) (((x) >> 13) & 0x1) +#define C_03C008_FORCE_DEGAMMA 0xFFFFDFFF +#define S_03C008_HIGH_PRECISION_FILTER(x) (((x) & 0x1) << 14) +#define G_03C008_HIGH_PRECISION_FILTER(x) (((x) >> 14) & 0x1) +#define C_03C008_HIGH_PRECISION_FILTER 0xFFFFBFFF +#define S_03C008_PERF_MIP(x) (((x) & 0x7) << 15) +#define G_03C008_PERF_MIP(x) (((x) >> 15) & 0x7) +#define C_03C008_PERF_MIP 0xFFFC7FFF +#define S_03C008_PERF_Z(x) (((x) & 0x3) << 18) +#define G_03C008_PERF_Z(x) (((x) >> 18) & 0x3) +#define C_03C008_PERF_Z 0xFFF3FFFF +#define S_03C008_FETCH_4(x) (((x) & 0x1) << 26) +#define G_03C008_FETCH_4(x) (((x) >> 26) & 0x1) +#define C_03C008_FETCH_4 0xFBFFFFFF +#define S_03C008_SAMPLE_IS_PCF(x) (((x) & 0x1) << 27) +#define G_03C008_SAMPLE_IS_PCF(x) (((x) >> 27) & 0x1) +#define C_03C008_SAMPLE_IS_PCF 0xF7FFFFFF +#define S_03C008_TYPE(x) (((x) & 0x1) << 31) +#define G_03C008_TYPE(x) (((x) >> 31) & 0x1) +#define C_03C008_TYPE 0x7FFFFFFF +#define R_00A40C_TD_PS_SAMPLER0_BORDER_ALPHA 0x00A40C +#define S_00A40C_BORDER_ALPHA(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A40C_BORDER_ALPHA(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A40C_BORDER_ALPHA 0x00000000 +#define R_00A408_TD_PS_SAMPLER0_BORDER_BLUE 0x00A408 +#define S_00A408_BORDER_BLUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A408_BORDER_BLUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A408_BORDER_BLUE 0x00000000 +#define R_00A404_TD_PS_SAMPLER0_BORDER_GREEN 0x00A404 +#define S_00A404_BORDER_GREEN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A404_BORDER_GREEN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A404_BORDER_GREEN 0x00000000 +#define R_00A400_TD_PS_SAMPLER0_BORDER_RED 0x00A400 +#define S_00A400_BORDER_RED(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A400_BORDER_RED(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A400_BORDER_RED 0x00000000 +#define R_00A60C_TD_VS_SAMPLER0_BORDER_ALPHA 0x00A60C +#define S_00A60C_BORDER_ALPHA(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A60C_BORDER_ALPHA(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A60C_BORDER_ALPHA 0x00000000 +#define R_00A608_TD_VS_SAMPLER0_BORDER_BLUE 0x00A608 +#define S_00A608_BORDER_BLUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A608_BORDER_BLUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A608_BORDER_BLUE 0x00000000 +#define R_00A604_TD_VS_SAMPLER0_BORDER_GREEN 0x00A604 +#define S_00A604_BORDER_GREEN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A604_BORDER_GREEN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A604_BORDER_GREEN 0x00000000 +#define R_00A600_TD_VS_SAMPLER0_BORDER_RED 0x00A600 +#define S_00A600_BORDER_RED(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A600_BORDER_RED(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A600_BORDER_RED 0x00000000 +#define R_00A80C_TD_GS_SAMPLER0_BORDER_ALPHA 0x00A80C +#define S_00A80C_BORDER_ALPHA(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A80C_BORDER_ALPHA(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A80C_BORDER_ALPHA 0x00000000 +#define R_00A808_TD_GS_SAMPLER0_BORDER_BLUE 0x00A808 +#define S_00A808_BORDER_BLUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A808_BORDER_BLUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A808_BORDER_BLUE 0x00000000 +#define R_00A804_TD_GS_SAMPLER0_BORDER_GREEN 0x00A804 +#define S_00A804_BORDER_GREEN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A804_BORDER_GREEN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A804_BORDER_GREEN 0x00000000 +#define R_00A800_TD_GS_SAMPLER0_BORDER_RED 0x00A800 +#define S_00A800_BORDER_RED(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A800_BORDER_RED(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A800_BORDER_RED 0x00000000 +#define R_030000_SQ_ALU_CONSTANT0_0 0x030000 +#define S_030000_X(x) (((x) & 0xFFFFFFFF) << 0) +#define G_030000_X(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_030000_X 0x00000000 +#define R_030004_SQ_ALU_CONSTANT1_0 0x030004 +#define S_030004_Y(x) (((x) & 0xFFFFFFFF) << 0) +#define G_030004_Y(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_030004_Y 0x00000000 +#define R_030008_SQ_ALU_CONSTANT2_0 0x030008 +#define S_030008_Z(x) (((x) & 0xFFFFFFFF) << 0) +#define G_030008_Z(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_030008_Z 0x00000000 +#define R_03000C_SQ_ALU_CONSTANT3_0 0x03000C +#define S_03000C_W(x) (((x) & 0xFFFFFFFF) << 0) +#define G_03000C_W(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_03000C_W 0x00000000 +#define R_0287E4_VGT_DMA_BASE_HI 0x0287E4 +#define R_0287E8_VGT_DMA_BASE 0x0287E8 +#define R_028E20_PA_CL_UCP0_X 0x028E20 +#define R_028E24_PA_CL_UCP0_Y 0x028E24 +#define R_028E28_PA_CL_UCP0_Z 0x028E28 +#define R_028E2C_PA_CL_UCP0_W 0x028E2C +#define R_028E30_PA_CL_UCP1_X 0x028E30 +#define R_028E34_PA_CL_UCP1_Y 0x028E34 +#define R_028E38_PA_CL_UCP1_Z 0x028E38 +#define R_028E3C_PA_CL_UCP1_W 0x028E3C +#define R_028E40_PA_CL_UCP2_X 0x028E40 +#define R_028E44_PA_CL_UCP2_Y 0x028E44 +#define R_028E48_PA_CL_UCP2_Z 0x028E48 +#define R_028E4C_PA_CL_UCP2_W 0x028E4C +#define R_028E50_PA_CL_UCP3_X 0x028E50 +#define R_028E54_PA_CL_UCP3_Y 0x028E54 +#define R_028E58_PA_CL_UCP3_Z 0x028E58 +#define R_028E5C_PA_CL_UCP3_W 0x028E5C +#define R_028E60_PA_CL_UCP4_X 0x028E60 +#define R_028E64_PA_CL_UCP4_Y 0x028E64 +#define R_028E68_PA_CL_UCP4_Z 0x028E68 +#define R_028E6C_PA_CL_UCP4_W 0x028E6C +#define R_028E70_PA_CL_UCP5_X 0x028E70 +#define R_028E74_PA_CL_UCP5_Y 0x028E74 +#define R_028E78_PA_CL_UCP5_Z 0x028E78 +#define R_028E7C_PA_CL_UCP5_W 0x028E7C +#define R_038000_RESOURCE0_WORD0 0x038000 +#define R_038004_RESOURCE0_WORD1 0x038004 +#define R_038008_RESOURCE0_WORD2 0x038008 +#define R_03800C_RESOURCE0_WORD3 0x03800C +#define R_038010_RESOURCE0_WORD4 0x038010 +#define R_038014_RESOURCE0_WORD5 0x038014 +#define R_038018_RESOURCE0_WORD6 0x038018 + +#define R_028140_ALU_CONST_BUFFER_SIZE_PS_0 0x00028140 +#define R_028180_ALU_CONST_BUFFER_SIZE_VS_0 0x00028180 +#define R_028940_ALU_CONST_CACHE_PS_0 0x00028940 +#define R_028980_ALU_CONST_CACHE_VS_0 0x00028980 + +#define R_03CFF0_SQ_VTX_BASE_VTX_LOC 0x03CFF0 +#define R_03CFF4_SQ_VTX_START_INST_LOC 0x03CFF4 + +#define R_03E200_SQ_LOOP_CONST_0 0x3E200 + +#define SQ_TEX_INST_LD 0x03 +#define SQ_TEX_INST_GET_GRADIENTS_H 0x7 +#define SQ_TEX_INST_GET_GRADIENTS_V 0x8 + +#define SQ_TEX_INST_SAMPLE 0x10 +#define SQ_TEX_INST_SAMPLE_L 0x11 +#define SQ_TEX_INST_SAMPLE_C 0x18 +#endif diff --git a/src/gallium/drivers/r600/r700_asm.c b/src/gallium/drivers/r600/r700_asm.c new file mode 100644 index 0000000..892dee8 --- /dev/null +++ b/src/gallium/drivers/r600/r700_asm.c @@ -0,0 +1,78 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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 +#include "util/u_memory.h" +#include "r600_pipe.h" +#include "r600_asm.h" +#include "r700_sq.h" + + +int r700_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsigned id) +{ + unsigned i; + + bc->bytecode[id++] = S_SQ_ALU_WORD0_SRC0_SEL(alu->src[0].sel) | + S_SQ_ALU_WORD0_SRC0_REL(alu->src[0].rel) | + S_SQ_ALU_WORD0_SRC0_CHAN(alu->src[0].chan) | + S_SQ_ALU_WORD0_SRC0_NEG(alu->src[0].neg) | + S_SQ_ALU_WORD0_SRC1_SEL(alu->src[1].sel) | + S_SQ_ALU_WORD0_SRC1_REL(alu->src[1].rel) | + S_SQ_ALU_WORD0_SRC1_CHAN(alu->src[1].chan) | + S_SQ_ALU_WORD0_SRC1_NEG(alu->src[1].neg) | + S_SQ_ALU_WORD0_LAST(alu->last); + + /* don't replace gpr by pv or ps for destination register */ + if (alu->is_op3) { + bc->bytecode[id++] = S_SQ_ALU_WORD1_DST_GPR(alu->dst.sel) | + S_SQ_ALU_WORD1_DST_CHAN(alu->dst.chan) | + S_SQ_ALU_WORD1_DST_REL(alu->dst.rel) | + S_SQ_ALU_WORD1_CLAMP(alu->dst.clamp) | + S_SQ_ALU_WORD1_OP3_SRC2_SEL(alu->src[2].sel) | + S_SQ_ALU_WORD1_OP3_SRC2_REL(alu->src[2].rel) | + S_SQ_ALU_WORD1_OP3_SRC2_CHAN(alu->src[2].chan) | + S_SQ_ALU_WORD1_OP3_SRC2_NEG(alu->src[2].neg) | + S_SQ_ALU_WORD1_OP3_ALU_INST(alu->inst) | + S_SQ_ALU_WORD1_BANK_SWIZZLE(alu->bank_swizzle); + } else { + bc->bytecode[id++] = S_SQ_ALU_WORD1_DST_GPR(alu->dst.sel) | + S_SQ_ALU_WORD1_DST_CHAN(alu->dst.chan) | + S_SQ_ALU_WORD1_DST_REL(alu->dst.rel) | + S_SQ_ALU_WORD1_CLAMP(alu->dst.clamp) | + S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu->src[0].abs) | + S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu->src[1].abs) | + S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu->dst.write) | + S_SQ_ALU_WORD1_OP2_ALU_INST(alu->inst) | + S_SQ_ALU_WORD1_BANK_SWIZZLE(alu->bank_swizzle) | + S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu->predicate) | + S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu->predicate); + } + if (alu->last) { + if (alu->nliteral && !alu->literal_added) { + R600_ERR("Bug in ALU processing for instruction 0x%08x, literal not added correctly\n", alu->inst); + } + for (i = 0; i < alu->nliteral; i++) { + bc->bytecode[id++] = alu->value[i]; + } + } + return 0; +} diff --git a/src/gallium/drivers/r600/r700_sq.h b/src/gallium/drivers/r600/r700_sq.h new file mode 100644 index 0000000..9a117ae --- /dev/null +++ b/src/gallium/drivers/r600/r700_sq.h @@ -0,0 +1,587 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#ifndef R700_SQ_H +#define R700_SQ_H + +#define P_SQ_CF_WORD0 +#define S_SQ_CF_WORD0_ADDR(x) (((x) & 0xFFFFFFFF) << 0) +#define G_SQ_CF_WORD0_ADDR(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_SQ_CF_WORD0_ADDR 0x00000000 +#define P_SQ_CF_WORD1 +#define S_SQ_CF_WORD1_POP_COUNT(x) (((x) & 0x7) << 0) +#define G_SQ_CF_WORD1_POP_COUNT(x) (((x) >> 0) & 0x7) +#define C_SQ_CF_WORD1_POP_COUNT 0xFFFFFFF8 +#define S_SQ_CF_WORD1_CF_CONST(x) (((x) & 0x1F) << 3) +#define G_SQ_CF_WORD1_CF_CONST(x) (((x) >> 3) & 0x1F) +#define C_SQ_CF_WORD1_CF_CONST 0xFFFFFF07 +#define S_SQ_CF_WORD1_COND(x) (((x) & 0x3) << 8) +#define G_SQ_CF_WORD1_COND(x) (((x) >> 8) & 0x3) +#define C_SQ_CF_WORD1_COND 0xFFFFFCFF +#define S_SQ_CF_WORD1_COUNT(x) (((x) & 0x7) << 10) +#define G_SQ_CF_WORD1_COUNT(x) (((x) >> 10) & 0x7) +#define C_SQ_CF_WORD1_COUNT 0xFFFFE3FF +#define S_SQ_CF_WORD1_CALL_COUNT(x) (((x) & 0x3F) << 13) +#define G_SQ_CF_WORD1_CALL_COUNT(x) (((x) >> 13) & 0x3F) +#define C_SQ_CF_WORD1_CALL_COUNT 0xFFF81FFF +#define S_SQ_CF_WORD1_END_OF_PROGRAM(x) (((x) & 0x1) << 21) +#define G_SQ_CF_WORD1_END_OF_PROGRAM(x) (((x) >> 21) & 0x1) +#define C_SQ_CF_WORD1_END_OF_PROGRAM 0xFFDFFFFF +#define S_SQ_CF_WORD1_VALID_PIXEL_MODE(x) (((x) & 0x1) << 22) +#define G_SQ_CF_WORD1_VALID_PIXEL_MODE(x) (((x) >> 22) & 0x1) +#define C_SQ_CF_WORD1_VALID_PIXEL_MODE 0xFFBFFFFF +#define S_SQ_CF_WORD1_CF_INST(x) (((x) & 0x7F) << 23) +#define G_SQ_CF_WORD1_CF_INST(x) (((x) >> 23) & 0x7F) +#define C_SQ_CF_WORD1_CF_INST 0xC07FFFFF +#define V_SQ_CF_WORD1_SQ_CF_INST_NOP 0x00000000 +#define V_SQ_CF_WORD1_SQ_CF_INST_TEX 0x00000001 +#define V_SQ_CF_WORD1_SQ_CF_INST_VTX 0x00000002 +#define V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC 0x00000003 +#define V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START 0x00000004 +#define V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END 0x00000005 +#define V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_DX10 0x00000006 +#define V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL 0x00000007 +#define V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE 0x00000008 +#define V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK 0x00000009 +#define V_SQ_CF_WORD1_SQ_CF_INST_JUMP 0x0000000A +#define V_SQ_CF_WORD1_SQ_CF_INST_PUSH 0x0000000B +#define V_SQ_CF_WORD1_SQ_CF_INST_PUSH_ELSE 0x0000000C +#define V_SQ_CF_WORD1_SQ_CF_INST_ELSE 0x0000000D +#define V_SQ_CF_WORD1_SQ_CF_INST_POP 0x0000000E +#define V_SQ_CF_WORD1_SQ_CF_INST_POP_JUMP 0x0000000F +#define V_SQ_CF_WORD1_SQ_CF_INST_POP_PUSH 0x00000010 +#define V_SQ_CF_WORD1_SQ_CF_INST_POP_PUSH_ELSE 0x00000011 +#define V_SQ_CF_WORD1_SQ_CF_INST_CALL 0x00000012 +#define V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS 0x00000013 +#define V_SQ_CF_WORD1_SQ_CF_INST_RETURN 0x00000014 +#define V_SQ_CF_WORD1_SQ_CF_INST_EMIT_VERTEX 0x00000015 +#define V_SQ_CF_WORD1_SQ_CF_INST_EMIT_CUT_VERTEX 0x00000016 +#define V_SQ_CF_WORD1_SQ_CF_INST_CUT_VERTEX 0x00000017 +#define V_SQ_CF_WORD1_SQ_CF_INST_KILL 0x00000018 +#define S_SQ_CF_WORD1_WHOLE_QUAD_MODE(x) (((x) & 0x1) << 30) +#define G_SQ_CF_WORD1_WHOLE_QUAD_MODE(x) (((x) >> 30) & 0x1) +#define C_SQ_CF_WORD1_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_SQ_CF_WORD1_BARRIER(x) (((x) & 0x1) << 31) +#define G_SQ_CF_WORD1_BARRIER(x) (((x) >> 31) & 0x1) +#define C_SQ_CF_WORD1_BARRIER 0x7FFFFFFF +#define S_SQ_CF_WORD1_COUNT_3(x) (((x) & 0x1) << 19) +#define G_SQ_CF_WORD1_COUNT_3(x) (((x) >> 19) & 0x1) +#define C_SQ_CF_WORD1_COUNT_3 0xFFF7FFFF +#define P_SQ_CF_ALU_WORD0 +#define S_SQ_CF_ALU_WORD0_ADDR(x) (((x) & 0x3FFFFF) << 0) +#define G_SQ_CF_ALU_WORD0_ADDR(x) (((x) >> 0) & 0x3FFFFF) +#define C_SQ_CF_ALU_WORD0_ADDR 0xFFC00000 +#define S_SQ_CF_ALU_WORD0_KCACHE_BANK0(x) (((x) & 0xF) << 22) +#define G_SQ_CF_ALU_WORD0_KCACHE_BANK0(x) (((x) >> 22) & 0xF) +#define C_SQ_CF_ALU_WORD0_KCACHE_BANK0 0xFC3FFFFF +#define S_SQ_CF_ALU_WORD0_KCACHE_BANK1(x) (((x) & 0xF) << 26) +#define G_SQ_CF_ALU_WORD0_KCACHE_BANK1(x) (((x) >> 26) & 0xF) +#define C_SQ_CF_ALU_WORD0_KCACHE_BANK1 0xC3FFFFFF +#define S_SQ_CF_ALU_WORD0_KCACHE_MODE0(x) (((x) & 0x3) << 30) +#define G_SQ_CF_ALU_WORD0_KCACHE_MODE0(x) (((x) >> 30) & 0x3) +#define C_SQ_CF_ALU_WORD0_KCACHE_MODE0 0x3FFFFFFF +#define P_SQ_CF_ALU_WORD1 +#define S_SQ_CF_ALU_WORD1_KCACHE_MODE1(x) (((x) & 0x3) << 0) +#define G_SQ_CF_ALU_WORD1_KCACHE_MODE1(x) (((x) >> 0) & 0x3) +#define C_SQ_CF_ALU_WORD1_KCACHE_MODE1 0xFFFFFFFC +#define S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(x) (((x) & 0xFF) << 2) +#define G_SQ_CF_ALU_WORD1_KCACHE_ADDR0(x) (((x) >> 2) & 0xFF) +#define C_SQ_CF_ALU_WORD1_KCACHE_ADDR0 0xFFFFFC03 +#define S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(x) (((x) & 0xFF) << 10) +#define G_SQ_CF_ALU_WORD1_KCACHE_ADDR1(x) (((x) >> 10) & 0xFF) +#define C_SQ_CF_ALU_WORD1_KCACHE_ADDR1 0xFFFC03FF +#define S_SQ_CF_ALU_WORD1_COUNT(x) (((x) & 0x7F) << 18) +#define G_SQ_CF_ALU_WORD1_COUNT(x) (((x) >> 18) & 0x7F) +#define C_SQ_CF_ALU_WORD1_COUNT 0xFE03FFFF +#define S_SQ_CF_ALU_WORD1_USES_WATERFALL(x) (((x) & 0x1) << 25) +#define G_SQ_CF_ALU_WORD1_USES_WATERFALL(x) (((x) >> 25) & 0x1) +#define C_SQ_CF_ALU_WORD1_USES_WATERFALL 0xFDFFFFFF +#define S_SQ_CF_ALU_WORD1_CF_INST(x) (((x) & 0xF) << 26) +#define G_SQ_CF_ALU_WORD1_CF_INST(x) (((x) >> 26) & 0xF) +#define C_SQ_CF_ALU_WORD1_CF_INST 0xC3FFFFFF +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU 0x00000008 +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE 0x00000009 +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER 0x0000000A +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER 0x0000000B +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_CONTINUE 0x0000000D +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_BREAK 0x0000000E +#define V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_ELSE_AFTER 0x0000000F +#define S_SQ_CF_ALU_WORD1_WHOLE_QUAD_MODE(x) (((x) & 0x1) << 30) +#define G_SQ_CF_ALU_WORD1_WHOLE_QUAD_MODE(x) (((x) >> 30) & 0x1) +#define C_SQ_CF_ALU_WORD1_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_SQ_CF_ALU_WORD1_BARRIER(x) (((x) & 0x1) << 31) +#define G_SQ_CF_ALU_WORD1_BARRIER(x) (((x) >> 31) & 0x1) +#define C_SQ_CF_ALU_WORD1_BARRIER 0x7FFFFFFF +#define S_SQ_CF_ALU_WORD1_ALT_CONST(x) (((x) & 0x1) << 25) +#define G_SQ_CF_ALU_WORD1_ALT_CONST(x) (((x) >> 25) & 0x1) +#define C_SQ_CF_ALU_WORD1_ALT_CONST 0xFDFFFFFF +#define P_SQ_CF_ALLOC_EXPORT_WORD0 +#define S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(x) (((x) & 0x1FFF) << 0) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(x) (((x) >> 0) & 0x1FFF) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE 0xFFFFE000 +#define S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(x) (((x) & 0x3) << 13) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(x) (((x) >> 13) & 0x3) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_TYPE 0xFFFF9FFF +#define V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL 0x00000000 +#define V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS 0x00000001 +#define V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM 0x00000002 +#define V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_SX 0x00000003 +#define S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(x) (((x) & 0x7F) << 15) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(x) (((x) >> 15) & 0x7F) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR 0xFFC07FFF +#define S_SQ_CF_ALLOC_EXPORT_WORD0_RW_REL(x) (((x) & 0x1) << 22) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_RW_REL(x) (((x) >> 22) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_RW_REL 0xFFBFFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD0_INDEX_GPR(x) (((x) & 0x7F) << 23) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_INDEX_GPR(x) (((x) >> 23) & 0x7F) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_INDEX_GPR 0xC07FFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(x) (((x) & 0x3) << 30) +#define G_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(x) (((x) >> 30) & 0x3) +#define C_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE 0x3FFFFFFF +#define P_SQ_CF_ALLOC_EXPORT_WORD1 +#define S_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(x) (((x) & 0xF) << 17) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT(x) (((x) >> 17) & 0xF) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_BURST_COUNT 0xFFE1FFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(x) (((x) & 0x1) << 21) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(x) (((x) >> 21) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM 0xFFDFFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_VALID_PIXEL_MODE(x) (((x) & 0x1) << 22) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_VALID_PIXEL_MODE(x) (((x) >> 22) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_VALID_PIXEL_MODE 0xFFBFFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(x) (((x) & 0x7F) << 23) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(x) (((x) >> 23) & 0x7F) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST 0xC07FFFFF +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM0 0x00000020 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM1 0x00000021 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM2 0x00000022 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_STREAM3 0x00000023 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_SCRATCH 0x00000024 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_REDUCTION 0x00000025 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_MEM_RING 0x00000026 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT 0x00000027 +#define V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE 0x00000028 +#define S_SQ_CF_ALLOC_EXPORT_WORD1_WHOLE_QUAD_MODE(x) (((x) & 0x1) << 30) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_WHOLE_QUAD_MODE(x) (((x) >> 30) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(x) (((x) & 0x1) << 31) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(x) (((x) >> 31) & 0x1) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER 0x7FFFFFFF +#define P_SQ_CF_ALLOC_EXPORT_WORD1_BUF +#define S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(x) (((x) & 0xFFF) << 0) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE(x) (((x) >> 0) & 0xFFF) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_BUF_ARRAY_SIZE 0xFFFFF000 +#define S_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(x) (((x) & 0xF) << 12) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK(x) (((x) >> 12) & 0xF) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_BUF_COMP_MASK 0xFFFF0FFF +#define P_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ +#define S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(x) (((x) & 0x7) << 0) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(x) (((x) >> 0) & 0x7) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X 0xFFFFFFF8 +#define S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(x) (((x) & 0x7) << 3) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(x) (((x) >> 3) & 0x7) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y 0xFFFFFFC7 +#define S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(x) (((x) & 0x7) << 6) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(x) (((x) >> 6) & 0x7) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z 0xFFFFFE3F +#define S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(x) (((x) & 0x7) << 9) +#define G_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(x) (((x) >> 9) & 0x7) +#define C_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W 0xFFFFF1FF +#define P_SQ_ALU_WORD0 +#define S_SQ_ALU_WORD0_SRC0_SEL(x) (((x) & 0x1FF) << 0) +#define G_SQ_ALU_WORD0_SRC0_SEL(x) (((x) >> 0) & 0x1FF) +#define C_SQ_ALU_WORD0_SRC0_SEL 0xFFFFFE00 +#define S_SQ_ALU_WORD0_SRC0_REL(x) (((x) & 0x1) << 9) +#define G_SQ_ALU_WORD0_SRC0_REL(x) (((x) >> 9) & 0x1) +#define C_SQ_ALU_WORD0_SRC0_REL 0xFFFFFDFF +#define S_SQ_ALU_WORD0_SRC0_CHAN(x) (((x) & 0x3) << 10) +#define G_SQ_ALU_WORD0_SRC0_CHAN(x) (((x) >> 10) & 0x3) +#define C_SQ_ALU_WORD0_SRC0_CHAN 0xFFFFF3FF +#define S_SQ_ALU_WORD0_SRC0_NEG(x) (((x) & 0x1) << 12) +#define G_SQ_ALU_WORD0_SRC0_NEG(x) (((x) >> 12) & 0x1) +#define C_SQ_ALU_WORD0_SRC0_NEG 0xFFFFEFFF +#define S_SQ_ALU_WORD0_SRC1_SEL(x) (((x) & 0x1FF) << 13) +#define G_SQ_ALU_WORD0_SRC1_SEL(x) (((x) >> 13) & 0x1FF) +#define C_SQ_ALU_WORD0_SRC1_SEL 0xFFC01FFF +#define S_SQ_ALU_WORD0_SRC1_REL(x) (((x) & 0x1) << 22) +#define G_SQ_ALU_WORD0_SRC1_REL(x) (((x) >> 22) & 0x1) +#define C_SQ_ALU_WORD0_SRC1_REL 0xFFBFFFFF +#define S_SQ_ALU_WORD0_SRC1_CHAN(x) (((x) & 0x3) << 23) +#define G_SQ_ALU_WORD0_SRC1_CHAN(x) (((x) >> 23) & 0x3) +#define C_SQ_ALU_WORD0_SRC1_CHAN 0xFE7FFFFF +#define S_SQ_ALU_WORD0_SRC1_NEG(x) (((x) & 0x1) << 25) +#define G_SQ_ALU_WORD0_SRC1_NEG(x) (((x) >> 25) & 0x1) +#define C_SQ_ALU_WORD0_SRC1_NEG 0xFDFFFFFF +#define S_SQ_ALU_WORD0_INDEX_MODE(x) (((x) & 0x7) << 26) +#define G_SQ_ALU_WORD0_INDEX_MODE(x) (((x) >> 26) & 0x7) +#define C_SQ_ALU_WORD0_INDEX_MODE 0xE3FFFFFF +#define S_SQ_ALU_WORD0_PRED_SEL(x) (((x) & 0x3) << 29) +#define G_SQ_ALU_WORD0_PRED_SEL(x) (((x) >> 29) & 0x3) +#define C_SQ_ALU_WORD0_PRED_SEL 0x9FFFFFFF +#define S_SQ_ALU_WORD0_LAST(x) (((x) & 0x1) << 31) +#define G_SQ_ALU_WORD0_LAST(x) (((x) >> 31) & 0x1) +#define C_SQ_ALU_WORD0_LAST 0x7FFFFFFF +#define P_SQ_ALU_WORD1 +#define S_SQ_ALU_WORD1_ENCODING(x) (((x) & 0x7) << 15) +#define G_SQ_ALU_WORD1_ENCODING(x) (((x) >> 15) & 0x7) +#define C_SQ_ALU_WORD1_ENCODING 0xFFFC7FFF +#define S_SQ_ALU_WORD1_BANK_SWIZZLE(x) (((x) & 0x7) << 18) +#define G_SQ_ALU_WORD1_BANK_SWIZZLE(x) (((x) >> 18) & 0x7) +#define C_SQ_ALU_WORD1_BANK_SWIZZLE 0xFFE3FFFF +#define S_SQ_ALU_WORD1_DST_GPR(x) (((x) & 0x7F) << 21) +#define G_SQ_ALU_WORD1_DST_GPR(x) (((x) >> 21) & 0x7F) +#define C_SQ_ALU_WORD1_DST_GPR 0xF01FFFFF +#define S_SQ_ALU_WORD1_DST_REL(x) (((x) & 0x1) << 28) +#define G_SQ_ALU_WORD1_DST_REL(x) (((x) >> 28) & 0x1) +#define C_SQ_ALU_WORD1_DST_REL 0xEFFFFFFF +#define S_SQ_ALU_WORD1_DST_CHAN(x) (((x) & 0x3) << 29) +#define G_SQ_ALU_WORD1_DST_CHAN(x) (((x) >> 29) & 0x3) +#define C_SQ_ALU_WORD1_DST_CHAN 0x9FFFFFFF +#define S_SQ_ALU_WORD1_CLAMP(x) (((x) & 0x1) << 31) +#define G_SQ_ALU_WORD1_CLAMP(x) (((x) >> 31) & 0x1) +#define C_SQ_ALU_WORD1_CLAMP 0x7FFFFFFF +#define P_SQ_ALU_WORD1_OP2 +#define S_SQ_ALU_WORD1_OP2_SRC0_ABS(x) (((x) & 0x1) << 0) +#define G_SQ_ALU_WORD1_OP2_SRC0_ABS(x) (((x) >> 0) & 0x1) +#define C_SQ_ALU_WORD1_OP2_SRC0_ABS 0xFFFFFFFE +#define S_SQ_ALU_WORD1_OP2_SRC1_ABS(x) (((x) & 0x1) << 1) +#define G_SQ_ALU_WORD1_OP2_SRC1_ABS(x) (((x) >> 1) & 0x1) +#define C_SQ_ALU_WORD1_OP2_SRC1_ABS 0xFFFFFFFD +#define S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(x) (((x) & 0x1) << 2) +#define G_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(x) (((x) >> 2) & 0x1) +#define C_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK 0xFFFFFFFB +#define S_SQ_ALU_WORD1_OP2_UPDATE_PRED(x) (((x) & 0x1) << 3) +#define G_SQ_ALU_WORD1_OP2_UPDATE_PRED(x) (((x) >> 3) & 0x1) +#define C_SQ_ALU_WORD1_OP2_UPDATE_PRED 0xFFFFFFF7 +#define S_SQ_ALU_WORD1_OP2_WRITE_MASK(x) (((x) & 0x1) << 4) +#define G_SQ_ALU_WORD1_OP2_WRITE_MASK(x) (((x) >> 4) & 0x1) +#define C_SQ_ALU_WORD1_OP2_WRITE_MASK 0xFFFFFFEF +#define S_SQ_ALU_WORD1_OP2_OMOD(x) (((x) & 0x3) << 5) +#define G_SQ_ALU_WORD1_OP2_OMOD(x) (((x) >> 5) & 0x3) +#define C_SQ_ALU_WORD1_OP2_OMOD 0xFFFFFF9F +#define S_SQ_ALU_WORD1_OP2_ALU_INST(x) (((x) & 0x7FF) << 7) +#define G_SQ_ALU_WORD1_OP2_ALU_INST(x) (((x) >> 7) & 0x7FF) +#define C_SQ_ALU_WORD1_OP2_ALU_INST 0xFFFC007F +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD 0x00000000 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL 0x00000001 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL_IEEE 0x00000002 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX 0x00000003 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN 0x00000004 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_DX10 0x00000005 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_DX10 0x00000006 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE 0x00000008 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT 0x00000009 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE 0x0000000A +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE 0x0000000B +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE_DX10 0x0000000C +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_DX10 0x0000000D +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_DX10 0x0000000E +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE_DX10 0x0000000F +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT 0x00000010 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC 0x00000011 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CEIL 0x00000012 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RNDNE 0x00000013 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR 0x00000014 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA 0x00000015 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR 0x00000016 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT 0x00000018 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV 0x00000019 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP 0x0000001A +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_UINT 0x0000001E +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_UINT 0x0000001F +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE 0x00000020 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT 0x00000021 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE 0x00000022 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE 0x00000023 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_INV 0x00000024 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_POP 0x00000025 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_CLR 0x00000026 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SET_RESTORE 0x00000027 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH 0x00000028 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH 0x00000029 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH 0x0000002A +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH 0x0000002B +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE 0x0000002C +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT 0x0000002D +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE 0x0000002E +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE 0x0000002F +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_AND_INT 0x00000030 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_OR_INT 0x00000031 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_XOR_INT 0x00000032 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOT_INT 0x00000033 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD_INT 0x00000034 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SUB_INT 0x00000035 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_INT 0x00000036 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_INT 0x00000037 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX_UINT 0x00000038 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN_UINT 0x00000039 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE_INT 0x0000003A +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_INT 0x0000003B +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_INT 0x0000003C +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE_INT 0x0000003D +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT_UINT 0x0000003E +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE_UINT 0x0000003F +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_UINT 0x00000040 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_UINT 0x00000041 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT 0x00000042 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_INT 0x00000043 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_INT 0x00000044 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT 0x00000045 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE_INT 0x00000046 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT_INT 0x00000047 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE_INT 0x00000048 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE_INT 0x00000049 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_PUSH_INT 0x0000004A +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT_PUSH_INT 0x0000004B +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE_PUSH_INT 0x0000004C +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_PUSH_INT 0x0000004D +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLT_PUSH_INT 0x0000004E +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETLE_PUSH_INT 0x0000004F +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4 0x00000050 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE 0x00000051 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE 0x00000052 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX4 0x00000053 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT 0x00000060 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE 0x00000061 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED 0x00000062 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE 0x00000063 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED 0x00000064 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_FF 0x00000065 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE 0x00000066 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED 0x00000067 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_FF 0x00000068 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE 0x00000069 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SQRT_IEEE 0x0000006A +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT 0x0000006B +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT 0x0000006C +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_UINT_TO_FLT 0x0000006D +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN 0x0000006E +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS 0x0000006F +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT 0x00000070 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHR_INT 0x00000071 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LSHL_INT 0x00000072 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_INT 0x00000073 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_INT 0x00000074 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULLO_UINT 0x00000075 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MULHI_UINT 0x00000076 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_INT 0x00000077 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_UINT 0x00000078 +#define V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT 0x00000079 +#define P_SQ_ALU_WORD1_OP3 +#define S_SQ_ALU_WORD1_OP3_SRC2_SEL(x) (((x) & 0x1FF) << 0) +#define G_SQ_ALU_WORD1_OP3_SRC2_SEL(x) (((x) >> 0) & 0x1FF) +#define C_SQ_ALU_WORD1_OP3_SRC2_SEL 0xFFFFFE00 +#define S_SQ_ALU_WORD1_OP3_SRC2_REL(x) (((x) & 0x1) << 9) +#define G_SQ_ALU_WORD1_OP3_SRC2_REL(x) (((x) >> 9) & 0x1) +#define C_SQ_ALU_WORD1_OP3_SRC2_REL 0xFFFFFDFF +#define S_SQ_ALU_WORD1_OP3_SRC2_CHAN(x) (((x) & 0x3) << 10) +#define G_SQ_ALU_WORD1_OP3_SRC2_CHAN(x) (((x) >> 10) & 0x3) +#define C_SQ_ALU_WORD1_OP3_SRC2_CHAN 0xFFFFF3FF +#define S_SQ_ALU_WORD1_OP3_SRC2_NEG(x) (((x) & 0x1) << 12) +#define G_SQ_ALU_WORD1_OP3_SRC2_NEG(x) (((x) >> 12) & 0x1) +#define C_SQ_ALU_WORD1_OP3_SRC2_NEG 0xFFFFEFFF +#define S_SQ_ALU_WORD1_OP3_ALU_INST(x) (((x) & 0x1F) << 13) +#define G_SQ_ALU_WORD1_OP3_ALU_INST(x) (((x) >> 13) & 0x1F) +#define C_SQ_ALU_WORD1_OP3_ALU_INST 0xFFFC1FFF +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT 0x0000000C +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_M2 0x0000000D +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_M4 0x0000000E +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT_D2 0x0000000F +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD 0x00000010 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_M2 0x00000011 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_M4 0x00000012 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_D2 0x00000013 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_IEEE 0x00000014 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_IEEE_M2 0x00000015 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_IEEE_M4 0x00000016 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD_IEEE_D2 0x00000017 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDE 0x00000018 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT 0x00000019 +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE 0x0000001A +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDE_INT 0x0000001C +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT_INT 0x0000001D +#define V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE_INT 0x0000001E +#define P_SQ_VTX_WORD0 +#define S_SQ_VTX_WORD0_VTX_INST(x) (((x) & 0x1F) << 0) +#define G_SQ_VTX_WORD0_VTX_INST(x) (((x) >> 0) & 0x1F) +#define C_SQ_VTX_WORD0_VTX_INST 0xFFFFFFE0 +#define S_SQ_VTX_WORD0_FETCH_TYPE(x) (((x) & 0x3) << 5) +#define G_SQ_VTX_WORD0_FETCH_TYPE(x) (((x) >> 5) & 0x3) +#define C_SQ_VTX_WORD0_FETCH_TYPE 0xFFFFFF9F +#define S_SQ_VTX_WORD0_FETCH_WHOLE_QUAD(x) (((x) & 0x1) << 7) +#define G_SQ_VTX_WORD0_FETCH_WHOLE_QUAD(x) (((x) >> 7) & 0x1) +#define C_SQ_VTX_WORD0_FETCH_WHOLE_QUAD 0xFFFFFF7F +#define S_SQ_VTX_WORD0_BUFFER_ID(x) (((x) & 0xFF) << 8) +#define G_SQ_VTX_WORD0_BUFFER_ID(x) (((x) >> 8) & 0xFF) +#define C_SQ_VTX_WORD0_BUFFER_ID 0xFFFF00FF +#define S_SQ_VTX_WORD0_SRC_GPR(x) (((x) & 0x7F) << 16) +#define G_SQ_VTX_WORD0_SRC_GPR(x) (((x) >> 16) & 0x7F) +#define C_SQ_VTX_WORD0_SRC_GPR 0xFF80FFFF +#define S_SQ_VTX_WORD0_SRC_REL(x) (((x) & 0x1) << 23) +#define G_SQ_VTX_WORD0_SRC_REL(x) (((x) >> 23) & 0x1) +#define C_SQ_VTX_WORD0_SRC_REL 0xFF7FFFFF +#define S_SQ_VTX_WORD0_SRC_SEL_X(x) (((x) & 0x3) << 24) +#define G_SQ_VTX_WORD0_SRC_SEL_X(x) (((x) >> 24) & 0x3) +#define C_SQ_VTX_WORD0_SRC_SEL_X 0xFCFFFFFF +#define S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(x) (((x) & 0x3F) << 26) +#define G_SQ_VTX_WORD0_MEGA_FETCH_COUNT(x) (((x) >> 26) & 0x3F) +#define C_SQ_VTX_WORD0_MEGA_FETCH_COUNT 0x03FFFFFF +#define P_SQ_VTX_WORD1 +#define S_SQ_VTX_WORD1_DST_SEL_X(x) (((x) & 0x7) << 9) +#define G_SQ_VTX_WORD1_DST_SEL_X(x) (((x) >> 9) & 0x7) +#define C_SQ_VTX_WORD1_DST_SEL_X 0xFFFFF1FF +#define S_SQ_VTX_WORD1_DST_SEL_Y(x) (((x) & 0x7) << 12) +#define G_SQ_VTX_WORD1_DST_SEL_Y(x) (((x) >> 12) & 0x7) +#define C_SQ_VTX_WORD1_DST_SEL_Y 0xFFFF8FFF +#define S_SQ_VTX_WORD1_DST_SEL_Z(x) (((x) & 0x7) << 15) +#define G_SQ_VTX_WORD1_DST_SEL_Z(x) (((x) >> 15) & 0x7) +#define C_SQ_VTX_WORD1_DST_SEL_Z 0xFFFC7FFF +#define S_SQ_VTX_WORD1_DST_SEL_W(x) (((x) & 0x7) << 18) +#define G_SQ_VTX_WORD1_DST_SEL_W(x) (((x) >> 18) & 0x7) +#define C_SQ_VTX_WORD1_DST_SEL_W 0xFFE3FFFF +#define S_SQ_VTX_WORD1_USE_CONST_FIELDS(x) (((x) & 0x1) << 21) +#define G_SQ_VTX_WORD1_USE_CONST_FIELDS(x) (((x) >> 21) & 0x1) +#define C_SQ_VTX_WORD1_USE_CONST_FIELDS 0xFFDFFFFF +#define S_SQ_VTX_WORD1_DATA_FORMAT(x) (((x) & 0x3F) << 22) +#define G_SQ_VTX_WORD1_DATA_FORMAT(x) (((x) >> 22) & 0x3F) +#define C_SQ_VTX_WORD1_DATA_FORMAT 0xF03FFFFF +#define S_SQ_VTX_WORD1_NUM_FORMAT_ALL(x) (((x) & 0x3) << 28) +#define G_SQ_VTX_WORD1_NUM_FORMAT_ALL(x) (((x) >> 28) & 0x3) +#define C_SQ_VTX_WORD1_NUM_FORMAT_ALL 0xCFFFFFFF +#define S_SQ_VTX_WORD1_FORMAT_COMP_ALL(x) (((x) & 0x1) << 30) +#define G_SQ_VTX_WORD1_FORMAT_COMP_ALL(x) (((x) >> 30) & 0x1) +#define C_SQ_VTX_WORD1_FORMAT_COMP_ALL 0xBFFFFFFF +#define S_SQ_VTX_WORD1_SRF_MODE_ALL(x) (((x) & 0x1) << 31) +#define G_SQ_VTX_WORD1_SRF_MODE_ALL(x) (((x) >> 31) & 0x1) +#define C_SQ_VTX_WORD1_SRF_MODE_ALL 0x7FFFFFFF +#define P_SQ_VTX_WORD1_GPR +#define S_SQ_VTX_WORD1_GPR_DST_GPR(x) (((x) & 0x7F) << 0) +#define G_SQ_VTX_WORD1_GPR_DST_GPR(x) (((x) >> 0) & 0x7F) +#define C_SQ_VTX_WORD1_GPR_DST_GPR 0xFFFFFF80 +#define S_SQ_VTX_WORD1_GPR_DST_REL(x) (((x) & 0x1) << 7) +#define G_SQ_VTX_WORD1_GPR_DST_REL(x) (((x) >> 7) & 0x1) +#define C_SQ_VTX_WORD1_GPR_DST_REL 0xFFFFFF7F +#define P_SQ_VTX_WORD1_SEM +#define S_SQ_VTX_WORD1_SEM_SEMANTIC_ID(x) (((x) & 0xFF) << 0) +#define G_SQ_VTX_WORD1_SEM_SEMANTIC_ID(x) (((x) >> 0) & 0xFF) +#define C_SQ_VTX_WORD1_SEM_SEMANTIC_ID 0xFFFFFF00 +#define P_SQ_VTX_WORD2 +#define S_SQ_VTX_WORD2_OFFSET(x) (((x) & 0xFFFF) << 0) +#define G_SQ_VTX_WORD2_OFFSET(x) (((x) >> 0) & 0xFFFF) +#define C_SQ_VTX_WORD2_OFFSET 0xFFFF0000 +#define S_SQ_VTX_WORD2_ENDIAN_SWAP(x) (((x) & 0x3) << 16) +#define G_SQ_VTX_WORD2_ENDIAN_SWAP(x) (((x) >> 16) & 0x3) +#define C_SQ_VTX_WORD2_ENDIAN_SWAP 0xFFFCFFFF +#define S_SQ_VTX_WORD2_CONST_BUF_NO_STRIDE(x) (((x) & 0x1) << 18) +#define G_SQ_VTX_WORD2_CONST_BUF_NO_STRIDE(x) (((x) >> 18) & 0x1) +#define C_SQ_VTX_WORD2_CONST_BUF_NO_STRIDE 0xFFFBFFFF +#define S_SQ_VTX_WORD2_MEGA_FETCH(x) (((x) & 0x1) << 19) +#define G_SQ_VTX_WORD2_MEGA_FETCH(x) (((x) >> 19) & 0x1) +#define C_SQ_VTX_WORD2_MEGA_FETCH 0xFFF7FFFF +#define S_SQ_VTX_WORD2_ALT_CONST(x) (((x) & 0x1) << 20) +#define G_SQ_VTX_WORD2_ALT_CONST(x) (((x) >> 20) & 0x1) +#define C_SQ_VTX_WORD2_ALT_CONST 0xFFEFFFFF +#define P_SQ_TEX_WORD0 +#define S_SQ_TEX_WORD0_TEX_INST(x) (((x) & 0x1F) << 0) +#define G_SQ_TEX_WORD0_TEX_INST(x) (((x) >> 0) & 0x1F) +#define C_SQ_TEX_WORD0_TEX_INST 0xFFFFFFE0 +#define S_SQ_TEX_WORD0_BC_FRAC_MODE(x) (((x) & 0x1) << 5) +#define G_SQ_TEX_WORD0_BC_FRAC_MODE(x) (((x) >> 5) & 0x1) +#define C_SQ_TEX_WORD0_BC_FRAC_MODE 0xFFFFFFDF +#define S_SQ_TEX_WORD0_FETCH_WHOLE_QUAD(x) (((x) & 0x1) << 7) +#define G_SQ_TEX_WORD0_FETCH_WHOLE_QUAD(x) (((x) >> 7) & 0x1) +#define C_SQ_TEX_WORD0_FETCH_WHOLE_QUAD 0xFFFFFF7F +#define S_SQ_TEX_WORD0_RESOURCE_ID(x) (((x) & 0xFF) << 8) +#define G_SQ_TEX_WORD0_RESOURCE_ID(x) (((x) >> 8) & 0xFF) +#define C_SQ_TEX_WORD0_RESOURCE_ID 0xFFFF00FF +#define S_SQ_TEX_WORD0_SRC_GPR(x) (((x) & 0x7F) << 16) +#define G_SQ_TEX_WORD0_SRC_GPR(x) (((x) >> 16) & 0x7F) +#define C_SQ_TEX_WORD0_SRC_GPR 0xFF80FFFF +#define S_SQ_TEX_WORD0_SRC_REL(x) (((x) & 0x1) << 23) +#define G_SQ_TEX_WORD0_SRC_REL(x) (((x) >> 23) & 0x1) +#define C_SQ_TEX_WORD0_SRC_REL 0xFF7FFFFF +#define S_SQ_TEX_WORD0_ALT_CONST(x) (((x) & 0x1) << 24) +#define G_SQ_TEX_WORD0_ALT_CONST(x) (((x) >> 24) & 0x1) +#define C_SQ_TEX_WORD0_ALT_CONST 0xFEFFFFFF +#define P_SQ_TEX_WORD1 +#define S_SQ_TEX_WORD1_DST_GPR(x) (((x) & 0x7F) << 0) +#define G_SQ_TEX_WORD1_DST_GPR(x) (((x) >> 0) & 0x7F) +#define C_SQ_TEX_WORD1_DST_GPR 0xFFFFFF80 +#define S_SQ_TEX_WORD1_DST_REL(x) (((x) & 0x1) << 7) +#define G_SQ_TEX_WORD1_DST_REL(x) (((x) >> 7) & 0x1) +#define C_SQ_TEX_WORD1_DST_REL 0xFFFFFF7F +#define S_SQ_TEX_WORD1_DST_SEL_X(x) (((x) & 0x7) << 9) +#define G_SQ_TEX_WORD1_DST_SEL_X(x) (((x) >> 9) & 0x7) +#define C_SQ_TEX_WORD1_DST_SEL_X 0xFFFFF1FF +#define S_SQ_TEX_WORD1_DST_SEL_Y(x) (((x) & 0x7) << 12) +#define G_SQ_TEX_WORD1_DST_SEL_Y(x) (((x) >> 12) & 0x7) +#define C_SQ_TEX_WORD1_DST_SEL_Y 0xFFFF8FFF +#define S_SQ_TEX_WORD1_DST_SEL_Z(x) (((x) & 0x7) << 15) +#define G_SQ_TEX_WORD1_DST_SEL_Z(x) (((x) >> 15) & 0x7) +#define C_SQ_TEX_WORD1_DST_SEL_Z 0xFFFC7FFF +#define S_SQ_TEX_WORD1_DST_SEL_W(x) (((x) & 0x7) << 18) +#define G_SQ_TEX_WORD1_DST_SEL_W(x) (((x) >> 18) & 0x7) +#define C_SQ_TEX_WORD1_DST_SEL_W 0xFFE3FFFF +#define S_SQ_TEX_WORD1_LOD_BIAS(x) (((x) & 0x7F) << 21) +#define G_SQ_TEX_WORD1_LOD_BIAS(x) (((x) >> 21) & 0x7F) +#define C_SQ_TEX_WORD1_LOD_BIAS 0xF01FFFFF +#define S_SQ_TEX_WORD1_COORD_TYPE_X(x) (((x) & 0x1) << 28) +#define G_SQ_TEX_WORD1_COORD_TYPE_X(x) (((x) >> 28) & 0x1) +#define C_SQ_TEX_WORD1_COORD_TYPE_X 0xEFFFFFFF +#define S_SQ_TEX_WORD1_COORD_TYPE_Y(x) (((x) & 0x1) << 29) +#define G_SQ_TEX_WORD1_COORD_TYPE_Y(x) (((x) >> 29) & 0x1) +#define C_SQ_TEX_WORD1_COORD_TYPE_Y 0xDFFFFFFF +#define S_SQ_TEX_WORD1_COORD_TYPE_Z(x) (((x) & 0x1) << 30) +#define G_SQ_TEX_WORD1_COORD_TYPE_Z(x) (((x) >> 30) & 0x1) +#define C_SQ_TEX_WORD1_COORD_TYPE_Z 0xBFFFFFFF +#define S_SQ_TEX_WORD1_COORD_TYPE_W(x) (((x) & 0x1) << 31) +#define G_SQ_TEX_WORD1_COORD_TYPE_W(x) (((x) >> 31) & 0x1) +#define C_SQ_TEX_WORD1_COORD_TYPE_W 0x7FFFFFFF +#define P_SQ_TEX_WORD2 +#define S_SQ_TEX_WORD2_OFFSET_X(x) (((x) & 0x1F) << 0) +#define G_SQ_TEX_WORD2_OFFSET_X(x) (((x) >> 0) & 0x1F) +#define C_SQ_TEX_WORD2_OFFSET_X 0xFFFFFFE0 +#define S_SQ_TEX_WORD2_OFFSET_Y(x) (((x) & 0x1F) << 5) +#define G_SQ_TEX_WORD2_OFFSET_Y(x) (((x) >> 5) & 0x1F) +#define C_SQ_TEX_WORD2_OFFSET_Y 0xFFFFFC1F +#define S_SQ_TEX_WORD2_OFFSET_Z(x) (((x) & 0x1F) << 10) +#define G_SQ_TEX_WORD2_OFFSET_Z(x) (((x) >> 10) & 0x1F) +#define C_SQ_TEX_WORD2_OFFSET_Z 0xFFFF83FF +#define S_SQ_TEX_WORD2_SAMPLER_ID(x) (((x) & 0x1F) << 15) +#define G_SQ_TEX_WORD2_SAMPLER_ID(x) (((x) >> 15) & 0x1F) +#define C_SQ_TEX_WORD2_SAMPLER_ID 0xFFF07FFF +#define S_SQ_TEX_WORD2_SRC_SEL_X(x) (((x) & 0x7) << 20) +#define G_SQ_TEX_WORD2_SRC_SEL_X(x) (((x) >> 20) & 0x7) +#define C_SQ_TEX_WORD2_SRC_SEL_X 0xFF8FFFFF +#define S_SQ_TEX_WORD2_SRC_SEL_Y(x) (((x) & 0x7) << 23) +#define G_SQ_TEX_WORD2_SRC_SEL_Y(x) (((x) >> 23) & 0x7) +#define C_SQ_TEX_WORD2_SRC_SEL_Y 0xFC7FFFFF +#define S_SQ_TEX_WORD2_SRC_SEL_Z(x) (((x) & 0x7) << 26) +#define G_SQ_TEX_WORD2_SRC_SEL_Z(x) (((x) >> 26) & 0x7) +#define C_SQ_TEX_WORD2_SRC_SEL_Z 0xE3FFFFFF +#define S_SQ_TEX_WORD2_SRC_SEL_W(x) (((x) & 0x7) << 29) +#define G_SQ_TEX_WORD2_SRC_SEL_W(x) (((x) >> 29) & 0x7) +#define C_SQ_TEX_WORD2_SRC_SEL_W 0x1FFFFFFF + +#endif diff --git a/src/gallium/drivers/rbug/Makefile b/src/gallium/drivers/rbug/Makefile new file mode 100644 index 0000000..64e172f --- /dev/null +++ b/src/gallium/drivers/rbug/Makefile @@ -0,0 +1,12 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = rbug + +C_SOURCES = \ + rbug_core.c \ + rbug_context.c \ + rbug_objects.c \ + rbug_screen.c + +include ../../Makefile.template diff --git a/src/gallium/drivers/rbug/SConscript b/src/gallium/drivers/rbug/SConscript new file mode 100644 index 0000000..169c271 --- /dev/null +++ b/src/gallium/drivers/rbug/SConscript @@ -0,0 +1,16 @@ +Import('*') + +env = env.Clone() + +rbug = env.ConvenienceLibrary( + target = 'rbug', + source = [ + 'rbug_context.c', + 'rbug_core.c', + 'rbug_objects.c', + 'rbug_screen.c', + ]) + +env.Alias('rbug', rbug) + +Export('rbug') diff --git a/src/gallium/drivers/rbug/rbug_context.c b/src/gallium/drivers/rbug/rbug_context.c new file mode 100644 index 0000000..94e57e4 --- /dev/null +++ b/src/gallium/drivers/rbug/rbug_context.c @@ -0,0 +1,1081 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "pipe/p_context.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "util/u_simple_list.h" + +#include "rbug/rbug_context.h" + +#include "rbug_context.h" +#include "rbug_objects.h" + + +static void +rbug_destroy(struct pipe_context *_pipe) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + remove_from_list(&rb_pipe->list); + pipe->destroy(pipe); + + FREE(rb_pipe); +} + +static void +rbug_draw_block_locked(struct rbug_context *rb_pipe, int flag) +{ + + if (rb_pipe->draw_blocker & flag) { + rb_pipe->draw_blocked |= flag; + } else if ((rb_pipe->draw_rule.blocker & flag) && + (rb_pipe->draw_blocker & RBUG_BLOCK_RULE)) { + int k; + boolean block = FALSE; + debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__, + (void *) rb_pipe->draw_rule.fs, (void *) rb_pipe->curr.fs, + (void *) rb_pipe->draw_rule.vs, (void *) rb_pipe->curr.vs, + (void *) rb_pipe->draw_rule.surf, 0, + (void *) rb_pipe->draw_rule.texture, 0); + if (rb_pipe->draw_rule.fs && + rb_pipe->draw_rule.fs == rb_pipe->curr.fs) + block = TRUE; + if (rb_pipe->draw_rule.vs && + rb_pipe->draw_rule.vs == rb_pipe->curr.vs) + block = TRUE; + if (rb_pipe->draw_rule.surf && + rb_pipe->draw_rule.surf == rb_pipe->curr.zsbuf) + block = TRUE; + if (rb_pipe->draw_rule.surf) + for (k = 0; k < rb_pipe->curr.nr_cbufs; k++) + if (rb_pipe->draw_rule.surf == rb_pipe->curr.cbufs[k]) + block = TRUE; + if (rb_pipe->draw_rule.texture) { + for (k = 0; k < rb_pipe->curr.num_fs_views; k++) + if (rb_pipe->draw_rule.texture == rb_pipe->curr.fs_texs[k]) + block = TRUE; + for (k = 0; k < rb_pipe->curr.num_vs_views; k++) { + if (rb_pipe->draw_rule.texture == rb_pipe->curr.vs_texs[k]) { + block = TRUE; + } + } + } + + if (block) + rb_pipe->draw_blocked |= (flag | RBUG_BLOCK_RULE); + } + + if (rb_pipe->draw_blocked) + rbug_notify_draw_blocked(rb_pipe); + + /* wait for rbug to clear the blocked flag */ + while (rb_pipe->draw_blocked & flag) { + rb_pipe->draw_blocked |= flag; + pipe_condvar_wait(rb_pipe->draw_cond, rb_pipe->draw_mutex); + } + +} + +static void +rbug_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *info) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe_mutex_lock(rb_pipe->draw_mutex); + rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE); + + pipe->draw_vbo(pipe, info); + + rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER); + pipe_mutex_unlock(rb_pipe->draw_mutex); +} + +static struct pipe_query * +rbug_create_query(struct pipe_context *_pipe, + unsigned query_type) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + return pipe->create_query(pipe, + query_type); +} + +static void +rbug_destroy_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->destroy_query(pipe, + query); +} + +static void +rbug_begin_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->begin_query(pipe, + query); +} + +static void +rbug_end_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->end_query(pipe, + query); +} + +static boolean +rbug_get_query_result(struct pipe_context *_pipe, + struct pipe_query *query, + boolean wait, + void *result) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + return pipe->get_query_result(pipe, + query, + wait, + result); +} + +static void * +rbug_create_blend_state(struct pipe_context *_pipe, + const struct pipe_blend_state *blend) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + return pipe->create_blend_state(pipe, + blend); +} + +static void +rbug_bind_blend_state(struct pipe_context *_pipe, + void *blend) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->bind_blend_state(pipe, + blend); +} + +static void +rbug_delete_blend_state(struct pipe_context *_pipe, + void *blend) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->delete_blend_state(pipe, + blend); +} + +static void * +rbug_create_sampler_state(struct pipe_context *_pipe, + const struct pipe_sampler_state *sampler) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + return pipe->create_sampler_state(pipe, + sampler); +} + +static void +rbug_bind_fragment_sampler_states(struct pipe_context *_pipe, + unsigned num_samplers, + void **samplers) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->bind_fragment_sampler_states(pipe, + num_samplers, + samplers); +} + +static void +rbug_bind_vertex_sampler_states(struct pipe_context *_pipe, + unsigned num_samplers, + void **samplers) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->bind_vertex_sampler_states(pipe, + num_samplers, + samplers); +} + +static void +rbug_delete_sampler_state(struct pipe_context *_pipe, + void *sampler) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->delete_sampler_state(pipe, + sampler); +} + +static void * +rbug_create_rasterizer_state(struct pipe_context *_pipe, + const struct pipe_rasterizer_state *rasterizer) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + return pipe->create_rasterizer_state(pipe, + rasterizer); +} + +static void +rbug_bind_rasterizer_state(struct pipe_context *_pipe, + void *rasterizer) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->bind_rasterizer_state(pipe, + rasterizer); +} + +static void +rbug_delete_rasterizer_state(struct pipe_context *_pipe, + void *rasterizer) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->delete_rasterizer_state(pipe, + rasterizer); +} + +static void * +rbug_create_depth_stencil_alpha_state(struct pipe_context *_pipe, + const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + return pipe->create_depth_stencil_alpha_state(pipe, + depth_stencil_alpha); +} + +static void +rbug_bind_depth_stencil_alpha_state(struct pipe_context *_pipe, + void *depth_stencil_alpha) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->bind_depth_stencil_alpha_state(pipe, + depth_stencil_alpha); +} + +static void +rbug_delete_depth_stencil_alpha_state(struct pipe_context *_pipe, + void *depth_stencil_alpha) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->delete_depth_stencil_alpha_state(pipe, + depth_stencil_alpha); +} + +static void * +rbug_create_fs_state(struct pipe_context *_pipe, + const struct pipe_shader_state *state) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + void *result; + + result = pipe->create_fs_state(pipe, state); + if (!result) + return NULL; + + return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_FRAGMENT); +} + +static void +rbug_bind_fs_state(struct pipe_context *_pipe, + void *_fs) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + void *fs; + + fs = rbug_shader_unwrap(_fs); + rb_pipe->curr.fs = rbug_shader(_fs); + pipe->bind_fs_state(pipe, + fs); +} + +static void +rbug_delete_fs_state(struct pipe_context *_pipe, + void *_fs) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct rbug_shader *rb_shader = rbug_shader(_fs); + + rbug_shader_destroy(rb_pipe, rb_shader); +} + +static void * +rbug_create_vs_state(struct pipe_context *_pipe, + const struct pipe_shader_state *state) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + void *result; + + result = pipe->create_vs_state(pipe, state); + if (!result) + return NULL; + + return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_VERTEX); +} + +static void +rbug_bind_vs_state(struct pipe_context *_pipe, + void *_vs) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + void *vs; + + vs = rbug_shader_unwrap(_vs); + rb_pipe->curr.vs = rbug_shader(_vs); + pipe->bind_vs_state(pipe, + vs); +} + +static void +rbug_delete_vs_state(struct pipe_context *_pipe, + void *_vs) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct rbug_shader *rb_shader = rbug_shader(_vs); + + rbug_shader_destroy(rb_pipe, rb_shader); +} + +static void * +rbug_create_gs_state(struct pipe_context *_pipe, + const struct pipe_shader_state *state) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + void *result; + + result = pipe->create_gs_state(pipe, state); + if (!result) + return NULL; + + return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_GEOM); +} + +static void +rbug_bind_gs_state(struct pipe_context *_pipe, + void *_gs) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + void *gs; + + gs = rbug_shader_unwrap(_gs); + rb_pipe->curr.gs = rbug_shader(_gs); + pipe->bind_gs_state(pipe, + gs); +} + +static void +rbug_delete_gs_state(struct pipe_context *_pipe, + void *_gs) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct rbug_shader *rb_shader = rbug_shader(_gs); + + rbug_shader_destroy(rb_pipe, rb_shader); +} + +static void * +rbug_create_vertex_elements_state(struct pipe_context *_pipe, + unsigned num_elements, + const struct pipe_vertex_element *vertex_elements) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + return pipe->create_vertex_elements_state(pipe, + num_elements, + vertex_elements); +} + +static void +rbug_bind_vertex_elements_state(struct pipe_context *_pipe, + void *velems) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->bind_vertex_elements_state(pipe, + velems); +} + +static void +rbug_delete_vertex_elements_state(struct pipe_context *_pipe, + void *velems) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->delete_vertex_elements_state(pipe, + velems); +} + +static void +rbug_set_blend_color(struct pipe_context *_pipe, + const struct pipe_blend_color *blend_color) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->set_blend_color(pipe, + blend_color); +} + +static void +rbug_set_stencil_ref(struct pipe_context *_pipe, + const struct pipe_stencil_ref *stencil_ref) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->set_stencil_ref(pipe, + stencil_ref); +} + +static void +rbug_set_clip_state(struct pipe_context *_pipe, + const struct pipe_clip_state *clip) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->set_clip_state(pipe, + clip); +} + +static void +rbug_set_constant_buffer(struct pipe_context *_pipe, + uint shader, + uint index, + struct pipe_resource *_resource) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + struct pipe_resource *unwrapped_resource; + struct pipe_resource *resource = NULL; + + /* XXX hmm? unwrap the input state */ + if (_resource) { + unwrapped_resource = rbug_resource_unwrap(_resource); + resource = unwrapped_resource; + } + + pipe->set_constant_buffer(pipe, + shader, + index, + resource); +} + +static void +rbug_set_framebuffer_state(struct pipe_context *_pipe, + const struct pipe_framebuffer_state *_state) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + struct pipe_framebuffer_state unwrapped_state; + struct pipe_framebuffer_state *state = NULL; + unsigned i; + + rb_pipe->curr.nr_cbufs = 0; + memset(rb_pipe->curr.cbufs, 0, sizeof(rb_pipe->curr.cbufs)); + + /* unwrap the input state */ + if (_state) { + memcpy(&unwrapped_state, _state, sizeof(unwrapped_state)); + + rb_pipe->curr.nr_cbufs = _state->nr_cbufs; + for(i = 0; i < _state->nr_cbufs; i++) { + unwrapped_state.cbufs[i] = rbug_surface_unwrap(_state->cbufs[i]); + if (_state->cbufs[i]) + rb_pipe->curr.cbufs[i] = rbug_resource(_state->cbufs[i]->texture); + } + unwrapped_state.zsbuf = rbug_surface_unwrap(_state->zsbuf); + state = &unwrapped_state; + } + + pipe->set_framebuffer_state(pipe, + state); +} + +static void +rbug_set_polygon_stipple(struct pipe_context *_pipe, + const struct pipe_poly_stipple *poly_stipple) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->set_polygon_stipple(pipe, + poly_stipple); +} + +static void +rbug_set_scissor_state(struct pipe_context *_pipe, + const struct pipe_scissor_state *scissor) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->set_scissor_state(pipe, + scissor); +} + +static void +rbug_set_viewport_state(struct pipe_context *_pipe, + const struct pipe_viewport_state *viewport) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->set_viewport_state(pipe, + viewport); +} + +static void +rbug_set_fragment_sampler_views(struct pipe_context *_pipe, + unsigned num, + struct pipe_sampler_view **_views) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view **views = NULL; + unsigned i; + + rb_pipe->curr.num_fs_views = 0; + memset(rb_pipe->curr.fs_views, 0, sizeof(rb_pipe->curr.fs_views)); + memset(rb_pipe->curr.fs_texs, 0, sizeof(rb_pipe->curr.fs_texs)); + memset(unwrapped_views, 0, sizeof(unwrapped_views)); + + if (_views) { + rb_pipe->curr.num_fs_views = num; + for (i = 0; i < num; i++) { + rb_pipe->curr.fs_views[i] = rbug_sampler_view(_views[i]); + rb_pipe->curr.fs_texs[i] = rbug_resource(_views[i] ? _views[i]->texture : NULL); + unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]); + } + views = unwrapped_views; + } + + pipe->set_fragment_sampler_views(pipe, num, views); +} + +static void +rbug_set_vertex_sampler_views(struct pipe_context *_pipe, + unsigned num, + struct pipe_sampler_view **_views) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + struct pipe_sampler_view *unwrapped_views[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_sampler_view **views = NULL; + unsigned i; + + rb_pipe->curr.num_vs_views = 0; + memset(rb_pipe->curr.vs_views, 0, sizeof(rb_pipe->curr.vs_views)); + memset(rb_pipe->curr.vs_texs, 0, sizeof(rb_pipe->curr.vs_texs)); + memset(unwrapped_views, 0, sizeof(unwrapped_views)); + + if (_views) { + rb_pipe->curr.num_vs_views = num; + for (i = 0; i < num; i++) { + rb_pipe->curr.vs_views[i] = rbug_sampler_view(_views[i]); + rb_pipe->curr.vs_texs[i] = rbug_resource(_views[i]->texture); + unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]); + } + views = unwrapped_views; + } + + pipe->set_vertex_sampler_views(pipe, num, views); +} + +static void +rbug_set_vertex_buffers(struct pipe_context *_pipe, + unsigned num_buffers, + const struct pipe_vertex_buffer *_buffers) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS]; + struct pipe_vertex_buffer *buffers = NULL; + unsigned i; + + if (num_buffers) { + memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers)); + for (i = 0; i < num_buffers; i++) + unwrapped_buffers[i].buffer = rbug_resource_unwrap(_buffers[i].buffer); + buffers = unwrapped_buffers; + } + + pipe->set_vertex_buffers(pipe, + num_buffers, + buffers); +} + +static void +rbug_set_index_buffer(struct pipe_context *_pipe, + const struct pipe_index_buffer *_ib) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + struct pipe_index_buffer unwrapped_ib, *ib = NULL; + + if (_ib) { + unwrapped_ib = *_ib; + unwrapped_ib.buffer = rbug_resource_unwrap(_ib->buffer); + ib = &unwrapped_ib; + } + + pipe->set_index_buffer(pipe, ib); +} + +static void +rbug_set_sample_mask(struct pipe_context *_pipe, + unsigned sample_mask) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->set_sample_mask(pipe, sample_mask); +} + +static void +rbug_resource_copy_region(struct pipe_context *_pipe, + struct pipe_resource *_dst, + unsigned dst_level, + unsigned dstx, + unsigned dsty, + unsigned dstz, + struct pipe_resource *_src, + unsigned src_level, + const struct pipe_box *src_box) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct rbug_resource *rb_resource_dst = rbug_resource(_dst); + struct rbug_resource *rb_resource_src = rbug_resource(_src); + struct pipe_context *pipe = rb_pipe->pipe; + struct pipe_resource *dst = rb_resource_dst->resource; + struct pipe_resource *src = rb_resource_src->resource; + + pipe->resource_copy_region(pipe, + dst, + dst_level, + dstx, + dsty, + dstz, + src, + src_level, + src_box); +} + +static void +rbug_clear(struct pipe_context *_pipe, + unsigned buffers, + const float *rgba, + double depth, + unsigned stencil) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->clear(pipe, + buffers, + rgba, + depth, + stencil); +} + +static void +rbug_clear_render_target(struct pipe_context *_pipe, + struct pipe_surface *_dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct rbug_surface *rb_surface_dst = rbug_surface(_dst); + struct pipe_context *pipe = rb_pipe->pipe; + struct pipe_surface *dst = rb_surface_dst->surface; + + pipe->clear_render_target(pipe, + dst, + rgba, + dstx, + dsty, + width, + height); +} + +static void +rbug_clear_depth_stencil(struct pipe_context *_pipe, + struct pipe_surface *_dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct rbug_surface *rb_surface_dst = rbug_surface(_dst); + struct pipe_context *pipe = rb_pipe->pipe; + struct pipe_surface *dst = rb_surface_dst->surface; + + pipe->clear_depth_stencil(pipe, + dst, + clear_flags, + depth, + stencil, + dstx, + dsty, + width, + height); +} + +static void +rbug_flush(struct pipe_context *_pipe, + unsigned flags, + struct pipe_fence_handle **fence) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct pipe_context *pipe = rb_pipe->pipe; + + pipe->flush(pipe, + flags, + fence); +} + +static unsigned int +rbug_is_resource_referenced(struct pipe_context *_pipe, + struct pipe_resource *_resource, + unsigned level, + int layer) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct rbug_resource *rb_resource = rbug_resource(_resource); + struct pipe_context *pipe = rb_pipe->pipe; + struct pipe_resource *resource = rb_resource->resource; + + return pipe->is_resource_referenced(pipe, + resource, + level, + layer); +} + +static struct pipe_sampler_view * +rbug_context_create_sampler_view(struct pipe_context *_pipe, + struct pipe_resource *_resource, + const struct pipe_sampler_view *templ) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct rbug_resource *rb_resource = rbug_resource(_resource); + struct pipe_context *pipe = rb_pipe->pipe; + struct pipe_resource *resource = rb_resource->resource; + struct pipe_sampler_view *result; + + result = pipe->create_sampler_view(pipe, + resource, + templ); + + if (result) + return rbug_sampler_view_create(rb_pipe, rb_resource, result); + return NULL; +} + +static void +rbug_context_sampler_view_destroy(struct pipe_context *_pipe, + struct pipe_sampler_view *_view) +{ + rbug_sampler_view_destroy(rbug_context(_pipe), + rbug_sampler_view(_view)); +} + +static struct pipe_surface * +rbug_context_create_surface(struct pipe_context *_pipe, + struct pipe_resource *_resource, + const struct pipe_surface *surf_tmpl) +{ + struct rbug_context *rb_pipe = rbug_context(_pipe); + struct rbug_resource *rb_resource = rbug_resource(_resource); + struct pipe_context *pipe = rb_pipe->pipe; + struct pipe_resource *resource = rb_resource->resource; + struct pipe_surface *result; + + result = pipe->create_surface(pipe, + resource, + surf_tmpl); + + if (result) + return rbug_surface_create(rb_pipe, rb_resource, result); + return NULL; +} + +static void +rbug_context_surface_destroy(struct pipe_context *_pipe, + struct pipe_surface *_surface) +{ + rbug_surface_destroy(rbug_context(_pipe), + rbug_surface(_surface)); +} + + + +static struct pipe_transfer * +rbug_context_get_transfer(struct pipe_context *_context, + struct pipe_resource *_resource, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct rbug_context *rb_pipe = rbug_context(_context); + struct rbug_resource *rb_resource = rbug_resource(_resource); + struct pipe_context *context = rb_pipe->pipe; + struct pipe_resource *resource = rb_resource->resource; + struct pipe_transfer *result; + + result = context->get_transfer(context, + resource, + level, + usage, + box); + + if (result) + return rbug_transfer_create(rb_pipe, rb_resource, result); + return NULL; +} + +static void +rbug_context_transfer_destroy(struct pipe_context *_pipe, + struct pipe_transfer *_transfer) +{ + rbug_transfer_destroy(rbug_context(_pipe), + rbug_transfer(_transfer)); +} + +static void * +rbug_context_transfer_map(struct pipe_context *_context, + struct pipe_transfer *_transfer) +{ + struct rbug_context *rb_pipe = rbug_context(_context); + struct rbug_transfer *rb_transfer = rbug_transfer(_transfer); + struct pipe_context *context = rb_pipe->pipe; + struct pipe_transfer *transfer = rb_transfer->transfer; + + return context->transfer_map(context, + transfer); +} + + + +static void +rbug_context_transfer_flush_region(struct pipe_context *_context, + struct pipe_transfer *_transfer, + const struct pipe_box *box) +{ + struct rbug_context *rb_pipe = rbug_context(_context); + struct rbug_transfer *rb_transfer = rbug_transfer(_transfer); + struct pipe_context *context = rb_pipe->pipe; + struct pipe_transfer *transfer = rb_transfer->transfer; + + context->transfer_flush_region(context, + transfer, + box); +} + + +static void +rbug_context_transfer_unmap(struct pipe_context *_context, + struct pipe_transfer *_transfer) +{ + struct rbug_context *rb_pipe = rbug_context(_context); + struct rbug_transfer *rb_transfer = rbug_transfer(_transfer); + struct pipe_context *context = rb_pipe->pipe; + struct pipe_transfer *transfer = rb_transfer->transfer; + + context->transfer_unmap(context, + transfer); +} + + +static void +rbug_context_transfer_inline_write(struct pipe_context *_context, + struct pipe_resource *_resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride) +{ + struct rbug_context *rb_pipe = rbug_context(_context); + struct rbug_resource *rb_resource = rbug_resource(_resource); + struct pipe_context *context = rb_pipe->pipe; + struct pipe_resource *resource = rb_resource->resource; + + context->transfer_inline_write(context, + resource, + level, + usage, + box, + data, + stride, + layer_stride); +} + + +struct pipe_context * +rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe) +{ + struct rbug_context *rb_pipe; + struct rbug_screen *rb_screen = rbug_screen(_screen); + + if (!rb_screen) + return NULL; + + rb_pipe = CALLOC_STRUCT(rbug_context); + if (!rb_pipe) + return NULL; + + pipe_mutex_init(rb_pipe->draw_mutex); + pipe_condvar_init(rb_pipe->draw_cond); + pipe_mutex_init(rb_pipe->call_mutex); + pipe_mutex_init(rb_pipe->list_mutex); + make_empty_list(&rb_pipe->shaders); + + rb_pipe->base.winsys = NULL; + rb_pipe->base.screen = _screen; + rb_pipe->base.priv = pipe->priv; /* expose wrapped data */ + rb_pipe->base.draw = NULL; + + rb_pipe->base.destroy = rbug_destroy; + rb_pipe->base.draw_vbo = rbug_draw_vbo; + rb_pipe->base.create_query = rbug_create_query; + rb_pipe->base.destroy_query = rbug_destroy_query; + rb_pipe->base.begin_query = rbug_begin_query; + rb_pipe->base.end_query = rbug_end_query; + rb_pipe->base.get_query_result = rbug_get_query_result; + rb_pipe->base.create_blend_state = rbug_create_blend_state; + rb_pipe->base.bind_blend_state = rbug_bind_blend_state; + rb_pipe->base.delete_blend_state = rbug_delete_blend_state; + rb_pipe->base.create_sampler_state = rbug_create_sampler_state; + rb_pipe->base.bind_fragment_sampler_states = rbug_bind_fragment_sampler_states; + rb_pipe->base.bind_vertex_sampler_states = rbug_bind_vertex_sampler_states; + rb_pipe->base.delete_sampler_state = rbug_delete_sampler_state; + rb_pipe->base.create_rasterizer_state = rbug_create_rasterizer_state; + rb_pipe->base.bind_rasterizer_state = rbug_bind_rasterizer_state; + rb_pipe->base.delete_rasterizer_state = rbug_delete_rasterizer_state; + rb_pipe->base.create_depth_stencil_alpha_state = rbug_create_depth_stencil_alpha_state; + rb_pipe->base.bind_depth_stencil_alpha_state = rbug_bind_depth_stencil_alpha_state; + rb_pipe->base.delete_depth_stencil_alpha_state = rbug_delete_depth_stencil_alpha_state; + rb_pipe->base.create_fs_state = rbug_create_fs_state; + rb_pipe->base.bind_fs_state = rbug_bind_fs_state; + rb_pipe->base.delete_fs_state = rbug_delete_fs_state; + rb_pipe->base.create_vs_state = rbug_create_vs_state; + rb_pipe->base.bind_vs_state = rbug_bind_vs_state; + rb_pipe->base.delete_vs_state = rbug_delete_vs_state; + rb_pipe->base.create_gs_state = rbug_create_gs_state; + rb_pipe->base.bind_gs_state = rbug_bind_gs_state; + rb_pipe->base.delete_gs_state = rbug_delete_gs_state; + rb_pipe->base.create_vertex_elements_state = rbug_create_vertex_elements_state; + rb_pipe->base.bind_vertex_elements_state = rbug_bind_vertex_elements_state; + rb_pipe->base.delete_vertex_elements_state = rbug_delete_vertex_elements_state; + rb_pipe->base.set_blend_color = rbug_set_blend_color; + rb_pipe->base.set_stencil_ref = rbug_set_stencil_ref; + rb_pipe->base.set_clip_state = rbug_set_clip_state; + rb_pipe->base.set_constant_buffer = rbug_set_constant_buffer; + rb_pipe->base.set_framebuffer_state = rbug_set_framebuffer_state; + rb_pipe->base.set_polygon_stipple = rbug_set_polygon_stipple; + rb_pipe->base.set_scissor_state = rbug_set_scissor_state; + rb_pipe->base.set_viewport_state = rbug_set_viewport_state; + rb_pipe->base.set_fragment_sampler_views = rbug_set_fragment_sampler_views; + rb_pipe->base.set_vertex_sampler_views = rbug_set_vertex_sampler_views; + rb_pipe->base.set_vertex_buffers = rbug_set_vertex_buffers; + rb_pipe->base.set_index_buffer = rbug_set_index_buffer; + rb_pipe->base.set_sample_mask = rbug_set_sample_mask; + rb_pipe->base.resource_copy_region = rbug_resource_copy_region; + rb_pipe->base.clear = rbug_clear; + rb_pipe->base.clear_render_target = rbug_clear_render_target; + rb_pipe->base.clear_depth_stencil = rbug_clear_depth_stencil; + rb_pipe->base.flush = rbug_flush; + rb_pipe->base.is_resource_referenced = rbug_is_resource_referenced; + rb_pipe->base.create_sampler_view = rbug_context_create_sampler_view; + rb_pipe->base.sampler_view_destroy = rbug_context_sampler_view_destroy; + rb_pipe->base.create_surface = rbug_context_create_surface; + rb_pipe->base.surface_destroy = rbug_context_surface_destroy; + rb_pipe->base.get_transfer = rbug_context_get_transfer; + rb_pipe->base.transfer_destroy = rbug_context_transfer_destroy; + rb_pipe->base.transfer_map = rbug_context_transfer_map; + rb_pipe->base.transfer_unmap = rbug_context_transfer_unmap; + rb_pipe->base.transfer_flush_region = rbug_context_transfer_flush_region; + rb_pipe->base.transfer_inline_write = rbug_context_transfer_inline_write; + + rb_pipe->pipe = pipe; + + rbug_screen_add_to_list(rb_screen, contexts, rb_pipe); + + return &rb_pipe->base; +} diff --git a/src/gallium/drivers/rbug/rbug_context.h b/src/gallium/drivers/rbug/rbug_context.h new file mode 100644 index 0000000..80c803d --- /dev/null +++ b/src/gallium/drivers/rbug/rbug_context.h @@ -0,0 +1,111 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef RBUG_CONTEXT_H +#define RBUG_CONTEXT_H + +#include "pipe/p_state.h" +#include "pipe/p_context.h" + +#include "rbug_screen.h" + + +struct rbug_context { + struct pipe_context base; /**< base class */ + + struct pipe_context *pipe; + + struct rbug_list list; + + /* call locking */ + pipe_mutex call_mutex; + + /* current state */ + struct { + struct rbug_shader *fs; + struct rbug_shader *vs; + struct rbug_shader *gs; + + struct rbug_sampler_view *fs_views[PIPE_MAX_SAMPLERS]; + struct rbug_resource *fs_texs[PIPE_MAX_SAMPLERS]; + unsigned num_fs_views; + + struct rbug_sampler_view *vs_views[PIPE_MAX_VERTEX_SAMPLERS]; + struct rbug_resource *vs_texs[PIPE_MAX_VERTEX_SAMPLERS]; + unsigned num_vs_views; + + unsigned nr_cbufs; + struct rbug_resource *cbufs[PIPE_MAX_COLOR_BUFS]; + struct rbug_resource *zsbuf; + } curr; + + /* draw locking */ + pipe_mutex draw_mutex; + pipe_condvar draw_cond; + unsigned draw_num_rules; + int draw_blocker; + int draw_blocked; + + struct { + struct rbug_shader *fs; + struct rbug_shader *vs; + + struct rbug_resource *texture; + struct rbug_resource *surf; + + int blocker; + } draw_rule; + + /* list of state objects */ + pipe_mutex list_mutex; + unsigned num_shaders; + struct rbug_list shaders; +}; + +static INLINE struct rbug_context * +rbug_context(struct pipe_context *pipe) +{ + return (struct rbug_context *)pipe; +} + + +/********************************************************** + * rbug_context.c + */ + +struct pipe_context * +rbug_context_create(struct pipe_screen *screen, struct pipe_context *pipe); + + +/********************************************************** + * rbug_core.c + */ + +void rbug_notify_draw_blocked(struct rbug_context *rb_context); + + +#endif /* RBUG_CONTEXT_H */ diff --git a/src/gallium/drivers/rbug/rbug_core.c b/src/gallium/drivers/rbug/rbug_core.c new file mode 100644 index 0000000..eb772d1 --- /dev/null +++ b/src/gallium/drivers/rbug/rbug_core.c @@ -0,0 +1,884 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "os/os_thread.h" +#include "util/u_format.h" +#include "util/u_string.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_simple_list.h" +#include "util/u_network.h" +#include "os/os_time.h" + +#include "tgsi/tgsi_parse.h" + +#include "rbug_context.h" +#include "rbug_objects.h" + +#include "rbug/rbug.h" + +#include + +#define U642VOID(x) ((void *)(unsigned long)(x)) +#define VOID2U64(x) ((uint64_t)(unsigned long)(x)) + +#define container_of(ptr, type, field) \ + (type*)((char*)ptr - offsetof(type, field)) + +struct rbug_rbug +{ + struct rbug_screen *rb_screen; + struct rbug_connection *con; + pipe_thread thread; + boolean running; +}; + +PIPE_THREAD_ROUTINE(rbug_thread, void_rbug); + + +/********************************************************** + * Helper functions + */ + + +static struct rbug_context * +rbug_get_context_locked(struct rbug_screen *rb_screen, rbug_context_t ctx) +{ + struct rbug_context *rb_context = NULL; + struct rbug_list *ptr; + + foreach(ptr, &rb_screen->contexts) { + rb_context = container_of(ptr, struct rbug_context, list); + if (ctx == VOID2U64(rb_context)) + break; + rb_context = NULL; + } + + return rb_context; +} + +static struct rbug_shader * +rbug_get_shader_locked(struct rbug_context *rb_context, rbug_shader_t shdr) +{ + struct rbug_shader *tr_shdr = NULL; + struct rbug_list *ptr; + + foreach(ptr, &rb_context->shaders) { + tr_shdr = container_of(ptr, struct rbug_shader, list); + if (shdr == VOID2U64(tr_shdr)) + break; + tr_shdr = NULL; + } + + return tr_shdr; +} + +static void * +rbug_shader_create_locked(struct pipe_context *pipe, + struct rbug_shader *rb_shader, + struct tgsi_token *tokens) +{ + void *state = NULL; + struct pipe_shader_state pss = { 0 }; + pss.tokens = tokens; + + switch(rb_shader->type) { + case RBUG_SHADER_FRAGMENT: + state = pipe->create_fs_state(pipe, &pss); + break; + case RBUG_SHADER_VERTEX: + state = pipe->create_vs_state(pipe, &pss); + break; + case RBUG_SHADER_GEOM: + state = pipe->create_gs_state(pipe, &pss); + break; + default: + assert(0); + break; + } + + return state; +} + +static void +rbug_shader_bind_locked(struct pipe_context *pipe, + struct rbug_shader *rb_shader, + void *state) +{ + switch(rb_shader->type) { + case RBUG_SHADER_FRAGMENT: + pipe->bind_fs_state(pipe, state); + break; + case RBUG_SHADER_VERTEX: + pipe->bind_vs_state(pipe, state); + break; + case RBUG_SHADER_GEOM: + pipe->bind_gs_state(pipe, state); + break; + default: + assert(0); + break; + } +} + +static void +rbug_shader_delete_locked(struct pipe_context *pipe, + struct rbug_shader *rb_shader, + void *state) +{ + switch(rb_shader->type) { + case RBUG_SHADER_FRAGMENT: + pipe->delete_fs_state(pipe, state); + break; + case RBUG_SHADER_VERTEX: + pipe->delete_vs_state(pipe, state); + break; + case RBUG_SHADER_GEOM: + pipe->delete_gs_state(pipe, state); + break; + default: + assert(0); + break; + } +} + +/************************************************ + * Request handler functions + */ + + +static int +rbug_texture_list(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) +{ + struct rbug_screen *rb_screen = tr_rbug->rb_screen; + struct rbug_resource *tr_tex = NULL; + struct rbug_list *ptr; + rbug_texture_t *texs; + int i = 0; + + pipe_mutex_lock(rb_screen->list_mutex); + texs = MALLOC(rb_screen->num_resources * sizeof(rbug_texture_t)); + foreach(ptr, &rb_screen->resources) { + tr_tex = container_of(ptr, struct rbug_resource, list); + texs[i++] = VOID2U64(tr_tex); + } + pipe_mutex_unlock(rb_screen->list_mutex); + + rbug_send_texture_list_reply(tr_rbug->con, serial, texs, i, NULL); + FREE(texs); + + return 0; +} + +static int +rbug_texture_info(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) +{ + struct rbug_screen *rb_screen = tr_rbug->rb_screen; + struct rbug_resource *tr_tex = NULL; + struct rbug_proto_texture_info *gpti = (struct rbug_proto_texture_info *)header; + struct rbug_list *ptr; + struct pipe_resource *t; + + pipe_mutex_lock(rb_screen->list_mutex); + foreach(ptr, &rb_screen->resources) { + tr_tex = container_of(ptr, struct rbug_resource, list); + if (gpti->texture == VOID2U64(tr_tex)) + break; + tr_tex = NULL; + } + + if (!tr_tex) { + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + t = tr_tex->resource; + rbug_send_texture_info_reply(tr_rbug->con, serial, + t->target, t->format, + &t->width0, 1, + &t->height0, 1, + &t->depth0, 1, + util_format_get_blockwidth(t->format), + util_format_get_blockheight(t->format), + util_format_get_blocksize(t->format), + t->last_level, + t->nr_samples, + t->bind, + NULL); + + pipe_mutex_unlock(rb_screen->list_mutex); + + return 0; +} + +static int +rbug_texture_read(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) +{ + struct rbug_proto_texture_read *gptr = (struct rbug_proto_texture_read *)header; + + struct rbug_screen *rb_screen = tr_rbug->rb_screen; + struct rbug_resource *tr_tex = NULL; + struct rbug_list *ptr; + + struct pipe_context *context = rb_screen->private_context; + struct pipe_resource *tex; + struct pipe_transfer *t; + + void *map; + + pipe_mutex_lock(rb_screen->list_mutex); + foreach(ptr, &rb_screen->resources) { + tr_tex = container_of(ptr, struct rbug_resource, list); + if (gptr->texture == VOID2U64(tr_tex)) + break; + tr_tex = NULL; + } + + if (!tr_tex) { + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + tex = tr_tex->resource; + t = pipe_get_transfer(context, tex, + gptr->level, gptr->face + gptr->zslice, + PIPE_TRANSFER_READ, + gptr->x, gptr->y, gptr->w, gptr->h); + + map = context->transfer_map(context, t); + + rbug_send_texture_read_reply(tr_rbug->con, serial, + t->resource->format, + util_format_get_blockwidth(t->resource->format), + util_format_get_blockheight(t->resource->format), + util_format_get_blocksize(t->resource->format), + (uint8_t*)map, + t->stride * util_format_get_nblocksy(t->resource->format, + t->box.height), + t->stride, + NULL); + + context->transfer_unmap(context, t); + context->transfer_destroy(context, t); + + pipe_mutex_unlock(rb_screen->list_mutex); + + return 0; +} + +static int +rbug_context_list(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) +{ + struct rbug_screen *rb_screen = tr_rbug->rb_screen; + struct rbug_list *ptr; + struct rbug_context *rb_context = NULL; + rbug_context_t *ctxs; + int i = 0; + + pipe_mutex_lock(rb_screen->list_mutex); + ctxs = MALLOC(rb_screen->num_contexts * sizeof(rbug_context_t)); + foreach(ptr, &rb_screen->contexts) { + rb_context = container_of(ptr, struct rbug_context, list); + ctxs[i++] = VOID2U64(rb_context); + } + pipe_mutex_unlock(rb_screen->list_mutex); + + rbug_send_context_list_reply(tr_rbug->con, serial, ctxs, i, NULL); + FREE(ctxs); + + return 0; +} + +static int +rbug_context_info(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) +{ + struct rbug_proto_context_info *info = (struct rbug_proto_context_info *)header; + + struct rbug_screen *rb_screen = tr_rbug->rb_screen; + struct rbug_context *rb_context = NULL; + rbug_texture_t cbufs[PIPE_MAX_COLOR_BUFS]; + rbug_texture_t texs[PIPE_MAX_SAMPLERS]; + int i; + + pipe_mutex_lock(rb_screen->list_mutex); + rb_context = rbug_get_context_locked(rb_screen, info->context); + + if (!rb_context) { + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + /* protect the pipe context */ + pipe_mutex_lock(rb_context->draw_mutex); + pipe_mutex_lock(rb_context->call_mutex); + + for (i = 0; i < rb_context->curr.nr_cbufs; i++) + cbufs[i] = VOID2U64(rb_context->curr.cbufs[i]); + + for (i = 0; i < rb_context->curr.num_fs_views; i++) + texs[i] = VOID2U64(rb_context->curr.fs_texs[i]); + + rbug_send_context_info_reply(tr_rbug->con, serial, + VOID2U64(rb_context->curr.vs), VOID2U64(rb_context->curr.fs), + texs, rb_context->curr.num_fs_views, + cbufs, rb_context->curr.nr_cbufs, + VOID2U64(rb_context->curr.zsbuf), + rb_context->draw_blocker, rb_context->draw_blocked, NULL); + + pipe_mutex_unlock(rb_context->call_mutex); + pipe_mutex_unlock(rb_context->draw_mutex); + pipe_mutex_unlock(rb_screen->list_mutex); + + return 0; +} + +static int +rbug_context_draw_block(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) +{ + struct rbug_proto_context_draw_block *block = (struct rbug_proto_context_draw_block *)header; + + struct rbug_screen *rb_screen = tr_rbug->rb_screen; + struct rbug_context *rb_context = NULL; + + pipe_mutex_lock(rb_screen->list_mutex); + rb_context = rbug_get_context_locked(rb_screen, block->context); + + if (!rb_context) { + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + pipe_mutex_lock(rb_context->draw_mutex); + rb_context->draw_blocker |= block->block; + pipe_mutex_unlock(rb_context->draw_mutex); + + pipe_mutex_unlock(rb_screen->list_mutex); + + return 0; +} + +static int +rbug_context_draw_step(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) +{ + struct rbug_proto_context_draw_step *step = (struct rbug_proto_context_draw_step *)header; + + struct rbug_screen *rb_screen = tr_rbug->rb_screen; + struct rbug_context *rb_context = NULL; + + pipe_mutex_lock(rb_screen->list_mutex); + rb_context = rbug_get_context_locked(rb_screen, step->context); + + if (!rb_context) { + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + pipe_mutex_lock(rb_context->draw_mutex); + if (rb_context->draw_blocked & RBUG_BLOCK_RULE) { + if (step->step & RBUG_BLOCK_RULE) + rb_context->draw_blocked &= ~RBUG_BLOCK_MASK; + } else { + rb_context->draw_blocked &= ~step->step; + } + pipe_mutex_unlock(rb_context->draw_mutex); + + pipe_condvar_broadcast(rb_context->draw_cond); + + pipe_mutex_unlock(rb_screen->list_mutex); + + return 0; +} + +static int +rbug_context_draw_unblock(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) +{ + struct rbug_proto_context_draw_unblock *unblock = (struct rbug_proto_context_draw_unblock *)header; + + struct rbug_screen *rb_screen = tr_rbug->rb_screen; + struct rbug_context *rb_context = NULL; + + pipe_mutex_lock(rb_screen->list_mutex); + rb_context = rbug_get_context_locked(rb_screen, unblock->context); + + if (!rb_context) { + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + pipe_mutex_lock(rb_context->draw_mutex); + if (rb_context->draw_blocked & RBUG_BLOCK_RULE) { + if (unblock->unblock & RBUG_BLOCK_RULE) + rb_context->draw_blocked &= ~RBUG_BLOCK_MASK; + } else { + rb_context->draw_blocked &= ~unblock->unblock; + } + rb_context->draw_blocker &= ~unblock->unblock; + pipe_mutex_unlock(rb_context->draw_mutex); + + pipe_condvar_broadcast(rb_context->draw_cond); + + pipe_mutex_unlock(rb_screen->list_mutex); + + return 0; +} + +static int +rbug_context_draw_rule(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) +{ + struct rbug_proto_context_draw_rule *rule = (struct rbug_proto_context_draw_rule *)header; + + struct rbug_screen *rb_screen = tr_rbug->rb_screen; + struct rbug_context *rb_context = NULL; + + pipe_mutex_lock(rb_screen->list_mutex); + rb_context = rbug_get_context_locked(rb_screen, rule->context); + + if (!rb_context) { + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + pipe_mutex_lock(rb_context->draw_mutex); + rb_context->draw_rule.vs = U642VOID(rule->vertex); + rb_context->draw_rule.fs = U642VOID(rule->fragment); + rb_context->draw_rule.texture = U642VOID(rule->texture); + rb_context->draw_rule.surf = U642VOID(rule->surface); + rb_context->draw_rule.blocker = rule->block; + rb_context->draw_blocker |= RBUG_BLOCK_RULE; + pipe_mutex_unlock(rb_context->draw_mutex); + + pipe_condvar_broadcast(rb_context->draw_cond); + + pipe_mutex_unlock(rb_screen->list_mutex); + + return 0; +} + +static int +rbug_context_flush(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) +{ + struct rbug_proto_context_flush *flush = (struct rbug_proto_context_flush *)header; + + struct rbug_screen *rb_screen = tr_rbug->rb_screen; + struct rbug_context *rb_context = NULL; + + pipe_mutex_lock(rb_screen->list_mutex); + rb_context = rbug_get_context_locked(rb_screen, flush->context); + + if (!rb_context) { + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + /* protect the pipe context */ + pipe_mutex_lock(rb_context->call_mutex); + + rb_context->pipe->flush(rb_context->pipe, flush->flags, NULL); + + pipe_mutex_unlock(rb_context->call_mutex); + pipe_mutex_unlock(rb_screen->list_mutex); + + return 0; +} + +static int +rbug_shader_list(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) +{ + struct rbug_proto_shader_list *list = (struct rbug_proto_shader_list *)header; + + struct rbug_screen *rb_screen = tr_rbug->rb_screen; + struct rbug_context *rb_context = NULL; + struct rbug_shader *tr_shdr = NULL; + struct rbug_list *ptr; + rbug_shader_t *shdrs; + int i = 0; + + pipe_mutex_lock(rb_screen->list_mutex); + rb_context = rbug_get_context_locked(rb_screen, list->context); + + if (!rb_context) { + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + pipe_mutex_lock(rb_context->list_mutex); + shdrs = MALLOC(rb_context->num_shaders * sizeof(rbug_shader_t)); + foreach(ptr, &rb_context->shaders) { + tr_shdr = container_of(ptr, struct rbug_shader, list); + shdrs[i++] = VOID2U64(tr_shdr); + } + + pipe_mutex_unlock(rb_context->list_mutex); + pipe_mutex_unlock(rb_screen->list_mutex); + + rbug_send_shader_list_reply(tr_rbug->con, serial, shdrs, i, NULL); + FREE(shdrs); + + return 0; +} + +static int +rbug_shader_info(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) +{ + struct rbug_proto_shader_info *info = (struct rbug_proto_shader_info *)header; + + struct rbug_screen *rb_screen = tr_rbug->rb_screen; + struct rbug_context *rb_context = NULL; + struct rbug_shader *tr_shdr = NULL; + unsigned original_len; + unsigned replaced_len; + + pipe_mutex_lock(rb_screen->list_mutex); + rb_context = rbug_get_context_locked(rb_screen, info->context); + + if (!rb_context) { + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + pipe_mutex_lock(rb_context->list_mutex); + + tr_shdr = rbug_get_shader_locked(rb_context, info->shader); + + if (!tr_shdr) { + pipe_mutex_unlock(rb_context->list_mutex); + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + /* just in case */ + assert(sizeof(struct tgsi_token) == 4); + + original_len = tgsi_num_tokens(tr_shdr->tokens); + if (tr_shdr->replaced_tokens) + replaced_len = tgsi_num_tokens(tr_shdr->replaced_tokens); + else + replaced_len = 0; + + rbug_send_shader_info_reply(tr_rbug->con, serial, + (uint32_t*)tr_shdr->tokens, original_len, + (uint32_t*)tr_shdr->replaced_tokens, replaced_len, + tr_shdr->disabled, + NULL); + + pipe_mutex_unlock(rb_context->list_mutex); + pipe_mutex_unlock(rb_screen->list_mutex); + + return 0; +} + +static int +rbug_shader_disable(struct rbug_rbug *tr_rbug, struct rbug_header *header) +{ + struct rbug_proto_shader_disable *dis = (struct rbug_proto_shader_disable *)header; + + struct rbug_screen *rb_screen = tr_rbug->rb_screen; + struct rbug_context *rb_context = NULL; + struct rbug_shader *tr_shdr = NULL; + + pipe_mutex_lock(rb_screen->list_mutex); + rb_context = rbug_get_context_locked(rb_screen, dis->context); + + if (!rb_context) { + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + pipe_mutex_lock(rb_context->list_mutex); + + tr_shdr = rbug_get_shader_locked(rb_context, dis->shader); + + if (!tr_shdr) { + pipe_mutex_unlock(rb_context->list_mutex); + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + tr_shdr->disabled = dis->disable; + + pipe_mutex_unlock(rb_context->list_mutex); + pipe_mutex_unlock(rb_screen->list_mutex); + + return 0; +} + +static int +rbug_shader_replace(struct rbug_rbug *tr_rbug, struct rbug_header *header) +{ + struct rbug_proto_shader_replace *rep = (struct rbug_proto_shader_replace *)header; + + struct rbug_screen *rb_screen = tr_rbug->rb_screen; + struct rbug_context *rb_context = NULL; + struct rbug_shader *tr_shdr = NULL; + struct pipe_context *pipe = NULL; + void *state; + + pipe_mutex_lock(rb_screen->list_mutex); + rb_context = rbug_get_context_locked(rb_screen, rep->context); + + if (!rb_context) { + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + pipe_mutex_lock(rb_context->list_mutex); + + tr_shdr = rbug_get_shader_locked(rb_context, rep->shader); + + if (!tr_shdr) { + pipe_mutex_unlock(rb_context->list_mutex); + pipe_mutex_unlock(rb_screen->list_mutex); + return -ESRCH; + } + + /* protect the pipe context */ + pipe_mutex_lock(rb_context->call_mutex); + + pipe = rb_context->pipe; + + /* remove old replaced shader */ + if (tr_shdr->replaced_shader) { + /* if this shader is bound rebind the original shader */ + if (rb_context->curr.fs == tr_shdr || rb_context->curr.vs == tr_shdr) + rbug_shader_bind_locked(pipe, tr_shdr, tr_shdr->shader); + + FREE(tr_shdr->replaced_tokens); + rbug_shader_delete_locked(pipe, tr_shdr, tr_shdr->replaced_shader); + tr_shdr->replaced_shader = NULL; + tr_shdr->replaced_tokens = NULL; + } + + /* empty inputs means restore old which we did above */ + if (rep->tokens_len == 0) + goto out; + + tr_shdr->replaced_tokens = tgsi_dup_tokens((struct tgsi_token *)rep->tokens); + if (!tr_shdr->replaced_tokens) + goto err; + + state = rbug_shader_create_locked(pipe, tr_shdr, tr_shdr->replaced_tokens); + if (!state) + goto err; + + /* bind new shader if the shader is currently a bound */ + if (rb_context->curr.fs == tr_shdr || rb_context->curr.vs == tr_shdr) + rbug_shader_bind_locked(pipe, tr_shdr, state); + + /* save state */ + tr_shdr->replaced_shader = state; + +out: + pipe_mutex_unlock(rb_context->call_mutex); + pipe_mutex_unlock(rb_context->list_mutex); + pipe_mutex_unlock(rb_screen->list_mutex); + + return 0; + +err: + FREE(tr_shdr->replaced_tokens); + tr_shdr->replaced_shader = NULL; + tr_shdr->replaced_tokens = NULL; + + pipe_mutex_unlock(rb_context->call_mutex); + pipe_mutex_unlock(rb_context->list_mutex); + pipe_mutex_unlock(rb_screen->list_mutex); + return -EINVAL; +} + +static boolean +rbug_header(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) +{ + int ret = 0; + + switch(header->opcode) { + case RBUG_OP_PING: + rbug_send_ping_reply(tr_rbug->con, serial, NULL); + break; + case RBUG_OP_TEXTURE_LIST: + ret = rbug_texture_list(tr_rbug, header, serial); + break; + case RBUG_OP_TEXTURE_INFO: + ret = rbug_texture_info(tr_rbug, header, serial); + break; + case RBUG_OP_TEXTURE_READ: + ret = rbug_texture_read(tr_rbug, header, serial); + break; + case RBUG_OP_CONTEXT_LIST: + ret = rbug_context_list(tr_rbug, header, serial); + break; + case RBUG_OP_CONTEXT_INFO: + ret = rbug_context_info(tr_rbug, header, serial); + break; + case RBUG_OP_CONTEXT_DRAW_BLOCK: + ret = rbug_context_draw_block(tr_rbug, header, serial); + break; + case RBUG_OP_CONTEXT_DRAW_STEP: + ret = rbug_context_draw_step(tr_rbug, header, serial); + break; + case RBUG_OP_CONTEXT_DRAW_UNBLOCK: + ret = rbug_context_draw_unblock(tr_rbug, header, serial); + break; + case RBUG_OP_CONTEXT_DRAW_RULE: + ret = rbug_context_draw_rule(tr_rbug, header, serial); + break; + case RBUG_OP_CONTEXT_FLUSH: + ret = rbug_context_flush(tr_rbug, header, serial); + break; + case RBUG_OP_SHADER_LIST: + ret = rbug_shader_list(tr_rbug, header, serial); + break; + case RBUG_OP_SHADER_INFO: + ret = rbug_shader_info(tr_rbug, header, serial); + break; + case RBUG_OP_SHADER_DISABLE: + ret = rbug_shader_disable(tr_rbug, header); + break; + case RBUG_OP_SHADER_REPLACE: + ret = rbug_shader_replace(tr_rbug, header); + break; + default: + debug_printf("%s - unsupported opcode %u\n", __FUNCTION__, header->opcode); + ret = -ENOSYS; + break; + } + rbug_free_header(header); + + if (ret) + rbug_send_error_reply(tr_rbug->con, serial, ret, NULL); + + return TRUE; +} + +static void +rbug_con(struct rbug_rbug *tr_rbug) +{ + struct rbug_header *header; + uint32_t serial; + + debug_printf("%s - connection received\n", __FUNCTION__); + + while(tr_rbug->running) { + header = rbug_get_message(tr_rbug->con, &serial); + if (!header) + break; + + if (!rbug_header(tr_rbug, header, serial)) + break; + } + + debug_printf("%s - connection closed\n", __FUNCTION__); + + rbug_disconnect(tr_rbug->con); + tr_rbug->con = NULL; +} + +PIPE_THREAD_ROUTINE(rbug_thread, void_tr_rbug) +{ + struct rbug_rbug *tr_rbug = void_tr_rbug; + uint16_t port = 13370; + int s = -1; + int c; + + u_socket_init(); + + for (;port <= 13379 && s < 0; port++) + s = u_socket_listen_on_port(port); + + if (s < 0) { + debug_printf("rbug_rbug - failed to listen\n"); + return NULL; + } + + u_socket_block(s, false); + + debug_printf("rbug_rbug - remote debugging listening on port %u\n", --port); + + while(tr_rbug->running) { + os_time_sleep(1); + + c = u_socket_accept(s); + if (c < 0) + continue; + + u_socket_block(c, true); + tr_rbug->con = rbug_from_socket(c); + + rbug_con(tr_rbug); + + u_socket_close(c); + } + + u_socket_close(s); + + u_socket_stop(); + + return NULL; +} + +/********************************************************** + * + */ + +struct rbug_rbug * +rbug_start(struct rbug_screen *rb_screen) +{ + struct rbug_rbug *tr_rbug = CALLOC_STRUCT(rbug_rbug); + if (!tr_rbug) + return NULL; + + tr_rbug->rb_screen = rb_screen; + tr_rbug->running = TRUE; + tr_rbug->thread = pipe_thread_create(rbug_thread, tr_rbug); + + return tr_rbug; +} + +void +rbug_stop(struct rbug_rbug *tr_rbug) +{ + if (!tr_rbug) + return; + + tr_rbug->running = false; + pipe_thread_wait(tr_rbug->thread); + + FREE(tr_rbug); + + return; +} + +void +rbug_notify_draw_blocked(struct rbug_context *rb_context) +{ + struct rbug_screen *rb_screen = rbug_screen(rb_context->base.screen); + struct rbug_rbug *tr_rbug = rb_screen->rbug; + + if (tr_rbug && tr_rbug->con) + rbug_send_context_draw_blocked(tr_rbug->con, + VOID2U64(rb_context), rb_context->draw_blocked, NULL); +} diff --git a/src/gallium/drivers/rbug/rbug_objects.c b/src/gallium/drivers/rbug/rbug_objects.c new file mode 100644 index 0000000..7d7cc48 --- /dev/null +++ b/src/gallium/drivers/rbug/rbug_objects.c @@ -0,0 +1,250 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_simple_list.h" + +#include "tgsi/tgsi_parse.h" + +#include "rbug_screen.h" +#include "rbug_objects.h" +#include "rbug_context.h" + + + +struct pipe_resource * +rbug_resource_create(struct rbug_screen *rb_screen, + struct pipe_resource *resource) +{ + struct rbug_resource *rb_resource; + + if(!resource) + goto error; + + assert(resource->screen == rb_screen->screen); + + rb_resource = CALLOC_STRUCT(rbug_resource); + if(!rb_resource) + goto error; + + memcpy(&rb_resource->base, resource, sizeof(struct pipe_resource)); + + pipe_reference_init(&rb_resource->base.reference, 1); + rb_resource->base.screen = &rb_screen->base; + rb_resource->resource = resource; + + rbug_screen_add_to_list(rb_screen, resources, rb_resource); + + return &rb_resource->base; + +error: + pipe_resource_reference(&resource, NULL); + return NULL; +} + +void +rbug_resource_destroy(struct rbug_resource *rb_resource) +{ + struct rbug_screen *rb_screen = rbug_screen(rb_resource->base.screen); + rbug_screen_remove_from_list(rb_screen, resources, rb_resource); + + pipe_resource_reference(&rb_resource->resource, NULL); + FREE(rb_resource); +} + + +struct pipe_surface * +rbug_surface_create(struct rbug_context *rb_context, + struct rbug_resource *rb_resource, + struct pipe_surface *surface) +{ + struct rbug_surface *rb_surface; + + if(!surface) + goto error; + + assert(surface->texture == rb_resource->resource); + + rb_surface = CALLOC_STRUCT(rbug_surface); + if(!rb_surface) + goto error; + + memcpy(&rb_surface->base, surface, sizeof(struct pipe_surface)); + + pipe_reference_init(&rb_surface->base.reference, 1); + rb_surface->base.texture = NULL; + pipe_resource_reference(&rb_surface->base.texture, &rb_resource->base); + rb_surface->surface = surface; + + return &rb_surface->base; + +error: + pipe_surface_reference(&surface, NULL); + return NULL; +} + +void +rbug_surface_destroy(struct rbug_context *rb_context, + struct rbug_surface *rb_surface) +{ + pipe_resource_reference(&rb_surface->base.texture, NULL); + rb_context->pipe->surface_destroy(rb_context->pipe, + rb_surface->surface); + FREE(rb_surface); +} + + +struct pipe_sampler_view * +rbug_sampler_view_create(struct rbug_context *rb_context, + struct rbug_resource *rb_resource, + struct pipe_sampler_view *view) +{ + struct rbug_sampler_view *rb_view; + + if (!view) + goto error; + + assert(view->texture == rb_resource->resource); + + rb_view = MALLOC(sizeof(struct rbug_sampler_view)); + + rb_view->base = *view; + rb_view->base.reference.count = 1; + rb_view->base.texture = NULL; + pipe_resource_reference(&rb_view->base.texture, &rb_resource->base); + rb_view->base.context = rb_context->pipe; + rb_view->sampler_view = view; + + return &rb_view->base; +error: + return NULL; +} + +void +rbug_sampler_view_destroy(struct rbug_context *rb_context, + struct rbug_sampler_view *rb_view) +{ + pipe_resource_reference(&rb_view->base.texture, NULL); + rb_context->pipe->sampler_view_destroy(rb_context->pipe, + rb_view->sampler_view); + FREE(rb_view); +} + + +struct pipe_transfer * +rbug_transfer_create(struct rbug_context *rb_context, + struct rbug_resource *rb_resource, + struct pipe_transfer *transfer) +{ + struct rbug_transfer *rb_transfer; + + if(!transfer) + goto error; + + assert(transfer->resource == rb_resource->resource); + + rb_transfer = CALLOC_STRUCT(rbug_transfer); + if(!rb_transfer) + goto error; + + memcpy(&rb_transfer->base, transfer, sizeof(struct pipe_transfer)); + + rb_transfer->base.resource = NULL; + rb_transfer->transfer = transfer; + rb_transfer->pipe = rb_context->pipe; + + pipe_resource_reference(&rb_transfer->base.resource, &rb_resource->base); + assert(rb_transfer->base.resource == &rb_resource->base); + + return &rb_transfer->base; + +error: + rb_context->pipe->transfer_destroy(rb_context->pipe, transfer); + return NULL; +} + +void +rbug_transfer_destroy(struct rbug_context *rb_context, + struct rbug_transfer *rb_transfer) +{ + pipe_resource_reference(&rb_transfer->base.resource, NULL); + rb_transfer->pipe->transfer_destroy(rb_context->pipe, + rb_transfer->transfer); + FREE(rb_transfer); +} + +void * +rbug_shader_create(struct rbug_context *rb_context, + const struct pipe_shader_state *state, + void *result, enum rbug_shader_type type) +{ + struct rbug_shader *rb_shader = CALLOC_STRUCT(rbug_shader); + + rb_shader->type = type; + rb_shader->shader = result; + rb_shader->tokens = tgsi_dup_tokens(state->tokens); + + /* works on context as well since its just a macro */ + rbug_screen_add_to_list(rb_context, shaders, rb_shader); + + return rb_shader; +} + +void +rbug_shader_destroy(struct rbug_context *rb_context, + struct rbug_shader *rb_shader) +{ + struct pipe_context *pipe = rb_context->pipe; + + /* works on context as well since its just a macro */ + rbug_screen_remove_from_list(rb_context, shaders, rb_shader); + + switch(rb_shader->type) { + case RBUG_SHADER_FRAGMENT: + if (rb_shader->replaced_shader) + pipe->delete_fs_state(pipe, rb_shader->replaced_shader); + pipe->delete_fs_state(pipe, rb_shader->shader); + break; + case RBUG_SHADER_VERTEX: + if (rb_shader->replaced_shader) + pipe->delete_vs_state(pipe, rb_shader->replaced_shader); + pipe->delete_vs_state(pipe, rb_shader->shader); + break; + case RBUG_SHADER_GEOM: + if (rb_shader->replaced_shader) + pipe->delete_gs_state(pipe, rb_shader->replaced_shader); + pipe->delete_gs_state(pipe, rb_shader->shader); + break; + default: + assert(0); + } + + FREE(rb_shader->replaced_tokens); + FREE(rb_shader->tokens); + FREE(rb_shader); +} diff --git a/src/gallium/drivers/rbug/rbug_objects.h b/src/gallium/drivers/rbug/rbug_objects.h new file mode 100644 index 0000000..3fba333 --- /dev/null +++ b/src/gallium/drivers/rbug/rbug_objects.h @@ -0,0 +1,228 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef RBUG_OBJECTS_H +#define RBUG_OBJECTS_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" + +#include "rbug_screen.h" + +struct rbug_context; + + +struct rbug_resource +{ + struct pipe_resource base; + + struct pipe_resource *resource; + + struct rbug_list list; +}; + + +enum rbug_shader_type +{ + RBUG_SHADER_GEOM, + RBUG_SHADER_VERTEX, + RBUG_SHADER_FRAGMENT, +}; + +struct rbug_shader +{ + struct rbug_list list; + + void *shader; + void *tokens; + void *replaced_shader; + void *replaced_tokens; + + enum rbug_shader_type type; + boolean disabled; +}; + + +struct rbug_sampler_view +{ + struct pipe_sampler_view base; + + struct pipe_sampler_view *sampler_view; +}; + + +struct rbug_surface +{ + struct pipe_surface base; + + struct pipe_surface *surface; +}; + + +struct rbug_transfer +{ + struct pipe_transfer base; + + struct pipe_context *pipe; + struct pipe_transfer *transfer; +}; + + +static INLINE struct rbug_resource * +rbug_resource(struct pipe_resource *_resource) +{ + if (!_resource) + return NULL; + (void)rbug_screen(_resource->screen); + return (struct rbug_resource *)_resource; +} + +static INLINE struct rbug_sampler_view * +rbug_sampler_view(struct pipe_sampler_view *_sampler_view) +{ + if (!_sampler_view) + return NULL; + (void)rbug_resource(_sampler_view->texture); + return (struct rbug_sampler_view *)_sampler_view; +} + +static INLINE struct rbug_surface * +rbug_surface(struct pipe_surface *_surface) +{ + if (!_surface) + return NULL; + (void)rbug_resource(_surface->texture); + return (struct rbug_surface *)_surface; +} + +static INLINE struct rbug_transfer * +rbug_transfer(struct pipe_transfer *_transfer) +{ + if (!_transfer) + return NULL; + (void)rbug_resource(_transfer->resource); + return (struct rbug_transfer *)_transfer; +} + +static INLINE struct rbug_shader * +rbug_shader(void *_state) +{ + if (!_state) + return NULL; + return (struct rbug_shader *)_state; +} + +static INLINE struct pipe_resource * +rbug_resource_unwrap(struct pipe_resource *_resource) +{ + if (!_resource) + return NULL; + return rbug_resource(_resource)->resource; +} + +static INLINE struct pipe_sampler_view * +rbug_sampler_view_unwrap(struct pipe_sampler_view *_sampler_view) +{ + if (!_sampler_view) + return NULL; + return rbug_sampler_view(_sampler_view)->sampler_view; +} + +static INLINE struct pipe_surface * +rbug_surface_unwrap(struct pipe_surface *_surface) +{ + if (!_surface) + return NULL; + return rbug_surface(_surface)->surface; +} + +static INLINE struct pipe_transfer * +rbug_transfer_unwrap(struct pipe_transfer *_transfer) +{ + if (!_transfer) + return NULL; + return rbug_transfer(_transfer)->transfer; +} + +static INLINE void * +rbug_shader_unwrap(void *_state) +{ + struct rbug_shader *shader; + if (!_state) + return NULL; + + shader = rbug_shader(_state); + return shader->replaced_shader ? shader->replaced_shader : shader->shader; +} + + +struct pipe_resource * +rbug_resource_create(struct rbug_screen *rb_screen, + struct pipe_resource *resource); + +void +rbug_resource_destroy(struct rbug_resource *rb_resource); + +struct pipe_surface * +rbug_surface_create(struct rbug_context *rb_context, + struct rbug_resource *rb_resource, + struct pipe_surface *surface); + +void +rbug_surface_destroy(struct rbug_context *rb_context, + struct rbug_surface *rb_surface); + +struct pipe_sampler_view * +rbug_sampler_view_create(struct rbug_context *rb_context, + struct rbug_resource *rb_resource, + struct pipe_sampler_view *view); + +void +rbug_sampler_view_destroy(struct rbug_context *rb_context, + struct rbug_sampler_view *rb_sampler_view); + +struct pipe_transfer * +rbug_transfer_create(struct rbug_context *rb_context, + struct rbug_resource *rb_resource, + struct pipe_transfer *transfer); + +void +rbug_transfer_destroy(struct rbug_context *rb_context, + struct rbug_transfer *rb_transfer); + +void * +rbug_shader_create(struct rbug_context *rb_context, + const struct pipe_shader_state *state, + void *result, enum rbug_shader_type type); + +void +rbug_shader_destroy(struct rbug_context *rb_context, + struct rbug_shader *rb_shader); + + +#endif /* RBUG_OBJECTS_H */ diff --git a/src/gallium/drivers/rbug/rbug_public.h b/src/gallium/drivers/rbug/rbug_public.h new file mode 100644 index 0000000..b66740b --- /dev/null +++ b/src/gallium/drivers/rbug/rbug_public.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 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 RBUG_PUBLIC_H +#define RBUG_PUBLIC_H + +struct pipe_screen; +struct pipe_context; + +struct pipe_screen * +rbug_screen_create(struct pipe_screen *screen); + +boolean +rbug_enabled(void); + +#endif /* RBUG_PUBLIC_H */ diff --git a/src/gallium/drivers/rbug/rbug_screen.c b/src/gallium/drivers/rbug/rbug_screen.c new file mode 100644 index 0000000..d635ce5 --- /dev/null +++ b/src/gallium/drivers/rbug/rbug_screen.c @@ -0,0 +1,331 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "pipe/p_screen.h" +#include "pipe/p_state.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_simple_list.h" + +#include "rbug_public.h" +#include "rbug_screen.h" +#include "rbug_context.h" +#include "rbug_objects.h" + +DEBUG_GET_ONCE_BOOL_OPTION(rbug, "GALLIUM_RBUG", FALSE) + +static void +rbug_screen_destroy(struct pipe_screen *_screen) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct pipe_screen *screen = rb_screen->screen; + + screen->destroy(screen); + + FREE(rb_screen); +} + +static const char * +rbug_screen_get_name(struct pipe_screen *_screen) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct pipe_screen *screen = rb_screen->screen; + + return screen->get_name(screen); +} + +static const char * +rbug_screen_get_vendor(struct pipe_screen *_screen) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct pipe_screen *screen = rb_screen->screen; + + return screen->get_vendor(screen); +} + +static int +rbug_screen_get_param(struct pipe_screen *_screen, + enum pipe_cap param) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct pipe_screen *screen = rb_screen->screen; + + return screen->get_param(screen, + param); +} + +static int +rbug_screen_get_shader_param(struct pipe_screen *_screen, + unsigned shader, enum pipe_shader_cap param) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct pipe_screen *screen = rb_screen->screen; + + return screen->get_shader_param(screen, shader, + param); +} + +static float +rbug_screen_get_paramf(struct pipe_screen *_screen, + enum pipe_cap param) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct pipe_screen *screen = rb_screen->screen; + + return screen->get_paramf(screen, + param); +} + +static boolean +rbug_screen_is_format_supported(struct pipe_screen *_screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned tex_usage, + unsigned geom_flags) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct pipe_screen *screen = rb_screen->screen; + + return screen->is_format_supported(screen, + format, + target, + sample_count, + tex_usage, + geom_flags); +} + +static struct pipe_context * +rbug_screen_context_create(struct pipe_screen *_screen, + void *priv) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct pipe_screen *screen = rb_screen->screen; + struct pipe_context *result; + + result = screen->context_create(screen, priv); + if (result) + return rbug_context_create(_screen, result); + return NULL; +} + +static struct pipe_resource * +rbug_screen_resource_create(struct pipe_screen *_screen, + const struct pipe_resource *templat) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct pipe_screen *screen = rb_screen->screen; + struct pipe_resource *result; + + result = screen->resource_create(screen, + templat); + + if (result) + return rbug_resource_create(rb_screen, result); + return NULL; +} + +static struct pipe_resource * +rbug_screen_resource_from_handle(struct pipe_screen *_screen, + const struct pipe_resource *templ, + struct winsys_handle *handle) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct pipe_screen *screen = rb_screen->screen; + struct pipe_resource *result; + + result = screen->resource_from_handle(screen, templ, handle); + + result = rbug_resource_create(rbug_screen(_screen), result); + + return result; +} + +static boolean +rbug_screen_resource_get_handle(struct pipe_screen *_screen, + struct pipe_resource *_resource, + struct winsys_handle *handle) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct rbug_resource *rb_resource = rbug_resource(_resource); + struct pipe_screen *screen = rb_screen->screen; + struct pipe_resource *resource = rb_resource->resource; + + return screen->resource_get_handle(screen, resource, handle); +} + + + +static void +rbug_screen_resource_destroy(struct pipe_screen *screen, + struct pipe_resource *_resource) +{ + rbug_resource_destroy(rbug_resource(_resource)); +} + +static struct pipe_resource * +rbug_screen_user_buffer_create(struct pipe_screen *_screen, + void *ptr, + unsigned bytes, + unsigned usage) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct pipe_screen *screen = rb_screen->screen; + struct pipe_resource *result; + + result = screen->user_buffer_create(screen, + ptr, + bytes, + usage); + + if (result) + return rbug_resource_create(rb_screen, result); + return NULL; +} + + + +static void +rbug_screen_flush_frontbuffer(struct pipe_screen *_screen, + struct pipe_resource *_resource, + unsigned level, unsigned layer, + void *context_private) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct rbug_resource *rb_resource = rbug_resource(_resource); + struct pipe_screen *screen = rb_screen->screen; + struct pipe_resource *resource = rb_resource->resource; + + screen->flush_frontbuffer(screen, + resource, + level, layer, + context_private); +} + +static void +rbug_screen_fence_reference(struct pipe_screen *_screen, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct pipe_screen *screen = rb_screen->screen; + + screen->fence_reference(screen, + ptr, + fence); +} + +static int +rbug_screen_fence_signalled(struct pipe_screen *_screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct pipe_screen *screen = rb_screen->screen; + + return screen->fence_signalled(screen, + fence, + flags); +} + +static int +rbug_screen_fence_finish(struct pipe_screen *_screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + struct rbug_screen *rb_screen = rbug_screen(_screen); + struct pipe_screen *screen = rb_screen->screen; + + return screen->fence_finish(screen, + fence, + flags); +} + +boolean +rbug_enabled() +{ + return debug_get_option_rbug(); +} + +struct pipe_screen * +rbug_screen_create(struct pipe_screen *screen) +{ + struct rbug_screen *rb_screen; + + if (!debug_get_option_rbug()) + return screen; + + rb_screen = CALLOC_STRUCT(rbug_screen); + if (!rb_screen) + return screen; + + pipe_mutex_init(rb_screen->list_mutex); + make_empty_list(&rb_screen->contexts); + make_empty_list(&rb_screen->resources); + make_empty_list(&rb_screen->surfaces); + make_empty_list(&rb_screen->transfers); + + rb_screen->base.winsys = NULL; + + rb_screen->base.destroy = rbug_screen_destroy; + rb_screen->base.get_name = rbug_screen_get_name; + rb_screen->base.get_vendor = rbug_screen_get_vendor; + rb_screen->base.get_param = rbug_screen_get_param; + rb_screen->base.get_shader_param = rbug_screen_get_shader_param; + rb_screen->base.get_paramf = rbug_screen_get_paramf; + rb_screen->base.is_format_supported = rbug_screen_is_format_supported; + rb_screen->base.context_create = rbug_screen_context_create; + rb_screen->base.resource_create = rbug_screen_resource_create; + rb_screen->base.resource_from_handle = rbug_screen_resource_from_handle; + rb_screen->base.resource_get_handle = rbug_screen_resource_get_handle; + rb_screen->base.resource_destroy = rbug_screen_resource_destroy; + rb_screen->base.user_buffer_create = rbug_screen_user_buffer_create; + rb_screen->base.flush_frontbuffer = rbug_screen_flush_frontbuffer; + rb_screen->base.fence_reference = rbug_screen_fence_reference; + rb_screen->base.fence_signalled = rbug_screen_fence_signalled; + rb_screen->base.fence_finish = rbug_screen_fence_finish; + + rb_screen->screen = screen; + + rb_screen->private_context = screen->context_create(screen, NULL); + if (!rb_screen->private_context) + goto err_free; + + rb_screen->rbug = rbug_start(rb_screen); + + if (!rb_screen->rbug) + goto err_context; + + return &rb_screen->base; + +err_context: + rb_screen->private_context->destroy(rb_screen->private_context); +err_free: + FREE(rb_screen); + return screen; +} diff --git a/src/gallium/drivers/rbug/rbug_screen.h b/src/gallium/drivers/rbug/rbug_screen.h new file mode 100644 index 0000000..a53afac --- /dev/null +++ b/src/gallium/drivers/rbug/rbug_screen.h @@ -0,0 +1,100 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef RBUG_SCREEN_H +#define RBUG_SCREEN_H + +#include "pipe/p_screen.h" +#include "pipe/p_defines.h" + +#include "os/os_thread.h" + +struct rbug_list { + struct rbug_list *next; + struct rbug_list *prev; +}; + + +struct rbug_screen +{ + struct pipe_screen base; + + struct pipe_screen *screen; + struct pipe_context *private_context; + + /* remote debugger */ + struct rbug_rbug *rbug; + + pipe_mutex list_mutex; + int num_contexts; + int num_resources; + int num_surfaces; + int num_transfers; + struct rbug_list contexts; + struct rbug_list resources; + struct rbug_list surfaces; + struct rbug_list transfers; +}; + +static INLINE struct rbug_screen * +rbug_screen(struct pipe_screen *screen) +{ + return (struct rbug_screen *)screen; +} + +#define rbug_screen_add_to_list(scr, name, obj) \ + do { \ + pipe_mutex_lock(scr->list_mutex); \ + insert_at_head(&scr->name, &obj->list); \ + scr->num_##name++; \ + pipe_mutex_unlock(scr->list_mutex); \ + } while (0) + +#define rbug_screen_remove_from_list(scr, name, obj) \ + do { \ + pipe_mutex_lock(scr->list_mutex); \ + remove_from_list(&obj->list); \ + scr->num_##name--; \ + pipe_mutex_unlock(scr->list_mutex); \ + } while (0) + + + +/********************************************************** + * rbug_core.c + */ + +struct rbug_rbug; + +struct rbug_rbug * +rbug_start(struct rbug_screen *rb_screen); + +void +rbug_stop(struct rbug_rbug *rbug); + + +#endif /* RBUG_SCREEN_H */ diff --git a/src/gallium/drivers/softpipe/Makefile b/src/gallium/drivers/softpipe/Makefile new file mode 100644 index 0000000..2895358 --- /dev/null +++ b/src/gallium/drivers/softpipe/Makefile @@ -0,0 +1,38 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = softpipe + +C_SOURCES = \ + sp_fs_exec.c \ + sp_fs_sse.c \ + sp_clear.c \ + sp_fence.c \ + sp_flush.c \ + sp_query.c \ + sp_context.c \ + sp_draw_arrays.c \ + sp_prim_vbuf.c \ + sp_quad_pipe.c \ + sp_quad_stipple.c \ + sp_quad_depth_test.c \ + sp_quad_fs.c \ + sp_quad_blend.c \ + sp_screen.c \ + sp_setup.c \ + sp_state_blend.c \ + sp_state_clip.c \ + sp_state_derived.c \ + sp_state_sampler.c \ + sp_state_shader.c \ + sp_state_so.c \ + sp_state_rasterizer.c \ + sp_state_surface.c \ + sp_state_vertex.c \ + sp_texture.c \ + sp_tex_sample.c \ + sp_tex_tile_cache.c \ + sp_tile_cache.c \ + sp_surface.c + +include ../../Makefile.template diff --git a/src/gallium/drivers/softpipe/SConscript b/src/gallium/drivers/softpipe/SConscript new file mode 100644 index 0000000..ea10e8a --- /dev/null +++ b/src/gallium/drivers/softpipe/SConscript @@ -0,0 +1,42 @@ +Import('*') + +env = env.Clone() + +softpipe = env.ConvenienceLibrary( + target = 'softpipe', + source = [ + 'sp_fs_exec.c', + 'sp_fs_sse.c', + 'sp_clear.c', + 'sp_context.c', + 'sp_draw_arrays.c', + 'sp_fence.c', + 'sp_flush.c', + 'sp_prim_vbuf.c', + 'sp_setup.c', + 'sp_quad_blend.c', + 'sp_quad_pipe.c', + 'sp_quad_depth_test.c', + 'sp_quad_fs.c', + 'sp_quad_stipple.c', + 'sp_query.c', + 'sp_screen.c', + 'sp_state_blend.c', + 'sp_state_clip.c', + 'sp_state_derived.c', + 'sp_state_rasterizer.c', + 'sp_state_sampler.c', + 'sp_state_shader.c', + 'sp_state_so.c', + 'sp_state_surface.c', + 'sp_state_vertex.c', + 'sp_surface.c', + 'sp_tex_sample.c', + 'sp_tex_tile_cache.c', + 'sp_texture.c', + 'sp_tile_cache.c', + ]) + +env.Alias('softpipe', softpipe) + +Export('softpipe') diff --git a/src/gallium/drivers/softpipe/sp_clear.c b/src/gallium/drivers/softpipe/sp_clear.c new file mode 100644 index 0000000..ae3f00f --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_clear.c @@ -0,0 +1,84 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * 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 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: + * Brian Paul + * Michel Dänzer + */ + + +#include "pipe/p_defines.h" +#include "util/u_pack_color.h" +#include "sp_clear.h" +#include "sp_context.h" +#include "sp_query.h" +#include "sp_tile_cache.h" + + +/** + * Clear the given buffers to the specified values. + * No masking, no scissor (clear entire buffer). + */ +void +softpipe_clear(struct pipe_context *pipe, unsigned buffers, const float *rgba, + double depth, unsigned stencil) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + union util_color uc; + unsigned cv; + uint i; + + if (softpipe->no_rast) + return; + + if (!softpipe_check_render_cond(softpipe)) + return; + +#if 0 + softpipe_update_derived(softpipe); /* not needed?? */ +#endif + + if (buffers & PIPE_CLEAR_COLOR) { + for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++) { + struct pipe_surface *ps = softpipe->framebuffer.cbufs[i]; + + util_pack_color(rgba, ps->format, &uc); + sp_tile_cache_clear(softpipe->cbuf_cache[i], rgba, uc.ui); + } + } + + if (buffers & PIPE_CLEAR_DEPTHSTENCIL) { + static const float zero[4] = { 0.0F, 0.0F, 0.0F, 0.0F }; + struct pipe_surface *ps = softpipe->framebuffer.zsbuf; + + cv = util_pack_z_stencil(ps->format, depth, stencil); + sp_tile_cache_clear(softpipe->zsbuf_cache, zero, cv); + } + + softpipe->dirty_render_cache = TRUE; +} diff --git a/src/gallium/drivers/softpipe/sp_clear.h b/src/gallium/drivers/softpipe/sp_clear.h new file mode 100644 index 0000000..9be3b86 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_clear.h @@ -0,0 +1,42 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Author: + * Brian Paul + */ + +#ifndef SP_CLEAR_H +#define SP_CLEAR_H + +struct pipe_context; + +extern void +softpipe_clear(struct pipe_context *pipe, unsigned buffers, const float *rgba, + double depth, unsigned stencil); + + +#endif /* SP_CLEAR_H */ diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c new file mode 100644 index 0000000..e935ce6 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -0,0 +1,331 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2008 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 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: + * Keith Whitwell + */ + +#include "draw/draw_context.h" +#include "draw/draw_vbuf.h" +#include "pipe/p_defines.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "tgsi/tgsi_exec.h" +#include "sp_clear.h" +#include "sp_context.h" +#include "sp_flush.h" +#include "sp_prim_vbuf.h" +#include "sp_state.h" +#include "sp_surface.h" +#include "sp_tile_cache.h" +#include "sp_tex_tile_cache.h" +#include "sp_texture.h" +#include "sp_query.h" + + + +/** + * Map any drawing surfaces which aren't already mapped + */ +void +softpipe_map_transfers(struct softpipe_context *sp) +{ + unsigned i; + + for (i = 0; i < sp->framebuffer.nr_cbufs; i++) { + sp_tile_cache_map_transfers(sp->cbuf_cache[i]); + } + + sp_tile_cache_map_transfers(sp->zsbuf_cache); +} + + +/** + * Unmap any mapped drawing surfaces + */ +void +softpipe_unmap_transfers(struct softpipe_context *sp) +{ + uint i; + + for (i = 0; i < sp->framebuffer.nr_cbufs; i++) { + sp_tile_cache_unmap_transfers(sp->cbuf_cache[i]); + } + + sp_tile_cache_unmap_transfers(sp->zsbuf_cache); +} + + +static void +softpipe_destroy( struct pipe_context *pipe ) +{ + struct softpipe_context *softpipe = softpipe_context( pipe ); + uint i; + + if (softpipe->draw) + draw_destroy( softpipe->draw ); + + softpipe->quad.shade->destroy( softpipe->quad.shade ); + softpipe->quad.depth_test->destroy( softpipe->quad.depth_test ); + softpipe->quad.blend->destroy( softpipe->quad.blend ); + softpipe->quad.pstipple->destroy( softpipe->quad.pstipple ); + + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + sp_destroy_tile_cache(softpipe->cbuf_cache[i]); + pipe_surface_reference(&softpipe->framebuffer.cbufs[i], NULL); + } + + sp_destroy_tile_cache(softpipe->zsbuf_cache); + pipe_surface_reference(&softpipe->framebuffer.zsbuf, NULL); + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + sp_destroy_tex_tile_cache(softpipe->tex_cache[i]); + pipe_sampler_view_reference(&softpipe->sampler_views[i], NULL); + } + + for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { + sp_destroy_tex_tile_cache(softpipe->vertex_tex_cache[i]); + pipe_sampler_view_reference(&softpipe->vertex_sampler_views[i], NULL); + } + + for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) { + sp_destroy_tex_tile_cache(softpipe->geometry_tex_cache[i]); + pipe_sampler_view_reference(&softpipe->geometry_sampler_views[i], NULL); + } + + for (i = 0; i < PIPE_SHADER_TYPES; i++) { + uint j; + + for (j = 0; j < PIPE_MAX_CONSTANT_BUFFERS; j++) { + if (softpipe->constants[i][j]) { + pipe_resource_reference(&softpipe->constants[i][j], NULL); + } + } + } + + tgsi_exec_machine_destroy(softpipe->fs_machine); + + FREE( softpipe ); +} + + +/** + * if (the texture is being used as a framebuffer surface) + * return PIPE_REFERENCED_FOR_WRITE + * else if (the texture is a bound texture source) + * return PIPE_REFERENCED_FOR_READ + * else + * return PIPE_UNREFERENCED + */ +static unsigned int +softpipe_is_resource_referenced( struct pipe_context *pipe, + struct pipe_resource *texture, + unsigned level, int layer) +{ + struct softpipe_context *softpipe = softpipe_context( pipe ); + unsigned i; + + if (texture->target == PIPE_BUFFER) + return PIPE_UNREFERENCED; + + /* check if any of the bound drawing surfaces are this texture */ + if (softpipe->dirty_render_cache) { + for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++) { + if (softpipe->framebuffer.cbufs[i] && + softpipe->framebuffer.cbufs[i]->texture == texture) { + return PIPE_REFERENCED_FOR_WRITE; + } + } + if (softpipe->framebuffer.zsbuf && + softpipe->framebuffer.zsbuf->texture == texture) { + return PIPE_REFERENCED_FOR_WRITE; + } + } + + /* check if any of the tex_cache textures are this texture */ + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + if (softpipe->tex_cache[i] && + softpipe->tex_cache[i]->texture == texture) + return PIPE_REFERENCED_FOR_READ; + } + for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { + if (softpipe->vertex_tex_cache[i] && + softpipe->vertex_tex_cache[i]->texture == texture) + return PIPE_REFERENCED_FOR_READ; + } + for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) { + if (softpipe->geometry_tex_cache[i] && + softpipe->geometry_tex_cache[i]->texture == texture) + return PIPE_REFERENCED_FOR_READ; + } + + return PIPE_UNREFERENCED; +} + + + + +static void +softpipe_render_condition( struct pipe_context *pipe, + struct pipe_query *query, + uint mode ) +{ + struct softpipe_context *softpipe = softpipe_context( pipe ); + + softpipe->render_cond_query = query; + softpipe->render_cond_mode = mode; +} + + + +struct pipe_context * +softpipe_create_context( struct pipe_screen *screen, + void *priv ) +{ + struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context); + uint i; + + util_init_math(); + +#ifdef PIPE_ARCH_X86 + softpipe->use_sse = !debug_get_bool_option( "GALLIUM_NOSSE", FALSE ); +#else + softpipe->use_sse = FALSE; +#endif + + softpipe->dump_fs = debug_get_bool_option( "GALLIUM_DUMP_FS", FALSE ); + softpipe->dump_gs = debug_get_bool_option( "SOFTPIPE_DUMP_GS", FALSE ); + + softpipe->pipe.winsys = NULL; + softpipe->pipe.screen = screen; + softpipe->pipe.destroy = softpipe_destroy; + softpipe->pipe.priv = priv; + + /* state setters */ + softpipe_init_blend_funcs(&softpipe->pipe); + softpipe_init_clip_funcs(&softpipe->pipe); + softpipe_init_query_funcs( softpipe ); + softpipe_init_rasterizer_funcs(&softpipe->pipe); + softpipe_init_sampler_funcs(&softpipe->pipe); + softpipe_init_shader_funcs(&softpipe->pipe); + softpipe_init_streamout_funcs(&softpipe->pipe); + softpipe_init_texture_funcs( &softpipe->pipe ); + softpipe_init_vertex_funcs(&softpipe->pipe); + + softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; + + softpipe->pipe.draw_vbo = softpipe_draw_vbo; + softpipe->pipe.draw_stream_output = softpipe_draw_stream_output; + + softpipe->pipe.clear = softpipe_clear; + softpipe->pipe.flush = softpipe_flush; + + softpipe->pipe.is_resource_referenced = softpipe_is_resource_referenced; + + softpipe->pipe.render_condition = softpipe_render_condition; + + /* + * Alloc caches for accessing drawing surfaces and textures. + * Must be before quad stage setup! + */ + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) + softpipe->cbuf_cache[i] = sp_create_tile_cache( &softpipe->pipe ); + softpipe->zsbuf_cache = sp_create_tile_cache( &softpipe->pipe ); + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) + softpipe->tex_cache[i] = sp_create_tex_tile_cache( &softpipe->pipe ); + for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { + softpipe->vertex_tex_cache[i] = sp_create_tex_tile_cache( &softpipe->pipe ); + } + for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) { + softpipe->geometry_tex_cache[i] = sp_create_tex_tile_cache( &softpipe->pipe ); + } + + softpipe->fs_machine = tgsi_exec_machine_create(); + + /* setup quad rendering stages */ + softpipe->quad.shade = sp_quad_shade_stage(softpipe); + softpipe->quad.depth_test = sp_quad_depth_test_stage(softpipe); + softpipe->quad.blend = sp_quad_blend_stage(softpipe); + softpipe->quad.pstipple = sp_quad_polygon_stipple_stage(softpipe); + + + /* + * Create drawing context and plug our rendering stage into it. + */ + softpipe->draw = draw_create(&softpipe->pipe); + if (!softpipe->draw) + goto fail; + + draw_texture_samplers(softpipe->draw, + PIPE_SHADER_VERTEX, + PIPE_MAX_VERTEX_SAMPLERS, + (struct tgsi_sampler **) + softpipe->tgsi.vert_samplers_list); + + draw_texture_samplers(softpipe->draw, + PIPE_SHADER_GEOMETRY, + PIPE_MAX_GEOMETRY_SAMPLERS, + (struct tgsi_sampler **) + softpipe->tgsi.geom_samplers_list); + + if (debug_get_bool_option( "SP_NO_RAST", FALSE )) + softpipe->no_rast = TRUE; + + softpipe->vbuf_backend = sp_create_vbuf_backend(softpipe); + if (!softpipe->vbuf_backend) + goto fail; + + softpipe->vbuf = draw_vbuf_stage(softpipe->draw, softpipe->vbuf_backend); + if (!softpipe->vbuf) + goto fail; + + draw_set_rasterize_stage(softpipe->draw, softpipe->vbuf); + draw_set_render(softpipe->draw, softpipe->vbuf_backend); + + + /* plug in AA line/point stages */ + draw_install_aaline_stage(softpipe->draw, &softpipe->pipe); + draw_install_aapoint_stage(softpipe->draw, &softpipe->pipe); + + /* Do polygon stipple w/ texture map + frag prog? */ +#if DO_PSTIPPLE_IN_DRAW_MODULE + draw_install_pstipple_stage(softpipe->draw, &softpipe->pipe); +#endif + + draw_wide_point_sprites(softpipe->draw, TRUE); + + sp_init_surface_functions(softpipe); + + return &softpipe->pipe; + + fail: + softpipe_destroy(&softpipe->pipe); + return NULL; +} diff --git a/src/gallium/drivers/softpipe/sp_context.h b/src/gallium/drivers/softpipe/sp_context.h new file mode 100644 index 0000000..9361a3d --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_context.h @@ -0,0 +1,201 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef SP_CONTEXT_H +#define SP_CONTEXT_H + +#include "pipe/p_context.h" + +#include "draw/draw_vertex.h" + +#include "sp_quad_pipe.h" + + +/** Do polygon stipple in the driver here, or in the draw module? */ +#define DO_PSTIPPLE_IN_DRAW_MODULE 1 + + +struct softpipe_vbuf_render; +struct draw_context; +struct draw_stage; +struct softpipe_tile_cache; +struct softpipe_tex_tile_cache; +struct sp_fragment_shader; +struct sp_vertex_shader; +struct sp_velems_state; +struct sp_so_state; + + +struct softpipe_context { + struct pipe_context pipe; /**< base class */ + + /** Constant state objects */ + struct pipe_blend_state *blend; + struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_state *vertex_samplers[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_sampler_state *geometry_samplers[PIPE_MAX_GEOMETRY_SAMPLERS]; + struct pipe_depth_stencil_alpha_state *depth_stencil; + struct pipe_rasterizer_state *rasterizer; + struct sp_fragment_shader *fs; + struct sp_vertex_shader *vs; + struct sp_geometry_shader *gs; + struct sp_velems_state *velems; + struct sp_so_state *so; + + /** Other rendering state */ + struct pipe_blend_color blend_color; + struct pipe_stencil_ref stencil_ref; + struct pipe_clip_state clip; + struct pipe_resource *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS]; + struct pipe_framebuffer_state framebuffer; + struct pipe_poly_stipple poly_stipple; + struct pipe_scissor_state scissor; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_sampler_view *geometry_sampler_views[PIPE_MAX_GEOMETRY_SAMPLERS]; + struct pipe_viewport_state viewport; + struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; + struct pipe_index_buffer index_buffer; + struct { + struct softpipe_resource *buffer[PIPE_MAX_SO_BUFFERS]; + int offset[PIPE_MAX_SO_BUFFERS]; + int so_count[PIPE_MAX_SO_BUFFERS]; + int num_buffers; + } so_target; + struct pipe_query_data_so_statistics so_stats; + + unsigned num_samplers; + unsigned num_sampler_views; + unsigned num_vertex_samplers; + unsigned num_vertex_sampler_views; + unsigned num_geometry_samplers; + unsigned num_geometry_sampler_views; + unsigned num_vertex_buffers; + + unsigned dirty; /**< Mask of SP_NEW_x flags */ + + /* Counter for occlusion queries. Note this supports overlapping + * queries. + */ + uint64_t occlusion_count; + unsigned active_query_count; + + /** Mapped vertex buffers */ + ubyte *mapped_vbuffer[PIPE_MAX_ATTRIBS]; + + /** Mapped constant buffers */ + const void *mapped_constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS]; + unsigned const_buffer_size[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS]; + + /** Vertex format */ + struct vertex_info vertex_info; + struct vertex_info vertex_info_vbuf; + + /** Which vertex shader output slot contains point size */ + int psize_slot; + + /** The reduced version of the primitive supplied by the state tracker */ + unsigned reduced_api_prim; + + /** Derived information about which winding orders to cull */ + unsigned cull_mode; + + /** + * The reduced primitive after unfilled triangles, wide-line decomposition, + * etc, are taken into account. This is the primitive type that's actually + * rasterized. + */ + unsigned reduced_prim; + + /** Derived from scissor and surface bounds: */ + struct pipe_scissor_state cliprect; + + unsigned line_stipple_counter; + + /** Conditional query object and mode */ + struct pipe_query *render_cond_query; + uint render_cond_mode; + + /** Software quad rendering pipeline */ + struct { + struct quad_stage *shade; + struct quad_stage *depth_test; + struct quad_stage *blend; + struct quad_stage *pstipple; + struct quad_stage *first; /**< points to one of the above stages */ + } quad; + + /** TGSI exec things */ + struct { + struct sp_sampler_varient *geom_samplers_list[PIPE_MAX_GEOMETRY_SAMPLERS]; + struct sp_sampler_varient *vert_samplers_list[PIPE_MAX_VERTEX_SAMPLERS]; + struct sp_sampler_varient *frag_samplers_list[PIPE_MAX_SAMPLERS]; + } tgsi; + + struct tgsi_exec_machine *fs_machine; + + /** The primitive drawing context */ + struct draw_context *draw; + + /** Draw module backend */ + struct vbuf_render *vbuf_backend; + struct draw_stage *vbuf; + + boolean dirty_render_cache; + + struct softpipe_tile_cache *cbuf_cache[PIPE_MAX_COLOR_BUFS]; + struct softpipe_tile_cache *zsbuf_cache; + + unsigned tex_timestamp; + struct softpipe_tex_tile_cache *tex_cache[PIPE_MAX_SAMPLERS]; + struct softpipe_tex_tile_cache *vertex_tex_cache[PIPE_MAX_VERTEX_SAMPLERS]; + struct softpipe_tex_tile_cache *geometry_tex_cache[PIPE_MAX_GEOMETRY_SAMPLERS]; + + unsigned use_sse : 1; + unsigned dump_fs : 1; + unsigned dump_gs : 1; + unsigned no_rast : 1; +}; + + +static INLINE struct softpipe_context * +softpipe_context( struct pipe_context *pipe ) +{ + return (struct softpipe_context *)pipe; +} + +void +softpipe_reset_sampler_varients(struct softpipe_context *softpipe); + +struct pipe_context * +softpipe_create_context( struct pipe_screen *, void *priv ); + + +#endif /* SP_CONTEXT_H */ diff --git a/src/gallium/drivers/softpipe/sp_draw_arrays.c b/src/gallium/drivers/softpipe/sp_draw_arrays.c new file mode 100644 index 0000000..01b4ca9 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_draw_arrays.c @@ -0,0 +1,162 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Author: + * Brian Paul + * Keith Whitwell + */ + + +#include "pipe/p_defines.h" +#include "pipe/p_context.h" +#include "util/u_inlines.h" +#include "util/u_prim.h" + +#include "sp_context.h" +#include "sp_query.h" +#include "sp_state.h" +#include "sp_texture.h" + +#include "draw/draw_context.h" + + + + + +void +softpipe_draw_stream_output(struct pipe_context *pipe, unsigned mode) +{ + struct softpipe_context *sp = softpipe_context(pipe); + struct draw_context *draw = sp->draw; + const unsigned start = 0; + const unsigned count = sp->so_target.so_count[0]; + void *buf = sp->so_target.buffer[0]->data; + int offset = sp->so_target.offset[0]; + + if (!softpipe_check_render_cond(sp) || + sp->so_target.num_buffers != 1) + return; + + sp->reduced_api_prim = u_reduced_prim(mode); + + if (sp->dirty) { + softpipe_update_derived(sp); + } + + softpipe_map_transfers(sp); + + /* Map so buffers */ + if (offset < 0) /* we were appending so start from beginning */ + offset = 0; + buf = (void*)((int32_t*)buf + offset); + draw_set_mapped_vertex_buffer(draw, 0, buf); + + draw_set_mapped_index_buffer(draw, NULL); + + /* draw! */ + draw_arrays(draw, mode, start, count); + + /* unmap vertex/index buffers - will cause draw module to flush */ + draw_set_mapped_vertex_buffer(draw, 0, NULL); + + /* + * TODO: Flush only when a user vertex/index buffer is present + * (or even better, modify draw module to do this + * internally when this condition is seen?) + */ + draw_flush(draw); + + /* Note: leave drawing surfaces mapped */ + sp->dirty_render_cache = TRUE; +} + + +/** + * This function handles drawing indexed and non-indexed prims, + * instanced and non-instanced drawing, with or without min/max element + * indexes. + * All the other drawing functions are expressed in terms of this + * function. + * + * For non-indexed prims, indexBuffer should be NULL. + * For non-instanced drawing, instanceCount should be 1. + * When the min/max element indexes aren't known, minIndex should be 0 + * and maxIndex should be ~0. + */ +void +softpipe_draw_vbo(struct pipe_context *pipe, + const struct pipe_draw_info *info) +{ + struct softpipe_context *sp = softpipe_context(pipe); + struct draw_context *draw = sp->draw; + void *mapped_indices = NULL; + unsigned i; + + if (!softpipe_check_render_cond(sp)) + return; + + sp->reduced_api_prim = u_reduced_prim(info->mode); + + if (sp->dirty) { + softpipe_update_derived(sp); + } + + softpipe_map_transfers(sp); + + /* Map vertex buffers */ + for (i = 0; i < sp->num_vertex_buffers; i++) { + void *buf = softpipe_resource(sp->vertex_buffer[i].buffer)->data; + draw_set_mapped_vertex_buffer(draw, i, buf); + } + + /* Map index buffer, if present */ + if (info->indexed && sp->index_buffer.buffer) + mapped_indices = softpipe_resource(sp->index_buffer.buffer)->data; + + draw_set_mapped_index_buffer(draw, mapped_indices); + + /* draw! */ + draw_vbo(draw, info); + + /* unmap vertex/index buffers - will cause draw module to flush */ + for (i = 0; i < sp->num_vertex_buffers; i++) { + draw_set_mapped_vertex_buffer(draw, i, NULL); + } + if (mapped_indices) { + draw_set_mapped_index_buffer(draw, NULL); + } + + /* + * TODO: Flush only when a user vertex/index buffer is present + * (or even better, modify draw module to do this + * internally when this condition is seen?) + */ + draw_flush(draw); + + /* Note: leave drawing surfaces mapped */ + sp->dirty_render_cache = TRUE; +} diff --git a/src/gallium/drivers/softpipe/sp_fence.c b/src/gallium/drivers/softpipe/sp_fence.c new file mode 100644 index 0000000..66c5214 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_fence.c @@ -0,0 +1,70 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "pipe/p_screen.h" +#include "util/u_debug.h" +#include "sp_fence.h" + + +static void +softpipe_fence_reference(struct pipe_screen *screen, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + assert(!*ptr); + assert(!fence); +} + + +static int +softpipe_fence_signalled(struct pipe_screen *screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + assert(!fence); + return 0; +} + + +static int +softpipe_fence_finish(struct pipe_screen *screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + assert(!fence); + return 0; +} + + +void +softpipe_init_screen_fence_funcs(struct pipe_screen *screen) +{ + screen->fence_reference = softpipe_fence_reference; + screen->fence_finish = softpipe_fence_finish; + screen->fence_signalled = softpipe_fence_signalled; +} diff --git a/src/gallium/drivers/softpipe/sp_fence.h b/src/gallium/drivers/softpipe/sp_fence.h new file mode 100644 index 0000000..39c3324 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_fence.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 SP_FENCE_H_ +#define SP_FENCE_H_ + + +struct pipe_screen; + + +void +softpipe_init_screen_fence_funcs(struct pipe_screen *screen); + + +#endif /* SP_FENCE_H_ */ diff --git a/src/gallium/drivers/softpipe/sp_flush.c b/src/gallium/drivers/softpipe/sp_flush.c new file mode 100644 index 0000000..4258395 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_flush.c @@ -0,0 +1,178 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Author: + * Keith Whitwell + */ + + +#include "pipe/p_defines.h" +#include "pipe/p_screen.h" +#include "draw/draw_context.h" +#include "sp_flush.h" +#include "sp_context.h" +#include "sp_state.h" +#include "sp_tile_cache.h" +#include "sp_tex_tile_cache.h" + + +void +softpipe_flush( struct pipe_context *pipe, + unsigned flags, + struct pipe_fence_handle **fence ) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + uint i; + + draw_flush(softpipe->draw); + + if (flags & PIPE_FLUSH_TEXTURE_CACHE) { + for (i = 0; i < softpipe->num_sampler_views; i++) { + sp_flush_tex_tile_cache(softpipe->tex_cache[i]); + } + for (i = 0; i < softpipe->num_vertex_sampler_views; i++) { + sp_flush_tex_tile_cache(softpipe->vertex_tex_cache[i]); + } + for (i = 0; i < softpipe->num_geometry_sampler_views; i++) { + sp_flush_tex_tile_cache(softpipe->geometry_tex_cache[i]); + } + } + + if (flags & PIPE_FLUSH_SWAPBUFFERS) { + /* If this is a swapbuffers, just flush color buffers. + * + * The zbuffer changes are not discarded, but held in the cache + * in the hope that a later clear will wipe them out. + */ + for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++) + if (softpipe->cbuf_cache[i]) + sp_flush_tile_cache(softpipe->cbuf_cache[i]); + + /* Need this call for hardware buffers before swapbuffers. + * + * there should probably be another/different flush-type function + * that's called before swapbuffers because we don't always want + * to unmap surfaces when flushing. + */ + softpipe_unmap_transfers(softpipe); + } + else if (flags & PIPE_FLUSH_RENDER_CACHE) { + for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++) + if (softpipe->cbuf_cache[i]) + sp_flush_tile_cache(softpipe->cbuf_cache[i]); + + if (softpipe->zsbuf_cache) + sp_flush_tile_cache(softpipe->zsbuf_cache); + + softpipe->dirty_render_cache = FALSE; + } + + /* Enable to dump BMPs of the color/depth buffers each frame */ +#if 0 + if(flags & PIPE_FLUSH_FRAME) { + static unsigned frame_no = 1; + static char filename[256]; + util_snprintf(filename, sizeof(filename), "cbuf_%u.bmp", frame_no); + debug_dump_surface_bmp(softpipe, filename, softpipe->framebuffer.cbufs[0]); + util_snprintf(filename, sizeof(filename), "zsbuf_%u.bmp", frame_no); + debug_dump_surface_bmp(softpipe, filename, softpipe->framebuffer.zsbuf); + ++frame_no; + } +#endif + + if (fence) + *fence = NULL; +} + + +/** + * Flush context if necessary. + * + * Returns FALSE if it would have block, but do_not_block was set, TRUE + * otherwise. + * + * TODO: move this logic to an auxiliary library? + */ +boolean +softpipe_flush_resource(struct pipe_context *pipe, + struct pipe_resource *texture, + unsigned level, + int layer, + unsigned flush_flags, + boolean read_only, + boolean cpu_access, + boolean do_not_block) +{ + unsigned referenced; + + referenced = pipe->is_resource_referenced(pipe, texture, level, layer); + + if ((referenced & PIPE_REFERENCED_FOR_WRITE) || + ((referenced & PIPE_REFERENCED_FOR_READ) && !read_only)) { + + /* + * TODO: The semantics of these flush flags are too obtuse. They should + * disappear and the pipe driver should just ensure that all visible + * side-effects happen when they need to happen. + */ + if (referenced & PIPE_REFERENCED_FOR_WRITE) + flush_flags |= PIPE_FLUSH_RENDER_CACHE; + + if (referenced & PIPE_REFERENCED_FOR_READ) + flush_flags |= PIPE_FLUSH_TEXTURE_CACHE; + + if (cpu_access) { + /* + * Flush and wait. + */ + + struct pipe_fence_handle *fence = NULL; + + if (do_not_block) + return FALSE; + + pipe->flush(pipe, flush_flags, &fence); + + if (fence) { + /* + * This is for illustrative purposes only, as softpipe does not + * have fences. + */ + pipe->screen->fence_finish(pipe->screen, fence, 0); + pipe->screen->fence_reference(pipe->screen, &fence, NULL); + } + } else { + /* + * Just flush. + */ + + pipe->flush(pipe, flush_flags, NULL); + } + } + + return TRUE; +} diff --git a/src/gallium/drivers/softpipe/sp_flush.h b/src/gallium/drivers/softpipe/sp_flush.h new file mode 100644 index 0000000..22a5cee --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_flush.h @@ -0,0 +1,50 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef SP_FLUSH_H +#define SP_FLUSH_H + +#include "pipe/p_compiler.h" + +struct pipe_context; +struct pipe_fence_handle; + +void +softpipe_flush(struct pipe_context *pipe, unsigned flags, + struct pipe_fence_handle **fence); + +boolean +softpipe_flush_resource(struct pipe_context *pipe, + struct pipe_resource *texture, + unsigned level, + int layer, + unsigned flush_flags, + boolean read_only, + boolean cpu_access, + boolean do_not_block); + +#endif diff --git a/src/gallium/drivers/softpipe/sp_fs.h b/src/gallium/drivers/softpipe/sp_fs.h new file mode 100644 index 0000000..4792ace --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_fs.h @@ -0,0 +1,54 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef SP_FS_H +#define SP_FS_H + +struct sp_fragment_shader * +softpipe_create_fs_exec(struct softpipe_context *softpipe, + const struct pipe_shader_state *templ); + +struct sp_fragment_shader * +softpipe_create_fs_sse(struct softpipe_context *softpipe, + const struct pipe_shader_state *templ); + +struct sp_fragment_shader * +softpipe_create_fs_llvm(struct softpipe_context *softpipe, + const struct pipe_shader_state *templ); + +struct tgsi_interp_coef; +struct tgsi_exec_vector; + +void sp_setup_pos_vector(const struct tgsi_interp_coef *coef, + float x, float y, + struct tgsi_exec_vector *quadpos); + + +#endif diff --git a/src/gallium/drivers/softpipe/sp_fs_exec.c b/src/gallium/drivers/softpipe/sp_fs_exec.c new file mode 100644 index 0000000..346e1b4 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_fs_exec.c @@ -0,0 +1,211 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Execute fragment shader using the TGSI interpreter. + */ + +#include "sp_context.h" +#include "sp_state.h" +#include "sp_fs.h" +#include "sp_quad.h" + +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_memory.h" +#include "tgsi/tgsi_exec.h" +#include "tgsi/tgsi_parse.h" + + +/** + * Subclass of sp_fragment_shader + */ +struct sp_exec_fragment_shader +{ + struct sp_fragment_shader base; + /* No other members for now */ +}; + + +/** cast wrapper */ +static INLINE struct sp_exec_fragment_shader * +sp_exec_fragment_shader(const struct sp_fragment_shader *base) +{ + return (struct sp_exec_fragment_shader *) base; +} + + +static void +exec_prepare( const struct sp_fragment_shader *base, + struct tgsi_exec_machine *machine, + struct tgsi_sampler **samplers ) +{ + /* + * Bind tokens/shader to the interpreter's machine state. + * Avoid redundant binding. + */ + if (machine->Tokens != base->shader.tokens) { + tgsi_exec_machine_bind_shader( machine, + base->shader.tokens, + PIPE_MAX_SAMPLERS, + samplers ); + } +} + + + +/** + * Compute quad X,Y,Z,W for the four fragments in a quad. + * + * This should really be part of the compiled shader. + */ +static void +setup_pos_vector(const struct tgsi_interp_coef *coef, + float x, float y, + struct tgsi_exec_vector *quadpos) +{ + uint chan; + /* do X */ + quadpos->xyzw[0].f[0] = x; + quadpos->xyzw[0].f[1] = x + 1; + quadpos->xyzw[0].f[2] = x; + quadpos->xyzw[0].f[3] = x + 1; + + /* do Y */ + quadpos->xyzw[1].f[0] = y; + quadpos->xyzw[1].f[1] = y; + quadpos->xyzw[1].f[2] = y + 1; + quadpos->xyzw[1].f[3] = y + 1; + + /* do Z and W for all fragments in the quad */ + for (chan = 2; chan < 4; chan++) { + const float dadx = coef->dadx[chan]; + const float dady = coef->dady[chan]; + const float a0 = coef->a0[chan] + dadx * x + dady * y; + quadpos->xyzw[chan].f[0] = a0; + quadpos->xyzw[chan].f[1] = a0 + dadx; + quadpos->xyzw[chan].f[2] = a0 + dady; + quadpos->xyzw[chan].f[3] = a0 + dadx + dady; + } +} + + +/* TODO: hide the machine struct in here somewhere, remove from this + * interface: + */ +static unsigned +exec_run( const struct sp_fragment_shader *base, + struct tgsi_exec_machine *machine, + struct quad_header *quad ) +{ + /* Compute X, Y, Z, W vals for this quad */ + setup_pos_vector(quad->posCoef, + (float)quad->input.x0, (float)quad->input.y0, + &machine->QuadPos); + + /* convert 0 to 1.0 and 1 to -1.0 */ + machine->Face = (float) (quad->input.facing * -2 + 1); + + quad->inout.mask &= tgsi_exec_machine_run( machine ); + if (quad->inout.mask == 0) + return FALSE; + + /* store outputs */ + { + const ubyte *sem_name = base->info.output_semantic_name; + const ubyte *sem_index = base->info.output_semantic_index; + const uint n = base->info.num_outputs; + uint i; + for (i = 0; i < n; i++) { + switch (sem_name[i]) { + case TGSI_SEMANTIC_COLOR: + { + uint cbuf = sem_index[i]; + + assert(sizeof(quad->output.color[cbuf]) == + sizeof(machine->Outputs[i])); + + /* copy float[4][4] result */ + memcpy(quad->output.color[cbuf], + &machine->Outputs[i], + sizeof(quad->output.color[0]) ); + } + break; + case TGSI_SEMANTIC_POSITION: + { + uint j; + + for (j = 0; j < 4; j++) + quad->output.depth[j] = machine->Outputs[i].xyzw[2].f[j]; + } + break; + case TGSI_SEMANTIC_STENCIL: + { + uint j; + + for (j = 0; j < 4; j++) + quad->output.stencil[j] = (unsigned)machine->Outputs[i].xyzw[1].f[j]; + } + break; + } + } + } + + return TRUE; +} + + +static void +exec_delete( struct sp_fragment_shader *base ) +{ + FREE((void *) base->shader.tokens); + FREE(base); +} + + +struct sp_fragment_shader * +softpipe_create_fs_exec(struct softpipe_context *softpipe, + const struct pipe_shader_state *templ) +{ + struct sp_exec_fragment_shader *shader; + + /* Decide whether we'll be codegenerating this shader and if so do + * that now. + */ + + shader = CALLOC_STRUCT(sp_exec_fragment_shader); + if (!shader) + return NULL; + + /* we need to keep a local copy of the tokens */ + shader->base.shader.tokens = tgsi_dup_tokens(templ->tokens); + shader->base.prepare = exec_prepare; + shader->base.run = exec_run; + shader->base.delete = exec_delete; + + return &shader->base; +} diff --git a/src/gallium/drivers/softpipe/sp_fs_sse.c b/src/gallium/drivers/softpipe/sp_fs_sse.c new file mode 100644 index 0000000..5b18cd0 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_fs_sse.c @@ -0,0 +1,249 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Execute fragment shader using runtime SSE code generation. + */ + +#include "sp_context.h" +#include "sp_state.h" +#include "sp_fs.h" +#include "sp_quad.h" + +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_memory.h" +#include "tgsi/tgsi_exec.h" +#include "tgsi/tgsi_sse2.h" + + +#if defined(PIPE_ARCH_X86) + +#include "rtasm/rtasm_x86sse.h" + + + +/** + * Subclass of sp_fragment_shader + */ +struct sp_sse_fragment_shader +{ + struct sp_fragment_shader base; + struct x86_function sse2_program; + tgsi_sse2_fs_function func; + float immediates[TGSI_EXEC_NUM_IMMEDIATES][4]; +}; + + +/** cast wrapper */ +static INLINE struct sp_sse_fragment_shader * +sp_sse_fragment_shader(const struct sp_fragment_shader *base) +{ + return (struct sp_sse_fragment_shader *) base; +} + + +static void +fs_sse_prepare( const struct sp_fragment_shader *base, + struct tgsi_exec_machine *machine, + struct tgsi_sampler **samplers ) +{ + machine->Samplers = samplers; +} + + + +/** + * Compute quad X,Y,Z,W for the four fragments in a quad. + * + * This should really be part of the compiled shader. + */ +static void +setup_pos_vector(const struct tgsi_interp_coef *coef, + float x, float y, + struct tgsi_exec_vector *quadpos) +{ + uint chan; + /* do X */ + quadpos->xyzw[0].f[0] = x; + quadpos->xyzw[0].f[1] = x + 1; + quadpos->xyzw[0].f[2] = x; + quadpos->xyzw[0].f[3] = x + 1; + + /* do Y */ + quadpos->xyzw[1].f[0] = y; + quadpos->xyzw[1].f[1] = y; + quadpos->xyzw[1].f[2] = y + 1; + quadpos->xyzw[1].f[3] = y + 1; + + /* do Z and W for all fragments in the quad */ + for (chan = 2; chan < 4; chan++) { + const float dadx = coef->dadx[chan]; + const float dady = coef->dady[chan]; + const float a0 = coef->a0[chan] + dadx * x + dady * y; + quadpos->xyzw[chan].f[0] = a0; + quadpos->xyzw[chan].f[1] = a0 + dadx; + quadpos->xyzw[chan].f[2] = a0 + dady; + quadpos->xyzw[chan].f[3] = a0 + dadx + dady; + } +} + + +/* TODO: codegenerate the whole run function, skip this wrapper. + * TODO: break dependency on tgsi_exec_machine struct + * TODO: push Position calculation into the generated shader + * TODO: process >1 quad at a time + */ +static unsigned +fs_sse_run( const struct sp_fragment_shader *base, + struct tgsi_exec_machine *machine, + struct quad_header *quad ) +{ + struct sp_sse_fragment_shader *shader = sp_sse_fragment_shader(base); + + /* Compute X, Y, Z, W vals for this quad -- place in temp[0] for now */ + setup_pos_vector(quad->posCoef, + (float)quad->input.x0, (float)quad->input.y0, + machine->Temps); + + /* init kill mask */ + tgsi_set_kill_mask(machine, 0x0); + tgsi_set_exec_mask(machine, 1, 1, 1, 1); + + shader->func( machine, + (const float (*)[4])machine->Consts[0], + (const float (*)[4])shader->immediates, + machine->InterpCoefs + /*, &machine->QuadPos*/ + ); + + quad->inout.mask &= ~(machine->Temps[TGSI_EXEC_TEMP_KILMASK_I].xyzw[TGSI_EXEC_TEMP_KILMASK_C].u[0]); + if (quad->inout.mask == 0) + return FALSE; + + /* store outputs */ + { + const ubyte *sem_name = base->info.output_semantic_name; + const ubyte *sem_index = base->info.output_semantic_index; + const uint n = base->info.num_outputs; + uint i; + for (i = 0; i < n; i++) { + switch (sem_name[i]) { + case TGSI_SEMANTIC_COLOR: + { + uint cbuf = sem_index[i]; + + assert(sizeof(quad->output.color[cbuf]) == + sizeof(machine->Outputs[i])); + + /* copy float[4][4] result */ + memcpy(quad->output.color[cbuf], + &machine->Outputs[i], + sizeof(quad->output.color[0]) ); + } + break; + case TGSI_SEMANTIC_POSITION: + { + uint j; + for (j = 0; j < 4; j++) + quad->output.depth[j] = machine->Outputs[i].xyzw[2].f[j]; + } + break; + case TGSI_SEMANTIC_STENCIL: + { + uint j; + for (j = 0; j < 4; j++) + quad->output.stencil[j] = machine->Outputs[i].xyzw[1].f[j]; + } + break; + } + } + } + + return TRUE; +} + + +static void +fs_sse_delete( struct sp_fragment_shader *base ) +{ + struct sp_sse_fragment_shader *shader = sp_sse_fragment_shader(base); + + x86_release_func( &shader->sse2_program ); + FREE(shader); +} + + +struct sp_fragment_shader * +softpipe_create_fs_sse(struct softpipe_context *softpipe, + const struct pipe_shader_state *templ) +{ + struct sp_sse_fragment_shader *shader; + + if (!softpipe->use_sse) + return NULL; + + shader = CALLOC_STRUCT(sp_sse_fragment_shader); + if (!shader) + return NULL; + + x86_init_func( &shader->sse2_program ); + + if (!tgsi_emit_sse2( templ->tokens, &shader->sse2_program, + shader->immediates, FALSE )) { + FREE(shader); + return NULL; + } + + shader->func = (tgsi_sse2_fs_function) x86_get_func( &shader->sse2_program ); + if (!shader->func) { + x86_release_func( &shader->sse2_program ); + FREE(shader); + return NULL; + } + + shader->base.shader.tokens = NULL; /* don't hold reference to templ->tokens */ + shader->base.prepare = fs_sse_prepare; + shader->base.run = fs_sse_run; + shader->base.delete = fs_sse_delete; + + return &shader->base; +} + + +#else + +/* Maybe put this variant in the header file. + */ +struct sp_fragment_shader * +softpipe_create_fs_sse(struct softpipe_context *softpipe, + const struct pipe_shader_state *templ) +{ + return NULL; +} + +#endif diff --git a/src/gallium/drivers/softpipe/sp_limits.h b/src/gallium/drivers/softpipe/sp_limits.h new file mode 100644 index 0000000..a7a24c9 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_limits.h @@ -0,0 +1,42 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL THE 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 SP_LIMITS_H +#define SP_LIMITS_H + + + +#define SP_MAX_TEXTURE_2D_LEVELS 15 /* 16K x 16K */ +#define SP_MAX_TEXTURE_3D_LEVELS 9 /* 512 x 512 x 512 */ + + +/** Max surface size */ +#define MAX_WIDTH (1 << (SP_MAX_TEXTURE_2D_LEVELS - 1)) +#define MAX_HEIGHT (1 << (SP_MAX_TEXTURE_2D_LEVELS - 1)) + + +#endif /* SP_LIMITS_H */ diff --git a/src/gallium/drivers/softpipe/sp_prim_vbuf.c b/src/gallium/drivers/softpipe/sp_prim_vbuf.c new file mode 100644 index 0000000..c60249d --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_prim_vbuf.c @@ -0,0 +1,602 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Interface between 'draw' module's output and the softpipe rasterizer/setup + * code. When the 'draw' module has finished filling a vertex buffer, the + * draw_arrays() functions below will be called. Loop over the vertices and + * call the point/line/tri setup functions. + * + * Authors + * Brian Paul + */ + + +#include "sp_context.h" +#include "sp_setup.h" +#include "sp_state.h" +#include "sp_prim_vbuf.h" +#include "draw/draw_context.h" +#include "draw/draw_vbuf.h" +#include "util/u_memory.h" +#include "util/u_prim.h" + + +#define SP_MAX_VBUF_INDEXES 1024 +#define SP_MAX_VBUF_SIZE 4096 + +typedef const float (*cptrf4)[4]; + +/** + * Subclass of vbuf_render. + */ +struct softpipe_vbuf_render +{ + struct vbuf_render base; + struct softpipe_context *softpipe; + struct setup_context *setup; + + uint prim; + uint vertex_size; + uint nr_vertices; + uint vertex_buffer_size; + void *vertex_buffer; +}; + + +/** cast wrapper */ +static struct softpipe_vbuf_render * +softpipe_vbuf_render(struct vbuf_render *vbr) +{ + return (struct softpipe_vbuf_render *) vbr; +} + + +/** This tells the draw module about our desired vertex layout */ +static const struct vertex_info * +sp_vbuf_get_vertex_info(struct vbuf_render *vbr) +{ + struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr); + return softpipe_get_vbuf_vertex_info(cvbr->softpipe); +} + + +static boolean +sp_vbuf_allocate_vertices(struct vbuf_render *vbr, + ushort vertex_size, ushort nr_vertices) +{ + struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr); + unsigned size = vertex_size * nr_vertices; + + if (cvbr->vertex_buffer_size < size) { + align_free(cvbr->vertex_buffer); + cvbr->vertex_buffer = align_malloc(size, 16); + cvbr->vertex_buffer_size = size; + } + + cvbr->vertex_size = vertex_size; + cvbr->nr_vertices = nr_vertices; + + return cvbr->vertex_buffer != NULL; +} + + +static void +sp_vbuf_release_vertices(struct vbuf_render *vbr) +{ + /* keep the old allocation for next time */ +} + + +static void * +sp_vbuf_map_vertices(struct vbuf_render *vbr) +{ + struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr); + return cvbr->vertex_buffer; +} + + +static void +sp_vbuf_unmap_vertices(struct vbuf_render *vbr, + ushort min_index, + ushort max_index ) +{ + struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr); + assert( cvbr->vertex_buffer_size >= (max_index+1) * cvbr->vertex_size ); + (void) cvbr; + /* do nothing */ +} + + +static boolean +sp_vbuf_set_primitive(struct vbuf_render *vbr, unsigned prim) +{ + struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr); + struct setup_context *setup_ctx = cvbr->setup; + + sp_setup_prepare( setup_ctx ); + + cvbr->softpipe->reduced_prim = u_reduced_prim(prim); + cvbr->prim = prim; + return TRUE; +} + + +static INLINE cptrf4 get_vert( const void *vertex_buffer, + int index, + int stride ) +{ + return (cptrf4)((char *)vertex_buffer + index * stride); +} + + +/** + * draw elements / indexed primitives + */ +static void +sp_vbuf_draw_elements(struct vbuf_render *vbr, const ushort *indices, uint nr) +{ + struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr); + struct softpipe_context *softpipe = cvbr->softpipe; + const unsigned stride = softpipe->vertex_info_vbuf.size * sizeof(float); + const void *vertex_buffer = cvbr->vertex_buffer; + struct setup_context *setup = cvbr->setup; + const boolean flatshade_first = softpipe->rasterizer->flatshade_first; + unsigned i; + + switch (cvbr->prim) { + case PIPE_PRIM_POINTS: + for (i = 0; i < nr; i++) { + sp_setup_point( setup, + get_vert(vertex_buffer, indices[i-0], stride) ); + } + break; + + case PIPE_PRIM_LINES: + for (i = 1; i < nr; i += 2) { + sp_setup_line( setup, + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + break; + + case PIPE_PRIM_LINE_STRIP: + for (i = 1; i < nr; i ++) { + sp_setup_line( setup, + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + break; + + case PIPE_PRIM_LINE_LOOP: + for (i = 1; i < nr; i ++) { + sp_setup_line( setup, + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + if (nr) { + sp_setup_line( setup, + get_vert(vertex_buffer, indices[nr-1], stride), + get_vert(vertex_buffer, indices[0], stride) ); + } + break; + + case PIPE_PRIM_TRIANGLES: + for (i = 2; i < nr; i += 3) { + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + break; + + case PIPE_PRIM_TRIANGLE_STRIP: + if (flatshade_first) { + for (i = 2; i < nr; i += 1) { + /* emit first triangle vertex as first triangle vertex */ + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i+(i&1)-1], stride), + get_vert(vertex_buffer, indices[i-(i&1)], stride) ); + + } + } + else { + for (i = 2; i < nr; i += 1) { + /* emit last triangle vertex as last triangle vertex */ + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[i+(i&1)-2], stride), + get_vert(vertex_buffer, indices[i-(i&1)-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + } + break; + + case PIPE_PRIM_TRIANGLE_FAN: + if (flatshade_first) { + for (i = 2; i < nr; i += 1) { + /* emit first non-spoke vertex as first vertex */ + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride), + get_vert(vertex_buffer, indices[0], stride) ); + } + } + else { + for (i = 2; i < nr; i += 1) { + /* emit last non-spoke vertex as last vertex */ + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[0], stride), + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + } + break; + + case PIPE_PRIM_QUADS: + /* GL quads don't follow provoking vertex convention */ + if (flatshade_first) { + /* emit last quad vertex as first triangle vertex */ + for (i = 3; i < nr; i += 4) { + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[i-0], stride), + get_vert(vertex_buffer, indices[i-3], stride), + get_vert(vertex_buffer, indices[i-2], stride) ); + + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[i-0], stride), + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i-1], stride) ); + } + } + else { + /* emit last quad vertex as last triangle vertex */ + for (i = 3; i < nr; i += 4) { + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[i-3], stride), + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + } + break; + + case PIPE_PRIM_QUAD_STRIP: + /* GL quad strips don't follow provoking vertex convention */ + if (flatshade_first) { + /* emit last quad vertex as first triangle vertex */ + for (i = 3; i < nr; i += 2) { + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[i-0], stride), + get_vert(vertex_buffer, indices[i-3], stride), + get_vert(vertex_buffer, indices[i-2], stride) ); + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[i-0], stride), + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-3], stride) ); + } + } + else { + /* emit last quad vertex as last triangle vertex */ + for (i = 3; i < nr; i += 2) { + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[i-3], stride), + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-3], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + } + break; + + case PIPE_PRIM_POLYGON: + /* Almost same as tri fan but the _first_ vertex specifies the flat + * shading color. + */ + if (flatshade_first) { + /* emit first polygon vertex as first triangle vertex */ + for (i = 2; i < nr; i += 1) { + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[0], stride), + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + } + } + else { + /* emit first polygon vertex as last triangle vertex */ + for (i = 2; i < nr; i += 1) { + sp_setup_tri( setup, + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride), + get_vert(vertex_buffer, indices[0], stride) ); + } + } + break; + + default: + assert(0); + } +} + + +/** + * This function is hit when the draw module is working in pass-through mode. + * It's up to us to convert the vertex array into point/line/tri prims. + */ +static void +sp_vbuf_draw_arrays(struct vbuf_render *vbr, uint start, uint nr) +{ + struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr); + struct softpipe_context *softpipe = cvbr->softpipe; + struct setup_context *setup = cvbr->setup; + const unsigned stride = softpipe->vertex_info_vbuf.size * sizeof(float); + const void *vertex_buffer = + (void *) get_vert(cvbr->vertex_buffer, start, stride); + const boolean flatshade_first = softpipe->rasterizer->flatshade_first; + unsigned i; + + switch (cvbr->prim) { + case PIPE_PRIM_POINTS: + for (i = 0; i < nr; i++) { + sp_setup_point( setup, + get_vert(vertex_buffer, i-0, stride) ); + } + break; + + case PIPE_PRIM_LINES: + for (i = 1; i < nr; i += 2) { + sp_setup_line( setup, + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + break; + + case PIPE_PRIM_LINE_STRIP: + for (i = 1; i < nr; i ++) { + sp_setup_line( setup, + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + break; + + case PIPE_PRIM_LINE_LOOP: + for (i = 1; i < nr; i ++) { + sp_setup_line( setup, + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + if (nr) { + sp_setup_line( setup, + get_vert(vertex_buffer, nr-1, stride), + get_vert(vertex_buffer, 0, stride) ); + } + break; + + case PIPE_PRIM_TRIANGLES: + for (i = 2; i < nr; i += 3) { + sp_setup_tri( setup, + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + break; + + case PIPE_PRIM_TRIANGLE_STRIP: + if (flatshade_first) { + for (i = 2; i < nr; i++) { + /* emit first triangle vertex as first triangle vertex */ + sp_setup_tri( setup, + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i+(i&1)-1, stride), + get_vert(vertex_buffer, i-(i&1), stride) ); + } + } + else { + for (i = 2; i < nr; i++) { + /* emit last triangle vertex as last triangle vertex */ + sp_setup_tri( setup, + get_vert(vertex_buffer, i+(i&1)-2, stride), + get_vert(vertex_buffer, i-(i&1)-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + } + break; + + case PIPE_PRIM_TRIANGLE_FAN: + if (flatshade_first) { + for (i = 2; i < nr; i += 1) { + /* emit first non-spoke vertex as first vertex */ + sp_setup_tri( setup, + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride), + get_vert(vertex_buffer, 0, stride) ); + } + } + else { + for (i = 2; i < nr; i += 1) { + /* emit last non-spoke vertex as last vertex */ + sp_setup_tri( setup, + get_vert(vertex_buffer, 0, stride), + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + } + break; + + case PIPE_PRIM_QUADS: + /* GL quads don't follow provoking vertex convention */ + if (flatshade_first) { + /* emit last quad vertex as first triangle vertex */ + for (i = 3; i < nr; i += 4) { + sp_setup_tri( setup, + get_vert(vertex_buffer, i-0, stride), + get_vert(vertex_buffer, i-3, stride), + get_vert(vertex_buffer, i-2, stride) ); + sp_setup_tri( setup, + get_vert(vertex_buffer, i-0, stride), + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i-1, stride) ); + } + } + else { + /* emit last quad vertex as last triangle vertex */ + for (i = 3; i < nr; i += 4) { + sp_setup_tri( setup, + get_vert(vertex_buffer, i-3, stride), + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i-0, stride) ); + sp_setup_tri( setup, + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + } + break; + + case PIPE_PRIM_QUAD_STRIP: + /* GL quad strips don't follow provoking vertex convention */ + if (flatshade_first) { + /* emit last quad vertex as first triangle vertex */ + for (i = 3; i < nr; i += 2) { + sp_setup_tri( setup, + get_vert(vertex_buffer, i-0, stride), + get_vert(vertex_buffer, i-3, stride), + get_vert(vertex_buffer, i-2, stride) ); + sp_setup_tri( setup, + get_vert(vertex_buffer, i-0, stride), + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-3, stride) ); + } + } + else { + /* emit last quad vertex as last triangle vertex */ + for (i = 3; i < nr; i += 2) { + sp_setup_tri( setup, + get_vert(vertex_buffer, i-3, stride), + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i-0, stride) ); + sp_setup_tri( setup, + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-3, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + } + break; + + case PIPE_PRIM_POLYGON: + /* Almost same as tri fan but the _first_ vertex specifies the flat + * shading color. + */ + if (flatshade_first) { + /* emit first polygon vertex as first triangle vertex */ + for (i = 2; i < nr; i += 1) { + sp_setup_tri( setup, + get_vert(vertex_buffer, 0, stride), + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); + } + } + else { + /* emit first polygon vertex as last triangle vertex */ + for (i = 2; i < nr; i += 1) { + sp_setup_tri( setup, + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride), + get_vert(vertex_buffer, 0, stride) ); + } + } + break; + + default: + assert(0); + } +} + +static void +sp_vbuf_so_info(struct vbuf_render *vbr, uint primitives, uint vertices) +{ + struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr); + struct softpipe_context *softpipe = cvbr->softpipe; + unsigned i; + + for (i = 0; i < softpipe->so_target.num_buffers; ++i) { + softpipe->so_target.so_count[i] += vertices; + } + + softpipe->so_stats.num_primitives_written = primitives; + softpipe->so_stats.primitives_storage_needed = + vertices * 4 /*sizeof(float|int32)*/ * 4 /*x,y,z,w*/; +} + + +static void +sp_vbuf_destroy(struct vbuf_render *vbr) +{ + struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr); + if (cvbr->vertex_buffer) + align_free(cvbr->vertex_buffer); + sp_setup_destroy_context(cvbr->setup); + FREE(cvbr); +} + + +/** + * Create the post-transform vertex handler for the given context. + */ +struct vbuf_render * +sp_create_vbuf_backend(struct softpipe_context *sp) +{ + struct softpipe_vbuf_render *cvbr = CALLOC_STRUCT(softpipe_vbuf_render); + + assert(sp->draw); + + cvbr->base.max_indices = SP_MAX_VBUF_INDEXES; + cvbr->base.max_vertex_buffer_bytes = SP_MAX_VBUF_SIZE; + + cvbr->base.get_vertex_info = sp_vbuf_get_vertex_info; + cvbr->base.allocate_vertices = sp_vbuf_allocate_vertices; + cvbr->base.map_vertices = sp_vbuf_map_vertices; + cvbr->base.unmap_vertices = sp_vbuf_unmap_vertices; + cvbr->base.set_primitive = sp_vbuf_set_primitive; + cvbr->base.draw_elements = sp_vbuf_draw_elements; + cvbr->base.draw_arrays = sp_vbuf_draw_arrays; + cvbr->base.release_vertices = sp_vbuf_release_vertices; + cvbr->base.set_stream_output_info = sp_vbuf_so_info; + cvbr->base.destroy = sp_vbuf_destroy; + + cvbr->softpipe = sp; + + cvbr->setup = sp_setup_create_context(cvbr->softpipe); + + return &cvbr->base; +} diff --git a/src/gallium/drivers/softpipe/sp_prim_vbuf.h b/src/gallium/drivers/softpipe/sp_prim_vbuf.h new file mode 100644 index 0000000..ad01cc2 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_prim_vbuf.h @@ -0,0 +1,38 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef SP_VBUF_H +#define SP_VBUF_H + + +struct softpipe_context; + +extern struct vbuf_render * +sp_create_vbuf_backend(struct softpipe_context *softpipe); + + +#endif /* SP_VBUF_H */ diff --git a/src/gallium/drivers/softpipe/sp_public.h b/src/gallium/drivers/softpipe/sp_public.h new file mode 100644 index 0000000..62d0903 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_public.h @@ -0,0 +1,10 @@ +#ifndef SP_PUBLIC_H +#define SP_PUBLIC_H + +struct pipe_screen; +struct sw_winsys; + +struct pipe_screen * +softpipe_create_screen(struct sw_winsys *winsys); + +#endif diff --git a/src/gallium/drivers/softpipe/sp_quad.h b/src/gallium/drivers/softpipe/sp_quad.h new file mode 100644 index 0000000..e745aa8 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_quad.h @@ -0,0 +1,107 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef SP_QUAD_H +#define SP_QUAD_H + +#include "pipe/p_state.h" +#include "tgsi/tgsi_exec.h" + + +#define QUAD_PRIM_POINT 1 +#define QUAD_PRIM_LINE 2 +#define QUAD_PRIM_TRI 3 + + +/* The rasterizer generates 2x2 quads of fragment and feeds them to + * the current fp_machine (see below). + * Remember that Y=0=top with Y increasing down the window. + */ +#define QUAD_TOP_LEFT 0 +#define QUAD_TOP_RIGHT 1 +#define QUAD_BOTTOM_LEFT 2 +#define QUAD_BOTTOM_RIGHT 3 + +#define MASK_TOP_LEFT (1 << QUAD_TOP_LEFT) +#define MASK_TOP_RIGHT (1 << QUAD_TOP_RIGHT) +#define MASK_BOTTOM_LEFT (1 << QUAD_BOTTOM_LEFT) +#define MASK_BOTTOM_RIGHT (1 << QUAD_BOTTOM_RIGHT) +#define MASK_ALL 0xf + + +/** + * Quad stage inputs (pos, coverage, front/back face, etc) + */ +struct quad_header_input +{ + int x0, y0; /**< quad window pos, always even */ + float coverage[QUAD_SIZE]; /**< fragment coverage for antialiasing */ + unsigned facing:1; /**< Front (0) or back (1) facing? */ + unsigned prim:2; /**< QUAD_PRIM_POINT, LINE, TRI */ +}; + + +/** + * Quad stage inputs/outputs. + */ +struct quad_header_inout +{ + unsigned mask:4; +}; + + +/** + * Quad stage outputs (color & depth). + */ +struct quad_header_output +{ + /** colors in SOA format (rrrr, gggg, bbbb, aaaa) */ + float color[PIPE_MAX_COLOR_BUFS][NUM_CHANNELS][QUAD_SIZE]; + float depth[QUAD_SIZE]; + uint8_t stencil[QUAD_SIZE]; +}; + + +/** + * Encodes everything we need to know about a 2x2 pixel block. Uses + * "Channel-Serial" or "SoA" layout. + */ +struct quad_header { + struct quad_header_input input; + struct quad_header_inout inout; + struct quad_header_output output; + + /* Redundant/duplicated: + */ + const struct tgsi_interp_coef *posCoef; + const struct tgsi_interp_coef *coef; +}; + +#endif /* SP_QUAD_H */ diff --git a/src/gallium/drivers/softpipe/sp_quad_blend.c b/src/gallium/drivers/softpipe/sp_quad_blend.c new file mode 100644 index 0000000..6af1b2d --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_quad_blend.c @@ -0,0 +1,1061 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * quad blending + * \author Brian Paul + */ + +#include "pipe/p_defines.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_format.h" +#include "sp_context.h" +#include "sp_quad.h" +#include "sp_tile_cache.h" +#include "sp_quad_pipe.h" + + +#define VEC4_COPY(DST, SRC) \ +do { \ + DST[0] = SRC[0]; \ + DST[1] = SRC[1]; \ + DST[2] = SRC[2]; \ + DST[3] = SRC[3]; \ +} while(0) + +#define VEC4_SCALAR(DST, SRC) \ +do { \ + DST[0] = SRC; \ + DST[1] = SRC; \ + DST[2] = SRC; \ + DST[3] = SRC; \ +} while(0) + +#define VEC4_ADD(R, A, B) \ +do { \ + R[0] = A[0] + B[0]; \ + R[1] = A[1] + B[1]; \ + R[2] = A[2] + B[2]; \ + R[3] = A[3] + B[3]; \ +} while (0) + +#define VEC4_SUB(R, A, B) \ +do { \ + R[0] = A[0] - B[0]; \ + R[1] = A[1] - B[1]; \ + R[2] = A[2] - B[2]; \ + R[3] = A[3] - B[3]; \ +} while (0) + +/** Add and limit result to ceiling of 1.0 */ +#define VEC4_ADD_SAT(R, A, B) \ +do { \ + R[0] = A[0] + B[0]; if (R[0] > 1.0f) R[0] = 1.0f; \ + R[1] = A[1] + B[1]; if (R[1] > 1.0f) R[1] = 1.0f; \ + R[2] = A[2] + B[2]; if (R[2] > 1.0f) R[2] = 1.0f; \ + R[3] = A[3] + B[3]; if (R[3] > 1.0f) R[3] = 1.0f; \ +} while (0) + +/** Subtract and limit result to floor of 0.0 */ +#define VEC4_SUB_SAT(R, A, B) \ +do { \ + R[0] = A[0] - B[0]; if (R[0] < 0.0f) R[0] = 0.0f; \ + R[1] = A[1] - B[1]; if (R[1] < 0.0f) R[1] = 0.0f; \ + R[2] = A[2] - B[2]; if (R[2] < 0.0f) R[2] = 0.0f; \ + R[3] = A[3] - B[3]; if (R[3] < 0.0f) R[3] = 0.0f; \ +} while (0) + +#define VEC4_MUL(R, A, B) \ +do { \ + R[0] = A[0] * B[0]; \ + R[1] = A[1] * B[1]; \ + R[2] = A[2] * B[2]; \ + R[3] = A[3] * B[3]; \ +} while (0) + +#define VEC4_MIN(R, A, B) \ +do { \ + R[0] = (A[0] < B[0]) ? A[0] : B[0]; \ + R[1] = (A[1] < B[1]) ? A[1] : B[1]; \ + R[2] = (A[2] < B[2]) ? A[2] : B[2]; \ + R[3] = (A[3] < B[3]) ? A[3] : B[3]; \ +} while (0) + +#define VEC4_MAX(R, A, B) \ +do { \ + R[0] = (A[0] > B[0]) ? A[0] : B[0]; \ + R[1] = (A[1] > B[1]) ? A[1] : B[1]; \ + R[2] = (A[2] > B[2]) ? A[2] : B[2]; \ + R[3] = (A[3] > B[3]) ? A[3] : B[3]; \ +} while (0) + + + +static void +logicop_quad(struct quad_stage *qs, + float (*quadColor)[4], + float (*dest)[4]) +{ + struct softpipe_context *softpipe = qs->softpipe; + ubyte src[4][4], dst[4][4], res[4][4]; + uint *src4 = (uint *) src; + uint *dst4 = (uint *) dst; + uint *res4 = (uint *) res; + uint j; + + + /* convert to ubyte */ + for (j = 0; j < 4; j++) { /* loop over R,G,B,A channels */ + dst[j][0] = float_to_ubyte(dest[j][0]); /* P0 */ + dst[j][1] = float_to_ubyte(dest[j][1]); /* P1 */ + dst[j][2] = float_to_ubyte(dest[j][2]); /* P2 */ + dst[j][3] = float_to_ubyte(dest[j][3]); /* P3 */ + + src[j][0] = float_to_ubyte(quadColor[j][0]); /* P0 */ + src[j][1] = float_to_ubyte(quadColor[j][1]); /* P1 */ + src[j][2] = float_to_ubyte(quadColor[j][2]); /* P2 */ + src[j][3] = float_to_ubyte(quadColor[j][3]); /* P3 */ + } + + switch (softpipe->blend->logicop_func) { + case PIPE_LOGICOP_CLEAR: + for (j = 0; j < 4; j++) + res4[j] = 0; + break; + case PIPE_LOGICOP_NOR: + for (j = 0; j < 4; j++) + res4[j] = ~(src4[j] | dst4[j]); + break; + case PIPE_LOGICOP_AND_INVERTED: + for (j = 0; j < 4; j++) + res4[j] = ~src4[j] & dst4[j]; + break; + case PIPE_LOGICOP_COPY_INVERTED: + for (j = 0; j < 4; j++) + res4[j] = ~src4[j]; + break; + case PIPE_LOGICOP_AND_REVERSE: + for (j = 0; j < 4; j++) + res4[j] = src4[j] & ~dst4[j]; + break; + case PIPE_LOGICOP_INVERT: + for (j = 0; j < 4; j++) + res4[j] = ~dst4[j]; + break; + case PIPE_LOGICOP_XOR: + for (j = 0; j < 4; j++) + res4[j] = dst4[j] ^ src4[j]; + break; + case PIPE_LOGICOP_NAND: + for (j = 0; j < 4; j++) + res4[j] = ~(src4[j] & dst4[j]); + break; + case PIPE_LOGICOP_AND: + for (j = 0; j < 4; j++) + res4[j] = src4[j] & dst4[j]; + break; + case PIPE_LOGICOP_EQUIV: + for (j = 0; j < 4; j++) + res4[j] = ~(src4[j] ^ dst4[j]); + break; + case PIPE_LOGICOP_NOOP: + for (j = 0; j < 4; j++) + res4[j] = dst4[j]; + break; + case PIPE_LOGICOP_OR_INVERTED: + for (j = 0; j < 4; j++) + res4[j] = ~src4[j] | dst4[j]; + break; + case PIPE_LOGICOP_COPY: + for (j = 0; j < 4; j++) + res4[j] = src4[j]; + break; + case PIPE_LOGICOP_OR_REVERSE: + for (j = 0; j < 4; j++) + res4[j] = src4[j] | ~dst4[j]; + break; + case PIPE_LOGICOP_OR: + for (j = 0; j < 4; j++) + res4[j] = src4[j] | dst4[j]; + break; + case PIPE_LOGICOP_SET: + for (j = 0; j < 4; j++) + res4[j] = ~0; + break; + default: + assert(0 && "invalid logicop mode"); + } + + for (j = 0; j < 4; j++) { + quadColor[j][0] = ubyte_to_float(res[j][0]); + quadColor[j][1] = ubyte_to_float(res[j][1]); + quadColor[j][2] = ubyte_to_float(res[j][2]); + quadColor[j][3] = ubyte_to_float(res[j][3]); + } +} + + + +/** + * Do blending for a 2x2 quad for one color buffer. + * \param quadColor the incoming quad colors + * \param dest the destination/framebuffer quad colors + * \param blend_index which set of blending terms to use + * \param has_dst_alpha does the dest color buffer have an alpha channel? + */ +static void +blend_quad(struct quad_stage *qs, + float (*quadColor)[4], + float (*dest)[4], + unsigned blend_index, + boolean has_dst_alpha) +{ + static const float zero[4] = { 0, 0, 0, 0 }; + static const float one[4] = { 1, 1, 1, 1 }; + struct softpipe_context *softpipe = qs->softpipe; + float source[4][QUAD_SIZE] = { { 0 } }; + + /* + * Compute src/first term RGB + */ + switch (softpipe->blend->rt[blend_index].rgb_src_factor) { + case PIPE_BLENDFACTOR_ONE: + VEC4_COPY(source[0], quadColor[0]); /* R */ + VEC4_COPY(source[1], quadColor[1]); /* G */ + VEC4_COPY(source[2], quadColor[2]); /* B */ + break; + case PIPE_BLENDFACTOR_SRC_COLOR: + VEC4_MUL(source[0], quadColor[0], quadColor[0]); /* R */ + VEC4_MUL(source[1], quadColor[1], quadColor[1]); /* G */ + VEC4_MUL(source[2], quadColor[2], quadColor[2]); /* B */ + break; + case PIPE_BLENDFACTOR_SRC_ALPHA: + { + const float *alpha = quadColor[3]; + VEC4_MUL(source[0], quadColor[0], alpha); /* R */ + VEC4_MUL(source[1], quadColor[1], alpha); /* G */ + VEC4_MUL(source[2], quadColor[2], alpha); /* B */ + } + break; + case PIPE_BLENDFACTOR_DST_COLOR: + VEC4_MUL(source[0], quadColor[0], dest[0]); /* R */ + VEC4_MUL(source[1], quadColor[1], dest[1]); /* G */ + VEC4_MUL(source[2], quadColor[2], dest[2]); /* B */ + break; + case PIPE_BLENDFACTOR_DST_ALPHA: + if (has_dst_alpha) { + const float *alpha = dest[3]; + VEC4_MUL(source[0], quadColor[0], alpha); /* R */ + VEC4_MUL(source[1], quadColor[1], alpha); /* G */ + VEC4_MUL(source[2], quadColor[2], alpha); /* B */ + } + else { + VEC4_COPY(source[0], quadColor[0]); /* R */ + VEC4_COPY(source[1], quadColor[1]); /* G */ + VEC4_COPY(source[2], quadColor[2]); /* B */ + } + break; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + if (has_dst_alpha) { + const float *alpha = quadColor[3]; + float diff[4], temp[4]; + VEC4_SUB(diff, one, dest[3]); + VEC4_MIN(temp, alpha, diff); + VEC4_MUL(source[0], quadColor[0], temp); /* R */ + VEC4_MUL(source[1], quadColor[1], temp); /* G */ + VEC4_MUL(source[2], quadColor[2], temp); /* B */ + } + else { + VEC4_COPY(source[0], zero); /* R */ + VEC4_COPY(source[1], zero); /* G */ + VEC4_COPY(source[2], zero); /* B */ + } + break; + case PIPE_BLENDFACTOR_CONST_COLOR: + { + float comp[4]; + VEC4_SCALAR(comp, softpipe->blend_color.color[0]); /* R */ + VEC4_MUL(source[0], quadColor[0], comp); /* R */ + VEC4_SCALAR(comp, softpipe->blend_color.color[1]); /* G */ + VEC4_MUL(source[1], quadColor[1], comp); /* G */ + VEC4_SCALAR(comp, softpipe->blend_color.color[2]); /* B */ + VEC4_MUL(source[2], quadColor[2], comp); /* B */ + } + break; + case PIPE_BLENDFACTOR_CONST_ALPHA: + { + float alpha[4]; + VEC4_SCALAR(alpha, softpipe->blend_color.color[3]); + VEC4_MUL(source[0], quadColor[0], alpha); /* R */ + VEC4_MUL(source[1], quadColor[1], alpha); /* G */ + VEC4_MUL(source[2], quadColor[2], alpha); /* B */ + } + break; + case PIPE_BLENDFACTOR_SRC1_COLOR: + assert(0); /* to do */ + break; + case PIPE_BLENDFACTOR_SRC1_ALPHA: + assert(0); /* to do */ + break; + case PIPE_BLENDFACTOR_ZERO: + VEC4_COPY(source[0], zero); /* R */ + VEC4_COPY(source[1], zero); /* G */ + VEC4_COPY(source[2], zero); /* B */ + break; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + { + float inv_comp[4]; + VEC4_SUB(inv_comp, one, quadColor[0]); /* R */ + VEC4_MUL(source[0], quadColor[0], inv_comp); /* R */ + VEC4_SUB(inv_comp, one, quadColor[1]); /* G */ + VEC4_MUL(source[1], quadColor[1], inv_comp); /* G */ + VEC4_SUB(inv_comp, one, quadColor[2]); /* B */ + VEC4_MUL(source[2], quadColor[2], inv_comp); /* B */ + } + break; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + { + float inv_alpha[4]; + VEC4_SUB(inv_alpha, one, quadColor[3]); + VEC4_MUL(source[0], quadColor[0], inv_alpha); /* R */ + VEC4_MUL(source[1], quadColor[1], inv_alpha); /* G */ + VEC4_MUL(source[2], quadColor[2], inv_alpha); /* B */ + } + break; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + if (has_dst_alpha) { + float inv_alpha[4]; + VEC4_SUB(inv_alpha, one, dest[3]); + VEC4_MUL(source[0], quadColor[0], inv_alpha); /* R */ + VEC4_MUL(source[1], quadColor[1], inv_alpha); /* G */ + VEC4_MUL(source[2], quadColor[2], inv_alpha); /* B */ + } + else { + VEC4_COPY(source[0], zero); /* R */ + VEC4_COPY(source[1], zero); /* G */ + VEC4_COPY(source[2], zero); /* B */ + } + break; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + { + float inv_comp[4]; + VEC4_SUB(inv_comp, one, dest[0]); /* R */ + VEC4_MUL(source[0], quadColor[0], inv_comp); /* R */ + VEC4_SUB(inv_comp, one, dest[1]); /* G */ + VEC4_MUL(source[1], quadColor[1], inv_comp); /* G */ + VEC4_SUB(inv_comp, one, dest[2]); /* B */ + VEC4_MUL(source[2], quadColor[2], inv_comp); /* B */ + } + break; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + { + float inv_comp[4]; + /* R */ + VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[0]); + VEC4_MUL(source[0], quadColor[0], inv_comp); + /* G */ + VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[1]); + VEC4_MUL(source[1], quadColor[1], inv_comp); + /* B */ + VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[2]); + VEC4_MUL(source[2], quadColor[2], inv_comp); + } + break; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + { + float inv_alpha[4]; + VEC4_SCALAR(inv_alpha, 1.0f - softpipe->blend_color.color[3]); + VEC4_MUL(source[0], quadColor[0], inv_alpha); /* R */ + VEC4_MUL(source[1], quadColor[1], inv_alpha); /* G */ + VEC4_MUL(source[2], quadColor[2], inv_alpha); /* B */ + } + break; + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + assert(0); /* to do */ + break; + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + assert(0); /* to do */ + break; + default: + assert(0 && "invalid rgb src factor"); + } + + /* + * Compute src/first term A + */ + switch (softpipe->blend->rt[blend_index].alpha_src_factor) { + case PIPE_BLENDFACTOR_ONE: + VEC4_COPY(source[3], quadColor[3]); /* A */ + break; + case PIPE_BLENDFACTOR_SRC_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_SRC_ALPHA: + { + const float *alpha = quadColor[3]; + VEC4_MUL(source[3], quadColor[3], alpha); /* A */ + } + break; + case PIPE_BLENDFACTOR_DST_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_DST_ALPHA: + if (has_dst_alpha) + VEC4_MUL(source[3], quadColor[3], dest[3]); /* A */ + else + VEC4_COPY(source[3], quadColor[3]); /* A */ + break; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + /* multiply alpha by 1.0 */ + VEC4_COPY(source[3], quadColor[3]); /* A */ + break; + case PIPE_BLENDFACTOR_CONST_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_CONST_ALPHA: + { + float comp[4]; + VEC4_SCALAR(comp, softpipe->blend_color.color[3]); /* A */ + VEC4_MUL(source[3], quadColor[3], comp); /* A */ + } + break; + case PIPE_BLENDFACTOR_ZERO: + VEC4_COPY(source[3], zero); /* A */ + break; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + { + float inv_alpha[4]; + VEC4_SUB(inv_alpha, one, quadColor[3]); + VEC4_MUL(source[3], quadColor[3], inv_alpha); /* A */ + } + break; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + if (has_dst_alpha) { + float inv_alpha[4]; + VEC4_SUB(inv_alpha, one, dest[3]); + VEC4_MUL(source[3], quadColor[3], inv_alpha); /* A */ + } + else { + VEC4_COPY(source[3], zero); /* A */ + } + break; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + { + float inv_comp[4]; + /* A */ + VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[3]); + VEC4_MUL(source[3], quadColor[3], inv_comp); + } + break; + default: + assert(0 && "invalid alpha src factor"); + } + + + /* + * Compute dest/second term RGB + */ + switch (softpipe->blend->rt[blend_index].rgb_dst_factor) { + case PIPE_BLENDFACTOR_ONE: + /* dest = dest * 1 NO-OP, leave dest as-is */ + break; + case PIPE_BLENDFACTOR_SRC_COLOR: + VEC4_MUL(dest[0], dest[0], quadColor[0]); /* R */ + VEC4_MUL(dest[1], dest[1], quadColor[1]); /* G */ + VEC4_MUL(dest[2], dest[2], quadColor[2]); /* B */ + break; + case PIPE_BLENDFACTOR_SRC_ALPHA: + VEC4_MUL(dest[0], dest[0], quadColor[3]); /* R * A */ + VEC4_MUL(dest[1], dest[1], quadColor[3]); /* G * A */ + VEC4_MUL(dest[2], dest[2], quadColor[3]); /* B * A */ + break; + case PIPE_BLENDFACTOR_DST_ALPHA: + if (has_dst_alpha) { + VEC4_MUL(dest[0], dest[0], dest[3]); /* R * A */ + VEC4_MUL(dest[1], dest[1], dest[3]); /* G * A */ + VEC4_MUL(dest[2], dest[2], dest[3]); /* B * A */ + } + else { + /* dest = dest * 1 NO-OP, leave dest as-is */ + } + break; + case PIPE_BLENDFACTOR_DST_COLOR: + VEC4_MUL(dest[0], dest[0], dest[0]); /* R */ + VEC4_MUL(dest[1], dest[1], dest[1]); /* G */ + VEC4_MUL(dest[2], dest[2], dest[2]); /* B */ + break; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + if (has_dst_alpha) { + const float *alpha = quadColor[3]; + float diff[4], temp[4]; + VEC4_SUB(diff, one, dest[3]); + VEC4_MIN(temp, alpha, diff); + VEC4_MUL(dest[0], quadColor[0], temp); /* R */ + VEC4_MUL(dest[1], quadColor[1], temp); /* G */ + VEC4_MUL(dest[2], quadColor[2], temp); /* B */ + } + else { + VEC4_COPY(dest[0], zero); /* R */ + VEC4_COPY(dest[1], zero); /* G */ + VEC4_COPY(dest[2], zero); /* B */ + } + break; + case PIPE_BLENDFACTOR_CONST_COLOR: + { + float comp[4]; + VEC4_SCALAR(comp, softpipe->blend_color.color[0]); /* R */ + VEC4_MUL(dest[0], dest[0], comp); /* R */ + VEC4_SCALAR(comp, softpipe->blend_color.color[1]); /* G */ + VEC4_MUL(dest[1], dest[1], comp); /* G */ + VEC4_SCALAR(comp, softpipe->blend_color.color[2]); /* B */ + VEC4_MUL(dest[2], dest[2], comp); /* B */ + } + break; + case PIPE_BLENDFACTOR_CONST_ALPHA: + { + float comp[4]; + VEC4_SCALAR(comp, softpipe->blend_color.color[3]); /* A */ + VEC4_MUL(dest[0], dest[0], comp); /* R */ + VEC4_MUL(dest[1], dest[1], comp); /* G */ + VEC4_MUL(dest[2], dest[2], comp); /* B */ + } + break; + case PIPE_BLENDFACTOR_ZERO: + VEC4_COPY(dest[0], zero); /* R */ + VEC4_COPY(dest[1], zero); /* G */ + VEC4_COPY(dest[2], zero); /* B */ + break; + case PIPE_BLENDFACTOR_SRC1_COLOR: + case PIPE_BLENDFACTOR_SRC1_ALPHA: + /* XXX what are these? */ + assert(0); + break; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + { + float inv_comp[4]; + VEC4_SUB(inv_comp, one, quadColor[0]); /* R */ + VEC4_MUL(dest[0], inv_comp, dest[0]); /* R */ + VEC4_SUB(inv_comp, one, quadColor[1]); /* G */ + VEC4_MUL(dest[1], inv_comp, dest[1]); /* G */ + VEC4_SUB(inv_comp, one, quadColor[2]); /* B */ + VEC4_MUL(dest[2], inv_comp, dest[2]); /* B */ + } + break; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + { + float one_minus_alpha[QUAD_SIZE]; + VEC4_SUB(one_minus_alpha, one, quadColor[3]); + VEC4_MUL(dest[0], dest[0], one_minus_alpha); /* R */ + VEC4_MUL(dest[1], dest[1], one_minus_alpha); /* G */ + VEC4_MUL(dest[2], dest[2], one_minus_alpha); /* B */ + } + break; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + if (has_dst_alpha) { + float inv_comp[4]; + VEC4_SUB(inv_comp, one, dest[3]); /* A */ + VEC4_MUL(dest[0], inv_comp, dest[0]); /* R */ + VEC4_MUL(dest[1], inv_comp, dest[1]); /* G */ + VEC4_MUL(dest[2], inv_comp, dest[2]); /* B */ + } + else { + VEC4_COPY(dest[0], zero); /* R */ + VEC4_COPY(dest[1], zero); /* G */ + VEC4_COPY(dest[2], zero); /* B */ + } + break; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + { + float inv_comp[4]; + VEC4_SUB(inv_comp, one, dest[0]); /* R */ + VEC4_MUL(dest[0], dest[0], inv_comp); /* R */ + VEC4_SUB(inv_comp, one, dest[1]); /* G */ + VEC4_MUL(dest[1], dest[1], inv_comp); /* G */ + VEC4_SUB(inv_comp, one, dest[2]); /* B */ + VEC4_MUL(dest[2], dest[2], inv_comp); /* B */ + } + break; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + { + float inv_comp[4]; + /* R */ + VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[0]); + VEC4_MUL(dest[0], dest[0], inv_comp); + /* G */ + VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[1]); + VEC4_MUL(dest[1], dest[1], inv_comp); + /* B */ + VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[2]); + VEC4_MUL(dest[2], dest[2], inv_comp); + } + break; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + { + float inv_comp[4]; + VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[3]); + VEC4_MUL(dest[0], dest[0], inv_comp); + VEC4_MUL(dest[1], dest[1], inv_comp); + VEC4_MUL(dest[2], dest[2], inv_comp); + } + break; + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + /* XXX what are these? */ + assert(0); + break; + default: + assert(0 && "invalid rgb dst factor"); + } + + /* + * Compute dest/second term A + */ + switch (softpipe->blend->rt[blend_index].alpha_dst_factor) { + case PIPE_BLENDFACTOR_ONE: + /* dest = dest * 1 NO-OP, leave dest as-is */ + break; + case PIPE_BLENDFACTOR_SRC_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_SRC_ALPHA: + VEC4_MUL(dest[3], dest[3], quadColor[3]); /* A * A */ + break; + case PIPE_BLENDFACTOR_DST_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_DST_ALPHA: + if (has_dst_alpha) { + VEC4_MUL(dest[3], dest[3], dest[3]); /* A */ + } + else { + /* dest = dest * 1 NO-OP, leave dest as-is */ + } + break; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + /* dest = dest * 1 NO-OP, leave dest as-is */ + break; + case PIPE_BLENDFACTOR_CONST_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_CONST_ALPHA: + { + float comp[4]; + VEC4_SCALAR(comp, softpipe->blend_color.color[3]); /* A */ + VEC4_MUL(dest[3], dest[3], comp); /* A */ + } + break; + case PIPE_BLENDFACTOR_ZERO: + VEC4_COPY(dest[3], zero); /* A */ + break; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + { + float one_minus_alpha[QUAD_SIZE]; + VEC4_SUB(one_minus_alpha, one, quadColor[3]); + VEC4_MUL(dest[3], dest[3], one_minus_alpha); /* A */ + } + break; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + if (has_dst_alpha) { + float inv_comp[4]; + VEC4_SUB(inv_comp, one, dest[3]); /* A */ + VEC4_MUL(dest[3], inv_comp, dest[3]); /* A */ + } + else { + VEC4_COPY(dest[3], zero); /* A */ + } + break; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + /* fall-through */ + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + { + float inv_comp[4]; + VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[3]); + VEC4_MUL(dest[3], dest[3], inv_comp); + } + break; + default: + assert(0 && "invalid alpha dst factor"); + } + + /* + * Combine RGB terms + */ + switch (softpipe->blend->rt[blend_index].rgb_func) { + case PIPE_BLEND_ADD: + VEC4_ADD_SAT(quadColor[0], source[0], dest[0]); /* R */ + VEC4_ADD_SAT(quadColor[1], source[1], dest[1]); /* G */ + VEC4_ADD_SAT(quadColor[2], source[2], dest[2]); /* B */ + break; + case PIPE_BLEND_SUBTRACT: + VEC4_SUB_SAT(quadColor[0], source[0], dest[0]); /* R */ + VEC4_SUB_SAT(quadColor[1], source[1], dest[1]); /* G */ + VEC4_SUB_SAT(quadColor[2], source[2], dest[2]); /* B */ + break; + case PIPE_BLEND_REVERSE_SUBTRACT: + VEC4_SUB_SAT(quadColor[0], dest[0], source[0]); /* R */ + VEC4_SUB_SAT(quadColor[1], dest[1], source[1]); /* G */ + VEC4_SUB_SAT(quadColor[2], dest[2], source[2]); /* B */ + break; + case PIPE_BLEND_MIN: + VEC4_MIN(quadColor[0], source[0], dest[0]); /* R */ + VEC4_MIN(quadColor[1], source[1], dest[1]); /* G */ + VEC4_MIN(quadColor[2], source[2], dest[2]); /* B */ + break; + case PIPE_BLEND_MAX: + VEC4_MAX(quadColor[0], source[0], dest[0]); /* R */ + VEC4_MAX(quadColor[1], source[1], dest[1]); /* G */ + VEC4_MAX(quadColor[2], source[2], dest[2]); /* B */ + break; + default: + assert(0 && "invalid rgb blend func"); + } + + /* + * Combine A terms + */ + switch (softpipe->blend->rt[blend_index].alpha_func) { + case PIPE_BLEND_ADD: + VEC4_ADD_SAT(quadColor[3], source[3], dest[3]); /* A */ + break; + case PIPE_BLEND_SUBTRACT: + VEC4_SUB_SAT(quadColor[3], source[3], dest[3]); /* A */ + break; + case PIPE_BLEND_REVERSE_SUBTRACT: + VEC4_SUB_SAT(quadColor[3], dest[3], source[3]); /* A */ + break; + case PIPE_BLEND_MIN: + VEC4_MIN(quadColor[3], source[3], dest[3]); /* A */ + break; + case PIPE_BLEND_MAX: + VEC4_MAX(quadColor[3], source[3], dest[3]); /* A */ + break; + default: + assert(0 && "invalid alpha blend func"); + } +} + +static void +colormask_quad(unsigned colormask, + float (*quadColor)[4], + float (*dest)[4]) +{ + /* R */ + if (!(colormask & PIPE_MASK_R)) + COPY_4V(quadColor[0], dest[0]); + + /* G */ + if (!(colormask & PIPE_MASK_G)) + COPY_4V(quadColor[1], dest[1]); + + /* B */ + if (!(colormask & PIPE_MASK_B)) + COPY_4V(quadColor[2], dest[2]); + + /* A */ + if (!(colormask & PIPE_MASK_A)) + COPY_4V(quadColor[3], dest[3]); +} + + +static void +blend_fallback(struct quad_stage *qs, + struct quad_header *quads[], + unsigned nr) +{ + struct softpipe_context *softpipe = qs->softpipe; + const struct pipe_blend_state *blend = softpipe->blend; + unsigned cbuf; + + for (cbuf = 0; cbuf < softpipe->framebuffer.nr_cbufs; cbuf++) + { + /* which blend/mask state index to use: */ + const uint blend_buf = blend->independent_blend_enable ? cbuf : 0; + float dest[4][QUAD_SIZE]; + struct softpipe_cached_tile *tile + = sp_get_cached_tile(softpipe->cbuf_cache[cbuf], + quads[0]->input.x0, + quads[0]->input.y0); + boolean has_dst_alpha + = util_format_has_alpha(softpipe->framebuffer.cbufs[cbuf]->format); + uint q, i, j; + + for (q = 0; q < nr; q++) { + struct quad_header *quad = quads[q]; + float (*quadColor)[4] = quad->output.color[cbuf]; + const int itx = (quad->input.x0 & (TILE_SIZE-1)); + const int ity = (quad->input.y0 & (TILE_SIZE-1)); + + /* get/swizzle dest colors + */ + for (j = 0; j < QUAD_SIZE; j++) { + int x = itx + (j & 1); + int y = ity + (j >> 1); + for (i = 0; i < 4; i++) { + dest[i][j] = tile->data.color[y][x][i]; + } + } + + + if (blend->logicop_enable) { + logicop_quad( qs, quadColor, dest ); + } + else if (blend->rt[blend_buf].blend_enable) { + blend_quad( qs, quadColor, dest, blend_buf, has_dst_alpha ); + } + + if (blend->rt[blend_buf].colormask != 0xf) + colormask_quad( blend->rt[cbuf].colormask, quadColor, dest); + + /* Output color values + */ + for (j = 0; j < QUAD_SIZE; j++) { + if (quad->inout.mask & (1 << j)) { + int x = itx + (j & 1); + int y = ity + (j >> 1); + for (i = 0; i < 4; i++) { /* loop over color chans */ + tile->data.color[y][x][i] = quadColor[i][j]; + } + } + } + } + } +} + + +static void +blend_single_add_src_alpha_inv_src_alpha(struct quad_stage *qs, + struct quad_header *quads[], + unsigned nr) +{ + static const float one[4] = { 1, 1, 1, 1 }; + float one_minus_alpha[QUAD_SIZE]; + float dest[4][QUAD_SIZE]; + float source[4][QUAD_SIZE]; + uint i, j, q; + + struct softpipe_cached_tile *tile + = sp_get_cached_tile(qs->softpipe->cbuf_cache[0], + quads[0]->input.x0, + quads[0]->input.y0); + + for (q = 0; q < nr; q++) { + struct quad_header *quad = quads[q]; + float (*quadColor)[4] = quad->output.color[0]; + const float *alpha = quadColor[3]; + const int itx = (quad->input.x0 & (TILE_SIZE-1)); + const int ity = (quad->input.y0 & (TILE_SIZE-1)); + + /* get/swizzle dest colors */ + for (j = 0; j < QUAD_SIZE; j++) { + int x = itx + (j & 1); + int y = ity + (j >> 1); + for (i = 0; i < 4; i++) { + dest[i][j] = tile->data.color[y][x][i]; + } + } + + VEC4_MUL(source[0], quadColor[0], alpha); /* R */ + VEC4_MUL(source[1], quadColor[1], alpha); /* G */ + VEC4_MUL(source[2], quadColor[2], alpha); /* B */ + VEC4_MUL(source[3], quadColor[3], alpha); /* A */ + + VEC4_SUB(one_minus_alpha, one, alpha); + VEC4_MUL(dest[0], dest[0], one_minus_alpha); /* R */ + VEC4_MUL(dest[1], dest[1], one_minus_alpha); /* G */ + VEC4_MUL(dest[2], dest[2], one_minus_alpha); /* B */ + VEC4_MUL(dest[3], dest[3], one_minus_alpha); /* B */ + + VEC4_ADD_SAT(quadColor[0], source[0], dest[0]); /* R */ + VEC4_ADD_SAT(quadColor[1], source[1], dest[1]); /* G */ + VEC4_ADD_SAT(quadColor[2], source[2], dest[2]); /* B */ + VEC4_ADD_SAT(quadColor[3], source[3], dest[3]); /* A */ + + for (j = 0; j < QUAD_SIZE; j++) { + if (quad->inout.mask & (1 << j)) { + int x = itx + (j & 1); + int y = ity + (j >> 1); + for (i = 0; i < 4; i++) { /* loop over color chans */ + tile->data.color[y][x][i] = quadColor[i][j]; + } + } + } + } +} + +static void +blend_single_add_one_one(struct quad_stage *qs, + struct quad_header *quads[], + unsigned nr) +{ + float dest[4][QUAD_SIZE]; + uint i, j, q; + + struct softpipe_cached_tile *tile + = sp_get_cached_tile(qs->softpipe->cbuf_cache[0], + quads[0]->input.x0, + quads[0]->input.y0); + + for (q = 0; q < nr; q++) { + struct quad_header *quad = quads[q]; + float (*quadColor)[4] = quad->output.color[0]; + const int itx = (quad->input.x0 & (TILE_SIZE-1)); + const int ity = (quad->input.y0 & (TILE_SIZE-1)); + + /* get/swizzle dest colors */ + for (j = 0; j < QUAD_SIZE; j++) { + int x = itx + (j & 1); + int y = ity + (j >> 1); + for (i = 0; i < 4; i++) { + dest[i][j] = tile->data.color[y][x][i]; + } + } + + VEC4_ADD_SAT(quadColor[0], quadColor[0], dest[0]); /* R */ + VEC4_ADD_SAT(quadColor[1], quadColor[1], dest[1]); /* G */ + VEC4_ADD_SAT(quadColor[2], quadColor[2], dest[2]); /* B */ + VEC4_ADD_SAT(quadColor[3], quadColor[3], dest[3]); /* A */ + + for (j = 0; j < QUAD_SIZE; j++) { + if (quad->inout.mask & (1 << j)) { + int x = itx + (j & 1); + int y = ity + (j >> 1); + for (i = 0; i < 4; i++) { /* loop over color chans */ + tile->data.color[y][x][i] = quadColor[i][j]; + } + } + } + } +} + + +static void +single_output_color(struct quad_stage *qs, + struct quad_header *quads[], + unsigned nr) +{ + uint i, j, q; + + struct softpipe_cached_tile *tile + = sp_get_cached_tile(qs->softpipe->cbuf_cache[0], + quads[0]->input.x0, + quads[0]->input.y0); + + for (q = 0; q < nr; q++) { + struct quad_header *quad = quads[q]; + float (*quadColor)[4] = quad->output.color[0]; + const int itx = (quad->input.x0 & (TILE_SIZE-1)); + const int ity = (quad->input.y0 & (TILE_SIZE-1)); + + for (j = 0; j < QUAD_SIZE; j++) { + if (quad->inout.mask & (1 << j)) { + int x = itx + (j & 1); + int y = ity + (j >> 1); + for (i = 0; i < 4; i++) { /* loop over color chans */ + tile->data.color[y][x][i] = quadColor[i][j]; + } + } + } + } +} + +static void +blend_noop(struct quad_stage *qs, + struct quad_header *quads[], + unsigned nr) +{ +} + + +static void +choose_blend_quad(struct quad_stage *qs, + struct quad_header *quads[], + unsigned nr) +{ + struct softpipe_context *softpipe = qs->softpipe; + const struct pipe_blend_state *blend = softpipe->blend; + + qs->run = blend_fallback; + + if (softpipe->framebuffer.nr_cbufs == 0) { + qs->run = blend_noop; + } + else if (!softpipe->blend->logicop_enable && + softpipe->blend->rt[0].colormask == 0xf && + softpipe->framebuffer.nr_cbufs == 1) + { + if (!blend->rt[0].blend_enable) { + qs->run = single_output_color; + } + else if (blend->rt[0].rgb_src_factor == blend->rt[0].alpha_src_factor && + blend->rt[0].rgb_dst_factor == blend->rt[0].alpha_dst_factor && + blend->rt[0].rgb_func == blend->rt[0].alpha_func) + { + if (blend->rt[0].alpha_func == PIPE_BLEND_ADD) { + if (blend->rt[0].rgb_src_factor == PIPE_BLENDFACTOR_ONE && + blend->rt[0].rgb_dst_factor == PIPE_BLENDFACTOR_ONE) { + qs->run = blend_single_add_one_one; + } + else if (blend->rt[0].rgb_src_factor == PIPE_BLENDFACTOR_SRC_ALPHA && + blend->rt[0].rgb_dst_factor == PIPE_BLENDFACTOR_INV_SRC_ALPHA) + qs->run = blend_single_add_src_alpha_inv_src_alpha; + + } + } + } + + qs->run(qs, quads, nr); +} + + +static void blend_begin(struct quad_stage *qs) +{ + qs->run = choose_blend_quad; +} + + +static void blend_destroy(struct quad_stage *qs) +{ + FREE( qs ); +} + + +struct quad_stage *sp_quad_blend_stage( struct softpipe_context *softpipe ) +{ + struct quad_stage *stage = CALLOC_STRUCT(quad_stage); + + stage->softpipe = softpipe; + stage->begin = blend_begin; + stage->run = choose_blend_quad; + stage->destroy = blend_destroy; + + return stage; +} diff --git a/src/gallium/drivers/softpipe/sp_quad_depth_test.c b/src/gallium/drivers/softpipe/sp_quad_depth_test.c new file mode 100644 index 0000000..89b2a91 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_quad_depth_test.c @@ -0,0 +1,939 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL THE 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. + * + **************************************************************************/ + +/** + * \brief Quad depth / stencil testing + */ + +#include "pipe/p_defines.h" +#include "util/u_format.h" +#include "util/u_memory.h" +#include "tgsi/tgsi_scan.h" +#include "sp_context.h" +#include "sp_quad.h" +#include "sp_quad_pipe.h" +#include "sp_tile_cache.h" +#include "sp_state.h" /* for sp_fragment_shader */ + + +struct depth_data { + struct pipe_surface *ps; + enum pipe_format format; + unsigned bzzzz[QUAD_SIZE]; /**< Z values fetched from depth buffer */ + unsigned qzzzz[QUAD_SIZE]; /**< Z values from the quad */ + ubyte stencilVals[QUAD_SIZE]; + boolean use_shader_stencil_refs; + ubyte shader_stencil_refs[QUAD_SIZE]; + struct softpipe_cached_tile *tile; +}; + + + +static void +get_depth_stencil_values( struct depth_data *data, + const struct quad_header *quad ) +{ + unsigned j; + const struct softpipe_cached_tile *tile = data->tile; + + switch (data->format) { + case PIPE_FORMAT_Z16_UNORM: + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->input.x0 % TILE_SIZE + (j & 1); + int y = quad->input.y0 % TILE_SIZE + (j >> 1); + data->bzzzz[j] = tile->data.depth16[y][x]; + } + break; + case PIPE_FORMAT_Z32_UNORM: + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->input.x0 % TILE_SIZE + (j & 1); + int y = quad->input.y0 % TILE_SIZE + (j >> 1); + data->bzzzz[j] = tile->data.depth32[y][x]; + } + break; + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->input.x0 % TILE_SIZE + (j & 1); + int y = quad->input.y0 % TILE_SIZE + (j >> 1); + data->bzzzz[j] = tile->data.depth32[y][x] & 0xffffff; + data->stencilVals[j] = tile->data.depth32[y][x] >> 24; + } + break; + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->input.x0 % TILE_SIZE + (j & 1); + int y = quad->input.y0 % TILE_SIZE + (j >> 1); + data->bzzzz[j] = tile->data.depth32[y][x] >> 8; + data->stencilVals[j] = tile->data.depth32[y][x] & 0xff; + } + break; + case PIPE_FORMAT_S8_USCALED: + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->input.x0 % TILE_SIZE + (j & 1); + int y = quad->input.y0 % TILE_SIZE + (j >> 1); + data->bzzzz[j] = 0; + data->stencilVals[j] = tile->data.stencil8[y][x]; + } + break; + default: + assert(0); + } +} + + +/** + * If the shader has not been run, interpolate the depth values + * ourselves. + */ +static void +interpolate_quad_depth( struct quad_header *quad ) +{ + const float fx = (float) quad->input.x0; + const float fy = (float) quad->input.y0; + const float dzdx = quad->posCoef->dadx[2]; + const float dzdy = quad->posCoef->dady[2]; + const float z0 = quad->posCoef->a0[2] + dzdx * fx + dzdy * fy; + + quad->output.depth[0] = z0; + quad->output.depth[1] = z0 + dzdx; + quad->output.depth[2] = z0 + dzdy; + quad->output.depth[3] = z0 + dzdx + dzdy; +} + + +/** + * Compute the depth_data::qzzzz[] values from the float fragment Z values. + */ +static void +convert_quad_depth( struct depth_data *data, + const struct quad_header *quad ) +{ + unsigned j; + + /* Convert quad's float depth values to int depth values (qzzzz). + * If the Z buffer stores integer values, we _have_ to do the depth + * compares with integers (not floats). Otherwise, the float->int->float + * conversion of Z values (which isn't an identity function) will cause + * Z-fighting errors. + */ + switch (data->format) { + case PIPE_FORMAT_Z16_UNORM: + { + float scale = 65535.0; + + for (j = 0; j < QUAD_SIZE; j++) { + data->qzzzz[j] = (unsigned) (quad->output.depth[j] * scale); + } + } + break; + case PIPE_FORMAT_Z32_UNORM: + { + double scale = (double) (uint) ~0UL; + + for (j = 0; j < QUAD_SIZE; j++) { + data->qzzzz[j] = (unsigned) (quad->output.depth[j] * scale); + } + } + break; + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + { + float scale = (float) ((1 << 24) - 1); + + for (j = 0; j < QUAD_SIZE; j++) { + data->qzzzz[j] = (unsigned) (quad->output.depth[j] * scale); + } + } + break; + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + { + float scale = (float) ((1 << 24) - 1); + + for (j = 0; j < QUAD_SIZE; j++) { + data->qzzzz[j] = (unsigned) (quad->output.depth[j] * scale); + } + } + break; + default: + assert(0); + } +} + + +/** + * Compute the depth_data::shader_stencil_refs[] values from the float fragment stencil values. + */ +static void +convert_quad_stencil( struct depth_data *data, + const struct quad_header *quad ) +{ + unsigned j; + + data->use_shader_stencil_refs = TRUE; + /* Copy quads stencil values + */ + switch (data->format) { + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + { + for (j = 0; j < QUAD_SIZE; j++) { + data->shader_stencil_refs[j] = ((unsigned)(quad->output.stencil[j])); + } + } + break; + default: + assert(0); + } +} + +/** + * Write data->bzzzz[] values and data->stencilVals into the Z/stencil buffer. + */ +static void +write_depth_stencil_values( struct depth_data *data, + struct quad_header *quad ) +{ + struct softpipe_cached_tile *tile = data->tile; + unsigned j; + + /* put updated Z values back into cached tile */ + switch (data->format) { + case PIPE_FORMAT_Z16_UNORM: + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->input.x0 % TILE_SIZE + (j & 1); + int y = quad->input.y0 % TILE_SIZE + (j >> 1); + tile->data.depth16[y][x] = (ushort) data->bzzzz[j]; + } + break; + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z32_UNORM: + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->input.x0 % TILE_SIZE + (j & 1); + int y = quad->input.y0 % TILE_SIZE + (j >> 1); + tile->data.depth32[y][x] = data->bzzzz[j]; + } + break; + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->input.x0 % TILE_SIZE + (j & 1); + int y = quad->input.y0 % TILE_SIZE + (j >> 1); + tile->data.depth32[y][x] = (data->stencilVals[j] << 24) | data->bzzzz[j]; + } + break; + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->input.x0 % TILE_SIZE + (j & 1); + int y = quad->input.y0 % TILE_SIZE + (j >> 1); + tile->data.depth32[y][x] = (data->bzzzz[j] << 8) | data->stencilVals[j]; + } + break; + case PIPE_FORMAT_X8Z24_UNORM: + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->input.x0 % TILE_SIZE + (j & 1); + int y = quad->input.y0 % TILE_SIZE + (j >> 1); + tile->data.depth32[y][x] = data->bzzzz[j] << 8; + } + break; + case PIPE_FORMAT_S8_USCALED: + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->input.x0 % TILE_SIZE + (j & 1); + int y = quad->input.y0 % TILE_SIZE + (j >> 1); + tile->data.stencil8[y][x] = data->stencilVals[j]; + } + break; + + default: + assert(0); + } +} + + + +/** Only 8-bit stencil supported */ +#define STENCIL_MAX 0xff + + +/** + * Do the basic stencil test (compare stencil buffer values against the + * reference value. + * + * \param data->stencilVals the stencil values from the stencil buffer + * \param func the stencil func (PIPE_FUNC_x) + * \param ref the stencil reference value + * \param valMask the stencil value mask indicating which bits of the stencil + * values and ref value are to be used. + * \return mask indicating which pixels passed the stencil test + */ +static unsigned +do_stencil_test(struct depth_data *data, + unsigned func, + unsigned ref, unsigned valMask) +{ + unsigned passMask = 0x0; + unsigned j; + ubyte refs[QUAD_SIZE]; + + for (j = 0; j < QUAD_SIZE; j++) { + if (data->use_shader_stencil_refs) + refs[j] = data->shader_stencil_refs[j] & valMask; + else + refs[j] = ref & valMask; + } + + switch (func) { + case PIPE_FUNC_NEVER: + /* passMask = 0x0 */ + break; + case PIPE_FUNC_LESS: + for (j = 0; j < QUAD_SIZE; j++) { + if (refs[j] < (data->stencilVals[j] & valMask)) { + passMask |= (1 << j); + } + } + break; + case PIPE_FUNC_EQUAL: + for (j = 0; j < QUAD_SIZE; j++) { + if (refs[j] == (data->stencilVals[j] & valMask)) { + passMask |= (1 << j); + } + } + break; + case PIPE_FUNC_LEQUAL: + for (j = 0; j < QUAD_SIZE; j++) { + if (refs[j] <= (data->stencilVals[j] & valMask)) { + passMask |= (1 << j); + } + } + break; + case PIPE_FUNC_GREATER: + for (j = 0; j < QUAD_SIZE; j++) { + if (refs[j] > (data->stencilVals[j] & valMask)) { + passMask |= (1 << j); + } + } + break; + case PIPE_FUNC_NOTEQUAL: + for (j = 0; j < QUAD_SIZE; j++) { + if (refs[j] != (data->stencilVals[j] & valMask)) { + passMask |= (1 << j); + } + } + break; + case PIPE_FUNC_GEQUAL: + for (j = 0; j < QUAD_SIZE; j++) { + if (refs[j] >= (data->stencilVals[j] & valMask)) { + passMask |= (1 << j); + } + } + break; + case PIPE_FUNC_ALWAYS: + passMask = MASK_ALL; + break; + default: + assert(0); + } + + return passMask; +} + + +/** + * Apply the stencil operator to stencil values. + * + * \param data->stencilVals the stencil buffer values (read and written) + * \param mask indicates which pixels to update + * \param op the stencil operator (PIPE_STENCIL_OP_x) + * \param ref the stencil reference value + * \param wrtMask writemask controlling which bits are changed in the + * stencil values + */ +static void +apply_stencil_op(struct depth_data *data, + unsigned mask, unsigned op, ubyte ref, ubyte wrtMask) +{ + unsigned j; + ubyte newstencil[QUAD_SIZE]; + ubyte refs[QUAD_SIZE]; + + for (j = 0; j < QUAD_SIZE; j++) { + newstencil[j] = data->stencilVals[j]; + if (data->use_shader_stencil_refs) + refs[j] = data->shader_stencil_refs[j]; + else + refs[j] = ref; + } + + switch (op) { + case PIPE_STENCIL_OP_KEEP: + /* no-op */ + break; + case PIPE_STENCIL_OP_ZERO: + for (j = 0; j < QUAD_SIZE; j++) { + if (mask & (1 << j)) { + newstencil[j] = 0; + } + } + break; + case PIPE_STENCIL_OP_REPLACE: + for (j = 0; j < QUAD_SIZE; j++) { + if (mask & (1 << j)) { + newstencil[j] = refs[j]; + } + } + break; + case PIPE_STENCIL_OP_INCR: + for (j = 0; j < QUAD_SIZE; j++) { + if (mask & (1 << j)) { + if (data->stencilVals[j] < STENCIL_MAX) { + newstencil[j] = data->stencilVals[j] + 1; + } + } + } + break; + case PIPE_STENCIL_OP_DECR: + for (j = 0; j < QUAD_SIZE; j++) { + if (mask & (1 << j)) { + if (data->stencilVals[j] > 0) { + newstencil[j] = data->stencilVals[j] - 1; + } + } + } + break; + case PIPE_STENCIL_OP_INCR_WRAP: + for (j = 0; j < QUAD_SIZE; j++) { + if (mask & (1 << j)) { + newstencil[j] = data->stencilVals[j] + 1; + } + } + break; + case PIPE_STENCIL_OP_DECR_WRAP: + for (j = 0; j < QUAD_SIZE; j++) { + if (mask & (1 << j)) { + newstencil[j] = data->stencilVals[j] - 1; + } + } + break; + case PIPE_STENCIL_OP_INVERT: + for (j = 0; j < QUAD_SIZE; j++) { + if (mask & (1 << j)) { + newstencil[j] = ~data->stencilVals[j]; + } + } + break; + default: + assert(0); + } + + /* + * update the stencil values + */ + if (wrtMask != STENCIL_MAX) { + /* apply bit-wise stencil buffer writemask */ + for (j = 0; j < QUAD_SIZE; j++) { + data->stencilVals[j] = (wrtMask & newstencil[j]) | (~wrtMask & data->stencilVals[j]); + } + } + else { + for (j = 0; j < QUAD_SIZE; j++) { + data->stencilVals[j] = newstencil[j]; + } + } +} + + + +/** + * To increase efficiency, we should probably have multiple versions + * of this function that are specifically for Z16, Z32 and FP Z buffers. + * Try to effectively do that with codegen... + */ +static boolean +depth_test_quad(struct quad_stage *qs, + struct depth_data *data, + struct quad_header *quad) +{ + struct softpipe_context *softpipe = qs->softpipe; + unsigned zmask = 0; + unsigned j; + + switch (softpipe->depth_stencil->depth.func) { + case PIPE_FUNC_NEVER: + /* zmask = 0 */ + break; + case PIPE_FUNC_LESS: + /* Note this is pretty much a single sse or cell instruction. + * Like this: quad->mask &= (quad->outputs.depth < zzzz); + */ + for (j = 0; j < QUAD_SIZE; j++) { + if (data->qzzzz[j] < data->bzzzz[j]) + zmask |= 1 << j; + } + break; + case PIPE_FUNC_EQUAL: + for (j = 0; j < QUAD_SIZE; j++) { + if (data->qzzzz[j] == data->bzzzz[j]) + zmask |= 1 << j; + } + break; + case PIPE_FUNC_LEQUAL: + for (j = 0; j < QUAD_SIZE; j++) { + if (data->qzzzz[j] <= data->bzzzz[j]) + zmask |= (1 << j); + } + break; + case PIPE_FUNC_GREATER: + for (j = 0; j < QUAD_SIZE; j++) { + if (data->qzzzz[j] > data->bzzzz[j]) + zmask |= (1 << j); + } + break; + case PIPE_FUNC_NOTEQUAL: + for (j = 0; j < QUAD_SIZE; j++) { + if (data->qzzzz[j] != data->bzzzz[j]) + zmask |= (1 << j); + } + break; + case PIPE_FUNC_GEQUAL: + for (j = 0; j < QUAD_SIZE; j++) { + if (data->qzzzz[j] >= data->bzzzz[j]) + zmask |= (1 << j); + } + break; + case PIPE_FUNC_ALWAYS: + zmask = MASK_ALL; + break; + default: + assert(0); + } + + quad->inout.mask &= zmask; + if (quad->inout.mask == 0) + return FALSE; + + /* Update our internal copy only if writemask set. Even if + * depth.writemask is FALSE, may still need to write out buffer + * data due to stencil changes. + */ + if (softpipe->depth_stencil->depth.writemask) { + for (j = 0; j < QUAD_SIZE; j++) { + if (quad->inout.mask & (1 << j)) { + data->bzzzz[j] = data->qzzzz[j]; + } + } + } + + return TRUE; +} + + + +/** + * Do stencil (and depth) testing. Stenciling depends on the outcome of + * depth testing. + */ +static void +depth_stencil_test_quad(struct quad_stage *qs, + struct depth_data *data, + struct quad_header *quad) +{ + struct softpipe_context *softpipe = qs->softpipe; + unsigned func, zFailOp, zPassOp, failOp; + ubyte ref, wrtMask, valMask; + uint face = quad->input.facing; + + if (!softpipe->depth_stencil->stencil[1].enabled) { + /* single-sided stencil test, use front (face=0) state */ + face = 0; + } + + /* 0 = front-face, 1 = back-face */ + assert(face == 0 || face == 1); + + /* choose front or back face function, operator, etc */ + /* XXX we could do these initializations once per primitive */ + func = softpipe->depth_stencil->stencil[face].func; + failOp = softpipe->depth_stencil->stencil[face].fail_op; + zFailOp = softpipe->depth_stencil->stencil[face].zfail_op; + zPassOp = softpipe->depth_stencil->stencil[face].zpass_op; + ref = softpipe->stencil_ref.ref_value[face]; + wrtMask = softpipe->depth_stencil->stencil[face].writemask; + valMask = softpipe->depth_stencil->stencil[face].valuemask; + + /* do the stencil test first */ + { + unsigned passMask, failMask; + passMask = do_stencil_test(data, func, ref, valMask); + failMask = quad->inout.mask & ~passMask; + quad->inout.mask &= passMask; + + if (failOp != PIPE_STENCIL_OP_KEEP) { + apply_stencil_op(data, failMask, failOp, ref, wrtMask); + } + } + + if (quad->inout.mask) { + /* now the pixels that passed the stencil test are depth tested */ + if (softpipe->depth_stencil->depth.enabled) { + const unsigned origMask = quad->inout.mask; + + depth_test_quad(qs, data, quad); /* quad->mask is updated */ + + /* update stencil buffer values according to z pass/fail result */ + if (zFailOp != PIPE_STENCIL_OP_KEEP) { + const unsigned zFailMask = origMask & ~quad->inout.mask; + apply_stencil_op(data, zFailMask, zFailOp, ref, wrtMask); + } + + if (zPassOp != PIPE_STENCIL_OP_KEEP) { + const unsigned zPassMask = origMask & quad->inout.mask; + apply_stencil_op(data, zPassMask, zPassOp, ref, wrtMask); + } + } + else { + /* no depth test, apply Zpass operator to stencil buffer values */ + apply_stencil_op(data, quad->inout.mask, zPassOp, ref, wrtMask); + } + } +} + + +#define ALPHATEST( FUNC, COMP ) \ + static int \ + alpha_test_quads_##FUNC( struct quad_stage *qs, \ + struct quad_header *quads[], \ + unsigned nr ) \ + { \ + const float ref = qs->softpipe->depth_stencil->alpha.ref_value; \ + const uint cbuf = 0; /* only output[0].alpha is tested */ \ + unsigned pass_nr = 0; \ + unsigned i; \ + \ + for (i = 0; i < nr; i++) { \ + const float *aaaa = quads[i]->output.color[cbuf][3]; \ + unsigned passMask = 0; \ + \ + if (aaaa[0] COMP ref) passMask |= (1 << 0); \ + if (aaaa[1] COMP ref) passMask |= (1 << 1); \ + if (aaaa[2] COMP ref) passMask |= (1 << 2); \ + if (aaaa[3] COMP ref) passMask |= (1 << 3); \ + \ + quads[i]->inout.mask &= passMask; \ + \ + if (quads[i]->inout.mask) \ + quads[pass_nr++] = quads[i]; \ + } \ + \ + return pass_nr; \ + } + + +ALPHATEST( LESS, < ) +ALPHATEST( EQUAL, == ) +ALPHATEST( LEQUAL, <= ) +ALPHATEST( GREATER, > ) +ALPHATEST( NOTEQUAL, != ) +ALPHATEST( GEQUAL, >= ) + + +/* XXX: Incorporate into shader using KILP. + */ +static int +alpha_test_quads(struct quad_stage *qs, + struct quad_header *quads[], + unsigned nr) +{ + switch (qs->softpipe->depth_stencil->alpha.func) { + case PIPE_FUNC_LESS: + return alpha_test_quads_LESS( qs, quads, nr ); + case PIPE_FUNC_EQUAL: + return alpha_test_quads_EQUAL( qs, quads, nr ); + break; + case PIPE_FUNC_LEQUAL: + return alpha_test_quads_LEQUAL( qs, quads, nr ); + case PIPE_FUNC_GREATER: + return alpha_test_quads_GREATER( qs, quads, nr ); + case PIPE_FUNC_NOTEQUAL: + return alpha_test_quads_NOTEQUAL( qs, quads, nr ); + case PIPE_FUNC_GEQUAL: + return alpha_test_quads_GEQUAL( qs, quads, nr ); + case PIPE_FUNC_ALWAYS: + return nr; + case PIPE_FUNC_NEVER: + default: + return 0; + } +} + + +static unsigned mask_count[16] = +{ + 0, /* 0x0 */ + 1, /* 0x1 */ + 1, /* 0x2 */ + 2, /* 0x3 */ + 1, /* 0x4 */ + 2, /* 0x5 */ + 2, /* 0x6 */ + 3, /* 0x7 */ + 1, /* 0x8 */ + 2, /* 0x9 */ + 2, /* 0xa */ + 3, /* 0xb */ + 2, /* 0xc */ + 3, /* 0xd */ + 3, /* 0xe */ + 4, /* 0xf */ +}; + + + +/** + * General depth/stencil test function. Used when there's no fast-path. + */ +static void +depth_test_quads_fallback(struct quad_stage *qs, + struct quad_header *quads[], + unsigned nr) +{ + unsigned i, pass = 0; + const struct sp_fragment_shader *fs = qs->softpipe->fs; + boolean interp_depth = !fs->info.writes_z; + boolean shader_stencil_ref = fs->info.writes_stencil; + struct depth_data data; + + data.use_shader_stencil_refs = FALSE; + + if (qs->softpipe->depth_stencil->alpha.enabled) { + nr = alpha_test_quads(qs, quads, nr); + } + + if (qs->softpipe->framebuffer.zsbuf && + (qs->softpipe->depth_stencil->depth.enabled || + qs->softpipe->depth_stencil->stencil[0].enabled)) { + + data.ps = qs->softpipe->framebuffer.zsbuf; + data.format = data.ps->format; + data.tile = sp_get_cached_tile(qs->softpipe->zsbuf_cache, + quads[0]->input.x0, + quads[0]->input.y0); + + for (i = 0; i < nr; i++) { + get_depth_stencil_values(&data, quads[i]); + + if (qs->softpipe->depth_stencil->depth.enabled) { + if (interp_depth) + interpolate_quad_depth(quads[i]); + + convert_quad_depth(&data, quads[i]); + } + + if (qs->softpipe->depth_stencil->stencil[0].enabled) { + if (shader_stencil_ref) + convert_quad_stencil(&data, quads[i]); + + depth_stencil_test_quad(qs, &data, quads[i]); + write_depth_stencil_values(&data, quads[i]); + } + else { + if (!depth_test_quad(qs, &data, quads[i])) + continue; + + if (qs->softpipe->depth_stencil->depth.writemask) + write_depth_stencil_values(&data, quads[i]); + } + + quads[pass++] = quads[i]; + } + + nr = pass; + } + + if (qs->softpipe->active_query_count) { + for (i = 0; i < nr; i++) + qs->softpipe->occlusion_count += mask_count[quads[i]->inout.mask]; + } + + if (nr) + qs->next->run(qs->next, quads, nr); +} + + +/** + * Special-case Z testing for 16-bit Zbuffer and Z buffer writes enabled. + */ + +#define NAME depth_interp_z16_less_write +#define OPERATOR < +#include "sp_quad_depth_test_tmp.h" + +#define NAME depth_interp_z16_equal_write +#define OPERATOR == +#include "sp_quad_depth_test_tmp.h" + +#define NAME depth_interp_z16_lequal_write +#define OPERATOR <= +#include "sp_quad_depth_test_tmp.h" + +#define NAME depth_interp_z16_greater_write +#define OPERATOR > +#include "sp_quad_depth_test_tmp.h" + +#define NAME depth_interp_z16_notequal_write +#define OPERATOR != +#include "sp_quad_depth_test_tmp.h" + +#define NAME depth_interp_z16_gequal_write +#define OPERATOR >= +#include "sp_quad_depth_test_tmp.h" + +#define NAME depth_interp_z16_always_write +#define ALWAYS 1 +#include "sp_quad_depth_test_tmp.h" + + + +static void +depth_noop(struct quad_stage *qs, + struct quad_header *quads[], + unsigned nr) +{ + qs->next->run(qs->next, quads, nr); +} + + + +static void +choose_depth_test(struct quad_stage *qs, + struct quad_header *quads[], + unsigned nr) +{ + boolean interp_depth = !qs->softpipe->fs->info.writes_z; + + boolean alpha = qs->softpipe->depth_stencil->alpha.enabled; + + boolean depth = qs->softpipe->depth_stencil->depth.enabled; + + unsigned depthfunc = qs->softpipe->depth_stencil->depth.func; + + boolean stencil = qs->softpipe->depth_stencil->stencil[0].enabled; + + boolean depthwrite = qs->softpipe->depth_stencil->depth.writemask; + + boolean occlusion = qs->softpipe->active_query_count; + + if(!qs->softpipe->framebuffer.zsbuf) + depth = depthwrite = stencil = FALSE; + + /* default */ + qs->run = depth_test_quads_fallback; + + /* look for special cases */ + if (!alpha && + !depth && + !occlusion && + !stencil) { + qs->run = depth_noop; + } + else if (!alpha && + interp_depth && + depth && + depthwrite && + !occlusion && + !stencil) + { + if (qs->softpipe->framebuffer.zsbuf->format == PIPE_FORMAT_Z16_UNORM) { + switch (depthfunc) { + case PIPE_FUNC_NEVER: + qs->run = depth_test_quads_fallback; + break; + case PIPE_FUNC_LESS: + qs->run = depth_interp_z16_less_write; + break; + case PIPE_FUNC_EQUAL: + qs->run = depth_interp_z16_equal_write; + break; + case PIPE_FUNC_LEQUAL: + qs->run = depth_interp_z16_lequal_write; + break; + case PIPE_FUNC_GREATER: + qs->run = depth_interp_z16_greater_write; + break; + case PIPE_FUNC_NOTEQUAL: + qs->run = depth_interp_z16_notequal_write; + break; + case PIPE_FUNC_GEQUAL: + qs->run = depth_interp_z16_gequal_write; + break; + case PIPE_FUNC_ALWAYS: + qs->run = depth_interp_z16_always_write; + break; + default: + qs->run = depth_test_quads_fallback; + break; + } + } + } + + /* next quad/fragment stage */ + qs->run( qs, quads, nr ); +} + + + +static void +depth_test_begin(struct quad_stage *qs) +{ + qs->run = choose_depth_test; + qs->next->begin(qs->next); +} + + +static void +depth_test_destroy(struct quad_stage *qs) +{ + FREE( qs ); +} + + +struct quad_stage * +sp_quad_depth_test_stage(struct softpipe_context *softpipe) +{ + struct quad_stage *stage = CALLOC_STRUCT(quad_stage); + + stage->softpipe = softpipe; + stage->begin = depth_test_begin; + stage->run = choose_depth_test; + stage->destroy = depth_test_destroy; + + return stage; +} diff --git a/src/gallium/drivers/softpipe/sp_quad_depth_test_tmp.h b/src/gallium/drivers/softpipe/sp_quad_depth_test_tmp.h new file mode 100644 index 0000000..25af415 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_quad_depth_test_tmp.h @@ -0,0 +1,147 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL THE 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. + * + **************************************************************************/ + + +/* + * Template for generating Z test functions + * Only PIPE_FORMAT_Z16_UNORM supported at this time. + */ + + +#ifndef NAME +#error "NAME is not defined!" +#endif + +#if !defined(OPERATOR) && !defined(ALWAYS) +#error "neither OPERATOR nor ALWAYS is defined!" +#endif + + +/* + * NOTE: there's no guarantee that the quads are sequentially side by + * side. The fragment shader may have culled some quads, etc. Sliver + * triangles may generate non-sequential quads. + */ +static void +NAME(struct quad_stage *qs, + struct quad_header *quads[], + unsigned nr) +{ + unsigned i, pass = 0; + const unsigned ix = quads[0]->input.x0; + const unsigned iy = quads[0]->input.y0; + const float fx = (float) ix; + const float fy = (float) iy; + const float dzdx = quads[0]->posCoef->dadx[2]; + const float dzdy = quads[0]->posCoef->dady[2]; + const float z0 = quads[0]->posCoef->a0[2] + dzdx * fx + dzdy * fy; + struct softpipe_cached_tile *tile; + ushort (*depth16)[TILE_SIZE]; + ushort init_idepth[4], idepth[4], depth_step; + const float scale = 65535.0; + + /* compute scaled depth of the four pixels in first quad */ + init_idepth[0] = (ushort)((z0) * scale); + init_idepth[1] = (ushort)((z0 + dzdx) * scale); + init_idepth[2] = (ushort)((z0 + dzdy) * scale); + init_idepth[3] = (ushort)((z0 + dzdx + dzdy) * scale); + + depth_step = (ushort)(dzdx * scale); + + tile = sp_get_cached_tile(qs->softpipe->zsbuf_cache, ix, iy); + + for (i = 0; i < nr; i++) { + const unsigned outmask = quads[i]->inout.mask; + const int dx = quads[i]->input.x0 - ix; + unsigned mask = 0; + + /* compute depth for this quad */ + idepth[0] = init_idepth[0] + dx * depth_step; + idepth[1] = init_idepth[1] + dx * depth_step; + idepth[2] = init_idepth[2] + dx * depth_step; + idepth[3] = init_idepth[3] + dx * depth_step; + + depth16 = (ushort (*)[TILE_SIZE]) + &tile->data.depth16[iy % TILE_SIZE][(ix + dx)% TILE_SIZE]; + +#ifdef ALWAYS + if (outmask & 1) { + depth16[0][0] = idepth[0]; + mask |= (1 << 0); + } + + if (outmask & 2) { + depth16[0][1] = idepth[1]; + mask |= (1 << 1); + } + + if (outmask & 4) { + depth16[1][0] = idepth[2]; + mask |= (1 << 2); + } + + if (outmask & 8) { + depth16[1][1] = idepth[3]; + mask |= (1 << 3); + } +#else + /* Note: OPERATOR appears here: */ + if ((outmask & 1) && (idepth[0] OPERATOR depth16[0][0])) { + depth16[0][0] = idepth[0]; + mask |= (1 << 0); + } + + if ((outmask & 2) && (idepth[1] OPERATOR depth16[0][1])) { + depth16[0][1] = idepth[1]; + mask |= (1 << 1); + } + + if ((outmask & 4) && (idepth[2] OPERATOR depth16[1][0])) { + depth16[1][0] = idepth[2]; + mask |= (1 << 2); + } + + if ((outmask & 8) && (idepth[3] OPERATOR depth16[1][1])) { + depth16[1][1] = idepth[3]; + mask |= (1 << 3); + } +#endif + + depth16 = (ushort (*)[TILE_SIZE]) &depth16[0][2]; + + quads[i]->inout.mask = mask; + if (quads[i]->inout.mask) + quads[pass++] = quads[i]; + } + + if (pass) + qs->next->run(qs->next, quads, pass); +} + + +#undef NAME +#undef OPERATOR +#undef ALWAYS diff --git a/src/gallium/drivers/softpipe/sp_quad_fs.c b/src/gallium/drivers/softpipe/sp_quad_fs.c new file mode 100644 index 0000000..90f4787 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_quad_fs.c @@ -0,0 +1,176 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2008 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 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. + * + **************************************************************************/ + +/* Vertices are just an array of floats, with all the attributes + * packed. We currently assume a layout like: + * + * attr[0][0..3] - window position + * attr[1..n][0..3] - remaining attributes. + * + * Attributes are assumed to be 4 floats wide but are packed so that + * all the enabled attributes run contiguously. + */ + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" + +#include "sp_context.h" +#include "sp_state.h" +#include "sp_quad.h" +#include "sp_quad_pipe.h" + + +struct quad_shade_stage +{ + struct quad_stage stage; /**< base class */ + + /* no other fields at this time */ +}; + + +/** cast wrapper */ +static INLINE struct quad_shade_stage * +quad_shade_stage(struct quad_stage *qs) +{ + return (struct quad_shade_stage *) qs; +} + + +/** + * Execute fragment shader for the four fragments in the quad. + * \return TRUE if quad is alive, FALSE if all four pixels are killed + */ +static INLINE boolean +shade_quad(struct quad_stage *qs, struct quad_header *quad) +{ + struct softpipe_context *softpipe = qs->softpipe; + struct tgsi_exec_machine *machine = softpipe->fs_machine; + + /* run shader */ + return softpipe->fs->run( softpipe->fs, machine, quad ); +} + + + +static void +coverage_quad(struct quad_stage *qs, struct quad_header *quad) +{ + struct softpipe_context *softpipe = qs->softpipe; + uint cbuf; + + /* loop over colorbuffer outputs */ + for (cbuf = 0; cbuf < softpipe->framebuffer.nr_cbufs; cbuf++) { + float (*quadColor)[4] = quad->output.color[cbuf]; + unsigned j; + for (j = 0; j < QUAD_SIZE; j++) { + assert(quad->input.coverage[j] >= 0.0); + assert(quad->input.coverage[j] <= 1.0); + quadColor[3][j] *= quad->input.coverage[j]; + } + } +} + + +/** + * Shade/write an array of quads + * Called via quad_stage::run() + */ +static void +shade_quads(struct quad_stage *qs, + struct quad_header *quads[], + unsigned nr) +{ + struct softpipe_context *softpipe = qs->softpipe; + struct tgsi_exec_machine *machine = softpipe->fs_machine; + unsigned i, nr_quads = 0; + + tgsi_exec_set_constant_buffers(machine, PIPE_MAX_CONSTANT_BUFFERS, + softpipe->mapped_constants[PIPE_SHADER_FRAGMENT], + softpipe->const_buffer_size[PIPE_SHADER_FRAGMENT]); + + machine->InterpCoefs = quads[0]->coef; + + for (i = 0; i < nr; i++) { + if (!shade_quad(qs, quads[i])) + continue; /* quad totally culled/killed */ + + if (/*do_coverage*/ 0) + coverage_quad( qs, quads[i] ); + + quads[nr_quads++] = quads[i]; + } + + if (nr_quads) + qs->next->run(qs->next, quads, nr_quads); +} + + +/** + * Per-primitive (or per-begin?) setup + */ +static void +shade_begin(struct quad_stage *qs) +{ + struct softpipe_context *softpipe = qs->softpipe; + + softpipe->fs->prepare( softpipe->fs, + softpipe->fs_machine, + (struct tgsi_sampler **) + softpipe->tgsi.frag_samplers_list ); + + qs->next->begin(qs->next); +} + + +static void +shade_destroy(struct quad_stage *qs) +{ + FREE( qs ); +} + + +struct quad_stage * +sp_quad_shade_stage( struct softpipe_context *softpipe ) +{ + struct quad_shade_stage *qss = CALLOC_STRUCT(quad_shade_stage); + if (!qss) + goto fail; + + qss->stage.softpipe = softpipe; + qss->stage.begin = shade_begin; + qss->stage.run = shade_quads; + qss->stage.destroy = shade_destroy; + + return &qss->stage; + +fail: + FREE(qss); + return NULL; +} diff --git a/src/gallium/drivers/softpipe/sp_quad_pipe.c b/src/gallium/drivers/softpipe/sp_quad_pipe.c new file mode 100644 index 0000000..2cfd02a --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_quad_pipe.c @@ -0,0 +1,69 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "sp_context.h" +#include "sp_state.h" +#include "pipe/p_shader_tokens.h" + +static void +sp_push_quad_first( struct softpipe_context *sp, + struct quad_stage *quad ) +{ + quad->next = sp->quad.first; + sp->quad.first = quad; +} + + +void +sp_build_quad_pipeline(struct softpipe_context *sp) +{ + boolean early_depth_test = + sp->depth_stencil->depth.enabled && + sp->framebuffer.zsbuf && + !sp->depth_stencil->alpha.enabled && + !sp->fs->info.uses_kill && + !sp->fs->info.writes_z && + !sp->fs->info.writes_stencil; + + sp->quad.first = sp->quad.blend; + + if (early_depth_test) { + sp_push_quad_first( sp, sp->quad.shade ); + sp_push_quad_first( sp, sp->quad.depth_test ); + } + else { + sp_push_quad_first( sp, sp->quad.depth_test ); + sp_push_quad_first( sp, sp->quad.shade ); + } + +#if !DO_PSTIPPLE_IN_DRAW_MODULE + if (sp->rasterizer->poly_stipple_enable) + sp_push_quad_first( sp, sp->quad.pstipple ); +#endif +} + diff --git a/src/gallium/drivers/softpipe/sp_quad_pipe.h b/src/gallium/drivers/softpipe/sp_quad_pipe.h new file mode 100644 index 0000000..c0aa134 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_quad_pipe.h @@ -0,0 +1,72 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef SP_QUAD_PIPE_H +#define SP_QUAD_PIPE_H + + +struct softpipe_context; +struct quad_header; + + +/** + * Fragment processing is performed on 2x2 blocks of pixels called "quads". + * Quad processing is performed with a pipeline of stages represented by + * this type. + */ +struct quad_stage { + struct softpipe_context *softpipe; + + struct quad_stage *next; + + void (*begin)(struct quad_stage *qs); + + /** the stage action */ + void (*run)(struct quad_stage *qs, struct quad_header *quad[], unsigned nr); + + void (*destroy)(struct quad_stage *qs); +}; + + +struct quad_stage *sp_quad_polygon_stipple_stage( struct softpipe_context *softpipe ); +struct quad_stage *sp_quad_earlyz_stage( struct softpipe_context *softpipe ); +struct quad_stage *sp_quad_shade_stage( struct softpipe_context *softpipe ); +struct quad_stage *sp_quad_alpha_test_stage( struct softpipe_context *softpipe ); +struct quad_stage *sp_quad_stencil_test_stage( struct softpipe_context *softpipe ); +struct quad_stage *sp_quad_depth_test_stage( struct softpipe_context *softpipe ); +struct quad_stage *sp_quad_occlusion_stage( struct softpipe_context *softpipe ); +struct quad_stage *sp_quad_coverage_stage( struct softpipe_context *softpipe ); +struct quad_stage *sp_quad_blend_stage( struct softpipe_context *softpipe ); +struct quad_stage *sp_quad_colormask_stage( struct softpipe_context *softpipe ); +struct quad_stage *sp_quad_output_stage( struct softpipe_context *softpipe ); + +void sp_build_quad_pipeline(struct softpipe_context *sp); + +#endif /* SP_QUAD_PIPE_H */ diff --git a/src/gallium/drivers/softpipe/sp_quad_stipple.c b/src/gallium/drivers/softpipe/sp_quad_stipple.c new file mode 100644 index 0000000..a0527a5 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_quad_stipple.c @@ -0,0 +1,81 @@ + +/** + * quad polygon stipple stage + */ + +#include "sp_context.h" +#include "sp_quad.h" +#include "sp_quad_pipe.h" +#include "pipe/p_defines.h" +#include "util/u_memory.h" + + +/** + * Apply polygon stipple to quads produced by triangle rasterization + */ +static void +stipple_quad(struct quad_stage *qs, struct quad_header *quads[], unsigned nr) +{ + static const uint bit31 = 1 << 31; + static const uint bit30 = 1 << 30; + unsigned pass = nr; + + struct softpipe_context *softpipe = qs->softpipe; + unsigned q; + + pass = 0; + + for (q = 0; q < nr; q++) { + struct quad_header *quad = quads[q]; + + const int col0 = quad->input.x0 % 32; + const int y0 = quad->input.y0; + const int y1 = y0 + 1; + const uint stipple0 = softpipe->poly_stipple.stipple[y0 % 32]; + const uint stipple1 = softpipe->poly_stipple.stipple[y1 % 32]; + + /* turn off quad mask bits that fail the stipple test */ + if ((stipple0 & (bit31 >> col0)) == 0) + quad->inout.mask &= ~MASK_TOP_LEFT; + + if ((stipple0 & (bit30 >> col0)) == 0) + quad->inout.mask &= ~MASK_TOP_RIGHT; + + if ((stipple1 & (bit31 >> col0)) == 0) + quad->inout.mask &= ~MASK_BOTTOM_LEFT; + + if ((stipple1 & (bit30 >> col0)) == 0) + quad->inout.mask &= ~MASK_BOTTOM_RIGHT; + + if (quad->inout.mask) + quads[pass++] = quad; + } + + qs->next->run(qs->next, quads, pass); +} + + +static void stipple_begin(struct quad_stage *qs) +{ + qs->next->begin(qs->next); +} + + +static void stipple_destroy(struct quad_stage *qs) +{ + FREE( qs ); +} + + +struct quad_stage * +sp_quad_polygon_stipple_stage( struct softpipe_context *softpipe ) +{ + struct quad_stage *stage = CALLOC_STRUCT(quad_stage); + + stage->softpipe = softpipe; + stage->begin = stipple_begin; + stage->run = stipple_quad; + stage->destroy = stipple_destroy; + + return stage; +} diff --git a/src/gallium/drivers/softpipe/sp_query.c b/src/gallium/drivers/softpipe/sp_query.c new file mode 100644 index 0000000..4ae69c1 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_query.c @@ -0,0 +1,207 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Author: + * Keith Whitwell + */ + +#include "draw/draw_context.h" +#include "os/os_time.h" +#include "pipe/p_defines.h" +#include "util/u_memory.h" +#include "sp_context.h" +#include "sp_query.h" +#include "sp_state.h" + +struct softpipe_query { + unsigned type; + uint64_t start; + uint64_t end; + struct pipe_query_data_so_statistics so; +}; + + +static struct softpipe_query *softpipe_query( struct pipe_query *p ) +{ + return (struct softpipe_query *)p; +} + +static struct pipe_query * +softpipe_create_query(struct pipe_context *pipe, + unsigned type) +{ + struct softpipe_query* sq; + + assert(type == PIPE_QUERY_OCCLUSION_COUNTER || + type == PIPE_QUERY_TIME_ELAPSED || + type == PIPE_QUERY_SO_STATISTICS || + type == PIPE_QUERY_GPU_FINISHED || + type == PIPE_QUERY_TIMESTAMP_DISJOINT); + sq = CALLOC_STRUCT( softpipe_query ); + sq->type = type; + + return (struct pipe_query *)sq; +} + + +static void +softpipe_destroy_query(struct pipe_context *pipe, struct pipe_query *q) +{ + FREE(q); +} + + +static void +softpipe_begin_query(struct pipe_context *pipe, struct pipe_query *q) +{ + struct softpipe_context *softpipe = softpipe_context( pipe ); + struct softpipe_query *sq = softpipe_query(q); + + switch (sq->type) { + case PIPE_QUERY_OCCLUSION_COUNTER: + sq->start = softpipe->occlusion_count; + break; + case PIPE_QUERY_TIME_ELAPSED: + sq->start = 1000*os_time_get(); + break; + case PIPE_QUERY_SO_STATISTICS: + sq->so.num_primitives_written = 0; + sq->so.primitives_storage_needed = 0; + break; + case PIPE_QUERY_GPU_FINISHED: + break; + case PIPE_QUERY_TIMESTAMP_DISJOINT: + default: + assert(0); + break; + } + softpipe->active_query_count++; + softpipe->dirty |= SP_NEW_QUERY; +} + + +static void +softpipe_end_query(struct pipe_context *pipe, struct pipe_query *q) +{ + struct softpipe_context *softpipe = softpipe_context( pipe ); + struct softpipe_query *sq = softpipe_query(q); + + softpipe->active_query_count--; + switch (sq->type) { + case PIPE_QUERY_OCCLUSION_COUNTER: + sq->end = softpipe->occlusion_count; + break; + case PIPE_QUERY_TIME_ELAPSED: + sq->end = 1000*os_time_get(); + break; + case PIPE_QUERY_SO_STATISTICS: + sq->so.num_primitives_written = + softpipe->so_stats.num_primitives_written; + sq->so.primitives_storage_needed = + softpipe->so_stats.primitives_storage_needed; + break; + case PIPE_QUERY_GPU_FINISHED: + case PIPE_QUERY_TIMESTAMP_DISJOINT: + break; + default: + assert(0); + break; + } + softpipe->dirty |= SP_NEW_QUERY; +} + + +static boolean +softpipe_get_query_result(struct pipe_context *pipe, + struct pipe_query *q, + boolean wait, + void *vresult) +{ + struct softpipe_query *sq = softpipe_query(q); + uint64_t *result = (uint64_t*)vresult; + + switch (sq->type) { + case PIPE_QUERY_SO_STATISTICS: + memcpy(vresult, &sq->so, + sizeof(struct pipe_query_data_so_statistics)); + break; + case PIPE_QUERY_GPU_FINISHED: + *result = TRUE; + break; + case PIPE_QUERY_TIMESTAMP_DISJOINT: { + struct pipe_query_data_timestamp_disjoint td; + /*os_get_time is in microseconds*/ + td.frequency = 1000000; + td.disjoint = FALSE; + memcpy(vresult, &sq->so, + sizeof(struct pipe_query_data_timestamp_disjoint)); + } + break; + default: + *result = sq->end - sq->start; + break; + } + return TRUE; +} + + +/** + * Called by rendering function to check rendering is conditional. + * \return TRUE if we should render, FALSE if we should skip rendering + */ +boolean +softpipe_check_render_cond(struct softpipe_context *sp) +{ + struct pipe_context *pipe = &sp->pipe; + boolean b, wait; + uint64_t result; + + if (!sp->render_cond_query) { + return TRUE; /* no query predicate, draw normally */ + } + + wait = (sp->render_cond_mode == PIPE_RENDER_COND_WAIT || + sp->render_cond_mode == PIPE_RENDER_COND_BY_REGION_WAIT); + + b = pipe->get_query_result(pipe, sp->render_cond_query, wait, &result); + if (b) + return result > 0; + else + return TRUE; +} + + +void softpipe_init_query_funcs(struct softpipe_context *softpipe ) +{ + softpipe->pipe.create_query = softpipe_create_query; + softpipe->pipe.destroy_query = softpipe_destroy_query; + softpipe->pipe.begin_query = softpipe_begin_query; + softpipe->pipe.end_query = softpipe_end_query; + softpipe->pipe.get_query_result = softpipe_get_query_result; +} + + diff --git a/src/gallium/drivers/softpipe/sp_query.h b/src/gallium/drivers/softpipe/sp_query.h new file mode 100644 index 0000000..736c033 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_query.h @@ -0,0 +1,43 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Author: + * Keith Whitwell + */ + +#ifndef SP_QUERY_H +#define SP_QUERY_H + +extern boolean +softpipe_check_render_cond(struct softpipe_context *sp); + + +struct softpipe_context; +extern void softpipe_init_query_funcs(struct softpipe_context * ); + + +#endif /* SP_QUERY_H */ diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c new file mode 100644 index 0000000..cbdea19 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_screen.c @@ -0,0 +1,314 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "util/u_memory.h" +#include "util/u_format.h" +#include "util/u_format_s3tc.h" +#include "pipe/p_defines.h" +#include "pipe/p_screen.h" +#include "draw/draw_context.h" + +#include "state_tracker/sw_winsys.h" +#include "tgsi/tgsi_exec.h" + +#include "sp_texture.h" +#include "sp_screen.h" +#include "sp_context.h" +#include "sp_fence.h" +#include "sp_public.h" + + +static const char * +softpipe_get_vendor(struct pipe_screen *screen) +{ + return "VMware, Inc."; +} + + +static const char * +softpipe_get_name(struct pipe_screen *screen) +{ + return "softpipe"; +} + + +static int +softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param) +{ + switch (param) { + case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: + return PIPE_MAX_SAMPLERS; + case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS: +#ifdef HAVE_LLVM + /* Softpipe doesn't yet know how to tell draw/llvm about textures */ + return 0; +#else + return PIPE_MAX_VERTEX_SAMPLERS; +#endif + case PIPE_CAP_MAX_COMBINED_SAMPLERS: + return PIPE_MAX_SAMPLERS + PIPE_MAX_VERTEX_SAMPLERS; + case PIPE_CAP_NPOT_TEXTURES: + return 1; + case PIPE_CAP_TWO_SIDED_STENCIL: + return 1; + case PIPE_CAP_GLSL: + return 1; + case PIPE_CAP_SM3: + return 1; + case PIPE_CAP_ANISOTROPIC_FILTER: + return 0; + case PIPE_CAP_POINT_SPRITE: + return 1; + case PIPE_CAP_MAX_RENDER_TARGETS: + return PIPE_MAX_COLOR_BUFS; + case PIPE_CAP_OCCLUSION_QUERY: + return 1; + case PIPE_CAP_TIMER_QUERY: + return 1; + case PIPE_CAP_TEXTURE_MIRROR_CLAMP: + return 1; + case PIPE_CAP_TEXTURE_MIRROR_REPEAT: + return 1; + case PIPE_CAP_TEXTURE_SHADOW_MAP: + return 1; + case PIPE_CAP_TEXTURE_SWIZZLE: + return 1; + case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: + return SP_MAX_TEXTURE_2D_LEVELS; + case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: + return SP_MAX_TEXTURE_3D_LEVELS; + case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: + return SP_MAX_TEXTURE_2D_LEVELS; + case PIPE_CAP_BLEND_EQUATION_SEPARATE: + return 1; + case PIPE_CAP_INDEP_BLEND_ENABLE: + return 1; + case PIPE_CAP_INDEP_BLEND_FUNC: + return 1; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: + return 1; + case PIPE_CAP_STREAM_OUTPUT: + return 1; + case PIPE_CAP_PRIMITIVE_RESTART: + return 1; + case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: + return 0; + case PIPE_CAP_SHADER_STENCIL_EXPORT: + return 1; + default: + return 0; + } +} + +static int +softpipe_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shader_cap param) +{ + switch(shader) + { + case PIPE_SHADER_FRAGMENT: + return tgsi_exec_get_shader_param(param); + case PIPE_SHADER_VERTEX: + case PIPE_SHADER_GEOMETRY: + return draw_get_shader_param(shader, param); + default: + return 0; + } +} + +static float +softpipe_get_paramf(struct pipe_screen *screen, enum pipe_cap param) +{ + switch (param) { + case PIPE_CAP_MAX_LINE_WIDTH: + /* fall-through */ + case PIPE_CAP_MAX_LINE_WIDTH_AA: + return 255.0; /* arbitrary */ + case PIPE_CAP_MAX_POINT_WIDTH: + /* fall-through */ + case PIPE_CAP_MAX_POINT_WIDTH_AA: + return 255.0; /* arbitrary */ + case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: + return 16.0; /* not actually signficant at this time */ + case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: + return 16.0; /* arbitrary */ + default: + return 0; + } +} + + +/** + * Query format support for creating a texture, drawing surface, etc. + * \param format the format to test + * \param type one of PIPE_TEXTURE, PIPE_SURFACE + */ +static boolean +softpipe_is_format_supported( struct pipe_screen *screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned bind, + unsigned geom_flags ) +{ + struct sw_winsys *winsys = softpipe_screen(screen)->winsys; + const struct util_format_description *format_desc; + + assert(target == PIPE_BUFFER || + target == PIPE_TEXTURE_1D || + target == PIPE_TEXTURE_2D || + target == PIPE_TEXTURE_RECT || + target == PIPE_TEXTURE_3D || + target == PIPE_TEXTURE_CUBE); + + format_desc = util_format_description(format); + if (!format_desc) + return FALSE; + + if (sample_count > 1) + return FALSE; + + if (bind & (PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SCANOUT | + PIPE_BIND_SHARED)) { + if(!winsys->is_displaytarget_format_supported(winsys, bind, format)) + return FALSE; + } + + if (bind & PIPE_BIND_RENDER_TARGET) { + if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) + return FALSE; + + /* + * Although possible, it is unnatural to render into compressed or YUV + * surfaces. So disable these here to avoid going into weird paths + * inside the state trackers. + */ + if (format_desc->block.width != 1 || + format_desc->block.height != 1) + return FALSE; + } + + if (bind & PIPE_BIND_DEPTH_STENCIL) { + if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS) + return FALSE; + + /* + * TODO: Unfortunately we cannot render into anything more than 32 bits + * because we encode depth and stencil clear values into a 32bit word. + */ + if (format_desc->block.bits > 32) + return FALSE; + + /* + * TODO: eliminate this restriction + */ + if (format == PIPE_FORMAT_Z32_FLOAT) + return FALSE; + } + + /* + * All other operations (sampling, transfer, etc). + */ + + if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) { + return util_format_s3tc_enabled; + } + + /* + * Everything else should be supported by u_format. + */ + return TRUE; +} + + +static void +softpipe_destroy_screen( struct pipe_screen *screen ) +{ + struct softpipe_screen *sp_screen = softpipe_screen(screen); + struct sw_winsys *winsys = sp_screen->winsys; + + if(winsys->destroy) + winsys->destroy(winsys); + + FREE(screen); +} + + +/* This is often overriden by the co-state tracker. + */ +static void +softpipe_flush_frontbuffer(struct pipe_screen *_screen, + struct pipe_resource *resource, + unsigned level, unsigned layer, + void *context_private) +{ + struct softpipe_screen *screen = softpipe_screen(_screen); + struct sw_winsys *winsys = screen->winsys; + struct softpipe_resource *texture = softpipe_resource(resource); + + assert(texture->dt); + if (texture->dt) + winsys->displaytarget_display(winsys, texture->dt, context_private); +} + +/** + * Create a new pipe_screen object + * Note: we're not presently subclassing pipe_screen (no softpipe_screen). + */ +struct pipe_screen * +softpipe_create_screen(struct sw_winsys *winsys) +{ + struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen); + + if (!screen) + return NULL; + + screen->winsys = winsys; + + screen->base.winsys = NULL; + screen->base.destroy = softpipe_destroy_screen; + + screen->base.get_name = softpipe_get_name; + screen->base.get_vendor = softpipe_get_vendor; + screen->base.get_param = softpipe_get_param; + screen->base.get_shader_param = softpipe_get_shader_param; + screen->base.get_paramf = softpipe_get_paramf; + screen->base.is_format_supported = softpipe_is_format_supported; + screen->base.context_create = softpipe_create_context; + screen->base.flush_frontbuffer = softpipe_flush_frontbuffer; + + util_format_s3tc_init(); + + softpipe_init_screen_texture_funcs(&screen->base); + softpipe_init_screen_fence_funcs(&screen->base); + + return &screen->base; +} diff --git a/src/gallium/drivers/softpipe/sp_screen.h b/src/gallium/drivers/softpipe/sp_screen.h new file mode 100644 index 0000000..f741454 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_screen.h @@ -0,0 +1,62 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef SP_SCREEN_H +#define SP_SCREEN_H + +#include "pipe/p_screen.h" +#include "pipe/p_defines.h" + + +struct sw_winsys; + +struct softpipe_screen { + struct pipe_screen base; + + struct sw_winsys *winsys; + + /* Increments whenever textures are modified. Contexts can track + * this. + */ + unsigned timestamp; +}; + + + + +static INLINE struct softpipe_screen * +softpipe_screen( struct pipe_screen *pipe ) +{ + return (struct softpipe_screen *)pipe; +} + + + +#endif /* SP_SCREEN_H */ diff --git a/src/gallium/drivers/softpipe/sp_setup.c b/src/gallium/drivers/softpipe/sp_setup.c new file mode 100644 index 0000000..0ce28f4 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_setup.c @@ -0,0 +1,1447 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * \brief Primitive rasterization/rendering (points, lines, triangles) + * + * \author Keith Whitwell + * \author Brian Paul + */ + +#include "sp_context.h" +#include "sp_quad.h" +#include "sp_quad_pipe.h" +#include "sp_setup.h" +#include "sp_state.h" +#include "draw/draw_context.h" +#include "draw/draw_vertex.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_math.h" +#include "util/u_memory.h" + + +#define DEBUG_VERTS 0 +#define DEBUG_FRAGS 0 + + +/** + * Triangle edge info + */ +struct edge { + float dx; /**< X(v1) - X(v0), used only during setup */ + float dy; /**< Y(v1) - Y(v0), used only during setup */ + float dxdy; /**< dx/dy */ + float sx, sy; /**< first sample point coord */ + int lines; /**< number of lines on this edge */ +}; + + +/** + * Max number of quads (2x2 pixel blocks) to process per batch. + * This can't be arbitrarily increased since we depend on some 32-bit + * bitmasks (two bits per quad). + */ +#define MAX_QUADS 16 + + +/** + * Triangle setup info. + * Also used for line drawing (taking some liberties). + */ +struct setup_context { + struct softpipe_context *softpipe; + + /* Vertices are just an array of floats making up each attribute in + * turn. Currently fixed at 4 floats, but should change in time. + * Codegen will help cope with this. + */ + const float (*vmax)[4]; + const float (*vmid)[4]; + const float (*vmin)[4]; + const float (*vprovoke)[4]; + + struct edge ebot; + struct edge etop; + struct edge emaj; + + float oneoverarea; + int facing; + + float pixel_offset; + + struct quad_header quad[MAX_QUADS]; + struct quad_header *quad_ptrs[MAX_QUADS]; + unsigned count; + + struct tgsi_interp_coef coef[PIPE_MAX_SHADER_INPUTS]; + struct tgsi_interp_coef posCoef; /* For Z, W */ + + struct { + int left[2]; /**< [0] = row0, [1] = row1 */ + int right[2]; + int y; + } span; + +#if DEBUG_FRAGS + uint numFragsEmitted; /**< per primitive */ + uint numFragsWritten; /**< per primitive */ +#endif + + unsigned cull_face; /* which faces cull */ + unsigned nr_vertex_attrs; +}; + + + + + + + +/** + * Clip setup->quad against the scissor/surface bounds. + */ +static INLINE void +quad_clip(struct setup_context *setup, struct quad_header *quad) +{ + const struct pipe_scissor_state *cliprect = &setup->softpipe->cliprect; + const int minx = (int) cliprect->minx; + const int maxx = (int) cliprect->maxx; + const int miny = (int) cliprect->miny; + const int maxy = (int) cliprect->maxy; + + if (quad->input.x0 >= maxx || + quad->input.y0 >= maxy || + quad->input.x0 + 1 < minx || + quad->input.y0 + 1 < miny) { + /* totally clipped */ + quad->inout.mask = 0x0; + return; + } + if (quad->input.x0 < minx) + quad->inout.mask &= (MASK_BOTTOM_RIGHT | MASK_TOP_RIGHT); + if (quad->input.y0 < miny) + quad->inout.mask &= (MASK_BOTTOM_LEFT | MASK_BOTTOM_RIGHT); + if (quad->input.x0 == maxx - 1) + quad->inout.mask &= (MASK_BOTTOM_LEFT | MASK_TOP_LEFT); + if (quad->input.y0 == maxy - 1) + quad->inout.mask &= (MASK_TOP_LEFT | MASK_TOP_RIGHT); +} + + +/** + * Emit a quad (pass to next stage) with clipping. + */ +static INLINE void +clip_emit_quad(struct setup_context *setup, struct quad_header *quad) +{ + quad_clip( setup, quad ); + + if (quad->inout.mask) { + struct softpipe_context *sp = setup->softpipe; + + sp->quad.first->run( sp->quad.first, &quad, 1 ); + } +} + + + +/** + * Given an X or Y coordinate, return the block/quad coordinate that it + * belongs to. + */ +static INLINE int +block(int x) +{ + return x & ~(2-1); +} + + +static INLINE int +block_x(int x) +{ + return x & ~(16-1); +} + + +/** + * Render a horizontal span of quads + */ +static void +flush_spans(struct setup_context *setup) +{ + const int step = MAX_QUADS; + const int xleft0 = setup->span.left[0]; + const int xleft1 = setup->span.left[1]; + const int xright0 = setup->span.right[0]; + const int xright1 = setup->span.right[1]; + struct quad_stage *pipe = setup->softpipe->quad.first; + + const int minleft = block_x(MIN2(xleft0, xleft1)); + const int maxright = MAX2(xright0, xright1); + int x; + + /* process quads in horizontal chunks of 16 */ + for (x = minleft; x < maxright; x += step) { + unsigned skip_left0 = CLAMP(xleft0 - x, 0, step); + unsigned skip_left1 = CLAMP(xleft1 - x, 0, step); + unsigned skip_right0 = CLAMP(x + step - xright0, 0, step); + unsigned skip_right1 = CLAMP(x + step - xright1, 0, step); + unsigned lx = x; + unsigned q = 0; + + unsigned skipmask_left0 = (1U << skip_left0) - 1U; + unsigned skipmask_left1 = (1U << skip_left1) - 1U; + + /* These calculations fail when step == 32 and skip_right == 0. + */ + unsigned skipmask_right0 = ~0U << (unsigned)(step - skip_right0); + unsigned skipmask_right1 = ~0U << (unsigned)(step - skip_right1); + + unsigned mask0 = ~skipmask_left0 & ~skipmask_right0; + unsigned mask1 = ~skipmask_left1 & ~skipmask_right1; + + if (mask0 | mask1) { + do { + unsigned quadmask = (mask0 & 3) | ((mask1 & 3) << 2); + if (quadmask) { + setup->quad[q].input.x0 = lx; + setup->quad[q].input.y0 = setup->span.y; + setup->quad[q].input.facing = setup->facing; + setup->quad[q].inout.mask = quadmask; + setup->quad_ptrs[q] = &setup->quad[q]; + q++; + } + mask0 >>= 2; + mask1 >>= 2; + lx += 2; + } while (mask0 | mask1); + + pipe->run( pipe, setup->quad_ptrs, q ); + } + } + + + setup->span.y = 0; + setup->span.right[0] = 0; + setup->span.right[1] = 0; + setup->span.left[0] = 1000000; /* greater than right[0] */ + setup->span.left[1] = 1000000; /* greater than right[1] */ +} + + +#if DEBUG_VERTS +static void +print_vertex(const struct setup_context *setup, + const float (*v)[4]) +{ + int i; + debug_printf(" Vertex: (%p)\n", (void *) v); + for (i = 0; i < setup->nr_vertex_attrs; i++) { + debug_printf(" %d: %f %f %f %f\n", i, + v[i][0], v[i][1], v[i][2], v[i][3]); + if (util_is_inf_or_nan(v[i][0])) { + debug_printf(" NaN!\n"); + } + } +} +#endif + + +/** + * Sort the vertices from top to bottom order, setting up the triangle + * edge fields (ebot, emaj, etop). + * \return FALSE if coords are inf/nan (cull the tri), TRUE otherwise + */ +static boolean +setup_sort_vertices(struct setup_context *setup, + float det, + const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4]) +{ + if (setup->softpipe->rasterizer->flatshade_first) + setup->vprovoke = v0; + else + setup->vprovoke = v2; + + /* determine bottom to top order of vertices */ + { + float y0 = v0[0][1]; + float y1 = v1[0][1]; + float y2 = v2[0][1]; + if (y0 <= y1) { + if (y1 <= y2) { + /* y0<=y1<=y2 */ + setup->vmin = v0; + setup->vmid = v1; + setup->vmax = v2; + } + else if (y2 <= y0) { + /* y2<=y0<=y1 */ + setup->vmin = v2; + setup->vmid = v0; + setup->vmax = v1; + } + else { + /* y0<=y2<=y1 */ + setup->vmin = v0; + setup->vmid = v2; + setup->vmax = v1; + } + } + else { + if (y0 <= y2) { + /* y1<=y0<=y2 */ + setup->vmin = v1; + setup->vmid = v0; + setup->vmax = v2; + } + else if (y2 <= y1) { + /* y2<=y1<=y0 */ + setup->vmin = v2; + setup->vmid = v1; + setup->vmax = v0; + } + else { + /* y1<=y2<=y0 */ + setup->vmin = v1; + setup->vmid = v2; + setup->vmax = v0; + } + } + } + + setup->ebot.dx = setup->vmid[0][0] - setup->vmin[0][0]; + setup->ebot.dy = setup->vmid[0][1] - setup->vmin[0][1]; + setup->emaj.dx = setup->vmax[0][0] - setup->vmin[0][0]; + setup->emaj.dy = setup->vmax[0][1] - setup->vmin[0][1]; + setup->etop.dx = setup->vmax[0][0] - setup->vmid[0][0]; + setup->etop.dy = setup->vmax[0][1] - setup->vmid[0][1]; + + /* + * Compute triangle's area. Use 1/area to compute partial + * derivatives of attributes later. + * + * The area will be the same as prim->det, but the sign may be + * different depending on how the vertices get sorted above. + * + * To determine whether the primitive is front or back facing we + * use the prim->det value because its sign is correct. + */ + { + const float area = (setup->emaj.dx * setup->ebot.dy - + setup->ebot.dx * setup->emaj.dy); + + setup->oneoverarea = 1.0f / area; + + /* + debug_printf("%s one-over-area %f area %f det %f\n", + __FUNCTION__, setup->oneoverarea, area, det ); + */ + if (util_is_inf_or_nan(setup->oneoverarea)) + return FALSE; + } + + /* We need to know if this is a front or back-facing triangle for: + * - the GLSL gl_FrontFacing fragment attribute (bool) + * - two-sided stencil test + * 0 = front-facing, 1 = back-facing + */ + setup->facing = + ((det < 0.0) ^ + (setup->softpipe->rasterizer->front_ccw)); + + { + unsigned face = setup->facing == 0 ? PIPE_FACE_FRONT : PIPE_FACE_BACK; + + if (face & setup->cull_face) + return FALSE; + } + + + /* Prepare pixel offset for rasterisation: + * - pixel center (0.5, 0.5) for GL, or + * - assume (0.0, 0.0) for other APIs. + */ + if (setup->softpipe->rasterizer->gl_rasterization_rules) { + setup->pixel_offset = 0.5f; + } else { + setup->pixel_offset = 0.0f; + } + + return TRUE; +} + + +/* Apply cylindrical wrapping to v0, v1, v2 coordinates, if enabled. + * Input coordinates must be in [0, 1] range, otherwise results are undefined. + * Some combinations of coordinates produce invalid results, + * but this behaviour is acceptable. + */ +static void +tri_apply_cylindrical_wrap(float v0, + float v1, + float v2, + uint cylindrical_wrap, + float output[3]) +{ + if (cylindrical_wrap) { + float delta; + + delta = v1 - v0; + if (delta > 0.5f) { + v0 += 1.0f; + } + else if (delta < -0.5f) { + v1 += 1.0f; + } + + delta = v2 - v1; + if (delta > 0.5f) { + v1 += 1.0f; + } + else if (delta < -0.5f) { + v2 += 1.0f; + } + + delta = v0 - v2; + if (delta > 0.5f) { + v2 += 1.0f; + } + else if (delta < -0.5f) { + v0 += 1.0f; + } + } + + output[0] = v0; + output[1] = v1; + output[2] = v2; +} + + +/** + * Compute a0 for a constant-valued coefficient (GL_FLAT shading). + * The value value comes from vertex[slot][i]. + * The result will be put into setup->coef[slot].a0[i]. + * \param slot which attribute slot + * \param i which component of the slot (0..3) + */ +static void +const_coeff(struct setup_context *setup, + struct tgsi_interp_coef *coef, + uint vertSlot, uint i) +{ + assert(i <= 3); + + coef->dadx[i] = 0; + coef->dady[i] = 0; + + /* need provoking vertex info! + */ + coef->a0[i] = setup->vprovoke[vertSlot][i]; +} + + +/** + * Compute a0, dadx and dady for a linearly interpolated coefficient, + * for a triangle. + * v[0], v[1] and v[2] are vmin, vmid and vmax, respectively. + */ +static void +tri_linear_coeff(struct setup_context *setup, + struct tgsi_interp_coef *coef, + uint i, + const float v[3]) +{ + float botda = v[1] - v[0]; + float majda = v[2] - v[0]; + float a = setup->ebot.dy * majda - botda * setup->emaj.dy; + float b = setup->emaj.dx * botda - majda * setup->ebot.dx; + float dadx = a * setup->oneoverarea; + float dady = b * setup->oneoverarea; + + assert(i <= 3); + + coef->dadx[i] = dadx; + coef->dady[i] = dady; + + /* calculate a0 as the value which would be sampled for the + * fragment at (0,0), taking into account that we want to sample at + * pixel centers, in other words (pixel_offset, pixel_offset). + * + * this is neat but unfortunately not a good way to do things for + * triangles with very large values of dadx or dady as it will + * result in the subtraction and re-addition from a0 of a very + * large number, which means we'll end up loosing a lot of the + * fractional bits and precision from a0. the way to fix this is + * to define a0 as the sample at a pixel center somewhere near vmin + * instead - i'll switch to this later. + */ + coef->a0[i] = (v[0] - + (dadx * (setup->vmin[0][0] - setup->pixel_offset) + + dady * (setup->vmin[0][1] - setup->pixel_offset))); + + /* + debug_printf("attr[%d].%c: %f dx:%f dy:%f\n", + slot, "xyzw"[i], + setup->coef[slot].a0[i], + setup->coef[slot].dadx[i], + setup->coef[slot].dady[i]); + */ +} + + +/** + * Compute a0, dadx and dady for a perspective-corrected interpolant, + * for a triangle. + * We basically multiply the vertex value by 1/w before computing + * the plane coefficients (a0, dadx, dady). + * Later, when we compute the value at a particular fragment position we'll + * divide the interpolated value by the interpolated W at that fragment. + * v[0], v[1] and v[2] are vmin, vmid and vmax, respectively. + */ +static void +tri_persp_coeff(struct setup_context *setup, + struct tgsi_interp_coef *coef, + uint i, + const float v[3]) +{ + /* premultiply by 1/w (v[0][3] is always W): + */ + float mina = v[0] * setup->vmin[0][3]; + float mida = v[1] * setup->vmid[0][3]; + float maxa = v[2] * setup->vmax[0][3]; + float botda = mida - mina; + float majda = maxa - mina; + float a = setup->ebot.dy * majda - botda * setup->emaj.dy; + float b = setup->emaj.dx * botda - majda * setup->ebot.dx; + float dadx = a * setup->oneoverarea; + float dady = b * setup->oneoverarea; + + /* + debug_printf("tri persp %d,%d: %f %f %f\n", vertSlot, i, + setup->vmin[vertSlot][i], + setup->vmid[vertSlot][i], + setup->vmax[vertSlot][i] + ); + */ + assert(i <= 3); + + coef->dadx[i] = dadx; + coef->dady[i] = dady; + coef->a0[i] = (mina - + (dadx * (setup->vmin[0][0] - setup->pixel_offset) + + dady * (setup->vmin[0][1] - setup->pixel_offset))); +} + + +/** + * Special coefficient setup for gl_FragCoord. + * X and Y are trivial, though Y may have to be inverted for OpenGL. + * Z and W are copied from posCoef which should have already been computed. + * We could do a bit less work if we'd examine gl_FragCoord's swizzle mask. + */ +static void +setup_fragcoord_coeff(struct setup_context *setup, uint slot) +{ + struct sp_fragment_shader* spfs = setup->softpipe->fs; + /*X*/ + setup->coef[slot].a0[0] = spfs->pixel_center_integer ? 0.0 : 0.5; + setup->coef[slot].dadx[0] = 1.0; + setup->coef[slot].dady[0] = 0.0; + /*Y*/ + setup->coef[slot].a0[1] = + (spfs->origin_lower_left ? setup->softpipe->framebuffer.height-1 : 0) + + (spfs->pixel_center_integer ? 0.0 : 0.5); + setup->coef[slot].dadx[1] = 0.0; + setup->coef[slot].dady[1] = spfs->origin_lower_left ? -1.0 : 1.0; + /*Z*/ + setup->coef[slot].a0[2] = setup->posCoef.a0[2]; + setup->coef[slot].dadx[2] = setup->posCoef.dadx[2]; + setup->coef[slot].dady[2] = setup->posCoef.dady[2]; + /*W*/ + setup->coef[slot].a0[3] = setup->posCoef.a0[3]; + setup->coef[slot].dadx[3] = setup->posCoef.dadx[3]; + setup->coef[slot].dady[3] = setup->posCoef.dady[3]; +} + + + +/** + * Compute the setup->coef[] array dadx, dady, a0 values. + * Must be called after setup->vmin,vmid,vmax,vprovoke are initialized. + */ +static void +setup_tri_coefficients(struct setup_context *setup) +{ + struct softpipe_context *softpipe = setup->softpipe; + const struct sp_fragment_shader *spfs = softpipe->fs; + const struct vertex_info *vinfo = softpipe_get_vertex_info(softpipe); + uint fragSlot; + float v[3]; + + /* z and w are done by linear interpolation: + */ + v[0] = setup->vmin[0][2]; + v[1] = setup->vmid[0][2]; + v[2] = setup->vmax[0][2]; + tri_linear_coeff(setup, &setup->posCoef, 2, v); + + v[0] = setup->vmin[0][3]; + v[1] = setup->vmid[0][3]; + v[2] = setup->vmax[0][3]; + tri_linear_coeff(setup, &setup->posCoef, 3, v); + + /* setup interpolation for all the remaining attributes: + */ + for (fragSlot = 0; fragSlot < spfs->info.num_inputs; fragSlot++) { + const uint vertSlot = vinfo->attrib[fragSlot].src_index; + uint j; + + switch (vinfo->attrib[fragSlot].interp_mode) { + case INTERP_CONSTANT: + for (j = 0; j < NUM_CHANNELS; j++) + const_coeff(setup, &setup->coef[fragSlot], vertSlot, j); + break; + case INTERP_LINEAR: + for (j = 0; j < NUM_CHANNELS; j++) { + tri_apply_cylindrical_wrap(setup->vmin[vertSlot][j], + setup->vmid[vertSlot][j], + setup->vmax[vertSlot][j], + spfs->info.input_cylindrical_wrap[fragSlot] & (1 << j), + v); + tri_linear_coeff(setup, &setup->coef[fragSlot], j, v); + } + break; + case INTERP_PERSPECTIVE: + for (j = 0; j < NUM_CHANNELS; j++) { + tri_apply_cylindrical_wrap(setup->vmin[vertSlot][j], + setup->vmid[vertSlot][j], + setup->vmax[vertSlot][j], + spfs->info.input_cylindrical_wrap[fragSlot] & (1 << j), + v); + tri_persp_coeff(setup, &setup->coef[fragSlot], j, v); + } + break; + case INTERP_POS: + setup_fragcoord_coeff(setup, fragSlot); + break; + default: + assert(0); + } + + if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FACE) { + /* convert 0 to 1.0 and 1 to -1.0 */ + setup->coef[fragSlot].a0[0] = setup->facing * -2.0f + 1.0f; + setup->coef[fragSlot].dadx[0] = 0.0; + setup->coef[fragSlot].dady[0] = 0.0; + } + } +} + + +static void +setup_tri_edges(struct setup_context *setup) +{ + float vmin_x = setup->vmin[0][0] + setup->pixel_offset; + float vmid_x = setup->vmid[0][0] + setup->pixel_offset; + + float vmin_y = setup->vmin[0][1] - setup->pixel_offset; + float vmid_y = setup->vmid[0][1] - setup->pixel_offset; + float vmax_y = setup->vmax[0][1] - setup->pixel_offset; + + setup->emaj.sy = ceilf(vmin_y); + setup->emaj.lines = (int) ceilf(vmax_y - setup->emaj.sy); + setup->emaj.dxdy = setup->emaj.dy ? setup->emaj.dx / setup->emaj.dy : .0f; + setup->emaj.sx = vmin_x + (setup->emaj.sy - vmin_y) * setup->emaj.dxdy; + + setup->etop.sy = ceilf(vmid_y); + setup->etop.lines = (int) ceilf(vmax_y - setup->etop.sy); + setup->etop.dxdy = setup->etop.dy ? setup->etop.dx / setup->etop.dy : .0f; + setup->etop.sx = vmid_x + (setup->etop.sy - vmid_y) * setup->etop.dxdy; + + setup->ebot.sy = ceilf(vmin_y); + setup->ebot.lines = (int) ceilf(vmid_y - setup->ebot.sy); + setup->ebot.dxdy = setup->ebot.dy ? setup->ebot.dx / setup->ebot.dy : .0f; + setup->ebot.sx = vmin_x + (setup->ebot.sy - vmin_y) * setup->ebot.dxdy; +} + + +/** + * Render the upper or lower half of a triangle. + * Scissoring/cliprect is applied here too. + */ +static void +subtriangle(struct setup_context *setup, + struct edge *eleft, + struct edge *eright, + int lines) +{ + const struct pipe_scissor_state *cliprect = &setup->softpipe->cliprect; + const int minx = (int) cliprect->minx; + const int maxx = (int) cliprect->maxx; + const int miny = (int) cliprect->miny; + const int maxy = (int) cliprect->maxy; + int y, start_y, finish_y; + int sy = (int)eleft->sy; + + assert((int)eleft->sy == (int) eright->sy); + assert(lines >= 0); + + /* clip top/bottom */ + start_y = sy; + if (start_y < miny) + start_y = miny; + + finish_y = sy + lines; + if (finish_y > maxy) + finish_y = maxy; + + start_y -= sy; + finish_y -= sy; + + /* + debug_printf("%s %d %d\n", __FUNCTION__, start_y, finish_y); + */ + + for (y = start_y; y < finish_y; y++) { + + /* avoid accumulating adds as floats don't have the precision to + * accurately iterate large triangle edges that way. luckily we + * can just multiply these days. + * + * this is all drowned out by the attribute interpolation anyway. + */ + int left = (int)(eleft->sx + y * eleft->dxdy); + int right = (int)(eright->sx + y * eright->dxdy); + + /* clip left/right */ + if (left < minx) + left = minx; + if (right > maxx) + right = maxx; + + if (left < right) { + int _y = sy + y; + if (block(_y) != setup->span.y) { + flush_spans(setup); + setup->span.y = block(_y); + } + + setup->span.left[_y&1] = left; + setup->span.right[_y&1] = right; + } + } + + + /* save the values so that emaj can be restarted: + */ + eleft->sx += lines * eleft->dxdy; + eright->sx += lines * eright->dxdy; + eleft->sy += lines; + eright->sy += lines; +} + + +/** + * Recalculate prim's determinant. This is needed as we don't have + * get this information through the vbuf_render interface & we must + * calculate it here. + */ +static float +calc_det(const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4]) +{ + /* edge vectors e = v0 - v2, f = v1 - v2 */ + const float ex = v0[0][0] - v2[0][0]; + const float ey = v0[0][1] - v2[0][1]; + const float fx = v1[0][0] - v2[0][0]; + const float fy = v1[0][1] - v2[0][1]; + + /* det = cross(e,f).z */ + return ex * fy - ey * fx; +} + + +/** + * Do setup for triangle rasterization, then render the triangle. + */ +void +sp_setup_tri(struct setup_context *setup, + const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4]) +{ + float det; + +#if DEBUG_VERTS + debug_printf("Setup triangle:\n"); + print_vertex(setup, v0); + print_vertex(setup, v1); + print_vertex(setup, v2); +#endif + + if (setup->softpipe->no_rast) + return; + + det = calc_det(v0, v1, v2); + /* + debug_printf("%s\n", __FUNCTION__ ); + */ + +#if DEBUG_FRAGS + setup->numFragsEmitted = 0; + setup->numFragsWritten = 0; +#endif + + if (!setup_sort_vertices( setup, det, v0, v1, v2 )) + return; + + setup_tri_coefficients( setup ); + setup_tri_edges( setup ); + + assert(setup->softpipe->reduced_prim == PIPE_PRIM_TRIANGLES); + + setup->span.y = 0; + setup->span.right[0] = 0; + setup->span.right[1] = 0; + /* setup->span.z_mode = tri_z_mode( setup->ctx ); */ + + /* init_constant_attribs( setup ); */ + + if (setup->oneoverarea < 0.0) { + /* emaj on left: + */ + subtriangle( setup, &setup->emaj, &setup->ebot, setup->ebot.lines ); + subtriangle( setup, &setup->emaj, &setup->etop, setup->etop.lines ); + } + else { + /* emaj on right: + */ + subtriangle( setup, &setup->ebot, &setup->emaj, setup->ebot.lines ); + subtriangle( setup, &setup->etop, &setup->emaj, setup->etop.lines ); + } + + flush_spans( setup ); + +#if DEBUG_FRAGS + printf("Tri: %u frags emitted, %u written\n", + setup->numFragsEmitted, + setup->numFragsWritten); +#endif +} + + +/* Apply cylindrical wrapping to v0, v1 coordinates, if enabled. + * Input coordinates must be in [0, 1] range, otherwise results are undefined. + */ +static void +line_apply_cylindrical_wrap(float v0, + float v1, + uint cylindrical_wrap, + float output[2]) +{ + if (cylindrical_wrap) { + float delta; + + delta = v1 - v0; + if (delta > 0.5f) { + v0 += 1.0f; + } + else if (delta < -0.5f) { + v1 += 1.0f; + } + } + + output[0] = v0; + output[1] = v1; +} + + +/** + * Compute a0, dadx and dady for a linearly interpolated coefficient, + * for a line. + * v[0] and v[1] are vmin and vmax, respectively. + */ +static void +line_linear_coeff(const struct setup_context *setup, + struct tgsi_interp_coef *coef, + uint i, + const float v[2]) +{ + const float da = v[1] - v[0]; + const float dadx = da * setup->emaj.dx * setup->oneoverarea; + const float dady = da * setup->emaj.dy * setup->oneoverarea; + coef->dadx[i] = dadx; + coef->dady[i] = dady; + coef->a0[i] = (v[0] - + (dadx * (setup->vmin[0][0] - setup->pixel_offset) + + dady * (setup->vmin[0][1] - setup->pixel_offset))); +} + + +/** + * Compute a0, dadx and dady for a perspective-corrected interpolant, + * for a line. + * v[0] and v[1] are vmin and vmax, respectively. + */ +static void +line_persp_coeff(const struct setup_context *setup, + struct tgsi_interp_coef *coef, + uint i, + const float v[2]) +{ + const float a0 = v[0] * setup->vmin[0][3]; + const float a1 = v[1] * setup->vmax[0][3]; + const float da = a1 - a0; + const float dadx = da * setup->emaj.dx * setup->oneoverarea; + const float dady = da * setup->emaj.dy * setup->oneoverarea; + coef->dadx[i] = dadx; + coef->dady[i] = dady; + coef->a0[i] = (a0 - + (dadx * (setup->vmin[0][0] - setup->pixel_offset) + + dady * (setup->vmin[0][1] - setup->pixel_offset))); +} + + +/** + * Compute the setup->coef[] array dadx, dady, a0 values. + * Must be called after setup->vmin,vmax are initialized. + */ +static boolean +setup_line_coefficients(struct setup_context *setup, + const float (*v0)[4], + const float (*v1)[4]) +{ + struct softpipe_context *softpipe = setup->softpipe; + const struct sp_fragment_shader *spfs = softpipe->fs; + const struct vertex_info *vinfo = softpipe_get_vertex_info(softpipe); + uint fragSlot; + float area; + float v[2]; + + /* use setup->vmin, vmax to point to vertices */ + if (softpipe->rasterizer->flatshade_first) + setup->vprovoke = v0; + else + setup->vprovoke = v1; + setup->vmin = v0; + setup->vmax = v1; + + setup->emaj.dx = setup->vmax[0][0] - setup->vmin[0][0]; + setup->emaj.dy = setup->vmax[0][1] - setup->vmin[0][1]; + + /* NOTE: this is not really area but something proportional to it */ + area = setup->emaj.dx * setup->emaj.dx + setup->emaj.dy * setup->emaj.dy; + if (area == 0.0f || util_is_inf_or_nan(area)) + return FALSE; + setup->oneoverarea = 1.0f / area; + + /* z and w are done by linear interpolation: + */ + v[0] = setup->vmin[0][2]; + v[1] = setup->vmax[0][2]; + line_linear_coeff(setup, &setup->posCoef, 2, v); + + v[0] = setup->vmin[0][3]; + v[1] = setup->vmax[0][3]; + line_linear_coeff(setup, &setup->posCoef, 3, v); + + /* setup interpolation for all the remaining attributes: + */ + for (fragSlot = 0; fragSlot < spfs->info.num_inputs; fragSlot++) { + const uint vertSlot = vinfo->attrib[fragSlot].src_index; + uint j; + + switch (vinfo->attrib[fragSlot].interp_mode) { + case INTERP_CONSTANT: + for (j = 0; j < NUM_CHANNELS; j++) + const_coeff(setup, &setup->coef[fragSlot], vertSlot, j); + break; + case INTERP_LINEAR: + for (j = 0; j < NUM_CHANNELS; j++) { + line_apply_cylindrical_wrap(setup->vmin[vertSlot][j], + setup->vmax[vertSlot][j], + spfs->info.input_cylindrical_wrap[fragSlot] & (1 << j), + v); + line_linear_coeff(setup, &setup->coef[fragSlot], j, v); + } + break; + case INTERP_PERSPECTIVE: + for (j = 0; j < NUM_CHANNELS; j++) { + line_apply_cylindrical_wrap(setup->vmin[vertSlot][j], + setup->vmax[vertSlot][j], + spfs->info.input_cylindrical_wrap[fragSlot] & (1 << j), + v); + line_persp_coeff(setup, &setup->coef[fragSlot], j, v); + } + break; + case INTERP_POS: + setup_fragcoord_coeff(setup, fragSlot); + break; + default: + assert(0); + } + + if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FACE) { + /* convert 0 to 1.0 and 1 to -1.0 */ + setup->coef[fragSlot].a0[0] = setup->facing * -2.0f + 1.0f; + setup->coef[fragSlot].dadx[0] = 0.0; + setup->coef[fragSlot].dady[0] = 0.0; + } + } + return TRUE; +} + + +/** + * Plot a pixel in a line segment. + */ +static INLINE void +plot(struct setup_context *setup, int x, int y) +{ + const int iy = y & 1; + const int ix = x & 1; + const int quadX = x - ix; + const int quadY = y - iy; + const int mask = (1 << ix) << (2 * iy); + + if (quadX != setup->quad[0].input.x0 || + quadY != setup->quad[0].input.y0) + { + /* flush prev quad, start new quad */ + + if (setup->quad[0].input.x0 != -1) + clip_emit_quad( setup, &setup->quad[0] ); + + setup->quad[0].input.x0 = quadX; + setup->quad[0].input.y0 = quadY; + setup->quad[0].inout.mask = 0x0; + } + + setup->quad[0].inout.mask |= mask; +} + + +/** + * Do setup for line rasterization, then render the line. + * Single-pixel width, no stipple, etc. We rely on the 'draw' module + * to handle stippling and wide lines. + */ +void +sp_setup_line(struct setup_context *setup, + const float (*v0)[4], + const float (*v1)[4]) +{ + int x0 = (int) v0[0][0]; + int x1 = (int) v1[0][0]; + int y0 = (int) v0[0][1]; + int y1 = (int) v1[0][1]; + int dx = x1 - x0; + int dy = y1 - y0; + int xstep, ystep; + +#if DEBUG_VERTS + debug_printf("Setup line:\n"); + print_vertex(setup, v0); + print_vertex(setup, v1); +#endif + + if (setup->softpipe->no_rast) + return; + + if (dx == 0 && dy == 0) + return; + + if (!setup_line_coefficients(setup, v0, v1)) + return; + + assert(v0[0][0] < 1.0e9); + assert(v0[0][1] < 1.0e9); + assert(v1[0][0] < 1.0e9); + assert(v1[0][1] < 1.0e9); + + if (dx < 0) { + dx = -dx; /* make positive */ + xstep = -1; + } + else { + xstep = 1; + } + + if (dy < 0) { + dy = -dy; /* make positive */ + ystep = -1; + } + else { + ystep = 1; + } + + assert(dx >= 0); + assert(dy >= 0); + assert(setup->softpipe->reduced_prim == PIPE_PRIM_LINES); + + setup->quad[0].input.x0 = setup->quad[0].input.y0 = -1; + setup->quad[0].inout.mask = 0x0; + + /* XXX temporary: set coverage to 1.0 so the line appears + * if AA mode happens to be enabled. + */ + setup->quad[0].input.coverage[0] = + setup->quad[0].input.coverage[1] = + setup->quad[0].input.coverage[2] = + setup->quad[0].input.coverage[3] = 1.0; + + if (dx > dy) { + /*** X-major line ***/ + int i; + const int errorInc = dy + dy; + int error = errorInc - dx; + const int errorDec = error - dx; + + for (i = 0; i < dx; i++) { + plot(setup, x0, y0); + + x0 += xstep; + if (error < 0) { + error += errorInc; + } + else { + error += errorDec; + y0 += ystep; + } + } + } + else { + /*** Y-major line ***/ + int i; + const int errorInc = dx + dx; + int error = errorInc - dy; + const int errorDec = error - dy; + + for (i = 0; i < dy; i++) { + plot(setup, x0, y0); + + y0 += ystep; + if (error < 0) { + error += errorInc; + } + else { + error += errorDec; + x0 += xstep; + } + } + } + + /* draw final quad */ + if (setup->quad[0].inout.mask) { + clip_emit_quad( setup, &setup->quad[0] ); + } +} + + +static void +point_persp_coeff(const struct setup_context *setup, + const float (*vert)[4], + struct tgsi_interp_coef *coef, + uint vertSlot, uint i) +{ + assert(i <= 3); + coef->dadx[i] = 0.0F; + coef->dady[i] = 0.0F; + coef->a0[i] = vert[vertSlot][i] * vert[0][3]; +} + + +/** + * Do setup for point rasterization, then render the point. + * Round or square points... + * XXX could optimize a lot for 1-pixel points. + */ +void +sp_setup_point(struct setup_context *setup, + const float (*v0)[4]) +{ + struct softpipe_context *softpipe = setup->softpipe; + const struct sp_fragment_shader *spfs = softpipe->fs; + const int sizeAttr = setup->softpipe->psize_slot; + const float size + = sizeAttr > 0 ? v0[sizeAttr][0] + : setup->softpipe->rasterizer->point_size; + const float halfSize = 0.5F * size; + const boolean round = (boolean) setup->softpipe->rasterizer->point_smooth; + const float x = v0[0][0]; /* Note: data[0] is always position */ + const float y = v0[0][1]; + const struct vertex_info *vinfo = softpipe_get_vertex_info(softpipe); + uint fragSlot; + +#if DEBUG_VERTS + debug_printf("Setup point:\n"); + print_vertex(setup, v0); +#endif + + if (softpipe->no_rast) + return; + + assert(setup->softpipe->reduced_prim == PIPE_PRIM_POINTS); + + /* For points, all interpolants are constant-valued. + * However, for point sprites, we'll need to setup texcoords appropriately. + * XXX: which coefficients are the texcoords??? + * We may do point sprites as textured quads... + * + * KW: We don't know which coefficients are texcoords - ultimately + * the choice of what interpolation mode to use for each attribute + * should be determined by the fragment program, using + * per-attribute declaration statements that include interpolation + * mode as a parameter. So either the fragment program will have + * to be adjusted for pointsprite vs normal point behaviour, or + * otherwise a special interpolation mode will have to be defined + * which matches the required behaviour for point sprites. But - + * the latter is not a feature of normal hardware, and as such + * probably should be ruled out on that basis. + */ + setup->vprovoke = v0; + + /* setup Z, W */ + const_coeff(setup, &setup->posCoef, 0, 2); + const_coeff(setup, &setup->posCoef, 0, 3); + + for (fragSlot = 0; fragSlot < spfs->info.num_inputs; fragSlot++) { + const uint vertSlot = vinfo->attrib[fragSlot].src_index; + uint j; + + switch (vinfo->attrib[fragSlot].interp_mode) { + case INTERP_CONSTANT: + /* fall-through */ + case INTERP_LINEAR: + for (j = 0; j < NUM_CHANNELS; j++) + const_coeff(setup, &setup->coef[fragSlot], vertSlot, j); + break; + case INTERP_PERSPECTIVE: + for (j = 0; j < NUM_CHANNELS; j++) + point_persp_coeff(setup, setup->vprovoke, + &setup->coef[fragSlot], vertSlot, j); + break; + case INTERP_POS: + setup_fragcoord_coeff(setup, fragSlot); + break; + default: + assert(0); + } + + if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FACE) { + /* convert 0 to 1.0 and 1 to -1.0 */ + setup->coef[fragSlot].a0[0] = setup->facing * -2.0f + 1.0f; + setup->coef[fragSlot].dadx[0] = 0.0; + setup->coef[fragSlot].dady[0] = 0.0; + } + } + + + if (halfSize <= 0.5 && !round) { + /* special case for 1-pixel points */ + const int ix = ((int) x) & 1; + const int iy = ((int) y) & 1; + setup->quad[0].input.x0 = (int) x - ix; + setup->quad[0].input.y0 = (int) y - iy; + setup->quad[0].inout.mask = (1 << ix) << (2 * iy); + clip_emit_quad( setup, &setup->quad[0] ); + } + else { + if (round) { + /* rounded points */ + const int ixmin = block((int) (x - halfSize)); + const int ixmax = block((int) (x + halfSize)); + const int iymin = block((int) (y - halfSize)); + const int iymax = block((int) (y + halfSize)); + const float rmin = halfSize - 0.7071F; /* 0.7071 = sqrt(2)/2 */ + const float rmax = halfSize + 0.7071F; + const float rmin2 = MAX2(0.0F, rmin * rmin); + const float rmax2 = rmax * rmax; + const float cscale = 1.0F / (rmax2 - rmin2); + int ix, iy; + + for (iy = iymin; iy <= iymax; iy += 2) { + for (ix = ixmin; ix <= ixmax; ix += 2) { + float dx, dy, dist2, cover; + + setup->quad[0].inout.mask = 0x0; + + dx = (ix + 0.5f) - x; + dy = (iy + 0.5f) - y; + dist2 = dx * dx + dy * dy; + if (dist2 <= rmax2) { + cover = 1.0F - (dist2 - rmin2) * cscale; + setup->quad[0].input.coverage[QUAD_TOP_LEFT] = MIN2(cover, 1.0f); + setup->quad[0].inout.mask |= MASK_TOP_LEFT; + } + + dx = (ix + 1.5f) - x; + dy = (iy + 0.5f) - y; + dist2 = dx * dx + dy * dy; + if (dist2 <= rmax2) { + cover = 1.0F - (dist2 - rmin2) * cscale; + setup->quad[0].input.coverage[QUAD_TOP_RIGHT] = MIN2(cover, 1.0f); + setup->quad[0].inout.mask |= MASK_TOP_RIGHT; + } + + dx = (ix + 0.5f) - x; + dy = (iy + 1.5f) - y; + dist2 = dx * dx + dy * dy; + if (dist2 <= rmax2) { + cover = 1.0F - (dist2 - rmin2) * cscale; + setup->quad[0].input.coverage[QUAD_BOTTOM_LEFT] = MIN2(cover, 1.0f); + setup->quad[0].inout.mask |= MASK_BOTTOM_LEFT; + } + + dx = (ix + 1.5f) - x; + dy = (iy + 1.5f) - y; + dist2 = dx * dx + dy * dy; + if (dist2 <= rmax2) { + cover = 1.0F - (dist2 - rmin2) * cscale; + setup->quad[0].input.coverage[QUAD_BOTTOM_RIGHT] = MIN2(cover, 1.0f); + setup->quad[0].inout.mask |= MASK_BOTTOM_RIGHT; + } + + if (setup->quad[0].inout.mask) { + setup->quad[0].input.x0 = ix; + setup->quad[0].input.y0 = iy; + clip_emit_quad( setup, &setup->quad[0] ); + } + } + } + } + else { + /* square points */ + const int xmin = (int) (x + 0.75 - halfSize); + const int ymin = (int) (y + 0.25 - halfSize); + const int xmax = xmin + (int) size; + const int ymax = ymin + (int) size; + /* XXX could apply scissor to xmin,ymin,xmax,ymax now */ + const int ixmin = block(xmin); + const int ixmax = block(xmax - 1); + const int iymin = block(ymin); + const int iymax = block(ymax - 1); + int ix, iy; + + /* + debug_printf("(%f, %f) -> X:%d..%d Y:%d..%d\n", x, y, xmin, xmax,ymin,ymax); + */ + for (iy = iymin; iy <= iymax; iy += 2) { + uint rowMask = 0xf; + if (iy < ymin) { + /* above the top edge */ + rowMask &= (MASK_BOTTOM_LEFT | MASK_BOTTOM_RIGHT); + } + if (iy + 1 >= ymax) { + /* below the bottom edge */ + rowMask &= (MASK_TOP_LEFT | MASK_TOP_RIGHT); + } + + for (ix = ixmin; ix <= ixmax; ix += 2) { + uint mask = rowMask; + + if (ix < xmin) { + /* fragment is past left edge of point, turn off left bits */ + mask &= (MASK_BOTTOM_RIGHT | MASK_TOP_RIGHT); + } + if (ix + 1 >= xmax) { + /* past the right edge */ + mask &= (MASK_BOTTOM_LEFT | MASK_TOP_LEFT); + } + + setup->quad[0].inout.mask = mask; + setup->quad[0].input.x0 = ix; + setup->quad[0].input.y0 = iy; + clip_emit_quad( setup, &setup->quad[0] ); + } + } + } + } +} + + +/** + * Called by vbuf code just before we start buffering primitives. + */ +void +sp_setup_prepare(struct setup_context *setup) +{ + struct softpipe_context *sp = setup->softpipe; + + if (sp->dirty) { + softpipe_update_derived(sp); + } + + /* Note: nr_attrs is only used for debugging (vertex printing) */ + setup->nr_vertex_attrs = draw_num_shader_outputs(sp->draw); + + sp->quad.first->begin( sp->quad.first ); + + if (sp->reduced_api_prim == PIPE_PRIM_TRIANGLES && + sp->rasterizer->fill_front == PIPE_POLYGON_MODE_FILL && + sp->rasterizer->fill_back == PIPE_POLYGON_MODE_FILL) { + /* we'll do culling */ + setup->cull_face = sp->rasterizer->cull_face; + } + else { + /* 'draw' will do culling */ + setup->cull_face = PIPE_FACE_NONE; + } +} + + +void +sp_setup_destroy_context(struct setup_context *setup) +{ + FREE( setup ); +} + + +/** + * Create a new primitive setup/render stage. + */ +struct setup_context * +sp_setup_create_context(struct softpipe_context *softpipe) +{ + struct setup_context *setup = CALLOC_STRUCT(setup_context); + unsigned i; + + setup->softpipe = softpipe; + + for (i = 0; i < MAX_QUADS; i++) { + setup->quad[i].coef = setup->coef; + setup->quad[i].posCoef = &setup->posCoef; + } + + setup->span.left[0] = 1000000; /* greater than right[0] */ + setup->span.left[1] = 1000000; /* greater than right[1] */ + + return setup; +} diff --git a/src/gallium/drivers/softpipe/sp_setup.h b/src/gallium/drivers/softpipe/sp_setup.h new file mode 100644 index 0000000..9c8844d --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_setup.h @@ -0,0 +1,53 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +#ifndef SP_SETUP_H +#define SP_SETUP_H + +struct setup_context; +struct softpipe_context; + +void +sp_setup_tri( struct setup_context *setup, + const float (*v0)[4], + const float (*v1)[4], + const float (*v2)[4] ); + +void +sp_setup_line(struct setup_context *setup, + const float (*v0)[4], + const float (*v1)[4]); + +void +sp_setup_point( struct setup_context *setup, + const float (*v0)[4] ); + + +struct setup_context *sp_setup_create_context( struct softpipe_context *softpipe ); +void sp_setup_prepare( struct setup_context *setup ); +void sp_setup_destroy_context( struct setup_context *setup ); + +#endif diff --git a/src/gallium/drivers/softpipe/sp_state.h b/src/gallium/drivers/softpipe/sp_state.h new file mode 100644 index 0000000..525bf23 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_state.h @@ -0,0 +1,173 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef SP_STATE_H +#define SP_STATE_H + +#include "pipe/p_state.h" +#include "tgsi/tgsi_scan.h" + + +#define SP_NEW_VIEWPORT 0x1 +#define SP_NEW_RASTERIZER 0x2 +#define SP_NEW_FS 0x4 +#define SP_NEW_BLEND 0x8 +#define SP_NEW_CLIP 0x10 +#define SP_NEW_SCISSOR 0x20 +#define SP_NEW_STIPPLE 0x40 +#define SP_NEW_FRAMEBUFFER 0x80 +#define SP_NEW_DEPTH_STENCIL_ALPHA 0x100 +#define SP_NEW_CONSTANTS 0x200 +#define SP_NEW_SAMPLER 0x400 +#define SP_NEW_TEXTURE 0x800 +#define SP_NEW_VERTEX 0x1000 +#define SP_NEW_VS 0x2000 +#define SP_NEW_QUERY 0x4000 +#define SP_NEW_GS 0x8000 +#define SP_NEW_SO 0x10000 +#define SP_NEW_SO_BUFFERS 0x20000 + + +struct tgsi_sampler; +struct tgsi_exec_machine; +struct vertex_info; + + +/** + * Subclass of pipe_shader_state (though it doesn't really need to be). + * + * This is starting to look an awful lot like a quad pipeline stage... + */ +struct sp_fragment_shader { + struct pipe_shader_state shader; + + struct tgsi_shader_info info; + + struct draw_fragment_shader *draw_shader; + + boolean origin_lower_left; /**< fragment shader uses lower left position origin? */ + boolean pixel_center_integer; /**< fragment shader uses integer pixel center? */ + + void (*prepare)( const struct sp_fragment_shader *shader, + struct tgsi_exec_machine *machine, + struct tgsi_sampler **samplers); + + /* Run the shader - this interface will get cleaned up in the + * future: + */ + unsigned (*run)( const struct sp_fragment_shader *shader, + struct tgsi_exec_machine *machine, + struct quad_header *quad ); + + + void (*delete)( struct sp_fragment_shader * ); +}; + + +/** Subclass of pipe_shader_state */ +struct sp_vertex_shader { + struct pipe_shader_state shader; + struct draw_vertex_shader *draw_data; + int max_sampler; /* -1 if no samplers */ +}; + +/** Subclass of pipe_shader_state */ +struct sp_geometry_shader { + struct pipe_shader_state shader; + struct draw_geometry_shader *draw_data; + int max_sampler; +}; + +struct sp_velems_state { + unsigned count; + struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS]; +}; + +struct sp_so_state { + struct pipe_stream_output_state base; +}; + + +void +softpipe_init_blend_funcs(struct pipe_context *pipe); + +void +softpipe_init_clip_funcs(struct pipe_context *pipe); + +void +softpipe_init_sampler_funcs(struct pipe_context *pipe); + +void +softpipe_init_rasterizer_funcs(struct pipe_context *pipe); + +void +softpipe_init_shader_funcs(struct pipe_context *pipe); + +void +softpipe_init_streamout_funcs(struct pipe_context *pipe); + +void +softpipe_init_vertex_funcs(struct pipe_context *pipe); + +void +softpipe_set_framebuffer_state(struct pipe_context *, + const struct pipe_framebuffer_state *); + +void +softpipe_update_derived( struct softpipe_context *softpipe ); + +void +softpipe_draw_vbo(struct pipe_context *pipe, + const struct pipe_draw_info *info); + +void +softpipe_draw_stream_output(struct pipe_context *pipe, unsigned mode); + +void +softpipe_map_transfers(struct softpipe_context *sp); + +void +softpipe_unmap_transfers(struct softpipe_context *sp); + +void +softpipe_map_texture_surfaces(struct softpipe_context *sp); + +void +softpipe_unmap_texture_surfaces(struct softpipe_context *sp); + + +struct vertex_info * +softpipe_get_vertex_info(struct softpipe_context *softpipe); + +struct vertex_info * +softpipe_get_vbuf_vertex_info(struct softpipe_context *softpipe); + + +#endif diff --git a/src/gallium/drivers/softpipe/sp_state_blend.c b/src/gallium/drivers/softpipe/sp_state_blend.c new file mode 100644 index 0000000..1286382 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_state_blend.c @@ -0,0 +1,143 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#include "util/u_memory.h" +#include "draw/draw_context.h" +#include "sp_context.h" +#include "sp_state.h" + + +static void * +softpipe_create_blend_state(struct pipe_context *pipe, + const struct pipe_blend_state *blend) +{ + return mem_dup(blend, sizeof(*blend)); +} + + +static void +softpipe_bind_blend_state(struct pipe_context *pipe, + void *blend) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + draw_flush(softpipe->draw); + + softpipe->blend = (struct pipe_blend_state *)blend; + + softpipe->dirty |= SP_NEW_BLEND; +} + + +static void +softpipe_delete_blend_state(struct pipe_context *pipe, + void *blend) +{ + FREE( blend ); +} + + +static void +softpipe_set_blend_color(struct pipe_context *pipe, + const struct pipe_blend_color *blend_color) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + draw_flush(softpipe->draw); + + softpipe->blend_color = *blend_color; + + softpipe->dirty |= SP_NEW_BLEND; +} + + +static void * +softpipe_create_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_alpha_state *depth_stencil) +{ + return mem_dup(depth_stencil, sizeof(*depth_stencil)); +} + + +static void +softpipe_bind_depth_stencil_state(struct pipe_context *pipe, + void *depth_stencil) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + softpipe->depth_stencil = (struct pipe_depth_stencil_alpha_state *)depth_stencil; + + softpipe->dirty |= SP_NEW_DEPTH_STENCIL_ALPHA; +} + + +static void +softpipe_delete_depth_stencil_state(struct pipe_context *pipe, void *depth) +{ + FREE( depth ); +} + + +static void +softpipe_set_stencil_ref(struct pipe_context *pipe, + const struct pipe_stencil_ref *stencil_ref) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + softpipe->stencil_ref = *stencil_ref; + + softpipe->dirty |= SP_NEW_DEPTH_STENCIL_ALPHA; +} + + +static void +softpipe_set_sample_mask(struct pipe_context *pipe, + unsigned sample_mask) +{ +} + + +void +softpipe_init_blend_funcs(struct pipe_context *pipe) +{ + pipe->create_blend_state = softpipe_create_blend_state; + pipe->bind_blend_state = softpipe_bind_blend_state; + pipe->delete_blend_state = softpipe_delete_blend_state; + + pipe->set_blend_color = softpipe_set_blend_color; + + pipe->create_depth_stencil_alpha_state = softpipe_create_depth_stencil_state; + pipe->bind_depth_stencil_alpha_state = softpipe_bind_depth_stencil_state; + pipe->delete_depth_stencil_alpha_state = softpipe_delete_depth_stencil_state; + + pipe->set_stencil_ref = softpipe_set_stencil_ref; + + pipe->set_sample_mask = softpipe_set_sample_mask; +} diff --git a/src/gallium/drivers/softpipe/sp_state_clip.c b/src/gallium/drivers/softpipe/sp_state_clip.c new file mode 100644 index 0000000..f3a4c23 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_state_clip.c @@ -0,0 +1,93 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ +#include "sp_context.h" +#include "sp_state.h" +#include "draw/draw_context.h" + + +static void +softpipe_set_clip_state(struct pipe_context *pipe, + const struct pipe_clip_state *clip) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + /* pass the clip state to the draw module */ + draw_set_clip_state(softpipe->draw, clip); +} + + +static void +softpipe_set_viewport_state(struct pipe_context *pipe, + const struct pipe_viewport_state *viewport) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + /* pass the viewport info to the draw module */ + draw_set_viewport_state(softpipe->draw, viewport); + + softpipe->viewport = *viewport; /* struct copy */ + softpipe->dirty |= SP_NEW_VIEWPORT; +} + + +static void +softpipe_set_scissor_state(struct pipe_context *pipe, + const struct pipe_scissor_state *scissor) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + draw_flush(softpipe->draw); + + softpipe->scissor = *scissor; /* struct copy */ + softpipe->dirty |= SP_NEW_SCISSOR; +} + + +static void +softpipe_set_polygon_stipple(struct pipe_context *pipe, + const struct pipe_poly_stipple *stipple) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + draw_flush(softpipe->draw); + + softpipe->poly_stipple = *stipple; /* struct copy */ + softpipe->dirty |= SP_NEW_STIPPLE; +} + + +void +softpipe_init_clip_funcs(struct pipe_context *pipe) +{ + pipe->set_clip_state = softpipe_set_clip_state; + pipe->set_viewport_state = softpipe_set_viewport_state; + pipe->set_scissor_state = softpipe_set_scissor_state; + pipe->set_polygon_stipple = softpipe_set_polygon_stipple; +} diff --git a/src/gallium/drivers/softpipe/sp_state_derived.c b/src/gallium/drivers/softpipe/sp_state_derived.c new file mode 100644 index 0000000..3ba4d93 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_state_derived.c @@ -0,0 +1,281 @@ +/************************************************************************** + * + * Copyright 2003 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. + * + **************************************************************************/ + +#include "util/u_math.h" +#include "util/u_memory.h" +#include "pipe/p_shader_tokens.h" +#include "draw/draw_context.h" +#include "draw/draw_vertex.h" +#include "sp_context.h" +#include "sp_screen.h" +#include "sp_state.h" +#include "sp_texture.h" +#include "sp_tex_tile_cache.h" + + +/** + * Mark the current vertex layout as "invalid". + * We'll validate the vertex layout later, when we start to actually + * render a point or line or tri. + */ +static void +invalidate_vertex_layout(struct softpipe_context *softpipe) +{ + softpipe->vertex_info.num_attribs = 0; +} + + +/** + * The vertex info describes how to convert the post-transformed vertices + * (simple float[][4]) used by the 'draw' module into vertices for + * rasterization. + * + * This function validates the vertex layout and returns a pointer to a + * vertex_info object. + */ +struct vertex_info * +softpipe_get_vertex_info(struct softpipe_context *softpipe) +{ + struct vertex_info *vinfo = &softpipe->vertex_info; + + if (vinfo->num_attribs == 0) { + /* compute vertex layout now */ + const struct sp_fragment_shader *spfs = softpipe->fs; + struct vertex_info *vinfo_vbuf = &softpipe->vertex_info_vbuf; + const uint num = draw_num_shader_outputs(softpipe->draw); + uint i; + + /* Tell draw_vbuf to simply emit the whole post-xform vertex + * as-is. No longer any need to try and emit draw vertex_header + * info. + */ + vinfo_vbuf->num_attribs = 0; + for (i = 0; i < num; i++) { + draw_emit_vertex_attr(vinfo_vbuf, EMIT_4F, INTERP_PERSPECTIVE, i); + } + draw_compute_vertex_size(vinfo_vbuf); + + /* + * Loop over fragment shader inputs, searching for the matching output + * from the vertex shader. + */ + vinfo->num_attribs = 0; + for (i = 0; i < spfs->info.num_inputs; i++) { + int src; + enum interp_mode interp; + + switch (spfs->info.input_interpolate[i]) { + case TGSI_INTERPOLATE_CONSTANT: + interp = INTERP_CONSTANT; + break; + case TGSI_INTERPOLATE_LINEAR: + interp = INTERP_LINEAR; + break; + case TGSI_INTERPOLATE_PERSPECTIVE: + interp = INTERP_PERSPECTIVE; + break; + default: + assert(0); + interp = INTERP_LINEAR; + } + + switch (spfs->info.input_semantic_name[i]) { + case TGSI_SEMANTIC_POSITION: + interp = INTERP_POS; + break; + + case TGSI_SEMANTIC_COLOR: + if (softpipe->rasterizer->flatshade) { + interp = INTERP_CONSTANT; + } + break; + } + + /* this includes texcoords and varying vars */ + src = draw_find_shader_output(softpipe->draw, + spfs->info.input_semantic_name[i], + spfs->info.input_semantic_index[i]); + draw_emit_vertex_attr(vinfo, EMIT_4F, interp, src); + } + + softpipe->psize_slot = draw_find_shader_output(softpipe->draw, + TGSI_SEMANTIC_PSIZE, 0); + if (softpipe->psize_slot > 0) { + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_CONSTANT, + softpipe->psize_slot); + } + + draw_compute_vertex_size(vinfo); + } + + return vinfo; +} + + +/** + * Called from vbuf module. + * + * Note that there's actually two different vertex layouts in softpipe. + * + * The normal one is computed in softpipe_get_vertex_info() above and is + * used by the point/line/tri "setup" code. + * + * The other one (this one) is only used by the vbuf module (which is + * not normally used by default but used in testing). For the vbuf module, + * we basically want to pass-through the draw module's vertex layout as-is. + * When the softpipe vbuf code begins drawing, the normal vertex layout + * will come into play again. + */ +struct vertex_info * +softpipe_get_vbuf_vertex_info(struct softpipe_context *softpipe) +{ + (void) softpipe_get_vertex_info(softpipe); + return &softpipe->vertex_info_vbuf; +} + + +/** + * Recompute cliprect from scissor bounds, scissor enable and surface size. + */ +static void +compute_cliprect(struct softpipe_context *sp) +{ + /* SP_NEW_FRAMEBUFFER + */ + uint surfWidth = sp->framebuffer.width; + uint surfHeight = sp->framebuffer.height; + + /* SP_NEW_RASTERIZER + */ + if (sp->rasterizer->scissor) { + + /* SP_NEW_SCISSOR + * + * clip to scissor rect: + */ + sp->cliprect.minx = MAX2(sp->scissor.minx, 0); + sp->cliprect.miny = MAX2(sp->scissor.miny, 0); + sp->cliprect.maxx = MIN2(sp->scissor.maxx, surfWidth); + sp->cliprect.maxy = MIN2(sp->scissor.maxy, surfHeight); + } + else { + /* clip to surface bounds */ + sp->cliprect.minx = 0; + sp->cliprect.miny = 0; + sp->cliprect.maxx = surfWidth; + sp->cliprect.maxy = surfHeight; + } +} + + +static void +update_tgsi_samplers( struct softpipe_context *softpipe ) +{ + unsigned i; + + softpipe_reset_sampler_varients( softpipe ); + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + struct softpipe_tex_tile_cache *tc = softpipe->tex_cache[i]; + if (tc->texture) { + struct softpipe_resource *spt = softpipe_resource(tc->texture); + if (spt->timestamp != tc->timestamp) { + sp_tex_tile_cache_validate_texture( tc ); + /* + _debug_printf("INV %d %d\n", tc->timestamp, spt->timestamp); + */ + tc->timestamp = spt->timestamp; + } + } + } + + for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { + struct softpipe_tex_tile_cache *tc = softpipe->vertex_tex_cache[i]; + + if (tc->texture) { + struct softpipe_resource *spt = softpipe_resource(tc->texture); + + if (spt->timestamp != tc->timestamp) { + sp_tex_tile_cache_validate_texture(tc); + tc->timestamp = spt->timestamp; + } + } + } + + for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) { + struct softpipe_tex_tile_cache *tc = softpipe->geometry_tex_cache[i]; + + if (tc->texture) { + struct softpipe_resource *spt = softpipe_resource(tc->texture); + + if (spt->timestamp != tc->timestamp) { + sp_tex_tile_cache_validate_texture(tc); + tc->timestamp = spt->timestamp; + } + } + } +} + + +/* Hopefully this will remain quite simple, otherwise need to pull in + * something like the state tracker mechanism. + */ +void softpipe_update_derived( struct softpipe_context *softpipe ) +{ + struct softpipe_screen *sp_screen = softpipe_screen(softpipe->pipe.screen); + + /* Check for updated textures. + */ + if (softpipe->tex_timestamp != sp_screen->timestamp) { + softpipe->tex_timestamp = sp_screen->timestamp; + softpipe->dirty |= SP_NEW_TEXTURE; + } + + if (softpipe->dirty & (SP_NEW_SAMPLER | + SP_NEW_TEXTURE | + SP_NEW_FS | + SP_NEW_VS)) + update_tgsi_samplers( softpipe ); + + if (softpipe->dirty & (SP_NEW_RASTERIZER | + SP_NEW_FS | + SP_NEW_VS)) + invalidate_vertex_layout( softpipe ); + + if (softpipe->dirty & (SP_NEW_SCISSOR | + SP_NEW_RASTERIZER | + SP_NEW_FRAMEBUFFER)) + compute_cliprect(softpipe); + + if (softpipe->dirty & (SP_NEW_BLEND | + SP_NEW_DEPTH_STENCIL_ALPHA | + SP_NEW_FRAMEBUFFER | + SP_NEW_FS)) + sp_build_quad_pipeline(softpipe); + + softpipe->dirty = 0; +} diff --git a/src/gallium/drivers/softpipe/sp_state_rasterizer.c b/src/gallium/drivers/softpipe/sp_state_rasterizer.c new file mode 100644 index 0000000..3cd4acd --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_state_rasterizer.c @@ -0,0 +1,76 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "pipe/p_defines.h" +#include "util/u_memory.h" +#include "sp_context.h" +#include "sp_state.h" +#include "draw/draw_context.h" + + + +static void * +softpipe_create_rasterizer_state(struct pipe_context *pipe, + const struct pipe_rasterizer_state *rast) +{ + return mem_dup(rast, sizeof(*rast)); +} + + +static void +softpipe_bind_rasterizer_state(struct pipe_context *pipe, + void *rasterizer) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + if (softpipe->rasterizer == rasterizer) + return; + + /* pass-through to draw module */ + draw_set_rasterizer_state(softpipe->draw, rasterizer, rasterizer); + + softpipe->rasterizer = rasterizer; + + softpipe->dirty |= SP_NEW_RASTERIZER; +} + + +static void +softpipe_delete_rasterizer_state(struct pipe_context *pipe, + void *rasterizer) +{ + FREE( rasterizer ); +} + + +void +softpipe_init_rasterizer_funcs(struct pipe_context *pipe) +{ + pipe->create_rasterizer_state = softpipe_create_rasterizer_state; + pipe->bind_rasterizer_state = softpipe_bind_rasterizer_state; + pipe->delete_rasterizer_state = softpipe_delete_rasterizer_state; +} diff --git a/src/gallium/drivers/softpipe/sp_state_sampler.c b/src/gallium/drivers/softpipe/sp_state_sampler.c new file mode 100644 index 0000000..b59fbc3 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_state_sampler.c @@ -0,0 +1,436 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: + * Brian Paul + */ + +#include "util/u_memory.h" +#include "util/u_inlines.h" + +#include "draw/draw_context.h" + +#include "sp_context.h" +#include "sp_state.h" +#include "sp_texture.h" +#include "sp_tex_sample.h" +#include "sp_tex_tile_cache.h" + + +struct sp_sampler { + struct pipe_sampler_state base; + struct sp_sampler_varient *varients; + struct sp_sampler_varient *current; +}; + +static struct sp_sampler *sp_sampler( struct pipe_sampler_state *sampler ) +{ + return (struct sp_sampler *)sampler; +} + + +static void * +softpipe_create_sampler_state(struct pipe_context *pipe, + const struct pipe_sampler_state *sampler) +{ + struct sp_sampler *sp_sampler = CALLOC_STRUCT(sp_sampler); + + sp_sampler->base = *sampler; + sp_sampler->varients = NULL; + + return (void *)sp_sampler; +} + + +static void +softpipe_bind_sampler_states(struct pipe_context *pipe, + unsigned num, void **sampler) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + unsigned i; + + assert(num <= PIPE_MAX_SAMPLERS); + + /* Check for no-op */ + if (num == softpipe->num_samplers && + !memcmp(softpipe->sampler, sampler, num * sizeof(void *))) + return; + + draw_flush(softpipe->draw); + + for (i = 0; i < num; ++i) + softpipe->sampler[i] = sampler[i]; + for (i = num; i < PIPE_MAX_SAMPLERS; ++i) + softpipe->sampler[i] = NULL; + + softpipe->num_samplers = num; + + softpipe->dirty |= SP_NEW_SAMPLER; +} + + +static void +softpipe_bind_vertex_sampler_states(struct pipe_context *pipe, + unsigned num_samplers, + void **samplers) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + unsigned i; + + assert(num_samplers <= PIPE_MAX_VERTEX_SAMPLERS); + + /* Check for no-op */ + if (num_samplers == softpipe->num_vertex_samplers && + !memcmp(softpipe->vertex_samplers, samplers, num_samplers * sizeof(void *))) + return; + + draw_flush(softpipe->draw); + + for (i = 0; i < num_samplers; ++i) + softpipe->vertex_samplers[i] = samplers[i]; + for (i = num_samplers; i < PIPE_MAX_VERTEX_SAMPLERS; ++i) + softpipe->vertex_samplers[i] = NULL; + + softpipe->num_vertex_samplers = num_samplers; + + draw_set_samplers(softpipe->draw, + softpipe->vertex_samplers, + softpipe->num_vertex_samplers); + + softpipe->dirty |= SP_NEW_SAMPLER; +} + +static void +softpipe_bind_geometry_sampler_states(struct pipe_context *pipe, + unsigned num_samplers, + void **samplers) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + unsigned i; + + assert(num_samplers <= PIPE_MAX_GEOMETRY_SAMPLERS); + + /* Check for no-op */ + if (num_samplers == softpipe->num_geometry_samplers && + !memcmp(softpipe->geometry_samplers, samplers, num_samplers * sizeof(void *))) + return; + + draw_flush(softpipe->draw); + + for (i = 0; i < num_samplers; ++i) + softpipe->geometry_samplers[i] = samplers[i]; + for (i = num_samplers; i < PIPE_MAX_GEOMETRY_SAMPLERS; ++i) + softpipe->geometry_samplers[i] = NULL; + + softpipe->num_geometry_samplers = num_samplers; + + softpipe->dirty |= SP_NEW_SAMPLER; +} + + +static struct pipe_sampler_view * +softpipe_create_sampler_view(struct pipe_context *pipe, + struct pipe_resource *resource, + const struct pipe_sampler_view *templ) +{ + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_resource_reference(&view->texture, resource); + view->context = pipe; + } + + return view; +} + + +static void +softpipe_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_resource_reference(&view->texture, NULL); + FREE(view); +} + + +static void +softpipe_set_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + uint i; + + assert(num <= PIPE_MAX_SAMPLERS); + + /* Check for no-op */ + if (num == softpipe->num_sampler_views && + !memcmp(softpipe->sampler_views, views, num * sizeof(struct pipe_sampler_view *))) + return; + + draw_flush(softpipe->draw); + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + struct pipe_sampler_view *view = i < num ? views[i] : NULL; + + pipe_sampler_view_reference(&softpipe->sampler_views[i], view); + sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[i], view); + } + + softpipe->num_sampler_views = num; + + softpipe->dirty |= SP_NEW_TEXTURE; +} + + +static void +softpipe_set_vertex_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + uint i; + + assert(num <= PIPE_MAX_VERTEX_SAMPLERS); + + /* Check for no-op */ + if (num == softpipe->num_vertex_sampler_views && + !memcmp(softpipe->vertex_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) { + return; + } + + draw_flush(softpipe->draw); + + for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { + struct pipe_sampler_view *view = i < num ? views[i] : NULL; + + pipe_sampler_view_reference(&softpipe->vertex_sampler_views[i], view); + sp_tex_tile_cache_set_sampler_view(softpipe->vertex_tex_cache[i], view); + } + + softpipe->num_vertex_sampler_views = num; + + draw_set_sampler_views(softpipe->draw, + softpipe->vertex_sampler_views, + softpipe->num_vertex_sampler_views); + + softpipe->dirty |= SP_NEW_TEXTURE; +} + + +static void +softpipe_set_geometry_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + uint i; + + assert(num <= PIPE_MAX_GEOMETRY_SAMPLERS); + + /* Check for no-op */ + if (num == softpipe->num_geometry_sampler_views && + !memcmp(softpipe->geometry_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) { + return; + } + + draw_flush(softpipe->draw); + + for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) { + struct pipe_sampler_view *view = i < num ? views[i] : NULL; + + pipe_sampler_view_reference(&softpipe->geometry_sampler_views[i], view); + sp_tex_tile_cache_set_sampler_view(softpipe->geometry_tex_cache[i], view); + } + + softpipe->num_geometry_sampler_views = num; + + softpipe->dirty |= SP_NEW_TEXTURE; +} + + +/** + * Find/create an sp_sampler_varient object for sampling the given texture, + * sampler and tex unit. + * + * Note that the tex unit is significant. We can't re-use a sampler + * varient for multiple texture units because the sampler varient contains + * the texture object pointer. If the texture object pointer were stored + * somewhere outside the sampler varient, we could re-use samplers for + * multiple texture units. + */ +static struct sp_sampler_varient * +get_sampler_varient( unsigned unit, + struct sp_sampler *sampler, + struct pipe_resource *resource, + unsigned processor ) +{ + struct softpipe_resource *sp_texture = softpipe_resource(resource); + struct sp_sampler_varient *v = NULL; + union sp_sampler_key key; + + /* if this fails, widen the key.unit field and update this assertion */ + assert(PIPE_MAX_SAMPLERS <= 16); + + key.bits.target = sp_texture->base.target; + key.bits.is_pot = sp_texture->pot; + key.bits.processor = processor; + key.bits.unit = unit; + key.bits.pad = 0; + + if (sampler->current && + key.value == sampler->current->key.value) { + v = sampler->current; + } + + if (v == NULL) { + for (v = sampler->varients; v; v = v->next) + if (v->key.value == key.value) + break; + + if (v == NULL) { + v = sp_create_sampler_varient( &sampler->base, key ); + v->next = sampler->varients; + sampler->varients = v; + } + } + + sampler->current = v; + return v; +} + + +void +softpipe_reset_sampler_varients(struct softpipe_context *softpipe) +{ + int i; + + /* It's a bit hard to build these samplers ahead of time -- don't + * really know which samplers are going to be used for vertex and + * fragment programs. + */ + for (i = 0; i <= softpipe->vs->max_sampler; i++) { + if (softpipe->vertex_samplers[i]) { + struct pipe_resource *texture = NULL; + + if (softpipe->vertex_sampler_views[i]) { + texture = softpipe->vertex_sampler_views[i]->texture; + } + + softpipe->tgsi.vert_samplers_list[i] = + get_sampler_varient( i, + sp_sampler(softpipe->vertex_samplers[i]), + texture, + TGSI_PROCESSOR_VERTEX ); + + sp_sampler_varient_bind_texture( softpipe->tgsi.vert_samplers_list[i], + softpipe->vertex_tex_cache[i], + texture ); + } + } + + if (softpipe->gs) { + for (i = 0; i <= softpipe->gs->max_sampler; i++) { + if (softpipe->geometry_samplers[i]) { + struct pipe_resource *texture = NULL; + + if (softpipe->geometry_sampler_views[i]) { + texture = softpipe->geometry_sampler_views[i]->texture; + } + + softpipe->tgsi.geom_samplers_list[i] = + get_sampler_varient( + i, + sp_sampler(softpipe->geometry_samplers[i]), + texture, + TGSI_PROCESSOR_GEOMETRY ); + + sp_sampler_varient_bind_texture( + softpipe->tgsi.geom_samplers_list[i], + softpipe->geometry_tex_cache[i], + texture ); + } + } + } + + for (i = 0; i <= softpipe->fs->info.file_max[TGSI_FILE_SAMPLER]; i++) { + if (softpipe->sampler[i]) { + struct pipe_resource *texture = NULL; + + if (softpipe->sampler_views[i]) { + texture = softpipe->sampler_views[i]->texture; + } + + softpipe->tgsi.frag_samplers_list[i] = + get_sampler_varient( i, + sp_sampler(softpipe->sampler[i]), + texture, + TGSI_PROCESSOR_FRAGMENT ); + + sp_sampler_varient_bind_texture( softpipe->tgsi.frag_samplers_list[i], + softpipe->tex_cache[i], + texture ); + } + } +} + +static void +softpipe_delete_sampler_state(struct pipe_context *pipe, + void *sampler) +{ + struct sp_sampler *sp_sampler = (struct sp_sampler *)sampler; + struct sp_sampler_varient *v, *tmp; + + for (v = sp_sampler->varients; v; v = tmp) { + tmp = v->next; + sp_sampler_varient_destroy(v); + } + + FREE( sampler ); +} + + +void +softpipe_init_sampler_funcs(struct pipe_context *pipe) +{ + pipe->create_sampler_state = softpipe_create_sampler_state; + pipe->bind_fragment_sampler_states = softpipe_bind_sampler_states; + pipe->bind_vertex_sampler_states = softpipe_bind_vertex_sampler_states; + pipe->bind_geometry_sampler_states = softpipe_bind_geometry_sampler_states; + pipe->delete_sampler_state = softpipe_delete_sampler_state; + + pipe->set_fragment_sampler_views = softpipe_set_sampler_views; + pipe->set_vertex_sampler_views = softpipe_set_vertex_sampler_views; + pipe->set_geometry_sampler_views = softpipe_set_geometry_sampler_views; + + pipe->create_sampler_view = softpipe_create_sampler_view; + pipe->sampler_view_destroy = softpipe_sampler_view_destroy; +} + diff --git a/src/gallium/drivers/softpipe/sp_state_shader.c b/src/gallium/drivers/softpipe/sp_state_shader.c new file mode 100644 index 0000000..7fff338 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_state_shader.c @@ -0,0 +1,301 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "sp_context.h" +#include "sp_state.h" +#include "sp_fs.h" +#include "sp_texture.h" + +#include "pipe/p_defines.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "draw/draw_context.h" +#include "draw/draw_vs.h" +#include "draw/draw_gs.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_exec.h" +#include "tgsi/tgsi_scan.h" +#include "tgsi/tgsi_parse.h" + + +static void * +softpipe_create_fs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + struct sp_fragment_shader *state; + unsigned i; + + /* debug */ + if (softpipe->dump_fs) + tgsi_dump(templ->tokens, 0); + + /* codegen */ + state = softpipe_create_fs_sse( softpipe, templ ); + if (!state) { + state = softpipe_create_fs_exec( softpipe, templ ); + } + + if (!state) + return NULL; + + /* draw's fs state */ + state->draw_shader = draw_create_fragment_shader(softpipe->draw, templ); + if (!state->draw_shader) { + state->delete( state ); + return NULL; + } + + /* get/save the summary info for this shader */ + tgsi_scan_shader(templ->tokens, &state->info); + + for (i = 0; i < state->info.num_properties; ++i) { + if (state->info.properties[i].name == TGSI_PROPERTY_FS_COORD_ORIGIN) + state->origin_lower_left = state->info.properties[i].data[0]; + else if (state->info.properties[i].name == TGSI_PROPERTY_FS_COORD_PIXEL_CENTER) + state->pixel_center_integer = state->info.properties[i].data[0]; + } + + return state; +} + + +static void +softpipe_bind_fs_state(struct pipe_context *pipe, void *fs) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + draw_flush(softpipe->draw); + + if (softpipe->fs == fs) + return; + + draw_flush(softpipe->draw); + + softpipe->fs = fs; + + draw_bind_fragment_shader(softpipe->draw, + (softpipe->fs ? softpipe->fs->draw_shader : NULL)); + + softpipe->dirty |= SP_NEW_FS; +} + + +static void +softpipe_delete_fs_state(struct pipe_context *pipe, void *fs) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + struct sp_fragment_shader *state = fs; + + assert(fs != softpipe_context(pipe)->fs); + + if (softpipe->fs_machine->Tokens == state->shader.tokens) { + /* unbind the shader from the tgsi executor if we're + * deleting it. + */ + tgsi_exec_machine_bind_shader(softpipe->fs_machine, NULL, 0, NULL); + } + + draw_delete_fragment_shader(softpipe->draw, state->draw_shader); + + state->delete( state ); +} + + +static void * +softpipe_create_vs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + struct sp_vertex_shader *state; + + state = CALLOC_STRUCT(sp_vertex_shader); + if (state == NULL ) + goto fail; + + /* copy shader tokens, the ones passed in will go away. + */ + state->shader.tokens = tgsi_dup_tokens(templ->tokens); + if (state->shader.tokens == NULL) + goto fail; + + state->draw_data = draw_create_vertex_shader(softpipe->draw, templ); + if (state->draw_data == NULL) + goto fail; + + state->max_sampler = state->draw_data->info.file_max[TGSI_FILE_SAMPLER]; + + return state; + +fail: + if (state) { + FREE( (void *)state->shader.tokens ); + FREE( state->draw_data ); + FREE( state ); + } + return NULL; +} + + +static void +softpipe_bind_vs_state(struct pipe_context *pipe, void *vs) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + softpipe->vs = (struct sp_vertex_shader *) vs; + + draw_bind_vertex_shader(softpipe->draw, + (softpipe->vs ? softpipe->vs->draw_data : NULL)); + + softpipe->dirty |= SP_NEW_VS; +} + + +static void +softpipe_delete_vs_state(struct pipe_context *pipe, void *vs) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + struct sp_vertex_shader *state = (struct sp_vertex_shader *) vs; + + draw_delete_vertex_shader(softpipe->draw, state->draw_data); + FREE( (void *)state->shader.tokens ); + FREE( state ); +} + + +static void * +softpipe_create_gs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + struct sp_geometry_shader *state; + + state = CALLOC_STRUCT(sp_geometry_shader); + if (state == NULL ) + goto fail; + + /* debug */ + if (softpipe->dump_gs) + tgsi_dump(templ->tokens, 0); + + /* copy shader tokens, the ones passed in will go away. + */ + state->shader.tokens = tgsi_dup_tokens(templ->tokens); + if (state->shader.tokens == NULL) + goto fail; + + state->draw_data = draw_create_geometry_shader(softpipe->draw, templ); + if (state->draw_data == NULL) + goto fail; + + state->max_sampler = state->draw_data->info.file_max[TGSI_FILE_SAMPLER]; + + return state; + +fail: + if (state) { + FREE( (void *)state->shader.tokens ); + FREE( state->draw_data ); + FREE( state ); + } + return NULL; +} + + +static void +softpipe_bind_gs_state(struct pipe_context *pipe, void *gs) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + softpipe->gs = (struct sp_geometry_shader *)gs; + + draw_bind_geometry_shader(softpipe->draw, + (softpipe->gs ? softpipe->gs->draw_data : NULL)); + + softpipe->dirty |= SP_NEW_GS; +} + + +static void +softpipe_delete_gs_state(struct pipe_context *pipe, void *gs) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + struct sp_geometry_shader *state = + (struct sp_geometry_shader *)gs; + + draw_delete_geometry_shader(softpipe->draw, + (state) ? state->draw_data : 0); + FREE(state); +} + + +static void +softpipe_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + struct pipe_resource *constants) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + unsigned size = constants ? constants->width0 : 0; + const void *data = constants ? softpipe_resource(constants)->data : NULL; + + assert(shader < PIPE_SHADER_TYPES); + + draw_flush(softpipe->draw); + + /* note: reference counting */ + pipe_resource_reference(&softpipe->constants[shader][index], constants); + + if (shader == PIPE_SHADER_VERTEX || shader == PIPE_SHADER_GEOMETRY) { + draw_set_mapped_constant_buffer(softpipe->draw, shader, index, data, size); + } + + softpipe->mapped_constants[shader][index] = data; + softpipe->const_buffer_size[shader][index] = size; + + softpipe->dirty |= SP_NEW_CONSTANTS; +} + + +void +softpipe_init_shader_funcs(struct pipe_context *pipe) +{ + pipe->create_fs_state = softpipe_create_fs_state; + pipe->bind_fs_state = softpipe_bind_fs_state; + pipe->delete_fs_state = softpipe_delete_fs_state; + + pipe->create_vs_state = softpipe_create_vs_state; + pipe->bind_vs_state = softpipe_bind_vs_state; + pipe->delete_vs_state = softpipe_delete_vs_state; + + pipe->create_gs_state = softpipe_create_gs_state; + pipe->bind_gs_state = softpipe_bind_gs_state; + pipe->delete_gs_state = softpipe_delete_gs_state; + + pipe->set_constant_buffer = softpipe_set_constant_buffer; +} diff --git a/src/gallium/drivers/softpipe/sp_state_so.c b/src/gallium/drivers/softpipe/sp_state_so.c new file mode 100644 index 0000000..ddfa3ef --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_state_so.c @@ -0,0 +1,140 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL 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. + * + **************************************************************************/ + +#include "sp_context.h" +#include "sp_state.h" +#include "sp_texture.h" + +#include "util/u_format.h" +#include "util/u_memory.h" +#include "draw/draw_context.h" + + +static void * +softpipe_create_stream_output_state(struct pipe_context *pipe, + const struct pipe_stream_output_state *templ) +{ + struct sp_so_state *so; + so = (struct sp_so_state *) CALLOC_STRUCT(sp_so_state); + + if (so) { + so->base.num_outputs = templ->num_outputs; + so->base.stride = templ->stride; + memcpy(so->base.output_buffer, + templ->output_buffer, + sizeof(int) * templ->num_outputs); + memcpy(so->base.register_index, + templ->register_index, + sizeof(int) * templ->num_outputs); + memcpy(so->base.register_mask, + templ->register_mask, + sizeof(ubyte) * templ->num_outputs); + } + return so; +} + + +static void +softpipe_bind_stream_output_state(struct pipe_context *pipe, + void *so) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + struct sp_so_state *sp_so = (struct sp_so_state *) so; + + softpipe->so = sp_so; + + softpipe->dirty |= SP_NEW_SO; + + if (sp_so) + draw_set_so_state(softpipe->draw, &sp_so->base); +} + + +static void +softpipe_delete_stream_output_state(struct pipe_context *pipe, void *so) +{ + FREE( so ); +} + + +static void +softpipe_set_stream_output_buffers(struct pipe_context *pipe, + struct pipe_resource **buffers, + int *offsets, + int num_buffers) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + int i; + void *map_buffers[PIPE_MAX_SO_BUFFERS]; + + assert(num_buffers <= PIPE_MAX_SO_BUFFERS); + if (num_buffers > PIPE_MAX_SO_BUFFERS) + num_buffers = PIPE_MAX_SO_BUFFERS; + + softpipe->dirty |= SP_NEW_SO_BUFFERS; + + for (i = 0; i < num_buffers; ++i) { + void *mapped; + struct softpipe_resource *res = softpipe_resource(buffers[i]); + + if (!res) { + /* the whole call is invalid, bail out */ + softpipe->so_target.num_buffers = 0; + draw_set_mapped_so_buffers(softpipe->draw, 0, 0); + return; + } + + softpipe->so_target.buffer[i] = res; + softpipe->so_target.offset[i] = offsets[i]; + softpipe->so_target.so_count[i] = 0; + + mapped = res->data; + if (offsets[i] >= 0) + map_buffers[i] = ((char*)mapped) + offsets[i]; + else { + /* this is a buffer append */ + assert(!"appending not implemented"); + map_buffers[i] = mapped; + } + } + softpipe->so_target.num_buffers = num_buffers; + + draw_set_mapped_so_buffers(softpipe->draw, map_buffers, num_buffers); +} + + + +void +softpipe_init_streamout_funcs(struct pipe_context *pipe) +{ + pipe->create_stream_output_state = softpipe_create_stream_output_state; + pipe->bind_stream_output_state = softpipe_bind_stream_output_state; + pipe->delete_stream_output_state = softpipe_delete_stream_output_state; + + pipe->set_stream_output_buffers = softpipe_set_stream_output_buffers; +} + diff --git a/src/gallium/drivers/softpipe/sp_state_surface.c b/src/gallium/drivers/softpipe/sp_state_surface.c new file mode 100644 index 0000000..2db6fae --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_state_surface.c @@ -0,0 +1,104 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#include "sp_context.h" +#include "sp_state.h" +#include "sp_tile_cache.h" + +#include "draw/draw_context.h" + +#include "util/u_format.h" +#include "util/u_inlines.h" + + +/** + * XXX this might get moved someday + * Set the framebuffer surface info: color buffers, zbuffer, stencil buffer. + * Here, we flush the old surfaces and update the tile cache to point to the new + * surfaces. + */ +void +softpipe_set_framebuffer_state(struct pipe_context *pipe, + const struct pipe_framebuffer_state *fb) +{ + struct softpipe_context *sp = softpipe_context(pipe); + uint i; + + draw_flush(sp->draw); + + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + /* check if changing cbuf */ + if (sp->framebuffer.cbufs[i] != fb->cbufs[i]) { + /* flush old */ + sp_flush_tile_cache(sp->cbuf_cache[i]); + + /* assign new */ + pipe_surface_reference(&sp->framebuffer.cbufs[i], fb->cbufs[i]); + + /* update cache */ + sp_tile_cache_set_surface(sp->cbuf_cache[i], fb->cbufs[i]); + } + } + + sp->framebuffer.nr_cbufs = fb->nr_cbufs; + + /* zbuf changing? */ + if (sp->framebuffer.zsbuf != fb->zsbuf) { + /* flush old */ + sp_flush_tile_cache(sp->zsbuf_cache); + + /* assign new */ + pipe_surface_reference(&sp->framebuffer.zsbuf, fb->zsbuf); + + /* update cache */ + sp_tile_cache_set_surface(sp->zsbuf_cache, fb->zsbuf); + + /* Tell draw module how deep the Z/depth buffer is */ + if (sp->framebuffer.zsbuf) { + int depth_bits; + double mrd; + depth_bits = util_format_get_component_bits(sp->framebuffer.zsbuf->format, + UTIL_FORMAT_COLORSPACE_ZS, + 0); + if (depth_bits > 16) { + mrd = 0.0000001; + } + else { + mrd = 0.00002; + } + draw_set_mrd(sp->draw, mrd); + } + } + + sp->framebuffer.width = fb->width; + sp->framebuffer.height = fb->height; + + sp->dirty |= SP_NEW_FRAMEBUFFER; +} diff --git a/src/gallium/drivers/softpipe/sp_state_vertex.c b/src/gallium/drivers/softpipe/sp_state_vertex.c new file mode 100644 index 0000000..7d8055f --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_state_vertex.c @@ -0,0 +1,120 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + + +#include "sp_context.h" +#include "sp_state.h" + +#include "util/u_memory.h" +#include "draw/draw_context.h" + + +static void * +softpipe_create_vertex_elements_state(struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_element *attribs) +{ + struct sp_velems_state *velems; + assert(count <= PIPE_MAX_ATTRIBS); + velems = (struct sp_velems_state *) MALLOC(sizeof(struct sp_velems_state)); + if (velems) { + velems->count = count; + memcpy(velems->velem, attribs, sizeof(*attribs) * count); + } + return velems; +} + + +static void +softpipe_bind_vertex_elements_state(struct pipe_context *pipe, + void *velems) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + struct sp_velems_state *sp_velems = (struct sp_velems_state *) velems; + + softpipe->velems = sp_velems; + + softpipe->dirty |= SP_NEW_VERTEX; + + if (sp_velems) + draw_set_vertex_elements(softpipe->draw, sp_velems->count, sp_velems->velem); +} + + +static void +softpipe_delete_vertex_elements_state(struct pipe_context *pipe, void *velems) +{ + FREE( velems ); +} + + +static void +softpipe_set_vertex_buffers(struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_buffer *buffers) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + assert(count <= PIPE_MAX_ATTRIBS); + + memcpy(softpipe->vertex_buffer, buffers, count * sizeof(buffers[0])); + softpipe->num_vertex_buffers = count; + + softpipe->dirty |= SP_NEW_VERTEX; + + draw_set_vertex_buffers(softpipe->draw, count, buffers); +} + + +static void +softpipe_set_index_buffer(struct pipe_context *pipe, + const struct pipe_index_buffer *ib) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + if (ib) + memcpy(&softpipe->index_buffer, ib, sizeof(softpipe->index_buffer)); + else + memset(&softpipe->index_buffer, 0, sizeof(softpipe->index_buffer)); + + draw_set_index_buffer(softpipe->draw, ib); +} + + +void +softpipe_init_vertex_funcs(struct pipe_context *pipe) +{ + pipe->create_vertex_elements_state = softpipe_create_vertex_elements_state; + pipe->bind_vertex_elements_state = softpipe_bind_vertex_elements_state; + pipe->delete_vertex_elements_state = softpipe_delete_vertex_elements_state; + + pipe->set_vertex_buffers = softpipe_set_vertex_buffers; + pipe->set_index_buffer = softpipe_set_index_buffer; +} diff --git a/src/gallium/drivers/softpipe/sp_surface.c b/src/gallium/drivers/softpipe/sp_surface.c new file mode 100644 index 0000000..55b27e6 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_surface.c @@ -0,0 +1,38 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_surface.h" +#include "sp_context.h" +#include "sp_surface.h" + +void +sp_init_surface_functions(struct softpipe_context *sp) +{ + sp->pipe.resource_copy_region = util_resource_copy_region; + sp->pipe.clear_render_target = util_clear_render_target; + sp->pipe.clear_depth_stencil = util_clear_depth_stencil; +} diff --git a/src/gallium/drivers/softpipe/sp_surface.h b/src/gallium/drivers/softpipe/sp_surface.h new file mode 100644 index 0000000..22de3ba --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_surface.h @@ -0,0 +1,42 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* Authors: Keith Whitwell + */ + +#ifndef SP_SURFACE_H +#define SP_SURFACE_H + + +struct softpipe_context; + + +extern void +sp_init_surface_functions(struct softpipe_context *sp); + + +#endif /* SP_SURFACE_H */ diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.c b/src/gallium/drivers/softpipe/sp_tex_sample.c new file mode 100644 index 0000000..2eac4c7 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_tex_sample.c @@ -0,0 +1,2033 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2008-2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL 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. + * + **************************************************************************/ + +/** + * Texture sampling + * + * Authors: + * Brian Paul + * Keith Whitwell + */ + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "sp_quad.h" /* only for #define QUAD_* tokens */ +#include "sp_tex_sample.h" +#include "sp_tex_tile_cache.h" + + +/** Set to one to help debug texture sampling */ +#define DEBUG_TEX 0 + + +/* + * Return fractional part of 'f'. Used for computing interpolation weights. + * Need to be careful with negative values. + * Note, if this function isn't perfect you'll sometimes see 1-pixel bands + * of improperly weighted linear-filtered textures. + * The tests/texwrap.c demo is a good test. + */ +static INLINE float +frac(float f) +{ + return f - floorf(f); +} + + + +/** + * Linear interpolation macro + */ +static INLINE float +lerp(float a, float v0, float v1) +{ + return v0 + a * (v1 - v0); +} + + +/** + * Do 2D/bilinear interpolation of float values. + * v00, v10, v01 and v11 are typically four texture samples in a square/box. + * a and b are the horizontal and vertical interpolants. + * It's important that this function is inlined when compiled with + * optimization! If we find that's not true on some systems, convert + * to a macro. + */ +static INLINE float +lerp_2d(float a, float b, + float v00, float v10, float v01, float v11) +{ + const float temp0 = lerp(a, v00, v10); + const float temp1 = lerp(a, v01, v11); + return lerp(b, temp0, temp1); +} + + +/** + * As above, but 3D interpolation of 8 values. + */ +static INLINE float +lerp_3d(float a, float b, float c, + float v000, float v100, float v010, float v110, + float v001, float v101, float v011, float v111) +{ + const float temp0 = lerp_2d(a, b, v000, v100, v010, v110); + const float temp1 = lerp_2d(a, b, v001, v101, v011, v111); + return lerp(c, temp0, temp1); +} + + + +/** + * Compute coord % size for repeat wrap modes. + * Note that if coord is negative, coord % size doesn't give the right + * value. To avoid that problem we add a large multiple of the size + * (rather than using a conditional). + */ +static INLINE int +repeat(int coord, unsigned size) +{ + return (coord + size * 1024) % size; +} + + +/** + * Apply texture coord wrapping mode and return integer texture indexes + * for a vector of four texcoords (S or T or P). + * \param wrapMode PIPE_TEX_WRAP_x + * \param s the incoming texcoords + * \param size the texture image size + * \param icoord returns the integer texcoords + * \return integer texture index + */ +static void +wrap_nearest_repeat(const float s[4], unsigned size, int icoord[4]) +{ + uint ch; + /* s limited to [0,1) */ + /* i limited to [0,size-1] */ + for (ch = 0; ch < 4; ch++) { + int i = util_ifloor(s[ch] * size); + icoord[ch] = repeat(i, size); + } +} + + +static void +wrap_nearest_clamp(const float s[4], unsigned size, int icoord[4]) +{ + uint ch; + /* s limited to [0,1] */ + /* i limited to [0,size-1] */ + for (ch = 0; ch < 4; ch++) { + if (s[ch] <= 0.0F) + icoord[ch] = 0; + else if (s[ch] >= 1.0F) + icoord[ch] = size - 1; + else + icoord[ch] = util_ifloor(s[ch] * size); + } +} + + +static void +wrap_nearest_clamp_to_edge(const float s[4], unsigned size, int icoord[4]) +{ + uint ch; + /* s limited to [min,max] */ + /* i limited to [0, size-1] */ + const float min = 1.0F / (2.0F * size); + const float max = 1.0F - min; + for (ch = 0; ch < 4; ch++) { + if (s[ch] < min) + icoord[ch] = 0; + else if (s[ch] > max) + icoord[ch] = size - 1; + else + icoord[ch] = util_ifloor(s[ch] * size); + } +} + + +static void +wrap_nearest_clamp_to_border(const float s[4], unsigned size, int icoord[4]) +{ + uint ch; + /* s limited to [min,max] */ + /* i limited to [-1, size] */ + const float min = -1.0F / (2.0F * size); + const float max = 1.0F - min; + for (ch = 0; ch < 4; ch++) { + if (s[ch] <= min) + icoord[ch] = -1; + else if (s[ch] >= max) + icoord[ch] = size; + else + icoord[ch] = util_ifloor(s[ch] * size); + } +} + + +static void +wrap_nearest_mirror_repeat(const float s[4], unsigned size, int icoord[4]) +{ + uint ch; + const float min = 1.0F / (2.0F * size); + const float max = 1.0F - min; + for (ch = 0; ch < 4; ch++) { + const int flr = util_ifloor(s[ch]); + float u = frac(s[ch]); + if (flr & 1) + u = 1.0F - u; + if (u < min) + icoord[ch] = 0; + else if (u > max) + icoord[ch] = size - 1; + else + icoord[ch] = util_ifloor(u * size); + } +} + + +static void +wrap_nearest_mirror_clamp(const float s[4], unsigned size, int icoord[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { + /* s limited to [0,1] */ + /* i limited to [0,size-1] */ + const float u = fabsf(s[ch]); + if (u <= 0.0F) + icoord[ch] = 0; + else if (u >= 1.0F) + icoord[ch] = size - 1; + else + icoord[ch] = util_ifloor(u * size); + } +} + + +static void +wrap_nearest_mirror_clamp_to_edge(const float s[4], unsigned size, + int icoord[4]) +{ + uint ch; + /* s limited to [min,max] */ + /* i limited to [0, size-1] */ + const float min = 1.0F / (2.0F * size); + const float max = 1.0F - min; + for (ch = 0; ch < 4; ch++) { + const float u = fabsf(s[ch]); + if (u < min) + icoord[ch] = 0; + else if (u > max) + icoord[ch] = size - 1; + else + icoord[ch] = util_ifloor(u * size); + } +} + + +static void +wrap_nearest_mirror_clamp_to_border(const float s[4], unsigned size, + int icoord[4]) +{ + uint ch; + /* s limited to [min,max] */ + /* i limited to [0, size-1] */ + const float min = -1.0F / (2.0F * size); + const float max = 1.0F - min; + for (ch = 0; ch < 4; ch++) { + const float u = fabsf(s[ch]); + if (u < min) + icoord[ch] = -1; + else if (u > max) + icoord[ch] = size; + else + icoord[ch] = util_ifloor(u * size); + } +} + + +/** + * Used to compute texel locations for linear sampling for four texcoords. + * \param wrapMode PIPE_TEX_WRAP_x + * \param s the texcoords + * \param size the texture image size + * \param icoord0 returns first texture indexes + * \param icoord1 returns second texture indexes (usually icoord0 + 1) + * \param w returns blend factor/weight between texture indexes + * \param icoord returns the computed integer texture coords + */ +static void +wrap_linear_repeat(const float s[4], unsigned size, + int icoord0[4], int icoord1[4], float w[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { + float u = s[ch] * size - 0.5F; + icoord0[ch] = repeat(util_ifloor(u), size); + icoord1[ch] = repeat(icoord0[ch] + 1, size); + w[ch] = frac(u); + } +} + + +static void +wrap_linear_clamp(const float s[4], unsigned size, + int icoord0[4], int icoord1[4], float w[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { + float u = CLAMP(s[ch], 0.0F, 1.0F); + u = u * size - 0.5f; + icoord0[ch] = util_ifloor(u); + icoord1[ch] = icoord0[ch] + 1; + w[ch] = frac(u); + } +} + + +static void +wrap_linear_clamp_to_edge(const float s[4], unsigned size, + int icoord0[4], int icoord1[4], float w[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { + float u = CLAMP(s[ch], 0.0F, 1.0F); + u = u * size - 0.5f; + icoord0[ch] = util_ifloor(u); + icoord1[ch] = icoord0[ch] + 1; + if (icoord0[ch] < 0) + icoord0[ch] = 0; + if (icoord1[ch] >= (int) size) + icoord1[ch] = size - 1; + w[ch] = frac(u); + } +} + + +static void +wrap_linear_clamp_to_border(const float s[4], unsigned size, + int icoord0[4], int icoord1[4], float w[4]) +{ + const float min = -1.0F / (2.0F * size); + const float max = 1.0F - min; + uint ch; + for (ch = 0; ch < 4; ch++) { + float u = CLAMP(s[ch], min, max); + u = u * size - 0.5f; + icoord0[ch] = util_ifloor(u); + icoord1[ch] = icoord0[ch] + 1; + w[ch] = frac(u); + } +} + + +static void +wrap_linear_mirror_repeat(const float s[4], unsigned size, + int icoord0[4], int icoord1[4], float w[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { + const int flr = util_ifloor(s[ch]); + float u = frac(s[ch]); + if (flr & 1) + u = 1.0F - u; + u = u * size - 0.5F; + icoord0[ch] = util_ifloor(u); + icoord1[ch] = icoord0[ch] + 1; + if (icoord0[ch] < 0) + icoord0[ch] = 0; + if (icoord1[ch] >= (int) size) + icoord1[ch] = size - 1; + w[ch] = frac(u); + } +} + + +static void +wrap_linear_mirror_clamp(const float s[4], unsigned size, + int icoord0[4], int icoord1[4], float w[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { + float u = fabsf(s[ch]); + if (u >= 1.0F) + u = (float) size; + else + u *= size; + u -= 0.5F; + icoord0[ch] = util_ifloor(u); + icoord1[ch] = icoord0[ch] + 1; + w[ch] = frac(u); + } +} + + +static void +wrap_linear_mirror_clamp_to_edge(const float s[4], unsigned size, + int icoord0[4], int icoord1[4], float w[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { + float u = fabsf(s[ch]); + if (u >= 1.0F) + u = (float) size; + else + u *= size; + u -= 0.5F; + icoord0[ch] = util_ifloor(u); + icoord1[ch] = icoord0[ch] + 1; + if (icoord0[ch] < 0) + icoord0[ch] = 0; + if (icoord1[ch] >= (int) size) + icoord1[ch] = size - 1; + w[ch] = frac(u); + } +} + + +static void +wrap_linear_mirror_clamp_to_border(const float s[4], unsigned size, + int icoord0[4], int icoord1[4], float w[4]) +{ + const float min = -1.0F / (2.0F * size); + const float max = 1.0F - min; + uint ch; + for (ch = 0; ch < 4; ch++) { + float u = fabsf(s[ch]); + if (u <= min) + u = min * size; + else if (u >= max) + u = max * size; + else + u *= size; + u -= 0.5F; + icoord0[ch] = util_ifloor(u); + icoord1[ch] = icoord0[ch] + 1; + w[ch] = frac(u); + } +} + + +/** + * PIPE_TEX_WRAP_CLAMP for nearest sampling, unnormalized coords. + */ +static void +wrap_nearest_unorm_clamp(const float s[4], unsigned size, int icoord[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { + int i = util_ifloor(s[ch]); + icoord[ch]= CLAMP(i, 0, (int) size-1); + } +} + + +/** + * PIPE_TEX_WRAP_CLAMP_TO_BORDER for nearest sampling, unnormalized coords. + */ +static void +wrap_nearest_unorm_clamp_to_border(const float s[4], unsigned size, + int icoord[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { + icoord[ch]= util_ifloor( CLAMP(s[ch], -0.5F, (float) size + 0.5F) ); + } +} + + +/** + * PIPE_TEX_WRAP_CLAMP_TO_EDGE for nearest sampling, unnormalized coords. + */ +static void +wrap_nearest_unorm_clamp_to_edge(const float s[4], unsigned size, + int icoord[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { + icoord[ch]= util_ifloor( CLAMP(s[ch], 0.5F, (float) size - 0.5F) ); + } +} + + +/** + * PIPE_TEX_WRAP_CLAMP for linear sampling, unnormalized coords. + */ +static void +wrap_linear_unorm_clamp(const float s[4], unsigned size, + int icoord0[4], int icoord1[4], float w[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { + /* Not exactly what the spec says, but it matches NVIDIA output */ + float u = CLAMP(s[ch] - 0.5F, 0.0f, (float) size - 1.0f); + icoord0[ch] = util_ifloor(u); + icoord1[ch] = icoord0[ch] + 1; + w[ch] = frac(u); + } +} + + +/** + * PIPE_TEX_WRAP_CLAMP_TO_BORDER for linear sampling, unnormalized coords. + */ +static void +wrap_linear_unorm_clamp_to_border(const float s[4], unsigned size, + int icoord0[4], int icoord1[4], float w[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { + float u = CLAMP(s[ch], -0.5F, (float) size + 0.5F); + u -= 0.5F; + icoord0[ch] = util_ifloor(u); + icoord1[ch] = icoord0[ch] + 1; + if (icoord1[ch] > (int) size - 1) + icoord1[ch] = size - 1; + w[ch] = frac(u); + } +} + + +/** + * PIPE_TEX_WRAP_CLAMP_TO_EDGE for linear sampling, unnormalized coords. + */ +static void +wrap_linear_unorm_clamp_to_edge(const float s[4], unsigned size, + int icoord0[4], int icoord1[4], float w[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { + float u = CLAMP(s[ch], +0.5F, (float) size - 0.5F); + u -= 0.5F; + icoord0[ch] = util_ifloor(u); + icoord1[ch] = icoord0[ch] + 1; + if (icoord1[ch] > (int) size - 1) + icoord1[ch] = size - 1; + w[ch] = frac(u); + } +} + + + +/** + * Examine the quad's texture coordinates to compute the partial + * derivatives w.r.t X and Y, then compute lambda (level of detail). + */ +static float +compute_lambda_1d(const struct sp_sampler_varient *samp, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE]) +{ + const struct pipe_resource *texture = samp->texture; + float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); + float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); + float rho = MAX2(dsdx, dsdy) * texture->width0; + + return util_fast_log2(rho); +} + + +static float +compute_lambda_2d(const struct sp_sampler_varient *samp, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE]) +{ + const struct pipe_resource *texture = samp->texture; + float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); + float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); + float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); + float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); + float maxx = MAX2(dsdx, dsdy) * texture->width0; + float maxy = MAX2(dtdx, dtdy) * texture->height0; + float rho = MAX2(maxx, maxy); + + return util_fast_log2(rho); +} + + +static float +compute_lambda_3d(const struct sp_sampler_varient *samp, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE]) +{ + const struct pipe_resource *texture = samp->texture; + float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); + float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); + float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); + float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); + float dpdx = fabsf(p[QUAD_BOTTOM_RIGHT] - p[QUAD_BOTTOM_LEFT]); + float dpdy = fabsf(p[QUAD_TOP_LEFT] - p[QUAD_BOTTOM_LEFT]); + float maxx = MAX2(dsdx, dsdy) * texture->width0; + float maxy = MAX2(dtdx, dtdy) * texture->height0; + float maxz = MAX2(dpdx, dpdy) * texture->depth0; + float rho; + + rho = MAX2(maxx, maxy); + rho = MAX2(rho, maxz); + + return util_fast_log2(rho); +} + + +/** + * Compute lambda for a vertex texture sampler. + * Since there aren't derivatives to use, just return 0. + */ +static float +compute_lambda_vert(const struct sp_sampler_varient *samp, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE]) +{ + return 0.0f; +} + + + +/** + * Get a texel from a texture, using the texture tile cache. + * + * \param addr the template tex address containing cube, z, face info. + * \param x the x coord of texel within 2D image + * \param y the y coord of texel within 2D image + * \param rgba the quad to put the texel/color into + * + * XXX maybe move this into sp_tex_tile_cache.c and merge with the + * sp_get_cached_tile_tex() function. Also, get 4 texels instead of 1... + */ + + + + +static INLINE const float * +get_texel_2d_no_border(const struct sp_sampler_varient *samp, + union tex_tile_address addr, int x, int y) +{ + const struct softpipe_tex_cached_tile *tile; + + addr.bits.x = x / TILE_SIZE; + addr.bits.y = y / TILE_SIZE; + y %= TILE_SIZE; + x %= TILE_SIZE; + + tile = sp_get_cached_tile_tex(samp->cache, addr); + + return &tile->data.color[y][x][0]; +} + + +static INLINE const float * +get_texel_2d(const struct sp_sampler_varient *samp, + union tex_tile_address addr, int x, int y) +{ + const struct pipe_resource *texture = samp->texture; + unsigned level = addr.bits.level; + + if (x < 0 || x >= (int) u_minify(texture->width0, level) || + y < 0 || y >= (int) u_minify(texture->height0, level)) { + return sp_tex_tile_cache_border_color(samp->cache, + samp->sampler->border_color); + } + else { + return get_texel_2d_no_border( samp, addr, x, y ); + } +} + + +/* Gather a quad of adjacent texels within a tile: + */ +static INLINE void +get_texel_quad_2d_no_border_single_tile(const struct sp_sampler_varient *samp, + union tex_tile_address addr, + unsigned x, unsigned y, + const float *out[4]) +{ + const struct softpipe_tex_cached_tile *tile; + + addr.bits.x = x / TILE_SIZE; + addr.bits.y = y / TILE_SIZE; + y %= TILE_SIZE; + x %= TILE_SIZE; + + tile = sp_get_cached_tile_tex(samp->cache, addr); + + out[0] = &tile->data.color[y ][x ][0]; + out[1] = &tile->data.color[y ][x+1][0]; + out[2] = &tile->data.color[y+1][x ][0]; + out[3] = &tile->data.color[y+1][x+1][0]; +} + + +/* Gather a quad of potentially non-adjacent texels: + */ +static INLINE void +get_texel_quad_2d_no_border(const struct sp_sampler_varient *samp, + union tex_tile_address addr, + int x0, int y0, + int x1, int y1, + const float *out[4]) +{ + out[0] = get_texel_2d_no_border( samp, addr, x0, y0 ); + out[1] = get_texel_2d_no_border( samp, addr, x1, y0 ); + out[2] = get_texel_2d_no_border( samp, addr, x0, y1 ); + out[3] = get_texel_2d_no_border( samp, addr, x1, y1 ); +} + +/* Can involve a lot of unnecessary checks for border color: + */ +static INLINE void +get_texel_quad_2d(const struct sp_sampler_varient *samp, + union tex_tile_address addr, + int x0, int y0, + int x1, int y1, + const float *out[4]) +{ + out[0] = get_texel_2d( samp, addr, x0, y0 ); + out[1] = get_texel_2d( samp, addr, x1, y0 ); + out[3] = get_texel_2d( samp, addr, x1, y1 ); + out[2] = get_texel_2d( samp, addr, x0, y1 ); +} + + + +/* 3d varients: + */ +static INLINE const float * +get_texel_3d_no_border(const struct sp_sampler_varient *samp, + union tex_tile_address addr, int x, int y, int z) +{ + const struct softpipe_tex_cached_tile *tile; + + addr.bits.x = x / TILE_SIZE; + addr.bits.y = y / TILE_SIZE; + addr.bits.z = z; + y %= TILE_SIZE; + x %= TILE_SIZE; + + tile = sp_get_cached_tile_tex(samp->cache, addr); + + return &tile->data.color[y][x][0]; +} + + +static INLINE const float * +get_texel_3d(const struct sp_sampler_varient *samp, + union tex_tile_address addr, int x, int y, int z) +{ + const struct pipe_resource *texture = samp->texture; + unsigned level = addr.bits.level; + + if (x < 0 || x >= (int) u_minify(texture->width0, level) || + y < 0 || y >= (int) u_minify(texture->height0, level) || + z < 0 || z >= (int) u_minify(texture->depth0, level)) { + return sp_tex_tile_cache_border_color(samp->cache, + samp->sampler->border_color); + } + else { + return get_texel_3d_no_border( samp, addr, x, y, z ); + } +} + + +/** + * Given the logbase2 of a mipmap's base level size and a mipmap level, + * return the size (in texels) of that mipmap level. + * For example, if level[0].width = 256 then base_pot will be 8. + * If level = 2, then we'll return 64 (the width at level=2). + * Return 1 if level > base_pot. + */ +static INLINE unsigned +pot_level_size(unsigned base_pot, unsigned level) +{ + return (base_pot >= level) ? (1 << (base_pot - level)) : 1; +} + + +static void +print_sample(const char *function, float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + debug_printf("%s %g %g %g %g, %g %g %g %g, %g %g %g %g, %g %g %g %g\n", + function, + rgba[0][0], rgba[1][0], rgba[2][0], rgba[3][0], + rgba[0][1], rgba[1][1], rgba[2][1], rgba[3][1], + rgba[0][2], rgba[1][2], rgba[2][2], rgba[3][2], + rgba[0][3], rgba[1][3], rgba[2][3], rgba[3][3]); +} + + +/* Some image-filter fastpaths: + */ +static INLINE void +img_filter_2d_linear_repeat_POT(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + unsigned j; + unsigned level = samp->level; + unsigned xpot = pot_level_size(samp->xpot, level); + unsigned ypot = pot_level_size(samp->ypot, level); + unsigned xmax = (xpot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, xpot) - 1; */ + unsigned ymax = (ypot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, ypot) - 1; */ + union tex_tile_address addr; + + addr.value = 0; + addr.bits.level = samp->level; + + for (j = 0; j < QUAD_SIZE; j++) { + int c; + + float u = s[j] * xpot - 0.5F; + float v = t[j] * ypot - 0.5F; + + int uflr = util_ifloor(u); + int vflr = util_ifloor(v); + + float xw = u - (float)uflr; + float yw = v - (float)vflr; + + int x0 = uflr & (xpot - 1); + int y0 = vflr & (ypot - 1); + + const float *tx[4]; + + /* Can we fetch all four at once: + */ + if (x0 < xmax && y0 < ymax) { + get_texel_quad_2d_no_border_single_tile(samp, addr, x0, y0, tx); + } + else { + unsigned x1 = (x0 + 1) & (xpot - 1); + unsigned y1 = (y0 + 1) & (ypot - 1); + get_texel_quad_2d_no_border(samp, addr, x0, y0, x1, y1, tx); + } + + /* interpolate R, G, B, A */ + for (c = 0; c < 4; c++) { + rgba[c][j] = lerp_2d(xw, yw, + tx[0][c], tx[1][c], + tx[2][c], tx[3][c]); + } + } + + if (DEBUG_TEX) { + print_sample(__FUNCTION__, rgba); + } +} + + +static INLINE void +img_filter_2d_nearest_repeat_POT(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + unsigned j; + unsigned level = samp->level; + unsigned xpot = pot_level_size(samp->xpot, level); + unsigned ypot = pot_level_size(samp->ypot, level); + union tex_tile_address addr; + + addr.value = 0; + addr.bits.level = samp->level; + + for (j = 0; j < QUAD_SIZE; j++) { + int c; + + float u = s[j] * xpot; + float v = t[j] * ypot; + + int uflr = util_ifloor(u); + int vflr = util_ifloor(v); + + int x0 = uflr & (xpot - 1); + int y0 = vflr & (ypot - 1); + + const float *out = get_texel_2d_no_border(samp, addr, x0, y0); + + for (c = 0; c < 4; c++) { + rgba[c][j] = out[c]; + } + } + + if (DEBUG_TEX) { + print_sample(__FUNCTION__, rgba); + } +} + + +static INLINE void +img_filter_2d_nearest_clamp_POT(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + unsigned j; + unsigned level = samp->level; + unsigned xpot = pot_level_size(samp->xpot, level); + unsigned ypot = pot_level_size(samp->ypot, level); + union tex_tile_address addr; + + addr.value = 0; + addr.bits.level = samp->level; + + for (j = 0; j < QUAD_SIZE; j++) { + int c; + + float u = s[j] * xpot; + float v = t[j] * ypot; + + int x0, y0; + const float *out; + + x0 = util_ifloor(u); + if (x0 < 0) + x0 = 0; + else if (x0 > xpot - 1) + x0 = xpot - 1; + + y0 = util_ifloor(v); + if (y0 < 0) + y0 = 0; + else if (y0 > ypot - 1) + y0 = ypot - 1; + + out = get_texel_2d_no_border(samp, addr, x0, y0); + + for (c = 0; c < 4; c++) { + rgba[c][j] = out[c]; + } + } + + if (DEBUG_TEX) { + print_sample(__FUNCTION__, rgba); + } +} + + +static void +img_filter_1d_nearest(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + const struct pipe_resource *texture = samp->texture; + unsigned level0, j; + int width; + int x[4]; + union tex_tile_address addr; + + level0 = samp->level; + width = u_minify(texture->width0, level0); + + assert(width > 0); + + addr.value = 0; + addr.bits.level = samp->level; + + samp->nearest_texcoord_s(s, width, x); + + for (j = 0; j < QUAD_SIZE; j++) { + const float *out = get_texel_2d(samp, addr, x[j], 0); + int c; + for (c = 0; c < 4; c++) { + rgba[c][j] = out[c]; + } + } + + if (DEBUG_TEX) { + print_sample(__FUNCTION__, rgba); + } +} + + +static void +img_filter_2d_nearest(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + const struct pipe_resource *texture = samp->texture; + unsigned level0, j; + int width, height; + int x[4], y[4]; + union tex_tile_address addr; + + + level0 = samp->level; + width = u_minify(texture->width0, level0); + height = u_minify(texture->height0, level0); + + assert(width > 0); + assert(height > 0); + + addr.value = 0; + addr.bits.level = samp->level; + + samp->nearest_texcoord_s(s, width, x); + samp->nearest_texcoord_t(t, height, y); + + for (j = 0; j < QUAD_SIZE; j++) { + const float *out = get_texel_2d(samp, addr, x[j], y[j]); + int c; + for (c = 0; c < 4; c++) { + rgba[c][j] = out[c]; + } + } + + if (DEBUG_TEX) { + print_sample(__FUNCTION__, rgba); + } +} + + +static INLINE union tex_tile_address +face(union tex_tile_address addr, unsigned face ) +{ + addr.bits.face = face; + return addr; +} + + +static void +img_filter_cube_nearest(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + const struct pipe_resource *texture = samp->texture; + const unsigned *faces = samp->faces; /* zero when not cube-mapping */ + unsigned level0, j; + int width, height; + int x[4], y[4]; + union tex_tile_address addr; + + level0 = samp->level; + width = u_minify(texture->width0, level0); + height = u_minify(texture->height0, level0); + + assert(width > 0); + assert(height > 0); + + addr.value = 0; + addr.bits.level = samp->level; + + samp->nearest_texcoord_s(s, width, x); + samp->nearest_texcoord_t(t, height, y); + + for (j = 0; j < QUAD_SIZE; j++) { + const float *out = get_texel_2d(samp, face(addr, faces[j]), x[j], y[j]); + int c; + for (c = 0; c < 4; c++) { + rgba[c][j] = out[c]; + } + } + + if (DEBUG_TEX) { + print_sample(__FUNCTION__, rgba); + } +} + + +static void +img_filter_3d_nearest(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + const struct pipe_resource *texture = samp->texture; + unsigned level0, j; + int width, height, depth; + int x[4], y[4], z[4]; + union tex_tile_address addr; + + level0 = samp->level; + width = u_minify(texture->width0, level0); + height = u_minify(texture->height0, level0); + depth = u_minify(texture->depth0, level0); + + assert(width > 0); + assert(height > 0); + assert(depth > 0); + + samp->nearest_texcoord_s(s, width, x); + samp->nearest_texcoord_t(t, height, y); + samp->nearest_texcoord_p(p, depth, z); + + addr.value = 0; + addr.bits.level = samp->level; + + for (j = 0; j < QUAD_SIZE; j++) { + const float *out = get_texel_3d(samp, addr, x[j], y[j], z[j]); + int c; + for (c = 0; c < 4; c++) { + rgba[c][j] = out[c]; + } + } +} + + +static void +img_filter_1d_linear(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + const struct pipe_resource *texture = samp->texture; + unsigned level0, j; + int width; + int x0[4], x1[4]; + float xw[4]; /* weights */ + union tex_tile_address addr; + + level0 = samp->level; + width = u_minify(texture->width0, level0); + + assert(width > 0); + + addr.value = 0; + addr.bits.level = samp->level; + + samp->linear_texcoord_s(s, width, x0, x1, xw); + + for (j = 0; j < QUAD_SIZE; j++) { + const float *tx0 = get_texel_2d(samp, addr, x0[j], 0); + const float *tx1 = get_texel_2d(samp, addr, x1[j], 0); + int c; + + /* interpolate R, G, B, A */ + for (c = 0; c < 4; c++) { + rgba[c][j] = lerp(xw[j], tx0[c], tx1[c]); + } + } +} + + +static void +img_filter_2d_linear(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + const struct pipe_resource *texture = samp->texture; + unsigned level0, j; + int width, height; + int x0[4], y0[4], x1[4], y1[4]; + float xw[4], yw[4]; /* weights */ + union tex_tile_address addr; + + level0 = samp->level; + width = u_minify(texture->width0, level0); + height = u_minify(texture->height0, level0); + + assert(width > 0); + assert(height > 0); + + addr.value = 0; + addr.bits.level = samp->level; + + samp->linear_texcoord_s(s, width, x0, x1, xw); + samp->linear_texcoord_t(t, height, y0, y1, yw); + + for (j = 0; j < QUAD_SIZE; j++) { + const float *tx0 = get_texel_2d(samp, addr, x0[j], y0[j]); + const float *tx1 = get_texel_2d(samp, addr, x1[j], y0[j]); + const float *tx2 = get_texel_2d(samp, addr, x0[j], y1[j]); + const float *tx3 = get_texel_2d(samp, addr, x1[j], y1[j]); + int c; + + /* interpolate R, G, B, A */ + for (c = 0; c < 4; c++) { + rgba[c][j] = lerp_2d(xw[j], yw[j], + tx0[c], tx1[c], + tx2[c], tx3[c]); + } + } +} + + +static void +img_filter_cube_linear(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + const struct pipe_resource *texture = samp->texture; + const unsigned *faces = samp->faces; /* zero when not cube-mapping */ + unsigned level0, j; + int width, height; + int x0[4], y0[4], x1[4], y1[4]; + float xw[4], yw[4]; /* weights */ + union tex_tile_address addr; + + level0 = samp->level; + width = u_minify(texture->width0, level0); + height = u_minify(texture->height0, level0); + + assert(width > 0); + assert(height > 0); + + addr.value = 0; + addr.bits.level = samp->level; + + samp->linear_texcoord_s(s, width, x0, x1, xw); + samp->linear_texcoord_t(t, height, y0, y1, yw); + + for (j = 0; j < QUAD_SIZE; j++) { + union tex_tile_address addrj = face(addr, faces[j]); + const float *tx0 = get_texel_2d(samp, addrj, x0[j], y0[j]); + const float *tx1 = get_texel_2d(samp, addrj, x1[j], y0[j]); + const float *tx2 = get_texel_2d(samp, addrj, x0[j], y1[j]); + const float *tx3 = get_texel_2d(samp, addrj, x1[j], y1[j]); + int c; + + /* interpolate R, G, B, A */ + for (c = 0; c < 4; c++) { + rgba[c][j] = lerp_2d(xw[j], yw[j], + tx0[c], tx1[c], + tx2[c], tx3[c]); + } + } +} + + +static void +img_filter_3d_linear(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + const struct pipe_resource *texture = samp->texture; + unsigned level0, j; + int width, height, depth; + int x0[4], x1[4], y0[4], y1[4], z0[4], z1[4]; + float xw[4], yw[4], zw[4]; /* interpolation weights */ + union tex_tile_address addr; + + level0 = samp->level; + width = u_minify(texture->width0, level0); + height = u_minify(texture->height0, level0); + depth = u_minify(texture->depth0, level0); + + addr.value = 0; + addr.bits.level = level0; + + assert(width > 0); + assert(height > 0); + assert(depth > 0); + + samp->linear_texcoord_s(s, width, x0, x1, xw); + samp->linear_texcoord_t(t, height, y0, y1, yw); + samp->linear_texcoord_p(p, depth, z0, z1, zw); + + for (j = 0; j < QUAD_SIZE; j++) { + int c; + + const float *tx00 = get_texel_3d(samp, addr, x0[j], y0[j], z0[j]); + const float *tx01 = get_texel_3d(samp, addr, x1[j], y0[j], z0[j]); + const float *tx02 = get_texel_3d(samp, addr, x0[j], y1[j], z0[j]); + const float *tx03 = get_texel_3d(samp, addr, x1[j], y1[j], z0[j]); + + const float *tx10 = get_texel_3d(samp, addr, x0[j], y0[j], z1[j]); + const float *tx11 = get_texel_3d(samp, addr, x1[j], y0[j], z1[j]); + const float *tx12 = get_texel_3d(samp, addr, x0[j], y1[j], z1[j]); + const float *tx13 = get_texel_3d(samp, addr, x1[j], y1[j], z1[j]); + + /* interpolate R, G, B, A */ + for (c = 0; c < 4; c++) { + rgba[c][j] = lerp_3d(xw[j], yw[j], zw[j], + tx00[c], tx01[c], + tx02[c], tx03[c], + tx10[c], tx11[c], + tx12[c], tx13[c]); + } + } +} + + +/* Calculate level of detail for every fragment. + * Note that lambda has already been biased by global LOD bias. + */ +static INLINE void +compute_lod(const struct pipe_sampler_state *sampler, + const float biased_lambda, + const float lodbias[QUAD_SIZE], + float lod[QUAD_SIZE]) +{ + uint i; + + for (i = 0; i < QUAD_SIZE; i++) { + lod[i] = biased_lambda + lodbias[i]; + lod[i] = CLAMP(lod[i], sampler->min_lod, sampler->max_lod); + } +} + + +static void +mip_filter_linear(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + const struct pipe_resource *texture = samp->texture; + int level0; + float lambda; + float lod[QUAD_SIZE]; + + if (control == tgsi_sampler_lod_bias) { + lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; + compute_lod(samp->sampler, lambda, c0, lod); + } else { + assert(control == tgsi_sampler_lod_explicit); + + memcpy(lod, c0, sizeof(lod)); + } + + /* XXX: Take into account all lod values. + */ + lambda = lod[0]; + level0 = (int)lambda; + + if (lambda < 0.0) { + samp->level = 0; + samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); + } + else if (level0 >= texture->last_level) { + samp->level = texture->last_level; + samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); + } + else { + float levelBlend = lambda - level0; + float rgba0[4][4]; + float rgba1[4][4]; + int c,j; + + samp->level = level0; + samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba0); + + samp->level = level0+1; + samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba1); + + for (j = 0; j < QUAD_SIZE; j++) { + for (c = 0; c < 4; c++) { + rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]); + } + } + } + + if (DEBUG_TEX) { + print_sample(__FUNCTION__, rgba); + } +} + + +/** + * Compute nearest mipmap level from texcoords. + * Then sample the texture level for four elements of a quad. + * \param c0 the LOD bias factors, or absolute LODs (depending on control) + */ +static void +mip_filter_nearest(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + const struct pipe_resource *texture = samp->texture; + float lambda; + float lod[QUAD_SIZE]; + + if (control == tgsi_sampler_lod_bias) { + lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; + compute_lod(samp->sampler, lambda, c0, lod); + } else { + assert(control == tgsi_sampler_lod_explicit); + + memcpy(lod, c0, sizeof(lod)); + } + + /* XXX: Take into account all lod values. + */ + lambda = lod[0]; + + if (lambda < 0.0) { + samp->level = 0; + samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); + } + else { + samp->level = (int)(lambda + 0.5) ; + samp->level = MIN2(samp->level, (int)texture->last_level); + samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); + } + + if (DEBUG_TEX) { + print_sample(__FUNCTION__, rgba); + } +} + + +static void +mip_filter_none(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + float lambda; + float lod[QUAD_SIZE]; + + if (control == tgsi_sampler_lod_bias) { + lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; + compute_lod(samp->sampler, lambda, c0, lod); + } else { + assert(control == tgsi_sampler_lod_explicit); + + memcpy(lod, c0, sizeof(lod)); + } + + /* XXX: Take into account all lod values. + */ + lambda = lod[0]; + + if (lambda < 0.0) { + samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); + } + else { + samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); + } +} + + + +/** + * Specialized version of mip_filter_linear with hard-wired calls to + * 2d lambda calculation and 2d_linear_repeat_POT img filters. + */ +static void +mip_filter_linear_2d_linear_repeat_POT( + struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + const struct pipe_resource *texture = samp->texture; + int level0; + float lambda; + float lod[QUAD_SIZE]; + + if (control == tgsi_sampler_lod_bias) { + lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; + compute_lod(samp->sampler, lambda, c0, lod); + } else { + assert(control == tgsi_sampler_lod_explicit); + + memcpy(lod, c0, sizeof(lod)); + } + + /* XXX: Take into account all lod values. + */ + lambda = lod[0]; + level0 = (int)lambda; + + /* Catches both negative and large values of level0: + */ + if ((unsigned)level0 >= texture->last_level) { + if (level0 < 0) + samp->level = 0; + else + samp->level = texture->last_level; + + img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); + } + else { + float levelBlend = lambda - level0; + float rgba0[4][4]; + float rgba1[4][4]; + int c,j; + + samp->level = level0; + img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba0); + + samp->level = level0+1; + img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba1); + + for (j = 0; j < QUAD_SIZE; j++) { + for (c = 0; c < 4; c++) { + rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]); + } + } + } + + if (DEBUG_TEX) { + print_sample(__FUNCTION__, rgba); + } +} + + + +/** + * Do shadow/depth comparisons. + */ +static void +sample_compare(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + const struct pipe_sampler_state *sampler = samp->sampler; + int j, k0, k1, k2, k3; + float val; + + samp->mip_filter(tgsi_sampler, s, t, p, c0, control, rgba); + + /** + * Compare texcoord 'p' (aka R) against texture value 'rgba[0]' + * When we sampled the depth texture, the depth value was put into all + * RGBA channels. We look at the red channel here. + */ + + /* compare four texcoords vs. four texture samples */ + switch (sampler->compare_func) { + case PIPE_FUNC_LESS: + k0 = p[0] < rgba[0][0]; + k1 = p[1] < rgba[0][1]; + k2 = p[2] < rgba[0][2]; + k3 = p[3] < rgba[0][3]; + break; + case PIPE_FUNC_LEQUAL: + k0 = p[0] <= rgba[0][0]; + k1 = p[1] <= rgba[0][1]; + k2 = p[2] <= rgba[0][2]; + k3 = p[3] <= rgba[0][3]; + break; + case PIPE_FUNC_GREATER: + k0 = p[0] > rgba[0][0]; + k1 = p[1] > rgba[0][1]; + k2 = p[2] > rgba[0][2]; + k3 = p[3] > rgba[0][3]; + break; + case PIPE_FUNC_GEQUAL: + k0 = p[0] >= rgba[0][0]; + k1 = p[1] >= rgba[0][1]; + k2 = p[2] >= rgba[0][2]; + k3 = p[3] >= rgba[0][3]; + break; + case PIPE_FUNC_EQUAL: + k0 = p[0] == rgba[0][0]; + k1 = p[1] == rgba[0][1]; + k2 = p[2] == rgba[0][2]; + k3 = p[3] == rgba[0][3]; + break; + case PIPE_FUNC_NOTEQUAL: + k0 = p[0] != rgba[0][0]; + k1 = p[1] != rgba[0][1]; + k2 = p[2] != rgba[0][2]; + k3 = p[3] != rgba[0][3]; + break; + case PIPE_FUNC_ALWAYS: + k0 = k1 = k2 = k3 = 1; + break; + case PIPE_FUNC_NEVER: + k0 = k1 = k2 = k3 = 0; + break; + default: + k0 = k1 = k2 = k3 = 0; + assert(0); + break; + } + + /* convert four pass/fail values to an intensity in [0,1] */ + val = 0.25F * (k0 + k1 + k2 + k3); + + /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */ + for (j = 0; j < 4; j++) { + rgba[0][j] = rgba[1][j] = rgba[2][j] = val; + rgba[3][j] = 1.0F; + } +} + + +/** + * Use 3D texcoords to choose a cube face, then sample the 2D cube faces. + * Put face info into the sampler faces[] array. + */ +static void +sample_cube(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]) +{ + struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); + unsigned j; + float ssss[4], tttt[4]; + + /* + major axis + direction target sc tc ma + ---------- ------------------------------- --- --- --- + +rx TEXTURE_CUBE_MAP_POSITIVE_X_EXT -rz -ry rx + -rx TEXTURE_CUBE_MAP_NEGATIVE_X_EXT +rz -ry rx + +ry TEXTURE_CUBE_MAP_POSITIVE_Y_EXT +rx +rz ry + -ry TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT +rx -rz ry + +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz + -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz + */ + + /* Choose the cube face and compute new s/t coords for the 2D face. + * + * Use the same cube face for all four pixels in the quad. + * + * This isn't ideal, but if we want to use a different cube face + * per pixel in the quad, we'd have to also compute the per-face + * LOD here too. That's because the four post-face-selection + * texcoords are no longer related to each other (they're + * per-face!) so we can't use subtraction to compute the partial + * deriviates to compute the LOD. Doing so (near cube edges + * anyway) gives us pretty much random values. + */ + { + /* use the average of the four pixel's texcoords to choose the face */ + const float rx = 0.25 * (s[0] + s[1] + s[2] + s[3]); + const float ry = 0.25 * (t[0] + t[1] + t[2] + t[3]); + const float rz = 0.25 * (p[0] + p[1] + p[2] + p[3]); + const float arx = fabsf(rx), ary = fabsf(ry), arz = fabsf(rz); + + if (arx >= ary && arx >= arz) { + float sign = (rx >= 0.0F) ? 1.0F : -1.0F; + uint face = (rx >= 0.0F) ? PIPE_TEX_FACE_POS_X : PIPE_TEX_FACE_NEG_X; + for (j = 0; j < QUAD_SIZE; j++) { + const float ima = -0.5F / fabsf(s[j]); + ssss[j] = sign * p[j] * ima + 0.5F; + tttt[j] = t[j] * ima + 0.5F; + samp->faces[j] = face; + } + } + else if (ary >= arx && ary >= arz) { + float sign = (ry >= 0.0F) ? 1.0F : -1.0F; + uint face = (ry >= 0.0F) ? PIPE_TEX_FACE_POS_Y : PIPE_TEX_FACE_NEG_Y; + for (j = 0; j < QUAD_SIZE; j++) { + const float ima = -0.5F / fabsf(t[j]); + ssss[j] = -s[j] * ima + 0.5F; + tttt[j] = sign * -p[j] * ima + 0.5F; + samp->faces[j] = face; + } + } + else { + float sign = (rz >= 0.0F) ? 1.0F : -1.0F; + uint face = (rz >= 0.0F) ? PIPE_TEX_FACE_POS_Z : PIPE_TEX_FACE_NEG_Z; + for (j = 0; j < QUAD_SIZE; j++) { + const float ima = -0.5 / fabsf(p[j]); + ssss[j] = sign * -s[j] * ima + 0.5F; + tttt[j] = t[j] * ima + 0.5F; + samp->faces[j] = face; + } + } + } + + /* In our little pipeline, the compare stage is next. If compare + * is not active, this will point somewhere deeper into the + * pipeline, eg. to mip_filter or even img_filter. + */ + samp->compare(tgsi_sampler, ssss, tttt, NULL, c0, control, rgba); +} + + + +static wrap_nearest_func +get_nearest_unorm_wrap(unsigned mode) +{ + switch (mode) { + case PIPE_TEX_WRAP_CLAMP: + return wrap_nearest_unorm_clamp; + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return wrap_nearest_unorm_clamp_to_edge; + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + return wrap_nearest_unorm_clamp_to_border; + default: + assert(0); + return wrap_nearest_unorm_clamp; + } +} + + +static wrap_nearest_func +get_nearest_wrap(unsigned mode) +{ + switch (mode) { + case PIPE_TEX_WRAP_REPEAT: + return wrap_nearest_repeat; + case PIPE_TEX_WRAP_CLAMP: + return wrap_nearest_clamp; + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return wrap_nearest_clamp_to_edge; + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + return wrap_nearest_clamp_to_border; + case PIPE_TEX_WRAP_MIRROR_REPEAT: + return wrap_nearest_mirror_repeat; + case PIPE_TEX_WRAP_MIRROR_CLAMP: + return wrap_nearest_mirror_clamp; + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + return wrap_nearest_mirror_clamp_to_edge; + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + return wrap_nearest_mirror_clamp_to_border; + default: + assert(0); + return wrap_nearest_repeat; + } +} + + +static wrap_linear_func +get_linear_unorm_wrap(unsigned mode) +{ + switch (mode) { + case PIPE_TEX_WRAP_CLAMP: + return wrap_linear_unorm_clamp; + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return wrap_linear_unorm_clamp_to_edge; + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + return wrap_linear_unorm_clamp_to_border; + default: + assert(0); + return wrap_linear_unorm_clamp; + } +} + + +static wrap_linear_func +get_linear_wrap(unsigned mode) +{ + switch (mode) { + case PIPE_TEX_WRAP_REPEAT: + return wrap_linear_repeat; + case PIPE_TEX_WRAP_CLAMP: + return wrap_linear_clamp; + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return wrap_linear_clamp_to_edge; + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + return wrap_linear_clamp_to_border; + case PIPE_TEX_WRAP_MIRROR_REPEAT: + return wrap_linear_mirror_repeat; + case PIPE_TEX_WRAP_MIRROR_CLAMP: + return wrap_linear_mirror_clamp; + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + return wrap_linear_mirror_clamp_to_edge; + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + return wrap_linear_mirror_clamp_to_border; + default: + assert(0); + return wrap_linear_repeat; + } +} + + +static compute_lambda_func +get_lambda_func(const union sp_sampler_key key) +{ + if (key.bits.processor == TGSI_PROCESSOR_VERTEX) + return compute_lambda_vert; + + switch (key.bits.target) { + case PIPE_TEXTURE_1D: + return compute_lambda_1d; + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + case PIPE_TEXTURE_CUBE: + return compute_lambda_2d; + case PIPE_TEXTURE_3D: + return compute_lambda_3d; + default: + assert(0); + return compute_lambda_1d; + } +} + + +static filter_func +get_img_filter(const union sp_sampler_key key, + unsigned filter, + const struct pipe_sampler_state *sampler) +{ + switch (key.bits.target) { + case PIPE_TEXTURE_1D: + if (filter == PIPE_TEX_FILTER_NEAREST) + return img_filter_1d_nearest; + else + return img_filter_1d_linear; + break; + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + /* Try for fast path: + */ + if (key.bits.is_pot && + sampler->wrap_s == sampler->wrap_t && + sampler->normalized_coords) + { + switch (sampler->wrap_s) { + case PIPE_TEX_WRAP_REPEAT: + switch (filter) { + case PIPE_TEX_FILTER_NEAREST: + return img_filter_2d_nearest_repeat_POT; + case PIPE_TEX_FILTER_LINEAR: + return img_filter_2d_linear_repeat_POT; + default: + break; + } + break; + case PIPE_TEX_WRAP_CLAMP: + switch (filter) { + case PIPE_TEX_FILTER_NEAREST: + return img_filter_2d_nearest_clamp_POT; + default: + break; + } + } + } + /* Otherwise use default versions: + */ + if (filter == PIPE_TEX_FILTER_NEAREST) + return img_filter_2d_nearest; + else + return img_filter_2d_linear; + break; + case PIPE_TEXTURE_CUBE: + if (filter == PIPE_TEX_FILTER_NEAREST) + return img_filter_cube_nearest; + else + return img_filter_cube_linear; + break; + case PIPE_TEXTURE_3D: + if (filter == PIPE_TEX_FILTER_NEAREST) + return img_filter_3d_nearest; + else + return img_filter_3d_linear; + break; + default: + assert(0); + return img_filter_1d_nearest; + } +} + + +/** + * Bind the given texture object and texture cache to the sampler varient. + */ +void +sp_sampler_varient_bind_texture( struct sp_sampler_varient *samp, + struct softpipe_tex_tile_cache *tex_cache, + const struct pipe_resource *texture ) +{ + const struct pipe_sampler_state *sampler = samp->sampler; + + samp->texture = texture; + samp->cache = tex_cache; + samp->xpot = util_unsigned_logbase2( texture->width0 ); + samp->ypot = util_unsigned_logbase2( texture->height0 ); + samp->level = CLAMP((int) sampler->min_lod, 0, (int) texture->last_level); +} + + +void +sp_sampler_varient_destroy( struct sp_sampler_varient *samp ) +{ + FREE(samp); +} + + +/** + * Create a sampler varient for a given set of non-orthogonal state. + */ +struct sp_sampler_varient * +sp_create_sampler_varient( const struct pipe_sampler_state *sampler, + const union sp_sampler_key key ) +{ + struct sp_sampler_varient *samp = CALLOC_STRUCT(sp_sampler_varient); + if (!samp) + return NULL; + + samp->sampler = sampler; + samp->key = key; + + /* Note that (for instance) linear_texcoord_s and + * nearest_texcoord_s may be active at the same time, if the + * sampler min_img_filter differs from its mag_img_filter. + */ + if (sampler->normalized_coords) { + samp->linear_texcoord_s = get_linear_wrap( sampler->wrap_s ); + samp->linear_texcoord_t = get_linear_wrap( sampler->wrap_t ); + samp->linear_texcoord_p = get_linear_wrap( sampler->wrap_r ); + + samp->nearest_texcoord_s = get_nearest_wrap( sampler->wrap_s ); + samp->nearest_texcoord_t = get_nearest_wrap( sampler->wrap_t ); + samp->nearest_texcoord_p = get_nearest_wrap( sampler->wrap_r ); + } + else { + samp->linear_texcoord_s = get_linear_unorm_wrap( sampler->wrap_s ); + samp->linear_texcoord_t = get_linear_unorm_wrap( sampler->wrap_t ); + samp->linear_texcoord_p = get_linear_unorm_wrap( sampler->wrap_r ); + + samp->nearest_texcoord_s = get_nearest_unorm_wrap( sampler->wrap_s ); + samp->nearest_texcoord_t = get_nearest_unorm_wrap( sampler->wrap_t ); + samp->nearest_texcoord_p = get_nearest_unorm_wrap( sampler->wrap_r ); + } + + samp->compute_lambda = get_lambda_func( key ); + + samp->min_img_filter = get_img_filter(key, sampler->min_img_filter, sampler); + samp->mag_img_filter = get_img_filter(key, sampler->mag_img_filter, sampler); + + switch (sampler->min_mip_filter) { + case PIPE_TEX_MIPFILTER_NONE: + if (sampler->min_img_filter == sampler->mag_img_filter) + samp->mip_filter = samp->min_img_filter; + else + samp->mip_filter = mip_filter_none; + break; + + case PIPE_TEX_MIPFILTER_NEAREST: + samp->mip_filter = mip_filter_nearest; + break; + + case PIPE_TEX_MIPFILTER_LINEAR: + if (key.bits.is_pot && + sampler->min_img_filter == sampler->mag_img_filter && + sampler->normalized_coords && + sampler->wrap_s == PIPE_TEX_WRAP_REPEAT && + sampler->wrap_t == PIPE_TEX_WRAP_REPEAT && + sampler->min_img_filter == PIPE_TEX_FILTER_LINEAR) + { + samp->mip_filter = mip_filter_linear_2d_linear_repeat_POT; + } + else + { + samp->mip_filter = mip_filter_linear; + } + break; + } + + if (sampler->compare_mode != PIPE_TEX_COMPARE_NONE) { + samp->compare = sample_compare; + } + else { + /* Skip compare operation by promoting the mip_filter function + * pointer: + */ + samp->compare = samp->mip_filter; + } + + if (key.bits.target == PIPE_TEXTURE_CUBE) { + samp->base.get_samples = sample_cube; + } + else { + samp->faces[0] = 0; + samp->faces[1] = 0; + samp->faces[2] = 0; + samp->faces[3] = 0; + + /* Skip cube face determination by promoting the compare + * function pointer: + */ + samp->base.get_samples = samp->compare; + } + + return samp; +} diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.h b/src/gallium/drivers/softpipe/sp_tex_sample.h new file mode 100644 index 0000000..6114acf --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_tex_sample.h @@ -0,0 +1,153 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * Copyright 2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL 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. + * + **************************************************************************/ + +#ifndef SP_TEX_SAMPLE_H +#define SP_TEX_SAMPLE_H + + +#include "tgsi/tgsi_exec.h" + +struct sp_sampler_varient; + +typedef void (*wrap_nearest_func)(const float s[4], + unsigned size, + int icoord[4]); + +typedef void (*wrap_linear_func)(const float s[4], + unsigned size, + int icoord0[4], + int icoord1[4], + float w[4]); + +typedef float (*compute_lambda_func)(const struct sp_sampler_varient *sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE]); + +typedef void (*filter_func)(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + const float c0[QUAD_SIZE], + enum tgsi_sampler_control control, + float rgba[NUM_CHANNELS][QUAD_SIZE]); + + +union sp_sampler_key { + struct { + unsigned target:3; + unsigned is_pot:1; + unsigned processor:2; + unsigned unit:4; + unsigned pad:22; + } bits; + unsigned value; +}; + +/** + * Subclass of tgsi_sampler + */ +struct sp_sampler_varient +{ + struct tgsi_sampler base; /**< base class */ + + union sp_sampler_key key; + + /* The owner of this struct: + */ + const struct pipe_sampler_state *sampler; + + + /* Currently bound texture: + */ + const struct pipe_resource *texture; + struct softpipe_tex_tile_cache *cache; + + unsigned processor; + + /* For sp_get_samples_2d_linear_POT: + */ + unsigned xpot; + unsigned ypot; + unsigned level; + + unsigned faces[4]; + + wrap_nearest_func nearest_texcoord_s; + wrap_nearest_func nearest_texcoord_t; + wrap_nearest_func nearest_texcoord_p; + + wrap_linear_func linear_texcoord_s; + wrap_linear_func linear_texcoord_t; + wrap_linear_func linear_texcoord_p; + + filter_func min_img_filter; + filter_func mag_img_filter; + + compute_lambda_func compute_lambda; + + filter_func mip_filter; + filter_func compare; + + /* Linked list: + */ + struct sp_sampler_varient *next; +}; + +struct sp_sampler; + +/* Create a sampler varient for a given set of non-orthogonal state. Currently the + */ +struct sp_sampler_varient * +sp_create_sampler_varient( const struct pipe_sampler_state *sampler, + const union sp_sampler_key key ); + +void sp_sampler_varient_bind_texture( struct sp_sampler_varient *varient, + struct softpipe_tex_tile_cache *tex_cache, + const struct pipe_resource *tex ); + +void sp_sampler_varient_destroy( struct sp_sampler_varient * ); + + + +static INLINE struct sp_sampler_varient * +sp_sampler_varient(const struct tgsi_sampler *sampler) +{ + return (struct sp_sampler_varient *) sampler; +} + +extern void +sp_get_samples(struct tgsi_sampler *tgsi_sampler, + const float s[QUAD_SIZE], + const float t[QUAD_SIZE], + const float p[QUAD_SIZE], + float lodbias, + float rgba[NUM_CHANNELS][QUAD_SIZE]); + + +#endif /* SP_TEX_SAMPLE_H */ diff --git a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c new file mode 100644 index 0000000..1393164 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c @@ -0,0 +1,322 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Texture tile caching. + * + * Author: + * Brian Paul + */ + +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_tile.h" +#include "util/u_math.h" +#include "sp_context.h" +#include "sp_texture.h" +#include "sp_tex_tile_cache.h" + + + +struct softpipe_tex_tile_cache * +sp_create_tex_tile_cache( struct pipe_context *pipe ) +{ + struct softpipe_tex_tile_cache *tc; + uint pos; + + /* make sure max texture size works */ + assert((TILE_SIZE << TEX_ADDR_BITS) >= (1 << (SP_MAX_TEXTURE_2D_LEVELS-1))); + + tc = CALLOC_STRUCT( softpipe_tex_tile_cache ); + if (tc) { + tc->pipe = pipe; + for (pos = 0; pos < NUM_ENTRIES; pos++) { + tc->entries[pos].addr.bits.invalid = 1; + } + tc->last_tile = &tc->entries[0]; /* any tile */ + } + return tc; +} + + +void +sp_destroy_tex_tile_cache(struct softpipe_tex_tile_cache *tc) +{ + if (tc) { + uint pos; + + for (pos = 0; pos < NUM_ENTRIES; pos++) { + /*assert(tc->entries[pos].x < 0);*/ + } + if (tc->transfer) { + tc->pipe->transfer_destroy(tc->pipe, tc->transfer); + } + if (tc->tex_trans) { + tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans); + } + + FREE( tc ); + } +} + + + + +void +sp_tex_tile_cache_map_transfers(struct softpipe_tex_tile_cache *tc) +{ + if (tc->tex_trans && !tc->tex_trans_map) + tc->tex_trans_map = tc->pipe->transfer_map(tc->pipe, tc->tex_trans); +} + + +void +sp_tex_tile_cache_unmap_transfers(struct softpipe_tex_tile_cache *tc) +{ + if (tc->tex_trans_map) { + tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans); + tc->tex_trans_map = NULL; + } +} + +/** + * Invalidate all cached tiles for the cached texture. + * Should be called when the texture is modified. + */ +void +sp_tex_tile_cache_validate_texture(struct softpipe_tex_tile_cache *tc) +{ + unsigned i; + + assert(tc); + assert(tc->texture); + + for (i = 0; i < NUM_ENTRIES; i++) { + tc->entries[i].addr.bits.invalid = 1; + } +} + +static boolean +sp_tex_tile_is_compat_view(struct softpipe_tex_tile_cache *tc, + struct pipe_sampler_view *view) +{ + if (!view) + return FALSE; + return (tc->texture == view->texture && + tc->format == view->format && + tc->swizzle_r == view->swizzle_r && + tc->swizzle_g == view->swizzle_g && + tc->swizzle_b == view->swizzle_b && + tc->swizzle_a == view->swizzle_a); +} + +/** + * Specify the sampler view to cache. + */ +void +sp_tex_tile_cache_set_sampler_view(struct softpipe_tex_tile_cache *tc, + struct pipe_sampler_view *view) +{ + struct pipe_resource *texture = view ? view->texture : NULL; + uint i; + + assert(!tc->transfer); + + if (!sp_tex_tile_is_compat_view(tc, view)) { + pipe_resource_reference(&tc->texture, texture); + + if (tc->tex_trans) { + if (tc->tex_trans_map) { + tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans); + tc->tex_trans_map = NULL; + } + + tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans); + tc->tex_trans = NULL; + } + + if (view) { + tc->swizzle_r = view->swizzle_r; + tc->swizzle_g = view->swizzle_g; + tc->swizzle_b = view->swizzle_b; + tc->swizzle_a = view->swizzle_a; + tc->format = view->format; + } + + /* mark as entries as invalid/empty */ + /* XXX we should try to avoid this when the teximage hasn't changed */ + for (i = 0; i < NUM_ENTRIES; i++) { + tc->entries[i].addr.bits.invalid = 1; + } + + tc->tex_face = -1; /* any invalid value here */ + } +} + + + + +/** + * Flush the tile cache: write all dirty tiles back to the transfer. + * any tiles "flagged" as cleared will be "really" cleared. + */ +void +sp_flush_tex_tile_cache(struct softpipe_tex_tile_cache *tc) +{ + int pos; + + if (tc->texture) { + /* caching a texture, mark all entries as empty */ + for (pos = 0; pos < NUM_ENTRIES; pos++) { + tc->entries[pos].addr.bits.invalid = 1; + } + tc->tex_face = -1; + } + +} + + +/** + * Given the texture face, level, zslice, x and y values, compute + * the cache entry position/index where we'd hope to find the + * cached texture tile. + * This is basically a direct-map cache. + * XXX There's probably lots of ways in which we can improve this. + */ +static INLINE uint +tex_cache_pos( union tex_tile_address addr ) +{ + uint entry = (addr.bits.x + + addr.bits.y * 9 + + addr.bits.z * 3 + + addr.bits.face + + addr.bits.level * 7); + + return entry % NUM_ENTRIES; +} + +/** + * Similar to sp_get_cached_tile() but for textures. + * Tiles are read-only and indexed with more params. + */ +const struct softpipe_tex_cached_tile * +sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc, + union tex_tile_address addr ) +{ + struct softpipe_tex_cached_tile *tile; + + tile = tc->entries + tex_cache_pos( addr ); + + if (addr.value != tile->addr.value) { + + /* cache miss. Most misses are because we've invaldiated the + * texture cache previously -- most commonly on binding a new + * texture. Currently we effectively flush the cache on texture + * bind. + */ +#if 0 + _debug_printf("miss at %u: x=%d y=%d z=%d face=%d level=%d\n" + " tile %u: x=%d y=%d z=%d face=%d level=%d\n", + pos, x/TILE_SIZE, y/TILE_SIZE, z, face, level, + pos, tile->addr.bits.x, tile->addr.bits.y, tile->z, tile->face, tile->level); +#endif + + /* check if we need to get a new transfer */ + if (!tc->tex_trans || + tc->tex_face != addr.bits.face || + tc->tex_level != addr.bits.level || + tc->tex_z != addr.bits.z) { + /* get new transfer (view into texture) */ + + if (tc->tex_trans) { + if (tc->tex_trans_map) { + tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans); + tc->tex_trans_map = NULL; + } + + tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans); + tc->tex_trans = NULL; + } + + tc->tex_trans = + pipe_get_transfer(tc->pipe, tc->texture, + addr.bits.level, + addr.bits.face + addr.bits.z, + PIPE_TRANSFER_READ | PIPE_TRANSFER_UNSYNCHRONIZED, + 0, 0, + u_minify(tc->texture->width0, addr.bits.level), + u_minify(tc->texture->height0, addr.bits.level)); + + tc->tex_trans_map = tc->pipe->transfer_map(tc->pipe, tc->tex_trans); + + tc->tex_face = addr.bits.face; + tc->tex_level = addr.bits.level; + tc->tex_z = addr.bits.z; + } + + /* get tile from the transfer (view into texture) */ + pipe_get_tile_swizzle(tc->pipe, + tc->tex_trans, + addr.bits.x * TILE_SIZE, + addr.bits.y * TILE_SIZE, + TILE_SIZE, + TILE_SIZE, + tc->swizzle_r, + tc->swizzle_g, + tc->swizzle_b, + tc->swizzle_a, + tc->format, + (float *) tile->data.color); + tile->addr = addr; + } + + tc->last_tile = tile; + return tile; +} + + + +/** + * Return the swizzled border color. + */ +const float * +sp_tex_tile_cache_border_color(struct softpipe_tex_tile_cache *tc, + const float border_color[4]) +{ + float rgba01[6]; + + COPY_4V(rgba01, border_color); + rgba01[PIPE_SWIZZLE_ZERO] = 0.0f; + rgba01[PIPE_SWIZZLE_ONE] = 1.0f; + + tc->swz_border_color[0] = rgba01[tc->swizzle_r]; + tc->swz_border_color[1] = rgba01[tc->swizzle_g]; + tc->swz_border_color[2] = rgba01[tc->swizzle_b]; + tc->swz_border_color[3] = rgba01[tc->swizzle_a]; + + return tc->swz_border_color; +} diff --git a/src/gallium/drivers/softpipe/sp_tex_tile_cache.h b/src/gallium/drivers/softpipe/sp_tex_tile_cache.h new file mode 100644 index 0000000..e0b66bf --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_tex_tile_cache.h @@ -0,0 +1,170 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef SP_TEX_TILE_CACHE_H +#define SP_TEX_TILE_CACHE_H + + +#include "pipe/p_compiler.h" +#include "sp_limits.h" + + +struct softpipe_context; +struct softpipe_tex_tile_cache; + + +/** + * Cache tile size (width and height). This needs to be a power of two. + */ +#define TILE_SIZE_LOG2 6 +#define TILE_SIZE (1 << TILE_SIZE_LOG2) + + +#define TEX_ADDR_BITS (SP_MAX_TEXTURE_2D_LEVELS - 1 - TILE_SIZE_LOG2) +#define TEX_Z_BITS (SP_MAX_TEXTURE_2D_LEVELS - 1) + +/** + * Texture tile address as a union for fast compares. + */ +union tex_tile_address { + struct { + unsigned x:TEX_ADDR_BITS; /* 16K / TILE_SIZE */ + unsigned y:TEX_ADDR_BITS; /* 16K / TILE_SIZE */ + unsigned z:TEX_Z_BITS; /* 16K -- z not tiled */ + unsigned face:3; + unsigned level:4; + unsigned invalid:1; + } bits; + uint64_t value; +}; + + +struct softpipe_tex_cached_tile +{ + union tex_tile_address addr; + union { + float color[TILE_SIZE][TILE_SIZE][4]; + } data; +}; + +#define NUM_ENTRIES 50 + +struct softpipe_tex_tile_cache +{ + struct pipe_context *pipe; + struct pipe_transfer *transfer; + void *transfer_map; + + struct pipe_resource *texture; /**< if caching a texture */ + unsigned timestamp; + + struct softpipe_tex_cached_tile entries[NUM_ENTRIES]; + + struct pipe_transfer *tex_trans; + void *tex_trans_map; + int tex_face, tex_level, tex_z; + + unsigned swizzle_r; + unsigned swizzle_g; + unsigned swizzle_b; + unsigned swizzle_a; + unsigned format; + + struct softpipe_tex_cached_tile *last_tile; /**< most recently retrieved tile */ + + float swz_border_color[4]; /**< swizzled border color */ +}; + + +extern struct softpipe_tex_tile_cache * +sp_create_tex_tile_cache( struct pipe_context *pipe ); + +extern void +sp_destroy_tex_tile_cache(struct softpipe_tex_tile_cache *tc); + + +extern void +sp_tex_tile_cache_map_transfers(struct softpipe_tex_tile_cache *tc); + +extern void +sp_tex_tile_cache_unmap_transfers(struct softpipe_tex_tile_cache *tc); + +extern void +sp_tex_tile_cache_set_sampler_view(struct softpipe_tex_tile_cache *tc, + struct pipe_sampler_view *view); + +void +sp_tex_tile_cache_validate_texture(struct softpipe_tex_tile_cache *tc); + +extern void +sp_flush_tex_tile_cache(struct softpipe_tex_tile_cache *tc); + + + +extern const struct softpipe_tex_cached_tile * +sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc, + union tex_tile_address addr ); + +static INLINE union tex_tile_address +tex_tile_address( unsigned x, + unsigned y, + unsigned z, + unsigned face, + unsigned level ) +{ + union tex_tile_address addr; + + addr.value = 0; + addr.bits.x = x / TILE_SIZE; + addr.bits.y = y / TILE_SIZE; + addr.bits.z = z; + addr.bits.face = face; + addr.bits.level = level; + + return addr; +} + +/* Quickly retrieve tile if it matches last lookup. + */ +static INLINE const struct softpipe_tex_cached_tile * +sp_get_cached_tile_tex(struct softpipe_tex_tile_cache *tc, + union tex_tile_address addr ) +{ + if (tc->last_tile->addr.value == addr.value) + return tc->last_tile; + + return sp_find_cached_tile_tex( tc, addr ); +} + + +const float * +sp_tex_tile_cache_border_color(struct softpipe_tex_tile_cache *tc, + const float border_color[4]); + + +#endif /* SP_TEX_TILE_CACHE_H */ + diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c new file mode 100644 index 0000000..509d998 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -0,0 +1,486 @@ +/************************************************************************** + * + * Copyright 2006 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. + * + **************************************************************************/ + /* + * Authors: + * Keith Whitwell + * Michel Dänzer + */ + +#include "pipe/p_defines.h" +#include "util/u_inlines.h" + +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_transfer.h" + +#include "sp_context.h" +#include "sp_flush.h" +#include "sp_texture.h" +#include "sp_screen.h" + +#include "state_tracker/sw_winsys.h" + + +/** + * Conventional allocation path for non-display textures: + * Use a simple, maximally packed layout. + */ +static boolean +softpipe_resource_layout(struct pipe_screen *screen, + struct softpipe_resource *spr) +{ + struct pipe_resource *pt = &spr->base; + unsigned level; + unsigned width = pt->width0; + unsigned height = pt->height0; + unsigned depth = pt->depth0; + unsigned buffer_size = 0; + + for (level = 0; level <= pt->last_level; level++) { + spr->stride[level] = util_format_get_stride(pt->format, width); + + spr->level_offset[level] = buffer_size; + + buffer_size += (util_format_get_nblocksy(pt->format, height) * + ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) * + spr->stride[level]); + + width = u_minify(width, 1); + height = u_minify(height, 1); + depth = u_minify(depth, 1); + } + + spr->data = align_malloc(buffer_size, 16); + + return spr->data != NULL; +} + + +/** + * Texture layout for simple color buffers. + */ +static boolean +softpipe_displaytarget_layout(struct pipe_screen *screen, + struct softpipe_resource *spr) +{ + struct sw_winsys *winsys = softpipe_screen(screen)->winsys; + + /* Round up the surface size to a multiple of the tile size? + */ + spr->dt = winsys->displaytarget_create(winsys, + spr->base.bind, + spr->base.format, + spr->base.width0, + spr->base.height0, + 16, + &spr->stride[0] ); + + return spr->dt != NULL; +} + + +/** + * Create new pipe_resource given the template information. + */ +static struct pipe_resource * +softpipe_resource_create(struct pipe_screen *screen, + const struct pipe_resource *templat) +{ + struct softpipe_resource *spr = CALLOC_STRUCT(softpipe_resource); + if (!spr) + return NULL; + + assert(templat->format != PIPE_FORMAT_NONE); + + spr->base = *templat; + pipe_reference_init(&spr->base.reference, 1); + spr->base.screen = screen; + + spr->pot = (util_is_power_of_two(templat->width0) && + util_is_power_of_two(templat->height0) && + util_is_power_of_two(templat->depth0)); + + if (spr->base.bind & (PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SCANOUT | + PIPE_BIND_SHARED)) { + if (!softpipe_displaytarget_layout(screen, spr)) + goto fail; + } + else { + if (!softpipe_resource_layout(screen, spr)) + goto fail; + } + + return &spr->base; + + fail: + FREE(spr); + return NULL; +} + + +static void +softpipe_resource_destroy(struct pipe_screen *pscreen, + struct pipe_resource *pt) +{ + struct softpipe_screen *screen = softpipe_screen(pscreen); + struct softpipe_resource *spr = softpipe_resource(pt); + + if (spr->dt) { + /* display target */ + struct sw_winsys *winsys = screen->winsys; + winsys->displaytarget_destroy(winsys, spr->dt); + } + else if (!spr->userBuffer) { + /* regular texture */ + align_free(spr->data); + } + + FREE(spr); +} + + +static struct pipe_resource * +softpipe_resource_from_handle(struct pipe_screen *screen, + const struct pipe_resource *templat, + struct winsys_handle *whandle) +{ + struct sw_winsys *winsys = softpipe_screen(screen)->winsys; + struct softpipe_resource *spr = CALLOC_STRUCT(softpipe_resource); + if (!spr) + return NULL; + + spr->base = *templat; + pipe_reference_init(&spr->base.reference, 1); + spr->base.screen = screen; + + spr->pot = (util_is_power_of_two(templat->width0) && + util_is_power_of_two(templat->height0) && + util_is_power_of_two(templat->depth0)); + + spr->dt = winsys->displaytarget_from_handle(winsys, + templat, + whandle, + &spr->stride[0]); + if (!spr->dt) + goto fail; + + return &spr->base; + + fail: + FREE(spr); + return NULL; +} + + +static boolean +softpipe_resource_get_handle(struct pipe_screen *screen, + struct pipe_resource *pt, + struct winsys_handle *whandle) +{ + struct sw_winsys *winsys = softpipe_screen(screen)->winsys; + struct softpipe_resource *spr = softpipe_resource(pt); + + assert(spr->dt); + if (!spr->dt) + return FALSE; + + return winsys->displaytarget_get_handle(winsys, spr->dt, whandle); +} + + +/** + * Helper function to compute offset (in bytes) for a particular + * texture level/face/slice from the start of the buffer. + */ +static unsigned +sp_get_tex_image_offset(const struct softpipe_resource *spr, + unsigned level, unsigned layer) +{ + const unsigned hgt = u_minify(spr->base.height0, level); + const unsigned nblocksy = util_format_get_nblocksy(spr->base.format, hgt); + unsigned offset = spr->level_offset[level]; + + if (spr->base.target == PIPE_TEXTURE_CUBE || + spr->base.target == PIPE_TEXTURE_3D) { + offset += layer * nblocksy * spr->stride[level]; + } + else { + assert(layer == 0); + } + + return offset; +} + + +/** + * Get a pipe_surface "view" into a texture resource. + */ +static struct pipe_surface * +softpipe_create_surface(struct pipe_context *pipe, + struct pipe_resource *pt, + const struct pipe_surface *surf_tmpl) +{ + struct pipe_surface *ps; + unsigned level = surf_tmpl->u.tex.level; + + assert(level <= pt->last_level); + assert(surf_tmpl->u.tex.first_layer == surf_tmpl->u.tex.last_layer); + + ps = CALLOC_STRUCT(pipe_surface); + if (ps) { + pipe_reference_init(&ps->reference, 1); + pipe_resource_reference(&ps->texture, pt); + ps->context = pipe; + ps->format = surf_tmpl->format; + ps->width = u_minify(pt->width0, level); + ps->height = u_minify(pt->height0, level); + ps->usage = surf_tmpl->usage; + + ps->u.tex.level = level; + ps->u.tex.first_layer = surf_tmpl->u.tex.first_layer; + ps->u.tex.last_layer = surf_tmpl->u.tex.last_layer; + } + return ps; +} + + +/** + * Free a pipe_surface which was created with softpipe_create_surface(). + */ +static void +softpipe_surface_destroy(struct pipe_context *pipe, + struct pipe_surface *surf) +{ + /* Effectively do the texture_update work here - if texture images + * needed post-processing to put them into hardware layout, this is + * where it would happen. For softpipe, nothing to do. + */ + assert(surf->texture); + pipe_resource_reference(&surf->texture, NULL); + FREE(surf); +} + + +/** + * Geta pipe_transfer object which is used for moving data in/out of + * a resource object. + * \param pipe rendering context + * \param resource the resource to transfer in/out of + * \param sr indicates cube face or 3D texture slice + * \param usage bitmask of PIPE_TRANSFER_x flags + * \param box the 1D/2D/3D region of interest + */ +static struct pipe_transfer * +softpipe_get_transfer(struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct softpipe_resource *spr = softpipe_resource(resource); + struct softpipe_transfer *spt; + + assert(resource); + assert(level <= resource->last_level); + + /* make sure the requested region is in the image bounds */ + assert(box->x + box->width <= u_minify(resource->width0, level)); + assert(box->y + box->height <= u_minify(resource->height0, level)); + assert(box->z + box->depth <= (u_minify(resource->depth0, level) + resource->array_size - 1)); + + /* + * Transfers, like other pipe operations, must happen in order, so flush the + * context if necessary. + */ + if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) { + boolean read_only = !(usage & PIPE_TRANSFER_WRITE); + boolean do_not_block = !!(usage & PIPE_TRANSFER_DONTBLOCK); + if (!softpipe_flush_resource(pipe, resource, + level, box->depth > 1 ? -1 : box->z, + 0, /* flush_flags */ + read_only, + TRUE, /* cpu_access */ + do_not_block)) { + /* + * It would have blocked, but state tracker requested no to. + */ + assert(do_not_block); + return NULL; + } + } + + spt = CALLOC_STRUCT(softpipe_transfer); + if (spt) { + struct pipe_transfer *pt = &spt->base; + enum pipe_format format = resource->format; + const unsigned hgt = u_minify(spr->base.height0, level); + const unsigned nblocksy = util_format_get_nblocksy(format, hgt); + + pipe_resource_reference(&pt->resource, resource); + pt->level = level; + pt->usage = usage; + pt->box = *box; + pt->stride = spr->stride[level]; + pt->layer_stride = pt->stride * nblocksy; + + spt->offset = sp_get_tex_image_offset(spr, level, box->z); + + spt->offset += + box->y / util_format_get_blockheight(format) * spt->base.stride + + box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); + + return pt; + } + return NULL; +} + + +/** + * Free a pipe_transfer object which was created with + * softpipe_get_transfer(). + */ +static void +softpipe_transfer_destroy(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + pipe_resource_reference(&transfer->resource, NULL); + FREE(transfer); +} + + +/** + * Create memory mapping for given pipe_transfer object. + */ +static void * +softpipe_transfer_map(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct softpipe_transfer *spt = softpipe_transfer(transfer); + struct softpipe_resource *spr = softpipe_resource(transfer->resource); + struct sw_winsys *winsys = softpipe_screen(pipe->screen)->winsys; + uint8_t *map; + + /* resources backed by display target treated specially: + */ + if (spr->dt) { + map = winsys->displaytarget_map(winsys, spr->dt, transfer->usage); + } + else { + map = spr->data; + } + + if (map == NULL) + return NULL; + else + return map + spt->offset; +} + + +/** + * Unmap memory mapping for given pipe_transfer object. + */ +static void +softpipe_transfer_unmap(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct softpipe_resource *spr; + + assert(transfer->resource); + spr = softpipe_resource(transfer->resource); + + if (spr->dt) { + /* display target */ + struct sw_winsys *winsys = softpipe_screen(pipe->screen)->winsys; + winsys->displaytarget_unmap(winsys, spr->dt); + } + + if (transfer->usage & PIPE_TRANSFER_WRITE) { + /* Mark the texture as dirty to expire the tile caches. */ + spr->timestamp++; + } +} + +/** + * Create buffer which wraps user-space data. + */ +static struct pipe_resource * +softpipe_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned bind_flags) +{ + struct softpipe_resource *spr; + + spr = CALLOC_STRUCT(softpipe_resource); + if (!spr) + return NULL; + + pipe_reference_init(&spr->base.reference, 1); + spr->base.screen = screen; + spr->base.format = PIPE_FORMAT_R8_UNORM; /* ?? */ + spr->base.bind = bind_flags; + spr->base.usage = PIPE_USAGE_IMMUTABLE; + spr->base.flags = 0; + spr->base.width0 = bytes; + spr->base.height0 = 1; + spr->base.depth0 = 1; + spr->base.array_size = 1; + spr->userBuffer = TRUE; + spr->data = ptr; + + return &spr->base; +} + + +void +softpipe_init_texture_funcs(struct pipe_context *pipe) +{ + pipe->get_transfer = softpipe_get_transfer; + pipe->transfer_destroy = softpipe_transfer_destroy; + pipe->transfer_map = softpipe_transfer_map; + pipe->transfer_unmap = softpipe_transfer_unmap; + + pipe->transfer_flush_region = u_default_transfer_flush_region; + pipe->transfer_inline_write = u_default_transfer_inline_write; + + pipe->create_surface = softpipe_create_surface; + pipe->surface_destroy = softpipe_surface_destroy; +} + + +void +softpipe_init_screen_texture_funcs(struct pipe_screen *screen) +{ + screen->resource_create = softpipe_resource_create; + screen->resource_destroy = softpipe_resource_destroy; + screen->resource_from_handle = softpipe_resource_from_handle; + screen->resource_get_handle = softpipe_resource_get_handle; + screen->user_buffer_create = softpipe_user_buffer_create; + +} diff --git a/src/gallium/drivers/softpipe/sp_texture.h b/src/gallium/drivers/softpipe/sp_texture.h new file mode 100644 index 0000000..5603110 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_texture.h @@ -0,0 +1,104 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef SP_TEXTURE_H +#define SP_TEXTURE_H + + +#include "pipe/p_state.h" +#include "sp_limits.h" + + +struct pipe_context; +struct pipe_screen; +struct softpipe_context; + + +/** + * Subclass of pipe_resource. + */ +struct softpipe_resource +{ + struct pipe_resource base; + + unsigned long level_offset[SP_MAX_TEXTURE_2D_LEVELS]; + unsigned stride[SP_MAX_TEXTURE_2D_LEVELS]; + + /** + * Display target, only valid for PIPE_TEXTURE_2D with the + * PIPE_BIND_DISPLAY_TARGET usage. + */ + struct sw_displaytarget *dt; + + /** + * Malloc'ed data for regular buffers and textures, or a mapping to dt above. + */ + void *data; + + /* True if texture images are power-of-two in all dimensions: + */ + boolean pot; + boolean userBuffer; + + unsigned timestamp; +}; + + +/** + * Subclass of pipe_transfer. + */ +struct softpipe_transfer +{ + struct pipe_transfer base; + + unsigned long offset; +}; + + + +/** cast wrappers */ +static INLINE struct softpipe_resource * +softpipe_resource(struct pipe_resource *pt) +{ + return (struct softpipe_resource *) pt; +} + +static INLINE struct softpipe_transfer * +softpipe_transfer(struct pipe_transfer *pt) +{ + return (struct softpipe_transfer *) pt; +} + + +extern void +softpipe_init_screen_texture_funcs(struct pipe_screen *screen); + +extern void +softpipe_init_texture_funcs(struct pipe_context *pipe); + + +#endif /* SP_TEXTURE */ diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.c b/src/gallium/drivers/softpipe/sp_tile_cache.c new file mode 100644 index 0000000..480860a --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_tile_cache.c @@ -0,0 +1,544 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * Render target tile caching. + * + * Author: + * Brian Paul + */ + +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_tile.h" +#include "sp_tile_cache.h" + +static struct softpipe_cached_tile * +sp_alloc_tile(struct softpipe_tile_cache *tc); + + +/** + * Return the position in the cache for the tile that contains win pos (x,y). + * We currently use a direct mapped cache so this is like a hack key. + * At some point we should investige something more sophisticated, like + * a LRU replacement policy. + */ +#define CACHE_POS(x, y) \ + (((x) + (y) * 5) % NUM_ENTRIES) + + + +/** + * Is the tile at (x,y) in cleared state? + */ +static INLINE uint +is_clear_flag_set(const uint *bitvec, union tile_address addr) +{ + int pos, bit; + pos = addr.bits.y * (MAX_WIDTH / TILE_SIZE) + addr.bits.x; + assert(pos / 32 < (MAX_WIDTH / TILE_SIZE) * (MAX_HEIGHT / TILE_SIZE) / 32); + bit = bitvec[pos / 32] & (1 << (pos & 31)); + return bit; +} + + +/** + * Mark the tile at (x,y) as not cleared. + */ +static INLINE void +clear_clear_flag(uint *bitvec, union tile_address addr) +{ + int pos; + pos = addr.bits.y * (MAX_WIDTH / TILE_SIZE) + addr.bits.x; + assert(pos / 32 < (MAX_WIDTH / TILE_SIZE) * (MAX_HEIGHT / TILE_SIZE) / 32); + bitvec[pos / 32] &= ~(1 << (pos & 31)); +} + + +struct softpipe_tile_cache * +sp_create_tile_cache( struct pipe_context *pipe ) +{ + struct softpipe_tile_cache *tc; + uint pos; + int maxLevels, maxTexSize; + + /* sanity checking: max sure MAX_WIDTH/HEIGHT >= largest texture image */ + maxLevels = pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS); + maxTexSize = 1 << (maxLevels - 1); + assert(MAX_WIDTH >= maxTexSize); + + assert(sizeof(union tile_address) == 4); + + assert((TILE_SIZE << TILE_ADDR_BITS) >= MAX_WIDTH); + + tc = CALLOC_STRUCT( softpipe_tile_cache ); + if (tc) { + tc->pipe = pipe; + for (pos = 0; pos < NUM_ENTRIES; pos++) { + tc->tile_addrs[pos].bits.invalid = 1; + } + tc->last_tile_addr.bits.invalid = 1; + + /* this allocation allows us to guarantee that allocation + * failures are never fatal later + */ + tc->tile = MALLOC_STRUCT( softpipe_cached_tile ); + if (!tc->tile) + { + FREE(tc); + return NULL; + } + + /* XXX this code prevents valgrind warnings about use of uninitialized + * memory in programs that don't clear the surface before rendering. + * However, it breaks clearing in other situations (such as in + * progs/tests/drawbuffers, see bug 24402). + */ +#if 0 + /* set flags to indicate all the tiles are cleared */ + memset(tc->clear_flags, 255, sizeof(tc->clear_flags)); +#endif + } + return tc; +} + + +void +sp_destroy_tile_cache(struct softpipe_tile_cache *tc) +{ + if (tc) { + uint pos; + + for (pos = 0; pos < NUM_ENTRIES; pos++) { + /*assert(tc->entries[pos].x < 0);*/ + FREE( tc->entries[pos] ); + } + FREE( tc->tile ); + + if (tc->transfer) { + tc->pipe->transfer_destroy(tc->pipe, tc->transfer); + } + + FREE( tc ); + } +} + + +/** + * Specify the surface to cache. + */ +void +sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, + struct pipe_surface *ps) +{ + struct pipe_context *pipe = tc->pipe; + + if (tc->transfer) { + if (ps == tc->surface) + return; + + if (tc->transfer_map) { + pipe->transfer_unmap(pipe, tc->transfer); + tc->transfer_map = NULL; + } + + pipe->transfer_destroy(pipe, tc->transfer); + tc->transfer = NULL; + } + + tc->surface = ps; + + if (ps) { + tc->transfer = pipe_get_transfer(pipe, ps->texture, + ps->u.tex.level, ps->u.tex.first_layer, + PIPE_TRANSFER_READ_WRITE | + PIPE_TRANSFER_UNSYNCHRONIZED, + 0, 0, ps->width, ps->height); + + tc->depth_stencil = (ps->format == PIPE_FORMAT_Z24_UNORM_S8_USCALED || + ps->format == PIPE_FORMAT_Z24X8_UNORM || + ps->format == PIPE_FORMAT_S8_USCALED_Z24_UNORM || + ps->format == PIPE_FORMAT_X8Z24_UNORM || + ps->format == PIPE_FORMAT_Z16_UNORM || + ps->format == PIPE_FORMAT_Z32_UNORM || + ps->format == PIPE_FORMAT_S8_USCALED); + } +} + + +/** + * Return the transfer being cached. + */ +struct pipe_surface * +sp_tile_cache_get_surface(struct softpipe_tile_cache *tc) +{ + return tc->surface; +} + + +void +sp_tile_cache_map_transfers(struct softpipe_tile_cache *tc) +{ + if (tc->transfer && !tc->transfer_map) + tc->transfer_map = tc->pipe->transfer_map(tc->pipe, tc->transfer); +} + + +void +sp_tile_cache_unmap_transfers(struct softpipe_tile_cache *tc) +{ + if (tc->transfer_map) { + tc->pipe->transfer_unmap(tc->pipe, tc->transfer); + tc->transfer_map = NULL; + } +} + + +/** + * Set pixels in a tile to the given clear color/value, float. + */ +static void +clear_tile_rgba(struct softpipe_cached_tile *tile, + enum pipe_format format, + const float clear_value[4]) +{ + if (clear_value[0] == 0.0 && + clear_value[1] == 0.0 && + clear_value[2] == 0.0 && + clear_value[3] == 0.0) { + memset(tile->data.color, 0, sizeof(tile->data.color)); + } + else { + uint i, j; + for (i = 0; i < TILE_SIZE; i++) { + for (j = 0; j < TILE_SIZE; j++) { + tile->data.color[i][j][0] = clear_value[0]; + tile->data.color[i][j][1] = clear_value[1]; + tile->data.color[i][j][2] = clear_value[2]; + tile->data.color[i][j][3] = clear_value[3]; + } + } + } +} + + +/** + * Set a tile to a solid value/color. + */ +static void +clear_tile(struct softpipe_cached_tile *tile, + enum pipe_format format, + uint clear_value) +{ + uint i, j; + + switch (util_format_get_blocksize(format)) { + case 1: + memset(tile->data.any, clear_value, TILE_SIZE * TILE_SIZE); + break; + case 2: + if (clear_value == 0) { + memset(tile->data.any, 0, 2 * TILE_SIZE * TILE_SIZE); + } + else { + for (i = 0; i < TILE_SIZE; i++) { + for (j = 0; j < TILE_SIZE; j++) { + tile->data.depth16[i][j] = (ushort) clear_value; + } + } + } + break; + case 4: + if (clear_value == 0) { + memset(tile->data.any, 0, 4 * TILE_SIZE * TILE_SIZE); + } + else { + for (i = 0; i < TILE_SIZE; i++) { + for (j = 0; j < TILE_SIZE; j++) { + tile->data.color32[i][j] = clear_value; + } + } + } + break; + default: + assert(0); + } +} + + +/** + * Actually clear the tiles which were flagged as being in a clear state. + */ +static void +sp_tile_cache_flush_clear(struct softpipe_tile_cache *tc) +{ + struct pipe_transfer *pt = tc->transfer; + const uint w = tc->transfer->box.width; + const uint h = tc->transfer->box.height; + uint x, y; + uint numCleared = 0; + + assert(pt->resource); + if (!tc->tile) + tc->tile = sp_alloc_tile(tc); + + /* clear the scratch tile to the clear value */ + if (tc->depth_stencil) { + clear_tile(tc->tile, pt->resource->format, tc->clear_val); + } else { + clear_tile_rgba(tc->tile, pt->resource->format, tc->clear_color); + } + + /* push the tile to all positions marked as clear */ + for (y = 0; y < h; y += TILE_SIZE) { + for (x = 0; x < w; x += TILE_SIZE) { + union tile_address addr = tile_address(x, y); + + if (is_clear_flag_set(tc->clear_flags, addr)) { + /* write the scratch tile to the surface */ + if (tc->depth_stencil) { + pipe_put_tile_raw(tc->pipe, + pt, + x, y, TILE_SIZE, TILE_SIZE, + tc->tile->data.any, 0/*STRIDE*/); + } + else { + pipe_put_tile_rgba(tc->pipe, pt, + x, y, TILE_SIZE, TILE_SIZE, + (float *) tc->tile->data.color); + } + numCleared++; + } + } + } + + /* reset all clear flags to zero */ + memset(tc->clear_flags, 0, sizeof(tc->clear_flags)); + +#if 0 + debug_printf("num cleared: %u\n", numCleared); +#endif +} + +static void +sp_flush_tile(struct softpipe_tile_cache* tc, unsigned pos) +{ + if (!tc->tile_addrs[pos].bits.invalid) { + if (tc->depth_stencil) { + pipe_put_tile_raw(tc->pipe, tc->transfer, + tc->tile_addrs[pos].bits.x * TILE_SIZE, + tc->tile_addrs[pos].bits.y * TILE_SIZE, + TILE_SIZE, TILE_SIZE, + tc->entries[pos]->data.depth32, 0/*STRIDE*/); + } + else { + pipe_put_tile_rgba(tc->pipe, tc->transfer, + tc->tile_addrs[pos].bits.x * TILE_SIZE, + tc->tile_addrs[pos].bits.y * TILE_SIZE, + TILE_SIZE, TILE_SIZE, + (float *) tc->entries[pos]->data.color); + } + tc->tile_addrs[pos].bits.invalid = 1; /* mark as empty */ + } +} + +/** + * Flush the tile cache: write all dirty tiles back to the transfer. + * any tiles "flagged" as cleared will be "really" cleared. + */ +void +sp_flush_tile_cache(struct softpipe_tile_cache *tc) +{ + struct pipe_transfer *pt = tc->transfer; + int inuse = 0, pos; + + if (pt) { + /* caching a drawing transfer */ + for (pos = 0; pos < NUM_ENTRIES; pos++) { + struct softpipe_cached_tile *tile = tc->entries[pos]; + if (!tile) + { + assert(tc->tile_addrs[pos].bits.invalid); + continue; + } + + sp_flush_tile(tc, pos); + ++inuse; + } + + sp_tile_cache_flush_clear(tc); + + + tc->last_tile_addr.bits.invalid = 1; + } + +#if 0 + debug_printf("flushed tiles in use: %d\n", inuse); +#endif +} + +static struct softpipe_cached_tile * +sp_alloc_tile(struct softpipe_tile_cache *tc) +{ + struct softpipe_cached_tile * tile = MALLOC_STRUCT(softpipe_cached_tile); + if (!tile) + { + /* in this case, steal an existing tile */ + if (!tc->tile) + { + unsigned pos; + for (pos = 0; pos < NUM_ENTRIES; ++pos) { + if (!tc->entries[pos]) + continue; + + sp_flush_tile(tc, pos); + tc->tile = tc->entries[pos]; + tc->entries[pos] = NULL; + break; + } + + /* this should never happen */ + if (!tc->tile) + abort(); + } + + tile = tc->tile; + tc->tile = NULL; + + tc->last_tile_addr.bits.invalid = 1; + } + return tile; +} + +/** + * Get a tile from the cache. + * \param x, y position of tile, in pixels + */ +struct softpipe_cached_tile * +sp_find_cached_tile(struct softpipe_tile_cache *tc, + union tile_address addr ) +{ + struct pipe_transfer *pt = tc->transfer; + + /* cache pos/entry: */ + const int pos = CACHE_POS(addr.bits.x, + addr.bits.y); + struct softpipe_cached_tile *tile = tc->entries[pos]; + + if (!tile) { + tile = sp_alloc_tile(tc); + tc->entries[pos] = tile; + } + + if (addr.value != tc->tile_addrs[pos].value) { + + assert(pt->resource); + if (tc->tile_addrs[pos].bits.invalid == 0) { + /* put dirty tile back in framebuffer */ + if (tc->depth_stencil) { + pipe_put_tile_raw(tc->pipe, pt, + tc->tile_addrs[pos].bits.x * TILE_SIZE, + tc->tile_addrs[pos].bits.y * TILE_SIZE, + TILE_SIZE, TILE_SIZE, + tile->data.depth32, 0/*STRIDE*/); + } + else { + pipe_put_tile_rgba(tc->pipe, pt, + tc->tile_addrs[pos].bits.x * TILE_SIZE, + tc->tile_addrs[pos].bits.y * TILE_SIZE, + TILE_SIZE, TILE_SIZE, + (float *) tile->data.color); + } + } + + tc->tile_addrs[pos] = addr; + + if (is_clear_flag_set(tc->clear_flags, addr)) { + /* don't get tile from framebuffer, just clear it */ + if (tc->depth_stencil) { + clear_tile(tile, pt->resource->format, tc->clear_val); + } + else { + clear_tile_rgba(tile, pt->resource->format, tc->clear_color); + } + clear_clear_flag(tc->clear_flags, addr); + } + else { + /* get new tile data from transfer */ + if (tc->depth_stencil) { + pipe_get_tile_raw(tc->pipe, pt, + tc->tile_addrs[pos].bits.x * TILE_SIZE, + tc->tile_addrs[pos].bits.y * TILE_SIZE, + TILE_SIZE, TILE_SIZE, + tile->data.depth32, 0/*STRIDE*/); + } + else { + pipe_get_tile_rgba(tc->pipe, pt, + tc->tile_addrs[pos].bits.x * TILE_SIZE, + tc->tile_addrs[pos].bits.y * TILE_SIZE, + TILE_SIZE, TILE_SIZE, + (float *) tile->data.color); + } + } + } + + tc->last_tile = tile; + tc->last_tile_addr = addr; + return tile; +} + + + + + +/** + * When a whole surface is being cleared to a value we can avoid + * fetching tiles above. + * Save the color and set a 'clearflag' for each tile of the screen. + */ +void +sp_tile_cache_clear(struct softpipe_tile_cache *tc, const float *rgba, + uint clearValue) +{ + uint pos; + + tc->clear_color[0] = rgba[0]; + tc->clear_color[1] = rgba[1]; + tc->clear_color[2] = rgba[2]; + tc->clear_color[3] = rgba[3]; + + tc->clear_val = clearValue; + + /* set flags to indicate all the tiles are cleared */ + memset(tc->clear_flags, 255, sizeof(tc->clear_flags)); + + for (pos = 0; pos < NUM_ENTRIES; pos++) { + tc->tile_addrs[pos].bits.invalid = 1; + } + tc->last_tile_addr.bits.invalid = 1; +} diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.h b/src/gallium/drivers/softpipe/sp_tile_cache.h new file mode 100644 index 0000000..68140b1 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_tile_cache.h @@ -0,0 +1,161 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef SP_TILE_CACHE_H +#define SP_TILE_CACHE_H + + +#include "pipe/p_compiler.h" +#include "sp_texture.h" + + +struct softpipe_tile_cache; + + +/** + * Cache tile size (width and height). This needs to be a power of two. + */ +#define TILE_SIZE_LOG2 6 +#define TILE_SIZE (1 << TILE_SIZE_LOG2) + + +#define TILE_ADDR_BITS (SP_MAX_TEXTURE_2D_LEVELS - 1 - TILE_SIZE_LOG2) + + +/** + * Surface tile address as a union for fast compares. + */ +union tile_address { + struct { + unsigned x:TILE_ADDR_BITS; /* 16K / TILE_SIZE */ + unsigned y:TILE_ADDR_BITS; /* 16K / TILE_SIZE */ + unsigned invalid:1; + unsigned pad:15; + } bits; + unsigned value; +}; + + +struct softpipe_cached_tile +{ + union { + float color[TILE_SIZE][TILE_SIZE][4]; + uint color32[TILE_SIZE][TILE_SIZE]; + uint depth32[TILE_SIZE][TILE_SIZE]; + ushort depth16[TILE_SIZE][TILE_SIZE]; + ubyte stencil8[TILE_SIZE][TILE_SIZE]; + ubyte any[1]; + } data; +}; + +#define NUM_ENTRIES 50 + + +struct softpipe_tile_cache +{ + struct pipe_context *pipe; + struct pipe_surface *surface; /**< the surface we're caching */ + struct pipe_transfer *transfer; + void *transfer_map; + + union tile_address tile_addrs[NUM_ENTRIES]; + struct softpipe_cached_tile *entries[NUM_ENTRIES]; + uint clear_flags[(MAX_WIDTH / TILE_SIZE) * (MAX_HEIGHT / TILE_SIZE) / 32]; + float clear_color[4]; /**< for color bufs */ + uint clear_val; /**< for z+stencil */ + boolean depth_stencil; /**< Is the surface a depth/stencil format? */ + + struct softpipe_cached_tile *tile; /**< scratch tile for clears */ + + union tile_address last_tile_addr; + struct softpipe_cached_tile *last_tile; /**< most recently retrieved tile */ +}; + + +extern struct softpipe_tile_cache * +sp_create_tile_cache( struct pipe_context *pipe ); + +extern void +sp_destroy_tile_cache(struct softpipe_tile_cache *tc); + +extern void +sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, + struct pipe_surface *sps); + +extern struct pipe_surface * +sp_tile_cache_get_surface(struct softpipe_tile_cache *tc); + +extern void +sp_tile_cache_map_transfers(struct softpipe_tile_cache *tc); + +extern void +sp_tile_cache_unmap_transfers(struct softpipe_tile_cache *tc); + +extern void +sp_flush_tile_cache(struct softpipe_tile_cache *tc); + +extern void +sp_tile_cache_clear(struct softpipe_tile_cache *tc, const float *rgba, + uint clearValue); + +extern struct softpipe_cached_tile * +sp_find_cached_tile(struct softpipe_tile_cache *tc, + union tile_address addr ); + + +static INLINE union tile_address +tile_address( unsigned x, + unsigned y ) +{ + union tile_address addr; + + addr.value = 0; + addr.bits.x = x / TILE_SIZE; + addr.bits.y = y / TILE_SIZE; + + return addr; +} + +/* Quickly retrieve tile if it matches last lookup. + */ +static INLINE struct softpipe_cached_tile * +sp_get_cached_tile(struct softpipe_tile_cache *tc, + int x, int y ) +{ + union tile_address addr = tile_address( x, y ); + + if (tc->last_tile_addr.value == addr.value) + return tc->last_tile; + + return sp_find_cached_tile( tc, addr ); +} + + + + +#endif /* SP_TILE_CACHE_H */ + diff --git a/src/gallium/drivers/svga/Makefile b/src/gallium/drivers/svga/Makefile new file mode 100644 index 0000000..2728779 --- /dev/null +++ b/src/gallium/drivers/svga/Makefile @@ -0,0 +1,65 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = svga + +C_SOURCES = \ + svgadump/svga_shader_dump.c \ + svgadump/svga_shader_op.c \ + svgadump/svga_dump.c \ + svga_cmd.c \ + svga_context.c \ + svga_draw.c \ + svga_draw_arrays.c \ + svga_draw_elements.c \ + svga_pipe_blend.c \ + svga_pipe_blit.c \ + svga_pipe_clear.c \ + svga_pipe_constants.c \ + svga_pipe_depthstencil.c \ + svga_pipe_draw.c \ + svga_pipe_flush.c \ + svga_pipe_fs.c \ + svga_pipe_misc.c \ + svga_pipe_query.c \ + svga_pipe_rasterizer.c \ + svga_pipe_sampler.c \ + svga_pipe_vertex.c \ + svga_pipe_vs.c \ + svga_screen.c \ + svga_screen_cache.c \ + svga_state.c \ + svga_state_need_swtnl.c \ + svga_state_constants.c \ + svga_state_framebuffer.c \ + svga_state_rss.c \ + svga_state_tss.c \ + svga_state_vdecl.c \ + svga_state_fs.c \ + svga_state_vs.c \ + svga_swtnl_backend.c \ + svga_swtnl_draw.c \ + svga_swtnl_state.c \ + svga_tgsi.c \ + svga_tgsi_decl_sm20.c \ + svga_tgsi_decl_sm30.c \ + svga_tgsi_insn.c \ + svga_sampler_view.c \ + svga_surface.c \ + svga_resource.c \ + svga_resource_texture.c \ + svga_resource_buffer.c \ + svga_resource_buffer_upload.c + + +LIBRARY_INCLUDES = \ + -I$(TOP)/src/gallium/drivers/svga/include + +# With linux-debug we get a lots of warnings, filter out the bad flags. +CFLAGS := $(filter-out -pedantic, $(filter-out -ansi, $(CFLAGS))) + +LIBRARY_DEFINES = \ + -std=gnu99 -fvisibility=hidden \ + -DHAVE_STDINT_H -DHAVE_SYS_TYPES_H + +include ../../Makefile.template diff --git a/src/gallium/drivers/svga/SConscript b/src/gallium/drivers/svga/SConscript new file mode 100644 index 0000000..5455ed0 --- /dev/null +++ b/src/gallium/drivers/svga/SConscript @@ -0,0 +1,78 @@ +Import('*') + +env = env.Clone() + +if env['platform'] in ['linux']: + env.Append(CCFLAGS = ['-fvisibility=hidden']) + +if env['gcc']: + env.Append(CPPDEFINES = [ + 'HAVE_STDINT_H', + 'HAVE_SYS_TYPES_H', + ]) + +env.Prepend(CPPPATH = [ + 'include', +]) + +env.Append(CPPDEFINES = [ +]) + +sources = [ + 'svga_cmd.c', + 'svga_context.c', + 'svga_draw.c', + 'svga_draw_arrays.c', + 'svga_draw_elements.c', + 'svga_pipe_blend.c', + 'svga_pipe_blit.c', + 'svga_pipe_clear.c', + 'svga_pipe_constants.c', + 'svga_pipe_depthstencil.c', + 'svga_pipe_draw.c', + 'svga_pipe_flush.c', + 'svga_pipe_fs.c', + 'svga_pipe_misc.c', + 'svga_pipe_query.c', + 'svga_pipe_rasterizer.c', + 'svga_pipe_sampler.c', + 'svga_pipe_vertex.c', + 'svga_pipe_vs.c', + 'svga_resource.c', + 'svga_resource_buffer.c', + 'svga_resource_buffer_upload.c', + 'svga_resource_texture.c', + 'svga_sampler_view.c', + 'svga_screen.c', + 'svga_screen_cache.c', + 'svga_state.c', + 'svga_state_constants.c', + 'svga_state_framebuffer.c', + 'svga_state_need_swtnl.c', + 'svga_state_rss.c', + 'svga_state_tss.c', + 'svga_state_vdecl.c', + 'svga_state_fs.c', + 'svga_state_vs.c', + 'svga_surface.c', + 'svga_swtnl_backend.c', + 'svga_swtnl_draw.c', + 'svga_swtnl_state.c', + 'svga_tgsi.c', + 'svga_tgsi_decl_sm20.c', + 'svga_tgsi_decl_sm30.c', + 'svga_tgsi_insn.c', + + 'svgadump/svga_dump.c', + 'svgadump/svga_shader_dump.c', + 'svgadump/svga_shader_op.c', +] + +svga = env.ConvenienceLibrary( + target = 'svga', + source = sources, +) + +env.Alias('svga', svga) + +Export('svga') diff --git a/src/gallium/drivers/svga/include/svga3d_caps.h b/src/gallium/drivers/svga/include/svga3d_caps.h new file mode 100644 index 0000000..714ce9f --- /dev/null +++ b/src/gallium/drivers/svga/include/svga3d_caps.h @@ -0,0 +1,139 @@ +/********************************************************** + * Copyright 2007-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. + * + **********************************************************/ + +/* + * svga3d_caps.h -- + * + * Definitions for SVGA3D hardware capabilities. Capabilities + * are used to query for optional rendering features during + * driver initialization. The capability data is stored as very + * basic key/value dictionary within the "FIFO register" memory + * area at the beginning of BAR2. + * + * Note that these definitions are only for 3D capabilities. + * The SVGA device also has "device capabilities" and "FIFO + * capabilities", which are non-3D-specific and are stored as + * bitfields rather than key/value pairs. + */ + +#ifndef _SVGA3D_CAPS_H_ +#define _SVGA3D_CAPS_H_ + +#define SVGA_FIFO_3D_CAPS_SIZE (SVGA_FIFO_3D_CAPS_LAST - \ + SVGA_FIFO_3D_CAPS + 1) + + +/* + * SVGA3dCapsRecordType + * + * Record types that can be found in the caps block. + * Related record types are grouped together numerically so that + * SVGA3dCaps_FindRecord() can be applied on a range of record + * types. + */ + +typedef enum { + SVGA3DCAPS_RECORD_UNKNOWN = 0, + SVGA3DCAPS_RECORD_DEVCAPS_MIN = 0x100, + SVGA3DCAPS_RECORD_DEVCAPS = 0x100, + SVGA3DCAPS_RECORD_DEVCAPS_MAX = 0x1ff, +} SVGA3dCapsRecordType; + + +/* + * SVGA3dCapsRecordHeader + * + * Header field leading each caps block record. Contains the offset (in + * register words, NOT bytes) to the next caps block record (or the end + * of caps block records which will be a zero word) and the record type + * as defined above. + */ + +typedef +struct SVGA3dCapsRecordHeader { + uint32 length; + SVGA3dCapsRecordType type; +} +SVGA3dCapsRecordHeader; + + +/* + * SVGA3dCapsRecord + * + * Caps block record; "data" is a placeholder for the actual data structure + * contained within the record; for example a record containing a FOOBAR + * structure would be of size "sizeof(SVGA3dCapsRecordHeader) + + * sizeof(FOOBAR)". + */ + +typedef +struct SVGA3dCapsRecord { + SVGA3dCapsRecordHeader header; + uint32 data[1]; +} +SVGA3dCapsRecord; + + +typedef uint32 SVGA3dCapPair[2]; + + +/* + *---------------------------------------------------------------------- + * + * SVGA3dCaps_FindRecord + * + * Finds the record with the highest-valued type within the given range + * in the caps block. + * + * Result: pointer to found record, or NULL if not found. + * + *---------------------------------------------------------------------- + */ + +static INLINE SVGA3dCapsRecord * +SVGA3dCaps_FindRecord(const uint32 *capsBlock, + SVGA3dCapsRecordType recordTypeMin, + SVGA3dCapsRecordType recordTypeMax) +{ + SVGA3dCapsRecord *record, *found = NULL; + uint32 offset; + + /* + * Search linearly through the caps block records for the specified type. + */ + for (offset = 0; capsBlock[offset] != 0; offset += capsBlock[offset]) { + record = (SVGA3dCapsRecord *) (capsBlock + offset); + if ((record->header.type >= recordTypeMin) && + (record->header.type <= recordTypeMax) && + (!found || (record->header.type > found->header.type))) { + found = record; + } + } + + return found; +} + + +#endif // _SVGA3D_CAPS_H_ diff --git a/src/gallium/drivers/svga/include/svga3d_reg.h b/src/gallium/drivers/svga/include/svga3d_reg.h new file mode 100644 index 0000000..77cb453 --- /dev/null +++ b/src/gallium/drivers/svga/include/svga3d_reg.h @@ -0,0 +1,1793 @@ +/********************************************************** + * Copyright 1998-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. + * + **********************************************************/ + +/* + * svga3d_reg.h -- + * + * SVGA 3D hardware definitions + */ + +#ifndef _SVGA3D_REG_H_ +#define _SVGA3D_REG_H_ + +#include "svga_reg.h" + + +/* + * 3D Hardware Version + * + * The hardware version is stored in the SVGA_FIFO_3D_HWVERSION fifo + * register. Is set by the host and read by the guest. This lets + * us make new guest drivers which are backwards-compatible with old + * SVGA hardware revisions. It does not let us support old guest + * drivers. Good enough for now. + * + */ + +#define SVGA3D_MAKE_HWVERSION(major, minor) (((major) << 16) | ((minor) & 0xFF)) +#define SVGA3D_MAJOR_HWVERSION(version) ((version) >> 16) +#define SVGA3D_MINOR_HWVERSION(version) ((version) & 0xFF) + +typedef enum { + SVGA3D_HWVERSION_WS5_RC1 = SVGA3D_MAKE_HWVERSION(0, 1), + SVGA3D_HWVERSION_WS5_RC2 = SVGA3D_MAKE_HWVERSION(0, 2), + SVGA3D_HWVERSION_WS51_RC1 = SVGA3D_MAKE_HWVERSION(0, 3), + SVGA3D_HWVERSION_WS6_B1 = SVGA3D_MAKE_HWVERSION(1, 1), + SVGA3D_HWVERSION_FUSION_11 = SVGA3D_MAKE_HWVERSION(1, 4), + SVGA3D_HWVERSION_WS65_B1 = SVGA3D_MAKE_HWVERSION(2, 0), + SVGA3D_HWVERSION_CURRENT = SVGA3D_HWVERSION_WS65_B1, +} SVGA3dHardwareVersion; + +/* + * Generic Types + */ + +typedef uint32 SVGA3dBool; /* 32-bit Bool definition */ +#define SVGA3D_NUM_CLIPPLANES 6 +#define SVGA3D_MAX_SIMULTANEOUS_RENDER_TARGETS 8 + + +/* + * Surface formats. + * + * If you modify this list, be sure to keep GLUtil.c in sync. It + * includes the internal format definition of each surface in + * GLUtil_ConvertSurfaceFormat, and it contains a table of + * human-readable names in GLUtil_GetFormatName. + */ + +typedef enum SVGA3dSurfaceFormat { + SVGA3D_FORMAT_INVALID = 0, + + SVGA3D_X8R8G8B8 = 1, + SVGA3D_A8R8G8B8 = 2, + + SVGA3D_R5G6B5 = 3, + SVGA3D_X1R5G5B5 = 4, + SVGA3D_A1R5G5B5 = 5, + SVGA3D_A4R4G4B4 = 6, + + SVGA3D_Z_D32 = 7, + SVGA3D_Z_D16 = 8, + SVGA3D_Z_D24S8 = 9, + SVGA3D_Z_D15S1 = 10, + + SVGA3D_LUMINANCE8 = 11, + SVGA3D_LUMINANCE4_ALPHA4 = 12, + SVGA3D_LUMINANCE16 = 13, + SVGA3D_LUMINANCE8_ALPHA8 = 14, + + SVGA3D_DXT1 = 15, + SVGA3D_DXT2 = 16, + SVGA3D_DXT3 = 17, + SVGA3D_DXT4 = 18, + SVGA3D_DXT5 = 19, + + SVGA3D_BUMPU8V8 = 20, + SVGA3D_BUMPL6V5U5 = 21, + SVGA3D_BUMPX8L8V8U8 = 22, + SVGA3D_BUMPL8V8U8 = 23, + + SVGA3D_ARGB_S10E5 = 24, /* 16-bit floating-point ARGB */ + SVGA3D_ARGB_S23E8 = 25, /* 32-bit floating-point ARGB */ + + SVGA3D_A2R10G10B10 = 26, + + /* signed formats */ + SVGA3D_V8U8 = 27, + SVGA3D_Q8W8V8U8 = 28, + SVGA3D_CxV8U8 = 29, + + /* mixed formats */ + SVGA3D_X8L8V8U8 = 30, + SVGA3D_A2W10V10U10 = 31, + + SVGA3D_ALPHA8 = 32, + + /* Single- and dual-component floating point formats */ + SVGA3D_R_S10E5 = 33, + SVGA3D_R_S23E8 = 34, + SVGA3D_RG_S10E5 = 35, + SVGA3D_RG_S23E8 = 36, + + /* + * Any surface can be used as a buffer object, but SVGA3D_BUFFER is + * the most efficient format to use when creating new surfaces + * expressly for index or vertex data. + */ + SVGA3D_BUFFER = 37, + + SVGA3D_Z_D24X8 = 38, + + SVGA3D_V16U16 = 39, + + SVGA3D_G16R16 = 40, + SVGA3D_A16B16G16R16 = 41, + + /* Packed Video formats */ + SVGA3D_UYVY = 42, + SVGA3D_YUY2 = 43, + + SVGA3D_FORMAT_MAX +} SVGA3dSurfaceFormat; + +typedef uint32 SVGA3dColor; /* a, r, g, b */ + +/* + * These match the D3DFORMAT_OP definitions used by Direct3D. We need + * them so that we can query the host for what the supported surface + * operations are (when we're using the D3D backend, in particular), + * and so we can send those operations to the guest. + */ +typedef enum { + SVGA3DFORMAT_OP_TEXTURE = 0x00000001, + SVGA3DFORMAT_OP_VOLUMETEXTURE = 0x00000002, + SVGA3DFORMAT_OP_CUBETEXTURE = 0x00000004, + SVGA3DFORMAT_OP_OFFSCREEN_RENDERTARGET = 0x00000008, + SVGA3DFORMAT_OP_SAME_FORMAT_RENDERTARGET = 0x00000010, + SVGA3DFORMAT_OP_ZSTENCIL = 0x00000040, + SVGA3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH = 0x00000080, + +/* + * This format can be used as a render target if the current display mode + * is the same depth if the alpha channel is ignored. e.g. if the device + * can render to A8R8G8B8 when the display mode is X8R8G8B8, then the + * format op list entry for A8R8G8B8 should have this cap. + */ + SVGA3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET = 0x00000100, + +/* + * This format contains DirectDraw support (including Flip). This flag + * should not to be set on alpha formats. + */ + SVGA3DFORMAT_OP_DISPLAYMODE = 0x00000400, + +/* + * The rasterizer can support some level of Direct3D support in this format + * and implies that the driver can create a Context in this mode (for some + * render target format). When this flag is set, the SVGA3DFORMAT_OP_DISPLAYMODE + * flag must also be set. + */ + SVGA3DFORMAT_OP_3DACCELERATION = 0x00000800, + +/* + * This is set for a private format when the driver has put the bpp in + * the structure. + */ + SVGA3DFORMAT_OP_PIXELSIZE = 0x00001000, + +/* + * Indicates that this format can be converted to any RGB format for which + * SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB is specified + */ + SVGA3DFORMAT_OP_CONVERT_TO_ARGB = 0x00002000, + +/* + * Indicates that this format can be used to create offscreen plain surfaces. + */ + SVGA3DFORMAT_OP_OFFSCREENPLAIN = 0x00004000, + +/* + * Indicated that this format can be read as an SRGB texture (meaning that the + * sampler will linearize the looked up data) + */ + SVGA3DFORMAT_OP_SRGBREAD = 0x00008000, + +/* + * Indicates that this format can be used in the bumpmap instructions + */ + SVGA3DFORMAT_OP_BUMPMAP = 0x00010000, + +/* + * Indicates that this format can be sampled by the displacement map sampler + */ + SVGA3DFORMAT_OP_DMAP = 0x00020000, + +/* + * Indicates that this format cannot be used with texture filtering + */ + SVGA3DFORMAT_OP_NOFILTER = 0x00040000, + +/* + * Indicates that format conversions are supported to this RGB format if + * SVGA3DFORMAT_OP_CONVERT_TO_ARGB is specified in the source format. + */ + SVGA3DFORMAT_OP_MEMBEROFGROUP_ARGB = 0x00080000, + +/* + * Indicated that this format can be written as an SRGB target (meaning that the + * pixel pipe will DE-linearize data on output to format) + */ + SVGA3DFORMAT_OP_SRGBWRITE = 0x00100000, + +/* + * Indicates that this format cannot be used with alpha blending + */ + SVGA3DFORMAT_OP_NOALPHABLEND = 0x00200000, + +/* + * Indicates that the device can auto-generated sublevels for resources + * of this format + */ + SVGA3DFORMAT_OP_AUTOGENMIPMAP = 0x00400000, + +/* + * Indicates that this format can be used by vertex texture sampler + */ + SVGA3DFORMAT_OP_VERTEXTEXTURE = 0x00800000, + +/* + * Indicates that this format supports neither texture coordinate wrap + * modes, nor mipmapping + */ + SVGA3DFORMAT_OP_NOTEXCOORDWRAPNORMIP = 0x01000000 +} SVGA3dFormatOp; + +/* + * This structure is a conversion of SVGA3DFORMAT_OP_*. + * Entries must be located at the same position. + */ +typedef union { + uint32 value; + struct { + uint32 texture : 1; + uint32 volumeTexture : 1; + uint32 cubeTexture : 1; + uint32 offscreenRenderTarget : 1; + uint32 sameFormatRenderTarget : 1; + uint32 unknown1 : 1; + uint32 zStencil : 1; + uint32 zStencilArbitraryDepth : 1; + uint32 sameFormatUpToAlpha : 1; + uint32 unknown2 : 1; + uint32 displayMode : 1; + uint32 acceleration3d : 1; + uint32 pixelSize : 1; + uint32 convertToARGB : 1; + uint32 offscreenPlain : 1; + uint32 sRGBRead : 1; + uint32 bumpMap : 1; + uint32 dmap : 1; + uint32 noFilter : 1; + uint32 memberOfGroupARGB : 1; + uint32 sRGBWrite : 1; + uint32 noAlphaBlend : 1; + uint32 autoGenMipMap : 1; + uint32 vertexTexture : 1; + uint32 noTexCoordWrapNorMip : 1; + }; +} SVGA3dSurfaceFormatCaps; + +/* + * SVGA_3D_CMD_SETRENDERSTATE Types. All value types + * must fit in a uint32. + */ + +typedef enum { + SVGA3D_RS_INVALID = 0, + SVGA3D_RS_ZENABLE = 1, /* SVGA3dBool */ + SVGA3D_RS_ZWRITEENABLE = 2, /* SVGA3dBool */ + SVGA3D_RS_ALPHATESTENABLE = 3, /* SVGA3dBool */ + SVGA3D_RS_DITHERENABLE = 4, /* SVGA3dBool */ + SVGA3D_RS_BLENDENABLE = 5, /* SVGA3dBool */ + SVGA3D_RS_FOGENABLE = 6, /* SVGA3dBool */ + SVGA3D_RS_SPECULARENABLE = 7, /* SVGA3dBool */ + SVGA3D_RS_STENCILENABLE = 8, /* SVGA3dBool */ + SVGA3D_RS_LIGHTINGENABLE = 9, /* SVGA3dBool */ + SVGA3D_RS_NORMALIZENORMALS = 10, /* SVGA3dBool */ + SVGA3D_RS_POINTSPRITEENABLE = 11, /* SVGA3dBool */ + SVGA3D_RS_POINTSCALEENABLE = 12, /* SVGA3dBool */ + SVGA3D_RS_STENCILREF = 13, /* uint32 */ + SVGA3D_RS_STENCILMASK = 14, /* uint32 */ + SVGA3D_RS_STENCILWRITEMASK = 15, /* uint32 */ + SVGA3D_RS_FOGSTART = 16, /* float */ + SVGA3D_RS_FOGEND = 17, /* float */ + SVGA3D_RS_FOGDENSITY = 18, /* float */ + SVGA3D_RS_POINTSIZE = 19, /* float */ + SVGA3D_RS_POINTSIZEMIN = 20, /* float */ + SVGA3D_RS_POINTSIZEMAX = 21, /* float */ + SVGA3D_RS_POINTSCALE_A = 22, /* float */ + SVGA3D_RS_POINTSCALE_B = 23, /* float */ + SVGA3D_RS_POINTSCALE_C = 24, /* float */ + SVGA3D_RS_FOGCOLOR = 25, /* SVGA3dColor */ + SVGA3D_RS_AMBIENT = 26, /* SVGA3dColor */ + SVGA3D_RS_CLIPPLANEENABLE = 27, /* SVGA3dClipPlanes */ + SVGA3D_RS_FOGMODE = 28, /* SVGA3dFogMode */ + SVGA3D_RS_FILLMODE = 29, /* SVGA3dFillMode */ + SVGA3D_RS_SHADEMODE = 30, /* SVGA3dShadeMode */ + SVGA3D_RS_LINEPATTERN = 31, /* SVGA3dLinePattern */ + SVGA3D_RS_SRCBLEND = 32, /* SVGA3dBlendOp */ + SVGA3D_RS_DSTBLEND = 33, /* SVGA3dBlendOp */ + SVGA3D_RS_BLENDEQUATION = 34, /* SVGA3dBlendEquation */ + SVGA3D_RS_CULLMODE = 35, /* SVGA3dFace */ + SVGA3D_RS_ZFUNC = 36, /* SVGA3dCmpFunc */ + SVGA3D_RS_ALPHAFUNC = 37, /* SVGA3dCmpFunc */ + SVGA3D_RS_STENCILFUNC = 38, /* SVGA3dCmpFunc */ + SVGA3D_RS_STENCILFAIL = 39, /* SVGA3dStencilOp */ + SVGA3D_RS_STENCILZFAIL = 40, /* SVGA3dStencilOp */ + SVGA3D_RS_STENCILPASS = 41, /* SVGA3dStencilOp */ + SVGA3D_RS_ALPHAREF = 42, /* float (0.0 .. 1.0) */ + SVGA3D_RS_FRONTWINDING = 43, /* SVGA3dFrontWinding */ + SVGA3D_RS_COORDINATETYPE = 44, /* SVGA3dCoordinateType */ + SVGA3D_RS_ZBIAS = 45, /* float */ + SVGA3D_RS_RANGEFOGENABLE = 46, /* SVGA3dBool */ + SVGA3D_RS_COLORWRITEENABLE = 47, /* SVGA3dColorMask */ + SVGA3D_RS_VERTEXMATERIALENABLE = 48, /* SVGA3dBool */ + SVGA3D_RS_DIFFUSEMATERIALSOURCE = 49, /* SVGA3dVertexMaterial */ + SVGA3D_RS_SPECULARMATERIALSOURCE = 50, /* SVGA3dVertexMaterial */ + SVGA3D_RS_AMBIENTMATERIALSOURCE = 51, /* SVGA3dVertexMaterial */ + SVGA3D_RS_EMISSIVEMATERIALSOURCE = 52, /* SVGA3dVertexMaterial */ + SVGA3D_RS_TEXTUREFACTOR = 53, /* SVGA3dColor */ + SVGA3D_RS_LOCALVIEWER = 54, /* SVGA3dBool */ + SVGA3D_RS_SCISSORTESTENABLE = 55, /* SVGA3dBool */ + SVGA3D_RS_BLENDCOLOR = 56, /* SVGA3dColor */ + SVGA3D_RS_STENCILENABLE2SIDED = 57, /* SVGA3dBool */ + SVGA3D_RS_CCWSTENCILFUNC = 58, /* SVGA3dCmpFunc */ + SVGA3D_RS_CCWSTENCILFAIL = 59, /* SVGA3dStencilOp */ + SVGA3D_RS_CCWSTENCILZFAIL = 60, /* SVGA3dStencilOp */ + SVGA3D_RS_CCWSTENCILPASS = 61, /* SVGA3dStencilOp */ + SVGA3D_RS_VERTEXBLEND = 62, /* SVGA3dVertexBlendFlags */ + SVGA3D_RS_SLOPESCALEDEPTHBIAS = 63, /* float */ + SVGA3D_RS_DEPTHBIAS = 64, /* float */ + + + /* + * Output Gamma Level + * + * Output gamma effects the gamma curve of colors that are output from the + * rendering pipeline. A value of 1.0 specifies a linear color space. If the + * value is <= 0.0, gamma correction is ignored and linear color space is + * used. + */ + + SVGA3D_RS_OUTPUTGAMMA = 65, /* float */ + SVGA3D_RS_ZVISIBLE = 66, /* SVGA3dBool */ + SVGA3D_RS_LASTPIXEL = 67, /* SVGA3dBool */ + SVGA3D_RS_CLIPPING = 68, /* SVGA3dBool */ + SVGA3D_RS_WRAP0 = 69, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP1 = 70, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP2 = 71, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP3 = 72, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP4 = 73, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP5 = 74, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP6 = 75, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP7 = 76, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP8 = 77, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP9 = 78, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP10 = 79, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP11 = 80, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP12 = 81, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP13 = 82, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP14 = 83, /* SVGA3dWrapFlags */ + SVGA3D_RS_WRAP15 = 84, /* SVGA3dWrapFlags */ + SVGA3D_RS_MULTISAMPLEANTIALIAS = 85, /* SVGA3dBool */ + SVGA3D_RS_MULTISAMPLEMASK = 86, /* uint32 */ + SVGA3D_RS_INDEXEDVERTEXBLENDENABLE = 87, /* SVGA3dBool */ + SVGA3D_RS_TWEENFACTOR = 88, /* float */ + SVGA3D_RS_ANTIALIASEDLINEENABLE = 89, /* SVGA3dBool */ + SVGA3D_RS_COLORWRITEENABLE1 = 90, /* SVGA3dColorMask */ + SVGA3D_RS_COLORWRITEENABLE2 = 91, /* SVGA3dColorMask */ + SVGA3D_RS_COLORWRITEENABLE3 = 92, /* SVGA3dColorMask */ + SVGA3D_RS_SEPARATEALPHABLENDENABLE = 93, /* SVGA3dBool */ + SVGA3D_RS_SRCBLENDALPHA = 94, /* SVGA3dBlendOp */ + SVGA3D_RS_DSTBLENDALPHA = 95, /* SVGA3dBlendOp */ + SVGA3D_RS_BLENDEQUATIONALPHA = 96, /* SVGA3dBlendEquation */ + SVGA3D_RS_MAX +} SVGA3dRenderStateName; + +typedef enum { + SVGA3D_VERTEXMATERIAL_NONE = 0, /* Use the value in the current material */ + SVGA3D_VERTEXMATERIAL_DIFFUSE = 1, /* Use the value in the diffuse component */ + SVGA3D_VERTEXMATERIAL_SPECULAR = 2, /* Use the value in the specular component */ +} SVGA3dVertexMaterial; + +typedef enum { + SVGA3D_FILLMODE_INVALID = 0, + SVGA3D_FILLMODE_POINT = 1, + SVGA3D_FILLMODE_LINE = 2, + SVGA3D_FILLMODE_FILL = 3, + SVGA3D_FILLMODE_MAX +} SVGA3dFillModeType; + + +typedef +union { + struct { + uint16 mode; /* SVGA3dFillModeType */ + uint16 face; /* SVGA3dFace */ + }; + uint32 uintValue; +} SVGA3dFillMode; + +typedef enum { + SVGA3D_SHADEMODE_INVALID = 0, + SVGA3D_SHADEMODE_FLAT = 1, + SVGA3D_SHADEMODE_SMOOTH = 2, + SVGA3D_SHADEMODE_PHONG = 3, /* Not supported */ + SVGA3D_SHADEMODE_MAX +} SVGA3dShadeMode; + +typedef +union { + struct { + uint16 repeat; + uint16 pattern; + }; + uint32 uintValue; +} SVGA3dLinePattern; + +typedef enum { + SVGA3D_BLENDOP_INVALID = 0, + SVGA3D_BLENDOP_ZERO = 1, + SVGA3D_BLENDOP_ONE = 2, + SVGA3D_BLENDOP_SRCCOLOR = 3, + SVGA3D_BLENDOP_INVSRCCOLOR = 4, + SVGA3D_BLENDOP_SRCALPHA = 5, + SVGA3D_BLENDOP_INVSRCALPHA = 6, + SVGA3D_BLENDOP_DESTALPHA = 7, + SVGA3D_BLENDOP_INVDESTALPHA = 8, + SVGA3D_BLENDOP_DESTCOLOR = 9, + SVGA3D_BLENDOP_INVDESTCOLOR = 10, + SVGA3D_BLENDOP_SRCALPHASAT = 11, + SVGA3D_BLENDOP_BLENDFACTOR = 12, + SVGA3D_BLENDOP_INVBLENDFACTOR = 13, + SVGA3D_BLENDOP_MAX +} SVGA3dBlendOp; + +typedef enum { + SVGA3D_BLENDEQ_INVALID = 0, + SVGA3D_BLENDEQ_ADD = 1, + SVGA3D_BLENDEQ_SUBTRACT = 2, + SVGA3D_BLENDEQ_REVSUBTRACT = 3, + SVGA3D_BLENDEQ_MINIMUM = 4, + SVGA3D_BLENDEQ_MAXIMUM = 5, + SVGA3D_BLENDEQ_MAX +} SVGA3dBlendEquation; + +typedef enum { + SVGA3D_FRONTWINDING_INVALID = 0, + SVGA3D_FRONTWINDING_CW = 1, + SVGA3D_FRONTWINDING_CCW = 2, + SVGA3D_FRONTWINDING_MAX +} SVGA3dFrontWinding; + +typedef enum { + SVGA3D_FACE_INVALID = 0, + SVGA3D_FACE_NONE = 1, + SVGA3D_FACE_FRONT = 2, + SVGA3D_FACE_BACK = 3, + SVGA3D_FACE_FRONT_BACK = 4, + SVGA3D_FACE_MAX +} SVGA3dFace; + +/* + * The order and the values should not be changed + */ + +typedef enum { + SVGA3D_CMP_INVALID = 0, + SVGA3D_CMP_NEVER = 1, + SVGA3D_CMP_LESS = 2, + SVGA3D_CMP_EQUAL = 3, + SVGA3D_CMP_LESSEQUAL = 4, + SVGA3D_CMP_GREATER = 5, + SVGA3D_CMP_NOTEQUAL = 6, + SVGA3D_CMP_GREATEREQUAL = 7, + SVGA3D_CMP_ALWAYS = 8, + SVGA3D_CMP_MAX +} SVGA3dCmpFunc; + +/* + * SVGA3D_FOGFUNC_* specifies the fog equation, or PER_VERTEX which allows + * the fog factor to be specified in the alpha component of the specular + * (a.k.a. secondary) vertex color. + */ +typedef enum { + SVGA3D_FOGFUNC_INVALID = 0, + SVGA3D_FOGFUNC_EXP = 1, + SVGA3D_FOGFUNC_EXP2 = 2, + SVGA3D_FOGFUNC_LINEAR = 3, + SVGA3D_FOGFUNC_PER_VERTEX = 4 +} SVGA3dFogFunction; + +/* + * SVGA3D_FOGTYPE_* specifies if fog factors are computed on a per-vertex + * or per-pixel basis. + */ +typedef enum { + SVGA3D_FOGTYPE_INVALID = 0, + SVGA3D_FOGTYPE_VERTEX = 1, + SVGA3D_FOGTYPE_PIXEL = 2, + SVGA3D_FOGTYPE_MAX = 3 +} SVGA3dFogType; + +/* + * SVGA3D_FOGBASE_* selects depth or range-based fog. Depth-based fog is + * computed using the eye Z value of each pixel (or vertex), whereas range- + * based fog is computed using the actual distance (range) to the eye. + */ +typedef enum { + SVGA3D_FOGBASE_INVALID = 0, + SVGA3D_FOGBASE_DEPTHBASED = 1, + SVGA3D_FOGBASE_RANGEBASED = 2, + SVGA3D_FOGBASE_MAX = 3 +} SVGA3dFogBase; + +typedef enum { + SVGA3D_STENCILOP_INVALID = 0, + SVGA3D_STENCILOP_KEEP = 1, + SVGA3D_STENCILOP_ZERO = 2, + SVGA3D_STENCILOP_REPLACE = 3, + SVGA3D_STENCILOP_INCRSAT = 4, + SVGA3D_STENCILOP_DECRSAT = 5, + SVGA3D_STENCILOP_INVERT = 6, + SVGA3D_STENCILOP_INCR = 7, + SVGA3D_STENCILOP_DECR = 8, + SVGA3D_STENCILOP_MAX +} SVGA3dStencilOp; + +typedef enum { + SVGA3D_CLIPPLANE_0 = (1 << 0), + SVGA3D_CLIPPLANE_1 = (1 << 1), + SVGA3D_CLIPPLANE_2 = (1 << 2), + SVGA3D_CLIPPLANE_3 = (1 << 3), + SVGA3D_CLIPPLANE_4 = (1 << 4), + SVGA3D_CLIPPLANE_5 = (1 << 5), +} SVGA3dClipPlanes; + +typedef enum { + SVGA3D_CLEAR_COLOR = 0x1, + SVGA3D_CLEAR_DEPTH = 0x2, + SVGA3D_CLEAR_STENCIL = 0x4 +} SVGA3dClearFlag; + +typedef enum { + SVGA3D_RT_DEPTH = 0, + SVGA3D_RT_STENCIL = 1, + SVGA3D_RT_COLOR0 = 2, + SVGA3D_RT_COLOR1 = 3, + SVGA3D_RT_COLOR2 = 4, + SVGA3D_RT_COLOR3 = 5, + SVGA3D_RT_COLOR4 = 6, + SVGA3D_RT_COLOR5 = 7, + SVGA3D_RT_COLOR6 = 8, + SVGA3D_RT_COLOR7 = 9, + SVGA3D_RT_MAX, + SVGA3D_RT_INVALID = ((uint32)-1), +} SVGA3dRenderTargetType; + +#define SVGA3D_MAX_RT_COLOR (SVGA3D_RT_COLOR7 - SVGA3D_RT_COLOR0 + 1) + +typedef +union { + struct { + uint32 red : 1; + uint32 green : 1; + uint32 blue : 1; + uint32 alpha : 1; + }; + uint32 uintValue; +} SVGA3dColorMask; + +typedef enum { + SVGA3D_VBLEND_DISABLE = 0, + SVGA3D_VBLEND_1WEIGHT = 1, + SVGA3D_VBLEND_2WEIGHT = 2, + SVGA3D_VBLEND_3WEIGHT = 3, +} SVGA3dVertexBlendFlags; + +typedef enum { + SVGA3D_WRAPCOORD_0 = 1 << 0, + SVGA3D_WRAPCOORD_1 = 1 << 1, + SVGA3D_WRAPCOORD_2 = 1 << 2, + SVGA3D_WRAPCOORD_3 = 1 << 3, + SVGA3D_WRAPCOORD_ALL = 0xF, +} SVGA3dWrapFlags; + +/* + * SVGA_3D_CMD_TEXTURESTATE Types. All value types + * must fit in a uint32. + */ + +typedef enum { + SVGA3D_TS_INVALID = 0, + SVGA3D_TS_BIND_TEXTURE = 1, /* SVGA3dSurfaceId */ + SVGA3D_TS_COLOROP = 2, /* SVGA3dTextureCombiner */ + SVGA3D_TS_COLORARG1 = 3, /* SVGA3dTextureArgData */ + SVGA3D_TS_COLORARG2 = 4, /* SVGA3dTextureArgData */ + SVGA3D_TS_ALPHAOP = 5, /* SVGA3dTextureCombiner */ + SVGA3D_TS_ALPHAARG1 = 6, /* SVGA3dTextureArgData */ + SVGA3D_TS_ALPHAARG2 = 7, /* SVGA3dTextureArgData */ + SVGA3D_TS_ADDRESSU = 8, /* SVGA3dTextureAddress */ + SVGA3D_TS_ADDRESSV = 9, /* SVGA3dTextureAddress */ + SVGA3D_TS_MIPFILTER = 10, /* SVGA3dTextureFilter */ + SVGA3D_TS_MAGFILTER = 11, /* SVGA3dTextureFilter */ + SVGA3D_TS_MINFILTER = 12, /* SVGA3dTextureFilter */ + SVGA3D_TS_BORDERCOLOR = 13, /* SVGA3dColor */ + SVGA3D_TS_TEXCOORDINDEX = 14, /* uint32 */ + SVGA3D_TS_TEXTURETRANSFORMFLAGS = 15, /* SVGA3dTexTransformFlags */ + SVGA3D_TS_TEXCOORDGEN = 16, /* SVGA3dTextureCoordGen */ + SVGA3D_TS_BUMPENVMAT00 = 17, /* float */ + SVGA3D_TS_BUMPENVMAT01 = 18, /* float */ + SVGA3D_TS_BUMPENVMAT10 = 19, /* float */ + SVGA3D_TS_BUMPENVMAT11 = 20, /* float */ + SVGA3D_TS_TEXTURE_MIPMAP_LEVEL = 21, /* uint32 */ + SVGA3D_TS_TEXTURE_LOD_BIAS = 22, /* float */ + SVGA3D_TS_TEXTURE_ANISOTROPIC_LEVEL = 23, /* uint32 */ + SVGA3D_TS_ADDRESSW = 24, /* SVGA3dTextureAddress */ + + + /* + * Sampler Gamma Level + * + * Sampler gamma effects the color of samples taken from the sampler. A + * value of 1.0 will produce linear samples. If the value is <= 0.0 the + * gamma value is ignored and a linear space is used. + */ + + SVGA3D_TS_GAMMA = 25, /* float */ + SVGA3D_TS_BUMPENVLSCALE = 26, /* float */ + SVGA3D_TS_BUMPENVLOFFSET = 27, /* float */ + SVGA3D_TS_COLORARG0 = 28, /* SVGA3dTextureArgData */ + SVGA3D_TS_ALPHAARG0 = 29, /* SVGA3dTextureArgData */ + SVGA3D_TS_MAX +} SVGA3dTextureStateName; + +typedef enum { + SVGA3D_TC_INVALID = 0, + SVGA3D_TC_DISABLE = 1, + SVGA3D_TC_SELECTARG1 = 2, + SVGA3D_TC_SELECTARG2 = 3, + SVGA3D_TC_MODULATE = 4, + SVGA3D_TC_ADD = 5, + SVGA3D_TC_ADDSIGNED = 6, + SVGA3D_TC_SUBTRACT = 7, + SVGA3D_TC_BLENDTEXTUREALPHA = 8, + SVGA3D_TC_BLENDDIFFUSEALPHA = 9, + SVGA3D_TC_BLENDCURRENTALPHA = 10, + SVGA3D_TC_BLENDFACTORALPHA = 11, + SVGA3D_TC_MODULATE2X = 12, + SVGA3D_TC_MODULATE4X = 13, + SVGA3D_TC_DSDT = 14, + SVGA3D_TC_DOTPRODUCT3 = 15, + SVGA3D_TC_BLENDTEXTUREALPHAPM = 16, + SVGA3D_TC_ADDSIGNED2X = 17, + SVGA3D_TC_ADDSMOOTH = 18, + SVGA3D_TC_PREMODULATE = 19, + SVGA3D_TC_MODULATEALPHA_ADDCOLOR = 20, + SVGA3D_TC_MODULATECOLOR_ADDALPHA = 21, + SVGA3D_TC_MODULATEINVALPHA_ADDCOLOR = 22, + SVGA3D_TC_MODULATEINVCOLOR_ADDALPHA = 23, + SVGA3D_TC_BUMPENVMAPLUMINANCE = 24, + SVGA3D_TC_MULTIPLYADD = 25, + SVGA3D_TC_LERP = 26, + SVGA3D_TC_MAX +} SVGA3dTextureCombiner; + +#define SVGA3D_TC_CAP_BIT(svga3d_tc_op) (svga3d_tc_op ? (1 << (svga3d_tc_op - 1)) : 0) + +typedef enum { + SVGA3D_TEX_ADDRESS_INVALID = 0, + SVGA3D_TEX_ADDRESS_WRAP = 1, + SVGA3D_TEX_ADDRESS_MIRROR = 2, + SVGA3D_TEX_ADDRESS_CLAMP = 3, + SVGA3D_TEX_ADDRESS_BORDER = 4, + SVGA3D_TEX_ADDRESS_MIRRORONCE = 5, + SVGA3D_TEX_ADDRESS_EDGE = 6, + SVGA3D_TEX_ADDRESS_MAX +} SVGA3dTextureAddress; + +/* + * SVGA3D_TEX_FILTER_NONE as the minification filter means mipmapping is + * disabled, and the rasterizer should use the magnification filter instead. + */ +typedef enum { + SVGA3D_TEX_FILTER_NONE = 0, + SVGA3D_TEX_FILTER_NEAREST = 1, + SVGA3D_TEX_FILTER_LINEAR = 2, + SVGA3D_TEX_FILTER_ANISOTROPIC = 3, + SVGA3D_TEX_FILTER_FLATCUBIC = 4, // Deprecated, not implemented + SVGA3D_TEX_FILTER_GAUSSIANCUBIC = 5, // Deprecated, not implemented + SVGA3D_TEX_FILTER_PYRAMIDALQUAD = 6, // Not currently implemented + SVGA3D_TEX_FILTER_GAUSSIANQUAD = 7, // Not currently implemented + SVGA3D_TEX_FILTER_MAX +} SVGA3dTextureFilter; + +typedef enum { + SVGA3D_TEX_TRANSFORM_OFF = 0, + SVGA3D_TEX_TRANSFORM_S = (1 << 0), + SVGA3D_TEX_TRANSFORM_T = (1 << 1), + SVGA3D_TEX_TRANSFORM_R = (1 << 2), + SVGA3D_TEX_TRANSFORM_Q = (1 << 3), + SVGA3D_TEX_PROJECTED = (1 << 15), +} SVGA3dTexTransformFlags; + +typedef enum { + SVGA3D_TEXCOORD_GEN_OFF = 0, + SVGA3D_TEXCOORD_GEN_EYE_POSITION = 1, + SVGA3D_TEXCOORD_GEN_EYE_NORMAL = 2, + SVGA3D_TEXCOORD_GEN_REFLECTIONVECTOR = 3, + SVGA3D_TEXCOORD_GEN_SPHERE = 4, + SVGA3D_TEXCOORD_GEN_MAX +} SVGA3dTextureCoordGen; + +/* + * Texture argument constants for texture combiner + */ +typedef enum { + SVGA3D_TA_INVALID = 0, + SVGA3D_TA_CONSTANT = 1, + SVGA3D_TA_PREVIOUS = 2, + SVGA3D_TA_DIFFUSE = 3, + SVGA3D_TA_TEXTURE = 4, + SVGA3D_TA_SPECULAR = 5, + SVGA3D_TA_MAX +} SVGA3dTextureArgData; + +#define SVGA3D_TM_MASK_LEN 4 + +/* Modifiers for texture argument constants defined above. */ +typedef enum { + SVGA3D_TM_NONE = 0, + SVGA3D_TM_ALPHA = (1 << SVGA3D_TM_MASK_LEN), + SVGA3D_TM_ONE_MINUS = (2 << SVGA3D_TM_MASK_LEN), +} SVGA3dTextureArgModifier; + +#define SVGA3D_INVALID_ID ((uint32)-1) +#define SVGA3D_MAX_CLIP_PLANES 6 + +/* + * This is the limit to the number of fixed-function texture + * transforms and texture coordinates we can support. It does *not* + * correspond to the number of texture image units (samplers) we + * support! + */ +#define SVGA3D_MAX_TEXTURE_COORDS 8 + +/* + * Vertex declarations + * + * Notes: + * + * SVGA3D_DECLUSAGE_POSITIONT is for pre-transformed vertices. If you + * draw with any POSITIONT vertex arrays, the programmable vertex + * pipeline will be implicitly disabled. Drawing will take place as if + * no vertex shader was bound. + */ + +typedef enum { + SVGA3D_DECLUSAGE_POSITION = 0, + SVGA3D_DECLUSAGE_BLENDWEIGHT, // 1 + SVGA3D_DECLUSAGE_BLENDINDICES, // 2 + SVGA3D_DECLUSAGE_NORMAL, // 3 + SVGA3D_DECLUSAGE_PSIZE, // 4 + SVGA3D_DECLUSAGE_TEXCOORD, // 5 + SVGA3D_DECLUSAGE_TANGENT, // 6 + SVGA3D_DECLUSAGE_BINORMAL, // 7 + SVGA3D_DECLUSAGE_TESSFACTOR, // 8 + SVGA3D_DECLUSAGE_POSITIONT, // 9 + SVGA3D_DECLUSAGE_COLOR, // 10 + SVGA3D_DECLUSAGE_FOG, // 11 + SVGA3D_DECLUSAGE_DEPTH, // 12 + SVGA3D_DECLUSAGE_SAMPLE, // 13 + SVGA3D_DECLUSAGE_MAX +} SVGA3dDeclUsage; + +typedef enum { + SVGA3D_DECLMETHOD_DEFAULT = 0, + SVGA3D_DECLMETHOD_PARTIALU, + SVGA3D_DECLMETHOD_PARTIALV, + SVGA3D_DECLMETHOD_CROSSUV, // Normal + SVGA3D_DECLMETHOD_UV, + SVGA3D_DECLMETHOD_LOOKUP, // Lookup a displacement map + SVGA3D_DECLMETHOD_LOOKUPPRESAMPLED, // Lookup a pre-sampled displacement map +} SVGA3dDeclMethod; + +typedef enum { + SVGA3D_DECLTYPE_FLOAT1 = 0, + SVGA3D_DECLTYPE_FLOAT2 = 1, + SVGA3D_DECLTYPE_FLOAT3 = 2, + SVGA3D_DECLTYPE_FLOAT4 = 3, + SVGA3D_DECLTYPE_D3DCOLOR = 4, + SVGA3D_DECLTYPE_UBYTE4 = 5, + SVGA3D_DECLTYPE_SHORT2 = 6, + SVGA3D_DECLTYPE_SHORT4 = 7, + SVGA3D_DECLTYPE_UBYTE4N = 8, + SVGA3D_DECLTYPE_SHORT2N = 9, + SVGA3D_DECLTYPE_SHORT4N = 10, + SVGA3D_DECLTYPE_USHORT2N = 11, + SVGA3D_DECLTYPE_USHORT4N = 12, + SVGA3D_DECLTYPE_UDEC3 = 13, + SVGA3D_DECLTYPE_DEC3N = 14, + SVGA3D_DECLTYPE_FLOAT16_2 = 15, + SVGA3D_DECLTYPE_FLOAT16_4 = 16, + SVGA3D_DECLTYPE_MAX, +} SVGA3dDeclType; + +/* + * This structure is used for the divisor for geometry instancing; + * it's a direct translation of the Direct3D equivalent. + */ +typedef union { + struct { + /* + * For index data, this number represents the number of instances to draw. + * For instance data, this number represents the number of + * instances/vertex in this stream + */ + uint32 count : 30; + + /* + * This is 1 if this is supposed to be the data that is repeated for + * every instance. + */ + uint32 indexedData : 1; + + /* + * This is 1 if this is supposed to be the per-instance data. + */ + uint32 instanceData : 1; + }; + + uint32 value; +} SVGA3dVertexDivisor; + +typedef enum { + SVGA3D_PRIMITIVE_INVALID = 0, + SVGA3D_PRIMITIVE_TRIANGLELIST = 1, + SVGA3D_PRIMITIVE_POINTLIST = 2, + SVGA3D_PRIMITIVE_LINELIST = 3, + SVGA3D_PRIMITIVE_LINESTRIP = 4, + SVGA3D_PRIMITIVE_TRIANGLESTRIP = 5, + SVGA3D_PRIMITIVE_TRIANGLEFAN = 6, + SVGA3D_PRIMITIVE_MAX +} SVGA3dPrimitiveType; + +typedef enum { + SVGA3D_COORDINATE_INVALID = 0, + SVGA3D_COORDINATE_LEFTHANDED = 1, + SVGA3D_COORDINATE_RIGHTHANDED = 2, + SVGA3D_COORDINATE_MAX +} SVGA3dCoordinateType; + +typedef enum { + SVGA3D_TRANSFORM_INVALID = 0, + SVGA3D_TRANSFORM_WORLD = 1, + SVGA3D_TRANSFORM_VIEW = 2, + SVGA3D_TRANSFORM_PROJECTION = 3, + SVGA3D_TRANSFORM_TEXTURE0 = 4, + SVGA3D_TRANSFORM_TEXTURE1 = 5, + SVGA3D_TRANSFORM_TEXTURE2 = 6, + SVGA3D_TRANSFORM_TEXTURE3 = 7, + SVGA3D_TRANSFORM_TEXTURE4 = 8, + SVGA3D_TRANSFORM_TEXTURE5 = 9, + SVGA3D_TRANSFORM_TEXTURE6 = 10, + SVGA3D_TRANSFORM_TEXTURE7 = 11, + SVGA3D_TRANSFORM_WORLD1 = 12, + SVGA3D_TRANSFORM_WORLD2 = 13, + SVGA3D_TRANSFORM_WORLD3 = 14, + SVGA3D_TRANSFORM_MAX +} SVGA3dTransformType; + +typedef enum { + SVGA3D_LIGHTTYPE_INVALID = 0, + SVGA3D_LIGHTTYPE_POINT = 1, + SVGA3D_LIGHTTYPE_SPOT1 = 2, /* 1-cone, in degrees */ + SVGA3D_LIGHTTYPE_SPOT2 = 3, /* 2-cone, in radians */ + SVGA3D_LIGHTTYPE_DIRECTIONAL = 4, + SVGA3D_LIGHTTYPE_MAX +} SVGA3dLightType; + +typedef enum { + SVGA3D_CUBEFACE_POSX = 0, + SVGA3D_CUBEFACE_NEGX = 1, + SVGA3D_CUBEFACE_POSY = 2, + SVGA3D_CUBEFACE_NEGY = 3, + SVGA3D_CUBEFACE_POSZ = 4, + SVGA3D_CUBEFACE_NEGZ = 5, +} SVGA3dCubeFace; + +typedef enum { + SVGA3D_SHADERTYPE_COMPILED_DX8 = 0, + SVGA3D_SHADERTYPE_VS = 1, + SVGA3D_SHADERTYPE_PS = 2, + SVGA3D_SHADERTYPE_MAX +} SVGA3dShaderType; + +typedef enum { + SVGA3D_CONST_TYPE_FLOAT = 0, + SVGA3D_CONST_TYPE_INT = 1, + SVGA3D_CONST_TYPE_BOOL = 2, +} SVGA3dShaderConstType; + +#define SVGA3D_MAX_SURFACE_FACES 6 + +typedef enum { + SVGA3D_STRETCH_BLT_POINT = 0, + SVGA3D_STRETCH_BLT_LINEAR = 1, + SVGA3D_STRETCH_BLT_MAX +} SVGA3dStretchBltMode; + +typedef enum { + SVGA3D_QUERYTYPE_OCCLUSION = 0, + SVGA3D_QUERYTYPE_MAX +} SVGA3dQueryType; + +typedef enum { + SVGA3D_QUERYSTATE_PENDING = 0, /* Waiting on the host (set by guest) */ + SVGA3D_QUERYSTATE_SUCCEEDED = 1, /* Completed successfully (set by host) */ + SVGA3D_QUERYSTATE_FAILED = 2, /* Completed unsuccessfully (set by host) */ + SVGA3D_QUERYSTATE_NEW = 3, /* Never submitted (For guest use only) */ +} SVGA3dQueryState; + +typedef enum { + SVGA3D_WRITE_HOST_VRAM = 1, + SVGA3D_READ_HOST_VRAM = 2, +} SVGA3dTransferType; + +/* + * The maximum number vertex arrays we're guaranteed to support in + * SVGA_3D_CMD_DRAWPRIMITIVES. + */ +#define SVGA3D_MAX_VERTEX_ARRAYS 32 + +/* + * Identifiers for commands in the command FIFO. + * + * IDs between 1000 and 1039 (inclusive) were used by obsolete versions of + * the SVGA3D protocol and remain reserved; they should not be used in the + * future. + * + * IDs between 1040 and 1999 (inclusive) are available for use by the + * current SVGA3D protocol. + * + * FIFO clients other than SVGA3D should stay below 1000, or at 2000 + * and up. + */ + +#define SVGA_3D_CMD_LEGACY_BASE 1000 +#define SVGA_3D_CMD_BASE 1040 + +#define SVGA_3D_CMD_SURFACE_DEFINE SVGA_3D_CMD_BASE + 0 +#define SVGA_3D_CMD_SURFACE_DESTROY SVGA_3D_CMD_BASE + 1 +#define SVGA_3D_CMD_SURFACE_COPY SVGA_3D_CMD_BASE + 2 +#define SVGA_3D_CMD_SURFACE_STRETCHBLT SVGA_3D_CMD_BASE + 3 +#define SVGA_3D_CMD_SURFACE_DMA SVGA_3D_CMD_BASE + 4 +#define SVGA_3D_CMD_CONTEXT_DEFINE SVGA_3D_CMD_BASE + 5 +#define SVGA_3D_CMD_CONTEXT_DESTROY SVGA_3D_CMD_BASE + 6 +#define SVGA_3D_CMD_SETTRANSFORM SVGA_3D_CMD_BASE + 7 +#define SVGA_3D_CMD_SETZRANGE SVGA_3D_CMD_BASE + 8 +#define SVGA_3D_CMD_SETRENDERSTATE SVGA_3D_CMD_BASE + 9 +#define SVGA_3D_CMD_SETRENDERTARGET SVGA_3D_CMD_BASE + 10 +#define SVGA_3D_CMD_SETTEXTURESTATE SVGA_3D_CMD_BASE + 11 +#define SVGA_3D_CMD_SETMATERIAL SVGA_3D_CMD_BASE + 12 +#define SVGA_3D_CMD_SETLIGHTDATA SVGA_3D_CMD_BASE + 13 +#define SVGA_3D_CMD_SETLIGHTENABLED SVGA_3D_CMD_BASE + 14 +#define SVGA_3D_CMD_SETVIEWPORT SVGA_3D_CMD_BASE + 15 +#define SVGA_3D_CMD_SETCLIPPLANE SVGA_3D_CMD_BASE + 16 +#define SVGA_3D_CMD_CLEAR SVGA_3D_CMD_BASE + 17 +#define SVGA_3D_CMD_PRESENT SVGA_3D_CMD_BASE + 18 // Deprecated +#define SVGA_3D_CMD_SHADER_DEFINE SVGA_3D_CMD_BASE + 19 +#define SVGA_3D_CMD_SHADER_DESTROY SVGA_3D_CMD_BASE + 20 +#define SVGA_3D_CMD_SET_SHADER SVGA_3D_CMD_BASE + 21 +#define SVGA_3D_CMD_SET_SHADER_CONST SVGA_3D_CMD_BASE + 22 +#define SVGA_3D_CMD_DRAW_PRIMITIVES SVGA_3D_CMD_BASE + 23 +#define SVGA_3D_CMD_SETSCISSORRECT SVGA_3D_CMD_BASE + 24 +#define SVGA_3D_CMD_BEGIN_QUERY SVGA_3D_CMD_BASE + 25 +#define SVGA_3D_CMD_END_QUERY SVGA_3D_CMD_BASE + 26 +#define SVGA_3D_CMD_WAIT_FOR_QUERY SVGA_3D_CMD_BASE + 27 +#define SVGA_3D_CMD_PRESENT_READBACK SVGA_3D_CMD_BASE + 28 // Deprecated +#define SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN SVGA_3D_CMD_BASE + 29 +#define SVGA_3D_CMD_MAX SVGA_3D_CMD_BASE + 30 + +#define SVGA_3D_CMD_FUTURE_MAX 2000 + +/* + * Common substructures used in multiple FIFO commands: + */ + +typedef struct { + union { + struct { + uint16 function; // SVGA3dFogFunction + uint8 type; // SVGA3dFogType + uint8 base; // SVGA3dFogBase + }; + uint32 uintValue; + }; +} SVGA3dFogMode; + +/* + * Uniquely identify one image (a 1D/2D/3D array) from a surface. This + * is a surface ID as well as face/mipmap indices. + */ + +typedef +struct SVGA3dSurfaceImageId { + uint32 sid; + uint32 face; + uint32 mipmap; +} SVGA3dSurfaceImageId; + +typedef +struct SVGA3dGuestImage { + SVGAGuestPtr ptr; + + /* + * A note on interpretation of pitch: This value of pitch is the + * number of bytes between vertically adjacent image + * blocks. Normally this is the number of bytes between the first + * pixel of two adjacent scanlines. With compressed textures, + * however, this may represent the number of bytes between + * compression blocks rather than between rows of pixels. + * + * XXX: Compressed textures currently must be tightly packed in guest memory. + * + * If the image is 1-dimensional, pitch is ignored. + * + * If 'pitch' is zero, the SVGA3D device calculates a pitch value + * assuming each row of blocks is tightly packed. + */ + uint32 pitch; +} SVGA3dGuestImage; + + +/* + * FIFO command format definitions: + */ + +/* + * The data size header following cmdNum for every 3d command + */ +typedef +struct { + uint32 id; + uint32 size; +} SVGA3dCmdHeader; + +/* + * A surface is a hierarchy of host VRAM surfaces: 1D, 2D, or 3D, with + * optional mipmaps and cube faces. + */ + +typedef +struct { + uint32 width; + uint32 height; + uint32 depth; +} SVGA3dSize; + +typedef enum { + SVGA3D_SURFACE_CUBEMAP = (1 << 0), + SVGA3D_SURFACE_HINT_STATIC = (1 << 1), + SVGA3D_SURFACE_HINT_DYNAMIC = (1 << 2), + SVGA3D_SURFACE_HINT_INDEXBUFFER = (1 << 3), + SVGA3D_SURFACE_HINT_VERTEXBUFFER = (1 << 4), + SVGA3D_SURFACE_HINT_TEXTURE = (1 << 5), + SVGA3D_SURFACE_HINT_RENDERTARGET = (1 << 6), + SVGA3D_SURFACE_HINT_DEPTHSTENCIL = (1 << 7), + SVGA3D_SURFACE_HINT_WRITEONLY = (1 << 8), +} SVGA3dSurfaceFlags; + +typedef +struct { + uint32 numMipLevels; +} SVGA3dSurfaceFace; + +typedef +struct { + uint32 sid; + SVGA3dSurfaceFlags surfaceFlags; + SVGA3dSurfaceFormat format; + SVGA3dSurfaceFace face[SVGA3D_MAX_SURFACE_FACES]; + /* + * Followed by an SVGA3dSize structure for each mip level in each face. + * + * A note on surface sizes: Sizes are always specified in pixels, + * even if the true surface size is not a multiple of the minimum + * block size of the surface's format. For example, a 3x3x1 DXT1 + * compressed texture would actually be stored as a 4x4x1 image in + * memory. + */ +} SVGA3dCmdDefineSurface; /* SVGA_3D_CMD_SURFACE_DEFINE */ + +typedef +struct { + uint32 sid; +} SVGA3dCmdDestroySurface; /* SVGA_3D_CMD_SURFACE_DESTROY */ + +typedef +struct { + uint32 cid; +} SVGA3dCmdDefineContext; /* SVGA_3D_CMD_CONTEXT_DEFINE */ + +typedef +struct { + uint32 cid; +} SVGA3dCmdDestroyContext; /* SVGA_3D_CMD_CONTEXT_DESTROY */ + +typedef +struct { + uint32 cid; + SVGA3dClearFlag clearFlag; + uint32 color; + float depth; + uint32 stencil; + /* Followed by variable number of SVGA3dRect structures */ +} SVGA3dCmdClear; /* SVGA_3D_CMD_CLEAR */ + +typedef +struct SVGA3dCopyRect { + uint32 x; + uint32 y; + uint32 w; + uint32 h; + uint32 srcx; + uint32 srcy; +} SVGA3dCopyRect; + +typedef +struct SVGA3dCopyBox { + uint32 x; + uint32 y; + uint32 z; + uint32 w; + uint32 h; + uint32 d; + uint32 srcx; + uint32 srcy; + uint32 srcz; +} SVGA3dCopyBox; + +typedef +struct { + uint32 x; + uint32 y; + uint32 w; + uint32 h; +} SVGA3dRect; + +typedef +struct { + uint32 x; + uint32 y; + uint32 z; + uint32 w; + uint32 h; + uint32 d; +} SVGA3dBox; + +typedef +struct { + uint32 x; + uint32 y; + uint32 z; +} SVGA3dPoint; + +typedef +struct { + SVGA3dLightType type; + SVGA3dBool inWorldSpace; + float diffuse[4]; + float specular[4]; + float ambient[4]; + float position[4]; + float direction[4]; + float range; + float falloff; + float attenuation0; + float attenuation1; + float attenuation2; + float theta; + float phi; +} SVGA3dLightData; + +typedef +struct { + uint32 sid; + /* Followed by variable number of SVGA3dCopyRect structures */ +} SVGA3dCmdPresent; /* SVGA_3D_CMD_PRESENT */ + +typedef +struct { + SVGA3dRenderStateName state; + union { + uint32 uintValue; + float floatValue; + }; +} SVGA3dRenderState; + +typedef +struct { + uint32 cid; + /* Followed by variable number of SVGA3dRenderState structures */ +} SVGA3dCmdSetRenderState; /* SVGA_3D_CMD_SETRENDERSTATE */ + +typedef +struct { + uint32 cid; + SVGA3dRenderTargetType type; + SVGA3dSurfaceImageId target; +} SVGA3dCmdSetRenderTarget; /* SVGA_3D_CMD_SETRENDERTARGET */ + +typedef +struct { + SVGA3dSurfaceImageId src; + SVGA3dSurfaceImageId dest; + /* Followed by variable number of SVGA3dCopyBox structures */ +} SVGA3dCmdSurfaceCopy; /* SVGA_3D_CMD_SURFACE_COPY */ + +typedef +struct { + SVGA3dSurfaceImageId src; + SVGA3dSurfaceImageId dest; + SVGA3dBox boxSrc; + SVGA3dBox boxDest; + SVGA3dStretchBltMode mode; +} SVGA3dCmdSurfaceStretchBlt; /* SVGA_3D_CMD_SURFACE_STRETCHBLT */ + +typedef +struct { + /* + * If the discard flag is present in a surface DMA operation, the host may + * discard the contents of the current mipmap level and face of the target + * surface before applying the surface DMA contents. + */ + uint32 discard : 1; + + /* + * If the unsynchronized flag is present, the host may perform this upload + * without syncing to pending reads on this surface. + */ + uint32 unsynchronized : 1; + + /* + * Guests *MUST* set the reserved bits to 0 before submitting the command + * suffix as future flags may occupy these bits. + */ + uint32 reserved : 30; +} SVGA3dSurfaceDMAFlags; + +typedef +struct { + SVGA3dGuestImage guest; + SVGA3dSurfaceImageId host; + SVGA3dTransferType transfer; + /* + * Followed by variable number of SVGA3dCopyBox structures. For consistency + * in all clipping logic and coordinate translation, we define the + * "source" in each copyBox as the guest image and the + * "destination" as the host image, regardless of transfer + * direction. + * + * For efficiency, the SVGA3D device is free to copy more data than + * specified. For example, it may round copy boxes outwards such + * that they lie on particular alignment boundaries. + */ +} SVGA3dCmdSurfaceDMA; /* SVGA_3D_CMD_SURFACE_DMA */ + +/* + * SVGA3dCmdSurfaceDMASuffix -- + * + * This is a command suffix that will appear after a SurfaceDMA command in + * the FIFO. It contains some extra information that hosts may use to + * optimize performance or protect the guest. This suffix exists to preserve + * backwards compatibility while also allowing for new functionality to be + * implemented. + */ + +typedef +struct { + uint32 suffixSize; + + /* + * The maximum offset is used to determine the maximum offset from the + * guestPtr base address that will be accessed or written to during this + * surfaceDMA. If the suffix is supported, the host will respect this + * boundary while performing surface DMAs. + * + * Defaults to MAX_UINT32 + */ + uint32 maximumOffset; + + /* + * A set of flags that describes optimizations that the host may perform + * while performing this surface DMA operation. The guest should never rely + * on behaviour that is different when these flags are set for correctness. + * + * Defaults to 0 + */ + SVGA3dSurfaceDMAFlags flags; +} SVGA3dCmdSurfaceDMASuffix; + +/* + * SVGA_3D_CMD_DRAW_PRIMITIVES -- + * + * This command is the SVGA3D device's generic drawing entry point. + * It can draw multiple ranges of primitives, optionally using an + * index buffer, using an arbitrary collection of vertex buffers. + * + * Each SVGA3dVertexDecl defines a distinct vertex array to bind + * during this draw call. The declarations specify which surface + * the vertex data lives in, what that vertex data is used for, + * and how to interpret it. + * + * Each SVGA3dPrimitiveRange defines a collection of primitives + * to render using the same vertex arrays. An index buffer is + * optional. + */ + +typedef +struct { + /* + * A range hint is an optional specification for the range of indices + * in an SVGA3dArray that will be used. If 'last' is zero, it is assumed + * that the entire array will be used. + * + * These are only hints. The SVGA3D device may use them for + * performance optimization if possible, but it's also allowed to + * ignore these values. + */ + uint32 first; + uint32 last; +} SVGA3dArrayRangeHint; + +typedef +struct { + /* + * Define the origin and shape of a vertex or index array. Both + * 'offset' and 'stride' are in bytes. The provided surface will be + * reinterpreted as a flat array of bytes in the same format used + * by surface DMA operations. To avoid unnecessary conversions, the + * surface should be created with the SVGA3D_BUFFER format. + * + * Index 0 in the array starts 'offset' bytes into the surface. + * Index 1 begins at byte 'offset + stride', etc. Array indices may + * not be negative. + */ + uint32 surfaceId; + uint32 offset; + uint32 stride; +} SVGA3dArray; + +typedef +struct { + /* + * Describe a vertex array's data type, and define how it is to be + * used by the fixed function pipeline or the vertex shader. It + * isn't useful to have two VertexDecls with the same + * VertexArrayIdentity in one draw call. + */ + SVGA3dDeclType type; + SVGA3dDeclMethod method; + SVGA3dDeclUsage usage; + uint32 usageIndex; +} SVGA3dVertexArrayIdentity; + +typedef +struct { + SVGA3dVertexArrayIdentity identity; + SVGA3dArray array; + SVGA3dArrayRangeHint rangeHint; +} SVGA3dVertexDecl; + +typedef +struct { + /* + * Define a group of primitives to render, from sequential indices. + * + * The value of 'primitiveType' and 'primitiveCount' imply the + * total number of vertices that will be rendered. + */ + SVGA3dPrimitiveType primType; + uint32 primitiveCount; + + /* + * Optional index buffer. If indexArray.surfaceId is + * SVGA3D_INVALID_ID, we render without an index buffer. Rendering + * without an index buffer is identical to rendering with an index + * buffer containing the sequence [0, 1, 2, 3, ...]. + * + * If an index buffer is in use, indexWidth specifies the width in + * bytes of each index value. It must be less than or equal to + * indexArray.stride. + * + * (Currently, the SVGA3D device requires index buffers to be tightly + * packed. In other words, indexWidth == indexArray.stride) + */ + SVGA3dArray indexArray; + uint32 indexWidth; + + /* + * Optional index bias. This number is added to all indices from + * indexArray before they are used as vertex array indices. This + * can be used in multiple ways: + * + * - When not using an indexArray, this bias can be used to + * specify where in the vertex arrays to begin rendering. + * + * - A positive number here is equivalent to increasing the + * offset in each vertex array. + * + * - A negative number can be used to render using a small + * vertex array and an index buffer that contains large + * values. This may be used by some applications that + * crop a vertex buffer without modifying their index + * buffer. + * + * Note that rendering with a negative bias value may be slower and + * use more memory than rendering with a positive or zero bias. + */ + int32 indexBias; +} SVGA3dPrimitiveRange; + +typedef +struct { + uint32 cid; + uint32 numVertexDecls; + uint32 numRanges; + + /* + * There are two variable size arrays after the + * SVGA3dCmdDrawPrimitives structure. In order, + * they are: + * + * 1. SVGA3dVertexDecl, quantity 'numVertexDecls' + * 2. SVGA3dPrimitiveRange, quantity 'numRanges' + * 3. Optionally, SVGA3dVertexDivisor, quantity 'numVertexDecls' (contains + * the frequency divisor for this the corresponding vertex decl) + */ +} SVGA3dCmdDrawPrimitives; /* SVGA_3D_CMD_DRAWPRIMITIVES */ + +typedef +struct { + uint32 stage; + SVGA3dTextureStateName name; + union { + uint32 value; + float floatValue; + }; +} SVGA3dTextureState; + +typedef +struct { + uint32 cid; + /* Followed by variable number of SVGA3dTextureState structures */ +} SVGA3dCmdSetTextureState; /* SVGA_3D_CMD_SETTEXTURESTATE */ + +typedef +struct { + uint32 cid; + SVGA3dTransformType type; + float matrix[16]; +} SVGA3dCmdSetTransform; /* SVGA_3D_CMD_SETTRANSFORM */ + +typedef +struct { + float min; + float max; +} SVGA3dZRange; + +typedef +struct { + uint32 cid; + SVGA3dZRange zRange; +} SVGA3dCmdSetZRange; /* SVGA_3D_CMD_SETZRANGE */ + +typedef +struct { + float diffuse[4]; + float ambient[4]; + float specular[4]; + float emissive[4]; + float shininess; +} SVGA3dMaterial; + +typedef +struct { + uint32 cid; + SVGA3dFace face; + SVGA3dMaterial material; +} SVGA3dCmdSetMaterial; /* SVGA_3D_CMD_SETMATERIAL */ + +typedef +struct { + uint32 cid; + uint32 index; + SVGA3dLightData data; +} SVGA3dCmdSetLightData; /* SVGA_3D_CMD_SETLIGHTDATA */ + +typedef +struct { + uint32 cid; + uint32 index; + uint32 enabled; +} SVGA3dCmdSetLightEnabled; /* SVGA_3D_CMD_SETLIGHTENABLED */ + +typedef +struct { + uint32 cid; + SVGA3dRect rect; +} SVGA3dCmdSetViewport; /* SVGA_3D_CMD_SETVIEWPORT */ + +typedef +struct { + uint32 cid; + SVGA3dRect rect; +} SVGA3dCmdSetScissorRect; /* SVGA_3D_CMD_SETSCISSORRECT */ + +typedef +struct { + uint32 cid; + uint32 index; + float plane[4]; +} SVGA3dCmdSetClipPlane; /* SVGA_3D_CMD_SETCLIPPLANE */ + +typedef +struct { + uint32 cid; + uint32 shid; + SVGA3dShaderType type; + /* Followed by variable number of DWORDs for shader bycode */ +} SVGA3dCmdDefineShader; /* SVGA_3D_CMD_SHADER_DEFINE */ + +typedef +struct { + uint32 cid; + uint32 shid; + SVGA3dShaderType type; +} SVGA3dCmdDestroyShader; /* SVGA_3D_CMD_SHADER_DESTROY */ + +typedef +struct { + uint32 cid; + uint32 reg; /* register number */ + SVGA3dShaderType type; + SVGA3dShaderConstType ctype; + uint32 values[4]; +} SVGA3dCmdSetShaderConst; /* SVGA_3D_CMD_SET_SHADER_CONST */ + +typedef +struct { + uint32 cid; + SVGA3dShaderType type; + uint32 shid; +} SVGA3dCmdSetShader; /* SVGA_3D_CMD_SET_SHADER */ + +typedef +struct { + uint32 cid; + SVGA3dQueryType type; +} SVGA3dCmdBeginQuery; /* SVGA_3D_CMD_BEGIN_QUERY */ + +typedef +struct { + uint32 cid; + SVGA3dQueryType type; + SVGAGuestPtr guestResult; /* Points to an SVGA3dQueryResult structure */ +} SVGA3dCmdEndQuery; /* SVGA_3D_CMD_END_QUERY */ + +typedef +struct { + uint32 cid; /* Same parameters passed to END_QUERY */ + SVGA3dQueryType type; + SVGAGuestPtr guestResult; +} SVGA3dCmdWaitForQuery; /* SVGA_3D_CMD_WAIT_FOR_QUERY */ + +typedef +struct { + uint32 totalSize; /* Set by guest before query is ended. */ + SVGA3dQueryState state; /* Set by host or guest. See SVGA3dQueryState. */ + union { /* Set by host on exit from PENDING state */ + uint32 result32; + }; +} SVGA3dQueryResult; + +/* + * SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN -- + * + * This is a blit from an SVGA3D surface to a Screen Object. Just + * like GMR-to-screen blits, this blit may be directed at a + * specific screen or to the virtual coordinate space. + * + * The blit copies from a rectangular region of an SVGA3D surface + * image to a rectangular region of a screen or screens. + * + * This command takes an optional variable-length list of clipping + * rectangles after the body of the command. If no rectangles are + * specified, there is no clipping region. The entire destRect is + * drawn to. If one or more rectangles are included, they describe + * a clipping region. The clip rectangle coordinates are measured + * relative to the top-left corner of destRect. + * + * This clipping region serves multiple purposes: + * + * - It can be used to perform an irregularly shaped blit more + * efficiently than by issuing many separate blit commands. + * + * - It is equivalent to allowing blits with non-integer + * source coordinates. You could blit just one half-pixel + * of a source, for example, by specifying a larger + * destination rectangle than you need, then removing + * part of it using a clip rectangle. + * + * Availability: + * SVGA_FIFO_CAP_SCREEN_OBJECT + * + * Limitations: + * + * - Currently, no backend supports blits from a mipmap or face + * other than the first one. + */ + +typedef +struct { + SVGA3dSurfaceImageId srcImage; + SVGASignedRect srcRect; + uint32 destScreenId; /* Screen ID or SVGA_ID_INVALID for virt. coords */ + SVGASignedRect destRect; /* Supports scaling if src/rest different size */ + /* Clipping: zero or more SVGASignedRects follow */ +} SVGA3dCmdBlitSurfaceToScreen; /* SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN */ + + +/* + * Capability query index. + * + * Notes: + * + * 1. SVGA3D_DEVCAP_MAX_TEXTURES reflects the maximum number of + * fixed-function texture units available. Each of these units + * work in both FFP and Shader modes, and they support texture + * transforms and texture coordinates. The host may have additional + * texture image units that are only usable with shaders. + * + * 2. The BUFFER_FORMAT capabilities are deprecated, and they always + * return TRUE. Even on physical hardware that does not support + * these formats natively, the SVGA3D device will provide an emulation + * which should be invisible to the guest OS. + * + * In general, the SVGA3D device should support any operation on + * any surface format, it just may perform some of these + * operations in software depending on the capabilities of the + * available physical hardware. + * + * XXX: In the future, we will add capabilities that describe in + * detail what formats are supported in hardware for what kinds + * of operations. + */ + +typedef enum { + SVGA3D_DEVCAP_3D = 0, + SVGA3D_DEVCAP_MAX_LIGHTS = 1, + SVGA3D_DEVCAP_MAX_TEXTURES = 2, /* See note (1) */ + SVGA3D_DEVCAP_MAX_CLIP_PLANES = 3, + SVGA3D_DEVCAP_VERTEX_SHADER_VERSION = 4, + SVGA3D_DEVCAP_VERTEX_SHADER = 5, + SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION = 6, + SVGA3D_DEVCAP_FRAGMENT_SHADER = 7, + SVGA3D_DEVCAP_MAX_RENDER_TARGETS = 8, + SVGA3D_DEVCAP_S23E8_TEXTURES = 9, + SVGA3D_DEVCAP_S10E5_TEXTURES = 10, + SVGA3D_DEVCAP_MAX_FIXED_VERTEXBLEND = 11, + SVGA3D_DEVCAP_D16_BUFFER_FORMAT = 12, /* See note (2) */ + SVGA3D_DEVCAP_D24S8_BUFFER_FORMAT = 13, /* See note (2) */ + SVGA3D_DEVCAP_D24X8_BUFFER_FORMAT = 14, /* See note (2) */ + SVGA3D_DEVCAP_QUERY_TYPES = 15, + SVGA3D_DEVCAP_TEXTURE_GRADIENT_SAMPLING = 16, + SVGA3D_DEVCAP_MAX_POINT_SIZE = 17, + SVGA3D_DEVCAP_MAX_SHADER_TEXTURES = 18, + SVGA3D_DEVCAP_MAX_TEXTURE_WIDTH = 19, + SVGA3D_DEVCAP_MAX_TEXTURE_HEIGHT = 20, + SVGA3D_DEVCAP_MAX_VOLUME_EXTENT = 21, + SVGA3D_DEVCAP_MAX_TEXTURE_REPEAT = 22, + SVGA3D_DEVCAP_MAX_TEXTURE_ASPECT_RATIO = 23, + SVGA3D_DEVCAP_MAX_TEXTURE_ANISOTROPY = 24, + SVGA3D_DEVCAP_MAX_PRIMITIVE_COUNT = 25, + SVGA3D_DEVCAP_MAX_VERTEX_INDEX = 26, + SVGA3D_DEVCAP_MAX_VERTEX_SHADER_INSTRUCTIONS = 27, + SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_INSTRUCTIONS = 28, + SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEMPS = 29, + SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_TEMPS = 30, + SVGA3D_DEVCAP_TEXTURE_OPS = 31, + SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8 = 32, + SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8 = 33, + SVGA3D_DEVCAP_SURFACEFMT_A2R10G10B10 = 34, + SVGA3D_DEVCAP_SURFACEFMT_X1R5G5B5 = 35, + SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5 = 36, + SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4 = 37, + SVGA3D_DEVCAP_SURFACEFMT_R5G6B5 = 38, + SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE16 = 39, + SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8_ALPHA8 = 40, + SVGA3D_DEVCAP_SURFACEFMT_ALPHA8 = 41, + SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8 = 42, + SVGA3D_DEVCAP_SURFACEFMT_Z_D16 = 43, + SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8 = 44, + SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8 = 45, + SVGA3D_DEVCAP_SURFACEFMT_DXT1 = 46, + SVGA3D_DEVCAP_SURFACEFMT_DXT2 = 47, + SVGA3D_DEVCAP_SURFACEFMT_DXT3 = 48, + SVGA3D_DEVCAP_SURFACEFMT_DXT4 = 49, + SVGA3D_DEVCAP_SURFACEFMT_DXT5 = 50, + SVGA3D_DEVCAP_SURFACEFMT_BUMPX8L8V8U8 = 51, + SVGA3D_DEVCAP_SURFACEFMT_A2W10V10U10 = 52, + SVGA3D_DEVCAP_SURFACEFMT_BUMPU8V8 = 53, + SVGA3D_DEVCAP_SURFACEFMT_Q8W8V8U8 = 54, + SVGA3D_DEVCAP_SURFACEFMT_CxV8U8 = 55, + SVGA3D_DEVCAP_SURFACEFMT_R_S10E5 = 56, + SVGA3D_DEVCAP_SURFACEFMT_R_S23E8 = 57, + SVGA3D_DEVCAP_SURFACEFMT_RG_S10E5 = 58, + SVGA3D_DEVCAP_SURFACEFMT_RG_S23E8 = 59, + SVGA3D_DEVCAP_SURFACEFMT_ARGB_S10E5 = 60, + SVGA3D_DEVCAP_SURFACEFMT_ARGB_S23E8 = 61, + SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEXTURES = 63, + + /* + * Note that MAX_SIMULTANEOUS_RENDER_TARGETS is a maximum count of color + * render targets. This does no include the depth or stencil targets. + */ + SVGA3D_DEVCAP_MAX_SIMULTANEOUS_RENDER_TARGETS = 64, + + SVGA3D_DEVCAP_SURFACEFMT_V16U16 = 65, + SVGA3D_DEVCAP_SURFACEFMT_G16R16 = 66, + SVGA3D_DEVCAP_SURFACEFMT_A16B16G16R16 = 67, + SVGA3D_DEVCAP_SURFACEFMT_UYVY = 68, + SVGA3D_DEVCAP_SURFACEFMT_YUY2 = 69, + + /* + * Don't add new caps into the previous section; the values in this + * enumeration must not change. You can put new values right before + * SVGA3D_DEVCAP_MAX. + */ + SVGA3D_DEVCAP_MAX /* This must be the last index. */ +} SVGA3dDevCapIndex; + +typedef union { + Bool b; + uint32 u; + int32 i; + float f; +} SVGA3dDevCapResult; + +#endif /* _SVGA3D_REG_H_ */ diff --git a/src/gallium/drivers/svga/include/svga3d_shaderdefs.h b/src/gallium/drivers/svga/include/svga3d_shaderdefs.h new file mode 100644 index 0000000..2078c4a --- /dev/null +++ b/src/gallium/drivers/svga/include/svga3d_shaderdefs.h @@ -0,0 +1,519 @@ +/********************************************************** + * Copyright 2007-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. + * + **********************************************************/ + +/* + * svga3d_shaderdefs.h -- + * + * SVGA3D byte code format and limit definitions. + * + * The format of the byte code directly corresponds to that defined + * by Microsoft DirectX SDK 9.0c (file d3d9types.h). The format can + * also be extended so that different shader formats can be supported + * for example GLSL, ARB vp/fp, NV/ATI shader formats, etc. + * + */ + +#ifndef __SVGA3D_SHADER_DEFS__ +#define __SVGA3D_SHADER_DEFS__ + +/* SVGA3D shader hardware limits. */ + +#define SVGA3D_INPUTREG_MAX 16 +#define SVGA3D_OUTPUTREG_MAX 12 +#define SVGA3D_VERTEX_SAMPLERREG_MAX 4 +#define SVGA3D_PIXEL_SAMPLERREG_MAX 16 +#define SVGA3D_SAMPLERREG_MAX (SVGA3D_PIXEL_SAMPLERREG_MAX+\ + SVGA3D_VERTEX_SAMPLERREG_MAX) +#define SVGA3D_TEMPREG_MAX 32 +#define SVGA3D_CONSTREG_MAX 256 +#define SVGA3D_CONSTINTREG_MAX 16 +#define SVGA3D_CONSTBOOLREG_MAX 16 +#define SVGA3D_ADDRREG_MAX 1 +#define SVGA3D_PREDREG_MAX 1 + +/* SVGA3D byte code specific limits */ + +#define SVGA3D_MAX_SRC_REGS 4 +#define SVGA3D_MAX_NESTING_LEVEL 32 + +/* SVGA3D version information. */ + +#define SVGA3D_VS_TYPE 0xFFFE +#define SVGA3D_PS_TYPE 0xFFFF + +typedef struct { + union { + struct { + uint32 minor : 8; + uint32 major : 8; + uint32 type : 16; + }; + + uint32 value; + }; +} SVGA3dShaderVersion; + +#define SVGA3D_VS_10 ((SVGA3D_VS_TYPE << 16) | 1 << 8) +#define SVGA3D_VS_11 (SVGA3D_VS_10 | 1) +#define SVGA3D_VS_20 ((SVGA3D_VS_TYPE << 16) | 2 << 8) +#define SVGA3D_VS_30 ((SVGA3D_VS_TYPE << 16) | 3 << 8) + +#define SVGA3D_PS_10 ((SVGA3D_PS_TYPE << 16) | 1 << 8) +#define SVGA3D_PS_11 (SVGA3D_PS_10 | 1) +#define SVGA3D_PS_12 (SVGA3D_PS_10 | 2) +#define SVGA3D_PS_13 (SVGA3D_PS_10 | 3) +#define SVGA3D_PS_14 (SVGA3D_PS_10 | 4) +#define SVGA3D_PS_20 ((SVGA3D_PS_TYPE << 16) | 2 << 8) +#define SVGA3D_PS_30 ((SVGA3D_PS_TYPE << 16) | 3 << 8) + +/* The *_ENABLED are for backwards compatibility with old drivers */ +typedef enum { + SVGA3DPSVERSION_NONE = 0, + SVGA3DPSVERSION_ENABLED = 1, + SVGA3DPSVERSION_11 = 3, + SVGA3DPSVERSION_12 = 5, + SVGA3DPSVERSION_13 = 7, + SVGA3DPSVERSION_14 = 9, + SVGA3DPSVERSION_20 = 11, + SVGA3DPSVERSION_30 = 13, + SVGA3DPSVERSION_40 = 15, + SVGA3DPSVERSION_MAX +} SVGA3dPixelShaderVersion; + +typedef enum { + SVGA3DVSVERSION_NONE = 0, + SVGA3DVSVERSION_ENABLED = 1, + SVGA3DVSVERSION_11 = 3, + SVGA3DVSVERSION_20 = 5, + SVGA3DVSVERSION_30 = 7, + SVGA3DVSVERSION_40 = 9, + SVGA3DVSVERSION_MAX +} SVGA3dVertexShaderVersion; + +/* SVGA3D instruction op codes. */ + +typedef enum { + SVGA3DOP_NOP = 0, + SVGA3DOP_MOV, + SVGA3DOP_ADD, + SVGA3DOP_SUB, + SVGA3DOP_MAD, + SVGA3DOP_MUL, + SVGA3DOP_RCP, + SVGA3DOP_RSQ, + SVGA3DOP_DP3, + SVGA3DOP_DP4, + SVGA3DOP_MIN, + SVGA3DOP_MAX, + SVGA3DOP_SLT, + SVGA3DOP_SGE, + SVGA3DOP_EXP, + SVGA3DOP_LOG, + SVGA3DOP_LIT, + SVGA3DOP_DST, + SVGA3DOP_LRP, + SVGA3DOP_FRC, + SVGA3DOP_M4x4, + SVGA3DOP_M4x3, + SVGA3DOP_M3x4, + SVGA3DOP_M3x3, + SVGA3DOP_M3x2, + SVGA3DOP_CALL, + SVGA3DOP_CALLNZ, + SVGA3DOP_LOOP, + SVGA3DOP_RET, + SVGA3DOP_ENDLOOP, + SVGA3DOP_LABEL, + SVGA3DOP_DCL, + SVGA3DOP_POW, + SVGA3DOP_CRS, + SVGA3DOP_SGN, + SVGA3DOP_ABS, + SVGA3DOP_NRM, + SVGA3DOP_SINCOS, + SVGA3DOP_REP, + SVGA3DOP_ENDREP, + SVGA3DOP_IF, + SVGA3DOP_IFC, + SVGA3DOP_ELSE, + SVGA3DOP_ENDIF, + SVGA3DOP_BREAK, + SVGA3DOP_BREAKC, + SVGA3DOP_MOVA, + SVGA3DOP_DEFB, + SVGA3DOP_DEFI, + SVGA3DOP_TEXCOORD = 64, + SVGA3DOP_TEXKILL, + SVGA3DOP_TEX, + SVGA3DOP_TEXBEM, + SVGA3DOP_TEXBEML, + SVGA3DOP_TEXREG2AR, + SVGA3DOP_TEXREG2GB = 70, + SVGA3DOP_TEXM3x2PAD, + SVGA3DOP_TEXM3x2TEX, + SVGA3DOP_TEXM3x3PAD, + SVGA3DOP_TEXM3x3TEX, + SVGA3DOP_RESERVED0, + SVGA3DOP_TEXM3x3SPEC, + SVGA3DOP_TEXM3x3VSPEC, + SVGA3DOP_EXPP, + SVGA3DOP_LOGP, + SVGA3DOP_CND = 80, + SVGA3DOP_DEF, + SVGA3DOP_TEXREG2RGB, + SVGA3DOP_TEXDP3TEX, + SVGA3DOP_TEXM3x2DEPTH, + SVGA3DOP_TEXDP3, + SVGA3DOP_TEXM3x3, + SVGA3DOP_TEXDEPTH, + SVGA3DOP_CMP, + SVGA3DOP_BEM, + SVGA3DOP_DP2ADD = 90, + SVGA3DOP_DSX, + SVGA3DOP_DSY, + SVGA3DOP_TEXLDD, + SVGA3DOP_SETP, + SVGA3DOP_TEXLDL, + SVGA3DOP_BREAKP = 96, + SVGA3DOP_LAST_INST, + SVGA3DOP_PHASE = 0xFFFD, + SVGA3DOP_COMMENT = 0xFFFE, + SVGA3DOP_END = 0xFFFF, +} SVGA3dShaderOpCodeType; + +/* SVGA3D operation control/comparison function types */ + +typedef enum { + SVGA3DOPCONT_NONE, + SVGA3DOPCONT_PROJECT, /* Projective texturing */ + SVGA3DOPCONT_BIAS, /* Texturing with a LOD bias */ +} SVGA3dShaderOpCodeControlFnType; + +typedef enum { + SVGA3DOPCOMP_RESERVED0 = 0, + SVGA3DOPCOMP_GT, + SVGA3DOPCOMP_EQ, + SVGA3DOPCOMP_GE, + SVGA3DOPCOMP_LT, + SVGA3DOPCOMPC_NE, + SVGA3DOPCOMP_LE, + SVGA3DOPCOMP_RESERVED1 +} SVGA3dShaderOpCodeCompFnType; + +/* SVGA3D register types */ + +typedef enum { + SVGA3DREG_TEMP = 0, /* Temporary register file */ + SVGA3DREG_INPUT, /* Input register file */ + SVGA3DREG_CONST, /* Constant register file */ + SVGA3DREG_ADDR, /* Address register for VS */ + SVGA3DREG_TEXTURE = 3, /* Texture register file for PS */ + SVGA3DREG_RASTOUT, /* Rasterizer register file */ + SVGA3DREG_ATTROUT, /* Attribute output register file */ + SVGA3DREG_TEXCRDOUT, /* Texture coordinate output register file */ + SVGA3DREG_OUTPUT = 6, /* Output register file for VS 3.0+ */ + SVGA3DREG_CONSTINT, /* Constant integer vector register file */ + SVGA3DREG_COLOROUT, /* Color output register file */ + SVGA3DREG_DEPTHOUT, /* Depth output register file */ + SVGA3DREG_SAMPLER, /* Sampler state register file */ + SVGA3DREG_CONST2, /* Constant register file 2048 - 4095 */ + SVGA3DREG_CONST3, /* Constant register file 4096 - 6143 */ + SVGA3DREG_CONST4, /* Constant register file 6144 - 8191 */ + SVGA3DREG_CONSTBOOL, /* Constant boolean register file */ + SVGA3DREG_LOOP, /* Loop counter register file */ + SVGA3DREG_TEMPFLOAT16, /* 16-bit float temp register file */ + SVGA3DREG_MISCTYPE, /* Miscellaneous (single) registers */ + SVGA3DREG_LABEL, /* Label */ + SVGA3DREG_PREDICATE, /* Predicate register */ +} SVGA3dShaderRegType; + +/* SVGA3D rasterizer output register types */ + +typedef enum { + SVGA3DRASTOUT_POSITION = 0, + SVGA3DRASTOUT_FOG, + SVGA3DRASTOUT_PSIZE +} SVGA3dShaderRastOutRegType; + +/* SVGA3D miscellaneous register types */ + +typedef enum { + SVGA3DMISCREG_POSITION = 0, /* Input position x,y,z,rhw (PS) */ + SVGA3DMISCREG_FACE /* Floating point primitive area (PS) */ +} SVGA3DShaderMiscRegType; + +/* SVGA3D sampler types */ + +typedef enum { + SVGA3DSAMP_UNKNOWN = 0, /* Uninitialized value */ + SVGA3DSAMP_2D = 2, /* dcl_2d s# (for declaring a 2-D texture) */ + SVGA3DSAMP_CUBE, /* dcl_cube s# (for declaring a cube texture) */ + SVGA3DSAMP_VOLUME, /* dcl_volume s# (for declaring a volume texture) */ +} SVGA3dShaderSamplerType; + +/* SVGA3D sampler format classes */ + +typedef enum { + SVGA3DSAMPFORMAT_ARGB, /* ARGB formats */ + SVGA3DSAMPFORMAT_V8U8, /* Sign and normalize (SNORM) V & U */ + SVGA3DSAMPFORMAT_Q8W8V8U8, /* SNORM all */ + SVGA3DSAMPFORMAT_CxV8U8, /* SNORM V & U, C=SQRT(1-U^2-V^2) */ + SVGA3DSAMPFORMAT_X8L8V8U8, /* SNORM V & U */ + SVGA3DSAMPFORMAT_A2W10V10U10, /* SNORM W, V & U */ + SVGA3DSAMPFORMAT_DXT_PMA, /* DXT pre-multiplied alpha */ + SVGA3DSAMPFORMAT_YUV, /* YUV video format */ + SVGA3DSAMPFORMAT_UYVY, /* UYVY video format */ + SVGA3DSAMPFORMAT_Rx, /* R16F/32F */ + SVGA3DSAMPFORMAT_RxGx, /* R16FG16F, R32FG32F */ + SVGA3DSAMPFORMAT_V16U16, /* SNORM all */ +} SVGA3DShaderSamplerFormatClass; + +/* SVGA3D write mask */ + +#define SVGA3DWRITEMASK_0 1 /* Component 0 (X;Red) */ +#define SVGA3DWRITEMASK_1 2 /* Component 1 (Y;Green) */ +#define SVGA3DWRITEMASK_2 4 /* Component 2 (Z;Blue) */ +#define SVGA3DWRITEMASK_3 8 /* Component 3 (W;Alpha) */ +#define SVGA3DWRITEMASK_ALL 15 /* All components */ + +/* SVGA3D destination modifiers */ + +#define SVGA3DDSTMOD_NONE 0 /* nop */ +#define SVGA3DDSTMOD_SATURATE 1 /* clamp to [0, 1] */ +#define SVGA3DDSTMOD_PARTIALPRECISION 2 /* Partial precision hint */ + +/* + * Relevant to multisampling only: + * When the pixel center is not covered, sample + * attribute or compute gradients/LOD + * using multisample "centroid" location. + * "Centroid" is some location within the covered + * region of the pixel. + */ + +#define SVGA3DDSTMOD_MSAMPCENTROID 4 + +/* SVGA3D source swizzle */ + +#define SVGA3DSWIZZLE_REPLICATEX 0x00 +#define SVGA3DSWIZZLE_REPLICATEY 0x55 +#define SVGA3DSWIZZLE_REPLICATEZ 0xAA +#define SVGA3DSWIZZLE_REPLICATEW 0xFF +#define SVGA3DSWIZZLE_NONE 0xE4 +#define SVGA3DSWIZZLE_YZXW 0xC9 +#define SVGA3DSWIZZLE_ZXYW 0xD2 +#define SVGA3DSWIZZLE_WXYZ 0x1B + +/* SVGA3D source modifiers */ + +typedef enum { + SVGA3DSRCMOD_NONE = 0, /* nop */ + SVGA3DSRCMOD_NEG, /* negate */ + SVGA3DSRCMOD_BIAS, /* bias */ + SVGA3DSRCMOD_BIASNEG, /* bias and negate */ + SVGA3DSRCMOD_SIGN, /* sign */ + SVGA3DSRCMOD_SIGNNEG, /* sign and negate */ + SVGA3DSRCMOD_COMP, /* complement */ + SVGA3DSRCMOD_X2, /* x2 */ + SVGA3DSRCMOD_X2NEG, /* x2 and negate */ + SVGA3DSRCMOD_DZ, /* divide through by z component */ + SVGA3DSRCMOD_DW, /* divide through by w component */ + SVGA3DSRCMOD_ABS, /* abs() */ + SVGA3DSRCMOD_ABSNEG, /* -abs() */ + SVGA3DSRCMOD_NOT, /* ! (for predicate register) */ +} SVGA3dShaderSrcModType; + +/* SVGA3D instruction token */ + +typedef struct { + union { + struct { + uint32 comment_op : 16; + uint32 comment_size : 16; + }; + + struct { + uint32 op : 16; + uint32 control : 3; + uint32 reserved2 : 5; + uint32 size : 4; + uint32 predicated : 1; + uint32 reserved1 : 1; + uint32 coissue : 1; + uint32 reserved0 : 1; + }; + + uint32 value; + }; +} SVGA3dShaderInstToken; + +/* SVGA3D destination parameter token */ + +typedef struct { + union { + struct { + uint32 num : 11; + uint32 type_upper : 2; + uint32 relAddr : 1; + uint32 reserved1 : 2; + uint32 mask : 4; + uint32 dstMod : 4; + uint32 shfScale : 4; + uint32 type_lower : 3; + uint32 reserved0 : 1; + }; + + uint32 value; + }; +} SVGA3dShaderDestToken; + +/* SVGA3D source parameter token */ + +typedef struct { + union { + struct { + uint32 num : 11; + uint32 type_upper : 2; + uint32 relAddr : 1; + uint32 reserved1 : 2; + uint32 swizzle : 8; + uint32 srcMod : 4; + uint32 type_lower : 3; + uint32 reserved0 : 1; + }; + + uint32 value; + }; +} SVGA3dShaderSrcToken; + +/* SVGA3DOP_DCL parameter tokens */ + +typedef struct { + union { + struct { + union { + struct { + uint32 usage : 5; + uint32 reserved1 : 11; + uint32 index : 4; + uint32 reserved0 : 12; + }; /* input / output declaration */ + + struct { + uint32 reserved3 : 27; + uint32 type : 4; + uint32 reserved2 : 1; + }; /* sampler declaration */ + }; + + SVGA3dShaderDestToken dst; + }; + + uint32 values[2]; + }; +} SVGA3DOpDclArgs; + +/* SVGA3DOP_DEF parameter tokens */ + +typedef struct { + union { + struct { + SVGA3dShaderDestToken dst; + + union { + float constValues[4]; + int constIValues[4]; + Bool constBValue; + }; + }; + + uint32 values[5]; + }; +} SVGA3DOpDefArgs; + +/* SVGA3D shader token */ + +typedef union { + uint32 value; + SVGA3dShaderInstToken inst; + SVGA3dShaderDestToken dest; + SVGA3dShaderSrcToken src; +} SVGA3dShaderToken; + +/* SVGA3D shader program */ + +typedef struct { + SVGA3dShaderVersion version; + /* SVGA3dShaderToken stream */ +} SVGA3dShaderProgram; + +/* SVGA3D version specific register assignments */ + +static const uint32 SVGA3D_INPUT_REG_POSITION_VS11 = 0; +static const uint32 SVGA3D_INPUT_REG_PSIZE_VS11 = 1; +static const uint32 SVGA3D_INPUT_REG_FOG_VS11 = 3; +static const uint32 SVGA3D_INPUT_REG_FOG_MASK_VS11 = SVGA3DWRITEMASK_3; +static const uint32 SVGA3D_INPUT_REG_COLOR_BASE_VS11 = 2; +static const uint32 SVGA3D_INPUT_REG_TEXCOORD_BASE_VS11 = 4; + +static const uint32 SVGA3D_INPUT_REG_COLOR_BASE_PS11 = 0; +static const uint32 SVGA3D_INPUT_REG_TEXCOORD_BASE_PS11 = 2; +static const uint32 SVGA3D_OUTPUT_REG_DEPTH_PS11 = 0; +static const uint32 SVGA3D_OUTPUT_REG_COLOR_PS11 = 1; + +static const uint32 SVGA3D_INPUT_REG_COLOR_BASE_PS20 = 0; +static const uint32 SVGA3D_INPUT_REG_COLOR_NUM_PS20 = 2; +static const uint32 SVGA3D_INPUT_REG_TEXCOORD_BASE_PS20 = 2; +static const uint32 SVGA3D_INPUT_REG_TEXCOORD_NUM_PS20 = 8; +static const uint32 SVGA3D_OUTPUT_REG_COLOR_BASE_PS20 = 1; +static const uint32 SVGA3D_OUTPUT_REG_COLOR_NUM_PS20 = 4; +static const uint32 SVGA3D_OUTPUT_REG_DEPTH_BASE_PS20 = 0; +static const uint32 SVGA3D_OUTPUT_REG_DEPTH_NUM_PS20 = 1; + +/* + *---------------------------------------------------------------------- + * + * SVGA3dShaderGetRegType -- + * + * As the register type is split into two non sequential fields, + * this function provides an useful way of accessing the actual + * register type without having to manually concatenate the + * type_upper and type_lower fields. + * + * Results: + * Returns the register type. + * + *---------------------------------------------------------------------- + */ + +static INLINE SVGA3dShaderRegType +SVGA3dShaderGetRegType(uint32 token) +{ + SVGA3dShaderSrcToken src; + src.value = token; + return (SVGA3dShaderRegType)(src.type_upper << 3 | src.type_lower); +} + +#endif /* __SVGA3D_SHADER_DEFS__ */ diff --git a/src/gallium/drivers/svga/include/svga_escape.h b/src/gallium/drivers/svga/include/svga_escape.h new file mode 100644 index 0000000..7b85e9b --- /dev/null +++ b/src/gallium/drivers/svga/include/svga_escape.h @@ -0,0 +1,89 @@ +/********************************************************** + * Copyright 2007-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. + * + **********************************************************/ + +/* + * svga_escape.h -- + * + * Definitions for our own (vendor-specific) SVGA Escape commands. + */ + +#ifndef _SVGA_ESCAPE_H_ +#define _SVGA_ESCAPE_H_ + + +/* + * Namespace IDs for the escape command + */ + +#define SVGA_ESCAPE_NSID_VMWARE 0x00000000 +#define SVGA_ESCAPE_NSID_DEVEL 0xFFFFFFFF + + +/* + * Within SVGA_ESCAPE_NSID_VMWARE, we multiplex commands according to + * the first DWORD of escape data (after the nsID and size). As a + * guideline we're using the high word and low word as a major and + * minor command number, respectively. + * + * Major command number allocation: + * + * 0000: Reserved + * 0001: SVGA_ESCAPE_VMWARE_LOG (svga_binary_logger.h) + * 0002: SVGA_ESCAPE_VMWARE_VIDEO (svga_overlay.h) + * 0003: SVGA_ESCAPE_VMWARE_HINT (svga_escape.h) + */ + +#define SVGA_ESCAPE_VMWARE_MAJOR_MASK 0xFFFF0000 + + +/* + * SVGA Hint commands. + * + * These escapes let the SVGA driver provide optional information to + * he host about the state of the guest or guest applications. The + * host can use these hints to make user interface or performance + * decisions. + * + * Notes: + * + * - SVGA_ESCAPE_VMWARE_HINT_FULLSCREEN is deprecated for guests + * that use the SVGA Screen Object extension. Instead of sending + * this escape, use the SVGA_SCREEN_FULLSCREEN_HINT flag on your + * Screen Object. + */ + +#define SVGA_ESCAPE_VMWARE_HINT 0x00030000 +#define SVGA_ESCAPE_VMWARE_HINT_FULLSCREEN 0x00030001 // Deprecated + +typedef +struct { + uint32 command; + uint32 fullscreen; + struct { + int32 x, y; + } monitorPosition; +} SVGAEscapeHintFullscreen; + +#endif /* _SVGA_ESCAPE_H_ */ diff --git a/src/gallium/drivers/svga/include/svga_overlay.h b/src/gallium/drivers/svga/include/svga_overlay.h new file mode 100644 index 0000000..82c1d3f --- /dev/null +++ b/src/gallium/drivers/svga/include/svga_overlay.h @@ -0,0 +1,201 @@ +/********************************************************** + * Copyright 2007-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. + * + **********************************************************/ + +/* + * svga_overlay.h -- + * + * Definitions for video-overlay support. + */ + +#ifndef _SVGA_OVERLAY_H_ +#define _SVGA_OVERLAY_H_ + +#include "svga_reg.h" + +/* + * Video formats we support + */ + +#define VMWARE_FOURCC_YV12 0x32315659 // 'Y' 'V' '1' '2' +#define VMWARE_FOURCC_YUY2 0x32595559 // 'Y' 'U' 'Y' '2' +#define VMWARE_FOURCC_UYVY 0x59565955 // 'U' 'Y' 'V' 'Y' + +typedef enum { + SVGA_OVERLAY_FORMAT_INVALID = 0, + SVGA_OVERLAY_FORMAT_YV12 = VMWARE_FOURCC_YV12, + SVGA_OVERLAY_FORMAT_YUY2 = VMWARE_FOURCC_YUY2, + SVGA_OVERLAY_FORMAT_UYVY = VMWARE_FOURCC_UYVY, +} SVGAOverlayFormat; + +#define SVGA_VIDEO_COLORKEY_MASK 0x00ffffff + +#define SVGA_ESCAPE_VMWARE_VIDEO 0x00020000 + +#define SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS 0x00020001 + /* FIFO escape layout: + * Type, Stream Id, (Register Id, Value) pairs */ + +#define SVGA_ESCAPE_VMWARE_VIDEO_FLUSH 0x00020002 + /* FIFO escape layout: + * Type, Stream Id */ + +typedef +struct SVGAEscapeVideoSetRegs { + struct { + uint32 cmdType; + uint32 streamId; + } header; + + // May include zero or more items. + struct { + uint32 registerId; + uint32 value; + } items[1]; +} SVGAEscapeVideoSetRegs; + +typedef +struct SVGAEscapeVideoFlush { + uint32 cmdType; + uint32 streamId; +} SVGAEscapeVideoFlush; + + +/* + * Struct definitions for the video overlay commands built on + * SVGAFifoCmdEscape. + */ +typedef +struct { + uint32 command; + uint32 overlay; +} SVGAFifoEscapeCmdVideoBase; + +typedef +struct { + SVGAFifoEscapeCmdVideoBase videoCmd; +} SVGAFifoEscapeCmdVideoFlush; + +typedef +struct { + SVGAFifoEscapeCmdVideoBase videoCmd; + struct { + uint32 regId; + uint32 value; + } items[1]; +} SVGAFifoEscapeCmdVideoSetRegs; + +typedef +struct { + SVGAFifoEscapeCmdVideoBase videoCmd; + struct { + uint32 regId; + uint32 value; + } items[SVGA_VIDEO_NUM_REGS]; +} SVGAFifoEscapeCmdVideoSetAllRegs; + + +/* + *---------------------------------------------------------------------- + * + * VMwareVideoGetAttributes -- + * + * Computes the size, pitches and offsets for YUV frames. + * + * Results: + * TRUE on success; otherwise FALSE on failure. + * + * Side effects: + * Pitches and offsets for the given YUV frame are put in 'pitches' + * and 'offsets' respectively. They are both optional though. + * + *---------------------------------------------------------------------- + */ + +static INLINE Bool +VMwareVideoGetAttributes(const SVGAOverlayFormat format, // IN + uint32 *width, // IN / OUT + uint32 *height, // IN / OUT + uint32 *size, // OUT + uint32 *pitches, // OUT (optional) + uint32 *offsets) // OUT (optional) +{ + int tmp; + + *width = (*width + 1) & ~1; + + if (offsets) { + offsets[0] = 0; + } + + switch (format) { + case VMWARE_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 VMWARE_FOURCC_YUY2: + case VMWARE_FOURCC_UYVY: + *size = *width * 2; + + if (pitches) { + pitches[0] = *size; + } + + *size *= *height; + break; + + default: + return FALSE; + } + + return TRUE; +} + +#endif // _SVGA_OVERLAY_H_ diff --git a/src/gallium/drivers/svga/include/svga_reg.h b/src/gallium/drivers/svga/include/svga_reg.h new file mode 100644 index 0000000..1b96c2e --- /dev/null +++ b/src/gallium/drivers/svga/include/svga_reg.h @@ -0,0 +1,1346 @@ +/********************************************************** + * Copyright 1998-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. + * + **********************************************************/ + +/* + * svga_reg.h -- + * + * Virtual hardware definitions for the VMware SVGA II device. + */ + +#ifndef _SVGA_REG_H_ +#define _SVGA_REG_H_ + +/* + * PCI device IDs. + */ +#define PCI_VENDOR_ID_VMWARE 0x15AD +#define PCI_DEVICE_ID_VMWARE_SVGA2 0x0405 + +/* + * Legal values for the SVGA_REG_CURSOR_ON register in old-fashioned + * cursor bypass mode. This is still supported, but no new guest + * drivers should use it. + */ +#define SVGA_CURSOR_ON_HIDE 0x0 /* Must be 0 to maintain backward compatibility */ +#define SVGA_CURSOR_ON_SHOW 0x1 /* Must be 1 to maintain backward compatibility */ +#define SVGA_CURSOR_ON_REMOVE_FROM_FB 0x2 /* Remove the cursor from the framebuffer because we need to see what's under it */ +#define SVGA_CURSOR_ON_RESTORE_TO_FB 0x3 /* Put the cursor back in the framebuffer so the user can see it */ + +/* + * The maximum framebuffer size that can traced for e.g. guests in VESA mode. + * The changeMap in the monitor is proportional to this number. Therefore, we'd + * like to keep it as small as possible to reduce monitor overhead (using + * SVGA_VRAM_MAX_SIZE for this increases the size of the shared area by over + * 4k!). + * + * NB: For compatibility reasons, this value must be greater than 0xff0000. + * See bug 335072. + */ +#define SVGA_FB_MAX_TRACEABLE_SIZE 0x1000000 + +#define SVGA_MAX_PSEUDOCOLOR_DEPTH 8 +#define SVGA_MAX_PSEUDOCOLORS (1 << SVGA_MAX_PSEUDOCOLOR_DEPTH) +#define SVGA_NUM_PALETTE_REGS (3 * SVGA_MAX_PSEUDOCOLORS) + +#define SVGA_MAGIC 0x900000UL +#define SVGA_MAKE_ID(ver) (SVGA_MAGIC << 8 | (ver)) + +/* Version 2 let the address of the frame buffer be unsigned on Win32 */ +#define SVGA_VERSION_2 2 +#define SVGA_ID_2 SVGA_MAKE_ID(SVGA_VERSION_2) + +/* Version 1 has new registers starting with SVGA_REG_CAPABILITIES so + PALETTE_BASE has moved */ +#define SVGA_VERSION_1 1 +#define SVGA_ID_1 SVGA_MAKE_ID(SVGA_VERSION_1) + +/* Version 0 is the initial version */ +#define SVGA_VERSION_0 0 +#define SVGA_ID_0 SVGA_MAKE_ID(SVGA_VERSION_0) + +/* "Invalid" value for all SVGA IDs. (Version ID, screen object ID, surface ID...) */ +#define SVGA_ID_INVALID 0xFFFFFFFF + +/* Port offsets, relative to BAR0 */ +#define SVGA_INDEX_PORT 0x0 +#define SVGA_VALUE_PORT 0x1 +#define SVGA_BIOS_PORT 0x2 +#define SVGA_IRQSTATUS_PORT 0x8 + +/* + * Interrupt source flags for IRQSTATUS_PORT and IRQMASK. + * + * Interrupts are only supported when the + * SVGA_CAP_IRQMASK capability is present. + */ +#define SVGA_IRQFLAG_ANY_FENCE 0x1 /* Any fence was passed */ +#define SVGA_IRQFLAG_FIFO_PROGRESS 0x2 /* Made forward progress in the FIFO */ +#define SVGA_IRQFLAG_FENCE_GOAL 0x4 /* SVGA_FIFO_FENCE_GOAL reached */ + +/* + * Registers + */ + +enum { + SVGA_REG_ID = 0, + SVGA_REG_ENABLE = 1, + SVGA_REG_WIDTH = 2, + SVGA_REG_HEIGHT = 3, + SVGA_REG_MAX_WIDTH = 4, + SVGA_REG_MAX_HEIGHT = 5, + SVGA_REG_DEPTH = 6, + SVGA_REG_BITS_PER_PIXEL = 7, /* Current bpp in the guest */ + SVGA_REG_PSEUDOCOLOR = 8, + SVGA_REG_RED_MASK = 9, + SVGA_REG_GREEN_MASK = 10, + SVGA_REG_BLUE_MASK = 11, + SVGA_REG_BYTES_PER_LINE = 12, + SVGA_REG_FB_START = 13, /* (Deprecated) */ + SVGA_REG_FB_OFFSET = 14, + SVGA_REG_VRAM_SIZE = 15, + SVGA_REG_FB_SIZE = 16, + + /* ID 0 implementation only had the above registers, then the palette */ + + SVGA_REG_CAPABILITIES = 17, + SVGA_REG_MEM_START = 18, /* (Deprecated) */ + SVGA_REG_MEM_SIZE = 19, + SVGA_REG_CONFIG_DONE = 20, /* Set when memory area configured */ + SVGA_REG_SYNC = 21, /* See "FIFO Synchronization Registers" */ + SVGA_REG_BUSY = 22, /* See "FIFO Synchronization Registers" */ + SVGA_REG_GUEST_ID = 23, /* Set guest OS identifier */ + SVGA_REG_CURSOR_ID = 24, /* (Deprecated) */ + SVGA_REG_CURSOR_X = 25, /* (Deprecated) */ + SVGA_REG_CURSOR_Y = 26, /* (Deprecated) */ + SVGA_REG_CURSOR_ON = 27, /* (Deprecated) */ + SVGA_REG_HOST_BITS_PER_PIXEL = 28, /* (Deprecated) */ + SVGA_REG_SCRATCH_SIZE = 29, /* Number of scratch registers */ + SVGA_REG_MEM_REGS = 30, /* Number of FIFO registers */ + SVGA_REG_NUM_DISPLAYS = 31, /* (Deprecated) */ + SVGA_REG_PITCHLOCK = 32, /* Fixed pitch for all modes */ + SVGA_REG_IRQMASK = 33, /* Interrupt mask */ + + /* Legacy multi-monitor support */ + SVGA_REG_NUM_GUEST_DISPLAYS = 34,/* Number of guest displays in X/Y direction */ + SVGA_REG_DISPLAY_ID = 35, /* Display ID for the following display attributes */ + SVGA_REG_DISPLAY_IS_PRIMARY = 36,/* Whether this is a primary display */ + SVGA_REG_DISPLAY_POSITION_X = 37,/* The display position x */ + SVGA_REG_DISPLAY_POSITION_Y = 38,/* The display position y */ + SVGA_REG_DISPLAY_WIDTH = 39, /* The display's width */ + SVGA_REG_DISPLAY_HEIGHT = 40, /* The display's height */ + + /* See "Guest memory regions" below. */ + SVGA_REG_GMR_ID = 41, + SVGA_REG_GMR_DESCRIPTOR = 42, + SVGA_REG_GMR_MAX_IDS = 43, + SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH = 44, + + SVGA_REG_TRACES = 45, /* Enable trace-based updates even when FIFO is on */ + SVGA_REG_TOP = 46, /* Must be 1 more than the last register */ + + SVGA_PALETTE_BASE = 1024, /* Base of SVGA color map */ + /* Next 768 (== 256*3) registers exist for colormap */ + + SVGA_SCRATCH_BASE = SVGA_PALETTE_BASE + SVGA_NUM_PALETTE_REGS + /* Base of scratch registers */ + /* Next reg[SVGA_REG_SCRATCH_SIZE] registers exist for scratch usage: + First 4 are reserved for VESA BIOS Extension; any remaining are for + the use of the current SVGA driver. */ +}; + + +/* + * Guest memory regions (GMRs): + * + * This is a new memory mapping feature available in SVGA devices + * which have the SVGA_CAP_GMR bit set. Previously, there were two + * fixed memory regions available with which to share data between the + * device and the driver: the FIFO ('MEM') and the framebuffer. GMRs + * are our name for an extensible way of providing arbitrary DMA + * buffers for use between the driver and the SVGA device. They are a + * new alternative to framebuffer memory, usable for both 2D and 3D + * graphics operations. + * + * Since GMR mapping must be done synchronously with guest CPU + * execution, we use a new pair of SVGA registers: + * + * SVGA_REG_GMR_ID -- + * + * Read/write. + * This register holds the 32-bit ID (a small positive integer) + * of a GMR to create, delete, or redefine. Writing this register + * has no side-effects. + * + * SVGA_REG_GMR_DESCRIPTOR -- + * + * Write-only. + * Writing this register will create, delete, or redefine the GMR + * specified by the above ID register. If this register is zero, + * the GMR is deleted. Any pointers into this GMR (including those + * currently being processed by FIFO commands) will be + * synchronously invalidated. + * + * If this register is nonzero, it must be the physical page + * number (PPN) of a data structure which describes the physical + * layout of the memory region this GMR should describe. The + * descriptor structure will be read synchronously by the SVGA + * device when this register is written. The descriptor need not + * remain allocated for the lifetime of the GMR. + * + * The guest driver should write SVGA_REG_GMR_ID first, then + * SVGA_REG_GMR_DESCRIPTOR. + * + * SVGA_REG_GMR_MAX_IDS -- + * + * Read-only. + * The SVGA device may choose to support a maximum number of + * user-defined GMR IDs. This register holds the number of supported + * IDs. (The maximum supported ID plus 1) + * + * SVGA_REG_GMR_MAX_DESCRIPTOR_LENGTH -- + * + * Read-only. + * The SVGA device may choose to put a limit on the total number + * of SVGAGuestMemDescriptor structures it will read when defining + * a single GMR. + * + * The descriptor structure is an array of SVGAGuestMemDescriptor + * structures. Each structure may do one of three things: + * + * - Terminate the GMR descriptor list. + * (ppn==0, numPages==0) + * + * - Add a PPN or range of PPNs to the GMR's virtual address space. + * (ppn != 0, numPages != 0) + * + * - Provide the PPN of the next SVGAGuestMemDescriptor, in order to + * support multi-page GMR descriptor tables without forcing the + * driver to allocate physically contiguous memory. + * (ppn != 0, numPages == 0) + * + * Note that each physical page of SVGAGuestMemDescriptor structures + * can describe at least 2MB of guest memory. If the driver needs to + * use more than one page of descriptor structures, it must use one of + * its SVGAGuestMemDescriptors to point to an additional page. The + * device will never automatically cross a page boundary. + * + * Once the driver has described a GMR, it is immediately available + * for use via any FIFO command that uses an SVGAGuestPtr structure. + * These pointers include a GMR identifier plus an offset into that + * GMR. + * + * The driver must check the SVGA_CAP_GMR bit before using the GMR + * registers. + */ + +/* + * Special GMR IDs, allowing SVGAGuestPtrs to point to framebuffer + * memory as well. In the future, these IDs could even be used to + * allow legacy memory regions to be redefined by the guest as GMRs. + * + * Using the guest framebuffer (GFB) at BAR1 for general purpose DMA + * is being phased out. Please try to use user-defined GMRs whenever + * possible. + */ +#define SVGA_GMR_NULL ((uint32) -1) +#define SVGA_GMR_FRAMEBUFFER ((uint32) -2) // Guest Framebuffer (GFB) + +typedef +struct SVGAGuestMemDescriptor { + uint32 ppn; + uint32 numPages; +} SVGAGuestMemDescriptor; + +typedef +struct SVGAGuestPtr { + uint32 gmrId; + uint32 offset; +} SVGAGuestPtr; + + +/* + * SVGAGMRImageFormat -- + * + * This is a packed representation of the source 2D image format + * for a GMR-to-screen blit. Currently it is defined as an encoding + * of the screen's color depth and bits-per-pixel, however, 16 bits + * are reserved for future use to identify other encodings (such as + * RGBA or higher-precision images). + * + * Currently supported formats: + * + * bpp depth Format Name + * --- ----- ----------- + * 32 24 32-bit BGRX + * 24 24 24-bit BGR + * 16 16 RGB 5-6-5 + * 16 15 RGB 5-5-5 + * + */ + +typedef +struct SVGAGMRImageFormat { + union { + struct { + uint32 bitsPerPixel : 8; + uint32 colorDepth : 8; + uint32 reserved : 16; // Must be zero + }; + + uint32 value; + }; +} SVGAGMRImageFormat; + +/* + * SVGAColorBGRX -- + * + * A 24-bit color format (BGRX), which does not depend on the + * format of the legacy guest framebuffer (GFB) or the current + * GMRFB state. + */ + +typedef +struct SVGAColorBGRX { + union { + struct { + uint32 b : 8; + uint32 g : 8; + uint32 r : 8; + uint32 x : 8; // Unused + }; + + uint32 value; + }; +} SVGAColorBGRX; + + +/* + * SVGASignedRect -- + * SVGASignedPoint -- + * + * Signed rectangle and point primitives. These are used by the new + * 2D primitives for drawing to Screen Objects, which can occupy a + * signed virtual coordinate space. + * + * SVGASignedRect specifies a half-open interval: the (left, top) + * pixel is part of the rectangle, but the (right, bottom) pixel is + * not. + */ + +typedef +struct SVGASignedRect { + int32 left; + int32 top; + int32 right; + int32 bottom; +} SVGASignedRect; + +typedef +struct SVGASignedPoint { + int32 x; + int32 y; +} SVGASignedPoint; + + +/* + * Capabilities + * + * Note the holes in the bitfield. Missing bits have been deprecated, + * and must not be reused. Those capabilities will never be reported + * by new versions of the SVGA device. + */ + +#define SVGA_CAP_NONE 0x00000000 +#define SVGA_CAP_RECT_COPY 0x00000002 +#define SVGA_CAP_CURSOR 0x00000020 +#define SVGA_CAP_CURSOR_BYPASS 0x00000040 // Legacy (Use Cursor Bypass 3 instead) +#define SVGA_CAP_CURSOR_BYPASS_2 0x00000080 // Legacy (Use Cursor Bypass 3 instead) +#define SVGA_CAP_8BIT_EMULATION 0x00000100 +#define SVGA_CAP_ALPHA_CURSOR 0x00000200 +#define SVGA_CAP_3D 0x00004000 +#define SVGA_CAP_EXTENDED_FIFO 0x00008000 +#define SVGA_CAP_MULTIMON 0x00010000 // Legacy multi-monitor support +#define SVGA_CAP_PITCHLOCK 0x00020000 +#define SVGA_CAP_IRQMASK 0x00040000 +#define SVGA_CAP_DISPLAY_TOPOLOGY 0x00080000 // Legacy multi-monitor support +#define SVGA_CAP_GMR 0x00100000 +#define SVGA_CAP_TRACES 0x00200000 + + +/* + * FIFO register indices. + * + * The FIFO is a chunk of device memory mapped into guest physmem. It + * is always treated as 32-bit words. + * + * The guest driver gets to decide how to partition it between + * - FIFO registers (there are always at least 4, specifying where the + * following data area is and how much data it contains; there may be + * more registers following these, depending on the FIFO protocol + * version in use) + * - FIFO data, written by the guest and slurped out by the VMX. + * These indices are 32-bit word offsets into the FIFO. + */ + +enum { + /* + * Block 1 (basic registers): The originally defined FIFO registers. + * These exist and are valid for all versions of the FIFO protocol. + */ + + SVGA_FIFO_MIN = 0, + SVGA_FIFO_MAX, /* The distance from MIN to MAX must be at least 10K */ + SVGA_FIFO_NEXT_CMD, + SVGA_FIFO_STOP, + + /* + * Block 2 (extended registers): Mandatory registers for the extended + * FIFO. These exist if the SVGA caps register includes + * SVGA_CAP_EXTENDED_FIFO; some of them are valid only if their + * associated capability bit is enabled. + * + * Note that when originally defined, SVGA_CAP_EXTENDED_FIFO implied + * support only for (FIFO registers) CAPABILITIES, FLAGS, and FENCE. + * This means that the guest has to test individually (in most cases + * using FIFO caps) for the presence of registers after this; the VMX + * can define "extended FIFO" to mean whatever it wants, and currently + * won't enable it unless there's room for that set and much more. + */ + + SVGA_FIFO_CAPABILITIES = 4, + SVGA_FIFO_FLAGS, + // Valid with SVGA_FIFO_CAP_FENCE: + SVGA_FIFO_FENCE, + + /* + * Block 3a (optional extended registers): Additional registers for the + * extended FIFO, whose presence isn't actually implied by + * SVGA_CAP_EXTENDED_FIFO; these exist if SVGA_FIFO_MIN is high enough to + * leave room for them. + * + * These in block 3a, the VMX currently considers mandatory for the + * extended FIFO. + */ + + // Valid if exists (i.e. if extended FIFO enabled): + SVGA_FIFO_3D_HWVERSION, /* See SVGA3dHardwareVersion in svga3d_reg.h */ + // Valid with SVGA_FIFO_CAP_PITCHLOCK: + SVGA_FIFO_PITCHLOCK, + + // Valid with SVGA_FIFO_CAP_CURSOR_BYPASS_3: + SVGA_FIFO_CURSOR_ON, /* Cursor bypass 3 show/hide register */ + SVGA_FIFO_CURSOR_X, /* Cursor bypass 3 x register */ + SVGA_FIFO_CURSOR_Y, /* Cursor bypass 3 y register */ + SVGA_FIFO_CURSOR_COUNT, /* Incremented when any of the other 3 change */ + SVGA_FIFO_CURSOR_LAST_UPDATED,/* Last time the host updated the cursor */ + + // Valid with SVGA_FIFO_CAP_RESERVE: + SVGA_FIFO_RESERVED, /* Bytes past NEXT_CMD with real contents */ + + /* + * Valid with SVGA_FIFO_CAP_SCREEN_OBJECT: + * + * By default this is SVGA_ID_INVALID, to indicate that the cursor + * coordinates are specified relative to the virtual root. If this + * is set to a specific screen ID, cursor position is reinterpreted + * as a signed offset relative to that screen's origin. This is the + * only way to place the cursor on a non-rooted screen. + */ + SVGA_FIFO_CURSOR_SCREEN_ID, + + /* + * XXX: The gap here, up until SVGA_FIFO_3D_CAPS, can be used for new + * registers, but this must be done carefully and with judicious use of + * capability bits, since comparisons based on SVGA_FIFO_MIN aren't + * enough to tell you whether the register exists: we've shipped drivers + * and products that used SVGA_FIFO_3D_CAPS but didn't know about some of + * the earlier ones. The actual order of introduction was: + * - PITCHLOCK + * - 3D_CAPS + * - CURSOR_* (cursor bypass 3) + * - RESERVED + * So, code that wants to know whether it can use any of the + * aforementioned registers, or anything else added after PITCHLOCK and + * before 3D_CAPS, needs to reason about something other than + * SVGA_FIFO_MIN. + */ + + /* + * 3D caps block space; valid with 3D hardware version >= + * SVGA3D_HWVERSION_WS6_B1. + */ + SVGA_FIFO_3D_CAPS = 32, + SVGA_FIFO_3D_CAPS_LAST = 32 + 255, + + /* + * End of VMX's current definition of "extended-FIFO registers". + * Registers before here are always enabled/disabled as a block; either + * the extended FIFO is enabled and includes all preceding registers, or + * it's disabled entirely. + * + * Block 3b (truly optional extended registers): Additional registers for + * the extended FIFO, which the VMX already knows how to enable and + * disable with correct granularity. + * + * Registers after here exist if and only if the guest SVGA driver + * sets SVGA_FIFO_MIN high enough to leave room for them. + */ + + // Valid if register exists: + SVGA_FIFO_GUEST_3D_HWVERSION, /* Guest driver's 3D version */ + SVGA_FIFO_FENCE_GOAL, /* Matching target for SVGA_IRQFLAG_FENCE_GOAL */ + SVGA_FIFO_BUSY, /* See "FIFO Synchronization Registers" */ + + /* + * Always keep this last. This defines the maximum number of + * registers we know about. At power-on, this value is placed in + * the SVGA_REG_MEM_REGS register, and we expect the guest driver + * to allocate this much space in FIFO memory for registers. + */ + SVGA_FIFO_NUM_REGS +}; + + +/* + * Definition of registers included in extended FIFO support. + * + * The guest SVGA driver gets to allocate the FIFO between registers + * and data. It must always allocate at least 4 registers, but old + * drivers stopped there. + * + * The VMX will enable extended FIFO support if and only if the guest + * left enough room for all registers defined as part of the mandatory + * set for the extended FIFO. + * + * Note that the guest drivers typically allocate the FIFO only at + * initialization time, not at mode switches, so it's likely that the + * number of FIFO registers won't change without a reboot. + * + * All registers less than this value are guaranteed to be present if + * svgaUser->fifo.extended is set. Any later registers must be tested + * individually for compatibility at each use (in the VMX). + * + * This value is used only by the VMX, so it can change without + * affecting driver compatibility; keep it that way? + */ +#define SVGA_FIFO_EXTENDED_MANDATORY_REGS (SVGA_FIFO_3D_CAPS_LAST + 1) + + +/* + * FIFO Synchronization Registers + * + * This explains the relationship between the various FIFO + * sync-related registers in IOSpace and in FIFO space. + * + * SVGA_REG_SYNC -- + * + * The SYNC register can be used in two different ways by the guest: + * + * 1. If the guest wishes to fully sync (drain) the FIFO, + * it will write once to SYNC then poll on the BUSY + * register. The FIFO is sync'ed once BUSY is zero. + * + * 2. If the guest wants to asynchronously wake up the host, + * it will write once to SYNC without polling on BUSY. + * Ideally it will do this after some new commands have + * been placed in the FIFO, and after reading a zero + * from SVGA_FIFO_BUSY. + * + * (1) is the original behaviour that SYNC was designed to + * support. Originally, a write to SYNC would implicitly + * trigger a read from BUSY. This causes us to synchronously + * process the FIFO. + * + * This behaviour has since been changed so that writing SYNC + * will *not* implicitly cause a read from BUSY. Instead, it + * makes a channel call which asynchronously wakes up the MKS + * thread. + * + * New guests can use this new behaviour to implement (2) + * efficiently. This lets guests get the host's attention + * without waiting for the MKS to poll, which gives us much + * better CPU utilization on SMP hosts and on UP hosts while + * we're blocked on the host GPU. + * + * Old guests shouldn't notice the behaviour change. SYNC was + * never guaranteed to process the entire FIFO, since it was + * bounded to a particular number of CPU cycles. Old guests will + * still loop on the BUSY register until the FIFO is empty. + * + * Writing to SYNC currently has the following side-effects: + * + * - Sets SVGA_REG_BUSY to TRUE (in the monitor) + * - Asynchronously wakes up the MKS thread for FIFO processing + * - The value written to SYNC is recorded as a "reason", for + * stats purposes. + * + * If SVGA_FIFO_BUSY is available, drivers are advised to only + * write to SYNC if SVGA_FIFO_BUSY is FALSE. Drivers should set + * SVGA_FIFO_BUSY to TRUE after writing to SYNC. The MKS will + * eventually set SVGA_FIFO_BUSY on its own, but this approach + * lets the driver avoid sending multiple asynchronous wakeup + * messages to the MKS thread. + * + * SVGA_REG_BUSY -- + * + * This register is set to TRUE when SVGA_REG_SYNC is written, + * and it reads as FALSE when the FIFO has been completely + * drained. + * + * Every read from this register causes us to synchronously + * process FIFO commands. There is no guarantee as to how many + * commands each read will process. + * + * CPU time spent processing FIFO commands will be billed to + * the guest. + * + * New drivers should avoid using this register unless they + * need to guarantee that the FIFO is completely drained. It + * is overkill for performing a sync-to-fence. Older drivers + * will use this register for any type of synchronization. + * + * SVGA_FIFO_BUSY -- + * + * This register is a fast way for the guest driver to check + * whether the FIFO is already being processed. It reads and + * writes at normal RAM speeds, with no monitor intervention. + * + * If this register reads as TRUE, the host is guaranteeing that + * any new commands written into the FIFO will be noticed before + * the MKS goes back to sleep. + * + * If this register reads as FALSE, no such guarantee can be + * made. + * + * The guest should use this register to quickly determine + * whether or not it needs to wake up the host. If the guest + * just wrote a command or group of commands that it would like + * the host to begin processing, it should: + * + * 1. Read SVGA_FIFO_BUSY. If it reads as TRUE, no further + * action is necessary. + * + * 2. Write TRUE to SVGA_FIFO_BUSY. This informs future guest + * code that we've already sent a SYNC to the host and we + * don't need to send a duplicate. + * + * 3. Write a reason to SVGA_REG_SYNC. This will send an + * asynchronous wakeup to the MKS thread. + */ + + +/* + * FIFO Capabilities + * + * Fence -- Fence register and command are supported + * Accel Front -- Front buffer only commands are supported + * Pitch Lock -- Pitch lock register is supported + * Video -- SVGA Video overlay units are supported + * Escape -- Escape command is supported + * + * XXX: Add longer descriptions for each capability, including a list + * of the new features that each capability provides. + * + * SVGA_FIFO_CAP_SCREEN_OBJECT -- + * + * Provides dynamic multi-screen rendering, for improved Unity and + * multi-monitor modes. With Screen Object, the guest can + * dynamically create and destroy 'screens', which can represent + * Unity windows or virtual monitors. Screen Object also provides + * strong guarantees that DMA operations happen only when + * guest-initiated. Screen Object deprecates the BAR1 guest + * framebuffer (GFB) and all commands that work only with the GFB. + * + * New registers: + * FIFO_CURSOR_SCREEN_ID, VIDEO_DATA_GMRID, VIDEO_DST_SCREEN_ID + * + * New 2D commands: + * DEFINE_SCREEN, DESTROY_SCREEN, DEFINE_GMRFB, BLIT_GMRFB_TO_SCREEN, + * BLIT_SCREEN_TO_GMRFB, ANNOTATION_FILL, ANNOTATION_COPY + * + * New 3D commands: + * BLIT_SURFACE_TO_SCREEN + * + * New guarantees: + * + * - The host will not read or write guest memory, including the GFB, + * except when explicitly initiated by a DMA command. + * + * - All DMA, including legacy DMA like UPDATE and PRESENT_READBACK, + * is guaranteed to complete before any subsequent FENCEs. + * + * - All legacy commands which affect a Screen (UPDATE, PRESENT, + * PRESENT_READBACK) as well as new Screen blit commands will + * all behave consistently as blits, and memory will be read + * or written in FIFO order. + * + * For example, if you PRESENT from one SVGA3D surface to multiple + * places on the screen, the data copied will always be from the + * SVGA3D surface at the time the PRESENT was issued in the FIFO. + * This was not necessarily true on devices without Screen Object. + * + * This means that on devices that support Screen Object, the + * PRESENT_READBACK command should not be necessary unless you + * actually want to read back the results of 3D rendering into + * system memory. (And for that, the BLIT_SCREEN_TO_GMRFB + * command provides a strict superset of functionality.) + * + * - When a screen is resized, either using Screen Object commands or + * legacy multimon registers, its contents are preserved. + */ + +#define SVGA_FIFO_CAP_NONE 0 +#define SVGA_FIFO_CAP_FENCE (1<<0) +#define SVGA_FIFO_CAP_ACCELFRONT (1<<1) +#define SVGA_FIFO_CAP_PITCHLOCK (1<<2) +#define SVGA_FIFO_CAP_VIDEO (1<<3) +#define SVGA_FIFO_CAP_CURSOR_BYPASS_3 (1<<4) +#define SVGA_FIFO_CAP_ESCAPE (1<<5) +#define SVGA_FIFO_CAP_RESERVE (1<<6) +#define SVGA_FIFO_CAP_SCREEN_OBJECT (1<<7) + + +/* + * FIFO Flags + * + * Accel Front -- Driver should use front buffer only commands + */ + +#define SVGA_FIFO_FLAG_NONE 0 +#define SVGA_FIFO_FLAG_ACCELFRONT (1<<0) +#define SVGA_FIFO_FLAG_RESERVED (1<<31) // Internal use only + +/* + * FIFO reservation sentinel value + */ + +#define SVGA_FIFO_RESERVED_UNKNOWN 0xffffffff + + +/* + * Video overlay support + */ + +#define SVGA_NUM_OVERLAY_UNITS 32 + + +/* + * Video capabilities that the guest is currently using + */ + +#define SVGA_VIDEO_FLAG_COLORKEY 0x0001 + + +/* + * Offsets for the video overlay registers + */ + +enum { + SVGA_VIDEO_ENABLED = 0, + SVGA_VIDEO_FLAGS, + SVGA_VIDEO_DATA_OFFSET, + SVGA_VIDEO_FORMAT, + SVGA_VIDEO_COLORKEY, + SVGA_VIDEO_SIZE, // Deprecated + SVGA_VIDEO_WIDTH, + SVGA_VIDEO_HEIGHT, + SVGA_VIDEO_SRC_X, + SVGA_VIDEO_SRC_Y, + SVGA_VIDEO_SRC_WIDTH, + SVGA_VIDEO_SRC_HEIGHT, + SVGA_VIDEO_DST_X, // Signed int32 + SVGA_VIDEO_DST_Y, // Signed int32 + SVGA_VIDEO_DST_WIDTH, + SVGA_VIDEO_DST_HEIGHT, + SVGA_VIDEO_PITCH_1, + SVGA_VIDEO_PITCH_2, + SVGA_VIDEO_PITCH_3, + SVGA_VIDEO_DATA_GMRID, // Optional, defaults to SVGA_GMR_FRAMEBUFFER + SVGA_VIDEO_DST_SCREEN_ID, // Optional, defaults to virtual coords (SVGA_ID_INVALID) + SVGA_VIDEO_NUM_REGS +}; + + +/* + * SVGA Overlay Units + * + * width and height relate to the entire source video frame. + * srcX, srcY, srcWidth and srcHeight represent subset of the source + * video frame to be displayed. + */ + +typedef struct SVGAOverlayUnit { + uint32 enabled; + uint32 flags; + uint32 dataOffset; + uint32 format; + uint32 colorKey; + uint32 size; + uint32 width; + uint32 height; + uint32 srcX; + uint32 srcY; + uint32 srcWidth; + uint32 srcHeight; + int32 dstX; + int32 dstY; + uint32 dstWidth; + uint32 dstHeight; + uint32 pitches[3]; + uint32 dataGMRId; + uint32 dstScreenId; +} SVGAOverlayUnit; + + +/* + * SVGAScreenObject -- + * + * This is a new way to represent a guest's multi-monitor screen or + * Unity window. Screen objects are only supported if the + * SVGA_FIFO_CAP_SCREEN_OBJECT capability bit is set. + * + * If Screen Objects are supported, they can be used to fully + * replace the functionality provided by the framebuffer registers + * (SVGA_REG_WIDTH, HEIGHT, etc.) and by SVGA_CAP_DISPLAY_TOPOLOGY. + * + * The screen object is a struct with guaranteed binary + * compatibility. New flags can be added, and the struct may grow, + * but existing fields must retain their meaning. + * + */ + +#define SVGA_SCREEN_HAS_ROOT (1 << 0) // Screen is present in the virtual coord space +#define SVGA_SCREEN_IS_PRIMARY (1 << 1) // Guest considers this screen to be 'primary' +#define SVGA_SCREEN_FULLSCREEN_HINT (1 << 2) // Guest is running a fullscreen app here + +typedef +struct SVGAScreenObject { + uint32 structSize; // sizeof(SVGAScreenObject) + uint32 id; + uint32 flags; + struct { + uint32 width; + uint32 height; + } size; + struct { + int32 x; + int32 y; + } root; // Only used if SVGA_SCREEN_HAS_ROOT is set. +} SVGAScreenObject; + + +/* + * Commands in the command FIFO: + * + * Command IDs defined below are used for the traditional 2D FIFO + * communication (not all commands are available for all versions of the + * SVGA FIFO protocol). + * + * Note the holes in the command ID numbers: These commands have been + * deprecated, and the old IDs must not be reused. + * + * Command IDs from 1000 to 1999 are reserved for use by the SVGA3D + * protocol. + * + * Each command's parameters are described by the comments and + * structs below. + */ + +typedef enum { + SVGA_CMD_INVALID_CMD = 0, + SVGA_CMD_UPDATE = 1, + SVGA_CMD_RECT_COPY = 3, + SVGA_CMD_DEFINE_CURSOR = 19, + SVGA_CMD_DEFINE_ALPHA_CURSOR = 22, + SVGA_CMD_UPDATE_VERBOSE = 25, + SVGA_CMD_FRONT_ROP_FILL = 29, + SVGA_CMD_FENCE = 30, + SVGA_CMD_ESCAPE = 33, + SVGA_CMD_DEFINE_SCREEN = 34, + SVGA_CMD_DESTROY_SCREEN = 35, + SVGA_CMD_DEFINE_GMRFB = 36, + SVGA_CMD_BLIT_GMRFB_TO_SCREEN = 37, + SVGA_CMD_BLIT_SCREEN_TO_GMRFB = 38, + SVGA_CMD_ANNOTATION_FILL = 39, + SVGA_CMD_ANNOTATION_COPY = 40, + SVGA_CMD_MAX +} SVGAFifoCmdId; + +#define SVGA_CMD_MAX_ARGS 64 + + +/* + * SVGA_CMD_UPDATE -- + * + * This is a DMA transfer which copies from the Guest Framebuffer + * (GFB) at BAR1 + SVGA_REG_FB_OFFSET to any screens which + * intersect with the provided virtual rectangle. + * + * This command does not support using arbitrary guest memory as a + * data source- it only works with the pre-defined GFB memory. + * This command also does not support signed virtual coordinates. + * If you have defined screens (using SVGA_CMD_DEFINE_SCREEN) with + * negative root x/y coordinates, the negative portion of those + * screens will not be reachable by this command. + * + * This command is not necessary when using framebuffer + * traces. Traces are automatically enabled if the SVGA FIFO is + * disabled, and you may explicitly enable/disable traces using + * SVGA_REG_TRACES. With traces enabled, any write to the GFB will + * automatically act as if a subsequent SVGA_CMD_UPDATE was issued. + * + * Traces and SVGA_CMD_UPDATE are the only supported ways to render + * pseudocolor screen updates. The newer Screen Object commands + * only support true color formats. + * + * Availability: + * Always available. + */ + +typedef +struct { + uint32 x; + uint32 y; + uint32 width; + uint32 height; +} SVGAFifoCmdUpdate; + + +/* + * SVGA_CMD_RECT_COPY -- + * + * Perform a rectangular DMA transfer from one area of the GFB to + * another, and copy the result to any screens which intersect it. + * + * Availability: + * SVGA_CAP_RECT_COPY + */ + +typedef +struct { + uint32 srcX; + uint32 srcY; + uint32 destX; + uint32 destY; + uint32 width; + uint32 height; +} SVGAFifoCmdRectCopy; + + +/* + * SVGA_CMD_DEFINE_CURSOR -- + * + * Provide a new cursor image, as an AND/XOR mask. + * + * The recommended way to position the cursor overlay is by using + * the SVGA_FIFO_CURSOR_* registers, supported by the + * SVGA_FIFO_CAP_CURSOR_BYPASS_3 capability. + * + * Availability: + * SVGA_CAP_CURSOR + */ + +typedef +struct { + uint32 id; // Reserved, must be zero. + uint32 hotspotX; + uint32 hotspotY; + uint32 width; + uint32 height; + uint32 andMaskDepth; // Value must be 1 or equal to BITS_PER_PIXEL + uint32 xorMaskDepth; // Value must be 1 or equal to BITS_PER_PIXEL + /* + * Followed by scanline data for AND mask, then XOR mask. + * Each scanline is padded to a 32-bit boundary. + */ +} SVGAFifoCmdDefineCursor; + + +/* + * SVGA_CMD_DEFINE_ALPHA_CURSOR -- + * + * Provide a new cursor image, in 32-bit BGRA format. + * + * The recommended way to position the cursor overlay is by using + * the SVGA_FIFO_CURSOR_* registers, supported by the + * SVGA_FIFO_CAP_CURSOR_BYPASS_3 capability. + * + * Availability: + * SVGA_CAP_ALPHA_CURSOR + */ + +typedef +struct { + uint32 id; // Reserved, must be zero. + uint32 hotspotX; + uint32 hotspotY; + uint32 width; + uint32 height; + /* Followed by scanline data */ +} SVGAFifoCmdDefineAlphaCursor; + + +/* + * SVGA_CMD_UPDATE_VERBOSE -- + * + * Just like SVGA_CMD_UPDATE, but also provide a per-rectangle + * 'reason' value, an opaque cookie which is used by internal + * debugging tools. Third party drivers should not use this + * command. + * + * Availability: + * SVGA_CAP_EXTENDED_FIFO + */ + +typedef +struct { + uint32 x; + uint32 y; + uint32 width; + uint32 height; + uint32 reason; +} SVGAFifoCmdUpdateVerbose; + + +/* + * SVGA_CMD_FRONT_ROP_FILL -- + * + * This is a hint which tells the SVGA device that the driver has + * just filled a rectangular region of the GFB with a solid + * color. Instead of reading these pixels from the GFB, the device + * can assume that they all equal 'color'. This is primarily used + * for remote desktop protocols. + * + * Availability: + * SVGA_FIFO_CAP_ACCELFRONT + */ + +#define SVGA_ROP_COPY 0x03 + +typedef +struct { + uint32 color; // In the same format as the GFB + uint32 x; + uint32 y; + uint32 width; + uint32 height; + uint32 rop; // Must be SVGA_ROP_COPY +} SVGAFifoCmdFrontRopFill; + + +/* + * SVGA_CMD_FENCE -- + * + * Insert a synchronization fence. When the SVGA device reaches + * this command, it will copy the 'fence' value into the + * SVGA_FIFO_FENCE register. It will also compare the fence against + * SVGA_FIFO_FENCE_GOAL. If the fence matches the goal and the + * SVGA_IRQFLAG_FENCE_GOAL interrupt is enabled, the device will + * raise this interrupt. + * + * Availability: + * SVGA_FIFO_FENCE for this command, + * SVGA_CAP_IRQMASK for SVGA_FIFO_FENCE_GOAL. + */ + +typedef +struct { + uint32 fence; +} SVGAFifoCmdFence; + + +/* + * SVGA_CMD_ESCAPE -- + * + * Send an extended or vendor-specific variable length command. + * This is used for video overlay, third party plugins, and + * internal debugging tools. See svga_escape.h + * + * Availability: + * SVGA_FIFO_CAP_ESCAPE + */ + +typedef +struct { + uint32 nsid; + uint32 size; + /* followed by 'size' bytes of data */ +} SVGAFifoCmdEscape; + + +/* + * SVGA_CMD_DEFINE_SCREEN -- + * + * Define or redefine an SVGAScreenObject. See the description of + * SVGAScreenObject above. The video driver is responsible for + * generating new screen IDs. They should be small positive + * integers. The virtual device will have an implementation + * specific upper limit on the number of screen IDs + * supported. Drivers are responsible for recycling IDs. The first + * valid ID is zero. + * + * - Interaction with other registers: + * + * For backwards compatibility, when the GFB mode registers (WIDTH, + * HEIGHT, PITCHLOCK, BITS_PER_PIXEL) are modified, the SVGA device + * deletes all screens other than screen #0, and redefines screen + * #0 according to the specified mode. Drivers that use + * SVGA_CMD_DEFINE_SCREEN should destroy or redefine screen #0. + * + * If you use screen objects, do not use the legacy multi-mon + * registers (SVGA_REG_NUM_GUEST_DISPLAYS, SVGA_REG_DISPLAY_*). + * + * Availability: + * SVGA_FIFO_CAP_SCREEN_OBJECT + */ + +typedef +struct { + SVGAScreenObject screen; // Variable-length according to version +} SVGAFifoCmdDefineScreen; + + +/* + * SVGA_CMD_DESTROY_SCREEN -- + * + * Destroy an SVGAScreenObject. Its ID is immediately available for + * re-use. + * + * Availability: + * SVGA_FIFO_CAP_SCREEN_OBJECT + */ + +typedef +struct { + uint32 screenId; +} SVGAFifoCmdDestroyScreen; + + +/* + * SVGA_CMD_DEFINE_GMRFB -- + * + * This command sets a piece of SVGA device state called the + * Guest Memory Region Framebuffer, or GMRFB. The GMRFB is a + * piece of light-weight state which identifies the location and + * format of an image in guest memory or in BAR1. The GMRFB has + * an arbitrary size, and it doesn't need to match the geometry + * of the GFB or any screen object. + * + * The GMRFB can be redefined as often as you like. You could + * always use the same GMRFB, you could redefine it before + * rendering from a different guest screen, or you could even + * redefine it before every blit. + * + * There are multiple ways to use this command. The simplest way is + * to use it to move the framebuffer either to elsewhere in the GFB + * (BAR1) memory region, or to a user-defined GMR. This lets a + * driver use a framebuffer allocated entirely out of normal system + * memory, which we encourage. + * + * Another way to use this command is to set up a ring buffer of + * updates in GFB memory. If a driver wants to ensure that no + * frames are skipped by the SVGA device, it is important that the + * driver not modify the source data for a blit until the device is + * done processing the command. One efficient way to accomplish + * this is to use a ring of small DMA buffers. Each buffer is used + * for one blit, then we move on to the next buffer in the + * ring. The FENCE mechanism is used to protect each buffer from + * re-use until the device is finished with that buffer's + * corresponding blit. + * + * This command does not affect the meaning of SVGA_CMD_UPDATE. + * UPDATEs always occur from the legacy GFB memory area. This + * command has no support for pseudocolor GMRFBs. Currently only + * true-color 15, 16, and 24-bit depths are supported. Future + * devices may expose capabilities for additional framebuffer + * formats. + * + * The default GMRFB value is undefined. Drivers must always send + * this command at least once before performing any blit from the + * GMRFB. + * + * Availability: + * SVGA_FIFO_CAP_SCREEN_OBJECT + */ + +typedef +struct { + SVGAGuestPtr ptr; + uint32 bytesPerLine; + SVGAGMRImageFormat format; +} SVGAFifoCmdDefineGMRFB; + + +/* + * SVGA_CMD_BLIT_GMRFB_TO_SCREEN -- + * + * This is a guest-to-host blit. It performs a DMA operation to + * copy a rectangular region of pixels from the current GMRFB to + * one or more Screen Objects. + * + * The destination coordinate may be specified relative to a + * screen's origin (if a screen ID is specified) or relative to the + * virtual coordinate system's origin (if the screen ID is + * SVGA_ID_INVALID). The actual destination may span zero or more + * screens, in the case of a virtual destination rect or a rect + * which extends off the edge of the specified screen. + * + * This command writes to the screen's "base layer": the underlying + * framebuffer which exists below any cursor or video overlays. No + * action is necessary to explicitly hide or update any overlays + * which exist on top of the updated region. + * + * The SVGA device is guaranteed to finish reading from the GMRFB + * by the time any subsequent FENCE commands are reached. + * + * This command consumes an annotation. See the + * SVGA_CMD_ANNOTATION_* commands for details. + * + * Availability: + * SVGA_FIFO_CAP_SCREEN_OBJECT + */ + +typedef +struct { + SVGASignedPoint srcOrigin; + SVGASignedRect destRect; + uint32 destScreenId; +} SVGAFifoCmdBlitGMRFBToScreen; + + +/* + * SVGA_CMD_BLIT_SCREEN_TO_GMRFB -- + * + * This is a host-to-guest blit. It performs a DMA operation to + * copy a rectangular region of pixels from a single Screen Object + * back to the current GMRFB. + * + * Usage note: This command should be used rarely. It will + * typically be inefficient, but it is necessary for some types of + * synchronization between 3D (GPU) and 2D (CPU) rendering into + * overlapping areas of a screen. + * + * The source coordinate is specified relative to a screen's + * origin. The provided screen ID must be valid. If any parameters + * are invalid, the resulting pixel values are undefined. + * + * This command reads the screen's "base layer". Overlays like + * video and cursor are not included, but any data which was sent + * using a blit-to-screen primitive will be available, no matter + * whether the data's original source was the GMRFB or the 3D + * acceleration hardware. + * + * Note that our guest-to-host blits and host-to-guest blits aren't + * symmetric in their current implementation. While the parameters + * are identical, host-to-guest blits are a lot less featureful. + * They do not support clipping: If the source parameters don't + * fully fit within a screen, the blit fails. They must originate + * from exactly one screen. Virtual coordinates are not directly + * supported. + * + * Host-to-guest blits do support the same set of GMRFB formats + * offered by guest-to-host blits. + * + * The SVGA device is guaranteed to finish writing to the GMRFB by + * the time any subsequent FENCE commands are reached. + * + * Availability: + * SVGA_FIFO_CAP_SCREEN_OBJECT + */ + +typedef +struct { + SVGASignedPoint destOrigin; + SVGASignedRect srcRect; + uint32 srcScreenId; +} SVGAFifoCmdBlitScreenToGMRFB; + + +/* + * SVGA_CMD_ANNOTATION_FILL -- + * + * This is a blit annotation. This command stores a small piece of + * device state which is consumed by the next blit-to-screen + * command. The state is only cleared by commands which are + * specifically documented as consuming an annotation. Other + * commands (such as ESCAPEs for debugging) may intervene between + * the annotation and its associated blit. + * + * This annotation is a promise about the contents of the next + * blit: The video driver is guaranteeing that all pixels in that + * blit will have the same value, specified here as a color in + * SVGAColorBGRX format. + * + * The SVGA device can still render the blit correctly even if it + * ignores this annotation, but the annotation may allow it to + * perform the blit more efficiently, for example by ignoring the + * source data and performing a fill in hardware. + * + * This annotation is most important for performance when the + * user's display is being remoted over a network connection. + * + * Availability: + * SVGA_FIFO_CAP_SCREEN_OBJECT + */ + +typedef +struct { + SVGAColorBGRX color; +} SVGAFifoCmdAnnotationFill; + + +/* + * SVGA_CMD_ANNOTATION_COPY -- + * + * This is a blit annotation. See SVGA_CMD_ANNOTATION_FILL for more + * information about annotations. + * + * This annotation is a promise about the contents of the next + * blit: The video driver is guaranteeing that all pixels in that + * blit will have the same value as those which already exist at an + * identically-sized region on the same or a different screen. + * + * Note that the source pixels for the COPY in this annotation are + * sampled before applying the anqnotation's associated blit. They + * are allowed to overlap with the blit's destination pixels. + * + * The copy source rectangle is specified the same way as the blit + * destination: it can be a rectangle which spans zero or more + * screens, specified relative to either a screen or to the virtual + * coordinate system's origin. If the source rectangle includes + * pixels which are not from exactly one screen, the results are + * undefined. + * + * Availability: + * SVGA_FIFO_CAP_SCREEN_OBJECT + */ + +typedef +struct { + SVGASignedPoint srcOrigin; + uint32 srcScreenId; +} SVGAFifoCmdAnnotationCopy; + +#endif diff --git a/src/gallium/drivers/svga/include/svga_types.h b/src/gallium/drivers/svga/include/svga_types.h new file mode 100644 index 0000000..7fd9bab --- /dev/null +++ b/src/gallium/drivers/svga/include/svga_types.h @@ -0,0 +1,46 @@ +/********************************************************** + * Copyright 1998-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 _SVGA_TYPES_H_ +#define _SVGA_TYPES_H_ + +#include "pipe/p_compiler.h" + +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; + +typedef uint8_t Bool; + +#endif /* _SVGA_TYPES_H_ */ + diff --git a/src/gallium/drivers/svga/svga_cmd.c b/src/gallium/drivers/svga/svga_cmd.c new file mode 100644 index 0000000..05eab8a --- /dev/null +++ b/src/gallium/drivers/svga/svga_cmd.c @@ -0,0 +1,1429 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +/** + * svga_cmd.c -- + * + * Command construction utility for the SVGA3D protocol used by + * the VMware SVGA device, based on the svgautil library. + */ + +#include "svga_winsys.h" +#include "svga_resource_buffer.h" +#include "svga_resource_texture.h" +#include "svga_surface.h" +#include "svga_cmd.h" + +/* + *---------------------------------------------------------------------- + * + * surface_to_surfaceid -- + * + * Utility function for surface ids. + * Can handle null surface. Does a surface_reallocation so you need + * to have allocated the fifo space before converting. + * + * Results: + * id is filld out. + * + * Side effects: + * One surface relocation is preformed for texture handle. + * + *---------------------------------------------------------------------- + */ + +static INLINE +void surface_to_surfaceid(struct svga_winsys_context *swc, // IN + struct pipe_surface *surface, // IN + SVGA3dSurfaceImageId *id, // OUT + unsigned flags) // IN +{ + if(surface) { + struct svga_surface *s = svga_surface(surface); + swc->surface_relocation(swc, &id->sid, s->handle, flags); + id->face = s->real_face; /* faces have the same order */ + id->mipmap = s->real_level; + } + else { + swc->surface_relocation(swc, &id->sid, NULL, flags); + id->face = 0; + id->mipmap = 0; + } +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_FIFOReserve -- + * + * Reserve space for an SVGA3D FIFO command. + * + * The 2D SVGA commands have been around for a while, so they + * have a rather asymmetric structure. The SVGA3D protocol is + * more uniform: each command begins with a header containing the + * command number and the full size. + * + * This is a convenience wrapper around SVGA_FIFOReserve. We + * reserve space for the whole command, and write the header. + * + * This function must be paired with SVGA_FIFOCommitAll(). + * + * Results: + * Returns a pointer to the space reserved for command-specific + * data. It must be 'cmdSize' bytes long. + * + * Side effects: + * Begins a FIFO reservation. + * + *---------------------------------------------------------------------- + */ + +void * +SVGA3D_FIFOReserve(struct svga_winsys_context *swc, + uint32 cmd, // IN + uint32 cmdSize, // IN + uint32 nr_relocs) // IN +{ + SVGA3dCmdHeader *header; + + header = swc->reserve(swc, sizeof *header + cmdSize, nr_relocs); + if(!header) + return NULL; + + header->id = cmd; + header->size = cmdSize; + + return &header[1]; +} + + +void +SVGA_FIFOCommitAll(struct svga_winsys_context *swc) +{ + swc->commit(swc); +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_DefineContext -- + * + * Create a new context, to be referred to with the provided ID. + * + * Context objects encapsulate all render state, and shader + * objects are per-context. + * + * Surfaces are not per-context. The same surface can be shared + * between multiple contexts, and surface operations can occur + * without a context. + * + * If the provided context ID already existed, it is redefined. + * + * Context IDs are arbitrary small non-negative integers, + * global to the entire SVGA device. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_DefineContext(struct svga_winsys_context *swc) // IN +{ + SVGA3dCmdDefineContext *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_CONTEXT_DEFINE, sizeof *cmd, 0); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + + swc->commit(swc); + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_DestroyContext -- + * + * Delete a context created with SVGA3D_DefineContext. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_DestroyContext(struct svga_winsys_context *swc) // IN +{ + SVGA3dCmdDestroyContext *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_CONTEXT_DESTROY, sizeof *cmd, 0); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + + swc->commit(swc); + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_BeginDefineSurface -- + * + * Begin a SURFACE_DEFINE command. This reserves space for it in + * the FIFO, and returns pointers to the command's faces and + * mipsizes arrays. + * + * This function must be paired with SVGA_FIFOCommitAll(). + * The faces and mipSizes arrays are initialized to zero. + * + * This creates a "surface" object in the SVGA3D device, + * with the provided surface ID (sid). Surfaces are generic + * containers for host VRAM objects like textures, vertex + * buffers, and depth/stencil buffers. + * + * Surfaces are hierarchial: + * + * - Surface may have multiple faces (for cube maps) + * + * - Each face has a list of mipmap levels + * + * - Each mipmap image may have multiple volume + * slices, if the image is three dimensional. + * + * - Each slice is a 2D array of 'blocks' + * + * - Each block may be one or more pixels. + * (Usually 1, more for DXT or YUV formats.) + * + * Surfaces are generic host VRAM objects. The SVGA3D device + * may optimize surfaces according to the format they were + * created with, but this format does not limit the ways in + * which the surface may be used. For example, a depth surface + * can be used as a texture, or a floating point image may + * be used as a vertex buffer. Some surface usages may be + * lower performance, due to software emulation, but any + * usage should work with any surface. + * + * If 'sid' is already defined, the old surface is deleted + * and this new surface replaces it. + * + * Surface IDs are arbitrary small non-negative integers, + * global to the entire SVGA device. + * + * Results: + * Returns pointers to arrays allocated in the FIFO for 'faces' + * and 'mipSizes'. + * + * Side effects: + * Begins a FIFO reservation. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_BeginDefineSurface(struct svga_winsys_context *swc, + struct svga_winsys_surface *sid, // IN + SVGA3dSurfaceFlags flags, // IN + SVGA3dSurfaceFormat format, // IN + SVGA3dSurfaceFace **faces, // OUT + SVGA3dSize **mipSizes, // OUT + uint32 numMipSizes) // IN +{ + SVGA3dCmdDefineSurface *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SURFACE_DEFINE, sizeof *cmd + + sizeof **mipSizes * numMipSizes, 1); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + swc->surface_relocation(swc, &cmd->sid, sid, SVGA_RELOC_WRITE); + cmd->surfaceFlags = flags; + cmd->format = format; + + *faces = &cmd->face[0]; + *mipSizes = (SVGA3dSize*) &cmd[1]; + + memset(*faces, 0, sizeof **faces * SVGA3D_MAX_SURFACE_FACES); + memset(*mipSizes, 0, sizeof **mipSizes * numMipSizes); + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_DefineSurface2D -- + * + * This is a simplified version of SVGA3D_BeginDefineSurface(), + * which does not support cube maps, mipmaps, or volume textures. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_DefineSurface2D(struct svga_winsys_context *swc, // IN + struct svga_winsys_surface *sid, // IN + uint32 width, // IN + uint32 height, // IN + SVGA3dSurfaceFormat format) // IN +{ + SVGA3dSize *mipSizes; + SVGA3dSurfaceFace *faces; + enum pipe_error ret; + + ret = SVGA3D_BeginDefineSurface(swc, + sid, 0, format, &faces, &mipSizes, 1); + if(ret != PIPE_OK) + return ret; + + faces[0].numMipLevels = 1; + + mipSizes[0].width = width; + mipSizes[0].height = height; + mipSizes[0].depth = 1; + + swc->commit(swc);; + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_DestroySurface -- + * + * Release the host VRAM encapsulated by a particular surface ID. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_DestroySurface(struct svga_winsys_context *swc, + struct svga_winsys_surface *sid) // IN +{ + SVGA3dCmdDestroySurface *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SURFACE_DESTROY, sizeof *cmd, 1); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + swc->surface_relocation(swc, &cmd->sid, sid, SVGA_RELOC_READ); + swc->commit(swc);; + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_BeginSurfaceDMA-- + * + * Begin a SURFACE_DMA command. This reserves space for it in + * the FIFO, and returns a pointer to the command's box array. + * This function must be paired with SVGA_FIFOCommitAll(). + * + * When the SVGA3D device asynchronously processes this FIFO + * command, a DMA operation is performed between host VRAM and + * a generic SVGAGuestPtr. The guest pointer may refer to guest + * VRAM (provided by the SVGA PCI device) or to guest system + * memory that has been set up as a Guest Memory Region (GMR) + * by the SVGA device. + * + * The guest's DMA buffer must remain valid (not freed, paged out, + * or overwritten) until the host has finished processing this + * command. The guest can determine that the host has finished + * by using the SVGA device's FIFO Fence mechanism. + * + * The guest's image buffer can be an arbitrary size and shape. + * Guest image data is interpreted according to the SVGA3D surface + * format specified when the surface was defined. + * + * The caller may optionally define the guest image's pitch. + * guestImage->pitch can either be zero (assume image is tightly + * packed) or it must be the number of bytes between vertically + * adjacent image blocks. + * + * The provided copybox list specifies which regions of the source + * image are to be copied, and where they appear on the destination. + * + * NOTE: srcx/srcy are always on the guest image and x/y are + * always on the host image, regardless of the actual transfer + * direction! + * + * For efficiency, the SVGA3D device is free to copy more data + * than specified. For example, it may round copy boxes outwards + * such that they lie on particular alignment boundaries. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_SurfaceDMA(struct svga_winsys_context *swc, + struct svga_transfer *st, // IN + SVGA3dTransferType transfer, // IN + const SVGA3dCopyBox *boxes, // IN + uint32 numBoxes) // IN +{ + struct svga_texture *texture = svga_texture(st->base.resource); + SVGA3dCmdSurfaceDMA *cmd; + SVGA3dCmdSurfaceDMASuffix *pSuffix; + uint32 boxesSize = sizeof *boxes * numBoxes; + unsigned region_flags; + unsigned surface_flags; + + if(transfer == SVGA3D_WRITE_HOST_VRAM) { + region_flags = SVGA_RELOC_READ; + surface_flags = SVGA_RELOC_WRITE; + } + else if(transfer == SVGA3D_READ_HOST_VRAM) { + region_flags = SVGA_RELOC_WRITE; + surface_flags = SVGA_RELOC_READ; + } + else { + assert(0); + return PIPE_ERROR_BAD_INPUT; + } + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SURFACE_DMA, + sizeof *cmd + boxesSize + sizeof *pSuffix, + 2); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + swc->region_relocation(swc, &cmd->guest.ptr, st->hwbuf, 0, region_flags); + cmd->guest.pitch = st->base.stride; + + swc->surface_relocation(swc, &cmd->host.sid, texture->handle, surface_flags); + cmd->host.face = st->face; /* PIPE_TEX_FACE_* and SVGA3D_CUBEFACE_* match */ + cmd->host.mipmap = st->base.level; + + cmd->transfer = transfer; + + memcpy(&cmd[1], boxes, boxesSize); + + pSuffix = (SVGA3dCmdSurfaceDMASuffix *)((uint8_t*)cmd + sizeof *cmd + boxesSize); + pSuffix->suffixSize = sizeof *pSuffix; + pSuffix->maximumOffset = st->hw_nblocksy*st->base.stride; + memset(&pSuffix->flags, 0, sizeof pSuffix->flags); + + swc->commit(swc); + + return PIPE_OK; +} + + +enum pipe_error +SVGA3D_BufferDMA(struct svga_winsys_context *swc, + struct svga_winsys_buffer *guest, + struct svga_winsys_surface *host, + SVGA3dTransferType transfer, // IN + uint32 size, // IN + uint32 guest_offset, // IN + uint32 host_offset, // IN + SVGA3dSurfaceDMAFlags flags) // IN +{ + SVGA3dCmdSurfaceDMA *cmd; + SVGA3dCopyBox *box; + SVGA3dCmdSurfaceDMASuffix *pSuffix; + unsigned region_flags; + unsigned surface_flags; + + if(transfer == SVGA3D_WRITE_HOST_VRAM) { + region_flags = SVGA_RELOC_READ; + surface_flags = SVGA_RELOC_WRITE; + } + else if(transfer == SVGA3D_READ_HOST_VRAM) { + region_flags = SVGA_RELOC_WRITE; + surface_flags = SVGA_RELOC_READ; + } + else { + assert(0); + return PIPE_ERROR_BAD_INPUT; + } + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SURFACE_DMA, + sizeof *cmd + sizeof *box + sizeof *pSuffix, + 2); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + swc->region_relocation(swc, &cmd->guest.ptr, guest, 0, region_flags); + cmd->guest.pitch = 0; + + swc->surface_relocation(swc, &cmd->host.sid, host, surface_flags); + cmd->host.face = 0; + cmd->host.mipmap = 0; + + cmd->transfer = transfer; + + box = (SVGA3dCopyBox *)&cmd[1]; + box->x = host_offset; + box->y = 0; + box->z = 0; + box->w = size; + box->h = 1; + box->d = 1; + box->srcx = guest_offset; + box->srcy = 0; + box->srcz = 0; + + pSuffix = (SVGA3dCmdSurfaceDMASuffix *)((uint8_t*)cmd + sizeof *cmd + sizeof *box); + pSuffix->suffixSize = sizeof *pSuffix; + pSuffix->maximumOffset = guest_offset + size; + pSuffix->flags = flags; + + swc->commit(swc); + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_SetRenderTarget -- + * + * Bind a surface object to a particular render target attachment + * point on the current context. Render target attachment points + * exist for color buffers, a depth buffer, and a stencil buffer. + * + * The SVGA3D device is quite lenient about the types of surfaces + * that may be used as render targets. The color buffers must + * all be the same size, but the depth and stencil buffers do not + * have to be the same size as the color buffer. All attachments + * are optional. + * + * Some combinations of render target formats may require software + * emulation, depending on the capabilities of the host graphics + * API and graphics hardware. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_SetRenderTarget(struct svga_winsys_context *swc, + SVGA3dRenderTargetType type, // IN + struct pipe_surface *surface) // IN +{ + SVGA3dCmdSetRenderTarget *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SETRENDERTARGET, sizeof *cmd, 1); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + + cmd->cid = swc->cid; + + cmd->type = type; + + surface_to_surfaceid(swc, surface, &cmd->target, SVGA_RELOC_WRITE); + + swc->commit(swc); + + return PIPE_OK; +} + + + + + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_DefineShader -- + * + * Upload the bytecode for a new shader. The bytecode is "SVGA3D + * format", which is theoretically a binary-compatible superset + * of Microsoft's DirectX shader bytecode. In practice, the + * SVGA3D bytecode doesn't yet have any extensions to DirectX's + * bytecode format. + * + * The SVGA3D device supports shader models 1.1 through 2.0. + * + * The caller chooses a shader ID (small positive integer) by + * which this shader will be identified in future commands. This + * ID is in a namespace which is per-context and per-shader-type. + * + * 'bytecodeLen' is specified in bytes. It must be a multiple of 4. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_DefineShader(struct svga_winsys_context *swc, + uint32 shid, // IN + SVGA3dShaderType type, // IN + const uint32 *bytecode, // IN + uint32 bytecodeLen) // IN +{ + SVGA3dCmdDefineShader *cmd; + + assert(bytecodeLen % 4 == 0); + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SHADER_DEFINE, sizeof *cmd + bytecodeLen, + 0); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + cmd->shid = shid; + cmd->type = type; + memcpy(&cmd[1], bytecode, bytecodeLen); + swc->commit(swc); + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_DestroyShader -- + * + * Delete a shader that was created by SVGA3D_DefineShader. If + * the shader was the current vertex or pixel shader for its + * context, rendering results are undefined until a new shader is + * bound. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_DestroyShader(struct svga_winsys_context *swc, + uint32 shid, // IN + SVGA3dShaderType type) // IN +{ + SVGA3dCmdDestroyShader *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SHADER_DESTROY, sizeof *cmd, + 0); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + cmd->shid = shid; + cmd->type = type; + swc->commit(swc); + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_SetShaderConst -- + * + * Set the value of a shader constant. + * + * Shader constants are analogous to uniform variables in GLSL, + * except that they belong to the render context rather than to + * an individual shader. + * + * Constants may have one of three types: A 4-vector of floats, + * a 4-vector of integers, or a single boolean flag. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_SetShaderConst(struct svga_winsys_context *swc, + uint32 reg, // IN + SVGA3dShaderType type, // IN + SVGA3dShaderConstType ctype, // IN + const void *value) // IN +{ + SVGA3dCmdSetShaderConst *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SET_SHADER_CONST, sizeof *cmd, + 0); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + cmd->reg = reg; + cmd->type = type; + cmd->ctype = ctype; + + switch (ctype) { + + case SVGA3D_CONST_TYPE_FLOAT: + case SVGA3D_CONST_TYPE_INT: + memcpy(&cmd->values, value, sizeof cmd->values); + break; + + case SVGA3D_CONST_TYPE_BOOL: + memset(&cmd->values, 0, sizeof cmd->values); + cmd->values[0] = *(uint32*)value; + break; + + default: + assert(0); + break; + + } + swc->commit(swc); + + return PIPE_OK; +} + + + + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_SetShader -- + * + * Switch active shaders. This binds a new vertex or pixel shader + * to the specified context. + * + * A shader ID of SVGA3D_INVALID_ID unbinds any shader, switching + * back to the fixed function vertex or pixel pipeline. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_SetShader(struct svga_winsys_context *swc, + SVGA3dShaderType type, // IN + uint32 shid) // IN +{ + SVGA3dCmdSetShader *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SET_SHADER, sizeof *cmd, + 0); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + cmd->type = type; + cmd->shid = shid; + swc->commit(swc); + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_BeginClear -- + * + * Begin a CLEAR command. This reserves space for it in the FIFO, + * and returns a pointer to the command's rectangle array. This + * function must be paired with SVGA_FIFOCommitAll(). + * + * Clear is a rendering operation which fills a list of + * rectangles with constant values on all render target types + * indicated by 'flags'. + * + * Clear is not affected by clipping, depth test, or other + * render state which affects the fragment pipeline. + * + * Results: + * None. + * + * Side effects: + * May write to attached render target surfaces. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_BeginClear(struct svga_winsys_context *swc, + SVGA3dClearFlag flags, // IN + uint32 color, // IN + float depth, // IN + uint32 stencil, // IN + SVGA3dRect **rects, // OUT + uint32 numRects) // IN +{ + SVGA3dCmdClear *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_CLEAR, + sizeof *cmd + sizeof **rects * numRects, + 0); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + cmd->clearFlag = flags; + cmd->color = color; + cmd->depth = depth; + cmd->stencil = stencil; + *rects = (SVGA3dRect*) &cmd[1]; + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_ClearRect -- + * + * This is a simplified version of SVGA3D_BeginClear(). + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_ClearRect(struct svga_winsys_context *swc, + SVGA3dClearFlag flags, // IN + uint32 color, // IN + float depth, // IN + uint32 stencil, // IN + uint32 x, // IN + uint32 y, // IN + uint32 w, // IN + uint32 h) // IN +{ + SVGA3dRect *rect; + enum pipe_error ret; + + ret = SVGA3D_BeginClear(swc, flags, color, depth, stencil, &rect, 1); + if(ret != PIPE_OK) + return PIPE_ERROR_OUT_OF_MEMORY; + + memset(rect, 0, sizeof *rect); + rect->x = x; + rect->y = y; + rect->w = w; + rect->h = h; + swc->commit(swc); + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_BeginDrawPrimitives -- + * + * Begin a DRAW_PRIMITIVES command. This reserves space for it in + * the FIFO, and returns a pointer to the command's arrays. + * This function must be paired with SVGA_FIFOCommitAll(). + * + * Drawing commands consist of two variable-length arrays: + * SVGA3dVertexDecl elements declare a set of vertex buffers to + * use while rendering, and SVGA3dPrimitiveRange elements specify + * groups of primitives each with an optional index buffer. + * + * The decls and ranges arrays are initialized to zero. + * + * Results: + * None. + * + * Side effects: + * May write to attached render target surfaces. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_BeginDrawPrimitives(struct svga_winsys_context *swc, + SVGA3dVertexDecl **decls, // OUT + uint32 numVertexDecls, // IN + SVGA3dPrimitiveRange **ranges, // OUT + uint32 numRanges) // IN +{ + SVGA3dCmdDrawPrimitives *cmd; + SVGA3dVertexDecl *declArray; + SVGA3dPrimitiveRange *rangeArray; + uint32 declSize = sizeof **decls * numVertexDecls; + uint32 rangeSize = sizeof **ranges * numRanges; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_DRAW_PRIMITIVES, + sizeof *cmd + declSize + rangeSize, + numVertexDecls + numRanges); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + cmd->numVertexDecls = numVertexDecls; + cmd->numRanges = numRanges; + + declArray = (SVGA3dVertexDecl*) &cmd[1]; + rangeArray = (SVGA3dPrimitiveRange*) &declArray[numVertexDecls]; + + memset(declArray, 0, declSize); + memset(rangeArray, 0, rangeSize); + + *decls = declArray; + *ranges = rangeArray; + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_BeginSurfaceCopy -- + * + * Begin a SURFACE_COPY command. This reserves space for it in + * the FIFO, and returns a pointer to the command's arrays. This + * function must be paired with SVGA_FIFOCommitAll(). + * + * The box array is initialized with zeroes. + * + * Results: + * None. + * + * Side effects: + * Asynchronously copies a list of boxes from surface to surface. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_BeginSurfaceCopy(struct svga_winsys_context *swc, + struct pipe_surface *src, // IN + struct pipe_surface *dest, // IN + SVGA3dCopyBox **boxes, // OUT + uint32 numBoxes) // IN +{ + SVGA3dCmdSurfaceCopy *cmd; + uint32 boxesSize = sizeof **boxes * numBoxes; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SURFACE_COPY, sizeof *cmd + boxesSize, + 2); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + surface_to_surfaceid(swc, src, &cmd->src, SVGA_RELOC_READ); + surface_to_surfaceid(swc, dest, &cmd->dest, SVGA_RELOC_WRITE); + *boxes = (SVGA3dCopyBox*) &cmd[1]; + + memset(*boxes, 0, boxesSize); + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_SurfaceStretchBlt -- + * + * Issue a SURFACE_STRETCHBLT command: an asynchronous + * surface-to-surface blit, with scaling. + * + * Results: + * None. + * + * Side effects: + * Asynchronously copies one box from surface to surface. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_SurfaceStretchBlt(struct svga_winsys_context *swc, + struct pipe_surface *src, // IN + struct pipe_surface *dest, // IN + SVGA3dBox *boxSrc, // IN + SVGA3dBox *boxDest, // IN + SVGA3dStretchBltMode mode) // IN +{ + SVGA3dCmdSurfaceStretchBlt *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SURFACE_STRETCHBLT, sizeof *cmd, + 2); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + surface_to_surfaceid(swc, src, &cmd->src, SVGA_RELOC_READ); + surface_to_surfaceid(swc, dest, &cmd->dest, SVGA_RELOC_WRITE); + cmd->boxSrc = *boxSrc; + cmd->boxDest = *boxDest; + cmd->mode = mode; + swc->commit(swc); + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_SetViewport -- + * + * Set the current context's viewport rectangle. The viewport + * is clipped to the dimensions of the current render target, + * then all rendering is clipped to the viewport. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_SetViewport(struct svga_winsys_context *swc, + SVGA3dRect *rect) // IN +{ + SVGA3dCmdSetViewport *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SETVIEWPORT, sizeof *cmd, + 0); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + cmd->rect = *rect; + swc->commit(swc); + + return PIPE_OK; +} + + + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_SetScissorRect -- + * + * Set the current context's scissor rectangle. If scissor + * is enabled then all rendering is clipped to the scissor. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_SetScissorRect(struct svga_winsys_context *swc, + SVGA3dRect *rect) // IN +{ + SVGA3dCmdSetScissorRect *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SETSCISSORRECT, sizeof *cmd, + 0); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + cmd->rect = *rect; + swc->commit(swc); + + return PIPE_OK; +} + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_SetClipPlane -- + * + * Set one of the current context's clip planes. If the clip + * plane is enabled then all 3d rendering is clipped to against + * the plane. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error SVGA3D_SetClipPlane(struct svga_winsys_context *swc, + uint32 index, const float *plane) +{ + SVGA3dCmdSetClipPlane *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SETCLIPPLANE, sizeof *cmd, + 0); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + cmd->index = index; + cmd->plane[0] = plane[0]; + cmd->plane[1] = plane[1]; + cmd->plane[2] = plane[2]; + cmd->plane[3] = plane[3]; + swc->commit(swc); + + return PIPE_OK; +} + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_SetZRange -- + * + * Set the range of the depth buffer to use. 'min' and 'max' + * are values between 0.0 and 1.0. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_SetZRange(struct svga_winsys_context *swc, + float zMin, // IN + float zMax) // IN +{ + SVGA3dCmdSetZRange *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SETZRANGE, sizeof *cmd, + 0); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + cmd->zRange.min = zMin; + cmd->zRange.max = zMax; + swc->commit(swc); + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_BeginSetTextureState -- + * + * Begin a SETTEXTURESTATE command. This reserves space for it in + * the FIFO, and returns a pointer to the command's texture state + * array. This function must be paired with SVGA_FIFOCommitAll(). + * + * This command sets rendering state which is per-texture-unit. + * + * XXX: Individual texture states need documentation. However, + * they are very similar to the texture states defined by + * Direct3D. The D3D documentation is a good starting point + * for understanding SVGA3D texture states. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_BeginSetTextureState(struct svga_winsys_context *swc, + SVGA3dTextureState **states, // OUT + uint32 numStates) // IN +{ + SVGA3dCmdSetTextureState *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SETTEXTURESTATE, + sizeof *cmd + sizeof **states * numStates, + numStates); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + *states = (SVGA3dTextureState*) &cmd[1]; + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_BeginSetRenderState -- + * + * Begin a SETRENDERSTATE command. This reserves space for it in + * the FIFO, and returns a pointer to the command's texture state + * array. This function must be paired with SVGA_FIFOCommitAll(). + * + * This command sets rendering state which is global to the context. + * + * XXX: Individual render states need documentation. However, + * they are very similar to the render states defined by + * Direct3D. The D3D documentation is a good starting point + * for understanding SVGA3D render states. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_BeginSetRenderState(struct svga_winsys_context *swc, + SVGA3dRenderState **states, // OUT + uint32 numStates) // IN +{ + SVGA3dCmdSetRenderState *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SETRENDERSTATE, + sizeof *cmd + sizeof **states * numStates, + 0); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + *states = (SVGA3dRenderState*) &cmd[1]; + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_BeginQuery-- + * + * Issues a SVGA_3D_CMD_BEGIN_QUERY command. + * + * Results: + * None. + * + * Side effects: + * Commits space in the FIFO memory. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_BeginQuery(struct svga_winsys_context *swc, + SVGA3dQueryType type) // IN +{ + SVGA3dCmdBeginQuery *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_BEGIN_QUERY, + sizeof *cmd, + 0); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + cmd->type = type; + + swc->commit(swc); + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_EndQuery-- + * + * Issues a SVGA_3D_CMD_END_QUERY command. + * + * Results: + * None. + * + * Side effects: + * Commits space in the FIFO memory. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_EndQuery(struct svga_winsys_context *swc, + SVGA3dQueryType type, // IN + struct svga_winsys_buffer *buffer) // IN/OUT +{ + SVGA3dCmdEndQuery *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_END_QUERY, + sizeof *cmd, + 1); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + cmd->type = type; + + swc->region_relocation(swc, &cmd->guestResult, buffer, 0, + SVGA_RELOC_WRITE); + + swc->commit(swc); + + return PIPE_OK; +} + + +/* + *---------------------------------------------------------------------- + * + * SVGA3D_WaitForQuery-- + * + * Issues a SVGA_3D_CMD_WAIT_FOR_QUERY command. This reserves space + * for it in the FIFO. This doesn't actually wait for the query to + * finish but instead tells the host to start a wait at the driver + * level. The caller can wait on the status variable in the + * guestPtr memory or send an insert fence instruction after this + * command and wait on the fence. + * + * Results: + * None. + * + * Side effects: + * Commits space in the FIFO memory. + * + *---------------------------------------------------------------------- + */ + +enum pipe_error +SVGA3D_WaitForQuery(struct svga_winsys_context *swc, + SVGA3dQueryType type, // IN + struct svga_winsys_buffer *buffer) // IN/OUT +{ + SVGA3dCmdWaitForQuery *cmd; + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_WAIT_FOR_QUERY, + sizeof *cmd, + 1); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + cmd->cid = swc->cid; + cmd->type = type; + + swc->region_relocation(swc, &cmd->guestResult, buffer, 0, + SVGA_RELOC_WRITE); + + swc->commit(swc); + + return PIPE_OK; +} diff --git a/src/gallium/drivers/svga/svga_cmd.h b/src/gallium/drivers/svga/svga_cmd.h new file mode 100644 index 0000000..0e568d7 --- /dev/null +++ b/src/gallium/drivers/svga/svga_cmd.h @@ -0,0 +1,235 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +/* + * svga_cmd.h -- + * + * Command construction utility for the SVGA3D protocol used by + * the VMware SVGA device, based on the svgautil library. + */ + +#ifndef __SVGA3D_H__ +#define __SVGA3D_H__ + + +#include "svga_types.h" +#include "svga_reg.h" +#include "svga3d_reg.h" + +#include "pipe/p_defines.h" + + +struct pipe_surface; +struct svga_transfer; +struct svga_winsys_context; +struct svga_winsys_buffer; +struct svga_winsys_surface; + + +/* + * SVGA Device Interoperability + */ + +void * +SVGA3D_FIFOReserve(struct svga_winsys_context *swc, uint32 cmd, uint32 cmdSize, uint32 nr_relocs); + +void +SVGA_FIFOCommitAll(struct svga_winsys_context *swc); + + +/* + * Context Management + */ + +enum pipe_error +SVGA3D_DefineContext(struct svga_winsys_context *swc); + +enum pipe_error +SVGA3D_DestroyContext(struct svga_winsys_context *swc); + + +/* + * Surface Management + */ + +enum pipe_error +SVGA3D_BeginDefineSurface(struct svga_winsys_context *swc, + struct svga_winsys_surface *sid, + SVGA3dSurfaceFlags flags, + SVGA3dSurfaceFormat format, + SVGA3dSurfaceFace **faces, + SVGA3dSize **mipSizes, + uint32 numMipSizes); +enum pipe_error +SVGA3D_DefineSurface2D(struct svga_winsys_context *swc, + struct svga_winsys_surface *sid, + uint32 width, + uint32 height, + SVGA3dSurfaceFormat format); +enum pipe_error +SVGA3D_DestroySurface(struct svga_winsys_context *swc, + struct svga_winsys_surface *sid); + + +/* + * Surface Operations + */ + +enum pipe_error +SVGA3D_SurfaceDMA(struct svga_winsys_context *swc, + struct svga_transfer *st, + SVGA3dTransferType transfer, + const SVGA3dCopyBox *boxes, + uint32 numBoxes); + +enum pipe_error +SVGA3D_BufferDMA(struct svga_winsys_context *swc, + struct svga_winsys_buffer *guest, + struct svga_winsys_surface *host, + SVGA3dTransferType transfer, + uint32 size, + uint32 guest_offset, + uint32 host_offset, + SVGA3dSurfaceDMAFlags flags); + +/* + * Drawing Operations + */ + + +enum pipe_error +SVGA3D_BeginClear(struct svga_winsys_context *swc, + SVGA3dClearFlag flags, + uint32 color, float depth, uint32 stencil, + SVGA3dRect **rects, uint32 numRects); + +enum pipe_error +SVGA3D_ClearRect(struct svga_winsys_context *swc, + SVGA3dClearFlag flags, uint32 color, float depth, + uint32 stencil, uint32 x, uint32 y, uint32 w, uint32 h); + +enum pipe_error +SVGA3D_BeginDrawPrimitives(struct svga_winsys_context *swc, + SVGA3dVertexDecl **decls, + uint32 numVertexDecls, + SVGA3dPrimitiveRange **ranges, + uint32 numRanges); + +/* + * Blits + */ + +enum pipe_error +SVGA3D_BeginSurfaceCopy(struct svga_winsys_context *swc, + struct pipe_surface *src, + struct pipe_surface *dest, + SVGA3dCopyBox **boxes, uint32 numBoxes); + + +enum pipe_error +SVGA3D_SurfaceStretchBlt(struct svga_winsys_context *swc, + struct pipe_surface *src, + struct pipe_surface *dest, + SVGA3dBox *boxSrc, SVGA3dBox *boxDest, + SVGA3dStretchBltMode mode); + +/* + * Shared FFP/Shader Render State + */ + +enum pipe_error +SVGA3D_SetRenderTarget(struct svga_winsys_context *swc, + SVGA3dRenderTargetType type, + struct pipe_surface *surface); + +enum pipe_error +SVGA3D_SetZRange(struct svga_winsys_context *swc, + float zMin, float zMax); + +enum pipe_error +SVGA3D_SetViewport(struct svga_winsys_context *swc, + SVGA3dRect *rect); + +enum pipe_error +SVGA3D_SetScissorRect(struct svga_winsys_context *swc, + SVGA3dRect *rect); + +enum pipe_error +SVGA3D_SetClipPlane(struct svga_winsys_context *swc, + uint32 index, const float *plane); + +enum pipe_error +SVGA3D_BeginSetTextureState(struct svga_winsys_context *swc, + SVGA3dTextureState **states, + uint32 numStates); + +enum pipe_error +SVGA3D_BeginSetRenderState(struct svga_winsys_context *swc, + SVGA3dRenderState **states, + uint32 numStates); + + +/* + * Shaders + */ + +enum pipe_error +SVGA3D_DefineShader(struct svga_winsys_context *swc, + uint32 shid, SVGA3dShaderType type, + const uint32 *bytecode, uint32 bytecodeLen); + +enum pipe_error +SVGA3D_DestroyShader(struct svga_winsys_context *swc, + uint32 shid, SVGA3dShaderType type); + +enum pipe_error +SVGA3D_SetShaderConst(struct svga_winsys_context *swc, + uint32 reg, SVGA3dShaderType type, + SVGA3dShaderConstType ctype, const void *value); + +enum pipe_error +SVGA3D_SetShader(struct svga_winsys_context *swc, + SVGA3dShaderType type, uint32 shid); + + +/* + * Queries + */ + +enum pipe_error +SVGA3D_BeginQuery(struct svga_winsys_context *swc, + SVGA3dQueryType type); + +enum pipe_error +SVGA3D_EndQuery(struct svga_winsys_context *swc, + SVGA3dQueryType type, + struct svga_winsys_buffer *buffer); + +enum pipe_error +SVGA3D_WaitForQuery(struct svga_winsys_context *swc, + SVGA3dQueryType type, + struct svga_winsys_buffer *buffer); + +#endif /* __SVGA3D_H__ */ diff --git a/src/gallium/drivers/svga/svga_context.c b/src/gallium/drivers/svga/svga_context.c new file mode 100644 index 0000000..1e513f1 --- /dev/null +++ b/src/gallium/drivers/svga/svga_context.c @@ -0,0 +1,252 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "svga_cmd.h" + +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "pipe/p_screen.h" +#include "util/u_memory.h" +#include "util/u_bitmask.h" +#include "util/u_upload_mgr.h" + +#include "svga_context.h" +#include "svga_screen.h" +#include "svga_resource_texture.h" +#include "svga_resource_buffer.h" +#include "svga_resource.h" +#include "svga_winsys.h" +#include "svga_swtnl.h" +#include "svga_draw.h" +#include "svga_debug.h" +#include "svga_state.h" + + +static void svga_destroy( struct pipe_context *pipe ) +{ + struct svga_context *svga = svga_context( pipe ); + unsigned shader; + + svga_cleanup_framebuffer( svga ); + svga_cleanup_tss_binding( svga ); + + svga_hwtnl_destroy( svga->hwtnl ); + + svga_cleanup_vertex_state(svga); + + svga->swc->destroy(svga->swc); + + svga_destroy_swtnl( svga ); + + u_upload_destroy( svga->upload_vb ); + u_upload_destroy( svga->upload_ib ); + + util_bitmask_destroy( svga->vs_bm ); + util_bitmask_destroy( svga->fs_bm ); + + for(shader = 0; shader < PIPE_SHADER_TYPES; ++shader) + pipe_resource_reference( &svga->curr.cb[shader], NULL ); + + FREE( svga ); +} + + + +struct pipe_context *svga_context_create( struct pipe_screen *screen, + void *priv ) +{ + struct svga_screen *svgascreen = svga_screen(screen); + struct svga_context *svga = NULL; + enum pipe_error ret; + + svga = CALLOC_STRUCT(svga_context); + if (svga == NULL) + goto no_svga; + + svga->pipe.winsys = screen->winsys; + svga->pipe.screen = screen; + svga->pipe.priv = priv; + svga->pipe.destroy = svga_destroy; + svga->pipe.clear = svga_clear; + + svga->swc = svgascreen->sws->context_create(svgascreen->sws); + if(!svga->swc) + goto no_swc; + + svga_init_resource_functions(svga); + svga_init_blend_functions(svga); + svga_init_blit_functions(svga); + svga_init_depth_stencil_functions(svga); + svga_init_draw_functions(svga); + svga_init_flush_functions(svga); + svga_init_misc_functions(svga); + svga_init_rasterizer_functions(svga); + svga_init_sampler_functions(svga); + svga_init_fs_functions(svga); + svga_init_vs_functions(svga); + svga_init_vertex_functions(svga); + svga_init_constbuffer_functions(svga); + svga_init_query_functions(svga); + svga_init_surface_functions(svga); + + + /* debug */ + svga->debug.no_swtnl = debug_get_bool_option("SVGA_NO_SWTNL", FALSE); + svga->debug.force_swtnl = debug_get_bool_option("SVGA_FORCE_SWTNL", FALSE); + svga->debug.use_min_mipmap = debug_get_bool_option("SVGA_USE_MIN_MIPMAP", FALSE); + svga->debug.disable_shader = debug_get_num_option("SVGA_DISABLE_SHADER", ~0); + + if (!svga_init_swtnl(svga)) + goto no_swtnl; + + svga->fs_bm = util_bitmask_create(); + if (svga->fs_bm == NULL) + goto no_fs_bm; + + svga->vs_bm = util_bitmask_create(); + if (svga->vs_bm == NULL) + goto no_vs_bm; + + svga->upload_ib = u_upload_create( &svga->pipe, + 32 * 1024, + 16, + PIPE_BIND_INDEX_BUFFER ); + if (svga->upload_ib == NULL) + goto no_upload_ib; + + svga->upload_vb = u_upload_create( &svga->pipe, + 128 * 1024, + 16, + PIPE_BIND_VERTEX_BUFFER ); + if (svga->upload_vb == NULL) + goto no_upload_vb; + + svga->hwtnl = svga_hwtnl_create( svga, + svga->upload_ib, + svga->swc ); + if (svga->hwtnl == NULL) + goto no_hwtnl; + + + ret = svga_emit_initial_state( svga ); + if (ret) + goto no_state; + + /* Avoid shortcircuiting state with initial value of zero. + */ + memset(&svga->state.hw_clear, 0xcd, sizeof(svga->state.hw_clear)); + memset(&svga->state.hw_clear.framebuffer, 0x0, + sizeof(svga->state.hw_clear.framebuffer)); + + memset(&svga->state.hw_draw, 0xcd, sizeof(svga->state.hw_draw)); + memset(&svga->state.hw_draw.views, 0x0, sizeof(svga->state.hw_draw.views)); + svga->state.hw_draw.num_views = 0; + + svga->dirty = ~0; + + LIST_INITHEAD(&svga->dirty_buffers); + + return &svga->pipe; + +no_state: + svga_hwtnl_destroy( svga->hwtnl ); +no_hwtnl: + u_upload_destroy( svga->upload_vb ); +no_upload_vb: + u_upload_destroy( svga->upload_ib ); +no_upload_ib: + util_bitmask_destroy( svga->vs_bm ); +no_vs_bm: + util_bitmask_destroy( svga->fs_bm ); +no_fs_bm: + svga_destroy_swtnl(svga); +no_swtnl: + svga->swc->destroy(svga->swc); +no_swc: + FREE(svga); +no_svga: + return NULL; +} + + +void svga_context_flush( struct svga_context *svga, + struct pipe_fence_handle **pfence ) +{ + struct svga_screen *svgascreen = svga_screen(svga->pipe.screen); + struct pipe_fence_handle *fence = NULL; + + svga->curr.nr_fbs = 0; + + /* Unmap upload manager buffers: + */ + u_upload_flush(svga->upload_vb); + u_upload_flush(svga->upload_ib); + + /* Ensure that texture dma uploads are processed + * before submitting commands. + */ + svga_context_flush_buffers(svga); + + /* Flush pending commands to hardware: + */ + svga->swc->flush(svga->swc, &fence); + + svga_screen_cache_flush(svgascreen, fence); + + /* To force the reemission of rendertargets and texture bindings at + * the beginning of every command buffer. + */ + svga->dirty |= SVGA_NEW_COMMAND_BUFFER; + + if (SVGA_DEBUG & DEBUG_SYNC) { + if (fence) + svga->pipe.screen->fence_finish( svga->pipe.screen, fence, 0); + } + + if(pfence) + *pfence = fence; + else + svgascreen->sws->fence_reference(svgascreen->sws, &fence, NULL); +} + + +void svga_hwtnl_flush_retry( struct svga_context *svga ) +{ + enum pipe_error ret = PIPE_OK; + + ret = svga_hwtnl_flush( svga->hwtnl ); + if (ret == PIPE_ERROR_OUT_OF_MEMORY) { + svga_context_flush( svga, NULL ); + ret = svga_hwtnl_flush( svga->hwtnl ); + } + + assert(ret == 0); +} + +struct svga_winsys_context * +svga_winsys_context( struct pipe_context *pipe ) +{ + return svga_context( pipe )->swc; +} diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h new file mode 100644 index 0000000..04e281a --- /dev/null +++ b/src/gallium/drivers/svga/svga_context.h @@ -0,0 +1,453 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_CONTEXT_H +#define SVGA_CONTEXT_H + + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" + +#include "util/u_double_list.h" + +#include "tgsi/tgsi_scan.h" + + +#define SVGA_TEX_UNITS 8 +#define SVGA_MAX_POINTSIZE 80.0 + +struct draw_vertex_shader; +struct svga_shader_result; +struct SVGACmdMemory; +struct util_bitmask; +struct u_upload_mgr; + + +struct svga_shader +{ + const struct tgsi_token *tokens; + + struct tgsi_shader_info info; + + struct svga_shader_result *results; + + unsigned id; + + boolean use_sm30; +}; + +struct svga_fragment_shader +{ + struct svga_shader base; +}; + +struct svga_vertex_shader +{ + struct svga_shader base; + + struct draw_vertex_shader *draw_shader; +}; + + +struct svga_cache_context; +struct svga_tracked_state; + +struct svga_blend_state { + + boolean need_white_fragments; + + /* Should be per-render-target: + */ + struct { + uint8_t writemask; + + boolean blend_enable; + uint8_t srcblend; + uint8_t dstblend; + uint8_t blendeq; + + boolean separate_alpha_blend_enable; + uint8_t srcblend_alpha; + uint8_t dstblend_alpha; + uint8_t blendeq_alpha; + + } rt[1]; +}; + +struct svga_depth_stencil_state { + unsigned zfunc:8; + unsigned zenable:1; + unsigned zwriteenable:1; + + unsigned alphatestenable:1; + unsigned alphafunc:8; + + struct { + unsigned enabled:1; + unsigned func:8; + unsigned fail:8; + unsigned zfail:8; + unsigned pass:8; + } stencil[2]; + + /* SVGA3D has one ref/mask/writemask triple shared between front & + * back face stencil. We really need two: + */ + unsigned stencil_mask:8; + unsigned stencil_writemask:8; + + float alpharef; +}; + +#define SVGA_UNFILLED_DISABLE 0 +#define SVGA_UNFILLED_LINE 1 +#define SVGA_UNFILLED_POINT 2 + +#define SVGA_PIPELINE_FLAG_POINTS (1<svga = svga; + hwtnl->upload_ib = upload_ib; + + hwtnl->cmd.swc = swc; + + return hwtnl; + +fail: + return NULL; +} + +void svga_hwtnl_destroy( struct svga_hwtnl *hwtnl ) +{ + int i, j; + + for (i = 0; i < PIPE_PRIM_MAX; i++) { + for (j = 0; j < IDX_CACHE_MAX; j++) { + pipe_resource_reference( &hwtnl->index_cache[i][j].buffer, + NULL ); + } + } + + for (i = 0; i < hwtnl->cmd.vdecl_count; i++) + pipe_resource_reference(&hwtnl->cmd.vdecl_vb[i], NULL); + + for (i = 0; i < hwtnl->cmd.prim_count; i++) + pipe_resource_reference(&hwtnl->cmd.prim_ib[i], NULL); + + + FREE(hwtnl); +} + + +void svga_hwtnl_set_flatshade( struct svga_hwtnl *hwtnl, + boolean flatshade, + boolean flatshade_first ) +{ + hwtnl->hw_pv = PV_FIRST; + hwtnl->api_pv = (flatshade && !flatshade_first) ? PV_LAST : PV_FIRST; +} + +void svga_hwtnl_set_unfilled( struct svga_hwtnl *hwtnl, + unsigned mode ) +{ + hwtnl->api_fillmode = mode; +} + +void svga_hwtnl_reset_vdecl( struct svga_hwtnl *hwtnl, + unsigned count ) +{ + unsigned i; + + assert(hwtnl->cmd.prim_count == 0); + + for (i = count; i < hwtnl->cmd.vdecl_count; i++) { + pipe_resource_reference(&hwtnl->cmd.vdecl_vb[i], + NULL); + } + + hwtnl->cmd.vdecl_count = count; +} + + +void svga_hwtnl_vdecl( struct svga_hwtnl *hwtnl, + unsigned i, + const SVGA3dVertexDecl *decl, + struct pipe_resource *vb) +{ + assert(hwtnl->cmd.prim_count == 0); + + assert( i < hwtnl->cmd.vdecl_count ); + + hwtnl->cmd.vdecl[i] = *decl; + + pipe_resource_reference(&hwtnl->cmd.vdecl_vb[i], vb); +} + + + +enum pipe_error +svga_hwtnl_flush( struct svga_hwtnl *hwtnl ) +{ + struct svga_winsys_context *swc = hwtnl->cmd.swc; + struct svga_context *svga = hwtnl->svga; + enum pipe_error ret; + + if (hwtnl->cmd.prim_count) { + struct svga_winsys_surface *vb_handle[SVGA3D_INPUTREG_MAX]; + struct svga_winsys_surface *ib_handle[QSZ]; + struct svga_winsys_surface *handle; + SVGA3dVertexDecl *vdecl; + SVGA3dPrimitiveRange *prim; + unsigned i; + + for (i = 0; i < hwtnl->cmd.vdecl_count; i++) { + handle = svga_buffer_handle(svga, hwtnl->cmd.vdecl_vb[i]); + if (handle == NULL) + return PIPE_ERROR_OUT_OF_MEMORY; + + vb_handle[i] = handle; + } + + for (i = 0; i < hwtnl->cmd.prim_count; i++) { + if (hwtnl->cmd.prim_ib[i]) { + handle = svga_buffer_handle(svga, hwtnl->cmd.prim_ib[i]); + if (handle == NULL) + return PIPE_ERROR_OUT_OF_MEMORY; + } + else + handle = NULL; + + ib_handle[i] = handle; + } + + SVGA_DBG(DEBUG_DMA, "draw to sid %p, %d prims\n", + svga->curr.framebuffer.cbufs[0] ? + svga_surface(svga->curr.framebuffer.cbufs[0])->handle : NULL, + hwtnl->cmd.prim_count); + + ret = SVGA3D_BeginDrawPrimitives(swc, + &vdecl, + hwtnl->cmd.vdecl_count, + &prim, + hwtnl->cmd.prim_count); + if (ret != PIPE_OK) + return ret; + + + memcpy( vdecl, + hwtnl->cmd.vdecl, + hwtnl->cmd.vdecl_count * sizeof hwtnl->cmd.vdecl[0]); + + for (i = 0; i < hwtnl->cmd.vdecl_count; i++) { + /* Given rangeHint is considered to be relative to indexBias, and + * indexBias varies per primitive, we cannot accurately supply an + * rangeHint when emitting more than one primitive per draw command. + */ + if (hwtnl->cmd.prim_count == 1) { + vdecl[i].rangeHint.first = hwtnl->cmd.min_index[0]; + vdecl[i].rangeHint.last = hwtnl->cmd.max_index[0] + 1; + } + else { + vdecl[i].rangeHint.first = 0; + vdecl[i].rangeHint.last = 0; + } + + swc->surface_relocation(swc, + &vdecl[i].array.surfaceId, + vb_handle[i], + SVGA_RELOC_READ); + } + + memcpy( prim, + hwtnl->cmd.prim, + hwtnl->cmd.prim_count * sizeof hwtnl->cmd.prim[0]); + + for (i = 0; i < hwtnl->cmd.prim_count; i++) { + swc->surface_relocation(swc, + &prim[i].indexArray.surfaceId, + ib_handle[i], + SVGA_RELOC_READ); + pipe_resource_reference(&hwtnl->cmd.prim_ib[i], NULL); + } + + SVGA_FIFOCommitAll( swc ); + hwtnl->cmd.prim_count = 0; + } + + return PIPE_OK; +} + + + + + +/*********************************************************************** + * Internal functions: + */ + +enum pipe_error svga_hwtnl_prim( struct svga_hwtnl *hwtnl, + const SVGA3dPrimitiveRange *range, + unsigned min_index, + unsigned max_index, + struct pipe_resource *ib ) +{ + int ret = PIPE_OK; + +#ifdef DEBUG + { + unsigned i; + for (i = 0; i < hwtnl->cmd.vdecl_count; i++) { + struct pipe_resource *vb = hwtnl->cmd.vdecl_vb[i]; + unsigned size = vb ? vb->width0 : 0; + unsigned offset = hwtnl->cmd.vdecl[i].array.offset; + unsigned stride = hwtnl->cmd.vdecl[i].array.stride; + unsigned index_bias = range->indexBias; + unsigned width; + + assert(vb); + assert(size); + assert(offset < size); + assert(index_bias >= 0); + assert(min_index <= max_index); + assert(offset + index_bias*stride < size); + if (min_index != ~0) { + assert(offset + (index_bias + min_index) * stride < size); + } + + switch (hwtnl->cmd.vdecl[i].identity.type) { + case SVGA3D_DECLTYPE_FLOAT1: + width = 4; + break; + case SVGA3D_DECLTYPE_FLOAT2: + width = 4*2; + break; + case SVGA3D_DECLTYPE_FLOAT3: + width = 4*3; + break; + case SVGA3D_DECLTYPE_FLOAT4: + width = 4*4; + break; + case SVGA3D_DECLTYPE_D3DCOLOR: + width = 4; + break; + case SVGA3D_DECLTYPE_UBYTE4: + width = 1*4; + break; + case SVGA3D_DECLTYPE_SHORT2: + width = 2*2; + break; + case SVGA3D_DECLTYPE_SHORT4: + width = 2*4; + break; + case SVGA3D_DECLTYPE_UBYTE4N: + width = 1*4; + break; + case SVGA3D_DECLTYPE_SHORT2N: + width = 2*2; + break; + case SVGA3D_DECLTYPE_SHORT4N: + width = 2*4; + break; + case SVGA3D_DECLTYPE_USHORT2N: + width = 2*2; + break; + case SVGA3D_DECLTYPE_USHORT4N: + width = 2*4; + break; + case SVGA3D_DECLTYPE_UDEC3: + width = 4; + break; + case SVGA3D_DECLTYPE_DEC3N: + width = 4; + break; + case SVGA3D_DECLTYPE_FLOAT16_2: + width = 2*2; + break; + case SVGA3D_DECLTYPE_FLOAT16_4: + width = 2*4; + break; + default: + assert(0); + width = 0; + break; + } + + assert(!stride || width <= stride); + if (max_index != ~0) { + assert(offset + (index_bias + max_index) * stride + width <= size); + } + } + + assert(range->indexWidth == range->indexArray.stride); + + if(ib) { + unsigned size = ib->width0; + unsigned offset = range->indexArray.offset; + unsigned stride = range->indexArray.stride; + unsigned count; + + assert(size); + assert(offset < size); + assert(stride); + + switch (range->primType) { + case SVGA3D_PRIMITIVE_POINTLIST: + count = range->primitiveCount; + break; + case SVGA3D_PRIMITIVE_LINELIST: + count = range->primitiveCount * 2; + break; + case SVGA3D_PRIMITIVE_LINESTRIP: + count = range->primitiveCount + 1; + break; + case SVGA3D_PRIMITIVE_TRIANGLELIST: + count = range->primitiveCount * 3; + break; + case SVGA3D_PRIMITIVE_TRIANGLESTRIP: + count = range->primitiveCount + 2; + break; + case SVGA3D_PRIMITIVE_TRIANGLEFAN: + count = range->primitiveCount + 2; + break; + default: + assert(0); + count = 0; + break; + } + + assert(offset + count*stride <= size); + } + } +#endif + + if (hwtnl->cmd.prim_count+1 >= QSZ) { + ret = svga_hwtnl_flush( hwtnl ); + if (ret != PIPE_OK) + return ret; + } + + /* min/max indices are relative to bias */ + hwtnl->cmd.min_index[hwtnl->cmd.prim_count] = min_index; + hwtnl->cmd.max_index[hwtnl->cmd.prim_count] = max_index; + + hwtnl->cmd.prim[hwtnl->cmd.prim_count] = *range; + + pipe_resource_reference(&hwtnl->cmd.prim_ib[hwtnl->cmd.prim_count], ib); + hwtnl->cmd.prim_count++; + + return ret; +} diff --git a/src/gallium/drivers/svga/svga_draw.h b/src/gallium/drivers/svga/svga_draw.h new file mode 100644 index 0000000..a2403d8 --- /dev/null +++ b/src/gallium/drivers/svga/svga_draw.h @@ -0,0 +1,83 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_DRAW_H +#define SVGA_DRAW_H + +#include "pipe/p_compiler.h" + +#include "svga_hw_reg.h" + +struct svga_hwtnl; +struct svga_winsys_context; +struct svga_screen; +struct svga_context; +struct pipe_resource; +struct u_upload_mgr; + +struct svga_hwtnl *svga_hwtnl_create( struct svga_context *svga, + struct u_upload_mgr *upload_ib, + struct svga_winsys_context *swc ); + +void svga_hwtnl_destroy( struct svga_hwtnl *hwtnl ); + +void svga_hwtnl_set_flatshade( struct svga_hwtnl *hwtnl, + boolean flatshade, + boolean flatshade_first ); + +void svga_hwtnl_set_unfilled( struct svga_hwtnl *hwtnl, + unsigned mode ); + +void svga_hwtnl_vdecl( struct svga_hwtnl *hwtnl, + unsigned i, + const SVGA3dVertexDecl *decl, + struct pipe_resource *vb); + +void svga_hwtnl_reset_vdecl( struct svga_hwtnl *hwtnl, + unsigned count ); + + +enum pipe_error +svga_hwtnl_draw_arrays( struct svga_hwtnl *hwtnl, + unsigned prim, + unsigned start, + unsigned count); + +enum pipe_error +svga_hwtnl_draw_range_elements( struct svga_hwtnl *hwtnl, + struct pipe_resource *indexBuffer, + unsigned index_size, + int index_bias, + unsigned min_index, + unsigned max_index, + unsigned prim, + unsigned start, + unsigned count ); + +enum pipe_error +svga_hwtnl_flush( struct svga_hwtnl *hwtnl ); + + +#endif /* SVGA_DRAW_H_ */ diff --git a/src/gallium/drivers/svga/svga_draw_arrays.c b/src/gallium/drivers/svga/svga_draw_arrays.c new file mode 100644 index 0000000..da33fae --- /dev/null +++ b/src/gallium/drivers/svga/svga_draw_arrays.c @@ -0,0 +1,297 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "svga_cmd.h" + +#include "util/u_inlines.h" +#include "indices/u_indices.h" + +#include "svga_hw_reg.h" +#include "svga_draw.h" +#include "svga_draw_private.h" +#include "svga_context.h" + + +#define DBG 0 + + + + +static enum pipe_error generate_indices( struct svga_hwtnl *hwtnl, + unsigned nr, + unsigned index_size, + u_generate_func generate, + struct pipe_resource **out_buf ) +{ + struct pipe_context *pipe = &hwtnl->svga->pipe; + struct pipe_transfer *transfer; + unsigned size = index_size * nr; + struct pipe_resource *dst = NULL; + void *dst_map = NULL; + + dst = pipe_buffer_create( pipe->screen, + PIPE_BIND_INDEX_BUFFER, + size ); + if (dst == NULL) + goto fail; + + dst_map = pipe_buffer_map( pipe, dst, PIPE_TRANSFER_WRITE, + &transfer); + if (dst_map == NULL) + goto fail; + + generate( nr, + dst_map ); + + pipe_buffer_unmap( pipe, dst, transfer ); + + *out_buf = dst; + return PIPE_OK; + +fail: + if (dst_map) + pipe_buffer_unmap( pipe, dst, transfer ); + + if (dst) + pipe->screen->resource_destroy( pipe->screen, dst ); + + return PIPE_ERROR_OUT_OF_MEMORY; +} + +static boolean compare( unsigned cached_nr, + unsigned nr, + unsigned type ) +{ + if (type == U_GENERATE_REUSABLE) + return cached_nr >= nr; + else + return cached_nr == nr; +} + +static enum pipe_error retrieve_or_generate_indices( struct svga_hwtnl *hwtnl, + unsigned prim, + unsigned gen_type, + unsigned gen_nr, + unsigned gen_size, + u_generate_func generate, + struct pipe_resource **out_buf ) +{ + enum pipe_error ret = PIPE_OK; + int i; + + for (i = 0; i < IDX_CACHE_MAX; i++) { + if (hwtnl->index_cache[prim][i].buffer != NULL && + hwtnl->index_cache[prim][i].generate == generate) + { + if (compare(hwtnl->index_cache[prim][i].gen_nr, gen_nr, gen_type)) + { + pipe_resource_reference( out_buf, + hwtnl->index_cache[prim][i].buffer ); + + if (DBG) + debug_printf("%s retrieve %d/%d\n", __FUNCTION__, i, gen_nr); + + return PIPE_OK; + } + else if (gen_type == U_GENERATE_REUSABLE) + { + pipe_resource_reference( &hwtnl->index_cache[prim][i].buffer, + NULL ); + + if (DBG) + debug_printf("%s discard %d/%d\n", __FUNCTION__, + i, hwtnl->index_cache[prim][i].gen_nr); + + break; + } + } + } + + if (i == IDX_CACHE_MAX) + { + unsigned smallest = 0; + unsigned smallest_size = ~0; + + for (i = 0; i < IDX_CACHE_MAX && smallest_size; i++) { + if (hwtnl->index_cache[prim][i].buffer == NULL) + { + smallest = i; + smallest_size = 0; + } + else if (hwtnl->index_cache[prim][i].gen_nr < smallest) + { + smallest = i; + smallest_size = hwtnl->index_cache[prim][i].gen_nr; + } + } + + assert (smallest != IDX_CACHE_MAX); + + pipe_resource_reference( &hwtnl->index_cache[prim][smallest].buffer, + NULL ); + + if (DBG) + debug_printf("%s discard smallest %d/%d\n", __FUNCTION__, + smallest, smallest_size); + + i = smallest; + } + + + ret = generate_indices( hwtnl, + gen_nr, + gen_size, + generate, + out_buf ); + if (ret != PIPE_OK) + return ret; + + + hwtnl->index_cache[prim][i].generate = generate; + hwtnl->index_cache[prim][i].gen_nr = gen_nr; + pipe_resource_reference( &hwtnl->index_cache[prim][i].buffer, + *out_buf ); + + if (DBG) + debug_printf("%s cache %d/%d\n", __FUNCTION__, + i, hwtnl->index_cache[prim][i].gen_nr); + + return PIPE_OK; +} + + + +static enum pipe_error +simple_draw_arrays( struct svga_hwtnl *hwtnl, + unsigned prim, unsigned start, unsigned count ) +{ + SVGA3dPrimitiveRange range; + unsigned hw_prim; + unsigned hw_count; + + hw_prim = svga_translate_prim(prim, count, &hw_count); + if (hw_count == 0) + return PIPE_ERROR_BAD_INPUT; + + range.primType = hw_prim; + range.primitiveCount = hw_count; + range.indexArray.surfaceId = SVGA3D_INVALID_ID; + range.indexArray.offset = 0; + range.indexArray.stride = 0; + range.indexWidth = 0; + range.indexBias = start; + + /* Min/max index should be calculated prior to applying bias, so we + * end up with min_index = 0, max_index = count - 1 and everybody + * looking at those numbers knows to adjust them by + * range.indexBias. + */ + return svga_hwtnl_prim( hwtnl, &range, 0, count - 1, NULL ); +} + + + + + + + + + + +enum pipe_error +svga_hwtnl_draw_arrays( struct svga_hwtnl *hwtnl, + unsigned prim, + unsigned start, + unsigned count) +{ + unsigned gen_prim, gen_size, gen_nr, gen_type; + u_generate_func gen_func; + enum pipe_error ret = PIPE_OK; + + if (hwtnl->api_fillmode != PIPE_POLYGON_MODE_FILL && + prim >= PIPE_PRIM_TRIANGLES) + { + gen_type = u_unfilled_generator( prim, + start, + count, + hwtnl->api_fillmode, + &gen_prim, + &gen_size, + &gen_nr, + &gen_func ); + } + else { + gen_type = u_index_generator( svga_hw_prims, + prim, + start, + count, + hwtnl->api_pv, + hwtnl->hw_pv, + &gen_prim, + &gen_size, + &gen_nr, + &gen_func ); + } + + if (gen_type == U_GENERATE_LINEAR) { + return simple_draw_arrays( hwtnl, gen_prim, start, count ); + } + else { + struct pipe_resource *gen_buf = NULL; + + /* Need to draw as indexed primitive. + * Potentially need to run the gen func to build an index buffer. + */ + ret = retrieve_or_generate_indices( hwtnl, + prim, + gen_type, + gen_nr, + gen_size, + gen_func, + &gen_buf ); + if (ret) + goto done; + + ret = svga_hwtnl_simple_draw_range_elements( hwtnl, + gen_buf, + gen_size, + start, + 0, + count - 1, + gen_prim, + 0, + gen_nr ); + + if (ret) + goto done; + + done: + if (gen_buf) + pipe_resource_reference( &gen_buf, NULL ); + + return ret; + } +} + diff --git a/src/gallium/drivers/svga/svga_draw_elements.c b/src/gallium/drivers/svga/svga_draw_elements.c new file mode 100644 index 0000000..c457917 --- /dev/null +++ b/src/gallium/drivers/svga/svga_draw_elements.c @@ -0,0 +1,255 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "util/u_upload_mgr.h" +#include "indices/u_indices.h" + +#include "svga_cmd.h" +#include "svga_draw.h" +#include "svga_draw_private.h" +#include "svga_resource_buffer.h" +#include "svga_winsys.h" +#include "svga_context.h" + +#include "svga_hw_reg.h" + + +static enum pipe_error +translate_indices( struct svga_hwtnl *hwtnl, + struct pipe_resource *src, + unsigned offset, + unsigned nr, + unsigned index_size, + u_translate_func translate, + struct pipe_resource **out_buf ) +{ + struct pipe_context *pipe = &hwtnl->svga->pipe; + struct pipe_transfer *src_transfer = NULL; + struct pipe_transfer *dst_transfer = NULL; + unsigned size = index_size * nr; + const void *src_map = NULL; + struct pipe_resource *dst = NULL; + void *dst_map = NULL; + + dst = pipe_buffer_create( pipe->screen, + PIPE_BIND_INDEX_BUFFER, + size ); + if (dst == NULL) + goto fail; + + src_map = pipe_buffer_map( pipe, src, PIPE_TRANSFER_READ, &src_transfer ); + if (src_map == NULL) + goto fail; + + dst_map = pipe_buffer_map( pipe, dst, PIPE_TRANSFER_WRITE, &dst_transfer ); + if (dst_map == NULL) + goto fail; + + translate( (const char *)src_map + offset, + nr, + dst_map ); + + pipe_buffer_unmap( pipe, src, src_transfer ); + pipe_buffer_unmap( pipe, dst, dst_transfer ); + + *out_buf = dst; + return PIPE_OK; + +fail: + if (src_map) + pipe_buffer_unmap( pipe, src, src_transfer ); + + if (dst_map) + pipe_buffer_unmap( pipe, dst, dst_transfer ); + + if (dst) + pipe->screen->resource_destroy( pipe->screen, dst ); + + return PIPE_ERROR_OUT_OF_MEMORY; +} + + + + + +enum pipe_error +svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl *hwtnl, + struct pipe_resource *index_buffer, + unsigned index_size, + int index_bias, + unsigned min_index, + unsigned max_index, + unsigned prim, + unsigned start, + unsigned count ) +{ + struct pipe_resource *upload_buffer = NULL; + SVGA3dPrimitiveRange range; + unsigned hw_prim; + unsigned hw_count; + unsigned index_offset = start * index_size; + int ret = PIPE_OK; + + hw_prim = svga_translate_prim(prim, count, &hw_count); + if (hw_count == 0) + goto done; + + if (index_buffer && + svga_buffer_is_user_buffer(index_buffer)) + { + assert( index_buffer->width0 >= index_offset + count * index_size ); + + ret = u_upload_buffer( hwtnl->upload_ib, + index_offset, + count * index_size, + index_buffer, + &index_offset, + &upload_buffer ); + if (ret) + goto done; + + /* Don't need to worry about refcounting index_buffer as this is + * just a stack variable without a counted reference of its own. + * The caller holds the reference. + */ + index_buffer = upload_buffer; + } + + range.primType = hw_prim; + range.primitiveCount = hw_count; + range.indexArray.offset = index_offset; + range.indexArray.stride = index_size; + range.indexWidth = index_size; + range.indexBias = index_bias; + + ret = svga_hwtnl_prim( hwtnl, &range, min_index, max_index, index_buffer ); + if (ret) + goto done; + +done: + if (upload_buffer) + pipe_resource_reference( &upload_buffer, NULL ); + + return ret; +} + + + + +enum pipe_error +svga_hwtnl_draw_range_elements( struct svga_hwtnl *hwtnl, + struct pipe_resource *index_buffer, + unsigned index_size, + int index_bias, + unsigned min_index, + unsigned max_index, + unsigned prim, unsigned start, unsigned count) +{ + unsigned gen_prim, gen_size, gen_nr, gen_type; + u_translate_func gen_func; + enum pipe_error ret = PIPE_OK; + + if (hwtnl->api_fillmode != PIPE_POLYGON_MODE_FILL && + prim >= PIPE_PRIM_TRIANGLES) + { + gen_type = u_unfilled_translator( prim, + index_size, + count, + hwtnl->api_fillmode, + &gen_prim, + &gen_size, + &gen_nr, + &gen_func ); + } + else + { + gen_type = u_index_translator( svga_hw_prims, + prim, + index_size, + count, + hwtnl->api_pv, + hwtnl->hw_pv, + &gen_prim, + &gen_size, + &gen_nr, + &gen_func ); + } + + + if (gen_type == U_TRANSLATE_MEMCPY) { + /* No need for translation, just pass through to hardware: + */ + return svga_hwtnl_simple_draw_range_elements( hwtnl, index_buffer, + index_size, + index_bias, + min_index, + max_index, + gen_prim, start, count ); + } + else { + struct pipe_resource *gen_buf = NULL; + + /* Need to allocate a new index buffer and run the translate + * func to populate it. Could potentially cache this translated + * index buffer with the original to avoid future + * re-translations. Not much point if we're just accelerating + * GL though, as index buffers are typically used only once + * there. + */ + ret = translate_indices( hwtnl, + index_buffer, + start * index_size, + gen_nr, + gen_size, + gen_func, + &gen_buf ); + if (ret) + goto done; + + ret = svga_hwtnl_simple_draw_range_elements( hwtnl, + gen_buf, + gen_size, + index_bias, + min_index, + max_index, + gen_prim, + 0, + gen_nr ); + if (ret) + goto done; + + done: + if (gen_buf) + pipe_resource_reference( &gen_buf, NULL ); + + return ret; + } +} + + + + + diff --git a/src/gallium/drivers/svga/svga_draw_private.h b/src/gallium/drivers/svga/svga_draw_private.h new file mode 100644 index 0000000..11afb59 --- /dev/null +++ b/src/gallium/drivers/svga/svga_draw_private.h @@ -0,0 +1,158 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_DRAW_H_ +#define SVGA_DRAW_H_ + +#include "pipe/p_compiler.h" +#include "pipe/p_defines.h" +#include "indices/u_indices.h" +#include "svga_hw_reg.h" +#include "svga3d_shaderdefs.h" + +struct svga_context; +struct u_upload_mgr; + +/* Should include polygon? + */ +static const unsigned svga_hw_prims = + ((1 << PIPE_PRIM_POINTS) | + (1 << PIPE_PRIM_LINES) | + (1 << PIPE_PRIM_LINE_STRIP) | + (1 << PIPE_PRIM_TRIANGLES) | + (1 << PIPE_PRIM_TRIANGLE_STRIP) | + (1 << PIPE_PRIM_TRIANGLE_FAN)); + + +static INLINE unsigned svga_translate_prim(unsigned mode, + unsigned count, + unsigned *out_count) +{ + switch (mode) { + case PIPE_PRIM_POINTS: + *out_count = count; + return SVGA3D_PRIMITIVE_POINTLIST; + + case PIPE_PRIM_LINES: + *out_count = count / 2; + return SVGA3D_PRIMITIVE_LINELIST; + + case PIPE_PRIM_LINE_STRIP: + *out_count = count - 1; + return SVGA3D_PRIMITIVE_LINESTRIP; + + case PIPE_PRIM_TRIANGLES: + *out_count = count / 3; + return SVGA3D_PRIMITIVE_TRIANGLELIST; + + case PIPE_PRIM_TRIANGLE_STRIP: + *out_count = count - 2; + return SVGA3D_PRIMITIVE_TRIANGLESTRIP; + + case PIPE_PRIM_TRIANGLE_FAN: + *out_count = count - 2; + return SVGA3D_PRIMITIVE_TRIANGLEFAN; + + default: + assert(0); + *out_count = 0; + return 0; + } +} + + +struct index_cache { + u_generate_func generate; + unsigned gen_nr; + + /* If non-null, this buffer is filled by calling + * generate(nr, map(buffer)) + */ + struct pipe_resource *buffer; +}; + +#define QSZ 32 + +struct draw_cmd { + struct svga_winsys_context *swc; + + SVGA3dVertexDecl vdecl[SVGA3D_INPUTREG_MAX]; + struct pipe_resource *vdecl_vb[SVGA3D_INPUTREG_MAX]; + unsigned vdecl_count; + + SVGA3dPrimitiveRange prim[QSZ]; + struct pipe_resource *prim_ib[QSZ]; + unsigned prim_count; + unsigned min_index[QSZ]; + unsigned max_index[QSZ]; +}; + +#define IDX_CACHE_MAX 8 + +struct svga_hwtnl { + struct svga_context *svga; + struct u_upload_mgr *upload_ib; + + /* Flatshade information: + */ + unsigned api_pv; + unsigned hw_pv; + unsigned api_fillmode; + + /* Cache the results of running a particular generate func on each + * primitive type. + */ + struct index_cache index_cache[PIPE_PRIM_MAX][IDX_CACHE_MAX]; + + /* Try to build the maximal draw command packet before emitting: + */ + struct draw_cmd cmd; +}; + + + +/*********************************************************************** + * Internal functions + */ +enum pipe_error +svga_hwtnl_prim( struct svga_hwtnl *hwtnl, + const SVGA3dPrimitiveRange *range, + unsigned min_index, + unsigned max_index, + struct pipe_resource *ib ); + +enum pipe_error +svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl *hwtnl, + struct pipe_resource *indexBuffer, + unsigned index_size, + int index_bias, + unsigned min_index, + unsigned max_index, + unsigned prim, + unsigned start, + unsigned count ); + + +#endif diff --git a/src/gallium/drivers/svga/svga_hw_reg.h b/src/gallium/drivers/svga/svga_hw_reg.h new file mode 100644 index 0000000..183f4b9 --- /dev/null +++ b/src/gallium/drivers/svga/svga_hw_reg.h @@ -0,0 +1,42 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_HW_REG_H +#define SVGA_HW_REG_H + +#include "pipe/p_compiler.h" + +#if defined(PIPE_CC_GCC) +#ifndef HAVE_STDINT_H +#define HAVE_STDINT_H +#endif +#endif + +#include "svga_types.h" + +#include "svga3d_reg.h" + + +#endif diff --git a/src/gallium/drivers/svga/svga_pipe_blend.c b/src/gallium/drivers/svga/svga_pipe_blend.c new file mode 100644 index 0000000..594eec7 --- /dev/null +++ b/src/gallium/drivers/svga/svga_pipe_blend.c @@ -0,0 +1,240 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "pipe/p_defines.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "svga_context.h" + +#include "svga_hw_reg.h" + + +static INLINE unsigned +svga_translate_blend_factor(unsigned factor) +{ + switch (factor) { + case PIPE_BLENDFACTOR_ZERO: return SVGA3D_BLENDOP_ZERO; + case PIPE_BLENDFACTOR_SRC_ALPHA: return SVGA3D_BLENDOP_SRCALPHA; + case PIPE_BLENDFACTOR_ONE: return SVGA3D_BLENDOP_ONE; + case PIPE_BLENDFACTOR_SRC_COLOR: return SVGA3D_BLENDOP_SRCCOLOR; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: return SVGA3D_BLENDOP_INVSRCCOLOR; + case PIPE_BLENDFACTOR_DST_COLOR: return SVGA3D_BLENDOP_DESTCOLOR; + case PIPE_BLENDFACTOR_INV_DST_COLOR: return SVGA3D_BLENDOP_INVDESTCOLOR; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: return SVGA3D_BLENDOP_INVSRCALPHA; + case PIPE_BLENDFACTOR_DST_ALPHA: return SVGA3D_BLENDOP_DESTALPHA; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: return SVGA3D_BLENDOP_INVDESTALPHA; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: return SVGA3D_BLENDOP_SRCALPHASAT; + case PIPE_BLENDFACTOR_CONST_COLOR: return SVGA3D_BLENDOP_BLENDFACTOR; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: return SVGA3D_BLENDOP_INVBLENDFACTOR; + case PIPE_BLENDFACTOR_CONST_ALPHA: return SVGA3D_BLENDOP_BLENDFACTOR; /* ? */ + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: return SVGA3D_BLENDOP_INVBLENDFACTOR; /* ? */ + default: + assert(0); + return SVGA3D_BLENDOP_ZERO; + } +} + +static INLINE unsigned +svga_translate_blend_func(unsigned mode) +{ + switch (mode) { + case PIPE_BLEND_ADD: return SVGA3D_BLENDEQ_ADD; + case PIPE_BLEND_SUBTRACT: return SVGA3D_BLENDEQ_SUBTRACT; + case PIPE_BLEND_REVERSE_SUBTRACT: return SVGA3D_BLENDEQ_REVSUBTRACT; + case PIPE_BLEND_MIN: return SVGA3D_BLENDEQ_MINIMUM; + case PIPE_BLEND_MAX: return SVGA3D_BLENDEQ_MAXIMUM; + default: + assert(0); + return SVGA3D_BLENDEQ_ADD; + } +} + + +static void * +svga_create_blend_state(struct pipe_context *pipe, + const struct pipe_blend_state *templ) +{ + struct svga_blend_state *blend = CALLOC_STRUCT( svga_blend_state ); + unsigned i; + + + /* Fill in the per-rendertarget blend state. We currently only + * have one rendertarget. + */ + for (i = 0; i < 1; i++) { + /* No way to set this in SVGA3D, and no way to correctly implement it on + * top of D3D9 API. Instead we try to simulate with various blend modes. + */ + if (templ->logicop_enable) { + switch (templ->logicop_func) { + case PIPE_LOGICOP_XOR: + case PIPE_LOGICOP_INVERT: + blend->need_white_fragments = TRUE; + blend->rt[i].blend_enable = TRUE; + blend->rt[i].srcblend = SVGA3D_BLENDOP_ONE; + blend->rt[i].dstblend = SVGA3D_BLENDOP_ONE; + blend->rt[i].blendeq = SVGA3D_BLENDEQ_SUBTRACT; + break; + case PIPE_LOGICOP_CLEAR: + blend->rt[i].blend_enable = TRUE; + blend->rt[i].srcblend = SVGA3D_BLENDOP_ZERO; + blend->rt[i].dstblend = SVGA3D_BLENDOP_ZERO; + blend->rt[i].blendeq = SVGA3D_BLENDEQ_MINIMUM; + break; + case PIPE_LOGICOP_COPY: + blend->rt[i].blend_enable = FALSE; + break; + case PIPE_LOGICOP_COPY_INVERTED: + blend->rt[i].blend_enable = TRUE; + blend->rt[i].srcblend = SVGA3D_BLENDOP_INVSRCCOLOR; + blend->rt[i].dstblend = SVGA3D_BLENDOP_ZERO; + blend->rt[i].blendeq = SVGA3D_BLENDEQ_ADD; + break; + case PIPE_LOGICOP_NOOP: + blend->rt[i].blend_enable = TRUE; + blend->rt[i].srcblend = SVGA3D_BLENDOP_ZERO; + blend->rt[i].dstblend = SVGA3D_BLENDOP_DESTCOLOR; + blend->rt[i].blendeq = SVGA3D_BLENDEQ_ADD; + break; + case PIPE_LOGICOP_SET: + blend->rt[i].blend_enable = TRUE; + blend->rt[i].srcblend = SVGA3D_BLENDOP_ONE; + blend->rt[i].dstblend = SVGA3D_BLENDOP_ONE; + blend->rt[i].blendeq = SVGA3D_BLENDEQ_MAXIMUM; + break; + case PIPE_LOGICOP_AND: + /* Approximate with minimum - works for the 0 & anything case: */ + blend->rt[i].blend_enable = TRUE; + blend->rt[i].srcblend = SVGA3D_BLENDOP_SRCCOLOR; + blend->rt[i].dstblend = SVGA3D_BLENDOP_DESTCOLOR; + blend->rt[i].blendeq = SVGA3D_BLENDEQ_MINIMUM; + break; + case PIPE_LOGICOP_AND_REVERSE: + blend->rt[i].blend_enable = TRUE; + blend->rt[i].srcblend = SVGA3D_BLENDOP_SRCCOLOR; + blend->rt[i].dstblend = SVGA3D_BLENDOP_INVDESTCOLOR; + blend->rt[i].blendeq = SVGA3D_BLENDEQ_MINIMUM; + break; + case PIPE_LOGICOP_AND_INVERTED: + blend->rt[i].blend_enable = TRUE; + blend->rt[i].srcblend = SVGA3D_BLENDOP_INVSRCCOLOR; + blend->rt[i].dstblend = SVGA3D_BLENDOP_DESTCOLOR; + blend->rt[i].blendeq = SVGA3D_BLENDEQ_MINIMUM; + break; + case PIPE_LOGICOP_OR: + /* Approximate with maximum - works for the 1 | anything case: */ + blend->rt[i].blend_enable = TRUE; + blend->rt[i].srcblend = SVGA3D_BLENDOP_SRCCOLOR; + blend->rt[i].dstblend = SVGA3D_BLENDOP_DESTCOLOR; + blend->rt[i].blendeq = SVGA3D_BLENDEQ_MAXIMUM; + break; + case PIPE_LOGICOP_OR_REVERSE: + blend->rt[i].blend_enable = TRUE; + blend->rt[i].srcblend = SVGA3D_BLENDOP_SRCCOLOR; + blend->rt[i].dstblend = SVGA3D_BLENDOP_INVDESTCOLOR; + blend->rt[i].blendeq = SVGA3D_BLENDEQ_MAXIMUM; + break; + case PIPE_LOGICOP_OR_INVERTED: + blend->rt[i].blend_enable = TRUE; + blend->rt[i].srcblend = SVGA3D_BLENDOP_INVSRCCOLOR; + blend->rt[i].dstblend = SVGA3D_BLENDOP_DESTCOLOR; + blend->rt[i].blendeq = SVGA3D_BLENDEQ_MAXIMUM; + break; + case PIPE_LOGICOP_NAND: + case PIPE_LOGICOP_NOR: + case PIPE_LOGICOP_EQUIV: + /* Fill these in with plausible values */ + blend->rt[i].blend_enable = FALSE; + break; + default: + assert(0); + break; + } + } + else { + blend->rt[i].blend_enable = templ->rt[0].blend_enable; + + if (templ->rt[0].blend_enable) { + blend->rt[i].srcblend = svga_translate_blend_factor(templ->rt[0].rgb_src_factor); + blend->rt[i].dstblend = svga_translate_blend_factor(templ->rt[0].rgb_dst_factor); + blend->rt[i].blendeq = svga_translate_blend_func(templ->rt[0].rgb_func); + blend->rt[i].srcblend_alpha = svga_translate_blend_factor(templ->rt[0].alpha_src_factor); + blend->rt[i].dstblend_alpha = svga_translate_blend_factor(templ->rt[0].alpha_dst_factor); + blend->rt[i].blendeq_alpha = svga_translate_blend_func(templ->rt[0].alpha_func); + + if (blend->rt[i].srcblend_alpha != blend->rt[i].srcblend || + blend->rt[i].dstblend_alpha != blend->rt[i].dstblend || + blend->rt[i].blendeq_alpha != blend->rt[i].blendeq) + { + blend->rt[i].separate_alpha_blend_enable = TRUE; + } + } + } + + blend->rt[i].writemask = templ->rt[0].colormask; + } + + return blend; +} + +static void svga_bind_blend_state(struct pipe_context *pipe, + void *blend) +{ + struct svga_context *svga = svga_context(pipe); + + svga->curr.blend = (struct svga_blend_state*)blend; + svga->dirty |= SVGA_NEW_BLEND; +} + + +static void svga_delete_blend_state(struct pipe_context *pipe, void *blend) +{ + FREE(blend); +} + +static void svga_set_blend_color( struct pipe_context *pipe, + const struct pipe_blend_color *blend_color ) +{ + struct svga_context *svga = svga_context(pipe); + + svga->curr.blend_color = *blend_color; + + svga->dirty |= SVGA_NEW_BLEND_COLOR; +} + + +void svga_init_blend_functions( struct svga_context *svga ) +{ + svga->pipe.create_blend_state = svga_create_blend_state; + svga->pipe.bind_blend_state = svga_bind_blend_state; + svga->pipe.delete_blend_state = svga_delete_blend_state; + + svga->pipe.set_blend_color = svga_set_blend_color; +} + + + diff --git a/src/gallium/drivers/svga/svga_pipe_blit.c b/src/gallium/drivers/svga/svga_pipe_blit.c new file mode 100644 index 0000000..4266988 --- /dev/null +++ b/src/gallium/drivers/svga/svga_pipe_blit.c @@ -0,0 +1,144 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "svga_resource_texture.h" +#include "svga_context.h" +#include "svga_debug.h" +#include "svga_cmd.h" +#include "svga_surface.h" + +#define FILE_DEBUG_FLAG DEBUG_BLIT + + +/* XXX still have doubts about this... */ +static void svga_surface_copy(struct pipe_context *pipe, + struct pipe_resource* dst_tex, + unsigned dst_level, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource* src_tex, + unsigned src_level, + const struct pipe_box *src_box) + { + struct svga_context *svga = svga_context(pipe); + struct svga_texture *stex = svga_texture(src_tex); + struct svga_texture *dtex = svga_texture(dst_tex); +/* struct pipe_screen *screen = pipe->screen; + SVGA3dCopyBox *box; + enum pipe_error ret; + struct pipe_surface *srcsurf, *dstsurf;*/ + unsigned dst_face, dst_z, src_face, src_z; + + svga_hwtnl_flush_retry( svga ); + +#if 0 + srcsurf = screen->get_tex_surface(screen, src_tex, + src_level, src_box->z, src_box->z, + PIPE_BIND_SAMPLER_VIEW); + + dstsurf = screen->get_tex_surface(screen, dst_tex, + dst_level, dst_box->z, dst_box->z, + PIPE_BIND_RENDER_TARGET); + + SVGA_DBG(DEBUG_DMA, "blit to sid %p (%d,%d), from sid %p (%d,%d) sz %dx%d\n", + svga_surface(dstsurf)->handle, + dstx, dsty, + svga_surface(srcsurf)->handle, + src_box->x, src_box->y, + width, height); + + ret = SVGA3D_BeginSurfaceCopy(svga->swc, + srcsurf, + dstsurf, + &box, + 1); + if(ret != PIPE_OK) { + + svga_context_flush(svga, NULL); + + ret = SVGA3D_BeginSurfaceCopy(svga->swc, + srcsurf, + dstsurf, + &box, + 1); + assert(ret == PIPE_OK); + } + + box->x = dstx; + box->y = dsty; + box->z = 0; + box->w = width; + box->h = height; + box->d = 1; + box->srcx = src_box->x; + box->srcy = src_box->y; + box->srcz = 0; + + SVGA_FIFOCommitAll(svga->swc); + + svga_surface(dstsurf)->dirty = TRUE; + svga_propagate_surface(pipe, dstsurf); + + pipe_surface_reference(&srcsurf, NULL); + pipe_surface_reference(&dstsurf, NULL); + +#else + if (src_tex->target == PIPE_TEXTURE_CUBE) { + src_face = src_box->z; + src_z = 0; + assert(src_box->depth == 1); + } + else { + src_face = 0; + src_z = src_box->z; + } + /* different src/dst type???*/ + if (dst_tex->target == PIPE_TEXTURE_CUBE) { + dst_face = dstz; + dst_z = 0; + assert(src_box->depth == 1); + } + else { + dst_face = 0; + dst_z = dstz; + } + svga_texture_copy_handle(svga, + stex->handle, + src_box->x, src_box->y, src_z, + src_level, src_face, + dtex->handle, + dstx, dsty, dst_z, + dst_level, dst_face, + src_box->width, src_box->height, src_box->depth); + +#endif + +} + + +void +svga_init_blit_functions(struct svga_context *svga) +{ + svga->pipe.resource_copy_region = svga_surface_copy; +} diff --git a/src/gallium/drivers/svga/svga_pipe_clear.c b/src/gallium/drivers/svga/svga_pipe_clear.c new file mode 100644 index 0000000..41f239c --- /dev/null +++ b/src/gallium/drivers/svga/svga_pipe_clear.c @@ -0,0 +1,127 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "svga_cmd.h" +#include "svga_debug.h" + +#include "pipe/p_defines.h" +#include "util/u_pack_color.h" + +#include "svga_context.h" +#include "svga_state.h" +#include "svga_surface.h" + + +static enum pipe_error +try_clear(struct svga_context *svga, + unsigned buffers, + const float *rgba, + double depth, + unsigned stencil) +{ + int ret = PIPE_OK; + SVGA3dRect rect = { 0, 0, 0, 0 }; + boolean restore_viewport = FALSE; + SVGA3dClearFlag flags = 0; + struct pipe_framebuffer_state *fb = &svga->curr.framebuffer; + union util_color uc; + + ret = svga_update_state(svga, SVGA_STATE_HW_CLEAR); + if (ret) + return ret; + + if ((buffers & PIPE_CLEAR_COLOR) && fb->cbufs[0]) { + flags |= SVGA3D_CLEAR_COLOR; + util_pack_color(rgba, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); + + rect.w = fb->cbufs[0]->width; + rect.h = fb->cbufs[0]->height; + } + + if ((buffers & PIPE_CLEAR_DEPTHSTENCIL) && fb->zsbuf) { + if (buffers & PIPE_CLEAR_DEPTH) + flags |= SVGA3D_CLEAR_DEPTH; + + if ((svga->curr.framebuffer.zsbuf->format == PIPE_FORMAT_S8_USCALED_Z24_UNORM) && + (buffers & PIPE_CLEAR_STENCIL)) + flags |= SVGA3D_CLEAR_STENCIL; + + rect.w = MAX2(rect.w, fb->zsbuf->width); + rect.h = MAX2(rect.h, fb->zsbuf->height); + } + + if (memcmp(&rect, &svga->state.hw_clear.viewport, sizeof(rect)) != 0) { + restore_viewport = TRUE; + ret = SVGA3D_SetViewport(svga->swc, &rect); + if (ret) + return ret; + } + + ret = SVGA3D_ClearRect(svga->swc, flags, uc.ui, depth, stencil, + rect.x, rect.y, rect.w, rect.h); + if (ret != PIPE_OK) + return ret; + + if (restore_viewport) { + memcpy(&rect, &svga->state.hw_clear.viewport, sizeof rect); + ret = SVGA3D_SetViewport(svga->swc, &rect); + } + + return ret; +} + +/** + * Clear the given surface to the specified value. + * No masking, no scissor (clear entire buffer). + */ +void +svga_clear(struct pipe_context *pipe, unsigned buffers, const float *rgba, + double depth, unsigned stencil) +{ + struct svga_context *svga = svga_context( pipe ); + int ret; + + if (buffers & PIPE_CLEAR_COLOR) + SVGA_DBG(DEBUG_DMA, "clear sid %p\n", + svga_surface(svga->curr.framebuffer.cbufs[0])->handle); + + ret = try_clear( svga, buffers, rgba, depth, stencil ); + + if (ret == PIPE_ERROR_OUT_OF_MEMORY) { + /* Flush command buffer and retry: + */ + svga_context_flush( svga, NULL ); + + ret = try_clear( svga, buffers, rgba, depth, stencil ); + } + + /* + * Mark target surfaces as dirty + * TODO Mark only cleared surfaces. + */ + svga_mark_surfaces_dirty(svga); + + assert (ret == PIPE_OK); +} diff --git a/src/gallium/drivers/svga/svga_pipe_constants.c b/src/gallium/drivers/svga/svga_pipe_constants.c new file mode 100644 index 0000000..2fa2142 --- /dev/null +++ b/src/gallium/drivers/svga/svga_pipe_constants.c @@ -0,0 +1,70 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "pipe/p_defines.h" +#include "util/u_math.h" +#include "tgsi/tgsi_parse.h" + +#include "svga_context.h" + +/*********************************************************************** + * Constant buffers + */ + +struct svga_constbuf +{ + unsigned type; + float (*data)[4]; + unsigned count; +}; + + + +static void svga_set_constant_buffer(struct pipe_context *pipe, + uint shader, uint index, + struct pipe_resource *buf) +{ + struct svga_context *svga = svga_context(pipe); + + assert(shader < PIPE_SHADER_TYPES); + assert(index == 0); + + pipe_resource_reference( &svga->curr.cb[shader], + buf ); + + if (shader == PIPE_SHADER_FRAGMENT) + svga->dirty |= SVGA_NEW_FS_CONST_BUFFER; + else + svga->dirty |= SVGA_NEW_VS_CONST_BUFFER; +} + + + +void svga_init_constbuffer_functions( struct svga_context *svga ) +{ + svga->pipe.set_constant_buffer = svga_set_constant_buffer; +} + diff --git a/src/gallium/drivers/svga/svga_pipe_depthstencil.c b/src/gallium/drivers/svga/svga_pipe_depthstencil.c new file mode 100644 index 0000000..c84615a --- /dev/null +++ b/src/gallium/drivers/svga/svga_pipe_depthstencil.c @@ -0,0 +1,169 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "pipe/p_defines.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "svga_context.h" +#include "svga_hw_reg.h" + + +static INLINE unsigned +svga_translate_compare_func(unsigned func) +{ + switch (func) { + case PIPE_FUNC_NEVER: return SVGA3D_CMP_NEVER; + case PIPE_FUNC_LESS: return SVGA3D_CMP_LESS; + case PIPE_FUNC_LEQUAL: return SVGA3D_CMP_LESSEQUAL; + case PIPE_FUNC_GREATER: return SVGA3D_CMP_GREATER; + case PIPE_FUNC_GEQUAL: return SVGA3D_CMP_GREATEREQUAL; + case PIPE_FUNC_NOTEQUAL: return SVGA3D_CMP_NOTEQUAL; + case PIPE_FUNC_EQUAL: return SVGA3D_CMP_EQUAL; + case PIPE_FUNC_ALWAYS: return SVGA3D_CMP_ALWAYS; + default: + assert(0); + return SVGA3D_CMP_ALWAYS; + } +} + +static INLINE unsigned +svga_translate_stencil_op(unsigned op) +{ + switch (op) { + case PIPE_STENCIL_OP_KEEP: return SVGA3D_STENCILOP_KEEP; + case PIPE_STENCIL_OP_ZERO: return SVGA3D_STENCILOP_ZERO; + case PIPE_STENCIL_OP_REPLACE: return SVGA3D_STENCILOP_REPLACE; + case PIPE_STENCIL_OP_INCR: return SVGA3D_STENCILOP_INCR; + case PIPE_STENCIL_OP_DECR: return SVGA3D_STENCILOP_DECR; + case PIPE_STENCIL_OP_INCR_WRAP: return SVGA3D_STENCILOP_INCRSAT; /* incorrect? */ + case PIPE_STENCIL_OP_DECR_WRAP: return SVGA3D_STENCILOP_DECRSAT; /* incorrect? */ + case PIPE_STENCIL_OP_INVERT: return SVGA3D_STENCILOP_INVERT; + default: + assert(0); + return SVGA3D_STENCILOP_KEEP; + } +} + + +static void * +svga_create_depth_stencil_state(struct pipe_context *pipe, + const struct pipe_depth_stencil_alpha_state *templ) +{ + struct svga_depth_stencil_state *ds = CALLOC_STRUCT( svga_depth_stencil_state ); + + /* Don't try to figure out CW/CCW correspondence with + * stencil[0]/[1] at this point. Presumably this can change as + * back/front face are modified. + */ + ds->stencil[0].enabled = templ->stencil[0].enabled; + if (ds->stencil[0].enabled) { + ds->stencil[0].func = svga_translate_compare_func(templ->stencil[0].func); + ds->stencil[0].fail = svga_translate_stencil_op(templ->stencil[0].fail_op); + ds->stencil[0].zfail = svga_translate_stencil_op(templ->stencil[0].zfail_op); + ds->stencil[0].pass = svga_translate_stencil_op(templ->stencil[0].zpass_op); + + /* SVGA3D has one ref/mask/writemask triple shared between front & + * back face stencil. We really need two: + */ + ds->stencil_mask = templ->stencil[0].valuemask & 0xff; + ds->stencil_writemask = templ->stencil[0].writemask & 0xff; + } + + + ds->stencil[1].enabled = templ->stencil[1].enabled; + if (templ->stencil[1].enabled) { + ds->stencil[1].func = svga_translate_compare_func(templ->stencil[1].func); + ds->stencil[1].fail = svga_translate_stencil_op(templ->stencil[1].fail_op); + ds->stencil[1].zfail = svga_translate_stencil_op(templ->stencil[1].zfail_op); + ds->stencil[1].pass = svga_translate_stencil_op(templ->stencil[1].zpass_op); + + ds->stencil_mask = templ->stencil[1].valuemask & 0xff; + ds->stencil_writemask = templ->stencil[1].writemask & 0xff; + } + + + ds->zenable = templ->depth.enabled; + if (ds->zenable) { + ds->zfunc = svga_translate_compare_func(templ->depth.func); + ds->zwriteenable = templ->depth.writemask; + } + + ds->alphatestenable = templ->alpha.enabled; + if (ds->alphatestenable) { + ds->alphafunc = svga_translate_compare_func(templ->alpha.func); + ds->alpharef = templ->alpha.ref_value; + } + + return ds; +} + +static void svga_bind_depth_stencil_state(struct pipe_context *pipe, + void *depth_stencil) +{ + struct svga_context *svga = svga_context(pipe); + + svga->curr.depth = (const struct svga_depth_stencil_state *)depth_stencil; + svga->dirty |= SVGA_NEW_DEPTH_STENCIL; +} + +static void svga_delete_depth_stencil_state(struct pipe_context *pipe, + void *depth_stencil) +{ + FREE(depth_stencil); +} + + +static void svga_set_stencil_ref( struct pipe_context *pipe, + const struct pipe_stencil_ref *stencil_ref ) +{ + struct svga_context *svga = svga_context(pipe); + + svga->curr.stencil_ref = *stencil_ref; + + svga->dirty |= SVGA_NEW_STENCIL_REF; +} + +static void +svga_set_sample_mask(struct pipe_context *pipe, + unsigned sample_mask) +{ +} + + +void svga_init_depth_stencil_functions( struct svga_context *svga ) +{ + svga->pipe.create_depth_stencil_alpha_state = svga_create_depth_stencil_state; + svga->pipe.bind_depth_stencil_alpha_state = svga_bind_depth_stencil_state; + svga->pipe.delete_depth_stencil_alpha_state = svga_delete_depth_stencil_state; + + svga->pipe.set_stencil_ref = svga_set_stencil_ref; + svga->pipe.set_sample_mask = svga_set_sample_mask; +} + + + + diff --git a/src/gallium/drivers/svga/svga_pipe_draw.c b/src/gallium/drivers/svga/svga_pipe_draw.c new file mode 100644 index 0000000..001ec36 --- /dev/null +++ b/src/gallium/drivers/svga/svga_pipe_draw.c @@ -0,0 +1,222 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "svga_cmd.h" + +#include "util/u_inlines.h" +#include "util/u_prim.h" +#include "util/u_time.h" +#include "indices/u_indices.h" + +#include "svga_hw_reg.h" +#include "svga_context.h" +#include "svga_screen.h" +#include "svga_draw.h" +#include "svga_state.h" +#include "svga_swtnl.h" +#include "svga_debug.h" + + + +static enum pipe_error +retry_draw_range_elements( struct svga_context *svga, + struct pipe_resource *index_buffer, + unsigned index_size, + int index_bias, + unsigned min_index, + unsigned max_index, + unsigned prim, + unsigned start, + unsigned count, + boolean do_retry ) +{ + enum pipe_error ret = 0; + + svga_hwtnl_set_unfilled( svga->hwtnl, + svga->curr.rast->hw_unfilled ); + + svga_hwtnl_set_flatshade( svga->hwtnl, + svga->curr.rast->templ.flatshade, + svga->curr.rast->templ.flatshade_first ); + + + ret = svga_update_state( svga, SVGA_STATE_HW_DRAW ); + if (ret) + goto retry; + + ret = svga_hwtnl_draw_range_elements( svga->hwtnl, + index_buffer, index_size, index_bias, + min_index, max_index, + prim, start, count ); + if (ret) + goto retry; + + if (svga->curr.any_user_vertex_buffers) { + ret = svga_hwtnl_flush( svga->hwtnl ); + if (ret) + goto retry; + } + + return PIPE_OK; + +retry: + svga_context_flush( svga, NULL ); + + if (do_retry) + { + return retry_draw_range_elements( svga, + index_buffer, index_size, index_bias, + min_index, max_index, + prim, start, count, + FALSE ); + } + + return ret; +} + + +static enum pipe_error +retry_draw_arrays( struct svga_context *svga, + unsigned prim, + unsigned start, + unsigned count, + boolean do_retry ) +{ + enum pipe_error ret; + + svga_hwtnl_set_unfilled( svga->hwtnl, + svga->curr.rast->hw_unfilled ); + + svga_hwtnl_set_flatshade( svga->hwtnl, + svga->curr.rast->templ.flatshade, + svga->curr.rast->templ.flatshade_first ); + + ret = svga_update_state( svga, SVGA_STATE_HW_DRAW ); + if (ret) + goto retry; + + ret = svga_hwtnl_draw_arrays( svga->hwtnl, prim, + start, count ); + if (ret) + goto retry; + + if (svga->curr.any_user_vertex_buffers) { + ret = svga_hwtnl_flush( svga->hwtnl ); + if (ret) + goto retry; + } + + return 0; + +retry: + if (ret == PIPE_ERROR_OUT_OF_MEMORY && do_retry) + { + svga_context_flush( svga, NULL ); + + return retry_draw_arrays( svga, + prim, + start, + count, + FALSE ); + } + + return ret; +} + + +static void +svga_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) +{ + struct svga_context *svga = svga_context( pipe ); + unsigned reduced_prim = u_reduced_prim( info->mode ); + unsigned count = info->count; + enum pipe_error ret = 0; + + if (!u_trim_pipe_prim( info->mode, &count )) + return; + + /* + * Mark currently bound target surfaces as dirty + * doesn't really matter if it is done before drawing. + * + * TODO If we ever normaly return something other then + * true we should not mark it as dirty then. + */ + svga_mark_surfaces_dirty(svga_context(pipe)); + + if (svga->curr.reduced_prim != reduced_prim) { + svga->curr.reduced_prim = reduced_prim; + svga->dirty |= SVGA_NEW_REDUCED_PRIMITIVE; + } + + svga_update_state_retry( svga, SVGA_STATE_NEED_SWTNL ); + +#ifdef DEBUG + if (svga->curr.vs->base.id == svga->debug.disable_shader || + svga->curr.fs->base.id == svga->debug.disable_shader) + return; +#endif + + if (svga->state.sw.need_swtnl) { + ret = svga_swtnl_draw_vbo( svga, info ); + } + else { + if (info->indexed && svga->curr.ib.buffer) { + unsigned offset; + + assert(svga->curr.ib.offset % svga->curr.ib.index_size == 0); + offset = svga->curr.ib.offset / svga->curr.ib.index_size; + + ret = retry_draw_range_elements( svga, + svga->curr.ib.buffer, + svga->curr.ib.index_size, + info->index_bias, + info->min_index, + info->max_index, + info->mode, + info->start + offset, + info->count, + TRUE ); + } + else { + ret = retry_draw_arrays( svga, + info->mode, + info->start, + info->count, + TRUE ); + } + } + + if (SVGA_DEBUG & DEBUG_FLUSH) { + svga_hwtnl_flush_retry( svga ); + svga_context_flush(svga, NULL); + } +} + + +void svga_init_draw_functions( struct svga_context *svga ) +{ + svga->pipe.draw_vbo = svga_draw_vbo; +} diff --git a/src/gallium/drivers/svga/svga_pipe_flush.c b/src/gallium/drivers/svga/svga_pipe_flush.c new file mode 100644 index 0000000..ab243aa --- /dev/null +++ b/src/gallium/drivers/svga/svga_pipe_flush.c @@ -0,0 +1,65 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "pipe/p_defines.h" +#include "svga_screen.h" +#include "svga_surface.h" +#include "svga_context.h" +#include "svga_debug.h" + + +static void svga_flush( struct pipe_context *pipe, + unsigned flags, + struct pipe_fence_handle **fence ) +{ + struct svga_context *svga = svga_context(pipe); + int i; + + /* Emit buffered drawing commands. + */ + svga_hwtnl_flush_retry( svga ); + + /* Emit back-copy from render target view to texture. + */ + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + if (svga->curr.framebuffer.cbufs[i]) + svga_propagate_surface(pipe, svga->curr.framebuffer.cbufs[i]); + } + if (svga->curr.framebuffer.zsbuf) + svga_propagate_surface(pipe, svga->curr.framebuffer.zsbuf); + + /* Flush command queue. + */ + svga_context_flush(svga, fence); + + SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "%s flags %x fence_ptr %p\n", + __FUNCTION__, flags, fence ? *fence : 0x0); +} + + +void svga_init_flush_functions( struct svga_context *svga ) +{ + svga->pipe.flush = svga_flush; +} diff --git a/src/gallium/drivers/svga/svga_pipe_fs.c b/src/gallium/drivers/svga/svga_pipe_fs.c new file mode 100644 index 0000000..b71bc66 --- /dev/null +++ b/src/gallium/drivers/svga/svga_pipe_fs.c @@ -0,0 +1,131 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_bitmask.h" +#include "tgsi/tgsi_parse.h" + +#include "svga_screen.h" +#include "svga_context.h" +#include "svga_tgsi.h" +#include "svga_hw_reg.h" +#include "svga_cmd.h" +#include "svga_debug.h" + + +/*********************************************************************** + * Fragment shaders + */ + +static void * +svga_create_fs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct svga_context *svga = svga_context(pipe); + struct svga_screen *svgascreen = svga_screen(pipe->screen); + struct svga_fragment_shader *fs; + + fs = CALLOC_STRUCT(svga_fragment_shader); + if (!fs) + return NULL; + + fs->base.tokens = tgsi_dup_tokens(templ->tokens); + + /* Collect basic info that we'll need later: + */ + tgsi_scan_shader(fs->base.tokens, &fs->base.info); + + fs->base.id = svga->debug.shader_id++; + fs->base.use_sm30 = svgascreen->use_ps30; + + if (SVGA_DEBUG & DEBUG_TGSI || 0) { + debug_printf("%s id: %u, inputs: %u, outputs: %u\n", + __FUNCTION__, fs->base.id, + fs->base.info.num_inputs, fs->base.info.num_outputs); + } + + return fs; +} + +static void +svga_bind_fs_state(struct pipe_context *pipe, void *shader) +{ + struct svga_fragment_shader *fs = (struct svga_fragment_shader *) shader; + struct svga_context *svga = svga_context(pipe); + + svga->curr.fs = fs; + svga->dirty |= SVGA_NEW_FS; +} + +static +void svga_delete_fs_state(struct pipe_context *pipe, void *shader) +{ + struct svga_context *svga = svga_context(pipe); + struct svga_fragment_shader *fs = (struct svga_fragment_shader *) shader; + struct svga_shader_result *result, *tmp; + enum pipe_error ret; + + svga_hwtnl_flush_retry( svga ); + + for (result = fs->base.results; result; result = tmp ) { + tmp = result->next; + + ret = SVGA3D_DestroyShader(svga->swc, + result->id, + SVGA3D_SHADERTYPE_PS ); + if(ret != PIPE_OK) { + svga_context_flush(svga, NULL); + ret = SVGA3D_DestroyShader(svga->swc, + result->id, + SVGA3D_SHADERTYPE_PS ); + assert(ret == PIPE_OK); + } + + util_bitmask_clear( svga->fs_bm, result->id ); + + svga_destroy_shader_result( result ); + + /* + * Remove stale references to this result to ensure a new result on the + * same address will be detected as a change. + */ + if(result == svga->state.hw_draw.fs) + svga->state.hw_draw.fs = NULL; + } + + FREE((void *)fs->base.tokens); + FREE(fs); +} + + +void svga_init_fs_functions( struct svga_context *svga ) +{ + svga->pipe.create_fs_state = svga_create_fs_state; + svga->pipe.bind_fs_state = svga_bind_fs_state; + svga->pipe.delete_fs_state = svga_delete_fs_state; +} + diff --git a/src/gallium/drivers/svga/svga_pipe_misc.c b/src/gallium/drivers/svga/svga_pipe_misc.c new file mode 100644 index 0000000..8c24fb3 --- /dev/null +++ b/src/gallium/drivers/svga/svga_pipe_misc.c @@ -0,0 +1,183 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "svga_cmd.h" + +#include "util/u_inlines.h" + +#include "svga_context.h" +#include "svga_surface.h" + + +static void svga_set_scissor_state( struct pipe_context *pipe, + const struct pipe_scissor_state *scissor ) +{ + struct svga_context *svga = svga_context(pipe); + + memcpy( &svga->curr.scissor, scissor, sizeof(*scissor) ); + svga->dirty |= SVGA_NEW_SCISSOR; +} + + +static void svga_set_polygon_stipple( struct pipe_context *pipe, + const struct pipe_poly_stipple *stipple ) +{ + /* overridden by the draw module */ +} + + +void svga_cleanup_framebuffer(struct svga_context *svga) +{ + struct pipe_framebuffer_state *curr = &svga->curr.framebuffer; + struct pipe_framebuffer_state *hw = &svga->state.hw_clear.framebuffer; + int i; + + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + pipe_surface_reference(&curr->cbufs[i], NULL); + pipe_surface_reference(&hw->cbufs[i], NULL); + } + + pipe_surface_reference(&curr->zsbuf, NULL); + pipe_surface_reference(&hw->zsbuf, NULL); +} + + +#define DEPTH_BIAS_SCALE_FACTOR_D16 ((float)(1<<15)) +#define DEPTH_BIAS_SCALE_FACTOR_D24S8 ((float)(1<<23)) +#define DEPTH_BIAS_SCALE_FACTOR_D32 ((float)(1<<31)) + + +static void svga_set_framebuffer_state(struct pipe_context *pipe, + const struct pipe_framebuffer_state *fb) +{ + struct svga_context *svga = svga_context(pipe); + struct pipe_framebuffer_state *dst = &svga->curr.framebuffer; + boolean propagate = FALSE; + int i; + + dst->width = fb->width; + dst->height = fb->height; + dst->nr_cbufs = fb->nr_cbufs; + + /* check if we need to propaget any of the target surfaces */ + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + if (dst->cbufs[i] && dst->cbufs[i] != fb->cbufs[i]) + if (svga_surface_needs_propagation(dst->cbufs[i])) + propagate = TRUE; + } + + if (propagate) { + /* make sure that drawing calls comes before propagation calls */ + svga_hwtnl_flush_retry( svga ); + + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) + if (dst->cbufs[i] && dst->cbufs[i] != fb->cbufs[i]) + svga_propagate_surface(pipe, dst->cbufs[i]); + } + + /* XXX: Actually the virtual hardware may support rendertargets with + * different size, depending on the host API and driver, but since we cannot + * know that make no such assumption here. */ + for(i = 0; i < fb->nr_cbufs; ++i) { + if (fb->zsbuf && fb->cbufs[i]) { + assert(fb->zsbuf->width == fb->cbufs[i]->width); + assert(fb->zsbuf->height == fb->cbufs[i]->height); + } + } + + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) + pipe_surface_reference(&dst->cbufs[i], fb->cbufs[i]); + pipe_surface_reference(&dst->zsbuf, fb->zsbuf); + + + if (svga->curr.framebuffer.zsbuf) + { + switch (svga->curr.framebuffer.zsbuf->format) { + case PIPE_FORMAT_Z16_UNORM: + svga->curr.depthscale = 1.0f / DEPTH_BIAS_SCALE_FACTOR_D16; + break; + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: + svga->curr.depthscale = 1.0f / DEPTH_BIAS_SCALE_FACTOR_D24S8; + break; + case PIPE_FORMAT_Z32_UNORM: + svga->curr.depthscale = 1.0f / DEPTH_BIAS_SCALE_FACTOR_D32; + break; + case PIPE_FORMAT_Z32_FLOAT: + svga->curr.depthscale = 1.0f / ((float)(1<<23)); + break; + default: + svga->curr.depthscale = 0.0f; + break; + } + } + else { + svga->curr.depthscale = 0.0f; + } + + svga->dirty |= SVGA_NEW_FRAME_BUFFER; +} + + + +static void svga_set_clip_state( struct pipe_context *pipe, + const struct pipe_clip_state *clip ) +{ + struct svga_context *svga = svga_context(pipe); + + svga->curr.clip = *clip; /* struct copy */ + + svga->dirty |= SVGA_NEW_CLIP; +} + + + +/* Called when driver state tracker notices changes to the viewport + * matrix: + */ +static void svga_set_viewport_state( struct pipe_context *pipe, + const struct pipe_viewport_state *viewport ) +{ + struct svga_context *svga = svga_context(pipe); + + svga->curr.viewport = *viewport; /* struct copy */ + + svga->dirty |= SVGA_NEW_VIEWPORT; +} + + + +void svga_init_misc_functions( struct svga_context *svga ) +{ + svga->pipe.set_scissor_state = svga_set_scissor_state; + svga->pipe.set_polygon_stipple = svga_set_polygon_stipple; + svga->pipe.set_framebuffer_state = svga_set_framebuffer_state; + svga->pipe.set_clip_state = svga_set_clip_state; + svga->pipe.set_viewport_state = svga_set_viewport_state; +} + + diff --git a/src/gallium/drivers/svga/svga_pipe_query.c b/src/gallium/drivers/svga/svga_pipe_query.c new file mode 100644 index 0000000..579f803 --- /dev/null +++ b/src/gallium/drivers/svga/svga_pipe_query.c @@ -0,0 +1,268 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "pipe/p_state.h" +#include "pipe/p_context.h" +#include "util/u_memory.h" + +#include "svga_cmd.h" +#include "svga_context.h" +#include "svga_screen.h" +#include "svga_resource_buffer.h" +#include "svga_winsys.h" +#include "svga_debug.h" + + +/* Fixme: want a public base class for all pipe structs, even if there + * isn't much in them. + */ +struct pipe_query { + int dummy; +}; + +struct svga_query { + struct pipe_query base; + SVGA3dQueryType type; + struct svga_winsys_buffer *hwbuf; + volatile SVGA3dQueryResult *queryResult; + struct pipe_fence_handle *fence; +}; + +/*********************************************************************** + * Inline conversion functions. These are better-typed than the + * macros used previously: + */ +static INLINE struct svga_query * +svga_query( struct pipe_query *q ) +{ + return (struct svga_query *)q; +} + +static boolean svga_get_query_result(struct pipe_context *pipe, + struct pipe_query *q, + boolean wait, + void *result); + +static struct pipe_query *svga_create_query( struct pipe_context *pipe, + unsigned query_type ) +{ + struct svga_context *svga = svga_context( pipe ); + struct svga_screen *svgascreen = svga_screen(pipe->screen); + struct svga_winsys_screen *sws = svgascreen->sws; + struct svga_query *sq; + + SVGA_DBG(DEBUG_QUERY, "%s\n", __FUNCTION__); + + sq = CALLOC_STRUCT(svga_query); + if (!sq) + goto no_sq; + + sq->type = SVGA3D_QUERYTYPE_OCCLUSION; + + sq->hwbuf = svga_winsys_buffer_create(svga, + 1, + SVGA_BUFFER_USAGE_PINNED, + sizeof *sq->queryResult); + if(!sq->hwbuf) + goto no_hwbuf; + + sq->queryResult = (SVGA3dQueryResult *)sws->buffer_map(sws, + sq->hwbuf, + PIPE_TRANSFER_WRITE); + if(!sq->queryResult) + goto no_query_result; + + sq->queryResult->totalSize = sizeof *sq->queryResult; + sq->queryResult->state = SVGA3D_QUERYSTATE_NEW; + + /* + * We request the buffer to be pinned and assume it is always mapped. + * + * The reason is that we don't want to wait for fences when checking the + * query status. + */ + sws->buffer_unmap(sws, sq->hwbuf); + + return &sq->base; + +no_query_result: + sws->buffer_destroy(sws, sq->hwbuf); +no_hwbuf: + FREE(sq); +no_sq: + return NULL; +} + +static void svga_destroy_query(struct pipe_context *pipe, + struct pipe_query *q) +{ + struct svga_screen *svgascreen = svga_screen(pipe->screen); + struct svga_winsys_screen *sws = svgascreen->sws; + struct svga_query *sq = svga_query( q ); + + SVGA_DBG(DEBUG_QUERY, "%s\n", __FUNCTION__); + sws->buffer_destroy(sws, sq->hwbuf); + sws->fence_reference(sws, &sq->fence, NULL); + FREE(sq); +} + +static void svga_begin_query(struct pipe_context *pipe, + struct pipe_query *q) +{ + struct svga_screen *svgascreen = svga_screen(pipe->screen); + struct svga_winsys_screen *sws = svgascreen->sws; + struct svga_context *svga = svga_context( pipe ); + struct svga_query *sq = svga_query( q ); + enum pipe_error ret; + + SVGA_DBG(DEBUG_QUERY, "%s\n", __FUNCTION__); + + assert(!svga->sq); + + /* Need to flush out buffered drawing commands so that they don't + * get counted in the query results. + */ + svga_hwtnl_flush_retry(svga); + + if(sq->queryResult->state == SVGA3D_QUERYSTATE_PENDING) { + /* The application doesn't care for the pending query result. We cannot + * let go the existing buffer and just get a new one because its storage + * may be reused for other purposes and clobbered by the host when it + * determines the query result. So the only option here is to wait for + * the existing query's result -- not a big deal, given that no sane + * application would do this. + */ + uint64_t result; + + svga_get_query_result(pipe, q, TRUE, &result); + + assert(sq->queryResult->state != SVGA3D_QUERYSTATE_PENDING); + } + + sq->queryResult->state = SVGA3D_QUERYSTATE_NEW; + sws->fence_reference(sws, &sq->fence, NULL); + + ret = SVGA3D_BeginQuery(svga->swc, sq->type); + if(ret != PIPE_OK) { + svga_context_flush(svga, NULL); + ret = SVGA3D_BeginQuery(svga->swc, sq->type); + assert(ret == PIPE_OK); + } + + svga->sq = sq; +} + +static void svga_end_query(struct pipe_context *pipe, + struct pipe_query *q) +{ + struct svga_context *svga = svga_context( pipe ); + struct svga_query *sq = svga_query( q ); + enum pipe_error ret; + + SVGA_DBG(DEBUG_QUERY, "%s\n", __FUNCTION__); + assert(svga->sq == sq); + + svga_hwtnl_flush_retry(svga); + + /* Set to PENDING before sending EndQuery. */ + sq->queryResult->state = SVGA3D_QUERYSTATE_PENDING; + + ret = SVGA3D_EndQuery( svga->swc, sq->type, sq->hwbuf); + if(ret != PIPE_OK) { + svga_context_flush(svga, NULL); + ret = SVGA3D_EndQuery( svga->swc, sq->type, sq->hwbuf); + assert(ret == PIPE_OK); + } + + /* TODO: Delay flushing. We don't really need to flush here, just ensure + * that there is one flush before svga_get_query_result attempts to get the + * result */ + svga_context_flush(svga, NULL); + + svga->sq = NULL; +} + +static boolean svga_get_query_result(struct pipe_context *pipe, + struct pipe_query *q, + boolean wait, + void *vresult) +{ + struct svga_context *svga = svga_context( pipe ); + struct svga_screen *svgascreen = svga_screen( pipe->screen ); + struct svga_winsys_screen *sws = svgascreen->sws; + struct svga_query *sq = svga_query( q ); + SVGA3dQueryState state; + uint64_t *result = (uint64_t*)vresult; + + SVGA_DBG(DEBUG_QUERY, "%s wait: %d\n", __FUNCTION__); + + /* The query status won't be updated by the host unless + * SVGA_3D_CMD_WAIT_FOR_QUERY is emitted. Unfortunately this will cause a + * synchronous wait on the host */ + if(!sq->fence) { + enum pipe_error ret; + + ret = SVGA3D_WaitForQuery( svga->swc, sq->type, sq->hwbuf); + if(ret != PIPE_OK) { + svga_context_flush(svga, NULL); + ret = SVGA3D_WaitForQuery( svga->swc, sq->type, sq->hwbuf); + assert(ret == PIPE_OK); + } + + svga_context_flush(svga, &sq->fence); + + assert(sq->fence); + } + + state = sq->queryResult->state; + if(state == SVGA3D_QUERYSTATE_PENDING) { + if(!wait) + return FALSE; + + sws->fence_finish(sws, sq->fence, 0); + + state = sq->queryResult->state; + } + + assert(state == SVGA3D_QUERYSTATE_SUCCEEDED || + state == SVGA3D_QUERYSTATE_FAILED); + + *result = (uint64_t)sq->queryResult->result32; + + SVGA_DBG(DEBUG_QUERY, "%s result %d\n", __FUNCTION__, (unsigned)*result); + + return TRUE; +} + + + +void svga_init_query_functions( struct svga_context *svga ) +{ + svga->pipe.create_query = svga_create_query; + svga->pipe.destroy_query = svga_destroy_query; + svga->pipe.begin_query = svga_begin_query; + svga->pipe.end_query = svga_end_query; + svga->pipe.get_query_result = svga_get_query_result; +} diff --git a/src/gallium/drivers/svga/svga_pipe_rasterizer.c b/src/gallium/drivers/svga/svga_pipe_rasterizer.c new file mode 100644 index 0000000..660eb07 --- /dev/null +++ b/src/gallium/drivers/svga/svga_pipe_rasterizer.c @@ -0,0 +1,250 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "draw/draw_context.h" +#include "util/u_inlines.h" +#include "pipe/p_defines.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "svga_context.h" + +#include "svga_hw_reg.h" + +/* Hardware frontwinding is always set up as SVGA3D_FRONTWINDING_CW. + */ +static SVGA3dFace svga_translate_cullmode( unsigned mode, + unsigned front_ccw ) +{ + const int hw_front_ccw = 0; /* hardware is always CW */ + switch (mode) { + case PIPE_FACE_NONE: + return SVGA3D_FACE_NONE; + case PIPE_FACE_FRONT: + return front_ccw == hw_front_ccw ? SVGA3D_FACE_FRONT : SVGA3D_FACE_BACK; + case PIPE_FACE_BACK: + return front_ccw == hw_front_ccw ? SVGA3D_FACE_BACK : SVGA3D_FACE_FRONT; + case PIPE_FACE_FRONT_AND_BACK: + return SVGA3D_FACE_FRONT_BACK; + default: + assert(0); + return SVGA3D_FACE_NONE; + } +} + +static SVGA3dShadeMode svga_translate_flatshade( unsigned mode ) +{ + return mode ? SVGA3D_SHADEMODE_FLAT : SVGA3D_SHADEMODE_SMOOTH; +} + + +static void * +svga_create_rasterizer_state(struct pipe_context *pipe, + const struct pipe_rasterizer_state *templ) +{ + struct svga_rasterizer_state *rast = CALLOC_STRUCT( svga_rasterizer_state ); + /* need this for draw module. */ + rast->templ = *templ; + + /* light_twoside - XXX: need fragment shader varient */ + /* poly_smooth - XXX: no fallback available */ + /* poly_stipple_enable - draw module */ + /* sprite_coord_enable - ? */ + /* point_quad_rasterization - ? */ + /* point_size_per_vertex - ? */ + /* sprite_coord_mode - ??? */ + /* bypass_vs_viewport_and_clip - handled by viewport setup */ + /* flatshade_first - handled by index translation */ + /* gl_rasterization_rules - XXX - viewport code */ + /* line_width - draw module */ + /* fill_cw, fill_ccw - draw module or index translation */ + + rast->shademode = svga_translate_flatshade( templ->flatshade ); + rast->cullmode = svga_translate_cullmode( templ->cull_face, + templ->front_ccw ); + rast->scissortestenable = templ->scissor; + rast->multisampleantialias = templ->multisample; + rast->antialiasedlineenable = templ->line_smooth; + rast->lastpixel = templ->line_last_pixel; + rast->pointsize = templ->point_size; + rast->hw_unfilled = PIPE_POLYGON_MODE_FILL; + + /* Use swtnl + decomposition implement these: + */ + if (templ->poly_stipple_enable) + rast->need_pipeline |= SVGA_PIPELINE_FLAG_TRIS; + + if (templ->line_width != 1.0 && + templ->line_width != 0.0) + rast->need_pipeline |= SVGA_PIPELINE_FLAG_LINES; + + if (templ->line_stipple_enable) { + /* LinePattern not implemented on all backends. + */ + if (0) { + SVGA3dLinePattern lp; + lp.repeat = templ->line_stipple_factor + 1; + lp.pattern = templ->line_stipple_pattern; + rast->linepattern = lp.uintValue; + } + else { + rast->need_pipeline |= SVGA_PIPELINE_FLAG_LINES; + } + } + + if (templ->point_smooth) + rast->need_pipeline |= SVGA_PIPELINE_FLAG_POINTS; + + { + int fill_front = templ->fill_front; + int fill_back = templ->fill_back; + int fill = PIPE_POLYGON_MODE_FILL; + boolean offset_front = util_get_offset(templ, fill_front); + boolean offset_back = util_get_offset(templ, fill_back); + boolean offset = 0; + + switch (templ->cull_face) { + case PIPE_FACE_FRONT_AND_BACK: + offset = 0; + fill = PIPE_POLYGON_MODE_FILL; + break; + + case PIPE_FACE_FRONT: + offset = offset_front; + fill = fill_front; + break; + + case PIPE_FACE_BACK: + offset = offset_back; + fill = fill_back; + break; + + case PIPE_FACE_NONE: + if (fill_front != fill_back || offset_front != offset_back) + { + /* Always need the draw module to work out different + * front/back fill modes: + */ + rast->need_pipeline |= SVGA_PIPELINE_FLAG_TRIS; + } + else { + offset = offset_front; + fill = fill_front; + } + break; + + default: + assert(0); + break; + } + + /* Unfilled primitive modes aren't implemented on all virtual + * hardware. We can do some unfilled processing with index + * translation, but otherwise need the draw module: + */ + if (fill != PIPE_POLYGON_MODE_FILL && + (templ->flatshade || + templ->light_twoside || + offset || + templ->cull_face != PIPE_FACE_NONE)) + { + fill = PIPE_POLYGON_MODE_FILL; + rast->need_pipeline |= SVGA_PIPELINE_FLAG_TRIS; + } + + /* If we are decomposing to lines, and lines need the pipeline, + * then we also need the pipeline for tris. + */ + if (fill == PIPE_POLYGON_MODE_LINE && + (rast->need_pipeline & SVGA_PIPELINE_FLAG_LINES)) + { + fill = PIPE_POLYGON_MODE_FILL; + rast->need_pipeline |= SVGA_PIPELINE_FLAG_TRIS; + } + + /* Similarly for points: + */ + if (fill == PIPE_POLYGON_MODE_POINT && + (rast->need_pipeline & SVGA_PIPELINE_FLAG_POINTS)) + { + fill = PIPE_POLYGON_MODE_FILL; + rast->need_pipeline |= SVGA_PIPELINE_FLAG_TRIS; + } + + if (offset) { + rast->slopescaledepthbias = templ->offset_scale; + rast->depthbias = templ->offset_units; + } + + rast->hw_unfilled = fill; + } + + + + + if (rast->need_pipeline & SVGA_PIPELINE_FLAG_TRIS) { + /* Turn off stuff which will get done in the draw module: + */ + rast->hw_unfilled = PIPE_POLYGON_MODE_FILL; + rast->slopescaledepthbias = 0; + rast->depthbias = 0; + } + + return rast; +} + +static void svga_bind_rasterizer_state( struct pipe_context *pipe, + void *state ) +{ + struct svga_context *svga = svga_context(pipe); + struct svga_rasterizer_state *raster = (struct svga_rasterizer_state *)state; + + svga->curr.rast = raster; + + draw_set_rasterizer_state(svga->swtnl.draw, raster ? &raster->templ : NULL, + state); + + svga->dirty |= SVGA_NEW_RAST; +} + +static void svga_delete_rasterizer_state(struct pipe_context *pipe, + void *raster) +{ + FREE(raster); +} + + +void svga_init_rasterizer_functions( struct svga_context *svga ) +{ + svga->pipe.create_rasterizer_state = svga_create_rasterizer_state; + svga->pipe.bind_rasterizer_state = svga_bind_rasterizer_state; + svga->pipe.delete_rasterizer_state = svga_delete_rasterizer_state; +} + + +/*********************************************************************** + * Hardware state update + */ + diff --git a/src/gallium/drivers/svga/svga_pipe_sampler.c b/src/gallium/drivers/svga/svga_pipe_sampler.c new file mode 100644 index 0000000..f44a0e1 --- /dev/null +++ b/src/gallium/drivers/svga/svga_pipe_sampler.c @@ -0,0 +1,267 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "pipe/p_defines.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "tgsi/tgsi_parse.h" + +#include "svga_context.h" +#include "svga_resource_texture.h" + +#include "svga_debug.h" + +static INLINE unsigned +translate_wrap_mode(unsigned wrap) +{ + switch (wrap) { + case PIPE_TEX_WRAP_REPEAT: + return SVGA3D_TEX_ADDRESS_WRAP; + + case PIPE_TEX_WRAP_CLAMP: + return SVGA3D_TEX_ADDRESS_CLAMP; + + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + /* Unfortunately SVGA3D_TEX_ADDRESS_EDGE not respected by + * hardware. + */ + return SVGA3D_TEX_ADDRESS_CLAMP; + + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + return SVGA3D_TEX_ADDRESS_BORDER; + + case PIPE_TEX_WRAP_MIRROR_REPEAT: + return SVGA3D_TEX_ADDRESS_MIRROR; + + case PIPE_TEX_WRAP_MIRROR_CLAMP: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + return SVGA3D_TEX_ADDRESS_MIRRORONCE; + + default: + assert(0); + return SVGA3D_TEX_ADDRESS_WRAP; + } +} + +static INLINE unsigned translate_img_filter( unsigned filter ) +{ + switch (filter) { + case PIPE_TEX_FILTER_NEAREST: return SVGA3D_TEX_FILTER_NEAREST; + case PIPE_TEX_FILTER_LINEAR: return SVGA3D_TEX_FILTER_LINEAR; + default: + assert(0); + return SVGA3D_TEX_FILTER_NEAREST; + } +} + +static INLINE unsigned translate_mip_filter( unsigned filter ) +{ + switch (filter) { + case PIPE_TEX_MIPFILTER_NONE: return SVGA3D_TEX_FILTER_NONE; + case PIPE_TEX_MIPFILTER_NEAREST: return SVGA3D_TEX_FILTER_NEAREST; + case PIPE_TEX_MIPFILTER_LINEAR: return SVGA3D_TEX_FILTER_LINEAR; + default: + assert(0); + return SVGA3D_TEX_FILTER_NONE; + } +} + +static void * +svga_create_sampler_state(struct pipe_context *pipe, + const struct pipe_sampler_state *sampler) +{ + struct svga_context *svga = svga_context(pipe); + struct svga_sampler_state *cso = CALLOC_STRUCT( svga_sampler_state ); + + cso->mipfilter = translate_mip_filter(sampler->min_mip_filter); + cso->magfilter = translate_img_filter( sampler->mag_img_filter ); + cso->minfilter = translate_img_filter( sampler->min_img_filter ); + cso->aniso_level = MAX2( sampler->max_anisotropy, 1 ); + if(sampler->max_anisotropy) + cso->magfilter = cso->minfilter = SVGA3D_TEX_FILTER_ANISOTROPIC; + cso->lod_bias = sampler->lod_bias; + cso->addressu = translate_wrap_mode(sampler->wrap_s); + cso->addressv = translate_wrap_mode(sampler->wrap_t); + cso->addressw = translate_wrap_mode(sampler->wrap_r); + cso->normalized_coords = sampler->normalized_coords; + cso->compare_mode = sampler->compare_mode; + cso->compare_func = sampler->compare_func; + + { + uint32 r = float_to_ubyte(sampler->border_color[0]); + uint32 g = float_to_ubyte(sampler->border_color[1]); + uint32 b = float_to_ubyte(sampler->border_color[2]); + uint32 a = float_to_ubyte(sampler->border_color[3]); + + cso->bordercolor = (a << 24) | (r << 16) | (g << 8) | b; + } + + /* No SVGA3D support for: + * - min/max LOD clamping + */ + cso->min_lod = 0; + cso->view_min_lod = MAX2(sampler->min_lod, 0); + cso->view_max_lod = MAX2(sampler->max_lod, 0); + + /* Use min_mipmap */ + if (svga->debug.use_min_mipmap) { + if (cso->view_min_lod == cso->view_max_lod) { + cso->min_lod = cso->view_min_lod; + cso->view_min_lod = 0; + cso->view_max_lod = 1000; /* Just a high number */ + cso->mipfilter = SVGA3D_TEX_FILTER_NONE; + } + } + + SVGA_DBG(DEBUG_VIEWS, "min %u, view(min %u, max %u) lod, mipfilter %s\n", + cso->min_lod, cso->view_min_lod, cso->view_max_lod, + cso->mipfilter == SVGA3D_TEX_FILTER_NONE ? "SVGA3D_TEX_FILTER_NONE" : "SOMETHING"); + + return cso; +} + +static void svga_bind_sampler_states(struct pipe_context *pipe, + unsigned num, void **sampler) +{ + struct svga_context *svga = svga_context(pipe); + unsigned i; + + assert(num <= PIPE_MAX_SAMPLERS); + + /* Check for no-op */ + if (num == svga->curr.num_samplers && + !memcmp(svga->curr.sampler, sampler, num * sizeof(void *))) { + if (0) debug_printf("sampler noop\n"); + return; + } + + for (i = 0; i < num; i++) + svga->curr.sampler[i] = sampler[i]; + + for (i = num; i < svga->curr.num_samplers; i++) + svga->curr.sampler[i] = NULL; + + svga->curr.num_samplers = num; + svga->dirty |= SVGA_NEW_SAMPLER; +} + +static void svga_delete_sampler_state(struct pipe_context *pipe, + void *sampler) +{ + FREE(sampler); +} + + +static struct pipe_sampler_view * +svga_create_sampler_view(struct pipe_context *pipe, + struct pipe_resource *texture, + const struct pipe_sampler_view *templ) +{ + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_resource_reference(&view->texture, texture); + view->context = pipe; + } + + return view; +} + + +static void +svga_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_resource_reference(&view->texture, NULL); + FREE(view); +} + +static void svga_set_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct svga_context *svga = svga_context(pipe); + unsigned flag_1d = 0; + unsigned flag_srgb = 0; + uint i; + + assert(num <= PIPE_MAX_SAMPLERS); + + /* Check for no-op */ + if (num == svga->curr.num_sampler_views && + !memcmp(svga->curr.sampler_views, views, num * sizeof(struct pipe_sampler_view *))) { + if (0) debug_printf("texture noop\n"); + return; + } + + for (i = 0; i < num; i++) { + pipe_sampler_view_reference(&svga->curr.sampler_views[i], + views[i]); + + if (!views[i]) + continue; + + if (views[i]->texture->format == PIPE_FORMAT_B8G8R8A8_SRGB) + flag_srgb |= 1 << i; + + if (views[i]->texture->target == PIPE_TEXTURE_1D) + flag_1d |= 1 << i; + } + + for (i = num; i < svga->curr.num_sampler_views; i++) + pipe_sampler_view_reference(&svga->curr.sampler_views[i], + NULL); + + svga->curr.num_sampler_views = num; + svga->dirty |= SVGA_NEW_TEXTURE_BINDING; + + if (flag_srgb != svga->curr.tex_flags.flag_srgb || + flag_1d != svga->curr.tex_flags.flag_1d) + { + svga->dirty |= SVGA_NEW_TEXTURE_FLAGS; + svga->curr.tex_flags.flag_1d = flag_1d; + svga->curr.tex_flags.flag_srgb = flag_srgb; + } +} + + + +void svga_init_sampler_functions( struct svga_context *svga ) +{ + svga->pipe.create_sampler_state = svga_create_sampler_state; + svga->pipe.bind_fragment_sampler_states = svga_bind_sampler_states; + svga->pipe.delete_sampler_state = svga_delete_sampler_state; + svga->pipe.set_fragment_sampler_views = svga_set_sampler_views; + svga->pipe.create_sampler_view = svga_create_sampler_view; + svga->pipe.sampler_view_destroy = svga_sampler_view_destroy; +} + + + diff --git a/src/gallium/drivers/svga/svga_pipe_vertex.c b/src/gallium/drivers/svga/svga_pipe_vertex.c new file mode 100644 index 0000000..86c7945 --- /dev/null +++ b/src/gallium/drivers/svga/svga_pipe_vertex.c @@ -0,0 +1,136 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "pipe/p_defines.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "tgsi/tgsi_parse.h" + +#include "svga_screen.h" +#include "svga_resource_buffer.h" +#include "svga_context.h" + + +static void svga_set_vertex_buffers(struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_buffer *buffers) +{ + struct svga_context *svga = svga_context(pipe); + unsigned i; + boolean any_user_buffer = FALSE; + + /* Check for no change */ + if (count == svga->curr.num_vertex_buffers && + memcmp(svga->curr.vb, buffers, count * sizeof buffers[0]) == 0) + return; + + /* Adjust refcounts */ + for (i = 0; i < count; i++) { + pipe_resource_reference(&svga->curr.vb[i].buffer, buffers[i].buffer); + if (svga_buffer_is_user_buffer(buffers[i].buffer)) + any_user_buffer = TRUE; + } + + for ( ; i < svga->curr.num_vertex_buffers; i++) + pipe_resource_reference(&svga->curr.vb[i].buffer, NULL); + + /* Copy remaining data */ + memcpy(svga->curr.vb, buffers, count * sizeof buffers[0]); + svga->curr.num_vertex_buffers = count; + svga->curr.any_user_vertex_buffers = any_user_buffer; + + svga->dirty |= SVGA_NEW_VBUFFER; +} + + +static void svga_set_index_buffer(struct pipe_context *pipe, + const struct pipe_index_buffer *ib) +{ + struct svga_context *svga = svga_context(pipe); + + if (ib) { + pipe_resource_reference(&svga->curr.ib.buffer, ib->buffer); + memcpy(&svga->curr.ib, ib, sizeof(svga->curr.ib)); + } + else { + pipe_resource_reference(&svga->curr.ib.buffer, NULL); + memset(&svga->curr.ib, 0, sizeof(svga->curr.ib)); + } + + /* TODO make this more like a state */ +} + + +static void * +svga_create_vertex_elements_state(struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_element *attribs) +{ + struct svga_velems_state *velems; + assert(count <= PIPE_MAX_ATTRIBS); + velems = (struct svga_velems_state *) MALLOC(sizeof(struct svga_velems_state)); + if (velems) { + velems->count = count; + memcpy(velems->velem, attribs, sizeof(*attribs) * count); + } + return velems; +} + +static void svga_bind_vertex_elements_state(struct pipe_context *pipe, + void *velems) +{ + struct svga_context *svga = svga_context(pipe); + struct svga_velems_state *svga_velems = (struct svga_velems_state *) velems; + + svga->curr.velems = svga_velems; + svga->dirty |= SVGA_NEW_VELEMENT; +} + +static void svga_delete_vertex_elements_state(struct pipe_context *pipe, + void *velems) +{ + FREE(velems); +} + +void svga_cleanup_vertex_state( struct svga_context *svga ) +{ + unsigned i; + + for (i = 0 ; i < svga->curr.num_vertex_buffers; i++) + pipe_resource_reference(&svga->curr.vb[i].buffer, NULL); +} + + +void svga_init_vertex_functions( struct svga_context *svga ) +{ + svga->pipe.set_vertex_buffers = svga_set_vertex_buffers; + svga->pipe.set_index_buffer = svga_set_index_buffer; + svga->pipe.create_vertex_elements_state = svga_create_vertex_elements_state; + svga->pipe.bind_vertex_elements_state = svga_bind_vertex_elements_state; + svga->pipe.delete_vertex_elements_state = svga_delete_vertex_elements_state; +} + + diff --git a/src/gallium/drivers/svga/svga_pipe_vs.c b/src/gallium/drivers/svga/svga_pipe_vs.c new file mode 100644 index 0000000..de8c919 --- /dev/null +++ b/src/gallium/drivers/svga/svga_pipe_vs.c @@ -0,0 +1,198 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "draw/draw_context.h" +#include "util/u_inlines.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_bitmask.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_text.h" + +#include "svga_screen.h" +#include "svga_context.h" +#include "svga_tgsi.h" +#include "svga_hw_reg.h" +#include "svga_cmd.h" +#include "svga_debug.h" + + +static const struct tgsi_token *substitute_vs( + unsigned shader_id, + const struct tgsi_token *old_tokens ) +{ +#if 0 + if (shader_id == 12) { + static struct tgsi_token tokens[300]; + + const char *text = + "VERT\n" + "DCL IN[0]\n" + "DCL IN[1]\n" + "DCL IN[2]\n" + "DCL OUT[0], POSITION\n" + "DCL TEMP[0..4]\n" + "IMM FLT32 { 1.0000, 1.0000, 1.0000, 1.0000 }\n" + "IMM FLT32 { 0.45, 1.0000, 1.0000, 1.0000 }\n" + "IMM FLT32 { 1.297863, 0.039245, 0.035993, 0.035976}\n" + "IMM FLT32 { -0.019398, 1.696131, -0.202151, -0.202050 }\n" + "IMM FLT32 { 0.051711, -0.348713, -0.979204, -0.978714 }\n" + "IMM FLT32 { 0.000000, 0.000003, 139.491577, 141.421356 }\n" + "DCL CONST[0..7]\n" + "DCL CONST[9..16]\n" + " MOV TEMP[2], IMM[0]\n" + + " MOV TEMP[2].xyz, IN[2]\n" + " MOV TEMP[2].xyz, IN[0]\n" + " MOV TEMP[2].xyz, IN[1]\n" + + " MUL TEMP[1], IMM[3], TEMP[2].yyyy\n" + " MAD TEMP[3], IMM[2], TEMP[2].xxxx, TEMP[1]\n" + " MAD TEMP[1], IMM[4], TEMP[2].zzzz, TEMP[3]\n" + " MAD TEMP[4], IMM[5], TEMP[2].wwww, TEMP[1]\n" + + " MOV OUT[0], TEMP[4]\n" + " END\n"; + + if (!tgsi_text_translate( text, + tokens, + Elements(tokens) )) + { + assert(0); + return NULL; + } + + return tokens; + } +#endif + + return old_tokens; +} + + +/*********************************************************************** + * Vertex shaders + */ + +static void * +svga_create_vs_state(struct pipe_context *pipe, + const struct pipe_shader_state *templ) +{ + struct svga_context *svga = svga_context(pipe); + struct svga_screen *svgascreen = svga_screen(pipe->screen); + struct svga_vertex_shader *vs = CALLOC_STRUCT(svga_vertex_shader); + if (!vs) + return NULL; + + /* substitute a debug shader? + */ + vs->base.tokens = tgsi_dup_tokens(substitute_vs(svga->debug.shader_id, + templ->tokens)); + + + /* Collect basic info that we'll need later: + */ + tgsi_scan_shader(vs->base.tokens, &vs->base.info); + + { + /* Need to do construct a new template in case we substitued a + * debug shader. + */ + struct pipe_shader_state tmp2 = *templ; + tmp2.tokens = vs->base.tokens; + vs->draw_shader = draw_create_vertex_shader(svga->swtnl.draw, &tmp2); + } + + vs->base.id = svga->debug.shader_id++; + vs->base.use_sm30 = svgascreen->use_vs30; + + if (SVGA_DEBUG & DEBUG_TGSI || 0) { + debug_printf("%s id: %u, inputs: %u, outputs: %u\n", + __FUNCTION__, vs->base.id, + vs->base.info.num_inputs, vs->base.info.num_outputs); + } + + return vs; +} + +static void svga_bind_vs_state(struct pipe_context *pipe, void *shader) +{ + struct svga_vertex_shader *vs = (struct svga_vertex_shader *)shader; + struct svga_context *svga = svga_context(pipe); + + svga->curr.vs = vs; + svga->dirty |= SVGA_NEW_VS; +} + + +static void svga_delete_vs_state(struct pipe_context *pipe, void *shader) +{ + struct svga_context *svga = svga_context(pipe); + struct svga_vertex_shader *vs = (struct svga_vertex_shader *)shader; + struct svga_shader_result *result, *tmp; + enum pipe_error ret; + + svga_hwtnl_flush_retry( svga ); + + draw_delete_vertex_shader(svga->swtnl.draw, vs->draw_shader); + + for (result = vs->base.results; result; result = tmp ) { + tmp = result->next; + + ret = SVGA3D_DestroyShader(svga->swc, + result->id, + SVGA3D_SHADERTYPE_VS ); + if(ret != PIPE_OK) { + svga_context_flush(svga, NULL); + ret = SVGA3D_DestroyShader(svga->swc, + result->id, + SVGA3D_SHADERTYPE_VS ); + assert(ret == PIPE_OK); + } + + util_bitmask_clear( svga->vs_bm, result->id ); + + svga_destroy_shader_result( result ); + + /* + * Remove stale references to this result to ensure a new result on the + * same address will be detected as a change. + */ + if(result == svga->state.hw_draw.vs) + svga->state.hw_draw.vs = NULL; + } + + FREE((void *)vs->base.tokens); + FREE(vs); +} + + +void svga_init_vs_functions( struct svga_context *svga ) +{ + svga->pipe.create_vs_state = svga_create_vs_state; + svga->pipe.bind_vs_state = svga_bind_vs_state; + svga->pipe.delete_vs_state = svga_delete_vs_state; +} + diff --git a/src/gallium/drivers/svga/svga_public.h b/src/gallium/drivers/svga/svga_public.h new file mode 100644 index 0000000..ded2e24 --- /dev/null +++ b/src/gallium/drivers/svga/svga_public.h @@ -0,0 +1,42 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +/** + * @file + * VMware SVGA public interface. Used by targets to create a stack. + * + * @author Jakob Bornecrantz Fonseca + */ + +#ifndef SVGA_PUBLIC_H_ +#define SVGA_PUBLIC_H_ + +struct pipe_screen; +struct svga_winsys_screen; + +struct pipe_screen * +svga_screen_create(struct svga_winsys_screen *sws); + +#endif /* SVGA_PUBLIC_H_ */ diff --git a/src/gallium/drivers/svga/svga_resource.c b/src/gallium/drivers/svga/svga_resource.c new file mode 100644 index 0000000..ef2a0c4 --- /dev/null +++ b/src/gallium/drivers/svga/svga_resource.c @@ -0,0 +1,56 @@ +#include "util/u_debug.h" + +#include "svga_resource.h" +#include "svga_resource_buffer.h" +#include "svga_resource_texture.h" +#include "svga_context.h" +#include "svga_screen.h" + + +static struct pipe_resource * +svga_resource_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + if (template->target == PIPE_BUFFER) + return svga_buffer_create(screen, template); + else + return svga_texture_create(screen, template); + +} + +static struct pipe_resource * +svga_resource_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle) +{ + if (template->target == PIPE_BUFFER) + return NULL; + else + return svga_texture_from_handle(screen, template, whandle); +} + + +void +svga_init_resource_functions(struct svga_context *svga) +{ + svga->pipe.is_resource_referenced = u_is_resource_referenced_vtbl; + svga->pipe.get_transfer = u_get_transfer_vtbl; + svga->pipe.transfer_map = u_transfer_map_vtbl; + svga->pipe.transfer_flush_region = u_transfer_flush_region_vtbl; + svga->pipe.transfer_unmap = u_transfer_unmap_vtbl; + svga->pipe.transfer_destroy = u_transfer_destroy_vtbl; + svga->pipe.transfer_inline_write = u_transfer_inline_write_vtbl; +} + +void +svga_init_screen_resource_functions(struct svga_screen *is) +{ + is->screen.resource_create = svga_resource_create; + is->screen.resource_from_handle = svga_resource_from_handle; + is->screen.resource_get_handle = u_resource_get_handle_vtbl; + is->screen.resource_destroy = u_resource_destroy_vtbl; + is->screen.user_buffer_create = svga_user_buffer_create; +} + + + diff --git a/src/gallium/drivers/svga/svga_resource.h b/src/gallium/drivers/svga/svga_resource.h new file mode 100644 index 0000000..851e3b5 --- /dev/null +++ b/src/gallium/drivers/svga/svga_resource.h @@ -0,0 +1,43 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef SVGA_RESOURCE_H +#define SVGA_RESOURCE_H + +struct svga_screen; + +#include "util/u_debug.h" + +struct svga_context; +struct svga_screen; + + +void svga_init_screen_resource_functions(struct svga_screen *is); +void svga_init_resource_functions(struct svga_context *svga ); + + +#endif /* SVGA_RESOURCE_H */ diff --git a/src/gallium/drivers/svga/svga_resource_buffer.c b/src/gallium/drivers/svga/svga_resource_buffer.c new file mode 100644 index 0000000..f12e2b6 --- /dev/null +++ b/src/gallium/drivers/svga/svga_resource_buffer.c @@ -0,0 +1,352 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "svga_cmd.h" + +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "os/os_thread.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "svga_context.h" +#include "svga_screen.h" +#include "svga_resource_buffer.h" +#include "svga_resource_buffer_upload.h" +#include "svga_winsys.h" +#include "svga_debug.h" + + +/** + * Vertex and index buffers need hardware backing. Constant buffers + * do not. No other types of buffers currently supported. + */ +static INLINE boolean +svga_buffer_needs_hw_storage(unsigned usage) +{ + return usage & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER); +} + + +static unsigned int +svga_buffer_is_referenced( struct pipe_context *pipe, + struct pipe_resource *buf, + unsigned level, int layer) +{ + struct svga_screen *ss = svga_screen(pipe->screen); + struct svga_buffer *sbuf = svga_buffer(buf); + + /** + * XXX: Check this. + * The screen may cache buffer writes, but when we map, we map out + * of those cached writes, so we don't need to set a + * PIPE_REFERENCED_FOR_WRITE flag for cached buffers. + */ + + if (!sbuf->handle || ss->sws->surface_is_flushed(ss->sws, sbuf->handle)) + return PIPE_UNREFERENCED; + + /** + * sws->surface_is_flushed() does not distinguish between read references + * and write references. So assume a reference is both, + * however, we make an exception for index- and vertex buffers, to avoid + * a flush in st_bufferobj_get_subdata, during display list replay. + */ + + if (sbuf->b.b.bind & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER)) + return PIPE_REFERENCED_FOR_READ; + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + + + + + + +static void * +svga_buffer_map_range( struct pipe_screen *screen, + struct pipe_resource *buf, + unsigned offset, + unsigned length, + unsigned usage ) +{ + struct svga_screen *ss = svga_screen(screen); + struct svga_winsys_screen *sws = ss->sws; + struct svga_buffer *sbuf = svga_buffer( buf ); + void *map; + + if (!sbuf->swbuf && !sbuf->hwbuf) { + if (svga_buffer_create_hw_storage(ss, sbuf) != PIPE_OK) { + /* + * We can't create a hardware buffer big enough, so create a malloc + * buffer instead. + */ + debug_printf("%s: failed to allocate %u KB of DMA, splitting DMA transfers\n", + __FUNCTION__, + (sbuf->b.b.width0 + 1023)/1024); + + sbuf->swbuf = align_malloc(sbuf->b.b.width0, 16); + } + } + + if (sbuf->swbuf) { + /* User/malloc buffer */ + map = sbuf->swbuf; + } + else if (sbuf->hwbuf) { + map = sws->buffer_map(sws, sbuf->hwbuf, usage); + } + else { + map = NULL; + } + + if(map) { + ++sbuf->map.count; + + if (usage & PIPE_TRANSFER_WRITE) { + assert(sbuf->map.count <= 1); + sbuf->map.writing = TRUE; + if (usage & PIPE_TRANSFER_FLUSH_EXPLICIT) + sbuf->map.flush_explicit = TRUE; + } + } + + return map; +} + + + +static void +svga_buffer_flush_mapped_range( struct pipe_screen *screen, + struct pipe_resource *buf, + unsigned offset, unsigned length) +{ + struct svga_buffer *sbuf = svga_buffer( buf ); + struct svga_screen *ss = svga_screen(screen); + + pipe_mutex_lock(ss->swc_mutex); + assert(sbuf->map.writing); + if(sbuf->map.writing) { + assert(sbuf->map.flush_explicit); + svga_buffer_add_range(sbuf, offset, offset + length); + } + pipe_mutex_unlock(ss->swc_mutex); +} + +static void +svga_buffer_unmap( struct pipe_screen *screen, + struct pipe_resource *buf) +{ + struct svga_screen *ss = svga_screen(screen); + struct svga_winsys_screen *sws = ss->sws; + struct svga_buffer *sbuf = svga_buffer( buf ); + + pipe_mutex_lock(ss->swc_mutex); + + assert(sbuf->map.count); + if(sbuf->map.count) + --sbuf->map.count; + + if(sbuf->hwbuf) + sws->buffer_unmap(sws, sbuf->hwbuf); + + if(sbuf->map.writing) { + if(!sbuf->map.flush_explicit) { + /* No mapped range was flushed -- flush the whole buffer */ + SVGA_DBG(DEBUG_DMA, "flushing the whole buffer\n"); + + svga_buffer_add_range(sbuf, 0, sbuf->b.b.width0); + } + + sbuf->map.writing = FALSE; + sbuf->map.flush_explicit = FALSE; + } + + pipe_mutex_unlock(ss->swc_mutex); +} + + + +static void +svga_buffer_destroy( struct pipe_screen *screen, + struct pipe_resource *buf ) +{ + struct svga_screen *ss = svga_screen(screen); + struct svga_buffer *sbuf = svga_buffer( buf ); + + assert(!p_atomic_read(&buf->reference.count)); + + assert(!sbuf->dma.pending); + + if(sbuf->handle) + svga_buffer_destroy_host_surface(ss, sbuf); + + if(sbuf->uploaded.buffer) + pipe_resource_reference(&sbuf->uploaded.buffer, NULL); + + if(sbuf->hwbuf) + svga_buffer_destroy_hw_storage(ss, sbuf); + + if(sbuf->swbuf && !sbuf->user) + align_free(sbuf->swbuf); + + FREE(sbuf); +} + + +/* Keep the original code more or less intact, implement transfers in + * terms of the old functions. + */ +static void * +svga_buffer_transfer_map( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + uint8_t *map = svga_buffer_map_range( pipe->screen, + transfer->resource, + transfer->box.x, + transfer->box.width, + transfer->usage ); + if (map == NULL) + return NULL; + + /* map_buffer() returned a pointer to the beginning of the buffer, + * but transfers are expected to return a pointer to just the + * region specified in the box. + */ + return map + transfer->box.x; +} + + + +static void svga_buffer_transfer_flush_region( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box) +{ + assert(box->x + box->width <= transfer->box.width); + + svga_buffer_flush_mapped_range(pipe->screen, + transfer->resource, + transfer->box.x + box->x, + box->width); +} + +static void svga_buffer_transfer_unmap( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + svga_buffer_unmap(pipe->screen, + transfer->resource); +} + + + + + + + +struct u_resource_vtbl svga_buffer_vtbl = +{ + u_default_resource_get_handle, /* get_handle */ + svga_buffer_destroy, /* resource_destroy */ + svga_buffer_is_referenced, /* is_resource_referenced */ + u_default_get_transfer, /* get_transfer */ + u_default_transfer_destroy, /* transfer_destroy */ + svga_buffer_transfer_map, /* transfer_map */ + svga_buffer_transfer_flush_region, /* transfer_flush_region */ + svga_buffer_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; + + + +struct pipe_resource * +svga_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + struct svga_screen *ss = svga_screen(screen); + struct svga_buffer *sbuf; + + sbuf = CALLOC_STRUCT(svga_buffer); + if(!sbuf) + goto error1; + + sbuf->b.b = *template; + sbuf->b.vtbl = &svga_buffer_vtbl; + pipe_reference_init(&sbuf->b.b.reference, 1); + sbuf->b.b.screen = screen; + + if(svga_buffer_needs_hw_storage(template->bind)) { + if(svga_buffer_create_host_surface(ss, sbuf) != PIPE_OK) + goto error2; + } + else { + sbuf->swbuf = align_malloc(template->width0, 64); + if(!sbuf->swbuf) + goto error2; + } + + return &sbuf->b.b; + +error2: + FREE(sbuf); +error1: + return NULL; +} + +struct pipe_resource * +svga_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned bind) +{ + struct svga_buffer *sbuf; + + sbuf = CALLOC_STRUCT(svga_buffer); + if(!sbuf) + goto no_sbuf; + + pipe_reference_init(&sbuf->b.b.reference, 1); + sbuf->b.vtbl = &svga_buffer_vtbl; + sbuf->b.b.screen = screen; + sbuf->b.b.format = PIPE_FORMAT_R8_UNORM; /* ?? */ + sbuf->b.b.usage = PIPE_USAGE_IMMUTABLE; + sbuf->b.b.bind = bind; + sbuf->b.b.width0 = bytes; + sbuf->b.b.height0 = 1; + sbuf->b.b.depth0 = 1; + sbuf->b.b.array_size = 1; + + sbuf->swbuf = ptr; + sbuf->user = TRUE; + + return &sbuf->b.b; + +no_sbuf: + return NULL; +} + + + diff --git a/src/gallium/drivers/svga/svga_resource_buffer.h b/src/gallium/drivers/svga/svga_resource_buffer.h new file mode 100644 index 0000000..d3ec11b --- /dev/null +++ b/src/gallium/drivers/svga/svga_resource_buffer.h @@ -0,0 +1,246 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_BUFFER_H +#define SVGA_BUFFER_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "util/u_transfer.h" + +#include "util/u_double_list.h" + +#include "svga_screen_cache.h" + + +/** + * Maximum number of discontiguous ranges + */ +#define SVGA_BUFFER_MAX_RANGES 32 + + +struct svga_screen; +struct svga_context; +struct svga_winsys_buffer; +struct svga_winsys_surface; + + +extern struct u_resource_vtbl svga_buffer_vtbl; + +struct svga_buffer_range +{ + unsigned start; + unsigned end; +}; + + +/** + * SVGA pipe buffer. + */ +struct svga_buffer +{ + struct u_resource b; + + /** + * Regular (non DMA'able) memory. + * + * Used for user buffers or for buffers which we know before hand that can + * never be used by the virtual hardware directly, such as constant buffers. + */ + void *swbuf; + + /** + * Whether swbuf was created by the user or not. + */ + boolean user; + + /** + * Creation key for the host surface handle. + * + * This structure describes all the host surface characteristics so that it + * can be looked up in cache, since creating a host surface is often a slow + * operation. + */ + struct svga_host_surface_cache_key key; + + /** + * Host surface handle. + * + * This is a platform independent abstraction for host SID. We create when + * trying to bind + */ + struct svga_winsys_surface *handle; + + /** + * Information about ongoing and past map operations. + */ + struct { + /** + * Number of concurrent mappings. + * + * XXX: It is impossible to guarantee concurrent maps work in all + * circumstances -- pipe_buffers really need transfer objects too. + */ + unsigned count; + + /** + * Whether this buffer is currently mapped for writing. + */ + boolean writing; + + /** + * Whether the application will tell us explicity which ranges it touched + * or not. + */ + boolean flush_explicit; + + /** + * Dirty ranges. + * + * Ranges that were touched by the application and need to be uploaded to + * the host. + * + * This information will be copied into dma.boxes, when emiting the + * SVGA3dCmdSurfaceDMA command. + */ + struct svga_buffer_range ranges[SVGA_BUFFER_MAX_RANGES]; + unsigned num_ranges; + } map; + + /** + * Information about uploaded version of user buffers. + */ + struct { + struct pipe_resource *buffer; + + /** + * We combine multiple user buffers into the same hardware buffer. This + * is the relative offset within that buffer. + */ + unsigned offset; + } uploaded; + + /** + * DMA'ble memory. + * + * A piece of GMR memory, with the same size of the buffer. It is created + * when mapping the buffer, and will be used to upload vertex data to the + * host. + */ + struct svga_winsys_buffer *hwbuf; + + /** + * Information about pending DMA uploads. + * + */ + struct { + /** + * Whether this buffer has an unfinished DMA upload command. + * + * If not set then the rest of the information is null. + */ + boolean pending; + + SVGA3dSurfaceDMAFlags flags; + + /** + * Pointer to the DMA copy box *inside* the command buffer. + */ + SVGA3dCopyBox *boxes; + + /** + * Context that has the pending DMA to this buffer. + */ + struct svga_context *svga; + } dma; + + /** + * Linked list head, used to gather all buffers with pending dma uploads on + * a context. It is only valid if the dma.pending is set above. + */ + struct list_head head; +}; + + +static INLINE struct svga_buffer * +svga_buffer(struct pipe_resource *buffer) +{ + if (buffer) { + assert(((struct svga_buffer *)buffer)->b.vtbl == &svga_buffer_vtbl); + return (struct svga_buffer *)buffer; + } + return NULL; +} + + +/** + * Returns TRUE for user buffers. We may + * decide to use an alternate upload path for these buffers. + */ +static INLINE boolean +svga_buffer_is_user_buffer( struct pipe_resource *buffer ) +{ + return svga_buffer(buffer)->user; +} + + + + +struct pipe_resource * +svga_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage); + +struct pipe_resource * +svga_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *template); + + + +/** + * Get the host surface handle for this buffer. + * + * This will ensure the host surface is updated, issuing DMAs as needed. + * + * NOTE: This may insert new commands in the context, so it *must* be called + * before reserving command buffer space. And, in order to insert commands + * it may need to call svga_context_flush(). + */ +struct svga_winsys_surface * +svga_buffer_handle(struct svga_context *svga, + struct pipe_resource *buf); + +void +svga_context_flush_buffers(struct svga_context *svga); + +struct svga_winsys_buffer * +svga_winsys_buffer_create(struct svga_context *svga, + unsigned alignment, + unsigned usage, + unsigned size); + +#endif /* SVGA_BUFFER_H */ diff --git a/src/gallium/drivers/svga/svga_resource_buffer_upload.c b/src/gallium/drivers/svga/svga_resource_buffer_upload.c new file mode 100644 index 0000000..3de5216 --- /dev/null +++ b/src/gallium/drivers/svga/svga_resource_buffer_upload.c @@ -0,0 +1,640 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "svga_cmd.h" + +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "os/os_thread.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "svga_context.h" +#include "svga_screen.h" +#include "svga_resource_buffer.h" +#include "svga_resource_buffer_upload.h" +#include "svga_winsys.h" +#include "svga_debug.h" + + +/** + * Allocate a winsys_buffer (ie. DMA, aka GMR memory). + * + * It will flush and retry in case the first attempt to create a DMA buffer + * fails, so it should not be called from any function involved in flushing + * to avoid recursion. + */ +struct svga_winsys_buffer * +svga_winsys_buffer_create( struct svga_context *svga, + unsigned alignment, + unsigned usage, + unsigned size ) +{ + struct svga_screen *svgascreen = svga_screen(svga->pipe.screen); + struct svga_winsys_screen *sws = svgascreen->sws; + struct svga_winsys_buffer *buf; + + /* Just try */ + buf = sws->buffer_create(sws, alignment, usage, size); + if(!buf) { + + SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "flushing screen to find %d bytes GMR\n", + size); + + /* Try flushing all pending DMAs */ + svga_context_flush(svga, NULL); + buf = sws->buffer_create(sws, alignment, usage, size); + } + + return buf; +} + + +void +svga_buffer_destroy_hw_storage(struct svga_screen *ss, struct svga_buffer *sbuf) +{ + struct svga_winsys_screen *sws = ss->sws; + + assert(!sbuf->map.count); + assert(sbuf->hwbuf); + if(sbuf->hwbuf) { + sws->buffer_destroy(sws, sbuf->hwbuf); + sbuf->hwbuf = NULL; + } +} + + + +/** + * Allocate DMA'ble storage for the buffer. + * + * Called before mapping a buffer. + */ +enum pipe_error +svga_buffer_create_hw_storage(struct svga_screen *ss, + struct svga_buffer *sbuf) +{ + assert(!sbuf->user); + + if(!sbuf->hwbuf) { + struct svga_winsys_screen *sws = ss->sws; + unsigned alignment = 16; + unsigned usage = 0; + unsigned size = sbuf->b.b.width0; + + sbuf->hwbuf = sws->buffer_create(sws, alignment, usage, size); + if(!sbuf->hwbuf) + return PIPE_ERROR_OUT_OF_MEMORY; + + assert(!sbuf->dma.pending); + } + + return PIPE_OK; +} + + + +enum pipe_error +svga_buffer_create_host_surface(struct svga_screen *ss, + struct svga_buffer *sbuf) +{ + if(!sbuf->handle) { + sbuf->key.flags = 0; + + sbuf->key.format = SVGA3D_BUFFER; + if(sbuf->b.b.bind & PIPE_BIND_VERTEX_BUFFER) + sbuf->key.flags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER; + if(sbuf->b.b.bind & PIPE_BIND_INDEX_BUFFER) + sbuf->key.flags |= SVGA3D_SURFACE_HINT_INDEXBUFFER; + + sbuf->key.size.width = sbuf->b.b.width0; + sbuf->key.size.height = 1; + sbuf->key.size.depth = 1; + + sbuf->key.numFaces = 1; + sbuf->key.numMipLevels = 1; + sbuf->key.cachable = 1; + + SVGA_DBG(DEBUG_DMA, "surface_create for buffer sz %d\n", sbuf->b.b.width0); + + sbuf->handle = svga_screen_surface_create(ss, &sbuf->key); + if(!sbuf->handle) + return PIPE_ERROR_OUT_OF_MEMORY; + + /* Always set the discard flag on the first time the buffer is written + * as svga_screen_surface_create might have passed a recycled host + * buffer. + */ + sbuf->dma.flags.discard = TRUE; + + SVGA_DBG(DEBUG_DMA, " --> got sid %p sz %d (buffer)\n", sbuf->handle, sbuf->b.b.width0); + } + + return PIPE_OK; +} + + +void +svga_buffer_destroy_host_surface(struct svga_screen *ss, + struct svga_buffer *sbuf) +{ + if(sbuf->handle) { + SVGA_DBG(DEBUG_DMA, " ungrab sid %p sz %d\n", sbuf->handle, sbuf->b.b.width0); + svga_screen_surface_destroy(ss, &sbuf->key, &sbuf->handle); + } +} + + +/** + * Variant of SVGA3D_BufferDMA which leaves the copy box temporarily in blank. + */ +static enum pipe_error +svga_buffer_upload_command(struct svga_context *svga, + struct svga_buffer *sbuf) +{ + struct svga_winsys_context *swc = svga->swc; + struct svga_winsys_buffer *guest = sbuf->hwbuf; + struct svga_winsys_surface *host = sbuf->handle; + SVGA3dTransferType transfer = SVGA3D_WRITE_HOST_VRAM; + SVGA3dCmdSurfaceDMA *cmd; + uint32 numBoxes = sbuf->map.num_ranges; + SVGA3dCopyBox *boxes; + SVGA3dCmdSurfaceDMASuffix *pSuffix; + unsigned region_flags; + unsigned surface_flags; + struct pipe_resource *dummy; + + if(transfer == SVGA3D_WRITE_HOST_VRAM) { + region_flags = SVGA_RELOC_READ; + surface_flags = SVGA_RELOC_WRITE; + } + else if(transfer == SVGA3D_READ_HOST_VRAM) { + region_flags = SVGA_RELOC_WRITE; + surface_flags = SVGA_RELOC_READ; + } + else { + assert(0); + return PIPE_ERROR_BAD_INPUT; + } + + assert(numBoxes); + + cmd = SVGA3D_FIFOReserve(swc, + SVGA_3D_CMD_SURFACE_DMA, + sizeof *cmd + numBoxes * sizeof *boxes + sizeof *pSuffix, + 2); + if(!cmd) + return PIPE_ERROR_OUT_OF_MEMORY; + + swc->region_relocation(swc, &cmd->guest.ptr, guest, 0, region_flags); + cmd->guest.pitch = 0; + + swc->surface_relocation(swc, &cmd->host.sid, host, surface_flags); + cmd->host.face = 0; + cmd->host.mipmap = 0; + + cmd->transfer = transfer; + + sbuf->dma.boxes = (SVGA3dCopyBox *)&cmd[1]; + sbuf->dma.svga = svga; + + /* Increment reference count */ + dummy = NULL; + pipe_resource_reference(&dummy, &sbuf->b.b); + + pSuffix = (SVGA3dCmdSurfaceDMASuffix *)((uint8_t*)cmd + sizeof *cmd + numBoxes * sizeof *boxes); + pSuffix->suffixSize = sizeof *pSuffix; + pSuffix->maximumOffset = sbuf->b.b.width0; + pSuffix->flags = sbuf->dma.flags; + + SVGA_FIFOCommitAll(swc); + + sbuf->dma.flags.discard = FALSE; + + return PIPE_OK; +} + + +/** + * Patch up the upload DMA command reserved by svga_buffer_upload_command + * with the final ranges. + */ +static void +svga_buffer_upload_flush(struct svga_context *svga, + struct svga_buffer *sbuf) +{ + SVGA3dCopyBox *boxes; + unsigned i; + + assert(sbuf->handle); + assert(sbuf->hwbuf); + assert(sbuf->map.num_ranges); + assert(sbuf->dma.svga == svga); + assert(sbuf->dma.boxes); + + /* + * Patch the DMA command with the final copy box. + */ + + SVGA_DBG(DEBUG_DMA, "dma to sid %p\n", sbuf->handle); + + boxes = sbuf->dma.boxes; + for(i = 0; i < sbuf->map.num_ranges; ++i) { + SVGA_DBG(DEBUG_DMA, " bytes %u - %u\n", + sbuf->map.ranges[i].start, sbuf->map.ranges[i].end); + + boxes[i].x = sbuf->map.ranges[i].start; + boxes[i].y = 0; + boxes[i].z = 0; + boxes[i].w = sbuf->map.ranges[i].end - sbuf->map.ranges[i].start; + boxes[i].h = 1; + boxes[i].d = 1; + boxes[i].srcx = sbuf->map.ranges[i].start; + boxes[i].srcy = 0; + boxes[i].srcz = 0; + } + + sbuf->map.num_ranges = 0; + + assert(sbuf->head.prev && sbuf->head.next); + LIST_DEL(&sbuf->head); +#ifdef DEBUG + sbuf->head.next = sbuf->head.prev = NULL; +#endif + sbuf->dma.pending = FALSE; + + sbuf->dma.svga = NULL; + sbuf->dma.boxes = NULL; + + /* Decrement reference count */ + pipe_reference(&(sbuf->b.b.reference), NULL); + sbuf = NULL; +} + + + +/** + * Note a dirty range. + * + * This function only notes the range down. It doesn't actually emit a DMA + * upload command. That only happens when a context tries to refer to this + * buffer, and the DMA upload command is added to that context's command buffer. + * + * We try to lump as many contiguous DMA transfers together as possible. + */ +void +svga_buffer_add_range(struct svga_buffer *sbuf, + unsigned start, + unsigned end) +{ + unsigned i; + unsigned nearest_range; + unsigned nearest_dist; + + assert(end > start); + + if (sbuf->map.num_ranges < SVGA_BUFFER_MAX_RANGES) { + nearest_range = sbuf->map.num_ranges; + nearest_dist = ~0; + } else { + nearest_range = SVGA_BUFFER_MAX_RANGES - 1; + nearest_dist = 0; + } + + /* + * Try to grow one of the ranges. + * + * Note that it is not this function task to care about overlapping ranges, + * as the GMR was already given so it is too late to do anything. Situations + * where overlapping ranges may pose a problem should be detected via + * pipe_context::is_resource_referenced and the context that refers to the + * buffer should be flushed. + */ + + for(i = 0; i < sbuf->map.num_ranges; ++i) { + int left_dist; + int right_dist; + int dist; + + left_dist = start - sbuf->map.ranges[i].end; + right_dist = sbuf->map.ranges[i].start - end; + dist = MAX2(left_dist, right_dist); + + if (dist <= 0) { + /* + * Ranges are contiguous or overlapping -- extend this one and return. + */ + + sbuf->map.ranges[i].start = MIN2(sbuf->map.ranges[i].start, start); + sbuf->map.ranges[i].end = MAX2(sbuf->map.ranges[i].end, end); + return; + } + else { + /* + * Discontiguous ranges -- keep track of the nearest range. + */ + + if (dist < nearest_dist) { + nearest_range = i; + nearest_dist = dist; + } + } + } + + /* + * We cannot add a new range to an existing DMA command, so patch-up the + * pending DMA upload and start clean. + */ + + if(sbuf->dma.pending) + svga_buffer_upload_flush(sbuf->dma.svga, sbuf); + + assert(!sbuf->dma.pending); + assert(!sbuf->dma.svga); + assert(!sbuf->dma.boxes); + + if (sbuf->map.num_ranges < SVGA_BUFFER_MAX_RANGES) { + /* + * Add a new range. + */ + + sbuf->map.ranges[sbuf->map.num_ranges].start = start; + sbuf->map.ranges[sbuf->map.num_ranges].end = end; + ++sbuf->map.num_ranges; + } else { + /* + * Everything else failed, so just extend the nearest range. + * + * It is OK to do this because we always keep a local copy of the + * host buffer data, for SW TNL, and the host never modifies the buffer. + */ + + assert(nearest_range < SVGA_BUFFER_MAX_RANGES); + assert(nearest_range < sbuf->map.num_ranges); + sbuf->map.ranges[nearest_range].start = MIN2(sbuf->map.ranges[nearest_range].start, start); + sbuf->map.ranges[nearest_range].end = MAX2(sbuf->map.ranges[nearest_range].end, end); + } +} + + + +/** + * Copy the contents of the malloc buffer to a hardware buffer. + */ +static INLINE enum pipe_error +svga_buffer_update_hw(struct svga_screen *ss, struct svga_buffer *sbuf) +{ + assert(!sbuf->user); + if(!sbuf->hwbuf) { + enum pipe_error ret; + void *map; + + assert(sbuf->swbuf); + if(!sbuf->swbuf) + return PIPE_ERROR; + + ret = svga_buffer_create_hw_storage(ss, sbuf); + if(ret != PIPE_OK) + return ret; + + pipe_mutex_lock(ss->swc_mutex); + map = ss->sws->buffer_map(ss->sws, sbuf->hwbuf, PIPE_TRANSFER_WRITE); + assert(map); + if(!map) { + pipe_mutex_unlock(ss->swc_mutex); + svga_buffer_destroy_hw_storage(ss, sbuf); + return PIPE_ERROR; + } + + memcpy(map, sbuf->swbuf, sbuf->b.b.width0); + ss->sws->buffer_unmap(ss->sws, sbuf->hwbuf); + + /* This user/malloc buffer is now indistinguishable from a gpu buffer */ + assert(!sbuf->map.count); + if(!sbuf->map.count) { + if(sbuf->user) + sbuf->user = FALSE; + else + align_free(sbuf->swbuf); + sbuf->swbuf = NULL; + } + + pipe_mutex_unlock(ss->swc_mutex); + } + + return PIPE_OK; +} + + +/** + * Upload the buffer to the host in a piecewise fashion. + * + * Used when the buffer is too big to fit in the GMR aperture. + */ +static INLINE enum pipe_error +svga_buffer_upload_piecewise(struct svga_screen *ss, + struct svga_context *svga, + struct svga_buffer *sbuf) +{ + struct svga_winsys_screen *sws = ss->sws; + const unsigned alignment = sizeof(void *); + const unsigned usage = 0; + unsigned i; + + assert(sbuf->map.num_ranges); + assert(!sbuf->dma.pending); + + SVGA_DBG(DEBUG_DMA, "dma to sid %p\n", sbuf->handle); + + for (i = 0; i < sbuf->map.num_ranges; ++i) { + struct svga_buffer_range *range = &sbuf->map.ranges[i]; + unsigned offset = range->start; + unsigned size = range->end - range->start; + + while (offset < range->end) { + struct svga_winsys_buffer *hwbuf; + uint8_t *map; + enum pipe_error ret; + + if (offset + size > range->end) + size = range->end - offset; + + hwbuf = sws->buffer_create(sws, alignment, usage, size); + while (!hwbuf) { + size /= 2; + if (!size) + return PIPE_ERROR_OUT_OF_MEMORY; + hwbuf = sws->buffer_create(sws, alignment, usage, size); + } + + SVGA_DBG(DEBUG_DMA, " bytes %u - %u\n", + offset, offset + size); + + map = sws->buffer_map(sws, hwbuf, + PIPE_TRANSFER_WRITE | + PIPE_TRANSFER_DISCARD); + assert(map); + if (map) { + memcpy(map, sbuf->swbuf, size); + sws->buffer_unmap(sws, hwbuf); + } + + ret = SVGA3D_BufferDMA(svga->swc, + hwbuf, sbuf->handle, + SVGA3D_WRITE_HOST_VRAM, + size, 0, offset, sbuf->dma.flags); + if(ret != PIPE_OK) { + svga_context_flush(svga, NULL); + ret = SVGA3D_BufferDMA(svga->swc, + hwbuf, sbuf->handle, + SVGA3D_WRITE_HOST_VRAM, + size, 0, offset, sbuf->dma.flags); + assert(ret == PIPE_OK); + } + + sbuf->dma.flags.discard = FALSE; + + sws->buffer_destroy(sws, hwbuf); + + offset += size; + } + } + + sbuf->map.num_ranges = 0; + + return PIPE_OK; +} + + + + +/* Get (or create/upload) the winsys surface handle so that we can + * refer to this buffer in fifo commands. + */ +struct svga_winsys_surface * +svga_buffer_handle(struct svga_context *svga, + struct pipe_resource *buf) +{ + struct pipe_screen *screen = svga->pipe.screen; + struct svga_screen *ss = svga_screen(screen); + struct svga_buffer *sbuf; + enum pipe_error ret; + + if(!buf) + return NULL; + + sbuf = svga_buffer(buf); + + assert(!sbuf->map.count); + assert(!sbuf->user); + + if(!sbuf->handle) { + ret = svga_buffer_create_host_surface(ss, sbuf); + if(ret != PIPE_OK) + return NULL; + } + + assert(sbuf->handle); + + if (sbuf->map.num_ranges) { + if (!sbuf->dma.pending) { + /* + * No pending DMA upload yet, so insert a DMA upload command now. + */ + + /* + * Migrate the data from swbuf -> hwbuf if necessary. + */ + ret = svga_buffer_update_hw(ss, sbuf); + if (ret == PIPE_OK) { + /* + * Queue a dma command. + */ + + ret = svga_buffer_upload_command(svga, sbuf); + if (ret == PIPE_ERROR_OUT_OF_MEMORY) { + svga_context_flush(svga, NULL); + ret = svga_buffer_upload_command(svga, sbuf); + assert(ret == PIPE_OK); + } + if (ret == PIPE_OK) { + sbuf->dma.pending = TRUE; + assert(!sbuf->head.prev && !sbuf->head.next); + LIST_ADDTAIL(&sbuf->head, &svga->dirty_buffers); + } + } + else if (ret == PIPE_ERROR_OUT_OF_MEMORY) { + /* + * The buffer is too big to fit in the GMR aperture, so break it in + * smaller pieces. + */ + ret = svga_buffer_upload_piecewise(ss, svga, sbuf); + } + + if (ret != PIPE_OK) { + /* + * Something unexpected happened above. There is very little that + * we can do other than proceeding while ignoring the dirty ranges. + */ + assert(0); + sbuf->map.num_ranges = 0; + } + } + else { + /* + * There a pending dma already. Make sure it is from this context. + */ + assert(sbuf->dma.svga == svga); + } + } + + assert(!sbuf->map.num_ranges || sbuf->dma.pending); + + return sbuf->handle; +} + + + +void +svga_context_flush_buffers(struct svga_context *svga) +{ + struct list_head *curr, *next; + struct svga_buffer *sbuf; + + curr = svga->dirty_buffers.next; + next = curr->next; + while(curr != &svga->dirty_buffers) { + sbuf = LIST_ENTRY(struct svga_buffer, curr, head); + + assert(p_atomic_read(&sbuf->b.b.reference.count) != 0); + assert(sbuf->dma.pending); + + svga_buffer_upload_flush(svga, sbuf); + + curr = next; + next = curr->next; + } +} diff --git a/src/gallium/drivers/svga/svga_resource_buffer_upload.h b/src/gallium/drivers/svga/svga_resource_buffer_upload.h new file mode 100644 index 0000000..11df306 --- /dev/null +++ b/src/gallium/drivers/svga/svga_resource_buffer_upload.h @@ -0,0 +1,54 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_BUFFER_UPLOAD_H +#define SVGA_BUFFER_UPLOAD_H + + +void +svga_buffer_add_range(struct svga_buffer *sbuf, + unsigned start, + unsigned end); + +enum pipe_error +svga_buffer_create_hw_storage(struct svga_screen *ss, + struct svga_buffer *sbuf); + +void +svga_buffer_destroy_hw_storage(struct svga_screen *ss, + struct svga_buffer *sbuf); + +enum pipe_error +svga_buffer_create_host_surface(struct svga_screen *ss, + struct svga_buffer *sbuf); + +void +svga_buffer_destroy_host_surface(struct svga_screen *ss, + struct svga_buffer *sbuf); + + + + +#endif /* SVGA_BUFFER_H */ diff --git a/src/gallium/drivers/svga/svga_resource_texture.c b/src/gallium/drivers/svga/svga_resource_texture.c new file mode 100644 index 0000000..7c9e600 --- /dev/null +++ b/src/gallium/drivers/svga/svga_resource_texture.c @@ -0,0 +1,646 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "svga_cmd.h" + +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "os/os_thread.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "svga_screen.h" +#include "svga_context.h" +#include "svga_resource_texture.h" +#include "svga_resource_buffer.h" +#include "svga_sampler_view.h" +#include "svga_winsys.h" +#include "svga_debug.h" + + +/* XXX: This isn't a real hardware flag, but just a hack for kernel to + * know about primary surfaces. Find a better way to accomplish this. + */ +#define SVGA3D_SURFACE_HINT_SCANOUT (1 << 9) + + +static unsigned int +svga_texture_is_referenced( struct pipe_context *pipe, + struct pipe_resource *texture, + unsigned level, int layer) +{ + struct svga_texture *tex = svga_texture(texture); + struct svga_screen *ss = svga_screen(pipe->screen); + + /** + * The screen does not cache texture writes. + */ + + if (!tex->handle || ss->sws->surface_is_flushed(ss->sws, tex->handle)) + return PIPE_UNREFERENCED; + + /** + * sws->surface_is_flushed() does not distinguish between read references + * and write references. So assume a reference is both. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + + + +/* + * Helper function and arrays + */ + +SVGA3dSurfaceFormat +svga_translate_format(enum pipe_format format) +{ + switch(format) { + + case PIPE_FORMAT_B8G8R8A8_UNORM: + return SVGA3D_A8R8G8B8; + case PIPE_FORMAT_B8G8R8X8_UNORM: + return SVGA3D_X8R8G8B8; + + /* Required for GL2.1: + */ + case PIPE_FORMAT_B8G8R8A8_SRGB: + return SVGA3D_A8R8G8B8; + + case PIPE_FORMAT_B5G6R5_UNORM: + return SVGA3D_R5G6B5; + case PIPE_FORMAT_B5G5R5A1_UNORM: + return SVGA3D_A1R5G5B5; + case PIPE_FORMAT_B4G4R4A4_UNORM: + return SVGA3D_A4R4G4B4; + + + /* XXX: Doesn't seem to work properly. + case PIPE_FORMAT_Z32_UNORM: + return SVGA3D_Z_D32; + */ + case PIPE_FORMAT_Z16_UNORM: + return SVGA3D_Z_D16; + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + return SVGA3D_Z_D24S8; + case PIPE_FORMAT_X8Z24_UNORM: + return SVGA3D_Z_D24X8; + + case PIPE_FORMAT_A8_UNORM: + return SVGA3D_ALPHA8; + case PIPE_FORMAT_L8_UNORM: + return SVGA3D_LUMINANCE8; + + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + return SVGA3D_DXT1; + case PIPE_FORMAT_DXT3_RGBA: + return SVGA3D_DXT3; + case PIPE_FORMAT_DXT5_RGBA: + return SVGA3D_DXT5; + + default: + return SVGA3D_FORMAT_INVALID; + } +} + + +SVGA3dSurfaceFormat +svga_translate_format_render(enum pipe_format format) +{ + switch(format) { + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_Z32_UNORM: + case PIPE_FORMAT_Z16_UNORM: + case PIPE_FORMAT_L8_UNORM: + return svga_translate_format(format); + +#if 1 + /* For on host conversion */ + case PIPE_FORMAT_DXT1_RGB: + return SVGA3D_X8R8G8B8; + case PIPE_FORMAT_DXT1_RGBA: + case PIPE_FORMAT_DXT3_RGBA: + case PIPE_FORMAT_DXT5_RGBA: + return SVGA3D_A8R8G8B8; +#endif + + default: + return SVGA3D_FORMAT_INVALID; + } +} + + +static INLINE void +svga_transfer_dma_band(struct svga_context *svga, + struct svga_transfer *st, + SVGA3dTransferType transfer, + unsigned y, unsigned h, unsigned srcy) +{ + struct svga_texture *texture = svga_texture(st->base.resource); + SVGA3dCopyBox box; + enum pipe_error ret; + + box.x = st->base.box.x; + box.y = y; + box.z = st->base.box.z; + box.w = st->base.box.width; + box.h = h; + box.d = 1; + box.srcx = 0; + box.srcy = srcy; + box.srcz = 0; + + if (st->base.resource->target == PIPE_TEXTURE_CUBE) { + st->face = st->base.box.z; + box.z = 0; + } + else + st->face = 0; + + SVGA_DBG(DEBUG_DMA, "dma %s sid %p, face %u, (%u, %u, %u) - (%u, %u, %u), %ubpp\n", + transfer == SVGA3D_WRITE_HOST_VRAM ? "to" : "from", + texture->handle, + st->face, + st->base.box.x, + y, + box.z, + st->base.box.x + st->base.box.width, + y + h, + box.z + 1, + util_format_get_blocksize(texture->b.b.format) * 8 / + (util_format_get_blockwidth(texture->b.b.format)*util_format_get_blockheight(texture->b.b.format))); + + ret = SVGA3D_SurfaceDMA(svga->swc, st, transfer, &box, 1); + if(ret != PIPE_OK) { + svga->swc->flush(svga->swc, NULL); + ret = SVGA3D_SurfaceDMA(svga->swc, st, transfer, &box, 1); + assert(ret == PIPE_OK); + } +} + + +static INLINE void +svga_transfer_dma(struct svga_context *svga, + struct svga_transfer *st, + SVGA3dTransferType transfer) +{ + struct svga_texture *texture = svga_texture(st->base.resource); + struct svga_screen *screen = svga_screen(texture->b.b.screen); + struct svga_winsys_screen *sws = screen->sws; + struct pipe_fence_handle *fence = NULL; + + if (transfer == SVGA3D_READ_HOST_VRAM) { + SVGA_DBG(DEBUG_PERF, "%s: readback transfer\n", __FUNCTION__); + } + + + if(!st->swbuf) { + /* Do the DMA transfer in a single go */ + + svga_transfer_dma_band(svga, st, transfer, st->base.box.y, st->base.box.height, 0); + + if(transfer == SVGA3D_READ_HOST_VRAM) { + svga_context_flush(svga, &fence); + sws->fence_finish(sws, fence, 0); + sws->fence_reference(sws, &fence, NULL); + } + } + else { + unsigned y, h, srcy; + unsigned blockheight = util_format_get_blockheight(st->base.resource->format); + h = st->hw_nblocksy * blockheight; + srcy = 0; + for(y = 0; y < st->base.box.height; y += h) { + unsigned offset, length; + void *hw, *sw; + + if (y + h > st->base.box.height) + h = st->base.box.height - y; + + /* Transfer band must be aligned to pixel block boundaries */ + assert(y % blockheight == 0); + assert(h % blockheight == 0); + + offset = y * st->base.stride / blockheight; + length = h * st->base.stride / blockheight; + + sw = (uint8_t *)st->swbuf + offset; + + if(transfer == SVGA3D_WRITE_HOST_VRAM) { + /* Wait for the previous DMAs to complete */ + /* TODO: keep one DMA (at half the size) in the background */ + if(y) { + svga_context_flush(svga, &fence); + sws->fence_finish(sws, fence, 0); + sws->fence_reference(sws, &fence, NULL); + } + + hw = sws->buffer_map(sws, st->hwbuf, PIPE_TRANSFER_WRITE); + assert(hw); + if(hw) { + memcpy(hw, sw, length); + sws->buffer_unmap(sws, st->hwbuf); + } + } + + svga_transfer_dma_band(svga, st, transfer, y, h, srcy); + + if(transfer == SVGA3D_READ_HOST_VRAM) { + svga_context_flush(svga, &fence); + sws->fence_finish(sws, fence, 0); + + hw = sws->buffer_map(sws, st->hwbuf, PIPE_TRANSFER_READ); + assert(hw); + if(hw) { + memcpy(sw, hw, length); + sws->buffer_unmap(sws, st->hwbuf); + } + } + } + } +} + + + + + +static boolean +svga_texture_get_handle(struct pipe_screen *screen, + struct pipe_resource *texture, + struct winsys_handle *whandle) +{ + struct svga_winsys_screen *sws = svga_winsys_screen(texture->screen); + unsigned stride; + + assert(svga_texture(texture)->key.cachable == 0); + svga_texture(texture)->key.cachable = 0; + stride = util_format_get_nblocksx(texture->format, texture->width0) * + util_format_get_blocksize(texture->format); + return sws->surface_get_handle(sws, svga_texture(texture)->handle, stride, whandle); +} + + +static void +svga_texture_destroy(struct pipe_screen *screen, + struct pipe_resource *pt) +{ + struct svga_screen *ss = svga_screen(screen); + struct svga_texture *tex = (struct svga_texture *)pt; + + ss->texture_timestamp++; + + svga_sampler_view_reference(&tex->cached_view, NULL); + + /* + DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); + */ + SVGA_DBG(DEBUG_DMA, "unref sid %p (texture)\n", tex->handle); + svga_screen_surface_destroy(ss, &tex->key, &tex->handle); + + FREE(tex); +} + + + + + + + +/* XXX: Still implementing this as if it was a screen function, but + * can now modify it to queue transfers on the context. + */ +static struct pipe_transfer * +svga_texture_get_transfer(struct pipe_context *pipe, + struct pipe_resource *texture, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct svga_context *svga = svga_context(pipe); + struct svga_screen *ss = svga_screen(pipe->screen); + struct svga_winsys_screen *sws = ss->sws; + struct svga_transfer *st; + unsigned nblocksx = util_format_get_nblocksx(texture->format, box->width); + unsigned nblocksy = util_format_get_nblocksy(texture->format, box->height); + + /* We can't map texture storage directly */ + if (usage & PIPE_TRANSFER_MAP_DIRECTLY) + return NULL; + + assert(box->depth == 1); + st = CALLOC_STRUCT(svga_transfer); + if (!st) + return NULL; + + pipe_resource_reference(&st->base.resource, texture); + st->base.level = level; + st->base.usage = usage; + st->base.box = *box; + st->base.stride = nblocksx*util_format_get_blocksize(texture->format); + st->base.layer_stride = 0; + + st->hw_nblocksy = nblocksy; + + st->hwbuf = svga_winsys_buffer_create(svga, + 1, + 0, + st->hw_nblocksy*st->base.stride); + while(!st->hwbuf && (st->hw_nblocksy /= 2)) { + st->hwbuf = svga_winsys_buffer_create(svga, + 1, + 0, + st->hw_nblocksy*st->base.stride); + } + + if(!st->hwbuf) + goto no_hwbuf; + + if(st->hw_nblocksy < nblocksy) { + /* We couldn't allocate a hardware buffer big enough for the transfer, + * so allocate regular malloc memory instead */ + debug_printf("%s: failed to allocate %u KB of DMA, splitting into %u x %u KB DMA transfers\n", + __FUNCTION__, + (nblocksy*st->base.stride + 1023)/1024, + (nblocksy + st->hw_nblocksy - 1)/st->hw_nblocksy, + (st->hw_nblocksy*st->base.stride + 1023)/1024); + st->swbuf = MALLOC(nblocksy*st->base.stride); + if(!st->swbuf) + goto no_swbuf; + } + + if (usage & PIPE_TRANSFER_READ) + svga_transfer_dma(svga, st, SVGA3D_READ_HOST_VRAM); + + return &st->base; + +no_swbuf: + sws->buffer_destroy(sws, st->hwbuf); +no_hwbuf: + FREE(st); + return NULL; +} + + +/* XXX: Still implementing this as if it was a screen function, but + * can now modify it to queue transfers on the context. + */ +static void * +svga_texture_transfer_map( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct svga_screen *ss = svga_screen(pipe->screen); + struct svga_winsys_screen *sws = ss->sws; + struct svga_transfer *st = svga_transfer(transfer); + + if(st->swbuf) + return st->swbuf; + else + /* The wait for read transfers already happened when svga_transfer_dma + * was called. */ + return sws->buffer_map(sws, st->hwbuf, transfer->usage); +} + + +/* XXX: Still implementing this as if it was a screen function, but + * can now modify it to queue transfers on the context. + */ +static void +svga_texture_transfer_unmap(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct svga_screen *ss = svga_screen(pipe->screen); + struct svga_winsys_screen *sws = ss->sws; + struct svga_transfer *st = svga_transfer(transfer); + + if(!st->swbuf) + sws->buffer_unmap(sws, st->hwbuf); +} + + +static void +svga_texture_transfer_destroy(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct svga_context *svga = svga_context(pipe); + struct svga_texture *tex = svga_texture(transfer->resource); + struct svga_screen *ss = svga_screen(pipe->screen); + struct svga_winsys_screen *sws = ss->sws; + struct svga_transfer *st = svga_transfer(transfer); + + if (st->base.usage & PIPE_TRANSFER_WRITE) { + svga_transfer_dma(svga, st, SVGA3D_WRITE_HOST_VRAM); + ss->texture_timestamp++; + tex->view_age[transfer->level] = ++(tex->age); + if (transfer->resource->target == PIPE_TEXTURE_CUBE) + tex->defined[transfer->box.z][transfer->level] = TRUE; + else + tex->defined[0][transfer->level] = TRUE; + } + + pipe_resource_reference(&st->base.resource, NULL); + FREE(st->swbuf); + sws->buffer_destroy(sws, st->hwbuf); + FREE(st); +} + + + + + +struct u_resource_vtbl svga_texture_vtbl = +{ + svga_texture_get_handle, /* get_handle */ + svga_texture_destroy, /* resource_destroy */ + svga_texture_is_referenced, /* is_resource_referenced */ + svga_texture_get_transfer, /* get_transfer */ + svga_texture_transfer_destroy, /* transfer_destroy */ + svga_texture_transfer_map, /* transfer_map */ + u_default_transfer_flush_region, /* transfer_flush_region */ + svga_texture_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; + + + + +struct pipe_resource * +svga_texture_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + struct svga_screen *svgascreen = svga_screen(screen); + struct svga_texture *tex = CALLOC_STRUCT(svga_texture); + + if (!tex) + goto error1; + + tex->b.b = *template; + tex->b.vtbl = &svga_texture_vtbl; + pipe_reference_init(&tex->b.b.reference, 1); + tex->b.b.screen = screen; + + assert(template->last_level < SVGA_MAX_TEXTURE_LEVELS); + if(template->last_level >= SVGA_MAX_TEXTURE_LEVELS) + goto error2; + + tex->key.flags = 0; + tex->key.size.width = template->width0; + tex->key.size.height = template->height0; + tex->key.size.depth = template->depth0; + + if(template->target == PIPE_TEXTURE_CUBE) { + tex->key.flags |= SVGA3D_SURFACE_CUBEMAP; + tex->key.numFaces = 6; + } + else { + tex->key.numFaces = 1; + } + + tex->key.cachable = 1; + + if (template->bind & PIPE_BIND_SAMPLER_VIEW) + tex->key.flags |= SVGA3D_SURFACE_HINT_TEXTURE; + + if (template->bind & PIPE_BIND_DISPLAY_TARGET) { + tex->key.cachable = 0; + } + + if (template->bind & PIPE_BIND_SHARED) { + tex->key.cachable = 0; + } + + if (template->bind & PIPE_BIND_SCANOUT) { + tex->key.flags |= SVGA3D_SURFACE_HINT_SCANOUT; + tex->key.cachable = 0; + } + + /* + * XXX: Never pass the SVGA3D_SURFACE_HINT_RENDERTARGET hint. Mesa cannot + * know beforehand whether a texture will be used as a rendertarget or not + * and it always requests PIPE_BIND_RENDER_TARGET, therefore + * passing the SVGA3D_SURFACE_HINT_RENDERTARGET here defeats its purpose. + */ +#if 0 + if((template->bind & PIPE_BIND_RENDER_TARGET) && + !util_format_is_s3tc(template->format)) + tex->key.flags |= SVGA3D_SURFACE_HINT_RENDERTARGET; +#endif + + if(template->bind & PIPE_BIND_DEPTH_STENCIL) + tex->key.flags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL; + + tex->key.numMipLevels = template->last_level + 1; + + tex->key.format = svga_translate_format(template->format); + if(tex->key.format == SVGA3D_FORMAT_INVALID) + goto error2; + + SVGA_DBG(DEBUG_DMA, "surface_create for texture\n", tex->handle); + tex->handle = svga_screen_surface_create(svgascreen, &tex->key); + if (tex->handle) + SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture)\n", tex->handle); + + return &tex->b.b; + +error2: + FREE(tex); +error1: + return NULL; +} + + + + +struct pipe_resource * +svga_texture_from_handle(struct pipe_screen *screen, + const struct pipe_resource *template, + struct winsys_handle *whandle) +{ + struct svga_winsys_screen *sws = svga_winsys_screen(screen); + struct svga_winsys_surface *srf; + struct svga_texture *tex; + enum SVGA3dSurfaceFormat format = 0; + assert(screen); + + /* Only supports one type */ + if ((template->target != PIPE_TEXTURE_2D && + template->target != PIPE_TEXTURE_RECT) || + template->last_level != 0 || + template->depth0 != 1) { + return NULL; + } + + srf = sws->surface_from_handle(sws, whandle, &format); + + if (!srf) + return NULL; + + if (svga_translate_format(template->format) != format) { + unsigned f1 = svga_translate_format(template->format); + unsigned f2 = format; + + /* It's okay for XRGB and ARGB or depth with/out stencil to get mixed up */ + if ( !( (f1 == SVGA3D_X8R8G8B8 && f2 == SVGA3D_A8R8G8B8) || + (f1 == SVGA3D_A8R8G8B8 && f2 == SVGA3D_X8R8G8B8) || + (f1 == SVGA3D_Z_D24X8 && f2 == SVGA3D_Z_D24S8) ) ) { + debug_printf("%s wrong format %u != %u\n", __FUNCTION__, f1, f2); + return NULL; + } + } + + tex = CALLOC_STRUCT(svga_texture); + if (!tex) + return NULL; + + tex->b.b = *template; + tex->b.vtbl = &svga_texture_vtbl; + pipe_reference_init(&tex->b.b.reference, 1); + tex->b.b.screen = screen; + + if (format == SVGA3D_X8R8G8B8) + tex->b.b.format = PIPE_FORMAT_B8G8R8X8_UNORM; + else if (format == SVGA3D_A8R8G8B8) + tex->b.b.format = PIPE_FORMAT_B8G8R8A8_UNORM; + else { + /* ?? */ + } + + SVGA_DBG(DEBUG_DMA, "wrap surface sid %p\n", srf); + + tex->key.cachable = 0; + tex->handle = srf; + + return &tex->b.b; +} + diff --git a/src/gallium/drivers/svga/svga_resource_texture.h b/src/gallium/drivers/svga/svga_resource_texture.h new file mode 100644 index 0000000..9a2911c --- /dev/null +++ b/src/gallium/drivers/svga/svga_resource_texture.h @@ -0,0 +1,136 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_TEXTURE_H +#define SVGA_TEXTURE_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "util/u_transfer.h" +#include "svga_screen_cache.h" + +struct pipe_context; +struct pipe_screen; +struct svga_context; +struct svga_winsys_surface; +enum SVGA3dSurfaceFormat; + + +#define SVGA_MAX_TEXTURE_LEVELS 16 + + +extern struct u_resource_vtbl svga_texture_vtbl; + + +struct svga_texture +{ + struct u_resource b; + + boolean defined[6][SVGA_MAX_TEXTURE_LEVELS]; + + struct svga_sampler_view *cached_view; + + unsigned view_age[SVGA_MAX_TEXTURE_LEVELS]; + unsigned age; + + boolean views_modified; + + /** + * Creation key for the host surface handle. + * + * This structure describes all the host surface characteristics so that it + * can be looked up in cache, since creating a host surface is often a slow + * operation. + */ + struct svga_host_surface_cache_key key; + + /** + * Handle for the host side surface. + * + * This handle is owned by this texture. Views should hold on to a reference + * to this texture and never destroy this handle directly. + */ + struct svga_winsys_surface *handle; +}; + + + +/* Note this is only used for texture (not buffer) transfers: + */ +struct svga_transfer +{ + struct pipe_transfer base; + + unsigned face; + + struct svga_winsys_buffer *hwbuf; + + /* Height of the hardware buffer in pixel blocks */ + unsigned hw_nblocksy; + + /* Temporary malloc buffer when we can't allocate a hardware buffer + * big enough */ + void *swbuf; +}; + + +static INLINE struct svga_texture *svga_texture( struct pipe_resource *resource ) +{ + struct svga_texture *tex = (struct svga_texture *)resource; + assert(tex == NULL || tex->b.vtbl == &svga_texture_vtbl); + return tex; +} + + +static INLINE struct svga_transfer * +svga_transfer(struct pipe_transfer *transfer) +{ + assert(transfer); + return (struct svga_transfer *)transfer; +} + + + +struct pipe_resource * +svga_texture_create(struct pipe_screen *screen, + const struct pipe_resource *template); + +struct pipe_resource * +svga_texture_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle); + + + +enum SVGA3dSurfaceFormat +svga_translate_format(enum pipe_format format); + +enum SVGA3dSurfaceFormat +svga_translate_format_render(enum pipe_format format); + + +#endif /* SVGA_TEXTURE_H */ diff --git a/src/gallium/drivers/svga/svga_sampler_view.c b/src/gallium/drivers/svga/svga_sampler_view.c new file mode 100644 index 0000000..6911f13 --- /dev/null +++ b/src/gallium/drivers/svga/svga_sampler_view.c @@ -0,0 +1,196 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "svga_cmd.h" + +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "os/os_thread.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "svga_screen.h" +#include "svga_context.h" +#include "svga_resource_texture.h" +#include "svga_sampler_view.h" +#include "svga_debug.h" +#include "svga_surface.h" + + +struct svga_sampler_view * +svga_get_tex_sampler_view(struct pipe_context *pipe, + struct pipe_resource *pt, + unsigned min_lod, unsigned max_lod) +{ + struct svga_screen *ss = svga_screen(pt->screen); + struct svga_texture *tex = svga_texture(pt); + struct svga_sampler_view *sv = NULL; + SVGA3dSurfaceFormat format = svga_translate_format(pt->format); + boolean view = TRUE; + + assert(pt); + assert(min_lod >= 0); + assert(min_lod <= max_lod); + assert(max_lod <= pt->last_level); + + + /* Is a view needed */ + { + /* + * Can't control max lod. For first level views and when we only + * look at one level we disable mip filtering to achive the same + * results as a view. + */ + if (min_lod == 0 && max_lod >= pt->last_level) + view = FALSE; + + if (util_format_is_s3tc(pt->format) && view) { + format = svga_translate_format_render(pt->format); + } + + if (ss->debug.no_sampler_view) + view = FALSE; + + if (ss->debug.force_sampler_view) + view = TRUE; + } + + /* First try the cache */ + if (view) { + pipe_mutex_lock(ss->tex_mutex); + if (tex->cached_view && + tex->cached_view->min_lod == min_lod && + tex->cached_view->max_lod == max_lod) { + svga_sampler_view_reference(&sv, tex->cached_view); + pipe_mutex_unlock(ss->tex_mutex); + SVGA_DBG(DEBUG_VIEWS, "svga: Sampler view: reuse %p, %u %u, last %u\n", + pt, min_lod, max_lod, pt->last_level); + svga_validate_sampler_view(svga_context(pipe), sv); + return sv; + } + pipe_mutex_unlock(ss->tex_mutex); + } + + sv = CALLOC_STRUCT(svga_sampler_view); + pipe_reference_init(&sv->reference, 1); + pipe_resource_reference(&sv->texture, pt); + sv->min_lod = min_lod; + sv->max_lod = max_lod; + + /* No view needed just use the whole texture */ + if (!view) { + SVGA_DBG(DEBUG_VIEWS, + "svga: Sampler view: no %p, mips %u..%u, nr %u, size (%ux%ux%u), last %u\n", + pt, min_lod, max_lod, + max_lod - min_lod + 1, + pt->width0, + pt->height0, + pt->depth0, + pt->last_level); + sv->key.cachable = 0; + sv->handle = tex->handle; + return sv; + } + + SVGA_DBG(DEBUG_VIEWS, + "svga: Sampler view: yes %p, mips %u..%u, nr %u, size (%ux%ux%u), last %u\n", + pt, min_lod, max_lod, + max_lod - min_lod + 1, + pt->width0, + pt->height0, + pt->depth0, + pt->last_level); + + sv->age = tex->age; + sv->handle = svga_texture_view_surface(pipe, tex, format, + min_lod, + max_lod - min_lod + 1, + -1, -1, + &sv->key); + + if (!sv->handle) { + assert(0); + sv->key.cachable = 0; + sv->handle = tex->handle; + return sv; + } + + pipe_mutex_lock(ss->tex_mutex); + svga_sampler_view_reference(&tex->cached_view, sv); + pipe_mutex_unlock(ss->tex_mutex); + + return sv; +} + +void +svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *v) +{ + struct svga_texture *tex = svga_texture(v->texture); + unsigned numFaces; + unsigned age = 0; + int i, k; + + assert(svga); + + if (v->handle == tex->handle) + return; + + age = tex->age; + + if(tex->b.b.target == PIPE_TEXTURE_CUBE) + numFaces = 6; + else + numFaces = 1; + + for (i = v->min_lod; i <= v->max_lod; i++) { + for (k = 0; k < numFaces; k++) { + if (v->age < tex->view_age[i]) + svga_texture_copy_handle(svga, + tex->handle, 0, 0, 0, i, k, + v->handle, 0, 0, 0, i - v->min_lod, k, + u_minify(tex->b.b.width0, i), + u_minify(tex->b.b.height0, i), + u_minify(tex->b.b.depth0, i)); + } + } + + v->age = age; +} + +void +svga_destroy_sampler_view_priv(struct svga_sampler_view *v) +{ + struct svga_texture *tex = svga_texture(v->texture); + + if(v->handle != tex->handle) { + struct svga_screen *ss = svga_screen(v->texture->screen); + SVGA_DBG(DEBUG_DMA, "unref sid %p (sampler view)\n", v->handle); + svga_screen_surface_destroy(ss, &v->key, &v->handle); + } + pipe_resource_reference(&v->texture, NULL); + FREE(v); +} diff --git a/src/gallium/drivers/svga/svga_sampler_view.h b/src/gallium/drivers/svga/svga_sampler_view.h new file mode 100644 index 0000000..e64665f --- /dev/null +++ b/src/gallium/drivers/svga/svga_sampler_view.h @@ -0,0 +1,97 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_SAMPLER_VIEW_H +#define SVGA_SAMPLER_VIEW_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "svga_screen_cache.h" + +struct pipe_context; +struct pipe_screen; +struct svga_context; +struct svga_winsys_surface; +enum SVGA3dSurfaceFormat; + + +/** + * A sampler's view into a texture + * + * We currently cache one sampler view on + * the texture and in there by holding a reference + * from the texture to the sampler view. + * + * Because of this we can not hold a refernce to the + * texture from the sampler view. So the user + * of the sampler views must make sure that the + * texture has a reference take for as long as + * the sampler view is refrenced. + * + * Just unreferencing the sampler_view before the + * texture is enough. + */ +struct svga_sampler_view +{ + struct pipe_reference reference; + + struct pipe_resource *texture; + + int min_lod; + int max_lod; + + unsigned age; + + struct svga_host_surface_cache_key key; + struct svga_winsys_surface *handle; +}; + + + +extern struct svga_sampler_view * +svga_get_tex_sampler_view(struct pipe_context *pipe, + struct pipe_resource *pt, + unsigned min_lod, unsigned max_lod); + +void +svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *v); + +void +svga_destroy_sampler_view_priv(struct svga_sampler_view *v); + +static INLINE void +svga_sampler_view_reference(struct svga_sampler_view **ptr, struct svga_sampler_view *v) +{ + struct svga_sampler_view *old = *ptr; + + if (pipe_reference(&(*ptr)->reference, &v->reference)) + svga_destroy_sampler_view_priv(old); + *ptr = v; +} + + +#endif diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c new file mode 100644 index 0000000..0781903 --- /dev/null +++ b/src/gallium/drivers/svga/svga_screen.c @@ -0,0 +1,547 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "util/u_string.h" +#include "util/u_math.h" + +#include "svga_winsys.h" +#include "svga_public.h" +#include "svga_context.h" +#include "svga_screen.h" +#include "svga_resource_texture.h" +#include "svga_resource.h" +#include "svga_debug.h" +#include "svga_surface.h" + +#include "svga3d_shaderdefs.h" + + +#ifdef DEBUG +int SVGA_DEBUG = 0; + +static const struct debug_named_value svga_debug_flags[] = { + { "dma", DEBUG_DMA, NULL }, + { "tgsi", DEBUG_TGSI, NULL }, + { "pipe", DEBUG_PIPE, NULL }, + { "state", DEBUG_STATE, NULL }, + { "screen", DEBUG_SCREEN, NULL }, + { "tex", DEBUG_TEX, NULL }, + { "swtnl", DEBUG_SWTNL, NULL }, + { "const", DEBUG_CONSTS, NULL }, + { "viewport", DEBUG_VIEWPORT, NULL }, + { "views", DEBUG_VIEWS, NULL }, + { "perf", DEBUG_PERF, NULL }, + { "flush", DEBUG_FLUSH, NULL }, + { "sync", DEBUG_SYNC, NULL }, + { "cache", DEBUG_CACHE, NULL }, + DEBUG_NAMED_VALUE_END +}; +#endif + +static const char * +svga_get_vendor( struct pipe_screen *pscreen ) +{ + return "VMware, Inc."; +} + + +static const char * +svga_get_name( struct pipe_screen *pscreen ) +{ +#ifdef DEBUG + /* Only return internal details in the DEBUG version: + */ + return "SVGA3D; build: DEBUG; mutex: " PIPE_ATOMIC; +#else + return "SVGA3D; build: RELEASE; "; +#endif +} + + + + +static float +svga_get_paramf(struct pipe_screen *screen, enum pipe_cap param) +{ + struct svga_screen *svgascreen = svga_screen(screen); + struct svga_winsys_screen *sws = svgascreen->sws; + SVGA3dDevCapResult result; + + switch (param) { + case PIPE_CAP_MAX_LINE_WIDTH: + /* fall-through */ + case PIPE_CAP_MAX_LINE_WIDTH_AA: + return 7.0; + + case PIPE_CAP_MAX_POINT_WIDTH: + /* fall-through */ + case PIPE_CAP_MAX_POINT_WIDTH_AA: + /* Keep this to a reasonable size to avoid failures in + * conform/pntaa.c: + */ + return SVGA_MAX_POINTSIZE; + + case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: + if(!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_TEXTURE_ANISOTROPY, &result)) + return 4.0; + return result.u; + + case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: + return 16.0; + + case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: + return 16; + case PIPE_CAP_MAX_COMBINED_SAMPLERS: + return 16; + case PIPE_CAP_NPOT_TEXTURES: + return 1; + case PIPE_CAP_TWO_SIDED_STENCIL: + return 1; + case PIPE_CAP_GLSL: + return svgascreen->use_ps30 && svgascreen->use_vs30; + case PIPE_CAP_ANISOTROPIC_FILTER: + return 1; + case PIPE_CAP_POINT_SPRITE: + return 1; + case PIPE_CAP_MAX_RENDER_TARGETS: + if(!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_RENDER_TARGETS, &result)) + return 1; + if(!result.u) + return 1; + return MIN2(result.u, PIPE_MAX_COLOR_BUFS); + case PIPE_CAP_OCCLUSION_QUERY: + return 1; + case PIPE_CAP_TIMER_QUERY: + return 0; + case PIPE_CAP_TEXTURE_SHADOW_MAP: + return 1; + + case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: + { + unsigned levels = SVGA_MAX_TEXTURE_LEVELS; + if (sws->get_cap(sws, SVGA3D_DEVCAP_MAX_TEXTURE_WIDTH, &result)) + levels = MIN2(util_logbase2(result.u) + 1, levels); + else + levels = 12 /* 2048x2048 */; + if (sws->get_cap(sws, SVGA3D_DEVCAP_MAX_TEXTURE_HEIGHT, &result)) + levels = MIN2(util_logbase2(result.u) + 1, levels); + else + levels = 12 /* 2048x2048 */; + return levels; + } + + case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: + if (!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_VOLUME_EXTENT, &result)) + return 8; /* max 128x128x128 */ + return MIN2(util_logbase2(result.u) + 1, SVGA_MAX_TEXTURE_LEVELS); + + case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: + /* + * No mechanism to query the host, and at least limited to 2048x2048 on + * certain hardware. + */ + return MIN2(screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS), + 12.0 /* 2048x2048 */); + + case PIPE_CAP_TEXTURE_MIRROR_REPEAT: /* req. for GL 1.4 */ + return 1; + + case PIPE_CAP_BLEND_EQUATION_SEPARATE: /* req. for GL 1.5 */ + return 1; + + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: + return 1; + case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: + case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: + return 0; + + case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: + return 1; + + default: + return 0; + } +} + + +/* This is a fairly pointless interface + */ +static int +svga_get_param(struct pipe_screen *screen, enum pipe_cap param) +{ + return (int) svga_get_paramf( screen, param ); +} + +static int svga_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shader_cap param) +{ + struct svga_screen *svgascreen = svga_screen(screen); + struct svga_winsys_screen *sws = svgascreen->sws; + SVGA3dDevCapResult result; + + switch (shader) + { + case PIPE_SHADER_FRAGMENT: + switch (param) + { + case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: + return svgascreen->use_ps30 ? 512 : 96; + case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: + return SVGA3D_MAX_NESTING_LEVEL; + case PIPE_SHADER_CAP_MAX_INPUTS: + return 10; + case PIPE_SHADER_CAP_MAX_CONSTS: + return svgascreen->use_ps30 ? 224 : 16; + case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: + return 1; + case PIPE_SHADER_CAP_MAX_TEMPS: + if (!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_TEMPS, &result)) + return svgascreen->use_ps30 ? 32 : 12; + return result.u; + case PIPE_SHADER_CAP_MAX_ADDRS: + return svgascreen->use_ps30 ? 1 : 0; + case PIPE_SHADER_CAP_MAX_PREDS: + return svgascreen->use_ps30 ? 1 : 0; + case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: + return 1; + case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: + return svgascreen->use_ps30 ? 1 : 0; + case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: + case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: + return 0; + case PIPE_SHADER_CAP_SUBROUTINES: + return 0; + } + break; + case PIPE_SHADER_VERTEX: + switch (param) + { + case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: + if (!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_VERTEX_SHADER_INSTRUCTIONS, &result)) + return svgascreen->use_vs30 ? 512 : 256; + return result.u; + case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: + case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: + /* XXX: until we have vertex texture support */ + return 0; + case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: + return SVGA3D_MAX_NESTING_LEVEL; + case PIPE_SHADER_CAP_MAX_INPUTS: + return 16; + case PIPE_SHADER_CAP_MAX_CONSTS: + return 256; + case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: + return 1; + case PIPE_SHADER_CAP_MAX_TEMPS: + if (!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEMPS, &result)) + return svgascreen->use_vs30 ? 32 : 12; + return result.u; + case PIPE_SHADER_CAP_MAX_ADDRS: + return svgascreen->use_vs30 ? 1 : 0; + case PIPE_SHADER_CAP_MAX_PREDS: + return svgascreen->use_vs30 ? 1 : 0; + case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: + return 1; + case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: + case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: + return svgascreen->use_vs30 ? 1 : 0; + case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: + return 0; + case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: + return 1; + case PIPE_SHADER_CAP_SUBROUTINES: + return 0; + default: + break; + } + break; + default: + break; + } + return 0; +} + +static INLINE SVGA3dDevCapIndex +svga_translate_format_cap(enum pipe_format format) +{ + switch(format) { + + case PIPE_FORMAT_B8G8R8A8_UNORM: + return SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8; + case PIPE_FORMAT_B8G8R8X8_UNORM: + return SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8; + + case PIPE_FORMAT_B5G6R5_UNORM: + return SVGA3D_DEVCAP_SURFACEFMT_R5G6B5; + case PIPE_FORMAT_B5G5R5A1_UNORM: + return SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5; + case PIPE_FORMAT_B4G4R4A4_UNORM: + return SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4; + + case PIPE_FORMAT_Z16_UNORM: + return SVGA3D_DEVCAP_SURFACEFMT_Z_D16; + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: + return SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8; + case PIPE_FORMAT_X8Z24_UNORM: + return SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8; + + case PIPE_FORMAT_A8_UNORM: + return SVGA3D_DEVCAP_SURFACEFMT_ALPHA8; + case PIPE_FORMAT_L8_UNORM: + return SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8; + + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + return SVGA3D_DEVCAP_SURFACEFMT_DXT1; + case PIPE_FORMAT_DXT3_RGBA: + return SVGA3D_DEVCAP_SURFACEFMT_DXT3; + case PIPE_FORMAT_DXT5_RGBA: + return SVGA3D_DEVCAP_SURFACEFMT_DXT5; + + default: + return SVGA3D_DEVCAP_MAX; + } +} + + +static boolean +svga_is_format_supported( struct pipe_screen *screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned tex_usage, + unsigned geom_flags ) +{ + struct svga_winsys_screen *sws = svga_screen(screen)->sws; + SVGA3dDevCapIndex index; + SVGA3dDevCapResult result; + + assert(tex_usage); + + if (sample_count > 1) + return FALSE; + + /* Override host capabilities */ + if (tex_usage & PIPE_BIND_RENDER_TARGET) { + switch(format) { + + /* Often unsupported/problematic. This means we end up with the same + * visuals for all virtual hardware implementations. + */ + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: + return FALSE; + + /* Simulate ability to render into compressed textures */ + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + case PIPE_FORMAT_DXT3_RGBA: + case PIPE_FORMAT_DXT5_RGBA: + return TRUE; + + default: + break; + } + } + + /* Try to query the host */ + index = svga_translate_format_cap(format); + if( index < SVGA3D_DEVCAP_MAX && + sws->get_cap(sws, index, &result) ) + { + SVGA3dSurfaceFormatCaps mask; + + mask.value = 0; + if (tex_usage & PIPE_BIND_RENDER_TARGET) + mask.offscreenRenderTarget = 1; + if (tex_usage & PIPE_BIND_DEPTH_STENCIL) + mask.zStencil = 1; + if (tex_usage & PIPE_BIND_SAMPLER_VIEW) + mask.texture = 1; + + if ((result.u & mask.value) == mask.value) + return TRUE; + else + return FALSE; + } + + /* Use our translate functions directly rather than relying on a + * duplicated list of supported formats which is prone to getting + * out of sync: + */ + if(tex_usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL)) + return svga_translate_format_render(format) != SVGA3D_FORMAT_INVALID; + else + return svga_translate_format(format) != SVGA3D_FORMAT_INVALID; +} + + +static void +svga_fence_reference(struct pipe_screen *screen, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + struct svga_winsys_screen *sws = svga_screen(screen)->sws; + sws->fence_reference(sws, ptr, fence); +} + + +static int +svga_fence_signalled(struct pipe_screen *screen, + struct pipe_fence_handle *fence, + unsigned flag) +{ + struct svga_winsys_screen *sws = svga_screen(screen)->sws; + return sws->fence_signalled(sws, fence, flag); +} + + +static int +svga_fence_finish(struct pipe_screen *screen, + struct pipe_fence_handle *fence, + unsigned flag) +{ + struct svga_winsys_screen *sws = svga_screen(screen)->sws; + + SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "%s fence_ptr %p\n", + __FUNCTION__, fence); + + return sws->fence_finish(sws, fence, flag); +} + + +static void +svga_destroy_screen( struct pipe_screen *screen ) +{ + struct svga_screen *svgascreen = svga_screen(screen); + + svga_screen_cache_cleanup(svgascreen); + + pipe_mutex_destroy(svgascreen->swc_mutex); + pipe_mutex_destroy(svgascreen->tex_mutex); + + svgascreen->sws->destroy(svgascreen->sws); + + FREE(svgascreen); +} + + +/** + * Create a new svga_screen object + */ +struct pipe_screen * +svga_screen_create(struct svga_winsys_screen *sws) +{ + struct svga_screen *svgascreen; + struct pipe_screen *screen; + SVGA3dDevCapResult result; + +#ifdef DEBUG + SVGA_DEBUG = debug_get_flags_option("SVGA_DEBUG", svga_debug_flags, 0 ); +#endif + + svgascreen = CALLOC_STRUCT(svga_screen); + if (!svgascreen) + goto error1; + + svgascreen->debug.force_level_surface_view = + debug_get_bool_option("SVGA_FORCE_LEVEL_SURFACE_VIEW", FALSE); + svgascreen->debug.force_surface_view = + debug_get_bool_option("SVGA_FORCE_SURFACE_VIEW", FALSE); + svgascreen->debug.force_sampler_view = + debug_get_bool_option("SVGA_FORCE_SAMPLER_VIEW", FALSE); + svgascreen->debug.no_surface_view = + debug_get_bool_option("SVGA_NO_SURFACE_VIEW", FALSE); + svgascreen->debug.no_sampler_view = + debug_get_bool_option("SVGA_NO_SAMPLER_VIEW", FALSE); + + screen = &svgascreen->screen; + + screen->destroy = svga_destroy_screen; + screen->get_name = svga_get_name; + screen->get_vendor = svga_get_vendor; + screen->get_param = svga_get_param; + screen->get_shader_param = svga_get_shader_param; + screen->get_paramf = svga_get_paramf; + screen->is_format_supported = svga_is_format_supported; + screen->context_create = svga_context_create; + screen->fence_reference = svga_fence_reference; + screen->fence_signalled = svga_fence_signalled; + screen->fence_finish = svga_fence_finish; + svgascreen->sws = sws; + + svga_init_screen_resource_functions(svgascreen); + + svgascreen->use_ps30 = + sws->get_cap(sws, SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION, &result) && + result.u >= SVGA3DPSVERSION_30 ? TRUE : FALSE; + + svgascreen->use_vs30 = + sws->get_cap(sws, SVGA3D_DEVCAP_VERTEX_SHADER_VERSION, &result) && + result.u >= SVGA3DVSVERSION_30 ? TRUE : FALSE; + +#if 1 + /* Shader model 2.0 is unsupported at the moment. */ + if(!svgascreen->use_ps30 || !svgascreen->use_vs30) + goto error2; +#else + if(debug_get_bool_option("SVGA_NO_SM30", FALSE)) + svgascreen->use_vs30 = svgascreen->use_ps30 = FALSE; +#endif + + pipe_mutex_init(svgascreen->tex_mutex); + pipe_mutex_init(svgascreen->swc_mutex); + + svga_screen_cache_init(svgascreen); + + return screen; +error2: + FREE(svgascreen); +error1: + return NULL; +} + +struct svga_winsys_screen * +svga_winsys_screen(struct pipe_screen *screen) +{ + return svga_screen(screen)->sws; +} + +#ifdef DEBUG +struct svga_screen * +svga_screen(struct pipe_screen *screen) +{ + assert(screen); + assert(screen->destroy == svga_destroy_screen); + return (struct svga_screen *)screen; +} +#endif diff --git a/src/gallium/drivers/svga/svga_screen.h b/src/gallium/drivers/svga/svga_screen.h new file mode 100644 index 0000000..86ec89d --- /dev/null +++ b/src/gallium/drivers/svga/svga_screen.h @@ -0,0 +1,83 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_SCREEN_H +#define SVGA_SCREEN_H + + +#include "pipe/p_screen.h" +#include "os/os_thread.h" + +#include "util/u_double_list.h" + +#include "svga_screen_cache.h" + + +struct svga_winsys_screen; +struct svga_winsys_context; +struct SVGACmdMemory; + +#define SVGA_COMBINE_USERBUFFERS 1 + +/** + * Subclass of pipe_screen + */ +struct svga_screen +{ + struct pipe_screen screen; + struct svga_winsys_screen *sws; + + unsigned use_ps30; + unsigned use_vs30; + + struct { + boolean force_level_surface_view; + boolean force_surface_view; + boolean no_surface_view; + boolean force_sampler_view; + boolean no_sampler_view; + } debug; + + unsigned texture_timestamp; + pipe_mutex tex_mutex; + + pipe_mutex swc_mutex; /* Used for buffer uploads */ + + struct svga_host_surface_cache cache; +}; + +#ifndef DEBUG +/** cast wrapper */ +static INLINE struct svga_screen * +svga_screen(struct pipe_screen *pscreen) +{ + return (struct svga_screen *) pscreen; +} +#else +struct svga_screen * +svga_screen(struct pipe_screen *screen); +#endif + +#endif /* SVGA_SCREEN_H */ diff --git a/src/gallium/drivers/svga/svga_screen_cache.c b/src/gallium/drivers/svga/svga_screen_cache.c new file mode 100644 index 0000000..eff36e0 --- /dev/null +++ b/src/gallium/drivers/svga/svga_screen_cache.c @@ -0,0 +1,347 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_memory.h" +#include "util/u_hash.h" + +#include "svga_debug.h" +#include "svga_winsys.h" +#include "svga_screen.h" +#include "svga_screen_cache.h" + + +#define SVGA_SURFACE_CACHE_ENABLED 1 + + +/** + * Compute the bucket for this key. + */ +static INLINE unsigned +svga_screen_cache_bucket(const struct svga_host_surface_cache_key *key) +{ + return util_hash_crc32( key, sizeof *key ) % SVGA_HOST_SURFACE_CACHE_BUCKETS; +} + + +static INLINE struct svga_winsys_surface * +svga_screen_cache_lookup(struct svga_screen *svgascreen, + const struct svga_host_surface_cache_key *key) +{ + struct svga_host_surface_cache *cache = &svgascreen->cache; + struct svga_winsys_screen *sws = svgascreen->sws; + struct svga_host_surface_cache_entry *entry; + struct svga_winsys_surface *handle = NULL; + struct list_head *curr, *next; + unsigned bucket; + unsigned tries = 0; + + assert(key->cachable); + + bucket = svga_screen_cache_bucket(key); + + pipe_mutex_lock(cache->mutex); + + curr = cache->bucket[bucket].next; + next = curr->next; + while(curr != &cache->bucket[bucket]) { + ++tries; + + entry = LIST_ENTRY(struct svga_host_surface_cache_entry, curr, bucket_head); + + assert(entry->handle); + + if(memcmp(&entry->key, key, sizeof *key) == 0 && + sws->fence_signalled( sws, entry->fence, 0 ) == 0) { + assert(sws->surface_is_flushed(sws, entry->handle)); + + handle = entry->handle; // Reference is transfered here. + entry->handle = NULL; + + LIST_DEL(&entry->bucket_head); + + LIST_DEL(&entry->head); + + LIST_ADD(&entry->head, &cache->empty); + + break; + } + + curr = next; + next = curr->next; + } + + pipe_mutex_unlock(cache->mutex); + + if (SVGA_DEBUG & DEBUG_DMA) + debug_printf("%s: cache %s after %u tries (bucket %d)\n", __FUNCTION__, + handle ? "hit" : "miss", tries, bucket); + + return handle; +} + + +/* + * Transfers a handle reference. + */ + +static INLINE void +svga_screen_cache_add(struct svga_screen *svgascreen, + const struct svga_host_surface_cache_key *key, + struct svga_winsys_surface **p_handle) +{ + struct svga_host_surface_cache *cache = &svgascreen->cache; + struct svga_winsys_screen *sws = svgascreen->sws; + struct svga_host_surface_cache_entry *entry = NULL; + struct svga_winsys_surface *handle = *p_handle; + + assert(key->cachable); + + assert(handle); + if(!handle) + return; + + *p_handle = NULL; + pipe_mutex_lock(cache->mutex); + + if(!LIST_IS_EMPTY(&cache->empty)) { + /* use the first empty entry */ + entry = LIST_ENTRY(struct svga_host_surface_cache_entry, cache->empty.next, head); + + LIST_DEL(&entry->head); + } + else if(!LIST_IS_EMPTY(&cache->unused)) { + /* free the last used buffer and reuse its entry */ + entry = LIST_ENTRY(struct svga_host_surface_cache_entry, cache->unused.prev, head); + SVGA_DBG(DEBUG_CACHE|DEBUG_DMA, + "unref sid %p (make space)\n", entry->handle); + sws->surface_reference(sws, &entry->handle, NULL); + + LIST_DEL(&entry->bucket_head); + + LIST_DEL(&entry->head); + } + + if(entry) { + entry->handle = handle; + memcpy(&entry->key, key, sizeof entry->key); + + SVGA_DBG(DEBUG_CACHE|DEBUG_DMA, + "cache sid %p\n", entry->handle); + LIST_ADD(&entry->head, &cache->validated); + } + else { + /* Couldn't cache the buffer -- this really shouldn't happen */ + SVGA_DBG(DEBUG_CACHE|DEBUG_DMA, + "unref sid %p (couldn't find space)\n", handle); + sws->surface_reference(sws, &handle, NULL); + } + + pipe_mutex_unlock(cache->mutex); +} + + +/** + * Called during the screen flush to move all buffers not in a validate list + * into the unused list. + */ +void +svga_screen_cache_flush(struct svga_screen *svgascreen, + struct pipe_fence_handle *fence) +{ + struct svga_host_surface_cache *cache = &svgascreen->cache; + struct svga_winsys_screen *sws = svgascreen->sws; + struct svga_host_surface_cache_entry *entry; + struct list_head *curr, *next; + unsigned bucket; + + pipe_mutex_lock(cache->mutex); + + curr = cache->validated.next; + next = curr->next; + while(curr != &cache->validated) { + entry = LIST_ENTRY(struct svga_host_surface_cache_entry, curr, head); + + assert(entry->handle); + + if(sws->surface_is_flushed(sws, entry->handle)) { + LIST_DEL(&entry->head); + + svgascreen->sws->fence_reference(svgascreen->sws, &entry->fence, fence); + + LIST_ADD(&entry->head, &cache->unused); + + bucket = svga_screen_cache_bucket(&entry->key); + LIST_ADD(&entry->bucket_head, &cache->bucket[bucket]); + } + + curr = next; + next = curr->next; + } + + pipe_mutex_unlock(cache->mutex); +} + + +void +svga_screen_cache_cleanup(struct svga_screen *svgascreen) +{ + struct svga_host_surface_cache *cache = &svgascreen->cache; + struct svga_winsys_screen *sws = svgascreen->sws; + unsigned i; + + for(i = 0; i < SVGA_HOST_SURFACE_CACHE_SIZE; ++i) { + if(cache->entries[i].handle) { + SVGA_DBG(DEBUG_CACHE|DEBUG_DMA, + "unref sid %p (shutdown)\n", cache->entries[i].handle); + sws->surface_reference(sws, &cache->entries[i].handle, NULL); + } + + if(cache->entries[i].fence) + svgascreen->sws->fence_reference(svgascreen->sws, &cache->entries[i].fence, NULL); + } + + pipe_mutex_destroy(cache->mutex); +} + + +enum pipe_error +svga_screen_cache_init(struct svga_screen *svgascreen) +{ + struct svga_host_surface_cache *cache = &svgascreen->cache; + unsigned i; + + pipe_mutex_init(cache->mutex); + + for(i = 0; i < SVGA_HOST_SURFACE_CACHE_BUCKETS; ++i) + LIST_INITHEAD(&cache->bucket[i]); + + LIST_INITHEAD(&cache->unused); + + LIST_INITHEAD(&cache->validated); + + LIST_INITHEAD(&cache->empty); + for(i = 0; i < SVGA_HOST_SURFACE_CACHE_SIZE; ++i) + LIST_ADDTAIL(&cache->entries[i].head, &cache->empty); + + return PIPE_OK; +} + + +struct svga_winsys_surface * +svga_screen_surface_create(struct svga_screen *svgascreen, + struct svga_host_surface_cache_key *key) +{ + struct svga_winsys_screen *sws = svgascreen->sws; + struct svga_winsys_surface *handle = NULL; + boolean cachable = SVGA_SURFACE_CACHE_ENABLED && key->cachable; + + SVGA_DBG(DEBUG_CACHE|DEBUG_DMA, + "%s sz %dx%dx%d mips %d faces %d cachable %d\n", + __FUNCTION__, + key->size.width, + key->size.height, + key->size.depth, + key->numMipLevels, + key->numFaces, + key->cachable); + + if (cachable) { + if (key->format == SVGA3D_BUFFER) { + /* For buffers, round the buffer size up to the nearest power + * of two to increase the probability of cache hits. Keep + * texture surface dimensions unchanged. + */ + uint32_t size = 1; + while(size < key->size.width) + size <<= 1; + key->size.width = size; + /* Since we're reusing buffers we're effectively transforming all + * of them into dynamic buffers. + * + * It would be nice to not cache long lived static buffers. But there + * is no way to detect the long lived from short lived ones yet. A + * good heuristic would be buffer size. + */ + key->flags &= ~SVGA3D_SURFACE_HINT_STATIC; + key->flags |= SVGA3D_SURFACE_HINT_DYNAMIC; + } + + handle = svga_screen_cache_lookup(svgascreen, key); + if (handle) { + if (key->format == SVGA3D_BUFFER) + SVGA_DBG(DEBUG_CACHE|DEBUG_DMA, + "reuse sid %p sz %d (buffer)\n", handle, + key->size.width); + else + SVGA_DBG(DEBUG_CACHE|DEBUG_DMA, + "reuse sid %p sz %dx%dx%d mips %d faces %d\n", handle, + key->size.width, + key->size.height, + key->size.depth, + key->numMipLevels, + key->numFaces); + } + } + + if (!handle) { + handle = sws->surface_create(sws, + key->flags, + key->format, + key->size, + key->numFaces, + key->numMipLevels); + if (handle) + SVGA_DBG(DEBUG_CACHE|DEBUG_DMA, + " CREATE sid %p sz %dx%dx%d\n", + handle, + key->size.width, + key->size.height, + key->size.depth); + } + + return handle; +} + + +void +svga_screen_surface_destroy(struct svga_screen *svgascreen, + const struct svga_host_surface_cache_key *key, + struct svga_winsys_surface **p_handle) +{ + struct svga_winsys_screen *sws = svgascreen->sws; + + /* We only set the cachable flag for surfaces of which we are the + * exclusive owner. So just hold onto our existing reference in + * that case. + */ + if(SVGA_SURFACE_CACHE_ENABLED && key->cachable) { + svga_screen_cache_add(svgascreen, key, p_handle); + } + else { + SVGA_DBG(DEBUG_DMA, + "unref sid %p (uncachable)\n", *p_handle); + sws->surface_reference(sws, p_handle, NULL); + } +} diff --git a/src/gallium/drivers/svga/svga_screen_cache.h b/src/gallium/drivers/svga/svga_screen_cache.h new file mode 100644 index 0000000..62156e3 --- /dev/null +++ b/src/gallium/drivers/svga/svga_screen_cache.h @@ -0,0 +1,144 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_SCREEN_CACHE_H_ +#define SVGA_SCREEN_CACHE_H_ + + +#include "svga_types.h" +#include "svga_reg.h" +#include "svga3d_reg.h" + +#include "os/os_thread.h" + +#include "util/u_double_list.h" + + +/* Guess the storage size of cached surfaces and try and keep it under + * this amount: + */ +#define SVGA_HOST_SURFACE_CACHE_BYTES 16*1024*1024 + +/* Maximum number of discrete surfaces in the cache: + */ +#define SVGA_HOST_SURFACE_CACHE_SIZE 1024 + +/* Number of hash buckets: + */ +#define SVGA_HOST_SURFACE_CACHE_BUCKETS 256 + + +struct svga_winsys_surface; +struct svga_screen; + +/** + * Same as svga_winsys_screen::surface_create. + */ +struct svga_host_surface_cache_key +{ + SVGA3dSurfaceFlags flags; + SVGA3dSurfaceFormat format; + SVGA3dSize size; + uint32_t numFaces:24; + uint32_t numMipLevels:7; + uint32_t cachable:1; /* False if this is a shared surface */ +}; + + +struct svga_host_surface_cache_entry +{ + /** + * Head for the LRU list, svga_host_surface_cache::unused, and + * svga_host_surface_cache::empty + */ + struct list_head head; + + /** Head for the bucket lists. */ + struct list_head bucket_head; + + struct svga_host_surface_cache_key key; + struct svga_winsys_surface *handle; + + struct pipe_fence_handle *fence; +}; + + +/** + * Cache of the host surfaces. + * + * A cache entry can be in the following stages: + * 1. empty + * 2. holding a buffer in a validate list + * 3. holding a flushed buffer (not in any validate list) with an active fence + * 4. holding a flushed buffer with an expired fence + * + * An entry progresses from 1 -> 2 -> 3 -> 4. When we need an entry to put a + * buffer into we preferencial take from 1, or from the least recentely used + * buffer from 3/4. + */ +struct svga_host_surface_cache +{ + pipe_mutex mutex; + + /* Unused buffers are put in buckets to speed up lookups */ + struct list_head bucket[SVGA_HOST_SURFACE_CACHE_BUCKETS]; + + /* Entries with unused buffers, ordered from most to least recently used + * (3 and 4) */ + struct list_head unused; + + /* Entries with buffers still in validate lists (2) */ + struct list_head validated; + + /** Empty entries (1) */ + struct list_head empty; + + /** The actual storage for the entries */ + struct svga_host_surface_cache_entry entries[SVGA_HOST_SURFACE_CACHE_SIZE]; +}; + + +void +svga_screen_cache_cleanup(struct svga_screen *svgascreen); + +void +svga_screen_cache_flush(struct svga_screen *svgascreen, + struct pipe_fence_handle *fence); + +enum pipe_error +svga_screen_cache_init(struct svga_screen *svgascreen); + + +struct svga_winsys_surface * +svga_screen_surface_create(struct svga_screen *svgascreen, + struct svga_host_surface_cache_key *key); + +void +svga_screen_surface_destroy(struct svga_screen *svgascreen, + const struct svga_host_surface_cache_key *key, + struct svga_winsys_surface **handle); + + +#endif /* SVGA_SCREEN_CACHE_H_ */ diff --git a/src/gallium/drivers/svga/svga_state.c b/src/gallium/drivers/svga/svga_state.c new file mode 100644 index 0000000..1c21d3a --- /dev/null +++ b/src/gallium/drivers/svga/svga_state.c @@ -0,0 +1,278 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_debug.h" +#include "pipe/p_defines.h" +#include "util/u_memory.h" +#include "draw/draw_context.h" + +#include "svga_context.h" +#include "svga_screen.h" +#include "svga_state.h" +#include "svga_draw.h" +#include "svga_cmd.h" +#include "svga_hw_reg.h" + +/* This is just enough to decide whether we need to use the draw + * module (swtnl) or not. + */ +static const struct svga_tracked_state *need_swtnl_state[] = +{ + &svga_update_need_swvfetch, + &svga_update_need_pipeline, + &svga_update_need_swtnl, + NULL +}; + + +/* Atoms to update hardware state prior to emitting a clear or draw + * packet. + */ +static const struct svga_tracked_state *hw_clear_state[] = +{ + &svga_hw_scissor, + &svga_hw_viewport, + &svga_hw_framebuffer, + NULL +}; + + +/* Atoms to update hardware state prior to emitting a draw packet. + */ +static const struct svga_tracked_state *hw_draw_state[] = +{ + &svga_hw_update_zero_stride, + &svga_hw_fs, + &svga_hw_vs, + &svga_hw_rss, + &svga_hw_tss, + &svga_hw_tss_binding, + &svga_hw_clip_planes, + &svga_hw_vdecl, + &svga_hw_fs_parameters, + &svga_hw_vs_parameters, + NULL +}; + + +static const struct svga_tracked_state *swtnl_draw_state[] = +{ + &svga_update_swtnl_draw, + &svga_update_swtnl_vdecl, + NULL +}; + +/* Flattens the graph of state dependencies. Could swap the positions + * of hw_clear_state and need_swtnl_state without breaking anything. + */ +static const struct svga_tracked_state **state_levels[] = +{ + need_swtnl_state, + hw_clear_state, + hw_draw_state, + swtnl_draw_state +}; + + + +static unsigned check_state( unsigned a, + unsigned b ) +{ + return (a & b); +} + +static void accumulate_state( unsigned *a, + unsigned b ) +{ + *a |= b; +} + + +static void xor_states( unsigned *result, + unsigned a, + unsigned b ) +{ + *result = a ^ b; +} + + + +static int update_state( struct svga_context *svga, + const struct svga_tracked_state *atoms[], + unsigned *state ) +{ + boolean debug = TRUE; + enum pipe_error ret = 0; + unsigned i; + + ret = svga_hwtnl_flush( svga->hwtnl ); + if (ret != 0) + return ret; + + if (debug) { + /* Debug version which enforces various sanity checks on the + * state flags which are generated and checked to help ensure + * state atoms are ordered correctly in the list. + */ + unsigned examined, prev; + + examined = 0; + prev = *state; + + for (i = 0; atoms[i] != NULL; i++) { + unsigned generated; + + assert(atoms[i]->dirty); + assert(atoms[i]->update); + + if (check_state(*state, atoms[i]->dirty)) { + if (0) + debug_printf("update: %s\n", atoms[i]->name); + ret = atoms[i]->update( svga, *state ); + if (ret != 0) + return ret; + } + + /* generated = (prev ^ state) + * if (examined & generated) + * fail; + */ + xor_states(&generated, prev, *state); + if (check_state(examined, generated)) { + debug_printf("state atom %s generated state already examined\n", + atoms[i]->name); + assert(0); + } + + prev = *state; + accumulate_state(&examined, atoms[i]->dirty); + } + } + else { + for (i = 0; atoms[i] != NULL; i++) { + if (check_state(*state, atoms[i]->dirty)) { + ret = atoms[i]->update( svga, *state ); + if (ret != 0) + return ret; + } + } + } + + return 0; +} + + + +int svga_update_state( struct svga_context *svga, + unsigned max_level ) +{ + struct svga_screen *screen = svga_screen(svga->pipe.screen); + int ret = 0; + int i; + + /* Check for updates to bound textures. This can't be done in an + * atom as there is no flag which could provoke this test, and we + * cannot create one. + */ + if (svga->state.texture_timestamp != screen->texture_timestamp) { + svga->state.texture_timestamp = screen->texture_timestamp; + svga->dirty |= SVGA_NEW_TEXTURE; + } + + for (i = 0; i <= max_level; i++) { + svga->dirty |= svga->state.dirty[i]; + + if (svga->dirty) { + ret = update_state( svga, + state_levels[i], + &svga->dirty ); + if (ret != 0) + return ret; + + svga->state.dirty[i] = 0; + } + } + + for (; i < SVGA_STATE_MAX; i++) + svga->state.dirty[i] |= svga->dirty; + + svga->dirty = 0; + return 0; +} + + + + +void svga_update_state_retry( struct svga_context *svga, + unsigned max_level ) +{ + int ret; + + ret = svga_update_state( svga, max_level ); + + if (ret == PIPE_ERROR_OUT_OF_MEMORY) { + svga_context_flush(svga, NULL); + ret = svga_update_state( svga, max_level ); + } + + assert( ret == 0 ); +} + + + +#define EMIT_RS(_rs, _count, _name, _value) \ +do { \ + _rs[_count].state = _name; \ + _rs[_count].uintValue = _value; \ + _count++; \ +} while (0) + + +/* Setup any hardware state which will be constant through the life of + * a context. + */ +enum pipe_error svga_emit_initial_state( struct svga_context *svga ) +{ + SVGA3dRenderState *rs; + unsigned count = 0; + const unsigned COUNT = 2; + enum pipe_error ret; + + ret = SVGA3D_BeginSetRenderState( svga->swc, &rs, COUNT ); + if (ret) + return ret; + + /* Always use D3D style coordinate space as this is the only one + * which is implemented on all backends. + */ + EMIT_RS(rs, count, SVGA3D_RS_COORDINATETYPE, SVGA3D_COORDINATE_LEFTHANDED ); + EMIT_RS(rs, count, SVGA3D_RS_FRONTWINDING, SVGA3D_FRONTWINDING_CW ); + + assert( COUNT == count ); + SVGA_FIFOCommitAll( svga->swc ); + + return 0; + +} diff --git a/src/gallium/drivers/svga/svga_state.h b/src/gallium/drivers/svga/svga_state.h new file mode 100644 index 0000000..22d5a6d --- /dev/null +++ b/src/gallium/drivers/svga/svga_state.h @@ -0,0 +1,95 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_STATE_H +#define SVGA_STATE_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_defines.h" + +struct svga_context; + + +void svga_init_state( struct svga_context *svga ); +void svga_destroy_state( struct svga_context *svga ); + + +struct svga_tracked_state { + const char *name; + unsigned dirty; + int (*update)( struct svga_context *svga, unsigned dirty ); +}; + +/* NEED_SWTNL + */ +extern struct svga_tracked_state svga_update_need_swvfetch; +extern struct svga_tracked_state svga_update_need_pipeline; +extern struct svga_tracked_state svga_update_need_swtnl; + +/* HW_CLEAR + */ +extern struct svga_tracked_state svga_hw_viewport; +extern struct svga_tracked_state svga_hw_scissor; +extern struct svga_tracked_state svga_hw_framebuffer; + +/* HW_DRAW + */ +extern struct svga_tracked_state svga_hw_vs; +extern struct svga_tracked_state svga_hw_fs; +extern struct svga_tracked_state svga_hw_rss; +extern struct svga_tracked_state svga_hw_tss; +extern struct svga_tracked_state svga_hw_tss_binding; +extern struct svga_tracked_state svga_hw_clip_planes; +extern struct svga_tracked_state svga_hw_vdecl; +extern struct svga_tracked_state svga_hw_fs_parameters; +extern struct svga_tracked_state svga_hw_vs_parameters; +extern struct svga_tracked_state svga_hw_update_zero_stride; + +/* SWTNL_DRAW + */ +extern struct svga_tracked_state svga_update_swtnl_draw; +extern struct svga_tracked_state svga_update_swtnl_vdecl; + +/* Bring the hardware fully up-to-date so that we can emit draw + * commands. + */ +#define SVGA_STATE_NEED_SWTNL 0 +#define SVGA_STATE_HW_CLEAR 1 +#define SVGA_STATE_HW_DRAW 2 +#define SVGA_STATE_SWTNL_DRAW 3 +#define SVGA_STATE_MAX 4 + + +enum pipe_error svga_update_state( struct svga_context *svga, + unsigned level ); + +void svga_update_state_retry( struct svga_context *svga, + unsigned level ); + + +enum pipe_error svga_emit_initial_state( struct svga_context *svga ); + +#endif diff --git a/src/gallium/drivers/svga/svga_state_constants.c b/src/gallium/drivers/svga/svga_state_constants.c new file mode 100644 index 0000000..97c818c --- /dev/null +++ b/src/gallium/drivers/svga/svga_state_constants.c @@ -0,0 +1,241 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "pipe/p_defines.h" + +#include "svga_context.h" +#include "svga_state.h" +#include "svga_cmd.h" +#include "svga_tgsi.h" +#include "svga_debug.h" + +#include "svga_hw_reg.h" + +/*********************************************************************** + * Hardware update + */ + +/* Convert from PIPE_SHADER_* to SVGA3D_SHADERTYPE_* + */ +static int svga_shader_type( int unit ) +{ + return unit + 1; +} + + +static int emit_const( struct svga_context *svga, + int unit, + int i, + const float *value ) +{ + int ret = PIPE_OK; + + if (memcmp(svga->state.hw_draw.cb[unit][i], value, 4 * sizeof(float)) != 0) { + if (SVGA_DEBUG & DEBUG_CONSTS) + debug_printf("%s %s %d: %f %f %f %f\n", + __FUNCTION__, + unit == PIPE_SHADER_VERTEX ? "VERT" : "FRAG", + i, + value[0], + value[1], + value[2], + value[3]); + + ret = SVGA3D_SetShaderConst( svga->swc, + i, + svga_shader_type(unit), + SVGA3D_CONST_TYPE_FLOAT, + value ); + if (ret) + return ret; + + memcpy(svga->state.hw_draw.cb[unit][i], value, 4 * sizeof(float)); + } + + return ret; +} + +static int emit_consts( struct svga_context *svga, + int offset, + int unit ) +{ + struct pipe_transfer *transfer = NULL; + unsigned count; + const float (*data)[4] = NULL; + unsigned i; + int ret = PIPE_OK; + + if (svga->curr.cb[unit] == NULL) + goto done; + + count = svga->curr.cb[unit]->width0 / (4 * sizeof(float)); + + data = (const float (*)[4])pipe_buffer_map(&svga->pipe, + svga->curr.cb[unit], + PIPE_TRANSFER_READ, + &transfer); + if (data == NULL) { + ret = PIPE_ERROR_OUT_OF_MEMORY; + goto done; + } + + for (i = 0; i < count; i++) { + ret = emit_const( svga, unit, offset + i, data[i] ); + if (ret) + goto done; + } + +done: + if (data) + pipe_buffer_unmap(&svga->pipe, svga->curr.cb[unit], transfer); + + return ret; +} + +static int emit_fs_consts( struct svga_context *svga, + unsigned dirty ) +{ + const struct svga_shader_result *result = svga->state.hw_draw.fs; + const struct svga_fs_compile_key *key = &result->key.fkey; + int ret = 0; + + ret = emit_consts( svga, 0, PIPE_SHADER_FRAGMENT ); + if (ret) + return ret; + + /* The internally generated fragment shader for xor blending + * doesn't have a 'result' struct. It should be fixed to avoid + * this special case, but work around it with a NULL check: + */ + if (result != NULL && + key->num_unnormalized_coords) + { + unsigned offset = result->shader->info.file_max[TGSI_FILE_CONSTANT] + 1; + int i; + + for (i = 0; i < key->num_textures; i++) { + if (key->tex[i].unnormalized) { + struct pipe_resource *tex = svga->curr.sampler_views[i]->texture; + float data[4]; + + data[0] = 1.0 / (float)tex->width0; + data[1] = 1.0 / (float)tex->height0; + data[2] = 1.0; + data[3] = 1.0; + + ret = emit_const( svga, + PIPE_SHADER_FRAGMENT, + key->tex[i].width_height_idx + offset, + data ); + if (ret) + return ret; + } + } + + offset += key->num_unnormalized_coords; + } + + return 0; +} + + +struct svga_tracked_state svga_hw_fs_parameters = +{ + "hw fs params", + (SVGA_NEW_FS_CONST_BUFFER | + SVGA_NEW_FS_RESULT | + SVGA_NEW_TEXTURE_BINDING), + emit_fs_consts +}; + +/*********************************************************************** + */ + +static int emit_vs_consts( struct svga_context *svga, + unsigned dirty ) +{ + const struct svga_shader_result *result = svga->state.hw_draw.vs; + const struct svga_vs_compile_key *key = &result->key.vkey; + int ret = 0; + unsigned offset; + + /* SVGA_NEW_VS_RESULT + */ + if (result == NULL) + return 0; + + /* SVGA_NEW_VS_CONST_BUFFER + */ + ret = emit_consts( svga, 0, PIPE_SHADER_VERTEX ); + if (ret) + return ret; + + offset = result->shader->info.file_max[TGSI_FILE_CONSTANT] + 1; + + /* SVGA_NEW_VS_RESULT + */ + if (key->need_prescale) { + ret = emit_const( svga, PIPE_SHADER_VERTEX, offset++, + svga->state.hw_clear.prescale.scale ); + if (ret) + return ret; + + ret = emit_const( svga, PIPE_SHADER_VERTEX, offset++, + svga->state.hw_clear.prescale.translate ); + if (ret) + return ret; + } + + /* SVGA_NEW_ZERO_STRIDE + */ + if (key->zero_stride_vertex_elements) { + unsigned i, curr_zero_stride = 0; + for (i = 0; i < PIPE_MAX_ATTRIBS; ++i) { + if (key->zero_stride_vertex_elements & (1 << i)) { + ret = emit_const( svga, PIPE_SHADER_VERTEX, offset++, + svga->curr.zero_stride_constants + + 4 * curr_zero_stride ); + if (ret) + return ret; + ++curr_zero_stride; + } + } + } + + return 0; +} + + +struct svga_tracked_state svga_hw_vs_parameters = +{ + "hw vs params", + (SVGA_NEW_PRESCALE | + SVGA_NEW_VS_CONST_BUFFER | + SVGA_NEW_ZERO_STRIDE | + SVGA_NEW_VS_RESULT), + emit_vs_consts +}; + diff --git a/src/gallium/drivers/svga/svga_state_framebuffer.c b/src/gallium/drivers/svga/svga_state_framebuffer.c new file mode 100644 index 0000000..fcbb35e --- /dev/null +++ b/src/gallium/drivers/svga/svga_state_framebuffer.c @@ -0,0 +1,440 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "pipe/p_defines.h" +#include "util/u_math.h" + +#include "svga_context.h" +#include "svga_state.h" +#include "svga_cmd.h" +#include "svga_debug.h" + + +/*********************************************************************** + * Hardware state update + */ + + +static int emit_framebuffer( struct svga_context *svga, + unsigned dirty ) +{ + const struct pipe_framebuffer_state *curr = &svga->curr.framebuffer; + struct pipe_framebuffer_state *hw = &svga->state.hw_clear.framebuffer; + boolean reemit = !!(dirty & SVGA_NEW_COMMAND_BUFFER); + unsigned i; + enum pipe_error ret; + + /* + * We need to reemit non-null surface bindings, even when they are not + * dirty, to ensure that the resources are paged in. + */ + + for(i = 0; i < PIPE_MAX_COLOR_BUFS; ++i) { + if (curr->cbufs[i] != hw->cbufs[i] || + (reemit && hw->cbufs[i])) { + if (svga->curr.nr_fbs++ > 8) + return PIPE_ERROR_OUT_OF_MEMORY; + + ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_COLOR0 + i, curr->cbufs[i]); + if (ret != PIPE_OK) + return ret; + + pipe_surface_reference(&hw->cbufs[i], curr->cbufs[i]); + } + } + + + if (curr->zsbuf != hw->zsbuf || + (reemit && hw->zsbuf)) { + ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_DEPTH, curr->zsbuf); + if (ret != PIPE_OK) + return ret; + + if (curr->zsbuf && + curr->zsbuf->format == PIPE_FORMAT_S8_USCALED_Z24_UNORM) { + ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_STENCIL, curr->zsbuf); + if (ret != PIPE_OK) + return ret; + } + else { + ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_STENCIL, NULL); + if (ret != PIPE_OK) + return ret; + } + + pipe_surface_reference(&hw->zsbuf, curr->zsbuf); + } + + + return 0; +} + + +struct svga_tracked_state svga_hw_framebuffer = +{ + "hw framebuffer state", + SVGA_NEW_FRAME_BUFFER | + SVGA_NEW_COMMAND_BUFFER, + emit_framebuffer +}; + + + + +/*********************************************************************** + */ + +static int emit_viewport( struct svga_context *svga, + unsigned dirty ) +{ + const struct pipe_viewport_state *viewport = &svga->curr.viewport; + struct svga_prescale prescale; + SVGA3dRect rect; + /* Not sure if this state is relevant with POSITIONT. Probably + * not, but setting to 0,1 avoids some state pingponging. + */ + float range_min = 0.0; + float range_max = 1.0; + float flip = -1.0; + boolean degenerate = FALSE; + enum pipe_error ret; + + float fb_width = svga->curr.framebuffer.width; + float fb_height = svga->curr.framebuffer.height; + + float fx = viewport->scale[0] * -1.0 + viewport->translate[0]; + float fy = flip * viewport->scale[1] * -1.0 + viewport->translate[1]; + float fw = viewport->scale[0] * 2; + float fh = flip * viewport->scale[1] * 2; + + memset( &prescale, 0, sizeof(prescale) ); + + /* Examine gallium viewport transformation and produce a screen + * rectangle and possibly vertex shader pre-transformation to + * get the same results. + */ + + SVGA_DBG(DEBUG_VIEWPORT, + "\ninitial %f,%f %fx%f\n", + fx, + fy, + fw, + fh); + + prescale.scale[0] = 1.0; + prescale.scale[1] = 1.0; + prescale.scale[2] = 1.0; + prescale.scale[3] = 1.0; + prescale.translate[0] = 0; + prescale.translate[1] = 0; + prescale.translate[2] = 0; + prescale.translate[3] = 0; + prescale.enabled = TRUE; + + + + if (fw < 0) { + prescale.scale[0] *= -1.0; + prescale.translate[0] += -fw; + fw = -fw; + fx = viewport->scale[0] * 1.0 + viewport->translate[0]; + } + + if (fh < 0) { + prescale.scale[1] *= -1.0; + prescale.translate[1] += -fh; + fh = -fh; + fy = flip * viewport->scale[1] * 1.0 + viewport->translate[1]; + } + + if (fx < 0) { + prescale.translate[0] += fx; + prescale.scale[0] *= fw / (fw + fx); + fw += fx; + fx = 0; + } + + if (fy < 0) { + prescale.translate[1] += fy; + prescale.scale[1] *= fh / (fh + fy); + fh += fy; + fy = 0; + } + + if (fx + fw > fb_width) { + prescale.scale[0] *= fw / (fb_width - fx); + prescale.translate[0] -= fx * (fw / (fb_width - fx)); + prescale.translate[0] += fx; + fw = fb_width - fx; + + } + + if (fy + fh > fb_height) { + prescale.scale[1] *= fh / (fb_height - fy); + prescale.translate[1] -= fy * (fh / (fb_height - fy)); + prescale.translate[1] += fy; + fh = fb_height - fy; + } + + if (fw < 0 || fh < 0) { + fw = fh = fx = fy = 0; + degenerate = TRUE; + goto out; + } + + + /* D3D viewport is integer space. Convert fx,fy,etc. to + * integers. + * + * TODO: adjust pretranslate correct for any subpixel error + * introduced converting to integers. + */ + rect.x = fx; + rect.y = fy; + rect.w = fw; + rect.h = fh; + + SVGA_DBG(DEBUG_VIEWPORT, + "viewport error %f,%f %fx%f\n", + fabs((float)rect.x - fx), + fabs((float)rect.y - fy), + fabs((float)rect.w - fw), + fabs((float)rect.h - fh)); + + SVGA_DBG(DEBUG_VIEWPORT, + "viewport %d,%d %dx%d\n", + rect.x, + rect.y, + rect.w, + rect.h); + + + /* Finally, to get GL rasterization rules, need to tweak the + * screen-space coordinates slightly relative to D3D which is + * what hardware implements natively. + */ + if (svga->curr.rast->templ.gl_rasterization_rules) { + float adjust_x = 0.0; + float adjust_y = 0.0; + + switch (svga->curr.reduced_prim) { + case PIPE_PRIM_LINES: + adjust_x = -0.5; + adjust_y = 0; + break; + case PIPE_PRIM_POINTS: + case PIPE_PRIM_TRIANGLES: + adjust_x = -0.375; + adjust_y = -0.5; + break; + } + + prescale.translate[0] += adjust_x; + prescale.translate[1] += adjust_y; + prescale.translate[2] = 0.5; /* D3D clip space */ + prescale.scale[2] = 0.5; /* D3D clip space */ + } + + + range_min = viewport->scale[2] * -1.0 + viewport->translate[2]; + range_max = viewport->scale[2] * 1.0 + viewport->translate[2]; + + /* D3D (and by implication SVGA) doesn't like dealing with zmax + * less than zmin. Detect that case, flip the depth range and + * invert our z-scale factor to achieve the same effect. + */ + if (range_min > range_max) { + float range_tmp; + range_tmp = range_min; + range_min = range_max; + range_max = range_tmp; + prescale.scale[2] = -prescale.scale[2]; + } + + if (prescale.enabled) { + float H[2]; + float J[2]; + int i; + + SVGA_DBG(DEBUG_VIEWPORT, + "prescale %f,%f %fx%f\n", + prescale.translate[0], + prescale.translate[1], + prescale.scale[0], + prescale.scale[1]); + + H[0] = (float)rect.w / 2.0; + H[1] = -(float)rect.h / 2.0; + J[0] = (float)rect.x + (float)rect.w / 2.0; + J[1] = (float)rect.y + (float)rect.h / 2.0; + + SVGA_DBG(DEBUG_VIEWPORT, + "H %f,%f\n" + "J %fx%f\n", + H[0], + H[1], + J[0], + J[1]); + + /* Adjust prescale to take into account the fact that it is + * going to be applied prior to the perspective divide and + * viewport transformation. + * + * Vwin = H(Vc/Vc.w) + J + * + * We want to tweak Vwin with scale and translation from above, + * as in: + * + * Vwin' = S Vwin + T + * + * But we can only modify the values at Vc. Plugging all the + * above together, and rearranging, eventually we get: + * + * Vwin' = H(Vc'/Vc'.w) + J + * where: + * Vc' = SVc + KVc.w + * K = (T + (S-1)J) / H + * + * Overwrite prescale.translate with values for K: + */ + for (i = 0; i < 2; i++) { + prescale.translate[i] = ((prescale.translate[i] + + (prescale.scale[i] - 1.0) * J[i]) / H[i]); + } + + SVGA_DBG(DEBUG_VIEWPORT, + "clipspace %f,%f %fx%f\n", + prescale.translate[0], + prescale.translate[1], + prescale.scale[0], + prescale.scale[1]); + } + +out: + if (degenerate) { + rect.x = 0; + rect.y = 0; + rect.w = 1; + rect.h = 1; + prescale.enabled = FALSE; + } + + if (memcmp(&rect, &svga->state.hw_clear.viewport, sizeof(rect)) != 0) { + ret = SVGA3D_SetViewport(svga->swc, &rect); + if(ret != PIPE_OK) + return ret; + + memcpy(&svga->state.hw_clear.viewport, &rect, sizeof(rect)); + assert(sizeof(rect) == sizeof(svga->state.hw_clear.viewport)); + } + + if (svga->state.hw_clear.depthrange.zmin != range_min || + svga->state.hw_clear.depthrange.zmax != range_max) + { + ret = SVGA3D_SetZRange(svga->swc, range_min, range_max ); + if(ret != PIPE_OK) + return ret; + + svga->state.hw_clear.depthrange.zmin = range_min; + svga->state.hw_clear.depthrange.zmax = range_max; + } + + if (memcmp(&prescale, &svga->state.hw_clear.prescale, sizeof prescale) != 0) { + svga->dirty |= SVGA_NEW_PRESCALE; + svga->state.hw_clear.prescale = prescale; + } + + return 0; +} + + +struct svga_tracked_state svga_hw_viewport = +{ + "hw viewport state", + ( SVGA_NEW_FRAME_BUFFER | + SVGA_NEW_VIEWPORT | + SVGA_NEW_RAST | + SVGA_NEW_REDUCED_PRIMITIVE ), + emit_viewport +}; + + +/*********************************************************************** + * Scissor state + */ +static int emit_scissor_rect( struct svga_context *svga, + unsigned dirty ) +{ + const struct pipe_scissor_state *scissor = &svga->curr.scissor; + SVGA3dRect rect; + + rect.x = scissor->minx; + rect.y = scissor->miny; + rect.w = scissor->maxx - scissor->minx; /* + 1 ?? */ + rect.h = scissor->maxy - scissor->miny; /* + 1 ?? */ + + return SVGA3D_SetScissorRect(svga->swc, &rect); +} + + +struct svga_tracked_state svga_hw_scissor = +{ + "hw scissor state", + SVGA_NEW_SCISSOR, + emit_scissor_rect +}; + + +/*********************************************************************** + * Userclip state + */ + +static int emit_clip_planes( struct svga_context *svga, + unsigned dirty ) +{ + unsigned i; + enum pipe_error ret; + + /* TODO: just emit directly from svga_set_clip_state()? + */ + for (i = 0; i < svga->curr.clip.nr; i++) { + ret = SVGA3D_SetClipPlane( svga->swc, + i, + svga->curr.clip.ucp[i] ); + if(ret != PIPE_OK) + return ret; + } + + return 0; +} + + +struct svga_tracked_state svga_hw_clip_planes = +{ + "hw viewport state", + SVGA_NEW_CLIP, + emit_clip_planes +}; diff --git a/src/gallium/drivers/svga/svga_state_fs.c b/src/gallium/drivers/svga/svga_state_fs.c new file mode 100644 index 0000000..ad6f294 --- /dev/null +++ b/src/gallium/drivers/svga/svga_state_fs.c @@ -0,0 +1,246 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "pipe/p_defines.h" +#include "util/u_math.h" +#include "util/u_bitmask.h" + +#include "svga_context.h" +#include "svga_state.h" +#include "svga_cmd.h" +#include "svga_tgsi.h" + +#include "svga_hw_reg.h" + + + +static INLINE int compare_fs_keys( const struct svga_fs_compile_key *a, + const struct svga_fs_compile_key *b ) +{ + unsigned keysize_a = svga_fs_key_size( a ); + unsigned keysize_b = svga_fs_key_size( b ); + + if (keysize_a != keysize_b) { + return (int)(keysize_a - keysize_b); + } + return memcmp( a, b, keysize_a ); +} + + +static struct svga_shader_result *search_fs_key( struct svga_fragment_shader *fs, + const struct svga_fs_compile_key *key ) +{ + struct svga_shader_result *result = fs->base.results; + + assert(key); + + for ( ; result; result = result->next) { + if (compare_fs_keys( key, &result->key.fkey ) == 0) + return result; + } + + return NULL; +} + + +static enum pipe_error compile_fs( struct svga_context *svga, + struct svga_fragment_shader *fs, + const struct svga_fs_compile_key *key, + struct svga_shader_result **out_result ) +{ + struct svga_shader_result *result; + enum pipe_error ret = PIPE_ERROR; + + result = svga_translate_fragment_program( fs, key ); + if (result == NULL) { + ret = PIPE_ERROR_OUT_OF_MEMORY; + goto fail; + } + + result->id = util_bitmask_add(svga->fs_bm); + if(result->id == UTIL_BITMASK_INVALID_INDEX) { + ret = PIPE_ERROR_OUT_OF_MEMORY; + goto fail; + } + + ret = SVGA3D_DefineShader(svga->swc, + result->id, + SVGA3D_SHADERTYPE_PS, + result->tokens, + result->nr_tokens * sizeof result->tokens[0]); + if (ret) + goto fail; + + *out_result = result; + result->next = fs->base.results; + fs->base.results = result; + return PIPE_OK; + +fail: + if (result) { + if (result->id != UTIL_BITMASK_INVALID_INDEX) + util_bitmask_clear( svga->fs_bm, result->id ); + svga_destroy_shader_result( result ); + } + return ret; +} + + +/* SVGA_NEW_TEXTURE_BINDING + * SVGA_NEW_RAST + * SVGA_NEW_NEED_SWTNL + * SVGA_NEW_SAMPLER + */ +static int make_fs_key( const struct svga_context *svga, + struct svga_fs_compile_key *key ) +{ + int i; + int idx = 0; + + memset(key, 0, sizeof *key); + + /* Only need fragment shader fixup for twoside lighting if doing + * hwtnl. Otherwise the draw module does the whole job for us. + * + * SVGA_NEW_SWTNL + */ + if (!svga->state.sw.need_swtnl) { + /* SVGA_NEW_RAST + */ + key->light_twoside = svga->curr.rast->templ.light_twoside; + key->front_ccw = svga->curr.rast->templ.front_ccw; + } + + /* The blend workaround for simulating logicop xor behaviour + * requires that the incoming fragment color be white. This change + * achieves that by creating a varient of the current fragment + * shader that overrides all output colors with 1,1,1,1 + * + * This will work for most shaders, including those containing + * TEXKIL and/or depth-write. However, it will break on the + * combination of xor-logicop plus alphatest. + * + * Ultimately, we could implement alphatest in the shader using + * texkil prior to overriding the outgoing fragment color. + * + * SVGA_NEW_BLEND + */ + if (svga->curr.blend->need_white_fragments) { + key->white_fragments = 1; + } + + /* XXX: want to limit this to the textures that the shader actually + * refers to. + * + * SVGA_NEW_TEXTURE_BINDING | SVGA_NEW_SAMPLER + */ + for (i = 0; i < svga->curr.num_sampler_views; i++) { + if (svga->curr.sampler_views[i]) { + assert(svga->curr.sampler[i]); + assert(svga->curr.sampler_views[i]->texture); + key->tex[i].texture_target = svga->curr.sampler_views[i]->texture->target; + if (!svga->curr.sampler[i]->normalized_coords) { + key->tex[i].width_height_idx = idx++; + key->tex[i].unnormalized = TRUE; + ++key->num_unnormalized_coords; + } + } + } + key->num_textures = svga->curr.num_sampler_views; + + idx = 0; + for (i = 0; i < svga->curr.num_samplers; ++i) { + if (svga->curr.sampler[i]) { + key->tex[i].compare_mode = svga->curr.sampler[i]->compare_mode; + key->tex[i].compare_func = svga->curr.sampler[i]->compare_func; + } + } + + return 0; +} + + + +static int emit_hw_fs( struct svga_context *svga, + unsigned dirty ) +{ + struct svga_shader_result *result = NULL; + unsigned id = SVGA3D_INVALID_ID; + int ret = 0; + + struct svga_fragment_shader *fs = svga->curr.fs; + struct svga_fs_compile_key key; + + /* SVGA_NEW_BLEND + * SVGA_NEW_TEXTURE_BINDING + * SVGA_NEW_RAST + * SVGA_NEW_NEED_SWTNL + * SVGA_NEW_SAMPLER + */ + ret = make_fs_key( svga, &key ); + if (ret) + return ret; + + result = search_fs_key( fs, &key ); + if (!result) { + ret = compile_fs( svga, fs, &key, &result ); + if (ret) + return ret; + } + + assert (result); + id = result->id; + + assert(id != SVGA3D_INVALID_ID); + + if (result != svga->state.hw_draw.fs) { + ret = SVGA3D_SetShader(svga->swc, + SVGA3D_SHADERTYPE_PS, + id ); + if (ret) + return ret; + + svga->dirty |= SVGA_NEW_FS_RESULT; + svga->state.hw_draw.fs = result; + } + + return 0; +} + +struct svga_tracked_state svga_hw_fs = +{ + "fragment shader (hwtnl)", + (SVGA_NEW_FS | + SVGA_NEW_TEXTURE_BINDING | + SVGA_NEW_NEED_SWTNL | + SVGA_NEW_RAST | + SVGA_NEW_SAMPLER | + SVGA_NEW_BLEND), + emit_hw_fs +}; + + + diff --git a/src/gallium/drivers/svga/svga_state_need_swtnl.c b/src/gallium/drivers/svga/svga_state_need_swtnl.c new file mode 100644 index 0000000..66fea02 --- /dev/null +++ b/src/gallium/drivers/svga/svga_state_need_swtnl.c @@ -0,0 +1,200 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "pipe/p_state.h" + + +#include "svga_context.h" +#include "svga_state.h" +#include "svga_debug.h" +#include "svga_hw_reg.h" + +/*********************************************************************** + */ + +static INLINE SVGA3dDeclType +svga_translate_vertex_format(enum pipe_format format) +{ + switch (format) { + case PIPE_FORMAT_R32_FLOAT: return SVGA3D_DECLTYPE_FLOAT1; + case PIPE_FORMAT_R32G32_FLOAT: return SVGA3D_DECLTYPE_FLOAT2; + case PIPE_FORMAT_R32G32B32_FLOAT: return SVGA3D_DECLTYPE_FLOAT3; + case PIPE_FORMAT_R32G32B32A32_FLOAT: return SVGA3D_DECLTYPE_FLOAT4; + case PIPE_FORMAT_B8G8R8A8_UNORM: return SVGA3D_DECLTYPE_D3DCOLOR; + case PIPE_FORMAT_R8G8B8A8_USCALED: return SVGA3D_DECLTYPE_UBYTE4; + case PIPE_FORMAT_R16G16_SSCALED: return SVGA3D_DECLTYPE_SHORT2; + case PIPE_FORMAT_R16G16B16A16_SSCALED: return SVGA3D_DECLTYPE_SHORT4; + case PIPE_FORMAT_R8G8B8A8_UNORM: return SVGA3D_DECLTYPE_UBYTE4N; + case PIPE_FORMAT_R16G16_SNORM: return SVGA3D_DECLTYPE_SHORT2N; + case PIPE_FORMAT_R16G16B16A16_SNORM: return SVGA3D_DECLTYPE_SHORT4N; + case PIPE_FORMAT_R16G16_UNORM: return SVGA3D_DECLTYPE_USHORT2N; + case PIPE_FORMAT_R16G16B16A16_UNORM: return SVGA3D_DECLTYPE_USHORT4N; + case PIPE_FORMAT_R10G10B10X2_USCALED: return SVGA3D_DECLTYPE_UDEC3; + case PIPE_FORMAT_R10G10B10X2_SNORM: return SVGA3D_DECLTYPE_DEC3N; + case PIPE_FORMAT_R16G16_FLOAT: return SVGA3D_DECLTYPE_FLOAT16_2; + case PIPE_FORMAT_R16G16B16A16_FLOAT: return SVGA3D_DECLTYPE_FLOAT16_4; + + default: + /* There are many formats without hardware support. This case + * will be hit regularly, meaning we'll need swvfetch. + */ + return SVGA3D_DECLTYPE_MAX; + } +} + + +static int update_need_swvfetch( struct svga_context *svga, + unsigned dirty ) +{ + unsigned i; + boolean need_swvfetch = FALSE; + + if (!svga->curr.velems) { + /* No vertex elements bound. */ + return 0; + } + + for (i = 0; i < svga->curr.velems->count; i++) { + svga->state.sw.ve_format[i] = svga_translate_vertex_format(svga->curr.velems->velem[i].src_format); + if (svga->state.sw.ve_format[i] == SVGA3D_DECLTYPE_MAX) { + need_swvfetch = TRUE; + break; + } + } + + if (need_swvfetch != svga->state.sw.need_swvfetch) { + svga->state.sw.need_swvfetch = need_swvfetch; + svga->dirty |= SVGA_NEW_NEED_SWVFETCH; + } + + return 0; +} + +struct svga_tracked_state svga_update_need_swvfetch = +{ + "update need_swvfetch", + ( SVGA_NEW_VELEMENT ), + update_need_swvfetch +}; + + +/*********************************************************************** + */ + +static int update_need_pipeline( struct svga_context *svga, + unsigned dirty ) +{ + + boolean need_pipeline = FALSE; + struct svga_vertex_shader *vs = svga->curr.vs; + + /* SVGA_NEW_RAST, SVGA_NEW_REDUCED_PRIMITIVE + */ + if (svga->curr.rast->need_pipeline & (1 << svga->curr.reduced_prim)) { + SVGA_DBG(DEBUG_SWTNL, "%s: rast need_pipeline (0x%x) & prim (0x%x)\n", + __FUNCTION__, + svga->curr.rast->need_pipeline, + (1 << svga->curr.reduced_prim) ); + need_pipeline = TRUE; + } + + /* EDGEFLAGS + */ + if (vs->base.info.writes_edgeflag) { + SVGA_DBG(DEBUG_SWTNL, "%s: edgeflags\n", __FUNCTION__); + need_pipeline = TRUE; + } + + /* SVGA_NEW_CLIP + */ + if (svga->curr.clip.nr) { + SVGA_DBG(DEBUG_SWTNL, "%s: userclip\n", __FUNCTION__); + need_pipeline = TRUE; + } + + if (need_pipeline != svga->state.sw.need_pipeline) { + svga->state.sw.need_pipeline = need_pipeline; + svga->dirty |= SVGA_NEW_NEED_PIPELINE; + } + + return 0; +} + + +struct svga_tracked_state svga_update_need_pipeline = +{ + "need pipeline", + (SVGA_NEW_RAST | + SVGA_NEW_CLIP | + SVGA_NEW_VS | + SVGA_NEW_REDUCED_PRIMITIVE), + update_need_pipeline +}; + + +/*********************************************************************** + */ + +static int update_need_swtnl( struct svga_context *svga, + unsigned dirty ) +{ + boolean need_swtnl; + + if (svga->debug.no_swtnl) { + svga->state.sw.need_swvfetch = 0; + svga->state.sw.need_pipeline = 0; + } + + need_swtnl = (svga->state.sw.need_swvfetch || + svga->state.sw.need_pipeline); + + if (svga->debug.force_swtnl) { + need_swtnl = 1; + } + + if (need_swtnl != svga->state.sw.need_swtnl) { + SVGA_DBG(DEBUG_SWTNL|DEBUG_PERF, + "%s need_swvfetch: %s, need_pipeline %s\n", + __FUNCTION__, + svga->state.sw.need_swvfetch ? "true" : "false", + svga->state.sw.need_pipeline ? "true" : "false"); + + svga->state.sw.need_swtnl = need_swtnl; + svga->dirty |= SVGA_NEW_NEED_SWTNL; + svga->swtnl.new_vdecl = TRUE; + } + + return 0; +} + + +struct svga_tracked_state svga_update_need_swtnl = +{ + "need swtnl", + (SVGA_NEW_NEED_PIPELINE | + SVGA_NEW_NEED_SWVFETCH), + update_need_swtnl +}; diff --git a/src/gallium/drivers/svga/svga_state_rss.c b/src/gallium/drivers/svga/svga_state_rss.c new file mode 100644 index 0000000..ab13f3f --- /dev/null +++ b/src/gallium/drivers/svga/svga_state_rss.c @@ -0,0 +1,286 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "pipe/p_defines.h" +#include "util/u_math.h" + +#include "svga_context.h" +#include "svga_state.h" +#include "svga_cmd.h" + + +struct rs_queue { + unsigned rs_count; + SVGA3dRenderState rs[SVGA3D_RS_MAX]; +}; + + +#define EMIT_RS(svga, value, token, fail) \ +do { \ + if (svga->state.hw_draw.rs[SVGA3D_RS_##token] != value) { \ + svga_queue_rs( &queue, SVGA3D_RS_##token, value ); \ + svga->state.hw_draw.rs[SVGA3D_RS_##token] = value; \ + } \ +} while (0) + +#define EMIT_RS_FLOAT(svga, fvalue, token, fail) \ +do { \ + unsigned value = fui(fvalue); \ + if (svga->state.hw_draw.rs[SVGA3D_RS_##token] != value) { \ + svga_queue_rs( &queue, SVGA3D_RS_##token, value ); \ + svga->state.hw_draw.rs[SVGA3D_RS_##token] = value; \ + } \ +} while (0) + + +static INLINE void +svga_queue_rs( struct rs_queue *q, + unsigned rss, + unsigned value ) +{ + q->rs[q->rs_count].state = rss; + q->rs[q->rs_count].uintValue = value; + q->rs_count++; +} + + +/* Compare old and new render states and emit differences between them + * to hardware. Simplest implementation would be to emit the whole of + * the "to" state. + */ +static int emit_rss( struct svga_context *svga, + unsigned dirty ) +{ + struct rs_queue queue; + + queue.rs_count = 0; + + if (dirty & SVGA_NEW_BLEND) { + const struct svga_blend_state *curr = svga->curr.blend; + + EMIT_RS( svga, curr->rt[0].writemask, COLORWRITEENABLE, fail ); + EMIT_RS( svga, curr->rt[0].blend_enable, BLENDENABLE, fail ); + + if (curr->rt[0].blend_enable) { + EMIT_RS( svga, curr->rt[0].srcblend, SRCBLEND, fail ); + EMIT_RS( svga, curr->rt[0].dstblend, DSTBLEND, fail ); + EMIT_RS( svga, curr->rt[0].blendeq, BLENDEQUATION, fail ); + + EMIT_RS( svga, curr->rt[0].separate_alpha_blend_enable, + SEPARATEALPHABLENDENABLE, fail ); + + if (curr->rt[0].separate_alpha_blend_enable) { + EMIT_RS( svga, curr->rt[0].srcblend_alpha, SRCBLENDALPHA, fail ); + EMIT_RS( svga, curr->rt[0].dstblend_alpha, DSTBLENDALPHA, fail ); + EMIT_RS( svga, curr->rt[0].blendeq_alpha, BLENDEQUATIONALPHA, fail ); + } + } + } + + if (dirty & SVGA_NEW_BLEND_COLOR) { + uint32 color; + uint32 r = float_to_ubyte(svga->curr.blend_color.color[0]); + uint32 g = float_to_ubyte(svga->curr.blend_color.color[1]); + uint32 b = float_to_ubyte(svga->curr.blend_color.color[2]); + uint32 a = float_to_ubyte(svga->curr.blend_color.color[3]); + + color = (a << 24) | (r << 16) | (g << 8) | b; + + EMIT_RS( svga, color, BLENDCOLOR, fail ); + } + + if (dirty & (SVGA_NEW_DEPTH_STENCIL | SVGA_NEW_RAST)) { + const struct svga_depth_stencil_state *curr = svga->curr.depth; + const struct svga_rasterizer_state *rast = svga->curr.rast; + + if (!curr->stencil[0].enabled) + { + /* Stencil disabled + */ + EMIT_RS( svga, FALSE, STENCILENABLE, fail ); + EMIT_RS( svga, FALSE, STENCILENABLE2SIDED, fail ); + } + else if (curr->stencil[0].enabled && !curr->stencil[1].enabled) + { + /* Regular stencil + */ + EMIT_RS( svga, TRUE, STENCILENABLE, fail ); + EMIT_RS( svga, FALSE, STENCILENABLE2SIDED, fail ); + + EMIT_RS( svga, curr->stencil[0].func, STENCILFUNC, fail ); + EMIT_RS( svga, curr->stencil[0].fail, STENCILFAIL, fail ); + EMIT_RS( svga, curr->stencil[0].zfail, STENCILZFAIL, fail ); + EMIT_RS( svga, curr->stencil[0].pass, STENCILPASS, fail ); + + EMIT_RS( svga, curr->stencil_mask, STENCILMASK, fail ); + EMIT_RS( svga, curr->stencil_writemask, STENCILWRITEMASK, fail ); + } + else + { + int cw, ccw; + + /* Hardware frontwinding is always CW, so if ours is also CW, + * then our definition of front face agrees with hardware. + * Otherwise need to flip. + */ + if (rast->templ.front_ccw) { + ccw = 0; + cw = 1; + } + else { + ccw = 1; + cw = 0; + } + + /* Twoside stencil + */ + EMIT_RS( svga, TRUE, STENCILENABLE, fail ); + EMIT_RS( svga, TRUE, STENCILENABLE2SIDED, fail ); + + EMIT_RS( svga, curr->stencil[cw].func, STENCILFUNC, fail ); + EMIT_RS( svga, curr->stencil[cw].fail, STENCILFAIL, fail ); + EMIT_RS( svga, curr->stencil[cw].zfail, STENCILZFAIL, fail ); + EMIT_RS( svga, curr->stencil[cw].pass, STENCILPASS, fail ); + + EMIT_RS( svga, curr->stencil[ccw].func, CCWSTENCILFUNC, fail ); + EMIT_RS( svga, curr->stencil[ccw].fail, CCWSTENCILFAIL, fail ); + EMIT_RS( svga, curr->stencil[ccw].zfail, CCWSTENCILZFAIL, fail ); + EMIT_RS( svga, curr->stencil[ccw].pass, CCWSTENCILPASS, fail ); + + EMIT_RS( svga, curr->stencil_mask, STENCILMASK, fail ); + EMIT_RS( svga, curr->stencil_writemask, STENCILWRITEMASK, fail ); + } + + EMIT_RS( svga, curr->zenable, ZENABLE, fail ); + if (curr->zenable) { + EMIT_RS( svga, curr->zfunc, ZFUNC, fail ); + EMIT_RS( svga, curr->zwriteenable, ZWRITEENABLE, fail ); + } + + EMIT_RS( svga, curr->alphatestenable, ALPHATESTENABLE, fail ); + if (curr->alphatestenable) { + EMIT_RS( svga, curr->alphafunc, ALPHAFUNC, fail ); + EMIT_RS_FLOAT( svga, curr->alpharef, ALPHAREF, fail ); + } + } + + if (dirty & SVGA_NEW_STENCIL_REF) { + EMIT_RS( svga, svga->curr.stencil_ref.ref_value[0], STENCILREF, fail ); + } + + if (dirty & (SVGA_NEW_RAST | SVGA_NEW_NEED_PIPELINE)) + { + const struct svga_rasterizer_state *curr = svga->curr.rast; + unsigned cullmode = curr->cullmode; + + /* Shademode: still need to rearrange index list to move + * flat-shading PV first vertex. + */ + EMIT_RS( svga, curr->shademode, SHADEMODE, fail ); + + /* Don't do culling while the software pipeline is active. It + * does it for us, and additionally introduces potentially + * back-facing triangles. + */ + if (svga->state.sw.need_pipeline) + cullmode = SVGA3D_FACE_NONE; + + EMIT_RS( svga, cullmode, CULLMODE, fail ); + EMIT_RS( svga, curr->scissortestenable, SCISSORTESTENABLE, fail ); + EMIT_RS( svga, curr->multisampleantialias, MULTISAMPLEANTIALIAS, fail ); + EMIT_RS( svga, curr->lastpixel, LASTPIXEL, fail ); + EMIT_RS( svga, curr->linepattern, LINEPATTERN, fail ); + EMIT_RS_FLOAT( svga, curr->pointsize, POINTSIZE, fail ); + /* XXX still need to set this? */ + EMIT_RS_FLOAT( svga, 0.0, POINTSIZEMIN, fail ); + EMIT_RS_FLOAT( svga, SVGA_MAX_POINTSIZE, POINTSIZEMAX, fail ); + } + + if (dirty & (SVGA_NEW_RAST | SVGA_NEW_FRAME_BUFFER | SVGA_NEW_NEED_PIPELINE)) + { + const struct svga_rasterizer_state *curr = svga->curr.rast; + float slope = 0.0; + float bias = 0.0; + + /* Need to modify depth bias according to bound depthbuffer + * format. Don't do hardware depthbias while the software + * pipeline is active. + */ + if (!svga->state.sw.need_pipeline && + svga->curr.framebuffer.zsbuf) + { + slope = curr->slopescaledepthbias; + bias = svga->curr.depthscale * curr->depthbias; + } + + EMIT_RS_FLOAT( svga, slope, SLOPESCALEDEPTHBIAS, fail ); + EMIT_RS_FLOAT( svga, bias, DEPTHBIAS, fail ); + } + + + if (queue.rs_count) { + SVGA3dRenderState *rs; + + if (SVGA3D_BeginSetRenderState( svga->swc, + &rs, + queue.rs_count ) != PIPE_OK) + goto fail; + + memcpy( rs, + queue.rs, + queue.rs_count * sizeof queue.rs[0]); + + SVGA_FIFOCommitAll( svga->swc ); + } + + return 0; + +fail: + /* XXX: need to poison cached hardware state on failure to ensure + * dirty state gets re-emitted. Fix this by re-instating partial + * FIFOCommit command and only updating cached hw state once the + * initial allocation has succeeded. + */ + memset(svga->state.hw_draw.rs, 0xcd, sizeof(svga->state.hw_draw.rs)); + + return PIPE_ERROR_OUT_OF_MEMORY; +} + + +struct svga_tracked_state svga_hw_rss = +{ + "hw rss state", + + (SVGA_NEW_BLEND | + SVGA_NEW_BLEND_COLOR | + SVGA_NEW_DEPTH_STENCIL | + SVGA_NEW_STENCIL_REF | + SVGA_NEW_RAST | + SVGA_NEW_FRAME_BUFFER | + SVGA_NEW_NEED_PIPELINE), + + emit_rss +}; diff --git a/src/gallium/drivers/svga/svga_state_tss.c b/src/gallium/drivers/svga/svga_state_tss.c new file mode 100644 index 0000000..f8b269a --- /dev/null +++ b/src/gallium/drivers/svga/svga_state_tss.c @@ -0,0 +1,289 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "pipe/p_defines.h" +#include "util/u_math.h" + +#include "svga_sampler_view.h" +#include "svga_winsys.h" +#include "svga_context.h" +#include "svga_state.h" +#include "svga_cmd.h" + + +void svga_cleanup_tss_binding(struct svga_context *svga) +{ + int i; + unsigned count = MAX2( svga->curr.num_sampler_views, + svga->state.hw_draw.num_views ); + + for (i = 0; i < count; i++) { + struct svga_hw_view_state *view = &svga->state.hw_draw.views[i]; + + svga_sampler_view_reference(&view->v, NULL); + pipe_sampler_view_reference( &svga->curr.sampler_views[i], NULL ); + pipe_resource_reference( &view->texture, NULL ); + + view->dirty = 1; + } +} + + +static int +update_tss_binding(struct svga_context *svga, + unsigned dirty ) +{ + boolean reemit = !!(dirty & SVGA_NEW_COMMAND_BUFFER); + unsigned i; + unsigned count = MAX2( svga->curr.num_sampler_views, + svga->state.hw_draw.num_views ); + unsigned min_lod; + unsigned max_lod; + + + struct { + struct { + unsigned unit; + struct svga_hw_view_state *view; + } bind[PIPE_MAX_SAMPLERS]; + + unsigned bind_count; + } queue; + + queue.bind_count = 0; + + for (i = 0; i < count; i++) { + const struct svga_sampler_state *s = svga->curr.sampler[i]; + struct svga_hw_view_state *view = &svga->state.hw_draw.views[i]; + struct pipe_resource *texture = NULL; + + /* get min max lod */ + if (svga->curr.sampler_views[i]) { + min_lod = MAX2(s->view_min_lod, 0); + max_lod = MIN2(s->view_max_lod, svga->curr.sampler_views[i]->texture->last_level); + texture = svga->curr.sampler_views[i]->texture; + } else { + min_lod = 0; + max_lod = 0; + } + + if (view->texture != texture || + view->min_lod != min_lod || + view->max_lod != max_lod) { + + svga_sampler_view_reference(&view->v, NULL); + pipe_resource_reference( &view->texture, texture ); + + view->dirty = TRUE; + view->min_lod = min_lod; + view->max_lod = max_lod; + + if (texture) + view->v = svga_get_tex_sampler_view(&svga->pipe, + texture, + min_lod, + max_lod); + } + + /* + * We need to reemit non-null texture bindings, even when they are not + * dirty, to ensure that the resources are paged in. + */ + + if (view->dirty || + (reemit && view->v)) { + queue.bind[queue.bind_count].unit = i; + queue.bind[queue.bind_count].view = view; + queue.bind_count++; + } + if (!view->dirty && view->v) { + svga_validate_sampler_view(svga, view->v); + } + } + + svga->state.hw_draw.num_views = svga->curr.num_sampler_views; + + if (queue.bind_count) { + SVGA3dTextureState *ts; + + if (SVGA3D_BeginSetTextureState( svga->swc, + &ts, + queue.bind_count ) != PIPE_OK) + goto fail; + + for (i = 0; i < queue.bind_count; i++) { + struct svga_winsys_surface *handle; + + ts[i].stage = queue.bind[i].unit; + ts[i].name = SVGA3D_TS_BIND_TEXTURE; + + if (queue.bind[i].view->v) { + handle = queue.bind[i].view->v->handle; + } + else { + handle = NULL; + } + svga->swc->surface_relocation(svga->swc, + &ts[i].value, + handle, + SVGA_RELOC_READ); + + queue.bind[i].view->dirty = FALSE; + } + + SVGA_FIFOCommitAll( svga->swc ); + } + + return 0; + +fail: + return PIPE_ERROR_OUT_OF_MEMORY; +} + + +struct svga_tracked_state svga_hw_tss_binding = { + "texture binding emit", + SVGA_NEW_TEXTURE_BINDING | + SVGA_NEW_SAMPLER | + SVGA_NEW_COMMAND_BUFFER, + update_tss_binding +}; + + +/*********************************************************************** + */ + +struct ts_queue { + unsigned ts_count; + SVGA3dTextureState ts[PIPE_MAX_SAMPLERS*SVGA3D_TS_MAX]; +}; + + +#define EMIT_TS(svga, unit, val, token, fail) \ +do { \ + if (svga->state.hw_draw.ts[unit][SVGA3D_TS_##token] != val) { \ + svga_queue_tss( &queue, unit, SVGA3D_TS_##token, val ); \ + svga->state.hw_draw.ts[unit][SVGA3D_TS_##token] = val; \ + } \ +} while (0) + +#define EMIT_TS_FLOAT(svga, unit, fvalue, token, fail) \ +do { \ + unsigned val = fui(fvalue); \ + if (svga->state.hw_draw.ts[unit][SVGA3D_TS_##token] != val) { \ + svga_queue_tss( &queue, unit, SVGA3D_TS_##token, val ); \ + svga->state.hw_draw.ts[unit][SVGA3D_TS_##token] = val; \ + } \ +} while (0) + + +static INLINE void +svga_queue_tss( struct ts_queue *q, + unsigned unit, + unsigned tss, + unsigned value ) +{ + assert(q->ts_count < sizeof(q->ts)/sizeof(q->ts[0])); + q->ts[q->ts_count].stage = unit; + q->ts[q->ts_count].name = tss; + q->ts[q->ts_count].value = value; + q->ts_count++; +} + + +static int +update_tss(struct svga_context *svga, + unsigned dirty ) +{ + unsigned i; + struct ts_queue queue; + + queue.ts_count = 0; + for (i = 0; i < svga->curr.num_samplers; i++) { + if (svga->curr.sampler[i]) { + const struct svga_sampler_state *curr = svga->curr.sampler[i]; + + EMIT_TS(svga, i, curr->mipfilter, MIPFILTER, fail); + EMIT_TS(svga, i, curr->min_lod, TEXTURE_MIPMAP_LEVEL, fail); + EMIT_TS(svga, i, curr->magfilter, MAGFILTER, fail); + EMIT_TS(svga, i, curr->minfilter, MINFILTER, fail); + EMIT_TS(svga, i, curr->aniso_level, TEXTURE_ANISOTROPIC_LEVEL, fail); + EMIT_TS_FLOAT(svga, i, curr->lod_bias, TEXTURE_LOD_BIAS, fail); + EMIT_TS(svga, i, curr->addressu, ADDRESSU, fail); + EMIT_TS(svga, i, curr->addressw, ADDRESSW, fail); + EMIT_TS(svga, i, curr->bordercolor, BORDERCOLOR, fail); + // TEXCOORDINDEX -- hopefully not needed + + if (svga->curr.tex_flags.flag_1d & (1 << i)) { + EMIT_TS(svga, i, SVGA3D_TEX_ADDRESS_WRAP, ADDRESSV, fail); + } + else + EMIT_TS(svga, i, curr->addressv, ADDRESSV, fail); + + if (svga->curr.tex_flags.flag_srgb & (1 << i)) + EMIT_TS_FLOAT(svga, i, 2.2f, GAMMA, fail); + else + EMIT_TS_FLOAT(svga, i, 1.0f, GAMMA, fail); + + } + } + + if (queue.ts_count) { + SVGA3dTextureState *ts; + + if (SVGA3D_BeginSetTextureState( svga->swc, + &ts, + queue.ts_count ) != PIPE_OK) + goto fail; + + memcpy( ts, + queue.ts, + queue.ts_count * sizeof queue.ts[0]); + + SVGA_FIFOCommitAll( svga->swc ); + } + + return 0; + +fail: + /* XXX: need to poison cached hardware state on failure to ensure + * dirty state gets re-emitted. Fix this by re-instating partial + * FIFOCommit command and only updating cached hw state once the + * initial allocation has succeeded. + */ + memset(svga->state.hw_draw.ts, 0xcd, sizeof(svga->state.hw_draw.ts)); + + return PIPE_ERROR_OUT_OF_MEMORY; +} + + +struct svga_tracked_state svga_hw_tss = { + "texture state emit", + (SVGA_NEW_SAMPLER | + SVGA_NEW_TEXTURE_FLAGS), + update_tss +}; + diff --git a/src/gallium/drivers/svga/svga_state_vdecl.c b/src/gallium/drivers/svga/svga_state_vdecl.c new file mode 100644 index 0000000..3af7bf2 --- /dev/null +++ b/src/gallium/drivers/svga/svga_state_vdecl.c @@ -0,0 +1,179 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "pipe/p_defines.h" +#include "util/u_math.h" +#include "util/u_upload_mgr.h" + +#include "svga_context.h" +#include "svga_state.h" +#include "svga_draw.h" +#include "svga_tgsi.h" +#include "svga_screen.h" +#include "svga_resource_buffer.h" + +#include "svga_hw_reg.h" + + +static int +upload_user_buffers( struct svga_context *svga ) +{ + enum pipe_error ret = PIPE_OK; + int i; + int nr; + + if (0) + debug_printf("%s: %d\n", __FUNCTION__, svga->curr.num_vertex_buffers); + + nr = svga->curr.num_vertex_buffers; + + for (i = 0; i < nr; i++) + { + if (svga_buffer_is_user_buffer(svga->curr.vb[i].buffer)) + { + struct svga_buffer *buffer = svga_buffer(svga->curr.vb[i].buffer); + + if (!buffer->uploaded.buffer) { + ret = u_upload_buffer( svga->upload_vb, + 0, + buffer->b.b.width0, + &buffer->b.b, + &buffer->uploaded.offset, + &buffer->uploaded.buffer ); + if (ret) + return ret; + + if (0) + debug_printf("%s: %d: orig buf %p upl buf %p ofs %d sz %d\n", + __FUNCTION__, + i, + buffer, + buffer->uploaded.buffer, + buffer->uploaded.offset, + buffer->b.b.width0); + } + + pipe_resource_reference( &svga->curr.vb[i].buffer, buffer->uploaded.buffer ); + svga->curr.vb[i].buffer_offset = buffer->uploaded.offset; + } + } + + if (0) + debug_printf("%s: DONE\n", __FUNCTION__); + + return ret; +} + + +/*********************************************************************** + */ + + +static int emit_hw_vs_vdecl( struct svga_context *svga, + unsigned dirty ) +{ + const struct pipe_vertex_element *ve = svga->curr.velems->velem; + SVGA3dVertexDecl decl; + unsigned i; + + assert(svga->curr.velems->count >= + svga->curr.vs->base.info.file_count[TGSI_FILE_INPUT]); + + svga_hwtnl_reset_vdecl( svga->hwtnl, + svga->curr.velems->count ); + + for (i = 0; i < svga->curr.velems->count; i++) { + const struct pipe_vertex_buffer *vb = &svga->curr.vb[ve[i].vertex_buffer_index]; + unsigned usage, index; + + + svga_generate_vdecl_semantics( i, &usage, &index ); + + /* SVGA_NEW_VELEMENT + */ + decl.identity.type = svga->state.sw.ve_format[i]; + decl.identity.method = SVGA3D_DECLMETHOD_DEFAULT; + decl.identity.usage = usage; + decl.identity.usageIndex = index; + decl.array.stride = vb->stride; + decl.array.offset = (vb->buffer_offset + + ve[i].src_offset); + + svga_hwtnl_vdecl( svga->hwtnl, + i, + &decl, + vb->buffer ); + } + + return 0; +} + + +static int emit_hw_vdecl( struct svga_context *svga, + unsigned dirty ) +{ + int ret = 0; + + /* SVGA_NEW_NEED_SWTNL + */ + if (svga->state.sw.need_swtnl) + return 0; /* Do not emit during swtnl */ + + /* If we get to here, we know that we're going to draw. Upload + * userbuffers now and try to combine multiple userbuffers from + * multiple draw calls into a single host buffer for performance. + */ + if (svga->curr.any_user_vertex_buffers && + SVGA_COMBINE_USERBUFFERS) + { + ret = upload_user_buffers( svga ); + if (ret) + return ret; + + svga->curr.any_user_vertex_buffers = FALSE; + } + + return emit_hw_vs_vdecl( svga, dirty ); +} + + +struct svga_tracked_state svga_hw_vdecl = +{ + "hw vertex decl state (hwtnl version)", + ( SVGA_NEW_NEED_SWTNL | + SVGA_NEW_VELEMENT | + SVGA_NEW_VBUFFER | + SVGA_NEW_RAST | + SVGA_NEW_FS | + SVGA_NEW_VS ), + emit_hw_vdecl +}; + + + + + + diff --git a/src/gallium/drivers/svga/svga_state_vs.c b/src/gallium/drivers/svga/svga_state_vs.c new file mode 100644 index 0000000..5133c70 --- /dev/null +++ b/src/gallium/drivers/svga/svga_state_vs.c @@ -0,0 +1,256 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "util/u_inlines.h" +#include "pipe/p_defines.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_bitmask.h" +#include "translate/translate.h" + +#include "svga_context.h" +#include "svga_state.h" +#include "svga_cmd.h" +#include "svga_tgsi.h" + +#include "svga_hw_reg.h" + +/*********************************************************************** + */ + + +static INLINE int compare_vs_keys( const struct svga_vs_compile_key *a, + const struct svga_vs_compile_key *b ) +{ + unsigned keysize = svga_vs_key_size( a ); + return memcmp( a, b, keysize ); +} + + +static struct svga_shader_result *search_vs_key( struct svga_vertex_shader *vs, + const struct svga_vs_compile_key *key ) +{ + struct svga_shader_result *result = vs->base.results; + + assert(key); + + for ( ; result; result = result->next) { + if (compare_vs_keys( key, &result->key.vkey ) == 0) + return result; + } + + return NULL; +} + + +static enum pipe_error compile_vs( struct svga_context *svga, + struct svga_vertex_shader *vs, + const struct svga_vs_compile_key *key, + struct svga_shader_result **out_result ) +{ + struct svga_shader_result *result; + enum pipe_error ret = PIPE_ERROR; + + result = svga_translate_vertex_program( vs, key ); + if (result == NULL) { + ret = PIPE_ERROR_OUT_OF_MEMORY; + goto fail; + } + + result->id = util_bitmask_add(svga->vs_bm); + if(result->id == UTIL_BITMASK_INVALID_INDEX) { + ret = PIPE_ERROR_OUT_OF_MEMORY; + goto fail; + } + + ret = SVGA3D_DefineShader(svga->swc, + result->id, + SVGA3D_SHADERTYPE_VS, + result->tokens, + result->nr_tokens * sizeof result->tokens[0]); + if (ret) + goto fail; + + *out_result = result; + result->next = vs->base.results; + vs->base.results = result; + return PIPE_OK; + +fail: + if (result) { + if (result->id != UTIL_BITMASK_INVALID_INDEX) + util_bitmask_clear( svga->vs_bm, result->id ); + svga_destroy_shader_result( result ); + } + return ret; +} + +/* SVGA_NEW_PRESCALE, SVGA_NEW_RAST, SVGA_NEW_ZERO_STRIDE + */ +static int make_vs_key( struct svga_context *svga, + struct svga_vs_compile_key *key ) +{ + memset(key, 0, sizeof *key); + key->need_prescale = svga->state.hw_clear.prescale.enabled; + key->allow_psiz = svga->curr.rast->templ.point_size_per_vertex; + key->zero_stride_vertex_elements = + svga->curr.zero_stride_vertex_elements; + key->num_zero_stride_vertex_elements = + svga->curr.num_zero_stride_vertex_elements; + return 0; +} + + + +static int emit_hw_vs( struct svga_context *svga, + unsigned dirty ) +{ + struct svga_shader_result *result = NULL; + unsigned id = SVGA3D_INVALID_ID; + int ret = 0; + + /* SVGA_NEW_NEED_SWTNL */ + if (!svga->state.sw.need_swtnl) { + struct svga_vertex_shader *vs = svga->curr.vs; + struct svga_vs_compile_key key; + + ret = make_vs_key( svga, &key ); + if (ret) + return ret; + + result = search_vs_key( vs, &key ); + if (!result) { + ret = compile_vs( svga, vs, &key, &result ); + if (ret) + return ret; + } + + assert (result); + id = result->id; + } + + if (result != svga->state.hw_draw.vs) { + ret = SVGA3D_SetShader(svga->swc, + SVGA3D_SHADERTYPE_VS, + id ); + if (ret) + return ret; + + svga->dirty |= SVGA_NEW_VS_RESULT; + svga->state.hw_draw.vs = result; + } + + return 0; +} + +struct svga_tracked_state svga_hw_vs = +{ + "vertex shader (hwtnl)", + (SVGA_NEW_VS | + SVGA_NEW_PRESCALE | + SVGA_NEW_NEED_SWTNL | + SVGA_NEW_ZERO_STRIDE), + emit_hw_vs +}; + + +/*********************************************************************** + */ +static int update_zero_stride( struct svga_context *svga, + unsigned dirty ) +{ + unsigned i; + + svga->curr.zero_stride_vertex_elements = 0; + svga->curr.num_zero_stride_vertex_elements = 0; + + for (i = 0; i < svga->curr.velems->count; i++) { + const struct pipe_vertex_element *vel = &svga->curr.velems->velem[i]; + const struct pipe_vertex_buffer *vbuffer = &svga->curr.vb[ + vel->vertex_buffer_index]; + + if (vbuffer->stride == 0) { + unsigned const_idx = + svga->curr.num_zero_stride_vertex_elements; + struct pipe_transfer *transfer; + struct translate *translate; + struct translate_key key; + void *mapped_buffer; + + svga->curr.zero_stride_vertex_elements |= (1 << i); + ++svga->curr.num_zero_stride_vertex_elements; + + key.output_stride = 4 * sizeof(float); + key.nr_elements = 1; + key.element[0].type = TRANSLATE_ELEMENT_NORMAL; + key.element[0].input_format = vel->src_format; + key.element[0].output_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + key.element[0].input_buffer = vel->vertex_buffer_index; + key.element[0].input_offset = vel->src_offset; + key.element[0].instance_divisor = vel->instance_divisor; + key.element[0].output_offset = const_idx * 4 * sizeof(float); + + translate_key_sanitize(&key); + /* translate_generic_create is technically private but + * we don't want to code-generate, just want generic + * translation */ + translate = translate_generic_create(&key); + + assert(vel->src_offset == 0); + + mapped_buffer = pipe_buffer_map_range(&svga->pipe, + vbuffer->buffer, + vel->src_offset, + util_format_get_blocksize(vel->src_format), + PIPE_TRANSFER_READ, + &transfer); + + translate->set_buffer(translate, vel->vertex_buffer_index, + mapped_buffer, + vbuffer->stride, vbuffer->max_index); + translate->run(translate, 0, 1, 0, + svga->curr.zero_stride_constants); + + pipe_buffer_unmap(&svga->pipe, + vbuffer->buffer, + transfer); + + translate->release(translate); + } + } + + if (svga->curr.num_zero_stride_vertex_elements) + svga->dirty |= SVGA_NEW_ZERO_STRIDE; + + return 0; +} + +struct svga_tracked_state svga_hw_update_zero_stride = +{ + "update zero_stride", + ( SVGA_NEW_VELEMENT | + SVGA_NEW_VBUFFER ), + update_zero_stride +}; diff --git a/src/gallium/drivers/svga/svga_surface.c b/src/gallium/drivers/svga/svga_surface.c new file mode 100644 index 0000000..3e4bed7 --- /dev/null +++ b/src/gallium/drivers/svga/svga_surface.c @@ -0,0 +1,389 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "svga_cmd.h" + +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "os/os_thread.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "svga_screen.h" +#include "svga_context.h" +#include "svga_resource_texture.h" +#include "svga_surface.h" +#include "svga_debug.h" + + +void +svga_texture_copy_handle(struct svga_context *svga, + struct svga_winsys_surface *src_handle, + unsigned src_x, unsigned src_y, unsigned src_z, + unsigned src_level, unsigned src_face, + struct svga_winsys_surface *dst_handle, + unsigned dst_x, unsigned dst_y, unsigned dst_z, + unsigned dst_level, unsigned dst_face, + unsigned width, unsigned height, unsigned depth) +{ + struct svga_surface dst, src; + enum pipe_error ret; + SVGA3dCopyBox box, *boxes; + + assert(svga); + + src.handle = src_handle; + src.real_level = src_level; + src.real_face = src_face; + src.real_zslice = 0; + + dst.handle = dst_handle; + dst.real_level = dst_level; + dst.real_face = dst_face; + dst.real_zslice = 0; + + box.x = dst_x; + box.y = dst_y; + box.z = dst_z; + box.w = width; + box.h = height; + box.d = depth; + box.srcx = src_x; + box.srcy = src_y; + box.srcz = src_z; + +/* + SVGA_DBG(DEBUG_VIEWS, "mipcopy src: %p %u (%ux%ux%u), dst: %p %u (%ux%ux%u)\n", + src_handle, src_level, src_x, src_y, src_z, + dst_handle, dst_level, dst_x, dst_y, dst_z); +*/ + + ret = SVGA3D_BeginSurfaceCopy(svga->swc, + &src.base, + &dst.base, + &boxes, 1); + if(ret != PIPE_OK) { + svga_context_flush(svga, NULL); + ret = SVGA3D_BeginSurfaceCopy(svga->swc, + &src.base, + &dst.base, + &boxes, 1); + assert(ret == PIPE_OK); + } + *boxes = box; + SVGA_FIFOCommitAll(svga->swc); +} + + +struct svga_winsys_surface * +svga_texture_view_surface(struct pipe_context *pipe, + struct svga_texture *tex, + SVGA3dSurfaceFormat format, + unsigned start_mip, + unsigned num_mip, + int face_pick, + int zslice_pick, + struct svga_host_surface_cache_key *key) /* OUT */ +{ + struct svga_screen *ss = svga_screen(pipe->screen); + struct svga_winsys_surface *handle; + uint32_t i, j; + unsigned z_offset = 0; + + SVGA_DBG(DEBUG_PERF, + "svga: Create surface view: face %d zslice %d mips %d..%d\n", + face_pick, zslice_pick, start_mip, start_mip+num_mip-1); + + key->flags = 0; + key->format = format; + key->numMipLevels = num_mip; + key->size.width = u_minify(tex->b.b.width0, start_mip); + key->size.height = u_minify(tex->b.b.height0, start_mip); + key->size.depth = zslice_pick < 0 ? u_minify(tex->b.b.depth0, start_mip) : 1; + key->cachable = 1; + assert(key->size.depth == 1); + + if(tex->b.b.target == PIPE_TEXTURE_CUBE && face_pick < 0) { + key->flags |= SVGA3D_SURFACE_CUBEMAP; + key->numFaces = 6; + } else { + key->numFaces = 1; + } + + if(key->format == SVGA3D_FORMAT_INVALID) { + key->cachable = 0; + return NULL; + } + + SVGA_DBG(DEBUG_DMA, "surface_create for texture view\n"); + handle = svga_screen_surface_create(ss, key); + if (!handle) { + key->cachable = 0; + return NULL; + } + + SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture view)\n", handle); + + if (face_pick < 0) + face_pick = 0; + + if (zslice_pick >= 0) + z_offset = zslice_pick; + + for (i = 0; i < key->numMipLevels; i++) { + for (j = 0; j < key->numFaces; j++) { + if(tex->defined[j + face_pick][i + start_mip]) { + unsigned depth = (zslice_pick < 0 ? + u_minify(tex->b.b.depth0, i + start_mip) : + 1); + + svga_texture_copy_handle(svga_context(pipe), + tex->handle, + 0, 0, z_offset, + i + start_mip, + j + face_pick, + handle, 0, 0, 0, i, j, + u_minify(tex->b.b.width0, i + start_mip), + u_minify(tex->b.b.height0, i + start_mip), + depth); + } + } + } + + return handle; +} + + +static struct pipe_surface * +svga_create_surface(struct pipe_context *pipe, + struct pipe_resource *pt, + const struct pipe_surface *surf_tmpl) +{ + struct svga_texture *tex = svga_texture(pt); + struct pipe_screen *screen = pipe->screen; + struct svga_surface *s; + unsigned face, zslice; + /* XXX surfaces should only be used for rendering purposes nowadays */ + boolean render = (surf_tmpl->usage & (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DEPTH_STENCIL)) ? TRUE : FALSE; + boolean view = FALSE; + SVGA3dSurfaceFormat format; + + assert(surf_tmpl->u.tex.first_layer == surf_tmpl->u.tex.last_layer); + + s = CALLOC_STRUCT(svga_surface); + if (!s) + return NULL; + + if (pt->target == PIPE_TEXTURE_CUBE) { + face = surf_tmpl->u.tex.first_layer; + zslice = 0; + } + else { + face = 0; + zslice = surf_tmpl->u.tex.first_layer; + } + + pipe_reference_init(&s->base.reference, 1); + pipe_resource_reference(&s->base.texture, pt); + s->base.context = pipe; + s->base.format = surf_tmpl->format; + s->base.width = u_minify(pt->width0, surf_tmpl->u.tex.level); + s->base.height = u_minify(pt->height0, surf_tmpl->u.tex.level); + s->base.usage = surf_tmpl->usage; + s->base.u.tex.level = surf_tmpl->u.tex.level; + s->base.u.tex.first_layer = surf_tmpl->u.tex.first_layer; + s->base.u.tex.last_layer = surf_tmpl->u.tex.last_layer; + + if (!render) + format = svga_translate_format(surf_tmpl->format); + else + format = svga_translate_format_render(surf_tmpl->format); + + assert(format != SVGA3D_FORMAT_INVALID); + + if (svga_screen(screen)->debug.force_surface_view) + view = TRUE; + + /* Currently only used for compressed textures */ + if (render && + format != svga_translate_format(surf_tmpl->format)) { + view = TRUE; + } + + if (surf_tmpl->u.tex.level != 0 && + svga_screen(screen)->debug.force_level_surface_view) + view = TRUE; + + if (pt->target == PIPE_TEXTURE_3D) + view = TRUE; + + if (svga_screen(screen)->debug.no_surface_view) + view = FALSE; + + if (view) { + SVGA_DBG(DEBUG_VIEWS, "svga: Surface view: yes %p, level %u face %u z %u, %p\n", + pt, surf_tmpl->u.tex.level, face, zslice, s); + + s->handle = svga_texture_view_surface(NULL, tex, format, surf_tmpl->u.tex.level, + 1, face, zslice, &s->key); + s->real_face = 0; + s->real_level = 0; + s->real_zslice = 0; + } else { + SVGA_DBG(DEBUG_VIEWS, "svga: Surface view: no %p, level %u, face %u, z %u, %p\n", + pt, surf_tmpl->u.tex.level, face, zslice, s); + + memset(&s->key, 0, sizeof s->key); + s->handle = tex->handle; + s->real_face = face; + s->real_zslice = zslice; + s->real_level = surf_tmpl->u.tex.level; + } + + return &s->base; +} + + +static void +svga_surface_destroy(struct pipe_context *pipe, + struct pipe_surface *surf) +{ + struct svga_surface *s = svga_surface(surf); + struct svga_texture *t = svga_texture(surf->texture); + struct svga_screen *ss = svga_screen(surf->texture->screen); + + if(s->handle != t->handle) { + SVGA_DBG(DEBUG_DMA, "unref sid %p (tex surface)\n", s->handle); + svga_screen_surface_destroy(ss, &s->key, &s->handle); + } + + pipe_resource_reference(&surf->texture, NULL); + FREE(surf); +} + + +static INLINE void +svga_mark_surface_dirty(struct pipe_surface *surf) +{ + struct svga_surface *s = svga_surface(surf); + + if(!s->dirty) { + struct svga_texture *tex = svga_texture(surf->texture); + + s->dirty = TRUE; + + if (s->handle == tex->handle) { + /* hmm so 3d textures always have all their slices marked ? */ + if (surf->texture->target == PIPE_TEXTURE_CUBE) + tex->defined[surf->u.tex.first_layer][surf->u.tex.level] = TRUE; + else + tex->defined[0][surf->u.tex.level] = TRUE; + } + else { + /* this will happen later in svga_propagate_surface */ + } + } +} + + +void svga_mark_surfaces_dirty(struct svga_context *svga) +{ + unsigned i; + + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + if (svga->curr.framebuffer.cbufs[i]) + svga_mark_surface_dirty(svga->curr.framebuffer.cbufs[i]); + } + if (svga->curr.framebuffer.zsbuf) + svga_mark_surface_dirty(svga->curr.framebuffer.zsbuf); +} + + +/** + * Progagate any changes from surfaces to texture. + * pipe is optional context to inline the blit command in. + */ +void +svga_propagate_surface(struct pipe_context *pipe, struct pipe_surface *surf) +{ + struct svga_surface *s = svga_surface(surf); + struct svga_texture *tex = svga_texture(surf->texture); + struct svga_screen *ss = svga_screen(surf->texture->screen); + unsigned zslice, face; + + if (!s->dirty) + return; + + if (surf->texture->target == PIPE_TEXTURE_CUBE) { + zslice = 0; + face = surf->u.tex.first_layer; + } + else { + zslice = surf->u.tex.first_layer; + face = 0; + } + + s->dirty = FALSE; + ss->texture_timestamp++; + tex->view_age[surf->u.tex.level] = ++(tex->age); + + if (s->handle != tex->handle) { + SVGA_DBG(DEBUG_VIEWS, "svga: Surface propagate: tex %p, level %u, from %p\n", tex, surf->u.tex.level, surf); + svga_texture_copy_handle(svga_context(pipe), + s->handle, 0, 0, 0, s->real_level, s->real_face, + tex->handle, 0, 0, zslice, surf->u.tex.level, face, + u_minify(tex->b.b.width0, surf->u.tex.level), + u_minify(tex->b.b.height0, surf->u.tex.level), 1); + tex->defined[face][surf->u.tex.level] = TRUE; + } +} + +/** + * Check if we should call svga_propagate_surface on the surface. + */ +boolean +svga_surface_needs_propagation(struct pipe_surface *surf) +{ + struct svga_surface *s = svga_surface(surf); + struct svga_texture *tex = svga_texture(surf->texture); + + return s->dirty && s->handle != tex->handle; +} + + + + + + +void +svga_init_surface_functions(struct svga_context *svga) +{ + svga->pipe.create_surface = svga_create_surface; + svga->pipe.surface_destroy = svga_surface_destroy; +} + diff --git a/src/gallium/drivers/svga/svga_surface.h b/src/gallium/drivers/svga/svga_surface.h new file mode 100644 index 0000000..afb8326 --- /dev/null +++ b/src/gallium/drivers/svga/svga_surface.h @@ -0,0 +1,93 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_SURFACE_H +#define SVGA_SURFACE_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "svga_screen_cache.h" + +struct pipe_context; +struct pipe_screen; +struct svga_context; +struct svga_texture; +struct svga_winsys_surface; +enum SVGA3dSurfaceFormat; + + +struct svga_surface +{ + struct pipe_surface base; + + struct svga_host_surface_cache_key key; + struct svga_winsys_surface *handle; + + unsigned real_face; + unsigned real_level; + unsigned real_zslice; + + boolean dirty; +}; + + +extern void +svga_propagate_surface(struct pipe_context *pipe, struct pipe_surface *surf); + +extern boolean +svga_surface_needs_propagation(struct pipe_surface *surf); + +struct svga_winsys_surface * +svga_texture_view_surface(struct pipe_context *pipe, + struct svga_texture *tex, + SVGA3dSurfaceFormat format, + unsigned start_mip, + unsigned num_mip, + int face_pick, + int zslice_pick, + struct svga_host_surface_cache_key *key); /* OUT */ + + +void +svga_texture_copy_handle(struct svga_context *svga, + struct svga_winsys_surface *src_handle, + unsigned src_x, unsigned src_y, unsigned src_z, + unsigned src_level, unsigned src_face, + struct svga_winsys_surface *dst_handle, + unsigned dst_x, unsigned dst_y, unsigned dst_z, + unsigned dst_level, unsigned dst_face, + unsigned width, unsigned height, unsigned depth); + + +static INLINE struct svga_surface * +svga_surface(struct pipe_surface *surface) +{ + assert(surface); + return (struct svga_surface *)surface; +} + +#endif diff --git a/src/gallium/drivers/svga/svga_swtnl.h b/src/gallium/drivers/svga/svga_swtnl.h new file mode 100644 index 0000000..fc094e5 --- /dev/null +++ b/src/gallium/drivers/svga/svga_swtnl.h @@ -0,0 +1,45 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_SWTNL_H +#define SVGA_SWTNL_H + +#include "pipe/p_compiler.h" + +struct svga_context; +struct pipe_context; +struct vbuf_render; + + +boolean svga_init_swtnl( struct svga_context *svga ); +void svga_destroy_swtnl( struct svga_context *svga ); + + +enum pipe_error +svga_swtnl_draw_vbo(struct svga_context *svga, + const struct pipe_draw_info *info); + + +#endif diff --git a/src/gallium/drivers/svga/svga_swtnl_backend.c b/src/gallium/drivers/svga/svga_swtnl_backend.c new file mode 100644 index 0000000..ff3da84 --- /dev/null +++ b/src/gallium/drivers/svga/svga_swtnl_backend.c @@ -0,0 +1,350 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "draw/draw_vbuf.h" +#include "draw/draw_context.h" +#include "draw/draw_vertex.h" + +#include "util/u_debug.h" +#include "util/u_inlines.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "svga_context.h" +#include "svga_state.h" +#include "svga_swtnl.h" + +#include "svga_types.h" +#include "svga_reg.h" +#include "svga3d_reg.h" +#include "svga_draw.h" +#include "svga_swtnl_private.h" + + +static const struct vertex_info * +svga_vbuf_render_get_vertex_info( struct vbuf_render *render ) +{ + struct svga_vbuf_render *svga_render = svga_vbuf_render(render); + struct svga_context *svga = svga_render->svga; + + svga_swtnl_update_vdecl(svga); + + return &svga_render->vertex_info; +} + + +static boolean +svga_vbuf_render_allocate_vertices( struct vbuf_render *render, + ushort vertex_size, + ushort nr_vertices ) +{ + struct svga_vbuf_render *svga_render = svga_vbuf_render(render); + struct svga_context *svga = svga_render->svga; + struct pipe_screen *screen = svga->pipe.screen; + size_t size = (size_t)nr_vertices * (size_t)vertex_size; + boolean new_vbuf = FALSE; + boolean new_ibuf = FALSE; + + if (svga_render->vertex_size != vertex_size) + svga->swtnl.new_vdecl = TRUE; + svga_render->vertex_size = (size_t)vertex_size; + + if (svga->swtnl.new_vbuf) + new_ibuf = new_vbuf = TRUE; + svga->swtnl.new_vbuf = FALSE; + + if (svga_render->vbuf_size < svga_render->vbuf_offset + svga_render->vbuf_used + size) + new_vbuf = TRUE; + + if (new_vbuf) + pipe_resource_reference(&svga_render->vbuf, NULL); + if (new_ibuf) + pipe_resource_reference(&svga_render->ibuf, NULL); + + if (!svga_render->vbuf) { + svga_render->vbuf_size = MAX2(size, svga_render->vbuf_alloc_size); + svga_render->vbuf = pipe_buffer_create(screen, + PIPE_BIND_VERTEX_BUFFER, + svga_render->vbuf_size); + if(!svga_render->vbuf) { + svga_context_flush(svga, NULL); + svga_render->vbuf = pipe_buffer_create(screen, + PIPE_BIND_VERTEX_BUFFER, + svga_render->vbuf_size); + assert(svga_render->vbuf); + } + + svga->swtnl.new_vdecl = TRUE; + svga_render->vbuf_offset = 0; + } else { + svga_render->vbuf_offset += svga_render->vbuf_used; + } + + svga_render->vbuf_used = 0; + + if (svga->swtnl.new_vdecl) + svga_render->vdecl_offset = svga_render->vbuf_offset; + + return TRUE; +} + +static void * +svga_vbuf_render_map_vertices( struct vbuf_render *render ) +{ + struct svga_vbuf_render *svga_render = svga_vbuf_render(render); + struct svga_context *svga = svga_render->svga; + + char *ptr = (char*)pipe_buffer_map(&svga->pipe, + svga_render->vbuf, + PIPE_TRANSFER_WRITE | + PIPE_TRANSFER_FLUSH_EXPLICIT | + PIPE_TRANSFER_DISCARD | + PIPE_TRANSFER_UNSYNCHRONIZED, + &svga_render->vbuf_transfer); + return ptr + svga_render->vbuf_offset; +} + +static void +svga_vbuf_render_unmap_vertices( struct vbuf_render *render, + ushort min_index, + ushort max_index ) +{ + struct svga_vbuf_render *svga_render = svga_vbuf_render(render); + struct svga_context *svga = svga_render->svga; + unsigned offset, length; + size_t used = svga_render->vertex_size * ((size_t)max_index + 1); + + offset = svga_render->vbuf_offset + svga_render->vertex_size * min_index; + length = svga_render->vertex_size * (max_index + 1 - min_index); + pipe_buffer_flush_mapped_range(&svga->pipe, + svga_render->vbuf_transfer, + offset, length); + pipe_buffer_unmap(&svga->pipe, svga_render->vbuf, svga_render->vbuf_transfer); + svga_render->min_index = min_index; + svga_render->max_index = max_index; + svga_render->vbuf_used = MAX2(svga_render->vbuf_used, used); +} + +static boolean +svga_vbuf_render_set_primitive( struct vbuf_render *render, + unsigned prim ) +{ + struct svga_vbuf_render *svga_render = svga_vbuf_render(render); + svga_render->prim = prim; + + return TRUE; +} + +static void +svga_vbuf_sumbit_state( struct svga_vbuf_render *svga_render ) +{ + struct svga_context *svga = svga_render->svga; + SVGA3dVertexDecl vdecl[PIPE_MAX_ATTRIBS]; + enum pipe_error ret; + int i; + + /* if the vdecl or vbuf hasn't changed do nothing */ + if (!svga->swtnl.new_vdecl) + return; + + memcpy(vdecl, svga_render->vdecl, sizeof(vdecl)); + + /* flush the hw state */ + ret = svga_hwtnl_flush(svga->hwtnl); + if (ret) { + svga_context_flush(svga, NULL); + ret = svga_hwtnl_flush(svga->hwtnl); + /* if we hit this path we might become synced with hw */ + svga->swtnl.new_vbuf = TRUE; + assert(ret == 0); + } + + svga_hwtnl_reset_vdecl(svga->hwtnl, svga_render->vdecl_count); + + for (i = 0; i < svga_render->vdecl_count; i++) { + vdecl[i].array.offset += svga_render->vdecl_offset; + + svga_hwtnl_vdecl( svga->hwtnl, + i, + &vdecl[i], + svga_render->vbuf ); + } + + /* We have already taken care of flatshading, so let the hwtnl + * module use whatever is most convenient: + */ + if (svga->state.sw.need_pipeline) { + svga_hwtnl_set_flatshade(svga->hwtnl, FALSE, FALSE); + svga_hwtnl_set_unfilled(svga->hwtnl, PIPE_POLYGON_MODE_FILL); + } + else { + svga_hwtnl_set_flatshade( svga->hwtnl, + svga->curr.rast->templ.flatshade, + svga->curr.rast->templ.flatshade_first ); + + svga_hwtnl_set_unfilled( svga->hwtnl, + svga->curr.rast->hw_unfilled ); + } + + svga->swtnl.new_vdecl = FALSE; +} + +static void +svga_vbuf_render_draw_arrays( struct vbuf_render *render, + unsigned start, + uint nr ) +{ + struct svga_vbuf_render *svga_render = svga_vbuf_render(render); + struct svga_context *svga = svga_render->svga; + unsigned bias = (svga_render->vbuf_offset - svga_render->vdecl_offset) / svga_render->vertex_size; + enum pipe_error ret = 0; + + svga_vbuf_sumbit_state(svga_render); + + /* Need to call update_state() again as the draw module may have + * altered some of our state behind our backs. Testcase: + * redbook/polys.c + */ + svga_update_state_retry( svga, SVGA_STATE_HW_DRAW ); + + ret = svga_hwtnl_draw_arrays(svga->hwtnl, svga_render->prim, start + bias, nr); + if (ret != PIPE_OK) { + svga_context_flush(svga, NULL); + ret = svga_hwtnl_draw_arrays(svga->hwtnl, svga_render->prim, start + bias, nr); + svga->swtnl.new_vbuf = TRUE; + assert(ret == PIPE_OK); + } +} + + +static void +svga_vbuf_render_draw_elements( struct vbuf_render *render, + const ushort *indices, + uint nr_indices) +{ + struct svga_vbuf_render *svga_render = svga_vbuf_render(render); + struct svga_context *svga = svga_render->svga; + struct pipe_screen *screen = svga->pipe.screen; + int bias = (svga_render->vbuf_offset - svga_render->vdecl_offset) / svga_render->vertex_size; + boolean ret; + size_t size = 2 * nr_indices; + + assert(( svga_render->vbuf_offset - svga_render->vdecl_offset) % svga_render->vertex_size == 0); + + if (svga_render->ibuf_size < svga_render->ibuf_offset + size) + pipe_resource_reference(&svga_render->ibuf, NULL); + + if (!svga_render->ibuf) { + svga_render->ibuf_size = MAX2(size, svga_render->ibuf_alloc_size); + svga_render->ibuf = pipe_buffer_create(screen, + PIPE_BIND_INDEX_BUFFER, + svga_render->ibuf_size); + svga_render->ibuf_offset = 0; + } + + pipe_buffer_write_nooverlap(&svga->pipe, svga_render->ibuf, + svga_render->ibuf_offset, 2 * nr_indices, indices); + + + /* off to hardware */ + svga_vbuf_sumbit_state(svga_render); + + /* Need to call update_state() again as the draw module may have + * altered some of our state behind our backs. Testcase: + * redbook/polys.c + */ + svga_update_state_retry( svga, SVGA_STATE_HW_DRAW ); + + ret = svga_hwtnl_draw_range_elements(svga->hwtnl, + svga_render->ibuf, + 2, + bias, + svga_render->min_index, + svga_render->max_index, + svga_render->prim, + svga_render->ibuf_offset / 2, nr_indices); + if(ret != PIPE_OK) { + svga_context_flush(svga, NULL); + ret = svga_hwtnl_draw_range_elements(svga->hwtnl, + svga_render->ibuf, + 2, + bias, + svga_render->min_index, + svga_render->max_index, + svga_render->prim, + svga_render->ibuf_offset / 2, nr_indices); + svga->swtnl.new_vbuf = TRUE; + assert(ret == PIPE_OK); + } + + svga_render->ibuf_offset += size; +} + + +static void +svga_vbuf_render_release_vertices( struct vbuf_render *render ) +{ + +} + + +static void +svga_vbuf_render_destroy( struct vbuf_render *render ) +{ + struct svga_vbuf_render *svga_render = svga_vbuf_render(render); + + pipe_resource_reference(&svga_render->vbuf, NULL); + pipe_resource_reference(&svga_render->ibuf, NULL); + FREE(svga_render); +} + + +/** + * Create a new primitive render. + */ +struct vbuf_render * +svga_vbuf_render_create( struct svga_context *svga ) +{ + struct svga_vbuf_render *svga_render = CALLOC_STRUCT(svga_vbuf_render); + + svga_render->svga = svga; + svga_render->ibuf_size = 0; + svga_render->vbuf_size = 0; + svga_render->ibuf_alloc_size = 4*1024; + svga_render->vbuf_alloc_size = 64*1024; + svga_render->base.max_vertex_buffer_bytes = 64*1024/10; + svga_render->base.max_indices = 65536; + svga_render->base.get_vertex_info = svga_vbuf_render_get_vertex_info; + svga_render->base.allocate_vertices = svga_vbuf_render_allocate_vertices; + svga_render->base.map_vertices = svga_vbuf_render_map_vertices; + svga_render->base.unmap_vertices = svga_vbuf_render_unmap_vertices; + svga_render->base.set_primitive = svga_vbuf_render_set_primitive; + svga_render->base.draw_elements = svga_vbuf_render_draw_elements; + svga_render->base.draw_arrays = svga_vbuf_render_draw_arrays; + svga_render->base.release_vertices = svga_vbuf_render_release_vertices; + svga_render->base.destroy = svga_vbuf_render_destroy; + + return &svga_render->base; +} diff --git a/src/gallium/drivers/svga/svga_swtnl_draw.c b/src/gallium/drivers/svga/svga_swtnl_draw.c new file mode 100644 index 0000000..814e8ed --- /dev/null +++ b/src/gallium/drivers/svga/svga_swtnl_draw.c @@ -0,0 +1,173 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "draw/draw_context.h" +#include "draw/draw_vbuf.h" +#include "util/u_inlines.h" +#include "pipe/p_state.h" + +#include "svga_context.h" +#include "svga_swtnl.h" +#include "svga_state.h" +#include "svga_swtnl_private.h" + + + +enum pipe_error +svga_swtnl_draw_vbo(struct svga_context *svga, + const struct pipe_draw_info *info) +{ + struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS]; + struct pipe_transfer *ib_transfer = NULL; + struct pipe_transfer *cb_transfer = NULL; + struct draw_context *draw = svga->swtnl.draw; + unsigned i; + const void *map; + enum pipe_error ret; + + assert(!svga->dirty); + assert(svga->state.sw.need_swtnl); + assert(draw); + + ret = svga_update_state(svga, SVGA_STATE_SWTNL_DRAW); + if (ret) { + svga_context_flush(svga, NULL); + ret = svga_update_state(svga, SVGA_STATE_SWTNL_DRAW); + svga->swtnl.new_vbuf = TRUE; + assert(ret == PIPE_OK); + } + + /* + * Map vertex buffers + */ + for (i = 0; i < svga->curr.num_vertex_buffers; i++) { + map = pipe_buffer_map(&svga->pipe, + svga->curr.vb[i].buffer, + PIPE_TRANSFER_READ, + &vb_transfer[i]); + + draw_set_mapped_vertex_buffer(draw, i, map); + } + + /* TODO move this to update_swtnl_draw */ + draw_set_index_buffer(draw, &svga->curr.ib); + + /* Map index buffer, if present */ + map = NULL; + if (info->indexed && svga->curr.ib.buffer) { + map = pipe_buffer_map(&svga->pipe, svga->curr.ib.buffer, + PIPE_TRANSFER_READ, + &ib_transfer); + } + draw_set_mapped_index_buffer(draw, map); + + if (svga->curr.cb[PIPE_SHADER_VERTEX]) { + map = pipe_buffer_map(&svga->pipe, + svga->curr.cb[PIPE_SHADER_VERTEX], + PIPE_TRANSFER_READ, + &cb_transfer); + assert(map); + draw_set_mapped_constant_buffer( + draw, PIPE_SHADER_VERTEX, 0, + map, + svga->curr.cb[PIPE_SHADER_VERTEX]->width0); + } + + draw_vbo(draw, info); + + draw_flush(svga->swtnl.draw); + + /* Ensure the draw module didn't touch this */ + assert(i == svga->curr.num_vertex_buffers); + + /* + * unmap vertex/index buffers + */ + for (i = 0; i < svga->curr.num_vertex_buffers; i++) { + pipe_buffer_unmap(&svga->pipe, svga->curr.vb[i].buffer, + vb_transfer[i]); + draw_set_mapped_vertex_buffer(draw, i, NULL); + } + + if (ib_transfer) { + pipe_buffer_unmap(&svga->pipe, svga->curr.ib.buffer, ib_transfer); + draw_set_mapped_index_buffer(draw, NULL); + } + + if (svga->curr.cb[PIPE_SHADER_VERTEX]) { + pipe_buffer_unmap(&svga->pipe, + svga->curr.cb[PIPE_SHADER_VERTEX], + cb_transfer); + } + + return ret; +} + + + + +boolean svga_init_swtnl( struct svga_context *svga ) +{ + svga->swtnl.backend = svga_vbuf_render_create(svga); + if(!svga->swtnl.backend) + goto fail; + + /* + * Create drawing context and plug our rendering stage into it. + */ + svga->swtnl.draw = draw_create(&svga->pipe); + if (svga->swtnl.draw == NULL) + goto fail; + + + draw_set_rasterize_stage(svga->swtnl.draw, + draw_vbuf_stage( svga->swtnl.draw, svga->swtnl.backend )); + + draw_set_render(svga->swtnl.draw, svga->swtnl.backend); + + draw_install_aaline_stage(svga->swtnl.draw, &svga->pipe); + draw_install_aapoint_stage(svga->swtnl.draw, &svga->pipe); + draw_install_pstipple_stage(svga->swtnl.draw, &svga->pipe); + + if (debug_get_bool_option("SVGA_SWTNL_FSE", FALSE)) + draw_set_driver_clipping(svga->swtnl.draw, TRUE, TRUE); + + return TRUE; + +fail: + if (svga->swtnl.backend) + svga->swtnl.backend->destroy( svga->swtnl.backend ); + + if (svga->swtnl.draw) + draw_destroy( svga->swtnl.draw ); + + return FALSE; +} + + +void svga_destroy_swtnl( struct svga_context *svga ) +{ + draw_destroy( svga->swtnl.draw ); +} diff --git a/src/gallium/drivers/svga/svga_swtnl_private.h b/src/gallium/drivers/svga/svga_swtnl_private.h new file mode 100644 index 0000000..8d08070 --- /dev/null +++ b/src/gallium/drivers/svga/svga_swtnl_private.h @@ -0,0 +1,95 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_SWTNL_PRIVATE_H +#define SVGA_SWTNL_PRIVATE_H + +#include "svga_swtnl.h" +#include "draw/draw_vertex.h" + +#include "svga_types.h" +#include "svga3d_reg.h" + +/** + * Primitive renderer for svga. + */ +struct svga_vbuf_render { + struct vbuf_render base; + + struct svga_context *svga; + struct vertex_info vertex_info; + + unsigned vertex_size; + + unsigned prim; + + struct pipe_resource *vbuf; + struct pipe_resource *ibuf; + struct pipe_transfer *vbuf_transfer; + struct pipe_transfer *ibuf_transfer; + + /* current size of buffer */ + size_t vbuf_size; + size_t ibuf_size; + + /* size of that the buffer should be */ + size_t vbuf_alloc_size; + size_t ibuf_alloc_size; + + /* current write place */ + size_t vbuf_offset; + size_t ibuf_offset; + + /* currently used */ + size_t vbuf_used; + + SVGA3dVertexDecl vdecl[PIPE_MAX_ATTRIBS]; + unsigned vdecl_offset; + unsigned vdecl_count; + + ushort min_index; + ushort max_index; +}; + +/** + * Basically a cast wrapper. + */ +static INLINE struct svga_vbuf_render * +svga_vbuf_render( struct vbuf_render *render ) +{ + assert(render); + return (struct svga_vbuf_render *)render; +} + + +struct vbuf_render * +svga_vbuf_render_create( struct svga_context *svga ); + + +int +svga_swtnl_update_vdecl( struct svga_context *svga ); + + +#endif diff --git a/src/gallium/drivers/svga/svga_swtnl_state.c b/src/gallium/drivers/svga/svga_swtnl_state.c new file mode 100644 index 0000000..a759238 --- /dev/null +++ b/src/gallium/drivers/svga/svga_swtnl_state.c @@ -0,0 +1,237 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#include "draw/draw_context.h" +#include "draw/draw_vbuf.h" +#include "util/u_inlines.h" +#include "pipe/p_state.h" + +#include "svga_context.h" +#include "svga_swtnl.h" +#include "svga_state.h" + +#include "svga_swtnl_private.h" + + +#define SVGA_POINT_ADJ_X -0.375 +#define SVGA_POINT_ADJ_Y -0.5 + +#define SVGA_LINE_ADJ_X -0.5 +#define SVGA_LINE_ADJ_Y -0.5 + +#define SVGA_TRIANGLE_ADJ_X -0.375 +#define SVGA_TRIANGLE_ADJ_Y -0.5 + + +static void set_draw_viewport( struct svga_context *svga ) +{ + struct pipe_viewport_state vp = svga->curr.viewport; + float adjx = 0; + float adjy = 0; + + switch (svga->curr.reduced_prim) { + case PIPE_PRIM_POINTS: + adjx = SVGA_POINT_ADJ_X; + adjy = SVGA_POINT_ADJ_Y; + break; + case PIPE_PRIM_LINES: + /* XXX: This is to compensate for the fact that wide lines are + * going to be drawn with triangles, but we're not catching all + * cases where that will happen. + */ + if (svga->curr.rast->templ.line_width > 1.0) + { + adjx = SVGA_LINE_ADJ_X + 0.175; + adjy = SVGA_LINE_ADJ_Y - 0.175; + } + else { + adjx = SVGA_LINE_ADJ_X; + adjy = SVGA_LINE_ADJ_Y; + } + break; + case PIPE_PRIM_TRIANGLES: + adjx += SVGA_TRIANGLE_ADJ_X; + adjy += SVGA_TRIANGLE_ADJ_Y; + break; + } + + vp.translate[0] += adjx; + vp.translate[1] += adjy; + + draw_set_viewport_state(svga->swtnl.draw, &vp); +} + +static int update_swtnl_draw( struct svga_context *svga, + unsigned dirty ) +{ + draw_flush( svga->swtnl.draw ); + + if (dirty & SVGA_NEW_VS) + draw_bind_vertex_shader(svga->swtnl.draw, + svga->curr.vs->draw_shader); + + if (dirty & SVGA_NEW_VBUFFER) + draw_set_vertex_buffers(svga->swtnl.draw, + svga->curr.num_vertex_buffers, + svga->curr.vb); + + if (dirty & SVGA_NEW_VELEMENT) + draw_set_vertex_elements(svga->swtnl.draw, + svga->curr.velems->count, + svga->curr.velems->velem ); + + if (dirty & SVGA_NEW_CLIP) + draw_set_clip_state(svga->swtnl.draw, + &svga->curr.clip); + + if (dirty & (SVGA_NEW_VIEWPORT | + SVGA_NEW_REDUCED_PRIMITIVE | + SVGA_NEW_RAST)) + set_draw_viewport( svga ); + + if (dirty & SVGA_NEW_RAST) + draw_set_rasterizer_state(svga->swtnl.draw, + &svga->curr.rast->templ, + (void *) svga->curr.rast); + + if (dirty & SVGA_NEW_FRAME_BUFFER) + draw_set_mrd(svga->swtnl.draw, + svga->curr.depthscale); + + return 0; +} + + +struct svga_tracked_state svga_update_swtnl_draw = +{ + "update draw module state", + (SVGA_NEW_VS | + SVGA_NEW_VBUFFER | + SVGA_NEW_VELEMENT | + SVGA_NEW_CLIP | + SVGA_NEW_VIEWPORT | + SVGA_NEW_RAST | + SVGA_NEW_FRAME_BUFFER | + SVGA_NEW_REDUCED_PRIMITIVE), + update_swtnl_draw +}; + + +int svga_swtnl_update_vdecl( struct svga_context *svga ) +{ + struct svga_vbuf_render *svga_render = svga_vbuf_render(svga->swtnl.backend); + struct draw_context *draw = svga->swtnl.draw; + struct vertex_info *vinfo = &svga_render->vertex_info; + SVGA3dVertexDecl vdecl[PIPE_MAX_ATTRIBS]; + const enum interp_mode colorInterp = + svga->curr.rast->templ.flatshade ? INTERP_CONSTANT : INTERP_LINEAR; + const struct svga_fragment_shader *fs = svga->curr.fs; + int offset = 0; + int nr_decls = 0; + int src, i; + + memset(vinfo, 0, sizeof(*vinfo)); + memset(vdecl, 0, sizeof(vdecl)); + + /* always add position */ + src = draw_find_shader_output(draw, TGSI_SEMANTIC_POSITION, 0); + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_LINEAR, src); + vinfo->attrib[0].emit = EMIT_4F; + vdecl[0].array.offset = offset; + vdecl[0].identity.type = SVGA3D_DECLTYPE_FLOAT4; + vdecl[0].identity.usage = SVGA3D_DECLUSAGE_POSITIONT; + vdecl[0].identity.usageIndex = 0; + offset += 16; + nr_decls++; + + for (i = 0; i < fs->base.info.num_inputs; i++) { + unsigned name = fs->base.info.input_semantic_name[i]; + unsigned index = fs->base.info.input_semantic_index[i]; + src = draw_find_shader_output(draw, name, index); + vdecl[nr_decls].array.offset = offset; + vdecl[nr_decls].identity.usageIndex = fs->base.info.input_semantic_index[i]; + + switch (name) { + case TGSI_SEMANTIC_COLOR: + draw_emit_vertex_attr(vinfo, EMIT_4F, colorInterp, src); + vdecl[nr_decls].identity.usage = SVGA3D_DECLUSAGE_COLOR; + vdecl[nr_decls].identity.type = SVGA3D_DECLTYPE_FLOAT4; + offset += 16; + nr_decls++; + break; + case TGSI_SEMANTIC_GENERIC: + draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src); + vdecl[nr_decls].identity.usage = SVGA3D_DECLUSAGE_TEXCOORD; + vdecl[nr_decls].identity.type = SVGA3D_DECLTYPE_FLOAT4; + vdecl[nr_decls].identity.usageIndex += 1; + offset += 16; + nr_decls++; + break; + case TGSI_SEMANTIC_FOG: + draw_emit_vertex_attr(vinfo, EMIT_1F, INTERP_PERSPECTIVE, src); + vdecl[nr_decls].identity.usage = SVGA3D_DECLUSAGE_TEXCOORD; + vdecl[nr_decls].identity.type = SVGA3D_DECLTYPE_FLOAT1; + assert(vdecl[nr_decls].identity.usageIndex == 0); + offset += 4; + nr_decls++; + break; + case TGSI_SEMANTIC_POSITION: + /* generated internally, not a vertex shader output */ + break; + default: + assert(0); + } + } + + draw_compute_vertex_size(vinfo); + + svga_render->vdecl_count = nr_decls; + for (i = 0; i < svga_render->vdecl_count; i++) + vdecl[i].array.stride = offset; + + if (memcmp(svga_render->vdecl, vdecl, sizeof(vdecl)) == 0) + return 0; + + memcpy(svga_render->vdecl, vdecl, sizeof(vdecl)); + svga->swtnl.new_vdecl = TRUE; + + return 0; +} + + +static int update_swtnl_vdecl( struct svga_context *svga, + unsigned dirty ) +{ + return svga_swtnl_update_vdecl( svga ); +} + + +struct svga_tracked_state svga_update_swtnl_vdecl = +{ + "update draw module vdecl", + (SVGA_NEW_VS | + SVGA_NEW_FS), + update_swtnl_vdecl +}; diff --git a/src/gallium/drivers/svga/svga_tgsi.c b/src/gallium/drivers/svga/svga_tgsi.c new file mode 100644 index 0000000..781fe63 --- /dev/null +++ b/src/gallium/drivers/svga/svga_tgsi.c @@ -0,0 +1,282 @@ +/********************************************************** + * 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. + * + **********************************************************/ + + +#include "pipe/p_compiler.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/p_defines.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_scan.h" +#include "util/u_memory.h" +#include "util/u_bitmask.h" + +#include "svgadump/svga_shader_dump.h" + +#include "svga_context.h" +#include "svga_tgsi.h" +#include "svga_tgsi_emit.h" +#include "svga_debug.h" + +#include "svga_hw_reg.h" +#include "svga3d_shaderdefs.h" + + +/* Sinkhole used only in error conditions. + */ +static char err_buf[128]; + +#if 0 +static void svga_destroy_shader_emitter( struct svga_shader_emitter *emit ) +{ + if (emit->buf != err_buf) + FREE(emit->buf); +} +#endif + + +static boolean svga_shader_expand( struct svga_shader_emitter *emit ) +{ + char *new_buf; + unsigned newsize = emit->size * 2; + + if(emit->buf != err_buf) + new_buf = REALLOC(emit->buf, emit->size, newsize); + else + new_buf = NULL; + + if (new_buf == NULL) { + emit->ptr = err_buf; + emit->buf = err_buf; + emit->size = sizeof(err_buf); + return FALSE; + } + + emit->size = newsize; + emit->ptr = new_buf + (emit->ptr - emit->buf); + emit->buf = new_buf; + return TRUE; +} + +static INLINE boolean reserve( struct svga_shader_emitter *emit, + unsigned nr_dwords ) +{ + if (emit->ptr - emit->buf + nr_dwords * sizeof(unsigned) >= emit->size) { + if (!svga_shader_expand( emit )) + return FALSE; + } + + return TRUE; +} + +boolean svga_shader_emit_dword( struct svga_shader_emitter *emit, + unsigned dword ) +{ + if (!reserve(emit, 1)) + return FALSE; + + *(unsigned *)emit->ptr = dword; + emit->ptr += sizeof dword; + return TRUE; +} + +boolean svga_shader_emit_dwords( struct svga_shader_emitter *emit, + const unsigned *dwords, + unsigned nr ) +{ + if (!reserve(emit, nr)) + return FALSE; + + memcpy( emit->ptr, dwords, nr * sizeof *dwords ); + emit->ptr += nr * sizeof *dwords; + return TRUE; +} + +boolean svga_shader_emit_opcode( struct svga_shader_emitter *emit, + unsigned opcode ) +{ + SVGA3dShaderInstToken *here; + + if (!reserve(emit, 1)) + return FALSE; + + here = (SVGA3dShaderInstToken *)emit->ptr; + here->value = opcode; + + if (emit->insn_offset) { + SVGA3dShaderInstToken *prev = (SVGA3dShaderInstToken *)(emit->buf + + emit->insn_offset); + prev->size = (here - prev) - 1; + } + + emit->insn_offset = emit->ptr - emit->buf; + emit->ptr += sizeof(unsigned); + return TRUE; +} + +#define SVGA3D_PS_2X (SVGA3D_PS_20 | 1) +#define SVGA3D_VS_2X (SVGA3D_VS_20 | 1) + +static boolean svga_shader_emit_header( struct svga_shader_emitter *emit ) +{ + SVGA3dShaderVersion header; + + memset( &header, 0, sizeof header ); + + switch (emit->unit) { + case PIPE_SHADER_FRAGMENT: + header.value = emit->use_sm30 ? SVGA3D_PS_30 : SVGA3D_PS_2X; + break; + case PIPE_SHADER_VERTEX: + header.value = emit->use_sm30 ? SVGA3D_VS_30 : SVGA3D_VS_2X; + break; + } + + return svga_shader_emit_dword( emit, header.value ); +} + + + + + +/* Parse TGSI shader and translate to SVGA/DX9 serialized + * representation. + * + * In this function SVGA shader is emitted to an in-memory buffer that + * can be dynamically grown. Once we've finished and know how large + * it is, it will be copied to a hardware buffer for upload. + */ +static struct svga_shader_result * +svga_tgsi_translate( const struct svga_shader *shader, + union svga_compile_key key, + unsigned unit ) +{ + struct svga_shader_result *result = NULL; + struct svga_shader_emitter emit; + int ret = 0; + + memset(&emit, 0, sizeof(emit)); + + emit.use_sm30 = shader->use_sm30; + emit.size = 1024; + emit.buf = MALLOC(emit.size); + if (emit.buf == NULL) { + ret = PIPE_ERROR_OUT_OF_MEMORY; + goto fail; + } + + emit.ptr = emit.buf; + emit.unit = unit; + emit.key = key; + + tgsi_scan_shader( shader->tokens, &emit.info); + + emit.imm_start = emit.info.file_max[TGSI_FILE_CONSTANT] + 1; + + if (unit == PIPE_SHADER_FRAGMENT) + emit.imm_start += key.fkey.num_unnormalized_coords; + + if (unit == PIPE_SHADER_VERTEX) { + emit.imm_start += key.vkey.need_prescale ? 2 : 0; + emit.imm_start += key.vkey.num_zero_stride_vertex_elements; + } + + emit.nr_hw_float_const = (emit.imm_start + emit.info.file_max[TGSI_FILE_IMMEDIATE] + 1); + + emit.nr_hw_temp = emit.info.file_max[TGSI_FILE_TEMPORARY] + 1; + emit.in_main_func = TRUE; + + if (!svga_shader_emit_header( &emit )) + goto fail; + + if (!svga_shader_emit_instructions( &emit, shader->tokens )) + goto fail; + + result = CALLOC_STRUCT(svga_shader_result); + if (result == NULL) + goto fail; + + result->shader = shader; + result->tokens = (const unsigned *)emit.buf; + result->nr_tokens = (emit.ptr - emit.buf) / sizeof(unsigned); + memcpy(&result->key, &key, sizeof key); + result->id = UTIL_BITMASK_INVALID_INDEX; + + if (SVGA_DEBUG & DEBUG_TGSI) + { + debug_printf( "#####################################\n" ); + debug_printf( "Shader %u below\n", shader->id ); + tgsi_dump( shader->tokens, 0 ); + if (SVGA_DEBUG & DEBUG_TGSI) { + debug_printf( "Shader %u compiled below\n", shader->id ); + svga_shader_dump( result->tokens, + result->nr_tokens , + FALSE ); + } + debug_printf( "#####################################\n" ); + } + + return result; + +fail: + FREE(result); + FREE(emit.buf); + return NULL; +} + + + + +struct svga_shader_result * +svga_translate_fragment_program( const struct svga_fragment_shader *fs, + const struct svga_fs_compile_key *fkey ) +{ + union svga_compile_key key; + memcpy(&key.fkey, fkey, sizeof *fkey); + + return svga_tgsi_translate( &fs->base, + key, + PIPE_SHADER_FRAGMENT ); +} + +struct svga_shader_result * +svga_translate_vertex_program( const struct svga_vertex_shader *vs, + const struct svga_vs_compile_key *vkey ) +{ + union svga_compile_key key; + memcpy(&key.vkey, vkey, sizeof *vkey); + + return svga_tgsi_translate( &vs->base, + key, + PIPE_SHADER_VERTEX ); +} + + +void svga_destroy_shader_result( struct svga_shader_result *result ) +{ + FREE((unsigned *)result->tokens); + FREE(result); +} + diff --git a/src/gallium/drivers/svga/svga_tgsi.h b/src/gallium/drivers/svga/svga_tgsi.h new file mode 100644 index 0000000..7ea909c --- /dev/null +++ b/src/gallium/drivers/svga/svga_tgsi.h @@ -0,0 +1,137 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_TGSI_H +#define SVGA_TGSI_H + +#include "pipe/p_state.h" + +#include "svga_hw_reg.h" + +struct svga_fragment_shader; +struct svga_vertex_shader; +struct svga_shader; +struct tgsi_shader_info; +struct tgsi_token; + + +struct svga_vs_compile_key +{ + unsigned zero_stride_vertex_elements; + unsigned need_prescale:1; + unsigned allow_psiz:1; + unsigned num_zero_stride_vertex_elements:6; +}; + +struct svga_fs_compile_key +{ + unsigned light_twoside:1; + unsigned front_ccw:1; + unsigned white_fragments:1; + unsigned num_textures:8; + unsigned num_unnormalized_coords:8; + struct { + unsigned compare_mode:1; + unsigned compare_func:3; + unsigned unnormalized:1; + unsigned width_height_idx:7; + unsigned texture_target:8; + } tex[PIPE_MAX_SAMPLERS]; +}; + +union svga_compile_key { + struct svga_vs_compile_key vkey; + struct svga_fs_compile_key fkey; +}; + +struct svga_shader_result +{ + const struct svga_shader *shader; + + /* Parameters used to generate this compilation result: + */ + union svga_compile_key key; + + /* Compiled shader tokens: + */ + const unsigned *tokens; + unsigned nr_tokens; + + /* SVGA Shader ID: + */ + unsigned id; + + /* Next compilation result: + */ + struct svga_shader_result *next; +}; + + +/* TGSI doesn't provide use with VS input semantics (they're actually + * pretty meaningless), so we just generate some plausible ones here. + * This is called both from within the TGSI translator and when + * building vdecls to ensure they match up. + * + * The real use of this information is matching vertex elements to + * fragment shader inputs in the case where vertex shader is disabled. + */ +static INLINE void svga_generate_vdecl_semantics( unsigned idx, + unsigned *usage, + unsigned *usage_index ) +{ + if (idx == 0) { + *usage = SVGA3D_DECLUSAGE_POSITION; + *usage_index = 0; + } + else { + *usage = SVGA3D_DECLUSAGE_TEXCOORD; + *usage_index = idx - 1; + } +} + + + +static INLINE unsigned svga_vs_key_size( const struct svga_vs_compile_key *key ) +{ + return sizeof *key; +} + +static INLINE unsigned svga_fs_key_size( const struct svga_fs_compile_key *key ) +{ + return (const char *)&key->tex[key->num_textures] - (const char *)key; +} + +struct svga_shader_result * +svga_translate_fragment_program( const struct svga_fragment_shader *fs, + const struct svga_fs_compile_key *fkey ); + +struct svga_shader_result * +svga_translate_vertex_program( const struct svga_vertex_shader *fs, + const struct svga_vs_compile_key *vkey ); + + +void svga_destroy_shader_result( struct svga_shader_result *result ); + +#endif diff --git a/src/gallium/drivers/svga/svga_tgsi_decl_sm20.c b/src/gallium/drivers/svga/svga_tgsi_decl_sm20.c new file mode 100644 index 0000000..1ae9906 --- /dev/null +++ b/src/gallium/drivers/svga/svga_tgsi_decl_sm20.c @@ -0,0 +1,277 @@ +/********************************************************** + * 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. + * + **********************************************************/ + + +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" +#include "util/u_memory.h" + +#include "svga_tgsi_emit.h" + + +static boolean ps20_input( struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned idx ) +{ + struct src_register reg; + SVGA3DOpDclArgs dcl; + SVGA3dShaderInstToken opcode; + + opcode = inst_token( SVGA3DOP_DCL ); + dcl.values[0] = 0; + dcl.values[1] = 0; + + switch (semantic.Name) { + case TGSI_SEMANTIC_POSITION: + /* Special case: + */ + reg = src_register( SVGA3DREG_MISCTYPE, + SVGA3DMISCREG_POSITION ); + break; + case TGSI_SEMANTIC_COLOR: + reg = src_register( SVGA3DREG_INPUT, + semantic.Index ); + break; + case TGSI_SEMANTIC_FOG: + assert(semantic.Index == 0); + reg = src_register( SVGA3DREG_TEXTURE, 0 ); + break; + case TGSI_SEMANTIC_GENERIC: + reg = src_register( SVGA3DREG_TEXTURE, + semantic.Index + 1 ); + break; + default: + assert(0); + return TRUE; + } + + emit->input_map[idx] = reg; + + dcl.dst = dst( reg ); + + dcl.usage = 0; + dcl.index = 0; + + dcl.values[0] |= 1<<31; + + return (emit_instruction(emit, opcode) && + svga_shader_emit_dwords( emit, dcl.values, Elements(dcl.values))); +} + + +static boolean ps20_output( struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned idx ) +{ + SVGA3dShaderDestToken reg; + + switch (semantic.Name) { + case TGSI_SEMANTIC_COLOR: + if (semantic.Index < PIPE_MAX_COLOR_BUFS) { + unsigned cbuf = semantic.Index; + + emit->output_map[idx] = dst_register( SVGA3DREG_TEMP, + emit->nr_hw_temp++ ); + emit->temp_col[cbuf] = emit->output_map[idx]; + emit->true_col[cbuf] = dst_register( SVGA3DREG_COLOROUT, + semantic.Index ); + } + else { + assert(0); + reg = dst_register( SVGA3DREG_COLOROUT, 0 ); + } + break; + case TGSI_SEMANTIC_POSITION: + emit->output_map[idx] = dst_register( SVGA3DREG_TEMP, + emit->nr_hw_temp++ ); + emit->temp_pos = emit->output_map[idx]; + emit->true_pos = dst_register( SVGA3DREG_DEPTHOUT, + semantic.Index ); + break; + default: + assert(0); + reg = dst_register( SVGA3DREG_COLOROUT, 0 ); + break; + } + + return TRUE; +} + + +static boolean vs20_input( struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned idx ) +{ + SVGA3DOpDclArgs dcl; + SVGA3dShaderInstToken opcode; + + opcode = inst_token( SVGA3DOP_DCL ); + dcl.values[0] = 0; + dcl.values[1] = 0; + + emit->input_map[idx] = src_register( SVGA3DREG_INPUT, idx ); + dcl.dst = dst_register( SVGA3DREG_INPUT, idx ); + + assert(dcl.dst.reserved0); + + /* Mesa doesn't provide use with VS input semantics (they're + * actually pretty meaningless), so we just generate some plausible + * ones here. This has to match what we declare in the vdecl code + * in svga_pipe_vertex.c. + */ + if (idx == 0) { + dcl.usage = SVGA3D_DECLUSAGE_POSITION; + dcl.index = 0; + } + else { + dcl.usage = SVGA3D_DECLUSAGE_TEXCOORD; + dcl.index = idx - 1; + } + + dcl.values[0] |= 1<<31; + + return (emit_instruction(emit, opcode) && + svga_shader_emit_dwords( emit, dcl.values, Elements(dcl.values))); +} + + +static boolean vs20_output( struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned idx ) +{ + /* Don't emit dcl instruction for vs20 inputs + */ + + /* Just build the register map table: + */ + switch (semantic.Name) { + case TGSI_SEMANTIC_POSITION: + assert(semantic.Index == 0); + emit->output_map[idx] = dst_register( SVGA3DREG_TEMP, + emit->nr_hw_temp++ ); + emit->temp_pos = emit->output_map[idx]; + emit->true_pos = dst_register( SVGA3DREG_RASTOUT, + SVGA3DRASTOUT_POSITION); + break; + case TGSI_SEMANTIC_PSIZE: + assert(semantic.Index == 0); + emit->output_map[idx] = dst_register( SVGA3DREG_TEMP, + emit->nr_hw_temp++ ); + emit->temp_psiz = emit->output_map[idx]; + emit->true_psiz = dst_register( SVGA3DREG_RASTOUT, + SVGA3DRASTOUT_PSIZE ); + break; + case TGSI_SEMANTIC_FOG: + assert(semantic.Index == 0); + emit->output_map[idx] = dst_register( SVGA3DREG_TEXCRDOUT, 0 ); + break; + case TGSI_SEMANTIC_COLOR: + /* oD0 */ + emit->output_map[idx] = dst_register( SVGA3DREG_ATTROUT, + semantic.Index ); + break; + case TGSI_SEMANTIC_GENERIC: + emit->output_map[idx] = dst_register( SVGA3DREG_TEXCRDOUT, + semantic.Index + 1 ); + break; + default: + assert(0); + emit->output_map[idx] = dst_register( SVGA3DREG_TEMP, 0 ); + return FALSE; + } + + return TRUE; +} + +static boolean ps20_sampler( struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned idx ) +{ + SVGA3DOpDclArgs dcl; + SVGA3dShaderInstToken opcode; + + opcode = inst_token( SVGA3DOP_DCL ); + dcl.values[0] = 0; + dcl.values[1] = 0; + + dcl.dst = dst_register( SVGA3DREG_SAMPLER, idx ); + dcl.type = svga_tgsi_sampler_type( emit, idx ); + + return (emit_instruction(emit, opcode) && + svga_shader_emit_dwords( emit, dcl.values, Elements(dcl.values))); +} + + +boolean svga_translate_decl_sm20( struct svga_shader_emitter *emit, + const struct tgsi_full_declaration *decl ) +{ + unsigned first = decl->Range.First; + unsigned last = decl->Range.Last; + unsigned semantic = 0; + unsigned semantic_idx = 0; + unsigned idx; + + if (decl->Declaration.Semantic) { + semantic = decl->Semantic.Name; + semantic_idx = decl->Semantic.Index; + } + + for( idx = first; idx <= last; idx++ ) { + boolean ok; + + switch (decl->Declaration.File) { + case TGSI_FILE_SAMPLER: + assert (emit->unit == PIPE_SHADER_FRAGMENT); + ok = ps20_sampler( emit, decl->Semantic, idx ); + break; + + case TGSI_FILE_INPUT: + if (emit->unit == PIPE_SHADER_VERTEX) + ok = vs20_input( emit, decl->Semantic, idx ); + else + ok = ps20_input( emit, decl->Semantic, idx ); + break; + + case TGSI_FILE_OUTPUT: + if (emit->unit == PIPE_SHADER_VERTEX) + ok = vs20_output( emit, decl->Semantic, idx ); + else + ok = ps20_output( emit, decl->Semantic, idx ); + break; + + default: + /* don't need to declare other vars */ + ok = TRUE; + } + + if (!ok) + return FALSE; + } + + return TRUE; +} + + + diff --git a/src/gallium/drivers/svga/svga_tgsi_decl_sm30.c b/src/gallium/drivers/svga/svga_tgsi_decl_sm30.c new file mode 100644 index 0000000..73102a7 --- /dev/null +++ b/src/gallium/drivers/svga/svga_tgsi_decl_sm30.c @@ -0,0 +1,395 @@ +/********************************************************** + * 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. + * + **********************************************************/ + + +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" +#include "util/u_memory.h" + +#include "svga_tgsi_emit.h" + +static boolean translate_vs_ps_semantic( struct tgsi_declaration_semantic semantic, + unsigned *usage, + unsigned *idx ) +{ + switch (semantic.Name) { + case TGSI_SEMANTIC_POSITION: + *idx = semantic.Index; + *usage = SVGA3D_DECLUSAGE_POSITION; + break; + case TGSI_SEMANTIC_COLOR: + + *idx = semantic.Index; + *usage = SVGA3D_DECLUSAGE_COLOR; + break; + case TGSI_SEMANTIC_BCOLOR: + *idx = semantic.Index + 2; /* sharing with COLOR */ + *usage = SVGA3D_DECLUSAGE_COLOR; + break; + case TGSI_SEMANTIC_FOG: + *idx = 0; + assert(semantic.Index == 0); + *usage = SVGA3D_DECLUSAGE_TEXCOORD; + break; + case TGSI_SEMANTIC_PSIZE: + *idx = semantic.Index; + *usage = SVGA3D_DECLUSAGE_PSIZE; + break; + case TGSI_SEMANTIC_GENERIC: + *idx = semantic.Index + 1; /* texcoord[0] is reserved for fog */ + *usage = SVGA3D_DECLUSAGE_TEXCOORD; + break; + case TGSI_SEMANTIC_NORMAL: + *idx = semantic.Index; + *usage = SVGA3D_DECLUSAGE_NORMAL; + break; + default: + assert(0); + *usage = SVGA3D_DECLUSAGE_TEXCOORD; + *idx = 0; + return FALSE; + } + + return TRUE; +} + + +static boolean emit_decl( struct svga_shader_emitter *emit, + SVGA3dShaderDestToken reg, + unsigned usage, + unsigned index ) +{ + SVGA3DOpDclArgs dcl; + SVGA3dShaderInstToken opcode; + + opcode = inst_token( SVGA3DOP_DCL ); + dcl.values[0] = 0; + dcl.values[1] = 0; + + dcl.dst = reg; + dcl.usage = usage; + dcl.index = index; + dcl.values[0] |= 1<<31; + + return (emit_instruction(emit, opcode) && + svga_shader_emit_dwords( emit, dcl.values, Elements(dcl.values))); +} + +static boolean emit_vface_decl( struct svga_shader_emitter *emit ) +{ + if (!emit->emitted_vface) { + SVGA3dShaderDestToken reg = + dst_register( SVGA3DREG_MISCTYPE, + SVGA3DMISCREG_FACE ); + + if (!emit_decl( emit, reg, 0, 0 )) + return FALSE; + + emit->emitted_vface = TRUE; + } + return TRUE; +} + +static boolean ps30_input( struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned idx ) +{ + unsigned usage, index; + SVGA3dShaderDestToken reg; + + if (semantic.Name == TGSI_SEMANTIC_POSITION) { + emit->input_map[idx] = src_register( SVGA3DREG_MISCTYPE, + SVGA3DMISCREG_POSITION ); + + emit->input_map[idx].base.swizzle = TRANSLATE_SWIZZLE( TGSI_SWIZZLE_X, + TGSI_SWIZZLE_Y, + TGSI_SWIZZLE_Y, + TGSI_SWIZZLE_Y ); + + reg = writemask( dst(emit->input_map[idx]), + TGSI_WRITEMASK_XY ); + + return emit_decl( emit, reg, 0, 0 ); + } + else if (emit->key.fkey.light_twoside && + (semantic.Name == TGSI_SEMANTIC_COLOR)) { + + if (!translate_vs_ps_semantic( semantic, &usage, &index )) + return FALSE; + + emit->internal_color_idx[emit->internal_color_count] = idx; + emit->input_map[idx] = src_register( SVGA3DREG_INPUT, emit->ps30_input_count ); + emit->ps30_input_count++; + emit->internal_color_count++; + + reg = dst( emit->input_map[idx] ); + + if (!emit_decl( emit, reg, usage, index )) + return FALSE; + + semantic.Name = TGSI_SEMANTIC_BCOLOR; + if (!translate_vs_ps_semantic( semantic, &usage, &index )) + return FALSE; + + reg = dst_register( SVGA3DREG_INPUT, emit->ps30_input_count++ ); + + if (!emit_decl( emit, reg, usage, index )) + return FALSE; + + if (!emit_vface_decl( emit )) + return FALSE; + + return TRUE; + } + else if (semantic.Name == TGSI_SEMANTIC_FACE) { + if (!emit_vface_decl( emit )) + return FALSE; + emit->emit_frontface = TRUE; + emit->internal_frontface_idx = idx; + return TRUE; + } + else { + + if (!translate_vs_ps_semantic( semantic, &usage, &index )) + return FALSE; + + emit->input_map[idx] = src_register( SVGA3DREG_INPUT, emit->ps30_input_count++ ); + reg = dst( emit->input_map[idx] ); + + return emit_decl( emit, reg, usage, index ); + } + +} + + +/* PS output registers are the same as 2.0 + */ +static boolean ps30_output( struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned idx ) +{ + SVGA3dShaderDestToken reg; + + switch (semantic.Name) { + case TGSI_SEMANTIC_COLOR: + if (emit->unit == PIPE_SHADER_FRAGMENT && + emit->key.fkey.white_fragments) { + + emit->output_map[idx] = dst_register( SVGA3DREG_TEMP, + emit->nr_hw_temp++ ); + emit->temp_col[idx] = emit->output_map[idx]; + emit->true_col[idx] = dst_register( SVGA3DREG_COLOROUT, + semantic.Index ); + } + else { + emit->output_map[idx] = dst_register( SVGA3DREG_COLOROUT, + semantic.Index ); + } + break; + case TGSI_SEMANTIC_POSITION: + emit->output_map[idx] = dst_register( SVGA3DREG_TEMP, + emit->nr_hw_temp++ ); + emit->temp_pos = emit->output_map[idx]; + emit->true_pos = dst_register( SVGA3DREG_DEPTHOUT, + semantic.Index ); + break; + default: + assert(0); + reg = dst_register( SVGA3DREG_COLOROUT, 0 ); + break; + } + + return TRUE; +} + + +/* We still make up the input semantics the same as in 2.0 + */ +static boolean vs30_input( struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned idx ) +{ + SVGA3DOpDclArgs dcl; + SVGA3dShaderInstToken opcode; + unsigned usage, index; + + opcode = inst_token( SVGA3DOP_DCL ); + dcl.values[0] = 0; + dcl.values[1] = 0; + + if (emit->key.vkey.zero_stride_vertex_elements & (1 << idx)) { + unsigned i; + unsigned offset = 0; + unsigned start_idx = emit->info.file_max[TGSI_FILE_CONSTANT] + 1; + /* adjust for prescale constants */ + start_idx += emit->key.vkey.need_prescale ? 2 : 0; + /* compute the offset from the start of zero stride constants */ + for (i = 0; i < PIPE_MAX_ATTRIBS && i < idx; ++i) { + if (emit->key.vkey.zero_stride_vertex_elements & (1<input_map[idx] = src_register( SVGA3DREG_CONST, + start_idx + offset ); + } else { + emit->input_map[idx] = src_register( SVGA3DREG_INPUT, idx ); + dcl.dst = dst_register( SVGA3DREG_INPUT, idx ); + + assert(dcl.dst.reserved0); + + svga_generate_vdecl_semantics( idx, &usage, &index ); + + dcl.usage = usage; + dcl.index = index; + dcl.values[0] |= 1<<31; + + return (emit_instruction(emit, opcode) && + svga_shader_emit_dwords( emit, dcl.values, Elements(dcl.values))); + } + return TRUE; +} + +/* VS3.0 outputs have proper declarations and semantic info for + * matching against PS inputs. + */ +static boolean vs30_output( struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned idx ) +{ + SVGA3DOpDclArgs dcl; + SVGA3dShaderInstToken opcode; + unsigned usage, index; + + opcode = inst_token( SVGA3DOP_DCL ); + dcl.values[0] = 0; + dcl.values[1] = 0; + + if (!translate_vs_ps_semantic( semantic, &usage, &index )) + return FALSE; + + dcl.dst = dst_register( SVGA3DREG_OUTPUT, idx ); + dcl.usage = usage; + dcl.index = index; + dcl.values[0] |= 1<<31; + + if (semantic.Name == TGSI_SEMANTIC_POSITION) { + assert(idx == 0); + emit->output_map[idx] = dst_register( SVGA3DREG_TEMP, + emit->nr_hw_temp++ ); + emit->temp_pos = emit->output_map[idx]; + emit->true_pos = dcl.dst; + } + else if (semantic.Name == TGSI_SEMANTIC_PSIZE) { + emit->output_map[idx] = dst_register( SVGA3DREG_TEMP, + emit->nr_hw_temp++ ); + emit->temp_psiz = emit->output_map[idx]; + + /* This has the effect of not declaring psiz (below) and not + * emitting the final MOV to true_psiz in the postamble. + */ + if (!emit->key.vkey.allow_psiz) + return TRUE; + + emit->true_psiz = dcl.dst; + } + else { + emit->output_map[idx] = dcl.dst; + } + + + return (emit_instruction(emit, opcode) && + svga_shader_emit_dwords( emit, dcl.values, Elements(dcl.values))); +} + +static boolean ps30_sampler( struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned idx ) +{ + SVGA3DOpDclArgs dcl; + SVGA3dShaderInstToken opcode; + + opcode = inst_token( SVGA3DOP_DCL ); + dcl.values[0] = 0; + dcl.values[1] = 0; + + dcl.dst = dst_register( SVGA3DREG_SAMPLER, idx ); + dcl.type = svga_tgsi_sampler_type( emit, idx ); + dcl.values[0] |= 1<<31; + + return (emit_instruction(emit, opcode) && + svga_shader_emit_dwords( emit, dcl.values, Elements(dcl.values))); +} + + +boolean svga_translate_decl_sm30( struct svga_shader_emitter *emit, + const struct tgsi_full_declaration *decl ) +{ + unsigned first = decl->Range.First; + unsigned last = decl->Range.Last; + unsigned semantic = 0; + unsigned semantic_idx = 0; + unsigned idx; + + if (decl->Declaration.Semantic) { + semantic = decl->Semantic.Name; + semantic_idx = decl->Semantic.Index; + } + + for( idx = first; idx <= last; idx++ ) { + boolean ok; + + switch (decl->Declaration.File) { + case TGSI_FILE_SAMPLER: + assert (emit->unit == PIPE_SHADER_FRAGMENT); + ok = ps30_sampler( emit, decl->Semantic, idx ); + break; + + case TGSI_FILE_INPUT: + if (emit->unit == PIPE_SHADER_VERTEX) + ok = vs30_input( emit, decl->Semantic, idx ); + else + ok = ps30_input( emit, decl->Semantic, idx ); + break; + + case TGSI_FILE_OUTPUT: + if (emit->unit == PIPE_SHADER_VERTEX) + ok = vs30_output( emit, decl->Semantic, idx ); + else + ok = ps30_output( emit, decl->Semantic, idx ); + break; + + default: + /* don't need to declare other vars */ + ok = TRUE; + } + + if (!ok) + return FALSE; + } + + return TRUE; +} + + + diff --git a/src/gallium/drivers/svga/svga_tgsi_emit.h b/src/gallium/drivers/svga/svga_tgsi_emit.h new file mode 100644 index 0000000..63ef7f8 --- /dev/null +++ b/src/gallium/drivers/svga/svga_tgsi_emit.h @@ -0,0 +1,368 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +#ifndef SVGA_TGSI_EMIT_H +#define SVGA_TGSI_EMIT_H + +#include "tgsi/tgsi_scan.h" +#include "svga_hw_reg.h" +#include "svga_tgsi.h" +#include "svga3d_shaderdefs.h" + +struct src_register +{ + SVGA3dShaderSrcToken base; + SVGA3dShaderSrcToken indirect; +}; + + +struct svga_arl_consts { + int number; + int idx; + int swizzle; + int arl_num; +}; + +/* Internal functions: + */ + +struct svga_shader_emitter +{ + boolean use_sm30; + + unsigned size; + char *buf; + char *ptr; + + union svga_compile_key key; + struct tgsi_shader_info info; + int unit; + + int imm_start; + + int nr_hw_float_const; + int nr_hw_int_const; + int nr_hw_temp; + + int insn_offset; + + int internal_temp_count; + int internal_imm_count; + + int internal_color_idx[2]; /* diffuse, specular */ + int internal_color_count; + + boolean emitted_vface; + boolean emit_frontface; + int internal_frontface_idx; + + int ps30_input_count; + + int dynamic_branching_level; + + boolean in_main_func; + + boolean created_zero_immediate; + int zero_immediate_idx; + + boolean created_loop_const; + int loop_const_idx; + + boolean created_sincos_consts; + int sincos_consts_idx; + + unsigned label[32]; + unsigned nr_labels; + + struct src_register input_map[PIPE_MAX_ATTRIBS]; + SVGA3dShaderDestToken output_map[PIPE_MAX_ATTRIBS]; + + struct src_register imm_0055; + SVGA3dShaderDestToken temp_pos; + SVGA3dShaderDestToken true_pos; + + SVGA3dShaderDestToken temp_col[PIPE_MAX_COLOR_BUFS]; + SVGA3dShaderDestToken true_col[PIPE_MAX_COLOR_BUFS]; + + SVGA3dShaderDestToken temp_psiz; + SVGA3dShaderDestToken true_psiz; + + struct svga_arl_consts arl_consts[12]; + int num_arl_consts; + int current_arl; +}; + + +boolean svga_shader_emit_dword( struct svga_shader_emitter *emit, + unsigned dword ); + +boolean svga_shader_emit_dwords( struct svga_shader_emitter *emit, + const unsigned *dwords, + unsigned nr ); + +boolean svga_shader_emit_opcode( struct svga_shader_emitter *emit, + unsigned opcode ); + +boolean svga_shader_emit_instructions( struct svga_shader_emitter *emit, + const struct tgsi_token *tokens ); + +boolean svga_translate_decl_sm20( struct svga_shader_emitter *emit, + const struct tgsi_full_declaration *decl ); + +boolean svga_translate_decl_sm30( struct svga_shader_emitter *emit, + const struct tgsi_full_declaration *decl ); + + +static INLINE boolean emit_dst( struct svga_shader_emitter *emit, + SVGA3dShaderDestToken dest ) +{ + assert(dest.reserved0); + assert(dest.mask); + return svga_shader_emit_dword( emit, dest.value ); +} + +static INLINE boolean emit_src( struct svga_shader_emitter *emit, + const struct src_register src ) +{ + if (src.base.relAddr) { + assert(src.base.reserved0); + assert(src.indirect.reserved0); + return (svga_shader_emit_dword( emit, src.base.value ) && + svga_shader_emit_dword( emit, src.indirect.value )); + } + else { + assert(src.base.reserved0); + return svga_shader_emit_dword( emit, src.base.value ); + } +} + + +static INLINE boolean emit_instruction( struct svga_shader_emitter *emit, + SVGA3dShaderInstToken opcode ) +{ + return svga_shader_emit_opcode( emit, opcode.value ); +} + + +static INLINE boolean emit_op1( struct svga_shader_emitter *emit, + SVGA3dShaderInstToken inst, + SVGA3dShaderDestToken dest, + struct src_register src0 ) +{ + return (emit_instruction( emit, inst ) && + emit_dst( emit, dest ) && + emit_src( emit, src0 )); +} + +static INLINE boolean emit_op2( struct svga_shader_emitter *emit, + SVGA3dShaderInstToken inst, + SVGA3dShaderDestToken dest, + struct src_register src0, + struct src_register src1 ) +{ + return (emit_instruction( emit, inst ) && + emit_dst( emit, dest ) && + emit_src( emit, src0 ) && + emit_src( emit, src1 )); +} + +static INLINE boolean emit_op3( struct svga_shader_emitter *emit, + SVGA3dShaderInstToken inst, + SVGA3dShaderDestToken dest, + struct src_register src0, + struct src_register src1, + struct src_register src2 ) +{ + return (emit_instruction( emit, inst ) && + emit_dst( emit, dest ) && + emit_src( emit, src0 ) && + emit_src( emit, src1 ) && + emit_src( emit, src2 )); +} + + +static INLINE boolean emit_op4( struct svga_shader_emitter *emit, + SVGA3dShaderInstToken inst, + SVGA3dShaderDestToken dest, + struct src_register src0, + struct src_register src1, + struct src_register src2, + struct src_register src3) +{ + return (emit_instruction( emit, inst ) && + emit_dst( emit, dest ) && + emit_src( emit, src0 ) && + emit_src( emit, src1 ) && + emit_src( emit, src2 ) && + emit_src( emit, src3 )); +} + + +#define TRANSLATE_SWIZZLE(x,y,z,w) ((x) | ((y) << 2) | ((z) << 4) | ((w) << 6)) +#define SWIZZLE_XYZW \ + TRANSLATE_SWIZZLE(TGSI_SWIZZLE_X,TGSI_SWIZZLE_Y,TGSI_SWIZZLE_Z,TGSI_SWIZZLE_W) +#define SWIZZLE_XXXX \ + TRANSLATE_SWIZZLE(TGSI_SWIZZLE_X,TGSI_SWIZZLE_X,TGSI_SWIZZLE_X,TGSI_SWIZZLE_X) +#define SWIZZLE_YYYY \ + TRANSLATE_SWIZZLE(TGSI_SWIZZLE_Y,TGSI_SWIZZLE_Y,TGSI_SWIZZLE_Y,TGSI_SWIZZLE_Y) +#define SWIZZLE_ZZZZ \ + TRANSLATE_SWIZZLE(TGSI_SWIZZLE_Z,TGSI_SWIZZLE_Z,TGSI_SWIZZLE_Z,TGSI_SWIZZLE_Z) +#define SWIZZLE_WWWW \ + TRANSLATE_SWIZZLE(TGSI_SWIZZLE_W,TGSI_SWIZZLE_W,TGSI_SWIZZLE_W,TGSI_SWIZZLE_W) + + + +static INLINE SVGA3dShaderInstToken +inst_token( unsigned opcode ) +{ + SVGA3dShaderInstToken inst; + + inst.value = 0; + inst.op = opcode; + + return inst; +} + +static INLINE SVGA3dShaderDestToken +dst_register( unsigned file, + int number ) +{ + SVGA3dShaderDestToken dest; + + dest.value = 0; + dest.num = number; + dest.type_upper = file >> 3; + dest.relAddr = 0; + dest.reserved1 = 0; + dest.mask = 0xf; + dest.dstMod = 0; + dest.shfScale = 0; + dest.type_lower = file & 0x7; + dest.reserved0 = 1; /* is_reg */ + + return dest; +} + +static INLINE SVGA3dShaderDestToken +writemask( SVGA3dShaderDestToken dest, + unsigned mask ) +{ + assert(dest.mask & mask); + dest.mask &= mask; + return dest; +} + + +static INLINE SVGA3dShaderSrcToken +src_token( unsigned file, int number ) +{ + SVGA3dShaderSrcToken src; + + src.value = 0; + src.num = number; + src.type_upper = file >> 3; + src.relAddr = 0; + src.reserved1 = 0; + src.swizzle = SWIZZLE_XYZW; + src.srcMod = 0; + src.type_lower = file & 0x7; + src.reserved0 = 1; /* is_reg */ + + return src; +} + + +static INLINE struct src_register +absolute( struct src_register src ) +{ + src.base.srcMod = SVGA3DSRCMOD_ABS; + + return src; +} + + +static INLINE struct src_register +negate( struct src_register src ) +{ + switch (src.base.srcMod) { + case SVGA3DSRCMOD_ABS: + src.base.srcMod = SVGA3DSRCMOD_ABSNEG; + break; + case SVGA3DSRCMOD_ABSNEG: + src.base.srcMod = SVGA3DSRCMOD_ABS; + break; + case SVGA3DSRCMOD_NEG: + src.base.srcMod = SVGA3DSRCMOD_NONE; + break; + case SVGA3DSRCMOD_NONE: + src.base.srcMod = SVGA3DSRCMOD_NEG; + break; + } + return src; +} + + +static INLINE struct src_register +src_register( unsigned file, int number ) +{ + struct src_register src; + + src.base = src_token( file, number ); + src.indirect.value = 0; + + return src; +} + +static INLINE SVGA3dShaderDestToken dst( struct src_register src ) +{ + return dst_register( SVGA3dShaderGetRegType( src.base.value ), + src.base.num ); +} + +static INLINE struct src_register src( SVGA3dShaderDestToken dst ) +{ + return src_register( SVGA3dShaderGetRegType( dst.value ), + dst.num ); +} + +static INLINE ubyte svga_tgsi_sampler_type( struct svga_shader_emitter *emit, + int idx ) +{ + switch (emit->key.fkey.tex[idx].texture_target) { + case PIPE_TEXTURE_1D: + return SVGA3DSAMP_2D; + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + return SVGA3DSAMP_2D; + case PIPE_TEXTURE_3D: + return SVGA3DSAMP_VOLUME; + case PIPE_TEXTURE_CUBE: + return SVGA3DSAMP_CUBE; + } + + return SVGA3DSAMP_UNKNOWN; +} + +#endif diff --git a/src/gallium/drivers/svga/svga_tgsi_insn.c b/src/gallium/drivers/svga/svga_tgsi_insn.c new file mode 100644 index 0000000..f2591c5 --- /dev/null +++ b/src/gallium/drivers/svga/svga_tgsi_insn.c @@ -0,0 +1,2970 @@ +/********************************************************** + * 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. + * + **********************************************************/ + + +#include "pipe/p_shader_tokens.h" +#include "tgsi/tgsi_parse.h" +#include "util/u_memory.h" + +#include "svga_tgsi_emit.h" +#include "svga_context.h" + + +static boolean emit_vs_postamble( struct svga_shader_emitter *emit ); +static boolean emit_ps_postamble( struct svga_shader_emitter *emit ); + + + + +static unsigned +translate_opcode( + uint opcode ) +{ + switch (opcode) { + case TGSI_OPCODE_ABS: return SVGA3DOP_ABS; + case TGSI_OPCODE_ADD: return SVGA3DOP_ADD; + case TGSI_OPCODE_BREAKC: return SVGA3DOP_BREAKC; + case TGSI_OPCODE_DP2A: return SVGA3DOP_DP2ADD; + case TGSI_OPCODE_DP3: return SVGA3DOP_DP3; + case TGSI_OPCODE_DP4: return SVGA3DOP_DP4; + case TGSI_OPCODE_FRC: return SVGA3DOP_FRC; + case TGSI_OPCODE_MAD: return SVGA3DOP_MAD; + case TGSI_OPCODE_MAX: return SVGA3DOP_MAX; + case TGSI_OPCODE_MIN: return SVGA3DOP_MIN; + case TGSI_OPCODE_MOV: return SVGA3DOP_MOV; + case TGSI_OPCODE_MUL: return SVGA3DOP_MUL; + case TGSI_OPCODE_NOP: return SVGA3DOP_NOP; + case TGSI_OPCODE_NRM4: return SVGA3DOP_NRM; + case TGSI_OPCODE_SSG: return SVGA3DOP_SGN; + default: + debug_printf("Unkown opcode %u\n", opcode); + assert( 0 ); + return SVGA3DOP_LAST_INST; + } +} + + +static unsigned translate_file( unsigned file ) +{ + switch (file) { + case TGSI_FILE_TEMPORARY: return SVGA3DREG_TEMP; + case TGSI_FILE_INPUT: return SVGA3DREG_INPUT; + case TGSI_FILE_OUTPUT: return SVGA3DREG_OUTPUT; /* VS3.0+ only */ + case TGSI_FILE_IMMEDIATE: return SVGA3DREG_CONST; + case TGSI_FILE_CONSTANT: return SVGA3DREG_CONST; + case TGSI_FILE_SAMPLER: return SVGA3DREG_SAMPLER; + case TGSI_FILE_ADDRESS: return SVGA3DREG_ADDR; + default: + assert( 0 ); + return SVGA3DREG_TEMP; + } +} + + + + + + +static SVGA3dShaderDestToken +translate_dst_register( struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn, + unsigned idx ) +{ + const struct tgsi_full_dst_register *reg = &insn->Dst[idx]; + SVGA3dShaderDestToken dest; + + switch (reg->Register.File) { + case TGSI_FILE_OUTPUT: + /* Output registers encode semantic information in their name. + * Need to lookup a table built at decl time: + */ + dest = emit->output_map[reg->Register.Index]; + break; + + default: + dest = dst_register( translate_file( reg->Register.File ), + reg->Register.Index ); + break; + } + + dest.mask = reg->Register.WriteMask; + assert(dest.mask); + + if (insn->Instruction.Saturate) + dest.dstMod = SVGA3DDSTMOD_SATURATE; + + return dest; +} + + +static struct src_register +swizzle( struct src_register src, + int x, + int y, + int z, + int w ) +{ + x = (src.base.swizzle >> (x * 2)) & 0x3; + y = (src.base.swizzle >> (y * 2)) & 0x3; + z = (src.base.swizzle >> (z * 2)) & 0x3; + w = (src.base.swizzle >> (w * 2)) & 0x3; + + src.base.swizzle = TRANSLATE_SWIZZLE(x,y,z,w); + + return src; +} + +static struct src_register +scalar( struct src_register src, + int comp ) +{ + return swizzle( src, comp, comp, comp, comp ); +} + +static INLINE boolean +svga_arl_needs_adjustment( const struct svga_shader_emitter *emit ) +{ + int i; + + for (i = 0; i < emit->num_arl_consts; ++i) { + if (emit->arl_consts[i].arl_num == emit->current_arl) + return TRUE; + } + return FALSE; +} + +static INLINE int +svga_arl_adjustment( const struct svga_shader_emitter *emit ) +{ + int i; + + for (i = 0; i < emit->num_arl_consts; ++i) { + if (emit->arl_consts[i].arl_num == emit->current_arl) + return emit->arl_consts[i].number; + } + return 0; +} + +static struct src_register +translate_src_register( const struct svga_shader_emitter *emit, + const struct tgsi_full_src_register *reg ) +{ + struct src_register src; + + switch (reg->Register.File) { + case TGSI_FILE_INPUT: + /* Input registers are referred to by their semantic name rather + * than by index. Use the mapping build up from the decls: + */ + src = emit->input_map[reg->Register.Index]; + break; + + case TGSI_FILE_IMMEDIATE: + /* Immediates are appended after TGSI constants in the D3D + * constant buffer. + */ + src = src_register( translate_file( reg->Register.File ), + reg->Register.Index + + emit->imm_start ); + break; + + default: + src = src_register( translate_file( reg->Register.File ), + reg->Register.Index ); + + break; + } + + /* Indirect addressing. + */ + if (reg->Register.Indirect) { + if (emit->unit == PIPE_SHADER_FRAGMENT) { + /* Pixel shaders have only loop registers for relative + * addressing into inputs. Ignore the redundant address + * register, the contents of aL should be in sync with it. + */ + if (reg->Register.File == TGSI_FILE_INPUT) { + src.base.relAddr = 1; + src.indirect = src_token(SVGA3DREG_LOOP, 0); + } + } + else { + /* Constant buffers only. + */ + if (reg->Register.File == TGSI_FILE_CONSTANT) { + /* we shift the offset towards the minimum */ + if (svga_arl_needs_adjustment( emit )) { + src.base.num -= svga_arl_adjustment( emit ); + } + src.base.relAddr = 1; + + /* Not really sure what should go in the second token: + */ + src.indirect = src_token( SVGA3DREG_ADDR, + reg->Indirect.Index ); + + src.indirect.swizzle = SWIZZLE_XXXX; + } + } + } + + src = swizzle( src, + reg->Register.SwizzleX, + reg->Register.SwizzleY, + reg->Register.SwizzleZ, + reg->Register.SwizzleW ); + + /* src.mod isn't a bitfield, unfortunately: + * See tgsi_util_get_full_src_register_sign_mode for implementation details. + */ + if (reg->Register.Absolute) { + if (reg->Register.Negate) + src.base.srcMod = SVGA3DSRCMOD_ABSNEG; + else + src.base.srcMod = SVGA3DSRCMOD_ABS; + } + else { + if (reg->Register.Negate) + src.base.srcMod = SVGA3DSRCMOD_NEG; + else + src.base.srcMod = SVGA3DSRCMOD_NONE; + } + + return src; +} + + +/* + * Get a temporary register, return -1 if none available + */ +static INLINE SVGA3dShaderDestToken +get_temp( struct svga_shader_emitter *emit ) +{ + int i = emit->nr_hw_temp + emit->internal_temp_count++; + + return dst_register( SVGA3DREG_TEMP, i ); +} + +/* Release a single temp. Currently only effective if it was the last + * allocated temp, otherwise release will be delayed until the next + * call to reset_temp_regs(). + */ +static INLINE void +release_temp( struct svga_shader_emitter *emit, + SVGA3dShaderDestToken temp ) +{ + if (temp.num == emit->internal_temp_count - 1) + emit->internal_temp_count--; +} + +static void reset_temp_regs( struct svga_shader_emitter *emit ) +{ + emit->internal_temp_count = 0; +} + + +static boolean submit_op0( struct svga_shader_emitter *emit, + SVGA3dShaderInstToken inst, + SVGA3dShaderDestToken dest ) +{ + return (emit_instruction( emit, inst ) && + emit_dst( emit, dest )); +} + +static boolean submit_op1( struct svga_shader_emitter *emit, + SVGA3dShaderInstToken inst, + SVGA3dShaderDestToken dest, + struct src_register src0 ) +{ + return emit_op1( emit, inst, dest, src0 ); +} + + +/* SVGA shaders may not refer to >1 constant register in a single + * instruction. This function checks for that usage and inserts a + * move to temporary if detected. + * + * The same applies to input registers -- at most a single input + * register may be read by any instruction. + */ +static boolean submit_op2( struct svga_shader_emitter *emit, + SVGA3dShaderInstToken inst, + SVGA3dShaderDestToken dest, + struct src_register src0, + struct src_register src1 ) +{ + SVGA3dShaderDestToken temp; + SVGA3dShaderRegType type0, type1; + boolean need_temp = FALSE; + + temp.value = 0; + type0 = SVGA3dShaderGetRegType( src0.base.value ); + type1 = SVGA3dShaderGetRegType( src1.base.value ); + + if (type0 == SVGA3DREG_CONST && + type1 == SVGA3DREG_CONST && + src0.base.num != src1.base.num) + need_temp = TRUE; + + if (type0 == SVGA3DREG_INPUT && + type1 == SVGA3DREG_INPUT && + src0.base.num != src1.base.num) + need_temp = TRUE; + + if (need_temp) + { + temp = get_temp( emit ); + + if (!emit_op1( emit, inst_token( SVGA3DOP_MOV ), temp, src0 )) + return FALSE; + + src0 = src( temp ); + } + + if (!emit_op2( emit, inst, dest, src0, src1 )) + return FALSE; + + if (need_temp) + release_temp( emit, temp ); + + return TRUE; +} + + +/* SVGA shaders may not refer to >1 constant register in a single + * instruction. This function checks for that usage and inserts a + * move to temporary if detected. + */ +static boolean submit_op3( struct svga_shader_emitter *emit, + SVGA3dShaderInstToken inst, + SVGA3dShaderDestToken dest, + struct src_register src0, + struct src_register src1, + struct src_register src2 ) +{ + SVGA3dShaderDestToken temp0; + SVGA3dShaderDestToken temp1; + boolean need_temp0 = FALSE; + boolean need_temp1 = FALSE; + SVGA3dShaderRegType type0, type1, type2; + + temp0.value = 0; + temp1.value = 0; + type0 = SVGA3dShaderGetRegType( src0.base.value ); + type1 = SVGA3dShaderGetRegType( src1.base.value ); + type2 = SVGA3dShaderGetRegType( src2.base.value ); + + if (inst.op != SVGA3DOP_SINCOS) { + if (type0 == SVGA3DREG_CONST && + ((type1 == SVGA3DREG_CONST && src0.base.num != src1.base.num) || + (type2 == SVGA3DREG_CONST && src0.base.num != src2.base.num))) + need_temp0 = TRUE; + + if (type1 == SVGA3DREG_CONST && + (type2 == SVGA3DREG_CONST && src1.base.num != src2.base.num)) + need_temp1 = TRUE; + } + + if (type0 == SVGA3DREG_INPUT && + ((type1 == SVGA3DREG_INPUT && src0.base.num != src1.base.num) || + (type2 == SVGA3DREG_INPUT && src0.base.num != src2.base.num))) + need_temp0 = TRUE; + + if (type1 == SVGA3DREG_INPUT && + (type2 == SVGA3DREG_INPUT && src1.base.num != src2.base.num)) + need_temp1 = TRUE; + + if (need_temp0) + { + temp0 = get_temp( emit ); + + if (!emit_op1( emit, inst_token( SVGA3DOP_MOV ), temp0, src0 )) + return FALSE; + + src0 = src( temp0 ); + } + + if (need_temp1) + { + temp1 = get_temp( emit ); + + if (!emit_op1( emit, inst_token( SVGA3DOP_MOV ), temp1, src1 )) + return FALSE; + + src1 = src( temp1 ); + } + + if (!emit_op3( emit, inst, dest, src0, src1, src2 )) + return FALSE; + + if (need_temp1) + release_temp( emit, temp1 ); + if (need_temp0) + release_temp( emit, temp0 ); + return TRUE; +} + + + + +/* SVGA shaders may not refer to >1 constant register in a single + * instruction. This function checks for that usage and inserts a + * move to temporary if detected. + */ +static boolean submit_op4( struct svga_shader_emitter *emit, + SVGA3dShaderInstToken inst, + SVGA3dShaderDestToken dest, + struct src_register src0, + struct src_register src1, + struct src_register src2, + struct src_register src3) +{ + SVGA3dShaderDestToken temp0; + SVGA3dShaderDestToken temp3; + boolean need_temp0 = FALSE; + boolean need_temp3 = FALSE; + SVGA3dShaderRegType type0, type1, type2, type3; + + temp0.value = 0; + temp3.value = 0; + type0 = SVGA3dShaderGetRegType( src0.base.value ); + type1 = SVGA3dShaderGetRegType( src1.base.value ); + type2 = SVGA3dShaderGetRegType( src2.base.value ); + type3 = SVGA3dShaderGetRegType( src2.base.value ); + + /* Make life a little easier - this is only used by the TXD + * instruction which is guaranteed not to have a constant/input reg + * in one slot at least: + */ + assert(type1 == SVGA3DREG_SAMPLER); + + if (type0 == SVGA3DREG_CONST && + ((type3 == SVGA3DREG_CONST && src0.base.num != src3.base.num) || + (type2 == SVGA3DREG_CONST && src0.base.num != src2.base.num))) + need_temp0 = TRUE; + + if (type3 == SVGA3DREG_CONST && + (type2 == SVGA3DREG_CONST && src3.base.num != src2.base.num)) + need_temp3 = TRUE; + + if (type0 == SVGA3DREG_INPUT && + ((type3 == SVGA3DREG_INPUT && src0.base.num != src3.base.num) || + (type2 == SVGA3DREG_INPUT && src0.base.num != src2.base.num))) + need_temp0 = TRUE; + + if (type3 == SVGA3DREG_INPUT && + (type2 == SVGA3DREG_INPUT && src3.base.num != src2.base.num)) + need_temp3 = TRUE; + + if (need_temp0) + { + temp0 = get_temp( emit ); + + if (!emit_op1( emit, inst_token( SVGA3DOP_MOV ), temp0, src0 )) + return FALSE; + + src0 = src( temp0 ); + } + + if (need_temp3) + { + temp3 = get_temp( emit ); + + if (!emit_op1( emit, inst_token( SVGA3DOP_MOV ), temp3, src3 )) + return FALSE; + + src3 = src( temp3 ); + } + + if (!emit_op4( emit, inst, dest, src0, src1, src2, src3 )) + return FALSE; + + if (need_temp3) + release_temp( emit, temp3 ); + if (need_temp0) + release_temp( emit, temp0 ); + return TRUE; +} + + +static boolean emit_def_const( struct svga_shader_emitter *emit, + SVGA3dShaderConstType type, + unsigned idx, + float a, + float b, + float c, + float d ) +{ + SVGA3DOpDefArgs def; + SVGA3dShaderInstToken opcode; + + switch (type) { + case SVGA3D_CONST_TYPE_FLOAT: + opcode = inst_token( SVGA3DOP_DEF ); + def.dst = dst_register( SVGA3DREG_CONST, idx ); + def.constValues[0] = a; + def.constValues[1] = b; + def.constValues[2] = c; + def.constValues[3] = d; + break; + case SVGA3D_CONST_TYPE_INT: + opcode = inst_token( SVGA3DOP_DEFI ); + def.dst = dst_register( SVGA3DREG_CONSTINT, idx ); + def.constIValues[0] = (int)a; + def.constIValues[1] = (int)b; + def.constIValues[2] = (int)c; + def.constIValues[3] = (int)d; + break; + default: + assert(0); + opcode = inst_token( SVGA3DOP_NOP ); + break; + } + + if (!emit_instruction(emit, opcode) || + !svga_shader_emit_dwords( emit, def.values, Elements(def.values))) + return FALSE; + + return TRUE; +} + +static INLINE boolean +create_zero_immediate( struct svga_shader_emitter *emit ) +{ + unsigned idx = emit->nr_hw_float_const++; + + if (!emit_def_const( emit, SVGA3D_CONST_TYPE_FLOAT, + idx, 0, 0, 0, 1 )) + return FALSE; + + emit->zero_immediate_idx = idx; + emit->created_zero_immediate = TRUE; + + return TRUE; +} + +static INLINE boolean +create_loop_const( struct svga_shader_emitter *emit ) +{ + unsigned idx = emit->nr_hw_int_const++; + + if (!emit_def_const( emit, SVGA3D_CONST_TYPE_INT, idx, + 255, /* iteration count */ + 0, /* initial value */ + 1, /* step size */ + 0 /* not used, must be 0 */)) + return FALSE; + + emit->loop_const_idx = idx; + emit->created_loop_const = TRUE; + + return TRUE; +} + +static INLINE boolean +create_sincos_consts( struct svga_shader_emitter *emit ) +{ + unsigned idx = emit->nr_hw_float_const++; + + if (!emit_def_const( emit, SVGA3D_CONST_TYPE_FLOAT, idx, + -1.5500992e-006f, + -2.1701389e-005f, + 0.0026041667f, + 0.00026041668f )) + return FALSE; + + emit->sincos_consts_idx = idx; + idx = emit->nr_hw_float_const++; + + if (!emit_def_const( emit, SVGA3D_CONST_TYPE_FLOAT, idx, + -0.020833334f, + -0.12500000f, + 1.0f, + 0.50000000f )) + return FALSE; + + emit->created_sincos_consts = TRUE; + + return TRUE; +} + +static INLINE boolean +create_arl_consts( struct svga_shader_emitter *emit ) +{ + int i; + + for (i = 0; i < emit->num_arl_consts; i += 4) { + int j; + unsigned idx = emit->nr_hw_float_const++; + float vals[4]; + for (j = 0; j < 4 && (j + i) < emit->num_arl_consts; ++j) { + vals[j] = emit->arl_consts[i + j].number; + emit->arl_consts[i + j].idx = idx; + switch (j) { + case 0: + emit->arl_consts[i + 0].swizzle = TGSI_SWIZZLE_X; + break; + case 1: + emit->arl_consts[i + 0].swizzle = TGSI_SWIZZLE_Y; + break; + case 2: + emit->arl_consts[i + 0].swizzle = TGSI_SWIZZLE_Z; + break; + case 3: + emit->arl_consts[i + 0].swizzle = TGSI_SWIZZLE_W; + break; + } + } + while (j < 4) + vals[j++] = 0; + + if (!emit_def_const( emit, SVGA3D_CONST_TYPE_FLOAT, idx, + vals[0], vals[1], + vals[2], vals[3])) + return FALSE; + } + + return TRUE; +} + +static INLINE struct src_register +get_vface( struct svga_shader_emitter *emit ) +{ + assert(emit->emitted_vface); + return src_register(SVGA3DREG_MISCTYPE, + SVGA3DMISCREG_FACE); +} + +/* returns {0, 0, 0, 1} immediate */ +static INLINE struct src_register +get_zero_immediate( struct svga_shader_emitter *emit ) +{ + assert(emit->created_zero_immediate); + assert(emit->zero_immediate_idx >= 0); + return src_register( SVGA3DREG_CONST, + emit->zero_immediate_idx ); +} + +/* returns the loop const */ +static INLINE struct src_register +get_loop_const( struct svga_shader_emitter *emit ) +{ + assert(emit->created_loop_const); + assert(emit->loop_const_idx >= 0); + return src_register( SVGA3DREG_CONSTINT, + emit->loop_const_idx ); +} + +/* returns a sincos const */ +static INLINE struct src_register +get_sincos_const( struct svga_shader_emitter *emit, + unsigned index ) +{ + assert(emit->created_sincos_consts); + assert(emit->sincos_consts_idx >= 0); + assert(index == 0 || index == 1); + return src_register( SVGA3DREG_CONST, + emit->sincos_consts_idx + index ); +} + +static INLINE struct src_register +get_fake_arl_const( struct svga_shader_emitter *emit ) +{ + struct src_register reg; + int idx = 0, swizzle = 0, i; + + for (i = 0; i < emit->num_arl_consts; ++ i) { + if (emit->arl_consts[i].arl_num == emit->current_arl) { + idx = emit->arl_consts[i].idx; + swizzle = emit->arl_consts[i].swizzle; + } + } + + reg = src_register( SVGA3DREG_CONST, idx ); + return scalar(reg, swizzle); +} + +static INLINE struct src_register +get_tex_dimensions( struct svga_shader_emitter *emit, int sampler_num ) +{ + int idx; + struct src_register reg; + + /* the width/height indexes start right after constants */ + idx = emit->key.fkey.tex[sampler_num].width_height_idx + + emit->info.file_max[TGSI_FILE_CONSTANT] + 1; + + reg = src_register( SVGA3DREG_CONST, idx ); + return reg; +} + +static boolean emit_fake_arl(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) +{ + const struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + struct src_register src1 = get_fake_arl_const( emit ); + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + SVGA3dShaderDestToken tmp = get_temp( emit ); + + if (!submit_op1(emit, inst_token( SVGA3DOP_MOV ), tmp, src0)) + return FALSE; + + if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ), tmp, src( tmp ), + src1)) + return FALSE; + + /* replicate the original swizzle */ + src1 = src(tmp); + src1.base.swizzle = src0.base.swizzle; + + return submit_op1( emit, inst_token( SVGA3DOP_MOVA ), + dst, src1 ); +} + +static boolean emit_if(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) +{ + const struct src_register src = translate_src_register( + emit, &insn->Src[0] ); + struct src_register zero = get_zero_immediate( emit ); + SVGA3dShaderInstToken if_token = inst_token( SVGA3DOP_IFC ); + + if_token.control = SVGA3DOPCOMPC_NE; + zero = scalar(zero, TGSI_SWIZZLE_X); + + emit->dynamic_branching_level++; + + return (emit_instruction( emit, if_token ) && + emit_src( emit, src ) && + emit_src( emit, zero ) ); +} + +static boolean emit_endif(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) +{ + emit->dynamic_branching_level--; + + return (emit_instruction( emit, + inst_token( SVGA3DOP_ENDIF ))); +} + +static boolean emit_else(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) +{ + return (emit_instruction( emit, + inst_token( SVGA3DOP_ELSE ))); +} + +/* Translate the following TGSI FLR instruction. + * FLR DST, SRC + * To the following SVGA3D instruction sequence. + * FRC TMP, SRC + * SUB DST, SRC, TMP + */ +static boolean emit_floor(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + const struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + SVGA3dShaderDestToken temp = get_temp( emit ); + + /* FRC TMP, SRC */ + if (!submit_op1( emit, inst_token( SVGA3DOP_FRC ), temp, src0 )) + return FALSE; + + /* SUB DST, SRC, TMP */ + if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ), dst, src0, + negate( src( temp ) ) )) + return FALSE; + + return TRUE; +} + + +/* Translate the following TGSI CMP instruction. + * CMP DST, SRC0, SRC1, SRC2 + * To the following SVGA3D instruction sequence. + * CMP DST, SRC0, SRC2, SRC1 + */ +static boolean emit_cmp(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + const struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + const struct src_register src1 = translate_src_register( + emit, &insn->Src[1] ); + const struct src_register src2 = translate_src_register( + emit, &insn->Src[2] ); + + if (emit->unit == PIPE_SHADER_VERTEX) { + SVGA3dShaderDestToken temp = get_temp(emit); + struct src_register zero = scalar(get_zero_immediate(emit), TGSI_SWIZZLE_X); + + /* Since vertex shaders don't support the CMP instruction, + * simulate it with SLT and LRP instructions. + * SLT TMP, SRC0, 0.0 + * LRP DST, TMP, SRC1, SRC2 + */ + if (!submit_op2(emit, inst_token(SVGA3DOP_SLT), temp, src0, zero)) + return FALSE; + return submit_op3(emit, inst_token(SVGA3DOP_LRP), dst, src(temp), src1, src2); + } + + /* CMP DST, SRC0, SRC2, SRC1 */ + return submit_op3( emit, inst_token( SVGA3DOP_CMP ), dst, src0, src2, src1); +} + + + +/* Translate the following TGSI DIV instruction. + * DIV DST.xy, SRC0, SRC1 + * To the following SVGA3D instruction sequence. + * RCP TMP.x, SRC1.xxxx + * RCP TMP.y, SRC1.yyyy + * MUL DST.xy, SRC0, TMP + */ +static boolean emit_div(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + const struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + const struct src_register src1 = translate_src_register( + emit, &insn->Src[1] ); + SVGA3dShaderDestToken temp = get_temp( emit ); + int i; + + /* For each enabled element, perform a RCP instruction. Note that + * RCP is scalar in SVGA3D: + */ + for (i = 0; i < 4; i++) { + unsigned channel = 1 << i; + if (dst.mask & channel) { + /* RCP TMP.?, SRC1.???? */ + if (!submit_op1( emit, inst_token( SVGA3DOP_RCP ), + writemask(temp, channel), + scalar(src1, i) )) + return FALSE; + } + } + + /* Then multiply them out with a single mul: + * + * MUL DST, SRC0, TMP + */ + if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ), dst, src0, + src( temp ) )) + return FALSE; + + return TRUE; +} + +/* Translate the following TGSI DP2 instruction. + * DP2 DST, SRC1, SRC2 + * To the following SVGA3D instruction sequence. + * MUL TMP, SRC1, SRC2 + * ADD DST, TMP.xxxx, TMP.yyyy + */ +static boolean emit_dp2(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + const struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + const struct src_register src1 = translate_src_register( + emit, &insn->Src[1] ); + SVGA3dShaderDestToken temp = get_temp( emit ); + struct src_register temp_src0, temp_src1; + + /* MUL TMP, SRC1, SRC2 */ + if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ), temp, src0, src1 )) + return FALSE; + + temp_src0 = scalar(src( temp ), TGSI_SWIZZLE_X); + temp_src1 = scalar(src( temp ), TGSI_SWIZZLE_Y); + + /* ADD DST, TMP.xxxx, TMP.yyyy */ + if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ), dst, + temp_src0, temp_src1 )) + return FALSE; + + return TRUE; +} + + +/* Translate the following TGSI DPH instruction. + * DPH DST, SRC1, SRC2 + * To the following SVGA3D instruction sequence. + * DP3 TMP, SRC1, SRC2 + * ADD DST, TMP, SRC2.wwww + */ +static boolean emit_dph(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + const struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + struct src_register src1 = translate_src_register( + emit, &insn->Src[1] ); + SVGA3dShaderDestToken temp = get_temp( emit ); + + /* DP3 TMP, SRC1, SRC2 */ + if (!submit_op2( emit, inst_token( SVGA3DOP_DP3 ), temp, src0, src1 )) + return FALSE; + + src1 = scalar(src1, TGSI_SWIZZLE_W); + + /* ADD DST, TMP, SRC2.wwww */ + if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ), dst, + src( temp ), src1 )) + return FALSE; + + return TRUE; +} + +/* Translate the following TGSI DST instruction. + * NRM DST, SRC + * To the following SVGA3D instruction sequence. + * DP3 TMP, SRC, SRC + * RSQ TMP, TMP + * MUL DST, SRC, TMP + */ +static boolean emit_nrm(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + const struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + SVGA3dShaderDestToken temp = get_temp( emit ); + + /* DP3 TMP, SRC, SRC */ + if (!submit_op2( emit, inst_token( SVGA3DOP_DP3 ), temp, src0, src0 )) + return FALSE; + + /* RSQ TMP, TMP */ + if (!submit_op1( emit, inst_token( SVGA3DOP_RSQ ), temp, src( temp ))) + return FALSE; + + /* MUL DST, SRC, TMP */ + if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ), dst, + src0, src( temp ))) + return FALSE; + + return TRUE; + +} + +static boolean do_emit_sincos(struct svga_shader_emitter *emit, + SVGA3dShaderDestToken dst, + struct src_register src0) +{ + src0 = scalar(src0, TGSI_SWIZZLE_X); + + if (emit->use_sm30) { + return submit_op1( emit, inst_token( SVGA3DOP_SINCOS ), + dst, src0 ); + } else { + struct src_register const1 = get_sincos_const( emit, 0 ); + struct src_register const2 = get_sincos_const( emit, 1 ); + + return submit_op3( emit, inst_token( SVGA3DOP_SINCOS ), + dst, src0, const1, const2 ); + } +} + +static boolean emit_sincos(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + SVGA3dShaderDestToken temp = get_temp( emit ); + + /* SCS TMP SRC */ + if (!do_emit_sincos(emit, writemask(temp, TGSI_WRITEMASK_XY), src0 )) + return FALSE; + + /* MOV DST TMP */ + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), dst, src( temp ) )) + return FALSE; + + return TRUE; +} + +/* + * SCS TMP SRC + * MOV DST TMP.yyyy + */ +static boolean emit_sin(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + SVGA3dShaderDestToken temp = get_temp( emit ); + + /* SCS TMP SRC */ + if (!do_emit_sincos(emit, writemask(temp, TGSI_WRITEMASK_Y), src0)) + return FALSE; + + src0 = scalar(src( temp ), TGSI_SWIZZLE_Y); + + /* MOV DST TMP.yyyy */ + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), dst, src0 )) + return FALSE; + + return TRUE; +} + +/* + * SCS TMP SRC + * MOV DST TMP.xxxx + */ +static boolean emit_cos(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + SVGA3dShaderDestToken temp = get_temp( emit ); + + /* SCS TMP SRC */ + if (!do_emit_sincos( emit, writemask(temp, TGSI_WRITEMASK_X), src0 )) + return FALSE; + + src0 = scalar(src( temp ), TGSI_SWIZZLE_X); + + /* MOV DST TMP.xxxx */ + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), dst, src0 )) + return FALSE; + + return TRUE; +} + + +/* + * ADD DST SRC0, negate(SRC0) + */ +static boolean emit_sub(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + struct src_register src1 = translate_src_register( + emit, &insn->Src[1] ); + + src1 = negate(src1); + + if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ), dst, + src0, src1 )) + return FALSE; + + return TRUE; +} + + +static boolean emit_kil(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderInstToken inst; + const struct tgsi_full_src_register *reg = &insn->Src[0]; + struct src_register src0; + + inst = inst_token( SVGA3DOP_TEXKILL ); + src0 = translate_src_register( emit, reg ); + + if (reg->Register.Absolute || + reg->Register.Negate || + reg->Register.Indirect || + reg->Register.SwizzleX != 0 || + reg->Register.SwizzleY != 1 || + reg->Register.SwizzleZ != 2 || + reg->Register.File != TGSI_FILE_TEMPORARY) + { + SVGA3dShaderDestToken temp = get_temp( emit ); + + submit_op1( emit, inst_token( SVGA3DOP_MOV ), temp, src0 ); + src0 = src( temp ); + } + + return submit_op0( emit, inst, dst(src0) ); +} + + +/* mesa state tracker always emits kilp as an unconditional + * kil */ +static boolean emit_kilp(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderInstToken inst; + SVGA3dShaderDestToken temp; + struct src_register one = scalar( get_zero_immediate( emit ), + TGSI_SWIZZLE_W ); + + inst = inst_token( SVGA3DOP_TEXKILL ); + + /* texkill doesn't allow negation on the operand so lets move + * negation of {1} to a temp register */ + temp = get_temp( emit ); + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), temp, + negate( one ) )) + return FALSE; + + return submit_op0( emit, inst, temp ); +} + +/* Implement conditionals by initializing destination reg to 'fail', + * then set predicate reg with UFOP_SETP, then move 'pass' to dest + * based on predicate reg. + * + * SETP src0, cmp, src1 -- do this first to avoid aliasing problems. + * MOV dst, fail + * MOV dst, pass, p0 + */ +static boolean +emit_conditional(struct svga_shader_emitter *emit, + unsigned compare_func, + SVGA3dShaderDestToken dst, + struct src_register src0, + struct src_register src1, + struct src_register pass, + struct src_register fail) +{ + SVGA3dShaderDestToken pred_reg = dst_register( SVGA3DREG_PREDICATE, 0 ); + SVGA3dShaderInstToken setp_token, mov_token; + setp_token = inst_token( SVGA3DOP_SETP ); + + switch (compare_func) { + case PIPE_FUNC_NEVER: + return submit_op1( emit, inst_token( SVGA3DOP_MOV ), + dst, fail ); + break; + case PIPE_FUNC_LESS: + setp_token.control = SVGA3DOPCOMP_LT; + break; + case PIPE_FUNC_EQUAL: + setp_token.control = SVGA3DOPCOMP_EQ; + break; + case PIPE_FUNC_LEQUAL: + setp_token.control = SVGA3DOPCOMP_LE; + break; + case PIPE_FUNC_GREATER: + setp_token.control = SVGA3DOPCOMP_GT; + break; + case PIPE_FUNC_NOTEQUAL: + setp_token.control = SVGA3DOPCOMPC_NE; + break; + case PIPE_FUNC_GEQUAL: + setp_token.control = SVGA3DOPCOMP_GE; + break; + case PIPE_FUNC_ALWAYS: + return submit_op1( emit, inst_token( SVGA3DOP_MOV ), + dst, pass ); + break; + } + + /* SETP src0, COMPOP, src1 */ + if (!submit_op2( emit, setp_token, pred_reg, + src0, src1 )) + return FALSE; + + mov_token = inst_token( SVGA3DOP_MOV ); + + /* MOV dst, fail */ + if (!submit_op1( emit, mov_token, dst, + fail )) + return FALSE; + + /* MOV dst, pass (predicated) + * + * Note that the predicate reg (and possible modifiers) is passed + * as the first source argument. + */ + mov_token.predicated = 1; + if (!submit_op2( emit, mov_token, dst, + src( pred_reg ), pass )) + return FALSE; + + return TRUE; +} + + +static boolean +emit_select(struct svga_shader_emitter *emit, + unsigned compare_func, + SVGA3dShaderDestToken dst, + struct src_register src0, + struct src_register src1 ) +{ + /* There are some SVGA instructions which implement some selects + * directly, but they are only available in the vertex shader. + */ + if (emit->unit == PIPE_SHADER_VERTEX) { + switch (compare_func) { + case PIPE_FUNC_GEQUAL: + return submit_op2( emit, inst_token( SVGA3DOP_SGE ), dst, src0, src1 ); + case PIPE_FUNC_LEQUAL: + return submit_op2( emit, inst_token( SVGA3DOP_SGE ), dst, src1, src0 ); + case PIPE_FUNC_GREATER: + return submit_op2( emit, inst_token( SVGA3DOP_SLT ), dst, src1, src0 ); + case PIPE_FUNC_LESS: + return submit_op2( emit, inst_token( SVGA3DOP_SLT ), dst, src0, src1 ); + default: + break; + } + } + + + /* Otherwise, need to use the setp approach: + */ + { + struct src_register one, zero; + /* zero immediate is 0,0,0,1 */ + zero = get_zero_immediate( emit ); + one = scalar( zero, TGSI_SWIZZLE_W ); + zero = scalar( zero, TGSI_SWIZZLE_X ); + + return emit_conditional( + emit, + compare_func, + dst, + src0, + src1, + one, zero); + } +} + + +static boolean emit_select_op(struct svga_shader_emitter *emit, + unsigned compare, + const struct tgsi_full_instruction *insn) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + struct src_register src1 = translate_src_register( + emit, &insn->Src[1] ); + + return emit_select( emit, compare, dst, src0, src1 ); +} + + +/* Translate texture instructions to SVGA3D representation. + */ +static boolean emit_tex2(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn, + SVGA3dShaderDestToken dst ) +{ + SVGA3dShaderInstToken inst; + struct src_register texcoord; + struct src_register sampler; + SVGA3dShaderDestToken tmp; + + inst.value = 0; + + switch (insn->Instruction.Opcode) { + case TGSI_OPCODE_TEX: + inst.op = SVGA3DOP_TEX; + break; + case TGSI_OPCODE_TXP: + inst.op = SVGA3DOP_TEX; + inst.control = SVGA3DOPCONT_PROJECT; + break; + case TGSI_OPCODE_TXB: + inst.op = SVGA3DOP_TEX; + inst.control = SVGA3DOPCONT_BIAS; + break; + case TGSI_OPCODE_TXL: + inst.op = SVGA3DOP_TEXLDL; + break; + default: + assert(0); + return FALSE; + } + + texcoord = translate_src_register( emit, &insn->Src[0] ); + sampler = translate_src_register( emit, &insn->Src[1] ); + + if (emit->key.fkey.tex[sampler.base.num].unnormalized || + emit->dynamic_branching_level > 0) + tmp = get_temp( emit ); + + /* Can't do mipmapping inside dynamic branch constructs. Force LOD + * zero in that case. + */ + if (emit->dynamic_branching_level > 0 && + inst.op == SVGA3DOP_TEX && + SVGA3dShaderGetRegType(texcoord.base.value) == SVGA3DREG_TEMP) { + struct src_register zero = get_zero_immediate( emit ); + + /* MOV tmp, texcoord */ + if (!submit_op1( emit, + inst_token( SVGA3DOP_MOV ), + tmp, + texcoord )) + return FALSE; + + /* MOV tmp.w, zero */ + if (!submit_op1( emit, + inst_token( SVGA3DOP_MOV ), + writemask( tmp, TGSI_WRITEMASK_W ), + scalar( zero, TGSI_SWIZZLE_X ))) + return FALSE; + + texcoord = src( tmp ); + inst.op = SVGA3DOP_TEXLDL; + } + + /* Explicit normalization of texcoords: + */ + if (emit->key.fkey.tex[sampler.base.num].unnormalized) { + struct src_register wh = get_tex_dimensions( emit, sampler.base.num ); + + /* MUL tmp, SRC0, WH */ + if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ), + tmp, texcoord, wh )) + return FALSE; + + texcoord = src( tmp ); + } + + return submit_op2( emit, inst, dst, texcoord, sampler ); +} + + + + +/* Translate texture instructions to SVGA3D representation. + */ +static boolean emit_tex4(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn, + SVGA3dShaderDestToken dst ) +{ + SVGA3dShaderInstToken inst; + struct src_register texcoord; + struct src_register ddx; + struct src_register ddy; + struct src_register sampler; + + texcoord = translate_src_register( emit, &insn->Src[0] ); + ddx = translate_src_register( emit, &insn->Src[1] ); + ddy = translate_src_register( emit, &insn->Src[2] ); + sampler = translate_src_register( emit, &insn->Src[3] ); + + inst.value = 0; + + switch (insn->Instruction.Opcode) { + case TGSI_OPCODE_TXD: + inst.op = SVGA3DOP_TEXLDD; /* 4 args! */ + break; + default: + assert(0); + return FALSE; + } + + return submit_op4( emit, inst, dst, texcoord, sampler, ddx, ddy ); +} + + +static boolean emit_tex(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderDestToken dst = + translate_dst_register( emit, insn, 0 ); + struct src_register src0 = + translate_src_register( emit, &insn->Src[0] ); + struct src_register src1 = + translate_src_register( emit, &insn->Src[1] ); + + SVGA3dShaderDestToken tex_result; + + /* check for shadow samplers */ + boolean compare = (emit->key.fkey.tex[src1.base.num].compare_mode == + PIPE_TEX_COMPARE_R_TO_TEXTURE); + + + /* If doing compare processing, need to put this value into a + * temporary so it can be used as a source later on. + */ + if (compare || + (!emit->use_sm30 && dst.mask != TGSI_WRITEMASK_XYZW) ) { + tex_result = get_temp( emit ); + } + else { + tex_result = dst; + } + + switch(insn->Instruction.Opcode) { + case TGSI_OPCODE_TEX: + case TGSI_OPCODE_TXB: + case TGSI_OPCODE_TXP: + case TGSI_OPCODE_TXL: + if (!emit_tex2( emit, insn, tex_result )) + return FALSE; + break; + case TGSI_OPCODE_TXD: + if (!emit_tex4( emit, insn, tex_result )) + return FALSE; + break; + default: + assert(0); + } + + + if (compare) { + if (dst.mask & TGSI_WRITEMASK_XYZ) { + SVGA3dShaderDestToken src0_zdivw = get_temp( emit ); + struct src_register tex_src_x = scalar(src(tex_result), TGSI_SWIZZLE_Y); + + /* Divide texcoord R by Q */ + if (!submit_op1( emit, inst_token( SVGA3DOP_RCP ), + writemask(src0_zdivw, TGSI_WRITEMASK_X), + scalar(src0, TGSI_SWIZZLE_W) )) + return FALSE; + + if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ), + writemask(src0_zdivw, TGSI_WRITEMASK_X), + scalar(src0, TGSI_SWIZZLE_Z), + scalar(src(src0_zdivw), TGSI_SWIZZLE_X) )) + return FALSE; + + if (!emit_select( + emit, + emit->key.fkey.tex[src1.base.num].compare_func, + writemask( dst, TGSI_WRITEMASK_XYZ ), + scalar(src(src0_zdivw), TGSI_SWIZZLE_X), + tex_src_x)) + return FALSE; + } + + if (dst.mask & TGSI_WRITEMASK_W) { + struct src_register one = + scalar( get_zero_immediate( emit ), TGSI_SWIZZLE_W ); + + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), + writemask( dst, TGSI_WRITEMASK_W ), + one )) + return FALSE; + } + + return TRUE; + } + else if (!emit->use_sm30 && dst.mask != TGSI_WRITEMASK_XYZW) + { + if (!emit_op1( emit, inst_token( SVGA3DOP_MOV ), dst, src(tex_result) )) + return FALSE; + } + + return TRUE; +} + +static boolean emit_bgnloop2( struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderInstToken inst = inst_token( SVGA3DOP_LOOP ); + struct src_register loop_reg = src_register( SVGA3DREG_LOOP, 0 ); + struct src_register const_int = get_loop_const( emit ); + + emit->dynamic_branching_level++; + + return (emit_instruction( emit, inst ) && + emit_src( emit, loop_reg ) && + emit_src( emit, const_int ) ); +} + +static boolean emit_endloop2( struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderInstToken inst = inst_token( SVGA3DOP_ENDLOOP ); + + emit->dynamic_branching_level--; + + return emit_instruction( emit, inst ); +} + +static boolean emit_brk( struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderInstToken inst = inst_token( SVGA3DOP_BREAK ); + return emit_instruction( emit, inst ); +} + +static boolean emit_scalar_op1( struct svga_shader_emitter *emit, + unsigned opcode, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderInstToken inst; + SVGA3dShaderDestToken dst; + struct src_register src; + + inst = inst_token( opcode ); + dst = translate_dst_register( emit, insn, 0 ); + src = translate_src_register( emit, &insn->Src[0] ); + src = scalar( src, TGSI_SWIZZLE_X ); + + return submit_op1( emit, inst, dst, src ); +} + + +static boolean emit_simple_instruction(struct svga_shader_emitter *emit, + unsigned opcode, + const struct tgsi_full_instruction *insn ) +{ + const struct tgsi_full_src_register *src = insn->Src; + SVGA3dShaderInstToken inst; + SVGA3dShaderDestToken dst; + + inst = inst_token( opcode ); + dst = translate_dst_register( emit, insn, 0 ); + + switch (insn->Instruction.NumSrcRegs) { + case 0: + return submit_op0( emit, inst, dst ); + case 1: + return submit_op1( emit, inst, dst, + translate_src_register( emit, &src[0] )); + case 2: + return submit_op2( emit, inst, dst, + translate_src_register( emit, &src[0] ), + translate_src_register( emit, &src[1] ) ); + case 3: + return submit_op3( emit, inst, dst, + translate_src_register( emit, &src[0] ), + translate_src_register( emit, &src[1] ), + translate_src_register( emit, &src[2] ) ); + default: + assert(0); + return FALSE; + } +} + + +static boolean emit_deriv(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + if (emit->dynamic_branching_level > 0 && + insn->Src[0].Register.File == TGSI_FILE_TEMPORARY) + { + struct src_register zero = get_zero_immediate( emit ); + SVGA3dShaderDestToken dst = + translate_dst_register( emit, insn, 0 ); + + /* Deriv opcodes not valid inside dynamic branching, workaround + * by zeroing out the destination. + */ + if (!submit_op1(emit, + inst_token( SVGA3DOP_MOV ), + dst, + scalar(zero, TGSI_SWIZZLE_X))) + return FALSE; + + return TRUE; + } + else { + unsigned opcode; + + switch (insn->Instruction.Opcode) { + case TGSI_OPCODE_DDX: + opcode = SVGA3DOP_DSX; + break; + case TGSI_OPCODE_DDY: + opcode = SVGA3DOP_DSY; + break; + default: + return FALSE; + } + + return emit_simple_instruction( emit, opcode, insn ); + } +} + +static boolean emit_arl(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) +{ + ++emit->current_arl; + if (emit->unit == PIPE_SHADER_FRAGMENT) { + /* MOVA not present in pixel shader instruction set. + * Ignore this instruction altogether since it is + * only used for loop counters -- and for that + * we reference aL directly. + */ + return TRUE; + } + if (svga_arl_needs_adjustment( emit )) { + return emit_fake_arl( emit, insn ); + } else { + /* no need to adjust, just emit straight arl */ + return emit_simple_instruction(emit, SVGA3DOP_MOVA, insn); + } +} + +static boolean alias_src_dst( struct src_register src, + SVGA3dShaderDestToken dst ) +{ + if (src.base.num != dst.num) + return FALSE; + + if (SVGA3dShaderGetRegType(dst.value) != + SVGA3dShaderGetRegType(src.base.value)) + return FALSE; + + return TRUE; +} + +static boolean emit_pow(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + struct src_register src1 = translate_src_register( + emit, &insn->Src[1] ); + boolean need_tmp = FALSE; + + /* POW can only output to a temporary */ + if (insn->Dst[0].Register.File != TGSI_FILE_TEMPORARY) + need_tmp = TRUE; + + /* POW src1 must not be the same register as dst */ + if (alias_src_dst( src1, dst )) + need_tmp = TRUE; + + /* it's a scalar op */ + src0 = scalar( src0, TGSI_SWIZZLE_X ); + src1 = scalar( src1, TGSI_SWIZZLE_X ); + + if (need_tmp) { + SVGA3dShaderDestToken tmp = writemask(get_temp( emit ), TGSI_WRITEMASK_X ); + + if (!submit_op2(emit, inst_token( SVGA3DOP_POW ), tmp, src0, src1)) + return FALSE; + + return submit_op1(emit, inst_token( SVGA3DOP_MOV ), dst, scalar(src(tmp), 0) ); + } + else { + return submit_op2(emit, inst_token( SVGA3DOP_POW ), dst, src0, src1); + } +} + +static boolean emit_xpd(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + const struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + const struct src_register src1 = translate_src_register( + emit, &insn->Src[1] ); + boolean need_dst_tmp = FALSE; + + /* XPD can only output to a temporary */ + if (SVGA3dShaderGetRegType(dst.value) != SVGA3DREG_TEMP) + need_dst_tmp = TRUE; + + /* The dst reg must not be the same as src0 or src1*/ + if (alias_src_dst(src0, dst) || + alias_src_dst(src1, dst)) + need_dst_tmp = TRUE; + + if (need_dst_tmp) { + SVGA3dShaderDestToken tmp = get_temp( emit ); + + /* Obey DX9 restrictions on mask: + */ + tmp.mask = dst.mask & TGSI_WRITEMASK_XYZ; + + if (!submit_op2(emit, inst_token( SVGA3DOP_CRS ), tmp, src0, src1)) + return FALSE; + + if (!submit_op1(emit, inst_token( SVGA3DOP_MOV ), dst, src( tmp ))) + return FALSE; + } + else { + if (!submit_op2(emit, inst_token( SVGA3DOP_CRS ), dst, src0, src1)) + return FALSE; + } + + /* Need to emit 1.0 to dst.w? + */ + if (dst.mask & TGSI_WRITEMASK_W) { + struct src_register zero = get_zero_immediate( emit ); + + if (!submit_op1(emit, + inst_token( SVGA3DOP_MOV ), + writemask(dst, TGSI_WRITEMASK_W), + zero)) + return FALSE; + } + + return TRUE; +} + + +static boolean emit_lrp(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + SVGA3dShaderDestToken tmp; + const struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + const struct src_register src1 = translate_src_register( + emit, &insn->Src[1] ); + const struct src_register src2 = translate_src_register( + emit, &insn->Src[2] ); + boolean need_dst_tmp = FALSE; + + /* The dst reg must not be the same as src0 or src2 */ + if (alias_src_dst(src0, dst) || + alias_src_dst(src2, dst)) + need_dst_tmp = TRUE; + + if (need_dst_tmp) { + tmp = get_temp( emit ); + tmp.mask = dst.mask; + } + else { + tmp = dst; + } + + if (!submit_op3(emit, inst_token( SVGA3DOP_LRP ), tmp, src0, src1, src2)) + return FALSE; + + if (need_dst_tmp) { + if (!submit_op1(emit, inst_token( SVGA3DOP_MOV ), dst, src( tmp ))) + return FALSE; + } + + return TRUE; +} + + +static boolean emit_dst_insn(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + if (emit->unit == PIPE_SHADER_VERTEX) { + /* SVGA/DX9 has a DST instruction, but only for vertex shaders: + */ + return emit_simple_instruction(emit, SVGA3DOP_DST, insn); + } + else { + + /* result[0] = 1 * 1; + * result[1] = a[1] * b[1]; + * result[2] = a[2] * 1; + * result[3] = 1 * b[3]; + */ + + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + SVGA3dShaderDestToken tmp; + const struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + const struct src_register src1 = translate_src_register( + emit, &insn->Src[1] ); + struct src_register zero = get_zero_immediate( emit ); + boolean need_tmp = FALSE; + + if (SVGA3dShaderGetRegType(dst.value) != SVGA3DREG_TEMP || + alias_src_dst(src0, dst) || + alias_src_dst(src1, dst)) + need_tmp = TRUE; + + if (need_tmp) { + tmp = get_temp( emit ); + } + else { + tmp = dst; + } + + /* tmp.xw = 1.0 + */ + if (tmp.mask & TGSI_WRITEMASK_XW) { + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), + writemask(tmp, TGSI_WRITEMASK_XW ), + scalar( zero, 3 ))) + return FALSE; + } + + /* tmp.yz = src0 + */ + if (tmp.mask & TGSI_WRITEMASK_YZ) { + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), + writemask(tmp, TGSI_WRITEMASK_YZ ), + src0)) + return FALSE; + } + + /* tmp.yw = tmp * src1 + */ + if (tmp.mask & TGSI_WRITEMASK_YW) { + if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ), + writemask(tmp, TGSI_WRITEMASK_YW ), + src(tmp), + src1)) + return FALSE; + } + + /* dst = tmp + */ + if (need_tmp) { + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), + dst, + src(tmp))) + return FALSE; + } + } + + return TRUE; +} + + +static boolean emit_exp(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + struct src_register src0 = + translate_src_register( emit, &insn->Src[0] ); + struct src_register zero = get_zero_immediate( emit ); + SVGA3dShaderDestToken fraction; + + if (dst.mask & TGSI_WRITEMASK_Y) + fraction = dst; + else if (dst.mask & TGSI_WRITEMASK_X) + fraction = get_temp( emit ); + else + fraction.value = 0; + + /* If y is being written, fill it with src0 - floor(src0). + */ + if (dst.mask & TGSI_WRITEMASK_XY) { + if (!submit_op1( emit, inst_token( SVGA3DOP_FRC ), + writemask( fraction, TGSI_WRITEMASK_Y ), + src0 )) + return FALSE; + } + + /* If x is being written, fill it with 2 ^ floor(src0). + */ + if (dst.mask & TGSI_WRITEMASK_X) { + if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ), + writemask( dst, TGSI_WRITEMASK_X ), + src0, + scalar( negate( src( fraction ) ), TGSI_SWIZZLE_Y ) ) ) + return FALSE; + + if (!submit_op1( emit, inst_token( SVGA3DOP_EXP ), + writemask( dst, TGSI_WRITEMASK_X ), + scalar( src( dst ), TGSI_SWIZZLE_X ) ) ) + return FALSE; + + if (!(dst.mask & TGSI_WRITEMASK_Y)) + release_temp( emit, fraction ); + } + + /* If z is being written, fill it with 2 ^ src0 (partial precision). + */ + if (dst.mask & TGSI_WRITEMASK_Z) { + if (!submit_op1( emit, inst_token( SVGA3DOP_EXPP ), + writemask( dst, TGSI_WRITEMASK_Z ), + src0 ) ) + return FALSE; + } + + /* If w is being written, fill it with one. + */ + if (dst.mask & TGSI_WRITEMASK_W) { + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), + writemask(dst, TGSI_WRITEMASK_W), + scalar( zero, TGSI_SWIZZLE_W ) )) + return FALSE; + } + + return TRUE; +} + +static boolean emit_lit(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + if (emit->unit == PIPE_SHADER_VERTEX) { + /* SVGA/DX9 has a LIT instruction, but only for vertex shaders: + */ + return emit_simple_instruction(emit, SVGA3DOP_LIT, insn); + } + else { + + /* D3D vs. GL semantics can be fairly easily accomodated by + * variations on this sequence. + * + * GL: + * tmp.y = src.x + * tmp.z = pow(src.y,src.w) + * p0 = src0.xxxx > 0 + * result = zero.wxxw + * (p0) result.yz = tmp + * + * D3D: + * tmp.y = src.x + * tmp.z = pow(src.y,src.w) + * p0 = src0.xxyy > 0 + * result = zero.wxxw + * (p0) result.yz = tmp + * + * Will implement the GL version for now. + */ + + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + SVGA3dShaderDestToken tmp = get_temp( emit ); + const struct src_register src0 = translate_src_register( + emit, &insn->Src[0] ); + struct src_register zero = get_zero_immediate( emit ); + + /* tmp = pow(src.y, src.w) + */ + if (dst.mask & TGSI_WRITEMASK_Z) { + if (!submit_op2(emit, inst_token( SVGA3DOP_POW ), + tmp, + scalar(src0, 1), + scalar(src0, 3))) + return FALSE; + } + + /* tmp.y = src.x + */ + if (dst.mask & TGSI_WRITEMASK_Y) { + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), + writemask(tmp, TGSI_WRITEMASK_Y ), + scalar(src0, 0))) + return FALSE; + } + + /* Can't quite do this with emit conditional due to the extra + * writemask on the predicated mov: + */ + { + SVGA3dShaderDestToken pred_reg = dst_register( SVGA3DREG_PREDICATE, 0 ); + SVGA3dShaderInstToken setp_token, mov_token; + struct src_register predsrc; + + setp_token = inst_token( SVGA3DOP_SETP ); + mov_token = inst_token( SVGA3DOP_MOV ); + + setp_token.control = SVGA3DOPCOMP_GT; + + /* D3D vs GL semantics: + */ + if (0) + predsrc = swizzle(src0, 0, 0, 1, 1); /* D3D */ + else + predsrc = swizzle(src0, 0, 0, 0, 0); /* GL */ + + /* SETP src0.xxyy, GT, {0}.x */ + if (!submit_op2( emit, setp_token, pred_reg, + predsrc, + swizzle(zero, 0, 0, 0, 0) )) + return FALSE; + + /* MOV dst, fail */ + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), dst, + swizzle(zero, 3, 0, 0, 3 ))) + return FALSE; + + /* MOV dst.yz, tmp (predicated) + * + * Note that the predicate reg (and possible modifiers) is passed + * as the first source argument. + */ + if (dst.mask & TGSI_WRITEMASK_YZ) { + mov_token.predicated = 1; + if (!submit_op2( emit, mov_token, + writemask(dst, TGSI_WRITEMASK_YZ), + src( pred_reg ), src( tmp ) )) + return FALSE; + } + } + } + + return TRUE; +} + + + + +static boolean emit_ex2( struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + SVGA3dShaderInstToken inst; + SVGA3dShaderDestToken dst; + struct src_register src0; + + inst = inst_token( SVGA3DOP_EXP ); + dst = translate_dst_register( emit, insn, 0 ); + src0 = translate_src_register( emit, &insn->Src[0] ); + src0 = scalar( src0, TGSI_SWIZZLE_X ); + + if (dst.mask != TGSI_WRITEMASK_XYZW) { + SVGA3dShaderDestToken tmp = get_temp( emit ); + + if (!submit_op1( emit, inst, tmp, src0 )) + return FALSE; + + return submit_op1( emit, inst_token( SVGA3DOP_MOV ), + dst, + scalar( src( tmp ), TGSI_SWIZZLE_X ) ); + } + + return submit_op1( emit, inst, dst, src0 ); +} + + +static boolean emit_log(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) +{ + SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); + struct src_register src0 = + translate_src_register( emit, &insn->Src[0] ); + struct src_register zero = get_zero_immediate( emit ); + SVGA3dShaderDestToken abs_tmp; + struct src_register abs_src0; + SVGA3dShaderDestToken log2_abs; + + abs_tmp.value = 0; + + if (dst.mask & TGSI_WRITEMASK_Z) + log2_abs = dst; + else if (dst.mask & TGSI_WRITEMASK_XY) + log2_abs = get_temp( emit ); + else + log2_abs.value = 0; + + /* If z is being written, fill it with log2( abs( src0 ) ). + */ + if (dst.mask & TGSI_WRITEMASK_XYZ) { + if (!src0.base.srcMod || src0.base.srcMod == SVGA3DSRCMOD_ABS) + abs_src0 = src0; + else { + abs_tmp = get_temp( emit ); + + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), + abs_tmp, + src0 ) ) + return FALSE; + + abs_src0 = src( abs_tmp ); + } + + abs_src0 = absolute( scalar( abs_src0, TGSI_SWIZZLE_X ) ); + + if (!submit_op1( emit, inst_token( SVGA3DOP_LOG ), + writemask( log2_abs, TGSI_WRITEMASK_Z ), + abs_src0 ) ) + return FALSE; + } + + if (dst.mask & TGSI_WRITEMASK_XY) { + SVGA3dShaderDestToken floor_log2; + + if (dst.mask & TGSI_WRITEMASK_X) + floor_log2 = dst; + else + floor_log2 = get_temp( emit ); + + /* If x is being written, fill it with floor( log2( abs( src0 ) ) ). + */ + if (!submit_op1( emit, inst_token( SVGA3DOP_FRC ), + writemask( floor_log2, TGSI_WRITEMASK_X ), + scalar( src( log2_abs ), TGSI_SWIZZLE_Z ) ) ) + return FALSE; + + if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ), + writemask( floor_log2, TGSI_WRITEMASK_X ), + scalar( src( log2_abs ), TGSI_SWIZZLE_Z ), + negate( src( floor_log2 ) ) ) ) + return FALSE; + + /* If y is being written, fill it with + * abs ( src0 ) / ( 2 ^ floor( log2( abs( src0 ) ) ) ). + */ + if (dst.mask & TGSI_WRITEMASK_Y) { + if (!submit_op1( emit, inst_token( SVGA3DOP_EXP ), + writemask( dst, TGSI_WRITEMASK_Y ), + negate( scalar( src( floor_log2 ), + TGSI_SWIZZLE_X ) ) ) ) + return FALSE; + + if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ), + writemask( dst, TGSI_WRITEMASK_Y ), + src( dst ), + abs_src0 ) ) + return FALSE; + } + + if (!(dst.mask & TGSI_WRITEMASK_X)) + release_temp( emit, floor_log2 ); + + if (!(dst.mask & TGSI_WRITEMASK_Z)) + release_temp( emit, log2_abs ); + } + + if (dst.mask & TGSI_WRITEMASK_XYZ && src0.base.srcMod && + src0.base.srcMod != SVGA3DSRCMOD_ABS) + release_temp( emit, abs_tmp ); + + /* If w is being written, fill it with one. + */ + if (dst.mask & TGSI_WRITEMASK_W) { + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), + writemask(dst, TGSI_WRITEMASK_W), + scalar( zero, TGSI_SWIZZLE_W ) )) + return FALSE; + } + + return TRUE; +} + + +static boolean emit_bgnsub( struct svga_shader_emitter *emit, + unsigned position, + const struct tgsi_full_instruction *insn ) +{ + unsigned i; + + /* Note that we've finished the main function and are now emitting + * subroutines. This affects how we terminate the generated + * shader. + */ + emit->in_main_func = FALSE; + + for (i = 0; i < emit->nr_labels; i++) { + if (emit->label[i] == position) { + return (emit_instruction( emit, inst_token( SVGA3DOP_RET ) ) && + emit_instruction( emit, inst_token( SVGA3DOP_LABEL ) ) && + emit_src( emit, src_register( SVGA3DREG_LABEL, i ))); + } + } + + assert(0); + return TRUE; +} + +static boolean emit_call( struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) +{ + unsigned position = insn->Label.Label; + unsigned i; + + for (i = 0; i < emit->nr_labels; i++) { + if (emit->label[i] == position) + break; + } + + if (emit->nr_labels == Elements(emit->label)) + return FALSE; + + if (i == emit->nr_labels) { + emit->label[i] = position; + emit->nr_labels++; + } + + return (emit_instruction( emit, inst_token( SVGA3DOP_CALL ) ) && + emit_src( emit, src_register( SVGA3DREG_LABEL, i ))); +} + + +static boolean emit_end( struct svga_shader_emitter *emit ) +{ + if (emit->unit == PIPE_SHADER_VERTEX) { + return emit_vs_postamble( emit ); + } + else { + return emit_ps_postamble( emit ); + } +} + + + +static boolean svga_emit_instruction( struct svga_shader_emitter *emit, + unsigned position, + const struct tgsi_full_instruction *insn ) +{ + switch (insn->Instruction.Opcode) { + + case TGSI_OPCODE_ARL: + return emit_arl( emit, insn ); + + case TGSI_OPCODE_TEX: + case TGSI_OPCODE_TXB: + case TGSI_OPCODE_TXP: + case TGSI_OPCODE_TXL: + case TGSI_OPCODE_TXD: + return emit_tex( emit, insn ); + + case TGSI_OPCODE_DDX: + case TGSI_OPCODE_DDY: + return emit_deriv( emit, insn ); + + case TGSI_OPCODE_BGNSUB: + return emit_bgnsub( emit, position, insn ); + + case TGSI_OPCODE_ENDSUB: + return TRUE; + + case TGSI_OPCODE_CAL: + return emit_call( emit, insn ); + + case TGSI_OPCODE_FLR: + case TGSI_OPCODE_TRUNC: /* should be TRUNC, not FLR */ + return emit_floor( emit, insn ); + + case TGSI_OPCODE_CMP: + return emit_cmp( emit, insn ); + + case TGSI_OPCODE_DIV: + return emit_div( emit, insn ); + + case TGSI_OPCODE_DP2: + return emit_dp2( emit, insn ); + + case TGSI_OPCODE_DPH: + return emit_dph( emit, insn ); + + case TGSI_OPCODE_NRM: + return emit_nrm( emit, insn ); + + case TGSI_OPCODE_COS: + return emit_cos( emit, insn ); + + case TGSI_OPCODE_SIN: + return emit_sin( emit, insn ); + + case TGSI_OPCODE_SCS: + return emit_sincos( emit, insn ); + + case TGSI_OPCODE_END: + /* TGSI always finishes the main func with an END */ + return emit_end( emit ); + + case TGSI_OPCODE_KIL: + return emit_kil( emit, insn ); + + /* Selection opcodes. The underlying language is fairly + * non-orthogonal about these. + */ + case TGSI_OPCODE_SEQ: + return emit_select_op( emit, PIPE_FUNC_EQUAL, insn ); + + case TGSI_OPCODE_SNE: + return emit_select_op( emit, PIPE_FUNC_NOTEQUAL, insn ); + + case TGSI_OPCODE_SGT: + return emit_select_op( emit, PIPE_FUNC_GREATER, insn ); + + case TGSI_OPCODE_SGE: + return emit_select_op( emit, PIPE_FUNC_GEQUAL, insn ); + + case TGSI_OPCODE_SLT: + return emit_select_op( emit, PIPE_FUNC_LESS, insn ); + + case TGSI_OPCODE_SLE: + return emit_select_op( emit, PIPE_FUNC_LEQUAL, insn ); + + case TGSI_OPCODE_SUB: + return emit_sub( emit, insn ); + + case TGSI_OPCODE_POW: + return emit_pow( emit, insn ); + + case TGSI_OPCODE_EX2: + return emit_ex2( emit, insn ); + + case TGSI_OPCODE_EXP: + return emit_exp( emit, insn ); + + case TGSI_OPCODE_LOG: + return emit_log( emit, insn ); + + case TGSI_OPCODE_LG2: + return emit_scalar_op1( emit, SVGA3DOP_LOG, insn ); + + case TGSI_OPCODE_RSQ: + return emit_scalar_op1( emit, SVGA3DOP_RSQ, insn ); + + case TGSI_OPCODE_RCP: + return emit_scalar_op1( emit, SVGA3DOP_RCP, insn ); + + case TGSI_OPCODE_CONT: + case TGSI_OPCODE_RET: + /* This is a noop -- we tell mesa that we can't support RET + * within a function (early return), so this will always be + * followed by an ENDSUB. + */ + return TRUE; + + /* These aren't actually used by any of the frontends we care + * about: + */ + case TGSI_OPCODE_CLAMP: + case TGSI_OPCODE_ROUND: + case TGSI_OPCODE_AND: + case TGSI_OPCODE_OR: + case TGSI_OPCODE_I2F: + case TGSI_OPCODE_NOT: + case TGSI_OPCODE_SHL: + case TGSI_OPCODE_ISHR: + case TGSI_OPCODE_XOR: + return FALSE; + + case TGSI_OPCODE_IF: + return emit_if( emit, insn ); + case TGSI_OPCODE_ELSE: + return emit_else( emit, insn ); + case TGSI_OPCODE_ENDIF: + return emit_endif( emit, insn ); + + case TGSI_OPCODE_BGNLOOP: + return emit_bgnloop2( emit, insn ); + case TGSI_OPCODE_ENDLOOP: + return emit_endloop2( emit, insn ); + case TGSI_OPCODE_BRK: + return emit_brk( emit, insn ); + + case TGSI_OPCODE_XPD: + return emit_xpd( emit, insn ); + + case TGSI_OPCODE_KILP: + return emit_kilp( emit, insn ); + + case TGSI_OPCODE_DST: + return emit_dst_insn( emit, insn ); + + case TGSI_OPCODE_LIT: + return emit_lit( emit, insn ); + + case TGSI_OPCODE_LRP: + return emit_lrp( emit, insn ); + + default: { + unsigned opcode = translate_opcode(insn->Instruction.Opcode); + + if (opcode == SVGA3DOP_LAST_INST) + return FALSE; + + if (!emit_simple_instruction( emit, opcode, insn )) + return FALSE; + } + } + + return TRUE; +} + + +static boolean svga_emit_immediate( struct svga_shader_emitter *emit, + struct tgsi_full_immediate *imm) +{ + static const float id[4] = {0,0,0,1}; + float value[4]; + unsigned i; + + assert(1 <= imm->Immediate.NrTokens && imm->Immediate.NrTokens <= 5); + for (i = 0; i < imm->Immediate.NrTokens - 1; i++) + value[i] = imm->u[i].Float; + + for ( ; i < 4; i++ ) + value[i] = id[i]; + + return emit_def_const( emit, SVGA3D_CONST_TYPE_FLOAT, + emit->imm_start + emit->internal_imm_count++, + value[0], value[1], value[2], value[3]); +} + +static boolean make_immediate( struct svga_shader_emitter *emit, + float a, + float b, + float c, + float d, + struct src_register *out ) +{ + unsigned idx = emit->nr_hw_float_const++; + + if (!emit_def_const( emit, SVGA3D_CONST_TYPE_FLOAT, + idx, a, b, c, d )) + return FALSE; + + *out = src_register( SVGA3DREG_CONST, idx ); + + return TRUE; +} + +static boolean emit_vs_preamble( struct svga_shader_emitter *emit ) +{ + if (!emit->key.vkey.need_prescale) { + if (!make_immediate( emit, 0, 0, .5, .5, + &emit->imm_0055)) + return FALSE; + } + + return TRUE; +} + +static boolean emit_ps_preamble( struct svga_shader_emitter *emit ) +{ + unsigned i; + + /* For SM20, need to initialize the temporaries we're using to hold + * color outputs to some value. Shaders which don't set all of + * these values are likely to be rejected by the DX9 runtime. + */ + if (!emit->use_sm30) { + struct src_register zero = get_zero_immediate( emit ); + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + if (SVGA3dShaderGetRegType(emit->true_col[i].value) != 0) { + + if (!submit_op1( emit, + inst_token(SVGA3DOP_MOV), + emit->temp_col[i], + zero )) + return FALSE; + } + } + } + + return TRUE; +} + +static boolean emit_ps_postamble( struct svga_shader_emitter *emit ) +{ + unsigned i; + + /* PS oDepth is incredibly fragile and it's very hard to catch the + * types of usage that break it during shader emit. Easier just to + * redirect the main program to a temporary and then only touch + * oDepth with a hand-crafted MOV below. + */ + if (SVGA3dShaderGetRegType(emit->true_pos.value) != 0) { + + if (!submit_op1( emit, + inst_token(SVGA3DOP_MOV), + emit->true_pos, + scalar(src(emit->temp_pos), TGSI_SWIZZLE_Z) )) + return FALSE; + } + + /* Similarly for SM20 color outputs... Luckily SM30 isn't so + * fragile. + */ + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + if (SVGA3dShaderGetRegType(emit->true_col[i].value) != 0) { + + /* Potentially override output colors with white for XOR + * logicop workaround. + */ + if (emit->unit == PIPE_SHADER_FRAGMENT && + emit->key.fkey.white_fragments) { + + struct src_register one = scalar( get_zero_immediate( emit ), + TGSI_SWIZZLE_W ); + + if (!submit_op1( emit, + inst_token(SVGA3DOP_MOV), + emit->true_col[i], + one )) + return FALSE; + } + else { + if (!submit_op1( emit, + inst_token(SVGA3DOP_MOV), + emit->true_col[i], + src(emit->temp_col[i]) )) + return FALSE; + } + } + } + + return TRUE; +} + +static boolean emit_vs_postamble( struct svga_shader_emitter *emit ) +{ + /* PSIZ output is incredibly fragile and it's very hard to catch + * the types of usage that break it during shader emit. Easier + * just to redirect the main program to a temporary and then only + * touch PSIZ with a hand-crafted MOV below. + */ + if (SVGA3dShaderGetRegType(emit->true_psiz.value) != 0) { + + if (!submit_op1( emit, + inst_token(SVGA3DOP_MOV), + emit->true_psiz, + scalar(src(emit->temp_psiz), TGSI_SWIZZLE_X) )) + return FALSE; + } + + /* Need to perform various manipulations on vertex position to cope + * with the different GL and D3D clip spaces. + */ + if (emit->key.vkey.need_prescale) { + SVGA3dShaderDestToken temp_pos = emit->temp_pos; + SVGA3dShaderDestToken pos = emit->true_pos; + unsigned offset = emit->info.file_max[TGSI_FILE_CONSTANT] + 1; + struct src_register prescale_scale = src_register( SVGA3DREG_CONST, + offset + 0 ); + struct src_register prescale_trans = src_register( SVGA3DREG_CONST, + offset + 1 ); + + /* MUL temp_pos.xyz, temp_pos, prescale.scale + * MAD result.position, temp_pos.wwww, prescale.trans, temp_pos + * --> Note that prescale.trans.w == 0 + */ + if (!submit_op2( emit, + inst_token(SVGA3DOP_MUL), + writemask(temp_pos, TGSI_WRITEMASK_XYZ), + src(temp_pos), + prescale_scale )) + return FALSE; + + if (!submit_op3( emit, + inst_token(SVGA3DOP_MAD), + pos, + swizzle(src(temp_pos), 3, 3, 3, 3), + prescale_trans, + src(temp_pos))) + return FALSE; + } + else { + SVGA3dShaderDestToken temp_pos = emit->temp_pos; + SVGA3dShaderDestToken pos = emit->true_pos; + struct src_register imm_0055 = emit->imm_0055; + + /* Adjust GL clipping coordinate space to hardware (D3D-style): + * + * DP4 temp_pos.z, {0,0,.5,.5}, temp_pos + * MOV result.position, temp_pos + */ + if (!submit_op2( emit, + inst_token(SVGA3DOP_DP4), + writemask(temp_pos, TGSI_WRITEMASK_Z), + imm_0055, + src(temp_pos) )) + return FALSE; + + if (!submit_op1( emit, + inst_token(SVGA3DOP_MOV), + pos, + src(temp_pos) )) + return FALSE; + } + + return TRUE; +} + +/* + 0: IF VFACE :4 + 1: COLOR = FrontColor; + 2: ELSE + 3: COLOR = BackColor; + 4: ENDIF + */ +static boolean emit_light_twoside( struct svga_shader_emitter *emit ) +{ + struct src_register vface, zero; + struct src_register front[2]; + struct src_register back[2]; + SVGA3dShaderDestToken color[2]; + int count = emit->internal_color_count; + int i; + SVGA3dShaderInstToken if_token; + + if (count == 0) + return TRUE; + + vface = get_vface( emit ); + zero = get_zero_immediate( emit ); + + /* Can't use get_temp() to allocate the color reg as such + * temporaries will be reclaimed after each instruction by the call + * to reset_temp_regs(). + */ + for (i = 0; i < count; i++) { + color[i] = dst_register( SVGA3DREG_TEMP, + emit->nr_hw_temp++ ); + + front[i] = emit->input_map[emit->internal_color_idx[i]]; + + /* Back is always the next input: + */ + back[i] = front[i]; + back[i].base.num = front[i].base.num + 1; + + /* Reassign the input_map to the actual front-face color: + */ + emit->input_map[emit->internal_color_idx[i]] = src(color[i]); + } + + if_token = inst_token( SVGA3DOP_IFC ); + + if (emit->key.fkey.front_ccw) + if_token.control = SVGA3DOPCOMP_LT; + else + if_token.control = SVGA3DOPCOMP_GT; + + zero = scalar(zero, TGSI_SWIZZLE_X); + + if (!(emit_instruction( emit, if_token ) && + emit_src( emit, vface ) && + emit_src( emit, zero ) )) + return FALSE; + + for (i = 0; i < count; i++) { + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), color[i], front[i] )) + return FALSE; + } + + if (!(emit_instruction( emit, inst_token( SVGA3DOP_ELSE)))) + return FALSE; + + for (i = 0; i < count; i++) { + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), color[i], back[i] )) + return FALSE; + } + + if (!emit_instruction( emit, inst_token( SVGA3DOP_ENDIF ) )) + return FALSE; + + return TRUE; +} + +/* + 0: SETP_GT TEMP, VFACE, 0 + where TEMP is a fake frontface register + */ +static boolean emit_frontface( struct svga_shader_emitter *emit ) +{ + struct src_register vface, zero; + SVGA3dShaderDestToken temp; + struct src_register pass, fail; + + vface = get_vface( emit ); + zero = get_zero_immediate( emit ); + + /* Can't use get_temp() to allocate the fake frontface reg as such + * temporaries will be reclaimed after each instruction by the call + * to reset_temp_regs(). + */ + temp = dst_register( SVGA3DREG_TEMP, + emit->nr_hw_temp++ ); + + if (emit->key.fkey.front_ccw) { + pass = scalar( zero, TGSI_SWIZZLE_X ); + fail = scalar( zero, TGSI_SWIZZLE_W ); + } else { + pass = scalar( zero, TGSI_SWIZZLE_W ); + fail = scalar( zero, TGSI_SWIZZLE_X ); + } + + if (!emit_conditional(emit, PIPE_FUNC_GREATER, + temp, vface, scalar( zero, TGSI_SWIZZLE_X ), + pass, fail)) + return FALSE; + + /* Reassign the input_map to the actual front-face color: + */ + emit->input_map[emit->internal_frontface_idx] = src(temp); + + return TRUE; +} + +static INLINE boolean +needs_to_create_zero( struct svga_shader_emitter *emit ) +{ + int i; + + if (emit->unit == PIPE_SHADER_FRAGMENT) { + if (!emit->use_sm30) + return TRUE; + + if (emit->key.fkey.light_twoside) + return TRUE; + + if (emit->key.fkey.white_fragments) + return TRUE; + + if (emit->emit_frontface) + return TRUE; + + if (emit->info.opcode_count[TGSI_OPCODE_DST] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_LIT] >= 1) + return TRUE; + } + + if (emit->unit == PIPE_SHADER_VERTEX) { + if (emit->info.opcode_count[TGSI_OPCODE_CMP] >= 1) + return TRUE; + } + + if (emit->info.opcode_count[TGSI_OPCODE_IF] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_BGNLOOP] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_DDX] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_DDY] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_SGE] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_SGT] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_SLE] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_SLT] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_SNE] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_SEQ] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_EXP] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_LOG] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_XPD] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_KILP] >= 1) + return TRUE; + + for (i = 0; i < emit->key.fkey.num_textures; i++) { + if (emit->key.fkey.tex[i].compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) + return TRUE; + } + + return FALSE; +} + +static INLINE boolean +needs_to_create_loop_const( struct svga_shader_emitter *emit ) +{ + return (emit->info.opcode_count[TGSI_OPCODE_BGNLOOP] >= 1); +} + +static INLINE boolean +needs_to_create_sincos_consts( struct svga_shader_emitter *emit ) +{ + return !emit->use_sm30 && (emit->info.opcode_count[TGSI_OPCODE_SIN] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_COS] >= 1 || + emit->info.opcode_count[TGSI_OPCODE_SCS] >= 1); +} + +static INLINE boolean +needs_to_create_arl_consts( struct svga_shader_emitter *emit ) +{ + return (emit->num_arl_consts > 0); +} + +static INLINE boolean +pre_parse_add_indirect( struct svga_shader_emitter *emit, + int num, int current_arl) +{ + int i; + assert(num < 0); + + for (i = 0; i < emit->num_arl_consts; ++i) { + if (emit->arl_consts[i].arl_num == current_arl) + break; + } + /* new entry */ + if (emit->num_arl_consts == i) { + ++emit->num_arl_consts; + } + emit->arl_consts[i].number = (emit->arl_consts[i].number > num) ? + num : + emit->arl_consts[i].number; + emit->arl_consts[i].arl_num = current_arl; + return TRUE; +} + +static boolean +pre_parse_instruction( struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn, + int current_arl) +{ + if (insn->Src[0].Register.Indirect && + insn->Src[0].Indirect.File == TGSI_FILE_ADDRESS) { + const struct tgsi_full_src_register *reg = &insn->Src[0]; + if (reg->Register.Index < 0) { + pre_parse_add_indirect(emit, reg->Register.Index, current_arl); + } + } + + if (insn->Src[1].Register.Indirect && + insn->Src[1].Indirect.File == TGSI_FILE_ADDRESS) { + const struct tgsi_full_src_register *reg = &insn->Src[1]; + if (reg->Register.Index < 0) { + pre_parse_add_indirect(emit, reg->Register.Index, current_arl); + } + } + + if (insn->Src[2].Register.Indirect && + insn->Src[2].Indirect.File == TGSI_FILE_ADDRESS) { + const struct tgsi_full_src_register *reg = &insn->Src[2]; + if (reg->Register.Index < 0) { + pre_parse_add_indirect(emit, reg->Register.Index, current_arl); + } + } + + return TRUE; +} + +static boolean +pre_parse_tokens( struct svga_shader_emitter *emit, + const struct tgsi_token *tokens ) +{ + struct tgsi_parse_context parse; + int current_arl = 0; + + tgsi_parse_init( &parse, tokens ); + + while (!tgsi_parse_end_of_tokens( &parse )) { + tgsi_parse_token( &parse ); + switch (parse.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_IMMEDIATE: + case TGSI_TOKEN_TYPE_DECLARATION: + break; + case TGSI_TOKEN_TYPE_INSTRUCTION: + if (parse.FullToken.FullInstruction.Instruction.Opcode == + TGSI_OPCODE_ARL) { + ++current_arl; + } + if (!pre_parse_instruction( emit, &parse.FullToken.FullInstruction, + current_arl )) + return FALSE; + break; + default: + break; + } + + } + return TRUE; +} + +static boolean svga_shader_emit_helpers( struct svga_shader_emitter *emit ) + +{ + if (needs_to_create_zero( emit )) { + create_zero_immediate( emit ); + } + if (needs_to_create_loop_const( emit )) { + create_loop_const( emit ); + } + if (needs_to_create_sincos_consts( emit )) { + create_sincos_consts( emit ); + } + if (needs_to_create_arl_consts( emit )) { + create_arl_consts( emit ); + } + + if (emit->unit == PIPE_SHADER_FRAGMENT) { + if (!emit_ps_preamble( emit )) + return FALSE; + + if (emit->key.fkey.light_twoside) { + if (!emit_light_twoside( emit )) + return FALSE; + } + if (emit->emit_frontface) { + if (!emit_frontface( emit )) + return FALSE; + } + } + + return TRUE; +} + +boolean svga_shader_emit_instructions( struct svga_shader_emitter *emit, + const struct tgsi_token *tokens ) +{ + struct tgsi_parse_context parse; + boolean ret = TRUE; + boolean helpers_emitted = FALSE; + unsigned line_nr = 0; + + tgsi_parse_init( &parse, tokens ); + emit->internal_imm_count = 0; + + if (emit->unit == PIPE_SHADER_VERTEX) { + ret = emit_vs_preamble( emit ); + if (!ret) + goto done; + } + + pre_parse_tokens(emit, tokens); + + while (!tgsi_parse_end_of_tokens( &parse )) { + tgsi_parse_token( &parse ); + + switch (parse.FullToken.Token.Type) { + case TGSI_TOKEN_TYPE_IMMEDIATE: + ret = svga_emit_immediate( emit, &parse.FullToken.FullImmediate ); + if (!ret) + goto done; + break; + + case TGSI_TOKEN_TYPE_DECLARATION: + if (emit->use_sm30) + ret = svga_translate_decl_sm30( emit, &parse.FullToken.FullDeclaration ); + else + ret = svga_translate_decl_sm20( emit, &parse.FullToken.FullDeclaration ); + if (!ret) + goto done; + break; + + case TGSI_TOKEN_TYPE_INSTRUCTION: + if (!helpers_emitted) { + if (!svga_shader_emit_helpers( emit )) + goto done; + helpers_emitted = TRUE; + } + ret = svga_emit_instruction( emit, + line_nr++, + &parse.FullToken.FullInstruction ); + if (!ret) + goto done; + break; + default: + break; + } + + reset_temp_regs( emit ); + } + + /* Need to terminate the current subroutine. Note that the + * hardware doesn't tolerate shaders without sub-routines + * terminating with RET+END. + */ + if (!emit->in_main_func) { + ret = emit_instruction( emit, inst_token( SVGA3DOP_RET ) ); + if (!ret) + goto done; + } + + assert(emit->dynamic_branching_level == 0); + + /* Need to terminate the whole shader: + */ + ret = emit_instruction( emit, inst_token( SVGA3DOP_END ) ); + if (!ret) + goto done; + +done: + assert(ret); + tgsi_parse_free( &parse ); + return ret; +} + diff --git a/src/gallium/drivers/svga/svga_winsys.h b/src/gallium/drivers/svga/svga_winsys.h new file mode 100644 index 0000000..5e4bdef --- /dev/null +++ b/src/gallium/drivers/svga/svga_winsys.h @@ -0,0 +1,305 @@ +/********************************************************** + * 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 + * VMware SVGA specific winsys interface. + * + * @author Jose Fonseca + * + * Documentation taken from the VMware SVGA DDK. + */ + +#ifndef SVGA_WINSYS_H_ +#define SVGA_WINSYS_H_ + + +#include "svga_types.h" +#include "svga_reg.h" +#include "svga3d_reg.h" + +#include "pipe/p_compiler.h" +#include "pipe/p_defines.h" + + +struct svga_winsys_screen; +struct svga_winsys_buffer; +struct pipe_screen; +struct pipe_context; +struct pipe_fence_handle; +struct pipe_resource; +struct svga_region; +struct winsys_handle; + + +#define SVGA_BUFFER_USAGE_PINNED (1 << 0) +#define SVGA_BUFFER_USAGE_WRAPPED (1 << 1) + + +#define SVGA_RELOC_WRITE 0x1 +#define SVGA_RELOC_READ 0x2 + + + +/** Opaque surface handle */ +struct svga_winsys_surface; + +/** Opaque buffer handle */ +struct svga_winsys_handle; + + +/** + * SVGA per-context winsys interface. + */ +struct svga_winsys_context +{ + void + (*destroy)(struct svga_winsys_context *swc); + + void * + (*reserve)(struct svga_winsys_context *swc, + uint32_t nr_bytes, uint32_t nr_relocs ); + + /** + * Emit a relocation for a host surface. + * + * @param flags bitmask of SVGA_RELOC_* flags + * + * NOTE: Order of this call does matter. It should be the same order + * as relocations appear in the command buffer. + */ + void + (*surface_relocation)(struct svga_winsys_context *swc, + uint32 *sid, + struct svga_winsys_surface *surface, + unsigned flags); + + /** + * Emit a relocation for a guest memory region. + * + * @param flags bitmask of SVGA_RELOC_* flags + * + * NOTE: Order of this call does matter. It should be the same order + * as relocations appear in the command buffer. + */ + void + (*region_relocation)(struct svga_winsys_context *swc, + struct SVGAGuestPtr *ptr, + struct svga_winsys_buffer *buffer, + uint32 offset, + unsigned flags); + + void + (*commit)(struct svga_winsys_context *swc); + + enum pipe_error + (*flush)(struct svga_winsys_context *swc, + struct pipe_fence_handle **pfence); + + /** + * Context ID used to fill in the commands + * + * Context IDs are arbitrary small non-negative integers, + * global to the entire SVGA device. + */ + uint32 cid; +}; + + +/** + * SVGA per-screen winsys interface. + */ +struct svga_winsys_screen +{ + void + (*destroy)(struct svga_winsys_screen *sws); + + boolean + (*get_cap)(struct svga_winsys_screen *sws, + SVGA3dDevCapIndex index, + SVGA3dDevCapResult *result); + + /** + * Create a new context. + * + * Context objects encapsulate all render state, and shader + * objects are per-context. + * + * Surfaces are not per-context. The same surface can be shared + * between multiple contexts, and surface operations can occur + * without a context. + */ + struct svga_winsys_context * + (*context_create)(struct svga_winsys_screen *sws); + + + /** + * This creates a "surface" object in the SVGA3D device, + * and returns the surface ID (sid). Surfaces are generic + * containers for host VRAM objects like textures, vertex + * buffers, and depth/stencil buffers. + * + * Surfaces are hierarchial: + * + * - Surface may have multiple faces (for cube maps) + * + * - Each face has a list of mipmap levels + * + * - Each mipmap image may have multiple volume + * slices, if the image is three dimensional. + * + * - Each slice is a 2D array of 'blocks' + * + * - Each block may be one or more pixels. + * (Usually 1, more for DXT or YUV formats.) + * + * Surfaces are generic host VRAM objects. The SVGA3D device + * may optimize surfaces according to the format they were + * created with, but this format does not limit the ways in + * which the surface may be used. For example, a depth surface + * can be used as a texture, or a floating point image may + * be used as a vertex buffer. Some surface usages may be + * lower performance, due to software emulation, but any + * usage should work with any surface. + */ + struct svga_winsys_surface * + (*surface_create)(struct svga_winsys_screen *sws, + SVGA3dSurfaceFlags flags, + SVGA3dSurfaceFormat format, + SVGA3dSize size, + uint32 numFaces, + uint32 numMipLevels); + + /** + * Creates a surface from a winsys handle. + * Used to implement pipe_screen::resource_from_handle. + */ + struct svga_winsys_surface * + (*surface_from_handle)(struct svga_winsys_screen *sws, + struct winsys_handle *whandle, + SVGA3dSurfaceFormat *format); + + /** + * Get a winsys_handle from a surface. + * Used to implement pipe_screen::resource_get_handle. + */ + boolean + (*surface_get_handle)(struct svga_winsys_screen *sws, + struct svga_winsys_surface *surface, + unsigned stride, + struct winsys_handle *whandle); + + /** + * Whether this surface is sitting in a validate list + */ + boolean + (*surface_is_flushed)(struct svga_winsys_screen *sws, + struct svga_winsys_surface *surface); + + /** + * Reference a SVGA3D surface object. This allows sharing of a + * surface between different objects. + */ + void + (*surface_reference)(struct svga_winsys_screen *sws, + struct svga_winsys_surface **pdst, + struct svga_winsys_surface *src); + + /** + * Buffer management. Buffer attributes are mostly fixed over its lifetime. + * + * @param usage bitmask of SVGA_BUFFER_USAGE_* flags. + * + * alignment indicates the client's alignment requirements, eg for + * SSE instructions. + */ + struct svga_winsys_buffer * + (*buffer_create)( struct svga_winsys_screen *sws, + unsigned alignment, + unsigned usage, + unsigned size ); + + /** + * Map the entire data store of a buffer object into the client's address. + * flags is a bitmaks of PIPE_TRANSFER_* + */ + void * + (*buffer_map)( struct svga_winsys_screen *sws, + struct svga_winsys_buffer *buf, + unsigned flags ); + + void + (*buffer_unmap)( struct svga_winsys_screen *sws, + struct svga_winsys_buffer *buf ); + + void + (*buffer_destroy)( struct svga_winsys_screen *sws, + struct svga_winsys_buffer *buf ); + + + /** + * Reference a fence object. + */ + void + (*fence_reference)( struct svga_winsys_screen *sws, + struct pipe_fence_handle **pdst, + struct pipe_fence_handle *src ); + + /** + * Checks whether the fence has been signalled. + * \param flags driver-specific meaning + * \return zero on success. + */ + int (*fence_signalled)( struct svga_winsys_screen *sws, + struct pipe_fence_handle *fence, + unsigned flag ); + + /** + * Wait for the fence to finish. + * \param flags driver-specific meaning + * \return zero on success. + */ + int (*fence_finish)( struct svga_winsys_screen *sws, + struct pipe_fence_handle *fence, + unsigned flag ); + +}; + + +struct svga_winsys_screen * +svga_winsys_screen(struct pipe_screen *screen); + +struct svga_winsys_context * +svga_winsys_context(struct pipe_context *context); + +struct pipe_resource * +svga_screen_buffer_wrap_surface(struct pipe_screen *screen, + enum SVGA3dSurfaceFormat format, + struct svga_winsys_surface *srf); + +struct svga_winsys_surface * +svga_screen_buffer_get_winsys_surface(struct pipe_resource *buffer); + +#endif /* SVGA_WINSYS_H_ */ diff --git a/src/gallium/drivers/svga/svgadump/svga_dump.c b/src/gallium/drivers/svga/svgadump/svga_dump.c new file mode 100644 index 0000000..d59fb89 --- /dev/null +++ b/src/gallium/drivers/svga/svgadump/svga_dump.c @@ -0,0 +1,1784 @@ +/********************************************************** + * 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 + * Dump SVGA commands. + * + * Generated automatically from svga3d_reg.h by svga_dump.py. + */ + +#include "svga_types.h" +#include "svga_shader_dump.h" +#include "svga3d_reg.h" + +#include "util/u_debug.h" +#include "svga_dump.h" + +static void +dump_SVGA3dVertexDecl(const SVGA3dVertexDecl *cmd) +{ + switch((*cmd).identity.type) { + case SVGA3D_DECLTYPE_FLOAT1: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_FLOAT1\n"); + break; + case SVGA3D_DECLTYPE_FLOAT2: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_FLOAT2\n"); + break; + case SVGA3D_DECLTYPE_FLOAT3: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_FLOAT3\n"); + break; + case SVGA3D_DECLTYPE_FLOAT4: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_FLOAT4\n"); + break; + case SVGA3D_DECLTYPE_D3DCOLOR: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_D3DCOLOR\n"); + break; + case SVGA3D_DECLTYPE_UBYTE4: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_UBYTE4\n"); + break; + case SVGA3D_DECLTYPE_SHORT2: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_SHORT2\n"); + break; + case SVGA3D_DECLTYPE_SHORT4: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_SHORT4\n"); + break; + case SVGA3D_DECLTYPE_UBYTE4N: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_UBYTE4N\n"); + break; + case SVGA3D_DECLTYPE_SHORT2N: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_SHORT2N\n"); + break; + case SVGA3D_DECLTYPE_SHORT4N: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_SHORT4N\n"); + break; + case SVGA3D_DECLTYPE_USHORT2N: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_USHORT2N\n"); + break; + case SVGA3D_DECLTYPE_USHORT4N: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_USHORT4N\n"); + break; + case SVGA3D_DECLTYPE_UDEC3: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_UDEC3\n"); + break; + case SVGA3D_DECLTYPE_DEC3N: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_DEC3N\n"); + break; + case SVGA3D_DECLTYPE_FLOAT16_2: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_FLOAT16_2\n"); + break; + case SVGA3D_DECLTYPE_FLOAT16_4: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_FLOAT16_4\n"); + break; + case SVGA3D_DECLTYPE_MAX: + _debug_printf("\t\t.identity.type = SVGA3D_DECLTYPE_MAX\n"); + break; + default: + _debug_printf("\t\t.identity.type = %i\n", (*cmd).identity.type); + break; + } + switch((*cmd).identity.method) { + case SVGA3D_DECLMETHOD_DEFAULT: + _debug_printf("\t\t.identity.method = SVGA3D_DECLMETHOD_DEFAULT\n"); + break; + case SVGA3D_DECLMETHOD_PARTIALU: + _debug_printf("\t\t.identity.method = SVGA3D_DECLMETHOD_PARTIALU\n"); + break; + case SVGA3D_DECLMETHOD_PARTIALV: + _debug_printf("\t\t.identity.method = SVGA3D_DECLMETHOD_PARTIALV\n"); + break; + case SVGA3D_DECLMETHOD_CROSSUV: + _debug_printf("\t\t.identity.method = SVGA3D_DECLMETHOD_CROSSUV\n"); + break; + case SVGA3D_DECLMETHOD_UV: + _debug_printf("\t\t.identity.method = SVGA3D_DECLMETHOD_UV\n"); + break; + case SVGA3D_DECLMETHOD_LOOKUP: + _debug_printf("\t\t.identity.method = SVGA3D_DECLMETHOD_LOOKUP\n"); + break; + case SVGA3D_DECLMETHOD_LOOKUPPRESAMPLED: + _debug_printf("\t\t.identity.method = SVGA3D_DECLMETHOD_LOOKUPPRESAMPLED\n"); + break; + default: + _debug_printf("\t\t.identity.method = %i\n", (*cmd).identity.method); + break; + } + switch((*cmd).identity.usage) { + case SVGA3D_DECLUSAGE_POSITION: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_POSITION\n"); + break; + case SVGA3D_DECLUSAGE_BLENDWEIGHT: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_BLENDWEIGHT\n"); + break; + case SVGA3D_DECLUSAGE_BLENDINDICES: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_BLENDINDICES\n"); + break; + case SVGA3D_DECLUSAGE_NORMAL: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_NORMAL\n"); + break; + case SVGA3D_DECLUSAGE_PSIZE: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_PSIZE\n"); + break; + case SVGA3D_DECLUSAGE_TEXCOORD: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_TEXCOORD\n"); + break; + case SVGA3D_DECLUSAGE_TANGENT: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_TANGENT\n"); + break; + case SVGA3D_DECLUSAGE_BINORMAL: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_BINORMAL\n"); + break; + case SVGA3D_DECLUSAGE_TESSFACTOR: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_TESSFACTOR\n"); + break; + case SVGA3D_DECLUSAGE_POSITIONT: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_POSITIONT\n"); + break; + case SVGA3D_DECLUSAGE_COLOR: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_COLOR\n"); + break; + case SVGA3D_DECLUSAGE_FOG: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_FOG\n"); + break; + case SVGA3D_DECLUSAGE_DEPTH: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_DEPTH\n"); + break; + case SVGA3D_DECLUSAGE_SAMPLE: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_SAMPLE\n"); + break; + case SVGA3D_DECLUSAGE_MAX: + _debug_printf("\t\t.identity.usage = SVGA3D_DECLUSAGE_MAX\n"); + break; + default: + _debug_printf("\t\t.identity.usage = %i\n", (*cmd).identity.usage); + break; + } + _debug_printf("\t\t.identity.usageIndex = %u\n", (*cmd).identity.usageIndex); + _debug_printf("\t\t.array.surfaceId = %u\n", (*cmd).array.surfaceId); + _debug_printf("\t\t.array.offset = %u\n", (*cmd).array.offset); + _debug_printf("\t\t.array.stride = %u\n", (*cmd).array.stride); + _debug_printf("\t\t.rangeHint.first = %u\n", (*cmd).rangeHint.first); + _debug_printf("\t\t.rangeHint.last = %u\n", (*cmd).rangeHint.last); +} + +static void +dump_SVGA3dTextureState(const SVGA3dTextureState *cmd) +{ + _debug_printf("\t\t.stage = %u\n", (*cmd).stage); + switch((*cmd).name) { + case SVGA3D_TS_INVALID: + _debug_printf("\t\t.name = SVGA3D_TS_INVALID\n"); + break; + case SVGA3D_TS_BIND_TEXTURE: + _debug_printf("\t\t.name = SVGA3D_TS_BIND_TEXTURE\n"); + break; + case SVGA3D_TS_COLOROP: + _debug_printf("\t\t.name = SVGA3D_TS_COLOROP\n"); + break; + case SVGA3D_TS_COLORARG1: + _debug_printf("\t\t.name = SVGA3D_TS_COLORARG1\n"); + break; + case SVGA3D_TS_COLORARG2: + _debug_printf("\t\t.name = SVGA3D_TS_COLORARG2\n"); + break; + case SVGA3D_TS_ALPHAOP: + _debug_printf("\t\t.name = SVGA3D_TS_ALPHAOP\n"); + break; + case SVGA3D_TS_ALPHAARG1: + _debug_printf("\t\t.name = SVGA3D_TS_ALPHAARG1\n"); + break; + case SVGA3D_TS_ALPHAARG2: + _debug_printf("\t\t.name = SVGA3D_TS_ALPHAARG2\n"); + break; + case SVGA3D_TS_ADDRESSU: + _debug_printf("\t\t.name = SVGA3D_TS_ADDRESSU\n"); + break; + case SVGA3D_TS_ADDRESSV: + _debug_printf("\t\t.name = SVGA3D_TS_ADDRESSV\n"); + break; + case SVGA3D_TS_MIPFILTER: + _debug_printf("\t\t.name = SVGA3D_TS_MIPFILTER\n"); + break; + case SVGA3D_TS_MAGFILTER: + _debug_printf("\t\t.name = SVGA3D_TS_MAGFILTER\n"); + break; + case SVGA3D_TS_MINFILTER: + _debug_printf("\t\t.name = SVGA3D_TS_MINFILTER\n"); + break; + case SVGA3D_TS_BORDERCOLOR: + _debug_printf("\t\t.name = SVGA3D_TS_BORDERCOLOR\n"); + break; + case SVGA3D_TS_TEXCOORDINDEX: + _debug_printf("\t\t.name = SVGA3D_TS_TEXCOORDINDEX\n"); + break; + case SVGA3D_TS_TEXTURETRANSFORMFLAGS: + _debug_printf("\t\t.name = SVGA3D_TS_TEXTURETRANSFORMFLAGS\n"); + break; + case SVGA3D_TS_TEXCOORDGEN: + _debug_printf("\t\t.name = SVGA3D_TS_TEXCOORDGEN\n"); + break; + case SVGA3D_TS_BUMPENVMAT00: + _debug_printf("\t\t.name = SVGA3D_TS_BUMPENVMAT00\n"); + break; + case SVGA3D_TS_BUMPENVMAT01: + _debug_printf("\t\t.name = SVGA3D_TS_BUMPENVMAT01\n"); + break; + case SVGA3D_TS_BUMPENVMAT10: + _debug_printf("\t\t.name = SVGA3D_TS_BUMPENVMAT10\n"); + break; + case SVGA3D_TS_BUMPENVMAT11: + _debug_printf("\t\t.name = SVGA3D_TS_BUMPENVMAT11\n"); + break; + case SVGA3D_TS_TEXTURE_MIPMAP_LEVEL: + _debug_printf("\t\t.name = SVGA3D_TS_TEXTURE_MIPMAP_LEVEL\n"); + break; + case SVGA3D_TS_TEXTURE_LOD_BIAS: + _debug_printf("\t\t.name = SVGA3D_TS_TEXTURE_LOD_BIAS\n"); + break; + case SVGA3D_TS_TEXTURE_ANISOTROPIC_LEVEL: + _debug_printf("\t\t.name = SVGA3D_TS_TEXTURE_ANISOTROPIC_LEVEL\n"); + break; + case SVGA3D_TS_ADDRESSW: + _debug_printf("\t\t.name = SVGA3D_TS_ADDRESSW\n"); + break; + case SVGA3D_TS_GAMMA: + _debug_printf("\t\t.name = SVGA3D_TS_GAMMA\n"); + break; + case SVGA3D_TS_BUMPENVLSCALE: + _debug_printf("\t\t.name = SVGA3D_TS_BUMPENVLSCALE\n"); + break; + case SVGA3D_TS_BUMPENVLOFFSET: + _debug_printf("\t\t.name = SVGA3D_TS_BUMPENVLOFFSET\n"); + break; + case SVGA3D_TS_COLORARG0: + _debug_printf("\t\t.name = SVGA3D_TS_COLORARG0\n"); + break; + case SVGA3D_TS_ALPHAARG0: + _debug_printf("\t\t.name = SVGA3D_TS_ALPHAARG0\n"); + break; + case SVGA3D_TS_MAX: + _debug_printf("\t\t.name = SVGA3D_TS_MAX\n"); + break; + default: + _debug_printf("\t\t.name = %i\n", (*cmd).name); + break; + } + _debug_printf("\t\t.value = %u\n", (*cmd).value); + _debug_printf("\t\t.floatValue = %f\n", (*cmd).floatValue); +} + +static void +dump_SVGA3dCopyBox(const SVGA3dCopyBox *cmd) +{ + _debug_printf("\t\t.x = %u\n", (*cmd).x); + _debug_printf("\t\t.y = %u\n", (*cmd).y); + _debug_printf("\t\t.z = %u\n", (*cmd).z); + _debug_printf("\t\t.w = %u\n", (*cmd).w); + _debug_printf("\t\t.h = %u\n", (*cmd).h); + _debug_printf("\t\t.d = %u\n", (*cmd).d); + _debug_printf("\t\t.srcx = %u\n", (*cmd).srcx); + _debug_printf("\t\t.srcy = %u\n", (*cmd).srcy); + _debug_printf("\t\t.srcz = %u\n", (*cmd).srcz); +} + +static void +dump_SVGA3dCmdSetClipPlane(const SVGA3dCmdSetClipPlane *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + _debug_printf("\t\t.index = %u\n", (*cmd).index); + _debug_printf("\t\t.plane[0] = %f\n", (*cmd).plane[0]); + _debug_printf("\t\t.plane[1] = %f\n", (*cmd).plane[1]); + _debug_printf("\t\t.plane[2] = %f\n", (*cmd).plane[2]); + _debug_printf("\t\t.plane[3] = %f\n", (*cmd).plane[3]); +} + +static void +dump_SVGA3dCmdWaitForQuery(const SVGA3dCmdWaitForQuery *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + switch((*cmd).type) { + case SVGA3D_QUERYTYPE_OCCLUSION: + _debug_printf("\t\t.type = SVGA3D_QUERYTYPE_OCCLUSION\n"); + break; + case SVGA3D_QUERYTYPE_MAX: + _debug_printf("\t\t.type = SVGA3D_QUERYTYPE_MAX\n"); + break; + default: + _debug_printf("\t\t.type = %i\n", (*cmd).type); + break; + } + _debug_printf("\t\t.guestResult.gmrId = %u\n", (*cmd).guestResult.gmrId); + _debug_printf("\t\t.guestResult.offset = %u\n", (*cmd).guestResult.offset); +} + +static void +dump_SVGA3dCmdSetRenderTarget(const SVGA3dCmdSetRenderTarget *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + switch((*cmd).type) { + case SVGA3D_RT_DEPTH: + _debug_printf("\t\t.type = SVGA3D_RT_DEPTH\n"); + break; + case SVGA3D_RT_STENCIL: + _debug_printf("\t\t.type = SVGA3D_RT_STENCIL\n"); + break; + default: + _debug_printf("\t\t.type = SVGA3D_RT_COLOR%u\n", (*cmd).type - SVGA3D_RT_COLOR0); + break; + } + _debug_printf("\t\t.target.sid = %u\n", (*cmd).target.sid); + _debug_printf("\t\t.target.face = %u\n", (*cmd).target.face); + _debug_printf("\t\t.target.mipmap = %u\n", (*cmd).target.mipmap); +} + +static void +dump_SVGA3dCmdSetTextureState(const SVGA3dCmdSetTextureState *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); +} + +static void +dump_SVGA3dCmdSurfaceCopy(const SVGA3dCmdSurfaceCopy *cmd) +{ + _debug_printf("\t\t.src.sid = %u\n", (*cmd).src.sid); + _debug_printf("\t\t.src.face = %u\n", (*cmd).src.face); + _debug_printf("\t\t.src.mipmap = %u\n", (*cmd).src.mipmap); + _debug_printf("\t\t.dest.sid = %u\n", (*cmd).dest.sid); + _debug_printf("\t\t.dest.face = %u\n", (*cmd).dest.face); + _debug_printf("\t\t.dest.mipmap = %u\n", (*cmd).dest.mipmap); +} + +static void +dump_SVGA3dCmdSetMaterial(const SVGA3dCmdSetMaterial *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + switch((*cmd).face) { + case SVGA3D_FACE_INVALID: + _debug_printf("\t\t.face = SVGA3D_FACE_INVALID\n"); + break; + case SVGA3D_FACE_NONE: + _debug_printf("\t\t.face = SVGA3D_FACE_NONE\n"); + break; + case SVGA3D_FACE_FRONT: + _debug_printf("\t\t.face = SVGA3D_FACE_FRONT\n"); + break; + case SVGA3D_FACE_BACK: + _debug_printf("\t\t.face = SVGA3D_FACE_BACK\n"); + break; + case SVGA3D_FACE_FRONT_BACK: + _debug_printf("\t\t.face = SVGA3D_FACE_FRONT_BACK\n"); + break; + case SVGA3D_FACE_MAX: + _debug_printf("\t\t.face = SVGA3D_FACE_MAX\n"); + break; + default: + _debug_printf("\t\t.face = %i\n", (*cmd).face); + break; + } + _debug_printf("\t\t.material.diffuse[0] = %f\n", (*cmd).material.diffuse[0]); + _debug_printf("\t\t.material.diffuse[1] = %f\n", (*cmd).material.diffuse[1]); + _debug_printf("\t\t.material.diffuse[2] = %f\n", (*cmd).material.diffuse[2]); + _debug_printf("\t\t.material.diffuse[3] = %f\n", (*cmd).material.diffuse[3]); + _debug_printf("\t\t.material.ambient[0] = %f\n", (*cmd).material.ambient[0]); + _debug_printf("\t\t.material.ambient[1] = %f\n", (*cmd).material.ambient[1]); + _debug_printf("\t\t.material.ambient[2] = %f\n", (*cmd).material.ambient[2]); + _debug_printf("\t\t.material.ambient[3] = %f\n", (*cmd).material.ambient[3]); + _debug_printf("\t\t.material.specular[0] = %f\n", (*cmd).material.specular[0]); + _debug_printf("\t\t.material.specular[1] = %f\n", (*cmd).material.specular[1]); + _debug_printf("\t\t.material.specular[2] = %f\n", (*cmd).material.specular[2]); + _debug_printf("\t\t.material.specular[3] = %f\n", (*cmd).material.specular[3]); + _debug_printf("\t\t.material.emissive[0] = %f\n", (*cmd).material.emissive[0]); + _debug_printf("\t\t.material.emissive[1] = %f\n", (*cmd).material.emissive[1]); + _debug_printf("\t\t.material.emissive[2] = %f\n", (*cmd).material.emissive[2]); + _debug_printf("\t\t.material.emissive[3] = %f\n", (*cmd).material.emissive[3]); + _debug_printf("\t\t.material.shininess = %f\n", (*cmd).material.shininess); +} + +static void +dump_SVGA3dCmdSetLightData(const SVGA3dCmdSetLightData *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + _debug_printf("\t\t.index = %u\n", (*cmd).index); + switch((*cmd).data.type) { + case SVGA3D_LIGHTTYPE_INVALID: + _debug_printf("\t\t.data.type = SVGA3D_LIGHTTYPE_INVALID\n"); + break; + case SVGA3D_LIGHTTYPE_POINT: + _debug_printf("\t\t.data.type = SVGA3D_LIGHTTYPE_POINT\n"); + break; + case SVGA3D_LIGHTTYPE_SPOT1: + _debug_printf("\t\t.data.type = SVGA3D_LIGHTTYPE_SPOT1\n"); + break; + case SVGA3D_LIGHTTYPE_SPOT2: + _debug_printf("\t\t.data.type = SVGA3D_LIGHTTYPE_SPOT2\n"); + break; + case SVGA3D_LIGHTTYPE_DIRECTIONAL: + _debug_printf("\t\t.data.type = SVGA3D_LIGHTTYPE_DIRECTIONAL\n"); + break; + case SVGA3D_LIGHTTYPE_MAX: + _debug_printf("\t\t.data.type = SVGA3D_LIGHTTYPE_MAX\n"); + break; + default: + _debug_printf("\t\t.data.type = %i\n", (*cmd).data.type); + break; + } + _debug_printf("\t\t.data.inWorldSpace = %u\n", (*cmd).data.inWorldSpace); + _debug_printf("\t\t.data.diffuse[0] = %f\n", (*cmd).data.diffuse[0]); + _debug_printf("\t\t.data.diffuse[1] = %f\n", (*cmd).data.diffuse[1]); + _debug_printf("\t\t.data.diffuse[2] = %f\n", (*cmd).data.diffuse[2]); + _debug_printf("\t\t.data.diffuse[3] = %f\n", (*cmd).data.diffuse[3]); + _debug_printf("\t\t.data.specular[0] = %f\n", (*cmd).data.specular[0]); + _debug_printf("\t\t.data.specular[1] = %f\n", (*cmd).data.specular[1]); + _debug_printf("\t\t.data.specular[2] = %f\n", (*cmd).data.specular[2]); + _debug_printf("\t\t.data.specular[3] = %f\n", (*cmd).data.specular[3]); + _debug_printf("\t\t.data.ambient[0] = %f\n", (*cmd).data.ambient[0]); + _debug_printf("\t\t.data.ambient[1] = %f\n", (*cmd).data.ambient[1]); + _debug_printf("\t\t.data.ambient[2] = %f\n", (*cmd).data.ambient[2]); + _debug_printf("\t\t.data.ambient[3] = %f\n", (*cmd).data.ambient[3]); + _debug_printf("\t\t.data.position[0] = %f\n", (*cmd).data.position[0]); + _debug_printf("\t\t.data.position[1] = %f\n", (*cmd).data.position[1]); + _debug_printf("\t\t.data.position[2] = %f\n", (*cmd).data.position[2]); + _debug_printf("\t\t.data.position[3] = %f\n", (*cmd).data.position[3]); + _debug_printf("\t\t.data.direction[0] = %f\n", (*cmd).data.direction[0]); + _debug_printf("\t\t.data.direction[1] = %f\n", (*cmd).data.direction[1]); + _debug_printf("\t\t.data.direction[2] = %f\n", (*cmd).data.direction[2]); + _debug_printf("\t\t.data.direction[3] = %f\n", (*cmd).data.direction[3]); + _debug_printf("\t\t.data.range = %f\n", (*cmd).data.range); + _debug_printf("\t\t.data.falloff = %f\n", (*cmd).data.falloff); + _debug_printf("\t\t.data.attenuation0 = %f\n", (*cmd).data.attenuation0); + _debug_printf("\t\t.data.attenuation1 = %f\n", (*cmd).data.attenuation1); + _debug_printf("\t\t.data.attenuation2 = %f\n", (*cmd).data.attenuation2); + _debug_printf("\t\t.data.theta = %f\n", (*cmd).data.theta); + _debug_printf("\t\t.data.phi = %f\n", (*cmd).data.phi); +} + +static void +dump_SVGA3dCmdSetViewport(const SVGA3dCmdSetViewport *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + _debug_printf("\t\t.rect.x = %u\n", (*cmd).rect.x); + _debug_printf("\t\t.rect.y = %u\n", (*cmd).rect.y); + _debug_printf("\t\t.rect.w = %u\n", (*cmd).rect.w); + _debug_printf("\t\t.rect.h = %u\n", (*cmd).rect.h); +} + +static void +dump_SVGA3dCmdSetScissorRect(const SVGA3dCmdSetScissorRect *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + _debug_printf("\t\t.rect.x = %u\n", (*cmd).rect.x); + _debug_printf("\t\t.rect.y = %u\n", (*cmd).rect.y); + _debug_printf("\t\t.rect.w = %u\n", (*cmd).rect.w); + _debug_printf("\t\t.rect.h = %u\n", (*cmd).rect.h); +} + +static void +dump_SVGA3dCopyRect(const SVGA3dCopyRect *cmd) +{ + _debug_printf("\t\t.x = %u\n", (*cmd).x); + _debug_printf("\t\t.y = %u\n", (*cmd).y); + _debug_printf("\t\t.w = %u\n", (*cmd).w); + _debug_printf("\t\t.h = %u\n", (*cmd).h); + _debug_printf("\t\t.srcx = %u\n", (*cmd).srcx); + _debug_printf("\t\t.srcy = %u\n", (*cmd).srcy); +} + +static void +dump_SVGA3dCmdSetShader(const SVGA3dCmdSetShader *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + switch((*cmd).type) { + case SVGA3D_SHADERTYPE_COMPILED_DX8: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_COMPILED_DX8\n"); + break; + case SVGA3D_SHADERTYPE_VS: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_VS\n"); + break; + case SVGA3D_SHADERTYPE_PS: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_PS\n"); + break; + case SVGA3D_SHADERTYPE_MAX: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_MAX\n"); + break; + default: + _debug_printf("\t\t.type = %i\n", (*cmd).type); + break; + } + _debug_printf("\t\t.shid = %u\n", (*cmd).shid); +} + +static void +dump_SVGA3dCmdEndQuery(const SVGA3dCmdEndQuery *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + switch((*cmd).type) { + case SVGA3D_QUERYTYPE_OCCLUSION: + _debug_printf("\t\t.type = SVGA3D_QUERYTYPE_OCCLUSION\n"); + break; + case SVGA3D_QUERYTYPE_MAX: + _debug_printf("\t\t.type = SVGA3D_QUERYTYPE_MAX\n"); + break; + default: + _debug_printf("\t\t.type = %i\n", (*cmd).type); + break; + } + _debug_printf("\t\t.guestResult.gmrId = %u\n", (*cmd).guestResult.gmrId); + _debug_printf("\t\t.guestResult.offset = %u\n", (*cmd).guestResult.offset); +} + +static void +dump_SVGA3dSize(const SVGA3dSize *cmd) +{ + _debug_printf("\t\t.width = %u\n", (*cmd).width); + _debug_printf("\t\t.height = %u\n", (*cmd).height); + _debug_printf("\t\t.depth = %u\n", (*cmd).depth); +} + +static void +dump_SVGA3dCmdDestroySurface(const SVGA3dCmdDestroySurface *cmd) +{ + _debug_printf("\t\t.sid = %u\n", (*cmd).sid); +} + +static void +dump_SVGA3dCmdDefineContext(const SVGA3dCmdDefineContext *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); +} + +static void +dump_SVGA3dRect(const SVGA3dRect *cmd) +{ + _debug_printf("\t\t.x = %u\n", (*cmd).x); + _debug_printf("\t\t.y = %u\n", (*cmd).y); + _debug_printf("\t\t.w = %u\n", (*cmd).w); + _debug_printf("\t\t.h = %u\n", (*cmd).h); +} + +static void +dump_SVGA3dCmdBeginQuery(const SVGA3dCmdBeginQuery *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + switch((*cmd).type) { + case SVGA3D_QUERYTYPE_OCCLUSION: + _debug_printf("\t\t.type = SVGA3D_QUERYTYPE_OCCLUSION\n"); + break; + case SVGA3D_QUERYTYPE_MAX: + _debug_printf("\t\t.type = SVGA3D_QUERYTYPE_MAX\n"); + break; + default: + _debug_printf("\t\t.type = %i\n", (*cmd).type); + break; + } +} + +static void +dump_SVGA3dRenderState(const SVGA3dRenderState *cmd) +{ + switch((*cmd).state) { + case SVGA3D_RS_INVALID: + _debug_printf("\t\t.state = SVGA3D_RS_INVALID\n"); + break; + case SVGA3D_RS_ZENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_ZENABLE\n"); + break; + case SVGA3D_RS_ZWRITEENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_ZWRITEENABLE\n"); + break; + case SVGA3D_RS_ALPHATESTENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_ALPHATESTENABLE\n"); + break; + case SVGA3D_RS_DITHERENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_DITHERENABLE\n"); + break; + case SVGA3D_RS_BLENDENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_BLENDENABLE\n"); + break; + case SVGA3D_RS_FOGENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_FOGENABLE\n"); + break; + case SVGA3D_RS_SPECULARENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_SPECULARENABLE\n"); + break; + case SVGA3D_RS_STENCILENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_STENCILENABLE\n"); + break; + case SVGA3D_RS_LIGHTINGENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_LIGHTINGENABLE\n"); + break; + case SVGA3D_RS_NORMALIZENORMALS: + _debug_printf("\t\t.state = SVGA3D_RS_NORMALIZENORMALS\n"); + break; + case SVGA3D_RS_POINTSPRITEENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_POINTSPRITEENABLE\n"); + break; + case SVGA3D_RS_POINTSCALEENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_POINTSCALEENABLE\n"); + break; + case SVGA3D_RS_STENCILREF: + _debug_printf("\t\t.state = SVGA3D_RS_STENCILREF\n"); + break; + case SVGA3D_RS_STENCILMASK: + _debug_printf("\t\t.state = SVGA3D_RS_STENCILMASK\n"); + break; + case SVGA3D_RS_STENCILWRITEMASK: + _debug_printf("\t\t.state = SVGA3D_RS_STENCILWRITEMASK\n"); + break; + case SVGA3D_RS_FOGSTART: + _debug_printf("\t\t.state = SVGA3D_RS_FOGSTART\n"); + break; + case SVGA3D_RS_FOGEND: + _debug_printf("\t\t.state = SVGA3D_RS_FOGEND\n"); + break; + case SVGA3D_RS_FOGDENSITY: + _debug_printf("\t\t.state = SVGA3D_RS_FOGDENSITY\n"); + break; + case SVGA3D_RS_POINTSIZE: + _debug_printf("\t\t.state = SVGA3D_RS_POINTSIZE\n"); + break; + case SVGA3D_RS_POINTSIZEMIN: + _debug_printf("\t\t.state = SVGA3D_RS_POINTSIZEMIN\n"); + break; + case SVGA3D_RS_POINTSIZEMAX: + _debug_printf("\t\t.state = SVGA3D_RS_POINTSIZEMAX\n"); + break; + case SVGA3D_RS_POINTSCALE_A: + _debug_printf("\t\t.state = SVGA3D_RS_POINTSCALE_A\n"); + break; + case SVGA3D_RS_POINTSCALE_B: + _debug_printf("\t\t.state = SVGA3D_RS_POINTSCALE_B\n"); + break; + case SVGA3D_RS_POINTSCALE_C: + _debug_printf("\t\t.state = SVGA3D_RS_POINTSCALE_C\n"); + break; + case SVGA3D_RS_FOGCOLOR: + _debug_printf("\t\t.state = SVGA3D_RS_FOGCOLOR\n"); + break; + case SVGA3D_RS_AMBIENT: + _debug_printf("\t\t.state = SVGA3D_RS_AMBIENT\n"); + break; + case SVGA3D_RS_CLIPPLANEENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_CLIPPLANEENABLE\n"); + break; + case SVGA3D_RS_FOGMODE: + _debug_printf("\t\t.state = SVGA3D_RS_FOGMODE\n"); + break; + case SVGA3D_RS_FILLMODE: + _debug_printf("\t\t.state = SVGA3D_RS_FILLMODE\n"); + break; + case SVGA3D_RS_SHADEMODE: + _debug_printf("\t\t.state = SVGA3D_RS_SHADEMODE\n"); + break; + case SVGA3D_RS_LINEPATTERN: + _debug_printf("\t\t.state = SVGA3D_RS_LINEPATTERN\n"); + break; + case SVGA3D_RS_SRCBLEND: + _debug_printf("\t\t.state = SVGA3D_RS_SRCBLEND\n"); + break; + case SVGA3D_RS_DSTBLEND: + _debug_printf("\t\t.state = SVGA3D_RS_DSTBLEND\n"); + break; + case SVGA3D_RS_BLENDEQUATION: + _debug_printf("\t\t.state = SVGA3D_RS_BLENDEQUATION\n"); + break; + case SVGA3D_RS_CULLMODE: + _debug_printf("\t\t.state = SVGA3D_RS_CULLMODE\n"); + break; + case SVGA3D_RS_ZFUNC: + _debug_printf("\t\t.state = SVGA3D_RS_ZFUNC\n"); + break; + case SVGA3D_RS_ALPHAFUNC: + _debug_printf("\t\t.state = SVGA3D_RS_ALPHAFUNC\n"); + break; + case SVGA3D_RS_STENCILFUNC: + _debug_printf("\t\t.state = SVGA3D_RS_STENCILFUNC\n"); + break; + case SVGA3D_RS_STENCILFAIL: + _debug_printf("\t\t.state = SVGA3D_RS_STENCILFAIL\n"); + break; + case SVGA3D_RS_STENCILZFAIL: + _debug_printf("\t\t.state = SVGA3D_RS_STENCILZFAIL\n"); + break; + case SVGA3D_RS_STENCILPASS: + _debug_printf("\t\t.state = SVGA3D_RS_STENCILPASS\n"); + break; + case SVGA3D_RS_ALPHAREF: + _debug_printf("\t\t.state = SVGA3D_RS_ALPHAREF\n"); + break; + case SVGA3D_RS_FRONTWINDING: + _debug_printf("\t\t.state = SVGA3D_RS_FRONTWINDING\n"); + break; + case SVGA3D_RS_COORDINATETYPE: + _debug_printf("\t\t.state = SVGA3D_RS_COORDINATETYPE\n"); + break; + case SVGA3D_RS_ZBIAS: + _debug_printf("\t\t.state = SVGA3D_RS_ZBIAS\n"); + break; + case SVGA3D_RS_RANGEFOGENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_RANGEFOGENABLE\n"); + break; + case SVGA3D_RS_COLORWRITEENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_COLORWRITEENABLE\n"); + break; + case SVGA3D_RS_VERTEXMATERIALENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_VERTEXMATERIALENABLE\n"); + break; + case SVGA3D_RS_DIFFUSEMATERIALSOURCE: + _debug_printf("\t\t.state = SVGA3D_RS_DIFFUSEMATERIALSOURCE\n"); + break; + case SVGA3D_RS_SPECULARMATERIALSOURCE: + _debug_printf("\t\t.state = SVGA3D_RS_SPECULARMATERIALSOURCE\n"); + break; + case SVGA3D_RS_AMBIENTMATERIALSOURCE: + _debug_printf("\t\t.state = SVGA3D_RS_AMBIENTMATERIALSOURCE\n"); + break; + case SVGA3D_RS_EMISSIVEMATERIALSOURCE: + _debug_printf("\t\t.state = SVGA3D_RS_EMISSIVEMATERIALSOURCE\n"); + break; + case SVGA3D_RS_TEXTUREFACTOR: + _debug_printf("\t\t.state = SVGA3D_RS_TEXTUREFACTOR\n"); + break; + case SVGA3D_RS_LOCALVIEWER: + _debug_printf("\t\t.state = SVGA3D_RS_LOCALVIEWER\n"); + break; + case SVGA3D_RS_SCISSORTESTENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_SCISSORTESTENABLE\n"); + break; + case SVGA3D_RS_BLENDCOLOR: + _debug_printf("\t\t.state = SVGA3D_RS_BLENDCOLOR\n"); + break; + case SVGA3D_RS_STENCILENABLE2SIDED: + _debug_printf("\t\t.state = SVGA3D_RS_STENCILENABLE2SIDED\n"); + break; + case SVGA3D_RS_CCWSTENCILFUNC: + _debug_printf("\t\t.state = SVGA3D_RS_CCWSTENCILFUNC\n"); + break; + case SVGA3D_RS_CCWSTENCILFAIL: + _debug_printf("\t\t.state = SVGA3D_RS_CCWSTENCILFAIL\n"); + break; + case SVGA3D_RS_CCWSTENCILZFAIL: + _debug_printf("\t\t.state = SVGA3D_RS_CCWSTENCILZFAIL\n"); + break; + case SVGA3D_RS_CCWSTENCILPASS: + _debug_printf("\t\t.state = SVGA3D_RS_CCWSTENCILPASS\n"); + break; + case SVGA3D_RS_VERTEXBLEND: + _debug_printf("\t\t.state = SVGA3D_RS_VERTEXBLEND\n"); + break; + case SVGA3D_RS_SLOPESCALEDEPTHBIAS: + _debug_printf("\t\t.state = SVGA3D_RS_SLOPESCALEDEPTHBIAS\n"); + break; + case SVGA3D_RS_DEPTHBIAS: + _debug_printf("\t\t.state = SVGA3D_RS_DEPTHBIAS\n"); + break; + case SVGA3D_RS_OUTPUTGAMMA: + _debug_printf("\t\t.state = SVGA3D_RS_OUTPUTGAMMA\n"); + break; + case SVGA3D_RS_ZVISIBLE: + _debug_printf("\t\t.state = SVGA3D_RS_ZVISIBLE\n"); + break; + case SVGA3D_RS_LASTPIXEL: + _debug_printf("\t\t.state = SVGA3D_RS_LASTPIXEL\n"); + break; + case SVGA3D_RS_CLIPPING: + _debug_printf("\t\t.state = SVGA3D_RS_CLIPPING\n"); + break; + case SVGA3D_RS_WRAP0: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP0\n"); + break; + case SVGA3D_RS_WRAP1: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP1\n"); + break; + case SVGA3D_RS_WRAP2: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP2\n"); + break; + case SVGA3D_RS_WRAP3: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP3\n"); + break; + case SVGA3D_RS_WRAP4: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP4\n"); + break; + case SVGA3D_RS_WRAP5: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP5\n"); + break; + case SVGA3D_RS_WRAP6: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP6\n"); + break; + case SVGA3D_RS_WRAP7: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP7\n"); + break; + case SVGA3D_RS_WRAP8: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP8\n"); + break; + case SVGA3D_RS_WRAP9: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP9\n"); + break; + case SVGA3D_RS_WRAP10: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP10\n"); + break; + case SVGA3D_RS_WRAP11: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP11\n"); + break; + case SVGA3D_RS_WRAP12: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP12\n"); + break; + case SVGA3D_RS_WRAP13: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP13\n"); + break; + case SVGA3D_RS_WRAP14: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP14\n"); + break; + case SVGA3D_RS_WRAP15: + _debug_printf("\t\t.state = SVGA3D_RS_WRAP15\n"); + break; + case SVGA3D_RS_MULTISAMPLEANTIALIAS: + _debug_printf("\t\t.state = SVGA3D_RS_MULTISAMPLEANTIALIAS\n"); + break; + case SVGA3D_RS_MULTISAMPLEMASK: + _debug_printf("\t\t.state = SVGA3D_RS_MULTISAMPLEMASK\n"); + break; + case SVGA3D_RS_INDEXEDVERTEXBLENDENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_INDEXEDVERTEXBLENDENABLE\n"); + break; + case SVGA3D_RS_TWEENFACTOR: + _debug_printf("\t\t.state = SVGA3D_RS_TWEENFACTOR\n"); + break; + case SVGA3D_RS_ANTIALIASEDLINEENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_ANTIALIASEDLINEENABLE\n"); + break; + case SVGA3D_RS_COLORWRITEENABLE1: + _debug_printf("\t\t.state = SVGA3D_RS_COLORWRITEENABLE1\n"); + break; + case SVGA3D_RS_COLORWRITEENABLE2: + _debug_printf("\t\t.state = SVGA3D_RS_COLORWRITEENABLE2\n"); + break; + case SVGA3D_RS_COLORWRITEENABLE3: + _debug_printf("\t\t.state = SVGA3D_RS_COLORWRITEENABLE3\n"); + break; + case SVGA3D_RS_SEPARATEALPHABLENDENABLE: + _debug_printf("\t\t.state = SVGA3D_RS_SEPARATEALPHABLENDENABLE\n"); + break; + case SVGA3D_RS_SRCBLENDALPHA: + _debug_printf("\t\t.state = SVGA3D_RS_SRCBLENDALPHA\n"); + break; + case SVGA3D_RS_DSTBLENDALPHA: + _debug_printf("\t\t.state = SVGA3D_RS_DSTBLENDALPHA\n"); + break; + case SVGA3D_RS_BLENDEQUATIONALPHA: + _debug_printf("\t\t.state = SVGA3D_RS_BLENDEQUATIONALPHA\n"); + break; + case SVGA3D_RS_MAX: + _debug_printf("\t\t.state = SVGA3D_RS_MAX\n"); + break; + default: + _debug_printf("\t\t.state = %i\n", (*cmd).state); + break; + } + _debug_printf("\t\t.uintValue = %u\n", (*cmd).uintValue); + _debug_printf("\t\t.floatValue = %f\n", (*cmd).floatValue); +} + +static void +dump_SVGA3dVertexDivisor(const SVGA3dVertexDivisor *cmd) +{ + _debug_printf("\t\t.value = %u\n", (*cmd).value); + _debug_printf("\t\t.count = %u\n", (*cmd).count); + _debug_printf("\t\t.indexedData = %u\n", (*cmd).indexedData); + _debug_printf("\t\t.instanceData = %u\n", (*cmd).instanceData); +} + +static void +dump_SVGA3dCmdDefineShader(const SVGA3dCmdDefineShader *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + _debug_printf("\t\t.shid = %u\n", (*cmd).shid); + switch((*cmd).type) { + case SVGA3D_SHADERTYPE_COMPILED_DX8: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_COMPILED_DX8\n"); + break; + case SVGA3D_SHADERTYPE_VS: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_VS\n"); + break; + case SVGA3D_SHADERTYPE_PS: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_PS\n"); + break; + case SVGA3D_SHADERTYPE_MAX: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_MAX\n"); + break; + default: + _debug_printf("\t\t.type = %i\n", (*cmd).type); + break; + } +} + +static void +dump_SVGA3dCmdSetShaderConst(const SVGA3dCmdSetShaderConst *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + _debug_printf("\t\t.reg = %u\n", (*cmd).reg); + switch((*cmd).type) { + case SVGA3D_SHADERTYPE_COMPILED_DX8: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_COMPILED_DX8\n"); + break; + case SVGA3D_SHADERTYPE_VS: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_VS\n"); + break; + case SVGA3D_SHADERTYPE_PS: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_PS\n"); + break; + case SVGA3D_SHADERTYPE_MAX: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_MAX\n"); + break; + default: + _debug_printf("\t\t.type = %i\n", (*cmd).type); + break; + } + switch((*cmd).ctype) { + case SVGA3D_CONST_TYPE_FLOAT: + _debug_printf("\t\t.ctype = SVGA3D_CONST_TYPE_FLOAT\n"); + _debug_printf("\t\t.values[0] = %f\n", *(const float *)&(*cmd).values[0]); + _debug_printf("\t\t.values[1] = %f\n", *(const float *)&(*cmd).values[1]); + _debug_printf("\t\t.values[2] = %f\n", *(const float *)&(*cmd).values[2]); + _debug_printf("\t\t.values[3] = %f\n", *(const float *)&(*cmd).values[3]); + break; + case SVGA3D_CONST_TYPE_INT: + _debug_printf("\t\t.ctype = SVGA3D_CONST_TYPE_INT\n"); + _debug_printf("\t\t.values[0] = %u\n", (*cmd).values[0]); + _debug_printf("\t\t.values[1] = %u\n", (*cmd).values[1]); + _debug_printf("\t\t.values[2] = %u\n", (*cmd).values[2]); + _debug_printf("\t\t.values[3] = %u\n", (*cmd).values[3]); + break; + case SVGA3D_CONST_TYPE_BOOL: + _debug_printf("\t\t.ctype = SVGA3D_CONST_TYPE_BOOL\n"); + _debug_printf("\t\t.values[0] = %u\n", (*cmd).values[0]); + _debug_printf("\t\t.values[1] = %u\n", (*cmd).values[1]); + _debug_printf("\t\t.values[2] = %u\n", (*cmd).values[2]); + _debug_printf("\t\t.values[3] = %u\n", (*cmd).values[3]); + break; + default: + _debug_printf("\t\t.ctype = %i\n", (*cmd).ctype); + _debug_printf("\t\t.values[0] = %u\n", (*cmd).values[0]); + _debug_printf("\t\t.values[1] = %u\n", (*cmd).values[1]); + _debug_printf("\t\t.values[2] = %u\n", (*cmd).values[2]); + _debug_printf("\t\t.values[3] = %u\n", (*cmd).values[3]); + break; + } +} + +static void +dump_SVGA3dCmdSetZRange(const SVGA3dCmdSetZRange *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + _debug_printf("\t\t.zRange.min = %f\n", (*cmd).zRange.min); + _debug_printf("\t\t.zRange.max = %f\n", (*cmd).zRange.max); +} + +static void +dump_SVGA3dCmdDrawPrimitives(const SVGA3dCmdDrawPrimitives *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + _debug_printf("\t\t.numVertexDecls = %u\n", (*cmd).numVertexDecls); + _debug_printf("\t\t.numRanges = %u\n", (*cmd).numRanges); +} + +static void +dump_SVGA3dCmdSetLightEnabled(const SVGA3dCmdSetLightEnabled *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + _debug_printf("\t\t.index = %u\n", (*cmd).index); + _debug_printf("\t\t.enabled = %u\n", (*cmd).enabled); +} + +static void +dump_SVGA3dPrimitiveRange(const SVGA3dPrimitiveRange *cmd) +{ + switch((*cmd).primType) { + case SVGA3D_PRIMITIVE_INVALID: + _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_INVALID\n"); + break; + case SVGA3D_PRIMITIVE_TRIANGLELIST: + _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_TRIANGLELIST\n"); + break; + case SVGA3D_PRIMITIVE_POINTLIST: + _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_POINTLIST\n"); + break; + case SVGA3D_PRIMITIVE_LINELIST: + _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_LINELIST\n"); + break; + case SVGA3D_PRIMITIVE_LINESTRIP: + _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_LINESTRIP\n"); + break; + case SVGA3D_PRIMITIVE_TRIANGLESTRIP: + _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_TRIANGLESTRIP\n"); + break; + case SVGA3D_PRIMITIVE_TRIANGLEFAN: + _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_TRIANGLEFAN\n"); + break; + case SVGA3D_PRIMITIVE_MAX: + _debug_printf("\t\t.primType = SVGA3D_PRIMITIVE_MAX\n"); + break; + default: + _debug_printf("\t\t.primType = %i\n", (*cmd).primType); + break; + } + _debug_printf("\t\t.primitiveCount = %u\n", (*cmd).primitiveCount); + _debug_printf("\t\t.indexArray.surfaceId = %u\n", (*cmd).indexArray.surfaceId); + _debug_printf("\t\t.indexArray.offset = %u\n", (*cmd).indexArray.offset); + _debug_printf("\t\t.indexArray.stride = %u\n", (*cmd).indexArray.stride); + _debug_printf("\t\t.indexWidth = %u\n", (*cmd).indexWidth); + _debug_printf("\t\t.indexBias = %i\n", (*cmd).indexBias); +} + +static void +dump_SVGA3dCmdPresent(const SVGA3dCmdPresent *cmd) +{ + _debug_printf("\t\t.sid = %u\n", (*cmd).sid); +} + +static void +dump_SVGA3dCmdSetRenderState(const SVGA3dCmdSetRenderState *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); +} + +static void +dump_SVGA3dCmdSurfaceStretchBlt(const SVGA3dCmdSurfaceStretchBlt *cmd) +{ + _debug_printf("\t\t.src.sid = %u\n", (*cmd).src.sid); + _debug_printf("\t\t.src.face = %u\n", (*cmd).src.face); + _debug_printf("\t\t.src.mipmap = %u\n", (*cmd).src.mipmap); + _debug_printf("\t\t.dest.sid = %u\n", (*cmd).dest.sid); + _debug_printf("\t\t.dest.face = %u\n", (*cmd).dest.face); + _debug_printf("\t\t.dest.mipmap = %u\n", (*cmd).dest.mipmap); + _debug_printf("\t\t.boxSrc.x = %u\n", (*cmd).boxSrc.x); + _debug_printf("\t\t.boxSrc.y = %u\n", (*cmd).boxSrc.y); + _debug_printf("\t\t.boxSrc.z = %u\n", (*cmd).boxSrc.z); + _debug_printf("\t\t.boxSrc.w = %u\n", (*cmd).boxSrc.w); + _debug_printf("\t\t.boxSrc.h = %u\n", (*cmd).boxSrc.h); + _debug_printf("\t\t.boxSrc.d = %u\n", (*cmd).boxSrc.d); + _debug_printf("\t\t.boxDest.x = %u\n", (*cmd).boxDest.x); + _debug_printf("\t\t.boxDest.y = %u\n", (*cmd).boxDest.y); + _debug_printf("\t\t.boxDest.z = %u\n", (*cmd).boxDest.z); + _debug_printf("\t\t.boxDest.w = %u\n", (*cmd).boxDest.w); + _debug_printf("\t\t.boxDest.h = %u\n", (*cmd).boxDest.h); + _debug_printf("\t\t.boxDest.d = %u\n", (*cmd).boxDest.d); + switch((*cmd).mode) { + case SVGA3D_STRETCH_BLT_POINT: + _debug_printf("\t\t.mode = SVGA3D_STRETCH_BLT_POINT\n"); + break; + case SVGA3D_STRETCH_BLT_LINEAR: + _debug_printf("\t\t.mode = SVGA3D_STRETCH_BLT_LINEAR\n"); + break; + case SVGA3D_STRETCH_BLT_MAX: + _debug_printf("\t\t.mode = SVGA3D_STRETCH_BLT_MAX\n"); + break; + default: + _debug_printf("\t\t.mode = %i\n", (*cmd).mode); + break; + } +} + +static void +dump_SVGA3dCmdSurfaceDMA(const SVGA3dCmdSurfaceDMA *cmd) +{ + _debug_printf("\t\t.guest.ptr.gmrId = %u\n", (*cmd).guest.ptr.gmrId); + _debug_printf("\t\t.guest.ptr.offset = %u\n", (*cmd).guest.ptr.offset); + _debug_printf("\t\t.guest.pitch = %u\n", (*cmd).guest.pitch); + _debug_printf("\t\t.host.sid = %u\n", (*cmd).host.sid); + _debug_printf("\t\t.host.face = %u\n", (*cmd).host.face); + _debug_printf("\t\t.host.mipmap = %u\n", (*cmd).host.mipmap); + switch((*cmd).transfer) { + case SVGA3D_WRITE_HOST_VRAM: + _debug_printf("\t\t.transfer = SVGA3D_WRITE_HOST_VRAM\n"); + break; + case SVGA3D_READ_HOST_VRAM: + _debug_printf("\t\t.transfer = SVGA3D_READ_HOST_VRAM\n"); + break; + default: + _debug_printf("\t\t.transfer = %i\n", (*cmd).transfer); + break; + } +} + +static void +dump_SVGA3dCmdSurfaceDMASuffix(const SVGA3dCmdSurfaceDMASuffix *cmd) +{ + _debug_printf("\t\t.suffixSize = %u\n", (*cmd).suffixSize); + _debug_printf("\t\t.maximumOffset = %u\n", (*cmd).maximumOffset); + _debug_printf("\t\t.flags.discard = %u\n", (*cmd).flags.discard); + _debug_printf("\t\t.flags.unsynchronized = %u\n", (*cmd).flags.unsynchronized); +} + +static void +dump_SVGA3dCmdSetTransform(const SVGA3dCmdSetTransform *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + switch((*cmd).type) { + case SVGA3D_TRANSFORM_INVALID: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_INVALID\n"); + break; + case SVGA3D_TRANSFORM_WORLD: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_WORLD\n"); + break; + case SVGA3D_TRANSFORM_VIEW: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_VIEW\n"); + break; + case SVGA3D_TRANSFORM_PROJECTION: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_PROJECTION\n"); + break; + case SVGA3D_TRANSFORM_TEXTURE0: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE0\n"); + break; + case SVGA3D_TRANSFORM_TEXTURE1: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE1\n"); + break; + case SVGA3D_TRANSFORM_TEXTURE2: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE2\n"); + break; + case SVGA3D_TRANSFORM_TEXTURE3: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE3\n"); + break; + case SVGA3D_TRANSFORM_TEXTURE4: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE4\n"); + break; + case SVGA3D_TRANSFORM_TEXTURE5: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE5\n"); + break; + case SVGA3D_TRANSFORM_TEXTURE6: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE6\n"); + break; + case SVGA3D_TRANSFORM_TEXTURE7: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_TEXTURE7\n"); + break; + case SVGA3D_TRANSFORM_WORLD1: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_WORLD1\n"); + break; + case SVGA3D_TRANSFORM_WORLD2: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_WORLD2\n"); + break; + case SVGA3D_TRANSFORM_WORLD3: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_WORLD3\n"); + break; + case SVGA3D_TRANSFORM_MAX: + _debug_printf("\t\t.type = SVGA3D_TRANSFORM_MAX\n"); + break; + default: + _debug_printf("\t\t.type = %i\n", (*cmd).type); + break; + } + _debug_printf("\t\t.matrix[0] = %f\n", (*cmd).matrix[0]); + _debug_printf("\t\t.matrix[1] = %f\n", (*cmd).matrix[1]); + _debug_printf("\t\t.matrix[2] = %f\n", (*cmd).matrix[2]); + _debug_printf("\t\t.matrix[3] = %f\n", (*cmd).matrix[3]); + _debug_printf("\t\t.matrix[4] = %f\n", (*cmd).matrix[4]); + _debug_printf("\t\t.matrix[5] = %f\n", (*cmd).matrix[5]); + _debug_printf("\t\t.matrix[6] = %f\n", (*cmd).matrix[6]); + _debug_printf("\t\t.matrix[7] = %f\n", (*cmd).matrix[7]); + _debug_printf("\t\t.matrix[8] = %f\n", (*cmd).matrix[8]); + _debug_printf("\t\t.matrix[9] = %f\n", (*cmd).matrix[9]); + _debug_printf("\t\t.matrix[10] = %f\n", (*cmd).matrix[10]); + _debug_printf("\t\t.matrix[11] = %f\n", (*cmd).matrix[11]); + _debug_printf("\t\t.matrix[12] = %f\n", (*cmd).matrix[12]); + _debug_printf("\t\t.matrix[13] = %f\n", (*cmd).matrix[13]); + _debug_printf("\t\t.matrix[14] = %f\n", (*cmd).matrix[14]); + _debug_printf("\t\t.matrix[15] = %f\n", (*cmd).matrix[15]); +} + +static void +dump_SVGA3dCmdDestroyShader(const SVGA3dCmdDestroyShader *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + _debug_printf("\t\t.shid = %u\n", (*cmd).shid); + switch((*cmd).type) { + case SVGA3D_SHADERTYPE_COMPILED_DX8: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_COMPILED_DX8\n"); + break; + case SVGA3D_SHADERTYPE_VS: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_VS\n"); + break; + case SVGA3D_SHADERTYPE_PS: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_PS\n"); + break; + case SVGA3D_SHADERTYPE_MAX: + _debug_printf("\t\t.type = SVGA3D_SHADERTYPE_MAX\n"); + break; + default: + _debug_printf("\t\t.type = %i\n", (*cmd).type); + break; + } +} + +static void +dump_SVGA3dCmdDestroyContext(const SVGA3dCmdDestroyContext *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); +} + +static void +dump_SVGA3dCmdClear(const SVGA3dCmdClear *cmd) +{ + _debug_printf("\t\t.cid = %u\n", (*cmd).cid); + switch((*cmd).clearFlag) { + case SVGA3D_CLEAR_COLOR: + _debug_printf("\t\t.clearFlag = SVGA3D_CLEAR_COLOR\n"); + break; + case SVGA3D_CLEAR_DEPTH: + _debug_printf("\t\t.clearFlag = SVGA3D_CLEAR_DEPTH\n"); + break; + case SVGA3D_CLEAR_STENCIL: + _debug_printf("\t\t.clearFlag = SVGA3D_CLEAR_STENCIL\n"); + break; + default: + _debug_printf("\t\t.clearFlag = %i\n", (*cmd).clearFlag); + break; + } + _debug_printf("\t\t.color = %u\n", (*cmd).color); + _debug_printf("\t\t.depth = %f\n", (*cmd).depth); + _debug_printf("\t\t.stencil = %u\n", (*cmd).stencil); +} + +static void +dump_SVGA3dCmdDefineSurface(const SVGA3dCmdDefineSurface *cmd) +{ + _debug_printf("\t\t.sid = %u\n", (*cmd).sid); + switch((*cmd).surfaceFlags) { + case SVGA3D_SURFACE_CUBEMAP: + _debug_printf("\t\t.surfaceFlags = SVGA3D_SURFACE_CUBEMAP\n"); + break; + case SVGA3D_SURFACE_HINT_STATIC: + _debug_printf("\t\t.surfaceFlags = SVGA3D_SURFACE_HINT_STATIC\n"); + break; + case SVGA3D_SURFACE_HINT_DYNAMIC: + _debug_printf("\t\t.surfaceFlags = SVGA3D_SURFACE_HINT_DYNAMIC\n"); + break; + case SVGA3D_SURFACE_HINT_INDEXBUFFER: + _debug_printf("\t\t.surfaceFlags = SVGA3D_SURFACE_HINT_INDEXBUFFER\n"); + break; + case SVGA3D_SURFACE_HINT_VERTEXBUFFER: + _debug_printf("\t\t.surfaceFlags = SVGA3D_SURFACE_HINT_VERTEXBUFFER\n"); + break; + default: + _debug_printf("\t\t.surfaceFlags = %i\n", (*cmd).surfaceFlags); + break; + } + switch((*cmd).format) { + case SVGA3D_FORMAT_INVALID: + _debug_printf("\t\t.format = SVGA3D_FORMAT_INVALID\n"); + break; + case SVGA3D_X8R8G8B8: + _debug_printf("\t\t.format = SVGA3D_X8R8G8B8\n"); + break; + case SVGA3D_A8R8G8B8: + _debug_printf("\t\t.format = SVGA3D_A8R8G8B8\n"); + break; + case SVGA3D_R5G6B5: + _debug_printf("\t\t.format = SVGA3D_R5G6B5\n"); + break; + case SVGA3D_X1R5G5B5: + _debug_printf("\t\t.format = SVGA3D_X1R5G5B5\n"); + break; + case SVGA3D_A1R5G5B5: + _debug_printf("\t\t.format = SVGA3D_A1R5G5B5\n"); + break; + case SVGA3D_A4R4G4B4: + _debug_printf("\t\t.format = SVGA3D_A4R4G4B4\n"); + break; + case SVGA3D_Z_D32: + _debug_printf("\t\t.format = SVGA3D_Z_D32\n"); + break; + case SVGA3D_Z_D16: + _debug_printf("\t\t.format = SVGA3D_Z_D16\n"); + break; + case SVGA3D_Z_D24S8: + _debug_printf("\t\t.format = SVGA3D_Z_D24S8\n"); + break; + case SVGA3D_Z_D15S1: + _debug_printf("\t\t.format = SVGA3D_Z_D15S1\n"); + break; + case SVGA3D_LUMINANCE8: + _debug_printf("\t\t.format = SVGA3D_LUMINANCE8\n"); + break; + case SVGA3D_LUMINANCE4_ALPHA4: + _debug_printf("\t\t.format = SVGA3D_LUMINANCE4_ALPHA4\n"); + break; + case SVGA3D_LUMINANCE16: + _debug_printf("\t\t.format = SVGA3D_LUMINANCE16\n"); + break; + case SVGA3D_LUMINANCE8_ALPHA8: + _debug_printf("\t\t.format = SVGA3D_LUMINANCE8_ALPHA8\n"); + break; + case SVGA3D_DXT1: + _debug_printf("\t\t.format = SVGA3D_DXT1\n"); + break; + case SVGA3D_DXT2: + _debug_printf("\t\t.format = SVGA3D_DXT2\n"); + break; + case SVGA3D_DXT3: + _debug_printf("\t\t.format = SVGA3D_DXT3\n"); + break; + case SVGA3D_DXT4: + _debug_printf("\t\t.format = SVGA3D_DXT4\n"); + break; + case SVGA3D_DXT5: + _debug_printf("\t\t.format = SVGA3D_DXT5\n"); + break; + case SVGA3D_BUMPU8V8: + _debug_printf("\t\t.format = SVGA3D_BUMPU8V8\n"); + break; + case SVGA3D_BUMPL6V5U5: + _debug_printf("\t\t.format = SVGA3D_BUMPL6V5U5\n"); + break; + case SVGA3D_BUMPX8L8V8U8: + _debug_printf("\t\t.format = SVGA3D_BUMPX8L8V8U8\n"); + break; + case SVGA3D_BUMPL8V8U8: + _debug_printf("\t\t.format = SVGA3D_BUMPL8V8U8\n"); + break; + case SVGA3D_ARGB_S10E5: + _debug_printf("\t\t.format = SVGA3D_ARGB_S10E5\n"); + break; + case SVGA3D_ARGB_S23E8: + _debug_printf("\t\t.format = SVGA3D_ARGB_S23E8\n"); + break; + case SVGA3D_A2R10G10B10: + _debug_printf("\t\t.format = SVGA3D_A2R10G10B10\n"); + break; + case SVGA3D_V8U8: + _debug_printf("\t\t.format = SVGA3D_V8U8\n"); + break; + case SVGA3D_Q8W8V8U8: + _debug_printf("\t\t.format = SVGA3D_Q8W8V8U8\n"); + break; + case SVGA3D_CxV8U8: + _debug_printf("\t\t.format = SVGA3D_CxV8U8\n"); + break; + case SVGA3D_X8L8V8U8: + _debug_printf("\t\t.format = SVGA3D_X8L8V8U8\n"); + break; + case SVGA3D_A2W10V10U10: + _debug_printf("\t\t.format = SVGA3D_A2W10V10U10\n"); + break; + case SVGA3D_ALPHA8: + _debug_printf("\t\t.format = SVGA3D_ALPHA8\n"); + break; + case SVGA3D_R_S10E5: + _debug_printf("\t\t.format = SVGA3D_R_S10E5\n"); + break; + case SVGA3D_R_S23E8: + _debug_printf("\t\t.format = SVGA3D_R_S23E8\n"); + break; + case SVGA3D_RG_S10E5: + _debug_printf("\t\t.format = SVGA3D_RG_S10E5\n"); + break; + case SVGA3D_RG_S23E8: + _debug_printf("\t\t.format = SVGA3D_RG_S23E8\n"); + break; + case SVGA3D_BUFFER: + _debug_printf("\t\t.format = SVGA3D_BUFFER\n"); + break; + case SVGA3D_Z_D24X8: + _debug_printf("\t\t.format = SVGA3D_Z_D24X8\n"); + break; + case SVGA3D_FORMAT_MAX: + _debug_printf("\t\t.format = SVGA3D_FORMAT_MAX\n"); + break; + default: + _debug_printf("\t\t.format = %i\n", (*cmd).format); + break; + } + _debug_printf("\t\t.face[0].numMipLevels = %u\n", (*cmd).face[0].numMipLevels); + _debug_printf("\t\t.face[1].numMipLevels = %u\n", (*cmd).face[1].numMipLevels); + _debug_printf("\t\t.face[2].numMipLevels = %u\n", (*cmd).face[2].numMipLevels); + _debug_printf("\t\t.face[3].numMipLevels = %u\n", (*cmd).face[3].numMipLevels); + _debug_printf("\t\t.face[4].numMipLevels = %u\n", (*cmd).face[4].numMipLevels); + _debug_printf("\t\t.face[5].numMipLevels = %u\n", (*cmd).face[5].numMipLevels); +} + +static void +dump_SVGASignedRect(const SVGASignedRect *cmd) +{ + _debug_printf("\t\t.left = %i\n", (*cmd).left); + _debug_printf("\t\t.top = %i\n", (*cmd).top); + _debug_printf("\t\t.right = %i\n", (*cmd).right); + _debug_printf("\t\t.bottom = %i\n", (*cmd).bottom); +} + +static void +dump_SVGA3dCmdBlitSurfaceToScreen(const SVGA3dCmdBlitSurfaceToScreen *cmd) +{ + _debug_printf("\t\t.srcImage.sid = %u\n", (*cmd).srcImage.sid); + _debug_printf("\t\t.srcImage.face = %u\n", (*cmd).srcImage.face); + _debug_printf("\t\t.srcImage.mipmap = %u\n", (*cmd).srcImage.mipmap); + _debug_printf("\t\t.srcRect.left = %i\n", (*cmd).srcRect.left); + _debug_printf("\t\t.srcRect.top = %i\n", (*cmd).srcRect.top); + _debug_printf("\t\t.srcRect.right = %i\n", (*cmd).srcRect.right); + _debug_printf("\t\t.srcRect.bottom = %i\n", (*cmd).srcRect.bottom); + _debug_printf("\t\t.destScreenId = %u\n", (*cmd).destScreenId); + _debug_printf("\t\t.destRect.left = %i\n", (*cmd).destRect.left); + _debug_printf("\t\t.destRect.top = %i\n", (*cmd).destRect.top); + _debug_printf("\t\t.destRect.right = %i\n", (*cmd).destRect.right); + _debug_printf("\t\t.destRect.bottom = %i\n", (*cmd).destRect.bottom); +} + + +void +svga_dump_command(uint32_t cmd_id, const void *data, uint32_t size) +{ + const uint8_t *body = (const uint8_t *)data; + const uint8_t *next = body + size; + + switch(cmd_id) { + case SVGA_3D_CMD_SURFACE_DEFINE: + _debug_printf("\tSVGA_3D_CMD_SURFACE_DEFINE\n"); + { + const SVGA3dCmdDefineSurface *cmd = (const SVGA3dCmdDefineSurface *)body; + dump_SVGA3dCmdDefineSurface(cmd); + body = (const uint8_t *)&cmd[1]; + while(body + sizeof(SVGA3dSize) <= next) { + dump_SVGA3dSize((const SVGA3dSize *)body); + body += sizeof(SVGA3dSize); + } + } + break; + case SVGA_3D_CMD_SURFACE_DESTROY: + _debug_printf("\tSVGA_3D_CMD_SURFACE_DESTROY\n"); + { + const SVGA3dCmdDestroySurface *cmd = (const SVGA3dCmdDestroySurface *)body; + dump_SVGA3dCmdDestroySurface(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_SURFACE_COPY: + _debug_printf("\tSVGA_3D_CMD_SURFACE_COPY\n"); + { + const SVGA3dCmdSurfaceCopy *cmd = (const SVGA3dCmdSurfaceCopy *)body; + dump_SVGA3dCmdSurfaceCopy(cmd); + body = (const uint8_t *)&cmd[1]; + while(body + sizeof(SVGA3dCopyBox) <= next) { + dump_SVGA3dCopyBox((const SVGA3dCopyBox *)body); + body += sizeof(SVGA3dCopyBox); + } + } + break; + case SVGA_3D_CMD_SURFACE_STRETCHBLT: + _debug_printf("\tSVGA_3D_CMD_SURFACE_STRETCHBLT\n"); + { + const SVGA3dCmdSurfaceStretchBlt *cmd = (const SVGA3dCmdSurfaceStretchBlt *)body; + dump_SVGA3dCmdSurfaceStretchBlt(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_SURFACE_DMA: + _debug_printf("\tSVGA_3D_CMD_SURFACE_DMA\n"); + { + const SVGA3dCmdSurfaceDMA *cmd = (const SVGA3dCmdSurfaceDMA *)body; + dump_SVGA3dCmdSurfaceDMA(cmd); + body = (const uint8_t *)&cmd[1]; + while(body + sizeof(SVGA3dCopyBox) <= next) { + dump_SVGA3dCopyBox((const SVGA3dCopyBox *)body); + body += sizeof(SVGA3dCopyBox); + } + while(body + sizeof(SVGA3dCmdSurfaceDMASuffix) <= next) { + dump_SVGA3dCmdSurfaceDMASuffix((const SVGA3dCmdSurfaceDMASuffix *)body); + body += sizeof(SVGA3dCmdSurfaceDMASuffix); + } + } + break; + case SVGA_3D_CMD_CONTEXT_DEFINE: + _debug_printf("\tSVGA_3D_CMD_CONTEXT_DEFINE\n"); + { + const SVGA3dCmdDefineContext *cmd = (const SVGA3dCmdDefineContext *)body; + dump_SVGA3dCmdDefineContext(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_CONTEXT_DESTROY: + _debug_printf("\tSVGA_3D_CMD_CONTEXT_DESTROY\n"); + { + const SVGA3dCmdDestroyContext *cmd = (const SVGA3dCmdDestroyContext *)body; + dump_SVGA3dCmdDestroyContext(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_SETTRANSFORM: + _debug_printf("\tSVGA_3D_CMD_SETTRANSFORM\n"); + { + const SVGA3dCmdSetTransform *cmd = (const SVGA3dCmdSetTransform *)body; + dump_SVGA3dCmdSetTransform(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_SETZRANGE: + _debug_printf("\tSVGA_3D_CMD_SETZRANGE\n"); + { + const SVGA3dCmdSetZRange *cmd = (const SVGA3dCmdSetZRange *)body; + dump_SVGA3dCmdSetZRange(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_SETRENDERSTATE: + _debug_printf("\tSVGA_3D_CMD_SETRENDERSTATE\n"); + { + const SVGA3dCmdSetRenderState *cmd = (const SVGA3dCmdSetRenderState *)body; + dump_SVGA3dCmdSetRenderState(cmd); + body = (const uint8_t *)&cmd[1]; + while(body + sizeof(SVGA3dRenderState) <= next) { + dump_SVGA3dRenderState((const SVGA3dRenderState *)body); + body += sizeof(SVGA3dRenderState); + } + } + break; + case SVGA_3D_CMD_SETRENDERTARGET: + _debug_printf("\tSVGA_3D_CMD_SETRENDERTARGET\n"); + { + const SVGA3dCmdSetRenderTarget *cmd = (const SVGA3dCmdSetRenderTarget *)body; + dump_SVGA3dCmdSetRenderTarget(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_SETTEXTURESTATE: + _debug_printf("\tSVGA_3D_CMD_SETTEXTURESTATE\n"); + { + const SVGA3dCmdSetTextureState *cmd = (const SVGA3dCmdSetTextureState *)body; + dump_SVGA3dCmdSetTextureState(cmd); + body = (const uint8_t *)&cmd[1]; + while(body + sizeof(SVGA3dTextureState) <= next) { + dump_SVGA3dTextureState((const SVGA3dTextureState *)body); + body += sizeof(SVGA3dTextureState); + } + } + break; + case SVGA_3D_CMD_SETMATERIAL: + _debug_printf("\tSVGA_3D_CMD_SETMATERIAL\n"); + { + const SVGA3dCmdSetMaterial *cmd = (const SVGA3dCmdSetMaterial *)body; + dump_SVGA3dCmdSetMaterial(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_SETLIGHTDATA: + _debug_printf("\tSVGA_3D_CMD_SETLIGHTDATA\n"); + { + const SVGA3dCmdSetLightData *cmd = (const SVGA3dCmdSetLightData *)body; + dump_SVGA3dCmdSetLightData(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_SETLIGHTENABLED: + _debug_printf("\tSVGA_3D_CMD_SETLIGHTENABLED\n"); + { + const SVGA3dCmdSetLightEnabled *cmd = (const SVGA3dCmdSetLightEnabled *)body; + dump_SVGA3dCmdSetLightEnabled(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_SETVIEWPORT: + _debug_printf("\tSVGA_3D_CMD_SETVIEWPORT\n"); + { + const SVGA3dCmdSetViewport *cmd = (const SVGA3dCmdSetViewport *)body; + dump_SVGA3dCmdSetViewport(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_SETCLIPPLANE: + _debug_printf("\tSVGA_3D_CMD_SETCLIPPLANE\n"); + { + const SVGA3dCmdSetClipPlane *cmd = (const SVGA3dCmdSetClipPlane *)body; + dump_SVGA3dCmdSetClipPlane(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_CLEAR: + _debug_printf("\tSVGA_3D_CMD_CLEAR\n"); + { + const SVGA3dCmdClear *cmd = (const SVGA3dCmdClear *)body; + dump_SVGA3dCmdClear(cmd); + body = (const uint8_t *)&cmd[1]; + while(body + sizeof(SVGA3dRect) <= next) { + dump_SVGA3dRect((const SVGA3dRect *)body); + body += sizeof(SVGA3dRect); + } + } + break; + case SVGA_3D_CMD_PRESENT: + _debug_printf("\tSVGA_3D_CMD_PRESENT\n"); + { + const SVGA3dCmdPresent *cmd = (const SVGA3dCmdPresent *)body; + dump_SVGA3dCmdPresent(cmd); + body = (const uint8_t *)&cmd[1]; + while(body + sizeof(SVGA3dCopyRect) <= next) { + dump_SVGA3dCopyRect((const SVGA3dCopyRect *)body); + body += sizeof(SVGA3dCopyRect); + } + } + break; + case SVGA_3D_CMD_SHADER_DEFINE: + _debug_printf("\tSVGA_3D_CMD_SHADER_DEFINE\n"); + { + const SVGA3dCmdDefineShader *cmd = (const SVGA3dCmdDefineShader *)body; + dump_SVGA3dCmdDefineShader(cmd); + body = (const uint8_t *)&cmd[1]; + svga_shader_dump((const uint32_t *)body, + (unsigned)(next - body)/sizeof(uint32_t), + FALSE ); + body = next; + } + break; + case SVGA_3D_CMD_SHADER_DESTROY: + _debug_printf("\tSVGA_3D_CMD_SHADER_DESTROY\n"); + { + const SVGA3dCmdDestroyShader *cmd = (const SVGA3dCmdDestroyShader *)body; + dump_SVGA3dCmdDestroyShader(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_SET_SHADER: + _debug_printf("\tSVGA_3D_CMD_SET_SHADER\n"); + { + const SVGA3dCmdSetShader *cmd = (const SVGA3dCmdSetShader *)body; + dump_SVGA3dCmdSetShader(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_SET_SHADER_CONST: + _debug_printf("\tSVGA_3D_CMD_SET_SHADER_CONST\n"); + { + const SVGA3dCmdSetShaderConst *cmd = (const SVGA3dCmdSetShaderConst *)body; + dump_SVGA3dCmdSetShaderConst(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_DRAW_PRIMITIVES: + _debug_printf("\tSVGA_3D_CMD_DRAW_PRIMITIVES\n"); + { + const SVGA3dCmdDrawPrimitives *cmd = (const SVGA3dCmdDrawPrimitives *)body; + unsigned i, j; + dump_SVGA3dCmdDrawPrimitives(cmd); + body = (const uint8_t *)&cmd[1]; + for(i = 0; i < cmd->numVertexDecls; ++i) { + dump_SVGA3dVertexDecl((const SVGA3dVertexDecl *)body); + body += sizeof(SVGA3dVertexDecl); + } + for(j = 0; j < cmd->numRanges; ++j) { + dump_SVGA3dPrimitiveRange((const SVGA3dPrimitiveRange *)body); + body += sizeof(SVGA3dPrimitiveRange); + } + while(body + sizeof(SVGA3dVertexDivisor) <= next) { + dump_SVGA3dVertexDivisor((const SVGA3dVertexDivisor *)body); + body += sizeof(SVGA3dVertexDivisor); + } + } + break; + case SVGA_3D_CMD_SETSCISSORRECT: + _debug_printf("\tSVGA_3D_CMD_SETSCISSORRECT\n"); + { + const SVGA3dCmdSetScissorRect *cmd = (const SVGA3dCmdSetScissorRect *)body; + dump_SVGA3dCmdSetScissorRect(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_BEGIN_QUERY: + _debug_printf("\tSVGA_3D_CMD_BEGIN_QUERY\n"); + { + const SVGA3dCmdBeginQuery *cmd = (const SVGA3dCmdBeginQuery *)body; + dump_SVGA3dCmdBeginQuery(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_END_QUERY: + _debug_printf("\tSVGA_3D_CMD_END_QUERY\n"); + { + const SVGA3dCmdEndQuery *cmd = (const SVGA3dCmdEndQuery *)body; + dump_SVGA3dCmdEndQuery(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_WAIT_FOR_QUERY: + _debug_printf("\tSVGA_3D_CMD_WAIT_FOR_QUERY\n"); + { + const SVGA3dCmdWaitForQuery *cmd = (const SVGA3dCmdWaitForQuery *)body; + dump_SVGA3dCmdWaitForQuery(cmd); + body = (const uint8_t *)&cmd[1]; + } + break; + case SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN: + _debug_printf("\tSVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN\n"); + { + const SVGA3dCmdBlitSurfaceToScreen *cmd = (const SVGA3dCmdBlitSurfaceToScreen *)body; + dump_SVGA3dCmdBlitSurfaceToScreen(cmd); + body = (const uint8_t *)&cmd[1]; + while(body + sizeof(SVGASignedRect) <= next) { + dump_SVGASignedRect((const SVGASignedRect *)body); + body += sizeof(SVGASignedRect); + } + } + break; + default: + _debug_printf("\t0x%08x\n", cmd_id); + break; + } + + while(body + sizeof(uint32_t) <= next) { + _debug_printf("\t\t0x%08x\n", *(const uint32_t *)body); + body += sizeof(uint32_t); + } + while(body + sizeof(uint32_t) <= next) + _debug_printf("\t\t0x%02x\n", *body++); +} + + +void +svga_dump_commands(const void *commands, uint32_t size) +{ + const uint8_t *next = commands; + const uint8_t *last = next + size; + + assert(size % sizeof(uint32_t) == 0); + + while(next < last) { + const uint32_t cmd_id = *(const uint32_t *)next; + + if(SVGA_3D_CMD_BASE <= cmd_id && cmd_id < SVGA_3D_CMD_MAX) { + const SVGA3dCmdHeader *header = (const SVGA3dCmdHeader *)next; + const uint8_t *body = (const uint8_t *)&header[1]; + + next = body + header->size; + if(next > last) + break; + + svga_dump_command(cmd_id, body, header->size); + } + else if(cmd_id == SVGA_CMD_FENCE) { + _debug_printf("\tSVGA_CMD_FENCE\n"); + _debug_printf("\t\t0x%08x\n", ((const uint32_t *)next)[1]); + next += 2*sizeof(uint32_t); + } + else { + _debug_printf("\t0x%08x\n", cmd_id); + next += sizeof(uint32_t); + } + } +} + diff --git a/src/gallium/drivers/svga/svgadump/svga_dump.h b/src/gallium/drivers/svga/svgadump/svga_dump.h new file mode 100644 index 0000000..ca01543 --- /dev/null +++ b/src/gallium/drivers/svga/svgadump/svga_dump.h @@ -0,0 +1,37 @@ +/********************************************************** + * 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 SVGA_DUMP_H_ +#define SVGA_DUMP_H_ + +#include "pipe/p_compiler.h" + +void +svga_dump_command(uint32_t cmd_id, const void *data, uint32_t size); + +void +svga_dump_commands(const void *commands, uint32_t size); + +#endif /* SVGA_DUMP_H_ */ diff --git a/src/gallium/drivers/svga/svgadump/svga_dump.py b/src/gallium/drivers/svga/svgadump/svga_dump.py new file mode 100755 index 0000000..0bc0b3a --- /dev/null +++ b/src/gallium/drivers/svga/svgadump/svga_dump.py @@ -0,0 +1,340 @@ +#!/usr/bin/env python +''' +Generates dumper for the SVGA 3D command stream using pygccxml. + +Jose Fonseca +''' + +copyright = ''' +/********************************************************** + * 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. + * + **********************************************************/ + ''' + +import os +import sys + +from pygccxml import parser +from pygccxml import declarations + +from pygccxml.declarations import algorithm +from pygccxml.declarations import decl_visitor +from pygccxml.declarations import type_traits +from pygccxml.declarations import type_visitor + + +enums = True + + +class decl_dumper_t(decl_visitor.decl_visitor_t): + + def __init__(self, instance = '', decl = None): + decl_visitor.decl_visitor_t.__init__(self) + self._instance = instance + self.decl = decl + + def clone(self): + return decl_dumper_t(self._instance, self.decl) + + def visit_class(self): + class_ = self.decl + assert self.decl.class_type in ('struct', 'union') + + for variable in class_.variables(): + if variable.name != '': + #print 'variable = %r' % variable.name + dump_type(self._instance + '.' + variable.name, variable.type) + + def visit_enumeration(self): + if enums: + print ' switch(%s) {' % ("(*cmd)" + self._instance,) + for name, value in self.decl.values: + print ' case %s:' % (name,) + print ' _debug_printf("\\t\\t%s = %s\\n");' % (self._instance, name) + print ' break;' + print ' default:' + print ' _debug_printf("\\t\\t%s = %%i\\n", %s);' % (self._instance, "(*cmd)" + self._instance) + print ' break;' + print ' }' + else: + print ' _debug_printf("\\t\\t%s = %%i\\n", %s);' % (self._instance, "(*cmd)" + self._instance) + + +def dump_decl(instance, decl): + dumper = decl_dumper_t(instance, decl) + algorithm.apply_visitor(dumper, decl) + + +class type_dumper_t(type_visitor.type_visitor_t): + + def __init__(self, instance, type_): + type_visitor.type_visitor_t.__init__(self) + self.instance = instance + self.type = type_ + + def clone(self): + return type_dumper_t(self.instance, self.type) + + def visit_char(self): + self.print_instance('%i') + + def visit_unsigned_char(self): + self.print_instance('%u') + + def visit_signed_char(self): + self.print_instance('%i') + + def visit_wchar(self): + self.print_instance('%i') + + def visit_short_int(self): + self.print_instance('%i') + + def visit_short_unsigned_int(self): + self.print_instance('%u') + + def visit_bool(self): + self.print_instance('%i') + + def visit_int(self): + self.print_instance('%i') + + def visit_unsigned_int(self): + self.print_instance('%u') + + def visit_long_int(self): + self.print_instance('%li') + + def visit_long_unsigned_int(self): + self.print_instance('%lu') + + def visit_long_long_int(self): + self.print_instance('%lli') + + def visit_long_long_unsigned_int(self): + self.print_instance('%llu') + + def visit_float(self): + self.print_instance('%f') + + def visit_double(self): + self.print_instance('%f') + + def visit_array(self): + for i in range(type_traits.array_size(self.type)): + dump_type(self.instance + '[%i]' % i, type_traits.base_type(self.type)) + + def visit_pointer(self): + self.print_instance('%p') + + def visit_declarated(self): + #print 'decl = %r' % self.type.decl_string + decl = type_traits.remove_declarated(self.type) + dump_decl(self.instance, decl) + + def print_instance(self, format): + print ' _debug_printf("\\t\\t%s = %s\\n", %s);' % (self.instance, format, "(*cmd)" + self.instance) + + +def dump_type(instance, type_): + type_ = type_traits.remove_alias(type_) + visitor = type_dumper_t(instance, type_) + algorithm.apply_visitor(visitor, type_) + + +def dump_struct(decls, class_): + print 'static void' + print 'dump_%s(const %s *cmd)' % (class_.name, class_.name) + print '{' + dump_decl('', class_) + print '}' + print '' + + +cmds = [ + ('SVGA_3D_CMD_SURFACE_DEFINE', 'SVGA3dCmdDefineSurface', (), 'SVGA3dSize'), + ('SVGA_3D_CMD_SURFACE_DESTROY', 'SVGA3dCmdDestroySurface', (), None), + ('SVGA_3D_CMD_SURFACE_COPY', 'SVGA3dCmdSurfaceCopy', (), 'SVGA3dCopyBox'), + ('SVGA_3D_CMD_SURFACE_STRETCHBLT', 'SVGA3dCmdSurfaceStretchBlt', (), None), + ('SVGA_3D_CMD_SURFACE_DMA', 'SVGA3dCmdSurfaceDMA', (), 'SVGA3dCopyBox'), + ('SVGA_3D_CMD_CONTEXT_DEFINE', 'SVGA3dCmdDefineContext', (), None), + ('SVGA_3D_CMD_CONTEXT_DESTROY', 'SVGA3dCmdDestroyContext', (), None), + ('SVGA_3D_CMD_SETTRANSFORM', 'SVGA3dCmdSetTransform', (), None), + ('SVGA_3D_CMD_SETZRANGE', 'SVGA3dCmdSetZRange', (), None), + ('SVGA_3D_CMD_SETRENDERSTATE', 'SVGA3dCmdSetRenderState', (), 'SVGA3dRenderState'), + ('SVGA_3D_CMD_SETRENDERTARGET', 'SVGA3dCmdSetRenderTarget', (), None), + ('SVGA_3D_CMD_SETTEXTURESTATE', 'SVGA3dCmdSetTextureState', (), 'SVGA3dTextureState'), + ('SVGA_3D_CMD_SETMATERIAL', 'SVGA3dCmdSetMaterial', (), None), + ('SVGA_3D_CMD_SETLIGHTDATA', 'SVGA3dCmdSetLightData', (), None), + ('SVGA_3D_CMD_SETLIGHTENABLED', 'SVGA3dCmdSetLightEnabled', (), None), + ('SVGA_3D_CMD_SETVIEWPORT', 'SVGA3dCmdSetViewport', (), None), + ('SVGA_3D_CMD_SETCLIPPLANE', 'SVGA3dCmdSetClipPlane', (), None), + ('SVGA_3D_CMD_CLEAR', 'SVGA3dCmdClear', (), 'SVGA3dRect'), + ('SVGA_3D_CMD_PRESENT', 'SVGA3dCmdPresent', (), 'SVGA3dCopyRect'), + ('SVGA_3D_CMD_SHADER_DEFINE', 'SVGA3dCmdDefineShader', (), None), + ('SVGA_3D_CMD_SHADER_DESTROY', 'SVGA3dCmdDestroyShader', (), None), + ('SVGA_3D_CMD_SET_SHADER', 'SVGA3dCmdSetShader', (), None), + ('SVGA_3D_CMD_SET_SHADER_CONST', 'SVGA3dCmdSetShaderConst', (), None), + ('SVGA_3D_CMD_DRAW_PRIMITIVES', 'SVGA3dCmdDrawPrimitives', (('SVGA3dVertexDecl', 'numVertexDecls'), ('SVGA3dPrimitiveRange', 'numRanges')), 'SVGA3dVertexDivisor'), + ('SVGA_3D_CMD_SETSCISSORRECT', 'SVGA3dCmdSetScissorRect', (), None), + ('SVGA_3D_CMD_BEGIN_QUERY', 'SVGA3dCmdBeginQuery', (), None), + ('SVGA_3D_CMD_END_QUERY', 'SVGA3dCmdEndQuery', (), None), + ('SVGA_3D_CMD_WAIT_FOR_QUERY', 'SVGA3dCmdWaitForQuery', (), None), + #('SVGA_3D_CMD_PRESENT_READBACK', None, (), None), + ('SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN', 'SVGA3dCmdBlitSurfaceToScreen', (), 'SVGASignedRect'), +] + +def dump_cmds(): + print r''' +void +svga_dump_command(uint32_t cmd_id, const void *data, uint32_t size) +{ + const uint8_t *body = (const uint8_t *)data; + const uint8_t *next = body + size; +''' + print ' switch(cmd_id) {' + indexes = 'ijklmn' + for id, header, body, footer in cmds: + print ' case %s:' % id + print ' _debug_printf("\\t%s\\n");' % id + print ' {' + print ' const %s *cmd = (const %s *)body;' % (header, header) + if len(body): + print ' unsigned ' + ', '.join(indexes[:len(body)]) + ';' + print ' dump_%s(cmd);' % header + print ' body = (const uint8_t *)&cmd[1];' + for i in range(len(body)): + struct, count = body[i] + idx = indexes[i] + print ' for(%s = 0; %s < cmd->%s; ++%s) {' % (idx, idx, count, idx) + print ' dump_%s((const %s *)body);' % (struct, struct) + print ' body += sizeof(%s);' % struct + print ' }' + if footer is not None: + print ' while(body + sizeof(%s) <= next) {' % footer + print ' dump_%s((const %s *)body);' % (footer, footer) + print ' body += sizeof(%s);' % footer + print ' }' + if id == 'SVGA_3D_CMD_SHADER_DEFINE': + print ' svga_shader_dump((const uint32_t *)body,' + print ' (unsigned)(next - body)/sizeof(uint32_t),' + print ' FALSE);' + print ' body = next;' + print ' }' + print ' break;' + print ' default:' + print ' _debug_printf("\\t0x%08x\\n", cmd_id);' + print ' break;' + print ' }' + print r''' + while(body + sizeof(uint32_t) <= next) { + _debug_printf("\t\t0x%08x\n", *(const uint32_t *)body); + body += sizeof(uint32_t); + } + while(body + sizeof(uint32_t) <= next) + _debug_printf("\t\t0x%02x\n", *body++); +} +''' + print r''' +void +svga_dump_commands(const void *commands, uint32_t size) +{ + const uint8_t *next = commands; + const uint8_t *last = next + size; + + assert(size % sizeof(uint32_t) == 0); + + while(next < last) { + const uint32_t cmd_id = *(const uint32_t *)next; + + if(SVGA_3D_CMD_BASE <= cmd_id && cmd_id < SVGA_3D_CMD_MAX) { + const SVGA3dCmdHeader *header = (const SVGA3dCmdHeader *)next; + const uint8_t *body = (const uint8_t *)&header[1]; + + next = body + header->size; + if(next > last) + break; + + svga_dump_command(cmd_id, body, header->size); + } + else if(cmd_id == SVGA_CMD_FENCE) { + _debug_printf("\tSVGA_CMD_FENCE\n"); + _debug_printf("\t\t0x%08x\n", ((const uint32_t *)next)[1]); + next += 2*sizeof(uint32_t); + } + else { + _debug_printf("\t0x%08x\n", cmd_id); + next += sizeof(uint32_t); + } + } +} +''' + +def main(): + print copyright.strip() + print + print '/**' + print ' * @file' + print ' * Dump SVGA commands.' + print ' *' + print ' * Generated automatically from svga3d_reg.h by svga_dump.py.' + print ' */' + print + print '#include "svga_types.h"' + print '#include "svga_shader_dump.h"' + print '#include "svga3d_reg.h"' + print + print '#include "util/u_debug.h"' + print '#include "svga_dump.h"' + print + + config = parser.config_t( + include_paths = ['../../../include', '../include'], + compiler = 'gcc', + ) + + headers = [ + 'svga_types.h', + 'svga3d_reg.h', + ] + + decls = parser.parse(headers, config, parser.COMPILATION_MODE.ALL_AT_ONCE) + global_ns = declarations.get_global_namespace(decls) + + names = set() + for id, header, body, footer in cmds: + names.add(header) + for struct, count in body: + names.add(struct) + if footer is not None: + names.add(footer) + + for class_ in global_ns.classes(lambda decl: decl.name in names): + dump_struct(decls, class_) + + dump_cmds() + + +if __name__ == '__main__': + main() diff --git a/src/gallium/drivers/svga/svgadump/svga_shader.h b/src/gallium/drivers/svga/svgadump/svga_shader.h new file mode 100644 index 0000000..5db64bf --- /dev/null +++ b/src/gallium/drivers/svga/svgadump/svga_shader.h @@ -0,0 +1,227 @@ +/********************************************************** + * Copyright 2007-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 Shader Token Definitions + * + * @author Michal Krol + */ + +#ifndef ST_SHADER_SVGA_H +#define ST_SHADER_SVGA_H + +#include "pipe/p_compiler.h" + +struct sh_op +{ + unsigned opcode:16; + unsigned control:8; + unsigned length:4; + unsigned predicated:1; + unsigned unused:1; + unsigned coissue:1; + unsigned is_reg:1; +}; + +struct sh_reg +{ + unsigned number:11; + unsigned type_hi:2; + unsigned relative:1; + unsigned unused:14; + unsigned type_lo:3; + unsigned is_reg:1; +}; + +static INLINE unsigned +sh_reg_type( struct sh_reg reg ) +{ + return reg.type_lo | (reg.type_hi << 3); +} + +struct sh_cdata +{ + float xyzw[4]; +}; + +struct sh_def +{ + struct sh_op op; + struct sh_reg reg; + struct sh_cdata cdata; +}; + +struct sh_defb +{ + struct sh_op op; + struct sh_reg reg; + uint data; +}; + +struct sh_idata +{ + int xyzw[4]; +}; + +struct sh_defi +{ + struct sh_op op; + struct sh_reg reg; + struct sh_idata idata; +}; + +#define PS_TEXTURETYPE_UNKNOWN SVGA3DSAMP_UNKNOWN +#define PS_TEXTURETYPE_2D SVGA3DSAMP_2D +#define PS_TEXTURETYPE_CUBE SVGA3DSAMP_CUBE +#define PS_TEXTURETYPE_VOLUME SVGA3DSAMP_VOLUME + +struct sh_sampleinfo +{ + unsigned unused:27; + unsigned texture_type:4; + unsigned is_reg:1; +}; + +struct sh_semantic +{ + unsigned usage:4; + unsigned unused1:12; + unsigned usage_index:4; + unsigned unused2:11; + unsigned is_reg:1; +}; + +#define SH_WRITEMASK_0 0x1 +#define SH_WRITEMASK_1 0x2 +#define SH_WRITEMASK_2 0x4 +#define SH_WRITEMASK_3 0x8 +#define SH_WRITEMASK_ALL 0xf + +#define SH_DSTMOD_NONE 0x0 +#define SH_DSTMOD_SATURATE 0x1 +#define SH_DSTMOD_PARTIALPRECISION 0x2 +#define SH_DSTMOD_MSAMPCENTROID 0x4 + +struct sh_dstreg +{ + unsigned number:11; + unsigned type_hi:2; + unsigned relative:1; + unsigned unused:2; + unsigned write_mask:4; + unsigned modifier:4; + unsigned shift_scale:4; + unsigned type_lo:3; + unsigned is_reg:1; +}; + +static INLINE unsigned +sh_dstreg_type( struct sh_dstreg reg ) +{ + return reg.type_lo | (reg.type_hi << 3); +} + +struct sh_dcl +{ + struct sh_op op; + union { + struct sh_sampleinfo sampleinfo; + struct sh_semantic semantic; + } u; + struct sh_dstreg reg; +}; + +struct sh_srcreg +{ + unsigned number:11; + unsigned type_hi:2; + unsigned relative:1; + unsigned unused:2; + unsigned swizzle_x:2; + unsigned swizzle_y:2; + unsigned swizzle_z:2; + unsigned swizzle_w:2; + unsigned modifier:4; + unsigned type_lo:3; + unsigned is_reg:1; +}; + +static INLINE unsigned +sh_srcreg_type( struct sh_srcreg reg ) +{ + return reg.type_lo | (reg.type_hi << 3); +} + +struct sh_dstop +{ + struct sh_op op; + struct sh_dstreg dst; +}; + +struct sh_srcop +{ + struct sh_op op; + struct sh_srcreg src; +}; + +struct sh_src2op +{ + struct sh_op op; + struct sh_srcreg src0; + struct sh_srcreg src1; +}; + +struct sh_unaryop +{ + struct sh_op op; + struct sh_dstreg dst; + struct sh_srcreg src; +}; + +struct sh_binaryop +{ + struct sh_op op; + struct sh_dstreg dst; + struct sh_srcreg src0; + struct sh_srcreg src1; +}; + +struct sh_trinaryop +{ + struct sh_op op; + struct sh_dstreg dst; + struct sh_srcreg src0; + struct sh_srcreg src1; + struct sh_srcreg src2; +}; + +struct sh_comment +{ + unsigned opcode:16; + unsigned size:16; +}; + +#endif /* ST_SHADER_SVGA_H */ diff --git a/src/gallium/drivers/svga/svgadump/svga_shader_dump.c b/src/gallium/drivers/svga/svgadump/svga_shader_dump.c new file mode 100644 index 0000000..4ee1bf2 --- /dev/null +++ b/src/gallium/drivers/svga/svgadump/svga_shader_dump.c @@ -0,0 +1,722 @@ +/********************************************************** + * 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 + * SVGA Shader Dump Facilities + * + * @author Michal Krol + */ + +#include "svga_shader.h" +#include "svga_shader_dump.h" +#include "svga_shader_op.h" +#include "util/u_debug.h" + +#include "../svga_hw_reg.h" +#include "svga3d_shaderdefs.h" + +struct dump_info +{ + uint32 version; + boolean is_ps; + int indent; +}; + +#define DUMP_MAX_OP_SRC 4 + +struct dump_op +{ + struct sh_op op; + struct sh_dstreg dst; + struct sh_srcreg dstind; + struct sh_srcreg src[DUMP_MAX_OP_SRC]; + struct sh_srcreg srcind[DUMP_MAX_OP_SRC]; + struct sh_srcreg p0; +}; + +static void +dump_indent(int indent) +{ + int i; + + for (i = 0; i < indent; ++i) { + _debug_printf(" "); + } +} + +static void dump_op( struct sh_op op, const char *mnemonic ) +{ + assert( op.is_reg == 0 ); + + if (op.predicated) { + _debug_printf("(p0) "); + } + if (op.coissue) + _debug_printf( "+" ); + _debug_printf( "%s", mnemonic ); + + switch (op.opcode) { + case SVGA3DOP_TEX: + switch (op.control) { + case 0: + break; + case 1 /* PROJECT */: + _debug_printf("p"); + break; + case 2 /* BIAS */: + _debug_printf("b"); + break; + default: + assert(0); + } + break; + + case SVGA3DOP_IFC: + case SVGA3DOP_BREAKC: + case SVGA3DOP_SETP: + switch (op.control) { + case SVGA3DOPCOMP_GT: + _debug_printf("_gt"); + break; + case SVGA3DOPCOMP_EQ: + _debug_printf("_eq"); + break; + case SVGA3DOPCOMP_GE: + _debug_printf("_ge"); + break; + case SVGA3DOPCOMP_LT: + _debug_printf("_lt"); + break; + case SVGA3DOPCOMPC_NE: + _debug_printf("_ne"); + break; + case SVGA3DOPCOMP_LE: + _debug_printf("_le"); + break; + default: + assert(0); + } + break; + + default: + assert(op.control == 0); + } +} + +static void +format_reg(const char *name, + const struct sh_reg reg, + const struct sh_srcreg *indreg) +{ + if (reg.relative) { + assert(indreg); + + if (sh_srcreg_type(*indreg) == SVGA3DREG_LOOP) { + _debug_printf("%s[aL+%u]", name, reg.number); + } else { + _debug_printf("%s[a%u.x+%u]", name, indreg->number, reg.number); + } + } else { + _debug_printf("%s%u", name, reg.number); + } +} + +static void dump_reg( struct sh_reg reg, struct sh_srcreg *indreg, const struct dump_info *di ) +{ + assert( reg.is_reg == 1 ); + + switch (sh_reg_type( reg )) { + case SVGA3DREG_TEMP: + format_reg("r", reg, NULL); + break; + + case SVGA3DREG_INPUT: + format_reg("v", reg, indreg); + break; + + case SVGA3DREG_CONST: + format_reg("c", reg, indreg); + break; + + case SVGA3DREG_ADDR: /* VS */ + /* SVGA3DREG_TEXTURE */ /* PS */ + assert(!reg.relative); + if (di->is_ps) { + format_reg("t", reg, NULL); + } else { + format_reg("a", reg, NULL); + } + break; + + case SVGA3DREG_RASTOUT: + assert(!reg.relative); + switch (reg.number) { + case 0 /*POSITION*/: + _debug_printf( "oPos" ); + break; + case 1 /*FOG*/: + _debug_printf( "oFog" ); + break; + case 2 /*POINT_SIZE*/: + _debug_printf( "oPts" ); + break; + default: + assert( 0 ); + _debug_printf( "???" ); + } + break; + + case SVGA3DREG_ATTROUT: + assert( reg.number < 2 ); + format_reg("oD", reg, NULL); + break; + + case SVGA3DREG_TEXCRDOUT: /* VS */ + /* SVGA3DREG_OUTPUT */ /* VS3.0+ */ + if (!di->is_ps && di->version >= SVGA3D_VS_30) { + format_reg("o", reg, indreg); + } else { + format_reg("oT", reg, NULL); + } + break; + + case SVGA3DREG_COLOROUT: + format_reg("oC", reg, NULL); + break; + + case SVGA3DREG_DEPTHOUT: + assert(!reg.relative); + assert(reg.number == 0); + _debug_printf("oDepth"); + break; + + case SVGA3DREG_SAMPLER: + format_reg("s", reg, NULL); + break; + + case SVGA3DREG_CONSTBOOL: + format_reg("b", reg, NULL); + break; + + case SVGA3DREG_CONSTINT: + format_reg("i", reg, NULL); + break; + + case SVGA3DREG_LOOP: + assert(!reg.relative); + assert( reg.number == 0 ); + _debug_printf( "aL" ); + break; + + case SVGA3DREG_MISCTYPE: + assert(!reg.relative); + switch (reg.number) { + case SVGA3DMISCREG_POSITION: + _debug_printf("vPos"); + break; + case SVGA3DMISCREG_FACE: + _debug_printf("vFace"); + break; + default: + assert(0); + _debug_printf("???"); + } + break; + + case SVGA3DREG_LABEL: + format_reg("l", reg, NULL); + break; + + case SVGA3DREG_PREDICATE: + format_reg("p", reg, NULL); + break; + + default: + assert( 0 ); + _debug_printf( "???" ); + } +} + +static void dump_cdata( struct sh_cdata cdata ) +{ + _debug_printf( "%f, %f, %f, %f", cdata.xyzw[0], cdata.xyzw[1], cdata.xyzw[2], cdata.xyzw[3] ); +} + +static void dump_idata( struct sh_idata idata ) +{ + _debug_printf( "%d, %d, %d, %d", idata.xyzw[0], idata.xyzw[1], idata.xyzw[2], idata.xyzw[3] ); +} + +static void dump_bdata( boolean bdata ) +{ + _debug_printf( bdata ? "TRUE" : "FALSE" ); +} + +static void +dump_sampleinfo(struct sh_sampleinfo sampleinfo) +{ + assert( sampleinfo.is_reg == 1 ); + + switch (sampleinfo.texture_type) { + case SVGA3DSAMP_2D: + _debug_printf( "_2d" ); + break; + case SVGA3DSAMP_CUBE: + _debug_printf( "_cube" ); + break; + case SVGA3DSAMP_VOLUME: + _debug_printf( "_volume" ); + break; + default: + assert( 0 ); + } +} + +static void +dump_semantic(uint usage, + uint usage_index) +{ + switch (usage) { + case SVGA3D_DECLUSAGE_POSITION: + _debug_printf("_position"); + break; + case SVGA3D_DECLUSAGE_BLENDWEIGHT: + _debug_printf("_blendweight"); + break; + case SVGA3D_DECLUSAGE_BLENDINDICES: + _debug_printf("_blendindices"); + break; + case SVGA3D_DECLUSAGE_NORMAL: + _debug_printf("_normal"); + break; + case SVGA3D_DECLUSAGE_PSIZE: + _debug_printf("_psize"); + break; + case SVGA3D_DECLUSAGE_TEXCOORD: + _debug_printf("_texcoord"); + break; + case SVGA3D_DECLUSAGE_TANGENT: + _debug_printf("_tangent"); + break; + case SVGA3D_DECLUSAGE_BINORMAL: + _debug_printf("_binormal"); + break; + case SVGA3D_DECLUSAGE_TESSFACTOR: + _debug_printf("_tessfactor"); + break; + case SVGA3D_DECLUSAGE_POSITIONT: + _debug_printf("_positiont"); + break; + case SVGA3D_DECLUSAGE_COLOR: + _debug_printf("_color"); + break; + case SVGA3D_DECLUSAGE_FOG: + _debug_printf("_fog"); + break; + case SVGA3D_DECLUSAGE_DEPTH: + _debug_printf("_depth"); + break; + case SVGA3D_DECLUSAGE_SAMPLE: + _debug_printf("_sample"); + break; + default: + assert(!"Unknown usage"); + _debug_printf("_???"); + } + + if (usage_index) { + _debug_printf("%u", usage_index); + } +} + +static void +dump_dstreg(struct sh_dstreg dstreg, + struct sh_srcreg *indreg, + const struct dump_info *di) +{ + union { + struct sh_reg reg; + struct sh_dstreg dstreg; + } u; + + memset(&u, 0, sizeof(u)); + + assert( (dstreg.modifier & (SVGA3DDSTMOD_SATURATE | SVGA3DDSTMOD_PARTIALPRECISION)) == dstreg.modifier ); + + if (dstreg.modifier & SVGA3DDSTMOD_SATURATE) + _debug_printf( "_sat" ); + if (dstreg.modifier & SVGA3DDSTMOD_PARTIALPRECISION) + _debug_printf( "_pp" ); + switch (dstreg.shift_scale) { + case 0: + break; + case 1: + _debug_printf( "_x2" ); + break; + case 2: + _debug_printf( "_x4" ); + break; + case 3: + _debug_printf( "_x8" ); + break; + case 13: + _debug_printf( "_d8" ); + break; + case 14: + _debug_printf( "_d4" ); + break; + case 15: + _debug_printf( "_d2" ); + break; + default: + assert( 0 ); + } + _debug_printf( " " ); + + u.dstreg = dstreg; + dump_reg( u.reg, indreg, di); + if (dstreg.write_mask != SVGA3DWRITEMASK_ALL) { + _debug_printf( "." ); + if (dstreg.write_mask & SVGA3DWRITEMASK_0) + _debug_printf( "x" ); + if (dstreg.write_mask & SVGA3DWRITEMASK_1) + _debug_printf( "y" ); + if (dstreg.write_mask & SVGA3DWRITEMASK_2) + _debug_printf( "z" ); + if (dstreg.write_mask & SVGA3DWRITEMASK_3) + _debug_printf( "w" ); + } +} + +static void dump_srcreg( struct sh_srcreg srcreg, struct sh_srcreg *indreg, const struct dump_info *di ) +{ + switch (srcreg.modifier) { + case SVGA3DSRCMOD_NEG: + case SVGA3DSRCMOD_BIASNEG: + case SVGA3DSRCMOD_SIGNNEG: + case SVGA3DSRCMOD_X2NEG: + case SVGA3DSRCMOD_ABSNEG: + _debug_printf( "-" ); + break; + case SVGA3DSRCMOD_COMP: + _debug_printf( "1-" ); + break; + case SVGA3DSRCMOD_NOT: + _debug_printf( "!" ); + } + dump_reg( *(struct sh_reg *) &srcreg, indreg, di ); + switch (srcreg.modifier) { + case SVGA3DSRCMOD_NONE: + case SVGA3DSRCMOD_NEG: + case SVGA3DSRCMOD_COMP: + case SVGA3DSRCMOD_NOT: + break; + case SVGA3DSRCMOD_BIAS: + case SVGA3DSRCMOD_BIASNEG: + _debug_printf( "_bias" ); + break; + case SVGA3DSRCMOD_SIGN: + case SVGA3DSRCMOD_SIGNNEG: + _debug_printf( "_bx2" ); + break; + case SVGA3DSRCMOD_X2: + case SVGA3DSRCMOD_X2NEG: + _debug_printf( "_x2" ); + break; + case SVGA3DSRCMOD_DZ: + _debug_printf( "_dz" ); + break; + case SVGA3DSRCMOD_DW: + _debug_printf( "_dw" ); + break; + case SVGA3DSRCMOD_ABS: + case SVGA3DSRCMOD_ABSNEG: + _debug_printf("_abs"); + break; + default: + assert( 0 ); + } + if (srcreg.swizzle_x != 0 || srcreg.swizzle_y != 1 || srcreg.swizzle_z != 2 || srcreg.swizzle_w != 3) { + _debug_printf( "." ); + if (srcreg.swizzle_x == srcreg.swizzle_y && srcreg.swizzle_y == srcreg.swizzle_z && srcreg.swizzle_z == srcreg.swizzle_w) { + _debug_printf( "%c", "xyzw"[srcreg.swizzle_x] ); + } + else { + _debug_printf( "%c", "xyzw"[srcreg.swizzle_x] ); + _debug_printf( "%c", "xyzw"[srcreg.swizzle_y] ); + _debug_printf( "%c", "xyzw"[srcreg.swizzle_z] ); + _debug_printf( "%c", "xyzw"[srcreg.swizzle_w] ); + } + } +} + +static void +parse_op(struct dump_info *di, + const uint **token, + struct dump_op *op, + uint num_dst, + uint num_src) +{ + uint i; + + assert(num_dst <= 1); + assert(num_src <= DUMP_MAX_OP_SRC); + + op->op = *(struct sh_op *)*token; + *token += sizeof(struct sh_op) / sizeof(uint); + + if (num_dst >= 1) { + op->dst = *(struct sh_dstreg *)*token; + *token += sizeof(struct sh_dstreg) / sizeof(uint); + if (op->dst.relative && + (!di->is_ps && di->version >= SVGA3D_VS_30)) { + op->dstind = *(struct sh_srcreg *)*token; + *token += sizeof(struct sh_srcreg) / sizeof(uint); + } + } + + if (op->op.predicated) { + op->p0 = *(struct sh_srcreg *)*token; + *token += sizeof(struct sh_srcreg) / sizeof(uint); + } + + for (i = 0; i < num_src; ++i) { + op->src[i] = *(struct sh_srcreg *)*token; + *token += sizeof(struct sh_srcreg) / sizeof(uint); + if (op->src[i].relative && + ((!di->is_ps && di->version >= SVGA3D_VS_20) || + (di->is_ps && di->version >= SVGA3D_PS_30))) { + op->srcind[i] = *(struct sh_srcreg *)*token; + *token += sizeof(struct sh_srcreg) / sizeof(uint); + } + } +} + +static void +dump_inst(struct dump_info *di, + const unsigned **assem, + struct sh_op op, + const struct sh_opcode_info *info) +{ + struct dump_op dop; + boolean not_first_arg = FALSE; + uint i; + + assert(info->num_dst <= 1); + + di->indent -= info->pre_dedent; + dump_indent(di->indent); + di->indent += info->post_indent; + + dump_op(op, info->mnemonic); + + parse_op(di, assem, &dop, info->num_dst, info->num_src); + if (info->num_dst > 0) { + dump_dstreg(dop.dst, &dop.dstind, di); + not_first_arg = TRUE; + } + + for (i = 0; i < info->num_src; i++) { + if (not_first_arg) { + _debug_printf(", "); + } else { + _debug_printf(" "); + } + dump_srcreg(dop.src[i], &dop.srcind[i], di); + not_first_arg = TRUE; + } + + _debug_printf("\n"); +} + +void +svga_shader_dump( + const unsigned *assem, + unsigned dwords, + unsigned do_binary ) +{ + boolean finished = FALSE; + struct dump_info di; + + di.version = *assem++; + di.is_ps = (di.version & 0xFFFF0000) == 0xFFFF0000; + di.indent = 0; + + _debug_printf( + "%s_%u_%u\n", + di.is_ps ? "ps" : "vs", + (di.version >> 8) & 0xff, + di.version & 0xff ); + + while (!finished) { + struct sh_op op = *(struct sh_op *) assem; + + switch (op.opcode) { + case SVGA3DOP_DCL: + { + struct sh_dcl dcl = *(struct sh_dcl *) assem; + + _debug_printf( "dcl" ); + switch (sh_dstreg_type(dcl.reg)) { + case SVGA3DREG_INPUT: + if ((di.is_ps && di.version >= SVGA3D_PS_30) || + (!di.is_ps && di.version >= SVGA3D_VS_30)) { + dump_semantic(dcl.u.semantic.usage, + dcl.u.semantic.usage_index); + } + break; + case SVGA3DREG_TEXCRDOUT: + if (!di.is_ps && di.version >= SVGA3D_VS_30) { + dump_semantic(dcl.u.semantic.usage, + dcl.u.semantic.usage_index); + } + break; + case SVGA3DREG_SAMPLER: + dump_sampleinfo( dcl.u.sampleinfo ); + break; + } + dump_dstreg(dcl.reg, NULL, &di); + _debug_printf( "\n" ); + assem += sizeof( struct sh_dcl ) / sizeof( unsigned ); + } + break; + + case SVGA3DOP_DEFB: + { + struct sh_defb defb = *(struct sh_defb *) assem; + + _debug_printf( "defb " ); + dump_reg( defb.reg, NULL, &di ); + _debug_printf( ", " ); + dump_bdata( defb.data ); + _debug_printf( "\n" ); + assem += sizeof( struct sh_defb ) / sizeof( unsigned ); + } + break; + + case SVGA3DOP_DEFI: + { + struct sh_defi defi = *(struct sh_defi *) assem; + + _debug_printf( "defi " ); + dump_reg( defi.reg, NULL, &di ); + _debug_printf( ", " ); + dump_idata( defi.idata ); + _debug_printf( "\n" ); + assem += sizeof( struct sh_defi ) / sizeof( unsigned ); + } + break; + + case SVGA3DOP_TEXCOORD: + { + struct sh_opcode_info info = *svga_opcode_info(op.opcode); + + assert(di.is_ps); + if (di.version > SVGA3D_PS_13) { + assert(info.num_src == 0); + + info.num_src = 1; + } + + dump_inst(&di, &assem, op, &info); + } + break; + + case SVGA3DOP_TEX: + { + struct sh_opcode_info info = *svga_opcode_info(op.opcode); + + assert(di.is_ps); + if (di.version > SVGA3D_PS_13) { + assert(info.num_src == 0); + + if (di.version > SVGA3D_PS_14) { + info.num_src = 2; + info.mnemonic = "texld"; + } else { + info.num_src = 1; + } + } + + dump_inst(&di, &assem, op, &info); + } + break; + + case SVGA3DOP_DEF: + { + struct sh_def def = *(struct sh_def *) assem; + + _debug_printf( "def " ); + dump_reg( def.reg, NULL, &di ); + _debug_printf( ", " ); + dump_cdata( def.cdata ); + _debug_printf( "\n" ); + assem += sizeof( struct sh_def ) / sizeof( unsigned ); + } + break; + + case SVGA3DOP_SINCOS: + { + struct sh_opcode_info info = *svga_opcode_info(op.opcode); + + if ((di.is_ps && di.version >= SVGA3D_PS_30) || + (!di.is_ps && di.version >= SVGA3D_VS_30)) { + assert(info.num_src == 3); + + info.num_src = 1; + } + + dump_inst(&di, &assem, op, &info); + } + break; + + case SVGA3DOP_PHASE: + _debug_printf( "phase\n" ); + assem += sizeof( struct sh_op ) / sizeof( unsigned ); + break; + + case SVGA3DOP_COMMENT: + { + struct sh_comment comment = *(struct sh_comment *)assem; + + /* Ignore comment contents. */ + assem += sizeof(struct sh_comment) / sizeof(unsigned) + comment.size; + } + break; + + case SVGA3DOP_END: + finished = TRUE; + break; + + default: + { + const struct sh_opcode_info *info = svga_opcode_info(op.opcode); + + dump_inst(&di, &assem, op, info); + } + } + } +} diff --git a/src/gallium/drivers/svga/svgadump/svga_shader_dump.h b/src/gallium/drivers/svga/svgadump/svga_shader_dump.h new file mode 100644 index 0000000..a2657ac --- /dev/null +++ b/src/gallium/drivers/svga/svgadump/svga_shader_dump.h @@ -0,0 +1,42 @@ +/********************************************************** + * 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 + * SVGA Shader Dump Facilities + * + * @author Michal Krol + */ + +#ifndef SVGA_SHADER_DUMP_H +#define SVGA_SHADER_DUMP_H + +void +svga_shader_dump( + const unsigned *assem, + unsigned dwords, + unsigned do_binary ); + +#endif /* SVGA_SHADER_DUMP_H */ diff --git a/src/gallium/drivers/svga/svgadump/svga_shader_op.c b/src/gallium/drivers/svga/svgadump/svga_shader_op.c new file mode 100644 index 0000000..95612a8 --- /dev/null +++ b/src/gallium/drivers/svga/svgadump/svga_shader_op.c @@ -0,0 +1,168 @@ +/********************************************************** + * 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 + * SVGA Shader Token Opcode Info + * + * @author Michal Krol + */ + +#include "util/u_debug.h" +#include "svga_shader_op.h" + +#include "../svga_hw_reg.h" +#include "svga3d_shaderdefs.h" + +#define SVGA3DOP_INVALID SVGA3DOP_END +#define TGSI_OPCODE_INVALID TGSI_OPCODE_LAST + +static struct sh_opcode_info opcode_info[] = +{ + { "nop", 0, 0, 0, 0, SVGA3DOP_NOP }, + { "mov", 1, 1, 0, 0, SVGA3DOP_MOV, }, + { "add", 1, 2, 0, 0, SVGA3DOP_ADD, }, + { "sub", 1, 2, 0, 0, SVGA3DOP_SUB, }, + { "mad", 1, 3, 0, 0, SVGA3DOP_MAD, }, + { "mul", 1, 2, 0, 0, SVGA3DOP_MUL, }, + { "rcp", 1, 1, 0, 0, SVGA3DOP_RCP, }, + { "rsq", 1, 1, 0, 0, SVGA3DOP_RSQ, }, + { "dp3", 1, 2, 0, 0, SVGA3DOP_DP3, }, + { "dp4", 1, 2, 0, 0, SVGA3DOP_DP4, }, + { "min", 1, 2, 0, 0, SVGA3DOP_MIN, }, + { "max", 1, 2, 0, 0, SVGA3DOP_MAX, }, + { "slt", 1, 2, 0, 0, SVGA3DOP_SLT, }, + { "sge", 1, 2, 0, 0, SVGA3DOP_SGE, }, + { "exp", 1, 1, 0, 0, SVGA3DOP_EXP, }, + { "log", 1, 1, 0, 0, SVGA3DOP_LOG, }, + { "lit", 1, 1, 0, 0, SVGA3DOP_LIT, }, + { "dst", 1, 2, 0, 0, SVGA3DOP_DST, }, + { "lrp", 1, 3, 0, 0, SVGA3DOP_LRP, }, + { "frc", 1, 1, 0, 0, SVGA3DOP_FRC, }, + { "m4x4", 1, 2, 0, 0, SVGA3DOP_M4x4, }, + { "m4x3", 1, 2, 0, 0, SVGA3DOP_M4x3, }, + { "m3x4", 1, 2, 0, 0, SVGA3DOP_M3x4, }, + { "m3x3", 1, 2, 0, 0, SVGA3DOP_M3x3, }, + { "m3x2", 1, 2, 0, 0, SVGA3DOP_M3x2, }, + { "call", 0, 1, 0, 0, SVGA3DOP_CALL, }, + { "callnz", 0, 2, 0, 0, SVGA3DOP_CALLNZ, }, + { "loop", 0, 2, 0, 1, SVGA3DOP_LOOP, }, + { "ret", 0, 0, 0, 0, SVGA3DOP_RET, }, + { "endloop", 0, 0, 1, 0, SVGA3DOP_ENDLOOP, }, + { "label", 0, 1, 0, 0, SVGA3DOP_LABEL, }, + { "dcl", 0, 0, 0, 0, SVGA3DOP_DCL, }, + { "pow", 1, 2, 0, 0, SVGA3DOP_POW, }, + { "crs", 1, 2, 0, 0, SVGA3DOP_CRS, }, + { "sgn", 1, 3, 0, 0, SVGA3DOP_SGN, }, + { "abs", 1, 1, 0, 0, SVGA3DOP_ABS, }, + { "nrm", 1, 1, 0, 0, SVGA3DOP_NRM, }, /* 3-componenet normalization */ + { "sincos", 1, 3, 0, 0, SVGA3DOP_SINCOS, }, + { "rep", 0, 1, 0, 1, SVGA3DOP_REP, }, + { "endrep", 0, 0, 1, 0, SVGA3DOP_ENDREP, }, + { "if", 0, 1, 0, 1, SVGA3DOP_IF, }, + { "ifc", 0, 2, 0, 1, SVGA3DOP_IFC, }, + { "else", 0, 0, 1, 1, SVGA3DOP_ELSE, }, + { "endif", 0, 0, 1, 0, SVGA3DOP_ENDIF, }, + { "break", 0, 0, 0, 0, SVGA3DOP_BREAK, }, + { "breakc", 0, 2, 0, 0, SVGA3DOP_BREAKC, }, + { "mova", 1, 1, 0, 0, SVGA3DOP_MOVA, }, + { "defb", 0, 0, 0, 0, SVGA3DOP_DEFB, }, + { "defi", 0, 0, 0, 0, SVGA3DOP_DEFI, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "???", 0, 0, 0, 0, SVGA3DOP_INVALID, }, + { "texcoord", 1, 0, 0, 0, SVGA3DOP_TEXCOORD, }, + { "texkill", 1, 0, 0, 0, SVGA3DOP_TEXKILL, }, + { "tex", 1, 0, 0, 0, SVGA3DOP_TEX, }, + { "texbem", 1, 1, 0, 0, SVGA3DOP_TEXBEM, }, + { "texbeml", 1, 1, 0, 0, SVGA3DOP_TEXBEML, }, + { "texreg2ar", 1, 1, 0, 0, SVGA3DOP_TEXREG2AR, }, + { "texreg2gb", 1, 1, 0, 0, SVGA3DOP_TEXREG2GB, }, + { "texm3x2pad", 1, 1, 0, 0, SVGA3DOP_TEXM3x2PAD, }, + { "texm3x2tex", 1, 1, 0, 0, SVGA3DOP_TEXM3x2TEX, }, + { "texm3x3pad", 1, 1, 0, 0, SVGA3DOP_TEXM3x3PAD, }, + { "texm3x3tex", 1, 1, 0, 0, SVGA3DOP_TEXM3x3TEX, }, + { "reserved0", 0, 0, 0, 0, SVGA3DOP_RESERVED0, }, + { "texm3x3spec", 1, 2, 0, 0, SVGA3DOP_TEXM3x3SPEC, }, + { "texm3x3vspec", 1, 1, 0, 0, SVGA3DOP_TEXM3x3VSPEC,}, + { "expp", 1, 1, 0, 0, SVGA3DOP_EXPP, }, + { "logp", 1, 1, 0, 0, SVGA3DOP_LOGP, }, + { "cnd", 1, 3, 0, 0, SVGA3DOP_CND, }, + { "def", 0, 0, 0, 0, SVGA3DOP_DEF, }, + { "texreg2rgb", 1, 1, 0, 0, SVGA3DOP_TEXREG2RGB, }, + { "texdp3tex", 1, 1, 0, 0, SVGA3DOP_TEXDP3TEX, }, + { "texm3x2depth", 1, 1, 0, 0, SVGA3DOP_TEXM3x2DEPTH,}, + { "texdp3", 1, 1, 0, 0, SVGA3DOP_TEXDP3, }, + { "texm3x3", 1, 1, 0, 0, SVGA3DOP_TEXM3x3, }, + { "texdepth", 1, 0, 0, 0, SVGA3DOP_TEXDEPTH, }, + { "cmp", 1, 3, 0, 0, SVGA3DOP_CMP, }, + { "bem", 1, 2, 0, 0, SVGA3DOP_BEM, }, + { "dp2add", 1, 3, 0, 0, SVGA3DOP_DP2ADD, }, + { "dsx", 1, 1, 0, 0, SVGA3DOP_INVALID, }, + { "dsy", 1, 1, 0, 0, SVGA3DOP_INVALID, }, + { "texldd", 1, 4, 0, 0, SVGA3DOP_INVALID, }, + { "setp", 1, 2, 0, 0, SVGA3DOP_SETP, }, + { "texldl", 1, 2, 0, 0, SVGA3DOP_INVALID, }, + { "breakp", 0, 1, 0, 0, SVGA3DOP_INVALID, }, +}; + +const struct sh_opcode_info *svga_opcode_info( uint op ) +{ + struct sh_opcode_info *info; + + if (op >= sizeof( opcode_info ) / sizeof( opcode_info[0] )) { + /* The opcode is either PHASE, COMMENT, END or out of range. + */ + assert( 0 ); + return NULL; + } + + info = &opcode_info[op]; + + if (info->svga_opcode == SVGA3DOP_INVALID) { + /* No valid information. Please provide number of dst/src registers. + */ + assert( 0 ); + return NULL; + } + + /* Sanity check. + */ + assert( op == info->svga_opcode ); + + return info; +} diff --git a/src/gallium/drivers/svga/svgadump/svga_shader_op.h b/src/gallium/drivers/svga/svgadump/svga_shader_op.h new file mode 100644 index 0000000..a5ccae5 --- /dev/null +++ b/src/gallium/drivers/svga/svgadump/svga_shader_op.h @@ -0,0 +1,48 @@ +/********************************************************** + * 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 + * SVGA Shader Token Opcode Info + * + * @author Michal Krol + */ + +#ifndef SVGA_SHADER_OP_H +#define SVGA_SHADER_OP_H + +struct sh_opcode_info +{ + const char *mnemonic; + unsigned num_dst:8; + unsigned num_src:8; + unsigned pre_dedent:1; + unsigned post_indent:1; + unsigned svga_opcode:16; +}; + +const struct sh_opcode_info *svga_opcode_info( unsigned op ); + +#endif /* SVGA_SHADER_OP_H */ diff --git a/src/gallium/drivers/trace/Makefile b/src/gallium/drivers/trace/Makefile new file mode 100644 index 0000000..99e5fb8 --- /dev/null +++ b/src/gallium/drivers/trace/Makefile @@ -0,0 +1,13 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = trace + +C_SOURCES = \ + tr_context.c \ + tr_dump.c \ + tr_dump_state.c \ + tr_screen.c \ + tr_texture.c + +include ../../Makefile.template diff --git a/src/gallium/drivers/trace/SConscript b/src/gallium/drivers/trace/SConscript new file mode 100644 index 0000000..1384fe3 --- /dev/null +++ b/src/gallium/drivers/trace/SConscript @@ -0,0 +1,17 @@ +Import('*') + +env = env.Clone() + +trace = env.ConvenienceLibrary( + target = 'trace', + source = [ + 'tr_context.c', + 'tr_dump.c', + 'tr_dump_state.c', + 'tr_screen.c', + 'tr_texture.c', + ]) + +env.Alias('trace', trace) + +Export('trace') diff --git a/src/gallium/drivers/trace/tr_context.c b/src/gallium/drivers/trace/tr_context.c new file mode 100644 index 0000000..eaabae8 --- /dev/null +++ b/src/gallium/drivers/trace/tr_context.c @@ -0,0 +1,1516 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_simple_list.h" + +#include "pipe/p_format.h" +#include "pipe/p_screen.h" + +#include "tr_dump.h" +#include "tr_dump_state.h" +#include "tr_public.h" +#include "tr_screen.h" +#include "tr_texture.h" +#include "tr_context.h" + + + + + +static INLINE struct pipe_resource * +trace_resource_unwrap(struct trace_context *tr_ctx, + struct pipe_resource *resource) +{ + struct trace_resource *tr_tex; + + if(!resource) + return NULL; + + tr_tex = trace_resource(resource); + + assert(tr_tex->resource); + return tr_tex->resource; +} + + +static INLINE struct pipe_surface * +trace_surface_unwrap(struct trace_context *tr_ctx, + struct pipe_surface *surface) +{ + struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen); + struct trace_surface *tr_surf; + + if(!surface) + return NULL; + + assert(surface->texture); + if(!surface->texture) + return surface; + + tr_surf = trace_surface(surface); + + assert(tr_surf->surface); + assert(tr_surf->surface->texture->screen == tr_scr->screen); + (void) tr_scr; + return tr_surf->surface; +} + + +static INLINE void +trace_context_draw_vbo(struct pipe_context *_pipe, + const struct pipe_draw_info *info) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "draw_vbo"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(draw_info, info); + + pipe->draw_vbo(pipe, info); + + trace_dump_call_end(); +} + + +static INLINE struct pipe_query * +trace_context_create_query(struct pipe_context *_pipe, + unsigned query_type) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + struct pipe_query *result; + + trace_dump_call_begin("pipe_context", "create_query"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(uint, query_type); + + result = pipe->create_query(pipe, query_type); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + return result; +} + + +static INLINE void +trace_context_destroy_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "destroy_query"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, query); + + pipe->destroy_query(pipe, query); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_begin_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "begin_query"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, query); + + pipe->begin_query(pipe, query); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_end_query(struct pipe_context *_pipe, + struct pipe_query *query) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "end_query"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, query); + + pipe->end_query(pipe, query); + + trace_dump_call_end(); +} + + +static INLINE boolean +trace_context_get_query_result(struct pipe_context *_pipe, + struct pipe_query *query, + boolean wait, + void *presult) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + uint64_t result; + boolean _result; + + trace_dump_call_begin("pipe_context", "get_query_result"); + + trace_dump_arg(ptr, pipe); + + _result = pipe->get_query_result(pipe, query, wait, presult); + result = *((uint64_t*)presult); + + trace_dump_arg(uint, result); + trace_dump_ret(bool, _result); + + trace_dump_call_end(); + + return _result; +} + + +static INLINE void * +trace_context_create_blend_state(struct pipe_context *_pipe, + const struct pipe_blend_state *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + void * result; + + trace_dump_call_begin("pipe_context", "create_blend_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(blend_state, state); + + result = pipe->create_blend_state(pipe, state); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + return result; +} + + +static INLINE void +trace_context_bind_blend_state(struct pipe_context *_pipe, + void *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "bind_blend_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, state); + + pipe->bind_blend_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_delete_blend_state(struct pipe_context *_pipe, + void *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "delete_blend_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, state); + + pipe->delete_blend_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void * +trace_context_create_sampler_state(struct pipe_context *_pipe, + const struct pipe_sampler_state *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + void * result; + + trace_dump_call_begin("pipe_context", "create_sampler_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(sampler_state, state); + + result = pipe->create_sampler_state(pipe, state); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + return result; +} + + +static INLINE void +trace_context_bind_fragment_sampler_states(struct pipe_context *_pipe, + unsigned num_states, + void **states) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "bind_fragment_sampler_states"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(uint, num_states); + trace_dump_arg_array(ptr, states, num_states); + + pipe->bind_fragment_sampler_states(pipe, num_states, states); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_bind_vertex_sampler_states(struct pipe_context *_pipe, + unsigned num_states, + void **states) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + if (!pipe->bind_vertex_sampler_states) + return; + + trace_dump_call_begin("pipe_context", "bind_vertex_sampler_states"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(uint, num_states); + trace_dump_arg_array(ptr, states, num_states); + + pipe->bind_vertex_sampler_states(pipe, num_states, states); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_delete_sampler_state(struct pipe_context *_pipe, + void *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "delete_sampler_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, state); + + pipe->delete_sampler_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void * +trace_context_create_rasterizer_state(struct pipe_context *_pipe, + const struct pipe_rasterizer_state *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + void * result; + + trace_dump_call_begin("pipe_context", "create_rasterizer_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(rasterizer_state, state); + + result = pipe->create_rasterizer_state(pipe, state); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + return result; +} + + +static INLINE void +trace_context_bind_rasterizer_state(struct pipe_context *_pipe, + void *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "bind_rasterizer_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, state); + + pipe->bind_rasterizer_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_delete_rasterizer_state(struct pipe_context *_pipe, + void *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "delete_rasterizer_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, state); + + pipe->delete_rasterizer_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void * +trace_context_create_depth_stencil_alpha_state(struct pipe_context *_pipe, + const struct pipe_depth_stencil_alpha_state *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + void * result; + + trace_dump_call_begin("pipe_context", "create_depth_stencil_alpha_state"); + + result = pipe->create_depth_stencil_alpha_state(pipe, state); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(depth_stencil_alpha_state, state); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + return result; +} + + +static INLINE void +trace_context_bind_depth_stencil_alpha_state(struct pipe_context *_pipe, + void *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "bind_depth_stencil_alpha_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, state); + + pipe->bind_depth_stencil_alpha_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_delete_depth_stencil_alpha_state(struct pipe_context *_pipe, + void *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "delete_depth_stencil_alpha_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, state); + + pipe->delete_depth_stencil_alpha_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void * +trace_context_create_fs_state(struct pipe_context *_pipe, + const struct pipe_shader_state *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + void * result; + + trace_dump_call_begin("pipe_context", "create_fs_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(shader_state, state); + + result = pipe->create_fs_state(pipe, state); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + return result; +} + + +static INLINE void +trace_context_bind_fs_state(struct pipe_context *_pipe, + void *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "bind_fs_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, state); + + pipe->bind_fs_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_delete_fs_state(struct pipe_context *_pipe, + void *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "delete_fs_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, state); + + pipe->delete_fs_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void * +trace_context_create_vs_state(struct pipe_context *_pipe, + const struct pipe_shader_state *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + void * result; + + trace_dump_call_begin("pipe_context", "create_vs_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(shader_state, state); + + result = pipe->create_vs_state(pipe, state); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + return result; +} + + +static INLINE void +trace_context_bind_vs_state(struct pipe_context *_pipe, + void *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "bind_vs_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, state); + + pipe->bind_vs_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_delete_vs_state(struct pipe_context *_pipe, + void *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "delete_vs_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, state); + + pipe->delete_vs_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void * +trace_context_create_vertex_elements_state(struct pipe_context *_pipe, + unsigned num_elements, + const struct pipe_vertex_element *elements) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + void * result; + + trace_dump_call_begin("pipe_context", "create_vertex_elements_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(uint, num_elements); + + trace_dump_arg_begin("elements"); + trace_dump_struct_array(vertex_element, elements, num_elements); + trace_dump_arg_end(); + + result = pipe->create_vertex_elements_state(pipe, num_elements, elements); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + return result; +} + + +static INLINE void +trace_context_bind_vertex_elements_state(struct pipe_context *_pipe, + void *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "bind_vertex_elements_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, state); + + pipe->bind_vertex_elements_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_delete_vertex_elements_state(struct pipe_context *_pipe, + void *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "delete_vertex_elements_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, state); + + pipe->delete_vertex_elements_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_set_blend_color(struct pipe_context *_pipe, + const struct pipe_blend_color *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "set_blend_color"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(blend_color, state); + + pipe->set_blend_color(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_set_stencil_ref(struct pipe_context *_pipe, + const struct pipe_stencil_ref *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "set_stencil_ref"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(stencil_ref, state); + + pipe->set_stencil_ref(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_set_clip_state(struct pipe_context *_pipe, + const struct pipe_clip_state *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "set_clip_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(clip_state, state); + + pipe->set_clip_state(pipe, state); + + trace_dump_call_end(); +} + +static INLINE void +trace_context_set_sample_mask(struct pipe_context *_pipe, + unsigned sample_mask) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "set_sample_mask"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(uint, sample_mask); + + pipe->set_sample_mask(pipe, sample_mask); + + trace_dump_call_end(); +} + +static INLINE void +trace_context_set_constant_buffer(struct pipe_context *_pipe, + uint shader, uint index, + struct pipe_resource *buffer) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + if (buffer) { + buffer = trace_resource_unwrap(tr_ctx, buffer); + } + + trace_dump_call_begin("pipe_context", "set_constant_buffer"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(uint, shader); + trace_dump_arg(uint, index); + trace_dump_arg(ptr, buffer); + + pipe->set_constant_buffer(pipe, shader, index, buffer); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_set_framebuffer_state(struct pipe_context *_pipe, + const struct pipe_framebuffer_state *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + struct pipe_framebuffer_state unwrapped_state; + unsigned i; + + + /* Unwrap the input state */ + memcpy(&unwrapped_state, state, sizeof(unwrapped_state)); + for(i = 0; i < state->nr_cbufs; ++i) + unwrapped_state.cbufs[i] = trace_surface_unwrap(tr_ctx, state->cbufs[i]); + for(i = state->nr_cbufs; i < PIPE_MAX_COLOR_BUFS; ++i) + unwrapped_state.cbufs[i] = NULL; + unwrapped_state.zsbuf = trace_surface_unwrap(tr_ctx, state->zsbuf); + state = &unwrapped_state; + + trace_dump_call_begin("pipe_context", "set_framebuffer_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(framebuffer_state, state); + + pipe->set_framebuffer_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_set_polygon_stipple(struct pipe_context *_pipe, + const struct pipe_poly_stipple *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "set_polygon_stipple"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(poly_stipple, state); + + pipe->set_polygon_stipple(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_set_scissor_state(struct pipe_context *_pipe, + const struct pipe_scissor_state *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "set_scissor_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(scissor_state, state); + + pipe->set_scissor_state(pipe, state); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_set_viewport_state(struct pipe_context *_pipe, + const struct pipe_viewport_state *state) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "set_viewport_state"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(viewport_state, state); + + pipe->set_viewport_state(pipe, state); + + trace_dump_call_end(); +} + + +static struct pipe_sampler_view * +trace_create_sampler_view(struct pipe_context *_pipe, + struct pipe_resource *_resource, + const struct pipe_sampler_view *templ) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct trace_resource *tr_tex = trace_resource(_resource); + struct pipe_context *pipe = tr_ctx->pipe; + struct pipe_resource *texture = tr_tex->resource; + struct pipe_sampler_view *result; + struct trace_sampler_view *tr_view; + + trace_dump_call_begin("pipe_context", "create_sampler_view"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, texture); + trace_dump_arg(sampler_view_template, templ); + + result = pipe->create_sampler_view(pipe, texture, templ); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + /* + * Wrap pipe_sampler_view + */ + tr_view = CALLOC_STRUCT(trace_sampler_view); + tr_view->base = *templ; + tr_view->base.reference.count = 1; + tr_view->base.texture = NULL; + pipe_resource_reference(&tr_view->base.texture, _resource); + tr_view->base.context = _pipe; + tr_view->sampler_view = result; + result = &tr_view->base; + + return result; +} + + +static void +trace_sampler_view_destroy(struct pipe_context *_pipe, + struct pipe_sampler_view *_view) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct trace_sampler_view *tr_view = trace_sampler_view(_view); + struct pipe_context *pipe = tr_ctx->pipe; + struct pipe_sampler_view *view = tr_view->sampler_view; + + trace_dump_call_begin("pipe_context", "sampler_view_destroy"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, view); + + pipe_sampler_view_reference(&tr_view->sampler_view, NULL); + + trace_dump_call_end(); + + pipe_resource_reference(&_view->texture, NULL); + FREE(_view); +} + +/******************************************************************** + * surface + */ + + +static struct pipe_surface * +trace_create_surface(struct pipe_context *_pipe, + struct pipe_resource *_texture, + const struct pipe_surface *surf_tmpl) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct trace_resource *tr_tex = trace_resource(_texture); + struct pipe_context *pipe = tr_ctx->pipe; + struct pipe_resource *texture = tr_tex->resource; + struct pipe_surface *result = NULL; + + trace_dump_call_begin("pipe_context", "create_surface"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, texture); + /* hmm some values unitialized there */ + trace_dump_arg(surface, surf_tmpl); + + result = pipe->create_surface(pipe, texture, surf_tmpl); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + result = trace_surf_create(tr_tex, result); + + return result; +} + + +static void +trace_surface_destroy(struct pipe_context *_pipe, + struct pipe_surface *_surface) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + struct trace_surface *tr_surf = trace_surface(_surface); + struct pipe_surface *surface = tr_surf->surface; + + trace_dump_call_begin("pipe_context", "surface_destroy"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, surface); + + trace_dump_call_end(); + + trace_surf_destroy(tr_surf); +} + + +static INLINE void +trace_context_set_fragment_sampler_views(struct pipe_context *_pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct trace_sampler_view *tr_view; + struct pipe_context *pipe = tr_ctx->pipe; + struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS]; + unsigned i; + + for(i = 0; i < num; ++i) { + tr_view = trace_sampler_view(views[i]); + unwrapped_views[i] = tr_view ? tr_view->sampler_view : NULL; + } + views = unwrapped_views; + + trace_dump_call_begin("pipe_context", "set_fragment_sampler_views"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(uint, num); + trace_dump_arg_array(ptr, views, num); + + pipe->set_fragment_sampler_views(pipe, num, views); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_set_vertex_sampler_views(struct pipe_context *_pipe, + unsigned num, + struct pipe_sampler_view **views) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct trace_sampler_view *tr_view; + struct pipe_context *pipe = tr_ctx->pipe; + struct pipe_sampler_view *unwrapped_views[PIPE_MAX_VERTEX_SAMPLERS]; + unsigned i; + + if (!pipe->set_vertex_sampler_views) + return; + + for(i = 0; i < num; ++i) { + tr_view = trace_sampler_view(views[i]); + unwrapped_views[i] = tr_view ? tr_view->sampler_view : NULL; + } + views = unwrapped_views; + + trace_dump_call_begin("pipe_context", "set_vertex_sampler_views"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(uint, num); + trace_dump_arg_array(ptr, views, num); + + pipe->set_vertex_sampler_views(pipe, num, views); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_set_vertex_buffers(struct pipe_context *_pipe, + unsigned num_buffers, + const struct pipe_vertex_buffer *buffers) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + unsigned i; + + trace_dump_call_begin("pipe_context", "set_vertex_buffers"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(uint, num_buffers); + + trace_dump_arg_begin("buffers"); + trace_dump_struct_array(vertex_buffer, buffers, num_buffers); + trace_dump_arg_end(); + + if (num_buffers) { + struct pipe_vertex_buffer *_buffers = MALLOC(num_buffers * sizeof(*_buffers)); + memcpy(_buffers, buffers, num_buffers * sizeof(*_buffers)); + for (i = 0; i < num_buffers; i++) + _buffers[i].buffer = trace_resource_unwrap(tr_ctx, buffers[i].buffer); + pipe->set_vertex_buffers(pipe, num_buffers, _buffers); + FREE(_buffers); + } else { + pipe->set_vertex_buffers(pipe, num_buffers, NULL); + } + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_set_index_buffer(struct pipe_context *_pipe, + const struct pipe_index_buffer *ib) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "set_index_buffer"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(index_buffer, ib); + + if (ib) { + struct pipe_index_buffer _ib; + _ib = *ib; + _ib.buffer = trace_resource_unwrap(tr_ctx, ib->buffer); + pipe->set_index_buffer(pipe, &_ib); + } else { + pipe->set_index_buffer(pipe, NULL); + } + + trace_dump_call_end(); +} + +static INLINE void +trace_context_resource_copy_region(struct pipe_context *_pipe, + struct pipe_resource *dst, + unsigned dst_level, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource *src, + unsigned src_level, + const struct pipe_box *src_box) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + dst = trace_resource_unwrap(tr_ctx, dst); + src = trace_resource_unwrap(tr_ctx, src); + + trace_dump_call_begin("pipe_context", "resource_copy_region"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, dst); + trace_dump_arg(uint, dst_level); + trace_dump_arg(uint, dstx); + trace_dump_arg(uint, dsty); + trace_dump_arg(uint, dstz); + trace_dump_arg(ptr, src); + trace_dump_arg(uint, src_level); + trace_dump_arg(box, src_box); + + pipe->resource_copy_region(pipe, + dst, dst_level, dstx, dsty, dstz, + src, src_level, src_box); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_clear(struct pipe_context *_pipe, + unsigned buffers, + const float *rgba, + double depth, + unsigned stencil) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "clear"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(uint, buffers); + if (rgba) + trace_dump_arg_array(float, rgba, 4); + else + trace_dump_null(); + trace_dump_arg(float, depth); + trace_dump_arg(uint, stencil); + + pipe->clear(pipe, buffers, rgba, depth, stencil); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_clear_render_target(struct pipe_context *_pipe, + struct pipe_surface *dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + dst = trace_surface_unwrap(tr_ctx, dst); + + trace_dump_call_begin("pipe_context", "clear_render_target"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, dst); + trace_dump_arg_array(float, rgba, 4); + trace_dump_arg(uint, dstx); + trace_dump_arg(uint, dsty); + trace_dump_arg(uint, width); + trace_dump_arg(uint, height); + + pipe->clear_render_target(pipe, dst, rgba, dstx, dsty, width, height); + + trace_dump_call_end(); +} + +static INLINE void +trace_context_clear_depth_stencil(struct pipe_context *_pipe, + struct pipe_surface *dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + dst = trace_surface_unwrap(tr_ctx, dst); + + trace_dump_call_begin("pipe_context", "clear_depth_stencil"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, dst); + trace_dump_arg(uint, clear_flags); + trace_dump_arg(float, depth); + trace_dump_arg(uint, stencil); + trace_dump_arg(uint, dstx); + trace_dump_arg(uint, dsty); + trace_dump_arg(uint, width); + trace_dump_arg(uint, height); + + pipe->clear_depth_stencil(pipe, dst, clear_flags, depth, stencil, + dstx, dsty, width, height); + + trace_dump_call_end(); +} + +static INLINE void +trace_context_flush(struct pipe_context *_pipe, + unsigned flags, + struct pipe_fence_handle **fence) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "flush"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(uint, flags); + + pipe->flush(pipe, flags, fence); + + if(fence) + trace_dump_ret(ptr, *fence); + + trace_dump_call_end(); +} + + +static INLINE void +trace_context_destroy(struct pipe_context *_pipe) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + + trace_dump_call_begin("pipe_context", "destroy"); + trace_dump_arg(ptr, pipe); + trace_dump_call_end(); + + pipe->destroy(pipe); + + FREE(tr_ctx); +} + +static unsigned int +trace_is_resource_referenced( struct pipe_context *_pipe, + struct pipe_resource *_resource, + unsigned level, int layer) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct trace_resource *tr_tex = trace_resource(_resource); + struct pipe_context *pipe = tr_ctx->pipe; + struct pipe_resource *texture = tr_tex->resource; + unsigned int referenced; + + trace_dump_call_begin("pipe_context", "is_resource_referenced"); + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, texture); + trace_dump_arg(uint, level); + trace_dump_arg(int, layer); + + referenced = pipe->is_resource_referenced(pipe, texture, level, layer); + + trace_dump_ret(uint, referenced); + trace_dump_call_end(); + + return referenced; +} + + +/******************************************************************** + * transfer + */ + + +static struct pipe_transfer * +trace_context_get_transfer(struct pipe_context *_context, + struct pipe_resource *_resource, + unsigned level, + unsigned usage, + const struct pipe_box *box) +{ + struct trace_context *tr_context = trace_context(_context); + struct trace_resource *tr_tex = trace_resource(_resource); + struct pipe_context *context = tr_context->pipe; + struct pipe_resource *texture = tr_tex->resource; + struct pipe_transfer *result = NULL; + + assert(texture->screen == context->screen); + + /* + * Map and transfers can't be serialized so we convert all write transfers + * to transfer_inline_write and ignore read transfers. + */ + + result = context->get_transfer(context, texture, level, usage, box); + + if (result) + result = trace_transfer_create(tr_context, tr_tex, result); + + return result; +} + + +static void +trace_context_transfer_destroy(struct pipe_context *_context, + struct pipe_transfer *_transfer) +{ + struct trace_context *tr_context = trace_context(_context); + struct trace_transfer *tr_trans = trace_transfer(_transfer); + + trace_transfer_destroy(tr_context, tr_trans); +} + + +static void * +trace_context_transfer_map(struct pipe_context *_context, + struct pipe_transfer *_transfer) +{ + struct trace_context *tr_context = trace_context(_context); + struct trace_transfer *tr_trans = trace_transfer(_transfer); + struct pipe_context *context = tr_context->pipe; + struct pipe_transfer *transfer = tr_trans->transfer; + void *map; + + map = context->transfer_map(context, transfer); + if(map) { + if(transfer->usage & PIPE_TRANSFER_WRITE) { + assert(!tr_trans->map); + tr_trans->map = map; + } + } + + return map; +} + + +static void +trace_context_transfer_flush_region( struct pipe_context *_context, + struct pipe_transfer *_transfer, + const struct pipe_box *box) +{ + struct trace_context *tr_context = trace_context(_context); + struct trace_transfer *tr_transfer = trace_transfer(_transfer); + struct pipe_context *context = tr_context->pipe; + struct pipe_transfer *transfer = tr_transfer->transfer; + + context->transfer_flush_region(context, + transfer, + box); +} + +static void +trace_context_transfer_unmap(struct pipe_context *_context, + struct pipe_transfer *_transfer) +{ + struct trace_context *tr_ctx = trace_context(_context); + struct trace_transfer *tr_trans = trace_transfer(_transfer); + struct pipe_context *context = tr_ctx->pipe; + struct pipe_transfer *transfer = tr_trans->transfer; + + if(tr_trans->map) { + /* + * Fake a transfer_inline_write + */ + + struct pipe_resource *resource = transfer->resource; + unsigned level = transfer->level; + unsigned usage = transfer->usage; + const struct pipe_box *box = &transfer->box; + unsigned stride = transfer->stride; + unsigned layer_stride = transfer->layer_stride; + + trace_dump_call_begin("pipe_context", "transfer_inline_write"); + + trace_dump_arg(ptr, context); + trace_dump_arg(ptr, resource); + trace_dump_arg(uint, level); + trace_dump_arg(uint, usage); + trace_dump_arg(box, box); + + trace_dump_arg_begin("data"); + trace_dump_box_bytes(tr_trans->map, + resource->format, + box, + stride, + layer_stride); + trace_dump_arg_end(); + + trace_dump_arg(uint, stride); + trace_dump_arg(uint, layer_stride); + + trace_dump_call_end(); + + tr_trans->map = NULL; + } + + context->transfer_unmap(context, transfer); +} + + +static void +trace_context_transfer_inline_write(struct pipe_context *_context, + struct pipe_resource *_resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride) +{ + struct trace_context *tr_context = trace_context(_context); + struct trace_resource *tr_tex = trace_resource(_resource); + struct pipe_context *context = tr_context->pipe; + struct pipe_resource *resource = tr_tex->resource; + + assert(resource->screen == context->screen); + + trace_dump_call_begin("pipe_context", "transfer_inline_write"); + + trace_dump_arg(ptr, context); + trace_dump_arg(ptr, resource); + trace_dump_arg(uint, level); + trace_dump_arg(uint, usage); + trace_dump_arg(box, box); + + trace_dump_arg_begin("data"); + trace_dump_box_bytes(data, + resource->format, + box, + stride, + layer_stride); + trace_dump_arg_end(); + + trace_dump_arg(uint, stride); + trace_dump_arg(uint, layer_stride); + + trace_dump_call_end(); + + context->transfer_inline_write(context, resource, + level, usage, box, data, stride, layer_stride); +} + + + + +static const struct debug_named_value rbug_blocker_flags[] = { + {"before", 1, NULL}, + {"after", 2, NULL}, + DEBUG_NAMED_VALUE_END +}; + +struct pipe_context * +trace_context_create(struct trace_screen *tr_scr, + struct pipe_context *pipe) +{ + struct trace_context *tr_ctx; + + if(!pipe) + goto error1; + + if(!trace_enabled()) + goto error1; + + tr_ctx = CALLOC_STRUCT(trace_context); + if(!tr_ctx) + goto error1; + + tr_ctx->base.winsys = NULL; + tr_ctx->base.priv = pipe->priv; /* expose wrapped priv data */ + tr_ctx->base.screen = &tr_scr->base; + + tr_ctx->base.destroy = trace_context_destroy; + tr_ctx->base.draw_vbo = trace_context_draw_vbo; + tr_ctx->base.create_query = trace_context_create_query; + tr_ctx->base.destroy_query = trace_context_destroy_query; + tr_ctx->base.begin_query = trace_context_begin_query; + tr_ctx->base.end_query = trace_context_end_query; + tr_ctx->base.get_query_result = trace_context_get_query_result; + tr_ctx->base.create_blend_state = trace_context_create_blend_state; + tr_ctx->base.bind_blend_state = trace_context_bind_blend_state; + tr_ctx->base.delete_blend_state = trace_context_delete_blend_state; + tr_ctx->base.create_sampler_state = trace_context_create_sampler_state; + tr_ctx->base.bind_fragment_sampler_states = trace_context_bind_fragment_sampler_states; + tr_ctx->base.bind_vertex_sampler_states = trace_context_bind_vertex_sampler_states; + tr_ctx->base.delete_sampler_state = trace_context_delete_sampler_state; + tr_ctx->base.create_rasterizer_state = trace_context_create_rasterizer_state; + tr_ctx->base.bind_rasterizer_state = trace_context_bind_rasterizer_state; + tr_ctx->base.delete_rasterizer_state = trace_context_delete_rasterizer_state; + tr_ctx->base.create_depth_stencil_alpha_state = trace_context_create_depth_stencil_alpha_state; + tr_ctx->base.bind_depth_stencil_alpha_state = trace_context_bind_depth_stencil_alpha_state; + tr_ctx->base.delete_depth_stencil_alpha_state = trace_context_delete_depth_stencil_alpha_state; + tr_ctx->base.create_fs_state = trace_context_create_fs_state; + tr_ctx->base.bind_fs_state = trace_context_bind_fs_state; + tr_ctx->base.delete_fs_state = trace_context_delete_fs_state; + tr_ctx->base.create_vs_state = trace_context_create_vs_state; + tr_ctx->base.bind_vs_state = trace_context_bind_vs_state; + tr_ctx->base.delete_vs_state = trace_context_delete_vs_state; + tr_ctx->base.create_vertex_elements_state = trace_context_create_vertex_elements_state; + tr_ctx->base.bind_vertex_elements_state = trace_context_bind_vertex_elements_state; + tr_ctx->base.delete_vertex_elements_state = trace_context_delete_vertex_elements_state; + tr_ctx->base.set_blend_color = trace_context_set_blend_color; + tr_ctx->base.set_stencil_ref = trace_context_set_stencil_ref; + tr_ctx->base.set_clip_state = trace_context_set_clip_state; + tr_ctx->base.set_sample_mask = trace_context_set_sample_mask; + tr_ctx->base.set_constant_buffer = trace_context_set_constant_buffer; + tr_ctx->base.set_framebuffer_state = trace_context_set_framebuffer_state; + tr_ctx->base.set_polygon_stipple = trace_context_set_polygon_stipple; + tr_ctx->base.set_scissor_state = trace_context_set_scissor_state; + tr_ctx->base.set_viewport_state = trace_context_set_viewport_state; + tr_ctx->base.set_fragment_sampler_views = trace_context_set_fragment_sampler_views; + tr_ctx->base.set_vertex_sampler_views = trace_context_set_vertex_sampler_views; + tr_ctx->base.create_sampler_view = trace_create_sampler_view; + tr_ctx->base.sampler_view_destroy = trace_sampler_view_destroy; + tr_ctx->base.create_surface = trace_create_surface; + tr_ctx->base.surface_destroy = trace_surface_destroy; + tr_ctx->base.set_vertex_buffers = trace_context_set_vertex_buffers; + tr_ctx->base.set_index_buffer = trace_context_set_index_buffer; + tr_ctx->base.resource_copy_region = trace_context_resource_copy_region; + tr_ctx->base.clear = trace_context_clear; + tr_ctx->base.clear_render_target = trace_context_clear_render_target; + tr_ctx->base.clear_depth_stencil = trace_context_clear_depth_stencil; + tr_ctx->base.flush = trace_context_flush; + tr_ctx->base.is_resource_referenced = trace_is_resource_referenced; + + tr_ctx->base.get_transfer = trace_context_get_transfer; + tr_ctx->base.transfer_destroy = trace_context_transfer_destroy; + tr_ctx->base.transfer_map = trace_context_transfer_map; + tr_ctx->base.transfer_unmap = trace_context_transfer_unmap; + tr_ctx->base.transfer_flush_region = trace_context_transfer_flush_region; + tr_ctx->base.transfer_inline_write = trace_context_transfer_inline_write; + + tr_ctx->pipe = pipe; + + return &tr_ctx->base; + +error1: + return pipe; +} diff --git a/src/gallium/drivers/trace/tr_context.h b/src/gallium/drivers/trace/tr_context.h new file mode 100644 index 0000000..dadbe56 --- /dev/null +++ b/src/gallium/drivers/trace/tr_context.h @@ -0,0 +1,70 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef TR_CONTEXT_H_ +#define TR_CONTEXT_H_ + + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" +#include "pipe/p_context.h" + +#include "tr_screen.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +struct trace_screen; + +struct trace_context +{ + struct pipe_context base; + + struct pipe_context *pipe; +}; + + +static INLINE struct trace_context * +trace_context(struct pipe_context *pipe) +{ + assert(pipe); + return (struct trace_context *)pipe; +} + + +struct pipe_context * +trace_context_create(struct trace_screen *tr_scr, + struct pipe_context *pipe); + + +#ifdef __cplusplus +} +#endif + +#endif /* TR_CONTEXT_H_ */ diff --git a/src/gallium/drivers/trace/tr_dump.c b/src/gallium/drivers/trace/tr_dump.c new file mode 100644 index 0000000..51a4ea9 --- /dev/null +++ b/src/gallium/drivers/trace/tr_dump.c @@ -0,0 +1,635 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/** + * @file + * Trace dumping functions. + * + * For now we just use standard XML for dumping the trace calls, as this is + * simple to write, parse, and visually inspect, but the actual representation + * is abstracted out of this file, so that we can switch to a binary + * representation if/when it becomes justified. + * + * @author Jose Fonseca + */ + +#include "pipe/p_config.h" + +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) +#include +#endif + +#include "pipe/p_compiler.h" +#include "os/os_thread.h" +#include "os/os_stream.h" +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "util/u_string.h" +#include "util/u_math.h" +#include "util/u_format.h" + +#include "tr_dump.h" +#include "tr_screen.h" +#include "tr_texture.h" + + +static struct os_stream *stream = NULL; +static unsigned refcount = 0; +static pipe_mutex call_mutex; +static long unsigned call_no = 0; +static boolean dumping = FALSE; +static boolean initialized = FALSE; + + +static INLINE void +trace_dump_write(const char *buf, size_t size) +{ + if(stream) + os_stream_write(stream, buf, size); +} + + +static INLINE void +trace_dump_writes(const char *s) +{ + trace_dump_write(s, strlen(s)); +} + + +static INLINE void +trace_dump_writef(const char *format, ...) +{ + static char buf[1024]; + unsigned len; + va_list ap; + va_start(ap, format); + len = util_vsnprintf(buf, sizeof(buf), format, ap); + va_end(ap); + trace_dump_write(buf, len); +} + + +static INLINE void +trace_dump_escape(const char *str) +{ + const unsigned char *p = (const unsigned char *)str; + unsigned char c; + while((c = *p++) != 0) { + if(c == '<') + trace_dump_writes("<"); + else if(c == '>') + trace_dump_writes(">"); + else if(c == '&') + trace_dump_writes("&"); + else if(c == '\'') + trace_dump_writes("'"); + else if(c == '\"') + trace_dump_writes("""); + else if(c >= 0x20 && c <= 0x7e) + trace_dump_writef("%c", c); + else + trace_dump_writef("&#%u;", c); + } +} + + +static INLINE void +trace_dump_indent(unsigned level) +{ + unsigned i; + for(i = 0; i < level; ++i) + trace_dump_writes("\t"); +} + + +static INLINE void +trace_dump_newline(void) +{ + trace_dump_writes("\n"); +} + + +static INLINE void +trace_dump_tag(const char *name) +{ + trace_dump_writes("<"); + trace_dump_writes(name); + trace_dump_writes("/>"); +} + + +static INLINE void +trace_dump_tag_begin(const char *name) +{ + trace_dump_writes("<"); + trace_dump_writes(name); + trace_dump_writes(">"); +} + +static INLINE void +trace_dump_tag_begin1(const char *name, + const char *attr1, const char *value1) +{ + trace_dump_writes("<"); + trace_dump_writes(name); + trace_dump_writes(" "); + trace_dump_writes(attr1); + trace_dump_writes("='"); + trace_dump_escape(value1); + trace_dump_writes("'>"); +} + + +static INLINE void +trace_dump_tag_begin2(const char *name, + const char *attr1, const char *value1, + const char *attr2, const char *value2) +{ + trace_dump_writes("<"); + trace_dump_writes(name); + trace_dump_writes(" "); + trace_dump_writes(attr1); + trace_dump_writes("=\'"); + trace_dump_escape(value1); + trace_dump_writes("\' "); + trace_dump_writes(attr2); + trace_dump_writes("=\'"); + trace_dump_escape(value2); + trace_dump_writes("\'>"); +} + + +static INLINE void +trace_dump_tag_begin3(const char *name, + const char *attr1, const char *value1, + const char *attr2, const char *value2, + const char *attr3, const char *value3) +{ + trace_dump_writes("<"); + trace_dump_writes(name); + trace_dump_writes(" "); + trace_dump_writes(attr1); + trace_dump_writes("=\'"); + trace_dump_escape(value1); + trace_dump_writes("\' "); + trace_dump_writes(attr2); + trace_dump_writes("=\'"); + trace_dump_escape(value2); + trace_dump_writes("\' "); + trace_dump_writes(attr3); + trace_dump_writes("=\'"); + trace_dump_escape(value3); + trace_dump_writes("\'>"); +} + + +static INLINE void +trace_dump_tag_end(const char *name) +{ + trace_dump_writes(""); +} + +static void +trace_dump_trace_close(void) +{ + if(stream) { + trace_dump_writes("\n"); + os_stream_close(stream); + stream = NULL; + refcount = 0; + call_no = 0; + pipe_mutex_destroy(call_mutex); + } +} + +void trace_dump_init() +{ + if (initialized) + return; + + pipe_mutex_init(call_mutex); + dumping = FALSE; + initialized = TRUE; +} + +boolean trace_dump_trace_begin() +{ + const char *filename; + + assert(initialized); + + filename = debug_get_option("GALLIUM_TRACE", NULL); + if(!filename) + return FALSE; + + if(!stream) { + + stream = os_file_stream_create(filename); + if(!stream) + return FALSE; + + trace_dump_writes("\n"); + trace_dump_writes("\n"); + trace_dump_writes("\n"); + +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) + /* Linux applications rarely cleanup GL / Gallium resources so catch + * application exit here */ + atexit(trace_dump_trace_close); +#endif + } + + ++refcount; + + return TRUE; +} + +boolean trace_dump_trace_enabled(void) +{ + return stream ? TRUE : FALSE; +} + +void trace_dump_trace_end(void) +{ + if(stream) + if(!--refcount) + trace_dump_trace_close(); +} + +/* + * Call lock + */ + +void trace_dump_call_lock(void) +{ + pipe_mutex_lock(call_mutex); +} + +void trace_dump_call_unlock(void) +{ + pipe_mutex_unlock(call_mutex); +} + +/* + * Dumping control + */ + +void trace_dumping_start_locked(void) +{ + dumping = TRUE; +} + +void trace_dumping_stop_locked(void) +{ + dumping = FALSE; +} + +boolean trace_dumping_enabled_locked(void) +{ + return dumping; +} + +void trace_dumping_start(void) +{ + pipe_mutex_lock(call_mutex); + trace_dumping_start_locked(); + pipe_mutex_unlock(call_mutex); +} + +void trace_dumping_stop(void) +{ + pipe_mutex_lock(call_mutex); + trace_dumping_stop_locked(); + pipe_mutex_unlock(call_mutex); +} + +boolean trace_dumping_enabled(void) +{ + boolean ret; + pipe_mutex_lock(call_mutex); + ret = trace_dumping_enabled_locked(); + pipe_mutex_unlock(call_mutex); + return ret; +} + +/* + * Dump functions + */ + +void trace_dump_call_begin_locked(const char *klass, const char *method) +{ + if (!dumping) + return; + + ++call_no; + trace_dump_indent(1); + trace_dump_writes(""); + trace_dump_newline(); +} + +void trace_dump_call_end_locked(void) +{ + if (!dumping) + return; + + trace_dump_indent(1); + trace_dump_tag_end("call"); + trace_dump_newline(); + os_stream_flush(stream); +} + +void trace_dump_call_begin(const char *klass, const char *method) +{ + pipe_mutex_lock(call_mutex); + trace_dump_call_begin_locked(klass, method); +} + +void trace_dump_call_end(void) +{ + trace_dump_call_end_locked(); + pipe_mutex_unlock(call_mutex); +} + +void trace_dump_arg_begin(const char *name) +{ + if (!dumping) + return; + + trace_dump_indent(2); + trace_dump_tag_begin1("arg", "name", name); +} + +void trace_dump_arg_end(void) +{ + if (!dumping) + return; + + trace_dump_tag_end("arg"); + trace_dump_newline(); +} + +void trace_dump_ret_begin(void) +{ + if (!dumping) + return; + + trace_dump_indent(2); + trace_dump_tag_begin("ret"); +} + +void trace_dump_ret_end(void) +{ + if (!dumping) + return; + + trace_dump_tag_end("ret"); + trace_dump_newline(); +} + +void trace_dump_bool(int value) +{ + if (!dumping) + return; + + trace_dump_writef("%c", value ? '1' : '0'); +} + +void trace_dump_int(long long int value) +{ + if (!dumping) + return; + + trace_dump_writef("%lli", value); +} + +void trace_dump_uint(long long unsigned value) +{ + if (!dumping) + return; + + trace_dump_writef("%llu", value); +} + +void trace_dump_float(double value) +{ + if (!dumping) + return; + + trace_dump_writef("%g", value); +} + +void trace_dump_bytes(const void *data, + size_t size) +{ + static const char hex_table[16] = "0123456789ABCDEF"; + const uint8_t *p = data; + size_t i; + + if (!dumping) + return; + + trace_dump_writes(""); + for(i = 0; i < size; ++i) { + uint8_t byte = *p++; + char hex[2]; + hex[0] = hex_table[byte >> 4]; + hex[1] = hex_table[byte & 0xf]; + trace_dump_write(hex, 2); + } + trace_dump_writes(""); +} + +void trace_dump_box_bytes(const void *data, + enum pipe_format format, + const struct pipe_box *box, + unsigned stride, + unsigned slice_stride) +{ + size_t size; + + if (slice_stride) + size = box->depth * slice_stride; + else if (stride) + size = util_format_get_nblocksy(format, box->height) * stride; + else { + size = util_format_get_nblocksx(format, box->width) * util_format_get_blocksize(format); + } + + trace_dump_bytes(data, size); +} + +void trace_dump_string(const char *str) +{ + if (!dumping) + return; + + trace_dump_writes(""); + trace_dump_escape(str); + trace_dump_writes(""); +} + +void trace_dump_enum(const char *value) +{ + if (!dumping) + return; + + trace_dump_writes(""); + trace_dump_escape(value); + trace_dump_writes(""); +} + +void trace_dump_array_begin(void) +{ + if (!dumping) + return; + + trace_dump_writes(""); +} + +void trace_dump_array_end(void) +{ + if (!dumping) + return; + + trace_dump_writes(""); +} + +void trace_dump_elem_begin(void) +{ + if (!dumping) + return; + + trace_dump_writes(""); +} + +void trace_dump_elem_end(void) +{ + if (!dumping) + return; + + trace_dump_writes(""); +} + +void trace_dump_struct_begin(const char *name) +{ + if (!dumping) + return; + + trace_dump_writef("", name); +} + +void trace_dump_struct_end(void) +{ + if (!dumping) + return; + + trace_dump_writes(""); +} + +void trace_dump_member_begin(const char *name) +{ + if (!dumping) + return; + + trace_dump_writef("", name); +} + +void trace_dump_member_end(void) +{ + if (!dumping) + return; + + trace_dump_writes(""); +} + +void trace_dump_null(void) +{ + if (!dumping) + return; + + trace_dump_writes(""); +} + +void trace_dump_ptr(const void *value) +{ + if (!dumping) + return; + + if(value) + trace_dump_writef("0x%08lx", (unsigned long)(uintptr_t)value); + else + trace_dump_null(); +} + + +void trace_dump_resource_ptr(struct pipe_resource *_resource) +{ + if (!dumping) + return; + + if (_resource) { + struct trace_resource *tr_resource = trace_resource(_resource); + trace_dump_ptr(tr_resource->resource); + } else { + trace_dump_null(); + } +} + +void trace_dump_surface_ptr(struct pipe_surface *_surface) +{ + if (!dumping) + return; + + if (_surface) { + struct trace_surface *tr_surf = trace_surface(_surface); + trace_dump_ptr(tr_surf->surface); + } else { + trace_dump_null(); + } +} + +void trace_dump_transfer_ptr(struct pipe_transfer *_transfer) +{ + if (!dumping) + return; + + if (_transfer) { + struct trace_transfer *tr_tran = trace_transfer(_transfer); + trace_dump_ptr(tr_tran->transfer); + } else { + trace_dump_null(); + } +} diff --git a/src/gallium/drivers/trace/tr_dump.h b/src/gallium/drivers/trace/tr_dump.h new file mode 100644 index 0000000..74c5e83 --- /dev/null +++ b/src/gallium/drivers/trace/tr_dump.h @@ -0,0 +1,188 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Trace data dumping primitives. + */ + +#ifndef TR_DUMP_H +#define TR_DUMP_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" + +struct pipe_resource; +struct pipe_surface; +struct pipe_transfer; +struct pipe_box; + +/* + * Call before use. + */ +void trace_dump_init(void); + +/* + * Low level dumping controls. + * + * Opening the trace file and checking if that is opened. + */ +boolean trace_dump_trace_begin(void); +boolean trace_dump_trace_enabled(void); +void trace_dump_trace_end(void); + +/* + * Lock and unlock the call mutex. + * + * It used by the none locked version of dumping control + * and begin/end call dump functions. + * + * Begin takes the lock while end unlocks it. Use the _locked + * version to avoid locking/unlocking it. + */ +void trace_dump_call_lock(void); +void trace_dump_call_unlock(void); + +/* + * High level dumping control. + */ +void trace_dumping_start_locked(void); +void trace_dumping_stop_locked(void); +boolean trace_dumping_enabled_locked(void); +void trace_dumping_start(void); +void trace_dumping_stop(void); +boolean trace_dumping_enabled(void); + +void trace_dump_call_begin_locked(const char *klass, const char *method); +void trace_dump_call_end_locked(void); +void trace_dump_call_begin(const char *klass, const char *method); +void trace_dump_call_end(void); + +void trace_dump_arg_begin(const char *name); +void trace_dump_arg_end(void); +void trace_dump_ret_begin(void); +void trace_dump_ret_end(void); +void trace_dump_bool(int value); +void trace_dump_int(long long int value); +void trace_dump_uint(long long unsigned value); +void trace_dump_float(double value); +void trace_dump_bytes(const void *data, size_t size); +void trace_dump_box_bytes(const void *data, + enum pipe_format format, + const struct pipe_box *box, + unsigned stride, + unsigned slice_stride); +void trace_dump_string(const char *str); +void trace_dump_enum(const char *value); +void trace_dump_array_begin(void); +void trace_dump_array_end(void); +void trace_dump_elem_begin(void); +void trace_dump_elem_end(void); +void trace_dump_struct_begin(const char *name); +void trace_dump_struct_end(void); +void trace_dump_member_begin(const char *name); +void trace_dump_member_end(void); +void trace_dump_null(void); +void trace_dump_ptr(const void *value); +/* will turn a wrapped object into the real one and dump ptr */ +void trace_dump_resource_ptr(struct pipe_resource *_texture); +void trace_dump_surface_ptr(struct pipe_surface *_surface); +void trace_dump_transfer_ptr(struct pipe_transfer *_transfer); + +/* + * Code saving macros. + */ + +#define trace_dump_arg(_type, _arg) \ + do { \ + trace_dump_arg_begin(#_arg); \ + trace_dump_##_type(_arg); \ + trace_dump_arg_end(); \ + } while(0) + +#define trace_dump_arg_struct(_type, _arg) \ + do { \ + trace_dump_arg_begin(#_arg); \ + trace_dump_##_type(&_arg); \ + trace_dump_arg_end(); \ + } while(0) + +#define trace_dump_ret(_type, _arg) \ + do { \ + trace_dump_ret_begin(); \ + trace_dump_##_type(_arg); \ + trace_dump_ret_end(); \ + } while(0) + +#define trace_dump_array(_type, _obj, _size) \ + do { \ + size_t idx; \ + trace_dump_array_begin(); \ + for(idx = 0; idx < (_size); ++idx) { \ + trace_dump_elem_begin(); \ + trace_dump_##_type((_obj)[idx]); \ + trace_dump_elem_end(); \ + } \ + trace_dump_array_end(); \ + } while(0) + +#define trace_dump_struct_array(_type, _obj, _size) \ + do { \ + size_t idx; \ + trace_dump_array_begin(); \ + for(idx = 0; idx < (_size); ++idx) { \ + trace_dump_elem_begin(); \ + trace_dump_##_type(&(_obj)[idx]); \ + trace_dump_elem_end(); \ + } \ + trace_dump_array_end(); \ + } while(0) + +#define trace_dump_member(_type, _obj, _member) \ + do { \ + trace_dump_member_begin(#_member); \ + trace_dump_##_type((_obj)->_member); \ + trace_dump_member_end(); \ + } while(0) + +#define trace_dump_arg_array(_type, _arg, _size) \ + do { \ + trace_dump_arg_begin(#_arg); \ + trace_dump_array(_type, _arg, _size); \ + trace_dump_arg_end(); \ + } while(0) + +#define trace_dump_member_array(_type, _obj, _member) \ + do { \ + trace_dump_member_begin(#_member); \ + trace_dump_array(_type, (_obj)->_member, sizeof((_obj)->_member)/sizeof((_obj)->_member[0])); \ + trace_dump_member_end(); \ + } while(0) + + +#endif /* TR_DUMP_H */ diff --git a/src/gallium/drivers/trace/tr_dump_state.c b/src/gallium/drivers/trace/tr_dump_state.c new file mode 100644 index 0000000..155c869 --- /dev/null +++ b/src/gallium/drivers/trace/tr_dump_state.c @@ -0,0 +1,596 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "pipe/p_compiler.h" +#include "util/u_memory.h" +#include "util/u_format.h" +#include "tgsi/tgsi_dump.h" + +#include "tr_dump.h" +#include "tr_dump_state.h" + + +void trace_dump_format(enum pipe_format format) +{ + if (!trace_dumping_enabled_locked()) + return; + + trace_dump_enum(util_format_name(format) ); +} + + +void trace_dump_resource_template(const struct pipe_resource *templat) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!templat) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_resource"); + + trace_dump_member(int, templat, target); + trace_dump_member(format, templat, format); + + trace_dump_member_begin("width"); + trace_dump_uint(templat->width0); + trace_dump_member_end(); + + trace_dump_member_begin("height"); + trace_dump_uint(templat->height0); + trace_dump_member_end(); + + trace_dump_member_begin("depth"); + trace_dump_uint(templat->depth0); + trace_dump_member_end(); + + trace_dump_member_begin("array_size"); + trace_dump_uint(templat->array_size); + trace_dump_member_end(); + + trace_dump_member(uint, templat, last_level); + trace_dump_member(uint, templat, usage); + trace_dump_member(uint, templat, bind); + trace_dump_member(uint, templat, flags); + + trace_dump_struct_end(); +} + + +void trace_dump_box(const struct pipe_box *box) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!box) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_box"); + + trace_dump_member(uint, box, x); + trace_dump_member(uint, box, y); + trace_dump_member(uint, box, z); + trace_dump_member(uint, box, width); + trace_dump_member(uint, box, height); + trace_dump_member(uint, box, depth); + + trace_dump_struct_end(); +} + + +void trace_dump_rasterizer_state(const struct pipe_rasterizer_state *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_rasterizer_state"); + + trace_dump_member(bool, state, flatshade); + trace_dump_member(bool, state, light_twoside); + trace_dump_member(uint, state, front_ccw); + trace_dump_member(uint, state, cull_face); + trace_dump_member(uint, state, fill_front); + trace_dump_member(uint, state, fill_back); + trace_dump_member(bool, state, offset_point); + trace_dump_member(bool, state, offset_line); + trace_dump_member(bool, state, offset_tri); + trace_dump_member(bool, state, scissor); + trace_dump_member(bool, state, poly_smooth); + trace_dump_member(bool, state, poly_stipple_enable); + trace_dump_member(bool, state, point_smooth); + trace_dump_member(uint, state, sprite_coord_enable); + trace_dump_member(bool, state, sprite_coord_mode); + trace_dump_member(bool, state, point_quad_rasterization); + trace_dump_member(bool, state, point_size_per_vertex); + trace_dump_member(bool, state, multisample); + trace_dump_member(bool, state, line_smooth); + trace_dump_member(bool, state, line_stipple_enable); + trace_dump_member(uint, state, line_stipple_factor); + trace_dump_member(uint, state, line_stipple_pattern); + trace_dump_member(bool, state, line_last_pixel); + trace_dump_member(bool, state, flatshade_first); + trace_dump_member(bool, state, gl_rasterization_rules); + + trace_dump_member(float, state, line_width); + trace_dump_member(float, state, point_size); + trace_dump_member(float, state, offset_units); + trace_dump_member(float, state, offset_scale); + + trace_dump_struct_end(); +} + + +void trace_dump_poly_stipple(const struct pipe_poly_stipple *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_poly_stipple"); + + trace_dump_member_begin("stipple"); + trace_dump_array(uint, + state->stipple, + Elements(state->stipple)); + trace_dump_member_end(); + + trace_dump_struct_end(); +} + + +void trace_dump_viewport_state(const struct pipe_viewport_state *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_viewport_state"); + + trace_dump_member_array(float, state, scale); + trace_dump_member_array(float, state, translate); + + trace_dump_struct_end(); +} + + +void trace_dump_scissor_state(const struct pipe_scissor_state *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_scissor_state"); + + trace_dump_member(uint, state, minx); + trace_dump_member(uint, state, miny); + trace_dump_member(uint, state, maxx); + trace_dump_member(uint, state, maxy); + + trace_dump_struct_end(); +} + + +void trace_dump_clip_state(const struct pipe_clip_state *state) +{ + unsigned i; + + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_clip_state"); + + trace_dump_member_begin("ucp"); + trace_dump_array_begin(); + for(i = 0; i < PIPE_MAX_CLIP_PLANES; ++i) { + trace_dump_elem_begin(); + trace_dump_array(float, state->ucp[i], 4); + trace_dump_elem_end(); + } + trace_dump_array_end(); + trace_dump_member_end(); + + trace_dump_member(uint, state, nr); + + trace_dump_struct_end(); +} + + +void trace_dump_shader_state(const struct pipe_shader_state *state) +{ + static char str[8192]; + + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + tgsi_dump_str(state->tokens, 0, str, sizeof(str)); + + trace_dump_struct_begin("pipe_shader_state"); + + trace_dump_member_begin("tokens"); + trace_dump_string(str); + trace_dump_member_end(); + + trace_dump_struct_end(); +} + + +void trace_dump_depth_stencil_alpha_state(const struct pipe_depth_stencil_alpha_state *state) +{ + unsigned i; + + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_depth_stencil_alpha_state"); + + trace_dump_member_begin("depth"); + trace_dump_struct_begin("pipe_depth_state"); + trace_dump_member(bool, &state->depth, enabled); + trace_dump_member(bool, &state->depth, writemask); + trace_dump_member(uint, &state->depth, func); + trace_dump_struct_end(); + trace_dump_member_end(); + + trace_dump_member_begin("stencil"); + trace_dump_array_begin(); + for(i = 0; i < Elements(state->stencil); ++i) { + trace_dump_elem_begin(); + trace_dump_struct_begin("pipe_stencil_state"); + trace_dump_member(bool, &state->stencil[i], enabled); + trace_dump_member(uint, &state->stencil[i], func); + trace_dump_member(uint, &state->stencil[i], fail_op); + trace_dump_member(uint, &state->stencil[i], zpass_op); + trace_dump_member(uint, &state->stencil[i], zfail_op); + trace_dump_member(uint, &state->stencil[i], valuemask); + trace_dump_member(uint, &state->stencil[i], writemask); + trace_dump_struct_end(); + trace_dump_elem_end(); + } + trace_dump_array_end(); + trace_dump_member_end(); + + trace_dump_member_begin("alpha"); + trace_dump_struct_begin("pipe_alpha_state"); + trace_dump_member(bool, &state->alpha, enabled); + trace_dump_member(uint, &state->alpha, func); + trace_dump_member(float, &state->alpha, ref_value); + trace_dump_struct_end(); + trace_dump_member_end(); + + trace_dump_struct_end(); +} + +void trace_dump_blend_state(const struct pipe_blend_state *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_bytes(state, sizeof *state); +} + + +void trace_dump_blend_color(const struct pipe_blend_color *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_blend_color"); + + trace_dump_member_array(float, state, color); + + trace_dump_struct_end(); +} + +void trace_dump_stencil_ref(const struct pipe_stencil_ref *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_stencil_ref"); + + trace_dump_member_array(uint, state, ref_value); + + trace_dump_struct_end(); +} + +void trace_dump_framebuffer_state(const struct pipe_framebuffer_state *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + trace_dump_struct_begin("pipe_framebuffer_state"); + + trace_dump_member(uint, state, width); + trace_dump_member(uint, state, height); + trace_dump_member(uint, state, nr_cbufs); + trace_dump_member_array(ptr, state, cbufs); + trace_dump_member(ptr, state, zsbuf); + + trace_dump_struct_end(); +} + + +void trace_dump_sampler_state(const struct pipe_sampler_state *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_sampler_state"); + + trace_dump_member(uint, state, wrap_s); + trace_dump_member(uint, state, wrap_t); + trace_dump_member(uint, state, wrap_r); + trace_dump_member(uint, state, min_img_filter); + trace_dump_member(uint, state, min_mip_filter); + trace_dump_member(uint, state, mag_img_filter); + trace_dump_member(uint, state, compare_mode); + trace_dump_member(uint, state, compare_func); + trace_dump_member(bool, state, normalized_coords); + trace_dump_member(uint, state, max_anisotropy); + trace_dump_member(float, state, lod_bias); + trace_dump_member(float, state, min_lod); + trace_dump_member(float, state, max_lod); + trace_dump_member_array(float, state, border_color); + + trace_dump_struct_end(); +} + + +void trace_dump_sampler_view_template(const struct pipe_sampler_view *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_sampler_view"); + + trace_dump_member(format, state, format); + /* XXX */ + trace_dump_member(uint, state, u.tex.first_level); + trace_dump_member(uint, state, u.tex.last_level); + trace_dump_member(uint, state, u.tex.first_layer); + trace_dump_member(uint, state, u.tex.last_layer); + trace_dump_member(uint, state, u.buf.first_element); + trace_dump_member(uint, state, u.buf.last_element); + trace_dump_member(uint, state, swizzle_r); + trace_dump_member(uint, state, swizzle_g); + trace_dump_member(uint, state, swizzle_b); + trace_dump_member(uint, state, swizzle_a); + + trace_dump_struct_end(); +} + + +void trace_dump_surface(const struct pipe_surface *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_surface"); + + trace_dump_member(format, state, format); + trace_dump_member(uint, state, width); + trace_dump_member(uint, state, height); + + trace_dump_member(uint, state, usage); + + trace_dump_member(ptr, state, texture); + trace_dump_member(uint, state, u.tex.level); + trace_dump_member(uint, state, u.tex.first_layer); + trace_dump_member(uint, state, u.tex.last_layer); + trace_dump_member(uint, state, u.buf.first_element); + trace_dump_member(uint, state, u.buf.last_element); + + trace_dump_struct_end(); +} + + +void trace_dump_transfer(const struct pipe_transfer *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_transfer"); + + trace_dump_member(uint, state, box.x); + trace_dump_member(uint, state, box.y); + trace_dump_member(uint, state, box.z); + trace_dump_member(uint, state, box.width); + trace_dump_member(uint, state, box.height); + trace_dump_member(uint, state, box.depth); + + trace_dump_member(uint, state, stride); + trace_dump_member(uint, state, layer_stride); + trace_dump_member(uint, state, usage); + + trace_dump_member(ptr, state, resource); + + trace_dump_struct_end(); +} + + +void trace_dump_vertex_buffer(const struct pipe_vertex_buffer *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_vertex_buffer"); + + trace_dump_member(uint, state, stride); + trace_dump_member(uint, state, max_index); + trace_dump_member(uint, state, buffer_offset); + trace_dump_member(resource_ptr, state, buffer); + + trace_dump_struct_end(); +} + + +void trace_dump_index_buffer(const struct pipe_index_buffer *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_index_buffer"); + + trace_dump_member(uint, state, index_size); + trace_dump_member(uint, state, offset); + trace_dump_member(resource_ptr, state, buffer); + + trace_dump_struct_end(); +} + + +void trace_dump_vertex_element(const struct pipe_vertex_element *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_vertex_element"); + + trace_dump_member(uint, state, src_offset); + + trace_dump_member(uint, state, vertex_buffer_index); + + trace_dump_member(format, state, src_format); + + trace_dump_struct_end(); +} + + +void trace_dump_draw_info(const struct pipe_draw_info *state) +{ + if (!trace_dumping_enabled_locked()) + return; + + if(!state) { + trace_dump_null(); + return; + } + + trace_dump_struct_begin("pipe_draw_info"); + + trace_dump_member(bool, state, indexed); + + trace_dump_member(uint, state, mode); + trace_dump_member(uint, state, start); + trace_dump_member(uint, state, count); + + trace_dump_member(uint, state, start_instance); + trace_dump_member(uint, state, instance_count); + + trace_dump_member(int, state, index_bias); + trace_dump_member(uint, state, min_index); + trace_dump_member(uint, state, max_index); + + trace_dump_struct_end(); +} diff --git a/src/gallium/drivers/trace/tr_dump_state.h b/src/gallium/drivers/trace/tr_dump_state.h new file mode 100644 index 0000000..fe8ece7 --- /dev/null +++ b/src/gallium/drivers/trace/tr_dump_state.h @@ -0,0 +1,83 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef TR_DUMP_STATE_H_ +#define TR_DUMP_STATE_H_ + +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include "pipe/p_shader_tokens.h" + + +void trace_dump_format(enum pipe_format format); + +void trace_dump_resource_template(const struct pipe_resource *templat); + +void trace_dump_box(const struct pipe_box *box); + +void trace_dump_rasterizer_state(const struct pipe_rasterizer_state *state); + +void trace_dump_poly_stipple(const struct pipe_poly_stipple *state); + +void trace_dump_viewport_state(const struct pipe_viewport_state *state); + +void trace_dump_scissor_state(const struct pipe_scissor_state *state); + +void trace_dump_clip_state(const struct pipe_clip_state *state); + +void trace_dump_token(const struct tgsi_token *token); + +void trace_dump_shader_state(const struct pipe_shader_state *state); + +void trace_dump_depth_stencil_alpha_state(const struct pipe_depth_stencil_alpha_state *state); + +void trace_dump_blend_state(const struct pipe_blend_state *state); + +void trace_dump_blend_color(const struct pipe_blend_color *state); + +void trace_dump_stencil_ref(const struct pipe_stencil_ref *state); + +void trace_dump_framebuffer_state(const struct pipe_framebuffer_state *state); + +void trace_dump_sampler_state(const struct pipe_sampler_state *state); + +void trace_dump_sampler_view_template(const struct pipe_sampler_view *view); + +void trace_dump_surface(const struct pipe_surface *state); + +void trace_dump_transfer(const struct pipe_transfer *state); + +void trace_dump_vertex_buffer(const struct pipe_vertex_buffer *state); + +void trace_dump_index_buffer(const struct pipe_index_buffer *state); + +void trace_dump_vertex_element(const struct pipe_vertex_element *state); + +void trace_dump_draw_info(const struct pipe_draw_info *state); + + +#endif /* TR_STATE_H */ diff --git a/src/gallium/drivers/trace/tr_public.h b/src/gallium/drivers/trace/tr_public.h new file mode 100644 index 0000000..aee4937 --- /dev/null +++ b/src/gallium/drivers/trace/tr_public.h @@ -0,0 +1,48 @@ +/************************************************************************** + * + * 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 TR_PUBLIC_H +#define TR_PUBLIC_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct pipe_screen; +struct pipe_context; + +struct pipe_screen * +trace_screen_create(struct pipe_screen *screen); + +boolean +trace_enabled(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TR_PUBLIC_H */ diff --git a/src/gallium/drivers/trace/tr_screen.c b/src/gallium/drivers/trace/tr_screen.c new file mode 100644 index 0000000..c2de2da --- /dev/null +++ b/src/gallium/drivers/trace/tr_screen.c @@ -0,0 +1,552 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_simple_list.h" + +#include "tr_dump.h" +#include "tr_dump_state.h" +#include "tr_texture.h" +#include "tr_context.h" +#include "tr_screen.h" +#include "tr_public.h" + +#include "pipe/p_format.h" + + +static boolean trace = FALSE; + +static const char * +trace_screen_get_name(struct pipe_screen *_screen) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + const char *result; + + trace_dump_call_begin("pipe_screen", "get_name"); + + trace_dump_arg(ptr, screen); + + result = screen->get_name(screen); + + trace_dump_ret(string, result); + + trace_dump_call_end(); + + return result; +} + + +static const char * +trace_screen_get_vendor(struct pipe_screen *_screen) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + const char *result; + + trace_dump_call_begin("pipe_screen", "get_vendor"); + + trace_dump_arg(ptr, screen); + + result = screen->get_vendor(screen); + + trace_dump_ret(string, result); + + trace_dump_call_end(); + + return result; +} + + +static int +trace_screen_get_param(struct pipe_screen *_screen, + enum pipe_cap param) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + int result; + + trace_dump_call_begin("pipe_screen", "get_param"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(int, param); + + result = screen->get_param(screen, param); + + trace_dump_ret(int, result); + + trace_dump_call_end(); + + return result; +} + + +static int +trace_screen_get_shader_param(struct pipe_screen *_screen, unsigned shader, + enum pipe_shader_cap param) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + int result; + + trace_dump_call_begin("pipe_screen", "get_shader_param"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(int, shader); + trace_dump_arg(int, param); + + result = screen->get_shader_param(screen, shader, param); + + trace_dump_ret(int, result); + + trace_dump_call_end(); + + return result; +} + + +static float +trace_screen_get_paramf(struct pipe_screen *_screen, + enum pipe_cap param) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + float result; + + trace_dump_call_begin("pipe_screen", "get_paramf"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(int, param); + + result = screen->get_paramf(screen, param); + + trace_dump_ret(float, result); + + trace_dump_call_end(); + + return result; +} + + +static boolean +trace_screen_is_format_supported(struct pipe_screen *_screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned tex_usage, + unsigned geom_flags) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + boolean result; + + trace_dump_call_begin("pipe_screen", "is_format_supported"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(format, format); + trace_dump_arg(int, target); + trace_dump_arg(uint, sample_count); + trace_dump_arg(uint, tex_usage); + trace_dump_arg(uint, geom_flags); + + result = screen->is_format_supported(screen, format, target, sample_count, + tex_usage, geom_flags); + + trace_dump_ret(bool, result); + + trace_dump_call_end(); + + return result; +} + + +static struct pipe_context * +trace_screen_context_create(struct pipe_screen *_screen, void *priv) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_context *result; + + trace_dump_call_begin("pipe_screen", "context_create"); + + trace_dump_arg(ptr, screen); + + result = screen->context_create(screen, priv); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + result = trace_context_create(tr_scr, result); + + return result; +} + + +static void +trace_screen_flush_frontbuffer(struct pipe_screen *_screen, + struct pipe_resource *_resource, + unsigned level, unsigned layer, + void *context_private) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct trace_resource *tr_res = trace_resource(_resource); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_resource *resource = tr_res->resource; + + trace_dump_call_begin("pipe_screen", "flush_frontbuffer"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, resource); + trace_dump_arg(uint, level); + trace_dump_arg(uint, layer); + /* XXX: hide, as there is nothing we can do with this + trace_dump_arg(ptr, context_private); + */ + + screen->flush_frontbuffer(screen, resource, level, layer, context_private); + + trace_dump_call_end(); +} + + +/******************************************************************** + * texture + */ + + +static struct pipe_resource * +trace_screen_resource_create(struct pipe_screen *_screen, + const struct pipe_resource *templat) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_resource *result; + + trace_dump_call_begin("pipe_screen", "resource_create"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(resource_template, templat); + + result = screen->resource_create(screen, templat); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + result = trace_resource_create(tr_scr, result); + + return result; +} + +static struct pipe_resource * +trace_screen_resource_from_handle(struct pipe_screen *_screen, + const struct pipe_resource *templ, + struct winsys_handle *handle) +{ + struct trace_screen *tr_screen = trace_screen(_screen); + struct pipe_screen *screen = tr_screen->screen; + struct pipe_resource *result; + + /* TODO trace call */ + + result = screen->resource_from_handle(screen, templ, handle); + + result = trace_resource_create(trace_screen(_screen), result); + + return result; +} + +static boolean +trace_screen_resource_get_handle(struct pipe_screen *_screen, + struct pipe_resource *_texture, + struct winsys_handle *handle) +{ + struct trace_screen *tr_screen = trace_screen(_screen); + struct trace_resource *tr_texture = trace_resource(_texture); + struct pipe_screen *screen = tr_screen->screen; + struct pipe_resource *texture = tr_texture->resource; + + /* TODO trace call */ + + return screen->resource_get_handle(screen, texture, handle); +} + + + +static void +trace_screen_resource_destroy(struct pipe_screen *_screen, + struct pipe_resource *_texture) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct trace_resource *tr_tex = trace_resource(_texture); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_resource *texture = tr_tex->resource; + + assert(texture->screen == screen); + + trace_dump_call_begin("pipe_screen", "texture_destroy"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, texture); + + trace_dump_call_end(); + + trace_resource_destroy(tr_scr, tr_tex); +} + + + +/******************************************************************** + * buffer + */ + + + +static struct pipe_resource * +trace_screen_user_buffer_create(struct pipe_screen *_screen, + void *data, + unsigned size, + unsigned usage) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_resource *result; + + trace_dump_call_begin("pipe_screen", "user_buffer_create"); + + trace_dump_arg(ptr, screen); + trace_dump_arg_begin("data"); + trace_dump_bytes(data, size); + trace_dump_arg_end(); + trace_dump_arg(uint, size); + trace_dump_arg(uint, usage); + + result = screen->user_buffer_create(screen, data, size, usage); + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + if(result) { + assert(!(result->flags & TRACE_FLAG_USER_BUFFER)); + result->flags |= TRACE_FLAG_USER_BUFFER; + } + + return trace_resource_create(tr_scr, result); +} + + + + +/******************************************************************** + * fence + */ + + +static void +trace_screen_fence_reference(struct pipe_screen *_screen, + struct pipe_fence_handle **pdst, + struct pipe_fence_handle *src) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + struct pipe_fence_handle *dst; + + assert(pdst); + dst = *pdst; + + trace_dump_call_begin("pipe_screen", "fence_reference"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, dst); + trace_dump_arg(ptr, src); + + screen->fence_reference(screen, pdst, src); + + trace_dump_call_end(); +} + + +static int +trace_screen_fence_signalled(struct pipe_screen *_screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + int result; + + trace_dump_call_begin("pipe_screen", "fence_signalled"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, fence); + trace_dump_arg(uint, flags); + + result = screen->fence_signalled(screen, fence, flags); + + trace_dump_ret(int, result); + + trace_dump_call_end(); + + return result; +} + + +static int +trace_screen_fence_finish(struct pipe_screen *_screen, + struct pipe_fence_handle *fence, + unsigned flags) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + int result; + + trace_dump_call_begin("pipe_screen", "fence_finish"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, fence); + trace_dump_arg(uint, flags); + + result = screen->fence_finish(screen, fence, flags); + + trace_dump_ret(int, result); + + trace_dump_call_end(); + + return result; +} + + +/******************************************************************** + * screen + */ + +static void +trace_screen_destroy(struct pipe_screen *_screen) +{ + struct trace_screen *tr_scr = trace_screen(_screen); + struct pipe_screen *screen = tr_scr->screen; + + trace_dump_call_begin("pipe_screen", "destroy"); + trace_dump_arg(ptr, screen); + trace_dump_call_end(); + trace_dump_trace_end(); + + screen->destroy(screen); + + FREE(tr_scr); +} + +boolean +trace_enabled(void) +{ + static boolean firstrun = TRUE; + + if (!firstrun) + return trace; + firstrun = FALSE; + + trace_dump_init(); + + if(trace_dump_trace_begin()) { + trace_dumping_start(); + trace = TRUE; + } + + return trace; +} + +struct pipe_screen * +trace_screen_create(struct pipe_screen *screen) +{ + struct trace_screen *tr_scr; + struct pipe_winsys *winsys; + + if(!screen) + goto error1; + + if (!trace_enabled()) + goto error1; + + trace_dump_call_begin("", "pipe_screen_create"); + + tr_scr = CALLOC_STRUCT(trace_screen); + if(!tr_scr) + goto error2; + +#if 0 + winsys = trace_winsys_create(screen->winsys); + if(!winsys) + goto error3; +#else + winsys = screen->winsys; +#endif + tr_scr->base.winsys = winsys; + tr_scr->base.destroy = trace_screen_destroy; + tr_scr->base.get_name = trace_screen_get_name; + tr_scr->base.get_vendor = trace_screen_get_vendor; + tr_scr->base.get_param = trace_screen_get_param; + tr_scr->base.get_shader_param = trace_screen_get_shader_param; + tr_scr->base.get_paramf = trace_screen_get_paramf; + tr_scr->base.is_format_supported = trace_screen_is_format_supported; + assert(screen->context_create); + tr_scr->base.context_create = trace_screen_context_create; + tr_scr->base.resource_create = trace_screen_resource_create; + tr_scr->base.resource_from_handle = trace_screen_resource_from_handle; + tr_scr->base.resource_get_handle = trace_screen_resource_get_handle; + tr_scr->base.resource_destroy = trace_screen_resource_destroy; + tr_scr->base.user_buffer_create = trace_screen_user_buffer_create; + tr_scr->base.fence_reference = trace_screen_fence_reference; + tr_scr->base.fence_signalled = trace_screen_fence_signalled; + tr_scr->base.fence_finish = trace_screen_fence_finish; + tr_scr->base.flush_frontbuffer = trace_screen_flush_frontbuffer; + + tr_scr->screen = screen; + + trace_dump_ret(ptr, screen); + trace_dump_call_end(); + + return &tr_scr->base; + +error2: + trace_dump_ret(ptr, screen); + trace_dump_call_end(); + trace_dump_trace_end(); +error1: + return screen; +} + + +struct trace_screen * +trace_screen(struct pipe_screen *screen) +{ + assert(screen); + assert(screen->destroy == trace_screen_destroy); + return (struct trace_screen *)screen; +} diff --git a/src/gallium/drivers/trace/tr_screen.h b/src/gallium/drivers/trace/tr_screen.h new file mode 100644 index 0000000..3598cea --- /dev/null +++ b/src/gallium/drivers/trace/tr_screen.h @@ -0,0 +1,74 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef TR_SCREEN_H_ +#define TR_SCREEN_H_ + + +#include "pipe/p_screen.h" +#include "os/os_thread.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct tr_list { + struct tr_list *next; + struct tr_list *prev; +}; + +/** + * It often happens that new data is written directly to the user buffers + * without mapping/unmapping. This flag marks user buffers, so that their + * contents can be dumpped before being used by the pipe context. + */ +#define TRACE_FLAG_USER_BUFFER (1 << 31) + + +struct trace_screen +{ + struct pipe_screen base; + + struct pipe_screen *screen; +}; + + +/* + * tr_screen.c + */ + + +struct trace_screen * +trace_screen(struct pipe_screen *screen); + +#ifdef __cplusplus +} +#endif + +#endif /* TR_SCREEN_H_ */ diff --git a/src/gallium/drivers/trace/tr_texture.c b/src/gallium/drivers/trace/tr_texture.c new file mode 100644 index 0000000..2799734 --- /dev/null +++ b/src/gallium/drivers/trace/tr_texture.c @@ -0,0 +1,158 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "util/u_inlines.h" +#include "util/u_hash_table.h" +#include "util/u_memory.h" +#include "util/u_simple_list.h" + +#include "tr_screen.h" +#include "tr_context.h" +#include "tr_texture.h" + + +struct pipe_resource * +trace_resource_create(struct trace_screen *tr_scr, + struct pipe_resource *texture) +{ + struct trace_resource *tr_tex; + + if(!texture) + goto error; + + assert(texture->screen == tr_scr->screen); + + tr_tex = CALLOC_STRUCT(trace_resource); + if(!tr_tex) + goto error; + + memcpy(&tr_tex->base, texture, sizeof(struct pipe_resource)); + + pipe_reference_init(&tr_tex->base.reference, 1); + tr_tex->base.screen = &tr_scr->base; + tr_tex->resource = texture; + + return &tr_tex->base; + +error: + pipe_resource_reference(&texture, NULL); + return NULL; +} + + +void +trace_resource_destroy(struct trace_screen *tr_scr, + struct trace_resource *tr_tex) +{ + pipe_resource_reference(&tr_tex->resource, NULL); + FREE(tr_tex); +} + + +struct pipe_surface * +trace_surf_create(struct trace_resource *tr_tex, + struct pipe_surface *surface) +{ + struct trace_surface *tr_surf; + + if(!surface) + goto error; + + assert(surface->texture == tr_tex->resource); + + tr_surf = CALLOC_STRUCT(trace_surface); + if(!tr_surf) + goto error; + + memcpy(&tr_surf->base, surface, sizeof(struct pipe_surface)); + + pipe_reference_init(&tr_surf->base.reference, 1); + tr_surf->base.texture = NULL; + pipe_resource_reference(&tr_surf->base.texture, &tr_tex->base); + tr_surf->surface = surface; + + return &tr_surf->base; + +error: + pipe_surface_reference(&surface, NULL); + return NULL; +} + + +void +trace_surf_destroy(struct trace_surface *tr_surf) +{ + pipe_resource_reference(&tr_surf->base.texture, NULL); + pipe_surface_reference(&tr_surf->surface, NULL); + FREE(tr_surf); +} + + +struct pipe_transfer * +trace_transfer_create(struct trace_context *tr_ctx, + struct trace_resource *tr_tex, + struct pipe_transfer *transfer) +{ + struct trace_transfer *tr_trans; + + if(!transfer) + goto error; + + assert(transfer->resource == tr_tex->resource); + + tr_trans = CALLOC_STRUCT(trace_transfer); + if(!tr_trans) + goto error; + + memcpy(&tr_trans->base, transfer, sizeof(struct pipe_transfer)); + + tr_trans->base.resource = NULL; + tr_trans->transfer = transfer; + + pipe_resource_reference(&tr_trans->base.resource, &tr_tex->base); + assert(tr_trans->base.resource == &tr_tex->base); + + return &tr_trans->base; + +error: + tr_ctx->pipe->transfer_destroy(tr_ctx->pipe, transfer); + return NULL; +} + + +void +trace_transfer_destroy(struct trace_context *tr_context, + struct trace_transfer *tr_trans) +{ + struct pipe_context *context = tr_context->pipe; + struct pipe_transfer *transfer = tr_trans->transfer; + + pipe_resource_reference(&tr_trans->base.resource, NULL); + context->transfer_destroy(context, transfer); + FREE(tr_trans); +} + diff --git a/src/gallium/drivers/trace/tr_texture.h b/src/gallium/drivers/trace/tr_texture.h new file mode 100644 index 0000000..3352c96 --- /dev/null +++ b/src/gallium/drivers/trace/tr_texture.h @@ -0,0 +1,144 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef TR_TEXTURE_H_ +#define TR_TEXTURE_H_ + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" + +#include "tr_screen.h" + +struct trace_context; + +struct trace_resource +{ + struct pipe_resource base; + + struct pipe_resource *resource; + + struct tr_list list; +}; + + +struct trace_surface +{ + struct pipe_surface base; + + struct pipe_surface *surface; + + struct tr_list list; +}; + + +struct trace_sampler_view +{ + struct pipe_sampler_view base; + + struct pipe_sampler_view *sampler_view; +}; + + +struct trace_transfer +{ + struct pipe_transfer base; + + struct pipe_transfer *transfer; + struct pipe_context *pipe; + + struct tr_list list; + + void *map; +}; + + +static INLINE struct trace_resource * +trace_resource(struct pipe_resource *texture) +{ + if(!texture) + return NULL; + (void)trace_screen(texture->screen); + return (struct trace_resource *)texture; +} + + +static INLINE struct trace_surface * +trace_surface(struct pipe_surface *surface) +{ + if(!surface) + return NULL; + (void)trace_resource(surface->texture); + return (struct trace_surface *)surface; +} + + +static INLINE struct trace_sampler_view * +trace_sampler_view(struct pipe_sampler_view *sampler_view) +{ + if (!sampler_view) + return NULL; + return (struct trace_sampler_view *)sampler_view; +} + + +static INLINE struct trace_transfer * +trace_transfer(struct pipe_transfer *transfer) +{ + if(!transfer) + return NULL; + (void)trace_resource(transfer->resource); + return (struct trace_transfer *)transfer; +} + + +struct pipe_resource * +trace_resource_create(struct trace_screen *tr_scr, + struct pipe_resource *texture); + +void +trace_resource_destroy(struct trace_screen *tr_scr, + struct trace_resource *tr_tex); + +struct pipe_surface * +trace_surf_create(struct trace_resource *tr_tex, + struct pipe_surface *surface); + +void +trace_surf_destroy(struct trace_surface *tr_surf); + +struct pipe_transfer * +trace_transfer_create(struct trace_context *tr_ctx, + struct trace_resource *tr_tex, + struct pipe_transfer *transfer); + +void +trace_transfer_destroy(struct trace_context *tr_ctx, + struct trace_transfer *tr_trans); + + +#endif /* TR_TEXTURE_H_ */ diff --git a/src/gallium/include/pipe/p_compiler.h b/src/gallium/include/pipe/p_compiler.h new file mode 100644 index 0000000..3d6b5b5 --- /dev/null +++ b/src/gallium/include/pipe/p_compiler.h @@ -0,0 +1,297 @@ +/************************************************************************** + * + * Copyright 2007-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. + * + **************************************************************************/ + +#ifndef P_COMPILER_H +#define P_COMPILER_H + + +#include "p_config.h" + +#include +#include +#include +#include +#include + + +#if defined(_WIN32) && !defined(__WIN32__) +#define __WIN32__ +#endif + +#if defined(_MSC_VER) + +/* Avoid 'expression is always true' warning */ +#pragma warning(disable: 4296) + +#endif /* _MSC_VER */ + + +/* + * Alternative stdint.h and stdbool.h headers are supplied in include/c99 for + * systems that lack it. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +#if !defined(__HAIKU__) && !defined(__USE_MISC) +typedef unsigned int uint; +typedef unsigned short ushort; +#endif +typedef unsigned char ubyte; + +typedef unsigned char boolean; +#ifndef TRUE +#define TRUE true +#endif +#ifndef FALSE +#define FALSE false +#endif + +#ifndef va_copy +#ifdef __va_copy +#define va_copy(dest, src) __va_copy((dest), (src)) +#else +#define va_copy(dest, src) (dest) = (src) +#endif +#endif + +/* Function inlining */ +#ifndef INLINE +# ifdef __cplusplus +# define INLINE inline +# elif defined(__GNUC__) +# define INLINE __inline__ +# elif defined(_MSC_VER) +# define INLINE __inline +# elif defined(__ICL) +# define INLINE __inline +# elif defined(__INTEL_COMPILER) +# define INLINE inline +# elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100) +# define INLINE __inline +# elif defined(__SUNPRO_C) && defined(__C99FEATURES__) +# define INLINE inline +# elif (__STDC_VERSION__ >= 199901L) /* C99 */ +# define INLINE inline +# else +# define INLINE +# endif +#endif + +/* Forced function inlining */ +#ifndef ALWAYS_INLINE +# ifdef __GNUC__ +# define ALWAYS_INLINE inline __attribute__((always_inline)) +# elif defined(_MSC_VER) +# define ALWAYS_INLINE __forceinline +# else +# define ALWAYS_INLINE INLINE +# endif +#endif + +/* + * Define the C99 restrict keyword. + * + * See also: + * - http://cellperformance.beyond3d.com/articles/2006/05/demystifying-the-restrict-keyword.html + */ +#ifndef restrict +# if (__STDC_VERSION__ >= 199901L) + /* C99 */ +# elif defined(__SUNPRO_C) && defined(__C99FEATURES__) + /* C99 */ +# elif defined(__GNUC__) +# define restrict __restrict__ +# elif defined(_MSC_VER) +# define restrict __restrict +# else +# define restrict /* */ +# endif +#endif + + +/* Function visibility */ +#ifndef PUBLIC +# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define PUBLIC __attribute__((visibility("default"))) +# elif defined(_MSC_VER) +# define PUBLIC __declspec(dllexport) +# else +# define PUBLIC +# endif +#endif + + +/* The __FUNCTION__ gcc variable is generally only used for debugging. + * If we're not using gcc, define __FUNCTION__ as a cpp symbol here. + */ +#ifndef __FUNCTION__ +# if !defined(__GNUC__) +# if (__STDC_VERSION__ >= 199901L) /* C99 */ || \ + (defined(__SUNPRO_C) && defined(__C99FEATURES__)) +# define __FUNCTION__ __func__ +# else +# define __FUNCTION__ "" +# endif +# endif +# if defined(_MSC_VER) && _MSC_VER < 1300 +# define __FUNCTION__ "" +# endif +#endif + + + +/* This should match linux gcc cdecl semantics everywhere, so that we + * just codegen one calling convention on all platforms. + */ +#ifdef _MSC_VER +#define PIPE_CDECL __cdecl +#else +#define PIPE_CDECL +#endif + + + +#if defined(__GNUC__) +#define PIPE_DEPRECATED __attribute__((__deprecated__)) +#else +#define PIPE_DEPRECATED +#endif + + + +/* Macros for data alignment. */ +#if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) + +/* See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Type-Attributes.html */ +#define PIPE_ALIGN_TYPE(_alignment, _type) _type __attribute__((aligned(_alignment))) + +/* See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Variable-Attributes.html */ +#define PIPE_ALIGN_VAR(_alignment) __attribute__((aligned(_alignment))) + +#if (__GNUC__ > 4 || (__GNUC__ == 4 &&__GNUC_MINOR__>1)) && !defined(PIPE_ARCH_X86_64) +#define PIPE_ALIGN_STACK __attribute__((force_align_arg_pointer)) +#else +#define PIPE_ALIGN_STACK +#endif + +#elif defined(_MSC_VER) + +/* See http://msdn.microsoft.com/en-us/library/83ythb65.aspx */ +#define PIPE_ALIGN_TYPE(_alignment, _type) __declspec(align(_alignment)) _type +#define PIPE_ALIGN_VAR(_alignment) __declspec(align(_alignment)) + +#define PIPE_ALIGN_STACK + +#elif defined(SWIG) + +#define PIPE_ALIGN_TYPE(_alignment, _type) _type +#define PIPE_ALIGN_VAR(_alignment) + +#define PIPE_ALIGN_STACK + +#else + +#error "Unsupported compiler" + +#endif + + +#if defined(__GNUC__) + +#define PIPE_READ_WRITE_BARRIER() __asm__("":::"memory") + +#elif defined(_MSC_VER) + +void _ReadWriteBarrier(void); +#pragma intrinsic(_ReadWriteBarrier) +#define PIPE_READ_WRITE_BARRIER() _ReadWriteBarrier() + +#else + +#warning "Unsupported compiler" +#define PIPE_READ_WRITE_BARRIER() /* */ + +#endif + + +/* You should use these macros to mark if blocks where the if condition + * is either likely to be true, or unlikely to be true. + * + * This will inform human readers of this fact, and will also inform + * the compiler, who will in turn inform the CPU. + * + * CPUs often start executing code inside the if or the else blocks + * without knowing whether the condition is true or not, and will have + * to throw the work away if they find out later they executed the + * wrong part of the if. + * + * If these macros are used, the CPU is more likely to correctly predict + * the right path, and will avoid speculatively executing the wrong branch, + * thus not throwing away work, resulting in better performance. + * + * In light of this, it is also a good idea to mark as "likely" a path + * which is not necessarily always more likely, but that will benefit much + * more from performance improvements since it is already much faster than + * the other path, or viceversa with "unlikely". + * + * Example usage: + * if(unlikely(do_we_need_a_software_fallback())) + * do_software_fallback(); + * else + * render_with_gpu(); + * + * The macros follow the Linux kernel convention, and more examples can + * be found there. + * + * Note that profile guided optimization can offer better results, but + * needs an appropriate coverage suite and does not inform human readers. + */ +#ifdef __GNUC__ +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) +#else +#define likely(x) !!(x) +#define unlikely(x) !!(x) +#endif + + +#if defined(__cplusplus) +} +#endif + + +#endif /* P_COMPILER_H */ diff --git a/src/gallium/include/pipe/p_config.h b/src/gallium/include/pipe/p_config.h new file mode 100644 index 0000000..74a1fa2 --- /dev/null +++ b/src/gallium/include/pipe/p_config.h @@ -0,0 +1,214 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Gallium configuration defines. + * + * This header file sets several defines based on the compiler, processor + * architecture, and operating system being used. These defines should be used + * throughout the code to facilitate porting to new platforms. It is likely that + * this file is auto-generated by an autoconf-like tool at some point, as some + * things cannot be determined by pre-defined environment alone. + * + * See also: + * - http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html + * - echo | gcc -dM -E - | sort + * - http://msdn.microsoft.com/en-us/library/b0084kay.aspx + * + * @author José Fonseca + */ + +#ifndef P_CONFIG_H_ +#define P_CONFIG_H_ + + +/* + * Compiler + */ + +#if defined(__GNUC__) +#define PIPE_CC_GCC +#define PIPE_CC_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) +#endif + +/* + * Meaning of _MSC_VER value: + * - 1400: Visual C++ 2005 + * - 1310: Visual C++ .NET 2003 + * - 1300: Visual C++ .NET 2002 + * + * __MSC__ seems to be an old macro -- it is not pre-defined on recent MSVC + * versions. + */ +#if defined(_MSC_VER) || defined(__MSC__) +#define PIPE_CC_MSVC +#endif + +#if defined(__ICL) +#define PIPE_CC_ICL +#endif + + +/* + * Processor architecture + */ + +#if defined(__i386__) /* gcc */ || defined(_M_IX86) /* msvc */ || defined(_X86_) || defined(__386__) || defined(i386) || defined(__i386) /* Sun cc */ +#define PIPE_ARCH_X86 +#endif + +#if defined(__x86_64__) /* gcc */ || defined(_M_X64) /* msvc */ || defined(_M_AMD64) /* msvc */ || defined(__x86_64) /* Sun cc */ +#define PIPE_ARCH_X86_64 +#endif + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) +#if defined(PIPE_CC_GCC) && !defined(__SSE2__) +/* #warning SSE2 support requires -msse -msse2 compiler options */ +#else +#define PIPE_ARCH_SSE +#endif +#if defined(PIPE_CC_GCC) && !defined(__SSSE3__) +/* #warning SSE3 support requires -msse3 compiler options */ +#else +#define PIPE_ARCH_SSSE3 +#endif +#endif + +#if defined(__PPC__) +#define PIPE_ARCH_PPC +#if defined(__PPC64__) +#define PIPE_ARCH_PPC_64 +#endif +#endif + + +/* + * Endian detection. + */ + +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) +#define PIPE_ARCH_LITTLE_ENDIAN +#elif defined(PIPE_ARCH_PPC) || defined(PIPE_ARCH_PPC_64) +#define PIPE_ARCH_BIG_ENDIAN +#else +#define PIPE_ARCH_UNKNOWN_ENDIAN +#endif + + +#if !defined(PIPE_OS_EMBEDDED) + +/* + * Auto-detect the operating system family. + * + * See subsystem below for a more fine-grained distinction. + */ + +#if defined(__linux__) +#define PIPE_OS_LINUX +#define PIPE_OS_UNIX +#endif + +#if defined(__FreeBSD__) +#define PIPE_OS_FREEBSD +#define PIPE_OS_BSD +#define PIPE_OS_UNIX +#endif + +#if defined(__OpenBSD__) +#define PIPE_OS_OPENBSD +#define PIPE_OS_BSD +#define PIPE_OS_UNIX +#endif + +#if defined(__NetBSD__) +#define PIPE_OS_NETBSD +#define PIPE_OS_BSD +#define PIPE_OS_UNIX +#endif + +#if defined(__GNU__) +#define PIPE_OS_HURD +#define PIPE_OS_UNIX +#endif + +#if defined(__sun) +#define PIPE_OS_SOLARIS +#define PIPE_OS_UNIX +#endif + +#if defined(__APPLE__) +#define PIPE_OS_APPLE +#define PIPE_OS_UNIX +#endif + +#if defined(_WIN32) || defined(WIN32) +#define PIPE_OS_WINDOWS +#endif + +#if defined(__HAIKU__) +#define PIPE_OS_HAIKU +#define PIPE_OS_UNIX +#endif + +#if defined(__CYGWIN__) +#define PIPE_OS_CYGWIN +#define PIPE_OS_UNIX +#endif + +/* + * Try to auto-detect the subsystem. + * + * NOTE: There is no way to auto-detect most of these. + */ + +#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) +#define PIPE_SUBSYSTEM_DRI +#endif /* PIPE_OS_LINUX || PIPE_OS_BSD || PIPE_OS_SOLARIS */ + +#if defined(PIPE_OS_WINDOWS) +#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) +/* Windows 2000/XP Display Driver */ +#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) +/* Windows 2000/XP Miniport Driver */ +#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) +/* Windows User-space Library */ +#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE) +/* Windows CE 5.0/6.0 */ +#else +#ifdef _WIN32_WCE +#define PIPE_SUBSYSTEM_WINDOWS_CE +#else /* !_WIN32_WCE */ +#error No PIPE_SUBSYSTEM_WINDOWS_xxx subsystem defined. +#endif /* !_WIN32_WCE */ +#endif +#endif /* PIPE_OS_WINDOWS */ + +#endif /* !PIPE_OS_EMBEDDED */ + + +#endif /* P_CONFIG_H_ */ diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h new file mode 100644 index 0000000..589cac2 --- /dev/null +++ b/src/gallium/include/pipe/p_context.h @@ -0,0 +1,409 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef PIPE_CONTEXT_H +#define PIPE_CONTEXT_H + +#include "p_compiler.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +struct pipe_blend_color; +struct pipe_blend_state; +struct pipe_box; +struct pipe_clip_state; +struct pipe_depth_stencil_alpha_state; +struct pipe_draw_info; +struct pipe_fence_handle; +struct pipe_framebuffer_state; +struct pipe_index_buffer; +struct pipe_query; +struct pipe_poly_stipple; +struct pipe_rasterizer_state; +struct pipe_resource; +struct pipe_sampler_state; +struct pipe_sampler_view; +struct pipe_scissor_state; +struct pipe_shader_state; +struct pipe_stencil_ref; +struct pipe_stream_output_state; +struct pipe_surface; +struct pipe_vertex_buffer; +struct pipe_vertex_element; +struct pipe_viewport_state; + +/** + * Gallium rendering context. Basically: + * - state setting functions + * - VBO drawing functions + * - surface functions + */ +struct pipe_context { + struct pipe_winsys *winsys; + struct pipe_screen *screen; + + void *priv; /**< context private data (for DRI for example) */ + void *draw; /**< private, for draw module (temporary?) */ + + void (*destroy)( struct pipe_context * ); + + /** + * VBO drawing + */ + /*@{*/ + void (*draw_vbo)( struct pipe_context *pipe, + const struct pipe_draw_info *info ); + + /** + * Draw the stream output buffer at index 0 + */ + void (*draw_stream_output)( struct pipe_context *pipe, unsigned mode ); + /*@}*/ + + /** + * Predicate subsequent rendering on occlusion query result + * \param query the query predicate, or NULL if no predicate + * \param mode one of PIPE_RENDER_COND_x + */ + void (*render_condition)( struct pipe_context *pipe, + struct pipe_query *query, + uint mode ); + + /** + * Query objects + */ + /*@{*/ + struct pipe_query *(*create_query)( struct pipe_context *pipe, + unsigned query_type ); + + void (*destroy_query)(struct pipe_context *pipe, + struct pipe_query *q); + + void (*begin_query)(struct pipe_context *pipe, struct pipe_query *q); + void (*end_query)(struct pipe_context *pipe, struct pipe_query *q); + + /** + * Get results of a query. + * \param wait if true, this query will block until the result is ready + * \return TRUE if results are ready, FALSE otherwise + */ + boolean (*get_query_result)(struct pipe_context *pipe, + struct pipe_query *q, + boolean wait, + void *result); + /*@}*/ + + /** + * State functions (create/bind/destroy state objects) + */ + /*@{*/ + void * (*create_blend_state)(struct pipe_context *, + const struct pipe_blend_state *); + void (*bind_blend_state)(struct pipe_context *, void *); + void (*delete_blend_state)(struct pipe_context *, void *); + + void * (*create_sampler_state)(struct pipe_context *, + const struct pipe_sampler_state *); + void (*bind_fragment_sampler_states)(struct pipe_context *, + unsigned num_samplers, + void **samplers); + void (*bind_vertex_sampler_states)(struct pipe_context *, + unsigned num_samplers, + void **samplers); + void (*bind_geometry_sampler_states)(struct pipe_context *, + unsigned num_samplers, + void **samplers); + void (*delete_sampler_state)(struct pipe_context *, void *); + + void * (*create_rasterizer_state)(struct pipe_context *, + const struct pipe_rasterizer_state *); + void (*bind_rasterizer_state)(struct pipe_context *, void *); + void (*delete_rasterizer_state)(struct pipe_context *, void *); + + void * (*create_depth_stencil_alpha_state)(struct pipe_context *, + const struct pipe_depth_stencil_alpha_state *); + void (*bind_depth_stencil_alpha_state)(struct pipe_context *, void *); + void (*delete_depth_stencil_alpha_state)(struct pipe_context *, void *); + + void * (*create_fs_state)(struct pipe_context *, + const struct pipe_shader_state *); + void (*bind_fs_state)(struct pipe_context *, void *); + void (*delete_fs_state)(struct pipe_context *, void *); + + void * (*create_vs_state)(struct pipe_context *, + const struct pipe_shader_state *); + void (*bind_vs_state)(struct pipe_context *, void *); + void (*delete_vs_state)(struct pipe_context *, void *); + + void * (*create_gs_state)(struct pipe_context *, + const struct pipe_shader_state *); + void (*bind_gs_state)(struct pipe_context *, void *); + void (*delete_gs_state)(struct pipe_context *, void *); + + void * (*create_vertex_elements_state)(struct pipe_context *, + unsigned num_elements, + const struct pipe_vertex_element *); + void (*bind_vertex_elements_state)(struct pipe_context *, void *); + void (*delete_vertex_elements_state)(struct pipe_context *, void *); + + void * (*create_stream_output_state)(struct pipe_context *, + const struct pipe_stream_output_state *); + void (*bind_stream_output_state)(struct pipe_context *, void *); + void (*delete_stream_output_state)(struct pipe_context*, void*); + + /*@}*/ + + /** + * Parameter-like state (or properties) + */ + /*@{*/ + void (*set_blend_color)( struct pipe_context *, + const struct pipe_blend_color * ); + + void (*set_stencil_ref)( struct pipe_context *, + const struct pipe_stencil_ref * ); + + void (*set_sample_mask)( struct pipe_context *, + unsigned sample_mask ); + + void (*set_clip_state)( struct pipe_context *, + const struct pipe_clip_state * ); + + void (*set_constant_buffer)( struct pipe_context *, + uint shader, uint index, + struct pipe_resource *buf ); + + void (*set_framebuffer_state)( struct pipe_context *, + const struct pipe_framebuffer_state * ); + + void (*set_polygon_stipple)( struct pipe_context *, + const struct pipe_poly_stipple * ); + + void (*set_scissor_state)( struct pipe_context *, + const struct pipe_scissor_state * ); + + void (*set_viewport_state)( struct pipe_context *, + const struct pipe_viewport_state * ); + + void (*set_fragment_sampler_views)(struct pipe_context *, + unsigned num_views, + struct pipe_sampler_view **); + + void (*set_vertex_sampler_views)(struct pipe_context *, + unsigned num_views, + struct pipe_sampler_view **); + + void (*set_geometry_sampler_views)(struct pipe_context *, + unsigned num_views, + struct pipe_sampler_view **); + + void (*set_vertex_buffers)( struct pipe_context *, + unsigned num_buffers, + const struct pipe_vertex_buffer * ); + + void (*set_index_buffer)( struct pipe_context *pipe, + const struct pipe_index_buffer * ); + + void (*set_stream_output_buffers)(struct pipe_context *, + struct pipe_resource **buffers, + int *offsets, /*array of offsets + from the start of each + of the buffers */ + int num_buffers); + + /*@}*/ + + + /** + * Resource functions for blit-like functionality + * + * If a driver supports multisampling, resource_resolve must be available. + */ + /*@{*/ + + /** + * Copy a block of pixels from one resource to another. + * The resource must be of the same format. + * Resources with nr_samples > 1 are not allowed. + */ + void (*resource_copy_region)(struct pipe_context *pipe, + struct pipe_resource *dst, + unsigned dst_level, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource *src, + unsigned src_level, + const struct pipe_box *src_box); + + /** + * Resolve a multisampled resource into a non-multisampled one. + * Source and destination must have the same size and same format. + */ + void (*resource_resolve)(struct pipe_context *pipe, + struct pipe_resource *dst, + unsigned dst_layer, + struct pipe_resource *src, + unsigned src_layer); + + /*@}*/ + + /** + * Clear the specified set of currently bound buffers to specified values. + * The entire buffers are cleared (no scissor, no colormask, etc). + * + * \param buffers bitfield of PIPE_CLEAR_* values. + * \param rgba pointer to an array of one float for each of r, g, b, a. + * \param depth depth clear value in [0,1]. + * \param stencil stencil clear value + */ + void (*clear)(struct pipe_context *pipe, + unsigned buffers, + const float *rgba, + double depth, + unsigned stencil); + + /** + * Clear a color rendertarget surface. + * \param rgba pointer to an array of one float for each of r, g, b, a. + */ + void (*clear_render_target)(struct pipe_context *pipe, + struct pipe_surface *dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height); + + /** + * Clear a depth-stencil surface. + * \param clear_flags bitfield of PIPE_CLEAR_DEPTH/STENCIL values. + * \param depth depth clear value in [0,1]. + * \param stencil stencil clear value + */ + void (*clear_depth_stencil)(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height); + + /** Flush rendering + * \param flags bitmask of PIPE_FLUSH_x tokens) + */ + void (*flush)( struct pipe_context *pipe, + unsigned flags, + struct pipe_fence_handle **fence ); + + /** + * Check whether a texture is referenced by an unflushed hw command. + * The state-tracker uses this function to avoid unnecessary flushes. + * It is safe (but wasteful) to always return + * PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE. + * \param pipe context whose unflushed hw commands will be checked. + * \param texture texture to check. + * \param level mipmap level. + * \param layer cubemap face, 2d array or 3d slice, 0 otherwise. Use -1 for any layer. + * \return mask of PIPE_REFERENCED_FOR_READ/WRITE or PIPE_UNREFERENCED + */ + unsigned int (*is_resource_referenced)(struct pipe_context *pipe, + struct pipe_resource *texture, + unsigned level, int layer); + + /** + * Create a view on a texture to be used by a shader stage. + */ + struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx, + struct pipe_resource *texture, + const struct pipe_sampler_view *templat); + + void (*sampler_view_destroy)(struct pipe_context *ctx, + struct pipe_sampler_view *view); + + + /** + * Get a surface which is a "view" into a resource, used by + * render target / depth stencil stages. + * \param usage bitmaks of PIPE_BIND_* flags + */ + struct pipe_surface *(*create_surface)(struct pipe_context *ctx, + struct pipe_resource *resource, + const struct pipe_surface *templat); + + void (*surface_destroy)(struct pipe_context *ctx, + struct pipe_surface *); + + /** + * Get a transfer object for transferring data to/from a texture. + * + * Transfers are (by default) context-private and allow uploads to be + * interleaved with + */ + struct pipe_transfer *(*get_transfer)(struct pipe_context *, + struct pipe_resource *resource, + unsigned level, + unsigned usage, /* a combination of PIPE_TRANSFER_x */ + const struct pipe_box *); + + void (*transfer_destroy)(struct pipe_context *, + struct pipe_transfer *); + + void *(*transfer_map)( struct pipe_context *, + struct pipe_transfer *transfer ); + + /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the + * regions specified with this call are guaranteed to be written to + * the resource. + */ + void (*transfer_flush_region)( struct pipe_context *, + struct pipe_transfer *transfer, + const struct pipe_box *); + + void (*transfer_unmap)( struct pipe_context *, + struct pipe_transfer *transfer ); + + + /* One-shot transfer operation with data supplied in a user + * pointer. XXX: strides?? + */ + void (*transfer_inline_write)( struct pipe_context *, + struct pipe_resource *, + unsigned level, + unsigned usage, /* a combination of PIPE_TRANSFER_x */ + const struct pipe_box *, + const void *data, + unsigned stride, + unsigned layer_stride); + +}; + + +#ifdef __cplusplus +} +#endif + +#endif /* PIPE_CONTEXT_H */ diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h new file mode 100644 index 0000000..f5af15f --- /dev/null +++ b/src/gallium/include/pipe/p_defines.h @@ -0,0 +1,516 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef PIPE_DEFINES_H +#define PIPE_DEFINES_H + +#include "p_compiler.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Gallium error codes. + * + * - A zero value always means success. + * - A negative value always means failure. + * - The meaning of a positive value is function dependent. + */ +enum pipe_error { + PIPE_OK = 0, + PIPE_ERROR = -1, /**< Generic error */ + PIPE_ERROR_BAD_INPUT = -2, + PIPE_ERROR_OUT_OF_MEMORY = -3, + PIPE_ERROR_RETRY = -4 + /* TODO */ +}; + + +#define PIPE_BLENDFACTOR_ONE 0x1 +#define PIPE_BLENDFACTOR_SRC_COLOR 0x2 +#define PIPE_BLENDFACTOR_SRC_ALPHA 0x3 +#define PIPE_BLENDFACTOR_DST_ALPHA 0x4 +#define PIPE_BLENDFACTOR_DST_COLOR 0x5 +#define PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE 0x6 +#define PIPE_BLENDFACTOR_CONST_COLOR 0x7 +#define PIPE_BLENDFACTOR_CONST_ALPHA 0x8 +#define PIPE_BLENDFACTOR_SRC1_COLOR 0x9 +#define PIPE_BLENDFACTOR_SRC1_ALPHA 0x0A +#define PIPE_BLENDFACTOR_ZERO 0x11 +#define PIPE_BLENDFACTOR_INV_SRC_COLOR 0x12 +#define PIPE_BLENDFACTOR_INV_SRC_ALPHA 0x13 +#define PIPE_BLENDFACTOR_INV_DST_ALPHA 0x14 +#define PIPE_BLENDFACTOR_INV_DST_COLOR 0x15 +#define PIPE_BLENDFACTOR_INV_CONST_COLOR 0x17 +#define PIPE_BLENDFACTOR_INV_CONST_ALPHA 0x18 +#define PIPE_BLENDFACTOR_INV_SRC1_COLOR 0x19 +#define PIPE_BLENDFACTOR_INV_SRC1_ALPHA 0x1A + +#define PIPE_BLEND_ADD 0 +#define PIPE_BLEND_SUBTRACT 1 +#define PIPE_BLEND_REVERSE_SUBTRACT 2 +#define PIPE_BLEND_MIN 3 +#define PIPE_BLEND_MAX 4 + +#define PIPE_LOGICOP_CLEAR 0 +#define PIPE_LOGICOP_NOR 1 +#define PIPE_LOGICOP_AND_INVERTED 2 +#define PIPE_LOGICOP_COPY_INVERTED 3 +#define PIPE_LOGICOP_AND_REVERSE 4 +#define PIPE_LOGICOP_INVERT 5 +#define PIPE_LOGICOP_XOR 6 +#define PIPE_LOGICOP_NAND 7 +#define PIPE_LOGICOP_AND 8 +#define PIPE_LOGICOP_EQUIV 9 +#define PIPE_LOGICOP_NOOP 10 +#define PIPE_LOGICOP_OR_INVERTED 11 +#define PIPE_LOGICOP_COPY 12 +#define PIPE_LOGICOP_OR_REVERSE 13 +#define PIPE_LOGICOP_OR 14 +#define PIPE_LOGICOP_SET 15 + +#define PIPE_MASK_R 0x1 +#define PIPE_MASK_G 0x2 +#define PIPE_MASK_B 0x4 +#define PIPE_MASK_A 0x8 +#define PIPE_MASK_RGBA 0xf + + +/** + * Inequality functions. Used for depth test, stencil compare, alpha + * test, shadow compare, etc. + */ +#define PIPE_FUNC_NEVER 0 +#define PIPE_FUNC_LESS 1 +#define PIPE_FUNC_EQUAL 2 +#define PIPE_FUNC_LEQUAL 3 +#define PIPE_FUNC_GREATER 4 +#define PIPE_FUNC_NOTEQUAL 5 +#define PIPE_FUNC_GEQUAL 6 +#define PIPE_FUNC_ALWAYS 7 + +/** Polygon fill mode */ +#define PIPE_POLYGON_MODE_FILL 0 +#define PIPE_POLYGON_MODE_LINE 1 +#define PIPE_POLYGON_MODE_POINT 2 + +/** Polygon face specification, eg for culling */ +#define PIPE_FACE_NONE 0 +#define PIPE_FACE_FRONT 1 +#define PIPE_FACE_BACK 2 +#define PIPE_FACE_FRONT_AND_BACK (PIPE_FACE_FRONT | PIPE_FACE_BACK) + +/** Stencil ops */ +#define PIPE_STENCIL_OP_KEEP 0 +#define PIPE_STENCIL_OP_ZERO 1 +#define PIPE_STENCIL_OP_REPLACE 2 +#define PIPE_STENCIL_OP_INCR 3 +#define PIPE_STENCIL_OP_DECR 4 +#define PIPE_STENCIL_OP_INCR_WRAP 5 +#define PIPE_STENCIL_OP_DECR_WRAP 6 +#define PIPE_STENCIL_OP_INVERT 7 + +/** Texture types. + * See the documentation for info on PIPE_TEXTURE_RECT vs PIPE_TEXTURE_2D */ +enum pipe_texture_target { + PIPE_BUFFER = 0, + PIPE_TEXTURE_1D = 1, + PIPE_TEXTURE_2D = 2, + PIPE_TEXTURE_3D = 3, + PIPE_TEXTURE_CUBE = 4, + PIPE_TEXTURE_RECT = 5, + PIPE_TEXTURE_1D_ARRAY = 6, + PIPE_TEXTURE_2D_ARRAY = 7, + PIPE_MAX_TEXTURE_TYPES +}; + +#define PIPE_TEX_FACE_POS_X 0 +#define PIPE_TEX_FACE_NEG_X 1 +#define PIPE_TEX_FACE_POS_Y 2 +#define PIPE_TEX_FACE_NEG_Y 3 +#define PIPE_TEX_FACE_POS_Z 4 +#define PIPE_TEX_FACE_NEG_Z 5 +#define PIPE_TEX_FACE_MAX 6 + +#define PIPE_TEX_WRAP_REPEAT 0 +#define PIPE_TEX_WRAP_CLAMP 1 +#define PIPE_TEX_WRAP_CLAMP_TO_EDGE 2 +#define PIPE_TEX_WRAP_CLAMP_TO_BORDER 3 +#define PIPE_TEX_WRAP_MIRROR_REPEAT 4 +#define PIPE_TEX_WRAP_MIRROR_CLAMP 5 +#define PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE 6 +#define PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER 7 + +/* Between mipmaps, ie mipfilter + */ +#define PIPE_TEX_MIPFILTER_NEAREST 0 +#define PIPE_TEX_MIPFILTER_LINEAR 1 +#define PIPE_TEX_MIPFILTER_NONE 2 + +/* Within a mipmap, ie min/mag filter + */ +#define PIPE_TEX_FILTER_NEAREST 0 +#define PIPE_TEX_FILTER_LINEAR 1 + +#define PIPE_TEX_COMPARE_NONE 0 +#define PIPE_TEX_COMPARE_R_TO_TEXTURE 1 + +/** + * Clear buffer bits + */ +/** All color buffers currently bound */ +#define PIPE_CLEAR_COLOR (1 << 0) +#define PIPE_CLEAR_DEPTH (1 << 1) +#define PIPE_CLEAR_STENCIL (1 << 2) +/** Depth/stencil combined */ +#define PIPE_CLEAR_DEPTHSTENCIL (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL) + +/** + * Transfer object usage flags + */ +enum pipe_transfer_usage { + /** + * Resource contents read back (or accessed directly) at transfer + * create time. + */ + PIPE_TRANSFER_READ = (1 << 0), + + /** + * Resource contents will be written back at transfer_destroy + * time (or modified as a result of being accessed directly). + */ + PIPE_TRANSFER_WRITE = (1 << 1), + + /** + * Read/modify/write + */ + PIPE_TRANSFER_READ_WRITE = PIPE_TRANSFER_READ | PIPE_TRANSFER_WRITE, + + /** + * The transfer should map the texture storage directly. The driver may + * return NULL if that isn't possible, and the state tracker needs to cope + * with that and use an alternative path without this flag. + * + * E.g. the state tracker could have a simpler path which maps textures and + * does read/modify/write cycles on them directly, and a more complicated + * path which uses minimal read and write transfers. + */ + PIPE_TRANSFER_MAP_DIRECTLY = (1 << 2), + + /** + * Discards the memory within the mapped region. + * + * It should not be used with PIPE_TRANSFER_CPU_READ. + * + * See also: + * - OpenGL's ARB_map_buffer_range extension, MAP_INVALIDATE_RANGE_BIT flag. + * - Direct3D's D3DLOCK_DISCARD flag. + */ + PIPE_TRANSFER_DISCARD = (1 << 8), + + /** + * Fail if the resource cannot be mapped immediately. + * + * See also: + * - Direct3D's D3DLOCK_DONOTWAIT flag. + * - Mesa3D's MESA_MAP_NOWAIT_BIT flag. + * - WDDM's D3DDDICB_LOCKFLAGS.DonotWait flag. + */ + PIPE_TRANSFER_DONTBLOCK = (1 << 9), + + /** + * Do not attempt to synchronize pending operations on the resource when mapping. + * + * It should not be used with PIPE_TRANSFER_CPU_READ. + * + * See also: + * - OpenGL's ARB_map_buffer_range extension, MAP_UNSYNCHRONIZED_BIT flag. + * - Direct3D's D3DLOCK_NOOVERWRITE flag. + * - WDDM's D3DDDICB_LOCKFLAGS.IgnoreSync flag. + */ + PIPE_TRANSFER_UNSYNCHRONIZED = (1 << 10), + PIPE_TRANSFER_NOOVERWRITE = (1 << 10), /* are these really the same?? */ + + /** + * Written ranges will be notified later with + * pipe_context::transfer_flush_region. + * + * It should not be used with PIPE_TRANSFER_CPU_READ. + * + * See also: + * - pipe_context::transfer_flush_region + * - OpenGL's ARB_map_buffer_range extension, MAP_FLUSH_EXPLICIT_BIT flag. + */ + PIPE_TRANSFER_FLUSH_EXPLICIT = (1 << 11) + +}; + + +/* + * Resource binding flags -- state tracker must specify in advance all + * the ways a resource might be used. + */ +#define PIPE_BIND_DEPTH_STENCIL (1 << 0) /* create_surface */ +#define PIPE_BIND_RENDER_TARGET (1 << 1) /* create_surface */ +#define PIPE_BIND_SAMPLER_VIEW (1 << 2) /* create_sampler_view */ +#define PIPE_BIND_VERTEX_BUFFER (1 << 3) /* set_vertex_buffers */ +#define PIPE_BIND_INDEX_BUFFER (1 << 4) /* draw_elements */ +#define PIPE_BIND_CONSTANT_BUFFER (1 << 5) /* set_constant_buffer */ +#define PIPE_BIND_DISPLAY_TARGET (1 << 8) /* flush_front_buffer */ +#define PIPE_BIND_TRANSFER_WRITE (1 << 9) /* get_transfer */ +#define PIPE_BIND_TRANSFER_READ (1 << 10) /* get_transfer */ +#define PIPE_BIND_STREAM_OUTPUT (1 << 11) /* set_stream_output_buffers */ +#define PIPE_BIND_CUSTOM (1 << 16) /* state-tracker/winsys usages */ + +/* The first two flags above were previously part of the amorphous + * TEXTURE_USAGE, most of which are now descriptions of the ways a + * particular texture can be bound to the gallium pipeline. The two flags + * below do not fit within that and probably need to be migrated to some + * other place. + * + * It seems like scanout is used by the Xorg state tracker to ask for + * a texture suitable for actual scanout (hence the name), which + * implies extra layout constraints on some hardware. It may also + * have some special meaning regarding mouse cursor images. + * + * The shared flag is quite underspecified, but certainly isn't a + * binding flag - it seems more like a message to the winsys to create + * a shareable allocation. + */ +#define PIPE_BIND_SCANOUT (1 << 14) /* */ +#define PIPE_BIND_SHARED (1 << 15) /* get_texture_handle ??? */ + + +/* Flags for the driver about resource behaviour: + */ +#define PIPE_RESOURCE_FLAG_GEN_MIPS (1 << 0) /* Driver performs autogen mips */ +#define PIPE_RESOURCE_FLAG_DRV_PRIV (1 << 16) /* driver/winsys private */ +#define PIPE_RESOURCE_FLAG_ST_PRIV (1 << 24) /* state-tracker/winsys private */ + +/* Hint about the expected lifecycle of a resource. + */ +#define PIPE_USAGE_DEFAULT 0 /* many uploads, draws intermixed */ +#define PIPE_USAGE_DYNAMIC 1 /* many uploads, draws intermixed */ +#define PIPE_USAGE_STATIC 2 /* same as immutable?? */ +#define PIPE_USAGE_IMMUTABLE 3 /* no change after first upload */ +#define PIPE_USAGE_STREAM 4 /* upload, draw, upload, draw */ +#define PIPE_USAGE_STAGING 5 /* supports data transfers from the GPU to the CPU */ + + +/* These are intended to be used in calls to is_format_supported, but + * no driver actually uses these flags, and only the glx/xlib state + * tracker issues them. + * + * Deprecate? + */ +#define PIPE_TEXTURE_GEOM_NON_SQUARE 0x1 +#define PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO 0x2 + + +/** + * Flush types: + */ +#define PIPE_FLUSH_RENDER_CACHE 0x1 +#define PIPE_FLUSH_TEXTURE_CACHE 0x2 +#define PIPE_FLUSH_SWAPBUFFERS 0x4 +#define PIPE_FLUSH_FRAME 0x8 /**< Mark the end of a frame */ + + +/** + * Shaders + */ +#define PIPE_SHADER_VERTEX 0 +#define PIPE_SHADER_FRAGMENT 1 +#define PIPE_SHADER_GEOMETRY 2 +#define PIPE_SHADER_TYPES 3 + + +/** + * Primitive types: + */ +#define PIPE_PRIM_POINTS 0 +#define PIPE_PRIM_LINES 1 +#define PIPE_PRIM_LINE_LOOP 2 +#define PIPE_PRIM_LINE_STRIP 3 +#define PIPE_PRIM_TRIANGLES 4 +#define PIPE_PRIM_TRIANGLE_STRIP 5 +#define PIPE_PRIM_TRIANGLE_FAN 6 +#define PIPE_PRIM_QUADS 7 +#define PIPE_PRIM_QUAD_STRIP 8 +#define PIPE_PRIM_POLYGON 9 +#define PIPE_PRIM_LINES_ADJACENCY 10 +#define PIPE_PRIM_LINE_STRIP_ADJACENCY 11 +#define PIPE_PRIM_TRIANGLES_ADJACENCY 12 +#define PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY 13 +#define PIPE_PRIM_MAX 14 + + +/** + * Query object types + */ +#define PIPE_QUERY_OCCLUSION_COUNTER 0 +#define PIPE_QUERY_PRIMITIVES_GENERATED 1 +#define PIPE_QUERY_PRIMITIVES_EMITTED 2 +#define PIPE_QUERY_TIME_ELAPSED 3 +#define PIPE_QUERY_SO_STATISTICS 5 +#define PIPE_QUERY_GPU_FINISHED 6 +#define PIPE_QUERY_TIMESTAMP_DISJOINT 7 +#define PIPE_QUERY_TYPES 8 + + +/** + * Conditional rendering modes + */ +#define PIPE_RENDER_COND_WAIT 0 +#define PIPE_RENDER_COND_NO_WAIT 1 +#define PIPE_RENDER_COND_BY_REGION_WAIT 2 +#define PIPE_RENDER_COND_BY_REGION_NO_WAIT 3 + + +/** + * Point sprite coord modes + */ +#define PIPE_SPRITE_COORD_UPPER_LEFT 0 +#define PIPE_SPRITE_COORD_LOWER_LEFT 1 + + +/** + * Texture swizzles + */ +#define PIPE_SWIZZLE_RED 0 +#define PIPE_SWIZZLE_GREEN 1 +#define PIPE_SWIZZLE_BLUE 2 +#define PIPE_SWIZZLE_ALPHA 3 +#define PIPE_SWIZZLE_ZERO 4 +#define PIPE_SWIZZLE_ONE 5 + + +/** + * Implementation capabilities/limits which are queried through + * pipe_screen::get_param() and pipe_screen::get_paramf(). + */ +enum pipe_cap { + PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS, + PIPE_CAP_NPOT_TEXTURES, + PIPE_CAP_TWO_SIDED_STENCIL, + PIPE_CAP_GLSL, /* XXX need something better */ + PIPE_CAP_DUAL_SOURCE_BLEND, + PIPE_CAP_ANISOTROPIC_FILTER, + PIPE_CAP_POINT_SPRITE, + PIPE_CAP_MAX_RENDER_TARGETS, + PIPE_CAP_OCCLUSION_QUERY, + PIPE_CAP_TIMER_QUERY, + PIPE_CAP_TEXTURE_SHADOW_MAP, + PIPE_CAP_TEXTURE_SWIZZLE, + PIPE_CAP_MAX_TEXTURE_2D_LEVELS, + PIPE_CAP_MAX_TEXTURE_3D_LEVELS, + PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS, + PIPE_CAP_MAX_LINE_WIDTH, + PIPE_CAP_MAX_LINE_WIDTH_AA, + PIPE_CAP_MAX_POINT_WIDTH, + PIPE_CAP_MAX_POINT_WIDTH_AA, + PIPE_CAP_MAX_TEXTURE_ANISOTROPY, + PIPE_CAP_MAX_TEXTURE_LOD_BIAS, + PIPE_CAP_GUARD_BAND_LEFT, /*< float */ + PIPE_CAP_GUARD_BAND_TOP, /*< float */ + PIPE_CAP_GUARD_BAND_RIGHT, /*< float */ + PIPE_CAP_GUARD_BAND_BOTTOM, /*< float */ + PIPE_CAP_TEXTURE_MIRROR_CLAMP, + PIPE_CAP_TEXTURE_MIRROR_REPEAT, + PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS, + PIPE_CAP_BLEND_EQUATION_SEPARATE, + PIPE_CAP_SM3, /*< Shader Model, supported */ + PIPE_CAP_STREAM_OUTPUT, + PIPE_CAP_PRIMITIVE_RESTART, + /** Maximum texture image units accessible from vertex and fragment shaders + * combined */ + PIPE_CAP_MAX_COMBINED_SAMPLERS, + /** blend enables and write masks per rendertarget */ + PIPE_CAP_INDEP_BLEND_ENABLE, + /** different blend funcs per rendertarget */ + PIPE_CAP_INDEP_BLEND_FUNC, + PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE, + PIPE_CAP_ARRAY_TEXTURES, + PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT, + PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT, + PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER, + PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER, + PIPE_CAP_DEPTH_CLAMP, + PIPE_CAP_SHADER_STENCIL_EXPORT, +}; + +/* Shader caps not specific to any single stage */ +enum pipe_shader_cap +{ + PIPE_SHADER_CAP_MAX_INSTRUCTIONS, /* if 0, it means the stage is unsupported */ + PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS, + PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS, + PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS, + PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH, + PIPE_SHADER_CAP_MAX_INPUTS, + PIPE_SHADER_CAP_MAX_CONSTS, + PIPE_SHADER_CAP_MAX_CONST_BUFFERS, + PIPE_SHADER_CAP_MAX_TEMPS, + PIPE_SHADER_CAP_MAX_ADDRS, + PIPE_SHADER_CAP_MAX_PREDS, + /* boolean caps */ + PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED, + PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR, + PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR, + PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR, + PIPE_SHADER_CAP_INDIRECT_CONST_ADDR, + PIPE_SHADER_CAP_SUBROUTINES, /* BGNSUB, ENDSUB, CAL, RET */ +}; + +/** + * Referenced query flags. + */ + +#define PIPE_UNREFERENCED 0 +#define PIPE_REFERENCED_FOR_READ (1 << 0) +#define PIPE_REFERENCED_FOR_WRITE (1 << 1) + +/** + * Composite query types + */ +struct pipe_query_data_so_statistics +{ + uint64_t num_primitives_written; + uint64_t primitives_storage_needed; +}; +struct pipe_query_data_timestamp_disjoint +{ + uint64_t frequency; + boolean disjoint; +}; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/include/pipe/p_format.h b/src/gallium/include/pipe/p_format.h new file mode 100644 index 0000000..22cc7aa --- /dev/null +++ b/src/gallium/include/pipe/p_format.h @@ -0,0 +1,201 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright (c) 2008 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 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. + * + **************************************************************************/ + +#ifndef PIPE_FORMAT_H +#define PIPE_FORMAT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Texture/surface image formats (preliminary) + */ + +/* KW: Added lots of surface formats to support vertex element layout + * definitions, and eventually render-to-vertex-buffer. + */ + +enum pipe_format { + PIPE_FORMAT_NONE = 0, + PIPE_FORMAT_B8G8R8A8_UNORM = 1, + PIPE_FORMAT_B8G8R8X8_UNORM = 2, + PIPE_FORMAT_A8R8G8B8_UNORM = 3, + PIPE_FORMAT_X8R8G8B8_UNORM = 4, + PIPE_FORMAT_B5G5R5A1_UNORM = 5, + PIPE_FORMAT_B4G4R4A4_UNORM = 6, + PIPE_FORMAT_B5G6R5_UNORM = 7, + PIPE_FORMAT_R10G10B10A2_UNORM = 8, + PIPE_FORMAT_L8_UNORM = 9, /**< ubyte luminance */ + PIPE_FORMAT_A8_UNORM = 10, /**< ubyte alpha */ + PIPE_FORMAT_I8_UNORM = 11, /**< ubyte intensity */ + PIPE_FORMAT_L8A8_UNORM = 12, /**< ubyte alpha, luminance */ + PIPE_FORMAT_L16_UNORM = 13, /**< ushort luminance */ + PIPE_FORMAT_UYVY = 14, + PIPE_FORMAT_YUYV = 15, + PIPE_FORMAT_Z16_UNORM = 16, + PIPE_FORMAT_Z32_UNORM = 17, + PIPE_FORMAT_Z32_FLOAT = 18, + PIPE_FORMAT_Z24_UNORM_S8_USCALED = 19, + PIPE_FORMAT_S8_USCALED_Z24_UNORM = 20, + PIPE_FORMAT_Z24X8_UNORM = 21, + PIPE_FORMAT_X8Z24_UNORM = 22, + PIPE_FORMAT_S8_USCALED = 23, /**< ubyte stencil */ + PIPE_FORMAT_R64_FLOAT = 24, + PIPE_FORMAT_R64G64_FLOAT = 25, + PIPE_FORMAT_R64G64B64_FLOAT = 26, + PIPE_FORMAT_R64G64B64A64_FLOAT = 27, + PIPE_FORMAT_R32_FLOAT = 28, + PIPE_FORMAT_R32G32_FLOAT = 29, + PIPE_FORMAT_R32G32B32_FLOAT = 30, + PIPE_FORMAT_R32G32B32A32_FLOAT = 31, + PIPE_FORMAT_R32_UNORM = 32, + PIPE_FORMAT_R32G32_UNORM = 33, + PIPE_FORMAT_R32G32B32_UNORM = 34, + PIPE_FORMAT_R32G32B32A32_UNORM = 35, + PIPE_FORMAT_R32_USCALED = 36, + PIPE_FORMAT_R32G32_USCALED = 37, + PIPE_FORMAT_R32G32B32_USCALED = 38, + PIPE_FORMAT_R32G32B32A32_USCALED = 39, + PIPE_FORMAT_R32_SNORM = 40, + PIPE_FORMAT_R32G32_SNORM = 41, + PIPE_FORMAT_R32G32B32_SNORM = 42, + PIPE_FORMAT_R32G32B32A32_SNORM = 43, + PIPE_FORMAT_R32_SSCALED = 44, + PIPE_FORMAT_R32G32_SSCALED = 45, + PIPE_FORMAT_R32G32B32_SSCALED = 46, + PIPE_FORMAT_R32G32B32A32_SSCALED = 47, + PIPE_FORMAT_R16_UNORM = 48, + PIPE_FORMAT_R16G16_UNORM = 49, + PIPE_FORMAT_R16G16B16_UNORM = 50, + PIPE_FORMAT_R16G16B16A16_UNORM = 51, + PIPE_FORMAT_R16_USCALED = 52, + PIPE_FORMAT_R16G16_USCALED = 53, + PIPE_FORMAT_R16G16B16_USCALED = 54, + PIPE_FORMAT_R16G16B16A16_USCALED = 55, + PIPE_FORMAT_R16_SNORM = 56, + PIPE_FORMAT_R16G16_SNORM = 57, + PIPE_FORMAT_R16G16B16_SNORM = 58, + PIPE_FORMAT_R16G16B16A16_SNORM = 59, + PIPE_FORMAT_R16_SSCALED = 60, + PIPE_FORMAT_R16G16_SSCALED = 61, + PIPE_FORMAT_R16G16B16_SSCALED = 62, + PIPE_FORMAT_R16G16B16A16_SSCALED = 63, + PIPE_FORMAT_R8_UNORM = 64, + PIPE_FORMAT_R8G8_UNORM = 65, + PIPE_FORMAT_R8G8B8_UNORM = 66, + PIPE_FORMAT_R8G8B8A8_UNORM = 67, + PIPE_FORMAT_X8B8G8R8_UNORM = 68, + PIPE_FORMAT_R8_USCALED = 69, + PIPE_FORMAT_R8G8_USCALED = 70, + PIPE_FORMAT_R8G8B8_USCALED = 71, + PIPE_FORMAT_R8G8B8A8_USCALED = 72, + PIPE_FORMAT_R8_SNORM = 74, + PIPE_FORMAT_R8G8_SNORM = 75, + PIPE_FORMAT_R8G8B8_SNORM = 76, + PIPE_FORMAT_R8G8B8A8_SNORM = 77, + PIPE_FORMAT_R8_SSCALED = 82, + PIPE_FORMAT_R8G8_SSCALED = 83, + PIPE_FORMAT_R8G8B8_SSCALED = 84, + PIPE_FORMAT_R8G8B8A8_SSCALED = 85, + PIPE_FORMAT_R32_FIXED = 87, + PIPE_FORMAT_R32G32_FIXED = 88, + PIPE_FORMAT_R32G32B32_FIXED = 89, + PIPE_FORMAT_R32G32B32A32_FIXED = 90, + PIPE_FORMAT_R16_FLOAT = 91, + PIPE_FORMAT_R16G16_FLOAT = 92, + PIPE_FORMAT_R16G16B16_FLOAT = 93, + PIPE_FORMAT_R16G16B16A16_FLOAT = 94, + + /* sRGB formats */ + PIPE_FORMAT_L8_SRGB = 95, + PIPE_FORMAT_L8A8_SRGB = 96, + PIPE_FORMAT_R8G8B8_SRGB = 97, + PIPE_FORMAT_A8B8G8R8_SRGB = 98, + PIPE_FORMAT_X8B8G8R8_SRGB = 99, + PIPE_FORMAT_B8G8R8A8_SRGB = 100, + PIPE_FORMAT_B8G8R8X8_SRGB = 101, + PIPE_FORMAT_A8R8G8B8_SRGB = 102, + PIPE_FORMAT_X8R8G8B8_SRGB = 103, + PIPE_FORMAT_R8G8B8A8_SRGB = 104, + + /* compressed formats */ + PIPE_FORMAT_DXT1_RGB = 105, + PIPE_FORMAT_DXT1_RGBA = 106, + PIPE_FORMAT_DXT3_RGBA = 107, + PIPE_FORMAT_DXT5_RGBA = 108, + + /* sRGB, compressed */ + PIPE_FORMAT_DXT1_SRGB = 109, + PIPE_FORMAT_DXT1_SRGBA = 110, + PIPE_FORMAT_DXT3_SRGBA = 111, + PIPE_FORMAT_DXT5_SRGBA = 112, + + /* rgtc compressed */ + PIPE_FORMAT_RGTC1_UNORM = 113, + PIPE_FORMAT_RGTC1_SNORM = 114, + PIPE_FORMAT_RGTC2_UNORM = 115, + PIPE_FORMAT_RGTC2_SNORM = 116, + + PIPE_FORMAT_R8G8_B8G8_UNORM = 117, + PIPE_FORMAT_G8R8_G8B8_UNORM = 118, + + /* mixed formats */ + PIPE_FORMAT_R8SG8SB8UX8U_NORM = 119, + PIPE_FORMAT_R5SG5SB6U_NORM = 120, + + /* TODO: re-order these */ + PIPE_FORMAT_A8B8G8R8_UNORM = 121, + PIPE_FORMAT_B5G5R5X1_UNORM = 122, + PIPE_FORMAT_R10G10B10A2_USCALED = 123, + PIPE_FORMAT_R11G11B10_FLOAT = 124, + PIPE_FORMAT_R9G9B9E5_FLOAT = 125, + PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED = 126, + PIPE_FORMAT_R1_UNORM = 127, + PIPE_FORMAT_R10G10B10X2_USCALED = 128, + PIPE_FORMAT_R10G10B10X2_SNORM = 129, + PIPE_FORMAT_L4A4_UNORM = 130, + PIPE_FORMAT_B10G10R10A2_UNORM = 131, + PIPE_FORMAT_R10SG10SB10SA2U_NORM = 132, + PIPE_FORMAT_R8G8Bx_SNORM = 133, + PIPE_FORMAT_R8G8B8X8_UNORM = 134, + PIPE_FORMAT_B4G4R4X4_UNORM = 135, + + /* some stencil samplers formats */ + PIPE_FORMAT_X24S8_USCALED = 136, + PIPE_FORMAT_S8X24_USCALED = 137, + PIPE_FORMAT_X32_S8X24_USCALED = 138, + PIPE_FORMAT_COUNT +}; + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h new file mode 100644 index 0000000..850eb84 --- /dev/null +++ b/src/gallium/include/pipe/p_screen.h @@ -0,0 +1,209 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * + * Screen, Adapter or GPU + * + * These are driver functions/facilities that are context independent. + */ + + +#ifndef P_SCREEN_H +#define P_SCREEN_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "pipe/p_defines.h" + + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** Opaque type */ +struct winsys_handle; +/** Opaque type */ +struct pipe_fence_handle; +struct pipe_winsys; +struct pipe_resource; +struct pipe_surface; +struct pipe_transfer; + + +/** + * Gallium screen/adapter context. Basically everything + * hardware-specific that doesn't actually require a rendering + * context. + */ +struct pipe_screen { + struct pipe_winsys *winsys; + + void (*destroy)( struct pipe_screen * ); + + + const char *(*get_name)( struct pipe_screen * ); + + const char *(*get_vendor)( struct pipe_screen * ); + + /** + * Query an integer-valued capability/parameter/limit + * \param param one of PIPE_CAP_x + */ + int (*get_param)( struct pipe_screen *, enum pipe_cap param ); + + /** + * Query a float-valued capability/parameter/limit + * \param param one of PIPE_CAP_x + */ + float (*get_paramf)( struct pipe_screen *, enum pipe_cap param ); + + /** + * Query a per-shader-stage integer-valued capability/parameter/limit + * \param param one of PIPE_CAP_x + */ + int (*get_shader_param)( struct pipe_screen *, unsigned shader, enum pipe_shader_cap param ); + + struct pipe_context * (*context_create)( struct pipe_screen *, + void *priv ); + + /** + * Check if the given pipe_format is supported as a texture or + * drawing surface. + * \param bindings bitmask of PIPE_BIND_* + * \param geom_flags bitmask of PIPE_TEXTURE_GEOM_* + */ + boolean (*is_format_supported)( struct pipe_screen *, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned bindings, + unsigned geom_flags ); + + /** + * Create a new texture object, using the given template info. + */ + struct pipe_resource * (*resource_create)(struct pipe_screen *, + const struct pipe_resource *templat); + + /** + * Create a texture from a winsys_handle. The handle is often created in + * another process by first creating a pipe texture and then calling + * resource_get_handle. + */ + struct pipe_resource * (*resource_from_handle)(struct pipe_screen *, + const struct pipe_resource *templat, + struct winsys_handle *handle); + + /** + * Get a winsys_handle from a texture. Some platforms/winsys requires + * that the texture is created with a special usage flag like + * DISPLAYTARGET or PRIMARY. + */ + boolean (*resource_get_handle)(struct pipe_screen *, + struct pipe_resource *tex, + struct winsys_handle *handle); + + + void (*resource_destroy)(struct pipe_screen *, + struct pipe_resource *pt); + + + /** + * Create a buffer that wraps user-space data. + * + * Effectively this schedules a delayed call to buffer_create + * followed by an upload of the data at *some point in the future*, + * or perhaps never. Basically the allocate/upload is delayed + * until the buffer is actually passed to hardware. + * + * The intention is to provide a quick way to turn regular data + * into a buffer, and secondly to avoid a copy operation if that + * data subsequently turns out to be only accessed by the CPU. + * + * Common example is OpenGL vertex buffers that are subsequently + * processed either by software TNL in the driver or by passing to + * hardware. + * + * XXX: What happens if the delayed call to buffer_create() fails? + * + * Note that ptr may be accessed at any time upto the time when the + * buffer is destroyed, so the data must not be freed before then. + */ + struct pipe_resource *(*user_buffer_create)(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned bind_flags); + + /** + * Do any special operations to ensure frontbuffer contents are + * displayed, eg copy fake frontbuffer. + * \param winsys_drawable_handle an opaque handle that the calling context + * gets out-of-band + */ + void (*flush_frontbuffer)( struct pipe_screen *screen, + struct pipe_resource *resource, + unsigned level, unsigned layer, + void *winsys_drawable_handle ); + + + + /** Set ptr = fence, with reference counting */ + void (*fence_reference)( struct pipe_screen *screen, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence ); + + /** + * Checks whether the fence has been signalled. + * \param flags driver-specific meaning + * \return zero on success. + */ + int (*fence_signalled)( struct pipe_screen *screen, + struct pipe_fence_handle *fence, + unsigned flags ); + + /** + * Wait for the fence to finish. + * \param flags driver-specific meaning + * \return zero on success. + */ + int (*fence_finish)( struct pipe_screen *screen, + struct pipe_fence_handle *fence, + unsigned flags ); + +}; + + +#ifdef __cplusplus +} +#endif + +#endif /* P_SCREEN_H */ diff --git a/src/gallium/include/pipe/p_shader_tokens.h b/src/gallium/include/pipe/p_shader_tokens.h new file mode 100644 index 0000000..ba433b2 --- /dev/null +++ b/src/gallium/include/pipe/p_shader_tokens.h @@ -0,0 +1,494 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2009-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL 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. + * + **************************************************************************/ + +#ifndef P_SHADER_TOKENS_H +#define P_SHADER_TOKENS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +struct tgsi_header +{ + unsigned HeaderSize : 8; + unsigned BodySize : 24; +}; + +#define TGSI_PROCESSOR_FRAGMENT 0 +#define TGSI_PROCESSOR_VERTEX 1 +#define TGSI_PROCESSOR_GEOMETRY 2 + +struct tgsi_processor +{ + unsigned Processor : 4; /* TGSI_PROCESSOR_ */ + unsigned Padding : 28; +}; + +#define TGSI_TOKEN_TYPE_DECLARATION 0 +#define TGSI_TOKEN_TYPE_IMMEDIATE 1 +#define TGSI_TOKEN_TYPE_INSTRUCTION 2 +#define TGSI_TOKEN_TYPE_PROPERTY 3 + +struct tgsi_token +{ + unsigned Type : 4; /**< TGSI_TOKEN_TYPE_x */ + unsigned NrTokens : 8; /**< UINT */ + unsigned Padding : 20; +}; + +enum tgsi_file_type { + TGSI_FILE_NULL =0, + TGSI_FILE_CONSTANT =1, + TGSI_FILE_INPUT =2, + TGSI_FILE_OUTPUT =3, + TGSI_FILE_TEMPORARY =4, + TGSI_FILE_SAMPLER =5, + TGSI_FILE_ADDRESS =6, + TGSI_FILE_IMMEDIATE =7, + TGSI_FILE_PREDICATE =8, + TGSI_FILE_SYSTEM_VALUE =9, + TGSI_FILE_IMMEDIATE_ARRAY =10, + TGSI_FILE_TEMPORARY_ARRAY =11, + TGSI_FILE_COUNT /**< how many TGSI_FILE_ types */ +}; + + +#define TGSI_WRITEMASK_NONE 0x00 +#define TGSI_WRITEMASK_X 0x01 +#define TGSI_WRITEMASK_Y 0x02 +#define TGSI_WRITEMASK_XY 0x03 +#define TGSI_WRITEMASK_Z 0x04 +#define TGSI_WRITEMASK_XZ 0x05 +#define TGSI_WRITEMASK_YZ 0x06 +#define TGSI_WRITEMASK_XYZ 0x07 +#define TGSI_WRITEMASK_W 0x08 +#define TGSI_WRITEMASK_XW 0x09 +#define TGSI_WRITEMASK_YW 0x0A +#define TGSI_WRITEMASK_XYW 0x0B +#define TGSI_WRITEMASK_ZW 0x0C +#define TGSI_WRITEMASK_XZW 0x0D +#define TGSI_WRITEMASK_YZW 0x0E +#define TGSI_WRITEMASK_XYZW 0x0F + +#define TGSI_INTERPOLATE_CONSTANT 0 +#define TGSI_INTERPOLATE_LINEAR 1 +#define TGSI_INTERPOLATE_PERSPECTIVE 2 +#define TGSI_INTERPOLATE_COUNT 3 + +#define TGSI_CYLINDRICAL_WRAP_X (1 << 0) +#define TGSI_CYLINDRICAL_WRAP_Y (1 << 1) +#define TGSI_CYLINDRICAL_WRAP_Z (1 << 2) +#define TGSI_CYLINDRICAL_WRAP_W (1 << 3) + +struct tgsi_declaration +{ + unsigned Type : 4; /**< TGSI_TOKEN_TYPE_DECLARATION */ + unsigned NrTokens : 8; /**< UINT */ + unsigned File : 4; /**< one of TGSI_FILE_x */ + unsigned UsageMask : 4; /**< bitmask of TGSI_WRITEMASK_x flags */ + unsigned Interpolate : 4; /**< one of TGSI_INTERPOLATE_x */ + unsigned Dimension : 1; /**< any extra dimension info? */ + unsigned Semantic : 1; /**< BOOL, any semantic info? */ + unsigned Centroid : 1; /**< centroid sampling? */ + unsigned Invariant : 1; /**< invariant optimization? */ + unsigned CylindricalWrap:4; /**< TGSI_CYLINDRICAL_WRAP_x flags */ +}; + +struct tgsi_declaration_range +{ + unsigned First : 16; /**< UINT */ + unsigned Last : 16; /**< UINT */ +}; + +struct tgsi_declaration_dimension +{ + unsigned Index2D:16; /**< UINT */ + unsigned Padding:16; +}; + +#define TGSI_SEMANTIC_POSITION 0 +#define TGSI_SEMANTIC_COLOR 1 +#define TGSI_SEMANTIC_BCOLOR 2 /**< back-face color */ +#define TGSI_SEMANTIC_FOG 3 +#define TGSI_SEMANTIC_PSIZE 4 +#define TGSI_SEMANTIC_GENERIC 5 +#define TGSI_SEMANTIC_NORMAL 6 +#define TGSI_SEMANTIC_FACE 7 +#define TGSI_SEMANTIC_EDGEFLAG 8 +#define TGSI_SEMANTIC_PRIMID 9 +#define TGSI_SEMANTIC_INSTANCEID 10 +#define TGSI_SEMANTIC_STENCIL 11 +#define TGSI_SEMANTIC_COUNT 12 /**< number of semantic values */ + +struct tgsi_declaration_semantic +{ + unsigned Name : 8; /**< one of TGSI_SEMANTIC_x */ + unsigned Index : 16; /**< UINT */ + unsigned Padding : 8; +}; + +#define TGSI_IMM_FLOAT32 0 +#define TGSI_IMM_UINT32 1 +#define TGSI_IMM_INT32 2 + +struct tgsi_immediate +{ + unsigned Type : 4; /**< TGSI_TOKEN_TYPE_IMMEDIATE */ + unsigned NrTokens : 14; /**< UINT */ + unsigned DataType : 4; /**< one of TGSI_IMM_x */ + unsigned Padding : 10; +}; + +union tgsi_immediate_data +{ + float Float; + unsigned Uint; + int Int; +}; + +#define TGSI_PROPERTY_GS_INPUT_PRIM 0 +#define TGSI_PROPERTY_GS_OUTPUT_PRIM 1 +#define TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES 2 +#define TGSI_PROPERTY_FS_COORD_ORIGIN 3 +#define TGSI_PROPERTY_FS_COORD_PIXEL_CENTER 4 +#define TGSI_PROPERTY_COUNT 5 + +struct tgsi_property { + unsigned Type : 4; /**< TGSI_TOKEN_TYPE_PROPERTY */ + unsigned NrTokens : 8; /**< UINT */ + unsigned PropertyName : 8; /**< one of TGSI_PROPERTY */ + unsigned Padding : 12; +}; + +#define TGSI_FS_COORD_ORIGIN_UPPER_LEFT 0 +#define TGSI_FS_COORD_ORIGIN_LOWER_LEFT 1 + +#define TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER 0 +#define TGSI_FS_COORD_PIXEL_CENTER_INTEGER 1 + +struct tgsi_property_data { + unsigned Data; +}; + +/* TGSI opcodes. + * + * For more information on semantics of opcodes and + * which APIs are known to use which opcodes, see + * gallium/docs/source/tgsi.rst + */ +#define TGSI_OPCODE_ARL 0 +#define TGSI_OPCODE_MOV 1 +#define TGSI_OPCODE_LIT 2 +#define TGSI_OPCODE_RCP 3 +#define TGSI_OPCODE_RSQ 4 +#define TGSI_OPCODE_EXP 5 +#define TGSI_OPCODE_LOG 6 +#define TGSI_OPCODE_MUL 7 +#define TGSI_OPCODE_ADD 8 +#define TGSI_OPCODE_DP3 9 +#define TGSI_OPCODE_DP4 10 +#define TGSI_OPCODE_DST 11 +#define TGSI_OPCODE_MIN 12 +#define TGSI_OPCODE_MAX 13 +#define TGSI_OPCODE_SLT 14 +#define TGSI_OPCODE_SGE 15 +#define TGSI_OPCODE_MAD 16 +#define TGSI_OPCODE_SUB 17 +#define TGSI_OPCODE_LRP 18 +#define TGSI_OPCODE_CND 19 + /* gap */ +#define TGSI_OPCODE_DP2A 21 + /* gap */ +#define TGSI_OPCODE_FRC 24 +#define TGSI_OPCODE_CLAMP 25 +#define TGSI_OPCODE_FLR 26 +#define TGSI_OPCODE_ROUND 27 +#define TGSI_OPCODE_EX2 28 +#define TGSI_OPCODE_LG2 29 +#define TGSI_OPCODE_POW 30 +#define TGSI_OPCODE_XPD 31 + /* gap */ +#define TGSI_OPCODE_ABS 33 +#define TGSI_OPCODE_RCC 34 +#define TGSI_OPCODE_DPH 35 +#define TGSI_OPCODE_COS 36 +#define TGSI_OPCODE_DDX 37 +#define TGSI_OPCODE_DDY 38 +#define TGSI_OPCODE_KILP 39 /* predicated kill */ +#define TGSI_OPCODE_PK2H 40 +#define TGSI_OPCODE_PK2US 41 +#define TGSI_OPCODE_PK4B 42 +#define TGSI_OPCODE_PK4UB 43 +#define TGSI_OPCODE_RFL 44 +#define TGSI_OPCODE_SEQ 45 +#define TGSI_OPCODE_SFL 46 +#define TGSI_OPCODE_SGT 47 +#define TGSI_OPCODE_SIN 48 +#define TGSI_OPCODE_SLE 49 +#define TGSI_OPCODE_SNE 50 +#define TGSI_OPCODE_STR 51 +#define TGSI_OPCODE_TEX 52 +#define TGSI_OPCODE_TXD 53 +#define TGSI_OPCODE_TXP 54 +#define TGSI_OPCODE_UP2H 55 +#define TGSI_OPCODE_UP2US 56 +#define TGSI_OPCODE_UP4B 57 +#define TGSI_OPCODE_UP4UB 58 +#define TGSI_OPCODE_X2D 59 +#define TGSI_OPCODE_ARA 60 +#define TGSI_OPCODE_ARR 61 +#define TGSI_OPCODE_BRA 62 +#define TGSI_OPCODE_CAL 63 +#define TGSI_OPCODE_RET 64 +#define TGSI_OPCODE_SSG 65 /* SGN */ +#define TGSI_OPCODE_CMP 66 +#define TGSI_OPCODE_SCS 67 +#define TGSI_OPCODE_TXB 68 +#define TGSI_OPCODE_NRM 69 +#define TGSI_OPCODE_DIV 70 +#define TGSI_OPCODE_DP2 71 +#define TGSI_OPCODE_TXL 72 +#define TGSI_OPCODE_BRK 73 +#define TGSI_OPCODE_IF 74 + /* gap */ +#define TGSI_OPCODE_ELSE 77 +#define TGSI_OPCODE_ENDIF 78 + /* gap */ +#define TGSI_OPCODE_PUSHA 81 +#define TGSI_OPCODE_POPA 82 +#define TGSI_OPCODE_CEIL 83 +#define TGSI_OPCODE_I2F 84 +#define TGSI_OPCODE_NOT 85 +#define TGSI_OPCODE_TRUNC 86 +#define TGSI_OPCODE_SHL 87 + /* gap */ +#define TGSI_OPCODE_AND 89 +#define TGSI_OPCODE_OR 90 +#define TGSI_OPCODE_MOD 91 +#define TGSI_OPCODE_XOR 92 +#define TGSI_OPCODE_SAD 93 +#define TGSI_OPCODE_TXF 94 +#define TGSI_OPCODE_TXQ 95 +#define TGSI_OPCODE_CONT 96 +#define TGSI_OPCODE_EMIT 97 +#define TGSI_OPCODE_ENDPRIM 98 +#define TGSI_OPCODE_BGNLOOP 99 +#define TGSI_OPCODE_BGNSUB 100 +#define TGSI_OPCODE_ENDLOOP 101 +#define TGSI_OPCODE_ENDSUB 102 + /* gap */ +#define TGSI_OPCODE_NOP 107 + /* gap */ +#define TGSI_OPCODE_NRM4 112 +#define TGSI_OPCODE_CALLNZ 113 +#define TGSI_OPCODE_IFC 114 +#define TGSI_OPCODE_BREAKC 115 +#define TGSI_OPCODE_KIL 116 /* conditional kill */ +#define TGSI_OPCODE_END 117 /* aka HALT */ + /* gap */ +#define TGSI_OPCODE_F2I 119 +#define TGSI_OPCODE_IDIV 120 +#define TGSI_OPCODE_IMAX 121 +#define TGSI_OPCODE_IMIN 122 +#define TGSI_OPCODE_INEG 123 +#define TGSI_OPCODE_ISGE 124 +#define TGSI_OPCODE_ISHR 125 +#define TGSI_OPCODE_ISLT 126 +#define TGSI_OPCODE_F2U 127 +#define TGSI_OPCODE_U2F 128 +#define TGSI_OPCODE_UADD 129 +#define TGSI_OPCODE_UDIV 130 +#define TGSI_OPCODE_UMAD 131 +#define TGSI_OPCODE_UMAX 132 +#define TGSI_OPCODE_UMIN 133 +#define TGSI_OPCODE_UMOD 134 +#define TGSI_OPCODE_UMUL 135 +#define TGSI_OPCODE_USEQ 136 +#define TGSI_OPCODE_USGE 137 +#define TGSI_OPCODE_USHR 138 +#define TGSI_OPCODE_USLT 139 +#define TGSI_OPCODE_USNE 140 +#define TGSI_OPCODE_SWITCH 141 +#define TGSI_OPCODE_CASE 142 +#define TGSI_OPCODE_DEFAULT 143 +#define TGSI_OPCODE_ENDSWITCH 144 +#define TGSI_OPCODE_LAST 145 + +#define TGSI_SAT_NONE 0 /* do not saturate */ +#define TGSI_SAT_ZERO_ONE 1 /* clamp to [0,1] */ +#define TGSI_SAT_MINUS_PLUS_ONE 2 /* clamp to [-1,1] */ + +/** + * Opcode is the operation code to execute. A given operation defines the + * semantics how the source registers (if any) are interpreted and what is + * written to the destination registers (if any) as a result of execution. + * + * NumDstRegs and NumSrcRegs is the number of destination and source registers, + * respectively. For a given operation code, those numbers are fixed and are + * present here only for convenience. + * + * If Predicate is TRUE, tgsi_instruction_predicate token immediately follows. + * + * Saturate controls how are final results in destination registers modified. + */ + +struct tgsi_instruction +{ + unsigned Type : 4; /* TGSI_TOKEN_TYPE_INSTRUCTION */ + unsigned NrTokens : 8; /* UINT */ + unsigned Opcode : 8; /* TGSI_OPCODE_ */ + unsigned Saturate : 2; /* TGSI_SAT_ */ + unsigned NumDstRegs : 2; /* UINT */ + unsigned NumSrcRegs : 4; /* UINT */ + unsigned Predicate : 1; /* BOOL */ + unsigned Label : 1; + unsigned Texture : 1; + unsigned Padding : 1; +}; + +/* + * If tgsi_instruction::Label is TRUE, tgsi_instruction_label follows. + * + * If tgsi_instruction::Texture is TRUE, tgsi_instruction_texture follows. + * + * Then, tgsi_instruction::NumDstRegs of tgsi_dst_register follow. + * + * Then, tgsi_instruction::NumSrcRegs of tgsi_src_register follow. + * + * tgsi_instruction::NrTokens contains the total number of words that make the + * instruction, including the instruction word. + */ + +#define TGSI_SWIZZLE_X 0 +#define TGSI_SWIZZLE_Y 1 +#define TGSI_SWIZZLE_Z 2 +#define TGSI_SWIZZLE_W 3 + +struct tgsi_instruction_label +{ + unsigned Label : 24; /* UINT */ + unsigned Padding : 8; +}; + +#define TGSI_TEXTURE_UNKNOWN 0 +#define TGSI_TEXTURE_1D 1 +#define TGSI_TEXTURE_2D 2 +#define TGSI_TEXTURE_3D 3 +#define TGSI_TEXTURE_CUBE 4 +#define TGSI_TEXTURE_RECT 5 +#define TGSI_TEXTURE_SHADOW1D 6 +#define TGSI_TEXTURE_SHADOW2D 7 +#define TGSI_TEXTURE_SHADOWRECT 8 +#define TGSI_TEXTURE_COUNT 9 + +struct tgsi_instruction_texture +{ + unsigned Texture : 8; /* TGSI_TEXTURE_ */ + unsigned Padding : 24; +}; + +/* + * For SM3, the following constraint applies. + * - Swizzle is either set to identity or replicate. + */ +struct tgsi_instruction_predicate +{ + int Index : 16; /* SINT */ + unsigned SwizzleX : 2; /* TGSI_SWIZZLE_x */ + unsigned SwizzleY : 2; /* TGSI_SWIZZLE_x */ + unsigned SwizzleZ : 2; /* TGSI_SWIZZLE_x */ + unsigned SwizzleW : 2; /* TGSI_SWIZZLE_x */ + unsigned Negate : 1; /* BOOL */ + unsigned Padding : 7; +}; + +/** + * File specifies the register array to access. + * + * Index specifies the element number of a register in the register file. + * + * If Indirect is TRUE, Index should be offset by the X component of a source + * register that follows. The register can be now fetched into local storage + * for further processing. + * + * If Negate is TRUE, all components of the fetched register are negated. + * + * The fetched register components are swizzled according to SwizzleX, SwizzleY, + * SwizzleZ and SwizzleW. + * + */ + +struct tgsi_src_register +{ + unsigned File : 4; /* TGSI_FILE_ */ + unsigned Indirect : 1; /* BOOL */ + unsigned Dimension : 1; /* BOOL */ + int Index : 16; /* SINT */ + unsigned SwizzleX : 2; /* TGSI_SWIZZLE_ */ + unsigned SwizzleY : 2; /* TGSI_SWIZZLE_ */ + unsigned SwizzleZ : 2; /* TGSI_SWIZZLE_ */ + unsigned SwizzleW : 2; /* TGSI_SWIZZLE_ */ + unsigned Absolute : 1; /* BOOL */ + unsigned Negate : 1; /* BOOL */ +}; + +/** + * If tgsi_src_register::Modifier is TRUE, tgsi_src_register_modifier follows. + * + * Then, if tgsi_src_register::Indirect is TRUE, another tgsi_src_register + * follows. + * + * Then, if tgsi_src_register::Dimension is TRUE, tgsi_dimension follows. + */ + + +struct tgsi_dimension +{ + unsigned Indirect : 1; /* BOOL */ + unsigned Dimension : 1; /* BOOL */ + unsigned Padding : 14; + int Index : 16; /* SINT */ +}; + +struct tgsi_dst_register +{ + unsigned File : 4; /* TGSI_FILE_ */ + unsigned WriteMask : 4; /* TGSI_WRITEMASK_ */ + unsigned Indirect : 1; /* BOOL */ + unsigned Dimension : 1; /* BOOL */ + int Index : 16; /* SINT */ + unsigned Padding : 6; +}; + + +#ifdef __cplusplus +} +#endif + +#endif /* P_SHADER_TOKENS_H */ diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h new file mode 100644 index 0000000..226ae86 --- /dev/null +++ b/src/gallium/include/pipe/p_state.h @@ -0,0 +1,483 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/** + * @file + * + * Abstract graphics pipe state objects. + * + * Basic notes: + * 1. Want compact representations, so we use bitfields. + * 2. Put bitfields before other (GLfloat) fields. + */ + + +#ifndef PIPE_STATE_H +#define PIPE_STATE_H + +#include "p_compiler.h" +#include "p_defines.h" +#include "p_format.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Implementation limits + */ +#define PIPE_MAX_ATTRIBS 32 +#define PIPE_MAX_CLIP_PLANES 6 +#define PIPE_MAX_COLOR_BUFS 8 +#define PIPE_MAX_CONSTANT_BUFFERS 32 +#define PIPE_MAX_SAMPLERS 16 +#define PIPE_MAX_VERTEX_SAMPLERS 16 +#define PIPE_MAX_GEOMETRY_SAMPLERS 16 +#define PIPE_MAX_SHADER_INPUTS 32 +#define PIPE_MAX_SHADER_OUTPUTS 32 +#define PIPE_MAX_TEXTURE_LEVELS 16 +#define PIPE_MAX_SO_BUFFERS 4 + + +struct pipe_reference +{ + int32_t count; /* atomic */ +}; + + + +/** + * Primitive (point/line/tri) rasterization info + */ +struct pipe_rasterizer_state +{ + unsigned flatshade:1; + unsigned light_twoside:1; + unsigned front_ccw:1; + unsigned cull_face:2; /**< PIPE_FACE_x */ + unsigned fill_front:2; /**< PIPE_POLYGON_MODE_x */ + unsigned fill_back:2; /**< PIPE_POLYGON_MODE_x */ + unsigned offset_point:1; + unsigned offset_line:1; + unsigned offset_tri:1; + unsigned scissor:1; + unsigned poly_smooth:1; + unsigned poly_stipple_enable:1; + unsigned point_smooth:1; + unsigned sprite_coord_enable:PIPE_MAX_SHADER_OUTPUTS; + unsigned sprite_coord_mode:1; /**< PIPE_SPRITE_COORD_ */ + unsigned point_quad_rasterization:1; /** points rasterized as quads or points */ + unsigned point_size_per_vertex:1; /**< size computed in vertex shader */ + unsigned multisample:1; /* XXX maybe more ms state in future */ + unsigned line_smooth:1; + unsigned line_stipple_enable:1; + unsigned line_stipple_factor:8; /**< [1..256] actually */ + unsigned line_stipple_pattern:16; + unsigned line_last_pixel:1; + + /** + * Use the first vertex of a primitive as the provoking vertex for + * flat shading. + */ + unsigned flatshade_first:1; + + /** + * When true, triangle rasterization uses (0.5, 0.5) pixel centers + * for determining pixel ownership. + * + * When false, triangle rasterization uses (0,0) pixel centers for + * determining pixel ownership. + * + * Triangle rasterization always uses a 'top,left' rule for pixel + * ownership, this just alters which point we consider the pixel + * center for that test. + */ + unsigned gl_rasterization_rules:1; + + float line_width; + float point_size; /**< used when no per-vertex size */ + float offset_units; + float offset_scale; +}; + + +struct pipe_poly_stipple +{ + unsigned stipple[32]; +}; + + +struct pipe_viewport_state +{ + float scale[4]; + float translate[4]; +}; + + +struct pipe_scissor_state +{ + unsigned minx:16; + unsigned miny:16; + unsigned maxx:16; + unsigned maxy:16; +}; + + +struct pipe_clip_state +{ + float ucp[PIPE_MAX_CLIP_PLANES][4]; + unsigned nr; + unsigned depth_clamp:1; +}; + + +struct pipe_shader_state +{ + const struct tgsi_token *tokens; +}; + + +struct pipe_depth_state +{ + unsigned enabled:1; /**< depth test enabled? */ + unsigned writemask:1; /**< allow depth buffer writes? */ + unsigned func:3; /**< depth test func (PIPE_FUNC_x) */ +}; + + +struct pipe_stencil_state +{ + unsigned enabled:1; /**< stencil[0]: stencil enabled, stencil[1]: two-side enabled */ + unsigned func:3; /**< PIPE_FUNC_x */ + unsigned fail_op:3; /**< PIPE_STENCIL_OP_x */ + unsigned zpass_op:3; /**< PIPE_STENCIL_OP_x */ + unsigned zfail_op:3; /**< PIPE_STENCIL_OP_x */ + unsigned valuemask:8; + unsigned writemask:8; +}; + + +struct pipe_alpha_state +{ + unsigned enabled:1; + unsigned func:3; /**< PIPE_FUNC_x */ + float ref_value; /**< reference value */ +}; + + +struct pipe_depth_stencil_alpha_state +{ + struct pipe_depth_state depth; + struct pipe_stencil_state stencil[2]; /**< [0] = front, [1] = back */ + struct pipe_alpha_state alpha; +}; + + +struct pipe_rt_blend_state +{ + unsigned blend_enable:1; + + unsigned rgb_func:3; /**< PIPE_BLEND_x */ + unsigned rgb_src_factor:5; /**< PIPE_BLENDFACTOR_x */ + unsigned rgb_dst_factor:5; /**< PIPE_BLENDFACTOR_x */ + + unsigned alpha_func:3; /**< PIPE_BLEND_x */ + unsigned alpha_src_factor:5; /**< PIPE_BLENDFACTOR_x */ + unsigned alpha_dst_factor:5; /**< PIPE_BLENDFACTOR_x */ + + unsigned colormask:4; /**< bitmask of PIPE_MASK_R/G/B/A */ +}; + +struct pipe_blend_state +{ + unsigned independent_blend_enable:1; + unsigned logicop_enable:1; + unsigned logicop_func:4; /**< PIPE_LOGICOP_x */ + unsigned dither:1; + unsigned alpha_to_coverage:1; + unsigned alpha_to_one:1; + struct pipe_rt_blend_state rt[PIPE_MAX_COLOR_BUFS]; +}; + + +struct pipe_blend_color +{ + float color[4]; +}; + +struct pipe_stencil_ref +{ + ubyte ref_value[2]; +}; + +struct pipe_framebuffer_state +{ + unsigned width, height; + + /** multiple color buffers for multiple render targets */ + unsigned nr_cbufs; + struct pipe_surface *cbufs[PIPE_MAX_COLOR_BUFS]; + + struct pipe_surface *zsbuf; /**< Z/stencil buffer */ +}; + + +/** + * Texture sampler state. + */ +struct pipe_sampler_state +{ + unsigned wrap_s:3; /**< PIPE_TEX_WRAP_x */ + unsigned wrap_t:3; /**< PIPE_TEX_WRAP_x */ + unsigned wrap_r:3; /**< PIPE_TEX_WRAP_x */ + unsigned min_img_filter:2; /**< PIPE_TEX_FILTER_x */ + unsigned min_mip_filter:2; /**< PIPE_TEX_MIPFILTER_x */ + unsigned mag_img_filter:2; /**< PIPE_TEX_FILTER_x */ + unsigned compare_mode:1; /**< PIPE_TEX_COMPARE_x */ + unsigned compare_func:3; /**< PIPE_FUNC_x */ + unsigned normalized_coords:1; /**< Are coords normalized to [0,1]? */ + unsigned max_anisotropy:6; + float lod_bias; /**< LOD/lambda bias */ + float min_lod, max_lod; /**< LOD clamp range, after bias */ + float border_color[4]; +}; + + +/** + * A view into a texture that can be bound to a color render target / + * depth stencil attachment point. + */ +struct pipe_surface +{ + struct pipe_reference reference; + struct pipe_resource *texture; /**< resource into which this is a view */ + struct pipe_context *context; /**< context this view belongs to */ + enum pipe_format format; + + /* XXX width/height should be removed */ + unsigned width; /**< logical width in pixels */ + unsigned height; /**< logical height in pixels */ + + unsigned usage; /**< bitmask of PIPE_BIND_x */ + + union { + struct { + unsigned level; + unsigned first_layer:16; + unsigned last_layer:16; + } tex; + struct { + unsigned first_element; + unsigned last_element; + } buf; + } u; +}; + + +/** + * A view into a texture that can be bound to a shader stage. + */ +struct pipe_sampler_view +{ + struct pipe_reference reference; + enum pipe_format format; /**< typed PIPE_FORMAT_x */ + struct pipe_resource *texture; /**< texture into which this is a view */ + struct pipe_context *context; /**< context this view belongs to */ + union { + struct { + unsigned first_layer:16; /**< first layer to use for array textures */ + unsigned last_layer:16; /**< last layer to use for array textures */ + unsigned first_level:8; /**< first mipmap level to use */ + unsigned last_level:8; /**< last mipmap level to use */ + } tex; + struct { + unsigned first_element; + unsigned last_element; + } buf; + } u; + unsigned swizzle_r:3; /**< PIPE_SWIZZLE_x for red component */ + unsigned swizzle_g:3; /**< PIPE_SWIZZLE_x for green component */ + unsigned swizzle_b:3; /**< PIPE_SWIZZLE_x for blue component */ + unsigned swizzle_a:3; /**< PIPE_SWIZZLE_x for alpha component */ +}; + + +/** + * Subregion of 1D/2D/3D image resource. + */ +struct pipe_box +{ + unsigned x; + unsigned y; + unsigned z; + unsigned width; + unsigned height; + unsigned depth; +}; + + +/** + * A memory object/resource such as a vertex buffer or texture. + */ +struct pipe_resource +{ + struct pipe_reference reference; + struct pipe_screen *screen; /**< screen that this texture belongs to */ + enum pipe_texture_target target; /**< PIPE_TEXTURE_x */ + enum pipe_format format; /**< PIPE_FORMAT_x */ + + unsigned width0; + unsigned height0; + unsigned depth0; + unsigned array_size; + + unsigned last_level:8; /**< Index of last mipmap level present/defined */ + unsigned nr_samples:8; /**< for multisampled surfaces, nr of samples */ + unsigned usage:8; /**< PIPE_USAGE_x (not a bitmask) */ + + unsigned bind; /**< bitmask of PIPE_BIND_x */ + unsigned flags; /**< bitmask of PIPE_RESOURCE_FLAG_x */ +}; + +struct pipe_stream_output_state +{ + /**< number of the output buffer to insert each element into */ + int output_buffer[PIPE_MAX_SHADER_OUTPUTS]; + /**< which register to grab each output from */ + int register_index[PIPE_MAX_SHADER_OUTPUTS]; + /**< TGSI_WRITEMASK signifying which components to output */ + ubyte register_mask[PIPE_MAX_SHADER_OUTPUTS]; + /**< number of outputs */ + int num_outputs; + + /**< stride for an entire vertex, only used if all output_buffers + * are 0 */ + unsigned stride; +}; + + +/** + * Transfer object. For data transfer to/from a resource. + */ +struct pipe_transfer +{ + struct pipe_resource *resource; /**< resource to transfer to/from */ + unsigned level; + enum pipe_transfer_usage usage; + struct pipe_box box; + unsigned stride; + unsigned layer_stride; + void *data; +}; + + + +/** + * A vertex buffer. Typically, all the vertex data/attributes for + * drawing something will be in one buffer. But it's also possible, for + * example, to put colors in one buffer and texcoords in another. + */ +struct pipe_vertex_buffer +{ + unsigned stride; /**< stride to same attrib in next vertex, in bytes */ + unsigned max_index; /**< number of vertices in this buffer */ + unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */ + struct pipe_resource *buffer; /**< the actual buffer */ +}; + + +/** + * Information to describe a vertex attribute (position, color, etc) + */ +struct pipe_vertex_element +{ + /** Offset of this attribute, in bytes, from the start of the vertex */ + unsigned src_offset; + + /** Instance data rate divisor. 0 means this is per-vertex data, + * n means per-instance data used for n consecutive instances (n > 0). + */ + unsigned instance_divisor; + + /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does + * this attribute live in? + */ + unsigned vertex_buffer_index; + + enum pipe_format src_format; +}; + + +/** + * An index buffer. When an index buffer is bound, all indices to vertices + * will be looked up in the buffer. + */ +struct pipe_index_buffer +{ + unsigned index_size; /**< size of an index, in bytes */ + unsigned offset; /**< offset to start of data in buffer, in bytes */ + struct pipe_resource *buffer; /**< the actual buffer */ +}; + + +/** + * Information to describe a draw_vbo call. + */ +struct pipe_draw_info +{ + boolean indexed; /**< use index buffer */ + + unsigned mode; /**< the mode of the primitive */ + unsigned start; /**< the index of the first vertex */ + unsigned count; /**< number of vertices */ + + unsigned start_instance; /**< first instance id */ + unsigned instance_count; /**< number of instances */ + + /** + * For indexed drawing, these fields apply after index lookup. + */ + int index_bias; /**< a bias to be added to each index */ + unsigned min_index; /**< the min index */ + unsigned max_index; /**< the max index */ + + /** + * Primitive restart enable/index (only applies to indexed drawing) + */ + boolean primitive_restart; + unsigned restart_index; +}; + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gallium/include/state_tracker/drisw_api.h b/src/gallium/include/state_tracker/drisw_api.h new file mode 100644 index 0000000..944a649 --- /dev/null +++ b/src/gallium/include/state_tracker/drisw_api.h @@ -0,0 +1,23 @@ +#ifndef _DRISW_API_H_ +#define _DRISW_API_H_ + +#include "pipe/p_compiler.h" + +struct pipe_screen; +struct dri_drawable; + +/** + * This callback struct is intended for the winsys to call the loader. + */ +struct drisw_loader_funcs +{ + void (*put_image) (struct dri_drawable *dri_drawable, + void *data, unsigned width, unsigned height); +}; + +/** + * Implemented by the drisw target. + */ +struct pipe_screen * drisw_create_screen(struct drisw_loader_funcs *lf); + +#endif diff --git a/src/gallium/include/state_tracker/drm_driver.h b/src/gallium/include/state_tracker/drm_driver.h new file mode 100644 index 0000000..d94c1e6 --- /dev/null +++ b/src/gallium/include/state_tracker/drm_driver.h @@ -0,0 +1,71 @@ + +#ifndef _DRM_DRIVER_H_ +#define _DRM_DRIVER_H_ + +#include "pipe/p_compiler.h" + +struct pipe_screen; +struct pipe_winsys; +struct pipe_context; +struct pipe_resource; + +#define DRM_API_HANDLE_TYPE_SHARED 0 +#define DRM_API_HANDLE_TYPE_KMS 1 + +/** + * For use with pipe_screen::{texture_from_handle|texture_get_handle}. + */ +struct winsys_handle +{ + /** + * Unused for texture_from_handle, always + * DRM_API_HANDLE_TYPE_SHARED. Input to texture_get_handle, + * use TEXTURE_USAGE to select handle for kms or ipc. + */ + unsigned type; + /** + * Input to texture_from_handle. + * Output for texture_get_handle. + */ + unsigned handle; + /** + * Input to texture_from_handle. + * Output for texture_get_handle. + */ + unsigned stride; +}; + +struct drm_driver_descriptor +{ + /** + * Identifying sufix/prefix of the binary, used by egl. + */ + const char *name; + + /** + * Kernel driver name, as accepted by drmOpenByName. + */ + const char *driver_name; + + /** + * Create a pipe srcreen. + * + * This function does any wrapping of the screen. + * For example wrapping trace or rbug debugging drivers around it. + */ + struct pipe_screen* (*create_screen)(int drm_fd); +}; + +extern struct drm_driver_descriptor driver_descriptor; + +/** + * Instantiate a drm_driver_descriptor struct. + */ +#define DRM_DRIVER_DESCRIPTOR(name_str, driver_name_str, func) \ +struct drm_driver_descriptor driver_descriptor = { \ + .name = name_str, \ + .driver_name = driver_name_str, \ + .create_screen = func, \ +}; + +#endif diff --git a/src/gallium/include/state_tracker/graw.h b/src/gallium/include/state_tracker/graw.h new file mode 100644 index 0000000..217fa31 --- /dev/null +++ b/src/gallium/include/state_tracker/graw.h @@ -0,0 +1,96 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef GALLIUM_RAW_H +#define GALLIUM_RAW_H + +/* This is an API for exercising gallium functionality in a + * platform-neutral fashion. Whatever platform integration is + * necessary to implement this interface is orchestrated by the + * individual target building this entity. + * + * For instance, the graw-xlib target includes code to implent these + * interfaces on top of the X window system. + * + * Programs using this interface may additionally benefit from some of + * the utilities currently in the libgallium.a library, especially + * those for parsing text representations of TGSI shaders. + */ + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" + +struct pipe_context; +struct pipe_screen; +struct pipe_surface; + +/* Returns a handle to be used with flush_frontbuffer()/present(). + * + * Query format support with screen::is_format_supported and usage + * XXX. + */ +PUBLIC struct pipe_screen *graw_create_window_and_screen( int x, + int y, + unsigned width, + unsigned height, + enum pipe_format format, + void **handle); + +PUBLIC void graw_set_display_func( void (*func)( void ) ); +PUBLIC void graw_main_loop( void ); + +PUBLIC void *graw_parse_geometry_shader( struct pipe_context *pipe, + const char *text ); + +PUBLIC void *graw_parse_vertex_shader( struct pipe_context *pipe, + const char *text ); + +PUBLIC void *graw_parse_fragment_shader( struct pipe_context *pipe, + const char *text ); + +/* Parse a single command-line option, if any. Options include: + * + * -o + * + * If an option has been successfully parsed, argi is updated + * to point just after the option and return TRUE. + */ +PUBLIC boolean graw_parse_args(int *argi, int argc, char *argv[]); + +/* Saves surface contents to a file. + * + * If filename is NULL, the filename provided with the `-o' option + * is used. If the option has not been specified, the surface + * will not be saved. + * + * Returns TRUE if the surface has been saved. + */ +PUBLIC boolean graw_save_surface_to_file(struct pipe_context *pipe, + struct pipe_surface *surface, + const char *filename); + +#endif diff --git a/src/gallium/include/state_tracker/st_api.h b/src/gallium/include/state_tracker/st_api.h new file mode 100644 index 0000000..1c2148b --- /dev/null +++ b/src/gallium/include/state_tracker/st_api.h @@ -0,0 +1,470 @@ +/********************************************************** + * 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 _ST_API_H_ +#define _ST_API_H_ + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" + +/** + * \file API for communication between state trackers and state tracker + * managers. + * + * While both are state tackers, we use the term state tracker for rendering + * APIs such as OpenGL or OpenVG, and state tracker manager for window system + * APIs such as EGL or GLX in this file. + * + * This file defines an API to be implemented by both state trackers and state + * tracker managers. + */ + +/** + * The supported rendering API of a state tracker. + */ +enum st_api_type { + ST_API_OPENGL, + ST_API_OPENVG, + + ST_API_COUNT +}; + +/** + * The profile of a context. + */ +enum st_profile_type +{ + ST_PROFILE_DEFAULT, + ST_PROFILE_OPENGL_CORE, + ST_PROFILE_OPENGL_ES1, + ST_PROFILE_OPENGL_ES2 +}; + +/* for profile_mask in st_api */ +#define ST_PROFILE_DEFAULT_MASK (1 << ST_PROFILE_DEFAULT) +#define ST_PROFILE_OPENGL_CORE_MASK (1 << ST_PROFILE_OPENGL_CORE) +#define ST_PROFILE_OPENGL_ES1_MASK (1 << ST_PROFILE_OPENGL_ES1) +#define ST_PROFILE_OPENGL_ES2_MASK (1 << ST_PROFILE_OPENGL_ES2) + +/** + * Used in st_context_iface->teximage. + */ +enum st_texture_type { + ST_TEXTURE_1D, + ST_TEXTURE_2D, + ST_TEXTURE_3D, + ST_TEXTURE_RECT +}; + +/** + * Available attachments of framebuffer. + */ +enum st_attachment_type { + ST_ATTACHMENT_FRONT_LEFT, + ST_ATTACHMENT_BACK_LEFT, + ST_ATTACHMENT_FRONT_RIGHT, + ST_ATTACHMENT_BACK_RIGHT, + ST_ATTACHMENT_DEPTH_STENCIL, + ST_ATTACHMENT_ACCUM, + ST_ATTACHMENT_SAMPLE, + + ST_ATTACHMENT_COUNT, + ST_ATTACHMENT_INVALID = -1 +}; + +/* for buffer_mask in st_visual */ +#define ST_ATTACHMENT_FRONT_LEFT_MASK (1 << ST_ATTACHMENT_FRONT_LEFT) +#define ST_ATTACHMENT_BACK_LEFT_MASK (1 << ST_ATTACHMENT_BACK_LEFT) +#define ST_ATTACHMENT_FRONT_RIGHT_MASK (1 << ST_ATTACHMENT_FRONT_RIGHT) +#define ST_ATTACHMENT_BACK_RIGHT_MASK (1 << ST_ATTACHMENT_BACK_RIGHT) +#define ST_ATTACHMENT_DEPTH_STENCIL_MASK (1 << ST_ATTACHMENT_DEPTH_STENCIL) +#define ST_ATTACHMENT_ACCUM_MASK (1 << ST_ATTACHMENT_ACCUM) +#define ST_ATTACHMENT_SAMPLE_MASK (1 << ST_ATTACHMENT_SAMPLE) + +/** + * Enumerations of state tracker context resources. + */ +enum st_context_resource_type { + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_2D, + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_3D, + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_POSITIVE_X, + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_NEGATIVE_X, + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_POSITIVE_Y, + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_NEGATIVE_Y, + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_POSITIVE_Z, + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_NEGATIVE_Z, + ST_CONTEXT_RESOURCE_OPENGL_RENDERBUFFER, + ST_CONTEXT_RESOURCE_OPENVG_PARENT_IMAGE +}; + +/** + * Value to st_manager->get_param function. + */ +enum st_manager_param { + /** + * The dri state tracker on old libGL's doesn't do the right thing + * with regards to invalidating the framebuffers. + * + * For the mesa state tracker that means that it needs to invalidate + * the framebuffer in glViewport itself. + */ + ST_MANAGER_BROKEN_INVALIDATE +}; + +/** + * The return type of st_api->get_proc_address. + */ +typedef void (*st_proc_t)(void); + +struct pipe_context; +struct pipe_resource; +struct pipe_fence_handle; + +/** + * Used in st_context_iface->get_resource_for_egl_image. + */ +struct st_context_resource +{ + /* these fields are filled by the caller */ + enum st_context_resource_type type; + void *resource; + + /* this is owned by the caller */ + struct pipe_resource *texture; +}; + +/** + * Used in st_manager_iface->get_egl_image. + */ +struct st_egl_image +{ + /* this is owned by the caller */ + struct pipe_resource *texture; + + unsigned level; + unsigned layer; +}; + +/** + * Represent the visual of a framebuffer. + */ +struct st_visual +{ + /** + * Available buffers. Tested with ST_FRAMEBUFFER_*_MASK. + */ + unsigned buffer_mask; + + /** + * Buffer formats. The formats are always set even when the buffer is + * not available. + */ + enum pipe_format color_format; + enum pipe_format depth_stencil_format; + enum pipe_format accum_format; + int samples; + + /** + * Desired render buffer. + */ + enum st_attachment_type render_buffer; +}; + +/** + * Represent the attributes of a context. + */ +struct st_context_attribs +{ + /** + * The profile and minimal version to support. + * + * The valid profiles and versions are rendering API dependent. The latest + * version satisfying the request should be returned, unless + * forward_compatiible is true. + */ + enum st_profile_type profile; + int major, minor; + + /** + * Enable debugging. + */ + boolean debug; + + /** + * Return the exact version and disallow the use of deprecated features. + */ + boolean forward_compatible; + + /** + * The visual of the framebuffers the context will be bound to. + */ + struct st_visual visual; +}; + +/** + * Represent a windowing system drawable. + * + * The framebuffer is implemented by the state tracker manager and + * used by the state trackers. + * + * Instead of the winsys pokeing into the API context to figure + * out what buffers that might be needed in the future by the API + * context, it calls into the framebuffer to get the textures. + * + * This structure along with the notify_invalid_framebuffer + * allows framebuffers to be shared between different threads + * but at the same make the API context free from thread + * syncronisation primitves, with the exception of a small + * atomic flag used for notification of framebuffer dirty status. + * + * The thread syncronisation is put inside the framebuffer + * and only called once the framebuffer has become dirty. + */ +struct st_framebuffer_iface +{ + /** + * Available for the state tracker manager to use. + */ + void *st_manager_private; + + /** + * The visual of a framebuffer. + */ + const struct st_visual *visual; + + /** + * Flush the front buffer. + * + * On some window systems, changes to the front buffers are not immediately + * visible. They need to be flushed. + * + * @att is one of the front buffer attachments. + */ + boolean (*flush_front)(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt); + + /** + * The state tracker asks for the textures it needs. + * + * It should try to only ask for attachments that it currently renders + * to, thus allowing the winsys to delay the allocation of textures not + * needed. For example front buffer attachments are not needed if you + * only do back buffer rendering. + * + * The implementor of this function needs to also ensure + * thread safty as this call might be done from multiple threads. + * + * The returned textures are owned by the caller. They should be + * unreferenced when no longer used. If this function is called multiple + * times with different sets of attachments, those buffers not included in + * the last call might be destroyed. This behavior might change in the + * future. + */ + boolean (*validate)(struct st_framebuffer_iface *stfbi, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_resource **out); +}; + +/** + * Represent a rendering context. + * + * This entity is created from st_api and used by the state tracker manager. + */ +struct st_context_iface +{ + /** + * Available for the state tracker and the manager to use. + */ + void *st_context_private; + void *st_manager_private; + + /** + * Destroy the context. + */ + void (*destroy)(struct st_context_iface *stctxi); + + /** + * Invalidate the current textures that was taken from a framebuffer. + * + * The state tracker manager calls this function to let the rendering + * context know that it should update the textures it got from + * st_framebuffer_iface::validate. It should do so at the latest time possible. + * Possible right before sending triangles to the pipe context. + * + * For certain platforms this function might be called from a thread other + * than the thread that the context is currently bound in, and must + * therefore be thread safe. But it is the state tracker manager's + * responsibility to make sure that the framebuffer is bound to the context + * and the API context is current for the duration of this call. + * + * Thus reducing the sync primitive needed to a single atomic flag. + */ + void (*notify_invalid_framebuffer)(struct st_context_iface *stctxi, + struct st_framebuffer_iface *stfbi); + + /** + * Flush all drawing from context to the pipe also flushes the pipe. + */ + void (*flush)(struct st_context_iface *stctxi, unsigned flags, + struct pipe_fence_handle **fence); + + /** + * Replace the texture image of a texture object at the specified level. + * + * This function is optional. + */ + boolean (*teximage)(struct st_context_iface *stctxi, enum st_texture_type target, + int level, enum pipe_format internal_format, + struct pipe_resource *tex, boolean mipmap); + + /** + * Used to implement glXCopyContext. + */ + void (*copy)(struct st_context_iface *stctxi, + struct st_context_iface *stsrci, unsigned mask); + + /** + * Used to implement wglShareLists. + */ + boolean (*share)(struct st_context_iface *stctxi, + struct st_context_iface *stsrci); + + /** + * Look up and return the info of a resource for EGLImage. + * + * This function is optional. + */ + boolean (*get_resource_for_egl_image)(struct st_context_iface *stctxi, + struct st_context_resource *stres); +}; + + +/** + * Represent a state tracker manager. + * + * This interface is implemented by the state tracker manager. It corresponds + * to a "display" in the window system. + */ +struct st_manager +{ + struct pipe_screen *screen; + + /** + * Look up and return the info of an EGLImage. + * + * This is used to implement for example EGLImageTargetTexture2DOES. + * The GLeglImageOES agrument of that call is passed directly to this + * function call and the information needed to access this is returned + * in the given struct out. + * + * @smapi: manager owning the caller context + * @stctx: caller context + * @egl_image: EGLImage that caller recived + * @out: return struct filled out with access information. + * + * This function is optional. + */ + boolean (*get_egl_image)(struct st_manager *smapi, + void *egl_image, + struct st_egl_image *out); + + /** + * Query an manager param. + */ + int (*get_param)(struct st_manager *smapi, + enum st_manager_param param); +}; + +/** + * Represent a rendering API such as OpenGL or OpenVG. + * + * Implemented by the state tracker and used by the state tracker manager. + */ +struct st_api +{ + /** + * The name of the rendering API. This is informative. + */ + const char *name; + + /** + * The supported rendering API. + */ + enum st_api_type api; + + /** + * The supported profiles. Tested with ST_PROFILE_*_MASK. + */ + unsigned profile_mask; + + /** + * Destroy the API. + */ + void (*destroy)(struct st_api *stapi); + + /** + * Return an API entry point. + * + * For GL this is the same as _glapi_get_proc_address. + */ + st_proc_t (*get_proc_address)(struct st_api *stapi, const char *procname); + + /** + * Create a rendering context. + */ + struct st_context_iface *(*create_context)(struct st_api *stapi, + struct st_manager *smapi, + const struct st_context_attribs *attribs, + struct st_context_iface *stsharei); + + /** + * Bind the context to the calling thread with draw and read as drawables. + * + * The framebuffers might be NULL, or might have different visuals than the + * context does. + */ + boolean (*make_current)(struct st_api *stapi, + struct st_context_iface *stctxi, + struct st_framebuffer_iface *stdrawi, + struct st_framebuffer_iface *streadi); + + /** + * Get the currently bound context in the calling thread. + */ + struct st_context_iface *(*get_current)(struct st_api *stapi); +}; + +/** + * Return true if the visual has the specified buffers. + */ +static INLINE boolean +st_visual_have_buffers(const struct st_visual *visual, unsigned mask) +{ + return ((visual->buffer_mask & mask) == mask); +} + +#endif /* _ST_API_H_ */ diff --git a/src/gallium/include/state_tracker/sw_winsys.h b/src/gallium/include/state_tracker/sw_winsys.h new file mode 100644 index 0000000..0b11fe3 --- /dev/null +++ b/src/gallium/include/state_tracker/sw_winsys.h @@ -0,0 +1,145 @@ +/************************************************************************** + * + * Copyright 2007-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 TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Software rasterizer winsys. + */ + + +#ifndef SW_WINSYS_H +#define SW_WINSYS_H + + +#include "pipe/p_compiler.h" /* for boolean */ +#include "pipe/p_format.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct winsys_handle; +struct pipe_screen; +struct pipe_context; +struct pipe_resource; + + +/** + * Opaque pointer. + */ +struct sw_displaytarget; + + +/** + * This is the interface that sw expects any window system + * hosting it to implement. + * + * sw is for the most part a self sufficient driver. The only thing it + * does not know is how to display a surface. + */ +struct sw_winsys +{ + void + (*destroy)( struct sw_winsys *ws ); + + boolean + (*is_displaytarget_format_supported)( struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format ); + + /** + * Allocate storage for a render target. + * + * Often surfaces which are meant to be blitted to the front screen (i.e., + * display targets) must be allocated with special characteristics, memory + * pools, or obtained directly from the windowing system. + * + * This callback is invoked by the pipe_screen when creating a texture marked + * with the PIPE_BIND_DISPLAY_TARGET flag to get the underlying + * storage. + */ + struct sw_displaytarget * + (*displaytarget_create)( struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride ); + + /** + * Used to implement texture_from_handle. + */ + struct sw_displaytarget * + (*displaytarget_from_handle)( struct sw_winsys *ws, + const struct pipe_resource *templat, + struct winsys_handle *whandle, + unsigned *stride ); + + /** + * Used to implement texture_get_handle. + */ + boolean + (*displaytarget_get_handle)( struct sw_winsys *ws, + struct sw_displaytarget *dt, + struct winsys_handle *whandle ); + + /** + * \param flags bitmask of PIPE_TRANSFER_x flags + */ + void * + (*displaytarget_map)( struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags ); + + void + (*displaytarget_unmap)( struct sw_winsys *ws, + struct sw_displaytarget *dt ); + + /** + * @sa pipe_screen:flush_frontbuffer. + * + * This call will likely become asynchronous eventually. + */ + void + (*displaytarget_display)( struct sw_winsys *ws, + struct sw_displaytarget *dt, + void *context_private ); + + void + (*displaytarget_destroy)( struct sw_winsys *ws, + struct sw_displaytarget *dt ); +}; + + + +#ifdef __cplusplus +} +#endif + +#endif /* SW_WINSYS_H */ diff --git a/src/gallium/include/state_tracker/xlib_sw_winsys.h b/src/gallium/include/state_tracker/xlib_sw_winsys.h new file mode 100644 index 0000000..4e7ccc1 --- /dev/null +++ b/src/gallium/include/state_tracker/xlib_sw_winsys.h @@ -0,0 +1,29 @@ +#ifndef XLIB_SW_WINSYS_H +#define XLIB_SW_WINSYS_H + +#include "state_tracker/sw_winsys.h" +#include + + +struct pipe_screen; +struct pipe_resource; + +/* This is what the xlib software winsys expects to find in the + * "private" field of flush_frontbuffers(). + * + * Xlib-based state trackers somehow need to know this. + */ +struct xlib_drawable { + Visual *visual; + int depth; + Drawable drawable; +}; + + +/* This is the public interface to the ws/xlib module. Why isn't it + * being defined in that directory? + */ +struct sw_winsys *xlib_create_sw_winsys( Display *display ); + + +#endif diff --git a/src/gallium/state_trackers/Makefile b/src/gallium/state_trackers/Makefile new file mode 100644 index 0000000..0900efc --- /dev/null +++ b/src/gallium/state_trackers/Makefile @@ -0,0 +1,29 @@ +TOP = ../../.. +include $(TOP)/configs/current + + +SUBDIRS = $(GALLIUM_STATE_TRACKERS_DIRS) + + +default: subdirs + + +subdirs: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE)) || exit 1 ; \ + fi \ + done + + +clean: + rm -f `find . -name \*.[oa]` + rm -f `find . -name depend` + + +install: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) $@) || exit 1 ; \ + fi \ + done diff --git a/src/gallium/state_trackers/d3d1x/Makefile b/src/gallium/state_trackers/d3d1x/Makefile new file mode 100644 index 0000000..75076ee --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/Makefile @@ -0,0 +1,11 @@ +SUBDIRS=d3dapi gd3dapi docs d3d1xstutil d3d1xshader gd3d1x gd3d11 gd3d10 dxgi dxgid3d11 dxgid3d10 + +all: + @for dir in $(SUBDIRS) ; do $(MAKE) -C "$$dir" || exit $?; done + +clean: + rm -f `find . -name \*.[oa]` + rm -f `find . -name depend` + +install: + diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/Makefile b/src/gallium/state_trackers/d3d1x/d3d1xshader/Makefile new file mode 100644 index 0000000..f132518 --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/Makefile @@ -0,0 +1,16 @@ +LIBNAME=d3d1xshader +CPP_SOURCES=$(wildcard src/*.cpp) src/sm4_text.cpp +LIBRARY_INCLUDES=-Iinclude -I../d3dapi -I../w32api +PROGS=tools/fxdis +PROGS_DEPS=libd3d1xshader.a +LIBS=$(PROGS_DEPS) + +include ../Makefile.inc + +include/sm4.h: include/sm4_defs.h + +include/sm4_defs.h: $(wildcard defs/*.txt) + ./gen-header.sh $^ > $@ + +src/sm4_text.cpp: $(wildcard defs/*.txt) + ./gen-text.sh $^ > $@ diff --git a/src/gallium/state_trackers/d3d1x/d3d1xstutil/Makefile b/src/gallium/state_trackers/d3d1x/d3d1xstutil/Makefile new file mode 100644 index 0000000..f986f8e --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/d3d1xstutil/Makefile @@ -0,0 +1,5 @@ +LIBNAME=d3d1xstutil +CPP_SOURCES=$(wildcard src/*.cpp) +LIBRARY_INCLUDES=-Iinclude -I../gd3dapi -I../d3dapi -I../w32api -I../../../include -I../../../auxiliary + +include ../Makefile.inc diff --git a/src/gallium/state_trackers/d3d1x/d3dapi/Makefile b/src/gallium/state_trackers/d3d1x/d3dapi/Makefile new file mode 100644 index 0000000..8b16b1b --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/d3dapi/Makefile @@ -0,0 +1,4 @@ +all: idl + +include ../Makefile.inc + diff --git a/src/gallium/state_trackers/d3d1x/d3dapi/d3d10misc.h b/src/gallium/state_trackers/d3d1x/d3dapi/d3d10misc.h new file mode 100644 index 0000000..4f866ff --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/d3dapi/d3d10misc.h @@ -0,0 +1,47 @@ +/* + * Copyright 2008 Henri Verbeet for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __D3D10MISC_H__ +#define __D3D10MISC_H__ + +#include "d3d10.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum D3D10_DRIVER_TYPE { + D3D10_DRIVER_TYPE_HARDWARE = 0, + D3D10_DRIVER_TYPE_REFERENCE = 1, + D3D10_DRIVER_TYPE_NULL = 2, + D3D10_DRIVER_TYPE_SOFTWARE = 3, + D3D10_DRIVER_TYPE_WARP = 5, // added by Luca Barbieri in Sep 2010 +} D3D10_DRIVER_TYPE; + +HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, + HMODULE swrast, UINT flags, UINT sdk_version, ID3D10Device **device); + +HRESULT WINAPI D3D10CreateDeviceAndSwapChain(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, + HMODULE swrast, UINT flags, UINT sdk_version, DXGI_SWAP_CHAIN_DESC *swapchain_desc, + IDXGISwapChain **swapchain, ID3D10Device **device); + +#ifdef __cplusplus +} +#endif + +#endif /* __D3D10MISC_H__ */ diff --git a/src/gallium/state_trackers/d3d1x/docs/Makefile b/src/gallium/state_trackers/d3d1x/docs/Makefile new file mode 100644 index 0000000..7f38fa7 --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/docs/Makefile @@ -0,0 +1,5 @@ +all: module_dependencies.svg module_dependencies.pdf +.IGNORE: module_dependencies.svg module_dependencies.pdf + +include ../Makefile.inc + diff --git a/src/gallium/state_trackers/d3d1x/dxgi/Makefile b/src/gallium/state_trackers/d3d1x/dxgi/Makefile new file mode 100644 index 0000000..6cdc33b --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/dxgi/Makefile @@ -0,0 +1,17 @@ +LIBNAME=dxgi +LIBRARY_INCLUDES=-I../../../../../include -Iinclude -I../gd3dapi -I../d3dapi -I../w32api -I../d3d1xstutil/include -I../include -I../../../include -I../../../auxiliary -I../../../state_trackers/egl/common +LIBRARY_DEFINES=-DDXGI_DRIVER_SEARCH_DIR=\"$(EGL_DRIVER_INSTALL_DIR)\" +CPP_SOURCES=$(wildcard src/*.cpp) + +include ../Makefile.inc + +ifneq ($(findstring x11, $(EGL_PLATFORMS)),) +LIBRARY_DEFINES += -DGALLIUM_DXGI_USE_X11 +endif +ifneq ($(findstring drm, $(EGL_PLATFORMS)),) +LIBRARY_DEFINES += -DGALLIUM_DXGI_USE_DRM +endif +ifneq ($(findstring fbdev, $(EGL_PLATFORMS)),) +LIBRARY_DEFINES += -DGALLIUM_DXGI_USE_FBDEV +endif + diff --git a/src/gallium/state_trackers/d3d1x/dxgid3d10/Makefile b/src/gallium/state_trackers/d3d1x/dxgid3d10/Makefile new file mode 100644 index 0000000..85f41e8 --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/dxgid3d10/Makefile @@ -0,0 +1,4 @@ +LIBNAME=dxgid3d10 +CPP_SOURCES=$(wildcard *.cpp) +LIBRARY_INCLUDES=-I../gd3dapi -I../d3dapi -I../w32api -I../d3d1xstutil/include -I../include -I../../../include -I../../../auxiliary +include ../Makefile.inc diff --git a/src/gallium/state_trackers/d3d1x/dxgid3d11/Makefile b/src/gallium/state_trackers/d3d1x/dxgid3d11/Makefile new file mode 100644 index 0000000..591d1be --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/dxgid3d11/Makefile @@ -0,0 +1,4 @@ +LIBNAME=dxgid3d11 +CPP_SOURCES=$(wildcard *.cpp) +LIBRARY_INCLUDES=-I../gd3dapi -I../d3dapi -I../w32api -I../d3d1xstutil/include -I../include -I../../../include -I../../../auxiliary +include ../Makefile.inc diff --git a/src/gallium/state_trackers/d3d1x/gd3d10/Makefile b/src/gallium/state_trackers/d3d1x/gd3d10/Makefile new file mode 100644 index 0000000..300149d --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/gd3d10/Makefile @@ -0,0 +1,20 @@ +LIBNAME=gd3d10 +CPP_SOURCES=d3d10.generated.cpp +LIBRARY_INCLUDES=-I../gd3d1x -I../gd3dapi -I../d3dapi -I../w32api -I../d3d1xstutil/include -I../d3d1xshader/include -I../../../include -I../../../auxiliary -I../../../state_trackers/egl/common + +GEN_D3D10=perl d3d10.pl + +include ../Makefile.inc + +d3d10.generated.o: d3d10_objects.generated.h d3d10_screen.generated.h d3d10_context.generated.h d3d10_misc.generated.h + +d3d10.generated.cpp: ../gd3d11/d3d11.cpp d3d10.pl + $(GEN_D3D10) $< > $@ +d3d10_objects.generated.h: ../gd3d11/d3d11_objects.h d3d10.pl + $(GEN_D3D10) $< > $@ +d3d10_screen.generated.h: ../gd3d11/d3d11_screen.h d3d10.pl + $(GEN_D3D10) $< > $@ +d3d10_context.generated.h: ../gd3d11/d3d11_context.h d3d10.pl + $(GEN_D3D10) $< > $@ +d3d10_misc.generated.h: ../gd3d11/d3d11_misc.h d3d10.pl + $(GEN_D3D10) $< > $@ diff --git a/src/gallium/state_trackers/d3d1x/gd3d11/Makefile b/src/gallium/state_trackers/d3d1x/gd3d11/Makefile new file mode 100644 index 0000000..650c11d --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/gd3d11/Makefile @@ -0,0 +1,6 @@ +LIBNAME=gd3d11 +CPP_SOURCES=d3d11.cpp +LIBRARY_INCLUDES=-I../gd3d1x -I../gd3dapi -I../d3dapi -I../w32api -I../d3d1xstutil/include -I../d3d1xshader/include -I../../../include -I../../../auxiliary -I../../../state_trackers/egl/common + +include ../Makefile.inc + diff --git a/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_context.h b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_context.h new file mode 100644 index 0000000..e1ba6c1 --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_context.h @@ -0,0 +1,2082 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* used to unbind things, we need 128 due to resources */ +static const void* zero_data[128]; + +#define UPDATE_VIEWS_SHIFT (D3D11_STAGES * 0) +#define UPDATE_SAMPLERS_SHIFT (D3D11_STAGES * 1) +#define UPDATE_VERTEX_BUFFERS (1 << (D3D11_STAGES * 2)) + +#if API >= 11 +template +struct GalliumD3D11DeviceContext : + public GalliumD3D11DeviceChild +{ +#else +template +struct GalliumD3D10Device : public GalliumD3D10ScreenImpl +{ + typedef simple_ptr_traits PtrTraits; + typedef GalliumD3D10Device GalliumD3D10DeviceContext; +#endif + + refcnt_ptr, PtrTraits> shaders[D3D11_STAGES]; + refcnt_ptr input_layout; + refcnt_ptr index_buffer; + refcnt_ptr rasterizer_state; + refcnt_ptr depth_stencil_state; + refcnt_ptr blend_state; + refcnt_ptr depth_stencil_view; + refcnt_ptr render_predicate; + + refcnt_ptr constant_buffers[D3D11_STAGES][D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT]; + refcnt_ptr shader_resource_views[D3D11_STAGES][D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT]; + refcnt_ptr samplers[D3D11_STAGES][D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT]; + refcnt_ptr input_buffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]; + refcnt_ptr render_target_views[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT]; + refcnt_ptr so_targets[D3D11_SO_BUFFER_SLOT_COUNT]; + +#if API >= 11 + refcnt_ptr cs_unordered_access_views[D3D11_PS_CS_UAV_REGISTER_COUNT]; + refcnt_ptr om_unordered_access_views[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT]; +#endif + + D3D11_VIEWPORT viewports[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; + D3D11_RECT scissor_rects[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; + unsigned so_offsets[D3D11_SO_BUFFER_SLOT_COUNT]; + D3D11_PRIMITIVE_TOPOLOGY primitive_topology; + DXGI_FORMAT index_format; + unsigned index_offset; + BOOL render_predicate_value; + float blend_color[4]; + unsigned sample_mask; + unsigned stencil_ref; + bool depth_clamp; + + void* default_input_layout; + void* default_rasterizer; + void* default_depth_stencil; + void* default_blend; + void* default_sampler; + void* ld_sampler; + void * default_shaders[D3D11_STAGES]; + + // derived state + int primitive_mode; + struct pipe_vertex_buffer vertex_buffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]; + struct pipe_resource* so_buffers[D3D11_SO_BUFFER_SLOT_COUNT]; + struct pipe_sampler_view* sampler_views[D3D11_STAGES][D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT]; + struct + { + void* ld; // accessed with a -1 index from v + void* v[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT]; + } sampler_csos[D3D11_STAGES]; + struct pipe_resource * buffers[D3D11_SO_BUFFER_SLOT_COUNT]; + unsigned num_shader_resource_views[D3D11_STAGES]; + unsigned num_samplers[D3D11_STAGES]; + unsigned num_vertex_buffers; + unsigned num_render_target_views; + unsigned num_viewports; + unsigned num_scissor_rects; + unsigned num_so_targets; + + struct pipe_context* pipe; + unsigned update_flags; + + bool owns_pipe; + unsigned context_flags; + + GalliumD3D11Caps caps; + + cso_context* cso_ctx; + gen_mipmap_state* gen_mipmap; + +#if API >= 11 +#define SYNCHRONIZED do {} while(0) + + GalliumD3D11DeviceContext(GalliumD3D11Screen* device, pipe_context* pipe, bool owns_pipe, unsigned context_flags = 0) + : GalliumD3D11DeviceChild(device), pipe(pipe), owns_pipe(owns_pipe), context_flags(context_flags) + { + caps = device->screen_caps; + init_context(); + } + + ~GalliumD3D11DeviceContext() + { + destroy_context(); + } +#else +#define SYNCHRONIZED lock_t > lock_(this->mutex) + + GalliumD3D10Device(pipe_screen* screen, pipe_context* pipe, bool owns_pipe, unsigned creation_flags, IDXGIAdapter* adapter) + : GalliumD3D10ScreenImpl(screen, pipe, owns_pipe, creation_flags, adapter), pipe(pipe), owns_pipe(owns_pipe), context_flags(0) + { + caps = this->screen_caps; + init_context(); + } + + ~GalliumD3D10Device() + { + destroy_context(); + } +#endif + + void init_context() + { + if(!pipe->begin_query) + caps.queries = false; + if(!pipe->render_condition) + caps.render_condition = false; + if(!pipe->bind_gs_state) + { + caps.gs = false; + caps.stages = 2; + } + if(!pipe->set_stream_output_buffers) + caps.so = false; + if(!pipe->set_geometry_sampler_views) + caps.stages_with_sampling &=~ (1 << PIPE_SHADER_GEOMETRY); + if(!pipe->set_fragment_sampler_views) + caps.stages_with_sampling &=~ (1 << PIPE_SHADER_FRAGMENT); + if(!pipe->set_vertex_sampler_views) + caps.stages_with_sampling &=~ (1 << PIPE_SHADER_VERTEX); + + update_flags = 0; + + // pipeline state + memset(viewports, 0, sizeof(viewports)); + memset(scissor_rects, 0, sizeof(scissor_rects)); + memset(so_offsets, 0, sizeof(so_offsets)); + primitive_topology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED; + index_format = DXGI_FORMAT_UNKNOWN; + index_offset = 0; + render_predicate_value = 0; + memset(blend_color, 0, sizeof(blend_color)); + sample_mask = ~0; + stencil_ref = 0; + depth_clamp = 0; + + // derived state + primitive_mode = 0; + memset(vertex_buffers, 0, sizeof(vertex_buffers)); + memset(so_buffers, 0, sizeof(so_buffers)); + memset(sampler_views, 0, sizeof(sampler_views)); + memset(sampler_csos, 0, sizeof(sampler_csos)); + memset(num_shader_resource_views, 0, sizeof(num_shader_resource_views)); + memset(num_samplers, 0, sizeof(num_samplers)); + num_vertex_buffers = 0; + num_render_target_views = 0; + num_viewports = 0; + num_scissor_rects = 0; + num_so_targets = 0; + + default_input_layout = pipe->create_vertex_elements_state(pipe, 0, 0); + + struct pipe_rasterizer_state rasterizerd; + memset(&rasterizerd, 0, sizeof(rasterizerd)); + rasterizerd.gl_rasterization_rules = 1; + rasterizerd.cull_face = PIPE_FACE_BACK; + default_rasterizer = pipe->create_rasterizer_state(pipe, &rasterizerd); + + struct pipe_depth_stencil_alpha_state depth_stencild; + memset(&depth_stencild, 0, sizeof(depth_stencild)); + depth_stencild.depth.enabled = TRUE; + depth_stencild.depth.writemask = 1; + depth_stencild.depth.func = PIPE_FUNC_LESS; + default_depth_stencil = pipe->create_depth_stencil_alpha_state(pipe, &depth_stencild); + + struct pipe_blend_state blendd; + memset(&blendd, 0, sizeof(blendd)); + blendd.rt[0].colormask = 0xf; + default_blend = pipe->create_blend_state(pipe, &blendd); + + struct pipe_sampler_state samplerd; + memset(&samplerd, 0, sizeof(samplerd)); + samplerd.normalized_coords = 1; + samplerd.min_img_filter = PIPE_TEX_FILTER_LINEAR; + samplerd.mag_img_filter = PIPE_TEX_FILTER_LINEAR; + samplerd.min_mip_filter = PIPE_TEX_MIPFILTER_LINEAR; + samplerd.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + samplerd.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + samplerd.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + samplerd.border_color[0] = 1.0f; + samplerd.border_color[1] = 1.0f; + samplerd.border_color[2] = 1.0f; + samplerd.border_color[3] = 1.0f; + samplerd.min_lod = -FLT_MAX; + samplerd.max_lod = FLT_MAX; + samplerd.max_anisotropy = 1; + default_sampler = pipe->create_sampler_state(pipe, &samplerd); + + memset(&samplerd, 0, sizeof(samplerd)); + samplerd.normalized_coords = 0; + samplerd.min_img_filter = PIPE_TEX_FILTER_NEAREST; + samplerd.mag_img_filter = PIPE_TEX_FILTER_NEAREST; + samplerd.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + samplerd.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_BORDER; + samplerd.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_BORDER; + samplerd.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_BORDER; + samplerd.min_lod = -FLT_MAX; + samplerd.max_lod = FLT_MAX; + samplerd.max_anisotropy = 1; + ld_sampler = pipe->create_sampler_state(pipe, &samplerd); + + for(unsigned s = 0; s < D3D11_STAGES; ++s) + { + sampler_csos[s].ld = ld_sampler; + for(unsigned i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i) + sampler_csos[s].v[i] = default_sampler; + } + + // TODO: should this really be empty shaders, or should they be all-passthrough? + memset(default_shaders, 0, sizeof(default_shaders)); + struct ureg_program *ureg; + ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT); + ureg_END(ureg); + default_shaders[PIPE_SHADER_FRAGMENT] = ureg_create_shader_and_destroy(ureg, pipe); + + ureg = ureg_create(TGSI_PROCESSOR_VERTEX); + ureg_END(ureg); + default_shaders[PIPE_SHADER_VERTEX] = ureg_create_shader_and_destroy(ureg, pipe); + + cso_ctx = cso_create_context(pipe); + gen_mipmap = util_create_gen_mipmap(pipe, cso_ctx); + + RestoreGalliumState(); + } + + void destroy_context() + { + util_destroy_gen_mipmap(gen_mipmap); + cso_destroy_context(cso_ctx); + + pipe->bind_vertex_elements_state(pipe, 0); + pipe->delete_vertex_elements_state(pipe, default_input_layout); + + pipe->bind_rasterizer_state(pipe, 0); + pipe->delete_rasterizer_state(pipe, default_rasterizer); + + pipe->bind_depth_stencil_alpha_state(pipe, 0); + pipe->delete_depth_stencil_alpha_state(pipe, default_depth_stencil); + + pipe->bind_blend_state(pipe, 0); + pipe->delete_blend_state(pipe, default_blend); + + pipe->bind_fragment_sampler_states(pipe, 0, 0); + pipe->bind_vertex_sampler_states(pipe, 0, 0); + if(pipe->bind_geometry_sampler_states) + pipe->bind_geometry_sampler_states(pipe, 0, 0); + pipe->delete_sampler_state(pipe, default_sampler); + pipe->delete_sampler_state(pipe, ld_sampler); + + pipe->bind_fs_state(pipe, 0); + pipe->delete_fs_state(pipe, default_shaders[PIPE_SHADER_FRAGMENT]); + + pipe->bind_vs_state(pipe, 0); + pipe->delete_vs_state(pipe, default_shaders[PIPE_SHADER_VERTEX]); + + if(owns_pipe) + pipe->destroy(pipe); + } + + virtual unsigned STDMETHODCALLTYPE GetContextFlags(void) + { + return context_flags; + } +#if API >= 11 +#define SET_SHADER_EXTRA_ARGS , \ + ID3D11ClassInstance *const *ppClassInstances, \ + unsigned count +#define GET_SHADER_EXTRA_ARGS , \ + ID3D11ClassInstance **ppClassInstances, \ + unsigned *out_count +#else +#define SET_SHADER_EXTRA_ARGS +#define GET_SHADER_EXTRA_ARGS +#endif + +/* On Windows D3D11, SetConstantBuffers and SetShaderResources crash if passed a null pointer. + * Instead, you have to pass a pointer to nulls to unbind things. + * We do the same. + * TODO: is D3D10 the same? + */ + template + void xs_set_shader(GalliumD3D11Shader<>* shader) + { + if(shader != shaders[s].p) + { + shaders[s] = shader; + void* shader_cso = shader ? shader->object : default_shaders[s]; + switch(s) + { + case PIPE_SHADER_VERTEX: + pipe->bind_vs_state(pipe, shader_cso); + break; + case PIPE_SHADER_FRAGMENT: + pipe->bind_fs_state(pipe, shader_cso); + break; + case PIPE_SHADER_GEOMETRY: + pipe->bind_gs_state(pipe, shader_cso); + break; + } + update_flags |= (1 << (UPDATE_SAMPLERS_SHIFT + s)) | (1 << (UPDATE_VIEWS_SHIFT + s)); + } + } + + template + void xs_set_constant_buffers(unsigned start, unsigned count, GalliumD3D11Buffer *const *constbufs) + { + for(unsigned i = 0; i < count; ++i) + { + if(constbufs[i] != constant_buffers[s][i].p) + { + constant_buffers[s][i] = constbufs[i]; + if(s < caps.stages && start + i < caps.constant_buffers[s]) + pipe->set_constant_buffer(pipe, s, start + i, constbufs[i] ? constbufs[i]->resource : NULL); + } + } + } + + template + void xs_set_shader_resources(unsigned start, unsigned count, GalliumD3D11ShaderResourceView *const *srvs) + { + int last_different = -1; + for(unsigned i = 0; i < count; ++i) + { + if(shader_resource_views[s][start + i].p != srvs[i]) + { + shader_resource_views[s][start + i] = srvs[i]; + sampler_views[s][start + i] = srvs[i] ? srvs[i]->object : 0; + last_different = i; + } + } + if(last_different >= 0) + { + num_shader_resource_views[s] = std::max(num_shader_resource_views[s], start + last_different + 1); + update_flags |= 1 << (UPDATE_VIEWS_SHIFT + s); + } + } + + template + void xs_set_samplers(unsigned start, unsigned count, GalliumD3D11SamplerState *const *samps) + { + int last_different = -1; + for(unsigned i = 0; i < count; ++i) + { + if(samplers[s][start + i].p != samps[i]) + { + samplers[s][start + i] = samps[i]; + sampler_csos[s].v[start + i] = samps[i] ? samps[i]->object : default_sampler; + } + if(last_different >= 0) + { + num_samplers[s] = std::max(num_samplers[s], start + last_different + 1); + update_flags |= (UPDATE_SAMPLERS_SHIFT + s); + } + } + } + +#define IMPLEMENT_SHADER_STAGE(XS, Stage) \ + virtual void STDMETHODCALLTYPE XS##SetShader( \ + ID3D11##Stage##Shader *pShader \ + SET_SHADER_EXTRA_ARGS) \ + { \ + SYNCHRONIZED; \ + xs_set_shader((GalliumD3D11Shader<>*)pShader); \ + } \ + virtual void STDMETHODCALLTYPE XS##GetShader(\ + ID3D11##Stage##Shader **ppShader \ + GET_SHADER_EXTRA_ARGS) \ + { \ + SYNCHRONIZED; \ + *ppShader = (ID3D11##Stage##Shader*)shaders[D3D11_STAGE_##XS].ref(); \ + } \ + virtual void STDMETHODCALLTYPE XS##SetConstantBuffers(\ + unsigned start, \ + unsigned count, \ + ID3D11Buffer *const* constant_buffers) \ + { \ + SYNCHRONIZED; \ + xs_set_constant_buffers(start, count, (GalliumD3D11Buffer *const *)constant_buffers); \ + } \ + virtual void STDMETHODCALLTYPE XS##GetConstantBuffers(\ + unsigned start, \ + unsigned count, \ + ID3D11Buffer **out_constant_buffers) \ + { \ + SYNCHRONIZED; \ + for(unsigned i = 0; i < count; ++i) \ + out_constant_buffers[i] = constant_buffers[D3D11_STAGE_##XS][start + i].ref(); \ + } \ + virtual void STDMETHODCALLTYPE XS##SetShaderResources(\ + unsigned start, \ + unsigned count, \ + ID3D11ShaderResourceView *const *new_shader_resource_views) \ + { \ + SYNCHRONIZED; \ + xs_set_shader_resources(start, count, (GalliumD3D11ShaderResourceView *const *)new_shader_resource_views); \ + } \ + virtual void STDMETHODCALLTYPE XS##GetShaderResources(\ + unsigned start, \ + unsigned count, \ + ID3D11ShaderResourceView **out_shader_resource_views) \ + { \ + SYNCHRONIZED; \ + for(unsigned i = 0; i < count; ++i) \ + out_shader_resource_views[i] = shader_resource_views[D3D11_STAGE_##XS][start + i].ref(); \ + } \ + virtual void STDMETHODCALLTYPE XS##SetSamplers(\ + unsigned start, \ + unsigned count, \ + ID3D11SamplerState *const *new_samplers) \ + { \ + SYNCHRONIZED; \ + xs_set_samplers(start, count, (GalliumD3D11SamplerState *const *)new_samplers); \ + } \ + virtual void STDMETHODCALLTYPE XS##GetSamplers( \ + unsigned start, \ + unsigned count, \ + ID3D11SamplerState **out_samplers) \ + { \ + SYNCHRONIZED; \ + for(unsigned i = 0; i < count; ++i) \ + out_samplers[i] = samplers[D3D11_STAGE_##XS][start + i].ref(); \ + } + +#define DO_VS(x) x +#define DO_GS(x) do {if(caps.gs) {x;}} while(0) +#define DO_PS(x) x +#define DO_HS(x) +#define DO_DS(x) +#define DO_CS(x) + IMPLEMENT_SHADER_STAGE(VS, Vertex) + IMPLEMENT_SHADER_STAGE(GS, Geometry) + IMPLEMENT_SHADER_STAGE(PS, Pixel) + +#if API >= 11 + IMPLEMENT_SHADER_STAGE(HS, Hull) + IMPLEMENT_SHADER_STAGE(DS, Domain) + IMPLEMENT_SHADER_STAGE(CS, Compute) + + virtual void STDMETHODCALLTYPE CSSetUnorderedAccessViews( + unsigned start, + unsigned count, + ID3D11UnorderedAccessView *const *new_unordered_access_views, + const unsigned *new_uav_initial_counts) + { + SYNCHRONIZED; + for(unsigned i = 0; i < count; ++i) + cs_unordered_access_views[start + i] = new_unordered_access_views[i]; + } + + virtual void STDMETHODCALLTYPE CSGetUnorderedAccessViews( + unsigned start, + unsigned count, + ID3D11UnorderedAccessView **out_unordered_access_views) + { + SYNCHRONIZED; + for(unsigned i = 0; i < count; ++i) + out_unordered_access_views[i] = cs_unordered_access_views[start + i].ref(); + } +#endif + + template + void update_stage() + { + if(update_flags & (1 << (UPDATE_VIEWS_SHIFT + s))) + { + while(num_shader_resource_views[s] && !sampler_views[s][num_shader_resource_views[s] - 1]) \ + --num_shader_resource_views[s]; + if((1 << s) & caps.stages_with_sampling) + { + struct pipe_sampler_view* views_to_bind[PIPE_MAX_SAMPLERS]; + unsigned num_views_to_bind = shaders[s] ? shaders[s]->slot_to_resource.size() : 0; + for(unsigned i = 0; i < num_views_to_bind; ++i) + { + views_to_bind[i] = sampler_views[s][shaders[s]->slot_to_resource[i]]; + } + switch(s) + { + case PIPE_SHADER_VERTEX: + pipe->set_vertex_sampler_views(pipe, num_views_to_bind, views_to_bind); + break; + case PIPE_SHADER_FRAGMENT: + pipe->set_fragment_sampler_views(pipe, num_views_to_bind, views_to_bind); + break; + case PIPE_SHADER_GEOMETRY: + pipe->set_geometry_sampler_views(pipe, num_views_to_bind, views_to_bind); + break; + } + } + } + + if(update_flags & (1 << (UPDATE_SAMPLERS_SHIFT + s))) + { + while(num_samplers[s] && !sampler_csos[s].v[num_samplers[s] - 1]) + --num_samplers[s]; + if((1 << s) & caps.stages_with_sampling) + { + void* samplers_to_bind[PIPE_MAX_SAMPLERS]; + unsigned num_samplers_to_bind = shaders[s] ? shaders[s]->slot_to_sampler.size() : 0; + for(unsigned i = 0; i < num_samplers_to_bind; ++i) + { + // index can be -1 to access sampler_csos[s].ld + samplers_to_bind[i] = *(sampler_csos[s].v + shaders[s]->slot_to_sampler[i]); + } + switch(s) + { + case PIPE_SHADER_VERTEX: + pipe->bind_vertex_sampler_states(pipe, num_samplers_to_bind, samplers_to_bind); + break; + case PIPE_SHADER_FRAGMENT: + pipe->bind_fragment_sampler_states(pipe, num_samplers_to_bind, samplers_to_bind); + break; + case PIPE_SHADER_GEOMETRY: + pipe->bind_geometry_sampler_states(pipe, num_samplers_to_bind, samplers_to_bind); + break; + } + } + } + } + + void update_state() + { + update_stage(); + update_stage(); + update_stage(); +#if API >= 11 + update_stage(); + update_stage(); + update_stage(); +#endif + + if(update_flags & UPDATE_VERTEX_BUFFERS) + { + while(num_vertex_buffers && !vertex_buffers[num_vertex_buffers - 1].buffer) + --num_vertex_buffers; + pipe->set_vertex_buffers(pipe, num_vertex_buffers, vertex_buffers); + } + + update_flags = 0; + } + + virtual void STDMETHODCALLTYPE IASetInputLayout( + ID3D11InputLayout *new_input_layout) + { + SYNCHRONIZED; + if(new_input_layout != input_layout.p) + { + input_layout = new_input_layout; + pipe->bind_vertex_elements_state(pipe, new_input_layout ? ((GalliumD3D11InputLayout*)new_input_layout)->object : default_input_layout); + } + } + + virtual void STDMETHODCALLTYPE IAGetInputLayout( + ID3D11InputLayout **out_input_layout) + { + SYNCHRONIZED; + *out_input_layout = input_layout.ref(); + } + + virtual void STDMETHODCALLTYPE IASetVertexBuffers( + unsigned start, + unsigned count, + ID3D11Buffer *const *new_vertex_buffers, + const unsigned *new_strides, + const unsigned *new_offsets) + { + SYNCHRONIZED; + int last_different = -1; + for(unsigned i = 0; i < count; ++i) + { + ID3D11Buffer* buffer = new_vertex_buffers[i]; + if(buffer != input_buffers[start + i].p + || vertex_buffers[start + i].buffer_offset != new_offsets[i] + || vertex_buffers[start + i].stride != new_offsets[i] + ) + { + input_buffers[start + i] = buffer; + vertex_buffers[start + i].buffer = buffer ? ((GalliumD3D11Buffer*)buffer)->resource : 0; + vertex_buffers[start + i].buffer_offset = new_offsets[i]; + vertex_buffers[start + i].stride = new_strides[i]; + vertex_buffers[start + i].max_index = ~0; + last_different = i; + } + } + if(last_different >= 0) + { + num_vertex_buffers = std::max(num_vertex_buffers, start + count); + update_flags |= UPDATE_VERTEX_BUFFERS; + } + } + + virtual void STDMETHODCALLTYPE IAGetVertexBuffers( + unsigned start, + unsigned count, + ID3D11Buffer **out_vertex_buffers, + unsigned *out_strides, + unsigned *out_offsets) + { + SYNCHRONIZED; + if(out_vertex_buffers) + { + for(unsigned i = 0; i < count; ++i) + out_vertex_buffers[i] = input_buffers[start + i].ref(); + } + + if(out_offsets) + { + for(unsigned i = 0; i < count; ++i) + out_offsets[i] = vertex_buffers[start + i].buffer_offset; + } + + if(out_strides) + { + for(unsigned i = 0; i < count; ++i) + out_strides[i] = vertex_buffers[start + i].stride; + } + } + + void set_index_buffer() + { + pipe_index_buffer ib; + if(!index_buffer) + { + memset(&ib, 0, sizeof(ib)); + } + else + { + if(index_format == DXGI_FORMAT_R32_UINT) + ib.index_size = 4; + else if(index_format == DXGI_FORMAT_R16_UINT) + ib.index_size = 2; + else + ib.index_size = 1; + ib.offset = index_offset; + ib.buffer = index_buffer ? ((GalliumD3D11Buffer*)index_buffer.p)->resource : 0; + } + pipe->set_index_buffer(pipe, &ib); + } + + virtual void STDMETHODCALLTYPE IASetIndexBuffer( + ID3D11Buffer *new_index_buffer, + DXGI_FORMAT new_index_format, + unsigned new_index_offset) + { + SYNCHRONIZED; + if(index_buffer.p != new_index_buffer || index_format != new_index_format || index_offset != new_index_offset) + { + index_buffer = new_index_buffer; + index_format = new_index_format; + index_offset = new_index_offset; + + set_index_buffer(); + } + } + + virtual void STDMETHODCALLTYPE IAGetIndexBuffer( + ID3D11Buffer **out_index_buffer, + DXGI_FORMAT *out_index_format, + unsigned *out_index_offset) + { + SYNCHRONIZED; + if(out_index_buffer) + *out_index_buffer = index_buffer.ref(); + if(out_index_format) + *out_index_format = index_format; + if(out_index_offset) + *out_index_offset = index_offset; + } + + virtual void STDMETHODCALLTYPE IASetPrimitiveTopology( + D3D11_PRIMITIVE_TOPOLOGY new_primitive_topology) + { + SYNCHRONIZED; + if(primitive_topology != new_primitive_topology) + { + if(new_primitive_topology < D3D_PRIMITIVE_TOPOLOGY_COUNT) + primitive_mode = d3d_to_pipe_prim[new_primitive_topology]; + else + primitive_mode = 0; + primitive_topology = new_primitive_topology; + } + } + + virtual void STDMETHODCALLTYPE IAGetPrimitiveTopology( + D3D11_PRIMITIVE_TOPOLOGY *out_primitive_topology) + { + SYNCHRONIZED; + *out_primitive_topology = primitive_topology; + } + + virtual void STDMETHODCALLTYPE DrawIndexed( + unsigned index_count, + unsigned start_index_location, + int base_vertex_location) + { + SYNCHRONIZED; + if(update_flags) + update_state(); + + pipe_draw_info info; + info.mode = primitive_mode; + info.indexed = TRUE; + info.count = index_count; + info.start = start_index_location; + info.index_bias = base_vertex_location; + info.min_index = 0; + info.max_index = ~0; + info.start_instance = 0; + info.instance_count = 1; + + pipe->draw_vbo(pipe, &info); + } + + virtual void STDMETHODCALLTYPE Draw( + unsigned vertex_count, + unsigned start_vertex_location) + { + SYNCHRONIZED; + if(update_flags) + update_state(); + + pipe_draw_info info; + info.mode = primitive_mode; + info.indexed = FALSE; + info.count = vertex_count; + info.start = start_vertex_location; + info.index_bias = 0; + info.min_index = 0; + info.max_index = ~0; + info.start_instance = 0; + info.instance_count = 1; + + pipe->draw_vbo(pipe, &info); + } + + virtual void STDMETHODCALLTYPE DrawIndexedInstanced( + unsigned index_countPerInstance, + unsigned instance_count, + unsigned start_index_location, + int base_vertex_location, + unsigned start_instance_location) + { + SYNCHRONIZED; + if(update_flags) + update_state(); + + pipe_draw_info info; + info.mode = primitive_mode; + info.indexed = TRUE; + info.count = index_countPerInstance; + info.start = start_index_location; + info.index_bias = base_vertex_location; + info.min_index = 0; + info.max_index = ~0; + info.start_instance = start_instance_location; + info.instance_count = instance_count; + + pipe->draw_vbo(pipe, &info); + } + + virtual void STDMETHODCALLTYPE DrawInstanced( + unsigned vertex_countPerInstance, + unsigned instance_count, + unsigned start_vertex_location, + unsigned start_instance_location) + { + SYNCHRONIZED; + if(update_flags) + update_state(); + + pipe_draw_info info; + info.mode = primitive_mode; + info.indexed = FALSE; + info.count = vertex_countPerInstance; + info.start = start_vertex_location; + info.index_bias = 0; + info.min_index = 0; + info.max_index = ~0; + info.start_instance = start_instance_location; + info.instance_count = instance_count; + + pipe->draw_vbo(pipe, &info); + } + + virtual void STDMETHODCALLTYPE DrawAuto(void) + { + if(!caps.so) + return; + + SYNCHRONIZED; + if(update_flags) + update_state(); + + pipe->draw_stream_output(pipe, primitive_mode); + } + + virtual void STDMETHODCALLTYPE DrawIndexedInstancedIndirect( + ID3D11Buffer *buffer, + unsigned aligned_byte_offset) + { + SYNCHRONIZED; + if(update_flags) + update_state(); + + struct { + unsigned count; + unsigned instance_count; + unsigned start; + unsigned index_bias; + } data; + + pipe_buffer_read(pipe, ((GalliumD3D11Buffer*)buffer)->resource, aligned_byte_offset, sizeof(data), &data); + + pipe_draw_info info; + info.mode = primitive_mode; + info.indexed = TRUE; + info.start = data.start; + info.count = data.count; + info.index_bias = data.index_bias; + info.min_index = 0; + info.max_index = ~0; + info.start_instance = 0; + info.instance_count = data.instance_count; + + pipe->draw_vbo(pipe, &info); + } + + virtual void STDMETHODCALLTYPE DrawInstancedIndirect( + ID3D11Buffer *buffer, + unsigned aligned_byte_offset) + { + SYNCHRONIZED; + if(update_flags) + update_state(); + + struct { + unsigned count; + unsigned instance_count; + unsigned start; + } data; + + pipe_buffer_read(pipe, ((GalliumD3D11Buffer*)buffer)->resource, aligned_byte_offset, sizeof(data), &data); + + pipe_draw_info info; + info.mode = primitive_mode; + info.indexed = FALSE; + info.start = data.start; + info.count = data.count; + info.index_bias = 0; + info.min_index = 0; + info.max_index = ~0; + info.start_instance = 0; + info.instance_count = data.instance_count; + + pipe->draw_vbo(pipe, &info); + } + +#if API >= 11 + virtual void STDMETHODCALLTYPE Dispatch( + unsigned thread_group_count_x, + unsigned thread_group_count_y, + unsigned thread_group_count_z) + { +// uncomment this when this is implemented +// SYNCHRONIZED; +// if(update_flags) +// update_state(); + } + + virtual void STDMETHODCALLTYPE DispatchIndirect( + ID3D11Buffer *buffer, + unsigned aligned_byte_offset) + { +// uncomment this when this is implemented +// SYNCHRONIZED; +// if(update_flags) +// update_state(); + } +#endif + + void set_clip() + { + pipe_clip_state clip; + clip.nr = 0; + clip.depth_clamp = depth_clamp; + pipe->set_clip_state(pipe, &clip); + } + + virtual void STDMETHODCALLTYPE RSSetState( + ID3D11RasterizerState *new_rasterizer_state) + { + SYNCHRONIZED; + if(new_rasterizer_state != rasterizer_state.p) + { + rasterizer_state = new_rasterizer_state; + pipe->bind_rasterizer_state(pipe, new_rasterizer_state ? ((GalliumD3D11RasterizerState*)new_rasterizer_state)->object : default_rasterizer); + bool new_depth_clamp = new_rasterizer_state ? ((GalliumD3D11RasterizerState*)new_rasterizer_state)->depth_clamp : false; + if(depth_clamp != new_depth_clamp) + { + depth_clamp = new_depth_clamp; + set_clip(); + } + } + } + + virtual void STDMETHODCALLTYPE RSGetState( + ID3D11RasterizerState **out_rasterizer_state) + { + SYNCHRONIZED; + *out_rasterizer_state = rasterizer_state.ref(); + } + + void set_viewport() + { + // TODO: is depth correct? it seems D3D10/11 uses a [-1,1]x[-1,1]x[0,1] cube + pipe_viewport_state viewport; + float half_width = viewports[0].Width * 0.5f; + float half_height = viewports[0].Height * 0.5f; + + viewport.scale[0] = half_width; + viewport.scale[1] = -half_height; + viewport.scale[2] = (viewports[0].MaxDepth - viewports[0].MinDepth); + viewport.scale[3] = 1.0f; + viewport.translate[0] = half_width + viewports[0].TopLeftX; + viewport.translate[1] = half_height + viewports[0].TopLeftY; + viewport.translate[2] = viewports[0].MinDepth; + viewport.translate[3] = 1.0f; + pipe->set_viewport_state(pipe, &viewport); + } + + virtual void STDMETHODCALLTYPE RSSetViewports( + unsigned count, + const D3D11_VIEWPORT *new_viewports) + { + SYNCHRONIZED; + if(count) + { + if(memcmp(&viewports[0], &new_viewports[0], sizeof(viewports[0]))) + { + viewports[0] = new_viewports[0]; + set_viewport(); + } + for(unsigned i = 1; i < count; ++i) + viewports[i] = new_viewports[i]; + } + else if(num_viewports) + { + // TODO: what should we do here? + memset(&viewports[0], 0, sizeof(viewports[0])); + set_viewport(); + } + num_viewports = count; + } + + virtual void STDMETHODCALLTYPE RSGetViewports( + unsigned *out_count, + D3D11_VIEWPORT *out_viewports) + { + SYNCHRONIZED; + if(out_viewports) + { + unsigned i; + for(i = 0; i < std::min(*out_count, num_viewports); ++i) + out_viewports[i] = viewports[i]; + + memset(out_viewports + i, 0, (*out_count - i) * sizeof(D3D11_VIEWPORT)); + } + + *out_count = num_viewports; + } + + void set_scissor() + { + pipe_scissor_state scissor; + scissor.minx = scissor_rects[0].left; + scissor.miny = scissor_rects[0].top; + scissor.maxx = scissor_rects[0].right; + scissor.maxy = scissor_rects[0].bottom; + pipe->set_scissor_state(pipe, &scissor); + } + + virtual void STDMETHODCALLTYPE RSSetScissorRects( + unsigned count, + const D3D11_RECT *new_rects) + { + SYNCHRONIZED; + if(count) + { + if(memcmp(&scissor_rects[0], &new_rects[0], sizeof(scissor_rects[0]))) + { + scissor_rects[0] = new_rects[0]; + set_scissor(); + } + for(unsigned i = 1; i < count; ++i) + scissor_rects[i] = new_rects[i]; + } + else if(num_scissor_rects) + { + // TODO: what should we do here? + memset(&scissor_rects[0], 0, sizeof(scissor_rects[0])); + set_scissor(); + } + + num_scissor_rects = count; + } + + virtual void STDMETHODCALLTYPE RSGetScissorRects( + unsigned *out_count, + D3D11_RECT *out_rects) + { + SYNCHRONIZED; + if(out_rects) + { + unsigned i; + for(i = 0; i < std::min(*out_count, num_scissor_rects); ++i) + out_rects[i] = scissor_rects[i]; + + memset(out_rects + i, 0, (*out_count - i) * sizeof(D3D11_RECT)); + } + + *out_count = num_scissor_rects; + } + + virtual void STDMETHODCALLTYPE OMSetBlendState( + ID3D11BlendState *new_blend_state, + const float new_blend_factor[4], + unsigned new_sample_mask) + { + SYNCHRONIZED; + float white[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + + if(blend_state.p != new_blend_state) + { + pipe->bind_blend_state(pipe, new_blend_state ? ((GalliumD3D11BlendState*)new_blend_state)->object : default_blend); + blend_state = new_blend_state; + } + + // Windows D3D11 does this, even though it's apparently undocumented + if(!new_blend_factor) + new_blend_factor = white; + + if(memcmp(blend_color, new_blend_factor, sizeof(blend_color))) + { + pipe->set_blend_color(pipe, (struct pipe_blend_color*)new_blend_factor); + memcpy(blend_color, new_blend_factor, sizeof(blend_color)); + } + + if(sample_mask != new_sample_mask) + { + pipe->set_sample_mask(pipe, new_sample_mask); + sample_mask = new_sample_mask; + } + } + + virtual void STDMETHODCALLTYPE OMGetBlendState( + ID3D11BlendState **out_blend_state, + float out_blend_factor[4], + unsigned *out_sample_mask) + { + SYNCHRONIZED; + if(out_blend_state) + *out_blend_state = blend_state.ref(); + if(out_blend_factor) + memcpy(out_blend_factor, blend_color, sizeof(blend_color)); + if(out_sample_mask) + *out_sample_mask = sample_mask; + } + + void set_stencil_ref() + { + struct pipe_stencil_ref sref; + sref.ref_value[0] = stencil_ref; + sref.ref_value[1] = stencil_ref; + pipe->set_stencil_ref(pipe, &sref); + } + + virtual void STDMETHODCALLTYPE OMSetDepthStencilState( + ID3D11DepthStencilState *new_depth_stencil_state, + unsigned new_stencil_ref) + { + SYNCHRONIZED; + if(new_depth_stencil_state != depth_stencil_state.p) + { + pipe->bind_depth_stencil_alpha_state(pipe, new_depth_stencil_state ? ((GalliumD3D11DepthStencilState*)new_depth_stencil_state)->object : default_depth_stencil); + depth_stencil_state = new_depth_stencil_state; + } + + if(new_stencil_ref != stencil_ref) + { + stencil_ref = new_stencil_ref; + set_stencil_ref(); + } + } + + virtual void STDMETHODCALLTYPE OMGetDepthStencilState( + ID3D11DepthStencilState **out_depth_stencil_state, + unsigned *out_stencil_ref) + { + SYNCHRONIZED; + if(*out_depth_stencil_state) + *out_depth_stencil_state = depth_stencil_state.ref(); + if(out_stencil_ref) + *out_stencil_ref = stencil_ref; + } + + void set_framebuffer() + { + struct pipe_framebuffer_state fb; + memset(&fb, 0, sizeof(fb)); + if(depth_stencil_view) + { + struct pipe_surface* surf = ((GalliumD3D11DepthStencilView*)depth_stencil_view.p)->object; + fb.zsbuf = surf; + if(surf->width > fb.width) + fb.width = surf->width; + if(surf->height > fb.height) + fb.height = surf->height; + } + fb.nr_cbufs = num_render_target_views; + unsigned i; + for(i = 0; i < num_render_target_views; ++i) + { + if(render_target_views[i]) + { + struct pipe_surface* surf = ((GalliumD3D11RenderTargetView*)render_target_views[i].p)->object; + fb.cbufs[i] = surf; + if(surf->width > fb.width) + fb.width = surf->width; + if(surf->height > fb.height) + fb.height = surf->height; + } + } + + pipe->set_framebuffer_state(pipe, &fb); + } + + /* TODO: the docs say that we should unbind conflicting resources (e.g. those bound for read while we are binding them for write too), but we aren't. + * Hopefully nobody relies on this happening + */ + + virtual void STDMETHODCALLTYPE OMSetRenderTargets( + unsigned count, + ID3D11RenderTargetView *const *new_render_target_views, + ID3D11DepthStencilView *new_depth_stencil_view) + { + SYNCHRONIZED; + if(!new_render_target_views) + count = 0; + if(count == num_render_target_views) + { + for(unsigned i = 0; i < count; ++i) + { + if(new_render_target_views[i] != render_target_views[i].p) + goto changed; + } + return; + } +changed: + depth_stencil_view = new_depth_stencil_view; + unsigned i; + for(i = 0; i < count; ++i) + { + render_target_views[i] = new_render_target_views[i]; +#if API >= 11 + om_unordered_access_views[i] = (ID3D11UnorderedAccessView*)NULL; +#endif + } + for(; i < num_render_target_views; ++i) + render_target_views[i] = (ID3D11RenderTargetView*)NULL; + num_render_target_views = count; + set_framebuffer(); + } + + virtual void STDMETHODCALLTYPE OMGetRenderTargets( + unsigned count, + ID3D11RenderTargetView **out_render_target_views, + ID3D11DepthStencilView **out_depth_stencil_view) + { + SYNCHRONIZED; + if(out_render_target_views) + { + unsigned i; + for(i = 0; i < std::min(num_render_target_views, count); ++i) + out_render_target_views[i] = render_target_views[i].ref(); + + for(; i < count; ++i) + out_render_target_views[i] = 0; + } + + if(out_depth_stencil_view) + *out_depth_stencil_view = depth_stencil_view.ref(); + } + +#if API >= 11 + /* TODO: what is this supposed to do _exactly_? are we doing the right thing? */ + virtual void STDMETHODCALLTYPE OMSetRenderTargetsAndUnorderedAccessViews( + unsigned rtv_count, + ID3D11RenderTargetView *const *new_render_target_views, + ID3D11DepthStencilView *new_depth_stencil_view, + unsigned uav_start, + unsigned uav_count, + ID3D11UnorderedAccessView *const *new_unordered_access_views, + const unsigned *new_uav_initial_counts) + { + SYNCHRONIZED; + if(rtv_count != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL) + OMSetRenderTargets(rtv_count, new_render_target_views, new_depth_stencil_view); + + if(uav_count != D3D11_KEEP_UNORDERED_ACCESS_VIEWS) + { + for(unsigned i = 0; i < uav_count; ++i) + { + om_unordered_access_views[uav_start + i] = new_unordered_access_views[i]; + render_target_views[uav_start + i] = (ID3D11RenderTargetView*)0; + } + } + } + + virtual void STDMETHODCALLTYPE OMGetRenderTargetsAndUnorderedAccessViews( + unsigned rtv_count, + ID3D11RenderTargetView **out_render_target_views, + ID3D11DepthStencilView **out_depth_stencil_view, + unsigned uav_start, + unsigned uav_count, + ID3D11UnorderedAccessView **out_unordered_access_views) + { + SYNCHRONIZED; + if(out_render_target_views) + OMGetRenderTargets(rtv_count, out_render_target_views, out_depth_stencil_view); + + if(out_unordered_access_views) + { + for(unsigned i = 0; i < uav_count; ++i) + out_unordered_access_views[i] = om_unordered_access_views[uav_start + i].ref(); + } + } +#endif + + virtual void STDMETHODCALLTYPE SOSetTargets( + unsigned count, + ID3D11Buffer *const *new_so_targets, + const unsigned *new_offsets) + { + SYNCHRONIZED; + unsigned i; + if(!new_so_targets) + count = 0; + bool changed = false; + for(i = 0; i < count; ++i) + { + ID3D11Buffer* buffer = new_so_targets[i]; + if(buffer != so_targets[i].p || new_offsets[i] != so_offsets[i]) + { + so_buffers[i] = buffer ? ((GalliumD3D11Buffer*)buffer)->resource : 0; + so_targets[i] = buffer; + so_offsets[i] = new_offsets[i]; + changed = true; + } + } + for(; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i) + { + if(so_targets[i].p || so_offsets[i]) + { + changed = true; + so_targets[i] = (ID3D11Buffer*)0; + so_offsets[i] = 0; + } + } + num_so_targets = count; + + if(changed && caps.so) + pipe->set_stream_output_buffers(pipe, so_buffers, (int*)so_offsets, num_so_targets); + } + + virtual void STDMETHODCALLTYPE SOGetTargets( + unsigned count, + ID3D11Buffer **out_so_targets +#if API < 11 + , UINT *out_offsets +#endif + ) + { + SYNCHRONIZED; + for(unsigned i = 0; i < count; ++i) + { + out_so_targets[i] = so_targets[i].ref(); +#if API < 11 + out_offsets[i] = so_offsets[i]; +#endif + } + } + + virtual void STDMETHODCALLTYPE Begin( + ID3D11Asynchronous *async) + { + SYNCHRONIZED; + if(caps.queries) + pipe->begin_query(pipe, ((GalliumD3D11Asynchronous<>*)async)->query); + } + + virtual void STDMETHODCALLTYPE End( + ID3D11Asynchronous *async) + { + SYNCHRONIZED; + if(caps.queries) + pipe->end_query(pipe, ((GalliumD3D11Asynchronous<>*)async)->query); + } + + virtual HRESULT STDMETHODCALLTYPE GetData( + ID3D11Asynchronous *iasync, + void *out_data, + unsigned data_size, + unsigned get_data_flags) + { + SYNCHRONIZED; + if(!caps.queries) + return E_NOTIMPL; + + GalliumD3D11Asynchronous<>* async = (GalliumD3D11Asynchronous<>*)iasync; + void* tmp_data = alloca(async->data_size); + boolean ret = pipe->get_query_result(pipe, async->query, !(get_data_flags & D3D11_ASYNC_GETDATA_DONOTFLUSH), tmp_data); + if(out_data) + memcpy(out_data, tmp_data, std::min(async->data_size, data_size)); + return ret ? S_OK : S_FALSE; + } + + void set_render_condition() + { + if(caps.render_condition) + { + if(!render_predicate) + pipe->render_condition(pipe, 0, 0); + else + { + GalliumD3D11Predicate* predicate = (GalliumD3D11Predicate*)render_predicate.p; + if(!render_predicate_value && predicate->desc.Query == D3D11_QUERY_OCCLUSION_PREDICATE) + { + unsigned mode = (predicate->desc.MiscFlags & D3D11_QUERY_MISC_PREDICATEHINT) ? PIPE_RENDER_COND_NO_WAIT : PIPE_RENDER_COND_WAIT; + pipe->render_condition(pipe, predicate->query, mode); + } + else + { + /* TODO: add inverted predication to Gallium*/ + pipe->render_condition(pipe, 0, 0); + } + } + } + } + + virtual void STDMETHODCALLTYPE SetPredication( + ID3D11Predicate *new_predicate, + BOOL new_predicate_value) + { + SYNCHRONIZED; + if(render_predicate.p != new_predicate || render_predicate_value != new_predicate_value) + { + render_predicate = new_predicate; + render_predicate_value = new_predicate_value; + set_render_condition(); + } + } + + virtual void STDMETHODCALLTYPE GetPredication( + ID3D11Predicate **out_predicate, + BOOL *out_predicate_value) + { + SYNCHRONIZED; + if(out_predicate) + *out_predicate = render_predicate.ref(); + if(out_predicate_value) + *out_predicate_value = render_predicate_value; + } + + static unsigned d3d11_subresource_to_level(struct pipe_resource* resource, unsigned subresource) + { + if(subresource <= resource->last_level) + { + return subresource; + } + else + { + unsigned levels = resource->last_level + 1; + return subresource % levels; + } + } + + static unsigned d3d11_subresource_to_face(struct pipe_resource* resource, unsigned subresource) + { + if(subresource <= resource->last_level) + { + return 0; + } + else + { + unsigned levels = resource->last_level + 1; + return subresource / levels; + } + } + + + /* TODO: deferred contexts will need a different implementation of this, + * because we can't put the transfer info into the resource itself. + * Also, there are very different restrictions, for obvious reasons. + */ + virtual HRESULT STDMETHODCALLTYPE Map( + ID3D11Resource *iresource, + unsigned subresource, + D3D11_MAP map_type, + unsigned map_flags, + D3D11_MAPPED_SUBRESOURCE *mapped_resource) + { + SYNCHRONIZED; + GalliumD3D11Resource<>* resource = (GalliumD3D11Resource<>*)iresource; + if(resource->transfers.count(subresource)) + return E_FAIL; + unsigned level = d3d11_subresource_to_level(resource->resource, subresource); + unsigned face = d3d11_subresource_to_face(resource->resource, subresource); + pipe_box box = d3d11_to_pipe_box(resource->resource, level, 0); + /* XXX the translation from subresource to level/face(zslice/array layer) isn't quite right */ + unsigned usage = 0; + if(map_type == D3D11_MAP_READ) + usage = PIPE_TRANSFER_READ; + else if(map_type == D3D11_MAP_WRITE) + usage = PIPE_TRANSFER_WRITE; + else if(map_type == D3D11_MAP_READ_WRITE) + usage = PIPE_TRANSFER_READ_WRITE; + else if(map_type == D3D11_MAP_WRITE_DISCARD) + usage = PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD; + else if(map_type == D3D11_MAP_WRITE_NO_OVERWRITE) + usage = PIPE_TRANSFER_WRITE | PIPE_TRANSFER_NOOVERWRITE; + else + return E_INVALIDARG; + if(map_type & D3D10_MAP_FLAG_DO_NOT_WAIT) + usage |= PIPE_TRANSFER_DONTBLOCK; + struct pipe_transfer* transfer = pipe->get_transfer(pipe, resource->resource, level, usage, &box); + if(!transfer) { + if(map_type & D3D10_MAP_FLAG_DO_NOT_WAIT) + return DXGI_ERROR_WAS_STILL_DRAWING; + else + return E_FAIL; + } + resource->transfers[subresource] = transfer; + mapped_resource->pData = pipe->transfer_map(pipe, transfer); + mapped_resource->RowPitch = transfer->stride; + mapped_resource->DepthPitch = transfer->layer_stride; + return S_OK; + } + + virtual void STDMETHODCALLTYPE Unmap( + ID3D11Resource *iresource, + unsigned subresource) + { + SYNCHRONIZED; + GalliumD3D11Resource<>* resource = (GalliumD3D11Resource<>*)iresource; + std::unordered_map::iterator i = resource->transfers.find(subresource); + if(i != resource->transfers.end()) + { + pipe->transfer_unmap(pipe, i->second); + pipe->transfer_destroy(pipe, i->second); + resource->transfers.erase(i); + } + } + + virtual void STDMETHODCALLTYPE CopySubresourceRegion( + ID3D11Resource *dst_resource, + unsigned dst_subresource, + unsigned dst_x, + unsigned dst_y, + unsigned dst_z, + ID3D11Resource *src_resource, + unsigned src_subresource, + const D3D11_BOX *src_box) + { + SYNCHRONIZED; + GalliumD3D11Resource<>* dst = (GalliumD3D11Resource<>*)dst_resource; + GalliumD3D11Resource<>* src = (GalliumD3D11Resource<>*)src_resource; + unsigned dst_level = d3d11_subresource_to_level(dst->resource, dst_subresource); + unsigned dst_face = d3d11_subresource_to_face(dst->resource, dst_subresource); + unsigned src_level = d3d11_subresource_to_level(src->resource, src_subresource); + unsigned src_face = d3d11_subresource_to_face(src->resource, src_subresource); + /* XXX the translation from subresource to level/face(zslice/array layer) isn't quite right */ + pipe_box box = d3d11_to_pipe_box(src->resource, src_level, src_box); + { + pipe->resource_copy_region(pipe, + dst->resource, dst_level, dst_x, dst_y, dst_z, + src->resource, src_level, &box); + } + } + + virtual void STDMETHODCALLTYPE CopyResource( + ID3D11Resource *dst_resource, + ID3D11Resource *src_resource) + { + SYNCHRONIZED; + GalliumD3D11Resource<>* dst = (GalliumD3D11Resource<>*)dst_resource; + GalliumD3D11Resource<>* src = (GalliumD3D11Resource<>*)src_resource; + unsigned level; + for(level = 0; level <= dst->resource->last_level; ++level) + { + unsigned layers = 1; + pipe_box box; + if (dst->resource->target == PIPE_TEXTURE_CUBE) + layers = 6; + else if (dst->resource->target == PIPE_TEXTURE_3D) + layers = u_minify(dst->resource->depth0, level); + /* else layers = dst->resource->array_size; */ + box.x = box.y = box.z = 0; + box.width = u_minify(dst->resource->width0, level); + box.height = u_minify(dst->resource->height0, level); + box.depth = layers; + pipe->resource_copy_region(pipe, + dst->resource, level, 0, 0, 0, + src->resource, level, &box); + } + } + + virtual void STDMETHODCALLTYPE UpdateSubresource( + ID3D11Resource *dst_resource, + unsigned dst_subresource, + const D3D11_BOX *pDstBox, + const void *pSrcData, + unsigned src_row_pitch, + unsigned src_depth_pitch) + { + SYNCHRONIZED; + GalliumD3D11Resource<>* dst = (GalliumD3D11Resource<>*)dst_resource; + unsigned dst_level = d3d11_subresource_to_level(dst->resource, dst_subresource); + /* XXX the translation from subresource to level/face(zslice/array layer) isn't quite right */ + pipe_box box = d3d11_to_pipe_box(dst->resource, dst_level, pDstBox); + pipe->transfer_inline_write(pipe, dst->resource, dst_level, PIPE_TRANSFER_WRITE, &box, pSrcData, src_row_pitch, src_depth_pitch); + } + +#if API >= 11 + virtual void STDMETHODCALLTYPE CopyStructureCount( + ID3D11Buffer *dst_buffer, + unsigned dst_aligned_byte_offset, + ID3D11UnorderedAccessView *src_view) + { + SYNCHRONIZED; + } +#endif + + virtual void STDMETHODCALLTYPE ClearRenderTargetView( + ID3D11RenderTargetView *render_target_view, + const float color[4]) + { + SYNCHRONIZED; + GalliumD3D11RenderTargetView* view = ((GalliumD3D11RenderTargetView*)render_target_view); + pipe->clear_render_target(pipe, view->object, color, 0, 0, view->object->width, view->object->height); + } + + virtual void STDMETHODCALLTYPE ClearDepthStencilView( + ID3D11DepthStencilView *depth_stencil_view, + unsigned clear_flags, + float depth, + UINT8 stencil) + { + SYNCHRONIZED; + GalliumD3D11DepthStencilView* view = ((GalliumD3D11DepthStencilView*)depth_stencil_view); + unsigned flags = 0; + if(clear_flags & D3D11_CLEAR_DEPTH) + flags |= PIPE_CLEAR_DEPTH; + if(clear_flags & D3D11_CLEAR_STENCIL) + flags |= PIPE_CLEAR_STENCIL; + pipe->clear_depth_stencil(pipe, view->object, flags, depth, stencil, 0, 0, view->object->width, view->object->height); + } + +#if API >= 11 + virtual void STDMETHODCALLTYPE ClearUnorderedAccessViewUint( + ID3D11UnorderedAccessView *unordered_access_view, + const unsigned values[4]) + { + SYNCHRONIZED; + } + + virtual void STDMETHODCALLTYPE ClearUnorderedAccessViewFloat( + ID3D11UnorderedAccessView *unordered_access_view, + const float values[4]) + { + SYNCHRONIZED; + } +#endif + + void restore_gallium_state_blit_only() + { + pipe->bind_blend_state(pipe, blend_state.p ? blend_state.p->object : default_blend); + pipe->bind_depth_stencil_alpha_state(pipe, depth_stencil_state.p ? depth_stencil_state.p->object : default_depth_stencil); + pipe->bind_rasterizer_state(pipe, rasterizer_state.p ? rasterizer_state.p->object : default_rasterizer); + pipe->bind_vertex_elements_state(pipe, input_layout.p ? input_layout.p->object : default_input_layout); + pipe->bind_fs_state(pipe, shaders[D3D11_STAGE_PS].p ? shaders[D3D11_STAGE_PS].p->object : default_shaders[PIPE_SHADER_FRAGMENT]); + pipe->bind_vs_state(pipe, shaders[D3D11_STAGE_VS].p ? shaders[D3D11_STAGE_VS].p->object : default_shaders[PIPE_SHADER_VERTEX]); + if(caps.gs) + pipe->bind_gs_state(pipe, shaders[D3D11_STAGE_GS].p ? shaders[D3D11_STAGE_GS].p->object : default_shaders[PIPE_SHADER_GEOMETRY]); + set_framebuffer(); + set_viewport(); + set_clip(); + set_render_condition(); + // TODO: restore stream output + + update_flags |= UPDATE_VERTEX_BUFFERS | (1 << (UPDATE_SAMPLERS_SHIFT + D3D11_STAGE_PS)) | (1 << (UPDATE_VIEWS_SHIFT + D3D11_STAGE_PS)); + } + + virtual void STDMETHODCALLTYPE RestoreGalliumStateBlitOnly() + { + SYNCHRONIZED; + restore_gallium_state_blit_only(); + } + + virtual void STDMETHODCALLTYPE GenerateMips( + ID3D11ShaderResourceView *shader_resource_view) + { + SYNCHRONIZED; + + GalliumD3D11ShaderResourceView* view = (GalliumD3D11ShaderResourceView*)shader_resource_view; + if(caps.gs) + pipe->bind_gs_state(pipe, 0); + if(caps.so) + pipe->bind_stream_output_state(pipe, 0); + if(pipe->render_condition) + pipe->render_condition(pipe, 0, 0); + util_gen_mipmap(gen_mipmap, view->object, 0, 0, view->object->texture->last_level, PIPE_TEX_FILTER_LINEAR); + restore_gallium_state_blit_only(); + } + + virtual void STDMETHODCALLTYPE RestoreGalliumState() + { + SYNCHRONIZED; + restore_gallium_state_blit_only(); + + set_index_buffer(); + set_stencil_ref(); + pipe->set_blend_color(pipe, (struct pipe_blend_color*)blend_color); + pipe->set_sample_mask(pipe, sample_mask); + + for(unsigned s = 0; s < 3; ++s) + { + unsigned num = std::min(caps.constant_buffers[s], (unsigned)D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT); + for(unsigned i = 0; i < num; ++i) + pipe->set_constant_buffer(pipe, s, i, constant_buffers[s][i].p ? constant_buffers[s][i].p->resource : 0); + } + + if(caps.so) + pipe->set_stream_output_buffers(pipe, so_buffers, (int*)so_offsets, num_so_targets); + + update_flags |= (1 << (UPDATE_SAMPLERS_SHIFT + D3D11_STAGE_VS)) | (1 << (UPDATE_VIEWS_SHIFT + D3D11_STAGE_VS)); + update_flags |= (1 << (UPDATE_SAMPLERS_SHIFT + D3D11_STAGE_GS)) | (1 << (UPDATE_VIEWS_SHIFT + D3D11_STAGE_GS)); + + set_scissor(); + } + +#if API >= 11 + /* TODO: hack SRVs or sampler states to handle this, or add to Gallium */ + virtual void STDMETHODCALLTYPE SetResourceMinLOD( + ID3D11Resource *iresource, + float min_lod) + { + SYNCHRONIZED; + GalliumD3D11Resource<>* resource = (GalliumD3D11Resource<>*)iresource; + if(resource->min_lod != min_lod) + { + // TODO: actually do anything? + resource->min_lod = min_lod; + } + } + + virtual float STDMETHODCALLTYPE GetResourceMinLOD( + ID3D11Resource *iresource) + { + SYNCHRONIZED; + GalliumD3D11Resource<>* resource = (GalliumD3D11Resource<>*)iresource; + return resource->min_lod; + } +#endif + + virtual void STDMETHODCALLTYPE ResolveSubresource( + ID3D11Resource *dst_resource, + unsigned dst_subresource, + ID3D11Resource *src_resource, + unsigned src_subresource, + DXGI_FORMAT format) + { + SYNCHRONIZED; + GalliumD3D11Resource<>* dst = (GalliumD3D11Resource<>*)dst_resource; + GalliumD3D11Resource<>* src = (GalliumD3D11Resource<>*)src_resource; + unsigned dst_layer = d3d11_subresource_to_face(dst->resource, dst_subresource); + unsigned src_layer = d3d11_subresource_to_face(src->resource, src_subresource); + pipe->resource_resolve(pipe, dst->resource, dst_layer, src->resource, src_layer); + } + +#if API >= 11 + virtual void STDMETHODCALLTYPE ExecuteCommandList( + ID3D11CommandList *command_list, + BOOL restore_context_state) + { + SYNCHRONIZED; + } + + virtual HRESULT STDMETHODCALLTYPE FinishCommandList( + BOOL restore_deferred_context_state, + ID3D11CommandList **out_command_list) + { + SYNCHRONIZED; + return E_NOTIMPL; + } +#endif + + virtual void STDMETHODCALLTYPE ClearState(void) + { + /* we don't take a lock here because we would deadlock otherwise + * TODO: this is probably incorrect, because ClearState should likely be atomic. + * However, I can't think of any correct usage that would be affected by this + * being non-atomic, and making this atomic is quite expensive and complicates + * the code + */ + + // we qualify all calls so that we avoid virtual dispatch and might get them inlined + // TODO: make sure all this gets inlined, which might require more compiler flags + // TODO: optimize this +#if API >= 11 + GalliumD3D11DeviceContext::PSSetShader(0, 0, 0); + GalliumD3D11DeviceContext::GSSetShader(0, 0, 0); + GalliumD3D11DeviceContext::VSSetShader(0, 0, 0); + GalliumD3D11DeviceContext::HSSetShader(0, 0, 0); + GalliumD3D11DeviceContext::DSSetShader(0, 0, 0); + GalliumD3D11DeviceContext::CSSetShader(0, 0, 0); +#else + GalliumD3D11DeviceContext::PSSetShader(0); + GalliumD3D11DeviceContext::GSSetShader(0); + GalliumD3D11DeviceContext::VSSetShader(0); +#endif + + GalliumD3D11DeviceContext::IASetInputLayout(0); + GalliumD3D11DeviceContext::IASetIndexBuffer(0, DXGI_FORMAT_UNKNOWN, 0); + GalliumD3D11DeviceContext::RSSetState(0); + GalliumD3D11DeviceContext::OMSetDepthStencilState(0, 0); + GalliumD3D11DeviceContext::OMSetBlendState(0, (float*)zero_data, ~0); + GalliumD3D11DeviceContext::SetPredication(0, 0); + GalliumD3D11DeviceContext::IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_UNDEFINED); + + GalliumD3D11DeviceContext::PSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data); + GalliumD3D11DeviceContext::GSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data); + GalliumD3D11DeviceContext::VSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data); +#if API >= 11 + GalliumD3D11DeviceContext::HSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data); + GalliumD3D11DeviceContext::DSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data); + GalliumD3D11DeviceContext::CSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data); +#endif + + GalliumD3D11DeviceContext::IASetVertexBuffers(0, num_vertex_buffers, (ID3D11Buffer**)zero_data, (unsigned*)zero_data, (unsigned*)zero_data); +#if API >= 11 + GalliumD3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews(0, 0, 0 , 0, 0, 0, 0); +#else + GalliumD3D11DeviceContext::OMSetRenderTargets(0, 0, 0 ); +#endif + GalliumD3D11DeviceContext::SOSetTargets(0, 0, 0); + + GalliumD3D11DeviceContext::PSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_PS], (ID3D11ShaderResourceView**)zero_data); + GalliumD3D11DeviceContext::GSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_GS], (ID3D11ShaderResourceView**)zero_data); + GalliumD3D11DeviceContext::VSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_VS], (ID3D11ShaderResourceView**)zero_data); +#if API >= 11 + GalliumD3D11DeviceContext::HSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_HS], (ID3D11ShaderResourceView**)zero_data); + GalliumD3D11DeviceContext::DSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_DS], (ID3D11ShaderResourceView**)zero_data); + GalliumD3D11DeviceContext::CSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_CS], (ID3D11ShaderResourceView**)zero_data); +#endif + + GalliumD3D11DeviceContext::PSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_PS], (ID3D11SamplerState**)zero_data); + GalliumD3D11DeviceContext::GSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_GS], (ID3D11SamplerState**)zero_data); + GalliumD3D11DeviceContext::VSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_VS], (ID3D11SamplerState**)zero_data); +#if API >= 11 + GalliumD3D11DeviceContext::HSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_HS], (ID3D11SamplerState**)zero_data); + GalliumD3D11DeviceContext::DSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_DS], (ID3D11SamplerState**)zero_data); + GalliumD3D11DeviceContext::CSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_CS], (ID3D11SamplerState**)zero_data); +#endif + + GalliumD3D11DeviceContext::RSSetViewports(0, 0); + GalliumD3D11DeviceContext::RSSetScissorRects(0, 0); + } + + virtual void STDMETHODCALLTYPE Flush(void) + { + SYNCHRONIZED; + pipe->flush(pipe, PIPE_FLUSH_FRAME, 0); + } + + /* In Direct3D 10, if the reference count of an object drops to 0, it is automatically + * cleanly unbound from the pipeline. + * In Direct3D 11, the pipeline holds a reference. + * + * Note that instead of always scanning the pipeline on destruction, we could + * maintain the internal reference count on DirectX 10 and use it to check if an + * object is still bound. + * Presumably, on average, scanning is faster if the application is well written. + */ +#if API < 11 +#define IMPLEMENT_SIMPLE_UNBIND(name, member, gallium, def) \ + void Unbind##name(ID3D11##name* state) \ + { \ + SYNCHRONIZED; \ + if((void*)state == (void*)member.p) \ + { \ + member.p = 0; \ + pipe->bind_##gallium##_state(pipe, default_##def); \ + } \ + } + IMPLEMENT_SIMPLE_UNBIND(BlendState, blend_state, blend, blend) + IMPLEMENT_SIMPLE_UNBIND(RasterizerState, rasterizer_state, rasterizer, rasterizer) + IMPLEMENT_SIMPLE_UNBIND(DepthStencilState, depth_stencil_state, depth_stencil_alpha, depth_stencil) + IMPLEMENT_SIMPLE_UNBIND(InputLayout, input_layout, vertex_elements, input_layout) + IMPLEMENT_SIMPLE_UNBIND(PixelShader, shaders[D3D11_STAGE_PS], fs, shaders[D3D11_STAGE_PS]) + IMPLEMENT_SIMPLE_UNBIND(VertexShader, shaders[D3D11_STAGE_VS], vs, shaders[D3D11_STAGE_VS]) + IMPLEMENT_SIMPLE_UNBIND(GeometryShader, shaders[D3D11_STAGE_GS], gs, shaders[D3D11_STAGE_GS]) + + void UnbindPredicate(ID3D11Predicate* predicate) + { + SYNCHRONIZED; + if(predicate == render_predicate) + { + render_predicate.p = NULL; + render_predicate_value = 0; + pipe->render_condition(pipe, 0, 0); + } + } + + void UnbindSamplerState(ID3D11SamplerState* state) + { + SYNCHRONIZED; + for(unsigned s = 0; s < D3D11_STAGES; ++s) + { + for(unsigned i = 0; i < num_samplers[s]; ++i) + { + if(samplers[s][i] == state) + { + samplers[s][i].p = NULL; + sampler_csos[s].v[i] = NULL; + update_flags |= (1 << (UPDATE_SAMPLERS_SHIFT + s)); + } + } + } + } + + void UnbindBuffer(ID3D11Buffer* buffer) + { + SYNCHRONIZED; + if(buffer == index_buffer) + { + index_buffer.p = 0; + index_format = DXGI_FORMAT_UNKNOWN; + index_offset = 0; + struct pipe_index_buffer ib; + memset(&ib, 0, sizeof(ib)); + pipe->set_index_buffer(pipe, &ib); + } + + for(unsigned i = 0; i < num_vertex_buffers; ++i) + { + if(buffer == input_buffers[i]) + { + input_buffers[i].p = 0; + memset(&vertex_buffers[num_vertex_buffers], 0, sizeof(vertex_buffers[num_vertex_buffers])); + update_flags |= UPDATE_VERTEX_BUFFERS; + } + } + + for(unsigned s = 0; s < D3D11_STAGES; ++s) + { + for(unsigned i = 0; i < sizeof(constant_buffers) / sizeof(constant_buffers[0]); ++i) + { + if(constant_buffers[s][i] == buffer) + { + constant_buffers[s][i] = (ID3D10Buffer*)NULL; + pipe->set_constant_buffer(pipe, s, i, NULL); + } + } + } + } + + void UnbindDepthStencilView(ID3D11DepthStencilView * view) + { + SYNCHRONIZED; + if(view == depth_stencil_view) + { + depth_stencil_view.p = NULL; + set_framebuffer(); + } + } + + void UnbindRenderTargetView(ID3D11RenderTargetView* view) + { + SYNCHRONIZED; + bool any_bound = false; + for(unsigned i = 0; i < num_render_target_views; ++i) + { + if(render_target_views[i] == view) + { + render_target_views[i].p = NULL; + any_bound = true; + } + } + if(any_bound) + set_framebuffer(); + } + + void UnbindShaderResourceView(ID3D11ShaderResourceView* view) + { + SYNCHRONIZED; + for(unsigned s = 0; s < D3D11_STAGES; ++s) + { + for(unsigned i = 0; i < num_shader_resource_views[s]; ++i) + { + if(shader_resource_views[s][i] == view) + { + shader_resource_views[s][i].p = NULL; + sampler_views[s][i] = NULL; + update_flags |= (1 << (UPDATE_VIEWS_SHIFT + s)); + } + } + } + } +#endif + +#undef SYNCHRONIZED +}; + +#if API >= 11 +/* This approach serves two purposes. + * First, we don't want to do an atomic operation to manipulate the reference + * count every time something is bound/unbound to the pipeline, since they are + * expensive. + * Fortunately, the immediate context can only be used by a single thread, so + * we don't have to use them, as long as a separate reference count is used + * (see dual_refcnt_t). + * + * Second, we want to avoid the Device -> DeviceContext -> bound DeviceChild -> Device + * garbage cycle. + * To avoid it, DeviceChild doesn't hold a reference to Device as usual, but adds + * one for each external reference count, while internal nonatomic_add_ref doesn't + * add any. + * + * Note that ideally we would to eliminate the non-atomic op too, but this is more + * complicated, since we would either need to use garbage collection and give up + * deterministic destruction (especially bad for large textures), or scan the whole + * pipeline state every time the reference count of object drops to 0, which risks + * pathological slowdowns. + * + * Since this microoptimization should matter relatively little, let's avoid it for now. + * + * Note that deferred contexts don't use this, since as a whole, they must thread-safe. + * Eliminating the atomic ops for deferred contexts seems substantially harder. + * This might be a problem if they are used in a one-shot multithreaded rendering + * fashion, where SMP cacheline bouncing on the reference count may be visible. + * + * The idea would be to attach a structure of reference counts indexed by deferred + * context id to each object. Ideally, this should be organized like ext2 block pointers. + * + * Every deferred context would get a reference count in its own cacheline. + * The external count is protected by a lock bit, and there is also a "lock bit" in each + * internal count. + * + * When the external count has to be dropped to 0, the lock bit is taken and all internal + * reference counts are scanned, taking a count of them. A flag would also be set on them. + * Deferred context manipulation would notice the flag, and update the count. + * Once the count goes to zero, the object is freed. + * + * The problem of this is that if the external reference count ping-pongs between + * zero and non-zero, the scans will take a lot of time. + * + * The idea to solve this is to compute the scans in a binary-tree like fashion, where + * each binary tree node would have a "determined bit", which would be invalidated + * by manipulations. + * + * However, all this complexity might actually be a loss in most cases, so let's just + * stick to a single atomic refcnt for now. + * + * Also, we don't even support deferred contexts yet, so this can wait. + */ +struct nonatomic_device_child_ptr_traits +{ + static void add_ref(void* p) + { + if(p) + ((GalliumD3D11DeviceChild<>*)p)->nonatomic_add_ref(); + } + + static void release(void* p) + { + if(p) + ((GalliumD3D11DeviceChild<>*)p)->nonatomic_release(); + } +}; + +struct GalliumD3D11ImmediateDeviceContext + : public GalliumD3D11DeviceContext +{ + GalliumD3D11ImmediateDeviceContext(GalliumD3D11Screen* device, pipe_context* pipe, unsigned context_flags = 0) + : GalliumD3D11DeviceContext(device, pipe, context_flags) + { + // not necessary, but tests that the API at least basically works + ClearState(); + } + + /* we do this since otherwise we would have a garbage cycle between this and the device */ + virtual ULONG STDMETHODCALLTYPE AddRef() + { + return this->device->AddRef(); + } + + virtual ULONG STDMETHODCALLTYPE Release() + { + return this->device->Release(); + } + + virtual D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE GetType() + { + return D3D11_DEVICE_CONTEXT_IMMEDIATE; + } +}; + +static ID3D11DeviceContext* GalliumD3D11ImmediateDeviceContext_Create(GalliumD3D11Screen* device, struct pipe_context* pipe, bool owns_pipe) +{ + return new GalliumD3D11ImmediateDeviceContext(device, pipe, owns_pipe); +} + +static void GalliumD3D11ImmediateDeviceContext_RestoreGalliumState(ID3D11DeviceContext* context) +{ + ((GalliumD3D11ImmediateDeviceContext*)context)->RestoreGalliumState(); +} + +static void GalliumD3D11ImmediateDeviceContext_RestoreGalliumStateBlitOnly(ID3D11DeviceContext* context) +{ + ((GalliumD3D11ImmediateDeviceContext*)context)->RestoreGalliumStateBlitOnly(); +} + +static void GalliumD3D11ImmediateDeviceContext_Destroy(ID3D11DeviceContext* context) +{ + delete (GalliumD3D11ImmediateDeviceContext*)context; +} +#endif diff --git a/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_misc.h b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_misc.h new file mode 100644 index 0000000..357f51b --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_misc.h @@ -0,0 +1,92 @@ +#if API < 11 +extern "C" HRESULT STDMETHODCALLTYPE D3D10CreateBlob( + SIZE_T num_bytes, + LPD3D10BLOB *out_buffer +); + +HRESULT STDMETHODCALLTYPE D3D10CreateBlob( + SIZE_T num_bytes, + LPD3D10BLOB *out_buffer +) +{ + void* data = malloc(num_bytes); + if(!data) + return E_OUTOFMEMORY; + *out_buffer = new GalliumD3DBlob(data, num_bytes); + return S_OK; +} + +LPCSTR STDMETHODCALLTYPE D3D10GetPixelShaderProfile( + ID3D10Device *device +) +{ + return "ps_4_0"; +} + +LPCSTR STDMETHODCALLTYPE D3D10GetVertexShaderProfile( + ID3D10Device *device +) +{ + return "vs_4_0"; +} + +LPCSTR STDMETHODCALLTYPE D3D10GetGeometryShaderProfile( + ID3D10Device *device +) +{ + return "gs_4_0"; +} + +static HRESULT dxbc_assemble_as_blob(struct dxbc_chunk_header** chunks, unsigned num_chunks, ID3D10Blob** blob) +{ + std::pair p = dxbc_assemble(chunks, num_chunks); + if(!p.first) + return E_OUTOFMEMORY; + *blob = new GalliumD3DBlob(p.first, p.second); + return S_OK; +} + +HRESULT D3D10GetInputSignatureBlob( + const void *shader_bytecode, + SIZE_T bytecode_length, + ID3D10Blob **signature_blob +) +{ + dxbc_chunk_signature* sig = dxbc_find_signature(shader_bytecode, bytecode_length, false); + if(!sig) + return E_FAIL; + + return dxbc_assemble_as_blob((dxbc_chunk_header**)&sig, 1, signature_blob); +} + +HRESULT D3D10GetOutputSignatureBlob( + const void *shader_bytecode, + SIZE_T bytecode_length, + ID3D10Blob **signature_blob +) +{ + dxbc_chunk_signature* sig = dxbc_find_signature(shader_bytecode, bytecode_length, true); + if(!sig) + return E_FAIL; + + return dxbc_assemble_as_blob((dxbc_chunk_header**)&sig, 1, signature_blob); +} + +HRESULT D3D10GetInputAndOutputSignatureBlob( + const void *shader_bytecode, + SIZE_T bytecode_length, + ID3D10Blob **signature_blob +) +{ + dxbc_chunk_signature* sigs[2]; + sigs[0] = dxbc_find_signature(shader_bytecode, bytecode_length, false); + if(!sigs[0]) + return E_FAIL; + sigs[1] = dxbc_find_signature(shader_bytecode, bytecode_length, true); + if(!sigs[1]) + return E_FAIL; + + return dxbc_assemble_as_blob((dxbc_chunk_header**)&sigs, 2, signature_blob); +} + +#endif diff --git a/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_objects.h b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_objects.h new file mode 100644 index 0000000..836603e --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_objects.h @@ -0,0 +1,717 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +template +struct GalliumD3D11DeviceChild : public GalliumPrivateDataComObject +{ + GalliumD3D11Screen* device; // must not be null + + + // if this is called, the subclass constructor must set device itself + GalliumD3D11DeviceChild() + : device(0) + {} + + GalliumD3D11DeviceChild(GalliumD3D11Screen* p_device) + { + // we store the reference count minus one in refcnt + device = p_device; + device->AddRef(); + } + + /* The purpose of this is to avoid cyclic garbage, since this won't hold + * a pointer to the device if it is only held by a pipeline binding in the immediate context + * + * TODO: we could only manipulate the device refcnt when atomic_refcnt == 0 changes, + * but this requires more complex atomic ops + */ + inline ULONG add_ref() + { + device->AddRef(); + return GalliumPrivateDataComObject::add_ref(); + } + + inline ULONG release() + { + device->Release(); + return GalliumPrivateDataComObject::release(); + } + + virtual ULONG STDMETHODCALLTYPE AddRef() + { + return add_ref(); + } + + virtual ULONG STDMETHODCALLTYPE Release() + { + return release(); + } + + virtual void STDMETHODCALLTYPE GetDevice( + ID3D11Device **out_device + ) + { + device->AddRef(); + *out_device = device; + } +}; + +template +struct GalliumD3D11Object : public GalliumD3D11DeviceChild +{ + Object* object; + GalliumD3D11Object(GalliumD3D11Screen* device, Object* object) + : GalliumD3D11DeviceChild(device), object(object) + {} + + virtual ~GalliumD3D11Object(); +}; + +#define IMPLEMENT_OBJECT_DTOR(name, gallium) \ +template<> \ +GalliumD3D11Object::~GalliumD3D11Object() \ +{ \ + DX10_ONLY(device->Unbind##name(this)); \ + device->immediate_pipe->delete_##gallium##_state(device->immediate_pipe, object); \ +} + +#define IMPLEMENT_VIEW_DTOR(name, gallium) \ +template<> \ +GalliumD3D11Object::~GalliumD3D11Object() \ +{ \ + DX10_ONLY(device->Unbind##name(this)); \ + pipe_##gallium##_reference(&object, 0); \ +} + +IMPLEMENT_OBJECT_DTOR(InputLayout, vertex_elements) +IMPLEMENT_OBJECT_DTOR(DepthStencilState, depth_stencil_alpha) +IMPLEMENT_OBJECT_DTOR(RasterizerState, rasterizer) +IMPLEMENT_OBJECT_DTOR(SamplerState, sampler) +IMPLEMENT_OBJECT_DTOR(BlendState, blend) +IMPLEMENT_OBJECT_DTOR(VertexShader, vs) +IMPLEMENT_OBJECT_DTOR(PixelShader, fs) +IMPLEMENT_OBJECT_DTOR(GeometryShader, gs) + +IMPLEMENT_VIEW_DTOR(ShaderResourceView, sampler_view) +IMPLEMENT_VIEW_DTOR(RenderTargetView, surface) +IMPLEMENT_VIEW_DTOR(DepthStencilView, surface) + +#if API >= 11 +// IMPLEMENT_VIEW_DTOR(UnorderedAccessView, surface); +// IMPLEMENT_OBJECT_DTOR(HullShader, tcs); +// IMPLEMENT_OBJECT_DTOR(DomainShader, tes); +// IMPLEMENT_OBJECT_DTOR(ComputeShader, cs); +#else +IMPLEMENT_OBJECT_DTOR(BlendState1, blend) +IMPLEMENT_VIEW_DTOR(ShaderResourceView1, sampler_view) +#endif + +template +struct GalliumD3D11DescribedObject : public GalliumD3D11Object +{ + Desc desc; + GalliumD3D11DescribedObject(GalliumD3D11Screen* device, Object* object, const Desc& desc) + : GalliumD3D11Object(device, object), desc(desc) + {} + + virtual void STDMETHODCALLTYPE GetDesc(Desc *out_desc) + { + memcpy(out_desc, &desc, sizeof(desc)); + } +}; + +typedef GalliumD3D11Object GalliumD3D11InputLayout; +typedef GalliumD3D11DescribedObject GalliumD3D11DepthStencilState; +typedef GalliumD3D11DescribedObject GalliumD3D11RasterizerStateBase; +typedef GalliumD3D11DescribedObject GalliumD3D11SamplerState; + +#if API >= 11 +typedef GalliumD3D11DescribedObject GalliumD3D11BlendState; +#else +typedef GalliumD3D10DescribedObject GalliumD3D10BlendStateBase; + +struct GalliumD3D10BlendState : public GalliumD3D10BlendStateBase +{ + static D3D10_BLEND_DESC convert_to_d3d10(const D3D10_BLEND_DESC1& desc1) + { + D3D10_BLEND_DESC desc; + desc.AlphaToCoverageEnable = desc1.AlphaToCoverageEnable; + desc.SrcBlend = desc1.RenderTarget[0].SrcBlend; + desc.DestBlend = desc1.RenderTarget[0].DestBlend; + desc.BlendOp = desc1.RenderTarget[0].BlendOp; + desc.SrcBlendAlpha = desc1.RenderTarget[0].SrcBlendAlpha; + desc.DestBlendAlpha = desc1.RenderTarget[0].DestBlendAlpha; + desc.BlendOpAlpha = desc1.RenderTarget[0].BlendOpAlpha; + for(unsigned i = 0; i < 8; ++i) + { + desc.BlendEnable[i] = desc1.RenderTarget[i].BlendEnable; + desc.RenderTargetWriteMask[i] = desc1.RenderTarget[i].RenderTargetWriteMask; + } + return desc; + } + + D3D10_BLEND_DESC1 desc1; + + GalliumD3D10BlendState(GalliumD3D10Screen* device, void* object, const D3D10_BLEND_DESC& desc) + : GalliumD3D10BlendStateBase(device, object, desc) + { + memset(&desc1, 0, sizeof(desc1)); + desc1.AlphaToCoverageEnable = desc.AlphaToCoverageEnable; + desc1.RenderTarget[0].SrcBlend = desc.SrcBlend; + desc1.RenderTarget[0].DestBlend = desc.DestBlend; + desc1.RenderTarget[0].BlendOp = desc.BlendOp; + desc1.RenderTarget[0].SrcBlendAlpha = desc.SrcBlendAlpha; + desc1.RenderTarget[0].DestBlendAlpha = desc.DestBlendAlpha; + desc1.RenderTarget[0].BlendOpAlpha = desc.BlendOpAlpha; + for(unsigned i = 0; i < 8; ++i) + { + desc1.RenderTarget[i].BlendEnable = desc.BlendEnable[i]; + desc1.RenderTarget[i].RenderTargetWriteMask = desc.RenderTargetWriteMask[i]; + } + } + + GalliumD3D10BlendState(GalliumD3D10Screen* device, void* object, const D3D10_BLEND_DESC1& desc) + : GalliumD3D10BlendStateBase(device, object, convert_to_d3d10(desc)), desc1(desc1) + {} + + virtual void STDMETHODCALLTYPE GetDesc1(D3D10_BLEND_DESC1 *out_desc) + { + memcpy(out_desc, &desc1, sizeof(desc1)); + } +}; +#endif + +struct GalliumD3D11RasterizerState : public GalliumD3D11RasterizerStateBase +{ + bool depth_clamp; + + GalliumD3D11RasterizerState(GalliumD3D11Screen* device, void* object, const D3D11_RASTERIZER_DESC& desc, bool depth_clamp) + : GalliumD3D11RasterizerStateBase(device, object, desc), depth_clamp(depth_clamp) + {} +}; + +template +struct GalliumD3D11Shader : public GalliumD3D11Object +{ + std::vector slot_to_resource; + std::vector slot_to_sampler; + + GalliumD3D11Shader(GalliumD3D11Screen* device, void* object) + : GalliumD3D11Object(device, object) + {} +}; + +typedef GalliumD3D11Shader GalliumD3D11VertexShader; +typedef GalliumD3D11Shader GalliumD3D11GeometryShader; +typedef GalliumD3D11Shader GalliumD3D11PixelShader; + +#if API >= 11 +/* +typedef GalliumD3D11Shader GalliumD3D11HullShader; +typedef GalliumD3D11Shader GalliumD3D11DomainShader; +typedef GalliumD3D11Shader GalliumD3D11ComputeShader; +*/ +#endif + +template +struct GalliumD3D11ResourceBase : public GalliumD3D11DeviceChild +{ + unsigned eviction_priority; + + virtual void STDMETHODCALLTYPE SetEvictionPriority( + unsigned new_eviction_priority + ) + { + eviction_priority = new_eviction_priority; + } + + virtual unsigned STDMETHODCALLTYPE GetEvictionPriority() + { + return eviction_priority; + } +}; + +template +struct GalliumDXGIResource : public IDXGIResource +{ + virtual HRESULT STDMETHODCALLTYPE SetEvictionPriority( + unsigned new_eviction_priority + ) + { + static_cast(this)->eviction_priority = new_eviction_priority; + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE GetEvictionPriority(unsigned* out_eviction_priority) + { + *out_eviction_priority = static_cast(this)->eviction_priority; + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE GetDevice( + REFIID riid, + void **out_parent) + { + if(!static_cast(this)->device) + return E_NOINTERFACE; + return static_cast(this)->device->QueryInterface(riid, out_parent); + } + + virtual HRESULT STDMETHODCALLTYPE GetParent( + REFIID riid, + void **out_parent) + { + if(!static_cast(this)->device) + return E_NOINTERFACE; + return static_cast(this)->device->QueryInterface(riid, out_parent); + } +}; + +template +struct com_traits > : public com_traits +{}; + +template +struct GalliumD3D11Resource + : public GalliumMultiComObject< + GalliumMultiPrivateDataComObject< + GalliumD3D11ResourceBase, + GalliumDXGIResource > + >, + IGalliumResource + > +{ + struct pipe_resource* resource; + std::unordered_map transfers; + float min_lod; + DXGI_USAGE dxgi_usage; + + GalliumD3D11Resource(GalliumD3D11Screen* device = 0, struct pipe_resource* resource = 0, unsigned dxgi_usage = 0) + : resource(resource), min_lod(0), dxgi_usage(dxgi_usage) + { + this->device = device; + if(device) + device->AddRef(); + this->eviction_priority = 0; + } + + ~GalliumD3D11Resource() + { + pipe_resource_reference(&resource, 0); + } + + virtual HRESULT STDMETHODCALLTYPE GetUsage( + DXGI_USAGE *out_usage + ) + { + *out_usage = this->dxgi_usage; + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE GetSharedHandle(HANDLE *out_shared_handle) + { + return E_NOTIMPL; + } + + virtual struct pipe_resource* STDMETHODCALLTYPE GetGalliumResource() + { + return resource; + } +}; + +template +struct GalliumD3D11TypedResource : public GalliumD3D11Resource +{ + Desc desc; + GalliumD3D11TypedResource() {} + GalliumD3D11TypedResource(GalliumD3D11Screen* device, struct pipe_resource* resource, const Desc& desc, unsigned dxgi_usage) + : GalliumD3D11Resource(device, resource, dxgi_usage), desc(desc) + {} + virtual void STDMETHODCALLTYPE GetType( + D3D11_RESOURCE_DIMENSION *out_resource_dimension) + { + *out_resource_dimension = Dim; + } + virtual void STDMETHODCALLTYPE GetDesc(Desc *out_desc) + { + memcpy(out_desc, &desc, sizeof(desc)); + } +}; + +typedef GalliumD3D11TypedResource GalliumD3D11Texture1DBase; +typedef GalliumD3D11TypedResource GalliumD3D11Texture2DBase; +typedef GalliumD3D11TypedResource GalliumD3D11Texture3DBase; +typedef GalliumD3D11TypedResource GalliumD3D11BufferBase; + +#if API >= 11 +typedef GalliumD3D11BufferBase GalliumD3D11Buffer; +typedef GalliumD3D11Texture1DBase GalliumD3D11Texture1D; +typedef GalliumD3D11Texture2DBase GalliumD3D11Texture2D; +typedef GalliumD3D11Texture3DBase GalliumD3D11Texture3D; +#else +struct GalliumD3D10Buffer : public GalliumD3D10BufferBase +{ + GalliumD3D10Buffer(GalliumD3D10Screen* device, struct pipe_resource* resource, const D3D10_BUFFER_DESC& desc, unsigned dxgi_usage) + : GalliumD3D10BufferBase(device, resource, desc, dxgi_usage) + {} + + ~GalliumD3D10Buffer() + { + device->UnbindBuffer(this); + } + + virtual HRESULT STDMETHODCALLTYPE Map( + D3D10_MAP map_type, + unsigned map_flags, + void **out_data) + { + D3D10_MAPPED_SUBRESOURCE msr; + HRESULT hr = device->Map(this, 0, map_type, map_flags, &msr); + if(!SUCCEEDED(hr)) + return hr; + *out_data = msr.pData; + return S_OK; + } + + virtual void STDMETHODCALLTYPE Unmap() + { + device->Unmap(this, 0); + } +}; + +struct GalliumD3D10Texture1D : public GalliumD3D10Texture1DBase +{ + GalliumD3D10Texture1D(GalliumD3D10Screen* device, struct pipe_resource* resource, const D3D10_TEXTURE1D_DESC& desc, unsigned dxgi_usage) + : GalliumD3D10Texture1DBase(device, resource, desc, dxgi_usage) + {} + + virtual HRESULT STDMETHODCALLTYPE Map( + unsigned subresource, + D3D10_MAP map_type, + unsigned map_flags, + void **out_data) + { + D3D10_MAPPED_SUBRESOURCE msr; + HRESULT hr = device->Map(this, subresource, map_type, map_flags, &msr); + if(!SUCCEEDED(hr)) + return hr; + *out_data = msr.pData; + return S_OK; + } + + virtual void STDMETHODCALLTYPE Unmap( + unsigned subresource + ) + { + device->Unmap(this, subresource); + } +}; + +struct GalliumD3D10Texture2D : public GalliumD3D10Texture2DBase +{ + GalliumD3D10Texture2D() {} + GalliumD3D10Texture2D(GalliumD3D10Screen* device, struct pipe_resource* resource, const D3D10_TEXTURE2D_DESC& desc, unsigned dxgi_usage) + : GalliumD3D10Texture2DBase(device, resource, desc, dxgi_usage) + {} + + virtual HRESULT STDMETHODCALLTYPE Map( + unsigned subresource, + D3D10_MAP map_type, + unsigned map_flags, + D3D10_MAPPED_TEXTURE2D *out_mapped_subresource) + { + D3D10_MAPPED_SUBRESOURCE msr; + HRESULT hr = device->Map(this, subresource, map_type, map_flags, &msr); + if(!SUCCEEDED(hr)) + return hr; + out_mapped_subresource->pData = msr.pData; + out_mapped_subresource->RowPitch = msr.RowPitch; + return S_OK; + } + + virtual void STDMETHODCALLTYPE Unmap( + unsigned subresource + ) + { + device->Unmap(this, subresource); + } +}; + + +struct GalliumD3D10Texture3D : public GalliumD3D10Texture3DBase +{ + GalliumD3D10Texture3D(GalliumD3D10Screen* device, struct pipe_resource* resource, const D3D10_TEXTURE3D_DESC& desc, unsigned dxgi_usage) + : GalliumD3D10Texture3DBase(device, resource, desc, dxgi_usage) + {} + + virtual HRESULT STDMETHODCALLTYPE Map( + unsigned subresource, + D3D10_MAP map_type, + unsigned map_flags, + D3D10_MAPPED_TEXTURE3D *out_mapped_subresource) + { + D3D10_MAPPED_SUBRESOURCE msr; + HRESULT hr = device->Map(this, subresource, map_type, map_flags, &msr); + if(!SUCCEEDED(hr)) + return hr; + out_mapped_subresource->pData = msr.pData; + out_mapped_subresource->RowPitch = msr.RowPitch; + out_mapped_subresource->DepthPitch = msr.DepthPitch; + return S_OK; + } + + virtual void STDMETHODCALLTYPE Unmap( + unsigned subresource + ) + { + device->Unmap(this, subresource); + } +}; +#endif + +struct GalliumD3D11Surface : public GalliumMultiPrivateDataComObject +{ + GalliumD3D11Surface(GalliumD3D11Screen* device, struct pipe_resource* resource, const D3D11_TEXTURE2D_DESC& desc, unsigned dxgi_usage) + { + this->device = device; + this->device->AddRef(); + this->resource = resource; + this->desc = desc; + this->dxgi_usage = dxgi_usage; + } + + virtual HRESULT STDMETHODCALLTYPE GetDesc( + DXGI_SURFACE_DESC *out_desc) + { + out_desc->Format = this->desc.Format; + out_desc->Width = this->desc.Width; + out_desc->Height = this->desc.Height; + out_desc->SampleDesc = this->desc.SampleDesc; + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE GetParent( + REFIID riid, + void **out_parent) + { + if(!device) + return E_NOINTERFACE; + return device->QueryInterface(riid, out_parent); + } + + /* TODO: somehow implement these */ + virtual HRESULT STDMETHODCALLTYPE GetDC( + BOOL discard, + HDC *out_hdc) + { + *out_hdc = 0; + return E_NOTIMPL; + } + + virtual HRESULT STDMETHODCALLTYPE ReleaseDC( + RECT *out_dirty_rect) + { + return E_NOTIMPL; + } + + virtual HRESULT STDMETHODCALLTYPE Map( + DXGI_MAPPED_RECT *out_locked_rect, + unsigned map_flags) + { + D3D11_MAP d3d_map; + if(map_flags & DXGI_MAP_DISCARD) + d3d_map = D3D11_MAP_WRITE_DISCARD; + else + { + if(map_flags & DXGI_MAP_READ) + { + if(map_flags & DXGI_MAP_WRITE) + d3d_map = D3D11_MAP_READ_WRITE; + else + d3d_map = D3D11_MAP_READ; + } + else + d3d_map = D3D11_MAP_WRITE; + } + D3D11_MAPPED_SUBRESOURCE d3d_mapped; + HRESULT hres = this->device->get_immediate_context()->Map(this, 0, d3d_map, 0, &d3d_mapped); + out_locked_rect->pBits = (uint8_t*)d3d_mapped.pData; + out_locked_rect->Pitch = d3d_mapped.RowPitch; + return hres; + } + + virtual HRESULT STDMETHODCALLTYPE Unmap(void) + { + this->device->get_immediate_context()->Unmap(this, 0); + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE GetDevice( + REFIID riid, + void **out_parent) + { + if(!device) + return E_NOINTERFACE; + return device->QueryInterface(riid, out_parent); + } +}; + +template +struct GalliumD3D11View : public GalliumD3D11DescribedObject +{ + GalliumD3D11Resource<>* resource; + GalliumD3D11View(GalliumD3D11Screen* device, GalliumD3D11Resource<>* resource, Object* object, const Desc& desc) + : GalliumD3D11DescribedObject(device, object, desc), resource(resource) + { + resource->AddRef(); + } + + ~GalliumD3D11View() + { + resource->Release(); + } + + virtual void STDMETHODCALLTYPE GetResource(ID3D11Resource** out_resource) + { + resource->AddRef(); + *out_resource = resource; + } +}; + +typedef GalliumD3D11View GalliumD3D11DepthStencilView; +typedef GalliumD3D11View GalliumD3D11RenderTargetView; + +#if API >= 11 +typedef GalliumD3D11View GalliumD3D11ShaderResourceView; +#else +typedef GalliumD3D10View GalliumD3D10ShaderResourceViewBase; + +struct GalliumD3D10ShaderResourceView : public GalliumD3D10ShaderResourceViewBase +{ + GalliumD3D10ShaderResourceView(GalliumD3D10Screen* device, GalliumD3D10Resource<>* resource, struct pipe_sampler_view* view, const D3D10_SHADER_RESOURCE_VIEW_DESC1& desc) + : GalliumD3D10ShaderResourceViewBase(device, resource, view, desc) + {} + + virtual void STDMETHODCALLTYPE GetDesc1(D3D10_SHADER_RESOURCE_VIEW_DESC1 *out_desc) + { + memcpy(out_desc, &desc, sizeof(*out_desc)); + } + + virtual void STDMETHODCALLTYPE GetDesc(D3D10_SHADER_RESOURCE_VIEW_DESC *out_desc) + { + memcpy(out_desc, &desc, sizeof(*out_desc)); + } +}; +#endif + +template +struct GalliumD3D11Asynchronous : public GalliumD3D11DeviceChild +{ + struct pipe_query* query; + unsigned data_size; + + GalliumD3D11Asynchronous(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size) + : GalliumD3D11DeviceChild(device), query(query), data_size(data_size) + {} + + ~GalliumD3D11Asynchronous() + { + this->device->immediate_pipe->destroy_query(this->device->immediate_pipe, query); + } + + virtual unsigned STDMETHODCALLTYPE GetDataSize() + { + return data_size; + } + +#if API < 11 + virtual void STDMETHODCALLTYPE Begin() + { + this->device->Begin(this); + } + + virtual void STDMETHODCALLTYPE End() + { + this->device->End(this); + } + + virtual HRESULT STDMETHODCALLTYPE GetData( + void * out_data, + unsigned data_size, + unsigned get_data_flags) + { + return this->device->GetData(this, out_data, data_size, get_data_flags); + } +#endif +}; + +template +struct GalliumD3D11QueryOrPredicate : public GalliumD3D11Asynchronous +{ + D3D11_QUERY_DESC desc; + GalliumD3D11QueryOrPredicate(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size, const D3D11_QUERY_DESC& desc) + : GalliumD3D11Asynchronous(device, query, data_size), desc(desc) + {} + + virtual void STDMETHODCALLTYPE GetDesc( + D3D11_QUERY_DESC *out_desc) + { + *out_desc = desc; + } +}; + +struct GalliumD3D11Query : public GalliumD3D11QueryOrPredicate +{ + GalliumD3D11Query(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size, const D3D11_QUERY_DESC& desc) + : GalliumD3D11QueryOrPredicate(device, query, data_size, desc) + {} +}; + +struct GalliumD3D11Predicate : public GalliumD3D11QueryOrPredicate +{ + GalliumD3D11Predicate(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size, const D3D11_QUERY_DESC& desc) + : GalliumD3D11QueryOrPredicate(device, query, data_size, desc) + {} + + ~GalliumD3D11Predicate() + { + DX10_ONLY(device->UnbindPredicate(this)); + } +}; + +struct GalliumD3D11Counter : public GalliumD3D11Asynchronous +{ + D3D11_COUNTER_DESC desc; + GalliumD3D11Counter(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size, const D3D11_COUNTER_DESC& desc) + : GalliumD3D11Asynchronous(device, query, data_size), desc(desc) + {} + + virtual void STDMETHODCALLTYPE GetDesc( + D3D11_COUNTER_DESC *out_desc) + { + *out_desc = desc; + } +}; diff --git a/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_screen.h b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_screen.h new file mode 100644 index 0000000..9cfdc83 --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_screen.h @@ -0,0 +1,1455 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +DEBUG_GET_ONCE_BOOL_OPTION(dump_shaders, "D3D1X_DUMP_SHADERS", FALSE); + +/* These cap sets are much more correct than the ones in u_caps.c */ +/* TODO: it seems cube levels should be the same as 2D levels */ + +/* DX 9_1 */ +static unsigned caps_dx_9_1[] = { + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1), + UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */ + UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 8), /* 256 */ + UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */ + UTIL_CHECK_TERMINATE +}; + +/* DX 9_2 */ +static unsigned caps_dx_9_2[] = { + UTIL_CHECK_CAP(OCCLUSION_QUERY), + UTIL_CHECK_CAP(TWO_SIDED_STENCIL), + UTIL_CHECK_CAP(TEXTURE_MIRROR_CLAMP), + UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE), + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1), + UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */ + UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */ + UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */ + UTIL_CHECK_TERMINATE +}; + +/* DX 9_3 */ +static unsigned caps_dx_9_3[] = { + UTIL_CHECK_CAP(OCCLUSION_QUERY), + UTIL_CHECK_CAP(TWO_SIDED_STENCIL), + UTIL_CHECK_CAP(TEXTURE_MIRROR_CLAMP), + UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE), + UTIL_CHECK_CAP(SM3), + //UTIL_CHECK_CAP(INSTANCING), + UTIL_CHECK_CAP(OCCLUSION_QUERY), + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 4), + UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 13), /* 4096 */ + UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */ + UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */ + UTIL_CHECK_TERMINATE +}; + + +// this is called "screen" because in the D3D10 case it's only part of the device +template +struct GalliumD3D11ScreenImpl : public GalliumD3D11Screen +{ + D3D_FEATURE_LEVEL feature_level; + int format_support[PIPE_FORMAT_COUNT]; + unsigned creation_flags; + unsigned exception_mode; + maybe_mutex_t mutex; + +/* TODO: Direct3D 11 specifies that fine-grained locking should be used if the driver supports it. + * Right now, I don't trust Gallium drivers to get this right. + */ +#define SYNCHRONIZED lock_t > lock_(mutex) + + GalliumD3D11ScreenImpl(struct pipe_screen* screen, struct pipe_context* immediate_pipe, BOOL owns_immediate_pipe,unsigned creation_flags, IDXGIAdapter* adapter) + : GalliumD3D11Screen(screen, immediate_pipe, adapter), creation_flags(creation_flags) + { + memset(&screen_caps, 0, sizeof(screen_caps)); + screen_caps.gs = screen->get_shader_param(screen, PIPE_SHADER_GEOMETRY, PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0; + screen_caps.so = !!screen->get_param(screen, PIPE_CAP_STREAM_OUTPUT); + screen_caps.queries = screen->get_param(screen, PIPE_CAP_OCCLUSION_QUERY); + screen_caps.render_condition = screen_caps.queries; + for(unsigned i = 0; i < PIPE_SHADER_TYPES; ++i) + screen_caps.constant_buffers[i] = screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_CONST_BUFFERS); + screen_caps.stages = 0; + for(unsigned i = 0; i < PIPE_SHADER_TYPES; ++i) + { + if(!screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_INSTRUCTIONS)) + break; + screen_caps.stages = i + 1; + } + + screen_caps.stages_with_sampling = (1 << screen_caps.stages) - 1; + if(!screen->get_param(screen, PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS)) + screen_caps.stages_with_sampling &=~ (1 << PIPE_SHADER_VERTEX); + + memset(format_support, 0xff, sizeof(format_support)); + + float default_level; + /* don't even attempt to autodetect D3D10 level support, since it's just not fully implemented yet */ + if(util_check_caps(screen, caps_dx_9_3)) + default_level = 9.3; + else if(util_check_caps(screen, caps_dx_9_2)) + default_level = 9.2; + else if(util_check_caps(screen, caps_dx_9_1)) + default_level = 9.1; + else + { + _debug_printf("Warning: driver does not even meet D3D_FEATURE_LEVEL_9_1 features, advertising it anyway!\n"); + default_level = 9.1; + } + + char default_level_name[64]; + sprintf(default_level_name, "%.1f", default_level); + float feature_level_number = atof(debug_get_option("D3D11_FEATURE_LEVEL", default_level_name)); + if(!feature_level_number) + feature_level_number = default_level; + +#if API >= 11 + if(feature_level_number >= 11.0f) + feature_level = D3D_FEATURE_LEVEL_11_0; + else +#endif + if(feature_level_number >= 10.1f) + feature_level = D3D_FEATURE_LEVEL_10_1; + else if(feature_level_number >= 10.0f) + feature_level = D3D_FEATURE_LEVEL_10_0; + else if(feature_level_number >= 9.3f) + feature_level = D3D_FEATURE_LEVEL_9_3; + else if(feature_level_number >= 9.2f) + feature_level = D3D_FEATURE_LEVEL_9_2; + else + feature_level = D3D_FEATURE_LEVEL_9_1; + +#if API >= 11 + immediate_context = GalliumD3D11ImmediateDeviceContext_Create(this, immediate_pipe, owns_immediate_pipe); + // release to the reference to ourselves that the immediate context took, to avoid a garbage cycle + immediate_context->Release(); +#endif + } + + ~GalliumD3D11ScreenImpl() + { +#if API >= 11 + GalliumD3D11ImmediateDeviceContext_Destroy(immediate_context); +#endif + } + + virtual D3D_FEATURE_LEVEL STDMETHODCALLTYPE GetFeatureLevel(void) + { + return feature_level; + } + + virtual unsigned STDMETHODCALLTYPE GetCreationFlags(void) + { + return creation_flags; + } + + virtual HRESULT STDMETHODCALLTYPE GetDeviceRemovedReason(void) + { + return S_OK; + } + +#if API >= 11 + virtual void STDMETHODCALLTYPE GetImmediateContext( + ID3D11DeviceContext **out_immediate_context) + { + immediate_context->AddRef(); + *out_immediate_context = immediate_context; + } +#endif + + virtual HRESULT STDMETHODCALLTYPE SetExceptionMode(unsigned RaiseFlags) + { + exception_mode = RaiseFlags; + return S_OK; + } + + virtual unsigned STDMETHODCALLTYPE GetExceptionMode(void) + { + return exception_mode; + } + + virtual HRESULT STDMETHODCALLTYPE CheckCounter( + const D3D11_COUNTER_DESC *desc, + D3D11_COUNTER_TYPE *type, + unsigned *active_counters, + LPSTR sz_name, + unsigned *name_length, + LPSTR sz_units, + unsigned *units_length, + LPSTR sz_description, + unsigned *description_length) + { + return E_NOTIMPL; + } + + virtual void STDMETHODCALLTYPE CheckCounterInfo( + D3D11_COUNTER_INFO *counter_info) + { + /* none supported at the moment */ + counter_info->LastDeviceDependentCounter = (D3D11_COUNTER)0; + counter_info->NumDetectableParallelUnits = 1; + counter_info->NumSimultaneousCounters = 0; + } + +#if API >= 11 + virtual HRESULT STDMETHODCALLTYPE CheckFeatureSupport( + D3D11_FEATURE feature, + void *out_feature_support_data, + unsigned feature_support_data_size) + { + SYNCHRONIZED; + + switch(feature) + { + case D3D11_FEATURE_THREADING: + { + D3D11_FEATURE_DATA_THREADING* data = (D3D11_FEATURE_DATA_THREADING*)out_feature_support_data; + if(feature_support_data_size != sizeof(*data)) + return E_INVALIDARG; + + data->DriverCommandLists = FALSE; + data->DriverConcurrentCreates = FALSE; + return S_OK; + } + case D3D11_FEATURE_DOUBLES: + { + D3D11_FEATURE_DATA_DOUBLES* data = (D3D11_FEATURE_DATA_DOUBLES*)out_feature_support_data; + if(feature_support_data_size != sizeof(*data)) + return E_INVALIDARG; + + data->DoublePrecisionFloatShaderOps = FALSE; + return S_OK; + } + case D3D11_FEATURE_FORMAT_SUPPORT: + { + D3D11_FEATURE_DATA_FORMAT_SUPPORT* data = (D3D11_FEATURE_DATA_FORMAT_SUPPORT*)out_feature_support_data; + if(feature_support_data_size != sizeof(*data)) + return E_INVALIDARG; + + return this->CheckFormatSupport(data->InFormat, &data->OutFormatSupport); + } + case D3D11_FEATURE_FORMAT_SUPPORT2: + { + D3D11_FEATURE_DATA_FORMAT_SUPPORT* data = (D3D11_FEATURE_DATA_FORMAT_SUPPORT*)out_feature_support_data; + if(feature_support_data_size != sizeof(*data)) + return E_INVALIDARG; + + data->OutFormatSupport = 0; + /* TODO: should this be S_OK? */ + return E_INVALIDARG; + } + case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS: + { + D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS* data = (D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS*)out_feature_support_data; + if(feature_support_data_size != sizeof(*data)) + return E_INVALIDARG; + + data->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x = FALSE; + return S_OK; + } + default: + return E_INVALIDARG; + } + } +#endif + + virtual HRESULT STDMETHODCALLTYPE CheckFormatSupport( + DXGI_FORMAT dxgi_format, + unsigned *out_format_support + ) + { + SYNCHRONIZED; + + /* TODO: MSAA, advanced features */ + pipe_format format = dxgi_to_pipe_format[dxgi_format]; + if(!format) + return E_INVALIDARG; + + int support = format_support[format]; + if(support < 0) + { + support = 0; + unsigned buffer = D3D11_FORMAT_SUPPORT_BUFFER | D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER | D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER; + unsigned sampler_view = D3D11_FORMAT_SUPPORT_SHADER_SAMPLE | D3D11_FORMAT_SUPPORT_MIP | D3D11_FORMAT_SUPPORT_MIP_AUTOGEN; + if(util_format_is_depth_or_stencil(format)) + sampler_view |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON; + + /* TODO: do this properly when Gallium drivers actually support index/vertex format queries */ + if(screen->is_format_supported(screen, format, PIPE_BUFFER, 0, PIPE_BIND_VERTEX_BUFFER, 0) + || (screen->is_format_supported(screen, format, PIPE_BUFFER, 0, PIPE_BIND_INDEX_BUFFER, 0) + || format == PIPE_FORMAT_R8_UNORM)) + support |= buffer; + if(screen->is_format_supported(screen, format, PIPE_BUFFER, 0, PIPE_BIND_STREAM_OUTPUT, 0)) + support |= buffer | D3D11_FORMAT_SUPPORT_SO_BUFFER; + if(screen->is_format_supported(screen, format, PIPE_TEXTURE_1D, 0, PIPE_BIND_SAMPLER_VIEW, 0)) + support |= D3D11_FORMAT_SUPPORT_TEXTURE1D | sampler_view; + if(screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW, 0)) + support |= D3D11_FORMAT_SUPPORT_TEXTURE2D | sampler_view; + if(screen->is_format_supported(screen, format, PIPE_TEXTURE_CUBE, 0, PIPE_BIND_SAMPLER_VIEW, 0)) + support |= D3D11_FORMAT_SUPPORT_TEXTURE2D | sampler_view; + if(screen->is_format_supported(screen, format, PIPE_TEXTURE_3D, 0, PIPE_BIND_SAMPLER_VIEW, 0)) + support |= D3D11_FORMAT_SUPPORT_TEXTURE3D | sampler_view; + if(screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, PIPE_BIND_RENDER_TARGET, 0)) + support |= D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_RENDER_TARGET | D3D11_FORMAT_SUPPORT_BLENDABLE; + if(screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, PIPE_BIND_DEPTH_STENCIL, 0)) + support |= D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_DEPTH_STENCIL; + if(screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, PIPE_BIND_DISPLAY_TARGET, 0)) + support |= D3D11_FORMAT_SUPPORT_DISPLAY; + format_support[format] = support; + } + *out_format_support = support; + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE CheckMultisampleQualityLevels( + DXGI_FORMAT format, + unsigned sample_count, + unsigned *pcount + ) + { + SYNCHRONIZED; + + if(sample_count == 1) + *pcount = 1; + else + *pcount = 0; + return S_OK; + } + + template + bool convert_blend_state(T& to, const U& from, unsigned BlendEnable, unsigned RenderTargetWriteMask) + { + if(invalid(0 + || from.SrcBlend >= D3D11_BLEND_COUNT + || from.SrcBlendAlpha >= D3D11_BLEND_COUNT + || from.DestBlend >= D3D11_BLEND_COUNT + || from.DestBlendAlpha >= D3D11_BLEND_COUNT + || from.BlendOp >= 6 + || from.BlendOpAlpha >= 6 + || !from.BlendOp + || !from.BlendOpAlpha + )) + return false; + + to.blend_enable = BlendEnable; + + to.rgb_func = from.BlendOp - 1; + to.alpha_func = from.BlendOpAlpha - 1; + + to.rgb_src_factor = d3d11_to_pipe_blend[from.SrcBlend]; + to.alpha_src_factor = d3d11_to_pipe_blend[from.SrcBlendAlpha]; + to.rgb_dst_factor = d3d11_to_pipe_blend[from.DestBlend]; + to.alpha_dst_factor = d3d11_to_pipe_blend[from.DestBlendAlpha]; + + to.colormask = RenderTargetWriteMask & 0xf; + return true; + } + +#if API >= 11 + virtual HRESULT STDMETHODCALLTYPE CreateBlendState( + const D3D11_BLEND_DESC *blend_state_desc, + ID3D11BlendState **out_blend_state + ) +#else + virtual HRESULT STDMETHODCALLTYPE CreateBlendState1( + const D3D10_BLEND_DESC1 *blend_state_desc, + ID3D10BlendState1 **out_blend_state + ) +#endif + { + SYNCHRONIZED; + + pipe_blend_state state; + memset(&state, 0, sizeof(state)); + state.alpha_to_coverage = !!blend_state_desc->AlphaToCoverageEnable; + state.independent_blend_enable = !!blend_state_desc->IndependentBlendEnable; + assert(PIPE_MAX_COLOR_BUFS >= 8); + for(unsigned i = 0; i < 8; ++i) + { + if(!convert_blend_state( + state.rt[i], + blend_state_desc->RenderTarget[i], + blend_state_desc->RenderTarget[i].BlendEnable, + blend_state_desc->RenderTarget[i].RenderTargetWriteMask)) + return E_INVALIDARG; + } + + if(!out_blend_state) + return S_FALSE; + + void* object = immediate_pipe->create_blend_state(immediate_pipe, &state); + if(!object) + return E_FAIL; + + *out_blend_state = new GalliumD3D11BlendState(this, object, *blend_state_desc); + return S_OK; + } + +#if API < 11 + virtual HRESULT STDMETHODCALLTYPE CreateBlendState( + const D3D10_BLEND_DESC *blend_state_desc, + ID3D10BlendState **out_blend_state + ) + { + SYNCHRONIZED; + + pipe_blend_state state; + memset(&state, 0, sizeof(state)); + state.alpha_to_coverage = !!blend_state_desc->AlphaToCoverageEnable; + assert(PIPE_MAX_COLOR_BUFS >= 8); + for(unsigned i = 0; i < 8; ++i) + { + if(!convert_blend_state( + state.rt[i], + *blend_state_desc, + blend_state_desc->BlendEnable[i], + blend_state_desc->RenderTargetWriteMask[i])) + return E_INVALIDARG; + } + + for(unsigned i = 1; i < 8; ++i) + { + if(memcmp(&state.rt[0], &state.rt[i], sizeof(state.rt[0]))) + { + state.independent_blend_enable = TRUE; + break; + } + } + + void* object = immediate_pipe->create_blend_state(immediate_pipe, &state); + if(!object) + return E_FAIL; + + *out_blend_state = new GalliumD3D11BlendState(this, object, *blend_state_desc); + return S_OK; + } +#endif + + virtual HRESULT STDMETHODCALLTYPE CreateDepthStencilState( + const D3D11_DEPTH_STENCIL_DESC *depth_stencil_state_desc, + ID3D11DepthStencilState **depth_stencil_state + ) + { + SYNCHRONIZED; + + pipe_depth_stencil_alpha_state state; + memset(&state, 0, sizeof(state)); + state.depth.enabled = !!depth_stencil_state_desc->DepthEnable; + state.depth.writemask = depth_stencil_state_desc->DepthWriteMask; + state.depth.func = depth_stencil_state_desc->DepthFunc - 1; + state.stencil[0].enabled = !!depth_stencil_state_desc->StencilEnable; + state.stencil[0].writemask = depth_stencil_state_desc->StencilWriteMask; + state.stencil[0].valuemask = depth_stencil_state_desc->StencilReadMask; + state.stencil[0].zpass_op = d3d11_to_pipe_stencil_op[depth_stencil_state_desc->FrontFace.StencilPassOp]; + state.stencil[0].fail_op = d3d11_to_pipe_stencil_op[depth_stencil_state_desc->FrontFace.StencilFailOp]; + state.stencil[0].zfail_op = d3d11_to_pipe_stencil_op[depth_stencil_state_desc->FrontFace.StencilDepthFailOp]; + state.stencil[0].func = depth_stencil_state_desc->FrontFace.StencilFunc - 1; + state.stencil[1].enabled = !!depth_stencil_state_desc->StencilEnable; + state.stencil[1].writemask = depth_stencil_state_desc->StencilWriteMask; + state.stencil[1].valuemask = depth_stencil_state_desc->StencilReadMask; + state.stencil[1].zpass_op = d3d11_to_pipe_stencil_op[depth_stencil_state_desc->BackFace.StencilPassOp]; + state.stencil[1].fail_op = d3d11_to_pipe_stencil_op[depth_stencil_state_desc->BackFace.StencilFailOp]; + state.stencil[1].zfail_op = d3d11_to_pipe_stencil_op[depth_stencil_state_desc->BackFace.StencilDepthFailOp]; + state.stencil[1].func = depth_stencil_state_desc->BackFace.StencilFunc - 1; + + if(!depth_stencil_state) + return S_FALSE; + + void* object = immediate_pipe->create_depth_stencil_alpha_state(immediate_pipe, &state); + if(!object) + return E_FAIL; + + *depth_stencil_state = new GalliumD3D11DepthStencilState(this, object, *depth_stencil_state_desc); + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE CreateRasterizerState( + const D3D11_RASTERIZER_DESC *rasterizer_desc, + ID3D11RasterizerState **out_rasterizer_state) + { + SYNCHRONIZED; + + pipe_rasterizer_state state; + memset(&state, 0, sizeof(state)); + state.gl_rasterization_rules = 1; /* D3D10/11 use GL rules */ + state.fill_front = state.fill_back = (rasterizer_desc->FillMode == D3D11_FILL_WIREFRAME) ? PIPE_POLYGON_MODE_LINE : PIPE_POLYGON_MODE_FILL; + if(rasterizer_desc->CullMode == D3D11_CULL_FRONT) + state.cull_face = PIPE_FACE_FRONT; + else if(rasterizer_desc->CullMode == D3D11_CULL_BACK) + state.cull_face = PIPE_FACE_BACK; + else + state.cull_face = PIPE_FACE_NONE; + state.front_ccw = !!rasterizer_desc->FrontCounterClockwise; + /* TODO: is this correct? */ + /* TODO: we are ignoring depthBiasClamp! */ + state.offset_tri = state.offset_line = state.offset_point = rasterizer_desc->SlopeScaledDepthBias || rasterizer_desc->DepthBias; + state.offset_scale = rasterizer_desc->SlopeScaledDepthBias; + state.offset_units = rasterizer_desc->DepthBias; + state.scissor = !!rasterizer_desc->ScissorEnable; + state.multisample = !!rasterizer_desc->MultisampleEnable; + state.line_smooth = !!rasterizer_desc->AntialiasedLineEnable; + + /* TODO: is this correct? */ + state.point_quad_rasterization = 1; + + if(!out_rasterizer_state) + return S_FALSE; + + void* object = immediate_pipe->create_rasterizer_state(immediate_pipe, &state); + if(!object) + return E_FAIL; + + *out_rasterizer_state = new GalliumD3D11RasterizerState(this, object, *rasterizer_desc, !rasterizer_desc->DepthClipEnable); + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE CreateSamplerState( + const D3D11_SAMPLER_DESC *sampler_desc, + ID3D11SamplerState **out_sampler_state) + { + SYNCHRONIZED; + + pipe_sampler_state state; + memset(&state, 0, sizeof(state)); + state.normalized_coords = 1; + state.min_mip_filter = (sampler_desc->Filter & 1); + state.mag_img_filter = ((sampler_desc->Filter >> 2) & 1); + state.min_img_filter = ((sampler_desc->Filter >> 4) & 1); + if(sampler_desc->Filter & 0x40) + state.max_anisotropy = sampler_desc->MaxAnisotropy; + if(sampler_desc->Filter & 0x80) + { + state.compare_mode = PIPE_TEX_COMPARE_R_TO_TEXTURE; + state.compare_func = sampler_desc->ComparisonFunc; + } + state.wrap_s = d3d11_to_pipe_wrap[sampler_desc->AddressU]; + state.wrap_t = d3d11_to_pipe_wrap[sampler_desc->AddressV]; + state.wrap_r = d3d11_to_pipe_wrap[sampler_desc->AddressW]; + state.lod_bias = sampler_desc->MipLODBias; + memcpy(state.border_color, sampler_desc->BorderColor, sizeof(state.border_color)); + state.min_lod = sampler_desc->MinLOD; + state.max_lod = sampler_desc->MaxLOD; + + if(!out_sampler_state) + return S_FALSE; + + void* object = immediate_pipe->create_sampler_state(immediate_pipe, &state); + if(!object) + return E_FAIL; + + *out_sampler_state = new GalliumD3D11SamplerState(this, object, *sampler_desc); + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE CreateInputLayout( + const D3D11_INPUT_ELEMENT_DESC *input_element_descs, + unsigned count, + const void *shader_bytecode_with_input_signature, + SIZE_T bytecode_length, + ID3D11InputLayout **out_input_layout) + { + SYNCHRONIZED; + + if(count > D3D11_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT) + return E_INVALIDARG; + assert(D3D11_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT <= PIPE_MAX_ATTRIBS); + + // putting semantics matching in the core API seems to be a (minor) design mistake + + struct dxbc_chunk_signature* sig = dxbc_find_signature(shader_bytecode_with_input_signature, bytecode_length, false); + D3D11_SIGNATURE_PARAMETER_DESC* params; + unsigned num_params = dxbc_parse_signature(sig, ¶ms); + + typedef std::unordered_map, unsigned> semantic_to_idx_map_t; + semantic_to_idx_map_t semantic_to_idx_map; + for(unsigned i = 0; i < count; ++i) + semantic_to_idx_map[std::make_pair(c_string(input_element_descs[i].SemanticName), input_element_descs[i].SemanticIndex)] = i; + + struct pipe_vertex_element elements[D3D11_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT]; + + unsigned num_params_to_use = std::min(num_params, (unsigned)D3D11_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT); + for(unsigned i = 0; i < num_params_to_use; ++i) + { + int idx = -1; + semantic_to_idx_map_t::iterator iter = semantic_to_idx_map.find(std::make_pair(c_string(params[i].SemanticName), params[i].SemanticIndex)); + if(iter != semantic_to_idx_map.end()) + idx = iter->second; + + // TODO: I kind of doubt Gallium drivers will like null elements; should we do something about it, either here, in the interface, or in the drivers? + // TODO: also, in which cases should we return errors? (i.e. duplicate semantics in vs, duplicate semantics in layout, unmatched semantic in vs, unmatched semantic in layout) + memset(&elements[i], 0, sizeof(elements[i])); + if(idx >= 0) + { + elements[i].src_format = dxgi_to_pipe_format[input_element_descs[idx].Format]; + elements[i].src_offset = input_element_descs[idx].AlignedByteOffset; + elements[i].vertex_buffer_index = input_element_descs[idx].InputSlot; + elements[i].instance_divisor = input_element_descs[idx].InstanceDataStepRate; + } + } + + free(params); + + if(!out_input_layout) + return S_FALSE; + + void* object = immediate_pipe->create_vertex_elements_state(immediate_pipe, num_params_to_use, elements); + if(!object) + return E_FAIL; + + *out_input_layout = new GalliumD3D11InputLayout(this, object); + return S_OK; + } + + static unsigned d3d11_to_pipe_bind_flags(unsigned bind_flags) + { + unsigned bind = 0; + if(bind_flags & D3D11_BIND_VERTEX_BUFFER) + bind |= PIPE_BIND_VERTEX_BUFFER; + if(bind_flags & D3D11_BIND_INDEX_BUFFER) + bind |= PIPE_BIND_INDEX_BUFFER; + if(bind_flags & D3D11_BIND_CONSTANT_BUFFER) + bind |= PIPE_BIND_CONSTANT_BUFFER; + if(bind_flags & D3D11_BIND_SHADER_RESOURCE) + bind |= PIPE_BIND_SAMPLER_VIEW; + if(bind_flags & D3D11_BIND_STREAM_OUTPUT) + bind |= PIPE_BIND_STREAM_OUTPUT; + if(bind_flags & D3D11_BIND_RENDER_TARGET) + bind |= PIPE_BIND_RENDER_TARGET; + if(bind_flags & D3D11_BIND_DEPTH_STENCIL) + bind |= PIPE_BIND_DEPTH_STENCIL; + return bind; + } + + inline HRESULT create_resource( + pipe_texture_target target, + unsigned width, + unsigned height, + unsigned depth, + unsigned mip_levels, + unsigned array_size, + DXGI_FORMAT format, + const DXGI_SAMPLE_DESC* SampleDesc, + D3D11_USAGE usage, + unsigned bind_flags, + unsigned c_p_u_access_flags, + unsigned misc_flags, + const D3D11_SUBRESOURCE_DATA *initial_data, + DXGI_USAGE dxgi_usage, + struct pipe_resource** ppresource + ) + { + if(invalid(format >= DXGI_FORMAT_COUNT)) + return E_INVALIDARG; + if(misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE) + { + if(target != PIPE_TEXTURE_2D) + return E_INVALIDARG; + target = PIPE_TEXTURE_CUBE; + + if(array_size != 6) + return E_NOTIMPL; + } + else + { + if(array_size > 1) + return E_NOTIMPL; + array_size = 1; + } + /* TODO: msaa */ + struct pipe_resource templat; + memset(&templat, 0, sizeof(templat)); + templat.target = target; + templat.width0 = width; + templat.height0 = height; + templat.depth0 = depth; + if(mip_levels) + templat.last_level = mip_levels - 1; + else + templat.last_level = MAX2(MAX2(util_logbase2(templat.width0), util_logbase2(templat.height0)), util_logbase2(templat.depth0)); + templat.format = dxgi_to_pipe_format[format]; + templat.bind = d3d11_to_pipe_bind_flags(bind_flags); + if(c_p_u_access_flags & D3D11_CPU_ACCESS_READ) + templat.bind |= PIPE_BIND_TRANSFER_READ; + if(c_p_u_access_flags & D3D11_CPU_ACCESS_WRITE) + templat.bind |= PIPE_BIND_TRANSFER_WRITE; + if(misc_flags & D3D11_RESOURCE_MISC_SHARED) + templat.bind |= PIPE_BIND_SHARED; + if(misc_flags & D3D11_RESOURCE_MISC_GDI_COMPATIBLE) + templat.bind |= PIPE_BIND_TRANSFER_READ | PIPE_BIND_TRANSFER_WRITE; + if(dxgi_usage & DXGI_USAGE_BACK_BUFFER) + templat.bind |= PIPE_BIND_DISPLAY_TARGET; + templat.usage = d3d11_to_pipe_usage[usage]; + if(invalid(!templat.format)) + return E_NOTIMPL; + + if(!ppresource) + return S_FALSE; + + struct pipe_resource* resource = screen->resource_create(screen, &templat); + if(!resource) + return E_FAIL; + if(initial_data) + { + for(unsigned slice = 0; slice < array_size; ++slice) + { + for(unsigned level = 0; level <= templat.last_level; ++level) + { + struct pipe_box box; + box.x = box.y = 0; + box.z = slice; + box.width = u_minify(width, level); + box.height = u_minify(height, level); + box.depth = 1; + immediate_pipe->transfer_inline_write(immediate_pipe, resource, level, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD | PIPE_TRANSFER_UNSYNCHRONIZED, &box, initial_data->pSysMem, initial_data->SysMemPitch, initial_data->SysMemSlicePitch); + ++initial_data; + } + } + } + *ppresource = resource; + return S_OK; + } + + static unsigned d3d_to_dxgi_usage(unsigned bind, unsigned misc) + { + unsigned dxgi_usage = 0; + if(bind |= D3D11_BIND_RENDER_TARGET) + dxgi_usage |= DXGI_USAGE_RENDER_TARGET_OUTPUT; + if(bind & D3D11_BIND_SHADER_RESOURCE) + dxgi_usage |= DXGI_USAGE_SHADER_INPUT; +#if API >= 11 + if(bind & D3D11_BIND_UNORDERED_ACCESS) + dxgi_usage |= DXGI_USAGE_UNORDERED_ACCESS; +#endif + if(misc & D3D11_RESOURCE_MISC_SHARED) + dxgi_usage |= DXGI_USAGE_SHARED; + return dxgi_usage; + } + + virtual HRESULT STDMETHODCALLTYPE CreateTexture1D( + const D3D11_TEXTURE1D_DESC *desc, + const D3D11_SUBRESOURCE_DATA *initial_data, + ID3D11Texture1D **out_texture1d) + { + SYNCHRONIZED; + + struct pipe_resource* resource; + DXGI_USAGE dxgi_usage = d3d_to_dxgi_usage(desc->BindFlags, desc->MiscFlags); + HRESULT hr = create_resource(PIPE_TEXTURE_1D, desc->Width, 1, 1, desc->MipLevels, desc->ArraySize, desc->Format, 0, desc->Usage, desc->BindFlags, desc->CPUAccessFlags, desc->MiscFlags, initial_data, dxgi_usage, out_texture1d ? &resource : 0); + if(hr != S_OK) + return hr; + D3D11_TEXTURE1D_DESC cdesc = *desc; + cdesc.MipLevels = resource->last_level + 1; + *out_texture1d = new GalliumD3D11Texture1D(this, resource, cdesc, dxgi_usage); + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE CreateTexture2D( + const D3D11_TEXTURE2D_DESC *desc, + const D3D11_SUBRESOURCE_DATA *initial_data, + ID3D11Texture2D **out_texture2d) + { + SYNCHRONIZED; + + struct pipe_resource* resource; + DXGI_USAGE dxgi_usage = d3d_to_dxgi_usage(desc->BindFlags, desc->MiscFlags); + HRESULT hr = create_resource(PIPE_TEXTURE_2D, desc->Width, desc->Height, 1, desc->MipLevels, desc->ArraySize, desc->Format, &desc->SampleDesc, desc->Usage, desc->BindFlags, desc->CPUAccessFlags, desc->MiscFlags, initial_data, dxgi_usage, out_texture2d ? &resource : 0); + if(hr != S_OK) + return hr; + D3D11_TEXTURE2D_DESC cdesc = *desc; + cdesc.MipLevels = resource->last_level + 1; + if(cdesc.MipLevels == 1 && cdesc.ArraySize == 1) + *out_texture2d = new GalliumD3D11Surface(this, resource, cdesc, dxgi_usage); + else + *out_texture2d = new GalliumD3D11Texture2D(this, resource, cdesc, dxgi_usage); + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE CreateTexture3D( + const D3D11_TEXTURE3D_DESC *desc, + const D3D11_SUBRESOURCE_DATA *initial_data, + ID3D11Texture3D **out_texture3d) + { + SYNCHRONIZED; + + struct pipe_resource* resource; + DXGI_USAGE dxgi_usage = d3d_to_dxgi_usage(desc->BindFlags, desc->MiscFlags); + HRESULT hr = create_resource(PIPE_TEXTURE_3D, desc->Width, desc->Height, desc->Depth, desc->MipLevels, 1, desc->Format, 0, desc->Usage, desc->BindFlags, desc->CPUAccessFlags, desc->MiscFlags, initial_data, dxgi_usage, out_texture3d ? &resource : 0); + if(hr != S_OK) + return hr; + D3D11_TEXTURE3D_DESC cdesc = *desc; + cdesc.MipLevels = resource->last_level + 1; + *out_texture3d = new GalliumD3D11Texture3D(this, resource, cdesc, dxgi_usage); + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE CreateBuffer( + const D3D11_BUFFER_DESC *desc, + const D3D11_SUBRESOURCE_DATA *initial_data, + ID3D11Buffer **out_buffer) + { + SYNCHRONIZED; + + struct pipe_resource* resource; + DXGI_USAGE dxgi_usage = d3d_to_dxgi_usage(desc->BindFlags, desc->MiscFlags); + HRESULT hr = create_resource(PIPE_BUFFER, desc->ByteWidth, 1, 1, 1, 1, DXGI_FORMAT_R8_UNORM, 0, desc->Usage, desc->BindFlags, desc->CPUAccessFlags, desc->MiscFlags, initial_data, dxgi_usage, out_buffer ? &resource : 0); + if(hr != S_OK) + return hr; + *out_buffer = new GalliumD3D11Buffer(this, resource, *desc, dxgi_usage); + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE OpenGalliumResource( + struct pipe_resource* resource, + IUnknown** dxgi_resource) + { + SYNCHRONIZED; + + /* TODO: maybe support others */ + assert(resource->target == PIPE_TEXTURE_2D); + *dxgi_resource = 0; + D3D11_TEXTURE2D_DESC desc; + memset(&desc, 0, sizeof(desc)); + desc.Width = resource->width0; + desc.Height = resource->height0; + init_pipe_to_dxgi_format(); + desc.Format = pipe_to_dxgi_format[resource->format]; + desc.SampleDesc.Count = resource->nr_samples; + desc.SampleDesc.Quality = 0; + desc.ArraySize = 1; + desc.MipLevels = resource->last_level + 1; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; + if(resource->bind & PIPE_BIND_RENDER_TARGET) + desc.BindFlags |= D3D11_BIND_RENDER_TARGET; + if(resource->bind & PIPE_BIND_DEPTH_STENCIL) + desc.BindFlags |= D3D11_BIND_DEPTH_STENCIL; + if(resource->bind & PIPE_BIND_SAMPLER_VIEW) + desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE; + if(resource->bind & PIPE_BIND_SHARED) + desc.MiscFlags |= D3D11_RESOURCE_MISC_SHARED; + DXGI_USAGE dxgi_usage = d3d_to_dxgi_usage(desc.BindFlags, desc.MiscFlags); + if(desc.MipLevels == 1 && desc.ArraySize == 1) + *dxgi_resource = (ID3D11Texture2D*)new GalliumD3D11Surface(this, resource, desc, dxgi_usage); + else + *dxgi_resource = (ID3D11Texture2D*)new GalliumD3D11Texture2D(this, resource, desc, dxgi_usage); + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE CreateSurface( + const DXGI_SURFACE_DESC *dxgi_desc, + unsigned count, + DXGI_USAGE usage, + const DXGI_SHARED_RESOURCE *shared_resource, + IDXGISurface **out_surface) + { + SYNCHRONIZED; + + D3D11_TEXTURE2D_DESC desc; + memset(&desc, 0, sizeof(desc)); + + struct pipe_resource* resource; + desc.Width = dxgi_desc->Width; + desc.Height = dxgi_desc->Height; + desc.Format = dxgi_desc->Format; + desc.SampleDesc = dxgi_desc->SampleDesc; + desc.ArraySize = count; + desc.MipLevels = 1; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; + if(usage & DXGI_USAGE_RENDER_TARGET_OUTPUT) + desc.BindFlags |= D3D11_BIND_RENDER_TARGET; + if(usage & DXGI_USAGE_SHADER_INPUT) + desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE; +#if API >= 11 + if(usage & DXGI_USAGE_UNORDERED_ACCESS) + desc.BindFlags |= D3D11_BIND_UNORDERED_ACCESS; +#endif + if(usage & DXGI_USAGE_SHARED) + desc.MiscFlags |= D3D11_RESOURCE_MISC_SHARED; + HRESULT hr = create_resource(PIPE_TEXTURE_2D, dxgi_desc->Width, dxgi_desc->Height, 1, 1, count, dxgi_desc->Format, &dxgi_desc->SampleDesc, D3D11_USAGE_DEFAULT, desc.BindFlags, D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE, desc.MiscFlags, 0, usage, &resource); + if(hr != S_OK) + return hr; + *out_surface = new GalliumD3D11Surface(this, resource, desc, usage); + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE CreateShaderResourceView( + ID3D11Resource *iresource, + const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, + ID3D11ShaderResourceView **out_srv) + { +#if API >= 11 + D3D11_SHADER_RESOURCE_VIEW_DESC def_desc; +#else + if(desc->ViewDimension == D3D10_1_SRV_DIMENSION_TEXTURECUBEARRAY) + return E_INVALIDARG; + D3D10_SHADER_RESOURCE_VIEW_DESC1 desc1; + memset(&desc1, 0, sizeof(desc1)); + memcpy(&desc1, desc, sizeof(*desc)); + return CreateShaderResourceView1(iresource, &desc1, (ID3D10ShaderResourceView1**)out_srv); + } + + virtual HRESULT STDMETHODCALLTYPE CreateShaderResourceView1( + ID3D11Resource *iresource, + const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, + ID3D10ShaderResourceView1 **out_srv) + { + D3D10_SHADER_RESOURCE_VIEW_DESC1 def_desc; +#endif + SYNCHRONIZED; + + if(!desc) + { + struct pipe_resource* resource = ((GalliumD3D11Resource<>*)iresource)->resource; + init_pipe_to_dxgi_format(); + memset(&def_desc, 0, sizeof(def_desc)); + def_desc.Format = pipe_to_dxgi_format[resource->format]; + switch(resource->target) + { + case PIPE_BUFFER: + def_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; + def_desc.Buffer.ElementWidth = resource->width0; + break; + case PIPE_TEXTURE_1D: + def_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D; + def_desc.Texture1D.MipLevels = resource->last_level + 1; + break; + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + def_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + def_desc.Texture2D.MipLevels = resource->last_level + 1; + break; + case PIPE_TEXTURE_3D: + def_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; + def_desc.Texture3D.MipLevels = resource->last_level + 1; + break; + case PIPE_TEXTURE_CUBE: + def_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; + def_desc.TextureCube.MipLevels = resource->last_level + 1; + break; + default: + return E_INVALIDARG; + } + desc = &def_desc; + } + + struct pipe_sampler_view templat; + memset(&templat, 0, sizeof(templat)); + if(invalid(format >= DXGI_FORMAT_COUNT)) + return E_INVALIDARG; + templat.format = dxgi_to_pipe_format[desc->Format]; + if(!templat.format) + return E_NOTIMPL; + templat.swizzle_r = PIPE_SWIZZLE_RED; + templat.swizzle_g = PIPE_SWIZZLE_GREEN; + templat.swizzle_b = PIPE_SWIZZLE_BLUE; + templat.swizzle_a = PIPE_SWIZZLE_ALPHA; + + templat.texture = ((GalliumD3D11Resource<>*)iresource)->resource; + switch(desc->ViewDimension) + { + case D3D11_SRV_DIMENSION_TEXTURE1D: + case D3D11_SRV_DIMENSION_TEXTURE2D: + case D3D11_SRV_DIMENSION_TEXTURE3D: + case D3D11_SRV_DIMENSION_TEXTURE1DARRAY: + case D3D11_SRV_DIMENSION_TEXTURE2DARRAY: + /* yes, this works for all of these types (but TODO: texture arrays) */ + templat.u.tex.first_level = desc->Texture1D.MostDetailedMip; + templat.u.tex.last_level = templat.u.tex.first_level + desc->Texture1D.MipLevels - 1; + break; + case D3D11_SRV_DIMENSION_BUFFER: + case D3D11_SRV_DIMENSION_TEXTURE2DMS: + case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY: + return E_NOTIMPL; + default: + return E_INVALIDARG; + } + + if(!out_srv) + return S_FALSE; + + struct pipe_sampler_view* view = immediate_pipe->create_sampler_view(immediate_pipe, templat.texture, &templat); + if(!view) + return E_FAIL; + *out_srv = new GalliumD3D11ShaderResourceView(this, (GalliumD3D11Resource<>*)iresource, view, *desc); + return S_OK; + } + +#if API >= 11 + virtual HRESULT STDMETHODCALLTYPE CreateUnorderedAccessView( + ID3D11Resource *resource, + const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, + ID3D11UnorderedAccessView **out_uav) + { + SYNCHRONIZED; + + return E_NOTIMPL; + + // remember to return S_FALSE and not crash if out_u_a_view == 0 and parameters are valid + } +#endif + + virtual HRESULT STDMETHODCALLTYPE CreateRenderTargetView( + ID3D11Resource *iresource, + const D3D11_RENDER_TARGET_VIEW_DESC *desc, + ID3D11RenderTargetView **out_rtv) + { + SYNCHRONIZED; + + D3D11_RENDER_TARGET_VIEW_DESC def_desc; + if(!desc) + { + struct pipe_resource* resource = ((GalliumD3D11Resource<>*)iresource)->resource; + init_pipe_to_dxgi_format(); + memset(&def_desc, 0, sizeof(def_desc)); + def_desc.Format = pipe_to_dxgi_format[resource->format]; + switch(resource->target) + { + case PIPE_BUFFER: + def_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER; + def_desc.Buffer.ElementWidth = resource->width0; + break; + case PIPE_TEXTURE_1D: + def_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1D; + break; + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + def_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; + break; + case PIPE_TEXTURE_3D: + def_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D; + def_desc.Texture3D.WSize = resource->depth0; + break; + case PIPE_TEXTURE_CUBE: + def_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; + def_desc.Texture2DArray.ArraySize = 6; + break; + default: + return E_INVALIDARG; + } + desc = &def_desc; + } + + struct pipe_surface templat; + memset(&templat, 0, sizeof(templat)); + if(invalid(desc->format >= DXGI_FORMAT_COUNT)) + return E_INVALIDARG; + templat.format = dxgi_to_pipe_format[desc->Format]; + if(!templat.format) + return E_NOTIMPL; + templat.usage = PIPE_BIND_RENDER_TARGET; + templat.texture = ((GalliumD3D11Resource<>*)iresource)->resource; + + switch(desc->ViewDimension) + { + case D3D11_RTV_DIMENSION_TEXTURE1D: + case D3D11_RTV_DIMENSION_TEXTURE2D: + templat.u.tex.level = desc->Texture1D.MipSlice; + break; + case D3D11_RTV_DIMENSION_TEXTURE3D: + templat.u.tex.level = desc->Texture3D.MipSlice; + templat.u.tex.first_layer = desc->Texture3D.FirstWSlice; + /* XXX FIXME */ + templat.u.tex.last_layer = desc->Texture3D.FirstWSlice; + break; + case D3D11_RTV_DIMENSION_TEXTURE1DARRAY: + case D3D11_RTV_DIMENSION_TEXTURE2DARRAY: + templat.u.tex.level = desc->Texture1DArray.MipSlice; + templat.u.tex.first_layer = desc->Texture1DArray.FirstArraySlice; + /* XXX FIXME */ + templat.u.tex.last_layer = desc->Texture1DArray.FirstArraySlice; + break; + case D3D11_RTV_DIMENSION_BUFFER: + case D3D11_RTV_DIMENSION_TEXTURE2DMS: + case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY: + return E_NOTIMPL; + default: + return E_INVALIDARG; + } + + if(!out_rtv) + return S_FALSE; + + struct pipe_surface* surface = immediate_pipe->create_surface(immediate_pipe, templat.texture, &templat); + if(!surface) + return E_FAIL; + *out_rtv = new GalliumD3D11RenderTargetView(this, (GalliumD3D11Resource<>*)iresource, surface, *desc); + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE CreateDepthStencilView( + ID3D11Resource *iresource, + const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, + ID3D11DepthStencilView **out_depth_stencil_view) + { + SYNCHRONIZED; + + D3D11_DEPTH_STENCIL_VIEW_DESC def_desc; + if(!desc) + { + struct pipe_resource* resource = ((GalliumD3D11Resource<>*)iresource)->resource; + init_pipe_to_dxgi_format(); + memset(&def_desc, 0, sizeof(def_desc)); + def_desc.Format = pipe_to_dxgi_format[resource->format]; + switch(resource->target) + { + case PIPE_TEXTURE_1D: + def_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE1D; + break; + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_RECT: + def_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; + break; + case PIPE_TEXTURE_CUBE: + def_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY; + def_desc.Texture2DArray.ArraySize = 6; + break; + default: + return E_INVALIDARG; + } + desc = &def_desc; + } + + struct pipe_surface templat; + memset(&templat, 0, sizeof(templat)); + if(invalid(desc->format >= DXGI_FORMAT_COUNT)) + return E_INVALIDARG; + templat.format = dxgi_to_pipe_format[desc->Format]; + if(!templat.format) + return E_NOTIMPL; + templat.usage = PIPE_BIND_DEPTH_STENCIL; + templat.texture = ((GalliumD3D11Resource<>*)iresource)->resource; + + switch(desc->ViewDimension) + { + case D3D11_DSV_DIMENSION_TEXTURE1D: + case D3D11_DSV_DIMENSION_TEXTURE2D: + templat.u.tex.level = desc->Texture1D.MipSlice; + break; + case D3D11_DSV_DIMENSION_TEXTURE1DARRAY: + case D3D11_DSV_DIMENSION_TEXTURE2DARRAY: + templat.u.tex.level = desc->Texture1DArray.MipSlice; + templat.u.tex.first_layer = desc->Texture1DArray.FirstArraySlice; + /* XXX FIXME */ + templat.u.tex.last_layer = desc->Texture1DArray.FirstArraySlice; + break; + case D3D11_DSV_DIMENSION_TEXTURE2DMS: + case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY: + return E_NOTIMPL; + default: + return E_INVALIDARG; + } + + if(!out_depth_stencil_view) + return S_FALSE; + + struct pipe_surface* surface = immediate_pipe->create_surface(immediate_pipe, templat.texture, &templat); + if(!surface) + return E_FAIL; + *out_depth_stencil_view = new GalliumD3D11DepthStencilView(this, (GalliumD3D11Resource<>*)iresource, surface, *desc); + return S_OK; + } + + GalliumD3D11Shader<>* create_stage_shader(unsigned type, const void* shader_bytecode, SIZE_T bytecode_length +#if API >= 11 + , ID3D11ClassLinkage *class_linkage +#endif + ) + { + bool dump = debug_get_option_dump_shaders(); + + dxbc_chunk_header* sm4_chunk = dxbc_find_shader_bytecode(shader_bytecode, bytecode_length); + if(!sm4_chunk) + return 0; + + std::auto_ptr sm4(sm4_parse(sm4_chunk + 1, bswap_le32(sm4_chunk->size))); + if(!sm4.get()) + return 0; + + if(dump) + sm4->dump(); + + struct pipe_shader_state tgsi_shader; + memset(&tgsi_shader, 0, sizeof(tgsi_shader)); + tgsi_shader.tokens = (const tgsi_token*)sm4_to_tgsi(*sm4); + if(!tgsi_shader.tokens) + return 0; + + if(dump) + tgsi_dump(tgsi_shader.tokens, 0); + + void* shader_cso; + GalliumD3D11Shader<>* shader; + + switch(type) + { + case PIPE_SHADER_VERTEX: + shader_cso = immediate_pipe->create_vs_state(immediate_pipe, &tgsi_shader); + shader = (GalliumD3D11Shader<>*)new GalliumD3D11VertexShader(this, shader_cso); + break; + case PIPE_SHADER_FRAGMENT: + shader_cso = immediate_pipe->create_fs_state(immediate_pipe, &tgsi_shader); + shader = (GalliumD3D11Shader<>*)new GalliumD3D11PixelShader(this, shader_cso); + break; + case PIPE_SHADER_GEOMETRY: + shader_cso = immediate_pipe->create_gs_state(immediate_pipe, &tgsi_shader); + shader = (GalliumD3D11Shader<>*)new GalliumD3D11GeometryShader(this, shader_cso); + break; + default: + shader_cso = 0; + shader = 0; + break; + } + + if(shader) + { + shader->slot_to_resource = sm4->slot_to_resource; + shader->slot_to_sampler = sm4->slot_to_sampler; + } + + free((void*)tgsi_shader.tokens); + return shader; + } + +#if API >= 11 +#define CREATE_SHADER_ARGS \ + const void *shader_bytecode, \ + SIZE_T bytecode_length, \ + ID3D11ClassLinkage *class_linkage +#define PASS_SHADER_ARGS shader_bytecode, bytecode_length, class_linkage +#else +#define CREATE_SHADER_ARGS \ + const void *shader_bytecode, \ + SIZE_T bytecode_length +#define PASS_SHADER_ARGS shader_bytecode, bytecode_length +#endif + +#define IMPLEMENT_CREATE_SHADER(Stage, GALLIUM) \ + virtual HRESULT STDMETHODCALLTYPE Create##Stage##Shader( \ + CREATE_SHADER_ARGS, \ + ID3D11##Stage##Shader **out_shader) \ + { \ + SYNCHRONIZED; \ + GalliumD3D11##Stage##Shader* shader = (GalliumD3D11##Stage##Shader*)create_stage_shader(PIPE_SHADER_##GALLIUM, PASS_SHADER_ARGS); \ + if(!shader) \ + return E_FAIL; \ + if(out_shader) \ + { \ + *out_shader = shader; \ + return S_OK; \ + } \ + else \ + { \ + shader->Release(); \ + return S_FALSE; \ + } \ + } + +#define IMPLEMENT_NOTIMPL_CREATE_SHADER(Stage) \ + virtual HRESULT STDMETHODCALLTYPE Create##Stage##Shader( \ + CREATE_SHADER_ARGS, \ + ID3D11##Stage##Shader **out_shader) \ + { \ + return E_NOTIMPL; \ + } + + IMPLEMENT_CREATE_SHADER(Vertex, VERTEX) + IMPLEMENT_CREATE_SHADER(Pixel, FRAGMENT) + IMPLEMENT_CREATE_SHADER(Geometry, GEOMETRY) +#if API >= 11 + IMPLEMENT_NOTIMPL_CREATE_SHADER(Hull) + IMPLEMENT_NOTIMPL_CREATE_SHADER(Domain) + IMPLEMENT_NOTIMPL_CREATE_SHADER(Compute) +#endif + + virtual HRESULT STDMETHODCALLTYPE CreateGeometryShaderWithStreamOutput( + const void *shader_bytecode, + SIZE_T bytecode_length, + const D3D11_SO_DECLARATION_ENTRY *so_declaration, + unsigned num_entries, +#if API >= 11 + const unsigned *buffer_strides, + unsigned num_strides, + unsigned rasterized_stream, + ID3D11ClassLinkage *class_linkage, +#else + UINT output_stream_stride, +#endif + ID3D11GeometryShader **out_geometry_shader) + { + SYNCHRONIZED; + + return E_NOTIMPL; + + // remember to return S_FALSE if ppGeometyShader == NULL and the shader is OK + } + +#if API >= 11 + virtual HRESULT STDMETHODCALLTYPE CreateClassLinkage( + ID3D11ClassLinkage **out_linkage) + { + SYNCHRONIZED; + + return E_NOTIMPL; + } +#endif + + virtual HRESULT STDMETHODCALLTYPE CreateQuery( + const D3D11_QUERY_DESC *query_desc, + ID3D11Query **out_query) + { + SYNCHRONIZED; + + if(invalid(query_desc->Query >= D3D11_QUERY_COUNT)) + return E_INVALIDARG; + unsigned query_type = d3d11_to_pipe_query[query_desc->Query]; + if(!query_type) + return E_NOTIMPL; + + if(out_query) + return S_FALSE; + + struct pipe_query* query = immediate_pipe->create_query(immediate_pipe, query_type); + if(!query) + return E_FAIL; + + *out_query = new GalliumD3D11Query(this, query, d3d11_query_size[query_desc->Query], *query_desc); + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE CreatePredicate( + const D3D11_QUERY_DESC *predicate_desc, + ID3D11Predicate **out_predicate) + { + SYNCHRONIZED; + + unsigned query_type; + switch(predicate_desc->Query) + { + case D3D11_QUERY_SO_OVERFLOW_PREDICATE: + return E_NOTIMPL; + case D3D11_QUERY_OCCLUSION_PREDICATE: + query_type = PIPE_QUERY_OCCLUSION_COUNTER; + break; + default: + return E_INVALIDARG; + } + + if(out_predicate) + return S_FALSE; + + struct pipe_query* query = immediate_pipe->create_query(immediate_pipe, query_type); + if(!query) + return E_FAIL; + + *out_predicate = new GalliumD3D11Predicate(this, query, sizeof(BOOL), *predicate_desc); + return S_OK; + } + + + virtual HRESULT STDMETHODCALLTYPE CreateCounter( + const D3D11_COUNTER_DESC *counter_desc, + ID3D11Counter **out_counter) + { + SYNCHRONIZED; + + return E_NOTIMPL; + + // remember to return S_FALSE if out_counter == NULL and everything is OK + } + +#if API >= 11 + virtual HRESULT STDMETHODCALLTYPE CreateDeferredContext( + unsigned context_flags, + ID3D11DeviceContext **out_deferred_context) + { + SYNCHRONIZED; + + // TODO: this will have to be implemented using a new Gallium util module + return E_NOTIMPL; + + // remember to return S_FALSE if out_counter == NULL and everything is OK + } +#endif + + virtual HRESULT STDMETHODCALLTYPE OpenSharedResource( + HANDLE resource, + REFIID iid, + void **out_resource) + { + SYNCHRONIZED; + + // TODO: the problem here is that we need to communicate dimensions somehow + return E_NOTIMPL; + + // remember to return S_FALSE if out_counter == NULL and everything is OK +#if 0 + struct pipe_resou rce templat; + struct winsys_handle handle; + handle.stride = 0; + handle.handle = resource; + handle.type = DRM_API_HANDLE_TYPE_SHARED; + screen->resource_from_handle(screen, &templat, &handle); +#endif + } + +#if API < 11 + /* these are documented as "Not implemented". + * According to the UMDDI documentation, they apparently turn on a + * (width + 1) x (height + 1) convolution filter for 1-bit textures. + * Probably nothing uses these, assuming it has ever been implemented anywhere. + */ + void STDMETHODCALLTYPE SetTextFilterSize( + UINT width, + UINT height + ) + {} + + virtual void STDMETHODCALLTYPE GetTextFilterSize( + UINT *width, + UINT *height + ) + {} +#endif + +#if API >= 11 + virtual void STDMETHODCALLTYPE RestoreGalliumState() + { + GalliumD3D11ImmediateDeviceContext_RestoreGalliumState(immediate_context); + } + + virtual void STDMETHODCALLTYPE RestoreGalliumStateBlitOnly() + { + GalliumD3D11ImmediateDeviceContext_RestoreGalliumStateBlitOnly(immediate_context); + } +#endif + + virtual struct pipe_context* STDMETHODCALLTYPE GetGalliumContext(void) + { + return immediate_pipe; + } + +#undef SYNCHRONIZED +}; diff --git a/src/gallium/state_trackers/d3d1x/gd3d1x/Makefile b/src/gallium/state_trackers/d3d1x/gd3d1x/Makefile new file mode 100644 index 0000000..32d2956 --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/gd3d1x/Makefile @@ -0,0 +1,7 @@ +LIBNAME=gd3d1x +CPP_SOURCES=$(wildcard *.cpp) +LIBRARY_INCLUDES=-Iinclude -I../gd3dapi -I../d3dapi -I../w32api -I../d3d1xstutil/include -I../d3d1xshader/include -I../../../include -I../../../auxiliary -I../../../state_trackers/egl/common +PROGS=tools/dxbc2tgsi +PROGS_DEPS=libgd3d1x.a ../d3d1xshader/libd3d1xshader.a ../d3d1xstutil/libd3d1xstutil.a ../../../auxiliary/libgallium.a +LIBS=$(PROGS_DEPS) -ldl +include ../Makefile.inc diff --git a/src/gallium/state_trackers/d3d1x/gd3d1x/d3d1x_private.h b/src/gallium/state_trackers/d3d1x/gd3d1x/d3d1x_private.h new file mode 100644 index 0000000..977f0cd --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/gd3d1x/d3d1x_private.h @@ -0,0 +1,95 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef D3D1X_PRIVATE_H_ +#define D3D1X_PRIVATE_H_ + +#include +#include +#include +#include + +#include "dxbc.h" +#include "sm4.h" +#include "sm4_to_tgsi.h" + +#include "d3d1xstutil.h" + +#include +#include + +extern "C" +{ +#include +#include +#include +#include +#include +#include +#include +#include +} + +#include "galliumdxgi.h" +#include "galliumd3d10_1.h" +#include "galliumd3d11.h" + +#ifdef CHECK +#define invalid(x) unlikely(x) +#else +#define invalid(x) (0) +#endif + +#define D3D10_STAGE_VS 0 +#define D3D10_STAGE_PS 1 +#define D3D10_STAGE_GS 2 +#define D3D10_STAGES 3 + +#define D3D11_STAGE_VS 0 +#define D3D11_STAGE_PS 1 +#define D3D11_STAGE_GS 2 +#define D3D11_STAGE_HS 3 +#define D3D11_STAGE_DS 4 +#define D3D11_STAGE_CS 5 +#define D3D11_STAGES 6 + +#define D3D11_BLEND_COUNT 20 +extern unsigned d3d11_to_pipe_blend[D3D11_BLEND_COUNT]; + +#define D3D11_USAGE_COUNT 4 +extern unsigned d3d11_to_pipe_usage[D3D11_USAGE_COUNT]; + +#define D3D11_STENCIL_OP_COUNT 9 +extern unsigned d3d11_to_pipe_stencil_op[D3D11_STENCIL_OP_COUNT]; + +#define D3D11_TEXTURE_ADDRESS_COUNT 6 +extern unsigned d3d11_to_pipe_wrap[D3D11_TEXTURE_ADDRESS_COUNT]; + +#define D3D11_QUERY_COUNT 16 +extern unsigned d3d11_to_pipe_query[D3D11_QUERY_COUNT]; +extern unsigned d3d11_query_size[D3D11_QUERY_COUNT]; + +#endif /* D3D1X_H_ */ diff --git a/src/gallium/state_trackers/d3d1x/gd3d1x/sm4_to_tgsi.h b/src/gallium/state_trackers/d3d1x/gd3d1x/sm4_to_tgsi.h new file mode 100644 index 0000000..5722b27 --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/gd3d1x/sm4_to_tgsi.h @@ -0,0 +1,34 @@ +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef SM4_TO_TGSI_H_ +#define SM4_TO_TGSI_H_ + +#include "sm4.h" + +void* sm4_to_tgsi(struct sm4_program& program); + +#endif /* SM4_TO_TGSI_H_ */ diff --git a/src/gallium/state_trackers/d3d1x/gd3dapi/Makefile b/src/gallium/state_trackers/d3d1x/gd3dapi/Makefile new file mode 100644 index 0000000..8b16b1b --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/gd3dapi/Makefile @@ -0,0 +1,4 @@ +all: idl + +include ../Makefile.inc + diff --git a/src/gallium/state_trackers/d3d1x/progs/Makefile b/src/gallium/state_trackers/d3d1x/progs/Makefile new file mode 100644 index 0000000..143e531 --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/progs/Makefile @@ -0,0 +1,46 @@ +LIBRARY_INCLUDES = -Id3d10app -Id3d11app -I../gd3dapi -I../d3dapi -I../w32api +LIBS= \ + ../dxgi/libdxgi.a \ + ../gd3d1x/libgd3d1x.a \ + ../d3d1xshader/libd3d1xshader.a \ + ../d3d1xstutil/libd3d1xstutil.a \ + ../../egl/libegl.a \ + ../../../auxiliary/libgallium.a \ + ../../../winsys/sw/wrapper/libwsw.a \ + ../../../winsys/sw/xlib/libws_xlib.a \ + ../../../winsys/sw/dri/libswdri.a \ + ../../../../../lib/libEGL.so + +LDADD=-ldl + +all: bin/d3d10tri bin/d3d11tri bin/d3d11tex bin/d3d11gears +include ../Makefile.inc + +ifneq ($(findstring fbdev, $(EGL_PLATFORMS)),) +LIBS += ../../../winsys/sw/fbdev/libfbdev.a +endif + +ifneq ($(findstring x11, $(EGL_PLATFORMS)),) +LDADD += -ldrm -lX11 -lXext -lXfixes +LIBS += ../../../winsys/sw/xlib/libws_xlib.a +endif + +ifneq ($(findstring kms, $(EGL_PLATFORMS)),) +LDADD += -ldrm +endif + +LIBS_D3D10 = ../dxgid3d10/libdxgid3d10.a ../gd3d10/libgd3d10.a $(LIBS) +LIBS_D3D11 = ../dxgid3d11/libdxgid3d11.a ../gd3d11/libgd3d11.a $(LIBS) + +bin/d3d10tri: d3d10app/d3d10x11main.o d3d10tri/d3d10tri.o $(LIBS_D3D10) + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS_D3D10) -Wl,--end-group $(LDADD) + +bin/d3d11tri: d3d11app/d3d11x11main.o d3d11tri/d3d11tri.o $(LIBS_D3D11) + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS_D3D11) -Wl,--end-group $(LDADD) + +bin/d3d11tex: d3d11app/d3d11x11main.o d3d11tex/d3d11tex.o $(LIBS_D3D11) + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS_D3D11) -Wl,--end-group $(LDADD) + +bin/d3d11gears: d3d11app/d3d11x11main.o d3d11gears/d3d11gears.o $(LIBS_D3D11) + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS_D3D11) -Wl,--end-group $(LDADD) + diff --git a/src/gallium/state_trackers/d3d1x/winedlls/Makefile b/src/gallium/state_trackers/d3d1x/winedlls/Makefile new file mode 100644 index 0000000..c7e51b2 --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/winedlls/Makefile @@ -0,0 +1,11 @@ +SUBDIRS=dxgi d3d10 d3d10_1 d3d11 + +all: + @for dir in $(SUBDIRS) ; do $(MAKE) -C "$$dir" || exit $?; done + +clean: + rm -f `find . -name \*.[oa]` + rm -f `find . -name depend` + +install: + sudo install */*.dll.so /usr/lib/wine diff --git a/src/gallium/state_trackers/d3d1x/winedlls/version.rc.h b/src/gallium/state_trackers/d3d1x/winedlls/version.rc.h new file mode 100644 index 0000000..096d119 --- /dev/null +++ b/src/gallium/state_trackers/d3d1x/winedlls/version.rc.h @@ -0,0 +1,30 @@ +1 VERSIONINFO +FILEVERSION 6,0,6000,16386 +PRODUCTVERSION 6,0,6000,16386 +FILEFLAGSMASK 63 +FILEFLAGS 0 +FILEOS 0x00000000L +FILETYPE 0x00000002L +FILESUBTYPE 0x00000000L +{ + BLOCK "StringFileInfo" + { + BLOCK "040904E4" + { + // all Wine DLLs claim to be from Microsoft, maybe it's needed for compatibility + VALUE "CompanyName", "Microsoft Corporation" + VALUE "FileDescription", "GalliumD3D1x " NAME " runtime" + VALUE "FileVersion", "6.0.6000.16386" + VALUE "InternalName", "" + VALUE "LegalCopyright", "Copyright (c) 2010 Luca Barbieri and other contributors" + VALUE "OriginalFilename", FILENAME ".dll" + VALUE "ProductName", "GalliumD3D1x" + VALUE "ProductVersion", "6.0.6000.16386" + } + } + BLOCK "VarFileInfo" + { + VALUE "Translation", 0x0409, 0x04E4 + } +} + diff --git a/src/gallium/state_trackers/dri/Makefile b/src/gallium/state_trackers/dri/Makefile new file mode 100644 index 0000000..72e7057 --- /dev/null +++ b/src/gallium/state_trackers/dri/Makefile @@ -0,0 +1,12 @@ +# src/gallium/state_trackers/dri/Makefile +TOP = ../../../.. +include $(TOP)/configs/current + +SUBDIRS = drm sw + +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 new file mode 100644 index 0000000..7702d8e --- /dev/null +++ b/src/gallium/state_trackers/dri/SConscript @@ -0,0 +1,6 @@ +Import('*') + +SConscript([ + 'sw/SConscript', + 'drm/SConscript', +]) diff --git a/src/gallium/state_trackers/dri/common/dri_context.c b/src/gallium/state_trackers/dri/common/dri_context.c new file mode 100644 index 0000000..fc68ee1 --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_context.c @@ -0,0 +1,211 @@ +/************************************************************************** + * + * 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 + */ + +#include "utils.h" + +#include "dri_screen.h" +#include "dri_drawable.h" +#include "dri_context.h" + +#include "pipe/p_context.h" +#include "state_tracker/st_context.h" + +static void +dri_init_extensions(struct dri_context *ctx) +{ + struct st_context *st = (struct st_context *) ctx->st; + + /* New extensions should be added in mesa/state_tracker/st_extensions.c + * and not in this file. */ + driInitExtensions(st->ctx, NULL, GL_FALSE); +} + +GLboolean +dri_create_context(gl_api api, const struct gl_config * visual, + __DRIcontext * cPriv, void *sharedContextPrivate) +{ + __DRIscreen *sPriv = cPriv->driScreenPriv; + struct dri_screen *screen = dri_screen(sPriv); + struct st_api *stapi = screen->st_api; + struct dri_context *ctx = NULL; + struct st_context_iface *st_share = NULL; + struct st_context_attribs attribs; + + memset(&attribs, 0, sizeof(attribs)); + switch (api) { + case API_OPENGLES: + attribs.profile = ST_PROFILE_OPENGL_ES1; + break; + case API_OPENGLES2: + attribs.profile = ST_PROFILE_OPENGL_ES2; + break; + default: + attribs.profile = ST_PROFILE_DEFAULT; + break; + } + + if (sharedContextPrivate) { + st_share = ((struct dri_context *)sharedContextPrivate)->st; + } + + ctx = CALLOC_STRUCT(dri_context); + if (ctx == NULL) + goto fail; + + cPriv->driverPrivate = ctx; + ctx->cPriv = cPriv; + ctx->sPriv = sPriv; + ctx->lock = screen->drmLock; + + driParseConfigFiles(&ctx->optionCache, + &screen->optionCache, sPriv->myNum, "dri"); + + dri_fill_st_visual(&attribs.visual, screen, visual); + ctx->st = stapi->create_context(stapi, &screen->base, &attribs, st_share); + if (ctx->st == NULL) + goto fail; + ctx->st->st_manager_private = (void *) ctx; + ctx->stapi = stapi; + + /* + * libmesagallium.a that this state tracker will be linked to expects + * OpenGL's _glapi_table. That is, it expects libGL.so instead of + * libGLESv1_CM.so or libGLESv2.so. As there is no clean way to know the + * shared library the app links to, use the api as a simple check. + * It might be as well to simply remove this function call though. + */ + if (api == API_OPENGL) + dri_init_extensions(ctx); + + return GL_TRUE; + + fail: + if (ctx && ctx->st) + ctx->st->destroy(ctx->st); + + FREE(ctx); + return GL_FALSE; +} + +void +dri_destroy_context(__DRIcontext * cPriv) +{ + struct dri_context *ctx = dri_context(cPriv); + + /* note: we are freeing values and nothing more because + * driParseConfigFiles allocated values only - the rest + * is owned by screen optionCache. + */ + FREE(ctx->optionCache.values); + + /* No particular reason to wait for command completion before + * destroying a context, but it is probably worthwhile flushing it + * to avoid having to add code elsewhere to cope with flushing a + * partially destroyed context. + */ + ctx->st->flush(ctx->st, 0, NULL); + ctx->st->destroy(ctx->st); + + FREE(ctx); +} + +GLboolean +dri_unbind_context(__DRIcontext * cPriv) +{ + /* dri_util.c ensures cPriv is not null */ + struct dri_screen *screen = dri_screen(cPriv->driScreenPriv); + struct dri_context *ctx = dri_context(cPriv); + struct dri_drawable *draw = dri_drawable(ctx->dPriv); + struct dri_drawable *read = dri_drawable(ctx->rPriv); + struct st_api *stapi = screen->st_api; + + if (--ctx->bind_count == 0) { + if (ctx->st == ctx->stapi->get_current(ctx->stapi)) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + stapi->make_current(stapi, NULL, NULL, NULL); + draw->context = NULL; + read->context = NULL; + } + } + + return GL_TRUE; +} + +GLboolean +dri_make_current(__DRIcontext * cPriv, + __DRIdrawable * driDrawPriv, + __DRIdrawable * driReadPriv) +{ + /* dri_util.c ensures cPriv is not null */ + struct dri_context *ctx = dri_context(cPriv); + struct dri_drawable *draw = dri_drawable(driDrawPriv); + struct dri_drawable *read = dri_drawable(driReadPriv); + struct st_context_iface *old_st = ctx->stapi->get_current(ctx->stapi); + + if (old_st && old_st != ctx->st) + old_st->flush(old_st, PIPE_FLUSH_RENDER_CACHE, NULL); + + ++ctx->bind_count; + + if (!driDrawPriv && !driReadPriv) + return ctx->stapi->make_current(ctx->stapi, ctx->st, NULL, NULL); + else if (!driDrawPriv || !driReadPriv) + return GL_FALSE; + + draw->context = ctx; + if (ctx->dPriv != driDrawPriv) { + ctx->dPriv = driDrawPriv; + draw->texture_stamp = driDrawPriv->lastStamp - 1; + } + read->context = ctx; + if (ctx->rPriv != driReadPriv) { + ctx->rPriv = driReadPriv; + read->texture_stamp = driReadPriv->lastStamp - 1; + } + + ctx->stapi->make_current(ctx->stapi, ctx->st, &draw->base, &read->base); + + return GL_TRUE; +} + +struct dri_context * +dri_get_current(__DRIscreen *sPriv) +{ + struct dri_screen *screen = dri_screen(sPriv); + struct st_api *stapi = screen->st_api; + struct st_context_iface *st; + + st = stapi->get_current(stapi); + + return (struct dri_context *) (st) ? st->st_manager_private : NULL; +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_context.h b/src/gallium/state_trackers/dri/common/dri_context.h new file mode 100644 index 0000000..35105e8 --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_context.h @@ -0,0 +1,97 @@ +/************************************************************************** + * + * Copyright (C) 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 DRI_CONTEXT_H +#define DRI_CONTEXT_H + +#include "pipe/p_compiler.h" +#include "dri_wrapper.h" + +struct pipe_context; +struct pipe_fence; +struct st_api; +struct st_context_iface; +struct dri_drawable; + +struct dri_context +{ + /* dri */ + __DRIscreen *sPriv; + __DRIcontext *cPriv; + __DRIdrawable *dPriv; + __DRIdrawable *rPriv; + + driOptionCache optionCache; + + drmLock *lock; + boolean isLocked; + boolean stLostLock; + boolean wsLostLock; + + unsigned int bind_count; + + /* gallium */ + struct st_api *stapi; + struct st_context_iface *st; +}; + +static INLINE struct dri_context * +dri_context(__DRIcontext * driContextPriv) +{ + if (!driContextPriv) + return NULL; + return (struct dri_context *)driContextPriv->driverPrivate; +} + +/*********************************************************************** + * dri_context.c + */ +void dri_destroy_context(__DRIcontext * driContextPriv); + +boolean dri_unbind_context(__DRIcontext * driContextPriv); + +boolean +dri_make_current(__DRIcontext * driContextPriv, + __DRIdrawable * driDrawPriv, + __DRIdrawable * driReadPriv); + +struct dri_context * +dri_get_current(__DRIscreen * driScreenPriv); + +boolean +dri_create_context(gl_api api, + const struct gl_config * visual, + __DRIcontext * driContextPriv, + void *sharedContextPrivate); + +#endif + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_drawable.c b/src/gallium/state_trackers/dri/common/dri_drawable.c new file mode 100644 index 0000000..6193670 --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_drawable.c @@ -0,0 +1,267 @@ +/************************************************************************** + * + * 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 + */ + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" + +#include "pipe/p_screen.h" +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" + + +static boolean +dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_resource **out) +{ + struct dri_drawable *drawable = + (struct dri_drawable *) stfbi->st_manager_private; + struct dri_screen *screen = dri_screen(drawable->sPriv); + unsigned statt_mask, new_mask; + boolean new_stamp; + int i; + + statt_mask = 0x0; + for (i = 0; i < count; i++) + statt_mask |= (1 << statts[i]); + + /* record newly allocated textures */ + new_mask = (statt_mask & ~drawable->texture_mask); + + /* + * dPriv->pStamp is the server stamp. It should be accessed with a lock, at + * least for DRI1. dPriv->lastStamp is the client stamp. It has the value + * of the server stamp when last checked. + */ + new_stamp = (drawable->texture_stamp != drawable->dPriv->lastStamp); + + if (new_stamp || new_mask || screen->broken_invalidate) { + if (new_stamp && drawable->update_drawable_info) + drawable->update_drawable_info(drawable); + + drawable->allocate_textures(drawable, statts, count); + + /* add existing textures */ + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + if (drawable->textures[i]) + statt_mask |= (1 << i); + } + + drawable->texture_stamp = drawable->dPriv->lastStamp; + drawable->texture_mask = statt_mask; + } + + if (!out) + return TRUE; + + for (i = 0; i < count; i++) { + out[i] = NULL; + pipe_resource_reference(&out[i], drawable->textures[statts[i]]); + } + + return TRUE; +} + +static boolean +dri_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + struct dri_drawable *drawable = + (struct dri_drawable *) stfbi->st_manager_private; + + /* XXX remove this and just set the correct one on the framebuffer */ + drawable->flush_frontbuffer(drawable, statt); + + return TRUE; +} + +/** + * This is called when we need to set up GL rendering to a new X window. + */ +boolean +dri_create_buffer(__DRIscreen * sPriv, + __DRIdrawable * dPriv, + const struct gl_config * visual, boolean isPixmap) +{ + struct dri_screen *screen = sPriv->private; + struct dri_drawable *drawable = NULL; + + if (isPixmap) + goto fail; /* not implemented */ + + drawable = CALLOC_STRUCT(dri_drawable); + if (drawable == NULL) + goto fail; + + dri_fill_st_visual(&drawable->stvis, screen, visual); + + /* setup the st_framebuffer_iface */ + drawable->base.visual = &drawable->stvis; + drawable->base.flush_front = dri_st_framebuffer_flush_front; + drawable->base.validate = dri_st_framebuffer_validate; + drawable->base.st_manager_private = (void *) drawable; + + drawable->screen = screen; + drawable->sPriv = sPriv; + drawable->dPriv = dPriv; + dPriv->driverPrivate = (void *)drawable; + + return GL_TRUE; +fail: + FREE(drawable); + return GL_FALSE; +} + +void +dri_destroy_buffer(__DRIdrawable * dPriv) +{ + struct dri_drawable *drawable = dri_drawable(dPriv); + int i; + + pipe_surface_reference(&drawable->drisw_surface, NULL); + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_resource_reference(&drawable->textures[i], NULL); + + FREE(drawable); +} + +/** + * Validate the texture at an attachment. Allocate the texture if it does not + * exist. Used by the TFP extension. + */ +static void +dri_drawable_validate_att(struct dri_drawable *drawable, + enum st_attachment_type statt) +{ + enum st_attachment_type statts[ST_ATTACHMENT_COUNT]; + unsigned i, count = 0; + + /* check if buffer already exists */ + if (drawable->texture_mask & (1 << statt)) + return; + + /* make sure DRI2 does not destroy existing buffers */ + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + if (drawable->texture_mask & (1 << i)) { + statts[count++] = i; + } + } + statts[count++] = statt; + + drawable->texture_stamp = drawable->dPriv->lastStamp - 1; + + drawable->base.validate(&drawable->base, statts, count, NULL); +} + +/** + * These are used for GLX_EXT_texture_from_pixmap + */ +static void +dri_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_resource *pt; + + dri_drawable_validate_att(drawable, ST_ATTACHMENT_FRONT_LEFT); + + pt = drawable->textures[ST_ATTACHMENT_FRONT_LEFT]; + + if (pt) { + enum pipe_format internal_format = pt->format; + + if (format == __DRI_TEXTURE_FORMAT_RGB) { + /* only need to cover the formats recognized by dri_fill_st_visual */ + switch (internal_format) { + case PIPE_FORMAT_B8G8R8A8_UNORM: + internal_format = PIPE_FORMAT_B8G8R8X8_UNORM; + break; + case PIPE_FORMAT_A8R8G8B8_UNORM: + internal_format = PIPE_FORMAT_X8R8G8B8_UNORM; + break; + default: + break; + } + } + + ctx->st->teximage(ctx->st, + (target == GL_TEXTURE_2D) ? ST_TEXTURE_2D : ST_TEXTURE_RECT, + 0, internal_format, pt, FALSE); + } +} + +static void +dri_set_tex_buffer(__DRIcontext *pDRICtx, GLint target, + __DRIdrawable *dPriv) +{ + dri_set_tex_buffer2(pDRICtx, target, __DRI_TEXTURE_FORMAT_RGBA, dPriv); +} + +const __DRItexBufferExtension driTexBufferExtension = { + { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION }, + dri_set_tex_buffer, + dri_set_tex_buffer2, +}; + +/** + * Get the format and binding of an attachment. + */ +void +dri_drawable_get_format(struct dri_drawable *drawable, + enum st_attachment_type statt, + enum pipe_format *format, + unsigned *bind) +{ + 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; + *bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + *format = drawable->stvis.depth_stencil_format; + *bind = PIPE_BIND_DEPTH_STENCIL; /* XXX sampler? */ + break; + default: + *format = PIPE_FORMAT_NONE; + *bind = 0; + break; + } +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_drawable.h b/src/gallium/state_trackers/dri/common/dri_drawable.h new file mode 100644 index 0000000..7f1aa51 --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_drawable.h @@ -0,0 +1,100 @@ +/************************************************************************** + * + * 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 DRI_DRAWABLE_H +#define DRI_DRAWABLE_H + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "state_tracker/st_api.h" + +struct pipe_surface; +struct st_framebuffer; +struct dri_context; + +struct dri_drawable +{ + struct st_framebuffer_iface base; + struct st_visual stvis; + + struct dri_screen *screen; + struct dri_context *context; + + /* dri */ + __DRIdrawable *dPriv; + __DRIscreen *sPriv; + + __DRIbuffer old[8]; + unsigned old_num; + unsigned old_w; + unsigned old_h; + + struct pipe_resource *textures[ST_ATTACHMENT_COUNT]; + unsigned int texture_mask, texture_stamp; + + /* used only by DRISW */ + struct pipe_surface *drisw_surface; + + /* hooks filled in by dri2 & drisw */ + void (*allocate_textures)(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned count); + + void (*update_drawable_info)(struct dri_drawable *drawable); + + void (*flush_frontbuffer)(struct dri_drawable *drawable, + enum st_attachment_type statt); +}; + +static INLINE struct dri_drawable * +dri_drawable(__DRIdrawable * driDrawPriv) +{ + return (struct dri_drawable *) (driDrawPriv) + ? driDrawPriv->driverPrivate : NULL; +} + +/*********************************************************************** + * dri_drawable.c + */ +boolean +dri_create_buffer(__DRIscreen * sPriv, + __DRIdrawable * dPriv, + const struct gl_config * visual, boolean isPixmap); + +void dri_destroy_buffer(__DRIdrawable * dPriv); + +void +dri_drawable_get_format(struct dri_drawable *drawable, + enum st_attachment_type statt, + enum pipe_format *format, + unsigned *bind); + +extern const __DRItexBufferExtension driTexBufferExtension; + +#endif + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_screen.c b/src/gallium/state_trackers/dri/common/dri_screen.c new file mode 100644 index 0000000..f6e22c7 --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_screen.c @@ -0,0 +1,396 @@ +/************************************************************************** + * + * 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 + */ + +#include "utils.h" +#include "xmlpool.h" + +#include "dri_screen.h" + +#include "util/u_inlines.h" +#include "pipe/p_screen.h" +#include "pipe/p_format.h" +#include "state_tracker/st_gl_api.h" /* for st_gl_api_create */ + +#include "util/u_debug.h" + +PUBLIC const char __driConfigOptions[] = + DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE + DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS) + DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0) + DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY +/* DRI_CONF_FORCE_S3TC_ENABLE(false) */ + DRI_CONF_ALLOW_LARGE_TEXTURES(1) + DRI_CONF_SECTION_END DRI_CONF_END; + +static const uint __driNConfigOptions = 3; + +static const __DRIconfig ** +dri_fill_in_modes(struct dri_screen *screen, + unsigned pixel_bits) +{ + __DRIconfig **configs = NULL; + __DRIconfig **configs_r5g6b5 = NULL; + __DRIconfig **configs_a8r8g8b8 = NULL; + __DRIconfig **configs_x8r8g8b8 = NULL; + uint8_t depth_bits_array[5]; + uint8_t stencil_bits_array[5]; + uint8_t msaa_samples_array[5]; + unsigned depth_buffer_factor; + unsigned back_buffer_factor; + unsigned msaa_samples_factor; + unsigned i; + struct pipe_screen *p_screen = screen->base.screen; + boolean pf_r5g6b5, pf_a8r8g8b8, pf_x8r8g8b8; + boolean pf_z16, pf_x8z24, pf_z24x8, pf_s8z24, pf_z24s8, pf_z32; + + static const GLenum back_buffer_modes[] = { + GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML + }; + + depth_bits_array[0] = 0; + stencil_bits_array[0] = 0; + depth_buffer_factor = 1; + + pf_x8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24X8_UNORM, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_DEPTH_STENCIL, 0); + pf_z24x8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_X8Z24_UNORM, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_DEPTH_STENCIL, 0); + pf_s8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_DEPTH_STENCIL, 0); + pf_z24s8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_DEPTH_STENCIL, 0); + pf_a8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_RENDER_TARGET, 0); + pf_x8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8X8_UNORM, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_RENDER_TARGET, 0); + pf_r5g6b5 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B5G6R5_UNORM, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_RENDER_TARGET, 0); + + /* We can only get a 16 or 32 bit depth buffer with getBuffersWithFormat */ + if (dri_with_format(screen->sPriv)) { + pf_z16 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z16_UNORM, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_DEPTH_STENCIL, 0); + pf_z32 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z32_UNORM, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_DEPTH_STENCIL, 0); + } else { + pf_z16 = FALSE; + pf_z32 = FALSE; + } + + if (pf_z16) { + depth_bits_array[depth_buffer_factor] = 16; + stencil_bits_array[depth_buffer_factor++] = 0; + } + if (pf_x8z24 || pf_z24x8) { + depth_bits_array[depth_buffer_factor] = 24; + stencil_bits_array[depth_buffer_factor++] = 0; + screen->d_depth_bits_last = pf_x8z24; + } + if (pf_s8z24 || pf_z24s8) { + depth_bits_array[depth_buffer_factor] = 24; + stencil_bits_array[depth_buffer_factor++] = 8; + screen->sd_depth_bits_last = pf_s8z24; + } + if (pf_z32) { + depth_bits_array[depth_buffer_factor] = 32; + stencil_bits_array[depth_buffer_factor++] = 0; + } + + msaa_samples_array[0] = 0; + back_buffer_factor = 3; + + /* also test color for msaa 2/4/6/8 - just assume it'll work for all depth buffers */ + if (pf_r5g6b5) { + msaa_samples_factor = 1; + for (i = 1; i < 5; i++) { + if (p_screen->is_format_supported(p_screen, PIPE_FORMAT_B5G6R5_UNORM, + PIPE_TEXTURE_2D, i*2, + PIPE_BIND_RENDER_TARGET, 0)) { + msaa_samples_array[msaa_samples_factor] = i * 2; + msaa_samples_factor++; + } + } + + configs_r5g6b5 = driCreateConfigs(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, + depth_bits_array, stencil_bits_array, + depth_buffer_factor, back_buffer_modes, + back_buffer_factor, + msaa_samples_array, msaa_samples_factor, + GL_TRUE); + } + + if (pf_a8r8g8b8) { + msaa_samples_factor = 1; + for (i = 1; i < 5; i++) { + if (p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_TEXTURE_2D, i*2, + PIPE_BIND_RENDER_TARGET, 0)) { + msaa_samples_array[msaa_samples_factor] = i * 2; + msaa_samples_factor++; + } + } + + configs_a8r8g8b8 = driCreateConfigs(GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, + depth_bits_array, + stencil_bits_array, + depth_buffer_factor, + back_buffer_modes, + back_buffer_factor, + msaa_samples_array, + msaa_samples_factor, + GL_TRUE); + } + + if (pf_x8r8g8b8) { + msaa_samples_factor = 1; + for (i = 1; i < 5; i++) { + if (p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8X8_UNORM, + PIPE_TEXTURE_2D, i*2, + PIPE_BIND_RENDER_TARGET, 0)) { + msaa_samples_array[msaa_samples_factor] = i * 2; + msaa_samples_factor++; + } + } + + configs_x8r8g8b8 = driCreateConfigs(GL_BGR, GL_UNSIGNED_INT_8_8_8_8_REV, + depth_bits_array, + stencil_bits_array, + depth_buffer_factor, + back_buffer_modes, + back_buffer_factor, + msaa_samples_array, + msaa_samples_factor, + GL_TRUE); + } + + if (pixel_bits == 16) { + configs = configs_r5g6b5; + if (configs_a8r8g8b8) + configs = configs ? driConcatConfigs(configs, configs_a8r8g8b8) : configs_a8r8g8b8; + if (configs_x8r8g8b8) + configs = configs ? driConcatConfigs(configs, configs_x8r8g8b8) : configs_x8r8g8b8; + } else { + configs = configs_a8r8g8b8; + if (configs_x8r8g8b8) + configs = configs ? driConcatConfigs(configs, configs_x8r8g8b8) : configs_x8r8g8b8; + if (configs_r5g6b5) + configs = configs ? driConcatConfigs(configs, configs_r5g6b5) : configs_r5g6b5; + } + + if (configs == NULL) { + debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__); + return NULL; + } + + return (const __DRIconfig **)configs; +} + +/** + * Roughly the converse of dri_fill_in_modes. + */ +void +dri_fill_st_visual(struct st_visual *stvis, struct dri_screen *screen, + const struct gl_config *mode) +{ + memset(stvis, 0, sizeof(*stvis)); + + if (!mode) + return; + + stvis->samples = mode->samples; + stvis->render_buffer = ST_ATTACHMENT_INVALID; + + if (mode->redBits == 8) { + if (mode->alphaBits == 8) + stvis->color_format = PIPE_FORMAT_B8G8R8A8_UNORM; + else + stvis->color_format = PIPE_FORMAT_B8G8R8X8_UNORM; + } else { + stvis->color_format = PIPE_FORMAT_B5G6R5_UNORM; + } + + switch (mode->depthBits) { + default: + case 0: + stvis->depth_stencil_format = PIPE_FORMAT_NONE; + break; + case 16: + stvis->depth_stencil_format = PIPE_FORMAT_Z16_UNORM; + break; + case 24: + if (mode->stencilBits == 0) { + stvis->depth_stencil_format = (screen->d_depth_bits_last) ? + PIPE_FORMAT_Z24X8_UNORM: + PIPE_FORMAT_X8Z24_UNORM; + } else { + stvis->depth_stencil_format = (screen->sd_depth_bits_last) ? + PIPE_FORMAT_Z24_UNORM_S8_USCALED: + PIPE_FORMAT_S8_USCALED_Z24_UNORM; + } + break; + case 32: + stvis->depth_stencil_format = PIPE_FORMAT_Z32_UNORM; + break; + } + + stvis->accum_format = (mode->haveAccumBuffer) ? + PIPE_FORMAT_R16G16B16A16_SNORM : PIPE_FORMAT_NONE; + + stvis->buffer_mask |= ST_ATTACHMENT_FRONT_LEFT_MASK; + if (mode->doubleBufferMode) + stvis->buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK; + if (mode->stereoMode) { + stvis->buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK; + if (mode->doubleBufferMode) + stvis->buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK; + } + + if (mode->haveDepthBuffer || mode->haveStencilBuffer) + stvis->buffer_mask |= ST_ATTACHMENT_DEPTH_STENCIL_MASK; + /* let the state tracker allocate the accum buffer */ +} + +static boolean +dri_get_egl_image(struct st_manager *smapi, + void *egl_image, + struct st_egl_image *stimg) +{ + struct dri_screen *screen = (struct dri_screen *)smapi; + __DRIimage *img = NULL; + + if (screen->lookup_egl_image) { + img = screen->lookup_egl_image(screen, egl_image); + } + + if (!img) + return FALSE; + + stimg->texture = NULL; + pipe_resource_reference(&stimg->texture, img->texture); + stimg->level = img->level; + stimg->layer = img->layer; + + return TRUE; +} + +static int +dri_get_param(struct st_manager *smapi, + enum st_manager_param param) +{ + struct dri_screen *screen = (struct dri_screen *)smapi; + + switch(param) { + case ST_MANAGER_BROKEN_INVALIDATE: + return screen->broken_invalidate; + default: + return 0; + } +} + +static void +dri_destroy_option_cache(struct dri_screen * screen) +{ + int i; + + if (screen->optionCache.info) { + for (i = 0; i < (1 << screen->optionCache.tableSize); ++i) { + FREE(screen->optionCache.info[i].name); + FREE(screen->optionCache.info[i].ranges); + } + FREE(screen->optionCache.info); + } + + FREE(screen->optionCache.values); +} + +void +dri_destroy_screen_helper(struct dri_screen * screen) +{ + if (screen->st_api && screen->st_api->destroy) + screen->st_api->destroy(screen->st_api); + + if (screen->base.screen) + screen->base.screen->destroy(screen->base.screen); + + dri_destroy_option_cache(screen); +} + +void +dri_destroy_screen(__DRIscreen * sPriv) +{ + struct dri_screen *screen = dri_screen(sPriv); + + dri_destroy_screen_helper(screen); + + FREE(screen); + sPriv->private = NULL; + sPriv->extensions = NULL; +} + +const __DRIconfig ** +dri_init_screen_helper(struct dri_screen *screen, + struct pipe_screen *pscreen, + unsigned pixel_bits) +{ + screen->base.screen = pscreen; + if (!screen->base.screen) { + debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); + return NULL; + } + + screen->base.get_egl_image = dri_get_egl_image; + screen->base.get_param = dri_get_param; + + screen->st_api = st_gl_api_create(); + if (!screen->st_api) + return NULL; + + if(pscreen->get_param(pscreen, PIPE_CAP_NPOT_TEXTURES)) + screen->target = PIPE_TEXTURE_2D; + else + screen->target = PIPE_TEXTURE_RECT; + + driParseOptionInfo(&screen->optionCache, + __driConfigOptions, __driNConfigOptions); + + return dri_fill_in_modes(screen, pixel_bits); +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_screen.h b/src/gallium/state_trackers/dri/common/dri_screen.h new file mode 100644 index 0000000..8cb0a10 --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_screen.h @@ -0,0 +1,131 @@ +/************************************************************************** + * + * 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 DRI_SCREEN_H +#define DRI_SCREEN_H + +#include "dri_wrapper.h" +#include "xmlconfig.h" + +#include "pipe/p_compiler.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "state_tracker/st_api.h" + +struct dri_context; +struct dri_drawable; + +struct dri_screen +{ + /* st_api */ + struct st_manager base; + struct st_api *st_api; + + /* on old libGL's invalidate doesn't get called as it should */ + boolean broken_invalidate; + + /* dri */ + __DRIscreen *sPriv; + + /** + * Configuration cache with default values for all contexts + */ + driOptionCache optionCache; + + /* drm */ + int fd; + drmLock *drmLock; + + /* gallium */ + boolean d_depth_bits_last; + boolean sd_depth_bits_last; + boolean auto_fake_front; + enum pipe_texture_target target; + + /* hooks filled in by dri2 & drisw */ + __DRIimage * (*lookup_egl_image)(struct dri_screen *ctx, void *handle); +}; + +/** cast wrapper */ +static INLINE struct dri_screen * +dri_screen(__DRIscreen * sPriv) +{ + return (struct dri_screen *)sPriv->private; +} + +struct __DRIimageRec { + struct pipe_resource *texture; + unsigned level; + unsigned layer; + + void *loader_private; +}; + +#ifndef __NOT_HAVE_DRM_H + +static INLINE boolean +dri_with_format(__DRIscreen * sPriv) +{ + const __DRIdri2LoaderExtension *loader = sPriv->dri2.loader; + + return loader + && (loader->base.version >= 3) + && (loader->getBuffersWithFormat != NULL); +} + +#else + +static INLINE boolean +dri_with_format(__DRIscreen * sPriv) +{ + return TRUE; +} + +#endif + +void +dri_fill_st_visual(struct st_visual *stvis, struct dri_screen *screen, + const struct gl_config *mode); + +const __DRIconfig ** +dri_init_screen_helper(struct dri_screen *screen, + struct pipe_screen *pscreen, + unsigned pixel_bits); + +void +dri_destroy_screen_helper(struct dri_screen * screen); + +void +dri_destroy_screen(__DRIscreen * sPriv); + +#endif + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_wrapper.h b/src/gallium/state_trackers/dri/common/dri_wrapper.h new file mode 100644 index 0000000..141ba02 --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_wrapper.h @@ -0,0 +1,10 @@ +#ifndef DRI_WRAPPER_H +#define DRI_WRAPPER_H + +#ifndef __NOT_HAVE_DRM_H +#include "dri_util.h" +#else +#include "drisw_util.h" +#endif + +#endif diff --git a/src/gallium/state_trackers/dri/drm/Makefile b/src/gallium/state_trackers/dri/drm/Makefile new file mode 100644 index 0000000..c717b2b --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/Makefile @@ -0,0 +1,30 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = dridrm + +LIBRARY_INCLUDES = \ + -I$(TOP)/include \ + -I$(TOP)/src/mapi \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/gallium/state_trackers/dri/common \ + -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 \ + 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 0000000..b188f76 --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/SConscript @@ -0,0 +1,28 @@ +####################################################################### +# SConscript for dri state_tracker + +Import('*') + +env = env.Clone() + +env.ParseConfig('pkg-config --cflags --libs libdrm') + +env.Append(CPPPATH = [ + '#/src/mapi', + '#/src/mesa', + '#/src/gallium/state_trackers/dri/common', + '#/src/mesa/drivers/dri/common', +]) + +sources = [ + 'dri_context.c', + 'dri_drawable.c', + 'dri_screen.c', + 'dri2.c', +] + +st_dri = env.ConvenienceLibrary( + target = 'st_dri', + source = sources, +) +Export('st_dri') 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 0000000..997a17b --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri2.c @@ -0,0 +1,614 @@ +/* + * 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_driver.h" + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.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 = drawable->context; + + dri2InvalidateDrawable(dPriv); + drawable->dPriv->lastStamp = *drawable->dPriv->pStamp; + + if (ctx) + ctx->st->notify_invalid_framebuffer(ctx->st, &drawable->base); +} + +static const __DRI2flushExtension dri2FlushExtension = { + { __DRI2_FLUSH, __DRI2_FLUSH_VERSION }, + dri2_flush_drawable, + dri2_invalidate_drawable, +}; + +/** + * 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; + unsigned bind; + int att, bpp; + + dri_drawable_get_format(drawable, statts[i], &format, &bind); + 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_resources. + */ +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_resource templ; + struct winsys_handle whandle; + boolean have_depth = FALSE; + unsigned i, bind; + + 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_resource_reference(&drawable->textures[i], NULL); + + memset(&templ, 0, sizeof(templ)); + templ.target = screen->target; + templ.last_level = 0; + templ.width0 = dri_drawable->w; + templ.height0 = dri_drawable->h; + templ.depth0 = 1; + templ.array_size = 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; + } + + dri_drawable_get_format(drawable, statt, &format, &bind); + if (statt == ST_ATTACHMENT_INVALID || format == PIPE_FORMAT_NONE) + continue; + + templ.format = format; + templ.bind = bind; + whandle.handle = buf->name; + whandle.stride = buf->pitch; + + drawable->textures[statt] = + screen->base.screen->resource_from_handle(screen->base.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. + */ + +static 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); + if (buffers) + dri2_drawable_process_buffers(drawable, buffers, num_buffers); +} + +static 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); + } +} + +static __DRIimage * +dri2_lookup_egl_image(struct dri_screen *screen, void *handle) +{ + __DRIimageLookupExtension *loader = screen->sPriv->dri2.image; + __DRIimage *img; + + if (!loader->lookupEGLImage) + return NULL; + + img = loader->lookupEGLImage(screen->sPriv, + handle, screen->sPriv->loaderPrivate); + + return img; +} + +static __DRIimage * +dri2_create_image_from_name(__DRIscreen *_screen, + int width, int height, int format, + int name, int pitch, void *loaderPrivate) +{ + struct dri_screen *screen = dri_screen(_screen); + __DRIimage *img; + struct pipe_resource templ; + struct winsys_handle whandle; + unsigned tex_usage; + enum pipe_format pf; + + tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; + + switch (format) { + case __DRI_IMAGE_FORMAT_RGB565: + pf = PIPE_FORMAT_B5G6R5_UNORM; + break; + case __DRI_IMAGE_FORMAT_XRGB8888: + pf = PIPE_FORMAT_B8G8R8X8_UNORM; + break; + case __DRI_IMAGE_FORMAT_ARGB8888: + pf = PIPE_FORMAT_B8G8R8A8_UNORM; + break; + default: + pf = PIPE_FORMAT_NONE; + break; + } + if (pf == PIPE_FORMAT_NONE) + return NULL; + + img = CALLOC_STRUCT(__DRIimageRec); + if (!img) + return NULL; + + memset(&templ, 0, sizeof(templ)); + templ.bind = tex_usage; + templ.format = pf; + templ.target = screen->target; + templ.last_level = 0; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.array_size = 1; + + memset(&whandle, 0, sizeof(whandle)); + whandle.handle = name; + whandle.stride = pitch * util_format_get_blocksize(pf); + + img->texture = screen->base.screen->resource_from_handle(screen->base.screen, + &templ, &whandle); + if (!img->texture) { + FREE(img); + return NULL; + } + + img->level = 0; + img->layer = 0; + img->loader_private = loaderPrivate; + + return img; +} + +static __DRIimage * +dri2_create_image_from_renderbuffer(__DRIcontext *context, + int renderbuffer, void *loaderPrivate) +{ + struct dri_context *ctx = dri_context(context->driverPrivate); + + if (!ctx->st->get_resource_for_egl_image) + return NULL; + + /* TODO */ + return NULL; +} + +static __DRIimage * +dri2_create_image(__DRIscreen *_screen, + int width, int height, int format, + unsigned int use, void *loaderPrivate) +{ + struct dri_screen *screen = dri_screen(_screen); + __DRIimage *img; + struct pipe_resource templ; + unsigned tex_usage; + enum pipe_format pf; + + tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; + + switch (format) { + case __DRI_IMAGE_FORMAT_RGB565: + pf = PIPE_FORMAT_B5G6R5_UNORM; + break; + case __DRI_IMAGE_FORMAT_XRGB8888: + pf = PIPE_FORMAT_B8G8R8X8_UNORM; + break; + case __DRI_IMAGE_FORMAT_ARGB8888: + pf = PIPE_FORMAT_B8G8R8A8_UNORM; + break; + default: + pf = PIPE_FORMAT_NONE; + break; + } + if (pf == PIPE_FORMAT_NONE) + return NULL; + + img = CALLOC_STRUCT(__DRIimageRec); + if (!img) + return NULL; + + memset(&templ, 0, sizeof(templ)); + templ.bind = tex_usage; + templ.format = pf; + templ.target = PIPE_TEXTURE_2D; + templ.last_level = 0; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + + img->texture = screen->base.screen->resource_create(screen->base.screen, &templ); + if (!img->texture) { + FREE(img); + return NULL; + } + + img->level = 0; + img->layer = 0; + + img->loader_private = loaderPrivate; + return img; +} + +static GLboolean +dri2_query_image(__DRIimage *image, int attrib, int *value) +{ + struct winsys_handle whandle; + memset(&whandle, 0, sizeof(whandle)); + + switch (attrib) { + case __DRI_IMAGE_ATTRIB_STRIDE: + image->texture->screen->resource_get_handle(image->texture->screen, + image->texture, &whandle); + *value = whandle.stride; + return GL_TRUE; + case __DRI_IMAGE_ATTRIB_HANDLE: + whandle.type = DRM_API_HANDLE_TYPE_KMS; + image->texture->screen->resource_get_handle(image->texture->screen, + image->texture, &whandle); + *value = whandle.handle; + return GL_TRUE; + case __DRI_IMAGE_ATTRIB_NAME: + whandle.type = DRM_API_HANDLE_TYPE_SHARED; + image->texture->screen->resource_get_handle(image->texture->screen, + image->texture, &whandle); + *value = whandle.handle; + return GL_TRUE; + default: + return GL_FALSE; + } +} + +static void +dri2_destroy_image(__DRIimage *img) +{ + pipe_resource_reference(&img->texture, NULL); + FREE(img); +} + +static struct __DRIimageExtensionRec dri2ImageExtension = { + { __DRI_IMAGE, __DRI_IMAGE_VERSION }, + dri2_create_image_from_name, + dri2_create_image_from_renderbuffer, + dri2_destroy_image, + dri2_create_image, + dri2_query_image, +}; + +/* + * Backend function init_screen. + */ + +static const __DRIextension *dri_screen_extensions[] = { + &driReadDrawableExtension, + &driCopySubBufferExtension.base, + &driSwapControlExtension.base, + &driMediaStreamCounterExtension.base, + &driTexBufferExtension.base, + &dri2FlushExtension.base, + &dri2ImageExtension.base, + &dri2ConfigQueryExtension.base, + NULL +}; + +/** + * This is the driver specific part of the createNewScreen entry point. + * + * Returns the struct gl_config supported by this driver. + */ +static const __DRIconfig ** +dri2_init_screen(__DRIscreen * sPriv) +{ + const __DRIconfig **configs; + struct dri_screen *screen; + struct pipe_screen *pscreen; + + screen = CALLOC_STRUCT(dri_screen); + if (!screen) + return NULL; + + screen->sPriv = sPriv; + screen->fd = sPriv->fd; + + sPriv->private = (void *)screen; + sPriv->extensions = dri_screen_extensions; + + pscreen = driver_descriptor.create_screen(screen->fd); + /* dri_init_screen_helper checks pscreen for us */ + + configs = dri_init_screen_helper(screen, pscreen, 32); + if (!configs) + goto fail; + + sPriv->api_mask = 0; + if (screen->st_api->profile_mask & ST_PROFILE_DEFAULT_MASK) + sPriv->api_mask |= 1 << __DRI_API_OPENGL; + if (screen->st_api->profile_mask & ST_PROFILE_OPENGL_ES1_MASK) + sPriv->api_mask |= 1 << __DRI_API_GLES; + if (screen->st_api->profile_mask & ST_PROFILE_OPENGL_ES2_MASK) + sPriv->api_mask |= 1 << __DRI_API_GLES2; + + screen->auto_fake_front = dri_with_format(sPriv); + screen->broken_invalidate = !sPriv->dri2.useInvalidate; + screen->lookup_egl_image = dri2_lookup_egl_image; + + return configs; +fail: + dri_destroy_screen_helper(screen); + FREE(screen); + return NULL; +} + +static boolean +dri2_create_context(gl_api api, const struct gl_config * visual, + __DRIcontext * cPriv, void *sharedContextPrivate) +{ + struct dri_context *ctx = NULL; + + if (!dri_create_context(api, visual, cPriv, sharedContextPrivate)) + return FALSE; + + ctx = cPriv->driverPrivate; + + return TRUE; +} + +static boolean +dri2_create_buffer(__DRIscreen * sPriv, + __DRIdrawable * dPriv, + const struct gl_config * visual, boolean isPixmap) +{ + struct dri_drawable *drawable = NULL; + + if (!dri_create_buffer(sPriv, dPriv, visual, isPixmap)) + return FALSE; + + drawable = dPriv->driverPrivate; + + drawable->allocate_textures = dri2_allocate_textures; + drawable->flush_frontbuffer = dri2_flush_frontbuffer; + + return TRUE; +} + +/** + * DRI driver virtual function table. + * + * DRI versions differ in their implementation of init_screen and swap_buffers. + */ +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = NULL, + .InitScreen2 = dri2_init_screen, + .DestroyScreen = dri_destroy_screen, + .CreateContext = dri2_create_context, + .DestroyContext = dri_destroy_context, + .CreateBuffer = dri2_create_buffer, + .DestroyBuffer = dri_destroy_buffer, + .MakeCurrent = dri_make_current, + .UnbindContext = dri_unbind_context, + + .GetSwapInfo = NULL, + .GetDrawableMSC = NULL, + .WaitForMSC = NULL, + + .SwapBuffers = NULL, + .CopySubBuffer = NULL, +}; + +/* This is the table of extensions that the loader will dlsym() for. */ +PUBLIC const __DRIextension *__driDriverExtensions[] = { + &driCoreExtension.base, + &driLegacyExtension.base, + &driDRI2Extension.base, + NULL +}; + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ 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 0000000..5cfbbae --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri_context.c @@ -0,0 +1 @@ +../common/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 0000000..0fc19be --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri_drawable.c @@ -0,0 +1 @@ +../common/dri_drawable.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 0000000..847f651 --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri_screen.c @@ -0,0 +1 @@ +../common/dri_screen.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 0000000..33bc0ed --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/Makefile @@ -0,0 +1,25 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = drisw + +LIBRARY_DEFINES = -D__NOT_HAVE_DRM_H + +LIBRARY_INCLUDES = \ + -I../dri \ + -I$(TOP)/include \ + -I$(TOP)/src/mapi \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/gallium/state_trackers/dri/common \ + -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 \ + drisw.c + +include ../../../Makefile.template diff --git a/src/gallium/state_trackers/dri/sw/SConscript b/src/gallium/state_trackers/dri/sw/SConscript new file mode 100644 index 0000000..d0c3efc --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/SConscript @@ -0,0 +1,28 @@ +####################################################################### +# SConscript for dri state_tracker + +Import('*') + +env = env.Clone() + +env.Append(CPPPATH = [ + '#/src/mapi', + '#/src/mesa', + '#/src/gallium/state_trackers/dri/common', + '#/src/mesa/drivers/dri/common', +]) + +env.Append(CPPDEFINES = [('__NOT_HAVE_DRM_H', '1')]) + +sources = [ + 'dri_context.c', + 'dri_drawable.c', + 'dri_screen.c', + 'drisw.c', +] + +st_drisw = env.ConvenienceLibrary( + target = 'st_drisw', + source = sources, +) +Export('st_drisw') 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 0000000..5cfbbae --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri_context.c @@ -0,0 +1 @@ +../common/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 0000000..0fc19be --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri_drawable.c @@ -0,0 +1 @@ +../common/dri_drawable.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 0000000..847f651 --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri_screen.c @@ -0,0 +1 @@ +../common/dri_screen.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 0000000..30088b0 --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/drisw.c @@ -0,0 +1,320 @@ +/************************************************************************** + * + * 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: + * + * xshm / texture_from_pixmap / EGLImage: + * + * Allow the loaders to use the XSHM extension. It probably requires callbacks + * for createImage/destroyImage similar to DRI2 getBuffers. + */ + +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "pipe/p_context.h" +#include "state_tracker/drisw_api.h" + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" + +DEBUG_GET_ONCE_BOOL_OPTION(swrast_no_present, "SWRAST_NO_PRESENT", FALSE); +static boolean swrast_no_present = FALSE; + +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, unsigned width, unsigned height) +{ + __DRIscreen *sPriv = dPriv->driScreenPriv; + const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader; + + loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP, + 0, 0, width, height, + data, dPriv->loaderPrivate); +} + +static void +drisw_update_drawable_info(struct dri_drawable *drawable) +{ + __DRIdrawable *dPriv = drawable->dPriv; + + get_drawable_info(dPriv, &dPriv->w, &dPriv->h); +} + +static void +drisw_put_image(struct dri_drawable *drawable, + void *data, unsigned width, unsigned height) +{ + __DRIdrawable *dPriv = drawable->dPriv; + + put_image(dPriv, data, width, height); +} + +static INLINE void +drisw_present_texture(__DRIdrawable *dPriv, + struct pipe_resource *ptex) +{ + struct dri_drawable *drawable = dri_drawable(dPriv); + struct dri_screen *screen = dri_screen(drawable->sPriv); + + if (swrast_no_present) + return; + + screen->base.screen->flush_frontbuffer(screen->base.screen, ptex, 0, 0, drawable); +} + +static INLINE void +drisw_invalidate_drawable(__DRIdrawable *dPriv) +{ + struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv); + struct dri_drawable *drawable = dri_drawable(dPriv); + + drawable->texture_stamp = dPriv->lastStamp - 1; + + /* check if swapping currently bound buffer */ + if (ctx && ctx->dPriv == dPriv) + ctx->st->notify_invalid_framebuffer(ctx->st, &drawable->base); +} + +static INLINE void +drisw_copy_to_front(__DRIdrawable * dPriv, + struct pipe_resource *ptex) +{ + drisw_present_texture(dPriv, ptex); + + drisw_invalidate_drawable(dPriv); +} + +/* + * Backend functions for st_framebuffer interface and swap_buffers. + */ + +static void +drisw_swap_buffers(__DRIdrawable *dPriv) +{ + struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv); + struct dri_drawable *drawable = dri_drawable(dPriv); + struct pipe_resource *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); + } +} + +static void +drisw_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt) +{ + struct dri_context *ctx = dri_get_current(drawable->sPriv); + struct pipe_resource *ptex; + + if (!ctx) + return; + + ptex = drawable->textures[statt]; + + if (ptex) { + drisw_copy_to_front(ctx->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. + */ +static void +drisw_allocate_textures(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned count) +{ + struct dri_screen *screen = dri_screen(drawable->sPriv); + struct pipe_resource templ; + unsigned width, height; + boolean resized; + unsigned 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_resource_reference(&drawable->textures[i], NULL); + } + + memset(&templ, 0, sizeof(templ)); + templ.target = screen->target; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.array_size = 1; + templ.last_level = 0; + + for (i = 0; i < count; i++) { + enum pipe_format format; + unsigned bind; + + /* the texture already exists or not requested */ + if (drawable->textures[statts[i]]) + continue; + + dri_drawable_get_format(drawable, statts[i], &format, &bind); + + /* if we don't do any present, no need for display targets */ + if (statts[i] != ST_ATTACHMENT_DEPTH_STENCIL && !swrast_no_present) + bind |= PIPE_BIND_DISPLAY_TARGET; + + if (format == PIPE_FORMAT_NONE) + continue; + + templ.format = format; + templ.bind = bind; + + drawable->textures[statts[i]] = + screen->base.screen->resource_create(screen->base.screen, &templ); + } + + drawable->old_w = width; + drawable->old_h = height; +} + +/* + * Backend function for init_screen. + */ + +static const __DRIextension *drisw_screen_extensions[] = { + NULL +}; + +static struct drisw_loader_funcs drisw_lf = { + .put_image = drisw_put_image +}; + +static const __DRIconfig ** +drisw_init_screen(__DRIscreen * sPriv) +{ + const __DRIconfig **configs; + struct dri_screen *screen; + struct pipe_screen *pscreen; + + screen = CALLOC_STRUCT(dri_screen); + if (!screen) + return NULL; + + screen->sPriv = sPriv; + screen->fd = -1; + + swrast_no_present = debug_get_option_swrast_no_present(); + + sPriv->private = (void *)screen; + sPriv->extensions = drisw_screen_extensions; + + pscreen = drisw_create_screen(&drisw_lf); + /* dri_init_screen_helper checks pscreen for us */ + + configs = dri_init_screen_helper(screen, pscreen, 32); + if (!configs) + goto fail; + + return configs; +fail: + dri_destroy_screen_helper(screen); + FREE(screen); + return NULL; +} + +static boolean +drisw_create_buffer(__DRIscreen * sPriv, + __DRIdrawable * dPriv, + const struct gl_config * visual, boolean isPixmap) +{ + struct dri_drawable *drawable = NULL; + + if (!dri_create_buffer(sPriv, dPriv, visual, isPixmap)) + return FALSE; + + drawable = dPriv->driverPrivate; + + drawable->allocate_textures = drisw_allocate_textures; + drawable->update_drawable_info = drisw_update_drawable_info; + drawable->flush_frontbuffer = drisw_flush_frontbuffer; + + return TRUE; +} + +/** + * DRI driver virtual function table. + * + * DRI versions differ in their implementation of init_screen and swap_buffers. + */ +const struct __DriverAPIRec driDriverAPI = { + .InitScreen = drisw_init_screen, + .DestroyScreen = dri_destroy_screen, + .CreateContext = dri_create_context, + .DestroyContext = dri_destroy_context, + .CreateBuffer = drisw_create_buffer, + .DestroyBuffer = dri_destroy_buffer, + .MakeCurrent = dri_make_current, + .UnbindContext = dri_unbind_context, + + .SwapBuffers = drisw_swap_buffers, +}; + +/* This is the table of extensions that the loader will dlsym() for. */ +PUBLIC const __DRIextension *__driDriverExtensions[] = { + &driCoreExtension.base, + &driSWRastExtension.base, + NULL +}; + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/egl/Makefile b/src/gallium/state_trackers/egl/Makefile new file mode 100644 index 0000000..8cfcef9 --- /dev/null +++ b/src/gallium/state_trackers/egl/Makefile @@ -0,0 +1,96 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +common_INCLUDES = \ + -I. \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/egl/main \ + -I$(TOP)/include + +common_SOURCES = $(wildcard common/*.c) +common_OBJECTS = $(common_SOURCES:.c=.o) + +x11_INCLUDES = \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/glx \ + -I$(TOP)/src/mapi \ + -I$(TOP)/src/mesa \ + $(X11_CFLAGS) \ + $(shell pkg-config --cflags-only-I libdrm dri2proto) + +x11_SOURCES = $(wildcard x11/*.c) \ + $(TOP)/src/glx/dri2.c +x11_OBJECTS = $(x11_SOURCES:.c=.o) + + +drm_INCLUDES = -I$(TOP)/src/gallium/winsys $(shell pkg-config --cflags-only-I libdrm) +drm_SOURCES = $(wildcard drm/*.c) +drm_OBJECTS = $(drm_SOURCES:.c=.o) + + +fbdev_INCLUDES = -I$(TOP)/src/gallium/winsys/sw +fbdev_SOURCES = $(wildcard fbdev/*.c) +fbdev_OBJECTS = $(fbdev_SOURCES:.c=.o) + + +ALL_INCLUDES = $(common_INCLUDES) $(x11_INCLUDES) $(drm_INCLUDES) $(fbdev_INCLUDES) +ALL_SOURCES = $(common_SOURCES) $(x11_SOURCES) $(drm_SOURCES) $(fbdev_SOURCES) + +EGL_OBJECTS = $(common_OBJECTS) +EGL_CPPFLAGS = $(common_INCLUDES) + +# add backends +ifneq ($(findstring x11, $(EGL_PLATFORMS)),) +EGL_OBJECTS += $(x11_OBJECTS) +EGL_CPPFLAGS += -DHAVE_X11_BACKEND +endif +ifneq ($(findstring drm, $(EGL_PLATFORMS)),) +EGL_OBJECTS += $(drm_OBJECTS) +EGL_CPPFLAGS += -DHAVE_DRM_BACKEND +endif +ifneq ($(findstring fbdev, $(EGL_PLATFORMS)),) +EGL_OBJECTS += $(fbdev_OBJECTS) +EGL_CPPFLAGS += -DHAVE_FBDEV_BACKEND +endif + +##### TARGETS ##### + +default: depend libegl.a + +libegl.a: $(EGL_OBJECTS) Makefile + $(MKLIB) -o egl -static $(EGL_OBJECTS) + +depend: + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(ALL_INCLUDES) $(ALL_SOURCES) 2> /dev/null + +clean: + rm -f libegl.a + rm -f $(EGL_OBJECTS) + rm -f depend depend.bak + +# Dummy target +install: + @echo -n "" + +##### RULES ##### + +define egl-cc +$(CC) -c $(common_INCLUDES) $($(1)_INCLUDES) $(DEFINES) $(CFLAGS) $< -o $@ +endef + +$(common_OBJECTS): %.o: %.c + $(CC) -c $(EGL_CPPFLAGS) $(DEFINES) $(CFLAGS) $< -o $@ + +$(x11_OBJECTS): %.o: %.c + $(call egl-cc,x11) + +$(drm_OBJECTS): %.o: %.c + $(call egl-cc,drm) + +$(fbdev_OBJECTS): %.o: %.c + $(call egl-cc,fbdev) + +sinclude depend diff --git a/src/gallium/state_trackers/egl/SConscript b/src/gallium/state_trackers/egl/SConscript new file mode 100644 index 0000000..50c7681 --- /dev/null +++ b/src/gallium/state_trackers/egl/SConscript @@ -0,0 +1,34 @@ +####################################################################### +# SConscript for egl state_tracker + +Import('*') + +env = env.Clone() + +env.Append(CPPPATH = [ + '#/src/egl/main', + '#/src/gallium/winsys/sw', + '.', +]) +env.Append(CPPDEFINES = [ + 'HAVE_GDI_BACKEND', +]) + +common_sources = [ + 'common/egl_g3d.c', + 'common/egl_g3d_api.c', + 'common/egl_g3d_image.c', + 'common/egl_g3d_st.c', + 'common/egl_g3d_sync.c', + 'common/native_helper.c', +] + +gdi_sources = common_sources + [ + 'gdi/native_gdi.c', +] + +st_egl_gdi = env.ConvenienceLibrary( + target = 'st_egl_gdi', + source = gdi_sources, +) +Export('st_egl_gdi') diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c new file mode 100644 index 0000000..a3750ac --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -0,0 +1,627 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2009-2010 Chia-I Wu + * + * 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 "egldriver.h" +#include "eglcurrent.h" +#include "egllog.h" + +#include "pipe/p_screen.h" +#include "util/u_memory.h" +#include "util/u_format.h" +#include "util/u_string.h" + +#include "egl_g3d.h" +#include "egl_g3d_api.h" +#include "egl_g3d_st.h" +#include "egl_g3d_loader.h" +#include "native.h" + +/** + * Get the native platform. + */ +static const struct native_platform * +egl_g3d_get_platform(_EGLDriver *drv, _EGLPlatformType plat) +{ + struct egl_g3d_driver *gdrv = egl_g3d_driver(drv); + + if (!gdrv->platforms[plat]) { + const char *plat_name = NULL; + const struct native_platform *nplat = NULL; + + switch (plat) { + case _EGL_PLATFORM_WINDOWS: + plat_name = "Windows"; +#ifdef HAVE_GDI_BACKEND + nplat = native_get_gdi_platform(); +#endif + break; + case _EGL_PLATFORM_X11: + plat_name = "X11"; +#ifdef HAVE_X11_BACKEND + nplat = native_get_x11_platform(); +#endif + break; + case _EGL_PLATFORM_DRM: + plat_name = "DRM"; +#ifdef HAVE_DRM_BACKEND + nplat = native_get_drm_platform(); +#endif + break; + case _EGL_PLATFORM_FBDEV: + plat_name = "FBDEV"; +#ifdef HAVE_FBDEV_BACKEND + nplat = native_get_fbdev_platform(); +#endif + break; + default: + break; + } + + if (!nplat) + _eglLog(_EGL_WARNING, "unsupported platform %s", plat_name); + + gdrv->platforms[plat] = nplat; + } + + return gdrv->platforms[plat]; +} + +#ifdef EGL_MESA_screen_surface + +static void +egl_g3d_add_screens(_EGLDriver *drv, _EGLDisplay *dpy) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + const struct native_connector **native_connectors; + EGLint num_connectors, i; + + native_connectors = + gdpy->native->modeset->get_connectors(gdpy->native, &num_connectors, NULL); + if (!num_connectors) { + if (native_connectors) + FREE(native_connectors); + return; + } + + for (i = 0; i < num_connectors; i++) { + const struct native_connector *nconn = native_connectors[i]; + struct egl_g3d_screen *gscr; + const struct native_mode **native_modes; + EGLint num_modes, j; + + /* TODO support for hotplug */ + native_modes = + gdpy->native->modeset->get_modes(gdpy->native, nconn, &num_modes); + if (!num_modes) { + if (native_modes) + FREE(native_modes); + continue; + } + + gscr = CALLOC_STRUCT(egl_g3d_screen); + if (!gscr) { + FREE(native_modes); + continue; + } + + _eglInitScreen(&gscr->base, dpy, num_modes); + for (j = 0; j < gscr->base.NumModes; j++) { + const struct native_mode *nmode = native_modes[j]; + _EGLMode *mode = &gscr->base.Modes[j]; + + mode->Width = nmode->width; + mode->Height = nmode->height; + mode->RefreshRate = nmode->refresh_rate; + mode->Optimal = EGL_FALSE; + mode->Interlaced = EGL_FALSE; + /* no need to strdup() */ + mode->Name = nmode->desc; + } + + gscr->native = nconn; + gscr->native_modes = native_modes; + + _eglLinkScreen(&gscr->base); + } + + FREE(native_connectors); +} + +#endif /* EGL_MESA_screen_surface */ + +/** + * Initialize and validate the EGL config attributes. + */ +static EGLBoolean +init_config_attributes(_EGLConfig *conf, const struct native_config *nconf, + EGLint api_mask, enum pipe_format depth_stencil_format, + EGLBoolean preserve_buffer, EGLint max_swap_interval) +{ + uint rgba[4], depth_stencil[2], buffer_size; + EGLint surface_type; + EGLint i; + + /* get the color and depth/stencil component sizes */ + assert(nconf->color_format != PIPE_FORMAT_NONE); + buffer_size = 0; + for (i = 0; i < 4; i++) { + rgba[i] = util_format_get_component_bits(nconf->color_format, + UTIL_FORMAT_COLORSPACE_RGB, i); + buffer_size += rgba[i]; + } + for (i = 0; i < 2; i++) { + if (depth_stencil_format != PIPE_FORMAT_NONE) { + depth_stencil[i] = + util_format_get_component_bits(depth_stencil_format, + UTIL_FORMAT_COLORSPACE_ZS, i); + } + else { + depth_stencil[i] = 0; + } + } + + surface_type = 0x0; + if (nconf->window_bit) + surface_type |= EGL_WINDOW_BIT; + if (nconf->pixmap_bit) + surface_type |= EGL_PIXMAP_BIT; +#ifdef EGL_MESA_screen_surface + if (nconf->scanout_bit) + surface_type |= EGL_SCREEN_BIT_MESA; +#endif + + if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_BACK_LEFT)) + surface_type |= EGL_PBUFFER_BIT; + + conf->Conformant = api_mask; + conf->RenderableType = api_mask; + + conf->RedSize = rgba[0]; + conf->GreenSize = rgba[1]; + conf->BlueSize = rgba[2]; + conf->AlphaSize = rgba[3]; + conf->BufferSize = buffer_size; + + conf->DepthSize = depth_stencil[0]; + conf->StencilSize = depth_stencil[1]; + + conf->SurfaceType = surface_type; + + conf->NativeRenderable = EGL_TRUE; + if (surface_type & EGL_WINDOW_BIT) { + conf->NativeVisualID = nconf->native_visual_id; + conf->NativeVisualType = nconf->native_visual_type; + } + + if (surface_type & EGL_PBUFFER_BIT) { + conf->BindToTextureRGB = EGL_TRUE; + if (rgba[3]) + conf->BindToTextureRGBA = EGL_TRUE; + + conf->MaxPbufferWidth = 4096; + conf->MaxPbufferHeight = 4096; + conf->MaxPbufferPixels = 4096 * 4096; + } + + conf->Level = nconf->level; + conf->Samples = nconf->samples; + conf->SampleBuffers = 0; + + if (nconf->slow_config) + conf->ConfigCaveat = EGL_SLOW_CONFIG; + + if (nconf->transparent_rgb) { + conf->TransparentType = EGL_TRANSPARENT_RGB; + conf->TransparentRedValue = nconf->transparent_rgb_values[0]; + conf->TransparentGreenValue = nconf->transparent_rgb_values[1]; + conf->TransparentBlueValue = nconf->transparent_rgb_values[2]; + } + + conf->MinSwapInterval = 0; + conf->MaxSwapInterval = max_swap_interval; + if (preserve_buffer) + conf->SurfaceType |= EGL_SWAP_BEHAVIOR_PRESERVED_BIT; + + return _eglValidateConfig(conf, EGL_FALSE); +} + +/** + * Initialize an EGL config from the native config. + */ +static EGLBoolean +egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLConfig *conf, const struct native_config *nconf, + enum pipe_format depth_stencil_format, + int preserve_buffer, int max_swap_interval) +{ + struct egl_g3d_config *gconf = egl_g3d_config(conf); + EGLint buffer_mask, api_mask; + EGLBoolean valid; + + /* skip single-buffered configs */ + if (!(nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_BACK_LEFT))) + return EGL_FALSE; + + buffer_mask = 0x0; + if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_FRONT_LEFT)) + buffer_mask |= ST_ATTACHMENT_FRONT_LEFT_MASK; + if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_BACK_LEFT)) + buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK; + if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_FRONT_RIGHT)) + buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK; + if (nconf->buffer_mask & (1 << NATIVE_ATTACHMENT_BACK_RIGHT)) + buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK; + + gconf->stvis.buffer_mask = buffer_mask; + gconf->stvis.color_format = nconf->color_format; + gconf->stvis.depth_stencil_format = depth_stencil_format; + gconf->stvis.accum_format = PIPE_FORMAT_NONE; + gconf->stvis.samples = nconf->samples; + + gconf->stvis.render_buffer = (buffer_mask & ST_ATTACHMENT_BACK_LEFT_MASK) ? + ST_ATTACHMENT_BACK_LEFT : ST_ATTACHMENT_FRONT_LEFT; + + api_mask = dpy->ClientAPIsMask; + /* this is required by EGL, not by OpenGL ES */ + if (nconf->window_bit && + gconf->stvis.render_buffer != ST_ATTACHMENT_BACK_LEFT) + api_mask &= ~(EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT); + + if (!api_mask) { + _eglLog(_EGL_DEBUG, "no state tracker supports config 0x%x", + nconf->native_visual_id); + } + + valid = init_config_attributes(&gconf->base, + nconf, api_mask, depth_stencil_format, + preserve_buffer, max_swap_interval); + if (!valid) { + _eglLog(_EGL_DEBUG, "skip invalid config 0x%x", nconf->native_visual_id); + return EGL_FALSE; + } + + gconf->native = nconf; + + return EGL_TRUE; +} + +/** + * Get all interested depth/stencil formats of a display. + */ +static EGLint +egl_g3d_fill_depth_stencil_formats(_EGLDisplay *dpy, + enum pipe_format formats[8]) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct pipe_screen *screen = gdpy->native->screen; + const EGLint candidates[] = { + 1, PIPE_FORMAT_Z16_UNORM, + 1, PIPE_FORMAT_Z32_UNORM, + 2, PIPE_FORMAT_Z24_UNORM_S8_USCALED, PIPE_FORMAT_S8_USCALED_Z24_UNORM, + 2, PIPE_FORMAT_Z24X8_UNORM, PIPE_FORMAT_X8Z24_UNORM, + 0 + }; + const EGLint *fmt = candidates; + EGLint count; + + count = 0; + formats[count++] = PIPE_FORMAT_NONE; + + while (*fmt) { + EGLint i, n = *fmt++; + + /* pick the first supported format */ + for (i = 0; i < n; i++) { + if (screen->is_format_supported(screen, fmt[i], + PIPE_TEXTURE_2D, 0, PIPE_BIND_DEPTH_STENCIL, 0)) { + formats[count++] = fmt[i]; + break; + } + } + + fmt += n; + } + + return count; +} + +/** + * Add configs to display and return the next config ID. + */ +static EGLint +egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + const struct native_config **native_configs; + enum pipe_format depth_stencil_formats[8]; + int num_formats, num_configs, i, j; + int preserve_buffer, max_swap_interval; + + native_configs = gdpy->native->get_configs(gdpy->native, &num_configs); + if (!num_configs) { + if (native_configs) + FREE(native_configs); + return id; + } + + preserve_buffer = + gdpy->native->get_param(gdpy->native, NATIVE_PARAM_PRESERVE_BUFFER); + max_swap_interval = + gdpy->native->get_param(gdpy->native, NATIVE_PARAM_MAX_SWAP_INTERVAL); + + num_formats = egl_g3d_fill_depth_stencil_formats(dpy, + depth_stencil_formats); + + for (i = 0; i < num_configs; i++) { + for (j = 0; j < num_formats; j++) { + struct egl_g3d_config *gconf; + + gconf = CALLOC_STRUCT(egl_g3d_config); + if (gconf) { + _eglInitConfig(&gconf->base, dpy, id); + if (!egl_g3d_init_config(drv, dpy, &gconf->base, + native_configs[i], depth_stencil_formats[j], + preserve_buffer, max_swap_interval)) { + FREE(gconf); + break; + } + + _eglLinkConfig(&gconf->base); + id++; + } + } + } + + FREE(native_configs); + return id; +} + +static void +egl_g3d_invalid_surface(struct native_display *ndpy, + struct native_surface *nsurf, + unsigned int seq_num) +{ + /* XXX not thread safe? */ + struct egl_g3d_surface *gsurf = egl_g3d_surface(nsurf->user_data); + struct egl_g3d_context *gctx; + + /* + * Some functions such as egl_g3d_copy_buffers create a temporary native + * surface. There is no gsurf associated with it. + */ + gctx = (gsurf) ? egl_g3d_context(gsurf->base.CurrentContext) : NULL; + if (gctx) + gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, gsurf->stfbi); +} + +static struct pipe_screen * +egl_g3d_new_drm_screen(struct native_display *ndpy, const char *name, int fd) +{ + _EGLDisplay *dpy = (_EGLDisplay *) ndpy->user_data; + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + return gdpy->loader->create_drm_screen(name, fd); +} + +static struct pipe_screen * +egl_g3d_new_sw_screen(struct native_display *ndpy, struct sw_winsys *ws) +{ + _EGLDisplay *dpy = (_EGLDisplay *) ndpy->user_data; + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + return gdpy->loader->create_sw_screen(ws); +} + +static struct native_event_handler egl_g3d_native_event_handler = { + egl_g3d_invalid_surface, + egl_g3d_new_drm_screen, + egl_g3d_new_sw_screen +}; + +static void +egl_g3d_free_config(void *conf) +{ + struct egl_g3d_config *gconf = egl_g3d_config((_EGLConfig *) conf); + FREE(gconf); +} + +static void +egl_g3d_free_screen(void *scr) +{ +#ifdef EGL_MESA_screen_surface + struct egl_g3d_screen *gscr = egl_g3d_screen((_EGLScreen *) scr); + FREE(gscr->native_modes); + FREE(gscr); +#endif +} + +static EGLBoolean +egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + + _eglReleaseDisplayResources(drv, dpy); + + if (gdpy->pipe) + gdpy->pipe->destroy(gdpy->pipe); + + if (dpy->Configs) { + _eglDestroyArray(dpy->Configs, egl_g3d_free_config); + dpy->Configs = NULL; + } + if (dpy->Screens) { + _eglDestroyArray(dpy->Screens, egl_g3d_free_screen); + dpy->Screens = NULL; + } + + _eglCleanupDisplay(dpy); + + if (gdpy->smapi) + egl_g3d_destroy_st_manager(gdpy->smapi); + + if (gdpy->native) + gdpy->native->destroy(gdpy->native); + + FREE(gdpy); + dpy->DriverData = NULL; + + return EGL_TRUE; +} + +static EGLBoolean +egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy, + EGLint *major, EGLint *minor) +{ + struct egl_g3d_driver *gdrv = egl_g3d_driver(drv); + struct egl_g3d_display *gdpy; + const struct native_platform *nplat; + + nplat = egl_g3d_get_platform(drv, dpy->Platform); + if (!nplat) + return EGL_FALSE; + + gdpy = CALLOC_STRUCT(egl_g3d_display); + if (!gdpy) { + _eglError(EGL_BAD_ALLOC, "eglInitialize"); + goto fail; + } + gdpy->loader = gdrv->loader; + dpy->DriverData = gdpy; + + _eglLog(_EGL_INFO, "use %s for display %p", nplat->name, dpy->PlatformDisplay); + gdpy->native = nplat->create_display(dpy->PlatformDisplay, + &egl_g3d_native_event_handler, (void *) dpy); + if (!gdpy->native) { + _eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)"); + goto fail; + } + + if (gdpy->loader->profile_masks[ST_API_OPENGL] & ST_PROFILE_DEFAULT_MASK) + dpy->ClientAPIsMask |= EGL_OPENGL_BIT; + if (gdpy->loader->profile_masks[ST_API_OPENGL] & ST_PROFILE_OPENGL_ES1_MASK) + dpy->ClientAPIsMask |= EGL_OPENGL_ES_BIT; + if (gdpy->loader->profile_masks[ST_API_OPENGL] & ST_PROFILE_OPENGL_ES2_MASK) + dpy->ClientAPIsMask |= EGL_OPENGL_ES2_BIT; + if (gdpy->loader->profile_masks[ST_API_OPENVG] & ST_PROFILE_DEFAULT_MASK) + dpy->ClientAPIsMask |= EGL_OPENVG_BIT; + + gdpy->smapi = egl_g3d_create_st_manager(dpy); + if (!gdpy->smapi) { + _eglError(EGL_NOT_INITIALIZED, + "eglInitialize(failed to create st manager)"); + goto fail; + } + +#ifdef EGL_MESA_screen_surface + /* enable MESA_screen_surface before adding (and validating) configs */ + if (gdpy->native->modeset) { + dpy->Extensions.MESA_screen_surface = EGL_TRUE; + egl_g3d_add_screens(drv, dpy); + } +#endif + + dpy->Extensions.KHR_image_base = EGL_TRUE; + if (gdpy->native->get_param(gdpy->native, NATIVE_PARAM_USE_NATIVE_BUFFER)) + dpy->Extensions.KHR_image_pixmap = EGL_TRUE; + + dpy->Extensions.KHR_reusable_sync = EGL_TRUE; + dpy->Extensions.KHR_fence_sync = EGL_TRUE; + + dpy->Extensions.KHR_surfaceless_gles1 = EGL_TRUE; + dpy->Extensions.KHR_surfaceless_gles2 = EGL_TRUE; + dpy->Extensions.KHR_surfaceless_opengl = EGL_TRUE; + + if (dpy->Platform == _EGL_PLATFORM_DRM) { + dpy->Extensions.MESA_drm_display = EGL_TRUE; + if (gdpy->native->buffer) + dpy->Extensions.MESA_drm_image = EGL_TRUE; + } + + if (egl_g3d_add_configs(drv, dpy, 1) == 1) { + _eglError(EGL_NOT_INITIALIZED, "eglInitialize(unable to add configs)"); + goto fail; + } + + *major = 1; + *minor = 4; + + return EGL_TRUE; + +fail: + if (gdpy) + egl_g3d_terminate(drv, dpy); + return EGL_FALSE; +} + +static _EGLProc +egl_g3d_get_proc_address(_EGLDriver *drv, const char *procname) +{ + struct egl_g3d_driver *gdrv = egl_g3d_driver(drv); + struct st_api *stapi = NULL; + + if (procname && procname[0] == 'v' && procname[1] == 'g') + stapi = gdrv->loader->get_st_api(ST_API_OPENVG); + else if (procname && procname[0] == 'g' && procname[1] == 'l') + stapi = gdrv->loader->get_st_api(ST_API_OPENGL); + + return (_EGLProc) ((stapi) ? + stapi->get_proc_address(stapi, procname) : NULL); +} + +static EGLint +egl_g3d_probe(_EGLDriver *drv, _EGLDisplay *dpy) +{ + return (egl_g3d_get_platform(drv, dpy->Platform)) ? 90 : 0; +} + +_EGLDriver * +egl_g3d_create_driver(const struct egl_g3d_loader *loader) +{ + struct egl_g3d_driver *gdrv; + + gdrv = CALLOC_STRUCT(egl_g3d_driver); + if (!gdrv) + return NULL; + + gdrv->loader = loader; + + egl_g3d_init_driver_api(&gdrv->base); + gdrv->base.API.Initialize = egl_g3d_initialize; + gdrv->base.API.Terminate = egl_g3d_terminate; + gdrv->base.API.GetProcAddress = egl_g3d_get_proc_address; + + gdrv->base.Probe = egl_g3d_probe; + + /* to be filled by the caller */ + gdrv->base.Name = NULL; + gdrv->base.Unload = NULL; + + return &gdrv->base; +} + +void +egl_g3d_destroy_driver(_EGLDriver *drv) +{ + struct egl_g3d_driver *gdrv = egl_g3d_driver(drv); + FREE(gdrv); +} diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.h b/src/gallium/state_trackers/egl/common/egl_g3d.h new file mode 100644 index 0000000..9873fee --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d.h @@ -0,0 +1,130 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2009-2010 Chia-I Wu + * + * 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 _EGL_G3D_H_ +#define _EGL_G3D_H_ + +#include "pipe/p_compiler.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_format.h" +#include "os/os_thread.h" +#include "egldriver.h" +#include "egldisplay.h" +#include "eglcontext.h" +#include "eglsurface.h" +#include "eglconfig.h" +#include "eglimage.h" +#include "eglsync.h" +#include "eglscreen.h" +#include "eglmode.h" + +#include "native.h" +#include "egl_g3d_st.h" +#include "egl_g3d_loader.h" + +struct egl_g3d_driver { + _EGLDriver base; + const struct egl_g3d_loader *loader; + const struct native_platform *platforms[_EGL_NUM_PLATFORMS]; +}; + +struct egl_g3d_display { + struct native_display *native; + + const struct egl_g3d_loader *loader; + struct st_manager *smapi; + struct pipe_context *pipe; +}; + +struct egl_g3d_context { + _EGLContext base; + + struct st_api *stapi; + + struct st_context_iface *stctxi; +}; + +struct egl_g3d_surface { + _EGLSurface base; + + struct st_visual stvis; + struct st_framebuffer_iface *stfbi; + + /* the native surface; NULL for pbuffers */ + struct native_surface *native; + struct pipe_resource *render_texture; + + EGLenum client_buffer_type; + EGLClientBuffer client_buffer; + + unsigned int sequence_number; +}; + +struct egl_g3d_config { + _EGLConfig base; + const struct native_config *native; + struct st_visual stvis; +}; + +struct egl_g3d_image { + _EGLImage base; + struct pipe_resource *texture; + unsigned level; + unsigned layer; +}; + +/* standard typecasts */ +_EGL_DRIVER_STANDARD_TYPECASTS(egl_g3d) +_EGL_DRIVER_TYPECAST(egl_g3d_image, _EGLImage, obj) + +#ifdef EGL_KHR_reusable_sync + +struct egl_g3d_sync { + _EGLSync base; + + /* the mutex protects only the condvar, not the struct */ + pipe_mutex mutex; + pipe_condvar condvar; + + /* for fence sync */ + struct pipe_fence_handle *fence; +}; +_EGL_DRIVER_TYPECAST(egl_g3d_sync, _EGLSync, obj) + +#endif /* EGL_KHR_reusable_sync */ + +#ifdef EGL_MESA_screen_surface + +struct egl_g3d_screen { + _EGLScreen base; + const struct native_connector *native; + const struct native_mode **native_modes; +}; +_EGL_DRIVER_TYPECAST(egl_g3d_screen, _EGLScreen, obj) + +#endif /* EGL_MESA_screen_surface */ + +#endif /* _EGL_G3D_H_ */ diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_api.c b/src/gallium/state_trackers/egl/common/egl_g3d_api.c new file mode 100644 index 0000000..169a441 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_api.c @@ -0,0 +1,944 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2009-2010 Chia-I Wu + * + * 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 "egldriver.h" +#include "eglcurrent.h" +#include "egllog.h" + +#include "pipe/p_screen.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "util/u_box.h" + +#include "egl_g3d.h" +#include "egl_g3d_api.h" +#include "egl_g3d_image.h" +#include "egl_g3d_sync.h" +#include "egl_g3d_st.h" +#include "egl_g3d_loader.h" +#include "native.h" + +/** + * Return the state tracker for the given context. + */ +static struct st_api * +egl_g3d_choose_st(_EGLDriver *drv, _EGLContext *ctx, + enum st_profile_type *profile) +{ + struct egl_g3d_driver *gdrv = egl_g3d_driver(drv); + struct st_api *stapi; + EGLint api = -1; + + *profile = ST_PROFILE_DEFAULT; + + switch (ctx->ClientAPI) { + case EGL_OPENGL_ES_API: + switch (ctx->ClientVersion) { + case 1: + api = ST_API_OPENGL; + *profile = ST_PROFILE_OPENGL_ES1; + break; + case 2: + api = ST_API_OPENGL; + *profile = ST_PROFILE_OPENGL_ES2; + break; + default: + _eglLog(_EGL_WARNING, "unknown client version %d", + ctx->ClientVersion); + break; + } + break; + case EGL_OPENVG_API: + api = ST_API_OPENVG; + break; + case EGL_OPENGL_API: + api = ST_API_OPENGL; + break; + default: + _eglLog(_EGL_WARNING, "unknown client API 0x%04x", ctx->ClientAPI); + break; + } + + switch (api) { + case ST_API_OPENGL: + stapi = gdrv->loader->guess_gl_api(*profile); + break; + case ST_API_OPENVG: + stapi = gdrv->loader->get_st_api(api); + break; + default: + stapi = NULL; + break; + } + if (stapi && !(stapi->profile_mask & (1 << *profile))) + stapi = NULL; + + return stapi; +} + +static int +egl_g3d_compare_config(const _EGLConfig *conf1, const _EGLConfig *conf2, + void *priv_data) +{ + const _EGLConfig *criteria = (const _EGLConfig *) priv_data; + + /* EGL_NATIVE_VISUAL_TYPE ignored? */ + return _eglCompareConfigs(conf1, conf2, criteria, EGL_TRUE); +} + +static EGLBoolean +egl_g3d_match_config(const _EGLConfig *conf, const _EGLConfig *criteria) +{ + if (!_eglMatchConfig(conf, criteria)) + return EGL_FALSE; + + if (criteria->MatchNativePixmap != EGL_NONE && + criteria->MatchNativePixmap != EGL_DONT_CARE) { + struct egl_g3d_display *gdpy = egl_g3d_display(conf->Display); + struct egl_g3d_config *gconf = egl_g3d_config(conf); + EGLNativePixmapType pix = + (EGLNativePixmapType) criteria->MatchNativePixmap; + + if (!gdpy->native->is_pixmap_supported(gdpy->native, pix, gconf->native)) + return EGL_FALSE; + } + + return EGL_TRUE; +} + +static EGLBoolean +egl_g3d_choose_config(_EGLDriver *drv, _EGLDisplay *dpy, const EGLint *attribs, + EGLConfig *configs, EGLint size, EGLint *num_configs) +{ + _EGLConfig **tmp_configs, criteria; + EGLint tmp_size, i; + + if (!num_configs) + return _eglError(EGL_BAD_PARAMETER, "eglChooseConfigs"); + + if (!_eglParseConfigAttribList(&criteria, dpy, attribs)) + return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig"); + + /* get the number of matched configs */ + tmp_size = _eglFilterArray(dpy->Configs, NULL, 0, + (_EGLArrayForEach) egl_g3d_match_config, (void *) &criteria); + if (!tmp_size) { + *num_configs = tmp_size; + return EGL_TRUE; + } + + tmp_configs = MALLOC(sizeof(tmp_configs[0]) * tmp_size); + if (!tmp_configs) + return _eglError(EGL_BAD_ALLOC, "eglChooseConfig(out of memory)"); + + /* get the matched configs */ + _eglFilterArray(dpy->Configs, (void **) tmp_configs, tmp_size, + (_EGLArrayForEach) egl_g3d_match_config, (void *) &criteria); + + /* perform sorting of configs */ + if (configs && tmp_size) { + _eglSortConfigs((const _EGLConfig **) tmp_configs, tmp_size, + egl_g3d_compare_config, (void *) &criteria); + tmp_size = MIN2(tmp_size, size); + for (i = 0; i < tmp_size; i++) + configs[i] = _eglGetConfigHandle(tmp_configs[i]); + } + + FREE(tmp_configs); + + *num_configs = tmp_size; + + return EGL_TRUE; +} + +static _EGLContext * +egl_g3d_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, + _EGLContext *share, const EGLint *attribs) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_context *gshare = egl_g3d_context(share); + struct egl_g3d_config *gconf = egl_g3d_config(conf); + struct egl_g3d_context *gctx; + struct st_context_attribs stattribs; + + gctx = CALLOC_STRUCT(egl_g3d_context); + if (!gctx) { + _eglError(EGL_BAD_ALLOC, "eglCreateContext"); + return NULL; + } + + if (!_eglInitContext(&gctx->base, dpy, conf, attribs)) { + FREE(gctx); + return NULL; + } + + memset(&stattribs, 0, sizeof(stattribs)); + if (gconf) + stattribs.visual = gconf->stvis; + + gctx->stapi = egl_g3d_choose_st(drv, &gctx->base, &stattribs.profile); + if (!gctx->stapi) { + FREE(gctx); + return NULL; + } + + gctx->stctxi = gctx->stapi->create_context(gctx->stapi, gdpy->smapi, + &stattribs, (gshare) ? gshare->stctxi : NULL); + if (!gctx->stctxi) { + FREE(gctx); + return NULL; + } + + gctx->stctxi->st_manager_private = (void *) &gctx->base; + + return &gctx->base; +} + +/** + * Destroy a context. + */ +static void +destroy_context(_EGLDisplay *dpy, _EGLContext *ctx) +{ + struct egl_g3d_context *gctx = egl_g3d_context(ctx); + + /* FIXME a context might live longer than its display */ + if (!dpy->Initialized) + _eglLog(_EGL_FATAL, "destroy a context with an unitialized display"); + + gctx->stctxi->destroy(gctx->stctxi); + + FREE(gctx); +} + +static EGLBoolean +egl_g3d_destroy_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx) +{ + if (_eglPutContext(ctx)) + destroy_context(dpy, ctx); + return EGL_TRUE; +} + +struct egl_g3d_create_surface_arg { + EGLint type; + union { + EGLNativeWindowType win; + EGLNativePixmapType pix; + } u; +}; + +static _EGLSurface * +egl_g3d_create_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, + struct egl_g3d_create_surface_arg *arg, + const EGLint *attribs) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_config *gconf = egl_g3d_config(conf); + struct egl_g3d_surface *gsurf; + struct native_surface *nsurf; + const char *err; + + switch (arg->type) { + case EGL_WINDOW_BIT: + err = "eglCreateWindowSurface"; + break; + case EGL_PIXMAP_BIT: + err = "eglCreatePixmapSurface"; + break; +#ifdef EGL_MESA_screen_surface + case EGL_SCREEN_BIT_MESA: + err = "eglCreateScreenSurface"; + break; +#endif + default: + err = "eglCreateUnknownSurface"; + break; + } + + gsurf = CALLOC_STRUCT(egl_g3d_surface); + if (!gsurf) { + _eglError(EGL_BAD_ALLOC, err); + return NULL; + } + + if (!_eglInitSurface(&gsurf->base, dpy, arg->type, conf, attribs)) { + FREE(gsurf); + return NULL; + } + + /* create the native surface */ + switch (arg->type) { + case EGL_WINDOW_BIT: + nsurf = gdpy->native->create_window_surface(gdpy->native, + arg->u.win, gconf->native); + break; + case EGL_PIXMAP_BIT: + nsurf = gdpy->native->create_pixmap_surface(gdpy->native, + arg->u.pix, gconf->native); + break; +#ifdef EGL_MESA_screen_surface + case EGL_SCREEN_BIT_MESA: + /* prefer back buffer (move to _eglInitSurface?) */ + gsurf->base.RenderBuffer = EGL_BACK_BUFFER; + nsurf = gdpy->native->modeset->create_scanout_surface(gdpy->native, + gconf->native, gsurf->base.Width, gsurf->base.Height); + break; +#endif + default: + nsurf = NULL; + break; + } + + if (!nsurf) { + FREE(gsurf); + return NULL; + } + /* initialize the geometry */ + if (!nsurf->validate(nsurf, 0x0, &gsurf->sequence_number, NULL, + &gsurf->base.Width, &gsurf->base.Height)) { + nsurf->destroy(nsurf); + FREE(gsurf); + return NULL; + } + + gsurf->stvis = gconf->stvis; + if (gsurf->base.RenderBuffer == EGL_SINGLE_BUFFER) + gsurf->stvis.render_buffer = ST_ATTACHMENT_FRONT_LEFT; + + gsurf->stfbi = egl_g3d_create_st_framebuffer(&gsurf->base); + if (!gsurf->stfbi) { + nsurf->destroy(nsurf); + FREE(gsurf); + return NULL; + } + + nsurf->user_data = &gsurf->base; + gsurf->native = nsurf; + + return &gsurf->base; +} + +static _EGLSurface * +egl_g3d_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLConfig *conf, EGLNativeWindowType win, + const EGLint *attribs) +{ + struct egl_g3d_create_surface_arg arg; + + memset(&arg, 0, sizeof(arg)); + arg.type = EGL_WINDOW_BIT; + arg.u.win = win; + + return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); +} + +static _EGLSurface * +egl_g3d_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLConfig *conf, EGLNativePixmapType pix, + const EGLint *attribs) +{ + struct egl_g3d_create_surface_arg arg; + + memset(&arg, 0, sizeof(arg)); + arg.type = EGL_PIXMAP_BIT; + arg.u.pix = pix; + + return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); +} + +static struct egl_g3d_surface * +create_pbuffer_surface(_EGLDisplay *dpy, _EGLConfig *conf, + const EGLint *attribs, const char *func) +{ + struct egl_g3d_config *gconf = egl_g3d_config(conf); + struct egl_g3d_surface *gsurf; + + gsurf = CALLOC_STRUCT(egl_g3d_surface); + if (!gsurf) { + _eglError(EGL_BAD_ALLOC, func); + return NULL; + } + + if (!_eglInitSurface(&gsurf->base, dpy, EGL_PBUFFER_BIT, conf, attribs)) { + FREE(gsurf); + return NULL; + } + + gsurf->stvis = gconf->stvis; + + gsurf->stfbi = egl_g3d_create_st_framebuffer(&gsurf->base); + if (!gsurf->stfbi) { + FREE(gsurf); + return NULL; + } + + return gsurf; +} + +static _EGLSurface * +egl_g3d_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLConfig *conf, const EGLint *attribs) +{ + struct egl_g3d_surface *gsurf; + + gsurf = create_pbuffer_surface(dpy, conf, attribs, + "eglCreatePbufferSurface"); + if (!gsurf) + return NULL; + + gsurf->client_buffer_type = EGL_NONE; + + return &gsurf->base; +} + +static _EGLSurface * +egl_g3d_create_pbuffer_from_client_buffer(_EGLDriver *drv, _EGLDisplay *dpy, + EGLenum buftype, + EGLClientBuffer buffer, + _EGLConfig *conf, + const EGLint *attribs) +{ + struct egl_g3d_surface *gsurf; + struct pipe_resource *ptex = NULL; + EGLint pbuffer_attribs[32]; + EGLint count, i; + + switch (buftype) { + case EGL_OPENVG_IMAGE: + break; + default: + _eglError(EGL_BAD_PARAMETER, "eglCreatePbufferFromClientBuffer"); + return NULL; + break; + } + + /* parse the attributes first */ + count = 0; + for (i = 0; attribs && attribs[i] != EGL_NONE; i++) { + EGLint attr = attribs[i++]; + EGLint val = attribs[i]; + EGLint err = EGL_SUCCESS; + + switch (attr) { + case EGL_TEXTURE_FORMAT: + case EGL_TEXTURE_TARGET: + case EGL_MIPMAP_TEXTURE: + pbuffer_attribs[count++] = attr; + pbuffer_attribs[count++] = val; + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + /* bail out */ + if (err != EGL_SUCCESS) { + _eglError(err, "eglCreatePbufferFromClientBuffer"); + return NULL; + } + } + + pbuffer_attribs[count++] = EGL_NONE; + + gsurf = create_pbuffer_surface(dpy, conf, pbuffer_attribs, + "eglCreatePbufferFromClientBuffer"); + if (!gsurf) + return NULL; + + gsurf->client_buffer_type = buftype; + gsurf->client_buffer = buffer; + + /* validate now so that it fails if the client buffer is invalid */ + if (!gsurf->stfbi->validate(gsurf->stfbi, + &gsurf->stvis.render_buffer, 1, &ptex)) { + egl_g3d_destroy_st_framebuffer(gsurf->stfbi); + FREE(gsurf); + return NULL; + } + pipe_resource_reference(&ptex, NULL); + + return &gsurf->base; +} + +/** + * Destroy a surface. + */ +static void +destroy_surface(_EGLDisplay *dpy, _EGLSurface *surf) +{ + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + + /* FIXME a surface might live longer than its display */ + if (!dpy->Initialized) + _eglLog(_EGL_FATAL, "destroy a surface with an unitialized display"); + + pipe_resource_reference(&gsurf->render_texture, NULL); + egl_g3d_destroy_st_framebuffer(gsurf->stfbi); + if (gsurf->native) + gsurf->native->destroy(gsurf->native); + FREE(gsurf); +} + +static EGLBoolean +egl_g3d_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) +{ + if (_eglPutSurface(surf)) + destroy_surface(dpy, surf); + return EGL_TRUE; +} + +static EGLBoolean +egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx) +{ + struct egl_g3d_context *gctx = egl_g3d_context(ctx); + struct egl_g3d_surface *gdraw = egl_g3d_surface(draw); + struct egl_g3d_surface *gread = egl_g3d_surface(read); + struct egl_g3d_context *old_gctx; + _EGLContext *old_ctx; + _EGLSurface *old_draw, *old_read; + EGLBoolean ok = EGL_TRUE; + + /* make new bindings */ + if (!_eglBindContext(ctx, draw, read, &old_ctx, &old_draw, &old_read)) + return EGL_FALSE; + + old_gctx = egl_g3d_context(old_ctx); + if (old_gctx) { + /* flush old context */ + old_gctx->stctxi->flush(old_gctx->stctxi, + PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); + } + + if (gctx) { + ok = gctx->stapi->make_current(gctx->stapi, gctx->stctxi, + (gdraw) ? gdraw->stfbi : NULL, (gread) ? gread->stfbi : NULL); + if (ok) { + if (gdraw) { + gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, + gdraw->stfbi); + + if (gdraw->base.Type == EGL_WINDOW_BIT) { + gctx->base.WindowRenderBuffer = + (gdraw->stvis.render_buffer == ST_ATTACHMENT_FRONT_LEFT) ? + EGL_SINGLE_BUFFER : EGL_BACK_BUFFER; + } + } + if (gread && gread != gdraw) { + gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, + gread->stfbi); + } + } + } + else if (old_gctx) { + ok = old_gctx->stapi->make_current(old_gctx->stapi, NULL, NULL, NULL); + if (ok) + old_gctx->base.WindowRenderBuffer = EGL_NONE; + } + + if (ok) { + if (_eglPutContext(old_ctx)) + destroy_context(dpy, old_ctx); + if (_eglPutSurface(old_draw)) + destroy_surface(dpy, old_draw); + if (_eglPutSurface(old_read)) + destroy_surface(dpy, old_read); + } + else { + /* undo the previous _eglBindContext */ + _eglBindContext(old_ctx, old_draw, old_read, &ctx, &draw, &read); + assert(&gctx->base == ctx && + &gdraw->base == draw && + &gread->base == read); + + _eglPutSurface(draw); + _eglPutSurface(read); + _eglPutContext(ctx); + + _eglPutSurface(old_draw); + _eglPutSurface(old_read); + _eglPutContext(old_ctx); + } + + return ok; +} + +static EGLBoolean +egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) +{ + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + _EGLContext *ctx = _eglGetCurrentContext(); + struct egl_g3d_context *gctx = NULL; + + /* no-op for pixmap or pbuffer surface */ + if (gsurf->base.Type == EGL_PIXMAP_BIT || + gsurf->base.Type == EGL_PBUFFER_BIT) + return EGL_TRUE; + + /* or when the surface is single-buffered */ + if (gsurf->stvis.render_buffer == ST_ATTACHMENT_FRONT_LEFT) + return EGL_TRUE; + + if (ctx && ctx->DrawSurface == surf) + gctx = egl_g3d_context(ctx); + + /* flush if the surface is current */ + if (gctx) { + gctx->stctxi->flush(gctx->stctxi, + PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); + } + + return gsurf->native->present(gsurf->native, + NATIVE_ATTACHMENT_BACK_LEFT, + gsurf->base.SwapBehavior == EGL_BUFFER_PRESERVED, + gsurf->base.SwapInterval); +} + +/** + * Get the pipe surface of the given attachment of the native surface. + */ +static struct pipe_resource * +get_pipe_resource(struct native_display *ndpy, struct native_surface *nsurf, + enum native_attachment natt) +{ + struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS]; + + textures[natt] = NULL; + nsurf->validate(nsurf, 1 << natt, NULL, textures, NULL, NULL); + + return textures[natt]; +} + +static EGLBoolean +egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, + EGLNativePixmapType target) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + _EGLContext *ctx = _eglGetCurrentContext(); + struct egl_g3d_config *gconf; + struct native_surface *nsurf; + struct pipe_resource *ptex; + + if (!gsurf->render_texture) + return EGL_TRUE; + + gconf = egl_g3d_config(egl_g3d_find_pixmap_config(dpy, target)); + if (!gconf) + return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers"); + + nsurf = gdpy->native->create_pixmap_surface(gdpy->native, + target, gconf->native); + if (!nsurf) + return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers"); + + /* flush if the surface is current */ + if (ctx && ctx->DrawSurface == &gsurf->base) { + struct egl_g3d_context *gctx = egl_g3d_context(ctx); + gctx->stctxi->flush(gctx->stctxi, + PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); + } + + /* create a pipe context to copy surfaces */ + if (!gdpy->pipe) { + gdpy->pipe = + gdpy->native->screen->context_create(gdpy->native->screen, NULL); + if (!gdpy->pipe) + return EGL_FALSE; + } + + ptex = get_pipe_resource(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT); + if (ptex) { + struct pipe_box src_box; + + u_box_origin_2d(ptex->width0, ptex->height0, &src_box); + gdpy->pipe->resource_copy_region(gdpy->pipe, ptex, 0, 0, 0, 0, + gsurf->render_texture, 0, &src_box); + gdpy->pipe->flush(gdpy->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + nsurf->present(nsurf, NATIVE_ATTACHMENT_FRONT_LEFT, FALSE, 0); + + pipe_resource_reference(&ptex, NULL); + } + + nsurf->destroy(nsurf); + + return EGL_TRUE; +} + +static EGLBoolean +egl_g3d_wait_client(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_context *gctx = egl_g3d_context(ctx); + struct pipe_screen *screen = gdpy->native->screen; + struct pipe_fence_handle *fence = NULL; + + gctx->stctxi->flush(gctx->stctxi, + PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, &fence); + if (fence) { + screen->fence_finish(screen, fence, 0); + screen->fence_reference(screen, &fence, NULL); + } + + return EGL_TRUE; +} + +static EGLBoolean +egl_g3d_wait_native(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + + if (engine != EGL_CORE_NATIVE_ENGINE) + return _eglError(EGL_BAD_PARAMETER, "eglWaitNative"); + + if (ctx && ctx->DrawSurface) { + struct egl_g3d_surface *gsurf = egl_g3d_surface(ctx->DrawSurface); + + if (gsurf->native) + gsurf->native->wait(gsurf->native); + } + + return EGL_TRUE; +} + +static EGLBoolean +egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLSurface *surf, EGLint buffer) +{ + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + _EGLContext *es1 = _eglGetAPIContext(EGL_OPENGL_ES_API); + struct egl_g3d_context *gctx; + enum pipe_format internal_format; + enum st_texture_type target; + + if (!gsurf || gsurf->base.Type != EGL_PBUFFER_BIT) + return _eglError(EGL_BAD_SURFACE, "eglBindTexImage"); + if (buffer != EGL_BACK_BUFFER) + return _eglError(EGL_BAD_PARAMETER, "eglBindTexImage"); + if (gsurf->base.BoundToTexture) + return _eglError(EGL_BAD_ACCESS, "eglBindTexImage"); + + switch (gsurf->base.TextureFormat) { + case EGL_TEXTURE_RGB: + internal_format = PIPE_FORMAT_R8G8B8_UNORM; + break; + case EGL_TEXTURE_RGBA: + internal_format = PIPE_FORMAT_B8G8R8A8_UNORM; + break; + default: + return _eglError(EGL_BAD_MATCH, "eglBindTexImage"); + } + + switch (gsurf->base.TextureTarget) { + case EGL_TEXTURE_2D: + target = ST_TEXTURE_2D; + break; + default: + return _eglError(EGL_BAD_MATCH, "eglBindTexImage"); + } + + if (!es1) + return EGL_TRUE; + if (!gsurf->render_texture) + return EGL_FALSE; + + /* flush properly if the surface is bound */ + if (gsurf->base.CurrentContext) { + gctx = egl_g3d_context(gsurf->base.CurrentContext); + gctx->stctxi->flush(gctx->stctxi, + PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); + } + + gctx = egl_g3d_context(es1); + if (gctx->stctxi->teximage) { + if (!gctx->stctxi->teximage(gctx->stctxi, target, + gsurf->base.MipmapLevel, internal_format, + gsurf->render_texture, gsurf->base.MipmapTexture)) + return EGL_FALSE; + gsurf->base.BoundToTexture = EGL_TRUE; + } + + return EGL_TRUE; +} + +static EGLBoolean +egl_g3d_release_tex_image(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLSurface *surf, EGLint buffer) +{ + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + + if (!gsurf || gsurf->base.Type != EGL_PBUFFER_BIT || + !gsurf->base.BoundToTexture) + return _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage"); + if (buffer != EGL_BACK_BUFFER) + return _eglError(EGL_BAD_PARAMETER, "eglReleaseTexImage"); + + if (gsurf->render_texture) { + _EGLContext *ctx = _eglGetAPIContext(EGL_OPENGL_ES_API); + struct egl_g3d_context *gctx = egl_g3d_context(ctx); + + /* what if the context the surface binds to is no longer current? */ + if (gctx) { + gctx->stctxi->teximage(gctx->stctxi, ST_TEXTURE_2D, + gsurf->base.MipmapLevel, PIPE_FORMAT_NONE, NULL, FALSE); + } + } + + gsurf->base.BoundToTexture = EGL_FALSE; + + return EGL_TRUE; +} + +#ifdef EGL_MESA_screen_surface + +static _EGLSurface * +egl_g3d_create_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLConfig *conf, const EGLint *attribs) +{ + struct egl_g3d_create_surface_arg arg; + + memset(&arg, 0, sizeof(arg)); + arg.type = EGL_SCREEN_BIT_MESA; + + return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); +} + +static EGLBoolean +egl_g3d_show_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLScreen *scr, _EGLSurface *surf, + _EGLMode *mode) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_screen *gscr = egl_g3d_screen(scr); + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + struct native_surface *nsurf; + const struct native_mode *nmode; + EGLBoolean changed; + + if (gsurf) { + EGLint idx; + + if (!mode) + return _eglError(EGL_BAD_MATCH, "eglShowSurfaceMESA"); + if (gsurf->base.Type != EGL_SCREEN_BIT_MESA) + return _eglError(EGL_BAD_SURFACE, "eglShowScreenSurfaceMESA"); + if (gsurf->base.Width < mode->Width || gsurf->base.Height < mode->Height) + return _eglError(EGL_BAD_MATCH, + "eglShowSurfaceMESA(surface smaller than mode size)"); + + /* find the index of the mode */ + for (idx = 0; idx < gscr->base.NumModes; idx++) + if (mode == &gscr->base.Modes[idx]) + break; + if (idx >= gscr->base.NumModes) { + return _eglError(EGL_BAD_MODE_MESA, + "eglShowSurfaceMESA(unknown mode)"); + } + + nsurf = gsurf->native; + nmode = gscr->native_modes[idx]; + } + else { + if (mode) + return _eglError(EGL_BAD_MATCH, "eglShowSurfaceMESA"); + + /* disable the screen */ + nsurf = NULL; + nmode = NULL; + } + + /* TODO surface panning by CRTC choosing */ + changed = gdpy->native->modeset->program(gdpy->native, 0, nsurf, + gscr->base.OriginX, gscr->base.OriginY, &gscr->native, 1, nmode); + if (changed) { + gscr->base.CurrentSurface = &gsurf->base; + gscr->base.CurrentMode = mode; + } + + return changed; +} + +#endif /* EGL_MESA_screen_surface */ + +/** + * Find a config that supports the pixmap. + */ +_EGLConfig * +egl_g3d_find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_config *gconf; + EGLint i; + + for (i = 0; i < dpy->Configs->Size; i++) { + gconf = egl_g3d_config((_EGLConfig *) dpy->Configs->Elements[i]); + if (gdpy->native->is_pixmap_supported(gdpy->native, pix, gconf->native)) + break; + } + + return (i < dpy->Configs->Size) ? &gconf->base : NULL; +} + +void +egl_g3d_init_driver_api(_EGLDriver *drv) +{ + _eglInitDriverFallbacks(drv); + + drv->API.ChooseConfig = egl_g3d_choose_config; + + drv->API.CreateContext = egl_g3d_create_context; + drv->API.DestroyContext = egl_g3d_destroy_context; + drv->API.CreateWindowSurface = egl_g3d_create_window_surface; + drv->API.CreatePixmapSurface = egl_g3d_create_pixmap_surface; + drv->API.CreatePbufferSurface = egl_g3d_create_pbuffer_surface; + drv->API.CreatePbufferFromClientBuffer = egl_g3d_create_pbuffer_from_client_buffer; + drv->API.DestroySurface = egl_g3d_destroy_surface; + drv->API.MakeCurrent = egl_g3d_make_current; + drv->API.SwapBuffers = egl_g3d_swap_buffers; + drv->API.CopyBuffers = egl_g3d_copy_buffers; + drv->API.WaitClient = egl_g3d_wait_client; + drv->API.WaitNative = egl_g3d_wait_native; + + drv->API.BindTexImage = egl_g3d_bind_tex_image; + drv->API.ReleaseTexImage = egl_g3d_release_tex_image; + + drv->API.CreateImageKHR = egl_g3d_create_image; + drv->API.DestroyImageKHR = egl_g3d_destroy_image; +#ifdef EGL_MESA_drm_image + drv->API.CreateDRMImageMESA = egl_g3d_create_drm_image; + drv->API.ExportDRMImageMESA = egl_g3d_export_drm_image; +#endif + +#ifdef EGL_KHR_reusable_sync + drv->API.CreateSyncKHR = egl_g3d_create_sync; + drv->API.DestroySyncKHR = egl_g3d_destroy_sync; + drv->API.ClientWaitSyncKHR = egl_g3d_client_wait_sync; + drv->API.SignalSyncKHR = egl_g3d_signal_sync; +#endif + +#ifdef EGL_MESA_screen_surface + drv->API.CreateScreenSurfaceMESA = egl_g3d_create_screen_surface; + drv->API.ShowScreenSurfaceMESA = egl_g3d_show_screen_surface; +#endif +} diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_api.h b/src/gallium/state_trackers/egl/common/egl_g3d_api.h new file mode 100644 index 0000000..d5196c1 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_api.h @@ -0,0 +1,37 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2009-2010 Chia-I Wu + * + * 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 _EGL_G3D_API_H_ +#define _EGL_G3D_API_H_ + +#include "egl_g3d.h" + +void +egl_g3d_init_driver_api(_EGLDriver *drv); + +_EGLConfig * +egl_g3d_find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix); + +#endif /* _EGL_G3D_API_H_ */ diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_image.c b/src/gallium/state_trackers/egl/common/egl_g3d_image.c new file mode 100644 index 0000000..b2d6b43 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_image.c @@ -0,0 +1,334 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "pipe/p_screen.h" +#include "util/u_memory.h" +#include "util/u_rect.h" +#include "util/u_inlines.h" +#include "eglcurrent.h" +#include "egllog.h" + +#include "native.h" +#include "egl_g3d.h" +#include "egl_g3d_api.h" +#include "egl_g3d_image.h" + +/* for struct winsys_handle */ +#include "state_tracker/drm_driver.h" + +/** + * Reference and return the front left buffer of the native pixmap. + */ +static struct pipe_resource * +egl_g3d_reference_native_pixmap(_EGLDisplay *dpy, EGLNativePixmapType pix) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_config *gconf; + struct native_surface *nsurf; + struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS]; + enum native_attachment natt; + + gconf = egl_g3d_config(egl_g3d_find_pixmap_config(dpy, pix)); + if (!gconf) + return NULL; + + nsurf = gdpy->native->create_pixmap_surface(gdpy->native, + pix, gconf->native); + if (!nsurf) + return NULL; + + natt = NATIVE_ATTACHMENT_FRONT_LEFT; + if (!nsurf->validate(nsurf, 1 << natt, NULL, textures, NULL, NULL)) + textures[natt] = NULL; + + nsurf->destroy(nsurf); + + return textures[natt]; +} + +#ifdef EGL_MESA_drm_image + +static struct pipe_resource * +egl_g3d_create_drm_buffer(_EGLDisplay *dpy, _EGLImage *img, + const EGLint *attribs) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct pipe_screen *screen = gdpy->native->screen; + struct pipe_resource templ; + _EGLImageAttribs attrs; + EGLint format, valid_use; + + if (_eglParseImageAttribList(&attrs, dpy, attribs) != EGL_SUCCESS) + return NULL; + + if (attrs.Width <= 0 || attrs.Height <= 0) { + _eglLog(_EGL_DEBUG, "bad width or height (%dx%d)", + attrs.Width, attrs.Height); + return NULL; + } + + switch (attrs.DRMBufferFormatMESA) { + case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: + format = PIPE_FORMAT_B8G8R8A8_UNORM; + break; + default: + _eglLog(_EGL_DEBUG, "bad image format value 0x%04x", + attrs.DRMBufferFormatMESA); + return NULL; + break; + } + + valid_use = EGL_DRM_BUFFER_USE_SCANOUT_MESA | + EGL_DRM_BUFFER_USE_SHARE_MESA; + if (attrs.DRMBufferUseMESA & ~valid_use) { + _eglLog(_EGL_DEBUG, "bad image use bit 0x%04x", + attrs.DRMBufferUseMESA); + return NULL; + } + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.format = format; + templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; + templ.width0 = attrs.Width; + templ.height0 = attrs.Height; + templ.depth0 = 1; + + /* + * XXX fix apps (e.g. wayland) and pipe drivers (e.g. i915) and remove the + * size check + */ + if ((attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SCANOUT_MESA) && + attrs.Width >= 640 && attrs.Height >= 480) + templ.bind |= PIPE_BIND_SCANOUT; + if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_SHARE_MESA) + templ.bind |= PIPE_BIND_SHARED; + + return screen->resource_create(screen, &templ); +} + +static struct pipe_resource * +egl_g3d_reference_drm_buffer(_EGLDisplay *dpy, EGLint name, + _EGLImage *img, const EGLint *attribs) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct pipe_resource templ; + struct winsys_handle wsh; + _EGLImageAttribs attrs; + EGLint format; + + if (dpy->Platform != _EGL_PLATFORM_DRM) + return NULL; + + if (_eglParseImageAttribList(&attrs, dpy, attribs) != EGL_SUCCESS) + return NULL; + + if (attrs.Width <= 0 || attrs.Height <= 0 || + attrs.DRMBufferStrideMESA <= 0) { + _eglLog(_EGL_DEBUG, "bad width, height, or stride (%dx%dx%d)", + attrs.Width, attrs.Height, attrs.DRMBufferStrideMESA); + return NULL; + } + + switch (attrs.DRMBufferFormatMESA) { + case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA: + format = PIPE_FORMAT_B8G8R8A8_UNORM; + break; + default: + _eglLog(_EGL_DEBUG, "bad image format value 0x%04x", + attrs.DRMBufferFormatMESA); + return NULL; + break; + } + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.format = format; + templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; + templ.width0 = attrs.Width; + templ.height0 = attrs.Height; + templ.depth0 = 1; + templ.array_size = 1; + + memset(&wsh, 0, sizeof(wsh)); + wsh.handle = (unsigned) name; + wsh.stride = + attrs.DRMBufferStrideMESA * util_format_get_blocksize(templ.format); + + return gdpy->native->buffer->import_buffer(gdpy->native, &templ, &wsh); +} + +#endif /* EGL_MESA_drm_image */ + +_EGLImage * +egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, + EGLenum target, EGLClientBuffer buffer, + const EGLint *attribs) +{ + struct pipe_resource *ptex; + struct egl_g3d_image *gimg; + unsigned level = 0, layer = 0; + + gimg = CALLOC_STRUCT(egl_g3d_image); + if (!gimg) { + _eglError(EGL_BAD_ALLOC, "eglCreateEGLImageKHR"); + return NULL; + } + + if (!_eglInitImage(&gimg->base, dpy)) { + FREE(gimg); + return NULL; + } + + switch (target) { + case EGL_NATIVE_PIXMAP_KHR: + ptex = egl_g3d_reference_native_pixmap(dpy, + (EGLNativePixmapType) buffer); + break; +#ifdef EGL_MESA_drm_image + case EGL_DRM_BUFFER_MESA: + ptex = egl_g3d_reference_drm_buffer(dpy, + (EGLint) buffer, &gimg->base, attribs); + break; +#endif + default: + ptex = NULL; + break; + } + + if (!ptex) { + FREE(gimg); + return NULL; + } + + if (level > ptex->last_level) { + _eglError(EGL_BAD_MATCH, "eglCreateEGLImageKHR"); + pipe_resource_reference(&gimg->texture, NULL); + FREE(gimg); + return NULL; + } + if (layer >= (u_minify(ptex->depth0, level) + ptex->array_size - 1)) { + _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR"); + pipe_resource_reference(&gimg->texture, NULL); + FREE(gimg); + return NULL; + } + + /* transfer the ownership to the image */ + gimg->texture = ptex; + gimg->level = level; + gimg->layer = layer; + + return &gimg->base; +} + +EGLBoolean +egl_g3d_destroy_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *img) +{ + struct egl_g3d_image *gimg = egl_g3d_image(img); + + pipe_resource_reference(&gimg->texture, NULL); + FREE(gimg); + + return EGL_TRUE; +} + +_EGLImage * +egl_g3d_create_drm_image(_EGLDriver *drv, _EGLDisplay *dpy, + const EGLint *attribs) +{ + struct egl_g3d_image *gimg; + struct pipe_resource *ptex; + + gimg = CALLOC_STRUCT(egl_g3d_image); + if (!gimg) { + _eglError(EGL_BAD_ALLOC, "eglCreateDRMImageKHR"); + return NULL; + } + + if (!_eglInitImage(&gimg->base, dpy)) { + FREE(gimg); + return NULL; + } + +#ifdef EGL_MESA_drm_image + ptex = egl_g3d_create_drm_buffer(dpy, &gimg->base, attribs); +#else + ptex = NULL; +#endif + if (!ptex) { + FREE(gimg); + return NULL; + } + + /* transfer the ownership to the image */ + gimg->texture = ptex; + gimg->level = 0; + gimg->layer = 0; + + return &gimg->base; +} + +EGLBoolean +egl_g3d_export_drm_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *img, + EGLint *name, EGLint *handle, EGLint *stride) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_image *gimg = egl_g3d_image(img); + struct winsys_handle wsh; + + if (dpy->Platform != _EGL_PLATFORM_DRM) + return EGL_FALSE; + + /* get shared handle */ + if (name) { + memset(&handle, 0, sizeof(handle)); + wsh.type = DRM_API_HANDLE_TYPE_SHARED; + if (!gdpy->native->buffer->export_buffer(gdpy->native, + gimg->texture, &wsh)) + return EGL_FALSE; + + *name = wsh.handle; + } + + /* get KMS handle */ + if (handle || stride) { + memset(&wsh, 0, sizeof(wsh)); + wsh.type = DRM_API_HANDLE_TYPE_KMS; + if (!gdpy->native->buffer->export_buffer(gdpy->native, + gimg->texture, &wsh)) + return EGL_FALSE; + + if (handle) + *handle = wsh.handle; + if (stride) + *stride = wsh.stride; + } + + return EGL_TRUE; +} diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_image.h b/src/gallium/state_trackers/egl/common/egl_g3d_image.h new file mode 100644 index 0000000..f051da8 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_image.h @@ -0,0 +1,50 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _EGL_G3D_IMAGE_H_ +#define _EGL_G3D_IMAGE_H_ + +#include "egl_g3d.h" + +_EGLImage * +egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, + EGLenum target, EGLClientBuffer buffer, + const EGLint *attribs); + +EGLBoolean +egl_g3d_destroy_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *image); + +_EGLImage * +egl_g3d_create_drm_image(_EGLDriver *drv, _EGLDisplay *dpy, + const EGLint *attribs); + +EGLBoolean +egl_g3d_export_drm_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *img, + EGLint *name, EGLint *handle, EGLint *stride); + +#endif /* _EGL_G3D_IMAGE_H_ */ diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_loader.h b/src/gallium/state_trackers/egl/common/egl_g3d_loader.h new file mode 100644 index 0000000..78bfe21 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_loader.h @@ -0,0 +1,54 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _EGL_G3D_LOADER_H_ +#define _EGL_G3D_LOADER_H_ + +#include "pipe/p_compiler.h" +#include "state_tracker/st_api.h" +#include "egltypedefs.h" + +struct pipe_screen; +struct sw_winsys; + +struct egl_g3d_loader { + uint profile_masks[ST_API_COUNT]; + struct st_api *(*get_st_api)(enum st_api_type api); + struct st_api *(*guess_gl_api)(enum st_profile_type profile); + + struct pipe_screen *(*create_drm_screen)(const char *name, int fd); + struct pipe_screen *(*create_sw_screen)(struct sw_winsys *ws); +}; + +_EGLDriver * +egl_g3d_create_driver(const struct egl_g3d_loader *loader); + +void +egl_g3d_destroy_driver(_EGLDriver *drv); + +#endif /* _EGL_G3D_LOADER_H_ */ diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_st.c b/src/gallium/state_trackers/egl/common/egl_g3d_st.c new file mode 100644 index 0000000..2b944b5 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_st.c @@ -0,0 +1,312 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "util/u_memory.h" +#include "util/u_string.h" +#include "util/u_inlines.h" +#include "util/u_pointer.h" +#include "util/u_dl.h" +#include "egldriver.h" +#include "eglimage.h" +#include "eglmutex.h" + +#include "egl_g3d.h" +#include "egl_g3d_st.h" + +struct egl_g3d_st_manager { + struct st_manager base; + _EGLDisplay *display; +}; + +static INLINE struct egl_g3d_st_manager * +egl_g3d_st_manager(struct st_manager *smapi) +{ + return (struct egl_g3d_st_manager *) smapi; +} + +static boolean +egl_g3d_st_manager_get_egl_image(struct st_manager *smapi, + void *egl_image, + struct st_egl_image *out) +{ + struct egl_g3d_st_manager *gsmapi = egl_g3d_st_manager(smapi); + EGLImageKHR handle = (EGLImageKHR) egl_image; + _EGLImage *img; + struct egl_g3d_image *gimg; + + /* this is called from state trackers */ + _eglLockMutex(&gsmapi->display->Mutex); + + img = _eglLookupImage(handle, gsmapi->display); + if (!img) { + _eglUnlockMutex(&gsmapi->display->Mutex); + return FALSE; + } + + gimg = egl_g3d_image(img); + + out->texture = NULL; + pipe_resource_reference(&out->texture, gimg->texture); + out->level = gimg->level; + out->layer = gimg->layer; + + _eglUnlockMutex(&gsmapi->display->Mutex); + + return TRUE; +} + +static int +egl_g3d_st_manager_get_param(struct st_manager *smapi, + enum st_manager_param param) +{ + return 0; +} + +struct st_manager * +egl_g3d_create_st_manager(_EGLDisplay *dpy) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_st_manager *gsmapi; + + gsmapi = CALLOC_STRUCT(egl_g3d_st_manager); + if (gsmapi) { + gsmapi->display = dpy; + + gsmapi->base.screen = gdpy->native->screen; + gsmapi->base.get_egl_image = egl_g3d_st_manager_get_egl_image; + gsmapi->base.get_param = egl_g3d_st_manager_get_param; + } + + return &gsmapi->base;; +} + +void +egl_g3d_destroy_st_manager(struct st_manager *smapi) +{ + struct egl_g3d_st_manager *gsmapi = egl_g3d_st_manager(smapi); + FREE(gsmapi); +} + +static boolean +egl_g3d_st_framebuffer_flush_front_pbuffer(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + return TRUE; +} + +static void +pbuffer_reference_openvg_image(struct egl_g3d_surface *gsurf) +{ + /* TODO */ +} + +static void +pbuffer_allocate_render_texture(struct egl_g3d_surface *gsurf) +{ + struct egl_g3d_display *gdpy = + egl_g3d_display(gsurf->base.Resource.Display); + struct pipe_screen *screen = gdpy->native->screen; + struct pipe_resource templ, *ptex; + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.last_level = 0; + templ.width0 = gsurf->base.Width; + templ.height0 = gsurf->base.Height; + templ.depth0 = 1; + templ.array_size = 1; + templ.format = gsurf->stvis.color_format; + templ.bind = PIPE_BIND_RENDER_TARGET; + + ptex = screen->resource_create(screen, &templ); + gsurf->render_texture = ptex; +} + +static boolean +egl_g3d_st_framebuffer_validate_pbuffer(struct st_framebuffer_iface *stfbi, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_resource **out) +{ + _EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private; + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + unsigned i; + + for (i = 0; i < count; i++) { + out[i] = NULL; + + if (gsurf->stvis.render_buffer != statts[i]) + continue; + + if (!gsurf->render_texture) { + switch (gsurf->client_buffer_type) { + case EGL_NONE: + pbuffer_allocate_render_texture(gsurf); + break; + case EGL_OPENVG_IMAGE: + pbuffer_reference_openvg_image(gsurf); + break; + default: + break; + } + + if (!gsurf->render_texture) + return FALSE; + } + + pipe_resource_reference(&out[i], gsurf->render_texture); + } + + return TRUE; +} + +static boolean +egl_g3d_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + _EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private; + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + + return gsurf->native->present(gsurf->native, + NATIVE_ATTACHMENT_FRONT_LEFT, FALSE, 0); +} + +static boolean +egl_g3d_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_resource **out) +{ + _EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private; + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS]; + uint attachment_mask = 0; + unsigned i; + + for (i = 0; i < count; i++) { + int natt; + + switch (statts[i]) { + case ST_ATTACHMENT_FRONT_LEFT: + natt = NATIVE_ATTACHMENT_FRONT_LEFT; + break; + case ST_ATTACHMENT_BACK_LEFT: + natt = NATIVE_ATTACHMENT_BACK_LEFT; + break; + case ST_ATTACHMENT_FRONT_RIGHT: + natt = NATIVE_ATTACHMENT_FRONT_RIGHT; + break; + case ST_ATTACHMENT_BACK_RIGHT: + natt = NATIVE_ATTACHMENT_BACK_RIGHT; + break; + default: + natt = -1; + break; + } + + if (natt >= 0) + attachment_mask |= 1 << natt; + } + + if (!gsurf->native->validate(gsurf->native, attachment_mask, + &gsurf->sequence_number, textures, &gsurf->base.Width, + &gsurf->base.Height)) + return FALSE; + + for (i = 0; i < count; i++) { + struct pipe_resource *tex; + int natt; + + switch (statts[i]) { + case ST_ATTACHMENT_FRONT_LEFT: + natt = NATIVE_ATTACHMENT_FRONT_LEFT; + break; + case ST_ATTACHMENT_BACK_LEFT: + natt = NATIVE_ATTACHMENT_BACK_LEFT; + break; + case ST_ATTACHMENT_FRONT_RIGHT: + natt = NATIVE_ATTACHMENT_FRONT_RIGHT; + break; + case ST_ATTACHMENT_BACK_RIGHT: + natt = NATIVE_ATTACHMENT_BACK_RIGHT; + break; + default: + natt = -1; + break; + } + + if (natt >= 0) { + tex = textures[natt]; + + if (statts[i] == stfbi->visual->render_buffer) + pipe_resource_reference(&gsurf->render_texture, tex); + + if (attachment_mask & (1 << natt)) { + /* transfer the ownership to the caller */ + out[i] = tex; + attachment_mask &= ~(1 << natt); + } + else { + /* the attachment is listed more than once */ + pipe_resource_reference(&out[i], tex); + } + } + } + + return TRUE; +} + +struct st_framebuffer_iface * +egl_g3d_create_st_framebuffer(_EGLSurface *surf) +{ + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + struct st_framebuffer_iface *stfbi; + + stfbi = CALLOC_STRUCT(st_framebuffer_iface); + if (!stfbi) + return NULL; + + stfbi->visual = &gsurf->stvis; + if (gsurf->base.Type != EGL_PBUFFER_BIT) { + stfbi->flush_front = egl_g3d_st_framebuffer_flush_front; + stfbi->validate = egl_g3d_st_framebuffer_validate; + } + else { + stfbi->flush_front = egl_g3d_st_framebuffer_flush_front_pbuffer; + stfbi->validate = egl_g3d_st_framebuffer_validate_pbuffer; + } + stfbi->st_manager_private = (void *) &gsurf->base; + + return stfbi; +} + +void +egl_g3d_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi) +{ + FREE(stfbi); +} diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_st.h b/src/gallium/state_trackers/egl/common/egl_g3d_st.h new file mode 100644 index 0000000..1f9f078 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_st.h @@ -0,0 +1,48 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _EGL_G3D_ST_H_ +#define _EGL_G3D_ST_H_ + +#include "pipe/p_compiler.h" +#include "state_tracker/st_api.h" +#include "egltypedefs.h" + +struct st_manager * +egl_g3d_create_st_manager(_EGLDisplay *dpy); + +void +egl_g3d_destroy_st_manager(struct st_manager *smapi); + +struct st_framebuffer_iface * +egl_g3d_create_st_framebuffer(_EGLSurface *surf); + +void +egl_g3d_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi); + +#endif /* _EGL_G3D_ST_H_ */ diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_sync.c b/src/gallium/state_trackers/egl/common/egl_g3d_sync.c new file mode 100644 index 0000000..4e6d944 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_sync.c @@ -0,0 +1,283 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "util/u_memory.h" +#include "util/u_atomic.h" +#include "os/os_thread.h" +#include "eglsync.h" +#include "eglcurrent.h" + +#include "egl_g3d.h" +#include "egl_g3d_sync.h" + +#ifdef EGL_KHR_reusable_sync + +/** + * Wait for the conditional variable. + */ +static EGLint +egl_g3d_wait_sync_condvar(struct egl_g3d_sync *gsync, EGLTimeKHR timeout) +{ + _EGLDisplay *dpy = gsync->base.Resource.Display; + + pipe_mutex_lock(gsync->mutex); + + /* unlock display lock just before waiting */ + _eglUnlockMutex(&dpy->Mutex); + + /* No timed wait. Always treat timeout as EGL_FOREVER_KHR */ + pipe_condvar_wait(gsync->condvar, gsync->mutex); + + _eglLockMutex(&dpy->Mutex); + + pipe_mutex_unlock(gsync->mutex); + + return EGL_CONDITION_SATISFIED_KHR; +} + +/** + * Signal the conditional variable. + */ +static void +egl_g3d_signal_sync_condvar(struct egl_g3d_sync *gsync) +{ + pipe_mutex_lock(gsync->mutex); + pipe_condvar_broadcast(gsync->condvar); + pipe_mutex_unlock(gsync->mutex); +} + +/** + * Insert a fence command to the command stream of the current context. + */ +static EGLint +egl_g3d_insert_fence_sync(struct egl_g3d_sync *gsync) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + struct egl_g3d_context *gctx = egl_g3d_context(ctx); + + /* already checked in egl_g3d_create_sync */ + assert(gctx); + + /* insert the fence command */ + gctx->stctxi->flush(gctx->stctxi, 0x0, &gsync->fence); + if (!gsync->fence) + gsync->base.SyncStatus = EGL_SIGNALED_KHR; + + return EGL_SUCCESS; +} + +/** + * Wait for the fence sync to be signaled. + */ +static EGLint +egl_g3d_wait_fence_sync(struct egl_g3d_sync *gsync, EGLTimeKHR timeout) +{ + EGLint ret; + + if (gsync->fence) { + _EGLDisplay *dpy = gsync->base.Resource.Display; + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct pipe_screen *screen = gdpy->native->screen; + struct pipe_fence_handle *fence = gsync->fence; + + gsync->fence = NULL; + + _eglUnlockMutex(&dpy->Mutex); + /* no timed finish? */ + screen->fence_finish(screen, fence, 0x0); + ret = EGL_CONDITION_SATISFIED_KHR; + _eglLockMutex(&dpy->Mutex); + + gsync->base.SyncStatus = EGL_SIGNALED_KHR; + + screen->fence_reference(screen, &fence, NULL); + egl_g3d_signal_sync_condvar(gsync); + } + else { + ret = egl_g3d_wait_sync_condvar(gsync, timeout); + } + + return ret; +} + +static INLINE void +egl_g3d_ref_sync(struct egl_g3d_sync *gsync) +{ + _eglGetSync(&gsync->base); +} + +static INLINE void +egl_g3d_unref_sync(struct egl_g3d_sync *gsync) +{ + if (_eglPutSync(&gsync->base)) { + pipe_condvar_destroy(gsync->condvar); + pipe_mutex_destroy(gsync->mutex); + + if (gsync->fence) { + struct egl_g3d_display *gdpy = + egl_g3d_display(gsync->base.Resource.Display); + struct pipe_screen *screen = gdpy->native->screen; + + screen->fence_reference(screen, &gsync->fence, NULL); + } + + FREE(gsync); + } +} + +_EGLSync * +egl_g3d_create_sync(_EGLDriver *drv, _EGLDisplay *dpy, + EGLenum type, const EGLint *attrib_list) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + struct egl_g3d_sync *gsync; + EGLint err; + + if (!ctx || ctx->Resource.Display != dpy) { + _eglError(EGL_BAD_MATCH, "eglCreateSyncKHR"); + return NULL; + } + + gsync = CALLOC_STRUCT(egl_g3d_sync); + if (!gsync) { + _eglError(EGL_BAD_ALLOC, "eglCreateSyncKHR"); + return NULL; + } + + if (!_eglInitSync(&gsync->base, dpy, type, attrib_list)) { + FREE(gsync); + return NULL; + } + + switch (type) { + case EGL_SYNC_REUSABLE_KHR: + err = EGL_SUCCESS; + break; + case EGL_SYNC_FENCE_KHR: + err = egl_g3d_insert_fence_sync(gsync); + break; + default: + err = EGL_BAD_ATTRIBUTE; + break; + } + + if (err != EGL_SUCCESS) { + _eglError(err, "eglCreateSyncKHR"); + FREE(gsync); + return NULL; + } + + pipe_mutex_init(gsync->mutex); + pipe_condvar_init(gsync->condvar); + + return &gsync->base; +} + +EGLBoolean +egl_g3d_destroy_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync) +{ + struct egl_g3d_sync *gsync = egl_g3d_sync(sync); + + switch (gsync->base.Type) { + case EGL_SYNC_REUSABLE_KHR: + /* signal the waiters */ + if (gsync->base.SyncStatus != EGL_SIGNALED_KHR) { + gsync->base.SyncStatus = EGL_SIGNALED_KHR; + egl_g3d_signal_sync_condvar(gsync); + } + break; + default: + break; + } + + egl_g3d_unref_sync(gsync); + + return EGL_TRUE; +} + +EGLint +egl_g3d_client_wait_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, + EGLint flags, EGLTimeKHR timeout) +{ + struct egl_g3d_sync *gsync = egl_g3d_sync(sync); + EGLint ret = EGL_CONDITION_SATISFIED_KHR; + + if (gsync->base.SyncStatus != EGL_SIGNALED_KHR) { + /* flush if there is a current context */ + if (flags & EGL_SYNC_FLUSH_COMMANDS_BIT_KHR) { + _EGLContext *ctx = _eglGetCurrentContext(); + struct egl_g3d_context *gctx = egl_g3d_context(ctx); + + if (gctx) + gctx->stctxi->flush(gctx->stctxi, PIPE_FLUSH_RENDER_CACHE , NULL); + } + + if (timeout) { + /* reference the sync object in case it is destroyed while waiting */ + egl_g3d_ref_sync(gsync); + + switch (gsync->base.Type) { + case EGL_SYNC_REUSABLE_KHR: + ret = egl_g3d_wait_sync_condvar(gsync, timeout); + break; + case EGL_SYNC_FENCE_KHR: + ret = egl_g3d_wait_fence_sync(gsync, timeout); + default: + break; + } + + egl_g3d_unref_sync(gsync); + } + else { + ret = EGL_TIMEOUT_EXPIRED_KHR; + } + } + + return ret; +} + +EGLBoolean +egl_g3d_signal_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, + EGLenum mode) +{ + struct egl_g3d_sync *gsync = egl_g3d_sync(sync); + + /* only for reusable sync */ + if (sync->Type != EGL_SYNC_REUSABLE_KHR) + return _eglError(EGL_BAD_MATCH, "eglSignalSyncKHR"); + + if (gsync->base.SyncStatus != mode) { + gsync->base.SyncStatus = mode; + if (mode == EGL_SIGNALED_KHR) + egl_g3d_signal_sync_condvar(gsync); + } + + return EGL_TRUE; +} + +#endif /* EGL_KHR_reusable_sync */ diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_sync.h b/src/gallium/state_trackers/egl/common/egl_g3d_sync.h new file mode 100644 index 0000000..3179ca0 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_sync.h @@ -0,0 +1,53 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _EGL_G3D_SYNC_H_ +#define _EGL_G3D_SYNC_H_ + +#include "egl_g3d.h" + +#ifdef EGL_KHR_reusable_sync + +_EGLSync * +egl_g3d_create_sync(_EGLDriver *drv, _EGLDisplay *dpy, + EGLenum type, const EGLint *attrib_list); + +EGLBoolean +egl_g3d_destroy_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync); + +EGLint +egl_g3d_client_wait_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, + EGLint flags, EGLTimeKHR timeout); + +EGLBoolean +egl_g3d_signal_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, + EGLenum mode); + +#endif /* EGL_KHR_reusable_sync */ + +#endif /* _EGL_G3D_SYNC_H_ */ diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h new file mode 100644 index 0000000..3886ca2 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/native.h @@ -0,0 +1,250 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2009-2010 Chia-I Wu + * + * 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 _NATIVE_H_ +#define _NATIVE_H_ + +#include "EGL/egl.h" /* for EGL native types */ + +#include "pipe/p_compiler.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "state_tracker/sw_winsys.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "native_buffer.h" +#include "native_modeset.h" + +/** + * Only color buffers are listed. The others are allocated privately through, + * for example, st_renderbuffer_alloc_storage(). + */ +enum native_attachment { + NATIVE_ATTACHMENT_FRONT_LEFT, + NATIVE_ATTACHMENT_BACK_LEFT, + NATIVE_ATTACHMENT_FRONT_RIGHT, + NATIVE_ATTACHMENT_BACK_RIGHT, + + NUM_NATIVE_ATTACHMENTS +}; + +enum native_param_type { + /* + * Return TRUE if window/pixmap surfaces use the buffers of the native + * types. + */ + NATIVE_PARAM_USE_NATIVE_BUFFER, + + /** + * Return TRUE if native_surface::present can preserve the buffer. + */ + NATIVE_PARAM_PRESERVE_BUFFER, + + /** + * Return the maximum supported swap interval. + */ + NATIVE_PARAM_MAX_SWAP_INTERVAL +}; + +struct native_surface { + /** + * Available for caller's use. + */ + void *user_data; + + void (*destroy)(struct native_surface *nsurf); + + /** + * Present the given buffer to the native engine. + */ + boolean (*present)(struct native_surface *nsurf, + enum native_attachment natt, + boolean preserve, + uint swap_interval); + + /** + * Validate the buffers of the surface. textures, if not NULL, points to an + * array of size NUM_NATIVE_ATTACHMENTS and the returned textures are owned + * by the caller. A sequence number is also returned. The caller can use + * it to check if anything has changed since the last call. Any of the + * pointers may be NULL and it indicates the caller has no interest in those + * values. + * + * If this function is called multiple times with different attachment + * masks, those not listed in the latest call might be destroyed. This + * behavior might change in the future. + */ + boolean (*validate)(struct native_surface *nsurf, uint attachment_mask, + unsigned int *seq_num, struct pipe_resource **textures, + int *width, int *height); + + /** + * Wait until all native commands affecting the surface has been executed. + */ + void (*wait)(struct native_surface *nsurf); +}; + +/** + * Describe a native display config. + */ +struct native_config { + /* available buffers and their format */ + uint buffer_mask; + enum pipe_format color_format; + + /* supported surface types */ + boolean window_bit; + boolean pixmap_bit; + boolean scanout_bit; + + int native_visual_id; + int native_visual_type; + int level; + int samples; + boolean slow_config; + boolean transparent_rgb; + int transparent_rgb_values[3]; +}; + +/** + * A pipe winsys abstracts the OS. A pipe screen abstracts the graphcis + * hardware. A native display consists of a pipe winsys, a pipe screen, and + * the native display server. + */ +struct native_display { + /** + * The pipe screen of the native display. + */ + struct pipe_screen *screen; + + /** + * Available for caller's use. + */ + void *user_data; + + void (*destroy)(struct native_display *ndpy); + + /** + * Query the parameters of the native display. + * + * The return value is defined by the parameter. + */ + int (*get_param)(struct native_display *ndpy, + enum native_param_type param); + + /** + * Get the supported configs. The configs are owned by the display, but + * the returned array should be FREE()ed. + */ + const struct native_config **(*get_configs)(struct native_display *ndpy, + int *num_configs); + + /** + * Test if a pixmap is supported by the given config. Required unless no + * config has pixmap_bit set. + * + * This function is usually called to find a config that supports a given + * pixmap. Thus, it is usually called with the same pixmap in a row. + */ + boolean (*is_pixmap_supported)(struct native_display *ndpy, + EGLNativePixmapType pix, + const struct native_config *nconf); + + + /** + * Create a window surface. Required unless no config has window_bit set. + */ + struct native_surface *(*create_window_surface)(struct native_display *ndpy, + EGLNativeWindowType win, + const struct native_config *nconf); + + /** + * Create a pixmap surface. Required unless no config has pixmap_bit set. + */ + struct native_surface *(*create_pixmap_surface)(struct native_display *ndpy, + EGLNativePixmapType pix, + const struct native_config *nconf); + + const struct native_display_buffer *buffer; + const struct native_display_modeset *modeset; +}; + +/** + * The handler for events that a native display may generate. The events are + * generated asynchronously and the handler may be called by any thread at any + * time. + */ +struct native_event_handler { + /** + * This function is called when a surface needs to be validated. + */ + void (*invalid_surface)(struct native_display *ndpy, + struct native_surface *nsurf, + unsigned int seq_num); + + struct pipe_screen *(*new_drm_screen)(struct native_display *ndpy, + const char *name, int fd); + struct pipe_screen *(*new_sw_screen)(struct native_display *ndpy, + struct sw_winsys *ws); +}; + +/** + * Test whether an attachment is set in the mask. + */ +static INLINE boolean +native_attachment_mask_test(uint mask, enum native_attachment att) +{ + return !!(mask & (1 << att)); +} + +struct native_platform { + const char *name; + + struct native_display *(*create_display)(void *dpy, + struct native_event_handler *handler, + void *user_data); +}; + +const struct native_platform * +native_get_gdi_platform(void); + +const struct native_platform * +native_get_x11_platform(void); + +const struct native_platform * +native_get_drm_platform(void); + +const struct native_platform * +native_get_fbdev_platform(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _NATIVE_H_ */ diff --git a/src/gallium/state_trackers/egl/common/native_buffer.h b/src/gallium/state_trackers/egl/common/native_buffer.h new file mode 100644 index 0000000..5c29ab9 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/native_buffer.h @@ -0,0 +1,59 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _NATIVE_BUFFER_H_ +#define _NATIVE_BUFFER_H_ + +#include "pipe/p_compiler.h" + +struct native_display; +struct pipe_resource; + +/** + * Buffer interface of the native display. It allows native buffers to be + * imported and exported. + * + * Just like a native window or a native pixmap, a native buffer is another + * native type. Its definition depends on the native display. + * + * For DRM platform, the type of a native buffer is struct winsys_handle. + */ +struct native_display_buffer { + struct pipe_resource *(*import_buffer)(struct native_display *ndpy, + const struct pipe_resource *templ, + void *buf); + + /** + * The resource must be creatred with PIPE_BIND_SHARED. + */ + boolean (*export_buffer)(struct native_display *ndpy, + struct pipe_resource *res, + void *buf); +}; + +#endif /* _NATIVE_BUFFER_H_ */ diff --git a/src/gallium/state_trackers/egl/common/native_helper.c b/src/gallium/state_trackers/egl/common/native_helper.c new file mode 100644 index 0000000..0f2d020 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/native_helper.c @@ -0,0 +1,219 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" + +#include "native_helper.h" + +struct resource_surface { + struct pipe_screen *screen; + enum pipe_format format; + uint bind; + + struct pipe_resource *resources[NUM_NATIVE_ATTACHMENTS]; + uint resource_mask; + uint width, height; +}; + +struct resource_surface * +resource_surface_create(struct pipe_screen *screen, + enum pipe_format format, uint bind) +{ + struct resource_surface *rsurf = CALLOC_STRUCT(resource_surface); + + if (rsurf) { + rsurf->screen = screen; + rsurf->format = format; + rsurf->bind = bind; + } + + return rsurf; +} + +static void +resource_surface_free_resources(struct resource_surface *rsurf) +{ + if (rsurf->resource_mask) { + int i; + + for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) { + if (rsurf->resources[i]) + pipe_resource_reference(&rsurf->resources[i], NULL); + } + rsurf->resource_mask = 0x0; + } +} + +void +resource_surface_destroy(struct resource_surface *rsurf) +{ + resource_surface_free_resources(rsurf); + FREE(rsurf); +} + +boolean +resource_surface_set_size(struct resource_surface *rsurf, + uint width, uint height) +{ + boolean changed = FALSE; + + if (rsurf->width != width || rsurf->height != height) { + resource_surface_free_resources(rsurf); + rsurf->width = width; + rsurf->height = height; + changed = TRUE; + } + + return changed; +} + +void +resource_surface_get_size(struct resource_surface *rsurf, + uint *width, uint *height) +{ + if (width) + *width = rsurf->width; + if (height) + *height = rsurf->height; +} + +boolean +resource_surface_add_resources(struct resource_surface *rsurf, + uint resource_mask) +{ + struct pipe_resource templ; + int i; + + resource_mask &= ~rsurf->resource_mask; + if (!resource_mask) + return TRUE; + + if (!rsurf->width || !rsurf->height) + return FALSE; + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.format = rsurf->format; + templ.bind = rsurf->bind; + templ.width0 = rsurf->width; + templ.height0 = rsurf->height; + templ.depth0 = 1; + templ.array_size = 1; + + for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) { + if (resource_mask & (1 <resources[i]); + + rsurf->resources[i] = + rsurf->screen->resource_create(rsurf->screen, &templ); + if (rsurf->resources[i]) + rsurf->resource_mask |= 1 << i; + } + } + + return ((rsurf->resource_mask & resource_mask) == resource_mask); +} + + +void +resource_surface_get_resources(struct resource_surface *rsurf, + struct pipe_resource **resources, + uint resource_mask) +{ + int i; + + for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) { + if (resource_mask & (1 << i)) { + resources[i] = NULL; + pipe_resource_reference(&resources[i], rsurf->resources[i]); + } + } +} + +struct pipe_resource * +resource_surface_get_single_resource(struct resource_surface *rsurf, + enum native_attachment which) +{ + struct pipe_resource *pres = NULL; + pipe_resource_reference(&pres, rsurf->resources[which]); + return pres; +} + +static INLINE void +pointer_swap(const void **p1, const void **p2) +{ + const void *tmp = *p1; + *p1 = *p2; + *p2 = tmp; +} + +void +resource_surface_swap_buffers(struct resource_surface *rsurf, + enum native_attachment buf1, + enum native_attachment buf2, + boolean only_if_exist) +{ + const uint buf1_bit = 1 << buf1; + const uint buf2_bit = 1 << buf2; + uint mask; + + if (only_if_exist && !(rsurf->resources[buf1] && rsurf->resources[buf2])) + return; + + pointer_swap((const void **) &rsurf->resources[buf1], + (const void **) &rsurf->resources[buf2]); + + /* swap mask bits */ + mask = rsurf->resource_mask & ~(buf1_bit | buf2_bit); + if (rsurf->resource_mask & buf1_bit) + mask |= buf2_bit; + if (rsurf->resource_mask & buf2_bit) + mask |= buf1_bit; + + rsurf->resource_mask = mask; +} + +boolean +resource_surface_present(struct resource_surface *rsurf, + enum native_attachment which, + void *winsys_drawable_handle) +{ + struct pipe_resource *pres = rsurf->resources[which]; + + if (!pres) + return TRUE; + + rsurf->screen->flush_frontbuffer(rsurf->screen, + pres, 0, 0, winsys_drawable_handle); + + return TRUE; +} diff --git a/src/gallium/state_trackers/egl/common/native_helper.h b/src/gallium/state_trackers/egl/common/native_helper.h new file mode 100644 index 0000000..d1569ac --- /dev/null +++ b/src/gallium/state_trackers/egl/common/native_helper.h @@ -0,0 +1,71 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "native.h" + +struct resource_surface; +struct sw_winsys; + +struct resource_surface * +resource_surface_create(struct pipe_screen *screen, + enum pipe_format format, uint bind); + +void +resource_surface_destroy(struct resource_surface *rsurf); + +boolean +resource_surface_set_size(struct resource_surface *rsurf, + uint width, uint height); + +void +resource_surface_get_size(struct resource_surface *rsurf, + uint *width, uint *height); + +boolean +resource_surface_add_resources(struct resource_surface *rsurf, + uint resource_mask); + +void +resource_surface_get_resources(struct resource_surface *rsurf, + struct pipe_resource **resources, + uint resource_mask); + +struct pipe_resource * +resource_surface_get_single_resource(struct resource_surface *rsurf, + enum native_attachment which); + +void +resource_surface_swap_buffers(struct resource_surface *rsurf, + enum native_attachment buf1, + enum native_attachment buf2, + boolean only_if_exist); + +boolean +resource_surface_present(struct resource_surface *rsurf, + enum native_attachment which, + void *winsys_drawable_handle); diff --git a/src/gallium/state_trackers/egl/common/native_modeset.h b/src/gallium/state_trackers/egl/common/native_modeset.h new file mode 100644 index 0000000..2598082 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/native_modeset.h @@ -0,0 +1,88 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2009-2010 Chia-I Wu + * + * 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 _NATIVE_MODESET_H_ +#define _NATIVE_MODESET_H_ + +#include "pipe/p_compiler.h" + +struct native_display; +struct native_surface; +struct native_config; + +struct native_connector { + int dummy; +}; + +struct native_mode { + const char *desc; + int width, height; + int refresh_rate; /* HZ * 1000 */ +}; + +/** + * Mode setting interface of the native display. It exposes the mode setting + * capabilities of the underlying graphics hardware. + */ +struct native_display_modeset { + /** + * Get the available physical connectors and the number of CRTCs. + */ + const struct native_connector **(*get_connectors)(struct native_display *ndpy, + int *num_connectors, + int *num_crtcs); + + /** + * Get the current supported modes of a connector. The returned modes may + * change every time this function is called and those from previous calls + * might become invalid. + */ + const struct native_mode **(*get_modes)(struct native_display *ndpy, + const struct native_connector *nconn, + int *num_modes); + + /** + * Create a scan-out surface. Required unless no config has scanout_bit + * set. + */ + struct native_surface *(*create_scanout_surface)(struct native_display *ndpy, + const struct native_config *nconf, + uint width, uint height); + + /** + * Program the CRTC to output the surface to the given connectors with the + * given mode. When surface is not given, the CRTC is disabled. + * + * This interface does not export a way to query capabilities of the CRTCs. + * The native display usually needs to dynamically map the index to a CRTC + * that supports the given connectors. + */ + boolean (*program)(struct native_display *ndpy, int crtc_idx, + struct native_surface *nsurf, uint x, uint y, + const struct native_connector **nconns, int num_nconns, + const struct native_mode *nmode); +}; + +#endif /* _NATIVE_MODESET_H_ */ diff --git a/src/gallium/state_trackers/egl/drm/modeset.c b/src/gallium/state_trackers/egl/drm/modeset.c new file mode 100644 index 0000000..0cc06ca --- /dev/null +++ b/src/gallium/state_trackers/egl/drm/modeset.c @@ -0,0 +1,644 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "egllog.h" + +#include "native_drm.h" + +static boolean +drm_surface_validate(struct native_surface *nsurf, uint attachment_mask, + unsigned int *seq_num, struct pipe_resource **textures, + int *width, int *height) +{ + struct drm_surface *drmsurf = drm_surface(nsurf); + + if (!resource_surface_add_resources(drmsurf->rsurf, attachment_mask)) + return FALSE; + if (textures) + resource_surface_get_resources(drmsurf->rsurf, textures, attachment_mask); + + if (seq_num) + *seq_num = drmsurf->sequence_number; + if (width) + *width = drmsurf->width; + if (height) + *height = drmsurf->height; + + return TRUE; +} + +/** + * Add textures as DRM framebuffers. + */ +static boolean +drm_surface_init_framebuffers(struct native_surface *nsurf, boolean need_back) +{ + struct drm_surface *drmsurf = drm_surface(nsurf); + struct drm_display *drmdpy = drmsurf->drmdpy; + int num_framebuffers = (need_back) ? 2 : 1; + int i, err; + + for (i = 0; i < num_framebuffers; i++) { + struct drm_framebuffer *fb; + enum native_attachment natt; + struct winsys_handle whandle; + uint block_bits; + + if (i == 0) { + fb = &drmsurf->front_fb; + natt = NATIVE_ATTACHMENT_FRONT_LEFT; + } + else { + fb = &drmsurf->back_fb; + natt = NATIVE_ATTACHMENT_BACK_LEFT; + } + + if (!fb->texture) { + /* make sure the texture has been allocated */ + resource_surface_add_resources(drmsurf->rsurf, 1 << natt); + fb->texture = + resource_surface_get_single_resource(drmsurf->rsurf, natt); + if (!fb->texture) + return FALSE; + } + + /* already initialized */ + if (fb->buffer_id) + continue; + + /* TODO detect the real value */ + fb->is_passive = TRUE; + + memset(&whandle, 0, sizeof(whandle)); + whandle.type = DRM_API_HANDLE_TYPE_KMS; + + if (!drmdpy->base.screen->resource_get_handle(drmdpy->base.screen, + fb->texture, &whandle)) + return FALSE; + + block_bits = util_format_get_blocksizebits(drmsurf->color_format); + err = drmModeAddFB(drmdpy->fd, drmsurf->width, drmsurf->height, + block_bits, block_bits, whandle.stride, whandle.handle, + &fb->buffer_id); + if (err) { + fb->buffer_id = 0; + return FALSE; + } + } + + return TRUE; +} + +static boolean +drm_surface_flush_frontbuffer(struct native_surface *nsurf) +{ +#ifdef DRM_MODE_FEATURE_DIRTYFB + struct drm_surface *drmsurf = drm_surface(nsurf); + struct drm_display *drmdpy = drmsurf->drmdpy; + + if (drmsurf->front_fb.is_passive) + drmModeDirtyFB(drmdpy->fd, drmsurf->front_fb.buffer_id, NULL, 0); +#endif + + return TRUE; +} + +static boolean +drm_surface_swap_buffers(struct native_surface *nsurf) +{ + struct drm_surface *drmsurf = drm_surface(nsurf); + struct drm_crtc *drmcrtc = &drmsurf->current_crtc; + struct drm_display *drmdpy = drmsurf->drmdpy; + struct drm_framebuffer tmp_fb; + int err; + + if (!drmsurf->back_fb.buffer_id) { + if (!drm_surface_init_framebuffers(&drmsurf->base, TRUE)) + return FALSE; + } + + if (drmsurf->is_shown && drmcrtc->crtc) { + err = drmModeSetCrtc(drmdpy->fd, drmcrtc->crtc->crtc_id, + drmsurf->back_fb.buffer_id, drmcrtc->crtc->x, drmcrtc->crtc->y, + drmcrtc->connectors, drmcrtc->num_connectors, &drmcrtc->crtc->mode); + if (err) + return FALSE; + } + + /* swap the buffers */ + tmp_fb = drmsurf->front_fb; + drmsurf->front_fb = drmsurf->back_fb; + drmsurf->back_fb = tmp_fb; + + resource_surface_swap_buffers(drmsurf->rsurf, + NATIVE_ATTACHMENT_FRONT_LEFT, NATIVE_ATTACHMENT_BACK_LEFT, FALSE); + /* the front/back textures are swapped */ + drmsurf->sequence_number++; + drmdpy->event_handler->invalid_surface(&drmdpy->base, + &drmsurf->base, drmsurf->sequence_number); + + return TRUE; +} + +static boolean +drm_surface_present(struct native_surface *nsurf, + enum native_attachment natt, + boolean preserve, + uint swap_interval) +{ + boolean ret; + + if (preserve || swap_interval) + return FALSE; + + switch (natt) { + case NATIVE_ATTACHMENT_FRONT_LEFT: + ret = drm_surface_flush_frontbuffer(nsurf); + break; + case NATIVE_ATTACHMENT_BACK_LEFT: + ret = drm_surface_swap_buffers(nsurf); + break; + default: + ret = FALSE; + break; + } + + return ret; +} + +static void +drm_surface_wait(struct native_surface *nsurf) +{ + /* no-op */ +} + +static void +drm_surface_destroy(struct native_surface *nsurf) +{ + struct drm_surface *drmsurf = drm_surface(nsurf); + + if (drmsurf->current_crtc.crtc) + drmModeFreeCrtc(drmsurf->current_crtc.crtc); + + if (drmsurf->front_fb.buffer_id) + drmModeRmFB(drmsurf->drmdpy->fd, drmsurf->front_fb.buffer_id); + pipe_resource_reference(&drmsurf->front_fb.texture, NULL); + + if (drmsurf->back_fb.buffer_id) + drmModeRmFB(drmsurf->drmdpy->fd, drmsurf->back_fb.buffer_id); + pipe_resource_reference(&drmsurf->back_fb.texture, NULL); + + resource_surface_destroy(drmsurf->rsurf); + FREE(drmsurf); +} + +static struct drm_surface * +drm_display_create_surface(struct native_display *ndpy, + const struct native_config *nconf, + uint width, uint height) +{ + struct drm_display *drmdpy = drm_display(ndpy); + struct drm_config *drmconf = drm_config(nconf); + struct drm_surface *drmsurf; + + drmsurf = CALLOC_STRUCT(drm_surface); + if (!drmsurf) + return NULL; + + drmsurf->drmdpy = drmdpy; + drmsurf->color_format = drmconf->base.color_format; + drmsurf->width = width; + drmsurf->height = height; + + drmsurf->rsurf = resource_surface_create(drmdpy->base.screen, + drmsurf->color_format, + PIPE_BIND_RENDER_TARGET | + PIPE_BIND_SAMPLER_VIEW | + PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SCANOUT); + if (!drmsurf->rsurf) { + FREE(drmsurf); + return NULL; + } + + resource_surface_set_size(drmsurf->rsurf, drmsurf->width, drmsurf->height); + + drmsurf->base.destroy = drm_surface_destroy; + drmsurf->base.present = drm_surface_present; + drmsurf->base.validate = drm_surface_validate; + drmsurf->base.wait = drm_surface_wait; + + return drmsurf; +} + +/** + * Choose a CRTC that supports all given connectors. + */ +static uint32_t +drm_display_choose_crtc(struct native_display *ndpy, + uint32_t *connectors, int num_connectors) +{ + struct drm_display *drmdpy = drm_display(ndpy); + int idx; + + for (idx = 0; idx < drmdpy->resources->count_crtcs; idx++) { + boolean found_crtc = TRUE; + int i, j; + + for (i = 0; i < num_connectors; i++) { + drmModeConnectorPtr connector; + int encoder_idx = -1; + + connector = drmModeGetConnector(drmdpy->fd, connectors[i]); + if (!connector) { + found_crtc = FALSE; + break; + } + + /* find an encoder the CRTC supports */ + for (j = 0; j < connector->count_encoders; j++) { + drmModeEncoderPtr encoder = + drmModeGetEncoder(drmdpy->fd, connector->encoders[j]); + if (encoder->possible_crtcs & (1 << idx)) { + encoder_idx = j; + break; + } + drmModeFreeEncoder(encoder); + } + + drmModeFreeConnector(connector); + if (encoder_idx < 0) { + found_crtc = FALSE; + break; + } + } + + if (found_crtc) + break; + } + + if (idx >= drmdpy->resources->count_crtcs) { + _eglLog(_EGL_WARNING, + "failed to find a CRTC that supports the given %d connectors", + num_connectors); + return 0; + } + + return drmdpy->resources->crtcs[idx]; +} + +/** + * Remember the original CRTC status and set the CRTC + */ +static boolean +drm_display_set_crtc(struct native_display *ndpy, int crtc_idx, + uint32_t buffer_id, uint32_t x, uint32_t y, + uint32_t *connectors, int num_connectors, + drmModeModeInfoPtr mode) +{ + struct drm_display *drmdpy = drm_display(ndpy); + struct drm_crtc *drmcrtc = &drmdpy->saved_crtcs[crtc_idx]; + uint32_t crtc_id; + int err; + + if (drmcrtc->crtc) { + crtc_id = drmcrtc->crtc->crtc_id; + } + else { + int count = 0, i; + + /* + * Choose the CRTC once. It could be more dynamic, but let's keep it + * simple for now. + */ + crtc_id = drm_display_choose_crtc(&drmdpy->base, + connectors, num_connectors); + + /* save the original CRTC status */ + drmcrtc->crtc = drmModeGetCrtc(drmdpy->fd, crtc_id); + if (!drmcrtc->crtc) + return FALSE; + + for (i = 0; i < drmdpy->num_connectors; i++) { + struct drm_connector *drmconn = &drmdpy->connectors[i]; + drmModeConnectorPtr connector = drmconn->connector; + drmModeEncoderPtr encoder; + + encoder = drmModeGetEncoder(drmdpy->fd, connector->encoder_id); + if (encoder) { + if (encoder->crtc_id == crtc_id) { + drmcrtc->connectors[count++] = connector->connector_id; + if (count >= Elements(drmcrtc->connectors)) + break; + } + drmModeFreeEncoder(encoder); + } + } + + drmcrtc->num_connectors = count; + } + + err = drmModeSetCrtc(drmdpy->fd, crtc_id, buffer_id, x, y, + connectors, num_connectors, mode); + if (err) { + drmModeFreeCrtc(drmcrtc->crtc); + drmcrtc->crtc = NULL; + drmcrtc->num_connectors = 0; + + return FALSE; + } + + return TRUE; +} + +static boolean +drm_display_program(struct native_display *ndpy, int crtc_idx, + struct native_surface *nsurf, uint x, uint y, + const struct native_connector **nconns, int num_nconns, + const struct native_mode *nmode) +{ + struct drm_display *drmdpy = drm_display(ndpy); + struct drm_surface *drmsurf = drm_surface(nsurf); + const struct drm_mode *drmmode = drm_mode(nmode); + uint32_t connector_ids[32]; + uint32_t buffer_id; + drmModeModeInfo mode_tmp, *mode; + int i; + + if (num_nconns > Elements(connector_ids)) { + _eglLog(_EGL_WARNING, "too many connectors (%d)", num_nconns); + num_nconns = Elements(connector_ids); + } + + if (drmsurf) { + if (!drm_surface_init_framebuffers(&drmsurf->base, FALSE)) + return FALSE; + + buffer_id = drmsurf->front_fb.buffer_id; + /* the mode argument of drmModeSetCrtc is not constified */ + mode_tmp = drmmode->mode; + mode = &mode_tmp; + } + else { + /* disable the CRTC */ + buffer_id = 0; + mode = NULL; + num_nconns = 0; + } + + for (i = 0; i < num_nconns; i++) { + struct drm_connector *drmconn = drm_connector(nconns[i]); + connector_ids[i] = drmconn->connector->connector_id; + } + + if (!drm_display_set_crtc(&drmdpy->base, crtc_idx, buffer_id, x, y, + connector_ids, num_nconns, mode)) { + _eglLog(_EGL_WARNING, "failed to set CRTC %d", crtc_idx); + + return FALSE; + } + + if (drmdpy->shown_surfaces[crtc_idx]) + drmdpy->shown_surfaces[crtc_idx]->is_shown = FALSE; + drmdpy->shown_surfaces[crtc_idx] = drmsurf; + + /* remember the settings for buffer swapping */ + if (drmsurf) { + uint32_t crtc_id = drmdpy->saved_crtcs[crtc_idx].crtc->crtc_id; + struct drm_crtc *drmcrtc = &drmsurf->current_crtc; + + if (drmcrtc->crtc) + drmModeFreeCrtc(drmcrtc->crtc); + drmcrtc->crtc = drmModeGetCrtc(drmdpy->fd, crtc_id); + + assert(num_nconns < Elements(drmcrtc->connectors)); + memcpy(drmcrtc->connectors, connector_ids, + sizeof(*connector_ids) * num_nconns); + drmcrtc->num_connectors = num_nconns; + + drmsurf->is_shown = TRUE; + } + + return TRUE; +} + +static const struct native_mode ** +drm_display_get_modes(struct native_display *ndpy, + const struct native_connector *nconn, + int *num_modes) +{ + struct drm_display *drmdpy = drm_display(ndpy); + struct drm_connector *drmconn = drm_connector(nconn); + const struct native_mode **nmodes_return; + int count, i; + + /* delete old data */ + if (drmconn->connector) { + drmModeFreeConnector(drmconn->connector); + FREE(drmconn->drm_modes); + + drmconn->connector = NULL; + drmconn->drm_modes = NULL; + drmconn->num_modes = 0; + } + + /* detect again */ + drmconn->connector = drmModeGetConnector(drmdpy->fd, drmconn->connector_id); + if (!drmconn->connector) + return NULL; + + count = drmconn->connector->count_modes; + drmconn->drm_modes = CALLOC(count, sizeof(*drmconn->drm_modes)); + if (!drmconn->drm_modes) { + drmModeFreeConnector(drmconn->connector); + drmconn->connector = NULL; + + return NULL; + } + + for (i = 0; i < count; i++) { + struct drm_mode *drmmode = &drmconn->drm_modes[i]; + drmModeModeInfoPtr mode = &drmconn->connector->modes[i]; + + drmmode->mode = *mode; + + drmmode->base.desc = drmmode->mode.name; + drmmode->base.width = drmmode->mode.hdisplay; + drmmode->base.height = drmmode->mode.vdisplay; + drmmode->base.refresh_rate = drmmode->mode.vrefresh; + /* not all kernels have vrefresh = refresh_rate * 1000 */ + if (drmmode->base.refresh_rate < 1000) + drmmode->base.refresh_rate *= 1000; + } + + nmodes_return = MALLOC(count * sizeof(*nmodes_return)); + if (nmodes_return) { + for (i = 0; i < count; i++) + nmodes_return[i] = &drmconn->drm_modes[i].base; + if (num_modes) + *num_modes = count; + } + + return nmodes_return; +} + +static const struct native_connector ** +drm_display_get_connectors(struct native_display *ndpy, int *num_connectors, + int *num_crtc) +{ + struct drm_display *drmdpy = drm_display(ndpy); + const struct native_connector **connectors; + int i; + + if (!drmdpy->connectors) { + drmdpy->connectors = + CALLOC(drmdpy->resources->count_connectors, sizeof(*drmdpy->connectors)); + if (!drmdpy->connectors) + return NULL; + + for (i = 0; i < drmdpy->resources->count_connectors; i++) { + struct drm_connector *drmconn = &drmdpy->connectors[i]; + + drmconn->connector_id = drmdpy->resources->connectors[i]; + /* drmconn->connector is allocated when the modes are asked */ + } + + drmdpy->num_connectors = drmdpy->resources->count_connectors; + } + + connectors = MALLOC(drmdpy->num_connectors * sizeof(*connectors)); + if (connectors) { + for (i = 0; i < drmdpy->num_connectors; i++) + connectors[i] = &drmdpy->connectors[i].base; + if (num_connectors) + *num_connectors = drmdpy->num_connectors; + } + + if (num_crtc) + *num_crtc = drmdpy->resources->count_crtcs; + + return connectors; +} + +static struct native_surface * +drm_display_create_scanout_surface(struct native_display *ndpy, + const struct native_config *nconf, + uint width, uint height) +{ + struct drm_surface *drmsurf; + + drmsurf = drm_display_create_surface(ndpy, nconf, width, height); + return &drmsurf->base; +} + +static struct native_display_modeset drm_display_modeset = { + .get_connectors = drm_display_get_connectors, + .get_modes = drm_display_get_modes, + .create_scanout_surface = drm_display_create_scanout_surface, + .program = drm_display_program +}; + +void +drm_display_fini_modeset(struct native_display *ndpy) +{ + struct drm_display *drmdpy = drm_display(ndpy); + int i; + + if (drmdpy->connectors) { + for (i = 0; i < drmdpy->num_connectors; i++) { + struct drm_connector *drmconn = &drmdpy->connectors[i]; + if (drmconn->connector) { + drmModeFreeConnector(drmconn->connector); + FREE(drmconn->drm_modes); + } + } + FREE(drmdpy->connectors); + } + + if (drmdpy->shown_surfaces) { + FREE(drmdpy->shown_surfaces); + drmdpy->shown_surfaces = NULL; + } + + if (drmdpy->saved_crtcs) { + for (i = 0; i < drmdpy->resources->count_crtcs; i++) { + struct drm_crtc *drmcrtc = &drmdpy->saved_crtcs[i]; + + if (drmcrtc->crtc) { + /* restore crtc */ + drmModeSetCrtc(drmdpy->fd, drmcrtc->crtc->crtc_id, + drmcrtc->crtc->buffer_id, drmcrtc->crtc->x, drmcrtc->crtc->y, + drmcrtc->connectors, drmcrtc->num_connectors, + &drmcrtc->crtc->mode); + + drmModeFreeCrtc(drmcrtc->crtc); + } + } + FREE(drmdpy->saved_crtcs); + } + + if (drmdpy->resources) { + drmModeFreeResources(drmdpy->resources); + drmdpy->resources = NULL; + } + + drmdpy->base.modeset = NULL; +} + +boolean +drm_display_init_modeset(struct native_display *ndpy) +{ + struct drm_display *drmdpy = drm_display(ndpy); + + /* resources are fixed, unlike crtc, connector, or encoder */ + drmdpy->resources = drmModeGetResources(drmdpy->fd); + if (!drmdpy->resources) { + _eglLog(_EGL_DEBUG, "Failed to get KMS resources. Disable modeset."); + return FALSE; + } + + drmdpy->saved_crtcs = + CALLOC(drmdpy->resources->count_crtcs, sizeof(*drmdpy->saved_crtcs)); + if (!drmdpy->saved_crtcs) { + drm_display_fini_modeset(&drmdpy->base); + return FALSE; + } + + drmdpy->shown_surfaces = + CALLOC(drmdpy->resources->count_crtcs, sizeof(*drmdpy->shown_surfaces)); + if (!drmdpy->shown_surfaces) { + drm_display_fini_modeset(&drmdpy->base); + return FALSE; + } + + drmdpy->base.modeset = &drm_display_modeset; + + return TRUE; +} diff --git a/src/gallium/state_trackers/egl/drm/native_drm.c b/src/gallium/state_trackers/egl/drm/native_drm.c new file mode 100644 index 0000000..2441b43 --- /dev/null +++ b/src/gallium/state_trackers/egl/drm/native_drm.c @@ -0,0 +1,267 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2010 Chia-I Wu + * + * 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 +#include +#include + +#include "util/u_memory.h" +#include "egllog.h" + +#include "native_drm.h" + +/* see get_drm_screen_name */ +#include +#include "radeon/drm/radeon_drm_public.h" + +static boolean +drm_display_is_format_supported(struct native_display *ndpy, + enum pipe_format fmt, boolean is_color) +{ + return ndpy->screen->is_format_supported(ndpy->screen, + fmt, PIPE_TEXTURE_2D, 0, + (is_color) ? PIPE_BIND_RENDER_TARGET : + PIPE_BIND_DEPTH_STENCIL, 0); +} + +static const struct native_config ** +drm_display_get_configs(struct native_display *ndpy, int *num_configs) +{ + struct drm_display *drmdpy = drm_display(ndpy); + const struct native_config **configs; + + /* first time */ + if (!drmdpy->config) { + struct native_config *nconf; + enum pipe_format format; + + drmdpy->config = CALLOC(1, sizeof(*drmdpy->config)); + if (!drmdpy->config) + return NULL; + + nconf = &drmdpy->config->base; + + nconf->buffer_mask = + (1 << NATIVE_ATTACHMENT_FRONT_LEFT) | + (1 << NATIVE_ATTACHMENT_BACK_LEFT); + + format = PIPE_FORMAT_B8G8R8A8_UNORM; + if (!drm_display_is_format_supported(&drmdpy->base, format, TRUE)) { + format = PIPE_FORMAT_A8R8G8B8_UNORM; + if (!drm_display_is_format_supported(&drmdpy->base, format, TRUE)) + format = PIPE_FORMAT_NONE; + } + if (format == PIPE_FORMAT_NONE) { + FREE(drmdpy->config); + drmdpy->config = NULL; + return NULL; + } + + nconf->color_format = format; + + /* support KMS */ + if (drmdpy->resources) + nconf->scanout_bit = TRUE; + } + + configs = MALLOC(sizeof(*configs)); + if (configs) { + configs[0] = &drmdpy->config->base; + if (num_configs) + *num_configs = 1; + } + + return configs; +} + +static int +drm_display_get_param(struct native_display *ndpy, + enum native_param_type param) +{ + int val; + + switch (param) { + case NATIVE_PARAM_USE_NATIVE_BUFFER: + case NATIVE_PARAM_PRESERVE_BUFFER: + case NATIVE_PARAM_MAX_SWAP_INTERVAL: + default: + val = 0; + break; + } + + return val; +} + +static void +drm_display_destroy(struct native_display *ndpy) +{ + struct drm_display *drmdpy = drm_display(ndpy); + + if (drmdpy->config) + FREE(drmdpy->config); + + drm_display_fini_modeset(&drmdpy->base); + + if (drmdpy->base.screen) + drmdpy->base.screen->destroy(drmdpy->base.screen); + + if (drmdpy->fd >= 0) + close(drmdpy->fd); + + FREE(drmdpy); +} + +static const char * +get_drm_screen_name(int fd, drmVersionPtr version) +{ + const char *name = version->name; + + if (name && !strcmp(name, "radeon")) { + int chip_id; + struct drm_radeon_info info; + + memset(&info, 0, sizeof(info)); + info.request = RADEON_INFO_DEVICE_ID; + info.value = pointer_to_intptr(&chip_id); + if (drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)) != 0) + return NULL; + + name = is_r3xx(chip_id) ? "r300" : "r600"; + } + + return name; +} + +/** + * Initialize KMS and pipe screen. + */ +static boolean +drm_display_init_screen(struct native_display *ndpy) +{ + struct drm_display *drmdpy = drm_display(ndpy); + drmVersionPtr version; + const char *name; + + version = drmGetVersion(drmdpy->fd); + if (!version) { + _eglLog(_EGL_WARNING, "invalid fd %d", drmdpy->fd); + return FALSE; + } + + name = get_drm_screen_name(drmdpy->fd, version); + if (name) { + drmdpy->base.screen = + drmdpy->event_handler->new_drm_screen(&drmdpy->base, name, drmdpy->fd); + } + drmFreeVersion(version); + + if (!drmdpy->base.screen) { + _eglLog(_EGL_WARNING, "failed to create DRM screen"); + return FALSE; + } + + return TRUE; +} + +static struct pipe_resource * +drm_display_import_buffer(struct native_display *ndpy, + const struct pipe_resource *templ, + void *buf) +{ + return ndpy->screen->resource_from_handle(ndpy->screen, + templ, (struct winsys_handle *) buf); +} + +static boolean +drm_display_export_buffer(struct native_display *ndpy, + struct pipe_resource *res, + void *buf) +{ + return ndpy->screen->resource_get_handle(ndpy->screen, + res, (struct winsys_handle *) buf); +} + +static struct native_display_buffer drm_display_buffer = { + drm_display_import_buffer, + drm_display_export_buffer +}; + +static struct native_display * +drm_create_display(int fd, struct native_event_handler *event_handler, + void *user_data) +{ + struct drm_display *drmdpy; + + drmdpy = CALLOC_STRUCT(drm_display); + if (!drmdpy) + return NULL; + + drmdpy->fd = fd; + drmdpy->event_handler = event_handler; + drmdpy->base.user_data = user_data; + + if (!drm_display_init_screen(&drmdpy->base)) { + drm_display_destroy(&drmdpy->base); + return NULL; + } + + drmdpy->base.destroy = drm_display_destroy; + drmdpy->base.get_param = drm_display_get_param; + drmdpy->base.get_configs = drm_display_get_configs; + + drmdpy->base.buffer = &drm_display_buffer; + drm_display_init_modeset(&drmdpy->base); + + return &drmdpy->base; +} + +static struct native_display * +native_create_display(void *dpy, struct native_event_handler *event_handler, + void *user_data) +{ + int fd; + + if (dpy) { + fd = dup((int) pointer_to_intptr(dpy)); + } + else { + fd = open("/dev/dri/card0", O_RDWR); + } + if (fd < 0) + return NULL; + + return drm_create_display(fd, event_handler, user_data); +} + +static const struct native_platform drm_platform = { + "DRM", /* name */ + native_create_display +}; + +const struct native_platform * +native_get_drm_platform(void) +{ + return &drm_platform; +} diff --git a/src/gallium/state_trackers/egl/drm/native_drm.h b/src/gallium/state_trackers/egl/drm/native_drm.h new file mode 100644 index 0000000..03c4fe0 --- /dev/null +++ b/src/gallium/state_trackers/egl/drm/native_drm.h @@ -0,0 +1,146 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2010 Chia-I Wu + * + * 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 _NATIVE_DRM_H_ +#define _NATIVE_DRM_H_ + +#include +#include + +#include "pipe/p_compiler.h" +#include "util/u_format.h" +#include "pipe/p_state.h" +#include "state_tracker/drm_driver.h" + +#include "common/native.h" +#include "common/native_helper.h" + +struct drm_config; +struct drm_crtc; +struct drm_connector; +struct drm_mode; +struct drm_surface; + +struct drm_display { + struct native_display base; + + struct native_event_handler *event_handler; + + int fd; + struct drm_config *config; + + /* for modesetting */ + drmModeResPtr resources; + struct drm_connector *connectors; + int num_connectors; + + struct drm_surface **shown_surfaces; + /* save the original settings of the CRTCs */ + struct drm_crtc *saved_crtcs; +}; + +struct drm_config { + struct native_config base; +}; + +struct drm_crtc { + drmModeCrtcPtr crtc; + uint32_t connectors[32]; + int num_connectors; +}; + +struct drm_framebuffer { + struct pipe_resource *texture; + boolean is_passive; + + uint32_t buffer_id; +}; + +struct drm_surface { + struct native_surface base; + struct drm_display *drmdpy; + + struct resource_surface *rsurf; + enum pipe_format color_format; + int width, height; + + unsigned int sequence_number; + struct drm_framebuffer front_fb, back_fb; + + boolean is_shown; + struct drm_crtc current_crtc; +}; + +struct drm_connector { + struct native_connector base; + + uint32_t connector_id; + drmModeConnectorPtr connector; + struct drm_mode *drm_modes; + int num_modes; +}; + +struct drm_mode { + struct native_mode base; + drmModeModeInfo mode; +}; + +static INLINE struct drm_display * +drm_display(const struct native_display *ndpy) +{ + return (struct drm_display *) ndpy; +} + +static INLINE struct drm_config * +drm_config(const struct native_config *nconf) +{ + return (struct drm_config *) nconf; +} + +static INLINE struct drm_surface * +drm_surface(const struct native_surface *nsurf) +{ + return (struct drm_surface *) nsurf; +} + +static INLINE struct drm_connector * +drm_connector(const struct native_connector *nconn) +{ + return (struct drm_connector *) nconn; +} + +static INLINE struct drm_mode * +drm_mode(const struct native_mode *nmode) +{ + return (struct drm_mode *) nmode; +} + +boolean +drm_display_init_modeset(struct native_display *ndpy); + +void +drm_display_fini_modeset(struct native_display *ndpy); + +#endif /* _NATIVE_DRM_H_ */ diff --git a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c new file mode 100644 index 0000000..1b5ea8b --- /dev/null +++ b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c @@ -0,0 +1,495 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include +#include +#include +#include +#include + +#include "pipe/p_screen.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "util/u_pointer.h" + +#include "common/native.h" +#include "common/native_helper.h" +#include "fbdev/fbdev_sw_winsys.h" + +struct fbdev_display { + struct native_display base; + + int fd; + struct native_event_handler *event_handler; + + struct fb_fix_screeninfo finfo; + struct fb_var_screeninfo vinfo; + + struct native_config config; + struct native_connector connector; + struct native_mode mode; + + struct fbdev_surface *current_surface; +}; + +struct fbdev_surface { + struct native_surface base; + + struct fbdev_display *fbdpy; + struct resource_surface *rsurf; + int width, height; + + unsigned int sequence_number; + + boolean is_current; +}; + +static INLINE struct fbdev_display * +fbdev_display(const struct native_display *ndpy) +{ + return (struct fbdev_display *) ndpy; +} + +static INLINE struct fbdev_surface * +fbdev_surface(const struct native_surface *nsurf) +{ + return (struct fbdev_surface *) nsurf; +} + +static boolean +fbdev_surface_validate(struct native_surface *nsurf, uint attachment_mask, + unsigned int *seq_num, struct pipe_resource **textures, + int *width, int *height) +{ + struct fbdev_surface *fbsurf = fbdev_surface(nsurf); + + if (!resource_surface_add_resources(fbsurf->rsurf, attachment_mask)) + return FALSE; + if (textures) + resource_surface_get_resources(fbsurf->rsurf, textures, attachment_mask); + + if (seq_num) + *seq_num = fbsurf->sequence_number; + if (width) + *width = fbsurf->width; + if (height) + *height = fbsurf->height; + + return TRUE; +} + +static boolean +fbdev_surface_flush_frontbuffer(struct native_surface *nsurf) +{ + struct fbdev_surface *fbsurf = fbdev_surface(nsurf); + + if (!fbsurf->is_current) + return TRUE; + + return resource_surface_present(fbsurf->rsurf, + NATIVE_ATTACHMENT_FRONT_LEFT, NULL); +} + +static boolean +fbdev_surface_swap_buffers(struct native_surface *nsurf) +{ + struct fbdev_surface *fbsurf = fbdev_surface(nsurf); + struct fbdev_display *fbdpy = fbsurf->fbdpy; + boolean ret = TRUE; + + if (fbsurf->is_current) { + ret = resource_surface_present(fbsurf->rsurf, + NATIVE_ATTACHMENT_BACK_LEFT, NULL); + } + + resource_surface_swap_buffers(fbsurf->rsurf, + NATIVE_ATTACHMENT_FRONT_LEFT, NATIVE_ATTACHMENT_BACK_LEFT, TRUE); + /* the front/back textures are swapped */ + fbsurf->sequence_number++; + fbdpy->event_handler->invalid_surface(&fbdpy->base, + &fbsurf->base, fbsurf->sequence_number); + + return ret; +} + +static boolean +fbdev_surface_present(struct native_surface *nsurf, + enum native_attachment natt, + boolean preserve, + uint swap_interval) +{ + boolean ret; + + if (preserve || swap_interval) + return FALSE; + + switch (natt) { + case NATIVE_ATTACHMENT_FRONT_LEFT: + ret = fbdev_surface_flush_frontbuffer(nsurf); + break; + case NATIVE_ATTACHMENT_BACK_LEFT: + ret = fbdev_surface_swap_buffers(nsurf); + break; + default: + ret = FALSE; + break; + } + + return ret; +} + +static void +fbdev_surface_wait(struct native_surface *nsurf) +{ + /* no-op */ +} + +static void +fbdev_surface_destroy(struct native_surface *nsurf) +{ + struct fbdev_surface *fbsurf = fbdev_surface(nsurf); + + resource_surface_destroy(fbsurf->rsurf); + FREE(fbsurf); +} + +static struct native_surface * +fbdev_display_create_scanout_surface(struct native_display *ndpy, + const struct native_config *nconf, + uint width, uint height) +{ + struct fbdev_display *fbdpy = fbdev_display(ndpy); + struct fbdev_surface *fbsurf; + + fbsurf = CALLOC_STRUCT(fbdev_surface); + if (!fbsurf) + return NULL; + + fbsurf->fbdpy = fbdpy; + fbsurf->width = width; + fbsurf->height = height; + + fbsurf->rsurf = resource_surface_create(fbdpy->base.screen, + nconf->color_format, + PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SCANOUT); + if (!fbsurf->rsurf) { + FREE(fbsurf); + return NULL; + } + + resource_surface_set_size(fbsurf->rsurf, fbsurf->width, fbsurf->height); + + fbsurf->base.destroy = fbdev_surface_destroy; + fbsurf->base.present = fbdev_surface_present; + fbsurf->base.validate = fbdev_surface_validate; + fbsurf->base.wait = fbdev_surface_wait; + + return &fbsurf->base; +} + +static boolean +fbdev_display_program(struct native_display *ndpy, int crtc_idx, + struct native_surface *nsurf, uint x, uint y, + const struct native_connector **nconns, int num_nconns, + const struct native_mode *nmode) +{ + struct fbdev_display *fbdpy = fbdev_display(ndpy); + struct fbdev_surface *fbsurf = fbdev_surface(nsurf); + + if (x || y) + return FALSE; + + if (fbdpy->current_surface) { + if (fbdpy->current_surface == fbsurf) + return TRUE; + fbdpy->current_surface->is_current = FALSE; + } + + if (fbsurf) + fbsurf->is_current = TRUE; + fbdpy->current_surface = fbsurf; + + return TRUE; +} + +static const struct native_mode ** +fbdev_display_get_modes(struct native_display *ndpy, + const struct native_connector *nconn, + int *num_modes) +{ + struct fbdev_display *fbdpy = fbdev_display(ndpy); + const struct native_mode **modes; + + modes = MALLOC(sizeof(*modes)); + if (modes) { + modes[0] = &fbdpy->mode; + if (num_modes) + *num_modes = 1; + } + + return modes; +} + +static const struct native_connector ** +fbdev_display_get_connectors(struct native_display *ndpy, int *num_connectors, + int *num_crtc) +{ + struct fbdev_display *fbdpy = fbdev_display(ndpy); + const struct native_connector **connectors; + + connectors = MALLOC(sizeof(*connectors)); + if (connectors) { + connectors[0] = &fbdpy->connector; + if (num_connectors) + *num_connectors = 1; + } + + return connectors; +} + +static struct native_display_modeset fbdev_display_modeset = { + .get_connectors = fbdev_display_get_connectors, + .get_modes = fbdev_display_get_modes, + .create_scanout_surface = fbdev_display_create_scanout_surface, + .program = fbdev_display_program +}; + +static const struct native_config ** +fbdev_display_get_configs(struct native_display *ndpy, int *num_configs) +{ + struct fbdev_display *fbdpy = fbdev_display(ndpy); + const struct native_config **configs; + + configs = MALLOC(sizeof(*configs)); + if (configs) { + configs[0] = &fbdpy->config; + if (num_configs) + *num_configs = 1; + } + + return configs; +} + +static int +fbdev_display_get_param(struct native_display *ndpy, + enum native_param_type param) +{ + int val; + + switch (param) { + case NATIVE_PARAM_USE_NATIVE_BUFFER: + case NATIVE_PARAM_PRESERVE_BUFFER: + case NATIVE_PARAM_MAX_SWAP_INTERVAL: + default: + val = 0; + break; + } + + return val; +} + +static void +fbdev_display_destroy(struct native_display *ndpy) +{ + struct fbdev_display *fbdpy = fbdev_display(ndpy); + + fbdpy->base.screen->destroy(fbdpy->base.screen); + close(fbdpy->fd); + FREE(fbdpy); +} + +static boolean +fbdev_display_init_modes(struct native_display *ndpy) +{ + struct fbdev_display *fbdpy = fbdev_display(ndpy); + struct native_mode *nmode = &fbdpy->mode; + + nmode->desc = "Current Mode"; + nmode->width = fbdpy->vinfo.xres; + nmode->height = fbdpy->vinfo.yres; + nmode->refresh_rate = 60 * 1000; /* dummy */ + + return TRUE; +} + +static boolean +fbdev_display_init_connectors(struct native_display *ndpy) +{ + return TRUE; +} + +static enum pipe_format +vinfo_to_format(const struct fb_var_screeninfo *vinfo) +{ + enum pipe_format format = PIPE_FORMAT_NONE; + + switch (vinfo->bits_per_pixel) { + case 32: + if (vinfo->red.length == 8 && + vinfo->green.length == 8 && + vinfo->blue.length == 8) { + format = (vinfo->transp.length == 8) ? + PIPE_FORMAT_B8G8R8A8_UNORM : PIPE_FORMAT_B8G8R8X8_UNORM; + } + break; + case 16: + if (vinfo->red.length == 5 && + vinfo->green.length == 6 && + vinfo->blue.length == 5 && + vinfo->transp.length == 0) + format = PIPE_FORMAT_B5G6R5_UNORM; + break; + default: + break; + } + + return format; +} + +static boolean +fbdev_display_init_configs(struct native_display *ndpy) +{ + struct fbdev_display *fbdpy = fbdev_display(ndpy); + struct native_config *nconf = &fbdpy->config; + + nconf->color_format = vinfo_to_format(&fbdpy->vinfo); + if (nconf->color_format == PIPE_FORMAT_NONE) + return FALSE; + + nconf->buffer_mask = + (1 << NATIVE_ATTACHMENT_FRONT_LEFT) | + (1 << NATIVE_ATTACHMENT_BACK_LEFT); + + nconf->scanout_bit = TRUE; + + return TRUE; +} + +static boolean +fbdev_display_init(struct native_display *ndpy) +{ + struct fbdev_display *fbdpy = fbdev_display(ndpy); + struct sw_winsys *ws; + + if (ioctl(fbdpy->fd, FBIOGET_FSCREENINFO, &fbdpy->finfo)) + return FALSE; + + if (ioctl(fbdpy->fd, FBIOGET_VSCREENINFO, &fbdpy->vinfo)) + return FALSE; + + if (fbdpy->finfo.visual != FB_VISUAL_TRUECOLOR || + fbdpy->finfo.type != FB_TYPE_PACKED_PIXELS) + return FALSE; + + if (!fbdev_display_init_configs(&fbdpy->base) || + !fbdev_display_init_connectors(&fbdpy->base) || + !fbdev_display_init_modes(&fbdpy->base)) + return FALSE; + + ws = fbdev_create_sw_winsys(fbdpy->fd, fbdpy->config.color_format); + if (ws) { + fbdpy->base.screen = + fbdpy->event_handler->new_sw_screen(&fbdpy->base, ws); + } + + if (fbdpy->base.screen) { + if (!fbdpy->base.screen->is_format_supported(fbdpy->base.screen, + fbdpy->config.color_format, PIPE_TEXTURE_2D, 0, + PIPE_BIND_RENDER_TARGET, 0)) { + fbdpy->base.screen->destroy(fbdpy->base.screen); + fbdpy->base.screen = NULL; + } + } + + return (fbdpy->base.screen != NULL); +} + +static struct native_display * +fbdev_display_create(int fd, struct native_event_handler *event_handler, + void *user_data) +{ + struct fbdev_display *fbdpy; + + fbdpy = CALLOC_STRUCT(fbdev_display); + if (!fbdpy) + return NULL; + + fbdpy->fd = fd; + fbdpy->event_handler = event_handler; + fbdpy->base.user_data = user_data; + + if (!fbdev_display_init(&fbdpy->base)) { + FREE(fbdpy); + return NULL; + } + + fbdpy->base.destroy = fbdev_display_destroy; + fbdpy->base.get_param = fbdev_display_get_param; + fbdpy->base.get_configs = fbdev_display_get_configs; + + fbdpy->base.modeset = &fbdev_display_modeset; + + return &fbdpy->base; +} + +static struct native_display * +native_create_display(void *dpy, struct native_event_handler *event_handler, + void *user_data) +{ + struct native_display *ndpy; + int fd; + + /* well, this makes fd 0 being ignored */ + if (!dpy) { + fd = open("/dev/fb0", O_RDWR); + } + else { + fd = dup((int) pointer_to_intptr(dpy)); + } + if (fd < 0) + return NULL; + + ndpy = fbdev_display_create(fd, event_handler, user_data); + if (!ndpy) + close(fd); + + return ndpy; +} + +static const struct native_platform fbdev_platform = { + "FBDEV", /* name */ + native_create_display +}; + +const struct native_platform * +native_get_fbdev_platform(void) +{ + return &fbdev_platform; +} diff --git a/src/gallium/state_trackers/egl/gdi/native_gdi.c b/src/gallium/state_trackers/egl/gdi/native_gdi.c new file mode 100644 index 0000000..d259e6e --- /dev/null +++ b/src/gallium/state_trackers/egl/gdi/native_gdi.c @@ -0,0 +1,426 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include + +#include "pipe/p_compiler.h" +#include "util/u_memory.h" +#include "util/u_format.h" +#include "util/u_inlines.h" +#include "gdi/gdi_sw_winsys.h" + +#include "common/native_helper.h" +#include "common/native.h" + +struct gdi_display { + struct native_display base; + + HDC hDC; + struct native_event_handler *event_handler; + + struct native_config *configs; + int num_configs; +}; + +struct gdi_surface { + struct native_surface base; + + HWND hWnd; + enum pipe_format color_format; + + struct gdi_display *gdpy; + + unsigned int server_stamp; + unsigned int client_stamp; + + struct resource_surface *rsurf; +}; + +static INLINE struct gdi_display * +gdi_display(const struct native_display *ndpy) +{ + return (struct gdi_display *) ndpy; +} + +static INLINE struct gdi_surface * +gdi_surface(const struct native_surface *nsurf) +{ + return (struct gdi_surface *) nsurf; +} + +/** + * Update the geometry of the surface. This is a slow functions. + */ +static void +gdi_surface_update_geometry(struct native_surface *nsurf) +{ + struct gdi_surface *gsurf = gdi_surface(nsurf); + RECT rect; + uint w, h; + + GetClientRect(gsurf->hWnd, &rect); + w = rect.right - rect.left; + h = rect.bottom - rect.top; + + if (resource_surface_set_size(gsurf->rsurf, w, h)) + gsurf->server_stamp++; +} + +/** + * Update the buffers of the surface. + */ +static boolean +gdi_surface_update_buffers(struct native_surface *nsurf, uint buffer_mask) +{ + struct gdi_surface *gsurf = gdi_surface(nsurf); + + if (gsurf->client_stamp != gsurf->server_stamp) { + gdi_surface_update_geometry(&gsurf->base); + gsurf->client_stamp = gsurf->server_stamp; + } + + return resource_surface_add_resources(gsurf->rsurf, buffer_mask); +} + +/** + * Emulate an invalidate event. + */ +static void +gdi_surface_invalidate(struct native_surface *nsurf) +{ + struct gdi_surface *gsurf = gdi_surface(nsurf); + struct gdi_display *gdpy = gsurf->gdpy; + + gsurf->server_stamp++; + gdpy->event_handler->invalid_surface(&gdpy->base, + &gsurf->base, gsurf->server_stamp); +} + +static boolean +gdi_surface_flush_frontbuffer(struct native_surface *nsurf) +{ + struct gdi_surface *gsurf = gdi_surface(nsurf); + HDC hDC; + boolean ret; + + hDC = GetDC(gsurf->hWnd); + ret = resource_surface_present(gsurf->rsurf, + NATIVE_ATTACHMENT_FRONT_LEFT, (void *) hDC); + ReleaseDC(gsurf->hWnd, hDC); + + /* force buffers to be updated in next validation call */ + gdi_surface_invalidate(&gsurf->base); + + return ret; +} + +static boolean +gdi_surface_swap_buffers(struct native_surface *nsurf) +{ + struct gdi_surface *gsurf = gdi_surface(nsurf); + HDC hDC; + boolean ret; + + hDC = GetDC(gsurf->hWnd); + ret = resource_surface_present(gsurf->rsurf, + NATIVE_ATTACHMENT_BACK_LEFT, (void *) hDC); + ReleaseDC(gsurf->hWnd, hDC); + + resource_surface_swap_buffers(gsurf->rsurf, + NATIVE_ATTACHMENT_FRONT_LEFT, NATIVE_ATTACHMENT_BACK_LEFT, TRUE); + /* the front/back buffers have been swapped */ + gdi_surface_invalidate(&gsurf->base); + + return ret; +} + +static boolean +gdi_surface_present(struct native_surface *nsurf, + enum native_attachment natt, + boolean preserve, + uint swap_interval) +{ + boolean ret; + + if (preserve || swap_interval) + return FALSE; + + switch (natt) { + case NATIVE_ATTACHMENT_FRONT_LEFT: + ret = gdi_surface_flush_frontbuffer(nsurf); + break; + case NATIVE_ATTACHMENT_BACK_LEFT: + ret = gdi_surface_swap_buffers(nsurf); + break; + default: + ret = FALSE; + break; + } + + return ret; +} + +static boolean +gdi_surface_validate(struct native_surface *nsurf, uint attachment_mask, + unsigned int *seq_num, struct pipe_resource **textures, + int *width, int *height) +{ + struct gdi_surface *gsurf = gdi_surface(nsurf); + uint w, h; + + if (!gdi_surface_update_buffers(&gsurf->base, attachment_mask)) + return FALSE; + + if (seq_num) + *seq_num = gsurf->client_stamp; + + if (textures) + resource_surface_get_resources(gsurf->rsurf, textures, attachment_mask); + + resource_surface_get_size(gsurf->rsurf, &w, &h); + if (width) + *width = w; + if (height) + *height = h; + + return TRUE; +} + +static void +gdi_surface_wait(struct native_surface *nsurf) +{ + /* no-op */ +} + +static void +gdi_surface_destroy(struct native_surface *nsurf) +{ + struct gdi_surface *gsurf = gdi_surface(nsurf); + + resource_surface_destroy(gsurf->rsurf); + FREE(gsurf); +} + +static struct native_surface * +gdi_display_create_window_surface(struct native_display *ndpy, + EGLNativeWindowType win, + const struct native_config *nconf) +{ + struct gdi_display *gdpy = gdi_display(ndpy); + struct gdi_surface *gsurf; + + gsurf = CALLOC_STRUCT(gdi_surface); + if (!gsurf) + return NULL; + + gsurf->gdpy = gdpy; + gsurf->color_format = nconf->color_format; + gsurf->hWnd = (HWND) win; + + gsurf->rsurf = resource_surface_create(gdpy->base.screen, + gsurf->color_format, + PIPE_BIND_RENDER_TARGET | + PIPE_BIND_SAMPLER_VIEW | + PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SCANOUT); + if (!gsurf->rsurf) { + FREE(gsurf); + return NULL; + } + + /* initialize the geometry */ + gdi_surface_update_geometry(&gsurf->base); + + gsurf->base.destroy = gdi_surface_destroy; + gsurf->base.present = gdi_surface_present; + gsurf->base.validate = gdi_surface_validate; + gsurf->base.wait = gdi_surface_wait; + + return &gsurf->base; +} + +static int +fill_color_formats(struct native_display *ndpy, enum pipe_format formats[8]) +{ + struct pipe_screen *screen = ndpy->screen; + int i, count = 0; + + enum pipe_format candidates[] = { + /* 32-bit */ + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_A8R8G8B8_UNORM, + /* 24-bit */ + PIPE_FORMAT_B8G8R8X8_UNORM, + PIPE_FORMAT_X8R8G8B8_UNORM, + /* 16-bit */ + PIPE_FORMAT_B5G6R5_UNORM + }; + + assert(Elements(candidates) <= 8); + + for (i = 0; i < Elements(candidates); i++) { + if (screen->is_format_supported(screen, candidates[i], + PIPE_TEXTURE_2D, 0, PIPE_BIND_RENDER_TARGET, 0)) + formats[count++] = candidates[i]; + } + + return count; +} + +static const struct native_config ** +gdi_display_get_configs(struct native_display *ndpy, int *num_configs) +{ + struct gdi_display *gdpy = gdi_display(ndpy); + const struct native_config **configs; + int i; + + /* first time */ + if (!gdpy->configs) { + enum pipe_format formats[8]; + int i, count; + + count = fill_color_formats(&gdpy->base, formats); + + gdpy->configs = CALLOC(count, sizeof(*gdpy->configs)); + if (!gdpy->configs) + return NULL; + + for (i = 0; i < count; i++) { + struct native_config *nconf = &gdpy->configs[i]; + + nconf->buffer_mask = + (1 << NATIVE_ATTACHMENT_FRONT_LEFT) | + (1 << NATIVE_ATTACHMENT_BACK_LEFT); + nconf->color_format = formats[i]; + + nconf->window_bit = TRUE; + nconf->slow_config = TRUE; + } + + gdpy->num_configs = count; + } + + configs = MALLOC(gdpy->num_configs * sizeof(*configs)); + if (configs) { + for (i = 0; i < gdpy->num_configs; i++) + configs[i] = (const struct native_config *) &gdpy->configs[i]; + if (num_configs) + *num_configs = gdpy->num_configs; + } + return configs; +} + +static int +gdi_display_get_param(struct native_display *ndpy, + enum native_param_type param) +{ + int val; + + switch (param) { + case NATIVE_PARAM_USE_NATIVE_BUFFER: + /* private buffers are allocated */ + val = FALSE; + break; + case NATIVE_PARAM_PRESERVE_BUFFER: + case NATIVE_PARAM_MAX_SWAP_INTERVAL: + default: + val = 0; + break; + } + + return val; +} + +static void +gdi_display_destroy(struct native_display *ndpy) +{ + struct gdi_display *gdpy = gdi_display(ndpy); + + if (gdpy->configs) + FREE(gdpy->configs); + + gdpy->base.screen->destroy(gdpy->base.screen); + + FREE(gdpy); +} + +static struct native_display * +gdi_create_display(HDC hDC, struct native_event_handler *event_handler, + void *user_data) +{ + struct gdi_display *gdpy; + struct sw_winsys *winsys; + + gdpy = CALLOC_STRUCT(gdi_display); + if (!gdpy) + return NULL; + + gdpy->hDC = hDC; + gdpy->event_handler = event_handler; + gdpy->base.user_data = user_data; + + winsys = gdi_create_sw_winsys(); + if (!winsys) { + FREE(gdpy); + return NULL; + } + + gdpy->base.screen = gdpy->event_handler->new_sw_screen(&gdpy->base, winsys); + if (!gdpy->base.screen) { + if (winsys->destroy) + winsys->destroy(winsys); + FREE(gdpy); + return NULL; + } + + gdpy->base.destroy = gdi_display_destroy; + gdpy->base.get_param = gdi_display_get_param; + + gdpy->base.get_configs = gdi_display_get_configs; + gdpy->base.create_window_surface = gdi_display_create_window_surface; + + return &gdpy->base; +} + +static struct native_display * +native_create_display(void *dpy, struct native_event_handler *event_handler, + void *user_data) +{ + return gdi_create_display((HDC) dpy, event_handler, user_data); +} + +static const struct native_platform gdi_platform = { + "GDI", /* name */ + native_create_display +}; + +const struct native_platform * +native_get_gdi_platform(void) +{ + return &gdi_platform; +} diff --git a/src/gallium/state_trackers/egl/x11/glcore.h b/src/gallium/state_trackers/egl/x11/glcore.h new file mode 100644 index 0000000..547b111 --- /dev/null +++ b/src/gallium/state_trackers/egl/x11/glcore.h @@ -0,0 +1,181 @@ +#ifndef __gl_core_h_ +#define __gl_core_h_ + +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#if !defined(_WIN32_WCE) +#include +#endif + +#define GL_CORE_SGI 1 +#define GL_CORE_MESA 2 +#define GL_CORE_APPLE 4 +#define GL_CORE_WINDOWS 8 + +typedef struct __GLcontextRec __GLcontext; + +/* +** This file defines the interface between the GL core and the surrounding +** "operating system" that supports it (currently the GLX or WGL extensions). +** +** Members (data and function pointers) are documented as imported or +** exported according to how they are used by the core rendering functions. +** Imported members are initialized by the "operating system" and used by +** the core functions. Exported members are initialized by the core functions +** and used by the "operating system". +*/ + +/** + * Mode and limit information for a context. This information is + * kept around in the context so that values can be used during + * command execution, and for returning information about the + * context to the application. + * + * Instances of this structure are shared by the driver and the loader. To + * maintain binary compatability, new fields \b must be added only to the + * end of the structure. + * + * \sa _gl_context_modes_create + */ +typedef struct __GLcontextModesRec { + struct __GLcontextModesRec * next; + + GLboolean rgbMode; + GLboolean floatMode; + GLboolean colorIndexMode; + GLuint doubleBufferMode; + GLuint stereoMode; + + GLboolean haveAccumBuffer; + GLboolean haveDepthBuffer; + GLboolean haveStencilBuffer; + + GLint redBits, greenBits, blueBits, alphaBits; /* bits per comp */ + GLuint redMask, greenMask, blueMask, alphaMask; + GLint rgbBits; /* total bits for rgb */ + GLint indexBits; /* total bits for colorindex */ + + GLint accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits; + GLint depthBits; + GLint stencilBits; + + GLint numAuxBuffers; + + GLint level; + + GLint pixmapMode; + + /* GLX */ + GLint visualID; + GLint visualType; /**< One of the GLX X visual types. (i.e., + * \c GLX_TRUE_COLOR, etc.) + */ + + /* EXT_visual_rating / GLX 1.2 */ + GLint visualRating; + + /* EXT_visual_info / GLX 1.2 */ + GLint transparentPixel; + /* colors are floats scaled to ints */ + GLint transparentRed, transparentGreen, transparentBlue, transparentAlpha; + GLint transparentIndex; + + /* ARB_multisample / SGIS_multisample */ + GLint sampleBuffers; + GLint samples; + + /* SGIX_fbconfig / GLX 1.3 */ + GLint drawableType; + GLint renderType; + GLint xRenderable; + GLint fbconfigID; + + /* SGIX_pbuffer / GLX 1.3 */ + GLint maxPbufferWidth; + GLint maxPbufferHeight; + GLint maxPbufferPixels; + GLint optimalPbufferWidth; /* Only for SGIX_pbuffer. */ + GLint optimalPbufferHeight; /* Only for SGIX_pbuffer. */ + + /* SGIX_visual_select_group */ + GLint visualSelectGroup; + + /* OML_swap_method */ + GLint swapMethod; + + GLint screen; + + /* EXT_texture_from_pixmap */ + GLint bindToTextureRgb; + GLint bindToTextureRgba; + GLint bindToMipmapTexture; + GLint bindToTextureTargets; + GLint yInverted; +} __GLcontextModes; + +/* Several fields of __GLcontextModes can take these as values. Since + * GLX header files may not be available everywhere they need to be used, + * redefine them here. + */ +#define GLX_NONE 0x8000 +#define GLX_SLOW_CONFIG 0x8001 +#define GLX_TRUE_COLOR 0x8002 +#define GLX_DIRECT_COLOR 0x8003 +#define GLX_PSEUDO_COLOR 0x8004 +#define GLX_STATIC_COLOR 0x8005 +#define GLX_GRAY_SCALE 0x8006 +#define GLX_STATIC_GRAY 0x8007 +#define GLX_TRANSPARENT_RGB 0x8008 +#define GLX_TRANSPARENT_INDEX 0x8009 +#define GLX_NON_CONFORMANT_CONFIG 0x800D +#define GLX_SWAP_EXCHANGE_OML 0x8061 +#define GLX_SWAP_COPY_OML 0x8062 +#define GLX_SWAP_UNDEFINED_OML 0x8063 + +#define GLX_DONT_CARE 0xFFFFFFFF + +#define GLX_RGBA_BIT 0x00000001 +#define GLX_COLOR_INDEX_BIT 0x00000002 +#define GLX_WINDOW_BIT 0x00000001 +#define GLX_PIXMAP_BIT 0x00000002 +#define GLX_PBUFFER_BIT 0x00000004 + +#define GLX_BIND_TO_TEXTURE_RGB_EXT 0x20D0 +#define GLX_BIND_TO_TEXTURE_RGBA_EXT 0x20D1 +#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT 0x20D2 +#define GLX_BIND_TO_TEXTURE_TARGETS_EXT 0x20D3 +#define GLX_Y_INVERTED_EXT 0x20D4 + +#define GLX_TEXTURE_1D_BIT_EXT 0x00000001 +#define GLX_TEXTURE_2D_BIT_EXT 0x00000002 +#define GLX_TEXTURE_RECTANGLE_BIT_EXT 0x00000004 + +#endif /* __gl_core_h_ */ diff --git a/src/gallium/state_trackers/egl/x11/glxinit.c b/src/gallium/state_trackers/egl/x11/glxinit.c new file mode 100644 index 0000000..df8370f --- /dev/null +++ b/src/gallium/state_trackers/egl/x11/glxinit.c @@ -0,0 +1,658 @@ +/** + * GLX initialization. Code based on glxext.c, glx_query.c, and + * glcontextmodes.c under src/glx/. The major difference is that DRI + * related code is stripped out. + * + * If the maintenance of this file takes too much time, we should consider + * refactoring glxext.c. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "GL/glxproto.h" +#include "GL/glxtokens.h" +#include "GL/gl.h" /* for GL types needed by __GLcontextModes */ +#include "glcore.h" /* for __GLcontextModes */ + +#include "glxinit.h" + +#ifdef GLX_DIRECT_RENDERING + +typedef struct GLXGenericGetString +{ + CARD8 reqType; + CARD8 glxCode; + CARD16 length B16; + CARD32 for_whom B32; + CARD32 name B32; +} xGLXGenericGetStringReq; + +#define sz_xGLXGenericGetStringReq 12 +#define X_GLXGenericGetString 0 + +/* Extension required boiler plate */ + +static char *__glXExtensionName = GLX_EXTENSION_NAME; +static XExtensionInfo *__glXExtensionInfo = NULL; + +static int +__glXCloseDisplay(Display * dpy, XExtCodes * codes) +{ + return XextRemoveDisplay(__glXExtensionInfo, dpy); +} + +static /* const */ XExtensionHooks __glXExtensionHooks = { + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + __glXCloseDisplay, /* close_display */ + NULL, /* wire_to_event */ + NULL, /* event_to_wire */ + NULL, /* error */ + NULL, /* error_string */ +}; + +static XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay, __glXExtensionInfo, + __glXExtensionName, &__glXExtensionHooks, + __GLX_NUMBER_EVENTS, NULL) + +static GLint +_gl_convert_from_x_visual_type(int visualType) +{ +#define NUM_VISUAL_TYPES 6 + static const int glx_visual_types[NUM_VISUAL_TYPES] = { + GLX_STATIC_GRAY, GLX_GRAY_SCALE, + GLX_STATIC_COLOR, GLX_PSEUDO_COLOR, + GLX_TRUE_COLOR, GLX_DIRECT_COLOR + }; + + return ((unsigned) visualType < NUM_VISUAL_TYPES) + ? glx_visual_types[visualType] : GLX_NONE; +} + +static void +_gl_context_modes_destroy(__GLcontextModes * modes) +{ + while (modes != NULL) { + __GLcontextModes *const next = modes->next; + + Xfree(modes); + modes = next; + } +} + +static __GLcontextModes * +_gl_context_modes_create(unsigned count, size_t minimum_size) +{ + const size_t size = (minimum_size > sizeof(__GLcontextModes)) + ? minimum_size : sizeof(__GLcontextModes); + __GLcontextModes *base = NULL; + __GLcontextModes **next; + unsigned i; + + next = &base; + for (i = 0; i < count; i++) { + *next = (__GLcontextModes *) Xmalloc(size); + if (*next == NULL) { + _gl_context_modes_destroy(base); + base = NULL; + break; + } + + memset(*next, 0, size); + (*next)->visualID = GLX_DONT_CARE; + (*next)->visualType = GLX_DONT_CARE; + (*next)->visualRating = GLX_NONE; + (*next)->transparentPixel = GLX_NONE; + (*next)->transparentRed = GLX_DONT_CARE; + (*next)->transparentGreen = GLX_DONT_CARE; + (*next)->transparentBlue = GLX_DONT_CARE; + (*next)->transparentAlpha = GLX_DONT_CARE; + (*next)->transparentIndex = GLX_DONT_CARE; + (*next)->xRenderable = GLX_DONT_CARE; + (*next)->fbconfigID = GLX_DONT_CARE; + (*next)->swapMethod = GLX_SWAP_UNDEFINED_OML; + (*next)->bindToTextureRgb = GLX_DONT_CARE; + (*next)->bindToTextureRgba = GLX_DONT_CARE; + (*next)->bindToMipmapTexture = GLX_DONT_CARE; + (*next)->bindToTextureTargets = GLX_DONT_CARE; + (*next)->yInverted = GLX_DONT_CARE; + + next = &((*next)->next); + } + + return base; +} + +static char * +__glXQueryServerString(Display * dpy, int opcode, CARD32 screen, CARD32 name) +{ + xGLXGenericGetStringReq *req; + xGLXSingleReply reply; + int length; + int numbytes; + char *buf; + CARD32 for_whom = screen; + CARD32 glxCode = X_GLXQueryServerString; + + + LockDisplay(dpy); + + + /* All of the GLX protocol requests for getting a string from the server + * look the same. The exact meaning of the for_whom field is usually + * either the screen number (for glXQueryServerString) or the context tag + * (for GLXSingle). + */ + + GetReq(GLXGenericGetString, req); + req->reqType = opcode; + req->glxCode = glxCode; + req->for_whom = for_whom; + req->name = name; + + _XReply(dpy, (xReply *) & reply, 0, False); + + length = reply.length * 4; + numbytes = reply.size; + + buf = (char *) Xmalloc(numbytes); + if (buf != NULL) { + _XRead(dpy, buf, numbytes); + length -= numbytes; + } + + _XEatData(dpy, length); + + UnlockDisplay(dpy); + SyncHandle(); + + return buf; +} + +/************************************************************************/ +/* +** Free the per screen configs data as well as the array of +** __glXScreenConfigs. +*/ +static void +FreeScreenConfigs(__GLXdisplayPrivate * priv) +{ + __GLXscreenConfigs *psc; + GLint i, screens; + + /* Free screen configuration information */ + screens = ScreenCount(priv->dpy); + for (i = 0; i < screens; i++) { + psc = priv->screenConfigs[i]; + if (!psc) + continue; + if (psc->configs) { + _gl_context_modes_destroy(psc->configs); + psc->configs = NULL; /* NOTE: just for paranoia */ + } + Xfree((char *) psc->serverGLXexts); + } + XFree((char *) priv->screenConfigs); + priv->screenConfigs = NULL; +} + +/* +** Release the private memory referred to in a display private +** structure. The caller will free the extension structure. +*/ +static int +__glXFreeDisplayPrivate(XExtData * extension) +{ + __GLXdisplayPrivate *priv; + + priv = (__GLXdisplayPrivate *) extension->private_data; + FreeScreenConfigs(priv); + if (priv->serverGLXversion) + Xfree((char *) priv->serverGLXversion); + + Xfree((char *) priv); + return 0; +} + +/************************************************************************/ + +/* +** Query the version of the GLX extension. This procedure works even if +** the client extension is not completely set up. +*/ + +#define GLX_MAJOR_VERSION 1 /* current version numbers */ +#define GLX_MINOR_VERSION 4 + +static Bool +QueryVersion(Display * dpy, int opcode, int *major, int *minor) +{ + xGLXQueryVersionReq *req; + xGLXQueryVersionReply reply; + + /* Send the glXQueryVersion request */ + LockDisplay(dpy); + GetReq(GLXQueryVersion, req); + req->reqType = opcode; + req->glxCode = X_GLXQueryVersion; + req->majorVersion = GLX_MAJOR_VERSION; + req->minorVersion = GLX_MINOR_VERSION; + _XReply(dpy, (xReply *) & reply, 0, False); + UnlockDisplay(dpy); + SyncHandle(); + + if (reply.majorVersion != GLX_MAJOR_VERSION) { + /* + ** The server does not support the same major release as this + ** client. + */ + return GL_FALSE; + } + *major = reply.majorVersion; + *minor = min(reply.minorVersion, GLX_MINOR_VERSION); + return GL_TRUE; +} + +#define __GLX_MIN_CONFIG_PROPS 18 +#define __GLX_MAX_CONFIG_PROPS 500 +#define __GLX_EXT_CONFIG_PROPS 10 +#define __GLX_TOTAL_CONFIG (__GLX_MIN_CONFIG_PROPS + \ + 2 * __GLX_EXT_CONFIG_PROPS) + +static void +__glXInitializeVisualConfigFromTags(__GLcontextModes * config, int count, + const INT32 * bp, Bool tagged_only, + Bool fbconfig_style_tags) +{ + int i; + + if (!tagged_only) { + /* Copy in the first set of properties */ + config->visualID = *bp++; + + config->visualType = _gl_convert_from_x_visual_type(*bp++); + + config->rgbMode = *bp++; + + config->redBits = *bp++; + config->greenBits = *bp++; + config->blueBits = *bp++; + config->alphaBits = *bp++; + config->accumRedBits = *bp++; + config->accumGreenBits = *bp++; + config->accumBlueBits = *bp++; + config->accumAlphaBits = *bp++; + + config->doubleBufferMode = *bp++; + config->stereoMode = *bp++; + + config->rgbBits = *bp++; + config->depthBits = *bp++; + config->stencilBits = *bp++; + config->numAuxBuffers = *bp++; + config->level = *bp++; + + count -= __GLX_MIN_CONFIG_PROPS; + } + + /* + ** Additional properties may be in a list at the end + ** of the reply. They are in pairs of property type + ** and property value. + */ + +#define FETCH_OR_SET(tag) \ + config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1 + + for (i = 0; i < count; i += 2) { + switch (*bp++) { + case GLX_RGBA: + FETCH_OR_SET(rgbMode); + break; + case GLX_BUFFER_SIZE: + config->rgbBits = *bp++; + break; + case GLX_LEVEL: + config->level = *bp++; + break; + case GLX_DOUBLEBUFFER: + FETCH_OR_SET(doubleBufferMode); + break; + case GLX_STEREO: + FETCH_OR_SET(stereoMode); + break; + case GLX_AUX_BUFFERS: + config->numAuxBuffers = *bp++; + break; + case GLX_RED_SIZE: + config->redBits = *bp++; + break; + case GLX_GREEN_SIZE: + config->greenBits = *bp++; + break; + case GLX_BLUE_SIZE: + config->blueBits = *bp++; + break; + case GLX_ALPHA_SIZE: + config->alphaBits = *bp++; + break; + case GLX_DEPTH_SIZE: + config->depthBits = *bp++; + break; + case GLX_STENCIL_SIZE: + config->stencilBits = *bp++; + break; + case GLX_ACCUM_RED_SIZE: + config->accumRedBits = *bp++; + break; + case GLX_ACCUM_GREEN_SIZE: + config->accumGreenBits = *bp++; + break; + case GLX_ACCUM_BLUE_SIZE: + config->accumBlueBits = *bp++; + break; + case GLX_ACCUM_ALPHA_SIZE: + config->accumAlphaBits = *bp++; + break; + case GLX_VISUAL_CAVEAT_EXT: + config->visualRating = *bp++; + break; + case GLX_X_VISUAL_TYPE: + config->visualType = *bp++; + break; + case GLX_TRANSPARENT_TYPE: + config->transparentPixel = *bp++; + break; + case GLX_TRANSPARENT_INDEX_VALUE: + config->transparentIndex = *bp++; + break; + case GLX_TRANSPARENT_RED_VALUE: + config->transparentRed = *bp++; + break; + case GLX_TRANSPARENT_GREEN_VALUE: + config->transparentGreen = *bp++; + break; + case GLX_TRANSPARENT_BLUE_VALUE: + config->transparentBlue = *bp++; + break; + case GLX_TRANSPARENT_ALPHA_VALUE: + config->transparentAlpha = *bp++; + break; + case GLX_VISUAL_ID: + config->visualID = *bp++; + break; + case GLX_DRAWABLE_TYPE: + config->drawableType = *bp++; + break; + case GLX_RENDER_TYPE: + config->renderType = *bp++; + break; + case GLX_X_RENDERABLE: + config->xRenderable = *bp++; + break; + case GLX_FBCONFIG_ID: + config->fbconfigID = *bp++; + break; + case GLX_MAX_PBUFFER_WIDTH: + config->maxPbufferWidth = *bp++; + break; + case GLX_MAX_PBUFFER_HEIGHT: + config->maxPbufferHeight = *bp++; + break; + case GLX_MAX_PBUFFER_PIXELS: + config->maxPbufferPixels = *bp++; + break; + case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX: + config->optimalPbufferWidth = *bp++; + break; + case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX: + config->optimalPbufferHeight = *bp++; + break; + case GLX_VISUAL_SELECT_GROUP_SGIX: + config->visualSelectGroup = *bp++; + break; + case GLX_SWAP_METHOD_OML: + config->swapMethod = *bp++; + break; + case GLX_SAMPLE_BUFFERS_SGIS: + config->sampleBuffers = *bp++; + break; + case GLX_SAMPLES_SGIS: + config->samples = *bp++; + break; + case GLX_BIND_TO_TEXTURE_RGB_EXT: + config->bindToTextureRgb = *bp++; + break; + case GLX_BIND_TO_TEXTURE_RGBA_EXT: + config->bindToTextureRgba = *bp++; + break; + case GLX_BIND_TO_MIPMAP_TEXTURE_EXT: + config->bindToMipmapTexture = *bp++; + break; + case GLX_BIND_TO_TEXTURE_TARGETS_EXT: + config->bindToTextureTargets = *bp++; + break; + case GLX_Y_INVERTED_EXT: + config->yInverted = *bp++; + break; + case None: + i = count; + break; + default: + break; + } + } + + config->renderType = + (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT; + + config->haveAccumBuffer = ((config->accumRedBits + + config->accumGreenBits + + config->accumBlueBits + + config->accumAlphaBits) > 0); + config->haveDepthBuffer = (config->depthBits > 0); + config->haveStencilBuffer = (config->stencilBits > 0); +} + +static __GLcontextModes * +createConfigsFromProperties(Display * dpy, int nvisuals, int nprops, + int screen, GLboolean tagged_only) +{ + INT32 buf[__GLX_TOTAL_CONFIG], *props; + unsigned prop_size; + __GLcontextModes *modes, *m; + int i; + + if (nprops == 0) + return NULL; + + /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */ + + /* Check number of properties */ + if (nprops < __GLX_MIN_CONFIG_PROPS || nprops > __GLX_MAX_CONFIG_PROPS) + return NULL; + + /* Allocate memory for our config structure */ + modes = _gl_context_modes_create(nvisuals, sizeof(__GLcontextModes)); + if (!modes) + return NULL; + + prop_size = nprops * __GLX_SIZE_INT32; + if (prop_size <= sizeof(buf)) + props = buf; + else + props = Xmalloc(prop_size); + + /* Read each config structure and convert it into our format */ + m = modes; + for (i = 0; i < nvisuals; i++) { + _XRead(dpy, (char *) props, prop_size); + /* Older X servers don't send this so we default it here. */ + m->drawableType = GLX_WINDOW_BIT; + __glXInitializeVisualConfigFromTags(m, nprops, props, + tagged_only, GL_TRUE); + m->screen = screen; + m = m->next; + } + + if (props != buf) + Xfree(props); + + return modes; +} + +static GLboolean +getFBConfigs(__GLXscreenConfigs *psc, __GLXdisplayPrivate *priv, int screen) +{ + xGLXGetFBConfigsReq *fb_req; + xGLXGetFBConfigsSGIXReq *sgi_req; + xGLXVendorPrivateWithReplyReq *vpreq; + xGLXGetFBConfigsReply reply; + Display *dpy = priv->dpy; + + psc->serverGLXexts = + __glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS); + + LockDisplay(dpy); + + psc->configs = NULL; + if (atof(priv->serverGLXversion) >= 1.3) { + GetReq(GLXGetFBConfigs, fb_req); + fb_req->reqType = priv->majorOpcode; + fb_req->glxCode = X_GLXGetFBConfigs; + fb_req->screen = screen; + } + else if (strstr(psc->serverGLXexts, "GLX_SGIX_fbconfig") != NULL) { + GetReqExtra(GLXVendorPrivateWithReply, + sz_xGLXGetFBConfigsSGIXReq + + sz_xGLXVendorPrivateWithReplyReq, vpreq); + sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq; + sgi_req->reqType = priv->majorOpcode; + sgi_req->glxCode = X_GLXVendorPrivateWithReply; + sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX; + sgi_req->screen = screen; + } + else + goto out; + + if (!_XReply(dpy, (xReply *) & reply, 0, False)) + goto out; + + psc->configs = createConfigsFromProperties(dpy, + reply.numFBConfigs, + reply.numAttribs * 2, + screen, GL_TRUE); + + out: + UnlockDisplay(dpy); + return psc->configs != NULL; +} + +static GLboolean +AllocAndFetchScreenConfigs(Display * dpy, __GLXdisplayPrivate * priv) +{ + __GLXscreenConfigs *psc; + GLint i, screens; + + /* + ** First allocate memory for the array of per screen configs. + */ + screens = ScreenCount(dpy); + priv->screenConfigs = Xmalloc(screens * sizeof *priv->screenConfigs); + if (!priv->screenConfigs) { + return GL_FALSE; + } + + priv->serverGLXversion = + __glXQueryServerString(dpy, priv->majorOpcode, 0, GLX_VERSION); + if (priv->serverGLXversion == NULL) { + FreeScreenConfigs(priv); + return GL_FALSE; + } + + for (i = 0; i < screens; i++) { + psc = Xcalloc(1, sizeof *psc); + if (!psc) + return GL_FALSE; + getFBConfigs(psc, priv, i); + priv->screenConfigs[i] = psc; + } + + SyncHandle(); + + return GL_TRUE; +} + +_X_HIDDEN __GLXdisplayPrivate * +__glXInitialize(Display * dpy) +{ + XExtDisplayInfo *info = __glXFindDisplay(dpy); + XExtData **privList, *private, *found; + __GLXdisplayPrivate *dpyPriv; + XEDataObject dataObj; + int major, minor; + + if (!XextHasExtension(info)) + return NULL; + + /* See if a display private already exists. If so, return it */ + dataObj.display = dpy; + privList = XEHeadOfExtensionList(dataObj); + found = XFindOnExtensionList(privList, info->codes->extension); + if (found) + return (__GLXdisplayPrivate *) found->private_data; + + /* See if the versions are compatible */ + if (!QueryVersion(dpy, info->codes->major_opcode, &major, &minor)) + return NULL; + + /* + ** Allocate memory for all the pieces needed for this buffer. + */ + private = (XExtData *) Xmalloc(sizeof(XExtData)); + if (!private) + return NULL; + dpyPriv = (__GLXdisplayPrivate *) Xcalloc(1, sizeof(__GLXdisplayPrivate)); + if (!dpyPriv) { + Xfree(private); + return NULL; + } + + /* + ** Init the display private and then read in the screen config + ** structures from the server. + */ + dpyPriv->majorOpcode = info->codes->major_opcode; + dpyPriv->dpy = dpy; + + if (!AllocAndFetchScreenConfigs(dpy, dpyPriv)) { + Xfree(dpyPriv); + Xfree(private); + return NULL; + } + + /* + ** Fill in the private structure. This is the actual structure that + ** hangs off of the Display structure. Our private structure is + ** referred to by this structure. Got that? + */ + private->number = info->codes->extension; + private->next = 0; + private->free_private = __glXFreeDisplayPrivate; + private->private_data = (char *) dpyPriv; + XAddToExtensionList(privList, private); + + return dpyPriv; +} + +#endif /* GLX_DIRECT_RENDERING */ diff --git a/src/gallium/state_trackers/egl/x11/glxinit.h b/src/gallium/state_trackers/egl/x11/glxinit.h new file mode 100644 index 0000000..4078aef --- /dev/null +++ b/src/gallium/state_trackers/egl/x11/glxinit.h @@ -0,0 +1,22 @@ +#ifndef GLXINIT_INCLUDED +#define GLXINIT_INCLUDED + +#include +#include + +typedef struct { + __GLcontextModes *configs; + char *serverGLXexts; +} __GLXscreenConfigs; + +typedef struct { + Display *dpy; + __GLXscreenConfigs **screenConfigs; + char *serverGLXversion; + int majorOpcode; + struct x11_screen *xscr; +} __GLXdisplayPrivate; + +extern __GLXdisplayPrivate *__glXInitialize(Display * dpy); + +#endif /* GLXINIT_INCLUDED */ diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c new file mode 100644 index 0000000..0d19163 --- /dev/null +++ b/src/gallium/state_trackers/egl/x11/native_dri2.c @@ -0,0 +1,859 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2009-2010 Chia-I Wu + * + * 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 "util/u_math.h" +#include "util/u_format.h" +#include "util/u_inlines.h" +#include "util/u_hash_table.h" +#include "pipe/p_compiler.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "state_tracker/drm_driver.h" +#include "egllog.h" + +#include "native_x11.h" +#include "x11_screen.h" + +#ifdef GLX_DIRECT_RENDERING + +enum dri2_surface_type { + DRI2_SURFACE_TYPE_WINDOW, + DRI2_SURFACE_TYPE_PIXMAP, +}; + +struct dri2_display { + struct native_display base; + Display *dpy; + boolean own_dpy; + + struct native_event_handler *event_handler; + + struct x11_screen *xscr; + int xscr_number; + const char *dri_driver; + int dri_major, dri_minor; + + struct dri2_config *configs; + int num_configs; + + struct util_hash_table *surfaces; +}; + +struct dri2_surface { + struct native_surface base; + Drawable drawable; + enum dri2_surface_type type; + enum pipe_format color_format; + struct dri2_display *dri2dpy; + + unsigned int server_stamp; + unsigned int client_stamp; + int width, height; + struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS]; + uint valid_mask; + + boolean have_back, have_fake; + + struct x11_drawable_buffer *last_xbufs; + int last_num_xbufs; +}; + +struct dri2_config { + struct native_config base; +}; + +static INLINE struct dri2_display * +dri2_display(const struct native_display *ndpy) +{ + return (struct dri2_display *) ndpy; +} + +static INLINE struct dri2_surface * +dri2_surface(const struct native_surface *nsurf) +{ + return (struct dri2_surface *) nsurf; +} + +static INLINE struct dri2_config * +dri2_config(const struct native_config *nconf) +{ + return (struct dri2_config *) nconf; +} + +/** + * Process the buffers returned by the server. + */ +static void +dri2_surface_process_drawable_buffers(struct native_surface *nsurf, + struct x11_drawable_buffer *xbufs, + int num_xbufs) +{ + struct dri2_surface *dri2surf = dri2_surface(nsurf); + struct dri2_display *dri2dpy = dri2surf->dri2dpy; + struct pipe_resource templ; + struct winsys_handle whandle; + uint valid_mask; + int i; + + /* free the old textures */ + for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) + pipe_resource_reference(&dri2surf->textures[i], NULL); + dri2surf->valid_mask = 0x0; + + dri2surf->have_back = FALSE; + dri2surf->have_fake = FALSE; + + if (!xbufs) + return; + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.last_level = 0; + templ.width0 = dri2surf->width; + templ.height0 = dri2surf->height; + templ.depth0 = 1; + templ.array_size = 1; + templ.format = dri2surf->color_format; + templ.bind = PIPE_BIND_RENDER_TARGET; + + valid_mask = 0x0; + for (i = 0; i < num_xbufs; i++) { + struct x11_drawable_buffer *xbuf = &xbufs[i]; + const char *desc; + enum native_attachment natt; + + switch (xbuf->attachment) { + case DRI2BufferFrontLeft: + natt = NATIVE_ATTACHMENT_FRONT_LEFT; + desc = "DRI2 Front Buffer"; + break; + case DRI2BufferFakeFrontLeft: + natt = NATIVE_ATTACHMENT_FRONT_LEFT; + desc = "DRI2 Fake Front Buffer"; + dri2surf->have_fake = TRUE; + break; + case DRI2BufferBackLeft: + natt = NATIVE_ATTACHMENT_BACK_LEFT; + desc = "DRI2 Back Buffer"; + dri2surf->have_back = TRUE; + break; + default: + desc = NULL; + break; + } + + if (!desc || dri2surf->textures[natt]) { + if (!desc) + _eglLog(_EGL_WARNING, "unknown buffer %d", xbuf->attachment); + else + _eglLog(_EGL_WARNING, "both real and fake front buffers are listed"); + continue; + } + + memset(&whandle, 0, sizeof(whandle)); + whandle.stride = xbuf->pitch; + whandle.handle = xbuf->name; + dri2surf->textures[natt] = dri2dpy->base.screen->resource_from_handle( + dri2dpy->base.screen, &templ, &whandle); + if (dri2surf->textures[natt]) + valid_mask |= 1 << natt; + } + + dri2surf->valid_mask = valid_mask; +} + +/** + * Get the buffers from the server. + */ +static void +dri2_surface_get_buffers(struct native_surface *nsurf, uint buffer_mask) +{ + struct dri2_surface *dri2surf = dri2_surface(nsurf); + struct dri2_display *dri2dpy = dri2surf->dri2dpy; + unsigned int dri2atts[NUM_NATIVE_ATTACHMENTS * 2]; + int num_ins, num_outs, att; + struct x11_drawable_buffer *xbufs; + uint bpp = util_format_get_blocksizebits(dri2surf->color_format); + boolean with_format = FALSE; /* never ask for depth/stencil */ + + /* We must get the front on servers which doesn't support with format + * due to a silly bug in core dri2. You can't copy to/from a buffer + * that you haven't requested and you recive BadValue errors */ + if (dri2surf->dri2dpy->dri_minor < 1) { + with_format = FALSE; + buffer_mask |= (1 << NATIVE_ATTACHMENT_FRONT_LEFT); + } + + /* prepare the attachments */ + num_ins = 0; + for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) { + if (native_attachment_mask_test(buffer_mask, att)) { + unsigned int dri2att; + + switch (att) { + case NATIVE_ATTACHMENT_FRONT_LEFT: + dri2att = DRI2BufferFrontLeft; + break; + case NATIVE_ATTACHMENT_BACK_LEFT: + dri2att = DRI2BufferBackLeft; + break; + case NATIVE_ATTACHMENT_FRONT_RIGHT: + dri2att = DRI2BufferFrontRight; + break; + case NATIVE_ATTACHMENT_BACK_RIGHT: + dri2att = DRI2BufferBackRight; + break; + default: + assert(0); + dri2att = 0; + break; + } + + dri2atts[num_ins++] = dri2att; + if (with_format) + dri2atts[num_ins++] = bpp; + } + } + if (with_format) + num_ins /= 2; + + xbufs = x11_drawable_get_buffers(dri2dpy->xscr, dri2surf->drawable, + &dri2surf->width, &dri2surf->height, + dri2atts, with_format, num_ins, &num_outs); + + /* we should be able to do better... */ + if (xbufs && dri2surf->last_num_xbufs == num_outs && + memcmp(dri2surf->last_xbufs, xbufs, sizeof(*xbufs) * num_outs) == 0) { + FREE(xbufs); + dri2surf->client_stamp = dri2surf->server_stamp; + return; + } + + dri2_surface_process_drawable_buffers(&dri2surf->base, xbufs, num_outs); + + dri2surf->server_stamp++; + dri2surf->client_stamp = dri2surf->server_stamp; + + if (dri2surf->last_xbufs) + FREE(dri2surf->last_xbufs); + dri2surf->last_xbufs = xbufs; + dri2surf->last_num_xbufs = num_outs; +} + +/** + * Update the buffers of the surface. This is a slow function due to the + * round-trip to the server. + */ +static boolean +dri2_surface_update_buffers(struct native_surface *nsurf, uint buffer_mask) +{ + struct dri2_surface *dri2surf = dri2_surface(nsurf); + + dri2_surface_get_buffers(&dri2surf->base, buffer_mask); + + return ((dri2surf->valid_mask & buffer_mask) == buffer_mask); +} + +/** + * Return TRUE if the surface receives DRI2_InvalidateBuffers events. + */ +static INLINE boolean +dri2_surface_receive_events(struct native_surface *nsurf) +{ + struct dri2_surface *dri2surf = dri2_surface(nsurf); + return (dri2surf->dri2dpy->dri_minor >= 3); +} + +static boolean +dri2_surface_flush_frontbuffer(struct native_surface *nsurf) +{ + struct dri2_surface *dri2surf = dri2_surface(nsurf); + struct dri2_display *dri2dpy = dri2surf->dri2dpy; + + /* copy to real front buffer */ + if (dri2surf->have_fake) + x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable, + 0, 0, dri2surf->width, dri2surf->height, + DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft); + + /* force buffers to be updated in next validation call */ + if (!dri2_surface_receive_events(&dri2surf->base)) { + dri2surf->server_stamp++; + dri2dpy->event_handler->invalid_surface(&dri2dpy->base, + &dri2surf->base, dri2surf->server_stamp); + } + + return TRUE; +} + +static boolean +dri2_surface_swap_buffers(struct native_surface *nsurf) +{ + struct dri2_surface *dri2surf = dri2_surface(nsurf); + struct dri2_display *dri2dpy = dri2surf->dri2dpy; + + /* copy to front buffer */ + if (dri2surf->have_back) + x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable, + 0, 0, dri2surf->width, dri2surf->height, + DRI2BufferBackLeft, DRI2BufferFrontLeft); + + /* and update fake front buffer */ + if (dri2surf->have_fake) + x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable, + 0, 0, dri2surf->width, dri2surf->height, + DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft); + + /* force buffers to be updated in next validation call */ + if (!dri2_surface_receive_events(&dri2surf->base)) { + dri2surf->server_stamp++; + dri2dpy->event_handler->invalid_surface(&dri2dpy->base, + &dri2surf->base, dri2surf->server_stamp); + } + + return TRUE; +} + +static boolean +dri2_surface_present(struct native_surface *nsurf, + enum native_attachment natt, + boolean preserve, + uint swap_interval) +{ + boolean ret; + + if (swap_interval) + return FALSE; + + switch (natt) { + case NATIVE_ATTACHMENT_FRONT_LEFT: + ret = dri2_surface_flush_frontbuffer(nsurf); + break; + case NATIVE_ATTACHMENT_BACK_LEFT: + ret = dri2_surface_swap_buffers(nsurf); + break; + default: + ret = FALSE; + break; + } + + return ret; +} + +static boolean +dri2_surface_validate(struct native_surface *nsurf, uint attachment_mask, + unsigned int *seq_num, struct pipe_resource **textures, + int *width, int *height) +{ + struct dri2_surface *dri2surf = dri2_surface(nsurf); + + if (dri2surf->server_stamp != dri2surf->client_stamp || + (dri2surf->valid_mask & attachment_mask) != attachment_mask) { + if (!dri2_surface_update_buffers(&dri2surf->base, attachment_mask)) + return FALSE; + } + + if (seq_num) + *seq_num = dri2surf->client_stamp; + + if (textures) { + int att; + for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) { + if (native_attachment_mask_test(attachment_mask, att)) { + struct pipe_resource *ptex = dri2surf->textures[att]; + + textures[att] = NULL; + pipe_resource_reference(&textures[att], ptex); + } + } + } + + if (width) + *width = dri2surf->width; + if (height) + *height = dri2surf->height; + + return TRUE; +} + +static void +dri2_surface_wait(struct native_surface *nsurf) +{ + struct dri2_surface *dri2surf = dri2_surface(nsurf); + struct dri2_display *dri2dpy = dri2surf->dri2dpy; + + if (dri2surf->have_fake) { + x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable, + 0, 0, dri2surf->width, dri2surf->height, + DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft); + } +} + +static void +dri2_surface_destroy(struct native_surface *nsurf) +{ + struct dri2_surface *dri2surf = dri2_surface(nsurf); + int i; + + if (dri2surf->last_xbufs) + FREE(dri2surf->last_xbufs); + + for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) { + struct pipe_resource *ptex = dri2surf->textures[i]; + pipe_resource_reference(&ptex, NULL); + } + + if (dri2surf->drawable) { + x11_drawable_enable_dri2(dri2surf->dri2dpy->xscr, + dri2surf->drawable, FALSE); + + util_hash_table_remove(dri2surf->dri2dpy->surfaces, + (void *) dri2surf->drawable); + } + FREE(dri2surf); +} + +static struct dri2_surface * +dri2_display_create_surface(struct native_display *ndpy, + enum dri2_surface_type type, + Drawable drawable, + const struct native_config *nconf) +{ + struct dri2_display *dri2dpy = dri2_display(ndpy); + struct dri2_config *dri2conf = dri2_config(nconf); + struct dri2_surface *dri2surf; + + dri2surf = CALLOC_STRUCT(dri2_surface); + if (!dri2surf) + return NULL; + + dri2surf->dri2dpy = dri2dpy; + dri2surf->type = type; + dri2surf->drawable = drawable; + dri2surf->color_format = dri2conf->base.color_format; + + dri2surf->base.destroy = dri2_surface_destroy; + dri2surf->base.present = dri2_surface_present; + dri2surf->base.validate = dri2_surface_validate; + dri2surf->base.wait = dri2_surface_wait; + + if (drawable) { + x11_drawable_enable_dri2(dri2dpy->xscr, drawable, TRUE); + /* initialize the geometry */ + dri2_surface_update_buffers(&dri2surf->base, 0x0); + + util_hash_table_set(dri2surf->dri2dpy->surfaces, + (void *) dri2surf->drawable, (void *) &dri2surf->base); + } + + return dri2surf; +} + +static struct native_surface * +dri2_display_create_window_surface(struct native_display *ndpy, + EGLNativeWindowType win, + const struct native_config *nconf) +{ + struct dri2_surface *dri2surf; + + dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_WINDOW, + (Drawable) win, nconf); + return (dri2surf) ? &dri2surf->base : NULL; +} + +static struct native_surface * +dri2_display_create_pixmap_surface(struct native_display *ndpy, + EGLNativePixmapType pix, + const struct native_config *nconf) +{ + struct dri2_surface *dri2surf; + + dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_PIXMAP, + (Drawable) pix, nconf); + return (dri2surf) ? &dri2surf->base : NULL; +} + +static int +choose_color_format(const __GLcontextModes *mode, enum pipe_format formats[32]) +{ + int count = 0; + + switch (mode->rgbBits) { + case 32: + formats[count++] = PIPE_FORMAT_B8G8R8A8_UNORM; + formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM; + break; + case 24: + formats[count++] = PIPE_FORMAT_B8G8R8X8_UNORM; + formats[count++] = PIPE_FORMAT_X8R8G8B8_UNORM; + formats[count++] = PIPE_FORMAT_B8G8R8A8_UNORM; + formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM; + break; + case 16: + formats[count++] = PIPE_FORMAT_B5G6R5_UNORM; + break; + default: + break; + } + + return count; +} + +static boolean +is_format_supported(struct pipe_screen *screen, + enum pipe_format fmt, unsigned sample_count, boolean is_color) +{ + return screen->is_format_supported(screen, fmt, PIPE_TEXTURE_2D, sample_count, + (is_color) ? PIPE_BIND_RENDER_TARGET : + PIPE_BIND_DEPTH_STENCIL, 0); +} + +static boolean +dri2_display_convert_config(struct native_display *ndpy, + const __GLcontextModes *mode, + struct native_config *nconf) +{ + enum pipe_format formats[32]; + int num_formats, i; + int sample_count = 0; + + if (!(mode->renderType & GLX_RGBA_BIT) || !mode->rgbMode) + return FALSE; + + /* only interested in native renderable configs */ + if (!mode->xRenderable || !mode->drawableType) + return FALSE; + + /* fast/slow configs are probably not relevant */ + if (mode->visualRating == GLX_SLOW_CONFIG) + return FALSE; + + nconf->buffer_mask = 1 << NATIVE_ATTACHMENT_FRONT_LEFT; + if (mode->doubleBufferMode) + nconf->buffer_mask |= 1 << NATIVE_ATTACHMENT_BACK_LEFT; + if (mode->stereoMode) { + nconf->buffer_mask |= 1 << NATIVE_ATTACHMENT_FRONT_RIGHT; + if (mode->doubleBufferMode) + nconf->buffer_mask |= 1 << NATIVE_ATTACHMENT_BACK_RIGHT; + } + + /* choose color format */ + num_formats = choose_color_format(mode, formats); + for (i = 0; i < num_formats; i++) { + if (is_format_supported(ndpy->screen, formats[i], sample_count, TRUE)) { + nconf->color_format = formats[i]; + break; + } + } + if (nconf->color_format == PIPE_FORMAT_NONE) + return FALSE; + + if ((mode->drawableType & GLX_WINDOW_BIT) && mode->visualID) + nconf->window_bit = TRUE; + if (mode->drawableType & GLX_PIXMAP_BIT) + nconf->pixmap_bit = TRUE; + + nconf->native_visual_id = mode->visualID; + switch (mode->visualType) { + case GLX_TRUE_COLOR: + nconf->native_visual_type = TrueColor; + break; + case GLX_DIRECT_COLOR: + nconf->native_visual_type = DirectColor; + break; + case GLX_PSEUDO_COLOR: + nconf->native_visual_type = PseudoColor; + break; + case GLX_STATIC_COLOR: + nconf->native_visual_type = StaticColor; + break; + case GLX_GRAY_SCALE: + nconf->native_visual_type = GrayScale; + break; + case GLX_STATIC_GRAY: + nconf->native_visual_type = StaticGray; + break; + } + nconf->level = mode->level; + nconf->samples = mode->samples; + + nconf->slow_config = (mode->visualRating == GLX_SLOW_CONFIG); + + if (mode->transparentPixel == GLX_TRANSPARENT_RGB) { + nconf->transparent_rgb = TRUE; + nconf->transparent_rgb_values[0] = mode->transparentRed; + nconf->transparent_rgb_values[1] = mode->transparentGreen; + nconf->transparent_rgb_values[2] = mode->transparentBlue; + } + + return TRUE; +} + +static const struct native_config ** +dri2_display_get_configs(struct native_display *ndpy, int *num_configs) +{ + struct dri2_display *dri2dpy = dri2_display(ndpy); + const struct native_config **configs; + int i; + + /* first time */ + if (!dri2dpy->configs) { + const __GLcontextModes *modes; + int num_modes, count; + + modes = x11_screen_get_glx_configs(dri2dpy->xscr); + if (!modes) + return NULL; + num_modes = x11_context_modes_count(modes); + + dri2dpy->configs = CALLOC(num_modes, sizeof(*dri2dpy->configs)); + if (!dri2dpy->configs) + return NULL; + + count = 0; + for (i = 0; i < num_modes; i++) { + struct native_config *nconf = &dri2dpy->configs[count].base; + + if (dri2_display_convert_config(&dri2dpy->base, modes, nconf)) { + int j; + /* look for duplicates */ + for (j = 0; j < count; j++) { + if (memcmp(&dri2dpy->configs[j], nconf, sizeof(*nconf)) == 0) + break; + } + if (j == count) + count++; + } + modes = modes->next; + } + + dri2dpy->num_configs = count; + } + + configs = MALLOC(dri2dpy->num_configs * sizeof(*configs)); + if (configs) { + for (i = 0; i < dri2dpy->num_configs; i++) + configs[i] = (const struct native_config *) &dri2dpy->configs[i]; + if (num_configs) + *num_configs = dri2dpy->num_configs; + } + + return configs; +} + +static boolean +dri2_display_is_pixmap_supported(struct native_display *ndpy, + EGLNativePixmapType pix, + const struct native_config *nconf) +{ + struct dri2_display *dri2dpy = dri2_display(ndpy); + uint depth, nconf_depth; + + depth = x11_drawable_get_depth(dri2dpy->xscr, (Drawable) pix); + nconf_depth = util_format_get_blocksizebits(nconf->color_format); + + /* simple depth match for now */ + return (depth == nconf_depth || (depth == 24 && depth + 8 == nconf_depth)); +} + +static int +dri2_display_get_param(struct native_display *ndpy, + enum native_param_type param) +{ + int val; + + switch (param) { + case NATIVE_PARAM_USE_NATIVE_BUFFER: + /* DRI2GetBuffers uses the native buffers */ + val = TRUE; + break; + case NATIVE_PARAM_PRESERVE_BUFFER: + /* DRI2CopyRegion is used */ + val = TRUE; + break; + case NATIVE_PARAM_MAX_SWAP_INTERVAL: + default: + val = 0; + break; + } + + return val; +} + +static void +dri2_display_destroy(struct native_display *ndpy) +{ + struct dri2_display *dri2dpy = dri2_display(ndpy); + + if (dri2dpy->configs) + FREE(dri2dpy->configs); + + if (dri2dpy->base.screen) + dri2dpy->base.screen->destroy(dri2dpy->base.screen); + + if (dri2dpy->surfaces) + util_hash_table_destroy(dri2dpy->surfaces); + + if (dri2dpy->xscr) + x11_screen_destroy(dri2dpy->xscr); + if (dri2dpy->own_dpy) + XCloseDisplay(dri2dpy->dpy); + FREE(dri2dpy); +} + +static void +dri2_display_invalidate_buffers(struct x11_screen *xscr, Drawable drawable, + void *user_data) +{ + struct native_display *ndpy = (struct native_display* ) user_data; + struct dri2_display *dri2dpy = dri2_display(ndpy); + struct native_surface *nsurf; + struct dri2_surface *dri2surf; + + nsurf = (struct native_surface *) + util_hash_table_get(dri2dpy->surfaces, (void *) drawable); + if (!nsurf) + return; + + dri2surf = dri2_surface(nsurf); + + dri2surf->server_stamp++; + dri2dpy->event_handler->invalid_surface(&dri2dpy->base, + &dri2surf->base, dri2surf->server_stamp); +} + +/** + * Initialize DRI2 and pipe screen. + */ +static boolean +dri2_display_init_screen(struct native_display *ndpy) +{ + struct dri2_display *dri2dpy = dri2_display(ndpy); + int fd; + + if (!x11_screen_support(dri2dpy->xscr, X11_SCREEN_EXTENSION_DRI2) || + !x11_screen_support(dri2dpy->xscr, X11_SCREEN_EXTENSION_GLX)) { + _eglLog(_EGL_WARNING, "GLX/DRI2 is not supported"); + return FALSE; + } + + dri2dpy->dri_driver = x11_screen_probe_dri2(dri2dpy->xscr, + &dri2dpy->dri_major, &dri2dpy->dri_minor); + + fd = x11_screen_enable_dri2(dri2dpy->xscr, + dri2_display_invalidate_buffers, &dri2dpy->base); + if (fd < 0) + return FALSE; + + dri2dpy->base.screen = + dri2dpy->event_handler->new_drm_screen(&dri2dpy->base, + dri2dpy->dri_driver, fd); + if (!dri2dpy->base.screen) { + _eglLog(_EGL_WARNING, "failed to create DRM screen"); + return FALSE; + } + + return TRUE; +} + +static unsigned +dri2_display_hash_table_hash(void *key) +{ + XID drawable = pointer_to_uintptr(key); + return (unsigned) drawable; +} + +static int +dri2_display_hash_table_compare(void *key1, void *key2) +{ + return (key1 - key2); +} + +struct native_display * +x11_create_dri2_display(Display *dpy, + struct native_event_handler *event_handler, + void *user_data) +{ + struct dri2_display *dri2dpy; + + dri2dpy = CALLOC_STRUCT(dri2_display); + if (!dri2dpy) + return NULL; + + dri2dpy->event_handler = event_handler; + dri2dpy->base.user_data = user_data; + + dri2dpy->dpy = dpy; + if (!dri2dpy->dpy) { + dri2dpy->dpy = XOpenDisplay(NULL); + if (!dri2dpy->dpy) { + dri2_display_destroy(&dri2dpy->base); + return NULL; + } + dri2dpy->own_dpy = TRUE; + } + + dri2dpy->xscr_number = DefaultScreen(dri2dpy->dpy); + dri2dpy->xscr = x11_screen_create(dri2dpy->dpy, dri2dpy->xscr_number); + if (!dri2dpy->xscr) { + dri2_display_destroy(&dri2dpy->base); + return NULL; + } + + if (!dri2_display_init_screen(&dri2dpy->base)) { + dri2_display_destroy(&dri2dpy->base); + return NULL; + } + + dri2dpy->surfaces = util_hash_table_create(dri2_display_hash_table_hash, + dri2_display_hash_table_compare); + if (!dri2dpy->surfaces) { + dri2_display_destroy(&dri2dpy->base); + return NULL; + } + + dri2dpy->base.destroy = dri2_display_destroy; + dri2dpy->base.get_param = dri2_display_get_param; + dri2dpy->base.get_configs = dri2_display_get_configs; + dri2dpy->base.is_pixmap_supported = dri2_display_is_pixmap_supported; + dri2dpy->base.create_window_surface = dri2_display_create_window_surface; + dri2dpy->base.create_pixmap_surface = dri2_display_create_pixmap_surface; + + return &dri2dpy->base; +} + +#else /* GLX_DIRECT_RENDERING */ + +struct native_display * +x11_create_dri2_display(Display *dpy, + struct native_event_handler *event_handler, + void *user_data) +{ + return NULL; +} + +#endif /* GLX_DIRECT_RENDERING */ diff --git a/src/gallium/state_trackers/egl/x11/native_x11.c b/src/gallium/state_trackers/egl/x11/native_x11.c new file mode 100644 index 0000000..37c8b01 --- /dev/null +++ b/src/gallium/state_trackers/egl/x11/native_x11.c @@ -0,0 +1,66 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2009-2010 Chia-I Wu + * + * 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_debug.h" +#include "util/u_memory.h" +#include "util/u_string.h" +#include "egllog.h" + +#include "native_x11.h" + +static struct native_display * +native_create_display(void *dpy, struct native_event_handler *event_handler, + void *user_data) +{ + struct native_display *ndpy = NULL; + boolean force_sw; + + force_sw = debug_get_bool_option("EGL_SOFTWARE", FALSE); + if (!force_sw) { + ndpy = x11_create_dri2_display((Display *) dpy, + event_handler, user_data); + } + + if (!ndpy) { + EGLint level = (force_sw) ? _EGL_INFO : _EGL_WARNING; + + _eglLog(level, "use software fallback"); + ndpy = x11_create_ximage_display((Display *) dpy, + event_handler, user_data); + } + + return ndpy; +} + +static const struct native_platform x11_platform = { + "X11", /* name */ + native_create_display +}; + +const struct native_platform * +native_get_x11_platform(void) +{ + return &x11_platform; +} diff --git a/src/gallium/state_trackers/egl/x11/native_x11.h b/src/gallium/state_trackers/egl/x11/native_x11.h new file mode 100644 index 0000000..8945117 --- /dev/null +++ b/src/gallium/state_trackers/egl/x11/native_x11.h @@ -0,0 +1,42 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2009-2010 Chia-I Wu + * + * 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 _NATIVE_X11_H_ +#define _NATIVE_X11_H_ + +#include "common/native.h" +#include + +struct native_display * +x11_create_ximage_display(Display *dpy, + struct native_event_handler *event_handler, + void *user_data); + +struct native_display * +x11_create_dri2_display(Display *dpy, + struct native_event_handler *event_handler, + void *user_data); + +#endif /* _NATIVE_X11_H_ */ diff --git a/src/gallium/state_trackers/egl/x11/native_ximage.c b/src/gallium/state_trackers/egl/x11/native_ximage.c new file mode 100644 index 0000000..84811fb --- /dev/null +++ b/src/gallium/state_trackers/egl/x11/native_ximage.c @@ -0,0 +1,528 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2009-2010 Chia-I Wu + * + * 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 +#include +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_format.h" +#include "pipe/p_compiler.h" +#include "util/u_inlines.h" +#include "state_tracker/xlib_sw_winsys.h" +#include "util/u_debug.h" +#include "egllog.h" + +#include "common/native_helper.h" +#include "native_x11.h" +#include "x11_screen.h" + +enum ximage_surface_type { + XIMAGE_SURFACE_TYPE_WINDOW, + XIMAGE_SURFACE_TYPE_PIXMAP, +}; + +struct ximage_display { + struct native_display base; + Display *dpy; + boolean own_dpy; + + struct native_event_handler *event_handler; + + struct x11_screen *xscr; + int xscr_number; + + struct ximage_config *configs; + int num_configs; +}; + +struct ximage_surface { + struct native_surface base; + Drawable drawable; + enum ximage_surface_type type; + enum pipe_format color_format; + XVisualInfo visual; + struct ximage_display *xdpy; + + unsigned int server_stamp; + unsigned int client_stamp; + + struct resource_surface *rsurf; + struct xlib_drawable xdraw; +}; + +struct ximage_config { + struct native_config base; + const XVisualInfo *visual; +}; + +static INLINE struct ximage_display * +ximage_display(const struct native_display *ndpy) +{ + return (struct ximage_display *) ndpy; +} + +static INLINE struct ximage_surface * +ximage_surface(const struct native_surface *nsurf) +{ + return (struct ximage_surface *) nsurf; +} + +static INLINE struct ximage_config * +ximage_config(const struct native_config *nconf) +{ + return (struct ximage_config *) nconf; +} + +/** + * Update the geometry of the surface. This is a slow functions. + */ +static void +ximage_surface_update_geometry(struct native_surface *nsurf) +{ + struct ximage_surface *xsurf = ximage_surface(nsurf); + Status ok; + Window root; + int x, y; + unsigned int w, h, border, depth; + + ok = XGetGeometry(xsurf->xdpy->dpy, xsurf->drawable, + &root, &x, &y, &w, &h, &border, &depth); + if (ok && resource_surface_set_size(xsurf->rsurf, w, h)) + xsurf->server_stamp++; +} + +/** + * Update the buffers of the surface. + */ +static boolean +ximage_surface_update_buffers(struct native_surface *nsurf, uint buffer_mask) +{ + struct ximage_surface *xsurf = ximage_surface(nsurf); + + if (xsurf->client_stamp != xsurf->server_stamp) { + ximage_surface_update_geometry(&xsurf->base); + xsurf->client_stamp = xsurf->server_stamp; + } + + return resource_surface_add_resources(xsurf->rsurf, buffer_mask); +} + +/** + * Emulate an invalidate event. + */ +static void +ximage_surface_invalidate(struct native_surface *nsurf) +{ + struct ximage_surface *xsurf = ximage_surface(nsurf); + struct ximage_display *xdpy = xsurf->xdpy; + + xsurf->server_stamp++; + xdpy->event_handler->invalid_surface(&xdpy->base, + &xsurf->base, xsurf->server_stamp); +} + +static boolean +ximage_surface_flush_frontbuffer(struct native_surface *nsurf) +{ + struct ximage_surface *xsurf = ximage_surface(nsurf); + boolean ret; + + ret = resource_surface_present(xsurf->rsurf, + NATIVE_ATTACHMENT_FRONT_LEFT, (void *) &xsurf->xdraw); + /* force buffers to be updated in next validation call */ + ximage_surface_invalidate(&xsurf->base); + + return ret; +} + +static boolean +ximage_surface_swap_buffers(struct native_surface *nsurf) +{ + struct ximage_surface *xsurf = ximage_surface(nsurf); + boolean ret; + + ret = resource_surface_present(xsurf->rsurf, + NATIVE_ATTACHMENT_BACK_LEFT, (void *) &xsurf->xdraw); + + resource_surface_swap_buffers(xsurf->rsurf, + NATIVE_ATTACHMENT_FRONT_LEFT, NATIVE_ATTACHMENT_BACK_LEFT, TRUE); + /* the front/back buffers have been swapped */ + ximage_surface_invalidate(&xsurf->base); + + return ret; +} + +static boolean +ximage_surface_present(struct native_surface *nsurf, + enum native_attachment natt, + boolean preserve, + uint swap_interval) +{ + boolean ret; + + if (preserve || swap_interval) + return FALSE; + + switch (natt) { + case NATIVE_ATTACHMENT_FRONT_LEFT: + ret = ximage_surface_flush_frontbuffer(nsurf); + break; + case NATIVE_ATTACHMENT_BACK_LEFT: + ret = ximage_surface_swap_buffers(nsurf); + break; + default: + ret = FALSE; + break; + } + + return ret; +} + +static boolean +ximage_surface_validate(struct native_surface *nsurf, uint attachment_mask, + unsigned int *seq_num, struct pipe_resource **textures, + int *width, int *height) +{ + struct ximage_surface *xsurf = ximage_surface(nsurf); + uint w, h; + + if (!ximage_surface_update_buffers(&xsurf->base, attachment_mask)) + return FALSE; + + if (seq_num) + *seq_num = xsurf->client_stamp; + + if (textures) + resource_surface_get_resources(xsurf->rsurf, textures, attachment_mask); + + resource_surface_get_size(xsurf->rsurf, &w, &h); + if (width) + *width = w; + if (height) + *height = h; + + return TRUE; +} + +static void +ximage_surface_wait(struct native_surface *nsurf) +{ + struct ximage_surface *xsurf = ximage_surface(nsurf); + XSync(xsurf->xdpy->dpy, FALSE); + /* TODO XGetImage and update the front texture */ +} + +static void +ximage_surface_destroy(struct native_surface *nsurf) +{ + struct ximage_surface *xsurf = ximage_surface(nsurf); + + resource_surface_destroy(xsurf->rsurf); + FREE(xsurf); +} + +static struct ximage_surface * +ximage_display_create_surface(struct native_display *ndpy, + enum ximage_surface_type type, + Drawable drawable, + const struct native_config *nconf) +{ + struct ximage_display *xdpy = ximage_display(ndpy); + struct ximage_config *xconf = ximage_config(nconf); + struct ximage_surface *xsurf; + + xsurf = CALLOC_STRUCT(ximage_surface); + if (!xsurf) + return NULL; + + xsurf->xdpy = xdpy; + xsurf->type = type; + xsurf->color_format = xconf->base.color_format; + xsurf->drawable = drawable; + + xsurf->rsurf = resource_surface_create(xdpy->base.screen, + xsurf->color_format, + PIPE_BIND_RENDER_TARGET | + PIPE_BIND_SAMPLER_VIEW | + PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_SCANOUT); + if (!xsurf->rsurf) { + FREE(xsurf); + return NULL; + } + + xsurf->drawable = drawable; + xsurf->visual = *xconf->visual; + /* initialize the geometry */ + ximage_surface_update_geometry(&xsurf->base); + + xsurf->xdraw.visual = xsurf->visual.visual; + xsurf->xdraw.depth = xsurf->visual.depth; + xsurf->xdraw.drawable = xsurf->drawable; + + xsurf->base.destroy = ximage_surface_destroy; + xsurf->base.present = ximage_surface_present; + xsurf->base.validate = ximage_surface_validate; + xsurf->base.wait = ximage_surface_wait; + + return xsurf; +} + +static struct native_surface * +ximage_display_create_window_surface(struct native_display *ndpy, + EGLNativeWindowType win, + const struct native_config *nconf) +{ + struct ximage_surface *xsurf; + + xsurf = ximage_display_create_surface(ndpy, XIMAGE_SURFACE_TYPE_WINDOW, + (Drawable) win, nconf); + return (xsurf) ? &xsurf->base : NULL; +} + +static struct native_surface * +ximage_display_create_pixmap_surface(struct native_display *ndpy, + EGLNativePixmapType pix, + const struct native_config *nconf) +{ + struct ximage_surface *xsurf; + + xsurf = ximage_display_create_surface(ndpy, XIMAGE_SURFACE_TYPE_PIXMAP, + (Drawable) pix, nconf); + return (xsurf) ? &xsurf->base : NULL; +} + +static enum pipe_format +choose_format(const XVisualInfo *vinfo) +{ + enum pipe_format fmt; + /* TODO elaborate the formats */ + switch (vinfo->depth) { + case 32: + fmt = PIPE_FORMAT_B8G8R8A8_UNORM; + break; + case 24: + fmt = PIPE_FORMAT_B8G8R8X8_UNORM; + break; + case 16: + fmt = PIPE_FORMAT_B5G6R5_UNORM; + break; + default: + fmt = PIPE_FORMAT_NONE; + break; + } + + return fmt; +} + +static const struct native_config ** +ximage_display_get_configs(struct native_display *ndpy, int *num_configs) +{ + struct ximage_display *xdpy = ximage_display(ndpy); + const struct native_config **configs; + int i; + + /* first time */ + if (!xdpy->configs) { + const XVisualInfo *visuals; + int num_visuals, count; + + visuals = x11_screen_get_visuals(xdpy->xscr, &num_visuals); + if (!visuals) + return NULL; + + /* + * Create two configs for each visual. + * One with depth/stencil buffer; one without + */ + xdpy->configs = CALLOC(num_visuals * 2, sizeof(*xdpy->configs)); + if (!xdpy->configs) + return NULL; + + count = 0; + for (i = 0; i < num_visuals; i++) { + struct ximage_config *xconf = &xdpy->configs[count]; + + xconf->visual = &visuals[i]; + xconf->base.color_format = choose_format(xconf->visual); + if (xconf->base.color_format == PIPE_FORMAT_NONE) + continue; + + xconf->base.buffer_mask = + (1 << NATIVE_ATTACHMENT_FRONT_LEFT) | + (1 << NATIVE_ATTACHMENT_BACK_LEFT); + + xconf->base.window_bit = TRUE; + xconf->base.pixmap_bit = TRUE; + + xconf->base.native_visual_id = xconf->visual->visualid; +#if defined(__cplusplus) || defined(c_plusplus) + xconf->base.native_visual_type = xconf->visual->c_class; +#else + xconf->base.native_visual_type = xconf->visual->class; +#endif + + xconf->base.slow_config = TRUE; + + count++; + } + + xdpy->num_configs = count; + } + + configs = MALLOC(xdpy->num_configs * sizeof(*configs)); + if (configs) { + for (i = 0; i < xdpy->num_configs; i++) + configs[i] = (const struct native_config *) &xdpy->configs[i]; + if (num_configs) + *num_configs = xdpy->num_configs; + } + return configs; +} + +static boolean +ximage_display_is_pixmap_supported(struct native_display *ndpy, + EGLNativePixmapType pix, + const struct native_config *nconf) +{ + struct ximage_display *xdpy = ximage_display(ndpy); + enum pipe_format fmt; + uint depth; + + depth = x11_drawable_get_depth(xdpy->xscr, (Drawable) pix); + switch (depth) { + case 32: + fmt = PIPE_FORMAT_B8G8R8A8_UNORM; + break; + case 24: + fmt = PIPE_FORMAT_B8G8R8X8_UNORM; + break; + case 16: + fmt = PIPE_FORMAT_B5G6R5_UNORM; + break; + default: + fmt = PIPE_FORMAT_NONE; + break; + } + + return (fmt == nconf->color_format); +} + +static int +ximage_display_get_param(struct native_display *ndpy, + enum native_param_type param) +{ + int val; + + switch (param) { + case NATIVE_PARAM_USE_NATIVE_BUFFER: + /* private buffers are allocated */ + val = FALSE; + break; + case NATIVE_PARAM_PRESERVE_BUFFER: + case NATIVE_PARAM_MAX_SWAP_INTERVAL: + default: + val = 0; + break; + } + + return val; +} + +static void +ximage_display_destroy(struct native_display *ndpy) +{ + struct ximage_display *xdpy = ximage_display(ndpy); + + if (xdpy->configs) + FREE(xdpy->configs); + + xdpy->base.screen->destroy(xdpy->base.screen); + + x11_screen_destroy(xdpy->xscr); + if (xdpy->own_dpy) + XCloseDisplay(xdpy->dpy); + FREE(xdpy); +} + +struct native_display * +x11_create_ximage_display(Display *dpy, + struct native_event_handler *event_handler, + void *user_data) +{ + struct ximage_display *xdpy; + struct sw_winsys *winsys = NULL; + + xdpy = CALLOC_STRUCT(ximage_display); + if (!xdpy) + return NULL; + + xdpy->dpy = dpy; + if (!xdpy->dpy) { + xdpy->dpy = XOpenDisplay(NULL); + if (!xdpy->dpy) { + FREE(xdpy); + return NULL; + } + xdpy->own_dpy = TRUE; + } + + xdpy->event_handler = event_handler; + xdpy->base.user_data = user_data; + + xdpy->xscr_number = DefaultScreen(xdpy->dpy); + xdpy->xscr = x11_screen_create(xdpy->dpy, xdpy->xscr_number); + if (!xdpy->xscr) + goto fail; + + winsys = xlib_create_sw_winsys(xdpy->dpy); + if (!winsys) + goto fail; + + xdpy->base.screen = + xdpy->event_handler->new_sw_screen(&xdpy->base, winsys); + if (!xdpy->base.screen) + goto fail; + + xdpy->base.destroy = ximage_display_destroy; + xdpy->base.get_param = ximage_display_get_param; + + xdpy->base.get_configs = ximage_display_get_configs; + xdpy->base.is_pixmap_supported = ximage_display_is_pixmap_supported; + xdpy->base.create_window_surface = ximage_display_create_window_surface; + xdpy->base.create_pixmap_surface = ximage_display_create_pixmap_surface; + + return &xdpy->base; + +fail: + if (winsys && winsys->destroy) + winsys->destroy(winsys); + if (xdpy->xscr) + x11_screen_destroy(xdpy->xscr); + if (xdpy->dpy && xdpy->own_dpy) + XCloseDisplay(xdpy->dpy); + FREE(xdpy); + return NULL; +} diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.c b/src/gallium/state_trackers/egl/x11/x11_screen.c new file mode 100644 index 0000000..c919b79 --- /dev/null +++ b/src/gallium/state_trackers/egl/x11/x11_screen.c @@ -0,0 +1,446 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2009-2010 Chia-I Wu + * + * 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 +#include +#include +#include +#include +#include +#include + +#include "util/u_memory.h" +#include "egllog.h" + +#include "x11_screen.h" +#include "dri2.h" +#include "glxinit.h" + +struct x11_screen { + Display *dpy; + int number; + + /* + * This is used to fetch GLX visuals/fbconfigs. It steals code from GLX. + * It might be better to rewrite the part in Xlib or XCB. + */ + __GLXdisplayPrivate *glx_dpy; + + int dri_major, dri_minor; + char *dri_driver; + char *dri_device; + int dri_fd; + + x11_drawable_invalidate_buffers dri_invalidate_buffers; + void *dri_user_data; + + XVisualInfo *visuals; + int num_visuals; + + /* cached values for x11_drawable_get_depth */ + Drawable last_drawable; + unsigned int last_depth; +}; + + +/** + * Create a X11 screen. + */ +struct x11_screen * +x11_screen_create(Display *dpy, int screen) +{ + struct x11_screen *xscr; + + if (screen >= ScreenCount(dpy)) + return NULL; + + xscr = CALLOC_STRUCT(x11_screen); + if (xscr) { + xscr->dpy = dpy; + xscr->number = screen; + + xscr->dri_major = -1; + xscr->dri_fd = -1; + } + return xscr; +} + +/** + * Destroy a X11 screen. + */ +void +x11_screen_destroy(struct x11_screen *xscr) +{ + if (xscr->dri_fd >= 0) + close(xscr->dri_fd); + if (xscr->dri_driver) + Xfree(xscr->dri_driver); + if (xscr->dri_device) + Xfree(xscr->dri_device); + +#ifdef GLX_DIRECT_RENDERING + /* xscr->glx_dpy will be destroyed with the X display */ + if (xscr->glx_dpy) + xscr->glx_dpy->xscr = NULL; +#endif + + if (xscr->visuals) + XFree(xscr->visuals); + FREE(xscr); +} + +#ifdef GLX_DIRECT_RENDERING + +static boolean +x11_screen_init_dri2(struct x11_screen *xscr) +{ + if (xscr->dri_major < 0) { + int eventBase, errorBase; + + if (!DRI2QueryExtension(xscr->dpy, &eventBase, &errorBase) || + !DRI2QueryVersion(xscr->dpy, &xscr->dri_major, &xscr->dri_minor)) + xscr->dri_major = -1; + } + return (xscr->dri_major >= 0); +} + +static boolean +x11_screen_init_glx(struct x11_screen *xscr) +{ + if (!xscr->glx_dpy) + xscr->glx_dpy = __glXInitialize(xscr->dpy); + return (xscr->glx_dpy != NULL); +} + +#endif /* GLX_DIRECT_RENDERING */ + +/** + * Return true if the screen supports the extension. + */ +boolean +x11_screen_support(struct x11_screen *xscr, enum x11_screen_extension ext) +{ + boolean supported = FALSE; + + switch (ext) { + case X11_SCREEN_EXTENSION_XSHM: + supported = XShmQueryExtension(xscr->dpy); + break; +#ifdef GLX_DIRECT_RENDERING + case X11_SCREEN_EXTENSION_GLX: + supported = x11_screen_init_glx(xscr); + break; + case X11_SCREEN_EXTENSION_DRI2: + supported = x11_screen_init_dri2(xscr); + break; +#endif + default: + break; + } + + return supported; +} + +/** + * Return the X visuals. + */ +const XVisualInfo * +x11_screen_get_visuals(struct x11_screen *xscr, int *num_visuals) +{ + if (!xscr->visuals) { + XVisualInfo vinfo_template; + vinfo_template.screen = xscr->number; + xscr->visuals = XGetVisualInfo(xscr->dpy, VisualScreenMask, + &vinfo_template, &xscr->num_visuals); + } + + if (num_visuals) + *num_visuals = xscr->num_visuals; + return xscr->visuals; +} + +/** + * Return the depth of a drawable. + * + * Unlike other drawable functions, the drawable needs not be a DRI2 drawable. + */ +uint +x11_drawable_get_depth(struct x11_screen *xscr, Drawable drawable) +{ + unsigned int depth; + + if (drawable != xscr->last_drawable) { + Window root; + int x, y; + unsigned int w, h, border; + Status ok; + + ok = XGetGeometry(xscr->dpy, drawable, &root, + &x, &y, &w, &h, &border, &depth); + if (!ok) + depth = 0; + + xscr->last_drawable = drawable; + xscr->last_depth = depth; + } + else { + depth = xscr->last_depth; + } + + return depth; +} + +#ifdef GLX_DIRECT_RENDERING + +/** + * Return the GLX fbconfigs. + */ +const __GLcontextModes * +x11_screen_get_glx_configs(struct x11_screen *xscr) +{ + return (x11_screen_init_glx(xscr)) + ? xscr->glx_dpy->screenConfigs[xscr->number]->configs + : NULL; +} + +/** + * Probe the screen for the DRI2 driver name. + */ +const char * +x11_screen_probe_dri2(struct x11_screen *xscr, int *major, int *minor) +{ + if (!x11_screen_init_dri2(xscr)) + return NULL; + + /* get the driver name and the device name */ + if (!xscr->dri_driver) { + if (!DRI2Connect(xscr->dpy, RootWindow(xscr->dpy, xscr->number), + &xscr->dri_driver, &xscr->dri_device)) + xscr->dri_driver = xscr->dri_device = NULL; + } + if (major) + *major = xscr->dri_major; + if (minor) + *minor = xscr->dri_minor; + + return xscr->dri_driver; +} + +/** + * Enable DRI2 and returns the file descriptor of the DRM device. The file + * descriptor will be closed automatically when the screen is destoryed. + */ +int +x11_screen_enable_dri2(struct x11_screen *xscr, + x11_drawable_invalidate_buffers invalidate_buffers, + void *user_data) +{ + if (xscr->dri_fd < 0) { + int fd; + drm_magic_t magic; + + /* get the driver name and the device name first */ + if (!x11_screen_probe_dri2(xscr, NULL, NULL)) + return -1; + + fd = open(xscr->dri_device, O_RDWR); + if (fd < 0) { + _eglLog(_EGL_WARNING, "failed to open %s", xscr->dri_device); + return -1; + } + + memset(&magic, 0, sizeof(magic)); + if (drmGetMagic(fd, &magic)) { + _eglLog(_EGL_WARNING, "failed to get magic"); + close(fd); + return -1; + } + + if (!DRI2Authenticate(xscr->dpy, + RootWindow(xscr->dpy, xscr->number), magic)) { + _eglLog(_EGL_WARNING, "failed to authenticate magic"); + close(fd); + return -1; + } + + if (!x11_screen_init_glx(xscr)) { + _eglLog(_EGL_WARNING, "failed to initialize GLX"); + close(fd); + return -1; + } + if (xscr->glx_dpy->xscr) { + _eglLog(_EGL_WARNING, + "display is already managed by another x11 screen"); + close(fd); + return -1; + } + + xscr->glx_dpy->xscr = xscr; + xscr->dri_invalidate_buffers = invalidate_buffers; + xscr->dri_user_data = user_data; + + xscr->dri_fd = fd; + } + + return xscr->dri_fd; +} + +/** + * Create/Destroy the DRI drawable. + */ +void +x11_drawable_enable_dri2(struct x11_screen *xscr, + Drawable drawable, boolean on) +{ + if (on) + DRI2CreateDrawable(xscr->dpy, drawable); + else + DRI2DestroyDrawable(xscr->dpy, drawable); +} + +/** + * Copy between buffers of the DRI2 drawable. + */ +void +x11_drawable_copy_buffers(struct x11_screen *xscr, Drawable drawable, + int x, int y, int width, int height, + int src_buf, int dst_buf) +{ + XRectangle rect; + XserverRegion region; + + rect.x = x; + rect.y = y; + rect.width = width; + rect.height = height; + + region = XFixesCreateRegion(xscr->dpy, &rect, 1); + DRI2CopyRegion(xscr->dpy, drawable, region, dst_buf, src_buf); + XFixesDestroyRegion(xscr->dpy, region); +} + +/** + * Get the buffers of the DRI2 drawable. The returned array should be freed. + */ +struct x11_drawable_buffer * +x11_drawable_get_buffers(struct x11_screen *xscr, Drawable drawable, + int *width, int *height, unsigned int *attachments, + boolean with_format, int num_ins, int *num_outs) +{ + DRI2Buffer *dri2bufs; + + if (with_format) + dri2bufs = DRI2GetBuffersWithFormat(xscr->dpy, drawable, width, height, + attachments, num_ins, num_outs); + else + dri2bufs = DRI2GetBuffers(xscr->dpy, drawable, width, height, + attachments, num_ins, num_outs); + + return (struct x11_drawable_buffer *) dri2bufs; +} + +/** + * Create a mode list of the given size. + */ +__GLcontextModes * +x11_context_modes_create(unsigned count) +{ + const size_t size = sizeof(__GLcontextModes); + __GLcontextModes *base = NULL; + __GLcontextModes **next; + unsigned i; + + next = &base; + for (i = 0; i < count; i++) { + *next = (__GLcontextModes *) CALLOC(1, size); + if (*next == NULL) { + x11_context_modes_destroy(base); + base = NULL; + break; + } + next = &((*next)->next); + } + + return base; +} + +/** + * Destroy a mode list. + */ +void +x11_context_modes_destroy(__GLcontextModes *modes) +{ + while (modes != NULL) { + __GLcontextModes *next = modes->next; + FREE(modes); + modes = next; + } +} + +/** + * Return the number of the modes in the mode list. + */ +unsigned +x11_context_modes_count(const __GLcontextModes *modes) +{ + const __GLcontextModes *mode; + int count = 0; + for (mode = modes; mode; mode = mode->next) + count++; + return count; +} + +extern void +dri2InvalidateBuffers(Display *dpy, XID drawable); + +/** + * This is called from src/glx/dri2.c. + */ +void +dri2InvalidateBuffers(Display *dpy, XID drawable) +{ + __GLXdisplayPrivate *priv = __glXInitialize(dpy); + struct x11_screen *xscr = NULL; + + if (priv && priv->xscr) + xscr = priv->xscr; + if (!xscr || !xscr->dri_invalidate_buffers) + return; + + xscr->dri_invalidate_buffers(xscr, drawable, xscr->dri_user_data); +} + +extern unsigned +dri2GetSwapEventType(Display *dpy, XID drawable); + +/** + * This is also called from src/glx/dri2.c. + */ +unsigned dri2GetSwapEventType(Display *dpy, XID drawable) +{ + return 0; +} + +#endif /* GLX_DIRECT_RENDERING */ diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.h b/src/gallium/state_trackers/egl/x11/x11_screen.h new file mode 100644 index 0000000..2e313e0 --- /dev/null +++ b/src/gallium/state_trackers/egl/x11/x11_screen.h @@ -0,0 +1,116 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2009-2010 Chia-I Wu + * + * 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 _X11_SCREEN_H_ +#define _X11_SCREEN_H_ + +#include +#include +#include +#include "GL/gl.h" /* for GL types needed by __GLcontextModes */ +#include "glcore.h" /* for __GLcontextModes */ +#include "pipe/p_compiler.h" +#include "common/native.h" + +enum x11_screen_extension { + X11_SCREEN_EXTENSION_XSHM, + X11_SCREEN_EXTENSION_GLX, + X11_SCREEN_EXTENSION_DRI2, +}; + +/* the same as DRI2Buffer */ +struct x11_drawable_buffer { + unsigned int attachment; + unsigned int name; + unsigned int pitch; + unsigned int cpp; + unsigned int flags; +}; + +struct x11_screen; + +typedef void (*x11_drawable_invalidate_buffers)(struct x11_screen *xscr, + Drawable drawable, + void *user_data); + +struct x11_screen * +x11_screen_create(Display *dpy, int screen); + +void +x11_screen_destroy(struct x11_screen *xscr); + +boolean +x11_screen_support(struct x11_screen *xscr, enum x11_screen_extension ext); + +const XVisualInfo * +x11_screen_get_visuals(struct x11_screen *xscr, int *num_visuals); + +uint +x11_drawable_get_depth(struct x11_screen *xscr, Drawable drawable); + +#ifdef GLX_DIRECT_RENDERING + +/* GLX */ +const __GLcontextModes * +x11_screen_get_glx_configs(struct x11_screen *xscr); + +const __GLcontextModes * +x11_screen_get_glx_visuals(struct x11_screen *xscr); + +__GLcontextModes * +x11_context_modes_create(unsigned count); + +void +x11_context_modes_destroy(__GLcontextModes *modes); + +unsigned +x11_context_modes_count(const __GLcontextModes *modes); + +/* DRI2 */ +const char * +x11_screen_probe_dri2(struct x11_screen *xscr, int *major, int *minor); + +int +x11_screen_enable_dri2(struct x11_screen *xscr, + x11_drawable_invalidate_buffers invalidate_buffers, + void *user_data); + +void +x11_drawable_enable_dri2(struct x11_screen *xscr, + Drawable drawable, boolean on); + +void +x11_drawable_copy_buffers(struct x11_screen *xscr, Drawable drawable, + int x, int y, int width, int height, + int src_buf, int dst_buf); + +struct x11_drawable_buffer * +x11_drawable_get_buffers(struct x11_screen *xscr, Drawable drawable, + int *width, int *height, unsigned int *attachments, + boolean with_format, int num_ins, int *num_outs); + +#endif /* GLX_DIRECT_RENDERING */ + +#endif /* _X11_SCREEN_H_ */ diff --git a/src/gallium/state_trackers/glx/Makefile b/src/gallium/state_trackers/glx/Makefile new file mode 100644 index 0000000..f779035 --- /dev/null +++ b/src/gallium/state_trackers/glx/Makefile @@ -0,0 +1,25 @@ +TOP = ../../../.. +include $(TOP)/configs/current + + +SUBDIRS = xlib + + +default: subdirs + + +subdirs: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE)) || exit 1 ; \ + fi \ + done + + +clean: + rm -f `find . -name \*.[oa]` + rm -f `find . -name depend` + + +# Dummy install target +install: diff --git a/src/gallium/state_trackers/glx/xlib/Makefile b/src/gallium/state_trackers/glx/xlib/Makefile new file mode 100644 index 0000000..84cb36e --- /dev/null +++ b/src/gallium/state_trackers/glx/xlib/Makefile @@ -0,0 +1,19 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = xlib + +LIBRARY_INCLUDES = \ + -I$(TOP)/include \ + -I$(TOP)/src/mapi \ + -I$(TOP)/src/mesa \ + $(X11_CFLAGS) + +C_SOURCES = \ + glx_api.c \ + glx_getproc.c \ + glx_usefont.c \ + xm_api.c \ + xm_st.c + +include ../../../Makefile.template diff --git a/src/gallium/state_trackers/glx/xlib/SConscript b/src/gallium/state_trackers/glx/xlib/SConscript new file mode 100644 index 0000000..9e7ebf3 --- /dev/null +++ b/src/gallium/state_trackers/glx/xlib/SConscript @@ -0,0 +1,26 @@ +####################################################################### +# SConscript for xlib state_tracker + +Import('*') + +env = env.Clone() + +env.Append(CPPPATH = [ + '#/src/mapi', + '#/src/mesa', + '#/src/mesa/main', +]) + +sources = [ + 'glx_api.c', + 'glx_getproc.c', + 'glx_usefont.c', + 'xm_api.c', + 'xm_st.c', +] + +st_xlib = env.ConvenienceLibrary( + target = 'st_xlib', + source = sources, +) +Export('st_xlib') diff --git a/src/gallium/state_trackers/glx/xlib/glx_api.c b/src/gallium/state_trackers/glx/xlib/glx_api.c new file mode 100644 index 0000000..205a7e3 --- /dev/null +++ b/src/gallium/state_trackers/glx/xlib/glx_api.c @@ -0,0 +1,2641 @@ +/* + * Mesa 3-D graphics library + * Version: 7.6 + * + * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. + * Copyright (C) 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 + * 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. + */ + + +/** + * "Fake" GLX API implemented in terms of the XMesa*() functions. + */ + + + +#define GLX_GLXEXT_PROTOTYPES +#include "GL/glx.h" + +#include "xm_api.h" + + +/* This indicates the client-side GLX API and GLX encoder version. */ +#define CLIENT_MAJOR_VERSION 1 +#define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */ + +/* This indicates the server-side GLX decoder version. + * GLX 1.4 indicates OpenGL 1.3 support + */ +#define SERVER_MAJOR_VERSION 1 +#define SERVER_MINOR_VERSION 4 + +/* Who implemented this GLX? */ +#define VENDOR "Brian Paul" + +#define EXTENSIONS \ + "GLX_MESA_copy_sub_buffer " \ + "GLX_MESA_pixmap_colormap " \ + "GLX_MESA_release_buffers " \ + "GLX_ARB_get_proc_address " \ + "GLX_EXT_texture_from_pixmap " \ + "GLX_EXT_visual_info " \ + "GLX_EXT_visual_rating " \ + /*"GLX_SGI_video_sync "*/ \ + "GLX_SGIX_fbconfig " \ + "GLX_SGIX_pbuffer " + +#define DEFAULT_DIRECT GL_TRUE + + + +/** + * The GLXContext typedef is defined as a pointer to this structure. + */ +struct __GLXcontextRec +{ + Display *currentDpy; + GLboolean isDirect; + GLXDrawable currentDrawable; + GLXDrawable currentReadable; + XID xid; + + XMesaContext xmesaContext; +}; + + + +static pipe_tsd ContextTSD; + +/** Set current context for calling thread */ +static void +SetCurrentContext(GLXContext c) +{ + pipe_tsd_set(&ContextTSD, c); +} + +/** Get current context for calling thread */ +static GLXContext +GetCurrentContext(void) +{ + return pipe_tsd_get(&ContextTSD); +} + + + +/**********************************************************************/ +/*** GLX Visual Code ***/ +/**********************************************************************/ + +#define DONT_CARE -1 + + +static XMesaVisual *VisualTable = NULL; +static int NumVisuals = 0; + + + +/* Macro to handle c_class vs class field name in XVisualInfo struct */ +#if defined(__cplusplus) || defined(c_plusplus) +#define CLASS c_class +#else +#define CLASS class +#endif + + + +/* + * Test if the given XVisualInfo is usable for Mesa rendering. + */ +static GLboolean +is_usable_visual( XVisualInfo *vinfo ) +{ + switch (vinfo->CLASS) { + case StaticGray: + case GrayScale: + /* Any StaticGray/GrayScale visual works in RGB or CI mode */ + return GL_TRUE; + case StaticColor: + case PseudoColor: + /* Any StaticColor/PseudoColor visual of at least 4 bits */ + if (vinfo->depth>=4) { + return GL_TRUE; + } + else { + return GL_FALSE; + } + case TrueColor: + case DirectColor: + /* Any depth of TrueColor or DirectColor works in RGB mode */ + return GL_TRUE; + default: + /* This should never happen */ + return GL_FALSE; + } +} + + +/* + * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the + * configuration in our list of GLX visuals. + */ +static XMesaVisual +save_glx_visual( Display *dpy, XVisualInfo *vinfo, + GLboolean rgbFlag, GLboolean alphaFlag, GLboolean dbFlag, + GLboolean stereoFlag, + GLint depth_size, GLint stencil_size, + GLint accumRedSize, GLint accumGreenSize, + GLint accumBlueSize, GLint accumAlphaSize, + GLint level, GLint numAuxBuffers ) +{ + GLboolean ximageFlag = GL_TRUE; + XMesaVisual xmvis; + GLint i; + GLboolean comparePointers; + + if (dbFlag) { + /* Check if the MESA_BACK_BUFFER env var is set */ + char *backbuffer = _mesa_getenv("MESA_BACK_BUFFER"); + if (backbuffer) { + if (backbuffer[0]=='p' || backbuffer[0]=='P') { + ximageFlag = GL_FALSE; + } + else if (backbuffer[0]=='x' || backbuffer[0]=='X') { + ximageFlag = GL_TRUE; + } + else { + _mesa_warning(NULL, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage."); + } + } + } + + if (stereoFlag) { + /* stereo not supported */ + return NULL; + } + + if (stencil_size > 0 && depth_size > 0) + depth_size = 24; + + /* Comparing IDs uses less memory but sometimes fails. */ + /* XXX revisit this after 3.0 is finished. */ + if (_mesa_getenv("MESA_GLX_VISUAL_HACK")) + comparePointers = GL_TRUE; + else + comparePointers = GL_FALSE; + + /* Force the visual to have an alpha channel */ + if (rgbFlag && _mesa_getenv("MESA_GLX_FORCE_ALPHA")) + alphaFlag = GL_TRUE; + + /* First check if a matching visual is already in the list */ + for (i=0; idisplay == dpy + && v->mesa_visual.level == level + && v->mesa_visual.numAuxBuffers == numAuxBuffers + && v->ximage_flag == ximageFlag + && v->mesa_visual.rgbMode == rgbFlag + && v->mesa_visual.doubleBufferMode == dbFlag + && v->mesa_visual.stereoMode == stereoFlag + && (v->mesa_visual.alphaBits > 0) == alphaFlag + && (v->mesa_visual.depthBits >= depth_size || depth_size == 0) + && (v->mesa_visual.stencilBits >= stencil_size || stencil_size == 0) + && (v->mesa_visual.accumRedBits >= accumRedSize || accumRedSize == 0) + && (v->mesa_visual.accumGreenBits >= accumGreenSize || accumGreenSize == 0) + && (v->mesa_visual.accumBlueBits >= accumBlueSize || accumBlueSize == 0) + && (v->mesa_visual.accumAlphaBits >= accumAlphaSize || accumAlphaSize == 0)) { + /* now either compare XVisualInfo pointers or visual IDs */ + if ((!comparePointers && v->visinfo->visualid == vinfo->visualid) + || (comparePointers && v->vishandle == vinfo)) { + return v; + } + } + } + + /* Create a new visual and add it to the list. */ + + xmvis = XMesaCreateVisual( dpy, vinfo, rgbFlag, alphaFlag, dbFlag, + stereoFlag, ximageFlag, + depth_size, stencil_size, + accumRedSize, accumBlueSize, + accumBlueSize, accumAlphaSize, 0, level, + GLX_NONE_EXT ); + if (xmvis) { + /* Save a copy of the pointer now so we can find this visual again + * if we need to search for it in find_glx_visual(). + */ + xmvis->vishandle = vinfo; + /* Allocate more space for additional visual */ + VisualTable = (XMesaVisual *) _mesa_realloc( VisualTable, + sizeof(XMesaVisual) * NumVisuals, + sizeof(XMesaVisual) * (NumVisuals + 1)); + /* add xmvis to the list */ + VisualTable[NumVisuals] = xmvis; + NumVisuals++; + /* XXX minor hack, because XMesaCreateVisual doesn't support an + * aux buffers parameter. + */ + xmvis->mesa_visual.numAuxBuffers = numAuxBuffers; + } + return xmvis; +} + + +/** + * Return the default number of bits for the Z buffer. + * If defined, use the MESA_GLX_DEPTH_BITS env var value. + * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant. + * XXX probably do the same thing for stencil, accum, etc. + */ +static GLint +default_depth_bits(void) +{ + int zBits; + const char *zEnv = _mesa_getenv("MESA_GLX_DEPTH_BITS"); + if (zEnv) + zBits = atoi(zEnv); + else + zBits = DEFAULT_SOFTWARE_DEPTH_BITS; + return zBits; +} + +static GLint +default_alpha_bits(void) +{ + int aBits; + const char *aEnv = _mesa_getenv("MESA_GLX_ALPHA_BITS"); + if (aEnv) + aBits = atoi(aEnv); + else + aBits = 0; + return aBits; +} + +static GLint +default_accum_bits(void) +{ + return 16; +} + + + +/* + * Create a GLX visual from a regular XVisualInfo. + * This is called when Fake GLX is given an XVisualInfo which wasn't + * returned by glXChooseVisual. Since this is the first time we're + * considering this visual we'll take a guess at reasonable values + * for depth buffer size, stencil size, accum size, etc. + * This is the best we can do with a client-side emulation of GLX. + */ +static XMesaVisual +create_glx_visual( Display *dpy, XVisualInfo *visinfo ) +{ + GLint zBits = default_depth_bits(); + GLint accBits = default_accum_bits(); + GLboolean alphaFlag = default_alpha_bits() > 0; + + if (is_usable_visual( visinfo )) { + /* Configure this visual as RGB, double-buffered, depth-buffered. */ + /* This is surely wrong for some people's needs but what else */ + /* can be done? They should use glXChooseVisual(). */ + return save_glx_visual( dpy, visinfo, + GL_TRUE, /* rgb */ + alphaFlag, /* alpha */ + GL_TRUE, /* double */ + GL_FALSE, /* stereo */ + zBits, + STENCIL_BITS, + accBits, /* r */ + accBits, /* g */ + accBits, /* b */ + accBits, /* a */ + 0, /* level */ + 0 /* numAux */ + ); + } + else { + _mesa_warning(NULL, "Mesa: error in glXCreateContext: bad visual\n"); + return NULL; + } +} + + + +/* + * Find the GLX visual associated with an XVisualInfo. + */ +static XMesaVisual +find_glx_visual( Display *dpy, XVisualInfo *vinfo ) +{ + int i; + + /* try to match visual id */ + for (i=0;idisplay==dpy + && VisualTable[i]->visinfo->visualid == vinfo->visualid) { + return VisualTable[i]; + } + } + + /* if that fails, try to match pointers */ + for (i=0;idisplay==dpy && VisualTable[i]->vishandle==vinfo) { + return VisualTable[i]; + } + } + + return NULL; +} + + +/** + * Try to get an X visual which matches the given arguments. + */ +static XVisualInfo * +get_visual( Display *dpy, int scr, unsigned int depth, int xclass ) +{ + XVisualInfo temp, *vis; + long mask; + int n; + unsigned int default_depth; + int default_class; + + mask = VisualScreenMask | VisualDepthMask | VisualClassMask; + temp.screen = scr; + temp.depth = depth; + temp.CLASS = xclass; + + default_depth = DefaultDepth(dpy,scr); + default_class = DefaultVisual(dpy,scr)->CLASS; + + if (depth==default_depth && xclass==default_class) { + /* try to get root window's visual */ + temp.visualid = DefaultVisual(dpy,scr)->visualid; + mask |= VisualIDMask; + } + + vis = XGetVisualInfo( dpy, mask, &temp, &n ); + + /* In case bits/pixel > 24, make sure color channels are still <=8 bits. + * An SGI Infinite Reality system, for example, can have 30bpp pixels: + * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel. + */ + if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) { + if (_mesa_bitcount((GLuint) vis->red_mask ) <= 8 && + _mesa_bitcount((GLuint) vis->green_mask) <= 8 && + _mesa_bitcount((GLuint) vis->blue_mask ) <= 8) { + return vis; + } + else { + XFree((void *) vis); + return NULL; + } + } + + return vis; +} + + +/* + * Retrieve the value of the given environment variable and find + * the X visual which matches it. + * Input: dpy - the display + * screen - the screen number + * varname - the name of the environment variable + * Return: an XVisualInfo pointer to NULL if error. + */ +static XVisualInfo * +get_env_visual(Display *dpy, int scr, const char *varname) +{ + char value[100], type[100]; + int depth, xclass = -1; + XVisualInfo *vis; + + if (!_mesa_getenv( varname )) { + return NULL; + } + + strncpy( value, _mesa_getenv(varname), 100 ); + value[99] = 0; + + sscanf( value, "%s %d", type, &depth ); + + if (strcmp(type,"TrueColor")==0) xclass = TrueColor; + else if (strcmp(type,"DirectColor")==0) xclass = DirectColor; + else if (strcmp(type,"PseudoColor")==0) xclass = PseudoColor; + else if (strcmp(type,"StaticColor")==0) xclass = StaticColor; + else if (strcmp(type,"GrayScale")==0) xclass = GrayScale; + else if (strcmp(type,"StaticGray")==0) xclass = StaticGray; + + if (xclass>-1 && depth>0) { + vis = get_visual( dpy, scr, depth, xclass ); + if (vis) { + return vis; + } + } + + _mesa_warning(NULL, "GLX unable to find visual class=%s, depth=%d.", + type, depth); + + return NULL; +} + + + +/* + * Select an X visual which satisfies the RGBA flag and minimum depth. + * Input: dpy, + * screen - X display and screen number + * min_depth - minimum visual depth + * preferred_class - preferred GLX visual class or DONT_CARE + * Return: pointer to an XVisualInfo or NULL. + */ +static XVisualInfo * +choose_x_visual( Display *dpy, int screen, int min_depth, + int preferred_class ) +{ + XVisualInfo *vis; + int xclass, visclass = 0; + int depth; + + /* First see if the MESA_RGB_VISUAL env var is defined */ + vis = get_env_visual( dpy, screen, "MESA_RGB_VISUAL" ); + if (vis) { + return vis; + } + /* Otherwise, search for a suitable visual */ + if (preferred_class==DONT_CARE) { + for (xclass=0;xclass<6;xclass++) { + switch (xclass) { + case 0: visclass = TrueColor; break; + case 1: visclass = DirectColor; break; + case 2: visclass = PseudoColor; break; + case 3: visclass = StaticColor; break; + case 4: visclass = GrayScale; break; + case 5: visclass = StaticGray; break; + } + if (min_depth==0) { + /* start with shallowest */ + for (depth=0;depth<=32;depth++) { + if (visclass==TrueColor && depth==8) { + /* Special case: try to get 8-bit PseudoColor before */ + /* 8-bit TrueColor */ + vis = get_visual( dpy, screen, 8, PseudoColor ); + if (vis) { + return vis; + } + } + vis = get_visual( dpy, screen, depth, visclass ); + if (vis) { + return vis; + } + } + } + else { + /* start with deepest */ + for (depth=32;depth>=min_depth;depth--) { + if (visclass==TrueColor && depth==8) { + /* Special case: try to get 8-bit PseudoColor before */ + /* 8-bit TrueColor */ + vis = get_visual( dpy, screen, 8, PseudoColor ); + if (vis) { + return vis; + } + } + vis = get_visual( dpy, screen, depth, visclass ); + if (vis) { + return vis; + } + } + } + } + } + else { + /* search for a specific visual class */ + switch (preferred_class) { + case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break; + case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break; + case GLX_PSEUDO_COLOR_EXT: visclass = PseudoColor; break; + case GLX_STATIC_COLOR_EXT: visclass = StaticColor; break; + case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break; + case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break; + default: return NULL; + } + if (min_depth==0) { + /* start with shallowest */ + for (depth=0;depth<=32;depth++) { + vis = get_visual( dpy, screen, depth, visclass ); + if (vis) { + return vis; + } + } + } + else { + /* start with deepest */ + for (depth=32;depth>=min_depth;depth--) { + vis = get_visual( dpy, screen, depth, visclass ); + if (vis) { + return vis; + } + } + } + } + + /* didn't find a visual */ + return NULL; +} + + + + +/**********************************************************************/ +/*** Display-related functions ***/ +/**********************************************************************/ + + +/** + * Free all XMesaVisuals which are associated with the given display. + */ +static void +destroy_visuals_on_display(Display *dpy) +{ + int i; + for (i = 0; i < NumVisuals; i++) { + if (VisualTable[i]->display == dpy) { + /* remove this visual */ + int j; + free(VisualTable[i]); + for (j = i; j < NumVisuals - 1; j++) + VisualTable[j] = VisualTable[j + 1]; + NumVisuals--; + } + } +} + + +/** + * Called from XCloseDisplay() to let us free our display-related data. + */ +static int +close_display_callback(Display *dpy, XExtCodes *codes) +{ + xmesa_destroy_buffers_on_display(dpy); + destroy_visuals_on_display(dpy); + return 0; +} + + +/** + * Look for the named extension on given display and return a pointer + * to the _XExtension data, or NULL if extension not found. + */ +static _XExtension * +lookup_extension(Display *dpy, const char *extName) +{ + _XExtension *ext; + for (ext = dpy->ext_procs; ext; ext = ext->next) { + if (ext->name && strcmp(ext->name, extName) == 0) { + return ext; + } + } + return NULL; +} + + +/** + * Whenever we're given a new Display pointer, call this function to + * register our close_display_callback function. + */ +static void +register_with_display(Display *dpy) +{ + const char *extName = "MesaGLX"; + _XExtension *ext; + + ext = lookup_extension(dpy, extName); + if (!ext) { + XExtCodes *c = XAddExtension(dpy); + ext = dpy->ext_procs; /* new extension is at head of list */ + assert(c->extension == ext->codes.extension); + (void) c; + ext->name = _mesa_strdup(extName); + ext->close_display = close_display_callback; + } +} + + +/**********************************************************************/ +/*** Begin Fake GLX API Functions ***/ +/**********************************************************************/ + + +/** + * Helper used by glXChooseVisual and glXChooseFBConfig. + * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for + * the later. + * In either case, the attribute list is terminated with the value 'None'. + */ +static XMesaVisual +choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig ) +{ + const GLboolean rgbModeDefault = fbConfig; + const int *parselist; + XVisualInfo *vis; + int min_ci = 0; + int min_red=0, min_green=0, min_blue=0; + GLboolean rgb_flag = rgbModeDefault; + GLboolean alpha_flag = GL_FALSE; + GLboolean double_flag = GL_FALSE; + GLboolean stereo_flag = GL_FALSE; + GLint depth_size = 0; + GLint stencil_size = 0; + GLint accumRedSize = 0; + GLint accumGreenSize = 0; + GLint accumBlueSize = 0; + GLint accumAlphaSize = 0; + int level = 0; + int visual_type = DONT_CARE; + int trans_type = DONT_CARE; + int trans_value = DONT_CARE; + GLint caveat = DONT_CARE; + XMesaVisual xmvis = NULL; + int desiredVisualID = -1; + int numAux = 0; + + xmesa_init( dpy ); + + parselist = list; + + while (*parselist) { + + switch (*parselist) { + case GLX_USE_GL: + if (fbConfig) { + /* invalid token */ + return NULL; + } + else { + /* skip */ + parselist++; + } + break; + case GLX_BUFFER_SIZE: + parselist++; + min_ci = *parselist++; + break; + case GLX_LEVEL: + parselist++; + level = *parselist++; + break; + case GLX_RGBA: + if (fbConfig) { + /* invalid token */ + return NULL; + } + else { + rgb_flag = GL_TRUE; + parselist++; + } + break; + case GLX_DOUBLEBUFFER: + parselist++; + if (fbConfig) { + double_flag = *parselist++; + } + else { + double_flag = GL_TRUE; + } + break; + case GLX_STEREO: + parselist++; + if (fbConfig) { + stereo_flag = *parselist++; + } + else { + stereo_flag = GL_TRUE; + } + break; + case GLX_AUX_BUFFERS: + parselist++; + numAux = *parselist++; + if (numAux > MAX_AUX_BUFFERS) + return NULL; + break; + case GLX_RED_SIZE: + parselist++; + min_red = *parselist++; + break; + case GLX_GREEN_SIZE: + parselist++; + min_green = *parselist++; + break; + case GLX_BLUE_SIZE: + parselist++; + min_blue = *parselist++; + break; + case GLX_ALPHA_SIZE: + parselist++; + { + GLint size = *parselist++; + alpha_flag = size ? GL_TRUE : GL_FALSE; + } + break; + case GLX_DEPTH_SIZE: + parselist++; + depth_size = *parselist++; + break; + case GLX_STENCIL_SIZE: + parselist++; + stencil_size = *parselist++; + break; + case GLX_ACCUM_RED_SIZE: + parselist++; + { + GLint size = *parselist++; + accumRedSize = MAX2( accumRedSize, size ); + } + break; + case GLX_ACCUM_GREEN_SIZE: + parselist++; + { + GLint size = *parselist++; + accumGreenSize = MAX2( accumGreenSize, size ); + } + break; + case GLX_ACCUM_BLUE_SIZE: + parselist++; + { + GLint size = *parselist++; + accumBlueSize = MAX2( accumBlueSize, size ); + } + break; + case GLX_ACCUM_ALPHA_SIZE: + parselist++; + { + GLint size = *parselist++; + accumAlphaSize = MAX2( accumAlphaSize, size ); + } + break; + + /* + * GLX_EXT_visual_info extension + */ + case GLX_X_VISUAL_TYPE_EXT: + parselist++; + visual_type = *parselist++; + break; + case GLX_TRANSPARENT_TYPE_EXT: + parselist++; + trans_type = *parselist++; + break; + case GLX_TRANSPARENT_INDEX_VALUE_EXT: + parselist++; + trans_value = *parselist++; + break; + case GLX_TRANSPARENT_RED_VALUE_EXT: + case GLX_TRANSPARENT_GREEN_VALUE_EXT: + case GLX_TRANSPARENT_BLUE_VALUE_EXT: + case GLX_TRANSPARENT_ALPHA_VALUE_EXT: + /* ignore */ + parselist++; + parselist++; + break; + + /* + * GLX_EXT_visual_info extension + */ + case GLX_VISUAL_CAVEAT_EXT: + parselist++; + caveat = *parselist++; /* ignored for now */ + break; + + /* + * GLX_ARB_multisample + */ + case GLX_SAMPLE_BUFFERS_ARB: + /* ms not supported */ + return NULL; + case GLX_SAMPLES_ARB: + /* ms not supported */ + return NULL; + + /* + * FBConfig attribs. + */ + case GLX_RENDER_TYPE: + if (!fbConfig) + return NULL; + parselist++; + if (*parselist & GLX_RGBA_BIT) { + rgb_flag = GL_TRUE; + } + else if (*parselist & GLX_COLOR_INDEX_BIT) { + rgb_flag = GL_FALSE; + } + else if (*parselist == 0) { + rgb_flag = GL_TRUE; + } + parselist++; + break; + case GLX_DRAWABLE_TYPE: + if (!fbConfig) + return NULL; + parselist++; + if (*parselist & ~(GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT)) { + return NULL; /* bad bit */ + } + parselist++; + break; + case GLX_FBCONFIG_ID: + if (!fbConfig) + return NULL; + parselist++; + desiredVisualID = *parselist++; + break; + case GLX_X_RENDERABLE: + if (!fbConfig) + return NULL; + parselist += 2; + /* ignore */ + break; + +#ifdef GLX_EXT_texture_from_pixmap + case GLX_BIND_TO_TEXTURE_RGB_EXT: + parselist++; /*skip*/ + break; + case GLX_BIND_TO_TEXTURE_RGBA_EXT: + parselist++; /*skip*/ + break; + case GLX_BIND_TO_MIPMAP_TEXTURE_EXT: + parselist++; /*skip*/ + break; + case GLX_BIND_TO_TEXTURE_TARGETS_EXT: + parselist++; + if (*parselist & ~(GLX_TEXTURE_1D_BIT_EXT | + GLX_TEXTURE_2D_BIT_EXT | + GLX_TEXTURE_RECTANGLE_BIT_EXT)) { + /* invalid bit */ + return NULL; + } + break; + case GLX_Y_INVERTED_EXT: + parselist++; /*skip*/ + break; +#endif + + case None: + /* end of list */ + break; + + default: + /* undefined attribute */ + _mesa_warning(NULL, "unexpected attrib 0x%x in choose_visual()", + *parselist); + return NULL; + } + } + + (void) caveat; + + + /* + * Since we're only simulating the GLX extension this function will never + * find any real GL visuals. Instead, all we can do is try to find an RGB + * or CI visual of appropriate depth. Other requested attributes such as + * double buffering, depth buffer, etc. will be associated with the X + * visual and stored in the VisualTable[]. + */ + if (desiredVisualID != -1) { + /* try to get a specific visual, by visualID */ + XVisualInfo temp; + int n; + temp.visualid = desiredVisualID; + temp.screen = screen; + vis = XGetVisualInfo(dpy, VisualIDMask | VisualScreenMask, &temp, &n); + if (vis) { + /* give the visual some useful GLX attributes */ + double_flag = GL_TRUE; + rgb_flag = GL_TRUE; + } + } + else if (level==0) { + /* normal color planes */ + /* Get an RGB visual */ + int min_rgb = min_red + min_green + min_blue; + if (min_rgb>1 && min_rgb<8) { + /* a special case to be sure we can get a monochrome visual */ + min_rgb = 1; + } + vis = choose_x_visual( dpy, screen, min_rgb, visual_type ); + } + else { + _mesa_warning(NULL, "overlay not supported"); + return NULL; + } + + if (vis) { + /* Note: we're not exactly obeying the glXChooseVisual rules here. + * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the + * largest depth buffer size, which is 32bits/value. Instead, we + * return 16 to maintain performance with earlier versions of Mesa. + */ + if (stencil_size > 0) + depth_size = 24; /* if Z and stencil, always use 24+8 format */ + else if (depth_size > 24) + depth_size = 32; + else if (depth_size > 16) + depth_size = 24; + else if (depth_size > 0) { + depth_size = default_depth_bits(); + } + + if (!alpha_flag) { + alpha_flag = default_alpha_bits() > 0; + } + + /* we only support one size of stencil and accum buffers. */ + if (stencil_size > 0) + stencil_size = STENCIL_BITS; + + if (accumRedSize > 0 || + accumGreenSize > 0 || + accumBlueSize > 0 || + accumAlphaSize > 0) { + + accumRedSize = + accumGreenSize = + accumBlueSize = default_accum_bits(); + + accumAlphaSize = alpha_flag ? accumRedSize : 0; + } + + xmvis = save_glx_visual( dpy, vis, rgb_flag, alpha_flag, double_flag, + stereo_flag, depth_size, stencil_size, + accumRedSize, accumGreenSize, + accumBlueSize, accumAlphaSize, level, numAux ); + } + + return xmvis; +} + + +PUBLIC XVisualInfo * +glXChooseVisual( Display *dpy, int screen, int *list ) +{ + XMesaVisual xmvis; + + /* register ourselves as an extension on this display */ + register_with_display(dpy); + + xmvis = choose_visual(dpy, screen, list, GL_FALSE); + if (xmvis) { + /* create a new vishandle - the cached one may be stale */ + xmvis->vishandle = (XVisualInfo *) malloc(sizeof(XVisualInfo)); + if (xmvis->vishandle) { + memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo)); + } + return xmvis->vishandle; + } + else + return NULL; +} + + +PUBLIC GLXContext +glXCreateContext( Display *dpy, XVisualInfo *visinfo, + GLXContext share_list, Bool direct ) +{ + XMesaVisual xmvis; + GLXContext glxCtx; + GLXContext shareCtx = share_list; + + if (!dpy || !visinfo) + return 0; + + glxCtx = CALLOC_STRUCT(__GLXcontextRec); + if (!glxCtx) + return 0; + + /* deallocate unused windows/buffers */ +#if 0 + XMesaGarbageCollect(); +#endif + + xmvis = find_glx_visual( dpy, visinfo ); + if (!xmvis) { + /* This visual wasn't found with glXChooseVisual() */ + xmvis = create_glx_visual( dpy, visinfo ); + if (!xmvis) { + /* unusable visual */ + free(glxCtx); + return NULL; + } + } + + glxCtx->xmesaContext = XMesaCreateContext(xmvis, + shareCtx ? shareCtx->xmesaContext : NULL); + if (!glxCtx->xmesaContext) { + free(glxCtx); + return NULL; + } + + glxCtx->isDirect = DEFAULT_DIRECT; + glxCtx->currentDpy = dpy; + glxCtx->xid = (XID) glxCtx; /* self pointer */ + + return glxCtx; +} + + +/* XXX these may have to be removed due to thread-safety issues. */ +static GLXContext MakeCurrent_PrevContext = 0; +static GLXDrawable MakeCurrent_PrevDrawable = 0; +static GLXDrawable MakeCurrent_PrevReadable = 0; +static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0; +static XMesaBuffer MakeCurrent_PrevReadBuffer = 0; + + +/* GLX 1.3 and later */ +PUBLIC Bool +glXMakeContextCurrent( Display *dpy, GLXDrawable draw, + GLXDrawable read, GLXContext ctx ) +{ + GLXContext glxCtx = ctx; + static boolean firsttime = 1, no_rast = 0; + + if (firsttime) { + no_rast = getenv("SP_NO_RAST") != NULL; + firsttime = 0; + } + + if (ctx && draw && read) { + XMesaBuffer drawBuffer, readBuffer; + XMesaContext xmctx = glxCtx->xmesaContext; + + /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */ + if (ctx == MakeCurrent_PrevContext + && draw == MakeCurrent_PrevDrawable) { + drawBuffer = MakeCurrent_PrevDrawBuffer; + } + else { + drawBuffer = XMesaFindBuffer( dpy, draw ); + } + if (!drawBuffer) { + /* drawable must be a new window! */ + drawBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, draw ); + if (!drawBuffer) { + /* Out of memory, or context/drawable depth mismatch */ + return False; + } + } + + /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */ + if (ctx == MakeCurrent_PrevContext + && read == MakeCurrent_PrevReadable) { + readBuffer = MakeCurrent_PrevReadBuffer; + } + else { + readBuffer = XMesaFindBuffer( dpy, read ); + } + if (!readBuffer) { + /* drawable must be a new window! */ + readBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, read ); + if (!readBuffer) { + /* Out of memory, or context/drawable depth mismatch */ + return False; + } + } + + if (no_rast && + MakeCurrent_PrevContext == ctx && + MakeCurrent_PrevDrawable == draw && + MakeCurrent_PrevReadable == read && + MakeCurrent_PrevDrawBuffer == drawBuffer && + MakeCurrent_PrevReadBuffer == readBuffer) + return True; + + MakeCurrent_PrevContext = ctx; + MakeCurrent_PrevDrawable = draw; + MakeCurrent_PrevReadable = read; + MakeCurrent_PrevDrawBuffer = drawBuffer; + MakeCurrent_PrevReadBuffer = readBuffer; + + /* Now make current! */ + if (XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer)) { + ctx->currentDpy = dpy; + ctx->currentDrawable = draw; + ctx->currentReadable = read; + SetCurrentContext(ctx); + return True; + } + else { + return False; + } + } + else if (!ctx && !draw && !read) { + /* release current context w/out assigning new one. */ + XMesaMakeCurrent2( NULL, NULL, NULL ); + MakeCurrent_PrevContext = 0; + MakeCurrent_PrevDrawable = 0; + MakeCurrent_PrevReadable = 0; + MakeCurrent_PrevDrawBuffer = 0; + MakeCurrent_PrevReadBuffer = 0; + SetCurrentContext(NULL); + return True; + } + else { + /* The args must either all be non-zero or all zero. + * This is an error. + */ + return False; + } +} + + +PUBLIC Bool +glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx ) +{ + return glXMakeContextCurrent( dpy, drawable, drawable, ctx ); +} + + +PUBLIC GLXContext +glXGetCurrentContext(void) +{ + return GetCurrentContext(); +} + + +PUBLIC Display * +glXGetCurrentDisplay(void) +{ + GLXContext glxCtx = glXGetCurrentContext(); + + return glxCtx ? glxCtx->currentDpy : NULL; +} + + +PUBLIC Display * +glXGetCurrentDisplayEXT(void) +{ + return glXGetCurrentDisplay(); +} + + +PUBLIC GLXDrawable +glXGetCurrentDrawable(void) +{ + GLXContext gc = glXGetCurrentContext(); + return gc ? gc->currentDrawable : 0; +} + + +PUBLIC GLXDrawable +glXGetCurrentReadDrawable(void) +{ + GLXContext gc = glXGetCurrentContext(); + return gc ? gc->currentReadable : 0; +} + + +PUBLIC GLXDrawable +glXGetCurrentReadDrawableSGI(void) +{ + return glXGetCurrentReadDrawable(); +} + + +PUBLIC GLXPixmap +glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap ) +{ + XMesaVisual v; + XMesaBuffer b; + + v = find_glx_visual( dpy, visinfo ); + if (!v) { + v = create_glx_visual( dpy, visinfo ); + if (!v) { + /* unusable visual */ + return 0; + } + } + + b = XMesaCreatePixmapBuffer( v, pixmap, 0 ); + if (!b) { + return 0; + } + return b->drawable; +} + + +/*** GLX_MESA_pixmap_colormap ***/ + +PUBLIC GLXPixmap +glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo, + Pixmap pixmap, Colormap cmap ) +{ + XMesaVisual v; + XMesaBuffer b; + + v = find_glx_visual( dpy, visinfo ); + if (!v) { + v = create_glx_visual( dpy, visinfo ); + if (!v) { + /* unusable visual */ + return 0; + } + } + + b = XMesaCreatePixmapBuffer( v, pixmap, cmap ); + if (!b) { + return 0; + } + return b->drawable; +} + + +PUBLIC void +glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap ) +{ + XMesaBuffer b = XMesaFindBuffer(dpy, pixmap); + if (b) { + XMesaDestroyBuffer(b); + } + else if (_mesa_getenv("MESA_DEBUG")) { + _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n"); + } +} + + +PUBLIC void +glXCopyContext( Display *dpy, GLXContext src, GLXContext dst, + unsigned long mask ) +{ + XMesaContext xm_src = src->xmesaContext; + XMesaContext xm_dst = dst->xmesaContext; + (void) dpy; + if (MakeCurrent_PrevContext == src) { + glFlush(); + } + XMesaCopyContext(xm_src, xm_dst, mask); +} + + +PUBLIC Bool +glXQueryExtension( Display *dpy, int *errorBase, int *eventBase ) +{ + int op, ev, err; + /* Mesa's GLX isn't really an X extension but we try to act like one. */ + if (!XQueryExtension(dpy, GLX_EXTENSION_NAME, &op, &ev, &err)) + ev = err = 0; + if (errorBase) + *errorBase = err; + if (eventBase) + *eventBase = ev; + return True; /* we're faking GLX so always return success */ +} + + +PUBLIC void +glXDestroyContext( Display *dpy, GLXContext ctx ) +{ + GLXContext glxCtx = ctx; + (void) dpy; + MakeCurrent_PrevContext = 0; + MakeCurrent_PrevDrawable = 0; + MakeCurrent_PrevReadable = 0; + MakeCurrent_PrevDrawBuffer = 0; + MakeCurrent_PrevReadBuffer = 0; + XMesaDestroyContext( glxCtx->xmesaContext ); + XMesaGarbageCollect(); + free(glxCtx); +} + + +PUBLIC Bool +glXIsDirect( Display *dpy, GLXContext ctx ) +{ + GLXContext glxCtx = ctx; + (void) ctx; + return glxCtx->isDirect; +} + + + +PUBLIC void +glXSwapBuffers( Display *dpy, GLXDrawable drawable ) +{ + XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable ); + static boolean firsttime = 1, no_rast = 0; + + if (firsttime) { + no_rast = getenv("SP_NO_RAST") != NULL; + firsttime = 0; + } + + if (no_rast) + return; + + if (buffer) { + XMesaSwapBuffers(buffer); + } + else if (_mesa_getenv("MESA_DEBUG")) { + _mesa_warning(NULL, "glXSwapBuffers: invalid drawable 0x%x\n", + (int) drawable); + } +} + + + +/*** GLX_MESA_copy_sub_buffer ***/ + +PUBLIC void +glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable, + int x, int y, int width, int height ) +{ + XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable ); + if (buffer) { + XMesaCopySubBuffer(buffer, x, y, width, height); + } + else if (_mesa_getenv("MESA_DEBUG")) { + _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n"); + } +} + + +PUBLIC Bool +glXQueryVersion( Display *dpy, int *maj, int *min ) +{ + (void) dpy; + /* Return GLX version, not Mesa version */ + assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION); + *maj = CLIENT_MAJOR_VERSION; + *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION ); + return True; +} + + +/* + * Query the GLX attributes of the given XVisualInfo. + */ +static int +get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig ) +{ + ASSERT(xmvis); + switch(attrib) { + case GLX_USE_GL: + if (fbconfig) + return GLX_BAD_ATTRIBUTE; + *value = (int) True; + return 0; + case GLX_BUFFER_SIZE: + *value = xmvis->visinfo->depth; + return 0; + case GLX_LEVEL: + *value = xmvis->mesa_visual.level; + return 0; + case GLX_RGBA: + if (fbconfig) + return GLX_BAD_ATTRIBUTE; + if (xmvis->mesa_visual.rgbMode) { + *value = True; + } + else { + *value = False; + } + return 0; + case GLX_DOUBLEBUFFER: + *value = (int) xmvis->mesa_visual.doubleBufferMode; + return 0; + case GLX_STEREO: + *value = (int) xmvis->mesa_visual.stereoMode; + return 0; + case GLX_AUX_BUFFERS: + *value = xmvis->mesa_visual.numAuxBuffers; + return 0; + case GLX_RED_SIZE: + *value = xmvis->mesa_visual.redBits; + return 0; + case GLX_GREEN_SIZE: + *value = xmvis->mesa_visual.greenBits; + return 0; + case GLX_BLUE_SIZE: + *value = xmvis->mesa_visual.blueBits; + return 0; + case GLX_ALPHA_SIZE: + *value = xmvis->mesa_visual.alphaBits; + return 0; + case GLX_DEPTH_SIZE: + *value = xmvis->mesa_visual.depthBits; + return 0; + case GLX_STENCIL_SIZE: + *value = xmvis->mesa_visual.stencilBits; + return 0; + case GLX_ACCUM_RED_SIZE: + *value = xmvis->mesa_visual.accumRedBits; + return 0; + case GLX_ACCUM_GREEN_SIZE: + *value = xmvis->mesa_visual.accumGreenBits; + return 0; + case GLX_ACCUM_BLUE_SIZE: + *value = xmvis->mesa_visual.accumBlueBits; + return 0; + case GLX_ACCUM_ALPHA_SIZE: + *value = xmvis->mesa_visual.accumAlphaBits; + return 0; + + /* + * GLX_EXT_visual_info extension + */ + case GLX_X_VISUAL_TYPE_EXT: + switch (xmvis->visinfo->CLASS) { + case StaticGray: *value = GLX_STATIC_GRAY_EXT; return 0; + case GrayScale: *value = GLX_GRAY_SCALE_EXT; return 0; + case StaticColor: *value = GLX_STATIC_GRAY_EXT; return 0; + case PseudoColor: *value = GLX_PSEUDO_COLOR_EXT; return 0; + case TrueColor: *value = GLX_TRUE_COLOR_EXT; return 0; + case DirectColor: *value = GLX_DIRECT_COLOR_EXT; return 0; + } + return 0; + case GLX_TRANSPARENT_TYPE_EXT: + /* normal planes */ + *value = GLX_NONE_EXT; + return 0; + case GLX_TRANSPARENT_INDEX_VALUE_EXT: + /* undefined */ + return 0; + case GLX_TRANSPARENT_RED_VALUE_EXT: + /* undefined */ + return 0; + case GLX_TRANSPARENT_GREEN_VALUE_EXT: + /* undefined */ + return 0; + case GLX_TRANSPARENT_BLUE_VALUE_EXT: + /* undefined */ + return 0; + case GLX_TRANSPARENT_ALPHA_VALUE_EXT: + /* undefined */ + return 0; + + /* + * GLX_EXT_visual_info extension + */ + case GLX_VISUAL_CAVEAT_EXT: + /* test for zero, just in case */ + if (xmvis->mesa_visual.visualRating > 0) + *value = xmvis->mesa_visual.visualRating; + else + *value = GLX_NONE_EXT; + return 0; + + /* + * GLX_ARB_multisample + */ + case GLX_SAMPLE_BUFFERS_ARB: + *value = 0; + return 0; + case GLX_SAMPLES_ARB: + *value = 0; + return 0; + + /* + * For FBConfigs: + */ + case GLX_SCREEN_EXT: + if (!fbconfig) + return GLX_BAD_ATTRIBUTE; + *value = xmvis->visinfo->screen; + break; + case GLX_DRAWABLE_TYPE: /*SGIX too */ + if (!fbconfig) + return GLX_BAD_ATTRIBUTE; + *value = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT; + break; + case GLX_RENDER_TYPE_SGIX: + if (!fbconfig) + return GLX_BAD_ATTRIBUTE; + if (xmvis->mesa_visual.rgbMode) + *value = GLX_RGBA_BIT; + else + *value = GLX_COLOR_INDEX_BIT; + break; + case GLX_X_RENDERABLE_SGIX: + if (!fbconfig) + return GLX_BAD_ATTRIBUTE; + *value = True; /* XXX really? */ + break; + case GLX_FBCONFIG_ID_SGIX: + if (!fbconfig) + return GLX_BAD_ATTRIBUTE; + *value = xmvis->visinfo->visualid; + break; + case GLX_MAX_PBUFFER_WIDTH: + if (!fbconfig) + return GLX_BAD_ATTRIBUTE; + /* XXX or MAX_WIDTH? */ + *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen); + break; + case GLX_MAX_PBUFFER_HEIGHT: + if (!fbconfig) + return GLX_BAD_ATTRIBUTE; + *value = DisplayHeight(xmvis->display, xmvis->visinfo->screen); + break; + case GLX_MAX_PBUFFER_PIXELS: + if (!fbconfig) + return GLX_BAD_ATTRIBUTE; + *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen) * + DisplayHeight(xmvis->display, xmvis->visinfo->screen); + break; + case GLX_VISUAL_ID: + if (!fbconfig) + return GLX_BAD_ATTRIBUTE; + *value = xmvis->visinfo->visualid; + break; + +#ifdef GLX_EXT_texture_from_pixmap + case GLX_BIND_TO_TEXTURE_RGB_EXT: + *value = True; /*XXX*/ + break; + case GLX_BIND_TO_TEXTURE_RGBA_EXT: + /* XXX review */ + *value = xmvis->mesa_visual.alphaBits > 0 ? True : False; + break; + case GLX_BIND_TO_MIPMAP_TEXTURE_EXT: + *value = True; /*XXX*/ + break; + case GLX_BIND_TO_TEXTURE_TARGETS_EXT: + *value = (GLX_TEXTURE_1D_BIT_EXT | + GLX_TEXTURE_2D_BIT_EXT | + GLX_TEXTURE_RECTANGLE_BIT_EXT); /*XXX*/ + break; + case GLX_Y_INVERTED_EXT: + *value = True; /*XXX*/ + break; +#endif + + default: + return GLX_BAD_ATTRIBUTE; + } + return Success; +} + + +PUBLIC int +glXGetConfig( Display *dpy, XVisualInfo *visinfo, + int attrib, int *value ) +{ + XMesaVisual xmvis; + int k; + if (!dpy || !visinfo) + return GLX_BAD_ATTRIBUTE; + + xmvis = find_glx_visual( dpy, visinfo ); + if (!xmvis) { + /* this visual wasn't obtained with glXChooseVisual */ + xmvis = create_glx_visual( dpy, visinfo ); + if (!xmvis) { + /* this visual can't be used for GL rendering */ + if (attrib==GLX_USE_GL) { + *value = (int) False; + return 0; + } + else { + return GLX_BAD_VISUAL; + } + } + } + + k = get_config(xmvis, attrib, value, GL_FALSE); + return k; +} + + +PUBLIC void +glXWaitGL( void ) +{ + XMesaContext xmesa = XMesaGetCurrentContext(); + XMesaFlush( xmesa ); +} + + + +PUBLIC void +glXWaitX( void ) +{ + XMesaContext xmesa = XMesaGetCurrentContext(); + XMesaFlush( xmesa ); +} + + +static const char * +get_extensions( void ) +{ + return EXTENSIONS; +} + + + +/* GLX 1.1 and later */ +PUBLIC const char * +glXQueryExtensionsString( Display *dpy, int screen ) +{ + (void) dpy; + (void) screen; + return get_extensions(); +} + + + +/* GLX 1.1 and later */ +PUBLIC const char * +glXQueryServerString( Display *dpy, int screen, int name ) +{ + static char version[1000]; + sprintf(version, "%d.%d %s", + SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, xmesa_get_name()); + + (void) dpy; + (void) screen; + + switch (name) { + case GLX_EXTENSIONS: + return get_extensions(); + case GLX_VENDOR: + return VENDOR; + case GLX_VERSION: + return version; + default: + return NULL; + } +} + + + +/* GLX 1.1 and later */ +PUBLIC const char * +glXGetClientString( Display *dpy, int name ) +{ + static char version[1000]; + sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION, + CLIENT_MINOR_VERSION, xmesa_get_name()); + + (void) dpy; + + switch (name) { + case GLX_EXTENSIONS: + return get_extensions(); + case GLX_VENDOR: + return VENDOR; + case GLX_VERSION: + return version; + default: + return NULL; + } +} + + + +/* + * GLX 1.3 and later + */ + + +PUBLIC int +glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config, + int attribute, int *value ) +{ + XMesaVisual v = (XMesaVisual) config; + (void) dpy; + (void) config; + + if (!dpy || !config || !value) + return -1; + + return get_config(v, attribute, value, GL_TRUE); +} + + +PUBLIC GLXFBConfig * +glXGetFBConfigs( Display *dpy, int screen, int *nelements ) +{ + XVisualInfo *visuals, visTemplate; + const long visMask = VisualScreenMask; + int i; + + /* Get list of all X visuals */ + visTemplate.screen = screen; + visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements); + if (*nelements > 0) { + XMesaVisual *results; + results = (XMesaVisual *) malloc(*nelements * sizeof(XMesaVisual)); + if (!results) { + *nelements = 0; + return NULL; + } + for (i = 0; i < *nelements; i++) { + results[i] = create_glx_visual(dpy, visuals + i); + if (!results[i]) { + *nelements = i; + break; + } + } + return (GLXFBConfig *) results; + } + return NULL; +} + + +PUBLIC GLXFBConfig * +glXChooseFBConfig( Display *dpy, int screen, + const int *attribList, int *nitems ) +{ + XMesaVisual xmvis; + + if (!attribList || !attribList[0]) { + /* return list of all configs (per GLX_SGIX_fbconfig spec) */ + return glXGetFBConfigs(dpy, screen, nitems); + } + + xmvis = choose_visual(dpy, screen, attribList, GL_TRUE); + if (xmvis) { + GLXFBConfig *config = (GLXFBConfig *) malloc(sizeof(XMesaVisual)); + if (!config) { + *nitems = 0; + return NULL; + } + *nitems = 1; + config[0] = (GLXFBConfig) xmvis; + return (GLXFBConfig *) config; + } + else { + *nitems = 0; + return NULL; + } +} + + +PUBLIC XVisualInfo * +glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config ) +{ + if (dpy && config) { + XMesaVisual xmvis = (XMesaVisual) config; +#if 0 + return xmvis->vishandle; +#else + /* create a new vishandle - the cached one may be stale */ + xmvis->vishandle = (XVisualInfo *) malloc(sizeof(XVisualInfo)); + if (xmvis->vishandle) { + memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo)); + } + return xmvis->vishandle; +#endif + } + else { + return NULL; + } +} + + +PUBLIC GLXWindow +glXCreateWindow( Display *dpy, GLXFBConfig config, Window win, + const int *attribList ) +{ + XMesaVisual xmvis = (XMesaVisual) config; + XMesaBuffer xmbuf; + if (!xmvis) + return 0; + + xmbuf = XMesaCreateWindowBuffer(xmvis, win); + if (!xmbuf) + return 0; + + (void) dpy; + (void) attribList; /* Ignored in GLX 1.3 */ + + return win; /* A hack for now */ +} + + +PUBLIC void +glXDestroyWindow( Display *dpy, GLXWindow window ) +{ + XMesaBuffer b = XMesaFindBuffer(dpy, (Drawable) window); + if (b) + XMesaDestroyBuffer(b); + /* don't destroy X window */ +} + + +/* XXX untested */ +PUBLIC GLXPixmap +glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap, + const int *attribList ) +{ + XMesaVisual v = (XMesaVisual) config; + XMesaBuffer b; + const int *attr; + int target = 0, format = 0, mipmap = 0; + int value; + + if (!dpy || !config || !pixmap) + return 0; + + for (attr = attribList; attr && *attr; attr++) { + switch (*attr) { + case GLX_TEXTURE_FORMAT_EXT: + attr++; + switch (*attr) { + case GLX_TEXTURE_FORMAT_NONE_EXT: + case GLX_TEXTURE_FORMAT_RGB_EXT: + case GLX_TEXTURE_FORMAT_RGBA_EXT: + format = *attr; + break; + default: + /* error */ + return 0; + } + break; + case GLX_TEXTURE_TARGET_EXT: + attr++; + switch (*attr) { + case GLX_TEXTURE_1D_EXT: + case GLX_TEXTURE_2D_EXT: + case GLX_TEXTURE_RECTANGLE_EXT: + target = *attr; + break; + default: + /* error */ + return 0; + } + break; + case GLX_MIPMAP_TEXTURE_EXT: + attr++; + if (*attr) + mipmap = 1; + break; + default: + /* error */ + return 0; + } + } + + if (format == GLX_TEXTURE_FORMAT_RGB_EXT) { + if (get_config(v, GLX_BIND_TO_TEXTURE_RGB_EXT, + &value, GL_TRUE) != Success + || !value) { + return 0; /* error! */ + } + } + else if (format == GLX_TEXTURE_FORMAT_RGBA_EXT) { + if (get_config(v, GLX_BIND_TO_TEXTURE_RGBA_EXT, + &value, GL_TRUE) != Success + || !value) { + return 0; /* error! */ + } + } + if (mipmap) { + if (get_config(v, GLX_BIND_TO_MIPMAP_TEXTURE_EXT, + &value, GL_TRUE) != Success + || !value) { + return 0; /* error! */ + } + } + if (target == GLX_TEXTURE_1D_EXT) { + if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT, + &value, GL_TRUE) != Success + || (value & GLX_TEXTURE_1D_BIT_EXT) == 0) { + return 0; /* error! */ + } + } + else if (target == GLX_TEXTURE_2D_EXT) { + if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT, + &value, GL_TRUE) != Success + || (value & GLX_TEXTURE_2D_BIT_EXT) == 0) { + return 0; /* error! */ + } + } + if (target == GLX_TEXTURE_RECTANGLE_EXT) { + if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT, + &value, GL_TRUE) != Success + || (value & GLX_TEXTURE_RECTANGLE_BIT_EXT) == 0) { + return 0; /* error! */ + } + } + + if (format || target || mipmap) { + /* texture from pixmap */ + b = XMesaCreatePixmapTextureBuffer(v, pixmap, 0, format, target, mipmap); + } + else { + b = XMesaCreatePixmapBuffer( v, pixmap, 0 ); + } + if (!b) { + return 0; + } + + return pixmap; +} + + +PUBLIC void +glXDestroyPixmap( Display *dpy, GLXPixmap pixmap ) +{ + XMesaBuffer b = XMesaFindBuffer(dpy, (Drawable)pixmap); + if (b) + XMesaDestroyBuffer(b); + /* don't destroy X pixmap */ +} + + +PUBLIC GLXPbuffer +glXCreatePbuffer( Display *dpy, GLXFBConfig config, + const int *attribList ) +{ + XMesaVisual xmvis = (XMesaVisual) config; + XMesaBuffer xmbuf; + const int *attrib; + int width = 0, height = 0; + GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE; + + (void) dpy; + + for (attrib = attribList; *attrib; attrib++) { + switch (*attrib) { + case GLX_PBUFFER_WIDTH: + attrib++; + width = *attrib; + break; + case GLX_PBUFFER_HEIGHT: + attrib++; + height = *attrib; + break; + case GLX_PRESERVED_CONTENTS: + attrib++; + preserveContents = *attrib; + break; + case GLX_LARGEST_PBUFFER: + attrib++; + useLargest = *attrib; + break; + default: + return 0; + } + } + + if (width == 0 || height == 0) + return 0; + + if (width > MAX_WIDTH || height > MAX_HEIGHT) { + /* If allocation would have failed and GLX_LARGEST_PBUFFER is set, + * allocate the largest possible buffer. + */ + if (useLargest) { + width = MAX_WIDTH; + height = MAX_HEIGHT; + } + } + + xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height); + /* A GLXPbuffer handle must be an X Drawable because that's what + * glXMakeCurrent takes. + */ + if (xmbuf) { + xmbuf->largestPbuffer = useLargest; + xmbuf->preservedContents = preserveContents; + return (GLXPbuffer) xmbuf->drawable; + } + else { + return 0; + } +} + + +PUBLIC void +glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf ) +{ + XMesaBuffer b = XMesaFindBuffer(dpy, pbuf); + if (b) { + XMesaDestroyBuffer(b); + } +} + + +PUBLIC void +glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute, + unsigned int *value ) +{ + GLuint width, height; + XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw); + if (!xmbuf) + return; + + /* make sure buffer's dimensions are up to date */ + xmesa_get_window_size(dpy, xmbuf, &width, &height); + + switch (attribute) { + case GLX_WIDTH: + *value = width; + break; + case GLX_HEIGHT: + *value = height; + break; + case GLX_PRESERVED_CONTENTS: + *value = xmbuf->preservedContents; + break; + case GLX_LARGEST_PBUFFER: + *value = xmbuf->largestPbuffer; + break; + case GLX_FBCONFIG_ID: + *value = xmbuf->xm_visual->visinfo->visualid; + return; +#ifdef GLX_EXT_texture_from_pixmap + case GLX_TEXTURE_FORMAT_EXT: + *value = xmbuf->TextureFormat; + break; + case GLX_TEXTURE_TARGET_EXT: + *value = xmbuf->TextureTarget; + break; + case GLX_MIPMAP_TEXTURE_EXT: + *value = xmbuf->TextureMipmap; + break; +#endif + + default: + return; /* raise BadValue error */ + } +} + + +PUBLIC GLXContext +glXCreateNewContext( Display *dpy, GLXFBConfig config, + int renderType, GLXContext shareList, Bool direct ) +{ + GLXContext glxCtx; + GLXContext shareCtx = shareList; + XMesaVisual xmvis = (XMesaVisual) config; + + if (!dpy || !config || + (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE)) + return 0; + + glxCtx = CALLOC_STRUCT(__GLXcontextRec); + if (!glxCtx) + return 0; + + /* deallocate unused windows/buffers */ + XMesaGarbageCollect(); + + glxCtx->xmesaContext = XMesaCreateContext(xmvis, + shareCtx ? shareCtx->xmesaContext : NULL); + if (!glxCtx->xmesaContext) { + free(glxCtx); + return NULL; + } + + glxCtx->isDirect = DEFAULT_DIRECT; + glxCtx->currentDpy = dpy; + glxCtx->xid = (XID) glxCtx; /* self pointer */ + + return glxCtx; +} + + +PUBLIC int +glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value ) +{ + GLXContext glxCtx = ctx; + XMesaContext xmctx = glxCtx->xmesaContext; + + (void) dpy; + (void) ctx; + + switch (attribute) { + case GLX_FBCONFIG_ID: + *value = xmctx->xm_visual->visinfo->visualid; + break; + case GLX_RENDER_TYPE: + if (xmctx->xm_visual->mesa_visual.rgbMode) + *value = GLX_RGBA_TYPE; + else + *value = GLX_COLOR_INDEX_TYPE; + break; + case GLX_SCREEN: + *value = 0; + return Success; + default: + return GLX_BAD_ATTRIBUTE; + } + return 0; +} + + +PUBLIC void +glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask ) +{ + XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable); + if (xmbuf) + xmbuf->selectedEvents = mask; +} + + +PUBLIC void +glXGetSelectedEvent( Display *dpy, GLXDrawable drawable, + unsigned long *mask ) +{ + XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable); + if (xmbuf) + *mask = xmbuf->selectedEvents; + else + *mask = 0; +} + + + +/*** GLX_SGI_swap_control ***/ + +PUBLIC int +glXSwapIntervalSGI(int interval) +{ + (void) interval; + return 0; +} + + + +/*** GLX_SGI_video_sync ***/ + +static unsigned int FrameCounter = 0; + +PUBLIC int +glXGetVideoSyncSGI(unsigned int *count) +{ + /* this is a bogus implementation */ + *count = FrameCounter++; + return 0; +} + +PUBLIC int +glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count) +{ + if (divisor <= 0 || remainder < 0) + return GLX_BAD_VALUE; + /* this is a bogus implementation */ + FrameCounter++; + while (FrameCounter % divisor != remainder) + FrameCounter++; + *count = FrameCounter; + return 0; +} + + + +/*** GLX_SGI_make_current_read ***/ + +PUBLIC Bool +glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx) +{ + return glXMakeContextCurrent( dpy, draw, read, ctx ); +} + +/* not used +static GLXDrawable +glXGetCurrentReadDrawableSGI(void) +{ + return 0; +} +*/ + + +/*** GLX_SGIX_video_source ***/ +#if defined(_VL_H) + +PUBLIC GLXVideoSourceSGIX +glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode) +{ + (void) dpy; + (void) screen; + (void) server; + (void) path; + (void) nodeClass; + (void) drainNode; + return 0; +} + +PUBLIC void +glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src) +{ + (void) dpy; + (void) src; +} + +#endif + + +/*** GLX_EXT_import_context ***/ + +PUBLIC void +glXFreeContextEXT(Display *dpy, GLXContext context) +{ + (void) dpy; + (void) context; +} + +PUBLIC GLXContextID +glXGetContextIDEXT(const GLXContext context) +{ + (void) context; + return 0; +} + +PUBLIC GLXContext +glXImportContextEXT(Display *dpy, GLXContextID contextID) +{ + (void) dpy; + (void) contextID; + return 0; +} + +PUBLIC int +glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute, int *value) +{ + (void) dpy; + (void) context; + (void) attribute; + (void) value; + return 0; +} + + + +/*** GLX_SGIX_fbconfig ***/ + +PUBLIC int +glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value) +{ + return glXGetFBConfigAttrib(dpy, config, attribute, value); +} + +PUBLIC GLXFBConfigSGIX * +glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements) +{ + return (GLXFBConfig *) glXChooseFBConfig(dpy, screen, attrib_list, nelements); +} + + +PUBLIC GLXPixmap +glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap) +{ + XMesaVisual xmvis = (XMesaVisual) config; + XMesaBuffer xmbuf = XMesaCreatePixmapBuffer(xmvis, pixmap, 0); + return xmbuf->drawable; /* need to return an X ID */ +} + + +PUBLIC GLXContext +glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct) +{ + XMesaVisual xmvis = (XMesaVisual) config; + GLXContext glxCtx; + GLXContext shareCtx = share_list; + + glxCtx = CALLOC_STRUCT(__GLXcontextRec); + if (!glxCtx) + return 0; + + /* deallocate unused windows/buffers */ + XMesaGarbageCollect(); + + glxCtx->xmesaContext = XMesaCreateContext(xmvis, + shareCtx ? shareCtx->xmesaContext : NULL); + if (!glxCtx->xmesaContext) { + free(glxCtx); + return NULL; + } + + glxCtx->isDirect = DEFAULT_DIRECT; + glxCtx->currentDpy = dpy; + glxCtx->xid = (XID) glxCtx; /* self pointer */ + + return glxCtx; +} + + +PUBLIC XVisualInfo * +glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config) +{ + return glXGetVisualFromFBConfig(dpy, config); +} + + +PUBLIC GLXFBConfigSGIX +glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis) +{ + XMesaVisual xmvis = find_glx_visual(dpy, vis); + if (!xmvis) { + /* This visual wasn't found with glXChooseVisual() */ + xmvis = create_glx_visual(dpy, vis); + } + + return (GLXFBConfigSGIX) xmvis; +} + + + +/*** GLX_SGIX_pbuffer ***/ + +PUBLIC GLXPbufferSGIX +glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config, + unsigned int width, unsigned int height, + int *attribList) +{ + XMesaVisual xmvis = (XMesaVisual) config; + XMesaBuffer xmbuf; + const int *attrib; + GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE; + + (void) dpy; + + for (attrib = attribList; attrib && *attrib; attrib++) { + switch (*attrib) { + case GLX_PRESERVED_CONTENTS_SGIX: + attrib++; + preserveContents = *attrib; /* ignored */ + break; + case GLX_LARGEST_PBUFFER_SGIX: + attrib++; + useLargest = *attrib; /* ignored */ + break; + default: + return 0; + } + } + + /* not used at this time */ + (void) useLargest; + (void) preserveContents; + + xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height); + /* A GLXPbuffer handle must be an X Drawable because that's what + * glXMakeCurrent takes. + */ + return (GLXPbuffer) xmbuf->drawable; +} + + +PUBLIC void +glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf) +{ + XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf); + if (xmbuf) { + XMesaDestroyBuffer(xmbuf); + } +} + + +PUBLIC int +glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value) +{ + const XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf); + + if (!xmbuf) { + /* Generate GLXBadPbufferSGIX for bad pbuffer */ + return 0; + } + + switch (attribute) { + case GLX_PRESERVED_CONTENTS_SGIX: + *value = True; + break; + case GLX_LARGEST_PBUFFER_SGIX: + *value = xmesa_buffer_width(xmbuf) * xmesa_buffer_height(xmbuf); + break; + case GLX_WIDTH_SGIX: + *value = xmesa_buffer_width(xmbuf); + break; + case GLX_HEIGHT_SGIX: + *value = xmesa_buffer_height(xmbuf); + break; + case GLX_EVENT_MASK_SGIX: + *value = 0; /* XXX might be wrong */ + break; + default: + *value = 0; + } + return 0; +} + + +PUBLIC void +glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask) +{ + XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable); + if (xmbuf) { + /* Note: we'll never generate clobber events */ + xmbuf->selectedEvents = mask; + } +} + + +PUBLIC void +glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask) +{ + XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable); + if (xmbuf) { + *mask = xmbuf->selectedEvents; + } + else { + *mask = 0; + } +} + + + +/*** GLX_SGI_cushion ***/ + +PUBLIC void +glXCushionSGI(Display *dpy, Window win, float cushion) +{ + (void) dpy; + (void) win; + (void) cushion; +} + + + +/*** GLX_SGIX_video_resize ***/ + +PUBLIC int +glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel , Window window) +{ + (void) dpy; + (void) screen; + (void) channel; + (void) window; + return 0; +} + +PUBLIC int +glXChannelRectSGIX(Display *dpy, int screen, int channel, int x, int y, int w, int h) +{ + (void) dpy; + (void) screen; + (void) channel; + (void) x; + (void) y; + (void) w; + (void) h; + return 0; +} + +PUBLIC int +glXQueryChannelRectSGIX(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h) +{ + (void) dpy; + (void) screen; + (void) channel; + (void) x; + (void) y; + (void) w; + (void) h; + return 0; +} + +PUBLIC int +glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh) +{ + (void) dpy; + (void) screen; + (void) channel; + (void) dx; + (void) dy; + (void) dw; + (void) dh; + return 0; +} + +PUBLIC int +glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype) +{ + (void) dpy; + (void) screen; + (void) channel; + (void) synctype; + return 0; +} + + + +/*** GLX_SGIX_dmbuffer **/ + +#if defined(_DM_BUFFER_H_) +PUBLIC Bool +glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer) +{ + (void) dpy; + (void) pbuffer; + (void) params; + (void) dmbuffer; + return False; +} +#endif + + +/*** GLX_SGIX_swap_group ***/ + +PUBLIC void +glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, GLXDrawable member) +{ + (void) dpy; + (void) drawable; + (void) member; +} + + + +/*** GLX_SGIX_swap_barrier ***/ + +PUBLIC void +glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier) +{ + (void) dpy; + (void) drawable; + (void) barrier; +} + +PUBLIC Bool +glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max) +{ + (void) dpy; + (void) screen; + (void) max; + return False; +} + + + +/*** GLX_SUN_get_transparent_index ***/ + +PUBLIC Status +glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay, long *pTransparent) +{ + (void) dpy; + (void) overlay; + (void) underlay; + (void) pTransparent; + return 0; +} + + + +/*** GLX_MESA_release_buffers ***/ + +/* + * Release the depth, stencil, accum buffers attached to a GLXDrawable + * (a window or pixmap) prior to destroying the GLXDrawable. + */ +PUBLIC Bool +glXReleaseBuffersMESA( Display *dpy, GLXDrawable d ) +{ + XMesaBuffer b = XMesaFindBuffer(dpy, d); + if (b) { + XMesaDestroyBuffer(b); + return True; + } + return False; +} + +/*** GLX_EXT_texture_from_pixmap ***/ + +PUBLIC void +glXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer, + const int *attrib_list) +{ + XMesaBuffer b = XMesaFindBuffer(dpy, drawable); + if (b) + XMesaBindTexImage(dpy, b, buffer, attrib_list); +} + +PUBLIC void +glXReleaseTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer) +{ + XMesaBuffer b = XMesaFindBuffer(dpy, drawable); + if (b) + XMesaReleaseTexImage(dpy, b, buffer); +} diff --git a/src/gallium/state_trackers/glx/xlib/glx_getproc.c b/src/gallium/state_trackers/glx/xlib/glx_getproc.c new file mode 100644 index 0000000..26fcae7 --- /dev/null +++ b/src/gallium/state_trackers/glx/xlib/glx_getproc.c @@ -0,0 +1,215 @@ +/* + * Mesa 3-D graphics library + * Version: 7.6 + * + * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (C) 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 + * 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. + */ + + +/** + * glXGetProcAddress() + */ + + +#define GLX_GLXEXT_PROTOTYPES + +#include +#include "GL/glx.h" +#include "glapi/glapi.h" + + +struct name_address_pair { + const char *Name; + __GLXextFuncPtr Address; +}; + + +static struct name_address_pair GLX_functions[] = { + /*** GLX_VERSION_1_0 ***/ + { "glXChooseVisual", (__GLXextFuncPtr) glXChooseVisual }, + { "glXCopyContext", (__GLXextFuncPtr) glXCopyContext }, + { "glXCreateContext", (__GLXextFuncPtr) glXCreateContext }, + { "glXCreateGLXPixmap", (__GLXextFuncPtr) glXCreateGLXPixmap }, + { "glXDestroyContext", (__GLXextFuncPtr) glXDestroyContext }, + { "glXDestroyGLXPixmap", (__GLXextFuncPtr) glXDestroyGLXPixmap }, + { "glXGetConfig", (__GLXextFuncPtr) glXGetConfig }, + { "glXGetCurrentContext", (__GLXextFuncPtr) glXGetCurrentContext }, + { "glXGetCurrentDrawable", (__GLXextFuncPtr) glXGetCurrentDrawable }, + { "glXIsDirect", (__GLXextFuncPtr) glXIsDirect }, + { "glXMakeCurrent", (__GLXextFuncPtr) glXMakeCurrent }, + { "glXQueryExtension", (__GLXextFuncPtr) glXQueryExtension }, + { "glXQueryVersion", (__GLXextFuncPtr) glXQueryVersion }, + { "glXSwapBuffers", (__GLXextFuncPtr) glXSwapBuffers }, + { "glXUseXFont", (__GLXextFuncPtr) glXUseXFont }, + { "glXWaitGL", (__GLXextFuncPtr) glXWaitGL }, + { "glXWaitX", (__GLXextFuncPtr) glXWaitX }, + + /*** GLX_VERSION_1_1 ***/ + { "glXGetClientString", (__GLXextFuncPtr) glXGetClientString }, + { "glXQueryExtensionsString", (__GLXextFuncPtr) glXQueryExtensionsString }, + { "glXQueryServerString", (__GLXextFuncPtr) glXQueryServerString }, + + /*** GLX_VERSION_1_2 ***/ + { "glXGetCurrentDisplay", (__GLXextFuncPtr) glXGetCurrentDisplay }, + + /*** GLX_VERSION_1_3 ***/ + { "glXChooseFBConfig", (__GLXextFuncPtr) glXChooseFBConfig }, + { "glXCreateNewContext", (__GLXextFuncPtr) glXCreateNewContext }, + { "glXCreatePbuffer", (__GLXextFuncPtr) glXCreatePbuffer }, + { "glXCreatePixmap", (__GLXextFuncPtr) glXCreatePixmap }, + { "glXCreateWindow", (__GLXextFuncPtr) glXCreateWindow }, + { "glXDestroyPbuffer", (__GLXextFuncPtr) glXDestroyPbuffer }, + { "glXDestroyPixmap", (__GLXextFuncPtr) glXDestroyPixmap }, + { "glXDestroyWindow", (__GLXextFuncPtr) glXDestroyWindow }, + { "glXGetCurrentReadDrawable", (__GLXextFuncPtr) glXGetCurrentReadDrawable }, + { "glXGetFBConfigAttrib", (__GLXextFuncPtr) glXGetFBConfigAttrib }, + { "glXGetFBConfigs", (__GLXextFuncPtr) glXGetFBConfigs }, + { "glXGetSelectedEvent", (__GLXextFuncPtr) glXGetSelectedEvent }, + { "glXGetVisualFromFBConfig", (__GLXextFuncPtr) glXGetVisualFromFBConfig }, + { "glXMakeContextCurrent", (__GLXextFuncPtr) glXMakeContextCurrent }, + { "glXQueryContext", (__GLXextFuncPtr) glXQueryContext }, + { "glXQueryDrawable", (__GLXextFuncPtr) glXQueryDrawable }, + { "glXSelectEvent", (__GLXextFuncPtr) glXSelectEvent }, + + /*** GLX_VERSION_1_4 ***/ + { "glXGetProcAddress", (__GLXextFuncPtr) glXGetProcAddress }, + + /*** GLX_SGI_swap_control ***/ + { "glXSwapIntervalSGI", (__GLXextFuncPtr) glXSwapIntervalSGI }, + + /*** GLX_SGI_video_sync ***/ + { "glXGetVideoSyncSGI", (__GLXextFuncPtr) glXGetVideoSyncSGI }, + { "glXWaitVideoSyncSGI", (__GLXextFuncPtr) glXWaitVideoSyncSGI }, + + /*** GLX_SGI_make_current_read ***/ + { "glXMakeCurrentReadSGI", (__GLXextFuncPtr) glXMakeCurrentReadSGI }, + { "glXGetCurrentReadDrawableSGI", (__GLXextFuncPtr) glXGetCurrentReadDrawableSGI }, + + /*** GLX_SGIX_video_source ***/ +#if defined(_VL_H) + { "glXCreateGLXVideoSourceSGIX", (__GLXextFuncPtr) glXCreateGLXVideoSourceSGIX }, + { "glXDestroyGLXVideoSourceSGIX", (__GLXextFuncPtr) glXDestroyGLXVideoSourceSGIX }, +#endif + + /*** GLX_EXT_import_context ***/ + { "glXFreeContextEXT", (__GLXextFuncPtr) glXFreeContextEXT }, + { "glXGetContextIDEXT", (__GLXextFuncPtr) glXGetContextIDEXT }, + { "glXGetCurrentDisplayEXT", (__GLXextFuncPtr) glXGetCurrentDisplayEXT }, + { "glXImportContextEXT", (__GLXextFuncPtr) glXImportContextEXT }, + { "glXQueryContextInfoEXT", (__GLXextFuncPtr) glXQueryContextInfoEXT }, + + /*** GLX_SGIX_fbconfig ***/ + { "glXGetFBConfigAttribSGIX", (__GLXextFuncPtr) glXGetFBConfigAttribSGIX }, + { "glXChooseFBConfigSGIX", (__GLXextFuncPtr) glXChooseFBConfigSGIX }, + { "glXCreateGLXPixmapWithConfigSGIX", (__GLXextFuncPtr) glXCreateGLXPixmapWithConfigSGIX }, + { "glXCreateContextWithConfigSGIX", (__GLXextFuncPtr) glXCreateContextWithConfigSGIX }, + { "glXGetVisualFromFBConfigSGIX", (__GLXextFuncPtr) glXGetVisualFromFBConfigSGIX }, + { "glXGetFBConfigFromVisualSGIX", (__GLXextFuncPtr) glXGetFBConfigFromVisualSGIX }, + + /*** GLX_SGIX_pbuffer ***/ + { "glXCreateGLXPbufferSGIX", (__GLXextFuncPtr) glXCreateGLXPbufferSGIX }, + { "glXDestroyGLXPbufferSGIX", (__GLXextFuncPtr) glXDestroyGLXPbufferSGIX }, + { "glXQueryGLXPbufferSGIX", (__GLXextFuncPtr) glXQueryGLXPbufferSGIX }, + { "glXSelectEventSGIX", (__GLXextFuncPtr) glXSelectEventSGIX }, + { "glXGetSelectedEventSGIX", (__GLXextFuncPtr) glXGetSelectedEventSGIX }, + + /*** GLX_SGI_cushion ***/ + { "glXCushionSGI", (__GLXextFuncPtr) glXCushionSGI }, + + /*** GLX_SGIX_video_resize ***/ + { "glXBindChannelToWindowSGIX", (__GLXextFuncPtr) glXBindChannelToWindowSGIX }, + { "glXChannelRectSGIX", (__GLXextFuncPtr) glXChannelRectSGIX }, + { "glXQueryChannelRectSGIX", (__GLXextFuncPtr) glXQueryChannelRectSGIX }, + { "glXQueryChannelDeltasSGIX", (__GLXextFuncPtr) glXQueryChannelDeltasSGIX }, + { "glXChannelRectSyncSGIX", (__GLXextFuncPtr) glXChannelRectSyncSGIX }, + + /*** GLX_SGIX_dmbuffer **/ +#if defined(_DM_BUFFER_H_) + { "glXAssociateDMPbufferSGIX", (__GLXextFuncPtr) glXAssociateDMPbufferSGIX }, +#endif + + /*** GLX_SGIX_swap_group ***/ + { "glXJoinSwapGroupSGIX", (__GLXextFuncPtr) glXJoinSwapGroupSGIX }, + + /*** GLX_SGIX_swap_barrier ***/ + { "glXBindSwapBarrierSGIX", (__GLXextFuncPtr) glXBindSwapBarrierSGIX }, + { "glXQueryMaxSwapBarriersSGIX", (__GLXextFuncPtr) glXQueryMaxSwapBarriersSGIX }, + + /*** GLX_SUN_get_transparent_index ***/ + { "glXGetTransparentIndexSUN", (__GLXextFuncPtr) glXGetTransparentIndexSUN }, + + /*** GLX_MESA_copy_sub_buffer ***/ + { "glXCopySubBufferMESA", (__GLXextFuncPtr) glXCopySubBufferMESA }, + + /*** GLX_MESA_pixmap_colormap ***/ + { "glXCreateGLXPixmapMESA", (__GLXextFuncPtr) glXCreateGLXPixmapMESA }, + + /*** GLX_MESA_release_buffers ***/ + { "glXReleaseBuffersMESA", (__GLXextFuncPtr) glXReleaseBuffersMESA }, + + /*** GLX_ARB_get_proc_address ***/ + { "glXGetProcAddressARB", (__GLXextFuncPtr) glXGetProcAddressARB }, + + /*** GLX_EXT_texture_from_pixmap ***/ + { "glXBindTexImageEXT", (__GLXextFuncPtr) glXBindTexImageEXT }, + { "glXReleaseTexImageEXT", (__GLXextFuncPtr) glXReleaseTexImageEXT }, + + { NULL, NULL } /* end of list */ +}; + + + +/** + * Return address of named glX function, or NULL if not found. + */ +static __GLXextFuncPtr +_glxapi_get_proc_address(const char *funcName) +{ + GLuint i; + for (i = 0; GLX_functions[i].Name; i++) { + if (strcmp(GLX_functions[i].Name, funcName) == 0) + return GLX_functions[i].Address; + } + return NULL; +} + + +PUBLIC __GLXextFuncPtr +glXGetProcAddressARB(const GLubyte *procName) +{ + __GLXextFuncPtr f; + + f = _glxapi_get_proc_address((const char *) procName); + if (f) { + return f; + } + + f = (__GLXextFuncPtr) _glapi_get_proc_address((const char *) procName); + return f; +} + + +/* GLX 1.4 */ +PUBLIC +void (*glXGetProcAddress(const GLubyte *procName))() +{ + return glXGetProcAddressARB(procName); +} diff --git a/src/gallium/state_trackers/glx/xlib/glx_usefont.c b/src/gallium/state_trackers/glx/xlib/glx_usefont.c new file mode 100644 index 0000000..0aa37e1 --- /dev/null +++ b/src/gallium/state_trackers/glx/xlib/glx_usefont.c @@ -0,0 +1,374 @@ +/* + * Mesa 3-D graphics library + * Version: 7.6 + * + * Copyright (C) 1995 Thorsten.Ohl @ Physik.TH-Darmstadt.de + * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (C) 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 + * 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. + */ + + +/** + * Fake implementation of glXUseXFont(). + */ + + +#include "main/core.h" +#include + + +/* Some debugging info. */ + +#ifdef DEBUG +#undef _R +#undef _G +#undef _B +#include + +int debug_xfonts = 0; + +static void +dump_char_struct(XCharStruct * ch, char *prefix) +{ + printf("%slbearing = %d, rbearing = %d, width = %d\n", + prefix, ch->lbearing, ch->rbearing, ch->width); + printf("%sascent = %d, descent = %d, attributes = %u\n", + prefix, ch->ascent, ch->descent, (unsigned int) ch->attributes); +} + +static void +dump_font_struct(XFontStruct * font) +{ + printf("ascent = %d, descent = %d\n", font->ascent, font->descent); + printf("char_or_byte2 = (%u,%u)\n", + font->min_char_or_byte2, font->max_char_or_byte2); + printf("byte1 = (%u,%u)\n", font->min_byte1, font->max_byte1); + printf("all_chars_exist = %s\n", font->all_chars_exist ? "True" : "False"); + printf("default_char = %c (\\%03o)\n", + (char) (isprint(font->default_char) ? font->default_char : ' '), + font->default_char); + dump_char_struct(&font->min_bounds, "min> "); + dump_char_struct(&font->max_bounds, "max> "); +#if 0 + for (c = font->min_char_or_byte2; c <= font->max_char_or_byte2; c++) { + char prefix[8]; + sprintf(prefix, "%d> ", c); + dump_char_struct(&font->per_char[c], prefix); + } +#endif +} + +static void +dump_bitmap(unsigned int width, unsigned int height, GLubyte * bitmap) +{ + unsigned int x, y; + + printf(" "); + for (x = 0; x < 8 * width; x++) + printf("%o", 7 - (x % 8)); + putchar('\n'); + for (y = 0; y < height; y++) { + printf("%3o:", y); + for (x = 0; x < 8 * width; x++) + putchar((bitmap[width * (height - y - 1) + x / 8] & (1 << (7 - (x % + 8)))) + ? '*' : '.'); + printf(" "); + for (x = 0; x < width; x++) + printf("0x%02x, ", bitmap[width * (height - y - 1) + x]); + putchar('\n'); + } +} +#endif /* DEBUG */ + + +/* Implementation. */ + +/* Fill a BITMAP with a character C from thew current font + in the graphics context GC. WIDTH is the width in bytes + and HEIGHT is the height in bits. + + Note that the generated bitmaps must be used with + + glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE); + glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE); + glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei (GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei (GL_UNPACK_ALIGNMENT, 1); + + Possible optimizations: + + * use only one reusable pixmap with the maximum dimensions. + * draw the entire font into a single pixmap (careful with + proportional fonts!). +*/ + + +/* + * Generate OpenGL-compatible bitmap. + */ +static void +fill_bitmap(Display * dpy, Window win, GC gc, + unsigned int width, unsigned int height, + int x0, int y0, unsigned int c, GLubyte * bitmap) +{ + XImage *image; + unsigned int x, y; + Pixmap pixmap; + XChar2b char2b; + + pixmap = XCreatePixmap(dpy, win, 8 * width, height, 1); + XSetForeground(dpy, gc, 0); + XFillRectangle(dpy, pixmap, gc, 0, 0, 8 * width, height); + XSetForeground(dpy, gc, 1); + + char2b.byte1 = (c >> 8) & 0xff; + char2b.byte2 = (c & 0xff); + + XDrawString16(dpy, pixmap, gc, x0, y0, &char2b, 1); + + image = XGetImage(dpy, pixmap, 0, 0, 8 * width, height, 1, XYPixmap); + if (image) { + /* Fill the bitmap (X11 and OpenGL are upside down wrt each other). */ + for (y = 0; y < height; y++) + for (x = 0; x < 8 * width; x++) + if (XGetPixel(image, x, y)) + bitmap[width * (height - y - 1) + x / 8] |= + (1 << (7 - (x % 8))); + XDestroyImage(image); + } + + XFreePixmap(dpy, pixmap); +} + +/* + * determine if a given glyph is valid and return the + * corresponding XCharStruct. + */ +static XCharStruct * +isvalid(XFontStruct * fs, unsigned int which) +{ + unsigned int rows, pages; + unsigned int byte1 = 0, byte2 = 0; + int i, valid = 1; + + rows = fs->max_byte1 - fs->min_byte1 + 1; + pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1; + + if (rows == 1) { + /* "linear" fonts */ + if ((fs->min_char_or_byte2 > which) || (fs->max_char_or_byte2 < which)) + valid = 0; + } + else { + /* "matrix" fonts */ + byte2 = which & 0xff; + byte1 = which >> 8; + if ((fs->min_char_or_byte2 > byte2) || + (fs->max_char_or_byte2 < byte2) || + (fs->min_byte1 > byte1) || (fs->max_byte1 < byte1)) + valid = 0; + } + + if (valid) { + if (fs->per_char) { + if (rows == 1) { + /* "linear" fonts */ + return (fs->per_char + (which - fs->min_char_or_byte2)); + } + else { + /* "matrix" fonts */ + i = ((byte1 - fs->min_byte1) * pages) + + (byte2 - fs->min_char_or_byte2); + return (fs->per_char + i); + } + } + else { + return (&fs->min_bounds); + } + } + return (NULL); +} + + +PUBLIC void +glXUseXFont(Font font, int first, int count, int listbase) +{ + Display *dpy; + Window win; + Pixmap pixmap; + GC gc; + XGCValues values; + unsigned long valuemask; + XFontStruct *fs; + GLint swapbytes, lsbfirst, rowlength; + GLint skiprows, skippixels, alignment; + unsigned int max_width, max_height, max_bm_width, max_bm_height; + GLubyte *bm; + int i; + + dpy = glXGetCurrentDisplay(); + if (!dpy) + return; /* I guess glXMakeCurrent wasn't called */ + i = DefaultScreen(dpy); + win = RootWindow(dpy, i); + + fs = XQueryFont(dpy, font); + if (!fs) { + _mesa_error(NULL, GL_INVALID_VALUE, + "Couldn't get font structure information"); + return; + } + + /* Allocate a bitmap that can fit all characters. */ + max_width = fs->max_bounds.rbearing - fs->min_bounds.lbearing; + max_height = fs->max_bounds.ascent + fs->max_bounds.descent; + max_bm_width = (max_width + 7) / 8; + max_bm_height = max_height; + + bm = (GLubyte *) MALLOC((max_bm_width * max_bm_height) * sizeof(GLubyte)); + if (!bm) { + XFreeFontInfo(NULL, fs, 1); + _mesa_error(NULL, GL_OUT_OF_MEMORY, + "Couldn't allocate bitmap in glXUseXFont()"); + return; + } + +#if 0 + /* get the page info */ + pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1; + firstchar = (fs->min_byte1 << 8) + fs->min_char_or_byte2; + lastchar = (fs->max_byte1 << 8) + fs->max_char_or_byte2; + rows = fs->max_byte1 - fs->min_byte1 + 1; + unsigned int first_char, last_char, pages, rows; +#endif + + /* Save the current packing mode for bitmaps. */ + glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes); + glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst); + glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength); + glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows); + glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels); + glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); + + /* Enforce a standard packing mode which is compatible with + fill_bitmap() from above. This is actually the default mode, + except for the (non)alignment. */ + glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); + glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + pixmap = XCreatePixmap(dpy, win, 10, 10, 1); + values.foreground = BlackPixel(dpy, DefaultScreen(dpy)); + values.background = WhitePixel(dpy, DefaultScreen(dpy)); + values.font = fs->fid; + valuemask = GCForeground | GCBackground | GCFont; + gc = XCreateGC(dpy, pixmap, valuemask, &values); + XFreePixmap(dpy, pixmap); + +#ifdef DEBUG + if (debug_xfonts) + dump_font_struct(fs); +#endif + + for (i = 0; i < count; i++) { + unsigned int width, height, bm_width, bm_height; + GLfloat x0, y0, dx, dy; + XCharStruct *ch; + int x, y; + unsigned int c = first + i; + int list = listbase + i; + int valid; + + /* check on index validity and get the bounds */ + ch = isvalid(fs, c); + if (!ch) { + ch = &fs->max_bounds; + valid = 0; + } + else { + valid = 1; + } + +#ifdef DEBUG + if (debug_xfonts) { + char s[7]; + sprintf(s, isprint(c) ? "%c> " : "\\%03o> ", c); + dump_char_struct(ch, s); + } +#endif + + /* glBitmap()' parameters: + straight from the glXUseXFont(3) manpage. */ + width = ch->rbearing - ch->lbearing; + height = ch->ascent + ch->descent; + x0 = -ch->lbearing; + y0 = ch->descent - 0; /* XXX used to subtract 1 here */ + /* but that caused a conformace failure */ + dx = ch->width; + dy = 0; + + /* X11's starting point. */ + x = -ch->lbearing; + y = ch->ascent; + + /* Round the width to a multiple of eight. We will use this also + for the pixmap for capturing the X11 font. This is slightly + inefficient, but it makes the OpenGL part real easy. */ + bm_width = (width + 7) / 8; + bm_height = height; + + glNewList(list, GL_COMPILE); + if (valid && (bm_width > 0) && (bm_height > 0)) { + + memset(bm, '\0', bm_width * bm_height); + fill_bitmap(dpy, win, gc, bm_width, bm_height, x, y, c, bm); + + glBitmap(width, height, x0, y0, dx, dy, bm); +#ifdef DEBUG + if (debug_xfonts) { + printf("width/height = %u/%u\n", width, height); + printf("bm_width/bm_height = %u/%u\n", bm_width, bm_height); + dump_bitmap(bm_width, bm_height, bm); + } +#endif + } + else { + glBitmap(0, 0, 0.0, 0.0, dx, dy, NULL); + } + glEndList(); + } + + FREE(bm); + XFreeFontInfo(NULL, fs, 1); + XFreeGC(dpy, gc); + + /* Restore saved packing modes. */ + glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes); + glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst); + glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength); + glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels); + glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); +} diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c new file mode 100644 index 0000000..7c47a25 --- /dev/null +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -0,0 +1,1316 @@ +/* + * Mesa 3-D graphics library + * Version: 7.1 + * + * Copyright (C) 1999-2007 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. + */ + +/** + * \file xm_api.c + * + * All the XMesa* API functions. + * + * + * NOTES: + * + * The window coordinate system origin (0,0) is in the lower-left corner + * of the window. X11's window coordinate origin is in the upper-left + * corner of the window. Therefore, most drawing functions in this + * file have to flip Y coordinates. + * + * + * Byte swapping: If the Mesa host and the X display use a different + * byte order then there's some trickiness to be aware of when using + * XImages. The byte ordering used for the XImage is that of the X + * display, not the Mesa host. + * The color-to-pixel encoding for True/DirectColor must be done + * according to the display's visual red_mask, green_mask, and blue_mask. + * If XPutPixel is used to put a pixel into an XImage then XPutPixel will + * do byte swapping if needed. If one wants to directly "poke" the pixel + * into the XImage's buffer then the pixel must be byte swapped first. + * + */ + +#ifdef __CYGWIN__ +#undef WIN32 +#undef __WIN32__ +#endif + +#include "xm_api.h" +#include "xm_st.h" + +#include "pipe/p_defines.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" + +#include "xm_public.h" +#include + + +/* Driver interface routines, set up by xlib backend on library + * _init(). These are global in the same way that function names are + * global. + */ +static struct xm_driver driver; +static struct st_api *stapi; + +/* Default strict invalidate to false. This means we will not call + * XGetGeometry after every swapbuffers, which allows swapbuffers to + * remain asynchronous. For apps running at 100fps with synchronous + * swapping, a 10% boost is typical. For gears, I see closer to 20% + * speedup. + * + * Note that the work of copying data on swapbuffers doesn't disappear + * - this change just allows the X server to execute the PutImage + * asynchronously without us effectively blocked until its completion. + * + * This speeds up even llvmpipe's threaded rasterization as the + * swapbuffers operation was a large part of the serial component of + * an llvmpipe frame. + * + * The downside of this is correctness - applications which don't call + * glViewport on window resizes will get incorrect rendering. A + * better solution would be to have per-frame but asynchronous + * invalidation. Xcb almost looks as if it could provide this, but + * the API doesn't seem to quite be there. + */ +boolean xmesa_strict_invalidate = FALSE; + +void xmesa_set_driver( const struct xm_driver *templ ) +{ + driver = *templ; + stapi = driver.create_st_api(); + + xmesa_strict_invalidate = + debug_get_bool_option("XMESA_STRICT_INVALIDATE", FALSE); +} + + +/* + * XXX replace this with a linked list, or better yet, try to attach the + * gallium/mesa extra bits to the X Display object with XAddExtension(). + */ +#define MAX_DISPLAYS 10 +static struct xmesa_display Displays[MAX_DISPLAYS]; +static int NumDisplays = 0; + +static int +xmesa_get_param(struct st_manager *smapi, + enum st_manager_param param) +{ + switch(param) { + case ST_MANAGER_BROKEN_INVALIDATE: + return !xmesa_strict_invalidate; + default: + return 0; + } +} + +static XMesaDisplay +xmesa_init_display( Display *display ) +{ + pipe_static_mutex(init_mutex); + XMesaDisplay xmdpy; + int i; + + pipe_mutex_lock(init_mutex); + + /* Look for XMesaDisplay which corresponds to 'display' */ + for (i = 0; i < NumDisplays; i++) { + if (Displays[i].display == display) { + /* Found it */ + pipe_mutex_unlock(init_mutex); + return &Displays[i]; + } + } + + /* Create new XMesaDisplay */ + + assert(NumDisplays < MAX_DISPLAYS); + xmdpy = &Displays[NumDisplays]; + NumDisplays++; + + if (!xmdpy->display && display) { + xmdpy->display = display; + xmdpy->screen = driver.create_pipe_screen(display); + xmdpy->smapi = CALLOC_STRUCT(st_manager); + if (xmdpy->smapi) { + xmdpy->smapi->screen = xmdpy->screen; + xmdpy->smapi->get_param = xmesa_get_param; + } + + if (xmdpy->screen && xmdpy->smapi) { + pipe_mutex_init(xmdpy->mutex); + } + else { + if (xmdpy->screen) { + xmdpy->screen->destroy(xmdpy->screen); + xmdpy->screen = NULL; + } + if (xmdpy->smapi) { + FREE(xmdpy->smapi); + xmdpy->smapi = NULL; + } + + xmdpy->display = NULL; + } + } + if (!xmdpy->display || xmdpy->display != display) + xmdpy = NULL; + + pipe_mutex_unlock(init_mutex); + + return xmdpy; +} + +/**********************************************************************/ +/***** X Utility Functions *****/ +/**********************************************************************/ + + +/** + * Return the host's byte order as LSBFirst or MSBFirst ala X. + */ +static int host_byte_order( void ) +{ + int i = 1; + char *cptr = (char *) &i; + return (*cptr==1) ? LSBFirst : MSBFirst; +} + + + + +/** + * Return the true number of bits per pixel for XImages. + * For example, if we request a 24-bit deep visual we may actually need/get + * 32bpp XImages. This function returns the appropriate bpp. + * Input: dpy - the X display + * visinfo - desribes the visual to be used for XImages + * Return: true number of bits per pixel for XImages + */ +static int +bits_per_pixel( XMesaVisual xmv ) +{ + Display *dpy = xmv->display; + XVisualInfo * visinfo = xmv->visinfo; + XImage *img; + int bitsPerPixel; + /* Create a temporary XImage */ + img = XCreateImage( dpy, visinfo->visual, visinfo->depth, + ZPixmap, 0, /*format, offset*/ + (char*) MALLOC(8), /*data*/ + 1, 1, /*width, height*/ + 32, /*bitmap_pad*/ + 0 /*bytes_per_line*/ + ); + assert(img); + /* grab the bits/pixel value */ + bitsPerPixel = img->bits_per_pixel; + /* free the XImage */ + free( img->data ); + img->data = NULL; + XDestroyImage( img ); + return bitsPerPixel; +} + + + +/* + * Determine if a given X window ID is valid (window exists). + * Do this by calling XGetWindowAttributes() for the window and + * checking if we catch an X error. + * Input: dpy - the display + * win - the window to check for existance + * Return: GL_TRUE - window exists + * GL_FALSE - window doesn't exist + */ +static GLboolean WindowExistsFlag; + +static int window_exists_err_handler( Display* dpy, XErrorEvent* xerr ) +{ + (void) dpy; + if (xerr->error_code == BadWindow) { + WindowExistsFlag = GL_FALSE; + } + return 0; +} + +static GLboolean window_exists( Display *dpy, Window win ) +{ + XWindowAttributes wa; + int (*old_handler)( Display*, XErrorEvent* ); + WindowExistsFlag = GL_TRUE; + old_handler = XSetErrorHandler(window_exists_err_handler); + XGetWindowAttributes( dpy, win, &wa ); /* dummy request */ + XSetErrorHandler(old_handler); + return WindowExistsFlag; +} + +static Status +get_drawable_size( Display *dpy, Drawable d, uint *width, uint *height ) +{ + Window root; + Status stat; + int xpos, ypos; + unsigned int w, h, bw, depth; + stat = XGetGeometry(dpy, d, &root, &xpos, &ypos, &w, &h, &bw, &depth); + *width = w; + *height = h; + return stat; +} + + +/** + * Return the size of the window (or pixmap) that corresponds to the + * given XMesaBuffer. + * \param width returns width in pixels + * \param height returns height in pixels + */ +void +xmesa_get_window_size(Display *dpy, XMesaBuffer b, + GLuint *width, GLuint *height) +{ + XMesaDisplay xmdpy = xmesa_init_display(dpy); + Status stat; + + pipe_mutex_lock(xmdpy->mutex); + stat = get_drawable_size(dpy, b->ws.drawable, width, height); + pipe_mutex_unlock(xmdpy->mutex); + + if (!stat) { + /* probably querying a window that's recently been destroyed */ + _mesa_warning(NULL, "XGetGeometry failed!\n"); + *width = *height = 1; + } +} + +#define GET_REDMASK(__v) __v->mesa_visual.redMask +#define GET_GREENMASK(__v) __v->mesa_visual.greenMask +#define GET_BLUEMASK(__v) __v->mesa_visual.blueMask + + +/** + * Choose the pixel format for the given visual. + * This will tell the gallium driver how to pack pixel data into + * drawing surfaces. + */ +static GLuint +choose_pixel_format(XMesaVisual v) +{ + boolean native_byte_order = (host_byte_order() == + ImageByteOrder(v->display)); + + if ( GET_REDMASK(v) == 0x0000ff + && GET_GREENMASK(v) == 0x00ff00 + && GET_BLUEMASK(v) == 0xff0000 + && v->BitsPerPixel == 32) { + if (native_byte_order) { + /* no byteswapping needed */ + return PIPE_FORMAT_R8G8B8A8_UNORM; + } + else { + return PIPE_FORMAT_A8B8G8R8_UNORM; + } + } + else if ( GET_REDMASK(v) == 0xff0000 + && GET_GREENMASK(v) == 0x00ff00 + && GET_BLUEMASK(v) == 0x0000ff + && v->BitsPerPixel == 32) { + if (native_byte_order) { + /* no byteswapping needed */ + return PIPE_FORMAT_B8G8R8A8_UNORM; + } + else { + return PIPE_FORMAT_A8R8G8B8_UNORM; + } + } + else if ( GET_REDMASK(v) == 0x0000ff00 + && GET_GREENMASK(v) == 0x00ff0000 + && GET_BLUEMASK(v) == 0xff000000 + && v->BitsPerPixel == 32) { + if (native_byte_order) { + /* no byteswapping needed */ + return PIPE_FORMAT_A8R8G8B8_UNORM; + } + else { + return PIPE_FORMAT_B8G8R8A8_UNORM; + } + } + else if ( GET_REDMASK(v) == 0xf800 + && GET_GREENMASK(v) == 0x07e0 + && GET_BLUEMASK(v) == 0x001f + && native_byte_order + && v->BitsPerPixel == 16) { + /* 5-6-5 RGB */ + return PIPE_FORMAT_B5G6R5_UNORM; + } + + return PIPE_FORMAT_NONE; +} + + +/** + * Choose a depth/stencil format that satisfies the given depth and + * stencil sizes. + */ +static enum pipe_format +choose_depth_stencil_format(XMesaDisplay xmdpy, int depth, int stencil) +{ + const enum pipe_texture_target target = PIPE_TEXTURE_2D; + const unsigned tex_usage = PIPE_BIND_DEPTH_STENCIL; + const unsigned geom_flags = (PIPE_TEXTURE_GEOM_NON_SQUARE | + PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO); + const unsigned sample_count = 0; + enum pipe_format formats[8], fmt; + int count, i; + + count = 0; + + if (depth <= 16 && stencil == 0) { + formats[count++] = PIPE_FORMAT_Z16_UNORM; + } + if (depth <= 24 && stencil == 0) { + formats[count++] = PIPE_FORMAT_X8Z24_UNORM; + formats[count++] = PIPE_FORMAT_Z24X8_UNORM; + } + if (depth <= 24 && stencil <= 8) { + formats[count++] = PIPE_FORMAT_S8_USCALED_Z24_UNORM; + formats[count++] = PIPE_FORMAT_Z24_UNORM_S8_USCALED; + } + if (depth <= 32 && stencil == 0) { + formats[count++] = PIPE_FORMAT_Z32_UNORM; + } + + fmt = PIPE_FORMAT_NONE; + for (i = 0; i < count; i++) { + if (xmdpy->screen->is_format_supported(xmdpy->screen, formats[i], + target, sample_count, + tex_usage, geom_flags)) { + fmt = formats[i]; + break; + } + } + + return fmt; +} + + + +/**********************************************************************/ +/***** Linked list of XMesaBuffers *****/ +/**********************************************************************/ + +static XMesaBuffer XMesaBufferList = NULL; + + +/** + * Allocate a new XMesaBuffer object which corresponds to the given drawable. + * Note that XMesaBuffer is derived from struct gl_framebuffer. + * The new XMesaBuffer will not have any size (Width=Height=0). + * + * \param d the corresponding X drawable (window or pixmap) + * \param type either WINDOW, PIXMAP or PBUFFER, describing d + * \param vis the buffer's visual + * \param cmap the window's colormap, if known. + * \return new XMesaBuffer or NULL if any problem + */ +static XMesaBuffer +create_xmesa_buffer(Drawable d, BufferType type, + XMesaVisual vis, Colormap cmap) +{ + XMesaDisplay xmdpy = xmesa_init_display(vis->display); + XMesaBuffer b; + uint width, height; + + ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER); + + if (!xmdpy) + return NULL; + + b = (XMesaBuffer) CALLOC_STRUCT(xmesa_buffer); + if (!b) + return NULL; + + b->ws.drawable = d; + b->ws.visual = vis->visinfo->visual; + b->ws.depth = vis->visinfo->depth; + + b->xm_visual = vis; + b->type = type; + b->cmap = cmap; + + get_drawable_size(vis->display, d, &width, &height); + + /* + * Create framebuffer, but we'll plug in our own renderbuffers below. + */ + b->stfb = xmesa_create_st_framebuffer(xmdpy, b); + + /* GLX_EXT_texture_from_pixmap */ + b->TextureTarget = 0; + b->TextureFormat = GLX_TEXTURE_FORMAT_NONE_EXT; + b->TextureMipmap = 0; + + /* insert buffer into linked list */ + b->Next = XMesaBufferList; + XMesaBufferList = b; + + return b; +} + + +/** + * Find an XMesaBuffer by matching X display and colormap but NOT matching + * the notThis buffer. + */ +XMesaBuffer +xmesa_find_buffer(Display *dpy, Colormap cmap, XMesaBuffer notThis) +{ + XMesaBuffer b; + for (b = XMesaBufferList; b; b = b->Next) { + if (b->xm_visual->display == dpy && + b->cmap == cmap && + b != notThis) { + return b; + } + } + return NULL; +} + + +/** + * Remove buffer from linked list, delete if no longer referenced. + */ +static void +xmesa_free_buffer(XMesaBuffer buffer) +{ + XMesaBuffer prev = NULL, b; + + for (b = XMesaBufferList; b; b = b->Next) { + if (b == buffer) { + /* unlink buffer from list */ + if (prev) + prev->Next = buffer->Next; + else + XMesaBufferList = buffer->Next; + + /* Since the X window for the XMesaBuffer is going away, we don't + * want to dereference this pointer in the future. + */ + b->ws.drawable = 0; + + /* XXX we should move the buffer to a delete-pending list and destroy + * the buffer until it is no longer current. + */ + xmesa_destroy_st_framebuffer(buffer->stfb); + + free(buffer); + + return; + } + /* continue search */ + prev = b; + } + /* buffer not found in XMesaBufferList */ + _mesa_problem(NULL,"xmesa_free_buffer() - buffer not found\n"); +} + + + +/**********************************************************************/ +/***** Misc Private Functions *****/ +/**********************************************************************/ + + +/** + * When a context is bound for the first time, we can finally finish + * initializing the context's visual and buffer information. + * \param v the XMesaVisual to initialize + * \param b the XMesaBuffer to initialize (may be NULL) + * \param rgb_flag TRUE = RGBA mode, FALSE = color index mode + * \param window the window/pixmap we're rendering into + * \param cmap the colormap associated with the window/pixmap + * \return GL_TRUE=success, GL_FALSE=failure + */ +static GLboolean +initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b, + GLboolean rgb_flag, Drawable window, + Colormap cmap) +{ + ASSERT(!b || b->xm_visual == v); + + /* Save true bits/pixel */ + v->BitsPerPixel = bits_per_pixel(v); + assert(v->BitsPerPixel > 0); + + if (rgb_flag == GL_FALSE) { + /* COLOR-INDEXED WINDOW: not supported*/ + return GL_FALSE; + } + else { + /* RGB WINDOW: + * We support RGB rendering into almost any kind of visual. + */ + const int xclass = v->visualType; + if (xclass != GLX_TRUE_COLOR && xclass == !GLX_DIRECT_COLOR) { + _mesa_warning(NULL, + "XMesa: RGB mode rendering not supported in given visual.\n"); + return GL_FALSE; + } + v->mesa_visual.indexBits = 0; + + if (v->BitsPerPixel == 32) { + /* We use XImages for all front/back buffers. If an X Window or + * X Pixmap is 32bpp, there's no guarantee that the alpha channel + * will be preserved. For XImages we're in luck. + */ + v->mesa_visual.alphaBits = 8; + } + } + + /* + * If MESA_INFO env var is set print out some debugging info + * which can help Brian figure out what's going on when a user + * reports bugs. + */ + if (_mesa_getenv("MESA_INFO")) { + printf("X/Mesa visual = %p\n", (void *) v); + printf("X/Mesa level = %d\n", v->mesa_visual.level); + printf("X/Mesa depth = %d\n", v->visinfo->depth); + printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel); + } + + return GL_TRUE; +} + + + +#define NUM_VISUAL_TYPES 6 + +/** + * Convert an X visual type to a GLX visual type. + * + * \param visualType X visual type (i.e., \c TrueColor, \c StaticGray, etc.) + * to be converted. + * \return If \c visualType is a valid X visual type, a GLX visual type will + * be returned. Otherwise \c GLX_NONE will be returned. + * + * \note + * This code was lifted directly from lib/GL/glx/glcontextmodes.c in the + * DRI CVS tree. + */ +static GLint +xmesa_convert_from_x_visual_type( int visualType ) +{ + static const int glx_visual_types[ NUM_VISUAL_TYPES ] = { + GLX_STATIC_GRAY, GLX_GRAY_SCALE, + GLX_STATIC_COLOR, GLX_PSEUDO_COLOR, + GLX_TRUE_COLOR, GLX_DIRECT_COLOR + }; + + return ( (unsigned) visualType < NUM_VISUAL_TYPES ) + ? glx_visual_types[ visualType ] : GLX_NONE; +} + + +/**********************************************************************/ +/***** Public Functions *****/ +/**********************************************************************/ + + +/* + * Create a new X/Mesa visual. + * Input: display - X11 display + * visinfo - an XVisualInfo pointer + * rgb_flag - GL_TRUE = RGB mode, + * GL_FALSE = color index mode + * alpha_flag - alpha buffer requested? + * db_flag - GL_TRUE = double-buffered, + * GL_FALSE = single buffered + * stereo_flag - stereo visual? + * ximage_flag - GL_TRUE = use an XImage for back buffer, + * GL_FALSE = use an off-screen pixmap for back buffer + * depth_size - requested bits/depth values, or zero + * stencil_size - requested bits/stencil values, or zero + * accum_red_size - requested bits/red accum values, or zero + * accum_green_size - requested bits/green accum values, or zero + * accum_blue_size - requested bits/blue accum values, or zero + * accum_alpha_size - requested bits/alpha accum values, or zero + * num_samples - number of samples/pixel if multisampling, or zero + * level - visual level, usually 0 + * visualCaveat - ala the GLX extension, usually GLX_NONE + * Return; a new XMesaVisual or 0 if error. + */ +PUBLIC +XMesaVisual XMesaCreateVisual( Display *display, + XVisualInfo * visinfo, + GLboolean rgb_flag, + GLboolean alpha_flag, + GLboolean db_flag, + GLboolean stereo_flag, + GLboolean ximage_flag, + GLint depth_size, + GLint stencil_size, + GLint accum_red_size, + GLint accum_green_size, + GLint accum_blue_size, + GLint accum_alpha_size, + GLint num_samples, + GLint level, + GLint visualCaveat ) +{ + XMesaDisplay xmdpy = xmesa_init_display(display); + XMesaVisual v; + GLint red_bits, green_bits, blue_bits, alpha_bits; + + if (!xmdpy) + return NULL; + + /* For debugging only */ + if (_mesa_getenv("MESA_XSYNC")) { + /* This makes debugging X easier. + * In your debugger, set a breakpoint on _XError to stop when an + * X protocol error is generated. + */ + XSynchronize( display, 1 ); + } + + v = (XMesaVisual) CALLOC_STRUCT(xmesa_visual); + if (!v) { + return NULL; + } + + v->display = display; + + /* Save a copy of the XVisualInfo struct because the user may Xfree() + * the struct but we may need some of the information contained in it + * at a later time. + */ + v->visinfo = (XVisualInfo *) MALLOC(sizeof(*visinfo)); + if (!v->visinfo) { + free(v); + return NULL; + } + memcpy(v->visinfo, visinfo, sizeof(*visinfo)); + + v->ximage_flag = ximage_flag; + + v->mesa_visual.redMask = visinfo->red_mask; + v->mesa_visual.greenMask = visinfo->green_mask; + v->mesa_visual.blueMask = visinfo->blue_mask; + v->visualID = visinfo->visualid; + v->screen = visinfo->screen; + +#if !(defined(__cplusplus) || defined(c_plusplus)) + v->visualType = xmesa_convert_from_x_visual_type(visinfo->class); +#else + v->visualType = xmesa_convert_from_x_visual_type(visinfo->c_class); +#endif + + v->mesa_visual.visualRating = visualCaveat; + + if (alpha_flag) + v->mesa_visual.alphaBits = 8; + + (void) initialize_visual_and_buffer( v, NULL, rgb_flag, 0, 0 ); + + { + const int xclass = v->visualType; + if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) { + red_bits = _mesa_bitcount(GET_REDMASK(v)); + green_bits = _mesa_bitcount(GET_GREENMASK(v)); + blue_bits = _mesa_bitcount(GET_BLUEMASK(v)); + } + else { + /* this is an approximation */ + int depth; + depth = v->visinfo->depth; + red_bits = depth / 3; + depth -= red_bits; + green_bits = depth / 2; + depth -= green_bits; + blue_bits = depth; + alpha_bits = 0; + assert( red_bits + green_bits + blue_bits == v->visinfo->depth ); + } + alpha_bits = v->mesa_visual.alphaBits; + } + + /* initialize visual */ + { + struct gl_config *vis = &v->mesa_visual; + + vis->rgbMode = GL_TRUE; + vis->doubleBufferMode = db_flag; + vis->stereoMode = stereo_flag; + + vis->redBits = red_bits; + vis->greenBits = green_bits; + vis->blueBits = blue_bits; + vis->alphaBits = alpha_bits; + vis->rgbBits = red_bits + green_bits + blue_bits; + + vis->indexBits = 0; + vis->depthBits = depth_size; + vis->stencilBits = stencil_size; + + vis->accumRedBits = accum_red_size; + vis->accumGreenBits = accum_green_size; + vis->accumBlueBits = accum_blue_size; + vis->accumAlphaBits = accum_alpha_size; + + vis->haveAccumBuffer = accum_red_size > 0; + vis->haveDepthBuffer = depth_size > 0; + vis->haveStencilBuffer = stencil_size > 0; + + vis->numAuxBuffers = 0; + vis->level = 0; + vis->sampleBuffers = 0; + vis->samples = 0; + } + + v->stvis.buffer_mask = ST_ATTACHMENT_FRONT_LEFT_MASK; + if (db_flag) + v->stvis.buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK; + if (stereo_flag) { + v->stvis.buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK; + if (db_flag) + v->stvis.buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK; + } + + v->stvis.color_format = choose_pixel_format(v); + if (v->stvis.color_format == PIPE_FORMAT_NONE) { + FREE(v->visinfo); + FREE(v); + return NULL; + } + + v->stvis.depth_stencil_format = + choose_depth_stencil_format(xmdpy, depth_size, stencil_size); + + v->stvis.accum_format = (accum_red_size + + accum_green_size + accum_blue_size + accum_alpha_size) ? + PIPE_FORMAT_R16G16B16A16_SNORM : PIPE_FORMAT_NONE; + + v->stvis.samples = num_samples; + v->stvis.render_buffer = ST_ATTACHMENT_INVALID; + + /* XXX minor hack */ + v->mesa_visual.level = level; + return v; +} + + +PUBLIC +void XMesaDestroyVisual( XMesaVisual v ) +{ + free(v->visinfo); + free(v); +} + + +/** + * Return the informative name. + */ +const char * +xmesa_get_name(void) +{ + return stapi->name; +} + + +/** + * Do per-display initializations. + */ +void +xmesa_init( Display *display ) +{ + xmesa_init_display(display); +} + + +/** + * Create a new XMesaContext. + * \param v the XMesaVisual + * \param share_list another XMesaContext with which to share display + * lists or NULL if no sharing is wanted. + * \return an XMesaContext or NULL if error. + */ +PUBLIC +XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) +{ + XMesaDisplay xmdpy = xmesa_init_display(v->display); + struct st_context_attribs attribs; + XMesaContext c; + + if (!xmdpy) + return NULL; + + /* Note: the XMesaContext contains a Mesa struct gl_context struct (inheritance) */ + c = (XMesaContext) CALLOC_STRUCT(xmesa_context); + if (!c) + return NULL; + + c->xm_visual = v; + c->xm_buffer = NULL; /* set later by XMesaMakeCurrent */ + c->xm_read_buffer = NULL; + + memset(&attribs, 0, sizeof(attribs)); + attribs.profile = ST_PROFILE_DEFAULT; + attribs.visual = v->stvis; + + c->st = stapi->create_context(stapi, xmdpy->smapi, + &attribs, (share_list) ? share_list->st : NULL); + if (c->st == NULL) + goto fail; + + c->st->st_manager_private = (void *) c; + + return c; + +fail: + if (c->st) + c->st->destroy(c->st); + + free(c); + return NULL; +} + + + +PUBLIC +void XMesaDestroyContext( XMesaContext c ) +{ + c->st->destroy(c->st); + + /* FIXME: We should destroy the screen here, but if we do so, surfaces may + * outlive it, causing segfaults + struct pipe_screen *screen = c->st->pipe->screen; + screen->destroy(screen); + */ + + free(c); +} + + + +/** + * Private function for creating an XMesaBuffer which corresponds to an + * X window or pixmap. + * \param v the window's XMesaVisual + * \param w the window we're wrapping + * \return new XMesaBuffer or NULL if error + */ +PUBLIC XMesaBuffer +XMesaCreateWindowBuffer(XMesaVisual v, Window w) +{ + XWindowAttributes attr; + XMesaBuffer b; + Colormap cmap; + int depth; + + assert(v); + assert(w); + + /* Check that window depth matches visual depth */ + XGetWindowAttributes( v->display, w, &attr ); + depth = attr.depth; + if (v->visinfo->depth != depth) { + _mesa_warning(NULL, "XMesaCreateWindowBuffer: depth mismatch between visual (%d) and window (%d)!\n", + v->visinfo->depth, depth); + return NULL; + } + + /* Find colormap */ + if (attr.colormap) { + cmap = attr.colormap; + } + else { + _mesa_warning(NULL, "Window %u has no colormap!\n", (unsigned int) w); + /* this is weird, a window w/out a colormap!? */ + /* OK, let's just allocate a new one and hope for the best */ + cmap = XCreateColormap(v->display, w, attr.visual, AllocNone); + } + + b = create_xmesa_buffer((Drawable) w, WINDOW, v, cmap); + if (!b) + return NULL; + + if (!initialize_visual_and_buffer( v, b, v->mesa_visual.rgbMode, + (Drawable) w, cmap )) { + xmesa_free_buffer(b); + return NULL; + } + + return b; +} + + + +/** + * Create a new XMesaBuffer from an X pixmap. + * + * \param v the XMesaVisual + * \param p the pixmap + * \param cmap the colormap, may be 0 if using a \c GLX_TRUE_COLOR or + * \c GLX_DIRECT_COLOR visual for the pixmap + * \returns new XMesaBuffer or NULL if error + */ +PUBLIC XMesaBuffer +XMesaCreatePixmapBuffer(XMesaVisual v, Pixmap p, Colormap cmap) +{ + XMesaBuffer b; + + assert(v); + + b = create_xmesa_buffer((Drawable) p, PIXMAP, v, cmap); + if (!b) + return NULL; + + if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode, + (Drawable) p, cmap)) { + xmesa_free_buffer(b); + return NULL; + } + + return b; +} + + +/** + * For GLX_EXT_texture_from_pixmap + */ +XMesaBuffer +XMesaCreatePixmapTextureBuffer(XMesaVisual v, Pixmap p, + Colormap cmap, + int format, int target, int mipmap) +{ + GET_CURRENT_CONTEXT(ctx); + XMesaBuffer b; + + assert(v); + + b = create_xmesa_buffer((Drawable) p, PIXMAP, v, cmap); + if (!b) + return NULL; + + /* get pixmap size */ + xmesa_get_window_size(v->display, b, &b->width, &b->height); + + if (target == 0) { + /* examine dims */ + if (ctx->Extensions.ARB_texture_non_power_of_two) { + target = GLX_TEXTURE_2D_EXT; + } + else if ( _mesa_bitcount(b->width) == 1 + && _mesa_bitcount(b->height) == 1) { + /* power of two size */ + if (b->height == 1) { + target = GLX_TEXTURE_1D_EXT; + } + else { + target = GLX_TEXTURE_2D_EXT; + } + } + else if (ctx->Extensions.NV_texture_rectangle) { + target = GLX_TEXTURE_RECTANGLE_EXT; + } + else { + /* non power of two textures not supported */ + XMesaDestroyBuffer(b); + return 0; + } + } + + b->TextureTarget = target; + b->TextureFormat = format; + b->TextureMipmap = mipmap; + + if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode, + (Drawable) p, cmap)) { + xmesa_free_buffer(b); + return NULL; + } + + return b; +} + + + +XMesaBuffer +XMesaCreatePBuffer(XMesaVisual v, Colormap cmap, + unsigned int width, unsigned int height) +{ + Window root; + Drawable drawable; /* X Pixmap Drawable */ + XMesaBuffer b; + + /* allocate pixmap for front buffer */ + root = RootWindow( v->display, v->visinfo->screen ); + drawable = XCreatePixmap(v->display, root, width, height, + v->visinfo->depth); + if (!drawable) + return NULL; + + b = create_xmesa_buffer(drawable, PBUFFER, v, cmap); + if (!b) + return NULL; + + if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode, + drawable, cmap)) { + xmesa_free_buffer(b); + return NULL; + } + + return b; +} + + + +/* + * Deallocate an XMesaBuffer structure and all related info. + */ +PUBLIC void +XMesaDestroyBuffer(XMesaBuffer b) +{ + xmesa_free_buffer(b); +} + + +/** + * Notify the binding context to validate the buffer. + */ +void +xmesa_notify_invalid_buffer(XMesaBuffer b) +{ + XMesaContext xmctx = XMesaGetCurrentContext(); + + if (xmctx && xmctx->xm_buffer == b) + xmctx->st->notify_invalid_framebuffer(xmctx->st, b->stfb); +} + + +/** + * Query the current drawable size and notify the binding context. + */ +void +xmesa_check_buffer_size(XMesaBuffer b) +{ + if (b->type == PBUFFER) + return; + + xmesa_get_window_size(b->xm_visual->display, b, &b->width, &b->height); + xmesa_notify_invalid_buffer(b); +} + + +/* + * Bind buffer b to context c and make c the current rendering context. + */ +PUBLIC +GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer, + XMesaBuffer readBuffer ) +{ + XMesaContext old_ctx = XMesaGetCurrentContext(); + + if (old_ctx && old_ctx != c) { + XMesaFlush(old_ctx); + old_ctx->xm_buffer = NULL; + old_ctx->xm_read_buffer = NULL; + } + + if (c) { + if (!drawBuffer || !readBuffer) + return GL_FALSE; /* must specify buffers! */ + + if (c == old_ctx && + c->xm_buffer == drawBuffer && + c->xm_read_buffer == readBuffer) + return GL_TRUE; + + xmesa_check_buffer_size(drawBuffer); + if (readBuffer != drawBuffer) + xmesa_check_buffer_size(readBuffer); + + c->xm_buffer = drawBuffer; + c->xm_read_buffer = readBuffer; + + stapi->make_current(stapi, c->st, drawBuffer->stfb, readBuffer->stfb); + + /* Solution to Stephane Rehel's problem with glXReleaseBuffersMESA(): */ + drawBuffer->wasCurrent = GL_TRUE; + } + else { + /* Detach */ + stapi->make_current(stapi, NULL, NULL, NULL); + + } + return GL_TRUE; +} + + +/* + * Unbind the context c from its buffer. + */ +GLboolean XMesaUnbindContext( XMesaContext c ) +{ + /* A no-op for XFree86 integration purposes */ + return GL_TRUE; +} + + +XMesaContext XMesaGetCurrentContext( void ) +{ + struct st_context_iface *st = stapi->get_current(stapi); + return (XMesaContext) (st) ? st->st_manager_private : NULL; +} + + + +/** + * Swap front and back color buffers and have winsys display front buffer. + * If there's no front color buffer no swap actually occurs. + */ +PUBLIC +void XMesaSwapBuffers( XMesaBuffer b ) +{ + XMesaContext xmctx = XMesaGetCurrentContext(); + + if (xmctx && xmctx->xm_buffer == b) { + xmctx->st->flush( xmctx->st, + PIPE_FLUSH_RENDER_CACHE | + PIPE_FLUSH_SWAPBUFFERS | + PIPE_FLUSH_FRAME, + NULL); + } + + xmesa_swap_st_framebuffer(b->stfb); +} + + + +/* + * Copy sub-region of back buffer to front buffer + */ +void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height ) +{ + xmesa_copy_st_framebuffer(b->stfb, + ST_ATTACHMENT_BACK_LEFT, ST_ATTACHMENT_FRONT_LEFT, + x, y, width, height); +} + + + +void XMesaFlush( XMesaContext c ) +{ + if (c && c->xm_visual->display) { + XMesaDisplay xmdpy = xmesa_init_display(c->xm_visual->display); + struct pipe_fence_handle *fence = NULL; + + c->st->flush(c->st, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, &fence); + if (fence) { + xmdpy->screen->fence_finish(xmdpy->screen, fence, 0); + xmdpy->screen->fence_reference(xmdpy->screen, &fence, NULL); + } + XFlush( c->xm_visual->display ); + } +} + + + + + +XMesaBuffer XMesaFindBuffer( Display *dpy, Drawable d ) +{ + XMesaBuffer b; + for (b = XMesaBufferList; b; b = b->Next) { + if (b->ws.drawable == d && b->xm_visual->display == dpy) { + return b; + } + } + return NULL; +} + + +/** + * Free/destroy all XMesaBuffers associated with given display. + */ +void xmesa_destroy_buffers_on_display(Display *dpy) +{ + XMesaBuffer b, next; + for (b = XMesaBufferList; b; b = next) { + next = b->Next; + if (b->xm_visual->display == dpy) { + xmesa_free_buffer(b); + /* delete head of list? */ + if (XMesaBufferList == b) { + XMesaBufferList = next; + } + } + } +} + + +/* + * Look for XMesaBuffers whose X window has been destroyed. + * Deallocate any such XMesaBuffers. + */ +void XMesaGarbageCollect( void ) +{ + XMesaBuffer b, next; + for (b=XMesaBufferList; b; b=next) { + next = b->Next; + if (b->xm_visual && + b->xm_visual->display && + b->ws.drawable && + b->type == WINDOW) { + XSync(b->xm_visual->display, False); + if (!window_exists( b->xm_visual->display, b->ws.drawable )) { + /* found a dead window, free the ancillary info */ + XMesaDestroyBuffer( b ); + } + } + } +} + + + + +PUBLIC void +XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer, + const int *attrib_list) +{ +} + + + +PUBLIC void +XMesaReleaseTexImage(Display *dpy, XMesaBuffer drawable, int buffer) +{ +} + + +void +XMesaCopyContext(XMesaContext src, XMesaContext dst, unsigned long mask) +{ + if (dst->st->copy) + dst->st->copy(dst->st, src->st, mask); +} diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.h b/src/gallium/state_trackers/glx/xlib/xm_api.h new file mode 100644 index 0000000..4ea42dc --- /dev/null +++ b/src/gallium/state_trackers/glx/xlib/xm_api.h @@ -0,0 +1,390 @@ +/* + * Mesa 3-D graphics library + * Version: 7.1 + * + * Copyright (C) 1999-2007 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. + */ + + + +/* Sample Usage: + +In addition to the usual X calls to select a visual, create a colormap +and create a window, you must do the following to use the X/Mesa interface: + +1. Call XMesaCreateVisual() to make an XMesaVisual from an XVisualInfo. + +2. Call XMesaCreateContext() to create an X/Mesa rendering context, given + the XMesaVisual. + +3. Call XMesaCreateWindowBuffer() to create an XMesaBuffer from an X window + and XMesaVisual. + +4. Call XMesaMakeCurrent() to bind the XMesaBuffer to an XMesaContext and + to make the context the current one. + +5. Make gl* calls to render your graphics. + +6. Use XMesaSwapBuffers() when double buffering to swap front/back buffers. + +7. Before the X window is destroyed, call XMesaDestroyBuffer(). + +8. Before exiting, call XMesaDestroyVisual and XMesaDestroyContext. + +*/ + + + + +#ifndef XMESA_H +#define XMESA_H + + +#include "main/core.h" /* for gl_config */ +#include "state_tracker/st_api.h" +#include "os/os_thread.h" + +#include "state_tracker/xlib_sw_winsys.h" + +# include +# include +# include + +typedef struct xmesa_display *XMesaDisplay; +typedef struct xmesa_buffer *XMesaBuffer; +typedef struct xmesa_context *XMesaContext; +typedef struct xmesa_visual *XMesaVisual; + + +struct xmesa_display { + pipe_mutex mutex; + + Display *display; + struct pipe_screen *screen; + struct st_manager *smapi; + + struct pipe_context *pipe; +}; + + +/* + * Create a new X/Mesa visual. + * Input: display - X11 display + * visinfo - an XVisualInfo pointer + * rgb_flag - GL_TRUE = RGB mode, + * GL_FALSE = color index mode + * alpha_flag - alpha buffer requested? + * db_flag - GL_TRUE = double-buffered, + * GL_FALSE = single buffered + * stereo_flag - stereo visual? + * ximage_flag - GL_TRUE = use an XImage for back buffer, + * GL_FALSE = use an off-screen pixmap for back buffer + * depth_size - requested bits/depth values, or zero + * stencil_size - requested bits/stencil values, or zero + * accum_red_size - requested bits/red accum values, or zero + * accum_green_size - requested bits/green accum values, or zero + * accum_blue_size - requested bits/blue accum values, or zero + * accum_alpha_size - requested bits/alpha accum values, or zero + * num_samples - number of samples/pixel if multisampling, or zero + * level - visual level, usually 0 + * visualCaveat - ala the GLX extension, usually GLX_NONE_EXT + * Return; a new XMesaVisual or 0 if error. + */ +extern XMesaVisual XMesaCreateVisual( Display *display, + XVisualInfo * visinfo, + GLboolean rgb_flag, + GLboolean alpha_flag, + GLboolean db_flag, + GLboolean stereo_flag, + GLboolean ximage_flag, + GLint depth_size, + GLint stencil_size, + GLint accum_red_size, + GLint accum_green_size, + GLint accum_blue_size, + GLint accum_alpha_size, + GLint num_samples, + GLint level, + GLint visualCaveat ); + +/* + * Destroy an XMesaVisual, but not the associated XVisualInfo. + */ +extern void XMesaDestroyVisual( XMesaVisual v ); + + + +/* + * Create a new XMesaContext for rendering into an X11 window. + * + * Input: visual - an XMesaVisual + * share_list - another XMesaContext with which to share display + * lists or NULL if no sharing is wanted. + * Return: an XMesaContext or NULL if error. + */ +extern XMesaContext XMesaCreateContext( XMesaVisual v, + XMesaContext share_list ); + + +/* + * Destroy a rendering context as returned by XMesaCreateContext() + */ +extern void XMesaDestroyContext( XMesaContext c ); + + + +/* + * Create an XMesaBuffer from an X window. + */ +extern XMesaBuffer XMesaCreateWindowBuffer( XMesaVisual v, Window w ); + + +/* + * Create an XMesaBuffer from an X pixmap. + */ +extern XMesaBuffer XMesaCreatePixmapBuffer( XMesaVisual v, + Pixmap p, + Colormap cmap ); + + +/* + * Destroy an XMesaBuffer, but not the corresponding window or pixmap. + */ +extern void XMesaDestroyBuffer( XMesaBuffer b ); + + +/* + * Return the XMesaBuffer handle which corresponds to an X drawable, if any. + * + * New in Mesa 2.3. + */ +extern XMesaBuffer XMesaFindBuffer( Display *dpy, + Drawable d ); + + + +/* + * Bind two buffers (read and draw) to a context and make the + * context the current one. + * New in Mesa 3.3 + */ +extern GLboolean XMesaMakeCurrent2( XMesaContext c, + XMesaBuffer drawBuffer, + XMesaBuffer readBuffer ); + + +/* + * Unbind the current context from its buffer. + */ +extern GLboolean XMesaUnbindContext( XMesaContext c ); + + +/* + * Return a handle to the current context. + */ +extern XMesaContext XMesaGetCurrentContext( void ); + + +/* + * Swap the front and back buffers for the given buffer. No action is + * taken if the buffer is not double buffered. + */ +extern void XMesaSwapBuffers( XMesaBuffer b ); + + +/* + * Copy a sub-region of the back buffer to the front buffer. + * + * New in Mesa 2.6 + */ +extern void XMesaCopySubBuffer( XMesaBuffer b, + int x, + int y, + int width, + int height ); + + + + + +/* + * Flush/sync a context + */ +extern void XMesaFlush( XMesaContext c ); + + + +/* + * Scan for XMesaBuffers whose window/pixmap has been destroyed, then free + * any memory used by that buffer. + * + * New in Mesa 2.3. + */ +extern void XMesaGarbageCollect( void ); + + + +/* + * Create a pbuffer. + * New in Mesa 4.1 + */ +extern XMesaBuffer XMesaCreatePBuffer(XMesaVisual v, Colormap cmap, + unsigned int width, unsigned int height); + + + +/* + * Texture from Pixmap + * New in Mesa 7.1 + */ +extern void +XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer, + const int *attrib_list); + +extern void +XMesaReleaseTexImage(Display *dpy, XMesaBuffer drawable, int buffer); + + +extern XMesaBuffer +XMesaCreatePixmapTextureBuffer(XMesaVisual v, Pixmap p, + Colormap cmap, + int format, int target, int mipmap); + + +extern void +XMesaCopyContext(XMesaContext src, XMesaContext dst, unsigned long mask); + + +/*********************************************************************** + */ + +/** + * Visual inforation, derived from GLvisual. + * Basically corresponds to an XVisualInfo. + */ +struct xmesa_visual { + struct gl_config mesa_visual;/* Device independent visual parameters */ + int screen, visualID, visualType; + Display *display; /* The X11 display */ + XVisualInfo * visinfo; /* X's visual info (pointer to private copy) */ + XVisualInfo *vishandle; /* Only used in fakeglx.c */ + GLint BitsPerPixel; /* True bits per pixel for XImages */ + + GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */ + + struct st_visual stvis; +}; + + +/** + * Context info, derived from st_context. + * Basically corresponds to a GLXContext. + */ +struct xmesa_context { + struct st_context_iface *st; + XMesaVisual xm_visual; /** pixel format info */ + XMesaBuffer xm_buffer; /** current drawbuffer */ + XMesaBuffer xm_read_buffer; /** current readbuffer */ +}; + + +/** + * Types of X/GLX drawables we might render into. + */ +typedef enum { + WINDOW, /* An X window */ + GLXWINDOW, /* GLX window */ + PIXMAP, /* GLX pixmap */ + PBUFFER /* GLX Pbuffer */ +} BufferType; + + +/** + * Framebuffer information, derived from. + * Basically corresponds to a GLXDrawable. + */ +struct xmesa_buffer { + struct st_framebuffer_iface *stfb; + struct xlib_drawable ws; + + GLboolean wasCurrent; /* was ever the current buffer? */ + XMesaVisual xm_visual; /* the X/Mesa visual */ + Drawable drawable; /* Usually the X window ID */ + Colormap cmap; /* the X colormap */ + BufferType type; /* window, pixmap, pbuffer or glxwindow */ + + GLboolean largestPbuffer; /**< for pbuffers */ + GLboolean preservedContents; /**< for pbuffers */ + + XImage *tempImage; + unsigned long selectedEvents;/* for pbuffers only */ + + + GC gc; /* scratch GC for span, line, tri drawing */ + + /* GLX_EXT_texture_from_pixmap */ + GLint TextureTarget; /** GLX_TEXTURE_1D_EXT, for example */ + GLint TextureFormat; /** GLX_TEXTURE_FORMAT_RGB_EXT, for example */ + GLint TextureMipmap; /** 0 or 1 */ + + struct xmesa_buffer *Next; /* Linked list pointer: */ + + unsigned width, height; +}; + + + +extern const char * +xmesa_get_name(void); + +extern void +xmesa_init(Display *dpy); + +extern XMesaBuffer +xmesa_find_buffer(Display *dpy, Colormap cmap, XMesaBuffer notThis); + +extern void +xmesa_get_window_size(Display *dpy, XMesaBuffer b, + GLuint *width, GLuint *height); + +extern void +xmesa_notify_invalid_buffer(XMesaBuffer b); + +extern void +xmesa_check_buffer_size(XMesaBuffer b); + +extern void +xmesa_destroy_buffers_on_display(Display *dpy); + +static INLINE GLuint +xmesa_buffer_width(XMesaBuffer b) +{ + return b->width; +} + +static INLINE GLuint +xmesa_buffer_height(XMesaBuffer b) +{ + return b->height; +} + +extern boolean xmesa_strict_invalidate; + +#endif diff --git a/src/gallium/state_trackers/glx/xlib/xm_public.h b/src/gallium/state_trackers/glx/xlib/xm_public.h new file mode 100644 index 0000000..950eb21 --- /dev/null +++ b/src/gallium/state_trackers/glx/xlib/xm_public.h @@ -0,0 +1,48 @@ + +/************************************************************************** + * + * Copyright 2006 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. + * + **************************************************************************/ + +#ifndef XM_PUBLIC_H +#define XM_PUBLIC_H + +#include + +struct pipe_screen; +struct st_api; + +/* This is the driver interface required by the glx/xlib state tracker. + */ +struct xm_driver { + struct pipe_screen *(*create_pipe_screen)( Display *display ); + struct st_api *(*create_st_api)( void ); +}; + +extern void +xmesa_set_driver( const struct xm_driver *driver ); + + +#endif /* XM_PUBLIC_H */ diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.c b/src/gallium/state_trackers/glx/xlib/xm_st.c new file mode 100644 index 0000000..6bfe8b0 --- /dev/null +++ b/src/gallium/state_trackers/glx/xlib/xm_st.c @@ -0,0 +1,362 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "xm_api.h" +#include "xm_st.h" + +#include "util/u_inlines.h" + +struct xmesa_st_framebuffer { + XMesaDisplay display; + XMesaBuffer buffer; + struct pipe_screen *screen; + + struct st_visual stvis; + enum pipe_texture_target target; + + unsigned texture_width, texture_height, texture_mask; + struct pipe_resource *textures[ST_ATTACHMENT_COUNT]; + + struct pipe_resource *display_resource; +}; + +static INLINE struct xmesa_st_framebuffer * +xmesa_st_framebuffer(struct st_framebuffer_iface *stfbi) +{ + return (struct xmesa_st_framebuffer *) stfbi->st_manager_private; +} + +/** + * Display an attachment to the xlib_drawable of the framebuffer. + */ +static boolean +xmesa_st_framebuffer_display(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + struct pipe_resource *ptex = xstfb->textures[statt]; + struct pipe_resource *pres; + + if (!ptex) + return TRUE; + + pres = xstfb->display_resource; + /* (re)allocate the surface for the texture to be displayed */ + if (!pres || pres != ptex) { + pipe_resource_reference(&xstfb->display_resource, ptex); + pres = xstfb->display_resource; + } + + xstfb->screen->flush_frontbuffer(xstfb->screen, pres, 0, 0, &xstfb->buffer->ws); + + return TRUE; +} + +/** + * Copy the contents between the attachments. + */ +static void +xmesa_st_framebuffer_copy_textures(struct st_framebuffer_iface *stfbi, + enum st_attachment_type src_statt, + enum st_attachment_type dst_statt, + unsigned x, unsigned y, + unsigned width, unsigned height) +{ + struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + struct pipe_resource *src_ptex = xstfb->textures[src_statt]; + struct pipe_resource *dst_ptex = xstfb->textures[dst_statt]; + struct pipe_box src_box; + struct pipe_context *pipe; + + if (!src_ptex || !dst_ptex) + return; + + pipe = xstfb->display->pipe; + if (!pipe) { + pipe = xstfb->screen->context_create(xstfb->screen, NULL); + if (!pipe) + return; + xstfb->display->pipe = pipe; + } + + u_box_2d(x, y, width, height, &src_box); + + if (src_ptex && dst_ptex) + pipe->resource_copy_region(pipe, dst_ptex, 0, x, y, 0, + src_ptex, 0, &src_box); +} + +/** + * Remove outdated textures and create the requested ones. + * This is a helper used during framebuffer validation. + */ +static boolean +xmesa_st_framebuffer_validate_textures(struct st_framebuffer_iface *stfbi, + unsigned width, unsigned height, + unsigned mask) +{ + struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + struct pipe_resource templ; + enum st_attachment_type i; + + /* remove outdated textures */ + if (xstfb->texture_width != width || xstfb->texture_height != height) { + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_resource_reference(&xstfb->textures[i], NULL); + } + + memset(&templ, 0, sizeof(templ)); + templ.target = xstfb->target; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.array_size = 1; + templ.last_level = 0; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + enum pipe_format format; + unsigned bind; + + /* the texture already exists or not requested */ + if (xstfb->textures[i] || !(mask & (1 << i))) { + /* remember the texture */ + if (xstfb->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 = xstfb->stvis.color_format; + bind = PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_RENDER_TARGET; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + format = xstfb->stvis.depth_stencil_format; + bind = PIPE_BIND_DEPTH_STENCIL; + break; + default: + format = PIPE_FORMAT_NONE; + break; + } + + if (format != PIPE_FORMAT_NONE) { + templ.format = format; + templ.bind = bind; + + xstfb->textures[i] = + xstfb->screen->resource_create(xstfb->screen, &templ); + if (!xstfb->textures[i]) + return FALSE; + } + } + + xstfb->texture_width = width; + xstfb->texture_height = height; + xstfb->texture_mask = mask; + + return TRUE; +} + + +/** + * Check that a framebuffer's attachments match the window's size. + * + * Called via st_framebuffer_iface::validate() + * + * \param statts array of framebuffer attachments + * \param count number of framebuffer attachments in statts[] + * \param out returns resources for each of the attachments + */ +static boolean +xmesa_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_resource **out) +{ + struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + unsigned statt_mask, new_mask, i; + boolean resized; + boolean ret; + + /* build mask of ST_ATTACHMENT bits */ + statt_mask = 0x0; + for (i = 0; i < count; i++) + statt_mask |= 1 << statts[i]; + + /* record newly allocated textures */ + new_mask = statt_mask & ~xstfb->texture_mask; + + /* If xmesa_strict_invalidate is not set, we will not yet have + * called XGetGeometry(). Do so here: + */ + if (!xmesa_strict_invalidate) + xmesa_check_buffer_size(xstfb->buffer); + + resized = (xstfb->buffer->width != xstfb->texture_width || + xstfb->buffer->height != xstfb->texture_height); + + /* revalidate textures */ + if (resized || new_mask) { + ret = xmesa_st_framebuffer_validate_textures(stfbi, + xstfb->buffer->width, xstfb->buffer->height, statt_mask); + if (!ret) + return ret; + + if (!resized) { + enum st_attachment_type back, front; + + back = ST_ATTACHMENT_BACK_LEFT; + front = ST_ATTACHMENT_FRONT_LEFT; + /* copy the contents if front is newly allocated and back is not */ + if ((statt_mask & (1 << back)) && + (new_mask & (1 << front)) && + !(new_mask & (1 << back))) { + xmesa_st_framebuffer_copy_textures(stfbi, back, front, + 0, 0, xstfb->texture_width, xstfb->texture_height); + } + } + } + + for (i = 0; i < count; i++) { + out[i] = NULL; + pipe_resource_reference(&out[i], xstfb->textures[statts[i]]); + } + + return TRUE; +} + +/** + * Called via st_framebuffer_iface::flush_front() + */ +static boolean +xmesa_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + boolean ret; + + ret = xmesa_st_framebuffer_display(stfbi, statt); + + if (ret && xmesa_strict_invalidate) + xmesa_check_buffer_size(xstfb->buffer); + + return ret; +} + +struct st_framebuffer_iface * +xmesa_create_st_framebuffer(XMesaDisplay xmdpy, XMesaBuffer b) +{ + struct st_framebuffer_iface *stfbi; + struct xmesa_st_framebuffer *xstfb; + + assert(xmdpy->display == b->xm_visual->display); + + stfbi = CALLOC_STRUCT(st_framebuffer_iface); + xstfb = CALLOC_STRUCT(xmesa_st_framebuffer); + if (!stfbi || !xstfb) { + if (stfbi) + FREE(stfbi); + if (xstfb) + FREE(xstfb); + return NULL; + } + + xstfb->display = xmdpy; + xstfb->buffer = b; + xstfb->screen = xmdpy->screen; + xstfb->stvis = b->xm_visual->stvis; + if(xstfb->screen->get_param(xstfb->screen, PIPE_CAP_NPOT_TEXTURES)) + xstfb->target = PIPE_TEXTURE_2D; + else + xstfb->target = PIPE_TEXTURE_RECT; + + stfbi->visual = &xstfb->stvis; + stfbi->flush_front = xmesa_st_framebuffer_flush_front; + stfbi->validate = xmesa_st_framebuffer_validate; + stfbi->st_manager_private = (void *) xstfb; + + return stfbi; +} + +void +xmesa_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi) +{ + struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + int i; + + pipe_resource_reference(&xstfb->display_resource, NULL); + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_resource_reference(&xstfb->textures[i], NULL); + + FREE(xstfb); + FREE(stfbi); +} + +void +xmesa_swap_st_framebuffer(struct st_framebuffer_iface *stfbi) +{ + struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + boolean ret; + + ret = xmesa_st_framebuffer_display(stfbi, ST_ATTACHMENT_BACK_LEFT); + if (ret) { + struct pipe_resource **front, **back, *tmp; + + front = &xstfb->textures[ST_ATTACHMENT_FRONT_LEFT]; + back = &xstfb->textures[ST_ATTACHMENT_BACK_LEFT]; + /* swap textures only if the front texture has been allocated */ + if (*front) { + tmp = *front; + *front = *back; + *back = tmp; + + /* the current context should validate the buffer after swapping */ + if (!xmesa_strict_invalidate) + xmesa_notify_invalid_buffer(xstfb->buffer); + } + + if (xmesa_strict_invalidate) + xmesa_check_buffer_size(xstfb->buffer); + } +} + +void +xmesa_copy_st_framebuffer(struct st_framebuffer_iface *stfbi, + enum st_attachment_type src, + enum st_attachment_type dst, + int x, int y, int w, int h) +{ + xmesa_st_framebuffer_copy_textures(stfbi, src, dst, x, y, w, h); + if (dst == ST_ATTACHMENT_FRONT_LEFT) + xmesa_st_framebuffer_display(stfbi, dst); +} diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.h b/src/gallium/state_trackers/glx/xlib/xm_st.h new file mode 100644 index 0000000..8625976 --- /dev/null +++ b/src/gallium/state_trackers/glx/xlib/xm_st.h @@ -0,0 +1,52 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _XM_ST_H_ +#define _XM_ST_H_ + +#include "pipe/p_compiler.h" +#include "state_tracker/st_api.h" + +#include "xm_api.h" + +struct st_framebuffer_iface * +xmesa_create_st_framebuffer(XMesaDisplay xmdpy, XMesaBuffer b); + +void +xmesa_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi); + +void +xmesa_swap_st_framebuffer(struct st_framebuffer_iface *stfbi); + +void +xmesa_copy_st_framebuffer(struct st_framebuffer_iface *stfbi, + enum st_attachment_type src, + enum st_attachment_type dst, + int x, int y, int w, int h); + +#endif /* _XM_ST_H_ */ diff --git a/src/gallium/state_trackers/python/SConscript b/src/gallium/state_trackers/python/SConscript new file mode 100644 index 0000000..b837186 --- /dev/null +++ b/src/gallium/state_trackers/python/SConscript @@ -0,0 +1,66 @@ +import sys +import os.path + +Import('*') + +if env['toolchain'] == 'crossmingw': + # Cross-compilation not supported + Return() + +if not env.Detect(['swig']): + Return() + +env = env.Clone() + +env.Tool('python') + +env.Tool('swig') +env.Append(SWIGPATH = ['#src/gallium/include', '#src/gallium/include/pipe']) +env.Append(SWIGFLAGS = ['-python', '-keyword']) + +env.Append(CPPPATH = '.') + +if env['platform'] == 'windows': + env.Append(LIBS = [ + 'opengl32', + 'gdi32', + 'user32', + 'kernel32', + 'ws2_32', + ]) +else: + env.Append(CPPDEFINES = ['GCC_HASCLASSVISIBILITY']) + env.Append(LIBS = [ + 'GL', + 'X11', + ]) + +sources = [ + 'gallium.i', + 'st_device.c', + 'st_sample.c', + 'st_hardpipe_winsys.c', + 'st_softpipe_winsys.c', +] + +env.Prepend(LIBS = [ + ws_null, + trace, + gallium, +]) + +if env['llvm']: + env.Append(CPPDEFINES = ['HAVE_LLVMPIPE']) + env.Prepend(LIBS = [llvmpipe]) +if True: + env.Append(CPPDEFINES = ['HAVE_SOFTPIPE']) + env.Prepend(LIBS = [softpipe]) + +env['no_import_lib'] = 1 + +pyst = env.SharedLibrary( + target = '_gallium', + source = sources, +) + +env.Alias('python', pyst) diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c new file mode 100644 index 0000000..d0a4295 --- /dev/null +++ b/src/gallium/state_trackers/python/st_device.c @@ -0,0 +1,305 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_shader_tokens.h" +#include "util/u_inlines.h" +#include "cso_cache/cso_context.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_sampler.h" +#include "util/u_simple_shaders.h" +#include "trace/tr_public.h" + +#include "st_device.h" +#include "st_winsys.h" + + +static void +st_device_really_destroy(struct st_device *st_dev) +{ + if(st_dev->screen) { + /* FIXME: Don't really destroy until we keep track of every single + * reference or we end up causing a segmentation fault every time + * python exits. */ +#if 0 + st_dev->screen->destroy(st_dev->screen); +#endif + } + + FREE(st_dev); +} + + +static void +st_device_reference(struct st_device **ptr, struct st_device *st_dev) +{ + struct st_device *old_dev = *ptr; + + if (pipe_reference(&(*ptr)->reference, &st_dev->reference)) + st_device_really_destroy(old_dev); + *ptr = st_dev; +} + + +void +st_device_destroy(struct st_device *st_dev) +{ + st_device_reference(&st_dev, NULL); +} + + +struct st_device * +st_device_create(boolean hardware) +{ + struct pipe_screen *screen; + struct st_device *st_dev; + + if (hardware) + screen = st_hardware_screen_create(); + else + screen = st_software_screen_create("softpipe"); + + screen = trace_screen_create(screen); + if (!screen) + goto no_screen; + + st_dev = CALLOC_STRUCT(st_device); + if (!st_dev) + goto no_device; + + pipe_reference_init(&st_dev->reference, 1); + st_dev->screen = screen; + + return st_dev; + +no_device: + screen->destroy(screen); +no_screen: + return NULL; +} + + +void +st_context_destroy(struct st_context *st_ctx) +{ + unsigned i; + + if(st_ctx) { + struct st_device *st_dev = st_ctx->st_dev; + + if(st_ctx->cso) { + cso_delete_vertex_shader(st_ctx->cso, st_ctx->vs); + cso_delete_fragment_shader(st_ctx->cso, st_ctx->fs); + + cso_destroy_context(st_ctx->cso); + } + + if(st_ctx->pipe) + st_ctx->pipe->destroy(st_ctx->pipe); + + for(i = 0; i < PIPE_MAX_SAMPLERS; ++i) + pipe_sampler_view_reference(&st_ctx->fragment_sampler_views[i], NULL); + for(i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; ++i) + pipe_sampler_view_reference(&st_ctx->vertex_sampler_views[i], NULL); + pipe_resource_reference(&st_ctx->default_texture, NULL); + + FREE(st_ctx); + + st_device_reference(&st_dev, NULL); + } +} + + +struct st_context * +st_context_create(struct st_device *st_dev) +{ + struct st_context *st_ctx; + + st_ctx = CALLOC_STRUCT(st_context); + if(!st_ctx) + return NULL; + + st_device_reference(&st_ctx->st_dev, st_dev); + + st_ctx->pipe = st_dev->screen->context_create(st_dev->screen, NULL); + if(!st_ctx->pipe) { + st_context_destroy(st_ctx); + return NULL; + } + + st_ctx->cso = cso_create_context(st_ctx->pipe); + if(!st_ctx->cso) { + st_context_destroy(st_ctx); + return NULL; + } + + /* disabled blending/masking */ + { + struct pipe_blend_state blend; + memset(&blend, 0, sizeof(blend)); + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; + blend.rt[0].colormask = PIPE_MASK_RGBA; + cso_set_blend(st_ctx->cso, &blend); + } + + /* no-op depth/stencil/alpha */ + { + struct pipe_depth_stencil_alpha_state depthstencil; + memset(&depthstencil, 0, sizeof(depthstencil)); + cso_set_depth_stencil_alpha(st_ctx->cso, &depthstencil); + } + + /* rasterizer */ + { + struct pipe_rasterizer_state rasterizer; + memset(&rasterizer, 0, sizeof(rasterizer)); + rasterizer.cull_face = PIPE_FACE_NONE; + cso_set_rasterizer(st_ctx->cso, &rasterizer); + } + + /* clip */ + { + struct pipe_clip_state clip; + memset(&clip, 0, sizeof(clip)); + st_ctx->pipe->set_clip_state(st_ctx->pipe, &clip); + } + + /* identity viewport */ + { + struct pipe_viewport_state viewport; + viewport.scale[0] = 1.0; + viewport.scale[1] = 1.0; + viewport.scale[2] = 1.0; + viewport.scale[3] = 1.0; + viewport.translate[0] = 0.0; + viewport.translate[1] = 0.0; + viewport.translate[2] = 0.0; + viewport.translate[3] = 0.0; + cso_set_viewport(st_ctx->cso, &viewport); + } + + /* samplers */ + { + struct pipe_sampler_state sampler; + unsigned i; + memset(&sampler, 0, sizeof(sampler)); + sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; + sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST; + sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST; + sampler.normalized_coords = 1; + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) + cso_single_sampler(st_ctx->cso, i, &sampler); + cso_single_sampler_done(st_ctx->cso); + } + + /* default textures */ + { + struct pipe_context *pipe = st_ctx->pipe; + struct pipe_screen *screen = st_dev->screen; + struct pipe_resource templat; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; + unsigned i; + + memset( &templat, 0, sizeof( templat ) ); + templat.target = PIPE_TEXTURE_2D; + templat.format = PIPE_FORMAT_B8G8R8A8_UNORM; + templat.width0 = 1; + templat.height0 = 1; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.bind = PIPE_BIND_SAMPLER_VIEW; + + st_ctx->default_texture = screen->resource_create( screen, &templat ); + if(st_ctx->default_texture) { + struct pipe_box box; + uint32_t zero = 0; + + u_box_origin_2d( 1, 1, &box ); + + pipe->transfer_inline_write(pipe, + st_ctx->default_texture, + 0, + PIPE_TRANSFER_WRITE, + &box, + &zero, + sizeof zero, + 0); + } + + u_sampler_view_default_template(&view_templ, + st_ctx->default_texture, + st_ctx->default_texture->format); + view = st_ctx->pipe->create_sampler_view(st_ctx->pipe, + st_ctx->default_texture, + &view_templ); + + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) + pipe_sampler_view_reference(&st_ctx->fragment_sampler_views[i], view); + for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) + pipe_sampler_view_reference(&st_ctx->vertex_sampler_views[i], view); + + st_ctx->pipe->set_fragment_sampler_views(st_ctx->pipe, + PIPE_MAX_SAMPLERS, + st_ctx->fragment_sampler_views); + st_ctx->pipe->set_vertex_sampler_views(st_ctx->pipe, + PIPE_MAX_VERTEX_SAMPLERS, + st_ctx->vertex_sampler_views); + + pipe_sampler_view_reference(&view, NULL); + } + + /* vertex shader */ + { + const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, + TGSI_SEMANTIC_GENERIC }; + const uint semantic_indexes[] = { 0, 0 }; + st_ctx->vs = util_make_vertex_passthrough_shader(st_ctx->pipe, + 2, + semantic_names, + semantic_indexes); + cso_set_vertex_shader_handle(st_ctx->cso, st_ctx->vs); + } + + /* fragment shader */ + { + st_ctx->fs = util_make_fragment_passthrough_shader(st_ctx->pipe); + cso_set_fragment_shader_handle(st_ctx->cso, st_ctx->fs); + } + + return st_ctx; +} diff --git a/src/gallium/state_trackers/python/st_device.h b/src/gallium/state_trackers/python/st_device.h new file mode 100644 index 0000000..53e2556 --- /dev/null +++ b/src/gallium/state_trackers/python/st_device.h @@ -0,0 +1,111 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef ST_DEVICE_H_ +#define ST_DEVICE_H_ + + +#include "pipe/p_state.h" + +struct cso_context; +struct pipe_screen; +struct pipe_context; +struct st_winsys; + + +struct st_surface +{ + struct pipe_resource *texture; + unsigned level; + unsigned layer; +}; + + +struct st_context +{ + struct st_device *st_dev; + + struct pipe_context *pipe; + + struct cso_context *cso; + + void *vs; + void *fs; + void *gs; + + struct pipe_resource *default_texture; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; + + unsigned num_vertex_buffers; + struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS]; + + unsigned num_vertex_elements; + struct pipe_vertex_element vertex_elements[PIPE_MAX_ATTRIBS]; + + struct pipe_framebuffer_state framebuffer; +}; + + +struct st_device +{ + /* FIXME: we also need to refcount for textures and surfaces... */ + struct pipe_reference reference; + + struct pipe_screen *screen; +}; + + +static INLINE struct pipe_surface * +st_pipe_surface(struct pipe_context *pipe, struct st_surface *surface, unsigned usage) +{ + struct pipe_resource *texture = surface->texture; + struct pipe_surface surf_tmpl; + memset(&surf_tmpl, 0, sizeof(surf_tmpl)); + surf_tmpl.format = texture->format; + surf_tmpl.usage = usage; + surf_tmpl.u.tex.level = surface->level; + surf_tmpl.u.tex.first_layer = surface->layer; + surf_tmpl.u.tex.last_layer = surface->layer; + return pipe->create_surface(pipe, texture, &surf_tmpl); +} + +struct st_context * +st_context_create(struct st_device *st_dev); + +void +st_context_destroy(struct st_context *st_ctx); + +struct st_device * +st_device_create(boolean hardware); + +void +st_device_destroy(struct st_device *st_dev); + + +#endif /* ST_DEVICE_H_ */ diff --git a/src/gallium/state_trackers/python/st_hardpipe_winsys.c b/src/gallium/state_trackers/python/st_hardpipe_winsys.c new file mode 100644 index 0000000..c6743db --- /dev/null +++ b/src/gallium/state_trackers/python/st_hardpipe_winsys.c @@ -0,0 +1,212 @@ +/************************************************************************** + * + * Copyright 2008 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. + * + * + **************************************************************************/ + +/** + * @file + * Get a hardware accelerated Gallium screen/context from the OpenGL driver. + */ + + +#include "pipe/p_compiler.h" + +#ifdef PIPE_OS_WINDOWS +#include +#include +#else +#include +#include +#include +#include +#endif + +#include "st_winsys.h" + + +typedef struct pipe_screen * (GLAPIENTRY *PFNGETGALLIUMSCREENMESAPROC) (void); +typedef struct pipe_context * (GLAPIENTRY* PFNCREATEGALLIUMCONTEXTMESAPROC) (void); + +static PFNGETGALLIUMSCREENMESAPROC pfnGetGalliumScreenMESA = NULL; +static PFNCREATEGALLIUMCONTEXTMESAPROC pfnCreateGalliumContextMESA = NULL; + + +#ifdef PIPE_OS_WINDOWS + +static INLINE boolean +st_hardpipe_load(void) +{ + WNDCLASS wc; + HWND hwnd; + HGLRC hglrc; + HDC hdc; + PIXELFORMATDESCRIPTOR pfd; + int iPixelFormat; + + if(pfnGetGalliumScreenMESA && pfnCreateGalliumContextMESA) + return TRUE; + + memset(&wc, 0, sizeof wc); + wc.lpfnWndProc = DefWindowProc; + wc.lpszClassName = "gallium"; + wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; + RegisterClass(&wc); + + hwnd = CreateWindow(wc.lpszClassName, "gallium", 0, 0, 0, 0, 0, NULL, 0, wc.hInstance, NULL); + if (!hwnd) + return FALSE; + + hdc = GetDC(hwnd); + if (!hdc) + return FALSE; + + pfd.cColorBits = 3; + pfd.cRedBits = 1; + pfd.cGreenBits = 1; + pfd.cBlueBits = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; + pfd.iLayerType = PFD_MAIN_PLANE; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + + iPixelFormat = ChoosePixelFormat(hdc, &pfd); + if (!iPixelFormat) { + pfd.dwFlags |= PFD_DOUBLEBUFFER; + iPixelFormat = ChoosePixelFormat(hdc, &pfd); + } + if (!iPixelFormat) + return FALSE; + + SetPixelFormat(hdc, iPixelFormat, &pfd); + hglrc = wglCreateContext(hdc); + if (!hglrc) + return FALSE; + + if (!wglMakeCurrent(hdc, hglrc)) + return FALSE; + + pfnGetGalliumScreenMESA = (PFNGETGALLIUMSCREENMESAPROC)wglGetProcAddress("wglGetGalliumScreenMESA"); + if(!pfnGetGalliumScreenMESA) + return FALSE; + + pfnCreateGalliumContextMESA = (PFNCREATEGALLIUMCONTEXTMESAPROC)wglGetProcAddress("wglCreateGalliumContextMESA"); + if(!pfnCreateGalliumContextMESA) + return FALSE; + + DestroyWindow(hwnd); + + return TRUE; +} + +#else + +static INLINE boolean +st_hardpipe_load(void) +{ + Display *dpy; + int scrnum; + Window root; + int attribSingle[] = { + GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + None }; + int attribDouble[] = { + GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + None }; + XVisualInfo *visinfo; + GLXContext ctx = NULL; + XSetWindowAttributes attr; + unsigned long mask; + int width = 100, height = 100; + Window win; + + dpy = XOpenDisplay(NULL); + if (!dpy) + return FALSE; + + scrnum = 0; + + root = RootWindow(dpy, scrnum); + + visinfo = glXChooseVisual(dpy, scrnum, attribSingle); + if (!visinfo) + visinfo = glXChooseVisual(dpy, scrnum, attribDouble); + if (!visinfo) + return FALSE; + + ctx = glXCreateContext( dpy, visinfo, NULL, True ); + + if (!ctx) + return FALSE; + + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask; + + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow(dpy, root, 0, 0, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr); + + if (!glXMakeCurrent(dpy, win, ctx)) + return FALSE; + + pfnGetGalliumScreenMESA = (PFNGETGALLIUMSCREENMESAPROC)glXGetProcAddressARB((const GLubyte *)"glXGetGalliumScreenMESA"); + if(!pfnGetGalliumScreenMESA) + return FALSE; + + pfnCreateGalliumContextMESA = (PFNCREATEGALLIUMCONTEXTMESAPROC)glXGetProcAddressARB((const GLubyte *)"glXCreateGalliumContextMESA"); + if(!pfnCreateGalliumContextMESA) + return FALSE; + + glXDestroyContext(dpy, ctx); + XFree(visinfo); + XDestroyWindow(dpy, win); + XCloseDisplay(dpy); + + return TRUE; +} + +#endif + + +struct pipe_screen * +st_hardware_screen_create(void) +{ + if(st_hardpipe_load()) + return pfnGetGalliumScreenMESA(); + else + return st_software_screen_create(NULL); +} diff --git a/src/gallium/state_trackers/python/st_sample.c b/src/gallium/state_trackers/python/st_sample.c new file mode 100644 index 0000000..cac9a1a --- /dev/null +++ b/src/gallium/state_trackers/python/st_sample.c @@ -0,0 +1,594 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_tile.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "st_device.h" +#include "st_sample.h" + + +/** + * Use our own pseudo random generator to ensure consistent runs among + * multiple runs and platforms. + * + * @sa http://en.wikipedia.org/wiki/Linear_congruential_generator + */ +static uint32_t st_random(void) { + static uint64_t seed = UINT64_C(0xbb9a063afb0a739d); + + seed = UINT64_C(134775813) * seed + UINT64_C(1); + + return (uint32_t)(seed >> 32); +} + + +/** + * We don't want to include the patent-encumbered DXT code here, so instead + * we store several uncompressed/compressed data pairs for hardware testing + * purposes. + */ +struct dxt_data +{ + uint8_t rgba[16*4]; + uint8_t raw[16]; +}; + + +static const struct dxt_data +dxt1_rgb_data[] = { + { + { + 0x99, 0xb0, 0x8e, 0xff, + 0x5d, 0x62, 0x89, 0xff, + 0x99, 0xb0, 0x8e, 0xff, + 0x99, 0xb0, 0x8e, 0xff, + 0xd6, 0xff, 0x94, 0xff, + 0x5d, 0x62, 0x89, 0xff, + 0x99, 0xb0, 0x8e, 0xff, + 0xd6, 0xff, 0x94, 0xff, + 0x5d, 0x62, 0x89, 0xff, + 0x5d, 0x62, 0x89, 0xff, + 0x99, 0xb0, 0x8e, 0xff, + 0x21, 0x14, 0x84, 0xff, + 0x5d, 0x62, 0x89, 0xff, + 0x21, 0x14, 0x84, 0xff, + 0x21, 0x14, 0x84, 0xff, + 0x99, 0xb0, 0x8e, 0xff + }, + {0xf2, 0xd7, 0xb0, 0x20, 0xae, 0x2c, 0x6f, 0x97} + }, + { + { + 0xb5, 0xcf, 0x9c, 0xff, + 0x83, 0x8c, 0x8b, 0xff, + 0x21, 0x08, 0x6b, 0xff, + 0x83, 0x8c, 0x8b, 0xff, + 0x52, 0x4a, 0x7b, 0xff, + 0x83, 0x8c, 0x8b, 0xff, + 0x83, 0x8c, 0x8b, 0xff, + 0xb5, 0xcf, 0x9c, 0xff, + 0x21, 0x08, 0x6b, 0xff, + 0xb5, 0xcf, 0x9c, 0xff, + 0x83, 0x8c, 0x8b, 0xff, + 0x52, 0x4a, 0x7b, 0xff, + 0xb5, 0xcf, 0x9c, 0xff, + 0x83, 0x8c, 0x8b, 0xff, + 0x52, 0x4a, 0x7b, 0xff, + 0x83, 0x8c, 0x8b, 0xff + }, + {0x73, 0xb6, 0x4d, 0x20, 0x98, 0x2b, 0xe1, 0xb8} + }, + { + { + 0x00, 0x2c, 0xff, 0xff, + 0x94, 0x8d, 0x7b, 0xff, + 0x4a, 0x5c, 0xbd, 0xff, + 0x4a, 0x5c, 0xbd, 0xff, + 0x4a, 0x5c, 0xbd, 0xff, + 0x94, 0x8d, 0x7b, 0xff, + 0x94, 0x8d, 0x7b, 0xff, + 0x94, 0x8d, 0x7b, 0xff, + 0xde, 0xbe, 0x39, 0xff, + 0x94, 0x8d, 0x7b, 0xff, + 0xde, 0xbe, 0x39, 0xff, + 0xde, 0xbe, 0x39, 0xff, + 0xde, 0xbe, 0x39, 0xff, + 0xde, 0xbe, 0x39, 0xff, + 0xde, 0xbe, 0x39, 0xff, + 0x94, 0x8d, 0x7b, 0xff + }, + {0xe7, 0xdd, 0x7f, 0x01, 0xf9, 0xab, 0x08, 0x80} + }, + { + { + 0x6b, 0x24, 0x21, 0xff, + 0x7b, 0x4f, 0x5d, 0xff, + 0x7b, 0x4f, 0x5d, 0xff, + 0x8b, 0x7a, 0x99, 0xff, + 0x7b, 0x4f, 0x5d, 0xff, + 0x7b, 0x4f, 0x5d, 0xff, + 0x6b, 0x24, 0x21, 0xff, + 0x8b, 0x7a, 0x99, 0xff, + 0x9c, 0xa6, 0xd6, 0xff, + 0x6b, 0x24, 0x21, 0xff, + 0x7b, 0x4f, 0x5d, 0xff, + 0x8b, 0x7a, 0x99, 0xff, + 0x6b, 0x24, 0x21, 0xff, + 0x8b, 0x7a, 0x99, 0xff, + 0x7b, 0x4f, 0x5d, 0xff, + 0x9c, 0xa6, 0xd6, 0xff + }, + {0x3a, 0x9d, 0x24, 0x69, 0xbd, 0x9f, 0xb4, 0x39} + } +}; + + +static const struct dxt_data +dxt1_rgba_data[] = { + { + { + 0x00, 0x00, 0x00, 0x00, + 0x4e, 0xaa, 0x90, 0xff, + 0x4e, 0xaa, 0x90, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x4e, 0xaa, 0x90, 0xff, + 0x29, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x4e, 0xaa, 0x90, 0xff, + 0x73, 0x55, 0x21, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x4e, 0xaa, 0x90, 0xff, + 0x4e, 0xaa, 0x90, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x4e, 0xaa, 0x90, 0xff + }, + {0xff, 0x2f, 0xa4, 0x72, 0xeb, 0xb2, 0xbd, 0xbe} + }, + { + { + 0xb5, 0xe3, 0x63, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x6b, 0x24, 0x84, 0xff, + 0xb5, 0xe3, 0x63, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0xb5, 0xe3, 0x63, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x6b, 0x24, 0x84, 0xff, + 0x6b, 0x24, 0x84, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0xb5, 0xe3, 0x63, 0xff, + 0x90, 0x83, 0x73, 0xff, + 0xb5, 0xe3, 0x63, 0xff + }, + {0x30, 0x69, 0x0c, 0xb7, 0x4d, 0xf7, 0x0f, 0x67} + }, + { + { + 0x00, 0x00, 0x00, 0x00, + 0xc6, 0x86, 0x8c, 0xff, + 0xc6, 0x86, 0x8c, 0xff, + 0x21, 0x65, 0x42, 0xff, + 0x21, 0x65, 0x42, 0xff, + 0x21, 0x65, 0x42, 0xff, + 0x21, 0x65, 0x42, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x21, 0x65, 0x42, 0xff, + 0xc6, 0x86, 0x8c, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0xc6, 0x86, 0x8c, 0xff + }, + {0x28, 0x23, 0x31, 0xc4, 0x17, 0xc0, 0xd3, 0x7f} + }, + { + { + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0xc6, 0xe3, 0x9c, 0xff, + 0x7b, 0x1c, 0x52, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x7b, 0x1c, 0x52, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x7b, 0x1c, 0x52, 0xff, + 0xa0, 0x7f, 0x77, 0xff, + 0xc6, 0xe3, 0x9c, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0xa0, 0x7f, 0x77, 0xff + }, + {0xea, 0x78, 0x13, 0xc7, 0x7f, 0xfc, 0x33, 0xb6} + }, +}; + + +static const struct dxt_data +dxt3_rgba_data[] = { + { + { + 0x6d, 0xc6, 0x96, 0x77, + 0x6d, 0xc6, 0x96, 0xee, + 0x6d, 0xc6, 0x96, 0xaa, + 0x8c, 0xff, 0xb5, 0x44, + 0x6d, 0xc6, 0x96, 0xff, + 0x6d, 0xc6, 0x96, 0x88, + 0x31, 0x55, 0x5a, 0x66, + 0x6d, 0xc6, 0x96, 0x99, + 0x31, 0x55, 0x5a, 0xbb, + 0x31, 0x55, 0x5a, 0x55, + 0x31, 0x55, 0x5a, 0x11, + 0x6d, 0xc6, 0x96, 0xcc, + 0x6d, 0xc6, 0x96, 0xcc, + 0x6d, 0xc6, 0x96, 0x11, + 0x31, 0x55, 0x5a, 0x44, + 0x31, 0x55, 0x5a, 0x88 + }, + {0xe7, 0x4a, 0x8f, 0x96, 0x5b, 0xc1, 0x1c, 0x84, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a} + }, + { + { + 0xad, 0xeb, 0x73, 0x99, + 0x97, 0xaa, 0x86, 0x66, + 0x6b, 0x28, 0xad, 0x99, + 0xad, 0xeb, 0x73, 0x99, + 0x6b, 0x28, 0xad, 0x22, + 0xad, 0xeb, 0x73, 0xff, + 0x97, 0xaa, 0x86, 0x55, + 0x6b, 0x28, 0xad, 0x55, + 0x6b, 0x28, 0xad, 0x44, + 0xad, 0xeb, 0x73, 0x33, + 0x6b, 0x28, 0xad, 0xee, + 0x6b, 0x28, 0xad, 0x99, + 0x97, 0xaa, 0x86, 0x66, + 0xad, 0xeb, 0x73, 0xbb, + 0x97, 0xaa, 0x86, 0x99, + 0xad, 0xeb, 0x73, 0xbb + }, + {0x69, 0x99, 0xf2, 0x55, 0x34, 0x9e, 0xb6, 0xb9, 0x4e, 0xaf, 0x55, 0x69, 0x18, 0x61, 0x51, 0x22} + }, + { + { + 0x63, 0xd7, 0xd6, 0x00, + 0x57, 0x62, 0x5d, 0xdd, + 0x57, 0x62, 0x5d, 0xcc, + 0x57, 0x62, 0x5d, 0xbb, + 0x52, 0x28, 0x21, 0xaa, + 0x57, 0x62, 0x5d, 0xcc, + 0x57, 0x62, 0x5d, 0xcc, + 0x57, 0x62, 0x5d, 0x66, + 0x57, 0x62, 0x5d, 0x22, + 0x57, 0x62, 0x5d, 0xdd, + 0x63, 0xd7, 0xd6, 0xee, + 0x57, 0x62, 0x5d, 0x33, + 0x63, 0xd7, 0xd6, 0x55, + 0x52, 0x28, 0x21, 0x55, + 0x57, 0x62, 0x5d, 0x11, + 0x5d, 0x9c, 0x99, 0xee + }, + {0xd0, 0xbc, 0xca, 0x6c, 0xd2, 0x3e, 0x55, 0xe1, 0xba, 0x66, 0x44, 0x51, 0xfc, 0xfd, 0xcf, 0xb4} + }, + { + { + 0x94, 0x6f, 0x60, 0x22, + 0x94, 0x6f, 0x60, 0x22, + 0xc5, 0xab, 0x76, 0x11, + 0xc5, 0xab, 0x76, 0xee, + 0x63, 0x34, 0x4a, 0xdd, + 0x63, 0x34, 0x4a, 0x33, + 0x94, 0x6f, 0x60, 0x77, + 0xf7, 0xe7, 0x8c, 0x00, + 0x94, 0x6f, 0x60, 0x33, + 0x63, 0x34, 0x4a, 0xaa, + 0x94, 0x6f, 0x60, 0x77, + 0x63, 0x34, 0x4a, 0xcc, + 0x94, 0x6f, 0x60, 0xaa, + 0xf7, 0xe7, 0x8c, 0x99, + 0x63, 0x34, 0x4a, 0x44, + 0xc5, 0xab, 0x76, 0xaa + }, + {0x22, 0xe1, 0x3d, 0x07, 0xa3, 0xc7, 0x9a, 0xa4, 0x31, 0xf7, 0xa9, 0x61, 0xaf, 0x35, 0x77, 0x93} + }, +}; + + +static const struct dxt_data +dxt5_rgba_data[] = { + { + { + 0x6d, 0xc6, 0x96, 0x74, + 0x6d, 0xc6, 0x96, 0xf8, + 0x6d, 0xc6, 0x96, 0xb6, + 0x8c, 0xff, 0xb5, 0x53, + 0x6d, 0xc6, 0x96, 0xf8, + 0x6d, 0xc6, 0x96, 0x95, + 0x31, 0x55, 0x5a, 0x53, + 0x6d, 0xc6, 0x96, 0x95, + 0x31, 0x55, 0x5a, 0xb6, + 0x31, 0x55, 0x5a, 0x53, + 0x31, 0x55, 0x5a, 0x11, + 0x6d, 0xc6, 0x96, 0xd7, + 0x6d, 0xc6, 0x96, 0xb6, + 0x6d, 0xc6, 0x96, 0x11, + 0x31, 0x55, 0x5a, 0x32, + 0x31, 0x55, 0x5a, 0x95 + }, + {0xf8, 0x11, 0xc5, 0x0c, 0x9a, 0x73, 0xb4, 0x9c, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a} + }, + { + { + 0xad, 0xeb, 0x73, 0xa1, + 0x97, 0xaa, 0x86, 0x65, + 0x6b, 0x28, 0xad, 0xa1, + 0xad, 0xeb, 0x73, 0xa1, + 0x6b, 0x28, 0xad, 0x2a, + 0xad, 0xeb, 0x73, 0xfb, + 0x97, 0xaa, 0x86, 0x47, + 0x6b, 0x28, 0xad, 0x65, + 0x6b, 0x28, 0xad, 0x47, + 0xad, 0xeb, 0x73, 0x47, + 0x6b, 0x28, 0xad, 0xdd, + 0x6b, 0x28, 0xad, 0xa1, + 0x97, 0xaa, 0x86, 0x65, + 0xad, 0xeb, 0x73, 0xbf, + 0x97, 0xaa, 0x86, 0xa1, + 0xad, 0xeb, 0x73, 0xbf + }, + {0xfb, 0x2a, 0x34, 0x19, 0xdc, 0xbf, 0xe8, 0x71, 0x4e, 0xaf, 0x55, 0x69, 0x18, 0x61, 0x51, 0x22} + }, + { + { + 0x63, 0xd7, 0xd6, 0x00, + 0x57, 0x62, 0x5d, 0xf5, + 0x57, 0x62, 0x5d, 0xd2, + 0x57, 0x62, 0x5d, 0xaf, + 0x52, 0x28, 0x21, 0xaf, + 0x57, 0x62, 0x5d, 0xd2, + 0x57, 0x62, 0x5d, 0xd2, + 0x57, 0x62, 0x5d, 0x69, + 0x57, 0x62, 0x5d, 0x23, + 0x57, 0x62, 0x5d, 0xd2, + 0x63, 0xd7, 0xd6, 0xf5, + 0x57, 0x62, 0x5d, 0x46, + 0x63, 0xd7, 0xd6, 0x46, + 0x52, 0x28, 0x21, 0x69, + 0x57, 0x62, 0x5d, 0x23, + 0x5d, 0x9c, 0x99, 0xf5 + }, + {0xf5, 0x00, 0x81, 0x36, 0xa9, 0x17, 0xec, 0x1e, 0xba, 0x66, 0x44, 0x51, 0xfc, 0xfd, 0xcf, 0xb4} + }, + { + { + 0x94, 0x6f, 0x60, 0x25, + 0x94, 0x6f, 0x60, 0x25, + 0xc5, 0xab, 0x76, 0x05, + 0xc5, 0xab, 0x76, 0xe8, + 0x63, 0x34, 0x4a, 0xe8, + 0x63, 0x34, 0x4a, 0x25, + 0x94, 0x6f, 0x60, 0x86, + 0xf7, 0xe7, 0x8c, 0x05, + 0x94, 0x6f, 0x60, 0x25, + 0x63, 0x34, 0x4a, 0xa7, + 0x94, 0x6f, 0x60, 0x66, + 0x63, 0x34, 0x4a, 0xc7, + 0x94, 0x6f, 0x60, 0xa7, + 0xf7, 0xe7, 0x8c, 0xa7, + 0x63, 0x34, 0x4a, 0x45, + 0xc5, 0xab, 0x76, 0xa7 + }, + {0xe8, 0x05, 0x7f, 0x80, 0x33, 0x5f, 0xb5, 0x79, 0x31, 0xf7, 0xa9, 0x61, 0xaf, 0x35, 0x77, 0x93} + }, +}; + + +static INLINE void +st_sample_dxt_pixel_block(enum pipe_format format, + uint8_t *raw, + float *rgba, unsigned rgba_stride, + unsigned w, unsigned h) +{ + const struct dxt_data *data; + unsigned n; + unsigned i; + unsigned x, y, ch; + + switch(format) { + case PIPE_FORMAT_DXT1_RGB: + data = dxt1_rgb_data; + n = sizeof(dxt1_rgb_data)/sizeof(dxt1_rgb_data[0]); + break; + case PIPE_FORMAT_DXT1_RGBA: + data = dxt1_rgba_data; + n = sizeof(dxt1_rgba_data)/sizeof(dxt1_rgba_data[0]); + break; + case PIPE_FORMAT_DXT3_RGBA: + data = dxt3_rgba_data; + n = sizeof(dxt3_rgba_data)/sizeof(dxt3_rgba_data[0]); + break; + case PIPE_FORMAT_DXT5_RGBA: + data = dxt5_rgba_data; + n = sizeof(dxt5_rgba_data)/sizeof(dxt5_rgba_data[0]); + break; + default: + assert(0); + return; + } + + i = st_random() % n; + + for(y = 0; y < h; ++y) + for(x = 0; x < w; ++x) + for(ch = 0; ch < 4; ++ch) + rgba[y*rgba_stride + x*4 + ch] = (float)(data[i].rgba[y*4*4 + x*4 + ch])/255.0f; + + memcpy(raw, data[i].raw, util_format_get_blocksize(format)); +} + + +static INLINE void +st_sample_generic_pixel_block(enum pipe_format format, + uint8_t *raw, + float *rgba, unsigned rgba_stride, + unsigned w, unsigned h, + boolean norm) +{ + unsigned i; + unsigned x, y, ch; + int blocksize = util_format_get_blocksize(format); + + if (norm) { + for (y = 0; y < h; ++y) { + for (x = 0; x < w; ++x) { + for (ch = 0; ch < 4; ++ch) { + unsigned offset = y*rgba_stride + x*4 + ch; + rgba[offset] = (st_random() & 0xff) / (double)0xff; + } + } + } + + util_format_write_4f(format, + rgba, rgba_stride * sizeof(float), + raw, util_format_get_stride(format, w), + 0, 0, w, h); + + } else { + for (i = 0; i < blocksize; ++i) + raw[i] = (uint8_t)st_random(); + } + + util_format_read_4f(format, + rgba, rgba_stride * sizeof(float), + raw, util_format_get_stride(format, w), + 0, 0, w, h); + + if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) { + for (y = 0; y < h; ++y) { + for (x = 0; x < w; ++x) { + for (ch = 0; ch < 4; ++ch) { + unsigned offset = y*rgba_stride + x*4 + ch; + rgba[offset] = CLAMP(rgba[offset], 0.0f, 1.0f); + } + } + } + } +} + + +/** + * Randomly sample pixels. + */ +void +st_sample_pixel_block(enum pipe_format format, + void *raw, + float *rgba, unsigned rgba_stride, + unsigned w, unsigned h, + boolean norm) +{ + switch(format) { + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + case PIPE_FORMAT_DXT3_RGBA: + case PIPE_FORMAT_DXT5_RGBA: + st_sample_dxt_pixel_block(format, raw, rgba, rgba_stride, w, h); + break; + + default: + st_sample_generic_pixel_block(format, raw, rgba, rgba_stride, w, h, norm); + break; + } +} + + +void +st_sample_surface(struct pipe_context *pipe, + struct st_surface *surface, + float *rgba, + boolean norm) +{ + struct pipe_resource *texture = surface->texture; + unsigned width = u_minify(texture->width0, surface->level); + unsigned height = u_minify(texture->height0, surface->level); + uint rgba_stride = width * 4; + struct pipe_transfer *transfer; + void *raw; + + transfer = pipe_get_transfer(pipe, + surface->texture, + surface->level, + surface->layer, + PIPE_TRANSFER_WRITE, + 0, 0, + width, + height); + if (!transfer) + return; + + raw = pipe->transfer_map(pipe, transfer); + if (raw) { + enum pipe_format format = texture->format; + uint x, y; + int nblocksx = util_format_get_nblocksx(format, width); + int nblocksy = util_format_get_nblocksy(format, height); + int blockwidth = util_format_get_blockwidth(format); + int blockheight = util_format_get_blockheight(format); + int blocksize = util_format_get_blocksize(format); + + + for (y = 0; y < nblocksy; ++y) { + for (x = 0; x < nblocksx; ++x) { + st_sample_pixel_block(format, + (uint8_t *) raw + y * transfer->stride + x * blocksize, + rgba + y * blockheight * rgba_stride + x * blockwidth * 4, + rgba_stride, + MIN2(blockwidth, width - x*blockwidth), + MIN2(blockheight, height - y*blockheight), + norm); + } + } + + pipe->transfer_unmap(pipe, transfer); + } + + pipe->transfer_destroy(pipe, transfer); +} diff --git a/src/gallium/state_trackers/python/st_sample.h b/src/gallium/state_trackers/python/st_sample.h new file mode 100644 index 0000000..2fdbb39 --- /dev/null +++ b/src/gallium/state_trackers/python/st_sample.h @@ -0,0 +1,53 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef ST_SAMPLE_H_ +#define ST_SAMPLE_H_ + + +#include "pipe/p_format.h" + +struct pipe_context; +struct st_surface; + + +void +st_sample_pixel_block(enum pipe_format format, + void *raw, + float *rgba, unsigned rgba_stride, + unsigned w, unsigned h, + boolean norm); + +void +st_sample_surface(struct pipe_context *pipe, + struct st_surface *surface, + float *rgba, + boolean norm); + + +#endif /* ST_SAMPLE_H_ */ diff --git a/src/gallium/state_trackers/python/st_softpipe_winsys.c b/src/gallium/state_trackers/python/st_softpipe_winsys.c new file mode 100644 index 0000000..8584bad --- /dev/null +++ b/src/gallium/state_trackers/python/st_softpipe_winsys.c @@ -0,0 +1,78 @@ +/************************************************************************** + * + * 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. + * + * + **************************************************************************/ + +#include "util/u_debug.h" +#include "softpipe/sp_public.h" +#include "llvmpipe/lp_public.h" +#include "state_tracker/sw_winsys.h" +#include "sw/null/null_sw_winsys.h" +#include "st_winsys.h" + + +struct pipe_screen * +st_software_screen_create(const char *driver) +{ + struct sw_winsys *ws; + struct pipe_screen *screen = NULL; + + if (!driver) { + const char *default_driver; + +#if defined(HAVE_LLVMPIPE) + default_driver = "llvmpipe"; +#elif defined(HAVE_SOFTPIPE) + default_driver = "softpipe"; +#else + default_driver = ""; +#endif + + driver = debug_get_option("GALLIUM_DRIVER", default_driver); + } + + ws = null_sw_create(); + if(!ws) + return NULL; + +#ifdef HAVE_LLVMPIPE + if (strcmp(driver, "llvmpipe") == 0) { + screen = llvmpipe_create_screen(ws); + } +#endif + +#ifdef HAVE_SOFTPIPE + if (strcmp(driver, "softpipe") == 0) { + screen = softpipe_create_screen(ws); + } +#endif + + if (!screen) { + ws->destroy(ws); + } + + return screen; +} diff --git a/src/gallium/state_trackers/python/st_winsys.h b/src/gallium/state_trackers/python/st_winsys.h new file mode 100644 index 0000000..7d4066d --- /dev/null +++ b/src/gallium/state_trackers/python/st_winsys.h @@ -0,0 +1,43 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef ST_WINSYS_H_ +#define ST_WINSYS_H_ + + +struct pipe_screen; + + +struct pipe_screen * +st_hardware_screen_create(void); + +struct pipe_screen * +st_software_screen_create(const char *driver); + + +#endif /* ST_WINSYS_H_ */ diff --git a/src/gallium/state_trackers/vega/Makefile b/src/gallium/state_trackers/vega/Makefile new file mode 100644 index 0000000..7342c12 --- /dev/null +++ b/src/gallium/state_trackers/vega/Makefile @@ -0,0 +1,51 @@ +# src/gallium/state_trackers/vega/Makefile + +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = vega + +LIBRARY_INCLUDES = \ + -I$(TOP)/include \ + -I$(TOP)/src/mapi + +LIBRARY_DEFINES = \ + -DVEGA_VERSION_STRING=\"$(MESA_VERSION)\" + +C_SOURCES = \ + api.c \ + api_context.c \ + api_filters.c \ + api_images.c \ + api_masks.c \ + api_misc.c \ + api_paint.c \ + api_params.c \ + api_path.c \ + api_text.c \ + api_transform.c \ + vgu.c \ + vg_context.c \ + vg_manager.c \ + vg_state.c \ + vg_translate.c \ + polygon.c \ + bezier.c \ + path.c \ + paint.c \ + arc.c \ + image.c \ + renderer.c \ + stroker.c \ + mask.c \ + text.c \ + shader.c \ + shaders_cache.c + +GENERATED_SOURCES := api_tmp.h + +include ../../Makefile.template + +MAPI := $(TOP)/src/mapi +api_tmp.h: $(MAPI)/mapi/mapi_abi.py $(MAPI)/vgapi/vgapi.csv + $(PYTHON2) $< --printer vgapi --mode app $(MAPI)/vgapi/vgapi.csv > $@ diff --git a/src/gallium/state_trackers/vega/SConscript b/src/gallium/state_trackers/vega/SConscript new file mode 100644 index 0000000..4900135 --- /dev/null +++ b/src/gallium/state_trackers/vega/SConscript @@ -0,0 +1,61 @@ +####################################################################### +# SConscript for vega state_tracker + +Import('*') + +from sys import executable as python_cmd + +env = env.Clone() + +env.Append(CPPPATH = [ + '#/src/mapi', +]) +env.Append(CPPDEFINES = [ + 'VEGA_VERSION_STRING=', +]) + +vega_sources = [ + 'api.c', + 'api_context.c', + 'api_filters.c', + 'api_images.c', + 'api_masks.c', + 'api_misc.c', + 'api_paint.c', + 'api_params.c', + 'api_path.c', + 'api_text.c', + 'api_transform.c', + 'vgu.c', + 'vg_context.c', + 'vg_manager.c', + 'vg_state.c', + 'vg_translate.c', + 'polygon.c', + 'bezier.c', + 'path.c', + 'paint.c', + 'arc.c', + 'image.c', + 'renderer.c', + 'stroker.c', + 'mask.c', + 'shader.c', + 'shaders_cache.c', + 'text.c', +] + +api_tmp = env.CodeGenerate( + target = '#/src/gallium/state_trackers/vega/api_tmp.h', + script = '#src/mapi/mapi/mapi_abi.py', + source = '#src/mapi/vgapi/vgapi.csv', + command = python_cmd + ' $SCRIPT --printer vgapi --mode app $SOURCE > $TARGET' +) +env.Depends(vega_sources, api_tmp) + +st_vega = env.ConvenienceLibrary( + target = 'st_vega', + source = vega_sources, +) + +Export('st_vega') diff --git a/src/gallium/state_trackers/vega/api.c b/src/gallium/state_trackers/vega/api.c new file mode 100644 index 0000000..4bf7c71 --- /dev/null +++ b/src/gallium/state_trackers/vega/api.c @@ -0,0 +1,75 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "mapi/mapi.h" + +/* define vega_spec and vega_procs for use with mapi */ +#define API_TMP_DEFINE_SPEC +#include "api.h" + +static void api_init(void) +{ + static boolean initialized = FALSE; + if (!initialized) { + mapi_init(vega_spec); + initialized = TRUE; + } +} + +struct mapi_table *api_create_dispatch(void) +{ + struct mapi_table *tbl; + + api_init(); + + tbl = mapi_table_create(); + if (tbl) + mapi_table_fill(tbl, vega_procs); + + return tbl; +} + +void api_destroy_dispatch(struct mapi_table *tbl) +{ + mapi_table_destroy(tbl); +} + +void api_make_dispatch_current(const struct mapi_table *tbl) +{ + mapi_table_make_current(tbl); +} + +mapi_proc api_get_proc_address(const char *proc_name) +{ + if (!proc_name || proc_name[0] != 'v' || proc_name[1] != 'g') + return NULL; + proc_name += 2; + + api_init(); + return mapi_get_proc_address(proc_name); +} diff --git a/src/gallium/state_trackers/vega/api.h b/src/gallium/state_trackers/vega/api.h new file mode 100644 index 0000000..459dafb --- /dev/null +++ b/src/gallium/state_trackers/vega/api.h @@ -0,0 +1,48 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef API_H +#define API_H + +#include "VG/openvg.h" +#include "VG/vgext.h" +#include "vg_manager.h" + +#include "api_tmp.h" + +struct mapi_table; + +struct mapi_table *api_create_dispatch(void); + +void api_destroy_dispatch(struct mapi_table *tbl); + +void api_make_dispatch_current(const struct mapi_table *tbl); + +st_proc_t api_get_proc_address(const char *proc_name); + +#endif /* API_H */ diff --git a/src/gallium/state_trackers/vega/api_consts.h b/src/gallium/state_trackers/vega/api_consts.h new file mode 100644 index 0000000..e1b48d4 --- /dev/null +++ b/src/gallium/state_trackers/vega/api_consts.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, 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 API_CONSTS_H +#define API_CONSTS_H + +/*must be at least 32*/ +#define VEGA_MAX_SCISSOR_RECTS 32 + +/*must be at least 16*/ +#define VEGA_MAX_DASH_COUNT 32 + +/*must be at least 7*/ +#define VEGA_MAX_KERNEL_SIZE 7 + +/*must be at least 15*/ +#define VEGA_MAX_SEPARABLE_KERNEL_SIZE 15 + +/*must be at least 32*/ +#define VEGA_MAX_COLOR_RAMP_STOPS 256 + +#define VEGA_MAX_IMAGE_WIDTH 2048 + +#define VEGA_MAX_IMAGE_HEIGHT 2048 + +#define VEGA_MAX_IMAGE_PIXELS (2048*2048) + +#define VEGA_MAX_IMAGE_BYTES (2048*2048 * 4) + +/*must be at least 128*/ +#define VEGA_MAX_GAUSSIAN_STD_DEVIATION 128 + +#endif diff --git a/src/gallium/state_trackers/vega/api_context.c b/src/gallium/state_trackers/vega/api_context.c new file mode 100644 index 0000000..d6bbda5 --- /dev/null +++ b/src/gallium/state_trackers/vega/api_context.c @@ -0,0 +1,80 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "VG/openvg.h" + +#include "vg_manager.h" +#include "vg_context.h" +#include "api.h" + +#include "pipe/p_context.h" +#include "pipe/p_screen.h" + +VGErrorCode vegaGetError(void) +{ + struct vg_context *ctx = vg_current_context(); + VGErrorCode error = VG_NO_CONTEXT_ERROR; + + if (!ctx) + return error; + + error = ctx->_error; + ctx->_error = VG_NO_ERROR; + + return error; +} + +void vegaFlush(void) +{ + struct vg_context *ctx = vg_current_context(); + struct pipe_context *pipe; + + if (!ctx) + return; + + pipe = ctx->pipe; + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + + vg_manager_flush_frontbuffer(ctx); +} + +void vegaFinish(void) +{ + struct vg_context *ctx = vg_current_context(); + struct pipe_fence_handle *fence = NULL; + struct pipe_context *pipe; + + if (!ctx) + return; + + pipe = ctx->pipe; + + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, &fence); + if (fence) { + pipe->screen->fence_finish(pipe->screen, fence, 0); + pipe->screen->fence_reference(pipe->screen, &fence, NULL); + } +} diff --git a/src/gallium/state_trackers/vega/api_filters.c b/src/gallium/state_trackers/vega/api_filters.c new file mode 100644 index 0000000..724e382 --- /dev/null +++ b/src/gallium/state_trackers/vega/api_filters.c @@ -0,0 +1,704 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "VG/openvg.h" + +#include "vg_context.h" +#include "image.h" +#include "api.h" +#include "renderer.h" +#include "shaders_cache.h" + +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "pipe/p_screen.h" + +#include "util/u_format.h" +#include "util/u_sampler.h" +#include "util/u_string.h" + +#include "asm_filters.h" + + +struct filter_info { + struct vg_image *dst; + struct vg_image *src; + struct vg_shader * (*setup_shader)(struct vg_context *, void *); + void *user_data; + const void *const_buffer; + VGint const_buffer_len; + VGTilingMode tiling_mode; + struct pipe_sampler_view *extra_texture_view; +}; + +static INLINE struct pipe_resource *create_texture_1d(struct vg_context *ctx, + const VGuint *color_data, + const VGint color_data_len) +{ + struct pipe_context *pipe = ctx->pipe; + struct pipe_screen *screen = pipe->screen; + struct pipe_resource *tex = 0; + struct pipe_resource templ; + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_1D; + templ.format = PIPE_FORMAT_B8G8R8A8_UNORM; + templ.last_level = 0; + templ.width0 = color_data_len; + templ.height0 = 1; + templ.depth0 = 1; + templ.array_size = 1; + templ.bind = PIPE_BIND_SAMPLER_VIEW; + + tex = screen->resource_create(screen, &templ); + + { /* upload color_data */ + struct pipe_transfer *transfer = + pipe_get_transfer(pipe, tex, + 0, 0, + PIPE_TRANSFER_READ_WRITE , + 0, 0, tex->width0, tex->height0); + void *map = pipe->transfer_map(pipe, transfer); + memcpy(map, color_data, sizeof(VGint)*color_data_len); + pipe->transfer_unmap(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); + } + + return tex; +} + +static INLINE struct pipe_sampler_view *create_texture_1d_view(struct vg_context *ctx, + const VGuint *color_data, + const VGint color_data_len) +{ + struct pipe_context *pipe = ctx->pipe; + struct pipe_resource *texture; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; + + texture = create_texture_1d(ctx, color_data, color_data_len); + + if (!texture) + return NULL; + + u_sampler_view_default_template(&view_templ, texture, texture->format); + view = pipe->create_sampler_view(pipe, texture, &view_templ); + /* want the texture to go away if the view is freed */ + pipe_resource_reference(&texture, NULL); + + return view; +} + +static struct vg_shader * setup_color_matrix(struct vg_context *ctx, void *user_data) +{ + struct vg_shader *shader = + shader_create_from_text(ctx->pipe, color_matrix_asm, 200, + PIPE_SHADER_FRAGMENT); + return shader; +} + +static struct vg_shader * setup_convolution(struct vg_context *ctx, void *user_data) +{ + char buffer[1024]; + VGint num_consts = (VGint)(long)(user_data); + struct vg_shader *shader; + + util_snprintf(buffer, 1023, convolution_asm, num_consts, num_consts / 2 + 1); + + shader = shader_create_from_text(ctx->pipe, buffer, 200, + PIPE_SHADER_FRAGMENT); + + return shader; +} + +static struct vg_shader * setup_lookup(struct vg_context *ctx, void *user_data) +{ + struct vg_shader *shader = + shader_create_from_text(ctx->pipe, lookup_asm, + 200, PIPE_SHADER_FRAGMENT); + + return shader; +} + + +static struct vg_shader * setup_lookup_single(struct vg_context *ctx, void *user_data) +{ + char buffer[1024]; + VGImageChannel channel = (VGImageChannel)(user_data); + struct vg_shader *shader; + + switch(channel) { + case VG_RED: + util_snprintf(buffer, 1023, lookup_single_asm, "xxxx"); + break; + case VG_GREEN: + util_snprintf(buffer, 1023, lookup_single_asm, "yyyy"); + break; + case VG_BLUE: + util_snprintf(buffer, 1023, lookup_single_asm, "zzzz"); + break; + case VG_ALPHA: + util_snprintf(buffer, 1023, lookup_single_asm, "wwww"); + break; + default: + debug_assert(!"Unknown color channel"); + } + + shader = shader_create_from_text(ctx->pipe, buffer, 200, + PIPE_SHADER_FRAGMENT); + + return shader; +} + +static void execute_filter(struct vg_context *ctx, + struct filter_info *info) +{ + struct vg_shader *shader; + const struct pipe_sampler_state *samplers[2]; + struct pipe_sampler_view *views[2]; + struct pipe_sampler_state sampler; + uint tex_wrap; + + memset(&sampler, 0, sizeof(sampler)); + sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR; + sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR; + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + sampler.normalized_coords = 1; + + switch (info->tiling_mode) { + case VG_TILE_FILL: + tex_wrap = PIPE_TEX_WRAP_CLAMP_TO_BORDER; + /* copy border color */ + memcpy(sampler.border_color, ctx->state.vg.tile_fill_color, + sizeof(sampler.border_color)); + break; + case VG_TILE_PAD: + tex_wrap = PIPE_TEX_WRAP_CLAMP_TO_EDGE;; + break; + case VG_TILE_REPEAT: + tex_wrap = PIPE_TEX_WRAP_REPEAT;; + break; + case VG_TILE_REFLECT: + tex_wrap = PIPE_TEX_WRAP_MIRROR_REPEAT; + break; + default: + debug_assert(!"Unknown tiling mode"); + tex_wrap = 0; + break; + } + + sampler.wrap_s = tex_wrap; + sampler.wrap_t = tex_wrap; + sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + + samplers[0] = samplers[1] = &sampler; + views[0] = info->src->sampler_view; + views[1] = info->extra_texture_view; + + shader = info->setup_shader(ctx, info->user_data); + + if (renderer_filter_begin(ctx->renderer, + info->dst->sampler_view->texture, VG_TRUE, + ctx->state.vg.filter_channel_mask, + samplers, views, (info->extra_texture_view) ? 2 : 1, + shader->driver, info->const_buffer, info->const_buffer_len)) { + renderer_filter(ctx->renderer, + info->dst->x, info->dst->y, info->dst->width, info->dst->height, + info->src->x, info->src->y, info->src->width, info->src->height); + renderer_filter_end(ctx->renderer); + } + + vg_shader_destroy(ctx, shader); +} + +void vegaColorMatrix(VGImage dst, VGImage src, + const VGfloat * matrix) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_image *d, *s; + struct filter_info info; + + if (dst == VG_INVALID_HANDLE || src == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (!matrix || !is_aligned(matrix)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + d = (struct vg_image*)dst; + s = (struct vg_image*)src; + + if (vg_image_overlaps(d, s)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + info.dst = d; + info.src = s; + info.setup_shader = &setup_color_matrix; + info.user_data = NULL; + info.const_buffer = matrix; + info.const_buffer_len = 20 * sizeof(VGfloat); + info.tiling_mode = VG_TILE_PAD; + info.extra_texture_view = NULL; + execute_filter(ctx, &info); +} + +static VGfloat texture_offset(VGfloat width, VGint kernelSize, VGint current, VGint shift) +{ + VGfloat diff = current - shift; + + return diff / width; +} + +void vegaConvolve(VGImage dst, VGImage src, + VGint kernelWidth, VGint kernelHeight, + VGint shiftX, VGint shiftY, + const VGshort * kernel, + VGfloat scale, + VGfloat bias, + VGTilingMode tilingMode) +{ + struct vg_context *ctx = vg_current_context(); + VGfloat *buffer; + VGint buffer_len; + VGint i, j; + VGint idx = 0; + struct vg_image *d, *s; + VGint kernel_size = kernelWidth * kernelHeight; + struct filter_info info; + const VGint max_kernel_size = vgGeti(VG_MAX_KERNEL_SIZE); + + if (dst == VG_INVALID_HANDLE || src == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (kernelWidth <= 0 || kernelHeight <= 0 || + kernelWidth > max_kernel_size || kernelHeight > max_kernel_size) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (!kernel || !is_aligned_to(kernel, 2)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (tilingMode < VG_TILE_FILL || + tilingMode > VG_TILE_REFLECT) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + d = (struct vg_image*)dst; + s = (struct vg_image*)src; + + if (vg_image_overlaps(d, s)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + vg_validate_state(ctx); + + buffer_len = 8 + 2 * 4 * kernel_size; + buffer = (VGfloat*)malloc(buffer_len * sizeof(VGfloat)); + + buffer[0] = 0.f; + buffer[1] = 1.f; + buffer[2] = 2.f; /*unused*/ + buffer[3] = 4.f; /*unused*/ + + buffer[4] = kernelWidth * kernelHeight; + buffer[5] = scale; + buffer[6] = bias; + buffer[7] = 0.f; + + idx = 8; + for (j = 0; j < kernelHeight; ++j) { + for (i = 0; i < kernelWidth; ++i) { + VGint index = j * kernelWidth + i; + VGfloat x, y; + + x = texture_offset(s->width, kernelWidth, i, shiftX); + y = texture_offset(s->height, kernelHeight, j, shiftY); + + buffer[idx + index*4 + 0] = x; + buffer[idx + index*4 + 1] = y; + buffer[idx + index*4 + 2] = 0.f; + buffer[idx + index*4 + 3] = 0.f; + } + } + idx += kernel_size * 4; + + for (j = 0; j < kernelHeight; ++j) { + for (i = 0; i < kernelWidth; ++i) { + /* transpose the kernel */ + VGint index = j * kernelWidth + i; + VGint kindex = (kernelWidth - i - 1) * kernelHeight + (kernelHeight - j - 1); + buffer[idx + index*4 + 0] = kernel[kindex]; + buffer[idx + index*4 + 1] = kernel[kindex]; + buffer[idx + index*4 + 2] = kernel[kindex]; + buffer[idx + index*4 + 3] = kernel[kindex]; + } + } + + info.dst = d; + info.src = s; + info.setup_shader = &setup_convolution; + info.user_data = (void*)(long)(buffer_len/4); + info.const_buffer = buffer; + info.const_buffer_len = buffer_len * sizeof(VGfloat); + info.tiling_mode = tilingMode; + info.extra_texture_view = NULL; + execute_filter(ctx, &info); + + free(buffer); +} + +void vegaSeparableConvolve(VGImage dst, VGImage src, + VGint kernelWidth, + VGint kernelHeight, + VGint shiftX, VGint shiftY, + const VGshort * kernelX, + const VGshort * kernelY, + VGfloat scale, + VGfloat bias, + VGTilingMode tilingMode) +{ + struct vg_context *ctx = vg_current_context(); + VGshort *kernel; + VGint i, j, idx = 0; + const VGint max_kernel_size = vgGeti(VG_MAX_SEPARABLE_KERNEL_SIZE); + + if (dst == VG_INVALID_HANDLE || src == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (kernelWidth <= 0 || kernelHeight <= 0 || + kernelWidth > max_kernel_size || kernelHeight > max_kernel_size) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (!kernelX || !kernelY || + !is_aligned_to(kernelX, 2) || !is_aligned_to(kernelY, 2)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if (tilingMode < VG_TILE_FILL || + tilingMode > VG_TILE_REFLECT) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + kernel = malloc(sizeof(VGshort)*kernelWidth*kernelHeight); + for (i = 0; i < kernelWidth; ++i) { + for (j = 0; j < kernelHeight; ++j) { + kernel[idx] = kernelX[i] * kernelY[j]; + ++idx; + } + } + vgConvolve(dst, src, kernelWidth, kernelHeight, shiftX, shiftY, + kernel, scale, bias, tilingMode); + free(kernel); +} + +static INLINE VGfloat compute_gaussian_componenet(VGfloat x, VGfloat y, + VGfloat stdDeviationX, + VGfloat stdDeviationY) +{ + VGfloat mult = 1 / ( 2 * M_PI * stdDeviationX * stdDeviationY); + VGfloat e = exp( - ( pow(x, 2)/(2*pow(stdDeviationX, 2)) + + pow(y, 2)/(2*pow(stdDeviationY, 2)) ) ); + return mult * e; +} + +static INLINE VGint compute_kernel_size(VGfloat deviation) +{ + VGint size = ceil(2.146 * deviation); + if (size > 11) + return 11; + return size; +} + +static void compute_gaussian_kernel(VGfloat *kernel, + VGint width, VGint height, + VGfloat stdDeviationX, + VGfloat stdDeviationY) +{ + VGint i, j; + VGfloat scale = 0.0f; + + for (j = 0; j < height; ++j) { + for (i = 0; i < width; ++i) { + VGint idx = (height - j -1) * width + (width - i -1); + kernel[idx] = compute_gaussian_componenet(i-(ceil(width/2))-1, + j-ceil(height/2)-1, + stdDeviationX, stdDeviationY); + scale += kernel[idx]; + } + } + + for (j = 0; j < height; ++j) { + for (i = 0; i < width; ++i) { + VGint idx = j * width + i; + kernel[idx] /= scale; + } + } +} + +void vegaGaussianBlur(VGImage dst, VGImage src, + VGfloat stdDeviationX, + VGfloat stdDeviationY, + VGTilingMode tilingMode) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_image *d, *s; + VGfloat *buffer, *kernel; + VGint kernel_width, kernel_height, kernel_size; + VGint buffer_len; + VGint idx, i, j; + struct filter_info info; + + if (dst == VG_INVALID_HANDLE || src == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (stdDeviationX <= 0 || stdDeviationY <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (tilingMode < VG_TILE_FILL || + tilingMode > VG_TILE_REFLECT) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + d = (struct vg_image*)dst; + s = (struct vg_image*)src; + + if (vg_image_overlaps(d, s)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + kernel_width = compute_kernel_size(stdDeviationX); + kernel_height = compute_kernel_size(stdDeviationY); + kernel_size = kernel_width * kernel_height; + kernel = malloc(sizeof(VGfloat)*kernel_size); + compute_gaussian_kernel(kernel, kernel_width, kernel_height, + stdDeviationX, stdDeviationY); + + buffer_len = 8 + 2 * 4 * kernel_size; + buffer = (VGfloat*)malloc(buffer_len * sizeof(VGfloat)); + + buffer[0] = 0.f; + buffer[1] = 1.f; + buffer[2] = 2.f; /*unused*/ + buffer[3] = 4.f; /*unused*/ + + buffer[4] = kernel_width * kernel_height; + buffer[5] = 1.f;/*scale*/ + buffer[6] = 0.f;/*bias*/ + buffer[7] = 0.f; + + idx = 8; + for (j = 0; j < kernel_height; ++j) { + for (i = 0; i < kernel_width; ++i) { + VGint index = j * kernel_width + i; + VGfloat x, y; + + x = texture_offset(s->width, kernel_width, i, kernel_width/2); + y = texture_offset(s->height, kernel_height, j, kernel_height/2); + + buffer[idx + index*4 + 0] = x; + buffer[idx + index*4 + 1] = y; + buffer[idx + index*4 + 2] = 0.f; + buffer[idx + index*4 + 3] = 0.f; + } + } + idx += kernel_size * 4; + + for (j = 0; j < kernel_height; ++j) { + for (i = 0; i < kernel_width; ++i) { + /* transpose the kernel */ + VGint index = j * kernel_width + i; + VGint kindex = (kernel_width - i - 1) * kernel_height + (kernel_height - j - 1); + buffer[idx + index*4 + 0] = kernel[kindex]; + buffer[idx + index*4 + 1] = kernel[kindex]; + buffer[idx + index*4 + 2] = kernel[kindex]; + buffer[idx + index*4 + 3] = kernel[kindex]; + } + } + + info.dst = d; + info.src = s; + info.setup_shader = &setup_convolution; + info.user_data = (void*)(long)(buffer_len/4); + info.const_buffer = buffer; + info.const_buffer_len = buffer_len * sizeof(VGfloat); + info.tiling_mode = tilingMode; + info.extra_texture_view = NULL; + execute_filter(ctx, &info); + + free(buffer); + free(kernel); +} + +void vegaLookup(VGImage dst, VGImage src, + const VGubyte * redLUT, + const VGubyte * greenLUT, + const VGubyte * blueLUT, + const VGubyte * alphaLUT, + VGboolean outputLinear, + VGboolean outputPremultiplied) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_image *d, *s; + VGuint color_data[256]; + VGint i; + struct pipe_sampler_view *lut_texture_view; + VGfloat buffer[4]; + struct filter_info info; + + if (dst == VG_INVALID_HANDLE || src == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (!redLUT || !greenLUT || !blueLUT || !alphaLUT) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + d = (struct vg_image*)dst; + s = (struct vg_image*)src; + + if (vg_image_overlaps(d, s)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + for (i = 0; i < 256; ++i) { + color_data[i] = blueLUT[i] << 24 | greenLUT[i] << 16 | + redLUT[i] << 8 | alphaLUT[i]; + } + lut_texture_view = create_texture_1d_view(ctx, color_data, 255); + + buffer[0] = 0.f; + buffer[1] = 0.f; + buffer[2] = 1.f; + buffer[3] = 1.f; + + info.dst = d; + info.src = s; + info.setup_shader = &setup_lookup; + info.user_data = NULL; + info.const_buffer = buffer; + info.const_buffer_len = 4 * sizeof(VGfloat); + info.tiling_mode = VG_TILE_PAD; + info.extra_texture_view = lut_texture_view; + + execute_filter(ctx, &info); + + pipe_sampler_view_reference(&lut_texture_view, NULL); +} + +void vegaLookupSingle(VGImage dst, VGImage src, + const VGuint * lookupTable, + VGImageChannel sourceChannel, + VGboolean outputLinear, + VGboolean outputPremultiplied) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_image *d, *s; + struct pipe_sampler_view *lut_texture_view; + VGfloat buffer[4]; + struct filter_info info; + VGuint color_data[256]; + VGint i; + + if (dst == VG_INVALID_HANDLE || src == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (!lookupTable || !is_aligned(lookupTable)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (sourceChannel != VG_RED && sourceChannel != VG_GREEN && + sourceChannel != VG_BLUE && sourceChannel != VG_ALPHA) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + d = (struct vg_image*)dst; + s = (struct vg_image*)src; + + if (vg_image_overlaps(d, s)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + vg_validate_state(ctx); + + for (i = 0; i < 256; ++i) { + VGuint rgba = lookupTable[i]; + VGubyte blue, green, red, alpha; + red = (rgba & 0xff000000)>>24; + green = (rgba & 0x00ff0000)>>16; + blue = (rgba & 0x0000ff00)>> 8; + alpha = (rgba & 0x000000ff)>> 0; + color_data[i] = blue << 24 | green << 16 | + red << 8 | alpha; + } + lut_texture_view = create_texture_1d_view(ctx, color_data, 256); + + buffer[0] = 0.f; + buffer[1] = 0.f; + buffer[2] = 1.f; + buffer[3] = 1.f; + + info.dst = d; + info.src = s; + info.setup_shader = &setup_lookup_single; + info.user_data = (void*)sourceChannel; + info.const_buffer = buffer; + info.const_buffer_len = 4 * sizeof(VGfloat); + info.tiling_mode = VG_TILE_PAD; + info.extra_texture_view = lut_texture_view; + + execute_filter(ctx, &info); + + pipe_sampler_view_reference(&lut_texture_view, NULL); +} diff --git a/src/gallium/state_trackers/vega/api_images.c b/src/gallium/state_trackers/vega/api_images.c new file mode 100644 index 0000000..ad95409 --- /dev/null +++ b/src/gallium/state_trackers/vega/api_images.c @@ -0,0 +1,494 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "image.h" + +#include "VG/openvg.h" + +#include "vg_context.h" +#include "vg_translate.h" +#include "api_consts.h" +#include "api.h" + +#include "pipe/p_context.h" +#include "pipe/p_screen.h" +#include "util/u_inlines.h" +#include "util/u_tile.h" +#include "util/u_math.h" + +static INLINE VGboolean supported_image_format(VGImageFormat format) +{ + switch(format) { + case VG_sRGBX_8888: + case VG_sRGBA_8888: + case VG_sRGBA_8888_PRE: + case VG_sRGB_565: + case VG_sRGBA_5551: + case VG_sRGBA_4444: + case VG_sL_8: + case VG_lRGBX_8888: + case VG_lRGBA_8888: + case VG_lRGBA_8888_PRE: + case VG_lL_8: + case VG_A_8: + case VG_BW_1: +#ifdef OPENVG_VERSION_1_1 + case VG_A_1: + case VG_A_4: +#endif + case VG_sXRGB_8888: + case VG_sARGB_8888: + case VG_sARGB_8888_PRE: + case VG_sARGB_1555: + case VG_sARGB_4444: + case VG_lXRGB_8888: + case VG_lARGB_8888: + case VG_lARGB_8888_PRE: + case VG_sBGRX_8888: + case VG_sBGRA_8888: + case VG_sBGRA_8888_PRE: + case VG_sBGR_565: + case VG_sBGRA_5551: + case VG_sBGRA_4444: + case VG_lBGRX_8888: + case VG_lBGRA_8888: + case VG_lBGRA_8888_PRE: + case VG_sXBGR_8888: + case VG_sABGR_8888: + case VG_sABGR_8888_PRE: + case VG_sABGR_1555: + case VG_sABGR_4444: + case VG_lXBGR_8888: + case VG_lABGR_8888: + case VG_lABGR_8888_PRE: + return VG_TRUE; + default: + return VG_FALSE; + } + return VG_FALSE; +} + +VGImage vegaCreateImage(VGImageFormat format, + VGint width, VGint height, + VGbitfield allowedQuality) +{ + struct vg_context *ctx = vg_current_context(); + + if (!supported_image_format(format)) { + vg_set_error(ctx, VG_UNSUPPORTED_IMAGE_FORMAT_ERROR); + return VG_INVALID_HANDLE; + } + if (width <= 0 || height <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_INVALID_HANDLE; + } + if (width > vgGeti(VG_MAX_IMAGE_WIDTH) || + height > vgGeti(VG_MAX_IMAGE_HEIGHT)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_INVALID_HANDLE; + } + if (width * height > vgGeti(VG_MAX_IMAGE_PIXELS)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_INVALID_HANDLE; + } + + if (!(allowedQuality & ((VG_IMAGE_QUALITY_NONANTIALIASED | + VG_IMAGE_QUALITY_FASTER | + VG_IMAGE_QUALITY_BETTER)))) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_INVALID_HANDLE; + } + + return (VGImage)image_create(format, width, height); +} + +void vegaDestroyImage(VGImage image) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_image *img = (struct vg_image *)image; + + if (image == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (!vg_object_is_valid((void*)image, VG_OBJECT_IMAGE)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + image_destroy(img); +} + +void vegaClearImage(VGImage image, + VGint x, VGint y, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_image *img; + + if (image == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (width <= 0 || height <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + img = (struct vg_image*)image; + + if (x + width < 0 || y + height < 0) + return; + + image_clear(img, x, y, width, height); + +} + +void vegaImageSubData(VGImage image, + const void * data, + VGint dataStride, + VGImageFormat dataFormat, + VGint x, VGint y, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_image *img; + + if (image == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (!supported_image_format(dataFormat)) { + vg_set_error(ctx, VG_UNSUPPORTED_IMAGE_FORMAT_ERROR); + return; + } + if (width <= 0 || height <= 0 || !data || !is_aligned(data)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + img = (struct vg_image*)(image); + image_sub_data(img, data, dataStride, dataFormat, + x, y, width, height); +} + +void vegaGetImageSubData(VGImage image, + void * data, + VGint dataStride, + VGImageFormat dataFormat, + VGint x, VGint y, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_image *img; + + if (image == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (!supported_image_format(dataFormat)) { + vg_set_error(ctx, VG_UNSUPPORTED_IMAGE_FORMAT_ERROR); + return; + } + if (width <= 0 || height <= 0 || !data || !is_aligned(data)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + img = (struct vg_image*)image; + image_get_sub_data(img, data, dataStride, dataFormat, + x, y, width, height); +} + +VGImage vegaChildImage(VGImage parent, + VGint x, VGint y, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_image *p; + + if (parent == VG_INVALID_HANDLE || + !vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, (void*)parent) || + !vg_object_is_valid((void*)parent, VG_OBJECT_IMAGE)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return VG_INVALID_HANDLE; + } + if (width <= 0 || height <= 0 || x < 0 || y < 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_INVALID_HANDLE; + } + p = (struct vg_image *)parent; + if (x > p->width || y > p->height) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_INVALID_HANDLE; + } + if (x + width > p->width || y + height > p->height) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_INVALID_HANDLE; + } + + return (VGImage)image_child_image(p, x, y, width, height); +} + +VGImage vegaGetParent(VGImage image) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_image *img; + + if (image == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return VG_INVALID_HANDLE; + } + + img = (struct vg_image*)image; + if (img->parent) + return (VGImage)img->parent; + else + return image; +} + +void vegaCopyImage(VGImage dst, VGint dx, VGint dy, + VGImage src, VGint sx, VGint sy, + VGint width, VGint height, + VGboolean dither) +{ + struct vg_context *ctx = vg_current_context(); + + if (src == VG_INVALID_HANDLE || dst == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (width <= 0 || height <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + vg_validate_state(ctx); + image_copy((struct vg_image*)dst, dx, dy, + (struct vg_image*)src, sx, sy, + width, height, dither); +} + +void vegaDrawImage(VGImage image) +{ + struct vg_context *ctx = vg_current_context(); + + if (!ctx) + return; + + if (image == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + vg_validate_state(ctx); + image_draw((struct vg_image*)image, + &ctx->state.vg.image_user_to_surface_matrix); +} + +void vegaSetPixels(VGint dx, VGint dy, + VGImage src, VGint sx, VGint sy, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + + vg_validate_state(ctx); + + if (src == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (width <= 0 || height <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + image_set_pixels(dx, dy, (struct vg_image*)src, sx, sy, width, + height); +} + +void vegaGetPixels(VGImage dst, VGint dx, VGint dy, + VGint sx, VGint sy, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_image *img; + + if (dst == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (width <= 0 || height <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + img = (struct vg_image*)dst; + + image_get_pixels(img, dx, dy, + sx, sy, width, height); +} + +void vegaWritePixels(const void * data, VGint dataStride, + VGImageFormat dataFormat, + VGint dx, VGint dy, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct pipe_context *pipe = ctx->pipe; + + if (!supported_image_format(dataFormat)) { + vg_set_error(ctx, VG_UNSUPPORTED_IMAGE_FORMAT_ERROR); + return; + } + if (!data || !is_aligned(data)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if (width <= 0 || height <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + vg_validate_state(ctx); + { + struct vg_image *img = image_create(dataFormat, width, height); + image_sub_data(img, data, dataStride, dataFormat, 0, 0, + width, height); +#if 0 + struct matrix *matrix = &ctx->state.vg.image_user_to_surface_matrix; + matrix_translate(matrix, dx, dy); + image_draw(img); + matrix_translate(matrix, -dx, -dy); +#else + /* this looks like a better approach */ + image_set_pixels(dx, dy, img, 0, 0, width, height); +#endif + image_destroy(img); + } + /* make sure rendering has completed */ + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); +} + +void vegaReadPixels(void * data, VGint dataStride, + VGImageFormat dataFormat, + VGint sx, VGint sy, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct pipe_context *pipe = ctx->pipe; + + struct st_framebuffer *stfb = ctx->draw_buffer; + struct st_renderbuffer *strb = stfb->strb; + + VGfloat temp[VEGA_MAX_IMAGE_WIDTH][4]; + VGfloat *df = (VGfloat*)temp; + VGint i; + VGubyte *dst = (VGubyte *)data; + VGint xoffset = 0, yoffset = 0; + + if (!supported_image_format(dataFormat)) { + vg_set_error(ctx, VG_UNSUPPORTED_IMAGE_FORMAT_ERROR); + return; + } + if (!data || !is_aligned(data)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if (width <= 0 || height <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + /* make sure rendering has completed */ + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + if (sx < 0) { + xoffset = -sx; + xoffset *= _vega_size_for_format(dataFormat); + width += sx; + sx = 0; + } + if (sy < 0) { + yoffset = -sy; + yoffset *= dataStride; + height += sy; + sy = 0; + } + + if (sx + width > stfb->width || sy + height > stfb->height) { + width = stfb->width - sx; + height = stfb->height - sy; + /* nothing to read */ + if (width <= 0 || height <= 0) + return; + } + + { + VGint y = (stfb->height - sy) - 1, yStep = -1; + struct pipe_transfer *transfer; + + transfer = pipe_get_transfer(pipe, strb->texture, 0, 0, + PIPE_TRANSFER_READ, + 0, 0, sx + width, stfb->height - sy); + + /* Do a row at a time to flip image data vertically */ + for (i = 0; i < height; i++) { +#if 0 + debug_printf("%d-%d == %d\n", sy, height, y); +#endif + pipe_get_tile_rgba(pipe, transfer, sx, y, width, 1, df); + y += yStep; + _vega_pack_rgba_span_float(ctx, width, temp, dataFormat, + dst + yoffset + xoffset); + dst += dataStride; + } + + pipe->transfer_destroy(pipe, transfer); + } +} + +void vegaCopyPixels(VGint dx, VGint dy, + VGint sx, VGint sy, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct st_framebuffer *stfb = ctx->draw_buffer; + struct st_renderbuffer *strb = stfb->strb; + + if (width <= 0 || height <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + /* do nothing if we copy from outside the fb */ + if (dx >= (VGint)stfb->width || dy >= (VGint)stfb->height || + sx >= (VGint)stfb->width || sy >= (VGint)stfb->height) + return; + + vg_validate_state(ctx); + /* make sure rendering has completed */ + vgFinish(); + + vg_copy_surface(ctx, strb->surface, dx, dy, + strb->surface, sx, sy, width, height); +} diff --git a/src/gallium/state_trackers/vega/api_masks.c b/src/gallium/state_trackers/vega/api_masks.c new file mode 100644 index 0000000..beb15c3 --- /dev/null +++ b/src/gallium/state_trackers/vega/api_masks.c @@ -0,0 +1,244 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "VG/openvg.h" + +#include "mask.h" +#include "api.h" +#include "renderer.h" + +#include "vg_context.h" +#include "pipe/p_context.h" +#include "util/u_inlines.h" + +#include "util/u_pack_color.h" +#include "util/u_draw_quad.h" + +void vegaMask(VGHandle mask, VGMaskOperation operation, + VGint x, VGint y, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + + if (width <=0 || height <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (operation < VG_CLEAR_MASK || operation > VG_SUBTRACT_MASK) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + + vg_validate_state(ctx); + + if (operation == VG_CLEAR_MASK) { + mask_fill(x, y, width, height, 0.f); + } else if (operation == VG_FILL_MASK) { + mask_fill(x, y, width, height, 1.f); + } else if (vg_object_is_valid((void*)mask, VG_OBJECT_IMAGE)) { + struct vg_image *image = (struct vg_image *)mask; + mask_using_image(image, operation, x, y, width, height); + } else if (vg_object_is_valid((void*)mask, VG_OBJECT_MASK)) { + struct vg_mask_layer *layer = (struct vg_mask_layer *)mask; + mask_using_layer(layer, operation, x, y, width, height); + } else { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + } +} + +void vegaClear(VGint x, VGint y, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct st_framebuffer *stfb = ctx->draw_buffer; + + if (width <= 0 || height <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + vg_validate_state(ctx); +#if 0 + debug_printf("Clear [%d, %d, %d, %d] with [%f, %f, %f, %f]\n", + x, y, width, height, + ctx->state.vg.clear_color[0], + ctx->state.vg.clear_color[1], + ctx->state.vg.clear_color[2], + ctx->state.vg.clear_color[3]); +#endif + + /* check for a whole surface clear */ + if (!ctx->state.vg.scissoring && + (x == 0 && y == 0 && width == stfb->width && height == stfb->height)) { + ctx->pipe->clear(ctx->pipe, PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL, + ctx->state.vg.clear_color, 1., 0); + } else if (renderer_clear_begin(ctx->renderer)) { + /* XXX verify coord round-off */ + renderer_clear(ctx->renderer, x, y, width, height, ctx->state.vg.clear_color); + renderer_clear_end(ctx->renderer); + } +} + + +#ifdef OPENVG_VERSION_1_1 + + +void vegaRenderToMask(VGPath path, + VGbitfield paintModes, + VGMaskOperation operation) +{ + struct vg_context *ctx = vg_current_context(); + + if (path == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (!paintModes || (paintModes&(~(VG_STROKE_PATH|VG_FILL_PATH)))) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if (operation < VG_CLEAR_MASK || + operation > VG_SUBTRACT_MASK) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if (!vg_object_is_valid((void*)path, VG_OBJECT_PATH)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + vg_validate_state(ctx); + + mask_render_to((struct path *)path, paintModes, operation); +} + +VGMaskLayer vegaCreateMaskLayer(VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + + if (width <= 0 || height <= 0 || + width > vgGeti(VG_MAX_IMAGE_WIDTH) || + height > vgGeti(VG_MAX_IMAGE_HEIGHT)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_INVALID_HANDLE; + } + + return (VGMaskLayer)mask_layer_create(width, height); +} + +void vegaDestroyMaskLayer(VGMaskLayer maskLayer) +{ + struct vg_mask_layer *mask = 0; + struct vg_context *ctx = vg_current_context(); + + if (maskLayer == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (!vg_object_is_valid((void*)maskLayer, VG_OBJECT_MASK)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + mask = (struct vg_mask_layer *)maskLayer; + mask_layer_destroy(mask); +} + +void vegaFillMaskLayer(VGMaskLayer maskLayer, + VGint x, VGint y, + VGint width, VGint height, + VGfloat value) +{ + struct vg_mask_layer *mask = 0; + struct vg_context *ctx = vg_current_context(); + + if (maskLayer == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (value < 0 || value > 1) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (width <= 0 || height <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if (x < 0 || y < 0 || (x + width) < 0 || (y + height) < 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (!vg_object_is_valid((void*)maskLayer, VG_OBJECT_MASK)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + mask = (struct vg_mask_layer*)maskLayer; + + if (x + width > mask_layer_width(mask) || + y + height > mask_layer_height(mask)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + vg_validate_state(ctx); + + mask_layer_fill(mask, x, y, width, height, value); +} + +void vegaCopyMask(VGMaskLayer maskLayer, + VGint sx, VGint sy, + VGint dx, VGint dy, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_mask_layer *mask = 0; + + if (maskLayer == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (width <= 0 || height <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if (!vg_object_is_valid((void*)maskLayer, VG_OBJECT_MASK)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + vg_validate_state(ctx); + + mask = (struct vg_mask_layer*)maskLayer; + mask_copy(mask, sx, sy, dx, dy, width, height); +} + +#endif diff --git a/src/gallium/state_trackers/vega/api_misc.c b/src/gallium/state_trackers/vega/api_misc.c new file mode 100644 index 0000000..9e2ab03 --- /dev/null +++ b/src/gallium/state_trackers/vega/api_misc.c @@ -0,0 +1,84 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "VG/openvg.h" + +#include "vg_context.h" +#include "api.h" + +/* Hardware Queries */ +VGHardwareQueryResult vegaHardwareQuery(VGHardwareQueryType key, + VGint setting) +{ + struct vg_context *ctx = vg_current_context(); + + if (key < VG_IMAGE_FORMAT_QUERY || + key > VG_PATH_DATATYPE_QUERY) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_HARDWARE_UNACCELERATED; + } + + if (key == VG_IMAGE_FORMAT_QUERY) { + if (setting < VG_sRGBX_8888 || + setting > VG_lABGR_8888_PRE) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_HARDWARE_UNACCELERATED; + } + } else if (key == VG_PATH_DATATYPE_QUERY) { + if (setting < VG_PATH_DATATYPE_S_8 || + setting > VG_PATH_DATATYPE_F) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_HARDWARE_UNACCELERATED; + } + } + /* we're supposed to accelerate everything */ + return VG_HARDWARE_ACCELERATED; +} + +/* Renderer and Extension Information */ +const VGubyte *vegaGetString(VGStringID name) +{ + struct vg_context *ctx = vg_current_context(); + static const VGubyte *vendor = (VGubyte *)"Tungsten Graphics, Inc"; + static const VGubyte *renderer = (VGubyte *)"Vega OpenVG 1.1"; + static const VGubyte *version = (VGubyte *)"1.1"; + + if (!ctx) + return NULL; + + switch(name) { + case VG_VENDOR: + return vendor; + case VG_RENDERER: + return renderer; + case VG_VERSION: + return version; + case VG_EXTENSIONS: + return NULL; + default: + return NULL; + } +} diff --git a/src/gallium/state_trackers/vega/api_paint.c b/src/gallium/state_trackers/vega/api_paint.c new file mode 100644 index 0000000..1411806 --- /dev/null +++ b/src/gallium/state_trackers/vega/api_paint.c @@ -0,0 +1,166 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "VG/openvg.h" + +#include "vg_context.h" +#include "paint.h" +#include "api.h" + +VGPaint vegaCreatePaint(void) +{ + return (VGPaint) paint_create(vg_current_context()); +} + +void vegaDestroyPaint(VGPaint p) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_paint *paint; + + if (p == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + paint = (struct vg_paint *)p; + paint_destroy(paint); +} + +void vegaSetPaint(VGPaint paint, VGbitfield paintModes) +{ + struct vg_context *ctx = vg_current_context(); + + if (paint == VG_INVALID_HANDLE) { + /* restore the default */ + paint = (VGPaint)ctx->default_paint; + } else if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (!(paintModes & ((VG_FILL_PATH|VG_STROKE_PATH)))) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (paintModes & VG_FILL_PATH) { + ctx->state.vg.fill_paint = (struct vg_paint *)paint; + } + if (paintModes & VG_STROKE_PATH) { + ctx->state.vg.stroke_paint = (struct vg_paint *)paint; + } +} + +VGPaint vegaGetPaint(VGPaintMode paintMode) +{ + struct vg_context *ctx = vg_current_context(); + VGPaint paint = VG_INVALID_HANDLE; + + if (paintMode < VG_STROKE_PATH || paintMode > VG_FILL_PATH) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_INVALID_HANDLE; + } + + if (paintMode == VG_FILL_PATH) + paint = (VGPaint)ctx->state.vg.fill_paint; + else if (paintMode == VG_STROKE_PATH) + paint = (VGPaint)ctx->state.vg.stroke_paint; + + if (paint == (VGPaint)ctx->default_paint) + paint = VG_INVALID_HANDLE; + + return paint; +} + +void vegaSetColor(VGPaint paint, VGuint rgba) +{ + struct vg_context *ctx = vg_current_context(); + + if (paint == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + { + struct vg_paint *p = (struct vg_paint *)paint; + paint_set_colori(p, rgba); + } +} + +VGuint vegaGetColor(VGPaint paint) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_paint *p; + VGuint rgba = 0; + + if (paint == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return rgba; + } + + if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return rgba; + } + p = (struct vg_paint *)paint; + + return paint_colori(p); +} + +void vegaPaintPattern(VGPaint paint, VGImage pattern) +{ + struct vg_context *ctx = vg_current_context(); + + if (paint == VG_INVALID_HANDLE || + !vg_context_is_object_valid(ctx, VG_OBJECT_PAINT, (void *)paint)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (pattern == VG_INVALID_HANDLE) { + paint_set_type((struct vg_paint*)paint, VG_PAINT_TYPE_COLOR); + return; + } + + if (!vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, (void *)pattern)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + + if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT) || + !vg_object_is_valid((void*)pattern, VG_OBJECT_IMAGE)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + paint_set_pattern((struct vg_paint*)paint, + (struct vg_image*)pattern); +} + diff --git a/src/gallium/state_trackers/vega/api_params.c b/src/gallium/state_trackers/vega/api_params.c new file mode 100644 index 0000000..a73b6c3 --- /dev/null +++ b/src/gallium/state_trackers/vega/api_params.c @@ -0,0 +1,1677 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "VG/openvg.h" + +#include "vg_context.h" +#include "paint.h" +#include "path.h" +#include "image.h" +#include "text.h" +#include "matrix.h" +#include "api_consts.h" +#include "api.h" + +#include "pipe/p_compiler.h" +#include "util/u_pointer.h" +#include "util/u_math.h" + +#include + +static INLINE struct vg_state *current_state() +{ + struct vg_context *ctx = vg_current_context(); + if (!ctx) + return 0; + else + return &ctx->state.vg; +} + +static INLINE VGboolean count_in_bounds(VGParamType type, VGint count) +{ + if (count < 0) + return VG_FALSE; + + if (type == VG_SCISSOR_RECTS) + return (!(count % 4) && (count >= 0 || count <= VEGA_MAX_SCISSOR_RECTS * 4)); + else if (type == VG_STROKE_DASH_PATTERN) { + return count <= VEGA_MAX_DASH_COUNT; + } else { + VGint real_count = vgGetVectorSize(type); + return count == real_count; + } +} + +void vegaSetf (VGParamType type, VGfloat value) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_state *state = current_state(); + VGErrorCode error = VG_NO_ERROR; + + switch(type) { + case VG_MATRIX_MODE: + case VG_FILL_RULE: + case VG_IMAGE_QUALITY: + case VG_RENDERING_QUALITY: + case VG_BLEND_MODE: + case VG_IMAGE_MODE: +#ifdef OPENVG_VERSION_1_1 + case VG_COLOR_TRANSFORM: +#endif + case VG_STROKE_CAP_STYLE: + case VG_STROKE_JOIN_STYLE: + case VG_STROKE_DASH_PHASE_RESET: + case VG_MASKING: + case VG_SCISSORING: + case VG_PIXEL_LAYOUT: + case VG_SCREEN_LAYOUT: + case VG_FILTER_FORMAT_LINEAR: + case VG_FILTER_FORMAT_PREMULTIPLIED: + case VG_FILTER_CHANNEL_MASK: + + case VG_MAX_SCISSOR_RECTS: + case VG_MAX_DASH_COUNT: + case VG_MAX_KERNEL_SIZE: + case VG_MAX_SEPARABLE_KERNEL_SIZE: + case VG_MAX_COLOR_RAMP_STOPS: + case VG_MAX_IMAGE_WIDTH: + case VG_MAX_IMAGE_HEIGHT: + case VG_MAX_IMAGE_PIXELS: + case VG_MAX_IMAGE_BYTES: + case VG_MAX_GAUSSIAN_STD_DEVIATION: + case VG_MAX_FLOAT: + vgSeti(type, floor(value)); + return; + break; + case VG_STROKE_LINE_WIDTH: + state->stroke.line_width.f = value; + state->stroke.line_width.i = float_to_int_floor(*((VGuint*)(&value))); + break; + case VG_STROKE_MITER_LIMIT: + state->stroke.miter_limit.f = value; + state->stroke.miter_limit.i = float_to_int_floor(*((VGuint*)(&value))); + break; + case VG_STROKE_DASH_PHASE: + state->stroke.dash_phase.f = value; + state->stroke.dash_phase.i = float_to_int_floor(*((VGuint*)(&value))); + break; + default: + error = VG_ILLEGAL_ARGUMENT_ERROR; + break; + } + vg_set_error(ctx, error); +} + +void vegaSeti (VGParamType type, VGint value) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_state *state = current_state(); + VGErrorCode error = VG_NO_ERROR; + + switch(type) { + case VG_MATRIX_MODE: + if (value < VG_MATRIX_PATH_USER_TO_SURFACE || +#ifdef OPENVG_VERSION_1_1 + value > VG_MATRIX_GLYPH_USER_TO_SURFACE) +#else + value > VG_MATRIX_STROKE_PAINT_TO_USER) +#endif + error = VG_ILLEGAL_ARGUMENT_ERROR; + else + state->matrix_mode = value; + break; + case VG_FILL_RULE: + if (value < VG_EVEN_ODD || + value > VG_NON_ZERO) + error = VG_ILLEGAL_ARGUMENT_ERROR; + else + state->fill_rule = value; + break; + case VG_IMAGE_QUALITY: + state->image_quality = value; + break; + case VG_RENDERING_QUALITY: + if (value < VG_RENDERING_QUALITY_NONANTIALIASED || + value > VG_RENDERING_QUALITY_BETTER) + error = VG_ILLEGAL_ARGUMENT_ERROR; + else + state->rendering_quality = value; + break; + case VG_BLEND_MODE: + if (value < VG_BLEND_SRC || + value > VG_BLEND_ADDITIVE) + error = VG_ILLEGAL_ARGUMENT_ERROR; + else { + ctx->state.dirty |= BLEND_DIRTY; + state->blend_mode = value; + } + break; + case VG_IMAGE_MODE: + if (value < VG_DRAW_IMAGE_NORMAL || + value > VG_DRAW_IMAGE_STENCIL) + error = VG_ILLEGAL_ARGUMENT_ERROR; + else + state->image_mode = value; + break; +#ifdef OPENVG_VERSION_1_1 + case VG_COLOR_TRANSFORM: + state->color_transform = value; +#endif + break; + case VG_STROKE_LINE_WIDTH: + state->stroke.line_width.f = value; + state->stroke.line_width.i = value; + break; + case VG_STROKE_CAP_STYLE: + if (value < VG_CAP_BUTT || + value > VG_CAP_SQUARE) + error = VG_ILLEGAL_ARGUMENT_ERROR; + else + state->stroke.cap_style = value; + break; + case VG_STROKE_JOIN_STYLE: + if (value < VG_JOIN_MITER || + value > VG_JOIN_BEVEL) + error = VG_ILLEGAL_ARGUMENT_ERROR; + else + state->stroke.join_style = value; + break; + case VG_STROKE_MITER_LIMIT: + state->stroke.miter_limit.f = value; + state->stroke.miter_limit.i = value; + break; + case VG_STROKE_DASH_PHASE: + state->stroke.dash_phase.f = value; + state->stroke.dash_phase.i = value; + break; + case VG_STROKE_DASH_PHASE_RESET: + state->stroke.dash_phase_reset = value; + break; + case VG_MASKING: + state->masking = value; + break; + case VG_SCISSORING: + state->scissoring = value; + ctx->state.dirty |= DEPTH_STENCIL_DIRTY; + break; + case VG_PIXEL_LAYOUT: + if (value < VG_PIXEL_LAYOUT_UNKNOWN || + value > VG_PIXEL_LAYOUT_BGR_HORIZONTAL) + error = VG_ILLEGAL_ARGUMENT_ERROR; + else + state->pixel_layout = value; + break; + case VG_SCREEN_LAYOUT: + /* read only ignore */ + break; + case VG_FILTER_FORMAT_LINEAR: + state->filter_format_linear = value; + break; + case VG_FILTER_FORMAT_PREMULTIPLIED: + state->filter_format_premultiplied = value; + break; + case VG_FILTER_CHANNEL_MASK: + state->filter_channel_mask = value; + break; + + case VG_MAX_SCISSOR_RECTS: + case VG_MAX_DASH_COUNT: + case VG_MAX_KERNEL_SIZE: + case VG_MAX_SEPARABLE_KERNEL_SIZE: + case VG_MAX_COLOR_RAMP_STOPS: + case VG_MAX_IMAGE_WIDTH: + case VG_MAX_IMAGE_HEIGHT: + case VG_MAX_IMAGE_PIXELS: + case VG_MAX_IMAGE_BYTES: + case VG_MAX_GAUSSIAN_STD_DEVIATION: + case VG_MAX_FLOAT: + /* read only ignore */ + break; + default: + error = VG_ILLEGAL_ARGUMENT_ERROR; + break; + } + vg_set_error(ctx, error); +} + +void vegaSetfv(VGParamType type, VGint count, + const VGfloat * values) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_state *state = current_state(); + VGErrorCode error = VG_NO_ERROR; + + if ((count && !values) || !count_in_bounds(type, count) || !is_aligned(values)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + switch(type) { + case VG_MATRIX_MODE: + case VG_FILL_RULE: + case VG_IMAGE_QUALITY: + case VG_RENDERING_QUALITY: + case VG_BLEND_MODE: + case VG_IMAGE_MODE: +#ifdef OPENVG_VERSION_1_1 + case VG_COLOR_TRANSFORM: +#endif + case VG_STROKE_CAP_STYLE: + case VG_STROKE_JOIN_STYLE: + case VG_STROKE_DASH_PHASE_RESET: + case VG_MASKING: + case VG_SCISSORING: + case VG_PIXEL_LAYOUT: + case VG_SCREEN_LAYOUT: + case VG_FILTER_FORMAT_LINEAR: + case VG_FILTER_FORMAT_PREMULTIPLIED: + case VG_FILTER_CHANNEL_MASK: + vgSeti(type, floor(values[0])); + return; + break; + case VG_SCISSOR_RECTS: { + VGint i; + VGuint *x = (VGuint*)values; + for (i = 0; i < count; ++i) { + state->scissor_rects[i].f = values[i]; + state->scissor_rects[i].i = float_to_int_floor(x[i]); + } + state->scissor_rects_num = count / 4; + ctx->state.dirty |= DEPTH_STENCIL_DIRTY; + } + break; +#ifdef OPENVG_VERSION_1_1 + case VG_COLOR_TRANSFORM_VALUES: { + VGint i; + for (i = 0; i < count; ++i) { + state->color_transform_values[i] = values[i]; + } + } + break; +#endif + case VG_STROKE_LINE_WIDTH: + state->stroke.line_width.f = values[0]; + state->stroke.line_width.i = float_to_int_floor(*((VGuint*)(values))); + break; + case VG_STROKE_MITER_LIMIT: + state->stroke.miter_limit.f = values[0]; + state->stroke.miter_limit.i = float_to_int_floor(*((VGuint*)(values))); + break; + case VG_STROKE_DASH_PATTERN: { + int i; + for (i = 0; i < count; ++i) { + state->stroke.dash_pattern[i].f = values[i]; + state->stroke.dash_pattern[i].i = + float_to_int_floor(*((VGuint*)(values + i))); + } + state->stroke.dash_pattern_num = count; + } + break; + case VG_STROKE_DASH_PHASE: + state->stroke.dash_phase.f = values[0]; + state->stroke.dash_phase.i = float_to_int_floor(*((VGuint*)(values))); + break; + case VG_TILE_FILL_COLOR: + state->tile_fill_color[0] = values[0]; + state->tile_fill_color[1] = values[1]; + state->tile_fill_color[2] = values[2]; + state->tile_fill_color[3] = values[3]; + + state->tile_fill_colori[0] = float_to_int_floor(*((VGuint*)(values + 0))); + state->tile_fill_colori[1] = float_to_int_floor(*((VGuint*)(values + 1))); + state->tile_fill_colori[2] = float_to_int_floor(*((VGuint*)(values + 2))); + state->tile_fill_colori[3] = float_to_int_floor(*((VGuint*)(values + 3))); + break; + case VG_CLEAR_COLOR: + state->clear_color[0] = values[0]; + state->clear_color[1] = values[1]; + state->clear_color[2] = values[2]; + state->clear_color[3] = values[3]; + + state->clear_colori[0] = float_to_int_floor(*((VGuint*)(values + 0))); + state->clear_colori[1] = float_to_int_floor(*((VGuint*)(values + 1))); + state->clear_colori[2] = float_to_int_floor(*((VGuint*)(values + 2))); + state->clear_colori[3] = float_to_int_floor(*((VGuint*)(values + 3))); + break; +#ifdef OPENVG_VERSION_1_1 + case VG_GLYPH_ORIGIN: + state->glyph_origin[0].f = values[0]; + state->glyph_origin[1].f = values[1]; + + state->glyph_origin[0].i = float_to_int_floor(*((VGuint*)(values + 0))); + state->glyph_origin[1].i = float_to_int_floor(*((VGuint*)(values + 1))); + break; +#endif + + case VG_MAX_SCISSOR_RECTS: + case VG_MAX_DASH_COUNT: + case VG_MAX_KERNEL_SIZE: + case VG_MAX_SEPARABLE_KERNEL_SIZE: + case VG_MAX_COLOR_RAMP_STOPS: + case VG_MAX_IMAGE_WIDTH: + case VG_MAX_IMAGE_HEIGHT: + case VG_MAX_IMAGE_PIXELS: + case VG_MAX_IMAGE_BYTES: + case VG_MAX_GAUSSIAN_STD_DEVIATION: + case VG_MAX_FLOAT: + break; + default: + error = VG_ILLEGAL_ARGUMENT_ERROR; + break; + } + vg_set_error(ctx, error); +} + +void vegaSetiv(VGParamType type, VGint count, + const VGint * values) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_state *state = current_state(); + + if ((count && !values) || !count_in_bounds(type, count) || !is_aligned(values)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + switch(type) { + case VG_MATRIX_MODE: + case VG_FILL_RULE: + case VG_IMAGE_QUALITY: + case VG_RENDERING_QUALITY: + case VG_BLEND_MODE: + case VG_IMAGE_MODE: +#ifdef OPENVG_VERSION_1_1 + case VG_COLOR_TRANSFORM: +#endif + case VG_STROKE_CAP_STYLE: + case VG_STROKE_JOIN_STYLE: + case VG_STROKE_DASH_PHASE_RESET: + case VG_MASKING: + case VG_SCISSORING: + case VG_PIXEL_LAYOUT: + case VG_SCREEN_LAYOUT: + case VG_FILTER_FORMAT_LINEAR: + case VG_FILTER_FORMAT_PREMULTIPLIED: + case VG_FILTER_CHANNEL_MASK: + vgSeti(type, values[0]); + return; + break; + case VG_SCISSOR_RECTS: { + VGint i; + for (i = 0; i < count; ++i) { + state->scissor_rects[i].i = values[i]; + state->scissor_rects[i].f = values[i]; + } + state->scissor_rects_num = count / 4; + ctx->state.dirty |= DEPTH_STENCIL_DIRTY; + } + break; +#ifdef OPENVG_VERSION_1_1 + case VG_COLOR_TRANSFORM_VALUES: { + VGint i; + for (i = 0; i < count; ++i) { + state->color_transform_values[i] = values[i]; + } + } + break; +#endif + case VG_STROKE_LINE_WIDTH: + state->stroke.line_width.f = values[0]; + state->stroke.line_width.i = values[0]; + break; + case VG_STROKE_MITER_LIMIT: + state->stroke.miter_limit.f = values[0]; + state->stroke.miter_limit.i = values[0]; + break; + case VG_STROKE_DASH_PATTERN: { + int i; + for (i = 0; i < count; ++i) { + state->stroke.dash_pattern[i].f = values[i]; + state->stroke.dash_pattern[i].i = values[i]; + } + state->stroke.dash_pattern_num = count; + } + break; + case VG_STROKE_DASH_PHASE: + state->stroke.dash_phase.f = values[0]; + state->stroke.dash_phase.i = values[0]; + break; + case VG_TILE_FILL_COLOR: + state->tile_fill_color[0] = values[0]; + state->tile_fill_color[1] = values[1]; + state->tile_fill_color[2] = values[2]; + state->tile_fill_color[3] = values[3]; + + state->tile_fill_colori[0] = values[0]; + state->tile_fill_colori[1] = values[1]; + state->tile_fill_colori[2] = values[2]; + state->tile_fill_colori[3] = values[3]; + break; + case VG_CLEAR_COLOR: + state->clear_color[0] = values[0]; + state->clear_color[1] = values[1]; + state->clear_color[2] = values[2]; + state->clear_color[3] = values[3]; + + state->clear_colori[0] = values[0]; + state->clear_colori[1] = values[1]; + state->clear_colori[2] = values[2]; + state->clear_colori[3] = values[3]; + break; +#ifdef OPENVG_VERSION_1_1 + case VG_GLYPH_ORIGIN: + state->glyph_origin[0].f = values[0]; + state->glyph_origin[1].f = values[1]; + state->glyph_origin[0].i = values[0]; + state->glyph_origin[1].i = values[1]; + break; +#endif + + case VG_MAX_SCISSOR_RECTS: + case VG_MAX_DASH_COUNT: + case VG_MAX_KERNEL_SIZE: + case VG_MAX_SEPARABLE_KERNEL_SIZE: + case VG_MAX_COLOR_RAMP_STOPS: + case VG_MAX_IMAGE_WIDTH: + case VG_MAX_IMAGE_HEIGHT: + case VG_MAX_IMAGE_PIXELS: + case VG_MAX_IMAGE_BYTES: + case VG_MAX_GAUSSIAN_STD_DEVIATION: + case VG_MAX_FLOAT: + break; + + default: + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + break; + } +} + +VGfloat vegaGetf(VGParamType type) +{ + struct vg_context *ctx = vg_current_context(); + const struct vg_state *state = current_state(); + VGErrorCode error = VG_NO_ERROR; + VGfloat value = 0.0f; + + switch(type) { + case VG_MATRIX_MODE: + case VG_FILL_RULE: + case VG_IMAGE_QUALITY: + case VG_RENDERING_QUALITY: + case VG_BLEND_MODE: + case VG_IMAGE_MODE: +#ifdef OPENVG_VERSION_1_1 + case VG_COLOR_TRANSFORM: +#endif + case VG_STROKE_CAP_STYLE: + case VG_STROKE_JOIN_STYLE: + case VG_STROKE_DASH_PHASE_RESET: + case VG_MASKING: + case VG_SCISSORING: + case VG_PIXEL_LAYOUT: + case VG_SCREEN_LAYOUT: + case VG_FILTER_FORMAT_LINEAR: + case VG_FILTER_FORMAT_PREMULTIPLIED: + case VG_FILTER_CHANNEL_MASK: + return vgGeti(type); + break; + case VG_STROKE_LINE_WIDTH: + value = state->stroke.line_width.f; + break; + case VG_STROKE_MITER_LIMIT: + value = state->stroke.miter_limit.f; + break; + case VG_STROKE_DASH_PHASE: + value = state->stroke.dash_phase.f; + break; + + case VG_MAX_SCISSOR_RECTS: + case VG_MAX_DASH_COUNT: + case VG_MAX_KERNEL_SIZE: + case VG_MAX_SEPARABLE_KERNEL_SIZE: + case VG_MAX_COLOR_RAMP_STOPS: + case VG_MAX_IMAGE_WIDTH: + case VG_MAX_IMAGE_HEIGHT: + case VG_MAX_IMAGE_PIXELS: + case VG_MAX_IMAGE_BYTES: + case VG_MAX_GAUSSIAN_STD_DEVIATION: + return vgGeti(type); + break; + case VG_MAX_FLOAT: + value = 1e+10;/*must be at least 1e+10*/ + break; + default: + error = VG_ILLEGAL_ARGUMENT_ERROR; + break; + } + vg_set_error(ctx, error); + return value; +} + +VGint vegaGeti(VGParamType type) +{ + const struct vg_state *state = current_state(); + struct vg_context *ctx = vg_current_context(); + VGErrorCode error = VG_NO_ERROR; + VGint value = 0; + + switch(type) { + case VG_MATRIX_MODE: + value = state->matrix_mode; + break; + case VG_FILL_RULE: + value = state->fill_rule; + break; + case VG_IMAGE_QUALITY: + value = state->image_quality; + break; + case VG_RENDERING_QUALITY: + value = state->rendering_quality; + break; + case VG_BLEND_MODE: + value = state->blend_mode; + break; + case VG_IMAGE_MODE: + value = state->image_mode; + break; +#ifdef OPENVG_VERSION_1_1 + case VG_COLOR_TRANSFORM: + value = state->color_transform; + break; +#endif + case VG_STROKE_LINE_WIDTH: + value = state->stroke.line_width.i; + break; + case VG_STROKE_CAP_STYLE: + value = state->stroke.cap_style; + break; + case VG_STROKE_JOIN_STYLE: + value = state->stroke.join_style; + break; + case VG_STROKE_MITER_LIMIT: + value = state->stroke.miter_limit.i; + break; + case VG_STROKE_DASH_PHASE: + value = state->stroke.dash_phase.i; + break; + case VG_STROKE_DASH_PHASE_RESET: + value = state->stroke.dash_phase_reset; + break; + case VG_MASKING: + value = state->masking; + break; + case VG_SCISSORING: + value = state->scissoring; + break; + case VG_PIXEL_LAYOUT: + value = state->pixel_layout; + break; + case VG_SCREEN_LAYOUT: + value = state->screen_layout; + break; + case VG_FILTER_FORMAT_LINEAR: + value = state->filter_format_linear; + break; + case VG_FILTER_FORMAT_PREMULTIPLIED: + value = state->filter_format_premultiplied; + break; + case VG_FILTER_CHANNEL_MASK: + value = state->filter_channel_mask; + break; + + case VG_MAX_SCISSOR_RECTS: + value = 32; /*must be at least 32*/ + break; + case VG_MAX_DASH_COUNT: + value = 16; /*must be at least 16*/ + break; + case VG_MAX_KERNEL_SIZE: + value = 7; /*must be at least 7*/ + break; + case VG_MAX_SEPARABLE_KERNEL_SIZE: + value = 15; /*must be at least 15*/ + break; + case VG_MAX_COLOR_RAMP_STOPS: + value = 256; /*must be at least 32*/ + break; + case VG_MAX_IMAGE_WIDTH: + value = 2048; + break; + case VG_MAX_IMAGE_HEIGHT: + value = 2048; + break; + case VG_MAX_IMAGE_PIXELS: + value = 2048*2048; + break; + case VG_MAX_IMAGE_BYTES: + value = 2048*2048 * 4; + break; + case VG_MAX_GAUSSIAN_STD_DEVIATION: + value = 128; /*must be at least 128*/ + break; + + case VG_MAX_FLOAT: { + VGfloat val = vgGetf(type); + value = float_to_int_floor(*((VGuint*)&val)); + } + break; + default: + error = VG_ILLEGAL_ARGUMENT_ERROR; + break; + } + vg_set_error(ctx, error); + return value; +} + +VGint vegaGetVectorSize(VGParamType type) +{ + struct vg_context *ctx = vg_current_context(); + const struct vg_state *state = current_state(); + switch(type) { + case VG_MATRIX_MODE: + case VG_FILL_RULE: + case VG_IMAGE_QUALITY: + case VG_RENDERING_QUALITY: + case VG_BLEND_MODE: + case VG_IMAGE_MODE: + return 1; + case VG_SCISSOR_RECTS: + return state->scissor_rects_num * 4; +#ifdef OPENVG_VERSION_1_1 + case VG_COLOR_TRANSFORM: + return 1; + case VG_COLOR_TRANSFORM_VALUES: + return 8; +#endif + case VG_STROKE_LINE_WIDTH: + case VG_STROKE_CAP_STYLE: + case VG_STROKE_JOIN_STYLE: + case VG_STROKE_MITER_LIMIT: + return 1; + case VG_STROKE_DASH_PATTERN: + return state->stroke.dash_pattern_num; + case VG_STROKE_DASH_PHASE: + return 1; + case VG_STROKE_DASH_PHASE_RESET: + return 1; + case VG_TILE_FILL_COLOR: + return 4; + case VG_CLEAR_COLOR: + return 4; +#ifdef OPENVG_VERSION_1_1 + case VG_GLYPH_ORIGIN: + return 2; +#endif + case VG_MASKING: + return 1; + case VG_SCISSORING: + return 1; + case VG_PIXEL_LAYOUT: + return 1; + case VG_SCREEN_LAYOUT: + return 1; + case VG_FILTER_FORMAT_LINEAR: + return 1; + case VG_FILTER_FORMAT_PREMULTIPLIED: + return 1; + case VG_FILTER_CHANNEL_MASK: + return 1; + + case VG_MAX_COLOR_RAMP_STOPS: + return 1; + case VG_MAX_SCISSOR_RECTS: + case VG_MAX_DASH_COUNT: + case VG_MAX_KERNEL_SIZE: + case VG_MAX_SEPARABLE_KERNEL_SIZE: + case VG_MAX_IMAGE_WIDTH: + case VG_MAX_IMAGE_HEIGHT: + case VG_MAX_IMAGE_PIXELS: + case VG_MAX_IMAGE_BYTES: + case VG_MAX_FLOAT: + case VG_MAX_GAUSSIAN_STD_DEVIATION: + return 1; + default: + if (ctx) + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return 0; + } +} + +void vegaGetfv(VGParamType type, VGint count, + VGfloat * values) +{ + const struct vg_state *state = current_state(); + struct vg_context *ctx = vg_current_context(); + VGint real_count = vgGetVectorSize(type); + + if (!values || count <= 0 || count > real_count || !is_aligned(values)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + switch(type) { + case VG_MATRIX_MODE: + case VG_FILL_RULE: + case VG_IMAGE_QUALITY: + case VG_RENDERING_QUALITY: + case VG_BLEND_MODE: + case VG_IMAGE_MODE: +#ifdef OPENVG_VERSION_1_1 + case VG_COLOR_TRANSFORM: +#endif + case VG_STROKE_CAP_STYLE: + case VG_STROKE_JOIN_STYLE: + case VG_STROKE_DASH_PHASE_RESET: + case VG_MASKING: + case VG_SCISSORING: + case VG_PIXEL_LAYOUT: + case VG_SCREEN_LAYOUT: + case VG_FILTER_FORMAT_LINEAR: + case VG_FILTER_FORMAT_PREMULTIPLIED: + case VG_FILTER_CHANNEL_MASK: + case VG_MAX_SCISSOR_RECTS: + case VG_MAX_DASH_COUNT: + case VG_MAX_KERNEL_SIZE: + case VG_MAX_SEPARABLE_KERNEL_SIZE: + case VG_MAX_COLOR_RAMP_STOPS: + case VG_MAX_IMAGE_WIDTH: + case VG_MAX_IMAGE_HEIGHT: + case VG_MAX_IMAGE_PIXELS: + case VG_MAX_IMAGE_BYTES: + case VG_MAX_GAUSSIAN_STD_DEVIATION: + values[0] = vgGeti(type); + break; + case VG_MAX_FLOAT: + values[0] = vgGetf(type); + break; + case VG_SCISSOR_RECTS: { + VGint i; + for (i = 0; i < count; ++i) { + values[i] = state->scissor_rects[i].f; + } + } + break; +#ifdef OPENVG_VERSION_1_1 + case VG_COLOR_TRANSFORM_VALUES: { + memcpy(values, state->color_transform_values, + sizeof(VGfloat) * count); + } + break; +#endif + case VG_STROKE_LINE_WIDTH: + values[0] = state->stroke.line_width.f; + break; + case VG_STROKE_MITER_LIMIT: + values[0] = state->stroke.miter_limit.f; + break; + case VG_STROKE_DASH_PATTERN: { + VGint i; + for (i = 0; i < count; ++i) { + values[i] = state->stroke.dash_pattern[i].f; + } + } + break; + case VG_STROKE_DASH_PHASE: + values[0] = state->stroke.dash_phase.f; + break; + case VG_TILE_FILL_COLOR: + values[0] = state->tile_fill_color[0]; + values[1] = state->tile_fill_color[1]; + values[2] = state->tile_fill_color[2]; + values[3] = state->tile_fill_color[3]; + break; + case VG_CLEAR_COLOR: + values[0] = state->clear_color[0]; + values[1] = state->clear_color[1]; + values[2] = state->clear_color[2]; + values[3] = state->clear_color[3]; + break; +#ifdef OPENVG_VERSION_1_1 + case VG_GLYPH_ORIGIN: + values[0] = state->glyph_origin[0].f; + values[1] = state->glyph_origin[1].f; + break; +#endif + default: + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + break; + } +} + +void vegaGetiv(VGParamType type, VGint count, + VGint * values) +{ + const struct vg_state *state = current_state(); + struct vg_context *ctx = vg_current_context(); + VGint real_count = vgGetVectorSize(type); + + if (!values || count <= 0 || count > real_count || !is_aligned(values)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + switch(type) { + case VG_MATRIX_MODE: + case VG_FILL_RULE: + case VG_IMAGE_QUALITY: + case VG_RENDERING_QUALITY: + case VG_BLEND_MODE: + case VG_IMAGE_MODE: +#ifdef OPENVG_VERSION_1_1 + case VG_COLOR_TRANSFORM: +#endif + case VG_STROKE_CAP_STYLE: + case VG_STROKE_JOIN_STYLE: + case VG_STROKE_DASH_PHASE_RESET: + case VG_MASKING: + case VG_SCISSORING: + case VG_PIXEL_LAYOUT: + case VG_SCREEN_LAYOUT: + case VG_FILTER_FORMAT_LINEAR: + case VG_FILTER_FORMAT_PREMULTIPLIED: + case VG_FILTER_CHANNEL_MASK: + case VG_MAX_SCISSOR_RECTS: + case VG_MAX_DASH_COUNT: + case VG_MAX_KERNEL_SIZE: + case VG_MAX_SEPARABLE_KERNEL_SIZE: + case VG_MAX_COLOR_RAMP_STOPS: + case VG_MAX_IMAGE_WIDTH: + case VG_MAX_IMAGE_HEIGHT: + case VG_MAX_IMAGE_PIXELS: + case VG_MAX_IMAGE_BYTES: + case VG_MAX_GAUSSIAN_STD_DEVIATION: + values[0] = vgGeti(type); + break; + case VG_MAX_FLOAT: { + VGfloat val = vgGetf(type); + values[0] = float_to_int_floor(*((VGuint*)&val)); + } + break; + case VG_SCISSOR_RECTS: { + VGint i; + for (i = 0; i < count; ++i) { + values[i] = state->scissor_rects[i].i; + } + } + break; +#ifdef OPENVG_VERSION_1_1 + case VG_COLOR_TRANSFORM_VALUES: { + VGint i; + VGuint *x = (VGuint*)state->color_transform_values; + for (i = 0; i < count; ++i) { + values[i] = float_to_int_floor(x[i]); + } + } + break; +#endif + case VG_STROKE_LINE_WIDTH: + values[0] = state->stroke.line_width.i; + break; + case VG_STROKE_MITER_LIMIT: + values[0] = state->stroke.miter_limit.i; + break; + case VG_STROKE_DASH_PATTERN: { + VGint i; + for (i = 0; i < count; ++i) { + values[i] = state->stroke.dash_pattern[i].i; + } + } + break; + case VG_STROKE_DASH_PHASE: + values[0] = state->stroke.dash_phase.i; + break; + case VG_TILE_FILL_COLOR: + values[0] = state->tile_fill_colori[0]; + values[1] = state->tile_fill_colori[1]; + values[2] = state->tile_fill_colori[2]; + values[3] = state->tile_fill_colori[3]; + break; + case VG_CLEAR_COLOR: + values[0] = state->clear_colori[0]; + values[1] = state->clear_colori[1]; + values[2] = state->clear_colori[2]; + values[3] = state->clear_colori[3]; + break; +#ifdef OPENVG_VERSION_1_1 + case VG_GLYPH_ORIGIN: + values[0] = state->glyph_origin[0].i; + values[1] = state->glyph_origin[1].i; + break; +#endif + default: + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + break; + } +} + +void vegaSetParameterf(VGHandle object, + VGint paramType, + VGfloat value) +{ + struct vg_context *ctx = vg_current_context(); + void *ptr = (void*)object; + + if (!object || object == VG_INVALID_HANDLE || !is_aligned(ptr)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + switch(paramType) { + case VG_PAINT_TYPE: + case VG_PAINT_COLOR_RAMP_SPREAD_MODE: + case VG_PAINT_PATTERN_TILING_MODE: + vgSetParameteri(object, paramType, floor(value)); + return; + break; + case VG_PAINT_COLOR: + case VG_PAINT_COLOR_RAMP_STOPS: + case VG_PAINT_LINEAR_GRADIENT: + case VG_PAINT_RADIAL_GRADIENT: + /* it's an error if paramType refers to a vector parameter */ + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + break; + case VG_PAINT_COLOR_RAMP_PREMULTIPLIED: { + struct vg_paint *p = (struct vg_paint *)object; + paint_set_color_ramp_premultiplied(p, value); + } + break; + + case VG_PATH_DATATYPE: + case VG_PATH_FORMAT: + case VG_PATH_SCALE: + case VG_PATH_BIAS: + case VG_PATH_NUM_SEGMENTS: + case VG_PATH_NUM_COORDS: + + case VG_IMAGE_FORMAT: + case VG_IMAGE_WIDTH: + case VG_IMAGE_HEIGHT: + +#ifdef OPENVG_VERSION_1_1 + case VG_FONT_NUM_GLYPHS: + /* read only don't produce an error */ + break; +#endif + default: + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + break; + } +} + +void vegaSetParameteri(VGHandle object, + VGint paramType, + VGint value) +{ + struct vg_context *ctx = vg_current_context(); + void *ptr = (void*)object; + + if (!object || object == VG_INVALID_HANDLE || !is_aligned(ptr)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + switch(paramType) { + case VG_PAINT_TYPE: + if (value < VG_PAINT_TYPE_COLOR || + value > VG_PAINT_TYPE_PATTERN) + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + else { + struct vg_paint *paint = (struct vg_paint *)ptr; + paint_set_type(paint, value); + } + break; + case VG_PAINT_COLOR: + case VG_PAINT_COLOR_RAMP_STOPS: + case VG_PAINT_LINEAR_GRADIENT: + case VG_PAINT_RADIAL_GRADIENT: + /* it's an error if paramType refers to a vector parameter */ + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + break; + case VG_PAINT_COLOR_RAMP_SPREAD_MODE: + if (value < VG_COLOR_RAMP_SPREAD_PAD || + value > VG_COLOR_RAMP_SPREAD_REFLECT) + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + else { + struct vg_paint *paint = (struct vg_paint *)ptr; + paint_set_spread_mode(paint, value); + } + break; + case VG_PAINT_COLOR_RAMP_PREMULTIPLIED: { + struct vg_paint *p = (struct vg_paint *)object; + paint_set_color_ramp_premultiplied(p, value); + } + break; + case VG_PAINT_PATTERN_TILING_MODE: + if (value < VG_TILE_FILL || + value > VG_TILE_REFLECT) + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + else { + struct vg_paint *paint = (struct vg_paint *)ptr; + paint_set_pattern_tiling(paint, value); + } + break; + + case VG_PATH_DATATYPE: + case VG_PATH_FORMAT: + case VG_PATH_SCALE: + case VG_PATH_BIAS: + case VG_PATH_NUM_SEGMENTS: + case VG_PATH_NUM_COORDS: + + case VG_IMAGE_FORMAT: + case VG_IMAGE_WIDTH: + case VG_IMAGE_HEIGHT: + +#ifdef OPENVG_VERSION_1_1 + case VG_FONT_NUM_GLYPHS: + /* read only don't produce an error */ + break; +#endif + default: + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } +} + +void vegaSetParameterfv(VGHandle object, + VGint paramType, + VGint count, + const VGfloat * values) +{ + struct vg_context *ctx = vg_current_context(); + void *ptr = (void*)object; + VGint real_count = vgGetParameterVectorSize(object, paramType); + + if (!object || object == VG_INVALID_HANDLE || !is_aligned(ptr)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (count < 0 || count < real_count || + (values == NULL && count != 0) || + !is_aligned(values)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + switch(paramType) { + case VG_PAINT_TYPE: + case VG_PAINT_COLOR_RAMP_SPREAD_MODE: + case VG_PAINT_COLOR_RAMP_PREMULTIPLIED: + case VG_PAINT_PATTERN_TILING_MODE: + if (count != 1) + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + else + vgSetParameterf(object, paramType, values[0]); + return; + break; + case VG_PAINT_COLOR: { + if (count != 4) + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + else { + struct vg_paint *paint = (struct vg_paint *)object; + paint_set_color(paint, values); + } + } + break; + case VG_PAINT_COLOR_RAMP_STOPS: { + if (count && count < 4) + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + else { + struct vg_paint *paint = (struct vg_paint *)object; + count = MIN2(count, VEGA_MAX_COLOR_RAMP_STOPS); + paint_set_ramp_stops(paint, values, count); + { + VGint stopsi[VEGA_MAX_COLOR_RAMP_STOPS]; + int i = 0; + for (i = 0; i < count; ++i) { + stopsi[i] = float_to_int_floor(*((VGuint*)(values + i))); + } + paint_set_ramp_stopsi(paint, stopsi, count); + } + } + } + break; + case VG_PAINT_LINEAR_GRADIENT: { + if (count != 4) + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + else { + struct vg_paint *paint = (struct vg_paint *)object; + paint_set_linear_gradient(paint, values); + { + VGint vals[4]; + vals[0] = FLT_TO_INT(values[0]); + vals[1] = FLT_TO_INT(values[1]); + vals[2] = FLT_TO_INT(values[2]); + vals[3] = FLT_TO_INT(values[3]); + paint_set_linear_gradienti(paint, vals); + } + } + } + break; + case VG_PAINT_RADIAL_GRADIENT: { + if (count != 5) + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + else { + struct vg_paint *paint = (struct vg_paint *)object; + paint_set_radial_gradient(paint, values); + { + VGint vals[5]; + vals[0] = FLT_TO_INT(values[0]); + vals[1] = FLT_TO_INT(values[1]); + vals[2] = FLT_TO_INT(values[2]); + vals[3] = FLT_TO_INT(values[3]); + vals[4] = FLT_TO_INT(values[4]); + paint_set_radial_gradienti(paint, vals); + } + } + } + break; + + case VG_PATH_DATATYPE: + case VG_PATH_FORMAT: + case VG_PATH_SCALE: + case VG_PATH_BIAS: + case VG_PATH_NUM_SEGMENTS: + case VG_PATH_NUM_COORDS: + +#ifdef OPENVG_VERSION_1_1 + case VG_FONT_NUM_GLYPHS: + /* read only don't produce an error */ + break; +#endif + default: + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } +} + +void vegaSetParameteriv(VGHandle object, + VGint paramType, + VGint count, + const VGint * values) +{ + struct vg_context *ctx = vg_current_context(); + void *ptr = (void*)object; + VGint real_count = vgGetParameterVectorSize(object, paramType); + + if (!object || object == VG_INVALID_HANDLE || !is_aligned(ptr)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (count < 0 || count < real_count || + (values == NULL && count != 0) || + !is_aligned(values)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + switch(paramType) { + case VG_PAINT_TYPE: + case VG_PAINT_COLOR_RAMP_SPREAD_MODE: + case VG_PAINT_COLOR_RAMP_PREMULTIPLIED: + case VG_PAINT_PATTERN_TILING_MODE: + if (count != 1) + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + else + vgSetParameteri(object, paramType, values[0]); + return; + break; + case VG_PAINT_COLOR: { + if (count != 4) + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + else { + struct vg_paint *paint = (struct vg_paint *)object; + paint_set_coloriv(paint, values); + } + } + break; + case VG_PAINT_COLOR_RAMP_STOPS: { + if ((count % 5)) + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + else { + VGfloat *vals = 0; + int i; + struct vg_paint *paint = (struct vg_paint *)object; + if (count) { + vals = malloc(sizeof(VGfloat)*count); + for (i = 0; i < count; ++i) + vals[i] = values[i]; + } + + paint_set_ramp_stopsi(paint, values, count); + paint_set_ramp_stops(paint, vals, count); + free(vals); + } + } + break; + case VG_PAINT_LINEAR_GRADIENT: { + if (count != 4) + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + else { + VGfloat vals[4]; + struct vg_paint *paint = (struct vg_paint *)object; + vals[0] = values[0]; + vals[1] = values[1]; + vals[2] = values[2]; + vals[3] = values[3]; + paint_set_linear_gradient(paint, vals); + paint_set_linear_gradienti(paint, values); + } + } + break; + case VG_PAINT_RADIAL_GRADIENT: { + if (count != 5) + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + else { + VGfloat vals[5]; + struct vg_paint *paint = (struct vg_paint *)object; + vals[0] = values[0]; + vals[1] = values[1]; + vals[2] = values[2]; + vals[3] = values[3]; + vals[4] = values[4]; + paint_set_radial_gradient(paint, vals); + paint_set_radial_gradienti(paint, values); + } + } + break; + case VG_PATH_DATATYPE: + case VG_PATH_FORMAT: + case VG_PATH_SCALE: + case VG_PATH_BIAS: + case VG_PATH_NUM_SEGMENTS: + case VG_PATH_NUM_COORDS: + /* read only don't produce an error */ + break; + default: + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } +} + +VGint vegaGetParameterVectorSize(VGHandle object, + VGint paramType) +{ + struct vg_context *ctx = vg_current_context(); + void *ptr = (void*)object; + + if (!ptr || object == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return 0; + } + + switch(paramType) { + case VG_PAINT_TYPE: + case VG_PAINT_COLOR_RAMP_SPREAD_MODE: + case VG_PAINT_COLOR_RAMP_PREMULTIPLIED: + case VG_PAINT_PATTERN_TILING_MODE: + return 1; + case VG_PAINT_COLOR: + return 4; + case VG_PAINT_COLOR_RAMP_STOPS: { + struct vg_paint *p = (struct vg_paint *)object; + return paint_num_ramp_stops(p); + } + break; + case VG_PAINT_LINEAR_GRADIENT: + return 4; + case VG_PAINT_RADIAL_GRADIENT: + return 5; + + + case VG_PATH_FORMAT: + case VG_PATH_DATATYPE: + case VG_PATH_SCALE: + case VG_PATH_BIAS: + case VG_PATH_NUM_SEGMENTS: + case VG_PATH_NUM_COORDS: + return 1; + + case VG_IMAGE_FORMAT: + case VG_IMAGE_WIDTH: + case VG_IMAGE_HEIGHT: + return 1; + +#ifdef OPENVG_VERSION_1_1 + case VG_FONT_NUM_GLYPHS: + return 1; +#endif + + default: + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + break; + } + return 0; +} + + +VGfloat vegaGetParameterf(VGHandle object, + VGint paramType) +{ + struct vg_context *ctx = vg_current_context(); + void *ptr = (void*)object; + + if (!ptr || object == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return 0; + } + + switch(paramType) { + case VG_PAINT_TYPE: + case VG_PAINT_COLOR_RAMP_SPREAD_MODE: + case VG_PAINT_COLOR_RAMP_PREMULTIPLIED: + case VG_PAINT_PATTERN_TILING_MODE: + return vgGetParameteri(object, paramType); + break; + case VG_PAINT_COLOR: + case VG_PAINT_COLOR_RAMP_STOPS: + case VG_PAINT_LINEAR_GRADIENT: + case VG_PAINT_RADIAL_GRADIENT: + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + break; + + case VG_PATH_FORMAT: + return VG_PATH_FORMAT_STANDARD; + case VG_PATH_SCALE: { + struct path *p = (struct path*)object; + return path_scale(p); + } + case VG_PATH_BIAS: { + struct path *p = (struct path*)object; + return path_bias(p); + } + case VG_PATH_DATATYPE: + case VG_PATH_NUM_SEGMENTS: + case VG_PATH_NUM_COORDS: + return vgGetParameteri(object, paramType); + break; + + case VG_IMAGE_FORMAT: + case VG_IMAGE_WIDTH: + case VG_IMAGE_HEIGHT: +#ifdef OPENVG_VERSION_1_1 + case VG_FONT_NUM_GLYPHS: + return vgGetParameteri(object, paramType); + break; +#endif + + default: + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + break; + } + return 0; +} + +VGint vegaGetParameteri(VGHandle object, + VGint paramType) +{ + struct vg_context *ctx = vg_current_context(); + void *ptr = (void*)object; + + if (!ptr || object == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return 0; + } + + switch(paramType) { + case VG_PAINT_TYPE: { + struct vg_paint *paint = (struct vg_paint *)ptr; + return paint_type(paint); + } + break; + case VG_PAINT_COLOR_RAMP_SPREAD_MODE: { + struct vg_paint *p = (struct vg_paint *)object; + return paint_spread_mode(p); + } + case VG_PAINT_COLOR_RAMP_PREMULTIPLIED: { + struct vg_paint *p = (struct vg_paint *)object; + return paint_color_ramp_premultiplied(p); + } + break; + case VG_PAINT_PATTERN_TILING_MODE: { + struct vg_paint *p = (struct vg_paint *)object; + return paint_pattern_tiling(p); + } + break; + case VG_PAINT_COLOR: + case VG_PAINT_COLOR_RAMP_STOPS: + case VG_PAINT_LINEAR_GRADIENT: + case VG_PAINT_RADIAL_GRADIENT: + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + break; + + case VG_PATH_FORMAT: + return VG_PATH_FORMAT_STANDARD; + case VG_PATH_SCALE: + case VG_PATH_BIAS: + return vgGetParameterf(object, paramType); + case VG_PATH_DATATYPE: { + struct path *p = (struct path*)object; + return path_datatype(p); + } + case VG_PATH_NUM_SEGMENTS: { + struct path *p = (struct path*)object; + return path_num_segments(p); + } + case VG_PATH_NUM_COORDS: { + struct path *p = (struct path*)object; + return path_num_coords(p); + } + break; + + case VG_IMAGE_FORMAT: { + struct vg_image *img = (struct vg_image*)object; + return img->format; + } + break; + case VG_IMAGE_WIDTH: { + struct vg_image *img = (struct vg_image*)object; + return img->width; + } + break; + case VG_IMAGE_HEIGHT: { + struct vg_image *img = (struct vg_image*)object; + return img->height; + } + break; + +#ifdef OPENVG_VERSION_1_1 + case VG_FONT_NUM_GLYPHS: { + struct vg_font *font = (struct vg_font*)object; + return font_num_glyphs(font); + } + break; +#endif + + default: + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + break; + } + return 0; +} + +void vegaGetParameterfv(VGHandle object, + VGint paramType, + VGint count, + VGfloat * values) +{ + struct vg_context *ctx = vg_current_context(); + void *ptr = (void*)object; + VGint real_count = vgGetParameterVectorSize(object, paramType); + + if (!ptr || object == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (!values || count <= 0 || count > real_count || + !is_aligned(values)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + switch(paramType) { + case VG_PAINT_TYPE: { + struct vg_paint *p = (struct vg_paint *)object; + values[0] = paint_type(p); + } + break; + case VG_PAINT_COLOR_RAMP_SPREAD_MODE: { + struct vg_paint *p = (struct vg_paint *)object; + values[0] = paint_spread_mode(p); + } + break; + case VG_PAINT_COLOR_RAMP_PREMULTIPLIED: { + struct vg_paint *p = (struct vg_paint *)object; + values[0] = paint_color_ramp_premultiplied(p); + } + break; + case VG_PAINT_PATTERN_TILING_MODE: { + values[0] = vgGetParameterf(object, paramType); + } + break; + case VG_PAINT_COLOR: { + struct vg_paint *paint = (struct vg_paint *)object; + paint_get_color(paint, values); + } + break; + case VG_PAINT_COLOR_RAMP_STOPS: { + struct vg_paint *paint = (struct vg_paint *)object; + paint_ramp_stops(paint, values, count); + } + break; + case VG_PAINT_LINEAR_GRADIENT: { + struct vg_paint *paint = (struct vg_paint *)object; + paint_linear_gradient(paint, values); + } + break; + case VG_PAINT_RADIAL_GRADIENT: { + struct vg_paint *paint = (struct vg_paint *)object; + paint_radial_gradient(paint, values); + } + break; + + case VG_PATH_FORMAT: + case VG_PATH_DATATYPE: + case VG_PATH_NUM_SEGMENTS: + case VG_PATH_NUM_COORDS: + values[0] = vgGetParameteri(object, paramType); + break; + case VG_PATH_SCALE: + case VG_PATH_BIAS: + values[0] = vgGetParameterf(object, paramType); + break; + + case VG_IMAGE_FORMAT: + case VG_IMAGE_WIDTH: + case VG_IMAGE_HEIGHT: +#ifdef OPENVG_VERSION_1_1 + case VG_FONT_NUM_GLYPHS: + values[0] = vgGetParameteri(object, paramType); + break; +#endif + + default: + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + break; + } +} + +void vegaGetParameteriv(VGHandle object, + VGint paramType, + VGint count, + VGint * values) +{ + struct vg_context *ctx = vg_current_context(); + void *ptr = (void*)object; + VGint real_count = vgGetParameterVectorSize(object, paramType); + + if (!ptr || object == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (!values || count <= 0 || count > real_count || + !is_aligned(values)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + switch(paramType) { + case VG_PAINT_TYPE: + case VG_PAINT_COLOR_RAMP_SPREAD_MODE: + case VG_PAINT_COLOR_RAMP_PREMULTIPLIED: + case VG_PAINT_PATTERN_TILING_MODE: +#ifdef OPENVG_VERSION_1_1 + case VG_FONT_NUM_GLYPHS: + values[0] = vgGetParameteri(object, paramType); + break; +#endif + case VG_PAINT_COLOR: { + struct vg_paint *paint = (struct vg_paint *)object; + paint_get_coloriv(paint, values); + } + break; + case VG_PAINT_COLOR_RAMP_STOPS: { + struct vg_paint *paint = (struct vg_paint *)object; + paint_ramp_stopsi(paint, values, count); + } + break; + case VG_PAINT_LINEAR_GRADIENT: { + struct vg_paint *paint = (struct vg_paint *)object; + paint_linear_gradienti(paint, values); + } + break; + case VG_PAINT_RADIAL_GRADIENT: { + struct vg_paint *paint = (struct vg_paint *)object; + paint_radial_gradienti(paint, values); + } + break; + + case VG_PATH_SCALE: + case VG_PATH_BIAS: + values[0] = vgGetParameterf(object, paramType); + break; + case VG_PATH_FORMAT: + case VG_PATH_DATATYPE: + case VG_PATH_NUM_SEGMENTS: + case VG_PATH_NUM_COORDS: + values[0] = vgGetParameteri(object, paramType); + break; + + case VG_IMAGE_FORMAT: + case VG_IMAGE_WIDTH: + case VG_IMAGE_HEIGHT: + values[0] = vgGetParameteri(object, paramType); + break; + + default: + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + break; + } +} diff --git a/src/gallium/state_trackers/vega/api_path.c b/src/gallium/state_trackers/vega/api_path.c new file mode 100644 index 0000000..fe57b76 --- /dev/null +++ b/src/gallium/state_trackers/vega/api_path.c @@ -0,0 +1,485 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "VG/openvg.h" + +#include "vg_context.h" +#include "path.h" +#include "api.h" + +#include "pipe/p_context.h" + +VGPath vegaCreatePath(VGint pathFormat, + VGPathDatatype datatype, + VGfloat scale, VGfloat bias, + VGint segmentCapacityHint, + VGint coordCapacityHint, + VGbitfield capabilities) +{ + struct vg_context *ctx = vg_current_context(); + + if (pathFormat != VG_PATH_FORMAT_STANDARD) { + vg_set_error(ctx, VG_UNSUPPORTED_PATH_FORMAT_ERROR); + return VG_INVALID_HANDLE; + } + if (datatype < VG_PATH_DATATYPE_S_8 || + datatype > VG_PATH_DATATYPE_F) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_INVALID_HANDLE; + } + if (!scale) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_INVALID_HANDLE; + } + + return (VGPath)path_create(datatype, scale, bias, + segmentCapacityHint, coordCapacityHint, + capabilities); +} + +void vegaClearPath(VGPath path, VGbitfield capabilities) +{ + struct vg_context *ctx = vg_current_context(); + struct path *p = 0; + + if (path == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + p = (struct path *)path; + path_clear(p, capabilities); +} + +void vegaDestroyPath(VGPath p) +{ + struct path *path = 0; + struct vg_context *ctx = vg_current_context(); + + if (p == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + path = (struct path *)p; + path_destroy(path); +} + +void vegaRemovePathCapabilities(VGPath path, + VGbitfield capabilities) +{ + struct vg_context *ctx = vg_current_context(); + VGbitfield current; + struct path *p; + + if (path == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + p = (struct path*)path; + current = path_capabilities(p); + path_set_capabilities(p, (current & + (~(capabilities & VG_PATH_CAPABILITY_ALL)))); +} + +VGbitfield vegaGetPathCapabilities(VGPath path) +{ + struct vg_context *ctx = vg_current_context(); + struct path *p = 0; + + if (path == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return 0; + } + p = (struct path*)path; + return path_capabilities(p); +} + +void vegaAppendPath(VGPath dstPath, VGPath srcPath) +{ + struct vg_context *ctx = vg_current_context(); + struct path *src, *dst; + + if (dstPath == VG_INVALID_HANDLE || srcPath == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + src = (struct path *)srcPath; + dst = (struct path *)dstPath; + + if (!(path_capabilities(src) & VG_PATH_CAPABILITY_APPEND_FROM) || + !(path_capabilities(dst) & VG_PATH_CAPABILITY_APPEND_TO)) { + vg_set_error(ctx, VG_PATH_CAPABILITY_ERROR); + return; + } + path_append_path(dst, src); +} + +void vegaAppendPathData(VGPath dstPath, + VGint numSegments, + const VGubyte * pathSegments, + const void * pathData) +{ + struct vg_context *ctx = vg_current_context(); + struct path *p = 0; + VGint i; + + if (dstPath == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (!pathSegments) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if (numSegments <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + for (i = 0; i < numSegments; ++i) { + if (pathSegments[i] > VG_LCWARC_TO_REL) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + } + + p = (struct path*)dstPath; + + if (!pathData || !is_aligned_to(pathData, path_datatype_size(p))) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (!(path_capabilities(p)&VG_PATH_CAPABILITY_APPEND_TO)) { + vg_set_error(ctx, VG_PATH_CAPABILITY_ERROR); + return; + } + + path_append_data(p, numSegments, pathSegments, pathData); +} + +void vegaModifyPathCoords(VGPath dstPath, + VGint startIndex, + VGint numSegments, + const void * pathData) +{ + struct vg_context *ctx = vg_current_context(); + struct path *p = 0; + + if (dstPath == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (startIndex < 0 || numSegments <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + p = (struct path *)dstPath; + + if (!pathData || !is_aligned_to(pathData, path_datatype_size(p))) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (startIndex + numSegments > path_num_segments(p)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if (!(path_capabilities(p)&VG_PATH_CAPABILITY_MODIFY)) { + vg_set_error(ctx, VG_PATH_CAPABILITY_ERROR); + return; + } + path_modify_coords(p, startIndex, numSegments, pathData); +} + +void vegaTransformPath(VGPath dstPath, VGPath srcPath) +{ + struct vg_context *ctx = vg_current_context(); + struct path *src = 0, *dst = 0; + + if (dstPath == VG_INVALID_HANDLE || srcPath == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + src = (struct path *)srcPath; + dst = (struct path *)dstPath; + + if (!(path_capabilities(src) & VG_PATH_CAPABILITY_TRANSFORM_FROM) || + !(path_capabilities(dst) & VG_PATH_CAPABILITY_TRANSFORM_TO)) { + vg_set_error(ctx, VG_PATH_CAPABILITY_ERROR); + return; + } + path_transform(dst, src); +} + +VGboolean vegaInterpolatePath(VGPath dstPath, + VGPath startPath, + VGPath endPath, + VGfloat amount) +{ + struct vg_context *ctx = vg_current_context(); + struct path *start = 0, *dst = 0, *end = 0; + + if (dstPath == VG_INVALID_HANDLE || + startPath == VG_INVALID_HANDLE || + endPath == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return VG_FALSE; + } + dst = (struct path *)dstPath; + start = (struct path *)startPath; + end = (struct path *)endPath; + + if (!(path_capabilities(dst) & VG_PATH_CAPABILITY_INTERPOLATE_TO) || + !(path_capabilities(start) & VG_PATH_CAPABILITY_INTERPOLATE_FROM) || + !(path_capabilities(end) & VG_PATH_CAPABILITY_INTERPOLATE_FROM)) { + vg_set_error(ctx, VG_PATH_CAPABILITY_ERROR); + return VG_FALSE; + } + + return path_interpolate(dst, + start, end, amount); +} + +VGfloat vegaPathLength(VGPath path, + VGint startSegment, + VGint numSegments) +{ + struct vg_context *ctx = vg_current_context(); + struct path *p = 0; + + if (path == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return -1; + } + if (startSegment < 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return -1; + } + if (numSegments <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return -1; + } + p = (struct path*)path; + + if (!(path_capabilities(p) & VG_PATH_CAPABILITY_PATH_LENGTH)) { + vg_set_error(ctx, VG_PATH_CAPABILITY_ERROR); + return -1; + } + if (startSegment + numSegments > path_num_segments(p)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return -1; + } + + return path_length(p, startSegment, numSegments); +} + +void vegaPointAlongPath(VGPath path, + VGint startSegment, + VGint numSegments, + VGfloat distance, + VGfloat * x, VGfloat * y, + VGfloat * tangentX, + VGfloat * tangentY) +{ + struct vg_context *ctx = vg_current_context(); + struct path *p = 0; + VGbitfield caps; + + if (path == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (startSegment < 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if (numSegments <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (!is_aligned(x) || !is_aligned(y) || + !is_aligned(tangentX) || !is_aligned(tangentY)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + p = (struct path*)path; + + caps = path_capabilities(p); + if (!(caps & VG_PATH_CAPABILITY_POINT_ALONG_PATH) || + !(caps & VG_PATH_CAPABILITY_TANGENT_ALONG_PATH)) { + vg_set_error(ctx, VG_PATH_CAPABILITY_ERROR); + return; + } + + if (startSegment + numSegments > path_num_segments(p)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + { + VGfloat point[2], normal[2]; + path_point(p, startSegment, numSegments, distance, + point, normal); + if (x) + *x = point[0]; + if (y) + *y = point[1]; + if (tangentX) + *tangentX = -normal[1]; + if (tangentY) + *tangentY = normal[0]; + } +} + +void vegaPathBounds(VGPath path, + VGfloat * minX, + VGfloat * minY, + VGfloat * width, + VGfloat * height) +{ + struct vg_context *ctx = vg_current_context(); + struct path *p = 0; + VGbitfield caps; + + if (path == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (!minX || !minY || !width || !height) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (!is_aligned(minX) || !is_aligned(minY) || + !is_aligned(width) || !is_aligned(height)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + p = (struct path*)path; + + caps = path_capabilities(p); + if (!(caps & VG_PATH_CAPABILITY_PATH_BOUNDS)) { + vg_set_error(ctx, VG_PATH_CAPABILITY_ERROR); + return; + } + + path_bounding_rect(p, minX, minY, width, height); +} + +void vegaPathTransformedBounds(VGPath path, + VGfloat * minX, + VGfloat * minY, + VGfloat * width, + VGfloat * height) +{ + struct vg_context *ctx = vg_current_context(); + struct path *p = 0; + VGbitfield caps; + + if (path == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (!minX || !minY || !width || !height) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (!is_aligned(minX) || !is_aligned(minY) || + !is_aligned(width) || !is_aligned(height)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + p = (struct path*)path; + + caps = path_capabilities(p); + if (!(caps & VG_PATH_CAPABILITY_PATH_TRANSFORMED_BOUNDS)) { + vg_set_error(ctx, VG_PATH_CAPABILITY_ERROR); + return; + } + +#if 0 + /* faster, but seems to have precision problems... */ + path_bounding_rect(p, minX, minY, width, height); + if (*width > 0 && *height > 0) { + VGfloat pts[] = {*minX, *minY, + *minX + *width, *minY, + *minX + *width, *minY + *height, + *minX, *minY + *height}; + struct matrix *matrix = &ctx->state.vg.path_user_to_surface_matrix; + VGfloat maxX, maxY; + matrix_map_point(matrix, pts[0], pts[1], pts + 0, pts + 1); + matrix_map_point(matrix, pts[2], pts[3], pts + 2, pts + 3); + matrix_map_point(matrix, pts[4], pts[5], pts + 4, pts + 5); + matrix_map_point(matrix, pts[6], pts[7], pts + 6, pts + 7); + *minX = MIN2(pts[0], MIN2(pts[2], MIN2(pts[4], pts[6]))); + *minY = MIN2(pts[1], MIN2(pts[3], MIN2(pts[5], pts[7]))); + maxX = MAX2(pts[0], MAX2(pts[2], MAX2(pts[4], pts[6]))); + maxY = MAX2(pts[1], MAX2(pts[3], MAX2(pts[5], pts[7]))); + *width = maxX - *minX; + *height = maxY - *minY; + } +#else + { + struct path *dst = path_create(VG_PATH_DATATYPE_F, 1.0, 0, + 0, 0, VG_PATH_CAPABILITY_ALL); + path_transform(dst, p); + path_bounding_rect(dst, minX, minY, width, height); + path_destroy(dst); + } +#endif +} + + +void vegaDrawPath(VGPath path, VGbitfield paintModes) +{ + struct vg_context *ctx = vg_current_context(); + + if (path == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + if (!(paintModes & (VG_STROKE_PATH | VG_FILL_PATH))) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (path_is_empty((struct path*)path)) + return; + path_render((struct path*)path, paintModes, + &ctx->state.vg.path_user_to_surface_matrix); +} + diff --git a/src/gallium/state_trackers/vega/api_text.c b/src/gallium/state_trackers/vega/api_text.c new file mode 100644 index 0000000..7c6b479 --- /dev/null +++ b/src/gallium/state_trackers/vega/api_text.c @@ -0,0 +1,208 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "VG/openvg.h" + +#include "vg_context.h" +#include "text.h" +#include "api.h" + +#include "util/u_memory.h" + +#ifdef OPENVG_VERSION_1_1 + +VGFont vegaCreateFont(VGint glyphCapacityHint) +{ + struct vg_context *ctx = vg_current_context(); + + if (glyphCapacityHint < 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return VG_INVALID_HANDLE; + } + + return (VGFont) font_create(glyphCapacityHint); +} + +void vegaDestroyFont(VGFont f) +{ + struct vg_font *font = (struct vg_font *)f; + struct vg_context *ctx = vg_current_context(); + + if (f == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (!vg_object_is_valid((void *) font, VG_OBJECT_FONT)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + font_destroy(font); +} + +void vegaSetGlyphToPath(VGFont font, + VGuint glyphIndex, + VGPath path, + VGboolean isHinted, + const VGfloat glyphOrigin[2], + const VGfloat escapement[2]) +{ + struct vg_context *ctx = vg_current_context(); + struct path *pathObj; + struct vg_font *f; + + if (font == VG_INVALID_HANDLE || + !vg_context_is_object_valid(ctx, VG_OBJECT_FONT, (void *)font)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (!glyphOrigin || !escapement || + !is_aligned(glyphOrigin) || !is_aligned(escapement)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if (path != VG_INVALID_HANDLE && + !vg_context_is_object_valid(ctx, VG_OBJECT_PATH, (void *)path)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + pathObj = (struct path*) path; + f = (struct vg_font*) font; + + font_set_glyph_to_path(f, glyphIndex, pathObj, + isHinted, glyphOrigin, escapement); +} + +void vegaSetGlyphToImage(VGFont font, + VGuint glyphIndex, + VGImage image, + const VGfloat glyphOrigin[2], + const VGfloat escapement[2]) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_image *img_obj; + struct vg_font *f; + + if (font == VG_INVALID_HANDLE || + !vg_context_is_object_valid(ctx, VG_OBJECT_FONT, (void *)font)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (!glyphOrigin || !escapement || + !is_aligned(glyphOrigin) || !is_aligned(escapement)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if (image != VG_INVALID_HANDLE && + !vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, (void *)image)) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + img_obj = (struct vg_image*)image; + f = (struct vg_font*)font; + + font_set_glyph_to_image(f, glyphIndex, img_obj, glyphOrigin, escapement); +} + +void vegaClearGlyph(VGFont font, + VGuint glyphIndex) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_font *f; + + if (font == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + + f = (struct vg_font*) font; + + font_clear_glyph(f, glyphIndex); +} + +void vegaDrawGlyph(VGFont font, + VGuint glyphIndex, + VGbitfield paintModes, + VGboolean allowAutoHinting) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_font *f; + + if (font == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (paintModes & (~(VG_STROKE_PATH|VG_FILL_PATH))) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + f = (struct vg_font*)font; + + font_draw_glyph(f, glyphIndex, paintModes, allowAutoHinting); +} + +void vegaDrawGlyphs(VGFont font, + VGint glyphCount, + const VGuint *glyphIndices, + const VGfloat *adjustments_x, + const VGfloat *adjustments_y, + VGbitfield paintModes, + VGboolean allowAutoHinting) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_font *f; + + if (font == VG_INVALID_HANDLE) { + vg_set_error(ctx, VG_BAD_HANDLE_ERROR); + return; + } + if (glyphCount <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if (!glyphIndices || !is_aligned(glyphIndices)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if ((adjustments_x && !is_aligned(adjustments_x)) || + (adjustments_y && !is_aligned(adjustments_y))) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + if (paintModes & (~(VG_STROKE_PATH|VG_FILL_PATH))) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + f = (struct vg_font*)font; + + font_draw_glyphs(f, glyphCount, glyphIndices, + adjustments_x, adjustments_y, paintModes, allowAutoHinting); +} + +#endif /* OPENVG_VERSION_1_1 */ diff --git a/src/gallium/state_trackers/vega/api_transform.c b/src/gallium/state_trackers/vega/api_transform.c new file mode 100644 index 0000000..0a40fc6 --- /dev/null +++ b/src/gallium/state_trackers/vega/api_transform.c @@ -0,0 +1,129 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "VG/openvg.h" + +#include "vg_context.h" + +#include "matrix.h" +#include "api.h" + +void vegaLoadIdentity(void) +{ + struct vg_context *ctx = vg_current_context(); + struct matrix *mat = vg_state_matrix(&ctx->state.vg); + matrix_load_identity(mat); +} + +void vegaLoadMatrix(const VGfloat * m) +{ + struct vg_context *ctx = vg_current_context(); + struct matrix *mat; + + if (!ctx) + return; + + if (!m || !is_aligned(m)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + mat = vg_state_matrix(&ctx->state.vg); + matrix_init(mat, m); + if (!matrix_is_affine(mat)) { + if (ctx->state.vg.matrix_mode != VG_MATRIX_IMAGE_USER_TO_SURFACE) { + matrix_make_affine(mat); + } + } +} + +void vegaGetMatrix(VGfloat * m) +{ + struct vg_context *ctx = vg_current_context(); + struct matrix *mat; + + if (!ctx) + return; + + if (!m || !is_aligned(m)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + mat = vg_state_matrix(&ctx->state.vg); + memcpy(m, mat->m, sizeof(VGfloat)*9); +} + +void vegaMultMatrix(const VGfloat * m) +{ + struct vg_context *ctx = vg_current_context(); + struct matrix *dst, src; + + if (!ctx) + return; + + if (!m || !is_aligned(m)) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + matrix_init(&src, m); + dst = vg_state_matrix(&ctx->state.vg); + if (!matrix_is_affine(&src)) { + if (ctx->state.vg.matrix_mode != VG_MATRIX_IMAGE_USER_TO_SURFACE) { + matrix_make_affine(&src); + } + } + matrix_mult(dst, &src); + +} + +void vegaTranslate(VGfloat tx, VGfloat ty) +{ + struct vg_context *ctx = vg_current_context(); + struct matrix *dst = vg_state_matrix(&ctx->state.vg); + matrix_translate(dst, tx, ty); +} + +void vegaScale(VGfloat sx, VGfloat sy) +{ + struct vg_context *ctx = vg_current_context(); + struct matrix *dst = vg_state_matrix(&ctx->state.vg); + matrix_scale(dst, sx, sy); +} + +void vegaShear(VGfloat shx, VGfloat shy) +{ + struct vg_context *ctx = vg_current_context(); + struct matrix *dst = vg_state_matrix(&ctx->state.vg); + matrix_shear(dst, shx, shy); +} + +void vegaRotate(VGfloat angle) +{ + struct vg_context *ctx = vg_current_context(); + struct matrix *dst = vg_state_matrix(&ctx->state.vg); + matrix_rotate(dst, angle); +} diff --git a/src/gallium/state_trackers/vega/arc.c b/src/gallium/state_trackers/vega/arc.c new file mode 100644 index 0000000..65a985f --- /dev/null +++ b/src/gallium/state_trackers/vega/arc.c @@ -0,0 +1,709 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "arc.h" + +#include "matrix.h" +#include "bezier.h" +#include "polygon.h" +#include "stroker.h" +#include "path.h" + +#include "util/u_debug.h" +#include "util/u_math.h" + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#define DEBUG_ARCS 0 + +static const VGfloat two_pi = M_PI * 2; + + +static const double coeffs3Low[2][4][4] = { + { + { 3.85268, -21.229, -0.330434, 0.0127842 }, + { -1.61486, 0.706564, 0.225945, 0.263682 }, + { -0.910164, 0.388383, 0.00551445, 0.00671814 }, + { -0.630184, 0.192402, 0.0098871, 0.0102527 } + }, + { + { -0.162211, 9.94329, 0.13723, 0.0124084 }, + { -0.253135, 0.00187735, 0.0230286, 0.01264 }, + { -0.0695069, -0.0437594, 0.0120636, 0.0163087 }, + { -0.0328856, -0.00926032, -0.00173573, 0.00527385 } + } +}; + +/* coefficients for error estimation + while using cubic Bézier curves for approximation + 1/4 <= b/a <= 1 */ +static const double coeffs3High[2][4][4] = { + { + { 0.0899116, -19.2349, -4.11711, 0.183362 }, + { 0.138148, -1.45804, 1.32044, 1.38474 }, + { 0.230903, -0.450262, 0.219963, 0.414038 }, + { 0.0590565, -0.101062, 0.0430592, 0.0204699 } + }, + { + { 0.0164649, 9.89394, 0.0919496, 0.00760802 }, + { 0.0191603, -0.0322058, 0.0134667, -0.0825018 }, + { 0.0156192, -0.017535, 0.00326508, -0.228157 }, + { -0.0236752, 0.0405821, -0.0173086, 0.176187 } + } +}; + +/* safety factor to convert the "best" error approximation + into a "max bound" error */ +static const double safety3[] = { + 0.001, 4.98, 0.207, 0.0067 +}; + +/* The code below is from the OpenVG 1.1 Spec + * Section 18.4 */ + +/* Given: Points (x0, y0) and (x1, y1) + * Return: TRUE if a solution exists, FALSE otherwise + * Circle centers are written to (cx0, cy0) and (cx1, cy1) + */ +static VGboolean +find_unit_circles(double x0, double y0, double x1, double y1, + double *cx0, double *cy0, + double *cx1, double *cy1) +{ + /* Compute differences and averages */ + double dx = x0 - x1; + double dy = y0 - y1; + double xm = (x0 + x1)/2; + double ym = (y0 + y1)/2; + double dsq, disc, s, sdx, sdy; + + /* Solve for intersecting unit circles */ + dsq = dx*dx + dy*dy; + if (dsq == 0.0) return VG_FALSE; /* Points are coincident */ + disc = 1.0/dsq - 1.0/4.0; + + /* the precision we care about here is around float so if we're + * around the float defined zero then make it official to avoid + * precision problems later on */ + if (floatIsZero(disc)) + disc = 0.0; + + if (disc < 0.0) return VG_FALSE; /* Points are too far apart */ + s = sqrt(disc); + sdx = s*dx; + sdy = s*dy; + *cx0 = xm + sdy; + *cy0 = ym - sdx; + *cx1 = xm - sdy; + *cy1 = ym + sdx; + return VG_TRUE; +} + + +/* Given: Ellipse parameters rh, rv, rot (in degrees), + * endpoints (x0, y0) and (x1, y1) + * Return: TRUE if a solution exists, FALSE otherwise + * Ellipse centers are written to (cx0, cy0) and (cx1, cy1) + */ +static VGboolean +find_ellipses(double rh, double rv, double rot, + double x0, double y0, double x1, double y1, + double *cx0, double *cy0, double *cx1, double *cy1) +{ + double COS, SIN, x0p, y0p, x1p, y1p, pcx0, pcy0, pcx1, pcy1; + /* Convert rotation angle from degrees to radians */ + rot *= M_PI/180.0; + /* Pre-compute rotation matrix entries */ + COS = cos(rot); SIN = sin(rot); + /* Transform (x0, y0) and (x1, y1) into unit space */ + /* using (inverse) rotate, followed by (inverse) scale */ + x0p = (x0*COS + y0*SIN)/rh; + y0p = (-x0*SIN + y0*COS)/rv; + x1p = (x1*COS + y1*SIN)/rh; + y1p = (-x1*SIN + y1*COS)/rv; + if (!find_unit_circles(x0p, y0p, x1p, y1p, + &pcx0, &pcy0, &pcx1, &pcy1)) { + return VG_FALSE; + } + /* Transform back to original coordinate space */ + /* using (forward) scale followed by (forward) rotate */ + pcx0 *= rh; pcy0 *= rv; + pcx1 *= rh; pcy1 *= rv; + *cx0 = pcx0*COS - pcy0*SIN; + *cy0 = pcx0*SIN + pcy0*COS; + *cx1 = pcx1*COS - pcy1*SIN; + *cy1 = pcx1*SIN + pcy1*COS; + return VG_TRUE; +} + +static INLINE VGboolean +try_to_fix_radii(struct arc *arc) +{ + double COS, SIN, rot, x0p, y0p, x1p, y1p; + double dx, dy, dsq, scale; + + /* Convert rotation angle from degrees to radians */ + rot = DEGREES_TO_RADIANS(arc->theta); + + /* Pre-compute rotation matrix entries */ + COS = cos(rot); SIN = sin(rot); + + /* Transform (x0, y0) and (x1, y1) into unit space */ + /* using (inverse) rotate, followed by (inverse) scale */ + x0p = (arc->x1*COS + arc->y1*SIN)/arc->a; + y0p = (-arc->x1*SIN + arc->y1*COS)/arc->b; + x1p = (arc->x2*COS + arc->y2*SIN)/arc->a; + y1p = (-arc->x2*SIN + arc->y2*COS)/arc->b; + /* Compute differences and averages */ + dx = x0p - x1p; + dy = y0p - y1p; + + dsq = dx*dx + dy*dy; +#if 0 + if (dsq <= 0.001) { + debug_printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaa\n"); + } +#endif + scale = 1/(2/sqrt(dsq)); + arc->a *= scale; + arc->b *= scale; + return VG_TRUE; +} + +static INLINE double vector_normalize(double *v) +{ + double sq = v[0] * v[0] + v[1] * v[1]; + return sqrt(sq); +} +static INLINE double vector_orientation(double *v) +{ + double norm = vector_normalize(v); + double cosa = v[0] / norm; + double sina = v[1] / norm; + return (sina>=0 ? acos(cosa) : 2*M_PI - acos(cosa)); +} +static INLINE double vector_dot(double *v0, + double *v1) +{ + return v0[0] * v1[0] + v0[1] * v1[1]; +} + +static INLINE double vector_angles(double *v0, + double *v1) +{ + double dot = vector_dot(v0, v1); + double norm0 = vector_normalize(v0); + double norm1 = vector_normalize(v1); + + return acos(dot / (norm0 * norm1)); +} + +static VGboolean find_angles(struct arc *arc) +{ + double vec0[2], vec1[2]; + double lambda1, lambda2; + double angle; + struct matrix matrix; + + if (floatIsZero(arc->a) || floatIsZero(arc->b)) { + return VG_FALSE; + } + /* map the points to an identity circle */ + matrix_load_identity(&matrix); + matrix_scale(&matrix, 1.f, arc->a/arc->b); + matrix_rotate(&matrix, -arc->theta); + matrix_map_point(&matrix, + arc->x1, arc->y1, + &arc->x1, &arc->y1); + matrix_map_point(&matrix, + arc->x2, arc->y2, + &arc->x2, &arc->y2); + matrix_map_point(&matrix, + arc->cx, arc->cy, + &arc->cx, &arc->cy); + +#if DEBUG_ARCS + debug_printf("Matrix 3 [%f, %f, %f| %f, %f, %f| %f, %f, %f]\n", + matrix.m[0], matrix.m[1], matrix.m[2], + matrix.m[3], matrix.m[4], matrix.m[5], + matrix.m[6], matrix.m[7], matrix.m[8]); + debug_printf("Endpoints [%f, %f], [%f, %f]\n", + arc->x1, arc->y1, arc->x2, arc->y2); +#endif + + vec0[0] = arc->x1 - arc->cx; + vec0[1] = arc->y1 - arc->cy; + vec1[0] = arc->x2 - arc->cx; + vec1[1] = arc->y2 - arc->cy; + +#if DEBUG_ARCS + debug_printf("Vec is [%f, %f], [%f, %f], [%f, %f]\n", + vec0[0], vec0[1], vec1[0], vec1[1], arc->cx, arc->cy); +#endif + + lambda1 = vector_orientation(vec0); + + if (isnan(lambda1)) + lambda1 = 0.f; + + if (arc->type == VG_SCWARC_TO || + arc->type == VG_SCCWARC_TO) + angle = vector_angles(vec0, vec1); + else if (arc->type == VG_LCWARC_TO || + arc->type == VG_LCCWARC_TO) { + angle = 2*M_PI - vector_angles(vec0, vec1); + } else + abort(); + + if (isnan(angle)) + angle = M_PI; + + + if (arc->type == VG_SCWARC_TO || + arc->type == VG_LCWARC_TO) + lambda2 = lambda1 - angle; + else + lambda2 = lambda1 + angle; + +#if DEBUG_ARCS + debug_printf("Angle is %f and (%f, %f)\n", angle, lambda1, lambda2); +#endif + +#if 0 + arc->eta1 = atan2(sin(lambda1) / arc->b, + cos(lambda1) / arc->a); + arc->eta2 = atan2(sin(lambda2) / arc->b, + cos(lambda2) / arc->a); + + /* make sure we have eta1 <= eta2 <= eta1 + 2 PI */ + arc->eta2 -= two_pi * floor((arc->eta2 - arc->eta1) / two_pi); + + /* the preceding correction fails if we have exactly et2 - eta1 = 2 PI + it reduces the interval to zero length */ + if ((lambda2 - lambda1 > M_PI) && (arc->eta2 - arc->eta1 < M_PI)) { + arc->eta2 += 2 * M_PI; + } +#else + arc->eta1 = lambda1; + arc->eta2 = lambda2; +#endif + + return VG_TRUE; +} + +#if DEBUG_ARCS +static void check_endpoints(struct arc *arc) +{ + double x1, y1, x2, y2; + + double a_cos_eta1 = arc->a * cos(arc->eta1); + double b_sin_eta1 = arc->b * sin(arc->eta1); + x1 = arc->cx + a_cos_eta1 * arc->cos_theta - + b_sin_eta1 * arc->sin_theta; + y1 = arc->cy + a_cos_eta1 * arc->sin_theta + + b_sin_eta1 * arc->cos_theta; + + double a_cos_eta2 = arc->a * cos(arc->eta2); + double b_sin_eta2 = arc->b * sin(arc->eta2); + x2 = arc->cx + a_cos_eta2 * arc->cos_theta - + b_sin_eta2 * arc->sin_theta; + y2 = arc->cy + a_cos_eta2 * arc->sin_theta + + b_sin_eta2 * arc->cos_theta; + + debug_printf("Computed (%f, %f), (%f, %f)\n", + x1, y1, x2, y2); + debug_printf("Real (%f, %f), (%f, %f)\n", + arc->x1, arc->y1, + arc->x2, arc->y2); +} +#endif + +void arc_init(struct arc *arc, + VGPathSegment type, + VGfloat x1, VGfloat y1, + VGfloat x2, VGfloat y2, + VGfloat rh, VGfloat rv, + VGfloat rot) +{ + assert(type == VG_SCCWARC_TO || + type == VG_SCWARC_TO || + type == VG_LCCWARC_TO || + type == VG_LCWARC_TO); + arc->type = type; + arc->x1 = x1; + arc->y1 = y1; + arc->x2 = x2; + arc->y2 = y2; + arc->a = rh; + arc->b = rv; + arc->theta = rot; + arc->cos_theta = cos(arc->theta); + arc->sin_theta = sin(arc->theta); + { + double cx0, cy0, cx1, cy1; + double cx, cy; + arc->is_valid = find_ellipses(rh, rv, rot, x1, y1, x2, y2, + &cx0, &cy0, &cx1, &cy1); + + if (!arc->is_valid && try_to_fix_radii(arc)) { + rh = arc->a; + rv = arc->b; + arc->is_valid = + find_ellipses(rh, rv, rot, x1, y1, x2, y2, + &cx0, &cy0, &cx1, &cy1); + } + + if (type == VG_SCWARC_TO || + type == VG_LCCWARC_TO) { + cx = cx1; + cy = cy1; + } else { + cx = cx0; + cy = cy0; + } +#if DEBUG_ARCS + debug_printf("Centers are : (%f, %f) , (%f, %f). Real (%f, %f)\n", + cx0, cy0, cx1, cy1, cx, cy); +#endif + arc->cx = cx; + arc->cy = cy; + if (arc->is_valid) { + arc->is_valid = find_angles(arc); +#if DEBUG_ARCS + check_endpoints(arc); +#endif + /* remap a few points. find_angles requires + * rot in angles, the rest of the code + * will need them in radians. and find_angles + * modifies the center to match an identity + * circle so lets reset it */ + arc->theta = DEGREES_TO_RADIANS(rot); + arc->cos_theta = cos(arc->theta); + arc->sin_theta = sin(arc->theta); + arc->cx = cx; + arc->cy = cy; + } + } +} + +static INLINE double rational_function(double x, const double *c) +{ + return (x * (x * c[0] + c[1]) + c[2]) / (x + c[3]); +} + +static double estimate_error(struct arc *arc, + double etaA, double etaB) +{ + double eta = 0.5 * (etaA + etaB); + + double x = arc->b / arc->a; + double dEta = etaB - etaA; + double cos2 = cos(2 * eta); + double cos4 = cos(4 * eta); + double cos6 = cos(6 * eta); + double c0, c1; + + /* select the right coeficients set according to degree and b/a */ + const double (*coeffs)[4][4]; + const double *safety; + coeffs = (x < 0.25) ? coeffs3Low : coeffs3High; + safety = safety3; + + c0 = rational_function(x, coeffs[0][0]) + + cos2 * rational_function(x, coeffs[0][1]) + + cos4 * rational_function(x, coeffs[0][2]) + + cos6 * rational_function(x, coeffs[0][3]); + + c1 = rational_function(x, coeffs[1][0]) + + cos2 * rational_function(x, coeffs[1][1]) + + cos4 * rational_function(x, coeffs[1][2]) + + cos6 * rational_function(x, coeffs[1][3]); + + return rational_function(x, safety) * arc->a * exp(c0 + c1 * dEta); +} + +struct arc_cb { + void (*move)(struct arc_cb *cb, VGfloat x, VGfloat y); + void (*point)(struct arc_cb *cb, VGfloat x, VGfloat y); + void (*bezier)(struct arc_cb *cb, struct bezier *bezier); + + void *user_data; +}; + +static void cb_null_move(struct arc_cb *cb, VGfloat x, VGfloat y) +{ +} + +static void polygon_point(struct arc_cb *cb, VGfloat x, VGfloat y) +{ + struct polygon *poly = (struct polygon*)cb->user_data; + polygon_vertex_append(poly, x, y); +} + +static void polygon_bezier(struct arc_cb *cb, struct bezier *bezier) +{ + struct polygon *poly = (struct polygon*)cb->user_data; + bezier_add_to_polygon(bezier, poly); +} + +static void stroke_point(struct arc_cb *cb, VGfloat x, VGfloat y) +{ + struct stroker *stroker = (struct stroker*)cb->user_data; + stroker_line_to(stroker, x, y); +} + +static void stroke_curve(struct arc_cb *cb, struct bezier *bezier) +{ + struct stroker *stroker = (struct stroker*)cb->user_data; + stroker_curve_to(stroker, + bezier->x2, bezier->y2, + bezier->x3, bezier->y3, + bezier->x4, bezier->y4); +} + +static void stroke_emit_point(struct arc_cb *cb, VGfloat x, VGfloat y) +{ + struct stroker *stroker = (struct stroker*)cb->user_data; + stroker_emit_line_to(stroker, x, y); +} + +static void stroke_emit_curve(struct arc_cb *cb, struct bezier *bezier) +{ + struct stroker *stroker = (struct stroker*)cb->user_data; + stroker_emit_curve_to(stroker, + bezier->x2, bezier->y2, + bezier->x3, bezier->y3, + bezier->x4, bezier->y4); +} + +static void arc_path_move(struct arc_cb *cb, VGfloat x, VGfloat y) +{ + struct path *path = (struct path*)cb->user_data; + path_move_to(path, x, y); +} + +static void arc_path_point(struct arc_cb *cb, VGfloat x, VGfloat y) +{ + struct path *path = (struct path*)cb->user_data; + path_line_to(path, x, y); +} + +static void arc_path_bezier(struct arc_cb *cb, struct bezier *bezier) +{ + struct path *path = (struct path*)cb->user_data; + path_cubic_to(path, + bezier->x2, bezier->y2, + bezier->x3, bezier->y3, + bezier->x4, bezier->y4); +} + +static INLINE int num_beziers_needed(struct arc *arc) +{ + double threshold = 0.05; + VGboolean found = VG_FALSE; + int n = 1; + double min_eta, max_eta; + + min_eta = MIN2(arc->eta1, arc->eta2); + max_eta = MAX2(arc->eta1, arc->eta2); + + while ((! found) && (n < 1024)) { + double d_eta = (max_eta - min_eta) / n; + if (d_eta <= 0.5 * M_PI) { + double eta_b = min_eta; + int i; + found = VG_TRUE; + for (i = 0; found && (i < n); ++i) { + double etaA = eta_b; + eta_b += d_eta; + found = (estimate_error(arc, etaA, eta_b) <= threshold); + } + } + n = n << 1; + } + + return n; +} + +static void arc_to_beziers(struct arc *arc, + struct arc_cb cb, + struct matrix *matrix) +{ + int i; + int n = 1; + double d_eta, eta_b, cos_eta_b, + sin_eta_b, a_cos_eta_b, b_sin_eta_b, a_sin_eta_b, + b_cos_eta_b, x_b, y_b, x_b_dot, y_b_dot, lx, ly; + double t, alpha; + + { /* always move to the start of the arc */ + VGfloat x = arc->x1; + VGfloat y = arc->y1; + matrix_map_point(matrix, x, y, &x, &y); + cb.move(&cb, x, y); + } + + if (!arc->is_valid) { + VGfloat x = arc->x2; + VGfloat y = arc->y2; + matrix_map_point(matrix, x, y, &x, &y); + cb.point(&cb, x, y); + return; + } + + /* find the number of Bézier curves needed */ + n = num_beziers_needed(arc); + + d_eta = (arc->eta2 - arc->eta1) / n; + eta_b = arc->eta1; + + cos_eta_b = cos(eta_b); + sin_eta_b = sin(eta_b); + a_cos_eta_b = arc->a * cos_eta_b; + b_sin_eta_b = arc->b * sin_eta_b; + a_sin_eta_b = arc->a * sin_eta_b; + b_cos_eta_b = arc->b * cos_eta_b; + x_b = arc->cx + a_cos_eta_b * arc->cos_theta - + b_sin_eta_b * arc->sin_theta; + y_b = arc->cy + a_cos_eta_b * arc->sin_theta + + b_sin_eta_b * arc->cos_theta; + x_b_dot = -a_sin_eta_b * arc->cos_theta - + b_cos_eta_b * arc->sin_theta; + y_b_dot = -a_sin_eta_b * arc->sin_theta + + b_cos_eta_b * arc->cos_theta; + + { + VGfloat x = x_b, y = y_b; + matrix_map_point(matrix, x, y, &x, &y); + cb.point(&cb, x, y); + } + lx = x_b; + ly = y_b; + + t = tan(0.5 * d_eta); + alpha = sin(d_eta) * (sqrt(4 + 3 * t * t) - 1) / 3; + + for (i = 0; i < n; ++i) { + struct bezier bezier; + double xA = x_b; + double yA = y_b; + double xADot = x_b_dot; + double yADot = y_b_dot; + + eta_b += d_eta; + cos_eta_b = cos(eta_b); + sin_eta_b = sin(eta_b); + a_cos_eta_b = arc->a * cos_eta_b; + b_sin_eta_b = arc->b * sin_eta_b; + a_sin_eta_b = arc->a * sin_eta_b; + b_cos_eta_b = arc->b * cos_eta_b; + x_b = arc->cx + a_cos_eta_b * arc->cos_theta - + b_sin_eta_b * arc->sin_theta; + y_b = arc->cy + a_cos_eta_b * arc->sin_theta + + b_sin_eta_b * arc->cos_theta; + x_b_dot = -a_sin_eta_b * arc->cos_theta - + b_cos_eta_b * arc->sin_theta; + y_b_dot = -a_sin_eta_b * arc->sin_theta + + b_cos_eta_b * arc->cos_theta; + + bezier_init(&bezier, + lx, ly, + (float) (xA + alpha * xADot), (float) (yA + alpha * yADot), + (float) (x_b - alpha * x_b_dot), (float) (y_b - alpha * y_b_dot), + (float) x_b, (float) y_b); +#if 0 + debug_printf("%d) Bezier (%f, %f), (%f, %f), (%f, %f), (%f, %f)\n", + i, + bezier.x1, bezier.y1, + bezier.x2, bezier.y2, + bezier.x3, bezier.y3, + bezier.x4, bezier.y4); +#endif + bezier_transform(&bezier, matrix); + cb.bezier(&cb, &bezier); + lx = x_b; + ly = y_b; + } +} + + +void arc_add_to_polygon(struct arc *arc, + struct polygon *poly, + struct matrix *matrix) +{ + struct arc_cb cb; + + cb.move = cb_null_move; + cb.point = polygon_point; + cb.bezier = polygon_bezier; + cb.user_data = poly; + + arc_to_beziers(arc, cb, matrix); +} + +void arc_stroke_cb(struct arc *arc, + struct stroker *stroke, + struct matrix *matrix) +{ + struct arc_cb cb; + + cb.move = cb_null_move; + cb.point = stroke_point; + cb.bezier = stroke_curve; + cb.user_data = stroke; + + arc_to_beziers(arc, cb, matrix); +} + +void arc_stroker_emit(struct arc *arc, + struct stroker *stroker, + struct matrix *matrix) +{ + struct arc_cb cb; + + cb.move = cb_null_move; + cb.point = stroke_emit_point; + cb.bezier = stroke_emit_curve; + cb.user_data = stroker; + + arc_to_beziers(arc, cb, matrix); +} + +void arc_to_path(struct arc *arc, + struct path *path, + struct matrix *matrix) +{ + struct arc_cb cb; + + cb.move = arc_path_move; + cb.point = arc_path_point; + cb.bezier = arc_path_bezier; + cb.user_data = path; + + arc_to_beziers(arc, cb, matrix); +} diff --git a/src/gallium/state_trackers/vega/arc.h b/src/gallium/state_trackers/vega/arc.h new file mode 100644 index 0000000..3205cd5 --- /dev/null +++ b/src/gallium/state_trackers/vega/arc.h @@ -0,0 +1,80 @@ +/************************************************************************** + * + * 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 ARC_H +#define ARC_H + +#include "VG/openvg.h" + +struct polygon; +struct matrix; +struct stroker; +struct path; + +struct arc { + VGPathSegment type; + + VGfloat cx, cy; + + VGfloat a, b; + + VGfloat theta; + VGfloat cos_theta, sin_theta; + + VGfloat eta1; + VGfloat eta2; + + VGfloat x1, y1, x2, y2; + + VGboolean is_valid; +}; + +void arc_init(struct arc *arc, + VGPathSegment type, + VGfloat x1, VGfloat y1, + VGfloat x2, VGfloat y2, + VGfloat rh, VGfloat rv, + VGfloat rot); + +void arc_add_to_polygon(struct arc *arc, + struct polygon *poly, + struct matrix *matrix); + + +void arc_to_path(struct arc *arc, + struct path *p, + struct matrix *matrix); + +void arc_stroke_cb(struct arc *arc, + struct stroker *stroke, + struct matrix *matrix); + +void arc_stroker_emit(struct arc *arc, + struct stroker *stroke, + struct matrix *matrix); + + +#endif diff --git a/src/gallium/state_trackers/vega/asm_fill.h b/src/gallium/state_trackers/vega/asm_fill.h new file mode 100644 index 0000000..77e6a14 --- /dev/null +++ b/src/gallium/state_trackers/vega/asm_fill.h @@ -0,0 +1,693 @@ +/************************************************************************** + * + * 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 ASM_FILL_H +#define ASM_FILL_H + +#include "tgsi/tgsi_ureg.h" + +typedef void (* ureg_func)( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant); + +static INLINE void +solid_fill( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + ureg_MOV(ureg, *out, constant[2]); +} + +/** + * Perform frag-coord-to-paint-coord transform. The transformation is in + * CONST[4..6]. + */ +#define PAINT_TRANSFORM \ + ureg_MOV(ureg, ureg_writemask(temp[0], TGSI_WRITEMASK_XY), in[0]); \ + ureg_MOV(ureg, \ + ureg_writemask(temp[0], TGSI_WRITEMASK_Z), \ + ureg_scalar(constant[3], TGSI_SWIZZLE_Y)); \ + ureg_DP3(ureg, temp[1], constant[4], ureg_src(temp[0])); \ + ureg_DP3(ureg, temp[2], constant[5], ureg_src(temp[0])); \ + ureg_DP3(ureg, temp[3], constant[6], ureg_src(temp[0])); \ + ureg_RCP(ureg, temp[3], ureg_src(temp[3])); \ + ureg_MUL(ureg, temp[1], ureg_src(temp[1]), ureg_src(temp[3])); \ + ureg_MUL(ureg, temp[2], ureg_src(temp[2]), ureg_src(temp[3])); \ + ureg_MOV(ureg, \ + ureg_writemask(temp[4], TGSI_WRITEMASK_X), \ + ureg_src(temp[1])); \ + ureg_MOV(ureg, \ + ureg_writemask(temp[4], TGSI_WRITEMASK_Y), \ + ureg_src(temp[2])); + +static INLINE void +linear_grad( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + PAINT_TRANSFORM + + /* grad = DP2((x, y), CONST[2].xy) * CONST[2].z */ + ureg_MUL(ureg, temp[0], + ureg_scalar(constant[2], TGSI_SWIZZLE_Y), + ureg_scalar(ureg_src(temp[4]), TGSI_SWIZZLE_Y)); + ureg_MAD(ureg, temp[1], + ureg_scalar(constant[2], TGSI_SWIZZLE_X), + ureg_scalar(ureg_src(temp[4]), TGSI_SWIZZLE_X), + ureg_src(temp[0])); + ureg_MUL(ureg, temp[2], ureg_src(temp[1]), + ureg_scalar(constant[2], TGSI_SWIZZLE_Z)); + + ureg_TEX(ureg, *out, TGSI_TEXTURE_1D, ureg_src(temp[2]), sampler[0]); +} + +static INLINE void +radial_grad( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + PAINT_TRANSFORM + + /* + * Calculate (sqrt(B^2 + AC) - B) / A, where + * + * A is CONST[2].z, + * B is DP2((x, y), CONST[2].xy), and + * C is DP2((x, y), (x, y)). + */ + + /* B and C */ + ureg_DP2(ureg, temp[0], ureg_src(temp[4]), constant[2]); + ureg_DP2(ureg, temp[1], ureg_src(temp[4]), ureg_src(temp[4])); + + /* the square root */ + ureg_MUL(ureg, temp[2], ureg_src(temp[0]), ureg_src(temp[0])); + ureg_MAD(ureg, temp[3], ureg_src(temp[1]), + ureg_scalar(constant[2], TGSI_SWIZZLE_Z), ureg_src(temp[2])); + ureg_RSQ(ureg, temp[3], ureg_src(temp[3])); + ureg_RCP(ureg, temp[3], ureg_src(temp[3])); + + ureg_SUB(ureg, temp[3], ureg_src(temp[3]), ureg_src(temp[0])); + ureg_RCP(ureg, temp[0], ureg_scalar(constant[2], TGSI_SWIZZLE_Z)); + ureg_MUL(ureg, temp[0], ureg_src(temp[0]), ureg_src(temp[3])); + + ureg_TEX(ureg, *out, TGSI_TEXTURE_1D, ureg_src(temp[0]), sampler[0]); +} + + +static INLINE void +pattern( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + PAINT_TRANSFORM + + /* (s, t) = (x / tex_width, y / tex_height) */ + ureg_RCP(ureg, temp[0], + ureg_swizzle(constant[3], + TGSI_SWIZZLE_Z, + TGSI_SWIZZLE_W, + TGSI_SWIZZLE_Z, + TGSI_SWIZZLE_W)); + ureg_MOV(ureg, temp[1], ureg_src(temp[4])); + ureg_MUL(ureg, + ureg_writemask(temp[1], TGSI_WRITEMASK_X), + ureg_src(temp[1]), + ureg_src(temp[0])); + ureg_MUL(ureg, + ureg_writemask(temp[1], TGSI_WRITEMASK_Y), + ureg_src(temp[1]), + ureg_src(temp[0])); + + ureg_TEX(ureg, *out, TGSI_TEXTURE_2D, ureg_src(temp[1]), sampler[0]); +} + +static INLINE void +paint_degenerate( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + /* CONST[3].y is 1.0f */ + ureg_MOV(ureg, temp[1], ureg_scalar(constant[3], TGSI_SWIZZLE_Y)); + ureg_TEX(ureg, *out, TGSI_TEXTURE_1D, ureg_src(temp[1]), sampler[0]); +} + +static INLINE void +image_normal( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + /* store and pass image color in TEMP[1] */ + ureg_TEX(ureg, temp[1], TGSI_TEXTURE_2D, in[1], sampler[3]); + ureg_MOV(ureg, *out, ureg_src(temp[1])); +} + + +static INLINE void +image_multiply( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + /* store and pass image color in TEMP[1] */ + ureg_TEX(ureg, temp[1], TGSI_TEXTURE_2D, in[1], sampler[3]); + ureg_MUL(ureg, *out, ureg_src(temp[0]), ureg_src(temp[1])); +} + + +static INLINE void +image_stencil( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + /* store and pass image color in TEMP[1] */ + ureg_TEX(ureg, temp[1], TGSI_TEXTURE_2D, in[1], sampler[3]); + ureg_MOV(ureg, *out, ureg_src(temp[0])); +} + +static INLINE void +color_transform( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + /* note that TEMP[1] may already be used for image color */ + + ureg_MAD(ureg, temp[2], ureg_src(temp[0]), constant[0], constant[1]); + /* clamp to [0.0f, 1.0f] */ + ureg_CLAMP(ureg, temp[2], + ureg_src(temp[2]), + ureg_scalar(constant[3], TGSI_SWIZZLE_X), + ureg_scalar(constant[3], TGSI_SWIZZLE_Y)); + ureg_MOV(ureg, *out, ureg_src(temp[2])); +} + +static INLINE void +alpha_normal( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + /* save per-channel alpha in TEMP[1] */ + ureg_MOV(ureg, temp[1], ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W)); + + ureg_MOV(ureg, *out, ureg_src(temp[0])); +} + +static INLINE void +alpha_per_channel( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + /* save per-channel alpha in TEMP[1] */ + ureg_MUL(ureg, + ureg_writemask(temp[1], TGSI_WRITEMASK_W), + ureg_src(temp[0]), + ureg_src(temp[1])); + ureg_MUL(ureg, + ureg_writemask(temp[1], TGSI_WRITEMASK_XYZ), + ureg_src(temp[1]), + ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W)); + + /* update alpha */ + ureg_MOV(ureg, + ureg_writemask(temp[0], TGSI_WRITEMASK_W), + ureg_src(temp[1])); + ureg_MOV(ureg, *out, ureg_src(temp[0])); +} + +/** + * Premultiply src and dst. + */ +static INLINE void +blend_premultiply( struct ureg_program *ureg, + struct ureg_src src, + struct ureg_src src_channel_alpha, + struct ureg_src dst) +{ + /* premultiply src */ + ureg_MUL(ureg, + ureg_writemask(ureg_dst(src), TGSI_WRITEMASK_XYZ), + src, + src_channel_alpha); + /* premultiply dst */ + ureg_MUL(ureg, + ureg_writemask(ureg_dst(dst), TGSI_WRITEMASK_XYZ), + dst, + ureg_scalar(dst, TGSI_SWIZZLE_W)); +} + +/** + * Unpremultiply src. + */ +static INLINE void +blend_unpremultiply( struct ureg_program *ureg, + struct ureg_src src, + struct ureg_src one, + struct ureg_dst temp[1]) +{ + /* replace 0.0f by 1.0f before calculating reciprocal */ + ureg_CMP(ureg, + temp[0], + ureg_negate(ureg_scalar(src, TGSI_SWIZZLE_W)), + ureg_scalar(src, TGSI_SWIZZLE_W), + one); + ureg_RCP(ureg, temp[0], ureg_src(temp[0])); + + ureg_MUL(ureg, + ureg_writemask(ureg_dst(src), TGSI_WRITEMASK_XYZ), + src, + ureg_src(temp[0])); +} + +/** + * Emit instructions for the specified blend mode. Colors will be + * unpremultiplied. Two temporary registers are required. + * + * The output is written back to src. + */ +static INLINE void +blend_generic(struct ureg_program *ureg, + VGBlendMode mode, + struct ureg_src src, + struct ureg_src src_channel_alpha, + struct ureg_src dst, + struct ureg_src one, + struct ureg_dst temp[2]) +{ + struct ureg_dst out; + + blend_premultiply(ureg, src, src_channel_alpha, dst); + + /* blend in-place */ + out = ureg_dst(src); + + switch (mode) { + case VG_BLEND_SRC: + ureg_MOV(ureg, out, src); + break; + case VG_BLEND_SRC_OVER: + /* RGBA_out = RGBA_src + (1 - A_src) * RGBA_dst */ + ureg_SUB(ureg, temp[0], one, src_channel_alpha); + ureg_MAD(ureg, out, ureg_src(temp[0]), dst, src); + break; + case VG_BLEND_DST_OVER: + /* RGBA_out = RGBA_dst + (1 - A_dst) * RGBA_src */ + ureg_SUB(ureg, temp[0], one, ureg_scalar(dst, TGSI_SWIZZLE_W)); + ureg_MAD(ureg, out, ureg_src(temp[0]), src, dst); + break; + case VG_BLEND_SRC_IN: + ureg_MUL(ureg, out, src, ureg_scalar(dst, TGSI_SWIZZLE_W)); + break; + case VG_BLEND_DST_IN: + ureg_MUL(ureg, out, dst, src_channel_alpha); + break; + case VG_BLEND_MULTIPLY: + /* + * RGB_out = (1 - A_dst) * RGB_src + (1 - A_src) * RGB_dst + + * RGB_src * RGB_dst + */ + ureg_MAD(ureg, temp[0], + ureg_scalar(dst, TGSI_SWIZZLE_W), ureg_negate(src), src); + ureg_MAD(ureg, temp[1], + src_channel_alpha, ureg_negate(dst), dst); + ureg_MAD(ureg, temp[0], src, dst, ureg_src(temp[0])); + ureg_ADD(ureg, out, ureg_src(temp[0]), ureg_src(temp[1])); + /* alpha is src over */ + ureg_ADD(ureg, ureg_writemask(out, TGSI_WRITEMASK_W), + src, ureg_src(temp[1])); + break; + case VG_BLEND_SCREEN: + /* RGBA_out = RGBA_src + (1 - RGBA_src) * RGBA_dst */ + ureg_SUB(ureg, temp[0], one, src); + ureg_MAD(ureg, out, ureg_src(temp[0]), dst, src); + break; + case VG_BLEND_DARKEN: + case VG_BLEND_LIGHTEN: + /* src over */ + ureg_SUB(ureg, temp[0], one, src_channel_alpha); + ureg_MAD(ureg, temp[0], ureg_src(temp[0]), dst, src); + /* dst over */ + ureg_SUB(ureg, temp[1], one, ureg_scalar(dst, TGSI_SWIZZLE_W)); + ureg_MAD(ureg, temp[1], ureg_src(temp[1]), src, dst); + /* take min/max for colors */ + if (mode == VG_BLEND_DARKEN) { + ureg_MIN(ureg, ureg_writemask(out, TGSI_WRITEMASK_XYZ), + ureg_src(temp[0]), ureg_src(temp[1])); + } + else { + ureg_MAX(ureg, ureg_writemask(out, TGSI_WRITEMASK_XYZ), + ureg_src(temp[0]), ureg_src(temp[1])); + } + break; + case VG_BLEND_ADDITIVE: + /* RGBA_out = RGBA_src + RGBA_dst */ + ureg_ADD(ureg, temp[0], src, dst); + ureg_MIN(ureg, out, ureg_src(temp[0]), one); + break; + default: + assert(0); + break; + } + + blend_unpremultiply(ureg, src, one, temp); +} + +#define BLEND_GENERIC(mode) \ + do { \ + ureg_TEX(ureg, temp[2], TGSI_TEXTURE_2D, in[0], sampler[2]); \ + blend_generic(ureg, (mode), ureg_src(temp[0]), ureg_src(temp[1]), \ + ureg_src(temp[2]), \ + ureg_scalar(constant[3], TGSI_SWIZZLE_Y), temp + 3); \ + ureg_MOV(ureg, *out, ureg_src(temp[0])); \ + } while (0) + +static INLINE void +blend_src( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + BLEND_GENERIC(VG_BLEND_SRC); +} + +static INLINE void +blend_src_over( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + BLEND_GENERIC(VG_BLEND_SRC_OVER); +} + +static INLINE void +blend_dst_over( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + BLEND_GENERIC(VG_BLEND_DST_OVER); +} + +static INLINE void +blend_src_in( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + BLEND_GENERIC(VG_BLEND_SRC_IN); +} + +static INLINE void +blend_dst_in( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + BLEND_GENERIC(VG_BLEND_DST_IN); +} + +static INLINE void +blend_multiply( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + BLEND_GENERIC(VG_BLEND_MULTIPLY); +} + +static INLINE void +blend_screen( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + BLEND_GENERIC(VG_BLEND_SCREEN); +} + +static INLINE void +blend_darken( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + BLEND_GENERIC(VG_BLEND_DARKEN); +} + +static INLINE void +blend_lighten( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + BLEND_GENERIC(VG_BLEND_LIGHTEN); +} + +static INLINE void +blend_additive( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + BLEND_GENERIC(VG_BLEND_ADDITIVE); +} + +static INLINE void +mask( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + ureg_TEX(ureg, temp[1], TGSI_TEXTURE_2D, in[0], sampler[1]); + ureg_MUL(ureg, ureg_writemask(temp[0], TGSI_WRITEMASK_W), + ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W), + ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W)); + ureg_MOV(ureg, *out, ureg_src(temp[0])); +} + +static INLINE void +premultiply( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + ureg_MUL(ureg, + ureg_writemask(temp[0], TGSI_WRITEMASK_XYZ), + ureg_src(temp[0]), + ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W)); +} + +static INLINE void +unpremultiply( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + ureg_TEX(ureg, temp[0], TGSI_TEXTURE_2D, in[0], sampler[1]); +} + + +static INLINE void +color_bw( struct ureg_program *ureg, + struct ureg_dst *out, + struct ureg_src *in, + struct ureg_src *sampler, + struct ureg_dst *temp, + struct ureg_src *constant) +{ + ureg_ADD(ureg, temp[1], + ureg_scalar(constant[3], TGSI_SWIZZLE_Y), + ureg_scalar(constant[3], TGSI_SWIZZLE_Y)); + ureg_RCP(ureg, temp[2], ureg_src(temp[1])); + ureg_ADD(ureg, temp[1], + ureg_scalar(constant[3], TGSI_SWIZZLE_Y), + ureg_src(temp[2])); + ureg_ADD(ureg, ureg_writemask(temp[2], TGSI_WRITEMASK_X), + ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_X), + ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_Y)); + ureg_ADD(ureg, ureg_writemask(temp[2], TGSI_WRITEMASK_X), + ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_Z), + ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_X)); + ureg_SGE(ureg, + ureg_writemask(temp[0], TGSI_WRITEMASK_XYZ), + ureg_scalar(ureg_src(temp[2]), TGSI_SWIZZLE_X), + ureg_src(temp[1])); + ureg_SGE(ureg, + ureg_writemask(temp[0], TGSI_WRITEMASK_W), + ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W), + ureg_scalar(ureg_src(temp[2]), TGSI_SWIZZLE_Y)); + ureg_MOV(ureg, *out, ureg_src(temp[0])); +} + + +struct shader_asm_info { + VGint id; + ureg_func func; + + VGboolean needs_position; + + VGint start_const; + VGint num_consts; + + VGint start_sampler; + VGint num_samplers; + + VGint start_temp; + VGint num_temps; +}; + + +/* paint types */ +static const struct shader_asm_info shaders_paint_asm[] = { + {VEGA_SOLID_FILL_SHADER, solid_fill, + VG_FALSE, 2, 1, 0, 0, 0, 0}, + {VEGA_LINEAR_GRADIENT_SHADER, linear_grad, + VG_TRUE, 2, 5, 0, 1, 0, 5}, + {VEGA_RADIAL_GRADIENT_SHADER, radial_grad, + VG_TRUE, 2, 5, 0, 1, 0, 5}, + {VEGA_PATTERN_SHADER, pattern, + VG_TRUE, 3, 4, 0, 1, 0, 5}, + {VEGA_PAINT_DEGENERATE_SHADER, paint_degenerate, + VG_FALSE, 3, 1, 0, 1, 0, 2} +}; + +/* image draw modes */ +static const struct shader_asm_info shaders_image_asm[] = { + {VEGA_IMAGE_NORMAL_SHADER, image_normal, + VG_TRUE, 0, 0, 3, 1, 0, 2}, + {VEGA_IMAGE_MULTIPLY_SHADER, image_multiply, + VG_TRUE, 0, 0, 3, 1, 0, 2}, + {VEGA_IMAGE_STENCIL_SHADER, image_stencil, + VG_TRUE, 0, 0, 3, 1, 0, 2} +}; + +static const struct shader_asm_info shaders_color_transform_asm[] = { + {VEGA_COLOR_TRANSFORM_SHADER, color_transform, + VG_FALSE, 0, 4, 0, 0, 0, 3} +}; + +static const struct shader_asm_info shaders_alpha_asm[] = { + {VEGA_ALPHA_NORMAL_SHADER, alpha_normal, + VG_FALSE, 0, 0, 0, 0, 0, 2}, + {VEGA_ALPHA_PER_CHANNEL_SHADER, alpha_per_channel, + VG_FALSE, 0, 0, 0, 0, 0, 2} +}; + +/* extra blend modes */ +static const struct shader_asm_info shaders_blend_asm[] = { +#define BLEND_ASM_INFO(id, func) { (id), (func), VG_TRUE, 3, 1, 2, 1, 0, 5 } + BLEND_ASM_INFO(VEGA_BLEND_SRC_SHADER, blend_src), + BLEND_ASM_INFO(VEGA_BLEND_SRC_OVER_SHADER, blend_src_over), + BLEND_ASM_INFO(VEGA_BLEND_DST_OVER_SHADER, blend_dst_over), + BLEND_ASM_INFO(VEGA_BLEND_SRC_IN_SHADER, blend_src_in), + BLEND_ASM_INFO(VEGA_BLEND_DST_IN_SHADER, blend_dst_in), + BLEND_ASM_INFO(VEGA_BLEND_MULTIPLY_SHADER, blend_multiply), + BLEND_ASM_INFO(VEGA_BLEND_SCREEN_SHADER, blend_screen), + BLEND_ASM_INFO(VEGA_BLEND_DARKEN_SHADER, blend_darken), + BLEND_ASM_INFO(VEGA_BLEND_LIGHTEN_SHADER, blend_lighten), + BLEND_ASM_INFO(VEGA_BLEND_ADDITIVE_SHADER, blend_additive) +#undef BLEND_ASM_INFO +}; + +static const struct shader_asm_info shaders_mask_asm[] = { + {VEGA_MASK_SHADER, mask, + VG_TRUE, 0, 0, 1, 1, 0, 2} +}; + +/* premultiply */ +static const struct shader_asm_info shaders_premultiply_asm[] = { + {VEGA_PREMULTIPLY_SHADER, premultiply, + VG_FALSE, 0, 0, 0, 0, 0, 1}, + {VEGA_UNPREMULTIPLY_SHADER, unpremultiply, + VG_FALSE, 0, 0, 0, 0, 0, 1}, +}; + +/* color transform to black and white */ +static const struct shader_asm_info shaders_bw_asm[] = { + {VEGA_BW_SHADER, color_bw, + VG_FALSE, 3, 1, 0, 0, 0, 3}, +}; + +#endif diff --git a/src/gallium/state_trackers/vega/asm_filters.h b/src/gallium/state_trackers/vega/asm_filters.h new file mode 100644 index 0000000..60bed19 --- /dev/null +++ b/src/gallium/state_trackers/vega/asm_filters.h @@ -0,0 +1,117 @@ +/************************************************************************** + * + * 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 ASM_FILTERS_H +#define ASM_FILTERS_H + +static const char color_matrix_asm[] = + "FRAG\n" + "DCL IN[0], GENERIC[0], PERSPECTIVE\n" + "DCL OUT[0], COLOR, CONSTANT\n" + "DCL CONST[0..4], CONSTANT\n" + "DCL TEMP[0..4], CONSTANT\n" + "DCL SAMP[0], CONSTANT\n" + "TEX TEMP[0], IN[0], SAMP[0], 2D\n" + "MOV TEMP[1], TEMP[0].xxxx\n" + "MOV TEMP[2], TEMP[0].yyyy\n" + "MOV TEMP[3], TEMP[0].zzzz\n" + "MOV TEMP[4], TEMP[0].wwww\n" + "MUL TEMP[1], TEMP[1], CONST[0]\n" + "MUL TEMP[2], TEMP[2], CONST[1]\n" + "MUL TEMP[3], TEMP[3], CONST[2]\n" + "MUL TEMP[4], TEMP[4], CONST[3]\n" + "ADD TEMP[0], TEMP[1], CONST[4]\n" + "ADD TEMP[0], TEMP[0], TEMP[2]\n" + "ADD TEMP[0], TEMP[0], TEMP[3]\n" + "ADD TEMP[0], TEMP[0], TEMP[4]\n" + "MOV OUT[0], TEMP[0]\n" + "END\n"; + +static const char convolution_asm[] = + "FRAG\n" + "DCL IN[0], GENERIC[0], PERSPECTIVE\n" + "DCL OUT[0], COLOR, CONSTANT\n" + "DCL TEMP[0..4], CONSTANT\n" + "DCL ADDR[0], CONSTANT\n" + "DCL CONST[0..%d], CONSTANT\n" + "DCL SAMP[0], CONSTANT\n" + "0: MOV TEMP[0], CONST[0].xxxx\n" + "1: MOV TEMP[1], CONST[0].xxxx\n" + "2: BGNLOOP :14\n" + "3: SGE TEMP[0].z, TEMP[0].yyyy, CONST[1].xxxx\n" + "4: IF TEMP[0].zzzz :7\n" + "5: BRK\n" + "6: ENDIF\n" + "7: ARL ADDR[0].x, TEMP[0].yyyy\n" + "8: MOV TEMP[3], CONST[ADDR[0]+2]\n" + "9: ADD TEMP[4].xy, IN[0], TEMP[3]\n" + "10: TEX TEMP[2], TEMP[4], SAMP[0], 2D\n" + "11: MOV TEMP[3], CONST[ADDR[0]+%d]\n" + "12: MAD TEMP[1], TEMP[2], TEMP[3], TEMP[1]\n" + "13: ADD TEMP[0].y, TEMP[0].yyyy, CONST[0].yyyy\n" + "14: ENDLOOP :2\n" + "15: MAD OUT[0], TEMP[1], CONST[1].yyyy, CONST[1].zzzz\n" + "16: END\n"; + + +static const char lookup_asm[] = + "FRAG\n" + "DCL IN[0], GENERIC[0], PERSPECTIVE\n" + "DCL OUT[0], COLOR, CONSTANT\n" + "DCL TEMP[0..2], CONSTANT\n" + "DCL CONST[0], CONSTANT\n" + "DCL SAMP[0..1], CONSTANT\n" + "TEX TEMP[0], IN[0], SAMP[0], 2D\n" + "MOV TEMP[1], TEMP[0]\n" + /* do red */ + "TEX TEMP[2], TEMP[1].xxxx, SAMP[1], 1D\n" + "MOV TEMP[0].x, TEMP[2].xxxx\n" + /* do blue */ + "TEX TEMP[2], TEMP[1].yyyy, SAMP[1], 1D\n" + "MOV TEMP[0].y, TEMP[2].yyyy\n" + /* do green */ + "TEX TEMP[2], TEMP[1].zzzz, SAMP[1], 1D\n" + "MOV TEMP[0].z, TEMP[2].zzzz\n" + /* do alpha */ + "TEX TEMP[2], TEMP[1].wwww, SAMP[1], 1D\n" + "MOV TEMP[0].w, TEMP[2].wwww\n" + "MOV OUT[0], TEMP[0]\n" + "END\n"; + + +static const char lookup_single_asm[] = + "FRAG\n" + "DCL IN[0], GENERIC[0], PERSPECTIVE\n" + "DCL OUT[0], COLOR, CONSTANT\n" + "DCL TEMP[0..2], CONSTANT\n" + "DCL CONST[0], CONSTANT\n" + "DCL SAMP[0..1], CONSTANT\n" + "TEX TEMP[0], IN[0], SAMP[0], 2D\n" + "TEX TEMP[1], TEMP[0].%s, SAMP[1], 1D\n" + "MOV OUT[0], TEMP[1]\n" + "END\n"; + +#endif diff --git a/src/gallium/state_trackers/vega/asm_util.h b/src/gallium/state_trackers/vega/asm_util.h new file mode 100644 index 0000000..ae1842a --- /dev/null +++ b/src/gallium/state_trackers/vega/asm_util.h @@ -0,0 +1,85 @@ +/************************************************************************** + * + * 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 ASM_UTIL_H +#define ASM_UTIL_H + +/* μnew = μmask */ +static const char set_mask_asm[] = + "FRAG\n" + "DCL IN[0], GENERIC[0], PERSPECTIVE\n" + "DCL SAMP[0], CONSTANT\n" + "DCL OUT[0], COLOR, CONSTANT\n" + "0: TEX OUT[0], IN[0], SAMP[0], 2D\n"/*umask*/ + "1: END\n"; + +/* μnew = 1 – (1 – μmask)*(1 – μprev) */ +static const char union_mask_asm[] = + "FRAG\n" + "DCL IN[0], GENERIC[0], PERSPECTIVE\n" + "DCL IN[1], POSITION, LINEAR\n" + "DCL CONST[0], CONSTANT\n" + "DCL SAMP[0..1], CONSTANT\n" + "DCL TEMP[0..3], CONSTANT\n" + "DCL OUT[0], COLOR, CONSTANT\n" + "0: TEX TEMP[1], IN[0], SAMP[0], 2D\n"/*umask*/ + "1: TEX TEMP[0], IN[1], SAMP[1], 2D\n"/*uprev*/ + "2: SUB TEMP[2], CONST[0], TEMP[0]\n" + "3: SUB TEMP[3], CONST[0], TEMP[1]\n" + "4: MUL TEMP[0].w, TEMP[2].wwww, TEMP[3].wwww\n" + "5: SUB OUT[0], CONST[0], TEMP[0]\n" + "6: END\n"; + +/* μnew = μmask *μprev */ +static const char intersect_mask_asm[] = + "FRAG\n" + "DCL IN[0], GENERIC[0], PERSPECTIVE\n" + "DCL IN[1], POSITION, LINEAR\n" + "DCL CONST[0], CONSTANT\n" + "DCL SAMP[0..1], CONSTANT\n" + "DCL TEMP[0..1], CONSTANT\n" + "DCL OUT[0], COLOR, CONSTANT\n" + "0: TEX TEMP[0], IN[1], SAMP[1], 2D\n"/*uprev*/ + "1: TEX TEMP[1], IN[0], SAMP[0], 2D\n"/*umask*/ + "2: MUL OUT[0], TEMP[0].wwww, TEMP[1].wwww\n" + "3: END\n"; + +/* μnew = μprev*(1 – μmask) */ +static const char subtract_mask_asm[] = + "FRAG\n" + "DCL IN[0], GENERIC[0], PERSPECTIVE\n" + "DCL IN[1], POSITION, LINEAR\n" + "DCL CONST[0], CONSTANT\n" + "DCL SAMP[0..1], CONSTANT\n" + "DCL TEMP[0..2], CONSTANT\n" + "DCL OUT[0], COLOR, CONSTANT\n" + "0: TEX TEMP[1], IN[0], SAMP[0], 2D\n"/*umask*/ + "1: TEX TEMP[0], IN[1], SAMP[1], 2D\n"/*uprev*/ + "2: SUB TEMP[2], CONST[0], TEMP[1]\n" + "3: MUL OUT[0], TEMP[2].wwww, TEMP[0].wwww\n" + "4: END\n"; + +#endif diff --git a/src/gallium/state_trackers/vega/bezier.c b/src/gallium/state_trackers/vega/bezier.c new file mode 100644 index 0000000..5769e8e --- /dev/null +++ b/src/gallium/state_trackers/vega/bezier.c @@ -0,0 +1,706 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "bezier.h" + +#include "matrix.h" +#include "polygon.h" + +#include "pipe/p_compiler.h" +#include "util/u_debug.h" + +#include +#include +#include +#include + +static const float flatness = 0.5; + + +static INLINE void split_left(struct bezier *bez, VGfloat t, struct bezier* left) +{ + left->x1 = bez->x1; + left->y1 = bez->y1; + + left->x2 = bez->x1 + t * (bez->x2 - bez->x1); + left->y2 = bez->y1 + t * (bez->y2 - bez->y1); + + left->x3 = bez->x2 + t * (bez->x3 - bez->x2); + left->y3 = bez->y2 + t * (bez->y3 - bez->y2); + + bez->x3 = bez->x3 + t * (bez->x4 - bez->x3); + bez->y3 = bez->y3 + t * (bez->y4 - bez->y3); + + bez->x2 = left->x3 + t * (bez->x3 - left->x3); + bez->y2 = left->y3 + t * (bez->y3 - left->y3); + + left->x3 = left->x2 + t * (left->x3 - left->x2); + left->y3 = left->y2 + t * (left->y3 - left->y2); + + left->x4 = bez->x1 = left->x3 + t * (bez->x2 - left->x3); + left->y4 = bez->y1 = left->y3 + t * (bez->y2 - left->y3); +} + +static INLINE void split(struct bezier *bez, + struct bezier *first_half, + struct bezier *second_half) +{ + double c = (bez->x2 + bez->x3) * 0.5; + first_half->x2 = (bez->x1 + bez->x2) * 0.5; + second_half->x3 = (bez->x3 + bez->x4) * 0.5; + first_half->x1 = bez->x1; + second_half->x4 = bez->x4; + first_half->x3 = (first_half->x2 + c) * 0.5; + second_half->x2 = (second_half->x3 + c) * 0.5; + first_half->x4 = second_half->x1 = + (first_half->x3 + second_half->x2) * 0.5; + + c = (bez->y2 + bez->y3) / 2; + first_half->y2 = (bez->y1 + bez->y2) * 0.5; + second_half->y3 = (bez->y3 + bez->y4) * 0.5; + first_half->y1 = bez->y1; + second_half->y4 = bez->y4; + first_half->y3 = (first_half->y2 + c) * 0.5; + second_half->y2 = (second_half->y3 + c) * 0.5; + first_half->y4 = second_half->y1 = + (first_half->y3 + second_half->y2) * 0.5; +} + +struct polygon * bezier_to_polygon(struct bezier *bez) +{ + struct polygon *poly = polygon_create(64); + polygon_vertex_append(poly, bez->x1, bez->y1); + bezier_add_to_polygon(bez, poly); + return poly; +} + +void bezier_add_to_polygon(const struct bezier *bez, + struct polygon *poly) +{ + struct bezier beziers[32]; + struct bezier *b; + + beziers[0] = *bez; + b = beziers; + + while (b >= beziers) { + double y4y1 = b->y4 - b->y1; + double x4x1 = b->x4 - b->x1; + double l = ABS(x4x1) + ABS(y4y1); + double d; + if (l > 1.f) { + d = ABS((x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2)) + + ABS((x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3)); + } else { + d = ABS(b->x1 - b->x2) + ABS(b->y1 - b->y2) + + ABS(b->x1 - b->x3) + ABS(b->y1 - b->y3); + l = 1.; + } + if (d < flatness*l || b == beziers + 31) { + /* good enough, we pop it off and add the endpoint */ + polygon_vertex_append(poly, b->x4, b->y4); + --b; + } else { + /* split, second half of the bezier goes lower into the stack */ + split(b, b+1, b); + ++b; + } + } +} + +static void add_if_close(struct bezier *bez, VGfloat *length, VGfloat error) +{ + struct bezier left, right; /* bez poly splits */ + VGfloat len = 0.0; /* arc length */ + VGfloat chord; /* chord length */ + + len = len + line_length(bez->x1, bez->y1, bez->x2, bez->y2); + len = len + line_length(bez->x2, bez->y2, bez->x3, bez->y3); + len = len + line_length(bez->x3, bez->y3, bez->x4, bez->y4); + + chord = line_length(bez->x1, bez->y1, bez->x4, bez->y4); + + if ((len-chord) > error) { + split(bez, &left, &right); /* split in two */ + add_if_close(&left, length, error); /* try left side */ + add_if_close(&right, length, error); /* try right side */ + return; + } + + *length = *length + len; + + return; +} + +float bezier_length(struct bezier *bez, float error) +{ + VGfloat length = 0.f; + + add_if_close(bez, &length, error); + return length; +} + +void bezier_init(struct bezier *bez, + float x1, float y1, + float x2, float y2, + float x3, float y3, + float x4, float y4) +{ + bez->x1 = x1; + bez->y1 = y1; + bez->x2 = x2; + bez->y2 = y2; + bez->x3 = x3; + bez->y3 = y3; + bez->x4 = x4; + bez->y4 = y4; +#if 0 + debug_printf("bezier in [%f, %f, %f, %f, %f, %f]\n", + x1, y1, x2, y2, x3, y3, x4, y4); +#endif +} + + +static INLINE void bezier_init2v(struct bezier *bez, + float *pt1, + float *pt2, + float *pt3, + float *pt4) +{ + bez->x1 = pt1[0]; + bez->y1 = pt1[1]; + + bez->x2 = pt2[0]; + bez->y2 = pt2[1]; + + bez->x3 = pt3[0]; + bez->y3 = pt3[1]; + + bez->x4 = pt4[0]; + bez->y4 = pt4[1]; +} + + +void bezier_transform(struct bezier *bez, + struct matrix *matrix) +{ + assert(matrix_is_affine(matrix)); + matrix_map_point(matrix, bez->x1, bez->y1, &bez->x1, &bez->y1); + matrix_map_point(matrix, bez->x2, bez->y2, &bez->x2, &bez->y2); + matrix_map_point(matrix, bez->x3, bez->y3, &bez->x3, &bez->y3); + matrix_map_point(matrix, bez->x4, bez->y4, &bez->x4, &bez->y4); +} + +static INLINE void bezier_point_at(const struct bezier *bez, float t, float *pt) +{ + float a, b, c, d; + float m_t; + m_t = 1. - t; + b = m_t * m_t; + c = t * t; + d = c * t; + a = b * m_t; + b *= 3. * t; + c *= 3. * m_t; + pt[0] = a*bez->x1 + b*bez->x2 + c*bez->x3 + d*bez->x4; + pt[1] = a*bez->y1 + b*bez->y2 + c*bez->y3 + d*bez->y4; +} + +static INLINE void bezier_normal_at(const struct bezier *bez, float t, float *norm) +{ + float m_t = 1. - t; + float a = m_t * m_t; + float b = t * m_t; + float c = t * t; + + norm[0] = (bez->y2-bez->y1) * a + (bez->y3-bez->y2) * b + (bez->y4-bez->y3) * c; + norm[1] = -(bez->x2-bez->x1) * a - (bez->x3-bez->x2) * b - (bez->x4-bez->x3) * c; +} + +enum shift_result { + Ok, + Discard, + Split, + Circle +}; + +static enum shift_result good_offset(const struct bezier *b1, + const struct bezier *b2, + float offset, float threshold) +{ + const float o2 = offset*offset; + const float max_dist_line = threshold*offset*offset; + const float max_dist_normal = threshold*offset; + const float spacing = 0.25; + float i; + for (i = spacing; i < 0.99; i += spacing) { + float p1[2],p2[2], d, l; + float normal[2]; + bezier_point_at(b1, i, p1); + bezier_point_at(b2, i, p2); + d = (p1[0] - p2[0])*(p1[0] - p2[0]) + (p1[1] - p2[1])*(p1[1] - p2[1]); + if (ABS(d - o2) > max_dist_line) + return Split; + + bezier_normal_at(b1, i, normal); + l = ABS(normal[0]) + ABS(normal[1]); + if (l != 0.) { + d = ABS(normal[0]*(p1[1] - p2[1]) - normal[1]*(p1[0] - p2[0]) ) / l; + if (d > max_dist_normal) + return Split; + } + } + return Ok; +} + +static INLINE void shift_line_by_normal(float *l, float offset) +{ + float norm[4]; + float tx, ty; + + line_normal(l, norm); + line_normalize(norm); + + tx = (norm[2] - norm[0]) * offset; + ty = (norm[3] - norm[1]) * offset; + l[0] += tx; l[1] += ty; + l[2] += tx; l[3] += ty; +} + +static INLINE VGboolean is_bezier_line(float (*points)[2], int count) +{ + float dx13 = points[2][0] - points[0][0]; + float dy13 = points[2][1] - points[0][1]; + + float dx12 = points[1][0] - points[0][0]; + float dy12 = points[1][1] - points[0][1]; + + debug_assert(count > 2); + + if (count == 3) { + return floatsEqual(dx12 * dy13, dx13 * dy12); + } else if (count == 4) { + float dx14 = points[3][0] - points[0][0]; + float dy14 = points[3][1] - points[0][1]; + + return (floatsEqual(dx12 * dy13, dx13 * dy12) && + floatsEqual(dx12 * dy14, dx14 * dy12)); + } + + return VG_FALSE; +} + +static INLINE void compute_pt_normal(float *pt1, float *pt2, float *res) +{ + float line[4]; + float normal[4]; + line[0] = 0.f; line[1] = 0.f; + line[2] = pt2[0] - pt1[0]; + line[3] = pt2[1] - pt1[1]; + line_normal(line, normal); + line_normalize(normal); + + res[0] = normal[2]; + res[1] = normal[3]; +} + +static enum shift_result shift(const struct bezier *orig, + struct bezier *shifted, + float offset, float threshold) +{ + int i; + int map[4]; + VGboolean p1_p2_equal = (orig->x1 == orig->x2 && orig->y1 == orig->y2); + VGboolean p2_p3_equal = (orig->x2 == orig->x3 && orig->y2 == orig->y3); + VGboolean p3_p4_equal = (orig->x3 == orig->x4 && orig->y3 == orig->y4); + + float points[4][2]; + int np = 0; + float bounds[4]; + float points_shifted[4][2]; + float prev_normal[2]; + + points[np][0] = orig->x1; + points[np][1] = orig->y1; + map[0] = 0; + ++np; + if (!p1_p2_equal) { + points[np][0] = orig->x2; + points[np][1] = orig->y2; + ++np; + } + map[1] = np - 1; + if (!p2_p3_equal) { + points[np][0] = orig->x3; + points[np][1] = orig->y3; + ++np; + } + map[2] = np - 1; + if (!p3_p4_equal) { + points[np][0] = orig->x4; + points[np][1] = orig->y4; + ++np; + } + map[3] = np - 1; + if (np == 1) + return Discard; + + /* We need to specialcase lines of 3 or 4 points due to numerical + instability in intersection code below */ + if (np > 2 && is_bezier_line(points, np)) { + float l[4] = { points[0][0], points[0][1], + points[np-1][0], points[np-1][1] }; + float ctrl1[2], ctrl2[2]; + if (floatsEqual(points[0][0], points[np-1][0]) && + floatsEqual(points[0][1], points[np-1][1])) + return Discard; + + shift_line_by_normal(l, offset); + line_point_at(l, 0.33, ctrl1); + line_point_at(l, 0.66, ctrl2); + bezier_init(shifted, l[0], l[1], + ctrl1[0], ctrl1[1], ctrl2[0], ctrl2[1], + l[2], l[3]); + return Ok; + } + + bezier_bounds(orig, bounds); + if (np == 4 && bounds[2] < .1*offset && bounds[3] < .1*offset) { + float l = (orig->x1 - orig->x2)*(orig->x1 - orig->x2) + + (orig->y1 - orig->y2)*(orig->y1 - orig->y1) * + (orig->x3 - orig->x4)*(orig->x3 - orig->x4) + + (orig->y3 - orig->y4)*(orig->y3 - orig->y4); + float dot = (orig->x1 - orig->x2)*(orig->x3 - orig->x4) + + (orig->y1 - orig->y2)*(orig->y3 - orig->y4); + if (dot < 0 && dot*dot < 0.8*l) + /* the points are close and reverse dirction. Approximate the whole + thing by a semi circle */ + return Circle; + } + + compute_pt_normal(points[0], points[1], prev_normal); + + points_shifted[0][0] = points[0][0] + offset * prev_normal[0]; + points_shifted[0][1] = points[0][1] + offset * prev_normal[1]; + + for (i = 1; i < np - 1; ++i) { + float normal_sum[2], r; + float next_normal[2]; + compute_pt_normal(points[i], points[i + 1], next_normal); + + normal_sum[0] = prev_normal[0] + next_normal[0]; + normal_sum[1] = prev_normal[1] + next_normal[1]; + + r = 1.0 + prev_normal[0] * next_normal[0] + + prev_normal[1] * next_normal[1]; + + if (floatsEqual(r + 1, 1)) { + points_shifted[i][0] = points[i][0] + offset * prev_normal[0]; + points_shifted[i][1] = points[i][1] + offset * prev_normal[1]; + } else { + float k = offset / r; + points_shifted[i][0] = points[i][0] + k * normal_sum[0]; + points_shifted[i][1] = points[i][1] + k * normal_sum[1]; + } + + prev_normal[0] = next_normal[0]; + prev_normal[1] = next_normal[1]; + } + + points_shifted[np - 1][0] = points[np - 1][0] + offset * prev_normal[0]; + points_shifted[np - 1][1] = points[np - 1][1] + offset * prev_normal[1]; + + bezier_init2v(shifted, + points_shifted[map[0]], points_shifted[map[1]], + points_shifted[map[2]], points_shifted[map[3]]); + + return good_offset(orig, shifted, offset, threshold); +} + +static VGboolean make_circle(const struct bezier *b, float offset, struct bezier *o) +{ + float normals[3][2]; + float dist; + float angles[2]; + float sign = 1.f; + int i; + float circle[3][2]; + + normals[0][0] = b->y2 - b->y1; + normals[0][1] = b->x1 - b->x2; + dist = sqrt(normals[0][0]*normals[0][0] + normals[0][1]*normals[0][1]); + if (floatsEqual(dist + 1, 1.f)) + return VG_FALSE; + normals[0][0] /= dist; + normals[0][1] /= dist; + + normals[2][0] = b->y4 - b->y3; + normals[2][1] = b->x3 - b->x4; + dist = sqrt(normals[2][0]*normals[2][0] + normals[2][1]*normals[2][1]); + if (floatsEqual(dist + 1, 1.f)) + return VG_FALSE; + normals[2][0] /= dist; + normals[2][1] /= dist; + + normals[1][0] = b->x1 - b->x2 - b->x3 + b->x4; + normals[1][1] = b->y1 - b->y2 - b->y3 + b->y4; + dist = -1*sqrt(normals[1][0]*normals[1][0] + normals[1][1]*normals[1][1]); + normals[1][0] /= dist; + normals[1][1] /= dist; + + for (i = 0; i < 2; ++i) { + float cos_a = normals[i][0]*normals[i+1][0] + normals[i][1]*normals[i+1][1]; + if (cos_a > 1.) + cos_a = 1.; + if (cos_a < -1.) + cos_a = -1; + angles[i] = acos(cos_a)/M_PI; + } + + if (angles[0] + angles[1] > 1.) { + /* more than 180 degrees */ + normals[1][0] = -normals[1][0]; + normals[1][1] = -normals[1][1]; + angles[0] = 1. - angles[0]; + angles[1] = 1. - angles[1]; + sign = -1.; + } + + circle[0][0] = b->x1 + normals[0][0]*offset; + circle[0][1] = b->y1 + normals[0][1]*offset; + + circle[1][0] = 0.5*(b->x1 + b->x4) + normals[1][0]*offset; + circle[1][1] = 0.5*(b->y1 + b->y4) + normals[1][1]*offset; + + circle[2][0] = b->x4 + normals[2][0]*offset; + circle[2][1] = b->y4 + normals[2][1]*offset; + + for (i = 0; i < 2; ++i) { + float kappa = 2.*KAPPA * sign * offset * angles[i]; + + o->x1 = circle[i][0]; + o->y1 = circle[i][1]; + o->x2 = circle[i][0] - normals[i][1]*kappa; + o->y2 = circle[i][1] + normals[i][0]*kappa; + o->x3 = circle[i+1][0] + normals[i+1][1]*kappa; + o->y3 = circle[i+1][1] - normals[i+1][0]*kappa; + o->x4 = circle[i+1][0]; + o->y4 = circle[i+1][1]; + + ++o; + } + return VG_TRUE; +} + +int bezier_translate_by_normal(struct bezier *bez, + struct bezier *curves, + int max_curves, + float normal_len, + float threshold) +{ + struct bezier beziers[10]; + struct bezier *b, *o; + + /* fixme: this should really be floatsEqual */ + if (bez->x1 == bez->x2 && bez->x1 == bez->x3 && bez->x1 == bez->x4 && + bez->y1 == bez->y2 && bez->y1 == bez->y3 && bez->y1 == bez->y4) + return 0; + + --max_curves; +redo: + beziers[0] = *bez; + b = beziers; + o = curves; + + while (b >= beziers) { + int stack_segments = b - beziers + 1; + enum shift_result res; + if ((stack_segments == 10) || (o - curves == max_curves - stack_segments)) { + threshold *= 1.5; + if (threshold > 2.) + goto give_up; + goto redo; + } + res = shift(b, o, normal_len, threshold); + if (res == Discard) { + --b; + } else if (res == Ok) { + ++o; + --b; + continue; + } else if (res == Circle && max_curves - (o - curves) >= 2) { + /* add semi circle */ + if (make_circle(b, normal_len, o)) + o += 2; + --b; + } else { + split(b, b+1, b); + ++b; + } + } + +give_up: + while (b >= beziers) { + enum shift_result res = shift(b, o, normal_len, threshold); + + /* if res isn't Ok or Split then *o is undefined */ + if (res == Ok || res == Split) + ++o; + + --b; + } + + debug_assert(o - curves <= max_curves); + return o - curves; +} + +void bezier_bounds(const struct bezier *bez, + float *bounds/*x/y/width/height*/) +{ + float xmin = bez->x1; + float xmax = bez->x1; + float ymin = bez->y1; + float ymax = bez->y1; + + if (bez->x2 < xmin) + xmin = bez->x2; + else if (bez->x2 > xmax) + xmax = bez->x2; + if (bez->x3 < xmin) + xmin = bez->x3; + else if (bez->x3 > xmax) + xmax = bez->x3; + if (bez->x4 < xmin) + xmin = bez->x4; + else if (bez->x4 > xmax) + xmax = bez->x4; + + if (bez->y2 < ymin) + ymin = bez->y2; + else if (bez->y2 > ymax) + ymax = bez->y2; + if (bez->y3 < ymin) + ymin = bez->y3; + else if (bez->y3 > ymax) + ymax = bez->y3; + if (bez->y4 < ymin) + ymin = bez->y4; + else if (bez->y4 > ymax) + ymax = bez->y4; + + bounds[0] = xmin; /* x */ + bounds[1] = ymin; /* y */ + bounds[2] = xmax - xmin; /* width */ + bounds[3] = ymax - ymin; /* height */ +} + +void bezier_start_tangent(const struct bezier *bez, + float *tangent) +{ + tangent[0] = bez->x1; + tangent[1] = bez->y1; + tangent[2] = bez->x2; + tangent[3] = bez->y2; + + if (null_line(tangent)) { + tangent[0] = bez->x1; + tangent[1] = bez->y1; + tangent[2] = bez->x3; + tangent[3] = bez->y3; + } + if (null_line(tangent)) { + tangent[0] = bez->x1; + tangent[1] = bez->y1; + tangent[2] = bez->x4; + tangent[3] = bez->y4; + } +} + + +static INLINE VGfloat bezier_t_at_length(struct bezier *bez, + VGfloat at_length, + VGfloat error) +{ + VGfloat len = bezier_length(bez, error); + VGfloat t = 1.0; + VGfloat last_bigger = 1.; + + if (at_length > len || floatsEqual(at_length, len)) + return t; + + if (floatIsZero(at_length)) + return 0.f; + + t *= 0.5; + while (1) { + struct bezier right = *bez; + struct bezier left; + VGfloat tmp_len; + split_left(&right, t, &left); + tmp_len = bezier_length(&left, error); + if (ABS(tmp_len - at_length) < error) + break; + + if (tmp_len < at_length) { + t += (last_bigger - t)*.5; + } else { + last_bigger = t; + t -= t*.5; + } + } + return t; +} + +void bezier_point_at_length(struct bezier *bez, + float length, + float *point, + float *normal) +{ + /* ~0.000001 seems to be required to pass G2080x tests */ + VGfloat t = bezier_t_at_length(bez, length, 0.000001); + bezier_point_at(bez, t, point); + bezier_normal_at(bez, t, normal); + vector_unit(normal); +} + +void bezier_point_at_t(struct bezier *bez, float t, + float *point, float *normal) +{ + bezier_point_at(bez, t, point); + bezier_normal_at(bez, t, normal); + vector_unit(normal); +} + +void bezier_exact_bounds(const struct bezier *bez, + float *bounds/*x/y/width/height*/) +{ + struct polygon *poly = polygon_create(64); + polygon_vertex_append(poly, bez->x1, bez->y1); + bezier_add_to_polygon(bez, poly); + polygon_bounding_rect(poly, bounds); + polygon_destroy(poly); +} + diff --git a/src/gallium/state_trackers/vega/bezier.h b/src/gallium/state_trackers/vega/bezier.h new file mode 100644 index 0000000..e066660 --- /dev/null +++ b/src/gallium/state_trackers/vega/bezier.h @@ -0,0 +1,81 @@ +/************************************************************************** + * + * 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 BEZIER_H +#define BEZIER_H + +struct polygon; +struct matrix; + +struct bezier { + float x1, y1; + float x2, y2; + float x3, y3; + float x4, y4; +}; + + +#define BEZIER_DEFAULT_ERROR 0.01 + +/* kappa as being l of a circle with r = 1, we can emulate any + * circle of radius r by using the formula + * l = r . kappa + * More at: + * http://www.whizkidtech.redprince.net/bezier/circle/ */ +#define KAPPA 0.5522847498 + +void bezier_init(struct bezier *bez, + float x1, float y1, + float x2, float y2, + float x3, float y3, + float x4, float y4); + +struct polygon *bezier_to_polygon(struct bezier *bez); +void bezier_add_to_polygon(const struct bezier *bez, + struct polygon *poly); +float bezier_length(struct bezier *bez, float error); +void bezier_transform(struct bezier *bez, + struct matrix *mat); + +int bezier_translate_by_normal(struct bezier *b, + struct bezier *curves, + int max_curves, + float normal_len, + float threshold); +void bezier_bounds(const struct bezier *bez, + float *bounds/*x/y/width/height*/); +void bezier_exact_bounds(const struct bezier *bez, + float *bounds/*x/y/width/height*/); + +void bezier_start_tangent(const struct bezier *bez, + float *tangent); + +void bezier_point_at_length(struct bezier *bez, float length, + float *point, float *normal); +void bezier_point_at_t(struct bezier *bez, float t, + float *point, float *normal); + +#endif diff --git a/src/gallium/state_trackers/vega/image.c b/src/gallium/state_trackers/vega/image.c new file mode 100644 index 0000000..318ea94 --- /dev/null +++ b/src/gallium/state_trackers/vega/image.c @@ -0,0 +1,660 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "image.h" + +#include "vg_translate.h" +#include "vg_context.h" +#include "matrix.h" +#include "renderer.h" +#include "util_array.h" +#include "api_consts.h" +#include "shader.h" + +#include "pipe/p_context.h" +#include "pipe/p_screen.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_tile.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_sampler.h" +#include "util/u_surface.h" + +static enum pipe_format vg_format_to_pipe(VGImageFormat format) +{ + switch(format) { + case VG_sRGB_565: + return PIPE_FORMAT_B5G6R5_UNORM; + case VG_sRGBA_5551: + return PIPE_FORMAT_B5G5R5A1_UNORM; + case VG_sRGBA_4444: + return PIPE_FORMAT_B4G4R4A4_UNORM; + case VG_sL_8: + case VG_lL_8: + return PIPE_FORMAT_L8_UNORM; + case VG_BW_1: + return PIPE_FORMAT_B8G8R8A8_UNORM; + case VG_A_8: + return PIPE_FORMAT_A8_UNORM; +#ifdef OPENVG_VERSION_1_1 + case VG_A_1: + case VG_A_4: + return PIPE_FORMAT_A8_UNORM; +#endif + default: + return PIPE_FORMAT_B8G8R8A8_UNORM; + } +} + +static INLINE void vg_sync_size(VGfloat *src_loc, VGfloat *dst_loc) +{ + src_loc[2] = MIN2(src_loc[2], dst_loc[2]); + src_loc[3] = MIN2(src_loc[3], dst_loc[3]); + dst_loc[2] = src_loc[2]; + dst_loc[3] = src_loc[3]; +} + +static void vg_get_copy_coords(VGfloat *src_loc, + VGfloat src_width, VGfloat src_height, + VGfloat *dst_loc, + VGfloat dst_width, VGfloat dst_height) +{ + VGfloat dst_bounds[4], src_bounds[4]; + VGfloat src_shift[4], dst_shift[4], shift[4]; + + dst_bounds[0] = 0.f; + dst_bounds[1] = 0.f; + dst_bounds[2] = dst_width; + dst_bounds[3] = dst_height; + + src_bounds[0] = 0.f; + src_bounds[1] = 0.f; + src_bounds[2] = src_width; + src_bounds[3] = src_height; + + vg_bound_rect(src_loc, src_bounds, src_shift); + vg_bound_rect(dst_loc, dst_bounds, dst_shift); + shift[0] = src_shift[0] - dst_shift[0]; + shift[1] = src_shift[1] - dst_shift[1]; + + if (shift[0] < 0) + vg_shift_rectx(src_loc, src_bounds, -shift[0]); + else + vg_shift_rectx(dst_loc, dst_bounds, shift[0]); + + if (shift[1] < 0) + vg_shift_recty(src_loc, src_bounds, -shift[1]); + else + vg_shift_recty(dst_loc, dst_bounds, shift[1]); + + vg_sync_size(src_loc, dst_loc); +} + +static void vg_copy_texture(struct vg_context *ctx, + struct pipe_resource *dst, VGint dx, VGint dy, + struct pipe_sampler_view *src, VGint sx, VGint sy, + VGint width, VGint height) +{ + VGfloat dst_loc[4], src_loc[4]; + + dst_loc[0] = dx; + dst_loc[1] = dy; + dst_loc[2] = width; + dst_loc[3] = height; + + src_loc[0] = sx; + src_loc[1] = sy; + src_loc[2] = width; + src_loc[3] = height; + + vg_get_copy_coords(src_loc, src->texture->width0, src->texture->height0, + dst_loc, dst->width0, dst->height0); + + if (src_loc[2] >= 0 && src_loc[3] >= 0 && + dst_loc[2] >= 0 && dst_loc[3] >= 0) { + struct pipe_surface *surf, surf_tmpl; + + /* get the destination surface */ + u_surface_default_template(&surf_tmpl, dst, PIPE_BIND_RENDER_TARGET); + surf = ctx->pipe->create_surface(ctx->pipe, dst, &surf_tmpl); + if (surf && renderer_copy_begin(ctx->renderer, surf, VG_TRUE, src)) { + renderer_copy(ctx->renderer, + dst_loc[0], dst_loc[1], dst_loc[2], dst_loc[3], + src_loc[0], src_loc[1], src_loc[2], src_loc[3]); + renderer_copy_end(ctx->renderer); + } + + pipe_surface_reference(&surf, NULL); + } +} + +void vg_copy_surface(struct vg_context *ctx, + struct pipe_surface *dst, VGint dx, VGint dy, + struct pipe_surface *src, VGint sx, VGint sy, + VGint width, VGint height) +{ + VGfloat dst_loc[4], src_loc[4]; + + dst_loc[0] = dx; + dst_loc[1] = dy; + dst_loc[2] = width; + dst_loc[3] = height; + + src_loc[0] = sx; + src_loc[1] = sy; + src_loc[2] = width; + src_loc[3] = height; + + vg_get_copy_coords(src_loc, src->width, src->height, + dst_loc, dst->width, dst->height); + + if (src_loc[2] > 0 && src_loc[3] > 0 && + dst_loc[2] > 0 && dst_loc[3] > 0) { + if (src == dst) + renderer_copy_surface(ctx->renderer, + src, + src_loc[0], + src->height - (src_loc[1] + src_loc[3]), + src_loc[0] + src_loc[2], + src->height - src_loc[1], + dst, + dst_loc[0], + dst->height - (dst_loc[1] + dst_loc[3]), + dst_loc[0] + dst_loc[2], + dst->height - dst_loc[1], + 0, 0); + else + renderer_copy_surface(ctx->renderer, + src, + src_loc[0], + src->height - src_loc[1], + src_loc[0] + src_loc[2], + src->height - (src_loc[1] + src_loc[3]), + dst, + dst_loc[0], + dst->height - (dst_loc[1] + dst_loc[3]), + dst_loc[0] + dst_loc[2], + dst->height - dst_loc[1], + 0, 0); + } + +} + +static struct pipe_resource *image_texture(struct vg_image *img) +{ + struct pipe_resource *tex = img->sampler_view->texture; + return tex; +} + + +static void image_cleari(struct vg_image *img, VGint clear_colori, + VGint x, VGint y, VGint width, VGint height) +{ + VGint *clearbuf; + VGint i; + VGfloat dwidth, dheight; + + clearbuf = malloc(sizeof(VGint)*width*height); + for (i = 0; i < width*height; ++i) + clearbuf[i] = clear_colori; + + dwidth = MIN2(width, img->width); + dheight = MIN2(height, img->height); + + image_sub_data(img, clearbuf, width * sizeof(VGint), + VG_sRGBA_8888, + x, y, dwidth, dheight); + free(clearbuf); +} + +struct vg_image * image_create(VGImageFormat format, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct pipe_context *pipe = ctx->pipe; + struct vg_image *image = CALLOC_STRUCT(vg_image); + enum pipe_format pformat = vg_format_to_pipe(format); + struct pipe_resource pt, *newtex; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; + struct pipe_screen *screen = ctx->pipe->screen; + + vg_init_object(&image->base, ctx, VG_OBJECT_IMAGE); + + image->format = format; + image->width = width; + image->height = height; + + image->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + image->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + image->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + image->sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST; + image->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST; + image->sampler.normalized_coords = 1; + + assert(screen->is_format_supported(screen, pformat, PIPE_TEXTURE_2D, + 0, PIPE_BIND_SAMPLER_VIEW, 0)); + + memset(&pt, 0, sizeof(pt)); + pt.target = PIPE_TEXTURE_2D; + pt.format = pformat; + pt.last_level = 0; + pt.width0 = width; + pt.height0 = height; + pt.depth0 = 1; + pt.array_size = 1; + pt.bind = PIPE_BIND_SAMPLER_VIEW; + + newtex = screen->resource_create(screen, &pt); + + debug_assert(newtex); + + u_sampler_view_default_template(&view_templ, newtex, newtex->format); + /* R, G, and B are treated as 1.0 for alpha-only formats in OpenVG */ + if (newtex->format == PIPE_FORMAT_A8_UNORM) { + view_templ.swizzle_r = PIPE_SWIZZLE_ONE; + view_templ.swizzle_g = PIPE_SWIZZLE_ONE; + view_templ.swizzle_b = PIPE_SWIZZLE_ONE; + } + + view = pipe->create_sampler_view(pipe, newtex, &view_templ); + /* want the texture to go away if the view is freed */ + pipe_resource_reference(&newtex, NULL); + + image->sampler_view = view; + + vg_context_add_object(ctx, VG_OBJECT_IMAGE, image); + + image_cleari(image, 0, 0, 0, image->width, image->height); + return image; +} + +void image_destroy(struct vg_image *img) +{ + struct vg_context *ctx = vg_current_context(); + vg_context_remove_object(ctx, VG_OBJECT_IMAGE, img); + + + if (img->parent) { + /* remove img from the parent child array */ + int idx; + struct vg_image **array = + (struct vg_image **)img->parent->children_array->data; + + for (idx = 0; idx < img->parent->children_array->num_elements; ++idx) { + struct vg_image *child = array[idx]; + if (child == img) { + break; + } + } + debug_assert(idx < img->parent->children_array->num_elements); + array_remove_element(img->parent->children_array, idx); + } + + if (img->children_array && img->children_array->num_elements) { + /* reparent the children */ + VGint i; + struct vg_image *parent = img->parent; + struct vg_image **children = + (struct vg_image **)img->children_array->data; + if (!parent) { + VGint min_x = children[0]->x; + parent = children[0]; + + for (i = 1; i < img->children_array->num_elements; ++i) { + struct vg_image *child = children[i]; + if (child->x < min_x) { + parent = child; + } + } + } + + for (i = 0; i < img->children_array->num_elements; ++i) { + struct vg_image *child = children[i]; + if (child != parent) { + child->parent = parent; + if (!parent->children_array) { + parent->children_array = array_create( + sizeof(struct vg_image*)); + } + array_append_data(parent->children_array, + &child, 1); + } else + child->parent = NULL; + } + array_destroy(img->children_array); + } + + pipe_sampler_view_reference(&img->sampler_view, NULL); + FREE(img); +} + +void image_clear(struct vg_image *img, + VGint x, VGint y, VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + VGfloat *clear_colorf = ctx->state.vg.clear_color; + VGubyte r, g, b ,a; + VGint clear_colori; + /* FIXME: this is very nasty */ + r = float_to_ubyte(clear_colorf[0]); + g = float_to_ubyte(clear_colorf[1]); + b = float_to_ubyte(clear_colorf[2]); + a = float_to_ubyte(clear_colorf[3]); + clear_colori = r << 24 | g << 16 | b << 8 | a; + image_cleari(img, clear_colori, x, y, width, height); +} + +void image_sub_data(struct vg_image *image, + const void * data, + VGint dataStride, + VGImageFormat dataFormat, + VGint x, VGint y, + VGint width, VGint height) +{ + const VGint yStep = 1; + VGubyte *src = (VGubyte *)data; + VGfloat temp[VEGA_MAX_IMAGE_WIDTH][4]; + VGfloat *df = (VGfloat*)temp; + VGint i; + struct vg_context *ctx = vg_current_context(); + struct pipe_context *pipe = ctx->pipe; + struct pipe_resource *texture = image_texture(image); + VGint xoffset = 0, yoffset = 0; + + if (x < 0) { + xoffset -= x; + width += x; + x = 0; + } + if (y < 0) { + yoffset -= y; + height += y; + y = 0; + } + + if (width <= 0 || height <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (x > image->width || y > image->width) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + if (x + width > image->width) { + width = image->width - x; + } + + if (y + height > image->height) { + height = image->height - y; + } + + { /* upload color_data */ + struct pipe_transfer *transfer = pipe_get_transfer( + pipe, texture, 0, 0, + PIPE_TRANSFER_WRITE, 0, 0, texture->width0, texture->height0); + src += (dataStride * yoffset); + for (i = 0; i < height; i++) { + _vega_unpack_float_span_rgba(ctx, width, xoffset, src, dataFormat, temp); + pipe_put_tile_rgba(pipe, transfer, x+image->x, y+image->y, width, 1, df); + y += yStep; + src += dataStride; + } + pipe->transfer_destroy(pipe, transfer); + } +} + +void image_get_sub_data(struct vg_image * image, + void * data, + VGint dataStride, + VGImageFormat dataFormat, + VGint sx, VGint sy, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct pipe_context *pipe = ctx->pipe; + VGfloat temp[VEGA_MAX_IMAGE_WIDTH][4]; + VGfloat *df = (VGfloat*)temp; + VGint y = 0, yStep = 1; + VGint i; + VGubyte *dst = (VGubyte *)data; + + { + struct pipe_transfer *transfer = + pipe_get_transfer(pipe, + image->sampler_view->texture, 0, 0, + PIPE_TRANSFER_READ, + 0, 0, + image->x + image->width, + image->y + image->height); + /* Do a row at a time to flip image data vertically */ + for (i = 0; i < height; i++) { +#if 0 + debug_printf("%d-%d == %d\n", sy, height, y); +#endif + pipe_get_tile_rgba(pipe, transfer, sx+image->x, y, width, 1, df); + y += yStep; + _vega_pack_rgba_span_float(ctx, width, temp, dataFormat, dst); + dst += dataStride; + } + + pipe->transfer_destroy(pipe, transfer); + } +} + +struct vg_image * image_child_image(struct vg_image *parent, + VGint x, VGint y, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_image *image = CALLOC_STRUCT(vg_image); + + vg_init_object(&image->base, ctx, VG_OBJECT_IMAGE); + + image->x = parent->x + x; + image->y = parent->y + y; + image->width = width; + image->height = height; + image->parent = parent; + image->sampler_view = NULL; + pipe_sampler_view_reference(&image->sampler_view, + parent->sampler_view); + + image->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + image->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + image->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + image->sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST; + image->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST; + image->sampler.normalized_coords = 1; + + if (!parent->children_array) + parent->children_array = array_create( + sizeof(struct vg_image*)); + + array_append_data(parent->children_array, + &image, 1); + + vg_context_add_object(ctx, VG_OBJECT_IMAGE, image); + + return image; +} + +void image_copy(struct vg_image *dst, VGint dx, VGint dy, + struct vg_image *src, VGint sx, VGint sy, + VGint width, VGint height, + VGboolean dither) +{ + struct vg_context *ctx = vg_current_context(); + + if (width <= 0 || height <= 0) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + /* make sure rendering has completed */ + ctx->pipe->flush(ctx->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + vg_copy_texture(ctx, dst->sampler_view->texture, dst->x + dx, dst->y + dy, + src->sampler_view, src->x + sx, src->y + sy, width, height); +} + +void image_draw(struct vg_image *img, struct matrix *matrix) +{ + struct vg_context *ctx = vg_current_context(); + struct matrix paint_matrix; + VGfloat x1, y1; + VGfloat x2, y2; + VGfloat x3, y3; + VGfloat x4, y4; + + if (!vg_get_paint_matrix(ctx, + &ctx->state.vg.fill_paint_to_user_matrix, + matrix, + &paint_matrix)) + return; + + x1 = 0; + y1 = 0; + x2 = img->width; + y2 = 0; + x3 = img->width; + y3 = img->height; + x4 = 0; + y4 = img->height; + + shader_set_surface_matrix(ctx->shader, matrix); + shader_set_drawing_image(ctx->shader, VG_TRUE); + shader_set_paint(ctx->shader, ctx->state.vg.fill_paint); + shader_set_paint_matrix(ctx->shader, &paint_matrix); + shader_set_image(ctx->shader, img); + shader_bind(ctx->shader); + + renderer_texture_quad(ctx->renderer, image_texture(img), + img->x, img->y, img->x + img->width, img->y + img->height, + x1, y1, x2, y2, x3, y3, x4, y4); +} + +void image_set_pixels(VGint dx, VGint dy, + struct vg_image *src, VGint sx, VGint sy, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct pipe_context *pipe = ctx->pipe; + struct pipe_surface *surf, surf_tmpl; + struct st_renderbuffer *strb = ctx->draw_buffer->strb; + + /* make sure rendering has completed */ + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + + memset(&surf_tmpl, 0, sizeof(surf_tmpl)); + u_surface_default_template(&surf_tmpl, image_texture(src), + 0 /* no bind flag - not a surface*/); + surf = pipe->create_surface(pipe, image_texture(src), &surf_tmpl); + + vg_copy_surface(ctx, strb->surface, dx, dy, + surf, sx+src->x, sy+src->y, width, height); + + pipe->surface_destroy(pipe, surf); +} + +void image_get_pixels(struct vg_image *dst, VGint dx, VGint dy, + VGint sx, VGint sy, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct pipe_context *pipe = ctx->pipe; + struct pipe_surface *surf, surf_tmpl; + struct st_renderbuffer *strb = ctx->draw_buffer->strb; + + /* flip the y coordinates */ + /*dy = dst->height - dy - height;*/ + + /* make sure rendering has completed */ + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + + memset(&surf_tmpl, 0, sizeof(surf_tmpl)); + u_surface_default_template(&surf_tmpl, image_texture(dst), + PIPE_BIND_RENDER_TARGET); + surf = pipe->create_surface(pipe, image_texture(dst), &surf_tmpl); + + vg_copy_surface(ctx, surf, dst->x + dx, dst->y + dy, + strb->surface, sx, sy, width, height); + + pipe_surface_reference(&surf, NULL); +} + + +VGboolean vg_image_overlaps(struct vg_image *dst, + struct vg_image *src) +{ + if (dst == src || dst->parent == src || + dst == src->parent) + return VG_TRUE; + if (dst->parent && dst->parent == src->parent) { + VGfloat left1 = dst->x; + VGfloat left2 = src->x; + VGfloat right1 = dst->x + dst->width; + VGfloat right2 = src->x + src->width; + VGfloat bottom1 = dst->y; + VGfloat bottom2 = src->y; + VGfloat top1 = dst->y + dst->height; + VGfloat top2 = src->y + src->height; + + return !(left2 > right1 || right2 < left1 || + top2 > bottom1 || bottom2 < top1); + } + return VG_FALSE; +} + +VGint image_bind_samplers(struct vg_image *img, struct pipe_sampler_state **samplers, + struct pipe_sampler_view **sampler_views) +{ + img->sampler.min_img_filter = image_sampler_filter(img->base.ctx); + img->sampler.mag_img_filter = image_sampler_filter(img->base.ctx); + samplers[3] = &img->sampler; + sampler_views[3] = img->sampler_view; + return 1; +} + +VGint image_sampler_filter(struct vg_context *ctx) +{ + switch(ctx->state.vg.image_quality) { + case VG_IMAGE_QUALITY_NONANTIALIASED: + return PIPE_TEX_FILTER_NEAREST; + break; + case VG_IMAGE_QUALITY_FASTER: + return PIPE_TEX_FILTER_NEAREST; + break; + case VG_IMAGE_QUALITY_BETTER: + /* possibly use anisotropic filtering */ + return PIPE_TEX_FILTER_LINEAR; + break; + default: + debug_printf("Unknown image quality"); + } + return PIPE_TEX_FILTER_NEAREST; +} diff --git a/src/gallium/state_trackers/vega/image.h b/src/gallium/state_trackers/vega/image.h new file mode 100644 index 0000000..391c048 --- /dev/null +++ b/src/gallium/state_trackers/vega/image.h @@ -0,0 +1,104 @@ +/************************************************************************** + * + * 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 IMAGES_H +#define IMAGES_H + +#include "vg_context.h" +#include "pipe/p_state.h" + +struct pipe_resource; +struct array; +struct vg_context; +struct pipe_surface; + +struct vg_image { + struct vg_object base; + VGImageFormat format; + VGint x, y; + VGint width, height; + + struct vg_image *parent; + + struct pipe_sampler_view *sampler_view; + struct pipe_sampler_state sampler; + + struct array *children_array; +}; + +struct vg_image *image_create(VGImageFormat format, + VGint width, VGint height); +void image_destroy(struct vg_image *img); + +void image_clear(struct vg_image *img, + VGint x, VGint y, VGint width, VGint height); + +void image_sub_data(struct vg_image *image, + const void * data, + VGint dataStride, + VGImageFormat dataFormat, + VGint x, VGint y, + VGint width, VGint height); + +void image_get_sub_data(struct vg_image * image, + void * data, + VGint dataStride, + VGImageFormat dataFormat, + VGint x, VGint y, + VGint width, VGint height); + +struct vg_image *image_child_image(struct vg_image *parent, + VGint x, VGint y, + VGint width, VGint height); + +void image_copy(struct vg_image *dst, VGint dx, VGint dy, + struct vg_image *src, VGint sx, VGint sy, + VGint width, VGint height, + VGboolean dither); + +void image_draw(struct vg_image *img, struct matrix *matrix); + +void image_set_pixels(VGint dx, VGint dy, + struct vg_image *src, VGint sx, VGint sy, + VGint width, VGint height); +void image_get_pixels(struct vg_image *dst, VGint dx, VGint dy, + VGint sx, VGint sy, + VGint width, VGint height); + +VGint image_bind_samplers(struct vg_image *dst, struct pipe_sampler_state **samplers, + struct pipe_sampler_view **sampler_views); + +VGboolean vg_image_overlaps(struct vg_image *dst, + struct vg_image *src); + +VGint image_sampler_filter(struct vg_context *ctx); + +void vg_copy_surface(struct vg_context *ctx, + struct pipe_surface *dst, VGint dx, VGint dy, + struct pipe_surface *src, VGint sx, VGint sy, + VGint width, VGint height); + +#endif diff --git a/src/gallium/state_trackers/vega/mask.c b/src/gallium/state_trackers/vega/mask.c new file mode 100644 index 0000000..dfd0600 --- /dev/null +++ b/src/gallium/state_trackers/vega/mask.c @@ -0,0 +1,530 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "mask.h" + +#include "path.h" +#include "image.h" +#include "shaders_cache.h" +#include "renderer.h" +#include "asm_util.h" + +#include "pipe/p_context.h" +#include "pipe/p_screen.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_surface.h" +#include "util/u_sampler.h" + +struct vg_mask_layer { + struct vg_object base; + + VGint width; + VGint height; + + struct pipe_sampler_view *sampler_view; +}; + +static INLINE VGboolean +intersect_rectangles(VGint dwidth, VGint dheight, + VGint swidth, VGint sheight, + VGint tx, VGint ty, + VGint twidth, VGint theight, + VGint *offsets, + VGint *location) +{ + if (tx + twidth <= 0 || tx >= dwidth) + return VG_FALSE; + if (ty + theight <= 0 || ty >= dheight) + return VG_FALSE; + + offsets[0] = 0; + offsets[1] = 0; + location[0] = tx; + location[1] = ty; + + if (tx < 0) { + offsets[0] -= tx; + location[0] = 0; + + location[2] = MIN2(tx + swidth, MIN2(dwidth, tx + twidth)); + offsets[2] = location[2]; + } else { + offsets[2] = MIN2(twidth, MIN2(dwidth - tx, swidth )); + location[2] = offsets[2]; + } + + if (ty < 0) { + offsets[1] -= ty; + location[1] = 0; + + location[3] = MIN2(ty + sheight, MIN2(dheight, ty + theight)); + offsets[3] = location[3]; + } else { + offsets[3] = MIN2(theight, MIN2(dheight - ty, sheight)); + location[3] = offsets[3]; + } + + return VG_TRUE; +} + +#if DEBUG_MASKS +static void read_alpha_mask(void * data, VGint dataStride, + VGImageFormat dataFormat, + VGint sx, VGint sy, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct pipe_context *pipe = ctx->pipe; + + struct st_framebuffer *stfb = ctx->draw_buffer; + struct st_renderbuffer *strb = stfb->alpha_mask; + + VGfloat temp[VEGA_MAX_IMAGE_WIDTH][4]; + VGfloat *df = (VGfloat*)temp; + VGint y = (stfb->height - sy) - 1, yStep = -1; + VGint i; + VGubyte *dst = (VGubyte *)data; + VGint xoffset = 0, yoffset = 0; + + /* make sure rendering has completed */ + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + if (sx < 0) { + xoffset = -sx; + xoffset *= _vega_size_for_format(dataFormat); + width += sx; + sx = 0; + } + if (sy < 0) { + yoffset = -sy; + height += sy; + sy = 0; + y = (stfb->height - sy) - 1; + yoffset *= dataStride; + } + + { + struct pipe_surface *surf; + + surf = pipe->create_surface(pipe, strb->texture, 0, 0, 0, + PIPE_BIND_TRANSFER_READ); + + /* Do a row at a time to flip image data vertically */ + for (i = 0; i < height; i++) { +#if 0 + debug_printf("%d-%d == %d\n", sy, height, y); +#endif + pipe_get_tile_rgba(surf, sx, y, width, 1, df); + y += yStep; + _vega_pack_rgba_span_float(ctx, width, temp, dataFormat, + dst + yoffset + xoffset); + dst += dataStride; + } + + pipe_surface_reference(&surf, NULL); + } +} + +void save_alpha_to_file(const char *filename) +{ + struct vg_context *ctx = vg_current_context(); + struct st_framebuffer *stfb = ctx->draw_buffer; + VGint *data; + int i, j; + + data = malloc(sizeof(int) * stfb->width * stfb->height); + read_alpha_mask(data, stfb->width * sizeof(int), + VG_sRGBA_8888, + 0, 0, stfb->width, stfb->height); + fprintf(stderr, "/*---------- start */\n"); + fprintf(stderr, "const int image_width = %d;\n", + stfb->width); + fprintf(stderr, "const int image_height = %d;\n", + stfb->height); + fprintf(stderr, "const int image_data = {\n"); + for (i = 0; i < stfb->height; ++i) { + for (j = 0; j < stfb->width; ++j) { + int rgba = data[i * stfb->height + j]; + int argb = 0; + argb = (rgba >> 8); + argb |= ((rgba & 0xff) << 24); + fprintf(stderr, "0x%x, ", argb); + } + fprintf(stderr, "\n"); + } + fprintf(stderr, "};\n"); + fprintf(stderr, "/*---------- end */\n"); +} +#endif + +/* setup mask shader */ +static void *setup_mask_operation(VGMaskOperation operation) +{ + struct vg_context *ctx = vg_current_context(); + void *shader = 0; + + switch (operation) { + case VG_UNION_MASK: { + if (!ctx->mask.union_fs) { + ctx->mask.union_fs = shader_create_from_text(ctx->pipe, + union_mask_asm, + 200, + PIPE_SHADER_FRAGMENT); + } + shader = ctx->mask.union_fs->driver; + } + break; + case VG_INTERSECT_MASK: { + if (!ctx->mask.intersect_fs) { + ctx->mask.intersect_fs = shader_create_from_text(ctx->pipe, + intersect_mask_asm, + 200, + PIPE_SHADER_FRAGMENT); + } + shader = ctx->mask.intersect_fs->driver; + } + break; + case VG_SUBTRACT_MASK: { + if (!ctx->mask.subtract_fs) { + ctx->mask.subtract_fs = shader_create_from_text(ctx->pipe, + subtract_mask_asm, + 200, + PIPE_SHADER_FRAGMENT); + } + shader = ctx->mask.subtract_fs->driver; + } + break; + case VG_SET_MASK: { + if (!ctx->mask.set_fs) { + ctx->mask.set_fs = shader_create_from_text(ctx->pipe, + set_mask_asm, + 200, + PIPE_SHADER_FRAGMENT); + } + shader = ctx->mask.set_fs->driver; + } + break; + default: + assert(0); + break; + } + + return shader; +} + +static void mask_resource_fill(struct pipe_resource *dst, + int x, int y, int width, int height, + VGfloat coverage) +{ + struct vg_context *ctx = vg_current_context(); + VGfloat fs_consts[12] = { + 0.0f, 0.0f, 0.0f, 0.0f, /* not used */ + 0.0f, 0.0f, 0.0f, 0.0f, /* not used */ + 0.0f, 0.0f, 0.0f, coverage /* color */ + }; + void *fs; + + if (x < 0) { + width += x; + x = 0; + } + if (y < 0) { + height += y; + y = 0; + } + + fs = shaders_cache_fill(ctx->sc, VEGA_SOLID_FILL_SHADER); + + if (renderer_filter_begin(ctx->renderer, dst, VG_FALSE, ~0, + NULL, NULL, 0, fs, (const void *) fs_consts, sizeof(fs_consts))) { + renderer_filter(ctx->renderer, x, y, width, height, 0, 0, 0, 0); + renderer_filter_end(ctx->renderer); + } + +#if DEBUG_MASKS + save_alpha_to_file(0); +#endif +} + + +static void mask_using_texture(struct pipe_sampler_view *sampler_view, + VGboolean is_layer, + VGMaskOperation operation, + VGint x, VGint y, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct pipe_sampler_view *dst_view = vg_get_surface_mask(ctx); + struct pipe_resource *dst = dst_view->texture; + struct pipe_resource *texture = sampler_view->texture; + const struct pipe_sampler_state *samplers[2]; + struct pipe_sampler_view *views[2]; + struct pipe_sampler_state sampler; + VGint offsets[4], loc[4]; + const VGfloat ones[4] = {1.f, 1.f, 1.f, 1.f}; + void *fs; + + if (!intersect_rectangles(dst->width0, dst->height0, + texture->width0, texture->height0, + x, y, width, height, + offsets, loc)) + return; +#if 0 + debug_printf("Offset = [%d, %d, %d, %d]\n", offsets[0], + offsets[1], offsets[2], offsets[3]); + debug_printf("Locati = [%d, %d, %d, %d]\n", loc[0], + loc[1], loc[2], loc[3]); +#endif + + + sampler = ctx->mask.sampler; + sampler.normalized_coords = 1; + samplers[0] = &sampler; + views[0] = sampler_view; + + /* prepare our blend surface */ + samplers[1] = &ctx->mask.sampler; + views[1] = vg_prepare_blend_surface_from_mask(ctx); + + fs = setup_mask_operation(operation); + + if (renderer_filter_begin(ctx->renderer, dst, VG_FALSE, + ~0, samplers, views, 2, fs, (const void *) ones, sizeof(ones))) { + /* layer should be flipped when used as a texture */ + if (is_layer) { + offsets[1] += offsets[3]; + offsets[3] = -offsets[3]; + } + renderer_filter(ctx->renderer, + loc[0], loc[1], loc[2], loc[3], + offsets[0], offsets[1], offsets[2], offsets[3]); + renderer_filter_end(ctx->renderer); + } +} + + +#ifdef OPENVG_VERSION_1_1 + +struct vg_mask_layer * mask_layer_create(VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_mask_layer *mask = 0; + + mask = CALLOC_STRUCT(vg_mask_layer); + vg_init_object(&mask->base, ctx, VG_OBJECT_MASK); + mask->width = width; + mask->height = height; + + { + struct pipe_resource pt; + struct pipe_context *pipe = ctx->pipe; + struct pipe_screen *screen = ctx->pipe->screen; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view = NULL; + struct pipe_resource *texture; + + memset(&pt, 0, sizeof(pt)); + pt.target = PIPE_TEXTURE_2D; + pt.format = PIPE_FORMAT_B8G8R8A8_UNORM; + pt.last_level = 0; + pt.width0 = width; + pt.height0 = height; + pt.depth0 = 1; + pt.array_size = 1; + pt.bind = PIPE_BIND_SAMPLER_VIEW; + + texture = screen->resource_create(screen, &pt); + + if (texture) { + u_sampler_view_default_template(&view_templ, texture, texture->format); + view = pipe->create_sampler_view(pipe, texture, &view_templ); + } + pipe_resource_reference(&texture, NULL); + mask->sampler_view = view; + } + + vg_context_add_object(ctx, VG_OBJECT_MASK, mask); + + return mask; +} + +void mask_layer_destroy(struct vg_mask_layer *layer) +{ + struct vg_context *ctx = vg_current_context(); + + vg_context_remove_object(ctx, VG_OBJECT_MASK, layer); + pipe_sampler_view_reference(&layer->sampler_view, NULL); + FREE(layer); +} + +void mask_layer_fill(struct vg_mask_layer *layer, + VGint x, VGint y, + VGint width, VGint height, + VGfloat value) +{ + VGfloat alpha_color[4] = {0, 0, 0, 0}; + + alpha_color[3] = value; + + mask_resource_fill(layer->sampler_view->texture, + x, y, width, height, value); +} + +void mask_copy(struct vg_mask_layer *layer, + VGint sx, VGint sy, + VGint dx, VGint dy, + VGint width, VGint height) +{ + struct vg_context *ctx = vg_current_context(); + struct pipe_sampler_view *src = vg_get_surface_mask(ctx); + struct pipe_surface *surf, surf_tmpl; + + /* get the destination surface */ + u_surface_default_template(&surf_tmpl, layer->sampler_view->texture, + PIPE_BIND_RENDER_TARGET); + surf = ctx->pipe->create_surface(ctx->pipe, layer->sampler_view->texture, + &surf_tmpl); + if (surf && renderer_copy_begin(ctx->renderer, surf, VG_FALSE, src)) { + /* layer should be flipped when used as a texture */ + sy += height; + height = -height; + + renderer_copy(ctx->renderer, + dx, dy, width, height, + sx, sy, width, height); + renderer_copy_end(ctx->renderer); + } + + pipe_surface_reference(&surf, NULL); +} + +static void mask_layer_render_to(struct vg_mask_layer *layer, + struct path *path, + VGbitfield paint_modes) +{ + struct vg_context *ctx = vg_current_context(); + struct pipe_context *pipe = ctx->pipe; + struct pipe_sampler_view *view = vg_get_surface_mask(ctx); + struct matrix *mat = &ctx->state.vg.path_user_to_surface_matrix; + struct pipe_surface *surf, surf_tmpl; + u_surface_default_template(&surf_tmpl, view->texture, + PIPE_BIND_RENDER_TARGET); + surf = pipe->create_surface(pipe, view->texture, &surf_tmpl); + + renderer_validate_for_mask_rendering(ctx->renderer, surf, mat); + + if (paint_modes & VG_FILL_PATH) { + path_fill(path); + } + + if (paint_modes & VG_STROKE_PATH){ + path_stroke(path); + } + + pipe_surface_reference(&surf, NULL); +} + +void mask_render_to(struct path *path, + VGbitfield paint_modes, + VGMaskOperation operation) +{ + struct vg_context *ctx = vg_current_context(); + struct st_framebuffer *stfb = ctx->draw_buffer; + struct vg_mask_layer *temp_layer; + VGint width, height; + + width = stfb->width; + height = stfb->height; + + temp_layer = mask_layer_create(width, height); + mask_layer_fill(temp_layer, 0, 0, width, height, 0.0f); + + mask_layer_render_to(temp_layer, path, paint_modes); + + mask_using_layer(temp_layer, operation, 0, 0, width, height); + + mask_layer_destroy(temp_layer); +} + +void mask_using_layer(struct vg_mask_layer *layer, + VGMaskOperation operation, + VGint x, VGint y, + VGint width, VGint height) +{ + mask_using_texture(layer->sampler_view, VG_TRUE, operation, + x, y, width, height); +} + +VGint mask_layer_width(struct vg_mask_layer *layer) +{ + return layer->width; +} + +VGint mask_layer_height(struct vg_mask_layer *layer) +{ + return layer->height; +} + + +#endif + +void mask_using_image(struct vg_image *image, + VGMaskOperation operation, + VGint x, VGint y, + VGint width, VGint height) +{ + mask_using_texture(image->sampler_view, VG_FALSE, operation, + x, y, width, height); +} + +void mask_fill(VGint x, VGint y, VGint width, VGint height, + VGfloat value) +{ + struct vg_context *ctx = vg_current_context(); + struct pipe_sampler_view *view = vg_get_surface_mask(ctx); + +#if DEBUG_MASKS + debug_printf("mask_fill(%d, %d, %d, %d) with rgba(%f, %f, %f, %f)\n", + x, y, width, height, + 0.0f, 0.0f, 0.0f, value); +#endif + + mask_resource_fill(view->texture, x, y, width, height, value); +} + +VGint mask_bind_samplers(struct pipe_sampler_state **samplers, + struct pipe_sampler_view **sampler_views) +{ + struct vg_context *ctx = vg_current_context(); + + if (ctx->state.vg.masking) { + samplers[1] = &ctx->mask.sampler; + sampler_views[1] = vg_get_surface_mask(ctx); + return 1; + } else + return 0; +} diff --git a/src/gallium/state_trackers/vega/mask.h b/src/gallium/state_trackers/vega/mask.h new file mode 100644 index 0000000..c626402 --- /dev/null +++ b/src/gallium/state_trackers/vega/mask.h @@ -0,0 +1,68 @@ +/************************************************************************** + * + * 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 MASK_H +#define MASK_H + +#include "vg_context.h" + +struct path; +struct vg_image; +struct pipe_resource; + +struct vg_mask_layer *mask_layer_create(VGint width, VGint height); +void mask_layer_destroy(struct vg_mask_layer *layer); +void mask_layer_fill(struct vg_mask_layer *layer, + VGint x, VGint y, + VGint width, VGint height, + VGfloat value); +VGint mask_layer_width(struct vg_mask_layer *layer); +VGint mask_layer_height(struct vg_mask_layer *layer); +void mask_copy(struct vg_mask_layer *layer, + VGint sx, VGint sy, + VGint dx, VGint dy, + VGint width, VGint height); + +void mask_render_to(struct path *path, + VGbitfield paint_modes, + VGMaskOperation operation); + +void mask_using_layer(struct vg_mask_layer *layer, + VGMaskOperation operation, + VGint x, VGint y, + VGint width, VGint height); +void mask_using_image(struct vg_image *image, + VGMaskOperation operation, + VGint x, VGint y, + VGint width, VGint height); +void mask_fill(VGint x, VGint y, + VGint width, VGint height, + VGfloat value); + +VGint mask_bind_samplers(struct pipe_sampler_state **samplers, + struct pipe_sampler_view **sampler_views); + +#endif diff --git a/src/gallium/state_trackers/vega/matrix.h b/src/gallium/state_trackers/vega/matrix.h new file mode 100644 index 0000000..bed2b31 --- /dev/null +++ b/src/gallium/state_trackers/vega/matrix.h @@ -0,0 +1,462 @@ +/************************************************************************** + * + * 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 MATRIX_H +#define MATRIX_H + +#include "VG/openvg.h" + +#include "pipe/p_compiler.h" +#include "util/u_math.h" + +#include +#include + +#define floatsEqual(x, y) (fabs(x - y) <= 0.00001f * MIN2(fabs(x), fabs(y))) +#define floatIsZero(x) (floatsEqual((x) + 1, 1)) +#define ABS(x) (fabsf(x)) + +#define DEGREES_TO_RADIANS(d) (0.0174532925199 * (d)) +#define FLT_TO_INT(flt) float_to_int_floor(((VGuint*)&(flt))[0]) + +static INLINE VGint float_to_int_floor(VGuint bits) +{ + int sign = (bits >> 31) ? -1 : 1; + int exp = ((bits >> 23) & 255) - 127; + int mant = bits & 0x007fffff; + int sh = 23 - exp; + + /* abs(value) >= 2^31 -> clamp. */ + + if (exp >= 31) + return (VGint)((sign < 0) ? 0x80000000u : 0x7fffffffu); + + /* abs(value) < 1 -> return -1 or 0. */ + + if (exp < 0) + return (sign < 0 && (exp > -127 || mant != 0)) ? -1 : 0; + + /* abs(value) >= 2^23 -> shift left. */ + + mant |= 0x00800000; + if (sh <= 0) + return sign * (mant << -sh); + + /* Negative -> add a rounding term. */ + + if (sign < 0) + mant += (1 << sh) - 1; + + /* Shift right to obtain the result. */ + + return sign * (mant >> sh); +} + + +struct matrix { + VGfloat m[9]; +}; + +static INLINE void matrix_init(struct matrix *mat, + const VGfloat *val) +{ + memcpy(mat->m, val, sizeof(VGfloat) * 9); +} + +static INLINE void matrix_inits(struct matrix *mat, + VGfloat m11, VGfloat m12, VGfloat m13, + VGfloat m21, VGfloat m22, VGfloat m23, + VGfloat m31, VGfloat m32, VGfloat m33) +{ + mat->m[0] = m11; mat->m[1] = m12; mat->m[2] = m13; + mat->m[3] = m21; mat->m[4] = m22; mat->m[5] = m23; + mat->m[6] = m31; mat->m[7] = m32; mat->m[8] = m33; +} + +static INLINE void matrix_load_identity(struct matrix *matrix) +{ + static const VGfloat identity[9] = {1.f, 0.f, 0.f, + 0.f, 1.f, 0.f, + 0.f, 0.f, 1.f}; + memcpy(matrix->m, identity, sizeof(identity)); +} + +static INLINE VGboolean matrix_is_identity(struct matrix *matrix) +{ + return floatsEqual(matrix->m[0], 1) && floatIsZero(matrix->m[1]) && + floatIsZero(matrix->m[2]) && + floatIsZero(matrix->m[3]) && floatsEqual(matrix->m[4], 1) && + floatIsZero(matrix->m[5]) && + floatIsZero(matrix->m[6]) && floatIsZero(matrix->m[7]) && + floatIsZero(matrix->m[8]); +} + +static INLINE VGboolean matrix_is_affine(struct matrix *matrix) +{ + return floatIsZero(matrix->m[2]) && floatIsZero(matrix->m[5]) + && floatsEqual(matrix->m[8], 1); +} + + +static INLINE void matrix_make_affine(struct matrix *matrix) +{ + matrix->m[2] = 0.f; + matrix->m[5] = 0.f; + matrix->m[8] = 1.f; +} + +static INLINE void matrix_mult(struct matrix *dst, + const struct matrix *src) +{ + VGfloat m11 = dst->m[0]*src->m[0] + dst->m[3]*src->m[1] + dst->m[6]*src->m[2]; + VGfloat m12 = dst->m[0]*src->m[3] + dst->m[3]*src->m[4] + dst->m[6]*src->m[5]; + VGfloat m13 = dst->m[0]*src->m[6] + dst->m[3]*src->m[7] + dst->m[6]*src->m[8]; + + VGfloat m21 = dst->m[1]*src->m[0] + dst->m[4]*src->m[1] + dst->m[7]*src->m[2]; + VGfloat m22 = dst->m[1]*src->m[3] + dst->m[4]*src->m[4] + dst->m[7]*src->m[5]; + VGfloat m23 = dst->m[1]*src->m[6] + dst->m[4]*src->m[7] + dst->m[7]*src->m[8]; + + VGfloat m31 = dst->m[2]*src->m[0] + dst->m[5]*src->m[1] + dst->m[8]*src->m[2]; + VGfloat m32 = dst->m[2]*src->m[3] + dst->m[5]*src->m[4] + dst->m[8]*src->m[5]; + VGfloat m33 = dst->m[2]*src->m[6] + dst->m[5]*src->m[7] + dst->m[8]*src->m[8]; + + dst->m[0] = m11; dst->m[1] = m21; dst->m[2] = m31; + dst->m[3] = m12; dst->m[4] = m22; dst->m[5] = m32; + dst->m[6] = m13; dst->m[7] = m23; dst->m[8] = m33; +} + + +static INLINE void matrix_map_point(struct matrix *mat, + VGfloat x, VGfloat y, + VGfloat *out_x, VGfloat *out_y) +{ + /* to be able to do matrix_map_point(m, x, y, &x, &y) use + * temporaries */ + VGfloat tmp_x = x, tmp_y = y; + + *out_x = mat->m[0]*tmp_x + mat->m[3]*tmp_y + mat->m[6]; + *out_y = mat->m[1]*tmp_x + mat->m[4]*tmp_y + mat->m[7]; + if (!matrix_is_affine(mat)) { + VGfloat w = 1/(mat->m[2]*tmp_x + mat->m[5]*tmp_y + mat->m[8]); + *out_x *= w; + *out_y *= w; + } +} + +static INLINE void matrix_translate(struct matrix *dst, + VGfloat tx, VGfloat ty) +{ + if (!matrix_is_affine(dst)) { + struct matrix trans_matrix; + matrix_load_identity(&trans_matrix); + trans_matrix.m[6] = tx; + trans_matrix.m[7] = ty; + matrix_mult(dst, &trans_matrix); + } else { + dst->m[6] += tx*dst->m[0] + ty*dst->m[3]; + dst->m[7] += ty*dst->m[4] + tx*dst->m[1]; + } +} + +static INLINE void matrix_scale(struct matrix *dst, + VGfloat sx, VGfloat sy) +{ + if (!matrix_is_affine(dst)) { + struct matrix scale_matrix; + matrix_load_identity(&scale_matrix); + scale_matrix.m[0] = sx; + scale_matrix.m[4] = sy; + matrix_mult(dst, &scale_matrix); + } else { + dst->m[0] *= sx; dst->m[1] *= sx; + dst->m[3] *= sy; dst->m[4] *= sy; + } +} + +static INLINE void matrix_shear(struct matrix *dst, + VGfloat shx, VGfloat shy) +{ + struct matrix shear_matrix; + matrix_load_identity(&shear_matrix); + shear_matrix.m[1] = shy; + shear_matrix.m[3] = shx; + matrix_mult(dst, &shear_matrix); +} + +static INLINE void matrix_rotate(struct matrix *dst, + VGfloat angle) +{ + struct matrix mat; + float sin_val = 0; + float cos_val = 0; + + + if (floatsEqual(angle, 90) || floatsEqual(angle, -270)) + sin_val = 1.f; + else if (floatsEqual(angle, 270) || floatsEqual(angle, -90)) + sin_val = -1.f; + else if (floatsEqual(angle, 180)) + cos_val = -1.f; + else { + float radians = DEGREES_TO_RADIANS(angle); + sin_val = sin(radians); + cos_val = cos(radians); + } + + if (!matrix_is_affine(dst)) { + matrix_load_identity(&mat); + mat.m[0] = cos_val; mat.m[1] = sin_val; + mat.m[3] = -sin_val; mat.m[4] = cos_val; + + matrix_mult(dst, &mat); + } else { + VGfloat m11 = cos_val*dst->m[0] + sin_val*dst->m[3]; + VGfloat m12 = cos_val*dst->m[1] + sin_val*dst->m[4]; + VGfloat m21 = -sin_val*dst->m[0] + cos_val*dst->m[3]; + VGfloat m22 = -sin_val*dst->m[1] + cos_val*dst->m[4]; + dst->m[0] = m11; dst->m[1] = m12; + dst->m[3] = m21; dst->m[4] = m22; + } +} + + +static INLINE VGfloat matrix_determinant(struct matrix *mat) +{ + return mat->m[0]*(mat->m[8]*mat->m[4]-mat->m[7]*mat->m[5]) - + mat->m[3]*(mat->m[8]*mat->m[1]-mat->m[7]*mat->m[2])+ + mat->m[6]*(mat->m[5]*mat->m[1]-mat->m[4]*mat->m[2]); +} + + +static INLINE void matrix_adjoint(struct matrix *mat) +{ + VGfloat h[9]; + h[0] = mat->m[4]*mat->m[8] - mat->m[5]*mat->m[7]; + h[3] = mat->m[5]*mat->m[6] - mat->m[3]*mat->m[8]; + h[6] = mat->m[3]*mat->m[7] - mat->m[4]*mat->m[6]; + h[1] = mat->m[2]*mat->m[7] - mat->m[1]*mat->m[8]; + h[4] = mat->m[0]*mat->m[8] - mat->m[2]*mat->m[6]; + h[7] = mat->m[1]*mat->m[6] - mat->m[0]*mat->m[7]; + h[2] = mat->m[1]*mat->m[5] - mat->m[2]*mat->m[4]; + h[5] = mat->m[2]*mat->m[3] - mat->m[0]*mat->m[5]; + h[8] = mat->m[0]*mat->m[4] - mat->m[1]*mat->m[3]; + + + memcpy(mat->m, h, sizeof(VGfloat) * 9); +} + +static INLINE void matrix_divs(struct matrix *mat, + VGfloat s) +{ + mat->m[0] /= s; + mat->m[1] /= s; + mat->m[2] /= s; + mat->m[3] /= s; + mat->m[4] /= s; + mat->m[5] /= s; + mat->m[6] /= s; + mat->m[7] /= s; + mat->m[8] /= s; +} + +static INLINE VGboolean matrix_invert(struct matrix *mat) +{ + VGfloat det = matrix_determinant(mat); + + if (floatIsZero(det)) + return VG_FALSE; + + matrix_adjoint(mat); + matrix_divs(mat, det); + return VG_TRUE; +} + +static INLINE VGboolean matrix_is_invertible(struct matrix *mat) +{ + return !floatIsZero(matrix_determinant(mat)); +} + + +static INLINE VGboolean matrix_square_to_quad(VGfloat dx0, VGfloat dy0, + VGfloat dx1, VGfloat dy1, + VGfloat dx3, VGfloat dy3, + VGfloat dx2, VGfloat dy2, + struct matrix *mat) +{ + VGfloat ax = dx0 - dx1 + dx2 - dx3; + VGfloat ay = dy0 - dy1 + dy2 - dy3; + + if (floatIsZero(ax) && floatIsZero(ay)) { + /* affine case */ + matrix_inits(mat, + dx1 - dx0, dy1 - dy0, 0, + dx2 - dx1, dy2 - dy1, 0, + dx0, dy0, 1); + } else { + VGfloat a, b, c, d, e, f, g, h; + VGfloat ax1 = dx1 - dx2; + VGfloat ax2 = dx3 - dx2; + VGfloat ay1 = dy1 - dy2; + VGfloat ay2 = dy3 - dy2; + + /* determinants */ + VGfloat gtop = ax * ay2 - ax2 * ay; + VGfloat htop = ax1 * ay - ax * ay1; + VGfloat bottom = ax1 * ay2 - ax2 * ay1; + + if (!bottom) + return VG_FALSE; + + g = gtop / bottom; + h = htop / bottom; + + a = dx1 - dx0 + g * dx1; + b = dx3 - dx0 + h * dx3; + c = dx0; + d = dy1 - dy0 + g * dy1; + e = dy3 - dy0 + h * dy3; + f = dy0; + + matrix_inits(mat, + a, d, g, + b, e, h, + c, f, 1.f); + } + + return VG_TRUE; +} + +static INLINE VGboolean matrix_quad_to_square(VGfloat sx0, VGfloat sy0, + VGfloat sx1, VGfloat sy1, + VGfloat sx2, VGfloat sy2, + VGfloat sx3, VGfloat sy3, + struct matrix *mat) +{ + if (!matrix_square_to_quad(sx0, sy0, sx1, sy1, + sx2, sy2, sx3, sy3, + mat)) + return VG_FALSE; + + return matrix_invert(mat); +} + + +static INLINE VGboolean matrix_quad_to_quad(VGfloat dx0, VGfloat dy0, + VGfloat dx1, VGfloat dy1, + VGfloat dx2, VGfloat dy2, + VGfloat dx3, VGfloat dy3, + VGfloat sx0, VGfloat sy0, + VGfloat sx1, VGfloat sy1, + VGfloat sx2, VGfloat sy2, + VGfloat sx3, VGfloat sy3, + struct matrix *mat) +{ + struct matrix sqr_to_qd; + + if (!matrix_square_to_quad(dx0, dy0, dx1, dy1, + dx2, dy2, dx3, dy3, + mat)) + return VG_FALSE; + + if (!matrix_quad_to_square(sx0, sy0, sx1, sy1, + sx2, sy2, sx3, sy3, + &sqr_to_qd)) + return VG_FALSE; + + matrix_mult(mat, &sqr_to_qd); + + return VG_TRUE; +} + + +static INLINE VGboolean null_line(const VGfloat *l) +{ + return floatsEqual(l[0], l[2]) && floatsEqual(l[1], l[3]); +} + +static INLINE void line_normal(float *l, float *norm) +{ + norm[0] = l[0]; + norm[1] = l[1]; + + norm[2] = l[0] + (l[3] - l[1]); + norm[3] = l[1] - (l[2] - l[0]); +} + +static INLINE void line_normalize(float *l) +{ + float x = l[2] - l[0]; + float y = l[3] - l[1]; + float len = sqrt(x*x + y*y); + l[2] = l[0] + x/len; + l[3] = l[1] + y/len; +} + +static INLINE VGfloat line_length(VGfloat x1, VGfloat y1, + VGfloat x2, VGfloat y2) +{ + VGfloat x = x2 - x1; + VGfloat y = y2 - y1; + return sqrt(x*x + y*y); +} + +static INLINE VGfloat line_lengthv(const VGfloat *l) +{ + VGfloat x = l[2] - l[0]; + VGfloat y = l[3] - l[1]; + return sqrt(x*x + y*y); +} + + +static INLINE void line_point_at(float *l, float t, float *pt) +{ + float dx = l[2] - l[0]; + float dy = l[3] - l[1]; + + pt[0] = l[0] + dx * t; + pt[1] = l[1] + dy * t; +} + +static INLINE void vector_unit(float *vec) +{ + float len = sqrt(vec[0] * vec[0] + vec[1] * vec[1]); + vec[0] /= len; + vec[1] /= len; +} + +static INLINE void line_normal_vector(float *line, float *vec) +{ + VGfloat normal[4]; + + line_normal(line, normal); + + vec[0] = normal[2] - normal[0]; + vec[1] = normal[3] - normal[1]; + + vector_unit(vec); +} + +#endif diff --git a/src/gallium/state_trackers/vega/paint.c b/src/gallium/state_trackers/vega/paint.c new file mode 100644 index 0000000..2db8cbc --- /dev/null +++ b/src/gallium/state_trackers/vega/paint.c @@ -0,0 +1,750 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "paint.h" + +#include "matrix.h" +#include "image.h" + +#include "pipe/p_compiler.h" +#include "util/u_inlines.h" + +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_sampler.h" + +#include "cso_cache/cso_context.h" + +struct vg_paint { + struct vg_object base; + + VGPaintType type; + + struct { + VGfloat color[4]; + VGint colori[4]; + } solid; + + struct { + VGColorRampSpreadMode spread; + VGuint color_data[1024]; + struct { + VGfloat coords[4]; + VGint coordsi[4]; + } linear; + struct { + VGfloat vals[5]; + VGint valsi[5]; + } radial; + struct pipe_sampler_view *sampler_view; + struct pipe_sampler_state sampler; + + VGfloat *ramp_stops; + VGint *ramp_stopsi; + VGint num_stops; + + VGboolean color_ramps_premultiplied; + } gradient; + + struct { + struct pipe_sampler_view *sampler_view; + VGTilingMode tiling_mode; + struct pipe_sampler_state sampler; + } pattern; + + /* XXX next 3 all unneded? */ + struct pipe_resource *cbuf; + struct pipe_shader_state fs_state; + void *fs; +}; + +static INLINE VGuint mix_pixels(VGuint p1, VGuint a, VGuint p2, VGuint b) +{ + VGuint t = (p1 & 0xff00ff) * a + (p2 & 0xff00ff) * b; + t >>= 8; t &= 0xff00ff; + + p1 = ((p1 >> 8) & 0xff00ff) * a + ((p2 >> 8) & 0xff00ff) * b; + p1 &= 0xff00ff00; p1 |= t; + + return p1; +} + +static INLINE VGuint float4_to_argb(const VGfloat *clr) +{ + return float_to_ubyte(clr[3]) << 24 | + float_to_ubyte(clr[0]) << 16 | + float_to_ubyte(clr[1]) << 8 | + float_to_ubyte(clr[2]) << 0; +} + +static INLINE void create_gradient_data(const VGfloat *ramp_stops, + VGint num, + VGuint *data, + VGint size) +{ + VGint i; + VGint pos = 0; + VGfloat fpos = 0, incr = 1.f / size; + VGuint last_color; + + while (fpos < ramp_stops[0]) { + data[pos] = float4_to_argb(ramp_stops + 1); + fpos += incr; + ++pos; + } + + for (i = 0; i < num - 1; ++i) { + VGint rcur = 5 * i; + VGint rnext = 5 * (i + 1); + VGfloat delta = 1.f/(ramp_stops[rnext] - ramp_stops[rcur]); + while (fpos < ramp_stops[rnext] && pos < size) { + VGint dist = 256 * ((fpos - ramp_stops[rcur]) * delta); + VGint idist = 256 - dist; + VGuint current_color = float4_to_argb(ramp_stops + rcur + 1); + VGuint next_color = float4_to_argb(ramp_stops + rnext + 1); + data[pos] = mix_pixels(current_color, idist, + next_color, dist); + fpos += incr; + ++pos; + } + } + + last_color = float4_to_argb(ramp_stops + ((num - 1) * 5 + 1)); + while (pos < size) { + data[pos] = last_color; + ++pos; + } + data[size-1] = last_color; +} + +static INLINE struct pipe_resource *create_gradient_texture(struct vg_paint *p) +{ + struct pipe_context *pipe = p->base.ctx->pipe; + struct pipe_screen *screen = pipe->screen; + struct pipe_resource *tex = 0; + struct pipe_resource templ; + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_1D; + templ.format = PIPE_FORMAT_B8G8R8A8_UNORM; + templ.last_level = 0; + templ.width0 = 1024; + templ.height0 = 1; + templ.depth0 = 1; + templ.array_size = 1; + templ.bind = PIPE_BIND_SAMPLER_VIEW; + + tex = screen->resource_create(screen, &templ); + + { /* upload color_data */ + struct pipe_transfer *transfer = + pipe_get_transfer(p->base.ctx->pipe, tex, 0, 0, + PIPE_TRANSFER_WRITE, 0, 0, 1024, 1); + void *map = pipe->transfer_map(pipe, transfer); + memcpy(map, p->gradient.color_data, sizeof(VGint)*1024); + pipe->transfer_unmap(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); + } + + return tex; +} + +static INLINE struct pipe_sampler_view *create_gradient_sampler_view(struct vg_paint *p) +{ + struct pipe_context *pipe = p->base.ctx->pipe; + struct pipe_resource *texture; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; + + texture = create_gradient_texture(p); + + if (!texture) + return NULL; + + u_sampler_view_default_template(&view_templ, texture, texture->format); + view = pipe->create_sampler_view(pipe, texture, &view_templ); + /* want the texture to go away if the view is freed */ + pipe_resource_reference(&texture, NULL); + + return view; +} + +struct vg_paint * paint_create(struct vg_context *ctx) +{ + struct vg_paint *paint = CALLOC_STRUCT(vg_paint); + const VGfloat default_color[] = {0.0f, 0.0f, 0.0f, 1.0f}; + const VGfloat def_ling[] = {0.0f, 0.0f, 1.0f, 0.0f}; + const VGfloat def_radg[] = {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; + vg_init_object(&paint->base, ctx, VG_OBJECT_PAINT); + vg_context_add_object(ctx, VG_OBJECT_PAINT, paint); + + paint->type = VG_PAINT_TYPE_COLOR; + memcpy(paint->solid.color, default_color, + 4 * sizeof(VGfloat)); + paint->gradient.spread = VG_COLOR_RAMP_SPREAD_PAD; + memcpy(paint->gradient.linear.coords, def_ling, + 4 * sizeof(VGfloat)); + memcpy(paint->gradient.radial.vals, def_radg, + 5 * sizeof(VGfloat)); + + paint->gradient.sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + paint->gradient.sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + paint->gradient.sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST; + paint->gradient.sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST; + paint->gradient.sampler.normalized_coords = 1; + + memcpy(&paint->pattern.sampler, + &paint->gradient.sampler, + sizeof(struct pipe_sampler_state)); + + return paint; +} + +void paint_destroy(struct vg_paint *paint) +{ + struct vg_context *ctx = paint->base.ctx; + pipe_sampler_view_reference(&paint->gradient.sampler_view, NULL); + if (paint->pattern.sampler_view) + pipe_sampler_view_reference(&paint->pattern.sampler_view, NULL); + if (ctx) + vg_context_remove_object(ctx, VG_OBJECT_PAINT, paint); + + free(paint->gradient.ramp_stopsi); + free(paint->gradient.ramp_stops); + FREE(paint); +} + +void paint_set_color(struct vg_paint *paint, + const VGfloat *color) +{ + paint->solid.color[0] = color[0]; + paint->solid.color[1] = color[1]; + paint->solid.color[2] = color[2]; + paint->solid.color[3] = color[3]; + + paint->solid.colori[0] = FLT_TO_INT(color[0]); + paint->solid.colori[1] = FLT_TO_INT(color[1]); + paint->solid.colori[2] = FLT_TO_INT(color[2]); + paint->solid.colori[3] = FLT_TO_INT(color[3]); +} + +static INLINE void paint_color_buffer(struct vg_paint *paint, void *buffer) +{ + VGfloat *map = (VGfloat*)buffer; + memcpy(buffer, paint->solid.color, 4 * sizeof(VGfloat)); + map[4] = 0.f; + map[5] = 1.f; + map[6] = 2.f; + map[7] = 4.f; +} + +static INLINE void paint_linear_gradient_buffer(struct vg_paint *paint, + const struct matrix *inv, + void *buffer) +{ + VGfloat *map = (VGfloat*)buffer; + VGfloat dd; + + map[0] = paint->gradient.linear.coords[2] - paint->gradient.linear.coords[0]; + map[1] = paint->gradient.linear.coords[3] - paint->gradient.linear.coords[1]; + dd = (map[0] * map[0] + map[1] * map[1]); + + map[2] = (dd > 0.0f) ? 1.f / dd : 0.f; + map[3] = 1.f; + + map[4] = 0.f; + map[5] = 1.f; + map[6] = 2.f; + map[7] = 4.f; + { + struct matrix mat; + matrix_load_identity(&mat); + /* VEGA_LINEAR_GRADIENT_SHADER expects the first point to be at (0, 0) */ + matrix_translate(&mat, -paint->gradient.linear.coords[0], -paint->gradient.linear.coords[1]); + matrix_mult(&mat, inv); + + map[8] = mat.m[0]; map[9] = mat.m[3]; map[10] = mat.m[6]; map[11] = 0.f; + map[12] = mat.m[1]; map[13] = mat.m[4]; map[14] = mat.m[7]; map[15] = 0.f; + map[16] = mat.m[2]; map[17] = mat.m[5]; map[18] = mat.m[8]; map[19] = 0.f; + } +#if 0 + debug_printf("Coords (%f, %f, %f, %f)\n", + map[0], map[1], map[2], map[3]); +#endif +} + + +static INLINE void paint_radial_gradient_buffer(struct vg_paint *paint, + const struct matrix *inv, + void *buffer) +{ + const VGfloat *center = &paint->gradient.radial.vals[0]; + const VGfloat *focal = &paint->gradient.radial.vals[2]; + VGfloat rr = paint->gradient.radial.vals[4]; + VGfloat *map = (VGfloat*)buffer; + VGfloat dd, new_focal[2]; + + rr *= rr; + + map[0] = center[0] - focal[0]; + map[1] = center[1] - focal[1]; + dd = map[0] * map[0] + map[1] * map[1]; + + /* focal point must lie inside the circle */ + if (0.998f * rr < dd) { + VGfloat scale; + + scale = (dd > 0.0f) ? sqrt(0.998f * rr / dd) : 0.0f; + map[0] *= scale; + map[1] *= scale; + + new_focal[0] = center[0] - map[0]; + new_focal[1] = center[1] - map[1]; + dd = map[0] * map[0] + map[1] * map[1]; + focal = new_focal; + } + + map[2] = (rr > dd) ? rr - dd : 1.0f; + map[3] = 1.f; + + map[4] = 0.f; + map[5] = 1.f; + map[6] = 2.f; + map[7] = 4.f; + + { + struct matrix mat; + matrix_load_identity(&mat); + matrix_translate(&mat, -focal[0], -focal[1]); + matrix_mult(&mat, inv); + + map[8] = mat.m[0]; map[9] = mat.m[3]; map[10] = mat.m[6]; map[11] = 0.f; + map[12] = mat.m[1]; map[13] = mat.m[4]; map[14] = mat.m[7]; map[15] = 0.f; + map[16] = mat.m[2]; map[17] = mat.m[5]; map[18] = mat.m[8]; map[19] = 0.f; + } + +#if 0 + debug_printf("Coords (%f, %f, %f, %f)\n", + map[0], map[1], map[2], map[3]); +#endif +} + + +static INLINE void paint_pattern_buffer(struct vg_paint *paint, + const struct matrix *inv, + void *buffer) +{ + VGfloat *map = (VGfloat *)buffer; + memcpy(map, paint->solid.color, 4 * sizeof(VGfloat)); + + map[4] = 0.f; + map[5] = 1.f; + map[6] = paint->pattern.sampler_view->texture->width0; + map[7] = paint->pattern.sampler_view->texture->height0; + { + struct matrix mat; + + memcpy(&mat, inv, sizeof(*inv)); + + map[8] = mat.m[0]; map[9] = mat.m[3]; map[10] = mat.m[6]; map[11] = 0.f; + map[12] = mat.m[1]; map[13] = mat.m[4]; map[14] = mat.m[7]; map[15] = 0.f; + map[16] = mat.m[2]; map[17] = mat.m[5]; map[18] = mat.m[8]; map[19] = 0.f; + } +} + +void paint_set_type(struct vg_paint *paint, VGPaintType type) +{ + paint->type = type; +} + +void paint_set_ramp_stops(struct vg_paint *paint, const VGfloat *stops, + int num) +{ + const VGfloat default_stops[] = {0.0f, 0.0f, 0.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}; + VGint i; + const VGint num_stops = num / 5; + VGfloat last_coord; + + paint->gradient.num_stops = num; + if (num) { + free(paint->gradient.ramp_stops); + paint->gradient.ramp_stops = malloc(sizeof(VGfloat)*num); + memcpy(paint->gradient.ramp_stops, stops, sizeof(VGfloat)*num); + } else + return; + + /* stops must be in increasing order. the last stop is 1.0. if the + * first one is bigger than 1 then the whole sequence is invalid*/ + if (stops[0] > 1) { + stops = default_stops; + num = 10; + } + last_coord = stops[0]; + for (i = 1; i < num_stops; ++i) { + VGint idx = 5 * i; + VGfloat coord = stops[idx]; + if (!floatsEqual(last_coord, coord) && coord < last_coord) { + stops = default_stops; + num = 10; + break; + } + last_coord = coord; + } + + create_gradient_data(stops, num / 5, paint->gradient.color_data, + 1024); + + if (paint->gradient.sampler_view) { + pipe_sampler_view_reference(&paint->gradient.sampler_view, NULL); + paint->gradient.sampler_view = NULL; + } + + paint->gradient.sampler_view = create_gradient_sampler_view(paint); +} + +void paint_set_colori(struct vg_paint *p, + VGuint rgba) +{ + p->solid.color[0] = ((rgba >> 24) & 0xff) / 255.f; + p->solid.color[1] = ((rgba >> 16) & 0xff) / 255.f; + p->solid.color[2] = ((rgba >> 8) & 0xff) / 255.f; + p->solid.color[3] = ((rgba >> 0) & 0xff) / 255.f; +} + +VGuint paint_colori(struct vg_paint *p) +{ +#define F2B(f) (float_to_ubyte(f)) + + return ((F2B(p->solid.color[0]) << 24) | + (F2B(p->solid.color[1]) << 16) | + (F2B(p->solid.color[2]) << 8) | + (F2B(p->solid.color[3]) << 0)); +#undef F2B +} + +void paint_set_linear_gradient(struct vg_paint *paint, + const VGfloat *coords) +{ + memcpy(paint->gradient.linear.coords, coords, sizeof(VGfloat) * 4); +} + +void paint_set_spread_mode(struct vg_paint *paint, + VGint mode) +{ + paint->gradient.spread = mode; + switch(mode) { + case VG_COLOR_RAMP_SPREAD_PAD: + paint->gradient.sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + break; + case VG_COLOR_RAMP_SPREAD_REPEAT: + paint->gradient.sampler.wrap_s = PIPE_TEX_WRAP_REPEAT; + break; + case VG_COLOR_RAMP_SPREAD_REFLECT: + paint->gradient.sampler.wrap_s = PIPE_TEX_WRAP_MIRROR_REPEAT; + break; + } +} + +VGColorRampSpreadMode paint_spread_mode(struct vg_paint *paint) +{ + return paint->gradient.spread; +} + +void paint_set_radial_gradient(struct vg_paint *paint, + const VGfloat *values) +{ + memcpy(paint->gradient.radial.vals, values, sizeof(VGfloat) * 5); +} + +void paint_set_pattern(struct vg_paint *paint, + struct vg_image *img) +{ + if (paint->pattern.sampler_view) + pipe_sampler_view_reference(&paint->pattern.sampler_view, NULL); + + paint->pattern.sampler_view = NULL; + pipe_sampler_view_reference(&paint->pattern.sampler_view, + img->sampler_view); +} + +void paint_set_pattern_tiling(struct vg_paint *paint, + VGTilingMode mode) +{ + paint->pattern.tiling_mode = mode; + + switch(mode) { + case VG_TILE_FILL: + paint->pattern.sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_BORDER; + paint->pattern.sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_BORDER; + break; + case VG_TILE_PAD: + paint->pattern.sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + paint->pattern.sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + break; + case VG_TILE_REPEAT: + paint->pattern.sampler.wrap_s = PIPE_TEX_WRAP_REPEAT; + paint->pattern.sampler.wrap_t = PIPE_TEX_WRAP_REPEAT; + break; + case VG_TILE_REFLECT: + paint->pattern.sampler.wrap_s = PIPE_TEX_WRAP_MIRROR_REPEAT; + paint->pattern.sampler.wrap_t = PIPE_TEX_WRAP_MIRROR_REPEAT; + break; + default: + debug_assert("!Unknown tiling mode"); + } +} + +void paint_get_color(struct vg_paint *paint, + VGfloat *color) +{ + color[0] = paint->solid.color[0]; + color[1] = paint->solid.color[1]; + color[2] = paint->solid.color[2]; + color[3] = paint->solid.color[3]; +} + +void paint_ramp_stops(struct vg_paint *paint, VGfloat *stops, + int num) +{ + memcpy(stops, paint->gradient.ramp_stops, sizeof(VGfloat)*num); +} + +void paint_linear_gradient(struct vg_paint *paint, + VGfloat *coords) +{ + memcpy(coords, paint->gradient.linear.coords, sizeof(VGfloat)*4); +} + +void paint_radial_gradient(struct vg_paint *paint, + VGfloat *coords) +{ + memcpy(coords, paint->gradient.radial.vals, sizeof(VGfloat)*5); +} + +int paint_num_ramp_stops(struct vg_paint *paint) +{ + return paint->gradient.num_stops; +} + +VGPaintType paint_type(struct vg_paint *paint) +{ + return paint->type; +} + +void paint_set_coloriv(struct vg_paint *paint, + const VGint *color) +{ + paint->solid.color[0] = color[0]; + paint->solid.color[1] = color[1]; + paint->solid.color[2] = color[2]; + paint->solid.color[3] = color[3]; + + paint->solid.colori[0] = color[0]; + paint->solid.colori[1] = color[1]; + paint->solid.colori[2] = color[2]; + paint->solid.colori[3] = color[3]; +} + +void paint_get_coloriv(struct vg_paint *paint, + VGint *color) +{ + color[0] = paint->solid.colori[0]; + color[1] = paint->solid.colori[1]; + color[2] = paint->solid.colori[2]; + color[3] = paint->solid.colori[3]; +} + +void paint_set_color_ramp_premultiplied(struct vg_paint *paint, + VGboolean set) +{ + paint->gradient.color_ramps_premultiplied = set; +} + +VGboolean paint_color_ramp_premultiplied(struct vg_paint *paint) +{ + return paint->gradient.color_ramps_premultiplied; +} + +void paint_set_ramp_stopsi(struct vg_paint *paint, const VGint *stops, + int num) +{ + if (num) { + free(paint->gradient.ramp_stopsi); + paint->gradient.ramp_stopsi = malloc(sizeof(VGint)*num); + memcpy(paint->gradient.ramp_stopsi, stops, sizeof(VGint)*num); + } +} + +void paint_ramp_stopsi(struct vg_paint *paint, VGint *stops, + int num) +{ + memcpy(stops, paint->gradient.ramp_stopsi, sizeof(VGint)*num); +} + +void paint_set_linear_gradienti(struct vg_paint *paint, + const VGint *coords) +{ + memcpy(paint->gradient.linear.coordsi, coords, sizeof(VGint) * 4); +} + +void paint_linear_gradienti(struct vg_paint *paint, + VGint *coords) +{ + memcpy(coords, paint->gradient.linear.coordsi, sizeof(VGint)*4); +} + +void paint_set_radial_gradienti(struct vg_paint *paint, + const VGint *values) +{ + memcpy(paint->gradient.radial.valsi, values, sizeof(VGint) * 5); +} + +void paint_radial_gradienti(struct vg_paint *paint, + VGint *coords) +{ + memcpy(coords, paint->gradient.radial.valsi, sizeof(VGint)*5); +} + +VGTilingMode paint_pattern_tiling(struct vg_paint *paint) +{ + return paint->pattern.tiling_mode; +} + +VGint paint_bind_samplers(struct vg_paint *paint, struct pipe_sampler_state **samplers, + struct pipe_sampler_view **sampler_views) +{ + struct vg_context *ctx = vg_current_context(); + + switch(paint->type) { + case VG_PAINT_TYPE_LINEAR_GRADIENT: + case VG_PAINT_TYPE_RADIAL_GRADIENT: { + if (paint->gradient.sampler_view) { + paint->gradient.sampler.min_img_filter = image_sampler_filter(ctx); + paint->gradient.sampler.mag_img_filter = image_sampler_filter(ctx); + samplers[0] = &paint->gradient.sampler; + sampler_views[0] = paint->gradient.sampler_view; + return 1; + } + } + break; + case VG_PAINT_TYPE_PATTERN: { + memcpy(paint->pattern.sampler.border_color, + ctx->state.vg.tile_fill_color, + sizeof(VGfloat) * 4); + paint->pattern.sampler.min_img_filter = image_sampler_filter(ctx); + paint->pattern.sampler.mag_img_filter = image_sampler_filter(ctx); + samplers[0] = &paint->pattern.sampler; + sampler_views[0] = paint->pattern.sampler_view; + return 1; + } + break; + default: + break; + } + return 0; +} + +void paint_resolve_type(struct vg_paint *paint) +{ + if (paint->type == VG_PAINT_TYPE_PATTERN && + !paint->pattern.sampler_view) { + paint->type = VG_PAINT_TYPE_COLOR; + } +} + +VGboolean paint_is_degenerate(struct vg_paint *paint) +{ + VGboolean degen; + VGfloat *vals; + + + switch (paint->type) { + case VG_PAINT_TYPE_LINEAR_GRADIENT: + vals = paint->gradient.linear.coords; + /* two points are coincident */ + degen = (floatsEqual(vals[0], vals[2]) && + floatsEqual(vals[1], vals[3])); + break; + case VG_PAINT_TYPE_RADIAL_GRADIENT: + vals = paint->gradient.radial.vals; + /* radius <= 0 */ + degen = (vals[4] <= 0.0f); + break; + case VG_PAINT_TYPE_COLOR: + case VG_PAINT_TYPE_PATTERN: + default: + degen = VG_FALSE; + break; + } + + return degen; +} + +VGint paint_constant_buffer_size(struct vg_paint *paint) +{ + switch(paint->type) { + case VG_PAINT_TYPE_COLOR: + return 8 * sizeof(VGfloat);/*4 color + 4 constants (0.f,1.f,2.f,4.f)*/ + break; + case VG_PAINT_TYPE_LINEAR_GRADIENT: + return 20 * sizeof(VGfloat); + break; + case VG_PAINT_TYPE_RADIAL_GRADIENT: + return 20 * sizeof(VGfloat); + break; + case VG_PAINT_TYPE_PATTERN: + return 20 * sizeof(VGfloat); + break; + default: + debug_printf("Uknown paint type: %d\n", paint->type); + } + + return 0; +} + +void paint_fill_constant_buffer(struct vg_paint *paint, + const struct matrix *mat, + void *buffer) +{ + switch(paint->type) { + case VG_PAINT_TYPE_COLOR: + paint_color_buffer(paint, buffer); + break; + case VG_PAINT_TYPE_LINEAR_GRADIENT: + paint_linear_gradient_buffer(paint, mat, buffer); + break; + case VG_PAINT_TYPE_RADIAL_GRADIENT: + paint_radial_gradient_buffer(paint, mat, buffer); + break; + case VG_PAINT_TYPE_PATTERN: + paint_pattern_buffer(paint, mat, buffer); + break; + + default: + abort(); + } +} diff --git a/src/gallium/state_trackers/vega/paint.h b/src/gallium/state_trackers/vega/paint.h new file mode 100644 index 0000000..3de3bbe --- /dev/null +++ b/src/gallium/state_trackers/vega/paint.h @@ -0,0 +1,122 @@ +/************************************************************************** + * + * 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 PAINT_H +#define PAINT_H + +#include "vg_context.h" + +#include "VG/openvg.h" +#include "pipe/p_state.h" + +struct vg_paint; +struct vg_image; +struct pipe_sampler_state; +struct pipe_resource; + +struct vg_paint *paint_create(struct vg_context *ctx); +void paint_destroy(struct vg_paint *paint); + +void paint_set_color(struct vg_paint *paint, + const VGfloat *color); +void paint_get_color(struct vg_paint *paint, + VGfloat *color); + +void paint_set_coloriv(struct vg_paint *paint, + const VGint *color); +void paint_get_coloriv(struct vg_paint *paint, + VGint *color); + +void paint_set_colori(struct vg_paint *paint, + VGuint rgba); + +VGuint paint_colori(struct vg_paint *paint); + +void paint_set_type(struct vg_paint *paint, VGPaintType type); +VGPaintType paint_type(struct vg_paint *paint); +void paint_resolve_type(struct vg_paint *paint); + +void paint_set_linear_gradient(struct vg_paint *paint, + const VGfloat *coords); +void paint_linear_gradient(struct vg_paint *paint, + VGfloat *coords); +void paint_set_linear_gradienti(struct vg_paint *paint, + const VGint *coords); +void paint_linear_gradienti(struct vg_paint *paint, + VGint *coords); + + +void paint_set_radial_gradient(struct vg_paint *paint, + const VGfloat *values); +void paint_radial_gradient(struct vg_paint *paint, + VGfloat *coords); +void paint_set_radial_gradienti(struct vg_paint *paint, + const VGint *values); +void paint_radial_gradienti(struct vg_paint *paint, + VGint *coords); + + +void paint_set_ramp_stops(struct vg_paint *paint, const VGfloat *stops, + int num); +void paint_ramp_stops(struct vg_paint *paint, VGfloat *stops, + int num); + +void paint_set_ramp_stopsi(struct vg_paint *paint, const VGint *stops, + int num); +void paint_ramp_stopsi(struct vg_paint *paint, VGint *stops, + int num); + +int paint_num_ramp_stops(struct vg_paint *paint); + +void paint_set_spread_mode(struct vg_paint *paint, + VGint mode); +VGColorRampSpreadMode paint_spread_mode(struct vg_paint *paint); + + +void paint_set_pattern(struct vg_paint *paint, + struct vg_image *img); +void paint_set_pattern_tiling(struct vg_paint *paint, + VGTilingMode mode); +VGTilingMode paint_pattern_tiling(struct vg_paint *paint); + +void paint_set_color_ramp_premultiplied(struct vg_paint *paint, + VGboolean set); +VGboolean paint_color_ramp_premultiplied(struct vg_paint *paint); + + +VGint paint_bind_samplers(struct vg_paint *paint, struct pipe_sampler_state **samplers, + struct pipe_sampler_view **sampler_views); + +VGboolean paint_is_degenerate(struct vg_paint *paint); + +VGint paint_constant_buffer_size(struct vg_paint *paint); + +void paint_fill_constant_buffer(struct vg_paint *paint, + const struct matrix *mat, + void *buffer); + + +#endif diff --git a/src/gallium/state_trackers/vega/path.c b/src/gallium/state_trackers/vega/path.c new file mode 100644 index 0000000..d7253be --- /dev/null +++ b/src/gallium/state_trackers/vega/path.c @@ -0,0 +1,2074 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "path.h" + +#include "stroker.h" +#include "polygon.h" +#include "bezier.h" +#include "matrix.h" +#include "vg_context.h" +#include "util_array.h" +#include "arc.h" +#include "path_utils.h" +#include "paint.h" +#include "shader.h" + +#include "util/u_memory.h" + +#include + +#define DEBUG_PATH 0 + +struct path { + struct vg_object base; + VGbitfield caps; + VGboolean dirty; + VGboolean dirty_stroke; + + VGPathDatatype datatype; + + VGfloat scale; + VGfloat bias; + + VGint num_segments; + + struct array * segments; + struct array * control_points; + + struct { + struct polygon_array polygon_array; + struct matrix matrix; + } fill_polys; + + struct { + struct path *path; + struct matrix matrix; + VGfloat stroke_width; + VGfloat miter_limit; + VGCapStyle cap_style; + VGJoinStyle join_style; + } stroked; +}; + + +static INLINE void data_at(void **data, + struct path *p, + VGint start, VGint count, + VGfloat *out) +{ + VGPathDatatype dt = p->datatype; + VGint i; + VGint end = start + count; + VGfloat *itr = out; + + switch(dt) { + case VG_PATH_DATATYPE_S_8: { + VGbyte **bdata = (VGbyte **)data; + for (i = start; i < end; ++i) { + *itr = (*bdata)[i]; + ++itr; + } + *bdata += count; + } + break; + case VG_PATH_DATATYPE_S_16: { + VGshort **bdata = (VGshort **)data; + for (i = start; i < end; ++i) { + *itr = (*bdata)[i]; + ++itr; + } + *bdata += count; + } + break; + case VG_PATH_DATATYPE_S_32: { + VGint **bdata = (VGint **)data; + for (i = start; i < end; ++i) { + *itr = (*bdata)[i]; + ++itr; + } + *bdata += count; + } + break; + case VG_PATH_DATATYPE_F: { + VGfloat **fdata = (VGfloat **)data; + for (i = start; i < end; ++i) { + *itr = (*fdata)[i]; + ++itr; + } + *fdata += count; + } + break; + default: + debug_assert(!"Unknown path datatype!"); + } +} + + +void vg_float_to_datatype(VGPathDatatype datatype, + VGubyte *common_data, + const VGfloat *data, + VGint num_coords) +{ + VGint i; + switch(datatype) { + case VG_PATH_DATATYPE_S_8: { + for (i = 0; i < num_coords; ++i) { + common_data[i] = (VGubyte)data[i]; + } + } + break; + case VG_PATH_DATATYPE_S_16: { + VGshort *buf = (VGshort*)common_data; + for (i = 0; i < num_coords; ++i) { + buf[i] = (VGshort)data[i]; + } + } + break; + case VG_PATH_DATATYPE_S_32: { + VGint *buf = (VGint*)common_data; + for (i = 0; i < num_coords; ++i) { + buf[i] = (VGint)data[i]; + } + } + break; + case VG_PATH_DATATYPE_F: { + memcpy(common_data, data, sizeof(VGfloat) * num_coords); + } + break; + default: + debug_assert(!"Unknown path datatype!"); + } +} + +static void coords_adjust_by_scale_bias(struct path *p, + void *pdata, VGint num_coords, + VGfloat scale, VGfloat bias, + VGPathDatatype datatype) +{ + VGfloat data[8]; + void *coords = (VGfloat *)pdata; + VGubyte *common_data = (VGubyte *)pdata; + VGint size_dst = size_for_datatype(datatype); + VGint i; + + for (i = 0; i < num_coords; ++i) { + data_at(&coords, p, 0, 1, data); + data[0] = data[0] * scale + bias; + vg_float_to_datatype(datatype, common_data, data, 1); + common_data += size_dst; + } +} + +struct path * path_create(VGPathDatatype dt, VGfloat scale, VGfloat bias, + VGint segmentCapacityHint, + VGint coordCapacityHint, + VGbitfield capabilities) +{ + struct path *path = CALLOC_STRUCT(path); + + vg_init_object(&path->base, vg_current_context(), VG_OBJECT_PATH); + path->caps = capabilities & VG_PATH_CAPABILITY_ALL; + vg_context_add_object(vg_current_context(), VG_OBJECT_PATH, path); + + path->datatype = dt; + path->scale = scale; + path->bias = bias; + + path->segments = array_create(size_for_datatype(VG_PATH_DATATYPE_S_8)); + path->control_points = array_create(size_for_datatype(dt)); + + path->dirty = VG_TRUE; + path->dirty_stroke = VG_TRUE; + + return path; +} + +static void polygon_array_cleanup(struct polygon_array *polyarray) +{ + if (polyarray->array) { + VGint i; + + for (i = 0; i < polyarray->array->num_elements; i++) { + struct polygon *p = ((struct polygon **) polyarray->array->data)[i]; + polygon_destroy(p); + } + + array_destroy(polyarray->array); + polyarray->array = NULL; + } +} + +void path_destroy(struct path *p) +{ + vg_context_remove_object(vg_current_context(), VG_OBJECT_PATH, p); + + array_destroy(p->segments); + array_destroy(p->control_points); + + polygon_array_cleanup(&p->fill_polys.polygon_array); + + if (p->stroked.path) + path_destroy(p->stroked.path); + + FREE(p); +} + +VGbitfield path_capabilities(struct path *p) +{ + return p->caps; +} + +void path_set_capabilities(struct path *p, VGbitfield bf) +{ + p->caps = (bf & VG_PATH_CAPABILITY_ALL); +} + +void path_append_data(struct path *p, + VGint numSegments, + const VGubyte * pathSegments, + const void * pathData) +{ + VGint old_segments = p->num_segments; + VGint num_new_coords = num_elements_for_segments(pathSegments, numSegments); + array_append_data(p->segments, pathSegments, numSegments); + array_append_data(p->control_points, pathData, num_new_coords); + + p->num_segments += numSegments; + if (!floatsEqual(p->scale, 1.f) || !floatsEqual(p->bias, 0.f)) { + VGubyte *coords = (VGubyte*)p->control_points->data; + coords_adjust_by_scale_bias(p, + coords + old_segments * p->control_points->datatype_size, + num_new_coords, + p->scale, p->bias, p->datatype); + } + p->dirty = VG_TRUE; + p->dirty_stroke = VG_TRUE; +} + +VGint path_num_segments(struct path *p) +{ + return p->num_segments; +} + +static INLINE void map_if_relative(VGfloat ox, VGfloat oy, + VGboolean relative, + VGfloat *x, VGfloat *y) +{ + if (relative) { + if (x) + *x += ox; + if (y) + *y += oy; + } +} + +static INLINE void close_polygon(struct polygon *current, + VGfloat sx, VGfloat sy, + VGfloat ox, VGfloat oy, + struct matrix *matrix) +{ + if (!floatsEqual(sx, ox) || + !floatsEqual(sy, oy)) { + VGfloat x0 = sx; + VGfloat y0 = sy; + matrix_map_point(matrix, x0, y0, &x0, &y0); + polygon_vertex_append(current, x0, y0); + } +} + +static void convert_path(struct path *p, + VGPathDatatype to, + void *dst, + VGint num_coords) +{ + VGfloat data[8]; + void *coords = (VGfloat *)p->control_points->data; + VGubyte *common_data = (VGubyte *)dst; + VGint size_dst = size_for_datatype(to); + VGint i; + + for (i = 0; i < num_coords; ++i) { + data_at(&coords, p, 0, 1, data); + vg_float_to_datatype(to, common_data, data, 1); + common_data += size_dst; + } +} + +static void polygon_array_calculate_bounds( struct polygon_array *polyarray ) +{ + struct array *polys = polyarray->array; + VGfloat min_x, max_x; + VGfloat min_y, max_y; + VGfloat bounds[4]; + unsigned i; + + assert(polys); + + if (!polys->num_elements) { + polyarray->min_x = 0.0f; + polyarray->min_y = 0.0f; + polyarray->max_x = 0.0f; + polyarray->max_y = 0.0f; + return; + } + + polygon_bounding_rect((((struct polygon**)polys->data)[0]), bounds); + min_x = bounds[0]; + min_y = bounds[1]; + max_x = bounds[0] + bounds[2]; + max_y = bounds[1] + bounds[3]; + for (i = 1; i < polys->num_elements; ++i) { + struct polygon *p = (((struct polygon**)polys->data)[i]); + polygon_bounding_rect(p, bounds); + min_x = MIN2(min_x, bounds[0]); + min_y = MIN2(min_y, bounds[1]); + max_x = MAX2(max_x, bounds[0] + bounds[2]); + max_y = MAX2(max_y, bounds[1] + bounds[3]); + } + + polyarray->min_x = min_x; + polyarray->min_y = min_y; + polyarray->max_x = max_x; + polyarray->max_y = max_y; +} + + +static struct polygon_array * path_get_fill_polygons(struct path *p, struct matrix *matrix) +{ + VGint i; + struct polygon *current = 0; + VGfloat sx, sy, px, py, ox, oy; + VGfloat x0, y0, x1, y1, x2, y2, x3, y3; + VGfloat data[8]; + void *coords = (VGfloat *)p->control_points->data; + struct array *array; + + if (p->fill_polys.polygon_array.array) + { + if (memcmp( &p->fill_polys.matrix, + matrix, + sizeof *matrix ) == 0 && p->dirty == VG_FALSE) + { + return &p->fill_polys.polygon_array; + } + else { + polygon_array_cleanup(&p->fill_polys.polygon_array); + } + } + + /* an array of pointers to polygons */ + array = array_create(sizeof(struct polygon *)); + + sx = sy = px = py = ox = oy = 0.f; + + if (p->num_segments) + current = polygon_create(32); + + for (i = 0; i < p->num_segments; ++i) { + VGubyte segment = ((VGubyte*)(p->segments->data))[i]; + VGint command = SEGMENT_COMMAND(segment); + VGboolean relative = SEGMENT_ABS_REL(segment); + + switch(command) { + case VG_CLOSE_PATH: + close_polygon(current, sx, sy, ox, oy, matrix); + ox = sx; + oy = sy; + break; + case VG_MOVE_TO: + if (current && polygon_vertex_count(current) > 0) { + /* add polygon */ + close_polygon(current, sx, sy, ox, oy, matrix); + array_append_data(array, ¤t, 1); + current = polygon_create(32); + } + data_at(&coords, p, 0, 2, data); + x0 = data[0]; + y0 = data[1]; + map_if_relative(ox, oy, relative, &x0, &y0); + sx = x0; + sy = y0; + ox = x0; + oy = y0; + px = x0; + py = y0; + matrix_map_point(matrix, x0, y0, &x0, &y0); + polygon_vertex_append(current, x0, y0); + break; + case VG_LINE_TO: + data_at(&coords, p, 0, 2, data); + x0 = data[0]; + y0 = data[1]; + map_if_relative(ox, oy, relative, &x0, &y0); + ox = x0; + oy = y0; + px = x0; + py = y0; + matrix_map_point(matrix, x0, y0, &x0, &y0); + polygon_vertex_append(current, x0, y0); + break; + case VG_HLINE_TO: + data_at(&coords, p, 0, 1, data); + x0 = data[0]; + y0 = oy; + map_if_relative(ox, oy, relative, &x0, 0); + ox = x0; + px = x0; + py = y0; + matrix_map_point(matrix, x0, y0, &x0, &y0); + polygon_vertex_append(current, x0, y0); + break; + case VG_VLINE_TO: + data_at(&coords, p, 0, 1, data); + x0 = ox; + y0 = data[0]; + map_if_relative(ox, oy, relative, 0, &y0); + oy = y0; + px = x0; + py = y0; + matrix_map_point(matrix, x0, y0, &x0, &y0); + polygon_vertex_append(current, x0, y0); + break; + case VG_CUBIC_TO: { + struct bezier bezier; + data_at(&coords, p, 0, 6, data); + x0 = ox; + y0 = oy; + x1 = data[0]; + y1 = data[1]; + x2 = data[2]; + y2 = data[3]; + x3 = data[4]; + y3 = data[5]; + map_if_relative(ox, oy, relative, &x1, &y1); + map_if_relative(ox, oy, relative, &x2, &y2); + map_if_relative(ox, oy, relative, &x3, &y3); + ox = x3; + oy = y3; + px = x2; + py = y2; + assert(matrix_is_affine(matrix)); + matrix_map_point(matrix, x0, y0, &x0, &y0); + matrix_map_point(matrix, x1, y1, &x1, &y1); + matrix_map_point(matrix, x2, y2, &x2, &y2); + matrix_map_point(matrix, x3, y3, &x3, &y3); + bezier_init(&bezier, x0, y0, x1, y1, + x2, y2, x3, y3); + bezier_add_to_polygon(&bezier, current); + } + break; + case VG_QUAD_TO: { + struct bezier bezier; + data_at(&coords, p, 0, 4, data); + x0 = ox; + y0 = oy; + x1 = data[0]; + y1 = data[1]; + x3 = data[2]; + y3 = data[3]; + map_if_relative(ox, oy, relative, &x1, &y1); + map_if_relative(ox, oy, relative, &x3, &y3); + px = x1; + py = y1; + { /* form a cubic out of it */ + x2 = (x3 + 2*x1) / 3.f; + y2 = (y3 + 2*y1) / 3.f; + x1 = (x0 + 2*x1) / 3.f; + y1 = (y0 + 2*y1) / 3.f; + } + ox = x3; + oy = y3; + assert(matrix_is_affine(matrix)); + matrix_map_point(matrix, x0, y0, &x0, &y0); + matrix_map_point(matrix, x1, y1, &x1, &y1); + matrix_map_point(matrix, x2, y2, &x2, &y2); + matrix_map_point(matrix, x3, y3, &x3, &y3); + bezier_init(&bezier, x0, y0, x1, y1, + x2, y2, x3, y3); + bezier_add_to_polygon(&bezier, current); + } + break; + case VG_SQUAD_TO: { + struct bezier bezier; + data_at(&coords, p, 0, 2, data); + x0 = ox; + y0 = oy; + x1 = 2*ox-px; + y1 = 2*oy-py; + x3 = data[0]; + y3 = data[1]; + map_if_relative(ox, oy, relative, &x3, &y3); + px = x1; + py = y1; + { /* form a cubic out of it */ + x2 = (x3 + 2*x1) / 3.f; + y2 = (y3 + 2*y1) / 3.f; + x1 = (x0 + 2*x1) / 3.f; + y1 = (y0 + 2*y1) / 3.f; + } + ox = x3; + oy = y3; + assert(matrix_is_affine(matrix)); + matrix_map_point(matrix, x0, y0, &x0, &y0); + matrix_map_point(matrix, x1, y1, &x1, &y1); + matrix_map_point(matrix, x2, y2, &x2, &y2); + matrix_map_point(matrix, x3, y3, &x3, &y3); + bezier_init(&bezier, x0, y0, x1, y1, + x2, y2, x3, y3); + bezier_add_to_polygon(&bezier, current); + } + break; + case VG_SCUBIC_TO: { + struct bezier bezier; + data_at(&coords, p, 0, 4, data); + x0 = ox; + y0 = oy; + x1 = 2*ox-px; + y1 = 2*oy-py; + x2 = data[0]; + y2 = data[1]; + x3 = data[2]; + y3 = data[3]; + map_if_relative(ox, oy, relative, &x2, &y2); + map_if_relative(ox, oy, relative, &x3, &y3); + ox = x3; + oy = y3; + px = x2; + py = y2; + assert(matrix_is_affine(matrix)); + matrix_map_point(matrix, x0, y0, &x0, &y0); + matrix_map_point(matrix, x1, y1, &x1, &y1); + matrix_map_point(matrix, x2, y2, &x2, &y2); + matrix_map_point(matrix, x3, y3, &x3, &y3); + bezier_init(&bezier, x0, y0, x1, y1, + x2, y2, x3, y3); + bezier_add_to_polygon(&bezier, current); + } + break; + case VG_SCCWARC_TO: + case VG_SCWARC_TO: + case VG_LCCWARC_TO: + case VG_LCWARC_TO: { + VGfloat rh, rv, rot; + struct arc arc; + + data_at(&coords, p, 0, 5, data); + x0 = ox; + y0 = oy; + rh = data[0]; + rv = data[1]; + rot = data[2]; + x1 = data[3]; + y1 = data[4]; + map_if_relative(ox, oy, relative, &x1, &y1); +#if 0 + debug_printf("------- ARC (%f, %f), (%f, %f) %f, %f, %f\n", + x0, y0, x1, y1, rh, rv, rot); +#endif + arc_init(&arc, command, x0, y0, x1, y1, + rh, rv, rot); + arc_add_to_polygon(&arc, current, + matrix); + ox = x1; + oy = y1; + px = x1; + py = y1; + } + break; + default: + abort(); + assert(!"Unknown segment!"); + } + } + if (current) { + if (polygon_vertex_count(current) > 0) { + close_polygon(current, sx, sy, ox, oy, matrix); + array_append_data(array, ¤t, 1); + } else + polygon_destroy(current); + } + + p->fill_polys.polygon_array.array = array; + p->fill_polys.matrix = *matrix; + + polygon_array_calculate_bounds( &p->fill_polys.polygon_array ); + + p->dirty = VG_FALSE; + + return &p->fill_polys.polygon_array; +} + +VGbyte path_datatype_size(struct path *p) +{ + return size_for_datatype(p->datatype); +} + +VGPathDatatype path_datatype(struct path *p) +{ + return p->datatype; +} + +VGfloat path_scale(struct path *p) +{ + return p->scale; +} + +VGfloat path_bias(struct path *p) +{ + return p->bias; +} + +VGint path_num_coords(struct path *p) +{ + return num_elements_for_segments((VGubyte*)p->segments->data, + p->num_segments); +} + +void path_modify_coords(struct path *p, + VGint startIndex, + VGint numSegments, + const void * pathData) +{ + VGubyte *segments = (VGubyte*)(p->segments->data); + VGint count = num_elements_for_segments(&segments[startIndex], numSegments); + VGint start_cp = num_elements_for_segments(segments, startIndex); + + array_change_data(p->control_points, pathData, start_cp, count); + coords_adjust_by_scale_bias(p, + ((VGubyte*)p->control_points->data) + + (startIndex * p->control_points->datatype_size), + path_num_coords(p), + p->scale, p->bias, p->datatype); + p->dirty = VG_TRUE; + p->dirty_stroke = VG_TRUE; +} + +void path_for_each_segment(struct path *path, + path_for_each_cb cb, + void *user_data) +{ + VGint i; + struct path_for_each_data p; + VGfloat data[8]; + void *coords = (VGfloat *)path->control_points->data; + + p.coords = data; + p.sx = p.sy = p.px = p.py = p.ox = p.oy = 0.f; + p.user_data = user_data; + + for (i = 0; i < path->num_segments; ++i) { + VGint command; + VGboolean relative; + + p.segment = ((VGubyte*)(path->segments->data))[i]; + command = SEGMENT_COMMAND(p.segment); + relative = SEGMENT_ABS_REL(p.segment); + + switch(command) { + case VG_CLOSE_PATH: + cb(path, &p); + break; + case VG_MOVE_TO: + data_at(&coords, path, 0, 2, data); + map_if_relative(p.ox, p.oy, relative, &data[0], &data[1]); + cb(path, &p); + p.sx = data[0]; + p.sy = data[1]; + p.ox = data[0]; + p.oy = data[1]; + p.px = data[0]; + p.py = data[1]; + break; + case VG_LINE_TO: + data_at(&coords, path, 0, 2, data); + map_if_relative(p.ox, p.oy, relative, &data[0], &data[1]); + cb(path, &p); + p.ox = data[0]; + p.oy = data[1]; + p.px = data[0]; + p.py = data[1]; + break; + case VG_HLINE_TO: + data_at(&coords, path, 0, 1, data); + map_if_relative(p.ox, p.oy, relative, &data[0], 0); + p.segment = VG_LINE_TO; + data[1] = p.oy; + cb(path, &p); + p.ox = data[0]; + p.oy = data[1]; + p.px = data[0]; + p.py = data[1]; + break; + case VG_VLINE_TO: + data_at(&coords, path, 0, 1, data); + map_if_relative(p.ox, p.oy, relative, 0, &data[0]); + p.segment = VG_LINE_TO; + data[1] = data[0]; + data[0] = p.ox; + cb(path, &p); + p.ox = data[0]; + p.oy = data[1]; + p.px = data[0]; + p.py = data[1]; + break; + case VG_CUBIC_TO: { + data_at(&coords, path, 0, 6, data); + map_if_relative(p.ox, p.oy, relative, &data[0], &data[1]); + map_if_relative(p.ox, p.oy, relative, &data[2], &data[3]); + map_if_relative(p.ox, p.oy, relative, &data[4], &data[5]); + cb(path, &p); + p.px = data[2]; + p.py = data[3]; + p.ox = data[4]; + p.oy = data[5]; + } + break; + case VG_QUAD_TO: { + data_at(&coords, path, 0, 4, data); + map_if_relative(p.ox, p.oy, relative, &data[0], &data[1]); + map_if_relative(p.ox, p.oy, relative, &data[2], &data[3]); + cb(path, &p); + p.px = data[0]; + p.py = data[1]; + p.ox = data[2]; + p.oy = data[3]; + } + break; + case VG_SQUAD_TO: { + data_at(&coords, path, 0, 2, data); + map_if_relative(p.ox, p.oy, relative, &data[0], &data[1]); + cb(path, &p); + p.px = 2*p.ox-p.px; + p.py = 2*p.oy-p.py; + p.ox = data[2]; + p.oy = data[3]; + } + break; + case VG_SCUBIC_TO: { + data_at(&coords, path, 0, 4, data); + map_if_relative(p.ox, p.oy, relative, &data[0], &data[1]); + map_if_relative(p.ox, p.oy, relative, &data[2], &data[3]); + cb(path, &p); + p.px = data[0]; + p.py = data[1]; + p.ox = data[2]; + p.oy = data[3]; + } + break; + case VG_SCCWARC_TO: + case VG_SCWARC_TO: + case VG_LCCWARC_TO: + case VG_LCWARC_TO: { + data_at(&coords, path, 0, 5, data); + map_if_relative(p.ox, p.oy, relative, &data[3], &data[4]); +#if 0 + debug_printf("------- ARC (%f, %f), (%f, %f) %f, %f, %f\n", + p.ox, p.oy, data[3], data[4], data[0], data[1], data[2]); +#endif + cb(path, &p); + p.ox = data[3]; + p.oy = data[4]; + p.px = data[3]; + p.py = data[4]; + } + break; + default: + abort(); + assert(!"Unknown segment!"); + } + } +} + +struct transform_data { + struct array *segments; + struct array *coords; + + struct matrix *matrix; + + VGPathDatatype datatype; +}; + +static VGboolean transform_cb(struct path *p, + struct path_for_each_data *pd) +{ + struct transform_data *td = (struct transform_data *)pd->user_data; + VGint num_coords = num_elements_for_segments(&pd->segment, 1); + VGubyte segment = SEGMENT_COMMAND(pd->segment);/* abs bit is 0 */ + VGfloat data[8]; + VGubyte common_data[sizeof(VGfloat)*8]; + + memcpy(data, pd->coords, sizeof(VGfloat) * num_coords); + + switch(segment) { + case VG_CLOSE_PATH: + break; + case VG_MOVE_TO: + matrix_map_point(td->matrix, + data[0], data[1], &data[0], &data[1]); + break; + case VG_LINE_TO: + matrix_map_point(td->matrix, + data[0], data[1], &data[0], &data[1]); + break; + case VG_HLINE_TO: + case VG_VLINE_TO: + assert(0); + break; + case VG_QUAD_TO: + matrix_map_point(td->matrix, + data[0], data[1], &data[0], &data[1]); + matrix_map_point(td->matrix, + data[2], data[3], &data[2], &data[3]); + break; + case VG_CUBIC_TO: + matrix_map_point(td->matrix, + data[0], data[1], &data[0], &data[1]); + matrix_map_point(td->matrix, + data[2], data[3], &data[2], &data[3]); + matrix_map_point(td->matrix, + data[4], data[5], &data[4], &data[5]); + break; + case VG_SQUAD_TO: + matrix_map_point(td->matrix, + data[0], data[1], &data[0], &data[1]); + break; + case VG_SCUBIC_TO: + matrix_map_point(td->matrix, + data[0], data[1], &data[0], &data[1]); + matrix_map_point(td->matrix, + data[2], data[3], &data[2], &data[3]); + break; + case VG_SCCWARC_TO: + case VG_SCWARC_TO: + case VG_LCCWARC_TO: + case VG_LCWARC_TO: { + struct arc arc; + struct path *path = path_create(td->datatype, + 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); + arc_init(&arc, segment, + pd->ox, pd->oy, data[3], data[4], + data[0], data[1], data[2]); + + arc_to_path(&arc, path, td->matrix); + + num_coords = path_num_coords(path); + + array_append_data(td->segments, path->segments->data, + path->num_segments); + array_append_data(td->coords, path->control_points->data, + num_coords); + path_destroy(path); + + return VG_TRUE; + } + break; + default: + break; + } + + vg_float_to_datatype(td->datatype, common_data, data, num_coords); + + array_append_data(td->segments, &pd->segment, 1); + array_append_data(td->coords, common_data, num_coords); + return VG_TRUE; +} + +void path_transform(struct path *dst, struct path *src) +{ + struct transform_data data; + struct vg_context *ctx = dst->base.ctx; + + data.segments = dst->segments; + data.coords = dst->control_points; + data.matrix = &ctx->state.vg.path_user_to_surface_matrix; + data.datatype = dst->datatype; + + path_for_each_segment(src, transform_cb, (void*)&data); + + dst->num_segments = dst->segments->num_elements; + dst->dirty = VG_TRUE; + dst->dirty_stroke = VG_TRUE; +} + +void path_append_path(struct path *dst, + struct path *src) +{ + VGint num_coords = path_num_coords(src); + void *dst_data = malloc(size_for_datatype(dst->datatype) * num_coords); + array_append_data(dst->segments, + src->segments->data, + src->num_segments); + convert_path(src, dst->datatype, + dst_data, num_coords); + array_append_data(dst->control_points, + dst_data, + num_coords); + free(dst_data); + + dst->num_segments += src->num_segments; + dst->dirty = VG_TRUE; + dst->dirty_stroke = VG_TRUE; +} + +static INLINE VGboolean is_segment_arc(VGubyte segment) +{ + VGubyte scommand = SEGMENT_COMMAND(segment); + return (scommand == VG_SCCWARC_TO || + scommand == VG_SCWARC_TO || + scommand == VG_LCCWARC_TO || + scommand == VG_LCWARC_TO); +} + +struct path_iter_data { + struct path *path; + VGubyte segment; + void *coords; + VGfloat px, py, ox, oy, sx, sy; +}; +static INLINE VGubyte normalize_coords(struct path_iter_data *pd, + VGint *num_coords, + VGfloat *data) +{ + VGint command = SEGMENT_COMMAND(pd->segment); + VGboolean relative = SEGMENT_ABS_REL(pd->segment); + + switch(command) { + case VG_CLOSE_PATH: + *num_coords = 0; + pd->ox = pd->sx; + pd->oy = pd->sy; + return VG_CLOSE_PATH; + break; + case VG_MOVE_TO: + data_at(&pd->coords, pd->path, 0, 2, data); + map_if_relative(pd->ox, pd->oy, relative, &data[0], &data[1]); + pd->sx = data[0]; + pd->sy = data[1]; + pd->ox = data[0]; + pd->oy = data[1]; + pd->px = data[0]; + pd->py = data[1]; + *num_coords = 2; + return VG_MOVE_TO_ABS; + break; + case VG_LINE_TO: + data_at(&pd->coords, pd->path, 0, 2, data); + map_if_relative(pd->ox, pd->oy, relative, &data[0], &data[1]); + pd->ox = data[0]; + pd->oy = data[1]; + pd->px = data[0]; + pd->py = data[1]; + *num_coords = 2; + return VG_LINE_TO_ABS; + break; + case VG_HLINE_TO: + data_at(&pd->coords, pd->path, 0, 1, data); + map_if_relative(pd->ox, pd->oy, relative, &data[0], 0); + data[1] = pd->oy; + pd->ox = data[0]; + pd->oy = data[1]; + pd->px = data[0]; + pd->py = data[1]; + *num_coords = 2; + return VG_LINE_TO_ABS; + break; + case VG_VLINE_TO: + data_at(&pd->coords, pd->path, 0, 1, data); + map_if_relative(pd->ox, pd->oy, relative, 0, &data[0]); + data[1] = data[0]; + data[0] = pd->ox; + pd->ox = data[0]; + pd->oy = data[1]; + pd->px = data[0]; + pd->py = data[1]; + *num_coords = 2; + return VG_LINE_TO_ABS; + break; + case VG_CUBIC_TO: { + data_at(&pd->coords, pd->path, 0, 6, data); + map_if_relative(pd->ox, pd->oy, relative, &data[0], &data[1]); + map_if_relative(pd->ox, pd->oy, relative, &data[2], &data[3]); + map_if_relative(pd->ox, pd->oy, relative, &data[4], &data[5]); + pd->px = data[2]; + pd->py = data[3]; + pd->ox = data[4]; + pd->oy = data[5]; + *num_coords = 6; + return VG_CUBIC_TO_ABS; + } + break; + case VG_QUAD_TO: { + VGfloat x0, y0, x1, y1, x2, y2, x3, y3; + data_at(&pd->coords, pd->path, 0, 4, data); + x0 = pd->ox; + y0 = pd->oy; + x1 = data[0]; + y1 = data[1]; + x3 = data[2]; + y3 = data[3]; + map_if_relative(pd->ox, pd->oy, relative, &x1, &y1); + map_if_relative(pd->ox, pd->oy, relative, &x3, &y3); + pd->px = x1; + pd->py = y1; + { /* form a cubic out of it */ + x2 = (x3 + 2*x1) / 3.f; + y2 = (y3 + 2*y1) / 3.f; + x1 = (x0 + 2*x1) / 3.f; + y1 = (y0 + 2*y1) / 3.f; + } + pd->ox = x3; + pd->oy = y3; + data[0] = x1; + data[1] = y1; + data[2] = x2; + data[3] = y2; + data[4] = x3; + data[5] = y3; + *num_coords = 6; + return VG_CUBIC_TO_ABS; + } + break; + case VG_SQUAD_TO: { + VGfloat x0, y0, x1, y1, x2, y2, x3, y3; + data_at(&pd->coords, pd->path, 0, 2, data); + x0 = pd->ox; + y0 = pd->oy; + x1 = 2 * pd->ox - pd->px; + y1 = 2 * pd->oy - pd->py; + x3 = data[0]; + y3 = data[1]; + map_if_relative(pd->ox, pd->oy, relative, &x3, &y3); + pd->px = x1; + pd->py = y1; + { /* form a cubic out of it */ + x2 = (x3 + 2*x1) / 3.f; + y2 = (y3 + 2*y1) / 3.f; + x1 = (x0 + 2*x1) / 3.f; + y1 = (y0 + 2*y1) / 3.f; + } + pd->ox = x3; + pd->oy = y3; + data[0] = x1; + data[1] = y1; + data[2] = x2; + data[3] = y2; + data[4] = x3; + data[5] = y3; + *num_coords = 6; + return VG_CUBIC_TO_ABS; + } + break; + case VG_SCUBIC_TO: { + VGfloat x0, y0, x1, y1, x2, y2, x3, y3; + data_at(&pd->coords, pd->path, 0, 4, data); + x0 = pd->ox; + y0 = pd->oy; + x1 = 2*pd->ox-pd->px; + y1 = 2*pd->oy-pd->py; + x2 = data[0]; + y2 = data[1]; + x3 = data[2]; + y3 = data[3]; + map_if_relative(pd->ox, pd->oy, relative, &x2, &y2); + map_if_relative(pd->ox, pd->oy, relative, &x3, &y3); + pd->ox = x3; + pd->oy = y3; + pd->px = x2; + pd->py = y2; + data[0] = x1; + data[1] = y1; + data[2] = x2; + data[3] = y2; + data[4] = x3; + data[5] = y3; + *num_coords = 6; + return VG_CUBIC_TO_ABS; + } + break; + case VG_SCCWARC_TO: + case VG_SCWARC_TO: + case VG_LCCWARC_TO: + case VG_LCWARC_TO: { + data_at(&pd->coords, pd->path, 0, 5, data); + map_if_relative(pd->ox, pd->oy, relative, &data[3], &data[4]); + pd->ox = data[3]; + pd->oy = data[4]; + pd->px = data[3]; + pd->py = data[4]; + *num_coords = 5; + return command | VG_ABSOLUTE; + } + break; + default: + abort(); + assert(!"Unknown segment!"); + } +} + +static void linearly_interpolate(VGfloat *result, + const VGfloat *start, + const VGfloat *end, + VGfloat amount, + VGint number) +{ + VGint i; + for (i = 0; i < number; ++i) { + result[i] = start[i] + (end[i] - start[i]) * amount; + } +} + +VGboolean path_interpolate(struct path *dst, + struct path *start, struct path *end, + VGfloat amount) +{ + /* temporary path that we can discard if it will turn + * out that start is not compatible with end */ + struct path *res_path = path_create(dst->datatype, + 1.0, 0.0, + 0, 0, dst->caps); + VGint i; + VGfloat start_coords[8]; + VGfloat end_coords[8]; + VGfloat results[8]; + VGubyte common_data[sizeof(VGfloat)*8]; + struct path_iter_data start_iter, end_iter; + + memset(&start_iter, 0, sizeof(struct path_iter_data)); + memset(&end_iter, 0, sizeof(struct path_iter_data)); + + start_iter.path = start; + start_iter.coords = start->control_points->data; + end_iter.path = end; + end_iter.coords = end->control_points->data; + + for (i = 0; i < start->num_segments; ++i) { + VGubyte segment; + VGubyte ssegment, esegment; + VGint snum_coords, enum_coords; + start_iter.segment = ((VGubyte*)(start->segments->data))[i]; + end_iter.segment = ((VGubyte*)(end->segments->data))[i]; + + ssegment = normalize_coords(&start_iter, &snum_coords, + start_coords); + esegment = normalize_coords(&end_iter, &enum_coords, + end_coords); + + if (is_segment_arc(ssegment)) { + if (!is_segment_arc(esegment)) { + path_destroy(res_path); + return VG_FALSE; + } + if (amount > 0.5) + segment = esegment; + else + segment = ssegment; + } else if (is_segment_arc(esegment)) { + path_destroy(res_path); + return VG_FALSE; + } + else if (ssegment != esegment) { + path_destroy(res_path); + return VG_FALSE; + } + else + segment = ssegment; + + linearly_interpolate(results, start_coords, end_coords, + amount, snum_coords); + vg_float_to_datatype(dst->datatype, common_data, results, snum_coords); + path_append_data(res_path, 1, &segment, common_data); + } + + path_append_path(dst, res_path); + path_destroy(res_path); + + dst->dirty = VG_TRUE; + dst->dirty_stroke = VG_TRUE; + + return VG_TRUE; +} + +void path_clear(struct path *p, VGbitfield capabilities) +{ + path_set_capabilities(p, capabilities); + array_destroy(p->segments); + array_destroy(p->control_points); + p->segments = array_create(size_for_datatype(VG_PATH_DATATYPE_S_8)); + p->control_points = array_create(size_for_datatype(p->datatype)); + p->num_segments = 0; + p->dirty = VG_TRUE; + p->dirty_stroke = VG_TRUE; +} + +struct path * path_create_stroke(struct path *p, + struct matrix *matrix) +{ + VGint i; + VGfloat sx, sy, px, py, ox, oy; + VGfloat x0, y0, x1, y1, x2, y2, x3, y3; + VGfloat data[8]; + void *coords = (VGfloat *)p->control_points->data; + int dashed = (p->base.ctx->state.vg.stroke.dash_pattern_num ? 1 : 0); + struct dash_stroker stroker; + struct vg_state *vg_state = &p->base.ctx->state.vg; + + if (p->stroked.path) + { + /* ### compare the dash patterns to see if we can cache them. + * for now we simply always bail out if the path is dashed. + */ + if (memcmp( &p->stroked.matrix, + matrix, + sizeof *matrix ) == 0 && + !dashed && !p->dirty_stroke && + floatsEqual(p->stroked.stroke_width, vg_state->stroke.line_width.f) && + floatsEqual(p->stroked.miter_limit, vg_state->stroke.miter_limit.f) && + p->stroked.cap_style == vg_state->stroke.cap_style && + p->stroked.join_style == vg_state->stroke.join_style) + { + return p->stroked.path; + } + else { + path_destroy( p->stroked.path ); + p->stroked.path = NULL; + } + } + + + sx = sy = px = py = ox = oy = 0.f; + + if (dashed) + dash_stroker_init((struct stroker *)&stroker, vg_state); + else + stroker_init((struct stroker *)&stroker, vg_state); + + stroker_begin((struct stroker *)&stroker); + + for (i = 0; i < p->num_segments; ++i) { + VGubyte segment = ((VGubyte*)(p->segments->data))[i]; + VGint command = SEGMENT_COMMAND(segment); + VGboolean relative = SEGMENT_ABS_REL(segment); + + switch(command) { + case VG_CLOSE_PATH: { + VGfloat x0 = sx; + VGfloat y0 = sy; + matrix_map_point(matrix, x0, y0, &x0, &y0); + stroker_line_to((struct stroker *)&stroker, x0, y0); + } + break; + case VG_MOVE_TO: + data_at(&coords, p, 0, 2, data); + x0 = data[0]; + y0 = data[1]; + map_if_relative(ox, oy, relative, &x0, &y0); + sx = x0; + sy = y0; + ox = x0; + oy = y0; + px = x0; + py = y0; + matrix_map_point(matrix, x0, y0, &x0, &y0); + stroker_move_to((struct stroker *)&stroker, x0, y0); + break; + case VG_LINE_TO: + data_at(&coords, p, 0, 2, data); + x0 = data[0]; + y0 = data[1]; + map_if_relative(ox, oy, relative, &x0, &y0); + ox = x0; + oy = y0; + px = x0; + py = y0; + matrix_map_point(matrix, x0, y0, &x0, &y0); + stroker_line_to((struct stroker *)&stroker, x0, y0); + break; + case VG_HLINE_TO: + data_at(&coords, p, 0, 1, data); + x0 = data[0]; + y0 = oy; + map_if_relative(ox, oy, relative, &x0, 0); + ox = x0; + px = x0; + py = y0; + matrix_map_point(matrix, x0, y0, &x0, &y0); + stroker_line_to((struct stroker *)&stroker, x0, y0); + break; + case VG_VLINE_TO: + data_at(&coords, p, 0, 1, data); + x0 = ox; + y0 = data[0]; + map_if_relative(ox, oy, relative, 0, &y0); + oy = y0; + px = x0; + py = y0; + matrix_map_point(matrix, x0, y0, &x0, &y0); + stroker_line_to((struct stroker *)&stroker, x0, y0); + break; + case VG_CUBIC_TO: { + data_at(&coords, p, 0, 6, data); + x0 = ox; + y0 = oy; + x1 = data[0]; + y1 = data[1]; + x2 = data[2]; + y2 = data[3]; + x3 = data[4]; + y3 = data[5]; + map_if_relative(ox, oy, relative, &x1, &y1); + map_if_relative(ox, oy, relative, &x2, &y2); + map_if_relative(ox, oy, relative, &x3, &y3); + if (floatsEqual(x1, ox) && floatsEqual(y1, oy) && + floatsEqual(x1, x2) && floatsEqual(y1, y2) && + floatsEqual(x2, x3) && floatsEqual(y2, y3)) { + /*ignore the empty segment */ + continue; + } else if (floatsEqual(x3, ox) && floatsEqual(y3, oy)) { + /* if dup vertex, emit a line */ + ox = x3; + oy = y3; + matrix_map_point(matrix, x3, y3, &x3, &y3); + stroker_line_to((struct stroker *)&stroker, x3, y3); + continue; + } + ox = x3; + oy = y3; + px = x2; + py = y2; + assert(matrix_is_affine(matrix)); + matrix_map_point(matrix, x0, y0, &x0, &y0); + matrix_map_point(matrix, x1, y1, &x1, &y1); + matrix_map_point(matrix, x2, y2, &x2, &y2); + matrix_map_point(matrix, x3, y3, &x3, &y3); + stroker_curve_to((struct stroker *)&stroker, x1, y1, x2, y2, x3, y3); + } + break; + case VG_QUAD_TO: { + data_at(&coords, p, 0, 4, data); + x0 = ox; + y0 = oy; + x1 = data[0]; + y1 = data[1]; + x3 = data[2]; + y3 = data[3]; + map_if_relative(ox, oy, relative, &x1, &y1); + map_if_relative(ox, oy, relative, &x3, &y3); + px = x1; + py = y1; + { /* form a cubic out of it */ + x2 = (x3 + 2*x1) / 3.f; + y2 = (y3 + 2*y1) / 3.f; + x1 = (x0 + 2*x1) / 3.f; + y1 = (y0 + 2*y1) / 3.f; + } + if (floatsEqual(x1, ox) && floatsEqual(y1, oy) && + floatsEqual(x1, x2) && floatsEqual(y1, y2) && + floatsEqual(x2, x3) && floatsEqual(y2, y3)) { + /*ignore the empty segment */ + continue; + } else if (floatsEqual(x3, ox) && floatsEqual(y3, oy)) { + /* if dup vertex, emit a line */ + ox = x3; + oy = y3; + matrix_map_point(matrix, x3, y3, &x3, &y3); + stroker_line_to((struct stroker *)&stroker, x3, y3); + continue; + } + ox = x3; + oy = y3; + assert(matrix_is_affine(matrix)); + matrix_map_point(matrix, x0, y0, &x0, &y0); + matrix_map_point(matrix, x1, y1, &x1, &y1); + matrix_map_point(matrix, x2, y2, &x2, &y2); + matrix_map_point(matrix, x3, y3, &x3, &y3); + stroker_curve_to((struct stroker *)&stroker, x1, y1, x2, y2, x3, y3); + } + break; + case VG_SQUAD_TO: { + data_at(&coords, p, 0, 2, data); + x0 = ox; + y0 = oy; + x1 = 2*ox-px; + y1 = 2*oy-py; + x3 = data[0]; + y3 = data[1]; + map_if_relative(ox, oy, relative, &x3, &y3); + px = x1; + py = y1; + { /* form a cubic out of it */ + x2 = (x3 + 2*x1) / 3.f; + y2 = (y3 + 2*y1) / 3.f; + x1 = (x0 + 2*x1) / 3.f; + y1 = (y0 + 2*y1) / 3.f; + } + if (floatsEqual(x1, ox) && floatsEqual(y1, oy) && + floatsEqual(x1, x2) && floatsEqual(y1, y2) && + floatsEqual(x2, x3) && floatsEqual(y2, y3)) { + /*ignore the empty segment */ + continue; + } else if (floatsEqual(x3, ox) && floatsEqual(y3, oy)) { + /* if dup vertex, emit a line */ + ox = x3; + oy = y3; + matrix_map_point(matrix, x3, y3, &x3, &y3); + stroker_line_to((struct stroker *)&stroker, x3, y3); + continue; + } + ox = x3; + oy = y3; + assert(matrix_is_affine(matrix)); + matrix_map_point(matrix, x0, y0, &x0, &y0); + matrix_map_point(matrix, x1, y1, &x1, &y1); + matrix_map_point(matrix, x2, y2, &x2, &y2); + matrix_map_point(matrix, x3, y3, &x3, &y3); + stroker_curve_to((struct stroker *)&stroker, x1, y1, x2, y2, x3, y3); + } + break; + case VG_SCUBIC_TO: { + data_at(&coords, p, 0, 4, data); + x0 = ox; + y0 = oy; + x1 = 2*ox-px; + y1 = 2*oy-py; + x2 = data[0]; + y2 = data[1]; + x3 = data[2]; + y3 = data[3]; + map_if_relative(ox, oy, relative, &x2, &y2); + map_if_relative(ox, oy, relative, &x3, &y3); + if (floatsEqual(x1, ox) && floatsEqual(y1, oy) && + floatsEqual(x1, x2) && floatsEqual(y1, y2) && + floatsEqual(x2, x3) && floatsEqual(y2, y3)) { + /*ignore the empty segment */ + continue; + } else if (floatsEqual(x3, ox) && floatsEqual(y3, oy)) { + /* if dup vertex, emit a line */ + ox = x3; + oy = y3; + matrix_map_point(matrix, x3, y3, &x3, &y3); + stroker_line_to((struct stroker *)&stroker, x3, y3); + continue; + } + ox = x3; + oy = y3; + px = x2; + py = y2; + assert(matrix_is_affine(matrix)); + matrix_map_point(matrix, x0, y0, &x0, &y0); + matrix_map_point(matrix, x1, y1, &x1, &y1); + matrix_map_point(matrix, x2, y2, &x2, &y2); + matrix_map_point(matrix, x3, y3, &x3, &y3); + stroker_curve_to((struct stroker *)&stroker, x1, y1, x2, y2, x3, y3); + } + break; + case VG_SCCWARC_TO: + case VG_SCWARC_TO: + case VG_LCCWARC_TO: + case VG_LCWARC_TO: { + VGfloat rh, rv, rot; + struct arc arc; + + data_at(&coords, p, 0, 5, data); + x0 = ox; + y0 = oy; + rh = data[0]; + rv = data[1]; + rot = data[2]; + x1 = data[3]; + y1 = data[4]; + map_if_relative(ox, oy, relative, &x1, &y1); + if (floatsEqual(x1, ox) && floatsEqual(y1, oy)) { + /* if dup vertex, emit a line */ + ox = x1; + oy = y1; + matrix_map_point(matrix, x1, y1, &x1, &y1); + stroker_line_to((struct stroker *)&stroker, x1, y1); + continue; + } + arc_init(&arc, command, x0, y0, x1, y1, + rh, rv, rot); + arc_stroke_cb(&arc, (struct stroker *)&stroker, + matrix); + ox = x1; + oy = y1; + px = x1; + py = y1; + } + break; + default: + abort(); + assert(!"Unknown segment!"); + } + } + + stroker_end((struct stroker *)&stroker); + + if (dashed) + dash_stroker_cleanup((struct dash_stroker *)&stroker); + else + stroker_cleanup((struct stroker *)&stroker); + + p->stroked.path = stroker.base.path; + p->stroked.matrix = *matrix; + p->dirty_stroke = VG_FALSE; + p->stroked.stroke_width = vg_state->stroke.line_width.f; + p->stroked.miter_limit = vg_state->stroke.miter_limit.f; + p->stroked.cap_style = vg_state->stroke.cap_style; + p->stroked.join_style = vg_state->stroke.join_style; + + return stroker.base.path; +} + +void path_render(struct path *p, VGbitfield paintModes, + struct matrix *mat) +{ + struct vg_context *ctx = vg_current_context(); + struct matrix paint_matrix; + + vg_validate_state(ctx); + + shader_set_drawing_image(ctx->shader, VG_FALSE); + shader_set_image(ctx->shader, 0); +#if 0 + fprintf(stderr, "Matrix(11=%f 12=%f 13=%f 21=%f 22=%f 23=%f 31=%f 32=%f 33=%f)\n", + mat->m[0], mat->m[1], mat->m[2], + mat->m[3], mat->m[4], mat->m[5], + mat->m[6], mat->m[7], mat->m[8]); +#endif + if ((paintModes & VG_FILL_PATH) && + vg_get_paint_matrix(ctx, + &ctx->state.vg.fill_paint_to_user_matrix, + mat, + &paint_matrix)) { + /* First the fill */ + shader_set_surface_matrix(ctx->shader, mat); + shader_set_paint(ctx->shader, ctx->state.vg.fill_paint); + shader_set_paint_matrix(ctx->shader, &paint_matrix); + shader_bind(ctx->shader); + path_fill(p); + } + + if ((paintModes & VG_STROKE_PATH) && + vg_get_paint_matrix(ctx, + &ctx->state.vg.stroke_paint_to_user_matrix, + mat, + &paint_matrix)) { + /* 8.7.5: "line width less than or equal to 0 prevents stroking from + * taking place."*/ + if (ctx->state.vg.stroke.line_width.f <= 0) + return; + shader_set_surface_matrix(ctx->shader, mat); + shader_set_paint(ctx->shader, ctx->state.vg.stroke_paint); + shader_set_paint_matrix(ctx->shader, &paint_matrix); + shader_bind(ctx->shader); + path_stroke(p); + } +} + +void path_fill(struct path *p) +{ + struct vg_context *ctx = vg_current_context(); + struct matrix identity; + + matrix_load_identity(&identity); + + { + struct polygon_array *polygon_array = path_get_fill_polygons(p, &identity); + struct array *polys = polygon_array->array; + + if (!polygon_array || !polys || !polys->num_elements) { + return; + } + polygon_array_fill(polygon_array, ctx); + } +} + +void path_stroke(struct path *p) +{ + struct vg_context *ctx = vg_current_context(); + VGFillRule old_fill = ctx->state.vg.fill_rule; + struct matrix identity; + struct path *stroke; + + matrix_load_identity(&identity); + stroke = path_create_stroke(p, &identity); + if (stroke && !path_is_empty(stroke)) { + ctx->state.vg.fill_rule = VG_NON_ZERO; + + path_fill(stroke); + + ctx->state.vg.fill_rule = old_fill; + } +} + +void path_move_to(struct path *p, float x, float y) +{ + VGubyte segment = VG_MOVE_TO_ABS; + VGubyte common_data[sizeof(VGfloat) * 2]; + VGfloat data[2] = {x, y}; + + vg_float_to_datatype(p->datatype, common_data, data, 2); + path_append_data(p, 1, &segment, common_data); +} + +void path_line_to(struct path *p, float x, float y) +{ + VGubyte segment = VG_LINE_TO_ABS; + VGubyte common_data[sizeof(VGfloat) * 2]; + VGfloat data[2] = {x, y}; + + vg_float_to_datatype(p->datatype, common_data, data, 2); + + path_append_data(p, 1, &segment, common_data); +} + +void path_cubic_to(struct path *p, float px1, float py1, + float px2, float py2, + float x, float y) +{ + VGubyte segment = VG_CUBIC_TO_ABS; + VGubyte common_data[sizeof(VGfloat) * 6]; + VGfloat data[6]; + + data[0] = px1; data[1] = py1; + data[2] = px2; data[3] = py2; + data[4] = x; data[5] = y; + + vg_float_to_datatype(p->datatype, common_data, data, 6); + + path_append_data(p, 1, &segment, common_data); +} + +static INLINE void line_bounds(VGfloat *line /*x1,y1,x2,y2*/, + VGfloat *bounds) +{ + bounds[0] = MIN2(line[0], line[2]); + bounds[1] = MIN2(line[1], line[3]); + bounds[2] = MAX2(line[0], line[2]) - bounds[0]; + bounds[3] = MAX2(line[1], line[3]) - bounds[1]; +} + +static INLINE void unite_bounds(VGfloat *bounds, + VGfloat *el) +{ + VGfloat cx1, cy1, cx2, cy2; + VGfloat nx1, ny1, nx2, ny2; + + cx1 = bounds[0]; + cy1 = bounds[1]; + cx2 = bounds[0] + bounds[2]; + cy2 = bounds[1] + bounds[3]; + + nx1 = el[0]; + ny1 = el[1]; + nx2 = el[0] + el[2]; + ny2 = el[1] + el[3]; + + bounds[0] = MIN2(cx1, nx1); + bounds[1] = MIN2(cy1, ny1); + bounds[2] = MAX2(cx2, nx2) - bounds[0]; + bounds[3] = MAX2(cy2, ny2) - bounds[1]; +} + +static INLINE void set_bounds(VGfloat *bounds, + VGfloat *element_bounds, + VGboolean *initialized) +{ + if (!(*initialized)) { + memcpy(bounds, element_bounds, 4 * sizeof(VGfloat)); + *initialized = VG_TRUE; + } else + unite_bounds(bounds, element_bounds); +} + +void path_bounding_rect(struct path *p, float *x, float *y, + float *w, float *h) +{ + VGint i; + VGfloat coords[8]; + struct path_iter_data iter; + VGint num_coords; + VGfloat bounds[4]; + VGfloat element_bounds[4]; + VGfloat ox, oy; + VGboolean bounds_inited = VG_FALSE; + + memset(&iter, 0, sizeof(struct path_iter_data)); + memset(&bounds, 0, sizeof(bounds)); + + if (!p->num_segments) { + bounds[2] = -1; + bounds[3] = -1; + } + + + iter.path = p; + iter.coords = p->control_points->data; + + for (i = 0; i < p->num_segments; ++i) { + VGubyte segment; + iter.segment = ((VGubyte*)(p->segments->data))[i]; + + ox = iter.ox; + oy = iter.oy; + + segment = normalize_coords(&iter, &num_coords, coords); + + switch(segment) { + case VG_CLOSE_PATH: + case VG_MOVE_TO_ABS: + break; + case VG_LINE_TO_ABS: { + VGfloat line[4] = {ox, oy, coords[0], coords[1]}; + line_bounds(line, element_bounds); + set_bounds(bounds, element_bounds, &bounds_inited); + } + break; + case VG_CUBIC_TO_ABS: { + struct bezier bezier; + bezier_init(&bezier, ox, oy, + coords[0], coords[1], + coords[2], coords[3], + coords[4], coords[5]); + bezier_exact_bounds(&bezier, element_bounds); + set_bounds(bounds, element_bounds, &bounds_inited); + } + break; + case VG_SCCWARC_TO: + case VG_SCWARC_TO: + case VG_LCCWARC_TO: + case VG_LCWARC_TO: { + struct arc arc; + struct matrix identity; + struct path *path = path_create(VG_PATH_DATATYPE_F, + 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); + + matrix_load_identity(&identity); + arc_init(&arc, segment, + ox, oy, coords[3], coords[4], + coords[0], coords[1], coords[2]); + + arc_to_path(&arc, path, &identity); + + path_bounding_rect(path, element_bounds + 0, element_bounds + 1, + element_bounds + 2, element_bounds + 3); + set_bounds(bounds, element_bounds, &bounds_inited); + } + break; + default: + assert(0); + } + } + + *x = bounds[0]; + *y = bounds[1]; + *w = bounds[2]; + *h = bounds[3]; +} + +float path_length(struct path *p, int start_segment, int num_segments) +{ + VGint i; + VGfloat coords[8]; + struct path_iter_data iter; + VGint num_coords; + VGfloat length = 0; + VGfloat ox, oy; + VGboolean in_range = VG_FALSE; + + memset(&iter, 0, sizeof(struct path_iter_data)); + + iter.path = p; + iter.coords = p->control_points->data; + + for (i = 0; i < (start_segment + num_segments); ++i) { + VGubyte segment; + + iter.segment = ((VGubyte*)(p->segments->data))[i]; + + ox = iter.ox; + oy = iter.oy; + + segment = normalize_coords(&iter, &num_coords, coords); + + in_range = (i >= start_segment) && i <= (start_segment + num_segments); + if (!in_range) + continue; + + switch(segment) { + case VG_MOVE_TO_ABS: + break; + case VG_CLOSE_PATH: { + VGfloat line[4] = {ox, oy, iter.sx, iter.sy}; + length += line_lengthv(line); + } + break; + case VG_LINE_TO_ABS: { + VGfloat line[4] = {ox, oy, coords[0], coords[1]}; + length += line_lengthv(line); + } + break; + case VG_CUBIC_TO_ABS: { + struct bezier bezier; + bezier_init(&bezier, ox, oy, + coords[0], coords[1], + coords[2], coords[3], + coords[4], coords[5]); + length += bezier_length(&bezier, BEZIER_DEFAULT_ERROR); + } + break; + case VG_SCCWARC_TO: + case VG_SCWARC_TO: + case VG_LCCWARC_TO: + case VG_LCWARC_TO: { + struct arc arc; + struct matrix identity; + struct path *path = path_create(VG_PATH_DATATYPE_F, + 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); + + matrix_load_identity(&identity); + arc_init(&arc, segment, + ox, oy, coords[3], coords[4], + coords[0], coords[1], coords[2]); + + arc_to_path(&arc, path, &identity); + + length += path_length(path, 0, path_num_segments(path)); + } + break; + default: + assert(0); + } + } + + return length; +} + +static INLINE VGboolean point_on_current_segment(VGfloat distance, + VGfloat length, + VGfloat segment_length) +{ + return + (((floatIsZero(distance) || distance < 0) && floatIsZero(length)) || + ((distance > length || floatsEqual(distance, length)) && + (floatsEqual(distance, length + segment_length) || + distance < (length + segment_length)))); +} + +static VGboolean path_point_segment(struct path_iter_data iter, + struct path_iter_data prev_iter, + VGfloat coords[8], + VGfloat distance, + VGfloat length, VGfloat *current_length, + VGfloat *point, VGfloat *normal) +{ + switch (iter.segment) { + case VG_MOVE_TO_ABS: + break; + case VG_CLOSE_PATH: { + VGfloat line[4] = {prev_iter.ox, prev_iter.oy, iter.sx, iter.sy}; + VGboolean on_current_segment = VG_FALSE; + *current_length = line_lengthv(line); + on_current_segment = point_on_current_segment(distance, + length, + *current_length); + if (on_current_segment) { + VGfloat at = (distance - length) / line_lengthv(line); + line_normal_vector(line, normal); + line_point_at(line, at, point); + return VG_TRUE; + } + } + break; + case VG_LINE_TO_ABS: { + VGfloat line[4] = {prev_iter.ox, prev_iter.oy, coords[0], coords[1]}; + VGboolean on_current_segment = VG_FALSE; + *current_length = line_lengthv(line); + on_current_segment = point_on_current_segment(distance, + length, + *current_length); + if (on_current_segment) { + VGfloat at = (distance - length) / line_lengthv(line); + line_normal_vector(line, normal); + line_point_at(line, at, point); + return VG_TRUE; + } + } + break; + case VG_CUBIC_TO_ABS: { + struct bezier bezier; + bezier_init(&bezier, prev_iter.ox, prev_iter.oy, + coords[0], coords[1], + coords[2], coords[3], + coords[4], coords[5]); + *current_length = bezier_length(&bezier, BEZIER_DEFAULT_ERROR); + if (point_on_current_segment(distance, length, *current_length)) { + bezier_point_at_length(&bezier, distance - length, + point, normal); + return VG_TRUE; + } + } + break; + case VG_SCCWARC_TO: + case VG_SCWARC_TO: + case VG_LCCWARC_TO: + case VG_LCWARC_TO: { + struct arc arc; + struct matrix identity; + struct path *path = path_create(VG_PATH_DATATYPE_F, + 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); + + matrix_load_identity(&identity); + arc_init(&arc, iter.segment, + prev_iter.ox, prev_iter.oy, coords[3], coords[4], + coords[0], coords[1], coords[2]); + + arc_to_path(&arc, path, &identity); + + *current_length = path_length(path, 0, path_num_segments(path)); + if (point_on_current_segment(distance, length, *current_length)) { + path_point(path, 0, path_num_segments(path), + distance - length, point, normal); + return VG_TRUE; + } + } + break; + default: + assert(0); + } + return VG_FALSE; +} + +void path_point(struct path *p, VGint start_segment, VGint num_segments, + VGfloat distance, VGfloat *point, VGfloat *normal) +{ + VGint i; + VGfloat coords[8]; + struct path_iter_data iter, prev_iter; + VGint num_coords; + VGfloat length = 0; + VGfloat current_length = 0; + + memset(&iter, 0, sizeof(struct path_iter_data)); + memset(&prev_iter, 0, sizeof(struct path_iter_data)); + + point[0] = 0; + point[1] = 0; + + normal[0] = 0; + normal[1] = -1; + + iter.path = p; + iter.coords = p->control_points->data; + if (distance < 0) + distance = 0; + + for (i = 0; i < (start_segment + num_segments); ++i) { + VGboolean outside_range = (i < start_segment || + i >= (start_segment + num_segments)); + + prev_iter = iter; + + iter.segment = ((VGubyte*)(p->segments->data))[i]; + iter.segment = normalize_coords(&iter, &num_coords, coords); + + if (outside_range) + continue; + + if (path_point_segment(iter, prev_iter, coords, + distance, length, ¤t_length, + point, normal)) + return; + + length += current_length; + } + + /* + *OpenVG 1.0 - 8.6.11 vgPointAlongPath + * + * If distance is greater than or equal to the path length + *(i.e., the value returned by vgPathLength when called with the same + *startSegment and numSegments parameters), the visual ending point of + *the path is used. + */ + { + switch (iter.segment) { + case VG_MOVE_TO_ABS: + break; + case VG_CLOSE_PATH: { + VGfloat line[4] = {prev_iter.ox, prev_iter.oy, iter.sx, iter.sy}; + line_normal_vector(line, normal); + line_point_at(line, 1.f, point); + } + break; + case VG_LINE_TO_ABS: { + VGfloat line[4] = {prev_iter.ox, prev_iter.oy, coords[0], coords[1]}; + line_normal_vector(line, normal); + line_point_at(line, 1.f, point); + } + break; + case VG_CUBIC_TO_ABS: { + struct bezier bezier; + bezier_init(&bezier, prev_iter.ox, prev_iter.oy, + coords[0], coords[1], + coords[2], coords[3], + coords[4], coords[5]); + bezier_point_at_t(&bezier, 1.f, point, normal); + } + break; + case VG_SCCWARC_TO: + case VG_SCWARC_TO: + case VG_LCCWARC_TO: + case VG_LCWARC_TO: { + struct arc arc; + struct matrix identity; + struct path *path = path_create(VG_PATH_DATATYPE_F, + 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); + + matrix_load_identity(&identity); + arc_init(&arc, iter.segment, + prev_iter.ox, prev_iter.oy, coords[3], coords[4], + coords[0], coords[1], coords[2]); + + arc_to_path(&arc, path, &identity); + + path_point(path, 0, path_num_segments(path), + /* to make sure we're bigger than len * 2 it */ + 2 * path_length(path, 0, path_num_segments(path)), + point, normal); + } + break; + default: + assert(0); + } + } +} + +VGboolean path_is_empty(struct path *p) +{ + return p->segments->num_elements == 0; +} diff --git a/src/gallium/state_trackers/vega/path.h b/src/gallium/state_trackers/vega/path.h new file mode 100644 index 0000000..d84b1f0 --- /dev/null +++ b/src/gallium/state_trackers/vega/path.h @@ -0,0 +1,126 @@ +/************************************************************************** + * + * 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 _PATH_H +#define _PATH_H + +#include "VG/openvg.h" + +struct path; +struct polygon; +struct matrix; + +enum fill_rule { + ODD_EVEN_FILL, + WINDING_FILL +}; + + +struct path_for_each_data { + VGubyte segment; + /* all coords are absolute, even if segment is relative */ + const VGfloat *coords; + VGfloat sx, sy, ox, oy, px, py; + void *user_data; +}; + +typedef VGboolean (*path_for_each_cb)(struct path *p, + struct path_for_each_data *data); + + +struct path *path_create(VGPathDatatype dt, VGfloat scale, VGfloat bias, + VGint segmentCapacityHint, + VGint coordCapacityHint, + VGbitfield capabilities); +void path_destroy(struct path *p); + +VGbitfield path_capabilities(struct path *p); +void path_set_capabilities(struct path *p, VGbitfield bf); + +void path_append_data(struct path *p, + VGint numSegments, + const VGubyte * pathSegments, + const void * pathData); + +void path_append_path(struct path *dst, + struct path *src); + +VGint path_num_segments(struct path *p); + +void path_bounding_rect(struct path *p, float *x, float *y, + float *w, float *h); +float path_length(struct path *p, int start_segment, int num_segments); + +void path_set_fill_rule(enum fill_rule fill); +enum fill_rule path_fill_rule(enum fill_rule fill); + +VGboolean path_is_empty(struct path *p); + +VGbyte path_datatype_size(struct path *p); + +VGPathDatatype path_datatype(struct path *p); +VGfloat path_scale(struct path *p); +VGfloat path_bias(struct path *p); +VGint path_num_coords(struct path *p); + +void path_modify_coords(struct path *p, + VGint startIndex, + VGint numSegments, + const void * pathData); + +struct path *path_create_stroke(struct path *p, + struct matrix *m); + +void path_for_each_segment(struct path *path, + path_for_each_cb cb, + void *user_data); + +void path_transform(struct path *dst, struct path *src); +VGboolean path_interpolate(struct path *dst, + struct path *start, struct path *end, + VGfloat amount); + +void path_clear(struct path *p, VGbitfield capabilities); +void path_render(struct path *p, VGbitfield paintModes, struct matrix *mat); +void path_fill(struct path *p); +void path_stroke(struct path *p); + +void path_move_to(struct path *p, float x, float y); +void path_line_to(struct path *p, float x, float y); +void path_cubic_to(struct path *p, float px1, float py1, + float px2, float py2, + float x, float y); + +void path_point(struct path *p, VGint startSegment, VGint numSegments, + VGfloat distance, VGfloat *point, VGfloat *normal); + + + +void vg_float_to_datatype(VGPathDatatype datatype, + VGubyte *common_data, + const VGfloat *data, + VGint num_coords); +#endif diff --git a/src/gallium/state_trackers/vega/path_utils.h b/src/gallium/state_trackers/vega/path_utils.h new file mode 100644 index 0000000..c2b3221 --- /dev/null +++ b/src/gallium/state_trackers/vega/path_utils.h @@ -0,0 +1,109 @@ +/************************************************************************** + * + * 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 PATH_UTILS_H +#define PATH_UTILS_H + +#include "VG/openvg.h" + +#define SEGMENT_COMMAND(command) /* Extract segment type */ \ + ((command) & 0x1e) +#define SEGMENT_ABS_REL(command) /* Extract absolute/relative bit */ \ + ((command) & 0x1) + +static INLINE VGint size_for_datatype(VGPathDatatype datatype) +{ + switch(datatype) { + case VG_PATH_DATATYPE_S_8: + return 1; + case VG_PATH_DATATYPE_S_16: + return 2; + case VG_PATH_DATATYPE_S_32: + return 4; + case VG_PATH_DATATYPE_F: + return 4; + default: + assert(!"unknown datatype"); + } + return 0; +} + +static INLINE VGint num_elements_for_segments(const VGubyte *segments, + VGint num_segments) +{ + VGint i; + VGint count = 0; + + for (i = 0; i < num_segments; ++i) { + VGubyte segment = segments[i]; + VGint command = SEGMENT_COMMAND(segment); + switch(command) { + case VG_CLOSE_PATH: + break; + case VG_MOVE_TO: + count += 2; + break; + case VG_LINE_TO: + count += 2; + break; + case VG_HLINE_TO: + count += 1; + break; + case VG_VLINE_TO: + count += 1; + break; + case VG_QUAD_TO: + count += 4; + break; + case VG_CUBIC_TO: + count += 6; + break; + case VG_SQUAD_TO: + count += 2; + break; + case VG_SCUBIC_TO: + count += 4; + break; + case VG_SCCWARC_TO: + count += 5; + break; + case VG_SCWARC_TO: + count += 5; + break; + case VG_LCCWARC_TO: + count += 5; + break; + case VG_LCWARC_TO: + count += 5; + break; + default: + assert(!"Unknown segment!"); + } + } + return count; +} + +#endif diff --git a/src/gallium/state_trackers/vega/polygon.c b/src/gallium/state_trackers/vega/polygon.c new file mode 100644 index 0000000..a491de2 --- /dev/null +++ b/src/gallium/state_trackers/vega/polygon.c @@ -0,0 +1,368 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "polygon.h" + +#include "matrix.h" /*for floatsEqual*/ +#include "vg_context.h" +#include "vg_state.h" +#include "renderer.h" +#include "util_array.h" +#include "VG/openvg.h" + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "pipe/p_screen.h" + +#include "util/u_draw_quad.h" +#include "util/u_math.h" + +#include +#include + +#define DEBUG_POLYGON 0 + +#define COMPONENTS 2 + +struct polygon +{ + VGfloat *data; + VGint size; + + VGint num_verts; + + VGboolean dirty; + struct pipe_resource *vbuf; + struct pipe_screen *screen; +}; + +static float *ptr_to_vertex(float *data, int idx) +{ + return data + (idx * COMPONENTS); +} + +#if 0 +static void polygon_print(struct polygon *poly) +{ + int i; + float *vert; + debug_printf("Polygon %p, size = %d\n", poly, poly->num_verts); + for (i = 0; i < poly->num_verts; ++i) { + vert = ptr_to_vertex(poly->data, i); + debug_printf("%f, %f, ", vert[0], vert[1]); + } + debug_printf("\nend\n"); +} +#endif + + +struct polygon * polygon_create(int size) +{ + struct polygon *poly = (struct polygon*)malloc(sizeof(struct polygon)); + + poly->data = malloc(sizeof(float) * COMPONENTS * size); + poly->size = size; + poly->num_verts = 0; + poly->dirty = VG_TRUE; + poly->vbuf = NULL; + + return poly; +} + +struct polygon * polygon_create_from_data(float *data, int size) +{ + struct polygon *poly = polygon_create(size); + + memcpy(poly->data, data, sizeof(float) * COMPONENTS * size); + poly->num_verts = size; + poly->dirty = VG_TRUE; + poly->vbuf = NULL; + + return poly; +} + +void polygon_destroy(struct polygon *poly) +{ + if (poly->vbuf) + pipe_resource_reference(&poly->vbuf, NULL); + + free(poly->data); + free(poly); +} + +void polygon_resize(struct polygon *poly, int new_size) +{ + float *data = (float*)malloc(sizeof(float) * COMPONENTS * new_size); + int size = MIN2(sizeof(float) * COMPONENTS * new_size, + sizeof(float) * COMPONENTS * poly->size); + memcpy(data, poly->data, size); + free(poly->data); + poly->data = data; + poly->size = new_size; + poly->dirty = VG_TRUE; +} + +int polygon_size(struct polygon *poly) +{ + return poly->size; +} + +int polygon_vertex_count(struct polygon *poly) +{ + return poly->num_verts; +} + +float * polygon_data(struct polygon *poly) +{ + return poly->data; +} + +void polygon_vertex_append(struct polygon *p, + float x, float y) +{ + float *vert; +#if DEBUG_POLYGON + debug_printf("Append vertex [%f, %f]\n", x, y); +#endif + if (p->num_verts >= p->size) { + polygon_resize(p, p->size * 2); + } + + vert = ptr_to_vertex(p->data, p->num_verts); + vert[0] = x; + vert[1] = y; + ++p->num_verts; + p->dirty = VG_TRUE; +} + +void polygon_set_vertex(struct polygon *p, int idx, + float x, float y) +{ + float *vert; + if (idx >= p->num_verts) { + /*fixme: error reporting*/ + abort(); + return; + } + + vert = ptr_to_vertex(p->data, idx); + vert[0] = x; + vert[1] = y; + p->dirty = VG_TRUE; +} + +void polygon_vertex(struct polygon *p, int idx, + float *vertex) +{ + float *vert; + if (idx >= p->num_verts) { + /*fixme: error reporting*/ + abort(); + return; + } + + vert = ptr_to_vertex(p->data, idx); + vertex[0] = vert[0]; + vertex[1] = vert[1]; +} + +void polygon_bounding_rect(struct polygon *p, + float *rect) +{ + int i; + float minx, miny, maxx, maxy; + float *vert = ptr_to_vertex(p->data, 0); + minx = vert[0]; + maxx = vert[0]; + miny = vert[1]; + maxy = vert[1]; + + for (i = 1; i < p->num_verts; ++i) { + vert = ptr_to_vertex(p->data, i); + minx = MIN2(vert[0], minx); + miny = MIN2(vert[1], miny); + + maxx = MAX2(vert[0], maxx); + maxy = MAX2(vert[1], maxy); + } + + rect[0] = minx; + rect[1] = miny; + rect[2] = maxx - minx; + rect[3] = maxy - miny; +} + +int polygon_contains_point(struct polygon *p, + float x, float y) +{ + return 0; +} + +void polygon_append_polygon(struct polygon *dst, + struct polygon *src) +{ + if (dst->num_verts + src->num_verts >= dst->size) { + polygon_resize(dst, dst->num_verts + src->num_verts * 1.5); + } + memcpy(ptr_to_vertex(dst->data, dst->num_verts), + src->data, src->num_verts * COMPONENTS * sizeof(VGfloat)); + dst->num_verts += src->num_verts; +} + +VGboolean polygon_is_closed(struct polygon *p) +{ + VGfloat start[2], end[2]; + + polygon_vertex(p, 0, start); + polygon_vertex(p, p->num_verts - 1, end); + + return floatsEqual(start[0], end[0]) && floatsEqual(start[1], end[1]); +} + +static void polygon_prepare_buffer(struct vg_context *ctx, + struct polygon *poly) +{ + int vert_size; + struct pipe_context *pipe; + + vert_size = poly->num_verts * COMPONENTS * sizeof(float); + + /*polygon_print(poly);*/ + + pipe = ctx->pipe; + + if (poly->vbuf == NULL || poly->dirty) { + if (poly->vbuf) { + pipe_resource_reference(&poly->vbuf, + NULL); + } + poly->screen = pipe->screen; + poly->vbuf= pipe_user_buffer_create(poly->screen, + poly->data, + vert_size, + PIPE_BIND_VERTEX_BUFFER); + poly->dirty = VG_FALSE; + } +} + +void polygon_fill(struct polygon *poly, struct vg_context *ctx) +{ + struct pipe_vertex_element velement; + struct pipe_vertex_buffer vbuffer; + VGfloat bounds[4]; + VGfloat min_x, min_y, max_x, max_y; + + assert(poly); + polygon_bounding_rect(poly, bounds); + min_x = bounds[0]; + min_y = bounds[1]; + max_x = bounds[0] + bounds[2]; + max_y = bounds[1] + bounds[3]; + +#if DEBUG_POLYGON + debug_printf("Poly bounds are [%f, %f], [%f, %f]\n", + min_x, min_y, max_x, max_y); +#endif + + polygon_prepare_buffer(ctx, poly); + + /* tell renderer about the vertex attributes */ + memset(&velement, 0, sizeof(velement)); + velement.src_offset = 0; + velement.instance_divisor = 0; + velement.vertex_buffer_index = 0; + velement.src_format = PIPE_FORMAT_R32G32_FLOAT; + + /* tell renderer about the vertex buffer */ + memset(&vbuffer, 0, sizeof(vbuffer)); + vbuffer.buffer = poly->vbuf; + vbuffer.stride = COMPONENTS * sizeof(float); /* vertex size */ + vbuffer.buffer_offset = 0; + vbuffer.max_index = poly->num_verts - 1; + + renderer_polygon_stencil_begin(ctx->renderer, + &velement, ctx->state.vg.fill_rule, VG_FALSE); + renderer_polygon_stencil(ctx->renderer, &vbuffer, + PIPE_PRIM_TRIANGLE_FAN, 0, (VGuint) poly->num_verts); + renderer_polygon_stencil_end(ctx->renderer); + + renderer_polygon_fill_begin(ctx->renderer, VG_FALSE); + renderer_polygon_fill(ctx->renderer, min_x, min_y, max_x, max_y); + renderer_polygon_fill_end(ctx->renderer); +} + +void polygon_array_fill(struct polygon_array *polyarray, struct vg_context *ctx) +{ + struct array *polys = polyarray->array; + VGfloat min_x = polyarray->min_x; + VGfloat min_y = polyarray->min_y; + VGfloat max_x = polyarray->max_x; + VGfloat max_y = polyarray->max_y; + struct pipe_vertex_element velement; + struct pipe_vertex_buffer vbuffer; + VGint i; + + +#if DEBUG_POLYGON + debug_printf("%s: Poly bounds are [%f, %f], [%f, %f]\n", + __FUNCTION__, + min_x, min_y, max_x, max_y); +#endif + + /* tell renderer about the vertex attributes */ + memset(&velement, 0, sizeof(velement)); + velement.src_offset = 0; + velement.instance_divisor = 0; + velement.vertex_buffer_index = 0; + velement.src_format = PIPE_FORMAT_R32G32_FLOAT; + + /* tell renderer about the vertex buffer */ + memset(&vbuffer, 0, sizeof(vbuffer)); + vbuffer.stride = COMPONENTS * sizeof(float); /* vertex size */ + vbuffer.buffer_offset = 0; + + /* prepare the stencil buffer */ + renderer_polygon_stencil_begin(ctx->renderer, + &velement, ctx->state.vg.fill_rule, VG_FALSE); + for (i = 0; i < polys->num_elements; ++i) { + struct polygon *poly = (((struct polygon**)polys->data)[i]); + + polygon_prepare_buffer(ctx, poly); + vbuffer.buffer = poly->vbuf; + vbuffer.max_index = poly->num_verts - 1; + + renderer_polygon_stencil(ctx->renderer, &vbuffer, + PIPE_PRIM_TRIANGLE_FAN, 0, (VGuint) poly->num_verts); + } + renderer_polygon_stencil_end(ctx->renderer); + + /* fill it */ + renderer_polygon_fill_begin(ctx->renderer, VG_FALSE); + renderer_polygon_fill(ctx->renderer, min_x, min_y, max_x, max_y); + renderer_polygon_fill_end(ctx->renderer); +} diff --git a/src/gallium/state_trackers/vega/polygon.h b/src/gallium/state_trackers/vega/polygon.h new file mode 100644 index 0000000..22672b7 --- /dev/null +++ b/src/gallium/state_trackers/vega/polygon.h @@ -0,0 +1,75 @@ +/************************************************************************** + * + * 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 POLYGON_H +#define POLYGON_H + +#include "VG/openvg.h" + +struct polygon; +struct vg_context; +struct vg_paint; +struct array; + +struct polygon *polygon_create(int size); +struct polygon *polygon_create_from_data(float *data, int size); +void polygon_destroy(struct polygon *poly); + +void polygon_resize(struct polygon *poly, int new_size); +int polygon_size(struct polygon *poly); + +int polygon_vertex_count(struct polygon *poly); +float * polygon_data(struct polygon *poly); + +void polygon_vertex_append(struct polygon *p, + float x, float y); +void polygon_append_polygon(struct polygon *dst, + struct polygon *src); +void polygon_set_vertex(struct polygon *p, int idx, + float x, float y); +void polygon_vertex(struct polygon *p, int idx, + float *vertex); + +void polygon_bounding_rect(struct polygon *p, + float *rect); +int polygon_contains_point(struct polygon *p, + float x, float y); + +VGboolean polygon_is_closed(struct polygon *p); + +void polygon_fill(struct polygon *p, struct vg_context *pipe); + +/* TODO: make a file/module around this struct + */ +struct polygon_array { + struct array *array; + VGfloat min_x, max_x; + VGfloat min_y, max_y; +}; + +void polygon_array_fill(struct polygon_array *polyarray, struct vg_context *ctx); + +#endif diff --git a/src/gallium/state_trackers/vega/renderer.c b/src/gallium/state_trackers/vega/renderer.c new file mode 100644 index 0000000..7871c51 --- /dev/null +++ b/src/gallium/state_trackers/vega/renderer.c @@ -0,0 +1,1566 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. All Rights Reserved. + * Copyright 2010 LunarG, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "renderer.h" + +#include "vg_context.h" +#include "image.h" + +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "pipe/p_screen.h" +#include "pipe/p_shader_tokens.h" + +#include "util/u_draw_quad.h" +#include "util/u_simple_shaders.h" +#include "util/u_memory.h" +#include "util/u_sampler.h" +#include "util/u_surface.h" +#include "util/u_math.h" +#include "util/u_format.h" + +#include "cso_cache/cso_context.h" +#include "tgsi/tgsi_ureg.h" + +typedef enum { + RENDERER_STATE_INIT, + RENDERER_STATE_COPY, + RENDERER_STATE_DRAWTEX, + RENDERER_STATE_SCISSOR, + RENDERER_STATE_CLEAR, + RENDERER_STATE_FILTER, + RENDERER_STATE_POLYGON_STENCIL, + RENDERER_STATE_POLYGON_FILL, + NUM_RENDERER_STATES +} RendererState; + +typedef enum { + RENDERER_VS_PLAIN, + RENDERER_VS_COLOR, + RENDERER_VS_TEXTURE, + NUM_RENDERER_VS +} RendererVs; + +typedef enum { + RENDERER_FS_COLOR, + RENDERER_FS_TEXTURE, + RENDERER_FS_SCISSOR, + RENDERER_FS_WHITE, + NUM_RENDERER_FS +} RendererFs; + +struct renderer { + struct pipe_context *pipe; + struct cso_context *cso; + + VGbitfield dirty; + struct { + struct pipe_rasterizer_state rasterizer; + struct pipe_depth_stencil_alpha_state dsa; + struct pipe_framebuffer_state fb; + } g3d; + struct matrix projection; + + struct matrix mvp; + struct pipe_resource *vs_cbuf; + + struct pipe_resource *fs_cbuf; + VGfloat fs_cbuf_data[32]; + VGint fs_cbuf_len; + + struct pipe_vertex_element velems[2]; + VGfloat vertices[4][2][4]; + + void *cached_vs[NUM_RENDERER_VS]; + void *cached_fs[NUM_RENDERER_FS]; + + RendererState state; + + /* state data */ + union { + struct { + VGint tex_width; + VGint tex_height; + } copy; + + struct { + VGint tex_width; + VGint tex_height; + } drawtex; + + struct { + VGboolean restore_dsa; + } scissor; + + struct { + VGboolean use_sampler; + VGint tex_width, tex_height; + } filter; + + struct { + struct pipe_depth_stencil_alpha_state dsa; + VGboolean manual_two_sides; + VGboolean restore_dsa; + } polygon_stencil; + } u; +}; + +/** + * Return VG_TRUE if the renderer can use the resource as the asked bindings. + */ +static VGboolean renderer_can_support(struct renderer *renderer, + struct pipe_resource *res, + unsigned bindings) +{ + struct pipe_screen *screen = renderer->pipe->screen; + + return screen->is_format_supported(screen, + res->format, res->target, 0, bindings, 0); +} + +/** + * Set the model-view-projection matrix used by vertex shaders. + */ +static void renderer_set_mvp(struct renderer *renderer, + const struct matrix *mvp) +{ + struct matrix *cur = &renderer->mvp; + struct pipe_resource *cbuf; + VGfloat consts[3][4]; + VGint i; + + /* projection only */ + if (!mvp) + mvp = &renderer->projection; + + /* re-upload only if necessary */ + if (memcmp(cur, mvp, sizeof(*mvp)) == 0) + return; + + /* 3x3 matrix to 3 constant vectors (no Z) */ + for (i = 0; i < 3; i++) { + consts[i][0] = mvp->m[i + 0]; + consts[i][1] = mvp->m[i + 3]; + consts[i][2] = 0.0f; + consts[i][3] = mvp->m[i + 6]; + } + + cbuf = renderer->vs_cbuf; + pipe_resource_reference(&cbuf, NULL); + cbuf = pipe_buffer_create(renderer->pipe->screen, + PIPE_BIND_CONSTANT_BUFFER, + sizeof(consts)); + if (cbuf) { + pipe_buffer_write(renderer->pipe, cbuf, + 0, sizeof(consts), consts); + } + renderer->pipe->set_constant_buffer(renderer->pipe, + PIPE_SHADER_VERTEX, 0, cbuf); + + memcpy(cur, mvp, sizeof(*mvp)); + renderer->vs_cbuf = cbuf; +} + +/** + * Create a simple vertex shader that passes through position and the given + * attribute. + */ +static void *create_passthrough_vs(struct pipe_context *pipe, int semantic_name) +{ + struct ureg_program *ureg; + struct ureg_src src[2], constants[3]; + struct ureg_dst dst[2], tmp; + int i; + + ureg = ureg_create(TGSI_PROCESSOR_VERTEX); + if (!ureg) + return NULL; + + /* position is in user coordinates */ + src[0] = ureg_DECL_vs_input(ureg, 0); + dst[0] = ureg_DECL_output(ureg, TGSI_SEMANTIC_POSITION, 0); + tmp = ureg_DECL_temporary(ureg); + for (i = 0; i < Elements(constants); i++) + constants[i] = ureg_DECL_constant(ureg, i); + + /* transform to clipped coordinates */ + ureg_DP4(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_X), src[0], constants[0]); + ureg_DP4(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_Y), src[0], constants[1]); + ureg_MOV(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_Z), src[0]); + ureg_DP4(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_W), src[0], constants[2]); + ureg_MOV(ureg, dst[0], ureg_src(tmp)); + + if (semantic_name >= 0) { + src[1] = ureg_DECL_vs_input(ureg, 1); + dst[1] = ureg_DECL_output(ureg, semantic_name, 0); + ureg_MOV(ureg, dst[1], src[1]); + } + + ureg_END(ureg); + + return ureg_create_shader_and_destroy(ureg, pipe); +} + +/** + * Set renderer vertex shader. + * + * This function modifies vertex_shader state. + */ +static void renderer_set_vs(struct renderer *r, RendererVs id) +{ + /* create as needed */ + if (!r->cached_vs[id]) { + int semantic_name = -1; + + switch (id) { + case RENDERER_VS_PLAIN: + break; + case RENDERER_VS_COLOR: + semantic_name = TGSI_SEMANTIC_COLOR; + break; + case RENDERER_VS_TEXTURE: + semantic_name = TGSI_SEMANTIC_GENERIC; + break; + default: + assert(!"Unknown renderer vs id"); + break; + } + + r->cached_vs[id] = create_passthrough_vs(r->pipe, semantic_name); + } + + cso_set_vertex_shader_handle(r->cso, r->cached_vs[id]); +} + +/** + * Create a simple fragment shader that sets the depth to 0.0f. + */ +static void *create_scissor_fs(struct pipe_context *pipe) +{ + struct ureg_program *ureg; + struct ureg_dst out; + struct ureg_src imm; + + ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT); + out = ureg_DECL_output(ureg, TGSI_SEMANTIC_POSITION, 0); + imm = ureg_imm4f(ureg, 0.0f, 0.0f, 0.0f, 0.0f); + + ureg_MOV(ureg, ureg_writemask(out, TGSI_WRITEMASK_Z), imm); + ureg_END(ureg); + + return ureg_create_shader_and_destroy(ureg, pipe); +} + +/** + * Create a simple fragment shader that sets the color to white. + */ +static void *create_white_fs(struct pipe_context *pipe) +{ + struct ureg_program *ureg; + struct ureg_dst out; + struct ureg_src imm; + + ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT); + out = ureg_DECL_output(ureg, TGSI_SEMANTIC_COLOR, 0); + imm = ureg_imm4f(ureg, 1.0f, 1.0f, 1.0f, 1.0f); + + ureg_MOV(ureg, out, imm); + ureg_END(ureg); + + return ureg_create_shader_and_destroy(ureg, pipe); +} + +/** + * Set renderer fragment shader. + * + * This function modifies fragment_shader state. + */ +static void renderer_set_fs(struct renderer *r, RendererFs id) +{ + /* create as needed */ + if (!r->cached_fs[id]) { + void *fs = NULL; + + switch (id) { + case RENDERER_FS_COLOR: + fs = util_make_fragment_passthrough_shader(r->pipe); + break; + case RENDERER_FS_TEXTURE: + fs = util_make_fragment_tex_shader(r->pipe, + TGSI_TEXTURE_2D, TGSI_INTERPOLATE_LINEAR); + break; + case RENDERER_FS_SCISSOR: + fs = create_scissor_fs(r->pipe); + break; + case RENDERER_FS_WHITE: + fs = create_white_fs(r->pipe); + break; + default: + assert(!"Unknown renderer fs id"); + break; + } + + r->cached_fs[id] = fs; + } + + cso_set_fragment_shader_handle(r->cso, r->cached_fs[id]); +} + +typedef enum { + VEGA_Y0_TOP, + VEGA_Y0_BOTTOM +} VegaOrientation; + +static void vg_set_viewport(struct renderer *r, + VegaOrientation orientation) +{ + const struct pipe_framebuffer_state *fb = &r->g3d.fb; + struct pipe_viewport_state viewport; + VGfloat y_scale = (orientation == VEGA_Y0_BOTTOM) ? -2.f : 2.f; + + viewport.scale[0] = fb->width / 2.f; + viewport.scale[1] = fb->height / y_scale; + viewport.scale[2] = 1.0; + viewport.scale[3] = 1.0; + viewport.translate[0] = fb->width / 2.f; + viewport.translate[1] = fb->height / 2.f; + viewport.translate[2] = 0.0; + viewport.translate[3] = 0.0; + + cso_set_viewport(r->cso, &viewport); +} + +/** + * Set renderer target. + * + * This function modifies framebuffer and viewport states. + */ +static void renderer_set_target(struct renderer *r, + struct pipe_surface *cbuf, + struct pipe_surface *zsbuf, + VGboolean y0_top) +{ + struct pipe_framebuffer_state fb; + + memset(&fb, 0, sizeof(fb)); + fb.width = cbuf->width; + fb.height = cbuf->height; + fb.cbufs[0] = cbuf; + fb.nr_cbufs = 1; + fb.zsbuf = zsbuf; + cso_set_framebuffer(r->cso, &fb); + + vg_set_viewport(r, (y0_top) ? VEGA_Y0_TOP : VEGA_Y0_BOTTOM); +} + +/** + * Set renderer blend state. Blending is disabled. + * + * This function modifies blend state. + */ +static void renderer_set_blend(struct renderer *r, + VGbitfield channel_mask) +{ + struct pipe_blend_state blend; + + memset(&blend, 0, sizeof(blend)); + + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; + + if (channel_mask & VG_RED) + blend.rt[0].colormask |= PIPE_MASK_R; + if (channel_mask & VG_GREEN) + blend.rt[0].colormask |= PIPE_MASK_G; + if (channel_mask & VG_BLUE) + blend.rt[0].colormask |= PIPE_MASK_B; + if (channel_mask & VG_ALPHA) + blend.rt[0].colormask |= PIPE_MASK_A; + + cso_set_blend(r->cso, &blend); +} + +/** + * Set renderer sampler and view states. + * + * This function modifies samplers and fragment_sampler_views states. + */ +static void renderer_set_samplers(struct renderer *r, + uint num_views, + struct pipe_sampler_view **views) +{ + struct pipe_sampler_state sampler; + unsigned tex_filter = PIPE_TEX_FILTER_NEAREST; + unsigned tex_wrap = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + uint i; + + memset(&sampler, 0, sizeof(sampler)); + + sampler.min_img_filter = tex_filter; + sampler.mag_img_filter = tex_filter; + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + + sampler.wrap_s = tex_wrap; + sampler.wrap_t = tex_wrap; + sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + + sampler.normalized_coords = 1; + + /* set samplers */ + for (i = 0; i < num_views; i++) + cso_single_sampler(r->cso, i, &sampler); + cso_single_sampler_done(r->cso); + + /* set views */ + cso_set_fragment_sampler_views(r->cso, num_views, views); +} + +/** + * Set custom renderer fragment shader, and optionally set samplers and views + * and upload the fragment constant buffer. + * + * This function modifies fragment_shader, samplers and fragment_sampler_views + * states. + */ +static void renderer_set_custom_fs(struct renderer *renderer, + void *fs, + const struct pipe_sampler_state **samplers, + struct pipe_sampler_view **views, + VGint num_samplers, + const void *const_buffer, + VGint const_buffer_len) +{ + cso_set_fragment_shader_handle(renderer->cso, fs); + + /* set samplers and views */ + if (num_samplers) { + cso_set_samplers(renderer->cso, num_samplers, samplers); + cso_set_fragment_sampler_views(renderer->cso, num_samplers, views); + } + + /* upload fs constant buffer */ + if (const_buffer_len) { + struct pipe_resource *cbuf = renderer->fs_cbuf; + + if (!cbuf || renderer->fs_cbuf_len != const_buffer_len || + memcmp(renderer->fs_cbuf_data, const_buffer, const_buffer_len)) { + pipe_resource_reference(&cbuf, NULL); + + cbuf = pipe_buffer_create(renderer->pipe->screen, + PIPE_BIND_CONSTANT_BUFFER, const_buffer_len); + pipe_buffer_write(renderer->pipe, cbuf, 0, + const_buffer_len, const_buffer); + renderer->pipe->set_constant_buffer(renderer->pipe, + PIPE_SHADER_FRAGMENT, 0, cbuf); + + renderer->fs_cbuf = cbuf; + if (const_buffer_len <= sizeof(renderer->fs_cbuf_data)) { + memcpy(renderer->fs_cbuf_data, const_buffer, const_buffer_len); + renderer->fs_cbuf_len = const_buffer_len; + } + else { + renderer->fs_cbuf_len = 0; + } + } + } +} + +/** + * Setup renderer quad position. + */ +static void renderer_quad_pos(struct renderer *r, + VGfloat x0, VGfloat y0, + VGfloat x1, VGfloat y1, + VGboolean scissor) +{ + VGfloat z; + + /* the depth test is used for scissoring */ + z = (scissor) ? 0.0f : 1.0f; + + /* positions */ + r->vertices[0][0][0] = x0; + r->vertices[0][0][1] = y0; + r->vertices[0][0][2] = z; + + r->vertices[1][0][0] = x1; + r->vertices[1][0][1] = y0; + r->vertices[1][0][2] = z; + + r->vertices[2][0][0] = x1; + r->vertices[2][0][1] = y1; + r->vertices[2][0][2] = z; + + r->vertices[3][0][0] = x0; + r->vertices[3][0][1] = y1; + r->vertices[3][0][2] = z; +} + +/** + * Setup renderer quad texture coordinates. + */ +static void renderer_quad_texcoord(struct renderer *r, + VGfloat x0, VGfloat y0, + VGfloat x1, VGfloat y1, + VGint tex_width, VGint tex_height) +{ + VGfloat s0, t0, s1, t1, r0, q0; + VGint i; + + s0 = x0 / tex_width; + s1 = x1 / tex_width; + t0 = y0 / tex_height; + t1 = y1 / tex_height; + r0 = 0.0f; + q0 = 1.0f; + + /* texcoords */ + r->vertices[0][1][0] = s0; + r->vertices[0][1][1] = t0; + + r->vertices[1][1][0] = s1; + r->vertices[1][1][1] = t0; + + r->vertices[2][1][0] = s1; + r->vertices[2][1][1] = t1; + + r->vertices[3][1][0] = s0; + r->vertices[3][1][1] = t1; + + for (i = 0; i < 4; i++) { + r->vertices[i][1][2] = r0; + r->vertices[i][1][3] = q0; + } +} + +/** + * Draw renderer quad. + */ +static void renderer_quad_draw(struct renderer *r) +{ + struct pipe_resource *buf; + + buf = pipe_user_buffer_create(r->pipe->screen, + r->vertices, + sizeof(r->vertices), + PIPE_BIND_VERTEX_BUFFER); + if (buf) { + util_draw_vertex_buffer(r->pipe, buf, 0, + PIPE_PRIM_TRIANGLE_FAN, + Elements(r->vertices), /* verts */ + Elements(r->vertices[0])); /* attribs/vert */ + + pipe_resource_reference(&buf, NULL); + } +} + +/** + * Prepare the renderer for copying. + */ +VGboolean renderer_copy_begin(struct renderer *renderer, + struct pipe_surface *dst, + VGboolean y0_top, + struct pipe_sampler_view *src) +{ + assert(renderer->state == RENDERER_STATE_INIT); + + /* sanity check */ + if (!renderer_can_support(renderer, + dst->texture, PIPE_BIND_RENDER_TARGET) || + !renderer_can_support(renderer, + src->texture, PIPE_BIND_SAMPLER_VIEW)) + return VG_FALSE; + + cso_save_framebuffer(renderer->cso); + cso_save_viewport(renderer->cso); + cso_save_blend(renderer->cso); + cso_save_samplers(renderer->cso); + cso_save_fragment_sampler_views(renderer->cso); + cso_save_fragment_shader(renderer->cso); + cso_save_vertex_shader(renderer->cso); + + renderer_set_target(renderer, dst, NULL, y0_top); + + renderer_set_blend(renderer, ~0); + renderer_set_samplers(renderer, 1, &src); + + renderer_set_fs(renderer, RENDERER_FS_TEXTURE); + renderer_set_vs(renderer, RENDERER_VS_TEXTURE); + + renderer_set_mvp(renderer, NULL); + + /* remember the texture size */ + renderer->u.copy.tex_width = src->texture->width0; + renderer->u.copy.tex_height = src->texture->height0; + renderer->state = RENDERER_STATE_COPY; + + return VG_TRUE; +} + +/** + * Draw into the destination rectangle given by (x, y, w, h). The texture is + * sampled from within the rectangle given by (sx, sy, sw, sh). + * + * The coordinates are in surface coordinates. + */ +void renderer_copy(struct renderer *renderer, + VGint x, VGint y, VGint w, VGint h, + VGint sx, VGint sy, VGint sw, VGint sh) +{ + assert(renderer->state == RENDERER_STATE_COPY); + + /* there is no depth buffer for scissoring anyway */ + renderer_quad_pos(renderer, x, y, x + w, y + h, VG_FALSE); + renderer_quad_texcoord(renderer, sx, sy, sx + sw, sy + sh, + renderer->u.copy.tex_width, + renderer->u.copy.tex_height); + + renderer_quad_draw(renderer); +} + +/** + * End copying and restore the states. + */ +void renderer_copy_end(struct renderer *renderer) +{ + assert(renderer->state == RENDERER_STATE_COPY); + + cso_restore_framebuffer(renderer->cso); + cso_restore_viewport(renderer->cso); + cso_restore_blend(renderer->cso); + cso_restore_samplers(renderer->cso); + cso_restore_fragment_sampler_views(renderer->cso); + cso_restore_fragment_shader(renderer->cso); + cso_restore_vertex_shader(renderer->cso); + + renderer->state = RENDERER_STATE_INIT; +} + +/** + * Prepare the renderer for textured drawing. + */ +VGboolean renderer_drawtex_begin(struct renderer *renderer, + struct pipe_sampler_view *src) +{ + assert(renderer->state == RENDERER_STATE_INIT); + + if (!renderer_can_support(renderer, src->texture, PIPE_BIND_SAMPLER_VIEW)) + return VG_FALSE; + + cso_save_blend(renderer->cso); + cso_save_samplers(renderer->cso); + cso_save_fragment_sampler_views(renderer->cso); + cso_save_fragment_shader(renderer->cso); + cso_save_vertex_shader(renderer->cso); + + renderer_set_blend(renderer, ~0); + + renderer_set_samplers(renderer, 1, &src); + + renderer_set_fs(renderer, RENDERER_FS_TEXTURE); + renderer_set_vs(renderer, RENDERER_VS_TEXTURE); + + renderer_set_mvp(renderer, NULL); + + /* remember the texture size */ + renderer->u.drawtex.tex_width = src->texture->width0; + renderer->u.drawtex.tex_height = src->texture->height0; + renderer->state = RENDERER_STATE_DRAWTEX; + + return VG_TRUE; +} + +/** + * Draw into the destination rectangle given by (x, y, w, h). The texture is + * sampled from within the rectangle given by (sx, sy, sw, sh). + * + * The coordinates are in surface coordinates. + */ +void renderer_drawtex(struct renderer *renderer, + VGint x, VGint y, VGint w, VGint h, + VGint sx, VGint sy, VGint sw, VGint sh) +{ + assert(renderer->state == RENDERER_STATE_DRAWTEX); + + /* with scissoring */ + renderer_quad_pos(renderer, x, y, x + w, y + h, VG_TRUE); + renderer_quad_texcoord(renderer, sx, sy, sx + sw, sy + sh, + renderer->u.drawtex.tex_width, + renderer->u.drawtex.tex_height); + + renderer_quad_draw(renderer); +} + +/** + * End textured drawing and restore the states. + */ +void renderer_drawtex_end(struct renderer *renderer) +{ + assert(renderer->state == RENDERER_STATE_DRAWTEX); + + cso_restore_blend(renderer->cso); + cso_restore_samplers(renderer->cso); + cso_restore_fragment_sampler_views(renderer->cso); + cso_restore_fragment_shader(renderer->cso); + cso_restore_vertex_shader(renderer->cso); + + renderer->state = RENDERER_STATE_INIT; +} + +/** + * Prepare the renderer for scissor update. This will reset the depth buffer + * to 1.0f. + */ +VGboolean renderer_scissor_begin(struct renderer *renderer, + VGboolean restore_dsa) +{ + struct pipe_depth_stencil_alpha_state dsa; + + assert(renderer->state == RENDERER_STATE_INIT); + + if (restore_dsa) + cso_save_depth_stencil_alpha(renderer->cso); + cso_save_blend(renderer->cso); + cso_save_fragment_shader(renderer->cso); + + /* enable depth writes */ + memset(&dsa, 0, sizeof(dsa)); + dsa.depth.enabled = 1; + dsa.depth.writemask = 1; + dsa.depth.func = PIPE_FUNC_ALWAYS; + cso_set_depth_stencil_alpha(renderer->cso, &dsa); + + /* disable color writes */ + renderer_set_blend(renderer, 0); + renderer_set_fs(renderer, RENDERER_FS_SCISSOR); + + renderer_set_mvp(renderer, NULL); + + renderer->u.scissor.restore_dsa = restore_dsa; + renderer->state = RENDERER_STATE_SCISSOR; + + /* clear the depth buffer to 1.0f */ + renderer->pipe->clear(renderer->pipe, + PIPE_CLEAR_DEPTHSTENCIL, NULL, 1.0f, 0); + + return VG_TRUE; +} + +/** + * Add a scissor rectangle. Depth values inside the rectangle will be set to + * 0.0f. + */ +void renderer_scissor(struct renderer *renderer, + VGint x, VGint y, VGint width, VGint height) +{ + assert(renderer->state == RENDERER_STATE_SCISSOR); + + renderer_quad_pos(renderer, x, y, x + width, y + height, VG_FALSE); + renderer_quad_draw(renderer); +} + +/** + * End scissor update and restore the states. + */ +void renderer_scissor_end(struct renderer *renderer) +{ + assert(renderer->state == RENDERER_STATE_SCISSOR); + + if (renderer->u.scissor.restore_dsa) + cso_restore_depth_stencil_alpha(renderer->cso); + cso_restore_blend(renderer->cso); + cso_restore_fragment_shader(renderer->cso); + + renderer->state = RENDERER_STATE_INIT; +} + +/** + * Prepare the renderer for clearing. + */ +VGboolean renderer_clear_begin(struct renderer *renderer) +{ + assert(renderer->state == RENDERER_STATE_INIT); + + cso_save_blend(renderer->cso); + cso_save_fragment_shader(renderer->cso); + cso_save_vertex_shader(renderer->cso); + + renderer_set_blend(renderer, ~0); + renderer_set_fs(renderer, RENDERER_FS_COLOR); + renderer_set_vs(renderer, RENDERER_VS_COLOR); + + renderer_set_mvp(renderer, NULL); + + renderer->state = RENDERER_STATE_CLEAR; + + return VG_TRUE; +} + +/** + * Clear the framebuffer with the specified region and color. + * + * The coordinates are in surface coordinates. + */ +void renderer_clear(struct renderer *renderer, + VGint x, VGint y, VGint width, VGint height, + const VGfloat color[4]) +{ + VGuint i; + + assert(renderer->state == RENDERER_STATE_CLEAR); + + renderer_quad_pos(renderer, x, y, x + width, y + height, VG_TRUE); + for (i = 0; i < 4; i++) + memcpy(renderer->vertices[i][1], color, sizeof(VGfloat) * 4); + + renderer_quad_draw(renderer); +} + +/** + * End clearing and retore the states. + */ +void renderer_clear_end(struct renderer *renderer) +{ + assert(renderer->state == RENDERER_STATE_CLEAR); + + cso_restore_blend(renderer->cso); + cso_restore_fragment_shader(renderer->cso); + cso_restore_vertex_shader(renderer->cso); + + renderer->state = RENDERER_STATE_INIT; +} + +/** + * Prepare the renderer for image filtering. + */ +VGboolean renderer_filter_begin(struct renderer *renderer, + struct pipe_resource *dst, + VGboolean y0_top, + VGbitfield channel_mask, + const struct pipe_sampler_state **samplers, + struct pipe_sampler_view **views, + VGint num_samplers, + void *fs, + const void *const_buffer, + VGint const_buffer_len) +{ + struct pipe_surface *surf, surf_tmpl; + + assert(renderer->state == RENDERER_STATE_INIT); + + if (!fs) + return VG_FALSE; + if (!renderer_can_support(renderer, dst, PIPE_BIND_RENDER_TARGET)) + return VG_FALSE; + + u_surface_default_template(&surf_tmpl, dst, + PIPE_BIND_RENDER_TARGET); + surf = renderer->pipe->create_surface(renderer->pipe, dst, &surf_tmpl); + if (!surf) + return VG_FALSE; + + cso_save_framebuffer(renderer->cso); + cso_save_viewport(renderer->cso); + cso_save_blend(renderer->cso); + + /* set the image as the target */ + renderer_set_target(renderer, surf, NULL, y0_top); + pipe_surface_reference(&surf, NULL); + + renderer_set_blend(renderer, channel_mask); + + if (num_samplers) { + struct pipe_resource *tex; + + cso_save_samplers(renderer->cso); + cso_save_fragment_sampler_views(renderer->cso); + cso_save_fragment_shader(renderer->cso); + cso_save_vertex_shader(renderer->cso); + + renderer_set_custom_fs(renderer, fs, + samplers, views, num_samplers, + const_buffer, const_buffer_len); + renderer_set_vs(renderer, RENDERER_VS_TEXTURE); + + tex = views[0]->texture; + renderer->u.filter.tex_width = tex->width0; + renderer->u.filter.tex_height = tex->height0; + renderer->u.filter.use_sampler = VG_TRUE; + } + else { + cso_save_fragment_shader(renderer->cso); + + renderer_set_custom_fs(renderer, fs, NULL, NULL, 0, + const_buffer, const_buffer_len); + + renderer->u.filter.use_sampler = VG_FALSE; + } + + renderer_set_mvp(renderer, NULL); + + renderer->state = RENDERER_STATE_FILTER; + + return VG_TRUE; +} + +/** + * Draw into a rectangle of the destination with the specified region of the + * texture(s). + * + * The coordinates are in surface coordinates. + */ +void renderer_filter(struct renderer *renderer, + VGint x, VGint y, VGint w, VGint h, + VGint sx, VGint sy, VGint sw, VGint sh) +{ + assert(renderer->state == RENDERER_STATE_FILTER); + + renderer_quad_pos(renderer, x, y, x + w, y + h, VG_FALSE); + if (renderer->u.filter.use_sampler) { + renderer_quad_texcoord(renderer, sx, sy, sx + sw, sy + sh, + renderer->u.filter.tex_width, + renderer->u.filter.tex_height); + } + + renderer_quad_draw(renderer); +} + +/** + * End image filtering and restore the states. + */ +void renderer_filter_end(struct renderer *renderer) +{ + assert(renderer->state == RENDERER_STATE_FILTER); + + if (renderer->u.filter.use_sampler) { + cso_restore_samplers(renderer->cso); + cso_restore_fragment_sampler_views(renderer->cso); + cso_restore_vertex_shader(renderer->cso); + } + + cso_restore_framebuffer(renderer->cso); + cso_restore_viewport(renderer->cso); + cso_restore_blend(renderer->cso); + cso_restore_fragment_shader(renderer->cso); + + renderer->state = RENDERER_STATE_INIT; +} + +/** + * Prepare the renderer for polygon silhouette rendering. + */ +VGboolean renderer_polygon_stencil_begin(struct renderer *renderer, + struct pipe_vertex_element *velem, + VGFillRule rule, + VGboolean restore_dsa) +{ + struct pipe_depth_stencil_alpha_state *dsa; + VGboolean manual_two_sides; + + assert(renderer->state == RENDERER_STATE_INIT); + + cso_save_vertex_elements(renderer->cso); + cso_save_blend(renderer->cso); + cso_save_depth_stencil_alpha(renderer->cso); + + cso_set_vertex_elements(renderer->cso, 1, velem); + + /* disable color writes */ + renderer_set_blend(renderer, 0); + + manual_two_sides = VG_FALSE; + dsa = &renderer->u.polygon_stencil.dsa; + memset(dsa, 0, sizeof(*dsa)); + if (rule == VG_EVEN_ODD) { + dsa->stencil[0].enabled = 1; + dsa->stencil[0].writemask = 1; + dsa->stencil[0].fail_op = PIPE_STENCIL_OP_KEEP; + dsa->stencil[0].zfail_op = PIPE_STENCIL_OP_KEEP; + dsa->stencil[0].zpass_op = PIPE_STENCIL_OP_INVERT; + dsa->stencil[0].func = PIPE_FUNC_ALWAYS; + dsa->stencil[0].valuemask = ~0; + } + else { + assert(rule == VG_NON_ZERO); + + /* front face */ + dsa->stencil[0].enabled = 1; + dsa->stencil[0].writemask = ~0; + dsa->stencil[0].fail_op = PIPE_STENCIL_OP_KEEP; + dsa->stencil[0].zfail_op = PIPE_STENCIL_OP_KEEP; + dsa->stencil[0].zpass_op = PIPE_STENCIL_OP_INCR_WRAP; + dsa->stencil[0].func = PIPE_FUNC_ALWAYS; + dsa->stencil[0].valuemask = ~0; + + if (renderer->pipe->screen->get_param(renderer->pipe->screen, + PIPE_CAP_TWO_SIDED_STENCIL)) { + /* back face */ + dsa->stencil[1] = dsa->stencil[0]; + dsa->stencil[1].zpass_op = PIPE_STENCIL_OP_DECR_WRAP; + } + else { + manual_two_sides = VG_TRUE; + } + } + cso_set_depth_stencil_alpha(renderer->cso, dsa); + + if (manual_two_sides) + cso_save_rasterizer(renderer->cso); + + renderer->u.polygon_stencil.manual_two_sides = manual_two_sides; + renderer->u.polygon_stencil.restore_dsa = restore_dsa; + renderer->state = RENDERER_STATE_POLYGON_STENCIL; + + return VG_TRUE; +} + +/** + * Render a polygon silhouette to stencil buffer. + */ +void renderer_polygon_stencil(struct renderer *renderer, + struct pipe_vertex_buffer *vbuf, + VGuint mode, VGuint start, VGuint count) +{ + assert(renderer->state == RENDERER_STATE_POLYGON_STENCIL); + + renderer->pipe->set_vertex_buffers(renderer->pipe, 1, vbuf); + + if (!renderer->u.polygon_stencil.manual_two_sides) { + util_draw_arrays(renderer->pipe, mode, start, count); + } + else { + struct pipe_rasterizer_state raster; + struct pipe_depth_stencil_alpha_state dsa; + + raster = renderer->g3d.rasterizer; + dsa = renderer->u.polygon_stencil.dsa; + + /* front */ + raster.cull_face = PIPE_FACE_BACK; + dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_INCR_WRAP; + + cso_set_rasterizer(renderer->cso, &raster); + cso_set_depth_stencil_alpha(renderer->cso, &dsa); + util_draw_arrays(renderer->pipe, mode, start, count); + + /* back */ + raster.cull_face = PIPE_FACE_FRONT; + dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_DECR_WRAP; + + cso_set_rasterizer(renderer->cso, &raster); + cso_set_depth_stencil_alpha(renderer->cso, &dsa); + util_draw_arrays(renderer->pipe, mode, start, count); + } +} + +/** + * End polygon silhouette rendering. + */ +void renderer_polygon_stencil_end(struct renderer *renderer) +{ + assert(renderer->state == RENDERER_STATE_POLYGON_STENCIL); + + if (renderer->u.polygon_stencil.manual_two_sides) + cso_restore_rasterizer(renderer->cso); + + cso_restore_vertex_elements(renderer->cso); + + /* restore color writes */ + cso_restore_blend(renderer->cso); + + if (renderer->u.polygon_stencil.restore_dsa) + cso_restore_depth_stencil_alpha(renderer->cso); + + renderer->state = RENDERER_STATE_INIT; +} + +/** + * Prepare the renderer for polygon filling. + */ +VGboolean renderer_polygon_fill_begin(struct renderer *renderer, + VGboolean save_dsa) +{ + struct pipe_depth_stencil_alpha_state dsa; + + assert(renderer->state == RENDERER_STATE_INIT); + + if (save_dsa) + cso_save_depth_stencil_alpha(renderer->cso); + + /* setup stencil ops */ + memset(&dsa, 0, sizeof(dsa)); + dsa.stencil[0].enabled = 1; + dsa.stencil[0].func = PIPE_FUNC_NOTEQUAL; + dsa.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE; + dsa.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE; + dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE; + dsa.stencil[0].valuemask = ~0; + dsa.stencil[0].writemask = ~0; + dsa.depth = renderer->g3d.dsa.depth; + cso_set_depth_stencil_alpha(renderer->cso, &dsa); + + renderer->state = RENDERER_STATE_POLYGON_FILL; + + return VG_TRUE; +} + +/** + * Fill a polygon. + */ +void renderer_polygon_fill(struct renderer *renderer, + VGfloat min_x, VGfloat min_y, + VGfloat max_x, VGfloat max_y) +{ + assert(renderer->state == RENDERER_STATE_POLYGON_FILL); + + renderer_quad_pos(renderer, min_x, min_y, max_x, max_y, VG_TRUE); + renderer_quad_draw(renderer); +} + +/** + * End polygon filling. + */ +void renderer_polygon_fill_end(struct renderer *renderer) +{ + assert(renderer->state == RENDERER_STATE_POLYGON_FILL); + + cso_restore_depth_stencil_alpha(renderer->cso); + + renderer->state = RENDERER_STATE_INIT; +} + +struct renderer * renderer_create(struct vg_context *owner) +{ + struct renderer *renderer; + struct pipe_rasterizer_state *raster; + struct pipe_stencil_ref sr; + VGint i; + + renderer = CALLOC_STRUCT(renderer); + if (!renderer) + return NULL; + + renderer->pipe = owner->pipe; + renderer->cso = owner->cso_context; + + /* init vertex data that doesn't change */ + for (i = 0; i < 4; i++) + renderer->vertices[i][0][3] = 1.0f; /* w */ + + for (i = 0; i < 2; i++) { + renderer->velems[i].src_offset = i * 4 * sizeof(float); + renderer->velems[i].instance_divisor = 0; + renderer->velems[i].vertex_buffer_index = 0; + renderer->velems[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + } + cso_set_vertex_elements(renderer->cso, 2, renderer->velems); + + /* GL rasterization rules */ + raster = &renderer->g3d.rasterizer; + memset(raster, 0, sizeof(*raster)); + raster->gl_rasterization_rules = 1; + cso_set_rasterizer(renderer->cso, raster); + + /* fixed at 0 */ + memset(&sr, 0, sizeof(sr)); + cso_set_stencil_ref(renderer->cso, &sr); + + renderer_set_vs(renderer, RENDERER_VS_PLAIN); + + renderer->state = RENDERER_STATE_INIT; + + return renderer; +} + +void renderer_destroy(struct renderer *ctx) +{ + int i; + + for (i = 0; i < NUM_RENDERER_VS; i++) { + if (ctx->cached_vs[i]) + cso_delete_vertex_shader(ctx->cso, ctx->cached_vs[i]); + } + for (i = 0; i < NUM_RENDERER_FS; i++) { + if (ctx->cached_fs[i]) + cso_delete_fragment_shader(ctx->cso, ctx->cached_fs[i]); + } + + pipe_resource_reference(&ctx->vs_cbuf, NULL); + pipe_resource_reference(&ctx->fs_cbuf, NULL); + + FREE(ctx); +} + +static void update_clip_state(struct renderer *renderer, + const struct vg_state *state) +{ + struct pipe_depth_stencil_alpha_state *dsa = &renderer->g3d.dsa; + + memset(dsa, 0, sizeof(struct pipe_depth_stencil_alpha_state)); + + if (state->scissoring) { + struct pipe_framebuffer_state *fb = &renderer->g3d.fb; + int i; + + renderer_scissor_begin(renderer, VG_FALSE); + + for (i = 0; i < state->scissor_rects_num; ++i) { + const float x = state->scissor_rects[i * 4 + 0].f; + const float y = state->scissor_rects[i * 4 + 1].f; + const float width = state->scissor_rects[i * 4 + 2].f; + const float height = state->scissor_rects[i * 4 + 3].f; + VGint x0, y0, x1, y1, iw, ih; + + x0 = (VGint) x; + y0 = (VGint) y; + if (x0 < 0) + x0 = 0; + if (y0 < 0) + y0 = 0; + + /* note that x1 and y1 are exclusive */ + x1 = (VGint) ceilf(x + width); + y1 = (VGint) ceilf(y + height); + if (x1 > fb->width) + x1 = fb->width; + if (y1 > fb->height) + y1 = fb->height; + + iw = x1 - x0; + ih = y1 - y0; + if (iw > 0 && ih> 0 ) + renderer_scissor(renderer, x0, y0, iw, ih); + } + + renderer_scissor_end(renderer); + + dsa->depth.enabled = 1; /* glEnable(GL_DEPTH_TEST); */ + dsa->depth.writemask = 0;/*glDepthMask(FALSE);*/ + dsa->depth.func = PIPE_FUNC_GEQUAL; + } +} + +static void renderer_validate_blend(struct renderer *renderer, + const struct vg_state *state, + enum pipe_format fb_format) +{ + struct pipe_blend_state blend; + + memset(&blend, 0, sizeof(blend)); + blend.rt[0].colormask = PIPE_MASK_RGBA; + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; + + /* TODO alpha masking happens after blending? */ + + switch (state->blend_mode) { + case VG_BLEND_SRC: + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; + break; + case VG_BLEND_SRC_OVER: + if (!util_format_has_alpha(fb_format)) { + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_SRC_ALPHA; + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_INV_SRC_ALPHA; + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_INV_SRC_ALPHA; + blend.rt[0].blend_enable = 1; + } + break; + case VG_BLEND_SRC_IN: + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_DST_ALPHA; + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; + blend.rt[0].blend_enable = 1; + break; + case VG_BLEND_DST_IN: + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ZERO; + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ZERO; + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_SRC_ALPHA; + blend.rt[0].blend_enable = 1; + break; + case VG_BLEND_DST_OVER: + case VG_BLEND_MULTIPLY: + case VG_BLEND_SCREEN: + case VG_BLEND_DARKEN: + case VG_BLEND_LIGHTEN: + case VG_BLEND_ADDITIVE: + /* need a shader */ + break; + default: + assert(!"not implemented blend mode"); + break; + } + + cso_set_blend(renderer->cso, &blend); +} + +/** + * Propogate OpenVG state changes to the renderer. Only framebuffer, blending + * and scissoring states are relevant here. + */ +void renderer_validate(struct renderer *renderer, + VGbitfield dirty, + const struct st_framebuffer *stfb, + const struct vg_state *state) +{ + assert(renderer->state == RENDERER_STATE_INIT); + + dirty |= renderer->dirty; + renderer->dirty = 0; + + if (dirty & FRAMEBUFFER_DIRTY) { + struct pipe_framebuffer_state *fb = &renderer->g3d.fb; + struct matrix *proj = &renderer->projection; + + memset(fb, 0, sizeof(struct pipe_framebuffer_state)); + fb->width = stfb->width; + fb->height = stfb->height; + fb->nr_cbufs = 1; + fb->cbufs[0] = stfb->strb->surface; + fb->zsbuf = stfb->dsrb->surface; + + cso_set_framebuffer(renderer->cso, fb); + vg_set_viewport(renderer, VEGA_Y0_BOTTOM); + + matrix_load_identity(proj); + matrix_translate(proj, -1.0f, -1.0f); + matrix_scale(proj, 2.0f / fb->width, 2.0f / fb->height); + + /* we also got a new depth buffer */ + if (dirty & DEPTH_STENCIL_DIRTY) { + renderer->pipe->clear(renderer->pipe, + PIPE_CLEAR_DEPTHSTENCIL, NULL, 0.0, 0); + } + } + + /* must be last because it renders to the depth buffer*/ + if (dirty & DEPTH_STENCIL_DIRTY) { + update_clip_state(renderer, state); + cso_set_depth_stencil_alpha(renderer->cso, &renderer->g3d.dsa); + } + + if (dirty & BLEND_DIRTY) + renderer_validate_blend(renderer, state, stfb->strb->format); +} + +/** + * Prepare the renderer for OpenVG pipeline. + */ +void renderer_validate_for_shader(struct renderer *renderer, + const struct pipe_sampler_state **samplers, + struct pipe_sampler_view **views, + VGint num_samplers, + const struct matrix *modelview, + void *fs, + const void *const_buffer, + VGint const_buffer_len) +{ + struct matrix mvp = renderer->projection; + + /* will be used in POLYGON_STENCIL and POLYGON_FILL */ + matrix_mult(&mvp, modelview); + renderer_set_mvp(renderer, &mvp); + + renderer_set_custom_fs(renderer, fs, + samplers, views, num_samplers, + const_buffer, const_buffer_len); +} + +void renderer_validate_for_mask_rendering(struct renderer *renderer, + struct pipe_surface *dst, + const struct matrix *modelview) +{ + struct matrix mvp = renderer->projection; + + /* will be used in POLYGON_STENCIL and POLYGON_FILL */ + matrix_mult(&mvp, modelview); + renderer_set_mvp(renderer, &mvp); + + renderer_set_target(renderer, dst, renderer->g3d.fb.zsbuf, VG_FALSE); + renderer_set_blend(renderer, ~0); + renderer_set_fs(renderer, RENDERER_FS_WHITE); + + /* set internal dirty flags (hacky!) */ + renderer->dirty = FRAMEBUFFER_DIRTY | BLEND_DIRTY; +} + +void renderer_copy_surface(struct renderer *ctx, + struct pipe_surface *src, + int srcX0, int srcY0, + int srcX1, int srcY1, + struct pipe_surface *dst, + int dstX0, int dstY0, + int dstX1, int dstY1, + float z, unsigned filter) +{ + struct pipe_context *pipe = ctx->pipe; + struct pipe_screen *screen = pipe->screen; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; + struct pipe_box src_box; + struct pipe_resource texTemp, *tex; + const struct pipe_framebuffer_state *fb = &ctx->g3d.fb; + const int srcW = abs(srcX1 - srcX0); + const int srcH = abs(srcY1 - srcY0); + const int srcLeft = MIN2(srcX0, srcX1); + const int srcTop = MIN2(srcY0, srcY1); + + assert(filter == PIPE_TEX_MIPFILTER_NEAREST || + filter == PIPE_TEX_MIPFILTER_LINEAR); + + if (srcLeft != srcX0) { + /* left-right flip */ + int tmp = dstX0; + dstX0 = dstX1; + dstX1 = tmp; + } + + if (srcTop != srcY0) { + /* up-down flip */ + int tmp = dstY0; + dstY0 = dstY1; + dstY1 = tmp; + } + + assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE_2D, + 0, PIPE_BIND_SAMPLER_VIEW, 0)); + assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, + 0, PIPE_BIND_SAMPLER_VIEW, 0)); + assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, + 0, PIPE_BIND_RENDER_TARGET, 0)); + + /* + * XXX for now we're always creating a temporary texture. + * Strictly speaking that's not always needed. + */ + + /* create temp texture */ + memset(&texTemp, 0, sizeof(texTemp)); + texTemp.target = PIPE_TEXTURE_2D; + texTemp.format = src->format; + texTemp.last_level = 0; + texTemp.width0 = srcW; + texTemp.height0 = srcH; + texTemp.depth0 = 1; + texTemp.array_size = 1; + texTemp.bind = PIPE_BIND_SAMPLER_VIEW; + + tex = screen->resource_create(screen, &texTemp); + if (!tex) + return; + + u_sampler_view_default_template(&view_templ, tex, tex->format); + view = pipe->create_sampler_view(pipe, tex, &view_templ); + + if (!view) + return; + + u_box_2d_zslice(srcLeft, srcTop, src->u.tex.first_layer, srcW, srcH, &src_box); + + pipe->resource_copy_region(pipe, + tex, 0, 0, 0, 0, /* dest */ + src->texture, 0, &src_box); + + assert(floatsEqual(z, 0.0f)); + + /* draw */ + if (fb->cbufs[0] == dst) { + /* transform back to surface coordinates */ + dstY0 = dst->height - dstY0; + dstY1 = dst->height - dstY1; + + if (renderer_drawtex_begin(ctx, view)) { + renderer_drawtex(ctx, + dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0, + 0, 0, view->texture->width0, view->texture->height0); + renderer_drawtex_end(ctx); + } + } + else { + if (renderer_copy_begin(ctx, dst, VG_TRUE, view)) { + renderer_copy(ctx, + dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0, + 0, 0, view->texture->width0, view->texture->height0); + renderer_copy_end(ctx); + } + } +} + +void renderer_texture_quad(struct renderer *r, + struct pipe_resource *tex, + VGfloat x1offset, VGfloat y1offset, + VGfloat x2offset, VGfloat y2offset, + VGfloat x1, VGfloat y1, + VGfloat x2, VGfloat y2, + VGfloat x3, VGfloat y3, + VGfloat x4, VGfloat y4) +{ + const VGfloat z = 0.0f; + + assert(r->state == RENDERER_STATE_INIT); + assert(tex->width0 != 0); + assert(tex->height0 != 0); + + cso_save_vertex_shader(r->cso); + + renderer_set_vs(r, RENDERER_VS_TEXTURE); + + /* manually set up positions */ + r->vertices[0][0][0] = x1; + r->vertices[0][0][1] = y1; + r->vertices[0][0][2] = z; + + r->vertices[1][0][0] = x2; + r->vertices[1][0][1] = y2; + r->vertices[1][0][2] = z; + + r->vertices[2][0][0] = x3; + r->vertices[2][0][1] = y3; + r->vertices[2][0][2] = z; + + r->vertices[3][0][0] = x4; + r->vertices[3][0][1] = y4; + r->vertices[3][0][2] = z; + + /* texcoords */ + renderer_quad_texcoord(r, x1offset, y1offset, + x2offset, y2offset, tex->width0, tex->height0); + + renderer_quad_draw(r); + + cso_restore_vertex_shader(r->cso); +} diff --git a/src/gallium/state_trackers/vega/renderer.h b/src/gallium/state_trackers/vega/renderer.h new file mode 100644 index 0000000..fe71993 --- /dev/null +++ b/src/gallium/state_trackers/vega/renderer.h @@ -0,0 +1,159 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. All Rights Reserved. + * Copyright 2010 LunarG, 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 RENDERER_H +#define RENDERER_H + +#include "VG/openvg.h" + +struct renderer; + +struct vg_context; +struct vg_state; +struct st_framebuffer; +struct pipe_resource; +struct pipe_sampler_state; +struct pipe_sampler_view; +struct pipe_surface; +struct pipe_vertex_element; +struct pipe_vertex_buffer; +struct matrix; + +struct renderer *renderer_create(struct vg_context *owner); +void renderer_destroy(struct renderer *); + +void renderer_validate(struct renderer *renderer, + VGbitfield dirty, + const struct st_framebuffer *stfb, + const struct vg_state *state); + +void renderer_validate_for_shader(struct renderer *renderer, + const struct pipe_sampler_state **samplers, + struct pipe_sampler_view **views, + VGint num_samplers, + const struct matrix *modelview, + void *fs, + const void *const_buffer, + VGint const_buffer_len); + +void renderer_validate_for_mask_rendering(struct renderer *renderer, + struct pipe_surface *dst, + const struct matrix *modelview); + +VGboolean renderer_copy_begin(struct renderer *renderer, + struct pipe_surface *dst, + VGboolean y0_top, + struct pipe_sampler_view *src); + +void renderer_copy(struct renderer *renderer, + VGint x, VGint y, VGint w, VGint h, + VGint sx, VGint sy, VGint sw, VGint sh); + +void renderer_copy_end(struct renderer *renderer); + +VGboolean renderer_drawtex_begin(struct renderer *renderer, + struct pipe_sampler_view *src); + +void renderer_drawtex(struct renderer *renderer, + VGint x, VGint y, VGint w, VGint h, + VGint sx, VGint sy, VGint sw, VGint sh); + +void renderer_drawtex_end(struct renderer *renderer); + +VGboolean renderer_scissor_begin(struct renderer *renderer, + VGboolean restore_dsa); + +void renderer_scissor(struct renderer *renderer, + VGint x, VGint y, VGint width, VGint height); + +void renderer_scissor_end(struct renderer *renderer); + +VGboolean renderer_clear_begin(struct renderer *renderer); + +void renderer_clear(struct renderer *renderer, + VGint x, VGint y, VGint width, VGint height, + const VGfloat color[4]); + +void renderer_clear_end(struct renderer *renderer); + +VGboolean renderer_filter_begin(struct renderer *renderer, + struct pipe_resource *dst, + VGboolean y0_top, + VGbitfield channel_mask, + const struct pipe_sampler_state **samplers, + struct pipe_sampler_view **views, + VGint num_samplers, + void *fs, + const void *const_buffer, + VGint const_buffer_len); + +void renderer_filter(struct renderer *renderer, + VGint x, VGint y, VGint w, VGint h, + VGint sx, VGint sy, VGint sw, VGint sh); + +void renderer_filter_end(struct renderer *renderer); + +VGboolean renderer_polygon_stencil_begin(struct renderer *renderer, + struct pipe_vertex_element *velem, + VGFillRule rule, + VGboolean restore_dsa); + +void renderer_polygon_stencil(struct renderer *renderer, + struct pipe_vertex_buffer *vbuf, + VGuint mode, VGuint start, VGuint count); + +void renderer_polygon_stencil_end(struct renderer *renderer); + +VGboolean renderer_polygon_fill_begin(struct renderer *renderer, + VGboolean save_dsa); + +void renderer_polygon_fill(struct renderer *renderer, + VGfloat min_x, VGfloat min_y, + VGfloat max_x, VGfloat max_y); + +void renderer_polygon_fill_end(struct renderer *renderer); + +void renderer_texture_quad(struct renderer *, + struct pipe_resource *texture, + VGfloat x1offset, VGfloat y1offset, + VGfloat x2offset, VGfloat y2offset, + VGfloat x1, VGfloat y1, + VGfloat x2, VGfloat y2, + VGfloat x3, VGfloat y3, + VGfloat x4, VGfloat y4); + +void renderer_copy_surface(struct renderer *r, + struct pipe_surface *src, + int sx1, int sy1, + int sx2, int sy2, + struct pipe_surface *dst, + int dx1, int dy1, + int dx2, int dy2, + float z, unsigned filter); + + +#endif diff --git a/src/gallium/state_trackers/vega/shader.c b/src/gallium/state_trackers/vega/shader.c new file mode 100644 index 0000000..0ed7213 --- /dev/null +++ b/src/gallium/state_trackers/vega/shader.c @@ -0,0 +1,406 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "shader.h" + +#include "vg_context.h" +#include "shaders_cache.h" +#include "paint.h" +#include "mask.h" +#include "image.h" +#include "renderer.h" + +#include "pipe/p_context.h" +#include "pipe/p_screen.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_format.h" + +#define MAX_CONSTANTS 28 + +struct shader { + struct vg_context *context; + + VGboolean color_transform; + VGboolean masking; + struct vg_paint *paint; + struct vg_image *image; + + struct matrix modelview; + struct matrix paint_matrix; + + VGboolean drawing_image; + VGImageMode image_mode; + + float constants[MAX_CONSTANTS]; + struct pipe_resource *cbuf; + struct pipe_shader_state fs_state; + void *fs; +}; + +struct shader * shader_create(struct vg_context *ctx) +{ + struct shader *shader = 0; + + shader = CALLOC_STRUCT(shader); + shader->context = ctx; + + return shader; +} + +void shader_destroy(struct shader *shader) +{ + FREE(shader); +} + +void shader_set_color_transform(struct shader *shader, VGboolean set) +{ + shader->color_transform = set; +} + +void shader_set_masking(struct shader *shader, VGboolean set) +{ + shader->masking = set; +} + +VGboolean shader_is_masking(struct shader *shader) +{ + return shader->masking; +} + +void shader_set_paint(struct shader *shader, struct vg_paint *paint) +{ + shader->paint = paint; +} + +struct vg_paint * shader_paint(struct shader *shader) +{ + return shader->paint; +} + +static VGint setup_constant_buffer(struct shader *shader) +{ + const struct vg_state *state = &shader->context->state.vg; + VGint param_bytes = paint_constant_buffer_size(shader->paint); + VGint i; + + param_bytes += sizeof(VGfloat) * 8; + assert(param_bytes <= sizeof(shader->constants)); + + if (state->color_transform) { + for (i = 0; i < 8; i++) { + VGfloat val = (i < 4) ? 127.0f : 1.0f; + shader->constants[i] = + CLAMP(state->color_transform_values[i], -val, val); + } + } + else { + memset(shader->constants, 0, sizeof(VGfloat) * 8); + } + + paint_fill_constant_buffer(shader->paint, + &shader->paint_matrix, shader->constants + 8); + + return param_bytes; +} + +static VGboolean blend_use_shader(struct vg_context *ctx) +{ + VGboolean advanced_blending; + + switch (ctx->state.vg.blend_mode) { + case VG_BLEND_SRC_OVER: + advanced_blending = + util_format_has_alpha(ctx->draw_buffer->strb->format); + break; + case VG_BLEND_DST_OVER: + case VG_BLEND_MULTIPLY: + case VG_BLEND_SCREEN: + case VG_BLEND_DARKEN: + case VG_BLEND_LIGHTEN: + case VG_BLEND_ADDITIVE: + advanced_blending = VG_TRUE; + break; + default: + advanced_blending = VG_FALSE; + break; + } + + return advanced_blending; +} + +static VGint blend_bind_samplers(struct vg_context *ctx, + struct pipe_sampler_state **samplers, + struct pipe_sampler_view **sampler_views) +{ + if (blend_use_shader(ctx)) { + samplers[2] = &ctx->blend_sampler; + sampler_views[2] = vg_prepare_blend_surface(ctx); + + if (!samplers[0] || !sampler_views[0]) { + samplers[0] = samplers[2]; + sampler_views[0] = sampler_views[2]; + } + if (!samplers[1] || !sampler_views[1]) { + samplers[1] = samplers[0]; + sampler_views[1] = sampler_views[0]; + } + + return 1; + } + return 0; +} + +static VGint setup_samplers(struct shader *shader, + struct pipe_sampler_state **samplers, + struct pipe_sampler_view **sampler_views) +{ + struct vg_context *ctx = shader->context; + /* a little wonky: we use the num as a boolean that just says + * whether any sampler/textures have been set. the actual numbering + * for samplers is always the same: + * 0 - paint sampler/texture for gradient/pattern + * 1 - mask sampler/texture + * 2 - blend sampler/texture + * 3 - image sampler/texture + * */ + VGint num = 0; + + samplers[0] = NULL; + samplers[1] = NULL; + samplers[2] = NULL; + samplers[3] = NULL; + sampler_views[0] = NULL; + sampler_views[1] = NULL; + sampler_views[2] = NULL; + sampler_views[3] = NULL; + + num += paint_bind_samplers(shader->paint, samplers, sampler_views); + num += mask_bind_samplers(samplers, sampler_views); + num += blend_bind_samplers(ctx, samplers, sampler_views); + if (shader->drawing_image && shader->image) + num += image_bind_samplers(shader->image, samplers, sampler_views); + + return (num) ? 4 : 0; +} + +static INLINE VGboolean is_format_bw(struct shader *shader) +{ +#if 0 + struct vg_context *ctx = shader->context; + struct st_framebuffer *stfb = ctx->draw_buffer; +#endif + + if (shader->drawing_image && shader->image) { + if (shader->image->format == VG_BW_1) + return VG_TRUE; + } + + return VG_FALSE; +} + +static void setup_shader_program(struct shader *shader) +{ + struct vg_context *ctx = shader->context; + VGint shader_id = 0; + VGBlendMode blend_mode = ctx->state.vg.blend_mode; + VGboolean black_white = is_format_bw(shader); + + /* 1st stage: fill */ + if (!shader->drawing_image || + (shader->image_mode == VG_DRAW_IMAGE_MULTIPLY || shader->image_mode == VG_DRAW_IMAGE_STENCIL)) { + switch(paint_type(shader->paint)) { + case VG_PAINT_TYPE_COLOR: + shader_id |= VEGA_SOLID_FILL_SHADER; + break; + case VG_PAINT_TYPE_LINEAR_GRADIENT: + shader_id |= VEGA_LINEAR_GRADIENT_SHADER; + break; + case VG_PAINT_TYPE_RADIAL_GRADIENT: + shader_id |= VEGA_RADIAL_GRADIENT_SHADER; + break; + case VG_PAINT_TYPE_PATTERN: + shader_id |= VEGA_PATTERN_SHADER; + break; + + default: + abort(); + } + + if (paint_is_degenerate(shader->paint)) + shader_id = VEGA_PAINT_DEGENERATE_SHADER; + } + + /* second stage image */ + if (shader->drawing_image) { + switch(shader->image_mode) { + case VG_DRAW_IMAGE_NORMAL: + shader_id |= VEGA_IMAGE_NORMAL_SHADER; + break; + case VG_DRAW_IMAGE_MULTIPLY: + shader_id |= VEGA_IMAGE_MULTIPLY_SHADER; + break; + case VG_DRAW_IMAGE_STENCIL: + shader_id |= VEGA_IMAGE_STENCIL_SHADER; + break; + default: + debug_printf("Unknown image mode!"); + } + } + + if (shader->color_transform) + shader_id |= VEGA_COLOR_TRANSFORM_SHADER; + + if (blend_use_shader(ctx)) { + if (shader->drawing_image && shader->image_mode == VG_DRAW_IMAGE_STENCIL) + shader_id |= VEGA_ALPHA_PER_CHANNEL_SHADER; + else + shader_id |= VEGA_ALPHA_NORMAL_SHADER; + + switch(blend_mode) { + case VG_BLEND_SRC: + shader_id |= VEGA_BLEND_SRC_SHADER; + break; + case VG_BLEND_SRC_OVER: + shader_id |= VEGA_BLEND_SRC_OVER_SHADER; + break; + case VG_BLEND_DST_OVER: + shader_id |= VEGA_BLEND_DST_OVER_SHADER; + break; + case VG_BLEND_SRC_IN: + shader_id |= VEGA_BLEND_SRC_IN_SHADER; + break; + case VG_BLEND_DST_IN: + shader_id |= VEGA_BLEND_DST_IN_SHADER; + break; + case VG_BLEND_MULTIPLY: + shader_id |= VEGA_BLEND_MULTIPLY_SHADER; + break; + case VG_BLEND_SCREEN: + shader_id |= VEGA_BLEND_SCREEN_SHADER; + break; + case VG_BLEND_DARKEN: + shader_id |= VEGA_BLEND_DARKEN_SHADER; + break; + case VG_BLEND_LIGHTEN: + shader_id |= VEGA_BLEND_LIGHTEN_SHADER; + break; + case VG_BLEND_ADDITIVE: + shader_id |= VEGA_BLEND_ADDITIVE_SHADER; + break; + default: + assert(0); + break; + } + } + else { + /* update alpha of the source */ + if (shader->drawing_image && shader->image_mode == VG_DRAW_IMAGE_STENCIL) + shader_id |= VEGA_ALPHA_PER_CHANNEL_SHADER; + } + + if (shader->masking) + shader_id |= VEGA_MASK_SHADER; + + if (black_white) + shader_id |= VEGA_BW_SHADER; + + shader->fs = shaders_cache_fill(ctx->sc, shader_id); +} + + +void shader_bind(struct shader *shader) +{ + struct vg_context *ctx = shader->context; + struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; + VGint num_samplers, param_bytes; + + /* first resolve the real paint type */ + paint_resolve_type(shader->paint); + + num_samplers = setup_samplers(shader, samplers, sampler_views); + param_bytes = setup_constant_buffer(shader); + setup_shader_program(shader); + + renderer_validate_for_shader(ctx->renderer, + (const struct pipe_sampler_state **) samplers, + sampler_views, num_samplers, + &shader->modelview, + shader->fs, (const void *) shader->constants, param_bytes); +} + +void shader_set_image_mode(struct shader *shader, VGImageMode image_mode) +{ + shader->image_mode = image_mode; +} + +VGImageMode shader_image_mode(struct shader *shader) +{ + return shader->image_mode; +} + +void shader_set_drawing_image(struct shader *shader, VGboolean drawing_image) +{ + shader->drawing_image = drawing_image; +} + +VGboolean shader_drawing_image(struct shader *shader) +{ + return shader->drawing_image; +} + +void shader_set_image(struct shader *shader, struct vg_image *img) +{ + shader->image = img; +} + +/** + * Set the transformation to map a vertex to the surface coordinates. + */ +void shader_set_surface_matrix(struct shader *shader, + const struct matrix *mat) +{ + shader->modelview = *mat; +} + +/** + * Set the transformation to map a pixel to the paint coordinates. + */ +void shader_set_paint_matrix(struct shader *shader, const struct matrix *mat) +{ + const struct st_framebuffer *stfb = shader->context->draw_buffer; + const VGfloat px_center_offset = 0.5f; + + memcpy(&shader->paint_matrix, mat, sizeof(*mat)); + + /* make it window-to-paint for the shaders */ + matrix_translate(&shader->paint_matrix, px_center_offset, + stfb->height - 1.0f + px_center_offset); + matrix_scale(&shader->paint_matrix, 1.0f, -1.0f); +} diff --git a/src/gallium/state_trackers/vega/shader.h b/src/gallium/state_trackers/vega/shader.h new file mode 100644 index 0000000..8b97e53 --- /dev/null +++ b/src/gallium/state_trackers/vega/shader.h @@ -0,0 +1,63 @@ +/************************************************************************** + * + * 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 SHADER_H +#define SHADER_H + +#include "VG/openvg.h" + +struct shader; +struct vg_paint; +struct vg_context; +struct vg_image; +struct matrix; + +struct shader *shader_create(struct vg_context *context); +void shader_destroy(struct shader *shader); + +void shader_set_color_transform(struct shader *shader, VGboolean set); + +void shader_set_masking(struct shader *shader, VGboolean set); +VGboolean shader_is_masking(struct shader *shader); + +void shader_set_paint(struct shader *shader, struct vg_paint *paint); +struct vg_paint *shader_paint(struct shader *shader); + +void shader_set_image_mode(struct shader *shader, VGImageMode image_mode); +VGImageMode shader_image_mode(struct shader *shader); + +void shader_set_drawing_image(struct shader *shader, VGboolean drawing_image); +VGboolean shader_drawing_image(struct shader *shader); + +void shader_set_image(struct shader *shader, struct vg_image *img); + +void shader_set_surface_matrix(struct shader *shader, + const struct matrix *mat); +void shader_set_paint_matrix(struct shader *shader, const struct matrix *mat); + +void shader_bind(struct shader *shader); + +#endif diff --git a/src/gallium/state_trackers/vega/shaders_cache.c b/src/gallium/state_trackers/vega/shaders_cache.c new file mode 100644 index 0000000..023996c --- /dev/null +++ b/src/gallium/state_trackers/vega/shaders_cache.c @@ -0,0 +1,461 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "shaders_cache.h" + +#include "vg_context.h" + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_shader_tokens.h" + +#include "tgsi/tgsi_build.h" +#include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_parse.h" +#include "tgsi/tgsi_util.h" +#include "tgsi/tgsi_text.h" + +#include "util/u_memory.h" +#include "util/u_math.h" +#include "util/u_debug.h" +#include "cso_cache/cso_hash.h" +#include "cso_cache/cso_context.h" + +#include "VG/openvg.h" + +#include "asm_fill.h" + +/* Essentially we construct an ubber-shader based on the state + * of the pipeline. The stages are: + * 1) Paint generation (color/gradient/pattern) + * 2) Image composition (normal/multiply/stencil) + * 3) Color transform + * 4) Per-channel alpha generation + * 5) Extended blend (multiply/screen/darken/lighten) + * 6) Mask + * 7) Premultiply/Unpremultiply + * 8) Color transform (to black and white) + */ +#define SHADER_STAGES 8 + +struct cached_shader { + void *driver_shader; + struct pipe_shader_state state; +}; + +struct shaders_cache { + struct vg_context *pipe; + + struct cso_hash *hash; +}; + + +static INLINE struct tgsi_token *tokens_from_assembly(const char *txt, int num_tokens) +{ + struct tgsi_token *tokens; + + tokens = (struct tgsi_token *) MALLOC(num_tokens * sizeof(tokens[0])); + + tgsi_text_translate(txt, tokens, num_tokens); + +#if DEBUG_SHADERS + tgsi_dump(tokens, 0); +#endif + + return tokens; +} + +/* +static const char max_shader_preamble[] = + "FRAG\n" + "DCL IN[0], POSITION, LINEAR\n" + "DCL IN[1], GENERIC[0], PERSPECTIVE\n" + "DCL OUT[0], COLOR, CONSTANT\n" + "DCL CONST[0..9], CONSTANT\n" + "DCL TEMP[0..9], CONSTANT\n" + "DCL SAMP[0..9], CONSTANT\n"; + + max_shader_preamble strlen == 175 +*/ +#define MAX_PREAMBLE 175 + +static INLINE VGint range_min(VGint min, VGint current) +{ + if (min < 0) + min = current; + else + min = MIN2(min, current); + return min; +} + +static INLINE VGint range_max(VGint max, VGint current) +{ + return MAX2(max, current); +} + +static void * +combine_shaders(const struct shader_asm_info *shaders[SHADER_STAGES], int num_shaders, + struct pipe_context *pipe, + struct pipe_shader_state *shader) +{ + VGboolean declare_input = VG_FALSE; + VGint start_const = -1, end_const = 0; + VGint start_temp = -1, end_temp = 0; + VGint start_sampler = -1, end_sampler = 0; + VGint i, current_shader = 0; + VGint num_consts, num_temps, num_samplers; + struct ureg_program *ureg; + struct ureg_src in[2]; + struct ureg_src *sampler = NULL; + struct ureg_src *constant = NULL; + struct ureg_dst out, *temp = NULL; + void *p = NULL; + + for (i = 0; i < num_shaders; ++i) { + if (shaders[i]->num_consts) + start_const = range_min(start_const, shaders[i]->start_const); + if (shaders[i]->num_temps) + start_temp = range_min(start_temp, shaders[i]->start_temp); + if (shaders[i]->num_samplers) + start_sampler = range_min(start_sampler, shaders[i]->start_sampler); + + end_const = range_max(end_const, shaders[i]->start_const + + shaders[i]->num_consts); + end_temp = range_max(end_temp, shaders[i]->start_temp + + shaders[i]->num_temps); + end_sampler = range_max(end_sampler, shaders[i]->start_sampler + + shaders[i]->num_samplers); + if (shaders[i]->needs_position) + declare_input = VG_TRUE; + } + /* if they're still unitialized, initialize them */ + if (start_const < 0) + start_const = 0; + if (start_temp < 0) + start_temp = 0; + if (start_sampler < 0) + start_sampler = 0; + + num_consts = end_const - start_const; + num_temps = end_temp - start_temp; + num_samplers = end_sampler - start_sampler; + + ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT); + if (!ureg) + return NULL; + + if (declare_input) { + in[0] = ureg_DECL_fs_input(ureg, + TGSI_SEMANTIC_POSITION, + 0, + TGSI_INTERPOLATE_LINEAR); + in[1] = ureg_DECL_fs_input(ureg, + TGSI_SEMANTIC_GENERIC, + 0, + TGSI_INTERPOLATE_PERSPECTIVE); + } + + /* we always have a color output */ + out = ureg_DECL_output(ureg, TGSI_SEMANTIC_COLOR, 0); + + if (num_consts >= 1) { + constant = (struct ureg_src *) malloc(sizeof(struct ureg_src) * end_const); + for (i = start_const; i < end_const; i++) { + constant[i] = ureg_DECL_constant(ureg, i); + } + + } + + if (num_temps >= 1) { + temp = (struct ureg_dst *) malloc(sizeof(struct ureg_dst) * end_temp); + for (i = start_temp; i < end_temp; i++) { + temp[i] = ureg_DECL_temporary(ureg); + } + } + + if (num_samplers >= 1) { + sampler = (struct ureg_src *) malloc(sizeof(struct ureg_src) * end_sampler); + for (i = start_sampler; i < end_sampler; i++) { + sampler[i] = ureg_DECL_sampler(ureg, i); + } + } + + while (current_shader < num_shaders) { + if ((current_shader + 1) == num_shaders) { + shaders[current_shader]->func(ureg, + &out, + in, + sampler, + temp, + constant); + } else { + shaders[current_shader]->func(ureg, + &temp[0], + in, + sampler, + temp, + constant); + } + current_shader++; + } + + ureg_END(ureg); + + shader->tokens = ureg_finalize(ureg); + if(!shader->tokens) + return NULL; + + p = pipe->create_fs_state(pipe, shader); + ureg_destroy(ureg); + + if (num_temps >= 1) { + for (i = start_temp; i < end_temp; i++) { + ureg_release_temporary(ureg, temp[i]); + } + } + + if (temp) + free(temp); + if (constant) + free(constant); + if (sampler) + free(sampler); + + return p; +} + +static void * +create_shader(struct pipe_context *pipe, + int id, + struct pipe_shader_state *shader) +{ + int idx = 0, sh; + const struct shader_asm_info * shaders[SHADER_STAGES]; + + /* first stage */ + sh = SHADERS_GET_PAINT_SHADER(id); + switch (sh << SHADERS_PAINT_SHIFT) { + case VEGA_SOLID_FILL_SHADER: + case VEGA_LINEAR_GRADIENT_SHADER: + case VEGA_RADIAL_GRADIENT_SHADER: + case VEGA_PATTERN_SHADER: + case VEGA_PAINT_DEGENERATE_SHADER: + shaders[idx] = &shaders_paint_asm[(sh >> SHADERS_PAINT_SHIFT) - 1]; + assert(shaders[idx]->id == sh); + idx++; + break; + default: + break; + } + + /* second stage */ + sh = SHADERS_GET_IMAGE_SHADER(id); + switch (sh) { + case VEGA_IMAGE_NORMAL_SHADER: + case VEGA_IMAGE_MULTIPLY_SHADER: + case VEGA_IMAGE_STENCIL_SHADER: + shaders[idx] = &shaders_image_asm[(sh >> SHADERS_IMAGE_SHIFT) - 1]; + assert(shaders[idx]->id == sh); + idx++; + break; + default: + break; + } + + /* sanity check */ + assert(idx == ((!sh || sh == VEGA_IMAGE_NORMAL_SHADER) ? 1 : 2)); + + /* third stage */ + sh = SHADERS_GET_COLOR_TRANSFORM_SHADER(id); + switch (sh) { + case VEGA_COLOR_TRANSFORM_SHADER: + shaders[idx] = &shaders_color_transform_asm[ + (sh >> SHADERS_COLOR_TRANSFORM_SHIFT) - 1]; + assert(shaders[idx]->id == sh); + idx++; + break; + default: + break; + } + + /* fourth stage */ + sh = SHADERS_GET_ALPHA_SHADER(id); + switch (sh) { + case VEGA_ALPHA_NORMAL_SHADER: + case VEGA_ALPHA_PER_CHANNEL_SHADER: + shaders[idx] = &shaders_alpha_asm[ + (sh >> SHADERS_ALPHA_SHIFT) - 1]; + assert(shaders[idx]->id == sh); + idx++; + break; + default: + break; + } + + /* fifth stage */ + sh = SHADERS_GET_BLEND_SHADER(id); + switch (sh) { + case VEGA_BLEND_SRC_SHADER: + case VEGA_BLEND_SRC_OVER_SHADER: + case VEGA_BLEND_DST_OVER_SHADER: + case VEGA_BLEND_SRC_IN_SHADER: + case VEGA_BLEND_DST_IN_SHADER: + case VEGA_BLEND_MULTIPLY_SHADER: + case VEGA_BLEND_SCREEN_SHADER: + case VEGA_BLEND_DARKEN_SHADER: + case VEGA_BLEND_LIGHTEN_SHADER: + case VEGA_BLEND_ADDITIVE_SHADER: + shaders[idx] = &shaders_blend_asm[(sh >> SHADERS_BLEND_SHIFT) - 1]; + assert(shaders[idx]->id == sh); + idx++; + break; + default: + break; + } + + /* sixth stage */ + sh = SHADERS_GET_MASK_SHADER(id); + switch (sh) { + case VEGA_MASK_SHADER: + shaders[idx] = &shaders_mask_asm[(sh >> SHADERS_MASK_SHIFT) - 1]; + assert(shaders[idx]->id == sh); + idx++; + break; + default: + break; + } + + /* seventh stage */ + sh = SHADERS_GET_PREMULTIPLY_SHADER(id); + switch (sh) { + case VEGA_PREMULTIPLY_SHADER: + case VEGA_UNPREMULTIPLY_SHADER: + shaders[idx] = &shaders_premultiply_asm[ + (sh >> SHADERS_PREMULTIPLY_SHIFT) - 1]; + assert(shaders[idx]->id == sh); + idx++; + break; + default: + break; + } + + /* eighth stage */ + sh = SHADERS_GET_BW_SHADER(id); + switch (sh) { + case VEGA_BW_SHADER: + shaders[idx] = &shaders_bw_asm[(sh >> SHADERS_BW_SHIFT) - 1]; + assert(shaders[idx]->id == sh); + idx++; + break; + default: + break; + } + + return combine_shaders(shaders, idx, pipe, shader); +} + +/*************************************************/ + +struct shaders_cache * shaders_cache_create(struct vg_context *vg) +{ + struct shaders_cache *sc = CALLOC_STRUCT(shaders_cache); + + sc->pipe = vg; + sc->hash = cso_hash_create(); + + return sc; +} + +void shaders_cache_destroy(struct shaders_cache *sc) +{ + struct cso_hash_iter iter = cso_hash_first_node(sc->hash); + + while (!cso_hash_iter_is_null(iter)) { + struct cached_shader *cached = + (struct cached_shader *)cso_hash_iter_data(iter); + cso_delete_fragment_shader(sc->pipe->cso_context, + cached->driver_shader); + iter = cso_hash_erase(sc->hash, iter); + } + + cso_hash_delete(sc->hash); + FREE(sc); +} + +void * shaders_cache_fill(struct shaders_cache *sc, + int shader_key) +{ + VGint key = shader_key; + struct cached_shader *cached; + struct cso_hash_iter iter = cso_hash_find(sc->hash, key); + + if (cso_hash_iter_is_null(iter)) { + cached = CALLOC_STRUCT(cached_shader); + cached->driver_shader = create_shader(sc->pipe->pipe, key, &cached->state); + + cso_hash_insert(sc->hash, key, cached); + + return cached->driver_shader; + } + + cached = (struct cached_shader *)cso_hash_iter_data(iter); + + assert(cached->driver_shader); + return cached->driver_shader; +} + +struct vg_shader * shader_create_from_text(struct pipe_context *pipe, + const char *txt, int num_tokens, + int type) +{ + struct vg_shader *shader = (struct vg_shader *)MALLOC( + sizeof(struct vg_shader)); + struct tgsi_token *tokens = tokens_from_assembly(txt, num_tokens); + struct pipe_shader_state state; + + debug_assert(type == PIPE_SHADER_VERTEX || + type == PIPE_SHADER_FRAGMENT); + + state.tokens = tokens; + shader->type = type; + shader->tokens = tokens; + + if (type == PIPE_SHADER_FRAGMENT) + shader->driver = pipe->create_fs_state(pipe, &state); + else + shader->driver = pipe->create_vs_state(pipe, &state); + return shader; +} + +void vg_shader_destroy(struct vg_context *ctx, struct vg_shader *shader) +{ + if (shader->type == PIPE_SHADER_FRAGMENT) + cso_delete_fragment_shader(ctx->cso_context, shader->driver); + else + cso_delete_vertex_shader(ctx->cso_context, shader->driver); + FREE(shader->tokens); + FREE(shader); +} diff --git a/src/gallium/state_trackers/vega/shaders_cache.h b/src/gallium/state_trackers/vega/shaders_cache.h new file mode 100644 index 0000000..05014f2 --- /dev/null +++ b/src/gallium/state_trackers/vega/shaders_cache.h @@ -0,0 +1,120 @@ +/************************************************************************** + * + * 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 SHADERS_CACHE_H +#define SHADERS_CACHE_H + + +struct vg_context; +struct pipe_context; +struct tgsi_token; +struct shaders_cache; + +#define _SHADERS_PAINT_BITS 3 +#define _SHADERS_IMAGE_BITS 2 +#define _SHADERS_COLOR_TRANSFORM_BITS 1 +#define _SHADERS_ALPHA_BITS 2 +#define _SHADERS_BLEND_BITS 4 +#define _SHADERS_MASK_BITS 1 +#define _SHADERS_PREMULTIPLY_BITS 2 +#define _SHADERS_BW_BITS 1 + +#define SHADERS_PAINT_SHIFT (0) +#define SHADERS_IMAGE_SHIFT (SHADERS_PAINT_SHIFT + _SHADERS_PAINT_BITS) +#define SHADERS_COLOR_TRANSFORM_SHIFT (SHADERS_IMAGE_SHIFT + _SHADERS_IMAGE_BITS) +#define SHADERS_ALPHA_SHIFT (SHADERS_COLOR_TRANSFORM_SHIFT + _SHADERS_COLOR_TRANSFORM_BITS) +#define SHADERS_BLEND_SHIFT (SHADERS_ALPHA_SHIFT + _SHADERS_ALPHA_BITS) +#define SHADERS_MASK_SHIFT (SHADERS_BLEND_SHIFT + _SHADERS_BLEND_BITS) +#define SHADERS_PREMULTIPLY_SHIFT (SHADERS_MASK_SHIFT + _SHADERS_MASK_BITS) +#define SHADERS_BW_SHIFT (SHADERS_PREMULTIPLY_SHIFT + _SHADERS_PREMULTIPLY_BITS) + +#define _SHADERS_GET_STAGE(stage, id) \ + ((id) & (((1 << _SHADERS_ ## stage ## _BITS) - 1) << SHADERS_ ## stage ## _SHIFT)) + +#define SHADERS_GET_PAINT_SHADER(id) _SHADERS_GET_STAGE(PAINT, id) +#define SHADERS_GET_IMAGE_SHADER(id) _SHADERS_GET_STAGE(IMAGE, id) +#define SHADERS_GET_COLOR_TRANSFORM_SHADER(id) _SHADERS_GET_STAGE(COLOR_TRANSFORM, id) +#define SHADERS_GET_ALPHA_SHADER(id) _SHADERS_GET_STAGE(ALPHA, id) +#define SHADERS_GET_BLEND_SHADER(id) _SHADERS_GET_STAGE(BLEND, id) +#define SHADERS_GET_MASK_SHADER(id) _SHADERS_GET_STAGE(MASK, id) +#define SHADERS_GET_PREMULTIPLY_SHADER(id) _SHADERS_GET_STAGE(PREMULTIPLY, id) +#define SHADERS_GET_BW_SHADER(id) _SHADERS_GET_STAGE(BW, id) + +enum VegaShaderType { + VEGA_SOLID_FILL_SHADER = 1 << SHADERS_PAINT_SHIFT, + VEGA_LINEAR_GRADIENT_SHADER = 2 << SHADERS_PAINT_SHIFT, + VEGA_RADIAL_GRADIENT_SHADER = 3 << SHADERS_PAINT_SHIFT, + VEGA_PATTERN_SHADER = 4 << SHADERS_PAINT_SHIFT, + VEGA_PAINT_DEGENERATE_SHADER = 5 << SHADERS_PAINT_SHIFT, + + VEGA_IMAGE_NORMAL_SHADER = 1 << SHADERS_IMAGE_SHIFT, + VEGA_IMAGE_MULTIPLY_SHADER = 2 << SHADERS_IMAGE_SHIFT, + VEGA_IMAGE_STENCIL_SHADER = 3 << SHADERS_IMAGE_SHIFT, + + VEGA_COLOR_TRANSFORM_SHADER = 1 << SHADERS_COLOR_TRANSFORM_SHIFT, + + VEGA_ALPHA_NORMAL_SHADER = 1 << SHADERS_ALPHA_SHIFT, + VEGA_ALPHA_PER_CHANNEL_SHADER = 2 << SHADERS_ALPHA_SHIFT, + + VEGA_BLEND_SRC_SHADER = 1 << SHADERS_BLEND_SHIFT, + VEGA_BLEND_SRC_OVER_SHADER = 2 << SHADERS_BLEND_SHIFT, + VEGA_BLEND_DST_OVER_SHADER = 3 << SHADERS_BLEND_SHIFT, + VEGA_BLEND_SRC_IN_SHADER = 4 << SHADERS_BLEND_SHIFT, + VEGA_BLEND_DST_IN_SHADER = 5 << SHADERS_BLEND_SHIFT, + VEGA_BLEND_MULTIPLY_SHADER = 6 << SHADERS_BLEND_SHIFT, + VEGA_BLEND_SCREEN_SHADER = 7 << SHADERS_BLEND_SHIFT, + VEGA_BLEND_DARKEN_SHADER = 8 << SHADERS_BLEND_SHIFT, + VEGA_BLEND_LIGHTEN_SHADER = 9 << SHADERS_BLEND_SHIFT, + VEGA_BLEND_ADDITIVE_SHADER = 10<< SHADERS_BLEND_SHIFT, + + VEGA_MASK_SHADER = 1 << SHADERS_MASK_SHIFT, + + VEGA_PREMULTIPLY_SHADER = 1 << SHADERS_PREMULTIPLY_SHIFT, + VEGA_UNPREMULTIPLY_SHADER = 2 << SHADERS_PREMULTIPLY_SHIFT, + + VEGA_BW_SHADER = 1 << SHADERS_BW_SHIFT +}; + +struct vg_shader { + void *driver; + struct tgsi_token *tokens; + int type;/* PIPE_SHADER_VERTEX, PIPE_SHADER_FRAGMENT */ +}; + +struct shaders_cache *shaders_cache_create(struct vg_context *pipe); +void shaders_cache_destroy(struct shaders_cache *sc); +void *shaders_cache_fill(struct shaders_cache *sc, + int shader_key); + +struct vg_shader *shader_create_from_text(struct pipe_context *pipe, + const char *txt, int num_tokens, + int type); + +void vg_shader_destroy(struct vg_context *ctx, struct vg_shader *shader); + + + +#endif diff --git a/src/gallium/state_trackers/vega/stroker.c b/src/gallium/state_trackers/vega/stroker.c new file mode 100644 index 0000000..d89b6cf --- /dev/null +++ b/src/gallium/state_trackers/vega/stroker.c @@ -0,0 +1,1350 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "stroker.h" + +#include "path.h" +#include "vg_state.h" +#include "util_array.h" +#include "arc.h" +#include "bezier.h" +#include "matrix.h" +#include "path_utils.h" +#include "polygon.h" + +#include "util/u_math.h" + +#ifndef M_2PI +#define M_2PI 6.28318530717958647692528676655900576 +#endif + +#define STROKE_SEGMENTS 0 +#define STROKE_DEBUG 0 +#define DEBUG_EMITS 0 + +static const VGfloat curve_threshold = 0.25f; + +static const VGfloat zero_coords[] = {0.f, 0.f}; + +enum intersection_type { + NoIntersections, + BoundedIntersection, + UnboundedIntersection, +}; + +enum line_join_mode { + FlatJoin, + SquareJoin, + MiterJoin, + RoundJoin, + RoundCap +}; + +struct stroke_iterator { + void (*next)(struct stroke_iterator *); + VGboolean (*has_next)(struct stroke_iterator *); + + VGPathCommand (*current_command)(struct stroke_iterator *it); + void (*current_coords)(struct stroke_iterator *it, VGfloat *coords); + + VGint position; + VGint coord_position; + + const VGubyte *cmds; + const VGfloat *coords; + VGint num_commands; + VGint num_coords; + + struct polygon *curve_poly; + VGint curve_index; +}; + +static VGPathCommand stroke_itr_command(struct stroke_iterator *itr) +{ + return itr->current_command(itr); +} + +static void stroke_itr_coords(struct stroke_iterator *itr, VGfloat *coords) +{ + itr->current_coords(itr, coords); +} + +static void stroke_fw_itr_coords(struct stroke_iterator *itr, VGfloat *coords) +{ + if (itr->position >= itr->num_commands) + return; + switch (stroke_itr_command(itr)) { + case VG_MOVE_TO_ABS: + coords[0] = itr->coords[itr->coord_position]; + coords[1] = itr->coords[itr->coord_position + 1]; + break; + case VG_LINE_TO_ABS: + coords[0] = itr->coords[itr->coord_position]; + coords[1] = itr->coords[itr->coord_position + 1]; + break; + case VG_CUBIC_TO_ABS: + coords[0] = itr->coords[itr->coord_position]; + coords[1] = itr->coords[itr->coord_position + 1]; + coords[2] = itr->coords[itr->coord_position + 2]; + coords[3] = itr->coords[itr->coord_position + 3]; + coords[4] = itr->coords[itr->coord_position + 4]; + coords[5] = itr->coords[itr->coord_position + 5]; + break; + default: + debug_assert(!"invalid command!\n"); + } +} + + +static void stroke_bw_itr_coords(struct stroke_iterator *itr, VGfloat *coords) +{ + if (itr->position >= itr->num_commands) + return; + switch (stroke_itr_command(itr)) { + case VG_MOVE_TO_ABS: + coords[0] = itr->coords[itr->coord_position]; + coords[1] = itr->coords[itr->coord_position + 1]; + break; + case VG_LINE_TO_ABS: + coords[0] = itr->coords[itr->coord_position]; + coords[1] = itr->coords[itr->coord_position + 1]; + break; + case VG_CUBIC_TO_ABS: + coords[0] = itr->coords[itr->coord_position + 4]; + coords[1] = itr->coords[itr->coord_position + 5]; + coords[2] = itr->coords[itr->coord_position + 2]; + coords[3] = itr->coords[itr->coord_position + 3]; + coords[4] = itr->coords[itr->coord_position + 0]; + coords[5] = itr->coords[itr->coord_position + 1]; + break; + default: + debug_assert(!"invalid command!\n"); + } +} + + +static VGPathCommand stroke_fw_current_command(struct stroke_iterator *it) +{ + return it->cmds[it->position]; +} + +static VGPathCommand stroke_bw_current_command(struct stroke_iterator *it) +{ + VGPathCommand prev_cmd; + if (it->position == it->num_commands -1) + return VG_MOVE_TO_ABS; + + prev_cmd = it->cmds[it->position + 1]; + return prev_cmd; +} + +static VGboolean stroke_fw_has_next(struct stroke_iterator *itr) +{ + return itr->position < (itr->num_commands - 1); +} + +static VGboolean stroke_bw_has_next(struct stroke_iterator *itr) +{ + return itr->position > 0; +} + +static void stroke_fw_next(struct stroke_iterator *itr) +{ + VGubyte cmd; + debug_assert(stroke_fw_has_next(itr)); + + cmd = stroke_itr_command(itr); + + itr->coord_position += num_elements_for_segments(&cmd, 1); + ++itr->position; +} + +static void stroke_bw_next(struct stroke_iterator *itr) +{ + VGubyte cmd; + debug_assert(stroke_bw_has_next(itr)); + + --itr->position; + cmd = stroke_itr_command(itr); + + itr->coord_position -= num_elements_for_segments(&cmd, 1); +} + +static void stroke_itr_common_init(struct stroke_iterator *itr, + struct array *cmds, + struct array *coords) +{ + itr->cmds = (VGubyte*)cmds->data; + itr->num_commands = cmds->num_elements; + + itr->coords = (VGfloat*)coords->data; + itr->num_coords = coords->num_elements; +} + +static void stroke_forward_iterator(struct stroke_iterator *itr, + struct array *cmds, + struct array *coords) +{ + stroke_itr_common_init(itr, cmds, coords); + itr->position = 0; + itr->coord_position = 0; + + itr->next = stroke_fw_next; + itr->has_next = stroke_fw_has_next; + itr->current_command = stroke_fw_current_command; + itr->current_coords = stroke_fw_itr_coords; +} + +static void stroke_backward_iterator(struct stroke_iterator *itr, + struct array *cmds, + struct array *coords) +{ + VGubyte cmd; + stroke_itr_common_init(itr, cmds, coords); + itr->position = itr->num_commands - 1; + + cmd = stroke_bw_current_command(itr); + itr->coord_position = itr->num_coords - + num_elements_for_segments(&cmd, 1); + + itr->next = stroke_bw_next; + itr->has_next = stroke_bw_has_next; + itr->current_command = stroke_bw_current_command; + itr->current_coords = stroke_bw_itr_coords; +} + + + +static void stroke_flat_next(struct stroke_iterator *itr) +{ + VGubyte cmd; + + if (itr->curve_index >= 0) { + ++itr->curve_index; + if (itr->curve_index >= polygon_vertex_count(itr->curve_poly)) { + itr->curve_index = -1; + polygon_destroy(itr->curve_poly); + itr->curve_poly = 0; + } else + return; + } + debug_assert(stroke_fw_has_next(itr)); + + cmd = itr->cmds[itr->position]; + itr->coord_position += num_elements_for_segments(&cmd, 1); + ++itr->position; + + cmd = itr->cmds[itr->position]; + + if (cmd == VG_CUBIC_TO_ABS) { + struct bezier bezier; + VGfloat bez[8]; + + bez[0] = itr->coords[itr->coord_position - 2]; + bez[1] = itr->coords[itr->coord_position - 1]; + bez[2] = itr->coords[itr->coord_position]; + bez[3] = itr->coords[itr->coord_position + 1]; + bez[4] = itr->coords[itr->coord_position + 2]; + bez[5] = itr->coords[itr->coord_position + 3]; + bez[6] = itr->coords[itr->coord_position + 4]; + bez[7] = itr->coords[itr->coord_position + 5]; + + bezier_init(&bezier, + bez[0], bez[1], + bez[2], bez[3], + bez[4], bez[5], + bez[6], bez[7]); + /* skip the first one, it's the same as the prev point */ + itr->curve_index = 1; + if (itr->curve_poly) { + polygon_destroy(itr->curve_poly); + itr->curve_poly = 0; + } + itr->curve_poly = bezier_to_polygon(&bezier); + } +} + +static VGboolean stroke_flat_has_next(struct stroke_iterator *itr) +{ + return (itr->curve_index >= 0 && + itr->curve_index < (polygon_vertex_count(itr->curve_poly)-1)) + || itr->position < (itr->num_commands - 1); +} + +static VGPathCommand stroke_flat_current_command(struct stroke_iterator *it) +{ + if (it->cmds[it->position] == VG_CUBIC_TO_ABS) { + return VG_LINE_TO_ABS; + } + return it->cmds[it->position]; +} + +static void stroke_flat_itr_coords(struct stroke_iterator *itr, VGfloat *coords) +{ + if (itr->curve_index <= -1 && itr->position >= itr->num_commands) + return; + + if (itr->curve_index >= 0) { + polygon_vertex(itr->curve_poly, itr->curve_index, + coords); + return; + } + + switch (stroke_itr_command(itr)) { + case VG_MOVE_TO_ABS: + coords[0] = itr->coords[itr->coord_position]; + coords[1] = itr->coords[itr->coord_position + 1]; + break; + case VG_LINE_TO_ABS: + coords[0] = itr->coords[itr->coord_position]; + coords[1] = itr->coords[itr->coord_position + 1]; + break; + case VG_CUBIC_TO_ABS: + default: + debug_assert(!"invalid command!\n"); + } +} + +static void stroke_flat_iterator(struct stroke_iterator *itr, + struct array *cmds, + struct array *coords) +{ + stroke_itr_common_init(itr, cmds, coords); + itr->position = 0; + itr->coord_position = 0; + + itr->next = stroke_flat_next; + itr->has_next = stroke_flat_has_next; + itr->current_command = stroke_flat_current_command; + itr->current_coords = stroke_flat_itr_coords; + itr->curve_index = -1; + itr->curve_poly = 0; +} + + +static INLINE VGboolean finite_coords4(const VGfloat *c) +{ + return + isfinite(c[0]) && isfinite(c[1]) && + isfinite(c[2]) && isfinite(c[3]); +} + +/* from Graphics Gems II */ +#define SAME_SIGNS(a, b) ((a) * (b) >= 0) +static VGboolean do_lines_intersect(VGfloat x1, VGfloat y1, VGfloat x2, VGfloat y2, + VGfloat x3, VGfloat y3, VGfloat x4, VGfloat y4) +{ + VGfloat a1, a2, b1, b2, c1, c2; /* Coefficients of line eqns */ + VGfloat r1, r2, r3, r4; /* 'sign' values */ + + a1 = y2 - y1; + b1 = x1 - x2; + c1 = x2 * y1 - x1 * y2; + + r3 = a1 * x3 + b1 * y3 + c1; + r4 = a1 * x4 + b1 * y4 + c1; + + if (r3 != 0 && r4 != 0 && SAME_SIGNS(r3, r4)) + return VG_FALSE; + + a2 = y4 - y3; + b2 = x3 - x4; + c2 = x4 * y3 - x3 * y4; + + r1 = a2 * x1 + b2 * y1 + c2; + r2 = a2 * x2 + b2 * y2 + c2; + + if (r1 != 0 && r2 != 0 && SAME_SIGNS(r1, r2)) + return VG_FALSE; + + return VG_TRUE; +} + +static INLINE VGfloat line_dx(const VGfloat *l) +{ + return l[2] - l[0]; +} + +static INLINE VGfloat line_dy(const VGfloat *l) +{ + return l[3] - l[1]; +} + +static INLINE VGfloat line_angle(const VGfloat *l) +{ + const VGfloat dx = line_dx(l); + const VGfloat dy = line_dy(l); + + const VGfloat theta = atan2(-dy, dx) * 360.0 / M_2PI; + + const VGfloat theta_normalized = theta < 0 ? theta + 360 : theta; + + if (floatsEqual(theta_normalized, 360.f)) + return 0; + else + return theta_normalized; +} + +static INLINE void line_set_length(VGfloat *l, VGfloat len) +{ + VGfloat uv[] = {l[0], l[1], l[2], l[3]}; + if (null_line(l)) + return; + line_normalize(uv); + l[2] = l[0] + line_dx(uv) * len; + l[3] = l[1] + line_dy(uv) * len; +} + +static INLINE void line_translate(VGfloat *l, VGfloat x, VGfloat y) +{ + l[0] += x; + l[1] += y; + l[2] += x; + l[3] += y; +} + +static INLINE VGfloat line_angle_to(const VGfloat *l1, + const VGfloat *l2) +{ + VGfloat a1, a2, delta, delta_normalized; + if (null_line(l1) || null_line(l1)) + return 0; + + a1 = line_angle(l1); + a2 = line_angle(l2); + + delta = a2 - a1; + delta_normalized = delta < 0 ? delta + 360 : delta; + + if (floatsEqual(delta, 360.f)) + return 0; + else + return delta_normalized; +} + +static INLINE VGfloat line_angles(const VGfloat *l1, + const VGfloat *l2) +{ + VGfloat cos_line, rad = 0; + + if (null_line(l1) || null_line(l2)) + return 0; + + cos_line = (line_dx(l1)*line_dx(l2) + line_dy(l1)*line_dy(l2)) / + (line_lengthv(l1)*line_lengthv(l2)); + rad = 0; + + if (cos_line >= -1.0 && cos_line <= 1.0) + rad = acos(cos_line); + return rad * 360 / M_2PI; +} + + +static INLINE VGfloat adapted_angle_on_x(const VGfloat *line) +{ + const VGfloat identity[] = {0, 0, 1, 0}; + VGfloat angle = line_angles(line, identity); + if (line_dy(line) > 0) + angle = 360 - angle; + return angle; +} + +static enum intersection_type line_intersect(const VGfloat *l1, + const VGfloat *l2, + float *intersection_point) +{ + VGfloat isect[2] = { 0 }; + enum intersection_type type; + VGboolean dx_zero, ldx_zero; + + if (null_line(l1) || null_line(l2) || + !finite_coords4(l1) || !finite_coords4(l2)) + return NoIntersections; + + type = do_lines_intersect(l1[0], l1[1], l1[2], l1[3], l2[0], l2[1], l2[2], l2[3]) + ? BoundedIntersection : UnboundedIntersection; + + dx_zero = floatsEqual(line_dx(l1) + 1, 1); + ldx_zero = floatsEqual(line_dx(l2) + 1, 1); + + /* one of the lines is vertical */ + if (dx_zero && ldx_zero) { + type = NoIntersections; + } else if (dx_zero) { + VGfloat la = line_dy(l2) / line_dx(l2); + isect[0] = l1[0]; + isect[1] = la * l1[0] + l2[1] - la * l2[0]; + } else if (ldx_zero) { + VGfloat ta = line_dy(l1) / line_dx(l1); + isect[0] = l2[0]; + isect[1] = ta * l2[0] + l1[1] - ta*l1[0]; + } else { + VGfloat x; + VGfloat ta = line_dy(l1) / line_dx(l1); + VGfloat la = line_dy(l2) / line_dx(l2); + if (ta == la) + return NoIntersections; + + x = ( - l2[1] + la * l2[0] + l1[1] - ta * l1[0] ) / (la - ta); + isect[0] = x; + isect[1] = ta*(x - l1[0]) + l1[1]; + } + if (intersection_point) { + intersection_point[0] = isect[0]; + intersection_point[1] = isect[1]; + } + return type; +} + +static INLINE enum line_join_mode stroker_join_mode(struct stroker *s) +{ + switch(s->join_style) { + case VG_JOIN_MITER: + return MiterJoin; + case VG_JOIN_ROUND: + return RoundJoin; + case VG_JOIN_BEVEL: + return FlatJoin; + default: + return FlatJoin; + } +} + +static INLINE enum line_join_mode stroker_cap_mode(struct stroker *s) +{ + switch(s->cap_style) { + case VG_CAP_BUTT: + return FlatJoin; + case VG_CAP_ROUND: + return RoundCap; + case VG_CAP_SQUARE: + return SquareJoin; + default: + return FlatJoin; + } +} + +void stroker_emit_move_to(struct stroker *stroker, VGfloat x, VGfloat y) +{ + VGubyte cmds = VG_MOVE_TO_ABS; + VGfloat coords[2] = {x, y}; +#if DEBUG_EMITS + debug_printf("emit move %f, %f\n", x, y); +#endif + stroker->back2_x = stroker->back1_x; + stroker->back2_y = stroker->back1_y; + stroker->back1_x = x; + stroker->back1_y = y; + + path_append_data(stroker->path, + 1, + &cmds, &coords); +} + +void stroker_emit_line_to(struct stroker *stroker, VGfloat x, VGfloat y) +{ + VGubyte cmds = VG_LINE_TO_ABS; + VGfloat coords[2] = {x, y}; +#if DEBUG_EMITS + debug_printf("emit line %f, %f\n", x, y); +#endif + stroker->back2_x = stroker->back1_x; + stroker->back2_y = stroker->back1_y; + stroker->back1_x = x; + stroker->back1_y = y; + path_append_data(stroker->path, + 1, + &cmds, &coords); +} + +void stroker_emit_curve_to(struct stroker *stroker, VGfloat px1, VGfloat py1, + VGfloat px2, VGfloat py2, + VGfloat x, VGfloat y) +{ + VGubyte cmds = VG_CUBIC_TO_ABS; + VGfloat coords[6] = {px1, py1, px2, py2, x, y}; +#if DEBUG_EMITS + debug_printf("emit curve %f, %f, %f, %f, %f, %f\n", px1, py1, + px2, py2, x, y); +#endif + + if (px2 == x && py2 == y) { + if (px1 == x && py1 == y) { + stroker->back2_x = stroker->back1_x; + stroker->back2_y = stroker->back1_y; + } else { + stroker->back2_x = px1; + stroker->back2_y = py1; + } + } else { + stroker->back2_x = px2; + stroker->back2_y = py2; + } + stroker->back1_x = x; + stroker->back1_y = y; + + path_append_data(stroker->path, + 1, + &cmds, &coords); +} + +static INLINE void create_round_join(struct stroker *stroker, + VGfloat x1, VGfloat y1, + VGfloat x2, VGfloat y2, + VGfloat width, VGfloat height) +{ + struct arc arc; + struct matrix matrix; + + matrix_load_identity(&matrix); + + /*stroker_emit_line_to(stroker, nx, ny);*/ + + arc_init(&arc, VG_SCCWARC_TO_ABS, + x1, y1, x2, y2, width/2, height/2, 0); + arc_stroker_emit(&arc, stroker, &matrix); +} + + +static void create_joins(struct stroker *stroker, + VGfloat focal_x, VGfloat focal_y, + const VGfloat *next_line, enum line_join_mode join) +{ +#if DEBUG_EMITS + debug_printf("create_joins: focal=[%f, %f], next_line=[%f, %f,%f, %f]\n", + focal_x, focal_y, + next_line[0], next_line[1], next_line[2], next_line[3]); +#endif + /* if we're alredy connected do nothing */ + if (floatsEqual(stroker->back1_x, next_line[0]) && + floatsEqual(stroker->back1_y, next_line[1])) + return; + + if (join == FlatJoin) { + stroker_emit_line_to(stroker, next_line[0], next_line[1]); + } else { + VGfloat prev_line[] = {stroker->back2_x, stroker->back2_y, + stroker->back1_x, stroker->back1_y}; + + VGfloat isect[2] = { 0 }; + enum intersection_type type = line_intersect(prev_line, next_line, isect); + + if (join == SquareJoin) { + VGfloat offset = stroker->stroke_width / 2; + VGfloat l1[4] = {prev_line[0], + prev_line[1], + prev_line[2], + prev_line[3]}; + VGfloat l2[4] = {next_line[2], + next_line[3], + next_line[0], + next_line[1]}; + + line_translate(l1, line_dx(l1), line_dy(l1)); + line_set_length(l1, offset); + + line_translate(l2, line_dx(l2), line_dy(l2)); + line_set_length(l2, offset); + + stroker_emit_line_to(stroker, l1[2], l1[3]); + stroker_emit_line_to(stroker, l2[2], l2[3]); + stroker_emit_line_to(stroker, l2[0], l2[1]); + } else if (join == RoundJoin) { + VGfloat offset = stroker->stroke_width / 2; + VGfloat short_cut[4] = {prev_line[2], prev_line[3], + next_line[0], next_line[1]}; + VGfloat angle = line_angles(prev_line, short_cut); + + if (type == BoundedIntersection || + (angle > 90 && !floatsEqual(angle, 90.f))) { + stroker_emit_line_to(stroker, next_line[0], next_line[1]); + return; + } + create_round_join(stroker, prev_line[2], prev_line[3], + next_line[0], next_line[1], + offset * 2, offset * 2); + + stroker_emit_line_to(stroker, next_line[0], next_line[1]); + } else if (join == RoundCap) { + VGfloat offset = stroker->stroke_width / 2; + VGfloat l1[4] = { prev_line[0], prev_line[1], + prev_line[2], prev_line[3] }; + VGfloat l2[4] = {focal_x, focal_y, + prev_line[2], prev_line[3]}; + + line_translate(l1, line_dx(l1), line_dy(l1)); + line_set_length(l1, KAPPA * offset); + + /* normal between prev_line and focal */ + line_translate(l2, -line_dy(l2), line_dx(l2)); + line_set_length(l2, KAPPA * offset); + + stroker_emit_curve_to(stroker, l1[2], l1[3], + l2[2], l2[3], + l2[0], l2[1]); + + l2[0] = l2[0]; + l2[1] = l2[1]; + l2[2] = l2[0] - line_dx(l2); + l2[3] = l2[1] - line_dy(l2); + + line_translate(l1, next_line[0] - l1[0], next_line[1] - l1[1]); + + stroker_emit_curve_to(stroker, + l2[2], l2[3], + l1[2], l1[3], + l1[0], l1[1]); + } else if (join == MiterJoin) { + VGfloat miter_line[4] = {stroker->back1_x, stroker->back1_y, + isect[0], isect[1]}; + VGfloat sl = (stroker->stroke_width * stroker->miter_limit); + VGfloat inside_line[4] = {prev_line[2], prev_line[3], + next_line[0], next_line[1]}; + VGfloat angle = line_angle_to(inside_line, prev_line); + + if (type == BoundedIntersection || + (angle > 90 && !floatsEqual(angle, 90.f))) { + /* + debug_printf("f = %f, nl = %f, pl = %f, is = %f\n", + focal_x, next_line[0], + prev_line[2], isect[0]);*/ + stroker_emit_line_to(stroker, next_line[0], next_line[1]); + return; + } + + if (type == NoIntersections || line_lengthv(miter_line) > sl) { + stroker_emit_line_to(stroker, next_line[0], next_line[1]); + } else { + stroker_emit_line_to(stroker, isect[0], isect[1]); + stroker_emit_line_to(stroker, next_line[0], next_line[1]); + } + } else { + debug_assert(!"create_joins bad join style"); + } + } +} + +static void stroker_add_segment(struct stroker *stroker, + VGPathCommand cmd, + const VGfloat *coords, + VGint num_coords) +{ + /* skip duplicated points */ + if (stroker->segments->num_elements && + stroker->last_cmd == cmd) { + VGfloat *data = stroker->control_points->data; + data += stroker->control_points->num_elements; + data -= num_coords; + switch (cmd) { + case VG_MOVE_TO_ABS: + if (floatsEqual(coords[0], data[0]) && + floatsEqual(coords[1], data[1])) + return; + break; + case VG_LINE_TO_ABS: + if (floatsEqual(coords[0], data[0]) && + floatsEqual(coords[1], data[1])) + return; + break; + case VG_CUBIC_TO_ABS: + if (floatsEqual(coords[0], data[0]) && + floatsEqual(coords[1], data[1]) && + floatsEqual(coords[2], data[2]) && + floatsEqual(coords[3], data[3]) && + floatsEqual(coords[4], data[4]) && + floatsEqual(coords[5], data[5])) + return; + break; + default: + debug_assert(!"Invalid stroke segment"); + } + } else if (stroker->last_cmd == VG_CUBIC_TO_ABS && + cmd == VG_LINE_TO_ABS) { + VGfloat *data = stroker->control_points->data; + data += stroker->control_points->num_elements; + data -= 2; + if (floatsEqual(coords[0], data[0]) && + floatsEqual(coords[1], data[1])) + return; + } + stroker->last_cmd = cmd; + array_append_data(stroker->segments, &cmd, 1); + array_append_data(stroker->control_points, coords, num_coords); +} + +void stroker_move_to(struct stroker *stroker, VGfloat x, VGfloat y) +{ + VGfloat coords[2] = {x, y}; +#if STROKE_SEGMENTS + debug_printf("stroker_move_to(%f, %f)\n", x, y); +#endif + + if (stroker->segments->num_elements > 0) + stroker->process_subpath(stroker); + + array_reset(stroker->segments); + array_reset(stroker->control_points); + + stroker_add_segment(stroker, VG_MOVE_TO_ABS, coords, 2); +} + +void stroker_line_to(struct stroker *stroker, VGfloat x, VGfloat y) +{ + VGfloat coords[] = {x, y}; + +#if STROKE_SEGMENTS + debug_printf("stroker_line_to(%f, %f)\n", x, y); +#endif + if (!stroker->segments->num_elements) + stroker_add_segment(stroker, VG_MOVE_TO_ABS, zero_coords, 2); + + stroker_add_segment(stroker, VG_LINE_TO_ABS, coords, 2); +} + +void stroker_curve_to(struct stroker *stroker, VGfloat px1, VGfloat py1, + VGfloat px2, VGfloat py2, + VGfloat x, VGfloat y) +{ + VGfloat coords[] = {px1, py1, + px2, py2, + x, y}; +#if STROKE_SEGMENTS + debug_printf("stroker_curve_to(%f, %f, %f, %f, %f, %f)\n", + px1, py1, px2, py2, x, y); +#endif + if (!stroker->segments->num_elements) + stroker_add_segment(stroker, VG_MOVE_TO_ABS, zero_coords, 2); + + stroker_add_segment(stroker, VG_CUBIC_TO_ABS, coords, 6); +} + +static INLINE VGboolean is_segment_null(VGPathCommand cmd, + VGfloat *coords, + VGfloat *res) +{ + switch(cmd) { + case VG_MOVE_TO_ABS: + case VG_LINE_TO_ABS: + return floatsEqual(coords[0], res[0]) && + floatsEqual(coords[1], res[1]); + break; + case VG_CUBIC_TO_ABS: + return floatsEqual(coords[0], res[0]) && + floatsEqual(coords[1], res[1]) && + floatsEqual(coords[2], res[0]) && + floatsEqual(coords[3], res[1]) && + floatsEqual(coords[4], res[0]) && + floatsEqual(coords[5], res[1]); + break; + default: + assert(0); + } + return VG_FALSE; +} + +static VGboolean vg_stroke_outline(struct stroke_iterator *it, + struct stroker *stroker, + VGboolean cap_first, + VGfloat *start_tangent) +{ +#define MAX_OFFSET 16 + struct bezier offset_curves[MAX_OFFSET]; + VGPathCommand first_element; + VGfloat start[2], prev[2]; + VGboolean first = VG_TRUE; + VGfloat offset; + + first_element = stroke_itr_command(it); + if (first_element != VG_MOVE_TO_ABS) { + stroker_emit_move_to(stroker, 0.f, 0.f); + prev[0] = 0.f; + prev[1] = 0.f; + } + stroke_itr_coords(it, start); +#if STROKE_DEBUG + debug_printf(" -> (side) [%.2f, %.2f]\n", + start[0], + start[1]); +#endif + + prev[0] = start[0]; + prev[1] = start[1]; + + offset = stroker->stroke_width / 2; + + if (!it->has_next(it)) { + /* single point */ + + return VG_TRUE; + } + + while (it->has_next(it)) { + VGPathCommand cmd; + VGfloat coords[8]; + + it->next(it); + cmd = stroke_itr_command(it); + stroke_itr_coords(it, coords); + + if (cmd == VG_LINE_TO_ABS) { + VGfloat line[4] = {prev[0], prev[1], coords[0], coords[1]}; + VGfloat normal[4]; + line_normal(line, normal); + +#if STROKE_DEBUG + debug_printf("\n ---> (side) lineto [%.2f, %.2f]\n", coords[0], coords[1]); +#endif + line_set_length(normal, offset); + line_translate(line, line_dx(normal), line_dy(normal)); + + /* if we are starting a new subpath, move to correct starting point */ + if (first) { + if (cap_first) + create_joins(stroker, prev[0], prev[1], line, + stroker_cap_mode(stroker)); + else + stroker_emit_move_to(stroker, line[0], line[1]); + memcpy(start_tangent, line, + sizeof(VGfloat) * 4); + first = VG_FALSE; + } else { + create_joins(stroker, prev[0], prev[1], line, + stroker_join_mode(stroker)); + } + + /* add the stroke for this line */ + stroker_emit_line_to(stroker, line[2], line[3]); + prev[0] = coords[0]; + prev[1] = coords[1]; + } else if (cmd == VG_CUBIC_TO_ABS) { +#if STROKE_DEBUG + debug_printf("\n ---> (side) cubicTo [%.2f, %.2f]\n", + coords[4], + coords[5]); +#endif + struct bezier bezier; + int count; + + bezier_init(&bezier, + prev[0], prev[1], coords[0], coords[1], + coords[2], coords[3], coords[4], coords[5]); + + count = bezier_translate_by_normal(&bezier, + offset_curves, + MAX_OFFSET, + offset, + curve_threshold); + + if (count) { + /* if we are starting a new subpath, move to correct starting point */ + VGfloat tangent[4]; + VGint i; + + bezier_start_tangent(&bezier, tangent); + line_translate(tangent, + offset_curves[0].x1 - bezier.x1, + offset_curves[0].y1 - bezier.y1); + if (first) { + VGfloat pt[2] = {offset_curves[0].x1, + offset_curves[0].y1}; + + if (cap_first) { + create_joins(stroker, prev[0], prev[1], tangent, + stroker_cap_mode(stroker)); + } else { + stroker_emit_move_to(stroker, pt[0], pt[1]); + } + start_tangent[0] = tangent[0]; + start_tangent[1] = tangent[1]; + start_tangent[2] = tangent[2]; + start_tangent[3] = tangent[3]; + first = VG_FALSE; + } else { + create_joins(stroker, prev[0], prev[1], tangent, + stroker_join_mode(stroker)); + } + + /* add these beziers */ + for (i = 0; i < count; ++i) { + struct bezier *bez = &offset_curves[i]; + stroker_emit_curve_to(stroker, + bez->x2, bez->y2, + bez->x3, bez->y3, + bez->x4, bez->y4); + } + } + + prev[0] = coords[4]; + prev[1] = coords[5]; + } + } + + if (floatsEqual(start[0], prev[0]) && + floatsEqual(start[1], prev[1])) { + /* closed subpath, join first and last point */ +#if STROKE_DEBUG + debug_printf("\n stroker: closed subpath\n"); +#endif + create_joins(stroker, prev[0], prev[1], start_tangent, + stroker_join_mode(stroker)); + return VG_TRUE; + } else { +#if STROKE_DEBUG + debug_printf("\n stroker: open subpath\n"); +#endif + return VG_FALSE; + } +#undef MAX_OFFSET +} + +static void stroker_process_subpath(struct stroker *stroker) +{ + VGboolean fwclosed, bwclosed; + VGfloat fw_start_tangent[4], bw_start_tangent[4]; + struct stroke_iterator fwit; + struct stroke_iterator bwit; + debug_assert(stroker->segments->num_elements > 0); + + memset(fw_start_tangent, 0, + sizeof(VGfloat)*4); + memset(bw_start_tangent, 0, + sizeof(VGfloat)*4); + + stroke_forward_iterator(&fwit, stroker->segments, + stroker->control_points); + stroke_backward_iterator(&bwit, stroker->segments, + stroker->control_points); + + debug_assert(fwit.cmds[0] == VG_MOVE_TO_ABS); + + fwclosed = vg_stroke_outline(&fwit, stroker, VG_FALSE, fw_start_tangent); + bwclosed = vg_stroke_outline(&bwit, stroker, !fwclosed, bw_start_tangent); + + if (!bwclosed) + create_joins(stroker, + fwit.coords[0], fwit.coords[1], fw_start_tangent, + stroker_cap_mode(stroker)); + else { + /* hack to handle the requirement of the VG spec that says that strokes + * of len==0 that have butt cap or round cap still need + * to be rendered. (8.7.4 Stroke Generation) */ + if (stroker->segments->num_elements <= 3) { + VGPathCommand cmd; + VGfloat data[8], coords[8]; + struct stroke_iterator *it = &fwit; + + stroke_forward_iterator(it, stroker->segments, + stroker->control_points); + cmd = stroke_itr_command(it); + stroke_itr_coords(it, coords); + if (cmd != VG_MOVE_TO_ABS) { + memset(data, 0, sizeof(VGfloat) * 8); + if (!is_segment_null(cmd, coords, data)) + return; + } else { + data[0] = coords[0]; + data[1] = coords[1]; + } + while (it->has_next(it)) { + it->next(it); + cmd = stroke_itr_command(it); + stroke_itr_coords(it, coords); + if (!is_segment_null(cmd, coords, data)) + return; + } + /* generate the square/round cap */ + if (stroker->cap_style == VG_CAP_SQUARE) { + VGfloat offset = stroker->stroke_width / 2; + stroker_emit_move_to(stroker, data[0] - offset, + data[1] - offset); + stroker_emit_line_to(stroker, data[0] + offset, + data[1] - offset); + stroker_emit_line_to(stroker, data[0] + offset, + data[1] + offset); + stroker_emit_line_to(stroker, data[0] - offset, + data[1] + offset); + stroker_emit_line_to(stroker, data[0] - offset, + data[1] - offset); + } else if (stroker->cap_style == VG_CAP_ROUND) { + VGfloat offset = stroker->stroke_width / 2; + VGfloat cx = data[0], cy = data[1]; + { /*circle */ + struct arc arc; + struct matrix matrix; + matrix_load_identity(&matrix); + + stroker_emit_move_to(stroker, cx + offset, cy); + arc_init(&arc, VG_SCCWARC_TO_ABS, + cx + offset, cy, + cx - offset, cy, + offset, offset, 0); + arc_stroker_emit(&arc, stroker, &matrix); + arc_init(&arc, VG_SCCWARC_TO_ABS, + cx - offset, cy, + cx + offset, cy, + offset, offset, 0); + arc_stroker_emit(&arc, stroker, &matrix); + } + } + } + } +} + +static INLINE VGfloat dash_pattern(struct dash_stroker *stroker, + VGint idx) +{ + if (stroker->dash_pattern[idx] < 0) + return 0.f; + return stroker->dash_pattern[idx]; +} + +static void dash_stroker_process_subpath(struct stroker *str) +{ + struct dash_stroker *stroker = (struct dash_stroker *)str; + VGfloat sum_length = 0; + VGint i; + VGint idash = 0; + VGfloat pos = 0; + VGfloat elen = 0; + VGfloat doffset = stroker->dash_phase; + VGfloat estart = 0; + VGfloat estop = 0; + VGfloat cline[4]; + struct stroke_iterator it; + VGfloat prev[2]; + VGfloat move_to_pos[2]; + VGfloat line_to_pos[2]; + + VGboolean has_move_to = VG_FALSE; + + stroke_flat_iterator(&it, stroker->base.segments, + stroker->base.control_points); + + stroke_itr_coords(&it, prev); + move_to_pos[0] = prev[0]; + move_to_pos[1] = prev[1]; + + debug_assert(stroker->dash_pattern_num > 0); + + for (i = 0; i < stroker->dash_pattern_num; ++i) { + sum_length += dash_pattern(stroker, i); + } + + if (floatIsZero(sum_length)) { + return; + } + + doffset -= floorf(doffset / sum_length) * sum_length; + + while (!floatIsZero(doffset) && doffset >= dash_pattern(stroker, idash)) { + doffset -= dash_pattern(stroker, idash); + idash = (idash + 1) % stroker->dash_pattern_num; + } + + while (it.has_next(&it)) { + VGPathCommand cmd; + VGfloat coords[8]; + VGboolean done; + + it.next(&it); + cmd = stroke_itr_command(&it); + stroke_itr_coords(&it, coords); + + debug_assert(cmd == VG_LINE_TO_ABS); + cline[0] = prev[0]; + cline[1] = prev[1]; + cline[2] = coords[0]; + cline[3] = coords[1]; + + elen = line_lengthv(cline); + + estop = estart + elen; + + done = pos >= estop; + while (!done) { + VGfloat p2[2]; + + VGint idash_incr = 0; + VGboolean has_offset = doffset > 0; + VGfloat dpos = pos + dash_pattern(stroker, idash) - doffset - estart; + + debug_assert(dpos >= 0); + + if (dpos > elen) { /* dash extends this line */ + doffset = dash_pattern(stroker, idash) - (dpos - elen); + pos = estop; + done = VG_TRUE; + p2[0] = cline[2]; + p2[1] = cline[3]; + } else { /* Dash is on this line */ + line_point_at(cline, dpos/elen, p2); + pos = dpos + estart; + done = pos >= estop; + idash_incr = 1; + doffset = 0; + } + + if (idash % 2 == 0) { + line_to_pos[0] = p2[0]; + line_to_pos[1] = p2[1]; + + if (!has_offset || !has_move_to) { + stroker_move_to(&stroker->stroker, move_to_pos[0], move_to_pos[1]); + has_move_to = VG_TRUE; + } + stroker_line_to(&stroker->stroker, line_to_pos[0], line_to_pos[1]); + } else { + move_to_pos[0] = p2[0]; + move_to_pos[1] = p2[1]; + } + + idash = (idash + idash_incr) % stroker->dash_pattern_num; + } + + estart = estop; + prev[0] = coords[0]; + prev[1] = coords[1]; + } + + if (it.curve_poly) { + polygon_destroy(it.curve_poly); + it.curve_poly = 0; + } + + stroker->base.path = stroker->stroker.path; +} + +static void default_begin(struct stroker *stroker) +{ + array_reset(stroker->segments); + array_reset(stroker->control_points); +} + +static void default_end(struct stroker *stroker) +{ + if (stroker->segments->num_elements > 0) + stroker->process_subpath(stroker); +} + + +static void dash_stroker_begin(struct stroker *stroker) +{ + struct dash_stroker *dasher = + (struct dash_stroker *)stroker; + + default_begin(&dasher->stroker); + default_begin(stroker); +} + +static void dash_stroker_end(struct stroker *stroker) +{ + struct dash_stroker *dasher = + (struct dash_stroker *)stroker; + + default_end(stroker); + default_end(&dasher->stroker); +} + +void stroker_init(struct stroker *stroker, + struct vg_state *state) +{ + stroker->stroke_width = state->stroke.line_width.f; + stroker->miter_limit = state->stroke.miter_limit.f; + stroker->cap_style = state->stroke.cap_style; + stroker->join_style = state->stroke.join_style; + + stroker->begin = default_begin; + stroker->process_subpath = stroker_process_subpath; + stroker->end = default_end; + + stroker->segments = array_create(sizeof(VGubyte)); + stroker->control_points = array_create(sizeof(VGfloat)); + + stroker->back1_x = 0; + stroker->back1_y = 0; + stroker->back2_x = 0; + stroker->back2_y = 0; + + stroker->path = path_create(VG_PATH_DATATYPE_F, 1.0f, 0.0f, + 0, 0, VG_PATH_CAPABILITY_ALL); + + stroker->last_cmd = VG_CLOSE_PATH; +} + +void dash_stroker_init(struct stroker *str, + struct vg_state *state) +{ + struct dash_stroker *stroker = (struct dash_stroker *)str; + int i; + + stroker_init(str, state); + stroker_init(&stroker->stroker, state); + + { + int real_num = state->stroke.dash_pattern_num; + if (real_num % 2)/* if odd, ignore the last one */ + --real_num; + for (i = 0; i < real_num; ++i) + stroker->dash_pattern[i] = state->stroke.dash_pattern[i].f; + stroker->dash_pattern_num = real_num; + } + + stroker->dash_phase = state->stroke.dash_phase.f; + stroker->dash_phase_reset = state->stroke.dash_phase_reset; + + stroker->base.begin = dash_stroker_begin; + stroker->base.process_subpath = dash_stroker_process_subpath; + stroker->base.end = dash_stroker_end; + path_destroy(stroker->base.path); + stroker->base.path = NULL; +} + +void stroker_begin(struct stroker *stroker) +{ + stroker->begin(stroker); +} + +void stroker_end(struct stroker *stroker) +{ + stroker->end(stroker); +} + +void stroker_cleanup(struct stroker *stroker) +{ + array_destroy(stroker->segments); + array_destroy(stroker->control_points); +} + +void dash_stroker_cleanup(struct dash_stroker *stroker) +{ + /* if stroker->base.path is null means we never + * processed a valid path so delete the temp one + * we already created */ + if (!stroker->base.path) + path_destroy(stroker->stroker.path); + stroker_cleanup(&stroker->stroker); + stroker_cleanup((struct stroker*)stroker); +} diff --git a/src/gallium/state_trackers/vega/stroker.h b/src/gallium/state_trackers/vega/stroker.h new file mode 100644 index 0000000..36543cd --- /dev/null +++ b/src/gallium/state_trackers/vega/stroker.h @@ -0,0 +1,89 @@ +/************************************************************************** + * + * 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 STROKER_H +#define STROKER_H + +#include "VG/openvg.h" +#include "api_consts.h" + +struct path; +struct vg_state; +struct array; + +struct stroker { + void (*begin)(struct stroker *stroker); + void (*process_subpath)(struct stroker *stroker); + void (*end)(struct stroker *stroker); + + struct array *segments; + struct array *control_points; + struct path *path; + + VGfloat back1_x, back1_y; + VGfloat back2_x, back2_y; + + VGfloat stroke_width; + VGfloat miter_limit; + VGCapStyle cap_style; + VGJoinStyle join_style; + + VGPathCommand last_cmd; +}; + +struct dash_stroker { + struct stroker base; + + struct stroker stroker; + + VGfloat dash_pattern[VEGA_MAX_DASH_COUNT]; + VGint dash_pattern_num; + VGfloat dash_phase; + VGboolean dash_phase_reset; +}; + +void stroker_init(struct stroker *stroker, + struct vg_state *state); +void dash_stroker_init(struct stroker *stroker, + struct vg_state *state); +void dash_stroker_cleanup(struct dash_stroker *stroker); +void stroker_cleanup(struct stroker *stroker); + +void stroker_begin(struct stroker *stroker); +void stroker_move_to(struct stroker *stroker, VGfloat x, VGfloat y); +void stroker_line_to(struct stroker *stroker, VGfloat x, VGfloat y); +void stroker_curve_to(struct stroker *stroker, VGfloat px1, VGfloat py1, + VGfloat px2, VGfloat py2, + VGfloat x, VGfloat y); +void stroker_end(struct stroker *stroker); + +void stroker_emit_move_to(struct stroker *stroker, VGfloat x, VGfloat y); +void stroker_emit_line_to(struct stroker *stroker, VGfloat x, VGfloat y); +void stroker_emit_curve_to(struct stroker *stroker, VGfloat px1, VGfloat py1, + VGfloat px2, VGfloat py2, + VGfloat x, VGfloat y); + +#endif diff --git a/src/gallium/state_trackers/vega/text.c b/src/gallium/state_trackers/vega/text.c new file mode 100644 index 0000000..01ff602 --- /dev/null +++ b/src/gallium/state_trackers/vega/text.c @@ -0,0 +1,250 @@ +/************************************************************************** + * + * Copyright 2010 LunarG, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_memory.h" +#include "cso_cache/cso_hash.h" + +#include "text.h" +#include "image.h" +#include "path.h" +#include "api.h" + +#ifdef OPENVG_VERSION_1_1 + +struct vg_font { + struct vg_object base; + struct cso_hash *glyphs; +}; + +struct vg_glyph { + struct vg_object *object; /* it could be NULL */ + VGboolean is_hinted; + VGfloat glyph_origin[2]; + VGfloat escapement[2]; +}; + +static VGboolean del_glyph(struct vg_font *font, + VGuint glyphIndex) +{ + struct vg_glyph *glyph; + + glyph = (struct vg_glyph *) + cso_hash_take(font->glyphs, (unsigned) glyphIndex); + if (glyph) + FREE(glyph); + + return (glyph != NULL); +} + +static void add_glyph(struct vg_font *font, + VGuint glyphIndex, + struct vg_object *obj, + VGboolean isHinted, + const VGfloat glyphOrigin[2], + const VGfloat escapement[2]) +{ + struct vg_glyph *glyph; + + /* remove the existing one */ + del_glyph(font, glyphIndex); + + glyph = CALLOC_STRUCT(vg_glyph); + glyph->object = obj; + glyph->is_hinted = isHinted; + memcpy(glyph->glyph_origin, glyphOrigin, sizeof(glyphOrigin)); + memcpy(glyph->escapement, escapement, sizeof(escapement)); + + cso_hash_insert(font->glyphs, (unsigned) glyphIndex, glyph); +} + +static struct vg_glyph *get_glyph(struct vg_font *font, + VGuint glyphIndex) +{ + struct cso_hash_iter iter; + + iter = cso_hash_find(font->glyphs, (unsigned) glyphIndex); + return (struct vg_glyph *) cso_hash_iter_data(iter); +} + +static void vg_render_glyph(struct vg_context *ctx, + struct vg_glyph *glyph, + VGbitfield paintModes, + VGboolean allowAutoHinting) +{ + if (glyph->object && paintModes) { + struct vg_state *state = &ctx->state.vg; + struct matrix m; + + m = state->glyph_user_to_surface_matrix; + matrix_translate(&m, + state->glyph_origin[0].f - glyph->glyph_origin[0], + state->glyph_origin[1].f - glyph->glyph_origin[1]); + + if (glyph->object->type == VG_OBJECT_PATH) { + path_render((struct path *) glyph->object, paintModes, &m); + } + else { + assert(glyph->object->type == VG_OBJECT_IMAGE); + image_draw((struct vg_image *) glyph->object, &m); + } + } +} + +static void vg_advance_glyph(struct vg_context *ctx, + struct vg_glyph *glyph, + VGfloat adjustment_x, + VGfloat adjustment_y, + VGboolean last) +{ + struct vg_value *glyph_origin = ctx->state.vg.glyph_origin; + + glyph_origin[0].f += glyph->escapement[0] + adjustment_x; + glyph_origin[1].f += glyph->escapement[1] + adjustment_y; + + if (last) { + glyph_origin[0].i = float_to_int_floor(glyph_origin[0].f); + glyph_origin[1].i = float_to_int_floor(glyph_origin[1].f); + } +} + +struct vg_font *font_create(VGint glyphCapacityHint) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_font *font; + + font = CALLOC_STRUCT(vg_font); + vg_init_object(&font->base, ctx, VG_OBJECT_FONT); + font->glyphs = cso_hash_create(); + + vg_context_add_object(ctx, VG_OBJECT_FONT, font); + + return font; +} + +void font_destroy(struct vg_font *font) +{ + struct vg_context *ctx = vg_current_context(); + struct cso_hash_iter iter; + + vg_context_remove_object(ctx, VG_OBJECT_FONT, font); + + iter = cso_hash_first_node(font->glyphs); + while (!cso_hash_iter_is_null(iter)) { + struct vg_glyph *glyph = (struct vg_glyph *) cso_hash_iter_data(iter); + FREE(glyph); + iter = cso_hash_iter_next(iter); + } + cso_hash_delete(font->glyphs); + + FREE(font); +} + +void font_set_glyph_to_path(struct vg_font *font, + VGuint glyphIndex, + struct path *path, + VGboolean isHinted, + const VGfloat glyphOrigin[2], + const VGfloat escapement[2]) +{ + add_glyph(font, glyphIndex, (struct vg_object *) path, + isHinted, glyphOrigin, escapement); +} + +void font_set_glyph_to_image(struct vg_font *font, + VGuint glyphIndex, + struct vg_image *image, + const VGfloat glyphOrigin[2], + const VGfloat escapement[2]) +{ + add_glyph(font, glyphIndex, (struct vg_object *) image, + VG_TRUE, glyphOrigin, escapement); +} + +void font_clear_glyph(struct vg_font *font, + VGuint glyphIndex) +{ + if (!del_glyph(font, glyphIndex)) { + struct vg_context *ctx = vg_current_context(); + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + } +} + +void font_draw_glyph(struct vg_font *font, + VGuint glyphIndex, + VGbitfield paintModes, + VGboolean allowAutoHinting) +{ + struct vg_context *ctx = vg_current_context(); + struct vg_glyph *glyph; + + glyph = get_glyph(font, glyphIndex); + if (!glyph) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + + vg_render_glyph(ctx, glyph, paintModes, allowAutoHinting); + vg_advance_glyph(ctx, glyph, 0.0f, 0.0f, VG_TRUE); +} + +void font_draw_glyphs(struct vg_font *font, + VGint glyphCount, + const VGuint *glyphIndices, + const VGfloat *adjustments_x, + const VGfloat *adjustments_y, + VGbitfield paintModes, + VGboolean allowAutoHinting) +{ + struct vg_context *ctx = vg_current_context(); + VGint i; + + for (i = 0; i < glyphCount; ++i) { + if (!get_glyph(font, glyphIndices[i])) { + vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); + return; + } + } + + for (i = 0; i < glyphCount; ++i) { + struct vg_glyph *glyph; + VGfloat adj_x, adj_y; + + glyph = get_glyph(font, glyphIndices[i]); + + vg_render_glyph(ctx, glyph, paintModes, allowAutoHinting); + + adj_x = (adjustments_x) ? adjustments_x[i] : 0.0f; + adj_y = (adjustments_y) ? adjustments_y[i] : 0.0f; + vg_advance_glyph(ctx, glyph, adj_x, adj_y, (i == glyphCount - 1)); + } +} + +VGint font_num_glyphs(struct vg_font *font) +{ + return cso_hash_size(font->glyphs); +} + +#endif /* OPENVG_VERSION_1_1 */ diff --git a/src/gallium/state_trackers/vega/text.h b/src/gallium/state_trackers/vega/text.h new file mode 100644 index 0000000..6b3fa73 --- /dev/null +++ b/src/gallium/state_trackers/vega/text.h @@ -0,0 +1,71 @@ +/************************************************************************** + * + * Copyright 2010 LunarG, 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 _TEXT_H +#define _TEXT_H + +#include "vg_context.h" +#include "cso_cache/cso_hash.h" + +struct vg_font; +struct vg_image; +struct path; + +struct vg_font *font_create(VGint glyphCapacityHint); +void font_destroy(struct vg_font *font); + +void font_set_glyph_to_path(struct vg_font *font, + VGuint glyphIndex, + struct path *path, + VGboolean isHinted, + const VGfloat glyphOrigin[2], + const VGfloat escapement[2]); + +void font_set_glyph_to_image(struct vg_font *font, + VGuint glyphIndex, + struct vg_image *image, + const VGfloat glyphOrigin[2], + const VGfloat escapement[2]); + +void font_clear_glyph(struct vg_font *font, + VGuint glyphIndex); + +void font_draw_glyph(struct vg_font *font, + VGuint glyphIndex, + VGbitfield paintModes, + VGboolean allowAutoHinting); + +void font_draw_glyphs(struct vg_font *font, + VGint glyphCount, + const VGuint *glyphIndices, + const VGfloat *adjustments_x, + const VGfloat *adjustments_y, + VGbitfield paintModes, + VGboolean allowAutoHinting); + +VGint font_num_glyphs(struct vg_font *font); + +#endif /* _TEXT_H */ diff --git a/src/gallium/state_trackers/vega/util_array.h b/src/gallium/state_trackers/vega/util_array.h new file mode 100644 index 0000000..b2d22f4 --- /dev/null +++ b/src/gallium/state_trackers/vega/util_array.h @@ -0,0 +1,122 @@ +/************************************************************************** + * + * 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 UTIL_ARRAY_H +#define UTIL_ARRAY_H + +#include "util/u_memory.h" + +#define DEFAULT_ARRAY_SIZE 256 + +struct array { + VGint datatype_size; + void *data; + VGint size; + VGint num_elements; +}; + +static INLINE struct array *array_create(VGint datatype_size) +{ + struct array *array = CALLOC_STRUCT(array); + array->datatype_size = datatype_size; + + array->size = DEFAULT_ARRAY_SIZE; + array->data = malloc(array->size * array->datatype_size); + + return array; +} + + +static INLINE struct array *array_create_size(VGint datatype_size, VGint size) +{ + struct array *array = CALLOC_STRUCT(array); + array->datatype_size = datatype_size; + + array->size = size; + array->data = malloc(array->size * array->datatype_size); + + return array; +} + +static INLINE void array_destroy(struct array *array) +{ + if (array) + free(array->data); + FREE(array); +} + +static INLINE void array_resize(struct array *array, int num) +{ + VGint size = array->datatype_size * num; + void *data = malloc(size); + memcpy(data, array->data, array->size * array->datatype_size); + free(array->data); + array->data = data; + array->size = num; + array->num_elements = (array->num_elements > num) ? num : + array->num_elements; +} + +static INLINE void array_append_data(struct array *array, + const void *data, int num_elements) +{ + VGbyte *adata; + + while (array->num_elements + num_elements > array->size) { + array_resize(array, (array->num_elements + num_elements) * 1.5); + } + adata = (VGbyte *)array->data; + memcpy(adata + (array->num_elements * array->datatype_size), data, + num_elements * array->datatype_size); + array->num_elements += num_elements; +} + +static INLINE void array_change_data(struct array *array, + const void *data, + int start_idx, + int num_elements) +{ + VGbyte *adata = (VGbyte *)array->data; + memcpy(adata + (start_idx * array->datatype_size), data, + num_elements * array->datatype_size); +} + +static INLINE void array_remove_element(struct array *array, + int idx) +{ + VGbyte *adata = (VGbyte *)array->data; + memmove(adata + (idx * array->datatype_size), + adata + ((idx + 1) * array->datatype_size), + (array->num_elements - idx - 1) * array->datatype_size); + --array->num_elements; +} + +static INLINE void array_reset(struct array *array) +{ + array->num_elements = 0; +} + +#endif diff --git a/src/gallium/state_trackers/vega/vg_api.h b/src/gallium/state_trackers/vega/vg_api.h new file mode 100644 index 0000000..ce2a0d6 --- /dev/null +++ b/src/gallium/state_trackers/vega/vg_api.h @@ -0,0 +1,37 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef VG_API_H +#define VG_API_H + +struct st_api; + +const struct st_api * +vg_api_get(void); + +#endif /* VG_API_H */ diff --git a/src/gallium/state_trackers/vega/vg_context.c b/src/gallium/state_trackers/vega/vg_context.c new file mode 100644 index 0000000..0844012 --- /dev/null +++ b/src/gallium/state_trackers/vega/vg_context.c @@ -0,0 +1,527 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "vg_context.h" + +#include "paint.h" +#include "renderer.h" +#include "shaders_cache.h" +#include "shader.h" +#include "asm_util.h" +#include "vg_manager.h" +#include "api.h" +#include "mask.h" + +#include "pipe/p_context.h" +#include "util/u_inlines.h" + +#include "cso_cache/cso_context.h" + +#include "util/u_simple_shaders.h" +#include "util/u_memory.h" +#include "util/u_blit.h" +#include "util/u_sampler.h" +#include "util/u_surface.h" +#include "util/u_format.h" + +struct vg_context *_vg_context = 0; + +struct vg_context * vg_current_context(void) +{ + return _vg_context; +} + +/** + * A depth/stencil rb will be needed regardless of what the visual says. + */ +static boolean +choose_depth_stencil_format(struct vg_context *ctx) +{ + struct pipe_screen *screen = ctx->pipe->screen; + enum pipe_format formats[] = { + PIPE_FORMAT_Z24_UNORM_S8_USCALED, + PIPE_FORMAT_S8_USCALED_Z24_UNORM, + PIPE_FORMAT_NONE + }; + enum pipe_format *fmt; + + for (fmt = formats; *fmt != PIPE_FORMAT_NONE; fmt++) { + if (screen->is_format_supported(screen, *fmt, + PIPE_TEXTURE_2D, 0, PIPE_BIND_DEPTH_STENCIL, 0)) + break; + } + + ctx->ds_format = *fmt; + + return (ctx->ds_format != PIPE_FORMAT_NONE); +} + +void vg_set_current_context(struct vg_context *ctx) +{ + _vg_context = ctx; + api_make_dispatch_current((ctx) ? ctx->dispatch : NULL); +} + +struct vg_context * vg_create_context(struct pipe_context *pipe, + const void *visual, + struct vg_context *share) +{ + struct vg_context *ctx; + + ctx = CALLOC_STRUCT(vg_context); + + ctx->pipe = pipe; + if (!choose_depth_stencil_format(ctx)) { + FREE(ctx); + return NULL; + } + + ctx->dispatch = api_create_dispatch(); + + vg_init_state(&ctx->state.vg); + ctx->state.dirty = ALL_DIRTY; + + ctx->cso_context = cso_create_context(pipe); + + ctx->default_paint = paint_create(ctx); + ctx->state.vg.stroke_paint = ctx->default_paint; + ctx->state.vg.fill_paint = ctx->default_paint; + + + ctx->mask.sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->mask.sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->mask.sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->mask.sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + ctx->mask.sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; + ctx->mask.sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; + ctx->mask.sampler.normalized_coords = 0; + + ctx->blend_sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->blend_sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->blend_sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + ctx->blend_sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + ctx->blend_sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; + ctx->blend_sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; + ctx->blend_sampler.normalized_coords = 0; + + vg_set_error(ctx, VG_NO_ERROR); + + ctx->owned_objects[VG_OBJECT_PAINT] = cso_hash_create(); + ctx->owned_objects[VG_OBJECT_IMAGE] = cso_hash_create(); + ctx->owned_objects[VG_OBJECT_MASK] = cso_hash_create(); + ctx->owned_objects[VG_OBJECT_FONT] = cso_hash_create(); + ctx->owned_objects[VG_OBJECT_PATH] = cso_hash_create(); + + ctx->renderer = renderer_create(ctx); + ctx->sc = shaders_cache_create(ctx); + ctx->shader = shader_create(ctx); + + ctx->blit = util_create_blit(ctx->pipe, ctx->cso_context); + + return ctx; +} + +void vg_destroy_context(struct vg_context *ctx) +{ + struct pipe_resource **cbuf = &ctx->mask.cbuf; + + util_destroy_blit(ctx->blit); + renderer_destroy(ctx->renderer); + shaders_cache_destroy(ctx->sc); + shader_destroy(ctx->shader); + paint_destroy(ctx->default_paint); + + if (*cbuf) + pipe_resource_reference(cbuf, NULL); + + if (ctx->mask.union_fs) + vg_shader_destroy(ctx, ctx->mask.union_fs); + if (ctx->mask.intersect_fs) + vg_shader_destroy(ctx, ctx->mask.intersect_fs); + if (ctx->mask.subtract_fs) + vg_shader_destroy(ctx, ctx->mask.subtract_fs); + if (ctx->mask.set_fs) + vg_shader_destroy(ctx, ctx->mask.set_fs); + + cso_release_all(ctx->cso_context); + cso_destroy_context(ctx->cso_context); + + cso_hash_delete(ctx->owned_objects[VG_OBJECT_PAINT]); + cso_hash_delete(ctx->owned_objects[VG_OBJECT_IMAGE]); + cso_hash_delete(ctx->owned_objects[VG_OBJECT_MASK]); + cso_hash_delete(ctx->owned_objects[VG_OBJECT_FONT]); + cso_hash_delete(ctx->owned_objects[VG_OBJECT_PATH]); + + api_destroy_dispatch(ctx->dispatch); + + FREE(ctx); +} + +void vg_init_object(struct vg_object *obj, struct vg_context *ctx, enum vg_object_type type) +{ + obj->type = type; + obj->ctx = ctx; +} + +VGboolean vg_context_is_object_valid(struct vg_context *ctx, + enum vg_object_type type, + void *ptr) +{ + if (ctx) { + struct cso_hash *hash = ctx->owned_objects[type]; + if (!hash) + return VG_FALSE; + return cso_hash_contains(hash, (unsigned)(long)ptr); + } + return VG_FALSE; +} + +void vg_context_add_object(struct vg_context *ctx, + enum vg_object_type type, + void *ptr) +{ + if (ctx) { + struct cso_hash *hash = ctx->owned_objects[type]; + if (!hash) + return; + cso_hash_insert(hash, (unsigned)(long)ptr, ptr); + } +} + +void vg_context_remove_object(struct vg_context *ctx, + enum vg_object_type type, + void *ptr) +{ + if (ctx) { + struct cso_hash *hash = ctx->owned_objects[type]; + if (!hash) + return; + cso_hash_take(hash, (unsigned)(long)ptr); + } +} + +static struct pipe_resource * +create_texture(struct pipe_context *pipe, enum pipe_format format, + VGint width, VGint height) +{ + struct pipe_resource templ; + + memset(&templ, 0, sizeof(templ)); + + if (format != PIPE_FORMAT_NONE) { + templ.format = format; + } + else { + templ.format = PIPE_FORMAT_B8G8R8A8_UNORM; + } + + templ.target = PIPE_TEXTURE_2D; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.array_size = 1; + templ.last_level = 0; + + if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1)) { + templ.bind = PIPE_BIND_DEPTH_STENCIL; + } else { + templ.bind = (PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_RENDER_TARGET | + PIPE_BIND_SAMPLER_VIEW); + } + + return pipe->screen->resource_create(pipe->screen, &templ); +} + +static struct pipe_sampler_view * +create_tex_and_view(struct pipe_context *pipe, enum pipe_format format, + VGint width, VGint height) +{ + struct pipe_resource *texture; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; + + texture = create_texture(pipe, format, width, height); + + if (!texture) + return NULL; + + u_sampler_view_default_template(&view_templ, texture, texture->format); + view = pipe->create_sampler_view(pipe, texture, &view_templ); + /* want the texture to go away if the view is freed */ + pipe_resource_reference(&texture, NULL); + + return view; +} + +static void +vg_context_update_surface_mask_view(struct vg_context *ctx, + uint width, uint height) +{ + struct st_framebuffer *stfb = ctx->draw_buffer; + struct pipe_sampler_view *old_sampler_view = stfb->surface_mask_view; + struct pipe_context *pipe = ctx->pipe; + + if (old_sampler_view && + old_sampler_view->texture->width0 == width && + old_sampler_view->texture->height0 == height) + return; + + /* + we use PIPE_FORMAT_B8G8R8A8_UNORM because we want to render to + this texture and use it as a sampler, so while this wastes some + space it makes both of those a lot simpler + */ + stfb->surface_mask_view = create_tex_and_view(pipe, + PIPE_FORMAT_B8G8R8A8_UNORM, width, height); + + if (!stfb->surface_mask_view) { + if (old_sampler_view) + pipe_sampler_view_reference(&old_sampler_view, NULL); + return; + } + + /* XXX could this call be avoided? */ + vg_validate_state(ctx); + + /* alpha mask starts with 1.f alpha */ + mask_fill(0, 0, width, height, 1.f); + + /* if we had an old surface copy it over */ + if (old_sampler_view) { + struct pipe_box src_box; + u_box_origin_2d(MIN2(old_sampler_view->texture->width0, + stfb->surface_mask_view->texture->width0), + MIN2(old_sampler_view->texture->height0, + stfb->surface_mask_view->texture->height0), + &src_box); + + pipe->resource_copy_region(pipe, + stfb->surface_mask_view->texture, + 0, 0, 0, 0, + old_sampler_view->texture, + 0, &src_box); + } + + /* Free the old texture + */ + if (old_sampler_view) + pipe_sampler_view_reference(&old_sampler_view, NULL); +} + +static void +vg_context_update_blend_texture_view(struct vg_context *ctx, + uint width, uint height) +{ + struct pipe_context *pipe = ctx->pipe; + struct st_framebuffer *stfb = ctx->draw_buffer; + struct pipe_sampler_view *old = stfb->blend_texture_view; + + if (old && + old->texture->width0 == width && + old->texture->height0 == height) + return; + + stfb->blend_texture_view = create_tex_and_view(pipe, + PIPE_FORMAT_B8G8R8A8_UNORM, width, height); + + pipe_sampler_view_reference(&old, NULL); +} + +static boolean +vg_context_update_depth_stencil_rb(struct vg_context * ctx, + uint width, uint height) +{ + struct st_renderbuffer *dsrb = ctx->draw_buffer->dsrb; + struct pipe_context *pipe = ctx->pipe; + struct pipe_surface surf_tmpl; + + if ((dsrb->width == width && dsrb->height == height) && dsrb->texture) + return FALSE; + + /* unreference existing ones */ + pipe_surface_reference(&dsrb->surface, NULL); + pipe_resource_reference(&dsrb->texture, NULL); + dsrb->width = dsrb->height = 0; + + dsrb->texture = create_texture(pipe, dsrb->format, width, height); + if (!dsrb->texture) + return TRUE; + + memset(&surf_tmpl, 0, sizeof(surf_tmpl)); + u_surface_default_template(&surf_tmpl, dsrb->texture, + PIPE_BIND_DEPTH_STENCIL); + dsrb->surface = pipe->create_surface(pipe, + dsrb->texture, + &surf_tmpl); + if (!dsrb->surface) { + pipe_resource_reference(&dsrb->texture, NULL); + return TRUE; + } + + dsrb->width = width; + dsrb->height = height; + + assert(dsrb->surface->width == width); + assert(dsrb->surface->height == height); + + return TRUE; +} + +void vg_validate_state(struct vg_context *ctx) +{ + struct st_framebuffer *stfb = ctx->draw_buffer; + + vg_manager_validate_framebuffer(ctx); + + if (vg_context_update_depth_stencil_rb(ctx, stfb->width, stfb->height)) + ctx->state.dirty |= DEPTH_STENCIL_DIRTY; + + /* blend state depends on fb format */ + if (ctx->state.dirty & FRAMEBUFFER_DIRTY) + ctx->state.dirty |= BLEND_DIRTY; + + renderer_validate(ctx->renderer, ctx->state.dirty, + ctx->draw_buffer, &ctx->state.vg); + + ctx->state.dirty = 0; + + shader_set_masking(ctx->shader, ctx->state.vg.masking); + shader_set_image_mode(ctx->shader, ctx->state.vg.image_mode); + shader_set_color_transform(ctx->shader, ctx->state.vg.color_transform); +} + +VGboolean vg_object_is_valid(void *ptr, enum vg_object_type type) +{ + struct vg_object *obj = ptr; + if (ptr && is_aligned(obj) && obj->type == type) + return VG_TRUE; + else + return VG_FALSE; +} + +void vg_set_error(struct vg_context *ctx, + VGErrorCode code) +{ + /*vgGetError returns the oldest error code provided by + * an API call on the current context since the previous + * call to vgGetError on that context (or since the creation + of the context).*/ + if (ctx->_error == VG_NO_ERROR) + ctx->_error = code; +} + +static void vg_prepare_blend_texture(struct vg_context *ctx, + struct pipe_sampler_view *src) +{ + struct st_framebuffer *stfb = ctx->draw_buffer; + struct pipe_surface *surf; + struct pipe_surface surf_tmpl; + + vg_context_update_blend_texture_view(ctx, stfb->width, stfb->height); + + memset(&surf_tmpl, 0, sizeof(surf_tmpl)); + u_surface_default_template(&surf_tmpl, stfb->blend_texture_view->texture, + PIPE_BIND_RENDER_TARGET); + surf = ctx->pipe->create_surface(ctx->pipe, + stfb->blend_texture_view->texture, + &surf_tmpl); + if (surf) { + util_blit_pixels_tex(ctx->blit, + src, 0, 0, stfb->width, stfb->height, + surf, 0, 0, stfb->width, stfb->height, + 0.0, PIPE_TEX_MIPFILTER_NEAREST); + + pipe_surface_reference(&surf, NULL); + } +} + +struct pipe_sampler_view *vg_prepare_blend_surface(struct vg_context *ctx) +{ + struct pipe_context *pipe = ctx->pipe; + struct pipe_sampler_view *view; + struct pipe_sampler_view view_templ; + struct st_framebuffer *stfb = ctx->draw_buffer; + struct st_renderbuffer *strb = stfb->strb; + + vg_validate_state(ctx); + + u_sampler_view_default_template(&view_templ, strb->texture, strb->texture->format); + view = pipe->create_sampler_view(pipe, strb->texture, &view_templ); + + vg_prepare_blend_texture(ctx, view); + + pipe_sampler_view_reference(&view, NULL); + + return stfb->blend_texture_view; +} + + +struct pipe_sampler_view *vg_prepare_blend_surface_from_mask(struct vg_context *ctx) +{ + struct st_framebuffer *stfb = ctx->draw_buffer; + + vg_validate_state(ctx); + + vg_context_update_surface_mask_view(ctx, stfb->width, stfb->height); + vg_prepare_blend_texture(ctx, stfb->surface_mask_view); + + return stfb->blend_texture_view; +} + +struct pipe_sampler_view *vg_get_surface_mask(struct vg_context *ctx) +{ + struct st_framebuffer *stfb = ctx->draw_buffer; + + vg_context_update_surface_mask_view(ctx, stfb->width, stfb->height); + + return stfb->surface_mask_view; +} + +/** + * A transformation from window coordinates to paint coordinates. + */ +VGboolean vg_get_paint_matrix(struct vg_context *ctx, + const struct matrix *paint_to_user, + const struct matrix *user_to_surface, + struct matrix *mat) +{ + struct matrix tmp; + + /* get user-to-paint matrix */ + memcpy(mat, paint_to_user, sizeof(*paint_to_user)); + if (!matrix_invert(mat)) + return VG_FALSE; + + /* get surface-to-user matrix */ + memcpy(&tmp, user_to_surface, sizeof(*user_to_surface)); + if (!matrix_invert(&tmp)) + return VG_FALSE; + + matrix_mult(mat, &tmp); + + return VG_TRUE; +} diff --git a/src/gallium/state_trackers/vega/vg_context.h b/src/gallium/state_trackers/vega/vg_context.h new file mode 100644 index 0000000..d616a20 --- /dev/null +++ b/src/gallium/state_trackers/vega/vg_context.h @@ -0,0 +1,270 @@ +/************************************************************************** + * + * 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 VG_CONTEXT_H +#define VG_CONTEXT_H + +#include "vg_state.h" + +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include "util/u_pointer.h" +#include "util/u_math.h" +#include "state_tracker/st_api.h" + +#include "cso_cache/cso_hash.h" +#include "cso_cache/cso_context.h" + +struct renderer; +struct shaders_cache; +struct shader; +struct vg_shader; +struct mapi_table; + +struct st_renderbuffer { + enum pipe_format format; + struct pipe_surface *surface; + struct pipe_resource *texture; + VGint width, height; +}; + +struct st_framebuffer { + VGint width, height; + struct st_renderbuffer *strb; + struct st_renderbuffer *dsrb; + + struct pipe_sampler_view *surface_mask_view; + + struct pipe_sampler_view *blend_texture_view; + + + struct st_framebuffer_iface *iface; + enum st_attachment_type strb_att; + + void *privateData; +}; + +enum vg_object_type { + VG_OBJECT_UNKNOWN = 0, + VG_OBJECT_PAINT, + VG_OBJECT_IMAGE, + VG_OBJECT_MASK, + VG_OBJECT_FONT, + VG_OBJECT_PATH, + + VG_OBJECT_LAST +}; +enum dirty_state { + BLEND_DIRTY = 1 << 0, + FRAMEBUFFER_DIRTY = 1 << 1, + DEPTH_STENCIL_DIRTY = 1 << 2, + + ALL_DIRTY = BLEND_DIRTY | + FRAMEBUFFER_DIRTY | + DEPTH_STENCIL_DIRTY +}; + +struct vg_context +{ + struct st_context_iface iface; + struct mapi_table *dispatch; + + struct pipe_context *pipe; + enum pipe_format ds_format; + + struct { + struct vg_state vg; + VGbitfield dirty; + } state; + + VGErrorCode _error; + + struct st_framebuffer *draw_buffer; + int32_t draw_buffer_invalid; + + struct cso_hash *owned_objects[VG_OBJECT_LAST]; + + struct { + struct pipe_resource *cbuf; + struct pipe_sampler_state sampler; + + struct vg_shader *union_fs; + struct vg_shader *intersect_fs; + struct vg_shader *subtract_fs; + struct vg_shader *set_fs; + } mask; + + struct cso_context *cso_context; + + struct renderer *renderer; + struct shaders_cache *sc; + struct shader *shader; + + struct pipe_sampler_state blend_sampler; + struct vg_paint *default_paint; + + struct blit_state *blit; +}; + +struct vg_object { + enum vg_object_type type; + struct vg_context *ctx; +}; +void vg_init_object(struct vg_object *obj, struct vg_context *ctx, enum vg_object_type type); +VGboolean vg_object_is_valid(void *ptr, enum vg_object_type type); + +struct vg_context *vg_create_context(struct pipe_context *pipe, + const void *visual, + struct vg_context *share); +void vg_destroy_context(struct vg_context *ctx); +struct vg_context *vg_current_context(void); +void vg_set_current_context(struct vg_context *ctx); + +VGboolean vg_context_is_object_valid(struct vg_context *ctx, + enum vg_object_type type, + void *ptr); +void vg_context_add_object(struct vg_context *ctx, + enum vg_object_type type, + void *ptr); +void vg_context_remove_object(struct vg_context *ctx, + enum vg_object_type type, + void *ptr); + +void vg_validate_state(struct vg_context *ctx); + +void vg_set_error(struct vg_context *ctx, + VGErrorCode code); + +struct pipe_sampler_view *vg_prepare_blend_surface(struct vg_context *ctx); +struct pipe_sampler_view *vg_prepare_blend_surface_from_mask(struct vg_context *ctx); + +struct pipe_sampler_view *vg_get_surface_mask(struct vg_context *ctx); + +VGboolean vg_get_paint_matrix(struct vg_context *ctx, + const struct matrix *paint_to_user, + const struct matrix *user_to_surface, + struct matrix *mat); + +static INLINE VGboolean is_aligned_to(const void *ptr, VGbyte alignment) +{ + void *aligned = align_pointer(ptr, alignment); + return (ptr == aligned) ? VG_TRUE : VG_FALSE; +} + +static INLINE VGboolean is_aligned(const void *ptr) +{ + return is_aligned_to(ptr, 4); +} + +static INLINE void vg_shift_rectx(VGfloat coords[4], + const VGfloat *bounds, + const VGfloat shift) +{ + coords[0] += shift; + coords[2] -= shift; + if (bounds) { + coords[2] = MIN2(coords[2], bounds[2]); + /* bound x/y + width/height */ + if ((coords[0] + coords[2]) > (bounds[0] + bounds[2])) { + coords[2] = (bounds[0] + bounds[2]) - coords[0]; + } + } +} + +static INLINE void vg_shift_recty(VGfloat coords[4], + const VGfloat *bounds, + const VGfloat shift) +{ + coords[1] += shift; + coords[3] -= shift; + if (bounds) { + coords[3] = MIN2(coords[3], bounds[3]); + if ((coords[1] + coords[3]) > (bounds[1] + bounds[3])) { + coords[3] = (bounds[1] + bounds[3]) - coords[1]; + } + } +} + +static INLINE void vg_bound_rect(VGfloat coords[4], + const VGfloat bounds[4], + VGfloat shift[4]) +{ + /* if outside the bounds */ + if (coords[0] > (bounds[0] + bounds[2]) || + coords[1] > (bounds[1] + bounds[3]) || + (coords[0] + coords[2]) < bounds[0] || + (coords[1] + coords[3]) < bounds[1]) { + coords[0] = 0.f; + coords[1] = 0.f; + coords[2] = 0.f; + coords[3] = 0.f; + shift[0] = 0.f; + shift[1] = 0.f; + return; + } + + /* bound x */ + if (coords[0] < bounds[0]) { + shift[0] = bounds[0] - coords[0]; + coords[2] -= shift[0]; + coords[0] = bounds[0]; + } else + shift[0] = 0.f; + + /* bound y */ + if (coords[1] < bounds[1]) { + shift[1] = bounds[1] - coords[1]; + coords[3] -= shift[1]; + coords[1] = bounds[1]; + } else + shift[1] = 0.f; + + shift[2] = bounds[2] - coords[2]; + shift[3] = bounds[3] - coords[3]; + /* bound width/height */ + coords[2] = MIN2(coords[2], bounds[2]); + coords[3] = MIN2(coords[3], bounds[3]); + + /* bound x/y + width/height */ + if ((coords[0] + coords[2]) > (bounds[0] + bounds[2])) { + coords[2] = (bounds[0] + bounds[2]) - coords[0]; + } + if ((coords[1] + coords[3]) > (bounds[1] + bounds[3])) { + coords[3] = (bounds[1] + bounds[3]) - coords[1]; + } + + /* if outside the bounds */ + if ((coords[0] + coords[2]) < bounds[0] || + (coords[1] + coords[3]) < bounds[1]) { + coords[0] = 0.f; + coords[1] = 0.f; + coords[2] = 0.f; + coords[3] = 0.f; + return; + } +} + +#endif diff --git a/src/gallium/state_trackers/vega/vg_manager.c b/src/gallium/state_trackers/vega/vg_manager.c new file mode 100644 index 0000000..de93576 --- /dev/null +++ b/src/gallium/state_trackers/vega/vg_manager.c @@ -0,0 +1,371 @@ +/* + * 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 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "state_tracker/st_api.h" + +#include "pipe/p_context.h" +#include "pipe/p_screen.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "util/u_sampler.h" +#include "util/u_box.h" +#include "util/u_surface.h" + +#include "vg_api.h" +#include "vg_manager.h" +#include "vg_context.h" +#include "image.h" +#include "api.h" + +static boolean +vg_context_update_color_rb(struct vg_context *ctx, struct pipe_resource *pt) +{ + struct st_renderbuffer *strb = ctx->draw_buffer->strb; + struct pipe_context *pipe = ctx->pipe; + struct pipe_surface surf_tmpl; + + if (strb->texture == pt) { + pipe_resource_reference(&pt, NULL); + return FALSE; + } + + /* unreference existing ones */ + pipe_surface_reference(&strb->surface, NULL); + pipe_resource_reference(&strb->texture, NULL); + strb->width = strb->height = 0; + + strb->texture = pt; + + memset(&surf_tmpl, 0, sizeof(surf_tmpl)); + u_surface_default_template(&surf_tmpl, strb->texture, + PIPE_BIND_RENDER_TARGET); + strb->surface = pipe->create_surface(pipe, strb->texture, &surf_tmpl); + + if (!strb->surface) { + pipe_resource_reference(&strb->texture, NULL); + return TRUE; + } + + strb->width = pt->width0; + strb->height = pt->height0; + + return TRUE; +} + +/** + * Flush the front buffer if the current context renders to the front buffer. + */ +void +vg_manager_flush_frontbuffer(struct vg_context *ctx) +{ + struct st_framebuffer *stfb = ctx->draw_buffer; + + if (!stfb) + return; + + switch (stfb->strb_att) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_FRONT_RIGHT: + stfb->iface->flush_front(stfb->iface, stfb->strb_att); + break; + default: + break; + } +} + +/** + * Re-validate the framebuffer. + */ +void +vg_manager_validate_framebuffer(struct vg_context *ctx) +{ + struct st_framebuffer *stfb = ctx->draw_buffer; + struct pipe_resource *pt; + + /* no binding surface */ + if (!stfb) + return; + + if (!p_atomic_read(&ctx->draw_buffer_invalid)) + return; + + /* validate the fb */ + if (!stfb->iface->validate(stfb->iface, &stfb->strb_att, 1, &pt) || !pt) + return; + + p_atomic_set(&ctx->draw_buffer_invalid, FALSE); + + if (vg_context_update_color_rb(ctx, pt) || + stfb->width != pt->width0 || + stfb->height != pt->height0) + ctx->state.dirty |= FRAMEBUFFER_DIRTY; + + stfb->width = pt->width0; + stfb->height = pt->height0; +} + +static void +vg_context_notify_invalid_framebuffer(struct st_context_iface *stctxi, + struct st_framebuffer_iface *stfbi) +{ + struct vg_context *ctx = (struct vg_context *) stctxi; + p_atomic_set(&ctx->draw_buffer_invalid, TRUE); +} + +static void +vg_context_flush(struct st_context_iface *stctxi, unsigned flags, + struct pipe_fence_handle **fence) +{ + struct vg_context *ctx = (struct vg_context *) stctxi; + ctx->pipe->flush(ctx->pipe, flags, fence); + if (flags & PIPE_FLUSH_RENDER_CACHE) + vg_manager_flush_frontbuffer(ctx); +} + +static void +vg_context_destroy(struct st_context_iface *stctxi) +{ + struct vg_context *ctx = (struct vg_context *) stctxi; + struct pipe_context *pipe = ctx->pipe; + + vg_destroy_context(ctx); + pipe->destroy(pipe); +} + +static struct st_context_iface * +vg_api_create_context(struct st_api *stapi, struct st_manager *smapi, + const struct st_context_attribs *attribs, + struct st_context_iface *shared_stctxi) +{ + struct vg_context *shared_ctx = (struct vg_context *) shared_stctxi; + struct vg_context *ctx; + struct pipe_context *pipe; + + if (!(stapi->profile_mask & (1 << attribs->profile))) + return NULL; + + /* only 1.0 is supported */ + if (attribs->major > 1 || (attribs->major == 1 && attribs->minor > 0)) + return NULL; + + pipe = smapi->screen->context_create(smapi->screen, NULL); + if (!pipe) + return NULL; + ctx = vg_create_context(pipe, NULL, shared_ctx); + if (!ctx) { + pipe->destroy(pipe); + return NULL; + } + + ctx->iface.destroy = vg_context_destroy; + + ctx->iface.notify_invalid_framebuffer = + vg_context_notify_invalid_framebuffer; + ctx->iface.flush = vg_context_flush; + + ctx->iface.teximage = NULL; + ctx->iface.copy = NULL; + + ctx->iface.st_context_private = (void *) smapi; + + return &ctx->iface; +} + +static struct st_renderbuffer * +create_renderbuffer(enum pipe_format format) +{ + struct st_renderbuffer *strb; + + strb = CALLOC_STRUCT(st_renderbuffer); + if (strb) + strb->format = format; + + return strb; +} + +static void +destroy_renderbuffer(struct st_renderbuffer *strb) +{ + pipe_surface_reference(&strb->surface, NULL); + pipe_resource_reference(&strb->texture, NULL); + FREE(strb); +} + +/** + * Decide the buffer to render to. + */ +static enum st_attachment_type +choose_attachment(struct st_framebuffer_iface *stfbi) +{ + enum st_attachment_type statt; + + statt = stfbi->visual->render_buffer; + if (statt != ST_ATTACHMENT_INVALID) { + /* use the buffer given by the visual, unless it is unavailable */ + if (!st_visual_have_buffers(stfbi->visual, 1 << statt)) { + switch (statt) { + case ST_ATTACHMENT_BACK_LEFT: + statt = ST_ATTACHMENT_FRONT_LEFT; + break; + case ST_ATTACHMENT_BACK_RIGHT: + statt = ST_ATTACHMENT_FRONT_RIGHT; + break; + default: + break; + } + + if (!st_visual_have_buffers(stfbi->visual, 1 << statt)) + statt = ST_ATTACHMENT_INVALID; + } + } + + return statt; +} + +/** + * Bind the context to the given framebuffers. + */ +static boolean +vg_context_bind_framebuffers(struct st_context_iface *stctxi, + struct st_framebuffer_iface *stdrawi, + struct st_framebuffer_iface *streadi) +{ + struct vg_context *ctx = (struct vg_context *) stctxi; + struct st_framebuffer *stfb; + enum st_attachment_type strb_att; + + /* the draw and read framebuffers must be the same */ + if (stdrawi != streadi) + return FALSE; + + p_atomic_set(&ctx->draw_buffer_invalid, TRUE); + + strb_att = (stdrawi) ? choose_attachment(stdrawi) : ST_ATTACHMENT_INVALID; + + if (ctx->draw_buffer) { + stfb = ctx->draw_buffer; + + /* free the existing fb */ + if (!stdrawi || + stfb->strb_att != strb_att || + stfb->strb->format != stdrawi->visual->color_format) { + destroy_renderbuffer(stfb->strb); + destroy_renderbuffer(stfb->dsrb); + FREE(stfb); + + ctx->draw_buffer = NULL; + } + } + + if (!stdrawi) + return TRUE; + + if (strb_att == ST_ATTACHMENT_INVALID) + return FALSE; + + /* create a new fb */ + if (!ctx->draw_buffer) { + stfb = CALLOC_STRUCT(st_framebuffer); + if (!stfb) + return FALSE; + + stfb->strb = create_renderbuffer(stdrawi->visual->color_format); + if (!stfb->strb) { + FREE(stfb); + return FALSE; + } + + stfb->dsrb = create_renderbuffer(ctx->ds_format); + if (!stfb->dsrb) { + FREE(stfb->strb); + FREE(stfb); + return FALSE; + } + + stfb->width = 0; + stfb->height = 0; + stfb->strb_att = strb_att; + + ctx->draw_buffer = stfb; + } + + ctx->draw_buffer->iface = stdrawi; + + return TRUE; +} + +static boolean +vg_api_make_current(struct st_api *stapi, struct st_context_iface *stctxi, + struct st_framebuffer_iface *stdrawi, + struct st_framebuffer_iface *streadi) +{ + struct vg_context *ctx = (struct vg_context *) stctxi; + + if (stctxi) + vg_context_bind_framebuffers(stctxi, stdrawi, streadi); + vg_set_current_context(ctx); + + return TRUE; +} + +static struct st_context_iface * +vg_api_get_current(struct st_api *stapi) +{ + struct vg_context *ctx = vg_current_context(); + + return (ctx) ? &ctx->iface : NULL; +} + +static st_proc_t +vg_api_get_proc_address(struct st_api *stapi, const char *procname) +{ + return api_get_proc_address(procname); +} + +static void +vg_api_destroy(struct st_api *stapi) +{ +} + +static const struct st_api vg_api = { + "Vega " VEGA_VERSION_STRING, + ST_API_OPENVG, + ST_PROFILE_DEFAULT_MASK, + vg_api_destroy, + vg_api_get_proc_address, + vg_api_create_context, + vg_api_make_current, + vg_api_get_current, +}; + +const struct st_api * +vg_api_get(void) +{ + return &vg_api; +} diff --git a/src/gallium/state_trackers/vega/vg_manager.h b/src/gallium/state_trackers/vega/vg_manager.h new file mode 100644 index 0000000..1d97eb8 --- /dev/null +++ b/src/gallium/state_trackers/vega/vg_manager.h @@ -0,0 +1,41 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef VG_MANAGER_H +#define VG_MANAGER_H + +#include "state_tracker/st_api.h" +#include "vg_context.h" + +void +vg_manager_flush_frontbuffer(struct vg_context *ctx); + +void +vg_manager_validate_framebuffer(struct vg_context *ctx); + +#endif /* VG_MANAGER_H */ diff --git a/src/gallium/state_trackers/vega/vg_state.c b/src/gallium/state_trackers/vega/vg_state.c new file mode 100644 index 0000000..6f6bfda --- /dev/null +++ b/src/gallium/state_trackers/vega/vg_state.c @@ -0,0 +1,124 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "vg_state.h" + +#include + +void vg_init_state(struct vg_state *state) +{ + state->matrix_mode = VG_MATRIX_PATH_USER_TO_SURFACE; + state->fill_rule = VG_EVEN_ODD; + state->image_quality = VG_IMAGE_QUALITY_FASTER; + state->rendering_quality = VG_RENDERING_QUALITY_BETTER; + state->blend_mode = VG_BLEND_SRC_OVER; + state->image_mode = VG_DRAW_IMAGE_NORMAL; + + memset(state->scissor_rects, 0, sizeof(state->scissor_rects)); + state->scissor_rects_num = 0; + + state->color_transform = VG_FALSE; + state->color_transform_values[0] = 1.0f; + state->color_transform_values[1] = 1.0f; + state->color_transform_values[2] = 1.0f; + state->color_transform_values[3] = 1.0f; + state->color_transform_values[4] = 0.0f; + state->color_transform_values[5] = 0.0f; + state->color_transform_values[6] = 0.0f; + state->color_transform_values[7] = 0.0f; + + /* Stroke parameters */ + state->stroke.line_width.f = 1.0f; + state->stroke.line_width.i = 1; + state->stroke.cap_style = VG_CAP_BUTT; + state->stroke.join_style = VG_JOIN_MITER; + state->stroke.miter_limit.f = 4.0f; + state->stroke.miter_limit.i = 4; + state->stroke.dash_pattern_num = 0; + state->stroke.dash_phase.f = 0.0f; + state->stroke.dash_phase.i = 0; + state->stroke.dash_phase_reset = VG_FALSE; + + /* Edge fill color for VG_TILE_FILL tiling mode */ + state->tile_fill_color[0] = 0.0f; + state->tile_fill_color[1] = 0.0f; + state->tile_fill_color[2] = 0.0f; + state->tile_fill_color[3] = 0.0f; + + /* Color for vgClear */ + state->clear_color[0] = 0.0f; + state->clear_color[1] = 0.0f; + state->clear_color[2] = 0.0f; + state->clear_color[3] = 0.0f; + + /* Glyph origin */ + state->glyph_origin[0].f = 0.0f; + state->glyph_origin[1].f = 0.0f; + state->glyph_origin[0].i = 0; + state->glyph_origin[1].i = 0; + + /* Enable/disable alpha masking and scissoring */ + state->masking = VG_FALSE; + state->scissoring = VG_FALSE; + + /* Pixel layout information */ + state->pixel_layout = VG_PIXEL_LAYOUT_UNKNOWN; + state->screen_layout = VG_PIXEL_LAYOUT_UNKNOWN; + + /* Source format selection for image filters */ + state->filter_format_linear = VG_FALSE; + state->filter_format_premultiplied = VG_FALSE; + + /* Destination write enable mask for image filters */ + state->filter_channel_mask = (VG_RED | VG_GREEN | VG_BLUE | VG_ALPHA); + + matrix_load_identity(&state->path_user_to_surface_matrix); + matrix_load_identity(&state->image_user_to_surface_matrix); + matrix_load_identity(&state->fill_paint_to_user_matrix); + matrix_load_identity(&state->stroke_paint_to_user_matrix); + matrix_load_identity(&state->glyph_user_to_surface_matrix); +} + +struct matrix *vg_state_matrix(struct vg_state *state) +{ + switch(state->matrix_mode) { + case VG_MATRIX_PATH_USER_TO_SURFACE: + return &state->path_user_to_surface_matrix; + case VG_MATRIX_IMAGE_USER_TO_SURFACE: + return &state->image_user_to_surface_matrix; + case VG_MATRIX_FILL_PAINT_TO_USER: + return &state->fill_paint_to_user_matrix; + case VG_MATRIX_STROKE_PAINT_TO_USER: + return &state->stroke_paint_to_user_matrix; +#ifdef OPENVG_VERSION_1_1 + case VG_MATRIX_GLYPH_USER_TO_SURFACE: + return &state->glyph_user_to_surface_matrix; +#endif + default: + break; + } + return NULL; +} diff --git a/src/gallium/state_trackers/vega/vg_state.h b/src/gallium/state_trackers/vega/vg_state.h new file mode 100644 index 0000000..ed90689 --- /dev/null +++ b/src/gallium/state_trackers/vega/vg_state.h @@ -0,0 +1,109 @@ +/************************************************************************** + * + * 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 VG_STATE_H +#define VG_STATE_H + +#include "VG/openvg.h" + +#include "api_consts.h" +#include "matrix.h" + +struct vg_value +{ + VGfloat f; + VGint i; +}; + +struct vg_state { + /* Mode settings */ + VGMatrixMode matrix_mode; + VGFillRule fill_rule; + VGImageQuality image_quality; + VGRenderingQuality rendering_quality; + VGBlendMode blend_mode; + VGImageMode image_mode; + + /* Scissoring rectangles */ + struct vg_value scissor_rects[32*4]; + VGint scissor_rects_num; + + /* Color Transformation */ + VGboolean color_transform; + VGfloat color_transform_values[8]; + + /* Stroke parameters */ + struct { + struct vg_value line_width; + VGCapStyle cap_style; + VGJoinStyle join_style; + struct vg_value miter_limit; + struct vg_value dash_pattern[VEGA_MAX_DASH_COUNT]; + VGint dash_pattern_num; + struct vg_value dash_phase; + VGboolean dash_phase_reset; + } stroke; + + /* Edge fill color for VG_TILE_FILL tiling mode */ + VGfloat tile_fill_color[4]; + VGint tile_fill_colori[4]; + + /* Color for vgClear */ + VGfloat clear_color[4]; + VGint clear_colori[4]; + + /* Glyph origin */ + struct vg_value glyph_origin[2]; + + /* Enable/disable alpha masking and scissoring */ + VGboolean masking; + VGboolean scissoring; + + /* Pixel layout information */ + VGPixelLayout pixel_layout; + VGPixelLayout screen_layout; + + /* Source format selection for image filters */ + VGboolean filter_format_linear; + VGboolean filter_format_premultiplied; + + /* Destination write enable mask for image filters */ + VGbitfield filter_channel_mask; + + struct matrix path_user_to_surface_matrix; + struct matrix image_user_to_surface_matrix; + struct matrix fill_paint_to_user_matrix; + struct matrix stroke_paint_to_user_matrix; + struct matrix glyph_user_to_surface_matrix; + + struct vg_paint *stroke_paint; + struct vg_paint *fill_paint; +}; + +void vg_init_state(struct vg_state *state); +struct matrix * vg_state_matrix(struct vg_state *state); + +#endif diff --git a/src/gallium/state_trackers/vega/vg_translate.c b/src/gallium/state_trackers/vega/vg_translate.c new file mode 100644 index 0000000..03575ca --- /dev/null +++ b/src/gallium/state_trackers/vega/vg_translate.c @@ -0,0 +1,1112 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "vg_translate.h" + +#include "pipe/p_format.h" +#include "util/u_pack_color.h" + +void _vega_pack_rgba_span_float(struct vg_context *ctx, + VGuint n, VGfloat rgba[][4], + VGImageFormat dstFormat, + void *dstAddr) +{ + VGint i; + + switch (dstFormat) { + case VG_sRGBX_8888: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = 255; + dst[i] = r << 24 | g << 16 | b << 8 | a; + } + return; + } + break; + case VG_sRGBA_8888: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = r << 24 | g << 16 | b << 8 | a; + } + return; + } + break; + case VG_sRGBA_8888_PRE: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = r << 24 | g << 16 | b << 8 | a; + } + return; + } + break; + case VG_sRGB_565: { + VGshort *dst = (VGshort *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + r = (r / 255.0) * 32; + g = (g / 255.0) * 32; + b = (b / 255.0) * 32; + + dst[i] = b | g << 5 | r << 11; + } + return; + } + break; + case VG_sRGBA_5551: { + VGshort *dst = (VGshort *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b, a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + r = (r / 255.0) * 32; + g = (g / 255.0) * 32; + b = (b / 255.0) * 32; + a = (a / 255.0); + + dst[i] = a | b << 1 | g << 6 | r << 11; + } + return; + } + break; + case VG_sRGBA_4444: { + VGshort *dst = (VGshort *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b, a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + r = (r / 255.0) * 16; + g = (g / 255.0) * 16; + b = (b / 255.0) * 16; + a = (a / 255.0) * 16; + + dst[i] = a | b << 4 | g << 8 | r << 12; + } + return; + } + break; + case VG_sL_8: { + VGubyte *dst = (VGubyte *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b, a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + + dst[i] = a; + } + return; + } + break; + case VG_lRGBX_8888: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = 255; + dst[i] = r << 24 | g << 16 | b << 8 | a; + } + return; + } + break; + case VG_lRGBA_8888: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = r << 24 | g << 16 | b << 8 | a; + } + return; + } + case VG_lRGBA_8888_PRE: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = r << 24 | g << 16 | b << 8 | a; + } + return; + } + break; + case VG_lL_8: { + VGubyte *dst = (VGubyte *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = a; + } + return; + } + break; + case VG_A_8: { + VGubyte *dst = (VGubyte *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b, a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + + dst[i] = a; + } + return; + } + break; + case VG_BW_1: { + VGshort *dst = (VGshort *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b, a; + VGubyte res; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + + res = (r + g + b + a)/4; + dst[i] = (res & (128)); + } + return; + } + break; +#ifdef OPENVG_VERSION_1_1 + case VG_A_1: { + VGshort *dst = (VGshort *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b, a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + + dst[i] = (a & (128)); + } + return; + } + break; + case VG_A_4: { + VGshort *dst = (VGshort *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b, a; + VGubyte res; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + + res = a/4; + dst[i] = (res & (128)); + } + return; + } + break; +#endif + case VG_sXRGB_8888: + break; + case VG_sARGB_8888: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = a << 24 | r << 16 | g << 8 | b; + } + return; + } + break; + case VG_sARGB_8888_PRE: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = a << 24 | r << 16 | g << 8 | b; + } + return; + } + break; + case VG_sARGB_1555: + break; + case VG_sARGB_4444: + break; + case VG_lXRGB_8888: + break; + case VG_lARGB_8888: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = a << 24 | r << 16 | g << 8 | b; + } + return; + } + break; + case VG_lARGB_8888_PRE: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = a << 24 | r << 16 | g << 8 | b; + } + return; + } + break; + case VG_sBGRX_8888: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = 0xff; + dst[i] = b << 24 | g << 16 | r << 8 | a; + } + return; + } + break; + case VG_sBGRA_8888: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = b << 24 | g << 16 | r << 8 | a; + } + return; + } + break; + case VG_sBGRA_8888_PRE: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = b << 24 | g << 16 | r << 8 | a; + } + return; + } + break; + case VG_sBGR_565: + break; + case VG_sBGRA_5551: + break; + case VG_sBGRA_4444: + break; + case VG_lBGRX_8888: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = 0xff; + dst[i] = b << 24 | g << 16 | r << 8 | a; + } + return; + } + break; + case VG_lBGRA_8888: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = b << 24 | g << 16 | r << 8 | a; + } + return; + } + break; + case VG_lBGRA_8888_PRE: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = b << 24 | g << 16 | r << 8 | a; + } + return; + } + break; + case VG_sXBGR_8888: + break; + case VG_sABGR_8888: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = a << 24 | b << 16 | g << 8 | r; + } + return; + } + break; + case VG_sABGR_8888_PRE: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = a << 24 | b << 16 | g << 8 | r; + } + return; + } + break; + case VG_sABGR_1555: + break; + case VG_sABGR_4444: + break; + case VG_lXBGR_8888: + break; + case VG_lABGR_8888: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = a << 24 | b << 16 | g << 8 | r; + } + return; + } + break; + case VG_lABGR_8888_PRE: { + VGint *dst = (VGint *)dstAddr; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = float_to_ubyte(rgba[i][0]); + g = float_to_ubyte(rgba[i][1]); + b = float_to_ubyte(rgba[i][2]); + a = float_to_ubyte(rgba[i][3]); + dst[i] = a << 24 | b << 16 | g << 8 | r; + } + return; + } + break; + default: + assert(!"Unknown ReadPixels format"); + break; + } + assert(!"Not implemented ReadPixels format"); +} + +void _vega_unpack_float_span_rgba(struct vg_context *ctx, + VGuint n, + VGuint offset, + const void * data, + VGImageFormat dataFormat, + VGfloat rgba[][4]) +{ + VGint i; + union util_color uc; + + switch (dataFormat) { + case VG_sRGBX_8888: { + VGuint *src = (VGuint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = (*src >> 24) & 0xff; + g = (*src >> 16) & 0xff; + b = (*src >> 8) & 0xff; + a = 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + } + return; + case VG_sRGBA_8888: { + VGuint *src = (VGuint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = (*src >> 24) & 0xff; + g = (*src >> 16) & 0xff; + b = (*src >> 8) & 0xff; + a = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_sRGBA_8888_PRE: { + VGint *src = (VGint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = (*src >> 24) & 0xff; + g = (*src >> 16) & 0xff; + b = (*src >> 8) & 0xff; + a = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_sRGB_565: { + VGshort *src = (VGshort *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGfloat clr[4]; + clr[0] = ((*src >> 10) & 31)/31.; + clr[1] = ((*src >> 5) & 95)/95.; + clr[2] = ((*src >> 0) & 31)/31.; + clr[3] = 1.f; + + util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + } + return; + case VG_sRGBA_5551: { + VGshort *src = (VGshort *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGfloat clr[4]; + clr[0] = ((*src >> 10) & 31)/31.; + clr[1] = ((*src >> 5) & 31)/31.; + clr[2] = ((*src >> 1) & 31)/31.; + clr[3] = ((*src >> 0) & 1)/1.; + + util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + } + return; + case VG_sRGBA_4444: { + VGshort *src = (VGshort *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGfloat clr[4]; + clr[0] = ((*src >> 12) & 15)/15.; + clr[1] = ((*src >> 8) & 15)/15.; + clr[2] = ((*src >> 4) & 15)/15.; + clr[3] = ((*src >> 0) & 15)/15.; + + util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + } + return; + case VG_sL_8: { + VGubyte *src = (VGubyte *)data; + src += offset; + for (i = 0; i < n; ++i) { + util_pack_color_ub(0xff, 0xff, 0xff, *src, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + } + return; + case VG_lRGBX_8888: { + VGuint *src = (VGuint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = (*src >> 24) & 0xff; + g = (*src >> 16) & 0xff; + b = (*src >> 8) & 0xff; + a = 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + } + return; + case VG_lRGBA_8888: { + VGint *src = (VGint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = (*src >> 24) & 0xff; + g = (*src >> 16) & 0xff; + b = (*src >> 8) & 0xff; + a = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_lRGBA_8888_PRE: { + VGint *src = (VGint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + r = (*src >> 24) & 0xff; + g = (*src >> 16) & 0xff; + b = (*src >> 8) & 0xff; + a = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_lL_8: { + VGubyte *src = (VGubyte *)data; + src += offset; + for (i = 0; i < n; ++i) { + util_pack_color_ub(0xff, 0xff, 0xff, *src, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + } + return; + case VG_A_8: { + VGubyte *src = (VGubyte *)data; + src += offset; + for (i = 0; i < n; ++i) { + util_pack_color_ub(0xff, 0xff, 0xff, *src, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + } + return; + case VG_BW_1: { + VGubyte *src = (VGubyte *)data; + src += offset; + for (i = 0; i < n; i += 8) { + VGfloat clr[4]; + VGint j; + for (j = 0; j < 8 && j < n ; ++j) { + VGint shift = j; + clr[0] = (((*src) & (1<> shift); + clr[1] = clr[0]; + clr[2] = clr[0]; + clr[3] = 1.f; + + util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i+j][0] = uc.f[0]; + rgba[i+j][1] = uc.f[1]; + rgba[i+j][2] = uc.f[2]; + rgba[i+j][3] = uc.f[3]; + } + ++src; + } + } + return; +#ifdef OPENVG_VERSION_1_1 + case VG_A_1: { + VGubyte *src = (VGubyte *)data; + src += offset; + for (i = 0; i < n; i += 8) { + VGfloat clr[4]; + VGint j; + for (j = 0; j < 8 && j < n ; ++j) { + VGint shift = j; + clr[0] = 0.f; + clr[1] = 0.f; + clr[2] = 0.f; + clr[3] = (((*src) & (1<> shift); + + util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i+j][0] = uc.f[0]; + rgba[i+j][1] = uc.f[1]; + rgba[i+j][2] = uc.f[2]; + rgba[i+j][3] = uc.f[3]; + } + ++src; + } + } + return; + case VG_A_4: { + VGubyte *src = (VGubyte *)data; + src += offset/2; + for (i = 0; i < n; i += 2) { + VGfloat clr[4]; + VGint j; + for (j = 0; j < n && j < 2; ++j) { + VGint bitter, shift; + if (j == 0) { + bitter = 0x0f; + shift = 0; + } else { + bitter = 0xf0; + shift = 4; + } + clr[0] = 0.f; + clr[1] = 0.f; + clr[2] = 0.f; + clr[3] = ((*src) & (bitter)) >> shift; + + util_pack_color(clr, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i+j][0] = uc.f[0]; + rgba[i+j][1] = uc.f[1]; + rgba[i+j][2] = uc.f[2]; + rgba[i+j][3] = uc.f[3]; + } + ++src; + } + } + return; +#endif + case VG_sXRGB_8888: + break; + case VG_sARGB_8888: { + VGuint *src = (VGuint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + a = (*src >> 24) & 0xff; + r = (*src >> 16) & 0xff; + g = (*src >> 8) & 0xff; + b = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_sARGB_8888_PRE: { + VGuint *src = (VGuint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + a = (*src >> 24) & 0xff; + r = (*src >> 16) & 0xff; + g = (*src >> 8) & 0xff; + b = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_sARGB_1555: + break; + case VG_sARGB_4444: + break; + case VG_lXRGB_8888: + break; + case VG_lARGB_8888: { + VGint *src = (VGint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + a = (*src >> 24) & 0xff; + r = (*src >> 16) & 0xff; + g = (*src >> 8) & 0xff; + b = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_lARGB_8888_PRE: { + VGint *src = (VGint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + a = (*src >> 24) & 0xff; + r = (*src >> 16) & 0xff; + g = (*src >> 8) & 0xff; + b = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_sBGRX_8888: + break; + case VG_sBGRA_8888: { + VGuint *src = (VGuint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + b = (*src >> 24) & 0xff; + g = (*src >> 16) & 0xff; + r = (*src >> 8) & 0xff; + a = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_sBGRA_8888_PRE: { + VGuint *src = (VGuint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + b = (*src >> 24) & 0xff; + g = (*src >> 16) & 0xff; + r = (*src >> 8) & 0xff; + a = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_sBGR_565: + break; + case VG_sBGRA_5551: + break; + case VG_sBGRA_4444: + break; + case VG_lBGRX_8888: + break; + case VG_lBGRA_8888: { + VGuint *src = (VGuint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + b = (*src >> 24) & 0xff; + g = (*src >> 16) & 0xff; + r = (*src >> 8) & 0xff; + a = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_lBGRA_8888_PRE: { + VGuint *src = (VGuint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + b = (*src >> 24) & 0xff; + g = (*src >> 16) & 0xff; + r = (*src >> 8) & 0xff; + a = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_sXBGR_8888: + break; + case VG_sABGR_8888: { + VGuint *src = (VGuint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + a = (*src >> 24) & 0xff; + b = (*src >> 16) & 0xff; + g = (*src >> 8) & 0xff; + r = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_sABGR_8888_PRE: { + VGuint *src = (VGuint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + a = (*src >> 24) & 0xff; + b = (*src >> 16) & 0xff; + g = (*src >> 8) & 0xff; + r = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_sABGR_1555: + break; + case VG_sABGR_4444: + break; + case VG_lXBGR_8888: + break; + case VG_lABGR_8888: { + VGuint *src = (VGuint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + a = (*src >> 24) & 0xff; + b = (*src >> 16) & 0xff; + g = (*src >> 8) & 0xff; + r = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + case VG_lABGR_8888_PRE: { + VGuint *src = (VGuint *)data; + src += offset; + for (i = 0; i < n; ++i) { + VGubyte r, g, b ,a; + a = (*src >> 24) & 0xff; + b = (*src >> 16) & 0xff; + g = (*src >> 8) & 0xff; + r = (*src >> 0) & 0xff; + + util_pack_color_ub(r, g, b, a, PIPE_FORMAT_R32G32B32A32_FLOAT, &uc); + rgba[i][0] = uc.f[0]; + rgba[i][1] = uc.f[1]; + rgba[i][2] = uc.f[2]; + rgba[i][3] = uc.f[3]; + ++src; + } + return; + } + break; + default: + assert(!"Unknown ReadPixels format"); + break; + } + assert(!"Not implemented ReadPixels format"); +} + +VGint _vega_size_for_format(VGImageFormat dataFormat) +{ + switch (dataFormat) { + case VG_sRGBX_8888: + case VG_sRGBA_8888: + case VG_sRGBA_8888_PRE: + return 4; + case VG_sRGB_565: + case VG_sRGBA_5551: + case VG_sRGBA_4444: + return 2; + case VG_sL_8: + return 1; + case VG_lRGBX_8888: + case VG_lRGBA_8888: + case VG_lRGBA_8888_PRE: + return 4; + case VG_lL_8: + return 1; + case VG_A_8: + return 1; + case VG_BW_1: + return 1; +#ifdef OPENVG_VERSION_1_1 + case VG_A_1: + break; + case VG_A_4: + break; +#endif + case VG_sXRGB_8888: + case VG_sARGB_8888: + case VG_sARGB_8888_PRE: + return 4; + case VG_sARGB_1555: + case VG_sARGB_4444: + return 2; + case VG_lXRGB_8888: + case VG_lARGB_8888: + case VG_lARGB_8888_PRE: + case VG_sBGRX_8888: + case VG_sBGRA_8888: + case VG_sBGRA_8888_PRE: + return 4; + case VG_sBGR_565: + case VG_sBGRA_5551: + case VG_sBGRA_4444: + return 2; + case VG_lBGRX_8888: + case VG_lBGRA_8888: + case VG_lBGRA_8888_PRE: + case VG_sXBGR_8888: + case VG_sABGR_8888: + case VG_sABGR_8888_PRE: + return 4; + case VG_sABGR_1555: + case VG_sABGR_4444: + return 2; + case VG_lXBGR_8888: + case VG_lABGR_8888: + case VG_lABGR_8888_PRE: + return 4; + default: + assert(!"Unknown ReadPixels format"); + break; + } + assert(!"Not implemented ReadPixels format"); + return 0; +} diff --git a/src/gallium/state_trackers/vega/vg_translate.h b/src/gallium/state_trackers/vega/vg_translate.h new file mode 100644 index 0000000..70815ba --- /dev/null +++ b/src/gallium/state_trackers/vega/vg_translate.h @@ -0,0 +1,49 @@ +/************************************************************************** + * + * 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 VG_TRANSLATE_H +#define VG_TRANSLATE_H + +#include "VG/openvg.h" +#include "vg_context.h" + +/*FIXME: we really should be using translate module + * but pipe_format can't express some of the VG formats + * (the premultiplied ones) so currently it won't work */ + +void _vega_pack_rgba_span_float(struct vg_context *ctx, + VGuint n, VGfloat rgba[][4], + VGImageFormat dstFormat, + void *dstAddr); +void _vega_unpack_float_span_rgba(struct vg_context *ctx, + VGuint n, + VGuint offset, + const void * data, + VGImageFormat dataFormat, + VGfloat rgba[][4]); +VGint _vega_size_for_format(VGImageFormat format); + +#endif diff --git a/src/gallium/state_trackers/vega/vgu.c b/src/gallium/state_trackers/vega/vgu.c new file mode 100644 index 0000000..7dc51c5 --- /dev/null +++ b/src/gallium/state_trackers/vega/vgu.c @@ -0,0 +1,450 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "VG/openvg.h" +#include "VG/vgu.h" + +#include "matrix.h" +#include "path.h" + +#include "util/u_debug.h" +#include "util/u_pointer.h" + +#include +#include + +static VGboolean is_aligned_to(const void *ptr, VGbyte alignment) +{ + void *aligned = align_pointer(ptr, alignment); + return (ptr == aligned) ? VG_TRUE : VG_FALSE; +} + +static VGboolean is_aligned(const void *ptr) +{ + return is_aligned_to(ptr, 4); +} + +static void vgu_append_float_coords(VGPath path, + const VGubyte *cmds, + VGint num_cmds, + const VGfloat *coords, + VGint num_coords) +{ + VGubyte common_data[40 * sizeof(VGfloat)]; + struct path *p = (struct path *)path; + + vg_float_to_datatype(path_datatype(p), common_data, coords, num_coords); + vgAppendPathData(path, num_cmds, cmds, common_data); +} + +VGUErrorCode vguLine(VGPath path, + VGfloat x0, VGfloat y0, + VGfloat x1, VGfloat y1) +{ + static const VGubyte cmds[] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS}; + VGfloat coords[4]; + VGbitfield caps; + + if (path == VG_INVALID_HANDLE) { + return VGU_BAD_HANDLE_ERROR; + } + caps = vgGetPathCapabilities(path); + if (!(caps & VG_PATH_CAPABILITY_APPEND_TO)) { + return VGU_PATH_CAPABILITY_ERROR; + } + + coords[0] = x0; + coords[1] = y0; + coords[2] = x1; + coords[3] = y1; + + vgu_append_float_coords(path, cmds, 2, coords, 4); + + return VGU_NO_ERROR; +} + +VGUErrorCode vguPolygon(VGPath path, + const VGfloat * points, + VGint count, + VGboolean closed) +{ + VGubyte *cmds; + VGfloat *coords; + VGbitfield caps; + VGint i; + + if (path == VG_INVALID_HANDLE) { + return VGU_BAD_HANDLE_ERROR; + } + + if (!points || count <= 0 || !is_aligned(points)) { + return VGU_ILLEGAL_ARGUMENT_ERROR; + } + + caps = vgGetPathCapabilities(path); + if (!(caps & VG_PATH_CAPABILITY_APPEND_TO)) { + return VGU_PATH_CAPABILITY_ERROR; + } + + cmds = malloc(sizeof(VGubyte) * count + 1); + coords = malloc(sizeof(VGfloat) * count * 2); + + cmds[0] = VG_MOVE_TO_ABS; + coords[0] = points[0]; + coords[1] = points[1]; + for (i = 1; i < count; ++i) { + cmds[i] = VG_LINE_TO_ABS; + coords[2*i + 0] = points[2*i + 0]; + coords[2*i + 1] = points[2*i + 1]; + } + + if (closed) { + cmds[i] = VG_CLOSE_PATH; + ++i; + } + + vgu_append_float_coords(path, cmds, i, coords, 2*i); + + free(cmds); + free(coords); + + return VGU_NO_ERROR; +} + +VGUErrorCode vguRect(VGPath path, + VGfloat x, VGfloat y, + VGfloat width, VGfloat height) +{ + static const VGubyte cmds[] = {VG_MOVE_TO_ABS, + VG_HLINE_TO_REL, + VG_VLINE_TO_REL, + VG_HLINE_TO_REL, + VG_CLOSE_PATH + }; + VGfloat coords[5]; + VGbitfield caps; + + if (path == VG_INVALID_HANDLE) { + return VGU_BAD_HANDLE_ERROR; + } + caps = vgGetPathCapabilities(path); + if (!(caps & VG_PATH_CAPABILITY_APPEND_TO)) { + return VGU_PATH_CAPABILITY_ERROR; + } + if (width <= 0 || height <= 0) { + return VGU_ILLEGAL_ARGUMENT_ERROR; + } + + coords[0] = x; + coords[1] = y; + coords[2] = width; + coords[3] = height; + coords[4] = -width; + + vgu_append_float_coords(path, cmds, 5, coords, 5); + + return VGU_NO_ERROR; +} + +VGUErrorCode vguRoundRect(VGPath path, + VGfloat x, VGfloat y, + VGfloat width, + VGfloat height, + VGfloat arcWidth, + VGfloat arcHeight) +{ + static const VGubyte cmds[] = {VG_MOVE_TO_ABS, + VG_HLINE_TO_REL, + VG_SCCWARC_TO_REL, + VG_VLINE_TO_REL, + VG_SCCWARC_TO_REL, + VG_HLINE_TO_REL, + VG_SCCWARC_TO_REL, + VG_VLINE_TO_REL, + VG_SCCWARC_TO_REL, + VG_CLOSE_PATH + }; + VGfloat c[26]; + VGbitfield caps; + + if (path == VG_INVALID_HANDLE) { + return VGU_BAD_HANDLE_ERROR; + } + caps = vgGetPathCapabilities(path); + if (!(caps & VG_PATH_CAPABILITY_APPEND_TO)) { + return VGU_PATH_CAPABILITY_ERROR; + } + if (width <= 0 || height <= 0) { + return VGU_ILLEGAL_ARGUMENT_ERROR; + } + + c[0] = x + arcWidth/2; c[1] = y; + + c[2] = width - arcWidth; + + c[3] = arcWidth/2; c[4] = arcHeight/2; c[5] = 0; + c[6] = arcWidth/2; c[7] = arcHeight/2; + + c[8] = height - arcHeight; + + c[9] = arcWidth/2; c[10] = arcHeight/2; c[11] = 0; + c[12] = -arcWidth/2; c[13] = arcHeight/2; + + c[14] = -(width - arcWidth); + + c[15] = arcWidth/2; c[16] = arcHeight/2; c[17] = 0; + c[18] = -arcWidth/2; c[19] = -arcHeight/2; + + c[20] = -(height - arcHeight); + + c[21] = arcWidth/2; c[22] = arcHeight/2; c[23] = 0; + c[24] = arcWidth/2; c[25] = -arcHeight/2; + + vgu_append_float_coords(path, cmds, 10, c, 26); + + return VGU_NO_ERROR; +} + +VGUErrorCode vguEllipse(VGPath path, + VGfloat cx, VGfloat cy, + VGfloat width, + VGfloat height) +{ + static const VGubyte cmds[] = {VG_MOVE_TO_ABS, + VG_SCCWARC_TO_REL, + VG_SCCWARC_TO_REL, + VG_CLOSE_PATH + }; + VGfloat coords[12]; + VGbitfield caps; + + if (path == VG_INVALID_HANDLE) { + return VGU_BAD_HANDLE_ERROR; + } + caps = vgGetPathCapabilities(path); + if (!(caps & VG_PATH_CAPABILITY_APPEND_TO)) { + return VGU_PATH_CAPABILITY_ERROR; + } + if (width <= 0 || height <= 0) { + return VGU_ILLEGAL_ARGUMENT_ERROR; + } + + coords[0] = cx + width/2; coords[1] = cy; + + coords[2] = width/2; coords[3] = height/2; coords[4] = 0; + coords[5] = -width; coords[6] = 0; + + coords[7] = width/2; coords[8] = height/2; coords[9] = 0; + coords[10] = width; coords[11] = 0; + + vgu_append_float_coords(path, cmds, 4, coords, 11); + + return VGU_NO_ERROR; +} + +VGUErrorCode vguArc(VGPath path, + VGfloat x, VGfloat y, + VGfloat width, VGfloat height, + VGfloat startAngle, + VGfloat angleExtent, + VGUArcType arcType) +{ + VGubyte cmds[11]; + VGfloat coords[40]; + VGbitfield caps; + VGfloat last = startAngle + angleExtent; + VGint i, c = 0; + + if (path == VG_INVALID_HANDLE) { + return VGU_BAD_HANDLE_ERROR; + } + caps = vgGetPathCapabilities(path); + if (!(caps & VG_PATH_CAPABILITY_APPEND_TO)) { + return VGU_PATH_CAPABILITY_ERROR; + } + if (width <= 0 || height <= 0) { + return VGU_ILLEGAL_ARGUMENT_ERROR; + } + if (arcType != VGU_ARC_OPEN && + arcType != VGU_ARC_CHORD && + arcType != VGU_ARC_PIE) { + return VGU_ILLEGAL_ARGUMENT_ERROR; + } + + cmds[c] = VG_MOVE_TO_ABS; ++c; + coords[0] = x+cos(DEGREES_TO_RADIANS(startAngle))*width/2; + coords[1] = y+sin(DEGREES_TO_RADIANS(startAngle))*height/2; +#ifdef DEBUG_VGUARC + debug_printf("start [%f, %f]\n", coords[0], coords[1]); +#endif + i = 2; + if (angleExtent > 0) { + VGfloat angle = startAngle + 180; + while (angle < last) { + cmds[c] = VG_SCCWARC_TO_ABS; ++c; + coords[i] = width/2; coords[i+1] = height/2; coords[i+2] = 0; + coords[i+3] = x + cos(DEGREES_TO_RADIANS(angle))*width/2; + coords[i+4] = y + sin(DEGREES_TO_RADIANS(angle))*height/2; +#ifdef DEBUG_VGUARC + debug_printf("1 [%f, %f]\n", coords[i+3], + coords[i+4]); +#endif + i += 5; + angle += 180; + } + cmds[c] = VG_SCCWARC_TO_ABS; ++c; + coords[i] = width/2; coords[i+1] = height/2; coords[i+2] = 0; + coords[i+3] = x+cos(DEGREES_TO_RADIANS(last))*width/2; + coords[i+4] = y+sin(DEGREES_TO_RADIANS(last))*height/2; +#ifdef DEBUG_VGUARC + debug_printf("2 [%f, %f]\n", coords[i+3], + coords[i+4]); +#endif + i += 5; + } else { + VGfloat angle = startAngle - 180; + while (angle > last) { + cmds[c] = VG_SCWARC_TO_ABS; ++c; + coords[i] = width/2; coords[i+1] = height/2; coords[i+2] = 0; + coords[i+3] = x + cos(DEGREES_TO_RADIANS(angle)) * width/2; + coords[i+4] = y + sin(DEGREES_TO_RADIANS(angle)) * height/2; +#ifdef DEBUG_VGUARC + debug_printf("3 [%f, %f]\n", coords[i+3], + coords[i+4]); +#endif + angle -= 180; + i += 5; + } + cmds[c] = VG_SCWARC_TO_ABS; ++c; + coords[i] = width/2; coords[i+1] = height/2; coords[i+2] = 0; + coords[i+3] = x + cos(DEGREES_TO_RADIANS(last)) * width/2; + coords[i+4] = y + sin(DEGREES_TO_RADIANS(last)) * height/2; +#ifdef DEBUG_VGUARC + debug_printf("4 [%f, %f]\n", coords[i+3], + coords[i+4]); +#endif + i += 5; + } + + if (arcType == VGU_ARC_PIE) { + cmds[c] = VG_LINE_TO_ABS; ++c; + coords[i] = x; coords[i + 1] = y; + i += 2; + } + if (arcType == VGU_ARC_PIE || arcType == VGU_ARC_CHORD) { + cmds[c] = VG_CLOSE_PATH; + ++c; + } + + assert(c < 11); + + vgu_append_float_coords(path, cmds, c, coords, i); + + return VGU_NO_ERROR; +} + +VGUErrorCode vguComputeWarpQuadToSquare(VGfloat sx0, VGfloat sy0, + VGfloat sx1, VGfloat sy1, + VGfloat sx2, VGfloat sy2, + VGfloat sx3, VGfloat sy3, + VGfloat * matrix) +{ + struct matrix mat; + + if (!matrix || !is_aligned(matrix)) + return VGU_ILLEGAL_ARGUMENT_ERROR; + + if (!matrix_quad_to_square(sx0, sy0, + sx1, sy1, + sx2, sy2, + sx3, sy3, + &mat)) + return VGU_BAD_WARP_ERROR; + + if (!matrix_is_invertible(&mat)) + return VGU_BAD_WARP_ERROR; + + memcpy(matrix, mat.m, sizeof(VGfloat) * 9); + + return VGU_NO_ERROR; +} + +VGUErrorCode vguComputeWarpSquareToQuad(VGfloat dx0, VGfloat dy0, + VGfloat dx1, VGfloat dy1, + VGfloat dx2, VGfloat dy2, + VGfloat dx3, VGfloat dy3, + VGfloat * matrix) +{ + struct matrix mat; + + if (!matrix || !is_aligned(matrix)) + return VGU_ILLEGAL_ARGUMENT_ERROR; + + if (!matrix_square_to_quad(dx0, dy0, + dx1, dy1, + dx2, dy2, + dx3, dy3, + &mat)) + return VGU_BAD_WARP_ERROR; + + if (!matrix_is_invertible(&mat)) + return VGU_BAD_WARP_ERROR; + + memcpy(matrix, mat.m, sizeof(VGfloat) * 9); + + return VGU_NO_ERROR; +} + +VGUErrorCode vguComputeWarpQuadToQuad(VGfloat dx0, VGfloat dy0, + VGfloat dx1, VGfloat dy1, + VGfloat dx2, VGfloat dy2, + VGfloat dx3, VGfloat dy3, + VGfloat sx0, VGfloat sy0, + VGfloat sx1, VGfloat sy1, + VGfloat sx2, VGfloat sy2, + VGfloat sx3, VGfloat sy3, + VGfloat * matrix) +{ + struct matrix mat; + + if (!matrix || !is_aligned(matrix)) + return VGU_ILLEGAL_ARGUMENT_ERROR; + + if (!matrix_quad_to_quad(dx0, dy0, + dx1, dy1, + dx2, dy2, + dx3, dy3, + sx0, sy0, + sx1, sy1, + sx2, sy2, + sx3, sy3, + &mat)) + return VGU_BAD_WARP_ERROR; + + memcpy(matrix, mat.m, sizeof(VGfloat) * 9); + + return VGU_NO_ERROR; +} diff --git a/src/gallium/state_trackers/wgl/SConscript b/src/gallium/state_trackers/wgl/SConscript new file mode 100644 index 0000000..1b7597d --- /dev/null +++ b/src/gallium/state_trackers/wgl/SConscript @@ -0,0 +1,39 @@ +import os + +Import('*') + +env = env.Clone() + +env.Append(CPPPATH = [ + '#src/mapi', + '#src/mesa', + '.', +]) + +env.AppendUnique(CPPDEFINES = [ + '_GDI32_', # prevent wgl* being declared __declspec(dllimport) + 'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers + 'WIN32_LEAN_AND_MEAN', # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx +]) + +sources = [ + 'stw_context.c', + 'stw_device.c', + 'stw_ext_extensionsstring.c', + 'stw_ext_gallium.c', + 'stw_ext_pbuffer.c', + 'stw_ext_pixelformat.c', + 'stw_ext_swapinterval.c', + 'stw_framebuffer.c', + 'stw_getprocaddress.c', + 'stw_pixelformat.c', + 'stw_st.c', + 'stw_tls.c', + 'stw_wgl.c', +] + +wgl = env.ConvenienceLibrary( + target ='wgl', + source = sources, +) +Export('wgl') diff --git a/src/gallium/state_trackers/wgl/stw_context.c b/src/gallium/state_trackers/wgl/stw_context.c new file mode 100644 index 0000000..cd4f3c8 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_context.c @@ -0,0 +1,732 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include + +#include "pipe/p_compiler.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "util/u_memory.h" +#include "state_tracker/st_api.h" + +#include "stw_icd.h" +#include "stw_device.h" +#include "stw_winsys.h" +#include "stw_framebuffer.h" +#include "stw_pixelformat.h" +#include "stw_context.h" +#include "stw_tls.h" + + +static INLINE struct stw_context * +stw_current_context(void) +{ + struct st_context_iface *st; + + st = (stw_dev) ? stw_dev->stapi->get_current(stw_dev->stapi) : NULL; + + return (struct stw_context *) ((st) ? st->st_manager_private : NULL); +} + +BOOL APIENTRY +DrvCopyContext( + DHGLRC dhrcSource, + DHGLRC dhrcDest, + UINT fuMask ) +{ + struct stw_context *src; + struct stw_context *dst; + BOOL ret = FALSE; + + if (!stw_dev) + return FALSE; + + pipe_mutex_lock( stw_dev->ctx_mutex ); + + src = stw_lookup_context_locked( dhrcSource ); + dst = stw_lookup_context_locked( dhrcDest ); + + if (src && dst) { + /* FIXME */ + assert(0); + (void) src; + (void) dst; + (void) fuMask; + } + + pipe_mutex_unlock( stw_dev->ctx_mutex ); + + return ret; +} + +BOOL APIENTRY +DrvShareLists( + DHGLRC dhglrc1, + DHGLRC dhglrc2 ) +{ + struct stw_context *ctx1; + struct stw_context *ctx2; + BOOL ret = FALSE; + + if (!stw_dev) + return FALSE; + + pipe_mutex_lock( stw_dev->ctx_mutex ); + + ctx1 = stw_lookup_context_locked( dhglrc1 ); + ctx2 = stw_lookup_context_locked( dhglrc2 ); + + if (ctx1 && ctx2 && ctx2->st->share) + ret = ctx2->st->share(ctx2->st, ctx1->st); + + pipe_mutex_unlock( stw_dev->ctx_mutex ); + + return ret; +} + +DHGLRC APIENTRY +DrvCreateContext( + HDC hdc ) +{ + return DrvCreateLayerContext( hdc, 0 ); +} + +DHGLRC APIENTRY +DrvCreateLayerContext( + HDC hdc, + INT iLayerPlane ) +{ + int iPixelFormat; + const struct stw_pixelformat_info *pfi; + struct st_context_attribs attribs; + struct stw_context *ctx = NULL; + + if(!stw_dev) + return 0; + + if (iLayerPlane != 0) + return 0; + + iPixelFormat = GetPixelFormat(hdc); + if(!iPixelFormat) + return 0; + + pfi = stw_pixelformat_get_info( iPixelFormat - 1 ); + + ctx = CALLOC_STRUCT( stw_context ); + if (ctx == NULL) + goto no_ctx; + + ctx->hdc = hdc; + ctx->iPixelFormat = iPixelFormat; + + memset(&attribs, 0, sizeof(attribs)); + attribs.profile = ST_PROFILE_DEFAULT; + attribs.visual = pfi->stvis; + + ctx->st = stw_dev->stapi->create_context(stw_dev->stapi, + stw_dev->smapi, &attribs, NULL); + if (ctx->st == NULL) + goto no_st_ctx; + + ctx->st->st_manager_private = (void *) ctx; + + pipe_mutex_lock( stw_dev->ctx_mutex ); + ctx->dhglrc = handle_table_add(stw_dev->ctx_table, ctx); + pipe_mutex_unlock( stw_dev->ctx_mutex ); + if (!ctx->dhglrc) + goto no_hglrc; + + return ctx->dhglrc; + +no_hglrc: + ctx->st->destroy(ctx->st); +no_st_ctx: + FREE(ctx); +no_ctx: + return 0; +} + +BOOL APIENTRY +DrvDeleteContext( + DHGLRC dhglrc ) +{ + struct stw_context *ctx ; + BOOL ret = FALSE; + + if (!stw_dev) + return FALSE; + + pipe_mutex_lock( stw_dev->ctx_mutex ); + ctx = stw_lookup_context_locked(dhglrc); + handle_table_remove(stw_dev->ctx_table, dhglrc); + pipe_mutex_unlock( stw_dev->ctx_mutex ); + + if (ctx) { + struct stw_context *curctx = stw_current_context(); + + /* Unbind current if deleting current context. */ + if (curctx == ctx) + stw_dev->stapi->make_current(stw_dev->stapi, NULL, NULL, NULL); + + ctx->st->destroy(ctx->st); + FREE(ctx); + + ret = TRUE; + } + + return ret; +} + +BOOL APIENTRY +DrvReleaseContext( + DHGLRC dhglrc ) +{ + struct stw_context *ctx; + + if (!stw_dev) + return FALSE; + + pipe_mutex_lock( stw_dev->ctx_mutex ); + ctx = stw_lookup_context_locked( dhglrc ); + pipe_mutex_unlock( stw_dev->ctx_mutex ); + + if (!ctx) + return FALSE; + + /* The expectation is that ctx is the same context which is + * current for this thread. We should check that and return False + * if not the case. + */ + if (ctx != stw_current_context()) + return FALSE; + + if (stw_make_current( NULL, 0 ) == FALSE) + return FALSE; + + return TRUE; +} + + +DHGLRC +stw_get_current_context( void ) +{ + struct stw_context *ctx; + + ctx = stw_current_context(); + if(!ctx) + return 0; + + return ctx->dhglrc; +} + +HDC +stw_get_current_dc( void ) +{ + struct stw_context *ctx; + + ctx = stw_current_context(); + if(!ctx) + return NULL; + + return ctx->hdc; +} + +BOOL +stw_make_current( + HDC hdc, + DHGLRC dhglrc ) +{ + struct stw_context *curctx = NULL; + struct stw_context *ctx = NULL; + struct stw_framebuffer *fb = NULL; + BOOL ret = FALSE; + + if (!stw_dev) + return FALSE; + + curctx = stw_current_context(); + if (curctx != NULL) { + if (curctx->dhglrc == dhglrc) { + if (curctx->hdc == hdc) { + /* Return if already current. */ + return TRUE; + } + } else { + curctx->st->flush(curctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + } + } + + if (dhglrc) { + pipe_mutex_lock( stw_dev->ctx_mutex ); + ctx = stw_lookup_context_locked( dhglrc ); + pipe_mutex_unlock( stw_dev->ctx_mutex ); + if (!ctx) { + goto fail; + } + + fb = stw_framebuffer_from_hdc( hdc ); + if (fb) { + stw_framebuffer_update(fb); + } + else { + /* Applications should call SetPixelFormat before creating a context, + * but not all do, and the opengl32 runtime seems to use a default pixel + * format in some cases, so we must create a framebuffer for those here + */ + int iPixelFormat = GetPixelFormat(hdc); + if (iPixelFormat) + fb = stw_framebuffer_create( hdc, iPixelFormat ); + if (!fb) + goto fail; + } + + if (fb->iPixelFormat != ctx->iPixelFormat) { + SetLastError(ERROR_INVALID_PIXEL_FORMAT); + goto fail; + } + + /* Bind the new framebuffer */ + ctx->hdc = hdc; + + ret = stw_dev->stapi->make_current(stw_dev->stapi, ctx->st, fb->stfb, fb->stfb); + stw_framebuffer_reference(&ctx->current_framebuffer, fb); + } else { + ret = stw_dev->stapi->make_current(stw_dev->stapi, NULL, NULL, NULL); + } + +fail: + + if (fb) { + stw_framebuffer_release(fb); + } + + /* On failure, make the thread's current rendering context not current + * before returning */ + if (!ret) { + stw_dev->stapi->make_current(stw_dev->stapi, NULL, NULL, NULL); + ctx = NULL; + } + + /* Unreference the previous framebuffer if any. It must be done after + * make_current, as it can be referenced inside. + */ + if (curctx && curctx != ctx) { + stw_framebuffer_reference(&curctx->current_framebuffer, NULL); + } + + return ret; +} + +/** + * Flush the current context if it is bound to the framebuffer. + */ +void +stw_flush_current_locked( struct stw_framebuffer *fb ) +{ + struct stw_context *ctx = stw_current_context(); + + if (ctx && ctx->current_framebuffer == fb) { + ctx->st->flush(ctx->st, + PIPE_FLUSH_RENDER_CACHE | + PIPE_FLUSH_SWAPBUFFERS | + PIPE_FLUSH_FRAME, + NULL); + } +} + +/** + * Notify the current context that the framebuffer has become invalid. + */ +void +stw_notify_current_locked( struct stw_framebuffer *fb ) +{ + struct stw_context *ctx = stw_current_context(); + + if (ctx && ctx->current_framebuffer == fb) + ctx->st->notify_invalid_framebuffer(ctx->st, fb->stfb); +} + +/** + * Although WGL allows different dispatch entrypoints per context + */ +static const GLCLTPROCTABLE cpt = +{ + OPENGL_VERSION_110_ENTRIES, + { + &glNewList, + &glEndList, + &glCallList, + &glCallLists, + &glDeleteLists, + &glGenLists, + &glListBase, + &glBegin, + &glBitmap, + &glColor3b, + &glColor3bv, + &glColor3d, + &glColor3dv, + &glColor3f, + &glColor3fv, + &glColor3i, + &glColor3iv, + &glColor3s, + &glColor3sv, + &glColor3ub, + &glColor3ubv, + &glColor3ui, + &glColor3uiv, + &glColor3us, + &glColor3usv, + &glColor4b, + &glColor4bv, + &glColor4d, + &glColor4dv, + &glColor4f, + &glColor4fv, + &glColor4i, + &glColor4iv, + &glColor4s, + &glColor4sv, + &glColor4ub, + &glColor4ubv, + &glColor4ui, + &glColor4uiv, + &glColor4us, + &glColor4usv, + &glEdgeFlag, + &glEdgeFlagv, + &glEnd, + &glIndexd, + &glIndexdv, + &glIndexf, + &glIndexfv, + &glIndexi, + &glIndexiv, + &glIndexs, + &glIndexsv, + &glNormal3b, + &glNormal3bv, + &glNormal3d, + &glNormal3dv, + &glNormal3f, + &glNormal3fv, + &glNormal3i, + &glNormal3iv, + &glNormal3s, + &glNormal3sv, + &glRasterPos2d, + &glRasterPos2dv, + &glRasterPos2f, + &glRasterPos2fv, + &glRasterPos2i, + &glRasterPos2iv, + &glRasterPos2s, + &glRasterPos2sv, + &glRasterPos3d, + &glRasterPos3dv, + &glRasterPos3f, + &glRasterPos3fv, + &glRasterPos3i, + &glRasterPos3iv, + &glRasterPos3s, + &glRasterPos3sv, + &glRasterPos4d, + &glRasterPos4dv, + &glRasterPos4f, + &glRasterPos4fv, + &glRasterPos4i, + &glRasterPos4iv, + &glRasterPos4s, + &glRasterPos4sv, + &glRectd, + &glRectdv, + &glRectf, + &glRectfv, + &glRecti, + &glRectiv, + &glRects, + &glRectsv, + &glTexCoord1d, + &glTexCoord1dv, + &glTexCoord1f, + &glTexCoord1fv, + &glTexCoord1i, + &glTexCoord1iv, + &glTexCoord1s, + &glTexCoord1sv, + &glTexCoord2d, + &glTexCoord2dv, + &glTexCoord2f, + &glTexCoord2fv, + &glTexCoord2i, + &glTexCoord2iv, + &glTexCoord2s, + &glTexCoord2sv, + &glTexCoord3d, + &glTexCoord3dv, + &glTexCoord3f, + &glTexCoord3fv, + &glTexCoord3i, + &glTexCoord3iv, + &glTexCoord3s, + &glTexCoord3sv, + &glTexCoord4d, + &glTexCoord4dv, + &glTexCoord4f, + &glTexCoord4fv, + &glTexCoord4i, + &glTexCoord4iv, + &glTexCoord4s, + &glTexCoord4sv, + &glVertex2d, + &glVertex2dv, + &glVertex2f, + &glVertex2fv, + &glVertex2i, + &glVertex2iv, + &glVertex2s, + &glVertex2sv, + &glVertex3d, + &glVertex3dv, + &glVertex3f, + &glVertex3fv, + &glVertex3i, + &glVertex3iv, + &glVertex3s, + &glVertex3sv, + &glVertex4d, + &glVertex4dv, + &glVertex4f, + &glVertex4fv, + &glVertex4i, + &glVertex4iv, + &glVertex4s, + &glVertex4sv, + &glClipPlane, + &glColorMaterial, + &glCullFace, + &glFogf, + &glFogfv, + &glFogi, + &glFogiv, + &glFrontFace, + &glHint, + &glLightf, + &glLightfv, + &glLighti, + &glLightiv, + &glLightModelf, + &glLightModelfv, + &glLightModeli, + &glLightModeliv, + &glLineStipple, + &glLineWidth, + &glMaterialf, + &glMaterialfv, + &glMateriali, + &glMaterialiv, + &glPointSize, + &glPolygonMode, + &glPolygonStipple, + &glScissor, + &glShadeModel, + &glTexParameterf, + &glTexParameterfv, + &glTexParameteri, + &glTexParameteriv, + &glTexImage1D, + &glTexImage2D, + &glTexEnvf, + &glTexEnvfv, + &glTexEnvi, + &glTexEnviv, + &glTexGend, + &glTexGendv, + &glTexGenf, + &glTexGenfv, + &glTexGeni, + &glTexGeniv, + &glFeedbackBuffer, + &glSelectBuffer, + &glRenderMode, + &glInitNames, + &glLoadName, + &glPassThrough, + &glPopName, + &glPushName, + &glDrawBuffer, + &glClear, + &glClearAccum, + &glClearIndex, + &glClearColor, + &glClearStencil, + &glClearDepth, + &glStencilMask, + &glColorMask, + &glDepthMask, + &glIndexMask, + &glAccum, + &glDisable, + &glEnable, + &glFinish, + &glFlush, + &glPopAttrib, + &glPushAttrib, + &glMap1d, + &glMap1f, + &glMap2d, + &glMap2f, + &glMapGrid1d, + &glMapGrid1f, + &glMapGrid2d, + &glMapGrid2f, + &glEvalCoord1d, + &glEvalCoord1dv, + &glEvalCoord1f, + &glEvalCoord1fv, + &glEvalCoord2d, + &glEvalCoord2dv, + &glEvalCoord2f, + &glEvalCoord2fv, + &glEvalMesh1, + &glEvalPoint1, + &glEvalMesh2, + &glEvalPoint2, + &glAlphaFunc, + &glBlendFunc, + &glLogicOp, + &glStencilFunc, + &glStencilOp, + &glDepthFunc, + &glPixelZoom, + &glPixelTransferf, + &glPixelTransferi, + &glPixelStoref, + &glPixelStorei, + &glPixelMapfv, + &glPixelMapuiv, + &glPixelMapusv, + &glReadBuffer, + &glCopyPixels, + &glReadPixels, + &glDrawPixels, + &glGetBooleanv, + &glGetClipPlane, + &glGetDoublev, + &glGetError, + &glGetFloatv, + &glGetIntegerv, + &glGetLightfv, + &glGetLightiv, + &glGetMapdv, + &glGetMapfv, + &glGetMapiv, + &glGetMaterialfv, + &glGetMaterialiv, + &glGetPixelMapfv, + &glGetPixelMapuiv, + &glGetPixelMapusv, + &glGetPolygonStipple, + &glGetString, + &glGetTexEnvfv, + &glGetTexEnviv, + &glGetTexGendv, + &glGetTexGenfv, + &glGetTexGeniv, + &glGetTexImage, + &glGetTexParameterfv, + &glGetTexParameteriv, + &glGetTexLevelParameterfv, + &glGetTexLevelParameteriv, + &glIsEnabled, + &glIsList, + &glDepthRange, + &glFrustum, + &glLoadIdentity, + &glLoadMatrixf, + &glLoadMatrixd, + &glMatrixMode, + &glMultMatrixf, + &glMultMatrixd, + &glOrtho, + &glPopMatrix, + &glPushMatrix, + &glRotated, + &glRotatef, + &glScaled, + &glScalef, + &glTranslated, + &glTranslatef, + &glViewport, + &glArrayElement, + &glBindTexture, + &glColorPointer, + &glDisableClientState, + &glDrawArrays, + &glDrawElements, + &glEdgeFlagPointer, + &glEnableClientState, + &glIndexPointer, + &glIndexub, + &glIndexubv, + &glInterleavedArrays, + &glNormalPointer, + &glPolygonOffset, + &glTexCoordPointer, + &glVertexPointer, + &glAreTexturesResident, + &glCopyTexImage1D, + &glCopyTexImage2D, + &glCopyTexSubImage1D, + &glCopyTexSubImage2D, + &glDeleteTextures, + &glGenTextures, + &glGetPointerv, + &glIsTexture, + &glPrioritizeTextures, + &glTexSubImage1D, + &glTexSubImage2D, + &glPopClientAttrib, + &glPushClientAttrib + } +}; + +PGLCLTPROCTABLE APIENTRY +DrvSetContext( + HDC hdc, + DHGLRC dhglrc, + PFN_SETPROCTABLE pfnSetProcTable ) +{ + PGLCLTPROCTABLE r = (PGLCLTPROCTABLE)&cpt; + + if (!stw_make_current( hdc, dhglrc )) + r = NULL; + + return r; +} diff --git a/src/gallium/state_trackers/wgl/stw_context.h b/src/gallium/state_trackers/wgl/stw_context.h new file mode 100644 index 0000000..0bbed84 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_context.h @@ -0,0 +1,55 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef STW_CONTEXT_H +#define STW_CONTEXT_H + +#include + +struct stw_framebuffer; +struct st_context_iface; + +struct stw_context +{ + struct st_context_iface *st; + DHGLRC dhglrc; + int iPixelFormat; + HDC hdc; + + struct stw_framebuffer *current_framebuffer; +}; + +DHGLRC stw_get_current_context( void ); + +HDC stw_get_current_dc( void ); + +BOOL stw_make_current( HDC hdc, DHGLRC dhglrc ); + +void stw_flush_current_locked( struct stw_framebuffer *fb ); +void stw_notify_current_locked( struct stw_framebuffer *fb ); + +#endif /* STW_CONTEXT_H */ diff --git a/src/gallium/state_trackers/wgl/stw_device.c b/src/gallium/state_trackers/wgl/stw_device.c new file mode 100644 index 0000000..c4822d4 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_device.c @@ -0,0 +1,221 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include + +#include "glapi/glapi.h" +#include "util/u_debug.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "pipe/p_screen.h" + +#include "stw_device.h" +#include "stw_winsys.h" +#include "stw_pixelformat.h" +#include "stw_icd.h" +#include "stw_tls.h" +#include "stw_framebuffer.h" +#include "stw_st.h" + +extern _glthread_Mutex OneTimeLock; + + +struct stw_device *stw_dev = NULL; + +static int +stw_get_param(struct st_manager *smapi, + enum st_manager_param param) +{ + return 0; +} + +boolean +stw_init(const struct stw_winsys *stw_winsys) +{ + static struct stw_device stw_dev_storage; + struct pipe_screen *screen; + + debug_printf("%s\n", __FUNCTION__); + + assert(!stw_dev); + + stw_tls_init(); + + stw_dev = &stw_dev_storage; + memset(stw_dev, 0, sizeof(*stw_dev)); + +#ifdef DEBUG + stw_dev->memdbg_no = debug_memory_begin(); +#endif + + stw_dev->stw_winsys = stw_winsys; + + _glthread_INIT_MUTEX(OneTimeLock); + + stw_dev->stapi = stw_st_create_api(); + stw_dev->smapi = CALLOC_STRUCT(st_manager); + if (!stw_dev->stapi || !stw_dev->smapi) + goto error1; + + screen = stw_winsys->create_screen(); + if(!screen) + goto error1; + + if(stw_winsys->get_adapter_luid) + stw_winsys->get_adapter_luid(screen, &stw_dev->AdapterLuid); + + stw_dev->smapi->screen = screen; + stw_dev->smapi->get_param = stw_get_param; + stw_dev->screen = screen; + + stw_dev->max_2d_levels = + screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS); + stw_dev->max_2d_length = 1 << (stw_dev->max_2d_levels - 1); + + pipe_mutex_init( stw_dev->ctx_mutex ); + pipe_mutex_init( stw_dev->fb_mutex ); + + stw_dev->ctx_table = handle_table_create(); + if (!stw_dev->ctx_table) { + goto error1; + } + + stw_pixelformat_init(); + + return TRUE; + +error1: + if (stw_dev->smapi) + FREE(stw_dev->smapi); + if (stw_dev->stapi) + stw_dev->stapi->destroy(stw_dev->stapi); + + stw_dev = NULL; + return FALSE; +} + + +boolean +stw_init_thread(void) +{ + return stw_tls_init_thread(); +} + + +void +stw_cleanup_thread(void) +{ + stw_tls_cleanup_thread(); +} + + +void +stw_cleanup(void) +{ + DHGLRC dhglrc; + + debug_printf("%s\n", __FUNCTION__); + + if (!stw_dev) + return; + + /* + * Abort cleanup if there are still active contexts. In some situations + * this DLL may be unloaded before the DLL that is using GL contexts is. + */ + pipe_mutex_lock( stw_dev->ctx_mutex ); + dhglrc = handle_table_get_first_handle(stw_dev->ctx_table); + pipe_mutex_unlock( stw_dev->ctx_mutex ); + if (dhglrc) { + debug_printf("%s: contexts still active -- cleanup aborted\n", __FUNCTION__); + stw_dev = NULL; + return; + } + + handle_table_destroy(stw_dev->ctx_table); + + stw_framebuffer_cleanup(); + + pipe_mutex_destroy( stw_dev->fb_mutex ); + pipe_mutex_destroy( stw_dev->ctx_mutex ); + + FREE(stw_dev->smapi); + stw_dev->stapi->destroy(stw_dev->stapi); + + stw_dev->screen->destroy(stw_dev->screen); + + _glthread_DESTROY_MUTEX(OneTimeLock); + + _glapi_destroy_multithread(); + +#ifdef DEBUG + debug_memory_end(stw_dev->memdbg_no); +#endif + + stw_tls_cleanup(); + + stw_dev = NULL; +} + + +struct stw_context * +stw_lookup_context_locked( DHGLRC dhglrc ) +{ + if (dhglrc == 0) + return NULL; + + if (stw_dev == NULL) + return NULL; + + return (struct stw_context *) handle_table_get(stw_dev->ctx_table, dhglrc); +} + + +void APIENTRY +DrvSetCallbackProcs( + INT nProcs, + PROC *pProcs ) +{ + size_t size; + + if (stw_dev == NULL) + return; + + size = MIN2(nProcs * sizeof *pProcs, sizeof stw_dev->callbacks); + memcpy(&stw_dev->callbacks, pProcs, size); + + return; +} + + +BOOL APIENTRY +DrvValidateVersion( + ULONG ulVersion ) +{ + /* TODO: get the expected version from the winsys */ + return ulVersion == 1; +} diff --git a/src/gallium/state_trackers/wgl/stw_device.h b/src/gallium/state_trackers/wgl/stw_device.h new file mode 100644 index 0000000..3c2b6d9 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_device.h @@ -0,0 +1,85 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef STW_DEVICE_H_ +#define STW_DEVICE_H_ + + +#include "pipe/p_compiler.h" +#include "os/os_thread.h" +#include "util/u_handle_table.h" +#include "stw_icd.h" +#include "stw_pixelformat.h" + + +#define STW_MAX_PIXELFORMATS 256 + + +struct pipe_screen; +struct st_api; +struct st_manager; +struct stw_framebuffer; + +struct stw_device +{ + const struct stw_winsys *stw_winsys; + + struct pipe_screen *screen; + + /* Cache some PIPE_CAP_* */ + unsigned max_2d_levels; + unsigned max_2d_length; + + struct st_api *stapi; + struct st_manager *smapi; + + LUID AdapterLuid; + + struct stw_pixelformat_info pixelformats[STW_MAX_PIXELFORMATS]; + unsigned pixelformat_count; + unsigned pixelformat_extended_count; + + GLCALLBACKTABLE callbacks; + + pipe_mutex ctx_mutex; + struct handle_table *ctx_table; + + pipe_mutex fb_mutex; + struct stw_framebuffer *fb_head; + +#ifdef DEBUG + unsigned long memdbg_no; +#endif +}; + +struct stw_context * +stw_lookup_context_locked( DHGLRC hglrc ); + +extern struct stw_device *stw_dev; + + +#endif /* STW_DEVICE_H_ */ diff --git a/src/gallium/state_trackers/wgl/stw_ext_extensionsstring.c b/src/gallium/state_trackers/wgl/stw_ext_extensionsstring.c new file mode 100644 index 0000000..ecb326f --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_ext_extensionsstring.c @@ -0,0 +1,60 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * 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. + * + **************************************************************************/ + +#include + +#define WGL_WGLEXT_PROTOTYPES + +#include +#include + + +static const char *stw_extension_string = + "WGL_ARB_extensions_string " + "WGL_ARB_multisample " + "WGL_ARB_pbuffer " + "WGL_ARB_pixel_format " +/* "WGL_EXT_swap_interval " */ + "WGL_EXT_extensions_string"; + + +WINGDIAPI const char * APIENTRY +wglGetExtensionsStringARB( + HDC hdc ) +{ + (void) hdc; + + return stw_extension_string; +} + + +WINGDIAPI const char * APIENTRY +wglGetExtensionsStringEXT( void ) +{ + return stw_extension_string; +} diff --git a/src/gallium/state_trackers/wgl/stw_ext_gallium.c b/src/gallium/state_trackers/wgl/stw_ext_gallium.c new file mode 100644 index 0000000..5ecbd80 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_ext_gallium.c @@ -0,0 +1,50 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#include "pipe/p_screen.h" +#include "stw_device.h" +#include "stw_winsys.h" +#include "stw_ext_gallium.h" + + +struct pipe_screen * APIENTRY +wglGetGalliumScreenMESA(void) +{ + return stw_dev ? stw_dev->screen : NULL; +} + + +/* XXX: Unify with stw_create_layer_context */ +struct pipe_context * APIENTRY +wglCreateGalliumContextMESA(void) +{ + if(!stw_dev) + return NULL; + + return stw_dev->screen->context_create( stw_dev->screen, NULL ); +} diff --git a/src/gallium/state_trackers/wgl/stw_ext_gallium.h b/src/gallium/state_trackers/wgl/stw_ext_gallium.h new file mode 100644 index 0000000..cc35f2b --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_ext_gallium.h @@ -0,0 +1,47 @@ +/************************************************************************** + * + * 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 STW_EXTGALLIUM_H_ +#define STW_EXTGALLIUM_H_ + + +#include + + +struct pipe_screen; +struct pipe_context; + + +struct pipe_screen * APIENTRY +wglGetGalliumScreenMESA(void); + + +struct pipe_context * APIENTRY +wglCreateGalliumContextMESA(void); + + +#endif /* STW_EXTGALLIUM_H_ */ diff --git a/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c b/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c new file mode 100644 index 0000000..32636c6 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c @@ -0,0 +1,212 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include + +#define WGL_WGLEXT_PROTOTYPES + +#include +#include + +#include "pipe/p_defines.h" +#include "pipe/p_screen.h" + +#include "stw_device.h" +#include "stw_pixelformat.h" +#include "stw_framebuffer.h" + + +HPBUFFERARB WINAPI +wglCreatePbufferARB(HDC _hDC, + int iPixelFormat, + int iWidth, + int iHeight, + const int *piAttribList) +{ + static boolean first = TRUE; + const int *piAttrib; + int useLargest = 0; + const struct stw_pixelformat_info *info; + struct stw_framebuffer *fb; + HWND hWnd; + HDC hDC; + + info = stw_pixelformat_get_info(iPixelFormat); + if (!info) { + SetLastError(ERROR_INVALID_PIXEL_FORMAT); + return 0; + } + + if (iWidth <= 0 || iHeight <= 0) { + SetLastError(ERROR_INVALID_DATA); + return 0; + } + + for (piAttrib = piAttribList; *piAttrib; piAttrib++) { + switch (*piAttrib) { + case WGL_PBUFFER_LARGEST_ARB: + piAttrib++; + useLargest = *piAttrib; + break; + default: + SetLastError(ERROR_INVALID_DATA); + return 0; + } + } + + if (iWidth > stw_dev->max_2d_length) { + if (useLargest) { + iWidth = stw_dev->max_2d_length; + } else { + SetLastError(ERROR_NO_SYSTEM_RESOURCES); + return 0; + } + } + + if (iHeight > stw_dev->max_2d_length) { + if (useLargest) { + iHeight = stw_dev->max_2d_length; + } else { + SetLastError(ERROR_NO_SYSTEM_RESOURCES); + return 0; + } + } + + /* + * Implement pbuffers through invisible windows + */ + + if (first) { + WNDCLASS wc; + memset(&wc, 0, sizeof wc); + wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wc.lpfnWndProc = DefWindowProc; + wc.lpszClassName = "wglpbuffer"; + wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; + RegisterClass(&wc); + first = FALSE; + } + + hWnd = CreateWindowEx(0, + "wglpbuffer", /* wc.lpszClassName */ + "wglpbuffer", +#if 0 /* Useful for debugging what the application is drawing */ + WS_VISIBLE | +#endif + WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + CW_USEDEFAULT, CW_USEDEFAULT, /* x, y */ + iWidth, iHeight, + NULL, + NULL, + NULL, + NULL); + if (!hWnd) { + return 0; + } + + hDC = GetDC(hWnd); + if (!hDC) { + return 0; + } + + SetPixelFormat(hDC, iPixelFormat, &info->pfd); + + fb = stw_framebuffer_create(hDC, iPixelFormat); + if (!fb) { + SetLastError(ERROR_NO_SYSTEM_RESOURCES); + } + + return (HPBUFFERARB)fb; +} + + +HDC WINAPI +wglGetPbufferDCARB(HPBUFFERARB hPbuffer) +{ + struct stw_framebuffer *fb; + HDC hDC; + + fb = (struct stw_framebuffer *)hPbuffer; + + hDC = GetDC(fb->hWnd); + SetPixelFormat(hDC, fb->iPixelFormat, &fb->pfi->pfd); + + return hDC; +} + + +int WINAPI +wglReleasePbufferDCARB(HPBUFFERARB hPbuffer, + HDC hDC) +{ + struct stw_framebuffer *fb; + + fb = (struct stw_framebuffer *)hPbuffer; + + return ReleaseDC(fb->hWnd, hDC); +} + + +BOOL WINAPI +wglDestroyPbufferARB(HPBUFFERARB hPbuffer) +{ + struct stw_framebuffer *fb; + + fb = (struct stw_framebuffer *)hPbuffer; + + /* This will destroy all our data */ + return DestroyWindow(fb->hWnd); +} + + +BOOL WINAPI +wglQueryPbufferARB(HPBUFFERARB hPbuffer, + int iAttribute, + int *piValue) +{ + struct stw_framebuffer *fb; + + fb = (struct stw_framebuffer *)hPbuffer; + + switch (iAttribute) { + case WGL_PBUFFER_WIDTH_ARB: + *piValue = fb->width; + return TRUE; + case WGL_PBUFFER_HEIGHT_ARB: + *piValue = fb->width; + return TRUE; + case WGL_PBUFFER_LOST_ARB: + /* We assume that no content is ever lost due to display mode change */ + *piValue = FALSE; + return TRUE; + default: + SetLastError(ERROR_INVALID_DATA); + return FALSE; + } +} diff --git a/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c b/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c new file mode 100644 index 0000000..d0a9586 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c @@ -0,0 +1,500 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * + * WGL_ARB_pixel_format extension implementation. + * + * @sa http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt + */ + + +#include + +#define WGL_WGLEXT_PROTOTYPES + +#include +#include + +#include "pipe/p_compiler.h" +#include "util/u_memory.h" +#include "stw_device.h" +#include "stw_pixelformat.h" + + +static boolean +stw_query_attrib( + int iPixelFormat, + int iLayerPlane, + int attrib, + int *pvalue ) +{ + uint count; + uint index; + const struct stw_pixelformat_info *pfi; + + count = stw_pixelformat_get_extended_count(); + + if (attrib == WGL_NUMBER_PIXEL_FORMATS_ARB) { + *pvalue = (int) count; + return TRUE; + } + + index = (uint) iPixelFormat - 1; + if (index >= count) + return FALSE; + + pfi = stw_pixelformat_get_info( index ); + + switch (attrib) { + case WGL_DRAW_TO_WINDOW_ARB: + *pvalue = pfi->pfd.dwFlags & PFD_DRAW_TO_WINDOW ? TRUE : FALSE; + return TRUE; + + case WGL_DRAW_TO_BITMAP_ARB: + *pvalue = pfi->pfd.dwFlags & PFD_DRAW_TO_BITMAP ? TRUE : FALSE; + return TRUE; + + case WGL_NEED_PALETTE_ARB: + *pvalue = pfi->pfd.dwFlags & PFD_NEED_PALETTE ? TRUE : FALSE; + return TRUE; + + case WGL_NEED_SYSTEM_PALETTE_ARB: + *pvalue = pfi->pfd.dwFlags & PFD_NEED_SYSTEM_PALETTE ? TRUE : FALSE; + return TRUE; + + case WGL_SWAP_METHOD_ARB: + *pvalue = pfi->pfd.dwFlags & PFD_SWAP_COPY ? WGL_SWAP_COPY_ARB : WGL_SWAP_UNDEFINED_ARB; + return TRUE; + + case WGL_SWAP_LAYER_BUFFERS_ARB: + *pvalue = FALSE; + return TRUE; + + case WGL_NUMBER_OVERLAYS_ARB: + *pvalue = 0; + return TRUE; + + case WGL_NUMBER_UNDERLAYS_ARB: + *pvalue = 0; + return TRUE; + } + + if (iLayerPlane != 0) + return FALSE; + + switch (attrib) { + case WGL_ACCELERATION_ARB: + *pvalue = WGL_FULL_ACCELERATION_ARB; + break; + + case WGL_TRANSPARENT_ARB: + *pvalue = FALSE; + break; + + case WGL_TRANSPARENT_RED_VALUE_ARB: + case WGL_TRANSPARENT_GREEN_VALUE_ARB: + case WGL_TRANSPARENT_BLUE_VALUE_ARB: + case WGL_TRANSPARENT_ALPHA_VALUE_ARB: + case WGL_TRANSPARENT_INDEX_VALUE_ARB: + break; + + case WGL_SHARE_DEPTH_ARB: + case WGL_SHARE_STENCIL_ARB: + case WGL_SHARE_ACCUM_ARB: + *pvalue = TRUE; + break; + + case WGL_SUPPORT_GDI_ARB: + *pvalue = pfi->pfd.dwFlags & PFD_SUPPORT_GDI ? TRUE : FALSE; + break; + + case WGL_SUPPORT_OPENGL_ARB: + *pvalue = pfi->pfd.dwFlags & PFD_SUPPORT_OPENGL ? TRUE : FALSE; + break; + + case WGL_DOUBLE_BUFFER_ARB: + *pvalue = pfi->pfd.dwFlags & PFD_DOUBLEBUFFER ? TRUE : FALSE; + break; + + case WGL_STEREO_ARB: + *pvalue = pfi->pfd.dwFlags & PFD_STEREO ? TRUE : FALSE; + break; + + case WGL_PIXEL_TYPE_ARB: + switch (pfi->pfd.iPixelType) { + case PFD_TYPE_RGBA: + *pvalue = WGL_TYPE_RGBA_ARB; + break; + case PFD_TYPE_COLORINDEX: + *pvalue = WGL_TYPE_COLORINDEX_ARB; + break; + default: + return FALSE; + } + break; + + case WGL_COLOR_BITS_ARB: + *pvalue = pfi->pfd.cColorBits; + break; + + case WGL_RED_BITS_ARB: + *pvalue = pfi->pfd.cRedBits; + break; + + case WGL_RED_SHIFT_ARB: + *pvalue = pfi->pfd.cRedShift; + break; + + case WGL_GREEN_BITS_ARB: + *pvalue = pfi->pfd.cGreenBits; + break; + + case WGL_GREEN_SHIFT_ARB: + *pvalue = pfi->pfd.cGreenShift; + break; + + case WGL_BLUE_BITS_ARB: + *pvalue = pfi->pfd.cBlueBits; + break; + + case WGL_BLUE_SHIFT_ARB: + *pvalue = pfi->pfd.cBlueShift; + break; + + case WGL_ALPHA_BITS_ARB: + *pvalue = pfi->pfd.cAlphaBits; + break; + + case WGL_ALPHA_SHIFT_ARB: + *pvalue = pfi->pfd.cAlphaShift; + break; + + case WGL_ACCUM_BITS_ARB: + *pvalue = pfi->pfd.cAccumBits; + break; + + case WGL_ACCUM_RED_BITS_ARB: + *pvalue = pfi->pfd.cAccumRedBits; + break; + + case WGL_ACCUM_GREEN_BITS_ARB: + *pvalue = pfi->pfd.cAccumGreenBits; + break; + + case WGL_ACCUM_BLUE_BITS_ARB: + *pvalue = pfi->pfd.cAccumBlueBits; + break; + + case WGL_ACCUM_ALPHA_BITS_ARB: + *pvalue = pfi->pfd.cAccumAlphaBits; + break; + + case WGL_DEPTH_BITS_ARB: + *pvalue = pfi->pfd.cDepthBits; + break; + + case WGL_STENCIL_BITS_ARB: + *pvalue = pfi->pfd.cStencilBits; + break; + + case WGL_AUX_BUFFERS_ARB: + *pvalue = pfi->pfd.cAuxBuffers; + break; + + case WGL_SAMPLE_BUFFERS_ARB: + *pvalue = 1; + break; + + case WGL_SAMPLES_ARB: + *pvalue = pfi->stvis.samples; + break; + + + /* WGL_ARB_pbuffer */ + + case WGL_MAX_PBUFFER_WIDTH_ARB: + case WGL_MAX_PBUFFER_HEIGHT_ARB: + *pvalue = stw_dev->max_2d_length; + break; + + case WGL_MAX_PBUFFER_PIXELS_ARB: + *pvalue = stw_dev->max_2d_length * stw_dev->max_2d_length; + break; + + case WGL_DRAW_TO_PBUFFER_ARB: + *pvalue = 1; + break; + + + default: + return FALSE; + } + + return TRUE; +} + +struct attrib_match_info +{ + int attribute; + int weight; + BOOL exact; +}; + +static const struct attrib_match_info attrib_match[] = { + + /* WGL_ARB_pixel_format */ + { WGL_DRAW_TO_WINDOW_ARB, 0, TRUE }, + { WGL_DRAW_TO_BITMAP_ARB, 0, TRUE }, + { WGL_ACCELERATION_ARB, 0, TRUE }, + { WGL_NEED_PALETTE_ARB, 0, TRUE }, + { WGL_NEED_SYSTEM_PALETTE_ARB, 0, TRUE }, + { WGL_SWAP_LAYER_BUFFERS_ARB, 0, TRUE }, + { WGL_SWAP_METHOD_ARB, 0, TRUE }, + { WGL_NUMBER_OVERLAYS_ARB, 4, FALSE }, + { WGL_NUMBER_UNDERLAYS_ARB, 4, FALSE }, + /*{ WGL_SHARE_DEPTH_ARB, 0, TRUE },*/ /* no overlays -- ignore */ + /*{ WGL_SHARE_STENCIL_ARB, 0, TRUE },*/ /* no overlays -- ignore */ + /*{ WGL_SHARE_ACCUM_ARB, 0, TRUE },*/ /* no overlays -- ignore */ + { WGL_SUPPORT_GDI_ARB, 0, TRUE }, + { WGL_SUPPORT_OPENGL_ARB, 0, TRUE }, + { WGL_DOUBLE_BUFFER_ARB, 0, TRUE }, + { WGL_STEREO_ARB, 0, TRUE }, + { WGL_PIXEL_TYPE_ARB, 0, TRUE }, + { WGL_COLOR_BITS_ARB, 1, FALSE }, + { WGL_RED_BITS_ARB, 1, FALSE }, + { WGL_GREEN_BITS_ARB, 1, FALSE }, + { WGL_BLUE_BITS_ARB, 1, FALSE }, + { WGL_ALPHA_BITS_ARB, 1, FALSE }, + { WGL_ACCUM_BITS_ARB, 1, FALSE }, + { WGL_ACCUM_RED_BITS_ARB, 1, FALSE }, + { WGL_ACCUM_GREEN_BITS_ARB, 1, FALSE }, + { WGL_ACCUM_BLUE_BITS_ARB, 1, FALSE }, + { WGL_ACCUM_ALPHA_BITS_ARB, 1, FALSE }, + { WGL_DEPTH_BITS_ARB, 1, FALSE }, + { WGL_STENCIL_BITS_ARB, 1, FALSE }, + { WGL_AUX_BUFFERS_ARB, 2, FALSE }, + + /* WGL_ARB_multisample */ + { WGL_SAMPLE_BUFFERS_ARB, 2, FALSE }, + { WGL_SAMPLES_ARB, 2, FALSE } +}; + +struct stw_pixelformat_score +{ + int points; + uint index; +}; + +static BOOL +score_pixelformats( + struct stw_pixelformat_score *scores, + uint count, + int attribute, + int expected_value ) +{ + uint i; + const struct attrib_match_info *ami = NULL; + uint index; + + /* Find out if a given attribute should be considered for score calculation. + */ + for (i = 0; i < sizeof( attrib_match ) / sizeof( attrib_match[0] ); i++) { + if (attrib_match[i].attribute == attribute) { + ami = &attrib_match[i]; + break; + } + } + if (ami == NULL) + return TRUE; + + /* Iterate all pixelformats, query the requested attribute and calculate + * score points. + */ + for (index = 0; index < count; index++) { + int actual_value; + + if (!stw_query_attrib( index + 1, 0, attribute, &actual_value )) + return FALSE; + + if (ami->exact) { + /* For an exact match criteria, if the actual and expected values differ, + * the score is set to 0 points, effectively removing the pixelformat + * from a list of matching pixelformats. + */ + if (actual_value != expected_value) + scores[index].points = 0; + } + else { + /* For a minimum match criteria, if the actual value is smaller than the expected + * value, the pixelformat is rejected (score set to 0). However, if the actual + * value is bigger, the pixelformat is given a penalty to favour pixelformats that + * more closely match the expected values. + */ + if (actual_value < expected_value) + scores[index].points = 0; + else if (actual_value > expected_value) + scores[index].points -= (actual_value - expected_value) * ami->weight; + } + } + + return TRUE; +} + +WINGDIAPI BOOL APIENTRY +wglChoosePixelFormatARB( + HDC hdc, + const int *piAttribIList, + const FLOAT *pfAttribFList, + UINT nMaxFormats, + int *piFormats, + UINT *nNumFormats ) +{ + uint count; + struct stw_pixelformat_score *scores; + uint i; + + *nNumFormats = 0; + + /* Allocate and initialize pixelformat score table -- better matches + * have higher scores. Start with a high score and take out penalty + * points for a mismatch when the match does not have to be exact. + * Set a score to 0 if there is a mismatch for an exact match criteria. + */ + count = stw_pixelformat_get_extended_count(); + scores = (struct stw_pixelformat_score *) MALLOC( count * sizeof( struct stw_pixelformat_score ) ); + if (scores == NULL) + return FALSE; + for (i = 0; i < count; i++) { + scores[i].points = 0x7fffffff; + scores[i].index = i; + } + + /* Given the attribute list calculate a score for each pixelformat. + */ + if (piAttribIList != NULL) { + while (*piAttribIList != 0) { + if (!score_pixelformats( scores, count, piAttribIList[0], piAttribIList[1] )) { + FREE( scores ); + return FALSE; + } + piAttribIList += 2; + } + } + if (pfAttribFList != NULL) { + while (*pfAttribFList != 0) { + if (!score_pixelformats( scores, count, (int) pfAttribFList[0], (int) pfAttribFList[1] )) { + FREE( scores ); + return FALSE; + } + pfAttribFList += 2; + } + } + + /* Bubble-sort the resulting scores. Pixelformats with higher scores go first. + * TODO: Find out if there are any patent issues with it. + */ + if (count > 1) { + uint n = count; + boolean swapped; + + do { + swapped = FALSE; + for (i = 1; i < n; i++) { + if (scores[i - 1].points < scores[i].points) { + struct stw_pixelformat_score score = scores[i - 1]; + + scores[i - 1] = scores[i]; + scores[i] = score; + swapped = TRUE; + } + } + n--; + } + while (swapped); + } + + /* Return a list of pixelformats that are the best match. + * Reject pixelformats with non-positive scores. + */ + for (i = 0; i < count; i++) { + if (scores[i].points > 0) { + if (*nNumFormats < nMaxFormats) + piFormats[*nNumFormats] = scores[i].index + 1; + (*nNumFormats)++; + } + } + + FREE( scores ); + return TRUE; +} + +WINGDIAPI BOOL APIENTRY +wglGetPixelFormatAttribfvARB( + HDC hdc, + int iPixelFormat, + int iLayerPlane, + UINT nAttributes, + const int *piAttributes, + FLOAT *pfValues ) +{ + UINT i; + + (void) hdc; + + for (i = 0; i < nAttributes; i++) { + int value; + + if (!stw_query_attrib( iPixelFormat, iLayerPlane, piAttributes[i], &value )) + return FALSE; + pfValues[i] = (FLOAT) value; + } + + return TRUE; +} + +WINGDIAPI BOOL APIENTRY +wglGetPixelFormatAttribivARB( + HDC hdc, + int iPixelFormat, + int iLayerPlane, + UINT nAttributes, + const int *piAttributes, + int *piValues ) +{ + UINT i; + + (void) hdc; + + for (i = 0; i < nAttributes; i++) { + if (!stw_query_attrib( iPixelFormat, iLayerPlane, piAttributes[i], &piValues[i] )) + return FALSE; + } + + return TRUE; +} diff --git a/src/gallium/state_trackers/wgl/stw_ext_swapinterval.c b/src/gallium/state_trackers/wgl/stw_ext_swapinterval.c new file mode 100644 index 0000000..9eac6a1 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_ext_swapinterval.c @@ -0,0 +1,57 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * 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. + * + **************************************************************************/ + +#include + +#define WGL_WGLEXT_PROTOTYPES + +#include +#include +#include "util/u_debug.h" + +/* A dummy implementation of this extension. + * + * Required as some applications retrieve and call these functions + * regardless of the fact that we don't advertise the extension and + * further more the results of wglGetProcAddress are NULL. + */ +WINGDIAPI BOOL APIENTRY +wglSwapIntervalEXT(int interval) +{ + (void) interval; + debug_printf("%s: %d\n", __FUNCTION__, interval); + return TRUE; +} + +WINGDIAPI int APIENTRY +wglGetSwapIntervalEXT(void) +{ + return 0; +} + + diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.c b/src/gallium/state_trackers/wgl/stw_framebuffer.c new file mode 100644 index 0000000..733222a --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_framebuffer.c @@ -0,0 +1,592 @@ +/************************************************************************** + * + * 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, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include + +#include "pipe/p_format.h" +#include "pipe/p_screen.h" +#include "util/u_format.h" +#include "util/u_memory.h" +#include "state_tracker/st_api.h" + +#include "stw_icd.h" +#include "stw_framebuffer.h" +#include "stw_device.h" +#include "stw_winsys.h" +#include "stw_tls.h" +#include "stw_context.h" +#include "stw_st.h" + + +/** + * Search the framebuffer with the matching HWND while holding the + * stw_dev::fb_mutex global lock. + */ +static INLINE struct stw_framebuffer * +stw_framebuffer_from_hwnd_locked( + HWND hwnd ) +{ + struct stw_framebuffer *fb; + + for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next) + if (fb->hWnd == hwnd) { + pipe_mutex_lock(fb->mutex); + break; + } + + return fb; +} + + +/** + * Destroy this framebuffer. Both stw_dev::fb_mutex and stw_framebuffer::mutex + * must be held, by this order. If there are still references to the + * framebuffer, nothing will happen. + */ +static INLINE void +stw_framebuffer_destroy_locked( + struct stw_framebuffer *fb ) +{ + struct stw_framebuffer **link; + + /* check the reference count */ + fb->refcnt--; + if (fb->refcnt) { + pipe_mutex_unlock( fb->mutex ); + return; + } + + link = &stw_dev->fb_head; + while (*link != fb) + link = &(*link)->next; + assert(*link); + *link = fb->next; + fb->next = NULL; + + if(fb->shared_surface) + stw_dev->stw_winsys->shared_surface_close(stw_dev->screen, fb->shared_surface); + + stw_st_destroy_framebuffer_locked(fb->stfb); + + pipe_mutex_unlock( fb->mutex ); + + pipe_mutex_destroy( fb->mutex ); + + FREE( fb ); +} + + +void +stw_framebuffer_release( + struct stw_framebuffer *fb) +{ + assert(fb); + pipe_mutex_unlock( fb->mutex ); +} + + +static INLINE void +stw_framebuffer_get_size( struct stw_framebuffer *fb ) +{ + unsigned width, height; + RECT client_rect; + RECT window_rect; + POINT client_pos; + + assert(fb->hWnd); + + /* Get the client area size. */ + GetClientRect( fb->hWnd, &client_rect ); + assert(client_rect.left == 0); + assert(client_rect.top == 0); + width = client_rect.right - client_rect.left; + height = client_rect.bottom - client_rect.top; + + if(width < 1) + width = 1; + if(height < 1) + height = 1; + + if(width != fb->width || height != fb->height) { + fb->must_resize = TRUE; + fb->width = width; + fb->height = height; + } + + client_pos.x = 0; + client_pos.y = 0; + ClientToScreen(fb->hWnd, &client_pos); + + GetWindowRect(fb->hWnd, &window_rect); + + fb->client_rect.left = client_pos.x - window_rect.left; + fb->client_rect.top = client_pos.y - window_rect.top; + fb->client_rect.right = fb->client_rect.left + fb->width; + fb->client_rect.bottom = fb->client_rect.top + fb->height; + +#if 0 + debug_printf("\n"); + debug_printf("%s: client_position = (%i, %i)\n", + __FUNCTION__, client_pos.x, client_pos.y); + debug_printf("%s: window_rect = (%i, %i) - (%i, %i)\n", + __FUNCTION__, + window_rect.left, window_rect.top, + window_rect.right, window_rect.bottom); + debug_printf("%s: client_rect = (%i, %i) - (%i, %i)\n", + __FUNCTION__, + fb->client_rect.left, fb->client_rect.top, + fb->client_rect.right, fb->client_rect.bottom); +#endif +} + + +/** + * @sa http://msdn.microsoft.com/en-us/library/ms644975(VS.85).aspx + * @sa http://msdn.microsoft.com/en-us/library/ms644960(VS.85).aspx + */ +LRESULT CALLBACK +stw_call_window_proc( + int nCode, + WPARAM wParam, + LPARAM lParam ) +{ + struct stw_tls_data *tls_data; + PCWPSTRUCT pParams = (PCWPSTRUCT)lParam; + struct stw_framebuffer *fb; + + tls_data = stw_tls_get_data(); + if(!tls_data) + return 0; + + if (nCode < 0 || !stw_dev) + return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam); + + if (pParams->message == WM_WINDOWPOSCHANGED) { + /* We handle WM_WINDOWPOSCHANGED instead of WM_SIZE because according to + * http://blogs.msdn.com/oldnewthing/archive/2008/01/15/7113860.aspx + * WM_SIZE is generated from WM_WINDOWPOSCHANGED by DefWindowProc so it + * can be masked out by the application. */ + LPWINDOWPOS lpWindowPos = (LPWINDOWPOS)pParams->lParam; + if((lpWindowPos->flags & SWP_SHOWWINDOW) || + !(lpWindowPos->flags & SWP_NOMOVE) || + !(lpWindowPos->flags & SWP_NOSIZE)) { + fb = stw_framebuffer_from_hwnd( pParams->hwnd ); + if(fb) { + /* Size in WINDOWPOS includes the window frame, so get the size + * of the client area via GetClientRect. */ + stw_framebuffer_get_size(fb); + stw_framebuffer_release(fb); + } + } + } + else if (pParams->message == WM_DESTROY) { + pipe_mutex_lock( stw_dev->fb_mutex ); + fb = stw_framebuffer_from_hwnd_locked( pParams->hwnd ); + if(fb) + stw_framebuffer_destroy_locked(fb); + pipe_mutex_unlock( stw_dev->fb_mutex ); + } + + return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam); +} + + +struct stw_framebuffer * +stw_framebuffer_create( + HDC hdc, + int iPixelFormat ) +{ + HWND hWnd; + struct stw_framebuffer *fb; + const struct stw_pixelformat_info *pfi; + + /* We only support drawing to a window. */ + hWnd = WindowFromDC( hdc ); + if(!hWnd) + return NULL; + + fb = CALLOC_STRUCT( stw_framebuffer ); + if (fb == NULL) + return NULL; + + fb->hDC = hdc; + fb->hWnd = hWnd; + fb->iPixelFormat = iPixelFormat; + + fb->pfi = pfi = stw_pixelformat_get_info( iPixelFormat - 1 ); + fb->stfb = stw_st_create_framebuffer( fb ); + if (!fb->stfb) { + FREE( fb ); + return NULL; + } + + fb->refcnt = 1; + + stw_framebuffer_get_size(fb); + + pipe_mutex_init( fb->mutex ); + + /* This is the only case where we lock the stw_framebuffer::mutex before + * stw_dev::fb_mutex, since no other thread can know about this framebuffer + * and we must prevent any other thread from destroying it before we return. + */ + pipe_mutex_lock( fb->mutex ); + + pipe_mutex_lock( stw_dev->fb_mutex ); + fb->next = stw_dev->fb_head; + stw_dev->fb_head = fb; + pipe_mutex_unlock( stw_dev->fb_mutex ); + + return fb; +} + +/** + * Have ptr reference fb. The referenced framebuffer should be locked. + */ +void +stw_framebuffer_reference( + struct stw_framebuffer **ptr, + struct stw_framebuffer *fb) +{ + struct stw_framebuffer *old_fb = *ptr; + + if (old_fb == fb) + return; + + if (fb) + fb->refcnt++; + if (old_fb) { + pipe_mutex_lock(stw_dev->fb_mutex); + + pipe_mutex_lock(old_fb->mutex); + stw_framebuffer_destroy_locked(old_fb); + + pipe_mutex_unlock(stw_dev->fb_mutex); + } + + *ptr = fb; +} + + +/** + * Update the framebuffer's size if necessary. + */ +void +stw_framebuffer_update( + struct stw_framebuffer *fb) +{ + assert(fb->stfb); + assert(fb->height); + assert(fb->width); + + /* XXX: It would be nice to avoid checking the size again -- in theory + * stw_call_window_proc would have cought the resize and stored the right + * size already, but unfortunately threads created before the DllMain is + * called don't get a DLL_THREAD_ATTACH notification, and there is no way + * to know of their existing without using the not very portable PSAPI. + */ + stw_framebuffer_get_size(fb); +} + + +void +stw_framebuffer_cleanup( void ) +{ + struct stw_framebuffer *fb; + struct stw_framebuffer *next; + + if (!stw_dev) + return; + + pipe_mutex_lock( stw_dev->fb_mutex ); + + fb = stw_dev->fb_head; + while (fb) { + next = fb->next; + + pipe_mutex_lock(fb->mutex); + stw_framebuffer_destroy_locked(fb); + + fb = next; + } + stw_dev->fb_head = NULL; + + pipe_mutex_unlock( stw_dev->fb_mutex ); +} + + +/** + * Given an hdc, return the corresponding stw_framebuffer. + */ +static INLINE struct stw_framebuffer * +stw_framebuffer_from_hdc_locked( + HDC hdc ) +{ + HWND hwnd; + struct stw_framebuffer *fb; + + /* + * Some applications create and use several HDCs for the same window, so + * looking up the framebuffer by the HDC is not reliable. Use HWND whenever + * possible. + */ + hwnd = WindowFromDC(hdc); + if(hwnd) + return stw_framebuffer_from_hwnd_locked(hwnd); + + for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next) + if (fb->hDC == hdc) { + pipe_mutex_lock(fb->mutex); + break; + } + + return fb; +} + + +/** + * Given an hdc, return the corresponding stw_framebuffer. + */ +struct stw_framebuffer * +stw_framebuffer_from_hdc( + HDC hdc ) +{ + struct stw_framebuffer *fb; + + if (!stw_dev) + return NULL; + + pipe_mutex_lock( stw_dev->fb_mutex ); + fb = stw_framebuffer_from_hdc_locked(hdc); + pipe_mutex_unlock( stw_dev->fb_mutex ); + + return fb; +} + + +/** + * Given an hdc, return the corresponding stw_framebuffer. + */ +struct stw_framebuffer * +stw_framebuffer_from_hwnd( + HWND hwnd ) +{ + struct stw_framebuffer *fb; + + pipe_mutex_lock( stw_dev->fb_mutex ); + fb = stw_framebuffer_from_hwnd_locked(hwnd); + pipe_mutex_unlock( stw_dev->fb_mutex ); + + return fb; +} + + +BOOL APIENTRY +DrvSetPixelFormat( + HDC hdc, + LONG iPixelFormat ) +{ + uint count; + uint index; + struct stw_framebuffer *fb; + + if (!stw_dev) + return FALSE; + + index = (uint) iPixelFormat - 1; + count = stw_pixelformat_get_extended_count(); + if (index >= count) + return FALSE; + + fb = stw_framebuffer_from_hdc_locked(hdc); + if(fb) { + /* SetPixelFormat must be called only once */ + stw_framebuffer_release( fb ); + return FALSE; + } + + fb = stw_framebuffer_create(hdc, iPixelFormat); + if(!fb) { + return FALSE; + } + + stw_framebuffer_release( fb ); + + /* Some applications mistakenly use the undocumented wglSetPixelFormat + * function instead of SetPixelFormat, so we call SetPixelFormat here to + * avoid opengl32.dll's wglCreateContext to fail */ + if (GetPixelFormat(hdc) == 0) { + SetPixelFormat(hdc, iPixelFormat, NULL); + } + + return TRUE; +} + + +int +stw_pixelformat_get( + HDC hdc ) +{ + int iPixelFormat = 0; + struct stw_framebuffer *fb; + + fb = stw_framebuffer_from_hdc(hdc); + if(fb) { + iPixelFormat = fb->iPixelFormat; + stw_framebuffer_release(fb); + } + + return iPixelFormat; +} + + +BOOL APIENTRY +DrvPresentBuffers(HDC hdc, PGLPRESENTBUFFERSDATA data) +{ + struct stw_framebuffer *fb; + struct pipe_screen *screen; + struct pipe_resource *res; + + if (!stw_dev) + return FALSE; + + fb = stw_framebuffer_from_hdc( hdc ); + if (fb == NULL) + return FALSE; + + screen = stw_dev->screen; + + res = (struct pipe_resource *)data->pPrivateData; + + if(data->hSharedSurface != fb->hSharedSurface) { + if(fb->shared_surface) { + stw_dev->stw_winsys->shared_surface_close(screen, fb->shared_surface); + fb->shared_surface = NULL; + } + + fb->hSharedSurface = data->hSharedSurface; + + if(data->hSharedSurface && + stw_dev->stw_winsys->shared_surface_open) { + fb->shared_surface = stw_dev->stw_winsys->shared_surface_open(screen, fb->hSharedSurface); + } + } + + if(fb->shared_surface) { + stw_dev->stw_winsys->compose(screen, + res, + fb->shared_surface, + &fb->client_rect, + data->PresentHistoryToken); + } + else { + stw_dev->stw_winsys->present( screen, res, hdc ); + } + + stw_framebuffer_update(fb); + stw_notify_current_locked(fb); + + stw_framebuffer_release(fb); + + return TRUE; +} + + +/** + * Queue a composition. + * + * It will drop the lock on success. + */ +BOOL +stw_framebuffer_present_locked(HDC hdc, + struct stw_framebuffer *fb, + struct pipe_resource *res) +{ + if(stw_dev->callbacks.wglCbPresentBuffers && + stw_dev->stw_winsys->compose) { + GLCBPRESENTBUFFERSDATA data; + + memset(&data, 0, sizeof data); + data.magic1 = 2; + data.magic2 = 0; + data.AdapterLuid = stw_dev->AdapterLuid; + data.rect = fb->client_rect; + data.pPrivateData = (void *)res; + + stw_notify_current_locked(fb); + stw_framebuffer_release(fb); + + return stw_dev->callbacks.wglCbPresentBuffers(hdc, &data); + } + else { + struct pipe_screen *screen = stw_dev->screen; + + stw_dev->stw_winsys->present( screen, res, hdc ); + + stw_framebuffer_update(fb); + stw_notify_current_locked(fb); + stw_framebuffer_release(fb); + + return TRUE; + } +} + + +BOOL APIENTRY +DrvSwapBuffers( + HDC hdc ) +{ + struct stw_framebuffer *fb; + + if (!stw_dev) + return FALSE; + + fb = stw_framebuffer_from_hdc( hdc ); + if (fb == NULL) + return FALSE; + + if (!(fb->pfi->pfd.dwFlags & PFD_DOUBLEBUFFER)) { + stw_framebuffer_release(fb); + return TRUE; + } + + stw_flush_current_locked(fb); + + return stw_st_swap_framebuffer_locked(fb->stfb); +} + + +BOOL APIENTRY +DrvSwapLayerBuffers( + HDC hdc, + UINT fuPlanes ) +{ + if(fuPlanes & WGL_SWAP_MAIN_PLANE) + return DrvSwapBuffers(hdc); + + return FALSE; +} diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.h b/src/gallium/state_trackers/wgl/stw_framebuffer.h new file mode 100644 index 0000000..6604e54 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_framebuffer.h @@ -0,0 +1,167 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef STW_FRAMEBUFFER_H +#define STW_FRAMEBUFFER_H + +#include + +#include "os/os_thread.h" + +struct pipe_resource; +struct st_framebuffer_iface; +struct stw_pixelformat_info; + +/** + * Windows framebuffer, derived from gl_framebuffer. + */ +struct stw_framebuffer +{ + /** + * This mutex has two purposes: + * - protect the access to the mutable data members below + * - prevent the framebuffer from being deleted while being accessed. + * + * It is OK to lock this mutex while holding the stw_device::fb_mutex lock, + * but the opposite must never happen. + */ + pipe_mutex mutex; + + /* + * Immutable members. + * + * Note that even access to immutable members implies acquiring the mutex + * above, to prevent the framebuffer from being destroyed. + */ + + HDC hDC; + HWND hWnd; + + int iPixelFormat; + const struct stw_pixelformat_info *pfi; + + struct st_framebuffer_iface *stfb; + + /* + * Mutable members. + */ + + unsigned refcnt; + + + /* FIXME: Make this work for multiple contexts bound to the same framebuffer */ + boolean must_resize; + + unsigned width; + unsigned height; + + /** + * Client area rectangle, relative to the window upper-left corner. + * + * @sa GLCBPRESENTBUFFERSDATA::rect. + */ + RECT client_rect; + + HANDLE hSharedSurface; + struct stw_shared_surface *shared_surface; + + /** + * This is protected by stw_device::fb_mutex, not the mutex above. + * + * Deletions must be done by first acquiring stw_device::fb_mutex, and then + * acquiring the stw_framebuffer::mutex of the framebuffer to be deleted. + * This ensures that nobody else is reading/writing to the. + * + * It is not necessary to aquire the mutex above to navigate the linked list + * given that deletions are done with stw_device::fb_mutex held, so no other + * thread can delete. + */ + struct stw_framebuffer *next; +}; + + +/** + * Create a new framebuffer object which will correspond to the given HDC. + * + * This function will acquire stw_framebuffer::mutex. stw_framebuffer_release + * must be called when done + */ +struct stw_framebuffer * +stw_framebuffer_create( + HDC hdc, + int iPixelFormat ); + +void +stw_framebuffer_reference( + struct stw_framebuffer **ptr, + struct stw_framebuffer *fb); + +/** + * Search a framebuffer with a matching HWND. + * + * This function will acquire stw_framebuffer::mutex. stw_framebuffer_release + * must be called when done + */ +struct stw_framebuffer * +stw_framebuffer_from_hwnd( + HWND hwnd ); + +/** + * Search a framebuffer with a matching HDC. + * + * This function will acquire stw_framebuffer::mutex. stw_framebuffer_release + * must be called when done + */ +struct stw_framebuffer * +stw_framebuffer_from_hdc( + HDC hdc ); + +BOOL +stw_framebuffer_present_locked(HDC hdc, + struct stw_framebuffer *fb, + struct pipe_resource *res); + +void +stw_framebuffer_update( + struct stw_framebuffer *fb); + +/** + * Release stw_framebuffer::mutex lock. This framebuffer must not be accessed + * after calling this function, as it may have been deleted by another thread + * in the meanwhile. + */ +void +stw_framebuffer_release( + struct stw_framebuffer *fb); + +/** + * Cleanup any existing framebuffers when exiting application. + */ +void +stw_framebuffer_cleanup(void); + +#endif /* STW_FRAMEBUFFER_H */ diff --git a/src/gallium/state_trackers/wgl/stw_getprocaddress.c b/src/gallium/state_trackers/wgl/stw_getprocaddress.c new file mode 100644 index 0000000..b0aef94 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_getprocaddress.c @@ -0,0 +1,97 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include + +#define WGL_WGLEXT_PROTOTYPES + +#include +#include + +#include "glapi/glapi.h" +#include "stw_ext_gallium.h" +#include "stw_device.h" +#include "stw_icd.h" + +struct stw_extension_entry +{ + const char *name; + PROC proc; +}; + +#define STW_EXTENSION_ENTRY(P) { #P, (PROC) P } + +static const struct stw_extension_entry stw_extension_entries[] = { + + /* WGL_ARB_extensions_string */ + STW_EXTENSION_ENTRY( wglGetExtensionsStringARB ), + + /* WGL_ARB_pbuffer */ + STW_EXTENSION_ENTRY( wglCreatePbufferARB ), + STW_EXTENSION_ENTRY( wglGetPbufferDCARB ), + STW_EXTENSION_ENTRY( wglReleasePbufferDCARB ), + STW_EXTENSION_ENTRY( wglDestroyPbufferARB ), + STW_EXTENSION_ENTRY( wglQueryPbufferARB ), + + /* WGL_ARB_pixel_format */ + STW_EXTENSION_ENTRY( wglChoosePixelFormatARB ), + STW_EXTENSION_ENTRY( wglGetPixelFormatAttribfvARB ), + STW_EXTENSION_ENTRY( wglGetPixelFormatAttribivARB ), + + /* WGL_EXT_extensions_string */ + STW_EXTENSION_ENTRY( wglGetExtensionsStringEXT ), + + /* WGL_EXT_swap_interval */ + STW_EXTENSION_ENTRY( wglGetSwapIntervalEXT ), + STW_EXTENSION_ENTRY( wglSwapIntervalEXT ), + + /* WGL_EXT_gallium ? */ + STW_EXTENSION_ENTRY( wglGetGalliumScreenMESA ), + STW_EXTENSION_ENTRY( wglCreateGalliumContextMESA ), + + { NULL, NULL } +}; + +PROC APIENTRY +DrvGetProcAddress( + LPCSTR lpszProc ) +{ + const struct stw_extension_entry *entry; + + if (!stw_dev) + return NULL; + + if (lpszProc[0] == 'w' && lpszProc[1] == 'g' && lpszProc[2] == 'l') + for (entry = stw_extension_entries; entry->name; entry++) + if (strcmp( lpszProc, entry->name ) == 0) + return entry->proc; + + if (lpszProc[0] == 'g' && lpszProc[1] == 'l') + return (PROC) _glapi_get_proc_address( lpszProc ); + + return NULL; +} diff --git a/src/gallium/state_trackers/wgl/stw_icd.h b/src/gallium/state_trackers/wgl/stw_icd.h new file mode 100644 index 0000000..02eb543 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_icd.h @@ -0,0 +1,599 @@ +/************************************************************************** + * + * 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, 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 STW_ICD_H +#define STW_ICD_H + + +#include + +#include "GL/gl.h" + + +typedef ULONG DHGLRC; + +#define OPENGL_VERSION_110_ENTRIES 336 + +struct __GLdispatchTableRec +{ + void (GLAPIENTRY * NewList)(GLuint, GLenum); + void (GLAPIENTRY * EndList)(void); + void (GLAPIENTRY * CallList)(GLuint); + void (GLAPIENTRY * CallLists)(GLsizei, GLenum, const GLvoid *); + void (GLAPIENTRY * DeleteLists)(GLuint, GLsizei); + GLuint (GLAPIENTRY * GenLists)(GLsizei); + void (GLAPIENTRY * ListBase)(GLuint); + void (GLAPIENTRY * Begin)(GLenum); + void (GLAPIENTRY * Bitmap)(GLsizei, GLsizei, GLfloat, GLfloat, GLfloat, GLfloat, const GLubyte *); + void (GLAPIENTRY * Color3b)(GLbyte, GLbyte, GLbyte); + void (GLAPIENTRY * Color3bv)(const GLbyte *); + void (GLAPIENTRY * Color3d)(GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * Color3dv)(const GLdouble *); + void (GLAPIENTRY * Color3f)(GLfloat, GLfloat, GLfloat); + void (GLAPIENTRY * Color3fv)(const GLfloat *); + void (GLAPIENTRY * Color3i)(GLint, GLint, GLint); + void (GLAPIENTRY * Color3iv)(const GLint *); + void (GLAPIENTRY * Color3s)(GLshort, GLshort, GLshort); + void (GLAPIENTRY * Color3sv)(const GLshort *); + void (GLAPIENTRY * Color3ub)(GLubyte, GLubyte, GLubyte); + void (GLAPIENTRY * Color3ubv)(const GLubyte *); + void (GLAPIENTRY * Color3ui)(GLuint, GLuint, GLuint); + void (GLAPIENTRY * Color3uiv)(const GLuint *); + void (GLAPIENTRY * Color3us)(GLushort, GLushort, GLushort); + void (GLAPIENTRY * Color3usv)(const GLushort *); + void (GLAPIENTRY * Color4b)(GLbyte, GLbyte, GLbyte, GLbyte); + void (GLAPIENTRY * Color4bv)(const GLbyte *); + void (GLAPIENTRY * Color4d)(GLdouble, GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * Color4dv)(const GLdouble *); + void (GLAPIENTRY * Color4f)(GLfloat, GLfloat, GLfloat, GLfloat); + void (GLAPIENTRY * Color4fv)(const GLfloat *); + void (GLAPIENTRY * Color4i)(GLint, GLint, GLint, GLint); + void (GLAPIENTRY * Color4iv)(const GLint *); + void (GLAPIENTRY * Color4s)(GLshort, GLshort, GLshort, GLshort); + void (GLAPIENTRY * Color4sv)(const GLshort *); + void (GLAPIENTRY * Color4ub)(GLubyte, GLubyte, GLubyte, GLubyte); + void (GLAPIENTRY * Color4ubv)(const GLubyte *); + void (GLAPIENTRY * Color4ui)(GLuint, GLuint, GLuint, GLuint); + void (GLAPIENTRY * Color4uiv)(const GLuint *); + void (GLAPIENTRY * Color4us)(GLushort, GLushort, GLushort, GLushort); + void (GLAPIENTRY * Color4usv)(const GLushort *); + void (GLAPIENTRY * EdgeFlag)(GLboolean); + void (GLAPIENTRY * EdgeFlagv)(const GLboolean *); + void (GLAPIENTRY * End)(void); + void (GLAPIENTRY * Indexd)(GLdouble); + void (GLAPIENTRY * Indexdv)(const GLdouble *); + void (GLAPIENTRY * Indexf)(GLfloat); + void (GLAPIENTRY * Indexfv)(const GLfloat *); + void (GLAPIENTRY * Indexi)(GLint); + void (GLAPIENTRY * Indexiv)(const GLint *); + void (GLAPIENTRY * Indexs)(GLshort); + void (GLAPIENTRY * Indexsv)(const GLshort *); + void (GLAPIENTRY * Normal3b)(GLbyte, GLbyte, GLbyte); + void (GLAPIENTRY * Normal3bv)(const GLbyte *); + void (GLAPIENTRY * Normal3d)(GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * Normal3dv)(const GLdouble *); + void (GLAPIENTRY * Normal3f)(GLfloat, GLfloat, GLfloat); + void (GLAPIENTRY * Normal3fv)(const GLfloat *); + void (GLAPIENTRY * Normal3i)(GLint, GLint, GLint); + void (GLAPIENTRY * Normal3iv)(const GLint *); + void (GLAPIENTRY * Normal3s)(GLshort, GLshort, GLshort); + void (GLAPIENTRY * Normal3sv)(const GLshort *); + void (GLAPIENTRY * RasterPos2d)(GLdouble, GLdouble); + void (GLAPIENTRY * RasterPos2dv)(const GLdouble *); + void (GLAPIENTRY * RasterPos2f)(GLfloat, GLfloat); + void (GLAPIENTRY * RasterPos2fv)(const GLfloat *); + void (GLAPIENTRY * RasterPos2i)(GLint, GLint); + void (GLAPIENTRY * RasterPos2iv)(const GLint *); + void (GLAPIENTRY * RasterPos2s)(GLshort, GLshort); + void (GLAPIENTRY * RasterPos2sv)(const GLshort *); + void (GLAPIENTRY * RasterPos3d)(GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * RasterPos3dv)(const GLdouble *); + void (GLAPIENTRY * RasterPos3f)(GLfloat, GLfloat, GLfloat); + void (GLAPIENTRY * RasterPos3fv)(const GLfloat *); + void (GLAPIENTRY * RasterPos3i)(GLint, GLint, GLint); + void (GLAPIENTRY * RasterPos3iv)(const GLint *); + void (GLAPIENTRY * RasterPos3s)(GLshort, GLshort, GLshort); + void (GLAPIENTRY * RasterPos3sv)(const GLshort *); + void (GLAPIENTRY * RasterPos4d)(GLdouble, GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * RasterPos4dv)(const GLdouble *); + void (GLAPIENTRY * RasterPos4f)(GLfloat, GLfloat, GLfloat, GLfloat); + void (GLAPIENTRY * RasterPos4fv)(const GLfloat *); + void (GLAPIENTRY * RasterPos4i)(GLint, GLint, GLint, GLint); + void (GLAPIENTRY * RasterPos4iv)(const GLint *); + void (GLAPIENTRY * RasterPos4s)(GLshort, GLshort, GLshort, GLshort); + void (GLAPIENTRY * RasterPos4sv)(const GLshort *); + void (GLAPIENTRY * Rectd)(GLdouble, GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * Rectdv)(const GLdouble *, const GLdouble *); + void (GLAPIENTRY * Rectf)(GLfloat, GLfloat, GLfloat, GLfloat); + void (GLAPIENTRY * Rectfv)(const GLfloat *, const GLfloat *); + void (GLAPIENTRY * Recti)(GLint, GLint, GLint, GLint); + void (GLAPIENTRY * Rectiv)(const GLint *, const GLint *); + void (GLAPIENTRY * Rects)(GLshort, GLshort, GLshort, GLshort); + void (GLAPIENTRY * Rectsv)(const GLshort *, const GLshort *); + void (GLAPIENTRY * TexCoord1d)(GLdouble); + void (GLAPIENTRY * TexCoord1dv)(const GLdouble *); + void (GLAPIENTRY * TexCoord1f)(GLfloat); + void (GLAPIENTRY * TexCoord1fv)(const GLfloat *); + void (GLAPIENTRY * TexCoord1i)(GLint); + void (GLAPIENTRY * TexCoord1iv)(const GLint *); + void (GLAPIENTRY * TexCoord1s)(GLshort); + void (GLAPIENTRY * TexCoord1sv)(const GLshort *); + void (GLAPIENTRY * TexCoord2d)(GLdouble, GLdouble); + void (GLAPIENTRY * TexCoord2dv)(const GLdouble *); + void (GLAPIENTRY * TexCoord2f)(GLfloat, GLfloat); + void (GLAPIENTRY * TexCoord2fv)(const GLfloat *); + void (GLAPIENTRY * TexCoord2i)(GLint, GLint); + void (GLAPIENTRY * TexCoord2iv)(const GLint *); + void (GLAPIENTRY * TexCoord2s)(GLshort, GLshort); + void (GLAPIENTRY * TexCoord2sv)(const GLshort *); + void (GLAPIENTRY * TexCoord3d)(GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * TexCoord3dv)(const GLdouble *); + void (GLAPIENTRY * TexCoord3f)(GLfloat, GLfloat, GLfloat); + void (GLAPIENTRY * TexCoord3fv)(const GLfloat *); + void (GLAPIENTRY * TexCoord3i)(GLint, GLint, GLint); + void (GLAPIENTRY * TexCoord3iv)(const GLint *); + void (GLAPIENTRY * TexCoord3s)(GLshort, GLshort, GLshort); + void (GLAPIENTRY * TexCoord3sv)(const GLshort *); + void (GLAPIENTRY * TexCoord4d)(GLdouble, GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * TexCoord4dv)(const GLdouble *); + void (GLAPIENTRY * TexCoord4f)(GLfloat, GLfloat, GLfloat, GLfloat); + void (GLAPIENTRY * TexCoord4fv)(const GLfloat *); + void (GLAPIENTRY * TexCoord4i)(GLint, GLint, GLint, GLint); + void (GLAPIENTRY * TexCoord4iv)(const GLint *); + void (GLAPIENTRY * TexCoord4s)(GLshort, GLshort, GLshort, GLshort); + void (GLAPIENTRY * TexCoord4sv)(const GLshort *); + void (GLAPIENTRY * Vertex2d)(GLdouble, GLdouble); + void (GLAPIENTRY * Vertex2dv)(const GLdouble *); + void (GLAPIENTRY * Vertex2f)(GLfloat, GLfloat); + void (GLAPIENTRY * Vertex2fv)(const GLfloat *); + void (GLAPIENTRY * Vertex2i)(GLint, GLint); + void (GLAPIENTRY * Vertex2iv)(const GLint *); + void (GLAPIENTRY * Vertex2s)(GLshort, GLshort); + void (GLAPIENTRY * Vertex2sv)(const GLshort *); + void (GLAPIENTRY * Vertex3d)(GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * Vertex3dv)(const GLdouble *); + void (GLAPIENTRY * Vertex3f)(GLfloat, GLfloat, GLfloat); + void (GLAPIENTRY * Vertex3fv)(const GLfloat *); + void (GLAPIENTRY * Vertex3i)(GLint, GLint, GLint); + void (GLAPIENTRY * Vertex3iv)(const GLint *); + void (GLAPIENTRY * Vertex3s)(GLshort, GLshort, GLshort); + void (GLAPIENTRY * Vertex3sv)(const GLshort *); + void (GLAPIENTRY * Vertex4d)(GLdouble, GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * Vertex4dv)(const GLdouble *); + void (GLAPIENTRY * Vertex4f)(GLfloat, GLfloat, GLfloat, GLfloat); + void (GLAPIENTRY * Vertex4fv)(const GLfloat *); + void (GLAPIENTRY * Vertex4i)(GLint, GLint, GLint, GLint); + void (GLAPIENTRY * Vertex4iv)(const GLint *); + void (GLAPIENTRY * Vertex4s)(GLshort, GLshort, GLshort, GLshort); + void (GLAPIENTRY * Vertex4sv)(const GLshort *); + void (GLAPIENTRY * ClipPlane)(GLenum, const GLdouble *); + void (GLAPIENTRY * ColorMaterial)(GLenum, GLenum); + void (GLAPIENTRY * CullFace)(GLenum); + void (GLAPIENTRY * Fogf)(GLenum, GLfloat); + void (GLAPIENTRY * Fogfv)(GLenum, const GLfloat *); + void (GLAPIENTRY * Fogi)(GLenum, GLint); + void (GLAPIENTRY * Fogiv)(GLenum, const GLint *); + void (GLAPIENTRY * FrontFace)(GLenum); + void (GLAPIENTRY * Hint)(GLenum, GLenum); + void (GLAPIENTRY * Lightf)(GLenum, GLenum, GLfloat); + void (GLAPIENTRY * Lightfv)(GLenum, GLenum, const GLfloat *); + void (GLAPIENTRY * Lighti)(GLenum, GLenum, GLint); + void (GLAPIENTRY * Lightiv)(GLenum, GLenum, const GLint *); + void (GLAPIENTRY * LightModelf)(GLenum, GLfloat); + void (GLAPIENTRY * LightModelfv)(GLenum, const GLfloat *); + void (GLAPIENTRY * LightModeli)(GLenum, GLint); + void (GLAPIENTRY * LightModeliv)(GLenum, const GLint *); + void (GLAPIENTRY * LineStipple)(GLint, GLushort); + void (GLAPIENTRY * LineWidth)(GLfloat); + void (GLAPIENTRY * Materialf)(GLenum, GLenum, GLfloat); + void (GLAPIENTRY * Materialfv)(GLenum, GLenum, const GLfloat *); + void (GLAPIENTRY * Materiali)(GLenum, GLenum, GLint); + void (GLAPIENTRY * Materialiv)(GLenum, GLenum, const GLint *); + void (GLAPIENTRY * PointSize)(GLfloat); + void (GLAPIENTRY * PolygonMode)(GLenum, GLenum); + void (GLAPIENTRY * PolygonStipple)(const GLubyte *); + void (GLAPIENTRY * Scissor)(GLint, GLint, GLsizei, GLsizei); + void (GLAPIENTRY * ShadeModel)(GLenum); + void (GLAPIENTRY * TexParameterf)(GLenum, GLenum, GLfloat); + void (GLAPIENTRY * TexParameterfv)(GLenum, GLenum, const GLfloat *); + void (GLAPIENTRY * TexParameteri)(GLenum, GLenum, GLint); + void (GLAPIENTRY * TexParameteriv)(GLenum, GLenum, const GLint *); + void (GLAPIENTRY * TexImage1D)(GLenum, GLint, GLint, GLsizei, GLint, GLenum, GLenum, const GLvoid *); + void (GLAPIENTRY * TexImage2D)(GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); + void (GLAPIENTRY * TexEnvf)(GLenum, GLenum, GLfloat); + void (GLAPIENTRY * TexEnvfv)(GLenum, GLenum, const GLfloat *); + void (GLAPIENTRY * TexEnvi)(GLenum, GLenum, GLint); + void (GLAPIENTRY * TexEnviv)(GLenum, GLenum, const GLint *); + void (GLAPIENTRY * TexGend)(GLenum, GLenum, GLdouble); + void (GLAPIENTRY * TexGendv)(GLenum, GLenum, const GLdouble *); + void (GLAPIENTRY * TexGenf)(GLenum, GLenum, GLfloat); + void (GLAPIENTRY * TexGenfv)(GLenum, GLenum, const GLfloat *); + void (GLAPIENTRY * TexGeni)(GLenum, GLenum, GLint); + void (GLAPIENTRY * TexGeniv)(GLenum, GLenum, const GLint *); + void (GLAPIENTRY * FeedbackBuffer)(GLsizei, GLenum, GLfloat *); + void (GLAPIENTRY * SelectBuffer)(GLsizei, GLuint *); + GLint (GLAPIENTRY * RenderMode)(GLenum); + void (GLAPIENTRY * InitNames)(void); + void (GLAPIENTRY * LoadName)(GLuint); + void (GLAPIENTRY * PassThrough)(GLfloat); + void (GLAPIENTRY * PopName)(void); + void (GLAPIENTRY * PushName)(GLuint); + void (GLAPIENTRY * DrawBuffer)(GLenum); + void (GLAPIENTRY * Clear)(GLbitfield); + void (GLAPIENTRY * ClearAccum)(GLfloat, GLfloat, GLfloat, GLfloat); + void (GLAPIENTRY * ClearIndex)(GLfloat); + void (GLAPIENTRY * ClearColor)(GLclampf, GLclampf, GLclampf, GLclampf); + void (GLAPIENTRY * ClearStencil)(GLint); + void (GLAPIENTRY * ClearDepth)(GLclampd); + void (GLAPIENTRY * StencilMask)(GLuint); + void (GLAPIENTRY * ColorMask)(GLboolean, GLboolean, GLboolean, GLboolean); + void (GLAPIENTRY * DepthMask)(GLboolean); + void (GLAPIENTRY * IndexMask)(GLuint); + void (GLAPIENTRY * Accum)(GLenum, GLfloat); + void (GLAPIENTRY * Disable)(GLenum); + void (GLAPIENTRY * Enable)(GLenum); + void (GLAPIENTRY * Finish)(void); + void (GLAPIENTRY * Flush)(void); + void (GLAPIENTRY * PopAttrib)(void); + void (GLAPIENTRY * PushAttrib)(GLbitfield); + void (GLAPIENTRY * Map1d)(GLenum, GLdouble, GLdouble, GLint, GLint, const GLdouble *); + void (GLAPIENTRY * Map1f)(GLenum, GLfloat, GLfloat, GLint, GLint, const GLfloat *); + void (GLAPIENTRY * Map2d)(GLenum, GLdouble, GLdouble, GLint, GLint, GLdouble, GLdouble, GLint, GLint, const GLdouble *); + void (GLAPIENTRY * Map2f)(GLenum, GLfloat, GLfloat, GLint, GLint, GLfloat, GLfloat, GLint, GLint, const GLfloat *); + void (GLAPIENTRY * MapGrid1d)(GLint, GLdouble, GLdouble); + void (GLAPIENTRY * MapGrid1f)(GLint, GLfloat, GLfloat); + void (GLAPIENTRY * MapGrid2d)(GLint, GLdouble, GLdouble, GLint, GLdouble, GLdouble); + void (GLAPIENTRY * MapGrid2f)(GLint, GLfloat, GLfloat, GLint, GLfloat, GLfloat); + void (GLAPIENTRY * EvalCoord1d)(GLdouble); + void (GLAPIENTRY * EvalCoord1dv)(const GLdouble *); + void (GLAPIENTRY * EvalCoord1f)(GLfloat); + void (GLAPIENTRY * EvalCoord1fv)(const GLfloat *); + void (GLAPIENTRY * EvalCoord2d)(GLdouble, GLdouble); + void (GLAPIENTRY * EvalCoord2dv)(const GLdouble *); + void (GLAPIENTRY * EvalCoord2f)(GLfloat, GLfloat); + void (GLAPIENTRY * EvalCoord2fv)(const GLfloat *); + void (GLAPIENTRY * EvalMesh1)(GLenum, GLint, GLint); + void (GLAPIENTRY * EvalPoint1)(GLint); + void (GLAPIENTRY * EvalMesh2)(GLenum, GLint, GLint, GLint, GLint); + void (GLAPIENTRY * EvalPoint2)(GLint, GLint); + void (GLAPIENTRY * AlphaFunc)(GLenum, GLclampf); + void (GLAPIENTRY * BlendFunc)(GLenum, GLenum); + void (GLAPIENTRY * LogicOp)(GLenum); + void (GLAPIENTRY * StencilFunc)(GLenum, GLint, GLuint); + void (GLAPIENTRY * StencilOp)(GLenum, GLenum, GLenum); + void (GLAPIENTRY * DepthFunc)(GLenum); + void (GLAPIENTRY * PixelZoom)(GLfloat, GLfloat); + void (GLAPIENTRY * PixelTransferf)(GLenum, GLfloat); + void (GLAPIENTRY * PixelTransferi)(GLenum, GLint); + void (GLAPIENTRY * PixelStoref)(GLenum, GLfloat); + void (GLAPIENTRY * PixelStorei)(GLenum, GLint); + void (GLAPIENTRY * PixelMapfv)(GLenum, GLint, const GLfloat *); + void (GLAPIENTRY * PixelMapuiv)(GLenum, GLint, const GLuint *); + void (GLAPIENTRY * PixelMapusv)(GLenum, GLint, const GLushort *); + void (GLAPIENTRY * ReadBuffer)(GLenum); + void (GLAPIENTRY * CopyPixels)(GLint, GLint, GLsizei, GLsizei, GLenum); + void (GLAPIENTRY * ReadPixels)(GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid *); + void (GLAPIENTRY * DrawPixels)(GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); + void (GLAPIENTRY * GetBooleanv)(GLenum, GLboolean *); + void (GLAPIENTRY * GetClipPlane)(GLenum, GLdouble *); + void (GLAPIENTRY * GetDoublev)(GLenum, GLdouble *); + GLenum (GLAPIENTRY * GetError)(void); + void (GLAPIENTRY * GetFloatv)(GLenum, GLfloat *); + void (GLAPIENTRY * GetIntegerv)(GLenum, GLint *); + void (GLAPIENTRY * GetLightfv)(GLenum, GLenum, GLfloat *); + void (GLAPIENTRY * GetLightiv)(GLenum, GLenum, GLint *); + void (GLAPIENTRY * GetMapdv)(GLenum, GLenum, GLdouble *); + void (GLAPIENTRY * GetMapfv)(GLenum, GLenum, GLfloat *); + void (GLAPIENTRY * GetMapiv)(GLenum, GLenum, GLint *); + void (GLAPIENTRY * GetMaterialfv)(GLenum, GLenum, GLfloat *); + void (GLAPIENTRY * GetMaterialiv)(GLenum, GLenum, GLint *); + void (GLAPIENTRY * GetPixelMapfv)(GLenum, GLfloat *); + void (GLAPIENTRY * GetPixelMapuiv)(GLenum, GLuint *); + void (GLAPIENTRY * GetPixelMapusv)(GLenum, GLushort *); + void (GLAPIENTRY * GetPolygonStipple)(GLubyte *); + const GLubyte * (GLAPIENTRY * GetString)(GLenum); + void (GLAPIENTRY * GetTexEnvfv)(GLenum, GLenum, GLfloat *); + void (GLAPIENTRY * GetTexEnviv)(GLenum, GLenum, GLint *); + void (GLAPIENTRY * GetTexGendv)(GLenum, GLenum, GLdouble *); + void (GLAPIENTRY * GetTexGenfv)(GLenum, GLenum, GLfloat *); + void (GLAPIENTRY * GetTexGeniv)(GLenum, GLenum, GLint *); + void (GLAPIENTRY * GetTexImage)(GLenum, GLint, GLenum, GLenum, GLvoid *); + void (GLAPIENTRY * GetTexParameterfv)(GLenum, GLenum, GLfloat *); + void (GLAPIENTRY * GetTexParameteriv)(GLenum, GLenum, GLint *); + void (GLAPIENTRY * GetTexLevelParameterfv)(GLenum, GLint, GLenum, GLfloat *); + void (GLAPIENTRY * GetTexLevelParameteriv)(GLenum, GLint, GLenum, GLint *); + GLboolean (GLAPIENTRY * IsEnabled)(GLenum); + GLboolean (GLAPIENTRY * IsList)(GLuint); + void (GLAPIENTRY * DepthRange)(GLclampd, GLclampd); + void (GLAPIENTRY * Frustum)(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * LoadIdentity)(void); + void (GLAPIENTRY * LoadMatrixf)(const GLfloat *); + void (GLAPIENTRY * LoadMatrixd)(const GLdouble *); + void (GLAPIENTRY * MatrixMode)(GLenum); + void (GLAPIENTRY * MultMatrixf)(const GLfloat *); + void (GLAPIENTRY * MultMatrixd)(const GLdouble *); + void (GLAPIENTRY * Ortho)(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * PopMatrix)(void); + void (GLAPIENTRY * PushMatrix)(void); + void (GLAPIENTRY * Rotated)(GLdouble, GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * Rotatef)(GLfloat, GLfloat, GLfloat, GLfloat); + void (GLAPIENTRY * Scaled)(GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * Scalef)(GLfloat, GLfloat, GLfloat); + void (GLAPIENTRY * Translated)(GLdouble, GLdouble, GLdouble); + void (GLAPIENTRY * Translatef)(GLfloat, GLfloat, GLfloat); + void (GLAPIENTRY * Viewport)(GLint, GLint, GLsizei, GLsizei); + void (GLAPIENTRY * ArrayElement)(GLint); + void (GLAPIENTRY * BindTexture)(GLenum, GLuint); + void (GLAPIENTRY * ColorPointer)(GLint, GLenum, GLsizei, const GLvoid *); + void (GLAPIENTRY * DisableClientState)(GLenum); + void (GLAPIENTRY * DrawArrays)(GLenum, GLint, GLsizei); + void (GLAPIENTRY * DrawElements)(GLenum, GLsizei, GLenum, const GLvoid *); + void (GLAPIENTRY * EdgeFlagPointer)(GLsizei, const GLvoid *); + void (GLAPIENTRY * EnableClientState)(GLenum); + void (GLAPIENTRY * IndexPointer)(GLenum, GLsizei, const GLvoid *); + void (GLAPIENTRY * Indexub)(GLubyte); + void (GLAPIENTRY * Indexubv)(const GLubyte *); + void (GLAPIENTRY * InterleavedArrays)(GLenum, GLsizei, const GLvoid *); + void (GLAPIENTRY * NormalPointer)(GLenum, GLsizei, const GLvoid *); + void (GLAPIENTRY * PolygonOffset)(GLfloat, GLfloat); + void (GLAPIENTRY * TexCoordPointer)(GLint, GLenum, GLsizei, const GLvoid *); + void (GLAPIENTRY * VertexPointer)(GLint, GLenum, GLsizei, const GLvoid *); + GLboolean (GLAPIENTRY * AreTexturesResident)(GLsizei, const GLuint *, GLboolean *); + void (GLAPIENTRY * CopyTexImage1D)(GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLint); + void (GLAPIENTRY * CopyTexImage2D)(GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint); + void (GLAPIENTRY * CopyTexSubImage1D)(GLenum, GLint, GLint, GLint, GLint, GLsizei); + void (GLAPIENTRY * CopyTexSubImage2D)(GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); + void (GLAPIENTRY * DeleteTextures)(GLsizei, const GLuint *); + void (GLAPIENTRY * GenTextures)(GLsizei, GLuint *); + void (GLAPIENTRY * GetPointerv)(GLenum, GLvoid **); + GLboolean (GLAPIENTRY * IsTexture)(GLuint); + void (GLAPIENTRY * PrioritizeTextures)(GLsizei, const GLuint *, const GLclampf *); + void (GLAPIENTRY * TexSubImage1D)(GLenum, GLint, GLint, GLsizei, GLenum, GLenum, const GLvoid *); + void (GLAPIENTRY * TexSubImage2D)(GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); + void (GLAPIENTRY * PopClientAttrib)(void); + void (GLAPIENTRY * PushClientAttrib)(GLbitfield); +}; + +typedef struct __GLdispatchTableRec GLDISPATCHTABLE; + +typedef struct _GLCLTPROCTABLE +{ + int cEntries; + GLDISPATCHTABLE glDispatchTable; +} GLCLTPROCTABLE, * PGLCLTPROCTABLE; + +typedef VOID (APIENTRY * PFN_SETPROCTABLE)(PGLCLTPROCTABLE); + +/** + * Presentation data passed to opengl32!wglCbPresentBuffers. + * + * Pure software drivers don't need to worry about this -- if they stick to the + * GDI API then will integrate with the Desktop Window Manager (DWM) without + * problems. Hardware drivers, however, cannot present directly to the primary + * surface while the DWM is active, as DWM gets exclusive access to the primary + * surface. + * + * Proper DWM integration requires: + * - advertise the PFD_SUPPORT_COMPOSITION flag + * - redirect glFlush/glfinish/wglSwapBuffers into a surface shared with the + * DWM process. + * + * @sa http://www.opengl.org/pipeline/article/vol003_7/ + * @sa http://blogs.msdn.com/greg_schechter/archive/2006/05/02/588934.aspx + */ +typedef struct _GLCBPRESENTBUFFERSDATA +{ + /** + * wglCbPresentBuffers enforces this to be 2. + */ + DWORD magic1; + + /** + * wglCbPresentBuffers enforces to be 0 or 1, but it is most commonly + * set to 0. + */ + DWORD magic2; + + /** + * Locally unique identifier (LUID) of the graphics adapter. + * + * This should contain the value returned by D3DKMTOpenAdapterFromHdc. It + * is passed to dwmapi!DwmpDxGetWindowSharedSurface in order to obtain + * the shared surface handle for the bound drawable (window). + * + * @sa http://msdn.microsoft.com/en-us/library/ms799177.aspx + */ + LUID AdapterLuid; + + /** + * This is passed unmodified to DrvPresentBuffers + */ + LPVOID pPrivateData; + + /** + * Client area rectangle to update, relative to the window upper-left corner. + */ + RECT rect; +} GLCBPRESENTBUFFERSDATA, *PGLCBPRESENTBUFFERSDATA; + +/** + * Callbacks supplied to DrvSetCallbackProcs by the OpenGL runtime. + * + * Pointers to several callback functions in opengl32.dll. + */ +typedef struct _GLCALLBACKTABLE +{ + /** Unused */ + PROC wglCbSetCurrentValue; + + /** Unused */ + PROC wglCbGetCurrentValue; + + /** Unused */ + PROC wglCbGetDhglrc; + + /** Unused */ + PROC wglCbGetDdHandle; + + /** + * Queue a present composition. + * + * Makes the runtime call DrvPresentBuffers with the composition information. + */ + BOOL (APIENTRY *wglCbPresentBuffers)(HDC hdc, PGLCBPRESENTBUFFERSDATA data); + +} GLCALLBACKTABLE; + +typedef struct _GLPRESENTBUFFERSDATA +{ + /** + * The shared surface handle. + * + * Return by dwmapi!DwmpDxGetWindowSharedSurface. + * + * @sa http://channel9.msdn.com/forums/TechOff/251261-Help-Getting-the-shared-window-texture-out-of-DWM-/ + */ + HANDLE hSharedSurface; + + LUID AdapterLuid; + + /** + * Present history token. + * + * This is returned by dwmapi!DwmpDxGetWindowSharedSurface and + * should be passed to D3DKMTRender in D3DKMT_RENDER::PresentHistoryToken. + * + * @sa http://msdn.microsoft.com/en-us/library/ms799176.aspx + */ + ULONGLONG PresentHistoryToken; + + /** Same as GLCBPRESENTBUFFERSDATA::pPrivateData */ + LPVOID pPrivateData; +} GLPRESENTBUFFERSDATA, *PGLPRESENTBUFFERSDATA; + +BOOL APIENTRY +DrvCopyContext( + DHGLRC dhrcSource, + DHGLRC dhrcDest, + UINT fuMask ); + +DHGLRC APIENTRY +DrvCreateLayerContext( + HDC hdc, + INT iLayerPlane ); + +DHGLRC APIENTRY +DrvCreateContext( + HDC hdc ); + +BOOL APIENTRY +DrvDeleteContext( + DHGLRC dhglrc ); + +BOOL APIENTRY +DrvDescribeLayerPlane( + HDC hdc, + INT iPixelFormat, + INT iLayerPlane, + UINT nBytes, + LPLAYERPLANEDESCRIPTOR plpd ); + +LONG APIENTRY +DrvDescribePixelFormat( + HDC hdc, + INT iPixelFormat, + ULONG cjpfd, + PIXELFORMATDESCRIPTOR *ppfd ); + +int APIENTRY +DrvGetLayerPaletteEntries( + HDC hdc, + INT iLayerPlane, + INT iStart, + INT cEntries, + COLORREF *pcr ); + +PROC APIENTRY +DrvGetProcAddress( + LPCSTR lpszProc ); + +BOOL APIENTRY +DrvPresentBuffers(HDC hdc, PGLPRESENTBUFFERSDATA data); + +BOOL APIENTRY +DrvRealizeLayerPalette( + HDC hdc, + INT iLayerPlane, + BOOL bRealize ); + +BOOL APIENTRY +DrvReleaseContext( + DHGLRC dhglrc ); + +void APIENTRY +DrvSetCallbackProcs( + INT nProcs, + PROC *pProcs ); + +PGLCLTPROCTABLE APIENTRY +DrvSetContext( + HDC hdc, + DHGLRC dhglrc, + PFN_SETPROCTABLE pfnSetProcTable ); + +int APIENTRY +DrvSetLayerPaletteEntries( + HDC hdc, + INT iLayerPlane, + INT iStart, + INT cEntries, + CONST COLORREF *pcr ); + +BOOL APIENTRY +DrvSetPixelFormat( + HDC hdc, + LONG iPixelFormat ); + +BOOL APIENTRY +DrvShareLists( + DHGLRC dhglrc1, + DHGLRC dhglrc2 ); + +BOOL APIENTRY +DrvSwapBuffers( + HDC hdc ); + +BOOL APIENTRY +DrvSwapLayerBuffers( + HDC hdc, + UINT fuPlanes ); + +BOOL APIENTRY +DrvValidateVersion( + ULONG ulVersion ); + +#endif /* STW_ICD_H */ diff --git a/src/gallium/state_trackers/wgl/stw_pixelformat.c b/src/gallium/state_trackers/wgl/stw_pixelformat.c new file mode 100644 index 0000000..5ede1d4 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_pixelformat.c @@ -0,0 +1,401 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "pipe/p_format.h" +#include "pipe/p_defines.h" +#include "pipe/p_screen.h" + +#include "util/u_format.h" +#include "util/u_debug.h" +#include "util/u_memory.h" + +#include "stw_icd.h" +#include "stw_device.h" +#include "stw_pixelformat.h" +#include "stw_tls.h" + + +struct stw_pf_color_info +{ + enum pipe_format format; + struct { + unsigned char red; + unsigned char green; + unsigned char blue; + unsigned char alpha; + } bits; + struct { + unsigned char red; + unsigned char green; + unsigned char blue; + unsigned char alpha; + } shift; +}; + +struct stw_pf_depth_info +{ + enum pipe_format format; + struct { + unsigned char depth; + unsigned char stencil; + } bits; +}; + + +/* NOTE: order matters, since in otherwise equal circumstances the first + * format listed will get chosen */ + +static const struct stw_pf_color_info +stw_pf_color[] = { + /* no-alpha */ + { PIPE_FORMAT_B8G8R8X8_UNORM, { 8, 8, 8, 0}, {16, 8, 0, 0} }, + { PIPE_FORMAT_X8R8G8B8_UNORM, { 8, 8, 8, 0}, { 8, 16, 24, 0} }, + { PIPE_FORMAT_B5G6R5_UNORM, { 5, 6, 5, 0}, {11, 5, 0, 0} }, + /* alpha */ + { PIPE_FORMAT_B8G8R8A8_UNORM, { 8, 8, 8, 8}, {16, 8, 0, 24} }, + { PIPE_FORMAT_A8R8G8B8_UNORM, { 8, 8, 8, 8}, { 8, 16, 24, 0} }, +#if 0 + { PIPE_FORMAT_R10G10B10A2_UNORM, {10, 10, 10, 2}, { 0, 10, 20, 30} }, +#endif + { PIPE_FORMAT_B5G5R5A1_UNORM, { 5, 5, 5, 1}, {10, 5, 0, 15} }, + { PIPE_FORMAT_B4G4R4A4_UNORM, { 4, 4, 4, 4}, {16, 4, 0, 12} } +}; + + +static const struct stw_pf_depth_info +stw_pf_depth_stencil[] = { + /* pure depth */ + { PIPE_FORMAT_Z32_UNORM, {32, 0} }, + { PIPE_FORMAT_X8Z24_UNORM, {24, 0} }, + { PIPE_FORMAT_Z24X8_UNORM, {24, 0} }, + { PIPE_FORMAT_Z16_UNORM, {16, 0} }, + /* combined depth-stencil */ + { PIPE_FORMAT_Z24_UNORM_S8_USCALED, {24, 8} }, + { PIPE_FORMAT_S8_USCALED_Z24_UNORM, {24, 8} } +}; + + +static const boolean +stw_pf_doublebuffer[] = { + FALSE, + TRUE, +}; + + +const unsigned +stw_pf_multisample[] = { + 0, + 4 +}; + + +static void +stw_pixelformat_add( + struct stw_device *stw_dev, + const struct stw_pf_color_info *color, + const struct stw_pf_depth_info *depth, + unsigned accum, + boolean doublebuffer, + unsigned samples ) +{ + boolean extended = FALSE; + struct stw_pixelformat_info *pfi; + + assert(stw_dev->pixelformat_extended_count < STW_MAX_PIXELFORMATS); + if(stw_dev->pixelformat_extended_count >= STW_MAX_PIXELFORMATS) + return; + + assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 0) == color->bits.red); + assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 1) == color->bits.green); + assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 2) == color->bits.blue); + assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 3) == color->bits.alpha); + assert(util_format_get_component_bits(depth->format, UTIL_FORMAT_COLORSPACE_ZS, 0) == depth->bits.depth); + assert(util_format_get_component_bits(depth->format, UTIL_FORMAT_COLORSPACE_ZS, 1) == depth->bits.stencil); + + pfi = &stw_dev->pixelformats[stw_dev->pixelformat_extended_count]; + + memset(pfi, 0, sizeof *pfi); + + pfi->pfd.nSize = sizeof pfi->pfd; + pfi->pfd.nVersion = 1; + + pfi->pfd.dwFlags = PFD_SUPPORT_OPENGL; + + /* TODO: also support non-native pixel formats */ + pfi->pfd.dwFlags |= PFD_DRAW_TO_WINDOW; + + /* See http://www.opengl.org/pipeline/article/vol003_7/ */ + pfi->pfd.dwFlags |= PFD_SUPPORT_COMPOSITION; + + if (doublebuffer) + pfi->pfd.dwFlags |= PFD_DOUBLEBUFFER | PFD_SWAP_COPY; + + pfi->pfd.iPixelType = PFD_TYPE_RGBA; + + pfi->pfd.cColorBits = color->bits.red + color->bits.green + color->bits.blue + color->bits.alpha; + pfi->pfd.cRedBits = color->bits.red; + pfi->pfd.cRedShift = color->shift.red; + pfi->pfd.cGreenBits = color->bits.green; + pfi->pfd.cGreenShift = color->shift.green; + pfi->pfd.cBlueBits = color->bits.blue; + pfi->pfd.cBlueShift = color->shift.blue; + pfi->pfd.cAlphaBits = color->bits.alpha; + pfi->pfd.cAlphaShift = color->shift.alpha; + pfi->pfd.cAccumBits = 4*accum; + pfi->pfd.cAccumRedBits = accum; + pfi->pfd.cAccumGreenBits = accum; + pfi->pfd.cAccumBlueBits = accum; + pfi->pfd.cAccumAlphaBits = accum; + pfi->pfd.cDepthBits = depth->bits.depth; + pfi->pfd.cStencilBits = depth->bits.stencil; + pfi->pfd.cAuxBuffers = 0; + pfi->pfd.iLayerType = 0; + pfi->pfd.bReserved = 0; + pfi->pfd.dwLayerMask = 0; + pfi->pfd.dwVisibleMask = 0; + pfi->pfd.dwDamageMask = 0; + + /* + * since state trackers can allocate depth/stencil/accum buffers, we provide + * only color buffers here + */ + pfi->stvis.buffer_mask = ST_ATTACHMENT_FRONT_LEFT_MASK; + if (doublebuffer) + pfi->stvis.buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK; + + pfi->stvis.color_format = color->format; + pfi->stvis.depth_stencil_format = depth->format; + + pfi->stvis.accum_format = (accum) ? + PIPE_FORMAT_R16G16B16A16_SNORM : PIPE_FORMAT_NONE; + + pfi->stvis.samples = samples; + pfi->stvis.render_buffer = ST_ATTACHMENT_INVALID; + + ++stw_dev->pixelformat_extended_count; + + if(!extended) { + ++stw_dev->pixelformat_count; + assert(stw_dev->pixelformat_count == stw_dev->pixelformat_extended_count); + } +} + +void +stw_pixelformat_init( void ) +{ + struct pipe_screen *screen = stw_dev->screen; + unsigned i, j, k, l; + + assert( !stw_dev->pixelformat_count ); + assert( !stw_dev->pixelformat_extended_count ); + + for(i = 0; i < Elements(stw_pf_multisample); ++i) { + unsigned samples = stw_pf_multisample[i]; + + /* FIXME: re-enabled MSAA when we can query it */ + if(samples) + continue; + + for(j = 0; j < Elements(stw_pf_color); ++j) { + const struct stw_pf_color_info *color = &stw_pf_color[j]; + + if(!screen->is_format_supported(screen, color->format, PIPE_TEXTURE_2D, + 0, PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET, 0)) + continue; + + for(k = 0; k < Elements(stw_pf_doublebuffer); ++k) { + unsigned doublebuffer = stw_pf_doublebuffer[k]; + + for(l = 0; l < Elements(stw_pf_depth_stencil); ++l) { + const struct stw_pf_depth_info *depth = &stw_pf_depth_stencil[l]; + + if(!screen->is_format_supported(screen, depth->format, PIPE_TEXTURE_2D, + 0, PIPE_BIND_DEPTH_STENCIL, 0)) + continue; + + stw_pixelformat_add( stw_dev, color, depth, 0, doublebuffer, samples ); + stw_pixelformat_add( stw_dev, color, depth, 16, doublebuffer, samples ); + } + } + } + } + + assert( stw_dev->pixelformat_count <= stw_dev->pixelformat_extended_count ); + assert( stw_dev->pixelformat_extended_count <= STW_MAX_PIXELFORMATS ); +} + +uint +stw_pixelformat_get_count( void ) +{ + return stw_dev->pixelformat_count; +} + +uint +stw_pixelformat_get_extended_count( void ) +{ + return stw_dev->pixelformat_extended_count; +} + +const struct stw_pixelformat_info * +stw_pixelformat_get_info( uint index ) +{ + assert( index < stw_dev->pixelformat_extended_count ); + + return &stw_dev->pixelformats[index]; +} + + +LONG APIENTRY +DrvDescribePixelFormat( + HDC hdc, + INT iPixelFormat, + ULONG cjpfd, + PIXELFORMATDESCRIPTOR *ppfd ) +{ + uint count; + uint index; + const struct stw_pixelformat_info *pfi; + + (void) hdc; + + if (!stw_dev) + return 0; + + count = stw_pixelformat_get_extended_count(); + index = (uint) iPixelFormat - 1; + + if (ppfd == NULL) + return count; + if (index >= count || cjpfd != sizeof( PIXELFORMATDESCRIPTOR )) + return 0; + + pfi = stw_pixelformat_get_info( index ); + + memcpy(ppfd, &pfi->pfd, sizeof( PIXELFORMATDESCRIPTOR )); + + return count; +} + +BOOL APIENTRY +DrvDescribeLayerPlane( + HDC hdc, + INT iPixelFormat, + INT iLayerPlane, + UINT nBytes, + LPLAYERPLANEDESCRIPTOR plpd ) +{ + assert(0); + return FALSE; +} + +int APIENTRY +DrvGetLayerPaletteEntries( + HDC hdc, + INT iLayerPlane, + INT iStart, + INT cEntries, + COLORREF *pcr ) +{ + assert(0); + return 0; +} + +int APIENTRY +DrvSetLayerPaletteEntries( + HDC hdc, + INT iLayerPlane, + INT iStart, + INT cEntries, + CONST COLORREF *pcr ) +{ + assert(0); + return 0; +} + +BOOL APIENTRY +DrvRealizeLayerPalette( + HDC hdc, + INT iLayerPlane, + BOOL bRealize ) +{ + assert(0); + return FALSE; +} + +/* Only used by the wgl code, but have it here to avoid exporting the + * pixelformat.h functionality. + */ +int stw_pixelformat_choose( HDC hdc, + CONST PIXELFORMATDESCRIPTOR *ppfd ) +{ + uint count; + uint index; + uint bestindex; + uint bestdelta; + + (void) hdc; + + count = stw_pixelformat_get_count(); + bestindex = count; + bestdelta = ~0U; + + for (index = 0; index < count; index++) { + uint delta = 0; + const struct stw_pixelformat_info *pfi = stw_pixelformat_get_info( index ); + + if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) && + !!(ppfd->dwFlags & PFD_DOUBLEBUFFER) != + !!(pfi->pfd.dwFlags & PFD_DOUBLEBUFFER)) + continue; + + /* FIXME: Take in account individual channel bits */ + if (ppfd->cColorBits != pfi->pfd.cColorBits) + delta += 8; + + if (ppfd->cDepthBits != pfi->pfd.cDepthBits) + delta += 4; + + if (ppfd->cStencilBits != pfi->pfd.cStencilBits) + delta += 2; + + if (ppfd->cAlphaBits != pfi->pfd.cAlphaBits) + delta++; + + if (delta < bestdelta) { + bestindex = index; + bestdelta = delta; + if (bestdelta == 0) + break; + } + } + + if (bestindex == count) + return 0; + + return bestindex + 1; +} diff --git a/src/gallium/state_trackers/wgl/stw_pixelformat.h b/src/gallium/state_trackers/wgl/stw_pixelformat.h new file mode 100644 index 0000000..282c9f6 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_pixelformat.h @@ -0,0 +1,67 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#ifndef STW_PIXELFORMAT_H +#define STW_PIXELFORMAT_H + +#include + +#ifndef PFD_SUPPORT_COMPOSITION +#define PFD_SUPPORT_COMPOSITION 0x00008000 +#endif + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "state_tracker/st_api.h" + +struct stw_pixelformat_info +{ + PIXELFORMATDESCRIPTOR pfd; + + struct st_visual stvis; +}; + +void +stw_pixelformat_init( void ); + +uint +stw_pixelformat_get_count( void ); + +uint +stw_pixelformat_get_extended_count( void ); + +const struct stw_pixelformat_info * +stw_pixelformat_get_info( uint index ); + +int +stw_pixelformat_choose( HDC hdc, + CONST PIXELFORMATDESCRIPTOR *ppfd ); + +int +stw_pixelformat_get(HDC hdc); + +#endif /* STW_PIXELFORMAT_H */ diff --git a/src/gallium/state_trackers/wgl/stw_st.c b/src/gallium/state_trackers/wgl/stw_st.c new file mode 100644 index 0000000..b58d916 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_st.c @@ -0,0 +1,258 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * 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: + * Chia-I Wu + */ + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "state_tracker/st_gl_api.h" /* for st_gl_api_create */ + +#include "stw_st.h" +#include "stw_device.h" +#include "stw_framebuffer.h" +#include "stw_pixelformat.h" + +struct stw_st_framebuffer { + struct st_framebuffer_iface base; + + struct stw_framebuffer *fb; + struct st_visual stvis; + + struct pipe_resource *textures[ST_ATTACHMENT_COUNT]; + unsigned texture_width, texture_height; + unsigned texture_mask; +}; + +static INLINE struct stw_st_framebuffer * +stw_st_framebuffer(struct st_framebuffer_iface *stfb) +{ + return (struct stw_st_framebuffer *) stfb; +} + +/** + * Remove outdated textures and create the requested ones. + */ +static void +stw_st_framebuffer_validate_locked(struct st_framebuffer_iface *stfb, + unsigned width, unsigned height, + unsigned mask) +{ + struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb); + struct pipe_resource templ; + unsigned i; + + /* remove outdated textures */ + if (stwfb->texture_width != width || stwfb->texture_height != height) { + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_resource_reference(&stwfb->textures[i], NULL); + } + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.array_size = 1; + templ.last_level = 0; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + enum pipe_format format; + unsigned bind; + + /* the texture already exists or not requested */ + if (stwfb->textures[i] || !(mask & (1 << i))) { + /* remember the texture */ + if (stwfb->textures[i]) + mask |= (1 << i); + continue; + } + + switch (i) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_BACK_LEFT: + format = stwfb->stvis.color_format; + bind = PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_RENDER_TARGET; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + format = stwfb->stvis.depth_stencil_format; + bind = PIPE_BIND_DEPTH_STENCIL; + break; + default: + format = PIPE_FORMAT_NONE; + break; + } + + if (format != PIPE_FORMAT_NONE) { + templ.format = format; + templ.bind = bind; + + stwfb->textures[i] = + stw_dev->screen->resource_create(stw_dev->screen, &templ); + } + } + + stwfb->texture_width = width; + stwfb->texture_height = height; + stwfb->texture_mask = mask; +} + +static boolean +stw_st_framebuffer_validate(struct st_framebuffer_iface *stfb, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_resource **out) +{ + struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb); + unsigned statt_mask, i; + + statt_mask = 0x0; + for (i = 0; i < count; i++) + statt_mask |= 1 << statts[i]; + + pipe_mutex_lock(stwfb->fb->mutex); + + if (stwfb->fb->must_resize || (statt_mask & ~stwfb->texture_mask)) { + stw_st_framebuffer_validate_locked(&stwfb->base, + stwfb->fb->width, stwfb->fb->height, statt_mask); + stwfb->fb->must_resize = FALSE; + } + + for (i = 0; i < count; i++) { + out[i] = NULL; + pipe_resource_reference(&out[i], stwfb->textures[statts[i]]); + } + + stw_framebuffer_release(stwfb->fb); + + return TRUE; +} + +/** + * Present an attachment of the framebuffer. + */ +static boolean +stw_st_framebuffer_present_locked(struct st_framebuffer_iface *stfb, + enum st_attachment_type statt) +{ + struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb); + struct pipe_resource *resource; + + resource = stwfb->textures[statt]; + if (resource) { + stw_framebuffer_present_locked(stwfb->fb->hDC, stwfb->fb, resource); + } + + return TRUE; +} + +static boolean +stw_st_framebuffer_flush_front(struct st_framebuffer_iface *stfb, + enum st_attachment_type statt) +{ + struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb); + + pipe_mutex_lock(stwfb->fb->mutex); + + return stw_st_framebuffer_present_locked(&stwfb->base, statt); +} + +/** + * Create a framebuffer interface. + */ +struct st_framebuffer_iface * +stw_st_create_framebuffer(struct stw_framebuffer *fb) +{ + struct stw_st_framebuffer *stwfb; + + stwfb = CALLOC_STRUCT(stw_st_framebuffer); + if (!stwfb) + return NULL; + + stwfb->fb = fb; + stwfb->stvis = fb->pfi->stvis; + + stwfb->base.visual = &stwfb->stvis; + stwfb->base.flush_front = stw_st_framebuffer_flush_front; + stwfb->base.validate = stw_st_framebuffer_validate; + + return &stwfb->base; +} + +/** + * Destroy a framebuffer interface. + */ +void +stw_st_destroy_framebuffer_locked(struct st_framebuffer_iface *stfb) +{ + struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb); + int i; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_resource_reference(&stwfb->textures[i], NULL); + + FREE(stwfb); +} + +/** + * Swap the buffers of the given framebuffer. + */ +boolean +stw_st_swap_framebuffer_locked(struct st_framebuffer_iface *stfb) +{ + struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb); + unsigned front = ST_ATTACHMENT_FRONT_LEFT, back = ST_ATTACHMENT_BACK_LEFT; + struct pipe_resource *ptex; + unsigned mask; + + /* swap the textures */ + ptex = stwfb->textures[front]; + stwfb->textures[front] = stwfb->textures[back]; + stwfb->textures[back] = ptex; + + /* convert to mask */ + front = 1 << front; + back = 1 << back; + + /* swap the bits in mask */ + mask = stwfb->texture_mask & ~(front | back); + if (stwfb->texture_mask & front) + mask |= back; + if (stwfb->texture_mask & back) + mask |= front; + stwfb->texture_mask = mask; + + front = ST_ATTACHMENT_FRONT_LEFT; + return stw_st_framebuffer_present_locked(&stwfb->base, front); +} + +/** + * Create an st_api of the state tracker. + */ +struct st_api * +stw_st_create_api(void) +{ + return st_gl_api_create(); +} diff --git a/src/gallium/state_trackers/wgl/stw_st.h b/src/gallium/state_trackers/wgl/stw_st.h new file mode 100644 index 0000000..23771d8 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_st.h @@ -0,0 +1,47 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * 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: + * Chia-I Wu + */ + +#ifndef STW_ST_H +#define STW_ST_H + +#include "state_tracker/st_api.h" + +struct stw_framebuffer; + +struct st_api * +stw_st_create_api(void); + +struct st_framebuffer_iface * +stw_st_create_framebuffer(struct stw_framebuffer *fb); + +void +stw_st_destroy_framebuffer_locked(struct st_framebuffer_iface *stfb); + +boolean +stw_st_swap_framebuffer_locked(struct st_framebuffer_iface *stfb); + +#endif /* STW_ST_H */ diff --git a/src/gallium/state_trackers/wgl/stw_tls.c b/src/gallium/state_trackers/wgl/stw_tls.c new file mode 100644 index 0000000..4bd6a92 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_tls.c @@ -0,0 +1,139 @@ +/************************************************************************** + * + * 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 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. + * + **************************************************************************/ + +#include + +#include "pipe/p_compiler.h" +#include "util/u_memory.h" +#include "stw_tls.h" + +static DWORD tlsIndex = TLS_OUT_OF_INDEXES; + +boolean +stw_tls_init(void) +{ + tlsIndex = TlsAlloc(); + if (tlsIndex == TLS_OUT_OF_INDEXES) { + return FALSE; + } + + return TRUE; +} + +static INLINE struct stw_tls_data * +stw_tls_data_create() +{ + struct stw_tls_data *data; + + data = CALLOC_STRUCT(stw_tls_data); + if (!data) + goto no_data; + + data->hCallWndProcHook = SetWindowsHookEx(WH_CALLWNDPROC, + stw_call_window_proc, + NULL, + GetCurrentThreadId()); + if(data->hCallWndProcHook == NULL) + goto no_hook; + + TlsSetValue(tlsIndex, data); + + return data; + +no_hook: + FREE(data); +no_data: + return NULL; +} + +boolean +stw_tls_init_thread(void) +{ + struct stw_tls_data *data; + + if (tlsIndex == TLS_OUT_OF_INDEXES) { + return FALSE; + } + + data = stw_tls_data_create(); + if(!data) + return FALSE; + + return TRUE; +} + +void +stw_tls_cleanup_thread(void) +{ + struct stw_tls_data *data; + + if (tlsIndex == TLS_OUT_OF_INDEXES) { + return; + } + + data = (struct stw_tls_data *) TlsGetValue(tlsIndex); + if(data) { + TlsSetValue(tlsIndex, NULL); + + if(data->hCallWndProcHook) { + UnhookWindowsHookEx(data->hCallWndProcHook); + data->hCallWndProcHook = NULL; + } + + FREE(data); + } +} + +void +stw_tls_cleanup(void) +{ + if (tlsIndex != TLS_OUT_OF_INDEXES) { + TlsFree(tlsIndex); + tlsIndex = TLS_OUT_OF_INDEXES; + } +} + +struct stw_tls_data * +stw_tls_get_data(void) +{ + struct stw_tls_data *data; + + if (tlsIndex == TLS_OUT_OF_INDEXES) { + return NULL; + } + + data = (struct stw_tls_data *) TlsGetValue(tlsIndex); + if(!data) { + /* DllMain is called with DLL_THREAD_ATTACH only by threads created after + * the DLL is loaded by the process */ + data = stw_tls_data_create(); + if(!data) + return NULL; + } + + return data; +} diff --git a/src/gallium/state_trackers/wgl/stw_tls.h b/src/gallium/state_trackers/wgl/stw_tls.h new file mode 100644 index 0000000..fbf8b1c --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_tls.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 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. + * + **************************************************************************/ + +#ifndef STW_TLS_H +#define STW_TLS_H + +#include + +struct stw_tls_data +{ + HHOOK hCallWndProcHook; +}; + +boolean +stw_tls_init(void); + +boolean +stw_tls_init_thread(void); + +void +stw_tls_cleanup_thread(void); + +void +stw_tls_cleanup(void); + +struct stw_tls_data * +stw_tls_get_data(void); + +LRESULT CALLBACK +stw_call_window_proc( + int nCode, + WPARAM wParam, + LPARAM lParam ); + +#endif /* STW_TLS_H */ diff --git a/src/gallium/state_trackers/wgl/stw_wgl.c b/src/gallium/state_trackers/wgl/stw_wgl.c new file mode 100644 index 0000000..5fbb7bf --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_wgl.c @@ -0,0 +1,321 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include + +#include "util/u_debug.h" +#include "stw_icd.h" +#include "stw_context.h" +#include "stw_pixelformat.h" +#include "stw_wgl.h" + + +WINGDIAPI BOOL APIENTRY +wglCopyContext( + HGLRC hglrcSrc, + HGLRC hglrcDst, + UINT mask ) +{ + return DrvCopyContext( (DHGLRC)(UINT_PTR)hglrcSrc, + (DHGLRC)(UINT_PTR)hglrcDst, + mask ); +} + +WINGDIAPI HGLRC APIENTRY +wglCreateContext( + HDC hdc ) +{ + return (HGLRC) DrvCreateContext(hdc); +} + +WINGDIAPI HGLRC APIENTRY +wglCreateLayerContext( + HDC hdc, + int iLayerPlane ) +{ + return (HGLRC) DrvCreateLayerContext( hdc, iLayerPlane ); +} + +WINGDIAPI BOOL APIENTRY +wglDeleteContext( + HGLRC hglrc ) +{ + return DrvDeleteContext((DHGLRC)(UINT_PTR)hglrc ); +} + + +WINGDIAPI HGLRC APIENTRY +wglGetCurrentContext( VOID ) +{ + return (HGLRC)(UINT_PTR)stw_get_current_context(); +} + +WINGDIAPI HDC APIENTRY +wglGetCurrentDC( VOID ) +{ + return stw_get_current_dc(); +} + +WINGDIAPI BOOL APIENTRY +wglMakeCurrent( + HDC hdc, + HGLRC hglrc ) +{ + return DrvSetContext( hdc, (DHGLRC)(UINT_PTR)hglrc, NULL ) ? TRUE : FALSE; +} + + +WINGDIAPI BOOL APIENTRY +wglSwapBuffers( + HDC hdc ) +{ + return DrvSwapBuffers( hdc ); +} + + +WINGDIAPI DWORD WINAPI +wglSwapMultipleBuffers(UINT n, + CONST WGLSWAP *ps) +{ + UINT i; + + for (i =0; i < n; ++i) + wglSwapBuffers(ps->hdc); + + return 0; +} + + +WINGDIAPI BOOL APIENTRY +wglSwapLayerBuffers( + HDC hdc, + UINT fuPlanes ) +{ + return DrvSwapLayerBuffers( hdc, fuPlanes ); +} + +WINGDIAPI PROC APIENTRY +wglGetProcAddress( + LPCSTR lpszProc ) +{ + return DrvGetProcAddress( lpszProc ); +} + + +WINGDIAPI int APIENTRY +wglChoosePixelFormat( + HDC hdc, + CONST PIXELFORMATDESCRIPTOR *ppfd ) +{ + if (ppfd->nSize != sizeof( PIXELFORMATDESCRIPTOR ) || ppfd->nVersion != 1) + return 0; + if (ppfd->iPixelType != PFD_TYPE_RGBA) + return 0; + if (!(ppfd->dwFlags & PFD_DRAW_TO_WINDOW)) + return 0; + if (!(ppfd->dwFlags & PFD_SUPPORT_OPENGL)) + return 0; + if (ppfd->dwFlags & PFD_DRAW_TO_BITMAP) + return 0; + if (ppfd->dwFlags & PFD_SUPPORT_GDI) + return 0; + if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE) && (ppfd->dwFlags & PFD_STEREO)) + return 0; + + return stw_pixelformat_choose( hdc, ppfd ); +} + +WINGDIAPI int APIENTRY +wglDescribePixelFormat( + HDC hdc, + int iPixelFormat, + UINT nBytes, + LPPIXELFORMATDESCRIPTOR ppfd ) +{ + return DrvDescribePixelFormat( hdc, iPixelFormat, nBytes, ppfd ); +} + +WINGDIAPI int APIENTRY +wglGetPixelFormat( + HDC hdc ) +{ + return stw_pixelformat_get( hdc ); +} + +WINGDIAPI BOOL APIENTRY +wglSetPixelFormat( + HDC hdc, + int iPixelFormat, + const PIXELFORMATDESCRIPTOR *ppfd ) +{ + if (ppfd->nSize != sizeof( PIXELFORMATDESCRIPTOR )) + return FALSE; + + return DrvSetPixelFormat( hdc, iPixelFormat ); +} + + +WINGDIAPI BOOL APIENTRY +wglUseFontBitmapsA( + HDC hdc, + DWORD first, + DWORD count, + DWORD listBase ) +{ + (void) hdc; + (void) first; + (void) count; + (void) listBase; + + assert( 0 ); + + return FALSE; +} + +WINGDIAPI BOOL APIENTRY +wglShareLists( + HGLRC hglrc1, + HGLRC hglrc2 ) +{ + return DrvShareLists((DHGLRC)(UINT_PTR)hglrc1, + (DHGLRC)(UINT_PTR)hglrc2); +} + +WINGDIAPI BOOL APIENTRY +wglUseFontBitmapsW( + HDC hdc, + DWORD first, + DWORD count, + DWORD listBase ) +{ + (void) hdc; + (void) first; + (void) count; + (void) listBase; + + assert( 0 ); + + return FALSE; +} + +WINGDIAPI BOOL APIENTRY +wglUseFontOutlinesA( + HDC hdc, + DWORD first, + DWORD count, + DWORD listBase, + FLOAT deviation, + FLOAT extrusion, + int format, + LPGLYPHMETRICSFLOAT lpgmf ) +{ + (void) hdc; + (void) first; + (void) count; + (void) listBase; + (void) deviation; + (void) extrusion; + (void) format; + (void) lpgmf; + + assert( 0 ); + + return FALSE; +} + +WINGDIAPI BOOL APIENTRY +wglUseFontOutlinesW( + HDC hdc, + DWORD first, + DWORD count, + DWORD listBase, + FLOAT deviation, + FLOAT extrusion, + int format, + LPGLYPHMETRICSFLOAT lpgmf ) +{ + (void) hdc; + (void) first; + (void) count; + (void) listBase; + (void) deviation; + (void) extrusion; + (void) format; + (void) lpgmf; + + assert( 0 ); + + return FALSE; +} + +WINGDIAPI BOOL APIENTRY +wglDescribeLayerPlane( + HDC hdc, + int iPixelFormat, + int iLayerPlane, + UINT nBytes, + LPLAYERPLANEDESCRIPTOR plpd ) +{ + return DrvDescribeLayerPlane(hdc, iPixelFormat, iLayerPlane, nBytes, plpd); +} + +WINGDIAPI int APIENTRY +wglSetLayerPaletteEntries( + HDC hdc, + int iLayerPlane, + int iStart, + int cEntries, + CONST COLORREF *pcr ) +{ + return DrvSetLayerPaletteEntries(hdc, iLayerPlane, iStart, cEntries, pcr); +} + +WINGDIAPI int APIENTRY +wglGetLayerPaletteEntries( + HDC hdc, + int iLayerPlane, + int iStart, + int cEntries, + COLORREF *pcr ) +{ + return DrvGetLayerPaletteEntries(hdc, iLayerPlane, iStart, cEntries, pcr); +} + +WINGDIAPI BOOL APIENTRY +wglRealizeLayerPalette( + HDC hdc, + int iLayerPlane, + BOOL bRealize ) +{ + (void) hdc; + (void) iLayerPlane; + (void) bRealize; + + assert( 0 ); + + return FALSE; +} diff --git a/src/gallium/state_trackers/wgl/stw_wgl.h b/src/gallium/state_trackers/wgl/stw_wgl.h new file mode 100644 index 0000000..57baaf0 --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_wgl.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, 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 STW_WGL_H_ +#define STW_WGL_H_ + + +#include + +#include + + +/* + * Undeclared APIs exported by opengl32.dll + */ + +WINGDIAPI BOOL WINAPI +wglSwapBuffers(HDC hdc); + +WINGDIAPI int WINAPI +wglChoosePixelFormat(HDC hdc, + CONST PIXELFORMATDESCRIPTOR *ppfd); + +WINGDIAPI int WINAPI +wglDescribePixelFormat(HDC hdc, + int iPixelFormat, + UINT nBytes, + LPPIXELFORMATDESCRIPTOR ppfd); + +WINGDIAPI int WINAPI +wglGetPixelFormat(HDC hdc); + +WINGDIAPI BOOL WINAPI +wglSetPixelFormat(HDC hdc, + int iPixelFormat, + CONST PIXELFORMATDESCRIPTOR *ppfd); + +#if defined(__MINGW32__) || (WINVER < 0x0500) + +typedef struct _WGLSWAP +{ + HDC hdc; + UINT uiFlags; +} WGLSWAP; + +#define WGL_SWAPMULTIPLE_MAX 16 + +WINGDIAPI DWORD WINAPI +wglSwapMultipleBuffers(UINT n, + CONST WGLSWAP *ps); + +#endif + + +#endif /* STW_WGL_H_ */ diff --git a/src/gallium/state_trackers/wgl/stw_winsys.h b/src/gallium/state_trackers/wgl/stw_winsys.h new file mode 100644 index 0000000..397065f --- /dev/null +++ b/src/gallium/state_trackers/wgl/stw_winsys.h @@ -0,0 +1,107 @@ +/************************************************************************** + * + * 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, 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 STW_WINSYS_H +#define STW_WINSYS_H + +#include /* for HDC */ + +#include "pipe/p_compiler.h" + +struct pipe_screen; +struct pipe_context; +struct pipe_resource; + +struct stw_shared_surface; + +struct stw_winsys +{ + struct pipe_screen * + (*create_screen)( void ); + + /* XXX is it actually possible to have non-zero level/layer ??? */ + /** + * Present the color buffer to the window associated with the device context. + */ + void + (*present)( struct pipe_screen *screen, + struct pipe_resource *res, + HDC hDC ); + + /** + * Locally unique identifier (LUID) of the graphics adapter. + * + * @sa GLCBPRESENTBUFFERSDATA::AdapterLuid; + */ + boolean + (*get_adapter_luid)( struct pipe_screen *screen, + LUID *pAdapterLuid ); + + /** + * Open a shared surface (optional). + * + * @sa GLCBPRESENTBUFFERSDATA::hSharedSurface; + */ + struct stw_shared_surface * + (*shared_surface_open)(struct pipe_screen *screen, + HANDLE hSharedSurface); + + /** + * Close a shared surface (optional). + */ + void + (*shared_surface_close)(struct pipe_screen *screen, + struct stw_shared_surface *surface); + + /** + * Compose into a shared (optional). + * + * Blit the color buffer into a shared surface. + * + * @sa GLPRESENTBUFFERSDATA::PresentHistoryToken. + */ + void + (*compose)( struct pipe_screen *screen, + struct pipe_resource *res, + struct stw_shared_surface *dest, + LPCRECT pRect, + ULONGLONG PresentHistoryToken ); +}; + +boolean +stw_init(const struct stw_winsys *stw_winsys); + +boolean +stw_init_thread(void); + +void +stw_cleanup_thread(void); + +void +stw_cleanup(void); + +#endif /* STW_WINSYS_H */ diff --git a/src/gallium/state_trackers/xorg/Makefile b/src/gallium/state_trackers/xorg/Makefile new file mode 100644 index 0000000..7a44d28 --- /dev/null +++ b/src/gallium/state_trackers/xorg/Makefile @@ -0,0 +1,23 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = xorgtracker + +LIBRARY_INCLUDES = \ + -DHAVE_CONFIG_H \ + $(shell pkg-config xextproto --atleast-version=7.0.99.1 \ + && echo "-DHAVE_XEXTPROTO_71") \ + $(shell pkg-config libkms --atleast-version=1.0 \ + && echo "-DHAVE_LIBKMS") \ + $(shell pkg-config libkms --silence-errors --cflags-only-I) \ + $(shell pkg-config --cflags-only-I pixman-1 xorg-server libdrm xproto dri2proto) \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/include \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/mesa/drivers/dri/common \ + -I$(TOP)/src/mesa/main + +C_SOURCES = $(wildcard ./*.c) + +include ../../Makefile.template diff --git a/src/gallium/state_trackers/xorg/SConscript b/src/gallium/state_trackers/xorg/SConscript new file mode 100644 index 0000000..1931569 --- /dev/null +++ b/src/gallium/state_trackers/xorg/SConscript @@ -0,0 +1,40 @@ +####################################################################### +# SConscript for xorg state_tracker + +Import('*') + +env = env.Clone() + +env.Append(CPPPATH = [ + '#/src/mesa', +]) + +env.ParseConfig('pkg-config --cflags --libs libdrm xorg-server') + +if env['kms']: + env.Append(CPPDEFINES = ['HAVE_LIBKMS']) + +conf = env.Configure() + +if conf.CheckHeader('X11/extensions/dpmsconst.h'): + env.Append(CPPDEFINES = [('HAVE_XEXTPROTO_71', '1')]) + +conf.Finish() + +sources = [ + 'xorg_composite.c', + 'xorg_crtc.c', + 'xorg_dri2.c', + 'xorg_driver.c', + 'xorg_exa.c', + 'xorg_exa_tgsi.c', + 'xorg_output.c', + 'xorg_renderer.c', + 'xorg_xv.c', +] + +st_xorg = env.ConvenienceLibrary( + target = 'st_xorg', + source = sources, +) +Export('st_xorg') diff --git a/src/gallium/state_trackers/xorg/xorg_composite.c b/src/gallium/state_trackers/xorg/xorg_composite.c new file mode 100644 index 0000000..d4dc84a --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_composite.c @@ -0,0 +1,583 @@ +#include "xorg_composite.h" + +#include "xorg_renderer.h" +#include "xorg_exa_tgsi.h" + +#include "cso_cache/cso_context.h" +#include "util/u_sampler.h" + + +/*XXX also in Xrender.h but the including it here breaks compilition */ +#define XFixedToDouble(f) (((double) (f)) / 65536.) + +struct xorg_composite_blend { + int op : 8; + + unsigned alpha_dst : 4; + unsigned alpha_src : 4; + + unsigned rgb_src : 8; /**< PIPE_BLENDFACTOR_x */ + unsigned rgb_dst : 8; /**< PIPE_BLENDFACTOR_x */ +}; + +#define BLEND_OP_OVER 3 +static const struct xorg_composite_blend xorg_blends[] = { + { PictOpClear, + 0, 0, PIPE_BLENDFACTOR_ZERO, PIPE_BLENDFACTOR_ZERO}, + { PictOpSrc, + 0, 0, PIPE_BLENDFACTOR_ONE, PIPE_BLENDFACTOR_ZERO}, + { PictOpDst, + 0, 0, PIPE_BLENDFACTOR_ZERO, PIPE_BLENDFACTOR_ONE}, + { PictOpOver, + 0, 1, PIPE_BLENDFACTOR_ONE, PIPE_BLENDFACTOR_INV_SRC_ALPHA}, + { PictOpOverReverse, + 1, 0, PIPE_BLENDFACTOR_INV_DST_ALPHA, PIPE_BLENDFACTOR_ONE}, + { PictOpIn, + 1, 0, PIPE_BLENDFACTOR_DST_ALPHA, PIPE_BLENDFACTOR_ZERO}, + { PictOpInReverse, + 0, 1, PIPE_BLENDFACTOR_ZERO, PIPE_BLENDFACTOR_SRC_ALPHA}, + { PictOpOut, + 1, 0, PIPE_BLENDFACTOR_INV_DST_ALPHA, PIPE_BLENDFACTOR_ZERO}, + { PictOpOutReverse, + 0, 1, PIPE_BLENDFACTOR_ZERO, PIPE_BLENDFACTOR_INV_SRC_ALPHA}, + { PictOpAtop, + 1, 1, PIPE_BLENDFACTOR_DST_ALPHA, PIPE_BLENDFACTOR_INV_SRC_ALPHA}, + { PictOpAtopReverse, + 1, 1, PIPE_BLENDFACTOR_INV_DST_ALPHA, PIPE_BLENDFACTOR_SRC_ALPHA}, + { PictOpXor, + 1, 1, PIPE_BLENDFACTOR_INV_DST_ALPHA, PIPE_BLENDFACTOR_INV_SRC_ALPHA}, + { PictOpAdd, + 0, 0, PIPE_BLENDFACTOR_ONE, PIPE_BLENDFACTOR_ONE}, +}; + + +static INLINE void +pixel_to_float4(Pixel pixel, float *color) +{ + CARD32 r, g, b, a; + + a = (pixel >> 24) & 0xff; + r = (pixel >> 16) & 0xff; + g = (pixel >> 8) & 0xff; + b = (pixel >> 0) & 0xff; + color[0] = ((float)r) / 255.; + color[1] = ((float)g) / 255.; + color[2] = ((float)b) / 255.; + color[3] = ((float)a) / 255.; +} + +static boolean +blend_for_op(struct xorg_composite_blend *blend, + int op, PicturePtr pSrcPicture, PicturePtr pMaskPicture, + PicturePtr pDstPicture) +{ + const int num_blends = + sizeof(xorg_blends)/sizeof(struct xorg_composite_blend); + int i; + boolean supported = FALSE; + + /* our default in case something goes wrong */ + *blend = xorg_blends[BLEND_OP_OVER]; + + for (i = 0; i < num_blends; ++i) { + if (xorg_blends[i].op == op) { + *blend = xorg_blends[i]; + supported = TRUE; + } + } + + /* If there's no dst alpha channel, adjust the blend op so that we'll treat + * it as always 1. */ + if (pDstPicture && + PICT_FORMAT_A(pDstPicture->format) == 0 && blend->alpha_dst) { + if (blend->rgb_src == PIPE_BLENDFACTOR_DST_ALPHA) + blend->rgb_src = PIPE_BLENDFACTOR_ONE; + else if (blend->rgb_src == PIPE_BLENDFACTOR_INV_DST_ALPHA) + blend->rgb_src = PIPE_BLENDFACTOR_ZERO; + } + + /* If the source alpha is being used, then we should only be in a case where + * the source blend factor is 0, and the source blend value is the mask + * channels multiplied by the source picture's alpha. */ + if (pMaskPicture && pMaskPicture->componentAlpha && + PICT_FORMAT_RGB(pMaskPicture->format) && blend->alpha_src) { + if (blend->rgb_dst == PIPE_BLENDFACTOR_SRC_ALPHA) { + blend->rgb_dst = PIPE_BLENDFACTOR_SRC_COLOR; + } else if (blend->rgb_dst == PIPE_BLENDFACTOR_INV_SRC_ALPHA) { + blend->rgb_dst = PIPE_BLENDFACTOR_INV_SRC_COLOR; + } + } + + return supported; +} + +static INLINE int +render_repeat_to_gallium(int mode) +{ + switch(mode) { + case RepeatNone: + return PIPE_TEX_WRAP_CLAMP_TO_BORDER; + case RepeatNormal: + return PIPE_TEX_WRAP_REPEAT; + case RepeatReflect: + return PIPE_TEX_WRAP_MIRROR_REPEAT; + case RepeatPad: + return PIPE_TEX_WRAP_CLAMP_TO_EDGE; + default: + debug_printf("Unsupported repeat mode\n"); + } + return PIPE_TEX_WRAP_REPEAT; +} + +static INLINE boolean +render_filter_to_gallium(int xrender_filter, int *out_filter) +{ + + switch (xrender_filter) { + case PictFilterNearest: + *out_filter = PIPE_TEX_FILTER_NEAREST; + break; + case PictFilterBilinear: + *out_filter = PIPE_TEX_FILTER_LINEAR; + break; + case PictFilterFast: + *out_filter = PIPE_TEX_FILTER_NEAREST; + break; + case PictFilterGood: + *out_filter = PIPE_TEX_FILTER_LINEAR; + break; + case PictFilterBest: + *out_filter = PIPE_TEX_FILTER_LINEAR; + break; + case PictFilterConvolution: + *out_filter = PIPE_TEX_FILTER_NEAREST; + return FALSE; + default: + debug_printf("Unknown xrender filter\n"); + *out_filter = PIPE_TEX_FILTER_NEAREST; + return FALSE; + } + + return TRUE; +} + +static boolean is_filter_accelerated(PicturePtr pic) +{ + int filter; + if (pic && !render_filter_to_gallium(pic->filter, &filter)) + return FALSE; + return TRUE; +} + +boolean xorg_composite_accelerated(int op, + PicturePtr pSrcPicture, + PicturePtr pMaskPicture, + PicturePtr pDstPicture) +{ + ScreenPtr pScreen = pDstPicture->pDrawable->pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct xorg_composite_blend blend; + + if (!is_filter_accelerated(pSrcPicture) || + !is_filter_accelerated(pMaskPicture)) { + XORG_FALLBACK("Unsupported Xrender filter"); + } + + if (pSrcPicture->pSourcePict) { + if (pSrcPicture->pSourcePict->type != SourcePictTypeSolidFill) + XORG_FALLBACK("Gradients not enabled (haven't been well tested)"); + } + + if (blend_for_op(&blend, op, + pSrcPicture, pMaskPicture, pDstPicture)) { + /* Check for component alpha */ + if (pMaskPicture && pMaskPicture->componentAlpha && + PICT_FORMAT_RGB(pMaskPicture->format)) { + if (blend.alpha_src && blend.rgb_src != PIPE_BLENDFACTOR_ZERO) { + XORG_FALLBACK("Component alpha not supported with source " + "alpha and source value blending. (op=%d)", + op); + } + } + + return TRUE; + } + XORG_FALLBACK("Unsupported composition operation = %d", op); +} + +static void +bind_blend_state(struct exa_context *exa, int op, + PicturePtr pSrcPicture, + PicturePtr pMaskPicture, + PicturePtr pDstPicture) +{ + struct xorg_composite_blend blend_opt; + struct pipe_blend_state blend; + + blend_for_op(&blend_opt, op, pSrcPicture, pMaskPicture, pDstPicture); + + memset(&blend, 0, sizeof(struct pipe_blend_state)); + blend.rt[0].blend_enable = 1; + blend.rt[0].colormask = PIPE_MASK_RGBA; + + blend.rt[0].rgb_src_factor = blend_opt.rgb_src; + blend.rt[0].alpha_src_factor = blend_opt.rgb_src; + blend.rt[0].rgb_dst_factor = blend_opt.rgb_dst; + blend.rt[0].alpha_dst_factor = blend_opt.rgb_dst; + + cso_set_blend(exa->renderer->cso, &blend); +} + +static unsigned +picture_format_fixups(struct exa_pixmap_priv *pSrc, PicturePtr pSrcPicture, boolean mask, + PicturePtr pDstPicture) +{ + boolean set_alpha = FALSE; + boolean swizzle = FALSE; + unsigned ret = 0; + + if (pSrc->picture_format == pSrcPicture->format) { + if (pSrc->picture_format == PICT_a8) { + if (mask) + return FS_MASK_LUMINANCE; + else if (pDstPicture->format != PICT_a8) { + /* if both dst and src are luminance then + * we don't want to swizzle the alpha (X) of the + * source into W component of the dst because + * it will break our destination */ + return FS_SRC_LUMINANCE; + } + } + return 0; + } + + if (pSrc->picture_format != PICT_a8r8g8b8) { + assert(!"can not handle formats"); + return 0; + } + + /* pSrc->picture_format == PICT_a8r8g8b8 */ + switch (pSrcPicture->format) { + case PICT_x8b8g8r8: + case PICT_b8g8r8: + set_alpha = TRUE; /* fall trough */ + case PICT_a8b8g8r8: + swizzle = TRUE; + break; + case PICT_x8r8g8b8: + case PICT_r8g8b8: + set_alpha = TRUE; /* fall through */ + case PICT_a8r8g8b8: + break; +#ifdef PICT_TYPE_BGRA + case PICT_b8g8r8a8: + case PICT_b8g8r8x8: + case PICT_a2r10g10b10: + case PICT_x2r10g10b10: + case PICT_a2b10g10r10: + case PICT_x2b10g10r10: +#endif + default: + assert(!"can not handle formats"); + return 0; + } + + if (set_alpha) + ret |= mask ? FS_MASK_SET_ALPHA : FS_SRC_SET_ALPHA; + if (swizzle) + ret |= mask ? FS_MASK_SWIZZLE_RGB : FS_SRC_SWIZZLE_RGB; + + return ret; +} + +static void +bind_shaders(struct exa_context *exa, int op, + PicturePtr pSrcPicture, PicturePtr pMaskPicture, PicturePtr pDstPicture, + struct exa_pixmap_priv *pSrc, struct exa_pixmap_priv *pMask) +{ + unsigned vs_traits = 0, fs_traits = 0; + struct xorg_shader shader; + + exa->has_solid_color = FALSE; + + if (pSrcPicture) { + if (pSrcPicture->repeatType == RepeatNone && pSrcPicture->transform) + fs_traits |= FS_SRC_REPEAT_NONE; + + if (pSrcPicture->pSourcePict) { + if (pSrcPicture->pSourcePict->type == SourcePictTypeSolidFill) { + fs_traits |= FS_SOLID_FILL; + vs_traits |= VS_SOLID_FILL; + debug_assert(pSrcPicture->format == PICT_a8r8g8b8); + pixel_to_float4(pSrcPicture->pSourcePict->solidFill.color, + exa->solid_color); + exa->has_solid_color = TRUE; + } else { + debug_assert("!gradients not supported"); + } + } else { + fs_traits |= FS_COMPOSITE; + vs_traits |= VS_COMPOSITE; + } + + fs_traits |= picture_format_fixups(pSrc, pSrcPicture, FALSE, pDstPicture); + } + + if (pMaskPicture) { + vs_traits |= VS_MASK; + fs_traits |= FS_MASK; + if (pMaskPicture->repeatType == RepeatNone && pMaskPicture->transform) + fs_traits |= FS_MASK_REPEAT_NONE; + if (pMaskPicture->componentAlpha) { + struct xorg_composite_blend blend; + blend_for_op(&blend, op, + pSrcPicture, pMaskPicture, NULL); + if (blend.alpha_src) { + fs_traits |= FS_CA_SRCALPHA; + } else + fs_traits |= FS_CA_FULL; + } + + fs_traits |= picture_format_fixups(pMask, pMaskPicture, TRUE, pDstPicture); + } + + shader = xorg_shaders_get(exa->renderer->shaders, vs_traits, fs_traits); + cso_set_vertex_shader_handle(exa->renderer->cso, shader.vs); + cso_set_fragment_shader_handle(exa->renderer->cso, shader.fs); +} + +static void +bind_samplers(struct exa_context *exa, int op, + PicturePtr pSrcPicture, PicturePtr pMaskPicture, + PicturePtr pDstPicture, + struct exa_pixmap_priv *pSrc, + struct exa_pixmap_priv *pMask, + struct exa_pixmap_priv *pDst) +{ + struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_state src_sampler, mask_sampler; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *src_view; + struct pipe_context *pipe = exa->pipe; + + exa->num_bound_samplers = 0; + + memset(&src_sampler, 0, sizeof(struct pipe_sampler_state)); + memset(&mask_sampler, 0, sizeof(struct pipe_sampler_state)); + + if (pSrcPicture && pSrc) { + if (exa->has_solid_color) { + debug_assert(!"solid color with textures"); + samplers[0] = NULL; + pipe_sampler_view_reference(&exa->bound_sampler_views[0], NULL); + } else { + unsigned src_wrap = render_repeat_to_gallium( + pSrcPicture->repeatType); + int filter; + + render_filter_to_gallium(pSrcPicture->filter, &filter); + + src_sampler.wrap_s = src_wrap; + src_sampler.wrap_t = src_wrap; + src_sampler.min_img_filter = filter; + src_sampler.mag_img_filter = filter; + src_sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; + src_sampler.normalized_coords = 1; + samplers[0] = &src_sampler; + exa->num_bound_samplers = 1; + u_sampler_view_default_template(&view_templ, + pSrc->tex, + pSrc->tex->format); + src_view = pipe->create_sampler_view(pipe, pSrc->tex, &view_templ); + pipe_sampler_view_reference(&exa->bound_sampler_views[0], NULL); + exa->bound_sampler_views[0] = src_view; + } + } + + if (pMaskPicture && pMask) { + unsigned mask_wrap = render_repeat_to_gallium( + pMaskPicture->repeatType); + int filter; + + render_filter_to_gallium(pMaskPicture->filter, &filter); + + mask_sampler.wrap_s = mask_wrap; + mask_sampler.wrap_t = mask_wrap; + mask_sampler.min_img_filter = filter; + mask_sampler.mag_img_filter = filter; + src_sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; + mask_sampler.normalized_coords = 1; + samplers[1] = &mask_sampler; + exa->num_bound_samplers = 2; + u_sampler_view_default_template(&view_templ, + pMask->tex, + pMask->tex->format); + src_view = pipe->create_sampler_view(pipe, pMask->tex, &view_templ); + pipe_sampler_view_reference(&exa->bound_sampler_views[1], NULL); + exa->bound_sampler_views[1] = src_view; + } + + cso_set_samplers(exa->renderer->cso, exa->num_bound_samplers, + (const struct pipe_sampler_state **)samplers); + cso_set_fragment_sampler_views(exa->renderer->cso, exa->num_bound_samplers, + exa->bound_sampler_views); +} + + + +static INLINE boolean matrix_from_pict_transform(PictTransform *trans, float *matrix) +{ + if (!trans) + return FALSE; + + matrix[0] = XFixedToDouble(trans->matrix[0][0]); + matrix[3] = XFixedToDouble(trans->matrix[0][1]); + matrix[6] = XFixedToDouble(trans->matrix[0][2]); + + matrix[1] = XFixedToDouble(trans->matrix[1][0]); + matrix[4] = XFixedToDouble(trans->matrix[1][1]); + matrix[7] = XFixedToDouble(trans->matrix[1][2]); + + matrix[2] = XFixedToDouble(trans->matrix[2][0]); + matrix[5] = XFixedToDouble(trans->matrix[2][1]); + matrix[8] = XFixedToDouble(trans->matrix[2][2]); + + return TRUE; +} + +static void +setup_transforms(struct exa_context *exa, + PicturePtr pSrcPicture, PicturePtr pMaskPicture) +{ + PictTransform *src_t = NULL; + PictTransform *mask_t = NULL; + + if (pSrcPicture) + src_t = pSrcPicture->transform; + if (pMaskPicture) + mask_t = pMaskPicture->transform; + + exa->transform.has_src = + matrix_from_pict_transform(src_t, exa->transform.src); + exa->transform.has_mask = + matrix_from_pict_transform(mask_t, exa->transform.mask); +} + +boolean xorg_composite_bind_state(struct exa_context *exa, + int op, + PicturePtr pSrcPicture, + PicturePtr pMaskPicture, + PicturePtr pDstPicture, + struct exa_pixmap_priv *pSrc, + struct exa_pixmap_priv *pMask, + struct exa_pixmap_priv *pDst) +{ + struct pipe_surface *dst_surf = xorg_gpu_surface(exa->pipe, pDst); + + renderer_bind_destination(exa->renderer, dst_surf, + pDst->width, + pDst->height); + + bind_blend_state(exa, op, pSrcPicture, pMaskPicture, pDstPicture); + bind_shaders(exa, op, pSrcPicture, pMaskPicture, pDstPicture, pSrc, pMask); + bind_samplers(exa, op, pSrcPicture, pMaskPicture, + pDstPicture, pSrc, pMask, pDst); + + setup_transforms(exa, pSrcPicture, pMaskPicture); + + if (exa->num_bound_samplers == 0 ) { /* solid fill */ + renderer_begin_solid(exa->renderer); + } else { + renderer_begin_textures(exa->renderer, + exa->num_bound_samplers); + } + + + pipe_surface_reference(&dst_surf, NULL); + return TRUE; +} + +void xorg_composite(struct exa_context *exa, + struct exa_pixmap_priv *dst, + int srcX, int srcY, int maskX, int maskY, + int dstX, int dstY, int width, int height) +{ + if (exa->num_bound_samplers == 0 ) { /* solid fill */ + renderer_solid(exa->renderer, + dstX, dstY, dstX + width, dstY + height, + exa->solid_color); + } else { + int pos[6] = {srcX, srcY, maskX, maskY, dstX, dstY}; + float *src_matrix = NULL; + float *mask_matrix = NULL; + + if (exa->transform.has_src) + src_matrix = exa->transform.src; + if (exa->transform.has_mask) + mask_matrix = exa->transform.mask; + + renderer_texture(exa->renderer, + pos, width, height, + exa->bound_sampler_views, + exa->num_bound_samplers, + src_matrix, mask_matrix); + } +} + +boolean xorg_solid_bind_state(struct exa_context *exa, + struct exa_pixmap_priv *pixmap, + Pixel fg) +{ + struct pipe_surface *dst_surf = xorg_gpu_surface(exa->pipe, pixmap); + unsigned vs_traits, fs_traits; + struct xorg_shader shader; + + pixel_to_float4(fg, exa->solid_color); + exa->has_solid_color = TRUE; + +#if 0 + debug_printf("Color Pixel=(%d, %d, %d, %d), RGBA=(%f, %f, %f, %f)\n", + (fg >> 24) & 0xff, (fg >> 16) & 0xff, + (fg >> 8) & 0xff, (fg >> 0) & 0xff, + exa->solid_color[0], exa->solid_color[1], + exa->solid_color[2], exa->solid_color[3]); +#endif + + vs_traits = VS_SOLID_FILL; + fs_traits = FS_SOLID_FILL; + + renderer_bind_destination(exa->renderer, dst_surf, + pixmap->width, pixmap->height); + bind_blend_state(exa, PictOpSrc, NULL, NULL, NULL); + cso_set_samplers(exa->renderer->cso, 0, NULL); + cso_set_fragment_sampler_views(exa->renderer->cso, 0, NULL); + + shader = xorg_shaders_get(exa->renderer->shaders, vs_traits, fs_traits); + cso_set_vertex_shader_handle(exa->renderer->cso, shader.vs); + cso_set_fragment_shader_handle(exa->renderer->cso, shader.fs); + + renderer_begin_solid(exa->renderer); + + pipe_surface_reference(&dst_surf, NULL); + return TRUE; +} + +void xorg_solid(struct exa_context *exa, + struct exa_pixmap_priv *pixmap, + int x0, int y0, int x1, int y1) +{ + renderer_solid(exa->renderer, + x0, y0, x1, y1, exa->solid_color); +} + +void +xorg_composite_done(struct exa_context *exa) +{ + renderer_draw_flush(exa->renderer); + + exa->transform.has_src = FALSE; + exa->transform.has_mask = FALSE; + exa->has_solid_color = FALSE; + exa->num_bound_samplers = 0; +} diff --git a/src/gallium/state_trackers/xorg/xorg_composite.h b/src/gallium/state_trackers/xorg/xorg_composite.h new file mode 100644 index 0000000..ec71ebf --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_composite.h @@ -0,0 +1,36 @@ +#ifndef XORG_COMPOSITE_H +#define XORG_COMPOSITE_H + +#include "xorg_exa.h" + +boolean xorg_composite_accelerated(int op, + PicturePtr pSrcPicture, + PicturePtr pMaskPicture, + PicturePtr pDstPicture); + +boolean xorg_composite_bind_state(struct exa_context *exa, + int op, + PicturePtr pSrcPicture, + PicturePtr pMaskPicture, + PicturePtr pDstPicture, + struct exa_pixmap_priv *pSrc, + struct exa_pixmap_priv *pMask, + struct exa_pixmap_priv *pDst); + +void xorg_composite(struct exa_context *exa, + struct exa_pixmap_priv *dst, + int srcX, int srcY, int maskX, int maskY, + int dstX, int dstY, int width, int height); + +boolean xorg_solid_bind_state(struct exa_context *exa, + struct exa_pixmap_priv *pixmap, + Pixel fg); +void xorg_solid(struct exa_context *exa, + struct exa_pixmap_priv *pixmap, + int x0, int y0, int x1, int y1); + + +void +xorg_composite_done(struct exa_context *exa); + +#endif diff --git a/src/gallium/state_trackers/xorg/xorg_crtc.c b/src/gallium/state_trackers/xorg/xorg_crtc.c new file mode 100644 index 0000000..28e30e0 --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_crtc.c @@ -0,0 +1,428 @@ +/* + * 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 +#include +#include +#include +#include +#include + +#include "xorg-server.h" +#include +#include +#include +#include +#include "xorg_tracker.h" +#include "xf86Modes.h" + +#ifdef HAVE_XEXTPROTO_71 +#include +#else +#define DPMS_SERVER +#include +#endif + +#include "state_tracker/drm_driver.h" +#include "util/u_inlines.h" +#include "util/u_rect.h" + +#ifdef HAVE_LIBKMS +#include "libkms.h" +#endif + +struct crtc_private +{ + drmModeCrtcPtr drm_crtc; + + /* hwcursor */ + struct pipe_resource *cursor_tex; + struct kms_bo *cursor_bo; + + unsigned cursor_handle; +}; + +static void +crtc_dpms(xf86CrtcPtr crtc, int mode) +{ + /* ScrnInfoPtr pScrn = crtc->scrn; */ + + switch (mode) { + case DPMSModeOn: + case DPMSModeStandby: + case DPMSModeSuspend: + break; + case DPMSModeOff: + break; + } +} + +static Bool +crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode, + Rotation rotation, int x, int y) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); + modesettingPtr ms = modesettingPTR(crtc->scrn); + xf86OutputPtr output = NULL; + struct crtc_private *crtcp = crtc->driver_private; + drmModeCrtcPtr drm_crtc = crtcp->drm_crtc; + drmModeModeInfo drm_mode; + int i, ret; + unsigned int connector_id; + + for (i = 0; i < config->num_output; output = NULL, i++) { + output = config->output[i]; + + if (output->crtc == crtc) + break; + } + + if (!output) + return FALSE; + + connector_id = xorg_output_get_id(output); + + drm_mode.clock = mode->Clock; + drm_mode.hdisplay = mode->HDisplay; + drm_mode.hsync_start = mode->HSyncStart; + drm_mode.hsync_end = mode->HSyncEnd; + drm_mode.htotal = mode->HTotal; + drm_mode.vdisplay = mode->VDisplay; + drm_mode.vsync_start = mode->VSyncStart; + drm_mode.vsync_end = mode->VSyncEnd; + drm_mode.vtotal = mode->VTotal; + drm_mode.flags = mode->Flags; + drm_mode.hskew = mode->HSkew; + drm_mode.vscan = mode->VScan; + drm_mode.vrefresh = mode->VRefresh; + if (!mode->name) + xf86SetModeDefaultName(mode); + strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN - 1); + drm_mode.name[DRM_DISPLAY_MODE_LEN - 1] = '\0'; + + ret = drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y, + &connector_id, 1, &drm_mode); + + if (ret) + return FALSE; + + crtc->x = x; + crtc->y = y; + crtc->mode = *mode; + crtc->rotation = rotation; + + return TRUE; +} + +static void +crtc_gamma_set(xf86CrtcPtr crtc, CARD16 * red, CARD16 * green, CARD16 * blue, + int size) +{ + /* XXX: hockup */ +} + +#if 0 /* Implement and enable to enable rotation and reflection. */ +static void * +crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height) +{ + /* ScrnInfoPtr pScrn = crtc->scrn; */ + + return NULL; +} + +static PixmapPtr +crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height) +{ + /* ScrnInfoPtr pScrn = crtc->scrn; */ + + return NULL; +} + +static void +crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data) +{ + /* ScrnInfoPtr pScrn = crtc->scrn; */ +} + +#endif + +/* + * Cursor functions + */ + +static void +crtc_set_cursor_colors(xf86CrtcPtr crtc, int bg, int fg) +{ + /* XXX: See if this one is needed, as we only support ARGB cursors */ +} + +static void +crtc_set_cursor_position(xf86CrtcPtr crtc, int x, int y) +{ + modesettingPtr ms = modesettingPTR(crtc->scrn); + struct crtc_private *crtcp = crtc->driver_private; + + drmModeMoveCursor(ms->fd, crtcp->drm_crtc->crtc_id, x, y); +} + +static void +crtc_load_cursor_argb_ga3d(xf86CrtcPtr crtc, CARD32 * image) +{ + unsigned char *ptr; + modesettingPtr ms = modesettingPTR(crtc->scrn); + struct crtc_private *crtcp = crtc->driver_private; + struct pipe_transfer *transfer; + + if (!crtcp->cursor_tex) { + struct pipe_resource templat; + struct winsys_handle whandle; + + memset(&templat, 0, sizeof(templat)); + templat.bind |= PIPE_BIND_RENDER_TARGET; + templat.bind |= PIPE_BIND_SCANOUT; + templat.target = PIPE_TEXTURE_2D; + templat.last_level = 0; + templat.depth0 = 1; + templat.array_size = 1; + templat.format = PIPE_FORMAT_B8G8R8A8_UNORM; + templat.width0 = 64; + templat.height0 = 64; + + memset(&whandle, 0, sizeof(whandle)); + whandle.type = DRM_API_HANDLE_TYPE_KMS; + + crtcp->cursor_tex = ms->screen->resource_create(ms->screen, + &templat); + ms->screen->resource_get_handle(ms->screen, crtcp->cursor_tex, &whandle); + + crtcp->cursor_handle = whandle.handle; + } + + transfer = pipe_get_transfer(ms->ctx, crtcp->cursor_tex, + 0, 0, + PIPE_TRANSFER_WRITE, + 0, 0, 64, 64); + ptr = ms->ctx->transfer_map(ms->ctx, transfer); + util_copy_rect(ptr, crtcp->cursor_tex->format, + transfer->stride, 0, 0, + 64, 64, (void*)image, 64 * 4, 0, 0); + ms->ctx->transfer_unmap(ms->ctx, transfer); + ms->ctx->transfer_destroy(ms->ctx, transfer); + + if (crtc->cursor_shown) + drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, + crtcp->cursor_handle, 64, 64); +} + +#if HAVE_LIBKMS +static void +crtc_load_cursor_argb_kms(xf86CrtcPtr crtc, CARD32 * image) +{ + modesettingPtr ms = modesettingPTR(crtc->scrn); + struct crtc_private *crtcp = crtc->driver_private; + unsigned char *ptr; + + if (!crtcp->cursor_bo) { + unsigned attr[8]; + + attr[0] = KMS_BO_TYPE; +#ifdef KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8 + attr[1] = KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8; +#else + attr[1] = KMS_BO_TYPE_CURSOR; +#endif + attr[2] = KMS_WIDTH; + attr[3] = 64; + attr[4] = KMS_HEIGHT; + attr[5] = 64; + attr[6] = 0; + + if (kms_bo_create(ms->kms, attr, &crtcp->cursor_bo)) + return; + + if (kms_bo_get_prop(crtcp->cursor_bo, KMS_HANDLE, + &crtcp->cursor_handle)) + goto err_bo_destroy; + } + + kms_bo_map(crtcp->cursor_bo, (void**)&ptr); + memcpy(ptr, image, 64*64*4); + kms_bo_unmap(crtcp->cursor_bo); + + if (crtc->cursor_shown) + drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, + crtcp->cursor_handle, 64, 64); + + return; + +err_bo_destroy: + kms_bo_destroy(&crtcp->cursor_bo); +} +#endif + +static void +crtc_load_cursor_argb(xf86CrtcPtr crtc, CARD32 * image) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); + modesettingPtr ms = modesettingPTR(crtc->scrn); + + /* Older X servers have cursor reference counting bugs leading to use of + * freed memory and consequently random crashes. Should be fixed as of + * xserver 1.8, but this workaround shouldn't hurt anyway. + */ + if (config->cursor) + config->cursor->refcnt++; + + if (ms->cursor) + FreeCursor(ms->cursor, None); + + ms->cursor = config->cursor; + + if (ms->screen) + crtc_load_cursor_argb_ga3d(crtc, image); +#ifdef HAVE_LIBKMS + else if (ms->kms) + crtc_load_cursor_argb_kms(crtc, image); +#endif +} + +static void +crtc_show_cursor(xf86CrtcPtr crtc) +{ + modesettingPtr ms = modesettingPTR(crtc->scrn); + struct crtc_private *crtcp = crtc->driver_private; + + if (crtcp->cursor_tex || crtcp->cursor_bo) + drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, + crtcp->cursor_handle, 64, 64); +} + +static void +crtc_hide_cursor(xf86CrtcPtr crtc) +{ + modesettingPtr ms = modesettingPTR(crtc->scrn); + struct crtc_private *crtcp = crtc->driver_private; + + drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, 0, 0, 0); +} + +/** + * Called at vt leave + */ +void +xorg_crtc_cursor_destroy(xf86CrtcPtr crtc) +{ + struct crtc_private *crtcp = crtc->driver_private; + + if (crtcp->cursor_tex) + pipe_resource_reference(&crtcp->cursor_tex, NULL); +#ifdef HAVE_LIBKMS + if (crtcp->cursor_bo) + kms_bo_destroy(&crtcp->cursor_bo); +#endif +} + +/* + * Misc functions + */ + +static void +crtc_destroy(xf86CrtcPtr crtc) +{ + struct crtc_private *crtcp = crtc->driver_private; + + xorg_crtc_cursor_destroy(crtc); + + drmModeFreeCrtc(crtcp->drm_crtc); + + free(crtcp); + crtc->driver_private = NULL; +} + +static const xf86CrtcFuncsRec crtc_funcs = { + .dpms = crtc_dpms, + .set_mode_major = crtc_set_mode_major, + + .set_cursor_colors = crtc_set_cursor_colors, + .set_cursor_position = crtc_set_cursor_position, + .show_cursor = crtc_show_cursor, + .hide_cursor = crtc_hide_cursor, + .load_cursor_argb = crtc_load_cursor_argb, + + .shadow_create = NULL, + .shadow_allocate = NULL, + .shadow_destroy = NULL, + + .gamma_set = crtc_gamma_set, + .destroy = crtc_destroy, +}; + +void +xorg_crtc_init(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + xf86CrtcPtr crtc; + drmModeResPtr res; + drmModeCrtcPtr drm_crtc = NULL; + struct crtc_private *crtcp; + int c; + + res = drmModeGetResources(ms->fd); + if (res == 0) { + ErrorF("Failed drmModeGetResources %d\n", errno); + return; + } + + for (c = 0; c < res->count_crtcs; c++) { + drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]); + + if (!drm_crtc) + continue; + + crtc = xf86CrtcCreate(pScrn, &crtc_funcs); + if (crtc == NULL) + goto out; + + crtcp = calloc(1, sizeof(struct crtc_private)); + if (!crtcp) { + xf86CrtcDestroy(crtc); + goto out; + } + + crtcp->drm_crtc = drm_crtc; + + crtc->driver_private = crtcp; + } + + out: + drmModeFreeResources(res); +} + +/* vim: set sw=4 ts=8 sts=4: */ diff --git a/src/gallium/state_trackers/xorg/xorg_dri2.c b/src/gallium/state_trackers/xorg/xorg_dri2.c new file mode 100644 index 0000000..17c34b7 --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_dri2.c @@ -0,0 +1,470 @@ +/* + * 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 "xorg-server.h" +#include "xf86.h" +#include "xf86_OSproc.h" + +#include "xorg_tracker.h" +#include "xorg_exa.h" + +#include "dri2.h" + +#include "pipe/p_state.h" +#include "util/u_inlines.h" + +#include "util/u_format.h" + +#include "state_tracker/drm_driver.h" + +/* Make all the #if cases in the code esier to read */ +#ifndef DRI2INFOREC_VERSION +#define DRI2INFOREC_VERSION 1 +#endif + +#if DRI2INFOREC_VERSION == 2 +static Bool set_format_in_do_create_buffer; +#endif + +typedef struct { + PixmapPtr pPixmap; + struct pipe_resource *tex; + struct pipe_fence_handle *fence; +} *BufferPrivatePtr; + +static Bool +dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int format) +{ + struct pipe_resource *tex = NULL; + ScreenPtr pScreen = pDraw->pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_pixmap_priv *exa_priv; + BufferPrivatePtr private = buffer->driverPrivate; + PixmapPtr pPixmap; + struct winsys_handle whandle; + + if (pDraw->type == DRAWABLE_PIXMAP) + pPixmap = (PixmapPtr) pDraw; + else + pPixmap = (*pScreen->GetWindowPixmap)((WindowPtr) pDraw); + exa_priv = exaGetPixmapDriverPrivate(pPixmap); + + + switch (buffer->attachment) { + default: + if (buffer->attachment != DRI2BufferFakeFrontLeft || + pDraw->type != DRAWABLE_PIXMAP) { + private->pPixmap = (*pScreen->CreatePixmap)(pScreen, pDraw->width, + pDraw->height, + pDraw->depth, + 0); + } + break; + case DRI2BufferFrontLeft: + break; + case DRI2BufferStencil: +#if DRI2INFOREC_VERSION >= 3 + case DRI2BufferDepthStencil: +#else + /* Works on old X servers because sanity checking is for the weak */ + case 9: +#endif + if (exa_priv->depth_stencil_tex && + !util_format_is_depth_or_stencil(exa_priv->depth_stencil_tex->format)) + exa_priv->depth_stencil_tex = NULL; + /* Fall through */ + case DRI2BufferDepth: + if (exa_priv->depth_stencil_tex) + pipe_resource_reference(&tex, exa_priv->depth_stencil_tex); + else { + struct pipe_resource template; + unsigned depthBits = (format != 0) ? format : pDraw->depth; + memset(&template, 0, sizeof(template)); + template.target = PIPE_TEXTURE_2D; + if (buffer->attachment == DRI2BufferDepth) { + switch(depthBits) { + case 16: + template.format = PIPE_FORMAT_Z16_UNORM; + break; + case 32: + template.format = PIPE_FORMAT_Z32_UNORM; + break; + default: + template.format = ms->ds_depth_bits_last ? + PIPE_FORMAT_Z24X8_UNORM : PIPE_FORMAT_X8Z24_UNORM; + break; + } + } else { + template.format = ms->ds_depth_bits_last ? + PIPE_FORMAT_Z24_UNORM_S8_USCALED : PIPE_FORMAT_S8_USCALED_Z24_UNORM; + } + template.width0 = pDraw->width; + template.height0 = pDraw->height; + template.depth0 = 1; + template.array_size = 1; + template.last_level = 0; + template.bind = PIPE_BIND_DEPTH_STENCIL | + PIPE_BIND_SHARED; + tex = ms->screen->resource_create(ms->screen, &template); + pipe_resource_reference(&exa_priv->depth_stencil_tex, tex); + } + break; + } + + if (!private->pPixmap) { + private->pPixmap = pPixmap; + pPixmap->refcnt++; + } + + if (!tex) { + /* First call to make sure we have a pixmap private */ + exaMoveInPixmap(private->pPixmap); + xorg_exa_set_shared_usage(private->pPixmap); + pScreen->ModifyPixmapHeader(private->pPixmap, 0, 0, 0, 0, 0, NULL); + /* Second call to make sure texture has valid contents */ + exaMoveInPixmap(private->pPixmap); + tex = xorg_exa_get_texture(private->pPixmap); + } + + if (!tex) + FatalError("NO TEXTURE IN DRI2\n"); + + memset(&whandle, 0, sizeof(whandle)); + whandle.type = DRM_API_HANDLE_TYPE_SHARED; + + ms->screen->resource_get_handle(ms->screen, tex, &whandle); + + buffer->name = whandle.handle; + buffer->pitch = whandle.stride; + buffer->cpp = 4; + buffer->driverPrivate = private; + buffer->flags = 0; /* not tiled */ +#if DRI2INFOREC_VERSION == 2 + /* ABI forwards/backwards compatibility */ + if (set_format_in_do_create_buffer) + ((DRI2Buffer2Ptr)buffer)->format = 0; +#elif DRI2INFOREC_VERSION >= 3 + buffer->format = 0; +#endif + private->tex = tex; + + return TRUE; +} + +static void +dri2_do_destroy_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer) +{ + ScreenPtr pScreen = pDraw->pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + BufferPrivatePtr private = buffer->driverPrivate; + struct exa_pixmap_priv *exa_priv = exaGetPixmapDriverPrivate(private->pPixmap); + + pipe_resource_reference(&private->tex, NULL); + ms->screen->fence_reference(ms->screen, &private->fence, NULL); + pipe_resource_reference(&exa_priv->depth_stencil_tex, NULL); + (*pScreen->DestroyPixmap)(private->pPixmap); +} + +#if DRI2INFOREC_VERSION >= 2 + +static DRI2Buffer2Ptr +dri2_create_buffer(DrawablePtr pDraw, unsigned int attachment, unsigned int format) +{ + DRI2Buffer2Ptr buffer; + BufferPrivatePtr private; + + buffer = calloc(1, sizeof *buffer); + if (!buffer) + return NULL; + + private = calloc(1, sizeof *private); + if (!private) { + goto fail; + } + + buffer->attachment = attachment; + buffer->driverPrivate = private; + + /* So far it is safe to downcast a DRI2Buffer2Ptr to DRI2BufferPtr */ + if (dri2_do_create_buffer(pDraw, (DRI2BufferPtr)buffer, format)) + return buffer; + + free(private); +fail: + free(buffer); + return NULL; +} + +static void +dri2_destroy_buffer(DrawablePtr pDraw, DRI2Buffer2Ptr buffer) +{ + /* So far it is safe to downcast a DRI2Buffer2Ptr to DRI2BufferPtr */ + dri2_do_destroy_buffer(pDraw, (DRI2BufferPtr)buffer); + + free(buffer->driverPrivate); + free(buffer); +} + +#endif /* DRI2INFOREC_VERSION >= 2 */ + +#if DRI2INFOREC_VERSION <= 2 + +static DRI2BufferPtr +dri2_create_buffers(DrawablePtr pDraw, unsigned int *attachments, int count) +{ + BufferPrivatePtr privates; + DRI2BufferPtr buffers; + int i; + + buffers = calloc(count, sizeof *buffers); + if (!buffers) + goto fail_buffers; + + privates = calloc(count, sizeof *privates); + if (!privates) + goto fail_privates; + + for (i = 0; i < count; i++) { + buffers[i].attachment = attachments[i]; + buffers[i].driverPrivate = &privates[i]; + + if (!dri2_do_create_buffer(pDraw, &buffers[i], 0)) + goto fail; + } + + return buffers; + +fail: + free(privates); +fail_privates: + free(buffers); +fail_buffers: + return NULL; +} + +static void +dri2_destroy_buffers(DrawablePtr pDraw, DRI2BufferPtr buffers, int count) +{ + int i; + + for (i = 0; i < count; i++) { + dri2_do_destroy_buffer(pDraw, &buffers[i]); + } + + if (buffers) { + free(buffers[0].driverPrivate); + free(buffers); + } +} + +#endif /* DRI2INFOREC_VERSION <= 2 */ + +static void +dri2_copy_region(DrawablePtr pDraw, RegionPtr pRegion, + DRI2BufferPtr pDestBuffer, DRI2BufferPtr pSrcBuffer) +{ + ScreenPtr pScreen = pDraw->pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + BufferPrivatePtr dst_priv = pDestBuffer->driverPrivate; + BufferPrivatePtr src_priv = pSrcBuffer->driverPrivate; + DrawablePtr src_draw; + DrawablePtr dst_draw; + GCPtr gc; + RegionPtr copy_clip; + Bool save_accel; + CustomizerPtr cust = ms->cust; + + /* + * In driCreateBuffers we dewrap windows into the + * backing pixmaps in order to get to the texture. + * We need to use the real drawable in CopyArea + * so that cliprects and offsets are correct. + */ + src_draw = (pSrcBuffer->attachment == DRI2BufferFrontLeft) ? pDraw : + &src_priv->pPixmap->drawable; + dst_draw = (pDestBuffer->attachment == DRI2BufferFrontLeft) ? pDraw : + &dst_priv->pPixmap->drawable; + + /* + * The clients implements glXWaitX with a copy front to fake and then + * waiting on the server to signal its completion of it. While + * glXWaitGL is a client side flush and a copy from fake to front. + * This is how it is done in the DRI2 protocol, how ever depending + * which type of drawables the server does things a bit differently + * then what the protocol says as the fake and front are the same. + * + * for pixmaps glXWaitX is a server flush. + * for pixmaps glXWaitGL is a client flush. + * for windows glXWaitX is a copy from front to fake then a server flush. + * for windows glXWaitGL is a client flush then a copy from fake to front. + * + * XXX in the windows case this code always flushes but that isn't a + * must in the glXWaitGL case but we don't know if this is a glXWaitGL + * or a glFlush/glFinish call. + */ + if (dst_priv->pPixmap == src_priv->pPixmap) { + /* pixmap glXWaitX */ + if (pSrcBuffer->attachment == DRI2BufferFrontLeft && + pDestBuffer->attachment == DRI2BufferFakeFrontLeft) { + ms->ctx->flush(ms->ctx, PIPE_FLUSH_SWAPBUFFERS, NULL); + return; + } + /* pixmap glXWaitGL */ + if (pDestBuffer->attachment == DRI2BufferFrontLeft && + pSrcBuffer->attachment == DRI2BufferFakeFrontLeft) { + return; + } else { + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "copying between the same pixmap\n"); + } + } + + gc = GetScratchGC(pDraw->depth, pScreen); + copy_clip = REGION_CREATE(pScreen, NULL, 0); + REGION_COPY(pScreen, copy_clip, pRegion); + (*gc->funcs->ChangeClip) (gc, CT_REGION, copy_clip, 0); + ValidateGC(dst_draw, gc); + + /* If this is a full buffer swap, throttle on the previous one */ + if (ms->swapThrottling && + dst_priv->fence && REGION_NUM_RECTS(pRegion) == 1) { + BoxPtr extents = REGION_EXTENTS(pScreen, pRegion); + + if (extents->x1 == 0 && extents->y1 == 0 && + extents->x2 == pDraw->width && extents->y2 == pDraw->height) { + ms->screen->fence_finish(ms->screen, dst_priv->fence, 0); + ms->screen->fence_reference(ms->screen, &dst_priv->fence, NULL); + } + } + + /* Try to make sure the blit will be accelerated */ + save_accel = ms->exa->accel; + ms->exa->accel = TRUE; + + /* In case it won't be though, make sure the GPU copy contents of the + * source pixmap will be used for the software fallback - presumably the + * client modified them before calling in here. + */ + exaMoveInPixmap(src_priv->pPixmap); + DamageRegionAppend(src_draw, pRegion); + DamageRegionProcessPending(src_draw); + + if (cust && cust->winsys_context_throttle) + cust->winsys_context_throttle(cust, ms->ctx, THROTTLE_SWAP); + + (*gc->ops->CopyArea)(src_draw, dst_draw, gc, + 0, 0, pDraw->width, pDraw->height, 0, 0); + ms->exa->accel = save_accel; + + FreeScratchGC(gc); + + ms->ctx->flush(ms->ctx, PIPE_FLUSH_SWAPBUFFERS, + (pDestBuffer->attachment == DRI2BufferFrontLeft + && ms->swapThrottling) ? + &dst_priv->fence : NULL); + + if (cust && cust->winsys_context_throttle) + cust->winsys_context_throttle(cust, ms->ctx, THROTTLE_RENDER); + +} + +Bool +xorg_dri2_init(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + DRI2InfoRec dri2info; +#if DRI2INFOREC_VERSION >= 2 + int major, minor; + + if (xf86LoaderCheckSymbol("DRI2Version")) { + DRI2Version(&major, &minor); + } else { + /* Assume version 1.0 */ + major = 1; + minor = 0; + } +#endif + + dri2info.version = min(DRI2INFOREC_VERSION, 3); + dri2info.fd = ms->fd; + + dri2info.driverName = pScrn->driverName; + dri2info.deviceName = "/dev/dri/card0"; /* FIXME */ + +#if DRI2INFOREC_VERSION >= 2 + dri2info.CreateBuffer = dri2_create_buffer; + dri2info.DestroyBuffer = dri2_destroy_buffer; +#endif + + /* For X servers in the 1.6.x series there where two DRI2 version. + * This allows us to build one binary that works on both servers. + */ +#if DRI2INFOREC_VERSION == 2 + if (minor == 0) { + set_format_in_do_create_buffer = FALSE; + dri2info.CreateBuffers = dri2_create_buffers; + dri2info.DestroyBuffers = dri2_destroy_buffers; + } else + set_format_in_do_create_buffer = FALSE; +#endif + + /* For version 1 set these unconditionaly. */ +#if DRI2INFOREC_VERSION == 1 + dri2info.CreateBuffers = dri2_create_buffers; + dri2info.DestroyBuffers = dri2_destroy_buffers; +#endif + dri2info.CopyRegion = dri2_copy_region; + dri2info.Wait = NULL; + + ms->d_depth_bits_last = + ms->screen->is_format_supported(ms->screen, PIPE_FORMAT_Z24X8_UNORM, + PIPE_TEXTURE_2D, + 0, + PIPE_BIND_DEPTH_STENCIL, 0); + ms->ds_depth_bits_last = + ms->screen->is_format_supported(ms->screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED, + PIPE_TEXTURE_2D, + 0, + PIPE_BIND_DEPTH_STENCIL, 0); + + return DRI2ScreenInit(pScreen, &dri2info); +} + +void +xorg_dri2_close(ScreenPtr pScreen) +{ + DRI2CloseScreen(pScreen); +} + +/* vim: set sw=4 ts=8 sts=4: */ diff --git a/src/gallium/state_trackers/xorg/xorg_driver.c b/src/gallium/state_trackers/xorg/xorg_driver.c new file mode 100644 index 0000000..66685ec --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_driver.c @@ -0,0 +1,1242 @@ +/* + * 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 "xorg-server.h" +#include "xf86.h" +#include "xf86_OSproc.h" +#include "compiler.h" +#include "xf86PciInfo.h" +#include "xf86Pci.h" +#include "mipointer.h" +#include "micmap.h" +#include +#include "fb.h" +#include "edid.h" +#include "xf86i2c.h" +#include "xf86Crtc.h" +#include "miscstruct.h" +#include "dixstruct.h" +#include "xf86xv.h" +#include "xorgVersion.h" +#ifndef XSERVER_LIBPCIACCESS +#error "libpciaccess needed" +#endif + +#include + +#include "state_tracker/drm_driver.h" +#include "pipe/p_context.h" +#include "xorg_tracker.h" +#include "xorg_winsys.h" + +#ifdef HAVE_LIBKMS +#include "libkms.h" +#endif + +/* + * Functions and symbols exported to Xorg via pointers. + */ + +static Bool drv_pre_init(ScrnInfoPtr pScrn, int flags); +static Bool drv_screen_init(int scrnIndex, ScreenPtr pScreen, int argc, + char **argv); +static Bool drv_switch_mode(int scrnIndex, DisplayModePtr mode, int flags); +static void drv_adjust_frame(int scrnIndex, int x, int y, int flags); +static Bool drv_enter_vt(int scrnIndex, int flags); +static void drv_leave_vt(int scrnIndex, int flags); +static void drv_free_screen(int scrnIndex, int flags); +static ModeStatus drv_valid_mode(int scrnIndex, DisplayModePtr mode, Bool verbose, + int flags); + +typedef enum +{ + OPTION_SW_CURSOR, + OPTION_2D_ACCEL, + OPTION_DEBUG_FALLBACK, + OPTION_THROTTLE_SWAP, + OPTION_THROTTLE_DIRTY, + OPTION_3D_ACCEL +} drv_option_enums; + +static const OptionInfoRec drv_options[] = { + {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE}, + {OPTION_2D_ACCEL, "2DAccel", OPTV_BOOLEAN, {0}, FALSE}, + {OPTION_DEBUG_FALLBACK, "DebugFallback", OPTV_BOOLEAN, {0}, FALSE}, + {OPTION_THROTTLE_SWAP, "SwapThrottling", OPTV_BOOLEAN, {0}, FALSE}, + {OPTION_THROTTLE_DIRTY, "DirtyThrottling", OPTV_BOOLEAN, {0}, FALSE}, + {OPTION_3D_ACCEL, "3DAccel", OPTV_BOOLEAN, {0}, FALSE}, + {-1, NULL, OPTV_NONE, {0}, FALSE} +}; + + +/* + * Exported Xorg driver functions to winsys + */ + +const OptionInfoRec * +xorg_tracker_available_options(int chipid, int busid) +{ + return drv_options; +} + +void +xorg_tracker_set_functions(ScrnInfoPtr scrn) +{ + scrn->PreInit = drv_pre_init; + scrn->ScreenInit = drv_screen_init; + scrn->SwitchMode = drv_switch_mode; + scrn->AdjustFrame = drv_adjust_frame; + scrn->EnterVT = drv_enter_vt; + scrn->LeaveVT = drv_leave_vt; + scrn->FreeScreen = drv_free_screen; + scrn->ValidMode = drv_valid_mode; +} + +Bool +xorg_tracker_have_modesetting(ScrnInfoPtr pScrn, struct pci_device *device) +{ + char *BusID = malloc(64); + sprintf(BusID, "pci:%04x:%02x:%02x.%d", + device->domain, device->bus, + device->dev, device->func); + + if (drmCheckModesettingSupported(BusID)) { + xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 0, + "Drm modesetting not supported %s\n", BusID); + free(BusID); + return FALSE; + } + + xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 0, + "Drm modesetting supported on %s\n", BusID); + + free(BusID); + return TRUE; +} + + +/* + * Internal function definitions + */ + +static Bool drv_init_front_buffer_functions(ScrnInfoPtr pScrn); +static Bool drv_close_screen(int scrnIndex, ScreenPtr pScreen); + + +/* + * Internal functions + */ + +static Bool +drv_get_rec(ScrnInfoPtr pScrn) +{ + if (pScrn->driverPrivate) + return TRUE; + + pScrn->driverPrivate = xnfcalloc(1, sizeof(modesettingRec)); + + return TRUE; +} + +static void +drv_free_rec(ScrnInfoPtr pScrn) +{ + if (!pScrn) + return; + + if (!pScrn->driverPrivate) + return; + + free(pScrn->driverPrivate); + + pScrn->driverPrivate = NULL; +} + +static void +drv_probe_ddc(ScrnInfoPtr pScrn, int index) +{ + ConfiguredMonitor = NULL; +} + +static Bool +drv_crtc_resize(ScrnInfoPtr pScrn, int width, int height) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + modesettingPtr ms = modesettingPTR(pScrn); + CustomizerPtr cust = ms->cust; + ScreenPtr pScreen = pScrn->pScreen; + int old_width, old_height; + PixmapPtr rootPixmap; + int i; + + if (width == pScrn->virtualX && height == pScrn->virtualY) + return TRUE; + + if (cust && cust->winsys_check_fb_size && + !cust->winsys_check_fb_size(cust, width*pScrn->bitsPerPixel / 8, + height)) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Requested framebuffer size %dx%dx%d will not fit " + "in display memory.\n", + width, height, pScrn->bitsPerPixel); + return FALSE; + } + + old_width = pScrn->virtualX; + old_height = pScrn->virtualY; + pScrn->virtualX = width; + pScrn->virtualY = height; + + /* ms->create_front_buffer will remove the old front buffer */ + + rootPixmap = pScreen->GetScreenPixmap(pScreen); + if (!pScreen->ModifyPixmapHeader(rootPixmap, width, height, -1, -1, -1, NULL)) + goto error_modify; + + pScrn->displayWidth = rootPixmap->devKind / (rootPixmap->drawable.bitsPerPixel / 8); + + if (!ms->create_front_buffer(pScrn) || !ms->bind_front_buffer(pScrn)) + goto error_create; + + /* + * create && bind will turn off all crtc(s) in the kernel so we need to + * re-enable all the crtcs again. For real HW we might want to do this + * before destroying the old framebuffer. + */ + for (i = 0; i < xf86_config->num_crtc; i++) { + xf86CrtcPtr crtc = xf86_config->crtc[i]; + + if (!crtc->enabled) + continue; + + crtc->funcs->set_mode_major(crtc, &crtc->mode, crtc->rotation, crtc->x, crtc->y); + } + + return TRUE; + + /* + * This is the error recovery path. + */ +error_create: + if (!pScreen->ModifyPixmapHeader(rootPixmap, old_width, old_height, -1, -1, -1, NULL)) + FatalError("failed to resize rootPixmap error path\n"); + + pScrn->displayWidth = rootPixmap->devKind / (rootPixmap->drawable.bitsPerPixel / 8); + +error_modify: + pScrn->virtualX = old_width; + pScrn->virtualY = old_height; + + if (ms->create_front_buffer(pScrn) && ms->bind_front_buffer(pScrn)) + return FALSE; + + FatalError("failed to setup old framebuffer\n"); + return FALSE; +} + +static const xf86CrtcConfigFuncsRec crtc_config_funcs = { + .resize = drv_crtc_resize +}; + +static Bool +drv_init_drm(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + + /* deal with server regeneration */ + if (ms->fd < 0) { + char *BusID; + + BusID = malloc(64); + sprintf(BusID, "PCI:%d:%d:%d", + ((ms->PciInfo->domain << 8) | ms->PciInfo->bus), + ms->PciInfo->dev, ms->PciInfo->func + ); + + + ms->fd = drmOpen(driver_descriptor.driver_name, BusID); + ms->isMaster = TRUE; + free(BusID); + + if (ms->fd >= 0) + return TRUE; + + return FALSE; + } + + return TRUE; +} + +static Bool +drv_init_resource_management(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + /* + ScreenPtr pScreen = pScrn->pScreen; + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + Bool fbAccessDisabled; + CARD8 *fbstart; + */ + + if (ms->screen || ms->kms) + return TRUE; + + if (!ms->no3D) + ms->screen = driver_descriptor.create_screen(ms->fd); + + if (ms->screen) + return TRUE; + +#ifdef HAVE_LIBKMS + if (!kms_create(ms->fd, &ms->kms)) + return TRUE; +#endif + + return FALSE; +} + +static void +drv_cleanup_fences(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + int i; + + assert(ms->screen); + + for (i = 0; i < XORG_NR_FENCES; i++) { + if (ms->fence[i]) { + ms->screen->fence_finish(ms->screen, ms->fence[i], 0); + ms->screen->fence_reference(ms->screen, &ms->fence[i], NULL); + } + } +} + +static Bool +drv_pre_init(ScrnInfoPtr pScrn, int flags) +{ + xf86CrtcConfigPtr xf86_config; + modesettingPtr ms; + rgb defaultWeight = { 0, 0, 0 }; + EntityInfoPtr pEnt; + EntPtr msEnt = NULL; + CustomizerPtr cust; + Bool use3D; + + if (pScrn->numEntities != 1) + return FALSE; + + pEnt = xf86GetEntityInfo(pScrn->entityList[0]); + + if (flags & PROBE_DETECT) { + drv_probe_ddc(pScrn, pEnt->index); + return TRUE; + } + + cust = (CustomizerPtr) pScrn->driverPrivate; + pScrn->driverPrivate = NULL; + + /* Allocate driverPrivate */ + if (!drv_get_rec(pScrn)) + return FALSE; + + ms = modesettingPTR(pScrn); + ms->pEnt = pEnt; + ms->cust = cust; + ms->fb_id = -1; + + pScrn->displayWidth = 640; /* default it */ + + if (ms->pEnt->location.type != BUS_PCI) + return FALSE; + + ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index); + + /* Allocate an entity private if necessary */ + if (xf86IsEntityShared(pScrn->entityList[0])) { + FatalError("Entity"); +#if 0 + msEnt = xf86GetEntityPrivate(pScrn->entityList[0], + modesettingEntityIndex)->ptr; + ms->entityPrivate = msEnt; +#else + (void)msEnt; +#endif + } else + ms->entityPrivate = NULL; + + if (xf86IsEntityShared(pScrn->entityList[0])) { + if (xf86IsPrimInitDone(pScrn->entityList[0])) { + /* do something */ + } else { + xf86SetPrimInitDone(pScrn->entityList[0]); + } + } + + ms->fd = -1; + if (!drv_init_drm(pScrn)) + return FALSE; + + pScrn->monitor = pScrn->confScreen->monitor; + pScrn->progClock = TRUE; + pScrn->rgbBits = 8; + + if (!xf86SetDepthBpp + (pScrn, 0, 0, 0, + PreferConvert24to32 | SupportConvert24to32 | Support32bppFb)) + return FALSE; + + switch (pScrn->depth) { + case 15: + case 16: + case 24: + break; + default: + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Given depth (%d) is not supported by the driver\n", + pScrn->depth); + return FALSE; + } + xf86PrintDepthBpp(pScrn); + + if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight)) + return FALSE; + if (!xf86SetDefaultVisual(pScrn, -1)) + return FALSE; + + /* Process the options */ + xf86CollectOptions(pScrn, NULL); + if (!(ms->Options = malloc(sizeof(drv_options)))) + return FALSE; + memcpy(ms->Options, drv_options, sizeof(drv_options)); + xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options); + + use3D = cust ? !cust->no_3d : TRUE; + ms->from_3D = xf86GetOptValBool(ms->Options, OPTION_3D_ACCEL, + &use3D) ? + X_CONFIG : X_PROBED; + + ms->no3D = !use3D; + + if (!drv_init_resource_management(pScrn)) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Could not init " + "Gallium3D or libKMS.\n"); + return FALSE; + } + + /* Allocate an xf86CrtcConfig */ + xf86CrtcConfigInit(pScrn, &crtc_config_funcs); + xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + + /* get max width and height */ + { + drmModeResPtr res; + int max_width, max_height; + + res = drmModeGetResources(ms->fd); + max_width = res->max_width; + max_height = res->max_height; + + if (ms->screen) { + int max; + + max = ms->screen->get_param(ms->screen, + PIPE_CAP_MAX_TEXTURE_2D_LEVELS); + max = 1 << (max - 1); + max_width = max < max_width ? max : max_width; + max_height = max < max_height ? max : max_height; + } + + xf86CrtcSetSizeRange(pScrn, res->min_width, + res->min_height, max_width, max_height); + xf86DrvMsg(pScrn->scrnIndex, X_PROBED, + "Min width %d, Max Width %d.\n", + res->min_width, max_width); + xf86DrvMsg(pScrn->scrnIndex, X_PROBED, + "Min height %d, Max Height %d.\n", + res->min_height, max_height); + drmModeFreeResources(res); + } + + + if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) { + ms->SWCursor = TRUE; + } + + xorg_crtc_init(pScrn); + xorg_output_init(pScrn); + + if (cust && cust->winsys_pre_init && !cust->winsys_pre_init(cust, ms->fd)) + return FALSE; + + if (!xf86InitialConfiguration(pScrn, TRUE)) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n"); + return FALSE; + } + + /* + * If the driver can do gamma correction, it should call xf86SetGamma() here. + */ + { + Gamma zeros = { 0.0, 0.0, 0.0 }; + + if (!xf86SetGamma(pScrn, zeros)) { + return FALSE; + } + } + + if (pScrn->modes == NULL) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n"); + return FALSE; + } + + pScrn->currentMode = pScrn->modes; + + /* Set display resolution */ + xf86SetDpi(pScrn, 0, 0); + + /* Load the required sub modules */ + if (!xf86LoadSubModule(pScrn, "fb")) + return FALSE; + + /* XXX: these aren't needed when we are using libkms */ + if (!xf86LoadSubModule(pScrn, "exa")) + return FALSE; + +#ifdef DRI2 + if (!xf86LoadSubModule(pScrn, "dri2")) + return FALSE; +#endif + + return TRUE; +} + +void xorg_flush(ScreenPtr pScreen) +{ + modesettingPtr ms = modesettingPTR(xf86Screens[pScreen->myNum]); + + if (ms->ctx) { + int j; + + ms->ctx->flush(ms->ctx, PIPE_FLUSH_RENDER_CACHE, + ms->dirtyThrottling ? + &ms->fence[XORG_NR_FENCES-1] : + NULL); + + if (ms->dirtyThrottling) { + if (ms->fence[0]) + ms->ctx->screen->fence_finish(ms->ctx->screen, + ms->fence[0], 0); + + /* The amount of rendering generated by a block handler can be + * quite small. Let us get a fair way ahead of hardware before + * throttling. + */ + for (j = 0; j < XORG_NR_FENCES - 1; j++) + ms->screen->fence_reference(ms->screen, + &ms->fence[j], + ms->fence[j+1]); + + ms->screen->fence_reference(ms->screen, + &ms->fence[XORG_NR_FENCES-1], + NULL); + } + } + +#ifdef DRM_MODE_FEATURE_DIRTYFB + { + RegionPtr dirty = DamageRegion(ms->damage); + unsigned num_cliprects = REGION_NUM_RECTS(dirty); + + if (num_cliprects) { + drmModeClip *clip = alloca(num_cliprects * sizeof(drmModeClip)); + BoxPtr rect = REGION_RECTS(dirty); + int i, ret; + + /* XXX no need for copy? */ + for (i = 0; i < num_cliprects; i++, rect++) { + clip[i].x1 = rect->x1; + clip[i].y1 = rect->y1; + clip[i].x2 = rect->x2; + clip[i].y2 = rect->y2; + } + + /* TODO query connector property to see if this is needed */ + ret = drmModeDirtyFB(ms->fd, ms->fb_id, clip, num_cliprects); + if (ret) { + debug_printf("%s: failed to send dirty (%i, %s)\n", + __func__, ret, strerror(-ret)); + } + + DamageEmpty(ms->damage); + } + } +#endif +} + +static void drv_block_handler(int i, pointer blockData, pointer pTimeout, + pointer pReadmask) +{ + ScreenPtr pScreen = screenInfo.screens[i]; + modesettingPtr ms = modesettingPTR(xf86Screens[pScreen->myNum]); + + pScreen->BlockHandler = ms->blockHandler; + pScreen->BlockHandler(i, blockData, pTimeout, pReadmask); + pScreen->BlockHandler = drv_block_handler; + + xorg_flush(pScreen); +} + +static Bool +drv_create_screen_resources(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + PixmapPtr rootPixmap; + Bool ret; + + ms->noEvict = TRUE; + + pScreen->CreateScreenResources = ms->createScreenResources; + ret = pScreen->CreateScreenResources(pScreen); + pScreen->CreateScreenResources = drv_create_screen_resources; + + ms->bind_front_buffer(pScrn); + + ms->noEvict = FALSE; + + drv_adjust_frame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); + +#ifdef DRM_MODE_FEATURE_DIRTYFB + rootPixmap = pScreen->GetScreenPixmap(pScreen); + ms->damage = DamageCreate(NULL, NULL, DamageReportNone, TRUE, + pScreen, rootPixmap); + + if (ms->damage) { + DamageRegister(&rootPixmap->drawable, ms->damage); + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Damage tracking initialized\n"); + } else { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Failed to create screen damage record\n"); + return FALSE; + } +#else + (void)rootPixmap; +#endif + + return ret; +} + +static Bool +drv_set_master(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + + if (!ms->isMaster && drmSetMaster(ms->fd) != 0) { + if (errno == EINVAL) { + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "drmSetMaster failed: 2.6.29 or newer kernel required for " + "multi-server DRI\n"); + } else { + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "drmSetMaster failed: %s\n", strerror(errno)); + } + return FALSE; + } + + ms->isMaster = TRUE; + return TRUE; +} + + +static Bool +drv_screen_init(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + VisualPtr visual; + CustomizerPtr cust = ms->cust; + MessageType from_st; + MessageType from_dt; + + if (!drv_set_master(pScrn)) + return FALSE; + + if (!drv_init_front_buffer_functions(pScrn)) { + FatalError("Could not init front buffer manager"); + return FALSE; + } + + pScrn->pScreen = pScreen; + + /* HW dependent - FIXME */ + pScrn->displayWidth = pScrn->virtualX; + + miClearVisualTypes(); + + if (!miSetVisualTypes(pScrn->depth, + miGetDefaultVisualMask(pScrn->depth), + pScrn->rgbBits, pScrn->defaultVisual)) + return FALSE; + + if (!miSetPixmapDepths()) + return FALSE; + + pScrn->memPhysBase = 0; + pScrn->fbOffset = 0; + + if (!fbScreenInit(pScreen, NULL, + pScrn->virtualX, pScrn->virtualY, + pScrn->xDpi, pScrn->yDpi, + pScrn->displayWidth, pScrn->bitsPerPixel)) + return FALSE; + + if (pScrn->bitsPerPixel > 8) { + /* Fixup RGB ordering */ + visual = pScreen->visuals + pScreen->numVisuals; + while (--visual >= pScreen->visuals) { + if ((visual->class | DynamicClass) == DirectColor) { + visual->offsetRed = pScrn->offset.red; + visual->offsetGreen = pScrn->offset.green; + visual->offsetBlue = pScrn->offset.blue; + visual->redMask = pScrn->mask.red; + visual->greenMask = pScrn->mask.green; + visual->blueMask = pScrn->mask.blue; + } + } + } + + fbPictureInit(pScreen, NULL, 0); + + ms->blockHandler = pScreen->BlockHandler; + pScreen->BlockHandler = drv_block_handler; + ms->createScreenResources = pScreen->CreateScreenResources; + pScreen->CreateScreenResources = drv_create_screen_resources; + + xf86SetBlackWhitePixels(pScreen); + + ms->accelerate_2d = xf86ReturnOptValBool(ms->Options, OPTION_2D_ACCEL, FALSE); + ms->debug_fallback = xf86ReturnOptValBool(ms->Options, OPTION_DEBUG_FALLBACK, ms->accelerate_2d); + + if (cust && cust->winsys_screen_init) + cust->winsys_screen_init(cust); + + ms->swapThrottling = cust ? cust->swap_throttling : TRUE; + from_st = xf86GetOptValBool(ms->Options, OPTION_THROTTLE_SWAP, + &ms->swapThrottling) ? + X_CONFIG : X_DEFAULT; + + ms->dirtyThrottling = cust ? cust->dirty_throttling : TRUE; + from_dt = xf86GetOptValBool(ms->Options, OPTION_THROTTLE_DIRTY, + &ms->dirtyThrottling) ? + X_CONFIG : X_DEFAULT; + + if (ms->screen) { + ms->exa = xorg_exa_init(pScrn, ms->accelerate_2d); + + xorg_xv_init(pScreen); +#ifdef DRI2 + xorg_dri2_init(pScreen); +#endif + } + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "##################################\n"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "# Usefull debugging info follows #\n"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "##################################\n"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Using %s backend\n", + ms->screen ? "Gallium3D" : "libkms"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "2D Acceleration is %s\n", + ms->screen && ms->accelerate_2d ? "enabled" : "disabled"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Fallback debugging is %s\n", + ms->debug_fallback ? "enabled" : "disabled"); +#ifdef DRI2 + xf86DrvMsg(pScrn->scrnIndex, ms->from_3D, "3D Acceleration is %s\n", + ms->screen ? "enabled" : "disabled"); +#else + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "3D Acceleration is disabled\n"); +#endif + xf86DrvMsg(pScrn->scrnIndex, from_st, "Swap Throttling is %s.\n", + ms->swapThrottling ? "enabled" : "disabled"); + xf86DrvMsg(pScrn->scrnIndex, from_dt, "Dirty Throttling is %s.\n", + ms->dirtyThrottling ? "enabled" : "disabled"); + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "##################################\n"); + + miInitializeBackingStore(pScreen); + xf86SetBackingStore(pScreen); + xf86SetSilkenMouse(pScreen); + miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); + + /* Need to extend HWcursor support to handle mask interleave */ + if (!ms->SWCursor) + xf86_cursors_init(pScreen, 64, 64, + HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 | + HARDWARE_CURSOR_ARGB | + ((cust && cust->unhidden_hw_cursor_update) ? + HARDWARE_CURSOR_UPDATE_UNHIDDEN : 0)); + + /* Must force it before EnterVT, so we are in control of VT and + * later memory should be bound when allocating, e.g rotate_mem */ + pScrn->vtSema = TRUE; + + pScreen->SaveScreen = xf86SaveScreen; + ms->CloseScreen = pScreen->CloseScreen; + pScreen->CloseScreen = drv_close_screen; + + if (!xf86CrtcScreenInit(pScreen)) + return FALSE; + + if (!miCreateDefColormap(pScreen)) + return FALSE; + + xf86DPMSInit(pScreen, xf86DPMSSet, 0); + + if (serverGeneration == 1) + xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); + + return drv_enter_vt(scrnIndex, 1); +} + +static void +drv_adjust_frame(int scrnIndex, int x, int y, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + xf86OutputPtr output = config->output[config->compat_output]; + xf86CrtcPtr crtc = output->crtc; + + if (crtc && crtc->enabled) { + crtc->funcs->set_mode_major(crtc, pScrn->currentMode, + RR_Rotate_0, x, y); + crtc->x = output->initial_x + x; + crtc->y = output->initial_y + y; + } +} + +static void +drv_free_screen(int scrnIndex, int flags) +{ + drv_free_rec(xf86Screens[scrnIndex]); +} + +static void +drv_leave_vt(int scrnIndex, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + modesettingPtr ms = modesettingPTR(pScrn); + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + CustomizerPtr cust = ms->cust; + int o; + + if (cust && cust->winsys_leave_vt) + cust->winsys_leave_vt(cust); + + for (o = 0; o < config->num_crtc; o++) { + xf86CrtcPtr crtc = config->crtc[o]; + + xorg_crtc_cursor_destroy(crtc); + + if (crtc->rotatedPixmap || crtc->rotatedData) { + crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap, + crtc->rotatedData); + crtc->rotatedPixmap = NULL; + crtc->rotatedData = NULL; + } + } + + if (ms->fb_id != -1) { + drmModeRmFB(ms->fd, ms->fb_id); + ms->fb_id = -1; + } + + /* idle hardware */ + if (!ms->kms) + drv_cleanup_fences(pScrn); + + if (drmDropMaster(ms->fd)) + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "drmDropMaster failed: %s\n", strerror(errno)); + + ms->isMaster = FALSE; + pScrn->vtSema = FALSE; +} + +/* + * This gets called when gaining control of the VT, and from ScreenInit(). + */ +static Bool +drv_enter_vt(int scrnIndex, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + modesettingPtr ms = modesettingPTR(pScrn); + CustomizerPtr cust = ms->cust; + + if (!drv_set_master(pScrn)) + return FALSE; + + if (!ms->create_front_buffer(pScrn)) + return FALSE; + + if (!flags && !ms->bind_front_buffer(pScrn)) + return FALSE; + + if (!xf86SetDesiredModes(pScrn)) + return FALSE; + + if (cust && cust->winsys_enter_vt) + cust->winsys_enter_vt(cust); + + return TRUE; +} + +static Bool +drv_switch_mode(int scrnIndex, DisplayModePtr mode, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + + return xf86SetSingleMode(pScrn, mode, RR_Rotate_0); +} + +static Bool +drv_close_screen(int scrnIndex, ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + modesettingPtr ms = modesettingPTR(pScrn); + CustomizerPtr cust = ms->cust; + + if (ms->cursor) { + FreeCursor(ms->cursor, None); + ms->cursor = NULL; + } + + if (cust && cust->winsys_screen_close) + cust->winsys_screen_close(cust); + +#ifdef DRI2 + if (ms->screen) + xorg_dri2_close(pScreen); +#endif + + pScreen->BlockHandler = ms->blockHandler; + pScreen->CreateScreenResources = ms->createScreenResources; + +#ifdef DRM_MODE_FEATURE_DIRTYFB + if (ms->damage) { + DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage); + DamageDestroy(ms->damage); + ms->damage = NULL; + } +#endif + + ms->destroy_front_buffer(pScrn); + + if (ms->exa) + xorg_exa_close(pScrn); + ms->exa = NULL; + + /* calls drop master make sure we don't talk to 3D HW after that */ + if (pScrn->vtSema) { + drv_leave_vt(scrnIndex, 0); + } + + pScrn->vtSema = FALSE; + pScreen->CloseScreen = ms->CloseScreen; + + return (*pScreen->CloseScreen) (scrnIndex, pScreen); +} + +static ModeStatus +drv_valid_mode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags) +{ + return MODE_OK; +} + + +/* + * Front buffer backing store functions. + */ + +static Bool +drv_destroy_front_buffer_ga3d(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + + if (!ms->root_texture) + return TRUE; + + if (ms->fb_id != -1) { + drmModeRmFB(ms->fd, ms->fb_id); + ms->fb_id = -1; + } + + pipe_resource_reference(&ms->root_texture, NULL); + return TRUE; +} + +static Bool +drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + struct pipe_resource *tex; + struct winsys_handle whandle; + unsigned fb_id; + int ret; + + ms->noEvict = TRUE; + + tex = xorg_exa_create_root_texture(pScrn, pScrn->virtualX, pScrn->virtualY, + pScrn->depth, pScrn->bitsPerPixel); + + if (!tex) + return FALSE; + + memset(&whandle, 0, sizeof(whandle)); + whandle.type = DRM_API_HANDLE_TYPE_KMS; + + if (!ms->screen->resource_get_handle(ms->screen, tex, &whandle)) + goto err_destroy; + + ret = drmModeAddFB(ms->fd, + pScrn->virtualX, + pScrn->virtualY, + pScrn->depth, + pScrn->bitsPerPixel, + whandle.stride, + whandle.handle, + &fb_id); + if (ret) { + debug_printf("%s: failed to create framebuffer (%i, %s)\n", + __func__, ret, strerror(-ret)); + goto err_destroy; + } + + if (!drv_destroy_front_buffer_ga3d(pScrn)) + FatalError("%s: failed to take down old framebuffer\n", __func__); + + pScrn->frameX0 = 0; + pScrn->frameY0 = 0; + drv_adjust_frame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); + + pipe_resource_reference(&ms->root_texture, tex); + pipe_resource_reference(&tex, NULL); + ms->fb_id = fb_id; + + return TRUE; + +err_destroy: + pipe_resource_reference(&tex, NULL); + return FALSE; +} + +static Bool +drv_bind_front_buffer_ga3d(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + ScreenPtr pScreen = pScrn->pScreen; + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + struct pipe_resource *check; + + xorg_exa_set_displayed_usage(rootPixmap); + xorg_exa_set_shared_usage(rootPixmap); + xorg_exa_set_texture(rootPixmap, ms->root_texture); + if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, NULL)) + FatalError("Couldn't adjust screen pixmap\n"); + + check = xorg_exa_get_texture(rootPixmap); + if (ms->root_texture != check) + FatalError("Created new root texture\n"); + + pipe_resource_reference(&check, NULL); + return TRUE; +} + +#ifdef HAVE_LIBKMS +static Bool +drv_destroy_front_buffer_kms(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + ScreenPtr pScreen = pScrn->pScreen; + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + + /* XXX Do something with the rootPixmap. + * This currently works fine but if we are getting crashes in + * the fb functions after VT switches maybe look more into it. + */ + (void)rootPixmap; + + if (!ms->root_bo) + return TRUE; + + if (ms->fb_id != -1) { + drmModeRmFB(ms->fd, ms->fb_id); + ms->fb_id = -1; + } + + kms_bo_unmap(ms->root_bo); + kms_bo_destroy(&ms->root_bo); + return TRUE; +} + +static Bool +drv_create_front_buffer_kms(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + unsigned handle, stride; + struct kms_bo *bo; + unsigned attr[8]; + unsigned fb_id; + int ret; + + attr[0] = KMS_BO_TYPE; +#ifdef KMS_BO_TYPE_SCANOUT_X8R8G8B8 + attr[1] = KMS_BO_TYPE_SCANOUT_X8R8G8B8; +#else + attr[1] = KMS_BO_TYPE_SCANOUT; +#endif + attr[2] = KMS_WIDTH; + attr[3] = pScrn->virtualX; + attr[4] = KMS_HEIGHT; + attr[5] = pScrn->virtualY; + attr[6] = 0; + + if (kms_bo_create(ms->kms, attr, &bo)) + return FALSE; + + if (kms_bo_get_prop(bo, KMS_PITCH, &stride)) + goto err_destroy; + + if (kms_bo_get_prop(bo, KMS_HANDLE, &handle)) + goto err_destroy; + + ret = drmModeAddFB(ms->fd, + pScrn->virtualX, + pScrn->virtualY, + pScrn->depth, + pScrn->bitsPerPixel, + stride, + handle, + &fb_id); + if (ret) { + debug_printf("%s: failed to create framebuffer (%i, %s)", + __func__, ret, strerror(-ret)); + goto err_destroy; + } + + if (!drv_destroy_front_buffer_kms(pScrn)) + FatalError("%s: could not takedown old bo", __func__); + + pScrn->frameX0 = 0; + pScrn->frameY0 = 0; + drv_adjust_frame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); + ms->root_bo = bo; + ms->fb_id = fb_id; + + return TRUE; + +err_destroy: + kms_bo_destroy(&bo); + return FALSE; +} + +static Bool +drv_bind_front_buffer_kms(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + ScreenPtr pScreen = pScrn->pScreen; + PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen); + unsigned stride; + void *ptr; + + if (kms_bo_get_prop(ms->root_bo, KMS_PITCH, &stride)) + return FALSE; + + if (kms_bo_map(ms->root_bo, &ptr)) + goto err_destroy; + + pScreen->ModifyPixmapHeader(rootPixmap, + pScrn->virtualX, + pScrn->virtualY, + pScreen->rootDepth, + pScrn->bitsPerPixel, + stride, + ptr); + +#if (XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1, 9, 99, 1, 0)) + + /* This a hack to work around EnableDisableFBAccess setting the pointer + * the real fix would be to replace pScrn->EnableDisableFBAccess hook + * and set the rootPixmap->devPrivate.ptr to something valid before that. + * + * But in its infinit visdome something uses either this some times before + * that, so our hook doesn't get called before the crash happens. + */ + pScrn->pixmapPrivate.ptr = ptr; + +#endif + + return TRUE; + +err_destroy: + kms_bo_destroy(&ms->root_bo); + return FALSE; +} +#endif /* HAVE_LIBKMS */ + +static Bool drv_init_front_buffer_functions(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + if (ms->screen) { + ms->destroy_front_buffer = drv_destroy_front_buffer_ga3d; + ms->create_front_buffer = drv_create_front_buffer_ga3d; + ms->bind_front_buffer = drv_bind_front_buffer_ga3d; +#ifdef HAVE_LIBKMS + } else if (ms->kms) { + ms->destroy_front_buffer = drv_destroy_front_buffer_kms; + ms->create_front_buffer = drv_create_front_buffer_kms; + ms->bind_front_buffer = drv_bind_front_buffer_kms; +#endif + } else + return FALSE; + + return TRUE; +} + +CustomizerPtr xorg_customizer(ScrnInfoPtr pScrn) +{ + return modesettingPTR(pScrn)->cust; +} + +Bool xorg_has_gallium(ScrnInfoPtr pScrn) +{ + return modesettingPTR(pScrn)->screen != NULL; +} + +/* vim: set sw=4 ts=8 sts=4: */ diff --git a/src/gallium/state_trackers/xorg/xorg_exa.c b/src/gallium/state_trackers/xorg/xorg_exa.c new file mode 100644 index 0000000..718a345 --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_exa.c @@ -0,0 +1,1090 @@ +/* + * 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 "xorg_exa.h" +#include "xorg_tracker.h" +#include "xorg_composite.h" +#include "xorg_exa_tgsi.h" + +#include +#include +#include +#include + +#include "pipe/p_format.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" + +#include "util/u_rect.h" +#include "util/u_math.h" +#include "util/u_debug.h" +#include "util/u_format.h" +#include "util/u_box.h" +#include "util/u_surface.h" + +#define DEBUG_PRINT 0 +#define ROUND_UP_TEXTURES 1 + +/* + * Helper functions + */ +struct render_format_str { + int format; + const char *name; +}; +static const struct render_format_str formats_info[] = +{ + {PICT_a8r8g8b8, "PICT_a8r8g8b8"}, + {PICT_x8r8g8b8, "PICT_x8r8g8b8"}, + {PICT_a8b8g8r8, "PICT_a8b8g8r8"}, + {PICT_x8b8g8r8, "PICT_x8b8g8r8"}, +#ifdef PICT_TYPE_BGRA + {PICT_b8g8r8a8, "PICT_b8g8r8a8"}, + {PICT_b8g8r8x8, "PICT_b8g8r8x8"}, + {PICT_a2r10g10b10, "PICT_a2r10g10b10"}, + {PICT_x2r10g10b10, "PICT_x2r10g10b10"}, + {PICT_a2b10g10r10, "PICT_a2b10g10r10"}, + {PICT_x2b10g10r10, "PICT_x2b10g10r10"}, +#endif + {PICT_r8g8b8, "PICT_r8g8b8"}, + {PICT_b8g8r8, "PICT_b8g8r8"}, + {PICT_r5g6b5, "PICT_r5g6b5"}, + {PICT_b5g6r5, "PICT_b5g6r5"}, + {PICT_a1r5g5b5, "PICT_a1r5g5b5"}, + {PICT_x1r5g5b5, "PICT_x1r5g5b5"}, + {PICT_a1b5g5r5, "PICT_a1b5g5r5"}, + {PICT_x1b5g5r5, "PICT_x1b5g5r5"}, + {PICT_a4r4g4b4, "PICT_a4r4g4b4"}, + {PICT_x4r4g4b4, "PICT_x4r4g4b4"}, + {PICT_a4b4g4r4, "PICT_a4b4g4r4"}, + {PICT_x4b4g4r4, "PICT_x4b4g4r4"}, + {PICT_a8, "PICT_a8"}, + {PICT_r3g3b2, "PICT_r3g3b2"}, + {PICT_b2g3r3, "PICT_b2g3r3"}, + {PICT_a2r2g2b2, "PICT_a2r2g2b2"}, + {PICT_a2b2g2r2, "PICT_a2b2g2r2"}, + {PICT_c8, "PICT_c8"}, + {PICT_g8, "PICT_g8"}, + {PICT_x4a4, "PICT_x4a4"}, + {PICT_x4c4, "PICT_x4c4"}, + {PICT_x4g4, "PICT_x4g4"}, + {PICT_a4, "PICT_a4"}, + {PICT_r1g2b1, "PICT_r1g2b1"}, + {PICT_b1g2r1, "PICT_b1g2r1"}, + {PICT_a1r1g1b1, "PICT_a1r1g1b1"}, + {PICT_a1b1g1r1, "PICT_a1b1g1r1"}, + {PICT_c4, "PICT_c4"}, + {PICT_g4, "PICT_g4"}, + {PICT_a1, "PICT_a1"}, + {PICT_g1, "PICT_g1"} +}; +static const char *render_format_name(int format) +{ + int i = 0; + for (i = 0; i < sizeof(formats_info)/sizeof(formats_info[0]); ++i) { + if (formats_info[i].format == format) + return formats_info[i].name; + } + return NULL; +} + +static void +exa_get_pipe_format(int depth, enum pipe_format *format, int *bbp, int *picture_format) +{ + switch (depth) { + case 32: + *format = PIPE_FORMAT_B8G8R8A8_UNORM; + *picture_format = PICT_a8r8g8b8; + assert(*bbp == 32); + break; + case 24: + *format = PIPE_FORMAT_B8G8R8X8_UNORM; + *picture_format = PICT_x8r8g8b8; + assert(*bbp == 32); + break; + case 16: + *format = PIPE_FORMAT_B5G6R5_UNORM; + *picture_format = PICT_r5g6b5; + assert(*bbp == 16); + break; + case 15: + *format = PIPE_FORMAT_B5G5R5A1_UNORM; + *picture_format = PICT_x1r5g5b5; + assert(*bbp == 16); + break; + case 8: + *format = PIPE_FORMAT_L8_UNORM; + *picture_format = PICT_a8; + assert(*bbp == 8); + break; + case 4: + case 1: + *format = PIPE_FORMAT_B8G8R8A8_UNORM; /* bad bad bad */ + break; + default: + assert(0); + break; + } +} + + +/* + * Static exported EXA functions + */ + +static void +ExaWaitMarker(ScreenPtr pScreen, int marker) +{ + /* Nothing to do, handled in the PrepareAccess hook */ +} + +static int +ExaMarkSync(ScreenPtr pScreen) +{ + return 1; +} + + +/*********************************************************************** + * Screen upload/download + */ + +static Bool +ExaDownloadFromScreen(PixmapPtr pPix, int x, int y, int w, int h, char *dst, + int dst_pitch) +{ + ScreenPtr pScreen = pPix->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa = ms->exa; + struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPix); + struct pipe_transfer *transfer; + + if (!priv || !priv->tex) + return FALSE; + + transfer = pipe_get_transfer(exa->pipe, priv->tex, 0, 0, + PIPE_TRANSFER_READ, x, y, w, h); + if (!transfer) + return FALSE; + +#if DEBUG_PRINT + debug_printf("------ ExaDownloadFromScreen(%d, %d, %d, %d, %d)\n", + x, y, w, h, dst_pitch); +#endif + + util_copy_rect((unsigned char*)dst, priv->tex->format, dst_pitch, 0, 0, + w, h, exa->pipe->transfer_map(exa->pipe, transfer), + transfer->stride, 0, 0); + + exa->pipe->transfer_unmap(exa->pipe, transfer); + exa->pipe->transfer_destroy(exa->pipe, transfer); + + return TRUE; +} + +static Bool +ExaUploadToScreen(PixmapPtr pPix, int x, int y, int w, int h, char *src, + int src_pitch) +{ + ScreenPtr pScreen = pPix->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa = ms->exa; + struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPix); + struct pipe_transfer *transfer; + + if (!priv || !priv->tex) + return FALSE; + + transfer = pipe_get_transfer(exa->pipe, priv->tex, 0, 0, + PIPE_TRANSFER_WRITE, x, y, w, h); + if (!transfer) + return FALSE; + +#if DEBUG_PRINT + debug_printf("++++++ ExaUploadToScreen(%d, %d, %d, %d, %d)\n", + x, y, w, h, src_pitch); +#endif + + util_copy_rect(exa->pipe->transfer_map(exa->pipe, transfer), + priv->tex->format, transfer->stride, 0, 0, w, h, + (unsigned char*)src, src_pitch, 0, 0); + + exa->pipe->transfer_unmap(exa->pipe, transfer); + exa->pipe->transfer_destroy(exa->pipe, transfer); + + return TRUE; +} + +static Bool +ExaPrepareAccess(PixmapPtr pPix, int index) +{ + ScreenPtr pScreen = pPix->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa = ms->exa; + struct exa_pixmap_priv *priv; + + priv = exaGetPixmapDriverPrivate(pPix); + + if (!priv) + return FALSE; + + if (!priv->tex) + return FALSE; + + if (priv->map_count == 0) + { + assert(pPix->drawable.width <= priv->tex->width0); + assert(pPix->drawable.height <= priv->tex->height0); + + priv->map_transfer = + pipe_get_transfer(exa->pipe, priv->tex, 0, 0, +#ifdef EXA_MIXED_PIXMAPS + PIPE_TRANSFER_MAP_DIRECTLY | +#endif + PIPE_TRANSFER_READ_WRITE, + 0, 0, + pPix->drawable.width, + pPix->drawable.height ); + if (!priv->map_transfer) +#ifdef EXA_MIXED_PIXMAPS + return FALSE; +#else + FatalError("failed to create transfer\n"); +#endif + + pPix->devPrivate.ptr = + exa->pipe->transfer_map(exa->pipe, priv->map_transfer); + pPix->devKind = priv->map_transfer->stride; + } + + priv->map_count++; + + return TRUE; +} + +static void +ExaFinishAccess(PixmapPtr pPix, int index) +{ + ScreenPtr pScreen = pPix->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa = ms->exa; + struct exa_pixmap_priv *priv; + priv = exaGetPixmapDriverPrivate(pPix); + + if (!priv) + return; + + if (!priv->map_transfer) + return; + + if (--priv->map_count == 0) { + assert(priv->map_transfer); + exa->pipe->transfer_unmap(exa->pipe, priv->map_transfer); + exa->pipe->transfer_destroy(exa->pipe, priv->map_transfer); + priv->map_transfer = NULL; + pPix->devPrivate.ptr = NULL; + } +} + +/*********************************************************************** + * Solid Fills + */ + +static Bool +ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg) +{ + ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap); + struct exa_context *exa = ms->exa; + +#if DEBUG_PRINT + debug_printf("ExaPrepareSolid(0x%x)\n", fg); +#endif + if (!exa->accel) + return FALSE; + + if (!exa->pipe) + XORG_FALLBACK("accle not enabled"); + + if (!priv || !priv->tex) + XORG_FALLBACK("%s", !priv ? "!priv" : "!priv->tex"); + + if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask)) + XORG_FALLBACK("planeMask is not solid"); + + if (alu != GXcopy) + XORG_FALLBACK("not GXcopy"); + + if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format, + priv->tex->target, 0, + PIPE_BIND_RENDER_TARGET, 0)) { + XORG_FALLBACK("format %s", util_format_name(priv->tex->format)); + } + + return xorg_solid_bind_state(exa, priv, fg); +} + +static void +ExaSolid(PixmapPtr pPixmap, int x0, int y0, int x1, int y1) +{ + ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa = ms->exa; + struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap); + +#if DEBUG_PRINT + debug_printf("\tExaSolid(%d, %d, %d, %d)\n", x0, y0, x1, y1); +#endif + + if (x0 == 0 && y0 == 0 && + x1 == pPixmap->drawable.width && y1 == pPixmap->drawable.height) { + exa->pipe->clear(exa->pipe, PIPE_CLEAR_COLOR, exa->solid_color, 0.0, 0); + return; + } + + xorg_solid(exa, priv, x0, y0, x1, y1) ; +} + + +static void +ExaDoneSolid(PixmapPtr pPixmap) +{ + ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap); + struct exa_context *exa = ms->exa; + + if (!priv) + return; + + xorg_composite_done(exa); +} + +/*********************************************************************** + * Copy Blits + */ + +static Bool +ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, + int ydir, int alu, Pixel planeMask) +{ + ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa = ms->exa; + struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pDstPixmap); + struct exa_pixmap_priv *src_priv = exaGetPixmapDriverPrivate(pSrcPixmap); + +#if DEBUG_PRINT + debug_printf("ExaPrepareCopy\n"); +#endif + + if (!exa->accel) + return FALSE; + + if (!exa->pipe) + XORG_FALLBACK("accle not enabled"); + + if (!priv || !priv->tex) + XORG_FALLBACK("pDst %s", !priv ? "!priv" : "!priv->tex"); + + if (!src_priv || !src_priv->tex) + XORG_FALLBACK("pSrc %s", !src_priv ? "!priv" : "!priv->tex"); + + if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask)) + XORG_FALLBACK("planeMask is not solid"); + + if (alu != GXcopy) + XORG_FALLBACK("alu not GXcopy"); + + if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format, + priv->tex->target, 0, + PIPE_BIND_RENDER_TARGET, 0)) + XORG_FALLBACK("pDst format %s", util_format_name(priv->tex->format)); + + if (!exa->scrn->is_format_supported(exa->scrn, src_priv->tex->format, + src_priv->tex->target, 0, + PIPE_BIND_SAMPLER_VIEW, 0)) + XORG_FALLBACK("pSrc format %s", util_format_name(src_priv->tex->format)); + + exa->copy.src = src_priv; + exa->copy.dst = priv; + + /* XXX this used to use resource_copy_region for same-surface copies, + * but they were redefined to not allow overlaps (some of the util code + * always assumed this anyway). + * Drivers should implement accelerated resource_copy_region or it will + * be slow - disable for now. + */ + if (0 && exa->copy.src != exa->copy.dst) { + exa->copy.use_surface_copy = TRUE; + } + else { + struct pipe_surface surf_tmpl; + exa->copy.use_surface_copy = FALSE; + + if (exa->copy.dst == exa->copy.src) + exa->copy.src_texture = renderer_clone_texture( exa->renderer, + exa->copy.src->tex ); + else + pipe_resource_reference(&exa->copy.src_texture, + exa->copy.src->tex); + + memset(&surf_tmpl, 0, sizeof(surf_tmpl)); + u_surface_default_template(&surf_tmpl, exa->copy.dst->tex, + PIPE_BIND_RENDER_TARGET); + exa->copy.dst_surface = + exa->pipe->create_surface(exa->pipe, + exa->copy.dst->tex, + &surf_tmpl); + + + renderer_copy_prepare(exa->renderer, + exa->copy.dst_surface, + exa->copy.src_texture ); + } + + + return TRUE; +} + +static void +ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY, + int width, int height) +{ + ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa = ms->exa; + struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pDstPixmap); + +#if DEBUG_PRINT + debug_printf("\tExaCopy(srcx=%d, srcy=%d, dstX=%d, dstY=%d, w=%d, h=%d)\n", + srcX, srcY, dstX, dstY, width, height); +#endif + + debug_assert(priv == exa->copy.dst); + (void) priv; + + if (exa->copy.use_surface_copy) { + struct pipe_box src_box; + u_box_2d(srcX, srcY, width, height, &src_box); + exa->pipe->resource_copy_region( exa->pipe, + exa->copy.dst->tex, + 0, + dstX, dstY, 0, + exa->copy.src->tex, + 0, &src_box); + } + else { + renderer_copy_pixmap(exa->renderer, + dstX, dstY, + srcX, srcY, + width, height, + exa->copy.src_texture->width0, + exa->copy.src_texture->height0); + } +} + +static void +ExaDoneCopy(PixmapPtr pPixmap) +{ + ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap); + struct exa_context *exa = ms->exa; + + if (!priv) + return; + + renderer_draw_flush(exa->renderer); + + exa->copy.src = NULL; + exa->copy.dst = NULL; + pipe_surface_reference(&exa->copy.dst_surface, NULL); + pipe_resource_reference(&exa->copy.src_texture, NULL); +} + + + +static Bool +picture_check_formats(struct exa_pixmap_priv *pSrc, PicturePtr pSrcPicture) +{ + if (pSrc->picture_format == pSrcPicture->format) + return TRUE; + + if (pSrc->picture_format != PICT_a8r8g8b8) + return FALSE; + + /* pSrc->picture_format == PICT_a8r8g8b8 */ + switch (pSrcPicture->format) { + case PICT_a8r8g8b8: + case PICT_x8r8g8b8: + case PICT_a8b8g8r8: + case PICT_x8b8g8r8: + /* just treat these two as x8... */ + case PICT_r8g8b8: + case PICT_b8g8r8: + return TRUE; +#ifdef PICT_TYPE_BGRA + case PICT_b8g8r8a8: + case PICT_b8g8r8x8: + return FALSE; /* does not support swizzleing the alpha channel yet */ + case PICT_a2r10g10b10: + case PICT_x2r10g10b10: + case PICT_a2b10g10r10: + case PICT_x2b10g10r10: + return FALSE; +#endif + default: + return FALSE; + } + return FALSE; +} + +/*********************************************************************** + * Composite entrypoints + */ + +static Bool +ExaCheckComposite(int op, + PicturePtr pSrcPicture, PicturePtr pMaskPicture, + PicturePtr pDstPicture) +{ + ScrnInfoPtr pScrn = xf86Screens[pDstPicture->pDrawable->pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa = ms->exa; + +#if DEBUG_PRINT + debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n", + op, pSrcPicture, pMaskPicture, pDstPicture, accelerated); +#endif + + if (!exa->accel) + return FALSE; + + return xorg_composite_accelerated(op, + pSrcPicture, + pMaskPicture, + pDstPicture); +} + + +static Bool +ExaPrepareComposite(int op, PicturePtr pSrcPicture, + PicturePtr pMaskPicture, PicturePtr pDstPicture, + PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst) +{ + ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa = ms->exa; + struct exa_pixmap_priv *priv; + + if (!exa->accel) + return FALSE; + +#if DEBUG_PRINT + debug_printf("ExaPrepareComposite(%d, src=0x%p, mask=0x%p, dst=0x%p)\n", + op, pSrcPicture, pMaskPicture, pDstPicture); + debug_printf("\tFormats: src(%s), mask(%s), dst(%s)\n", + pSrcPicture ? render_format_name(pSrcPicture->format) : "none", + pMaskPicture ? render_format_name(pMaskPicture->format) : "none", + pDstPicture ? render_format_name(pDstPicture->format) : "none"); +#endif + if (!exa->pipe) + XORG_FALLBACK("accle not enabled"); + + priv = exaGetPixmapDriverPrivate(pDst); + if (!priv || !priv->tex) + XORG_FALLBACK("pDst %s", !priv ? "!priv" : "!priv->tex"); + + if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format, + priv->tex->target, 0, + PIPE_BIND_RENDER_TARGET, 0)) + XORG_FALLBACK("pDst format: %s", util_format_name(priv->tex->format)); + + if (priv->picture_format != pDstPicture->format) + XORG_FALLBACK("pDst pic_format: %s != %s", + render_format_name(priv->picture_format), + render_format_name(pDstPicture->format)); + + if (pSrc) { + priv = exaGetPixmapDriverPrivate(pSrc); + if (!priv || !priv->tex) + XORG_FALLBACK("pSrc %s", !priv ? "!priv" : "!priv->tex"); + + if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format, + priv->tex->target, 0, + PIPE_BIND_SAMPLER_VIEW, 0)) + XORG_FALLBACK("pSrc format: %s", util_format_name(priv->tex->format)); + + if (!picture_check_formats(priv, pSrcPicture)) + XORG_FALLBACK("pSrc pic_format: %s != %s", + render_format_name(priv->picture_format), + render_format_name(pSrcPicture->format)); + + } + + if (pMask) { + priv = exaGetPixmapDriverPrivate(pMask); + if (!priv || !priv->tex) + XORG_FALLBACK("pMask %s", !priv ? "!priv" : "!priv->tex"); + + if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format, + priv->tex->target, 0, + PIPE_BIND_SAMPLER_VIEW, 0)) + XORG_FALLBACK("pMask format: %s", util_format_name(priv->tex->format)); + + if (!picture_check_formats(priv, pMaskPicture)) + XORG_FALLBACK("pMask pic_format: %s != %s", + render_format_name(priv->picture_format), + render_format_name(pMaskPicture->format)); + } + + return xorg_composite_bind_state(exa, op, pSrcPicture, pMaskPicture, + pDstPicture, + pSrc ? exaGetPixmapDriverPrivate(pSrc) : NULL, + pMask ? exaGetPixmapDriverPrivate(pMask) : NULL, + exaGetPixmapDriverPrivate(pDst)); +} + +static void +ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY, + int dstX, int dstY, int width, int height) +{ + ScrnInfoPtr pScrn = xf86Screens[pDst->drawable.pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa = ms->exa; + struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pDst); + +#if DEBUG_PRINT + debug_printf("\tExaComposite(src[%d,%d], mask=[%d, %d], dst=[%d, %d], dim=[%d, %d])\n", + srcX, srcY, maskX, maskY, dstX, dstY, width, height); + debug_printf("\t Num bound samplers = %d\n", + exa->num_bound_samplers); +#endif + + xorg_composite(exa, priv, srcX, srcY, maskX, maskY, + dstX, dstY, width, height); +} + + + +static void +ExaDoneComposite(PixmapPtr pPixmap) +{ + ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa = ms->exa; + + xorg_composite_done(exa); +} + + +/*********************************************************************** + * Pixmaps + */ + +static void * +ExaCreatePixmap(ScreenPtr pScreen, int size, int align) +{ + struct exa_pixmap_priv *priv; + + priv = calloc(1, sizeof(struct exa_pixmap_priv)); + if (!priv) + return NULL; + + return priv; +} + +static void +ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv) +{ + struct exa_pixmap_priv *priv = (struct exa_pixmap_priv *)dPriv; + + if (!priv) + return; + + pipe_resource_reference(&priv->tex, NULL); + + free(priv); +} + +static Bool +ExaPixmapIsOffscreen(PixmapPtr pPixmap) +{ + struct exa_pixmap_priv *priv; + + priv = exaGetPixmapDriverPrivate(pPixmap); + + if (!priv) + return FALSE; + + if (priv->tex) + return TRUE; + + return FALSE; +} + +int +xorg_exa_set_displayed_usage(PixmapPtr pPixmap) +{ + struct exa_pixmap_priv *priv; + priv = exaGetPixmapDriverPrivate(pPixmap); + + if (!priv) { + FatalError("NO PIXMAP PRIVATE\n"); + return 0; + } + + priv->flags |= PIPE_BIND_SCANOUT; + + return 0; +} + +int +xorg_exa_set_shared_usage(PixmapPtr pPixmap) +{ + struct exa_pixmap_priv *priv; + priv = exaGetPixmapDriverPrivate(pPixmap); + + if (!priv) { + FatalError("NO PIXMAP PRIVATE\n"); + return 0; + } + + priv->flags |= PIPE_BIND_SHARED; + + return 0; +} + + + +static Bool +size_match( int width, int tex_width ) +{ +#if ROUND_UP_TEXTURES + if (width > tex_width) + return FALSE; + + if (width * 2 < tex_width) + return FALSE; + + return TRUE; +#else + return width == tex_width; +#endif +} + +static Bool +ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, + int depth, int bitsPerPixel, int devKind, + pointer pPixData) +{ + ScreenPtr pScreen = pPixmap->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap); + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa = ms->exa; + + if (!priv || pPixData) + return FALSE; + + if (0) { + debug_printf("%s pixmap %p sz %dx%dx%d devKind %d\n", + __FUNCTION__, pPixmap, width, height, bitsPerPixel, devKind); + + if (priv->tex) + debug_printf(" ==> old texture %dx%d\n", + priv->tex->width0, + priv->tex->height0); + } + + + if (depth <= 0) + depth = pPixmap->drawable.depth; + + if (bitsPerPixel <= 0) + bitsPerPixel = pPixmap->drawable.bitsPerPixel; + + if (width <= 0) + width = pPixmap->drawable.width; + + if (height <= 0) + height = pPixmap->drawable.height; + + if (width <= 0 || height <= 0 || depth <= 0) + return FALSE; + + miModifyPixmapHeader(pPixmap, width, height, depth, + bitsPerPixel, devKind, NULL); + + priv->width = width; + priv->height = height; + + /* Deal with screen resize */ + if ((exa->accel || priv->flags) && + (!priv->tex || + !size_match(width, priv->tex->width0) || + !size_match(height, priv->tex->height0) || + priv->tex_flags != priv->flags)) { + struct pipe_resource *texture = NULL; + struct pipe_resource template; + + memset(&template, 0, sizeof(template)); + template.target = PIPE_TEXTURE_2D; + exa_get_pipe_format(depth, &template.format, &bitsPerPixel, &priv->picture_format); + if (ROUND_UP_TEXTURES && priv->flags == 0) { + template.width0 = util_next_power_of_two(width); + template.height0 = util_next_power_of_two(height); + } + else { + template.width0 = width; + template.height0 = height; + } + + template.depth0 = 1; + template.array_size = 1; + template.last_level = 0; + template.bind = PIPE_BIND_RENDER_TARGET | priv->flags; + priv->tex_flags = priv->flags; + texture = exa->scrn->resource_create(exa->scrn, &template); + + if (priv->tex) { + struct pipe_box src_box; + u_box_origin_2d(min(width, texture->width0), + min(height, texture->height0), + &src_box); + exa->pipe->resource_copy_region(exa->pipe, texture, + 0, 0, 0, 0, + priv->tex, + 0, &src_box); + } + + pipe_resource_reference(&priv->tex, texture); + /* the texture we create has one reference */ + pipe_resource_reference(&texture, NULL); + } + + return TRUE; +} + +struct pipe_resource * +xorg_exa_get_texture(PixmapPtr pPixmap) +{ + struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap); + struct pipe_resource *tex = NULL; + pipe_resource_reference(&tex, priv->tex); + return tex; +} + +Bool +xorg_exa_set_texture(PixmapPtr pPixmap, struct pipe_resource *tex) +{ + struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap); + + int mask = PIPE_BIND_SHARED | PIPE_BIND_SCANOUT; + + if (!priv) + return FALSE; + + if (pPixmap->drawable.width != tex->width0 || + pPixmap->drawable.height != tex->height0) + return FALSE; + + pipe_resource_reference(&priv->tex, tex); + priv->tex_flags = tex->bind & mask; + + return TRUE; +} + +struct pipe_resource * +xorg_exa_create_root_texture(ScrnInfoPtr pScrn, + int width, int height, + int depth, int bitsPerPixel) +{ + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa = ms->exa; + struct pipe_resource template; + int dummy; + + memset(&template, 0, sizeof(template)); + template.target = PIPE_TEXTURE_2D; + exa_get_pipe_format(depth, &template.format, &bitsPerPixel, &dummy); + template.width0 = width; + template.height0 = height; + template.depth0 = 1; + template.array_size = 1; + template.last_level = 0; + template.bind |= PIPE_BIND_RENDER_TARGET; + template.bind |= PIPE_BIND_SCANOUT; + template.bind |= PIPE_BIND_SHARED; + + return exa->scrn->resource_create(exa->scrn, &template); +} + +void +xorg_exa_close(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa = ms->exa; + + pipe_sampler_view_reference(&exa->bound_sampler_views[0], NULL); + pipe_sampler_view_reference(&exa->bound_sampler_views[1], NULL); + + renderer_destroy(exa->renderer); + + xorg_exa_finish(exa); + + if (exa->pipe) + exa->pipe->destroy(exa->pipe); + exa->pipe = NULL; + /* Since this was shared be proper with the pointer */ + ms->ctx = NULL; + + exaDriverFini(pScrn->pScreen); + free(exa); + ms->exa = NULL; +} + +void * +xorg_exa_init(ScrnInfoPtr pScrn, Bool accel) +{ + modesettingPtr ms = modesettingPTR(pScrn); + struct exa_context *exa; + ExaDriverPtr pExa; + CustomizerPtr cust = ms->cust; + + exa = calloc(1, sizeof(struct exa_context)); + if (!exa) + return NULL; + + pExa = exaDriverAlloc(); + if (!pExa) { + goto out_err; + } + + memset(pExa, 0, sizeof(*pExa)); + + pExa->exa_major = 2; + pExa->exa_minor = 2; + pExa->memoryBase = 0; + pExa->memorySize = 0; + pExa->offScreenBase = 0; + pExa->pixmapOffsetAlign = 0; + pExa->pixmapPitchAlign = 1; + pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS; +#ifdef EXA_SUPPORTS_PREPARE_AUX + pExa->flags |= EXA_SUPPORTS_PREPARE_AUX; +#endif +#ifdef EXA_MIXED_PIXMAPS + pExa->flags |= EXA_MIXED_PIXMAPS; +#endif + pExa->maxX = 8191; /* FIXME */ + pExa->maxY = 8191; /* FIXME */ + + pExa->WaitMarker = ExaWaitMarker; + pExa->MarkSync = ExaMarkSync; + pExa->PrepareSolid = ExaPrepareSolid; + pExa->Solid = ExaSolid; + pExa->DoneSolid = ExaDoneSolid; + pExa->PrepareCopy = ExaPrepareCopy; + pExa->Copy = ExaCopy; + pExa->DoneCopy = ExaDoneCopy; + pExa->CheckComposite = ExaCheckComposite; + pExa->PrepareComposite = ExaPrepareComposite; + pExa->Composite = ExaComposite; + pExa->DoneComposite = ExaDoneComposite; + pExa->PixmapIsOffscreen = ExaPixmapIsOffscreen; + pExa->DownloadFromScreen = ExaDownloadFromScreen; + pExa->UploadToScreen = ExaUploadToScreen; + pExa->PrepareAccess = ExaPrepareAccess; + pExa->FinishAccess = ExaFinishAccess; + pExa->CreatePixmap = ExaCreatePixmap; + pExa->DestroyPixmap = ExaDestroyPixmap; + pExa->ModifyPixmapHeader = ExaModifyPixmapHeader; + + if (!exaDriverInit(pScrn->pScreen, pExa)) { + goto out_err; + } + + exa->scrn = ms->screen; + exa->pipe = exa->scrn->context_create(exa->scrn, NULL); + if (exa->pipe == NULL) + goto out_err; + + /* Share context with DRI */ + ms->ctx = exa->pipe; + if (cust && cust->winsys_context_throttle) + cust->winsys_context_throttle(cust, ms->ctx, THROTTLE_RENDER); + + exa->renderer = renderer_create(exa->pipe); + exa->accel = accel; + + return (void *)exa; + +out_err: + xorg_exa_close(pScrn); + free(exa); + + return NULL; +} + +struct pipe_surface * +xorg_gpu_surface(struct pipe_context *pipe, struct exa_pixmap_priv *priv) +{ + struct pipe_surface surf_tmpl; + memset(&surf_tmpl, 0, sizeof(surf_tmpl)); + u_surface_default_template(&surf_tmpl, priv->tex, + PIPE_BIND_RENDER_TARGET); + + return pipe->create_surface(pipe, priv->tex, &surf_tmpl); + +} + +void xorg_exa_flush(struct exa_context *exa, uint pipeFlushFlags, + struct pipe_fence_handle **fence) +{ + exa->pipe->flush(exa->pipe, pipeFlushFlags, fence); +} + +void xorg_exa_finish(struct exa_context *exa) +{ + struct pipe_fence_handle *fence = NULL; + + xorg_exa_flush(exa, PIPE_FLUSH_RENDER_CACHE, &fence); + + exa->pipe->screen->fence_finish(exa->pipe->screen, fence, 0); + exa->pipe->screen->fence_reference(exa->pipe->screen, &fence, NULL); +} + diff --git a/src/gallium/state_trackers/xorg/xorg_exa.h b/src/gallium/state_trackers/xorg/xorg_exa.h new file mode 100644 index 0000000..1f78f60 --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_exa.h @@ -0,0 +1,81 @@ +#ifndef XORG_EXA_H +#define XORG_EXA_H + +#include "xorg_tracker.h" + +#include + +struct cso_context; +struct xorg_shaders; + +/* src + mask + dst */ +#define MAX_EXA_SAMPLERS 3 + +struct exa_context +{ + ExaDriverPtr pExa; + struct pipe_context *pipe; + struct pipe_screen *scrn; + struct xorg_renderer *renderer; + + struct pipe_sampler_view *bound_sampler_views[MAX_EXA_SAMPLERS]; + int num_bound_samplers; + + float solid_color[4]; + boolean has_solid_color; + + boolean accel; + + /* float[9] projective matrix bound to pictures */ + struct { + float src[9]; + float mask[9]; + boolean has_src; + boolean has_mask; + } transform; + + struct { + boolean use_surface_copy; + + struct exa_pixmap_priv *src; + struct exa_pixmap_priv *dst; + + struct pipe_surface *dst_surface; + + struct pipe_resource *src_texture; + } copy; +}; + +struct exa_pixmap_priv +{ + int width, height; + + int flags; + int tex_flags; + + int picture_format; + + struct pipe_resource *tex; + struct pipe_resource *depth_stencil_tex; + + struct pipe_transfer *map_transfer; + unsigned map_count; +}; + +#define XORG_FALLBACK(s, arg...) \ +do { \ + if (ms->debug_fallback) { \ + xf86DrvMsg(pScrn->scrnIndex, X_INFO, \ + "%s fallback " s "\n", __FUNCTION__, ##arg); \ + } \ + return FALSE; \ +} while(0) + +struct pipe_surface * +xorg_gpu_surface(struct pipe_context *pipe, struct exa_pixmap_priv *priv); + +void xorg_exa_flush(struct exa_context *exa, uint pipeFlushFlags, + struct pipe_fence_handle **fence); +void xorg_exa_finish(struct exa_context *exa); + +#endif diff --git a/src/gallium/state_trackers/xorg/xorg_exa_tgsi.c b/src/gallium/state_trackers/xorg/xorg_exa_tgsi.c new file mode 100644 index 0000000..fe1aab3 --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_exa_tgsi.c @@ -0,0 +1,690 @@ +#include "xorg_exa_tgsi.h" + +/*### stupidity defined in X11/extensions/XI.h */ +#undef Absolute + +#include "pipe/p_format.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "pipe/p_shader_tokens.h" + +#include "util/u_memory.h" + +#include "tgsi/tgsi_ureg.h" + +#include "cso_cache/cso_context.h" +#include "cso_cache/cso_hash.h" + +/* Vertex shader: + * IN[0] = vertex pos + * IN[1] = src tex coord | solid fill color + * IN[2] = mask tex coord + * IN[3] = dst tex coord + * CONST[0] = (2/dst_width, 2/dst_height, 1, 1) + * CONST[1] = (-1, -1, 0, 0) + * + * OUT[0] = vertex pos + * OUT[1] = src tex coord | solid fill color + * OUT[2] = mask tex coord + * OUT[3] = dst tex coord + */ + +/* Fragment shader: + * SAMP[0] = src + * SAMP[1] = mask + * SAMP[2] = dst + * IN[0] = pos src | solid fill color + * IN[1] = pos mask + * IN[2] = pos dst + * CONST[0] = (0, 0, 0, 1) + * + * OUT[0] = color + */ + +static void +print_fs_traits(int fs_traits) +{ + const char *strings[] = { + "FS_COMPOSITE", /* = 1 << 0, */ + "FS_MASK", /* = 1 << 1, */ + "FS_SOLID_FILL", /* = 1 << 2, */ + "FS_LINGRAD_FILL", /* = 1 << 3, */ + "FS_RADGRAD_FILL", /* = 1 << 4, */ + "FS_CA_FULL", /* = 1 << 5, */ /* src.rgba * mask.rgba */ + "FS_CA_SRCALPHA", /* = 1 << 6, */ /* src.aaaa * mask.rgba */ + "FS_YUV", /* = 1 << 7, */ + "FS_SRC_REPEAT_NONE", /* = 1 << 8, */ + "FS_MASK_REPEAT_NONE",/* = 1 << 9, */ + "FS_SRC_SWIZZLE_RGB", /* = 1 << 10, */ + "FS_MASK_SWIZZLE_RGB",/* = 1 << 11, */ + "FS_SRC_SET_ALPHA", /* = 1 << 12, */ + "FS_MASK_SET_ALPHA", /* = 1 << 13, */ + "FS_SRC_LUMINANCE", /* = 1 << 14, */ + "FS_MASK_LUMINANCE", /* = 1 << 15, */ + }; + int i, k; + debug_printf("%s: ", __func__); + + for (i = 0, k = 1; k < (1 << 16); i++, k <<= 1) { + if (fs_traits & k) + debug_printf("%s, ", strings[i]); + } + + debug_printf("\n"); +} + +struct xorg_shaders { + struct xorg_renderer *r; + + struct cso_hash *vs_hash; + struct cso_hash *fs_hash; +}; + +static INLINE void +src_in_mask(struct ureg_program *ureg, + struct ureg_dst dst, + struct ureg_src src, + struct ureg_src mask, + unsigned component_alpha, + unsigned mask_luminance) +{ + if (component_alpha == FS_CA_FULL) { + ureg_MUL(ureg, dst, src, mask); + } else if (component_alpha == FS_CA_SRCALPHA) { + ureg_MUL(ureg, dst, + ureg_scalar(src, TGSI_SWIZZLE_W), mask); + } + else { + if (mask_luminance) + ureg_MUL(ureg, dst, src, + ureg_scalar(mask, TGSI_SWIZZLE_X)); + else + ureg_MUL(ureg, dst, src, + ureg_scalar(mask, TGSI_SWIZZLE_W)); + } +} + +static struct ureg_src +vs_normalize_coords(struct ureg_program *ureg, struct ureg_src coords, + struct ureg_src const0, struct ureg_src const1) +{ + struct ureg_dst tmp = ureg_DECL_temporary(ureg); + struct ureg_src ret; + ureg_MAD(ureg, tmp, coords, const0, const1); + ret = ureg_src(tmp); + ureg_release_temporary(ureg, tmp); + return ret; +} + +static void +linear_gradient(struct ureg_program *ureg, + struct ureg_dst out, + struct ureg_src pos, + struct ureg_src sampler, + struct ureg_src coords, + struct ureg_src const0124, + struct ureg_src matrow0, + struct ureg_src matrow1, + struct ureg_src matrow2) +{ + struct ureg_dst temp0 = ureg_DECL_temporary(ureg); + struct ureg_dst temp1 = ureg_DECL_temporary(ureg); + struct ureg_dst temp2 = ureg_DECL_temporary(ureg); + struct ureg_dst temp3 = ureg_DECL_temporary(ureg); + struct ureg_dst temp4 = ureg_DECL_temporary(ureg); + struct ureg_dst temp5 = ureg_DECL_temporary(ureg); + + ureg_MOV(ureg, + ureg_writemask(temp0, TGSI_WRITEMASK_XY), pos); + ureg_MOV(ureg, + ureg_writemask(temp0, TGSI_WRITEMASK_Z), + ureg_scalar(const0124, TGSI_SWIZZLE_Y)); + + ureg_DP3(ureg, temp1, matrow0, ureg_src(temp0)); + ureg_DP3(ureg, temp2, matrow1, ureg_src(temp0)); + ureg_DP3(ureg, temp3, matrow2, ureg_src(temp0)); + ureg_RCP(ureg, temp3, ureg_src(temp3)); + ureg_MUL(ureg, temp1, ureg_src(temp1), ureg_src(temp3)); + ureg_MUL(ureg, temp2, ureg_src(temp2), ureg_src(temp3)); + + ureg_MOV(ureg, ureg_writemask(temp4, TGSI_WRITEMASK_X), + ureg_src(temp1)); + ureg_MOV(ureg, ureg_writemask(temp4, TGSI_WRITEMASK_Y), + ureg_src(temp2)); + + ureg_MUL(ureg, temp0, + ureg_scalar(coords, TGSI_SWIZZLE_Y), + ureg_scalar(ureg_src(temp4), TGSI_SWIZZLE_Y)); + ureg_MAD(ureg, temp1, + ureg_scalar(coords, TGSI_SWIZZLE_X), + ureg_scalar(ureg_src(temp4), TGSI_SWIZZLE_X), + ureg_src(temp0)); + + ureg_MUL(ureg, temp2, + ureg_src(temp1), + ureg_scalar(coords, TGSI_SWIZZLE_Z)); + + ureg_TEX(ureg, out, + TGSI_TEXTURE_1D, ureg_src(temp2), sampler); + + ureg_release_temporary(ureg, temp0); + ureg_release_temporary(ureg, temp1); + ureg_release_temporary(ureg, temp2); + ureg_release_temporary(ureg, temp3); + ureg_release_temporary(ureg, temp4); + ureg_release_temporary(ureg, temp5); +} + + +static void +radial_gradient(struct ureg_program *ureg, + struct ureg_dst out, + struct ureg_src pos, + struct ureg_src sampler, + struct ureg_src coords, + struct ureg_src const0124, + struct ureg_src matrow0, + struct ureg_src matrow1, + struct ureg_src matrow2) +{ + struct ureg_dst temp0 = ureg_DECL_temporary(ureg); + struct ureg_dst temp1 = ureg_DECL_temporary(ureg); + struct ureg_dst temp2 = ureg_DECL_temporary(ureg); + struct ureg_dst temp3 = ureg_DECL_temporary(ureg); + struct ureg_dst temp4 = ureg_DECL_temporary(ureg); + struct ureg_dst temp5 = ureg_DECL_temporary(ureg); + + ureg_MOV(ureg, + ureg_writemask(temp0, TGSI_WRITEMASK_XY), + pos); + ureg_MOV(ureg, + ureg_writemask(temp0, TGSI_WRITEMASK_Z), + ureg_scalar(const0124, TGSI_SWIZZLE_Y)); + + ureg_DP3(ureg, temp1, matrow0, ureg_src(temp0)); + ureg_DP3(ureg, temp2, matrow1, ureg_src(temp0)); + ureg_DP3(ureg, temp3, matrow2, ureg_src(temp0)); + ureg_RCP(ureg, temp3, ureg_src(temp3)); + ureg_MUL(ureg, temp1, ureg_src(temp1), ureg_src(temp3)); + ureg_MUL(ureg, temp2, ureg_src(temp2), ureg_src(temp3)); + + ureg_MOV(ureg, ureg_writemask(temp5, TGSI_WRITEMASK_X), + ureg_src(temp1)); + ureg_MOV(ureg, ureg_writemask(temp5, TGSI_WRITEMASK_Y), + ureg_src(temp2)); + + ureg_MUL(ureg, temp0, ureg_scalar(coords, TGSI_SWIZZLE_Y), + ureg_scalar(ureg_src(temp5), TGSI_SWIZZLE_Y)); + ureg_MAD(ureg, temp1, + ureg_scalar(coords, TGSI_SWIZZLE_X), + ureg_scalar(ureg_src(temp5), TGSI_SWIZZLE_X), + ureg_src(temp0)); + ureg_ADD(ureg, temp1, + ureg_src(temp1), ureg_src(temp1)); + ureg_MUL(ureg, temp3, + ureg_scalar(ureg_src(temp5), TGSI_SWIZZLE_Y), + ureg_scalar(ureg_src(temp5), TGSI_SWIZZLE_Y)); + ureg_MAD(ureg, temp4, + ureg_scalar(ureg_src(temp5), TGSI_SWIZZLE_X), + ureg_scalar(ureg_src(temp5), TGSI_SWIZZLE_X), + ureg_src(temp3)); + ureg_MOV(ureg, temp4, ureg_negate(ureg_src(temp4))); + ureg_MUL(ureg, temp2, + ureg_scalar(coords, TGSI_SWIZZLE_Z), + ureg_src(temp4)); + ureg_MUL(ureg, temp0, + ureg_scalar(const0124, TGSI_SWIZZLE_W), + ureg_src(temp2)); + ureg_MUL(ureg, temp3, + ureg_src(temp1), ureg_src(temp1)); + ureg_SUB(ureg, temp2, + ureg_src(temp3), ureg_src(temp0)); + ureg_RSQ(ureg, temp2, ureg_abs(ureg_src(temp2))); + ureg_RCP(ureg, temp2, ureg_src(temp2)); + ureg_SUB(ureg, temp1, + ureg_src(temp2), ureg_src(temp1)); + ureg_ADD(ureg, temp0, + ureg_scalar(coords, TGSI_SWIZZLE_Z), + ureg_scalar(coords, TGSI_SWIZZLE_Z)); + ureg_RCP(ureg, temp0, ureg_src(temp0)); + ureg_MUL(ureg, temp2, + ureg_src(temp1), ureg_src(temp0)); + ureg_TEX(ureg, out, TGSI_TEXTURE_1D, + ureg_src(temp2), sampler); + + ureg_release_temporary(ureg, temp0); + ureg_release_temporary(ureg, temp1); + ureg_release_temporary(ureg, temp2); + ureg_release_temporary(ureg, temp3); + ureg_release_temporary(ureg, temp4); + ureg_release_temporary(ureg, temp5); +} + +static void * +create_vs(struct pipe_context *pipe, + unsigned vs_traits) +{ + struct ureg_program *ureg; + struct ureg_src src; + struct ureg_dst dst; + struct ureg_src const0, const1; + boolean is_fill = (vs_traits & VS_FILL) != 0; + boolean is_composite = (vs_traits & VS_COMPOSITE) != 0; + boolean has_mask = (vs_traits & VS_MASK) != 0; + boolean is_yuv = (vs_traits & VS_YUV) != 0; + unsigned input_slot = 0; + + ureg = ureg_create(TGSI_PROCESSOR_VERTEX); + if (ureg == NULL) + return 0; + + const0 = ureg_DECL_constant(ureg, 0); + const1 = ureg_DECL_constant(ureg, 1); + + /* it has to be either a fill or a composite op */ + debug_assert((is_fill ^ is_composite) ^ is_yuv); + + src = ureg_DECL_vs_input(ureg, input_slot++); + dst = ureg_DECL_output(ureg, TGSI_SEMANTIC_POSITION, 0); + src = vs_normalize_coords(ureg, src, + const0, const1); + ureg_MOV(ureg, dst, src); + + if (is_yuv) { + src = ureg_DECL_vs_input(ureg, input_slot++); + dst = ureg_DECL_output(ureg, TGSI_SEMANTIC_GENERIC, 0); + ureg_MOV(ureg, dst, src); + } + + if (is_composite) { + src = ureg_DECL_vs_input(ureg, input_slot++); + dst = ureg_DECL_output(ureg, TGSI_SEMANTIC_GENERIC, 0); + ureg_MOV(ureg, dst, src); + } + + if (is_fill) { + src = ureg_DECL_vs_input(ureg, input_slot++); + dst = ureg_DECL_output(ureg, TGSI_SEMANTIC_COLOR, 0); + ureg_MOV(ureg, dst, src); + } + + if (has_mask) { + src = ureg_DECL_vs_input(ureg, input_slot++); + dst = ureg_DECL_output(ureg, TGSI_SEMANTIC_GENERIC, 1); + ureg_MOV(ureg, dst, src); + } + + ureg_END(ureg); + + return ureg_create_shader_and_destroy(ureg, pipe); +} + +static void * +create_yuv_shader(struct pipe_context *pipe, struct ureg_program *ureg) +{ + struct ureg_src y_sampler, u_sampler, v_sampler; + struct ureg_src pos; + struct ureg_src matrow0, matrow1, matrow2; + struct ureg_dst y, u, v, rgb; + struct ureg_dst out = ureg_DECL_output(ureg, + TGSI_SEMANTIC_COLOR, + 0); + + pos = ureg_DECL_fs_input(ureg, + TGSI_SEMANTIC_GENERIC, + 0, + TGSI_INTERPOLATE_PERSPECTIVE); + + rgb = ureg_DECL_temporary(ureg); + y = ureg_DECL_temporary(ureg); + u = ureg_DECL_temporary(ureg); + v = ureg_DECL_temporary(ureg); + + y_sampler = ureg_DECL_sampler(ureg, 0); + u_sampler = ureg_DECL_sampler(ureg, 1); + v_sampler = ureg_DECL_sampler(ureg, 2); + + matrow0 = ureg_DECL_constant(ureg, 0); + matrow1 = ureg_DECL_constant(ureg, 1); + matrow2 = ureg_DECL_constant(ureg, 2); + + ureg_TEX(ureg, y, + TGSI_TEXTURE_2D, pos, y_sampler); + ureg_TEX(ureg, u, + TGSI_TEXTURE_2D, pos, u_sampler); + ureg_TEX(ureg, v, + TGSI_TEXTURE_2D, pos, v_sampler); + + ureg_SUB(ureg, u, ureg_src(u), + ureg_scalar(matrow0, TGSI_SWIZZLE_W)); + ureg_SUB(ureg, v, ureg_src(v), + ureg_scalar(matrow0, TGSI_SWIZZLE_W)); + + ureg_MUL(ureg, rgb, + ureg_scalar(ureg_src(y), TGSI_SWIZZLE_X), + matrow0); + ureg_MAD(ureg, rgb, + ureg_scalar(ureg_src(u), TGSI_SWIZZLE_X), + matrow1, + ureg_src(rgb)); + ureg_MAD(ureg, rgb, + ureg_scalar(ureg_src(v), TGSI_SWIZZLE_X), + matrow2, + ureg_src(rgb)); + + /* rgb.a = 1; */ + ureg_MOV(ureg, ureg_writemask(rgb, TGSI_WRITEMASK_W), + ureg_scalar(matrow0, TGSI_SWIZZLE_X)); + + ureg_MOV(ureg, out, ureg_src(rgb)); + + ureg_release_temporary(ureg, rgb); + ureg_release_temporary(ureg, y); + ureg_release_temporary(ureg, u); + ureg_release_temporary(ureg, v); + + ureg_END(ureg); + + return ureg_create_shader_and_destroy(ureg, pipe); +} + + +static INLINE void +xrender_tex(struct ureg_program *ureg, + struct ureg_dst dst, + struct ureg_src coords, + struct ureg_src sampler, + struct ureg_src imm0, + boolean repeat_none, + boolean swizzle, + boolean set_alpha) +{ + if (repeat_none) { + struct ureg_dst tmp0 = ureg_DECL_temporary(ureg); + struct ureg_dst tmp1 = ureg_DECL_temporary(ureg); + ureg_SGT(ureg, tmp1, ureg_swizzle(coords, + TGSI_SWIZZLE_X, + TGSI_SWIZZLE_Y, + TGSI_SWIZZLE_X, + TGSI_SWIZZLE_Y), + ureg_scalar(imm0, TGSI_SWIZZLE_X)); + ureg_SLT(ureg, tmp0, ureg_swizzle(coords, + TGSI_SWIZZLE_X, + TGSI_SWIZZLE_Y, + TGSI_SWIZZLE_X, + TGSI_SWIZZLE_Y), + ureg_scalar(imm0, TGSI_SWIZZLE_W)); + ureg_MIN(ureg, tmp0, ureg_src(tmp0), ureg_src(tmp1)); + ureg_MIN(ureg, tmp0, ureg_scalar(ureg_src(tmp0), TGSI_SWIZZLE_X), + ureg_scalar(ureg_src(tmp0), TGSI_SWIZZLE_Y)); + ureg_TEX(ureg, tmp1, TGSI_TEXTURE_2D, coords, sampler); + if (swizzle) + ureg_MOV(ureg, tmp1, ureg_swizzle(ureg_src(tmp1), + TGSI_SWIZZLE_Z, + TGSI_SWIZZLE_Y, + TGSI_SWIZZLE_X, + TGSI_SWIZZLE_W)); + if (set_alpha) + ureg_MOV(ureg, + ureg_writemask(tmp1, TGSI_WRITEMASK_W), + ureg_scalar(imm0, TGSI_SWIZZLE_W)); + ureg_MUL(ureg, dst, ureg_src(tmp1), ureg_src(tmp0)); + ureg_release_temporary(ureg, tmp0); + ureg_release_temporary(ureg, tmp1); + } else { + if (swizzle) { + struct ureg_dst tmp = ureg_DECL_temporary(ureg); + ureg_TEX(ureg, tmp, TGSI_TEXTURE_2D, coords, sampler); + ureg_MOV(ureg, dst, ureg_swizzle(ureg_src(tmp), + TGSI_SWIZZLE_Z, + TGSI_SWIZZLE_Y, + TGSI_SWIZZLE_X, + TGSI_SWIZZLE_W)); + ureg_release_temporary(ureg, tmp); + } else { + ureg_TEX(ureg, dst, TGSI_TEXTURE_2D, coords, sampler); + } + if (set_alpha) + ureg_MOV(ureg, + ureg_writemask(dst, TGSI_WRITEMASK_W), + ureg_scalar(imm0, TGSI_SWIZZLE_W)); + } +} + +static void * +create_fs(struct pipe_context *pipe, + unsigned fs_traits) +{ + struct ureg_program *ureg; + struct ureg_src /*dst_sampler,*/ src_sampler, mask_sampler; + struct ureg_src /*dst_pos,*/ src_input, mask_pos; + struct ureg_dst src, mask; + struct ureg_dst out; + struct ureg_src imm0 = { 0 }; + unsigned has_mask = (fs_traits & FS_MASK) != 0; + unsigned is_fill = (fs_traits & FS_FILL) != 0; + unsigned is_composite = (fs_traits & FS_COMPOSITE) != 0; + unsigned is_solid = (fs_traits & FS_SOLID_FILL) != 0; + unsigned is_lingrad = (fs_traits & FS_LINGRAD_FILL) != 0; + unsigned is_radgrad = (fs_traits & FS_RADGRAD_FILL) != 0; + unsigned comp_alpha_mask = fs_traits & FS_COMPONENT_ALPHA; + unsigned is_yuv = (fs_traits & FS_YUV) != 0; + unsigned src_repeat_none = (fs_traits & FS_SRC_REPEAT_NONE) != 0; + unsigned mask_repeat_none = (fs_traits & FS_MASK_REPEAT_NONE) != 0; + unsigned src_swizzle = (fs_traits & FS_SRC_SWIZZLE_RGB) != 0; + unsigned mask_swizzle = (fs_traits & FS_MASK_SWIZZLE_RGB) != 0; + unsigned src_set_alpha = (fs_traits & FS_SRC_SET_ALPHA) != 0; + unsigned mask_set_alpha = (fs_traits & FS_MASK_SET_ALPHA) != 0; + unsigned src_luminance = (fs_traits & FS_SRC_LUMINANCE) != 0; + unsigned mask_luminance = (fs_traits & FS_MASK_LUMINANCE) != 0; + +#if 0 + print_fs_traits(fs_traits); +#else + (void)print_fs_traits; +#endif + + ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT); + if (ureg == NULL) + return 0; + + /* it has to be either a fill, a composite op or a yuv conversion */ + debug_assert((is_fill ^ is_composite) ^ is_yuv); + (void) is_yuv; + + out = ureg_DECL_output(ureg, + TGSI_SEMANTIC_COLOR, + 0); + + if (src_repeat_none || mask_repeat_none || + src_set_alpha || mask_set_alpha || + src_luminance) { + imm0 = ureg_imm4f(ureg, 0, 0, 0, 1); + } + if (is_composite) { + src_sampler = ureg_DECL_sampler(ureg, 0); + src_input = ureg_DECL_fs_input(ureg, + TGSI_SEMANTIC_GENERIC, + 0, + TGSI_INTERPOLATE_PERSPECTIVE); + } else if (is_fill) { + if (is_solid) + src_input = ureg_DECL_fs_input(ureg, + TGSI_SEMANTIC_COLOR, + 0, + TGSI_INTERPOLATE_PERSPECTIVE); + else + src_input = ureg_DECL_fs_input(ureg, + TGSI_SEMANTIC_POSITION, + 0, + TGSI_INTERPOLATE_PERSPECTIVE); + } else { + debug_assert(is_yuv); + return create_yuv_shader(pipe, ureg); + } + + if (has_mask) { + mask_sampler = ureg_DECL_sampler(ureg, 1); + mask_pos = ureg_DECL_fs_input(ureg, + TGSI_SEMANTIC_GENERIC, + 1, + TGSI_INTERPOLATE_PERSPECTIVE); + } + +#if 0 /* unused right now */ + dst_sampler = ureg_DECL_sampler(ureg, 2); + dst_pos = ureg_DECL_fs_input(ureg, + TGSI_SEMANTIC_POSITION, + 2, + TGSI_INTERPOLATE_PERSPECTIVE); +#endif + + + if (is_composite) { + if (has_mask || src_luminance) + src = ureg_DECL_temporary(ureg); + else + src = out; + xrender_tex(ureg, src, src_input, src_sampler, imm0, + src_repeat_none, src_swizzle, src_set_alpha); + } else if (is_fill) { + if (is_solid) { + if (has_mask || src_luminance) + src = ureg_dst(src_input); + else + ureg_MOV(ureg, out, src_input); + } else if (is_lingrad || is_radgrad) { + struct ureg_src coords, const0124, + matrow0, matrow1, matrow2; + + if (has_mask || src_luminance) + src = ureg_DECL_temporary(ureg); + else + src = out; + + coords = ureg_DECL_constant(ureg, 0); + const0124 = ureg_DECL_constant(ureg, 1); + matrow0 = ureg_DECL_constant(ureg, 2); + matrow1 = ureg_DECL_constant(ureg, 3); + matrow2 = ureg_DECL_constant(ureg, 4); + + if (is_lingrad) { + linear_gradient(ureg, src, + src_input, src_sampler, + coords, const0124, + matrow0, matrow1, matrow2); + } else if (is_radgrad) { + radial_gradient(ureg, src, + src_input, src_sampler, + coords, const0124, + matrow0, matrow1, matrow2); + } + } else + debug_assert(!"Unknown fill type!"); + } + if (src_luminance) { + ureg_MOV(ureg, src, + ureg_scalar(ureg_src(src), TGSI_SWIZZLE_X)); + ureg_MOV(ureg, ureg_writemask(src, TGSI_WRITEMASK_XYZ), + ureg_scalar(imm0, TGSI_SWIZZLE_X)); + if (!has_mask) + ureg_MOV(ureg, out, ureg_src(src)); + } + + if (has_mask) { + mask = ureg_DECL_temporary(ureg); + xrender_tex(ureg, mask, mask_pos, mask_sampler, imm0, + mask_repeat_none, mask_swizzle, mask_set_alpha); + /* src IN mask */ + src_in_mask(ureg, out, ureg_src(src), ureg_src(mask), + comp_alpha_mask, mask_luminance); + ureg_release_temporary(ureg, mask); + } + + ureg_END(ureg); + + return ureg_create_shader_and_destroy(ureg, pipe); +} + +struct xorg_shaders * xorg_shaders_create(struct xorg_renderer *r) +{ + struct xorg_shaders *sc = CALLOC_STRUCT(xorg_shaders); + + sc->r = r; + sc->vs_hash = cso_hash_create(); + sc->fs_hash = cso_hash_create(); + + return sc; +} + +static void +cache_destroy(struct cso_context *cso, + struct cso_hash *hash, + unsigned processor) +{ + struct cso_hash_iter iter = cso_hash_first_node(hash); + while (!cso_hash_iter_is_null(iter)) { + void *shader = (void *)cso_hash_iter_data(iter); + if (processor == PIPE_SHADER_FRAGMENT) { + cso_delete_fragment_shader(cso, shader); + } else if (processor == PIPE_SHADER_VERTEX) { + cso_delete_vertex_shader(cso, shader); + } + iter = cso_hash_erase(hash, iter); + } + cso_hash_delete(hash); +} + +void xorg_shaders_destroy(struct xorg_shaders *sc) +{ + cache_destroy(sc->r->cso, sc->vs_hash, + PIPE_SHADER_VERTEX); + cache_destroy(sc->r->cso, sc->fs_hash, + PIPE_SHADER_FRAGMENT); + + FREE(sc); +} + +static INLINE void * +shader_from_cache(struct pipe_context *pipe, + unsigned type, + struct cso_hash *hash, + unsigned key) +{ + void *shader = 0; + + struct cso_hash_iter iter = cso_hash_find(hash, key); + + if (cso_hash_iter_is_null(iter)) { + if (type == PIPE_SHADER_VERTEX) + shader = create_vs(pipe, key); + else + shader = create_fs(pipe, key); + cso_hash_insert(hash, key, shader); + } else + shader = (void *)cso_hash_iter_data(iter); + + return shader; +} + +struct xorg_shader xorg_shaders_get(struct xorg_shaders *sc, + unsigned vs_traits, + unsigned fs_traits) +{ + struct xorg_shader shader = { NULL, NULL }; + void *vs, *fs; + + vs = shader_from_cache(sc->r->pipe, PIPE_SHADER_VERTEX, + sc->vs_hash, vs_traits); + fs = shader_from_cache(sc->r->pipe, PIPE_SHADER_FRAGMENT, + sc->fs_hash, fs_traits); + + debug_assert(vs && fs); + if (!vs || !fs) + return shader; + + shader.vs = vs; + shader.fs = fs; + + return shader; +} diff --git a/src/gallium/state_trackers/xorg/xorg_exa_tgsi.h b/src/gallium/state_trackers/xorg/xorg_exa_tgsi.h new file mode 100644 index 0000000..6f2a361 --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_exa_tgsi.h @@ -0,0 +1,59 @@ +#ifndef XORG_EXA_TGSI_H +#define XORG_EXA_TGSI_H + +#include "xorg_renderer.h" + +enum xorg_vs_traits { + VS_COMPOSITE = 1 << 0, + VS_MASK = 1 << 1, + VS_SOLID_FILL = 1 << 2, + VS_LINGRAD_FILL = 1 << 3, + VS_RADGRAD_FILL = 1 << 4, + VS_YUV = 1 << 5, + + + VS_FILL = (VS_SOLID_FILL | + VS_LINGRAD_FILL | + VS_RADGRAD_FILL) +}; + +enum xorg_fs_traits { + FS_COMPOSITE = 1 << 0, + FS_MASK = 1 << 1, + FS_SOLID_FILL = 1 << 2, + FS_LINGRAD_FILL = 1 << 3, + FS_RADGRAD_FILL = 1 << 4, + FS_CA_FULL = 1 << 5, /* src.rgba * mask.rgba */ + FS_CA_SRCALPHA = 1 << 6, /* src.aaaa * mask.rgba */ + FS_YUV = 1 << 7, + FS_SRC_REPEAT_NONE = 1 << 8, + FS_MASK_REPEAT_NONE = 1 << 9, + FS_SRC_SWIZZLE_RGB = 1 << 10, + FS_MASK_SWIZZLE_RGB = 1 << 11, + FS_SRC_SET_ALPHA = 1 << 12, + FS_MASK_SET_ALPHA = 1 << 13, + FS_SRC_LUMINANCE = 1 << 14, + FS_MASK_LUMINANCE = 1 << 15, + + FS_FILL = (FS_SOLID_FILL | + FS_LINGRAD_FILL | + FS_RADGRAD_FILL), + FS_COMPONENT_ALPHA = (FS_CA_FULL | + FS_CA_SRCALPHA) +}; + +struct xorg_shader { + void *fs; + void *vs; +}; + +struct xorg_shaders; + +struct xorg_shaders *xorg_shaders_create(struct xorg_renderer *renderer); +void xorg_shaders_destroy(struct xorg_shaders *shaders); + +struct xorg_shader xorg_shaders_get(struct xorg_shaders *shaders, + unsigned vs_traits, + unsigned fs_traits); + +#endif diff --git a/src/gallium/state_trackers/xorg/xorg_output.c b/src/gallium/state_trackers/xorg/xorg_output.c new file mode 100644 index 0000000..5555b51 --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_output.c @@ -0,0 +1,303 @@ +/* + * 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 "xorg-server.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_XEXTPROTO_71 +#include +#else +#define DPMS_SERVER +#include +#endif + +#include "xorg_tracker.h" + +struct output_private +{ + drmModeConnectorPtr drm_connector; + + int c; +}; + +static char *output_enum_list[] = { + "Unknown", + "VGA", + "DVI", + "DVI", + "DVI", + "Composite", + "SVIDEO", + "LVDS", + "CTV", + "DIN", + "DP", + "HDMI", + "HDMI", +}; + +static void +output_create_resources(xf86OutputPtr output) +{ +#ifdef RANDR_12_INTERFACE +#endif /* RANDR_12_INTERFACE */ +} + +static void +output_dpms(xf86OutputPtr output, int mode) +{ +} + +static xf86OutputStatus +output_detect(xf86OutputPtr output) +{ + modesettingPtr ms = modesettingPTR(output->scrn); + struct output_private *priv = output->driver_private; + drmModeConnectorPtr drm_connector; + xf86OutputStatus status; + + drm_connector = drmModeGetConnector(ms->fd, priv->drm_connector->connector_id); + if (drm_connector) { + drmModeFreeConnector(priv->drm_connector); + priv->drm_connector = drm_connector; + } else { + drm_connector = priv->drm_connector; + } + + switch (drm_connector->connection) { + case DRM_MODE_CONNECTED: + status = XF86OutputStatusConnected; + break; + case DRM_MODE_DISCONNECTED: + status = XF86OutputStatusDisconnected; + break; + default: + status = XF86OutputStatusUnknown; + } + + return status; +} + +static DisplayModePtr +output_get_modes(xf86OutputPtr output) +{ + struct output_private *priv = output->driver_private; + drmModeConnectorPtr drm_connector = priv->drm_connector; + drmModeModeInfoPtr drm_mode = NULL; + DisplayModePtr modes = NULL, mode = NULL; + int i; + + for (i = 0; i < drm_connector->count_modes; i++) { + drm_mode = &drm_connector->modes[i]; + if (drm_mode) { + mode = calloc(1, sizeof(DisplayModeRec)); + if (!mode) + continue; + mode->Clock = drm_mode->clock; + mode->HDisplay = drm_mode->hdisplay; + mode->HSyncStart = drm_mode->hsync_start; + mode->HSyncEnd = drm_mode->hsync_end; + mode->HTotal = drm_mode->htotal; + mode->VDisplay = drm_mode->vdisplay; + mode->VSyncStart = drm_mode->vsync_start; + mode->VSyncEnd = drm_mode->vsync_end; + mode->VTotal = drm_mode->vtotal; + mode->Flags = drm_mode->flags; + mode->HSkew = drm_mode->hskew; + mode->VScan = drm_mode->vscan; + mode->VRefresh = xf86ModeVRefresh(mode); + mode->Private = (void *)drm_mode; + mode->type = 0; + if (drm_mode->type & DRM_MODE_TYPE_PREFERRED) + mode->type |= M_T_PREFERRED; + if (drm_mode->type & DRM_MODE_TYPE_DRIVER) + mode->type |= M_T_DRIVER; + xf86SetModeDefaultName(mode); + modes = xf86ModesAdd(modes, mode); + xf86PrintModeline(0, mode); + } + } + + return modes; +} + +static int +output_mode_valid(xf86OutputPtr output, DisplayModePtr pMode) +{ + modesettingPtr ms = modesettingPTR(output->scrn); + CustomizerPtr cust = ms->cust; + + if (cust && cust->winsys_check_fb_size && + !cust->winsys_check_fb_size(cust, pMode->HDisplay * + output->scrn->bitsPerPixel / 8, + pMode->VDisplay)) + return MODE_BAD; + + return MODE_OK; +} + +#ifdef RANDR_12_INTERFACE +static Bool +output_set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value) +{ + return TRUE; +} +#endif /* RANDR_12_INTERFACE */ + +#ifdef RANDR_13_INTERFACE +static Bool +output_get_property(xf86OutputPtr output, Atom property) +{ + return TRUE; +} +#endif /* RANDR_13_INTERFACE */ + +static void +output_destroy(xf86OutputPtr output) +{ + struct output_private *priv = output->driver_private; + drmModeFreeConnector(priv->drm_connector); + free(priv); + output->driver_private = NULL; +} + +static const xf86OutputFuncsRec output_funcs = { + .create_resources = output_create_resources, +#ifdef RANDR_12_INTERFACE + .set_property = output_set_property, +#endif +#ifdef RANDR_13_INTERFACE + .get_property = output_get_property, +#endif + .dpms = output_dpms, + .detect = output_detect, + + .get_modes = output_get_modes, + .mode_valid = output_mode_valid, + .destroy = output_destroy, +}; + +void +xorg_output_init(ScrnInfoPtr pScrn) +{ + modesettingPtr ms = modesettingPTR(pScrn); + xf86OutputPtr output; + drmModeResPtr res; + drmModeConnectorPtr drm_connector = NULL; + drmModeEncoderPtr drm_encoder = NULL; + struct output_private *priv; + char name[32]; + int c, v, p; + + res = drmModeGetResources(ms->fd); + if (res == 0) { + DRV_ERROR("Failed drmModeGetResources\n"); + return; + } + + for (c = 0; c < res->count_connectors; c++) { + drm_connector = drmModeGetConnector(ms->fd, res->connectors[c]); + if (!drm_connector) + goto out; + +#if 0 + for (p = 0; p < drm_connector->count_props; p++) { + drmModePropertyPtr prop; + + prop = drmModeGetProperty(ms->fd, drm_connector->props[p]); + + name = NULL; + if (prop) { + ErrorF("VALUES %d\n", prop->count_values); + + for (v = 0; v < prop->count_values; v++) + ErrorF("%s %lld\n", prop->name, prop->values[v]); + } + } +#else + (void)p; + (void)v; +#endif + + snprintf(name, 32, "%s%d", + output_enum_list[drm_connector->connector_type], + drm_connector->connector_type_id); + + + priv = calloc(sizeof(*priv), 1); + if (!priv) { + continue; + } + + output = xf86OutputCreate(pScrn, &output_funcs, name); + if (!output) { + free(priv); + continue; + } + + drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]); + if (drm_encoder) { + output->possible_crtcs = drm_encoder->possible_crtcs; + output->possible_clones = drm_encoder->possible_clones; + } else { + output->possible_crtcs = 0; + output->possible_clones = 0; + } + priv->c = c; + priv->drm_connector = drm_connector; + output->driver_private = priv; + output->subpixel_order = SubPixelHorizontalRGB; + output->interlaceAllowed = FALSE; + output->doubleScanAllowed = FALSE; + } + + out: + drmModeFreeResources(res); +} + +unsigned +xorg_output_get_id(xf86OutputPtr output) +{ + struct output_private *priv = output->driver_private; + return priv->drm_connector->connector_id; +} + +/* vim: set sw=4 ts=8 sts=4: */ diff --git a/src/gallium/state_trackers/xorg/xorg_renderer.c b/src/gallium/state_trackers/xorg/xorg_renderer.c new file mode 100644 index 0000000..a3d7c5a --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_renderer.c @@ -0,0 +1,714 @@ +#include "xorg_exa.h" +#include "xorg_renderer.h" + +#include "xorg_exa_tgsi.h" + +#include "cso_cache/cso_context.h" +#include "util/u_draw_quad.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "util/u_sampler.h" + +#include "util/u_inlines.h" +#include "util/u_box.h" + +#include + +#define floatsEqual(x, y) (fabs(x - y) <= 0.00001f * MIN2(fabs(x), fabs(y))) +#define floatIsZero(x) (floatsEqual((x) + 1, 1)) + +#define NUM_COMPONENTS 4 + +static INLINE boolean is_affine(float *matrix) +{ + return floatIsZero(matrix[2]) && floatIsZero(matrix[5]) + && floatsEqual(matrix[8], 1); +} +static INLINE void map_point(float *mat, float x, float y, + float *out_x, float *out_y) +{ + if (!mat) { + *out_x = x; + *out_y = y; + return; + } + + *out_x = mat[0]*x + mat[3]*y + mat[6]; + *out_y = mat[1]*x + mat[4]*y + mat[7]; + if (!is_affine(mat)) { + float w = 1/(mat[2]*x + mat[5]*y + mat[8]); + *out_x *= w; + *out_y *= w; + } +} + +static INLINE struct pipe_resource * +renderer_buffer_create(struct xorg_renderer *r) +{ + struct pipe_resource *buf = + pipe_user_buffer_create(r->pipe->screen, + r->buffer, + sizeof(float)* + r->buffer_size, +/* XXX was: PIPE_BUFFER_USAGE_PIXEL/PIPE_BUFFER_USAGE_GPU_WRITE even though this is a vertex buffer??? */ + PIPE_BIND_VERTEX_BUFFER); + r->buffer_size = 0; + + return buf; +} + +static INLINE void +renderer_draw(struct xorg_renderer *r) +{ + struct pipe_context *pipe = r->pipe; + struct pipe_resource *buf = 0; + int num_verts = r->buffer_size/(r->attrs_per_vertex * NUM_COMPONENTS); + + if (!r->buffer_size) + return; + + buf = renderer_buffer_create(r); + + + if (buf) { + cso_set_vertex_elements(r->cso, r->attrs_per_vertex, r->velems); + + util_draw_vertex_buffer(pipe, buf, 0, + PIPE_PRIM_QUADS, + num_verts, /* verts */ + r->attrs_per_vertex); /* attribs/vert */ + + pipe_resource_reference(&buf, NULL); + } +} + +static INLINE void +renderer_draw_conditional(struct xorg_renderer *r, + int next_batch) +{ + if (r->buffer_size + next_batch >= BUF_SIZE || + (next_batch == 0 && r->buffer_size)) { + renderer_draw(r); + } +} + +static void +renderer_init_state(struct xorg_renderer *r) +{ + struct pipe_depth_stencil_alpha_state dsa; + struct pipe_rasterizer_state raster; + unsigned i; + + /* set common initial clip state */ + memset(&dsa, 0, sizeof(struct pipe_depth_stencil_alpha_state)); + cso_set_depth_stencil_alpha(r->cso, &dsa); + + + /* XXX: move to renderer_init_state? */ + memset(&raster, 0, sizeof(struct pipe_rasterizer_state)); + raster.gl_rasterization_rules = 1; + cso_set_rasterizer(r->cso, &raster); + + /* vertex elements state */ + memset(&r->velems[0], 0, sizeof(r->velems[0]) * 3); + for (i = 0; i < 3; i++) { + r->velems[i].src_offset = i * 4 * sizeof(float); + r->velems[i].instance_divisor = 0; + r->velems[i].vertex_buffer_index = 0; + r->velems[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + } +} + + +static INLINE void +add_vertex_color(struct xorg_renderer *r, + float x, float y, + float color[4]) +{ + float *vertex = r->buffer + r->buffer_size; + + vertex[0] = x; + vertex[1] = y; + vertex[2] = 0.f; /*z*/ + vertex[3] = 1.f; /*w*/ + + vertex[4] = color[0]; /*r*/ + vertex[5] = color[1]; /*g*/ + vertex[6] = color[2]; /*b*/ + vertex[7] = color[3]; /*a*/ + + r->buffer_size += 8; +} + +static INLINE void +add_vertex_1tex(struct xorg_renderer *r, + float x, float y, float s, float t) +{ + float *vertex = r->buffer + r->buffer_size; + + vertex[0] = x; + vertex[1] = y; + vertex[2] = 0.f; /*z*/ + vertex[3] = 1.f; /*w*/ + + vertex[4] = s; /*s*/ + vertex[5] = t; /*t*/ + vertex[6] = 0.f; /*r*/ + vertex[7] = 1.f; /*q*/ + + r->buffer_size += 8; +} + +static void +add_vertex_data1(struct xorg_renderer *r, + float srcX, float srcY, float dstX, float dstY, + float width, float height, + struct pipe_resource *src, float *src_matrix) +{ + float s0, t0, s1, t1, s2, t2, s3, t3; + float pt0[2], pt1[2], pt2[2], pt3[2]; + + pt0[0] = srcX; + pt0[1] = srcY; + pt1[0] = (srcX + width); + pt1[1] = srcY; + pt2[0] = (srcX + width); + pt2[1] = (srcY + height); + pt3[0] = srcX; + pt3[1] = (srcY + height); + + if (src_matrix) { + map_point(src_matrix, pt0[0], pt0[1], &pt0[0], &pt0[1]); + map_point(src_matrix, pt1[0], pt1[1], &pt1[0], &pt1[1]); + map_point(src_matrix, pt2[0], pt2[1], &pt2[0], &pt2[1]); + map_point(src_matrix, pt3[0], pt3[1], &pt3[0], &pt3[1]); + } + + s0 = pt0[0] / src->width0; + s1 = pt1[0] / src->width0; + s2 = pt2[0] / src->width0; + s3 = pt3[0] / src->width0; + t0 = pt0[1] / src->height0; + t1 = pt1[1] / src->height0; + t2 = pt2[1] / src->height0; + t3 = pt3[1] / src->height0; + + /* 1st vertex */ + add_vertex_1tex(r, dstX, dstY, s0, t0); + /* 2nd vertex */ + add_vertex_1tex(r, dstX + width, dstY, s1, t1); + /* 3rd vertex */ + add_vertex_1tex(r, dstX + width, dstY + height, s2, t2); + /* 4th vertex */ + add_vertex_1tex(r, dstX, dstY + height, s3, t3); +} + + +static INLINE void +add_vertex_2tex(struct xorg_renderer *r, + float x, float y, + float s0, float t0, float s1, float t1) +{ + float *vertex = r->buffer + r->buffer_size; + + vertex[0] = x; + vertex[1] = y; + vertex[2] = 0.f; /*z*/ + vertex[3] = 1.f; /*w*/ + + vertex[4] = s0; /*s*/ + vertex[5] = t0; /*t*/ + vertex[6] = 0.f; /*r*/ + vertex[7] = 1.f; /*q*/ + + vertex[8] = s1; /*s*/ + vertex[9] = t1; /*t*/ + vertex[10] = 0.f; /*r*/ + vertex[11] = 1.f; /*q*/ + + r->buffer_size += 12; +} + +static void +add_vertex_data2(struct xorg_renderer *r, + float srcX, float srcY, float maskX, float maskY, + float dstX, float dstY, float width, float height, + struct pipe_resource *src, + struct pipe_resource *mask, + float *src_matrix, float *mask_matrix) +{ + float src_s0, src_t0, src_s1, src_t1; + float mask_s0, mask_t0, mask_s1, mask_t1; + float spt0[2], spt1[2]; + float mpt0[2], mpt1[2]; + + spt0[0] = srcX; + spt0[1] = srcY; + spt1[0] = srcX + width; + spt1[1] = srcY + height; + + mpt0[0] = maskX; + mpt0[1] = maskY; + mpt1[0] = maskX + width; + mpt1[1] = maskY + height; + + if (src_matrix) { + map_point(src_matrix, spt0[0], spt0[1], &spt0[0], &spt0[1]); + map_point(src_matrix, spt1[0], spt1[1], &spt1[0], &spt1[1]); + } + + if (mask_matrix) { + map_point(mask_matrix, mpt0[0], mpt0[1], &mpt0[0], &mpt0[1]); + map_point(mask_matrix, mpt1[0], mpt1[1], &mpt1[0], &mpt1[1]); + } + + src_s0 = spt0[0] / src->width0; + src_t0 = spt0[1] / src->height0; + src_s1 = spt1[0] / src->width0; + src_t1 = spt1[1] / src->height0; + + mask_s0 = mpt0[0] / mask->width0; + mask_t0 = mpt0[1] / mask->height0; + mask_s1 = mpt1[0] / mask->width0; + mask_t1 = mpt1[1] / mask->height0; + + /* 1st vertex */ + add_vertex_2tex(r, dstX, dstY, + src_s0, src_t0, mask_s0, mask_t0); + /* 2nd vertex */ + add_vertex_2tex(r, dstX + width, dstY, + src_s1, src_t0, mask_s1, mask_t0); + /* 3rd vertex */ + add_vertex_2tex(r, dstX + width, dstY + height, + src_s1, src_t1, mask_s1, mask_t1); + /* 4th vertex */ + add_vertex_2tex(r, dstX, dstY + height, + src_s0, src_t1, mask_s0, mask_t1); +} + +static struct pipe_resource * +setup_vertex_data_yuv(struct xorg_renderer *r, + float srcX, float srcY, float srcW, float srcH, + float dstX, float dstY, float dstW, float dstH, + struct pipe_resource **tex) +{ + float s0, t0, s1, t1; + float spt0[2], spt1[2]; + + spt0[0] = srcX; + spt0[1] = srcY; + spt1[0] = srcX + srcW; + spt1[1] = srcY + srcH; + + s0 = spt0[0] / tex[0]->width0; + t0 = spt0[1] / tex[0]->height0; + s1 = spt1[0] / tex[0]->width0; + t1 = spt1[1] / tex[0]->height0; + + /* 1st vertex */ + add_vertex_1tex(r, dstX, dstY, s0, t0); + /* 2nd vertex */ + add_vertex_1tex(r, dstX + dstW, dstY, + s1, t0); + /* 3rd vertex */ + add_vertex_1tex(r, dstX + dstW, dstY + dstH, + s1, t1); + /* 4th vertex */ + add_vertex_1tex(r, dstX, dstY + dstH, + s0, t1); + + return renderer_buffer_create(r); +} + + + +/* Set up framebuffer, viewport and vertex shader constant buffer + * state for a particular destinaton surface. In all our rendering, + * these concepts are linked. + */ +void renderer_bind_destination(struct xorg_renderer *r, + struct pipe_surface *surface, + int width, + int height ) +{ + + struct pipe_framebuffer_state fb; + struct pipe_viewport_state viewport; + + /* Framebuffer uses actual surface width/height + */ + memset(&fb, 0, sizeof fb); + fb.width = surface->width; + fb.height = surface->height; + fb.nr_cbufs = 1; + fb.cbufs[0] = surface; + fb.zsbuf = 0; + + /* Viewport just touches the bit we're interested in: + */ + viewport.scale[0] = width / 2.f; + viewport.scale[1] = height / 2.f; + viewport.scale[2] = 1.0; + viewport.scale[3] = 1.0; + viewport.translate[0] = width / 2.f; + viewport.translate[1] = height / 2.f; + viewport.translate[2] = 0.0; + viewport.translate[3] = 0.0; + + /* Constant buffer set up to match viewport dimensions: + */ + if (r->fb_width != width || + r->fb_height != height) + { + float vs_consts[8] = { + 2.f/width, 2.f/height, 1, 1, + -1, -1, 0, 0 + }; + + r->fb_width = width; + r->fb_height = height; + + renderer_set_constants(r, PIPE_SHADER_VERTEX, + vs_consts, sizeof vs_consts); + } + + cso_set_framebuffer(r->cso, &fb); + cso_set_viewport(r->cso, &viewport); +} + + +struct xorg_renderer * renderer_create(struct pipe_context *pipe) +{ + struct xorg_renderer *renderer = CALLOC_STRUCT(xorg_renderer); + + renderer->pipe = pipe; + renderer->cso = cso_create_context(pipe); + renderer->shaders = xorg_shaders_create(renderer); + + renderer_init_state(renderer); + + return renderer; +} + +void renderer_destroy(struct xorg_renderer *r) +{ + struct pipe_resource **vsbuf = &r->vs_const_buffer; + struct pipe_resource **fsbuf = &r->fs_const_buffer; + + if (*vsbuf) + pipe_resource_reference(vsbuf, NULL); + + if (*fsbuf) + pipe_resource_reference(fsbuf, NULL); + + if (r->shaders) { + xorg_shaders_destroy(r->shaders); + r->shaders = NULL; + } + + if (r->cso) { + cso_release_all(r->cso); + cso_destroy_context(r->cso); + r->cso = NULL; + } +} + + + + + +void renderer_set_constants(struct xorg_renderer *r, + int shader_type, + const float *params, + int param_bytes) +{ + struct pipe_resource **cbuf = + (shader_type == PIPE_SHADER_VERTEX) ? &r->vs_const_buffer : + &r->fs_const_buffer; + + pipe_resource_reference(cbuf, NULL); + *cbuf = pipe_buffer_create(r->pipe->screen, + PIPE_BIND_CONSTANT_BUFFER, + param_bytes); + + if (*cbuf) { + pipe_buffer_write(r->pipe, *cbuf, + 0, param_bytes, params); + } + r->pipe->set_constant_buffer(r->pipe, shader_type, 0, *cbuf); +} + + +void renderer_copy_prepare(struct xorg_renderer *r, + struct pipe_surface *dst_surface, + struct pipe_resource *src_texture) +{ + struct pipe_context *pipe = r->pipe; + struct pipe_screen *screen = pipe->screen; + struct xorg_shader shader; + + assert(screen->is_format_supported(screen, dst_surface->format, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_RENDER_TARGET, + 0)); + (void) screen; + + + /* set misc state we care about */ + { + struct pipe_blend_state blend; + memset(&blend, 0, sizeof(blend)); + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; + blend.rt[0].colormask = PIPE_MASK_RGBA; + cso_set_blend(r->cso, &blend); + } + + /* sampler */ + { + struct pipe_sampler_state sampler; + memset(&sampler, 0, sizeof(sampler)); + sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler.normalized_coords = 1; + cso_single_sampler(r->cso, 0, &sampler); + cso_single_sampler_done(r->cso); + } + + renderer_bind_destination(r, dst_surface, + dst_surface->width, + dst_surface->height); + + /* texture/sampler view */ + { + struct pipe_sampler_view templ; + struct pipe_sampler_view *src_view; + u_sampler_view_default_template(&templ, + src_texture, + src_texture->format); + src_view = pipe->create_sampler_view(pipe, src_texture, &templ); + cso_set_fragment_sampler_views(r->cso, 1, &src_view); + pipe_sampler_view_reference(&src_view, NULL); + } + + /* shaders */ + shader = xorg_shaders_get(r->shaders, + VS_COMPOSITE, + FS_COMPOSITE); + cso_set_vertex_shader_handle(r->cso, shader.vs); + cso_set_fragment_shader_handle(r->cso, shader.fs); + + r->buffer_size = 0; + r->attrs_per_vertex = 2; +} + +struct pipe_resource * +renderer_clone_texture(struct xorg_renderer *r, + struct pipe_resource *src) +{ + enum pipe_format format; + struct pipe_context *pipe = r->pipe; + struct pipe_screen *screen = pipe->screen; + struct pipe_resource *pt; + struct pipe_resource templ; + + if (pipe->is_resource_referenced(pipe, src, 0, 0) & + PIPE_REFERENCED_FOR_WRITE) + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + + /* the coming in texture should already have that invariance */ + debug_assert(screen->is_format_supported(screen, src->format, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_SAMPLER_VIEW, 0)); + + format = src->format; + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.format = format; + templ.last_level = 0; + templ.width0 = src->width0; + templ.height0 = src->height0; + templ.depth0 = 1; + templ.array_size = 1; + templ.bind = PIPE_BIND_SAMPLER_VIEW; + + pt = screen->resource_create(screen, &templ); + + debug_assert(!pt || pipe_is_referenced(&pt->reference)); + + if (!pt) + return NULL; + + { + /* copy source framebuffer surface into texture */ + struct pipe_box src_box; + u_box_origin_2d(src->width0, src->height0, &src_box); + + pipe->resource_copy_region(pipe, + pt, /* dest */ + 0, /* dest_level */ + 0, 0, 0, /* destx/y/z */ + src, + 0, &src_box); + } + + return pt; +} + + +void renderer_copy_pixmap(struct xorg_renderer *r, + int dx, int dy, + int sx, int sy, + int width, int height, + float src_width, + float src_height) +{ + float s0, t0, s1, t1; + float x0, y0, x1, y1; + + + /* XXX: could put the texcoord scaling calculation into the vertex + * shader. + */ + s0 = sx / src_width; + s1 = (sx + width) / src_width; + t0 = sy / src_height; + t1 = (sy + height) / src_height; + + x0 = dx; + x1 = dx + width; + y0 = dy; + y1 = dy + height; + + /* draw quad */ + renderer_draw_conditional(r, 4*8); + add_vertex_1tex(r, x0, y0, s0, t0); + add_vertex_1tex(r, x1, y0, s1, t0); + add_vertex_1tex(r, x1, y1, s1, t1); + add_vertex_1tex(r, x0, y1, s0, t1); +} + + + + +void renderer_draw_yuv(struct xorg_renderer *r, + float src_x, float src_y, float src_w, float src_h, + int dst_x, int dst_y, int dst_w, int dst_h, + struct pipe_resource **textures) +{ + struct pipe_context *pipe = r->pipe; + struct pipe_resource *buf = 0; + + buf = setup_vertex_data_yuv(r, + src_x, src_y, src_w, src_h, + dst_x, dst_y, dst_w, dst_h, + textures); + + if (buf) { + const int num_attribs = 2; /*pos + tex coord*/ + + cso_set_vertex_elements(r->cso, num_attribs, r->velems); + + util_draw_vertex_buffer(pipe, buf, 0, + PIPE_PRIM_QUADS, + 4, /* verts */ + num_attribs); /* attribs/vert */ + + pipe_resource_reference(&buf, NULL); + } +} + +void renderer_begin_solid(struct xorg_renderer *r) +{ + r->buffer_size = 0; + r->attrs_per_vertex = 2; +} + +void renderer_solid(struct xorg_renderer *r, + int x0, int y0, + int x1, int y1, + float *color) +{ + /* + debug_printf("solid rect[(%d, %d), (%d, %d)], rgba[%f, %f, %f, %f]\n", + x0, y0, x1, y1, color[0], color[1], color[2], color[3]);*/ + + renderer_draw_conditional(r, 4 * 8); + + /* 1st vertex */ + add_vertex_color(r, x0, y0, color); + /* 2nd vertex */ + add_vertex_color(r, x1, y0, color); + /* 3rd vertex */ + add_vertex_color(r, x1, y1, color); + /* 4th vertex */ + add_vertex_color(r, x0, y1, color); +} + +void renderer_draw_flush(struct xorg_renderer *r) +{ + renderer_draw_conditional(r, 0); +} + +void renderer_begin_textures(struct xorg_renderer *r, + int num_textures) +{ + r->attrs_per_vertex = 1 + num_textures; + r->buffer_size = 0; +} + +void renderer_texture(struct xorg_renderer *r, + int *pos, + int width, int height, + struct pipe_sampler_view **sampler_view, + int num_textures, + float *src_matrix, + float *mask_matrix) +{ + +#if 0 + if (src_matrix) { + debug_printf("src_matrix = \n"); + debug_printf("%f, %f, %f\n", src_matrix[0], src_matrix[1], src_matrix[2]); + debug_printf("%f, %f, %f\n", src_matrix[3], src_matrix[4], src_matrix[5]); + debug_printf("%f, %f, %f\n", src_matrix[6], src_matrix[7], src_matrix[8]); + } + if (mask_matrix) { + debug_printf("mask_matrix = \n"); + debug_printf("%f, %f, %f\n", mask_matrix[0], mask_matrix[1], mask_matrix[2]); + debug_printf("%f, %f, %f\n", mask_matrix[3], mask_matrix[4], mask_matrix[5]); + debug_printf("%f, %f, %f\n", mask_matrix[6], mask_matrix[7], mask_matrix[8]); + } +#endif + + switch(r->attrs_per_vertex) { + case 2: + renderer_draw_conditional(r, 4 * 8); + add_vertex_data1(r, + pos[0], pos[1], /* src */ + pos[4], pos[5], /* dst */ + width, height, + sampler_view[0]->texture, src_matrix); + break; + case 3: + renderer_draw_conditional(r, 4 * 12); + add_vertex_data2(r, + pos[0], pos[1], /* src */ + pos[2], pos[3], /* mask */ + pos[4], pos[5], /* dst */ + width, height, + sampler_view[0]->texture, sampler_view[1]->texture, + src_matrix, mask_matrix); + break; + default: + debug_assert(!"Unsupported number of textures"); + break; + } +} diff --git a/src/gallium/state_trackers/xorg/xorg_renderer.h b/src/gallium/state_trackers/xorg/xorg_renderer.h new file mode 100644 index 0000000..fb09fab --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_renderer.h @@ -0,0 +1,96 @@ +#ifndef XORG_RENDERER_H +#define XORG_RENDERER_H + +#include "pipe/p_context.h" +#include "pipe/p_state.h" + +struct xorg_shaders; +struct exa_pixmap_priv; + +/* max number of vertices * + * max number of attributes per vertex * + * max number of components per attribute + * + * currently the max is 100 quads + */ +#define BUF_SIZE (100 * 4 * 3 * 4) + +struct xorg_renderer { + struct pipe_context *pipe; + + struct cso_context *cso; + struct xorg_shaders *shaders; + + int fb_width; + int fb_height; + struct pipe_resource *vs_const_buffer; + struct pipe_resource *fs_const_buffer; + + float buffer[BUF_SIZE]; + int buffer_size; + struct pipe_vertex_element velems[3]; + + /* number of attributes per vertex for the current + * draw operation */ + int attrs_per_vertex; +}; + +struct xorg_renderer *renderer_create(struct pipe_context *pipe); +void renderer_destroy(struct xorg_renderer *renderer); + +void renderer_bind_destination(struct xorg_renderer *r, + struct pipe_surface *surface, + int width, + int height ); + +void renderer_bind_framebuffer(struct xorg_renderer *r, + struct exa_pixmap_priv *priv); +void renderer_bind_viewport(struct xorg_renderer *r, + struct exa_pixmap_priv *dst); +void renderer_set_constants(struct xorg_renderer *r, + int shader_type, + const float *buffer, + int size); + + +void renderer_draw_yuv(struct xorg_renderer *r, + float src_x, float src_y, float src_w, float src_h, + int dst_x, int dst_y, int dst_w, int dst_h, + struct pipe_resource **textures); + +void renderer_begin_solid(struct xorg_renderer *r); +void renderer_solid(struct xorg_renderer *r, + int x0, int y0, + int x1, int y1, + float *color); + +void renderer_begin_textures(struct xorg_renderer *r, + int num_textures); + +void renderer_texture(struct xorg_renderer *r, + int *pos, + int width, int height, + struct pipe_sampler_view **textures, + int num_textures, + float *src_matrix, + float *mask_matrix); + +void renderer_draw_flush(struct xorg_renderer *r); + +struct pipe_resource * +renderer_clone_texture(struct xorg_renderer *r, + struct pipe_resource *src); + +void renderer_copy_prepare(struct xorg_renderer *r, + struct pipe_surface *dst_surface, + struct pipe_resource *src_texture); + +void renderer_copy_pixmap(struct xorg_renderer *r, + int dx, int dy, + int sx, int sy, + int width, int height, + float src_width, + float src_height); + + +#endif diff --git a/src/gallium/state_trackers/xorg/xorg_tracker.h b/src/gallium/state_trackers/xorg/xorg_tracker.h new file mode 100644 index 0000000..56397b8 --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_tracker.h @@ -0,0 +1,224 @@ +/* + * 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 + * + */ + +#ifndef _XORG_TRACKER_H_ +#define _XORG_TRACKER_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "xf86Crtc.h" +#include + +#ifdef DRM_MODE_FEATURE_DIRTYFB +#include +#endif + +#include "pipe/p_screen.h" +#include "util/u_inlines.h" +#include "util/u_debug.h" + +#define DRV_ERROR(msg) xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg); + +struct kms_bo; +struct kms_driver; +struct exa_context; + +typedef struct +{ + int lastInstance; + int refCount; + ScrnInfoPtr pScrn_1; + ScrnInfoPtr pScrn_2; +} EntRec, *EntPtr; + +#define XORG_NR_FENCES 3 + +enum xorg_throttling_reason { + THROTTLE_RENDER, + THROTTLE_SWAP +}; + +typedef struct _CustomizerRec +{ + Bool dirty_throttling; + Bool swap_throttling; + Bool no_3d; + Bool unhidden_hw_cursor_update; + Bool (*winsys_pre_init) (struct _CustomizerRec *cust, int fd); + Bool (*winsys_screen_init)(struct _CustomizerRec *cust); + Bool (*winsys_screen_close)(struct _CustomizerRec *cust); + Bool (*winsys_enter_vt)(struct _CustomizerRec *cust); + Bool (*winsys_leave_vt)(struct _CustomizerRec *cust); + void (*winsys_context_throttle)(struct _CustomizerRec *cust, + struct pipe_context *pipe, + enum xorg_throttling_reason reason); + Bool (*winsys_check_fb_size) (struct _CustomizerRec *cust, + unsigned long pitch, + unsigned long height); +} CustomizerRec, *CustomizerPtr; + +typedef struct _modesettingRec +{ + /* drm */ + int fd; + unsigned fb_id; + + /* X */ + EntPtr entityPrivate; + + int Chipset; + EntityInfoPtr pEnt; + struct pci_device *PciInfo; + + Bool noAccel; + Bool SWCursor; + CursorPtr cursor; + Bool swapThrottling; + Bool dirtyThrottling; + CloseScreenProcPtr CloseScreen; + Bool no3D; + Bool from_3D; + Bool isMaster; + + /* Broken-out options. */ + OptionInfoPtr Options; + + void (*blockHandler)(int, pointer, pointer, pointer); + struct pipe_fence_handle *fence[XORG_NR_FENCES]; + + CreateScreenResourcesProcPtr createScreenResources; + + /* for frontbuffer backing store */ + Bool (*destroy_front_buffer)(ScrnInfoPtr pScrn); + Bool (*create_front_buffer)(ScrnInfoPtr pScrn); + Bool (*bind_front_buffer)(ScrnInfoPtr pScrn); + + /* kms */ + struct kms_driver *kms; + struct kms_bo *root_bo; + + /* gallium */ + struct pipe_screen *screen; + struct pipe_context *ctx; + boolean d_depth_bits_last; + boolean ds_depth_bits_last; + struct pipe_resource *root_texture; + + /* exa */ + struct exa_context *exa; + Bool noEvict; + Bool accelerate_2d; + Bool debug_fallback; + + CustomizerPtr cust; + +#ifdef DRM_MODE_FEATURE_DIRTYFB + DamagePtr damage; +#endif +} modesettingRec, *modesettingPtr; + +#define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate)) + +CustomizerPtr xorg_customizer(ScrnInfoPtr pScrn); + +Bool xorg_has_gallium(ScrnInfoPtr pScrn); + +void xorg_flush(ScreenPtr pScreen); +/*********************************************************************** + * xorg_exa.c + */ +struct pipe_resource * +xorg_exa_get_texture(PixmapPtr pPixmap); + +int +xorg_exa_set_displayed_usage(PixmapPtr pPixmap); + +int +xorg_exa_set_shared_usage(PixmapPtr pPixmap); + +Bool +xorg_exa_set_texture(PixmapPtr pPixmap, struct pipe_resource *tex); + +struct pipe_resource * +xorg_exa_create_root_texture(ScrnInfoPtr pScrn, + int width, int height, + int depth, int bpp); + +void * +xorg_exa_init(ScrnInfoPtr pScrn, Bool accel); + +void +xorg_exa_close(ScrnInfoPtr pScrn); + + +/*********************************************************************** + * xorg_dri2.c + */ +Bool +xorg_dri2_init(ScreenPtr pScreen); + +void +xorg_dri2_close(ScreenPtr pScreen); + + +/*********************************************************************** + * xorg_crtc.c + */ +void +xorg_crtc_init(ScrnInfoPtr pScrn); + +void +xorg_crtc_cursor_destroy(xf86CrtcPtr crtc); + + +/*********************************************************************** + * xorg_output.c + */ +void +xorg_output_init(ScrnInfoPtr pScrn); + +unsigned +xorg_output_get_id(xf86OutputPtr output); + + +/*********************************************************************** + * xorg_xv.c + */ +void +xorg_xv_init(ScreenPtr pScreen); + + +#endif /* _XORG_TRACKER_H_ */ diff --git a/src/gallium/state_trackers/xorg/xorg_winsys.h b/src/gallium/state_trackers/xorg/xorg_winsys.h new file mode 100644 index 0000000..865733b --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_winsys.h @@ -0,0 +1,50 @@ +/* + * 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 + * + */ + +/* + * File with all the junk needed to personalize the a xorg driver. + */ + +#ifndef _XORG_WINSYS_H_ +#define _XORG_WINSYS_H_ + +#include "xorg-server.h" +#include "xf86.h" +#include "pciaccess.h" + +#ifndef XSERVER_LIBPCIACCESS +#error "libpciaccess needed" +#endif + +void xorg_tracker_set_functions(ScrnInfoPtr scrn); +const OptionInfoRec * xorg_tracker_available_options(int chipid, int busid); +Bool xorg_tracker_have_modesetting(ScrnInfoPtr pScrn, struct pci_device *device); + +#endif diff --git a/src/gallium/state_trackers/xorg/xorg_xv.c b/src/gallium/state_trackers/xorg/xorg_xv.c new file mode 100644 index 0000000..c72ba9e --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_xv.c @@ -0,0 +1,776 @@ +#include "xorg_tracker.h" + +#include +#include +#include + +#include "xorg_exa.h" +#include "xorg_renderer.h" +#include "xorg_exa_tgsi.h" + +#include "cso_cache/cso_context.h" +#include "util/u_sampler.h" + +#include "pipe/p_screen.h" + +/*XXX get these from pipe's texture limits */ +#define IMAGE_MAX_WIDTH 2048 +#define IMAGE_MAX_HEIGHT 2048 + +#define RES_720P_X 1280 +#define RES_720P_Y 720 + + +/* The ITU-R BT.601 conversion matrix for SDTV. */ +/* original, matrix, but we transpose it to + * make the shader easier +static const float bt_601[] = { + 1.0, 0.0, 1.4075, , + 1.0, -0.3455, -0.7169, 0, + 1.0, 1.7790, 0., 0, +};*/ +static const float bt_601[] = { + 1.0, 1.0, 1.0, 0.5, + 0.0, -0.3455, 1.7790, 0, + 1.4075, -0.7169, 0., 0, +}; + +/* The ITU-R BT.709 conversion matrix for HDTV. */ +/* original, but we transpose to make the conversion + * in the shader easier +static const float bt_709[] = { + 1.0, 0.0, 1.581, 0, + 1.0, -0.1881, -0.47, 0, + 1.0, 1.8629, 0., 0, +};*/ +static const float bt_709[] = { + 1.0, 1.0, 1.0, 0.5, + 0.0, -0.1881, 1.8629, 0, + 1.581,-0.47 , 0.0, 0, +}; + +#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE) + +static Atom xvBrightness, xvContrast; + +#define NUM_TEXTURED_ATTRIBUTES 2 +static XF86AttributeRec TexturedAttributes[NUM_TEXTURED_ATTRIBUTES] = { + {XvSettable | XvGettable, -128, 127, "XV_BRIGHTNESS"}, + {XvSettable | XvGettable, 0, 255, "XV_CONTRAST"} +}; + +#define NUM_FORMATS 3 +static XF86VideoFormatRec Formats[NUM_FORMATS] = { + {15, TrueColor}, {16, TrueColor}, {24, TrueColor} +}; + +static XF86VideoEncodingRec DummyEncoding[1] = { + { + 0, + "XV_IMAGE", + IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT, + {1, 1} + } +}; + +#define NUM_IMAGES 3 +static XF86ImageRec Images[NUM_IMAGES] = { + XVIMAGE_UYVY, + XVIMAGE_YUY2, + XVIMAGE_YV12, +}; + +struct xorg_xv_port_priv { + struct xorg_renderer *r; + + RegionRec clip; + + int brightness; + int contrast; + + int current_set; + /* juggle two sets of seperate Y, U and V + * textures */ + struct pipe_resource *yuv[2][3]; + struct pipe_sampler_view *yuv_views[2][3]; +}; + + +static void +stop_video(ScrnInfoPtr pScrn, pointer data, Bool shutdown) +{ + struct xorg_xv_port_priv *priv = (struct xorg_xv_port_priv *)data; + + REGION_EMPTY(pScrn->pScreen, &priv->clip); +} + +static int +set_port_attribute(ScrnInfoPtr pScrn, + Atom attribute, INT32 value, pointer data) +{ + struct xorg_xv_port_priv *priv = (struct xorg_xv_port_priv *)data; + + if (attribute == xvBrightness) { + if ((value < -128) || (value > 127)) + return BadValue; + priv->brightness = value; + } else if (attribute == xvContrast) { + if ((value < 0) || (value > 255)) + return BadValue; + priv->contrast = value; + } else + return BadMatch; + + return Success; +} + +static int +get_port_attribute(ScrnInfoPtr pScrn, + Atom attribute, INT32 * value, pointer data) +{ + struct xorg_xv_port_priv *priv = (struct xorg_xv_port_priv *)data; + + if (attribute == xvBrightness) + *value = priv->brightness; + else if (attribute == xvContrast) + *value = priv->contrast; + else + return BadMatch; + + return Success; +} + +static void +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) +{ + if (vid_w > (drw_w << 1)) + drw_w = vid_w >> 1; + if (vid_h > (drw_h << 1)) + drw_h = vid_h >> 1; + + *p_w = drw_w; + *p_h = drw_h; +} + +static INLINE struct pipe_resource * +create_component_texture(struct pipe_context *pipe, + int width, int height) +{ + struct pipe_screen *screen = pipe->screen; + struct pipe_resource *tex = 0; + struct pipe_resource templ; + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.format = PIPE_FORMAT_L8_UNORM; + templ.last_level = 0; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.array_size = 1; + templ.bind = PIPE_BIND_SAMPLER_VIEW; + + tex = screen->resource_create(screen, &templ); + + return tex; +} + +static int +check_yuv_textures(struct xorg_xv_port_priv *priv, int width, int height) +{ + struct pipe_resource **dst = priv->yuv[priv->current_set]; + struct pipe_sampler_view **dst_view = priv->yuv_views[priv->current_set]; + struct pipe_sampler_view view_templ; + struct pipe_context *pipe = priv->r->pipe; + + if (!dst[0] || + dst[0]->width0 != width || + dst[0]->height0 != height) { + pipe_resource_reference(&dst[0], NULL); + pipe_sampler_view_reference(&dst_view[0], NULL); + } + if (!dst[1] || + dst[1]->width0 != width || + dst[1]->height0 != height) { + pipe_resource_reference(&dst[1], NULL); + pipe_sampler_view_reference(&dst_view[1], NULL); + } + if (!dst[2] || + dst[2]->width0 != width || + dst[2]->height0 != height) { + pipe_resource_reference(&dst[2], NULL); + pipe_sampler_view_reference(&dst_view[2], NULL); + } + + if (!dst[0]) { + dst[0] = create_component_texture(priv->r->pipe, width, height); + if (dst[0]) { + u_sampler_view_default_template(&view_templ, + dst[0], + dst[0]->format); + dst_view[0] = pipe->create_sampler_view(pipe, dst[0], &view_templ); + } + } + + if (!dst[1]) { + dst[1] = create_component_texture(priv->r->pipe, width, height); + if (dst[1]) { + u_sampler_view_default_template(&view_templ, + dst[1], + dst[1]->format); + dst_view[1] = pipe->create_sampler_view(pipe, dst[1], &view_templ); + } + } + + if (!dst[2]) { + dst[2] = create_component_texture(priv->r->pipe, width, height); + if (dst[2]) { + u_sampler_view_default_template(&view_templ, + dst[2], + dst[2]->format); + dst_view[2] = pipe->create_sampler_view(pipe, dst[2], &view_templ); + } + } + + if (!dst[0] || !dst[1] || !dst[2] || !dst_view[0] || !dst_view[1] || !dst_view[2] ) + return BadAlloc; + + return Success; +} + +static int +query_image_attributes(ScrnInfoPtr pScrn, + int id, + unsigned short *w, unsigned short *h, + int *pitches, int *offsets) +{ + int size, tmp; + + if (*w > IMAGE_MAX_WIDTH) + *w = IMAGE_MAX_WIDTH; + if (*h > IMAGE_MAX_HEIGHT) + *h = IMAGE_MAX_HEIGHT; + + *w = (*w + 1) & ~1; + if (offsets) + offsets[0] = 0; + + switch (id) { + case FOURCC_YV12: + *h = (*h + 1) & ~1; + size = (*w + 3) & ~3; + if (pitches) { + pitches[0] = size; + } + size *= *h; + if (offsets) { + offsets[1] = size; + } + tmp = ((*w >> 1) + 3) & ~3; + if (pitches) { + pitches[1] = pitches[2] = tmp; + } + tmp *= (*h >> 1); + size += tmp; + if (offsets) { + offsets[2] = size; + } + size += tmp; + break; + case FOURCC_UYVY: + case FOURCC_YUY2: + default: + size = *w << 1; + if (pitches) + pitches[0] = size; + size *= *h; + break; + } + + return size; +} + +static void +copy_packed_data(ScrnInfoPtr pScrn, + struct xorg_xv_port_priv *port, + int id, + unsigned char *buf, + int left, + int top, + unsigned short w, unsigned short h) +{ + int i, j; + struct pipe_resource **dst = port->yuv[port->current_set]; + struct pipe_transfer *ytrans, *utrans, *vtrans; + struct pipe_context *pipe = port->r->pipe; + char *ymap, *vmap, *umap; + unsigned char y1, y2, u, v; + int yidx, uidx, vidx; + int y_array_size = w * h; + + ytrans = pipe_get_transfer(pipe, dst[0], + 0, 0, + PIPE_TRANSFER_WRITE, + left, top, w, h); + utrans = pipe_get_transfer(pipe, dst[1], + 0, 0, + PIPE_TRANSFER_WRITE, + left, top, w, h); + vtrans = pipe_get_transfer(pipe, dst[2], + 0, 0, + PIPE_TRANSFER_WRITE, + left, top, w, h); + + ymap = (char*)pipe->transfer_map(pipe, ytrans); + umap = (char*)pipe->transfer_map(pipe, utrans); + vmap = (char*)pipe->transfer_map(pipe, vtrans); + + yidx = uidx = vidx = 0; + + switch (id) { + case FOURCC_YV12: { + int pitches[3], offsets[3]; + unsigned char *y, *u, *v; + query_image_attributes(pScrn, FOURCC_YV12, + &w, &h, pitches, offsets); + + y = buf + offsets[0]; + v = buf + offsets[1]; + u = buf + offsets[2]; + for (i = 0; i < h; ++i) { + for (j = 0; j < w; ++j) { + int yoffset = (w*i+j); + int ii = (i|1), jj = (j|1); + int vuoffset = (w/2)*(ii/2) + (jj/2); + ymap[yidx++] = y[yoffset]; + umap[uidx++] = u[vuoffset]; + vmap[vidx++] = v[vuoffset]; + } + } + } + break; + case FOURCC_UYVY: + for (i = 0; i < y_array_size; i +=2 ) { + /* extracting two pixels */ + u = buf[0]; + y1 = buf[1]; + v = buf[2]; + y2 = buf[3]; + buf += 4; + + ymap[yidx++] = y1; + ymap[yidx++] = y2; + umap[uidx++] = u; + umap[uidx++] = u; + vmap[vidx++] = v; + vmap[vidx++] = v; + } + break; + case FOURCC_YUY2: + for (i = 0; i < y_array_size; i +=2 ) { + /* extracting two pixels */ + y1 = buf[0]; + u = buf[1]; + y2 = buf[2]; + v = buf[3]; + + buf += 4; + + ymap[yidx++] = y1; + ymap[yidx++] = y2; + umap[uidx++] = u; + umap[uidx++] = u; + vmap[vidx++] = v; + vmap[vidx++] = v; + } + break; + default: + debug_assert(!"Unsupported yuv format!"); + break; + } + + pipe->transfer_unmap(pipe, ytrans); + pipe->transfer_unmap(pipe, utrans); + pipe->transfer_unmap(pipe, vtrans); + pipe->transfer_destroy(pipe, ytrans); + pipe->transfer_destroy(pipe, utrans); + pipe->transfer_destroy(pipe, vtrans); +} + + +static void +setup_fs_video_constants(struct xorg_renderer *r, boolean hdtv) +{ + const int param_bytes = 12 * sizeof(float); + const float *video_constants = (hdtv) ? bt_709 : bt_601; + + renderer_set_constants(r, PIPE_SHADER_FRAGMENT, + video_constants, param_bytes); +} + +static void +draw_yuv(struct xorg_xv_port_priv *port, + float src_x, float src_y, float src_w, float src_h, + int dst_x, int dst_y, int dst_w, int dst_h) +{ + struct pipe_resource **textures = port->yuv[port->current_set]; + + /*debug_printf(" draw_yuv([%d, %d, %d ,%d], [%d, %d, %d, %d])\n", + src_x, src_y, src_w, src_h, + dst_x, dst_y, dst_w, dst_h);*/ + renderer_draw_yuv(port->r, + src_x, src_y, src_w, src_h, + dst_x, dst_y, dst_w, dst_h, + textures); +} + +static void +bind_blend_state(struct xorg_xv_port_priv *port) +{ + struct pipe_blend_state blend; + + memset(&blend, 0, sizeof(struct pipe_blend_state)); + blend.rt[0].blend_enable = 0; + blend.rt[0].colormask = PIPE_MASK_RGBA; + + /* porter&duff src */ + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE; + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; + + cso_set_blend(port->r->cso, &blend); +} + + +static void +bind_shaders(struct xorg_xv_port_priv *port) +{ + unsigned vs_traits = 0, fs_traits = 0; + struct xorg_shader shader; + + vs_traits |= VS_YUV; + fs_traits |= FS_YUV; + + shader = xorg_shaders_get(port->r->shaders, vs_traits, fs_traits); + cso_set_vertex_shader_handle(port->r->cso, shader.vs); + cso_set_fragment_shader_handle(port->r->cso, shader.fs); +} + +static INLINE void +conditional_flush(struct pipe_context *pipe, struct pipe_resource **tex, + int num) +{ + int i; + for (i = 0; i < num; ++i) { + if (tex[i] && pipe->is_resource_referenced(pipe, tex[i], 0, 0) & + PIPE_REFERENCED_FOR_WRITE) { + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + return; + } + } +} + +static void +bind_samplers(struct xorg_xv_port_priv *port) +{ + struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_state sampler; + struct pipe_resource **dst = port->yuv[port->current_set]; + struct pipe_sampler_view **dst_views = port->yuv_views[port->current_set]; + + memset(&sampler, 0, sizeof(struct pipe_sampler_state)); + + conditional_flush(port->r->pipe, dst, 3); + + sampler.wrap_s = PIPE_TEX_WRAP_CLAMP; + sampler.wrap_t = PIPE_TEX_WRAP_CLAMP; + sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR; + sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR; + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; + sampler.normalized_coords = 1; + + samplers[0] = &sampler; + samplers[1] = &sampler; + samplers[2] = &sampler; + + + cso_set_samplers(port->r->cso, 3, + (const struct pipe_sampler_state **)samplers); + cso_set_fragment_sampler_views(port->r->cso, 3, dst_views); +} + +static int +display_video(ScrnInfoPtr pScrn, struct xorg_xv_port_priv *pPriv, int id, + RegionPtr dstRegion, + int src_x, int src_y, int src_w, int src_h, + int dstX, int dstY, int dst_w, int dst_h, + PixmapPtr pPixmap) +{ + modesettingPtr ms = modesettingPTR(pScrn); + BoxPtr pbox; + int nbox; + int dxo, dyo; + Bool hdtv; + int x, y, w, h; + struct exa_pixmap_priv *dst; + struct pipe_surface *dst_surf = NULL; + + exaMoveInPixmap(pPixmap); + dst = exaGetPixmapDriverPrivate(pPixmap); + + /*debug_printf("display_video([%d, %d, %d, %d], [%d, %d, %d, %d])\n", + src_x, src_y, src_w, src_h, dstX, dstY, dst_w, dst_h);*/ + + if (dst && !dst->tex) { + xorg_exa_set_shared_usage(pPixmap); + pScrn->pScreen->ModifyPixmapHeader(pPixmap, 0, 0, 0, 0, 0, NULL); + } + + if (!dst || !dst->tex) + XORG_FALLBACK("Xv destination %s", !dst ? "!dst" : "!dst->tex"); + + dst_surf = xorg_gpu_surface(pPriv->r->pipe, dst); + hdtv = ((src_w >= RES_720P_X) && (src_h >= RES_720P_Y)); + +#ifdef COMPOSITE + REGION_TRANSLATE(pScrn->pScreen, dstRegion, -pPixmap->screen_x, + -pPixmap->screen_y); +#endif + + dxo = dstRegion->extents.x1; + dyo = dstRegion->extents.y1; + + pbox = REGION_RECTS(dstRegion); + nbox = REGION_NUM_RECTS(dstRegion); + + renderer_bind_destination(pPriv->r, dst_surf, + dst_surf->width, dst_surf->height); + + bind_blend_state(pPriv); + bind_shaders(pPriv); + bind_samplers(pPriv); + setup_fs_video_constants(pPriv->r, hdtv); + + DamageDamageRegion(&pPixmap->drawable, dstRegion); + + while (nbox--) { + int box_x1 = pbox->x1; + int box_y1 = pbox->y1; + int box_x2 = pbox->x2; + int box_y2 = pbox->y2; + float diff_x = (float)src_w / (float)dst_w; + float diff_y = (float)src_h / (float)dst_h; + float offset_x = box_x1 - dstX; + float offset_y = box_y1 - dstY; + float offset_w; + float offset_h; + +#ifdef COMPOSITE + offset_x += pPixmap->screen_x; + offset_y += pPixmap->screen_y; +#endif + + x = box_x1; + y = box_y1; + w = box_x2 - box_x1; + h = box_y2 - box_y1; + + offset_w = dst_w - w; + offset_h = dst_h - h; + + draw_yuv(pPriv, + (float) src_x + offset_x*diff_x, (float) src_y + offset_y*diff_y, + (float) src_w - offset_w*diff_x, (float) src_h - offset_h*diff_y, + x, y, w, h); + + pbox++; + } + DamageRegionProcessPending(&pPixmap->drawable); + + pipe_surface_reference(&dst_surf, NULL); + + return TRUE; +} + +static int +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 id, unsigned char *buf, + short width, short height, + Bool sync, RegionPtr clipBoxes, pointer data, + DrawablePtr pDraw) +{ + struct xorg_xv_port_priv *pPriv = (struct xorg_xv_port_priv *) data; + ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex]; + PixmapPtr pPixmap; + INT32 x1, x2, y1, y2; + BoxRec dstBox; + int ret; + + /* Clip */ + x1 = src_x; + x2 = src_x + src_w; + y1 = src_y; + y2 = src_y + src_h; + + dstBox.x1 = drw_x; + dstBox.x2 = drw_x + drw_w; + dstBox.y1 = drw_y; + dstBox.y2 = drw_y + drw_h; + + if (!xf86XVClipVideoHelper(&dstBox, &x1, &x2, &y1, &y2, clipBoxes, + width, height)) + return Success; + + ret = check_yuv_textures(pPriv, width, height); + + if (ret) + return ret; + + copy_packed_data(pScrn, pPriv, id, buf, + src_x, src_y, width, height); + + if (pDraw->type == DRAWABLE_WINDOW) { + pPixmap = (*pScreen->GetWindowPixmap)((WindowPtr)pDraw); + } else { + pPixmap = (PixmapPtr)pDraw; + } + + display_video(pScrn, pPriv, id, clipBoxes, + src_x, src_y, src_w, src_h, + drw_x, drw_y, + drw_w, drw_h, pPixmap); + + pPriv->current_set = (pPriv->current_set + 1) & 1; + return Success; +} + +static struct xorg_xv_port_priv * +port_priv_create(struct xorg_renderer *r) +{ + struct xorg_xv_port_priv *priv = NULL; + + priv = calloc(1, sizeof(struct xorg_xv_port_priv)); + + if (!priv) + return NULL; + + priv->r = r; + + REGION_NULL(pScreen, &priv->clip); + + debug_assert(priv && priv->r); + + return priv; +} + +static XF86VideoAdaptorPtr +xorg_setup_textured_adapter(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + modesettingPtr ms = modesettingPTR(pScrn); + XF86VideoAdaptorPtr adapt; + XF86AttributePtr attrs; + DevUnion *dev_unions; + int nports = 16, i; + int nattributes; + + nattributes = NUM_TEXTURED_ATTRIBUTES; + + debug_assert(ms->exa); + debug_assert(ms->exa->renderer); + + adapt = calloc(1, sizeof(XF86VideoAdaptorRec)); + dev_unions = calloc(nports, sizeof(DevUnion)); + attrs = calloc(nattributes, sizeof(XF86AttributeRec)); + if (adapt == NULL || dev_unions == NULL || attrs == NULL) { + free(adapt); + free(dev_unions); + free(attrs); + return NULL; + } + + adapt->type = XvWindowMask | XvInputMask | XvImageMask; + adapt->flags = 0; + adapt->name = "Gallium3D Textured Video"; + adapt->nEncodings = 1; + adapt->pEncodings = DummyEncoding; + adapt->nFormats = NUM_FORMATS; + adapt->pFormats = Formats; + adapt->nPorts = 0; + adapt->pPortPrivates = dev_unions; + adapt->nAttributes = nattributes; + adapt->pAttributes = attrs; + memcpy(attrs, TexturedAttributes, nattributes * sizeof(XF86AttributeRec)); + adapt->nImages = NUM_IMAGES; + adapt->pImages = Images; + adapt->PutVideo = NULL; + adapt->PutStill = NULL; + adapt->GetVideo = NULL; + adapt->GetStill = NULL; + adapt->StopVideo = stop_video; + adapt->SetPortAttribute = set_port_attribute; + adapt->GetPortAttribute = get_port_attribute; + adapt->QueryBestSize = query_best_size; + adapt->PutImage = put_image; + adapt->QueryImageAttributes = query_image_attributes; + + for (i = 0; i < nports; i++) { + struct xorg_xv_port_priv *priv = + port_priv_create(ms->exa->renderer); + + adapt->pPortPrivates[i].ptr = (pointer) (priv); + adapt->nPorts++; + } + + return adapt; +} + +void +xorg_xv_init(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + /*modesettingPtr ms = modesettingPTR(pScrn);*/ + XF86VideoAdaptorPtr *adaptors, *new_adaptors = NULL; + XF86VideoAdaptorPtr textured_adapter; + int num_adaptors; + + num_adaptors = xf86XVListGenericAdaptors(pScrn, &adaptors); + new_adaptors = malloc((num_adaptors + 1) * sizeof(XF86VideoAdaptorPtr *)); + if (new_adaptors == NULL) + return; + + memcpy(new_adaptors, adaptors, num_adaptors * sizeof(XF86VideoAdaptorPtr)); + adaptors = new_adaptors; + + /* Add the adaptors supported by our hardware. First, set up the atoms + * that will be used by both output adaptors. + */ + xvBrightness = MAKE_ATOM("XV_BRIGHTNESS"); + xvContrast = MAKE_ATOM("XV_CONTRAST"); + + textured_adapter = xorg_setup_textured_adapter(pScreen); + + debug_assert(textured_adapter); + + if (textured_adapter) { + adaptors[num_adaptors++] = textured_adapter; + } + + if (num_adaptors) { + xf86XVScreenInit(pScreen, adaptors, num_adaptors); + } else { + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "Disabling Xv because no adaptors could be initialized.\n"); + } + + free(adaptors); +} diff --git a/src/gallium/targets/Makefile b/src/gallium/targets/Makefile new file mode 100644 index 0000000..a0bc5eb --- /dev/null +++ b/src/gallium/targets/Makefile @@ -0,0 +1,12 @@ +# src/gallium/winsys/Makefile +TOP = ../../.. +include $(TOP)/configs/current + +SUBDIRS = $(GALLIUM_TARGET_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/targets/Makefile.dri b/src/gallium/targets/Makefile.dri new file mode 100644 index 0000000..3fb4cc6 --- /dev/null +++ b/src/gallium/targets/Makefile.dri @@ -0,0 +1,116 @@ +# -*-makefile-*- + + +ifeq ($(MESA_LLVM),1) +PIPE_DRIVERS += $(TOP)/src/gallium/drivers/llvmpipe/libllvmpipe.a +LDFLAGS += $(LLVM_LDFLAGS) +DRIVER_EXTRAS = $(LLVM_LIBS) +else +LDFLAGS += -lstdc++ +endif + +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/mapi \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/winsys \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/mesa/main \ + -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) + +LIBNAME_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME) + + +##### 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_STAGING) + +$(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 '$(CXX)' -ldflags '$(LDFLAGS)' \ + $(OBJECTS) $(PIPE_DRIVERS) \ + -Wl,--start-group $(MESA_MODULES) -Wl,--end-group \ + $(DRI_LIB_DEPS) $(DRIVER_EXTRAS) + $(CXX) $(CFLAGS) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS) $(LDFLAGS); + @rm -f $@.test + mv -f $@.tmp $@ + +$(TOP)/$(LIB_DIR)/gallium: + mkdir -p $@ + +$(LIBNAME_STAGING): $(LIBNAME) + $(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/Makefile.xorg b/src/gallium/targets/Makefile.xorg new file mode 100644 index 0000000..47040bb --- /dev/null +++ b/src/gallium/targets/Makefile.xorg @@ -0,0 +1,82 @@ +# src/gallium/targets/Makefile.xorg + +# Template makefile for gallium xorg drivers. +# +# Usage: +# The minimum that the including makefile needs to define +# is TOP, LIBNAME and one of of the *_SOURCES. +# +# Optional defines: +# DRIVER_INCLUDES are appended to the list of includes directories. +# DRIVER_DEFINES is not used for makedepend, but for compilation. +# DRIVER_PIPES are pipe drivers and modules that the driver depends on. +# DRIVER_LINKS are flags given to the linker. + +### Basic defines ### + +OBJECTS = $(C_SOURCES:.c=.o) \ + $(CPP_SOURCES:.cpp=.o) \ + $(ASM_SOURCES:.S=.o) + +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/winsys \ + $(DRIVER_INCLUDES) + +LIBNAME_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET) + +ifeq ($(MESA_LLVM),1) +LD = $(CXX) +LDFLAGS += $(LLVM_LDFLAGS) +USE_CXX=1 +DRIVER_PIPES += $(TOP)/src/gallium/drivers/llvmpipe/libllvmpipe.a +DRIVER_LINKS += $(LLVM_LIBS) -lm -ldl +endif + + +##### TARGETS ##### + +default: depend $(TOP)/$(LIB_DIR)/gallium $(LIBNAME) $(LIBNAME_STAGING) + +$(LIBNAME): $(OBJECTS) Makefile ../Makefile.xorg $(LIBS) $(DRIVER_PIPES) + $(MKLIB) -linker '$(CC)' -noprefix -o $@ $(LDFLAGS) $(OBJECTS) $(DRIVER_PIPES) $(GALLIUM_AUXILIARIES) $(DRIVER_LINKS) + +depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURCES) + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(GENERATED_SOURCES) 2> /dev/null + +$(LIBNAME_STAGING): $(LIBNAME) + $(INSTALL) $(LIBNAME) $(TOP)/$(LIB_DIR)/gallium + +$(TOP)/$(LIB_DIR)/gallium: + mkdir -p $@ + +clean: + rm -f $(OBJECTS) $(GENERATED_SOURCES) $(LIBNAME).a depend depend.bak + +install: + $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + $(MINSTALL) -m 755 $(LIBNAME) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + + +##### RULES ##### + +%.s: %.c + $(CC) -S $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + +%.o: %.c + $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + +%.o: %.cpp + $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DRIVER_DEFINES) $< -o $@ + +%.o: %.S + $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + +sinclude depend + +.PHONY: default clean install diff --git a/src/gallium/targets/SConscript.dri b/src/gallium/targets/SConscript.dri new file mode 100644 index 0000000..101863a --- /dev/null +++ b/src/gallium/targets/SConscript.dri @@ -0,0 +1,81 @@ +################################### +# SConcscript file for dri targets + +Import('*') + +if not env['dri']: + Return() + +drienv = env.Clone() + +drienv.Replace(CPPPATH = [ + '#src/mesa/drivers/dri/common', + '#include', + '#include/GL/internal', + '#src/mapi', + '#src/gallium/include', + '#src/gallium/auxiliary', + '#src/gallium/drivers', + '#src/gallium/winsys', + '#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') + +dri_common_utils = drienv.SharedObject( + target = 'utils.o', + source = '#src/mesa/drivers/dri/common/utils.c' +) + +dri_common_xmlconfig = drienv.SharedObject( + target = 'xmlconfig.o', + source = '#src/mesa/drivers/dri/common/xmlconfig.c' +) + +dri_common_vblank = drienv.SharedObject( + target = 'vblank.o', + source = '#src/mesa/drivers/dri/common/vblank.c' +) + +dri_common_dri_util = drienv.SharedObject( + target = 'dri_util.o', + source = '#src/mesa/drivers/dri/common/dri_util.c' +) + +dri_common_drisw_util = drienv.SharedObject( + target = 'drisw_util.o', + source = '#src/mesa/drivers/dri/common/drisw_util.c' +) + + +COMMON_DRI_SW_OBJECTS = [ + dri_common_utils, + dri_common_xmlconfig, + dri_common_drisw_util, +] + +COMMON_DRI_DRM_OBJECTS = [ + dri_common_utils, + dri_common_xmlconfig, + dri_common_vblank, + dri_common_dri_util, +] + +drienv.AppendUnique(LIBS = [ + 'expat', +]) + +Export([ + 'drienv', + 'COMMON_DRI_SW_OBJECTS', + 'COMMON_DRI_DRM_OBJECTS', +]) diff --git a/src/gallium/targets/dri-i915/Makefile b/src/gallium/targets/dri-i915/Makefile new file mode 100644 index 0000000..9c10d71 --- /dev/null +++ b/src/gallium/targets/dri-i915/Makefile @@ -0,0 +1,32 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = i915_dri.so + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ + $(TOP)/src/gallium/winsys/i915/drm/libi915drm.a \ + $(TOP)/src/gallium/winsys/sw/wrapper/libwsw.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/galahad/libgalahad.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/rbug/librbug.a \ + $(TOP)/src/gallium/drivers/i915/libi915.a + +C_SOURCES = \ + target.c \ + $(COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +DRIVER_DEFINES = \ + -DGALLIUM_RBUG -DGALLIUM_TRACE -DGALLIUM_GALAHAD -DGALLIUM_SOFTPIPE + +ifeq ($(MESA_LLVM),1) +DRIVER_DEFINES += -DGALLIUM_LLVMPIPE +endif + +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 0000000..ab60013 --- /dev/null +++ b/src/gallium/targets/dri-i915/SConscript @@ -0,0 +1,29 @@ +Import('*') + +env = drienv.Clone() + +env.ParseConfig('pkg-config --cflags --libs libdrm_intel') + +env.Append(CPPDEFINES = ['GALLIUM_RBUG', 'GALLIUM_TRACE', 'GALLIUM_GALAHAD']) + +env.Prepend(LIBS = [ + ws_wrapper, + st_dri, + i915drm, + i915, + galahad, + trace, + rbug, + mesa, + glsl, + gallium, + COMMON_DRI_DRM_OBJECTS +]) + +module = env.LoadableModule( + target = 'i915_dri.so', + source = 'target.c', + SHLIBPREFIX = '', +) + +env.Alias('dri-i915', module) \ No newline at end of file diff --git a/src/gallium/targets/dri-i915/target.c b/src/gallium/targets/dri-i915/target.c new file mode 100644 index 0000000..a27b7bd --- /dev/null +++ b/src/gallium/targets/dri-i915/target.c @@ -0,0 +1,29 @@ + +#include "state_tracker/drm_driver.h" +#include "target-helpers/inline_wrapper_sw_helper.h" +#include "target-helpers/inline_debug_helper.h" +#include "i915/drm/i915_drm_public.h" +#include "i915/i915_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct i915_winsys *iws; + struct pipe_screen *screen; + + iws = i915_drm_winsys_create(fd); + if (!iws) + return NULL; + + screen = i915_screen_create(iws); + if (!screen) + return NULL; + + screen = sw_screen_wrap(screen); + + screen = debug_screen_wrap(screen); + + return screen; +} + +DRM_DRIVER_DESCRIPTOR("i915", "i915", create_screen) diff --git a/src/gallium/targets/dri-i965/Makefile b/src/gallium/targets/dri-i965/Makefile new file mode 100644 index 0000000..4b50d04 --- /dev/null +++ b/src/gallium/targets/dri-i965/Makefile @@ -0,0 +1,32 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = i965_dri.so + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ + $(TOP)/src/gallium/winsys/i965/drm/libi965drm.a \ + $(TOP)/src/gallium/winsys/sw/wrapper/libwsw.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/galahad/libgalahad.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/rbug/librbug.a \ + $(TOP)/src/gallium/drivers/i965/libi965.a + +C_SOURCES = \ + target.c \ + $(COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +DRIVER_DEFINES = \ + -DGALLIUM_RBUG -DGALLIUM_TRACE -DGALLIUM_GALAHAD -DGALLIUM_SOFTPIPE + +ifeq ($(MESA_LLVM),1) +DRIVER_DEFINES += -DGALLIUM_LLVMPIPE +endif + +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 0000000..669f70d --- /dev/null +++ b/src/gallium/targets/dri-i965/SConscript @@ -0,0 +1,32 @@ +Import('*') + +env = drienv.Clone() + +env.ParseConfig('pkg-config --cflags --libs libdrm_intel') + +env.Append(CPPDEFINES = [ + 'GALLIUM_SOFTPIPE', + 'GALLIUM_RBUG', + 'GALLIUM_TRACE' +]) + +env.Prepend(LIBS = [ + st_dri, + i965drm, + ws_wrapper, + i965, + trace, + rbug, + mesa, + glsl, + gallium, + COMMON_DRI_DRM_OBJECTS +]) + +module = env.LoadableModule( + target = 'i965_dri.so', + source = 'target.c', + SHLIBPREFIX = '', +) + +env.Alias('dri-i965', module) \ No newline at end of file diff --git a/src/gallium/targets/dri-i965/target.c b/src/gallium/targets/dri-i965/target.c new file mode 100644 index 0000000..0632b97 --- /dev/null +++ b/src/gallium/targets/dri-i965/target.c @@ -0,0 +1,29 @@ + +#include "target-helpers/inline_wrapper_sw_helper.h" +#include "target-helpers/inline_debug_helper.h" +#include "state_tracker/drm_driver.h" +#include "i965/drm/i965_drm_public.h" +#include "i965/brw_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct brw_winsys_screen *bws; + struct pipe_screen *screen; + + bws = i965_drm_winsys_screen_create(fd); + if (!bws) + return NULL; + + screen = brw_screen_create(bws); + if (!screen) + return NULL; + + screen = sw_screen_wrap(screen); + + screen = debug_screen_wrap(screen); + + return screen; +} + +DRM_DRIVER_DESCRIPTOR("i915", "i965", create_screen) diff --git a/src/gallium/targets/dri-noop/Makefile b/src/gallium/targets/dri-noop/Makefile new file mode 100644 index 0000000..21c5f4f --- /dev/null +++ b/src/gallium/targets/dri-noop/Makefile @@ -0,0 +1,34 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = noop_dri.so + +DRIVER_DEFINES = \ + -D__NOT_HAVE_DRM_H + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/sw/libdrisw.a \ + $(TOP)/src/gallium/winsys/sw/dri/libswdri.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/rbug/librbug.a \ + $(TOP)/src/gallium/drivers/noop/libnoop.a + +SWRAST_COMMON_GALLIUM_SOURCES = \ + $(TOP)/src/mesa/drivers/dri/common/utils.c \ + $(TOP)/src/mesa/drivers/dri/common/drisw_util.c \ + $(TOP)/src/mesa/drivers/dri/common/xmlconfig.c + +C_SOURCES = \ + swrast_drm_api.c \ + $(SWRAST_COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +ASM_SOURCES = + +include ../Makefile.dri + +INCLUDES += \ + -I$(TOP)/src/gallium/winsys/sw/dri + +symlinks: diff --git a/src/gallium/targets/dri-noop/SConscript b/src/gallium/targets/dri-noop/SConscript new file mode 100644 index 0000000..9c04ee6 --- /dev/null +++ b/src/gallium/targets/dri-noop/SConscript @@ -0,0 +1,31 @@ +Import('*') + +env = drienv.Clone() + +env.Append(CPPPATH = [ + '#/src/gallium/winsys/sw/dri', +]) + +env.Prepend(LIBS = [ + st_drisw, + ws_dri, + noop, + mesa, + glsl, + gallium, + COMMON_DRI_SW_OBJECTS +]) + +env.Prepend(LIBS = [noop]) + +swrastg_sources = [ + 'swrast_drm_api.c' +] + +module = env.LoadableModule( + target ='noop_dri.so', + source = swrastg_sources, + SHLIBPREFIX = '', +) + +env.Alias('dri-noop', module) diff --git a/src/gallium/targets/dri-noop/swrast_drm_api.c b/src/gallium/targets/dri-noop/swrast_drm_api.c new file mode 100644 index 0000000..a99779f --- /dev/null +++ b/src/gallium/targets/dri-noop/swrast_drm_api.c @@ -0,0 +1,63 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "pipe/p_compiler.h" +#include "util/u_memory.h" +#include "dri_sw_winsys.h" +#include "noop/noop_public.h" + +#include "target-helpers/inline_debug_helper.h" +#include "target-helpers/inline_sw_helper.h" + + +struct pipe_screen * +drisw_create_screen(struct drisw_loader_funcs *lf) +{ + struct sw_winsys *winsys = NULL; + struct pipe_screen *screen = NULL; + + winsys = dri_create_sw_winsys(lf); + if (winsys == NULL) + return NULL; + + screen = noop_screen_create(winsys); + if (!screen) + goto fail; + + screen = debug_screen_wrap(screen); + + return screen; + +fail: + if (winsys) + winsys->destroy(winsys); + + return NULL; +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/targets/dri-nouveau/Makefile b/src/gallium/targets/dri-nouveau/Makefile new file mode 100644 index 0000000..2f64f31 --- /dev/null +++ b/src/gallium/targets/dri-nouveau/Makefile @@ -0,0 +1,27 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = nouveau_dri.so + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ + $(TOP)/src/gallium/winsys/nouveau/drm/libnouveaudrm.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/rbug/librbug.a \ + $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ + $(TOP)/src/gallium/drivers/nv50/libnv50.a \ + $(TOP)/src/gallium/drivers/nouveau/libnouveau.a + +C_SOURCES = \ + target.c \ + $(COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +DRIVER_DEFINES = \ + -DGALLIUM_RBUG -DGALLIUM_TRACE + +include ../Makefile.dri + +DRI_LIB_DEPS += $(shell pkg-config libdrm_nouveau --libs) + +symlinks: diff --git a/src/gallium/targets/dri-nouveau/target.c b/src/gallium/targets/dri-nouveau/target.c new file mode 100644 index 0000000..e725a4d --- /dev/null +++ b/src/gallium/targets/dri-nouveau/target.c @@ -0,0 +1,20 @@ + +#include "target-helpers/inline_debug_helper.h" +#include "state_tracker/drm_driver.h" +#include "nouveau/drm/nouveau_drm_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct pipe_screen *screen; + + screen = nouveau_drm_screen_create(fd); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +} + +DRM_DRIVER_DESCRIPTOR("nouveau", "nouveau", create_screen) diff --git a/src/gallium/targets/dri-r300/Makefile b/src/gallium/targets/dri-r300/Makefile new file mode 100644 index 0000000..9afbb13 --- /dev/null +++ b/src/gallium/targets/dri-r300/Makefile @@ -0,0 +1,27 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = r300_dri.so + +PIPE_DRIVERS = \ + $(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/galahad/libgalahad.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/rbug/librbug.a \ + $(TOP)/src/gallium/drivers/r300/libr300.a + +C_SOURCES = \ + target.c \ + $(COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +DRIVER_DEFINES = \ + -DGALLIUM_RBUG -DGALLIUM_TRACE -DGALLIUM_GALAHAD + +include ../Makefile.dri + +DRI_LIB_DEPS += -ldrm_radeon + +symlinks: diff --git a/src/gallium/targets/dri-r300/SConscript b/src/gallium/targets/dri-r300/SConscript new file mode 100644 index 0000000..005b4bb --- /dev/null +++ b/src/gallium/targets/dri-r300/SConscript @@ -0,0 +1,28 @@ +Import('*') + +env = drienv.Clone() + +env.ParseConfig('pkg-config --cflags --libs libdrm_radeon') + +env.Append(CPPDEFINES = ['GALLIUM_RBUG', 'GALLIUM_TRACE', 'GALLIUM_GALAHAD']) + +env.Prepend(LIBS = [ + st_dri, + radeonwinsys, + r300, + galahad, + trace, + rbug, + mesa, + glsl, + gallium, + COMMON_DRI_DRM_OBJECTS +]) + +module = env.SharedLibrary( + target ='r300_dri.so', + source = 'target.c', + SHLIBPREFIX = '', +) + +env.Alias('dri-r300', module) \ No newline at end of file diff --git a/src/gallium/targets/dri-r300/target.c b/src/gallium/targets/dri-r300/target.c new file mode 100644 index 0000000..2ecf345 --- /dev/null +++ b/src/gallium/targets/dri-r300/target.c @@ -0,0 +1,26 @@ + +#include "target-helpers/inline_debug_helper.h" +#include "state_tracker/drm_driver.h" +#include "radeon/drm/radeon_drm_public.h" +#include "r300/r300_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct r300_winsys_screen *sws; + struct pipe_screen *screen; + + sws = r300_drm_winsys_screen_create(fd); + if (!sws) + return NULL; + + screen = r300_screen_create(sws); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +} + +DRM_DRIVER_DESCRIPTOR("r300", "radeon", create_screen) diff --git a/src/gallium/targets/dri-r600/Makefile b/src/gallium/targets/dri-r600/Makefile new file mode 100644 index 0000000..661283d --- /dev/null +++ b/src/gallium/targets/dri-r600/Makefile @@ -0,0 +1,26 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = r600_dri.so + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/drivers/r600/libr600.a \ + $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ + $(TOP)/src/gallium/winsys/r600/drm/libr600winsys.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/rbug/librbug.a + +C_SOURCES = \ + target.c \ + $(COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +DRIVER_DEFINES = \ + -DGALLIUM_RBUG -DGALLIUM_TRACE + +include ../Makefile.dri + +DRI_LIB_DEPS += + +symlinks: diff --git a/src/gallium/targets/dri-r600/SConscript b/src/gallium/targets/dri-r600/SConscript new file mode 100644 index 0000000..aa771db --- /dev/null +++ b/src/gallium/targets/dri-r600/SConscript @@ -0,0 +1,27 @@ +Import('*') + +env = drienv.Clone() + +env.ParseConfig('pkg-config --cflags --libs libdrm_radeon') + +env.Append(CPPDEFINES = ['GALLIUM_RBUG', 'GALLIUM_TRACE']) + +env.Prepend(LIBS = [ + st_dri, + r600winsys, + r600, + trace, + rbug, + mesa, + glsl, + gallium, + COMMON_DRI_DRM_OBJECTS +]) + +module = env.SharedLibrary( + target ='r600_dri.so', + source = 'target.c', + SHLIBPREFIX = '', +) + +env.Alias('dri-r600', module) diff --git a/src/gallium/targets/dri-r600/target.c b/src/gallium/targets/dri-r600/target.c new file mode 100644 index 0000000..8753e2b --- /dev/null +++ b/src/gallium/targets/dri-r600/target.c @@ -0,0 +1,24 @@ +#include "state_tracker/drm_driver.h" +#include "target-helpers/inline_debug_helper.h" +#include "r600/drm/r600_drm_public.h" +#include "r600/r600_public.h" + +static struct pipe_screen *create_screen(int fd) +{ + struct radeon *radeon; + struct pipe_screen *screen; + + radeon = r600_drm_winsys_create(fd); + if (!radeon) + return NULL; + + screen = r600_screen_create(radeon); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +} + +DRM_DRIVER_DESCRIPTOR("r600", "radeon", create_screen) diff --git a/src/gallium/targets/dri-swrast/Makefile b/src/gallium/targets/dri-swrast/Makefile new file mode 100644 index 0000000..948c45a --- /dev/null +++ b/src/gallium/targets/dri-swrast/Makefile @@ -0,0 +1,34 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = swrastg_dri.so + +DRIVER_DEFINES = \ + -D__NOT_HAVE_DRM_H -DGALLIUM_SOFTPIPE \ + -DGALLIUM_RBUG -DGALLIUM_TRACE + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/sw/libdrisw.a \ + $(TOP)/src/gallium/winsys/sw/dri/libswdri.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/rbug/librbug.a + +SWRAST_COMMON_GALLIUM_SOURCES = \ + $(TOP)/src/mesa/drivers/dri/common/utils.c \ + $(TOP)/src/mesa/drivers/dri/common/drisw_util.c \ + $(TOP)/src/mesa/drivers/dri/common/xmlconfig.c + +C_SOURCES = \ + swrast_drm_api.c \ + $(SWRAST_COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +ASM_SOURCES = + +include ../Makefile.dri + +INCLUDES += \ + -I$(TOP)/src/gallium/winsys/sw/dri + +symlinks: diff --git a/src/gallium/targets/dri-swrast/SConscript b/src/gallium/targets/dri-swrast/SConscript new file mode 100644 index 0000000..b674838 --- /dev/null +++ b/src/gallium/targets/dri-swrast/SConscript @@ -0,0 +1,42 @@ +Import('*') + +env = drienv.Clone() + +env.Append(CPPPATH = [ + '#/src/gallium/winsys/sw/dri', +]) + +env.Prepend(LIBS = [ + st_drisw, + ws_dri, + trace, + rbug, + mesa, + glsl, + gallium, + COMMON_DRI_SW_OBJECTS +]) + +if True: + env.Append(CPPDEFINES = [ + 'GALLIUM_SOFTPIPE', + 'GALLIUM_RBUG', + 'GALLIUM_TRACE', + ]) + env.Prepend(LIBS = [softpipe]) + +if env['llvm']: + env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE') + env.Prepend(LIBS = [llvmpipe]) + +swrastg_sources = [ + 'swrast_drm_api.c' +] + +module = env.LoadableModule( + target ='swrastg_dri.so', + source = swrastg_sources, + SHLIBPREFIX = '', +) + +env.Alias('dri-swrast', module) diff --git a/src/gallium/targets/dri-swrast/swrast_drm_api.c b/src/gallium/targets/dri-swrast/swrast_drm_api.c new file mode 100644 index 0000000..8d741c6 --- /dev/null +++ b/src/gallium/targets/dri-swrast/swrast_drm_api.c @@ -0,0 +1,62 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "pipe/p_compiler.h" +#include "util/u_memory.h" +#include "dri_sw_winsys.h" + +#include "target-helpers/inline_debug_helper.h" +#include "target-helpers/inline_sw_helper.h" + + +struct pipe_screen * +drisw_create_screen(struct drisw_loader_funcs *lf) +{ + struct sw_winsys *winsys = NULL; + struct pipe_screen *screen = NULL; + + winsys = dri_create_sw_winsys(lf); + if (winsys == NULL) + return NULL; + + screen = sw_screen_create(winsys); + if (!screen) + goto fail; + + screen = debug_screen_wrap(screen); + + return screen; + +fail: + if (winsys) + winsys->destroy(winsys); + + return NULL; +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/targets/dri-vmwgfx/Makefile b/src/gallium/targets/dri-vmwgfx/Makefile new file mode 100644 index 0000000..38f7893 --- /dev/null +++ b/src/gallium/targets/dri-vmwgfx/Makefile @@ -0,0 +1,23 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = vmwgfx_dri.so + +PIPE_DRIVERS = \ + $(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/rbug/librbug.a \ + $(TOP)/src/gallium/drivers/svga/libsvga.a + +C_SOURCES = \ + target.c \ + vmw_powf.c \ + $(COMMON_GALLIUM_SOURCES) + +DRIVER_DEFINES = \ + -DGALLIUM_RBUG -DGALLIUM_TRACE + +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 0000000..7888e4f --- /dev/null +++ b/src/gallium/targets/dri-vmwgfx/SConscript @@ -0,0 +1,25 @@ +Import('*') + +env = drienv.Clone() + +env.Append(CPPDEFINES = ['GALLIUM_RBUG', 'GALLIUM_TRACE']) + +env.Prepend(LIBS = [ + st_dri, + svgadrm, + svga, + trace, + rbug, + mesa, + glsl, + gallium, + COMMON_DRI_DRM_OBJECTS +]) + +module = env.LoadableModule( + target = 'vmwgfx_dri.so', + source = 'target.c', + SHLIBPREFIX = '', +) + +env.Alias('dri-vmwgfx', module) \ No newline at end of file diff --git a/src/gallium/targets/dri-vmwgfx/target.c b/src/gallium/targets/dri-vmwgfx/target.c new file mode 100644 index 0000000..15089d6 --- /dev/null +++ b/src/gallium/targets/dri-vmwgfx/target.c @@ -0,0 +1,26 @@ + +#include "target-helpers/inline_debug_helper.h" +#include "state_tracker/drm_driver.h" +#include "svga/drm/svga_drm_public.h" +#include "svga/svga_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct svga_winsys_screen *sws; + struct pipe_screen *screen; + + sws = svga_drm_winsys_screen_create(fd); + if (!sws) + return NULL; + + screen = svga_screen_create(sws); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +} + +DRM_DRIVER_DESCRIPTOR("vmwgfx", "vmwgfx", create_screen) diff --git a/src/gallium/targets/dri-vmwgfx/vmw_powf.c b/src/gallium/targets/dri-vmwgfx/vmw_powf.c new file mode 100644 index 0000000..ca5e39b --- /dev/null +++ b/src/gallium/targets/dri-vmwgfx/vmw_powf.c @@ -0,0 +1,17 @@ +/** + * Powf may leave an unresolved symbol pointing to a libstdc++.so powf. + * However, not all libstdc++.so include this function, so optionally + * replace the powf function with calls to expf and logf. + */ + +#ifdef VMW_RESOLVE_POWF + +extern float expf(float x); +extern float logf(float x); +extern float powf(float x, float y); + +float powf(float x, float y) { + return expf(logf(x)*y); +} + +#endif diff --git a/src/gallium/targets/egl-gdi/SConscript b/src/gallium/targets/egl-gdi/SConscript new file mode 100644 index 0000000..d52eeb7 --- /dev/null +++ b/src/gallium/targets/egl-gdi/SConscript @@ -0,0 +1,55 @@ +####################################################################### +# SConscript for egl-gdi target + +Import('*') + +env = env.Clone() + +env.Append(CPPPATH = [ + '#/src/gallium/state_trackers/egl', + '#/src/gallium/state_trackers/vega', + '#/src/egl/main', + '#/src/mesa', +]) + +env.Append(CPPDEFINES = [ + 'FEATURE_VG=1', + 'GALLIUM_SOFTPIPE', + 'GALLIUM_RBUG', + 'GALLIUM_TRACE', +]) + +env.Append(LIBS = [ + 'gdi32', + 'user32', + 'kernel32', + 'ws2_32', +]) + +env.Prepend(LIBS = [ + st_egl_gdi, + ws_gdi, + identity, + trace, + rbug, + softpipe, + vgapi, + st_vega, + gallium, + egl, +]) + +if env['llvm']: + env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE') + env.Prepend(LIBS = [llvmpipe]) + +egl_gallium = env.SharedLibrary( + target ='egl_gallium', + source = 'egl-static.c', +) + +env['no_import_lib'] = 1 + +egl_gdi = env.InstallSharedLibrary(egl_gallium) + +env.Alias('egl-gdi', egl_gdi) diff --git a/src/gallium/targets/egl-gdi/egl-static.c b/src/gallium/targets/egl-gdi/egl-static.c new file mode 100644 index 0000000..da6e5ce --- /dev/null +++ b/src/gallium/targets/egl-gdi/egl-static.c @@ -0,0 +1,143 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "common/egl_g3d_loader.h" +#include "state_tracker/st_gl_api.h" +#include "vg_api.h" +#include "target-helpers/inline_sw_helper.h" +#include "target-helpers/inline_debug_helper.h" +#include "egldriver.h" + +static struct st_api *stapis[ST_API_COUNT]; + +static struct st_api * +get_st_api(enum st_api_type api) +{ + struct st_api *stapi; + + stapi = stapis[api]; + if (stapi) + return stapi; + + switch (api) { +#if FEATURE_GL || FEATURE_ES1 || FEATURE_ES2 + case ST_API_OPENGL: + stapi = st_gl_api_create(); + break; +#endif +#if FEATURE_VG + case ST_API_OPENVG: + stapi = (struct st_api *) vg_api_get(); + break; +#endif + default: + break; + } + + stapis[api] = stapi; + + return stapi; +} + +static struct st_api * +guess_gl_api(enum st_profile_type profile) +{ + return get_st_api(ST_API_OPENGL); +} + +static struct pipe_screen * +create_drm_screen(const char *name, int fd) +{ + return NULL; +} + +static struct pipe_screen * +create_sw_screen(struct sw_winsys *ws) +{ + struct pipe_screen *screen; + + screen = sw_screen_create(ws); + if (screen) + screen = debug_screen_wrap(screen); + + return screen; +} + +static void +init_loader(struct egl_g3d_loader *loader) +{ +#if FEATURE_GL + loader->profile_masks[ST_API_OPENGL] |= ST_PROFILE_DEFAULT_MASK; +#endif +#if FEATURE_ES1 + loader->profile_masks[ST_API_OPENGL] |= ST_PROFILE_OPENGL_ES1_MASK; +#endif +#if FEATURE_ES2 + loader->profile_masks[ST_API_OPENGL] |= ST_PROFILE_OPENGL_ES2_MASK; +#endif +#if FEATURE_VG + loader->profile_masks[ST_API_OPENVG] |= ST_PROFILE_DEFAULT_MASK; +#endif + + loader->get_st_api = get_st_api; + loader->guess_gl_api = guess_gl_api; + loader->create_drm_screen = create_drm_screen; + loader->create_sw_screen = create_sw_screen; +} + +static void +egl_g3d_unload(_EGLDriver *drv) +{ + int i; + + egl_g3d_destroy_driver(drv); + + for (i = 0; i < ST_API_COUNT; i++) { + if (stapis[i]) { + stapis[i]->destroy(stapis[i]); + stapis[i] = NULL; + } + } +} + +static struct egl_g3d_loader loader; + +_EGLDriver * +_eglMain(const char *args) +{ + _EGLDriver *drv; + + init_loader(&loader); + drv = egl_g3d_create_driver(&loader); + if (drv) { + drv->Name = "Gallium"; + drv->Unload = egl_g3d_unload; + } + + return drv; +} diff --git a/src/gallium/targets/egl/Makefile b/src/gallium/targets/egl/Makefile new file mode 100644 index 0000000..63e9352 --- /dev/null +++ b/src/gallium/targets/egl/Makefile @@ -0,0 +1,253 @@ +# src/gallium/targets/egl/Makefile +# +# This is the Makefile for EGL Gallium driver package. The package consists of +# +# egl_gallium.so - EGL driver +# pipe_.so - pipe drivers +# st_.so - client API state trackers +# +# The following variables are examined +# +# EGL_PLATFORMS - platforms to support +# GALLIUM_WINSYS_DIRS - pipe drivers to support +# EGL_CLIENT_APIS - state trackers to support +# + +TOP = ../../../.. +include $(TOP)/configs/current + +ST_PREFIX := st_ +PIPE_PREFIX := pipe_ + +common_CPPFLAGS := \ + -I$(TOP)/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/winsys \ + $(LIBDRM_CFLAGS) + +common_SYS := +common_LIBS := \ + $(TOP)/src/gallium/drivers/identity/libidentity.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/rbug/librbug.a \ + $(GALLIUM_AUXILIARIES) + +# EGL driver +egl_CPPFLAGS := \ + -I$(TOP)/src/gallium/state_trackers/egl \ + -I$(TOP)/src/egl/main \ + -DPIPE_PREFIX=\"$(PIPE_PREFIX)\" -DST_PREFIX=\"$(ST_PREFIX)\" +egl_SYS := -lm $(DLOPEN_LIBS) -lEGL +egl_LIBS := $(TOP)/src/gallium/state_trackers/egl/libegl.a + +ifneq ($(findstring x11, $(EGL_PLATFORMS)),) +egl_SYS += -lX11 -lXext -lXfixes $(LIBDRM_LIB) +egl_LIBS += $(TOP)/src/gallium/winsys/sw/xlib/libws_xlib.a +endif +ifneq ($(findstring drm, $(EGL_PLATFORMS)),) +egl_SYS += $(LIBDRM_LIB) +endif +ifneq ($(findstring fbdev, $(EGL_PLATFORMS)),) +egl_LIBS += $(TOP)/src/gallium/winsys/sw/fbdev/libfbdev.a +endif + +# EGL_RENDERABLE_TYPE is a compile time attribute +ifneq ($(filter $(GL_LIB), $(EGL_CLIENT_APIS)),) +egl_CPPFLAGS += $(API_DEFINES) +endif +ifneq ($(filter $(GLESv1_CM_LIB), $(EGL_CLIENT_APIS)),) +egl_CPPFLAGS += -DFEATURE_ES1=1 +endif +ifneq ($(filter $(GLESv2_LIB), $(EGL_CLIENT_APIS)),) +egl_CPPFLAGS += -DFEATURE_ES2=1 +endif +ifneq ($(filter $(VG_LIB), $(EGL_CLIENT_APIS)),) +egl_CPPFLAGS += -DFEATURE_VG=1 +endif +egl_CPPFLAGS := $(sort $(egl_CPPFLAGS)) + +# i915 pipe driver +i915_CPPFLAGS := +i915_SYS := -ldrm_intel +i915_LIBS := \ + $(TOP)/src/gallium/winsys/i915/drm/libi915drm.a \ + $(TOP)/src/gallium/drivers/i915/libi915.a + +# i965 pipe driver +i965_CPPFLAGS := +i965_SYS := -ldrm_intel +i965_LIBS := \ + $(TOP)/src/gallium/winsys/i965/drm/libi965drm.a \ + $(TOP)/src/gallium/drivers/i965/libi965.a + +# nouveau pipe driver +nouveau_CPPFLAGS := +nouveau_SYS := -ldrm_nouveau +nouveau_LIBS := \ + $(TOP)/src/gallium/winsys/nouveau/drm/libnouveaudrm.a \ + $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ + $(TOP)/src/gallium/drivers/nv50/libnv50.a \ + $(TOP)/src/gallium/drivers/nouveau/libnouveau.a + +# r300 pipe driver +r300_CPPFLAGS := +r300_SYS := -ldrm -ldrm_radeon +r300_LIBS := \ + $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \ + $(TOP)/src/gallium/drivers/r300/libr300.a + +# r600 pipe driver +r600_CPPFLAGS := +r600_SYS := -ldrm -ldrm_radeon +r600_LIBS := \ + $(TOP)/src/gallium/winsys/r600/drm/libr600winsys.a \ + $(TOP)/src/gallium/drivers/r600/libr600.a + +# vmwgfx pipe driver +vmwgfx_CPPFLAGS := +vmwgfx_SYS := +vmwgfx_LIBS := \ + $(TOP)/src/gallium/winsys/svga/drm/libsvgadrm.a \ + $(TOP)/src/gallium/drivers/svga/libsvga.a + +# swrast (pseudo) pipe driver +swrast_CPPFLAGS := -DGALLIUM_SOFTPIPE -DGALLIUM_RBUG -DGALLIUM_TRACE +swrast_SYS := -lm +swrast_LIBS := $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a + +# LLVM +ifeq ($(MESA_LLVM),1) +common_SYS += $(LLVM_LIBS) +swrast_CPPFLAGS += -DGALLIUM_LLVMPIPE +swrast_LIBS += $(TOP)/src/gallium/drivers/llvmpipe/libllvmpipe.a +LDFLAGS += $(LLVM_LDFLAGS) +endif + +# OpenGL state tracker +GL_CPPFLAGS := -I$(TOP)/src/mesa $(API_DEFINES) +# do not link to $(GL_LIB) as the it supports GLES too +GL_SYS := $(DRI_LIB_DEPS) +GL_LIBS := $(TOP)/src/mesa/libmesagallium.a + +# OpenGL ES 1.x state tracker +GLESv1_CM_CPPFLAGS := -I$(TOP)/src/mesa +GLESv1_CM_SYS := $(DRI_LIB_DEPS) -l$(GLESv1_CM_LIB) +GLESv1_CM_LIBS := $(TOP)/src/mesa/libes1gallium.a + +# OpenGL ES 2.x state tracker +GLESv2_CPPFLAGS := -I$(TOP)/src/mesa +GLESv2_SYS := $(DRI_LIB_DEPS) -l$(GLESv2_LIB) +GLESv2_LIBS := $(TOP)/src/mesa/libes2gallium.a + +# OpenVG state tracker +OpenVG_CPPFLAGS := -I$(TOP)/src/gallium/state_trackers/vega +OpenVG_SYS := -lm -l$(VG_LIB) +OpenVG_LIBS := $(TOP)/src/gallium/state_trackers/vega/libvega.a + + +OUTPUT_PATH := $(TOP)/$(LIB_DIR)/egl + +# determine the outputs +ifneq ($(findstring i915/drm,$(GALLIUM_WINSYS_DIRS)),) +OUTPUTS += i915 +endif +ifneq ($(findstring i965/drm,$(GALLIUM_WINSYS_DIRS)),) +OUTPUTS += i965 +endif +ifneq ($(findstring nouveau/drm,$(GALLIUM_WINSYS_DIRS)),) +OUTPUTS += nouveau +endif +ifneq ($(findstring radeon/drm,$(GALLIUM_WINSYS_DIRS)),) +OUTPUTS += r300 +endif +ifneq ($(findstring r600/drm,$(GALLIUM_WINSYS_DIRS)),) +OUTPUTS += r600 +endif +ifneq ($(findstring svga/drm,$(GALLIUM_WINSYS_DIRS)),) +OUTPUTS += vmwgfx +endif +OUTPUTS += swrast +OUTPUTS := $(addprefix $(PIPE_PREFIX), $(OUTPUTS)) + +# EGL driver and state trackers +OUTPUTS += egl_gallium $(addprefix $(ST_PREFIX), $(EGL_CLIENT_APIS)) + +OUTPUTS := $(addsuffix .so, $(OUTPUTS)) +OUTPUTS := $(addprefix $(OUTPUT_PATH)/, $(OUTPUTS)) + +default: $(OUTPUTS) + +define mklib +$(MKLIB) -o $(notdir $@) -noprefix -linker '$(CC)' \ + -L$(TOP)/$(LIB_DIR) -ldflags '$(LDFLAGS)' \ + -install $(OUTPUT_PATH) $(MKLIB_OPTIONS) $< \ + -Wl,--start-group $(common_LIBS) $($(1)_LIBS) -Wl,--end-group \ + $(common_SYS) $($(1)_SYS) +endef + +define mklib-cxx +$(MKLIB) -o $(notdir $@) -noprefix -linker '$(CXX)' \ + -L$(TOP)/$(LIB_DIR) -ldflags '$(LDFLAGS)' \ + -cplusplus -install $(OUTPUT_PATH) $(MKLIB_OPTIONS) $< \ + -Wl,--start-group $(common_LIBS) $($(1)_LIBS) -Wl,--end-group \ + $(common_SYS) $($(1)_SYS) +endef + +# EGL driver +$(OUTPUT_PATH)/egl_gallium.so: egl.o $(egl_LIBS) + $(call mklib,egl) + +# pipe drivers +$(OUTPUT_PATH)/$(PIPE_PREFIX)i915.so: pipe_i915.o $(i915_LIBS) + $(call mklib,i915) + +$(OUTPUT_PATH)/$(PIPE_PREFIX)i965.so: pipe_i965.o $(i965_LIBS) + $(call mklib,i965) + +$(OUTPUT_PATH)/$(PIPE_PREFIX)nouveau.so: pipe_nouveau.o $(nouveau_LIBS) + $(call mklib,nouveau) + +$(OUTPUT_PATH)/$(PIPE_PREFIX)r300.so: pipe_r300.o $(r300_LIBS) + $(call mklib,r300) + +$(OUTPUT_PATH)/$(PIPE_PREFIX)r600.so: pipe_r600.o $(r600_LIBS) + $(call mklib,r600) + +$(OUTPUT_PATH)/$(PIPE_PREFIX)vmwgfx.so: pipe_vmwgfx.o $(vmwgfx_LIBS) + $(call mklib,vmwgfx) + +$(OUTPUT_PATH)/$(PIPE_PREFIX)swrast.so: pipe_swrast.o $(swrast_LIBS) + $(call mklib,swrast) + +# state trackers +$(OUTPUT_PATH)/$(ST_PREFIX)$(GL_LIB).so: st_GL.o $(GL_LIBS) + $(call mklib-cxx,GL) + +$(OUTPUT_PATH)/$(ST_PREFIX)$(GLESv1_CM_LIB).so: st_GLESv1_CM.o $(GLESv1_CM_LIBS) + $(call mklib-cxx,GLESv1_CM) + +$(OUTPUT_PATH)/$(ST_PREFIX)$(GLESv2_LIB).so: st_GLESv2.o $(GLESv2_LIBS) + $(call mklib-cxx,GLESv2) + +$(OUTPUT_PATH)/$(ST_PREFIX)$(VG_LIB).so: st_OpenVG.o $(OpenVG_LIBS) + $(call mklib,OpenVG) + +egl.o: egl.c + $(CC) -c -o $@ $< $(common_CPPFLAGS) $(egl_CPPFLAGS) $(DEFINES) $(CFLAGS) + +pipe_%.o: pipe_%.c + $(CC) -c -o $@ $< $(common_CPPFLAGS) $($*_CPPFLAGS) $(DEFINES) $(CFLAGS) + +st_%.o: st_%.c + $(CC) -c -o $@ $< $(common_CPPFLAGS) $($*_CPPFLAGS) $(DEFINES) $(CFLAGS) + +install: $(OUTPUTS) + $(INSTALL) -d $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR) + for out in $(OUTPUTS); do \ + $(MINSTALL) -m 755 "$$out" $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR); \ + done + +clean: + rm -f *.o diff --git a/src/gallium/targets/egl/egl.c b/src/gallium/targets/egl/egl.c new file mode 100644 index 0000000..786d5d1 --- /dev/null +++ b/src/gallium/targets/egl/egl.c @@ -0,0 +1,408 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "util/u_debug.h" +#include "util/u_string.h" +#include "util/u_memory.h" +#include "util/u_dl.h" +#include "egldriver.h" +#include "egllog.h" + +#include "state_tracker/st_api.h" +#include "state_tracker/drm_driver.h" +#include "common/egl_g3d_loader.h" + +#include "egl.h" + +struct egl_g3d_loader egl_g3d_loader; + +static struct st_module { + boolean initialized; + char *name; + struct util_dl_library *lib; + struct st_api *stapi; +} st_modules[ST_API_COUNT]; + +static struct pipe_module { + boolean initialized; + char *name; + struct util_dl_library *lib; + const struct drm_driver_descriptor *drmdd; + struct pipe_screen *(*swrast_create_screen)(struct sw_winsys *); +} pipe_modules[16]; + +static char * +loader_strdup(const char *s) +{ + size_t len = (s) ? strlen(s) : 0; + char *t = MALLOC(len + 1); + if (t) { + memcpy(t, s, len); + t[len] = '\0'; + } + return t; +} + +static EGLBoolean +dlopen_st_module_cb(const char *dir, size_t len, void *callback_data) +{ + struct st_module *stmod = + (struct st_module *) callback_data; + char path[1024]; + int ret; + + if (len) { + ret = util_snprintf(path, sizeof(path), + "%.*s/" ST_PREFIX "%s" UTIL_DL_EXT, len, dir, stmod->name); + } + else { + ret = util_snprintf(path, sizeof(path), + ST_PREFIX "%s" UTIL_DL_EXT, stmod->name); + } + + if (ret > 0 && ret < sizeof(path)) { + stmod->lib = util_dl_open(path); + if (stmod->lib) + _eglLog(_EGL_DEBUG, "loaded %s", path); + } + + return !(stmod->lib); +} + +static boolean +load_st_module(struct st_module *stmod, + const char *name, const char *procname) +{ + struct st_api *(*create_api)(void); + + _eglLog(_EGL_DEBUG, "searching for st module %s", name); + + stmod->name = loader_strdup(name); + if (stmod->name) + _eglSearchPathForEach(dlopen_st_module_cb, (void *) stmod); + else + stmod->lib = util_dl_open(NULL); + + if (stmod->lib) { + create_api = (struct st_api *(*)(void)) + util_dl_get_proc_address(stmod->lib, procname); + if (create_api) + stmod->stapi = create_api(); + + if (!stmod->stapi) { + util_dl_close(stmod->lib); + stmod->lib = NULL; + } + } + + if (!stmod->stapi) { + FREE(stmod->name); + stmod->name = NULL; + } + + return (stmod->stapi != NULL); +} + +static EGLBoolean +dlopen_pipe_module_cb(const char *dir, size_t len, void *callback_data) +{ + struct pipe_module *pmod = (struct pipe_module *) callback_data; + char path[1024]; + int ret; + + if (len) { + ret = util_snprintf(path, sizeof(path), + "%.*s/" PIPE_PREFIX "%s" UTIL_DL_EXT, len, dir, pmod->name); + } + else { + ret = util_snprintf(path, sizeof(path), + PIPE_PREFIX "%s" UTIL_DL_EXT, pmod->name); + } + if (ret > 0 && ret < sizeof(path)) { + pmod->lib = util_dl_open(path); + if (pmod->lib) + _eglLog(_EGL_DEBUG, "loaded %s", path); + } + + return !(pmod->lib); +} + +static boolean +load_pipe_module(struct pipe_module *pmod, const char *name) +{ + pmod->name = loader_strdup(name); + if (!pmod->name) + return FALSE; + + _eglLog(_EGL_DEBUG, "searching for pipe module %s", pmod->name); + _eglSearchPathForEach(dlopen_pipe_module_cb, (void *) pmod); + if (pmod->lib) { + pmod->drmdd = (const struct drm_driver_descriptor *) + util_dl_get_proc_address(pmod->lib, "driver_descriptor"); + + /* sanity check on the name */ + if (pmod->drmdd && strcmp(pmod->drmdd->name, pmod->name) != 0) + pmod->drmdd = NULL; + + /* swrast */ + if (pmod->drmdd && !pmod->drmdd->driver_name) { + pmod->swrast_create_screen = + (struct pipe_screen *(*)(struct sw_winsys *)) + util_dl_get_proc_address(pmod->lib, "swrast_create_screen"); + if (!pmod->swrast_create_screen) + pmod->drmdd = NULL; + } + + if (!pmod->drmdd) { + util_dl_close(pmod->lib); + pmod->lib = NULL; + } + } + + return (pmod->drmdd != NULL); +} + +static struct st_api * +get_st_api_full(enum st_api_type api, enum st_profile_type profile) +{ + struct st_module *stmod = &st_modules[api]; + const char *names[8], *symbol; + int i, count = 0; + + if (stmod->initialized) + return stmod->stapi; + + switch (api) { + case ST_API_OPENGL: + symbol = ST_CREATE_OPENGL_SYMBOL; + switch (profile) { + case ST_PROFILE_OPENGL_ES1: + names[count++] = "GLESv1_CM"; + names[count++] = "GL"; + break; + case ST_PROFILE_OPENGL_ES2: + names[count++] = "GLESv2"; + names[count++] = "GL"; + break; + default: + names[count++] = "GL"; + break; + } + break; + case ST_API_OPENVG: + symbol = ST_CREATE_OPENVG_SYMBOL; + names[count++] = "OpenVG"; + break; + default: + symbol = NULL; + assert(!"Unknown API Type\n"); + break; + } + + /* NULL means the process itself */ + names[count++] = NULL; + + for (i = 0; i < count; i++) { + if (load_st_module(stmod, names[i], symbol)) + break; + } + + if (!stmod->stapi) { + EGLint level = (egl_g3d_loader.profile_masks[api]) ? + _EGL_WARNING : _EGL_DEBUG; + _eglLog(level, "unable to load " ST_PREFIX "%s" UTIL_DL_EXT, names[0]); + } + + stmod->initialized = TRUE; + + return stmod->stapi; +} + +static struct st_api * +get_st_api(enum st_api_type api) +{ + enum st_profile_type profile = ST_PROFILE_DEFAULT; + + /* determine the profile from the linked libraries */ + if (api == ST_API_OPENGL) { + struct util_dl_library *self; + + self = util_dl_open(NULL); + if (self) { + if (util_dl_get_proc_address(self, "glColor4x")) + profile = ST_PROFILE_OPENGL_ES1; + else if (util_dl_get_proc_address(self, "glShaderBinary")) + profile = ST_PROFILE_OPENGL_ES2; + util_dl_close(self); + } + } + + return get_st_api_full(api, profile); +} + +static struct st_api * +guess_gl_api(enum st_profile_type profile) +{ + return get_st_api_full(ST_API_OPENGL, profile); +} + +static struct pipe_module * +get_pipe_module(const char *name) +{ + struct pipe_module *pmod = NULL; + int i; + + if (!name) + return NULL; + + for (i = 0; i < Elements(pipe_modules); i++) { + if (!pipe_modules[i].initialized || + strcmp(pipe_modules[i].name, name) == 0) { + pmod = &pipe_modules[i]; + break; + } + } + if (!pmod) + return NULL; + + if (!pmod->initialized) { + load_pipe_module(pmod, name); + pmod->initialized = TRUE; + } + + return pmod; +} + +static struct pipe_screen * +create_drm_screen(const char *name, int fd) +{ + struct pipe_module *pmod = get_pipe_module(name); + return (pmod && pmod->drmdd && pmod->drmdd->create_screen) ? + pmod->drmdd->create_screen(fd) : NULL; +} + +static struct pipe_screen * +create_sw_screen(struct sw_winsys *ws) +{ + struct pipe_module *pmod = get_pipe_module("swrast"); + return (pmod && pmod->swrast_create_screen) ? + pmod->swrast_create_screen(ws) : NULL; +} + +static const struct egl_g3d_loader * +loader_init(void) +{ + /* TODO detect at runtime? */ +#if FEATURE_GL + egl_g3d_loader.profile_masks[ST_API_OPENGL] |= ST_PROFILE_DEFAULT_MASK; +#endif +#if FEATURE_ES1 + egl_g3d_loader.profile_masks[ST_API_OPENGL] |= ST_PROFILE_OPENGL_ES1_MASK; +#endif +#if FEATURE_ES2 + egl_g3d_loader.profile_masks[ST_API_OPENGL] |= ST_PROFILE_OPENGL_ES2_MASK; +#endif +#if FEATURE_VG + egl_g3d_loader.profile_masks[ST_API_OPENVG] |= ST_PROFILE_DEFAULT_MASK; +#endif + + egl_g3d_loader.get_st_api = get_st_api; + egl_g3d_loader.guess_gl_api = guess_gl_api; + egl_g3d_loader.create_drm_screen = create_drm_screen; + egl_g3d_loader.create_sw_screen = create_sw_screen; + + return &egl_g3d_loader; +} + +static void +loader_fini(void) +{ + int i; + + for (i = 0; i < ST_API_COUNT; i++) { + struct st_module *stmod = &st_modules[i]; + + if (stmod->stapi) { + stmod->stapi->destroy(stmod->stapi); + stmod->stapi = NULL; + } + if (stmod->lib) { + util_dl_close(stmod->lib); + stmod->lib = NULL; + } + if (stmod->name) { + FREE(stmod->name); + stmod->name = NULL; + } + stmod->initialized = FALSE; + } + for (i = 0; i < Elements(pipe_modules); i++) { + struct pipe_module *pmod = &pipe_modules[i]; + + if (!pmod->initialized) + break; + + pmod->drmdd = NULL; + pmod->swrast_create_screen = NULL; + if (pmod->lib) { + util_dl_close(pmod->lib); + pmod->lib = NULL; + } + if (pmod->name) { + FREE(pmod->name); + pmod->name = NULL; + } + pmod->initialized = FALSE; + } +} + +static void +egl_g3d_unload(_EGLDriver *drv) +{ + egl_g3d_destroy_driver(drv); + loader_fini(); +} + +_EGLDriver * +_eglMain(const char *args) +{ + const struct egl_g3d_loader *loader; + _EGLDriver *drv; + + loader = loader_init(); + drv = egl_g3d_create_driver(loader); + if (!drv) { + loader_fini(); + return NULL; + } + + drv->Name = "Gallium"; + drv->Unload = egl_g3d_unload; + + return drv; +} diff --git a/src/gallium/targets/egl/egl.h b/src/gallium/targets/egl/egl.h new file mode 100644 index 0000000..5fd0678 --- /dev/null +++ b/src/gallium/targets/egl/egl.h @@ -0,0 +1,44 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _EGL_H_ +#define _EGL_H_ + +#include "pipe/p_compiler.h" +#include "state_tracker/st_api.h" + +#define ST_CREATE_OPENGL_SYMBOL "st_api_create_OpenGL" +#define ST_CREATE_OPENVG_SYMBOL "st_api_create_OpenVG" + +PUBLIC struct st_api * +st_api_create_OpenGL(void); + +PUBLIC struct st_api * +st_api_create_OpenVG(void); + +#endif /* _EGL_H_ */ diff --git a/src/gallium/targets/egl/pipe_i915.c b/src/gallium/targets/egl/pipe_i915.c new file mode 100644 index 0000000..cd74044 --- /dev/null +++ b/src/gallium/targets/egl/pipe_i915.c @@ -0,0 +1,27 @@ + +#include "target-helpers/inline_debug_helper.h" +#include "state_tracker/drm_driver.h" +#include "i915/drm/i915_drm_public.h" +#include "i915/i915_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct i915_winsys *iws; + struct pipe_screen *screen; + + iws = i915_drm_winsys_create(fd); + if (!iws) + return NULL; + + screen = i915_screen_create(iws); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +} + +PUBLIC +DRM_DRIVER_DESCRIPTOR("i915", "i915", create_screen) diff --git a/src/gallium/targets/egl/pipe_i965.c b/src/gallium/targets/egl/pipe_i965.c new file mode 100644 index 0000000..f810ecf --- /dev/null +++ b/src/gallium/targets/egl/pipe_i965.c @@ -0,0 +1,30 @@ + +#include "target-helpers/inline_debug_helper.h" +#include "target-helpers/inline_wrapper_sw_helper.h" +#include "state_tracker/drm_driver.h" +#include "i965/drm/i965_drm_public.h" +#include "i965/brw_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct brw_winsys_screen *bws; + struct pipe_screen *screen; + + bws = i965_drm_winsys_screen_create(fd); + if (!bws) + return NULL; + + screen = brw_screen_create(bws); + if (!screen) + return NULL; + + screen = sw_screen_wrap(screen); + + screen = debug_screen_wrap(screen); + + return screen; +} + +PUBLIC +DRM_DRIVER_DESCRIPTOR("i965", "i965", create_screen) diff --git a/src/gallium/targets/egl/pipe_nouveau.c b/src/gallium/targets/egl/pipe_nouveau.c new file mode 100644 index 0000000..0c9081b --- /dev/null +++ b/src/gallium/targets/egl/pipe_nouveau.c @@ -0,0 +1,21 @@ + +#include "target-helpers/inline_debug_helper.h" +#include "state_tracker/drm_driver.h" +#include "nouveau/drm/nouveau_drm_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct pipe_screen *screen; + + screen = nouveau_drm_screen_create(fd); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +} + +PUBLIC +DRM_DRIVER_DESCRIPTOR("nouveau", "nouveau", create_screen) diff --git a/src/gallium/targets/egl/pipe_r300.c b/src/gallium/targets/egl/pipe_r300.c new file mode 100644 index 0000000..d84bb92 --- /dev/null +++ b/src/gallium/targets/egl/pipe_r300.c @@ -0,0 +1,27 @@ + +#include "target-helpers/inline_debug_helper.h" +#include "state_tracker/drm_driver.h" +#include "radeon/drm/radeon_drm_public.h" +#include "r300/r300_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct r300_winsys_screen *sws; + struct pipe_screen *screen; + + sws = r300_drm_winsys_screen_create(fd); + if (!sws) + return NULL; + + screen = r300_screen_create(sws); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +} + +PUBLIC +DRM_DRIVER_DESCRIPTOR("r300", "radeon", create_screen) diff --git a/src/gallium/targets/egl/pipe_r600.c b/src/gallium/targets/egl/pipe_r600.c new file mode 100644 index 0000000..486a659 --- /dev/null +++ b/src/gallium/targets/egl/pipe_r600.c @@ -0,0 +1,27 @@ + +#include "state_tracker/drm_driver.h" +#include "target-helpers/inline_debug_helper.h" +#include "r600/drm/r600_drm_public.h" +#include "r600/r600_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct radeon *rw; + struct pipe_screen *screen; + + rw = r600_drm_winsys_create(fd); + if (!rw) + return NULL; + + screen = r600_screen_create(rw); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +} + +PUBLIC +DRM_DRIVER_DESCRIPTOR("r600", "radeon", create_screen) diff --git a/src/gallium/targets/egl/pipe_swrast.c b/src/gallium/targets/egl/pipe_swrast.c new file mode 100644 index 0000000..b2e3289 --- /dev/null +++ b/src/gallium/targets/egl/pipe_swrast.c @@ -0,0 +1,22 @@ + +#include "target-helpers/inline_sw_helper.h" +#include "target-helpers/inline_debug_helper.h" +#include "state_tracker/drm_driver.h" + +PUBLIC struct pipe_screen * +swrast_create_screen(struct sw_winsys *ws); + +PUBLIC +DRM_DRIVER_DESCRIPTOR("swrast", NULL, NULL) + +struct pipe_screen * +swrast_create_screen(struct sw_winsys *ws) +{ + struct pipe_screen *screen; + + screen = sw_screen_create(ws); + if (screen) + screen = debug_screen_wrap(screen); + + return screen; +} diff --git a/src/gallium/targets/egl/pipe_vmwgfx.c b/src/gallium/targets/egl/pipe_vmwgfx.c new file mode 100644 index 0000000..22a28fa --- /dev/null +++ b/src/gallium/targets/egl/pipe_vmwgfx.c @@ -0,0 +1,27 @@ + +#include "target-helpers/inline_debug_helper.h" +#include "state_tracker/drm_driver.h" +#include "svga/drm/svga_drm_public.h" +#include "svga/svga_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct svga_winsys_screen *sws; + struct pipe_screen *screen; + + sws = svga_drm_winsys_screen_create(fd); + if (!sws) + return NULL; + + screen = svga_screen_create(sws); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +} + +PUBLIC +DRM_DRIVER_DESCRIPTOR("vmwgfx", "vmwgfx", create_screen) diff --git a/src/gallium/targets/egl/st_GL.c b/src/gallium/targets/egl/st_GL.c new file mode 100644 index 0000000..c1df844 --- /dev/null +++ b/src/gallium/targets/egl/st_GL.c @@ -0,0 +1,8 @@ +#include "state_tracker/st_gl_api.h" +#include "egl.h" + +PUBLIC struct st_api * +st_api_create_OpenGL(void) +{ + return st_gl_api_create(); +} diff --git a/src/gallium/targets/egl/st_GLESv1_CM.c b/src/gallium/targets/egl/st_GLESv1_CM.c new file mode 100644 index 0000000..c1df844 --- /dev/null +++ b/src/gallium/targets/egl/st_GLESv1_CM.c @@ -0,0 +1,8 @@ +#include "state_tracker/st_gl_api.h" +#include "egl.h" + +PUBLIC struct st_api * +st_api_create_OpenGL(void) +{ + return st_gl_api_create(); +} diff --git a/src/gallium/targets/egl/st_GLESv2.c b/src/gallium/targets/egl/st_GLESv2.c new file mode 100644 index 0000000..c1df844 --- /dev/null +++ b/src/gallium/targets/egl/st_GLESv2.c @@ -0,0 +1,8 @@ +#include "state_tracker/st_gl_api.h" +#include "egl.h" + +PUBLIC struct st_api * +st_api_create_OpenGL(void) +{ + return st_gl_api_create(); +} diff --git a/src/gallium/targets/egl/st_OpenVG.c b/src/gallium/targets/egl/st_OpenVG.c new file mode 100644 index 0000000..d0bf4db --- /dev/null +++ b/src/gallium/targets/egl/st_OpenVG.c @@ -0,0 +1,8 @@ +#include "vg_api.h" +#include "egl.h" + +PUBLIC struct st_api * +st_api_create_OpenVG(void) +{ + return (struct st_api *) vg_api_get(); +} diff --git a/src/gallium/targets/graw-gdi/SConscript b/src/gallium/targets/graw-gdi/SConscript new file mode 100644 index 0000000..352efe9 --- /dev/null +++ b/src/gallium/targets/graw-gdi/SConscript @@ -0,0 +1,43 @@ +####################################################################### +# SConscript for graw-gdi + +Import('*') + +env = env.Clone() + +env.Append(CPPPATH = [ + '#src/gallium/winsys/sw', +]) + +env.Prepend(LIBS = [ + gallium, + 'gdi32', + 'user32', + 'ws2_32', +]) + +sources = [ + 'graw_gdi.c', + graw_util, +] + +if True: + env.Append(CPPDEFINES = ['GALLIUM_TRACE', 'GALLIUM_RBUG', 'GALLIUM_GALAHAD', 'GALLIUM_SOFTPIPE']) + env.Prepend(LIBS = [trace, rbug, galahad, softpipe]) + +if env['llvm']: + env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE') + env.Prepend(LIBS = [llvmpipe]) + +graw = env.SharedLibrary( + target = 'graw', + source = sources, + LIBS = ws_gdi + env['LIBS'], +) + +if env['platform'] == 'windows': + graw = env.FindIxes(graw, 'LIBPREFIX', 'LIBSUFFIX') +else: + graw = env.FindIxes(graw, 'SHLIBPREFIX', 'SHLIBSUFFIX') + +env.Alias('graw-gdi', graw) diff --git a/src/gallium/targets/graw-gdi/graw_gdi.c b/src/gallium/targets/graw-gdi/graw_gdi.c new file mode 100644 index 0000000..17ca2a7 --- /dev/null +++ b/src/gallium/targets/graw-gdi/graw_gdi.c @@ -0,0 +1,157 @@ +/************************************************************************** + * + * 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. + * + * + **************************************************************************/ + +#include "gdi/gdi_sw_winsys.h" +#include "pipe/p_screen.h" +#include "state_tracker/graw.h" +#include "target-helpers/inline_debug_helper.h" +#include "target-helpers/inline_sw_helper.h" +#include + + +static LRESULT CALLBACK +window_proc(HWND hWnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam) +{ + switch (uMsg) { + case WM_DESTROY: + PostQuitMessage(0); + break; + + default: + return DefWindowProc(hWnd, uMsg, wParam, lParam); + } + + return 0; +} + +static struct { + void (* draw)(void); +} graw; + +struct pipe_screen * +graw_create_window_and_screen(int x, + int y, + unsigned width, + unsigned height, + enum pipe_format format, + void **handle) +{ + struct sw_winsys *winsys = NULL; + struct pipe_screen *screen = NULL; + WNDCLASSEX wc = {sizeof(wc)}; + UINT style = WS_VISIBLE | WS_TILEDWINDOW; + RECT rect; + HWND hWnd = NULL; + HDC hDC = NULL; + + if (format != PIPE_FORMAT_R8G8B8A8_UNORM) + goto fail; + + winsys = gdi_create_sw_winsys(); + if (winsys == NULL) + goto fail; + + screen = sw_screen_create(winsys); + if (screen == NULL) + goto fail; + + wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = window_proc; + wc.lpszClassName = "graw-gdi"; + wc.hInstance = GetModuleHandle(NULL); + wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); + RegisterClassEx(&wc); + + SetRect(&rect, 0, 0, width, height); + AdjustWindowRectEx(&rect, style, FALSE, 0); + + hWnd = CreateWindowEx(0, + wc.lpszClassName, + wc.lpszClassName, + style, + x, + y, + rect.right - rect.left, + rect.bottom - rect.top, + NULL, + NULL, + wc.hInstance, + 0); + if (hWnd == NULL) + goto fail; + + hDC = GetDC(hWnd); + if (hDC == NULL) + goto fail; + + *handle = (void *)hDC; + + return debug_screen_wrap(screen); + +fail: + if (hWnd) + DestroyWindow(hWnd); + + if (screen) + screen->destroy(screen); + + return NULL; +} + +void +graw_set_display_func(void (* draw)(void)) +{ + graw.draw = draw; +} + +void +graw_main_loop(void) +{ + for (;;) { + MSG msg; + + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + if (msg.message == WM_QUIT) { + return; + } + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + if (graw.draw) { + graw.draw(); + } + + Sleep(0); + } +} diff --git a/src/gallium/targets/graw-null/SConscript b/src/gallium/targets/graw-null/SConscript new file mode 100644 index 0000000..ebac172 --- /dev/null +++ b/src/gallium/targets/graw-null/SConscript @@ -0,0 +1,32 @@ +####################################################################### +# SConscript for xlib winsys + +Import('*') + +env = env.Clone() + +graw_util = env.SharedObject( + source = ['graw_util.c'], +) + +env = env.Clone() + +sources = [ + 'graw_null.c', + graw_util, +] + +env.Prepend(LIBS = [gallium]) + +# TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions +graw = env.SharedLibrary( + target = 'graw', + source = sources, +) + +if env['platform'] == 'windows': + graw = env.FindIxes(graw, 'LIBPREFIX', 'LIBSUFFIX') +else: + graw = env.FindIxes(graw, 'SHLIBPREFIX', 'SHLIBSUFFIX') + +Export('graw_util', 'graw') diff --git a/src/gallium/targets/graw-null/graw_null.c b/src/gallium/targets/graw-null/graw_null.c new file mode 100644 index 0000000..f1fe387 --- /dev/null +++ b/src/gallium/targets/graw-null/graw_null.c @@ -0,0 +1,28 @@ +#include "state_tracker/graw.h" + + + + +struct pipe_screen * +graw_create_window_and_screen( int x, + int y, + unsigned width, + unsigned height, + enum pipe_format format, + void **handle) +{ + return NULL; +} + + + +void +graw_set_display_func( void (*draw)( void ) ) +{ +} + + +void +graw_main_loop( void ) +{ +} diff --git a/src/gallium/targets/graw-null/graw_util.c b/src/gallium/targets/graw-null/graw_util.c new file mode 100644 index 0000000..e5cf526 --- /dev/null +++ b/src/gallium/targets/graw-null/graw_util.c @@ -0,0 +1,92 @@ + +#include "pipe/p_compiler.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "tgsi/tgsi_text.h" +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "state_tracker/graw.h" + + +/* Helper functions. These are the same for all graw implementations. + */ +PUBLIC void * +graw_parse_geometry_shader(struct pipe_context *pipe, + const char *text) +{ + struct tgsi_token tokens[1024]; + struct pipe_shader_state state; + + if (!tgsi_text_translate(text, tokens, Elements(tokens))) + return NULL; + + state.tokens = tokens; + return pipe->create_gs_state(pipe, &state); +} + +PUBLIC void * +graw_parse_vertex_shader(struct pipe_context *pipe, + const char *text) +{ + struct tgsi_token tokens[1024]; + struct pipe_shader_state state; + + if (!tgsi_text_translate(text, tokens, Elements(tokens))) + return NULL; + + state.tokens = tokens; + return pipe->create_vs_state(pipe, &state); +} + +PUBLIC void * +graw_parse_fragment_shader(struct pipe_context *pipe, + const char *text) +{ + struct tgsi_token tokens[1024]; + struct pipe_shader_state state; + + if (!tgsi_text_translate(text, tokens, Elements(tokens))) + return NULL; + + state.tokens = tokens; + return pipe->create_fs_state(pipe, &state); +} + +static char out_filename[256] = ""; + +PUBLIC boolean +graw_parse_args(int *argi, + int argc, + char *argv[]) +{ + if (strcmp(argv[*argi], "-o") == 0) { + if (*argi + 1 >= argc) { + return FALSE; + } + + strncpy(out_filename, argv[*argi + 1], sizeof(out_filename) - 1); + out_filename[sizeof(out_filename) - 1] = '\0'; + *argi += 2; + return TRUE; + } + + return FALSE; +} + +PUBLIC boolean +graw_save_surface_to_file(struct pipe_context *pipe, + struct pipe_surface *surface, + const char *filename) +{ + if (!filename || !*filename) { + filename = out_filename; + if (!filename || !*filename) { + return FALSE; + } + } + + /* XXX: Make that working in release builds. + */ + debug_dump_surface_bmp(pipe, filename, surface); + return TRUE; +} diff --git a/src/gallium/targets/graw-xlib/SConscript b/src/gallium/targets/graw-xlib/SConscript new file mode 100644 index 0000000..42cb349 --- /dev/null +++ b/src/gallium/targets/graw-xlib/SConscript @@ -0,0 +1,42 @@ +####################################################################### +# SConscript for xlib winsys + +Import('*') + +env = env.Clone() + +env.Prepend(LIBS = [ + ws_xlib, + gallium, +]) + +env.Prepend(LIBS = env['X11_LIBS']) + +env.Append(CPPPATH = [ + '#src/gallium/drivers', + '#src/gallium/include/state_tracker', +]) + +env.Append(CPPDEFINES = ['GALLIUM_RBUG', 'GALLIUM_TRACE', 'GALLIUM_GALAHAD']) + +sources = [ + 'graw_xlib.c', + graw_util +] + +if True: + env.Append(CPPDEFINES = ['GALLIUM_TRACE', 'GALLIUM_RBUG', 'GALLIUM_GALAHAD', 'GALLIUM_SOFTPIPE']) + env.Prepend(LIBS = [trace, rbug, galahad, softpipe]) + +if env['llvm']: + env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE') + env.Prepend(LIBS = [llvmpipe]) + +graw = env.SharedLibrary( + target ='graw', + source = sources, +) + +graw = env.InstallSharedLibrary(graw, version=(1, 0)) + +env.Alias('graw-xlib', graw) diff --git a/src/gallium/targets/graw-xlib/graw_xlib.c b/src/gallium/targets/graw-xlib/graw_xlib.c new file mode 100644 index 0000000..578086f --- /dev/null +++ b/src/gallium/targets/graw-xlib/graw_xlib.c @@ -0,0 +1,171 @@ +#include "pipe/p_compiler.h" +#include "pipe/p_context.h" +#include "pipe/p_screen.h" +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "target-helpers/inline_sw_helper.h" +#include "target-helpers/inline_debug_helper.h" +#include "state_tracker/xlib_sw_winsys.h" +#include "state_tracker/graw.h" + +#include +#include +#include +#include + +static struct { + Display *display; + void (*draw)(void); +} graw; + + +static struct pipe_screen * +graw_create_screen( void ) +{ + struct pipe_screen *screen = NULL; + struct sw_winsys *winsys = NULL; + + /* Create the underlying winsys, which performs presents to Xlib + * drawables: + */ + winsys = xlib_create_sw_winsys( graw.display ); + if (winsys == NULL) + return NULL; + + screen = sw_screen_create( winsys ); + + /* Inject any wrapping layers we want to here: + */ + return debug_screen_wrap( screen ); +} + + +struct pipe_screen * +graw_create_window_and_screen( int x, + int y, + unsigned width, + unsigned height, + enum pipe_format format, + void **handle) +{ + struct pipe_screen *screen = NULL; + struct xlib_drawable *xlib_handle = NULL; + XSetWindowAttributes attr; + Window root; + Window win = 0; + XVisualInfo templat, *visinfo = NULL; + unsigned mask; + int n; + int scrnum; + + graw.display = XOpenDisplay(NULL); + if (graw.display == NULL) + return NULL; + + scrnum = DefaultScreen( graw.display ); + root = RootWindow( graw.display, scrnum ); + + + if (format != PIPE_FORMAT_R8G8B8A8_UNORM) + goto fail; + + if (graw.display == NULL) + goto fail; + + xlib_handle = CALLOC_STRUCT(xlib_drawable); + if (xlib_handle == NULL) + goto fail; + + + mask = VisualScreenMask | VisualDepthMask | VisualClassMask; + templat.screen = DefaultScreen(graw.display); + templat.depth = 32; + templat.class = TrueColor; + + visinfo = XGetVisualInfo(graw.display, mask, &templat, &n); + if (!visinfo) { + printf("Error: couldn't get an RGB, Double-buffered visual\n"); + exit(1); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap( graw.display, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + /* XXX this is a bad way to get a borderless window! */ + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( graw.display, root, x, y, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr ); + + + /* set hints and properties */ + { + char *name = NULL; + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(graw.display, win, &sizehints); + XSetStandardProperties(graw.display, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + XMapWindow(graw.display, win); + while (1) { + XEvent e; + XNextEvent( graw.display, &e ); + if (e.type == MapNotify && e.xmap.window == win) { + break; + } + } + + xlib_handle->visual = visinfo->visual; + xlib_handle->drawable = (Drawable)win; + xlib_handle->depth = visinfo->depth; + *handle = (void *)xlib_handle; + + screen = graw_create_screen(); + if (screen == NULL) + goto fail; + + XFree(visinfo); + return screen; + +fail: + if (screen) + screen->destroy(screen); + + if (xlib_handle) + FREE(xlib_handle); + + if (visinfo) + XFree(visinfo); + + if (win) + XDestroyWindow(graw.display, win); + + return NULL; +} + + +void +graw_set_display_func( void (*draw)( void ) ) +{ + graw.draw = draw; +} + +void +graw_main_loop( void ) +{ + int i; + for (i = 0; i < 10; i++) { + graw.draw(); + sleep(1); + } +} + diff --git a/src/gallium/targets/libgl-gdi/SConscript b/src/gallium/targets/libgl-gdi/SConscript new file mode 100644 index 0000000..ec7dbad --- /dev/null +++ b/src/gallium/targets/libgl-gdi/SConscript @@ -0,0 +1,46 @@ +####################################################################### +# SConscript for gdi winsys + +Import('*') + +env = env.Clone() + +env.Append(CPPPATH = [ + '#src/gallium/state_trackers/wgl', + '#src/gallium/winsys/sw', +]) + +env.Append(LIBS = [ + 'gdi32', + 'user32', + 'kernel32', + 'ws2_32', +]) + +sources = ['libgl_gdi.c'] +drivers = [] + +if True: + drivers += [softpipe] + +if env['llvm']: + env.Append(CPPDEFINES = 'HAVE_LLVMPIPE') + drivers += [llvmpipe] + +if env['gcc']: + sources += ['#src/gallium/state_trackers/wgl/opengl32.mingw.def'] +else: + sources += ['#src/gallium/state_trackers/wgl/opengl32.def'] + +drivers += [trace, rbug] + +env['no_import_lib'] = 1 + +opengl32 = env.SharedLibrary( + target ='opengl32', + source = sources, + LIBS = wgl + ws_gdi + glapi + mesa + drivers + gallium + glsl + env['LIBS'], +) + +env.Alias('opengl32', opengl32) +env.Alias('libgl-gdi', opengl32) diff --git a/src/gallium/targets/libgl-gdi/libgl_gdi.c b/src/gallium/targets/libgl-gdi/libgl_gdi.c new file mode 100644 index 0000000..112904a --- /dev/null +++ b/src/gallium/targets/libgl-gdi/libgl_gdi.c @@ -0,0 +1,167 @@ +/************************************************************************** + * + * Copyright 2009-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 + * Softpipe/LLVMpipe support. + * + * @author Jose Fonseca + */ + + +#include + +#include "util/u_debug.h" +#include "stw_winsys.h" +#include "gdi/gdi_sw_winsys.h" + +#include "softpipe/sp_texture.h" +#include "softpipe/sp_screen.h" +#include "softpipe/sp_public.h" + +#ifdef HAVE_LLVMPIPE +#include "llvmpipe/lp_texture.h" +#include "llvmpipe/lp_screen.h" +#include "llvmpipe/lp_public.h" +#endif + + +static boolean use_llvmpipe = FALSE; + + +static struct pipe_screen * +gdi_screen_create(void) +{ + const char *default_driver; + const char *driver; + struct pipe_screen *screen = NULL; + struct sw_winsys *winsys; + + winsys = gdi_create_sw_winsys(); + if(!winsys) + goto no_winsys; + +#ifdef HAVE_LLVMPIPE + default_driver = "llvmpipe"; +#else + default_driver = "softpipe"; +#endif + + driver = debug_get_option("GALLIUM_DRIVER", default_driver); + +#ifdef HAVE_LLVMPIPE + if (strcmp(driver, "llvmpipe") == 0) { + screen = llvmpipe_create_screen( winsys ); + } +#endif + + if (screen == NULL) { + screen = softpipe_create_screen( winsys ); + } else { + use_llvmpipe = TRUE; + } + + if(!screen) + goto no_screen; + + return screen; + +no_screen: + winsys->destroy(winsys); +no_winsys: + return NULL; +} + + +static void +gdi_present(struct pipe_screen *screen, + struct pipe_resource *res, + HDC hDC) +{ + /* This will fail if any interposing layer (trace, debug, etc) has + * been introduced between the state-trackers and the pipe driver. + * + * Ideally this would get replaced with a call to + * pipe_screen::flush_frontbuffer(). + * + * Failing that, it may be necessary for intervening layers to wrap + * other structs such as this stw_winsys as well... + */ + + struct sw_winsys *winsys = NULL; + struct sw_displaytarget *dt = NULL; + +#ifdef HAVE_LLVMPIPE + if (use_llvmpipe) { + winsys = llvmpipe_screen(screen)->winsys; + dt = llvmpipe_resource(res)->dt; + gdi_sw_display(winsys, dt, hDC); + return; + } +#endif + + winsys = softpipe_screen(screen)->winsys, + dt = softpipe_resource(res)->dt, + gdi_sw_display(winsys, dt, hDC); +} + + +static const struct stw_winsys stw_winsys = { + &gdi_screen_create, + &gdi_present, + NULL, /* get_adapter_luid */ + NULL, /* shared_surface_open */ + NULL, /* shared_surface_close */ + NULL /* compose */ +}; + + +BOOL WINAPI +DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) +{ + switch (fdwReason) { + case DLL_PROCESS_ATTACH: + stw_init(&stw_winsys); + stw_init_thread(); + break; + + case DLL_THREAD_ATTACH: + stw_init_thread(); + break; + + case DLL_THREAD_DETACH: + stw_cleanup_thread(); + break; + + case DLL_PROCESS_DETACH: + stw_cleanup_thread(); + stw_cleanup(); + break; + } + return TRUE; +} diff --git a/src/gallium/targets/libgl-xlib/Makefile b/src/gallium/targets/libgl-xlib/Makefile new file mode 100644 index 0000000..fb537c3 --- /dev/null +++ b/src/gallium/targets/libgl-xlib/Makefile @@ -0,0 +1,115 @@ +# src/gallium/targets/libgl-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)$(MESA_MINOR)0$(MESA_TINY) + + +INCLUDE_DIRS = \ + -I$(TOP)/include \ + -I$(TOP)/src/mapi \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/mesa/main \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/state_trackers/glx/xlib \ + -I$(TOP)/src/gallium/auxiliary \ + $(X11_CFLAGS) + +DEFINES += \ + -DGALLIUM_SOFTPIPE \ + -DGALLIUM_RBUG \ + -DGALLIUM_TRACE \ + -DGALLIUM_GALAHAD +#-DGALLIUM_CELL will be defined by the config */ + +XLIB_TARGET_SOURCES = \ + xlib.c + + +XLIB_TARGET_OBJECTS = $(XLIB_TARGET_SOURCES:.c=.o) + + +# Note: CELL_SPU_LIB is only defined for cell configs + +LIBS = \ + $(GALLIUM_DRIVERS) \ + $(TOP)/src/gallium/state_trackers/glx/xlib/libxlib.a \ + $(TOP)/src/gallium/winsys/sw/xlib/libws_xlib.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/rbug/librbug.a \ + $(TOP)/src/gallium/drivers/galahad/libgalahad.a \ + $(TOP)/src/mapi/glapi/libglapi.a \ + $(TOP)/src/mesa/libmesagallium.a \ + $(GALLIUM_AUXILIARIES) \ + $(CELL_SPU_LIB) \ + + +# LLVM +ifeq ($(MESA_LLVM),1) +DEFINES += -DGALLIUM_LLVMPIPE +GL_LIB_DEPS += $(LLVM_LIBS) +LDFLAGS += $(LLVM_LDFLAGS) +endif + + +.SUFFIXES : .cpp + +.c.o: + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + +.cpp.o: + $(CXX) -c $(INCLUDE_DIRS) $(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_TARGET_OBJECTS) $(LIBS) Makefile + $(TOP)/bin/mklib -o $(GL_LIB) \ + -linker "$(CXX)" -ldflags '$(LDFLAGS)' \ + -major $(GL_MAJOR) -minor $(GL_MINOR) -patch $(GL_TINY) \ + -cplusplus \ + -install $(TOP)/$(LIB_DIR)/gallium \ + $(MKLIB_OPTIONS) $(XLIB_TARGET_OBJECTS) \ + -Wl,--start-group $(LIBS) -Wl,--end-group $(GL_LIB_DEPS) + + +depend: $(XLIB_TARGET_SOURCES) + @ echo "running $(MKDEP)" + @ rm -f depend # workaround oops on gutsy?!? + @ touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) $(XLIB_TARGET_SOURCES) \ + > /dev/null 2>/dev/null + + +install: default + $(INSTALL) -d $(DESTDIR)$(INSTALL_DIR)/include/GL + $(INSTALL) -d $(DESTDIR)$(INSTALL_DIR)/$(LIB_DIR) + $(INSTALL) -m 644 $(TOP)/include/GL/*.h $(DESTDIR)$(INSTALL_DIR)/include/GL + @if [ -e $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) ]; then \ + $(MINSTALL) $(TOP)/$(LIB_DIR)/libGL* $(DESTDIR)$(INSTALL_DIR)/$(LIB_DIR); \ + fi + + +# Emacs tags +tags: + etags `find . -name \*.[ch]` $(TOP)/include/GL/*.h + +clean: + -rm -f *.o depend + + +include depend diff --git a/src/gallium/targets/libgl-xlib/SConscript b/src/gallium/targets/libgl-xlib/SConscript new file mode 100644 index 0000000..7f0f245 --- /dev/null +++ b/src/gallium/targets/libgl-xlib/SConscript @@ -0,0 +1,55 @@ +####################################################################### +# SConscript for xlib winsys + +Import('*') + +env = env.Clone() + +env.Append(CPPPATH = [ + '#/src/mapi', + '#/src/mesa', + '#/src/mesa/main', + '#src/gallium/state_trackers/glx/xlib', +]) + +env.Append(CPPDEFINES = ['USE_XSHM']) + +env.Prepend(LIBS = env['X11_LIBS']) + +env.Prepend(LIBS = [ + st_xlib, + ws_xlib, + glapi, + mesa, + glsl, + gallium, +]) + +sources = [ + 'xlib.c', +] + +if True: + env.Append(CPPDEFINES = ['GALLIUM_TRACE', 'GALLIUM_RBUG', 'GALLIUM_GALAHAD', 'GALLIUM_SOFTPIPE']) + env.Prepend(LIBS = [trace, rbug, galahad, softpipe]) + +if env['llvm']: + env.Append(CPPDEFINES = ['GALLIUM_LLVMPIPE']) + env.Prepend(LIBS = [llvmpipe]) + +if False: + # TODO: Detect Cell SDK + env.Append(CPPDEFINES = 'GALLIUM_CELL') + env.Prepend(LIBS = [cell]) + +# TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions +libgl = env.SharedLibrary( + target ='GL', + source = sources, +) + +if True: + # XXX: Only install this libGL.so if DRI not enabled + libgl = env.InstallSharedLibrary(libgl, version=(1, 5)) + +env.Alias('libgl-xlib', libgl) diff --git a/src/gallium/targets/libgl-xlib/xlib.c b/src/gallium/targets/libgl-xlib/xlib.c new file mode 100644 index 0000000..9a3e0e0 --- /dev/null +++ b/src/gallium/targets/libgl-xlib/xlib.c @@ -0,0 +1,138 @@ +/************************************************************************** + * + * 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 + */ +#include "pipe/p_compiler.h" +#include "util/u_debug.h" +#include "state_tracker/xlib_sw_winsys.h" +#include "xm_public.h" + +#include "state_tracker/st_api.h" +#include "state_tracker/st_gl_api.h" +#include "target-helpers/inline_sw_helper.h" +#include "target-helpers/inline_debug_helper.h" + + + +/* Helper function to build a subset of a driver stack consisting of + * one of the software rasterizers (cell, llvmpipe, softpipe) and the + * xlib winsys. + */ +static struct pipe_screen * +swrast_xlib_create_screen( Display *display ) +{ + struct sw_winsys *winsys; + struct pipe_screen *screen = NULL; + + /* Create the underlying winsys, which performs presents to Xlib + * drawables: + */ + winsys = xlib_create_sw_winsys( display ); + if (winsys == NULL) + return NULL; + + /* Create a software rasterizer on top of that winsys: + */ + screen = sw_screen_create( winsys ); + if (screen == NULL) + goto fail; + + /* Inject any wrapping layers we want to here: + */ + return debug_screen_wrap( screen ); + +fail: + if (winsys) + winsys->destroy( winsys ); + + return NULL; +} + +static struct xm_driver xlib_driver = +{ + .create_pipe_screen = swrast_xlib_create_screen, + .create_st_api = st_gl_api_create, +}; + + +/* Build the rendering stack. + */ +static void _init( void ) __attribute__((constructor)); +static void _init( void ) +{ + /* Initialize the xlib libgl code, pass in the winsys: + */ + xmesa_set_driver( &xlib_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); +} + + +/** + * When GLX_INDIRECT_RENDERING is defined, some symbols are missing in + * libglapi.a. We need to define them here. + */ +#ifdef GLX_INDIRECT_RENDERING + +#define GL_GLEXT_PROTOTYPES +#include "GL/gl.h" +#include "glapi/glapi.h" +#include "glapi/glapitable.h" + +#if defined(USE_MGL_NAMESPACE) +#define NAME(func) mgl##func +#else +#define NAME(func) gl##func +#endif + +#define DISPATCH(FUNC, ARGS, MESSAGE) \ + GET_DISPATCH()->FUNC ARGS + +#define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \ + return GET_DISPATCH()->FUNC ARGS + +/* skip normal ones */ +#define _GLAPI_SKIP_NORMAL_ENTRY_POINTS +#include "glapi/glapitemp.h" + +#endif /* GLX_INDIRECT_RENDERING */ diff --git a/src/gallium/targets/xorg-i915/Makefile b/src/gallium/targets/xorg-i915/Makefile new file mode 100644 index 0000000..8652404 --- /dev/null +++ b/src/gallium/targets/xorg-i915/Makefile @@ -0,0 +1,24 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = modesetting_drv.so + +C_SOURCES = \ + intel_target.c \ + intel_xorg.c + +DRIVER_DEFINES = \ + -DHAVE_CONFIG_H -DGALLIUM_RBUG -DGALLIUM_TRACE -DGALLIUM_GALAHAD + +DRIVER_PIPES = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ + $(TOP)/src/gallium/winsys/i915/drm/libi915drm.a \ + $(TOP)/src/gallium/drivers/i915/libi915.a \ + $(TOP)/src/gallium/drivers/galahad/libgalahad.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/rbug/librbug.a + +DRIVER_LINKS = \ + $(shell pkg-config --libs libdrm libdrm_intel) + +include ../Makefile.xorg diff --git a/src/gallium/targets/xorg-i915/intel_target.c b/src/gallium/targets/xorg-i915/intel_target.c new file mode 100644 index 0000000..8c8ef7e --- /dev/null +++ b/src/gallium/targets/xorg-i915/intel_target.c @@ -0,0 +1,26 @@ + +#include "state_tracker/drm_driver.h" +#include "target-helpers/inline_debug_helper.h" +#include "i915/drm/i915_drm_public.h" +#include "i915/i915_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct i915_winsys *iws; + struct pipe_screen *screen; + + iws = i915_drm_winsys_create(fd); + if (!iws) + return NULL; + + screen = i915_screen_create(iws); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +} + +DRM_DRIVER_DESCRIPTOR("i915", "i915", create_screen) 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 0000000..08f3b08 --- /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 0000000..494dce4 --- /dev/null +++ b/src/gallium/targets/xorg-i965/Makefile @@ -0,0 +1,26 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = i965g_drv.so + +C_SOURCES = \ + intel_target.c \ + intel_xorg.c + +DRIVER_DEFINES = \ + -DHAVE_CONFIG_H -DGALLIUM_SOFTPIPE \ + -DGALLIUM_RBUG -DGALLIUM_TRACE + +DRIVER_PIPES = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.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/rbug/librbug.a \ + $(TOP)/src/gallium/winsys/sw/wrapper/libwsw.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a + +DRIVER_LINKS = \ + $(shell pkg-config --libs libdrm libdrm_intel) + +include ../Makefile.xorg diff --git a/src/gallium/targets/xorg-i965/intel_target.c b/src/gallium/targets/xorg-i965/intel_target.c new file mode 100644 index 0000000..0632b97 --- /dev/null +++ b/src/gallium/targets/xorg-i965/intel_target.c @@ -0,0 +1,29 @@ + +#include "target-helpers/inline_wrapper_sw_helper.h" +#include "target-helpers/inline_debug_helper.h" +#include "state_tracker/drm_driver.h" +#include "i965/drm/i965_drm_public.h" +#include "i965/brw_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct brw_winsys_screen *bws; + struct pipe_screen *screen; + + bws = i965_drm_winsys_screen_create(fd); + if (!bws) + return NULL; + + screen = brw_screen_create(bws); + if (!screen) + return NULL; + + screen = sw_screen_wrap(screen); + + screen = debug_screen_wrap(screen); + + return screen; +} + +DRM_DRIVER_DESCRIPTOR("i915", "i965", create_screen) 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 0000000..f4608f0 --- /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 0000000..2fcd9ff --- /dev/null +++ b/src/gallium/targets/xorg-nouveau/Makefile @@ -0,0 +1,25 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = modesetting_drv.so + +C_SOURCES = \ + nouveau_target.c \ + nouveau_xorg.c + +DRIVER_DEFINES = \ + -DHAVE_CONFIG_H -DGALLIUM_RBUG -DGALLIUM_TRACE + +DRIVER_PIPES = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.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 \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/rbug/librbug.a + +DRIVER_LINKS = \ + $(shell pkg-config --libs libdrm libdrm_nouveau) + +include ../Makefile.xorg diff --git a/src/gallium/targets/xorg-nouveau/nouveau_target.c b/src/gallium/targets/xorg-nouveau/nouveau_target.c new file mode 100644 index 0000000..e725a4d --- /dev/null +++ b/src/gallium/targets/xorg-nouveau/nouveau_target.c @@ -0,0 +1,20 @@ + +#include "target-helpers/inline_debug_helper.h" +#include "state_tracker/drm_driver.h" +#include "nouveau/drm/nouveau_drm_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct pipe_screen *screen; + + screen = nouveau_drm_screen_create(fd); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +} + +DRM_DRIVER_DESCRIPTOR("nouveau", "nouveau", create_screen) 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 0000000..699af09 --- /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 0000000..d3bc356 --- /dev/null +++ b/src/gallium/targets/xorg-radeon/Makefile @@ -0,0 +1,24 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = radeon_drv.so + +C_SOURCES = \ + radeon_target.c \ + radeon_xorg.c + +DRIVER_DEFINES = \ + -DHAVE_CONFIG_H -DGALLIUM_RBUG -DGALLIUM_TRACE -DGALLIUM_GALAHAD + +DRIVER_PIPES = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ + $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \ + $(TOP)/src/gallium/drivers/r300/libr300.a \ + $(TOP)/src/gallium/drivers/galahad/libgalahad.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/rbug/librbug.a + +DRIVER_LINKS = \ + $(shell pkg-config --libs libdrm libdrm_radeon) + +include ../Makefile.xorg diff --git a/src/gallium/targets/xorg-radeon/radeon_target.c b/src/gallium/targets/xorg-radeon/radeon_target.c new file mode 100644 index 0000000..5a0a8dc --- /dev/null +++ b/src/gallium/targets/xorg-radeon/radeon_target.c @@ -0,0 +1,26 @@ + +#include "target-helpers/inline_debug_helper.h" +#include "state_tracker/drm_driver.h" +#include "radeon/drm/radeon_drm_public.h" +#include "r300/r300_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct r300_winsys_screen *sws; + struct pipe_screen *screen; + + sws = r300_drm_winsys_screen_create(fd); + if (!sws) + return NULL; + + screen = r300_screen_create(sws); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +} + +DRM_DRIVER_DESCRIPTOR("radeon", "radeon", create_screen) 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 0000000..0d6aa56 --- /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 0000000..04a444f --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/Makefile @@ -0,0 +1,33 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = vmwgfx_drv.so + +C_SOURCES = \ + vmw_xorg.c \ + vmw_video.c \ + vmw_ioctl.c \ + vmw_ctrl.c \ + vmw_target.c \ + vmw_screen.c + +DRIVER_INCLUDES = \ + -I$(TOP)/src/gallium + +DRIVER_DEFINES = \ + -std=gnu99 \ + -DGALLIUM_RBUG \ + -DGALLIUM_TRACE \ + -DHAVE_CONFIG_H + +DRIVER_PIPES = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ + $(TOP)/src/gallium/winsys/svga/drm/libsvgadrm.a \ + $(TOP)/src/gallium/drivers/svga/libsvga.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/rbug/librbug.a + +DRIVER_LINKS = \ + $(shell pkg-config --libs libdrm libkms) + +include ../Makefile.xorg diff --git a/src/gallium/targets/xorg-vmwgfx/SConscript b/src/gallium/targets/xorg-vmwgfx/SConscript new file mode 100644 index 0000000..099d49c --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/SConscript @@ -0,0 +1,63 @@ +import os.path + +Import('*') + +env = env.Clone() + +env.ParseConfig('pkg-config --cflags --libs libdrm xorg-server') + +if env['kms']: + env.ParseConfig('pkg-config --cflags --libs libkms') + +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, + rbug, + st_xorg, + svgadrm, + svga, + gallium, +]) + +sources = [ + 'vmw_ioctl.c', + 'vmw_ctrl.c', + 'vmw_screen.c', + 'vmw_target.c', + 'vmw_video.c', + 'vmw_xorg.c', +] + +# TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions +module = env.LoadableModule( + target ='vmwgfx_drv.so', + source = sources, + LIBS = env['LIBS'], + SHLIBPREFIX = '', +) + +env.Alias('xorg-vmwgfx', module) diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_ctrl.c b/src/gallium/targets/xorg-vmwgfx/vmw_ctrl.c new file mode 100644 index 0000000..9b422e6 --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_ctrl.c @@ -0,0 +1,524 @@ +/* + * Copyright 2006 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). + */ + +/* + * vmwarectrl.c -- + * + * The implementation of the VMWARE_CTRL protocol extension that + * allows X clients to communicate with the driver. + */ + +#include +#include "dixstruct.h" +#include "extnsionst.h" +#include +#include + +#include "vmw_driver.h" +#include "vmwarectrlproto.h" + +#include "xf86drm.h" + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrlQueryVersion -- + * + * Implementation of QueryVersion command handler. Initialises and + * sends a reply. + * + * Results: + * Standard response codes. + * + * Side effects: + * Writes reply to client + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareCtrlQueryVersion(ClientPtr client) +{ + xVMwareCtrlQueryVersionReply rep = { 0, }; + register int n; + + REQUEST_SIZE_MATCH(xVMwareCtrlQueryVersionReq); + + rep.type = X_Reply; + rep.length = 0; + rep.sequenceNumber = client->sequence; + rep.majorVersion = VMWARE_CTRL_MAJOR_VERSION; + rep.minorVersion = VMWARE_CTRL_MINOR_VERSION; + if (client->swapped) { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.majorVersion, n); + swapl(&rep.minorVersion, n); + } + WriteToClient(client, sizeof(xVMwareCtrlQueryVersionReply), (char *)&rep); + + return client->noClientException; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrlDoSetRes -- + * + * Set the custom resolution into the mode list. + * + * This is done by alternately updating one of two dynamic modes. It is + * done this way because the server gets upset if you try to switch + * to a new resolution that has the same index as the current one. + * + * Results: + * TRUE on success, FALSE otherwise. + * + * Side effects: + * One dynamic mode will be updated if successful. + * + *---------------------------------------------------------------------------- + */ + +static Bool +VMwareCtrlDoSetRes(ScrnInfoPtr pScrn, + CARD32 x, + CARD32 y) +{ + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); + struct vmw_rect rect; + rect.x = 0; + rect.y = 0; + rect.w = x; + rect.h = y; + + vmw_ioctl_update_layout(vmw, 1, &rect); + + return TRUE; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrlSetRes -- + * + * Implementation of SetRes command handler. Initialises and sends a + * reply. + * + * Results: + * Standard response codes. + * + * Side effects: + * Writes reply to client + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareCtrlSetRes(ClientPtr client) +{ + REQUEST(xVMwareCtrlSetResReq); + xVMwareCtrlSetResReply rep = { 0, }; + ScrnInfoPtr pScrn; + ExtensionEntry *ext; + register int n; + + REQUEST_SIZE_MATCH(xVMwareCtrlSetResReq); + + if (!(ext = CheckExtension(VMWARE_CTRL_PROTOCOL_NAME))) { + return BadMatch; + } + + pScrn = ext->extPrivate; + if (pScrn->scrnIndex != stuff->screen) { + return BadMatch; + } + + if (!VMwareCtrlDoSetRes(pScrn, stuff->x, stuff->y)) { + return BadValue; + } + + rep.type = X_Reply; + rep.length = (sizeof(xVMwareCtrlSetResReply) - sizeof(xGenericReply)) >> 2; + rep.sequenceNumber = client->sequence; + rep.screen = stuff->screen; + rep.x = stuff->x; + rep.y = stuff->y; + if (client->swapped) { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.screen, n); + swapl(&rep.x, n); + swapl(&rep.y, n); + } + WriteToClient(client, sizeof(xVMwareCtrlSetResReply), (char *)&rep); + + return client->noClientException; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrlDoSetTopology -- + * + * Set the custom topology and set a dynamic mode to the bounding box + * of the passed topology. If a topology is already pending, then do + * nothing but do not return failure. + * + * Results: + * TRUE on success, FALSE otherwise. + * + * Side effects: + * One dynamic mode and the pending xinerama state will be updated if + * successful. + * + *---------------------------------------------------------------------------- + */ + +static Bool +VMwareCtrlDoSetTopology(ScrnInfoPtr pScrn, + xXineramaScreenInfo *extents, + unsigned long number) +{ + struct vmw_rect *rects; + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); + int i; + + rects = calloc(number, sizeof(*rects)); + if (!rects) + return FALSE; + + for (i = 0; i < number; i++) { + rects[i].x = extents[i].x_org; + rects[i].y = extents[i].y_org; + rects[i].w = extents[i].width; + rects[i].h = extents[i].height; + } + + vmw_ioctl_update_layout(vmw, number, rects); + + free(rects); + return TRUE; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrlSetTopology -- + * + * Implementation of SetTopology command handler. Initialises and sends a + * reply. + * + * Results: + * Standard response codes. + * + * Side effects: + * Writes reply to client + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareCtrlSetTopology(ClientPtr client) +{ + REQUEST(xVMwareCtrlSetTopologyReq); + xVMwareCtrlSetTopologyReply rep = { 0, }; + ScrnInfoPtr pScrn; + ExtensionEntry *ext; + register int n; + xXineramaScreenInfo *extents; + + REQUEST_AT_LEAST_SIZE(xVMwareCtrlSetTopologyReq); + + if (!(ext = CheckExtension(VMWARE_CTRL_PROTOCOL_NAME))) { + return BadMatch; + } + + pScrn = ext->extPrivate; + if (pScrn->scrnIndex != stuff->screen) { + return BadMatch; + } + + extents = (xXineramaScreenInfo *)(stuff + 1); + if (!VMwareCtrlDoSetTopology(pScrn, extents, stuff->number)) { + return BadValue; + } + + rep.type = X_Reply; + rep.length = (sizeof(xVMwareCtrlSetTopologyReply) - sizeof(xGenericReply)) >> 2; + rep.sequenceNumber = client->sequence; + rep.screen = stuff->screen; + if (client->swapped) { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.screen, n); + } + WriteToClient(client, sizeof(xVMwareCtrlSetTopologyReply), (char *)&rep); + + return client->noClientException; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrlDispatch -- + * + * Dispatcher for VMWARE_CTRL commands. Calls the correct handler for + * each command type. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of individual command handlers. + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareCtrlDispatch(ClientPtr client) +{ + REQUEST(xReq); + + switch(stuff->data) { + case X_VMwareCtrlQueryVersion: + return VMwareCtrlQueryVersion(client); + case X_VMwareCtrlSetRes: + return VMwareCtrlSetRes(client); + case X_VMwareCtrlSetTopology: + return VMwareCtrlSetTopology(client); + } + return BadRequest; +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareCtrlQueryVersion -- + * + * Wrapper for QueryVersion handler that handles input from other-endian + * clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of unswapped implementation. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareCtrlQueryVersion(ClientPtr client) +{ + register int n; + + REQUEST(xVMwareCtrlQueryVersionReq); + REQUEST_SIZE_MATCH(xVMwareCtrlQueryVersionReq); + + swaps(&stuff->length, n); + + return VMwareCtrlQueryVersion(client); +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareCtrlSetRes -- + * + * Wrapper for SetRes handler that handles input from other-endian + * clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of unswapped implementation. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareCtrlSetRes(ClientPtr client) +{ + register int n; + + REQUEST(xVMwareCtrlSetResReq); + REQUEST_SIZE_MATCH(xVMwareCtrlSetResReq); + + swaps(&stuff->length, n); + swapl(&stuff->screen, n); + swapl(&stuff->x, n); + swapl(&stuff->y, n); + + return VMwareCtrlSetRes(client); +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareCtrlSetTopology -- + * + * Wrapper for SetTopology handler that handles input from other-endian + * clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of unswapped implementation. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareCtrlSetTopology(ClientPtr client) +{ + register int n; + + REQUEST(xVMwareCtrlSetTopologyReq); + REQUEST_SIZE_MATCH(xVMwareCtrlSetTopologyReq); + + swaps(&stuff->length, n); + swapl(&stuff->screen, n); + swapl(&stuff->number, n); + /* Each extent is a struct of shorts. */ + SwapRestS(stuff); + + return VMwareCtrlSetTopology(client); +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareCtrlDispatch -- + * + * Wrapper for dispatcher that handles input from other-endian clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of individual command handlers. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareCtrlDispatch(ClientPtr client) +{ + REQUEST(xReq); + + switch(stuff->data) { + case X_VMwareCtrlQueryVersion: + return SVMwareCtrlQueryVersion(client); + case X_VMwareCtrlSetRes: + return SVMwareCtrlSetRes(client); + case X_VMwareCtrlSetTopology: + return SVMwareCtrlSetTopology(client); + } + return BadRequest; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrlResetProc -- + * + * Cleanup handler called when the extension is removed. + * + * Results: + * None + * + * Side effects: + * None + * + *---------------------------------------------------------------------------- + */ + +static void +VMwareCtrlResetProc(ExtensionEntry* extEntry) +{ + /* Currently, no cleanup is necessary. */ +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrl_ExitInit -- + * + * Initialiser for the VMWARE_CTRL protocol extension. + * + * Results: + * None. + * + * Side effects: + * Protocol extension will be registered if successful. + * + *---------------------------------------------------------------------------- + */ + +void +vmw_ctrl_ext_init(struct vmw_customizer *vmw) +{ + ExtensionEntry *myext; + ScrnInfoPtr pScrn = vmw->pScrn; + + if (!(myext = CheckExtension(VMWARE_CTRL_PROTOCOL_NAME))) { + if (!(myext = AddExtension(VMWARE_CTRL_PROTOCOL_NAME, 0, 0, + VMwareCtrlDispatch, + SVMwareCtrlDispatch, + VMwareCtrlResetProc, + StandardMinorOpcode))) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Failed to add VMWARE_CTRL extension\n"); + return; + } + + /* + * For now, only support one screen as that's all the virtual + * hardware supports. + */ + myext->extPrivate = pScrn; + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Initialized VMWARE_CTRL extension version %d.%d\n", + VMWARE_CTRL_MAJOR_VERSION, VMWARE_CTRL_MINOR_VERSION); + } +} diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_ctrl.h b/src/gallium/targets/xorg-vmwgfx/vmw_ctrl.h new file mode 100644 index 0000000..65e1cf5 --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_ctrl.h @@ -0,0 +1,48 @@ +/* + * Copyright 2006 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). + */ + +/* + * vmw_ctrl.h -- + * + * The definitions used by the VMWARE_CTRL protocol extension that + * allows X clients to communicate with the driver. + */ + + +#ifndef _VMW_CTRL_H_ +#define _VMW_CTRL_H_ + +#define VMWARE_CTRL_PROTOCOL_NAME "VMWARE_CTRL" + +#define VMWARE_CTRL_MAJOR_VERSION 0 +#define VMWARE_CTRL_MINOR_VERSION 2 + +#define X_VMwareCtrlQueryVersion 0 +#define X_VMwareCtrlSetRes 1 +#define X_VMwareCtrlSetTopology 2 + +#endif /* _VMW_CTRL_H_ */ 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 0000000..8dfc9d2 --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_driver.h @@ -0,0 +1,120 @@ +/********************************************************** + * 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_rect +{ + int32_t x; + int32_t y; + uint32_t w; + uint32_t h; +}; + +struct vmw_customizer +{ + CustomizerRec base; + ScrnInfoPtr pScrn; + + int fd; + + void *cursor_priv; + + /* vmw_video.c */ + void *video_priv; + uint64_t max_fb_size; +}; + +static INLINE struct vmw_customizer * +vmw_customizer(CustomizerPtr cust) +{ + return cust ? (struct vmw_customizer *) cust : NULL; +} + +/*********************************************************************** + * vmw_ctrl.c + */ + +void vmw_ctrl_ext_init(struct vmw_customizer *vmw); + + +/*********************************************************************** + * 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); + +int vmw_ioctl_update_layout(struct vmw_customizer *vmw, uint32_t num, struct vmw_rect *rects); + + +#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 0000000..224a2d9 --- /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 0000000..7625d2f --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c @@ -0,0 +1,260 @@ +/********************************************************** + * 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/svga/drm/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 = calloc(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: + free(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)); + + free(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; +} + +int +vmw_ioctl_update_layout(struct vmw_customizer *vmw, uint32_t num, struct vmw_rect *rects) +{ + struct drm_vmw_update_layout_arg ul_arg; + int ret; + + assert(sizeof(struct vmw_rect) == sizeof(struct drm_vmw_rect)); + + memset(&ul_arg, 0, sizeof(ul_arg)); + ul_arg.num_outputs = num; + ul_arg.rects = (uint64_t)(uintptr_t)rects; + + ret = drmCommandWriteRead(vmw->fd, DRM_VMW_UPDATE_LAYOUT, + &ul_arg, sizeof(ul_arg)); + + return ret; +} 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 0000000..7662203 --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_screen.c @@ -0,0 +1,267 @@ +/********************************************************** + * 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 + +#include "cursorstr.h" +#include "../../winsys/svga/drm/vmwgfx_drm.h" + +void vmw_winsys_screen_set_throttling(struct pipe_screen *screen, + uint32_t throttle_us); + + +/* 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 void +vmw_context_throttle(CustomizerPtr cust, + struct pipe_context *pipe, + enum xorg_throttling_reason reason) +{ + switch (reason) { + case THROTTLE_RENDER: + vmw_winsys_screen_set_throttling(pipe->screen, 20000); + break; + default: + vmw_winsys_screen_set_throttling(pipe->screen, 0); + } +} + +static void +vmw_context_no_throttle(CustomizerPtr cust, + struct pipe_context *pipe, + enum xorg_throttling_reason reason) +{ + vmw_winsys_screen_set_throttling(pipe->screen, 0); +} + +static Bool +vmw_check_fb_size(CustomizerPtr cust, + unsigned long pitch, + unsigned long height) +{ + struct vmw_customizer *vmw = vmw_customizer(cust); + + /** + * 1) Is there a pitch alignment? + * 2) The 1024 byte pad is an arbitrary value to be on + */ + + return ((uint64_t) pitch * height + 1024ULL < vmw->max_fb_size); +} + +static Bool +vmw_pre_init(CustomizerPtr cust, int fd) +{ + struct vmw_customizer *vmw = vmw_customizer(cust); + drmVersionPtr ver; + + vmw->fd = fd; + + ver = drmGetVersion(vmw->fd); + if (ver == NULL || + (ver->version_major == 1 && ver->version_minor < 1)) { + cust->swap_throttling = TRUE; + cust->dirty_throttling = TRUE; + cust->winsys_context_throttle = vmw_context_no_throttle; + } else { + cust->swap_throttling = TRUE; + cust->dirty_throttling = FALSE; + cust->winsys_context_throttle = vmw_context_throttle; + debug_printf("%s: Enabling kernel throttling.\n", __func__); + + if (ver->version_major > 1 || + (ver->version_major == 1 && ver->version_minor >= 3)) { + struct drm_vmw_getparam_arg arg; + int ret; + + arg.param = DRM_VMW_PARAM_MAX_FB_SIZE; + ret = drmCommandWriteRead(fd, DRM_VMW_GET_PARAM, &arg, + sizeof(arg)); + if (!ret) { + vmw->max_fb_size = arg.value; + cust->winsys_check_fb_size = vmw_check_fb_size; + debug_printf("%s: Enabling fb size check.\n", __func__); + } + } + } + + if (ver) + drmFreeVersion(ver); + + return TRUE; +} + +static Bool +vmw_screen_init(CustomizerPtr cust) +{ + struct vmw_customizer *vmw = vmw_customizer(cust); + + vmw_screen_cursor_init(vmw); + + vmw_ctrl_ext_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_pre_init = vmw_pre_init; + 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; + cust->no_3d = TRUE; + cust->unhidden_hw_cursor_update = TRUE; + 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_target.c b/src/gallium/targets/xorg-vmwgfx/vmw_target.c new file mode 100644 index 0000000..15089d6 --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_target.c @@ -0,0 +1,26 @@ + +#include "target-helpers/inline_debug_helper.h" +#include "state_tracker/drm_driver.h" +#include "svga/drm/svga_drm_public.h" +#include "svga/svga_public.h" + +static struct pipe_screen * +create_screen(int fd) +{ + struct svga_winsys_screen *sws; + struct pipe_screen *screen; + + sws = svga_drm_winsys_screen_create(fd); + if (!sws) + return NULL; + + screen = svga_screen_create(sws); + if (!screen) + return NULL; + + screen = debug_screen_wrap(screen); + + return screen; +} + +DRM_DRIVER_DESCRIPTOR("vmwgfx", "vmwgfx", create_screen) 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 0000000..7979209 --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_video.c @@ -0,0 +1,1089 @@ +/* + * 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/svga/drm/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 = malloc((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) { + free(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); + REGION_UNINIT(pScreen, &video->port[i].clipBoxes); + } + + + /* 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 = calloc(1, sizeof(*video)); + if (!video) { + debug_printf("Not enough memory.\n"); + xf86XVFreeVideoAdaptorRec(adaptor); + return NULL; + } + + vmw->video_priv = video; + + adaptor->type = XvInputMask | XvImageMask | XvWindowMask; + + /** + * Note: CLIP_TO_VIEWPORT was removed from the flags, since with the + * crtc/output based modesetting, the viewport is not updated on + * RandR modeswitches. Hence the video may incorrectly be clipped away. + * The correct approach, (if needed) would be to clip against the + * scanout area union of all active crtcs. Revisit if needed. + */ + + adaptor->flags = VIDEO_OVERLAID_IMAGES; + 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; + REGION_NULL(pScrn->pScreen, &video->port[i].clipBoxes); + 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); + + xorg_flush(pScrn->pScreen); + + 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); + } + + xorg_flush(pScrn->pScreen); + + 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 = calloc(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; + + free(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; + + REGION_EMPTY(pScrn->pScreen, &port->clipBoxes); + + 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 0000000..87aad25 --- /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/targets/xorg-vmwgfx/vmwarectrlproto.h b/src/gallium/targets/xorg-vmwgfx/vmwarectrlproto.h new file mode 100644 index 0000000..269e10b --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmwarectrlproto.h @@ -0,0 +1,122 @@ +/* + * Copyright 2006 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). + */ + +/* + * vmwarectrlproto.h -- + * + * The description of the VMWARE_CTRL protocol extension that + * allows X clients to communicate with the driver. + */ + +#ifndef _VMWARE_CTRL_PROTO_H_ +#define _VMWARE_CTRL_PROTO_H_ + + +#include +#include "vmw_ctrl.h" + + +/* + * Requests and Replies + */ + +/* Version 0.1 definitions. */ + +typedef struct { + CARD8 reqType; /* always X_VMwareCtrlReqCode */ + CARD8 VMwareCtrlReqType; /* always X_VMwareCtrlQueryVersion */ + CARD16 length B16; + CARD32 majorVersion B32; + CARD32 minorVersion B32; +} xVMwareCtrlQueryVersionReq; +#define sz_xVMwareCtrlQueryVersionReq 12 + +typedef struct { + BYTE type; /* X_Reply */ + BYTE pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 majorVersion B32; + CARD32 minorVersion B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; +} xVMwareCtrlQueryVersionReply; +#define sz_xVMwareCtrlQueryVersionReply 32 + +typedef struct { + CARD8 reqType; /* always X_VMwareCtrlReqCode */ + CARD8 VMwareCtrlReqType; /* always X_VMwareCtrlSetRes */ + CARD16 length B16; + CARD32 screen B32; + CARD32 x B32; + CARD32 y B32; +} xVMwareCtrlSetResReq; +#define sz_xVMwareCtrlSetResReq 16 + +typedef struct { + BYTE type; /* X_Reply */ + BYTE pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 screen B32; + CARD32 x B32; + CARD32 y B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; +} xVMwareCtrlSetResReply; +#define sz_xVMwareCtrlSetResReply 32 + +/* Version 0.2 definitions. */ + +typedef struct { + CARD8 reqType; /* always X_VMwareCtrlReqCode */ + CARD8 VMwareCtrlReqType; /* always X_VMwareCtrlSetTopology */ + CARD16 length B16; + CARD32 screen B32; + CARD32 number B32; + CARD32 pad1 B32; +} xVMwareCtrlSetTopologyReq; +#define sz_xVMwareCtrlSetTopologyReq 16 + +typedef struct { + BYTE type; /* X_Reply */ + BYTE pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 screen B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; +} xVMwareCtrlSetTopologyReply; +#define sz_xVMwareCtrlSetTopologyReply 32 + +#endif /* _VMWARE_CTRL_PROTO_H_ */ diff --git a/src/gallium/tests/graw/SConscript b/src/gallium/tests/graw/SConscript new file mode 100644 index 0000000..3341b88 --- /dev/null +++ b/src/gallium/tests/graw/SConscript @@ -0,0 +1,35 @@ +Import('*') + +env = env.Clone() + +env.Prepend(LIBS = [gallium]) + +env.Prepend(LIBPATH = [graw.dir]) +env.Prepend(LIBS = ['graw']) + + +if env['platform'] in ('freebsd8', 'sunos5'): + env.Append(LIBS = ['m']) + +if env['platform'] == 'freebsd8': + env.Append(LIBS = ['pthread']) + +progs = [ + 'clear', + 'tri', + 'tri-instanced', + 'quad-tex', + 'fs-test', + 'vs-test', + 'gs-test', + 'shader-leak', + 'tri-gs', +] + +for name in progs: + program = env.Program( + target = name, + source = name + '.c', + ) + #env.Depends(program, graw) + env.Alias('graw-progs', program) diff --git a/src/gallium/tests/graw/clear.c b/src/gallium/tests/graw/clear.c new file mode 100644 index 0000000..1ff80ca --- /dev/null +++ b/src/gallium/tests/graw/clear.c @@ -0,0 +1,120 @@ +/* Display a cleared blue window. This demo has no dependencies on + * any utility code, just the graw interface and gallium. + */ + +#include "state_tracker/graw.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" + +enum pipe_format formats[] = { + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_NONE +}; + +static const int WIDTH = 300; +static const int HEIGHT = 300; + +struct pipe_screen *screen; +struct pipe_context *ctx; +struct pipe_surface *surf; +struct pipe_resource *tex; +static void *window = NULL; + +static void draw( void ) +{ + float clear_color[4] = {1,0,1,1}; + + ctx->clear(ctx, PIPE_CLEAR_COLOR, clear_color, 0, 0); + ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL); + + graw_save_surface_to_file(ctx, surf, NULL); + + screen->flush_frontbuffer(screen, tex, 0, 0, window); +} + +static void init( void ) +{ + struct pipe_framebuffer_state fb; + struct pipe_resource templat; + struct pipe_surface surf_tmpl; + int i; + + /* It's hard to say whether window or screen should be created + * first. Different environments would prefer one or the other. + * + * Also, no easy way of querying supported formats if the screen + * cannot be created first. + */ + for (i = 0; + window == NULL && formats[i] != PIPE_FORMAT_NONE; + i++) { + + screen = graw_create_window_and_screen(0,0,300,300, + formats[i], + &window); + } + if (window == NULL) + exit(2); + + ctx = screen->context_create(screen, NULL); + if (ctx == NULL) + exit(3); + + templat.target = PIPE_TEXTURE_2D; + templat.format = formats[i]; + templat.width0 = WIDTH; + templat.height0 = HEIGHT; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET); + + tex = screen->resource_create(screen, + &templat); + if (tex == NULL) + exit(4); + + surf_tmpl.format = templat.format; + surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; + surf_tmpl.u.tex.level = 0; + surf_tmpl.u.tex.first_layer = 0; + surf_tmpl.u.tex.last_layer = 0; + surf = ctx->create_surface(ctx, tex, &surf_tmpl); + if (surf == NULL) + exit(5); + + memset(&fb, 0, sizeof fb); + fb.nr_cbufs = 1; + fb.width = WIDTH; + fb.height = HEIGHT; + fb.cbufs[0] = surf; + + ctx->set_framebuffer_state(ctx, &fb); +} + +static void args(int argc, char *argv[]) +{ + int i; + + for (i = 1; i < argc;) { + if (graw_parse_args(&i, argc, argv)) { + continue; + } + exit(1); + } +} + +int main( int argc, char *argv[] ) +{ + args(argc, argv); + init(); + + graw_set_display_func( draw ); + graw_main_loop(); + return 0; +} diff --git a/src/gallium/tests/graw/fragment-shader/fragment-shader.py b/src/gallium/tests/graw/fragment-shader/fragment-shader.py new file mode 100644 index 0000000..ef65a9c --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/fragment-shader.py @@ -0,0 +1,257 @@ +#!/usr/bin/env python +########################################################################## +# +# 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. +# +########################################################################## + +import struct + +from gallium import * + +def make_image(surface): + data = surface.get_tile_rgba8(0, 0, surface.width, surface.height) + + import Image + outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1) + return outimage + +def save_image(filename, surface): + outimage = make_image(surface) + outimage.save(filename, "PNG") + +def test(dev, name): + ctx = dev.context_create() + + width = 320 + height = 320 + minz = 0.0 + maxz = 1.0 + + # disabled blending/masking + blend = Blend() + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.rt[0].colormask = PIPE_MASK_RGBA + ctx.set_blend(blend) + + # depth/stencil/alpha + depth_stencil_alpha = DepthStencilAlpha() + depth_stencil_alpha.depth.enabled = 0 + depth_stencil_alpha.depth.writemask = 1 + depth_stencil_alpha.depth.func = PIPE_FUNC_LESS + ctx.set_depth_stencil_alpha(depth_stencil_alpha) + + # rasterizer + rasterizer = Rasterizer() + rasterizer.front_winding = PIPE_WINDING_CW + rasterizer.cull_mode = PIPE_WINDING_NONE + rasterizer.scissor = 1 + ctx.set_rasterizer(rasterizer) + + # viewport + viewport = Viewport() + scale = FloatArray(4) + scale[0] = width / 2.0 + scale[1] = -height / 2.0 + scale[2] = (maxz - minz) / 2.0 + scale[3] = 1.0 + viewport.scale = scale + translate = FloatArray(4) + translate[0] = width / 2.0 + translate[1] = height / 2.0 + translate[2] = (maxz - minz) / 2.0 + translate[3] = 0.0 + viewport.translate = translate + ctx.set_viewport(viewport) + + # samplers + sampler = Sampler() + sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE + sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.normalized_coords = 1 + ctx.set_fragment_sampler(0, sampler) + + # scissor + scissor = Scissor() + scissor.minx = 0 + scissor.miny = 0 + scissor.maxx = width + scissor.maxy = height + ctx.set_scissor(scissor) + + clip = Clip() + clip.nr = 0 + ctx.set_clip(clip) + + # framebuffer + cbuf = dev.resource_create( + PIPE_FORMAT_B8G8R8X8_UNORM, + width, height, + bind=PIPE_BIND_RENDER_TARGET, + ).get_surface() + fb = Framebuffer() + fb.width = width + fb.height = height + fb.nr_cbufs = 1 + fb.set_cbuf(0, cbuf) + ctx.set_framebuffer(fb) + rgba = FloatArray(4); + rgba[0] = 0.5 + rgba[1] = 0.5 + rgba[2] = 0.5 + rgba[3] = 0.5 + ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0) + + # vertex shader + vs = Shader(''' + VERT + DCL IN[0], POSITION + DCL IN[1], COLOR + DCL OUT[0], POSITION + DCL OUT[1], COLOR + MOV OUT[0], IN[0] + MOV OUT[1], IN[1] + END + ''') + ctx.set_vertex_shader(vs) + + # fragment shader + fs = Shader(file('frag-' + name + '.sh', 'rt').read()) + ctx.set_fragment_shader(fs) + + constbuf0 = dev.buffer_create(64, + (PIPE_BUFFER_USAGE_CONSTANT | + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE), + 4 * 4 * 4) + + cbdata = '' + cbdata += struct.pack('4f', 0.4, 0.0, 0.0, 1.0) + cbdata += struct.pack('4f', 1.0, 1.0, 1.0, 1.0) + cbdata += struct.pack('4f', 2.0, 2.0, 2.0, 2.0) + cbdata += struct.pack('4f', 4.0, 8.0, 16.0, 32.0) + + constbuf0.write(cbdata, 0) + + ctx.set_constant_buffer(PIPE_SHADER_FRAGMENT, + 0, + constbuf0) + + constbuf1 = dev.buffer_create(64, + (PIPE_BUFFER_USAGE_CONSTANT | + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE), + 4 * 4 * 4) + + cbdata = '' + cbdata += struct.pack('4f', 0.1, 0.1, 0.1, 0.1) + cbdata += struct.pack('4f', 0.25, 0.25, 0.25, 0.25) + cbdata += struct.pack('4f', 0.5, 0.5, 0.5, 0.5) + cbdata += struct.pack('4f', 0.75, 0.75, 0.75, 0.75) + + constbuf1.write(cbdata, 0) + + ctx.set_constant_buffer(PIPE_SHADER_FRAGMENT, + 1, + constbuf1) + + xy = [ + -0.8, -0.8, + 0.8, -0.8, + 0.0, 0.8, + ] + color = [ + 1.0, 0.0, 0.0, + 0.0, 1.0, 0.0, + 0.0, 0.0, 1.0, + ] + + nverts = 3 + nattrs = 2 + verts = FloatArray(nverts * nattrs * 4) + + for i in range(0, nverts): + verts[i * nattrs * 4 + 0] = xy[i * 2 + 0] # x + verts[i * nattrs * 4 + 1] = xy[i * 2 + 1] # y + verts[i * nattrs * 4 + 2] = 0.5 # z + verts[i * nattrs * 4 + 3] = 1.0 # w + verts[i * nattrs * 4 + 4] = color[i * 3 + 0] # r + verts[i * nattrs * 4 + 5] = color[i * 3 + 1] # g + verts[i * nattrs * 4 + 6] = color[i * 3 + 2] # b + verts[i * nattrs * 4 + 7] = 1.0 # a + + ctx.draw_vertices(PIPE_PRIM_TRIANGLES, + nverts, + nattrs, + verts) + + ctx.flush() + + save_image('frag-' + name + '.png', cbuf) + +def main(): + tests = [ + 'abs', + 'add', + 'cb-1d', + 'cb-2d', + 'dp3', + 'dp4', + 'dst', + 'ex2', + 'flr', + 'frc', + 'lg2', + 'lit', + 'lrp', + 'mad', + 'max', + 'min', + 'mov', + 'mul', + 'rcp', + 'rsq', + 'sge', + 'slt', + 'srcmod-abs', + 'srcmod-absneg', + 'srcmod-neg', + 'srcmod-swz', + 'sub', + 'xpd', + ] + + dev = Device() + for t in tests: + test(dev, t) + +if __name__ == '__main__': + main() diff --git a/src/gallium/tests/graw/fs-test.c b/src/gallium/tests/graw/fs-test.c new file mode 100644 index 0000000..37be2d0 --- /dev/null +++ b/src/gallium/tests/graw/fs-test.c @@ -0,0 +1,555 @@ +/* Display a cleared blue window. This demo has no dependencies on + * any utility code, just the graw interface and gallium. + */ + +#include "state_tracker/graw.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include /* for fread(), etc */ + +#include "util/u_inlines.h" +#include "util/u_memory.h" /* Offset() */ +#include "util/u_draw_quad.h" +#include "util/u_box.h" + +static const char *filename = NULL; +unsigned show_fps = 0; + + +static void usage(char *name) +{ + fprintf(stderr, "usage: %s [ options ] shader_filename\n", name); +#ifndef WIN32 + fprintf(stderr, "\n" ); + fprintf(stderr, "options:\n"); + fprintf(stderr, " -fps show frames per second\n"); +#endif +} + + +enum pipe_format formats[] = { + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_NONE +}; + +static const int WIDTH = 250; +static const int HEIGHT = 250; + +static struct pipe_screen *screen = NULL; +static struct pipe_context *ctx = NULL; +static struct pipe_resource *rttex = NULL; +static struct pipe_resource *constbuf1 = NULL; +static struct pipe_resource *constbuf2 = NULL; +static struct pipe_surface *surf = NULL; +static struct pipe_sampler_view *sv = NULL; +static void *sampler = NULL; +static void *window = NULL; +static struct pipe_resource *samptex = NULL; + +struct vertex { + float position[4]; + float color[4]; + float texcoord[4]; +}; + +/* Vertex data matches progs/fp/fp-tri.c, but flipped in Y dimension + * so that the final images are the same. + */ +static struct vertex vertices[] = +{ + { { 0.9, 0.9, 0.0, 1.0 }, + { 0, 0, 1, 1 }, + { 1, 1, 0, 1 } }, + + { { 0.9, -0.9, 0.0, 1.0 }, + { 1, 0, 0, 1 }, + { 1, -1, 0, 1 } }, + + { {-0.9, 0.0, 0.0, 1.0 }, + { 0, 1, 0, 1 }, + { -1, 0, 0, 1 } }, +}; + +static float constants1[] = +{ 0.4, 0, 0, 1, + 1, 1, 1, 1, + 2, 2, 2, 2, + 4, 8, 16, 32, + + 3, 0, 0, 0, + 0, .5, 0, 0, + 1, 0, 0, 1, + 0, 0, 0, 1, + + 1, 0, 0, 0.5, + 0, 1, 0, 0.5, + 0, 0, 1, 0, + 0, 0, 0, 1, +}; + + +static float constants2[] = +{ 1, 0, 0, 1, + 0, 1, 0, 1, + 0, 0, 1, 1, + 0, 0, 0, 0, + + 1, 1, 0, 1, + 1, .5, 0, 1, + 1, 0, 0, 1, + 0, 0, 0, 1, + + 1, 0, 0, 0.5, + 0, 1, 0, 0.5, + 0, 0, 1, 0, + 0, 0, 0, 1, +}; + +static void init_fs_constbuf( void ) +{ + struct pipe_resource templat; + struct pipe_box box; + + templat.target = PIPE_BUFFER; + templat.format = PIPE_FORMAT_R8_UNORM; + templat.width0 = sizeof(constants1); + templat.height0 = 1; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = PIPE_BIND_CONSTANT_BUFFER; + + constbuf1 = screen->resource_create(screen, + &templat); + if (constbuf1 == NULL) + exit(4); + + constbuf2 = screen->resource_create(screen, + &templat); + if (constbuf2 == NULL) + exit(4); + + + { + u_box_2d(0,0,sizeof(constants1),1, &box); + + ctx->transfer_inline_write(ctx, + constbuf1, + 0, + PIPE_TRANSFER_WRITE, + &box, + constants1, + sizeof constants1, + sizeof constants1); + + + ctx->set_constant_buffer(ctx, + PIPE_SHADER_FRAGMENT, 0, + constbuf1); + } + { + u_box_2d(0,0,sizeof(constants2),1, &box); + + ctx->transfer_inline_write(ctx, + constbuf2, + 0, + PIPE_TRANSFER_WRITE, + &box, + constants2, + sizeof constants2, + sizeof constants2); + + + ctx->set_constant_buffer(ctx, + PIPE_SHADER_FRAGMENT, 1, + constbuf2); + } +} + + +static void set_viewport( float x, float y, + float width, float height, + float near, float far) +{ + float z = far; + float half_width = (float)width / 2.0f; + float half_height = (float)height / 2.0f; + float half_depth = ((float)far - (float)near) / 2.0f; + struct pipe_viewport_state vp; + + vp.scale[0] = half_width; + vp.scale[1] = half_height; + vp.scale[2] = half_depth; + vp.scale[3] = 1.0f; + + vp.translate[0] = half_width + x; + vp.translate[1] = half_height + y; + vp.translate[2] = half_depth + z; + vp.translate[3] = 0.0f; + + ctx->set_viewport_state( ctx, &vp ); +} + +static void set_vertices( void ) +{ + struct pipe_vertex_element ve[3]; + struct pipe_vertex_buffer vbuf; + void *handle; + + memset(ve, 0, sizeof ve); + + ve[0].src_offset = Offset(struct vertex, position); + ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + ve[1].src_offset = Offset(struct vertex, color); + ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + ve[2].src_offset = Offset(struct vertex, texcoord); + ve[2].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + handle = ctx->create_vertex_elements_state(ctx, 3, ve); + ctx->bind_vertex_elements_state(ctx, handle); + + + vbuf.stride = sizeof( struct vertex ); + vbuf.max_index = sizeof(vertices) / vbuf.stride; + vbuf.buffer_offset = 0; + vbuf.buffer = screen->user_buffer_create(screen, + vertices, + sizeof(vertices), + PIPE_BIND_VERTEX_BUFFER); + + ctx->set_vertex_buffers(ctx, 1, &vbuf); +} + +static void set_vertex_shader( void ) +{ + void *handle; + const char *text = + "VERT\n" + "DCL IN[0]\n" + "DCL IN[1]\n" + "DCL IN[2]\n" + "DCL OUT[0], POSITION\n" + "DCL OUT[1], COLOR[0]\n" + "DCL OUT[2], GENERIC[0]\n" + " MOV OUT[0], IN[0]\n" + " MOV OUT[1], IN[1]\n" + " MOV OUT[2], IN[2]\n" + " END\n"; + + handle = graw_parse_vertex_shader(ctx, text); + ctx->bind_vs_state(ctx, handle); +} + +static void set_fragment_shader( const char *filename ) +{ + FILE *f; + char buf[50000]; + void *handle; + int sz; + + if ((f = fopen(filename, "r")) == NULL) { + fprintf(stderr, "Couldn't open %s\n", filename); + exit(1); + } + + sz = fread(buf, 1, sizeof(buf), f); + if (!feof(f)) { + printf("file too long\n"); + exit(1); + } + printf("%.*s\n", sz, buf); + buf[sz] = 0; + + handle = graw_parse_fragment_shader(ctx, buf); + ctx->bind_fs_state(ctx, handle); + fclose(f); +} + + +static void draw( void ) +{ + float clear_color[4] = {.1,.3,.5,0}; + + ctx->clear(ctx, PIPE_CLEAR_COLOR, clear_color, 0, 0); + util_draw_arrays(ctx, PIPE_PRIM_TRIANGLES, 0, 3); + ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL); + + graw_save_surface_to_file(ctx, surf, NULL); + + screen->flush_frontbuffer(screen, rttex, 0, 0, window); +} + +#define SIZE 16 + +static void init_tex( void ) +{ + struct pipe_sampler_view sv_template; + struct pipe_sampler_state sampler_desc; + struct pipe_resource templat; + struct pipe_box box; + ubyte tex2d[SIZE][SIZE][4]; + int s, t; + +#if (SIZE != 2) + for (s = 0; s < SIZE; s++) { + for (t = 0; t < SIZE; t++) { + if (0) { + int x = (s ^ t) & 1; + tex2d[t][s][0] = (x) ? 0 : 63; + tex2d[t][s][1] = (x) ? 0 : 128; + tex2d[t][s][2] = 0; + tex2d[t][s][3] = 0xff; + } + else { + int x = ((s ^ t) >> 2) & 1; + tex2d[t][s][0] = s*255/(SIZE-1); + tex2d[t][s][1] = t*255/(SIZE-1); + tex2d[t][s][2] = (x) ? 0 : 128; + tex2d[t][s][3] = 0xff; + } + } + } +#else + tex2d[0][0][0] = 0; + tex2d[0][0][1] = 255; + tex2d[0][0][2] = 255; + tex2d[0][0][3] = 0; + + tex2d[0][1][0] = 0; + tex2d[0][1][1] = 0; + tex2d[0][1][2] = 255; + tex2d[0][1][3] = 255; + + tex2d[1][0][0] = 255; + tex2d[1][0][1] = 255; + tex2d[1][0][2] = 0; + tex2d[1][0][3] = 255; + + tex2d[1][1][0] = 255; + tex2d[1][1][1] = 0; + tex2d[1][1][2] = 0; + tex2d[1][1][3] = 255; +#endif + + templat.target = PIPE_TEXTURE_2D; + templat.format = PIPE_FORMAT_B8G8R8A8_UNORM; + templat.width0 = SIZE; + templat.height0 = SIZE; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = PIPE_BIND_SAMPLER_VIEW; + + + samptex = screen->resource_create(screen, + &templat); + if (samptex == NULL) + exit(4); + + u_box_2d(0,0,SIZE,SIZE, &box); + + ctx->transfer_inline_write(ctx, + samptex, + 0, + PIPE_TRANSFER_WRITE, + &box, + tex2d, + sizeof tex2d[0], + sizeof tex2d); + + /* Possibly read back & compare against original data: + */ + if (0) + { + struct pipe_transfer *t; + uint32_t *ptr; + t = pipe_get_transfer(ctx, samptex, + 0, 0, /* level, layer */ + PIPE_TRANSFER_READ, + 0, 0, SIZE, SIZE); /* x, y, width, height */ + + ptr = ctx->transfer_map(ctx, t); + + if (memcmp(ptr, tex2d, sizeof tex2d) != 0) { + assert(0); + exit(9); + } + + ctx->transfer_unmap(ctx, t); + + ctx->transfer_destroy(ctx, t); + } + + memset(&sv_template, 0, sizeof sv_template); + sv_template.format = samptex->format; + sv_template.texture = samptex; + sv_template.swizzle_r = 0; + sv_template.swizzle_g = 1; + sv_template.swizzle_b = 2; + sv_template.swizzle_a = 3; + sv = ctx->create_sampler_view(ctx, samptex, &sv_template); + if (sv == NULL) + exit(5); + + ctx->set_fragment_sampler_views(ctx, 1, &sv); + + + memset(&sampler_desc, 0, sizeof sampler_desc); + sampler_desc.wrap_s = PIPE_TEX_WRAP_REPEAT; + sampler_desc.wrap_t = PIPE_TEX_WRAP_REPEAT; + sampler_desc.wrap_r = PIPE_TEX_WRAP_REPEAT; + sampler_desc.min_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler_desc.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + sampler_desc.mag_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler_desc.compare_mode = PIPE_TEX_COMPARE_NONE; + sampler_desc.compare_func = 0; + sampler_desc.normalized_coords = 1; + sampler_desc.max_anisotropy = 0; + + sampler = ctx->create_sampler_state(ctx, &sampler_desc); + if (sampler == NULL) + exit(6); + + ctx->bind_fragment_sampler_states(ctx, 1, &sampler); + +} + +static void init( void ) +{ + struct pipe_framebuffer_state fb; + struct pipe_resource templat; + struct pipe_surface surf_tmpl; + int i; + + /* It's hard to say whether window or screen should be created + * first. Different environments would prefer one or the other. + * + * Also, no easy way of querying supported formats if the screen + * cannot be created first. + */ + for (i = 0; + window == NULL && formats[i] != PIPE_FORMAT_NONE; + i++) { + + screen = graw_create_window_and_screen(0,0,WIDTH,HEIGHT, + formats[i], + &window); + } + + ctx = screen->context_create(screen, NULL); + if (ctx == NULL) + exit(3); + + templat.target = PIPE_TEXTURE_2D; + templat.format = formats[i]; + templat.width0 = WIDTH; + templat.height0 = HEIGHT; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET); + + rttex = screen->resource_create(screen, + &templat); + if (rttex == NULL) + exit(4); + + surf_tmpl.format = templat.format; + surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; + surf_tmpl.u.tex.level = 0; + surf_tmpl.u.tex.first_layer = 0; + surf_tmpl.u.tex.last_layer = 0; + surf = ctx->create_surface(ctx, rttex, &surf_tmpl); + if (surf == NULL) + exit(5); + + memset(&fb, 0, sizeof fb); + fb.nr_cbufs = 1; + fb.width = WIDTH; + fb.height = HEIGHT; + fb.cbufs[0] = surf; + + ctx->set_framebuffer_state(ctx, &fb); + + { + struct pipe_blend_state blend; + void *handle; + memset(&blend, 0, sizeof blend); + blend.rt[0].colormask = PIPE_MASK_RGBA; + handle = ctx->create_blend_state(ctx, &blend); + ctx->bind_blend_state(ctx, handle); + } + + { + struct pipe_depth_stencil_alpha_state depthstencil; + void *handle; + memset(&depthstencil, 0, sizeof depthstencil); + handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil); + ctx->bind_depth_stencil_alpha_state(ctx, handle); + } + + { + struct pipe_rasterizer_state rasterizer; + void *handle; + memset(&rasterizer, 0, sizeof rasterizer); + rasterizer.cull_face = PIPE_FACE_NONE; + rasterizer.gl_rasterization_rules = 1; + handle = ctx->create_rasterizer_state(ctx, &rasterizer); + ctx->bind_rasterizer_state(ctx, handle); + } + + set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000); + + init_tex(); + init_fs_constbuf(); + + set_vertices(); + set_vertex_shader(); + set_fragment_shader(filename); +} + +static void args(int argc, char *argv[]) +{ + int i; + + for (i = 1; i < argc;) { + if (graw_parse_args(&i, argc, argv)) { + continue; + } + if (strcmp(argv[i], "-fps") == 0) { + show_fps = 1; + i++; + } + else if (i == argc - 1) { + filename = argv[i]; + i++; + } + else { + usage(argv[0]); + exit(1); + } + } + + if (!filename) { + usage(argv[0]); + exit(1); + } +} + +int main( int argc, char *argv[] ) +{ + args(argc,argv); + init(); + + graw_set_display_func( draw ); + graw_main_loop(); + return 0; +} diff --git a/src/gallium/tests/graw/gs-test.c b/src/gallium/tests/graw/gs-test.c new file mode 100644 index 0000000..812666a --- /dev/null +++ b/src/gallium/tests/graw/gs-test.c @@ -0,0 +1,624 @@ +/* Display a cleared blue window. This demo has no dependencies on + * any utility code, just the graw interface and gallium. + */ + +#include "state_tracker/graw.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include /* for fread(), etc */ + +#include "util/u_inlines.h" +#include "util/u_memory.h" /* Offset() */ +#include "util/u_draw_quad.h" +#include "util/u_box.h" + +static const char *filename = NULL; +unsigned show_fps = 0; +unsigned draw_strip = 0; + + +static void usage(char *name) +{ + fprintf(stderr, "usage: %s [ options ] shader_filename\n", name); +#ifndef WIN32 + fprintf(stderr, "\n" ); + fprintf(stderr, "options:\n"); + fprintf(stderr, " -fps show frames per second\n"); + fprintf(stderr, " -strip renders a triangle strip\n"); +#endif +} + + +enum pipe_format formats[] = { + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_NONE +}; + +static const int WIDTH = 250; +static const int HEIGHT = 250; + +static struct pipe_screen *screen = NULL; +static struct pipe_context *ctx = NULL; +static struct pipe_resource *rttex = NULL; +static struct pipe_resource *constbuf1 = NULL; +static struct pipe_resource *constbuf2 = NULL; +static struct pipe_surface *surf = NULL; +static struct pipe_sampler_view *sv = NULL; +static void *sampler = NULL; +static void *window = NULL; +static struct pipe_resource *samptex = NULL; + +struct vertex { + float position[4]; + float color[4]; + float texcoord[4]; + float generic[4]; +}; + +/* Vertex data matches progs/fp/fp-tri.c, but flipped in Y dimension + * so that the final images are the same. + */ +static struct vertex vertices[] = +{ + { { 0.9, 0.9, 0.0, 1.0 }, + { 0, 0, 1, 1 }, + { 1, 1, 0, 1 }, + { 1, 0, 1, 0 } + }, + + { { 0.9, -0.9, 0.0, 1.0 }, + { 1, 0, 0, 1 }, + { 1, -1, 0, 1 }, + { 0, 1, 0, 1 } + }, + + { {-0.9, 0.0, 0.0, 1.0 }, + { 0, 1, 0, 1 }, + { -1, 0, 0, 1 }, + { 0, 0, 1, 1 } + }, +}; + +static struct vertex vertices_strip[] = +{ + { { 0.9, 0.9, 0.0, 1.0 }, + { 0, 0, 1, 1 }, + { 1, 1, 0, 1 }, + { 1, 0, 0, 1 } + }, + + { { 0.9, -0.9, 0.0, 1.0 }, + { 1, 0, 0, 1 }, + { 1, -1, 0, 1 }, + { 0, 1, 0, 1 } + }, + + { {-0.9, 0.9, 0.0, 1.0 }, + { 0, 1, 0, 1 }, + { -1, 1, 0, 1 }, + { 0, 0, 1, 1 } + }, + + { {-0.9, -0.9, 0.0, 1.0 }, + { 1, 1, 0, 1 }, + { -1, -1, 0, 1 }, + { 1, 1, 0, 1 } + }, +}; + +static float constants1[] = +{ 0.4, 0, 0, 1, + 1, 1, 1, 1, + 2, 2, 2, 2, + 4, 8, 16, 32, + + 3, 0, 0, 0, + 0, .5, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1, + + 1, 0, 0, 0.5, + 0, 1, 0, 0.5, + 0, 0, 1, 0, + 0, 0, 0, 1, +}; + + +static float constants2[] = +{ 1, 0, 0, 1, + 0, 1, 0, 1, + 0, 0, 1, 1, + 0, 0, 0, 1, + + 1, 1, 0, 1, + 1, .5, 0, 1, + 0, 1, 1, 1, + 1, 0, 1, 1, + + 1, 0, 0, 0.5, + 0, 1, 0, 0.5, + 0, 0, 1, 0, + 0, 0, 0, 1, +}; + + +static void init_fs_constbuf( void ) +{ + struct pipe_resource templat; + struct pipe_box box; + + templat.target = PIPE_BUFFER; + templat.format = PIPE_FORMAT_R8_UNORM; + templat.width0 = sizeof(constants1); + templat.height0 = 1; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = PIPE_BIND_CONSTANT_BUFFER; + + constbuf1 = screen->resource_create(screen, &templat); + if (constbuf1 == NULL) + exit(4); + constbuf2 = screen->resource_create(screen, &templat); + if (constbuf2 == NULL) + exit(4); + + { + u_box_2d(0,0,sizeof(constants1),1, &box); + + ctx->transfer_inline_write(ctx, + constbuf1, + 0, + PIPE_TRANSFER_WRITE, + &box, + constants1, + sizeof constants1, + sizeof constants1); + + + ctx->set_constant_buffer(ctx, + PIPE_SHADER_GEOMETRY, 0, + constbuf1); + } + { + u_box_2d(0,0,sizeof(constants2),1, &box); + + ctx->transfer_inline_write(ctx, + constbuf2, + 0, + PIPE_TRANSFER_WRITE, + &box, + constants2, + sizeof constants2, + sizeof constants2); + + + ctx->set_constant_buffer(ctx, + PIPE_SHADER_GEOMETRY, 1, + constbuf2); + } +} + + +static void set_viewport( float x, float y, + float width, float height, + float near, float far) +{ + float z = far; + float half_width = (float)width / 2.0f; + float half_height = (float)height / 2.0f; + float half_depth = ((float)far - (float)near) / 2.0f; + struct pipe_viewport_state vp; + + vp.scale[0] = half_width; + vp.scale[1] = half_height; + vp.scale[2] = half_depth; + vp.scale[3] = 1.0f; + + vp.translate[0] = half_width + x; + vp.translate[1] = half_height + y; + vp.translate[2] = half_depth + z; + vp.translate[3] = 0.0f; + + ctx->set_viewport_state( ctx, &vp ); +} + +static void set_vertices( void ) +{ + struct pipe_vertex_element ve[4]; + struct pipe_vertex_buffer vbuf; + void *handle; + + memset(ve, 0, sizeof ve); + + ve[0].src_offset = Offset(struct vertex, position); + ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + ve[1].src_offset = Offset(struct vertex, color); + ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + ve[2].src_offset = Offset(struct vertex, texcoord); + ve[2].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + ve[3].src_offset = Offset(struct vertex, generic); + ve[3].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + handle = ctx->create_vertex_elements_state(ctx, 4, ve); + ctx->bind_vertex_elements_state(ctx, handle); + + vbuf.stride = sizeof( struct vertex ); + vbuf.buffer_offset = 0; + if (draw_strip) { + vbuf.max_index = sizeof(vertices_strip) / vbuf.stride; + vbuf.buffer = screen->user_buffer_create(screen, + vertices_strip, + sizeof(vertices_strip), + PIPE_BIND_VERTEX_BUFFER); + } else { + vbuf.max_index = sizeof(vertices) / vbuf.stride; + vbuf.buffer = screen->user_buffer_create(screen, + vertices, + sizeof(vertices), + PIPE_BIND_VERTEX_BUFFER); + } + + ctx->set_vertex_buffers(ctx, 1, &vbuf); +} + +static void set_vertex_shader( void ) +{ + void *handle; + const char *text = + "VERT\n" + "DCL IN[0]\n" + "DCL IN[1]\n" + "DCL IN[2]\n" + "DCL IN[3]\n" + "DCL OUT[0], POSITION\n" + "DCL OUT[1], COLOR[0]\n" + "DCL OUT[2], GENERIC[0]\n" + "DCL OUT[3], GENERIC[1]\n" + " MOV OUT[0], IN[0]\n" + " MOV OUT[1], IN[1]\n" + " MOV OUT[2], IN[2]\n" + " MOV OUT[3], IN[3]\n" + " END\n"; + + handle = graw_parse_vertex_shader(ctx, text); + ctx->bind_vs_state(ctx, handle); +} + +static void set_fragment_shader( void ) +{ + void *handle; + const char *text = + "FRAG\n" + "DCL IN[0], COLOR, LINEAR\n" + "DCL OUT[0], COLOR\n" + " 0: MOV OUT[0], IN[0]\n" + " 1: END\n"; + + handle = graw_parse_fragment_shader(ctx, text); + ctx->bind_fs_state(ctx, handle); +} + + +static void set_geometry_shader( void ) +{ + FILE *f; + char buf[50000]; + void *handle; + int sz; + + if ((f = fopen(filename, "r")) == NULL) { + fprintf(stderr, "Couldn't open %s\n", filename); + exit(1); + } + + sz = fread(buf, 1, sizeof(buf), f); + if (!feof(f)) { + printf("file too long\n"); + exit(1); + } + printf("%.*s\n", sz, buf); + buf[sz] = 0; + + handle = graw_parse_geometry_shader(ctx, buf); + ctx->bind_gs_state(ctx, handle); + fclose(f); +} + + +static void draw( void ) +{ + float clear_color[4] = {.1,.3,.5,0}; + + ctx->clear(ctx, PIPE_CLEAR_COLOR, clear_color, 0, 0); + if (draw_strip) + util_draw_arrays(ctx, PIPE_PRIM_TRIANGLE_STRIP, 0, 4); + else + util_draw_arrays(ctx, PIPE_PRIM_TRIANGLES, 0, 3); + + ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL); + + graw_save_surface_to_file(ctx, surf, NULL); + + screen->flush_frontbuffer(screen, rttex, 0, 0, window); +} + +#define SIZE 16 + +static void init_tex( void ) +{ + struct pipe_sampler_view sv_template; + struct pipe_sampler_state sampler_desc; + struct pipe_resource templat; + struct pipe_box box; + ubyte tex2d[SIZE][SIZE][4]; + int s, t; + +#if (SIZE != 2) + for (s = 0; s < SIZE; s++) { + for (t = 0; t < SIZE; t++) { + if (0) { + int x = (s ^ t) & 1; + tex2d[t][s][0] = (x) ? 0 : 63; + tex2d[t][s][1] = (x) ? 0 : 128; + tex2d[t][s][2] = 0; + tex2d[t][s][3] = 0xff; + } + else { + int x = ((s ^ t) >> 2) & 1; + tex2d[t][s][0] = s*255/(SIZE-1); + tex2d[t][s][1] = t*255/(SIZE-1); + tex2d[t][s][2] = (x) ? 0 : 128; + tex2d[t][s][3] = 0xff; + } + } + } +#else + tex2d[0][0][0] = 0; + tex2d[0][0][1] = 255; + tex2d[0][0][2] = 255; + tex2d[0][0][3] = 0; + + tex2d[0][1][0] = 0; + tex2d[0][1][1] = 0; + tex2d[0][1][2] = 255; + tex2d[0][1][3] = 255; + + tex2d[1][0][0] = 255; + tex2d[1][0][1] = 255; + tex2d[1][0][2] = 0; + tex2d[1][0][3] = 255; + + tex2d[1][1][0] = 255; + tex2d[1][1][1] = 0; + tex2d[1][1][2] = 0; + tex2d[1][1][3] = 255; +#endif + + templat.target = PIPE_TEXTURE_2D; + templat.format = PIPE_FORMAT_B8G8R8A8_UNORM; + templat.width0 = SIZE; + templat.height0 = SIZE; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = PIPE_BIND_SAMPLER_VIEW; + + + samptex = screen->resource_create(screen, + &templat); + if (samptex == NULL) + exit(4); + + u_box_2d(0,0,SIZE,SIZE, &box); + + ctx->transfer_inline_write(ctx, + samptex, + 0, + PIPE_TRANSFER_WRITE, + &box, + tex2d, + sizeof tex2d[0], + sizeof tex2d); + + /* Possibly read back & compare against original data: + */ + if (0) + { + struct pipe_transfer *t; + uint32_t *ptr; + t = pipe_get_transfer(ctx, samptex, + 0, 0, /* level, layer */ + PIPE_TRANSFER_READ, + 0, 0, SIZE, SIZE); /* x, y, width, height */ + + ptr = ctx->transfer_map(ctx, t); + + if (memcmp(ptr, tex2d, sizeof tex2d) != 0) { + assert(0); + exit(9); + } + + ctx->transfer_unmap(ctx, t); + + ctx->transfer_destroy(ctx, t); + } + + memset(&sv_template, 0, sizeof sv_template); + sv_template.format = samptex->format; + sv_template.texture = samptex; + sv_template.swizzle_r = 0; + sv_template.swizzle_g = 1; + sv_template.swizzle_b = 2; + sv_template.swizzle_a = 3; + sv = ctx->create_sampler_view(ctx, samptex, &sv_template); + if (sv == NULL) + exit(5); + + ctx->set_fragment_sampler_views(ctx, 1, &sv); + + + memset(&sampler_desc, 0, sizeof sampler_desc); + sampler_desc.wrap_s = PIPE_TEX_WRAP_REPEAT; + sampler_desc.wrap_t = PIPE_TEX_WRAP_REPEAT; + sampler_desc.wrap_r = PIPE_TEX_WRAP_REPEAT; + sampler_desc.min_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler_desc.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + sampler_desc.mag_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler_desc.compare_mode = PIPE_TEX_COMPARE_NONE; + sampler_desc.compare_func = 0; + sampler_desc.normalized_coords = 1; + sampler_desc.max_anisotropy = 0; + + sampler = ctx->create_sampler_state(ctx, &sampler_desc); + if (sampler == NULL) + exit(6); + + ctx->bind_fragment_sampler_states(ctx, 1, &sampler); + +} + +static void init( void ) +{ + struct pipe_framebuffer_state fb; + struct pipe_resource templat; + struct pipe_surface surf_tmpl; + int i; + + /* It's hard to say whether window or screen should be created + * first. Different environments would prefer one or the other. + * + * Also, no easy way of querying supported formats if the screen + * cannot be created first. + */ + for (i = 0; + window == NULL && formats[i] != PIPE_FORMAT_NONE; + i++) { + + screen = graw_create_window_and_screen(0,0,WIDTH,HEIGHT, + formats[i], + &window); + } + + ctx = screen->context_create(screen, NULL); + if (ctx == NULL) + exit(3); + + templat.target = PIPE_TEXTURE_2D; + templat.format = formats[i]; + templat.width0 = WIDTH; + templat.height0 = HEIGHT; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET); + + rttex = screen->resource_create(screen, + &templat); + if (rttex == NULL) + exit(4); + + surf_tmpl.format = templat.format; + surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; + surf_tmpl.u.tex.level = 0; + surf_tmpl.u.tex.first_layer = 0; + surf_tmpl.u.tex.last_layer = 0; + surf = ctx->create_surface(ctx, rttex, &surf_tmpl); + if (surf == NULL) + exit(5); + + memset(&fb, 0, sizeof fb); + fb.nr_cbufs = 1; + fb.width = WIDTH; + fb.height = HEIGHT; + fb.cbufs[0] = surf; + + ctx->set_framebuffer_state(ctx, &fb); + + { + struct pipe_blend_state blend; + void *handle; + memset(&blend, 0, sizeof blend); + blend.rt[0].colormask = PIPE_MASK_RGBA; + handle = ctx->create_blend_state(ctx, &blend); + ctx->bind_blend_state(ctx, handle); + } + + { + struct pipe_depth_stencil_alpha_state depthstencil; + void *handle; + memset(&depthstencil, 0, sizeof depthstencil); + handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil); + ctx->bind_depth_stencil_alpha_state(ctx, handle); + } + + { + struct pipe_rasterizer_state rasterizer; + void *handle; + memset(&rasterizer, 0, sizeof rasterizer); + rasterizer.cull_face = PIPE_FACE_NONE; + rasterizer.gl_rasterization_rules = 1; + handle = ctx->create_rasterizer_state(ctx, &rasterizer); + ctx->bind_rasterizer_state(ctx, handle); + } + + set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000); + + init_tex(); + init_fs_constbuf(); + + set_vertices(); + set_vertex_shader(); + set_fragment_shader(); + set_geometry_shader(); +} + +static void args(int argc, char *argv[]) +{ + int i; + + for (i = 1; i < argc;) { + if (graw_parse_args(&i, argc, argv)) { + continue; + } + if (strcmp(argv[i], "-fps") == 0) { + show_fps = 1; + i++; + } + else if (strcmp(argv[i], "-strip") == 0) { + draw_strip = 1; + i++; + } + else if (i == argc - 1) { + filename = argv[i]; + i++; + } + else { + usage(argv[0]); + exit(1); + } + } + + if (!filename) { + usage(argv[0]); + exit(1); + } +} + +int main( int argc, char *argv[] ) +{ + args(argc,argv); + init(); + + graw_set_display_func( draw ); + graw_main_loop(); + return 0; +} diff --git a/src/gallium/tests/graw/quad-tex.c b/src/gallium/tests/graw/quad-tex.c new file mode 100644 index 0000000..952131d --- /dev/null +++ b/src/gallium/tests/graw/quad-tex.c @@ -0,0 +1,408 @@ +/* Display a cleared blue window. This demo has no dependencies on + * any utility code, just the graw interface and gallium. + */ + +#include "state_tracker/graw.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" + +#include "util/u_inlines.h" +#include "util/u_memory.h" /* Offset() */ +#include "util/u_draw_quad.h" +#include "util/u_box.h" + +enum pipe_format formats[] = { + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_NONE +}; + +static const int WIDTH = 300; +static const int HEIGHT = 300; + +static struct pipe_screen *screen = NULL; +static struct pipe_context *ctx = NULL; +static struct pipe_resource *rttex = NULL; +static struct pipe_resource *samptex = NULL; +static struct pipe_surface *surf = NULL; +static struct pipe_sampler_view *sv = NULL; +static void *sampler = NULL; +static void *window = NULL; + +struct vertex { + float position[4]; + float color[4]; +}; + +static struct vertex vertices[] = +{ + { { 0.9, -0.9, 0.0, 1.0 }, + { 1, 0, 0, 1 } }, + + { { 0.9, 0.9, 0.0, 1.0 }, + { 1, 1, 0, 1 } }, + + { {-0.9, 0.9, 0.0, 1.0 }, + { 0, 1, 0, 1 } }, + + { {-0.9, -0.9, 0.0, 1.0 }, + { 0, 0, 0, 1 } }, +}; + + + + +static void set_viewport( float x, float y, + float width, float height, + float near, float far) +{ + float z = far; + float half_width = (float)width / 2.0f; + float half_height = (float)height / 2.0f; + float half_depth = ((float)far - (float)near) / 2.0f; + struct pipe_viewport_state vp; + + vp.scale[0] = half_width; + vp.scale[1] = half_height; + vp.scale[2] = half_depth; + vp.scale[3] = 1.0f; + + vp.translate[0] = half_width + x; + vp.translate[1] = half_height + y; + vp.translate[2] = half_depth + z; + vp.translate[3] = 0.0f; + + ctx->set_viewport_state( ctx, &vp ); +} + +static void set_vertices( void ) +{ + struct pipe_vertex_element ve[2]; + struct pipe_vertex_buffer vbuf; + void *handle; + + memset(ve, 0, sizeof ve); + + ve[0].src_offset = Offset(struct vertex, position); + ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + ve[1].src_offset = Offset(struct vertex, color); + ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + handle = ctx->create_vertex_elements_state(ctx, 2, ve); + ctx->bind_vertex_elements_state(ctx, handle); + + + vbuf.stride = sizeof( struct vertex ); + vbuf.max_index = sizeof(vertices) / vbuf.stride; + vbuf.buffer_offset = 0; + vbuf.buffer = screen->user_buffer_create(screen, + vertices, + sizeof(vertices), + PIPE_BIND_VERTEX_BUFFER); + + ctx->set_vertex_buffers(ctx, 1, &vbuf); +} + +static void set_vertex_shader( void ) +{ + void *handle; + const char *text = + "VERT\n" + "DCL IN[0]\n" + "DCL IN[1]\n" + "DCL OUT[0], POSITION\n" + "DCL OUT[1], GENERIC[0]\n" + " 0: MOV OUT[1], IN[1]\n" + " 1: MOV OUT[0], IN[0]\n" + " 2: END\n"; + + handle = graw_parse_vertex_shader(ctx, text); + ctx->bind_vs_state(ctx, handle); +} + +static void set_fragment_shader( void ) +{ + void *handle; + const char *text = + "FRAG\n" + "DCL IN[0], GENERIC[0], PERSPECTIVE\n" + "DCL OUT[0], COLOR\n" + "DCL TEMP[0]\n" + "DCL SAMP[0]\n" + " 0: TXP TEMP[0], IN[0], SAMP[0], 2D\n" + " 1: MOV OUT[0], TEMP[0]\n" + " 2: END\n"; + + handle = graw_parse_fragment_shader(ctx, text); + ctx->bind_fs_state(ctx, handle); +} + + +static void draw( void ) +{ + float clear_color[4] = {.5,.5,.5,1}; + + ctx->clear(ctx, PIPE_CLEAR_COLOR, clear_color, 0, 0); + util_draw_arrays(ctx, PIPE_PRIM_QUADS, 0, 4); + ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL); + + graw_save_surface_to_file(ctx, surf, NULL); + + screen->flush_frontbuffer(screen, rttex, 0, 0, window); +} + +#define SIZE 16 + +static void init_tex( void ) +{ + struct pipe_sampler_view sv_template; + struct pipe_sampler_state sampler_desc; + struct pipe_resource templat; + struct pipe_box box; + ubyte tex2d[SIZE][SIZE][4]; + int s, t; + +#if (SIZE != 2) + for (s = 0; s < SIZE; s++) { + for (t = 0; t < SIZE; t++) { + if (0) { + int x = (s ^ t) & 1; + tex2d[t][s][0] = (x) ? 0 : 63; + tex2d[t][s][1] = (x) ? 0 : 128; + tex2d[t][s][2] = 0; + tex2d[t][s][3] = 0xff; + } + else { + int x = ((s ^ t) >> 2) & 1; + tex2d[t][s][0] = s*255/(SIZE-1); + tex2d[t][s][1] = t*255/(SIZE-1); + tex2d[t][s][2] = (x) ? 0 : 128; + tex2d[t][s][3] = 0xff; + } + } + } +#else + tex2d[0][0][0] = 0; + tex2d[0][0][1] = 255; + tex2d[0][0][2] = 255; + tex2d[0][0][3] = 0; + + tex2d[0][1][0] = 0; + tex2d[0][1][1] = 0; + tex2d[0][1][2] = 255; + tex2d[0][1][3] = 255; + + tex2d[1][0][0] = 255; + tex2d[1][0][1] = 255; + tex2d[1][0][2] = 0; + tex2d[1][0][3] = 255; + + tex2d[1][1][0] = 255; + tex2d[1][1][1] = 0; + tex2d[1][1][2] = 0; + tex2d[1][1][3] = 255; +#endif + + templat.target = PIPE_TEXTURE_2D; + templat.format = PIPE_FORMAT_B8G8R8A8_UNORM; + templat.width0 = SIZE; + templat.height0 = SIZE; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = PIPE_BIND_SAMPLER_VIEW; + + + samptex = screen->resource_create(screen, + &templat); + if (samptex == NULL) + exit(4); + + u_box_2d(0,0,SIZE,SIZE, &box); + + ctx->transfer_inline_write(ctx, + samptex, + 0, + PIPE_TRANSFER_WRITE, + &box, + tex2d, + sizeof tex2d[0], + sizeof tex2d); + + /* Possibly read back & compare against original data: + */ + if (0) + { + struct pipe_transfer *t; + uint32_t *ptr; + t = pipe_get_transfer(ctx, samptex, + 0, 0, /* level, layer */ + PIPE_TRANSFER_READ, + 0, 0, SIZE, SIZE); /* x, y, width, height */ + + ptr = ctx->transfer_map(ctx, t); + + if (memcmp(ptr, tex2d, sizeof tex2d) != 0) { + assert(0); + exit(9); + } + + ctx->transfer_unmap(ctx, t); + + ctx->transfer_destroy(ctx, t); + } + + memset(&sv_template, 0, sizeof sv_template); + sv_template.format = samptex->format; + sv_template.texture = samptex; + sv_template.swizzle_r = 0; + sv_template.swizzle_g = 1; + sv_template.swizzle_b = 2; + sv_template.swizzle_a = 3; + sv = ctx->create_sampler_view(ctx, samptex, &sv_template); + if (sv == NULL) + exit(5); + + ctx->set_fragment_sampler_views(ctx, 1, &sv); + + + memset(&sampler_desc, 0, sizeof sampler_desc); + sampler_desc.wrap_s = PIPE_TEX_WRAP_REPEAT; + sampler_desc.wrap_t = PIPE_TEX_WRAP_REPEAT; + sampler_desc.wrap_r = PIPE_TEX_WRAP_REPEAT; + sampler_desc.min_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler_desc.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + sampler_desc.mag_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler_desc.compare_mode = PIPE_TEX_COMPARE_NONE; + sampler_desc.compare_func = 0; + sampler_desc.normalized_coords = 1; + sampler_desc.max_anisotropy = 0; + + sampler = ctx->create_sampler_state(ctx, &sampler_desc); + if (sampler == NULL) + exit(6); + + ctx->bind_fragment_sampler_states(ctx, 1, &sampler); + +} + +static void init( void ) +{ + struct pipe_framebuffer_state fb; + struct pipe_resource templat; + struct pipe_surface surf_tmpl; + int i; + + /* It's hard to say whether window or screen should be created + * first. Different environments would prefer one or the other. + * + * Also, no easy way of querying supported formats if the screen + * cannot be created first. + */ + for (i = 0; + window == NULL && formats[i] != PIPE_FORMAT_NONE; + i++) { + + screen = graw_create_window_and_screen(0,0,300,300, + formats[i], + &window); + } + + ctx = screen->context_create(screen, NULL); + if (ctx == NULL) + exit(3); + + templat.target = PIPE_TEXTURE_2D; + templat.format = formats[i]; + templat.width0 = WIDTH; + templat.height0 = HEIGHT; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET); + + rttex = screen->resource_create(screen, + &templat); + if (rttex == NULL) + exit(4); + + surf_tmpl.format = templat.format; + surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; + surf_tmpl.u.tex.level = 0; + surf_tmpl.u.tex.first_layer = 0; + surf_tmpl.u.tex.last_layer = 0; + surf = ctx->create_surface(ctx, rttex, &surf_tmpl); + if (surf == NULL) + exit(5); + + memset(&fb, 0, sizeof fb); + fb.nr_cbufs = 1; + fb.width = WIDTH; + fb.height = HEIGHT; + fb.cbufs[0] = surf; + + ctx->set_framebuffer_state(ctx, &fb); + + { + struct pipe_blend_state blend; + void *handle; + memset(&blend, 0, sizeof blend); + blend.rt[0].colormask = PIPE_MASK_RGBA; + handle = ctx->create_blend_state(ctx, &blend); + ctx->bind_blend_state(ctx, handle); + } + + { + struct pipe_depth_stencil_alpha_state depthstencil; + void *handle; + memset(&depthstencil, 0, sizeof depthstencil); + handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil); + ctx->bind_depth_stencil_alpha_state(ctx, handle); + } + + { + struct pipe_rasterizer_state rasterizer; + void *handle; + memset(&rasterizer, 0, sizeof rasterizer); + rasterizer.cull_face = PIPE_FACE_NONE; + rasterizer.gl_rasterization_rules = 1; + handle = ctx->create_rasterizer_state(ctx, &rasterizer); + ctx->bind_rasterizer_state(ctx, handle); + } + + set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000); + + init_tex(); + + set_vertices(); + set_vertex_shader(); + set_fragment_shader(); +} + +static void args(int argc, char *argv[]) +{ + int i; + + for (i = 1; i < argc;) { + if (graw_parse_args(&i, argc, argv)) { + continue; + } + exit(1); + } +} + +int main( int argc, char *argv[] ) +{ + args(argc, argv); + init(); + + graw_set_display_func( draw ); + graw_main_loop(); + return 0; +} diff --git a/src/gallium/tests/graw/shader-leak.c b/src/gallium/tests/graw/shader-leak.c new file mode 100644 index 0000000..b53f0a0 --- /dev/null +++ b/src/gallium/tests/graw/shader-leak.c @@ -0,0 +1,272 @@ +/** + * Create shaders in a loop to test memory usage. + */ + +#include +#include "state_tracker/graw.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" + +#include "util/u_memory.h" /* Offset() */ +#include "util/u_draw_quad.h" + + +static int num_iters = 100; + + +enum pipe_format formats[] = { + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_NONE +}; + +static const int WIDTH = 300; +static const int HEIGHT = 300; + +static struct pipe_screen *screen = NULL; +static struct pipe_context *ctx = NULL; +static struct pipe_surface *surf = NULL; +static struct pipe_resource *tex = NULL; +static void *window = NULL; + +struct vertex { + float position[4]; + float color[4]; +}; + +static struct vertex vertices[1] = +{ + { + { 0.0f, -0.9f, 0.0f, 1.0f }, + { 1.0f, 0.0f, 0.0f, 1.0f } + } +}; + + + + +static void set_viewport( float x, float y, + float width, float height, + float near, float far) +{ + float z = far; + float half_width = (float)width / 2.0f; + float half_height = (float)height / 2.0f; + float half_depth = ((float)far - (float)near) / 2.0f; + struct pipe_viewport_state vp; + + vp.scale[0] = half_width; + vp.scale[1] = half_height; + vp.scale[2] = half_depth; + vp.scale[3] = 1.0f; + + vp.translate[0] = half_width + x; + vp.translate[1] = half_height + y; + vp.translate[2] = half_depth + z; + vp.translate[3] = 0.0f; + + ctx->set_viewport_state( ctx, &vp ); +} + +static void set_vertices( void ) +{ + struct pipe_vertex_element ve[2]; + struct pipe_vertex_buffer vbuf; + void *handle; + + memset(ve, 0, sizeof ve); + + ve[0].src_offset = Offset(struct vertex, position); + ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + ve[1].src_offset = Offset(struct vertex, color); + ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + handle = ctx->create_vertex_elements_state(ctx, 2, ve); + ctx->bind_vertex_elements_state(ctx, handle); + + + vbuf.stride = sizeof(struct vertex); + vbuf.max_index = sizeof(vertices) / vbuf.stride; + vbuf.buffer_offset = 0; + vbuf.buffer = screen->user_buffer_create(screen, + vertices, + sizeof(vertices), + PIPE_BIND_VERTEX_BUFFER); + + ctx->set_vertex_buffers(ctx, 1, &vbuf); +} + +static void set_vertex_shader( void ) +{ + void *handle; + const char *text = + "VERT\n" + "DCL IN[0]\n" + "DCL IN[1]\n" + "DCL OUT[0], POSITION\n" + "DCL OUT[1], COLOR\n" + " 0: MOV OUT[1], IN[1]\n" + " 1: MOV OUT[0], IN[0]\n" + " 2: END\n"; + + handle = graw_parse_vertex_shader(ctx, text); + ctx->bind_vs_state(ctx, handle); +} + + + +static void * +set_fragment_shader( void ) +{ + void *handle; + const char *text = + "FRAG\n" + "DCL IN[0], COLOR, LINEAR\n" + "DCL OUT[0], COLOR\n" + "DCL TEMP[0..1]\n" + " 0: MUL TEMP[0], IN[0], IN[0]\n" + " 1: ADD TEMP[1], IN[0], IN[0]\n" + " 2: SUB OUT[0], TEMP[0], TEMP[1]\n" + " 3: END\n"; + + handle = graw_parse_fragment_shader(ctx, text); + return handle; +} + + +static void draw( void ) +{ + float clear_color[4] = {0, 0, 0, 1}; + int i; + + printf("Creating %d shaders\n", num_iters); + + for (i = 0; i < num_iters; i++) { + void *fs = set_fragment_shader(); + + ctx->bind_fs_state(ctx, fs); + + ctx->clear(ctx, PIPE_CLEAR_COLOR, clear_color, 0, 0); + util_draw_arrays(ctx, PIPE_PRIM_POINTS, 0, 1); + ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL); + + ctx->bind_fs_state(ctx, NULL); + ctx->delete_fs_state(ctx, fs); + } + + screen->flush_frontbuffer(screen, tex, 0, 0, window); + ctx->destroy(ctx); + + exit(0); +} + + +static void init( void ) +{ + struct pipe_framebuffer_state fb; + struct pipe_resource templat; + struct pipe_surface surf_tmpl; + int i; + + /* It's hard to say whether window or screen should be created + * first. Different environments would prefer one or the other. + * + * Also, no easy way of querying supported formats if the screen + * cannot be created first. + */ + for (i = 0; + window == NULL && formats[i] != PIPE_FORMAT_NONE; + i++) { + + screen = graw_create_window_and_screen(0,0,300,300, + formats[i], + &window); + } + + ctx = screen->context_create(screen, NULL); + if (ctx == NULL) + exit(3); + + templat.target = PIPE_TEXTURE_2D; + templat.format = formats[i]; + templat.width0 = WIDTH; + templat.height0 = HEIGHT; + templat.depth0 = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET); + + tex = screen->resource_create(screen, &templat); + if (tex == NULL) { + fprintf(stderr, "Unable to create screen texture!\n"); + exit(4); + } + + surf_tmpl.format = templat.format; + surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; + surf_tmpl.u.tex.level = 0; + surf_tmpl.u.tex.first_layer = 0; + surf_tmpl.u.tex.last_layer = 0; + surf = ctx->create_surface(ctx, tex, &surf_tmpl); + if (surf == NULL) { + fprintf(stderr, "Unable to create tex surface!\n"); + exit(5); + } + + memset(&fb, 0, sizeof fb); + fb.nr_cbufs = 1; + fb.width = WIDTH; + fb.height = HEIGHT; + fb.cbufs[0] = surf; + + ctx->set_framebuffer_state(ctx, &fb); + + { + struct pipe_blend_state blend; + void *handle; + memset(&blend, 0, sizeof blend); + blend.rt[0].colormask = PIPE_MASK_RGBA; + handle = ctx->create_blend_state(ctx, &blend); + ctx->bind_blend_state(ctx, handle); + } + + { + struct pipe_depth_stencil_alpha_state depthstencil; + void *handle; + memset(&depthstencil, 0, sizeof depthstencil); + handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil); + ctx->bind_depth_stencil_alpha_state(ctx, handle); + } + + { + struct pipe_rasterizer_state rasterizer; + void *handle; + memset(&rasterizer, 0, sizeof rasterizer); + rasterizer.cull_face = PIPE_FACE_NONE; + rasterizer.gl_rasterization_rules = 1; + handle = ctx->create_rasterizer_state(ctx, &rasterizer); + ctx->bind_rasterizer_state(ctx, handle); + } + + set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000); + set_vertices(); + set_vertex_shader(); + if (0) + set_fragment_shader(); +} + + +int main( int argc, char *argv[] ) +{ + if (argc > 1) + num_iters = atoi(argv[1]); + + init(); + + graw_set_display_func( draw ); + graw_main_loop(); + return 0; +} diff --git a/src/gallium/tests/graw/tri-gs.c b/src/gallium/tests/graw/tri-gs.c new file mode 100644 index 0000000..84ff3e6 --- /dev/null +++ b/src/gallium/tests/graw/tri-gs.c @@ -0,0 +1,273 @@ +/* Display a cleared blue window. This demo has no dependencies on + * any utility code, just the graw interface and gallium. + */ + +#include "state_tracker/graw.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" + +#include "util/u_memory.h" /* Offset() */ +#include "util/u_draw_quad.h" + +enum pipe_format formats[] = { + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_NONE +}; + +static const int WIDTH = 300; +static const int HEIGHT = 300; + +static struct pipe_screen *screen = NULL; +static struct pipe_context *ctx = NULL; +static struct pipe_surface *surf = NULL; +static struct pipe_resource *tex = NULL; +static void *window = NULL; + +struct vertex { + float position[4]; + float color[4]; +}; + +static struct vertex vertices[4] = +{ + { { 0.0f, -0.9f, 0.0f, 1.0f }, + { 1.0f, 0.0f, 0.0f, 1.0f } + }, + { { -0.9f, 0.9f, 0.0f, 1.0f }, + { 0.0f, 1.0f, 0.0f, 1.0f } + }, + { { 0.9f, 0.9f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f, 1.0f } + } +}; + + + + +static void set_viewport( float x, float y, + float width, float height, + float near, float far) +{ + float z = far; + float half_width = (float)width / 2.0f; + float half_height = (float)height / 2.0f; + float half_depth = ((float)far - (float)near) / 2.0f; + struct pipe_viewport_state vp; + + vp.scale[0] = half_width; + vp.scale[1] = half_height; + vp.scale[2] = half_depth; + vp.scale[3] = 1.0f; + + vp.translate[0] = half_width + x; + vp.translate[1] = half_height + y; + vp.translate[2] = half_depth + z; + vp.translate[3] = 0.0f; + + ctx->set_viewport_state( ctx, &vp ); +} + +static void set_vertices( void ) +{ + struct pipe_vertex_element ve[2]; + struct pipe_vertex_buffer vbuf; + void *handle; + + memset(ve, 0, sizeof ve); + + ve[0].src_offset = Offset(struct vertex, position); + ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + ve[1].src_offset = Offset(struct vertex, color); + ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + handle = ctx->create_vertex_elements_state(ctx, 2, ve); + ctx->bind_vertex_elements_state(ctx, handle); + + + vbuf.stride = sizeof( struct vertex ); + vbuf.max_index = sizeof(vertices) / vbuf.stride; + vbuf.buffer_offset = 0; + vbuf.buffer = screen->user_buffer_create(screen, + vertices, + sizeof(vertices), + PIPE_BIND_VERTEX_BUFFER); + + ctx->set_vertex_buffers(ctx, 1, &vbuf); +} + +static void set_vertex_shader( void ) +{ + void *handle; + const char *text = + "VERT\n" + "DCL IN[0]\n" + "DCL IN[1]\n" + "DCL OUT[0], POSITION\n" + "DCL OUT[1], COLOR\n" + " 0: MOV OUT[1], IN[1]\n" + " 1: MOV OUT[0], IN[0]\n" + " 2: END\n"; + + handle = graw_parse_vertex_shader(ctx, text); + ctx->bind_vs_state(ctx, handle); +} + +static void set_fragment_shader( void ) +{ + void *handle; + const char *text = + "FRAG\n" + "DCL IN[0], COLOR, LINEAR\n" + "DCL OUT[0], COLOR\n" + " 0: MOV OUT[0], IN[0]\n" + " 1: END\n"; + + handle = graw_parse_fragment_shader(ctx, text); + ctx->bind_fs_state(ctx, handle); +} + + +static void set_geometry_shader( void ) +{ + void *handle; + const char *text = + "GEOM\n" + "PROPERTY GS_INPUT_PRIMITIVE TRIANGLES\n" + "PROPERTY GS_OUTPUT_PRIMITIVE TRIANGLE_STRIP\n" + "DCL IN[][0], POSITION, CONSTANT\n" + "DCL IN[][1], COLOR, CONSTANT\n" + "DCL OUT[0], POSITION, CONSTANT\n" + "DCL OUT[1], COLOR, CONSTANT\n" + "0:MOV OUT[0], IN[0][0]\n" + "1:MOV OUT[1], IN[0][1]\n" + "2:EMIT\n" + "3:MOV OUT[0], IN[1][0]\n" + "4:MOV OUT[1], IN[0][1]\n" /* copy color from input vertex 0 */ + "5:EMIT\n" + "6:MOV OUT[0], IN[2][0]\n" + "7:MOV OUT[1], IN[2][1]\n" + "8:EMIT\n" + "9:ENDPRIM\n" + "10:END\n"; + + handle = graw_parse_geometry_shader(ctx, text); + ctx->bind_gs_state(ctx, handle); +} + +static void draw( void ) +{ + float clear_color[4] = {1,0,1,1}; + + ctx->clear(ctx, PIPE_CLEAR_COLOR, clear_color, 0, 0); + util_draw_arrays(ctx, PIPE_PRIM_TRIANGLES, 0, 3); + ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL); + + screen->flush_frontbuffer(screen, tex, 0, 0, window); +} + + +static void init( void ) +{ + struct pipe_framebuffer_state fb; + struct pipe_resource templat; + struct pipe_surface surf_tmpl; + int i; + + /* It's hard to say whether window or screen should be created + * first. Different environments would prefer one or the other. + * + * Also, no easy way of querying supported formats if the screen + * cannot be created first. + */ + for (i = 0; + window == NULL && formats[i] != PIPE_FORMAT_NONE; + i++) { + + screen = graw_create_window_and_screen(0,0,300,300, + formats[i], + &window); + } + + ctx = screen->context_create(screen, NULL); + if (ctx == NULL) + exit(3); + + templat.target = PIPE_TEXTURE_2D; + templat.format = formats[i]; + templat.width0 = WIDTH; + templat.height0 = HEIGHT; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET); + + tex = screen->resource_create(screen, + &templat); + if (tex == NULL) + exit(4); + + surf_tmpl.format = templat.format; + surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; + surf_tmpl.u.tex.level = 0; + surf_tmpl.u.tex.first_layer = 0; + surf_tmpl.u.tex.last_layer = 0; + surf = ctx->create_surface(ctx, tex, &surf_tmpl); + if (surf == NULL) + exit(5); + + memset(&fb, 0, sizeof fb); + fb.nr_cbufs = 1; + fb.width = WIDTH; + fb.height = HEIGHT; + fb.cbufs[0] = surf; + + ctx->set_framebuffer_state(ctx, &fb); + + { + struct pipe_blend_state blend; + void *handle; + memset(&blend, 0, sizeof blend); + blend.rt[0].colormask = PIPE_MASK_RGBA; + handle = ctx->create_blend_state(ctx, &blend); + ctx->bind_blend_state(ctx, handle); + } + + { + struct pipe_depth_stencil_alpha_state depthstencil; + void *handle; + memset(&depthstencil, 0, sizeof depthstencil); + handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil); + ctx->bind_depth_stencil_alpha_state(ctx, handle); + } + + { + struct pipe_rasterizer_state rasterizer; + void *handle; + memset(&rasterizer, 0, sizeof rasterizer); + rasterizer.cull_face = PIPE_FACE_NONE; + rasterizer.gl_rasterization_rules = 1; + handle = ctx->create_rasterizer_state(ctx, &rasterizer); + ctx->bind_rasterizer_state(ctx, handle); + } + + set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000); + set_vertices(); + set_vertex_shader(); + set_fragment_shader(); + set_geometry_shader(); +} + + +int main( int argc, char *argv[] ) +{ + init(); + + graw_set_display_func( draw ); + graw_main_loop(); + return 0; +} diff --git a/src/gallium/tests/graw/tri-instanced.c b/src/gallium/tests/graw/tri-instanced.c new file mode 100644 index 0000000..f33c061 --- /dev/null +++ b/src/gallium/tests/graw/tri-instanced.c @@ -0,0 +1,349 @@ +/* + * Test draw instancing. + */ + +#include +#include + +#include "state_tracker/graw.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" + +#include "util/u_memory.h" /* Offset() */ +#include "util/u_draw_quad.h" + + +enum pipe_format formats[] = { + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_NONE +}; + +static const int WIDTH = 300; +static const int HEIGHT = 300; + +static struct pipe_screen *screen = NULL; +static struct pipe_context *ctx = NULL; +static struct pipe_surface *surf = NULL; +static struct pipe_resource *tex = NULL; +static void *window = NULL; + +struct vertex { + float position[4]; + float color[4]; +}; + + +static int draw_elements = 0; + + +/** + * Vertex data. + * Each vertex has three attributes: position, color and translation. + * The translation attribute is a per-instance attribute. See + * "instance_divisor" below. + */ +static struct vertex vertices[4] = +{ + { + { 0.0f, -0.3f, 0.0f, 1.0f }, /* pos */ + { 1.0f, 0.0f, 0.0f, 1.0f } /* color */ + }, + { + { -0.2f, 0.3f, 0.0f, 1.0f }, + { 0.0f, 1.0f, 0.0f, 1.0f } + }, + { + { 0.2f, 0.3f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f, 1.0f } + } +}; + + +#define NUM_INST 5 + +static float inst_data[NUM_INST][4] = +{ + { -0.50f, 0.4f, 0.0f, 0.0f }, + { -0.25f, 0.1f, 0.0f, 0.0f }, + { 0.00f, 0.2f, 0.0f, 0.0f }, + { 0.25f, 0.1f, 0.0f, 0.0f }, + { 0.50f, 0.3f, 0.0f, 0.0f } +}; + + +static ushort indices[3] = { 0, 2, 1 }; + + +static void set_viewport( float x, float y, + float width, float height, + float near, float far) +{ + float z = far; + float half_width = (float)width / 2.0f; + float half_height = (float)height / 2.0f; + float half_depth = ((float)far - (float)near) / 2.0f; + struct pipe_viewport_state vp; + + vp.scale[0] = half_width; + vp.scale[1] = half_height; + vp.scale[2] = half_depth; + vp.scale[3] = 1.0f; + + vp.translate[0] = half_width + x; + vp.translate[1] = half_height + y; + vp.translate[2] = half_depth + z; + vp.translate[3] = 0.0f; + + ctx->set_viewport_state( ctx, &vp ); +} + + +static void set_vertices( void ) +{ + struct pipe_vertex_element ve[3]; + struct pipe_vertex_buffer vbuf[2]; + struct pipe_index_buffer ibuf; + void *handle; + + memset(ve, 0, sizeof ve); + + /* pos */ + ve[0].src_offset = Offset(struct vertex, position); + ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + ve[0].vertex_buffer_index = 0; + + /* color */ + ve[1].src_offset = Offset(struct vertex, color); + ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + ve[1].vertex_buffer_index = 0; + + /* per-instance info */ + ve[2].src_offset = 0; + ve[2].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + ve[2].vertex_buffer_index = 1; + ve[2].instance_divisor = 1; + + handle = ctx->create_vertex_elements_state(ctx, 3, ve); + ctx->bind_vertex_elements_state(ctx, handle); + + + /* vertex data */ + vbuf[0].stride = sizeof( struct vertex ); + vbuf[0].max_index = sizeof(vertices) / vbuf[0].stride; + vbuf[0].buffer_offset = 0; + vbuf[0].buffer = screen->user_buffer_create(screen, + vertices, + sizeof(vertices), + PIPE_BIND_VERTEX_BUFFER); + + /* instance data */ + vbuf[1].stride = sizeof( inst_data[0] ); + vbuf[1].max_index = sizeof(inst_data) / vbuf[1].stride; + vbuf[1].buffer_offset = 0; + vbuf[1].buffer = screen->user_buffer_create(screen, + inst_data, + sizeof(inst_data), + PIPE_BIND_VERTEX_BUFFER); + + + ctx->set_vertex_buffers(ctx, 2, vbuf); + + /* index data */ + ibuf.buffer = screen->user_buffer_create(screen, + indices, + sizeof(indices), + PIPE_BIND_VERTEX_BUFFER); + ibuf.offset = 0; + ibuf.index_size = 2; + + ctx->set_index_buffer(ctx, &ibuf); + +} + +static void set_vertex_shader( void ) +{ + void *handle; + const char *text = + "VERT\n" + "DCL IN[0]\n" + "DCL IN[1]\n" + "DCL IN[2]\n" + "DCL OUT[0], POSITION\n" + "DCL OUT[1], COLOR\n" + " 0: MOV OUT[1], IN[1]\n" + " 1: ADD OUT[0], IN[0], IN[2]\n" /* add instance pos to vertex pos */ + " 2: END\n"; + + handle = graw_parse_vertex_shader(ctx, text); + ctx->bind_vs_state(ctx, handle); +} + +static void set_fragment_shader( void ) +{ + void *handle; + const char *text = + "FRAG\n" + "DCL IN[0], COLOR, LINEAR\n" + "DCL OUT[0], COLOR\n" + " 0: MOV OUT[0], IN[0]\n" + " 1: END\n"; + + handle = graw_parse_fragment_shader(ctx, text); + ctx->bind_fs_state(ctx, handle); +} + + +static void draw( void ) +{ + float clear_color[4] = {1,0,1,1}; + struct pipe_draw_info info; + + ctx->clear(ctx, PIPE_CLEAR_COLOR, clear_color, 0, 0); + + util_draw_init_info(&info); + info.indexed = (draw_elements != 0); + info.mode = PIPE_PRIM_TRIANGLES; + info.start = 0; + info.count = 3; + /* draw NUM_INST triangles */ + info.instance_count = NUM_INST; + + ctx->draw_vbo(ctx, &info); + + ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL); + + graw_save_surface_to_file(ctx, surf, NULL); + + screen->flush_frontbuffer(screen, tex, 0, 0, window); +} + + +static void init( void ) +{ + struct pipe_framebuffer_state fb; + struct pipe_resource templat; + struct pipe_surface surf_tmpl; + int i; + + /* It's hard to say whether window or screen should be created + * first. Different environments would prefer one or the other. + * + * Also, no easy way of querying supported formats if the screen + * cannot be created first. + */ + for (i = 0; + window == NULL && formats[i] != PIPE_FORMAT_NONE; + i++) { + + screen = graw_create_window_and_screen(0,0,300,300, + formats[i], + &window); + } + + ctx = screen->context_create(screen, NULL); + if (ctx == NULL) + exit(3); + + templat.target = PIPE_TEXTURE_2D; + templat.format = formats[i]; + templat.width0 = WIDTH; + templat.height0 = HEIGHT; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET); + + tex = screen->resource_create(screen, + &templat); + if (tex == NULL) + exit(4); + + surf_tmpl.format = templat.format; + surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; + surf_tmpl.u.tex.level = 0; + surf_tmpl.u.tex.first_layer = 0; + surf_tmpl.u.tex.last_layer = 0; + surf = ctx->create_surface(ctx, tex, &surf_tmpl); + if (surf == NULL) + exit(5); + + memset(&fb, 0, sizeof fb); + fb.nr_cbufs = 1; + fb.width = WIDTH; + fb.height = HEIGHT; + fb.cbufs[0] = surf; + + ctx->set_framebuffer_state(ctx, &fb); + + { + struct pipe_blend_state blend; + void *handle; + memset(&blend, 0, sizeof blend); + blend.rt[0].colormask = PIPE_MASK_RGBA; + handle = ctx->create_blend_state(ctx, &blend); + ctx->bind_blend_state(ctx, handle); + } + + { + struct pipe_depth_stencil_alpha_state depthstencil; + void *handle; + memset(&depthstencil, 0, sizeof depthstencil); + handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil); + ctx->bind_depth_stencil_alpha_state(ctx, handle); + } + + { + struct pipe_rasterizer_state rasterizer; + void *handle; + memset(&rasterizer, 0, sizeof rasterizer); + rasterizer.cull_face = PIPE_FACE_NONE; + rasterizer.gl_rasterization_rules = 1; + handle = ctx->create_rasterizer_state(ctx, &rasterizer); + ctx->bind_rasterizer_state(ctx, handle); + } + + set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000); + set_vertices(); + set_vertex_shader(); + set_fragment_shader(); +} + + +static void options(int argc, char *argv[]) +{ + int i; + + for (i = 1; i < argc;) { + if (graw_parse_args(&i, argc, argv)) { + continue; + } + if (strcmp(argv[i], "-e") == 0) { + draw_elements = 1; + i++; + } + else { + i++; + } + } + if (draw_elements) + printf("Using pipe_context::draw_elements_instanced()\n"); + else + printf("Using pipe_context::draw_arrays_instanced()\n"); +} + + +int main( int argc, char *argv[] ) +{ + options(argc, argv); + + init(); + + graw_set_display_func( draw ); + graw_main_loop(); + return 0; +} diff --git a/src/gallium/tests/graw/tri.c b/src/gallium/tests/graw/tri.c new file mode 100644 index 0000000..2742c7c --- /dev/null +++ b/src/gallium/tests/graw/tri.c @@ -0,0 +1,270 @@ +/* Display a cleared blue window. This demo has no dependencies on + * any utility code, just the graw interface and gallium. + */ + +#include + +#include "state_tracker/graw.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" + +#include "util/u_memory.h" /* Offset() */ +#include "util/u_draw_quad.h" + +enum pipe_format formats[] = { + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_NONE +}; + +static const int WIDTH = 300; +static const int HEIGHT = 300; + +static struct pipe_screen *screen = NULL; +static struct pipe_context *ctx = NULL; +static struct pipe_surface *surf = NULL; +static struct pipe_resource *tex = NULL; +static void *window = NULL; + +struct vertex { + float position[4]; + float color[4]; +}; + +static struct vertex vertices[3] = +{ + { + { 0.0f, -0.9f, 0.0f, 1.0f }, + { 1.0f, 0.0f, 0.0f, 1.0f } + }, + { + { -0.9f, 0.9f, 0.0f, 1.0f }, + { 0.0f, 1.0f, 0.0f, 1.0f } + }, + { + { 0.9f, 0.9f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f, 1.0f } + } +}; + + + + +static void set_viewport( float x, float y, + float width, float height, + float near, float far) +{ + float z = far; + float half_width = (float)width / 2.0f; + float half_height = (float)height / 2.0f; + float half_depth = ((float)far - (float)near) / 2.0f; + struct pipe_viewport_state vp; + + vp.scale[0] = half_width; + vp.scale[1] = half_height; + vp.scale[2] = half_depth; + vp.scale[3] = 1.0f; + + vp.translate[0] = half_width + x; + vp.translate[1] = half_height + y; + vp.translate[2] = half_depth + z; + vp.translate[3] = 0.0f; + + ctx->set_viewport_state( ctx, &vp ); +} + +static void set_vertices( void ) +{ + struct pipe_vertex_element ve[2]; + struct pipe_vertex_buffer vbuf; + void *handle; + + memset(ve, 0, sizeof ve); + + ve[0].src_offset = Offset(struct vertex, position); + ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + ve[1].src_offset = Offset(struct vertex, color); + ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + handle = ctx->create_vertex_elements_state(ctx, 2, ve); + ctx->bind_vertex_elements_state(ctx, handle); + + + vbuf.stride = sizeof( struct vertex ); + vbuf.max_index = sizeof(vertices) / vbuf.stride; + vbuf.buffer_offset = 0; + vbuf.buffer = screen->user_buffer_create(screen, + vertices, + sizeof(vertices), + PIPE_BIND_VERTEX_BUFFER); + + ctx->set_vertex_buffers(ctx, 1, &vbuf); +} + +static void set_vertex_shader( void ) +{ + void *handle; + const char *text = + "VERT\n" + "DCL IN[0]\n" + "DCL IN[1]\n" + "DCL OUT[0], POSITION\n" + "DCL OUT[1], COLOR\n" + " 0: MOV OUT[1], IN[1]\n" + " 1: MOV OUT[0], IN[0]\n" + " 2: END\n"; + + handle = graw_parse_vertex_shader(ctx, text); + ctx->bind_vs_state(ctx, handle); +} + +static void set_fragment_shader( void ) +{ + void *handle; + const char *text = + "FRAG\n" + "DCL IN[0], COLOR, LINEAR\n" + "DCL OUT[0], COLOR\n" + " 0: MOV OUT[0], IN[0]\n" + " 1: END\n"; + + handle = graw_parse_fragment_shader(ctx, text); + ctx->bind_fs_state(ctx, handle); +} + + +static void draw( void ) +{ + float clear_color[4] = {1,0,1,1}; + + ctx->clear(ctx, PIPE_CLEAR_COLOR, clear_color, 0, 0); + util_draw_arrays(ctx, PIPE_PRIM_TRIANGLES, 0, 3); + ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL); + + graw_save_surface_to_file(ctx, surf, NULL); + + screen->flush_frontbuffer(screen, tex, 0, 0, window); +} + + +static void init( void ) +{ + struct pipe_framebuffer_state fb; + struct pipe_resource templat; + struct pipe_surface surf_tmpl; + int i; + + /* It's hard to say whether window or screen should be created + * first. Different environments would prefer one or the other. + * + * Also, no easy way of querying supported formats if the screen + * cannot be created first. + */ + for (i = 0; + window == NULL && formats[i] != PIPE_FORMAT_NONE; + i++) { + + screen = graw_create_window_and_screen(0,0,300,300, + formats[i], + &window); + } + + ctx = screen->context_create(screen, NULL); + if (ctx == NULL) { + fprintf(stderr, "Unable to create context!\n"); + exit(3); + } + + templat.target = PIPE_TEXTURE_2D; + templat.format = formats[i]; + templat.width0 = WIDTH; + templat.height0 = HEIGHT; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET); + + tex = screen->resource_create(screen, + &templat); + if (tex == NULL) { + fprintf(stderr, "Unable to create screen texture!\n"); + exit(4); + } + + surf_tmpl.format = templat.format; + surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; + surf_tmpl.u.tex.level = 0; + surf_tmpl.u.tex.first_layer = 0; + surf_tmpl.u.tex.last_layer = 0; + surf = ctx->create_surface(ctx, tex, &surf_tmpl); + if (surf == NULL) { + fprintf(stderr, "Unable to create tex surface!\n"); + exit(5); + } + + memset(&fb, 0, sizeof fb); + fb.nr_cbufs = 1; + fb.width = WIDTH; + fb.height = HEIGHT; + fb.cbufs[0] = surf; + + ctx->set_framebuffer_state(ctx, &fb); + + { + struct pipe_blend_state blend; + void *handle; + memset(&blend, 0, sizeof blend); + blend.rt[0].colormask = PIPE_MASK_RGBA; + handle = ctx->create_blend_state(ctx, &blend); + ctx->bind_blend_state(ctx, handle); + } + + { + struct pipe_depth_stencil_alpha_state depthstencil; + void *handle; + memset(&depthstencil, 0, sizeof depthstencil); + handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil); + ctx->bind_depth_stencil_alpha_state(ctx, handle); + } + + { + struct pipe_rasterizer_state rasterizer; + void *handle; + memset(&rasterizer, 0, sizeof rasterizer); + rasterizer.cull_face = PIPE_FACE_NONE; + rasterizer.gl_rasterization_rules = 1; + handle = ctx->create_rasterizer_state(ctx, &rasterizer); + ctx->bind_rasterizer_state(ctx, handle); + } + + set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000); + set_vertices(); + set_vertex_shader(); + set_fragment_shader(); +} + +static void args(int argc, char *argv[]) +{ + int i; + + for (i = 1; i < argc;) { + if (graw_parse_args(&i, argc, argv)) { + continue; + } + exit(1); + } +} + +int main( int argc, char *argv[] ) +{ + args(argc, argv); + init(); + + graw_set_display_func( draw ); + graw_main_loop(); + return 0; +} diff --git a/src/gallium/tests/graw/vertex-shader/vertex-shader.py b/src/gallium/tests/graw/vertex-shader/vertex-shader.py new file mode 100644 index 0000000..05e40db --- /dev/null +++ b/src/gallium/tests/graw/vertex-shader/vertex-shader.py @@ -0,0 +1,287 @@ +#!/usr/bin/env python +########################################################################## +# +# 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. +# +########################################################################## + + +import struct + +from gallium import * + +def make_image(surface): + data = surface.get_tile_rgba8(0, 0, surface.width, surface.height) + + import Image + outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1) + return outimage + +def save_image(filename, surface): + outimage = make_image(surface) + outimage.save(filename, "PNG") + +def test(dev, name): + ctx = dev.context_create() + + width = 320 + height = 320 + minz = 0.0 + maxz = 1.0 + + # disabled blending/masking + blend = Blend() + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.rt[0].colormask = PIPE_MASK_RGBA + ctx.set_blend(blend) + + # depth/stencil/alpha + depth_stencil_alpha = DepthStencilAlpha() + depth_stencil_alpha.depth.enabled = 0 + depth_stencil_alpha.depth.writemask = 1 + depth_stencil_alpha.depth.func = PIPE_FUNC_LESS + ctx.set_depth_stencil_alpha(depth_stencil_alpha) + + # rasterizer + rasterizer = Rasterizer() + rasterizer.front_winding = PIPE_WINDING_CW + rasterizer.cull_mode = PIPE_WINDING_NONE + rasterizer.scissor = 1 + ctx.set_rasterizer(rasterizer) + + # viewport + viewport = Viewport() + scale = FloatArray(4) + scale[0] = width / 2.0 + scale[1] = -height / 2.0 + scale[2] = (maxz - minz) / 2.0 + scale[3] = 1.0 + viewport.scale = scale + translate = FloatArray(4) + translate[0] = width / 2.0 + translate[1] = height / 2.0 + translate[2] = (maxz - minz) / 2.0 + translate[3] = 0.0 + viewport.translate = translate + ctx.set_viewport(viewport) + + # samplers + sampler = Sampler() + sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE + sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.normalized_coords = 1 + ctx.set_fragment_sampler(0, sampler) + + # scissor + scissor = Scissor() + scissor.minx = 0 + scissor.miny = 0 + scissor.maxx = width + scissor.maxy = height + ctx.set_scissor(scissor) + + clip = Clip() + clip.nr = 0 + ctx.set_clip(clip) + + # framebuffer + cbuf = dev.resource_create( + PIPE_FORMAT_B8G8R8X8_UNORM, + width, height, + bind=PIPE_BIND_RENDER_TARGET, + ).get_surface() + fb = Framebuffer() + fb.width = width + fb.height = height + fb.nr_cbufs = 1 + fb.set_cbuf(0, cbuf) + ctx.set_framebuffer(fb) + rgba = FloatArray(4); + rgba[0] = 0.5 + rgba[1] = 0.5 + rgba[2] = 0.5 + rgba[3] = 0.5 + ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0) + + # vertex shader + vs = Shader(file('vert-' + name + '.sh', 'rt').read()) + ctx.set_vertex_shader(vs) + + # fragment shader + fs = Shader(''' + FRAG + DCL IN[0], COLOR, LINEAR + DCL OUT[0], COLOR, CONSTANT + 0:MOV OUT[0], IN[0] + 1:END + ''') + ctx.set_fragment_shader(fs) + + constbuf0 = dev.buffer_create(64, + (PIPE_BUFFER_USAGE_CONSTANT | + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE), + 4 * 4 * 4) + + cbdata = '' + cbdata += struct.pack('4f', 0.4, 0.0, 0.0, 1.0) + cbdata += struct.pack('4f', 1.0, 1.0, 1.0, 1.0) + cbdata += struct.pack('4f', 2.0, 2.0, 2.0, 2.0) + cbdata += struct.pack('4f', 4.0, 8.0, 16.0, 32.0) + + constbuf0.write(cbdata, 0) + + ctx.set_constant_buffer(PIPE_SHADER_VERTEX, + 0, + constbuf0) + + constbuf1 = dev.buffer_create(64, + (PIPE_BUFFER_USAGE_CONSTANT | + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE), + 4 * 4 * 4) + + cbdata = '' + cbdata += struct.pack('4f', 0.1, 0.1, 0.1, 0.1) + cbdata += struct.pack('4f', 0.25, 0.25, 0.25, 0.25) + cbdata += struct.pack('4f', 0.5, 0.5, 0.5, 0.5) + cbdata += struct.pack('4f', 0.75, 0.75, 0.75, 0.75) + + constbuf1.write(cbdata, 0) + + ctx.set_constant_buffer(PIPE_SHADER_VERTEX, + 1, + constbuf1) + + xy = [ + 0.0, 0.8, + -0.2, 0.4, + 0.2, 0.4, + -0.4, 0.0, + 0.0, 0.0, + 0.4, 0.0, + -0.6, -0.4, + -0.2, -0.4, + 0.2, -0.4, + 0.6, -0.4, + -0.8, -0.8, + -0.4, -0.8, + 0.0, -0.8, + 0.4, -0.8, + 0.8, -0.8, + ] + color = [ + 1.0, 0.0, 0.0, + 0.0, 1.0, 0.0, + 0.0, 0.0, 1.0, + ] + tri = [ + 1, 2, 0, + 3, 4, 1, + 4, 2, 1, + 4, 5, 2, + 6, 7, 3, + 7, 4, 3, + 7, 8, 4, + 8, 5, 4, + 8, 9, 5, + 10, 11, 6, + 11, 7, 6, + 11, 12, 7, + 12, 8, 7, + 12, 13, 8, + 13, 9, 8, + 13, 14, 9, + ] + + nverts = 16 * 3 + nattrs = 2 + verts = FloatArray(nverts * nattrs * 4) + + for i in range(0, nverts): + verts[i * nattrs * 4 + 0] = xy[tri[i] * 2 + 0] # x + verts[i * nattrs * 4 + 1] = xy[tri[i] * 2 + 1] # y + verts[i * nattrs * 4 + 2] = 0.5 # z + verts[i * nattrs * 4 + 3] = 1.0 # w + verts[i * nattrs * 4 + 4] = color[(i % 3) * 3 + 0] # r + verts[i * nattrs * 4 + 5] = color[(i % 3) * 3 + 1] # g + verts[i * nattrs * 4 + 6] = color[(i % 3) * 3 + 2] # b + verts[i * nattrs * 4 + 7] = 1.0 # a + + ctx.draw_vertices(PIPE_PRIM_TRIANGLES, + nverts, + nattrs, + verts) + + ctx.flush() + + save_image('vert-' + name + '.png', cbuf) + +def main(): + tests = [ + 'abs', + 'add', + 'arl', + 'arr', + 'cb-1d', + 'cb-2d', + 'dp3', + 'dp4', + 'dst', + 'ex2', + 'flr', + 'frc', + 'lg2', + 'lit', + 'lrp', + 'mad', + 'max', + 'min', + 'mov', + 'mul', + 'rcp', + 'rsq', + 'sge', + 'slt', + 'srcmod-abs', + 'srcmod-absneg', + 'srcmod-neg', + 'srcmod-swz', + 'sub', + 'xpd', + ] + + dev = Device() + for t in tests: + test(dev, t) + +if __name__ == '__main__': + main() diff --git a/src/gallium/tests/graw/vs-test.c b/src/gallium/tests/graw/vs-test.c new file mode 100644 index 0000000..58908f3 --- /dev/null +++ b/src/gallium/tests/graw/vs-test.c @@ -0,0 +1,507 @@ +/* Display a cleared blue window. This demo has no dependencies on + * any utility code, just the graw interface and gallium. + */ + +#include "state_tracker/graw.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_shader_tokens.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" + +#include /* for fread(), etc */ + +#include "util/u_inlines.h" +#include "util/u_memory.h" /* Offset() */ +#include "util/u_draw_quad.h" +#include "util/u_box.h" + +static const char *filename = NULL; +unsigned show_fps = 0; + + +static void usage(char *name) +{ + fprintf(stderr, "usage: %s [ options ] shader_filename\n", name); +#ifndef WIN32 + fprintf(stderr, "\n" ); + fprintf(stderr, "options:\n"); + fprintf(stderr, " -fps show frames per second\n"); +#endif +} + + +enum pipe_format formats[] = { + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_NONE +}; + +static const int WIDTH = 250; +static const int HEIGHT = 250; + +static struct pipe_screen *screen = NULL; +static struct pipe_context *ctx = NULL; +static struct pipe_resource *rttex = NULL; +static struct pipe_resource *constbuf = NULL; +static struct pipe_surface *surf = NULL; +static struct pipe_sampler_view *sv = NULL; +static void *sampler = NULL; +static void *window = NULL; +static struct pipe_resource *samptex = NULL; + +struct vertex { + float position[4]; + float color[3]; +}; + +/* Draw a regular mesh + */ +#define MESH_SZ 16 +static struct vertex vertices[MESH_SZ * MESH_SZ]; + +static float constants[] = +{ 0.4, 0, 0, 1, + 1, 1, 1, 1, + 2, 2, 2, 2, + 4, 8, 16, 32, + + 3, 0, 0, 0, + 0, .5, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1, + + 1, 0, 0, 0.5, + 0, 1, 0, 0.5, + 0, 0, 1, 0, + 0, 0, 0, 1, +}; + +static void init_fs_constbuf( void ) +{ + struct pipe_resource templat; + struct pipe_box box; + + templat.target = PIPE_BUFFER; + templat.format = PIPE_FORMAT_R8_UNORM; + templat.width0 = sizeof(constants); + templat.height0 = 1; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = PIPE_BIND_CONSTANT_BUFFER; + + constbuf = screen->resource_create(screen, + &templat); + if (constbuf == NULL) + exit(4); + + + u_box_2d(0,0,sizeof(constants),1, &box); + + ctx->transfer_inline_write(ctx, + constbuf, + 0, + PIPE_TRANSFER_WRITE, + &box, + constants, + sizeof constants, + sizeof constants); + + + ctx->set_constant_buffer(ctx, + PIPE_SHADER_FRAGMENT, 0, + constbuf); +} + + +static void set_viewport( float x, float y, + float width, float height, + float near, float far) +{ + float z = far; + float half_width = (float)width / 2.0f; + float half_height = (float)height / 2.0f; + float half_depth = ((float)far - (float)near) / 2.0f; + struct pipe_viewport_state vp; + + vp.scale[0] = half_width; + vp.scale[1] = half_height; + vp.scale[2] = half_depth; + vp.scale[3] = 1.0f; + + vp.translate[0] = half_width + x; + vp.translate[1] = half_height + y; + vp.translate[2] = half_depth + z; + vp.translate[3] = 0.0f; + + ctx->set_viewport_state( ctx, &vp ); +} + +static void set_vertices( void ) +{ + struct pipe_vertex_element ve[2]; + struct pipe_vertex_buffer vbuf; + void *handle; + int x,y; + + memset(ve, 0, sizeof ve); + + ve[0].src_offset = Offset(struct vertex, position); + ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + ve[1].src_offset = Offset(struct vertex, color); + ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + handle = ctx->create_vertex_elements_state(ctx, 2, ve); + ctx->bind_vertex_elements_state(ctx, handle); + + for (x = 0; x < MESH_SZ; x++) { + for (y = 0; y < MESH_SZ; y++) { + int i = y * MESH_SZ + x; + vertices[i].position[0] = ((float)x)/MESH_SZ * 2.0 - 1.0; + vertices[i].position[1] = ((float)y)/MESH_SZ * 2.0 - 1.0; + vertices[i].position[2] = 0; + vertices[i].position[3] = 1.0; + + vertices[i].color[0] = .5; + vertices[i].color[1] = (float)x / (float)MESH_SZ; + vertices[i].color[2] = (float)y / (float)MESH_SZ; + } + } + + vbuf.stride = sizeof( struct vertex ); + vbuf.max_index = sizeof(vertices) / vbuf.stride; + vbuf.buffer_offset = 0; + vbuf.buffer = screen->user_buffer_create(screen, + vertices, + sizeof(vertices), + PIPE_BIND_VERTEX_BUFFER); + + ctx->set_vertex_buffers(ctx, 1, &vbuf); +} + +static void set_vertex_shader( void ) +{ + FILE *f; + char buf[50000]; + void *handle; + int sz; + + if ((f = fopen(filename, "r")) == NULL) { + fprintf(stderr, "Couldn't open %s\n", filename); + exit(1); + } + + sz = fread(buf, 1, sizeof(buf), f); + if (!feof(f)) { + printf("file too long\n"); + exit(1); + } + printf("%.*s\n", sz, buf); + buf[sz] = 0; + + handle = graw_parse_vertex_shader(ctx, buf); + ctx->bind_vs_state(ctx, handle); + fclose(f); +} + +static void set_fragment_shader( void ) +{ + void *handle; + const char *text = + "FRAG\n" + "DCL IN[0], COLOR, LINEAR\n" + "DCL OUT[0], COLOR\n" + " 0: MOV OUT[0], IN[0]\n" + " 1: END\n"; + + handle = graw_parse_fragment_shader(ctx, text); + ctx->bind_fs_state(ctx, handle); +} + + + +static void draw( void ) +{ + float clear_color[4] = {.1,.3,.5,0}; + + ctx->clear(ctx, PIPE_CLEAR_COLOR, clear_color, 0, 0); + util_draw_arrays(ctx, PIPE_PRIM_POINTS, 0, Elements(vertices)); + ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL); + + graw_save_surface_to_file(ctx, surf, NULL); + + screen->flush_frontbuffer(screen, rttex, 0, 0, window); +} + +#define SIZE 16 + +static void init_tex( void ) +{ + struct pipe_sampler_view sv_template; + struct pipe_sampler_state sampler_desc; + struct pipe_resource templat; + struct pipe_box box; + ubyte tex2d[SIZE][SIZE][4]; + int s, t; + +#if (SIZE != 2) + for (s = 0; s < SIZE; s++) { + for (t = 0; t < SIZE; t++) { + if (0) { + int x = (s ^ t) & 1; + tex2d[t][s][0] = (x) ? 0 : 63; + tex2d[t][s][1] = (x) ? 0 : 128; + tex2d[t][s][2] = 0; + tex2d[t][s][3] = 0xff; + } + else { + int x = ((s ^ t) >> 2) & 1; + tex2d[t][s][0] = s*255/(SIZE-1); + tex2d[t][s][1] = t*255/(SIZE-1); + tex2d[t][s][2] = (x) ? 0 : 128; + tex2d[t][s][3] = 0xff; + } + } + } +#else + tex2d[0][0][0] = 0; + tex2d[0][0][1] = 255; + tex2d[0][0][2] = 255; + tex2d[0][0][3] = 0; + + tex2d[0][1][0] = 0; + tex2d[0][1][1] = 0; + tex2d[0][1][2] = 255; + tex2d[0][1][3] = 255; + + tex2d[1][0][0] = 255; + tex2d[1][0][1] = 255; + tex2d[1][0][2] = 0; + tex2d[1][0][3] = 255; + + tex2d[1][1][0] = 255; + tex2d[1][1][1] = 0; + tex2d[1][1][2] = 0; + tex2d[1][1][3] = 255; +#endif + + templat.target = PIPE_TEXTURE_2D; + templat.format = PIPE_FORMAT_B8G8R8A8_UNORM; + templat.width0 = SIZE; + templat.height0 = SIZE; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = PIPE_BIND_SAMPLER_VIEW; + + + samptex = screen->resource_create(screen, + &templat); + if (samptex == NULL) + exit(4); + + u_box_2d(0,0,SIZE,SIZE, &box); + + ctx->transfer_inline_write(ctx, + samptex, + 0, + PIPE_TRANSFER_WRITE, + &box, + tex2d, + sizeof tex2d[0], + sizeof tex2d); + + /* Possibly read back & compare against original data: + */ + if (0) + { + struct pipe_transfer *t; + uint32_t *ptr; + t = pipe_get_transfer(ctx, samptex, + 0, 0, /* level, layer */ + PIPE_TRANSFER_READ, + 0, 0, SIZE, SIZE); /* x, y, width, height */ + + ptr = ctx->transfer_map(ctx, t); + + if (memcmp(ptr, tex2d, sizeof tex2d) != 0) { + assert(0); + exit(9); + } + + ctx->transfer_unmap(ctx, t); + + ctx->transfer_destroy(ctx, t); + } + + memset(&sv_template, 0, sizeof sv_template); + sv_template.format = samptex->format; + sv_template.texture = samptex; + sv_template.swizzle_r = 0; + sv_template.swizzle_g = 1; + sv_template.swizzle_b = 2; + sv_template.swizzle_a = 3; + sv = ctx->create_sampler_view(ctx, samptex, &sv_template); + if (sv == NULL) + exit(5); + + ctx->set_fragment_sampler_views(ctx, 1, &sv); + + + memset(&sampler_desc, 0, sizeof sampler_desc); + sampler_desc.wrap_s = PIPE_TEX_WRAP_REPEAT; + sampler_desc.wrap_t = PIPE_TEX_WRAP_REPEAT; + sampler_desc.wrap_r = PIPE_TEX_WRAP_REPEAT; + sampler_desc.min_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler_desc.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + sampler_desc.mag_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler_desc.compare_mode = PIPE_TEX_COMPARE_NONE; + sampler_desc.compare_func = 0; + sampler_desc.normalized_coords = 1; + sampler_desc.max_anisotropy = 0; + + sampler = ctx->create_sampler_state(ctx, &sampler_desc); + if (sampler == NULL) + exit(6); + + ctx->bind_fragment_sampler_states(ctx, 1, &sampler); + +} + +static void init( void ) +{ + struct pipe_framebuffer_state fb; + struct pipe_resource templat; + struct pipe_surface surf_tmpl; + int i; + + /* It's hard to say whether window or screen should be created + * first. Different environments would prefer one or the other. + * + * Also, no easy way of querying supported formats if the screen + * cannot be created first. + */ + for (i = 0; + window == NULL && formats[i] != PIPE_FORMAT_NONE; + i++) { + + screen = graw_create_window_and_screen(0,0,WIDTH,HEIGHT, + formats[i], + &window); + } + + ctx = screen->context_create(screen, NULL); + if (ctx == NULL) + exit(3); + + templat.target = PIPE_TEXTURE_2D; + templat.format = formats[i]; + templat.width0 = WIDTH; + templat.height0 = HEIGHT; + templat.depth0 = 1; + templat.array_size = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.bind = (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET); + + rttex = screen->resource_create(screen, + &templat); + if (rttex == NULL) + exit(4); + + surf_tmpl.format = templat.format; + surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; + surf_tmpl.u.tex.level = 0; + surf_tmpl.u.tex.first_layer = 0; + surf_tmpl.u.tex.last_layer = 0; + surf = ctx->create_surface(ctx, rttex, &surf_tmpl); + if (surf == NULL) + exit(5); + + memset(&fb, 0, sizeof fb); + fb.nr_cbufs = 1; + fb.width = WIDTH; + fb.height = HEIGHT; + fb.cbufs[0] = surf; + + ctx->set_framebuffer_state(ctx, &fb); + + { + struct pipe_blend_state blend; + void *handle; + memset(&blend, 0, sizeof blend); + blend.rt[0].colormask = PIPE_MASK_RGBA; + handle = ctx->create_blend_state(ctx, &blend); + ctx->bind_blend_state(ctx, handle); + } + + { + struct pipe_depth_stencil_alpha_state depthstencil; + void *handle; + memset(&depthstencil, 0, sizeof depthstencil); + handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil); + ctx->bind_depth_stencil_alpha_state(ctx, handle); + } + + { + struct pipe_rasterizer_state rasterizer; + void *handle; + memset(&rasterizer, 0, sizeof rasterizer); + rasterizer.cull_face = PIPE_FACE_NONE; + rasterizer.point_size = 8.0; + rasterizer.gl_rasterization_rules = 1; + handle = ctx->create_rasterizer_state(ctx, &rasterizer); + ctx->bind_rasterizer_state(ctx, handle); + } + + set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000); + + init_tex(); + init_fs_constbuf(); + + set_vertices(); + set_vertex_shader(); + set_fragment_shader(); +} + +static void args(int argc, char *argv[]) +{ + int i; + + for (i = 1; i < argc;) { + if (graw_parse_args(&i, argc, argv)) { + continue; + } + if (strcmp(argv[i], "-fps") == 0) { + show_fps = 1; + i++; + } + else if (i == argc - 1) { + filename = argv[i]; + i++; + } + else { + usage(argv[0]); + exit(1); + } + } + + if (!filename) { + usage(argv[0]); + exit(1); + } +} + +int main( int argc, char *argv[] ) +{ + args(argc,argv); + init(); + + graw_set_display_func( draw ); + graw_main_loop(); + return 0; +} diff --git a/src/gallium/tests/python/retrace/format.py b/src/gallium/tests/python/retrace/format.py new file mode 100755 index 0000000..a4285bf --- /dev/null +++ b/src/gallium/tests/python/retrace/format.py @@ -0,0 +1,173 @@ +#!/usr/bin/env python +########################################################################## +# +# 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. +# +########################################################################## + + +import sys + + +class Formatter: + '''Plain formatter''' + + def __init__(self, stream): + self.stream = stream + + def text(self, text): + self.stream.write(text) + + def newline(self): + self.text('\n') + + def function(self, name): + self.text(name) + + def variable(self, name): + self.text(name) + + def literal(self, value): + self.text(str(value)) + + def address(self, addr): + self.text(str(addr)) + + +class AnsiFormatter(Formatter): + '''Formatter for plain-text files which outputs ANSI escape codes. See + http://en.wikipedia.org/wiki/ANSI_escape_code for more information + concerning ANSI escape codes. + ''' + + _csi = '\33[' + + _normal = '0m' + _bold = '1m' + _italic = '3m' + _red = '31m' + _green = '32m' + _blue = '34m' + + def _escape(self, code): + self.text(self._csi + code) + + def function(self, name): + self._escape(self._bold) + Formatter.function(self, name) + self._escape(self._normal) + + def variable(self, name): + self._escape(self._italic) + Formatter.variable(self, name) + self._escape(self._normal) + + def literal(self, value): + self._escape(self._blue) + Formatter.literal(self, value) + self._escape(self._normal) + + def address(self, value): + self._escape(self._green) + Formatter.address(self, value) + self._escape(self._normal) + + +class WindowsConsoleFormatter(Formatter): + '''Formatter for the Windows Console. See + http://code.activestate.com/recipes/496901/ for more information. + ''' + + STD_INPUT_HANDLE = -10 + STD_OUTPUT_HANDLE = -11 + STD_ERROR_HANDLE = -12 + + FOREGROUND_BLUE = 0x01 + FOREGROUND_GREEN = 0x02 + FOREGROUND_RED = 0x04 + FOREGROUND_INTENSITY = 0x08 + BACKGROUND_BLUE = 0x10 + BACKGROUND_GREEN = 0x20 + BACKGROUND_RED = 0x40 + BACKGROUND_INTENSITY = 0x80 + + _normal = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED + _bold = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY + _italic = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED + _red = FOREGROUND_RED | FOREGROUND_INTENSITY + _green = FOREGROUND_GREEN | FOREGROUND_INTENSITY + _blue = FOREGROUND_BLUE | FOREGROUND_INTENSITY + + def __init__(self, stream): + Formatter.__init__(self, stream) + + if stream is sys.stdin: + nStdHandle = self.STD_INPUT_HANDLE + elif stream is sys.stdout: + nStdHandle = self.STD_OUTPUT_HANDLE + elif stream is sys.stderr: + nStdHandle = self.STD_ERROR_HANDLE + else: + nStdHandle = None + + if nStdHandle: + import ctypes + self.handle = ctypes.windll.kernel32.GetStdHandle(nStdHandle) + else: + self.handle = None + + def _attribute(self, attr): + if self.handle: + import ctypes + ctypes.windll.kernel32.SetConsoleTextAttribute(self.handle, attr) + + def function(self, name): + self._attribute(self._bold) + Formatter.function(self, name) + self._attribute(self._normal) + + def variable(self, name): + self._attribute(self._italic) + Formatter.variable(self, name) + self._attribute(self._normal) + + def literal(self, value): + self._attribute(self._blue) + Formatter.literal(self, value) + self._attribute(self._normal) + + def address(self, value): + self._attribute(self._green) + Formatter.address(self, value) + self._attribute(self._normal) + + +def DefaultFormatter(stream): + if sys.platform in ('linux2', 'cygwin'): + return AnsiFormatter(stream) + elif sys.platform in ('win32',): + return WindowsConsoleFormatter(stream) + else: + return Formatter(stream) + diff --git a/src/gallium/tests/python/retrace/interpreter.py b/src/gallium/tests/python/retrace/interpreter.py new file mode 100755 index 0000000..8437122 --- /dev/null +++ b/src/gallium/tests/python/retrace/interpreter.py @@ -0,0 +1,733 @@ +#!/usr/bin/env python +########################################################################## +# +# 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. +# +########################################################################## + + +import sys +import struct + +import gallium +import model +import parse as parser + + +try: + from struct import unpack_from +except ImportError: + def unpack_from(fmt, buf, offset=0): + size = struct.calcsize(fmt) + return struct.unpack(fmt, buf[offset:offset + size]) + + +def make_image(ctx, surface, x=None, y=None, w=None, h=None): + if x is None: + x = 0 + if y is None: + y = 0 + if w is None: + w = surface.width - x + if h is None: + h = surface.height - y + data = ctx.surface_read_rgba8(surface, x, y, surface.width, surface.height) + + import Image + outimage = Image.fromstring('RGBA', (w, h), data, "raw", 'RGBA', 0, 1) + return outimage + +def save_image(ctx, filename, surface, x=None, y=None, w=None, h=None): + outimage = make_image(ctx, surface, x, y, w, h) + outimage.save(filename, "PNG") + +def show_image(ctx, surface, title, x=None, y=None, w=None, h=None): + outimage = make_image(ctx, surface, x, y, w, h) + + import Tkinter as tk + from PIL import Image, ImageTk + root = tk.Tk() + + root.title(title) + + image1 = ImageTk.PhotoImage(outimage) + w = image1.width() + h = image1.height() + x = 100 + y = 100 + root.geometry("%dx%d+%d+%d" % (w, h, x, y)) + panel1 = tk.Label(root, image=image1) + panel1.pack(side='top', fill='both', expand='yes') + panel1.image = image1 + root.mainloop() + + +class Struct: + """C-like struct""" + + # A basic Python class can pass as a C-like structure + pass + + +struct_factories = { + "pipe_blend_color": gallium.BlendColor, + "pipe_blend_state": gallium.Blend, + #"pipe_clip_state": gallium.Clip, + #"pipe_buffer": gallium.Buffer, + "pipe_depth_state": gallium.Depth, + "pipe_stencil_state": gallium.Stencil, + "pipe_alpha_state": gallium.Alpha, + "pipe_depth_stencil_alpha_state": gallium.DepthStencilAlpha, + #"pipe_framebuffer_state": gallium.Framebuffer, + "pipe_poly_stipple": gallium.PolyStipple, + "pipe_rasterizer_state": gallium.Rasterizer, + "pipe_sampler_state": gallium.Sampler, + "pipe_scissor_state": gallium.Scissor, + #"pipe_shader_state": gallium.Shader, + #"pipe_vertex_buffer": gallium.VertexBuffer, + "pipe_vertex_element": gallium.VertexElement, + "pipe_viewport_state": gallium.Viewport, + #"pipe_texture": gallium.Texture, + 'pipe_subresource': gallium.pipe_subresource, + 'pipe_box': gallium.pipe_box, + 'pipe_draw_info': gallium.pipe_draw_info, +} + + +member_array_factories = { + #"pipe_rasterizer_state": {"sprite_coord_mode": gallium.ByteArray}, + "pipe_poly_stipple": {"stipple": gallium.UnsignedArray}, + "pipe_viewport_state": {"scale": gallium.FloatArray, "translate": gallium.FloatArray}, + #"pipe_clip_state": {"ucp": gallium.FloatArray}, + "pipe_depth_stencil_alpha_state": {"stencil": gallium.StencilArray}, + "pipe_blend_color": {"color": gallium.FloatArray}, + "pipe_sampler_state": {"border_color": gallium.FloatArray}, +} + + +class Translator(model.Visitor): + """Translate model arguments into regular Python objects""" + + def __init__(self, interpreter): + self.interpreter = interpreter + self.result = None + + def visit(self, node): + self.result = None + node.visit(self) + return self.result + + def visit_literal(self, node): + self.result = node.value + + def visit_named_constant(self, node): + # lookup the named constant in the gallium module + self.result = getattr(gallium, node.name) + + def visit_array(self, node): + array = [] + for element in node.elements: + array.append(self.visit(element)) + self.result = array + + def visit_struct(self, node): + struct_factory = struct_factories.get(node.name, Struct) + struct = struct_factory() + for member_name, member_node in node.members: + member_value = self.visit(member_node) + try: + array_factory = member_array_factories[node.name][member_name] + except KeyError: + pass + else: + assert isinstance(member_value, list) + array = array_factory(len(member_value)) + for i in range(len(member_value)): + array[i] = member_value[i] + member_value = array + #print node.name, member_name, member_value + assert isinstance(struct, Struct) or hasattr(struct, member_name) + setattr(struct, member_name, member_value) + self.result = struct + + def visit_pointer(self, node): + self.result = self.interpreter.lookup_object(node.address) + + +class Object: + + def __init__(self, interpreter, real): + self.interpreter = interpreter + self.real = real + + +class Global(Object): + + def __init__(self, interpreter, real): + self.interpreter = interpreter + self.real = real + + def pipe_screen_create(self): + real = gallium.Device() + return Screen(self.interpreter, real) + + def pipe_context_create(self, screen): + context = screen.real.context_create() + return Context(self.interpreter, context) + + +class Transfer: + + def __init__(self, resource, usage, subresource, box): + self.resource = resource + self.usage = usage + self.subresource = subresource + self.box = box + + +class Screen(Object): + + def __init__(self, interpreter, real): + Object.__init__(self, interpreter, real) + self.context = self.real.context_create() + + def destroy(self): + pass + + def get_name(self): + pass + + def get_vendor(self): + pass + + def get_param(self, param): + pass + + def get_paramf(self, param): + pass + + def context_create(self): + context = self.real.context_create() + return Context(self.interpreter, context) + + def is_format_supported(self, format, target, sample_count, bind, geom_flags): + return self.real.is_format_supported(format, target, sample_count, bind, geom_flags) + + def resource_create(self, templat): + return self.real.resource_create( + format = templat.format, + width = templat.width, + height = templat.height, + depth = templat.depth, + last_level = templat.last_level, + target = templat.target, + bind = templat.bind, + ) + + def texture_destroy(self, texture): + self.interpreter.unregister_object(texture) + + def texture_release(self, surface): + pass + + def tex_surface_release(self, surface): + pass + + def user_buffer_create(self, data, size, usage): + bind = usage + # We don't really care to distinguish between user and regular buffers + buffer = self.real.buffer_create(size, bind) + assert size == len(data) + self.context.buffer_write(buffer, data) + return buffer + + def buffer_create(self, alignment, usage, size): + return self.real.buffer_create(size, alignment, usage) + + def buffer_destroy(self, buffer): + pass + + def fence_finish(self, fence, flags): + pass + + def fence_reference(self, dst, src): + pass + + def flush_frontbuffer(self, resource): + pass + + +class Context(Object): + + def __init__(self, interpreter, real): + Object.__init__(self, interpreter, real) + self.cbufs = [] + self.zsbuf = None + self.vbufs = [] + self.velems = [] + self.dirty = False + + def destroy(self): + pass + + def create_blend_state(self, state): + if isinstance(state, str): + state = gallium.Blend(state) + sys.stdout.write('\t%s\n' % state) + return state + + def bind_blend_state(self, state): + if state is not None: + self.real.set_blend(state) + + def delete_blend_state(self, state): + pass + + def create_sampler_state(self, state): + return state + + def delete_sampler_state(self, state): + pass + + def bind_vertex_sampler_states(self, num_states, states): + for i in range(num_states): + self.real.set_vertex_sampler(i, states[i]) + + def bind_fragment_sampler_states(self, num_states, states): + for i in range(num_states): + self.real.set_fragment_sampler(i, states[i]) + + def create_rasterizer_state(self, state): + return state + + def bind_rasterizer_state(self, state): + if state is not None: + self.real.set_rasterizer(state) + + def delete_rasterizer_state(self, state): + pass + + def create_depth_stencil_alpha_state(self, state): + return state + + def bind_depth_stencil_alpha_state(self, state): + if state is not None: + self.real.set_depth_stencil_alpha(state) + + def delete_depth_stencil_alpha_state(self, state): + pass + + def create_fs_state(self, state): + tokens = str(state.tokens) + shader = gallium.Shader(tokens) + return shader + + create_vs_state = create_fs_state + + def bind_fs_state(self, state): + self.real.set_fragment_shader(state) + + def bind_vs_state(self, state): + self.real.set_vertex_shader(state) + + def delete_fs_state(self, state): + pass + + delete_vs_state = delete_fs_state + + def set_blend_color(self, state): + self.real.set_blend_color(state) + + def set_stencil_ref(self, state): + self.real.set_stencil_ref(state) + + def set_clip_state(self, state): + _state = gallium.Clip() + _state.nr = state.nr + if state.nr: + # FIXME + ucp = gallium.FloatArray(gallium.PIPE_MAX_CLIP_PLANES*4) + for i in range(len(state.ucp)): + for j in range(len(state.ucp[i])): + ucp[i*4 + j] = state.ucp[i][j] + _state.ucp = ucp + self.real.set_clip(_state) + + def dump_constant_buffer(self, buffer): + if not self.interpreter.verbosity(2): + return + + data = self.real.buffer_read(buffer) + format = '4f' + index = 0 + for offset in range(0, len(data), struct.calcsize(format)): + x, y, z, w = unpack_from(format, data, offset) + sys.stdout.write('\tCONST[%2u] = {%10.4f, %10.4f, %10.4f, %10.4f}\n' % (index, x, y, z, w)) + index += 1 + sys.stdout.flush() + + def set_constant_buffer(self, shader, index, buffer): + if buffer is not None: + self.real.set_constant_buffer(shader, index, buffer) + + self.dump_constant_buffer(buffer) + + def set_framebuffer_state(self, state): + _state = gallium.Framebuffer() + _state.width = state.width + _state.height = state.height + _state.nr_cbufs = state.nr_cbufs + for i in range(len(state.cbufs)): + _state.set_cbuf(i, state.cbufs[i]) + _state.set_zsbuf(state.zsbuf) + self.real.set_framebuffer(_state) + + self.cbufs = state.cbufs + self.zsbuf = state.zsbuf + + def set_polygon_stipple(self, state): + self.real.set_polygon_stipple(state) + + def set_scissor_state(self, state): + self.real.set_scissor(state) + + def set_viewport_state(self, state): + self.real.set_viewport(state) + + def create_sampler_view(self, texture, templ): + return self.real.create_sampler_view(texture, + format = templ.format, + first_level = templ.first_level, + last_level = templ.last_level, + swizzle_r = templ.swizzle_r, + swizzle_g = templ.swizzle_r, + swizzle_b = templ.swizzle_g, + swizzle_a = templ.swizzle_a) + + def sampler_view_destroy(self, view): + pass + + def set_fragment_sampler_views(self, num, views): + for i in range(num): + self.real.set_fragment_sampler_view(i, views[i]) + + def set_vertex_sampler_views(self, num, views): + for i in range(num): + self.real.set_vertex_sampler_view(i, views[i]) + + def set_vertex_buffers(self, num_buffers, buffers): + self.vbufs = buffers[0:num_buffers] + for i in range(num_buffers): + vbuf = buffers[i] + self.real.set_vertex_buffer( + i, + stride = vbuf.stride, + max_index = vbuf.max_index, + buffer_offset = vbuf.buffer_offset, + buffer = vbuf.buffer, + ) + + def create_vertex_elements_state(self, num_elements, elements): + return elements[0:num_elements] + + def bind_vertex_elements_state(self, state): + if state is None: + self.real.set_vertex_elements(0) + return + + elements = state + num_elements = len(elements) + self.velems = elements + for i in range(num_elements): + self.real.set_vertex_element(i, elements[i]) + self.real.set_vertex_elements(num_elements) + + def delete_vertex_elements_state(self, state): + pass + + def dump_vertices(self, start, count): + if not self.interpreter.verbosity(2): + return + + for index in range(start, start + count): + if index >= start + 16: + sys.stdout.write('\t...\n') + break + sys.stdout.write('\t{\n') + for velem in self.velems: + vbuf = self.vbufs[velem.vertex_buffer_index] + + offset = vbuf.buffer_offset + velem.src_offset + vbuf.stride*index + format = { + gallium.PIPE_FORMAT_R32_FLOAT: 'f', + gallium.PIPE_FORMAT_R32G32_FLOAT: '2f', + gallium.PIPE_FORMAT_R32G32B32_FLOAT: '3f', + gallium.PIPE_FORMAT_R32G32B32A32_FLOAT: '4f', + gallium.PIPE_FORMAT_A8R8G8B8_UNORM: '4B', + gallium.PIPE_FORMAT_R8G8B8A8_UNORM: '4B', + gallium.PIPE_FORMAT_B8G8R8A8_UNORM: '4B', + gallium.PIPE_FORMAT_R16G16B16_SNORM: '3h', + }[velem.src_format] + + data = self.real.buffer_read(vbuf.buffer) + values = unpack_from(format, data, offset) + sys.stdout.write('\t\t{' + ', '.join(map(str, values)) + '},\n') + sys.stdout.write('\t},\n') + sys.stdout.flush() + + def dump_indices(self, ibuf, isize, ibias, start, count): + if not self.interpreter.verbosity(2): + return + + format = { + 1: 'B', + 2: 'H', + 4: 'I', + }[isize] + + assert struct.calcsize(format) == isize + + data = self.real.buffer_read(ibuf) + maxindex, minindex = 0, 0xffffffff + + sys.stdout.write('\t{\n') + for i in range(start, start + count): + if i >= start + 16 and not self.interpreter.verbosity(3): + sys.stdout.write('\t...\n') + break + offset = i*isize + index, = unpack_from(format, data, offset) + sys.stdout.write('\t\t%u,\n' % index) + minindex = min(minindex, index) + maxindex = max(maxindex, index) + sys.stdout.write('\t},\n') + sys.stdout.flush() + + return minindex + ibias, maxindex + ibias + + def set_index_buffer(self, ib): + if ib: + self.real.set_index_buffer(ib.index_size, ib.offset, ib.buffer) + else: + self.real.set_index_buffer(0, 0, None) + + def draw_vbo(self, info): + if self.interpreter.verbosity(2): + if 0: + minindex, maxindex = self.dump_indices(indexBuffer, indexSize, indexBias, start, count) + + self.dump_vertices(info.minindex, info.maxindex + 1 - info.minindex) + + self.real.draw_vbo(info) + self._set_dirty() + + def resource_copy_region(self, dst, subdst, dstx, dsty, dstz, src, subsrc, srcx, srcy, srcz, width, height): + if dst is not None and src is not None: + if self.interpreter.options.all: + self.interpreter.present(self.real, src, 'resource_copy_src', srcx, srcy, width, height) + self.real.resource_copy_region(dst, subdst, dstx, dsty, dstx, src, subsrc, srcx, srcy, srcz, width, height) + flags = 0 + self.flush(flags) + if self.interpreter.options.all: + self.interpreter.present(self.real, dst, 'resource_copy_dst', dstx, dsty, width, height) + + def is_resource_referenced(self, texture, face, level): + #return self.real.is_resource_referenced(format, texture, face, level) + pass + + def buffer_write(self, buffer, data, size, offset=0): + assert size == len(data) + self.buffer_write(buffer, data) + + def surface_write(self, surface, data, stride, size): + if surface is None: + return +# assert surface.nblocksy * stride == size + surface.put_tile_raw(0, 0, surface.width, surface.height, data, stride) + + def get_transfer(self, texture, sr, usage, box): + if texture is None: + return None + transfer = Transfer(texture, sr, usage, box) + if transfer and usage & gallium.PIPE_TRANSFER_READ: + if self.interpreter.options.all: + surface = texture.get_surface(sr.face, sr.level, box.z) + self.interpreter.present(self.real, transfer.surface, 'transf_read', box.x, box.y, box.width, box.height) + return transfer + + def tex_transfer_destroy(self, transfer): + self.interpreter.unregister_object(transfer) + + def transfer_inline_write(self, resource, sr, usage, box, stride, slice_stride, data): + self.real.transfer_inline_write(resource, sr, usage, box, data, stride, slice_stride) + if self.interpreter.options.all: + for z in range(box.z, box.z + box.depth): + surface = resource.get_surface(sr.face, sr.level, box.z) + self.interpreter.present(self.real, surface, 'transf_inline_write%u' % z, box.x, box.y, box.width, box.height) + + def _set_dirty(self): + if self.interpreter.options.step: + self._present() + else: + self.dirty = True + + def flush(self, flags): + self.real.flush(flags) + if self.dirty: + if flags & gallium.PIPE_FLUSH_FRAME: + self._present() + self.dirty = False + return None + + def clear(self, buffers, rgba, depth, stencil): + _rgba = gallium.FloatArray(4) + for i in range(4): + _rgba[i] = rgba[i] + self.real.clear(buffers, _rgba, depth, stencil) + + def clear_render_target(self, dst, rgba, dstx, dsty, width, height): + _rgba = gallium.FloatArray(4) + for i in range(4): + _rgba[i] = rgba[i] + self.real.clear_render_target(dst, _rgba, dstx, dsty, width, height) + + def clear_depth_stencil(self, dst, clear_flags, depth, stencil, dstx, dsty, width, height): + self.real.clear_depth_stencil(dst, clear_flags, depth, stencil, dstx, dsty, width, height) + + def _present(self): + self.real.flush() + + if self.cbufs and self.cbufs[0]: + self.interpreter.present(self.real, self.cbufs[0], "cbuf") + if self.zsbuf: + if self.interpreter.options.all: + self.interpreter.present(self.real, self.zsbuf, "zsbuf") + def create_surface(self, texture, level, layer, usage): + if texture is None: + return None + return texture.get_surface(level, layer) + + def surface_destroy(self, surface): + self.interpreter.unregister_object(surface) + +class Interpreter(parser.TraceDumper): + + ignore_calls = set(( + ('pipe_screen', 'is_format_supported'), + ('pipe_screen', 'get_param'), + ('pipe_screen', 'get_paramf'), + )) + + def __init__(self, stream, options): + parser.TraceDumper.__init__(self, stream) + self.options = options + self.objects = {} + self.result = None + self.globl = Global(self, None) + self.call_no = None + + def register_object(self, address, object): + self.objects[address] = object + + def unregister_object(self, object): + # FIXME: + pass + + def lookup_object(self, address): + return self.objects[address] + + def interpret(self, trace): + for call in trace.calls: + self.interpret_call(call) + + def handle_call(self, call): + if self.options.stop and call.no > self.options.stop: + sys.exit(0) + + if (call.klass, call.method) in self.ignore_calls: + return + + self.call_no = call.no + + if self.verbosity(1): + parser.TraceDumper.handle_call(self, call) + sys.stdout.flush() + + args = [(str(name), self.interpret_arg(arg)) for name, arg in call.args] + + if call.klass: + name, obj = args[0] + args = args[1:] + else: + obj = self.globl + + method = getattr(obj, call.method) + ret = method(**dict(args)) + + if call.ret and isinstance(call.ret, model.Pointer): + if ret is None: + sys.stderr.write('warning: NULL returned\n') + self.register_object(call.ret.address, ret) + + self.call_no = None + + def interpret_arg(self, node): + translator = Translator(self) + return translator.visit(node) + + def verbosity(self, level): + return self.options.verbosity >= level + + def present(self, ctx, surface, description, x=None, y=None, w=None, h=None): + if self.call_no < self.options.start: + return + + if self.options.images: + filename = '%04u_%s.png' % (self.call_no, description) + save_image(ctx, filename, surface, x, y, w, h) + else: + title = '%u. %s' % (self.call_no, description) + show_image(ctx, surface, title, x, y, w, h) + + +class Main(parser.Main): + + def get_optparser(self): + optparser = parser.Main.get_optparser(self) + optparser.add_option("-q", "--quiet", action="store_const", const=0, dest="verbosity", help="no messages") + optparser.add_option("-v", "--verbose", action="count", dest="verbosity", default=1, help="increase verbosity level") + optparser.add_option("-i", "--images", action="store_true", dest="images", default=False, help="save images instead of showing them") + optparser.add_option("-a", "--all", action="store_true", dest="all", default=False, help="show depth, stencil, and transfers") + optparser.add_option("-s", "--step", action="store_true", dest="step", default=False, help="step trhough every draw") + optparser.add_option("-f", "--from", action="store", type="int", dest="start", default=0, help="from call no") + optparser.add_option("-t", "--to", action="store", type="int", dest="stop", default=0, help="until call no") + return optparser + + def process_arg(self, stream, options): + parser = Interpreter(stream, options) + parser.parse() + + +if __name__ == '__main__': + Main().main() diff --git a/src/gallium/tests/python/retrace/model.py b/src/gallium/tests/python/retrace/model.py new file mode 100755 index 0000000..d4a079f --- /dev/null +++ b/src/gallium/tests/python/retrace/model.py @@ -0,0 +1,213 @@ +#!/usr/bin/env python +########################################################################## +# +# 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. +# +########################################################################## + + +'''Trace data model.''' + + +import sys +import string +import format + +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO + + +class Node: + + def visit(self, visitor): + raise NotImplementedError + + def __str__(self): + stream = StringIO() + formatter = format.DefaultFormatter(stream) + pretty_printer = PrettyPrinter(formatter) + self.visit(pretty_printer) + return stream.getvalue() + + +class Literal(Node): + + def __init__(self, value): + self.value = value + + def visit(self, visitor): + visitor.visit_literal(self) + + +class NamedConstant(Node): + + def __init__(self, name): + self.name = name + + def visit(self, visitor): + visitor.visit_named_constant(self) + + +class Array(Node): + + def __init__(self, elements): + self.elements = elements + + def visit(self, visitor): + visitor.visit_array(self) + + +class Struct(Node): + + def __init__(self, name, members): + self.name = name + self.members = members + + def visit(self, visitor): + visitor.visit_struct(self) + + +class Pointer(Node): + + def __init__(self, address): + self.address = address + + def visit(self, visitor): + visitor.visit_pointer(self) + + +class Call: + + def __init__(self, no, klass, method, args, ret): + self.no = no + self.klass = klass + self.method = method + self.args = args + self.ret = ret + + def visit(self, visitor): + visitor.visit_call(self) + + +class Trace: + + def __init__(self, calls): + self.calls = calls + + def visit(self, visitor): + visitor.visit_trace(self) + + +class Visitor: + + def visit_literal(self, node): + raise NotImplementedError + + def visit_named_constant(self, node): + raise NotImplementedError + + def visit_array(self, node): + raise NotImplementedError + + def visit_struct(self, node): + raise NotImplementedError + + def visit_pointer(self, node): + raise NotImplementedError + + def visit_call(self, node): + raise NotImplementedError + + def visit_trace(self, node): + raise NotImplementedError + + +class PrettyPrinter: + + def __init__(self, formatter): + self.formatter = formatter + + def visit_literal(self, node): + if isinstance(node.value, basestring): + if len(node.value) >= 4096 or node.value.strip(string.printable): + self.formatter.text('...') + return + + self.formatter.literal('"' + node.value + '"') + return + + self.formatter.literal(repr(node.value)) + + def visit_named_constant(self, node): + self.formatter.literal(node.name) + + def visit_array(self, node): + self.formatter.text('{') + sep = '' + for value in node.elements: + self.formatter.text(sep) + value.visit(self) + sep = ', ' + self.formatter.text('}') + + def visit_struct(self, node): + self.formatter.text('{') + sep = '' + for name, value in node.members: + self.formatter.text(sep) + self.formatter.variable(name) + self.formatter.text(' = ') + value.visit(self) + sep = ', ' + self.formatter.text('}') + + def visit_pointer(self, node): + self.formatter.address(node.address) + + def visit_call(self, node): + self.formatter.text('%s ' % node.no) + if node.klass is not None: + self.formatter.function(node.klass + '::' + node.method) + else: + self.formatter.function(node.method) + self.formatter.text('(') + sep = '' + for name, value in node.args: + self.formatter.text(sep) + self.formatter.variable(name) + self.formatter.text(' = ') + value.visit(self) + sep = ', ' + self.formatter.text(')') + if node.ret is not None: + self.formatter.text(' = ') + node.ret.visit(self) + + def visit_trace(self, node): + for call in node.calls: + call.visit(self) + self.formatter.newline() + diff --git a/src/gallium/tests/python/retrace/parse.py b/src/gallium/tests/python/retrace/parse.py new file mode 100755 index 0000000..b08d368 --- /dev/null +++ b/src/gallium/tests/python/retrace/parse.py @@ -0,0 +1,392 @@ +#!/usr/bin/env python +########################################################################## +# +# 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. +# +########################################################################## + + +import sys +import xml.parsers.expat +import binascii +import optparse + +from model import * + + +ELEMENT_START, ELEMENT_END, CHARACTER_DATA, EOF = range(4) + + +class XmlToken: + + def __init__(self, type, name_or_data, attrs = None, line = None, column = None): + assert type in (ELEMENT_START, ELEMENT_END, CHARACTER_DATA, EOF) + self.type = type + self.name_or_data = name_or_data + self.attrs = attrs + self.line = line + self.column = column + + def __str__(self): + if self.type == ELEMENT_START: + return '<' + self.name_or_data + ' ...>' + if self.type == ELEMENT_END: + return '' + if self.type == CHARACTER_DATA: + return self.name_or_data + if self.type == EOF: + return 'end of file' + assert 0 + + +class XmlTokenizer: + """Expat based XML tokenizer.""" + + def __init__(self, fp, skip_ws = True): + self.fp = fp + self.tokens = [] + self.index = 0 + self.final = False + self.skip_ws = skip_ws + + self.character_pos = 0, 0 + self.character_data = '' + + self.parser = xml.parsers.expat.ParserCreate() + self.parser.StartElementHandler = self.handle_element_start + self.parser.EndElementHandler = self.handle_element_end + self.parser.CharacterDataHandler = self.handle_character_data + + def handle_element_start(self, name, attributes): + self.finish_character_data() + line, column = self.pos() + token = XmlToken(ELEMENT_START, name, attributes, line, column) + self.tokens.append(token) + + def handle_element_end(self, name): + self.finish_character_data() + line, column = self.pos() + token = XmlToken(ELEMENT_END, name, None, line, column) + self.tokens.append(token) + + def handle_character_data(self, data): + if not self.character_data: + self.character_pos = self.pos() + self.character_data += data + + def finish_character_data(self): + if self.character_data: + if not self.skip_ws or not self.character_data.isspace(): + line, column = self.character_pos + token = XmlToken(CHARACTER_DATA, self.character_data, None, line, column) + self.tokens.append(token) + self.character_data = '' + + def next(self): + size = 16*1024 + while self.index >= len(self.tokens) and not self.final: + self.tokens = [] + self.index = 0 + data = self.fp.read(size) + self.final = len(data) < size + data = data.rstrip('\0') + try: + self.parser.Parse(data, self.final) + except xml.parsers.expat.ExpatError, e: + #if e.code == xml.parsers.expat.errors.XML_ERROR_NO_ELEMENTS: + if e.code == 3: + pass + else: + raise e + if self.index >= len(self.tokens): + line, column = self.pos() + token = XmlToken(EOF, None, None, line, column) + else: + token = self.tokens[self.index] + self.index += 1 + return token + + def pos(self): + return self.parser.CurrentLineNumber, self.parser.CurrentColumnNumber + + +class TokenMismatch(Exception): + + def __init__(self, expected, found): + self.expected = expected + self.found = found + + def __str__(self): + return '%u:%u: %s expected, %s found' % (self.found.line, self.found.column, str(self.expected), str(self.found)) + + + +class XmlParser: + """Base XML document parser.""" + + def __init__(self, fp): + self.tokenizer = XmlTokenizer(fp) + self.consume() + + def consume(self): + self.token = self.tokenizer.next() + + def match_element_start(self, name): + return self.token.type == ELEMENT_START and self.token.name_or_data == name + + def match_element_end(self, name): + return self.token.type == ELEMENT_END and self.token.name_or_data == name + + def element_start(self, name): + while self.token.type == CHARACTER_DATA: + self.consume() + if self.token.type != ELEMENT_START: + raise TokenMismatch(XmlToken(ELEMENT_START, name), self.token) + if self.token.name_or_data != name: + raise TokenMismatch(XmlToken(ELEMENT_START, name), self.token) + attrs = self.token.attrs + self.consume() + return attrs + + def element_end(self, name): + while self.token.type == CHARACTER_DATA: + self.consume() + if self.token.type != ELEMENT_END: + raise TokenMismatch(XmlToken(ELEMENT_END, name), self.token) + if self.token.name_or_data != name: + raise TokenMismatch(XmlToken(ELEMENT_END, name), self.token) + self.consume() + + def character_data(self, strip = True): + data = '' + while self.token.type == CHARACTER_DATA: + data += self.token.name_or_data + self.consume() + if strip: + data = data.strip() + return data + + +class TraceParser(XmlParser): + + def __init__(self, fp): + XmlParser.__init__(self, fp) + self.last_call_no = 0 + + def parse(self): + self.element_start('trace') + while self.token.type not in (ELEMENT_END, EOF): + call = self.parse_call() + self.handle_call(call) + if self.token.type != EOF: + self.element_end('trace') + + def parse_call(self): + attrs = self.element_start('call') + try: + no = int(attrs['no']) + except KeyError: + self.last_call_no += 1 + no = self.last_call_no + else: + self.last_call_no = no + klass = attrs['class'] + method = attrs['method'] + args = [] + ret = None + while self.token.type == ELEMENT_START: + if self.token.name_or_data == 'arg': + arg = self.parse_arg() + args.append(arg) + elif self.token.name_or_data == 'ret': + ret = self.parse_ret() + elif self.token.name_or_data == 'call': + # ignore nested function calls + self.parse_call() + else: + raise TokenMismatch(" or ", self.token) + self.element_end('call') + + return Call(no, klass, method, args, ret) + + def parse_arg(self): + attrs = self.element_start('arg') + name = attrs['name'] + value = self.parse_value() + self.element_end('arg') + + return name, value + + def parse_ret(self): + attrs = self.element_start('ret') + value = self.parse_value() + self.element_end('ret') + + return value + + def parse_value(self): + expected_tokens = ('null', 'bool', 'int', 'uint', 'float', 'string', 'enum', 'array', 'struct', 'ptr', 'bytes') + if self.token.type == ELEMENT_START: + if self.token.name_or_data in expected_tokens: + method = getattr(self, 'parse_' + self.token.name_or_data) + return method() + raise TokenMismatch(" or " .join(expected_tokens), self.token) + + def parse_null(self): + self.element_start('null') + self.element_end('null') + return Literal(None) + + def parse_bool(self): + self.element_start('bool') + value = int(self.character_data()) + self.element_end('bool') + return Literal(value) + + def parse_int(self): + self.element_start('int') + value = int(self.character_data()) + self.element_end('int') + return Literal(value) + + def parse_uint(self): + self.element_start('uint') + value = int(self.character_data()) + self.element_end('uint') + return Literal(value) + + def parse_float(self): + self.element_start('float') + value = float(self.character_data()) + self.element_end('float') + return Literal(value) + + def parse_enum(self): + self.element_start('enum') + name = self.character_data() + self.element_end('enum') + return NamedConstant(name) + + def parse_string(self): + self.element_start('string') + value = self.character_data() + self.element_end('string') + return Literal(value) + + def parse_bytes(self): + self.element_start('bytes') + value = binascii.a2b_hex(self.character_data()) + self.element_end('bytes') + return Literal(value) + + def parse_array(self): + self.element_start('array') + elems = [] + while self.token.type != ELEMENT_END: + elems.append(self.parse_elem()) + self.element_end('array') + return Array(elems) + + def parse_elem(self): + self.element_start('elem') + value = self.parse_value() + self.element_end('elem') + return value + + def parse_struct(self): + attrs = self.element_start('struct') + name = attrs['name'] + members = [] + while self.token.type != ELEMENT_END: + members.append(self.parse_member()) + self.element_end('struct') + return Struct(name, members) + + def parse_member(self): + attrs = self.element_start('member') + name = attrs['name'] + value = self.parse_value() + self.element_end('member') + + return name, value + + def parse_ptr(self): + self.element_start('ptr') + address = self.character_data() + self.element_end('ptr') + + return Pointer(address) + + def handle_call(self, call): + pass + + +class TraceDumper(TraceParser): + + def __init__(self, fp): + TraceParser.__init__(self, fp) + self.formatter = format.DefaultFormatter(sys.stdout) + self.pretty_printer = PrettyPrinter(self.formatter) + + def handle_call(self, call): + call.visit(self.pretty_printer) + self.formatter.newline() + + +class Main: + '''Common main class for all retrace command line utilities.''' + + def __init__(self): + pass + + def main(self): + optparser = self.get_optparser() + (options, args) = optparser.parse_args(sys.argv[1:]) + + if args: + for arg in args: + if arg.endswith('.gz'): + from gzip import GzipFile + stream = GzipFile(arg, 'rt') + elif arg.endswith('.bz2'): + from bz2 import BZ2File + stream = BZ2File(arg, 'rU') + else: + stream = open(arg, 'rt') + self.process_arg(stream, options) + else: + self.process_arg(stream, options) + + def get_optparser(self): + optparser = optparse.OptionParser( + usage="\n\t%prog [options] [traces] ...") + return optparser + + def process_arg(self, stream, options): + parser = TraceDumper(stream) + parser.parse() + + +if __name__ == '__main__': + Main().main() diff --git a/src/gallium/tests/python/retrace/parser.py b/src/gallium/tests/python/retrace/parser.py new file mode 100755 index 0000000..bd47c9a --- /dev/null +++ b/src/gallium/tests/python/retrace/parser.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +########################################################################## +# +# 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. +# +########################################################################## + + +from parse import * + + +if __name__ == '__main__': + Main().main() diff --git a/src/gallium/tests/python/samples/gs.py b/src/gallium/tests/python/samples/gs.py new file mode 100644 index 0000000..936c0b3 --- /dev/null +++ b/src/gallium/tests/python/samples/gs.py @@ -0,0 +1,254 @@ +#!/usr/bin/env python +########################################################################## +# +# Copyright 2009 VMware +# 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. +# +########################################################################## + + +from gallium import * + + +def make_image(surface): + data = surface.get_tile_rgba8(0, 0, surface.width, surface.height) + + import Image + outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1) + return outimage + +def save_image(filename, surface): + outimage = make_image(surface) + outimage.save(filename, "PNG") + +def show_image(surface): + outimage = make_image(surface) + + import Tkinter as tk + from PIL import Image, ImageTk + root = tk.Tk() + + root.title('background image') + + image1 = ImageTk.PhotoImage(outimage) + w = image1.width() + h = image1.height() + x = 100 + y = 100 + root.geometry("%dx%d+%d+%d" % (w, h, x, y)) + panel1 = tk.Label(root, image=image1) + panel1.pack(side='top', fill='both', expand='yes') + panel1.image = image1 + root.mainloop() + + +def test(dev): + ctx = dev.context_create() + + width = 255 + height = 255 + minz = 0.0 + maxz = 1.0 + + # disabled blending/masking + blend = Blend() + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.rt[0].colormask = PIPE_MASK_RGBA + ctx.set_blend(blend) + + # depth/stencil/alpha + depth_stencil_alpha = DepthStencilAlpha() + depth_stencil_alpha.depth.enabled = 1 + depth_stencil_alpha.depth.writemask = 1 + depth_stencil_alpha.depth.func = PIPE_FUNC_LESS + ctx.set_depth_stencil_alpha(depth_stencil_alpha) + + # rasterizer + rasterizer = Rasterizer() + rasterizer.front_winding = PIPE_WINDING_CW + rasterizer.cull_mode = PIPE_WINDING_NONE + rasterizer.scissor = 1 + ctx.set_rasterizer(rasterizer) + + # viewport + viewport = Viewport() + scale = FloatArray(4) + scale[0] = width / 2.0 + scale[1] = -height / 2.0 + scale[2] = (maxz - minz) / 2.0 + scale[3] = 1.0 + viewport.scale = scale + translate = FloatArray(4) + translate[0] = width / 2.0 + translate[1] = height / 2.0 + translate[2] = (maxz - minz) / 2.0 + translate[3] = 0.0 + viewport.translate = translate + ctx.set_viewport(viewport) + + # samplers + sampler = Sampler() + sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE + sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.normalized_coords = 1 + ctx.set_sampler(0, sampler) + + # scissor + scissor = Scissor() + scissor.minx = 0 + scissor.miny = 0 + scissor.maxx = width + scissor.maxy = height + ctx.set_scissor(scissor) + + clip = Clip() + clip.nr = 0 + ctx.set_clip(clip) + + # framebuffer + cbuf = dev.resource_create( + PIPE_FORMAT_B8G8R8X8_UNORM, + width, height, + bind=PIPE_BIND_RENDER_TARGET, + ).get_surface() + zbuf = dev.resource_create( + PIPE_FORMAT_Z32_UNORM, + width, height, + bind=PIPE_BIND_DEPTH_STENCIL, + ).get_surface() + fb = Framebuffer() + fb.width = width + fb.height = height + fb.nr_cbufs = 1 + fb.set_cbuf(0, cbuf) + fb.set_zsbuf(zbuf) + ctx.set_framebuffer(fb) + rgba = FloatArray(4); + rgba[0] = 0.0 + rgba[1] = 0.0 + rgba[2] = 0.0 + rgba[3] = 0.0 + ctx.clear(PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL, rgba, 1.0, 0xff) + + # vertex shader + vs = Shader(''' + VERT + DCL IN[0], POSITION, CONSTANT + DCL IN[1], COLOR, CONSTANT + DCL OUT[0], POSITION, CONSTANT + DCL OUT[1], COLOR, CONSTANT + 0:MOV OUT[0], IN[0] + 1:MOV OUT[1], IN[1] + 2:END + ''') + ctx.set_vertex_shader(vs) + + gs = Shader(''' + GEOM + PROPERTY GS_INPUT_PRIMITIVE TRIANGLES + PROPERTY GS_OUTPUT_PRIMITIVE TRIANGLE_STRIP + DCL IN[][0], POSITION, CONSTANT + DCL IN[][1], COLOR, CONSTANT + DCL OUT[0], POSITION, CONSTANT + DCL OUT[1], COLOR, CONSTANT + 0:MOV OUT[0], IN[0][0] + 1:MOV OUT[1], IN[0][1] + 2:EMIT + 3:MOV OUT[0], IN[1][0] + 4:MOV OUT[1], IN[1][1] + 5:EMIT + 6:MOV OUT[0], IN[2][0] + 7:MOV OUT[1], IN[2][1] + 8:EMIT + 9:ENDPRIM + 10:END + ''') + ctx.set_geometry_shader(gs) + + # fragment shader + fs = Shader(''' + FRAG + DCL IN[0], COLOR, LINEAR + DCL OUT[0], COLOR, CONSTANT + 0:MOV OUT[0], IN[0] + 1:END + ''') + ctx.set_fragment_shader(fs) + + nverts = 3 + nattrs = 2 + verts = FloatArray(nverts * nattrs * 4) + + verts[ 0] = 0.0 # x1 + verts[ 1] = 0.8 # y1 + verts[ 2] = 0.2 # z1 + verts[ 3] = 1.0 # w1 + verts[ 4] = 1.0 # r1 + verts[ 5] = 0.0 # g1 + verts[ 6] = 0.0 # b1 + verts[ 7] = 1.0 # a1 + verts[ 8] = -0.8 # x2 + verts[ 9] = -0.8 # y2 + verts[10] = 0.5 # z2 + verts[11] = 1.0 # w2 + verts[12] = 0.0 # r2 + verts[13] = 1.0 # g2 + verts[14] = 0.0 # b2 + verts[15] = 1.0 # a2 + verts[16] = 0.8 # x3 + verts[17] = -0.8 # y3 + verts[18] = 0.8 # z3 + verts[19] = 1.0 # w3 + verts[20] = 0.0 # r3 + verts[21] = 0.0 # g3 + verts[22] = 1.0 # b3 + verts[23] = 1.0 # a3 + + ctx.draw_vertices(PIPE_PRIM_TRIANGLES, + nverts, + nattrs, + verts) + + ctx.flush() + + show_image(cbuf) + #show_image(zbuf) + #save_image('cbuf.png', cbuf) + #save_image('zbuf.png', zbuf) + + + +def main(): + dev = Device() + test(dev) + + +if __name__ == '__main__': + main() diff --git a/src/gallium/tests/python/samples/tri.py b/src/gallium/tests/python/samples/tri.py new file mode 100644 index 0000000..6d17c88 --- /dev/null +++ b/src/gallium/tests/python/samples/tri.py @@ -0,0 +1,233 @@ +#!/usr/bin/env python +########################################################################## +# +# 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. +# +########################################################################## + + +from gallium import * + + +def make_image(ctx, surface): + data = ctx.surface_read_rgba8(surface, 0, 0, surface.width, surface.height) + + import Image + outimage = Image.fromstring('RGBA', (surface.width, surface.height), data, "raw", 'RGBA', 0, 1) + return outimage + +def save_image(ctx, surface, filename): + outimage = make_image(ctx, surface) + outimage.save(filename, "PNG") + +def show_image(ctx, surface): + outimage = make_image(ctx, surface) + + import Tkinter as tk + from PIL import Image, ImageTk + root = tk.Tk() + + root.title('background image') + + image1 = ImageTk.PhotoImage(outimage) + w = image1.width() + h = image1.height() + x = 100 + y = 100 + root.geometry("%dx%d+%d+%d" % (w, h, x, y)) + panel1 = tk.Label(root, image=image1) + panel1.pack(side='top', fill='both', expand='yes') + panel1.image = image1 + root.mainloop() + + +def test(dev): + ctx = dev.context_create() + + width = 255 + height = 255 + minz = 0.0 + maxz = 1.0 + + # disabled blending/masking + blend = Blend() + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.rt[0].colormask = PIPE_MASK_RGBA + ctx.set_blend(blend) + + # depth/stencil/alpha + depth_stencil_alpha = DepthStencilAlpha() + depth_stencil_alpha.depth.enabled = 1 + depth_stencil_alpha.depth.writemask = 1 + depth_stencil_alpha.depth.func = PIPE_FUNC_LESS + ctx.set_depth_stencil_alpha(depth_stencil_alpha) + + # rasterizer + rasterizer = Rasterizer() + rasterizer.front_ccw = False + rasterizer.cull_face = PIPE_FACE_NONE + rasterizer.scissor = 1 + ctx.set_rasterizer(rasterizer) + + # viewport + viewport = Viewport() + scale = FloatArray(4) + scale[0] = width / 2.0 + scale[1] = -height / 2.0 + scale[2] = (maxz - minz) / 2.0 + scale[3] = 1.0 + viewport.scale = scale + translate = FloatArray(4) + translate[0] = width / 2.0 + translate[1] = height / 2.0 + translate[2] = (maxz - minz) / 2.0 + translate[3] = 0.0 + viewport.translate = translate + ctx.set_viewport(viewport) + + # samplers + sampler = Sampler() + sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE + sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.normalized_coords = 1 + ctx.set_fragment_sampler(0, sampler) + + # scissor + scissor = Scissor() + scissor.minx = 0 + scissor.miny = 0 + scissor.maxx = width + scissor.maxy = height + ctx.set_scissor(scissor) + + # clip + clip = Clip() + clip.nr = 0 + ctx.set_clip(clip) + + # framebuffer + cbuf = dev.resource_create( + PIPE_FORMAT_B8G8R8X8_UNORM, + width, height, + bind=PIPE_BIND_RENDER_TARGET, + ).get_surface() + zbuf = dev.resource_create( + PIPE_FORMAT_Z32_UNORM, + width, height, + bind=PIPE_BIND_DEPTH_STENCIL, + ).get_surface() + fb = Framebuffer() + fb.width = width + fb.height = height + fb.nr_cbufs = 1 + fb.set_cbuf(0, cbuf) + fb.set_zsbuf(zbuf) + ctx.set_framebuffer(fb) + rgba = FloatArray(4); + rgba[0] = 0.0 + rgba[1] = 0.0 + rgba[2] = 0.0 + rgba[3] = 0.0 + ctx.clear(PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL, rgba, 1.0, 0xff) + + # vertex shader + vs = Shader(''' + VERT + DCL IN[0] + DCL IN[1] + DCL OUT[0], POSITION, CONSTANT + DCL OUT[1], COLOR, CONSTANT + 0:MOV OUT[0], IN[0] + 1:MOV OUT[1], IN[1] + 2:END + ''') + ctx.set_vertex_shader(vs) + + # fragment shader + fs = Shader(''' + FRAG + DCL IN[0], COLOR, LINEAR + DCL OUT[0], COLOR, CONSTANT + 0:MOV OUT[0], IN[0] + 1:END + ''') + ctx.set_fragment_shader(fs) + + nverts = 3 + nattrs = 2 + verts = FloatArray(nverts * nattrs * 4) + + verts[ 0] = 0.0 # x1 + verts[ 1] = 0.8 # y1 + verts[ 2] = 0.2 # z1 + verts[ 3] = 1.0 # w1 + verts[ 4] = 1.0 # r1 + verts[ 5] = 0.0 # g1 + verts[ 6] = 0.0 # b1 + verts[ 7] = 1.0 # a1 + verts[ 8] = -0.8 # x2 + verts[ 9] = -0.8 # y2 + verts[10] = 0.5 # z2 + verts[11] = 1.0 # w2 + verts[12] = 0.0 # r2 + verts[13] = 1.0 # g2 + verts[14] = 0.0 # b2 + verts[15] = 1.0 # a2 + verts[16] = 0.8 # x3 + verts[17] = -0.8 # y3 + verts[18] = 0.8 # z3 + verts[19] = 1.0 # w3 + verts[20] = 0.0 # r3 + verts[21] = 0.0 # g3 + verts[22] = 1.0 # b3 + verts[23] = 1.0 # a3 + + ctx.draw_vertices(PIPE_PRIM_TRIANGLES, + nverts, + nattrs, + verts) + + ctx.flush() + + show_image(ctx, cbuf) + show_image(ctx, zbuf) + save_image(ctx, cbuf, 'cbuf.png') + save_image(ctx, zbuf, 'zbuf.png') + + + +def main(): + dev = Device() + test(dev) + + +if __name__ == '__main__': + main() diff --git a/src/gallium/tests/python/tests/base.py b/src/gallium/tests/python/tests/base.py new file mode 100755 index 0000000..d8cf84d --- /dev/null +++ b/src/gallium/tests/python/tests/base.py @@ -0,0 +1,399 @@ +#!/usr/bin/env python +########################################################################## +# +# Copyright 2009 VMware, Inc. +# 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 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. +# +########################################################################## + + +"""Base classes for tests. + +Loosely inspired on Python's unittest module. +""" + + +import os.path +import sys + +from gallium import * + + +# Enumerate all pixel formats +formats = {} +for name, value in globals().items(): + if name.startswith("PIPE_FORMAT_") and isinstance(value, int) and name not in ("PIPE_FORMAT_NONE", "PIPE_FORMAT_COUNT"): + formats[value] = name + +def make_image(width, height, rgba): + import Image + outimage = Image.new( + mode='RGB', + size=(width, height), + color=(0,0,0)) + outpixels = outimage.load() + for y in range(0, height): + for x in range(0, width): + offset = (y*width + x)*4 + r, g, b, a = [int(min(max(rgba[offset + ch], 0.0), 1.0)*255) for ch in range(4)] + outpixels[x, y] = r, g, b + return outimage + +def save_image(width, height, rgba, filename): + outimage = make_image(width, height, rgba) + outimage.save(filename, "PNG") + +def show_image(width, height, **rgbas): + import Tkinter as tk + from PIL import Image, ImageTk + + root = tk.Tk() + + x = 64 + y = 64 + + labels = rgbas.keys() + labels.sort() + for i in range(len(labels)): + label = labels[i] + outimage = make_image(width, height, rgbas[label]) + + if i: + window = tk.Toplevel(root) + else: + window = root + window.title(label) + image1 = ImageTk.PhotoImage(outimage) + w = image1.width() + h = image1.height() + window.geometry("%dx%d+%d+%d" % (w, h, x, y)) + panel1 = tk.Label(window, image=image1) + panel1.pack(side='top', fill='both', expand='yes') + panel1.image = image1 + x += w + 2 + + root.mainloop() + + +class TestFailure(Exception): + + pass + +class TestSkip(Exception): + + pass + + +class Test: + + def __init__(self): + pass + + def _run(self, result): + raise NotImplementedError + + def run(self): + result = TestResult() + self._run(result) + result.report() + + def assert_rgba(self, ctx, surface, x, y, w, h, expected_rgba, pixel_tol=4.0/256, surface_tol=0.85): + total = h*w + different = ctx.surface_compare_rgba(surface, x, y, w, h, expected_rgba, tol=pixel_tol) + if different: + sys.stderr.write("%u out of %u pixels differ\n" % (different, total)) + + if float(total - different)/float(total) < surface_tol: + if 0: + rgba = FloatArray(h*w*4) + ctx.surface_read_rgba(surface, x, y, w, h, rgba) + show_image(w, h, Result=rgba, Expected=expected_rgba) + save_image(w, h, rgba, "result.png") + save_image(w, h, expected_rgba, "expected.png") + #sys.exit(0) + + raise TestFailure + + +class TestCase(Test): + + tags = () + + def __init__(self, dev, **kargs): + Test.__init__(self) + self.dev = dev + self.__dict__.update(kargs) + + def description(self): + descriptions = [] + for tag in self.tags: + value = self.get(tag) + if value is not None and value != '': + descriptions.append(tag + '=' + str(value)) + return ' '.join(descriptions) + + def get(self, tag): + try: + method = getattr(self, '_get_' + tag) + except AttributeError: + return getattr(self, tag, None) + else: + return method() + + def _get_target(self): + return { + PIPE_TEXTURE_1D: "1d", + PIPE_TEXTURE_2D: "2d", + PIPE_TEXTURE_3D: "3d", + PIPE_TEXTURE_CUBE: "cube", + }[self.target] + + def _get_format(self): + name = formats[self.format] + if name.startswith('PIPE_FORMAT_'): + name = name[12:] + name = name.lower() + return name + + def _get_face(self): + if self.target == PIPE_TEXTURE_CUBE: + return { + PIPE_TEX_FACE_POS_X: "+x", + PIPE_TEX_FACE_NEG_X: "-x", + PIPE_TEX_FACE_POS_Y: "+y", + PIPE_TEX_FACE_NEG_Y: "-y", + PIPE_TEX_FACE_POS_Z: "+z", + PIPE_TEX_FACE_NEG_Z: "-z", + }[self.face] + else: + return '' + + def test(self): + raise NotImplementedError + + def _run(self, result): + result.test_start(self) + try: + self.test() + except KeyboardInterrupt: + raise + except TestSkip: + result.test_skipped(self) + except TestFailure: + result.test_failed(self) + else: + result.test_passed(self) + + +class TestSuite(Test): + + def __init__(self, tests = None): + Test.__init__(self) + if tests is None: + self.tests = [] + else: + self.tests = tests + + def add_test(self, test): + self.tests.append(test) + + def _run(self, result): + for test in self.tests: + test._run(result) + + +class TestResult: + + def __init__(self): + self.tests = 0 + self.passed = 0 + self.skipped = 0 + self.failed = 0 + + self.names = ['result'] + self.types = ['pass skip fail'] + self.rows = [] + + def test_start(self, test): + sys.stdout.write("Running %s...\n" % test.description()) + sys.stdout.flush() + self.tests += 1 + + def test_passed(self, test): + sys.stdout.write("PASS\n") + sys.stdout.flush() + self.passed += 1 + self.log_result(test, 'pass') + + def test_skipped(self, test): + sys.stdout.write("SKIP\n") + sys.stdout.flush() + self.skipped += 1 + self.log_result(test, 'skip') + + def test_failed(self, test): + sys.stdout.write("FAIL\n") + sys.stdout.flush() + self.failed += 1 + self.log_result(test, 'fail') + + def log_result(self, test, result): + row = ['']*len(self.names) + + # add result + assert self.names[0] == 'result' + assert result in ('pass', 'skip', 'fail') + row[0] = result + + # add tags + for tag in test.tags: + value = test.get(tag) + + # infer type + if value is None: + continue + elif isinstance(value, (int, float)): + value = str(value) + type = 'c' # continous + elif isinstance(value, basestring): + type = 'd' # discrete + else: + assert False + value = str(value) + type = 'd' # discrete + + # insert value + try: + col = self.names.index(tag, 1) + except ValueError: + self.names.append(tag) + self.types.append(type) + row.append(value) + else: + row[col] = value + assert self.types[col] == type + + self.rows.append(row) + + def report(self): + sys.stdout.write("%u tests, %u passed, %u skipped, %u failed\n\n" % (self.tests, self.passed, self.skipped, self.failed)) + sys.stdout.flush() + + name, ext = os.path.splitext(os.path.basename(sys.argv[0])) + + tree = self.report_tree(name) + self.report_junit(name, stdout=tree) + + def report_tree(self, name): + filename = name + '.tsv' + stream = file(filename, 'wt') + + # header + stream.write('\t'.join(self.names) + '\n') + stream.write('\t'.join(self.types) + '\n') + stream.write('class\n') + + # rows + for row in self.rows: + if row[0] == 'skip': + continue + row += ['']*(len(self.names) - len(row)) + stream.write('\t'.join(row) + '\n') + + stream.close() + + # See http://www.ailab.si/orange/doc/ofb/c_otherclass.htm + try: + import orange + import orngTree + except ImportError: + sys.stderr.write('Install Orange from http://www.ailab.si/orange/ for a classification tree.\n') + return None + + data = orange.ExampleTable(filename) + + tree = orngTree.TreeLearner(data, sameMajorityPruning=1, mForPruning=2) + + orngTree.printTxt(tree, maxDepth=4) + + text_tree = orngTree.dumpTree(tree) + + file(name + '.txt', 'wt').write(text_tree) + + orngTree.printDot(tree, fileName=name+'.dot', nodeShape='ellipse', leafShape='box') + + return text_tree + + def report_junit(self, name, stdout=None, stderr=None): + """Write test results in ANT's junit XML format, to use with Hudson CI. + + See also: + - http://fisheye.hudson-ci.org/browse/Hudson/trunk/hudson/main/core/src/test/resources/hudson/tasks/junit + - http://www.junit.org/node/399 + - http://wiki.apache.org/ant/Proposals/EnhancedTestReports + """ + + stream = file(name + '.xml', 'wt') + + stream.write('\n') + stream.write('\n' % self.escape_xml(name)) + stream.write(' \n') + stream.write(' \n') + + names = self.names[1:] + + for row in self.rows: + + test_name = ' '.join(['%s=%s' % pair for pair in zip(self.names[1:], row[1:])]) + + stream.write(' \n' % (self.escape_xml(test_name))) + + result = row[0] + if result == 'pass': + pass + elif result == 'skip': + stream.write(' \n') + else: + stream.write(' \n') + + stream.write(' \n') + + if stdout: + stream.write(' %s\n' % self.escape_xml(stdout)) + if stderr: + stream.write(' %s\n' % self.escape_xml(stderr)) + + stream.write('\n') + + stream.close() + + def escape_xml(self, s): + '''Escape a XML string.''' + s = s.replace('&', '&') + s = s.replace('<', '<') + s = s.replace('>', '>') + s = s.replace('"', '"') + s = s.replace("'", ''') + return s + diff --git a/src/gallium/tests/python/tests/surface_copy.py b/src/gallium/tests/python/tests/surface_copy.py new file mode 100755 index 0000000..7a6ede3 --- /dev/null +++ b/src/gallium/tests/python/tests/surface_copy.py @@ -0,0 +1,201 @@ +#!/usr/bin/env python +########################################################################## +# +# 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. +# +########################################################################## + + +import os +import random + +from gallium import * +from base import * + + +def lods(*dims): + size = max(dims) + lods = 0 + while size: + lods += 1 + size >>= 1 + return lods + + +class TextureTest(TestCase): + + tags = ( + 'target', + 'format', + 'width', + 'height', + 'depth', + 'last_level', + 'face', + 'level', + 'zslice', + ) + + def test(self): + dev = self.dev + ctx = self.ctx + + target = self.target + format = self.format + width = self.width + height = self.height + depth = self.depth + last_level = self.last_level + face = self.face + level = self.level + zslice = self.zslice + + bind = PIPE_BIND_SAMPLER_VIEW + geom_flags = 0 + sample_count = 0 + if not dev.is_format_supported(format, target, sample_count, bind, geom_flags): + raise TestSkip + + if not dev.is_format_supported(format, target, sample_count, bind, geom_flags): + raise TestSkip + + # textures + dst_texture = dev.resource_create( + target = target, + format = format, + width = width, + height = height, + depth = depth, + last_level = last_level, + bind = bind, + ) + + dst_surface = dst_texture.get_surface(face = face, level = level, zslice = zslice) + + src_texture = dev.resource_create( + target = target, + format = format, + width = dst_surface.width, + height = dst_surface.height, + depth = 1, + last_level = 0, + bind = PIPE_BIND_SAMPLER_VIEW, + ) + + src_surface = src_texture.get_surface() + + w = dst_surface.width + h = dst_surface.height + + stride = util_format_get_stride(format, w) + size = util_format_get_nblocksy(format, h) * stride + src_raw = os.urandom(size) + + ctx.surface_write_raw(src_surface, 0, 0, w, h, src_raw, stride) + + ctx.surface_copy(dst_surface, 0, 0, + src_surface, 0, 0, w, h) + + dst_raw = ctx.surface_read_raw(dst_surface, 0, 0, w, h) + + if dst_raw != src_raw: + raise TestFailure + + +def main(): + dev = Device() + ctx = dev.context_create() + suite = TestSuite() + + targets = [ + PIPE_TEXTURE_2D, + PIPE_TEXTURE_CUBE, + PIPE_TEXTURE_3D, + ] + + sizes = [64, 32, 16, 8, 4, 2, 1] + #sizes = [1020, 508, 252, 62, 30, 14, 6, 3] + #sizes = [64] + #sizes = [63] + + faces = [ + PIPE_TEX_FACE_POS_X, + PIPE_TEX_FACE_NEG_X, + PIPE_TEX_FACE_POS_Y, + PIPE_TEX_FACE_NEG_Y, + PIPE_TEX_FACE_POS_Z, + PIPE_TEX_FACE_NEG_Z, + ] + + try: + n = int(sys.argv[1]) + except: + n = 10000 + + for i in range(n): + format = random.choice(formats.keys()) + if not util_format_is_depth_or_stencil(format): + is_depth_or_stencil = util_format_is_depth_or_stencil(format) + + if is_depth_or_stencil: + target = PIPE_TEXTURE_2D + else: + target = random.choice(targets) + + size = random.choice(sizes) + + if target == PIPE_TEXTURE_3D: + depth = size + else: + depth = 1 + + if target == PIPE_TEXTURE_CUBE: + face = random.choice(faces) + else: + face = PIPE_TEX_FACE_POS_X + + levels = lods(size) + last_level = random.randint(0, levels - 1) + level = random.randint(0, last_level) + zslice = random.randint(0, max(depth >> level, 1) - 1) + + test = TextureTest( + dev = dev, + ctx = ctx, + target = target, + format = format, + width = size, + height = size, + depth = depth, + last_level = last_level, + face = face, + level = level, + zslice = zslice, + ) + suite.add_test(test) + suite.run() + + +if __name__ == '__main__': + main() diff --git a/src/gallium/tests/python/tests/texture_blit.py b/src/gallium/tests/python/tests/texture_blit.py new file mode 100755 index 0000000..089d05c --- /dev/null +++ b/src/gallium/tests/python/tests/texture_blit.py @@ -0,0 +1,638 @@ +#!/usr/bin/env python +########################################################################## +# +# Copyright 2009 VMware, Inc. +# 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 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. +# +########################################################################## + + +import random + +from gallium import * +from base import * + + +def lods(*dims): + size = max(dims) + lods = 0 + while size: + lods += 1 + size >>= 1 + return lods + + +def minify(dims, level = 1): + return [max(dim>>level, 1) for dim in dims] + + +def tex_coords(texture, face, level, zslice): + st = [ + [0.0, 0.0], + [1.0, 0.0], + [1.0, 1.0], + [0.0, 1.0], + ] + + if texture.target == PIPE_TEXTURE_2D or texture.target == PIPE_TEXTURE_RECT: + return [[s, t, 0.0] for s, t in st] + elif texture.target == PIPE_TEXTURE_3D: + depth = texture.get_depth(level) + if depth > 1: + r = float(zslice)/float(depth - 1) + else: + r = 0.0 + return [[s, t, r] for s, t in st] + elif texture.target == PIPE_TEXTURE_CUBE: + result = [] + for s, t in st: + # See http://developer.nvidia.com/object/cube_map_ogl_tutorial.html + sc = 2.0*s - 1.0 + tc = 2.0*t - 1.0 + if face == PIPE_TEX_FACE_POS_X: + rx = 1.0 + ry = -tc + rz = -sc + if face == PIPE_TEX_FACE_NEG_X: + rx = -1.0 + ry = -tc + rz = sc + if face == PIPE_TEX_FACE_POS_Y: + rx = sc + ry = 1.0 + rz = tc + if face == PIPE_TEX_FACE_NEG_Y: + rx = sc + ry = -1.0 + rz = -tc + if face == PIPE_TEX_FACE_POS_Z: + rx = sc + ry = -tc + rz = 1.0 + if face == PIPE_TEX_FACE_NEG_Z: + rx = -sc + ry = -tc + rz = -1.0 + result.append([rx, ry, rz]) + return result + +def is_pot(n): + return n & (n - 1) == 0 + + +class TextureColorSampleTest(TestCase): + + tags = ( + 'target', + 'format', + 'width', + 'height', + 'depth', + 'last_level', + 'face', + 'level', + 'zslice', + ) + + def test(self): + dev = self.dev + ctx = self.ctx + + target = self.target + format = self.format + width = self.width + height = self.height + depth = self.depth + last_level = self.last_level + face = self.face + level = self.level + zslice = self.zslice + minz = 0.0 + maxz = 1.0 + + bind = PIPE_BIND_SAMPLER_VIEW + geom_flags = 0 + sample_count = 0 + if width != height: + geom_flags |= PIPE_TEXTURE_GEOM_NON_SQUARE + if not is_pot(width) or not is_pot(height) or not is_pot(depth): + geom_flags |= PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO + + if not dev.is_format_supported(format, target, sample_count, bind, geom_flags): + raise TestSkip + + # disabled blending/masking + blend = Blend() + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.rt[0].colormask = PIPE_MASK_RGBA + ctx.set_blend(blend) + + # no-op depth/stencil/alpha + depth_stencil_alpha = DepthStencilAlpha() + ctx.set_depth_stencil_alpha(depth_stencil_alpha) + + # rasterizer + rasterizer = Rasterizer() + rasterizer.front_winding = PIPE_WINDING_CW + rasterizer.cull_mode = PIPE_WINDING_NONE + ctx.set_rasterizer(rasterizer) + + # samplers + sampler = Sampler() + sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.normalized_coords = 1 + sampler.min_lod = 0 + sampler.max_lod = PIPE_MAX_TEXTURE_LEVELS - 1 + ctx.set_fragment_sampler(0, sampler) + + # texture + texture = dev.resource_create( + target = target, + format = format, + width = width, + height = height, + depth = depth, + last_level = last_level, + bind = bind, + ) + + expected_rgba = FloatArray(height*width*4) + surface = texture.get_surface( + face = face, + level = level, + zslice = zslice, + ) + + ctx.surface_sample_rgba(surface, expected_rgba, True) + + ctx.set_fragment_sampler_texture(0, texture) + + # viewport + viewport = Viewport() + scale = FloatArray(4) + scale[0] = width + scale[1] = height + scale[2] = (maxz - minz) / 2.0 + scale[3] = 1.0 + viewport.scale = scale + translate = FloatArray(4) + translate[0] = 0.0 + translate[1] = 0.0 + translate[2] = (maxz - minz) / 2.0 + translate[3] = 0.0 + viewport.translate = translate + ctx.set_viewport(viewport) + + # scissor + scissor = Scissor() + scissor.minx = 0 + scissor.miny = 0 + scissor.maxx = width + scissor.maxy = height + ctx.set_scissor(scissor) + + # clip + clip = Clip() + clip.nr = 0 + ctx.set_clip(clip) + + # framebuffer + cbuf_tex = dev.resource_create( + PIPE_FORMAT_B8G8R8A8_UNORM, + width, + height, + bind = PIPE_BIND_RENDER_TARGET, + ) + + cbuf = cbuf_tex.get_surface() + fb = Framebuffer() + fb.width = width + fb.height = height + fb.nr_cbufs = 1 + fb.set_cbuf(0, cbuf) + ctx.set_framebuffer(fb) + rgba = FloatArray(4); + rgba[0] = 0.5 + rgba[1] = 0.5 + rgba[2] = 0.5 + rgba[3] = 0.5 + ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0) + del fb + + # vertex shader + vs = Shader(''' + VERT + DCL IN[0], POSITION, CONSTANT + DCL IN[1], GENERIC, CONSTANT + DCL OUT[0], POSITION, CONSTANT + DCL OUT[1], GENERIC, CONSTANT + 0:MOV OUT[0], IN[0] + 1:MOV OUT[1], IN[1] + 2:END + ''') + #vs.dump() + ctx.set_vertex_shader(vs) + + # fragment shader + op = { + PIPE_TEXTURE_1D: "1D", + PIPE_TEXTURE_2D: "2D", + PIPE_TEXTURE_3D: "3D", + PIPE_TEXTURE_CUBE: "CUBE", + }[target] + fs = Shader(''' + FRAG + DCL IN[0], GENERIC[0], LINEAR + DCL OUT[0], COLOR, CONSTANT + DCL SAMP[0], CONSTANT + 0:TEX OUT[0], IN[0], SAMP[0], %s + 1:END + ''' % op) + #fs.dump() + ctx.set_fragment_shader(fs) + + nverts = 4 + nattrs = 2 + verts = FloatArray(nverts * nattrs * 4) + + x = 0 + y = 0 + w, h = minify((width, height), level) + + pos = [ + [x, y], + [x+w, y], + [x+w, y+h], + [x, y+h], + ] + + tex = tex_coords(texture, face, level, zslice) + + for i in range(0, 4): + j = 8*i + verts[j + 0] = pos[i][0]/float(width) # x + verts[j + 1] = pos[i][1]/float(height) # y + verts[j + 2] = 0.0 # z + verts[j + 3] = 1.0 # w + verts[j + 4] = tex[i][0] # s + verts[j + 5] = tex[i][1] # r + verts[j + 6] = tex[i][2] # q + verts[j + 7] = 1.0 + + ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN, + nverts, + nattrs, + verts) + + ctx.flush() + + cbuf = cbuf_tex.get_surface() + + self.assert_rgba(ctx, cbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85) + + +class TextureDepthSampleTest(TestCase): + + tags = ( + 'target', + 'format', + 'width', + 'height', + 'depth', + 'last_level', + 'face', + 'level', + 'zslice', + ) + + def test(self): + dev = self.dev + ctx = self.ctx + + target = self.target + format = self.format + width = self.width + height = self.height + depth = self.depth + last_level = self.last_level + face = self.face + level = self.level + zslice = self.zslice + minz = 0.0 + maxz = 1.0 + + bind = PIPE_BIND_SAMPLER_VIEW + geom_flags = 0 + sample_count = 0 + if width != height: + geom_flags |= PIPE_TEXTURE_GEOM_NON_SQUARE + if not is_pot(width) or not is_pot(height) or not is_pot(depth): + geom_flags |= PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO + + if not dev.is_format_supported(format, target, sample_count, bind, geom_flags): + raise TestSkip + + # disabled blending/masking + blend = Blend() + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.rt[0].colormask = PIPE_MASK_RGBA + ctx.set_blend(blend) + + # depth/stencil/alpha + depth_stencil_alpha = DepthStencilAlpha() + depth_stencil_alpha.depth.enabled = 1 + depth_stencil_alpha.depth.writemask = 1 + depth_stencil_alpha.depth.func = PIPE_FUNC_LESS + ctx.set_depth_stencil_alpha(depth_stencil_alpha) + + # rasterizer + rasterizer = Rasterizer() + rasterizer.front_winding = PIPE_WINDING_CW + rasterizer.cull_mode = PIPE_WINDING_NONE + ctx.set_rasterizer(rasterizer) + + # viewport + viewport = Viewport() + scale = FloatArray(4) + scale[0] = width + scale[1] = height + scale[2] = (maxz - minz) / 2.0 + scale[3] = 1.0 + viewport.scale = scale + translate = FloatArray(4) + translate[0] = 0.0 + translate[1] = 0.0 + translate[2] = (maxz - minz) / 2.0 + translate[3] = 0.0 + viewport.translate = translate + ctx.set_viewport(viewport) + + # samplers + sampler = Sampler() + sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.normalized_coords = 1 + sampler.min_lod = 0 + sampler.max_lod = PIPE_MAX_TEXTURE_LEVELS - 1 + ctx.set_fragment_sampler(0, sampler) + + # texture + texture = dev.resource_create( + target = target, + format = format, + width = width, + height = height, + depth = depth, + last_level = last_level, + bind = bind, + ) + + expected_rgba = FloatArray(height*width*4) + surface = texture.get_surface( + face = face, + level = level, + zslice = zslice, + ) + + ctx.surface_sample_rgba(surface, expected_rgba, True) + + ctx.set_fragment_sampler_texture(0, texture) + + # scissor + scissor = Scissor() + scissor.minx = 0 + scissor.miny = 0 + scissor.maxx = width + scissor.maxy = height + ctx.set_scissor(scissor) + + # clip + clip = Clip() + clip.nr = 0 + ctx.set_clip(clip) + + # framebuffer + cbuf_tex = dev.resource_create( + PIPE_FORMAT_B8G8R8A8_UNORM, + width, + height, + bind = PIPE_BIND_RENDER_TARGET, + ) + + zsbuf_tex = dev.resource_create( + PIPE_FORMAT_X8Z24_UNORM, + width, + height, + bind = PIPE_BIND_RENDER_TARGET, + ) + + cbuf = cbuf_tex.get_surface() + zsbuf = zsbuf_tex.get_surface() + fb = Framebuffer() + fb.width = width + fb.height = height + fb.nr_cbufs = 1 + fb.set_cbuf(0, cbuf) + fb.set_zsbuf(zsbuf) + ctx.set_framebuffer(fb) + rgba = FloatArray(4); + rgba[0] = 0.5 + rgba[1] = 0.5 + rgba[2] = 0.5 + rgba[3] = 0.5 + ctx.clear(PIPE_CLEAR_DEPTHSTENCIL, rgba, 1.0, 0) + del fb + + # vertex shader + vs = Shader(''' + VERT + DCL IN[0], POSITION, CONSTANT + DCL IN[1], GENERIC, CONSTANT + DCL OUT[0], POSITION, CONSTANT + DCL OUT[1], GENERIC, CONSTANT + 0:MOV OUT[0], IN[0] + 1:MOV OUT[1], IN[1] + 2:END + ''') + #vs.dump() + ctx.set_vertex_shader(vs) + + # fragment shader + op = { + PIPE_TEXTURE_1D: "1D", + PIPE_TEXTURE_2D: "2D", + PIPE_TEXTURE_3D: "3D", + PIPE_TEXTURE_CUBE: "CUBE", + }[target] + fs = Shader(''' + FRAG + DCL IN[0], GENERIC[0], LINEAR + DCL SAMP[0], CONSTANT + DCL OUT[0].z, POSITION + 0:TEX OUT[0].z, IN[0], SAMP[0], %s + 1:END + ''' % op) + #fs.dump() + ctx.set_fragment_shader(fs) + + nverts = 4 + nattrs = 2 + verts = FloatArray(nverts * nattrs * 4) + + x = 0 + y = 0 + w, h = minify((width, height), level) + + pos = [ + [x, y], + [x+w, y], + [x+w, y+h], + [x, y+h], + ] + + tex = tex_coords(texture, face, level, zslice) + + for i in range(0, 4): + j = 8*i + verts[j + 0] = pos[i][0]/float(width) # x + verts[j + 1] = pos[i][1]/float(height) # y + verts[j + 2] = 0.0 # z + verts[j + 3] = 1.0 # w + verts[j + 4] = tex[i][0] # s + verts[j + 5] = tex[i][1] # r + verts[j + 6] = tex[i][2] # q + verts[j + 7] = 1.0 + + ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN, + nverts, + nattrs, + verts) + + ctx.flush() + + zsbuf = zsbuf_tex.get_surface() + + self.assert_rgba(ctx, zsbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85) + + + + +def main(): + random.seed(0xdead3eef) + + dev = Device() + ctx = dev.context_create() + suite = TestSuite() + + targets = [ + PIPE_TEXTURE_2D, + PIPE_TEXTURE_CUBE, + PIPE_TEXTURE_3D, + ] + + #sizes = [64, 32, 16, 8, 4, 2, 1] + #sizes = [1020, 508, 252, 62, 30, 14, 6, 3] + sizes = [64] + #sizes = [63] + + faces = [ + PIPE_TEX_FACE_POS_X, + PIPE_TEX_FACE_NEG_X, + PIPE_TEX_FACE_POS_Y, + PIPE_TEX_FACE_NEG_Y, + PIPE_TEX_FACE_POS_Z, + PIPE_TEX_FACE_NEG_Z, + ] + + try: + n = int(sys.argv[1]) + except: + n = 10000 + + for i in range(n): + format = random.choice(formats.keys()) + if not util_format_is_depth_or_stencil(format): + is_depth_or_stencil = util_format_is_depth_or_stencil(format) + + if is_depth_or_stencil: + target = PIPE_TEXTURE_2D + else: + target = random.choice(targets) + + size = random.choice(sizes) + + if target == PIPE_TEXTURE_3D: + depth = size + else: + depth = 1 + + if target == PIPE_TEXTURE_CUBE: + face = random.choice(faces) + else: + face = PIPE_TEX_FACE_POS_X + + levels = lods(size) + last_level = random.randint(0, levels - 1) + level = random.randint(0, last_level) + zslice = random.randint(0, max(depth >> level, 1) - 1) + + if is_depth_or_stencil: + klass = TextureDepthSampleTest + else: + klass = TextureColorSampleTest + + test = klass( + dev = dev, + ctx = ctx, + target = target, + format = format, + width = size, + height = size, + depth = depth, + last_level = last_level, + face = face, + level = level, + zslice = zslice, + ) + suite.add_test(test) + suite.run() + + +if __name__ == '__main__': + main() diff --git a/src/gallium/tests/python/tests/texture_render.py b/src/gallium/tests/python/tests/texture_render.py new file mode 100755 index 0000000..23f3d2a --- /dev/null +++ b/src/gallium/tests/python/tests/texture_render.py @@ -0,0 +1,320 @@ +#!/usr/bin/env python +########################################################################## +# +# 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. +# +########################################################################## + + +from gallium import * +from base import * + + +def lods(*dims): + size = max(dims) + lods = 0 + while size: + lods += 1 + size >>= 1 + return lods + + +class TextureTest(TestCase): + + tags = ( + 'target', + 'format', + 'width', + 'height', + 'depth', + 'last_level', + 'face', + 'level', + 'zslice', + ) + + def test(self): + dev = self.dev + + target = self.target + format = self.format + width = self.width + height = self.height + depth = self.depth + last_level = self.last_level + face = self.face + level = self.level + zslice = self.zslice + + # textures + dst_texture = dev.resource_create( + target = target, + format = format, + width = width, + height = height, + depth = depth, + last_level = last_level, + bind = PIPE_BIND_RENDER_TARGET, + ) + if dst_texture is None: + raise TestSkip + + dst_surface = dst_texture.get_surface(face = face, level = level, zslice = zslice) + + ref_texture = dev.resource_create( + target = target, + format = format, + width = dst_surface.width, + height = dst_surface.height, + depth = 1, + last_level = 0, + bind = PIPE_BIND_SAMPLER_VIEW, + ) + + ref_surface = ref_texture.get_surface() + + src_texture = dev.resource_create( + target = target, + format = PIPE_FORMAT_B8G8R8A8_UNORM, + width = dst_surface.width, + height = dst_surface.height, + depth = 1, + last_level = 0, + bind = PIPE_BIND_SAMPLER_VIEW, + ) + + src_surface = src_texture.get_surface() + + expected_rgba = FloatArray(height*width*4) + ref_surface.sample_rgba(expected_rgba) + + src_surface.put_tile_rgba(0, 0, src_surface.width, src_surface.height, expected_rgba) + + ctx = self.dev.context_create() + + # disabled blending/masking + blend = Blend() + blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE + blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE + blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO + blend.rt[0].colormask = PIPE_MASK_RGBA + ctx.set_blend(blend) + + # no-op depth/stencil/alpha + depth_stencil_alpha = DepthStencilAlpha() + ctx.set_depth_stencil_alpha(depth_stencil_alpha) + + # rasterizer + rasterizer = Rasterizer() + rasterizer.front_winding = PIPE_WINDING_CW + rasterizer.cull_mode = PIPE_WINDING_NONE + rasterizer.bypass_vs_clip_and_viewport = 1 + ctx.set_rasterizer(rasterizer) + + # samplers + sampler = Sampler() + sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST + sampler.normalized_coords = 1 + sampler.min_lod = 0 + sampler.max_lod = PIPE_MAX_TEXTURE_LEVELS - 1 + ctx.set_fragment_sampler(0, sampler) + ctx.set_fragment_sampler_texture(0, src_texture) + + # framebuffer + cbuf_tex = dev.resource_create( + PIPE_FORMAT_B8G8R8A8_UNORM, + width, + height, + bind = PIPE_BIND_RENDER_TARGET, + ) + + fb = Framebuffer() + fb.width = dst_surface.width + fb.height = dst_surface.height + fb.nr_cbufs = 1 + fb.set_cbuf(0, dst_surface) + ctx.set_framebuffer(fb) + rgba = FloatArray(4); + rgba[0] = 0.0 + rgba[1] = 0.0 + rgba[2] = 0.0 + rgba[3] = 0.0 + ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0) + del fb + + # vertex shader + vs = Shader(''' + VERT + DCL IN[0], POSITION, CONSTANT + DCL IN[1], GENERIC, CONSTANT + DCL OUT[0], POSITION, CONSTANT + DCL OUT[1], GENERIC, CONSTANT + 0:MOV OUT[0], IN[0] + 1:MOV OUT[1], IN[1] + 2:END + ''') + #vs.dump() + ctx.set_vertex_shader(vs) + + # fragment shader + fs = Shader(''' + FRAG + DCL IN[0], GENERIC[0], LINEAR + DCL OUT[0], COLOR, CONSTANT + DCL SAMP[0], CONSTANT + 0:TEX OUT[0], IN[0], SAMP[0], 2D + 1:END + ''') + #fs.dump() + ctx.set_fragment_shader(fs) + + nverts = 4 + nattrs = 2 + verts = FloatArray(nverts * nattrs * 4) + + x = 0 + y = 0 + w = dst_surface.width + h = dst_surface.height + + pos = [ + [x, y], + [x+w, y], + [x+w, y+h], + [x, y+h], + ] + + tex = [ + [0.0, 0.0], + [1.0, 0.0], + [1.0, 1.0], + [0.0, 1.0], + ] + + for i in range(0, 4): + j = 8*i + verts[j + 0] = pos[i][0] # x + verts[j + 1] = pos[i][1] # y + verts[j + 2] = 0.0 # z + verts[j + 3] = 1.0 # w + verts[j + 4] = tex[i][0] # s + verts[j + 5] = tex[i][1] # r + verts[j + 6] = 0.0 + verts[j + 7] = 1.0 + + ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN, + nverts, + nattrs, + verts) + + ctx.flush() + + self.assert_rgba(dst_surface, x, y, w, h, expected_rgba, 4.0/256, 0.85) + + + +def main(): + dev = Device() + suite = TestSuite() + + targets = [ + PIPE_TEXTURE_2D, + PIPE_TEXTURE_CUBE, + #PIPE_TEXTURE_3D, + ] + + formats = [ + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_B8G8R8X8_UNORM, + #PIPE_FORMAT_B8G8R8A8_SRGB, + PIPE_FORMAT_B5G6R5_UNORM, + PIPE_FORMAT_B5G5R5A1_UNORM, + PIPE_FORMAT_B4G4R4A4_UNORM, + #PIPE_FORMAT_Z32_UNORM, + #PIPE_FORMAT_S8_USCALED_Z24_UNORM, + #PIPE_FORMAT_X8Z24_UNORM, + #PIPE_FORMAT_Z16_UNORM, + #PIPE_FORMAT_S8_USCALED, + PIPE_FORMAT_A8_UNORM, + PIPE_FORMAT_L8_UNORM, + #PIPE_FORMAT_DXT1_RGB, + #PIPE_FORMAT_DXT1_RGBA, + #PIPE_FORMAT_DXT3_RGBA, + #PIPE_FORMAT_DXT5_RGBA, + ] + + sizes = [64, 32, 16, 8, 4, 2, 1] + #sizes = [1020, 508, 252, 62, 30, 14, 6, 3] + #sizes = [64] + #sizes = [63] + + faces = [ + PIPE_TEX_FACE_POS_X, + PIPE_TEX_FACE_NEG_X, + PIPE_TEX_FACE_POS_Y, + PIPE_TEX_FACE_NEG_Y, + PIPE_TEX_FACE_POS_Z, + PIPE_TEX_FACE_NEG_Z, + ] + + for target in targets: + for format in formats: + for size in sizes: + if target == PIPE_TEXTURE_3D: + depth = size + else: + depth = 1 + for face in faces: + if target != PIPE_TEXTURE_CUBE and face: + continue + levels = lods(size) + for last_level in range(levels): + for level in range(0, last_level + 1): + zslice = 0 + while zslice < depth >> level: + test = TextureTest( + dev = dev, + target = target, + format = format, + width = size, + height = size, + depth = depth, + last_level = last_level, + face = face, + level = level, + zslice = zslice, + ) + suite.add_test(test) + zslice = (zslice + 1)*2 - 1 + suite.run() + + +if __name__ == '__main__': + main() diff --git a/src/gallium/tests/python/tests/texture_transfer.py b/src/gallium/tests/python/tests/texture_transfer.py new file mode 100755 index 0000000..65c919b --- /dev/null +++ b/src/gallium/tests/python/tests/texture_transfer.py @@ -0,0 +1,182 @@ +#!/usr/bin/env python +########################################################################## +# +# Copyright 2009 VMware, Inc. +# 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 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. +# +########################################################################## + + +import os +import random + +from gallium import * +from base import * + + +def lods(*dims): + size = max(dims) + lods = 0 + while size: + lods += 1 + size >>= 1 + return lods + + +class TextureTest(TestCase): + + tags = ( + 'target', + 'format', + 'width', + 'height', + 'depth', + 'last_level', + 'face', + 'level', + 'zslice', + ) + + def test(self): + dev = self.dev + ctx = self.ctx + + target = self.target + format = self.format + width = self.width + height = self.height + depth = self.depth + last_level = self.last_level + face = self.face + level = self.level + zslice = self.zslice + + bind = PIPE_BIND_SAMPLER_VIEW + geom_flags = 0 + sample_count = 0 + if not dev.is_format_supported(format, target, sample_count, bind, geom_flags): + raise TestSkip + + # textures + texture = dev.resource_create( + target = target, + format = format, + width = width, + height = height, + depth = depth, + last_level = last_level, + bind = bind, + ) + + surface = texture.get_surface(face, level, zslice) + + stride = util_format_get_stride(format, surface.width) + size = util_format_get_nblocksy(format, surface.height) * stride + + in_raw = os.urandom(size) + + ctx.surface_write_raw(surface, 0, 0, surface.width, surface.height, in_raw, stride) + + out_raw = ctx.surface_read_raw(surface, 0, 0, surface.width, surface.height) + + if in_raw != out_raw: + raise TestFailure + + +def main(): + dev = Device() + ctx = dev.context_create() + suite = TestSuite() + + targets = [ + PIPE_TEXTURE_2D, + PIPE_TEXTURE_CUBE, + PIPE_TEXTURE_3D, + ] + + sizes = [64, 32, 16, 8, 4, 2, 1] + #sizes = [1020, 508, 252, 62, 30, 14, 6, 3] + #sizes = [64] + #sizes = [63] + + faces = [ + PIPE_TEX_FACE_POS_X, + PIPE_TEX_FACE_NEG_X, + PIPE_TEX_FACE_POS_Y, + PIPE_TEX_FACE_NEG_Y, + PIPE_TEX_FACE_POS_Z, + PIPE_TEX_FACE_NEG_Z, + ] + + try: + n = int(sys.argv[1]) + except: + n = 10000 + + for i in range(n): + format = random.choice(formats.keys()) + if not util_format_is_depth_or_stencil(format): + is_depth_or_stencil = util_format_is_depth_or_stencil(format) + + if is_depth_or_stencil: + target = PIPE_TEXTURE_2D + else: + target = random.choice(targets) + + size = random.choice(sizes) + + if target == PIPE_TEXTURE_3D: + depth = size + else: + depth = 1 + + if target == PIPE_TEXTURE_CUBE: + face = random.choice(faces) + else: + face = PIPE_TEX_FACE_POS_X + + levels = lods(size) + last_level = random.randint(0, levels - 1) + level = random.randint(0, last_level) + zslice = random.randint(0, max(depth >> level, 1) - 1) + + test = TextureTest( + dev = dev, + ctx = ctx, + target = target, + format = format, + width = size, + height = size, + depth = depth, + last_level = last_level, + face = face, + level = level, + zslice = zslice, + ) + suite.add_test(test) + suite.run() + + +if __name__ == '__main__': + main() diff --git a/src/gallium/tests/python/tests/tree.py b/src/gallium/tests/python/tests/tree.py new file mode 100755 index 0000000..0c1bcda --- /dev/null +++ b/src/gallium/tests/python/tests/tree.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# +# See also: +# http://www.ailab.si/orange/doc/ofb/c_otherclass.htm + +import os.path +import sys + +import orange +import orngTree + +for arg in sys.argv[1:]: + name, ext = os.path.splitext(arg) + + data = orange.ExampleTable(arg) + + tree = orngTree.TreeLearner(data, sameMajorityPruning=1, mForPruning=2) + + orngTree.printTxt(tree) + + file(name+'.txt', 'wt').write(orngTree.dumpTree(tree) + '\n') + + orngTree.printDot(tree, fileName=name+'.dot', nodeShape='ellipse', leafShape='box') diff --git a/src/gallium/tests/trivial/Makefile b/src/gallium/tests/trivial/Makefile new file mode 100644 index 0000000..2ed6341 --- /dev/null +++ b/src/gallium/tests/trivial/Makefile @@ -0,0 +1,49 @@ +# progs/gallium/simple/Makefile + +TOP = ../../../.. +include $(TOP)/configs/current + +INCLUDES = \ + -I. \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/winsys \ + $(PROG_INCLUDES) + +LINKS = \ + $(TOP)/src/gallium/drivers/rbug/librbug.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/galahad/libgalahad.a \ + $(TOP)/src/gallium/winsys/sw/null/libws_null.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(GALLIUM_AUXILIARIES) \ + $(PROG_LINKS) + +SOURCES = \ + tri.c \ + quad-tex.c + +OBJECTS = $(SOURCES:.c=.o) + +PROGS = $(OBJECTS:.o=) + +PROG_DEFINES = \ + -DGALLIUM_SOFTPIPE -DGALLIUM_RBUG -DGALLIUM_TRACE -DGALLIUM_GALAHAD + +##### TARGETS ##### + +default: $(PROGS) + +clean: + -rm -f $(PROGS) + -rm -f *.o + -rm -f result.bmp + +##### RULES ##### + +$(OBJECTS): %.o: %.c + $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $(PROG_DEFINES) $< -o $@ + +$(PROGS): %: %.o $(LINKS) + $(CC) $(LDFLAGS) $< $(LINKS) -lm -lpthread -ldl -o $@ diff --git a/src/gallium/tests/trivial/quad-tex.c b/src/gallium/tests/trivial/quad-tex.c new file mode 100644 index 0000000..92c5b4d --- /dev/null +++ b/src/gallium/tests/trivial/quad-tex.c @@ -0,0 +1,351 @@ +/************************************************************************** + * + * Copyright © 2010 Jakob Bornecrantz + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#define USE_TRACE 0 +#define WIDTH 300 +#define HEIGHT 300 +#define NEAR 30 +#define FAR 1000 +#define FLIP 0 + +/* pipe_*_state structs */ +#include "pipe/p_state.h" +/* pipe_context */ +#include "pipe/p_context.h" +/* pipe_screen */ +#include "pipe/p_screen.h" +/* PIPE_* */ +#include "pipe/p_defines.h" +/* TGSI_SEMANTIC_{POSITION|GENERIC} */ +#include "pipe/p_shader_tokens.h" +/* pipe_buffer_* helpers */ +#include "util/u_inlines.h" + +/* constant state object helper */ +#include "cso_cache/cso_context.h" + +/* u_sampler_view_default_template */ +#include "util/u_sampler.h" +/* debug_dump_surface_bmp */ +#include "util/u_debug.h" +/* util_draw_vertex_buffer helper */ +#include "util/u_draw_quad.h" +/* FREE & CALLOC_STRUCT */ +#include "util/u_memory.h" +/* util_make_[fragment|vertex]_passthrough_shader */ +#include "util/u_simple_shaders.h" + +/* sw_screen_create: to get a software pipe driver */ +#include "target-helpers/inline_sw_helper.h" +/* debug_screen_wrap: to wrap with debug pipe drivers */ +#include "target-helpers/inline_debug_helper.h" +/* null software winsys */ +#include "sw/null/null_sw_winsys.h" + +struct program +{ + struct pipe_screen *screen; + struct pipe_context *pipe; + struct cso_context *cso; + + struct pipe_blend_state blend; + struct pipe_depth_stencil_alpha_state depthstencil; + struct pipe_rasterizer_state rasterizer; + struct pipe_sampler_state sampler; + struct pipe_viewport_state viewport; + struct pipe_framebuffer_state framebuffer; + struct pipe_vertex_element velem[2]; + + void *vs; + void *fs; + + float clear_color[4]; + + struct pipe_resource *vbuf; + struct pipe_resource *target; + struct pipe_resource *tex; + struct pipe_sampler_view *view; +}; + +static void init_prog(struct program *p) +{ + struct pipe_surface surf_tmpl; + /* create the software rasterizer */ + p->screen = sw_screen_create(null_sw_create()); + /* wrap the screen with any debugger */ + p->screen = debug_screen_wrap(p->screen); + + /* create the pipe driver context and cso context */ + p->pipe = p->screen->context_create(p->screen, NULL); + p->cso = cso_create_context(p->pipe); + + /* set clear color */ + p->clear_color[0] = 0.3; + p->clear_color[1] = 0.1; + p->clear_color[2] = 0.3; + p->clear_color[3] = 1.0; + + /* vertex buffer */ + { + float vertices[4][2][4] = { + { + { 0.9f, 0.9f, 0.0f, 1.0f }, + { 1.0f, 1.0f, 0.0f, 1.0f } + }, + { + { -0.9f, 0.9f, 0.0f, 1.0f }, + { 0.0f, 1.0f, 0.0f, 1.0f } + }, + { + { -0.9f, -0.9f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f, 1.0f } + }, + { + { 0.9f, -0.9f, 0.0f, 1.0f }, + { 1.0f, 0.0f, 1.0f, 1.0f } + } + }; + + p->vbuf = pipe_buffer_create(p->screen, PIPE_BIND_VERTEX_BUFFER, sizeof(vertices)); + pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(vertices), vertices); + } + + /* render target texture */ + { + struct pipe_resource tmplt; + memset(&tmplt, 0, sizeof(tmplt)); + tmplt.target = PIPE_TEXTURE_2D; + tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */ + tmplt.width0 = WIDTH; + tmplt.height0 = HEIGHT; + tmplt.depth0 = 1; + tmplt.array_size = 1; + tmplt.last_level = 0; + tmplt.bind = PIPE_BIND_RENDER_TARGET; + + p->target = p->screen->resource_create(p->screen, &tmplt); + } + + /* sampler texture */ + { + uint32_t *ptr; + struct pipe_transfer *t; + struct pipe_resource t_tmplt; + struct pipe_sampler_view v_tmplt; + struct pipe_box box; + + memset(&t_tmplt, 0, sizeof(t_tmplt)); + t_tmplt.target = PIPE_TEXTURE_2D; + t_tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */ + t_tmplt.width0 = 2; + t_tmplt.height0 = 2; + t_tmplt.depth0 = 1; + t_tmplt.array_size = 1; + t_tmplt.last_level = 0; + t_tmplt.bind = PIPE_BIND_RENDER_TARGET; + + p->tex = p->screen->resource_create(p->screen, &t_tmplt); + + memset(&box, 0, sizeof(box)); + box.width = 2; + box.height = 2; + + t = p->pipe->get_transfer(p->pipe, p->tex, 0, PIPE_TRANSFER_WRITE, &box); + + ptr = p->pipe->transfer_map(p->pipe, t); + ptr[0] = 0xffff0000; + ptr[1] = 0xff0000ff; + ptr[2] = 0xff00ff00; + ptr[3] = 0xffffff00; + p->pipe->transfer_unmap(p->pipe, t); + + p->pipe->transfer_destroy(p->pipe, t); + + u_sampler_view_default_template(&v_tmplt, p->tex, p->tex->format); + + p->view = p->pipe->create_sampler_view(p->pipe, p->tex, &v_tmplt); + } + + /* disabled blending/masking */ + memset(&p->blend, 0, sizeof(p->blend)); + p->blend.rt[0].colormask = PIPE_MASK_RGBA; + + /* no-op depth/stencil/alpha */ + memset(&p->depthstencil, 0, sizeof(p->depthstencil)); + + /* rasterizer */ + memset(&p->rasterizer, 0, sizeof(p->rasterizer)); + p->rasterizer.cull_face = PIPE_FACE_NONE; + p->rasterizer.gl_rasterization_rules = 1; + + /* sampler */ + memset(&p->sampler, 0, sizeof(p->sampler)); + p->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + p->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + p->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + p->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + p->sampler.min_img_filter = PIPE_TEX_MIPFILTER_LINEAR; + p->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_LINEAR; + p->sampler.normalized_coords = 1; + + surf_tmpl.format = templat.format; + surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; + surf_tmpl.u.tex.level = 0; + surf_tmpl.u.tex.first_layer = 0; + surf_tmpl.u.tex.last_layer = 0; + /* drawing destination */ + memset(&p->framebuffer, 0, sizeof(p->framebuffer)); + p->framebuffer.width = WIDTH; + p->framebuffer.height = HEIGHT; + p->framebuffer.nr_cbufs = 1; + p->framebuffer.cbufs[0] = p->pipe->create_surface(p->pipe, p->target, &surf_tmpl); + + /* viewport, depth isn't really needed */ + { + float x = 0; + float y = 0; + float z = FAR; + float half_width = (float)WIDTH / 2.0f; + float half_height = (float)HEIGHT / 2.0f; + float half_depth = ((float)FAR - (float)NEAR) / 2.0f; + float scale, bias; + + if (FLIP) { + scale = -1.0f; + bias = (float)HEIGHT; + } else { + scale = 1.0f; + bias = 0.0f; + } + + p->viewport.scale[0] = half_width; + p->viewport.scale[1] = half_height * scale; + p->viewport.scale[2] = half_depth; + p->viewport.scale[3] = 1.0f; + + p->viewport.translate[0] = half_width + x; + p->viewport.translate[1] = (half_height + y) * scale + bias; + p->viewport.translate[2] = half_depth + z; + p->viewport.translate[3] = 0.0f; + } + + /* vertex elements state */ + memset(p->velem, 0, sizeof(p->velem)); + p->velem[0].src_offset = 0 * 4 * sizeof(float); /* offset 0, first element */ + p->velem[0].instance_divisor = 0; + p->velem[0].vertex_buffer_index = 0; + p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + p->velem[1].src_offset = 1 * 4 * sizeof(float); /* offset 16, second element */ + p->velem[1].instance_divisor = 0; + p->velem[1].vertex_buffer_index = 0; + p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + /* vertex shader */ + { + const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, + TGSI_SEMANTIC_GENERIC }; + const uint semantic_indexes[] = { 0, 0 }; + p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes); + } + + /* fragment shader */ + p->fs = util_make_fragment_tex_shader(p->pipe, TGSI_TEXTURE_2D, TGSI_INTERPOLATE_LINEAR); +} + +static void close_prog(struct program *p) +{ + /* unset bound textures as well */ + cso_set_fragment_sampler_views(p->cso, 0, NULL); + + /* unset all state */ + cso_release_all(p->cso); + + p->pipe->delete_vs_state(p->pipe, p->vs); + p->pipe->delete_fs_state(p->pipe, p->fs); + + pipe_surface_reference(&p->framebuffer.cbufs[0], NULL); + pipe_sampler_view_reference(&p->view, NULL); + pipe_resource_reference(&p->target, NULL); + pipe_resource_reference(&p->tex, NULL); + pipe_resource_reference(&p->vbuf, NULL); + + cso_destroy_context(p->cso); + p->pipe->destroy(p->pipe); + p->screen->destroy(p->screen); + + FREE(p); +} + +static void draw(struct program *p) +{ + /* set the render target */ + cso_set_framebuffer(p->cso, &p->framebuffer); + + /* clear the render target */ + p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, p->clear_color, 0, 0); + + /* set misc state we care about */ + cso_set_blend(p->cso, &p->blend); + cso_set_depth_stencil_alpha(p->cso, &p->depthstencil); + cso_set_rasterizer(p->cso, &p->rasterizer); + cso_set_viewport(p->cso, &p->viewport); + + /* sampler */ + cso_single_sampler(p->cso, 0, &p->sampler); + cso_single_sampler_done(p->cso); + + /* texture sampler view */ + cso_set_fragment_sampler_views(p->cso, 1, &p->view); + + /* shaders */ + cso_set_fragment_shader_handle(p->cso, p->fs); + cso_set_vertex_shader_handle(p->cso, p->vs); + + /* vertex element data */ + cso_set_vertex_elements(p->cso, 2, p->velem); + + util_draw_vertex_buffer(p->pipe, + p->vbuf, 0, + PIPE_PRIM_QUADS, + 4, /* verts */ + 2); /* attribs/vert */ + + p->pipe->flush(p->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + + debug_dump_surface_bmp(p->pipe, "result.bmp", p->framebuffer.cbufs[0]); +} + +int main(int argc, char** argv) +{ + struct program *p = CALLOC_STRUCT(program); + + init_prog(p); + draw(p); + close_prog(p); + + return 0; +} diff --git a/src/gallium/tests/trivial/tri.c b/src/gallium/tests/trivial/tri.c new file mode 100644 index 0000000..37c1573 --- /dev/null +++ b/src/gallium/tests/trivial/tri.c @@ -0,0 +1,280 @@ +/************************************************************************** + * + * Copyright © 2010 Jakob Bornecrantz + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#define USE_TRACE 0 +#define WIDTH 300 +#define HEIGHT 300 +#define NEAR 30 +#define FAR 1000 +#define FLIP 0 + +/* pipe_*_state structs */ +#include "pipe/p_state.h" +/* pipe_context */ +#include "pipe/p_context.h" +/* pipe_screen */ +#include "pipe/p_screen.h" +/* PIPE_* */ +#include "pipe/p_defines.h" +/* TGSI_SEMANTIC_{POSITION|GENERIC} */ +#include "pipe/p_shader_tokens.h" +/* pipe_buffer_* helpers */ +#include "util/u_inlines.h" + +/* constant state object helper */ +#include "cso_cache/cso_context.h" + +/* debug_dump_surface_bmp */ +#include "util/u_debug.h" +/* util_draw_vertex_buffer helper */ +#include "util/u_draw_quad.h" +/* FREE & CALLOC_STRUCT */ +#include "util/u_memory.h" +/* util_make_[fragment|vertex]_passthrough_shader */ +#include "util/u_simple_shaders.h" + +/* sw_screen_create: to get a software pipe driver */ +#include "target-helpers/inline_sw_helper.h" +/* debug_screen_wrap: to wrap with debug pipe drivers */ +#include "target-helpers/inline_debug_helper.h" +/* null software winsys */ +#include "sw/null/null_sw_winsys.h" + +struct program +{ + struct pipe_screen *screen; + struct pipe_context *pipe; + struct cso_context *cso; + + struct pipe_blend_state blend; + struct pipe_depth_stencil_alpha_state depthstencil; + struct pipe_rasterizer_state rasterizer; + struct pipe_viewport_state viewport; + struct pipe_framebuffer_state framebuffer; + struct pipe_vertex_element velem[2]; + + void *vs; + void *fs; + + float clear_color[4]; + + struct pipe_resource *vbuf; + struct pipe_resource *target; +}; + +static void init_prog(struct program *p) +{ + struct pipe_surface surf_tmpl; + /* create the software rasterizer */ + p->screen = sw_screen_create(null_sw_create()); + /* wrap the screen with any debugger */ + p->screen = debug_screen_wrap(p->screen); + + /* create the pipe driver context and cso context */ + p->pipe = p->screen->context_create(p->screen, NULL); + p->cso = cso_create_context(p->pipe); + + /* set clear color */ + p->clear_color[0] = 0.3; + p->clear_color[1] = 0.1; + p->clear_color[2] = 0.3; + p->clear_color[3] = 1.0; + + /* vertex buffer */ + { + float vertices[4][2][4] = { + { + { 0.0f, -0.9f, 0.0f, 1.0f }, + { 1.0f, 0.0f, 0.0f, 1.0f } + }, + { + { -0.9f, 0.9f, 0.0f, 1.0f }, + { 0.0f, 1.0f, 0.0f, 1.0f } + }, + { + { 0.9f, 0.9f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f, 1.0f } + } + }; + + p->vbuf = pipe_buffer_create(p->screen, PIPE_BIND_VERTEX_BUFFER, sizeof(vertices)); + pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(vertices), vertices); + } + + /* render target texture */ + { + struct pipe_resource tmplt; + memset(&tmplt, 0, sizeof(tmplt)); + tmplt.target = PIPE_TEXTURE_2D; + tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */ + tmplt.width0 = WIDTH; + tmplt.height0 = HEIGHT; + tmplt.depth0 = 1; + tmplt.array_size = 1; + tmplt.last_level = 0; + tmplt.bind = PIPE_BIND_RENDER_TARGET; + + p->target = p->screen->resource_create(p->screen, &tmplt); + } + + /* disabled blending/masking */ + memset(&p->blend, 0, sizeof(p->blend)); + p->blend.rt[0].colormask = PIPE_MASK_RGBA; + + /* no-op depth/stencil/alpha */ + memset(&p->depthstencil, 0, sizeof(p->depthstencil)); + + /* rasterizer */ + memset(&p->rasterizer, 0, sizeof(p->rasterizer)); + p->rasterizer.cull_face = PIPE_FACE_NONE; + p->rasterizer.gl_rasterization_rules = 1; + + surf_tmpl.format = templat.format; + surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; + surf_tmpl.u.tex.level = 0; + surf_tmpl.u.tex.first_layer = 0; + surf_tmpl.u.tex.last_layer = 0; + /* drawing destination */ + memset(&p->framebuffer, 0, sizeof(p->framebuffer)); + p->framebuffer.width = WIDTH; + p->framebuffer.height = HEIGHT; + p->framebuffer.nr_cbufs = 1; + p->framebuffer.cbufs[0] = p->pipe->create_surface(p->pipe, p->target, &surf_tmpl); + + /* viewport, depth isn't really needed */ + { + float x = 0; + float y = 0; + float z = FAR; + float half_width = (float)WIDTH / 2.0f; + float half_height = (float)HEIGHT / 2.0f; + float half_depth = ((float)FAR - (float)NEAR) / 2.0f; + float scale, bias; + + if (FLIP) { + scale = -1.0f; + bias = (float)HEIGHT; + } else { + scale = 1.0f; + bias = 0.0f; + } + + p->viewport.scale[0] = half_width; + p->viewport.scale[1] = half_height * scale; + p->viewport.scale[2] = half_depth; + p->viewport.scale[3] = 1.0f; + + p->viewport.translate[0] = half_width + x; + p->viewport.translate[1] = (half_height + y) * scale + bias; + p->viewport.translate[2] = half_depth + z; + p->viewport.translate[3] = 0.0f; + } + + /* vertex elements state */ + memset(p->velem, 0, sizeof(p->velem)); + p->velem[0].src_offset = 0 * 4 * sizeof(float); /* offset 0, first element */ + p->velem[0].instance_divisor = 0; + p->velem[0].vertex_buffer_index = 0; + p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + p->velem[1].src_offset = 1 * 4 * sizeof(float); /* offset 16, second element */ + p->velem[1].instance_divisor = 0; + p->velem[1].vertex_buffer_index = 0; + p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + + /* vertex shader */ + { + const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, + TGSI_SEMANTIC_COLOR }; + const uint semantic_indexes[] = { 0, 0 }; + p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes); + } + + /* fragment shader */ + p->fs = util_make_fragment_passthrough_shader(p->pipe); +} + +static void close_prog(struct program *p) +{ + /* unset all state */ + cso_release_all(p->cso); + + p->pipe->delete_vs_state(p->pipe, p->vs); + p->pipe->delete_fs_state(p->pipe, p->fs); + + pipe_surface_reference(&p->framebuffer.cbufs[0], NULL); + pipe_resource_reference(&p->target, NULL); + pipe_resource_reference(&p->vbuf, NULL); + + cso_destroy_context(p->cso); + p->pipe->destroy(p->pipe); + p->screen->destroy(p->screen); + + FREE(p); +} + +static void draw(struct program *p) +{ + /* set the render target */ + cso_set_framebuffer(p->cso, &p->framebuffer); + + /* clear the render target */ + p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, p->clear_color, 0, 0); + + /* set misc state we care about */ + cso_set_blend(p->cso, &p->blend); + cso_set_depth_stencil_alpha(p->cso, &p->depthstencil); + cso_set_rasterizer(p->cso, &p->rasterizer); + cso_set_viewport(p->cso, &p->viewport); + + /* shaders */ + cso_set_fragment_shader_handle(p->cso, p->fs); + cso_set_vertex_shader_handle(p->cso, p->vs); + + /* vertex element data */ + cso_set_vertex_elements(p->cso, 2, p->velem); + + util_draw_vertex_buffer(p->pipe, + p->vbuf, 0, + PIPE_PRIM_TRIANGLES, + 3, /* verts */ + 2); /* attribs/vert */ + + p->pipe->flush(p->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + + debug_dump_surface_bmp(p->pipe, "result.bmp", p->framebuffer.cbufs[0]); +} + +int main(int argc, char** argv) +{ + struct program *p = CALLOC_STRUCT(program); + + init_prog(p); + draw(p); + close_prog(p); + + return 0; +} diff --git a/src/gallium/tests/unit/Makefile b/src/gallium/tests/unit/Makefile new file mode 100644 index 0000000..bb3039f --- /dev/null +++ b/src/gallium/tests/unit/Makefile @@ -0,0 +1,49 @@ +# progs/gallium/simple/Makefile + +TOP = ../../../.. +include $(TOP)/configs/current + +INCLUDES = \ + -I. \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/winsys \ + $(PROG_INCLUDES) + +LINKS = \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/winsys/sw/null/libws_null.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(GALLIUM_AUXILIARIES) \ + $(PROG_LINKS) + +SOURCES = \ + pipe_barrier_test.c \ + u_cache_test.c \ + u_half_test.c \ + u_format_test.c \ + u_format_compatible_test.c \ + translate_test.c + + +OBJECTS = $(SOURCES:.c=.o) + +PROGS = $(OBJECTS:.o=) + +##### TARGETS ##### + +default: $(PROGS) + +clean: + -rm -f $(PROGS) + -rm -f *.o + -rm -f result.bmp + +##### RULES ##### + +$(OBJECTS): %.o: %.c + $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $(PROG_DEFINES) $< -o $@ + +$(PROGS): %: %.o + $(CC) $(LDFLAGS) $< $(LINKS) -lm -lpthread -ldl -o $@ diff --git a/src/gallium/tests/unit/SConscript b/src/gallium/tests/unit/SConscript new file mode 100644 index 0000000..655e8a9 --- /dev/null +++ b/src/gallium/tests/unit/SConscript @@ -0,0 +1,33 @@ +Import('*') + +env = env.Clone() + +env.Prepend(LIBS = [gallium]) + +if env['platform'] in ('freebsd8', 'sunos5'): + env.Append(LIBS = ['m']) + +if env['platform'] == 'freebsd8': + env.Append(LIBS = ['pthread']) + +progs = [ + 'pipe_barrier_test', + 'u_cache_test', + 'u_format_test', + 'u_format_compatible_test', + 'u_half_test', + 'translate_test' +] + +for prog in progs: + prog = env.Program( + target = prog, + source = prog + '.c', + ) + + env.InstallProgram(prog) + + # http://www.scons.org/wiki/UnitTests + test_alias = env.Alias('unit', [prog], prog[0].abspath) + AlwaysBuild(test_alias) + diff --git a/src/gallium/tests/unit/pipe_barrier_test.c b/src/gallium/tests/unit/pipe_barrier_test.c new file mode 100644 index 0000000..f5d72b0 --- /dev/null +++ b/src/gallium/tests/unit/pipe_barrier_test.c @@ -0,0 +1,86 @@ +/************************************************************************** + * + * Copyright 2009-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/* + * Test case for pipe_barrier. + * + * The test succeeds if no thread exits before all the other threads reach + * the barrier. + */ + + +#include + +#include "os/os_thread.h" +#include "os/os_time.h" + + +#define NUM_THREADS 10 + +static pipe_thread threads[NUM_THREADS]; +static pipe_barrier barrier; +static int thread_ids[NUM_THREADS]; + + +static PIPE_THREAD_ROUTINE(thread_function, thread_data) +{ + int thread_id = *((int *) thread_data); + + printf("thread %d starting\n", thread_id); + os_time_sleep(thread_id * 1000 * 1000); + printf("thread %d before barrier\n", thread_id); + pipe_barrier_wait(&barrier); + printf("thread %d exiting\n", thread_id); + + return NULL; +} + + +int main() +{ + int i; + + printf("pipe_barrier_test starting\n"); + + pipe_barrier_init(&barrier, NUM_THREADS); + + for (i = 0; i < NUM_THREADS; i++) { + thread_ids[i] = i; + threads[i] = pipe_thread_create(thread_function, (void *) &thread_ids[i]); + } + + for (i = 0; i < NUM_THREADS; i++ ) { + pipe_thread_wait(threads[i]); + } + + pipe_barrier_destroy(&barrier); + + printf("pipe_barrier_test exiting\n"); + + return 0; +} diff --git a/src/gallium/tests/unit/translate_test.c b/src/gallium/tests/unit/translate_test.c new file mode 100644 index 0000000..d0946a9 --- /dev/null +++ b/src/gallium/tests/unit/translate_test.c @@ -0,0 +1,310 @@ +/************************************************************************** + * + * Copyright © 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include +#include +#include +#include +#include +#include + +/* don't use this for serious use */ +static double rand_double() +{ + const double rm = (double)RAND_MAX + 1; + double div = 1; + double v = 0; + unsigned i; + for(i = 0; i < 4; ++i) + { + div *= rm; + v += (double)rand() / div; + } + return v; +} + +int main(int argc, char** argv) +{ + struct translate *(*create_fn)(const struct translate_key *key) = 0; + + struct translate_key key; + unsigned output_format; + unsigned input_format; + unsigned buffer_size = 4096; + unsigned char* buffer[5]; + unsigned char* byte_buffer; + float* float_buffer; + double* double_buffer; + unsigned count = 4; + unsigned i, j, k; + unsigned passed = 0; + unsigned total = 0; + const float error = 0.03125; + + create_fn = 0; + + util_cpu_detect(); + + if(argc <= 1) + {} + else if (!strcmp(argv[1], "generic")) + create_fn = translate_generic_create; + else if (!strcmp(argv[1], "x86")) + create_fn = translate_sse2_create; + else if (!strcmp(argv[1], "nosse")) + { + util_cpu_caps.has_sse = 0; + util_cpu_caps.has_sse2 = 0; + util_cpu_caps.has_sse3 = 0; + util_cpu_caps.has_sse4_1 = 0; + create_fn = translate_sse2_create; + } + else if (!strcmp(argv[1], "sse")) + { + if(!util_cpu_caps.has_sse || !rtasm_cpu_has_sse()) + { + printf("Error: CPU doesn't support SSE (test with qemu)\n"); + return 2; + } + util_cpu_caps.has_sse2 = 0; + util_cpu_caps.has_sse3 = 0; + util_cpu_caps.has_sse4_1 = 0; + create_fn = translate_sse2_create; + } + else if (!strcmp(argv[1], "sse2")) + { + if(!util_cpu_caps.has_sse2 || !rtasm_cpu_has_sse()) + { + printf("Error: CPU doesn't support SSE2 (test with qemu)\n"); + return 2; + } + util_cpu_caps.has_sse3 = 0; + util_cpu_caps.has_sse4_1 = 0; + create_fn = translate_sse2_create; + } + else if (!strcmp(argv[1], "sse3")) + { + if(!util_cpu_caps.has_sse3 || !rtasm_cpu_has_sse()) + { + printf("Error: CPU doesn't support SSE3 (test with qemu)\n"); + return 2; + } + util_cpu_caps.has_sse4_1 = 0; + create_fn = translate_sse2_create; + } + else if (!strcmp(argv[1], "sse4.1")) + { + if(!util_cpu_caps.has_sse4_1 || !rtasm_cpu_has_sse()) + { + printf("Error: CPU doesn't support SSE4.1 (test with qemu)\n"); + return 2; + } + create_fn = translate_sse2_create; + } + + if (!create_fn) + { + printf("Usage: ./translate_test [generic|x86|nosse|sse|sse2|sse3|sse4.1]\n"); + return 2; + } + + for (i = 1; i < Elements(buffer); ++i) + buffer[i] = align_malloc(buffer_size, 4096); + + byte_buffer = align_malloc(buffer_size, 4096); + float_buffer = align_malloc(buffer_size, 4096); + double_buffer = align_malloc(buffer_size, 4096); + + key.nr_elements = 1; + key.element[0].input_buffer = 0; + key.element[0].input_offset = 0; + key.element[0].output_offset = 0; + key.element[0].type = TRANSLATE_ELEMENT_NORMAL; + key.element[0].instance_divisor = 0; + + srand(4359025); + + /* avoid negative values that work badly when converted to unsigned format*/ + for (i = 0; i < buffer_size; ++i) + byte_buffer[i] = rand() & 0x7f7f7f7f; + + for (i = 0; i < buffer_size / sizeof(float); ++i) + float_buffer[i] = (float)rand_double(); + + for (i = 0; i < buffer_size / sizeof(double); ++i) + double_buffer[i] = rand_double(); + + for (output_format = 1; output_format < PIPE_FORMAT_COUNT; ++output_format) + { + const struct util_format_description* output_format_desc = util_format_description(output_format); + unsigned output_format_size; + unsigned output_normalized = 0; + + if (!output_format_desc + || !output_format_desc->fetch_rgba_float + || !output_format_desc->pack_rgba_float + || output_format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB + || output_format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN + || !translate_is_output_format_supported(output_format)) + continue; + + for(i = 0; i < output_format_desc->nr_channels; ++i) + { + if(output_format_desc->channel[i].type != UTIL_FORMAT_TYPE_FLOAT) + output_normalized |= (1 << output_format_desc->channel[i].normalized); + } + + output_format_size = util_format_get_stride(output_format, 1); + + for (input_format = 1; input_format < PIPE_FORMAT_COUNT; ++input_format) + { + const struct util_format_description* input_format_desc = util_format_description(input_format); + unsigned input_format_size; + struct translate* translate[2]; + unsigned fail = 0; + unsigned used_generic = 0; + unsigned input_normalized = 0; + boolean input_is_float = FALSE; + + if (!input_format_desc + || !input_format_desc->fetch_rgba_float + || !input_format_desc->pack_rgba_float + || input_format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB + || input_format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN + || !translate_is_output_format_supported(input_format)) + continue; + + input_format_size = util_format_get_stride(input_format, 1); + + for(i = 0; i < input_format_desc->nr_channels; ++i) + { + if(input_format_desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT) + { + input_is_float = 1; + input_normalized |= 1 << 1; + } + else + input_normalized |= (1 << input_format_desc->channel[i].normalized); + } + + if(((input_normalized | output_normalized) == 3) + || ((input_normalized & 1) && (output_normalized & 1) + && input_format_size * output_format_desc->nr_channels > output_format_size * input_format_desc->nr_channels)) + continue; + + key.element[0].input_format = input_format; + key.element[0].output_format = output_format; + key.output_stride = output_format_size; + translate[0] = create_fn(&key); + if (!translate[0]) + continue; + + key.element[0].input_format = output_format; + key.element[0].output_format = input_format; + key.output_stride = input_format_size; + translate[1] = create_fn(&key); + if(!translate[1]) + { + used_generic = 1; + translate[1] = translate_generic_create(&key); + if(!translate[1]) + continue; + } + + for(i = 1; i < 5; ++i) + memset(buffer[i], 0xcd - (0x22 * i), 4096); + + if(input_is_float && input_format_desc->channel[0].size == 32) + buffer[0] = (unsigned char*)float_buffer; + else if(input_is_float && input_format_desc->channel[0].size == 64) + buffer[0] = (unsigned char*)double_buffer; + else if(input_is_float) + abort(); + else + buffer[0] = byte_buffer; + + translate[0]->set_buffer(translate[0], 0, buffer[0], input_format_size, ~0); + translate[0]->run(translate[0], 0, count, 0, buffer[1]); + translate[1]->set_buffer(translate[1], 0, buffer[1], output_format_size, ~0); + translate[1]->run(translate[1], 0, count, 0, buffer[2]); + translate[0]->set_buffer(translate[0], 0, buffer[2], input_format_size, ~0); + translate[0]->run(translate[0], 0, count, 0, buffer[3]); + translate[1]->set_buffer(translate[1], 0, buffer[3], output_format_size, ~0); + translate[1]->run(translate[1], 0, count, 0, buffer[4]); + + for (i = 0; i < count; ++i) + { + float a[4]; + float b[4]; + input_format_desc->fetch_rgba_float(a, buffer[2] + i * input_format_size, 0, 0); + input_format_desc->fetch_rgba_float(b, buffer[4] + i * input_format_size, 0, 0); + + for (j = 0; j < count; ++j) + { + float d = a[j] - b[j]; + if (d > error || d < -error) + { + fail = 1; + break; + } + } + } + + printf("%s%s: %s -> %s -> %s -> %s -> %s\n", + fail ? "FAIL" : "PASS", + used_generic ? "[GENERIC]" : "", + input_format_desc->name, output_format_desc->name, input_format_desc->name, output_format_desc->name, input_format_desc->name); + + if (1) + { + for (i = 0; i < Elements(buffer); ++i) + { + unsigned format_size = (i & 1) ? output_format_size : input_format_size; + printf("%c ", (i == 2 || i == 4) ? '*' : ' '); + for (j = 0; j < count; ++j) + { + for (k = 0; k < format_size; ++k) + { + printf("%02x", buffer[i][j * format_size + k]); + } + printf(" "); + } + printf("\n"); + } + } + + if (!fail) + ++passed; + ++total; + + if(translate[1]) + translate[1]->release(translate[1]); + translate[0]->release(translate[0]); + } + } + + printf("%u/%u tests passed for translate_%s\n", passed, total, argv[1]); + return passed != total; +} diff --git a/src/gallium/tests/unit/u_cache_test.c b/src/gallium/tests/unit/u_cache_test.c new file mode 100644 index 0000000..0b62a76 --- /dev/null +++ b/src/gallium/tests/unit/u_cache_test.c @@ -0,0 +1,121 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/* + * Test case for u_cache. + */ + + +#include +#include + +#include "util/u_cache.h" +#include "util/u_hash.h" + + +typedef uint32_t cache_test_key; +typedef uint32_t cache_test_value; + + +static uint32_t +cache_test_hash(const void *key) +{ + return util_hash_crc32(key, sizeof(cache_test_key)); +} + + +static void +cache_test_destroy(void *key, void *value) +{ + free(key); + free(value); +} + + +static int +cache_test_compare(const void *key1, const void *key2) { + return !(key1 == key2); +} + + +int main() { + unsigned cache_size; + unsigned cache_count; + + for (cache_size = 2; cache_size < (1 << 15); cache_size *= 2) { + for (cache_count = (cache_size << 5); cache_count < (cache_size << 10); cache_count *= 2) { + struct util_cache * cache; + cache_test_key *key; + cache_test_value *value_in; + cache_test_value *value_out; + int i; + + printf("Testing cache size of %d with %d values.\n", cache_size, cache_count); + + cache = util_cache_create(cache_test_hash, + cache_test_compare, + cache_test_destroy, + cache_size); + + /* + * Retrieve a value from an empty cache. + */ + key = malloc(sizeof(cache_test_key)); + *key = 0xdeadbeef; + value_out = (cache_test_value *) util_cache_get(cache, key); + assert(value_out == NULL); + free(key); + + + /* + * Repeatedly insert into and retrieve values from the cache. + */ + for (i = 0; i < cache_count; i++) { + key = malloc(sizeof(cache_test_key)); + value_in = malloc(sizeof(cache_test_value)); + + *key = rand(); + *value_in = rand(); + util_cache_set(cache, key, value_in); + + value_out = util_cache_get(cache, key); + assert(value_out != NULL); + assert(value_in == value_out); + assert(*value_in == *value_out); + } + + /* + * In debug builds, this will trigger a self-check by the cache of + * the distribution of hits in its internal cache entries. + */ + util_cache_destroy(cache); + } + } + + return 0; +} diff --git a/src/gallium/tests/unit/u_format_compatible_test.c b/src/gallium/tests/unit/u_format_compatible_test.c new file mode 100644 index 0000000..c655c35 --- /dev/null +++ b/src/gallium/tests/unit/u_format_compatible_test.c @@ -0,0 +1,76 @@ +/************************************************************************** + * + * Copyright 2009-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include +#include + +#include "util/u_format.h" + + +static boolean +test_all(void) +{ + enum pipe_format src_format; + enum pipe_format dst_format; + + for (src_format = 1; src_format < PIPE_FORMAT_COUNT; ++src_format) { + const struct util_format_description *src_format_desc; + src_format_desc = util_format_description(src_format); + if (!src_format_desc) { + continue; + } + + for (dst_format = 1; dst_format < PIPE_FORMAT_COUNT; ++dst_format) { + const struct util_format_description *dst_format_desc; + dst_format_desc = util_format_description(dst_format); + if (!dst_format_desc) { + continue; + } + + if (dst_format == src_format) { + continue; + } + + if (util_is_format_compatible(src_format_desc, dst_format_desc)) { + debug_printf("%s -> %s\n", src_format_desc->short_name, dst_format_desc->short_name); + } + } + } + + return TRUE; +} + + +int main(int argc, char **argv) +{ + boolean success; + + success = test_all(); + + return success ? 0 : 1; +} diff --git a/src/gallium/tests/unit/u_format_test.c b/src/gallium/tests/unit/u_format_test.c new file mode 100644 index 0000000..ba0dd17 --- /dev/null +++ b/src/gallium/tests/unit/u_format_test.c @@ -0,0 +1,716 @@ +/************************************************************************** + * + * Copyright 2009-2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include +#include +#include + +#include "util/u_half.h" +#include "util/u_format.h" +#include "util/u_format_tests.h" +#include "util/u_format_s3tc.h" + + +static boolean +compare_float(float x, float y) +{ + float error = y - x; + + if (error < 0.0f) + error = -error; + + if (error > FLT_EPSILON) { + return FALSE; + } + + return TRUE; +} + + +static void +print_packed(const struct util_format_description *format_desc, + const char *prefix, + const uint8_t *packed, + const char *suffix) +{ + unsigned i; + const char *sep = ""; + + printf("%s", prefix); + for (i = 0; i < format_desc->block.bits/8; ++i) { + printf("%s%02x", sep, packed[i]); + sep = " "; + } + printf("%s", suffix); + fflush(stdout); +} + + +static void +print_unpacked_rgba_doubl(const struct util_format_description *format_desc, + const char *prefix, + const double unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4], + const char *suffix) +{ + unsigned i, j; + const char *sep = ""; + + printf("%s", prefix); + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + printf("%s{%f, %f, %f, %f}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]); + sep = ", "; + } + sep = ",\n"; + } + printf("%s", suffix); + fflush(stdout); +} + + +static void +print_unpacked_rgba_float(const struct util_format_description *format_desc, + const char *prefix, + float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4], + const char *suffix) +{ + unsigned i, j; + const char *sep = ""; + + printf("%s", prefix); + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + printf("%s{%f, %f, %f, %f}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]); + sep = ", "; + } + sep = ",\n"; + } + printf("%s", suffix); + fflush(stdout); +} + + +static void +print_unpacked_rgba_8unorm(const struct util_format_description *format_desc, + const char *prefix, + uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4], + const char *suffix) +{ + unsigned i, j; + const char *sep = ""; + + printf("%s", prefix); + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + printf("%s{0x%02x, 0x%02x, 0x%02x, 0x%02x}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]); + sep = ", "; + } + } + printf("%s", suffix); + fflush(stdout); +} + + +static void +print_unpacked_z_float(const struct util_format_description *format_desc, + const char *prefix, + float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH], + const char *suffix) +{ + unsigned i, j; + const char *sep = ""; + + printf("%s", prefix); + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + printf("%s%f", sep, unpacked[i][j]); + sep = ", "; + } + sep = ",\n"; + } + printf("%s", suffix); + fflush(stdout); +} + + +static void +print_unpacked_z_32unorm(const struct util_format_description *format_desc, + const char *prefix, + uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH], + const char *suffix) +{ + unsigned i, j; + const char *sep = ""; + + printf("%s", prefix); + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + printf("%s0x%08x", sep, unpacked[i][j]); + sep = ", "; + } + } + printf("%s", suffix); + fflush(stdout); +} + + +static void +print_unpacked_s_8uscaled(const struct util_format_description *format_desc, + const char *prefix, + uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH], + const char *suffix) +{ + unsigned i, j; + const char *sep = ""; + + printf("%s", prefix); + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + printf("%s0x%02x", sep, unpacked[i][j]); + sep = ", "; + } + } + printf("%s", suffix); + fflush(stdout); +} + + +static boolean +test_format_fetch_rgba_float(const struct util_format_description *format_desc, + const struct util_format_test_case *test) +{ + float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } }; + unsigned i, j, k; + boolean success; + + success = TRUE; + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + format_desc->fetch_rgba_float(unpacked[i][j], test->packed, j, i); + for (k = 0; k < 4; ++k) { + if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) { + success = FALSE; + } + } + } + } + + if (!success) { + print_unpacked_rgba_float(format_desc, "FAILED: ", unpacked, " obtained\n"); + print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n"); + } + + return success; +} + + +static boolean +test_format_unpack_rgba_float(const struct util_format_description *format_desc, + const struct util_format_test_case *test) +{ + float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } }; + unsigned i, j, k; + boolean success; + + format_desc->unpack_rgba_float(&unpacked[0][0][0], sizeof unpacked[0], + test->packed, 0, + format_desc->block.width, format_desc->block.height); + + success = TRUE; + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + for (k = 0; k < 4; ++k) { + if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) { + success = FALSE; + } + } + } + } + + if (!success) { + print_unpacked_rgba_float(format_desc, "FAILED: ", unpacked, " obtained\n"); + print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n"); + } + + return success; +} + + +static boolean +test_format_pack_rgba_float(const struct util_format_description *format_desc, + const struct util_format_test_case *test) +{ + float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4]; + uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; + unsigned i, j, k; + boolean success; + + if (test->format == PIPE_FORMAT_DXT1_RGBA) { + /* + * Skip S3TC as packed representation is not canonical. + * + * TODO: Do a round trip conversion. + */ + return TRUE; + } + + memset(packed, 0, sizeof packed); + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + for (k = 0; k < 4; ++k) { + unpacked[i][j][k] = (float) test->unpacked[i][j][k]; + } + } + } + + format_desc->pack_rgba_float(packed, 0, + &unpacked[0][0][0], sizeof unpacked[0], + format_desc->block.width, format_desc->block.height); + + success = TRUE; + for (i = 0; i < format_desc->block.bits/8; ++i) + if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) + success = FALSE; + + if (!success) { + print_packed(format_desc, "FAILED: ", packed, " obtained\n"); + print_packed(format_desc, " ", test->packed, " expected\n"); + } + + return success; +} + + +static boolean +convert_float_to_8unorm(uint8_t *dst, const double *src) +{ + unsigned i; + boolean accurate = TRUE; + + for (i = 0; i < UTIL_FORMAT_MAX_UNPACKED_HEIGHT*UTIL_FORMAT_MAX_UNPACKED_WIDTH*4; ++i) { + if (src[i] < 0.0) { + accurate = FALSE; + dst[i] = 0; + } + else if (src[i] > 1.0) { + accurate = FALSE; + dst[i] = 255; + } + else { + dst[i] = src[i] * 255.0; + } + } + + return accurate; +} + + +static boolean +test_format_unpack_rgba_8unorm(const struct util_format_description *format_desc, + const struct util_format_test_case *test) +{ + uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } }; + uint8_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } }; + unsigned i, j, k; + boolean success; + + format_desc->unpack_rgba_8unorm(&unpacked[0][0][0], sizeof unpacked[0], + test->packed, 0, + format_desc->block.width, format_desc->block.height); + + convert_float_to_8unorm(&expected[0][0][0], &test->unpacked[0][0][0]); + + success = TRUE; + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + for (k = 0; k < 4; ++k) { + if (expected[i][j][k] != unpacked[i][j][k]) { + success = FALSE; + } + } + } + } + + if (!success) { + print_unpacked_rgba_8unorm(format_desc, "FAILED: ", unpacked, " obtained\n"); + print_unpacked_rgba_8unorm(format_desc, " ", expected, " expected\n"); + } + + return success; +} + + +static boolean +test_format_pack_rgba_8unorm(const struct util_format_description *format_desc, + const struct util_format_test_case *test) +{ + uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4]; + uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; + unsigned i; + boolean success; + + if (test->format == PIPE_FORMAT_DXT1_RGBA) { + /* + * Skip S3TC as packed representation is not canonical. + * + * TODO: Do a round trip conversion. + */ + return TRUE; + } + + if (!convert_float_to_8unorm(&unpacked[0][0][0], &test->unpacked[0][0][0])) { + /* + * Skip test cases which cannot be represented by four unorm bytes. + */ + return TRUE; + } + + memset(packed, 0, sizeof packed); + + format_desc->pack_rgba_8unorm(packed, 0, + &unpacked[0][0][0], sizeof unpacked[0], + format_desc->block.width, format_desc->block.height); + + success = TRUE; + for (i = 0; i < format_desc->block.bits/8; ++i) + if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) + success = FALSE; + + if (!success) { + print_packed(format_desc, "FAILED: ", packed, " obtained\n"); + print_packed(format_desc, " ", test->packed, " expected\n"); + } + + return success; +} + + +static boolean +test_format_unpack_z_float(const struct util_format_description *format_desc, + const struct util_format_test_case *test) +{ + float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } }; + unsigned i, j; + boolean success; + + format_desc->unpack_z_float(&unpacked[0][0], sizeof unpacked[0], + test->packed, 0, + format_desc->block.width, format_desc->block.height); + + success = TRUE; + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + if (!compare_float(test->unpacked[i][j][0], unpacked[i][j])) { + success = FALSE; + } + } + } + + if (!success) { + print_unpacked_z_float(format_desc, "FAILED: ", unpacked, " obtained\n"); + print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n"); + } + + return success; +} + + +static boolean +test_format_pack_z_float(const struct util_format_description *format_desc, + const struct util_format_test_case *test) +{ + float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH]; + uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; + unsigned i, j; + boolean success; + + memset(packed, 0, sizeof packed); + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + unpacked[i][j] = (float) test->unpacked[i][j][0]; + if (test->unpacked[i][j][1]) { + return TRUE; + } + } + } + + format_desc->pack_z_float(packed, 0, + &unpacked[0][0], sizeof unpacked[0], + format_desc->block.width, format_desc->block.height); + + success = TRUE; + for (i = 0; i < format_desc->block.bits/8; ++i) + if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) + success = FALSE; + + if (!success) { + print_packed(format_desc, "FAILED: ", packed, " obtained\n"); + print_packed(format_desc, " ", test->packed, " expected\n"); + } + + return success; +} + + +static boolean +test_format_unpack_z_32unorm(const struct util_format_description *format_desc, + const struct util_format_test_case *test) +{ + uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } }; + uint32_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } }; + unsigned i, j; + boolean success; + + format_desc->unpack_z_32unorm(&unpacked[0][0], sizeof unpacked[0], + test->packed, 0, + format_desc->block.width, format_desc->block.height); + + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + expected[i][j] = test->unpacked[i][j][0] * 0xffffffff; + } + } + + success = TRUE; + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + if (expected[i][j] != unpacked[i][j]) { + success = FALSE; + } + } + } + + if (!success) { + print_unpacked_z_32unorm(format_desc, "FAILED: ", unpacked, " obtained\n"); + print_unpacked_z_32unorm(format_desc, " ", expected, " expected\n"); + } + + return success; +} + + +static boolean +test_format_pack_z_32unorm(const struct util_format_description *format_desc, + const struct util_format_test_case *test) +{ + uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH]; + uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; + unsigned i, j; + boolean success; + + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + unpacked[i][j] = test->unpacked[i][j][0] * 0xffffffff; + if (test->unpacked[i][j][1]) { + return TRUE; + } + } + } + + memset(packed, 0, sizeof packed); + + format_desc->pack_z_32unorm(packed, 0, + &unpacked[0][0], sizeof unpacked[0], + format_desc->block.width, format_desc->block.height); + + success = TRUE; + for (i = 0; i < format_desc->block.bits/8; ++i) + if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) + success = FALSE; + + if (!success) { + print_packed(format_desc, "FAILED: ", packed, " obtained\n"); + print_packed(format_desc, " ", test->packed, " expected\n"); + } + + return success; +} + + +static boolean +test_format_unpack_s_8uscaled(const struct util_format_description *format_desc, + const struct util_format_test_case *test) +{ + uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } }; + uint8_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } }; + unsigned i, j; + boolean success; + + format_desc->unpack_s_8uscaled(&unpacked[0][0], sizeof unpacked[0], + test->packed, 0, + format_desc->block.width, format_desc->block.height); + + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + expected[i][j] = test->unpacked[i][j][1]; + } + } + + success = TRUE; + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + if (expected[i][j] != unpacked[i][j]) { + success = FALSE; + } + } + } + + if (!success) { + print_unpacked_s_8uscaled(format_desc, "FAILED: ", unpacked, " obtained\n"); + print_unpacked_s_8uscaled(format_desc, " ", expected, " expected\n"); + } + + return success; +} + + +static boolean +test_format_pack_s_8uscaled(const struct util_format_description *format_desc, + const struct util_format_test_case *test) +{ + uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH]; + uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; + unsigned i, j; + boolean success; + + for (i = 0; i < format_desc->block.height; ++i) { + for (j = 0; j < format_desc->block.width; ++j) { + unpacked[i][j] = test->unpacked[i][j][1]; + if (test->unpacked[i][j][0]) { + return TRUE; + } + } + } + + memset(packed, 0, sizeof packed); + + format_desc->pack_s_8uscaled(packed, 0, + &unpacked[0][0], sizeof unpacked[0], + format_desc->block.width, format_desc->block.height); + + success = TRUE; + for (i = 0; i < format_desc->block.bits/8; ++i) + if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i])) + success = FALSE; + + if (!success) { + print_packed(format_desc, "FAILED: ", packed, " obtained\n"); + print_packed(format_desc, " ", test->packed, " expected\n"); + } + + return success; +} + + +typedef boolean +(*test_func_t)(const struct util_format_description *format_desc, + const struct util_format_test_case *test); + + +static boolean +test_one_func(const struct util_format_description *format_desc, + test_func_t func, + const char *suffix) +{ + unsigned i; + bool success = TRUE; + + printf("Testing util_format_%s_%s ...\n", + format_desc->short_name, suffix); + fflush(stdout); + + for (i = 0; i < util_format_nr_test_cases; ++i) { + const struct util_format_test_case *test = &util_format_test_cases[i]; + + if (test->format == format_desc->format) { + if (!func(format_desc, &util_format_test_cases[i])) { + success = FALSE; + } + } + } + + return success; +} + + +static boolean +test_all(void) +{ + enum pipe_format format; + bool success = TRUE; + + for (format = 1; format < PIPE_FORMAT_COUNT; ++format) { + const struct util_format_description *format_desc; + + format_desc = util_format_description(format); + if (!format_desc) { + continue; + } + + if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC && + !util_format_s3tc_enabled) { + continue; + } + +# define TEST_ONE_FUNC(name) \ + if (format_desc->name) { \ + if (!test_one_func(format_desc, &test_format_##name, #name)) { \ + success = FALSE; \ + } \ + } + + TEST_ONE_FUNC(fetch_rgba_float); + TEST_ONE_FUNC(pack_rgba_float); + TEST_ONE_FUNC(unpack_rgba_float); + TEST_ONE_FUNC(pack_rgba_8unorm); + TEST_ONE_FUNC(unpack_rgba_8unorm); + + TEST_ONE_FUNC(unpack_z_32unorm); + TEST_ONE_FUNC(pack_z_32unorm); + TEST_ONE_FUNC(unpack_z_float); + TEST_ONE_FUNC(pack_z_float); + TEST_ONE_FUNC(unpack_s_8uscaled); + TEST_ONE_FUNC(pack_s_8uscaled); + +# undef TEST_ONE_FUNC + } + + return success; +} + + +int main(int argc, char **argv) +{ + boolean success; + + util_format_s3tc_init(); + + success = test_all(); + + return success ? 0 : 1; +} diff --git a/src/gallium/tests/unit/u_half_test.c b/src/gallium/tests/unit/u_half_test.c new file mode 100644 index 0000000..00bda7f --- /dev/null +++ b/src/gallium/tests/unit/u_half_test.c @@ -0,0 +1,32 @@ +#include +#include +#include + +#include "util/u_math.h" +#include "util/u_half.h" + +int +main(int argc, char **argv) +{ + unsigned i; + unsigned roundtrip_fails = 0; + for(i = 0; i < 1 << 16; ++i) + { + uint16_t h = (uint16_t) i; + union fi f; + uint16_t rh; + f.ui = util_half_to_floatui(h); + rh = util_floatui_to_half(f.ui); + if(h != rh) + { + printf("Roundtrip failed: %x -> %x = %f -> %x\n", h, f.ui, f.f, rh); + ++roundtrip_fails; + } + } + + if(roundtrip_fails) + printf("Failure! %u/65536 half floats failed a conversion to float and back.\n", roundtrip_fails); + else + printf("Success!\n"); + return 0; +} diff --git a/src/gallium/winsys/Makefile b/src/gallium/winsys/Makefile new file mode 100644 index 0000000..bce5b3f --- /dev/null +++ b/src/gallium/winsys/Makefile @@ -0,0 +1,12 @@ +# src/gallium/winsys/Makefile +TOP = ../../.. +include $(TOP)/configs/current + +SUBDIRS = $(GALLIUM_WINSYS_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/SConscript b/src/gallium/winsys/SConscript new file mode 100644 index 0000000..d74f8a2 --- /dev/null +++ b/src/gallium/winsys/SConscript @@ -0,0 +1,39 @@ +Import('*') + + +SConscript([ + 'sw/wrapper/SConscript', +]) + +SConscript([ + 'sw/xlib/SConscript', +]) + +SConscript([ + 'sw/gdi/SConscript', +]) + +if env['dri']: + SConscript([ + 'sw/dri/SConscript', + ]) + + SConscript([ + 'svga/drm/SConscript', + ]) + + SConscript([ + 'i915/drm/SConscript', + ]) + + SConscript([ + 'i965/drm/SConscript', + ]) + + SConscript([ + 'radeon/drm/SConscript', + ]) + + SConscript([ + 'r600/drm/SConscript', + ]) diff --git a/src/gallium/winsys/i915/drm/Makefile b/src/gallium/winsys/i915/drm/Makefile new file mode 100644 index 0000000..1977de1 --- /dev/null +++ b/src/gallium/winsys/i915/drm/Makefile @@ -0,0 +1,16 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = i915drm + +C_SOURCES = \ + i915_drm_batchbuffer.c \ + i915_drm_buffer.c \ + i915_drm_fence.c \ + i915_drm_winsys.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 0000000..d8f5885 --- /dev/null +++ b/src/gallium/winsys/i915/drm/SConscript @@ -0,0 +1,19 @@ +Import('*') + +env = env.Clone() + +env.ParseConfig('pkg-config --cflags libdrm') + +i915drm_sources = [ + 'i915_drm_batchbuffer.c', + 'i915_drm_buffer.c', + 'i915_drm_fence.c', + 'i915_drm_winsys.c', +] + +i915drm = env.ConvenienceLibrary( + target ='i915drm', + source = i915drm_sources, +) + +Export('i915drm') diff --git a/src/gallium/winsys/i915/drm/i915_drm_batchbuffer.c b/src/gallium/winsys/i915/drm/i915_drm_batchbuffer.c new file mode 100644 index 0000000..ebe86dc --- /dev/null +++ b/src/gallium/winsys/i915/drm/i915_drm_batchbuffer.c @@ -0,0 +1,212 @@ + +#include "i915_drm_winsys.h" +#include "util/u_memory.h" + +#include "i915_drm.h" +#include "i915/i915_debug.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 + +struct i915_drm_batchbuffer +{ + struct i915_winsys_batchbuffer base; + + size_t actual_size; + + drm_intel_bo *bo; +}; + +static INLINE struct i915_drm_batchbuffer * +i915_drm_batchbuffer(struct i915_winsys_batchbuffer *batch) +{ + return (struct i915_drm_batchbuffer *)batch; +} + +static void +i915_drm_batchbuffer_reset(struct i915_drm_batchbuffer *batch) +{ + struct i915_drm_winsys *idws = i915_drm_winsys(batch->base.iws); + int ret; + + if (batch->bo) + drm_intel_bo_unreference(batch->bo); + batch->bo = drm_intel_bo_alloc(idws->gem_manager, + "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 i915_winsys_batchbuffer * +i915_drm_batchbuffer_create(struct i915_winsys *iws) +{ + struct i915_drm_winsys *idws = i915_drm_winsys(iws); + struct i915_drm_batchbuffer *batch = CALLOC_STRUCT(i915_drm_batchbuffer); + + batch->actual_size = idws->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_drm_batchbuffer_reset(batch); + + return &batch->base; +} + +static int +i915_drm_batchbuffer_reloc(struct i915_winsys_batchbuffer *ibatch, + struct i915_winsys_buffer *buffer, + enum i915_winsys_buffer_usage usage, + unsigned pre_add, bool fenced) +{ + struct i915_drm_batchbuffer *batch = i915_drm_batchbuffer(ibatch); + unsigned write_domain = 0; + unsigned read_domain = 0; + unsigned offset; + int ret = 0; + + assert(batch->base.relocs < batch->base.max_relocs); + + switch (usage) { + case I915_USAGE_SAMPLER: + write_domain = 0; + read_domain = I915_GEM_DOMAIN_SAMPLER; + break; + case I915_USAGE_RENDER: + write_domain = I915_GEM_DOMAIN_RENDER; + read_domain = I915_GEM_DOMAIN_RENDER; + break; + case I915_USAGE_2D_TARGET: + write_domain = I915_GEM_DOMAIN_RENDER; + read_domain = I915_GEM_DOMAIN_RENDER; + break; + case I915_USAGE_2D_SOURCE: + write_domain = 0; + read_domain = I915_GEM_DOMAIN_RENDER; + break; + case I915_USAGE_VERTEX: + write_domain = 0; + read_domain = I915_GEM_DOMAIN_VERTEX; + break; + default: + assert(0); + return -1; + } + + offset = (unsigned)(batch->base.ptr - batch->base.map); + + if (fenced) + ret = drm_intel_bo_emit_reloc_fence(batch->bo, offset, + intel_bo(buffer), pre_add, + read_domain, + write_domain); + else + 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 +i915_drm_batchbuffer_flush(struct i915_winsys_batchbuffer *ibatch, + struct pipe_fence_handle **fence) +{ + struct i915_drm_batchbuffer *batch = i915_drm_batchbuffer(ibatch); + unsigned used; + int ret; + + /* MI_BATCH_BUFFER_END */ + i915_winsys_batchbuffer_dword_unchecked(ibatch, (0xA<<23)); + + used = batch->base.ptr - batch->base.map; + if (used & 4) { + /* MI_NOOP */ + i915_winsys_batchbuffer_dword_unchecked(ibatch, 0); + used += 4; + } + + /* Do the sending to HW */ + ret = drm_intel_bo_subdata(batch->bo, 0, used, batch->base.map); + if (ret == 0 && i915_drm_winsys(ibatch->iws)->send_cmd) + ret = drm_intel_bo_exec(batch->bo, used, NULL, 0, 0); + + if (ret != 0 || i915_drm_winsys(ibatch->iws)->dump_cmd) { + i915_dump_batchbuffer(ibatch); + assert(ret == 0); + } + +#ifdef INTEL_RUN_SYNC + drm_intel_bo_wait_rendering(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) = i915_drm_fence_create(NULL); +#else + (*fence) = i915_drm_fence_create(batch->bo); +#endif + } + + i915_drm_batchbuffer_reset(batch); +} + +static void +i915_drm_batchbuffer_destroy(struct i915_winsys_batchbuffer *ibatch) +{ + struct i915_drm_batchbuffer *batch = i915_drm_batchbuffer(ibatch); + + if (batch->bo) + drm_intel_bo_unreference(batch->bo); + + FREE(batch->base.map); + FREE(batch); +} + +void i915_drm_winsys_init_batchbuffer_functions(struct i915_drm_winsys *idws) +{ + idws->base.batchbuffer_create = i915_drm_batchbuffer_create; + idws->base.batchbuffer_reloc = i915_drm_batchbuffer_reloc; + idws->base.batchbuffer_flush = i915_drm_batchbuffer_flush; + idws->base.batchbuffer_destroy = i915_drm_batchbuffer_destroy; +} diff --git a/src/gallium/winsys/i915/drm/i915_drm_buffer.c b/src/gallium/winsys/i915/drm/i915_drm_buffer.c new file mode 100644 index 0000000..01dd4bf --- /dev/null +++ b/src/gallium/winsys/i915/drm/i915_drm_buffer.c @@ -0,0 +1,227 @@ + +#include "state_tracker/drm_driver.h" +#include "i915_drm_winsys.h" +#include "util/u_memory.h" + +#include "i915_drm.h" + +static char *i915_drm_type_to_name(enum i915_winsys_buffer_type type) +{ + char *name; + + 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"; + } + + return name; +} + +static struct i915_winsys_buffer * +i915_drm_buffer_create(struct i915_winsys *iws, + unsigned size, + enum i915_winsys_buffer_type type) +{ + struct i915_drm_buffer *buf = CALLOC_STRUCT(i915_drm_buffer); + struct i915_drm_winsys *idws = i915_drm_winsys(iws); + + if (!buf) + return NULL; + + buf->magic = 0xDEAD1337; + buf->flinked = FALSE; + buf->flink = 0; + + buf->bo = drm_intel_bo_alloc(idws->gem_manager, + i915_drm_type_to_name(type), size, 0); + + if (!buf->bo) + goto err; + + return (struct i915_winsys_buffer *)buf; + +err: + assert(0); + FREE(buf); + return NULL; +} + +static struct i915_winsys_buffer * +i915_drm_buffer_create_tiled(struct i915_winsys *iws, + unsigned *stride, unsigned height, + enum i915_winsys_buffer_tile *tiling, + enum i915_winsys_buffer_type type) +{ + struct i915_drm_buffer *buf = CALLOC_STRUCT(i915_drm_buffer); + struct i915_drm_winsys *idws = i915_drm_winsys(iws); + unsigned long pitch = 0; + uint32_t tiling_mode = *tiling; + + if (!buf) + return NULL; + + buf->magic = 0xDEAD1337; + buf->flinked = FALSE; + buf->flink = 0; + + buf->bo = drm_intel_bo_alloc_tiled(idws->gem_manager, + i915_drm_type_to_name(type), + *stride, height, 1, + &tiling_mode, &pitch, 0); + + if (!buf->bo) + goto err; + + *stride = pitch; + *tiling = tiling_mode; + return (struct i915_winsys_buffer *)buf; + +err: + assert(0); + FREE(buf); + return NULL; +} + +static struct i915_winsys_buffer * +i915_drm_buffer_from_handle(struct i915_winsys *iws, + struct winsys_handle *whandle, + enum i915_winsys_buffer_tile *tiling, + unsigned *stride) +{ + struct i915_drm_winsys *idws = i915_drm_winsys(iws); + struct i915_drm_buffer *buf = CALLOC_STRUCT(i915_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->gem_manager, "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); + + *stride = whandle->stride; + *tiling = tile; + + return (struct i915_winsys_buffer *)buf; + +err: + FREE(buf); + return NULL; +} + +static boolean +i915_drm_buffer_get_handle(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + struct winsys_handle *whandle, + unsigned stride) +{ + struct i915_drm_buffer *buf = i915_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 void * +i915_drm_buffer_map(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + boolean write) +{ + struct i915_drm_buffer *buf = i915_drm_buffer(buffer); + drm_intel_bo *bo = intel_bo(buffer); + int ret = 0; + + assert(bo); + + if (buf->map_count) + goto out; + + ret = drm_intel_gem_bo_map_gtt(bo); + + buf->ptr = bo->virtual; + + assert(ret == 0); +out: + if (ret) + return NULL; + + buf->map_count++; + return buf->ptr; +} + +static void +i915_drm_buffer_unmap(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer) +{ + struct i915_drm_buffer *buf = i915_drm_buffer(buffer); + + if (--buf->map_count) + return; + + drm_intel_gem_bo_unmap_gtt(intel_bo(buffer)); +} + +static int +i915_drm_buffer_write(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + size_t offset, + size_t size, + const void *data) +{ + struct i915_drm_buffer *buf = i915_drm_buffer(buffer); + + return drm_intel_bo_subdata(buf->bo, offset, size, (void*)data); +} + +static void +i915_drm_buffer_destroy(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer) +{ + drm_intel_bo_unreference(intel_bo(buffer)); + +#ifdef DEBUG + i915_drm_buffer(buffer)->magic = 0; + i915_drm_buffer(buffer)->bo = NULL; +#endif + + FREE(buffer); +} + +void +i915_drm_winsys_init_buffer_functions(struct i915_drm_winsys *idws) +{ + idws->base.buffer_create = i915_drm_buffer_create; + idws->base.buffer_create_tiled = i915_drm_buffer_create_tiled; + idws->base.buffer_from_handle = i915_drm_buffer_from_handle; + idws->base.buffer_get_handle = i915_drm_buffer_get_handle; + idws->base.buffer_map = i915_drm_buffer_map; + idws->base.buffer_unmap = i915_drm_buffer_unmap; + idws->base.buffer_write = i915_drm_buffer_write; + idws->base.buffer_destroy = i915_drm_buffer_destroy; +} diff --git a/src/gallium/winsys/i915/drm/i915_drm_fence.c b/src/gallium/winsys/i915/drm/i915_drm_fence.c new file mode 100644 index 0000000..30ebf48 --- /dev/null +++ b/src/gallium/winsys/i915/drm/i915_drm_fence.c @@ -0,0 +1,83 @@ + +#include "i915_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 i915_drm_fence +{ + struct pipe_reference reference; + drm_intel_bo *bo; +}; + + +struct pipe_fence_handle * +i915_drm_fence_create(drm_intel_bo *bo) +{ + struct i915_drm_fence *fence = CALLOC_STRUCT(i915_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 +i915_drm_fence_reference(struct i915_winsys *iws, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + struct i915_drm_fence *old = (struct i915_drm_fence *)*ptr; + struct i915_drm_fence *f = (struct i915_drm_fence *)fence; + + if (pipe_reference(&((struct i915_drm_fence *)(*ptr))->reference, &f->reference)) { + if (old->bo) + drm_intel_bo_unreference(old->bo); + FREE(old); + } + *ptr = fence; +} + +static int +i915_drm_fence_signalled(struct i915_winsys *iws, + struct pipe_fence_handle *fence) +{ + assert(0); + + return 0; +} + +static int +i915_drm_fence_finish(struct i915_winsys *iws, + struct pipe_fence_handle *fence) +{ + struct i915_drm_fence *f = (struct i915_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 +i915_drm_winsys_init_fence_functions(struct i915_drm_winsys *idws) +{ + idws->base.fence_reference = i915_drm_fence_reference; + idws->base.fence_signalled = i915_drm_fence_signalled; + idws->base.fence_finish = i915_drm_fence_finish; +} diff --git a/src/gallium/winsys/i915/drm/i915_drm_public.h b/src/gallium/winsys/i915/drm/i915_drm_public.h new file mode 100644 index 0000000..b828d8d --- /dev/null +++ b/src/gallium/winsys/i915/drm/i915_drm_public.h @@ -0,0 +1,9 @@ + +#ifndef I915_DRM_PUBLIC_H +#define I915_DRM_PUBLIC_H + +struct i915_winsys; + +struct i915_winsys * i915_drm_winsys_create(int drmFD); + +#endif diff --git a/src/gallium/winsys/i915/drm/i915_drm_winsys.c b/src/gallium/winsys/i915/drm/i915_drm_winsys.c new file mode 100644 index 0000000..2288b48 --- /dev/null +++ b/src/gallium/winsys/i915/drm/i915_drm_winsys.c @@ -0,0 +1,78 @@ +#include + +#include "state_tracker/drm_driver.h" + +#include "i915_drm_winsys.h" +#include "i915_drm_public.h" +#include "util/u_memory.h" + + +/* + * Helper functions + */ + + +static void +i915_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 +i915_drm_winsys_destroy(struct i915_winsys *iws) +{ + struct i915_drm_winsys *idws = i915_drm_winsys(iws); + + drm_intel_bufmgr_destroy(idws->gem_manager); + + FREE(idws); +} + +struct i915_winsys * +i915_drm_winsys_create(int drmFD) +{ + struct i915_drm_winsys *idws; + unsigned int deviceID; + + idws = CALLOC_STRUCT(i915_drm_winsys); + if (!idws) + return NULL; + + i915_drm_get_device_id(&deviceID); + + i915_drm_winsys_init_batchbuffer_functions(idws); + i915_drm_winsys_init_buffer_functions(idws); + i915_drm_winsys_init_fence_functions(idws); + + idws->fd = drmFD; + idws->base.pci_id = deviceID; + idws->max_batch_size = 16 * 4096; + + idws->base.destroy = i915_drm_winsys_destroy; + + idws->gem_manager = drm_intel_bufmgr_gem_init(idws->fd, idws->max_batch_size); + drm_intel_bufmgr_gem_enable_reuse(idws->gem_manager); + drm_intel_bufmgr_gem_enable_fenced_relocs(idws->gem_manager); + + idws->dump_cmd = debug_get_bool_option("I915_DUMP_CMD", FALSE); + idws->send_cmd = !debug_get_bool_option("I915_NO_HW", FALSE); + + return &idws->base; +} diff --git a/src/gallium/winsys/i915/drm/i915_drm_winsys.h b/src/gallium/winsys/i915/drm/i915_drm_winsys.h new file mode 100644 index 0000000..0d74d02 --- /dev/null +++ b/src/gallium/winsys/i915/drm/i915_drm_winsys.h @@ -0,0 +1,72 @@ + +#ifndef INTEL_DRM_WINSYS_H +#define INTEL_DRM_WINSYS_H + +#include "i915/i915_batchbuffer.h" + +#include "drm.h" +#include "intel_bufmgr.h" + + +/* + * Winsys + */ + + +struct i915_drm_winsys +{ + struct i915_winsys base; + + boolean dump_cmd; + boolean send_cmd; + + int fd; /**< Drm file discriptor */ + + size_t max_batch_size; + + drm_intel_bufmgr *gem_manager; +}; + +static INLINE struct i915_drm_winsys * +i915_drm_winsys(struct i915_winsys *iws) +{ + return (struct i915_drm_winsys *)iws; +} + +struct pipe_fence_handle * i915_drm_fence_create(drm_intel_bo *bo); + +void i915_drm_winsys_init_batchbuffer_functions(struct i915_drm_winsys *idws); +void i915_drm_winsys_init_buffer_functions(struct i915_drm_winsys *idws); +void i915_drm_winsys_init_fence_functions(struct i915_drm_winsys *idws); + + +/* + * Buffer + */ + + +struct i915_drm_buffer { + unsigned magic; + + drm_intel_bo *bo; + + void *ptr; + unsigned map_count; + + boolean flinked; + unsigned flink; +}; + +static INLINE struct i915_drm_buffer * +i915_drm_buffer(struct i915_winsys_buffer *buffer) +{ + return (struct i915_drm_buffer *)buffer; +} + +static INLINE drm_intel_bo * +intel_bo(struct i915_winsys_buffer *buffer) +{ + return i915_drm_buffer(buffer)->bo; +} + +#endif diff --git a/src/gallium/winsys/i915/sw/Makefile b/src/gallium/winsys/i915/sw/Makefile new file mode 100644 index 0000000..6aab6d2 --- /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 0000000..84f427a --- /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 0000000..44773ae --- /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, bool fenced) +{ + 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 0000000..834805e --- /dev/null +++ b/src/gallium/winsys/i915/sw/i915_sw_buffer.c @@ -0,0 +1,114 @@ + +#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, + enum i915_winsys_buffer_type type) +{ + struct i915_sw_buffer *buf = CALLOC_STRUCT(i915_sw_buffer); + + if (!buf) + return NULL; + + buf->magic = 0xDEAD1337; + 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 struct i915_winsys_buffer * +i915_sw_buffer_create_tiled(struct i915_winsys *iws, + unsigned *stride, unsigned height, + enum i915_winsys_buffer_tile *tiling, + enum i915_winsys_buffer_type type) +{ + struct i915_sw_buffer *buf = CALLOC_STRUCT(i915_sw_buffer); + + if (!buf) + return NULL; + + buf->magic = 0xDEAD1337; + buf->type = type; + buf->ptr = CALLOC(*stride * height, 1); + buf->tiling = *tiling; + buf->stride = *stride; + + if (!buf->ptr) + goto err; + + return (struct i915_winsys_buffer *)buf; + +err: + assert(0); + FREE(buf); + return NULL; +} + +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_create_tiled = i915_sw_buffer_create_tiled; + 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 0000000..4b61b2a --- /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_public.h b/src/gallium/winsys/i915/sw/i915_sw_public.h new file mode 100644 index 0000000..e951a32 --- /dev/null +++ b/src/gallium/winsys/i915/sw/i915_sw_public.h @@ -0,0 +1,9 @@ + +#ifndef I915_SW_PUBLIC_H +#define I915_SW_PUBLIC_H + +struct i915_winsys; + +struct i915_winsys * i915_sw_winsys_create(void); + +#endif 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 0000000..058ddc4 --- /dev/null +++ b/src/gallium/winsys/i915/sw/i915_sw_winsys.c @@ -0,0 +1,56 @@ + +#include "i915_sw_winsys.h" +#include "i915_sw_public.h" +#include "util/u_memory.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 i915_winsys * +i915_sw_winsys_create() +{ + 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->base.pci_id = deviceID; + isws->max_batch_size = 16 * 4096; + + isws->dump_cmd = debug_get_bool_option("INTEL_DUMP_CMD", FALSE); + + return &isws->base; +} 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 0000000..3af2548 --- /dev/null +++ b/src/gallium/winsys/i915/sw/i915_sw_winsys.h @@ -0,0 +1,56 @@ + +#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; + + 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_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 tiling; + unsigned stride; +}; + +static INLINE struct i915_sw_buffer * +i915_sw_buffer(struct i915_winsys_buffer *buffer) +{ + return (struct i915_sw_buffer *)buffer; +} + +#endif diff --git a/src/gallium/winsys/i965/drm/Makefile b/src/gallium/winsys/i965/drm/Makefile new file mode 100644 index 0000000..46f98d7 --- /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_winsys.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 0000000..785be44 --- /dev/null +++ b/src/gallium/winsys/i965/drm/SConscript @@ -0,0 +1,17 @@ +Import('*') + +env = env.Clone() + +env.ParseConfig('pkg-config --cflags libdrm') + +i965drm_sources = [ + 'i965_drm_buffer.c', + 'i965_drm_winsys.c', +] + +i965drm = env.ConvenienceLibrary( + target ='i965drm', + source = i965drm_sources, +) + +Export('i965drm') 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 0000000..ed62db6 --- /dev/null +++ b/src/gallium/winsys/i965/drm/i965_drm_buffer.c @@ -0,0 +1,503 @@ + +#include "state_tracker/drm_driver.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->base.pci_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->base.pci_id, + buf->data_type, + buf->bo->offset + offset, + (char*)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_public.h b/src/gallium/winsys/i965/drm/i965_drm_public.h new file mode 100644 index 0000000..2913b07 --- /dev/null +++ b/src/gallium/winsys/i965/drm/i965_drm_public.h @@ -0,0 +1,9 @@ + +#ifndef I965_DRM_PUBLIC_H +#define I965_DRM_PUBLIC_H + +struct brw_winsys_screen; + +struct brw_winsys_screen * i965_drm_winsys_screen_create(int drmFD); + +#endif diff --git a/src/gallium/winsys/i965/drm/i965_drm_winsys.c b/src/gallium/winsys/i965/drm/i965_drm_winsys.c new file mode 100644 index 0000000..b08e622 --- /dev/null +++ b/src/gallium/winsys/i965/drm/i965_drm_winsys.c @@ -0,0 +1,74 @@ + +#include +#include "state_tracker/drm_driver.h" + +#include "i965_drm_winsys.h" +#include "i965_drm_public.h" +#include "util/u_memory.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); +} + +struct brw_winsys_screen * +i965_drm_winsys_screen_create(int drmFD) +{ + struct i965_libdrm_winsys *idws; + + debug_printf("%s\n", __FUNCTION__); + + idws = CALLOC_STRUCT(i965_libdrm_winsys); + if (!idws) + return NULL; + + i965_libdrm_get_device_id(&idws->base.pci_id); + + i965_libdrm_winsys_init_buffer_functions(idws); + + idws->fd = drmFD; + + 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 &idws->base; +} 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 0000000..82dbe61 --- /dev/null +++ b/src/gallium/winsys/i965/drm/i965_drm_winsys.h @@ -0,0 +1,60 @@ + +#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 */ +}; + +static INLINE struct i965_libdrm_winsys * +i965_libdrm_winsys(struct brw_winsys_screen *iws) +{ + return (struct i965_libdrm_winsys *)iws; +} + +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 0000000..cc82493 --- /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/mapi/glapi/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 0000000..c22df66 --- /dev/null +++ b/src/gallium/winsys/i965/xlib/xlib_i965.c @@ -0,0 +1,508 @@ +/************************************************************************** + * + * 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_resource.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.pci_id = PCI_CHIP_GM45_GM; + + 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_resource *resource, + unsigned level, unsigned layer) +{ + struct brw_texture *tex = brw_texture(resource); + struct xlib_brw_buffer *bo = xlib_brw_buffer(tex->bo); + /* not sure if the resource is really useful here but + since it was never implemented anyway... */ + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s level %u layer %u offset %x base sz %dx%d\n", __FUNCTION__, + level, layer, + bo->offset, + resource->width0, + resource->height0); +} + +static void +xlib_i965_flush_frontbuffer(struct pipe_screen *screen, + struct pipe_resource *resource, + unsigned level, unsigned layer, + void *context_private) +{ + xlib_i965_display_surface(NULL, resource, level, layer); +} + + +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); + 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 0000000..74a3c6a --- /dev/null +++ b/src/gallium/winsys/nouveau/drm/Makefile @@ -0,0 +1,11 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = nouveaudrm + +C_SOURCES = nouveau_drm_winsys.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 0000000..1207c2d --- /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_public.h b/src/gallium/winsys/nouveau/drm/nouveau_drm_public.h new file mode 100644 index 0000000..67b7c44 --- /dev/null +++ b/src/gallium/winsys/nouveau/drm/nouveau_drm_public.h @@ -0,0 +1,9 @@ + +#ifndef __NOUVEAU_DRM_PUBLIC_H__ +#define __NOUVEAU_DRM_PUBLIC_H__ + +struct pipe_screen; + +struct pipe_screen *nouveau_drm_screen_create(int drmFD); + +#endif diff --git a/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c b/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c new file mode 100644 index 0000000..d4bf124 --- /dev/null +++ b/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c @@ -0,0 +1,74 @@ +#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_winsys.h" +#include "nouveau_drm_public.h" + +#include "nouveau_drmif.h" +#include "nouveau_channel.h" +#include "nouveau_bo.h" + +#include "nouveau/nouveau_winsys.h" +#include "nouveau/nouveau_screen.h" + +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); + if (nv_screen) + nouveau_device_close(&nv_screen->device); + FREE(nv_winsys); +} + +struct pipe_screen * +nouveau_drm_screen_create(int fd) +{ + 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; + } + + return nvws->pscreen; +} diff --git a/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.h b/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.h new file mode 100644 index 0000000..9e529ec --- /dev/null +++ b/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.h @@ -0,0 +1,28 @@ +#ifndef __NOUVEAU_DRM_WINSYS_H__ +#define __NOUVEAU_DRM_WINSYS_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/r600/drm/Makefile b/src/gallium/winsys/r600/drm/Makefile new file mode 100644 index 0000000..91c6501 --- /dev/null +++ b/src/gallium/winsys/r600/drm/Makefile @@ -0,0 +1,23 @@ + +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = r600winsys + +C_SOURCES = \ + bof.c \ + evergreen_hw_context.c \ + radeon_bo.c \ + radeon_pciid.c \ + r600.c \ + r600_bo.c \ + r600_drm.c \ + r600_hw_context.c \ + r600_bomgr.c + +LIBRARY_INCLUDES = -I$(TOP)/src/gallium/drivers/r600 \ + $(shell pkg-config libdrm --cflags-only-I) + +include ../../../Makefile.template + +symlinks: diff --git a/src/gallium/winsys/r600/drm/SConscript b/src/gallium/winsys/r600/drm/SConscript new file mode 100644 index 0000000..dac0097 --- /dev/null +++ b/src/gallium/winsys/r600/drm/SConscript @@ -0,0 +1,25 @@ +Import('*') + +env = env.Clone() + +r600_sources = [ + 'bof.c', + 'evergreen_hw_context.c', + 'radeon_bo.c', + 'radeon_pciid.c', + 'r600.c', + 'r600_bo.c', + 'r600_drm.c', + 'r600_hw_context.c', + 'r600_bomgr.c', +] + +env.ParseConfig('pkg-config --cflags libdrm_radeon') +env.Append(CPPPATH = '#/src/gallium/drivers/r600') + +r600winsys = env.ConvenienceLibrary( + target ='r600winsys', + source = r600_sources, +) + +Export('r600winsys') diff --git a/src/gallium/winsys/r600/drm/bof.c b/src/gallium/winsys/r600/drm/bof.c new file mode 100644 index 0000000..0598cc6 --- /dev/null +++ b/src/gallium/winsys/r600/drm/bof.c @@ -0,0 +1,477 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#include +#include +#include +#include "bof.h" + +/* + * helpers + */ +static int bof_entry_grow(bof_t *bof) +{ + bof_t **array; + + if (bof->array_size < bof->nentry) + return 0; + array = realloc(bof->array, (bof->nentry + 16) * sizeof(void*)); + if (array == NULL) + return -ENOMEM; + bof->array = array; + bof->nentry += 16; + return 0; +} + +/* + * object + */ +bof_t *bof_object(void) +{ + bof_t *object; + + object = calloc(1, sizeof(bof_t)); + if (object == NULL) + return NULL; + object->refcount = 1; + object->type = BOF_TYPE_OBJECT; + object->size = 12; + return object; +} + +bof_t *bof_object_get(bof_t *object, const char *keyname) +{ + unsigned i; + + for (i = 0; i < object->array_size; i += 2) { + if (!strcmp(object->array[i]->value, keyname)) { + return object->array[i + 1]; + } + } + return NULL; +} + +int bof_object_set(bof_t *object, const char *keyname, bof_t *value) +{ + bof_t *key; + int r; + + if (object->type != BOF_TYPE_OBJECT) + return -EINVAL; + r = bof_entry_grow(object); + if (r) + return r; + key = bof_string(keyname); + if (key == NULL) + return -ENOMEM; + object->array[object->array_size++] = key; + object->array[object->array_size++] = value; + object->size += value->size; + object->size += key->size; + bof_incref(value); + return 0; +} + +/* + * array + */ +bof_t *bof_array(void) +{ + bof_t *array = bof_object(); + + if (array == NULL) + return NULL; + array->type = BOF_TYPE_ARRAY; + array->size = 12; + return array; +} + +int bof_array_append(bof_t *array, bof_t *value) +{ + int r; + if (array->type != BOF_TYPE_ARRAY) + return -EINVAL; + r = bof_entry_grow(array); + if (r) + return r; + array->array[array->array_size++] = value; + array->size += value->size; + bof_incref(value); + return 0; +} + +bof_t *bof_array_get(bof_t *bof, unsigned i) +{ + if (!bof_is_array(bof) || i >= bof->array_size) + return NULL; + return bof->array[i]; +} + +unsigned bof_array_size(bof_t *bof) +{ + if (!bof_is_array(bof)) + return 0; + return bof->array_size; +} + +/* + * blob + */ +bof_t *bof_blob(unsigned size, void *value) +{ + bof_t *blob = bof_object(); + + if (blob == NULL) + return NULL; + blob->type = BOF_TYPE_BLOB; + blob->value = calloc(1, size); + if (blob->value == NULL) { + bof_decref(blob); + return NULL; + } + blob->size = size; + memcpy(blob->value, value, size); + blob->size += 12; + return blob; +} + +unsigned bof_blob_size(bof_t *bof) +{ + if (!bof_is_blob(bof)) + return 0; + return bof->size - 12; +} + +void *bof_blob_value(bof_t *bof) +{ + if (!bof_is_blob(bof)) + return NULL; + return bof->value; +} + +/* + * string + */ +bof_t *bof_string(const char *value) +{ + bof_t *string = bof_object(); + + if (string == NULL) + return NULL; + string->type = BOF_TYPE_STRING; + string->size = strlen(value) + 1; + string->value = calloc(1, string->size); + if (string->value == NULL) { + bof_decref(string); + return NULL; + } + strcpy(string->value, value); + string->size += 12; + return string; +} + +/* + * int32 + */ +bof_t *bof_int32(int32_t value) +{ + bof_t *int32 = bof_object(); + + if (int32 == NULL) + return NULL; + int32->type = BOF_TYPE_INT32; + int32->size = 4; + int32->value = calloc(1, int32->size); + if (int32->value == NULL) { + bof_decref(int32); + return NULL; + } + memcpy(int32->value, &value, 4); + int32->size += 12; + return int32; +} + +int32_t bof_int32_value(bof_t *bof) +{ + return *((uint32_t*)bof->value); +} + +/* + * common + */ +static void bof_indent(int level) +{ + int i; + + for (i = 0; i < level; i++) + fprintf(stderr, " "); +} + +static void bof_print_bof(bof_t *bof, int level, int entry) +{ + bof_indent(level); + if (bof == NULL) { + fprintf(stderr, "--NULL-- for entry %d\n", entry); + return; + } + switch (bof->type) { + case BOF_TYPE_STRING: + fprintf(stderr, "%p string [%s %d]\n", bof, (char*)bof->value, bof->size); + break; + case BOF_TYPE_INT32: + fprintf(stderr, "%p int32 [%d %d]\n", bof, *(int*)bof->value, bof->size); + break; + case BOF_TYPE_BLOB: + fprintf(stderr, "%p blob [%d]\n", bof, bof->size); + break; + case BOF_TYPE_NULL: + fprintf(stderr, "%p null [%d]\n", bof, bof->size); + break; + case BOF_TYPE_OBJECT: + fprintf(stderr, "%p object [%d %d]\n", bof, bof->array_size / 2, bof->size); + break; + case BOF_TYPE_ARRAY: + fprintf(stderr, "%p array [%d %d]\n", bof, bof->array_size, bof->size); + break; + default: + fprintf(stderr, "%p unknown [%d]\n", bof, bof->type); + return; + } +} + +static void bof_print_rec(bof_t *bof, int level, int entry) +{ + unsigned i; + + bof_print_bof(bof, level, entry); + for (i = 0; i < bof->array_size; i++) { + bof_print_rec(bof->array[i], level + 2, i); + } +} + +void bof_print(bof_t *bof) +{ + bof_print_rec(bof, 0, 0); +} + +static int bof_read(bof_t *root, FILE *file, long end, int level) +{ + bof_t *bof = NULL; + int r; + + if (ftell(file) >= end) { + return 0; + } + r = bof_entry_grow(root); + if (r) + return r; + bof = bof_object(); + if (bof == NULL) + return -ENOMEM; + bof->offset = ftell(file); + r = fread(&bof->type, 4, 1, file); + if (r != 1) + goto out_err; + r = fread(&bof->size, 4, 1, file); + if (r != 1) + goto out_err; + r = fread(&bof->array_size, 4, 1, file); + if (r != 1) + goto out_err; + switch (bof->type) { + case BOF_TYPE_STRING: + case BOF_TYPE_INT32: + case BOF_TYPE_BLOB: + bof->value = calloc(1, bof->size - 12); + if (bof->value == NULL) { + goto out_err; + } + r = fread(bof->value, bof->size - 12, 1, file); + if (r != 1) { + fprintf(stderr, "error reading %d\n", bof->size - 12); + goto out_err; + } + break; + case BOF_TYPE_NULL: + return 0; + case BOF_TYPE_OBJECT: + case BOF_TYPE_ARRAY: + r = bof_read(bof, file, bof->offset + bof->size, level + 2); + if (r) + goto out_err; + break; + default: + fprintf(stderr, "invalid type %d\n", bof->type); + goto out_err; + } + root->array[root->centry++] = bof; + return bof_read(root, file, end, level); +out_err: + bof_decref(bof); + return -EINVAL; +} + +bof_t *bof_load_file(const char *filename) +{ + bof_t *root = bof_object(); + int r; + + if (root == NULL) { + fprintf(stderr, "%s failed to create root object\n", __func__); + return NULL; + } + root->file = fopen(filename, "r"); + if (root->file == NULL) + goto out_err; + r = fseek(root->file, 0L, SEEK_SET); + if (r) { + fprintf(stderr, "%s failed to seek into file %s\n", __func__, filename); + goto out_err; + } + root->offset = ftell(root->file); + r = fread(&root->type, 4, 1, root->file); + if (r != 1) + goto out_err; + r = fread(&root->size, 4, 1, root->file); + if (r != 1) + goto out_err; + r = fread(&root->array_size, 4, 1, root->file); + if (r != 1) + goto out_err; + r = bof_read(root, root->file, root->offset + root->size, 2); + if (r) + goto out_err; + return root; +out_err: + bof_decref(root); + return NULL; +} + +void bof_incref(bof_t *bof) +{ + bof->refcount++; +} + +void bof_decref(bof_t *bof) +{ + unsigned i; + + if (bof == NULL) + return; + if (--bof->refcount > 0) + return; + for (i = 0; i < bof->array_size; i++) { + bof_decref(bof->array[i]); + bof->array[i] = NULL; + } + bof->array_size = 0; + if (bof->file) { + fclose(bof->file); + bof->file = NULL; + } + free(bof->array); + free(bof->value); + free(bof); +} + +static int bof_file_write(bof_t *bof, FILE *file) +{ + unsigned i; + int r; + + r = fwrite(&bof->type, 4, 1, file); + if (r != 1) + return -EINVAL; + r = fwrite(&bof->size, 4, 1, file); + if (r != 1) + return -EINVAL; + r = fwrite(&bof->array_size, 4, 1, file); + if (r != 1) + return -EINVAL; + switch (bof->type) { + case BOF_TYPE_NULL: + if (bof->size) + return -EINVAL; + break; + case BOF_TYPE_STRING: + case BOF_TYPE_INT32: + case BOF_TYPE_BLOB: + r = fwrite(bof->value, bof->size - 12, 1, file); + if (r != 1) + return -EINVAL; + break; + case BOF_TYPE_OBJECT: + case BOF_TYPE_ARRAY: + for (i = 0; i < bof->array_size; i++) { + r = bof_file_write(bof->array[i], file); + if (r) + return r; + } + break; + default: + return -EINVAL; + } + return 0; +} + +int bof_dump_file(bof_t *bof, const char *filename) +{ + unsigned i; + int r = 0; + + if (bof->file) { + fclose(bof->file); + bof->file = NULL; + } + bof->file = fopen(filename, "w"); + if (bof->file == NULL) { + fprintf(stderr, "%s failed to open file %s\n", __func__, filename); + r = -EINVAL; + goto out_err; + } + r = fseek(bof->file, 0L, SEEK_SET); + if (r) { + fprintf(stderr, "%s failed to seek into file %s\n", __func__, filename); + goto out_err; + } + r = fwrite(&bof->type, 4, 1, bof->file); + if (r != 1) + goto out_err; + r = fwrite(&bof->size, 4, 1, bof->file); + if (r != 1) + goto out_err; + r = fwrite(&bof->array_size, 4, 1, bof->file); + if (r != 1) + goto out_err; + for (i = 0; i < bof->array_size; i++) { + r = bof_file_write(bof->array[i], bof->file); + if (r) + return r; + } +out_err: + fclose(bof->file); + bof->file = NULL; + return r; +} diff --git a/src/gallium/winsys/r600/drm/bof.h b/src/gallium/winsys/r600/drm/bof.h new file mode 100644 index 0000000..014affb --- /dev/null +++ b/src/gallium/winsys/r600/drm/bof.h @@ -0,0 +1,90 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#ifndef BOF_H +#define BOF_H + +#include +#include + +#define BOF_TYPE_STRING 0 +#define BOF_TYPE_NULL 1 +#define BOF_TYPE_BLOB 2 +#define BOF_TYPE_OBJECT 3 +#define BOF_TYPE_ARRAY 4 +#define BOF_TYPE_INT32 5 + +struct bof; + +typedef struct bof { + struct bof **array; + unsigned centry; + unsigned nentry; + unsigned refcount; + FILE *file; + uint32_t type; + uint32_t size; + uint32_t array_size; + void *value; + long offset; +} bof_t; + +extern int bof_file_flush(bof_t *root); +extern bof_t *bof_file_new(const char *filename); +extern int bof_object_dump(bof_t *object, const char *filename); + +/* object */ +extern bof_t *bof_object(void); +extern bof_t *bof_object_get(bof_t *object, const char *keyname); +extern int bof_object_set(bof_t *object, const char *keyname, bof_t *value); +/* array */ +extern bof_t *bof_array(void); +extern int bof_array_append(bof_t *array, bof_t *value); +extern bof_t *bof_array_get(bof_t *bof, unsigned i); +extern unsigned bof_array_size(bof_t *bof); +/* blob */ +extern bof_t *bof_blob(unsigned size, void *value); +extern unsigned bof_blob_size(bof_t *bof); +extern void *bof_blob_value(bof_t *bof); +/* string */ +extern bof_t *bof_string(const char *value); +/* int32 */ +extern bof_t *bof_int32(int32_t value); +extern int32_t bof_int32_value(bof_t *bof); +/* common functions */ +extern void bof_decref(bof_t *bof); +extern void bof_incref(bof_t *bof); +extern bof_t *bof_load_file(const char *filename); +extern int bof_dump_file(bof_t *bof, const char *filename); +extern void bof_print(bof_t *bof); + +static inline int bof_is_object(bof_t *bof){return (bof->type == BOF_TYPE_OBJECT);} +static inline int bof_is_blob(bof_t *bof){return (bof->type == BOF_TYPE_BLOB);} +static inline int bof_is_null(bof_t *bof){return (bof->type == BOF_TYPE_NULL);} +static inline int bof_is_int32(bof_t *bof){return (bof->type == BOF_TYPE_INT32);} +static inline int bof_is_array(bof_t *bof){return (bof->type == BOF_TYPE_ARRAY);} +static inline int bof_is_string(bof_t *bof){return (bof->type == BOF_TYPE_STRING);} + +#endif diff --git a/src/gallium/winsys/r600/drm/evergreen_hw_context.c b/src/gallium/winsys/r600/drm/evergreen_hw_context.c new file mode 100644 index 0000000..054b2b8 --- /dev/null +++ b/src/gallium/winsys/r600/drm/evergreen_hw_context.c @@ -0,0 +1,935 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#include +#include +#include +#include +#include +#include "xf86drm.h" +#include "r600.h" +#include "evergreend.h" +#include "radeon_drm.h" +#include "bof.h" +#include "pipe/p_compiler.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "r600_priv.h" + +#define GROUP_FORCE_NEW_BLOCK 0 + +static const struct r600_reg evergreen_config_reg_list[] = { + {PKT3_SET_CONFIG_REG, EVERGREEN_CONFIG_REG_OFFSET, R_008958_VGT_PRIMITIVE_TYPE, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, EVERGREEN_CONFIG_REG_OFFSET, R_008A14_PA_CL_ENHANCE, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, EVERGREEN_CONFIG_REG_OFFSET, R_008C00_SQ_CONFIG, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, EVERGREEN_CONFIG_REG_OFFSET, R_008C04_SQ_GPR_RESOURCE_MGMT_1, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, EVERGREEN_CONFIG_REG_OFFSET, R_008C08_SQ_GPR_RESOURCE_MGMT_2, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, EVERGREEN_CONFIG_REG_OFFSET, R_008C0C_SQ_THREAD_RESOURCE_MGMT, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, EVERGREEN_CONFIG_REG_OFFSET, R_008C18_SQ_THREAD_RESOURCE_MGMT_1, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, EVERGREEN_CONFIG_REG_OFFSET, R_008C1C_SQ_THREAD_RESOURCE_MGMT_2, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, EVERGREEN_CONFIG_REG_OFFSET, R_008C20_SQ_STACK_RESOURCE_MGMT_1, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, EVERGREEN_CONFIG_REG_OFFSET, R_008C24_SQ_STACK_RESOURCE_MGMT_2, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, EVERGREEN_CONFIG_REG_OFFSET, R_008C28_SQ_STACK_RESOURCE_MGMT_3, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, EVERGREEN_CONFIG_REG_OFFSET, R_008D8C_SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, EVERGREEN_CONFIG_REG_OFFSET, R_009100_SPI_CONFIG_CNTL, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, EVERGREEN_CONFIG_REG_OFFSET, R_00913C_SPI_CONFIG_CNTL_1, 0, 0, 0}, +}; + +static const struct r600_reg evergreen_ctl_const_list[] = { + {PKT3_SET_CTL_CONST, EVERGREEN_CTL_CONST_OFFSET, R_03CFF0_SQ_VTX_BASE_VTX_LOC, 0, 0, 0}, + {PKT3_SET_CTL_CONST, EVERGREEN_CTL_CONST_OFFSET, R_03CFF4_SQ_VTX_START_INST_LOC, 0, 0, 0}, +}; + +static const struct r600_reg evergreen_context_reg_list[] = { + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028000_DB_RENDER_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028004_DB_COUNT_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028008_DB_DEPTH_VIEW, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02800C_DB_RENDER_OVERRIDE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028010_DB_RENDER_OVERRIDE2, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028014_DB_HTILE_DATA_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028028_DB_STENCIL_CLEAR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02802C_DB_DEPTH_CLEAR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028030_PA_SC_SCREEN_SCISSOR_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028034_PA_SC_SCREEN_SCISSOR_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028040_DB_Z_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028044_DB_STENCIL_INFO, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028048_DB_Z_READ_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02804C_DB_STENCIL_READ_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028050_DB_Z_WRITE_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028054_DB_STENCIL_WRITE_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028058_DB_DEPTH_SIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02805C_DB_DEPTH_SLICE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028140_ALU_CONST_BUFFER_SIZE_PS_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028180_ALU_CONST_BUFFER_SIZE_VS_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028200_PA_SC_WINDOW_OFFSET, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028204_PA_SC_WINDOW_SCISSOR_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028208_PA_SC_WINDOW_SCISSOR_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02820C_PA_SC_CLIPRECT_RULE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028210_PA_SC_CLIPRECT_0_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028214_PA_SC_CLIPRECT_0_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028218_PA_SC_CLIPRECT_1_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02821C_PA_SC_CLIPRECT_1_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028220_PA_SC_CLIPRECT_2_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028224_PA_SC_CLIPRECT_2_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028228_PA_SC_CLIPRECT_3_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02822C_PA_SC_CLIPRECT_3_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028230_PA_SC_EDGERULE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028234_PA_SU_HARDWARE_SCREEN_OFFSET, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028238_CB_TARGET_MASK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02823C_CB_SHADER_MASK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028240_PA_SC_GENERIC_SCISSOR_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028244_PA_SC_GENERIC_SCISSOR_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028250_PA_SC_VPORT_SCISSOR_0_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028254_PA_SC_VPORT_SCISSOR_0_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028350_SX_MISC, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028380_SQ_VTX_SEMANTIC_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028384_SQ_VTX_SEMANTIC_1, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028388_SQ_VTX_SEMANTIC_2, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02838C_SQ_VTX_SEMANTIC_3, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028390_SQ_VTX_SEMANTIC_4, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028394_SQ_VTX_SEMANTIC_5, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028398_SQ_VTX_SEMANTIC_6, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02839C_SQ_VTX_SEMANTIC_7, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283A0_SQ_VTX_SEMANTIC_8, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283A4_SQ_VTX_SEMANTIC_9, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283A8_SQ_VTX_SEMANTIC_10, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283AC_SQ_VTX_SEMANTIC_11, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283B0_SQ_VTX_SEMANTIC_12, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283B4_SQ_VTX_SEMANTIC_13, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283B8_SQ_VTX_SEMANTIC_14, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283BC_SQ_VTX_SEMANTIC_15, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283C0_SQ_VTX_SEMANTIC_16, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283C4_SQ_VTX_SEMANTIC_17, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283C8_SQ_VTX_SEMANTIC_18, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283CC_SQ_VTX_SEMANTIC_19, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283D0_SQ_VTX_SEMANTIC_20, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283D4_SQ_VTX_SEMANTIC_21, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283D8_SQ_VTX_SEMANTIC_22, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283DC_SQ_VTX_SEMANTIC_23, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283E0_SQ_VTX_SEMANTIC_24, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283E4_SQ_VTX_SEMANTIC_25, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283E8_SQ_VTX_SEMANTIC_26, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283EC_SQ_VTX_SEMANTIC_27, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283F0_SQ_VTX_SEMANTIC_28, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283F4_SQ_VTX_SEMANTIC_29, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283F8_SQ_VTX_SEMANTIC_30, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0283FC_SQ_VTX_SEMANTIC_31, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0282D0_PA_SC_VPORT_ZMIN_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0282D4_PA_SC_VPORT_ZMAX_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028400_VGT_MAX_VTX_INDX, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028404_VGT_MIN_VTX_INDX, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028408_VGT_INDX_OFFSET, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02840C_VGT_MULTI_PRIM_IB_RESET_INDX, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028410_SX_ALPHA_TEST_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028414_CB_BLEND_RED, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028418_CB_BLEND_GREEN, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02841C_CB_BLEND_BLUE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028420_CB_BLEND_ALPHA, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028430_DB_STENCILREFMASK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028434_DB_STENCILREFMASK_BF, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028438_SX_ALPHA_REF, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02843C_PA_CL_VPORT_XSCALE_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028440_PA_CL_VPORT_XOFFSET_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028444_PA_CL_VPORT_YSCALE_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028448_PA_CL_VPORT_YOFFSET_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02844C_PA_CL_VPORT_ZSCALE_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028450_PA_CL_VPORT_ZOFFSET_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285BC_PA_CL_UCP0_X, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285C0_PA_CL_UCP0_Y, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285C4_PA_CL_UCP0_Z, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285C8_PA_CL_UCP0_W, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285CC_PA_CL_UCP1_X, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285D0_PA_CL_UCP1_Y, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285D4_PA_CL_UCP1_Z, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285D8_PA_CL_UCP1_W, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285DC_PA_CL_UCP2_X, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285E0_PA_CL_UCP2_Y, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285E4_PA_CL_UCP2_Z, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285E8_PA_CL_UCP2_W, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285EC_PA_CL_UCP3_X, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285F0_PA_CL_UCP3_Y, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285F4_PA_CL_UCP3_Z, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285F8_PA_CL_UCP3_W, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0285FC_PA_CL_UCP4_X, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028600_PA_CL_UCP4_Y, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028604_PA_CL_UCP4_Z, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028608_PA_CL_UCP4_W, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02860C_PA_CL_UCP5_X, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028610_PA_CL_UCP5_Y, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028614_PA_CL_UCP5_Z, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028618_PA_CL_UCP5_W, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02861C_SPI_VS_OUT_ID_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028620_SPI_VS_OUT_ID_1, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028624_SPI_VS_OUT_ID_2, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028628_SPI_VS_OUT_ID_3, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02862C_SPI_VS_OUT_ID_4, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028630_SPI_VS_OUT_ID_5, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028634_SPI_VS_OUT_ID_6, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028638_SPI_VS_OUT_ID_7, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02863C_SPI_VS_OUT_ID_8, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028640_SPI_VS_OUT_ID_9, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028644_SPI_PS_INPUT_CNTL_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028648_SPI_PS_INPUT_CNTL_1, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02864C_SPI_PS_INPUT_CNTL_2, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028650_SPI_PS_INPUT_CNTL_3, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028654_SPI_PS_INPUT_CNTL_4, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028658_SPI_PS_INPUT_CNTL_5, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02865C_SPI_PS_INPUT_CNTL_6, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028660_SPI_PS_INPUT_CNTL_7, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028664_SPI_PS_INPUT_CNTL_8, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028668_SPI_PS_INPUT_CNTL_9, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02866C_SPI_PS_INPUT_CNTL_10, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028670_SPI_PS_INPUT_CNTL_11, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028674_SPI_PS_INPUT_CNTL_12, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028678_SPI_PS_INPUT_CNTL_13, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02867C_SPI_PS_INPUT_CNTL_14, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028680_SPI_PS_INPUT_CNTL_15, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028684_SPI_PS_INPUT_CNTL_16, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028688_SPI_PS_INPUT_CNTL_17, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02868C_SPI_PS_INPUT_CNTL_18, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028690_SPI_PS_INPUT_CNTL_19, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028694_SPI_PS_INPUT_CNTL_20, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028698_SPI_PS_INPUT_CNTL_21, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02869C_SPI_PS_INPUT_CNTL_22, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286A0_SPI_PS_INPUT_CNTL_23, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286A4_SPI_PS_INPUT_CNTL_24, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286A8_SPI_PS_INPUT_CNTL_25, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286AC_SPI_PS_INPUT_CNTL_26, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286B0_SPI_PS_INPUT_CNTL_27, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286B4_SPI_PS_INPUT_CNTL_28, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286B8_SPI_PS_INPUT_CNTL_29, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286BC_SPI_PS_INPUT_CNTL_30, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286C0_SPI_PS_INPUT_CNTL_31, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286C4_SPI_VS_OUT_CONFIG, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286C8_SPI_THREAD_GROUPING, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286CC_SPI_PS_IN_CONTROL_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286D0_SPI_PS_IN_CONTROL_1, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286D4_SPI_INTERP_CONTROL_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286D8_SPI_INPUT_Z, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286DC_SPI_FOG_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286E0_SPI_BARYC_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286E4_SPI_PS_IN_CONTROL_2, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0286E8_SPI_COMPUTE_INPUT_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028780_CB_BLEND0_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028784_CB_BLEND1_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028788_CB_BLEND2_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02878C_CB_BLEND3_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028790_CB_BLEND4_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028794_CB_BLEND5_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028798_CB_BLEND6_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02879C_CB_BLEND7_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028800_DB_DEPTH_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02880C_DB_SHADER_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028808_CB_COLOR_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028810_PA_CL_CLIP_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028814_PA_SU_SC_MODE_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028818_PA_CL_VTE_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02881C_PA_CL_VS_OUT_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028820_PA_CL_NANINF_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028838_SQ_DYN_GPR_RESOURCE_LIMIT_1, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028840_SQ_PGM_START_PS, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028844_SQ_PGM_RESOURCES_PS, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028848_SQ_PGM_RESOURCES_2_PS, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02884C_SQ_PGM_EXPORTS_PS, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02885C_SQ_PGM_START_VS, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028860_SQ_PGM_RESOURCES_VS, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028864_SQ_PGM_RESOURCES_2_VS, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0288A4_SQ_PGM_START_FS, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0288A8_SQ_PGM_RESOURCES_FS, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0288EC_SQ_LDS_ALLOC_PS, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028900_SQ_ESGS_RING_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028904_SQ_GSVS_RING_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028908_SQ_ESTMP_RING_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02890C_SQ_GSTMP_RING_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028910_SQ_VSTMP_RING_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028914_SQ_PSTMP_RING_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02891C_SQ_GS_VERT_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028920_SQ_GS_VERT_ITEMSIZE_1, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028924_SQ_GS_VERT_ITEMSIZE_2, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028928_SQ_GS_VERT_ITEMSIZE_3, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028940_ALU_CONST_CACHE_PS_0, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028980_ALU_CONST_CACHE_VS_0, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A00_PA_SU_POINT_SIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A04_PA_SU_POINT_MINMAX, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A08_PA_SU_LINE_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A10_VGT_OUTPUT_PATH_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A14_VGT_HOS_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A18_VGT_HOS_MAX_TESS_LEVEL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A1C_VGT_HOS_MIN_TESS_LEVEL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A20_VGT_HOS_REUSE_DEPTH, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A24_VGT_GROUP_PRIM_TYPE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A28_VGT_GROUP_FIRST_DECR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A2C_VGT_GROUP_DECR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A30_VGT_GROUP_VECT_0_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A34_VGT_GROUP_VECT_1_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A38_VGT_GROUP_VECT_0_FMT_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A3C_VGT_GROUP_VECT_1_FMT_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A40_VGT_GS_MODE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A48_PA_SC_MODE_CNTL_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A4C_PA_SC_MODE_CNTL_1, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028AB4_VGT_REUSE_OFF, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028AB8_VGT_VTX_CNT_EN, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028ABC_DB_HTILE_SURFACE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028AC0_DB_SRESULTS_COMPARE_STATE0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028AC4_DB_SRESULTS_COMPARE_STATE1, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028AC8_DB_PRELOAD_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028B54_VGT_SHADER_STAGES_EN, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028B70_DB_ALPHA_TO_MASK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028B78_PA_SU_POLY_OFFSET_DB_FMT_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028B7C_PA_SU_POLY_OFFSET_CLAMP, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028B80_PA_SU_POLY_OFFSET_FRONT_SCALE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028B84_PA_SU_POLY_OFFSET_FRONT_OFFSET, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028B88_PA_SU_POLY_OFFSET_BACK_SCALE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028B8C_PA_SU_POLY_OFFSET_BACK_OFFSET, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028B94_VGT_STRMOUT_CONFIG, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028B98_VGT_STRMOUT_BUFFER_CONFIG, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C00_PA_SC_LINE_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C04_PA_SC_AA_CONFIG, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C08_PA_SU_VTX_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C0C_PA_CL_GB_VERT_CLIP_ADJ, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C10_PA_CL_GB_VERT_DISC_ADJ, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C14_PA_CL_GB_HORZ_CLIP_ADJ, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C18_PA_CL_GB_HORZ_DISC_ADJ, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C1C_PA_SC_AA_SAMPLE_LOCS_MCTX, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C3C_PA_SC_AA_MASK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C60_CB_COLOR0_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C64_CB_COLOR0_PITCH, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C68_CB_COLOR0_SLICE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C6C_CB_COLOR0_VIEW, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C70_CB_COLOR0_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C74_CB_COLOR0_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C78_CB_COLOR0_DIM, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C9C_CB_COLOR1_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CA0_CB_COLOR1_PITCH, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CA4_CB_COLOR1_SLICE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CA8_CB_COLOR1_VIEW, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CAC_CB_COLOR1_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CB0_CB_COLOR1_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CB4_CB_COLOR1_DIM, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CD8_CB_COLOR2_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CDC_CB_COLOR2_PITCH, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CE0_CB_COLOR2_SLICE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CE4_CB_COLOR2_VIEW, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CE8_CB_COLOR2_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CEC_CB_COLOR2_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CF0_CB_COLOR2_DIM, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D14_CB_COLOR3_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D18_CB_COLOR3_PITCH, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D1C_CB_COLOR3_SLICE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D20_CB_COLOR3_VIEW, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D24_CB_COLOR3_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D28_CB_COLOR3_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D2C_CB_COLOR3_DIM, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D50_CB_COLOR4_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D54_CB_COLOR4_PITCH, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D58_CB_COLOR4_SLICE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D5C_CB_COLOR4_VIEW, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D60_CB_COLOR4_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D64_CB_COLOR4_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D68_CB_COLOR4_DIM, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D8C_CB_COLOR5_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D90_CB_COLOR5_PITCH, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D94_CB_COLOR5_SLICE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D98_CB_COLOR5_VIEW, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D9C_CB_COLOR5_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DA0_CB_COLOR5_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DA4_CB_COLOR5_DIM, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DC8_CB_COLOR6_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DCC_CB_COLOR6_PITCH, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DD0_CB_COLOR6_SLICE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DD4_CB_COLOR6_VIEW, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DD8_CB_COLOR6_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DDC_CB_COLOR6_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DE0_CB_COLOR6_DIM, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E04_CB_COLOR7_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E08_CB_COLOR7_PITCH, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E0C_CB_COLOR7_SLICE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E10_CB_COLOR7_VIEW, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E14_CB_COLOR7_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E18_CB_COLOR7_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E1C_CB_COLOR7_DIM, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E40_CB_COLOR8_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E44_CB_COLOR8_PITCH, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E48_CB_COLOR8_SLICE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E4C_CB_COLOR8_VIEW, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E50_CB_COLOR8_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E54_CB_COLOR8_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E58_CB_COLOR8_DIM, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E5C_CB_COLOR9_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E60_CB_COLOR9_PITCH, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E64_CB_COLOR9_SLICE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E68_CB_COLOR9_VIEW, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E6C_CB_COLOR9_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E70_CB_COLOR9_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E74_CB_COLOR9_DIM, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E78_CB_COLOR10_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E7C_CB_COLOR10_PITCH, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E80_CB_COLOR10_SLICE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E84_CB_COLOR10_VIEW, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E88_CB_COLOR10_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E8C_CB_COLOR10_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E90_CB_COLOR10_DIM, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E94_CB_COLOR11_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E98_CB_COLOR11_PITCH, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E9C_CB_COLOR11_SLICE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028EA0_CB_COLOR11_VIEW, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028EA4_CB_COLOR11_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028EA8_CB_COLOR11_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028EAC_CB_COLOR11_DIM, 0, 0, 0}, +}; + +/* SHADER RESOURCE R600/R700 */ +static int evergreen_state_resource_init(struct r600_context *ctx, u32 offset) +{ + struct r600_reg r600_shader_resource[] = { + {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_030000_RESOURCE0_WORD0, 0, 0, 0}, + {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_030004_RESOURCE0_WORD1, 0, 0, 0}, + {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_030008_RESOURCE0_WORD2, 1, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_VC_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_03000C_RESOURCE0_WORD3, 1, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_VC_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_030010_RESOURCE0_WORD4, 0, 0, 0}, + {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_030014_RESOURCE0_WORD5, 0, 0, 0}, + {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_030018_RESOURCE0_WORD6, 0, 0, 0}, + {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_03001C_RESOURCE0_WORD7, 0, 0, 0}, + }; + unsigned nreg = Elements(r600_shader_resource); + + for (int i = 0; i < nreg; i++) { + r600_shader_resource[i].offset += offset; + } + return r600_context_add_block(ctx, r600_shader_resource, nreg); +} + +/* SHADER SAMPLER R600/R700 */ +static int r600_state_sampler_init(struct r600_context *ctx, u32 offset) +{ + struct r600_reg r600_shader_sampler[] = { + {PKT3_SET_SAMPLER, EVERGREEN_SAMPLER_OFFSET, R_03C000_SQ_TEX_SAMPLER_WORD0_0, 0, 0, 0}, + {PKT3_SET_SAMPLER, EVERGREEN_SAMPLER_OFFSET, R_03C004_SQ_TEX_SAMPLER_WORD1_0, 0, 0, 0}, + {PKT3_SET_SAMPLER, EVERGREEN_SAMPLER_OFFSET, R_03C008_SQ_TEX_SAMPLER_WORD2_0, 0, 0, 0}, + }; + unsigned nreg = Elements(r600_shader_sampler); + + for (int i = 0; i < nreg; i++) { + r600_shader_sampler[i].offset += offset; + } + return r600_context_add_block(ctx, r600_shader_sampler, nreg); +} + +/* SHADER SAMPLER BORDER R600/R700 */ +static int evergreen_state_sampler_border_init(struct r600_context *ctx, u32 offset, unsigned id) +{ + struct r600_reg r600_shader_sampler_border[] = { + {PKT3_SET_CONFIG_REG, 0, R_00A400_TD_PS_SAMPLER0_BORDER_INDEX, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, 0, R_00A404_TD_PS_SAMPLER0_BORDER_RED, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, 0, R_00A408_TD_PS_SAMPLER0_BORDER_GREEN, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, 0, R_00A40C_TD_PS_SAMPLER0_BORDER_BLUE, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, 0, R_00A410_TD_PS_SAMPLER0_BORDER_ALPHA, 0, 0, 0}, + }; + unsigned nreg = Elements(r600_shader_sampler_border); + unsigned fake_offset = (offset - R_00A400_TD_PS_SAMPLER0_BORDER_INDEX) * 0x100 + 0x40000 + id * 0x1C; + struct r600_range *range; + struct r600_block *block; + int r; + + for (int i = 0; i < nreg; i++) { + r600_shader_sampler_border[i].offset -= R_00A400_TD_PS_SAMPLER0_BORDER_INDEX; + r600_shader_sampler_border[i].offset += fake_offset; + } + r = r600_context_add_block(ctx, r600_shader_sampler_border, nreg); + if (r) { + return r; + } + /* set proper offset */ + range = &ctx->range[CTX_RANGE_ID(ctx, r600_shader_sampler_border[0].offset)]; + block = range->blocks[CTX_BLOCK_ID(ctx, r600_shader_sampler_border[0].offset)]; + block->pm4[1] = (offset - EVERGREEN_CONFIG_REG_OFFSET) >> 2; + return 0; +} + +static int evergreen_loop_const_init(struct r600_context *ctx, u32 offset) +{ + unsigned nreg = 32; + struct r600_reg r600_loop_consts[32]; + int i; + + for (i = 0; i < nreg; i++) { + r600_loop_consts[i].opcode = PKT3_SET_LOOP_CONST; + r600_loop_consts[i].offset_base = EVERGREEN_LOOP_CONST_OFFSET; + r600_loop_consts[i].offset = EVERGREEN_LOOP_CONST_OFFSET + ((offset + i) * 4); + r600_loop_consts[i].need_bo = 0; + r600_loop_consts[i].flush_flags = 0; + } + return r600_context_add_block(ctx, r600_loop_consts, nreg); +} + +int evergreen_context_init(struct r600_context *ctx, struct radeon *radeon) +{ + int r; + + memset(ctx, 0, sizeof(struct r600_context)); + ctx->radeon = radeon; + LIST_INITHEAD(&ctx->query_list); + + /* initialize hash */ + ctx->hash_size = 19; + ctx->hash_shift = 11; + for (int i = 0; i < 256; i++) { + ctx->range[i].start_offset = i << ctx->hash_shift; + ctx->range[i].end_offset = ((i + 1) << ctx->hash_shift) - 1; + ctx->range[i].blocks = calloc(1 << ctx->hash_shift, sizeof(void*)); + if (ctx->range[i].blocks == NULL) { + return -ENOMEM; + } + } + + /* add blocks */ + r = r600_context_add_block(ctx, evergreen_config_reg_list, + Elements(evergreen_config_reg_list)); + if (r) + goto out_err; + r = r600_context_add_block(ctx, evergreen_context_reg_list, + Elements(evergreen_context_reg_list)); + if (r) + goto out_err; + r = r600_context_add_block(ctx, evergreen_ctl_const_list, + Elements(evergreen_ctl_const_list)); + if (r) + goto out_err; + + + /* PS SAMPLER */ + for (int j = 0, offset = 0; j < 18; j++, offset += 0xC) { + r = r600_state_sampler_init(ctx, offset); + if (r) + goto out_err; + } + /* VS SAMPLER */ + for (int j = 0, offset = 0xD8; j < 18; j++, offset += 0xC) { + r = r600_state_sampler_init(ctx, offset); + if (r) + goto out_err; + } + /* PS SAMPLER BORDER */ + for (int j = 0; j < 18; j++) { + r = evergreen_state_sampler_border_init(ctx, R_00A400_TD_PS_SAMPLER0_BORDER_INDEX, j); + if (r) + goto out_err; + } + /* VS SAMPLER BORDER */ + for (int j = 0; j < 18; j++) { + r = evergreen_state_sampler_border_init(ctx, R_00A414_TD_VS_SAMPLER0_BORDER_INDEX, j); + if (r) + goto out_err; + } + /* PS RESOURCE */ + for (int j = 0, offset = 0; j < 176; j++, offset += 0x20) { + r = evergreen_state_resource_init(ctx, offset); + if (r) + goto out_err; + } + /* VS RESOURCE */ + for (int j = 0, offset = 0x1600; j < 160; j++, offset += 0x20) { + r = evergreen_state_resource_init(ctx, offset); + if (r) + goto out_err; + } + /* FS RESOURCE */ + for (int j = 0, offset = 0x7C00; j < 16; j++, offset += 0x20) { + r = evergreen_state_resource_init(ctx, offset); + if (r) + goto out_err; + } + + /* PS loop const */ + evergreen_loop_const_init(ctx, 0); + /* VS loop const */ + evergreen_loop_const_init(ctx, 32); + + /* setup block table */ + ctx->blocks = calloc(ctx->nblocks, sizeof(void*)); + for (int i = 0, c = 0; i < 256; i++) { + for (int j = 0; j < (1 << ctx->hash_shift); j++) { + if (ctx->range[i].blocks[j]) { + assert(c < ctx->nblocks); + ctx->blocks[c++] = ctx->range[i].blocks[j]; + j += (ctx->range[i].blocks[j]->nreg << 2) - 1; + } + } + } + + /* allocate cs variables */ + ctx->nreloc = RADEON_CTX_MAX_PM4; + ctx->reloc = calloc(ctx->nreloc, sizeof(struct r600_reloc)); + if (ctx->reloc == NULL) { + r = -ENOMEM; + goto out_err; + } + ctx->bo = calloc(ctx->nreloc, sizeof(void *)); + if (ctx->bo == NULL) { + r = -ENOMEM; + goto out_err; + } + ctx->pm4_ndwords = RADEON_CTX_MAX_PM4; + ctx->pm4 = calloc(ctx->pm4_ndwords, 4); + if (ctx->pm4 == NULL) { + r = -ENOMEM; + goto out_err; + } + /* save 16dwords space for fence mecanism */ + ctx->pm4_ndwords -= 16; + + LIST_INITHEAD(&ctx->fenced_bo); + + /* init dirty list */ + LIST_INITHEAD(&ctx->dirty); + return 0; +out_err: + r600_context_fini(ctx); + return r; +} + +static inline void evergreen_context_pipe_state_set_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned offset) +{ + struct r600_range *range; + struct r600_block *block; + + range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; + block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; + if (state == NULL) { + block->status &= ~(R600_BLOCK_STATUS_ENABLED | R600_BLOCK_STATUS_DIRTY); + r600_bo_reference(ctx->radeon, &block->reloc[1].bo, NULL); + r600_bo_reference(ctx->radeon , &block->reloc[2].bo, NULL); + LIST_DELINIT(&block->list); + return; + } + block->reg[0] = state->regs[0].value; + block->reg[1] = state->regs[1].value; + block->reg[2] = state->regs[2].value; + block->reg[3] = state->regs[3].value; + block->reg[4] = state->regs[4].value; + block->reg[5] = state->regs[5].value; + block->reg[6] = state->regs[6].value; + block->reg[7] = state->regs[7].value; + r600_bo_reference(ctx->radeon, &block->reloc[1].bo, NULL); + r600_bo_reference(ctx->radeon , &block->reloc[2].bo, NULL); + if (state->regs[0].bo) { + /* VERTEX RESOURCE, we preted there is 2 bo to relocate so + * we have single case btw VERTEX & TEXTURE resource + */ + r600_bo_reference(ctx->radeon, &block->reloc[1].bo, state->regs[0].bo); + r600_bo_reference(ctx->radeon, &block->reloc[2].bo, state->regs[0].bo); + } else { + /* TEXTURE RESOURCE */ + r600_bo_reference(ctx->radeon, &block->reloc[1].bo, state->regs[2].bo); + r600_bo_reference(ctx->radeon, &block->reloc[2].bo, state->regs[3].bo); + } + if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { + block->status |= R600_BLOCK_STATUS_ENABLED; + block->status |= R600_BLOCK_STATUS_DIRTY; + ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; + LIST_ADDTAIL(&block->list,&ctx->dirty); + } +} + +void evergreen_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid) +{ + unsigned offset = R_030000_SQ_TEX_RESOURCE_WORD0_0 + 0x20 * rid; + + evergreen_context_pipe_state_set_resource(ctx, state, offset); +} + +void evergreen_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid) +{ + unsigned offset = R_030000_SQ_TEX_RESOURCE_WORD0_0 + 0x1600 + 0x20 * rid; + + evergreen_context_pipe_state_set_resource(ctx, state, offset); +} + +void evergreen_context_pipe_state_set_fs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid) +{ + unsigned offset = R_030000_SQ_TEX_RESOURCE_WORD0_0 + 0x7C00 + 0x20 * rid; + + evergreen_context_pipe_state_set_resource(ctx, state, offset); +} + +static inline void evergreen_context_pipe_state_set_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned offset) +{ + struct r600_range *range; + struct r600_block *block; + + range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; + block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; + if (state == NULL) { + block->status &= ~(R600_BLOCK_STATUS_ENABLED | R600_BLOCK_STATUS_DIRTY); + LIST_DELINIT(&block->list); + return; + } + block->reg[0] = state->regs[0].value; + block->reg[1] = state->regs[1].value; + block->reg[2] = state->regs[2].value; + if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { + block->status |= R600_BLOCK_STATUS_ENABLED; + block->status |= R600_BLOCK_STATUS_DIRTY; + ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; + LIST_ADDTAIL(&block->list,&ctx->dirty); + } +} + +static inline void evergreen_context_pipe_state_set_sampler_border(struct r600_context *ctx, struct r600_pipe_state *state, unsigned offset, unsigned id) +{ + unsigned fake_offset = (offset - R_00A400_TD_PS_SAMPLER0_BORDER_INDEX) * 0x100 + 0x40000 + id * 0x1C; + struct r600_range *range; + struct r600_block *block; + + range = &ctx->range[CTX_RANGE_ID(ctx, fake_offset)]; + block = range->blocks[CTX_BLOCK_ID(ctx, fake_offset)]; + if (state == NULL) { + block->status &= ~(R600_BLOCK_STATUS_ENABLED | R600_BLOCK_STATUS_DIRTY); + LIST_DELINIT(&block->list); + return; + } + if (state->nregs <= 3) { + return; + } + block->reg[0] = id; + block->reg[1] = state->regs[3].value; + block->reg[2] = state->regs[4].value; + block->reg[3] = state->regs[5].value; + block->reg[4] = state->regs[6].value; + if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { + block->status |= R600_BLOCK_STATUS_ENABLED; + block->status |= R600_BLOCK_STATUS_DIRTY; + ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; + LIST_ADDTAIL(&block->list,&ctx->dirty); + } +} + +void evergreen_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id) +{ + unsigned offset; + + offset = 0x0003C000 + id * 0xc; + evergreen_context_pipe_state_set_sampler(ctx, state, offset); + evergreen_context_pipe_state_set_sampler_border(ctx, state, R_00A400_TD_PS_SAMPLER0_BORDER_INDEX, id); +} + +void evergreen_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id) +{ + unsigned offset; + + offset = 0x0003C0D8 + id * 0xc; + evergreen_context_pipe_state_set_sampler(ctx, state, offset); + evergreen_context_pipe_state_set_sampler_border(ctx, state, R_00A414_TD_VS_SAMPLER0_BORDER_INDEX, id); +} + + +void evergreen_context_draw(struct r600_context *ctx, const struct r600_draw *draw) +{ + struct r600_bo *cb[12]; + struct r600_bo *db; + unsigned ndwords = 9, flush; + struct r600_block *dirty_block = NULL; + struct r600_block *next_block; + + if (draw->indices) { + ndwords = 13; + /* make sure there is enough relocation space before scheduling draw */ + if (ctx->creloc >= (ctx->nreloc - 1)) { + r600_context_flush(ctx); + } + } + + /* find number of color buffer */ + db = r600_context_reg_bo(ctx, R_028048_DB_Z_READ_BASE); + cb[0] = r600_context_reg_bo(ctx, R_028C60_CB_COLOR0_BASE); + cb[1] = r600_context_reg_bo(ctx, R_028C9C_CB_COLOR1_BASE); + cb[2] = r600_context_reg_bo(ctx, R_028CD8_CB_COLOR2_BASE); + cb[3] = r600_context_reg_bo(ctx, R_028D14_CB_COLOR3_BASE); + cb[4] = r600_context_reg_bo(ctx, R_028D50_CB_COLOR4_BASE); + cb[5] = r600_context_reg_bo(ctx, R_028D8C_CB_COLOR5_BASE); + cb[6] = r600_context_reg_bo(ctx, R_028DC8_CB_COLOR6_BASE); + cb[7] = r600_context_reg_bo(ctx, R_028E04_CB_COLOR7_BASE); + cb[8] = r600_context_reg_bo(ctx, R_028E40_CB_COLOR8_BASE); + cb[9] = r600_context_reg_bo(ctx, R_028E5C_CB_COLOR9_BASE); + cb[10] = r600_context_reg_bo(ctx, R_028E78_CB_COLOR10_BASE); + cb[11] = r600_context_reg_bo(ctx, R_028E94_CB_COLOR11_BASE); + for (int i = 0; i < 12; i++) { + if (cb[i]) { + ndwords += 7; + } + } + if (db) + ndwords += 7; + + /* queries need some special values */ + if (ctx->num_query_running) { + r600_context_reg(ctx, + R_028004_DB_COUNT_CONTROL, + S_028004_PERFECT_ZPASS_COUNTS(1), + S_028004_PERFECT_ZPASS_COUNTS(1)); + r600_context_reg(ctx, + R_02800C_DB_RENDER_OVERRIDE, + S_02800C_NOOP_CULL_DISABLE(1), + S_02800C_NOOP_CULL_DISABLE(1)); + } + + if ((ctx->pm4_dirty_cdwords + ndwords + ctx->pm4_cdwords) > ctx->pm4_ndwords) { + /* need to flush */ + r600_context_flush(ctx); + } + /* at that point everythings is flushed and ctx->pm4_cdwords = 0 */ + if ((ctx->pm4_dirty_cdwords + ndwords) > ctx->pm4_ndwords) { + R600_ERR("context is too big to be scheduled\n"); + return; + } + + /* enough room to copy packet */ + LIST_FOR_EACH_ENTRY_SAFE(dirty_block, next_block, &ctx->dirty,list) { + r600_context_block_emit_dirty(ctx, dirty_block); + } + + /* draw packet */ + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_INDEX_TYPE, 0); + ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_index_type; + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_NUM_INSTANCES, 0); + ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_num_instances; + if (draw->indices) { + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_DRAW_INDEX, 3); + ctx->pm4[ctx->pm4_cdwords++] = draw->indices_bo_offset + r600_bo_offset(draw->indices); + ctx->pm4[ctx->pm4_cdwords++] = 0; + ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_num_indices; + ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_draw_initiator; + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_NOP, 0); + ctx->pm4[ctx->pm4_cdwords++] = 0; + r600_context_bo_reloc(ctx, &ctx->pm4[ctx->pm4_cdwords - 1], draw->indices); + } else { + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_DRAW_INDEX_AUTO, 1); + ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_num_indices; + ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_draw_initiator; + } + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE, 0); + ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0); + + /* flush color buffer */ + for (int i = 0; i < 12; i++) { + if (cb[i]) { + if (i > 7) { + flush = (S_0085F0_CB8_DEST_BASE_ENA(1) << (i - 8)) | + S_0085F0_CB_ACTION_ENA(1); + } else { + flush = (S_0085F0_CB0_DEST_BASE_ENA(1) << i) | + S_0085F0_CB_ACTION_ENA(1); + } + r600_context_bo_flush(ctx, flush, 0, cb[i]); + } + } + if (db) { + r600_context_bo_flush(ctx, + S_0085F0_DB_ACTION_ENA(1) | + S_0085F0_DB_DEST_BASE_ENA(1), + 0, db); + } + + /* all dirty state have been scheduled in current cs */ + ctx->pm4_dirty_cdwords = 0; +} + +static inline void evergreen_resource_set(struct r600_context *ctx, struct r600_pipe_state *state, unsigned offset) +{ + struct r600_range *range; + struct r600_block *block; + + range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; + block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; + block->reg[0] = state->regs[0].value; + block->reg[1] = state->regs[1].value; + block->reg[2] = state->regs[2].value; + block->reg[3] = state->regs[3].value; + block->reg[4] = state->regs[4].value; + block->reg[5] = state->regs[5].value; + block->reg[6] = state->regs[6].value; + block->reg[7] = state->regs[7].value; + r600_bo_reference(ctx->radeon, &block->reloc[1].bo, NULL); + r600_bo_reference(ctx->radeon , &block->reloc[2].bo, NULL); + if (state->regs[0].bo) { + /* VERTEX RESOURCE, we preted there is 2 bo to relocate so + * we have single case btw VERTEX & TEXTURE resource + */ + r600_bo_reference(ctx->radeon, &block->reloc[1].bo, state->regs[0].bo); + r600_bo_reference(ctx->radeon, &block->reloc[2].bo, state->regs[0].bo); + } else { + /* TEXTURE RESOURCE */ + r600_bo_reference(ctx->radeon, &block->reloc[1].bo, state->regs[2].bo); + r600_bo_reference(ctx->radeon, &block->reloc[2].bo, state->regs[3].bo); + } + if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { + block->status |= R600_BLOCK_STATUS_ENABLED; + block->status |= R600_BLOCK_STATUS_DIRTY; + ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; + LIST_ADDTAIL(&block->list,&ctx->dirty); + } +} + +void evergreen_ps_resource_set(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid) +{ + unsigned offset = R_030000_RESOURCE0_WORD0 + 0x20 * rid; + + evergreen_resource_set(ctx, state, offset); +} + +void evergreen_vs_resource_set(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid) +{ + unsigned offset = R_030000_RESOURCE0_WORD0 + 0x1600 + 0x20 * rid; + + evergreen_resource_set(ctx, state, offset); +} + +void evergreen_fs_resource_set(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid) +{ + unsigned offset = R_030000_RESOURCE0_WORD0 + 0x7C00 + 0x20 * rid; + + evergreen_resource_set(ctx, state, offset); +} diff --git a/src/gallium/winsys/r600/drm/r600.c b/src/gallium/winsys/r600/drm/r600.c new file mode 100644 index 0000000..0fae7b1 --- /dev/null +++ b/src/gallium/winsys/r600/drm/r600.c @@ -0,0 +1,125 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#include "xf86drm.h" +#include "radeon_drm.h" +#include "pipe/p_compiler.h" +#include "util/u_inlines.h" +#include "r600_priv.h" + +enum radeon_family r600_get_family(struct radeon *r600) +{ + return r600->family; +} + +enum chip_class r600_get_family_class(struct radeon *radeon) +{ + return radeon->chip_class; +} + +struct r600_tiling_info *r600_get_tiling_info(struct radeon *radeon) +{ + return &radeon->tiling_info; +} + +static int r600_get_device(struct radeon *r600) +{ + struct drm_radeon_info info; + + r600->device = 0; + info.request = RADEON_INFO_DEVICE_ID; + info.value = (uintptr_t)&r600->device; + return drmCommandWriteRead(r600->fd, DRM_RADEON_INFO, &info, sizeof(struct drm_radeon_info)); +} + +struct radeon *r600_new(int fd, unsigned device) +{ + struct radeon *r600; + int r; + + r600 = calloc(1, sizeof(*r600)); + if (r600 == NULL) { + return NULL; + } + r600->fd = fd; + r600->device = device; + if (fd >= 0) { + r = r600_get_device(r600); + if (r) { + R600_ERR("Failed to get device id\n"); + r600_delete(r600); + return NULL; + } + } + r600->family = radeon_family_from_device(r600->device); + if (r600->family == CHIP_UNKNOWN) { + R600_ERR("Unknown chipset 0x%04X\n", r600->device); + r600_delete(r600); + return NULL; + } + /* setup class */ + switch (r600->family) { + case CHIP_R600: + case CHIP_RV610: + case CHIP_RV630: + case CHIP_RV670: + case CHIP_RV620: + case CHIP_RV635: + case CHIP_RS780: + case CHIP_RS880: + r600->chip_class = R600; + break; + case CHIP_RV770: + case CHIP_RV730: + case CHIP_RV710: + case CHIP_RV740: + r600->chip_class = R700; + break; + case CHIP_CEDAR: + case CHIP_REDWOOD: + case CHIP_JUNIPER: + case CHIP_CYPRESS: + case CHIP_HEMLOCK: + case CHIP_PALM: + case CHIP_BARTS: + case CHIP_TURKS: + case CHIP_CAICOS: + r600->chip_class = EVERGREEN; + break; + default: + R600_ERR("unknown or unsupported chipset 0x%04X\n", r600->device); + break; + } + + return r600; +} + +void r600_delete(struct radeon *r600) +{ + if (r600 == NULL) + return; + drmClose(r600->fd); + free(r600); +} diff --git a/src/gallium/winsys/r600/drm/r600_bo.c b/src/gallium/winsys/r600/drm/r600_bo.c new file mode 100644 index 0000000..6a3737f --- /dev/null +++ b/src/gallium/winsys/r600/drm/r600_bo.c @@ -0,0 +1,193 @@ +/* + * Copyright 2010 Dave Airlie + * + * 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. + * + * Authors: + * Dave Airlie + */ +#include +#include +#include +#include "state_tracker/drm_driver.h" +#include "r600_priv.h" +#include "r600d.h" +#include "drm.h" +#include "radeon_drm.h" + +struct r600_bo *r600_bo(struct radeon *radeon, + unsigned size, unsigned alignment, + unsigned binding, unsigned usage) +{ + struct r600_bo *bo; + struct radeon_bo *rbo; + + if (binding & (PIPE_BIND_CONSTANT_BUFFER | PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER)) { + bo = r600_bomgr_bo_create(radeon->bomgr, size, alignment, *radeon->cfence); + if (bo) { + return bo; + } + } + + rbo = radeon_bo(radeon, 0, size, alignment); + if (rbo == NULL) { + return NULL; + } + + bo = calloc(1, sizeof(struct r600_bo)); + bo->size = size; + bo->alignment = alignment; + bo->bo = rbo; + if (binding & (PIPE_BIND_CONSTANT_BUFFER | PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER)) { + r600_bomgr_bo_init(radeon->bomgr, bo); + } + + /* Staging resources particpate in transfers and blits only + * and are used for uploads and downloads from regular + * resources. We generate them internally for some transfers. + */ + if (usage == PIPE_USAGE_STAGING) + bo->domains = RADEON_GEM_DOMAIN_CPU | RADEON_GEM_DOMAIN_GTT; + else + bo->domains = (RADEON_GEM_DOMAIN_CPU | + RADEON_GEM_DOMAIN_GTT | + RADEON_GEM_DOMAIN_VRAM); + + pipe_reference_init(&bo->reference, 1); + return bo; +} + +struct r600_bo *r600_bo_handle(struct radeon *radeon, + unsigned handle, unsigned *array_mode) +{ + struct r600_bo *bo = calloc(1, sizeof(struct r600_bo)); + struct radeon_bo *rbo; + + rbo = bo->bo = radeon_bo(radeon, handle, 0, 0); + if (rbo == NULL) { + free(bo); + return NULL; + } + bo->size = rbo->size; + bo->domains = (RADEON_GEM_DOMAIN_CPU | + RADEON_GEM_DOMAIN_GTT | + RADEON_GEM_DOMAIN_VRAM); + + pipe_reference_init(&bo->reference, 1); + + radeon_bo_get_tiling_flags(radeon, rbo, &bo->tiling_flags, &bo->kernel_pitch); + if (array_mode) { + if (bo->tiling_flags) { + if (bo->tiling_flags & RADEON_TILING_MICRO) + *array_mode = V_0280A0_ARRAY_1D_TILED_THIN1; + if ((bo->tiling_flags & (RADEON_TILING_MICRO | RADEON_TILING_MACRO)) == + (RADEON_TILING_MICRO | RADEON_TILING_MACRO)) + *array_mode = V_0280A0_ARRAY_2D_TILED_THIN1; + } else { + *array_mode = 0; + } + } + return bo; +} + +void *r600_bo_map(struct radeon *radeon, struct r600_bo *bo, unsigned usage, void *ctx) +{ + struct pipe_context *pctx = ctx; + + if (usage & PB_USAGE_UNSYNCHRONIZED) { + radeon_bo_map(radeon, bo->bo); + return (uint8_t *) bo->bo->data + bo->offset; + } + + if (p_atomic_read(&bo->bo->reference.count) > 1) { + if (usage & PB_USAGE_DONTBLOCK) { + return NULL; + } + if (ctx) { + pctx->flush(pctx, 0, NULL); + } + } + + if (usage & PB_USAGE_DONTBLOCK) { + uint32_t domain; + + if (radeon_bo_busy(radeon, bo->bo, &domain)) + return NULL; + if (radeon_bo_map(radeon, bo->bo)) { + return NULL; + } + goto out; + } + + radeon_bo_map(radeon, bo->bo); + if (radeon_bo_wait(radeon, bo->bo)) { + radeon_bo_unmap(radeon, bo->bo); + return NULL; + } + +out: + return (uint8_t *) bo->bo->data + bo->offset; +} + +void r600_bo_unmap(struct radeon *radeon, struct r600_bo *bo) +{ + radeon_bo_unmap(radeon, bo->bo); +} + +void r600_bo_destroy(struct radeon *radeon, struct r600_bo *bo) +{ + if (bo->manager_id) { + if (!r600_bomgr_bo_destroy(radeon->bomgr, bo)) { + /* destroy is delayed by buffer manager */ + return; + } + } + radeon_bo_reference(radeon, &bo->bo, NULL); + free(bo); +} + +void r600_bo_reference(struct radeon *radeon, struct r600_bo **dst, struct r600_bo *src) +{ + struct r600_bo *old = *dst; + + if (pipe_reference(&(*dst)->reference, &src->reference)) { + r600_bo_destroy(radeon, old); + } + *dst = src; +} + +boolean r600_bo_get_winsys_handle(struct radeon *radeon, struct r600_bo *bo, + unsigned stride, struct winsys_handle *whandle) +{ + whandle->stride = stride; + switch(whandle->type) { + case DRM_API_HANDLE_TYPE_KMS: + whandle->handle = r600_bo_get_handle(bo); + break; + case DRM_API_HANDLE_TYPE_SHARED: + if (radeon_bo_get_name(radeon, bo->bo, &whandle->handle)) + return FALSE; + break; + default: + return FALSE; + } + + return TRUE; +} diff --git a/src/gallium/winsys/r600/drm/r600_bomgr.c b/src/gallium/winsys/r600/drm/r600_bomgr.c new file mode 100644 index 0000000..446ef0f --- /dev/null +++ b/src/gallium/winsys/r600/drm/r600_bomgr.c @@ -0,0 +1,161 @@ +/* + * Copyright 2010 VMWare. + * Copyright 2010 Red Hat 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 + * 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. + * + * Authors: + * Jose Fonseca + * Thomas Hellström + * Jerome Glisse + */ +#include +#include +#include +#include +#include "r600_priv.h" + +static void r600_bomgr_timeout_flush(struct r600_bomgr *mgr) +{ + struct r600_bo *bo, *tmp; + int64_t now; + + now = os_time_get(); + LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &mgr->delayed, list) { + if(!os_time_timeout(bo->start, bo->end, now)) + break; + + mgr->num_delayed--; + bo->manager_id = 0; + LIST_DEL(&bo->list); + r600_bo_destroy(mgr->radeon, bo); + } +} + +static INLINE int r600_bo_is_compat(struct r600_bomgr *mgr, + struct r600_bo *bo, + unsigned size, + unsigned alignment, + unsigned cfence) +{ + if(bo->size < size) { + return 0; + } + + /* be lenient with size */ + if(bo->size >= 2*size) { + return 0; + } + + if(!pb_check_alignment(alignment, bo->alignment)) { + return 0; + } + + if (!fence_is_after(cfence, bo->fence)) { + return 0; + } + + return 1; +} + +struct r600_bo *r600_bomgr_bo_create(struct r600_bomgr *mgr, + unsigned size, + unsigned alignment, + unsigned cfence) +{ + struct r600_bo *bo, *tmp; + int64_t now; + + + pipe_mutex_lock(mgr->mutex); + + now = os_time_get(); + LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &mgr->delayed, list) { + if(r600_bo_is_compat(mgr, bo, size, alignment, cfence)) { + LIST_DEL(&bo->list); + --mgr->num_delayed; + r600_bomgr_timeout_flush(mgr); + pipe_mutex_unlock(mgr->mutex); + LIST_INITHEAD(&bo->list); + pipe_reference_init(&bo->reference, 1); + return bo; + } + + if(os_time_timeout(bo->start, bo->end, now)) { + mgr->num_delayed--; + bo->manager_id = 0; + LIST_DEL(&bo->list); + r600_bo_destroy(mgr->radeon, bo); + } + } + + pipe_mutex_unlock(mgr->mutex); + return NULL; +} + +void r600_bomgr_bo_init(struct r600_bomgr *mgr, struct r600_bo *bo) +{ + LIST_INITHEAD(&bo->list); + bo->manager_id = 1; +} + +bool r600_bomgr_bo_destroy(struct r600_bomgr *mgr, struct r600_bo *bo) +{ + bo->start = os_time_get(); + bo->end = bo->start + mgr->usecs; + pipe_mutex_lock(mgr->mutex); + LIST_ADDTAIL(&bo->list, &mgr->delayed); + ++mgr->num_delayed; + pipe_mutex_unlock(mgr->mutex); + return FALSE; +} + +void r600_bomgr_destroy(struct r600_bomgr *mgr) +{ + struct r600_bo *bo, *tmp; + + pipe_mutex_lock(mgr->mutex); + LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &mgr->delayed, list) { + mgr->num_delayed--; + bo->manager_id = 0; + LIST_DEL(&bo->list); + r600_bo_destroy(mgr->radeon, bo); + } + pipe_mutex_unlock(mgr->mutex); + + FREE(mgr); +} + +struct r600_bomgr *r600_bomgr_create(struct radeon *radeon, unsigned usecs) +{ + struct r600_bomgr *mgr; + + mgr = CALLOC_STRUCT(r600_bomgr); + if (mgr == NULL) + return NULL; + + mgr->radeon = radeon; + mgr->usecs = usecs; + LIST_INITHEAD(&mgr->delayed); + mgr->num_delayed = 0; + pipe_mutex_init(mgr->mutex); + + return mgr; +} diff --git a/src/gallium/winsys/r600/drm/r600_drm.c b/src/gallium/winsys/r600/drm/r600_drm.c new file mode 100644 index 0000000..0c9f6ef --- /dev/null +++ b/src/gallium/winsys/r600/drm/r600_drm.c @@ -0,0 +1,229 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + * Corbin Simpson + * Joakim Sindholt + */ +#include +#include +#include +#include "util/u_inlines.h" +#include "util/u_debug.h" +#include +#include "r600.h" +#include "r600_priv.h" +#include "r600_drm_public.h" +#include "xf86drm.h" +#include "radeon_drm.h" + +#ifndef RADEON_INFO_TILING_CONFIG +#define RADEON_INFO_TILING_CONFIG 0x6 +#endif + +static struct radeon *radeon_new(int fd, unsigned device); + +static int radeon_get_device(struct radeon *radeon) +{ + struct drm_radeon_info info; + int r; + + radeon->device = 0; + info.request = RADEON_INFO_DEVICE_ID; + info.value = (uintptr_t)&radeon->device; + r = drmCommandWriteRead(radeon->fd, DRM_RADEON_INFO, &info, + sizeof(struct drm_radeon_info)); + return r; +} + +static int radeon_drm_get_tiling(struct radeon *radeon) +{ + struct drm_radeon_info info; + int r; + uint32_t tiling_config; + + info.request = RADEON_INFO_TILING_CONFIG; + info.value = (uintptr_t)&tiling_config; + r = drmCommandWriteRead(radeon->fd, DRM_RADEON_INFO, &info, + sizeof(struct drm_radeon_info)); + + if (r) + return 0; + + switch ((tiling_config & 0xe) >> 1) { + case 0: + radeon->tiling_info.num_channels = 1; + break; + case 1: + radeon->tiling_info.num_channels = 2; + break; + case 2: + radeon->tiling_info.num_channels = 4; + break; + case 3: + radeon->tiling_info.num_channels = 8; + break; + default: + return -EINVAL; + } + + switch ((tiling_config & 0x30) >> 4) { + case 0: + radeon->tiling_info.num_banks = 4; + break; + case 1: + radeon->tiling_info.num_banks = 8; + break; + default: + return -EINVAL; + + } + switch ((tiling_config & 0xc0) >> 6) { + case 0: + radeon->tiling_info.group_bytes = 256; + break; + case 1: + radeon->tiling_info.group_bytes = 512; + break; + default: + return -EINVAL; + } + return 0; +} + +static int radeon_init_fence(struct radeon *radeon) +{ + radeon->fence = 1; + radeon->fence_bo = r600_bo(radeon, 4096, 0, 0, 0); + if (radeon->fence_bo == NULL) { + return -ENOMEM; + } + radeon->cfence = r600_bo_map(radeon, radeon->fence_bo, PB_USAGE_UNSYNCHRONIZED, NULL); + *radeon->cfence = 0; + return 0; +} + +static struct radeon *radeon_new(int fd, unsigned device) +{ + struct radeon *radeon; + int r; + + radeon = calloc(1, sizeof(*radeon)); + if (radeon == NULL) { + return NULL; + } + radeon->fd = fd; + radeon->device = device; + radeon->refcount = 1; + if (fd >= 0) { + r = radeon_get_device(radeon); + if (r) { + fprintf(stderr, "Failed to get device id\n"); + return radeon_decref(radeon); + } + } + radeon->family = radeon_family_from_device(radeon->device); + if (radeon->family == CHIP_UNKNOWN) { + fprintf(stderr, "Unknown chipset 0x%04X\n", radeon->device); + return radeon_decref(radeon); + } + /* setup class */ + switch (radeon->family) { + case CHIP_R600: + case CHIP_RV610: + case CHIP_RV630: + case CHIP_RV670: + case CHIP_RV620: + case CHIP_RV635: + case CHIP_RS780: + case CHIP_RS880: + radeon->chip_class = R600; + /* set default group bytes, overridden by tiling info ioctl */ + radeon->tiling_info.group_bytes = 256; + break; + case CHIP_RV770: + case CHIP_RV730: + case CHIP_RV710: + case CHIP_RV740: + radeon->chip_class = R700; + /* set default group bytes, overridden by tiling info ioctl */ + radeon->tiling_info.group_bytes = 256; + break; + case CHIP_CEDAR: + case CHIP_REDWOOD: + case CHIP_JUNIPER: + case CHIP_CYPRESS: + case CHIP_HEMLOCK: + case CHIP_PALM: + case CHIP_BARTS: + case CHIP_TURKS: + case CHIP_CAICOS: + radeon->chip_class = EVERGREEN; + /* set default group bytes, overridden by tiling info ioctl */ + radeon->tiling_info.group_bytes = 512; + break; + default: + fprintf(stderr, "%s unknown or unsupported chipset 0x%04X\n", + __func__, radeon->device); + break; + } + + if (radeon->chip_class == R600 || radeon->chip_class == R700) { + if (radeon_drm_get_tiling(radeon)) + return NULL; + } + radeon->bomgr = r600_bomgr_create(radeon, 1000000); + if (radeon->bomgr == NULL) { + return NULL; + } + r = radeon_init_fence(radeon); + if (r) { + radeon_decref(radeon); + return NULL; + } + return radeon; +} + +struct radeon *r600_drm_winsys_create(int drmfd) +{ + return radeon_new(drmfd, 0); +} + +struct radeon *radeon_decref(struct radeon *radeon) +{ + if (radeon == NULL) + return NULL; + if (--radeon->refcount > 0) { + return NULL; + } + + if (radeon->fence_bo) { + r600_bo_reference(radeon, &radeon->fence_bo, NULL); + } + + if (radeon->bomgr) + r600_bomgr_destroy(radeon->bomgr); + + free(radeon); + return NULL; +} diff --git a/src/gallium/winsys/r600/drm/r600_drm_public.h b/src/gallium/winsys/r600/drm/r600_drm_public.h new file mode 100644 index 0000000..cfce8df --- /dev/null +++ b/src/gallium/winsys/r600/drm/r600_drm_public.h @@ -0,0 +1,33 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#ifndef R600_DRM_PUBLIC_H +#define R600_DRM_PUBLIC_H + +struct radeon; + +struct radeon *r600_drm_winsys_create(int drmFD); + +#endif diff --git a/src/gallium/winsys/r600/drm/r600_hw_context.c b/src/gallium/winsys/r600/drm/r600_hw_context.c new file mode 100644 index 0000000..f10e2fd --- /dev/null +++ b/src/gallium/winsys/r600/drm/r600_hw_context.c @@ -0,0 +1,1386 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "xf86drm.h" +#include "radeon_drm.h" +#include "r600_priv.h" +#include "bof.h" +#include "r600d.h" + +#define GROUP_FORCE_NEW_BLOCK 0 + +static void INLINE r600_context_update_fenced_list(struct r600_context *ctx) +{ + for (int i = 0; i < ctx->creloc; i++) { + if (!LIST_IS_EMPTY(&ctx->bo[i]->fencedlist)) + LIST_DELINIT(&ctx->bo[i]->fencedlist); + LIST_ADDTAIL(&ctx->bo[i]->fencedlist, &ctx->fenced_bo); + ctx->bo[i]->fence = ctx->radeon->fence; + ctx->bo[i]->ctx = ctx; + } +} + +static void INLINE r600_context_fence_wraparound(struct r600_context *ctx, unsigned fence) +{ + struct radeon_bo *bo = NULL; + struct radeon_bo *tmp; + + LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &ctx->fenced_bo, fencedlist) { + if (bo->fence <= *ctx->radeon->cfence) { + LIST_DELINIT(&bo->fencedlist); + bo->fence = 0; + } else { + bo->fence = fence; + } + } +} + +int r600_context_add_block(struct r600_context *ctx, const struct r600_reg *reg, unsigned nreg) +{ + struct r600_block *block; + struct r600_range *range; + int offset; + + for (unsigned i = 0, n = 0; i < nreg; i += n) { + u32 j; + + /* ignore new block balise */ + if (reg[i].offset == GROUP_FORCE_NEW_BLOCK) { + n = 1; + continue; + } + + /* register that need relocation are in their own group */ + /* find number of consecutive registers */ + n = 0; + offset = reg[i].offset; + while (reg[i + n].offset == offset) { + n++; + offset += 4; + if ((n + i) >= nreg) + break; + if (n >= (R600_BLOCK_MAX_REG - 2)) + break; + } + + /* allocate new block */ + block = calloc(1, sizeof(struct r600_block)); + if (block == NULL) { + return -ENOMEM; + } + ctx->nblocks++; + for (int j = 0; j < n; j++) { + range = &ctx->range[CTX_RANGE_ID(ctx, reg[i + j].offset)]; + range->blocks[CTX_BLOCK_ID(ctx, reg[i + j].offset)] = block; + } + + /* initialize block */ + block->start_offset = reg[i].offset; + block->pm4[block->pm4_ndwords++] = PKT3(reg[i].opcode, n); + block->pm4[block->pm4_ndwords++] = (block->start_offset - reg[i].offset_base) >> 2; + block->reg = &block->pm4[block->pm4_ndwords]; + block->pm4_ndwords += n; + block->nreg = n; + LIST_INITHEAD(&block->list); + + for (j = 0; j < n; j++) { + if (reg[i+j].need_bo) { + block->nbo++; + assert(block->nbo < R600_BLOCK_MAX_BO); + block->pm4_bo_index[j] = block->nbo; + block->pm4[block->pm4_ndwords++] = PKT3(PKT3_NOP, 0); + block->pm4[block->pm4_ndwords++] = 0x00000000; + block->reloc[block->nbo].flush_flags = reg[i+j].flush_flags; + block->reloc[block->nbo].flush_mask = reg[i+j].flush_mask; + block->reloc[block->nbo].bo_pm4_index = block->pm4_ndwords - 1; + } + } + for (j = 0; j < n; j++) { + if (reg[i+j].flush_flags) { + block->pm4_flush_ndwords += 7; + } + } + /* check that we stay in limit */ + assert(block->pm4_ndwords < R600_BLOCK_MAX_REG); + } + return 0; +} + +/* R600/R700 configuration */ +static const struct r600_reg r600_config_reg_list[] = { + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_008958_VGT_PRIMITIVE_TYPE, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_008C00_SQ_CONFIG, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_008C04_SQ_GPR_RESOURCE_MGMT_1, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_008C08_SQ_GPR_RESOURCE_MGMT_2, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_008C0C_SQ_THREAD_RESOURCE_MGMT, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_008C10_SQ_STACK_RESOURCE_MGMT_1, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_008C14_SQ_STACK_RESOURCE_MGMT_2, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_008D8C_SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_009508_TA_CNTL_AUX, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_009714_VC_ENHANCE, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_009830_DB_DEBUG, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_009838_DB_WATERMARKS, 0, 0, 0}, +}; + +static const struct r600_reg r600_ctl_const_list[] = { + {PKT3_SET_CTL_CONST, R600_CTL_CONST_OFFSET, R_03CFF0_SQ_VTX_BASE_VTX_LOC, 0, 0, 0}, + {PKT3_SET_CTL_CONST, R600_CTL_CONST_OFFSET, R_03CFF4_SQ_VTX_START_INST_LOC, 0, 0, 0}, +}; + +static const struct r600_reg r600_context_reg_list[] = { + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028350_SX_MISC, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286C8_SPI_THREAD_GROUPING, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288A8_SQ_ESGS_RING_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288AC_SQ_GSVS_RING_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288B0_SQ_ESTMP_RING_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288B4_SQ_GSTMP_RING_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288B8_SQ_VSTMP_RING_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288BC_SQ_PSTMP_RING_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288C0_SQ_FBUF_RING_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288C4_SQ_REDUC_RING_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288C8_SQ_GS_VERT_ITEMSIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A10_VGT_OUTPUT_PATH_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A14_VGT_HOS_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A18_VGT_HOS_MAX_TESS_LEVEL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A1C_VGT_HOS_MIN_TESS_LEVEL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A20_VGT_HOS_REUSE_DEPTH, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A24_VGT_GROUP_PRIM_TYPE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A28_VGT_GROUP_FIRST_DECR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A2C_VGT_GROUP_DECR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A30_VGT_GROUP_VECT_0_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A34_VGT_GROUP_VECT_1_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A38_VGT_GROUP_VECT_0_FMT_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A3C_VGT_GROUP_VECT_1_FMT_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A40_VGT_GS_MODE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A4C_PA_SC_MODE_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028AB0_VGT_STRMOUT_EN, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028AB4_VGT_REUSE_OFF, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028AB8_VGT_VTX_CNT_EN, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028B20_VGT_STRMOUT_BUFFER_EN, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028028_DB_STENCIL_CLEAR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02802C_DB_DEPTH_CLEAR, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028040_CB_COLOR0_BASE, 1, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280A0_CB_COLOR0_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028060_CB_COLOR0_SIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028080_CB_COLOR0_VIEW, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280E0_CB_COLOR0_FRAG, 1, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280C0_CB_COLOR0_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028100_CB_COLOR0_MASK, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028044_CB_COLOR1_BASE, 1, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280A4_CB_COLOR1_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028064_CB_COLOR1_SIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028084_CB_COLOR1_VIEW, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280E4_CB_COLOR1_FRAG, 1, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280C4_CB_COLOR1_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028104_CB_COLOR1_MASK, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028048_CB_COLOR2_BASE, 1, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280A8_CB_COLOR2_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028068_CB_COLOR2_SIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028088_CB_COLOR2_VIEW, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280E8_CB_COLOR2_FRAG, 1, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280C8_CB_COLOR2_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028108_CB_COLOR2_MASK, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02804C_CB_COLOR3_BASE, 1, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280AC_CB_COLOR3_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02806C_CB_COLOR3_SIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02808C_CB_COLOR3_VIEW, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280EC_CB_COLOR3_FRAG, 1, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280CC_CB_COLOR3_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02810C_CB_COLOR3_MASK, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028050_CB_COLOR4_BASE, 1, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280B0_CB_COLOR4_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028070_CB_COLOR4_SIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028090_CB_COLOR4_VIEW, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280F0_CB_COLOR4_FRAG, 1, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280D0_CB_COLOR4_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028110_CB_COLOR4_MASK, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028054_CB_COLOR5_BASE, 1, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280B4_CB_COLOR5_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028074_CB_COLOR5_SIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028094_CB_COLOR5_VIEW, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280F4_CB_COLOR5_FRAG, 1, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280D4_CB_COLOR5_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028114_CB_COLOR5_MASK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028058_CB_COLOR6_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280B8_CB_COLOR6_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028078_CB_COLOR6_SIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028098_CB_COLOR6_VIEW, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280F8_CB_COLOR6_FRAG, 1, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280D8_CB_COLOR6_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028118_CB_COLOR6_MASK, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02805C_CB_COLOR7_BASE, 1, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280BC_CB_COLOR7_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02807C_CB_COLOR7_SIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02809C_CB_COLOR7_VIEW, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280FC_CB_COLOR7_FRAG, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280DC_CB_COLOR7_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02811C_CB_COLOR7_MASK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028120_CB_CLEAR_RED, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028124_CB_CLEAR_GREEN, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028128_CB_CLEAR_BLUE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02812C_CB_CLEAR_ALPHA, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028140_ALU_CONST_BUFFER_SIZE_PS_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028180_ALU_CONST_BUFFER_SIZE_VS_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028940_ALU_CONST_CACHE_PS_0, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028980_ALU_CONST_CACHE_VS_0, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02823C_CB_SHADER_MASK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028238_CB_TARGET_MASK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028410_SX_ALPHA_TEST_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028414_CB_BLEND_RED, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028418_CB_BLEND_GREEN, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02841C_CB_BLEND_BLUE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028420_CB_BLEND_ALPHA, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028424_CB_FOG_RED, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028428_CB_FOG_GREEN, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02842C_CB_FOG_BLUE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028430_DB_STENCILREFMASK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028434_DB_STENCILREFMASK_BF, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028438_SX_ALPHA_REF, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286DC_SPI_FOG_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286E0_SPI_FOG_FUNC_SCALE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286E4_SPI_FOG_FUNC_BIAS, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028780_CB_BLEND0_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028784_CB_BLEND1_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028788_CB_BLEND2_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02878C_CB_BLEND3_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028790_CB_BLEND4_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028794_CB_BLEND5_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028798_CB_BLEND6_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02879C_CB_BLEND7_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0287A0_CB_SHADER_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028800_DB_DEPTH_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028804_CB_BLEND_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028808_CB_COLOR_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02880C_DB_SHADER_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C04_PA_SC_AA_CONFIG, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C1C_PA_SC_AA_SAMPLE_LOCS_MCTX, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C20_PA_SC_AA_SAMPLE_LOCS_8S_WD1_MCTX, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C30_CB_CLRCMP_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C34_CB_CLRCMP_SRC, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C38_CB_CLRCMP_DST, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C3C_CB_CLRCMP_MSK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C48_PA_SC_AA_MASK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028D2C_DB_SRESULTS_COMPARE_STATE1, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028D44_DB_ALPHA_TO_MASK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02800C_DB_DEPTH_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028000_DB_DEPTH_SIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028004_DB_DEPTH_VIEW, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028010_DB_DEPTH_INFO, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028D0C_DB_RENDER_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028D10_DB_RENDER_OVERRIDE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028D24_DB_HTILE_SURFACE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028D30_DB_PRELOAD_CONTROL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028D34_DB_PREFETCH_LIMIT, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028030_PA_SC_SCREEN_SCISSOR_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028034_PA_SC_SCREEN_SCISSOR_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028200_PA_SC_WINDOW_OFFSET, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028204_PA_SC_WINDOW_SCISSOR_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028208_PA_SC_WINDOW_SCISSOR_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02820C_PA_SC_CLIPRECT_RULE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028210_PA_SC_CLIPRECT_0_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028214_PA_SC_CLIPRECT_0_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028218_PA_SC_CLIPRECT_1_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02821C_PA_SC_CLIPRECT_1_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028220_PA_SC_CLIPRECT_2_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028224_PA_SC_CLIPRECT_2_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028228_PA_SC_CLIPRECT_3_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02822C_PA_SC_CLIPRECT_3_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028230_PA_SC_EDGERULE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028240_PA_SC_GENERIC_SCISSOR_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028244_PA_SC_GENERIC_SCISSOR_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028250_PA_SC_VPORT_SCISSOR_0_TL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028254_PA_SC_VPORT_SCISSOR_0_BR, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0282D0_PA_SC_VPORT_ZMIN_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0282D4_PA_SC_VPORT_ZMAX_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02843C_PA_CL_VPORT_XSCALE_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028440_PA_CL_VPORT_XOFFSET_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028444_PA_CL_VPORT_YSCALE_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028448_PA_CL_VPORT_YOFFSET_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02844C_PA_CL_VPORT_ZSCALE_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028450_PA_CL_VPORT_ZOFFSET_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286D4_SPI_INTERP_CONTROL_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028810_PA_CL_CLIP_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028814_PA_SU_SC_MODE_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028818_PA_CL_VTE_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02881C_PA_CL_VS_OUT_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028820_PA_CL_NANINF_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A00_PA_SU_POINT_SIZE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A04_PA_SU_POINT_MINMAX, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A08_PA_SU_LINE_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A0C_PA_SC_LINE_STIPPLE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A48_PA_SC_MPASS_PS_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C00_PA_SC_LINE_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C08_PA_SU_VTX_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C0C_PA_CL_GB_VERT_CLIP_ADJ, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C10_PA_CL_GB_VERT_DISC_ADJ, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C14_PA_CL_GB_HORZ_CLIP_ADJ, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C18_PA_CL_GB_HORZ_DISC_ADJ, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028DF8_PA_SU_POLY_OFFSET_DB_FMT_CNTL, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028DFC_PA_SU_POLY_OFFSET_CLAMP, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E00_PA_SU_POLY_OFFSET_FRONT_SCALE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E04_PA_SU_POLY_OFFSET_FRONT_OFFSET, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E08_PA_SU_POLY_OFFSET_BACK_SCALE, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E0C_PA_SU_POLY_OFFSET_BACK_OFFSET, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E20_PA_CL_UCP0_X, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E24_PA_CL_UCP0_Y, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E28_PA_CL_UCP0_Z, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E2C_PA_CL_UCP0_W, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E30_PA_CL_UCP1_X, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E34_PA_CL_UCP1_Y, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E38_PA_CL_UCP1_Z, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E3C_PA_CL_UCP1_W, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E40_PA_CL_UCP2_X, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E44_PA_CL_UCP2_Y, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E48_PA_CL_UCP2_Z, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E4C_PA_CL_UCP2_W, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E50_PA_CL_UCP3_X, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E54_PA_CL_UCP3_Y, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E58_PA_CL_UCP3_Z, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E5C_PA_CL_UCP3_W, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E60_PA_CL_UCP4_X, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E64_PA_CL_UCP4_Y, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E68_PA_CL_UCP4_Z, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E6C_PA_CL_UCP4_W, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E70_PA_CL_UCP5_X, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E74_PA_CL_UCP5_Y, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E78_PA_CL_UCP5_Z, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028E7C_PA_CL_UCP5_W, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028380_SQ_VTX_SEMANTIC_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028384_SQ_VTX_SEMANTIC_1, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028388_SQ_VTX_SEMANTIC_2, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02838C_SQ_VTX_SEMANTIC_3, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028390_SQ_VTX_SEMANTIC_4, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028394_SQ_VTX_SEMANTIC_5, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028398_SQ_VTX_SEMANTIC_6, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02839C_SQ_VTX_SEMANTIC_7, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283A0_SQ_VTX_SEMANTIC_8, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283A4_SQ_VTX_SEMANTIC_9, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283A8_SQ_VTX_SEMANTIC_10, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283AC_SQ_VTX_SEMANTIC_11, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283B0_SQ_VTX_SEMANTIC_12, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283B4_SQ_VTX_SEMANTIC_13, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283B8_SQ_VTX_SEMANTIC_14, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283BC_SQ_VTX_SEMANTIC_15, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283C0_SQ_VTX_SEMANTIC_16, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283C4_SQ_VTX_SEMANTIC_17, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283C8_SQ_VTX_SEMANTIC_18, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283CC_SQ_VTX_SEMANTIC_19, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283D0_SQ_VTX_SEMANTIC_20, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283D4_SQ_VTX_SEMANTIC_21, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283D8_SQ_VTX_SEMANTIC_22, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283DC_SQ_VTX_SEMANTIC_23, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283E0_SQ_VTX_SEMANTIC_24, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283E4_SQ_VTX_SEMANTIC_25, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283E8_SQ_VTX_SEMANTIC_26, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283EC_SQ_VTX_SEMANTIC_27, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283F0_SQ_VTX_SEMANTIC_28, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283F4_SQ_VTX_SEMANTIC_29, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283F8_SQ_VTX_SEMANTIC_30, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0283FC_SQ_VTX_SEMANTIC_31, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028614_SPI_VS_OUT_ID_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028618_SPI_VS_OUT_ID_1, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02861C_SPI_VS_OUT_ID_2, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028620_SPI_VS_OUT_ID_3, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028624_SPI_VS_OUT_ID_4, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028628_SPI_VS_OUT_ID_5, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02862C_SPI_VS_OUT_ID_6, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028630_SPI_VS_OUT_ID_7, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028634_SPI_VS_OUT_ID_8, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028638_SPI_VS_OUT_ID_9, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286C4_SPI_VS_OUT_CONFIG, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028858_SQ_PGM_START_VS, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028868_SQ_PGM_RESOURCES_VS, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028894_SQ_PGM_START_FS, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288A4_SQ_PGM_RESOURCES_FS, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288D0_SQ_PGM_CF_OFFSET_VS, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288DC_SQ_PGM_CF_OFFSET_FS, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028644_SPI_PS_INPUT_CNTL_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028648_SPI_PS_INPUT_CNTL_1, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02864C_SPI_PS_INPUT_CNTL_2, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028650_SPI_PS_INPUT_CNTL_3, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028654_SPI_PS_INPUT_CNTL_4, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028658_SPI_PS_INPUT_CNTL_5, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02865C_SPI_PS_INPUT_CNTL_6, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028660_SPI_PS_INPUT_CNTL_7, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028664_SPI_PS_INPUT_CNTL_8, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028668_SPI_PS_INPUT_CNTL_9, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02866C_SPI_PS_INPUT_CNTL_10, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028670_SPI_PS_INPUT_CNTL_11, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028674_SPI_PS_INPUT_CNTL_12, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028678_SPI_PS_INPUT_CNTL_13, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02867C_SPI_PS_INPUT_CNTL_14, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028680_SPI_PS_INPUT_CNTL_15, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028684_SPI_PS_INPUT_CNTL_16, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028688_SPI_PS_INPUT_CNTL_17, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02868C_SPI_PS_INPUT_CNTL_18, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028690_SPI_PS_INPUT_CNTL_19, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028694_SPI_PS_INPUT_CNTL_20, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028698_SPI_PS_INPUT_CNTL_21, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02869C_SPI_PS_INPUT_CNTL_22, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286A0_SPI_PS_INPUT_CNTL_23, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286A4_SPI_PS_INPUT_CNTL_24, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286A8_SPI_PS_INPUT_CNTL_25, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286AC_SPI_PS_INPUT_CNTL_26, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286B0_SPI_PS_INPUT_CNTL_27, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286B4_SPI_PS_INPUT_CNTL_28, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286B8_SPI_PS_INPUT_CNTL_29, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286BC_SPI_PS_INPUT_CNTL_30, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286C0_SPI_PS_INPUT_CNTL_31, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286CC_SPI_PS_IN_CONTROL_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286D0_SPI_PS_IN_CONTROL_1, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286D8_SPI_INPUT_Z, 0, 0, 0}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028840_SQ_PGM_START_PS, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028850_SQ_PGM_RESOURCES_PS, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028854_SQ_PGM_EXPORTS_PS, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288CC_SQ_PGM_CF_OFFSET_PS, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028400_VGT_MAX_VTX_INDX, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028404_VGT_MIN_VTX_INDX, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028408_VGT_INDX_OFFSET, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02840C_VGT_MULTI_PRIM_IB_RESET_INDX, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A84_VGT_PRIMITIVEID_EN, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028A94_VGT_MULTI_PRIM_IB_RESET_EN, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028AA0_VGT_INSTANCE_STEP_RATE_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028AA4_VGT_INSTANCE_STEP_RATE_1, 0, 0, 0}, +}; + +/* SHADER RESOURCE R600/R700 */ +static int r600_state_resource_init(struct r600_context *ctx, u32 offset) +{ + struct r600_reg r600_shader_resource[] = { + {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_038000_RESOURCE0_WORD0, 0, 0, 0}, + {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_038004_RESOURCE0_WORD1, 0, 0, 0}, + {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_038008_RESOURCE0_WORD2, 1, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_VC_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_03800C_RESOURCE0_WORD3, 1, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_VC_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_038010_RESOURCE0_WORD4, 0, 0, 0}, + {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_038014_RESOURCE0_WORD5, 0, 0, 0}, + {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_038018_RESOURCE0_WORD6, 0, 0, 0}, + }; + unsigned nreg = Elements(r600_shader_resource); + + for (int i = 0; i < nreg; i++) { + r600_shader_resource[i].offset += offset; + } + return r600_context_add_block(ctx, r600_shader_resource, nreg); +} + +/* SHADER SAMPLER R600/R700 */ +static int r600_state_sampler_init(struct r600_context *ctx, u32 offset) +{ + struct r600_reg r600_shader_sampler[] = { + {PKT3_SET_SAMPLER, R600_SAMPLER_OFFSET, R_03C000_SQ_TEX_SAMPLER_WORD0_0, 0, 0, 0}, + {PKT3_SET_SAMPLER, R600_SAMPLER_OFFSET, R_03C004_SQ_TEX_SAMPLER_WORD1_0, 0, 0, 0}, + {PKT3_SET_SAMPLER, R600_SAMPLER_OFFSET, R_03C008_SQ_TEX_SAMPLER_WORD2_0, 0, 0, 0}, + }; + unsigned nreg = Elements(r600_shader_sampler); + + for (int i = 0; i < nreg; i++) { + r600_shader_sampler[i].offset += offset; + } + return r600_context_add_block(ctx, r600_shader_sampler, nreg); +} + +/* SHADER SAMPLER BORDER R600/R700 */ +static int r600_state_sampler_border_init(struct r600_context *ctx, u32 offset) +{ + struct r600_reg r600_shader_sampler_border[] = { + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_00A400_TD_PS_SAMPLER0_BORDER_RED, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_00A404_TD_PS_SAMPLER0_BORDER_GREEN, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_00A408_TD_PS_SAMPLER0_BORDER_BLUE, 0, 0, 0}, + {PKT3_SET_CONFIG_REG, R600_CONFIG_REG_OFFSET, R_00A40C_TD_PS_SAMPLER0_BORDER_ALPHA, 0, 0, 0}, + }; + unsigned nreg = Elements(r600_shader_sampler_border); + + for (int i = 0; i < nreg; i++) { + r600_shader_sampler_border[i].offset += offset; + } + return r600_context_add_block(ctx, r600_shader_sampler_border, nreg); +} + +static int r600_loop_const_init(struct r600_context *ctx, u32 offset) +{ + unsigned nreg = 32; + struct r600_reg r600_loop_consts[32]; + int i; + + for (i = 0; i < nreg; i++) { + r600_loop_consts[i].opcode = PKT3_SET_LOOP_CONST; + r600_loop_consts[i].offset_base = R600_LOOP_CONST_OFFSET; + r600_loop_consts[i].offset = R600_LOOP_CONST_OFFSET + ((offset + i) * 4); + r600_loop_consts[i].need_bo = 0; + r600_loop_consts[i].flush_flags = 0; + r600_loop_consts[i].flush_mask = 0; + } + return r600_context_add_block(ctx, r600_loop_consts, nreg); +} + +static void r600_context_clear_fenced_bo(struct r600_context *ctx) +{ + struct radeon_bo *bo, *tmp; + + LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &ctx->fenced_bo, fencedlist) { + LIST_DELINIT(&bo->fencedlist); + bo->fence = 0; + bo->ctx = NULL; + } +} + +/* initialize */ +void r600_context_fini(struct r600_context *ctx) +{ + struct r600_block *block; + struct r600_range *range; + + for (int i = 0; i < 256; i++) { + for (int j = 0; j < (1 << ctx->hash_shift); j++) { + block = ctx->range[i].blocks[j]; + if (block) { + for (int k = 0, offset = block->start_offset; k < block->nreg; k++, offset += 4) { + range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; + range->blocks[CTX_BLOCK_ID(ctx, offset)] = NULL; + } + for (int k = 1; k <= block->nbo; k++) { + r600_bo_reference(ctx->radeon, &block->reloc[k].bo, NULL); + } + free(block); + } + } + free(ctx->range[i].blocks); + } + free(ctx->blocks); + free(ctx->reloc); + free(ctx->bo); + free(ctx->pm4); + + r600_context_clear_fenced_bo(ctx); + memset(ctx, 0, sizeof(struct r600_context)); +} + +int r600_context_init(struct r600_context *ctx, struct radeon *radeon) +{ + int r; + + memset(ctx, 0, sizeof(struct r600_context)); + ctx->radeon = radeon; + LIST_INITHEAD(&ctx->query_list); + + /* initialize hash */ + ctx->hash_size = 19; + ctx->hash_shift = 11; + for (int i = 0; i < 256; i++) { + ctx->range[i].start_offset = i << ctx->hash_shift; + ctx->range[i].end_offset = ((i + 1) << ctx->hash_shift) - 1; + ctx->range[i].blocks = calloc(1 << ctx->hash_shift, sizeof(void*)); + if (ctx->range[i].blocks == NULL) { + return -ENOMEM; + } + } + + /* add blocks */ + r = r600_context_add_block(ctx, r600_config_reg_list, + Elements(r600_config_reg_list)); + if (r) + goto out_err; + r = r600_context_add_block(ctx, r600_context_reg_list, + Elements(r600_context_reg_list)); + if (r) + goto out_err; + r = r600_context_add_block(ctx, r600_ctl_const_list, + Elements(r600_ctl_const_list)); + if (r) + goto out_err; + + /* PS SAMPLER BORDER */ + for (int j = 0, offset = 0; j < 18; j++, offset += 0x10) { + r = r600_state_sampler_border_init(ctx, offset); + if (r) + goto out_err; + } + + /* VS SAMPLER BORDER */ + for (int j = 0, offset = 0x200; j < 18; j++, offset += 0x10) { + r = r600_state_sampler_border_init(ctx, offset); + if (r) + goto out_err; + } + /* PS SAMPLER */ + for (int j = 0, offset = 0; j < 18; j++, offset += 0xC) { + r = r600_state_sampler_init(ctx, offset); + if (r) + goto out_err; + } + /* VS SAMPLER */ + for (int j = 0, offset = 0xD8; j < 18; j++, offset += 0xC) { + r = r600_state_sampler_init(ctx, offset); + if (r) + goto out_err; + } + /* PS RESOURCE */ + for (int j = 0, offset = 0; j < 160; j++, offset += 0x1C) { + r = r600_state_resource_init(ctx, offset); + if (r) + goto out_err; + } + /* VS RESOURCE */ + for (int j = 0, offset = 0x1180; j < 160; j++, offset += 0x1C) { + r = r600_state_resource_init(ctx, offset); + if (r) + goto out_err; + } + /* FS RESOURCE */ + for (int j = 0, offset = 0x2300; j < 16; j++, offset += 0x1C) { + r = r600_state_resource_init(ctx, offset); + if (r) + goto out_err; + } + + /* PS loop const */ + r600_loop_const_init(ctx, 0); + /* VS loop const */ + r600_loop_const_init(ctx, 32); + + /* setup block table */ + ctx->blocks = calloc(ctx->nblocks, sizeof(void*)); + for (int i = 0, c = 0; i < 256; i++) { + for (int j = 0, add; j < (1 << ctx->hash_shift); j++) { + if (ctx->range[i].blocks[j]) { + add = 1; + for (int k = 0; k < c; k++) { + if (ctx->blocks[k] == ctx->range[i].blocks[j]) { + add = 0; + break; + } + } + if (add) { + assert(c < ctx->nblocks); + ctx->blocks[c++] = ctx->range[i].blocks[j]; + j += (ctx->range[i].blocks[j]->nreg << 2) - 1; + } + } + } + } + + /* allocate cs variables */ + ctx->nreloc = RADEON_CTX_MAX_PM4; + ctx->reloc = calloc(ctx->nreloc, sizeof(struct r600_reloc)); + if (ctx->reloc == NULL) { + r = -ENOMEM; + goto out_err; + } + ctx->bo = calloc(ctx->nreloc, sizeof(void *)); + if (ctx->bo == NULL) { + r = -ENOMEM; + goto out_err; + } + ctx->pm4_ndwords = RADEON_CTX_MAX_PM4; + ctx->pm4 = calloc(ctx->pm4_ndwords, 4); + if (ctx->pm4 == NULL) { + r = -ENOMEM; + goto out_err; + } + /* save 16dwords space for fence mecanism */ + ctx->pm4_ndwords -= 16; + + LIST_INITHEAD(&ctx->fenced_bo); + + /* init dirty list */ + LIST_INITHEAD(&ctx->dirty); + return 0; +out_err: + r600_context_fini(ctx); + return r; +} + +void r600_context_bo_flush(struct r600_context *ctx, unsigned flush_flags, + unsigned flush_mask, struct r600_bo *rbo) +{ + struct radeon_bo *bo; + + bo = r600_bo_get_bo(rbo); + /* if bo has already been flush */ + if (!(bo->last_flush ^ flush_flags)) { + bo->last_flush &= flush_mask; + return; + } + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_SURFACE_SYNC, 3); + ctx->pm4[ctx->pm4_cdwords++] = flush_flags; + ctx->pm4[ctx->pm4_cdwords++] = (bo->size + 255) >> 8; + ctx->pm4[ctx->pm4_cdwords++] = 0x00000000; + ctx->pm4[ctx->pm4_cdwords++] = 0x0000000A; + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_NOP, 0); + ctx->pm4[ctx->pm4_cdwords++] = bo->reloc_id; + bo->last_flush = (bo->last_flush | flush_flags) & flush_mask; +} + +void r600_context_bo_reloc(struct r600_context *ctx, u32 *pm4, struct r600_bo *rbo) +{ + struct radeon_bo *bo; + + bo = r600_bo_get_bo(rbo); + assert(bo != NULL); + if (bo->reloc) { + *pm4 = bo->reloc_id; + return; + } + bo->reloc = &ctx->reloc[ctx->creloc]; + bo->reloc_id = ctx->creloc * sizeof(struct r600_reloc) / 4; + ctx->reloc[ctx->creloc].handle = bo->handle; + ctx->reloc[ctx->creloc].read_domain = rbo->domains & (RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM); + ctx->reloc[ctx->creloc].write_domain = rbo->domains & (RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM); + ctx->reloc[ctx->creloc].flags = 0; + radeon_bo_reference(ctx->radeon, &ctx->bo[ctx->creloc], bo); + rbo->fence = ctx->radeon->fence; + ctx->creloc++; + /* set PKT3 to point to proper reloc */ + *pm4 = bo->reloc_id; +} + +void r600_context_pipe_state_set(struct r600_context *ctx, struct r600_pipe_state *state) +{ + struct r600_range *range; + struct r600_block *block; + + for (int i = 0; i < state->nregs; i++) { + unsigned id; + + range = &ctx->range[CTX_RANGE_ID(ctx, state->regs[i].offset)]; + block = range->blocks[CTX_BLOCK_ID(ctx, state->regs[i].offset)]; + id = (state->regs[i].offset - block->start_offset) >> 2; + block->reg[id] &= ~state->regs[i].mask; + block->reg[id] |= state->regs[i].value; + if (block->pm4_bo_index[id]) { + /* find relocation */ + id = block->pm4_bo_index[id]; + r600_bo_reference(ctx->radeon, &block->reloc[id].bo, state->regs[i].bo); + state->regs[i].bo->fence = ctx->radeon->fence; + } + if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { + block->status |= R600_BLOCK_STATUS_ENABLED; + block->status |= R600_BLOCK_STATUS_DIRTY; + ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; + LIST_ADDTAIL(&block->list,&ctx->dirty); + } + } +} + +static inline void r600_context_pipe_state_set_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned offset) +{ + struct r600_range *range; + struct r600_block *block; + + range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; + block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; + if (state == NULL) { + block->status &= ~(R600_BLOCK_STATUS_ENABLED | R600_BLOCK_STATUS_DIRTY); + r600_bo_reference(ctx->radeon, &block->reloc[1].bo, NULL); + r600_bo_reference(ctx->radeon , &block->reloc[2].bo, NULL); + LIST_DELINIT(&block->list); + return; + } + block->reg[0] = state->regs[0].value; + block->reg[1] = state->regs[1].value; + block->reg[2] = state->regs[2].value; + block->reg[3] = state->regs[3].value; + block->reg[4] = state->regs[4].value; + block->reg[5] = state->regs[5].value; + block->reg[6] = state->regs[6].value; + r600_bo_reference(ctx->radeon, &block->reloc[1].bo, NULL); + r600_bo_reference(ctx->radeon , &block->reloc[2].bo, NULL); + if (state->regs[0].bo) { + /* VERTEX RESOURCE, we preted there is 2 bo to relocate so + * we have single case btw VERTEX & TEXTURE resource + */ + r600_bo_reference(ctx->radeon, &block->reloc[1].bo, state->regs[0].bo); + r600_bo_reference(ctx->radeon, &block->reloc[2].bo, state->regs[0].bo); + state->regs[0].bo->fence = ctx->radeon->fence; + } else { + /* TEXTURE RESOURCE */ + r600_bo_reference(ctx->radeon, &block->reloc[1].bo, state->regs[2].bo); + r600_bo_reference(ctx->radeon, &block->reloc[2].bo, state->regs[3].bo); + state->regs[2].bo->fence = ctx->radeon->fence; + state->regs[3].bo->fence = ctx->radeon->fence; + } + if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { + block->status |= R600_BLOCK_STATUS_ENABLED; + block->status |= R600_BLOCK_STATUS_DIRTY; + ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; + LIST_ADDTAIL(&block->list,&ctx->dirty); + } +} + +void r600_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid) +{ + unsigned offset = R_038000_SQ_TEX_RESOURCE_WORD0_0 + 0x1C * rid; + + r600_context_pipe_state_set_resource(ctx, state, offset); +} + +void r600_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid) +{ + unsigned offset = R_038000_SQ_TEX_RESOURCE_WORD0_0 + 0x1180 + 0x1C * rid; + + r600_context_pipe_state_set_resource(ctx, state, offset); +} + +void r600_context_pipe_state_set_fs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid) +{ + unsigned offset = R_038000_SQ_TEX_RESOURCE_WORD0_0 + 0x2300 + 0x1C * rid; + + r600_context_pipe_state_set_resource(ctx, state, offset); +} + +static inline void r600_context_pipe_state_set_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned offset) +{ + struct r600_range *range; + struct r600_block *block; + + range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; + block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; + if (state == NULL) { + block->status &= ~(R600_BLOCK_STATUS_ENABLED | R600_BLOCK_STATUS_DIRTY); + LIST_DELINIT(&block->list); + return; + } + block->reg[0] = state->regs[0].value; + block->reg[1] = state->regs[1].value; + block->reg[2] = state->regs[2].value; + if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { + block->status |= R600_BLOCK_STATUS_ENABLED; + block->status |= R600_BLOCK_STATUS_DIRTY; + ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; + LIST_ADDTAIL(&block->list,&ctx->dirty); + } +} + +static inline void r600_context_pipe_state_set_sampler_border(struct r600_context *ctx, struct r600_pipe_state *state, unsigned offset) +{ + struct r600_range *range; + struct r600_block *block; + + range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; + block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; + if (state == NULL) { + block->status &= ~(R600_BLOCK_STATUS_ENABLED | R600_BLOCK_STATUS_DIRTY); + LIST_DELINIT(&block->list); + return; + } + if (state->nregs <= 3) { + return; + } + block->reg[0] = state->regs[3].value; + block->reg[1] = state->regs[4].value; + block->reg[2] = state->regs[5].value; + block->reg[3] = state->regs[6].value; + if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { + block->status |= R600_BLOCK_STATUS_ENABLED; + block->status |= R600_BLOCK_STATUS_DIRTY; + ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; + LIST_ADDTAIL(&block->list,&ctx->dirty); + } +} + +void r600_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id) +{ + unsigned offset; + + offset = 0x0003C000 + id * 0xc; + r600_context_pipe_state_set_sampler(ctx, state, offset); + offset = 0x0000A400 + id * 0x10; + r600_context_pipe_state_set_sampler_border(ctx, state, offset); +} + +void r600_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id) +{ + unsigned offset; + + offset = 0x0003C0D8 + id * 0xc; + r600_context_pipe_state_set_sampler(ctx, state, offset); + offset = 0x0000A600 + id * 0x10; + r600_context_pipe_state_set_sampler_border(ctx, state, offset); +} + +struct r600_bo *r600_context_reg_bo(struct r600_context *ctx, unsigned offset) +{ + struct r600_range *range; + struct r600_block *block; + unsigned id; + + range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; + block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; + offset -= block->start_offset; + id = block->pm4_bo_index[offset >> 2]; + if (block->reloc[id].bo) { + return block->reloc[id].bo; + } + return NULL; +} + +void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw) +{ + struct r600_bo *cb[8]; + struct r600_bo *db; + unsigned ndwords = 9; + struct r600_block *dirty_block = NULL; + struct r600_block *next_block; + + if (draw->indices) { + ndwords = 13; + /* make sure there is enough relocation space before scheduling draw */ + if (ctx->creloc >= (ctx->nreloc - 1)) { + r600_context_flush(ctx); + } + } + + /* find number of color buffer */ + db = r600_context_reg_bo(ctx, R_02800C_DB_DEPTH_BASE); + cb[0] = r600_context_reg_bo(ctx, R_028040_CB_COLOR0_BASE); + cb[1] = r600_context_reg_bo(ctx, R_028044_CB_COLOR1_BASE); + cb[2] = r600_context_reg_bo(ctx, R_028048_CB_COLOR2_BASE); + cb[3] = r600_context_reg_bo(ctx, R_02804C_CB_COLOR3_BASE); + cb[4] = r600_context_reg_bo(ctx, R_028050_CB_COLOR4_BASE); + cb[5] = r600_context_reg_bo(ctx, R_028054_CB_COLOR5_BASE); + cb[6] = r600_context_reg_bo(ctx, R_028058_CB_COLOR6_BASE); + cb[7] = r600_context_reg_bo(ctx, R_02805C_CB_COLOR7_BASE); + for (int i = 0; i < 8; i++) { + if (cb[i]) { + ndwords += 7; + } + } + if (db) + ndwords += 7; + + /* queries need some special values */ + if (ctx->num_query_running) { + if (ctx->radeon->family >= CHIP_RV770) { + r600_context_reg(ctx, + R_028D0C_DB_RENDER_CONTROL, + S_028D0C_R700_PERFECT_ZPASS_COUNTS(1), + S_028D0C_R700_PERFECT_ZPASS_COUNTS(1)); + } + r600_context_reg(ctx, + R_028D10_DB_RENDER_OVERRIDE, + S_028D10_NOOP_CULL_DISABLE(1), + S_028D10_NOOP_CULL_DISABLE(1)); + } + + if ((ctx->pm4_dirty_cdwords + ndwords + ctx->pm4_cdwords) > ctx->pm4_ndwords) { + /* need to flush */ + r600_context_flush(ctx); + } + /* at that point everythings is flushed and ctx->pm4_cdwords = 0 */ + if ((ctx->pm4_dirty_cdwords + ndwords) > ctx->pm4_ndwords) { + R600_ERR("context is too big to be scheduled\n"); + return; + } + + /* enough room to copy packet */ + LIST_FOR_EACH_ENTRY_SAFE(dirty_block, next_block, &ctx->dirty,list) { + r600_context_block_emit_dirty(ctx, dirty_block); + } + + /* draw packet */ + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_INDEX_TYPE, 0); + ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_index_type; + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_NUM_INSTANCES, 0); + ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_num_instances; + if (draw->indices) { + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_DRAW_INDEX, 3); + ctx->pm4[ctx->pm4_cdwords++] = draw->indices_bo_offset + r600_bo_offset(draw->indices); + ctx->pm4[ctx->pm4_cdwords++] = 0; + ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_num_indices; + ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_draw_initiator; + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_NOP, 0); + ctx->pm4[ctx->pm4_cdwords++] = 0; + r600_context_bo_reloc(ctx, &ctx->pm4[ctx->pm4_cdwords - 1], draw->indices); + } else { + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_DRAW_INDEX_AUTO, 1); + ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_num_indices; + ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_draw_initiator; + } + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE, 0); + ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0); + + /* flush color buffer */ + for (int i = 0; i < 8; i++) { + if (cb[i]) { + r600_context_bo_flush(ctx, + (S_0085F0_CB0_DEST_BASE_ENA(1) << i) | + S_0085F0_CB_ACTION_ENA(1), + 0, cb[i]); + } + } + if (db) { + r600_context_bo_flush(ctx, S_0085F0_DB_ACTION_ENA(1), 0, db); + } + + /* all dirty state have been scheduled in current cs */ + ctx->pm4_dirty_cdwords = 0; +} + +void r600_context_flush(struct r600_context *ctx) +{ + struct drm_radeon_cs drmib; + struct drm_radeon_cs_chunk chunks[2]; + uint64_t chunk_array[2]; + unsigned fence; + int r; + + if (!ctx->pm4_cdwords) + return; + + /* suspend queries */ + r600_context_queries_suspend(ctx); + + /* emit fence */ + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE, 0); + ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_PS_PARTIAL_FLUSH) | EVENT_INDEX(4); + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE_EOP, 4); + ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH_AND_INV_TS_EVENT) | EVENT_INDEX(5); + ctx->pm4[ctx->pm4_cdwords++] = 0; + ctx->pm4[ctx->pm4_cdwords++] = (1 << 29) | (0 << 24); + ctx->pm4[ctx->pm4_cdwords++] = ctx->radeon->fence; + ctx->pm4[ctx->pm4_cdwords++] = 0; + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_NOP, 0); + ctx->pm4[ctx->pm4_cdwords++] = 0; + r600_context_bo_reloc(ctx, &ctx->pm4[ctx->pm4_cdwords - 1], ctx->radeon->fence_bo); + +#if 1 + /* emit cs */ + drmib.num_chunks = 2; + drmib.chunks = (uint64_t)(uintptr_t)chunk_array; + chunks[0].chunk_id = RADEON_CHUNK_ID_IB; + chunks[0].length_dw = ctx->pm4_cdwords; + chunks[0].chunk_data = (uint64_t)(uintptr_t)ctx->pm4; + chunks[1].chunk_id = RADEON_CHUNK_ID_RELOCS; + chunks[1].length_dw = ctx->creloc * sizeof(struct r600_reloc) / 4; + chunks[1].chunk_data = (uint64_t)(uintptr_t)ctx->reloc; + chunk_array[0] = (uint64_t)(uintptr_t)&chunks[0]; + chunk_array[1] = (uint64_t)(uintptr_t)&chunks[1]; + r = drmCommandWriteRead(ctx->radeon->fd, DRM_RADEON_CS, &drmib, + sizeof(struct drm_radeon_cs)); +#else + *ctx->radeon->cfence = ctx->radeon->fence; +#endif + + r600_context_update_fenced_list(ctx); + + fence = ctx->radeon->fence + 1; + if (fence < ctx->radeon->fence) { + /* wrap around */ + fence = 1; + r600_context_fence_wraparound(ctx, fence); + } + ctx->radeon->fence = fence; + + /* restart */ + for (int i = 0; i < ctx->creloc; i++) { + ctx->bo[i]->reloc = NULL; + ctx->bo[i]->last_flush = 0; + radeon_bo_reference(ctx->radeon, &ctx->bo[i], NULL); + } + ctx->creloc = 0; + ctx->pm4_dirty_cdwords = 0; + ctx->pm4_cdwords = 0; + + /* resume queries */ + r600_context_queries_resume(ctx); + + /* set all valid group as dirty so they get reemited on + * next draw command + */ + for (int i = 0; i < ctx->nblocks; i++) { + if (ctx->blocks[i]->status & R600_BLOCK_STATUS_ENABLED) { + if(!(ctx->blocks[i]->status & R600_BLOCK_STATUS_DIRTY)) { + LIST_ADDTAIL(&ctx->blocks[i]->list,&ctx->dirty); + } + ctx->pm4_dirty_cdwords += ctx->blocks[i]->pm4_ndwords + ctx->blocks[i]->pm4_flush_ndwords; + ctx->blocks[i]->status |= R600_BLOCK_STATUS_DIRTY; + } + } +} + +void r600_context_dump_bof(struct r600_context *ctx, const char *file) +{ + bof_t *bcs, *blob, *array, *bo, *size, *handle, *device_id, *root; + unsigned i; + + root = device_id = bcs = blob = array = bo = size = handle = NULL; + root = bof_object(); + if (root == NULL) + goto out_err; + device_id = bof_int32(ctx->radeon->device); + if (device_id == NULL) + goto out_err; + if (bof_object_set(root, "device_id", device_id)) + goto out_err; + bof_decref(device_id); + device_id = NULL; + /* dump relocs */ + blob = bof_blob(ctx->creloc * 16, ctx->reloc); + if (blob == NULL) + goto out_err; + if (bof_object_set(root, "reloc", blob)) + goto out_err; + bof_decref(blob); + blob = NULL; + /* dump cs */ + blob = bof_blob(ctx->pm4_cdwords * 4, ctx->pm4); + if (blob == NULL) + goto out_err; + if (bof_object_set(root, "pm4", blob)) + goto out_err; + bof_decref(blob); + blob = NULL; + /* dump bo */ + array = bof_array(); + if (array == NULL) + goto out_err; + for (i = 0; i < ctx->creloc; i++) { + struct radeon_bo *rbo = ctx->bo[i]; + bo = bof_object(); + if (bo == NULL) + goto out_err; + size = bof_int32(rbo->size); + if (size == NULL) + goto out_err; + if (bof_object_set(bo, "size", size)) + goto out_err; + bof_decref(size); + size = NULL; + handle = bof_int32(rbo->handle); + if (handle == NULL) + goto out_err; + if (bof_object_set(bo, "handle", handle)) + goto out_err; + bof_decref(handle); + handle = NULL; + radeon_bo_map(ctx->radeon, rbo); + blob = bof_blob(rbo->size, rbo->data); + radeon_bo_unmap(ctx->radeon, rbo); + if (blob == NULL) + goto out_err; + if (bof_object_set(bo, "data", blob)) + goto out_err; + bof_decref(blob); + blob = NULL; + if (bof_array_append(array, bo)) + goto out_err; + bof_decref(bo); + bo = NULL; + } + if (bof_object_set(root, "bo", array)) + goto out_err; + bof_dump_file(root, file); +out_err: + bof_decref(blob); + bof_decref(array); + bof_decref(bo); + bof_decref(size); + bof_decref(handle); + bof_decref(device_id); + bof_decref(root); +} + +static void r600_query_result(struct r600_context *ctx, struct r600_query *query) +{ + u64 start, end; + u32 *results; + int i; + + results = r600_bo_map(ctx->radeon, query->buffer, 0, NULL); + for (i = 0; i < query->num_results; i += 4) { + start = (u64)results[i] | (u64)results[i + 1] << 32; + end = (u64)results[i + 2] | (u64)results[i + 3] << 32; + if ((start & 0x8000000000000000UL) && (end & 0x8000000000000000UL)) { + query->result += end - start; + } + } + r600_bo_unmap(ctx->radeon, query->buffer); + query->num_results = 0; +} + +void r600_query_begin(struct r600_context *ctx, struct r600_query *query) +{ + /* query request needs 6 dwords for begin + 6 dwords for end */ + if ((12 + ctx->pm4_cdwords) > ctx->pm4_ndwords) { + /* need to flush */ + r600_context_flush(ctx); + } + + /* if query buffer is full force a flush */ + if (query->num_results >= ((query->buffer_size >> 2) - 2)) { + r600_context_flush(ctx); + r600_query_result(ctx, query); + } + + /* emit begin query */ + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE, 2); + ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_ZPASS_DONE) | EVENT_INDEX(1); + ctx->pm4[ctx->pm4_cdwords++] = query->num_results + r600_bo_offset(query->buffer); + ctx->pm4[ctx->pm4_cdwords++] = 0; + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_NOP, 0); + ctx->pm4[ctx->pm4_cdwords++] = 0; + r600_context_bo_reloc(ctx, &ctx->pm4[ctx->pm4_cdwords - 1], query->buffer); + + query->state |= R600_QUERY_STATE_STARTED; + query->state ^= R600_QUERY_STATE_ENDED; + ctx->num_query_running++; +} + +void r600_query_end(struct r600_context *ctx, struct r600_query *query) +{ + /* emit begin query */ + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE, 2); + ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_ZPASS_DONE) | EVENT_INDEX(1); + ctx->pm4[ctx->pm4_cdwords++] = query->num_results + 8 + r600_bo_offset(query->buffer); + ctx->pm4[ctx->pm4_cdwords++] = 0; + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_NOP, 0); + ctx->pm4[ctx->pm4_cdwords++] = 0; + r600_context_bo_reloc(ctx, &ctx->pm4[ctx->pm4_cdwords - 1], query->buffer); + + query->num_results += 16; + query->state ^= R600_QUERY_STATE_STARTED; + query->state |= R600_QUERY_STATE_ENDED; + ctx->num_query_running--; +} + +struct r600_query *r600_context_query_create(struct r600_context *ctx, unsigned query_type) +{ + struct r600_query *query; + + if (query_type != PIPE_QUERY_OCCLUSION_COUNTER) + return NULL; + + query = calloc(1, sizeof(struct r600_query)); + if (query == NULL) + return NULL; + + query->type = query_type; + query->buffer_size = 4096; + + /* As of GL4, query buffers are normally read by the CPU after + * being written by the gpu, hence staging is probably a good + * usage pattern. + */ + query->buffer = r600_bo(ctx->radeon, query->buffer_size, 1, 0, + PIPE_USAGE_STAGING); + if (!query->buffer) { + free(query); + return NULL; + } + + LIST_ADDTAIL(&query->list, &ctx->query_list); + + return query; +} + +void r600_context_query_destroy(struct r600_context *ctx, struct r600_query *query) +{ + r600_bo_reference(ctx->radeon, &query->buffer, NULL); + LIST_DELINIT(&query->list); + free(query); +} + +boolean r600_context_query_result(struct r600_context *ctx, + struct r600_query *query, + boolean wait, void *vresult) +{ + uint64_t *result = (uint64_t*)vresult; + + if (query->num_results) { + r600_context_flush(ctx); + } + r600_query_result(ctx, query); + *result = query->result; + query->result = 0; + return TRUE; +} + +void r600_context_queries_suspend(struct r600_context *ctx) +{ + struct r600_query *query; + + LIST_FOR_EACH_ENTRY(query, &ctx->query_list, list) { + if (query->state & R600_QUERY_STATE_STARTED) { + r600_query_end(ctx, query); + query->state |= R600_QUERY_STATE_SUSPENDED; + } + } +} + +void r600_context_queries_resume(struct r600_context *ctx) +{ + struct r600_query *query; + + LIST_FOR_EACH_ENTRY(query, &ctx->query_list, list) { + if (query->state & R600_QUERY_STATE_SUSPENDED) { + r600_query_begin(ctx, query); + query->state ^= R600_QUERY_STATE_SUSPENDED; + } + } +} diff --git a/src/gallium/winsys/r600/drm/r600_priv.h b/src/gallium/winsys/r600/drm/r600_priv.h new file mode 100644 index 0000000..a38a648 --- /dev/null +++ b/src/gallium/winsys/r600/drm/r600_priv.h @@ -0,0 +1,257 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#ifndef R600_PRIV_H +#define R600_PRIV_H + +#include +#include +#include +#include +#include +#include +#include +#include "r600.h" + +struct r600_bomgr; +struct r600_bo; + +struct radeon { + int fd; + int refcount; + unsigned device; + unsigned family; + enum chip_class chip_class; + struct r600_tiling_info tiling_info; + struct r600_bomgr *bomgr; + unsigned fence; + unsigned *cfence; + struct r600_bo *fence_bo; +}; + +struct r600_reg { + unsigned opcode; + unsigned offset_base; + unsigned offset; + unsigned need_bo; + unsigned flush_flags; + unsigned flush_mask; +}; + +struct radeon_bo { + struct pipe_reference reference; + unsigned handle; + unsigned size; + unsigned alignment; + int map_count; + void *data; + struct list_head fencedlist; + unsigned fence; + struct r600_context *ctx; + boolean shared; + struct r600_reloc *reloc; + unsigned reloc_id; + unsigned last_flush; +}; + +struct r600_bo { + struct pipe_reference reference; + unsigned size; + unsigned tiling_flags; + unsigned kernel_pitch; + unsigned domains; + struct radeon_bo *bo; + unsigned fence; + /* manager data */ + struct list_head list; + unsigned manager_id; + unsigned alignment; + unsigned offset; + int64_t start; + int64_t end; +}; + +struct r600_bomgr { + struct radeon *radeon; + unsigned usecs; + pipe_mutex mutex; + struct list_head delayed; + unsigned num_delayed; +}; + +/* + * r600_drm.c + */ +struct radeon *r600_new(int fd, unsigned device); +void r600_delete(struct radeon *r600); + +/* + * radeon_pciid.c + */ +unsigned radeon_family_from_device(unsigned device); + +/* + * radeon_bo.c + */ +struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle, + unsigned size, unsigned alignment); +void radeon_bo_reference(struct radeon *radeon, struct radeon_bo **dst, + struct radeon_bo *src); +int radeon_bo_wait(struct radeon *radeon, struct radeon_bo *bo); +int radeon_bo_busy(struct radeon *radeon, struct radeon_bo *bo, uint32_t *domain); +int radeon_bo_fencelist(struct radeon *radeon, struct radeon_bo **bolist, uint32_t num_bo); +int radeon_bo_get_tiling_flags(struct radeon *radeon, + struct radeon_bo *bo, + uint32_t *tiling_flags, + uint32_t *pitch); +int radeon_bo_get_name(struct radeon *radeon, + struct radeon_bo *bo, + uint32_t *name); + +/* + * r600_hw_context.c + */ +int r600_context_init_fence(struct r600_context *ctx); +void r600_context_bo_reloc(struct r600_context *ctx, u32 *pm4, struct r600_bo *rbo); +void r600_context_bo_flush(struct r600_context *ctx, unsigned flush_flags, + unsigned flush_mask, struct r600_bo *rbo); +struct r600_bo *r600_context_reg_bo(struct r600_context *ctx, unsigned offset); +int r600_context_add_block(struct r600_context *ctx, const struct r600_reg *reg, unsigned nreg); + +/* + * r600_bo.c + */ +void r600_bo_destroy(struct radeon *radeon, struct r600_bo *bo); + +/* + * r600_bomgr.c + */ +struct r600_bomgr *r600_bomgr_create(struct radeon *radeon, unsigned usecs); +void r600_bomgr_destroy(struct r600_bomgr *mgr); +bool r600_bomgr_bo_destroy(struct r600_bomgr *mgr, struct r600_bo *bo); +void r600_bomgr_bo_init(struct r600_bomgr *mgr, struct r600_bo *bo); +struct r600_bo *r600_bomgr_bo_create(struct r600_bomgr *mgr, + unsigned size, + unsigned alignment, + unsigned cfence); + + +/* + * helpers + */ +#define CTX_RANGE_ID(ctx, offset) (((offset) >> (ctx)->hash_shift) & 255) +#define CTX_BLOCK_ID(ctx, offset) ((offset) & ((1 << (ctx)->hash_shift) - 1)) + +static void inline r600_context_reg(struct r600_context *ctx, + unsigned offset, unsigned value, + unsigned mask) +{ + struct r600_range *range; + struct r600_block *block; + unsigned id; + + range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; + block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; + id = (offset - block->start_offset) >> 2; + block->reg[id] &= ~mask; + block->reg[id] |= value; + if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { + ctx->pm4_dirty_cdwords += block->pm4_ndwords; + block->status |= R600_BLOCK_STATUS_ENABLED; + block->status |= R600_BLOCK_STATUS_DIRTY; + LIST_ADDTAIL(&block->list,&ctx->dirty); + } +} + +static inline void r600_context_block_emit_dirty(struct r600_context *ctx, struct r600_block *block) +{ + int id; + + for (int j = 0; j < block->nreg; j++) { + if (block->pm4_bo_index[j]) { + /* find relocation */ + id = block->pm4_bo_index[j]; + r600_context_bo_reloc(ctx, + &block->pm4[block->reloc[id].bo_pm4_index], + block->reloc[id].bo); + r600_context_bo_flush(ctx, + block->reloc[id].flush_flags, + block->reloc[id].flush_mask, + block->reloc[id].bo); + } + } + memcpy(&ctx->pm4[ctx->pm4_cdwords], block->pm4, block->pm4_ndwords * 4); + ctx->pm4_cdwords += block->pm4_ndwords; + block->status ^= R600_BLOCK_STATUS_DIRTY; + LIST_DELINIT(&block->list); +} + +/* + * radeon_bo.c + */ +static inline int radeon_bo_map(struct radeon *radeon, struct radeon_bo *bo) +{ + bo->map_count++; + return 0; +} + +static inline void radeon_bo_unmap(struct radeon *radeon, struct radeon_bo *bo) +{ + bo->map_count--; + assert(bo->map_count >= 0); +} + +/* + * r600_bo + */ +static inline struct radeon_bo *r600_bo_get_bo(struct r600_bo *bo) +{ + return bo->bo; +} + +static unsigned inline r600_bo_get_handle(struct r600_bo *bo) +{ + return bo->bo->handle; +} + +static unsigned inline r600_bo_get_size(struct r600_bo *bo) +{ + return bo->size; +} + +/* + * fence + */ +static inline bool fence_is_after(unsigned fence, unsigned ofence) +{ + /* handle wrap around */ + if (fence < 0x80000000 && ofence > 0x80000000) + return TRUE; + if (fence > ofence) + return TRUE; + return FALSE; +} + +#endif diff --git a/src/gallium/winsys/r600/drm/r600d.h b/src/gallium/winsys/r600/drm/r600d.h new file mode 100644 index 0000000..1c1ac76 --- /dev/null +++ b/src/gallium/winsys/r600/drm/r600d.h @@ -0,0 +1,2223 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#ifndef R600D_H +#define R600D_H + +/* evergreen values */ +#define EG_RESOURCE_OFFSET 0x00030000 +#define EG_RESOURCE_END 0x00034000 +#define EG_LOOP_CONST_OFFSET 0x0003A200 +#define EG_LOOP_CONST_END 0x0003A26C +#define EG_BOOL_CONST_OFFSET 0x0003A500 +#define EG_BOOL_CONST_END 0x0003A506 + + +#define R600_CONFIG_REG_OFFSET 0X00008000 +#define R600_CONFIG_REG_END 0X0000AC00 +#define R600_CONTEXT_REG_OFFSET 0X00028000 +#define R600_CONTEXT_REG_END 0X00029000 +#define R600_ALU_CONST_OFFSET 0X00030000 +#define R600_ALU_CONST_END 0X00032000 +#define R600_RESOURCE_OFFSET 0X00038000 +#define R600_RESOURCE_END 0X0003C000 +#define R600_SAMPLER_OFFSET 0X0003C000 +#define R600_SAMPLER_END 0X0003CFF0 +#define R600_CTL_CONST_OFFSET 0X0003CFF0 +#define R600_CTL_CONST_END 0X0003E200 +#define R600_LOOP_CONST_OFFSET 0X0003E200 +#define R600_LOOP_CONST_END 0X0003E380 +#define R600_BOOL_CONST_OFFSET 0X0003E380 +#define R600_BOOL_CONST_END 0X00040000 + +#define PKT3_NOP 0x10 +#define PKT3_INDIRECT_BUFFER_END 0x17 +#define PKT3_SET_PREDICATION 0x20 +#define PKT3_REG_RMW 0x21 +#define PKT3_COND_EXEC 0x22 +#define PKT3_PRED_EXEC 0x23 +#define PKT3_START_3D_CMDBUF 0x24 +#define PKT3_DRAW_INDEX_2 0x27 +#define PKT3_CONTEXT_CONTROL 0x28 +#define PKT3_DRAW_INDEX_IMMD_BE 0x29 +#define PKT3_INDEX_TYPE 0x2A +#define PKT3_DRAW_INDEX 0x2B +#define PKT3_DRAW_INDEX_AUTO 0x2D +#define PKT3_DRAW_INDEX_IMMD 0x2E +#define PKT3_NUM_INSTANCES 0x2F +#define PKT3_STRMOUT_BUFFER_UPDATE 0x34 +#define PKT3_INDIRECT_BUFFER_MP 0x38 +#define PKT3_MEM_SEMAPHORE 0x39 +#define PKT3_MPEG_INDEX 0x3A +#define PKT3_WAIT_REG_MEM 0x3C +#define PKT3_MEM_WRITE 0x3D +#define PKT3_INDIRECT_BUFFER 0x32 +#define PKT3_CP_INTERRUPT 0x40 +#define PKT3_SURFACE_SYNC 0x43 +#define PKT3_ME_INITIALIZE 0x44 +#define PKT3_COND_WRITE 0x45 +#define PKT3_EVENT_WRITE 0x46 +#define PKT3_EVENT_WRITE_EOP 0x47 +#define PKT3_ONE_REG_WRITE 0x57 +#define PKT3_SET_CONFIG_REG 0x68 +#define PKT3_SET_CONTEXT_REG 0x69 +#define PKT3_SET_ALU_CONST 0x6A +#define PKT3_SET_BOOL_CONST 0x6B +#define PKT3_SET_LOOP_CONST 0x6C +#define PKT3_SET_RESOURCE 0x6D +#define PKT3_SET_SAMPLER 0x6E +#define PKT3_SET_CTL_CONST 0x6F +#define PKT3_SURFACE_BASE_UPDATE 0x73 + +#define EVENT_TYPE_PS_PARTIAL_FLUSH 0x10 +#define EVENT_TYPE_CACHE_FLUSH_AND_INV_TS_EVENT 0x14 +#define EVENT_TYPE_ZPASS_DONE 0x15 +#define EVENT_TYPE_CACHE_FLUSH_AND_INV_EVENT 0x16 +#define EVENT_TYPE(x) ((x) << 0) +#define EVENT_INDEX(x) ((x) << 8) + /* 0 - any non-TS event + * 1 - ZPASS_DONE + * 2 - SAMPLE_PIPELINESTAT + * 3 - SAMPLE_STREAMOUTSTAT* + * 4 - *S_PARTIAL_FLUSH + * 5 - TS events + */ + +#define PKT_TYPE_S(x) (((x) & 0x3) << 30) +#define PKT_TYPE_G(x) (((x) >> 30) & 0x3) +#define PKT_TYPE_C 0x3FFFFFFF +#define PKT_COUNT_S(x) (((x) & 0x3FFF) << 16) +#define PKT_COUNT_G(x) (((x) >> 16) & 0x3FFF) +#define PKT_COUNT_C 0xC000FFFF +#define PKT0_BASE_INDEX_S(x) (((x) & 0xFFFF) << 0) +#define PKT0_BASE_INDEX_G(x) (((x) >> 0) & 0xFFFF) +#define PKT0_BASE_INDEX_C 0xFFFF0000 +#define PKT3_IT_OPCODE_S(x) (((x) & 0xFF) << 8) +#define PKT3_IT_OPCODE_G(x) (((x) >> 8) & 0xFF) +#define PKT3_IT_OPCODE_C 0xFFFF00FF +#define PKT0(index, count) (PKT_TYPE_S(0) | PKT0_BASE_INDEX_S(index) | PKT_COUNT_S(count)) +#define PKT3(op, count) (PKT_TYPE_S(3) | PKT3_IT_OPCODE_S(op) | PKT_COUNT_S(count)) + +/* Registers */ +#define R_0280A0_CB_COLOR0_INFO 0x0280A0 +#define S_0280A0_ENDIAN(x) (((x) & 0x3) << 0) +#define G_0280A0_ENDIAN(x) (((x) >> 0) & 0x3) +#define C_0280A0_ENDIAN 0xFFFFFFFC +#define S_0280A0_FORMAT(x) (((x) & 0x3F) << 2) +#define G_0280A0_FORMAT(x) (((x) >> 2) & 0x3F) +#define C_0280A0_FORMAT 0xFFFFFF03 +#define V_0280A0_COLOR_INVALID 0x00000000 +#define V_0280A0_COLOR_8 0x00000001 +#define V_0280A0_COLOR_4_4 0x00000002 +#define V_0280A0_COLOR_3_3_2 0x00000003 +#define V_0280A0_COLOR_16 0x00000005 +#define V_0280A0_COLOR_16_FLOAT 0x00000006 +#define V_0280A0_COLOR_8_8 0x00000007 +#define V_0280A0_COLOR_5_6_5 0x00000008 +#define V_0280A0_COLOR_6_5_5 0x00000009 +#define V_0280A0_COLOR_1_5_5_5 0x0000000A +#define V_0280A0_COLOR_4_4_4_4 0x0000000B +#define V_0280A0_COLOR_5_5_5_1 0x0000000C +#define V_0280A0_COLOR_32 0x0000000D +#define V_0280A0_COLOR_32_FLOAT 0x0000000E +#define V_0280A0_COLOR_16_16 0x0000000F +#define V_0280A0_COLOR_16_16_FLOAT 0x00000010 +#define V_0280A0_COLOR_8_24 0x00000011 +#define V_0280A0_COLOR_8_24_FLOAT 0x00000012 +#define V_0280A0_COLOR_24_8 0x00000013 +#define V_0280A0_COLOR_24_8_FLOAT 0x00000014 +#define V_0280A0_COLOR_10_11_11 0x00000015 +#define V_0280A0_COLOR_10_11_11_FLOAT 0x00000016 +#define V_0280A0_COLOR_11_11_10 0x00000017 +#define V_0280A0_COLOR_11_11_10_FLOAT 0x00000018 +#define V_0280A0_COLOR_2_10_10_10 0x00000019 +#define V_0280A0_COLOR_8_8_8_8 0x0000001A +#define V_0280A0_COLOR_10_10_10_2 0x0000001B +#define V_0280A0_COLOR_X24_8_32_FLOAT 0x0000001C +#define V_0280A0_COLOR_32_32 0x0000001D +#define V_0280A0_COLOR_32_32_FLOAT 0x0000001E +#define V_0280A0_COLOR_16_16_16_16 0x0000001F +#define V_0280A0_COLOR_16_16_16_16_FLOAT 0x00000020 +#define V_0280A0_COLOR_32_32_32_32 0x00000022 +#define V_0280A0_COLOR_32_32_32_32_FLOAT 0x00000023 +#define S_0280A0_ARRAY_MODE(x) (((x) & 0xF) << 8) +#define G_0280A0_ARRAY_MODE(x) (((x) >> 8) & 0xF) +#define C_0280A0_ARRAY_MODE 0xFFFFF0FF +#define V_0280A0_ARRAY_LINEAR_GENERAL 0x00000000 +#define V_0280A0_ARRAY_LINEAR_ALIGNED 0x00000001 +#define V_0280A0_ARRAY_1D_TILED_THIN1 0x00000002 +#define V_0280A0_ARRAY_2D_TILED_THIN1 0x00000004 +#define S_0280A0_NUMBER_TYPE(x) (((x) & 0x7) << 12) +#define G_0280A0_NUMBER_TYPE(x) (((x) >> 12) & 0x7) +#define C_0280A0_NUMBER_TYPE 0xFFFF8FFF +#define S_0280A0_READ_SIZE(x) (((x) & 0x1) << 15) +#define G_0280A0_READ_SIZE(x) (((x) >> 15) & 0x1) +#define C_0280A0_READ_SIZE 0xFFFF7FFF +#define S_0280A0_COMP_SWAP(x) (((x) & 0x3) << 16) +#define G_0280A0_COMP_SWAP(x) (((x) >> 16) & 0x3) +#define C_0280A0_COMP_SWAP 0xFFFCFFFF +#define S_0280A0_TILE_MODE(x) (((x) & 0x3) << 18) +#define G_0280A0_TILE_MODE(x) (((x) >> 18) & 0x3) +#define C_0280A0_TILE_MODE 0xFFF3FFFF +#define S_0280A0_BLEND_CLAMP(x) (((x) & 0x1) << 20) +#define G_0280A0_BLEND_CLAMP(x) (((x) >> 20) & 0x1) +#define C_0280A0_BLEND_CLAMP 0xFFEFFFFF +#define S_0280A0_CLEAR_COLOR(x) (((x) & 0x1) << 21) +#define G_0280A0_CLEAR_COLOR(x) (((x) >> 21) & 0x1) +#define C_0280A0_CLEAR_COLOR 0xFFDFFFFF +#define S_0280A0_BLEND_BYPASS(x) (((x) & 0x1) << 22) +#define G_0280A0_BLEND_BYPASS(x) (((x) >> 22) & 0x1) +#define C_0280A0_BLEND_BYPASS 0xFFBFFFFF +#define S_0280A0_BLEND_FLOAT32(x) (((x) & 0x1) << 23) +#define G_0280A0_BLEND_FLOAT32(x) (((x) >> 23) & 0x1) +#define C_0280A0_BLEND_FLOAT32 0xFF7FFFFF +#define S_0280A0_SIMPLE_FLOAT(x) (((x) & 0x1) << 24) +#define G_0280A0_SIMPLE_FLOAT(x) (((x) >> 24) & 0x1) +#define C_0280A0_SIMPLE_FLOAT 0xFEFFFFFF +#define S_0280A0_ROUND_MODE(x) (((x) & 0x1) << 25) +#define G_0280A0_ROUND_MODE(x) (((x) >> 25) & 0x1) +#define C_0280A0_ROUND_MODE 0xFDFFFFFF +#define S_0280A0_TILE_COMPACT(x) (((x) & 0x1) << 26) +#define G_0280A0_TILE_COMPACT(x) (((x) >> 26) & 0x1) +#define C_0280A0_TILE_COMPACT 0xFBFFFFFF +#define S_0280A0_SOURCE_FORMAT(x) (((x) & 0x1) << 27) +#define G_0280A0_SOURCE_FORMAT(x) (((x) >> 27) & 0x1) +#define C_0280A0_SOURCE_FORMAT 0xF7FFFFFF +#define R_028060_CB_COLOR0_SIZE 0x028060 +#define S_028060_PITCH_TILE_MAX(x) (((x) & 0x3FF) << 0) +#define G_028060_PITCH_TILE_MAX(x) (((x) >> 0) & 0x3FF) +#define C_028060_PITCH_TILE_MAX 0xFFFFFC00 +#define S_028060_SLICE_TILE_MAX(x) (((x) & 0xFFFFF) << 10) +#define G_028060_SLICE_TILE_MAX(x) (((x) >> 10) & 0xFFFFF) +#define C_028060_SLICE_TILE_MAX 0xC00003FF +#define R_028800_DB_DEPTH_CONTROL 0x028800 +#define S_028800_STENCIL_ENABLE(x) (((x) & 0x1) << 0) +#define G_028800_STENCIL_ENABLE(x) (((x) >> 0) & 0x1) +#define C_028800_STENCIL_ENABLE 0xFFFFFFFE +#define S_028800_Z_ENABLE(x) (((x) & 0x1) << 1) +#define G_028800_Z_ENABLE(x) (((x) >> 1) & 0x1) +#define C_028800_Z_ENABLE 0xFFFFFFFD +#define S_028800_Z_WRITE_ENABLE(x) (((x) & 0x1) << 2) +#define G_028800_Z_WRITE_ENABLE(x) (((x) >> 2) & 0x1) +#define C_028800_Z_WRITE_ENABLE 0xFFFFFFFB +#define S_028800_ZFUNC(x) (((x) & 0x7) << 4) +#define G_028800_ZFUNC(x) (((x) >> 4) & 0x7) +#define C_028800_ZFUNC 0xFFFFFF8F +#define S_028800_BACKFACE_ENABLE(x) (((x) & 0x1) << 7) +#define G_028800_BACKFACE_ENABLE(x) (((x) >> 7) & 0x1) +#define C_028800_BACKFACE_ENABLE 0xFFFFFF7F +#define S_028800_STENCILFUNC(x) (((x) & 0x7) << 8) +#define G_028800_STENCILFUNC(x) (((x) >> 8) & 0x7) +#define C_028800_STENCILFUNC 0xFFFFF8FF +#define S_028800_STENCILFAIL(x) (((x) & 0x7) << 11) +#define G_028800_STENCILFAIL(x) (((x) >> 11) & 0x7) +#define C_028800_STENCILFAIL 0xFFFFC7FF +#define S_028800_STENCILZPASS(x) (((x) & 0x7) << 14) +#define G_028800_STENCILZPASS(x) (((x) >> 14) & 0x7) +#define C_028800_STENCILZPASS 0xFFFE3FFF +#define S_028800_STENCILZFAIL(x) (((x) & 0x7) << 17) +#define G_028800_STENCILZFAIL(x) (((x) >> 17) & 0x7) +#define C_028800_STENCILZFAIL 0xFFF1FFFF +#define S_028800_STENCILFUNC_BF(x) (((x) & 0x7) << 20) +#define G_028800_STENCILFUNC_BF(x) (((x) >> 20) & 0x7) +#define C_028800_STENCILFUNC_BF 0xFF8FFFFF +#define S_028800_STENCILFAIL_BF(x) (((x) & 0x7) << 23) +#define G_028800_STENCILFAIL_BF(x) (((x) >> 23) & 0x7) +#define C_028800_STENCILFAIL_BF 0xFC7FFFFF +#define S_028800_STENCILZPASS_BF(x) (((x) & 0x7) << 26) +#define G_028800_STENCILZPASS_BF(x) (((x) >> 26) & 0x7) +#define C_028800_STENCILZPASS_BF 0xE3FFFFFF +#define S_028800_STENCILZFAIL_BF(x) (((x) & 0x7) << 29) +#define G_028800_STENCILZFAIL_BF(x) (((x) >> 29) & 0x7) +#define C_028800_STENCILZFAIL_BF 0x1FFFFFFF +#define R_028010_DB_DEPTH_INFO 0x028010 +#define S_028010_FORMAT(x) (((x) & 0x7) << 0) +#define G_028010_FORMAT(x) (((x) >> 0) & 0x7) +#define C_028010_FORMAT 0xFFFFFFF8 +#define V_028010_DEPTH_INVALID 0x00000000 +#define V_028010_DEPTH_16 0x00000001 +#define V_028010_DEPTH_X8_24 0x00000002 +#define V_028010_DEPTH_8_24 0x00000003 +#define V_028010_DEPTH_X8_24_FLOAT 0x00000004 +#define V_028010_DEPTH_8_24_FLOAT 0x00000005 +#define V_028010_DEPTH_32_FLOAT 0x00000006 +#define V_028010_DEPTH_X24_8_32_FLOAT 0x00000007 +#define S_028010_READ_SIZE(x) (((x) & 0x1) << 3) +#define G_028010_READ_SIZE(x) (((x) >> 3) & 0x1) +#define C_028010_READ_SIZE 0xFFFFFFF7 +#define S_028010_ARRAY_MODE(x) (((x) & 0xF) << 15) +#define G_028010_ARRAY_MODE(x) (((x) >> 15) & 0xF) +#define C_028010_ARRAY_MODE 0xFFF87FFF +#define S_028010_TILE_SURFACE_ENABLE(x) (((x) & 0x1) << 25) +#define G_028010_TILE_SURFACE_ENABLE(x) (((x) >> 25) & 0x1) +#define C_028010_TILE_SURFACE_ENABLE 0xFDFFFFFF +#define S_028010_TILE_COMPACT(x) (((x) & 0x1) << 26) +#define G_028010_TILE_COMPACT(x) (((x) >> 26) & 0x1) +#define C_028010_TILE_COMPACT 0xFBFFFFFF +#define S_028010_ZRANGE_PRECISION(x) (((x) & 0x1) << 31) +#define G_028010_ZRANGE_PRECISION(x) (((x) >> 31) & 0x1) +#define C_028010_ZRANGE_PRECISION 0x7FFFFFFF +#define R_028000_DB_DEPTH_SIZE 0x028000 +#define S_028000_PITCH_TILE_MAX(x) (((x) & 0x3FF) << 0) +#define G_028000_PITCH_TILE_MAX(x) (((x) >> 0) & 0x3FF) +#define C_028000_PITCH_TILE_MAX 0xFFFFFC00 +#define S_028000_SLICE_TILE_MAX(x) (((x) & 0xFFFFF) << 10) +#define G_028000_SLICE_TILE_MAX(x) (((x) >> 10) & 0xFFFFF) +#define C_028000_SLICE_TILE_MAX 0xC00003FF +#define R_028004_DB_DEPTH_VIEW 0x028004 +#define S_028004_SLICE_START(x) (((x) & 0x7FF) << 0) +#define G_028004_SLICE_START(x) (((x) >> 0) & 0x7FF) +#define C_028004_SLICE_START 0xFFFFF800 +#define S_028004_SLICE_MAX(x) (((x) & 0x7FF) << 13) +#define G_028004_SLICE_MAX(x) (((x) >> 13) & 0x7FF) +#define C_028004_SLICE_MAX 0xFF001FFF +#define R_028D24_DB_HTILE_SURFACE 0x028D24 +#define S_028D24_HTILE_WIDTH(x) (((x) & 0x1) << 0) +#define G_028D24_HTILE_WIDTH(x) (((x) >> 0) & 0x1) +#define C_028D24_HTILE_WIDTH 0xFFFFFFFE +#define S_028D24_HTILE_HEIGHT(x) (((x) & 0x1) << 1) +#define G_028D24_HTILE_HEIGHT(x) (((x) >> 1) & 0x1) +#define C_028D24_HTILE_HEIGHT 0xFFFFFFFD +#define S_028D24_LINEAR(x) (((x) & 0x1) << 2) +#define G_028D24_LINEAR(x) (((x) >> 2) & 0x1) +#define C_028D24_LINEAR 0xFFFFFFFB +#define S_028D24_FULL_CACHE(x) (((x) & 0x1) << 3) +#define G_028D24_FULL_CACHE(x) (((x) >> 3) & 0x1) +#define C_028D24_FULL_CACHE 0xFFFFFFF7 +#define S_028D24_HTILE_USES_PRELOAD_WIN(x) (((x) & 0x1) << 4) +#define G_028D24_HTILE_USES_PRELOAD_WIN(x) (((x) >> 4) & 0x1) +#define C_028D24_HTILE_USES_PRELOAD_WIN 0xFFFFFFEF +#define S_028D24_PRELOAD(x) (((x) & 0x1) << 5) +#define G_028D24_PRELOAD(x) (((x) >> 5) & 0x1) +#define C_028D24_PRELOAD 0xFFFFFFDF +#define S_028D24_PREFETCH_WIDTH(x) (((x) & 0x3F) << 6) +#define G_028D24_PREFETCH_WIDTH(x) (((x) >> 6) & 0x3F) +#define C_028D24_PREFETCH_WIDTH 0xFFFFF03F +#define S_028D24_PREFETCH_HEIGHT(x) (((x) & 0x3F) << 12) +#define G_028D24_PREFETCH_HEIGHT(x) (((x) >> 12) & 0x3F) +#define C_028D24_PREFETCH_HEIGHT 0xFFFC0FFF +#define R_028D34_DB_PREFETCH_LIMIT 0x028D34 +#define S_028D34_DEPTH_HEIGHT_TILE_MAX(x) (((x) & 0x3FF) << 0) +#define G_028D34_DEPTH_HEIGHT_TILE_MAX(x) (((x) >> 0) & 0x3FF) +#define C_028D34_DEPTH_HEIGHT_TILE_MAX 0xFFFFFC00 +#define R_028D10_DB_RENDER_OVERRIDE 0x028D10 +#define S_028D10_FORCE_HIZ_ENABLE(x) (((x) & 0x3) << 0) +#define G_028D10_FORCE_HIZ_ENABLE(x) (((x) >> 0) & 0x3) +#define C_028D10_FORCE_HIZ_ENABLE 0xFFFFFFFC +#define S_028D10_FORCE_HIS_ENABLE0(x) (((x) & 0x3) << 2) +#define G_028D10_FORCE_HIS_ENABLE0(x) (((x) >> 2) & 0x3) +#define C_028D10_FORCE_HIS_ENABLE0 0xFFFFFFF3 +#define S_028D10_FORCE_HIS_ENABLE1(x) (((x) & 0x3) << 4) +#define G_028D10_FORCE_HIS_ENABLE1(x) (((x) >> 4) & 0x3) +#define C_028D10_FORCE_HIS_ENABLE1 0xFFFFFFCF +#define S_028D10_FORCE_SHADER_Z_ORDER(x) (((x) & 0x1) << 6) +#define G_028D10_FORCE_SHADER_Z_ORDER(x) (((x) >> 6) & 0x1) +#define C_028D10_FORCE_SHADER_Z_ORDER 0xFFFFFFBF +#define S_028D10_FAST_Z_DISABLE(x) (((x) & 0x1) << 7) +#define G_028D10_FAST_Z_DISABLE(x) (((x) >> 7) & 0x1) +#define C_028D10_FAST_Z_DISABLE 0xFFFFFF7F +#define S_028D10_FAST_STENCIL_DISABLE(x) (((x) & 0x1) << 8) +#define G_028D10_FAST_STENCIL_DISABLE(x) (((x) >> 8) & 0x1) +#define C_028D10_FAST_STENCIL_DISABLE 0xFFFFFEFF +#define S_028D10_NOOP_CULL_DISABLE(x) (((x) & 0x1) << 9) +#define G_028D10_NOOP_CULL_DISABLE(x) (((x) >> 9) & 0x1) +#define C_028D10_NOOP_CULL_DISABLE 0xFFFFFDFF +#define S_028D10_FORCE_COLOR_KILL(x) (((x) & 0x1) << 10) +#define G_028D10_FORCE_COLOR_KILL(x) (((x) >> 10) & 0x1) +#define C_028D10_FORCE_COLOR_KILL 0xFFFFFBFF +#define S_028D10_FORCE_Z_READ(x) (((x) & 0x1) << 11) +#define G_028D10_FORCE_Z_READ(x) (((x) >> 11) & 0x1) +#define C_028D10_FORCE_Z_READ 0xFFFFF7FF +#define S_028D10_FORCE_STENCIL_READ(x) (((x) & 0x1) << 12) +#define G_028D10_FORCE_STENCIL_READ(x) (((x) >> 12) & 0x1) +#define C_028D10_FORCE_STENCIL_READ 0xFFFFEFFF +#define S_028D10_FORCE_FULL_Z_RANGE(x) (((x) & 0x3) << 13) +#define G_028D10_FORCE_FULL_Z_RANGE(x) (((x) >> 13) & 0x3) +#define C_028D10_FORCE_FULL_Z_RANGE 0xFFFF9FFF +#define S_028D10_FORCE_QC_SMASK_CONFLICT(x) (((x) & 0x1) << 15) +#define G_028D10_FORCE_QC_SMASK_CONFLICT(x) (((x) >> 15) & 0x1) +#define C_028D10_FORCE_QC_SMASK_CONFLICT 0xFFFF7FFF +#define S_028D10_DISABLE_VIEWPORT_CLAMP(x) (((x) & 0x1) << 16) +#define G_028D10_DISABLE_VIEWPORT_CLAMP(x) (((x) >> 16) & 0x1) +#define C_028D10_DISABLE_VIEWPORT_CLAMP 0xFFFEFFFF +#define S_028D10_IGNORE_SC_ZRANGE(x) (((x) & 0x1) << 17) +#define G_028D10_IGNORE_SC_ZRANGE(x) (((x) >> 17) & 0x1) +#define C_028D10_IGNORE_SC_ZRANGE 0xFFFDFFFF +#define R_028A40_VGT_GS_MODE 0x028A40 +#define S_028A40_MODE(x) (((x) & 0x3) << 0) +#define G_028A40_MODE(x) (((x) >> 0) & 0x3) +#define C_028A40_MODE 0xFFFFFFFC +#define S_028A40_ES_PASSTHRU(x) (((x) & 0x1) << 2) +#define G_028A40_ES_PASSTHRU(x) (((x) >> 2) & 0x1) +#define C_028A40_ES_PASSTHRU 0xFFFFFFFB +#define S_028A40_CUT_MODE(x) (((x) & 0x3) << 3) +#define G_028A40_CUT_MODE(x) (((x) >> 3) & 0x3) +#define C_028A40_CUT_MODE 0xFFFFFFE7 +#define R_008DFC_SQ_CF_WORD0 0x008DFC +#define S_008DFC_ADDR(x) (((x) & 0xFFFFFFFF) << 0) +#define G_008DFC_ADDR(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_008DFC_ADDR 0x00000000 +#define R_008DFC_SQ_CF_WORD1 0x008DFC +#define S_008DFC_POP_COUNT(x) (((x) & 0x7) << 0) +#define G_008DFC_POP_COUNT(x) (((x) >> 0) & 0x7) +#define C_008DFC_POP_COUNT 0xFFFFFFF8 +#define S_008DFC_CF_CONST(x) (((x) & 0x1F) << 3) +#define G_008DFC_CF_CONST(x) (((x) >> 3) & 0x1F) +#define C_008DFC_CF_CONST 0xFFFFFF07 +#define S_008DFC_COND(x) (((x) & 0x3) << 8) +#define G_008DFC_COND(x) (((x) >> 8) & 0x3) +#define C_008DFC_COND 0xFFFFFCFF +#define S_008DFC_COUNT(x) (((x) & 0x7) << 10) +#define G_008DFC_COUNT(x) (((x) >> 10) & 0x7) +#define C_008DFC_COUNT 0xFFFFE3FF +#define S_008DFC_CALL_COUNT(x) (((x) & 0x3F) << 13) +#define G_008DFC_CALL_COUNT(x) (((x) >> 13) & 0x3F) +#define C_008DFC_CALL_COUNT 0xFFF81FFF +#define S_008DFC_END_OF_PROGRAM(x) (((x) & 0x1) << 21) +#define G_008DFC_END_OF_PROGRAM(x) (((x) >> 21) & 0x1) +#define C_008DFC_END_OF_PROGRAM 0xFFDFFFFF +#define S_008DFC_VALID_PIXEL_MODE(x) (((x) & 0x1) << 22) +#define G_008DFC_VALID_PIXEL_MODE(x) (((x) >> 22) & 0x1) +#define C_008DFC_VALID_PIXEL_MODE 0xFFBFFFFF +#define S_008DFC_CF_INST(x) (((x) & 0x7F) << 23) +#define G_008DFC_CF_INST(x) (((x) >> 23) & 0x7F) +#define C_008DFC_CF_INST 0xC07FFFFF +#define V_008DFC_SQ_CF_INST_NOP 0x00000000 +#define V_008DFC_SQ_CF_INST_TEX 0x00000001 +#define V_008DFC_SQ_CF_INST_VTX 0x00000002 +#define V_008DFC_SQ_CF_INST_VTX_TC 0x00000003 +#define V_008DFC_SQ_CF_INST_LOOP_START 0x00000004 +#define V_008DFC_SQ_CF_INST_LOOP_END 0x00000005 +#define V_008DFC_SQ_CF_INST_LOOP_START_DX10 0x00000006 +#define V_008DFC_SQ_CF_INST_LOOP_START_NO_AL 0x00000007 +#define V_008DFC_SQ_CF_INST_LOOP_CONTINUE 0x00000008 +#define V_008DFC_SQ_CF_INST_LOOP_BREAK 0x00000009 +#define V_008DFC_SQ_CF_INST_JUMP 0x0000000A +#define V_008DFC_SQ_CF_INST_PUSH 0x0000000B +#define V_008DFC_SQ_CF_INST_PUSH_ELSE 0x0000000C +#define V_008DFC_SQ_CF_INST_ELSE 0x0000000D +#define V_008DFC_SQ_CF_INST_POP 0x0000000E +#define V_008DFC_SQ_CF_INST_POP_JUMP 0x0000000F +#define V_008DFC_SQ_CF_INST_POP_PUSH 0x00000010 +#define V_008DFC_SQ_CF_INST_POP_PUSH_ELSE 0x00000011 +#define V_008DFC_SQ_CF_INST_CALL 0x00000012 +#define V_008DFC_SQ_CF_INST_CALL_FS 0x00000013 +#define V_008DFC_SQ_CF_INST_RETURN 0x00000014 +#define V_008DFC_SQ_CF_INST_EMIT_VERTEX 0x00000015 +#define V_008DFC_SQ_CF_INST_EMIT_CUT_VERTEX 0x00000016 +#define V_008DFC_SQ_CF_INST_CUT_VERTEX 0x00000017 +#define V_008DFC_SQ_CF_INST_KILL 0x00000018 +#define S_008DFC_WHOLE_QUAD_MODE(x) (((x) & 0x1) << 30) +#define G_008DFC_WHOLE_QUAD_MODE(x) (((x) >> 30) & 0x1) +#define C_008DFC_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_008DFC_BARRIER(x) (((x) & 0x1) << 31) +#define G_008DFC_BARRIER(x) (((x) >> 31) & 0x1) +#define C_008DFC_BARRIER 0x7FFFFFFF +#define R_008DFC_SQ_CF_ALU_WORD0 0x008DFC +#define S_008DFC_ALU_ADDR(x) (((x) & 0x3FFFFF) << 0) +#define G_008DFC_ALU_ADDR(x) (((x) >> 0) & 0x3FFFFF) +#define C_008DFC_ALU_ADDR 0xFFC00000 +#define S_008DFC_KCACHE_BANK0(x) (((x) & 0xF) << 22) +#define G_008DFC_KCACHE_BANK0(x) (((x) >> 22) & 0xF) +#define C_008DFC_KCACHE_BANK0 0xFC3FFFFF +#define S_008DFC_KCACHE_BANK1(x) (((x) & 0xF) << 26) +#define G_008DFC_KCACHE_BANK1(x) (((x) >> 26) & 0xF) +#define C_008DFC_KCACHE_BANK1 0xC3FFFFFF +#define S_008DFC_KCACHE_MODE0(x) (((x) & 0x3) << 30) +#define G_008DFC_KCACHE_MODE0(x) (((x) >> 30) & 0x3) +#define C_008DFC_KCACHE_MODE0 0x3FFFFFFF +#define R_008DFC_SQ_CF_ALU_WORD1 0x008DFC +#define S_008DFC_KCACHE_MODE1(x) (((x) & 0x3) << 0) +#define G_008DFC_KCACHE_MODE1(x) (((x) >> 0) & 0x3) +#define C_008DFC_KCACHE_MODE1 0xFFFFFFFC +#define S_008DFC_KCACHE_ADDR0(x) (((x) & 0xFF) << 2) +#define G_008DFC_KCACHE_ADDR0(x) (((x) >> 2) & 0xFF) +#define C_008DFC_KCACHE_ADDR0 0xFFFFFC03 +#define S_008DFC_KCACHE_ADDR1(x) (((x) & 0xFF) << 10) +#define G_008DFC_KCACHE_ADDR1(x) (((x) >> 10) & 0xFF) +#define C_008DFC_KCACHE_ADDR1 0xFFFC03FF +#define S_008DFC_ALU_COUNT(x) (((x) & 0x7F) << 18) +#define G_008DFC_ALU_COUNT(x) (((x) >> 18) & 0x7F) +#define C_008DFC_ALU_COUNT 0xFE03FFFF +#define S_008DFC_USES_WATERFALL(x) (((x) & 0x1) << 25) +#define G_008DFC_USES_WATERFALL(x) (((x) >> 25) & 0x1) +#define C_008DFC_USES_WATERFALL 0xFDFFFFFF +#define S_008DFC_CF_ALU_INST(x) (((x) & 0xF) << 26) +#define G_008DFC_CF_ALU_INST(x) (((x) >> 26) & 0xF) +#define C_008DFC_CF_ALU_INST 0xC3FFFFFF +#define V_008DFC_SQ_CF_INST_ALU 0x00000008 +#define V_008DFC_SQ_CF_INST_ALU_PUSH_BEFORE 0x00000009 +#define V_008DFC_SQ_CF_INST_ALU_POP_AFTER 0x0000000A +#define V_008DFC_SQ_CF_INST_ALU_POP2_AFTER 0x0000000B +#define V_008DFC_SQ_CF_INST_ALU_CONTINUE 0x0000000D +#define V_008DFC_SQ_CF_INST_ALU_BREAK 0x0000000E +#define V_008DFC_SQ_CF_INST_ALU_ELSE_AFTER 0x0000000F +#define S_008DFC_WHOLE_QUAD_MODE(x) (((x) & 0x1) << 30) +#define G_008DFC_WHOLE_QUAD_MODE(x) (((x) >> 30) & 0x1) +#define C_008DFC_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_008DFC_BARRIER(x) (((x) & 0x1) << 31) +#define G_008DFC_BARRIER(x) (((x) >> 31) & 0x1) +#define C_008DFC_BARRIER 0x7FFFFFFF +#define R_008DFC_SQ_CF_ALLOC_EXPORT_WORD0 0x008DFC +#define S_008DFC_ARRAY_BASE(x) (((x) & 0x1FFF) << 0) +#define G_008DFC_ARRAY_BASE(x) (((x) >> 0) & 0x1FFF) +#define C_008DFC_ARRAY_BASE 0xFFFFE000 +#define S_008DFC_TYPE(x) (((x) & 0x3) << 13) +#define G_008DFC_TYPE(x) (((x) >> 13) & 0x3) +#define C_008DFC_TYPE 0xFFFF9FFF +#define S_008DFC_RW_GPR(x) (((x) & 0x7F) << 15) +#define G_008DFC_RW_GPR(x) (((x) >> 15) & 0x7F) +#define C_008DFC_RW_GPR 0xFFC07FFF +#define S_008DFC_RW_REL(x) (((x) & 0x1) << 22) +#define G_008DFC_RW_REL(x) (((x) >> 22) & 0x1) +#define C_008DFC_RW_REL 0xFFBFFFFF +#define S_008DFC_INDEX_GPR(x) (((x) & 0x7F) << 23) +#define G_008DFC_INDEX_GPR(x) (((x) >> 23) & 0x7F) +#define C_008DFC_INDEX_GPR 0xC07FFFFF +#define S_008DFC_ELEM_SIZE(x) (((x) & 0x3) << 30) +#define G_008DFC_ELEM_SIZE(x) (((x) >> 30) & 0x3) +#define C_008DFC_ELEM_SIZE 0x3FFFFFFF +#define R_008DFC_SQ_CF_ALLOC_EXPORT_WORD1 0x008DFC +#define S_008DFC_BURST_COUNT(x) (((x) & 0xF) << 17) +#define G_008DFC_BURST_COUNT(x) (((x) >> 17) & 0xF) +#define C_008DFC_BURST_COUNT 0xFFE1FFFF +#define S_008DFC_END_OF_PROGRAM(x) (((x) & 0x1) << 21) +#define G_008DFC_END_OF_PROGRAM(x) (((x) >> 21) & 0x1) +#define C_008DFC_END_OF_PROGRAM 0xFFDFFFFF +#define S_008DFC_VALID_PIXEL_MODE(x) (((x) & 0x1) << 22) +#define G_008DFC_VALID_PIXEL_MODE(x) (((x) >> 22) & 0x1) +#define C_008DFC_VALID_PIXEL_MODE 0xFFBFFFFF +#define S_008DFC_CF_INST(x) (((x) & 0x7F) << 23) +#define G_008DFC_CF_INST(x) (((x) >> 23) & 0x7F) +#define C_008DFC_CF_INST 0xC07FFFFF +#define V_008DFC_SQ_CF_INST_MEM_STREAM0 0x00000020 +#define V_008DFC_SQ_CF_INST_MEM_STREAM1 0x00000021 +#define V_008DFC_SQ_CF_INST_MEM_STREAM2 0x00000022 +#define V_008DFC_SQ_CF_INST_MEM_STREAM3 0x00000023 +#define V_008DFC_SQ_CF_INST_MEM_SCRATCH 0x00000024 +#define V_008DFC_SQ_CF_INST_MEM_REDUCTION 0x00000025 +#define V_008DFC_SQ_CF_INST_MEM_RING 0x00000026 +#define V_008DFC_SQ_CF_INST_EXPORT 0x00000027 +#define V_008DFC_SQ_CF_INST_EXPORT_DONE 0x00000028 +#define S_008DFC_WHOLE_QUAD_MODE(x) (((x) & 0x1) << 30) +#define G_008DFC_WHOLE_QUAD_MODE(x) (((x) >> 30) & 0x1) +#define C_008DFC_WHOLE_QUAD_MODE 0xBFFFFFFF +#define S_008DFC_BARRIER(x) (((x) & 0x1) << 31) +#define G_008DFC_BARRIER(x) (((x) >> 31) & 0x1) +#define C_008DFC_BARRIER 0x7FFFFFFF +#define R_008DFC_SQ_CF_ALLOC_EXPORT_WORD1_BUF 0x008DFC +#define S_008DFC_ARRAY_SIZE(x) (((x) & 0xFFF) << 0) +#define G_008DFC_ARRAY_SIZE(x) (((x) >> 0) & 0xFFF) +#define C_008DFC_ARRAY_SIZE 0xFFFFF000 +#define S_008DFC_COMP_MASK(x) (((x) & 0xF) << 12) +#define G_008DFC_COMP_MASK(x) (((x) >> 12) & 0xF) +#define C_008DFC_COMP_MASK 0xFFFF0FFF +#define R_008DFC_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ 0x008DFC +#define S_008DFC_SEL_X(x) (((x) & 0x7) << 0) +#define G_008DFC_SEL_X(x) (((x) >> 0) & 0x7) +#define C_008DFC_SEL_X 0xFFFFFFF8 +#define S_008DFC_SEL_Y(x) (((x) & 0x7) << 3) +#define G_008DFC_SEL_Y(x) (((x) >> 3) & 0x7) +#define C_008DFC_SEL_Y 0xFFFFFFC7 +#define S_008DFC_SEL_Z(x) (((x) & 0x7) << 6) +#define G_008DFC_SEL_Z(x) (((x) >> 6) & 0x7) +#define C_008DFC_SEL_Z 0xFFFFFE3F +#define S_008DFC_SEL_W(x) (((x) & 0x7) << 9) +#define G_008DFC_SEL_W(x) (((x) >> 9) & 0x7) +#define C_008DFC_SEL_W 0xFFFFF1FF +#define R_008DFC_SQ_VTX_WORD0 0x008DFC +#define S_008DFC_VTX_INST(x) (((x) & 0x1F) << 0) +#define G_008DFC_VTX_INST(x) (((x) >> 0) & 0x1F) +#define C_008DFC_VTX_INST 0xFFFFFFE0 +#define S_008DFC_FETCH_TYPE(x) (((x) & 0x3) << 5) +#define G_008DFC_FETCH_TYPE(x) (((x) >> 5) & 0x3) +#define C_008DFC_FETCH_TYPE 0xFFFFFF9F +#define S_008DFC_FETCH_WHOLE_QUAD(x) (((x) & 0x1) << 7) +#define G_008DFC_FETCH_WHOLE_QUAD(x) (((x) >> 7) & 0x1) +#define C_008DFC_FETCH_WHOLE_QUAD 0xFFFFFF7F +#define S_008DFC_BUFFER_ID(x) (((x) & 0xFF) << 8) +#define G_008DFC_BUFFER_ID(x) (((x) >> 8) & 0xFF) +#define C_008DFC_BUFFER_ID 0xFFFF00FF +#define S_008DFC_SRC_GPR(x) (((x) & 0x7F) << 16) +#define G_008DFC_SRC_GPR(x) (((x) >> 16) & 0x7F) +#define C_008DFC_SRC_GPR 0xFF80FFFF +#define S_008DFC_SRC_REL(x) (((x) & 0x1) << 23) +#define G_008DFC_SRC_REL(x) (((x) >> 23) & 0x1) +#define C_008DFC_SRC_REL 0xFF7FFFFF +#define S_008DFC_SRC_SEL_X(x) (((x) & 0x3) << 24) +#define G_008DFC_SRC_SEL_X(x) (((x) >> 24) & 0x3) +#define C_008DFC_SRC_SEL_X 0xFCFFFFFF +#define S_008DFC_MEGA_FETCH_COUNT(x) (((x) & 0x3F) << 26) +#define G_008DFC_MEGA_FETCH_COUNT(x) (((x) >> 26) & 0x3F) +#define C_008DFC_MEGA_FETCH_COUNT 0x03FFFFFF +#define R_008DFC_SQ_VTX_WORD1 0x008DFC +#define S_008DFC_DST_SEL_X(x) (((x) & 0x7) << 9) +#define G_008DFC_DST_SEL_X(x) (((x) >> 9) & 0x7) +#define C_008DFC_DST_SEL_X 0xFFFFF1FF +#define S_008DFC_DST_SEL_Y(x) (((x) & 0x7) << 12) +#define G_008DFC_DST_SEL_Y(x) (((x) >> 12) & 0x7) +#define C_008DFC_DST_SEL_Y 0xFFFF8FFF +#define S_008DFC_DST_SEL_Z(x) (((x) & 0x7) << 15) +#define G_008DFC_DST_SEL_Z(x) (((x) >> 15) & 0x7) +#define C_008DFC_DST_SEL_Z 0xFFFC7FFF +#define S_008DFC_DST_SEL_W(x) (((x) & 0x7) << 18) +#define G_008DFC_DST_SEL_W(x) (((x) >> 18) & 0x7) +#define C_008DFC_DST_SEL_W 0xFFE3FFFF +#define S_008DFC_USE_CONST_FIELDS(x) (((x) & 0x1) << 21) +#define G_008DFC_USE_CONST_FIELDS(x) (((x) >> 21) & 0x1) +#define C_008DFC_USE_CONST_FIELDS 0xFFDFFFFF +#define S_008DFC_DATA_FORMAT(x) (((x) & 0x3F) << 22) +#define G_008DFC_DATA_FORMAT(x) (((x) >> 22) & 0x3F) +#define C_008DFC_DATA_FORMAT 0xF03FFFFF +#define S_008DFC_NUM_FORMAT_ALL(x) (((x) & 0x3) << 28) +#define G_008DFC_NUM_FORMAT_ALL(x) (((x) >> 28) & 0x3) +#define C_008DFC_NUM_FORMAT_ALL 0xCFFFFFFF +#define S_008DFC_FORMAT_COMP_ALL(x) (((x) & 0x1) << 30) +#define G_008DFC_FORMAT_COMP_ALL(x) (((x) >> 30) & 0x1) +#define C_008DFC_FORMAT_COMP_ALL 0xBFFFFFFF +#define S_008DFC_SRF_MODE_ALL(x) (((x) & 0x1) << 31) +#define G_008DFC_SRF_MODE_ALL(x) (((x) >> 31) & 0x1) +#define C_008DFC_SRF_MODE_ALL 0x7FFFFFFF +#define R_008DFC_SQ_VTX_WORD1_GPR 0x008DFC +#define S_008DFC_DST_GPR(x) (((x) & 0x7F) << 0) +#define G_008DFC_DST_GPR(x) (((x) >> 0) & 0x7F) +#define C_008DFC_DST_GPR 0xFFFFFF80 +#define S_008DFC_DST_REL(x) (((x) & 0x1) << 7) +#define G_008DFC_DST_REL(x) (((x) >> 7) & 0x1) +#define C_008DFC_DST_REL 0xFFFFFF7F +#define R_008DFC_SQ_VTX_WORD2 0x008DFC +#define S_008DFC_OFFSET(x) (((x) & 0xFFFF) << 0) +#define G_008DFC_OFFSET(x) (((x) >> 0) & 0xFFFF) +#define C_008DFC_OFFSET 0xFFFF0000 +#define S_008DFC_ENDIAN_SWAP(x) (((x) & 0x3) << 16) +#define G_008DFC_ENDIAN_SWAP(x) (((x) >> 16) & 0x3) +#define C_008DFC_ENDIAN_SWAP 0xFFFCFFFF +#define S_008DFC_CONST_BUF_NO_STRIDE(x) (((x) & 0x1) << 18) +#define G_008DFC_CONST_BUF_NO_STRIDE(x) (((x) >> 18) & 0x1) +#define C_008DFC_CONST_BUF_NO_STRIDE 0xFFFBFFFF +#define S_008DFC_MEGA_FETCH(x) (((x) & 0x1) << 19) +#define G_008DFC_MEGA_FETCH(x) (((x) >> 19) & 0x1) +#define C_008DFC_MEGA_FETCH 0xFFF7FFFF +#define S_008DFC_ALT_CONST(x) (((x) & 0x1) << 20) +#define G_008DFC_ALT_CONST(x) (((x) >> 20) & 0x1) +#define C_008DFC_ALT_CONST 0xFFEFFFFF +#define R_008040_WAIT_UNTIL 0x008040 +#define S_008040_WAIT_CP_DMA_IDLE(x) (((x) & 0x1) << 8) +#define G_008040_WAIT_CP_DMA_IDLE(x) (((x) >> 8) & 0x1) +#define C_008040_WAIT_CP_DMA_IDLE 0xFFFFFEFF +#define S_008040_WAIT_CMDFIFO(x) (((x) & 0x1) << 10) +#define G_008040_WAIT_CMDFIFO(x) (((x) >> 10) & 0x1) +#define C_008040_WAIT_CMDFIFO 0xFFFFFBFF +#define S_008040_WAIT_2D_IDLE(x) (((x) & 0x1) << 14) +#define G_008040_WAIT_2D_IDLE(x) (((x) >> 14) & 0x1) +#define C_008040_WAIT_2D_IDLE 0xFFFFBFFF +#define S_008040_WAIT_3D_IDLE(x) (((x) & 0x1) << 15) +#define G_008040_WAIT_3D_IDLE(x) (((x) >> 15) & 0x1) +#define C_008040_WAIT_3D_IDLE 0xFFFF7FFF +#define S_008040_WAIT_2D_IDLECLEAN(x) (((x) & 0x1) << 16) +#define G_008040_WAIT_2D_IDLECLEAN(x) (((x) >> 16) & 0x1) +#define C_008040_WAIT_2D_IDLECLEAN 0xFFFEFFFF +#define S_008040_WAIT_3D_IDLECLEAN(x) (((x) & 0x1) << 17) +#define G_008040_WAIT_3D_IDLECLEAN(x) (((x) >> 17) & 0x1) +#define C_008040_WAIT_3D_IDLECLEAN 0xFFFDFFFF +#define S_008040_WAIT_EXTERN_SIG(x) (((x) & 0x1) << 19) +#define G_008040_WAIT_EXTERN_SIG(x) (((x) >> 19) & 0x1) +#define C_008040_WAIT_EXTERN_SIG 0xFFF7FFFF +#define S_008040_CMDFIFO_ENTRIES(x) (((x) & 0x1F) << 20) +#define G_008040_CMDFIFO_ENTRIES(x) (((x) >> 20) & 0x1F) +#define C_008040_CMDFIFO_ENTRIES 0xFE0FFFFF +#define R_0286CC_SPI_PS_IN_CONTROL_0 0x0286CC +#define S_0286CC_NUM_INTERP(x) (((x) & 0x3F) << 0) +#define G_0286CC_NUM_INTERP(x) (((x) >> 0) & 0x3F) +#define C_0286CC_NUM_INTERP 0xFFFFFFC0 +#define S_0286CC_POSITION_ENA(x) (((x) & 0x1) << 8) +#define G_0286CC_POSITION_ENA(x) (((x) >> 8) & 0x1) +#define C_0286CC_POSITION_ENA 0xFFFFFEFF +#define S_0286CC_POSITION_CENTROID(x) (((x) & 0x1) << 9) +#define G_0286CC_POSITION_CENTROID(x) (((x) >> 9) & 0x1) +#define C_0286CC_POSITION_CENTROID 0xFFFFFDFF +#define S_0286CC_POSITION_ADDR(x) (((x) & 0x1F) << 10) +#define G_0286CC_POSITION_ADDR(x) (((x) >> 10) & 0x1F) +#define C_0286CC_POSITION_ADDR 0xFFFF83FF +#define S_0286CC_PARAM_GEN(x) (((x) & 0xF) << 15) +#define G_0286CC_PARAM_GEN(x) (((x) >> 15) & 0xF) +#define C_0286CC_PARAM_GEN 0xFFF87FFF +#define S_0286CC_PARAM_GEN_ADDR(x) (((x) & 0x7F) << 19) +#define G_0286CC_PARAM_GEN_ADDR(x) (((x) >> 19) & 0x7F) +#define C_0286CC_PARAM_GEN_ADDR 0xFC07FFFF +#define S_0286CC_BARYC_SAMPLE_CNTL(x) (((x) & 0x3) << 26) +#define G_0286CC_BARYC_SAMPLE_CNTL(x) (((x) >> 26) & 0x3) +#define C_0286CC_BARYC_SAMPLE_CNTL 0xF3FFFFFF +#define S_0286CC_PERSP_GRADIENT_ENA(x) (((x) & 0x1) << 28) +#define G_0286CC_PERSP_GRADIENT_ENA(x) (((x) >> 28) & 0x1) +#define C_0286CC_PERSP_GRADIENT_ENA 0xEFFFFFFF +#define S_0286CC_LINEAR_GRADIENT_ENA(x) (((x) & 0x1) << 29) +#define G_0286CC_LINEAR_GRADIENT_ENA(x) (((x) >> 29) & 0x1) +#define C_0286CC_LINEAR_GRADIENT_ENA 0xDFFFFFFF +#define S_0286CC_POSITION_SAMPLE(x) (((x) & 0x1) << 30) +#define G_0286CC_POSITION_SAMPLE(x) (((x) >> 30) & 0x1) +#define C_0286CC_POSITION_SAMPLE 0xBFFFFFFF +#define S_0286CC_BARYC_AT_SAMPLE_ENA(x) (((x) & 0x1) << 31) +#define G_0286CC_BARYC_AT_SAMPLE_ENA(x) (((x) >> 31) & 0x1) +#define C_0286CC_BARYC_AT_SAMPLE_ENA 0x7FFFFFFF +#define R_0286D0_SPI_PS_IN_CONTROL_1 0x0286D0 +#define S_0286D0_GEN_INDEX_PIX(x) (((x) & 0x1) << 0) +#define G_0286D0_GEN_INDEX_PIX(x) (((x) >> 0) & 0x1) +#define C_0286D0_GEN_INDEX_PIX 0xFFFFFFFE +#define S_0286D0_GEN_INDEX_PIX_ADDR(x) (((x) & 0x7F) << 1) +#define G_0286D0_GEN_INDEX_PIX_ADDR(x) (((x) >> 1) & 0x7F) +#define C_0286D0_GEN_INDEX_PIX_ADDR 0xFFFFFF01 +#define S_0286D0_FRONT_FACE_ENA(x) (((x) & 0x1) << 8) +#define G_0286D0_FRONT_FACE_ENA(x) (((x) >> 8) & 0x1) +#define C_0286D0_FRONT_FACE_ENA 0xFFFFFEFF +#define S_0286D0_FRONT_FACE_CHAN(x) (((x) & 0x3) << 9) +#define G_0286D0_FRONT_FACE_CHAN(x) (((x) >> 9) & 0x3) +#define C_0286D0_FRONT_FACE_CHAN 0xFFFFF9FF +#define S_0286D0_FRONT_FACE_ALL_BITS(x) (((x) & 0x1) << 11) +#define G_0286D0_FRONT_FACE_ALL_BITS(x) (((x) >> 11) & 0x1) +#define C_0286D0_FRONT_FACE_ALL_BITS 0xFFFFF7FF +#define S_0286D0_FRONT_FACE_ADDR(x) (((x) & 0x1F) << 12) +#define G_0286D0_FRONT_FACE_ADDR(x) (((x) >> 12) & 0x1F) +#define C_0286D0_FRONT_FACE_ADDR 0xFFFE0FFF +#define S_0286D0_FOG_ADDR(x) (((x) & 0x7F) << 17) +#define G_0286D0_FOG_ADDR(x) (((x) >> 17) & 0x7F) +#define C_0286D0_FOG_ADDR 0xFF01FFFF +#define S_0286D0_FIXED_PT_POSITION_ENA(x) (((x) & 0x1) << 24) +#define G_0286D0_FIXED_PT_POSITION_ENA(x) (((x) >> 24) & 0x1) +#define C_0286D0_FIXED_PT_POSITION_ENA 0xFEFFFFFF +#define S_0286D0_FIXED_PT_POSITION_ADDR(x) (((x) & 0x1F) << 25) +#define G_0286D0_FIXED_PT_POSITION_ADDR(x) (((x) >> 25) & 0x1F) +#define C_0286D0_FIXED_PT_POSITION_ADDR 0xC1FFFFFF +#define R_0286C4_SPI_VS_OUT_CONFIG 0x0286C4 +#define S_0286C4_VS_PER_COMPONENT(x) (((x) & 0x1) << 0) +#define G_0286C4_VS_PER_COMPONENT(x) (((x) >> 0) & 0x1) +#define C_0286C4_VS_PER_COMPONENT 0xFFFFFFFE +#define S_0286C4_VS_EXPORT_COUNT(x) (((x) & 0x1F) << 1) +#define G_0286C4_VS_EXPORT_COUNT(x) (((x) >> 1) & 0x1F) +#define C_0286C4_VS_EXPORT_COUNT 0xFFFFFFC1 +#define S_0286C4_VS_EXPORTS_FOG(x) (((x) & 0x1) << 8) +#define G_0286C4_VS_EXPORTS_FOG(x) (((x) >> 8) & 0x1) +#define C_0286C4_VS_EXPORTS_FOG 0xFFFFFEFF +#define S_0286C4_VS_OUT_FOG_VEC_ADDR(x) (((x) & 0x1F) << 9) +#define G_0286C4_VS_OUT_FOG_VEC_ADDR(x) (((x) >> 9) & 0x1F) +#define C_0286C4_VS_OUT_FOG_VEC_ADDR 0xFFFFC1FF +#define R_028240_PA_SC_GENERIC_SCISSOR_TL 0x028240 +#define S_028240_TL_X(x) (((x) & 0x3FFF) << 0) +#define G_028240_TL_X(x) (((x) >> 0) & 0x3FFF) +#define C_028240_TL_X 0xFFFFC000 +#define S_028240_TL_Y(x) (((x) & 0x3FFF) << 16) +#define G_028240_TL_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028240_TL_Y 0xC000FFFF +#define S_028240_WINDOW_OFFSET_DISABLE(x) (((x) & 0x1) << 31) +#define G_028240_WINDOW_OFFSET_DISABLE(x) (((x) >> 31) & 0x1) +#define C_028240_WINDOW_OFFSET_DISABLE 0x7FFFFFFF +#define R_028244_PA_SC_GENERIC_SCISSOR_BR 0x028244 +#define S_028244_BR_X(x) (((x) & 0x3FFF) << 0) +#define G_028244_BR_X(x) (((x) >> 0) & 0x3FFF) +#define C_028244_BR_X 0xFFFFC000 +#define S_028244_BR_Y(x) (((x) & 0x3FFF) << 16) +#define G_028244_BR_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028244_BR_Y 0xC000FFFF +#define R_028030_PA_SC_SCREEN_SCISSOR_TL 0x028030 +#define S_028030_TL_X(x) (((x) & 0x7FFF) << 0) +#define G_028030_TL_X(x) (((x) >> 0) & 0x7FFF) +#define C_028030_TL_X 0xFFFF8000 +#define S_028030_TL_Y(x) (((x) & 0x7FFF) << 16) +#define G_028030_TL_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028030_TL_Y 0x8000FFFF +#define R_028034_PA_SC_SCREEN_SCISSOR_BR 0x028034 +#define S_028034_BR_X(x) (((x) & 0x7FFF) << 0) +#define G_028034_BR_X(x) (((x) >> 0) & 0x7FFF) +#define C_028034_BR_X 0xFFFF8000 +#define S_028034_BR_Y(x) (((x) & 0x7FFF) << 16) +#define G_028034_BR_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028034_BR_Y 0x8000FFFF +#define R_028204_PA_SC_WINDOW_SCISSOR_TL 0x028204 +#define S_028204_TL_X(x) (((x) & 0x3FFF) << 0) +#define G_028204_TL_X(x) (((x) >> 0) & 0x3FFF) +#define C_028204_TL_X 0xFFFFC000 +#define S_028204_TL_Y(x) (((x) & 0x3FFF) << 16) +#define G_028204_TL_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028204_TL_Y 0xC000FFFF +#define S_028204_WINDOW_OFFSET_DISABLE(x) (((x) & 0x1) << 31) +#define G_028204_WINDOW_OFFSET_DISABLE(x) (((x) >> 31) & 0x1) +#define C_028204_WINDOW_OFFSET_DISABLE 0x7FFFFFFF +#define R_028208_PA_SC_WINDOW_SCISSOR_BR 0x028208 +#define S_028208_BR_X(x) (((x) & 0x3FFF) << 0) +#define G_028208_BR_X(x) (((x) >> 0) & 0x3FFF) +#define C_028208_BR_X 0xFFFFC000 +#define S_028208_BR_Y(x) (((x) & 0x3FFF) << 16) +#define G_028208_BR_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028208_BR_Y 0xC000FFFF +#define R_0287F0_VGT_DRAW_INITIATOR 0x0287F0 +#define S_0287F0_SOURCE_SELECT(x) (((x) & 0x3) << 0) +#define G_0287F0_SOURCE_SELECT(x) (((x) >> 0) & 0x3) +#define C_0287F0_SOURCE_SELECT 0xFFFFFFFC +#define S_0287F0_MAJOR_MODE(x) (((x) & 0x3) << 2) +#define G_0287F0_MAJOR_MODE(x) (((x) >> 2) & 0x3) +#define C_0287F0_MAJOR_MODE 0xFFFFFFF3 +#define S_0287F0_SPRITE_EN(x) (((x) & 0x1) << 4) +#define G_0287F0_SPRITE_EN(x) (((x) >> 4) & 0x1) +#define C_0287F0_SPRITE_EN 0xFFFFFFEF +#define S_0287F0_NOT_EOP(x) (((x) & 0x1) << 5) +#define G_0287F0_NOT_EOP(x) (((x) >> 5) & 0x1) +#define C_0287F0_NOT_EOP 0xFFFFFFDF +#define S_0287F0_USE_OPAQUE(x) (((x) & 0x1) << 6) +#define G_0287F0_USE_OPAQUE(x) (((x) >> 6) & 0x1) +#define C_0287F0_USE_OPAQUE 0xFFFFFFBF +#define R_0280A0_CB_COLOR0_INFO 0x0280A0 +#define R_0280A4_CB_COLOR1_INFO 0x0280A4 +#define R_0280A8_CB_COLOR2_INFO 0x0280A8 +#define R_0280AC_CB_COLOR3_INFO 0x0280AC +#define R_0280B0_CB_COLOR4_INFO 0x0280B0 +#define R_0280B4_CB_COLOR5_INFO 0x0280B4 +#define R_0280B8_CB_COLOR6_INFO 0x0280B8 +#define R_0280BC_CB_COLOR7_INFO 0x0280BC +#define R_02800C_DB_DEPTH_BASE 0x02800C +#define R_028000_DB_DEPTH_SIZE 0x028000 +#define R_028004_DB_DEPTH_VIEW 0x028004 +#define R_028010_DB_DEPTH_INFO 0x028010 +#define R_028D24_DB_HTILE_SURFACE 0x028D24 +#define R_028D34_DB_PREFETCH_LIMIT 0x028D34 +#define R_0286D4_SPI_INTERP_CONTROL_0 0x0286D4 +#define R_028A48_PA_SC_MPASS_PS_CNTL 0x028A48 +#define R_028C00_PA_SC_LINE_CNTL 0x028C00 +#define R_028C04_PA_SC_AA_CONFIG 0x028C04 +#define R_028C08_PA_SU_VTX_CNTL 0x028C08 +#define R_028C1C_PA_SC_AA_SAMPLE_LOCS_MCTX 0x028C1C +#define R_028C48_PA_SC_AA_MASK 0x028C48 +#define R_028810_PA_CL_CLIP_CNTL 0x028810 +#define R_02881C_PA_CL_VS_OUT_CNTL 0x02881C +#define R_028820_PA_CL_NANINF_CNTL 0x028820 +#define R_028C0C_PA_CL_GB_VERT_CLIP_ADJ 0x028C0C +#define R_028C10_PA_CL_GB_VERT_DISC_ADJ 0x028C10 +#define R_028C14_PA_CL_GB_HORZ_CLIP_ADJ 0x028C14 +#define R_028C18_PA_CL_GB_HORZ_DISC_ADJ 0x028C18 +#define R_028814_PA_SU_SC_MODE_CNTL 0x028814 +#define R_028A00_PA_SU_POINT_SIZE 0x028A00 +#define R_028A04_PA_SU_POINT_MINMAX 0x028A04 +#define R_028A08_PA_SU_LINE_CNTL 0x028A08 +#define R_028A0C_PA_SC_LINE_STIPPLE 0x028A0C +#define R_028DF8_PA_SU_POLY_OFFSET_DB_FMT_CNTL 0x028DF8 +#define R_028DFC_PA_SU_POLY_OFFSET_CLAMP 0x028DFC +#define R_028E00_PA_SU_POLY_OFFSET_FRONT_SCALE 0x028E00 +#define R_028E04_PA_SU_POLY_OFFSET_FRONT_OFFSET 0x028E04 +#define R_028E08_PA_SU_POLY_OFFSET_BACK_SCALE 0x028E08 +#define R_028E0C_PA_SU_POLY_OFFSET_BACK_OFFSET 0x028E0C +#define R_028818_PA_CL_VTE_CNTL 0x028818 +#define R_02843C_PA_CL_VPORT_XSCALE_0 0x02843C +#define R_028444_PA_CL_VPORT_YSCALE_0 0x028444 +#define R_02844C_PA_CL_VPORT_ZSCALE_0 0x02844C +#define R_028440_PA_CL_VPORT_XOFFSET_0 0x028440 +#define R_028448_PA_CL_VPORT_YOFFSET_0 0x028448 +#define R_028450_PA_CL_VPORT_ZOFFSET_0 0x028450 +#define R_028250_PA_SC_VPORT_SCISSOR_0_TL 0x028250 +#define R_028254_PA_SC_VPORT_SCISSOR_0_BR 0x028254 +#define R_028780_CB_BLEND0_CONTROL 0x028780 +#define R_028784_CB_BLEND1_CONTROL 0x028784 +#define R_028788_CB_BLEND2_CONTROL 0x028788 +#define R_02878C_CB_BLEND3_CONTROL 0x02878C +#define R_028790_CB_BLEND4_CONTROL 0x028790 +#define R_028794_CB_BLEND5_CONTROL 0x028794 +#define R_028798_CB_BLEND6_CONTROL 0x028798 +#define R_02879C_CB_BLEND7_CONTROL 0x02879C +#define R_028804_CB_BLEND_CONTROL 0x028804 +#define R_028028_DB_STENCIL_CLEAR 0x028028 +#define R_02802C_DB_DEPTH_CLEAR 0x02802C +#define R_028430_DB_STENCILREFMASK 0x028430 +#define R_028434_DB_STENCILREFMASK_BF 0x028434 +#define R_028800_DB_DEPTH_CONTROL 0x028800 +#define R_02880C_DB_SHADER_CONTROL 0x02880C +#define R_028D0C_DB_RENDER_CONTROL 0x028D0C +#define S_028D0C_DEPTH_CLEAR_ENABLE(x) (((x) & 0x1) << 0) +#define S_028D0C_STENCIL_CLEAR_ENABLE(x) (((x) & 0x1) << 1) +#define S_028D0C_DEPTH_COPY_ENABLE(x) (((x) & 0x1) << 2) +#define S_028D0C_STENCIL_COPY_ENABLE(x) (((x) & 0x1) << 3) +#define S_028D0C_RESUMMARIZE_ENABLE(x) (((x) & 0x1) << 4) +#define S_028D0C_STENCIL_COMPRESS_DISABLE(x) (((x) & 0x1) << 5) +#define S_028D0C_DEPTH_COMPRESS_DISABLE(x) (((x) & 0x1) << 6) +#define S_028D0C_COPY_CENTROID(x) (((x) & 0x1) << 7) +#define S_028D0C_COPY_SAMPLE(x) (((x) & 0x1) << 8) +#define S_028D0C_R700_PERFECT_ZPASS_COUNTS(x) (((x) & 0x1) << 15) +#define R_028D10_DB_RENDER_OVERRIDE 0x028D10 +#define R_028D2C_DB_SRESULTS_COMPARE_STATE1 0x028D2C +#define R_028D30_DB_PRELOAD_CONTROL 0x028D30 +#define R_028D44_DB_ALPHA_TO_MASK 0x028D44 +#define R_028868_SQ_PGM_RESOURCES_VS 0x028868 +#define R_0286CC_SPI_PS_IN_CONTROL_0 0x0286CC +#define R_0286D0_SPI_PS_IN_CONTROL_1 0x0286D0 +#define R_028644_SPI_PS_INPUT_CNTL_0 0x028644 +#define R_028648_SPI_PS_INPUT_CNTL_1 0x028648 +#define R_02864C_SPI_PS_INPUT_CNTL_2 0x02864C +#define R_028650_SPI_PS_INPUT_CNTL_3 0x028650 +#define R_028654_SPI_PS_INPUT_CNTL_4 0x028654 +#define R_028658_SPI_PS_INPUT_CNTL_5 0x028658 +#define R_02865C_SPI_PS_INPUT_CNTL_6 0x02865C +#define R_028660_SPI_PS_INPUT_CNTL_7 0x028660 +#define R_028664_SPI_PS_INPUT_CNTL_8 0x028664 +#define R_028668_SPI_PS_INPUT_CNTL_9 0x028668 +#define R_02866C_SPI_PS_INPUT_CNTL_10 0x02866C +#define R_028670_SPI_PS_INPUT_CNTL_11 0x028670 +#define R_028674_SPI_PS_INPUT_CNTL_12 0x028674 +#define R_028678_SPI_PS_INPUT_CNTL_13 0x028678 +#define R_02867C_SPI_PS_INPUT_CNTL_14 0x02867C +#define R_028680_SPI_PS_INPUT_CNTL_15 0x028680 +#define R_028684_SPI_PS_INPUT_CNTL_16 0x028684 +#define R_028688_SPI_PS_INPUT_CNTL_17 0x028688 +#define R_02868C_SPI_PS_INPUT_CNTL_18 0x02868C +#define R_028690_SPI_PS_INPUT_CNTL_19 0x028690 +#define R_028694_SPI_PS_INPUT_CNTL_20 0x028694 +#define R_028698_SPI_PS_INPUT_CNTL_21 0x028698 +#define R_02869C_SPI_PS_INPUT_CNTL_22 0x02869C +#define R_0286A0_SPI_PS_INPUT_CNTL_23 0x0286A0 +#define R_0286A4_SPI_PS_INPUT_CNTL_24 0x0286A4 +#define R_0286A8_SPI_PS_INPUT_CNTL_25 0x0286A8 +#define R_0286AC_SPI_PS_INPUT_CNTL_26 0x0286AC +#define R_0286B0_SPI_PS_INPUT_CNTL_27 0x0286B0 +#define R_0286B4_SPI_PS_INPUT_CNTL_28 0x0286B4 +#define R_0286B8_SPI_PS_INPUT_CNTL_29 0x0286B8 +#define R_0286BC_SPI_PS_INPUT_CNTL_30 0x0286BC +#define R_0286C0_SPI_PS_INPUT_CNTL_31 0x0286C0 +#define R_028850_SQ_PGM_RESOURCES_PS 0x028850 +#define R_028854_SQ_PGM_EXPORTS_PS 0x028854 +#define R_008958_VGT_PRIMITIVE_TYPE 0x008958 +#define R_028A7C_VGT_DMA_INDEX_TYPE 0x028A7C +#define R_028A88_VGT_DMA_NUM_INSTANCES 0x028A88 +#define R_008970_VGT_NUM_INDICES 0x008970 +#define R_0287F0_VGT_DRAW_INITIATOR 0x0287F0 +#define R_028238_CB_TARGET_MASK 0x028238 +#define R_02823C_CB_SHADER_MASK 0x02823C +#define R_028060_CB_COLOR0_SIZE 0x028060 +#define S_028060_PITCH_TILE_MAX(x) (((x) & 0x3FF) << 0) +#define G_028060_PITCH_TILE_MAX(x) (((x) >> 0) & 0x3FF) +#define C_028060_PITCH_TILE_MAX 0xFFFFFC00 +#define S_028060_SLICE_TILE_MAX(x) (((x) & 0xFFFFF) << 10) +#define G_028060_SLICE_TILE_MAX(x) (((x) >> 10) & 0xFFFFF) +#define C_028060_SLICE_TILE_MAX 0xC00003FF +#define R_028064_CB_COLOR1_SIZE 0x028064 +#define R_028068_CB_COLOR2_SIZE 0x028068 +#define R_02806C_CB_COLOR3_SIZE 0x02806C +#define R_028070_CB_COLOR4_SIZE 0x028070 +#define R_028074_CB_COLOR5_SIZE 0x028074 +#define R_028078_CB_COLOR6_SIZE 0x028078 +#define R_02807C_CB_COLOR7_SIZE 0x02807C +#define R_028040_CB_COLOR0_BASE 0x028040 +#define R_028044_CB_COLOR1_BASE 0x028044 +#define R_028048_CB_COLOR2_BASE 0x028048 +#define R_02804C_CB_COLOR3_BASE 0x02804C +#define R_028050_CB_COLOR4_BASE 0x028050 +#define R_028054_CB_COLOR5_BASE 0x028054 +#define R_028058_CB_COLOR6_BASE 0x028058 +#define R_02805C_CB_COLOR7_BASE 0x02805C +#define R_028240_PA_SC_GENERIC_SCISSOR_TL 0x028240 +#define S_028240_TL_X(x) (((x) & 0x3FFF) << 0) +#define G_028240_TL_X(x) (((x) >> 0) & 0x3FFF) +#define C_028240_TL_X 0xFFFFC000 +#define S_028240_TL_Y(x) (((x) & 0x3FFF) << 16) +#define G_028240_TL_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028240_TL_Y 0xC000FFFF +#define R_028C04_PA_SC_AA_CONFIG 0x028C04 +#define S_028C04_MSAA_NUM_SAMPLES(x) (((x) & 0x3) << 0) +#define G_028C04_MSAA_NUM_SAMPLES(x) (((x) >> 0) & 0x3) +#define C_028C04_MSAA_NUM_SAMPLES 0xFFFFFFFC +#define S_028C04_AA_MASK_CENTROID_DTMN(x) (((x) & 0x1) << 4) +#define G_028C04_AA_MASK_CENTROID_DTMN(x) (((x) >> 4) & 0x1) +#define C_028C04_AA_MASK_CENTROID_DTMN 0xFFFFFFEF +#define S_028C04_MAX_SAMPLE_DIST(x) (((x) & 0xF) << 13) +#define G_028C04_MAX_SAMPLE_DIST(x) (((x) >> 13) & 0xF) +#define C_028C04_MAX_SAMPLE_DIST 0xFFFE1FFF +#define R_0288CC_SQ_PGM_CF_OFFSET_PS 0x0288CC +#define R_0288DC_SQ_PGM_CF_OFFSET_FS 0x0288DC +#define R_0288D0_SQ_PGM_CF_OFFSET_VS 0x0288D0 +#define R_028840_SQ_PGM_START_PS 0x028840 +#define R_028894_SQ_PGM_START_FS 0x028894 +#define R_028858_SQ_PGM_START_VS 0x028858 +#define R_028080_CB_COLOR0_VIEW 0x028080 +#define S_028080_SLICE_START(x) (((x) & 0x7FF) << 0) +#define G_028080_SLICE_START(x) (((x) >> 0) & 0x7FF) +#define C_028080_SLICE_START 0xFFFFF800 +#define S_028080_SLICE_MAX(x) (((x) & 0x7FF) << 13) +#define G_028080_SLICE_MAX(x) (((x) >> 13) & 0x7FF) +#define C_028080_SLICE_MAX 0xFF001FFF +#define R_028084_CB_COLOR1_VIEW 0x028084 +#define R_028088_CB_COLOR2_VIEW 0x028088 +#define R_02808C_CB_COLOR3_VIEW 0x02808C +#define R_028090_CB_COLOR4_VIEW 0x028090 +#define R_028094_CB_COLOR5_VIEW 0x028094 +#define R_028098_CB_COLOR6_VIEW 0x028098 +#define R_02809C_CB_COLOR7_VIEW 0x02809C +#define R_028100_CB_COLOR0_MASK 0x028100 +#define S_028100_CMASK_BLOCK_MAX(x) (((x) & 0xFFF) << 0) +#define G_028100_CMASK_BLOCK_MAX(x) (((x) >> 0) & 0xFFF) +#define C_028100_CMASK_BLOCK_MAX 0xFFFFF000 +#define S_028100_FMASK_TILE_MAX(x) (((x) & 0xFFFFF) << 12) +#define G_028100_FMASK_TILE_MAX(x) (((x) >> 12) & 0xFFFFF) +#define C_028100_FMASK_TILE_MAX 0x00000FFF +#define R_028104_CB_COLOR1_MASK 0x028104 +#define R_028108_CB_COLOR2_MASK 0x028108 +#define R_02810C_CB_COLOR3_MASK 0x02810C +#define R_028110_CB_COLOR4_MASK 0x028110 +#define R_028114_CB_COLOR5_MASK 0x028114 +#define R_028118_CB_COLOR6_MASK 0x028118 +#define R_02811C_CB_COLOR7_MASK 0x02811C +#define R_028040_CB_COLOR0_BASE 0x028040 +#define S_028040_BASE_256B(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028040_BASE_256B(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028040_BASE_256B 0x00000000 +#define R_0280E0_CB_COLOR0_FRAG 0x0280E0 +#define S_0280E0_BASE_256B(x) (((x) & 0xFFFFFFFF) << 0) +#define G_0280E0_BASE_256B(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_0280E0_BASE_256B 0x00000000 +#define R_0280E4_CB_COLOR1_FRAG 0x0280E4 +#define R_0280E8_CB_COLOR2_FRAG 0x0280E8 +#define R_0280EC_CB_COLOR3_FRAG 0x0280EC +#define R_0280F0_CB_COLOR4_FRAG 0x0280F0 +#define R_0280F4_CB_COLOR5_FRAG 0x0280F4 +#define R_0280F8_CB_COLOR6_FRAG 0x0280F8 +#define R_0280FC_CB_COLOR7_FRAG 0x0280FC +#define R_0280C0_CB_COLOR0_TILE 0x0280C0 +#define S_0280C0_BASE_256B(x) (((x) & 0xFFFFFFFF) << 0) +#define G_0280C0_BASE_256B(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_0280C0_BASE_256B 0x00000000 +#define R_0280C4_CB_COLOR1_TILE 0x0280C4 +#define R_0280C8_CB_COLOR2_TILE 0x0280C8 +#define R_0280CC_CB_COLOR3_TILE 0x0280CC +#define R_0280D0_CB_COLOR4_TILE 0x0280D0 +#define R_0280D4_CB_COLOR5_TILE 0x0280D4 +#define R_0280D8_CB_COLOR6_TILE 0x0280D8 +#define R_0280DC_CB_COLOR7_TILE 0x0280DC +#define R_028808_CB_COLOR_CONTROL 0x028808 +#define S_028808_FOG_ENABLE(x) (((x) & 0x1) << 0) +#define G_028808_FOG_ENABLE(x) (((x) >> 0) & 0x1) +#define C_028808_FOG_ENABLE 0xFFFFFFFE +#define S_028808_MULTIWRITE_ENABLE(x) (((x) & 0x1) << 1) +#define G_028808_MULTIWRITE_ENABLE(x) (((x) >> 1) & 0x1) +#define C_028808_MULTIWRITE_ENABLE 0xFFFFFFFD +#define S_028808_DITHER_ENABLE(x) (((x) & 0x1) << 2) +#define G_028808_DITHER_ENABLE(x) (((x) >> 2) & 0x1) +#define C_028808_DITHER_ENABLE 0xFFFFFFFB +#define S_028808_DEGAMMA_ENABLE(x) (((x) & 0x1) << 3) +#define G_028808_DEGAMMA_ENABLE(x) (((x) >> 3) & 0x1) +#define C_028808_DEGAMMA_ENABLE 0xFFFFFFF7 +#define S_028808_SPECIAL_OP(x) (((x) & 0x7) << 4) +#define G_028808_SPECIAL_OP(x) (((x) >> 4) & 0x7) +#define C_028808_SPECIAL_OP 0xFFFFFF8F +#define S_028808_PER_MRT_BLEND(x) (((x) & 0x1) << 7) +#define G_028808_PER_MRT_BLEND(x) (((x) >> 7) & 0x1) +#define C_028808_PER_MRT_BLEND 0xFFFFFF7F +#define S_028808_TARGET_BLEND_ENABLE(x) (((x) & 0xFF) << 8) +#define G_028808_TARGET_BLEND_ENABLE(x) (((x) >> 8) & 0xFF) +#define C_028808_TARGET_BLEND_ENABLE 0xFFFF00FF +#define S_028808_ROP3(x) (((x) & 0xFF) << 16) +#define G_028808_ROP3(x) (((x) >> 16) & 0xFF) +#define C_028808_ROP3 0xFF00FFFF +#define R_028614_SPI_VS_OUT_ID_0 0x028614 +#define S_028614_SEMANTIC_0(x) (((x) & 0xFF) << 0) +#define G_028614_SEMANTIC_0(x) (((x) >> 0) & 0xFF) +#define C_028614_SEMANTIC_0 0xFFFFFF00 +#define S_028614_SEMANTIC_1(x) (((x) & 0xFF) << 8) +#define G_028614_SEMANTIC_1(x) (((x) >> 8) & 0xFF) +#define C_028614_SEMANTIC_1 0xFFFF00FF +#define S_028614_SEMANTIC_2(x) (((x) & 0xFF) << 16) +#define G_028614_SEMANTIC_2(x) (((x) >> 16) & 0xFF) +#define C_028614_SEMANTIC_2 0xFF00FFFF +#define S_028614_SEMANTIC_3(x) (((x) & 0xFF) << 24) +#define G_028614_SEMANTIC_3(x) (((x) >> 24) & 0xFF) +#define C_028614_SEMANTIC_3 0x00FFFFFF +#define R_028618_SPI_VS_OUT_ID_1 0x028618 +#define R_02861C_SPI_VS_OUT_ID_2 0x02861C +#define R_028620_SPI_VS_OUT_ID_3 0x028620 +#define R_028624_SPI_VS_OUT_ID_4 0x028624 +#define R_028628_SPI_VS_OUT_ID_5 0x028628 +#define R_02862C_SPI_VS_OUT_ID_6 0x02862C +#define R_028630_SPI_VS_OUT_ID_7 0x028630 +#define R_028634_SPI_VS_OUT_ID_8 0x028634 +#define R_028638_SPI_VS_OUT_ID_9 0x028638 +#define R_038000_SQ_TEX_RESOURCE_WORD0_0 0x038000 +#define S_038000_DIM(x) (((x) & 0x7) << 0) +#define G_038000_DIM(x) (((x) >> 0) & 0x7) +#define C_038000_DIM 0xFFFFFFF8 +#define S_038000_TILE_MODE(x) (((x) & 0xF) << 3) +#define G_038000_TILE_MODE(x) (((x) >> 3) & 0xF) +#define C_038000_TILE_MODE 0xFFFFFF87 +#define S_038000_TILE_TYPE(x) (((x) & 0x1) << 7) +#define G_038000_TILE_TYPE(x) (((x) >> 7) & 0x1) +#define C_038000_TILE_TYPE 0xFFFFFF7F +#define S_038000_PITCH(x) (((x) & 0x7FF) << 8) +#define G_038000_PITCH(x) (((x) >> 8) & 0x7FF) +#define C_038000_PITCH 0xFFF800FF +#define S_038000_TEX_WIDTH(x) (((x) & 0x1FFF) << 19) +#define G_038000_TEX_WIDTH(x) (((x) >> 19) & 0x1FFF) +#define C_038000_TEX_WIDTH 0x0007FFFF +#define R_038004_SQ_TEX_RESOURCE_WORD1_0 0x038004 +#define S_038004_TEX_HEIGHT(x) (((x) & 0x1FFF) << 0) +#define G_038004_TEX_HEIGHT(x) (((x) >> 0) & 0x1FFF) +#define C_038004_TEX_HEIGHT 0xFFFFE000 +#define S_038004_TEX_DEPTH(x) (((x) & 0x1FFF) << 13) +#define G_038004_TEX_DEPTH(x) (((x) >> 13) & 0x1FFF) +#define C_038004_TEX_DEPTH 0xFC001FFF +#define S_038004_DATA_FORMAT(x) (((x) & 0x3F) << 26) +#define G_038004_DATA_FORMAT(x) (((x) >> 26) & 0x3F) +#define C_038004_DATA_FORMAT 0x03FFFFFF +#define V_038004_COLOR_INVALID 0x00000000 +#define V_038004_COLOR_8 0x00000001 +#define V_038004_COLOR_4_4 0x00000002 +#define V_038004_COLOR_3_3_2 0x00000003 +#define V_038004_COLOR_16 0x00000005 +#define V_038004_COLOR_16_FLOAT 0x00000006 +#define V_038004_COLOR_8_8 0x00000007 +#define V_038004_COLOR_5_6_5 0x00000008 +#define V_038004_COLOR_6_5_5 0x00000009 +#define V_038004_COLOR_1_5_5_5 0x0000000A +#define V_038004_COLOR_4_4_4_4 0x0000000B +#define V_038004_COLOR_5_5_5_1 0x0000000C +#define V_038004_COLOR_32 0x0000000D +#define V_038004_COLOR_32_FLOAT 0x0000000E +#define V_038004_COLOR_16_16 0x0000000F +#define V_038004_COLOR_16_16_FLOAT 0x00000010 +#define V_038004_COLOR_8_24 0x00000011 +#define V_038004_COLOR_8_24_FLOAT 0x00000012 +#define V_038004_COLOR_24_8 0x00000013 +#define V_038004_COLOR_24_8_FLOAT 0x00000014 +#define V_038004_COLOR_10_11_11 0x00000015 +#define V_038004_COLOR_10_11_11_FLOAT 0x00000016 +#define V_038004_COLOR_11_11_10 0x00000017 +#define V_038004_COLOR_11_11_10_FLOAT 0x00000018 +#define V_038004_COLOR_2_10_10_10 0x00000019 +#define V_038004_COLOR_8_8_8_8 0x0000001A +#define V_038004_COLOR_10_10_10_2 0x0000001B +#define V_038004_COLOR_X24_8_32_FLOAT 0x0000001C +#define V_038004_COLOR_32_32 0x0000001D +#define V_038004_COLOR_32_32_FLOAT 0x0000001E +#define V_038004_COLOR_16_16_16_16 0x0000001F +#define V_038004_COLOR_16_16_16_16_FLOAT 0x00000020 +#define V_038004_COLOR_32_32_32_32 0x00000022 +#define V_038004_COLOR_32_32_32_32_FLOAT 0x00000023 +#define R_038008_SQ_TEX_RESOURCE_WORD2_0 0x038008 +#define S_038008_BASE_ADDRESS(x) (((x) & 0xFFFFFFFF) << 0) +#define G_038008_BASE_ADDRESS(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_038008_BASE_ADDRESS 0x00000000 +#define R_03800C_SQ_TEX_RESOURCE_WORD3_0 0x03800C +#define S_03800C_MIP_ADDRESS(x) (((x) & 0xFFFFFFFF) << 0) +#define G_03800C_MIP_ADDRESS(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_03800C_MIP_ADDRESS 0x00000000 +#define R_038010_SQ_TEX_RESOURCE_WORD4_0 0x038010 +#define S_038010_FORMAT_COMP_X(x) (((x) & 0x3) << 0) +#define G_038010_FORMAT_COMP_X(x) (((x) >> 0) & 0x3) +#define C_038010_FORMAT_COMP_X 0xFFFFFFFC +#define S_038010_FORMAT_COMP_Y(x) (((x) & 0x3) << 2) +#define G_038010_FORMAT_COMP_Y(x) (((x) >> 2) & 0x3) +#define C_038010_FORMAT_COMP_Y 0xFFFFFFF3 +#define S_038010_FORMAT_COMP_Z(x) (((x) & 0x3) << 4) +#define G_038010_FORMAT_COMP_Z(x) (((x) >> 4) & 0x3) +#define C_038010_FORMAT_COMP_Z 0xFFFFFFCF +#define S_038010_FORMAT_COMP_W(x) (((x) & 0x3) << 6) +#define G_038010_FORMAT_COMP_W(x) (((x) >> 6) & 0x3) +#define C_038010_FORMAT_COMP_W 0xFFFFFF3F +#define S_038010_NUM_FORMAT_ALL(x) (((x) & 0x3) << 8) +#define G_038010_NUM_FORMAT_ALL(x) (((x) >> 8) & 0x3) +#define C_038010_NUM_FORMAT_ALL 0xFFFFFCFF +#define S_038010_SRF_MODE_ALL(x) (((x) & 0x1) << 10) +#define G_038010_SRF_MODE_ALL(x) (((x) >> 10) & 0x1) +#define C_038010_SRF_MODE_ALL 0xFFFFFBFF +#define S_038010_FORCE_DEGAMMA(x) (((x) & 0x1) << 11) +#define G_038010_FORCE_DEGAMMA(x) (((x) >> 11) & 0x1) +#define C_038010_FORCE_DEGAMMA 0xFFFFF7FF +#define S_038010_ENDIAN_SWAP(x) (((x) & 0x3) << 12) +#define G_038010_ENDIAN_SWAP(x) (((x) >> 12) & 0x3) +#define C_038010_ENDIAN_SWAP 0xFFFFCFFF +#define S_038010_REQUEST_SIZE(x) (((x) & 0x3) << 14) +#define G_038010_REQUEST_SIZE(x) (((x) >> 14) & 0x3) +#define C_038010_REQUEST_SIZE 0xFFFF3FFF +#define S_038010_DST_SEL_X(x) (((x) & 0x7) << 16) +#define G_038010_DST_SEL_X(x) (((x) >> 16) & 0x7) +#define C_038010_DST_SEL_X 0xFFF8FFFF +#define S_038010_DST_SEL_Y(x) (((x) & 0x7) << 19) +#define G_038010_DST_SEL_Y(x) (((x) >> 19) & 0x7) +#define C_038010_DST_SEL_Y 0xFFC7FFFF +#define S_038010_DST_SEL_Z(x) (((x) & 0x7) << 22) +#define G_038010_DST_SEL_Z(x) (((x) >> 22) & 0x7) +#define C_038010_DST_SEL_Z 0xFE3FFFFF +#define S_038010_DST_SEL_W(x) (((x) & 0x7) << 25) +#define G_038010_DST_SEL_W(x) (((x) >> 25) & 0x7) +#define C_038010_DST_SEL_W 0xF1FFFFFF +#define S_038010_BASE_LEVEL(x) (((x) & 0xF) << 28) +#define G_038010_BASE_LEVEL(x) (((x) >> 28) & 0xF) +#define C_038010_BASE_LEVEL 0x0FFFFFFF +#define R_038014_SQ_TEX_RESOURCE_WORD5_0 0x038014 +#define S_038014_LAST_LEVEL(x) (((x) & 0xF) << 0) +#define G_038014_LAST_LEVEL(x) (((x) >> 0) & 0xF) +#define C_038014_LAST_LEVEL 0xFFFFFFF0 +#define S_038014_BASE_ARRAY(x) (((x) & 0x1FFF) << 4) +#define G_038014_BASE_ARRAY(x) (((x) >> 4) & 0x1FFF) +#define C_038014_BASE_ARRAY 0xFFFE000F +#define S_038014_LAST_ARRAY(x) (((x) & 0x1FFF) << 17) +#define G_038014_LAST_ARRAY(x) (((x) >> 17) & 0x1FFF) +#define C_038014_LAST_ARRAY 0xC001FFFF +#define R_038018_SQ_TEX_RESOURCE_WORD6_0 0x038018 +#define S_038018_MPEG_CLAMP(x) (((x) & 0x3) << 0) +#define G_038018_MPEG_CLAMP(x) (((x) >> 0) & 0x3) +#define C_038018_MPEG_CLAMP 0xFFFFFFFC +#define S_038018_PERF_MODULATION(x) (((x) & 0x7) << 5) +#define G_038018_PERF_MODULATION(x) (((x) >> 5) & 0x7) +#define C_038018_PERF_MODULATION 0xFFFFFF1F +#define S_038018_INTERLACED(x) (((x) & 0x1) << 8) +#define G_038018_INTERLACED(x) (((x) >> 8) & 0x1) +#define C_038018_INTERLACED 0xFFFFFEFF +#define S_038018_TYPE(x) (((x) & 0x3) << 30) +#define G_038018_TYPE(x) (((x) >> 30) & 0x3) +#define C_038018_TYPE 0x3FFFFFFF +#define R_008040_WAIT_UNTIL 0x008040 +#define S_008040_WAIT_CP_DMA_IDLE(x) (((x) & 0x1) << 8) +#define G_008040_WAIT_CP_DMA_IDLE(x) (((x) >> 8) & 0x1) +#define C_008040_WAIT_CP_DMA_IDLE 0xFFFFFEFF +#define S_008040_WAIT_CMDFIFO(x) (((x) & 0x1) << 10) +#define G_008040_WAIT_CMDFIFO(x) (((x) >> 10) & 0x1) +#define C_008040_WAIT_CMDFIFO 0xFFFFFBFF +#define S_008040_WAIT_2D_IDLE(x) (((x) & 0x1) << 14) +#define G_008040_WAIT_2D_IDLE(x) (((x) >> 14) & 0x1) +#define C_008040_WAIT_2D_IDLE 0xFFFFBFFF +#define S_008040_WAIT_3D_IDLE(x) (((x) & 0x1) << 15) +#define G_008040_WAIT_3D_IDLE(x) (((x) >> 15) & 0x1) +#define C_008040_WAIT_3D_IDLE 0xFFFF7FFF +#define S_008040_WAIT_2D_IDLECLEAN(x) (((x) & 0x1) << 16) +#define G_008040_WAIT_2D_IDLECLEAN(x) (((x) >> 16) & 0x1) +#define C_008040_WAIT_2D_IDLECLEAN 0xFFFEFFFF +#define S_008040_WAIT_3D_IDLECLEAN(x) (((x) & 0x1) << 17) +#define G_008040_WAIT_3D_IDLECLEAN(x) (((x) >> 17) & 0x1) +#define C_008040_WAIT_3D_IDLECLEAN 0xFFFDFFFF +#define S_008040_WAIT_EXTERN_SIG(x) (((x) & 0x1) << 19) +#define G_008040_WAIT_EXTERN_SIG(x) (((x) >> 19) & 0x1) +#define C_008040_WAIT_EXTERN_SIG 0xFFF7FFFF +#define S_008040_CMDFIFO_ENTRIES(x) (((x) & 0x1F) << 20) +#define G_008040_CMDFIFO_ENTRIES(x) (((x) >> 20) & 0x1F) +#define C_008040_CMDFIFO_ENTRIES 0xFE0FFFFF +#define R_008958_VGT_PRIMITIVE_TYPE 0x008958 +#define S_008958_PRIM_TYPE(x) (((x) & 0x3F) << 0) +#define G_008958_PRIM_TYPE(x) (((x) >> 0) & 0x3F) +#define C_008958_PRIM_TYPE 0xFFFFFFC0 +#define R_008C00_SQ_CONFIG 0x008C00 +#define S_008C00_VC_ENABLE(x) (((x) & 0x1) << 0) +#define G_008C00_VC_ENABLE(x) (((x) >> 0) & 0x1) +#define C_008C00_VC_ENABLE 0xFFFFFFFE +#define S_008C00_EXPORT_SRC_C(x) (((x) & 0x1) << 1) +#define G_008C00_EXPORT_SRC_C(x) (((x) >> 1) & 0x1) +#define C_008C00_EXPORT_SRC_C 0xFFFFFFFD +#define S_008C00_DX9_CONSTS(x) (((x) & 0x1) << 2) +#define G_008C00_DX9_CONSTS(x) (((x) >> 2) & 0x1) +#define C_008C00_DX9_CONSTS 0xFFFFFFFB +#define S_008C00_ALU_INST_PREFER_VECTOR(x) (((x) & 0x1) << 3) +#define G_008C00_ALU_INST_PREFER_VECTOR(x) (((x) >> 3) & 0x1) +#define C_008C00_ALU_INST_PREFER_VECTOR 0xFFFFFFF7 +#define S_008C00_DX10_CLAMP(x) (((x) & 0x1) << 4) +#define G_008C00_DX10_CLAMP(x) (((x) >> 4) & 0x1) +#define C_008C00_DX10_CLAMP 0xFFFFFFEF +#define S_008C00_ALU_PREFER_ONE_WATERFALL(x) (((x) & 0x1) << 5) +#define G_008C00_ALU_PREFER_ONE_WATERFALL(x) (((x) >> 5) & 0x1) +#define C_008C00_ALU_PREFER_ONE_WATERFALL 0xFFFFFFDF +#define S_008C00_ALU_MAX_ONE_WATERFALL(x) (((x) & 0x1) << 6) +#define G_008C00_ALU_MAX_ONE_WATERFALL(x) (((x) >> 6) & 0x1) +#define C_008C00_ALU_MAX_ONE_WATERFALL 0xFFFFFFBF +#define S_008C00_CLAUSE_SEQ_PRIO(x) (((x) & 0x3) << 8) +#define G_008C00_CLAUSE_SEQ_PRIO(x) (((x) >> 8) & 0x3) +#define C_008C00_CLAUSE_SEQ_PRIO 0xFFFFFCFF +#define S_008C00_PS_PRIO(x) (((x) & 0x3) << 24) +#define G_008C00_PS_PRIO(x) (((x) >> 24) & 0x3) +#define C_008C00_PS_PRIO 0xFCFFFFFF +#define S_008C00_VS_PRIO(x) (((x) & 0x3) << 26) +#define G_008C00_VS_PRIO(x) (((x) >> 26) & 0x3) +#define C_008C00_VS_PRIO 0xF3FFFFFF +#define S_008C00_GS_PRIO(x) (((x) & 0x3) << 28) +#define G_008C00_GS_PRIO(x) (((x) >> 28) & 0x3) +#define C_008C00_GS_PRIO 0xCFFFFFFF +#define S_008C00_ES_PRIO(x) (((x) & 0x3) << 30) +#define G_008C00_ES_PRIO(x) (((x) >> 30) & 0x3) +#define C_008C00_ES_PRIO 0x3FFFFFFF +#define R_008C04_SQ_GPR_RESOURCE_MGMT_1 0x008C04 +#define S_008C04_NUM_PS_GPRS(x) (((x) & 0xFF) << 0) +#define G_008C04_NUM_PS_GPRS(x) (((x) >> 0) & 0xFF) +#define C_008C04_NUM_PS_GPRS 0xFFFFFF00 +#define S_008C04_NUM_VS_GPRS(x) (((x) & 0xFF) << 16) +#define G_008C04_NUM_VS_GPRS(x) (((x) >> 16) & 0xFF) +#define C_008C04_NUM_VS_GPRS 0xFF00FFFF +#define S_008C04_NUM_CLAUSE_TEMP_GPRS(x) (((x) & 0xF) << 28) +#define G_008C04_NUM_CLAUSE_TEMP_GPRS(x) (((x) >> 28) & 0xF) +#define C_008C04_NUM_CLAUSE_TEMP_GPRS 0x0FFFFFFF +#define R_008C08_SQ_GPR_RESOURCE_MGMT_2 0x008C08 +#define S_008C08_NUM_GS_GPRS(x) (((x) & 0xFF) << 0) +#define G_008C08_NUM_GS_GPRS(x) (((x) >> 0) & 0xFF) +#define C_008C08_NUM_GS_GPRS 0xFFFFFF00 +#define S_008C08_NUM_ES_GPRS(x) (((x) & 0xFF) << 16) +#define G_008C08_NUM_ES_GPRS(x) (((x) >> 16) & 0xFF) +#define C_008C08_NUM_ES_GPRS 0xFF00FFFF +#define R_008C0C_SQ_THREAD_RESOURCE_MGMT 0x008C0C +#define S_008C0C_NUM_PS_THREADS(x) (((x) & 0xFF) << 0) +#define G_008C0C_NUM_PS_THREADS(x) (((x) >> 0) & 0xFF) +#define C_008C0C_NUM_PS_THREADS 0xFFFFFF00 +#define S_008C0C_NUM_VS_THREADS(x) (((x) & 0xFF) << 8) +#define G_008C0C_NUM_VS_THREADS(x) (((x) >> 8) & 0xFF) +#define C_008C0C_NUM_VS_THREADS 0xFFFF00FF +#define S_008C0C_NUM_GS_THREADS(x) (((x) & 0xFF) << 16) +#define G_008C0C_NUM_GS_THREADS(x) (((x) >> 16) & 0xFF) +#define C_008C0C_NUM_GS_THREADS 0xFF00FFFF +#define S_008C0C_NUM_ES_THREADS(x) (((x) & 0xFF) << 24) +#define G_008C0C_NUM_ES_THREADS(x) (((x) >> 24) & 0xFF) +#define C_008C0C_NUM_ES_THREADS 0x00FFFFFF +#define R_008C10_SQ_STACK_RESOURCE_MGMT_1 0x008C10 +#define S_008C10_NUM_PS_STACK_ENTRIES(x) (((x) & 0xFFF) << 0) +#define G_008C10_NUM_PS_STACK_ENTRIES(x) (((x) >> 0) & 0xFFF) +#define C_008C10_NUM_PS_STACK_ENTRIES 0xFFFFF000 +#define S_008C10_NUM_VS_STACK_ENTRIES(x) (((x) & 0xFFF) << 16) +#define G_008C10_NUM_VS_STACK_ENTRIES(x) (((x) >> 16) & 0xFFF) +#define C_008C10_NUM_VS_STACK_ENTRIES 0xF000FFFF +#define R_008C14_SQ_STACK_RESOURCE_MGMT_2 0x008C14 +#define S_008C14_NUM_GS_STACK_ENTRIES(x) (((x) & 0xFFF) << 0) +#define G_008C14_NUM_GS_STACK_ENTRIES(x) (((x) >> 0) & 0xFFF) +#define C_008C14_NUM_GS_STACK_ENTRIES 0xFFFFF000 +#define S_008C14_NUM_ES_STACK_ENTRIES(x) (((x) & 0xFFF) << 16) +#define G_008C14_NUM_ES_STACK_ENTRIES(x) (((x) >> 16) & 0xFFF) +#define C_008C14_NUM_ES_STACK_ENTRIES 0xF000FFFF +#define R_008D8C_SQ_DYN_GPR_CNTL_PS_FLUSH_REQ 0x008D8C +#define S_008D8C_RING0_OFFSET(x) (((x) & 0xFF) << 0) +#define G_008D8C_RING0_OFFSET(x) (((x) >> 0) & 0xFF) +#define C_008D8C_RING0_OFFSET 0xFFFFFF00 +#define S_008D8C_ISOLATE_ES_ENABLE(x) (((x) & 0x1) << 12) +#define G_008D8C_ISOLATE_ES_ENABLE(x) (((x) >> 12) & 0x1) +#define C_008D8C_ISOLATE_ES_ENABLE 0xFFFFEFFF +#define S_008D8C_ISOLATE_GS_ENABLE(x) (((x) & 0x1) << 13) +#define G_008D8C_ISOLATE_GS_ENABLE(x) (((x) >> 13) & 0x1) +#define C_008D8C_ISOLATE_GS_ENABLE 0xFFFFDFFF +#define S_008D8C_VS_PC_LIMIT_ENABLE(x) (((x) & 0x1) << 14) +#define G_008D8C_VS_PC_LIMIT_ENABLE(x) (((x) >> 14) & 0x1) +#define C_008D8C_VS_PC_LIMIT_ENABLE 0xFFFFBFFF +#define R_009508_TA_CNTL_AUX 0x009508 +#define S_009508_DISABLE_CUBE_WRAP(x) (((x) & 0x1) << 0) +#define G_009508_DISABLE_CUBE_WRAP(x) (((x) >> 0) & 0x1) +#define C_009508_DISABLE_CUBE_WRAP 0xFFFFFFFE +#define S_009508_SYNC_GRADIENT(x) (((x) & 0x1) << 24) +#define G_009508_SYNC_GRADIENT(x) (((x) >> 24) & 0x1) +#define C_009508_SYNC_GRADIENT 0xFEFFFFFF +#define S_009508_SYNC_WALKER(x) (((x) & 0x1) << 25) +#define G_009508_SYNC_WALKER(x) (((x) >> 25) & 0x1) +#define C_009508_SYNC_WALKER 0xFDFFFFFF +#define S_009508_SYNC_ALIGNER(x) (((x) & 0x1) << 26) +#define G_009508_SYNC_ALIGNER(x) (((x) >> 26) & 0x1) +#define C_009508_SYNC_ALIGNER 0xFBFFFFFF +#define S_009508_BILINEAR_PRECISION(x) (((x) & 0x1) << 31) +#define G_009508_BILINEAR_PRECISION(x) (((x) >> 31) & 0x1) +#define C_009508_BILINEAR_PRECISION 0x7FFFFFFF +#define R_009714_VC_ENHANCE 0x009714 +#define R_009830_DB_DEBUG 0x009830 +#define R_009838_DB_WATERMARKS 0x009838 +#define S_009838_DEPTH_FREE(x) (((x) & 0x1F) << 0) +#define G_009838_DEPTH_FREE(x) (((x) >> 0) & 0x1F) +#define C_009838_DEPTH_FREE 0xFFFFFFE0 +#define S_009838_DEPTH_FLUSH(x) (((x) & 0x3F) << 5) +#define G_009838_DEPTH_FLUSH(x) (((x) >> 5) & 0x3F) +#define C_009838_DEPTH_FLUSH 0xFFFFF81F +#define S_009838_FORCE_SUMMARIZE(x) (((x) & 0xF) << 11) +#define G_009838_FORCE_SUMMARIZE(x) (((x) >> 11) & 0xF) +#define C_009838_FORCE_SUMMARIZE 0xFFFF87FF +#define S_009838_DEPTH_PENDING_FREE(x) (((x) & 0x1F) << 15) +#define G_009838_DEPTH_PENDING_FREE(x) (((x) >> 15) & 0x1F) +#define C_009838_DEPTH_PENDING_FREE 0xFFF07FFF +#define S_009838_DEPTH_CACHELINE_FREE(x) (((x) & 0x1F) << 20) +#define G_009838_DEPTH_CACHELINE_FREE(x) (((x) >> 20) & 0x1F) +#define C_009838_DEPTH_CACHELINE_FREE 0xFE0FFFFF +#define S_009838_EARLY_Z_PANIC_DISABLE(x) (((x) & 0x1) << 25) +#define G_009838_EARLY_Z_PANIC_DISABLE(x) (((x) >> 25) & 0x1) +#define C_009838_EARLY_Z_PANIC_DISABLE 0xFDFFFFFF +#define S_009838_LATE_Z_PANIC_DISABLE(x) (((x) & 0x1) << 26) +#define G_009838_LATE_Z_PANIC_DISABLE(x) (((x) >> 26) & 0x1) +#define C_009838_LATE_Z_PANIC_DISABLE 0xFBFFFFFF +#define S_009838_RE_Z_PANIC_DISABLE(x) (((x) & 0x1) << 27) +#define G_009838_RE_Z_PANIC_DISABLE(x) (((x) >> 27) & 0x1) +#define C_009838_RE_Z_PANIC_DISABLE 0xF7FFFFFF +#define S_009838_DB_EXTRA_DEBUG(x) (((x) & 0xF) << 28) +#define G_009838_DB_EXTRA_DEBUG(x) (((x) >> 28) & 0xF) +#define C_009838_DB_EXTRA_DEBUG 0x0FFFFFFF +#define R_028030_PA_SC_SCREEN_SCISSOR_TL 0x028030 +#define S_028030_TL_X(x) (((x) & 0x7FFF) << 0) +#define G_028030_TL_X(x) (((x) >> 0) & 0x7FFF) +#define C_028030_TL_X 0xFFFF8000 +#define S_028030_TL_Y(x) (((x) & 0x7FFF) << 16) +#define G_028030_TL_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028030_TL_Y 0x8000FFFF +#define R_028034_PA_SC_SCREEN_SCISSOR_BR 0x028034 +#define S_028034_BR_X(x) (((x) & 0x7FFF) << 0) +#define G_028034_BR_X(x) (((x) >> 0) & 0x7FFF) +#define C_028034_BR_X 0xFFFF8000 +#define S_028034_BR_Y(x) (((x) & 0x7FFF) << 16) +#define G_028034_BR_Y(x) (((x) >> 16) & 0x7FFF) +#define C_028034_BR_Y 0x8000FFFF +#define R_028200_PA_SC_WINDOW_OFFSET 0x028200 +#define S_028200_WINDOW_X_OFFSET(x) (((x) & 0x7FFF) << 0) +#define G_028200_WINDOW_X_OFFSET(x) (((x) >> 0) & 0x7FFF) +#define C_028200_WINDOW_X_OFFSET 0xFFFF8000 +#define S_028200_WINDOW_Y_OFFSET(x) (((x) & 0x7FFF) << 16) +#define G_028200_WINDOW_Y_OFFSET(x) (((x) >> 16) & 0x7FFF) +#define C_028200_WINDOW_Y_OFFSET 0x8000FFFF +#define R_028204_PA_SC_WINDOW_SCISSOR_TL 0x028204 +#define S_028204_TL_X(x) (((x) & 0x3FFF) << 0) +#define G_028204_TL_X(x) (((x) >> 0) & 0x3FFF) +#define C_028204_TL_X 0xFFFFC000 +#define S_028204_TL_Y(x) (((x) & 0x3FFF) << 16) +#define G_028204_TL_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028204_TL_Y 0xC000FFFF +#define S_028204_WINDOW_OFFSET_DISABLE(x) (((x) & 0x1) << 31) +#define G_028204_WINDOW_OFFSET_DISABLE(x) (((x) >> 31) & 0x1) +#define C_028204_WINDOW_OFFSET_DISABLE 0x7FFFFFFF +#define R_028208_PA_SC_WINDOW_SCISSOR_BR 0x028208 +#define S_028208_BR_X(x) (((x) & 0x3FFF) << 0) +#define G_028208_BR_X(x) (((x) >> 0) & 0x3FFF) +#define C_028208_BR_X 0xFFFFC000 +#define S_028208_BR_Y(x) (((x) & 0x3FFF) << 16) +#define G_028208_BR_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028208_BR_Y 0xC000FFFF +#define R_02820C_PA_SC_CLIPRECT_RULE 0x02820C +#define S_02820C_CLIP_RULE(x) (((x) & 0xFFFF) << 0) +#define G_02820C_CLIP_RULE(x) (((x) >> 0) & 0xFFFF) +#define C_02820C_CLIP_RULE 0xFFFF0000 +#define R_028210_PA_SC_CLIPRECT_0_TL 0x028210 +#define S_028210_TL_X(x) (((x) & 0x3FFF) << 0) +#define G_028210_TL_X(x) (((x) >> 0) & 0x3FFF) +#define C_028210_TL_X 0xFFFFC000 +#define S_028210_TL_Y(x) (((x) & 0x3FFF) << 16) +#define G_028210_TL_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028210_TL_Y 0xC000FFFF +#define R_028214_PA_SC_CLIPRECT_0_BR 0x028214 +#define S_028214_BR_X(x) (((x) & 0x3FFF) << 0) +#define G_028214_BR_X(x) (((x) >> 0) & 0x3FFF) +#define C_028214_BR_X 0xFFFFC000 +#define S_028214_BR_Y(x) (((x) & 0x3FFF) << 16) +#define G_028214_BR_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028214_BR_Y 0xC000FFFF +#define R_028218_PA_SC_CLIPRECT_1_TL 0x028218 +#define R_02821C_PA_SC_CLIPRECT_1_BR 0x02821C +#define R_028220_PA_SC_CLIPRECT_2_TL 0x028220 +#define R_028224_PA_SC_CLIPRECT_2_BR 0x028224 +#define R_028228_PA_SC_CLIPRECT_3_TL 0x028228 +#define R_02822C_PA_SC_CLIPRECT_3_BR 0x02822C +#define R_028230_PA_SC_EDGERULE 0x028230 +#define R_028240_PA_SC_GENERIC_SCISSOR_TL 0x028240 +#define S_028240_TL_X(x) (((x) & 0x3FFF) << 0) +#define G_028240_TL_X(x) (((x) >> 0) & 0x3FFF) +#define C_028240_TL_X 0xFFFFC000 +#define S_028240_TL_Y(x) (((x) & 0x3FFF) << 16) +#define G_028240_TL_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028240_TL_Y 0xC000FFFF +#define S_028240_WINDOW_OFFSET_DISABLE(x) (((x) & 0x1) << 31) +#define G_028240_WINDOW_OFFSET_DISABLE(x) (((x) >> 31) & 0x1) +#define C_028240_WINDOW_OFFSET_DISABLE 0x7FFFFFFF +#define R_028244_PA_SC_GENERIC_SCISSOR_BR 0x028244 +#define S_028244_BR_X(x) (((x) & 0x3FFF) << 0) +#define G_028244_BR_X(x) (((x) >> 0) & 0x3FFF) +#define C_028244_BR_X 0xFFFFC000 +#define S_028244_BR_Y(x) (((x) & 0x3FFF) << 16) +#define G_028244_BR_Y(x) (((x) >> 16) & 0x3FFF) +#define C_028244_BR_Y 0xC000FFFF +#define R_0282D0_PA_SC_VPORT_ZMIN_0 0x0282D0 +#define S_0282D0_VPORT_ZMIN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_0282D0_VPORT_ZMIN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_0282D0_VPORT_ZMIN 0x00000000 +#define R_0282D4_PA_SC_VPORT_ZMAX_0 0x0282D4 +#define S_0282D4_VPORT_ZMAX(x) (((x) & 0xFFFFFFFF) << 0) +#define G_0282D4_VPORT_ZMAX(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_0282D4_VPORT_ZMAX 0x00000000 +#define R_028350_SX_MISC 0x028350 +#define S_028350_MULTIPASS(x) (((x) & 0x1) << 0) +#define G_028350_MULTIPASS(x) (((x) >> 0) & 0x1) +#define C_028350_MULTIPASS 0xFFFFFFFE +#define R_028380_SQ_VTX_SEMANTIC_0 0x028380 +#define S_028380_SEMANTIC_ID(x) (((x) & 0xFF) << 0) +#define G_028380_SEMANTIC_ID(x) (((x) >> 0) & 0xFF) +#define C_028380_SEMANTIC_ID 0xFFFFFF00 +#define R_028384_SQ_VTX_SEMANTIC_1 0x028384 +#define R_028388_SQ_VTX_SEMANTIC_2 0x028388 +#define R_02838C_SQ_VTX_SEMANTIC_3 0x02838C +#define R_028390_SQ_VTX_SEMANTIC_4 0x028390 +#define R_028394_SQ_VTX_SEMANTIC_5 0x028394 +#define R_028398_SQ_VTX_SEMANTIC_6 0x028398 +#define R_02839C_SQ_VTX_SEMANTIC_7 0x02839C +#define R_0283A0_SQ_VTX_SEMANTIC_8 0x0283A0 +#define R_0283A4_SQ_VTX_SEMANTIC_9 0x0283A4 +#define R_0283A8_SQ_VTX_SEMANTIC_10 0x0283A8 +#define R_0283AC_SQ_VTX_SEMANTIC_11 0x0283AC +#define R_0283B0_SQ_VTX_SEMANTIC_12 0x0283B0 +#define R_0283B4_SQ_VTX_SEMANTIC_13 0x0283B4 +#define R_0283B8_SQ_VTX_SEMANTIC_14 0x0283B8 +#define R_0283BC_SQ_VTX_SEMANTIC_15 0x0283BC +#define R_0283C0_SQ_VTX_SEMANTIC_16 0x0283C0 +#define R_0283C4_SQ_VTX_SEMANTIC_17 0x0283C4 +#define R_0283C8_SQ_VTX_SEMANTIC_18 0x0283C8 +#define R_0283CC_SQ_VTX_SEMANTIC_19 0x0283CC +#define R_0283D0_SQ_VTX_SEMANTIC_20 0x0283D0 +#define R_0283D4_SQ_VTX_SEMANTIC_21 0x0283D4 +#define R_0283D8_SQ_VTX_SEMANTIC_22 0x0283D8 +#define R_0283DC_SQ_VTX_SEMANTIC_23 0x0283DC +#define R_0283E0_SQ_VTX_SEMANTIC_24 0x0283E0 +#define R_0283E4_SQ_VTX_SEMANTIC_25 0x0283E4 +#define R_0283E8_SQ_VTX_SEMANTIC_26 0x0283E8 +#define R_0283EC_SQ_VTX_SEMANTIC_27 0x0283EC +#define R_0283F0_SQ_VTX_SEMANTIC_28 0x0283F0 +#define R_0283F4_SQ_VTX_SEMANTIC_29 0x0283F4 +#define R_0283F8_SQ_VTX_SEMANTIC_30 0x0283F8 +#define R_0283FC_SQ_VTX_SEMANTIC_31 0x0283FC +#define R_028400_VGT_MAX_VTX_INDX 0x028400 +#define S_028400_MAX_INDX(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028400_MAX_INDX(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028400_MAX_INDX 0x00000000 +#define R_028404_VGT_MIN_VTX_INDX 0x028404 +#define S_028404_MIN_INDX(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028404_MIN_INDX(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028404_MIN_INDX 0x00000000 +#define R_028408_VGT_INDX_OFFSET 0x028408 +#define S_028408_INDX_OFFSET(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028408_INDX_OFFSET(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028408_INDX_OFFSET 0x00000000 +#define R_02840C_VGT_MULTI_PRIM_IB_RESET_INDX 0x02840C +#define S_02840C_RESET_INDX(x) (((x) & 0xFFFFFFFF) << 0) +#define G_02840C_RESET_INDX(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_02840C_RESET_INDX 0x00000000 +#define R_028410_SX_ALPHA_TEST_CONTROL 0x028410 +#define S_028410_ALPHA_FUNC(x) (((x) & 0x7) << 0) +#define G_028410_ALPHA_FUNC(x) (((x) >> 0) & 0x7) +#define C_028410_ALPHA_FUNC 0xFFFFFFF8 +#define S_028410_ALPHA_TEST_ENABLE(x) (((x) & 0x1) << 3) +#define G_028410_ALPHA_TEST_ENABLE(x) (((x) >> 3) & 0x1) +#define C_028410_ALPHA_TEST_ENABLE 0xFFFFFFF7 +#define S_028410_ALPHA_TEST_BYPASS(x) (((x) & 0x1) << 8) +#define G_028410_ALPHA_TEST_BYPASS(x) (((x) >> 8) & 0x1) +#define C_028410_ALPHA_TEST_BYPASS 0xFFFFFEFF +#define R_028414_CB_BLEND_RED 0x028414 +#define S_028414_BLEND_RED(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028414_BLEND_RED(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028414_BLEND_RED 0x00000000 +#define R_028418_CB_BLEND_GREEN 0x028418 +#define S_028418_BLEND_GREEN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028418_BLEND_GREEN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028418_BLEND_GREEN 0x00000000 +#define R_02841C_CB_BLEND_BLUE 0x02841C +#define S_02841C_BLEND_BLUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_02841C_BLEND_BLUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_02841C_BLEND_BLUE 0x00000000 +#define R_028420_CB_BLEND_ALPHA 0x028420 +#define S_028420_BLEND_ALPHA(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028420_BLEND_ALPHA(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028420_BLEND_ALPHA 0x00000000 +#define R_028438_SX_ALPHA_REF 0x028438 +#define S_028438_ALPHA_REF(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028438_ALPHA_REF(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028438_ALPHA_REF 0x00000000 +#define R_0286C8_SPI_THREAD_GROUPING 0x0286C8 +#define S_0286C8_PS_GROUPING(x) (((x) & 0x1F) << 0) +#define G_0286C8_PS_GROUPING(x) (((x) >> 0) & 0x1F) +#define C_0286C8_PS_GROUPING 0xFFFFFFE0 +#define S_0286C8_VS_GROUPING(x) (((x) & 0x1F) << 8) +#define G_0286C8_VS_GROUPING(x) (((x) >> 8) & 0x1F) +#define C_0286C8_VS_GROUPING 0xFFFFE0FF +#define S_0286C8_GS_GROUPING(x) (((x) & 0x1F) << 16) +#define G_0286C8_GS_GROUPING(x) (((x) >> 16) & 0x1F) +#define C_0286C8_GS_GROUPING 0xFFE0FFFF +#define S_0286C8_ES_GROUPING(x) (((x) & 0x1F) << 24) +#define G_0286C8_ES_GROUPING(x) (((x) >> 24) & 0x1F) +#define C_0286C8_ES_GROUPING 0xE0FFFFFF +#define R_0286D8_SPI_INPUT_Z 0x0286D8 +#define S_0286D8_PROVIDE_Z_TO_SPI(x) (((x) & 0x1) << 0) +#define G_0286D8_PROVIDE_Z_TO_SPI(x) (((x) >> 0) & 0x1) +#define C_0286D8_PROVIDE_Z_TO_SPI 0xFFFFFFFE +#define R_0286DC_SPI_FOG_CNTL 0x0286DC +#define S_0286DC_PASS_FOG_THROUGH_PS(x) (((x) & 0x1) << 0) +#define G_0286DC_PASS_FOG_THROUGH_PS(x) (((x) >> 0) & 0x1) +#define C_0286DC_PASS_FOG_THROUGH_PS 0xFFFFFFFE +#define S_0286DC_PIXEL_FOG_FUNC(x) (((x) & 0x3) << 1) +#define G_0286DC_PIXEL_FOG_FUNC(x) (((x) >> 1) & 0x3) +#define C_0286DC_PIXEL_FOG_FUNC 0xFFFFFFF9 +#define S_0286DC_PIXEL_FOG_SRC_SEL(x) (((x) & 0x1) << 3) +#define G_0286DC_PIXEL_FOG_SRC_SEL(x) (((x) >> 3) & 0x1) +#define C_0286DC_PIXEL_FOG_SRC_SEL 0xFFFFFFF7 +#define S_0286DC_VS_FOG_CLAMP_DISABLE(x) (((x) & 0x1) << 4) +#define G_0286DC_VS_FOG_CLAMP_DISABLE(x) (((x) >> 4) & 0x1) +#define C_0286DC_VS_FOG_CLAMP_DISABLE 0xFFFFFFEF +#define R_0286E0_SPI_FOG_FUNC_SCALE 0x0286E0 +#define S_0286E0_VALUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_0286E0_VALUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_0286E0_VALUE 0x00000000 +#define R_0286E4_SPI_FOG_FUNC_BIAS 0x0286E4 +#define S_0286E4_VALUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_0286E4_VALUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_0286E4_VALUE 0x00000000 +#define R_0287A0_CB_SHADER_CONTROL 0x0287A0 +#define S_0287A0_RT0_ENABLE(x) (((x) & 0x1) << 0) +#define G_0287A0_RT0_ENABLE(x) (((x) >> 0) & 0x1) +#define C_0287A0_RT0_ENABLE 0xFFFFFFFE +#define S_0287A0_RT1_ENABLE(x) (((x) & 0x1) << 1) +#define G_0287A0_RT1_ENABLE(x) (((x) >> 1) & 0x1) +#define C_0287A0_RT1_ENABLE 0xFFFFFFFD +#define S_0287A0_RT2_ENABLE(x) (((x) & 0x1) << 2) +#define G_0287A0_RT2_ENABLE(x) (((x) >> 2) & 0x1) +#define C_0287A0_RT2_ENABLE 0xFFFFFFFB +#define S_0287A0_RT3_ENABLE(x) (((x) & 0x1) << 3) +#define G_0287A0_RT3_ENABLE(x) (((x) >> 3) & 0x1) +#define C_0287A0_RT3_ENABLE 0xFFFFFFF7 +#define S_0287A0_RT4_ENABLE(x) (((x) & 0x1) << 4) +#define G_0287A0_RT4_ENABLE(x) (((x) >> 4) & 0x1) +#define C_0287A0_RT4_ENABLE 0xFFFFFFEF +#define S_0287A0_RT5_ENABLE(x) (((x) & 0x1) << 5) +#define G_0287A0_RT5_ENABLE(x) (((x) >> 5) & 0x1) +#define C_0287A0_RT5_ENABLE 0xFFFFFFDF +#define S_0287A0_RT6_ENABLE(x) (((x) & 0x1) << 6) +#define G_0287A0_RT6_ENABLE(x) (((x) >> 6) & 0x1) +#define C_0287A0_RT6_ENABLE 0xFFFFFFBF +#define S_0287A0_RT7_ENABLE(x) (((x) & 0x1) << 7) +#define G_0287A0_RT7_ENABLE(x) (((x) >> 7) & 0x1) +#define C_0287A0_RT7_ENABLE 0xFFFFFF7F +#define R_028894_SQ_PGM_START_FS 0x028894 +#define S_028894_PGM_START(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028894_PGM_START(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028894_PGM_START 0x00000000 +#define R_0288A4_SQ_PGM_RESOURCES_FS 0x0288A4 +#define S_0288A4_NUM_GPRS(x) (((x) & 0xFF) << 0) +#define G_0288A4_NUM_GPRS(x) (((x) >> 0) & 0xFF) +#define C_0288A4_NUM_GPRS 0xFFFFFF00 +#define S_0288A4_STACK_SIZE(x) (((x) & 0xFF) << 8) +#define G_0288A4_STACK_SIZE(x) (((x) >> 8) & 0xFF) +#define C_0288A4_STACK_SIZE 0xFFFF00FF +#define S_0288A4_DX10_CLAMP(x) (((x) & 0x1) << 21) +#define G_0288A4_DX10_CLAMP(x) (((x) >> 21) & 0x1) +#define C_0288A4_DX10_CLAMP 0xFFDFFFFF +#define R_0288A8_SQ_ESGS_RING_ITEMSIZE 0x0288A8 +#define S_0288A8_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288A8_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288A8_ITEMSIZE 0xFFFF8000 +#define R_0288AC_SQ_GSVS_RING_ITEMSIZE 0x0288AC +#define S_0288AC_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288AC_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288AC_ITEMSIZE 0xFFFF8000 +#define R_0288B0_SQ_ESTMP_RING_ITEMSIZE 0x0288B0 +#define S_0288B0_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288B0_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288B0_ITEMSIZE 0xFFFF8000 +#define R_0288B4_SQ_GSTMP_RING_ITEMSIZE 0x0288B4 +#define S_0288B4_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288B4_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288B4_ITEMSIZE 0xFFFF8000 +#define R_0288B8_SQ_VSTMP_RING_ITEMSIZE 0x0288B8 +#define S_0288B8_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288B8_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288B8_ITEMSIZE 0xFFFF8000 +#define R_0288BC_SQ_PSTMP_RING_ITEMSIZE 0x0288BC +#define S_0288BC_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288BC_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288BC_ITEMSIZE 0xFFFF8000 +#define R_0288C0_SQ_FBUF_RING_ITEMSIZE 0x0288C0 +#define S_0288C0_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288C0_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288C0_ITEMSIZE 0xFFFF8000 +#define R_0288C4_SQ_REDUC_RING_ITEMSIZE 0x0288C4 +#define S_0288C4_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288C4_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288C4_ITEMSIZE 0xFFFF8000 +#define R_0288C8_SQ_GS_VERT_ITEMSIZE 0x0288C8 +#define S_0288C8_ITEMSIZE(x) (((x) & 0x7FFF) << 0) +#define G_0288C8_ITEMSIZE(x) (((x) >> 0) & 0x7FFF) +#define C_0288C8_ITEMSIZE 0xFFFF8000 +#define R_0288DC_SQ_PGM_CF_OFFSET_FS 0x0288DC +#define S_0288DC_PGM_CF_OFFSET(x) (((x) & 0xFFFFF) << 0) +#define G_0288DC_PGM_CF_OFFSET(x) (((x) >> 0) & 0xFFFFF) +#define C_0288DC_PGM_CF_OFFSET 0xFFF00000 +#define R_028A10_VGT_OUTPUT_PATH_CNTL 0x028A10 +#define S_028A10_PATH_SELECT(x) (((x) & 0x3) << 0) +#define G_028A10_PATH_SELECT(x) (((x) >> 0) & 0x3) +#define C_028A10_PATH_SELECT 0xFFFFFFFC +#define R_028A14_VGT_HOS_CNTL 0x028A14 +#define S_028A14_TESS_MODE(x) (((x) & 0x3) << 0) +#define G_028A14_TESS_MODE(x) (((x) >> 0) & 0x3) +#define C_028A14_TESS_MODE 0xFFFFFFFC +#define R_028A18_VGT_HOS_MAX_TESS_LEVEL 0x028A18 +#define S_028A18_MAX_TESS(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028A18_MAX_TESS(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028A18_MAX_TESS 0x00000000 +#define R_028A1C_VGT_HOS_MIN_TESS_LEVEL 0x028A1C +#define S_028A1C_MIN_TESS(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028A1C_MIN_TESS(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028A1C_MIN_TESS 0x00000000 +#define R_028A20_VGT_HOS_REUSE_DEPTH 0x028A20 +#define S_028A20_REUSE_DEPTH(x) (((x) & 0xFF) << 0) +#define G_028A20_REUSE_DEPTH(x) (((x) >> 0) & 0xFF) +#define C_028A20_REUSE_DEPTH 0xFFFFFF00 +#define R_028A24_VGT_GROUP_PRIM_TYPE 0x028A24 +#define S_028A24_PRIM_TYPE(x) (((x) & 0x1F) << 0) +#define G_028A24_PRIM_TYPE(x) (((x) >> 0) & 0x1F) +#define C_028A24_PRIM_TYPE 0xFFFFFFE0 +#define S_028A24_RETAIN_ORDER(x) (((x) & 0x1) << 14) +#define G_028A24_RETAIN_ORDER(x) (((x) >> 14) & 0x1) +#define C_028A24_RETAIN_ORDER 0xFFFFBFFF +#define S_028A24_RETAIN_QUADS(x) (((x) & 0x1) << 15) +#define G_028A24_RETAIN_QUADS(x) (((x) >> 15) & 0x1) +#define C_028A24_RETAIN_QUADS 0xFFFF7FFF +#define S_028A24_PRIM_ORDER(x) (((x) & 0x7) << 16) +#define G_028A24_PRIM_ORDER(x) (((x) >> 16) & 0x7) +#define C_028A24_PRIM_ORDER 0xFFF8FFFF +#define R_028A28_VGT_GROUP_FIRST_DECR 0x028A28 +#define S_028A28_FIRST_DECR(x) (((x) & 0xF) << 0) +#define G_028A28_FIRST_DECR(x) (((x) >> 0) & 0xF) +#define C_028A28_FIRST_DECR 0xFFFFFFF0 +#define R_028A2C_VGT_GROUP_DECR 0x028A2C +#define S_028A2C_DECR(x) (((x) & 0xF) << 0) +#define G_028A2C_DECR(x) (((x) >> 0) & 0xF) +#define C_028A2C_DECR 0xFFFFFFF0 +#define R_028A30_VGT_GROUP_VECT_0_CNTL 0x028A30 +#define S_028A30_COMP_X_EN(x) (((x) & 0x1) << 0) +#define G_028A30_COMP_X_EN(x) (((x) >> 0) & 0x1) +#define C_028A30_COMP_X_EN 0xFFFFFFFE +#define S_028A30_COMP_Y_EN(x) (((x) & 0x1) << 1) +#define G_028A30_COMP_Y_EN(x) (((x) >> 1) & 0x1) +#define C_028A30_COMP_Y_EN 0xFFFFFFFD +#define S_028A30_COMP_Z_EN(x) (((x) & 0x1) << 2) +#define G_028A30_COMP_Z_EN(x) (((x) >> 2) & 0x1) +#define C_028A30_COMP_Z_EN 0xFFFFFFFB +#define S_028A30_COMP_W_EN(x) (((x) & 0x1) << 3) +#define G_028A30_COMP_W_EN(x) (((x) >> 3) & 0x1) +#define C_028A30_COMP_W_EN 0xFFFFFFF7 +#define S_028A30_STRIDE(x) (((x) & 0xFF) << 8) +#define G_028A30_STRIDE(x) (((x) >> 8) & 0xFF) +#define C_028A30_STRIDE 0xFFFF00FF +#define S_028A30_SHIFT(x) (((x) & 0xFF) << 16) +#define G_028A30_SHIFT(x) (((x) >> 16) & 0xFF) +#define C_028A30_SHIFT 0xFF00FFFF +#define R_028A34_VGT_GROUP_VECT_1_CNTL 0x028A34 +#define S_028A34_COMP_X_EN(x) (((x) & 0x1) << 0) +#define G_028A34_COMP_X_EN(x) (((x) >> 0) & 0x1) +#define C_028A34_COMP_X_EN 0xFFFFFFFE +#define S_028A34_COMP_Y_EN(x) (((x) & 0x1) << 1) +#define G_028A34_COMP_Y_EN(x) (((x) >> 1) & 0x1) +#define C_028A34_COMP_Y_EN 0xFFFFFFFD +#define S_028A34_COMP_Z_EN(x) (((x) & 0x1) << 2) +#define G_028A34_COMP_Z_EN(x) (((x) >> 2) & 0x1) +#define C_028A34_COMP_Z_EN 0xFFFFFFFB +#define S_028A34_COMP_W_EN(x) (((x) & 0x1) << 3) +#define G_028A34_COMP_W_EN(x) (((x) >> 3) & 0x1) +#define C_028A34_COMP_W_EN 0xFFFFFFF7 +#define S_028A34_STRIDE(x) (((x) & 0xFF) << 8) +#define G_028A34_STRIDE(x) (((x) >> 8) & 0xFF) +#define C_028A34_STRIDE 0xFFFF00FF +#define S_028A34_SHIFT(x) (((x) & 0xFF) << 16) +#define G_028A34_SHIFT(x) (((x) >> 16) & 0xFF) +#define C_028A34_SHIFT 0xFF00FFFF +#define R_028A38_VGT_GROUP_VECT_0_FMT_CNTL 0x028A38 +#define S_028A38_X_CONV(x) (((x) & 0xF) << 0) +#define G_028A38_X_CONV(x) (((x) >> 0) & 0xF) +#define C_028A38_X_CONV 0xFFFFFFF0 +#define S_028A38_X_OFFSET(x) (((x) & 0xF) << 4) +#define G_028A38_X_OFFSET(x) (((x) >> 4) & 0xF) +#define C_028A38_X_OFFSET 0xFFFFFF0F +#define S_028A38_Y_CONV(x) (((x) & 0xF) << 8) +#define G_028A38_Y_CONV(x) (((x) >> 8) & 0xF) +#define C_028A38_Y_CONV 0xFFFFF0FF +#define S_028A38_Y_OFFSET(x) (((x) & 0xF) << 12) +#define G_028A38_Y_OFFSET(x) (((x) >> 12) & 0xF) +#define C_028A38_Y_OFFSET 0xFFFF0FFF +#define S_028A38_Z_CONV(x) (((x) & 0xF) << 16) +#define G_028A38_Z_CONV(x) (((x) >> 16) & 0xF) +#define C_028A38_Z_CONV 0xFFF0FFFF +#define S_028A38_Z_OFFSET(x) (((x) & 0xF) << 20) +#define G_028A38_Z_OFFSET(x) (((x) >> 20) & 0xF) +#define C_028A38_Z_OFFSET 0xFF0FFFFF +#define S_028A38_W_CONV(x) (((x) & 0xF) << 24) +#define G_028A38_W_CONV(x) (((x) >> 24) & 0xF) +#define C_028A38_W_CONV 0xF0FFFFFF +#define S_028A38_W_OFFSET(x) (((x) & 0xF) << 28) +#define G_028A38_W_OFFSET(x) (((x) >> 28) & 0xF) +#define C_028A38_W_OFFSET 0x0FFFFFFF +#define R_028A3C_VGT_GROUP_VECT_1_FMT_CNTL 0x028A3C +#define S_028A3C_X_CONV(x) (((x) & 0xF) << 0) +#define G_028A3C_X_CONV(x) (((x) >> 0) & 0xF) +#define C_028A3C_X_CONV 0xFFFFFFF0 +#define S_028A3C_X_OFFSET(x) (((x) & 0xF) << 4) +#define G_028A3C_X_OFFSET(x) (((x) >> 4) & 0xF) +#define C_028A3C_X_OFFSET 0xFFFFFF0F +#define S_028A3C_Y_CONV(x) (((x) & 0xF) << 8) +#define G_028A3C_Y_CONV(x) (((x) >> 8) & 0xF) +#define C_028A3C_Y_CONV 0xFFFFF0FF +#define S_028A3C_Y_OFFSET(x) (((x) & 0xF) << 12) +#define G_028A3C_Y_OFFSET(x) (((x) >> 12) & 0xF) +#define C_028A3C_Y_OFFSET 0xFFFF0FFF +#define S_028A3C_Z_CONV(x) (((x) & 0xF) << 16) +#define G_028A3C_Z_CONV(x) (((x) >> 16) & 0xF) +#define C_028A3C_Z_CONV 0xFFF0FFFF +#define S_028A3C_Z_OFFSET(x) (((x) & 0xF) << 20) +#define G_028A3C_Z_OFFSET(x) (((x) >> 20) & 0xF) +#define C_028A3C_Z_OFFSET 0xFF0FFFFF +#define S_028A3C_W_CONV(x) (((x) & 0xF) << 24) +#define G_028A3C_W_CONV(x) (((x) >> 24) & 0xF) +#define C_028A3C_W_CONV 0xF0FFFFFF +#define S_028A3C_W_OFFSET(x) (((x) & 0xF) << 28) +#define G_028A3C_W_OFFSET(x) (((x) >> 28) & 0xF) +#define C_028A3C_W_OFFSET 0x0FFFFFFF +#define R_028A40_VGT_GS_MODE 0x028A40 +#define S_028A40_MODE(x) (((x) & 0x3) << 0) +#define G_028A40_MODE(x) (((x) >> 0) & 0x3) +#define C_028A40_MODE 0xFFFFFFFC +#define S_028A40_ES_PASSTHRU(x) (((x) & 0x1) << 2) +#define G_028A40_ES_PASSTHRU(x) (((x) >> 2) & 0x1) +#define C_028A40_ES_PASSTHRU 0xFFFFFFFB +#define S_028A40_CUT_MODE(x) (((x) & 0x3) << 3) +#define G_028A40_CUT_MODE(x) (((x) >> 3) & 0x3) +#define C_028A40_CUT_MODE 0xFFFFFFE7 +#define R_028A4C_PA_SC_MODE_CNTL 0x028A4C +#define S_028A4C_MSAA_ENABLE(x) (((x) & 0x1) << 0) +#define G_028A4C_MSAA_ENABLE(x) (((x) >> 0) & 0x1) +#define C_028A4C_MSAA_ENABLE 0xFFFFFFFE +#define S_028A4C_CLIPRECT_ENABLE(x) (((x) & 0x1) << 1) +#define G_028A4C_CLIPRECT_ENABLE(x) (((x) >> 1) & 0x1) +#define C_028A4C_CLIPRECT_ENABLE 0xFFFFFFFD +#define S_028A4C_LINE_STIPPLE_ENABLE(x) (((x) & 0x1) << 2) +#define G_028A4C_LINE_STIPPLE_ENABLE(x) (((x) >> 2) & 0x1) +#define C_028A4C_LINE_STIPPLE_ENABLE 0xFFFFFFFB +#define S_028A4C_MULTI_CHIP_PRIM_DISCARD_ENAB(x) (((x) & 0x1) << 3) +#define G_028A4C_MULTI_CHIP_PRIM_DISCARD_ENAB(x) (((x) >> 3) & 0x1) +#define C_028A4C_MULTI_CHIP_PRIM_DISCARD_ENAB 0xFFFFFFF7 +#define S_028A4C_WALK_ORDER_ENABLE(x) (((x) & 0x1) << 4) +#define G_028A4C_WALK_ORDER_ENABLE(x) (((x) >> 4) & 0x1) +#define C_028A4C_WALK_ORDER_ENABLE 0xFFFFFFEF +#define S_028A4C_HALVE_DETAIL_SAMPLE_PERF(x) (((x) & 0x1) << 5) +#define G_028A4C_HALVE_DETAIL_SAMPLE_PERF(x) (((x) >> 5) & 0x1) +#define C_028A4C_HALVE_DETAIL_SAMPLE_PERF 0xFFFFFFDF +#define S_028A4C_WALK_SIZE(x) (((x) & 0x1) << 6) +#define G_028A4C_WALK_SIZE(x) (((x) >> 6) & 0x1) +#define C_028A4C_WALK_SIZE 0xFFFFFFBF +#define S_028A4C_WALK_ALIGNMENT(x) (((x) & 0x1) << 7) +#define G_028A4C_WALK_ALIGNMENT(x) (((x) >> 7) & 0x1) +#define C_028A4C_WALK_ALIGNMENT 0xFFFFFF7F +#define S_028A4C_WALK_ALIGN8_PRIM_FITS_ST(x) (((x) & 0x1) << 8) +#define G_028A4C_WALK_ALIGN8_PRIM_FITS_ST(x) (((x) >> 8) & 0x1) +#define C_028A4C_WALK_ALIGN8_PRIM_FITS_ST 0xFFFFFEFF +#define S_028A4C_TILE_COVER_NO_SCISSOR(x) (((x) & 0x1) << 9) +#define G_028A4C_TILE_COVER_NO_SCISSOR(x) (((x) >> 9) & 0x1) +#define C_028A4C_TILE_COVER_NO_SCISSOR 0xFFFFFDFF +#define S_028A4C_KILL_PIX_POST_HI_Z(x) (((x) & 0x1) << 10) +#define G_028A4C_KILL_PIX_POST_HI_Z(x) (((x) >> 10) & 0x1) +#define C_028A4C_KILL_PIX_POST_HI_Z 0xFFFFFBFF +#define S_028A4C_KILL_PIX_POST_DETAIL_MASK(x) (((x) & 0x1) << 11) +#define G_028A4C_KILL_PIX_POST_DETAIL_MASK(x) (((x) >> 11) & 0x1) +#define C_028A4C_KILL_PIX_POST_DETAIL_MASK 0xFFFFF7FF +#define S_028A4C_MULTI_CHIP_SUPERTILE_ENABLE(x) (((x) & 0x1) << 12) +#define G_028A4C_MULTI_CHIP_SUPERTILE_ENABLE(x) (((x) >> 12) & 0x1) +#define C_028A4C_MULTI_CHIP_SUPERTILE_ENABLE 0xFFFFEFFF +#define S_028A4C_TILE_COVER_DISABLE(x) (((x) & 0x1) << 13) +#define G_028A4C_TILE_COVER_DISABLE(x) (((x) >> 13) & 0x1) +#define C_028A4C_TILE_COVER_DISABLE 0xFFFFDFFF +#define S_028A4C_FORCE_EOV_CNTDWN_ENABLE(x) (((x) & 0x1) << 14) +#define G_028A4C_FORCE_EOV_CNTDWN_ENABLE(x) (((x) >> 14) & 0x1) +#define C_028A4C_FORCE_EOV_CNTDWN_ENABLE 0xFFFFBFFF +#define S_028A4C_FORCE_EOV_TILE_ENABLE(x) (((x) & 0x1) << 15) +#define G_028A4C_FORCE_EOV_TILE_ENABLE(x) (((x) >> 15) & 0x1) +#define C_028A4C_FORCE_EOV_TILE_ENABLE 0xFFFF7FFF +#define S_028A4C_FORCE_EOV_REZ_ENABLE(x) (((x) & 0x1) << 16) +#define G_028A4C_FORCE_EOV_REZ_ENABLE(x) (((x) >> 16) & 0x1) +#define C_028A4C_FORCE_EOV_REZ_ENABLE 0xFFFEFFFF +#define S_028A4C_PS_ITER_SAMPLE(x) (((x) & 0x1) << 17) +#define G_028A4C_PS_ITER_SAMPLE(x) (((x) >> 17) & 0x1) +#define C_028A4C_PS_ITER_SAMPLE 0xFFFDFFFF +#define R_028A84_VGT_PRIMITIVEID_EN 0x028A84 +#define S_028A84_PRIMITIVEID_EN(x) (((x) & 0x1) << 0) +#define G_028A84_PRIMITIVEID_EN(x) (((x) >> 0) & 0x1) +#define C_028A84_PRIMITIVEID_EN 0xFFFFFFFE +#define R_028A94_VGT_MULTI_PRIM_IB_RESET_EN 0x028A94 +#define S_028A94_RESET_EN(x) (((x) & 0x1) << 0) +#define G_028A94_RESET_EN(x) (((x) >> 0) & 0x1) +#define C_028A94_RESET_EN 0xFFFFFFFE +#define R_028AA0_VGT_INSTANCE_STEP_RATE_0 0x028AA0 +#define S_028AA0_STEP_RATE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028AA0_STEP_RATE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028AA0_STEP_RATE 0x00000000 +#define R_028AA4_VGT_INSTANCE_STEP_RATE_1 0x028AA4 +#define S_028AA4_STEP_RATE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028AA4_STEP_RATE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028AA4_STEP_RATE 0x00000000 +#define R_028AB0_VGT_STRMOUT_EN 0x028AB0 +#define S_028AB0_STREAMOUT(x) (((x) & 0x1) << 0) +#define G_028AB0_STREAMOUT(x) (((x) >> 0) & 0x1) +#define C_028AB0_STREAMOUT 0xFFFFFFFE +#define R_028AB4_VGT_REUSE_OFF 0x028AB4 +#define S_028AB4_REUSE_OFF(x) (((x) & 0x1) << 0) +#define G_028AB4_REUSE_OFF(x) (((x) >> 0) & 0x1) +#define C_028AB4_REUSE_OFF 0xFFFFFFFE +#define R_028AB8_VGT_VTX_CNT_EN 0x028AB8 +#define S_028AB8_VTX_CNT_EN(x) (((x) & 0x1) << 0) +#define G_028AB8_VTX_CNT_EN(x) (((x) >> 0) & 0x1) +#define C_028AB8_VTX_CNT_EN 0xFFFFFFFE +#define R_028B20_VGT_STRMOUT_BUFFER_EN 0x028B20 +#define S_028B20_BUFFER_0_EN(x) (((x) & 0x1) << 0) +#define G_028B20_BUFFER_0_EN(x) (((x) >> 0) & 0x1) +#define C_028B20_BUFFER_0_EN 0xFFFFFFFE +#define S_028B20_BUFFER_1_EN(x) (((x) & 0x1) << 1) +#define G_028B20_BUFFER_1_EN(x) (((x) >> 1) & 0x1) +#define C_028B20_BUFFER_1_EN 0xFFFFFFFD +#define S_028B20_BUFFER_2_EN(x) (((x) & 0x1) << 2) +#define G_028B20_BUFFER_2_EN(x) (((x) >> 2) & 0x1) +#define C_028B20_BUFFER_2_EN 0xFFFFFFFB +#define S_028B20_BUFFER_3_EN(x) (((x) & 0x1) << 3) +#define G_028B20_BUFFER_3_EN(x) (((x) >> 3) & 0x1) +#define C_028B20_BUFFER_3_EN 0xFFFFFFF7 +#define R_028C20_PA_SC_AA_SAMPLE_LOCS_8S_WD1_MCTX 0x028C20 +#define S_028C20_S4_X(x) (((x) & 0xF) << 0) +#define G_028C20_S4_X(x) (((x) >> 0) & 0xF) +#define C_028C20_S4_X 0xFFFFFFF0 +#define S_028C20_S4_Y(x) (((x) & 0xF) << 4) +#define G_028C20_S4_Y(x) (((x) >> 4) & 0xF) +#define C_028C20_S4_Y 0xFFFFFF0F +#define S_028C20_S5_X(x) (((x) & 0xF) << 8) +#define G_028C20_S5_X(x) (((x) >> 8) & 0xF) +#define C_028C20_S5_X 0xFFFFF0FF +#define S_028C20_S5_Y(x) (((x) & 0xF) << 12) +#define G_028C20_S5_Y(x) (((x) >> 12) & 0xF) +#define C_028C20_S5_Y 0xFFFF0FFF +#define S_028C20_S6_X(x) (((x) & 0xF) << 16) +#define G_028C20_S6_X(x) (((x) >> 16) & 0xF) +#define C_028C20_S6_X 0xFFF0FFFF +#define S_028C20_S6_Y(x) (((x) & 0xF) << 20) +#define G_028C20_S6_Y(x) (((x) >> 20) & 0xF) +#define C_028C20_S6_Y 0xFF0FFFFF +#define S_028C20_S7_X(x) (((x) & 0xF) << 24) +#define G_028C20_S7_X(x) (((x) >> 24) & 0xF) +#define C_028C20_S7_X 0xF0FFFFFF +#define S_028C20_S7_Y(x) (((x) & 0xF) << 28) +#define G_028C20_S7_Y(x) (((x) >> 28) & 0xF) +#define C_028C20_S7_Y 0x0FFFFFFF +#define R_028C30_CB_CLRCMP_CONTROL 0x028C30 +#define S_028C30_CLRCMP_FCN_SRC(x) (((x) & 0x7) << 0) +#define G_028C30_CLRCMP_FCN_SRC(x) (((x) >> 0) & 0x7) +#define C_028C30_CLRCMP_FCN_SRC 0xFFFFFFF8 +#define S_028C30_CLRCMP_FCN_DST(x) (((x) & 0x7) << 8) +#define G_028C30_CLRCMP_FCN_DST(x) (((x) >> 8) & 0x7) +#define C_028C30_CLRCMP_FCN_DST 0xFFFFF8FF +#define S_028C30_CLRCMP_FCN_SEL(x) (((x) & 0x3) << 24) +#define G_028C30_CLRCMP_FCN_SEL(x) (((x) >> 24) & 0x3) +#define C_028C30_CLRCMP_FCN_SEL 0xFCFFFFFF +#define R_028C34_CB_CLRCMP_SRC 0x028C34 +#define S_028C34_CLRCMP_SRC(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028C34_CLRCMP_SRC(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028C34_CLRCMP_SRC 0x00000000 +#define R_028C38_CB_CLRCMP_DST 0x028C38 +#define S_028C38_CLRCMP_DST(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028C38_CLRCMP_DST(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028C38_CLRCMP_DST 0x00000000 +#define R_028C3C_CB_CLRCMP_MSK 0x028C3C +#define S_028C3C_CLRCMP_MSK(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028C3C_CLRCMP_MSK(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028C3C_CLRCMP_MSK 0x00000000 +#define R_0085F0_CP_COHER_CNTL 0x0085F0 +#define S_0085F0_DEST_BASE_0_ENA(x) (((x) & 0x1) << 0) +#define G_0085F0_DEST_BASE_0_ENA(x) (((x) >> 0) & 0x1) +#define C_0085F0_DEST_BASE_0_ENA 0xFFFFFFFE +#define S_0085F0_DEST_BASE_1_ENA(x) (((x) & 0x1) << 1) +#define G_0085F0_DEST_BASE_1_ENA(x) (((x) >> 1) & 0x1) +#define C_0085F0_DEST_BASE_1_ENA 0xFFFFFFFD +#define S_0085F0_SO0_DEST_BASE_ENA(x) (((x) & 0x1) << 2) +#define G_0085F0_SO0_DEST_BASE_ENA(x) (((x) >> 2) & 0x1) +#define C_0085F0_SO0_DEST_BASE_ENA 0xFFFFFFFB +#define S_0085F0_SO1_DEST_BASE_ENA(x) (((x) & 0x1) << 3) +#define G_0085F0_SO1_DEST_BASE_ENA(x) (((x) >> 3) & 0x1) +#define C_0085F0_SO1_DEST_BASE_ENA 0xFFFFFFF7 +#define S_0085F0_SO2_DEST_BASE_ENA(x) (((x) & 0x1) << 4) +#define G_0085F0_SO2_DEST_BASE_ENA(x) (((x) >> 4) & 0x1) +#define C_0085F0_SO2_DEST_BASE_ENA 0xFFFFFFEF +#define S_0085F0_SO3_DEST_BASE_ENA(x) (((x) & 0x1) << 5) +#define G_0085F0_SO3_DEST_BASE_ENA(x) (((x) >> 5) & 0x1) +#define C_0085F0_SO3_DEST_BASE_ENA 0xFFFFFFDF +#define S_0085F0_CB0_DEST_BASE_ENA(x) (((x) & 0x1) << 6) +#define G_0085F0_CB0_DEST_BASE_ENA(x) (((x) >> 6) & 0x1) +#define C_0085F0_CB0_DEST_BASE_ENA 0xFFFFFFBF +#define S_0085F0_CB1_DEST_BASE_ENA(x) (((x) & 0x1) << 7) +#define G_0085F0_CB1_DEST_BASE_ENA(x) (((x) >> 7) & 0x1) +#define C_0085F0_CB1_DEST_BASE_ENA 0xFFFFFF7F +#define S_0085F0_CB2_DEST_BASE_ENA(x) (((x) & 0x1) << 8) +#define G_0085F0_CB2_DEST_BASE_ENA(x) (((x) >> 8) & 0x1) +#define C_0085F0_CB2_DEST_BASE_ENA 0xFFFFFEFF +#define S_0085F0_CB3_DEST_BASE_ENA(x) (((x) & 0x1) << 9) +#define G_0085F0_CB3_DEST_BASE_ENA(x) (((x) >> 9) & 0x1) +#define C_0085F0_CB3_DEST_BASE_ENA 0xFFFFFDFF +#define S_0085F0_CB4_DEST_BASE_ENA(x) (((x) & 0x1) << 10) +#define G_0085F0_CB4_DEST_BASE_ENA(x) (((x) >> 10) & 0x1) +#define C_0085F0_CB4_DEST_BASE_ENA 0xFFFFFBFF +#define S_0085F0_CB5_DEST_BASE_ENA(x) (((x) & 0x1) << 11) +#define G_0085F0_CB5_DEST_BASE_ENA(x) (((x) >> 11) & 0x1) +#define C_0085F0_CB5_DEST_BASE_ENA 0xFFFFF7FF +#define S_0085F0_CB6_DEST_BASE_ENA(x) (((x) & 0x1) << 12) +#define G_0085F0_CB6_DEST_BASE_ENA(x) (((x) >> 12) & 0x1) +#define C_0085F0_CB6_DEST_BASE_ENA 0xFFFFEFFF +#define S_0085F0_CB7_DEST_BASE_ENA(x) (((x) & 0x1) << 13) +#define G_0085F0_CB7_DEST_BASE_ENA(x) (((x) >> 13) & 0x1) +#define C_0085F0_CB7_DEST_BASE_ENA 0xFFFFDFFF +#define S_0085F0_DB_DEST_BASE_ENA(x) (((x) & 0x1) << 14) +#define G_0085F0_DB_DEST_BASE_ENA(x) (((x) >> 14) & 0x1) +#define C_0085F0_DB_DEST_BASE_ENA 0xFFFFBFFF +#define S_0085F0_CR_DEST_BASE_ENA(x) (((x) & 0x1) << 15) +#define G_0085F0_CR_DEST_BASE_ENA(x) (((x) >> 15) & 0x1) +#define C_0085F0_CR_DEST_BASE_ENA 0xFFFF7FFF +#define S_0085F0_TC_ACTION_ENA(x) (((x) & 0x1) << 23) +#define G_0085F0_TC_ACTION_ENA(x) (((x) >> 23) & 0x1) +#define C_0085F0_TC_ACTION_ENA 0xFF7FFFFF +#define S_0085F0_VC_ACTION_ENA(x) (((x) & 0x1) << 24) +#define G_0085F0_VC_ACTION_ENA(x) (((x) >> 24) & 0x1) +#define C_0085F0_VC_ACTION_ENA 0xFEFFFFFF +#define S_0085F0_CB_ACTION_ENA(x) (((x) & 0x1) << 25) +#define G_0085F0_CB_ACTION_ENA(x) (((x) >> 25) & 0x1) +#define C_0085F0_CB_ACTION_ENA 0xFDFFFFFF +#define S_0085F0_DB_ACTION_ENA(x) (((x) & 0x1) << 26) +#define G_0085F0_DB_ACTION_ENA(x) (((x) >> 26) & 0x1) +#define C_0085F0_DB_ACTION_ENA 0xFBFFFFFF +#define S_0085F0_SH_ACTION_ENA(x) (((x) & 0x1) << 27) +#define G_0085F0_SH_ACTION_ENA(x) (((x) >> 27) & 0x1) +#define C_0085F0_SH_ACTION_ENA 0xF7FFFFFF +#define S_0085F0_SMX_ACTION_ENA(x) (((x) & 0x1) << 28) +#define G_0085F0_SMX_ACTION_ENA(x) (((x) >> 28) & 0x1) +#define C_0085F0_SMX_ACTION_ENA 0xEFFFFFFF +#define S_0085F0_CR0_ACTION_ENA(x) (((x) & 0x1) << 29) +#define G_0085F0_CR0_ACTION_ENA(x) (((x) >> 29) & 0x1) +#define C_0085F0_CR0_ACTION_ENA 0xDFFFFFFF +#define S_0085F0_CR1_ACTION_ENA(x) (((x) & 0x1) << 30) +#define G_0085F0_CR1_ACTION_ENA(x) (((x) >> 30) & 0x1) +#define C_0085F0_CR1_ACTION_ENA 0xBFFFFFFF +#define S_0085F0_CR2_ACTION_ENA(x) (((x) & 0x1) << 31) +#define G_0085F0_CR2_ACTION_ENA(x) (((x) >> 31) & 0x1) +#define C_0085F0_CR2_ACTION_ENA 0x7FFFFFFF + + +#define R_02812C_CB_CLEAR_ALPHA 0x02812C +#define S_02812C_CLEAR_ALPHA(x) (((x) & 0xFFFFFFFF) << 0) +#define G_02812C_CLEAR_ALPHA(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_02812C_CLEAR_ALPHA 0x00000000 +#define R_028128_CB_CLEAR_BLUE 0x028128 +#define S_028128_CLEAR_BLUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028128_CLEAR_BLUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028128_CLEAR_BLUE 0x00000000 +#define R_028124_CB_CLEAR_GREEN 0x028124 +#define S_028124_CLEAR_GREEN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028124_CLEAR_GREEN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028124_CLEAR_GREEN 0x00000000 +#define R_028120_CB_CLEAR_RED 0x028120 +#define S_028120_CLEAR_RED(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028120_CLEAR_RED(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028120_CLEAR_RED 0x00000000 +#define R_02842C_CB_FOG_BLUE 0x02842C +#define S_02842C_FOG_BLUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_02842C_FOG_BLUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_02842C_FOG_BLUE 0x00000000 +#define R_028428_CB_FOG_GREEN 0x028428 +#define S_028428_FOG_GREEN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028428_FOG_GREEN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028428_FOG_GREEN 0x00000000 +#define R_028424_CB_FOG_RED 0x028424 +#define S_028424_FOG_RED(x) (((x) & 0xFFFFFFFF) << 0) +#define G_028424_FOG_RED(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_028424_FOG_RED 0x00000000 +#define R_03C000_SQ_TEX_SAMPLER_WORD0_0 0x03C000 +#define S_03C000_CLAMP_X(x) (((x) & 0x7) << 0) +#define G_03C000_CLAMP_X(x) (((x) >> 0) & 0x7) +#define C_03C000_CLAMP_X 0xFFFFFFF8 +#define S_03C000_CLAMP_Y(x) (((x) & 0x7) << 3) +#define G_03C000_CLAMP_Y(x) (((x) >> 3) & 0x7) +#define C_03C000_CLAMP_Y 0xFFFFFFC7 +#define S_03C000_CLAMP_Z(x) (((x) & 0x7) << 6) +#define G_03C000_CLAMP_Z(x) (((x) >> 6) & 0x7) +#define C_03C000_CLAMP_Z 0xFFFFFE3F +#define S_03C000_XY_MAG_FILTER(x) (((x) & 0x7) << 9) +#define G_03C000_XY_MAG_FILTER(x) (((x) >> 9) & 0x7) +#define C_03C000_XY_MAG_FILTER 0xFFFFF1FF +#define S_03C000_XY_MIN_FILTER(x) (((x) & 0x7) << 12) +#define G_03C000_XY_MIN_FILTER(x) (((x) >> 12) & 0x7) +#define C_03C000_XY_MIN_FILTER 0xFFFF8FFF +#define S_03C000_Z_FILTER(x) (((x) & 0x3) << 15) +#define G_03C000_Z_FILTER(x) (((x) >> 15) & 0x3) +#define C_03C000_Z_FILTER 0xFFFE7FFF +#define S_03C000_MIP_FILTER(x) (((x) & 0x3) << 17) +#define G_03C000_MIP_FILTER(x) (((x) >> 17) & 0x3) +#define C_03C000_MIP_FILTER 0xFFF9FFFF +#define S_03C000_BORDER_COLOR_TYPE(x) (((x) & 0x3) << 22) +#define G_03C000_BORDER_COLOR_TYPE(x) (((x) >> 22) & 0x3) +#define C_03C000_BORDER_COLOR_TYPE 0xFF3FFFFF +#define S_03C000_POINT_SAMPLING_CLAMP(x) (((x) & 0x1) << 24) +#define G_03C000_POINT_SAMPLING_CLAMP(x) (((x) >> 24) & 0x1) +#define C_03C000_POINT_SAMPLING_CLAMP 0xFEFFFFFF +#define S_03C000_TEX_ARRAY_OVERRIDE(x) (((x) & 0x1) << 25) +#define G_03C000_TEX_ARRAY_OVERRIDE(x) (((x) >> 25) & 0x1) +#define C_03C000_TEX_ARRAY_OVERRIDE 0xFDFFFFFF +#define S_03C000_DEPTH_COMPARE_FUNCTION(x) (((x) & 0x7) << 26) +#define G_03C000_DEPTH_COMPARE_FUNCTION(x) (((x) >> 26) & 0x7) +#define C_03C000_DEPTH_COMPARE_FUNCTION 0xE3FFFFFF +#define S_03C000_CHROMA_KEY(x) (((x) & 0x3) << 29) +#define G_03C000_CHROMA_KEY(x) (((x) >> 29) & 0x3) +#define C_03C000_CHROMA_KEY 0x9FFFFFFF +#define S_03C000_LOD_USES_MINOR_AXIS(x) (((x) & 0x1) << 31) +#define G_03C000_LOD_USES_MINOR_AXIS(x) (((x) >> 31) & 0x1) +#define C_03C000_LOD_USES_MINOR_AXIS 0x7FFFFFFF +#define R_03C004_SQ_TEX_SAMPLER_WORD1_0 0x03C004 +#define S_03C004_MIN_LOD(x) (((x) & 0x3FF) << 0) +#define G_03C004_MIN_LOD(x) (((x) >> 0) & 0x3FF) +#define C_03C004_MIN_LOD 0xFFFFFC00 +#define S_03C004_MAX_LOD(x) (((x) & 0x3FF) << 10) +#define G_03C004_MAX_LOD(x) (((x) >> 10) & 0x3FF) +#define C_03C004_MAX_LOD 0xFFF003FF +#define S_03C004_LOD_BIAS(x) (((x) & 0xFFF) << 20) +#define G_03C004_LOD_BIAS(x) (((x) >> 20) & 0xFFF) +#define C_03C004_LOD_BIAS 0x000FFFFF +#define R_03C008_SQ_TEX_SAMPLER_WORD2_0 0x03C008 +#define S_03C008_LOD_BIAS_SEC(x) (((x) & 0xFFF) << 0) +#define G_03C008_LOD_BIAS_SEC(x) (((x) >> 0) & 0xFFF) +#define C_03C008_LOD_BIAS_SEC 0xFFFFF000 +#define S_03C008_MC_COORD_TRUNCATE(x) (((x) & 0x1) << 12) +#define G_03C008_MC_COORD_TRUNCATE(x) (((x) >> 12) & 0x1) +#define C_03C008_MC_COORD_TRUNCATE 0xFFFFEFFF +#define S_03C008_FORCE_DEGAMMA(x) (((x) & 0x1) << 13) +#define G_03C008_FORCE_DEGAMMA(x) (((x) >> 13) & 0x1) +#define C_03C008_FORCE_DEGAMMA 0xFFFFDFFF +#define S_03C008_HIGH_PRECISION_FILTER(x) (((x) & 0x1) << 14) +#define G_03C008_HIGH_PRECISION_FILTER(x) (((x) >> 14) & 0x1) +#define C_03C008_HIGH_PRECISION_FILTER 0xFFFFBFFF +#define S_03C008_PERF_MIP(x) (((x) & 0x7) << 15) +#define G_03C008_PERF_MIP(x) (((x) >> 15) & 0x7) +#define C_03C008_PERF_MIP 0xFFFC7FFF +#define S_03C008_PERF_Z(x) (((x) & 0x3) << 18) +#define G_03C008_PERF_Z(x) (((x) >> 18) & 0x3) +#define C_03C008_PERF_Z 0xFFF3FFFF +#define S_03C008_FETCH_4(x) (((x) & 0x1) << 26) +#define G_03C008_FETCH_4(x) (((x) >> 26) & 0x1) +#define C_03C008_FETCH_4 0xFBFFFFFF +#define S_03C008_SAMPLE_IS_PCF(x) (((x) & 0x1) << 27) +#define G_03C008_SAMPLE_IS_PCF(x) (((x) >> 27) & 0x1) +#define C_03C008_SAMPLE_IS_PCF 0xF7FFFFFF +#define S_03C008_TYPE(x) (((x) & 0x1) << 31) +#define G_03C008_TYPE(x) (((x) >> 31) & 0x1) +#define C_03C008_TYPE 0x7FFFFFFF +#define R_00A40C_TD_PS_SAMPLER0_BORDER_ALPHA 0x00A40C +#define S_00A40C_BORDER_ALPHA(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A40C_BORDER_ALPHA(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A40C_BORDER_ALPHA 0x00000000 +#define R_00A408_TD_PS_SAMPLER0_BORDER_BLUE 0x00A408 +#define S_00A408_BORDER_BLUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A408_BORDER_BLUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A408_BORDER_BLUE 0x00000000 +#define R_00A404_TD_PS_SAMPLER0_BORDER_GREEN 0x00A404 +#define S_00A404_BORDER_GREEN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A404_BORDER_GREEN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A404_BORDER_GREEN 0x00000000 +#define R_00A400_TD_PS_SAMPLER0_BORDER_RED 0x00A400 +#define S_00A400_BORDER_RED(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A400_BORDER_RED(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A400_BORDER_RED 0x00000000 +#define R_00A60C_TD_VS_SAMPLER0_BORDER_ALPHA 0x00A60C +#define S_00A60C_BORDER_ALPHA(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A60C_BORDER_ALPHA(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A60C_BORDER_ALPHA 0x00000000 +#define R_00A608_TD_VS_SAMPLER0_BORDER_BLUE 0x00A608 +#define S_00A608_BORDER_BLUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A608_BORDER_BLUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A608_BORDER_BLUE 0x00000000 +#define R_00A604_TD_VS_SAMPLER0_BORDER_GREEN 0x00A604 +#define S_00A604_BORDER_GREEN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A604_BORDER_GREEN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A604_BORDER_GREEN 0x00000000 +#define R_00A600_TD_VS_SAMPLER0_BORDER_RED 0x00A600 +#define S_00A600_BORDER_RED(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A600_BORDER_RED(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A600_BORDER_RED 0x00000000 +#define R_00A80C_TD_GS_SAMPLER0_BORDER_ALPHA 0x00A80C +#define S_00A80C_BORDER_ALPHA(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A80C_BORDER_ALPHA(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A80C_BORDER_ALPHA 0x00000000 +#define R_00A808_TD_GS_SAMPLER0_BORDER_BLUE 0x00A808 +#define S_00A808_BORDER_BLUE(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A808_BORDER_BLUE(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A808_BORDER_BLUE 0x00000000 +#define R_00A804_TD_GS_SAMPLER0_BORDER_GREEN 0x00A804 +#define S_00A804_BORDER_GREEN(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A804_BORDER_GREEN(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A804_BORDER_GREEN 0x00000000 +#define R_00A800_TD_GS_SAMPLER0_BORDER_RED 0x00A800 +#define S_00A800_BORDER_RED(x) (((x) & 0xFFFFFFFF) << 0) +#define G_00A800_BORDER_RED(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_00A800_BORDER_RED 0x00000000 +#define R_030000_SQ_ALU_CONSTANT0_0 0x030000 +#define S_030000_X(x) (((x) & 0xFFFFFFFF) << 0) +#define G_030000_X(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_030000_X 0x00000000 +#define R_030004_SQ_ALU_CONSTANT1_0 0x030004 +#define S_030004_Y(x) (((x) & 0xFFFFFFFF) << 0) +#define G_030004_Y(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_030004_Y 0x00000000 +#define R_030008_SQ_ALU_CONSTANT2_0 0x030008 +#define S_030008_Z(x) (((x) & 0xFFFFFFFF) << 0) +#define G_030008_Z(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_030008_Z 0x00000000 +#define R_03000C_SQ_ALU_CONSTANT3_0 0x03000C +#define S_03000C_W(x) (((x) & 0xFFFFFFFF) << 0) +#define G_03000C_W(x) (((x) >> 0) & 0xFFFFFFFF) +#define C_03000C_W 0x00000000 +#define R_0287E4_VGT_DMA_BASE_HI 0x0287E4 +#define R_0287E8_VGT_DMA_BASE 0x0287E8 +#define R_028E20_PA_CL_UCP0_X 0x028E20 +#define R_028E24_PA_CL_UCP0_Y 0x028E24 +#define R_028E28_PA_CL_UCP0_Z 0x028E28 +#define R_028E2C_PA_CL_UCP0_W 0x028E2C +#define R_028E30_PA_CL_UCP1_X 0x028E30 +#define R_028E34_PA_CL_UCP1_Y 0x028E34 +#define R_028E38_PA_CL_UCP1_Z 0x028E38 +#define R_028E3C_PA_CL_UCP1_W 0x028E3C +#define R_028E40_PA_CL_UCP2_X 0x028E40 +#define R_028E44_PA_CL_UCP2_Y 0x028E44 +#define R_028E48_PA_CL_UCP2_Z 0x028E48 +#define R_028E4C_PA_CL_UCP2_W 0x028E4C +#define R_028E50_PA_CL_UCP3_X 0x028E50 +#define R_028E54_PA_CL_UCP3_Y 0x028E54 +#define R_028E58_PA_CL_UCP3_Z 0x028E58 +#define R_028E5C_PA_CL_UCP3_W 0x028E5C +#define R_028E60_PA_CL_UCP4_X 0x028E60 +#define R_028E64_PA_CL_UCP4_Y 0x028E64 +#define R_028E68_PA_CL_UCP4_Z 0x028E68 +#define R_028E6C_PA_CL_UCP4_W 0x028E6C +#define R_028E70_PA_CL_UCP5_X 0x028E70 +#define R_028E74_PA_CL_UCP5_Y 0x028E74 +#define R_028E78_PA_CL_UCP5_Z 0x028E78 +#define R_028E7C_PA_CL_UCP5_W 0x028E7C +#define R_038000_RESOURCE0_WORD0 0x038000 +#define R_038004_RESOURCE0_WORD1 0x038004 +#define R_038008_RESOURCE0_WORD2 0x038008 +#define R_03800C_RESOURCE0_WORD3 0x03800C +#define R_038010_RESOURCE0_WORD4 0x038010 +#define R_038014_RESOURCE0_WORD5 0x038014 +#define R_038018_RESOURCE0_WORD6 0x038018 + +#define R_028140_ALU_CONST_BUFFER_SIZE_PS_0 0x00028140 +#define R_028180_ALU_CONST_BUFFER_SIZE_VS_0 0x00028180 +#define R_028940_ALU_CONST_CACHE_PS_0 0x00028940 +#define R_028980_ALU_CONST_CACHE_VS_0 0x00028980 + +#define R_03CFF0_SQ_VTX_BASE_VTX_LOC 0x03CFF0 +#define R_03CFF4_SQ_VTX_START_INST_LOC 0x03CFF4 + +#endif diff --git a/src/gallium/winsys/r600/drm/radeon_bo.c b/src/gallium/winsys/r600/drm/radeon_bo.c new file mode 100644 index 0000000..7e5f392 --- /dev/null +++ b/src/gallium/winsys/r600/drm/radeon_bo.c @@ -0,0 +1,235 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#define _FILE_OFFSET_BITS 64 +#include +#include +#include +#include +#include +#include "r600_priv.h" +#include "xf86drm.h" +#include "radeon_drm.h" + +static int radeon_bo_fixed_map(struct radeon *radeon, struct radeon_bo *bo) +{ + struct drm_radeon_gem_mmap args; + void *ptr; + int r; + + /* Zero out args to make valgrind happy */ + memset(&args, 0, sizeof(args)); + args.handle = bo->handle; + args.offset = 0; + args.size = (uint64_t)bo->size; + r = drmCommandWriteRead(radeon->fd, DRM_RADEON_GEM_MMAP, + &args, sizeof(args)); + if (r) { + fprintf(stderr, "error mapping %p 0x%08X (error = %d)\n", + bo, bo->handle, r); + return r; + } + ptr = mmap(0, args.size, PROT_READ|PROT_WRITE, MAP_SHARED, radeon->fd, args.addr_ptr); + if (ptr == MAP_FAILED) { + fprintf(stderr, "%s failed to map bo\n", __func__); + return -errno; + } + bo->data = ptr; + + bo->map_count++; + return 0; +} + +static void radeon_bo_fixed_unmap(struct radeon *radeon, struct radeon_bo *bo) +{ + munmap(bo->data, bo->size); + bo->data = NULL; +} + +struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle, + unsigned size, unsigned alignment) +{ + struct radeon_bo *bo; + int r; + + bo = calloc(1, sizeof(*bo)); + if (bo == NULL) { + return NULL; + } + bo->size = size; + bo->handle = handle; + pipe_reference_init(&bo->reference, 1); + bo->alignment = alignment; + LIST_INITHEAD(&bo->fencedlist); + + if (handle) { + struct drm_gem_open open_arg; + + memset(&open_arg, 0, sizeof(open_arg)); + open_arg.name = handle; + r = drmIoctl(radeon->fd, DRM_IOCTL_GEM_OPEN, &open_arg); + if (r != 0) { + free(bo); + return NULL; + } + bo->handle = open_arg.handle; + bo->size = open_arg.size; + bo->shared = TRUE; + } else { + struct drm_radeon_gem_create args; + + args.size = size; + args.alignment = alignment; + args.initial_domain = RADEON_GEM_DOMAIN_CPU; + args.flags = 0; + args.handle = 0; + r = drmCommandWriteRead(radeon->fd, DRM_RADEON_GEM_CREATE, + &args, sizeof(args)); + bo->handle = args.handle; + if (r) { + fprintf(stderr, "Failed to allocate :\n"); + fprintf(stderr, " size : %d bytes\n", size); + fprintf(stderr, " alignment : %d bytes\n", alignment); + free(bo); + return NULL; + } + } + if (radeon_bo_fixed_map(radeon, bo)) { + R600_ERR("failed to map bo\n"); + radeon_bo_reference(radeon, &bo, NULL); + return bo; + } + return bo; +} + +static void radeon_bo_destroy(struct radeon *radeon, struct radeon_bo *bo) +{ + struct drm_gem_close args; + + LIST_DEL(&bo->fencedlist); + radeon_bo_fixed_unmap(radeon, bo); + memset(&args, 0, sizeof(args)); + args.handle = bo->handle; + drmIoctl(radeon->fd, DRM_IOCTL_GEM_CLOSE, &args); + memset(bo, 0, sizeof(struct radeon_bo)); + free(bo); +} + +void radeon_bo_reference(struct radeon *radeon, + struct radeon_bo **dst, + struct radeon_bo *src) +{ + struct radeon_bo *old = *dst; + if (pipe_reference(&(*dst)->reference, &src->reference)) { + radeon_bo_destroy(radeon, old); + } + *dst = src; +} + +int radeon_bo_wait(struct radeon *radeon, struct radeon_bo *bo) +{ + struct drm_radeon_gem_wait_idle args; + int ret; + + if (!bo->shared) { + if (!bo->fence) + return 0; + if (bo->fence <= *radeon->cfence) { + LIST_DELINIT(&bo->fencedlist); + bo->fence = 0; + return 0; + } + } + + /* Zero out args to make valgrind happy */ + memset(&args, 0, sizeof(args)); + args.handle = bo->handle; + do { + ret = drmCommandWriteRead(radeon->fd, DRM_RADEON_GEM_WAIT_IDLE, + &args, sizeof(args)); + } while (ret == -EBUSY); + return ret; +} + +int radeon_bo_busy(struct radeon *radeon, struct radeon_bo *bo, uint32_t *domain) +{ + struct drm_radeon_gem_busy args; + int ret; + + if (!bo->shared) { + if (!bo->fence) + return 0; + if (bo->fence <= *radeon->cfence) { + LIST_DELINIT(&bo->fencedlist); + bo->fence = 0; + return 0; + } + } + + memset(&args, 0, sizeof(args)); + args.handle = bo->handle; + args.domain = 0; + + ret = drmCommandWriteRead(radeon->fd, DRM_RADEON_GEM_BUSY, + &args, sizeof(args)); + + *domain = args.domain; + return ret; +} + +int radeon_bo_get_tiling_flags(struct radeon *radeon, + struct radeon_bo *bo, + uint32_t *tiling_flags, + uint32_t *pitch) +{ + struct drm_radeon_gem_get_tiling args; + int ret; + + args.handle = bo->handle; + ret = drmCommandWriteRead(radeon->fd, DRM_RADEON_GEM_GET_TILING, + &args, sizeof(args)); + if (ret) + return ret; + + *tiling_flags = args.tiling_flags; + *pitch = args.pitch; + return ret; +} + +int radeon_bo_get_name(struct radeon *radeon, + struct radeon_bo *bo, + uint32_t *name) +{ + struct drm_gem_flink flink; + int ret; + + flink.handle = bo->handle; + ret = drmIoctl(radeon->fd, DRM_IOCTL_GEM_FLINK, &flink); + if (ret) + return ret; + + *name = flink.name; + return ret; +} diff --git a/src/gallium/winsys/r600/drm/radeon_pciid.c b/src/gallium/winsys/r600/drm/radeon_pciid.c new file mode 100644 index 0000000..4e1e746 --- /dev/null +++ b/src/gallium/winsys/r600/drm/radeon_pciid.c @@ -0,0 +1,500 @@ +/* + * Copyright 2010 Jerome Glisse + * + * 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. + * + * Authors: + * Jerome Glisse + */ +#include +#include "r600_priv.h" + +struct pci_id { + unsigned vendor; + unsigned device; + unsigned family; +}; + +struct pci_id radeon_pci_id[] = { + {0x1002, 0x3150, CHIP_RV380}, + {0x1002, 0x3152, CHIP_RV380}, + {0x1002, 0x3154, CHIP_RV380}, + {0x1002, 0x3E50, CHIP_RV380}, + {0x1002, 0x3E54, CHIP_RV380}, + {0x1002, 0x4136, CHIP_RS100}, + {0x1002, 0x4137, CHIP_RS200}, + {0x1002, 0x4144, CHIP_R300}, + {0x1002, 0x4145, CHIP_R300}, + {0x1002, 0x4146, CHIP_R300}, + {0x1002, 0x4147, CHIP_R300}, + {0x1002, 0x4148, CHIP_R350}, + {0x1002, 0x4149, CHIP_R350}, + {0x1002, 0x414A, CHIP_R350}, + {0x1002, 0x414B, CHIP_R350}, + {0x1002, 0x4150, CHIP_RV350}, + {0x1002, 0x4151, CHIP_RV350}, + {0x1002, 0x4152, CHIP_RV350}, + {0x1002, 0x4153, CHIP_RV350}, + {0x1002, 0x4154, CHIP_RV350}, + {0x1002, 0x4155, CHIP_RV350}, + {0x1002, 0x4156, CHIP_RV350}, + {0x1002, 0x4237, CHIP_RS200}, + {0x1002, 0x4242, CHIP_R200}, + {0x1002, 0x4243, CHIP_R200}, + {0x1002, 0x4336, CHIP_RS100}, + {0x1002, 0x4337, CHIP_RS200}, + {0x1002, 0x4437, CHIP_RS200}, + {0x1002, 0x4966, CHIP_RV250}, + {0x1002, 0x4967, CHIP_RV250}, + {0x1002, 0x4A48, CHIP_R420}, + {0x1002, 0x4A49, CHIP_R420}, + {0x1002, 0x4A4A, CHIP_R420}, + {0x1002, 0x4A4B, CHIP_R420}, + {0x1002, 0x4A4C, CHIP_R420}, + {0x1002, 0x4A4D, CHIP_R420}, + {0x1002, 0x4A4E, CHIP_R420}, + {0x1002, 0x4A4F, CHIP_R420}, + {0x1002, 0x4A50, CHIP_R420}, + {0x1002, 0x4A54, CHIP_R420}, + {0x1002, 0x4B48, CHIP_R420}, + {0x1002, 0x4B49, CHIP_R420}, + {0x1002, 0x4B4A, CHIP_R420}, + {0x1002, 0x4B4B, CHIP_R420}, + {0x1002, 0x4B4C, CHIP_R420}, + {0x1002, 0x4C57, CHIP_RV200}, + {0x1002, 0x4C58, CHIP_RV200}, + {0x1002, 0x4C59, CHIP_RV100}, + {0x1002, 0x4C5A, CHIP_RV100}, + {0x1002, 0x4C64, CHIP_RV250}, + {0x1002, 0x4C66, CHIP_RV250}, + {0x1002, 0x4C67, CHIP_RV250}, + {0x1002, 0x4E44, CHIP_R300}, + {0x1002, 0x4E45, CHIP_R300}, + {0x1002, 0x4E46, CHIP_R300}, + {0x1002, 0x4E47, CHIP_R300}, + {0x1002, 0x4E48, CHIP_R350}, + {0x1002, 0x4E49, CHIP_R350}, + {0x1002, 0x4E4A, CHIP_R350}, + {0x1002, 0x4E4B, CHIP_R350}, + {0x1002, 0x4E50, CHIP_RV350}, + {0x1002, 0x4E51, CHIP_RV350}, + {0x1002, 0x4E52, CHIP_RV350}, + {0x1002, 0x4E53, CHIP_RV350}, + {0x1002, 0x4E54, CHIP_RV350}, + {0x1002, 0x4E56, CHIP_RV350}, + {0x1002, 0x5144, CHIP_R100}, + {0x1002, 0x5145, CHIP_R100}, + {0x1002, 0x5146, CHIP_R100}, + {0x1002, 0x5147, CHIP_R100}, + {0x1002, 0x5148, CHIP_R200}, + {0x1002, 0x514C, CHIP_R200}, + {0x1002, 0x514D, CHIP_R200}, + {0x1002, 0x5157, CHIP_RV200}, + {0x1002, 0x5158, CHIP_RV200}, + {0x1002, 0x5159, CHIP_RV100}, + {0x1002, 0x515A, CHIP_RV100}, + {0x1002, 0x515E, CHIP_RV100}, + {0x1002, 0x5460, CHIP_RV380}, + {0x1002, 0x5462, CHIP_RV380}, + {0x1002, 0x5464, CHIP_RV380}, + {0x1002, 0x5657, CHIP_RV380}, + {0x1002, 0x5548, CHIP_R423}, + {0x1002, 0x5549, CHIP_R423}, + {0x1002, 0x554A, CHIP_R423}, + {0x1002, 0x554B, CHIP_R423}, + {0x1002, 0x554C, CHIP_R423}, + {0x1002, 0x554D, CHIP_R423}, + {0x1002, 0x554E, CHIP_R423}, + {0x1002, 0x554F, CHIP_R423}, + {0x1002, 0x5550, CHIP_R423}, + {0x1002, 0x5551, CHIP_R423}, + {0x1002, 0x5552, CHIP_R423}, + {0x1002, 0x5554, CHIP_R423}, + {0x1002, 0x564A, CHIP_RV410}, + {0x1002, 0x564B, CHIP_RV410}, + {0x1002, 0x564F, CHIP_RV410}, + {0x1002, 0x5652, CHIP_RV410}, + {0x1002, 0x5653, CHIP_RV410}, + {0x1002, 0x5834, CHIP_RS300}, + {0x1002, 0x5835, CHIP_RS300}, + {0x1002, 0x5954, CHIP_RS480}, + {0x1002, 0x5955, CHIP_RS480}, + {0x1002, 0x5974, CHIP_RS480}, + {0x1002, 0x5975, CHIP_RS480}, + {0x1002, 0x5960, CHIP_RV280}, + {0x1002, 0x5961, CHIP_RV280}, + {0x1002, 0x5962, CHIP_RV280}, + {0x1002, 0x5964, CHIP_RV280}, + {0x1002, 0x5965, CHIP_RV280}, + {0x1002, 0x5969, CHIP_RV100}, + {0x1002, 0x5a41, CHIP_RS400}, + {0x1002, 0x5a42, CHIP_RS400}, + {0x1002, 0x5a61, CHIP_RS400}, + {0x1002, 0x5a62, CHIP_RS400}, + {0x1002, 0x5b60, CHIP_RV380}, + {0x1002, 0x5b62, CHIP_RV380}, + {0x1002, 0x5b63, CHIP_RV380}, + {0x1002, 0x5b64, CHIP_RV380}, + {0x1002, 0x5b65, CHIP_RV380}, + {0x1002, 0x5c61, CHIP_RV280}, + {0x1002, 0x5c63, CHIP_RV280}, + {0x1002, 0x5d48, CHIP_R423}, + {0x1002, 0x5d49, CHIP_R423}, + {0x1002, 0x5d4a, CHIP_R423}, + {0x1002, 0x5d4c, CHIP_R423}, + {0x1002, 0x5d4d, CHIP_R423}, + {0x1002, 0x5d4e, CHIP_R423}, + {0x1002, 0x5d4f, CHIP_R423}, + {0x1002, 0x5d50, CHIP_R423}, + {0x1002, 0x5d52, CHIP_R423}, + {0x1002, 0x5d57, CHIP_R423}, + {0x1002, 0x5e48, CHIP_RV410}, + {0x1002, 0x5e4a, CHIP_RV410}, + {0x1002, 0x5e4b, CHIP_RV410}, + {0x1002, 0x5e4c, CHIP_RV410}, + {0x1002, 0x5e4d, CHIP_RV410}, + {0x1002, 0x5e4f, CHIP_RV410}, + {0x1002, 0x6880, CHIP_CYPRESS}, + {0x1002, 0x6888, CHIP_CYPRESS}, + {0x1002, 0x6889, CHIP_CYPRESS}, + {0x1002, 0x688A, CHIP_CYPRESS}, + {0x1002, 0x6898, CHIP_CYPRESS}, + {0x1002, 0x6899, CHIP_CYPRESS}, + {0x1002, 0x689c, CHIP_HEMLOCK}, + {0x1002, 0x689d, CHIP_HEMLOCK}, + {0x1002, 0x689e, CHIP_CYPRESS}, + {0x1002, 0x68a0, CHIP_JUNIPER}, + {0x1002, 0x68a1, CHIP_JUNIPER}, + {0x1002, 0x68a8, CHIP_JUNIPER}, + {0x1002, 0x68a9, CHIP_JUNIPER}, + {0x1002, 0x68b0, CHIP_JUNIPER}, + {0x1002, 0x68b8, CHIP_JUNIPER}, + {0x1002, 0x68b9, CHIP_JUNIPER}, + {0x1002, 0x68be, CHIP_JUNIPER}, + {0x1002, 0x68c0, CHIP_REDWOOD}, + {0x1002, 0x68c1, CHIP_REDWOOD}, + {0x1002, 0x68c8, CHIP_REDWOOD}, + {0x1002, 0x68c9, CHIP_REDWOOD}, + {0x1002, 0x68d8, CHIP_REDWOOD}, + {0x1002, 0x68d9, CHIP_REDWOOD}, + {0x1002, 0x68da, CHIP_REDWOOD}, + {0x1002, 0x68de, CHIP_REDWOOD}, + {0x1002, 0x68e0, CHIP_CEDAR}, + {0x1002, 0x68e1, CHIP_CEDAR}, + {0x1002, 0x68e4, CHIP_CEDAR}, + {0x1002, 0x68e5, CHIP_CEDAR}, + {0x1002, 0x68e8, CHIP_CEDAR}, + {0x1002, 0x68e9, CHIP_CEDAR}, + {0x1002, 0x68f1, CHIP_CEDAR}, + {0x1002, 0x68f8, CHIP_CEDAR}, + {0x1002, 0x68f9, CHIP_CEDAR}, + {0x1002, 0x68fe, CHIP_CEDAR}, + {0x1002, 0x7100, CHIP_R520}, + {0x1002, 0x7101, CHIP_R520}, + {0x1002, 0x7102, CHIP_R520}, + {0x1002, 0x7103, CHIP_R520}, + {0x1002, 0x7104, CHIP_R520}, + {0x1002, 0x7105, CHIP_R520}, + {0x1002, 0x7106, CHIP_R520}, + {0x1002, 0x7108, CHIP_R520}, + {0x1002, 0x7109, CHIP_R520}, + {0x1002, 0x710A, CHIP_R520}, + {0x1002, 0x710B, CHIP_R520}, + {0x1002, 0x710C, CHIP_R520}, + {0x1002, 0x710E, CHIP_R520}, + {0x1002, 0x710F, CHIP_R520}, + {0x1002, 0x7140, CHIP_RV515}, + {0x1002, 0x7141, CHIP_RV515}, + {0x1002, 0x7142, CHIP_RV515}, + {0x1002, 0x7143, CHIP_RV515}, + {0x1002, 0x7144, CHIP_RV515}, + {0x1002, 0x7145, CHIP_RV515}, + {0x1002, 0x7146, CHIP_RV515}, + {0x1002, 0x7147, CHIP_RV515}, + {0x1002, 0x7149, CHIP_RV515}, + {0x1002, 0x714A, CHIP_RV515}, + {0x1002, 0x714B, CHIP_RV515}, + {0x1002, 0x714C, CHIP_RV515}, + {0x1002, 0x714D, CHIP_RV515}, + {0x1002, 0x714E, CHIP_RV515}, + {0x1002, 0x714F, CHIP_RV515}, + {0x1002, 0x7151, CHIP_RV515}, + {0x1002, 0x7152, CHIP_RV515}, + {0x1002, 0x7153, CHIP_RV515}, + {0x1002, 0x715E, CHIP_RV515}, + {0x1002, 0x715F, CHIP_RV515}, + {0x1002, 0x7180, CHIP_RV515}, + {0x1002, 0x7181, CHIP_RV515}, + {0x1002, 0x7183, CHIP_RV515}, + {0x1002, 0x7186, CHIP_RV515}, + {0x1002, 0x7187, CHIP_RV515}, + {0x1002, 0x7188, CHIP_RV515}, + {0x1002, 0x718A, CHIP_RV515}, + {0x1002, 0x718B, CHIP_RV515}, + {0x1002, 0x718C, CHIP_RV515}, + {0x1002, 0x718D, CHIP_RV515}, + {0x1002, 0x718F, CHIP_RV515}, + {0x1002, 0x7193, CHIP_RV515}, + {0x1002, 0x7196, CHIP_RV515}, + {0x1002, 0x719B, CHIP_RV515}, + {0x1002, 0x719F, CHIP_RV515}, + {0x1002, 0x71C0, CHIP_RV530}, + {0x1002, 0x71C1, CHIP_RV530}, + {0x1002, 0x71C2, CHIP_RV530}, + {0x1002, 0x71C3, CHIP_RV530}, + {0x1002, 0x71C4, CHIP_RV530}, + {0x1002, 0x71C5, CHIP_RV530}, + {0x1002, 0x71C6, CHIP_RV530}, + {0x1002, 0x71C7, CHIP_RV530}, + {0x1002, 0x71CD, CHIP_RV530}, + {0x1002, 0x71CE, CHIP_RV530}, + {0x1002, 0x71D2, CHIP_RV530}, + {0x1002, 0x71D4, CHIP_RV530}, + {0x1002, 0x71D5, CHIP_RV530}, + {0x1002, 0x71D6, CHIP_RV530}, + {0x1002, 0x71DA, CHIP_RV530}, + {0x1002, 0x71DE, CHIP_RV530}, + {0x1002, 0x7200, CHIP_RV515}, + {0x1002, 0x7210, CHIP_RV515}, + {0x1002, 0x7211, CHIP_RV515}, + {0x1002, 0x7240, CHIP_R580}, + {0x1002, 0x7243, CHIP_R580}, + {0x1002, 0x7244, CHIP_R580}, + {0x1002, 0x7245, CHIP_R580}, + {0x1002, 0x7246, CHIP_R580}, + {0x1002, 0x7247, CHIP_R580}, + {0x1002, 0x7248, CHIP_R580}, + {0x1002, 0x7249, CHIP_R580}, + {0x1002, 0x724A, CHIP_R580}, + {0x1002, 0x724B, CHIP_R580}, + {0x1002, 0x724C, CHIP_R580}, + {0x1002, 0x724D, CHIP_R580}, + {0x1002, 0x724E, CHIP_R580}, + {0x1002, 0x724F, CHIP_R580}, + {0x1002, 0x7280, CHIP_RV570}, + {0x1002, 0x7281, CHIP_RV560}, + {0x1002, 0x7283, CHIP_RV560}, + {0x1002, 0x7284, CHIP_R580}, + {0x1002, 0x7287, CHIP_RV560}, + {0x1002, 0x7288, CHIP_RV570}, + {0x1002, 0x7289, CHIP_RV570}, + {0x1002, 0x728B, CHIP_RV570}, + {0x1002, 0x728C, CHIP_RV570}, + {0x1002, 0x7290, CHIP_RV560}, + {0x1002, 0x7291, CHIP_RV560}, + {0x1002, 0x7293, CHIP_RV560}, + {0x1002, 0x7297, CHIP_RV560}, + {0x1002, 0x7834, CHIP_RS300}, + {0x1002, 0x7835, CHIP_RS300}, + {0x1002, 0x791e, CHIP_RS690}, + {0x1002, 0x791f, CHIP_RS690}, + {0x1002, 0x793f, CHIP_RS600}, + {0x1002, 0x7941, CHIP_RS600}, + {0x1002, 0x7942, CHIP_RS600}, + {0x1002, 0x796c, CHIP_RS740}, + {0x1002, 0x796d, CHIP_RS740}, + {0x1002, 0x796e, CHIP_RS740}, + {0x1002, 0x796f, CHIP_RS740}, + {0x1002, 0x9400, CHIP_R600}, + {0x1002, 0x9401, CHIP_R600}, + {0x1002, 0x9402, CHIP_R600}, + {0x1002, 0x9403, CHIP_R600}, + {0x1002, 0x9405, CHIP_R600}, + {0x1002, 0x940A, CHIP_R600}, + {0x1002, 0x940B, CHIP_R600}, + {0x1002, 0x940F, CHIP_R600}, + {0x1002, 0x94A0, CHIP_RV740}, + {0x1002, 0x94A1, CHIP_RV740}, + {0x1002, 0x94A3, CHIP_RV740}, + {0x1002, 0x94B1, CHIP_RV740}, + {0x1002, 0x94B3, CHIP_RV740}, + {0x1002, 0x94B4, CHIP_RV740}, + {0x1002, 0x94B5, CHIP_RV740}, + {0x1002, 0x94B9, CHIP_RV740}, + {0x1002, 0x9440, CHIP_RV770}, + {0x1002, 0x9441, CHIP_RV770}, + {0x1002, 0x9442, CHIP_RV770}, + {0x1002, 0x9443, CHIP_RV770}, + {0x1002, 0x9444, CHIP_RV770}, + {0x1002, 0x9446, CHIP_RV770}, + {0x1002, 0x944A, CHIP_RV770}, + {0x1002, 0x944B, CHIP_RV770}, + {0x1002, 0x944C, CHIP_RV770}, + {0x1002, 0x944E, CHIP_RV770}, + {0x1002, 0x9450, CHIP_RV770}, + {0x1002, 0x9452, CHIP_RV770}, + {0x1002, 0x9456, CHIP_RV770}, + {0x1002, 0x945A, CHIP_RV770}, + {0x1002, 0x945B, CHIP_RV770}, + {0x1002, 0x9460, CHIP_RV770}, + {0x1002, 0x9462, CHIP_RV770}, + {0x1002, 0x946A, CHIP_RV770}, + {0x1002, 0x946B, CHIP_RV770}, + {0x1002, 0x947A, CHIP_RV770}, + {0x1002, 0x947B, CHIP_RV770}, + {0x1002, 0x9480, CHIP_RV730}, + {0x1002, 0x9487, CHIP_RV730}, + {0x1002, 0x9488, CHIP_RV730}, + {0x1002, 0x9489, CHIP_RV730}, + {0x1002, 0x948F, CHIP_RV730}, + {0x1002, 0x9490, CHIP_RV730}, + {0x1002, 0x9491, CHIP_RV730}, + {0x1002, 0x9495, CHIP_RV730}, + {0x1002, 0x9498, CHIP_RV730}, + {0x1002, 0x949C, CHIP_RV730}, + {0x1002, 0x949E, CHIP_RV730}, + {0x1002, 0x949F, CHIP_RV730}, + {0x1002, 0x94C0, CHIP_RV610}, + {0x1002, 0x94C1, CHIP_RV610}, + {0x1002, 0x94C3, CHIP_RV610}, + {0x1002, 0x94C4, CHIP_RV610}, + {0x1002, 0x94C5, CHIP_RV610}, + {0x1002, 0x94C6, CHIP_RV610}, + {0x1002, 0x94C7, CHIP_RV610}, + {0x1002, 0x94C8, CHIP_RV610}, + {0x1002, 0x94C9, CHIP_RV610}, + {0x1002, 0x94CB, CHIP_RV610}, + {0x1002, 0x94CC, CHIP_RV610}, + {0x1002, 0x94CD, CHIP_RV610}, + {0x1002, 0x9500, CHIP_RV670}, + {0x1002, 0x9501, CHIP_RV670}, + {0x1002, 0x9504, CHIP_RV670}, + {0x1002, 0x9505, CHIP_RV670}, + {0x1002, 0x9506, CHIP_RV670}, + {0x1002, 0x9507, CHIP_RV670}, + {0x1002, 0x9508, CHIP_RV670}, + {0x1002, 0x9509, CHIP_RV670}, + {0x1002, 0x950F, CHIP_RV670}, + {0x1002, 0x9511, CHIP_RV670}, + {0x1002, 0x9515, CHIP_RV670}, + {0x1002, 0x9517, CHIP_RV670}, + {0x1002, 0x9519, CHIP_RV670}, + {0x1002, 0x9540, CHIP_RV710}, + {0x1002, 0x9541, CHIP_RV710}, + {0x1002, 0x9542, CHIP_RV710}, + {0x1002, 0x954E, CHIP_RV710}, + {0x1002, 0x954F, CHIP_RV710}, + {0x1002, 0x9552, CHIP_RV710}, + {0x1002, 0x9553, CHIP_RV710}, + {0x1002, 0x9555, CHIP_RV710}, + {0x1002, 0x9557, CHIP_RV710}, + {0x1002, 0x9580, CHIP_RV630}, + {0x1002, 0x9581, CHIP_RV630}, + {0x1002, 0x9583, CHIP_RV630}, + {0x1002, 0x9586, CHIP_RV630}, + {0x1002, 0x9587, CHIP_RV630}, + {0x1002, 0x9588, CHIP_RV630}, + {0x1002, 0x9589, CHIP_RV630}, + {0x1002, 0x958A, CHIP_RV630}, + {0x1002, 0x958B, CHIP_RV630}, + {0x1002, 0x958C, CHIP_RV630}, + {0x1002, 0x958D, CHIP_RV630}, + {0x1002, 0x958E, CHIP_RV630}, + {0x1002, 0x958F, CHIP_RV630}, + {0x1002, 0x9590, CHIP_RV635}, + {0x1002, 0x9591, CHIP_RV635}, + {0x1002, 0x9593, CHIP_RV635}, + {0x1002, 0x9595, CHIP_RV635}, + {0x1002, 0x9596, CHIP_RV635}, + {0x1002, 0x9597, CHIP_RV635}, + {0x1002, 0x9598, CHIP_RV635}, + {0x1002, 0x9599, CHIP_RV635}, + {0x1002, 0x959B, CHIP_RV635}, + {0x1002, 0x95C0, CHIP_RV620}, + {0x1002, 0x95C2, CHIP_RV620}, + {0x1002, 0x95C4, CHIP_RV620}, + {0x1002, 0x95C5, CHIP_RV620}, + {0x1002, 0x95C6, CHIP_RV620}, + {0x1002, 0x95C7, CHIP_RV620}, + {0x1002, 0x95C9, CHIP_RV620}, + {0x1002, 0x95CC, CHIP_RV620}, + {0x1002, 0x95CD, CHIP_RV620}, + {0x1002, 0x95CE, CHIP_RV620}, + {0x1002, 0x95CF, CHIP_RV620}, + {0x1002, 0x9610, CHIP_RS780}, + {0x1002, 0x9611, CHIP_RS780}, + {0x1002, 0x9612, CHIP_RS780}, + {0x1002, 0x9613, CHIP_RS780}, + {0x1002, 0x9614, CHIP_RS780}, + {0x1002, 0x9615, CHIP_RS780}, + {0x1002, 0x9616, CHIP_RS780}, + {0x1002, 0x9710, CHIP_RS880}, + {0x1002, 0x9711, CHIP_RS880}, + {0x1002, 0x9712, CHIP_RS880}, + {0x1002, 0x9713, CHIP_RS880}, + {0x1002, 0x9714, CHIP_RS880}, + {0x1002, 0x9715, CHIP_RS880}, + {0x1002, 0x9802, CHIP_PALM}, + {0x1002, 0x9803, CHIP_PALM}, + {0x1002, 0x9804, CHIP_PALM}, + {0x1002, 0x9805, CHIP_PALM}, + {0x1002, 0x9806, CHIP_PALM}, + {0x1002, 0x9807, CHIP_PALM}, + {0x1002, 0x6720, CHIP_BARTS}, + {0x1002, 0x6721, CHIP_BARTS}, + {0x1002, 0x6722, CHIP_BARTS}, + {0x1002, 0x6723, CHIP_BARTS}, + {0x1002, 0x6724, CHIP_BARTS}, + {0x1002, 0x6725, CHIP_BARTS}, + {0x1002, 0x6726, CHIP_BARTS}, + {0x1002, 0x6727, CHIP_BARTS}, + {0x1002, 0x6728, CHIP_BARTS}, + {0x1002, 0x6729, CHIP_BARTS}, + {0x1002, 0x6738, CHIP_BARTS}, + {0x1002, 0x6739, CHIP_BARTS}, + {0x1002, 0x6740, CHIP_TURKS}, + {0x1002, 0x6741, CHIP_TURKS}, + {0x1002, 0x6742, CHIP_TURKS}, + {0x1002, 0x6743, CHIP_TURKS}, + {0x1002, 0x6744, CHIP_TURKS}, + {0x1002, 0x6745, CHIP_TURKS}, + {0x1002, 0x6746, CHIP_TURKS}, + {0x1002, 0x6747, CHIP_TURKS}, + {0x1002, 0x6748, CHIP_TURKS}, + {0x1002, 0x6749, CHIP_TURKS}, + {0x1002, 0x6750, CHIP_TURKS}, + {0x1002, 0x6758, CHIP_TURKS}, + {0x1002, 0x6759, CHIP_TURKS}, + {0x1002, 0x6760, CHIP_CAICOS}, + {0x1002, 0x6761, CHIP_CAICOS}, + {0x1002, 0x6762, CHIP_CAICOS}, + {0x1002, 0x6763, CHIP_CAICOS}, + {0x1002, 0x6764, CHIP_CAICOS}, + {0x1002, 0x6765, CHIP_CAICOS}, + {0x1002, 0x6766, CHIP_CAICOS}, + {0x1002, 0x6767, CHIP_CAICOS}, + {0x1002, 0x6768, CHIP_CAICOS}, + {0x1002, 0x6770, CHIP_CAICOS}, + {0x1002, 0x6779, CHIP_CAICOS}, + {0, 0}, +}; + +unsigned radeon_family_from_device(unsigned device) +{ + unsigned i; + + for (i = 0; ; i++) { + if (!radeon_pci_id[i].vendor) + return CHIP_UNKNOWN; + if (radeon_pci_id[i].device == device) + return radeon_pci_id[i].family; + } + return CHIP_UNKNOWN; +} diff --git a/src/gallium/winsys/radeon/drm/Makefile b/src/gallium/winsys/radeon/drm/Makefile new file mode 100644 index 0000000..aa73edd --- /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_common.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 0000000..2dbf61a --- /dev/null +++ b/src/gallium/winsys/radeon/drm/SConscript @@ -0,0 +1,19 @@ +Import('*') + +env = env.Clone() + +radeon_sources = [ + 'radeon_drm_buffer.c', + 'radeon_drm_common.c', + 'radeon_r300.c', +] + +env.ParseConfig('pkg-config --cflags libdrm_radeon') +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_drm_buffer.c b/src/gallium/winsys/radeon/drm/radeon_drm_buffer.c new file mode 100644 index 0000000..dc4b517 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_drm_buffer.c @@ -0,0 +1,564 @@ +#include "radeon_cs_gem.h" +#include "radeon_drm_buffer.h" + +#include "util/u_hash_table.h" +#include "util/u_memory.h" +#include "util/u_simple_list.h" +#include "pipebuffer/pb_bufmgr.h" +#include "os/os_thread.h" + +#include "state_tracker/drm_driver.h" + +#include +#include +#include + +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 { + /* Base class. */ + struct pb_manager base; + + /* Winsys. */ + struct radeon_drm_winsys *rws; + + /* List of mapped buffers and its mutex. */ + struct radeon_drm_buffer buffer_map_list; + pipe_mutex buffer_map_list_mutex; + + /* List of buffer handles and its mutex. */ + struct util_hash_table *buffer_handles; + pipe_mutex buffer_handles_mutex; +}; + +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); + int name; + + if (buf->bo->ptr != NULL) { + pipe_mutex_lock(buf->mgr->buffer_map_list_mutex); + /* Now test it again inside the mutex. */ + if (buf->bo->ptr != NULL) { + remove_from_list(buf); + radeon_bo_unmap(buf->bo); + buf->bo->ptr = NULL; + } + pipe_mutex_unlock(buf->mgr->buffer_map_list_mutex); + } + name = radeon_gem_name_bo(buf->bo); + if (name) { + pipe_mutex_lock(buf->mgr->buffer_handles_mutex); + util_hash_table_remove(buf->mgr->buffer_handles, + (void*)(uintptr_t)name); + pipe_mutex_unlock(buf->mgr->buffer_handles_mutex); + } + radeon_bo_unref(buf->bo); + + FREE(buf); +} + +static unsigned get_pb_usage_from_transfer_flags(enum pipe_transfer_usage usage) +{ + unsigned res = 0; + + if (usage & PIPE_TRANSFER_READ) + res |= PB_USAGE_CPU_READ; + + if (usage & PIPE_TRANSFER_WRITE) + res |= PB_USAGE_CPU_WRITE; + + if (usage & PIPE_TRANSFER_DONTBLOCK) + res |= PB_USAGE_DONTBLOCK; + + if (usage & PIPE_TRANSFER_UNSYNCHRONIZED) + res |= PB_USAGE_UNSYNCHRONIZED; + + return res; +} + +static void * +radeon_drm_buffer_map_internal(struct pb_buffer *_buf, + unsigned flags, void *flush_ctx) +{ + struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf); + struct radeon_drm_cs *cs = flush_ctx; + int write = 0; + + /* Note how we use radeon_bo_is_referenced_by_cs here. There are + * basically two places this map function can be called from: + * - pb_map + * - create_buffer (in the buffer reuse case) + * + * Since pb managers are per-winsys managers, not per-context managers, + * and we shouldn't reuse buffers if they are in-use in any context, + * we simply ask: is this buffer referenced by *any* CS? + * + * The problem with buffer_create is that it comes from pipe_screen, + * so we have no CS to look at, though luckily the following code + * is sufficient to tell whether the buffer is in use. */ + if (flags & PB_USAGE_DONTBLOCK) { + if (_buf->base.usage & RADEON_PB_USAGE_VERTEX) + if (radeon_bo_is_referenced_by_cs(buf->bo, NULL)) + return NULL; + } + + if (buf->bo->ptr != NULL) { + pipe_mutex_lock(buf->mgr->buffer_map_list_mutex); + /* Now test ptr again inside the mutex. We might have gotten a race + * during the first test. */ + if (buf->bo->ptr != NULL) { + remove_from_list(buf); + } + pipe_mutex_unlock(buf->mgr->buffer_map_list_mutex); + return buf->bo->ptr; + } + + if (flags & PB_USAGE_DONTBLOCK) { + uint32_t domain; + if (radeon_bo_is_busy(buf->bo, &domain)) + return NULL; + } + + /* If we don't have any CS and the buffer is referenced, + * we cannot flush. */ + assert(cs || !radeon_bo_is_referenced_by_cs(buf->bo, NULL)); + + if (cs && radeon_bo_is_referenced_by_cs(buf->bo, cs->cs)) { + cs->flush_cs(cs->flush_data); + } + + if (flags & PB_USAGE_CPU_WRITE) { + write = 1; + } + + if (radeon_bo_map(buf->bo, write)) { + return NULL; + } + + pipe_mutex_lock(buf->mgr->buffer_map_list_mutex); + remove_from_list(buf); + pipe_mutex_unlock(buf->mgr->buffer_map_list_mutex); + return buf->bo->ptr; +} + +static void +radeon_drm_buffer_unmap_internal(struct pb_buffer *_buf) +{ + struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf); + pipe_mutex_lock(buf->mgr->buffer_map_list_mutex); + if (is_empty_list(buf)) { /* = is not inserted... */ + insert_at_tail(&buf->mgr->buffer_map_list, buf); + } + pipe_mutex_unlock(buf->mgr->buffer_map_list_mutex); +} + +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_internal, + radeon_drm_buffer_unmap_internal, + radeon_drm_buffer_validate, + radeon_drm_buffer_fence, + radeon_drm_buffer_get_base_buffer, +}; + +static struct pb_buffer * +radeon_drm_bufmgr_create_buffer_from_handle_unsafe(struct pb_manager *_mgr, + uint32_t handle) +{ + struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); + struct radeon_drm_winsys *rws = mgr->rws; + struct radeon_drm_buffer *buf; + struct radeon_bo *bo; + + buf = util_hash_table_get(mgr->buffer_handles, (void*)(uintptr_t)handle); + + if (buf) { + struct pb_buffer *b = NULL; + pb_reference(&b, &buf->base); + return b; + } + + 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 = PB_USAGE_GPU_WRITE | PB_USAGE_GPU_READ; + buf->base.base.size = bo->size; + buf->base.vtbl = &radeon_drm_buffer_vtbl; + buf->mgr = mgr; + + buf->bo = bo; + + util_hash_table_set(mgr->buffer_handles, (void*)(uintptr_t)handle, buf); + + return &buf->base; +} + +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 pb_buffer *pb; + + pipe_mutex_lock(mgr->buffer_handles_mutex); + pb = radeon_drm_bufmgr_create_buffer_from_handle_unsafe(_mgr, handle); + pipe_mutex_unlock(mgr->buffer_handles_mutex); + + return pb; +} + +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_drm_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 = + (desc->usage & RADEON_PB_USAGE_DOMAIN_GTT ? RADEON_GEM_DOMAIN_GTT : 0) | + (desc->usage & RADEON_PB_USAGE_DOMAIN_VRAM ? RADEON_GEM_DOMAIN_VRAM : 0); + + 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); + util_hash_table_destroy(mgr->buffer_handles); + pipe_mutex_destroy(mgr->buffer_map_list_mutex); + pipe_mutex_destroy(mgr->buffer_handles_mutex); + FREE(mgr); +} + +static unsigned handle_hash(void *key) +{ + return (unsigned)key; +} + +static int handle_compare(void *key1, void *key2) +{ + return !((int)key1 == (int)key2); +} + +struct pb_manager * +radeon_drm_bufmgr_create(struct radeon_drm_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); + mgr->buffer_handles = util_hash_table_create(handle_hash, handle_compare); + pipe_mutex_init(mgr->buffer_map_list_mutex); + pipe_mutex_init(mgr->buffer_handles_mutex); + return &mgr->base; +} + +static struct radeon_drm_buffer *get_drm_buffer(struct pb_buffer *_buf) +{ + struct radeon_drm_buffer *buf = NULL; + + 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); + + if (base_buf->vtbl == &radeon_drm_buffer_vtbl) + buf = radeon_drm_buffer(base_buf); + } + + return buf; +} + +static void *radeon_drm_buffer_map(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *buf, + struct r300_winsys_cs *cs, + enum pipe_transfer_usage usage) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + + return pb_map(_buf, get_pb_usage_from_transfer_flags(usage), radeon_drm_cs(cs)); +} + +static void radeon_drm_buffer_unmap(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *buf) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + + pb_unmap(_buf); +} + +boolean radeon_drm_bufmgr_get_handle(struct pb_buffer *_buf, + struct winsys_handle *whandle) +{ + 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) { + flink.handle = buf->bo->handle; + + if (ioctl(buf->mgr->rws->fd, DRM_IOCTL_GEM_FLINK, &flink)) { + 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; +} + +static void radeon_drm_buffer_get_tiling(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *_buf, + enum r300_buffer_tiling *microtiled, + enum r300_buffer_tiling *macrotiled) +{ + struct radeon_drm_buffer *buf = get_drm_buffer(radeon_pb_buffer(_buf)); + uint32_t flags = 0, pitch; + + radeon_bo_get_tiling(buf->bo, &flags, &pitch); + + *microtiled = R300_BUFFER_LINEAR; + *macrotiled = R300_BUFFER_LINEAR; + if (flags & RADEON_BO_FLAGS_MICRO_TILE) + *microtiled = R300_BUFFER_TILED; + + if (flags & RADEON_BO_FLAGS_MACRO_TILE) + *macrotiled = R300_BUFFER_TILED; +} + +static void radeon_drm_buffer_set_tiling(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *_buf, + enum r300_buffer_tiling microtiled, + enum r300_buffer_tiling macrotiled, + uint32_t pitch) +{ + struct radeon_drm_buffer *buf = get_drm_buffer(radeon_pb_buffer(_buf)); + uint32_t flags = 0; + 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_set_tiling(buf->bo, flags, pitch); +} + +static void radeon_drm_bufmgr_add_buffer(struct r300_winsys_cs *rcs, + struct r300_winsys_cs_buffer *_buf, + enum r300_buffer_domain rd, + enum r300_buffer_domain wd) +{ + struct radeon_drm_cs *cs = radeon_drm_cs(rcs); + struct radeon_bo *bo = (struct radeon_bo*)_buf; + + radeon_cs_space_add_persistent_bo(cs->cs, bo, rd, wd); +} + +static void radeon_drm_bufmgr_write_reloc(struct r300_winsys_cs *rcs, + struct r300_winsys_cs_buffer *_buf, + enum r300_buffer_domain rd, + enum r300_buffer_domain wd) +{ + struct radeon_drm_cs *cs = radeon_drm_cs(rcs); + struct radeon_bo *bo = (struct radeon_bo*)_buf; + int retval; + + cs->cs->cdw = cs->base.cdw; + retval = radeon_cs_write_reloc(cs->cs, bo, rd, wd, 0); + cs->base.cdw = cs->cs->cdw; + if (retval) { + fprintf(stderr, "radeon: Relocation of %p (%d, %d, %d) failed!\n", + bo, rd, wd, 0); + } +} + +static struct r300_winsys_cs_buffer *radeon_drm_get_cs_handle( + struct r300_winsys_screen *rws, + struct r300_winsys_buffer *_buf) +{ + /* return pure radeon_bo. */ + return (struct r300_winsys_cs_buffer*) + get_drm_buffer(radeon_pb_buffer(_buf))->bo; +} + +static boolean radeon_drm_is_buffer_referenced(struct r300_winsys_cs *rcs, + struct r300_winsys_cs_buffer *_buf, + enum r300_reference_domain domain) +{ + struct radeon_drm_cs *cs = radeon_drm_cs(rcs); + struct radeon_bo *bo = (struct radeon_bo*)_buf; + uint32_t tmp; + + if (domain & R300_REF_CS) { + if (radeon_bo_is_referenced_by_cs(bo, cs->cs)) { + return TRUE; + } + } + + if (domain & R300_REF_HW) { + if (radeon_bo_is_busy(bo, &tmp)) { + return TRUE; + } + } + + return FALSE; +} + +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; + + pipe_mutex_lock(mgr->buffer_map_list_mutex); + + 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); + + pipe_mutex_unlock(mgr->buffer_map_list_mutex); +} + +static void radeon_drm_buffer_wait(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *_buf) +{ + struct radeon_drm_buffer *buf = get_drm_buffer(radeon_pb_buffer(_buf)); + + radeon_bo_wait(buf->bo); +} + +void radeon_drm_bufmgr_init_functions(struct radeon_drm_winsys *ws) +{ + ws->base.buffer_get_cs_handle = radeon_drm_get_cs_handle; + ws->base.buffer_set_tiling = radeon_drm_buffer_set_tiling; + ws->base.buffer_get_tiling = radeon_drm_buffer_get_tiling; + ws->base.buffer_map = radeon_drm_buffer_map; + ws->base.buffer_unmap = radeon_drm_buffer_unmap; + ws->base.buffer_wait = radeon_drm_buffer_wait; + ws->base.cs_is_buffer_referenced = radeon_drm_is_buffer_referenced; + ws->base.cs_add_buffer = radeon_drm_bufmgr_add_buffer; + ws->base.cs_write_reloc = radeon_drm_bufmgr_write_reloc; +} diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_buffer.h b/src/gallium/winsys/radeon/drm/radeon_drm_buffer.h new file mode 100644 index 0000000..494abdc --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_drm_buffer.h @@ -0,0 +1,53 @@ +/* + * 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_DRM_BUFFER_H +#define RADEON_DRM_BUFFER_H + +#include "radeon_winsys.h" + +#define RADEON_PB_USAGE_VERTEX (1 << 28) +#define RADEON_PB_USAGE_DOMAIN_GTT (1 << 29) +#define RADEON_PB_USAGE_DOMAIN_VRAM (1 << 30) + +static INLINE struct pb_buffer * +radeon_pb_buffer(struct r300_winsys_buffer *buffer) +{ + return (struct pb_buffer *)buffer; +} + +struct pb_manager *radeon_drm_bufmgr_create(struct radeon_drm_winsys *rws); +struct pb_buffer *radeon_drm_bufmgr_create_buffer_from_handle(struct pb_manager *_mgr, + uint32_t handle); +void radeon_drm_bufmgr_flush_maps(struct pb_manager *_mgr); +boolean radeon_drm_bufmgr_get_handle(struct pb_buffer *_buf, + struct winsys_handle *whandle); +void radeon_drm_bufmgr_init_functions(struct radeon_drm_winsys *ws); + +#endif diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_common.c b/src/gallium/winsys/radeon/drm/radeon_drm_common.c new file mode 100644 index 0000000..6bc6244 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_drm_common.c @@ -0,0 +1,239 @@ +/* + * 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_winsys.h" +#include "radeon_drm_buffer.h" +#include "radeon_drm_public.h" + +#include "pipebuffer/pb_bufmgr.h" +#include "util/u_memory.h" + +#include "state_tracker/drm_driver.h" + +#include +#include +#include +#include +#include + + +/* Enable/disable Hyper-Z access. Return TRUE on success. */ +static boolean radeon_set_hyperz_access(int fd, boolean enable) +{ +#ifndef RADEON_INFO_WANT_HYPERZ +#define RADEON_INFO_WANT_HYPERZ 7 +#endif + + struct drm_radeon_info info = {0}; + unsigned value = enable ? 1 : 0; + + if (!debug_get_bool_option("RADEON_HYPERZ", FALSE)) + return FALSE; + + info.value = (unsigned long)&value; + info.request = RADEON_INFO_WANT_HYPERZ; + + if (drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)) != 0) + return FALSE; + + if (enable && !value) + return FALSE; + + return TRUE; +} + +/* Helper function to do the ioctls needed for setup and init. */ +static void do_ioctls(struct radeon_drm_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(winsys->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 + + winsys->drm_2_3_0 = version->version_major > 2 || + version->version_minor >= 3; + + winsys->drm_2_6_0 = version->version_major > 2 || + (version->version_major == 2 && + version->version_minor >= 6); + + info.request = RADEON_INFO_DEVICE_ID; + retval = drmCommandWriteRead(winsys->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(winsys->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(winsys->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; + + winsys->hyperz = radeon_set_hyperz_access(winsys->fd, TRUE); + + retval = drmCommandWriteRead(winsys->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" + "radeon: HyperZ: %s\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, + winsys->hyperz ? "YES" : "NO"); + + drmFreeVersion(version); +} + +static void radeon_winsys_destroy(struct r300_winsys_screen *rws) +{ + struct radeon_drm_winsys *ws = (struct radeon_drm_winsys*)rws; + + ws->cman->destroy(ws->cman); + ws->kman->destroy(ws->kman); + + radeon_bo_manager_gem_dtor(ws->bom); + radeon_cs_manager_gem_dtor(ws->csm); + FREE(rws); +} + +struct r300_winsys_screen *r300_drm_winsys_screen_create(int fd) +{ + struct radeon_drm_winsys *ws = CALLOC_STRUCT(radeon_drm_winsys); + if (!ws) { + return NULL; + } + + ws->fd = fd; + do_ioctls(ws); + + if (!is_r3xx(ws->pci_id)) { + goto fail; + } + + /* Create managers. */ + ws->bom = radeon_bo_manager_gem_ctor(fd); + if (!ws->bom) + goto fail; + ws->csm = radeon_cs_manager_gem_ctor(fd); + if (!ws->csm) + goto fail; + ws->kman = radeon_drm_bufmgr_create(ws); + if (!ws->kman) + goto fail; + ws->cman = pb_cache_manager_create(ws->kman, 1000000); + if (!ws->cman) + goto fail; + + /* Set functions. */ + ws->base.destroy = radeon_winsys_destroy; + + radeon_drm_bufmgr_init_functions(ws); + radeon_winsys_init_functions(ws); + + return &ws->base; + +fail: + if (ws->bom) + radeon_bo_manager_gem_dtor(ws->bom); + if (ws->csm) + radeon_cs_manager_gem_dtor(ws->csm); + + if (ws->cman) + ws->cman->destroy(ws->cman); + if (ws->kman) + ws->kman->destroy(ws->kman); + + FREE(ws); + return NULL; +} diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_public.h b/src/gallium/winsys/radeon/drm/radeon_drm_public.h new file mode 100644 index 0000000..3a208cd --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_drm_public.h @@ -0,0 +1,222 @@ +#ifndef RADEON_DRM_PUBLIC_H +#define RADEON_DRM_PUBLIC_H + +#include "pipe/p_defines.h" + +struct r300_winsys_screen; + +struct r300_winsys_screen *r300_drm_winsys_screen_create(int fd); + +static INLINE boolean is_r3xx(int pciid) +{ + switch (pciid) { + case 0x4144: /* PCI_CHIP_R300_AD */ + case 0x4145: /* PCI_CHIP_R300_AE */ + case 0x4146: /* PCI_CHIP_R300_AF */ + case 0x4147: /* PCI_CHIP_R300_AG */ + case 0x4E44: /* PCI_CHIP_R300_ND */ + case 0x4E45: /* PCI_CHIP_R300_NE */ + case 0x4E46: /* PCI_CHIP_R300_NF */ + case 0x4E47: /* PCI_CHIP_R300_NG */ + case 0x4E48: /* PCI_CHIP_R350_NH */ + case 0x4E49: /* PCI_CHIP_R350_NI */ + case 0x4E4B: /* PCI_CHIP_R350_NK */ + case 0x4148: /* PCI_CHIP_R350_AH */ + case 0x4149: /* PCI_CHIP_R350_AI */ + case 0x414A: /* PCI_CHIP_R350_AJ */ + case 0x414B: /* PCI_CHIP_R350_AK */ + case 0x4E4A: /* PCI_CHIP_R360_NJ */ + case 0x4150: /* PCI_CHIP_RV350_AP */ + case 0x4151: /* PCI_CHIP_RV350_AQ */ + case 0x4152: /* PCI_CHIP_RV350_AR */ + case 0x4153: /* PCI_CHIP_RV350_AS */ + case 0x4154: /* PCI_CHIP_RV350_AT */ + case 0x4155: /* PCI_CHIP_RV350_AU */ + case 0x4156: /* PCI_CHIP_RV350_AV */ + case 0x4E50: /* PCI_CHIP_RV350_NP */ + case 0x4E51: /* PCI_CHIP_RV350_NQ */ + case 0x4E52: /* PCI_CHIP_RV350_NR */ + case 0x4E53: /* PCI_CHIP_RV350_NS */ + case 0x4E54: /* PCI_CHIP_RV350_NT */ + case 0x4E56: /* PCI_CHIP_RV350_NV */ + case 0x5460: /* PCI_CHIP_RV370_5460 */ + case 0x5462: /* PCI_CHIP_RV370_5462 */ + case 0x5464: /* PCI_CHIP_RV370_5464 */ + case 0x5B60: /* PCI_CHIP_RV370_5B60 */ + case 0x5B62: /* PCI_CHIP_RV370_5B62 */ + case 0x5B63: /* PCI_CHIP_RV370_5B63 */ + case 0x5B64: /* PCI_CHIP_RV370_5B64 */ + case 0x5B65: /* PCI_CHIP_RV370_5B65 */ + case 0x3150: /* PCI_CHIP_RV380_3150 */ + case 0x3152: /* PCI_CHIP_RV380_3152 */ + case 0x3154: /* PCI_CHIP_RV380_3154 */ + case 0x3155: /* PCI_CHIP_RV380_3155 */ + case 0x3E50: /* PCI_CHIP_RV380_3E50 */ + case 0x3E54: /* PCI_CHIP_RV380_3E54 */ + case 0x4A48: /* PCI_CHIP_R420_JH */ + case 0x4A49: /* PCI_CHIP_R420_JI */ + case 0x4A4A: /* PCI_CHIP_R420_JJ */ + case 0x4A4B: /* PCI_CHIP_R420_JK */ + case 0x4A4C: /* PCI_CHIP_R420_JL */ + case 0x4A4D: /* PCI_CHIP_R420_JM */ + case 0x4A4E: /* PCI_CHIP_R420_JN */ + case 0x4A4F: /* PCI_CHIP_R420_JO */ + case 0x4A50: /* PCI_CHIP_R420_JP */ + case 0x4A54: /* PCI_CHIP_R420_JT */ + case 0x5548: /* PCI_CHIP_R423_UH */ + case 0x5549: /* PCI_CHIP_R423_UI */ + case 0x554A: /* PCI_CHIP_R423_UJ */ + case 0x554B: /* PCI_CHIP_R423_UK */ + case 0x5550: /* PCI_CHIP_R423_5550 */ + case 0x5551: /* PCI_CHIP_R423_UQ */ + case 0x5552: /* PCI_CHIP_R423_UR */ + case 0x5554: /* PCI_CHIP_R423_UT */ + case 0x5D57: /* PCI_CHIP_R423_5D57 */ + case 0x554C: /* PCI_CHIP_R430_554C */ + case 0x554D: /* PCI_CHIP_R430_554D */ + case 0x554E: /* PCI_CHIP_R430_554E */ + case 0x554F: /* PCI_CHIP_R430_554F */ + case 0x5D48: /* PCI_CHIP_R430_5D48 */ + case 0x5D49: /* PCI_CHIP_R430_5D49 */ + case 0x5D4A: /* PCI_CHIP_R430_5D4A */ + case 0x5D4C: /* PCI_CHIP_R480_5D4C */ + case 0x5D4D: /* PCI_CHIP_R480_5D4D */ + case 0x5D4E: /* PCI_CHIP_R480_5D4E */ + case 0x5D4F: /* PCI_CHIP_R480_5D4F */ + case 0x5D50: /* PCI_CHIP_R480_5D50 */ + case 0x5D52: /* PCI_CHIP_R480_5D52 */ + case 0x4B49: /* PCI_CHIP_R481_4B49 */ + case 0x4B4A: /* PCI_CHIP_R481_4B4A */ + case 0x4B4B: /* PCI_CHIP_R481_4B4B */ + case 0x4B4C: /* PCI_CHIP_R481_4B4C */ + case 0x564A: /* PCI_CHIP_RV410_564A */ + case 0x564B: /* PCI_CHIP_RV410_564B */ + case 0x564F: /* PCI_CHIP_RV410_564F */ + case 0x5652: /* PCI_CHIP_RV410_5652 */ + case 0x5653: /* PCI_CHIP_RV410_5653 */ + case 0x5657: /* PCI_CHIP_RV410_5657 */ + case 0x5E48: /* PCI_CHIP_RV410_5E48 */ + case 0x5E4A: /* PCI_CHIP_RV410_5E4A */ + case 0x5E4B: /* PCI_CHIP_RV410_5E4B */ + case 0x5E4C: /* PCI_CHIP_RV410_5E4C */ + case 0x5E4D: /* PCI_CHIP_RV410_5E4D */ + case 0x5E4F: /* PCI_CHIP_RV410_5E4F */ + case 0x5A41: /* PCI_CHIP_RS400_5A41 */ + case 0x5A42: /* PCI_CHIP_RS400_5A42 */ + case 0x5A61: /* PCI_CHIP_RC410_5A61 */ + case 0x5A62: /* PCI_CHIP_RC410_5A62 */ + case 0x5954: /* PCI_CHIP_RS480_5954 */ + case 0x5955: /* PCI_CHIP_RS480_5955 */ + case 0x5974: /* PCI_CHIP_RS482_5974 */ + case 0x5975: /* PCI_CHIP_RS482_5975 */ + case 0x7100: /* PCI_CHIP_R520_7100 */ + case 0x7101: /* PCI_CHIP_R520_7101 */ + case 0x7102: /* PCI_CHIP_R520_7102 */ + case 0x7103: /* PCI_CHIP_R520_7103 */ + case 0x7104: /* PCI_CHIP_R520_7104 */ + case 0x7105: /* PCI_CHIP_R520_7105 */ + case 0x7106: /* PCI_CHIP_R520_7106 */ + case 0x7108: /* PCI_CHIP_R520_7108 */ + case 0x7109: /* PCI_CHIP_R520_7109 */ + case 0x710A: /* PCI_CHIP_R520_710A */ + case 0x710B: /* PCI_CHIP_R520_710B */ + case 0x710C: /* PCI_CHIP_R520_710C */ + case 0x710E: /* PCI_CHIP_R520_710E */ + case 0x710F: /* PCI_CHIP_R520_710F */ + case 0x7140: /* PCI_CHIP_RV515_7140 */ + case 0x7141: /* PCI_CHIP_RV515_7141 */ + case 0x7142: /* PCI_CHIP_RV515_7142 */ + case 0x7143: /* PCI_CHIP_RV515_7143 */ + case 0x7144: /* PCI_CHIP_RV515_7144 */ + case 0x7145: /* PCI_CHIP_RV515_7145 */ + case 0x7146: /* PCI_CHIP_RV515_7146 */ + case 0x7147: /* PCI_CHIP_RV515_7147 */ + case 0x7149: /* PCI_CHIP_RV515_7149 */ + case 0x714A: /* PCI_CHIP_RV515_714A */ + case 0x714B: /* PCI_CHIP_RV515_714B */ + case 0x714C: /* PCI_CHIP_RV515_714C */ + case 0x714D: /* PCI_CHIP_RV515_714D */ + case 0x714E: /* PCI_CHIP_RV515_714E */ + case 0x714F: /* PCI_CHIP_RV515_714F */ + case 0x7151: /* PCI_CHIP_RV515_7151 */ + case 0x7152: /* PCI_CHIP_RV515_7152 */ + case 0x7153: /* PCI_CHIP_RV515_7153 */ + case 0x715E: /* PCI_CHIP_RV515_715E */ + case 0x715F: /* PCI_CHIP_RV515_715F */ + case 0x7180: /* PCI_CHIP_RV515_7180 */ + case 0x7181: /* PCI_CHIP_RV515_7181 */ + case 0x7183: /* PCI_CHIP_RV515_7183 */ + case 0x7186: /* PCI_CHIP_RV515_7186 */ + case 0x7187: /* PCI_CHIP_RV515_7187 */ + case 0x7188: /* PCI_CHIP_RV515_7188 */ + case 0x718A: /* PCI_CHIP_RV515_718A */ + case 0x718B: /* PCI_CHIP_RV515_718B */ + case 0x718C: /* PCI_CHIP_RV515_718C */ + case 0x718D: /* PCI_CHIP_RV515_718D */ + case 0x718F: /* PCI_CHIP_RV515_718F */ + case 0x7193: /* PCI_CHIP_RV515_7193 */ + case 0x7196: /* PCI_CHIP_RV515_7196 */ + case 0x719B: /* PCI_CHIP_RV515_719B */ + case 0x719F: /* PCI_CHIP_RV515_719F */ + case 0x7200: /* PCI_CHIP_RV515_7200 */ + case 0x7210: /* PCI_CHIP_RV515_7210 */ + case 0x7211: /* PCI_CHIP_RV515_7211 */ + case 0x71C0: /* PCI_CHIP_RV530_71C0 */ + case 0x71C1: /* PCI_CHIP_RV530_71C1 */ + case 0x71C2: /* PCI_CHIP_RV530_71C2 */ + case 0x71C3: /* PCI_CHIP_RV530_71C3 */ + case 0x71C4: /* PCI_CHIP_RV530_71C4 */ + case 0x71C5: /* PCI_CHIP_RV530_71C5 */ + case 0x71C6: /* PCI_CHIP_RV530_71C6 */ + case 0x71C7: /* PCI_CHIP_RV530_71C7 */ + case 0x71CD: /* PCI_CHIP_RV530_71CD */ + case 0x71CE: /* PCI_CHIP_RV530_71CE */ + case 0x71D2: /* PCI_CHIP_RV530_71D2 */ + case 0x71D4: /* PCI_CHIP_RV530_71D4 */ + case 0x71D5: /* PCI_CHIP_RV530_71D5 */ + case 0x71D6: /* PCI_CHIP_RV530_71D6 */ + case 0x71DA: /* PCI_CHIP_RV530_71DA */ + case 0x71DE: /* PCI_CHIP_RV530_71DE */ + case 0x7281: /* PCI_CHIP_RV560_7281 */ + case 0x7283: /* PCI_CHIP_RV560_7283 */ + case 0x7287: /* PCI_CHIP_RV560_7287 */ + case 0x7290: /* PCI_CHIP_RV560_7290 */ + case 0x7291: /* PCI_CHIP_RV560_7291 */ + case 0x7293: /* PCI_CHIP_RV560_7293 */ + case 0x7297: /* PCI_CHIP_RV560_7297 */ + case 0x7280: /* PCI_CHIP_RV570_7280 */ + case 0x7288: /* PCI_CHIP_RV570_7288 */ + case 0x7289: /* PCI_CHIP_RV570_7289 */ + case 0x728B: /* PCI_CHIP_RV570_728B */ + case 0x728C: /* PCI_CHIP_RV570_728C */ + case 0x7240: /* PCI_CHIP_R580_7240 */ + case 0x7243: /* PCI_CHIP_R580_7243 */ + case 0x7244: /* PCI_CHIP_R580_7244 */ + case 0x7245: /* PCI_CHIP_R580_7245 */ + case 0x7246: /* PCI_CHIP_R580_7246 */ + case 0x7247: /* PCI_CHIP_R580_7247 */ + case 0x7248: /* PCI_CHIP_R580_7248 */ + case 0x7249: /* PCI_CHIP_R580_7249 */ + case 0x724A: /* PCI_CHIP_R580_724A */ + case 0x724B: /* PCI_CHIP_R580_724B */ + case 0x724C: /* PCI_CHIP_R580_724C */ + case 0x724D: /* PCI_CHIP_R580_724D */ + case 0x724E: /* PCI_CHIP_R580_724E */ + case 0x724F: /* PCI_CHIP_R580_724F */ + case 0x7284: /* PCI_CHIP_R580_7284 */ + case 0x793F: /* PCI_CHIP_RS600_793F */ + case 0x7941: /* PCI_CHIP_RS600_7941 */ + case 0x7942: /* PCI_CHIP_RS600_7942 */ + case 0x791E: /* PCI_CHIP_RS690_791E */ + case 0x791F: /* PCI_CHIP_RS690_791F */ + case 0x796C: /* PCI_CHIP_RS740_796C */ + case 0x796D: /* PCI_CHIP_RS740_796D */ + case 0x796E: /* PCI_CHIP_RS740_796E */ + case 0x796F: /* PCI_CHIP_RS740_796F */ + return TRUE; + default: + return FALSE; + } +} + +#endif 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 0000000..7a07280 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_r300.c @@ -0,0 +1,266 @@ +/* + * 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_drm_buffer.h" + +#include "util/u_memory.h" +#include "pipebuffer/pb_bufmgr.h" + +#include "radeon_cs_gem.h" +#include "state_tracker/drm_driver.h" + +static unsigned get_pb_usage_from_create_flags(unsigned bind, unsigned usage, + enum r300_buffer_domain domain) +{ + unsigned res = 0; + + if (bind & (PIPE_BIND_DEPTH_STENCIL | PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_SCANOUT)) + res |= PB_USAGE_GPU_WRITE; + + if (bind & PIPE_BIND_SAMPLER_VIEW) + res |= PB_USAGE_GPU_READ | PB_USAGE_GPU_WRITE; + + if (bind & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER)) + res |= PB_USAGE_GPU_READ; + + if (bind & PIPE_BIND_TRANSFER_WRITE) + res |= PB_USAGE_CPU_WRITE; + + if (bind & PIPE_BIND_TRANSFER_READ) + res |= PB_USAGE_CPU_READ; + + /* Is usage of any use for us? Probably not. */ + + /* Now add driver-specific usage flags. */ + if (bind & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER)) + res |= RADEON_PB_USAGE_VERTEX; + + if (domain & R300_DOMAIN_GTT) + res |= RADEON_PB_USAGE_DOMAIN_GTT; + + if (domain & R300_DOMAIN_VRAM) + res |= RADEON_PB_USAGE_DOMAIN_VRAM; + + return res; +} + +static struct r300_winsys_buffer * +radeon_r300_winsys_buffer_create(struct r300_winsys_screen *rws, + unsigned size, + unsigned alignment, + unsigned bind, + unsigned usage, + enum r300_buffer_domain domain) +{ + struct radeon_drm_winsys *ws = radeon_drm_winsys(rws); + struct pb_desc desc; + struct pb_manager *provider; + struct pb_buffer *buffer; + + memset(&desc, 0, sizeof(desc)); + desc.alignment = alignment; + desc.usage = get_pb_usage_from_create_flags(bind, usage, domain); + + /* Assign a buffer manager. */ + if (bind & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER)) + provider = ws->cman; + else + provider = ws->kman; + + buffer = provider->create_buffer(provider, size, &desc); + if (!buffer) + return NULL; + + return (struct r300_winsys_buffer*)buffer; +} + +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 = (struct r300_winsys_buffer*)_dst; +} + +static struct r300_winsys_buffer *radeon_r300_winsys_buffer_from_handle(struct r300_winsys_screen *rws, + struct winsys_handle *whandle, + unsigned *stride, + unsigned *size) +{ + struct radeon_drm_winsys *ws = radeon_drm_winsys(rws); + struct pb_buffer *_buf; + + _buf = radeon_drm_bufmgr_create_buffer_from_handle(ws->kman, whandle->handle); + + if (stride) + *stride = whandle->stride; + if (size && _buf) + *size = _buf->base.size; + + return (struct r300_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); + whandle->stride = stride; + return radeon_drm_bufmgr_get_handle(_buf, whandle); +} + +static void radeon_r300_winsys_cs_set_flush(struct r300_winsys_cs *rcs, + void (*flush)(void *), + void *user) +{ + struct radeon_drm_cs *cs = radeon_drm_cs(rcs); + cs->flush_cs = flush; + cs->flush_data = user; + radeon_cs_space_set_flush(cs->cs, flush, user); +} + +static boolean radeon_r300_winsys_cs_validate(struct r300_winsys_cs *rcs) +{ + struct radeon_drm_cs *cs = radeon_drm_cs(rcs); + + return radeon_cs_space_check(cs->cs) >= 0; +} + +static void radeon_r300_winsys_cs_reset_buffers(struct r300_winsys_cs *rcs) +{ + struct radeon_drm_cs *cs = radeon_drm_cs(rcs); + radeon_cs_space_reset_bos(cs->cs); +} + +static void radeon_r300_winsys_cs_flush(struct r300_winsys_cs *rcs) +{ + struct radeon_drm_cs *cs = radeon_drm_cs(rcs); + int retval; + + /* Don't flush a zero-sized CS. */ + if (!cs->base.cdw) { + return; + } + + cs->cs->cdw = cs->base.cdw; + + radeon_drm_bufmgr_flush_maps(cs->ws->kman); + + /* Emit the CS. */ + retval = radeon_cs_emit(cs->cs); + if (retval) { + if (debug_get_bool_option("RADEON_DUMP_CS", FALSE)) { + fprintf(stderr, "radeon: The kernel rejected CS, dumping...\n"); + radeon_cs_print(cs->cs, stderr); + } else { + fprintf(stderr, "radeon: The kernel rejected CS, " + "see dmesg for more information.\n"); + } + } + + /* 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(cs->cs); + + cs->base.buf = cs->cs->packets; + cs->base.cdw = cs->cs->cdw; +} + +static uint32_t radeon_get_value(struct r300_winsys_screen *rws, + enum r300_value_id id) +{ + struct radeon_drm_winsys *ws = (struct radeon_drm_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; + case R300_VID_DRM_2_3_0: + return ws->drm_2_3_0; + case R300_VID_DRM_2_6_0: + return ws->drm_2_6_0; + case R300_CAN_HYPERZ: + return ws->hyperz; + } + return 0; +} + +static struct r300_winsys_cs *radeon_r300_winsys_cs_create(struct r300_winsys_screen *rws) +{ + struct radeon_drm_winsys *ws = radeon_drm_winsys(rws); + struct radeon_drm_cs *cs = CALLOC_STRUCT(radeon_drm_cs); + + if (!cs) + return NULL; + + /* Size limit on IBs is 64 kibibytes. */ + cs->cs = radeon_cs_create(ws->csm, 1024 * 64 / 4); + if (!cs->cs) { + FREE(cs); + return NULL; + } + + radeon_cs_set_limit(cs->cs, + RADEON_GEM_DOMAIN_GTT, ws->gart_size); + radeon_cs_set_limit(cs->cs, + RADEON_GEM_DOMAIN_VRAM, ws->vram_size); + + cs->ws = ws; + cs->base.buf = cs->cs->packets; + cs->base.cdw = cs->cs->cdw; + return &cs->base; +} + +static void radeon_r300_winsys_cs_destroy(struct r300_winsys_cs *rcs) +{ + struct radeon_drm_cs *cs = radeon_drm_cs(rcs); + radeon_cs_destroy(cs->cs); + FREE(cs); +} + +void radeon_winsys_init_functions(struct radeon_drm_winsys *ws) +{ + ws->base.get_value = radeon_get_value; + ws->base.buffer_create = radeon_r300_winsys_buffer_create; + 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.cs_create = radeon_r300_winsys_cs_create; + ws->base.cs_destroy = radeon_r300_winsys_cs_destroy; + ws->base.cs_validate = radeon_r300_winsys_cs_validate; + ws->base.cs_flush = radeon_r300_winsys_cs_flush; + ws->base.cs_reset_buffers = radeon_r300_winsys_cs_reset_buffers; + ws->base.cs_set_flush = radeon_r300_winsys_cs_set_flush; +} 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 0000000..81da1a2 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_winsys.h @@ -0,0 +1,89 @@ +/* + * 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_drm_winsys { + struct r300_winsys_screen base; + + int fd; /* DRM file descriptor */ + + struct radeon_bo_manager *bom; /* Radeon BO manager. */ + struct pb_manager *kman; + struct pb_manager *cman; + + uint32_t pci_id; /* PCI ID */ + uint32_t gb_pipes; /* GB pipe count */ + uint32_t z_pipes; /* Z pipe count (rv530 only) */ + uint32_t gart_size; /* GART size. */ + uint32_t vram_size; /* VRAM size. */ + boolean squaretiling; /* Square tiling support. */ + /* DRM 2.3.0 (R500 VAP regs, MSPOS regs, fixed tex3D size checking) */ + boolean drm_2_3_0; + /* DRM 2.6.0 (Hyper-Z, GB_Z_PEQ_CONFIG allowed on rv350->r4xx) */ + boolean drm_2_6_0; + /* Hyper-Z user */ + boolean hyperz; + + /* Radeon CS manager. */ + struct radeon_cs_manager *csm; +}; + +struct radeon_drm_cs { + struct r300_winsys_cs base; + + /* The winsys. */ + struct radeon_drm_winsys *ws; + + /* The libdrm command stream. */ + struct radeon_cs *cs; + + /* Flush CS. */ + void (*flush_cs)(void *); + void *flush_data; +}; + +static INLINE struct radeon_drm_cs * +radeon_drm_cs(struct r300_winsys_cs *base) +{ + return (struct radeon_drm_cs*)base; +} + +static INLINE struct radeon_drm_winsys * +radeon_drm_winsys(struct r300_winsys_screen *base) +{ + return (struct radeon_drm_winsys*)base; +} + +void radeon_winsys_init_functions(struct radeon_drm_winsys *ws); + +#endif diff --git a/src/gallium/winsys/svga/drm/Makefile b/src/gallium/winsys/svga/drm/Makefile new file mode 100644 index 0000000..c2f59e0 --- /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 0000000..b049ea6 --- /dev/null +++ b/src/gallium/winsys/svga/drm/SConscript @@ -0,0 +1,41 @@ +Import('*') + +env = env.Clone() + +env.ParseConfig('pkg-config --cflags libdrm') + +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/svga_drm_public.h b/src/gallium/winsys/svga/drm/svga_drm_public.h new file mode 100644 index 0000000..e98c89d --- /dev/null +++ b/src/gallium/winsys/svga/drm/svga_drm_public.h @@ -0,0 +1,41 @@ +/********************************************************** + * 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. + * + **********************************************************/ + +/** + * @file + * VMware SVGA DRM winsys public interface. Used by targets to create a stack. + * + * @author Jakob Bornecrantz Fonseca + */ + +#ifndef SVGA_DRM_PUBLIC_H_ +#define SVGA_DRM_PUBLIC_H_ + +struct svga_winsys_screen; + +struct svga_winsys_screen * +svga_drm_winsys_screen_create(int fd); + +#endif /* SVGA_PUBLIC_H_ */ 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 0000000..eca174a --- /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 0000000..41fb447 --- /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 0000000..11626ee --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_context.c @@ -0,0 +1,416 @@ +/********************************************************** + * 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; + + boolean throttle_set; + uint32_t throttle_us; +}; + + +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 INLINE unsigned +vmw_translate_to_pb_flags(unsigned flags) +{ + unsigned f = 0; + if (flags & SVGA_RELOC_READ) + f |= PB_USAGE_GPU_READ; + + if (flags & SVGA_RELOC_WRITE) + f |= PB_USAGE_GPU_WRITE; + + return f; +} + +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; + uint32_t throttle_us; + + 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; + } + + throttle_us = vswc->throttle_set ? + vswc->throttle_us : vswc->vws->default_throttle_us; + + if (vswc->command.used) + vmw_ioctl_command(vswc->vws, + vswc->base.cid, + throttle_us, + 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; + unsigned translated_flags; + 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; + + translated_flags = vmw_translate_to_pb_flags(flags); + ret = pb_validate_add_buffer(vswc->validate, reloc->buffer, translated_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; +} + + +void +vmw_svga_context_set_throttling(struct pipe_context *pipe, + uint32_t throttle_us) +{ + struct svga_winsys_context *swc = svga_winsys_context(pipe); + struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); + + vswc->throttle_us = throttle_us; + vswc->throttle_set = TRUE; +} 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 0000000..aed8b93 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_context.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. + * + **********************************************************/ + +/** + * @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); + +void +vmw_svga_context_set_throttling(struct pipe_context *pipe, + uint32_t throttle_us); + +#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 0000000..873dd51 --- /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 0000000..5357b4f --- /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 0000000..51a4c55 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen.c @@ -0,0 +1,87 @@ +/********************************************************** + * 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); +} + +void +vmw_winsys_screen_set_throttling(struct pipe_screen *screen, + uint32_t throttle_us) +{ + struct vmw_winsys_screen *vws = + vmw_winsys_screen(svga_winsys_screen(screen)); + + vws->default_throttle_us = throttle_us; +} 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 0000000..b3de72d --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen.h @@ -0,0 +1,144 @@ +/********************************************************** + * 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; + uint32_t default_throttle_us; + + 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, + int32_t cid, + uint32_t throttle_us, + 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); +void vmw_winsys_screen_set_throttling(struct pipe_screen *screen, + uint32_t throttle_us); + +#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 0000000..258084a --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen_dri.c @@ -0,0 +1,241 @@ +/********************************************************** + * 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 "vmw_surface.h" +#include "svga_drm_public.h" + +#include "state_tracker/drm_driver.h" + +#include "vmwgfx_drm.h" +#include + +#include + +struct dri1_api_version { + int major; + int minor; + int patch_level; +}; + +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_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 target bootstrap code. + */ +struct svga_winsys_screen * +svga_drm_winsys_screen_create(int fd) +{ + struct vmw_winsys_screen *vws; + boolean use_old_scanout_flag = FALSE; + + 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; + + 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; + + return &vws->base; + +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; +} + +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; +} 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 0000000..d92ba38 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c @@ -0,0 +1,531 @@ +/********************************************************** + * 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, int32_t cid, + uint32_t throttle_us, 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; + arg.throttle_us = throttle_us; + + 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 0000000..b9823d7 --- /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 0000000..d96b2b9 --- /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, NULL); +} + + +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 0000000..5f1b9ad --- /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 0000000..3d61595 --- /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 0000000..2f2807d --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmwgfx_drm.h @@ -0,0 +1,572 @@ +/************************************************************************** + * + * 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 +/* guarded by minor version >= 2 */ +#define DRM_VMW_UPDATE_LAYOUT 15 + + +/*************************************************************************/ +/** + * 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 +#define DRM_VMW_PARAM_MAX_FB_SIZE 6 + +/** + * 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. + */ + +/*************************************************************************/ +/** + * DRM_VMW_UPDATE_LAYOUT - Update layout + * + * Updates the prefered modes and connection status for connectors. The + * command conisits of one drm_vmw_update_layout_arg pointing out a array + * of num_outputs drm_vmw_rect's. + */ + +/** + * struct drm_vmw_update_layout_arg + * + * @num_outputs: number of active + * @rects: pointer to array of drm_vmw_rect + * + * Input argument to the DRM_VMW_UPDATE_LAYOUT Ioctl. + */ + +struct drm_vmw_update_layout_arg { + uint32_t num_outputs; + uint32_t pad64; + uint64_t rects; +}; + +#endif diff --git a/src/gallium/winsys/sw/Makefile b/src/gallium/winsys/sw/Makefile new file mode 100644 index 0000000..094e811 --- /dev/null +++ b/src/gallium/winsys/sw/Makefile @@ -0,0 +1,22 @@ +# src/gallium/winsys/sw/Makefile +TOP = ../../../.. +include $(TOP)/configs/current + +SUBDIRS = null wrapper + +# TODO: this should go through a further indirection level +# (i.e. EGL should set a variable that is checked here) +ifneq ($(findstring x11, $(EGL_PLATFORMS)),) +SUBDIRS += xlib +endif + +ifneq ($(findstring fbdev, $(EGL_PLATFORMS)),) +SUBDIRS += fbdev +endif + +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/dri/Makefile b/src/gallium/winsys/sw/dri/Makefile new file mode 100644 index 0000000..a3fca6b --- /dev/null +++ b/src/gallium/winsys/sw/dri/Makefile @@ -0,0 +1,13 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = swdri + +LIBRARY_INCLUDES = + +LIBRARY_DEFINES = + +C_SOURCES = \ + dri_sw_winsys.c + +include ../../../Makefile.template diff --git a/src/gallium/winsys/sw/dri/SConscript b/src/gallium/winsys/sw/dri/SConscript new file mode 100644 index 0000000..b255d72 --- /dev/null +++ b/src/gallium/winsys/sw/dri/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_dri = env.ConvenienceLibrary( + target = 'ws_dri', + source = [ + 'dri_sw_winsys.c', + ] + ) + Export('ws_dri') diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.c b/src/gallium/winsys/sw/dri/dri_sw_winsys.c new file mode 100644 index 0000000..1bca827 --- /dev/null +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.c @@ -0,0 +1,225 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + +#include "pipe/p_compiler.h" +#include "pipe/p_format.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 "dri_sw_winsys.h" + + +struct dri_sw_displaytarget +{ + enum pipe_format format; + unsigned width; + unsigned height; + unsigned stride; + + void *data; + void *mapped; +}; + +struct dri_sw_winsys +{ + struct sw_winsys base; + + struct drisw_loader_funcs *lf; +}; + +static INLINE struct dri_sw_displaytarget * +dri_sw_displaytarget( struct sw_displaytarget *dt ) +{ + return (struct dri_sw_displaytarget *)dt; +} + +static INLINE struct dri_sw_winsys * +dri_sw_winsys( struct sw_winsys *ws ) +{ + return (struct dri_sw_winsys *)ws; +} + + +static boolean +dri_sw_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 struct sw_displaytarget * +dri_sw_displaytarget_create(struct sw_winsys *winsys, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) +{ + struct dri_sw_displaytarget *dri_sw_dt; + unsigned nblocksy, size, format_stride; + + dri_sw_dt = CALLOC_STRUCT(dri_sw_displaytarget); + if(!dri_sw_dt) + goto no_dt; + + dri_sw_dt->format = format; + dri_sw_dt->width = width; + dri_sw_dt->height = height; + + format_stride = util_format_get_stride(format, width); + dri_sw_dt->stride = align(format_stride, alignment); + + nblocksy = util_format_get_nblocksy(format, height); + size = dri_sw_dt->stride * nblocksy; + + dri_sw_dt->data = align_malloc(size, alignment); + if(!dri_sw_dt->data) + goto no_data; + + *stride = dri_sw_dt->stride; + return (struct sw_displaytarget *)dri_sw_dt; + +no_data: + FREE(dri_sw_dt); +no_dt: + return NULL; +} + +static void +dri_sw_displaytarget_destroy(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt); + + if (dri_sw_dt->data) { + FREE(dri_sw_dt->data); + } + + FREE(dri_sw_dt); +} + +static void * +dri_sw_displaytarget_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags) +{ + struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt); + dri_sw_dt->mapped = dri_sw_dt->data; + return dri_sw_dt->mapped; +} + +static void +dri_sw_displaytarget_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt); + dri_sw_dt->mapped = NULL; +} + +static struct sw_displaytarget * +dri_sw_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_resource *templ, + struct winsys_handle *whandle, + unsigned *stride) +{ + assert(0); + return NULL; +} + +static boolean +dri_sw_displaytarget_get_handle(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) +{ + assert(0); + return FALSE; +} + +static void +dri_sw_displaytarget_display(struct sw_winsys *ws, + struct sw_displaytarget *dt, + void *context_private) +{ + struct dri_sw_winsys *dri_sw_ws = dri_sw_winsys(ws); + struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt); + struct dri_drawable *dri_drawable = (struct dri_drawable *)context_private; + unsigned width, height; + + /* Set the width to 'stride / cpp'. + * + * PutImage correctly clips to the width of the dst drawable. + */ + width = dri_sw_dt->stride / util_format_get_blocksize(dri_sw_dt->format); + + height = dri_sw_dt->height; + + dri_sw_ws->lf->put_image(dri_drawable, dri_sw_dt->data, width, height); +} + + +static void +dri_destroy_sw_winsys(struct sw_winsys *winsys) +{ + FREE(winsys); +} + +struct sw_winsys * +dri_create_sw_winsys(struct drisw_loader_funcs *lf) +{ + struct dri_sw_winsys *ws; + + ws = CALLOC_STRUCT(dri_sw_winsys); + if (!ws) + return NULL; + + ws->lf = lf; + ws->base.destroy = dri_destroy_sw_winsys; + + ws->base.is_displaytarget_format_supported = dri_sw_is_displaytarget_format_supported; + + /* screen texture functions */ + ws->base.displaytarget_create = dri_sw_displaytarget_create; + ws->base.displaytarget_destroy = dri_sw_displaytarget_destroy; + ws->base.displaytarget_from_handle = dri_sw_displaytarget_from_handle; + ws->base.displaytarget_get_handle = dri_sw_displaytarget_get_handle; + + /* texture functions */ + ws->base.displaytarget_map = dri_sw_displaytarget_map; + ws->base.displaytarget_unmap = dri_sw_displaytarget_unmap; + + ws->base.displaytarget_display = dri_sw_displaytarget_display; + + return &ws->base; +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.h b/src/gallium/winsys/sw/dri/dri_sw_winsys.h new file mode 100644 index 0000000..329ac06 --- /dev/null +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.h @@ -0,0 +1,38 @@ +/************************************************************************** + * + * 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 DRI_SW_WINSYS +#define DRI_SW_WINSYS + +#include "state_tracker/drisw_api.h" + +struct sw_winsys; + +struct sw_winsys *dri_create_sw_winsys(struct drisw_loader_funcs *lf); + +#endif diff --git a/src/gallium/winsys/sw/fbdev/Makefile b/src/gallium/winsys/sw/fbdev/Makefile new file mode 100644 index 0000000..8832aab --- /dev/null +++ b/src/gallium/winsys/sw/fbdev/Makefile @@ -0,0 +1,13 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = fbdev + +LIBRARY_INCLUDES = + +LIBRARY_DEFINES = + +C_SOURCES = \ + fbdev_sw_winsys.c + +include ../../../Makefile.template diff --git a/src/gallium/winsys/sw/fbdev/SConscript b/src/gallium/winsys/sw/fbdev/SConscript new file mode 100644 index 0000000..3b5b4ff --- /dev/null +++ b/src/gallium/winsys/sw/fbdev/SConscript @@ -0,0 +1,23 @@ +####################################################################### +# SConscript for fbdev winsys + + +Import('*') + +if env['platform'] == 'linux': + + env = env.Clone() + + env.Append(CPPPATH = [ + '#/src/gallium/include', + '#/src/gallium/auxiliary', + '#/src/gallium/drivers', + ]) + + ws_fbdev = env.ConvenienceLibrary( + target = 'ws_fbdev', + source = [ + 'fbdev_sw_winsys.c', + ] + ) + Export('ws_fbdev') diff --git a/src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.c b/src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.c new file mode 100644 index 0000000..f4f4cd7 --- /dev/null +++ b/src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.c @@ -0,0 +1,224 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include +#include +#include + +#include "pipe/p_compiler.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "state_tracker/sw_winsys.h" + +#include "fbdev_sw_winsys.h" + +struct fbdev_sw_displaytarget +{ + enum pipe_format format; + unsigned width; + unsigned height; + unsigned stride; + + void *data; + void *mapped; +}; + +struct fbdev_sw_winsys +{ + struct sw_winsys base; + + int fd; + enum pipe_format format; + + struct fb_fix_screeninfo finfo; + void *fbmem; + unsigned rows; + unsigned stride; +}; + +static INLINE struct fbdev_sw_displaytarget * +fbdev_sw_displaytarget(struct sw_displaytarget *dt) +{ + return (struct fbdev_sw_displaytarget *) dt; +} + +static INLINE struct fbdev_sw_winsys * +fbdev_sw_winsys(struct sw_winsys *ws) +{ + return (struct fbdev_sw_winsys *) ws; +} + +static void +fbdev_displaytarget_display(struct sw_winsys *ws, + struct sw_displaytarget *dt, + void *context_private) +{ + struct fbdev_sw_winsys *fbdev = fbdev_sw_winsys(ws); + struct fbdev_sw_displaytarget *fbdt = fbdev_sw_displaytarget(dt); + unsigned rows, len, i; + + rows = MIN2(fbdt->height, fbdev->rows); + len = util_format_get_stride(fbdt->format, fbdt->width); + len = MIN2(len, fbdev->stride); + + for (i = 0; i < rows; i++) { + void *dst = fbdev->fbmem + fbdev->stride * i; + void *src = fbdt->data + fbdt->stride * i; + + memcpy(dst, src, len); + } +} + +static void +fbdev_displaytarget_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct fbdev_sw_displaytarget *fbdt = fbdev_sw_displaytarget(dt); + fbdt->mapped = NULL; +} + +static void * +fbdev_displaytarget_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags) +{ + struct fbdev_sw_displaytarget *fbdt = fbdev_sw_displaytarget(dt); + fbdt->mapped = fbdt->data; + return fbdt->mapped; +} + +static void +fbdev_displaytarget_destroy(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct fbdev_sw_displaytarget *fbdt = fbdev_sw_displaytarget(dt); + + if (fbdt->data) + align_free(fbdt->data); + + FREE(fbdt); +} + +static struct sw_displaytarget * +fbdev_displaytarget_create(struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) +{ + struct fbdev_sw_winsys *fbdev = fbdev_sw_winsys(ws); + struct fbdev_sw_displaytarget *fbdt; + unsigned nblocksy, size, format_stride; + + if (fbdev->format != format) + return NULL; + + fbdt = CALLOC_STRUCT(fbdev_sw_displaytarget); + if (!fbdt) + return NULL; + + fbdt->format = format; + fbdt->width = width; + fbdt->height = height; + + format_stride = util_format_get_stride(format, width); + fbdt->stride = align(format_stride, alignment); + + nblocksy = util_format_get_nblocksy(format, height); + size = fbdt->stride * nblocksy; + + fbdt->data = align_malloc(size, alignment); + if (!fbdt->data) { + FREE(fbdt); + return NULL; + } + + *stride = fbdt->stride; + + return (struct sw_displaytarget *) fbdt; +} + +static boolean +fbdev_is_displaytarget_format_supported(struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format) +{ + struct fbdev_sw_winsys *fbdev = fbdev_sw_winsys(ws); + return (fbdev->format == format); +} + +static void +fbdev_destroy(struct sw_winsys *ws) +{ + struct fbdev_sw_winsys *fbdev = fbdev_sw_winsys(ws); + + munmap(fbdev->fbmem, fbdev->finfo.smem_len); + FREE(fbdev); +} + +struct sw_winsys * +fbdev_create_sw_winsys(int fd, enum pipe_format format) +{ + struct fbdev_sw_winsys *fbdev; + + fbdev = CALLOC_STRUCT(fbdev_sw_winsys); + if (!fbdev) + return NULL; + + fbdev->fd = fd; + fbdev->format = format; + if (ioctl(fbdev->fd, FBIOGET_FSCREENINFO, &fbdev->finfo)) { + FREE(fbdev); + return NULL; + } + + fbdev->fbmem = mmap(0, fbdev->finfo.smem_len, + PROT_WRITE, MAP_SHARED, fbdev->fd, 0); + if (fbdev->fbmem == MAP_FAILED) { + FREE(fbdev); + return NULL; + } + + fbdev->rows = fbdev->finfo.smem_len / fbdev->finfo.line_length; + fbdev->stride = fbdev->finfo.line_length; + + fbdev->base.destroy = fbdev_destroy; + fbdev->base.is_displaytarget_format_supported = + fbdev_is_displaytarget_format_supported; + + fbdev->base.displaytarget_create = fbdev_displaytarget_create; + fbdev->base.displaytarget_destroy = fbdev_displaytarget_destroy; + fbdev->base.displaytarget_map = fbdev_displaytarget_map; + fbdev->base.displaytarget_unmap = fbdev_displaytarget_unmap; + + fbdev->base.displaytarget_display = fbdev_displaytarget_display; + + return &fbdev->base; +} diff --git a/src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.h b/src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.h new file mode 100644 index 0000000..d958ab9 --- /dev/null +++ b/src/gallium/winsys/sw/fbdev/fbdev_sw_winsys.h @@ -0,0 +1,38 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef FBDEV_SW_WINSYS +#define FBDEV_SW_WINSYS + +struct sw_winsys; +enum pipe_format; + +struct sw_winsys * +fbdev_create_sw_winsys(int fd, enum pipe_format format); + +#endif /* FBDEV_SW_WINSYS */ diff --git a/src/gallium/winsys/sw/gdi/SConscript b/src/gallium/winsys/sw/gdi/SConscript new file mode 100644 index 0000000..1267fc6 --- /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 0000000..2e12f6e --- /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_resource *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 0000000..4bbcb47 --- /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 0000000..b1882b5 --- /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 0000000..21837dc --- /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 0000000..73b777f --- /dev/null +++ b/src/gallium/winsys/sw/null/null_sw_winsys.c @@ -0,0 +1,150 @@ +/************************************************************************** + * + * 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 + +#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) +{ + fprintf(stderr, "null_sw_displaytarget_create() returning NULL\n"); + return NULL; +} + + +static struct sw_displaytarget * +null_sw_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_resource *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 0000000..1986186 --- /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 0000000..4771fbc --- /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/SConscript b/src/gallium/winsys/sw/wrapper/SConscript new file mode 100644 index 0000000..4c60488 --- /dev/null +++ b/src/gallium/winsys/sw/wrapper/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_wrapper = env.ConvenienceLibrary( + target = 'ws_wrapper', + source = [ + 'wrapper_sw_winsys.c', + ] +) +Export('ws_wrapper') 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 0000000..8f9a908 --- /dev/null +++ b/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c @@ -0,0 +1,321 @@ +/********************************************************** + * 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; + enum pipe_texture_target target; +}; + +struct wrapper_sw_displaytarget +{ + struct wrapper_sw_winsys *winsys; + struct pipe_resource *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_resource *tex = wdt->tex; + struct pipe_transfer *tr; + + tr = pipe_get_transfer(pipe, tex, 0, 0, + PIPE_TRANSFER_READ_WRITE, + 0, 0, wdt->width, wdt->height); + if (!tr) + return FALSE; + + *stride = tr->stride; + wdt->stride = tr->stride; + + pipe->transfer_destroy(pipe, tr); + + return TRUE; +} + +static struct sw_displaytarget * +wsw_dt_wrap_texture(struct wrapper_sw_winsys *wsw, + struct pipe_resource *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_resource_reference(&tex, NULL); + return NULL; +} + +static struct sw_displaytarget * +wsw_dt_create(struct sw_winsys *ws, + unsigned bind, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) +{ + struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); + struct pipe_resource templ; + struct pipe_resource *tex; + + /* + * XXX Why don't we just get the template. + */ + memset(&templ, 0, sizeof(templ)); + templ.target = wsw->target; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.array_size = 1; + templ.format = format; + templ.bind = bind; + + /* XXX alignment: we can't do anything about this */ + + tex = wsw->screen->resource_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_resource *templ, + struct winsys_handle *whandle, + unsigned *stride) +{ + struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); + struct pipe_resource *tex; + + tex = wsw->screen->resource_from_handle(wsw->screen, templ, whandle); + if (!tex) + return NULL; + + return wsw_dt_wrap_texture(wsw, tex, stride); +} + +static boolean +wsw_dt_get_handle(struct sw_winsys *ws, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) +{ + struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); + struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); + struct pipe_resource *tex = wdt->tex; + + return wsw->screen->resource_get_handle(wsw->screen, tex, whandle); +} + +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_resource *tex = wdt->tex; + struct pipe_transfer *tr; + void *ptr; + + if (!wdt->map_count) { + + assert(!wdt->transfer); + + tr = pipe_get_transfer(pipe, tex, 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->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->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_resource_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_wrap_pipe_screen(struct pipe_screen *screen) +{ + struct wrapper_sw_winsys *wsw = CALLOC_STRUCT(wrapper_sw_winsys); + + if (!wsw) + goto err; + + wsw->base.displaytarget_create = wsw_dt_create; + wsw->base.displaytarget_from_handle = wsw_dt_from_handle; + wsw->base.displaytarget_get_handle = wsw_dt_get_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_free; + + if(screen->get_param(screen, PIPE_CAP_NPOT_TEXTURES)) + wsw->target = PIPE_TEXTURE_2D; + else + wsw->target = PIPE_TEXTURE_RECT; + + return &wsw->base; + +err_free: + FREE(wsw); +err: + return NULL; +} + +struct pipe_screen * +wrapper_sw_winsys_dewrap_pipe_screen(struct sw_winsys *ws) +{ + struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); + struct pipe_screen *screen = wsw->screen; + + wsw->pipe->destroy(wsw->pipe); + /* don't destroy the screen its needed later on */ + + FREE(wsw); + return screen; +} 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 0000000..ae0196c --- /dev/null +++ b/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.h @@ -0,0 +1,44 @@ +/********************************************************** + * 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; + +/* + * Wrap a pipe screen. + */ +struct sw_winsys *wrapper_sw_winsys_wrap_pipe_screen(struct pipe_screen *screen); + +/* + * Destroy the sw_winsys and return the wrapped pipe_screen. + * Not destroying it as sw_winsys::destroy does. + */ +struct pipe_screen *wrapper_sw_winsys_dewrap_pipe_screen(struct sw_winsys *sw_winsys); + +#endif diff --git a/src/gallium/winsys/sw/xlib/Makefile b/src/gallium/winsys/sw/xlib/Makefile new file mode 100644 index 0000000..c669389 --- /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 0000000..df01a9e --- /dev/null +++ b/src/gallium/winsys/sw/xlib/SConscript @@ -0,0 +1,23 @@ +####################################################################### +# SConscript for xlib winsys + + +Import('*') + +if env['platform'] in ('cygwin', '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 0000000..3aef8da --- /dev/null +++ b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c @@ -0,0 +1,479 @@ +/************************************************************************** + * + * 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 + +DEBUG_GET_ONCE_BOOL_OPTION(xlib_no_shm, "XLIB_NO_SHM", FALSE) + +/** + * Display target for Xlib winsys. + * Low-level OS/window system memory buffer + */ +struct xlib_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; + Bool shm; /** Using shared memory images? */ +}; + + +/** + * Subclass of sw_winsys for Xlib winsys + */ +struct xlib_sw_winsys +{ + struct sw_winsys base; + Display *display; +}; + + + +/** Cast wrapper */ +static INLINE struct xlib_displaytarget * +xlib_displaytarget(struct sw_displaytarget *dt) +{ + return (struct xlib_displaytarget *) dt; +} + + +/** + * X Shared Memory Image extension code + */ + +static volatile int XErrorFlag = 0; + +/** + * Catches potential Xlib errors. + */ +static int +handle_xerror(Display *dpy, XErrorEvent *event) +{ + (void) dpy; + (void) event; + XErrorFlag = 1; + return 0; +} + + +static char * +alloc_shm(struct xlib_displaytarget *buf, unsigned size) +{ + XShmSegmentInfo *const shminfo = & buf->shminfo; + + shminfo->shmid = -1; + shminfo->shmaddr = (char *) -1; + + 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 display target. + */ +static void +alloc_shm_ximage(struct xlib_displaytarget *xlib_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 *); + + xlib_dt->tempImage = XShmCreateImage(xlib_dt->display, + xmb->visual, + xmb->depth, + ZPixmap, + NULL, + &xlib_dt->shminfo, + width, height); + if (xlib_dt->tempImage == NULL) { + xlib_dt->shm = False; + return; + } + + + XErrorFlag = 0; + old_handler = XSetErrorHandler(handle_xerror); + /* This may trigger the X protocol error we're ready to catch: */ + XShmAttach(xlib_dt->display, &xlib_dt->shminfo); + XSync(xlib_dt->display, False); + + if (XErrorFlag) { + /* we are on a remote display, this error is normal, don't print it */ + XFlush(xlib_dt->display); + XErrorFlag = 0; + XDestroyImage(xlib_dt->tempImage); + xlib_dt->tempImage = NULL; + xlib_dt->shm = False; + (void) XSetErrorHandler(old_handler); + return; + } + + xlib_dt->shm = True; +} + + +static void +alloc_ximage(struct xlib_displaytarget *xlib_dt, + struct xlib_drawable *xmb, + unsigned width, unsigned height) +{ + /* try allocating a shared memory image first */ + if (xlib_dt->shm) { + alloc_shm_ximage(xlib_dt, xmb, width, height); + if (xlib_dt->tempImage) + return; /* success */ + } + + /* try regular (non-shared memory) image */ + xlib_dt->tempImage = XCreateImage(xlib_dt->display, + xmb->visual, + xmb->depth, + ZPixmap, 0, + NULL, width, height, + 8, 0); +} + +static boolean +xlib_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 * +xlib_displaytarget_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags) +{ + struct xlib_displaytarget *xlib_dt = xlib_displaytarget(dt); + xlib_dt->mapped = xlib_dt->data; + return xlib_dt->mapped; +} + + +static void +xlib_displaytarget_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct xlib_displaytarget *xlib_dt = xlib_displaytarget(dt); + xlib_dt->mapped = NULL; +} + + +static void +xlib_displaytarget_destroy(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct xlib_displaytarget *xlib_dt = xlib_displaytarget(dt); + + if (xlib_dt->data) { + if (xlib_dt->shminfo.shmid >= 0) { + shmdt(xlib_dt->shminfo.shmaddr); + shmctl(xlib_dt->shminfo.shmid, IPC_RMID, 0); + + xlib_dt->shminfo.shmid = -1; + xlib_dt->shminfo.shmaddr = (char *) -1; + + xlib_dt->data = NULL; + if (xlib_dt->tempImage) + xlib_dt->tempImage->data = NULL; + } + else { + FREE(xlib_dt->data); + if (xlib_dt->tempImage && xlib_dt->tempImage->data == xlib_dt->data) { + xlib_dt->tempImage->data = NULL; + } + xlib_dt->data = NULL; + } + } + + if (xlib_dt->tempImage) { + XDestroyImage(xlib_dt->tempImage); + xlib_dt->tempImage = NULL; + } + + if (xlib_dt->gc) + XFreeGC(xlib_dt->display, xlib_dt->gc); + + FREE(xlib_dt); +} + + +/** + * Display/copy the image in the surface into the X window specified + * by the display target. + */ +static void +xlib_sw_display(struct xlib_drawable *xlib_drawable, + struct sw_displaytarget *dt) +{ + static boolean no_swap = 0; + static boolean firsttime = 1; + struct xlib_displaytarget *xlib_dt = xlib_displaytarget(dt); + Display *display = xlib_dt->display; + XImage *ximage; + + if (firsttime) { + no_swap = getenv("SP_NO_RAST") != NULL; + firsttime = 0; + } + + if (no_swap) + return; + + if (xlib_dt->drawable != xlib_drawable->drawable) { + if (xlib_dt->gc) { + XFreeGC(display, xlib_dt->gc); + xlib_dt->gc = NULL; + } + + if (xlib_dt->tempImage) { + XDestroyImage(xlib_dt->tempImage); + xlib_dt->tempImage = NULL; + } + + xlib_dt->drawable = xlib_drawable->drawable; + } + + if (xlib_dt->tempImage == NULL) { + assert(util_format_get_blockwidth(xlib_dt->format) == 1); + assert(util_format_get_blockheight(xlib_dt->format) == 1); + alloc_ximage(xlib_dt, xlib_drawable, + xlib_dt->stride / util_format_get_blocksize(xlib_dt->format), + xlib_dt->height); + if (!xlib_dt->tempImage) + return; + } + + if (xlib_dt->gc == NULL) { + xlib_dt->gc = XCreateGC(display, xlib_drawable->drawable, 0, NULL); + XSetFunction(display, xlib_dt->gc, GXcopy); + } + + if (xlib_dt->shm) { + ximage = xlib_dt->tempImage; + ximage->data = xlib_dt->data; + + /* _debug_printf("XSHM\n"); */ + XShmPutImage(xlib_dt->display, xlib_drawable->drawable, xlib_dt->gc, + ximage, 0, 0, 0, 0, xlib_dt->width, xlib_dt->height, False); + } + else { + /* display image in Window */ + ximage = xlib_dt->tempImage; + ximage->data = xlib_dt->data; + + /* check that the XImage has been previously initialized */ + assert(ximage->format); + assert(ximage->bitmap_unit); + + /* update XImage's fields */ + ximage->width = xlib_dt->width; + ximage->height = xlib_dt->height; + ximage->bytes_per_line = xlib_dt->stride; + + /* _debug_printf("XPUT\n"); */ + XPutImage(xlib_dt->display, xlib_drawable->drawable, xlib_dt->gc, + ximage, 0, 0, 0, 0, xlib_dt->width, xlib_dt->height); + } + + XFlush(xlib_dt->display); +} + + +/** + * Display/copy the image in the surface into the X window specified + * by the display target. + */ +static void +xlib_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 * +xlib_displaytarget_create(struct sw_winsys *winsys, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) +{ + struct xlib_displaytarget *xlib_dt; + unsigned nblocksy, size; + + xlib_dt = CALLOC_STRUCT(xlib_displaytarget); + if (!xlib_dt) + goto no_xlib_dt; + + xlib_dt->display = ((struct xlib_sw_winsys *)winsys)->display; + xlib_dt->format = format; + xlib_dt->width = width; + xlib_dt->height = height; + + nblocksy = util_format_get_nblocksy(format, height); + xlib_dt->stride = align(util_format_get_stride(format, width), alignment); + size = xlib_dt->stride * nblocksy; + + if (!debug_get_option_xlib_no_shm()) { + xlib_dt->data = alloc_shm(xlib_dt, size); + if (xlib_dt->data) { + xlib_dt->shm = True; + } + } + + if (!xlib_dt->data) { + xlib_dt->data = align_malloc(size, alignment); + if (!xlib_dt->data) + goto no_data; + } + + *stride = xlib_dt->stride; + return (struct sw_displaytarget *)xlib_dt; + +no_data: + FREE(xlib_dt); +no_xlib_dt: + return NULL; +} + + +static struct sw_displaytarget * +xlib_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_resource *templet, + struct winsys_handle *whandle, + unsigned *stride) +{ + assert(0); + return NULL; +} + + +static boolean +xlib_displaytarget_get_handle(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) +{ + assert(0); + return FALSE; +} + + +static void +xlib_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 = xlib_destroy; + + ws->base.is_displaytarget_format_supported = xlib_is_displaytarget_format_supported; + + ws->base.displaytarget_create = xlib_displaytarget_create; + ws->base.displaytarget_from_handle = xlib_displaytarget_from_handle; + ws->base.displaytarget_get_handle = xlib_displaytarget_get_handle; + ws->base.displaytarget_map = xlib_displaytarget_map; + ws->base.displaytarget_unmap = xlib_displaytarget_unmap; + ws->base.displaytarget_destroy = xlib_displaytarget_destroy; + + ws->base.displaytarget_display = xlib_displaytarget_display; + + return &ws->base; +} diff --git a/src/glsl/Makefile b/src/glsl/Makefile new file mode 100644 index 0000000..7e9471e --- /dev/null +++ b/src/glsl/Makefile @@ -0,0 +1,185 @@ +#src/glsl/pp/Makefile + +TOP = ../.. + +include $(TOP)/configs/current + +LIBNAME = glsl + +LIBGLCPP_SOURCES = \ + glcpp/glcpp-lex.c \ + glcpp/glcpp-parse.c \ + glcpp/pp.c + +GLCPP_SOURCES = \ + $(LIBGLCPP_SOURCES) \ + glcpp/glcpp.c + +C_SOURCES = \ + strtod.c \ + ralloc.c \ + $(LIBGLCPP_SOURCES) + +CXX_SOURCES = \ + ast_expr.cpp \ + ast_function.cpp \ + ast_to_hir.cpp \ + ast_type.cpp \ + builtin_function.cpp \ + glsl_lexer.cpp \ + glsl_parser.cpp \ + glsl_parser_extras.cpp \ + glsl_types.cpp \ + glsl_symbol_table.cpp \ + hir_field_selection.cpp \ + ir_basic_block.cpp \ + ir_clone.cpp \ + ir_constant_expression.cpp \ + ir.cpp \ + ir_expression_flattening.cpp \ + ir_function_can_inline.cpp \ + ir_function.cpp \ + ir_hierarchical_visitor.cpp \ + ir_hv_accept.cpp \ + ir_import_prototypes.cpp \ + ir_print_visitor.cpp \ + ir_reader.cpp \ + ir_rvalue_visitor.cpp \ + ir_set_program_inouts.cpp \ + ir_validate.cpp \ + ir_variable.cpp \ + ir_variable_refcount.cpp \ + linker.cpp \ + link_functions.cpp \ + loop_analysis.cpp \ + loop_controls.cpp \ + loop_unroll.cpp \ + lower_discard.cpp \ + lower_if_to_cond_assign.cpp \ + lower_instructions.cpp \ + lower_jumps.cpp \ + lower_mat_op_to_vec.cpp \ + lower_noise.cpp \ + lower_texture_projection.cpp \ + lower_variable_index_to_cond_assign.cpp \ + lower_vec_index_to_cond_assign.cpp \ + lower_vec_index_to_swizzle.cpp \ + lower_vector.cpp \ + opt_algebraic.cpp \ + opt_constant_folding.cpp \ + opt_constant_propagation.cpp \ + opt_constant_variable.cpp \ + opt_copy_propagation.cpp \ + opt_dead_code.cpp \ + opt_dead_code_local.cpp \ + opt_dead_functions.cpp \ + opt_discard_simplification.cpp \ + opt_function_inlining.cpp \ + opt_if_simplification.cpp \ + opt_noop_swizzle.cpp \ + opt_redundant_jumps.cpp \ + opt_structure_splitting.cpp \ + opt_swizzle_swizzle.cpp \ + opt_tree_grafting.cpp \ + s_expression.cpp + +LIBS = \ + $(TOP)/src/glsl/libglsl.a + +APPS = glsl_compiler glcpp/glcpp + +GLSL2_C_SOURCES = \ + ../mesa/program/hash_table.c \ + ../mesa/program/symbol_table.c +GLSL2_CXX_SOURCES = \ + main.cpp + +GLSL2_OBJECTS = \ + $(GLSL2_C_SOURCES:.c=.o) \ + $(GLSL2_CXX_SOURCES:.cpp=.o) + +### Basic defines ### + +DEFINES += \ + $(LIBRARY_DEFINES) \ + $(API_DEFINES) + +GLCPP_OBJECTS = \ + $(GLCPP_SOURCES:.c=.o) \ + ../mesa/program/hash_table.o + +OBJECTS = \ + $(C_SOURCES:.c=.o) \ + $(CXX_SOURCES:.cpp=.o) + +INCLUDES = \ + -I. \ + -I../mesa \ + -I../mapi \ + -I../../include \ + $(LIBRARY_INCLUDES) + +ALL_SOURCES = \ + $(C_SOURCES) \ + $(CXX_SOURCES) \ + $(GLSL2_CXX_SOURCES) \ + $(GLSL2_C_SOURCES) + +##### TARGETS ##### + +default: depend lib$(LIBNAME).a $(APPS) + +lib$(LIBNAME).a: $(OBJECTS) Makefile $(TOP)/src/glsl/Makefile.template + $(MKLIB) -cplusplus -o $(LIBNAME) -static $(OBJECTS) + +depend: $(ALL_SOURCES) Makefile + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(ALL_SOURCES) 2> /dev/null + +# Remove .o and backup files +clean: + rm -f $(GLCPP_OBJECTS) $(GLSL2_OBJECTS) $(OBJECTS) lib$(LIBNAME).a depend depend.bak + -rm -f $(APPS) + +# Dummy target +install: + @echo -n "" + + +##### RULES ##### + +glsl_compiler: $(GLSL2_OBJECTS) libglsl.a + $(APP_CXX) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $(GLSL2_OBJECTS) $(LIBS) -o $@ + +glcpp/glcpp: $(GLCPP_OBJECTS) libglsl.a + $(APP_CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $(GLCPP_OBJECTS) $(LIBS) -o $@ + +.cpp.o: + $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DEFINES) $< -o $@ + +.c.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@ + +glsl_lexer.cpp: glsl_lexer.lpp + flex --nounistd -o$@ $< + +glsl_parser.cpp: glsl_parser.ypp + bison -v -o "$@" -p "_mesa_glsl_" --defines=glsl_parser.h $< + +glcpp/glcpp-lex.c: glcpp/glcpp-lex.l + flex --nounistd -o$@ $< + +glcpp/glcpp-parse.c: glcpp/glcpp-parse.y + bison -v -o "$@" --defines=glcpp/glcpp-parse.h $< + +builtins: builtin_function.cpp builtins/profiles/* builtins/ir/* builtins/tools/generate_builtins.py builtins/tools/texture_builtins.py + @echo Bootstrapping the compiler... + cp builtins/tools/builtin_function.cpp . + make glsl_compiler + @echo Regenerating builtin_function.cpp... + $(PYTHON2) $(PYTHON_FLAGS) builtins/tools/generate_builtins.py > builtin_function.cpp + @echo Rebuilding the real compiler... + make glsl_compiler + +-include depend diff --git a/src/glsl/Makefile.template b/src/glsl/Makefile.template new file mode 100644 index 0000000..974987a --- /dev/null +++ b/src/glsl/Makefile.template @@ -0,0 +1,50 @@ +# src/glsl/Makefile.template + +# Template makefile for glsl libraries. +# +# Usage: +# The minimum that the including makefile needs to define +# is TOP, LIBNAME and one of of the *_SOURCES. +# +# Optional defines: +# LIBRARY_INCLUDES are appended to the list of includes directories. +# LIBRARY_DEFINES is not used for makedepend, but for compilation. + + +### Basic defines ### + +OBJECTS = $(C_SOURCES:.c=.o) + +INCLUDES = \ + -I. \ + $(LIBRARY_INCLUDES) + + +##### TARGETS ##### + +default: depend lib$(LIBNAME).a + +lib$(LIBNAME).a: $(OBJECTS) Makefile $(TOP)/src/glsl/Makefile.template + $(MKLIB) -o $(LIBNAME) -static $(OBJECTS) + +depend: $(C_SOURCES) + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) 2> /dev/null + +# Remove .o and backup files +clean: + rm -f $(OBJECTS) lib$(LIBNAME).a depend depend.bak + +# Dummy target +install: + @echo -n "" + + +##### RULES ##### + +.c.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@ + +-include depend + diff --git a/src/glsl/README b/src/glsl/README new file mode 100644 index 0000000..dd80a53 --- /dev/null +++ b/src/glsl/README @@ -0,0 +1,229 @@ +Welcome to Mesa's GLSL compiler. A brief overview of how things flow: + +1) lex and yacc-based preprocessor takes the incoming shader string +and produces a new string containing the preprocessed shader. This +takes care of things like #if, #ifdef, #define, and preprocessor macro +invocations. Note that #version, #extension, and some others are +passed straight through. See glcpp/* + +2) lex and yacc-based parser takes the preprocessed string and +generates the AST (abstract syntax tree). Almost no checking is +performed in this stage. See glsl_lexer.lpp and glsl_parser.ypp. + +3) The AST is converted to "HIR". This is the intermediate +representation of the compiler. Constructors are generated, function +calls are resolved to particular function signatures, and all the +semantic checking is performed. See ast_*.cpp for the conversion, and +ir.h for the IR structures. + +4) The driver (Mesa, or main.cpp for the standalone binary) performs +optimizations. These include copy propagation, dead code elimination, +constant folding, and others. Generally the driver will call +optimizations in a loop, as each may open up opportunities for other +optimizations to do additional work. See most files called ir_*.cpp + +5) linking is performed. This does checking to ensure that the +outputs of the vertex shader match the inputs of the fragment shader, +and assigns locations to uniforms, attributes, and varyings. See +linker.cpp. + +6) The driver may perform additional optimization at this point, as +for example dead code elimination previously couldn't remove functions +or global variable usage when we didn't know what other code would be +linked in. + +7) The driver performs code generation out of the IR, taking a linked +shader program and producing a compiled program for each stage. See +ir_to_mesa.cpp for Mesa IR code generation. + +FAQ: + +Q: What is HIR versus IR versus LIR? + +A: The idea behind the naming was that ast_to_hir would produce a +high-level IR ("HIR"), with things like matrix operations, structure +assignments, etc., present. A series of lowering passes would occur +that do things like break matrix multiplication into a series of dot +products/MADs, make structure assignment be a series of assignment of +components, flatten if statements into conditional moves, and such, +producing a low level IR ("LIR"). + +However, it now appears that each driver will have different +requirements from a LIR. A 915-generation chipset wants all functions +inlined, all loops unrolled, all ifs flattened, no variable array +accesses, and matrix multiplication broken down. The Mesa IR backend +for swrast would like matrices and structure assignment broken down, +but it can support function calls and dynamic branching. A 965 vertex +shader IR backend could potentially even handle some matrix operations +without breaking them down, but the 965 fragment shader IR backend +would want to break to have (almost) all operations down channel-wise +and perform optimization on that. As a result, there's no single +low-level IR that will make everyone happy. So that usage has fallen +out of favor, and each driver will perform a series of lowering passes +to take the HIR down to whatever restrictions it wants to impose +before doing codegen. + +Q: How is the IR structured? + +A: The best way to get started seeing it would be to run the +standalone compiler against a shader: + +./glsl_compiler --dump-lir \ + ~/src/piglit/tests/shaders/glsl-orangebook-ch06-bump.frag + +So for example one of the ir_instructions in main() contains: + +(assign (constant bool (1)) (var_ref litColor) (expression vec3 * (var_ref Surf +aceColor) (var_ref __retval) ) ) + +Or more visually: + (assign) + / | \ + (var_ref) (expression *) (constant bool 1) + / / \ +(litColor) (var_ref) (var_ref) + / \ + (SurfaceColor) (__retval) + +which came from: + +litColor = SurfaceColor * max(dot(normDelta, LightDir), 0.0); + +(the max call is not represented in this expression tree, as it was a +function call that got inlined but not brought into this expression +tree) + +Each of those nodes is a subclass of ir_instruction. A particular +ir_instruction instance may only appear once in the whole IR tree with +the exception of ir_variables, which appear once as variable +declarations: + +(declare () vec3 normDelta) + +and multiple times as the targets of variable dereferences: +... +(assign (constant bool (1)) (var_ref __retval) (expression float dot + (var_ref normDelta) (var_ref LightDir) ) ) +... +(assign (constant bool (1)) (var_ref __retval) (expression vec3 - + (var_ref LightDir) (expression vec3 * (constant float (2.000000)) + (expression vec3 * (expression float dot (var_ref normDelta) (var_ref + LightDir) ) (var_ref normDelta) ) ) ) ) +... + +Each node has a type. Expressions may involve several different types: +(declare (uniform ) mat4 gl_ModelViewMatrix) +((assign (constant bool (1)) (var_ref constructor_tmp) (expression + vec4 * (var_ref gl_ModelViewMatrix) (var_ref gl_Vertex) ) ) + +An expression tree can be arbitrarily deep, and the compiler tries to +keep them structured like that so that things like algebraic +optimizations ((color * 1.0 == color) and ((mat1 * mat2) * vec == mat1 +* (mat2 * vec))) or recognizing operation patterns for code generation +(vec1 * vec2 + vec3 == mad(vec1, vec2, vec3)) are easier. This comes +at the expense of additional trickery in implementing some +optimizations like CSE where one must navigate an expression tree. + +Q: Why no SSA representation? + +A: Converting an IR tree to SSA form makes dead code elmimination, +common subexpression elimination, and many other optimizations much +easier. However, in our primarily vector-based language, there's some +major questions as to how it would work. Do we do SSA on the scalar +or vector level? If we do it at the vector level, we're going to end +up with many different versions of the variable when encountering code +like: + +(assign (constant bool (1)) (swiz x (var_ref __retval) ) (var_ref a) ) +(assign (constant bool (1)) (swiz y (var_ref __retval) ) (var_ref b) ) +(assign (constant bool (1)) (swiz z (var_ref __retval) ) (var_ref c) ) + +If every masked update of a component relies on the previous value of +the variable, then we're probably going to be quite limited in our +dead code elimination wins, and recognizing common expressions may +just not happen. On the other hand, if we operate channel-wise, then +we'll be prone to optimizing the operation on one of the channels at +the expense of making its instruction flow different from the other +channels, and a vector-based GPU would end up with worse code than if +we didn't optimize operations on that channel! + +Once again, it appears that our optimization requirements are driven +significantly by the target architecture. For now, targeting the Mesa +IR backend, SSA does not appear to be that important to producing +excellent code, but we do expect to do some SSA-based optimizations +for the 965 fragment shader backend when that is developed. + +Q: How should I expand instructions that take multiple backend instructions? + +Sometimes you'll have to do the expansion in your code generation -- +see, for example, ir_to_mesa.cpp's handling of ir_unop_sqrt. However, +in many cases you'll want to do a pass over the IR to convert +non-native instructions to a series of native instructions. For +example, for the Mesa backend we have ir_div_to_mul_rcp.cpp because +Mesa IR (and many hardware backends) only have a reciprocal +instruction, not a divide. Implementing non-native instructions this +way gives the chance for constant folding to occur, so (a / 2.0) +becomes (a * 0.5) after codegen instead of (a * (1.0 / 2.0)) + +Q: How shoud I handle my special hardware instructions with respect to IR? + +Our current theory is that if multiple targets have an instruction for +some operation, then we should probably be able to represent that in +the IR. Generally this is in the form of an ir_{bin,un}op expression +type. For example, we initially implemented fract() using (a - +floor(a)), but both 945 and 965 have instructions to give that result, +and it would also simplify the implementation of mod(), so +ir_unop_fract was added. The following areas need updating to add a +new expression type: + +ir.h (new enum) +ir.cpp:get_num_operands() (used for ir_reader) +ir.cpp:operator_strs (used for ir_reader) +ir_constant_expression.cpp (you probably want to be able to constant fold) +ir_validate.cpp (check users have the right types) + +You may also need to update the backends if they will see the new expr type: + +../mesa/shaders/ir_to_mesa.cpp + +You can then use the new expression from builtins (if all backends +would rather see it), or scan the IR and convert to use your new +expression type (see ir_mod_to_fract, for example). + +Q: How is memory management handled in the compiler? + +The hierarchical memory allocator "talloc" developed for the Samba +project is used, so that things like optimization passes don't have to +worry about their garbage collection so much. It has a few nice +features, including low performance overhead and good debugging +support that's trivially available. + +Generally, each stage of the compile creates a talloc context and +allocates its memory out of that or children of it. At the end of the +stage, the pieces still live are stolen to a new context and the old +one freed, or the whole context is kept for use by the next stage. + +For IR transformations, a temporary context is used, then at the end +of all transformations, reparent_ir reparents all live nodes under the +shader's IR list, and the old context full of dead nodes is freed. +When developing a single IR transformation pass, this means that you +want to allocate instruction nodes out of the temporary context, so if +it becomes dead it doesn't live on as the child of a live node. At +the moment, optimization passes aren't passed that temporary context, +so they find it by calling talloc_parent() on a nearby IR node. The +talloc_parent() call is expensive, so many passes will cache the +result of the first talloc_parent(). Cleaning up all the optimization +passes to take a context argument and not call talloc_parent() is left +as an exercise. + +Q: What is the file naming convention in this directory? + +Initially, there really wasn't one. We have since adopted one: + + - Files that implement code lowering passes should be named lower_* + (e.g., lower_noise.cpp). + - Files that implement optimization passes should be named opt_*. + - Files that implement a class that is used throught the code should + take the name of that class (e.g., ir_hierarchical_visitor.cpp). + - Files that contain code not fitting in one of the previous + categories should have a sensible name (e.g., glsl_parser.ypp). diff --git a/src/glsl/SConscript b/src/glsl/SConscript new file mode 100644 index 0000000..c1adfe8 --- /dev/null +++ b/src/glsl/SConscript @@ -0,0 +1,110 @@ +import common + +Import('*') + +env = env.Clone() + +env.Prepend(CPPPATH = [ + '#src/mapi', + '#src/mesa', + '#src/glsl', +]) + +sources = [ + 'glcpp/glcpp-lex.c', + 'glcpp/glcpp-parse.c', + 'glcpp/pp.c', + 'ast_expr.cpp', + 'ast_function.cpp', + 'ast_to_hir.cpp', + 'ast_type.cpp', + 'builtin_function.cpp', + 'glsl_lexer.cpp', + 'glsl_parser.cpp', + 'glsl_parser_extras.cpp', + 'glsl_types.cpp', + 'glsl_symbol_table.cpp', + 'hir_field_selection.cpp', + 'ir_basic_block.cpp', + 'ir_clone.cpp', + 'ir_constant_expression.cpp', + 'ir.cpp', + 'ir_expression_flattening.cpp', + 'ir_function_can_inline.cpp', + 'ir_function.cpp', + 'ir_hierarchical_visitor.cpp', + 'ir_hv_accept.cpp', + 'ir_import_prototypes.cpp', + 'ir_print_visitor.cpp', + 'ir_reader.cpp', + 'ir_rvalue_visitor.cpp', + 'ir_set_program_inouts.cpp', + 'ir_validate.cpp', + 'ir_variable.cpp', + 'ir_variable_refcount.cpp', + 'linker.cpp', + 'link_functions.cpp', + 'loop_analysis.cpp', + 'loop_controls.cpp', + 'loop_unroll.cpp', + 'lower_discard.cpp', + 'lower_if_to_cond_assign.cpp', + 'lower_instructions.cpp', + 'lower_jumps.cpp', + 'lower_mat_op_to_vec.cpp', + 'lower_noise.cpp', + 'lower_variable_index_to_cond_assign.cpp', + 'lower_vec_index_to_cond_assign.cpp', + 'lower_vec_index_to_swizzle.cpp', + 'lower_vector.cpp', + 'opt_algebraic.cpp', + 'opt_constant_folding.cpp', + 'opt_constant_propagation.cpp', + 'opt_constant_variable.cpp', + 'opt_copy_propagation.cpp', + 'opt_dead_code.cpp', + 'opt_dead_code_local.cpp', + 'opt_dead_functions.cpp', + 'opt_discard_simplification.cpp', + 'opt_function_inlining.cpp', + 'opt_if_simplification.cpp', + 'opt_noop_swizzle.cpp', + 'opt_redundant_jumps.cpp', + 'opt_structure_splitting.cpp', + 'opt_swizzle_swizzle.cpp', + 'opt_tree_grafting.cpp', + 'ralloc.c', + 's_expression.cpp', + 'strtod.c', +] + +glsl = env.ConvenienceLibrary( + target = 'glsl', + source = sources, +) + +Export('glsl') + +# FIXME: We can't build the programs because there's a cyclic dependency between tis directory and src/mesa +Return() + +env = env.Clone() + +if env['platform'] == 'windows': + env.PrependUnique(LIBS = [ + 'user32', + ]) + +env.Prepend(LIBS = [glsl]) + +env.Program( + target = 'glsl2', + source = [ + 'main.cpp', + ] +) + +env.Program( + target = 'glcpp', + source = ['glcpp/glcpp.c'], +) diff --git a/src/glsl/ast.h b/src/glsl/ast.h new file mode 100644 index 0000000..da11f5a --- /dev/null +++ b/src/glsl/ast.h @@ -0,0 +1,726 @@ +/* -*- c++ -*- */ +/* + * Copyright © 2009 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#ifndef AST_H +#define AST_H + +#include "list.h" +#include "glsl_parser_extras.h" + +struct _mesa_glsl_parse_state; + +struct YYLTYPE; + +/** + * \defgroup AST Abstract syntax tree node definitions + * + * An abstract syntax tree is generated by the parser. This is a fairly + * direct representation of the gramma derivation for the source program. + * No symantic checking is done during the generation of the AST. Only + * syntactic checking is done. Symantic checking is performed by a later + * stage that converts the AST to a more generic intermediate representation. + * + *@{ + */ +/** + * Base class of all abstract syntax tree nodes + */ +class ast_node { +public: + /* Callers of this ralloc-based new need not call delete. It's + * easier to just ralloc_free 'ctx' (or any of its ancestors). */ + static void* operator new(size_t size, void *ctx) + { + void *node; + + node = rzalloc_size(ctx, size); + assert(node != NULL); + + return node; + } + + /* If the user *does* call delete, that's OK, we will just + * ralloc_free in that case. */ + static void operator delete(void *table) + { + ralloc_free(table); + } + + /** + * Print an AST node in something approximating the original GLSL code + */ + virtual void print(void) const; + + /** + * Convert the AST node to the high-level intermediate representation + */ + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + + /** + * Retrieve the source location of an AST node + * + * This function is primarily used to get the source position of an AST node + * into a form that can be passed to \c _mesa_glsl_error. + * + * \sa _mesa_glsl_error, ast_node::set_location + */ + struct YYLTYPE get_location(void) const + { + struct YYLTYPE locp; + + locp.source = this->location.source; + locp.first_line = this->location.line; + locp.first_column = this->location.column; + locp.last_line = locp.first_line; + locp.last_column = locp.first_column; + + return locp; + } + + /** + * Set the source location of an AST node from a parser location + * + * \sa ast_node::get_location + */ + void set_location(const struct YYLTYPE &locp) + { + this->location.source = locp.source; + this->location.line = locp.first_line; + this->location.column = locp.first_column; + } + + /** + * Source location of the AST node. + */ + struct { + unsigned source; /**< GLSL source number. */ + unsigned line; /**< Line number within the source string. */ + unsigned column; /**< Column in the line. */ + } location; + + exec_node link; + +protected: + /** + * The only constructor is protected so that only derived class objects can + * be created. + */ + ast_node(void); +}; + + +/** + * Operators for AST expression nodes. + */ +enum ast_operators { + ast_assign, + ast_plus, /**< Unary + operator. */ + ast_neg, + ast_add, + ast_sub, + ast_mul, + ast_div, + ast_mod, + ast_lshift, + ast_rshift, + ast_less, + ast_greater, + ast_lequal, + ast_gequal, + ast_equal, + ast_nequal, + ast_bit_and, + ast_bit_xor, + ast_bit_or, + ast_bit_not, + ast_logic_and, + ast_logic_xor, + ast_logic_or, + ast_logic_not, + + ast_mul_assign, + ast_div_assign, + ast_mod_assign, + ast_add_assign, + ast_sub_assign, + ast_ls_assign, + ast_rs_assign, + ast_and_assign, + ast_xor_assign, + ast_or_assign, + + ast_conditional, + + ast_pre_inc, + ast_pre_dec, + ast_post_inc, + ast_post_dec, + ast_field_selection, + ast_array_index, + + ast_function_call, + + ast_identifier, + ast_int_constant, + ast_uint_constant, + ast_float_constant, + ast_bool_constant, + + ast_sequence +}; + +/** + * Representation of any sort of expression. + */ +class ast_expression : public ast_node { +public: + ast_expression(int oper, ast_expression *, + ast_expression *, ast_expression *); + + ast_expression(const char *identifier) : + oper(ast_identifier) + { + subexpressions[0] = NULL; + subexpressions[1] = NULL; + subexpressions[2] = NULL; + primary_expression.identifier = (char *) identifier; + } + + static const char *operator_string(enum ast_operators op); + + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + + virtual void print(void) const; + + enum ast_operators oper; + + ast_expression *subexpressions[3]; + + union { + char *identifier; + int int_constant; + float float_constant; + unsigned uint_constant; + int bool_constant; + } primary_expression; + + + /** + * List of expressions for an \c ast_sequence or parameters for an + * \c ast_function_call + */ + exec_list expressions; +}; + +class ast_expression_bin : public ast_expression { +public: + ast_expression_bin(int oper, ast_expression *, ast_expression *); + + virtual void print(void) const; +}; + +/** + * Subclass of expressions for function calls + */ +class ast_function_expression : public ast_expression { +public: + ast_function_expression(ast_expression *callee) + : ast_expression(ast_function_call, callee, + NULL, NULL), + cons(false) + { + /* empty */ + } + + ast_function_expression(class ast_type_specifier *type) + : ast_expression(ast_function_call, (ast_expression *) type, + NULL, NULL), + cons(true) + { + /* empty */ + } + + bool is_constructor() const + { + return cons; + } + + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + +private: + /** + * Is this function call actually a constructor? + */ + bool cons; +}; + + +/** + * Number of possible operators for an ast_expression + * + * This is done as a define instead of as an additional value in the enum so + * that the compiler won't generate spurious messages like "warning: + * enumeration value ‘ast_num_operators’ not handled in switch" + */ +#define AST_NUM_OPERATORS (ast_sequence + 1) + + +class ast_compound_statement : public ast_node { +public: + ast_compound_statement(int new_scope, ast_node *statements); + virtual void print(void) const; + + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + + int new_scope; + exec_list statements; +}; + +class ast_declaration : public ast_node { +public: + ast_declaration(char *identifier, int is_array, ast_expression *array_size, + ast_expression *initializer); + virtual void print(void) const; + + char *identifier; + + int is_array; + ast_expression *array_size; + + ast_expression *initializer; +}; + + +enum { + ast_precision_none = 0, /**< Absence of precision qualifier. */ + ast_precision_high, + ast_precision_medium, + ast_precision_low +}; + +struct ast_type_qualifier { + union { + struct { + unsigned invariant:1; + unsigned constant:1; + unsigned attribute:1; + unsigned varying:1; + unsigned in:1; + unsigned out:1; + unsigned centroid:1; + unsigned uniform:1; + unsigned smooth:1; + unsigned flat:1; + unsigned noperspective:1; + + /** \name Layout qualifiers for GL_ARB_fragment_coord_conventions */ + /*@{*/ + unsigned origin_upper_left:1; + unsigned pixel_center_integer:1; + /*@}*/ + + /** + * Flag set if GL_ARB_explicit_attrib_location "location" layout + * qualifier is used. + */ + unsigned explicit_location:1; + } q; + unsigned i; + } flags; + + /** + * Location specified via GL_ARB_explicit_attrib_location layout + * + * \note + * This field is only valid if \c explicit_location is set. + */ + unsigned location; +}; + +class ast_struct_specifier : public ast_node { +public: + ast_struct_specifier(char *identifier, ast_node *declarator_list); + virtual void print(void) const; + + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + + char *name; + exec_list declarations; +}; + + +enum ast_types { + ast_void, + ast_float, + ast_int, + ast_uint, + ast_bool, + ast_vec2, + ast_vec3, + ast_vec4, + ast_bvec2, + ast_bvec3, + ast_bvec4, + ast_ivec2, + ast_ivec3, + ast_ivec4, + ast_uvec2, + ast_uvec3, + ast_uvec4, + ast_mat2, + ast_mat2x3, + ast_mat2x4, + ast_mat3x2, + ast_mat3, + ast_mat3x4, + ast_mat4x2, + ast_mat4x3, + ast_mat4, + ast_sampler1d, + ast_sampler2d, + ast_sampler2drect, + ast_sampler3d, + ast_samplercube, + ast_sampler1dshadow, + ast_sampler2dshadow, + ast_sampler2drectshadow, + ast_samplercubeshadow, + ast_sampler1darray, + ast_sampler2darray, + ast_sampler1darrayshadow, + ast_sampler2darrayshadow, + ast_isampler1d, + ast_isampler2d, + ast_isampler3d, + ast_isamplercube, + ast_isampler1darray, + ast_isampler2darray, + ast_usampler1d, + ast_usampler2d, + ast_usampler3d, + ast_usamplercube, + ast_usampler1darray, + ast_usampler2darray, + + ast_struct, + ast_type_name +}; + + +class ast_type_specifier : public ast_node { +public: + ast_type_specifier(int specifier); + + /** Construct a type specifier from a type name */ + ast_type_specifier(const char *name) + : type_specifier(ast_type_name), type_name(name), structure(NULL), + is_array(false), array_size(NULL), precision(ast_precision_none), + is_precision_statement(false) + { + /* empty */ + } + + /** Construct a type specifier from a structure definition */ + ast_type_specifier(ast_struct_specifier *s) + : type_specifier(ast_struct), type_name(s->name), structure(s), + is_array(false), array_size(NULL), precision(ast_precision_none), + is_precision_statement(false) + { + /* empty */ + } + + const struct glsl_type *glsl_type(const char **name, + struct _mesa_glsl_parse_state *state) + const; + + virtual void print(void) const; + + ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *); + + enum ast_types type_specifier; + + const char *type_name; + ast_struct_specifier *structure; + + int is_array; + ast_expression *array_size; + + unsigned precision:2; + + bool is_precision_statement; +}; + + +class ast_fully_specified_type : public ast_node { +public: + virtual void print(void) const; + bool has_qualifiers() const; + + ast_type_qualifier qualifier; + ast_type_specifier *specifier; +}; + + +class ast_declarator_list : public ast_node { +public: + ast_declarator_list(ast_fully_specified_type *); + virtual void print(void) const; + + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + + ast_fully_specified_type *type; + exec_list declarations; + + /** + * Special flag for vertex shader "invariant" declarations. + * + * Vertex shaders can contain "invariant" variable redeclarations that do + * not include a type. For example, "invariant gl_Position;". This flag + * is used to note these cases when no type is specified. + */ + int invariant; +}; + + +class ast_parameter_declarator : public ast_node { +public: + ast_parameter_declarator() + { + this->identifier = NULL; + this->is_array = false; + this->array_size = 0; + } + + virtual void print(void) const; + + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + + ast_fully_specified_type *type; + char *identifier; + int is_array; + ast_expression *array_size; + + static void parameters_to_hir(exec_list *ast_parameters, + bool formal, exec_list *ir_parameters, + struct _mesa_glsl_parse_state *state); + +private: + /** Is this parameter declaration part of a formal parameter list? */ + bool formal_parameter; + + /** + * Is this parameter 'void' type? + * + * This field is set by \c ::hir. + */ + bool is_void; +}; + + +class ast_function : public ast_node { +public: + ast_function(void); + + virtual void print(void) const; + + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + + ast_fully_specified_type *return_type; + char *identifier; + + exec_list parameters; + +private: + /** + * Is this prototype part of the function definition? + * + * Used by ast_function_definition::hir to process the parameters, etc. + * of the function. + * + * \sa ::hir + */ + bool is_definition; + + /** + * Function signature corresponding to this function prototype instance + * + * Used by ast_function_definition::hir to process the parameters, etc. + * of the function. + * + * \sa ::hir + */ + class ir_function_signature *signature; + + friend class ast_function_definition; +}; + + +class ast_declaration_statement : public ast_node { +public: + ast_declaration_statement(void); + + enum { + ast_function, + ast_declaration, + ast_precision + } mode; + + union { + class ast_function *function; + ast_declarator_list *declarator; + ast_type_specifier *type; + ast_node *node; + } declaration; +}; + + +class ast_expression_statement : public ast_node { +public: + ast_expression_statement(ast_expression *); + virtual void print(void) const; + + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + + ast_expression *expression; +}; + + +class ast_case_label : public ast_node { +public: + + /** + * An expression of NULL means 'default'. + */ + ast_expression *expression; +}; + +class ast_selection_statement : public ast_node { +public: + ast_selection_statement(ast_expression *condition, + ast_node *then_statement, + ast_node *else_statement); + virtual void print(void) const; + + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + + ast_expression *condition; + ast_node *then_statement; + ast_node *else_statement; +}; + + +class ast_switch_statement : public ast_node { +public: + ast_expression *expression; + exec_list statements; +}; + +class ast_iteration_statement : public ast_node { +public: + ast_iteration_statement(int mode, ast_node *init, ast_node *condition, + ast_expression *rest_expression, ast_node *body); + + virtual void print(void) const; + + virtual ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *); + + enum ast_iteration_modes { + ast_for, + ast_while, + ast_do_while + } mode; + + + ast_node *init_statement; + ast_node *condition; + ast_expression *rest_expression; + + ast_node *body; + +private: + /** + * Generate IR from the condition of a loop + * + * This is factored out of ::hir because some loops have the condition + * test at the top (for and while), and others have it at the end (do-while). + */ + void condition_to_hir(class ir_loop *, struct _mesa_glsl_parse_state *); +}; + + +class ast_jump_statement : public ast_node { +public: + ast_jump_statement(int mode, ast_expression *return_value); + virtual void print(void) const; + + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + + enum ast_jump_modes { + ast_continue, + ast_break, + ast_return, + ast_discard + } mode; + + ast_expression *opt_return_value; +}; + + +class ast_function_definition : public ast_node { +public: + virtual void print(void) const; + + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + + ast_function *prototype; + ast_compound_statement *body; +}; +/*@}*/ + +extern void +_mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state); + +extern ir_rvalue * +_mesa_ast_field_selection_to_hir(const ast_expression *expr, + exec_list *instructions, + struct _mesa_glsl_parse_state *state); + +void +emit_function(_mesa_glsl_parse_state *state, exec_list *instructions, + ir_function *f); + +#endif /* AST_H */ diff --git a/src/glsl/ast_expr.cpp b/src/glsl/ast_expr.cpp new file mode 100644 index 0000000..7e0c7bd --- /dev/null +++ b/src/glsl/ast_expr.cpp @@ -0,0 +1,96 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#include +#include +#include "ast.h" + +const char * +ast_expression::operator_string(enum ast_operators op) +{ + static const char *const operators[] = { + "=", + "+", + "-", + "+", + "-", + "*", + "/", + "%", + "<<", + ">>", + "<", + ">", + "<=", + ">=", + "==", + "!=", + "&", + "^", + "|", + "~", + "&&", + "^^", + "||", + "!", + + "*=", + "/=", + "%=", + "+=", + "-=", + "<<=", + ">>=", + "&=", + "^=", + "|=", + + "?:", + + "++", + "--", + "++", + "--", + ".", + }; + + assert((unsigned int)op < sizeof(operators) / sizeof(operators[0])); + + return operators[op]; +} + + +ast_expression_bin::ast_expression_bin(int oper, ast_expression *ex0, + ast_expression *ex1) : + ast_expression(oper, ex0, ex1, NULL) +{ + assert((oper >= ast_plus) && (oper <= ast_logic_not)); +} + + +void +ast_expression_bin::print(void) const +{ + subexpressions[0]->print(); + printf("%s ", operator_string(oper)); + subexpressions[1]->print(); +} diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp new file mode 100644 index 0000000..9ff0c0d --- /dev/null +++ b/src/glsl/ast_function.cpp @@ -0,0 +1,1267 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "glsl_symbol_table.h" +#include "ast.h" +#include "glsl_types.h" +#include "ir.h" +#include "main/core.h" /* for MIN2 */ + +static ir_rvalue * +convert_component(ir_rvalue *src, const glsl_type *desired_type); + +bool +apply_implicit_conversion(const glsl_type *to, ir_rvalue * &from, + struct _mesa_glsl_parse_state *state); + +static unsigned +process_parameters(exec_list *instructions, exec_list *actual_parameters, + exec_list *parameters, + struct _mesa_glsl_parse_state *state) +{ + unsigned count = 0; + + foreach_list (n, parameters) { + ast_node *const ast = exec_node_data(ast_node, n, link); + ir_rvalue *result = ast->hir(instructions, state); + + ir_constant *const constant = result->constant_expression_value(); + if (constant != NULL) + result = constant; + + actual_parameters->push_tail(result); + count++; + } + + return count; +} + + +/** + * Generate a source prototype for a function signature + * + * \param return_type Return type of the function. May be \c NULL. + * \param name Name of the function. + * \param parameters Parameter list for the function. This may be either a + * formal or actual parameter list. Only the type is used. + * + * \return + * A ralloced string representing the prototype of the function. + */ +char * +prototype_string(const glsl_type *return_type, const char *name, + exec_list *parameters) +{ + char *str = NULL; + + if (return_type != NULL) + str = ralloc_asprintf(NULL, "%s ", return_type->name); + + ralloc_asprintf_append(&str, "%s(", name); + + const char *comma = ""; + foreach_list(node, parameters) { + const ir_instruction *const param = (ir_instruction *) node; + + ralloc_asprintf_append(&str, "%s%s", comma, param->type->name); + comma = ", "; + } + + ralloc_strcat(&str, ")"); + return str; +} + + +static ir_rvalue * +match_function_by_name(exec_list *instructions, const char *name, + YYLTYPE *loc, exec_list *actual_parameters, + struct _mesa_glsl_parse_state *state) +{ + void *ctx = state; + ir_function *f = state->symbols->get_function(name); + ir_function_signature *sig; + + sig = f ? f->matching_signature(actual_parameters) : NULL; + + /* FINISHME: This doesn't handle the case where shader X contains a + * FINISHME: matching signature but shader X + N contains an _exact_ + * FINISHME: matching signature. + */ + if (sig == NULL && (f == NULL || state->es_shader || !f->has_user_signature()) && state->symbols->get_type(name) == NULL && (state->language_version == 110 || state->symbols->get_variable(name) == NULL)) { + /* The current shader doesn't contain a matching function or signature. + * Before giving up, look for the prototype in the built-in functions. + */ + for (unsigned i = 0; i < state->num_builtins_to_link; i++) { + ir_function *builtin; + builtin = state->builtins_to_link[i]->symbols->get_function(name); + sig = builtin ? builtin->matching_signature(actual_parameters) : NULL; + if (sig != NULL) { + if (f == NULL) { + f = new(ctx) ir_function(name); + state->symbols->add_global_function(f); + emit_function(state, instructions, f); + } + + f->add_signature(sig->clone_prototype(f, NULL)); + break; + } + } + } + + if (sig != NULL) { + /* Verify that 'out' and 'inout' actual parameters are lvalues. This + * isn't done in ir_function::matching_signature because that function + * cannot generate the necessary diagnostics. + */ + exec_list_iterator actual_iter = actual_parameters->iterator(); + exec_list_iterator formal_iter = sig->parameters.iterator(); + + while (actual_iter.has_next()) { + ir_rvalue *actual = (ir_rvalue *) actual_iter.get(); + ir_variable *formal = (ir_variable *) formal_iter.get(); + + assert(actual != NULL); + assert(formal != NULL); + + if ((formal->mode == ir_var_out) + || (formal->mode == ir_var_inout)) { + if (! actual->is_lvalue()) { + /* FINISHME: Log a better diagnostic here. There is no way + * FINISHME: to tell the user which parameter is invalid. + */ + _mesa_glsl_error(loc, state, "`%s' parameter is not lvalue", + (formal->mode == ir_var_out) ? "out" : "inout"); + } + } + + if (formal->type->is_numeric() || formal->type->is_boolean()) { + ir_rvalue *converted = convert_component(actual, formal->type); + actual->replace_with(converted); + } + + actual_iter.next(); + formal_iter.next(); + } + + /* Always insert the call in the instruction stream, and return a deref + * of its return val if it returns a value, since we don't know if + * the rvalue is going to be assigned to anything or not. + */ + ir_call *call = new(ctx) ir_call(sig, actual_parameters); + if (!sig->return_type->is_void()) { + ir_variable *var; + ir_dereference_variable *deref; + + var = new(ctx) ir_variable(sig->return_type, + ralloc_asprintf(ctx, "%s_retval", + sig->function_name()), + ir_var_temporary); + instructions->push_tail(var); + + deref = new(ctx) ir_dereference_variable(var); + ir_assignment *assign = new(ctx) ir_assignment(deref, call, NULL); + instructions->push_tail(assign); + if (state->language_version >= 120) + var->constant_value = call->constant_expression_value(); + + deref = new(ctx) ir_dereference_variable(var); + return deref; + } else { + instructions->push_tail(call); + return NULL; + } + } else { + char *str = prototype_string(NULL, name, actual_parameters); + + _mesa_glsl_error(loc, state, "no matching function for call to `%s'", + str); + ralloc_free(str); + + const char *prefix = "candidates are: "; + + for (int i = -1; i < state->num_builtins_to_link; i++) { + glsl_symbol_table *syms = i >= 0 ? state->builtins_to_link[i]->symbols + : state->symbols; + f = syms->get_function(name); + if (f == NULL) + continue; + + foreach_list (node, &f->signatures) { + ir_function_signature *sig = (ir_function_signature *) node; + + str = prototype_string(sig->return_type, f->name, &sig->parameters); + _mesa_glsl_error(loc, state, "%s%s\n", prefix, str); + ralloc_free(str); + + prefix = " "; + } + + } + + return ir_call::get_error_instruction(ctx); + } +} + + +/** + * Perform automatic type conversion of constructor parameters + * + * This implements the rules in the "Conversion and Scalar Constructors" + * section (GLSL 1.10 section 5.4.1), not the "Implicit Conversions" rules. + */ +static ir_rvalue * +convert_component(ir_rvalue *src, const glsl_type *desired_type) +{ + void *ctx = ralloc_parent(src); + const unsigned a = desired_type->base_type; + const unsigned b = src->type->base_type; + ir_expression *result = NULL; + + if (src->type->is_error()) + return src; + + assert(a <= GLSL_TYPE_BOOL); + assert(b <= GLSL_TYPE_BOOL); + + if ((a == b) || (src->type->is_integer() && desired_type->is_integer())) + return src; + + switch (a) { + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: + if (b == GLSL_TYPE_FLOAT) + result = new(ctx) ir_expression(ir_unop_f2i, desired_type, src, NULL); + else { + assert(b == GLSL_TYPE_BOOL); + result = new(ctx) ir_expression(ir_unop_b2i, desired_type, src, NULL); + } + break; + case GLSL_TYPE_FLOAT: + switch (b) { + case GLSL_TYPE_UINT: + result = new(ctx) ir_expression(ir_unop_u2f, desired_type, src, NULL); + break; + case GLSL_TYPE_INT: + result = new(ctx) ir_expression(ir_unop_i2f, desired_type, src, NULL); + break; + case GLSL_TYPE_BOOL: + result = new(ctx) ir_expression(ir_unop_b2f, desired_type, src, NULL); + break; + } + break; + case GLSL_TYPE_BOOL: + switch (b) { + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: + result = new(ctx) ir_expression(ir_unop_i2b, desired_type, src, NULL); + break; + case GLSL_TYPE_FLOAT: + result = new(ctx) ir_expression(ir_unop_f2b, desired_type, src, NULL); + break; + } + break; + } + + assert(result != NULL); + + /* Try constant folding; it may fold in the conversion we just added. */ + ir_constant *const constant = result->constant_expression_value(); + return (constant != NULL) ? (ir_rvalue *) constant : (ir_rvalue *) result; +} + +/** + * Dereference a specific component from a scalar, vector, or matrix + */ +static ir_rvalue * +dereference_component(ir_rvalue *src, unsigned component) +{ + void *ctx = ralloc_parent(src); + assert(component < src->type->components()); + + /* If the source is a constant, just create a new constant instead of a + * dereference of the existing constant. + */ + ir_constant *constant = src->as_constant(); + if (constant) + return new(ctx) ir_constant(constant, component); + + if (src->type->is_scalar()) { + return src; + } else if (src->type->is_vector()) { + return new(ctx) ir_swizzle(src, component, 0, 0, 0, 1); + } else { + assert(src->type->is_matrix()); + + /* Dereference a row of the matrix, then call this function again to get + * a specific element from that row. + */ + const int c = component / src->type->column_type()->vector_elements; + const int r = component % src->type->column_type()->vector_elements; + ir_constant *const col_index = new(ctx) ir_constant(c); + ir_dereference *const col = new(ctx) ir_dereference_array(src, col_index); + + col->type = src->type->column_type(); + + return dereference_component(col, r); + } + + assert(!"Should not get here."); + return NULL; +} + + +static ir_rvalue * +process_array_constructor(exec_list *instructions, + const glsl_type *constructor_type, + YYLTYPE *loc, exec_list *parameters, + struct _mesa_glsl_parse_state *state) +{ + void *ctx = state; + /* Array constructors come in two forms: sized and unsized. Sized array + * constructors look like 'vec4[2](a, b)', where 'a' and 'b' are vec4 + * variables. In this case the number of parameters must exactly match the + * specified size of the array. + * + * Unsized array constructors look like 'vec4[](a, b)', where 'a' and 'b' + * are vec4 variables. In this case the size of the array being constructed + * is determined by the number of parameters. + * + * From page 52 (page 58 of the PDF) of the GLSL 1.50 spec: + * + * "There must be exactly the same number of arguments as the size of + * the array being constructed. If no size is present in the + * constructor, then the array is explicitly sized to the number of + * arguments provided. The arguments are assigned in order, starting at + * element 0, to the elements of the constructed array. Each argument + * must be the same type as the element type of the array, or be a type + * that can be converted to the element type of the array according to + * Section 4.1.10 "Implicit Conversions."" + */ + exec_list actual_parameters; + const unsigned parameter_count = + process_parameters(instructions, &actual_parameters, parameters, state); + + if ((parameter_count == 0) + || ((constructor_type->length != 0) + && (constructor_type->length != parameter_count))) { + const unsigned min_param = (constructor_type->length == 0) + ? 1 : constructor_type->length; + + _mesa_glsl_error(loc, state, "array constructor must have %s %u " + "parameter%s", + (constructor_type->length != 0) ? "at least" : "exactly", + min_param, (min_param <= 1) ? "" : "s"); + return ir_call::get_error_instruction(ctx); + } + + if (constructor_type->length == 0) { + constructor_type = + glsl_type::get_array_instance(constructor_type->element_type(), + parameter_count); + assert(constructor_type != NULL); + assert(constructor_type->length == parameter_count); + } + + bool all_parameters_are_constant = true; + + /* Type cast each parameter and, if possible, fold constants. */ + foreach_list_safe(n, &actual_parameters) { + ir_rvalue *ir = (ir_rvalue *) n; + ir_rvalue *result = ir; + + /* Apply implicit conversions (not the scalar constructor rules!) */ + if (constructor_type->element_type()->is_float()) { + const glsl_type *desired_type = + glsl_type::get_instance(GLSL_TYPE_FLOAT, + ir->type->vector_elements, + ir->type->matrix_columns); + result = convert_component(ir, desired_type); + } + + if (result->type != constructor_type->element_type()) { + _mesa_glsl_error(loc, state, "type error in array constructor: " + "expected: %s, found %s", + constructor_type->element_type()->name, + result->type->name); + } + + /* Attempt to convert the parameter to a constant valued expression. + * After doing so, track whether or not all the parameters to the + * constructor are trivially constant valued expressions. + */ + ir_rvalue *const constant = result->constant_expression_value(); + + if (constant != NULL) + result = constant; + else + all_parameters_are_constant = false; + + ir->replace_with(result); + } + + if (all_parameters_are_constant) + return new(ctx) ir_constant(constructor_type, &actual_parameters); + + ir_variable *var = new(ctx) ir_variable(constructor_type, "array_ctor", + ir_var_temporary); + instructions->push_tail(var); + + int i = 0; + foreach_list(node, &actual_parameters) { + ir_rvalue *rhs = (ir_rvalue *) node; + ir_rvalue *lhs = new(ctx) ir_dereference_array(var, + new(ctx) ir_constant(i)); + + ir_instruction *assignment = new(ctx) ir_assignment(lhs, rhs, NULL); + instructions->push_tail(assignment); + + i++; + } + + return new(ctx) ir_dereference_variable(var); +} + + +/** + * Try to convert a record constructor to a constant expression + */ +static ir_constant * +constant_record_constructor(const glsl_type *constructor_type, + exec_list *parameters, void *mem_ctx) +{ + foreach_list(node, parameters) { + ir_constant *constant = ((ir_instruction *) node)->as_constant(); + if (constant == NULL) + return NULL; + node->replace_with(constant); + } + + return new(mem_ctx) ir_constant(constructor_type, parameters); +} + + +/** + * Determine if a list consists of a single scalar r-value + */ +bool +single_scalar_parameter(exec_list *parameters) +{ + const ir_rvalue *const p = (ir_rvalue *) parameters->head; + assert(((ir_rvalue *)p)->as_rvalue() != NULL); + + return (p->type->is_scalar() && p->next->is_tail_sentinel()); +} + + +/** + * Generate inline code for a vector constructor + * + * The generated constructor code will consist of a temporary variable + * declaration of the same type as the constructor. A sequence of assignments + * from constructor parameters to the temporary will follow. + * + * \return + * An \c ir_dereference_variable of the temprorary generated in the constructor + * body. + */ +ir_rvalue * +emit_inline_vector_constructor(const glsl_type *type, + exec_list *instructions, + exec_list *parameters, + void *ctx) +{ + assert(!parameters->is_empty()); + + ir_variable *var = new(ctx) ir_variable(type, "vec_ctor", ir_var_temporary); + instructions->push_tail(var); + + /* There are two kinds of vector constructors. + * + * - Construct a vector from a single scalar by replicating that scalar to + * all components of the vector. + * + * - Construct a vector from an arbirary combination of vectors and + * scalars. The components of the constructor parameters are assigned + * to the vector in order until the vector is full. + */ + const unsigned lhs_components = type->components(); + if (single_scalar_parameter(parameters)) { + ir_rvalue *first_param = (ir_rvalue *)parameters->head; + ir_rvalue *rhs = new(ctx) ir_swizzle(first_param, 0, 0, 0, 0, + lhs_components); + ir_dereference_variable *lhs = new(ctx) ir_dereference_variable(var); + const unsigned mask = (1U << lhs_components) - 1; + + assert(rhs->type == lhs->type); + + ir_instruction *inst = new(ctx) ir_assignment(lhs, rhs, NULL, mask); + instructions->push_tail(inst); + } else { + unsigned base_component = 0; + unsigned base_lhs_component = 0; + ir_constant_data data; + unsigned constant_mask = 0, constant_components = 0; + + memset(&data, 0, sizeof(data)); + + foreach_list(node, parameters) { + ir_rvalue *param = (ir_rvalue *) node; + unsigned rhs_components = param->type->components(); + + /* Do not try to assign more components to the vector than it has! + */ + if ((rhs_components + base_lhs_component) > lhs_components) { + rhs_components = lhs_components - base_lhs_component; + } + + const ir_constant *const c = param->as_constant(); + if (c != NULL) { + for (unsigned i = 0; i < rhs_components; i++) { + switch (c->type->base_type) { + case GLSL_TYPE_UINT: + data.u[i + base_component] = c->get_uint_component(i); + break; + case GLSL_TYPE_INT: + data.i[i + base_component] = c->get_int_component(i); + break; + case GLSL_TYPE_FLOAT: + data.f[i + base_component] = c->get_float_component(i); + break; + case GLSL_TYPE_BOOL: + data.b[i + base_component] = c->get_bool_component(i); + break; + default: + assert(!"Should not get here."); + break; + } + } + + /* Mask of fields to be written in the assignment. + */ + constant_mask |= ((1U << rhs_components) - 1) << base_lhs_component; + constant_components += rhs_components; + + base_component += rhs_components; + } + /* Advance the component index by the number of components + * that were just assigned. + */ + base_lhs_component += rhs_components; + } + + if (constant_mask != 0) { + ir_dereference *lhs = new(ctx) ir_dereference_variable(var); + const glsl_type *rhs_type = glsl_type::get_instance(var->type->base_type, + constant_components, + 1); + ir_rvalue *rhs = new(ctx) ir_constant(rhs_type, &data); + + ir_instruction *inst = + new(ctx) ir_assignment(lhs, rhs, NULL, constant_mask); + instructions->push_tail(inst); + } + + base_component = 0; + foreach_list(node, parameters) { + ir_rvalue *param = (ir_rvalue *) node; + unsigned rhs_components = param->type->components(); + + /* Do not try to assign more components to the vector than it has! + */ + if ((rhs_components + base_component) > lhs_components) { + rhs_components = lhs_components - base_component; + } + + const ir_constant *const c = param->as_constant(); + if (c == NULL) { + /* Mask of fields to be written in the assignment. + */ + const unsigned write_mask = ((1U << rhs_components) - 1) + << base_component; + + ir_dereference *lhs = new(ctx) ir_dereference_variable(var); + + /* Generate a swizzle so that LHS and RHS sizes match. + */ + ir_rvalue *rhs = + new(ctx) ir_swizzle(param, 0, 1, 2, 3, rhs_components); + + ir_instruction *inst = + new(ctx) ir_assignment(lhs, rhs, NULL, write_mask); + instructions->push_tail(inst); + } + + /* Advance the component index by the number of components that were + * just assigned. + */ + base_component += rhs_components; + } + } + return new(ctx) ir_dereference_variable(var); +} + + +/** + * Generate assignment of a portion of a vector to a portion of a matrix column + * + * \param src_base First component of the source to be used in assignment + * \param column Column of destination to be assiged + * \param row_base First component of the destination column to be assigned + * \param count Number of components to be assigned + * + * \note + * \c src_base + \c count must be less than or equal to the number of components + * in the source vector. + */ +ir_instruction * +assign_to_matrix_column(ir_variable *var, unsigned column, unsigned row_base, + ir_rvalue *src, unsigned src_base, unsigned count, + void *mem_ctx) +{ + ir_constant *col_idx = new(mem_ctx) ir_constant(column); + ir_dereference *column_ref = new(mem_ctx) ir_dereference_array(var, col_idx); + + assert(column_ref->type->components() >= (row_base + count)); + assert(src->type->components() >= (src_base + count)); + + /* Generate a swizzle that extracts the number of components from the source + * that are to be assigned to the column of the matrix. + */ + if (count < src->type->vector_elements) { + src = new(mem_ctx) ir_swizzle(src, + src_base + 0, src_base + 1, + src_base + 2, src_base + 3, + count); + } + + /* Mask of fields to be written in the assignment. + */ + const unsigned write_mask = ((1U << count) - 1) << row_base; + + return new(mem_ctx) ir_assignment(column_ref, src, NULL, write_mask); +} + + +/** + * Generate inline code for a matrix constructor + * + * The generated constructor code will consist of a temporary variable + * declaration of the same type as the constructor. A sequence of assignments + * from constructor parameters to the temporary will follow. + * + * \return + * An \c ir_dereference_variable of the temprorary generated in the constructor + * body. + */ +ir_rvalue * +emit_inline_matrix_constructor(const glsl_type *type, + exec_list *instructions, + exec_list *parameters, + void *ctx) +{ + assert(!parameters->is_empty()); + + ir_variable *var = new(ctx) ir_variable(type, "mat_ctor", ir_var_temporary); + instructions->push_tail(var); + + /* There are three kinds of matrix constructors. + * + * - Construct a matrix from a single scalar by replicating that scalar to + * along the diagonal of the matrix and setting all other components to + * zero. + * + * - Construct a matrix from an arbirary combination of vectors and + * scalars. The components of the constructor parameters are assigned + * to the matrix in colum-major order until the matrix is full. + * + * - Construct a matrix from a single matrix. The source matrix is copied + * to the upper left portion of the constructed matrix, and the remaining + * elements take values from the identity matrix. + */ + ir_rvalue *const first_param = (ir_rvalue *) parameters->head; + if (single_scalar_parameter(parameters)) { + /* Assign the scalar to the X component of a vec4, and fill the remaining + * components with zero. + */ + ir_variable *rhs_var = + new(ctx) ir_variable(glsl_type::vec4_type, "mat_ctor_vec", + ir_var_temporary); + instructions->push_tail(rhs_var); + + ir_constant_data zero; + zero.f[0] = 0.0; + zero.f[1] = 0.0; + zero.f[2] = 0.0; + zero.f[3] = 0.0; + + ir_instruction *inst = + new(ctx) ir_assignment(new(ctx) ir_dereference_variable(rhs_var), + new(ctx) ir_constant(rhs_var->type, &zero), + NULL); + instructions->push_tail(inst); + + ir_dereference *const rhs_ref = new(ctx) ir_dereference_variable(rhs_var); + + inst = new(ctx) ir_assignment(rhs_ref, first_param, NULL, 0x01); + instructions->push_tail(inst); + + /* Assign the temporary vector to each column of the destination matrix + * with a swizzle that puts the X component on the diagonal of the + * matrix. In some cases this may mean that the X component does not + * get assigned into the column at all (i.e., when the matrix has more + * columns than rows). + */ + static const unsigned rhs_swiz[4][4] = { + { 0, 1, 1, 1 }, + { 1, 0, 1, 1 }, + { 1, 1, 0, 1 }, + { 1, 1, 1, 0 } + }; + + const unsigned cols_to_init = MIN2(type->matrix_columns, + type->vector_elements); + for (unsigned i = 0; i < cols_to_init; i++) { + ir_constant *const col_idx = new(ctx) ir_constant(i); + ir_rvalue *const col_ref = new(ctx) ir_dereference_array(var, col_idx); + + ir_rvalue *const rhs_ref = new(ctx) ir_dereference_variable(rhs_var); + ir_rvalue *const rhs = new(ctx) ir_swizzle(rhs_ref, rhs_swiz[i], + type->vector_elements); + + inst = new(ctx) ir_assignment(col_ref, rhs, NULL); + instructions->push_tail(inst); + } + + for (unsigned i = cols_to_init; i < type->matrix_columns; i++) { + ir_constant *const col_idx = new(ctx) ir_constant(i); + ir_rvalue *const col_ref = new(ctx) ir_dereference_array(var, col_idx); + + ir_rvalue *const rhs_ref = new(ctx) ir_dereference_variable(rhs_var); + ir_rvalue *const rhs = new(ctx) ir_swizzle(rhs_ref, 1, 1, 1, 1, + type->vector_elements); + + inst = new(ctx) ir_assignment(col_ref, rhs, NULL); + instructions->push_tail(inst); + } + } else if (first_param->type->is_matrix()) { + /* From page 50 (56 of the PDF) of the GLSL 1.50 spec: + * + * "If a matrix is constructed from a matrix, then each component + * (column i, row j) in the result that has a corresponding + * component (column i, row j) in the argument will be initialized + * from there. All other components will be initialized to the + * identity matrix. If a matrix argument is given to a matrix + * constructor, it is an error to have any other arguments." + */ + assert(first_param->next->is_tail_sentinel()); + ir_rvalue *const src_matrix = first_param; + + /* If the source matrix is smaller, pre-initialize the relavent parts of + * the destination matrix to the identity matrix. + */ + if ((src_matrix->type->matrix_columns < var->type->matrix_columns) + || (src_matrix->type->vector_elements < var->type->vector_elements)) { + + /* If the source matrix has fewer rows, every column of the destination + * must be initialized. Otherwise only the columns in the destination + * that do not exist in the source must be initialized. + */ + unsigned col = + (src_matrix->type->vector_elements < var->type->vector_elements) + ? 0 : src_matrix->type->matrix_columns; + + const glsl_type *const col_type = var->type->column_type(); + for (/* empty */; col < var->type->matrix_columns; col++) { + ir_constant_data ident; + + ident.f[0] = 0.0; + ident.f[1] = 0.0; + ident.f[2] = 0.0; + ident.f[3] = 0.0; + + ident.f[col] = 1.0; + + ir_rvalue *const rhs = new(ctx) ir_constant(col_type, &ident); + + ir_rvalue *const lhs = + new(ctx) ir_dereference_array(var, new(ctx) ir_constant(col)); + + ir_instruction *inst = new(ctx) ir_assignment(lhs, rhs, NULL); + instructions->push_tail(inst); + } + } + + /* Assign columns from the source matrix to the destination matrix. + * + * Since the parameter will be used in the RHS of multiple assignments, + * generate a temporary and copy the paramter there. + */ + ir_variable *const rhs_var = + new(ctx) ir_variable(first_param->type, "mat_ctor_mat", + ir_var_temporary); + instructions->push_tail(rhs_var); + + ir_dereference *const rhs_var_ref = + new(ctx) ir_dereference_variable(rhs_var); + ir_instruction *const inst = + new(ctx) ir_assignment(rhs_var_ref, first_param, NULL); + instructions->push_tail(inst); + + const unsigned last_row = MIN2(src_matrix->type->vector_elements, + var->type->vector_elements); + const unsigned last_col = MIN2(src_matrix->type->matrix_columns, + var->type->matrix_columns); + + unsigned swiz[4] = { 0, 0, 0, 0 }; + for (unsigned i = 1; i < last_row; i++) + swiz[i] = i; + + const unsigned write_mask = (1U << last_row) - 1; + + for (unsigned i = 0; i < last_col; i++) { + ir_dereference *const lhs = + new(ctx) ir_dereference_array(var, new(ctx) ir_constant(i)); + ir_rvalue *const rhs_col = + new(ctx) ir_dereference_array(rhs_var, new(ctx) ir_constant(i)); + + /* If one matrix has columns that are smaller than the columns of the + * other matrix, wrap the column access of the larger with a swizzle + * so that the LHS and RHS of the assignment have the same size (and + * therefore have the same type). + * + * It would be perfectly valid to unconditionally generate the + * swizzles, this this will typically result in a more compact IR tree. + */ + ir_rvalue *rhs; + if (lhs->type->vector_elements != rhs_col->type->vector_elements) { + rhs = new(ctx) ir_swizzle(rhs_col, swiz, last_row); + } else { + rhs = rhs_col; + } + + ir_instruction *inst = + new(ctx) ir_assignment(lhs, rhs, NULL, write_mask); + instructions->push_tail(inst); + } + } else { + const unsigned cols = type->matrix_columns; + const unsigned rows = type->vector_elements; + unsigned col_idx = 0; + unsigned row_idx = 0; + + foreach_list (node, parameters) { + ir_rvalue *const rhs = (ir_rvalue *) node; + const unsigned components_remaining_this_column = rows - row_idx; + unsigned rhs_components = rhs->type->components(); + unsigned rhs_base = 0; + + /* Since the parameter might be used in the RHS of two assignments, + * generate a temporary and copy the paramter there. + */ + ir_variable *rhs_var = + new(ctx) ir_variable(rhs->type, "mat_ctor_vec", ir_var_temporary); + instructions->push_tail(rhs_var); + + ir_dereference *rhs_var_ref = + new(ctx) ir_dereference_variable(rhs_var); + ir_instruction *inst = new(ctx) ir_assignment(rhs_var_ref, rhs, NULL); + instructions->push_tail(inst); + + /* Assign the current parameter to as many components of the matrix + * as it will fill. + * + * NOTE: A single vector parameter can span two matrix columns. A + * single vec4, for example, can completely fill a mat2. + */ + if (rhs_components >= components_remaining_this_column) { + const unsigned count = MIN2(rhs_components, + components_remaining_this_column); + + rhs_var_ref = new(ctx) ir_dereference_variable(rhs_var); + + ir_instruction *inst = assign_to_matrix_column(var, col_idx, + row_idx, + rhs_var_ref, 0, + count, ctx); + instructions->push_tail(inst); + + rhs_base = count; + + col_idx++; + row_idx = 0; + } + + /* If there is data left in the parameter and components left to be + * set in the destination, emit another assignment. It is possible + * that the assignment could be of a vec4 to the last element of the + * matrix. In this case col_idx==cols, but there is still data + * left in the source parameter. Obviously, don't emit an assignment + * to data outside the destination matrix. + */ + if ((col_idx < cols) && (rhs_base < rhs_components)) { + const unsigned count = rhs_components - rhs_base; + + rhs_var_ref = new(ctx) ir_dereference_variable(rhs_var); + + ir_instruction *inst = assign_to_matrix_column(var, col_idx, + row_idx, + rhs_var_ref, + rhs_base, + count, ctx); + instructions->push_tail(inst); + + row_idx += count; + } + } + } + + return new(ctx) ir_dereference_variable(var); +} + + +ir_rvalue * +emit_inline_record_constructor(const glsl_type *type, + exec_list *instructions, + exec_list *parameters, + void *mem_ctx) +{ + ir_variable *const var = + new(mem_ctx) ir_variable(type, "record_ctor", ir_var_temporary); + ir_dereference_variable *const d = new(mem_ctx) ir_dereference_variable(var); + + instructions->push_tail(var); + + exec_node *node = parameters->head; + for (unsigned i = 0; i < type->length; i++) { + assert(!node->is_tail_sentinel()); + + ir_dereference *const lhs = + new(mem_ctx) ir_dereference_record(d->clone(mem_ctx, NULL), + type->fields.structure[i].name); + + ir_rvalue *const rhs = ((ir_instruction *) node)->as_rvalue(); + assert(rhs != NULL); + + ir_instruction *const assign = new(mem_ctx) ir_assignment(lhs, rhs, NULL); + + instructions->push_tail(assign); + node = node->next; + } + + return d; +} + + +ir_rvalue * +ast_function_expression::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + void *ctx = state; + /* There are three sorts of function calls. + * + * 1. constructors - The first subexpression is an ast_type_specifier. + * 2. methods - Only the .length() method of array types. + * 3. functions - Calls to regular old functions. + * + * Method calls are actually detected when the ast_field_selection + * expression is handled. + */ + if (is_constructor()) { + const ast_type_specifier *type = (ast_type_specifier *) subexpressions[0]; + YYLTYPE loc = type->get_location(); + const char *name; + + const glsl_type *const constructor_type = type->glsl_type(& name, state); + + /* constructor_type can be NULL if a variable with the same name as the + * structure has come into scope. + */ + if (constructor_type == NULL) { + _mesa_glsl_error(& loc, state, "unknown type `%s' (structure name " + "may be shadowed by a variable with the same name)", + type->type_name); + return ir_call::get_error_instruction(ctx); + } + + + /* Constructors for samplers are illegal. + */ + if (constructor_type->is_sampler()) { + _mesa_glsl_error(& loc, state, "cannot construct sampler type `%s'", + constructor_type->name); + return ir_call::get_error_instruction(ctx); + } + + if (constructor_type->is_array()) { + if (state->language_version <= 110) { + _mesa_glsl_error(& loc, state, + "array constructors forbidden in GLSL 1.10"); + return ir_call::get_error_instruction(ctx); + } + + return process_array_constructor(instructions, constructor_type, + & loc, &this->expressions, state); + } + + + /* There are two kinds of constructor call. Constructors for built-in + * language types, such as mat4 and vec2, are free form. The only + * requirement is that the parameters must provide enough values of the + * correct scalar type. Constructors for arrays and structures must + * have the exact number of parameters with matching types in the + * correct order. These constructors follow essentially the same type + * matching rules as functions. + */ + if (constructor_type->is_record()) { + exec_list actual_parameters; + + process_parameters(instructions, &actual_parameters, + &this->expressions, state); + + exec_node *node = actual_parameters.head; + for (unsigned i = 0; i < constructor_type->length; i++) { + ir_rvalue *ir = (ir_rvalue *) node; + + if (node->is_tail_sentinel()) { + _mesa_glsl_error(&loc, state, + "insufficient parameters to constructor " + "for `%s'", + constructor_type->name); + return ir_call::get_error_instruction(ctx); + } + + if (apply_implicit_conversion(constructor_type->fields.structure[i].type, + ir, state)) { + node->replace_with(ir); + } else { + _mesa_glsl_error(&loc, state, + "parameter type mismatch in constructor " + "for `%s.%s' (%s vs %s)", + constructor_type->name, + constructor_type->fields.structure[i].name, + ir->type->name, + constructor_type->fields.structure[i].type->name); + return ir_call::get_error_instruction(ctx);; + } + + node = node->next; + } + + if (!node->is_tail_sentinel()) { + _mesa_glsl_error(&loc, state, "too many parameters in constructor " + "for `%s'", constructor_type->name); + return ir_call::get_error_instruction(ctx); + } + + ir_rvalue *const constant = + constant_record_constructor(constructor_type, &actual_parameters, + state); + + return (constant != NULL) + ? constant + : emit_inline_record_constructor(constructor_type, instructions, + &actual_parameters, state); + } + + if (!constructor_type->is_numeric() && !constructor_type->is_boolean()) + return ir_call::get_error_instruction(ctx); + + /* Total number of components of the type being constructed. */ + const unsigned type_components = constructor_type->components(); + + /* Number of components from parameters that have actually been + * consumed. This is used to perform several kinds of error checking. + */ + unsigned components_used = 0; + + unsigned matrix_parameters = 0; + unsigned nonmatrix_parameters = 0; + exec_list actual_parameters; + + foreach_list (n, &this->expressions) { + ast_node *ast = exec_node_data(ast_node, n, link); + ir_rvalue *result = ast->hir(instructions, state)->as_rvalue(); + + /* From page 50 (page 56 of the PDF) of the GLSL 1.50 spec: + * + * "It is an error to provide extra arguments beyond this + * last used argument." + */ + if (components_used >= type_components) { + _mesa_glsl_error(& loc, state, "too many parameters to `%s' " + "constructor", + constructor_type->name); + return ir_call::get_error_instruction(ctx); + } + + if (!result->type->is_numeric() && !result->type->is_boolean()) { + _mesa_glsl_error(& loc, state, "cannot construct `%s' from a " + "non-numeric data type", + constructor_type->name); + return ir_call::get_error_instruction(ctx); + } + + /* Count the number of matrix and nonmatrix parameters. This + * is used below to enforce some of the constructor rules. + */ + if (result->type->is_matrix()) + matrix_parameters++; + else + nonmatrix_parameters++; + + actual_parameters.push_tail(result); + components_used += result->type->components(); + } + + /* From page 28 (page 34 of the PDF) of the GLSL 1.10 spec: + * + * "It is an error to construct matrices from other matrices. This + * is reserved for future use." + */ + if (state->language_version == 110 && matrix_parameters > 0 + && constructor_type->is_matrix()) { + _mesa_glsl_error(& loc, state, "cannot construct `%s' from a " + "matrix in GLSL 1.10", + constructor_type->name); + return ir_call::get_error_instruction(ctx); + } + + /* From page 50 (page 56 of the PDF) of the GLSL 1.50 spec: + * + * "If a matrix argument is given to a matrix constructor, it is + * an error to have any other arguments." + */ + if ((matrix_parameters > 0) + && ((matrix_parameters + nonmatrix_parameters) > 1) + && constructor_type->is_matrix()) { + _mesa_glsl_error(& loc, state, "for matrix `%s' constructor, " + "matrix must be only parameter", + constructor_type->name); + return ir_call::get_error_instruction(ctx); + } + + /* From page 28 (page 34 of the PDF) of the GLSL 1.10 spec: + * + * "In these cases, there must be enough components provided in the + * arguments to provide an initializer for every component in the + * constructed value." + */ + if (components_used < type_components && components_used != 1 + && matrix_parameters == 0) { + _mesa_glsl_error(& loc, state, "too few components to construct " + "`%s'", + constructor_type->name); + return ir_call::get_error_instruction(ctx); + } + + /* Later, we cast each parameter to the same base type as the + * constructor. Since there are no non-floating point matrices, we + * need to break them up into a series of column vectors. + */ + if (constructor_type->base_type != GLSL_TYPE_FLOAT) { + foreach_list_safe(n, &actual_parameters) { + ir_rvalue *matrix = (ir_rvalue *) n; + + if (!matrix->type->is_matrix()) + continue; + + /* Create a temporary containing the matrix. */ + ir_variable *var = new(ctx) ir_variable(matrix->type, "matrix_tmp", + ir_var_temporary); + instructions->push_tail(var); + instructions->push_tail(new(ctx) ir_assignment(new(ctx) + ir_dereference_variable(var), matrix, NULL)); + var->constant_value = matrix->constant_expression_value(); + + /* Replace the matrix with dereferences of its columns. */ + for (int i = 0; i < matrix->type->matrix_columns; i++) { + matrix->insert_before(new (ctx) ir_dereference_array(var, + new(ctx) ir_constant(i))); + } + matrix->remove(); + } + } + + bool all_parameters_are_constant = true; + + /* Type cast each parameter and, if possible, fold constants.*/ + foreach_list_safe(n, &actual_parameters) { + ir_rvalue *ir = (ir_rvalue *) n; + + const glsl_type *desired_type = + glsl_type::get_instance(constructor_type->base_type, + ir->type->vector_elements, + ir->type->matrix_columns); + ir_rvalue *result = convert_component(ir, desired_type); + + /* Attempt to convert the parameter to a constant valued expression. + * After doing so, track whether or not all the parameters to the + * constructor are trivially constant valued expressions. + */ + ir_rvalue *const constant = result->constant_expression_value(); + + if (constant != NULL) + result = constant; + else + all_parameters_are_constant = false; + + if (result != ir) { + ir->replace_with(result); + } + } + + /* If all of the parameters are trivially constant, create a + * constant representing the complete collection of parameters. + */ + if (all_parameters_are_constant) { + return new(ctx) ir_constant(constructor_type, &actual_parameters); + } else if (constructor_type->is_scalar()) { + return dereference_component((ir_rvalue *) actual_parameters.head, + 0); + } else if (constructor_type->is_vector()) { + return emit_inline_vector_constructor(constructor_type, + instructions, + &actual_parameters, + ctx); + } else { + assert(constructor_type->is_matrix()); + return emit_inline_matrix_constructor(constructor_type, + instructions, + &actual_parameters, + ctx); + } + } else { + const ast_expression *id = subexpressions[0]; + YYLTYPE loc = id->get_location(); + exec_list actual_parameters; + + process_parameters(instructions, &actual_parameters, &this->expressions, + state); + + return match_function_by_name(instructions, + id->primary_expression.identifier, & loc, + &actual_parameters, state); + } + + return ir_call::get_error_instruction(ctx); +} diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp new file mode 100644 index 0000000..ec25bcb --- /dev/null +++ b/src/glsl/ast_to_hir.cpp @@ -0,0 +1,3327 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ast_to_hir.c + * Convert abstract syntax to to high-level intermediate reprensentation (HIR). + * + * During the conversion to HIR, the majority of the symantic checking is + * preformed on the program. This includes: + * + * * Symbol table management + * * Type checking + * * Function binding + * + * The majority of this work could be done during parsing, and the parser could + * probably generate HIR directly. However, this results in frequent changes + * to the parser code. Since we do not assume that every system this complier + * is built on will have Flex and Bison installed, we have to store the code + * generated by these tools in our version control system. In other parts of + * the system we've seen problems where a parser was changed but the generated + * code was not committed, merge conflicts where created because two developers + * had slightly different versions of Bison installed, etc. + * + * I have also noticed that running Bison generated parsers in GDB is very + * irritating. When you get a segfault on '$$ = $1->foo', you can't very + * well 'print $1' in GDB. + * + * As a result, my preference is to put as little C code as possible in the + * parser (and lexer) sources. + */ + +#include "main/core.h" /* for struct gl_extensions */ +#include "glsl_symbol_table.h" +#include "glsl_parser_extras.h" +#include "ast.h" +#include "glsl_types.h" +#include "ir.h" + +void +_mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state) +{ + _mesa_glsl_initialize_variables(instructions, state); + _mesa_glsl_initialize_functions(instructions, state); + + state->symbols->language_version = state->language_version; + + state->current_function = NULL; + + /* Section 4.2 of the GLSL 1.20 specification states: + * "The built-in functions are scoped in a scope outside the global scope + * users declare global variables in. That is, a shader's global scope, + * available for user-defined functions and global variables, is nested + * inside the scope containing the built-in functions." + * + * Since built-in functions like ftransform() access built-in variables, + * it follows that those must be in the outer scope as well. + * + * We push scope here to create this nesting effect...but don't pop. + * This way, a shader's globals are still in the symbol table for use + * by the linker. + */ + state->symbols->push_scope(); + + foreach_list_typed (ast_node, ast, link, & state->translation_unit) + ast->hir(instructions, state); +} + + +/** + * If a conversion is available, convert one operand to a different type + * + * The \c from \c ir_rvalue is converted "in place". + * + * \param to Type that the operand it to be converted to + * \param from Operand that is being converted + * \param state GLSL compiler state + * + * \return + * If a conversion is possible (or unnecessary), \c true is returned. + * Otherwise \c false is returned. + */ +bool +apply_implicit_conversion(const glsl_type *to, ir_rvalue * &from, + struct _mesa_glsl_parse_state *state) +{ + void *ctx = state; + if (to->base_type == from->type->base_type) + return true; + + /* This conversion was added in GLSL 1.20. If the compilation mode is + * GLSL 1.10, the conversion is skipped. + */ + if (state->language_version < 120) + return false; + + /* From page 27 (page 33 of the PDF) of the GLSL 1.50 spec: + * + * "There are no implicit array or structure conversions. For + * example, an array of int cannot be implicitly converted to an + * array of float. There are no implicit conversions between + * signed and unsigned integers." + */ + /* FINISHME: The above comment is partially a lie. There is int/uint + * FINISHME: conversion for immediate constants. + */ + if (!to->is_float() || !from->type->is_numeric()) + return false; + + /* Convert to a floating point type with the same number of components + * as the original type - i.e. int to float, not int to vec4. + */ + to = glsl_type::get_instance(GLSL_TYPE_FLOAT, from->type->vector_elements, + from->type->matrix_columns); + + switch (from->type->base_type) { + case GLSL_TYPE_INT: + from = new(ctx) ir_expression(ir_unop_i2f, to, from, NULL); + break; + case GLSL_TYPE_UINT: + from = new(ctx) ir_expression(ir_unop_u2f, to, from, NULL); + break; + case GLSL_TYPE_BOOL: + from = new(ctx) ir_expression(ir_unop_b2f, to, from, NULL); + break; + default: + assert(0); + } + + return true; +} + + +static const struct glsl_type * +arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b, + bool multiply, + struct _mesa_glsl_parse_state *state, YYLTYPE *loc) +{ + const glsl_type *type_a = value_a->type; + const glsl_type *type_b = value_b->type; + + /* From GLSL 1.50 spec, page 56: + * + * "The arithmetic binary operators add (+), subtract (-), + * multiply (*), and divide (/) operate on integer and + * floating-point scalars, vectors, and matrices." + */ + if (!type_a->is_numeric() || !type_b->is_numeric()) { + _mesa_glsl_error(loc, state, + "Operands to arithmetic operators must be numeric"); + return glsl_type::error_type; + } + + + /* "If one operand is floating-point based and the other is + * not, then the conversions from Section 4.1.10 "Implicit + * Conversions" are applied to the non-floating-point-based operand." + */ + if (!apply_implicit_conversion(type_a, value_b, state) + && !apply_implicit_conversion(type_b, value_a, state)) { + _mesa_glsl_error(loc, state, + "Could not implicitly convert operands to " + "arithmetic operator"); + return glsl_type::error_type; + } + type_a = value_a->type; + type_b = value_b->type; + + /* "If the operands are integer types, they must both be signed or + * both be unsigned." + * + * From this rule and the preceeding conversion it can be inferred that + * both types must be GLSL_TYPE_FLOAT, or GLSL_TYPE_UINT, or GLSL_TYPE_INT. + * The is_numeric check above already filtered out the case where either + * type is not one of these, so now the base types need only be tested for + * equality. + */ + if (type_a->base_type != type_b->base_type) { + _mesa_glsl_error(loc, state, + "base type mismatch for arithmetic operator"); + return glsl_type::error_type; + } + + /* "All arithmetic binary operators result in the same fundamental type + * (signed integer, unsigned integer, or floating-point) as the + * operands they operate on, after operand type conversion. After + * conversion, the following cases are valid + * + * * The two operands are scalars. In this case the operation is + * applied, resulting in a scalar." + */ + if (type_a->is_scalar() && type_b->is_scalar()) + return type_a; + + /* "* One operand is a scalar, and the other is a vector or matrix. + * In this case, the scalar operation is applied independently to each + * component of the vector or matrix, resulting in the same size + * vector or matrix." + */ + if (type_a->is_scalar()) { + if (!type_b->is_scalar()) + return type_b; + } else if (type_b->is_scalar()) { + return type_a; + } + + /* All of the combinations of , , + * , , and have been + * handled. + */ + assert(!type_a->is_scalar()); + assert(!type_b->is_scalar()); + + /* "* The two operands are vectors of the same size. In this case, the + * operation is done component-wise resulting in the same size + * vector." + */ + if (type_a->is_vector() && type_b->is_vector()) { + if (type_a == type_b) { + return type_a; + } else { + _mesa_glsl_error(loc, state, + "vector size mismatch for arithmetic operator"); + return glsl_type::error_type; + } + } + + /* All of the combinations of , , + * , , , and + * have been handled. At least one of the operands must + * be matrix. Further, since there are no integer matrix types, the base + * type of both operands must be float. + */ + assert(type_a->is_matrix() || type_b->is_matrix()); + assert(type_a->base_type == GLSL_TYPE_FLOAT); + assert(type_b->base_type == GLSL_TYPE_FLOAT); + + /* "* The operator is add (+), subtract (-), or divide (/), and the + * operands are matrices with the same number of rows and the same + * number of columns. In this case, the operation is done component- + * wise resulting in the same size matrix." + * * The operator is multiply (*), where both operands are matrices or + * one operand is a vector and the other a matrix. A right vector + * operand is treated as a column vector and a left vector operand as a + * row vector. In all these cases, it is required that the number of + * columns of the left operand is equal to the number of rows of the + * right operand. Then, the multiply (*) operation does a linear + * algebraic multiply, yielding an object that has the same number of + * rows as the left operand and the same number of columns as the right + * operand. Section 5.10 "Vector and Matrix Operations" explains in + * more detail how vectors and matrices are operated on." + */ + if (! multiply) { + if (type_a == type_b) + return type_a; + } else { + if (type_a->is_matrix() && type_b->is_matrix()) { + /* Matrix multiply. The columns of A must match the rows of B. Given + * the other previously tested constraints, this means the vector type + * of a row from A must be the same as the vector type of a column from + * B. + */ + if (type_a->row_type() == type_b->column_type()) { + /* The resulting matrix has the number of columns of matrix B and + * the number of rows of matrix A. We get the row count of A by + * looking at the size of a vector that makes up a column. The + * transpose (size of a row) is done for B. + */ + const glsl_type *const type = + glsl_type::get_instance(type_a->base_type, + type_a->column_type()->vector_elements, + type_b->row_type()->vector_elements); + assert(type != glsl_type::error_type); + + return type; + } + } else if (type_a->is_matrix()) { + /* A is a matrix and B is a column vector. Columns of A must match + * rows of B. Given the other previously tested constraints, this + * means the vector type of a row from A must be the same as the + * vector the type of B. + */ + if (type_a->row_type() == type_b) { + /* The resulting vector has a number of elements equal to + * the number of rows of matrix A. */ + const glsl_type *const type = + glsl_type::get_instance(type_a->base_type, + type_a->column_type()->vector_elements, + 1); + assert(type != glsl_type::error_type); + + return type; + } + } else { + assert(type_b->is_matrix()); + + /* A is a row vector and B is a matrix. Columns of A must match rows + * of B. Given the other previously tested constraints, this means + * the type of A must be the same as the vector type of a column from + * B. + */ + if (type_a == type_b->column_type()) { + /* The resulting vector has a number of elements equal to + * the number of columns of matrix B. */ + const glsl_type *const type = + glsl_type::get_instance(type_a->base_type, + type_b->row_type()->vector_elements, + 1); + assert(type != glsl_type::error_type); + + return type; + } + } + + _mesa_glsl_error(loc, state, "size mismatch for matrix multiplication"); + return glsl_type::error_type; + } + + + /* "All other cases are illegal." + */ + _mesa_glsl_error(loc, state, "type mismatch"); + return glsl_type::error_type; +} + + +static const struct glsl_type * +unary_arithmetic_result_type(const struct glsl_type *type, + struct _mesa_glsl_parse_state *state, YYLTYPE *loc) +{ + /* From GLSL 1.50 spec, page 57: + * + * "The arithmetic unary operators negate (-), post- and pre-increment + * and decrement (-- and ++) operate on integer or floating-point + * values (including vectors and matrices). All unary operators work + * component-wise on their operands. These result with the same type + * they operated on." + */ + if (!type->is_numeric()) { + _mesa_glsl_error(loc, state, + "Operands to arithmetic operators must be numeric"); + return glsl_type::error_type; + } + + return type; +} + +/** + * \brief Return the result type of a bit-logic operation. + * + * If the given types to the bit-logic operator are invalid, return + * glsl_type::error_type. + * + * \param type_a Type of LHS of bit-logic op + * \param type_b Type of RHS of bit-logic op + */ +static const struct glsl_type * +bit_logic_result_type(const struct glsl_type *type_a, + const struct glsl_type *type_b, + ast_operators op, + struct _mesa_glsl_parse_state *state, YYLTYPE *loc) +{ + if (state->language_version < 130) { + _mesa_glsl_error(loc, state, "bit operations require GLSL 1.30"); + return glsl_type::error_type; + } + + /* From page 50 (page 56 of PDF) of GLSL 1.30 spec: + * + * "The bitwise operators and (&), exclusive-or (^), and inclusive-or + * (|). The operands must be of type signed or unsigned integers or + * integer vectors." + */ + if (!type_a->is_integer()) { + _mesa_glsl_error(loc, state, "LHS of `%s' must be an integer", + ast_expression::operator_string(op)); + return glsl_type::error_type; + } + if (!type_b->is_integer()) { + _mesa_glsl_error(loc, state, "RHS of `%s' must be an integer", + ast_expression::operator_string(op)); + return glsl_type::error_type; + } + + /* "The fundamental types of the operands (signed or unsigned) must + * match," + */ + if (type_a->base_type != type_b->base_type) { + _mesa_glsl_error(loc, state, "operands of `%s' must have the same " + "base type", ast_expression::operator_string(op)); + return glsl_type::error_type; + } + + /* "The operands cannot be vectors of differing size." */ + if (type_a->is_vector() && + type_b->is_vector() && + type_a->vector_elements != type_b->vector_elements) { + _mesa_glsl_error(loc, state, "operands of `%s' cannot be vectors of " + "different sizes", ast_expression::operator_string(op)); + return glsl_type::error_type; + } + + /* "If one operand is a scalar and the other a vector, the scalar is + * applied component-wise to the vector, resulting in the same type as + * the vector. The fundamental types of the operands [...] will be the + * resulting fundamental type." + */ + if (type_a->is_scalar()) + return type_b; + else + return type_a; +} + +static const struct glsl_type * +modulus_result_type(const struct glsl_type *type_a, + const struct glsl_type *type_b, + struct _mesa_glsl_parse_state *state, YYLTYPE *loc) +{ + if (state->language_version < 130) { + _mesa_glsl_error(loc, state, + "operator '%%' is reserved in %s", + state->version_string); + return glsl_type::error_type; + } + + /* From GLSL 1.50 spec, page 56: + * "The operator modulus (%) operates on signed or unsigned integers or + * integer vectors. The operand types must both be signed or both be + * unsigned." + */ + if (!type_a->is_integer() || !type_b->is_integer() + || (type_a->base_type != type_b->base_type)) { + _mesa_glsl_error(loc, state, "type mismatch"); + return glsl_type::error_type; + } + + /* "The operands cannot be vectors of differing size. If one operand is + * a scalar and the other vector, then the scalar is applied component- + * wise to the vector, resulting in the same type as the vector. If both + * are vectors of the same size, the result is computed component-wise." + */ + if (type_a->is_vector()) { + if (!type_b->is_vector() + || (type_a->vector_elements == type_b->vector_elements)) + return type_a; + } else + return type_b; + + /* "The operator modulus (%) is not defined for any other data types + * (non-integer types)." + */ + _mesa_glsl_error(loc, state, "type mismatch"); + return glsl_type::error_type; +} + + +static const struct glsl_type * +relational_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b, + struct _mesa_glsl_parse_state *state, YYLTYPE *loc) +{ + const glsl_type *type_a = value_a->type; + const glsl_type *type_b = value_b->type; + + /* From GLSL 1.50 spec, page 56: + * "The relational operators greater than (>), less than (<), greater + * than or equal (>=), and less than or equal (<=) operate only on + * scalar integer and scalar floating-point expressions." + */ + if (!type_a->is_numeric() + || !type_b->is_numeric() + || !type_a->is_scalar() + || !type_b->is_scalar()) { + _mesa_glsl_error(loc, state, + "Operands to relational operators must be scalar and " + "numeric"); + return glsl_type::error_type; + } + + /* "Either the operands' types must match, or the conversions from + * Section 4.1.10 "Implicit Conversions" will be applied to the integer + * operand, after which the types must match." + */ + if (!apply_implicit_conversion(type_a, value_b, state) + && !apply_implicit_conversion(type_b, value_a, state)) { + _mesa_glsl_error(loc, state, + "Could not implicitly convert operands to " + "relational operator"); + return glsl_type::error_type; + } + type_a = value_a->type; + type_b = value_b->type; + + if (type_a->base_type != type_b->base_type) { + _mesa_glsl_error(loc, state, "base type mismatch"); + return glsl_type::error_type; + } + + /* "The result is scalar Boolean." + */ + return glsl_type::bool_type; +} + +/** + * \brief Return the result type of a bit-shift operation. + * + * If the given types to the bit-shift operator are invalid, return + * glsl_type::error_type. + * + * \param type_a Type of LHS of bit-shift op + * \param type_b Type of RHS of bit-shift op + */ +static const struct glsl_type * +shift_result_type(const struct glsl_type *type_a, + const struct glsl_type *type_b, + ast_operators op, + struct _mesa_glsl_parse_state *state, YYLTYPE *loc) +{ + if (state->language_version < 130) { + _mesa_glsl_error(loc, state, "bit operations require GLSL 1.30"); + return glsl_type::error_type; + } + + /* From page 50 (page 56 of the PDF) of the GLSL 1.30 spec: + * + * "The shift operators (<<) and (>>). For both operators, the operands + * must be signed or unsigned integers or integer vectors. One operand + * can be signed while the other is unsigned." + */ + if (!type_a->is_integer()) { + _mesa_glsl_error(loc, state, "LHS of operator %s must be an integer or " + "integer vector", ast_expression::operator_string(op)); + return glsl_type::error_type; + + } + if (!type_b->is_integer()) { + _mesa_glsl_error(loc, state, "RHS of operator %s must be an integer or " + "integer vector", ast_expression::operator_string(op)); + return glsl_type::error_type; + } + + /* "If the first operand is a scalar, the second operand has to be + * a scalar as well." + */ + if (type_a->is_scalar() && !type_b->is_scalar()) { + _mesa_glsl_error(loc, state, "If the first operand of %s is scalar, the " + "second must be scalar as well", + ast_expression::operator_string(op)); + return glsl_type::error_type; + } + + /* If both operands are vectors, check that they have same number of + * elements. + */ + if (type_a->is_vector() && + type_b->is_vector() && + type_a->vector_elements != type_b->vector_elements) { + _mesa_glsl_error(loc, state, "Vector operands to operator %s must " + "have same number of elements", + ast_expression::operator_string(op)); + return glsl_type::error_type; + } + + /* "In all cases, the resulting type will be the same type as the left + * operand." + */ + return type_a; +} + +/** + * Validates that a value can be assigned to a location with a specified type + * + * Validates that \c rhs can be assigned to some location. If the types are + * not an exact match but an automatic conversion is possible, \c rhs will be + * converted. + * + * \return + * \c NULL if \c rhs cannot be assigned to a location with type \c lhs_type. + * Otherwise the actual RHS to be assigned will be returned. This may be + * \c rhs, or it may be \c rhs after some type conversion. + * + * \note + * In addition to being used for assignments, this function is used to + * type-check return values. + */ +ir_rvalue * +validate_assignment(struct _mesa_glsl_parse_state *state, + const glsl_type *lhs_type, ir_rvalue *rhs, + bool is_initializer) +{ + const glsl_type *rhs_type = rhs->type; + + /* If there is already some error in the RHS, just return it. Anything + * else will lead to an avalanche of error message back to the user. + */ + if (rhs_type->is_error()) + return rhs; + + /* If the types are identical, the assignment can trivially proceed. + */ + if (rhs_type == lhs_type) + return rhs; + + /* If the array element types are the same and the size of the LHS is zero, + * the assignment is okay for initializers embedded in variable + * declarations. + * + * Note: Whole-array assignments are not permitted in GLSL 1.10, but this + * is handled by ir_dereference::is_lvalue. + */ + if (is_initializer && lhs_type->is_array() && rhs->type->is_array() + && (lhs_type->element_type() == rhs->type->element_type()) + && (lhs_type->array_size() == 0)) { + return rhs; + } + + /* Check for implicit conversion in GLSL 1.20 */ + if (apply_implicit_conversion(lhs_type, rhs, state)) { + rhs_type = rhs->type; + if (rhs_type == lhs_type) + return rhs; + } + + return NULL; +} + +ir_rvalue * +do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state, + ir_rvalue *lhs, ir_rvalue *rhs, bool is_initializer, + YYLTYPE lhs_loc) +{ + void *ctx = state; + bool error_emitted = (lhs->type->is_error() || rhs->type->is_error()); + + if (!error_emitted) { + if (!lhs->is_lvalue()) { + _mesa_glsl_error(& lhs_loc, state, "non-lvalue in assignment"); + error_emitted = true; + } + + if (state->es_shader && lhs->type->is_array()) { + _mesa_glsl_error(&lhs_loc, state, "whole array assignment is not " + "allowed in GLSL ES 1.00."); + error_emitted = true; + } + } + + ir_rvalue *new_rhs = + validate_assignment(state, lhs->type, rhs, is_initializer); + if (new_rhs == NULL) { + _mesa_glsl_error(& lhs_loc, state, "type mismatch"); + } else { + rhs = new_rhs; + + /* If the LHS array was not declared with a size, it takes it size from + * the RHS. If the LHS is an l-value and a whole array, it must be a + * dereference of a variable. Any other case would require that the LHS + * is either not an l-value or not a whole array. + */ + if (lhs->type->array_size() == 0) { + ir_dereference *const d = lhs->as_dereference(); + + assert(d != NULL); + + ir_variable *const var = d->variable_referenced(); + + assert(var != NULL); + + if (var->max_array_access >= unsigned(rhs->type->array_size())) { + /* FINISHME: This should actually log the location of the RHS. */ + _mesa_glsl_error(& lhs_loc, state, "array size must be > %u due to " + "previous access", + var->max_array_access); + } + + var->type = glsl_type::get_array_instance(lhs->type->element_type(), + rhs->type->array_size()); + d->type = var->type; + } + } + + /* Most callers of do_assignment (assign, add_assign, pre_inc/dec, + * but not post_inc) need the converted assigned value as an rvalue + * to handle things like: + * + * i = j += 1; + * + * So we always just store the computed value being assigned to a + * temporary and return a deref of that temporary. If the rvalue + * ends up not being used, the temp will get copy-propagated out. + */ + ir_variable *var = new(ctx) ir_variable(rhs->type, "assignment_tmp", + ir_var_temporary); + ir_dereference_variable *deref_var = new(ctx) ir_dereference_variable(var); + instructions->push_tail(var); + instructions->push_tail(new(ctx) ir_assignment(deref_var, + rhs, + NULL)); + deref_var = new(ctx) ir_dereference_variable(var); + + if (!error_emitted) + instructions->push_tail(new(ctx) ir_assignment(lhs, deref_var, NULL)); + + return new(ctx) ir_dereference_variable(var); +} + +static ir_rvalue * +get_lvalue_copy(exec_list *instructions, ir_rvalue *lvalue) +{ + void *ctx = ralloc_parent(lvalue); + ir_variable *var; + + var = new(ctx) ir_variable(lvalue->type, "_post_incdec_tmp", + ir_var_temporary); + instructions->push_tail(var); + var->mode = ir_var_auto; + + instructions->push_tail(new(ctx) ir_assignment(new(ctx) ir_dereference_variable(var), + lvalue, NULL)); + + /* Once we've created this temporary, mark it read only so it's no + * longer considered an lvalue. + */ + var->read_only = true; + + return new(ctx) ir_dereference_variable(var); +} + + +ir_rvalue * +ast_node::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + (void) instructions; + (void) state; + + return NULL; +} + +static void +mark_whole_array_access(ir_rvalue *access) +{ + ir_dereference_variable *deref = access->as_dereference_variable(); + + if (deref) { + deref->var->max_array_access = deref->type->length - 1; + } +} + +static ir_rvalue * +do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1) +{ + int join_op; + ir_rvalue *cmp = NULL; + + if (operation == ir_binop_all_equal) + join_op = ir_binop_logic_and; + else + join_op = ir_binop_logic_or; + + switch (op0->type->base_type) { + case GLSL_TYPE_FLOAT: + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: + case GLSL_TYPE_BOOL: + return new(mem_ctx) ir_expression(operation, op0, op1); + + case GLSL_TYPE_ARRAY: { + for (unsigned int i = 0; i < op0->type->length; i++) { + ir_rvalue *e0, *e1, *result; + + e0 = new(mem_ctx) ir_dereference_array(op0->clone(mem_ctx, NULL), + new(mem_ctx) ir_constant(i)); + e1 = new(mem_ctx) ir_dereference_array(op1->clone(mem_ctx, NULL), + new(mem_ctx) ir_constant(i)); + result = do_comparison(mem_ctx, operation, e0, e1); + + if (cmp) { + cmp = new(mem_ctx) ir_expression(join_op, cmp, result); + } else { + cmp = result; + } + } + + mark_whole_array_access(op0); + mark_whole_array_access(op1); + break; + } + + case GLSL_TYPE_STRUCT: { + for (unsigned int i = 0; i < op0->type->length; i++) { + ir_rvalue *e0, *e1, *result; + const char *field_name = op0->type->fields.structure[i].name; + + e0 = new(mem_ctx) ir_dereference_record(op0->clone(mem_ctx, NULL), + field_name); + e1 = new(mem_ctx) ir_dereference_record(op1->clone(mem_ctx, NULL), + field_name); + result = do_comparison(mem_ctx, operation, e0, e1); + + if (cmp) { + cmp = new(mem_ctx) ir_expression(join_op, cmp, result); + } else { + cmp = result; + } + } + break; + } + + case GLSL_TYPE_ERROR: + case GLSL_TYPE_VOID: + case GLSL_TYPE_SAMPLER: + /* I assume a comparison of a struct containing a sampler just + * ignores the sampler present in the type. + */ + break; + + default: + assert(!"Should not get here."); + break; + } + + if (cmp == NULL) + cmp = new(mem_ctx) ir_constant(true); + + return cmp; +} + +ir_rvalue * +ast_expression::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + void *ctx = state; + static const int operations[AST_NUM_OPERATORS] = { + -1, /* ast_assign doesn't convert to ir_expression. */ + -1, /* ast_plus doesn't convert to ir_expression. */ + ir_unop_neg, + ir_binop_add, + ir_binop_sub, + ir_binop_mul, + ir_binop_div, + ir_binop_mod, + ir_binop_lshift, + ir_binop_rshift, + ir_binop_less, + ir_binop_greater, + ir_binop_lequal, + ir_binop_gequal, + ir_binop_all_equal, + ir_binop_any_nequal, + ir_binop_bit_and, + ir_binop_bit_xor, + ir_binop_bit_or, + ir_unop_bit_not, + ir_binop_logic_and, + ir_binop_logic_xor, + ir_binop_logic_or, + ir_unop_logic_not, + + /* Note: The following block of expression types actually convert + * to multiple IR instructions. + */ + ir_binop_mul, /* ast_mul_assign */ + ir_binop_div, /* ast_div_assign */ + ir_binop_mod, /* ast_mod_assign */ + ir_binop_add, /* ast_add_assign */ + ir_binop_sub, /* ast_sub_assign */ + ir_binop_lshift, /* ast_ls_assign */ + ir_binop_rshift, /* ast_rs_assign */ + ir_binop_bit_and, /* ast_and_assign */ + ir_binop_bit_xor, /* ast_xor_assign */ + ir_binop_bit_or, /* ast_or_assign */ + + -1, /* ast_conditional doesn't convert to ir_expression. */ + ir_binop_add, /* ast_pre_inc. */ + ir_binop_sub, /* ast_pre_dec. */ + ir_binop_add, /* ast_post_inc. */ + ir_binop_sub, /* ast_post_dec. */ + -1, /* ast_field_selection doesn't conv to ir_expression. */ + -1, /* ast_array_index doesn't convert to ir_expression. */ + -1, /* ast_function_call doesn't conv to ir_expression. */ + -1, /* ast_identifier doesn't convert to ir_expression. */ + -1, /* ast_int_constant doesn't convert to ir_expression. */ + -1, /* ast_uint_constant doesn't conv to ir_expression. */ + -1, /* ast_float_constant doesn't conv to ir_expression. */ + -1, /* ast_bool_constant doesn't conv to ir_expression. */ + -1, /* ast_sequence doesn't convert to ir_expression. */ + }; + ir_rvalue *result = NULL; + ir_rvalue *op[3]; + const struct glsl_type *type = glsl_type::error_type; + bool error_emitted = false; + YYLTYPE loc; + + loc = this->get_location(); + + switch (this->oper) { + case ast_assign: { + op[0] = this->subexpressions[0]->hir(instructions, state); + op[1] = this->subexpressions[1]->hir(instructions, state); + + result = do_assignment(instructions, state, op[0], op[1], false, + this->subexpressions[0]->get_location()); + error_emitted = result->type->is_error(); + type = result->type; + break; + } + + case ast_plus: + op[0] = this->subexpressions[0]->hir(instructions, state); + + type = unary_arithmetic_result_type(op[0]->type, state, & loc); + + error_emitted = type->is_error(); + + result = op[0]; + break; + + case ast_neg: + op[0] = this->subexpressions[0]->hir(instructions, state); + + type = unary_arithmetic_result_type(op[0]->type, state, & loc); + + error_emitted = type->is_error(); + + result = new(ctx) ir_expression(operations[this->oper], type, + op[0], NULL); + break; + + case ast_add: + case ast_sub: + case ast_mul: + case ast_div: + op[0] = this->subexpressions[0]->hir(instructions, state); + op[1] = this->subexpressions[1]->hir(instructions, state); + + type = arithmetic_result_type(op[0], op[1], + (this->oper == ast_mul), + state, & loc); + error_emitted = type->is_error(); + + result = new(ctx) ir_expression(operations[this->oper], type, + op[0], op[1]); + break; + + case ast_mod: + op[0] = this->subexpressions[0]->hir(instructions, state); + op[1] = this->subexpressions[1]->hir(instructions, state); + + type = modulus_result_type(op[0]->type, op[1]->type, state, & loc); + + assert(operations[this->oper] == ir_binop_mod); + + result = new(ctx) ir_expression(operations[this->oper], type, + op[0], op[1]); + error_emitted = type->is_error(); + break; + + case ast_lshift: + case ast_rshift: + if (state->language_version < 130) { + _mesa_glsl_error(&loc, state, "operator %s requires GLSL 1.30", + operator_string(this->oper)); + error_emitted = true; + } + + op[0] = this->subexpressions[0]->hir(instructions, state); + op[1] = this->subexpressions[1]->hir(instructions, state); + type = shift_result_type(op[0]->type, op[1]->type, this->oper, state, + &loc); + result = new(ctx) ir_expression(operations[this->oper], type, + op[0], op[1]); + error_emitted = op[0]->type->is_error() || op[1]->type->is_error(); + break; + + case ast_less: + case ast_greater: + case ast_lequal: + case ast_gequal: + op[0] = this->subexpressions[0]->hir(instructions, state); + op[1] = this->subexpressions[1]->hir(instructions, state); + + type = relational_result_type(op[0], op[1], state, & loc); + + /* The relational operators must either generate an error or result + * in a scalar boolean. See page 57 of the GLSL 1.50 spec. + */ + assert(type->is_error() + || ((type->base_type == GLSL_TYPE_BOOL) + && type->is_scalar())); + + result = new(ctx) ir_expression(operations[this->oper], type, + op[0], op[1]); + error_emitted = type->is_error(); + break; + + case ast_nequal: + case ast_equal: + op[0] = this->subexpressions[0]->hir(instructions, state); + op[1] = this->subexpressions[1]->hir(instructions, state); + + /* From page 58 (page 64 of the PDF) of the GLSL 1.50 spec: + * + * "The equality operators equal (==), and not equal (!=) + * operate on all types. They result in a scalar Boolean. If + * the operand types do not match, then there must be a + * conversion from Section 4.1.10 "Implicit Conversions" + * applied to one operand that can make them match, in which + * case this conversion is done." + */ + if ((!apply_implicit_conversion(op[0]->type, op[1], state) + && !apply_implicit_conversion(op[1]->type, op[0], state)) + || (op[0]->type != op[1]->type)) { + _mesa_glsl_error(& loc, state, "operands of `%s' must have the same " + "type", (this->oper == ast_equal) ? "==" : "!="); + error_emitted = true; + } else if ((state->language_version <= 110) + && (op[0]->type->is_array() || op[1]->type->is_array())) { + _mesa_glsl_error(& loc, state, "array comparisons forbidden in " + "GLSL 1.10"); + error_emitted = true; + } + + result = do_comparison(ctx, operations[this->oper], op[0], op[1]); + type = glsl_type::bool_type; + + assert(error_emitted || (result->type == glsl_type::bool_type)); + break; + + case ast_bit_and: + case ast_bit_xor: + case ast_bit_or: + op[0] = this->subexpressions[0]->hir(instructions, state); + op[1] = this->subexpressions[1]->hir(instructions, state); + type = bit_logic_result_type(op[0]->type, op[1]->type, this->oper, + state, &loc); + result = new(ctx) ir_expression(operations[this->oper], type, + op[0], op[1]); + error_emitted = op[0]->type->is_error() || op[1]->type->is_error(); + break; + + case ast_bit_not: + op[0] = this->subexpressions[0]->hir(instructions, state); + + if (state->language_version < 130) { + _mesa_glsl_error(&loc, state, "bit-wise operations require GLSL 1.30"); + error_emitted = true; + } + + if (!op[0]->type->is_integer()) { + _mesa_glsl_error(&loc, state, "operand of `~' must be an integer"); + error_emitted = true; + } + + type = op[0]->type; + result = new(ctx) ir_expression(ir_unop_bit_not, type, op[0], NULL); + break; + + case ast_logic_and: { + op[0] = this->subexpressions[0]->hir(instructions, state); + + if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) { + YYLTYPE loc = this->subexpressions[0]->get_location(); + + _mesa_glsl_error(& loc, state, "LHS of `%s' must be scalar boolean", + operator_string(this->oper)); + error_emitted = true; + } + + ir_constant *op0_const = op[0]->constant_expression_value(); + if (op0_const) { + if (op0_const->value.b[0]) { + op[1] = this->subexpressions[1]->hir(instructions, state); + + if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) { + YYLTYPE loc = this->subexpressions[1]->get_location(); + + _mesa_glsl_error(& loc, state, + "RHS of `%s' must be scalar boolean", + operator_string(this->oper)); + error_emitted = true; + } + result = op[1]; + } else { + result = op0_const; + } + type = glsl_type::bool_type; + } else { + ir_variable *const tmp = new(ctx) ir_variable(glsl_type::bool_type, + "and_tmp", + ir_var_temporary); + instructions->push_tail(tmp); + + ir_if *const stmt = new(ctx) ir_if(op[0]); + instructions->push_tail(stmt); + + op[1] = this->subexpressions[1]->hir(&stmt->then_instructions, state); + + if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) { + YYLTYPE loc = this->subexpressions[1]->get_location(); + + _mesa_glsl_error(& loc, state, + "RHS of `%s' must be scalar boolean", + operator_string(this->oper)); + error_emitted = true; + } + + ir_dereference *const then_deref = new(ctx) ir_dereference_variable(tmp); + ir_assignment *const then_assign = + new(ctx) ir_assignment(then_deref, op[1], NULL); + stmt->then_instructions.push_tail(then_assign); + + ir_dereference *const else_deref = new(ctx) ir_dereference_variable(tmp); + ir_assignment *const else_assign = + new(ctx) ir_assignment(else_deref, new(ctx) ir_constant(false), NULL); + stmt->else_instructions.push_tail(else_assign); + + result = new(ctx) ir_dereference_variable(tmp); + type = tmp->type; + } + break; + } + + case ast_logic_or: { + op[0] = this->subexpressions[0]->hir(instructions, state); + + if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) { + YYLTYPE loc = this->subexpressions[0]->get_location(); + + _mesa_glsl_error(& loc, state, "LHS of `%s' must be scalar boolean", + operator_string(this->oper)); + error_emitted = true; + } + + ir_constant *op0_const = op[0]->constant_expression_value(); + if (op0_const) { + if (op0_const->value.b[0]) { + result = op0_const; + } else { + op[1] = this->subexpressions[1]->hir(instructions, state); + + if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) { + YYLTYPE loc = this->subexpressions[1]->get_location(); + + _mesa_glsl_error(& loc, state, + "RHS of `%s' must be scalar boolean", + operator_string(this->oper)); + error_emitted = true; + } + result = op[1]; + } + type = glsl_type::bool_type; + } else { + ir_variable *const tmp = new(ctx) ir_variable(glsl_type::bool_type, + "or_tmp", + ir_var_temporary); + instructions->push_tail(tmp); + + ir_if *const stmt = new(ctx) ir_if(op[0]); + instructions->push_tail(stmt); + + op[1] = this->subexpressions[1]->hir(&stmt->else_instructions, state); + + if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) { + YYLTYPE loc = this->subexpressions[1]->get_location(); + + _mesa_glsl_error(& loc, state, "RHS of `%s' must be scalar boolean", + operator_string(this->oper)); + error_emitted = true; + } + + ir_dereference *const then_deref = new(ctx) ir_dereference_variable(tmp); + ir_assignment *const then_assign = + new(ctx) ir_assignment(then_deref, new(ctx) ir_constant(true), NULL); + stmt->then_instructions.push_tail(then_assign); + + ir_dereference *const else_deref = new(ctx) ir_dereference_variable(tmp); + ir_assignment *const else_assign = + new(ctx) ir_assignment(else_deref, op[1], NULL); + stmt->else_instructions.push_tail(else_assign); + + result = new(ctx) ir_dereference_variable(tmp); + type = tmp->type; + } + break; + } + + case ast_logic_xor: + op[0] = this->subexpressions[0]->hir(instructions, state); + op[1] = this->subexpressions[1]->hir(instructions, state); + + + result = new(ctx) ir_expression(operations[this->oper], glsl_type::bool_type, + op[0], op[1]); + type = glsl_type::bool_type; + break; + + case ast_logic_not: + op[0] = this->subexpressions[0]->hir(instructions, state); + + if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) { + YYLTYPE loc = this->subexpressions[0]->get_location(); + + _mesa_glsl_error(& loc, state, + "operand of `!' must be scalar boolean"); + error_emitted = true; + } + + result = new(ctx) ir_expression(operations[this->oper], glsl_type::bool_type, + op[0], NULL); + type = glsl_type::bool_type; + break; + + case ast_mul_assign: + case ast_div_assign: + case ast_add_assign: + case ast_sub_assign: { + op[0] = this->subexpressions[0]->hir(instructions, state); + op[1] = this->subexpressions[1]->hir(instructions, state); + + type = arithmetic_result_type(op[0], op[1], + (this->oper == ast_mul_assign), + state, & loc); + + ir_rvalue *temp_rhs = new(ctx) ir_expression(operations[this->oper], type, + op[0], op[1]); + + result = do_assignment(instructions, state, + op[0]->clone(ctx, NULL), temp_rhs, false, + this->subexpressions[0]->get_location()); + type = result->type; + error_emitted = (op[0]->type->is_error()); + + /* GLSL 1.10 does not allow array assignment. However, we don't have to + * explicitly test for this because none of the binary expression + * operators allow array operands either. + */ + + break; + } + + case ast_mod_assign: { + op[0] = this->subexpressions[0]->hir(instructions, state); + op[1] = this->subexpressions[1]->hir(instructions, state); + + type = modulus_result_type(op[0]->type, op[1]->type, state, & loc); + + assert(operations[this->oper] == ir_binop_mod); + + ir_rvalue *temp_rhs; + temp_rhs = new(ctx) ir_expression(operations[this->oper], type, + op[0], op[1]); + + result = do_assignment(instructions, state, + op[0]->clone(ctx, NULL), temp_rhs, false, + this->subexpressions[0]->get_location()); + type = result->type; + error_emitted = type->is_error(); + break; + } + + case ast_ls_assign: + case ast_rs_assign: { + op[0] = this->subexpressions[0]->hir(instructions, state); + op[1] = this->subexpressions[1]->hir(instructions, state); + type = shift_result_type(op[0]->type, op[1]->type, this->oper, state, + &loc); + ir_rvalue *temp_rhs = new(ctx) ir_expression(operations[this->oper], + type, op[0], op[1]); + result = do_assignment(instructions, state, op[0]->clone(ctx, NULL), + temp_rhs, false, + this->subexpressions[0]->get_location()); + error_emitted = op[0]->type->is_error() || op[1]->type->is_error(); + break; + } + + case ast_and_assign: + case ast_xor_assign: + case ast_or_assign: { + op[0] = this->subexpressions[0]->hir(instructions, state); + op[1] = this->subexpressions[1]->hir(instructions, state); + type = bit_logic_result_type(op[0]->type, op[1]->type, this->oper, + state, &loc); + ir_rvalue *temp_rhs = new(ctx) ir_expression(operations[this->oper], + type, op[0], op[1]); + result = do_assignment(instructions, state, op[0]->clone(ctx, NULL), + temp_rhs, false, + this->subexpressions[0]->get_location()); + error_emitted = op[0]->type->is_error() || op[1]->type->is_error(); + break; + } + + case ast_conditional: { + op[0] = this->subexpressions[0]->hir(instructions, state); + + /* From page 59 (page 65 of the PDF) of the GLSL 1.50 spec: + * + * "The ternary selection operator (?:). It operates on three + * expressions (exp1 ? exp2 : exp3). This operator evaluates the + * first expression, which must result in a scalar Boolean." + */ + if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) { + YYLTYPE loc = this->subexpressions[0]->get_location(); + + _mesa_glsl_error(& loc, state, "?: condition must be scalar boolean"); + error_emitted = true; + } + + /* The :? operator is implemented by generating an anonymous temporary + * followed by an if-statement. The last instruction in each branch of + * the if-statement assigns a value to the anonymous temporary. This + * temporary is the r-value of the expression. + */ + exec_list then_instructions; + exec_list else_instructions; + + op[1] = this->subexpressions[1]->hir(&then_instructions, state); + op[2] = this->subexpressions[2]->hir(&else_instructions, state); + + /* From page 59 (page 65 of the PDF) of the GLSL 1.50 spec: + * + * "The second and third expressions can be any type, as + * long their types match, or there is a conversion in + * Section 4.1.10 "Implicit Conversions" that can be applied + * to one of the expressions to make their types match. This + * resulting matching type is the type of the entire + * expression." + */ + if ((!apply_implicit_conversion(op[1]->type, op[2], state) + && !apply_implicit_conversion(op[2]->type, op[1], state)) + || (op[1]->type != op[2]->type)) { + YYLTYPE loc = this->subexpressions[1]->get_location(); + + _mesa_glsl_error(& loc, state, "Second and third operands of ?: " + "operator must have matching types."); + error_emitted = true; + type = glsl_type::error_type; + } else { + type = op[1]->type; + } + + /* From page 33 (page 39 of the PDF) of the GLSL 1.10 spec: + * + * "The second and third expressions must be the same type, but can + * be of any type other than an array." + */ + if ((state->language_version <= 110) && type->is_array()) { + _mesa_glsl_error(& loc, state, "Second and third operands of ?: " + "operator must not be arrays."); + error_emitted = true; + } + + ir_constant *cond_val = op[0]->constant_expression_value(); + ir_constant *then_val = op[1]->constant_expression_value(); + ir_constant *else_val = op[2]->constant_expression_value(); + + if (then_instructions.is_empty() + && else_instructions.is_empty() + && (cond_val != NULL) && (then_val != NULL) && (else_val != NULL)) { + result = (cond_val->value.b[0]) ? then_val : else_val; + } else { + ir_variable *const tmp = + new(ctx) ir_variable(type, "conditional_tmp", ir_var_temporary); + instructions->push_tail(tmp); + + ir_if *const stmt = new(ctx) ir_if(op[0]); + instructions->push_tail(stmt); + + then_instructions.move_nodes_to(& stmt->then_instructions); + ir_dereference *const then_deref = + new(ctx) ir_dereference_variable(tmp); + ir_assignment *const then_assign = + new(ctx) ir_assignment(then_deref, op[1], NULL); + stmt->then_instructions.push_tail(then_assign); + + else_instructions.move_nodes_to(& stmt->else_instructions); + ir_dereference *const else_deref = + new(ctx) ir_dereference_variable(tmp); + ir_assignment *const else_assign = + new(ctx) ir_assignment(else_deref, op[2], NULL); + stmt->else_instructions.push_tail(else_assign); + + result = new(ctx) ir_dereference_variable(tmp); + } + break; + } + + case ast_pre_inc: + case ast_pre_dec: { + op[0] = this->subexpressions[0]->hir(instructions, state); + if (op[0]->type->base_type == GLSL_TYPE_FLOAT) + op[1] = new(ctx) ir_constant(1.0f); + else + op[1] = new(ctx) ir_constant(1); + + type = arithmetic_result_type(op[0], op[1], false, state, & loc); + + ir_rvalue *temp_rhs; + temp_rhs = new(ctx) ir_expression(operations[this->oper], type, + op[0], op[1]); + + result = do_assignment(instructions, state, + op[0]->clone(ctx, NULL), temp_rhs, false, + this->subexpressions[0]->get_location()); + type = result->type; + error_emitted = op[0]->type->is_error(); + break; + } + + case ast_post_inc: + case ast_post_dec: { + op[0] = this->subexpressions[0]->hir(instructions, state); + if (op[0]->type->base_type == GLSL_TYPE_FLOAT) + op[1] = new(ctx) ir_constant(1.0f); + else + op[1] = new(ctx) ir_constant(1); + + error_emitted = op[0]->type->is_error() || op[1]->type->is_error(); + + type = arithmetic_result_type(op[0], op[1], false, state, & loc); + + ir_rvalue *temp_rhs; + temp_rhs = new(ctx) ir_expression(operations[this->oper], type, + op[0], op[1]); + + /* Get a temporary of a copy of the lvalue before it's modified. + * This may get thrown away later. + */ + result = get_lvalue_copy(instructions, op[0]->clone(ctx, NULL)); + + (void)do_assignment(instructions, state, + op[0]->clone(ctx, NULL), temp_rhs, false, + this->subexpressions[0]->get_location()); + + type = result->type; + error_emitted = op[0]->type->is_error(); + break; + } + + case ast_field_selection: + result = _mesa_ast_field_selection_to_hir(this, instructions, state); + type = result->type; + break; + + case ast_array_index: { + YYLTYPE index_loc = subexpressions[1]->get_location(); + + op[0] = subexpressions[0]->hir(instructions, state); + op[1] = subexpressions[1]->hir(instructions, state); + + error_emitted = op[0]->type->is_error() || op[1]->type->is_error(); + + ir_rvalue *const array = op[0]; + + result = new(ctx) ir_dereference_array(op[0], op[1]); + + /* Do not use op[0] after this point. Use array. + */ + op[0] = NULL; + + + if (error_emitted) + break; + + if (!array->type->is_array() + && !array->type->is_matrix() + && !array->type->is_vector()) { + _mesa_glsl_error(& index_loc, state, + "cannot dereference non-array / non-matrix / " + "non-vector"); + error_emitted = true; + } + + if (!op[1]->type->is_integer()) { + _mesa_glsl_error(& index_loc, state, + "array index must be integer type"); + error_emitted = true; + } else if (!op[1]->type->is_scalar()) { + _mesa_glsl_error(& index_loc, state, + "array index must be scalar"); + error_emitted = true; + } + + /* If the array index is a constant expression and the array has a + * declared size, ensure that the access is in-bounds. If the array + * index is not a constant expression, ensure that the array has a + * declared size. + */ + ir_constant *const const_index = op[1]->constant_expression_value(); + if (const_index != NULL) { + const int idx = const_index->value.i[0]; + const char *type_name; + unsigned bound = 0; + + if (array->type->is_matrix()) { + type_name = "matrix"; + } else if (array->type->is_vector()) { + type_name = "vector"; + } else { + type_name = "array"; + } + + /* From page 24 (page 30 of the PDF) of the GLSL 1.50 spec: + * + * "It is illegal to declare an array with a size, and then + * later (in the same shader) index the same array with an + * integral constant expression greater than or equal to the + * declared size. It is also illegal to index an array with a + * negative constant expression." + */ + if (array->type->is_matrix()) { + if (array->type->row_type()->vector_elements <= idx) { + bound = array->type->row_type()->vector_elements; + } + } else if (array->type->is_vector()) { + if (array->type->vector_elements <= idx) { + bound = array->type->vector_elements; + } + } else { + if ((array->type->array_size() > 0) + && (array->type->array_size() <= idx)) { + bound = array->type->array_size(); + } + } + + if (bound > 0) { + _mesa_glsl_error(& loc, state, "%s index must be < %u", + type_name, bound); + error_emitted = true; + } else if (idx < 0) { + _mesa_glsl_error(& loc, state, "%s index must be >= 0", + type_name); + error_emitted = true; + } + + if (array->type->is_array()) { + /* If the array is a variable dereference, it dereferences the + * whole array, by definition. Use this to get the variable. + * + * FINISHME: Should some methods for getting / setting / testing + * FINISHME: array access limits be added to ir_dereference? + */ + ir_variable *const v = array->whole_variable_referenced(); + if ((v != NULL) && (unsigned(idx) > v->max_array_access)) + v->max_array_access = idx; + } + } else if (array->type->array_size() == 0) { + _mesa_glsl_error(&loc, state, "unsized array index must be constant"); + } else { + if (array->type->is_array()) { + /* whole_variable_referenced can return NULL if the array is a + * member of a structure. In this case it is safe to not update + * the max_array_access field because it is never used for fields + * of structures. + */ + ir_variable *v = array->whole_variable_referenced(); + if (v != NULL) + v->max_array_access = array->type->array_size(); + } + } + + /* From page 23 (29 of the PDF) of the GLSL 1.30 spec: + * + * "Samplers aggregated into arrays within a shader (using square + * brackets [ ]) can only be indexed with integral constant + * expressions [...]." + * + * This restriction was added in GLSL 1.30. Shaders using earlier version + * of the language should not be rejected by the compiler front-end for + * using this construct. This allows useful things such as using a loop + * counter as the index to an array of samplers. If the loop in unrolled, + * the code should compile correctly. Instead, emit a warning. + */ + if (array->type->is_array() && + array->type->element_type()->is_sampler() && + const_index == NULL) { + + if (state->language_version == 100) { + _mesa_glsl_warning(&loc, state, + "sampler arrays indexed with non-constant " + "expressions is optional in GLSL ES 1.00"); + } else if (state->language_version < 130) { + _mesa_glsl_warning(&loc, state, + "sampler arrays indexed with non-constant " + "expressions is forbidden in GLSL 1.30 and " + "later"); + } else { + _mesa_glsl_error(&loc, state, + "sampler arrays indexed with non-constant " + "expressions is forbidden in GLSL 1.30 and " + "later"); + error_emitted = true; + } + } + + if (error_emitted) + result->type = glsl_type::error_type; + + type = result->type; + break; + } + + case ast_function_call: + /* Should *NEVER* get here. ast_function_call should always be handled + * by ast_function_expression::hir. + */ + assert(0); + break; + + case ast_identifier: { + /* ast_identifier can appear several places in a full abstract syntax + * tree. This particular use must be at location specified in the grammar + * as 'variable_identifier'. + */ + ir_variable *var = + state->symbols->get_variable(this->primary_expression.identifier); + + result = new(ctx) ir_dereference_variable(var); + + if (var != NULL) { + var->used = true; + type = result->type; + } else { + _mesa_glsl_error(& loc, state, "`%s' undeclared", + this->primary_expression.identifier); + + error_emitted = true; + } + break; + } + + case ast_int_constant: + type = glsl_type::int_type; + result = new(ctx) ir_constant(this->primary_expression.int_constant); + break; + + case ast_uint_constant: + type = glsl_type::uint_type; + result = new(ctx) ir_constant(this->primary_expression.uint_constant); + break; + + case ast_float_constant: + type = glsl_type::float_type; + result = new(ctx) ir_constant(this->primary_expression.float_constant); + break; + + case ast_bool_constant: + type = glsl_type::bool_type; + result = new(ctx) ir_constant(bool(this->primary_expression.bool_constant)); + break; + + case ast_sequence: { + /* It should not be possible to generate a sequence in the AST without + * any expressions in it. + */ + assert(!this->expressions.is_empty()); + + /* The r-value of a sequence is the last expression in the sequence. If + * the other expressions in the sequence do not have side-effects (and + * therefore add instructions to the instruction list), they get dropped + * on the floor. + */ + foreach_list_typed (ast_node, ast, link, &this->expressions) + result = ast->hir(instructions, state); + + type = result->type; + + /* Any errors should have already been emitted in the loop above. + */ + error_emitted = true; + break; + } + } + + if (type->is_error() && !error_emitted) + _mesa_glsl_error(& loc, state, "type mismatch"); + + return result; +} + + +ir_rvalue * +ast_expression_statement::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + /* It is possible to have expression statements that don't have an + * expression. This is the solitary semicolon: + * + * for (i = 0; i < 5; i++) + * ; + * + * In this case the expression will be NULL. Test for NULL and don't do + * anything in that case. + */ + if (expression != NULL) + expression->hir(instructions, state); + + /* Statements do not have r-values. + */ + return NULL; +} + + +ir_rvalue * +ast_compound_statement::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + if (new_scope) + state->symbols->push_scope(); + + foreach_list_typed (ast_node, ast, link, &this->statements) + ast->hir(instructions, state); + + if (new_scope) + state->symbols->pop_scope(); + + /* Compound statements do not have r-values. + */ + return NULL; +} + + +static const glsl_type * +process_array_type(YYLTYPE *loc, const glsl_type *base, ast_node *array_size, + struct _mesa_glsl_parse_state *state) +{ + unsigned length = 0; + + /* FINISHME: Reject delcarations of multidimensional arrays. */ + + if (array_size != NULL) { + exec_list dummy_instructions; + ir_rvalue *const ir = array_size->hir(& dummy_instructions, state); + YYLTYPE loc = array_size->get_location(); + + /* FINISHME: Verify that the grammar forbids side-effects in array + * FINISHME: sizes. i.e., 'vec4 [x = 12] data' + */ + assert(dummy_instructions.is_empty()); + + if (ir != NULL) { + if (!ir->type->is_integer()) { + _mesa_glsl_error(& loc, state, "array size must be integer type"); + } else if (!ir->type->is_scalar()) { + _mesa_glsl_error(& loc, state, "array size must be scalar type"); + } else { + ir_constant *const size = ir->constant_expression_value(); + + if (size == NULL) { + _mesa_glsl_error(& loc, state, "array size must be a " + "constant valued expression"); + } else if (size->value.i[0] <= 0) { + _mesa_glsl_error(& loc, state, "array size must be > 0"); + } else { + assert(size->type == ir->type); + length = size->value.u[0]; + } + } + } + } else if (state->es_shader) { + /* Section 10.17 of the GLSL ES 1.00 specification states that unsized + * array declarations have been removed from the language. + */ + _mesa_glsl_error(loc, state, "unsized array declarations are not " + "allowed in GLSL ES 1.00."); + } + + return glsl_type::get_array_instance(base, length); +} + + +const glsl_type * +ast_type_specifier::glsl_type(const char **name, + struct _mesa_glsl_parse_state *state) const +{ + const struct glsl_type *type; + + type = state->symbols->get_type(this->type_name); + *name = this->type_name; + + if (this->is_array) { + YYLTYPE loc = this->get_location(); + type = process_array_type(&loc, type, this->array_size, state); + } + + return type; +} + + +static void +apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual, + ir_variable *var, + struct _mesa_glsl_parse_state *state, + YYLTYPE *loc) +{ + if (qual->flags.q.invariant) { + if (var->used) { + _mesa_glsl_error(loc, state, + "variable `%s' may not be redeclared " + "`invariant' after being used", + var->name); + } else { + var->invariant = 1; + } + } + + if (qual->flags.q.constant || qual->flags.q.attribute + || qual->flags.q.uniform + || (qual->flags.q.varying && (state->target == fragment_shader))) + var->read_only = 1; + + if (qual->flags.q.centroid) + var->centroid = 1; + + if (qual->flags.q.attribute && state->target != vertex_shader) { + var->type = glsl_type::error_type; + _mesa_glsl_error(loc, state, + "`attribute' variables may not be declared in the " + "%s shader", + _mesa_glsl_shader_target_name(state->target)); + } + + /* From page 25 (page 31 of the PDF) of the GLSL 1.10 spec: + * + * "The varying qualifier can be used only with the data types + * float, vec2, vec3, vec4, mat2, mat3, and mat4, or arrays of + * these." + */ + if (qual->flags.q.varying) { + const glsl_type *non_array_type; + + if (var->type && var->type->is_array()) + non_array_type = var->type->fields.array; + else + non_array_type = var->type; + + if (non_array_type && non_array_type->base_type != GLSL_TYPE_FLOAT) { + var->type = glsl_type::error_type; + _mesa_glsl_error(loc, state, + "varying variables must be of base type float"); + } + } + + /* If there is no qualifier that changes the mode of the variable, leave + * the setting alone. + */ + if (qual->flags.q.in && qual->flags.q.out) + var->mode = ir_var_inout; + else if (qual->flags.q.attribute || qual->flags.q.in + || (qual->flags.q.varying && (state->target == fragment_shader))) + var->mode = ir_var_in; + else if (qual->flags.q.out + || (qual->flags.q.varying && (state->target == vertex_shader))) + var->mode = ir_var_out; + else if (qual->flags.q.uniform) + var->mode = ir_var_uniform; + + if (state->all_invariant && (state->current_function == NULL)) { + switch (state->target) { + case vertex_shader: + if (var->mode == ir_var_out) + var->invariant = true; + break; + case geometry_shader: + if ((var->mode == ir_var_in) || (var->mode == ir_var_out)) + var->invariant = true; + break; + case fragment_shader: + if (var->mode == ir_var_in) + var->invariant = true; + break; + } + } + + if (qual->flags.q.flat) + var->interpolation = ir_var_flat; + else if (qual->flags.q.noperspective) + var->interpolation = ir_var_noperspective; + else + var->interpolation = ir_var_smooth; + + var->pixel_center_integer = qual->flags.q.pixel_center_integer; + var->origin_upper_left = qual->flags.q.origin_upper_left; + if ((qual->flags.q.origin_upper_left || qual->flags.q.pixel_center_integer) + && (strcmp(var->name, "gl_FragCoord") != 0)) { + const char *const qual_string = (qual->flags.q.origin_upper_left) + ? "origin_upper_left" : "pixel_center_integer"; + + _mesa_glsl_error(loc, state, + "layout qualifier `%s' can only be applied to " + "fragment shader input `gl_FragCoord'", + qual_string); + } + + if (qual->flags.q.explicit_location) { + const bool global_scope = (state->current_function == NULL); + bool fail = false; + const char *string = ""; + + /* In the vertex shader only shader inputs can be given explicit + * locations. + * + * In the fragment shader only shader outputs can be given explicit + * locations. + */ + switch (state->target) { + case vertex_shader: + if (!global_scope || (var->mode != ir_var_in)) { + fail = true; + string = "input"; + } + break; + + case geometry_shader: + _mesa_glsl_error(loc, state, + "geometry shader variables cannot be given " + "explicit locations\n"); + break; + + case fragment_shader: + if (!global_scope || (var->mode != ir_var_in)) { + fail = true; + string = "output"; + } + break; + }; + + if (fail) { + _mesa_glsl_error(loc, state, + "only %s shader %s variables can be given an " + "explicit location\n", + _mesa_glsl_shader_target_name(state->target), + string); + } else { + var->explicit_location = true; + + /* This bit of silliness is needed because invalid explicit locations + * are supposed to be flagged during linking. Small negative values + * biased by VERT_ATTRIB_GENERIC0 or FRAG_RESULT_DATA0 could alias + * built-in values (e.g., -16+VERT_ATTRIB_GENERIC0 = VERT_ATTRIB_POS). + * The linker needs to be able to differentiate these cases. This + * ensures that negative values stay negative. + */ + if (qual->location >= 0) { + var->location = (state->target == vertex_shader) + ? (qual->location + VERT_ATTRIB_GENERIC0) + : (qual->location + FRAG_RESULT_DATA0); + } else { + var->location = qual->location; + } + } + } + + /* Does the declaration use the 'layout' keyword? + */ + const bool uses_layout = qual->flags.q.pixel_center_integer + || qual->flags.q.origin_upper_left + || qual->flags.q.explicit_location; + + /* Does the declaration use the deprecated 'attribute' or 'varying' + * keywords? + */ + const bool uses_deprecated_qualifier = qual->flags.q.attribute + || qual->flags.q.varying; + + /* Is the 'layout' keyword used with parameters that allow relaxed checking. + * Many implementations of GL_ARB_fragment_coord_conventions_enable and some + * implementations (only Mesa?) GL_ARB_explicit_attrib_location_enable + * allowed the layout qualifier to be used with 'varying' and 'attribute'. + * These extensions and all following extensions that add the 'layout' + * keyword have been modified to require the use of 'in' or 'out'. + * + * The following extension do not allow the deprecated keywords: + * + * GL_AMD_conservative_depth + * GL_ARB_gpu_shader5 + * GL_ARB_separate_shader_objects + * GL_ARB_tesselation_shader + * GL_ARB_transform_feedback3 + * GL_ARB_uniform_buffer_object + * + * It is unknown whether GL_EXT_shader_image_load_store or GL_NV_gpu_shader5 + * allow layout with the deprecated keywords. + */ + const bool relaxed_layout_qualifier_checking = + state->ARB_fragment_coord_conventions_enable; + + if (uses_layout && uses_deprecated_qualifier) { + if (relaxed_layout_qualifier_checking) { + _mesa_glsl_warning(loc, state, + "`layout' qualifier may not be used with " + "`attribute' or `varying'"); + } else { + _mesa_glsl_error(loc, state, + "`layout' qualifier may not be used with " + "`attribute' or `varying'"); + } + } + + if (var->type->is_array() && state->language_version != 110) { + var->array_lvalue = true; + } +} + +/** + * Get the variable that is being redeclared by this declaration + * + * Semantic checks to verify the validity of the redeclaration are also + * performed. If semantic checks fail, compilation error will be emitted via + * \c _mesa_glsl_error, but a non-\c NULL pointer will still be returned. + * + * \returns + * A pointer to an existing variable in the current scope if the declaration + * is a redeclaration, \c NULL otherwise. + */ +ir_variable * +get_variable_being_redeclared(ir_variable *var, ast_declaration *decl, + struct _mesa_glsl_parse_state *state) +{ + /* Check if this declaration is actually a re-declaration, either to + * resize an array or add qualifiers to an existing variable. + * + * This is allowed for variables in the current scope, or when at + * global scope (for built-ins in the implicit outer scope). + */ + ir_variable *earlier = state->symbols->get_variable(decl->identifier); + if (earlier == NULL || + (state->current_function != NULL && + !state->symbols->name_declared_this_scope(decl->identifier))) { + return NULL; + } + + + YYLTYPE loc = decl->get_location(); + + /* From page 24 (page 30 of the PDF) of the GLSL 1.50 spec, + * + * "It is legal to declare an array without a size and then + * later re-declare the same name as an array of the same + * type and specify a size." + */ + if ((earlier->type->array_size() == 0) + && var->type->is_array() + && (var->type->element_type() == earlier->type->element_type())) { + /* FINISHME: This doesn't match the qualifiers on the two + * FINISHME: declarations. It's not 100% clear whether this is + * FINISHME: required or not. + */ + + /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec: + * + * "The size [of gl_TexCoord] can be at most + * gl_MaxTextureCoords." + */ + const unsigned size = unsigned(var->type->array_size()); + if ((strcmp("gl_TexCoord", var->name) == 0) + && (size > state->Const.MaxTextureCoords)) { + _mesa_glsl_error(& loc, state, "`gl_TexCoord' array size cannot " + "be larger than gl_MaxTextureCoords (%u)\n", + state->Const.MaxTextureCoords); + } else if ((size > 0) && (size <= earlier->max_array_access)) { + _mesa_glsl_error(& loc, state, "array size must be > %u due to " + "previous access", + earlier->max_array_access); + } + + earlier->type = var->type; + delete var; + var = NULL; + } else if (state->ARB_fragment_coord_conventions_enable + && strcmp(var->name, "gl_FragCoord") == 0 + && earlier->type == var->type + && earlier->mode == var->mode) { + /* Allow redeclaration of gl_FragCoord for ARB_fcc layout + * qualifiers. + */ + earlier->origin_upper_left = var->origin_upper_left; + earlier->pixel_center_integer = var->pixel_center_integer; + } else { + _mesa_glsl_error(&loc, state, "`%s' redeclared", decl->identifier); + } + + return earlier; +} + +/** + * Generate the IR for an initializer in a variable declaration + */ +ir_rvalue * +process_initializer(ir_variable *var, ast_declaration *decl, + ast_fully_specified_type *type, + exec_list *initializer_instructions, + struct _mesa_glsl_parse_state *state) +{ + ir_rvalue *result = NULL; + + YYLTYPE initializer_loc = decl->initializer->get_location(); + + /* From page 24 (page 30 of the PDF) of the GLSL 1.10 spec: + * + * "All uniform variables are read-only and are initialized either + * directly by an application via API commands, or indirectly by + * OpenGL." + */ + if ((state->language_version <= 110) + && (var->mode == ir_var_uniform)) { + _mesa_glsl_error(& initializer_loc, state, + "cannot initialize uniforms in GLSL 1.10"); + } + + if (var->type->is_sampler()) { + _mesa_glsl_error(& initializer_loc, state, + "cannot initialize samplers"); + } + + if ((var->mode == ir_var_in) && (state->current_function == NULL)) { + _mesa_glsl_error(& initializer_loc, state, + "cannot initialize %s shader input / %s", + _mesa_glsl_shader_target_name(state->target), + (state->target == vertex_shader) + ? "attribute" : "varying"); + } + + ir_dereference *const lhs = new(state) ir_dereference_variable(var); + ir_rvalue *rhs = decl->initializer->hir(initializer_instructions, + state); + + /* Calculate the constant value if this is a const or uniform + * declaration. + */ + if (type->qualifier.flags.q.constant + || type->qualifier.flags.q.uniform) { + ir_rvalue *new_rhs = validate_assignment(state, var->type, rhs, true); + if (new_rhs != NULL) { + rhs = new_rhs; + + ir_constant *constant_value = rhs->constant_expression_value(); + if (!constant_value) { + _mesa_glsl_error(& initializer_loc, state, + "initializer of %s variable `%s' must be a " + "constant expression", + (type->qualifier.flags.q.constant) + ? "const" : "uniform", + decl->identifier); + if (var->type->is_numeric()) { + /* Reduce cascading errors. */ + var->constant_value = ir_constant::zero(state, var->type); + } + } else { + rhs = constant_value; + var->constant_value = constant_value; + } + } else { + _mesa_glsl_error(&initializer_loc, state, + "initializer of type %s cannot be assigned to " + "variable of type %s", + rhs->type->name, var->type->name); + if (var->type->is_numeric()) { + /* Reduce cascading errors. */ + var->constant_value = ir_constant::zero(state, var->type); + } + } + } + + if (rhs && !rhs->type->is_error()) { + bool temp = var->read_only; + if (type->qualifier.flags.q.constant) + var->read_only = false; + + /* Never emit code to initialize a uniform. + */ + const glsl_type *initializer_type; + if (!type->qualifier.flags.q.uniform) { + result = do_assignment(initializer_instructions, state, + lhs, rhs, true, + type->get_location()); + initializer_type = result->type; + } else + initializer_type = rhs->type; + + /* If the declared variable is an unsized array, it must inherrit + * its full type from the initializer. A declaration such as + * + * uniform float a[] = float[](1.0, 2.0, 3.0, 3.0); + * + * becomes + * + * uniform float a[4] = float[](1.0, 2.0, 3.0, 3.0); + * + * The assignment generated in the if-statement (below) will also + * automatically handle this case for non-uniforms. + * + * If the declared variable is not an array, the types must + * already match exactly. As a result, the type assignment + * here can be done unconditionally. For non-uniforms the call + * to do_assignment can change the type of the initializer (via + * the implicit conversion rules). For uniforms the initializer + * must be a constant expression, and the type of that expression + * was validated above. + */ + var->type = initializer_type; + + var->read_only = temp; + } + + return result; +} + +ir_rvalue * +ast_declarator_list::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + void *ctx = state; + const struct glsl_type *decl_type; + const char *type_name = NULL; + ir_rvalue *result = NULL; + YYLTYPE loc = this->get_location(); + + /* From page 46 (page 52 of the PDF) of the GLSL 1.50 spec: + * + * "To ensure that a particular output variable is invariant, it is + * necessary to use the invariant qualifier. It can either be used to + * qualify a previously declared variable as being invariant + * + * invariant gl_Position; // make existing gl_Position be invariant" + * + * In these cases the parser will set the 'invariant' flag in the declarator + * list, and the type will be NULL. + */ + if (this->invariant) { + assert(this->type == NULL); + + if (state->current_function != NULL) { + _mesa_glsl_error(& loc, state, + "All uses of `invariant' keyword must be at global " + "scope\n"); + } + + foreach_list_typed (ast_declaration, decl, link, &this->declarations) { + assert(!decl->is_array); + assert(decl->array_size == NULL); + assert(decl->initializer == NULL); + + ir_variable *const earlier = + state->symbols->get_variable(decl->identifier); + if (earlier == NULL) { + _mesa_glsl_error(& loc, state, + "Undeclared variable `%s' cannot be marked " + "invariant\n", decl->identifier); + } else if ((state->target == vertex_shader) + && (earlier->mode != ir_var_out)) { + _mesa_glsl_error(& loc, state, + "`%s' cannot be marked invariant, vertex shader " + "outputs only\n", decl->identifier); + } else if ((state->target == fragment_shader) + && (earlier->mode != ir_var_in)) { + _mesa_glsl_error(& loc, state, + "`%s' cannot be marked invariant, fragment shader " + "inputs only\n", decl->identifier); + } else if (earlier->used) { + _mesa_glsl_error(& loc, state, + "variable `%s' may not be redeclared " + "`invariant' after being used", + earlier->name); + } else { + earlier->invariant = true; + } + } + + /* Invariant redeclarations do not have r-values. + */ + return NULL; + } + + assert(this->type != NULL); + assert(!this->invariant); + + /* The type specifier may contain a structure definition. Process that + * before any of the variable declarations. + */ + (void) this->type->specifier->hir(instructions, state); + + decl_type = this->type->specifier->glsl_type(& type_name, state); + if (this->declarations.is_empty()) { + /* The only valid case where the declaration list can be empty is when + * the declaration is setting the default precision of a built-in type + * (e.g., 'precision highp vec4;'). + */ + + if (decl_type != NULL) { + } else { + _mesa_glsl_error(& loc, state, "incomplete declaration"); + } + } + + foreach_list_typed (ast_declaration, decl, link, &this->declarations) { + const struct glsl_type *var_type; + ir_variable *var; + + /* FINISHME: Emit a warning if a variable declaration shadows a + * FINISHME: declaration at a higher scope. + */ + + if ((decl_type == NULL) || decl_type->is_void()) { + if (type_name != NULL) { + _mesa_glsl_error(& loc, state, + "invalid type `%s' in declaration of `%s'", + type_name, decl->identifier); + } else { + _mesa_glsl_error(& loc, state, + "invalid type in declaration of `%s'", + decl->identifier); + } + continue; + } + + if (decl->is_array) { + var_type = process_array_type(&loc, decl_type, decl->array_size, + state); + } else { + var_type = decl_type; + } + + var = new(ctx) ir_variable(var_type, decl->identifier, ir_var_auto); + + /* From page 22 (page 28 of the PDF) of the GLSL 1.10 specification; + * + * "Global variables can only use the qualifiers const, + * attribute, uni form, or varying. Only one may be + * specified. + * + * Local variables can only use the qualifier const." + * + * This is relaxed in GLSL 1.30. It is also relaxed by any extension + * that adds the 'layout' keyword. + */ + if ((state->language_version < 130) + && !state->ARB_explicit_attrib_location_enable + && !state->ARB_fragment_coord_conventions_enable) { + if (this->type->qualifier.flags.q.out) { + _mesa_glsl_error(& loc, state, + "`out' qualifier in declaration of `%s' " + "only valid for function parameters in %s.", + decl->identifier, state->version_string); + } + if (this->type->qualifier.flags.q.in) { + _mesa_glsl_error(& loc, state, + "`in' qualifier in declaration of `%s' " + "only valid for function parameters in %s.", + decl->identifier, state->version_string); + } + /* FINISHME: Test for other invalid qualifiers. */ + } + + apply_type_qualifier_to_variable(& this->type->qualifier, var, state, + & loc); + + if (this->type->qualifier.flags.q.invariant) { + if ((state->target == vertex_shader) && !(var->mode == ir_var_out || + var->mode == ir_var_inout)) { + /* FINISHME: Note that this doesn't work for invariant on + * a function signature outval + */ + _mesa_glsl_error(& loc, state, + "`%s' cannot be marked invariant, vertex shader " + "outputs only\n", var->name); + } else if ((state->target == fragment_shader) && + !(var->mode == ir_var_in || var->mode == ir_var_inout)) { + /* FINISHME: Note that this doesn't work for invariant on + * a function signature inval + */ + _mesa_glsl_error(& loc, state, + "`%s' cannot be marked invariant, fragment shader " + "inputs only\n", var->name); + } + } + + if (state->current_function != NULL) { + const char *mode = NULL; + const char *extra = ""; + + /* There is no need to check for 'inout' here because the parser will + * only allow that in function parameter lists. + */ + if (this->type->qualifier.flags.q.attribute) { + mode = "attribute"; + } else if (this->type->qualifier.flags.q.uniform) { + mode = "uniform"; + } else if (this->type->qualifier.flags.q.varying) { + mode = "varying"; + } else if (this->type->qualifier.flags.q.in) { + mode = "in"; + extra = " or in function parameter list"; + } else if (this->type->qualifier.flags.q.out) { + mode = "out"; + extra = " or in function parameter list"; + } + + if (mode) { + _mesa_glsl_error(& loc, state, + "%s variable `%s' must be declared at " + "global scope%s", + mode, var->name, extra); + } + } else if (var->mode == ir_var_in) { + var->read_only = true; + + if (state->target == vertex_shader) { + bool error_emitted = false; + + /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec: + * + * "Vertex shader inputs can only be float, floating-point + * vectors, matrices, signed and unsigned integers and integer + * vectors. Vertex shader inputs can also form arrays of these + * types, but not structures." + * + * From page 31 (page 27 of the PDF) of the GLSL 1.30 spec: + * + * "Vertex shader inputs can only be float, floating-point + * vectors, matrices, signed and unsigned integers and integer + * vectors. They cannot be arrays or structures." + * + * From page 23 (page 29 of the PDF) of the GLSL 1.20 spec: + * + * "The attribute qualifier can be used only with float, + * floating-point vectors, and matrices. Attribute variables + * cannot be declared as arrays or structures." + */ + const glsl_type *check_type = var->type->is_array() + ? var->type->fields.array : var->type; + + switch (check_type->base_type) { + case GLSL_TYPE_FLOAT: + break; + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: + if (state->language_version > 120) + break; + /* FALLTHROUGH */ + default: + _mesa_glsl_error(& loc, state, + "vertex shader input / attribute cannot have " + "type %s`%s'", + var->type->is_array() ? "array of " : "", + check_type->name); + error_emitted = true; + } + + if (!error_emitted && (state->language_version <= 130) + && var->type->is_array()) { + _mesa_glsl_error(& loc, state, + "vertex shader input / attribute cannot have " + "array type"); + error_emitted = true; + } + } + } + + /* Precision qualifiers exists only in GLSL versions 1.00 and >= 1.30. + */ + if (this->type->specifier->precision != ast_precision_none + && state->language_version != 100 + && state->language_version < 130) { + + _mesa_glsl_error(&loc, state, + "precision qualifiers are supported only in GLSL ES " + "1.00, and GLSL 1.30 and later"); + } + + + /* Precision qualifiers only apply to floating point and integer types. + * + * From section 4.5.2 of the GLSL 1.30 spec: + * "Any floating point or any integer declaration can have the type + * preceded by one of these precision qualifiers [...] Literal + * constants do not have precision qualifiers. Neither do Boolean + * variables. + * + * In GLSL ES, sampler types are also allowed. + * + * From page 87 of the GLSL ES spec: + * "RESOLUTION: Allow sampler types to take a precision qualifier." + */ + if (this->type->specifier->precision != ast_precision_none + && !var->type->is_float() + && !var->type->is_integer() + && !(var->type->is_sampler() && state->es_shader) + && !(var->type->is_array() + && (var->type->fields.array->is_float() + || var->type->fields.array->is_integer()))) { + + _mesa_glsl_error(&loc, state, + "precision qualifiers apply only to floating point" + "%s types", state->es_shader ? ", integer, and sampler" + : "and integer"); + } + + /* Process the initializer and add its instructions to a temporary + * list. This list will be added to the instruction stream (below) after + * the declaration is added. This is done because in some cases (such as + * redeclarations) the declaration may not actually be added to the + * instruction stream. + */ + exec_list initializer_instructions; + ir_variable *earlier = get_variable_being_redeclared(var, decl, state); + + if (decl->initializer != NULL) { + result = process_initializer((earlier == NULL) ? var : earlier, + decl, this->type, + &initializer_instructions, state); + } + + /* From page 23 (page 29 of the PDF) of the GLSL 1.10 spec: + * + * "It is an error to write to a const variable outside of + * its declaration, so they must be initialized when + * declared." + */ + if (this->type->qualifier.flags.q.constant && decl->initializer == NULL) { + _mesa_glsl_error(& loc, state, + "const declaration of `%s' must be initialized", + decl->identifier); + } + + /* If the declaration is not a redeclaration, there are a few additional + * semantic checks that must be applied. In addition, variable that was + * created for the declaration should be added to the IR stream. + */ + if (earlier == NULL) { + /* From page 15 (page 21 of the PDF) of the GLSL 1.10 spec, + * + * "Identifiers starting with "gl_" are reserved for use by + * OpenGL, and may not be declared in a shader as either a + * variable or a function." + */ + if (strncmp(decl->identifier, "gl_", 3) == 0) + _mesa_glsl_error(& loc, state, + "identifier `%s' uses reserved `gl_' prefix", + decl->identifier); + + /* Add the variable to the symbol table. Note that the initializer's + * IR was already processed earlier (though it hasn't been emitted + * yet), without the variable in scope. + * + * This differs from most C-like languages, but it follows the GLSL + * specification. From page 28 (page 34 of the PDF) of the GLSL 1.50 + * spec: + * + * "Within a declaration, the scope of a name starts immediately + * after the initializer if present or immediately after the name + * being declared if not." + */ + if (!state->symbols->add_variable(var)) { + YYLTYPE loc = this->get_location(); + _mesa_glsl_error(&loc, state, "name `%s' already taken in the " + "current scope", decl->identifier); + continue; + } + + /* Push the variable declaration to the top. It means that all the + * variable declarations will appear in a funny last-to-first order, + * but otherwise we run into trouble if a function is prototyped, a + * global var is decled, then the function is defined with usage of + * the global var. See glslparsertest's CorrectModule.frag. + */ + instructions->push_head(var); + } + + instructions->append_list(&initializer_instructions); + } + + + /* Generally, variable declarations do not have r-values. However, + * one is used for the declaration in + * + * while (bool b = some_condition()) { + * ... + * } + * + * so we return the rvalue from the last seen declaration here. + */ + return result; +} + + +ir_rvalue * +ast_parameter_declarator::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + void *ctx = state; + const struct glsl_type *type; + const char *name = NULL; + YYLTYPE loc = this->get_location(); + + type = this->type->specifier->glsl_type(& name, state); + + if (type == NULL) { + if (name != NULL) { + _mesa_glsl_error(& loc, state, + "invalid type `%s' in declaration of `%s'", + name, this->identifier); + } else { + _mesa_glsl_error(& loc, state, + "invalid type in declaration of `%s'", + this->identifier); + } + + type = glsl_type::error_type; + } + + /* From page 62 (page 68 of the PDF) of the GLSL 1.50 spec: + * + * "Functions that accept no input arguments need not use void in the + * argument list because prototypes (or definitions) are required and + * therefore there is no ambiguity when an empty argument list "( )" is + * declared. The idiom "(void)" as a parameter list is provided for + * convenience." + * + * Placing this check here prevents a void parameter being set up + * for a function, which avoids tripping up checks for main taking + * parameters and lookups of an unnamed symbol. + */ + if (type->is_void()) { + if (this->identifier != NULL) + _mesa_glsl_error(& loc, state, + "named parameter cannot have type `void'"); + + is_void = true; + return NULL; + } + + if (formal_parameter && (this->identifier == NULL)) { + _mesa_glsl_error(& loc, state, "formal parameter lacks a name"); + return NULL; + } + + /* This only handles "vec4 foo[..]". The earlier specifier->glsl_type(...) + * call already handled the "vec4[..] foo" case. + */ + if (this->is_array) { + type = process_array_type(&loc, type, this->array_size, state); + } + + if (type->array_size() == 0) { + _mesa_glsl_error(&loc, state, "arrays passed as parameters must have " + "a declared size."); + type = glsl_type::error_type; + } + + is_void = false; + ir_variable *var = new(ctx) ir_variable(type, this->identifier, ir_var_in); + + /* Apply any specified qualifiers to the parameter declaration. Note that + * for function parameters the default mode is 'in'. + */ + apply_type_qualifier_to_variable(& this->type->qualifier, var, state, & loc); + + instructions->push_tail(var); + + /* Parameter declarations do not have r-values. + */ + return NULL; +} + + +void +ast_parameter_declarator::parameters_to_hir(exec_list *ast_parameters, + bool formal, + exec_list *ir_parameters, + _mesa_glsl_parse_state *state) +{ + ast_parameter_declarator *void_param = NULL; + unsigned count = 0; + + foreach_list_typed (ast_parameter_declarator, param, link, ast_parameters) { + param->formal_parameter = formal; + param->hir(ir_parameters, state); + + if (param->is_void) + void_param = param; + + count++; + } + + if ((void_param != NULL) && (count > 1)) { + YYLTYPE loc = void_param->get_location(); + + _mesa_glsl_error(& loc, state, + "`void' parameter must be only parameter"); + } +} + + +void +emit_function(_mesa_glsl_parse_state *state, exec_list *instructions, + ir_function *f) +{ + /* Emit the new function header */ + if (state->current_function == NULL) { + instructions->push_tail(f); + } else { + /* IR invariants disallow function declarations or definitions nested + * within other function definitions. Insert the new ir_function + * block in the instruction sequence before the ir_function block + * containing the current ir_function_signature. + */ + ir_function *const curr = + const_cast(state->current_function->function()); + + curr->insert_before(f); + } +} + + +ir_rvalue * +ast_function::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + void *ctx = state; + ir_function *f = NULL; + ir_function_signature *sig = NULL; + exec_list hir_parameters; + + const char *const name = identifier; + + /* From page 21 (page 27 of the PDF) of the GLSL 1.20 spec, + * + * "Function declarations (prototypes) cannot occur inside of functions; + * they must be at global scope, or for the built-in functions, outside + * the global scope." + * + * From page 27 (page 33 of the PDF) of the GLSL ES 1.00.16 spec, + * + * "User defined functions may only be defined within the global scope." + * + * Note that this language does not appear in GLSL 1.10. + */ + if ((state->current_function != NULL) && (state->language_version != 110)) { + YYLTYPE loc = this->get_location(); + _mesa_glsl_error(&loc, state, + "declaration of function `%s' not allowed within " + "function body", name); + } + + /* From page 15 (page 21 of the PDF) of the GLSL 1.10 spec, + * + * "Identifiers starting with "gl_" are reserved for use by + * OpenGL, and may not be declared in a shader as either a + * variable or a function." + */ + if (strncmp(name, "gl_", 3) == 0) { + YYLTYPE loc = this->get_location(); + _mesa_glsl_error(&loc, state, + "identifier `%s' uses reserved `gl_' prefix", name); + } + + /* Convert the list of function parameters to HIR now so that they can be + * used below to compare this function's signature with previously seen + * signatures for functions with the same name. + */ + ast_parameter_declarator::parameters_to_hir(& this->parameters, + is_definition, + & hir_parameters, state); + + const char *return_type_name; + const glsl_type *return_type = + this->return_type->specifier->glsl_type(& return_type_name, state); + + if (!return_type) { + YYLTYPE loc = this->get_location(); + _mesa_glsl_error(&loc, state, + "function `%s' has undeclared return type `%s'", + name, return_type_name); + return_type = glsl_type::error_type; + } + + /* From page 56 (page 62 of the PDF) of the GLSL 1.30 spec: + * "No qualifier is allowed on the return type of a function." + */ + if (this->return_type->has_qualifiers()) { + YYLTYPE loc = this->get_location(); + _mesa_glsl_error(& loc, state, + "function `%s' return type has qualifiers", name); + } + + /* Verify that this function's signature either doesn't match a previously + * seen signature for a function with the same name, or, if a match is found, + * that the previously seen signature does not have an associated definition. + */ + f = state->symbols->get_function(name); + if (f != NULL && (state->es_shader || f->has_user_signature())) { + sig = f->exact_matching_signature(&hir_parameters); + if (sig != NULL) { + const char *badvar = sig->qualifiers_match(&hir_parameters); + if (badvar != NULL) { + YYLTYPE loc = this->get_location(); + + _mesa_glsl_error(&loc, state, "function `%s' parameter `%s' " + "qualifiers don't match prototype", name, badvar); + } + + if (sig->return_type != return_type) { + YYLTYPE loc = this->get_location(); + + _mesa_glsl_error(&loc, state, "function `%s' return type doesn't " + "match prototype", name); + } + + if (is_definition && sig->is_defined) { + YYLTYPE loc = this->get_location(); + + _mesa_glsl_error(& loc, state, "function `%s' redefined", name); + } + } + } else { + f = new(ctx) ir_function(name); + if (!state->symbols->add_function(f)) { + /* This function name shadows a non-function use of the same name. */ + YYLTYPE loc = this->get_location(); + + _mesa_glsl_error(&loc, state, "function name `%s' conflicts with " + "non-function", name); + return NULL; + } + + emit_function(state, instructions, f); + } + + /* Verify the return type of main() */ + if (strcmp(name, "main") == 0) { + if (! return_type->is_void()) { + YYLTYPE loc = this->get_location(); + + _mesa_glsl_error(& loc, state, "main() must return void"); + } + + if (!hir_parameters.is_empty()) { + YYLTYPE loc = this->get_location(); + + _mesa_glsl_error(& loc, state, "main() must not take any parameters"); + } + } + + /* Finish storing the information about this new function in its signature. + */ + if (sig == NULL) { + sig = new(ctx) ir_function_signature(return_type); + f->add_signature(sig); + } + + sig->replace_parameters(&hir_parameters); + signature = sig; + + /* Function declarations (prototypes) do not have r-values. + */ + return NULL; +} + + +ir_rvalue * +ast_function_definition::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + prototype->is_definition = true; + prototype->hir(instructions, state); + + ir_function_signature *signature = prototype->signature; + if (signature == NULL) + return NULL; + + assert(state->current_function == NULL); + state->current_function = signature; + state->found_return = false; + + /* Duplicate parameters declared in the prototype as concrete variables. + * Add these to the symbol table. + */ + state->symbols->push_scope(); + foreach_iter(exec_list_iterator, iter, signature->parameters) { + ir_variable *const var = ((ir_instruction *) iter.get())->as_variable(); + + assert(var != NULL); + + /* The only way a parameter would "exist" is if two parameters have + * the same name. + */ + if (state->symbols->name_declared_this_scope(var->name)) { + YYLTYPE loc = this->get_location(); + + _mesa_glsl_error(& loc, state, "parameter `%s' redeclared", var->name); + } else { + state->symbols->add_variable(var); + } + } + + /* Convert the body of the function to HIR. */ + this->body->hir(&signature->body, state); + signature->is_defined = true; + + state->symbols->pop_scope(); + + assert(state->current_function == signature); + state->current_function = NULL; + + if (!signature->return_type->is_void() && !state->found_return) { + YYLTYPE loc = this->get_location(); + _mesa_glsl_error(& loc, state, "function `%s' has non-void return type " + "%s, but no return statement", + signature->function_name(), + signature->return_type->name); + } + + /* Function definitions do not have r-values. + */ + return NULL; +} + + +ir_rvalue * +ast_jump_statement::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + void *ctx = state; + + switch (mode) { + case ast_return: { + ir_return *inst; + assert(state->current_function); + + if (opt_return_value) { + ir_rvalue *const ret = opt_return_value->hir(instructions, state); + + /* The value of the return type can be NULL if the shader says + * 'return foo();' and foo() is a function that returns void. + * + * NOTE: The GLSL spec doesn't say that this is an error. The type + * of the return value is void. If the return type of the function is + * also void, then this should compile without error. Seriously. + */ + const glsl_type *const ret_type = + (ret == NULL) ? glsl_type::void_type : ret->type; + + /* Implicit conversions are not allowed for return values. */ + if (state->current_function->return_type != ret_type) { + YYLTYPE loc = this->get_location(); + + _mesa_glsl_error(& loc, state, + "`return' with wrong type %s, in function `%s' " + "returning %s", + ret_type->name, + state->current_function->function_name(), + state->current_function->return_type->name); + } + + inst = new(ctx) ir_return(ret); + } else { + if (state->current_function->return_type->base_type != + GLSL_TYPE_VOID) { + YYLTYPE loc = this->get_location(); + + _mesa_glsl_error(& loc, state, + "`return' with no value, in function %s returning " + "non-void", + state->current_function->function_name()); + } + inst = new(ctx) ir_return; + } + + state->found_return = true; + instructions->push_tail(inst); + break; + } + + case ast_discard: + if (state->target != fragment_shader) { + YYLTYPE loc = this->get_location(); + + _mesa_glsl_error(& loc, state, + "`discard' may only appear in a fragment shader"); + } + instructions->push_tail(new(ctx) ir_discard); + break; + + case ast_break: + case ast_continue: + /* FINISHME: Handle switch-statements. They cannot contain 'continue', + * FINISHME: and they use a different IR instruction for 'break'. + */ + /* FINISHME: Correctly handle the nesting. If a switch-statement is + * FINISHME: inside a loop, a 'continue' is valid and will bind to the + * FINISHME: loop. + */ + if (state->loop_or_switch_nesting == NULL) { + YYLTYPE loc = this->get_location(); + + _mesa_glsl_error(& loc, state, + "`%s' may only appear in a loop", + (mode == ast_break) ? "break" : "continue"); + } else { + ir_loop *const loop = state->loop_or_switch_nesting->as_loop(); + + /* Inline the for loop expression again, since we don't know + * where near the end of the loop body the normal copy of it + * is going to be placed. + */ + if (mode == ast_continue && + state->loop_or_switch_nesting_ast->rest_expression) { + state->loop_or_switch_nesting_ast->rest_expression->hir(instructions, + state); + } + + if (loop != NULL) { + ir_loop_jump *const jump = + new(ctx) ir_loop_jump((mode == ast_break) + ? ir_loop_jump::jump_break + : ir_loop_jump::jump_continue); + instructions->push_tail(jump); + } + } + + break; + } + + /* Jump instructions do not have r-values. + */ + return NULL; +} + + +ir_rvalue * +ast_selection_statement::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + void *ctx = state; + + ir_rvalue *const condition = this->condition->hir(instructions, state); + + /* From page 66 (page 72 of the PDF) of the GLSL 1.50 spec: + * + * "Any expression whose type evaluates to a Boolean can be used as the + * conditional expression bool-expression. Vector types are not accepted + * as the expression to if." + * + * The checks are separated so that higher quality diagnostics can be + * generated for cases where both rules are violated. + */ + if (!condition->type->is_boolean() || !condition->type->is_scalar()) { + YYLTYPE loc = this->condition->get_location(); + + _mesa_glsl_error(& loc, state, "if-statement condition must be scalar " + "boolean"); + } + + ir_if *const stmt = new(ctx) ir_if(condition); + + if (then_statement != NULL) { + state->symbols->push_scope(); + then_statement->hir(& stmt->then_instructions, state); + state->symbols->pop_scope(); + } + + if (else_statement != NULL) { + state->symbols->push_scope(); + else_statement->hir(& stmt->else_instructions, state); + state->symbols->pop_scope(); + } + + instructions->push_tail(stmt); + + /* if-statements do not have r-values. + */ + return NULL; +} + + +void +ast_iteration_statement::condition_to_hir(ir_loop *stmt, + struct _mesa_glsl_parse_state *state) +{ + void *ctx = state; + + if (condition != NULL) { + ir_rvalue *const cond = + condition->hir(& stmt->body_instructions, state); + + if ((cond == NULL) + || !cond->type->is_boolean() || !cond->type->is_scalar()) { + YYLTYPE loc = condition->get_location(); + + _mesa_glsl_error(& loc, state, + "loop condition must be scalar boolean"); + } else { + /* As the first code in the loop body, generate a block that looks + * like 'if (!condition) break;' as the loop termination condition. + */ + ir_rvalue *const not_cond = + new(ctx) ir_expression(ir_unop_logic_not, glsl_type::bool_type, cond, + NULL); + + ir_if *const if_stmt = new(ctx) ir_if(not_cond); + + ir_jump *const break_stmt = + new(ctx) ir_loop_jump(ir_loop_jump::jump_break); + + if_stmt->then_instructions.push_tail(break_stmt); + stmt->body_instructions.push_tail(if_stmt); + } + } +} + + +ir_rvalue * +ast_iteration_statement::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + void *ctx = state; + + /* For-loops and while-loops start a new scope, but do-while loops do not. + */ + if (mode != ast_do_while) + state->symbols->push_scope(); + + if (init_statement != NULL) + init_statement->hir(instructions, state); + + ir_loop *const stmt = new(ctx) ir_loop(); + instructions->push_tail(stmt); + + /* Track the current loop and / or switch-statement nesting. + */ + ir_instruction *const nesting = state->loop_or_switch_nesting; + ast_iteration_statement *nesting_ast = state->loop_or_switch_nesting_ast; + + state->loop_or_switch_nesting = stmt; + state->loop_or_switch_nesting_ast = this; + + if (mode != ast_do_while) + condition_to_hir(stmt, state); + + if (body != NULL) + body->hir(& stmt->body_instructions, state); + + if (rest_expression != NULL) + rest_expression->hir(& stmt->body_instructions, state); + + if (mode == ast_do_while) + condition_to_hir(stmt, state); + + if (mode != ast_do_while) + state->symbols->pop_scope(); + + /* Restore previous nesting before returning. + */ + state->loop_or_switch_nesting = nesting; + state->loop_or_switch_nesting_ast = nesting_ast; + + /* Loops do not have r-values. + */ + return NULL; +} + + +ir_rvalue * +ast_type_specifier::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + if (!this->is_precision_statement && this->structure == NULL) + return NULL; + + YYLTYPE loc = this->get_location(); + + if (this->precision != ast_precision_none + && state->language_version != 100 + && state->language_version < 130) { + _mesa_glsl_error(&loc, state, + "precision qualifiers exist only in " + "GLSL ES 1.00, and GLSL 1.30 and later"); + return NULL; + } + if (this->precision != ast_precision_none + && this->structure != NULL) { + _mesa_glsl_error(&loc, state, + "precision qualifiers do not apply to structures"); + return NULL; + } + + /* If this is a precision statement, check that the type to which it is + * applied is either float or int. + * + * From section 4.5.3 of the GLSL 1.30 spec: + * "The precision statement + * precision precision-qualifier type; + * can be used to establish a default precision qualifier. The type + * field can be either int or float [...]. Any other types or + * qualifiers will result in an error. + */ + if (this->is_precision_statement) { + assert(this->precision != ast_precision_none); + assert(this->structure == NULL); /* The check for structures was + * performed above. */ + if (this->is_array) { + _mesa_glsl_error(&loc, state, + "default precision statements do not apply to " + "arrays"); + return NULL; + } + if (this->type_specifier != ast_float + && this->type_specifier != ast_int) { + _mesa_glsl_error(&loc, state, + "default precision statements apply only to types " + "float and int"); + return NULL; + } + + /* FINISHME: Translate precision statements into IR. */ + return NULL; + } + + if (this->structure != NULL) + return this->structure->hir(instructions, state); + + return NULL; +} + + +ir_rvalue * +ast_struct_specifier::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + unsigned decl_count = 0; + + /* Make an initial pass over the list of structure fields to determine how + * many there are. Each element in this list is an ast_declarator_list. + * This means that we actually need to count the number of elements in the + * 'declarations' list in each of the elements. + */ + foreach_list_typed (ast_declarator_list, decl_list, link, + &this->declarations) { + foreach_list_const (decl_ptr, & decl_list->declarations) { + decl_count++; + } + } + + /* Allocate storage for the structure fields and process the field + * declarations. As the declarations are processed, try to also convert + * the types to HIR. This ensures that structure definitions embedded in + * other structure definitions are processed. + */ + glsl_struct_field *const fields = ralloc_array(state, glsl_struct_field, + decl_count); + + unsigned i = 0; + foreach_list_typed (ast_declarator_list, decl_list, link, + &this->declarations) { + const char *type_name; + + decl_list->type->specifier->hir(instructions, state); + + /* Section 10.9 of the GLSL ES 1.00 specification states that + * embedded structure definitions have been removed from the language. + */ + if (state->es_shader && decl_list->type->specifier->structure != NULL) { + YYLTYPE loc = this->get_location(); + _mesa_glsl_error(&loc, state, "Embedded structure definitions are " + "not allowed in GLSL ES 1.00."); + } + + const glsl_type *decl_type = + decl_list->type->specifier->glsl_type(& type_name, state); + + foreach_list_typed (ast_declaration, decl, link, + &decl_list->declarations) { + const struct glsl_type *field_type = decl_type; + if (decl->is_array) { + YYLTYPE loc = decl->get_location(); + field_type = process_array_type(&loc, decl_type, decl->array_size, + state); + } + fields[i].type = (field_type != NULL) + ? field_type : glsl_type::error_type; + fields[i].name = decl->identifier; + i++; + } + } + + assert(i == decl_count); + + const glsl_type *t = + glsl_type::get_record_instance(fields, decl_count, this->name); + + YYLTYPE loc = this->get_location(); + if (!state->symbols->add_type(name, t)) { + _mesa_glsl_error(& loc, state, "struct `%s' previously defined", name); + } else { + const glsl_type **s = reralloc(state, state->user_structures, + const glsl_type *, + state->num_user_structures + 1); + if (s != NULL) { + s[state->num_user_structures] = t; + state->user_structures = s; + state->num_user_structures++; + } + } + + /* Structure type definitions do not have r-values. + */ + return NULL; +} diff --git a/src/glsl/ast_type.cpp b/src/glsl/ast_type.cpp new file mode 100644 index 0000000..172b271 --- /dev/null +++ b/src/glsl/ast_type.cpp @@ -0,0 +1,119 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include "ast.h" +extern "C" { +#include "program/symbol_table.h" +} + +void +ast_type_specifier::print(void) const +{ + if (type_specifier == ast_struct) { + structure->print(); + } else { + printf("%s ", type_name); + } + + if (is_array) { + printf("[ "); + + if (array_size) { + array_size->print(); + } + + printf("] "); + } +} + +ast_type_specifier::ast_type_specifier(int specifier) + : type_specifier(ast_types(specifier)), type_name(NULL), structure(NULL), + is_array(false), array_size(NULL), precision(ast_precision_none), + is_precision_statement(false) +{ + static const char *const names[] = { + "void", + "float", + "int", + "uint", + "bool", + "vec2", + "vec3", + "vec4", + "bvec2", + "bvec3", + "bvec4", + "ivec2", + "ivec3", + "ivec4", + "uvec2", + "uvec3", + "uvec4", + "mat2", + "mat2x3", + "mat2x4", + "mat3x2", + "mat3", + "mat3x4", + "mat4x2", + "mat4x3", + "mat4", + "sampler1D", + "sampler2D", + "sampler2DRect", + "sampler3D", + "samplerCube", + "sampler1DShadow", + "sampler2DShadow", + "sampler2DRectShadow", + "samplerCubeShadow", + "sampler1DArray", + "sampler2DArray", + "sampler1DArrayShadow", + "sampler2DArrayShadow", + "isampler1D", + "isampler2D", + "isampler3D", + "isamplerCube", + "isampler1DArray", + "isampler2DArray", + "usampler1D", + "usampler2D", + "usampler3D", + "usamplerCube", + "usampler1DArray", + "usampler2DArray", + + NULL, /* ast_struct */ + NULL /* ast_type_name */ + }; + + type_name = names[specifier]; +} + +bool +ast_fully_specified_type::has_qualifiers() const +{ + return this->qualifier.flags.i != 0; +} diff --git a/src/glsl/builtin_function.cpp b/src/glsl/builtin_function.cpp new file mode 100644 index 0000000..c6d1fc8 --- /dev/null +++ b/src/glsl/builtin_function.cpp @@ -0,0 +1,13639 @@ +/* DO NOT MODIFY - automatically generated by generate_builtins.py */ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include "main/core.h" /* for struct gl_shader */ +#include "glsl_parser_extras.h" +#include "ir_reader.h" +#include "program.h" +#include "ast.h" + +extern "C" struct gl_shader * +_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type); + +gl_shader * +read_builtins(GLenum target, const char *protos, const char **functions, unsigned count) +{ + struct gl_context fakeCtx; + fakeCtx.API = API_OPENGL; + gl_shader *sh = _mesa_new_shader(NULL, 0, target); + struct _mesa_glsl_parse_state *st = + new(sh) _mesa_glsl_parse_state(&fakeCtx, target, sh); + + st->language_version = 130; + st->symbols->language_version = 130; + st->ARB_texture_rectangle_enable = true; + st->EXT_texture_array_enable = true; + _mesa_glsl_initialize_types(st); + + sh->ir = new(sh) exec_list; + sh->symbols = st->symbols; + + /* Read the IR containing the prototypes */ + _mesa_glsl_read_ir(st, sh->ir, protos, true); + + /* Read ALL the function bodies, telling the IR reader not to scan for + * prototypes (we've already created them). The IR reader will skip any + * signature that does not already exist as a prototype. + */ + for (unsigned i = 0; i < count; i++) { + _mesa_glsl_read_ir(st, sh->ir, functions[i], false); + + if (st->error) { + printf("error reading builtin: %.35s ...\n", functions[i]); + printf("Info log:\n%s\n", st->info_log); + ralloc_free(sh); + return NULL; + } + } + + reparent_ir(sh->ir, sh); + delete st; + + return sh; +} + +static const char builtin_abs[] = + "((function abs\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float abs (var_ref arg0)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 abs (var_ref arg0)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 abs (var_ref arg0)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 abs (var_ref arg0)))))\n" + "))\n" + "" +; +static const char builtin_acos[] = + "((function acos\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ((return (expression float - (constant float (1.5707963))\n" + " (call asin ((var_ref x)))))))\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ((return (expression vec2 - (constant float (1.5707963))\n" + " (call asin ((var_ref x)))))))\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ((return (expression vec3 - (constant float (1.5707963))\n" + " (call asin ((var_ref x)))))))\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ((return (expression vec4 - (constant float (1.5707963))\n" + " (call asin ((var_ref x)))))))\n" + "))\n" + "" +; +static const char builtin_acosh[] = + "((function acosh\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ((return (expression float log (expression float + (var_ref x) (expression float sqrt (expression float - (expression float * (var_ref x) (var_ref x)) (constant float (1)))))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ((return (expression vec2 log (expression vec2 + (var_ref x) (expression vec2 sqrt (expression vec2 - (expression vec2 * (var_ref x) (var_ref x)) (constant vec2 (1)))))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ((return (expression vec3 log (expression vec3 + (var_ref x) (expression vec3 sqrt (expression vec3 - (expression vec3 * (var_ref x) (var_ref x)) (constant vec3 (1)))))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ((return (expression vec4 log (expression vec4 + (var_ref x) (expression vec4 sqrt (expression vec4 - (expression vec4 * (var_ref x) (var_ref x)) (constant vec4 (1)))))))))\n" + "))\n" + "" +; +static const char builtin_all[] = + "((function all\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec2 arg0))\n" + " ((return (expression bool && (swiz x (var_ref arg0))(swiz y (var_ref arg0))))))\n" + "\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec3 arg0))\n" + " ((return (expression bool && (expression bool && (swiz x (var_ref arg0))(swiz y (var_ref arg0))) (swiz z (var_ref arg0))))))\n" + "\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec4 arg0))\n" + " ((return (expression bool && (expression bool && (expression bool && (swiz x (var_ref arg0))(swiz y (var_ref arg0))) (swiz z (var_ref arg0))) (swiz w (var_ref arg0))))))\n" + "))\n" + "" +; +static const char builtin_any[] = + "((function any\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec2 arg0))\n" + " ((return (expression bool any (var_ref arg0)))))\n" + "\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec3 arg0))\n" + " ((return (expression bool any (var_ref arg0)))))\n" + "\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec4 arg0))\n" + " ((return (expression bool any (var_ref arg0)))))\n" + "))\n" + "" +; +static const char builtin_asin[] = + "((function asin\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ((return (expression float *\n" + " (expression float sign (var_ref x))\n" + " (expression float -\n" + " (expression float *\n" + " (constant float (3.1415926))\n" + " (constant float (0.5)))\n" + " (expression float *\n" + " (expression float sqrt\n" + " (expression float -\n" + " (constant float (1.0))\n" + " (expression float abs (var_ref x))))\n" + " (expression float +\n" + " (constant float (1.5707288))\n" + " (expression float *\n" + " (expression float abs (var_ref x))\n" + " (expression float +\n" + " (constant float (-0.2121144))\n" + " (expression float *\n" + " (constant float (0.0742610))\n" + " (expression float abs (var_ref x))))))))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ((return (expression vec2 *\n" + " (expression vec2 sign (var_ref x))\n" + " (expression vec2 -\n" + " (expression float *\n" + " (constant float (3.1415926))\n" + " (constant float (0.5)))\n" + " (expression vec2 *\n" + " (expression vec2 sqrt\n" + " (expression vec2 -\n" + " (constant float (1.0))\n" + " (expression vec2 abs (var_ref x))))\n" + " (expression vec2 +\n" + " (constant float (1.5707288))\n" + " (expression vec2 *\n" + " (expression vec2 abs (var_ref x))\n" + " (expression vec2 +\n" + " (constant float (-0.2121144))\n" + " (expression vec2 *\n" + " (constant float (0.0742610))\n" + " (expression vec2 abs (var_ref x))))))))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ((return (expression vec3 *\n" + " (expression vec3 sign (var_ref x))\n" + " (expression vec3 -\n" + " (expression float *\n" + " (constant float (3.1415926))\n" + " (constant float (0.5)))\n" + " (expression vec3 *\n" + " (expression vec3 sqrt\n" + " (expression vec3 -\n" + " (constant float (1.0))\n" + " (expression vec3 abs (var_ref x))))\n" + " (expression vec3 +\n" + " (constant float (1.5707288))\n" + " (expression vec3 *\n" + " (expression vec3 abs (var_ref x))\n" + " (expression vec3 +\n" + " (constant float (-0.2121144))\n" + " (expression vec3 *\n" + " (constant float (0.0742610))\n" + " (expression vec3 abs (var_ref x))))))))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ((return (expression vec4 *\n" + " (expression vec4 sign (var_ref x))\n" + " (expression vec4 -\n" + " (expression float *\n" + " (constant float (3.1415926))\n" + " (constant float (0.5)))\n" + " (expression vec4 *\n" + " (expression vec4 sqrt\n" + " (expression vec4 -\n" + " (constant float (1.0))\n" + " (expression vec4 abs (var_ref x))))\n" + " (expression vec4 +\n" + " (constant float (1.5707288))\n" + " (expression vec4 *\n" + " (expression vec4 abs (var_ref x))\n" + " (expression vec4 +\n" + " (constant float (-0.2121144))\n" + " (expression vec4 *\n" + " (constant float (0.0742610))\n" + " (expression vec4 abs (var_ref x))))))))))))\n" + "))\n" + "" +; +static const char builtin_asinh[] = + "((function asinh\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ((return (expression float log (expression float + (var_ref x) (expression float sqrt (expression float + (expression float * (var_ref x) (var_ref x)) (constant float (1)))))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ((return (expression vec2 log (expression vec2 + (var_ref x) (expression vec2 sqrt (expression vec2 + (expression vec2 * (var_ref x) (var_ref x)) (constant vec2 (1)))))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ((return (expression vec3 log (expression vec3 + (var_ref x) (expression vec3 sqrt (expression vec3 + (expression vec3 * (var_ref x) (var_ref x)) (constant vec3 (1)))))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ((return (expression vec4 log (expression vec4 + (var_ref x) (expression vec4 sqrt (expression vec4 + (expression vec4 * (var_ref x) (var_ref x)) (constant vec4 (1)))))))))\n" + "))\n" + "" +; +static const char builtin_atan[] = + "((function atan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float y_over_x))\n" + " ((return (call asin ((expression float *\n" + " (var_ref y_over_x)\n" + " (expression float rsq\n" + " (expression float +\n" + " (expression float *\n" + " (var_ref y_over_x)\n" + " (var_ref y_over_x))\n" + " (constant float (1.0))))))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y_over_x))\n" + " ((return (call asin ((expression vec2 *\n" + " (var_ref y_over_x)\n" + " (expression vec2 rsq\n" + " (expression vec2 +\n" + " (expression vec2 *\n" + " (var_ref y_over_x)\n" + " (var_ref y_over_x))\n" + " (constant float (1.0))))))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y_over_x))\n" + " ((return (call asin ((expression vec3 *\n" + " (var_ref y_over_x)\n" + " (expression vec3 rsq\n" + " (expression vec3 +\n" + " (expression vec3 *\n" + " (var_ref y_over_x)\n" + " (var_ref y_over_x))\n" + " (constant float (1.0))))))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y_over_x))\n" + " ((return (call asin ((expression vec4 *\n" + " (var_ref y_over_x)\n" + " (expression vec4 rsq\n" + " (expression vec4 +\n" + " (expression vec4 *\n" + " (var_ref y_over_x)\n" + " (var_ref y_over_x))\n" + " (constant float (1.0))))))))))\n" + "\n" + " (signature float\n" + " (parameters\n" + " (declare (in ) float y)\n" + " (declare (in ) float x)\n" + " )\n" + " (\n" + " (declare () float r)\n" + " (if (expression bool > (expression float abs (var_ref x)) (constant float (0.000100))) (\n" + " (assign (constant bool (1)) (x) (var_ref r) (call atan ((expression float / (var_ref y) (var_ref x)))))\n" + " (if (expression bool < (var_ref x) (constant float (0.000000)) ) (\n" + " (if (expression bool >= (var_ref y) (constant float (0.000000)) )\n" + " ((assign (constant bool (1)) (x) (var_ref r) (expression float + (var_ref r) (constant float (3.141593)))))\n" + " ((assign (constant bool (1)) (x) (var_ref r) (expression float - (var_ref r) (constant float (3.141593))))))\n" + " )\n" + " (\n" + " ))\n" + " )\n" + " (\n" + " (declare () float sgn)\n" + " (assign (constant bool (1)) (x) (var_ref sgn) (expression float sign (var_ref y)))\n" + " (assign (constant bool (1)) (x) (var_ref r) (expression float * (var_ref sgn) (constant float (1.5707965))))\n" + " ))\n" + "\n" + " (return (var_ref r) )\n" + " ))\n" + "\n" + "\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y)\n" + " (declare (in) vec2 x))\n" + " ((declare () vec2 r)\n" + " (assign (constant bool (1)) (x) (var_ref r)\n" + " (call atan ((swiz x (var_ref y))\n" + " (swiz x (var_ref x)))))\n" + " (assign (constant bool (1)) (y) (var_ref r)\n" + " (call atan ((swiz y (var_ref y))\n" + " (swiz y (var_ref x)))))\n" + " (return (var_ref r))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y)\n" + " (declare (in) vec3 x))\n" + " ((declare () vec3 r)\n" + " (assign (constant bool (1)) (x) (var_ref r)\n" + " (call atan ((swiz x (var_ref y))\n" + " (swiz x (var_ref x)))))\n" + " (assign (constant bool (1)) (y) (var_ref r)\n" + " (call atan ((swiz y (var_ref y))\n" + " (swiz y (var_ref x)))))\n" + " (assign (constant bool (1)) (z) (var_ref r)\n" + " (call atan ((swiz z (var_ref y))\n" + " (swiz z (var_ref x)))))\n" + " (return (var_ref r))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y)\n" + " (declare (in) vec4 x))\n" + " ((declare () vec4 r)\n" + " (assign (constant bool (1)) (x) (var_ref r)\n" + " (call atan ((swiz x (var_ref y))\n" + " (swiz x (var_ref x)))))\n" + " (assign (constant bool (1)) (y) (var_ref r)\n" + " (call atan ((swiz y (var_ref y))\n" + " (swiz y (var_ref x)))))\n" + " (assign (constant bool (1)) (z) (var_ref r)\n" + " (call atan ((swiz z (var_ref y))\n" + " (swiz z (var_ref x)))))\n" + " (assign (constant bool (1)) (w) (var_ref r)\n" + " (call atan ((swiz w (var_ref y))\n" + " (swiz w (var_ref x)))))\n" + " (return (var_ref r)))))\n" + "\n" + "))\n" + "" +; +static const char builtin_atanh[] = + "((function atanh\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ((return (expression float * (constant float (0.5))\n" + " (expression float log\n" + " (expression float /\n" + " (expression float + (constant float (1)) (var_ref x))\n" + " (expression float - (constant float (1)) (var_ref x))))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ((return (expression vec2 * (constant vec2 (0.5))\n" + " (expression vec2 log\n" + " (expression vec2 /\n" + " (expression vec2 + (constant vec2 (1)) (var_ref x))\n" + " (expression vec2 - (constant vec2 (1)) (var_ref x))))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ((return (expression vec3 * (constant vec3 (0.5))\n" + " (expression vec3 log\n" + " (expression vec3 /\n" + " (expression vec3 + (constant vec3 (1)) (var_ref x))\n" + " (expression vec3 - (constant vec3 (1)) (var_ref x))))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ((return (expression vec4 * (constant vec4 (0.5))\n" + " (expression vec4 log\n" + " (expression vec4 /\n" + " (expression vec4 + (constant vec4 (1)) (var_ref x))\n" + " (expression vec4 - (constant vec4 (1)) (var_ref x))))))))\n" + "))\n" + "" +; +static const char builtin_ceil[] = + "((function ceil\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float ceil (var_ref arg0)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 ceil (var_ref arg0)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 ceil (var_ref arg0)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 ceil (var_ref arg0)))))\n" + "))\n" + "" +; +static const char builtin_clamp[] = + "((function clamp\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0)\n" + " (declare (in) float arg1)\n" + " (declare (in) float arg2))\n" + " ((return (expression float max (expression float min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) vec2 arg1)\n" + " (declare (in) vec2 arg2))\n" + " ((return (expression vec2 max (expression vec2 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) vec3 arg1)\n" + " (declare (in) vec3 arg2))\n" + " ((return (expression vec3 max (expression vec3 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) vec4 arg1)\n" + " (declare (in) vec4 arg2))\n" + " ((return (expression vec4 max (expression vec4 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) float arg1)\n" + " (declare (in) float arg2))\n" + " ((return (expression vec2 max (expression vec2 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) float arg1)\n" + " (declare (in) float arg2))\n" + " ((return (expression vec3 max (expression vec3 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) float arg1)\n" + " (declare (in) float arg2))\n" + " ((return (expression vec4 max (expression vec4 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature int\n" + " (parameters\n" + " (declare (in) int arg0)\n" + " (declare (in) int arg1)\n" + " (declare (in) int arg2))\n" + " ((return (expression int max (expression int min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature ivec2\n" + " (parameters\n" + " (declare (in) ivec2 arg0)\n" + " (declare (in) ivec2 arg1)\n" + " (declare (in) ivec2 arg2))\n" + " ((return (expression ivec2 max (expression ivec2 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature ivec3\n" + " (parameters\n" + " (declare (in) ivec3 arg0)\n" + " (declare (in) ivec3 arg1)\n" + " (declare (in) ivec3 arg2))\n" + " ((return (expression ivec3 max (expression ivec3 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) ivec4 arg0)\n" + " (declare (in) ivec4 arg1)\n" + " (declare (in) ivec4 arg2))\n" + " ((return (expression ivec4 max (expression ivec4 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature ivec2\n" + " (parameters\n" + " (declare (in) ivec2 arg0)\n" + " (declare (in) int arg1)\n" + " (declare (in) int arg2))\n" + " ((return (expression ivec2 max (expression ivec2 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature ivec3\n" + " (parameters\n" + " (declare (in) ivec3 arg0)\n" + " (declare (in) int arg1)\n" + " (declare (in) int arg2))\n" + " ((return (expression ivec3 max (expression ivec3 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) ivec4 arg0)\n" + " (declare (in) int arg1)\n" + " (declare (in) int arg2))\n" + " ((return (expression ivec4 max (expression ivec4 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature uint\n" + " (parameters\n" + " (declare (in) uint arg0)\n" + " (declare (in) uint arg1)\n" + " (declare (in) uint arg2))\n" + " ((return (expression uint max (expression uint min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature uvec2\n" + " (parameters\n" + " (declare (in) uvec2 arg0)\n" + " (declare (in) uvec2 arg1)\n" + " (declare (in) uvec2 arg2))\n" + " ((return (expression uvec2 max (expression uvec2 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature uvec3\n" + " (parameters\n" + " (declare (in) uvec3 arg0)\n" + " (declare (in) uvec3 arg1)\n" + " (declare (in) uvec3 arg2))\n" + " ((return (expression uvec3 max (expression uvec3 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) uvec4 arg0)\n" + " (declare (in) uvec4 arg1)\n" + " (declare (in) uvec4 arg2))\n" + " ((return (expression uvec4 max (expression uvec4 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature uvec2\n" + " (parameters\n" + " (declare (in) uvec2 arg0)\n" + " (declare (in) uint arg1)\n" + " (declare (in) uint arg2))\n" + " ((return (expression uvec2 max (expression uvec2 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature uvec3\n" + " (parameters\n" + " (declare (in) uvec3 arg0)\n" + " (declare (in) uint arg1)\n" + " (declare (in) uint arg2))\n" + " ((return (expression uvec3 max (expression uvec3 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) uvec4 arg0)\n" + " (declare (in) uint arg1)\n" + " (declare (in) uint arg2))\n" + " ((return (expression uvec4 max (expression uvec4 min (var_ref arg0) (var_ref arg2)) (var_ref arg1)))))\n" + "))\n" + "" +; +static const char builtin_cos[] = + "((function cos\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ((return (expression float cos (var_ref angle)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ((return (expression vec2 cos (var_ref angle)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ((return (expression vec3 cos (var_ref angle)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ((return (expression vec4 cos (var_ref angle)))))\n" + "))\n" + "" +; +static const char builtin_cosh[] = + "((function cosh\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ((return (expression float * (constant float (0.5))\n" + " (expression float +\n" + " (expression float exp (var_ref x))\n" + " (expression float exp (expression float neg (var_ref x))))))))\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ((return (expression vec2 * (constant vec2 (0.5))\n" + " (expression vec2 +\n" + " (expression vec2 exp (var_ref x))\n" + " (expression vec2 exp (expression vec2 neg (var_ref x))))))))\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ((return (expression vec3 * (constant vec3 (0.5))\n" + " (expression vec3 +\n" + " (expression vec3 exp (var_ref x))\n" + " (expression vec3 exp (expression vec3 neg (var_ref x))))))))\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ((return (expression vec4 * (constant vec4 (0.5))\n" + " (expression vec4 +\n" + " (expression vec4 exp (var_ref x))\n" + " (expression vec4 exp (expression vec4 neg (var_ref x))))))))\n" + "))\n" + "" +; +static const char builtin_cross[] = + "((function cross\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 a)\n" + " (declare (in) vec3 b))\n" + " ((return (expression vec3 -\n" + " (expression vec3 * (swiz yzx (var_ref a)) (swiz zxy (var_ref b)))\n" + " (expression vec3 * (swiz zxy (var_ref a)) (swiz yzx (var_ref b)))))))\n" + "))\n" + "" +; +static const char builtin_dFdx[] = + "((function dFdx\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p))\n" + " ((return (expression float dFdx (var_ref p)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 p))\n" + " ((return (expression vec2 dFdx (var_ref p)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 p))\n" + " ((return (expression vec3 dFdx (var_ref p)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 p))\n" + " ((return (expression vec4 dFdx (var_ref p)))))\n" + "))\n" + "" +; +static const char builtin_dFdy[] = + "((function dFdy\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p))\n" + " ((return (expression float dFdy (var_ref p)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 p))\n" + " ((return (expression vec2 dFdy (var_ref p)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 p))\n" + " ((return (expression vec3 dFdy (var_ref p)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 p))\n" + " ((return (expression vec4 dFdy (var_ref p)))))\n" + "))\n" + "" +; +static const char builtin_degrees[] = + "((function degrees\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float * (var_ref arg0) (constant float (57.295780))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 * (var_ref arg0) (constant float (57.295780))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 * (var_ref arg0) (constant float (57.295780))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 * (var_ref arg0) (constant float (57.295780))))))\n" + "))\n" + "" +; +static const char builtin_distance[] = + "((function distance\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p0)\n" + " (declare (in) float p1))\n" + " ((return (expression float abs (expression float - (var_ref p0) (var_ref p1))))))\n" + "\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 p0)\n" + " (declare (in) vec2 p1))\n" + " ((declare () vec2 p)\n" + " (assign (constant bool (1)) (xy) (var_ref p) (expression vec2 - (var_ref p0) (var_ref p1)))\n" + " (return (expression float sqrt (expression float dot (var_ref p) (var_ref p))))))\n" + "\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 p0)\n" + " (declare (in) vec3 p1))\n" + " ((declare () vec3 p)\n" + " (assign (constant bool (1)) (xyz) (var_ref p) (expression vec3 - (var_ref p0) (var_ref p1)))\n" + " (return (expression float sqrt (expression float dot (var_ref p) (var_ref p))))))\n" + "\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 p0)\n" + " (declare (in) vec4 p1))\n" + " ((declare () vec4 p)\n" + " (assign (constant bool (1)) (xyzw) (var_ref p) (expression vec4 - (var_ref p0) (var_ref p1)))\n" + " (return (expression float sqrt (expression float dot (var_ref p) (var_ref p))))))\n" + "))\n" + "" +; +static const char builtin_dot[] = + "((function dot\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0)\n" + " (declare (in) float arg1))\n" + " ((return (expression float * (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) vec2 arg1))\n" + " ((return (expression float dot (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) vec3 arg1))\n" + " ((return (expression float dot (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) vec4 arg1))\n" + " ((return (expression float dot (var_ref arg0) (var_ref arg1)))))\n" + "))\n" + "" +; +static const char builtin_equal[] = + "((function equal\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) vec2 arg1))\n" + " ((return (expression bvec2 == (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) vec3 arg1))\n" + " ((return (expression bvec3 == (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) vec4 arg1))\n" + " ((return (expression bvec4 == (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 arg0)\n" + " (declare (in) bvec2 arg1))\n" + " ((return (expression bvec2 == (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 arg0)\n" + " (declare (in) bvec3 arg1))\n" + " ((return (expression bvec3 == (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 arg0)\n" + " (declare (in) bvec4 arg1))\n" + " ((return (expression bvec4 == (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 arg0)\n" + " (declare (in) ivec2 arg1))\n" + " ((return (expression bvec2 == (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 arg0)\n" + " (declare (in) ivec3 arg1))\n" + " ((return (expression bvec3 == (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 arg0)\n" + " (declare (in) ivec4 arg1))\n" + " ((return (expression bvec4 == (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) uvec2 arg0)\n" + " (declare (in) uvec2 arg1))\n" + " ((return (expression bvec2 == (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) uvec3 arg0)\n" + " (declare (in) uvec3 arg1))\n" + " ((return (expression bvec3 == (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) uvec4 arg0)\n" + " (declare (in) uvec4 arg1))\n" + " ((return (expression bvec4 == (var_ref arg0) (var_ref arg1)))))\n" + "))\n" + "" +; +static const char builtin_exp[] = + "((function exp\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float exp (var_ref arg0)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 exp (var_ref arg0)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 exp (var_ref arg0)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 exp (var_ref arg0)))))\n" + "))\n" + "" +; +static const char builtin_exp2[] = + "((function exp2\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float exp2 (var_ref arg0)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 exp2 (var_ref arg0)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 exp2 (var_ref arg0)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 exp2 (var_ref arg0)))))\n" + "))\n" + "" +; +static const char builtin_faceforward[] = + "((function faceforward\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float N)\n" + " (declare (in) float I)\n" + " (declare (in) float Nref))\n" + " ((if (expression bool < (expression float * (var_ref Nref) (var_ref I)) (constant float (0)))\n" + " ((return (var_ref N)))\n" + " ((return (expression float neg (var_ref N)))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 N)\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 Nref))\n" + " ((if (expression bool < (expression float dot (var_ref Nref) (var_ref I)) (constant float (0)))\n" + " ((return (var_ref N)))\n" + " ((return (expression vec2 neg (var_ref N)))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 N)\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 Nref))\n" + " ((if (expression bool < (expression float dot (var_ref Nref) (var_ref I)) (constant float (0)))\n" + " ((return (var_ref N)))\n" + " ((return (expression vec3 neg (var_ref N)))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 N)\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 Nref))\n" + " ((if (expression bool < (expression float dot (var_ref Nref) (var_ref I)) (constant float (0)))\n" + " ((return (var_ref N)))\n" + " ((return (expression vec4 neg (var_ref N)))))))\n" + "))\n" + "" +; +static const char builtin_floor[] = + "((function floor\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float floor (var_ref arg0)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 floor (var_ref arg0)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 floor (var_ref arg0)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 floor (var_ref arg0)))))\n" + "))\n" + "" +; +static const char builtin_fract[] = + "((function fract\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ((return (expression float fract (var_ref x)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ((return (expression vec2 fract (var_ref x)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ((return (expression vec3 fract (var_ref x)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ((return (expression vec4 fract (var_ref x)))))\n" + "))\n" + "\n" + "" +; +static const char builtin_ftransform[] = + "((declare (uniform) mat4 gl_ModelViewProjectionMatrix)\n" + " (declare (in) vec4 gl_Vertex)\n" + " (function ftransform\n" + " (signature vec4\n" + " (parameters)\n" + " ((return (expression vec4 *\n" + " (var_ref gl_ModelViewProjectionMatrix)\n" + " (var_ref gl_Vertex)))))\n" + "))\n" + "" +; +static const char builtin_fwidth[] = + "((function fwidth\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p))\n" + " ((return (expression float +\n" + " (expression float abs (expression float dFdx (var_ref p)))\n" + " (expression float abs (expression float dFdy (var_ref p)))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 p))\n" + " ((return (expression vec2 +\n" + " (expression vec2 abs (expression vec2 dFdx (var_ref p)))\n" + " (expression vec2 abs (expression vec2 dFdy (var_ref p)))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 p))\n" + " ((return (expression vec3 +\n" + " (expression vec3 abs (expression vec3 dFdx (var_ref p)))\n" + " (expression vec3 abs (expression vec3 dFdy (var_ref p)))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 p))\n" + " ((return (expression vec4 +\n" + " (expression vec4 abs (expression vec4 dFdx (var_ref p)))\n" + " (expression vec4 abs (expression vec4 dFdy (var_ref p)))))))\n" + "))\n" + "" +; +static const char builtin_greaterThan[] = + "((function greaterThan\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) vec2 arg1))\n" + " ((return (expression bvec2 > (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) vec3 arg1))\n" + " ((return (expression bvec3 > (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) vec4 arg1))\n" + " ((return (expression bvec4 > (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 arg0)\n" + " (declare (in) ivec2 arg1))\n" + " ((return (expression bvec2 > (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 arg0)\n" + " (declare (in) ivec3 arg1))\n" + " ((return (expression bvec3 > (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 arg0)\n" + " (declare (in) ivec4 arg1))\n" + " ((return (expression bvec4 > (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) uvec2 arg0)\n" + " (declare (in) uvec2 arg1))\n" + " ((return (expression bvec2 > (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) uvec3 arg0)\n" + " (declare (in) uvec3 arg1))\n" + " ((return (expression bvec3 > (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) uvec4 arg0)\n" + " (declare (in) uvec4 arg1))\n" + " ((return (expression bvec4 > (var_ref arg0) (var_ref arg1)))))\n" + "))\n" + "" +; +static const char builtin_greaterThanEqual[] = + "((function greaterThanEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) vec2 arg1))\n" + " ((return (expression bvec2 >= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) vec3 arg1))\n" + " ((return (expression bvec3 >= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) vec4 arg1))\n" + " ((return (expression bvec4 >= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 arg0)\n" + " (declare (in) ivec2 arg1))\n" + " ((return (expression bvec2 >= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 arg0)\n" + " (declare (in) ivec3 arg1))\n" + " ((return (expression bvec3 >= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 arg0)\n" + " (declare (in) ivec4 arg1))\n" + " ((return (expression bvec4 >= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) uvec2 arg0)\n" + " (declare (in) uvec2 arg1))\n" + " ((return (expression bvec2 >= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) uvec3 arg0)\n" + " (declare (in) uvec3 arg1))\n" + " ((return (expression bvec3 >= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) uvec4 arg0)\n" + " (declare (in) uvec4 arg1))\n" + " ((return (expression bvec4 >= (var_ref arg0) (var_ref arg1)))))\n" + "))\n" + "" +; +static const char builtin_inversesqrt[] = + "((function inversesqrt\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float rsq (var_ref arg0)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 rsq (var_ref arg0)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 rsq (var_ref arg0)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 rsq (var_ref arg0)))))\n" + "))\n" + "" +; +static const char builtin_length[] = + "((function length\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float abs (var_ref arg0)))))\n" + "\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression float sqrt (expression float dot (var_ref arg0) (var_ref arg0))))))\n" + "\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression float sqrt (expression float dot (var_ref arg0) (var_ref arg0))))))\n" + "\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression float sqrt (expression float dot (var_ref arg0) (var_ref arg0))))))\n" + "))\n" + "" +; +static const char builtin_lessThan[] = + "((function lessThan\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) vec2 arg1))\n" + " ((return (expression bvec2 < (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) vec3 arg1))\n" + " ((return (expression bvec3 < (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) vec4 arg1))\n" + " ((return (expression bvec4 < (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 arg0)\n" + " (declare (in) ivec2 arg1))\n" + " ((return (expression bvec2 < (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 arg0)\n" + " (declare (in) ivec3 arg1))\n" + " ((return (expression bvec3 < (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 arg0)\n" + " (declare (in) ivec4 arg1))\n" + " ((return (expression bvec4 < (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) uvec2 arg0)\n" + " (declare (in) uvec2 arg1))\n" + " ((return (expression bvec2 < (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) uvec3 arg0)\n" + " (declare (in) uvec3 arg1))\n" + " ((return (expression bvec3 < (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) uvec4 arg0)\n" + " (declare (in) uvec4 arg1))\n" + " ((return (expression bvec4 < (var_ref arg0) (var_ref arg1)))))\n" + "))\n" + "" +; +static const char builtin_lessThanEqual[] = + "((function lessThanEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) vec2 arg1))\n" + " ((return (expression bvec2 <= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) vec3 arg1))\n" + " ((return (expression bvec3 <= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) vec4 arg1))\n" + " ((return (expression bvec4 <= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 arg0)\n" + " (declare (in) ivec2 arg1))\n" + " ((return (expression bvec2 <= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 arg0)\n" + " (declare (in) ivec3 arg1))\n" + " ((return (expression bvec3 <= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 arg0)\n" + " (declare (in) ivec4 arg1))\n" + " ((return (expression bvec4 <= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) uvec2 arg0)\n" + " (declare (in) uvec2 arg1))\n" + " ((return (expression bvec2 <= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) uvec3 arg0)\n" + " (declare (in) uvec3 arg1))\n" + " ((return (expression bvec3 <= (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) uvec4 arg0)\n" + " (declare (in) uvec4 arg1))\n" + " ((return (expression bvec4 <= (var_ref arg0) (var_ref arg1)))))\n" + "))\n" + "" +; +static const char builtin_log[] = + "((function log\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float log (var_ref arg0)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 log (var_ref arg0)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 log (var_ref arg0)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 log (var_ref arg0)))))\n" + "))\n" + "" +; +static const char builtin_log2[] = + "((function log2\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float log2 (var_ref arg0)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 log2 (var_ref arg0)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 log2 (var_ref arg0)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 log2 (var_ref arg0)))))\n" + "))\n" + "" +; +static const char builtin_matrixCompMult[] = + "((function matrixCompMult\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) mat2 x)\n" + " (declare (in) mat2 y))\n" + " ((declare () mat2 z)\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0)))))\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1)))))\n" + "(return (var_ref z))))\n" + "\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) mat3 x)\n" + " (declare (in) mat3 y))\n" + " ((declare () mat3 z)\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0)))))\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1)))))\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (2))) (expression vec3 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2)))))\n" + "(return (var_ref z))))\n" + "\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) mat4 x)\n" + " (declare (in) mat4 y))\n" + " ((declare () mat4 z)\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0)))))\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1)))))\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (2))) (expression vec4 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2)))))\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (3))) (expression vec4 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3)))))\n" + "(return (var_ref z))))\n" + "\n" + " (signature mat2x3\n" + " (parameters\n" + " (declare (in) mat2x3 x)\n" + " (declare (in) mat2x3 y))\n" + " ((declare () mat2x3 z)\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0)))))\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1)))))\n" + "(return (var_ref z))))\n" + "\n" + " (signature mat3x2\n" + " (parameters\n" + " (declare (in) mat3x2 x)\n" + " (declare (in) mat3x2 y))\n" + " ((declare () mat3x2 z)\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0)))))\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1)))))\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (2))) (expression vec2 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2)))))\n" + "(return (var_ref z))))\n" + "\n" + " (signature mat2x4\n" + " (parameters\n" + " (declare (in) mat2x4 x)\n" + " (declare (in) mat2x4 y))\n" + " ((declare () mat2x4 z)\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0)))))\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1)))))\n" + "(return (var_ref z))))\n" + "\n" + " (signature mat4x2\n" + " (parameters\n" + " (declare (in) mat4x2 x)\n" + " (declare (in) mat4x2 y))\n" + " ((declare () mat4x2 z)\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0)))))\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1)))))\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (2))) (expression vec2 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2)))))\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref z) (constant int (3))) (expression vec2 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3)))))\n" + "(return (var_ref z))))\n" + "\n" + " (signature mat3x4\n" + " (parameters\n" + " (declare (in) mat3x4 x)\n" + " (declare (in) mat3x4 y))\n" + " ((declare () mat3x4 z)\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0)))))\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1)))))\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref z) (constant int (2))) (expression vec4 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2)))))\n" + "(return (var_ref z))))\n" + "\n" + " (signature mat4x3\n" + " (parameters\n" + " (declare (in) mat4x3 x)\n" + " (declare (in) mat4x3 y))\n" + " ((declare () mat4x3 z)\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0)))))\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1)))))\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (2))) (expression vec3 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2)))))\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref z) (constant int (3))) (expression vec3 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3)))))\n" + "(return (var_ref z))))\n" + "))\n" + "" +; +static const char builtin_max[] = + "((function max\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0)\n" + " (declare (in) float arg1))\n" + " ((return (expression float max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) vec2 arg1))\n" + " ((return (expression vec2 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) vec3 arg1))\n" + " ((return (expression vec3 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) vec4 arg1))\n" + " ((return (expression vec4 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) float arg1))\n" + " ((return (expression vec2 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) float arg1))\n" + " ((return (expression vec3 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) float arg1))\n" + " ((return (expression vec4 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature int\n" + " (parameters\n" + " (declare (in) int arg0)\n" + " (declare (in) int arg1))\n" + " ((return (expression int max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature ivec2\n" + " (parameters\n" + " (declare (in) ivec2 arg0)\n" + " (declare (in) ivec2 arg1))\n" + " ((return (expression ivec2 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature ivec3\n" + " (parameters\n" + " (declare (in) ivec3 arg0)\n" + " (declare (in) ivec3 arg1))\n" + " ((return (expression ivec3 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) ivec4 arg0)\n" + " (declare (in) ivec4 arg1))\n" + " ((return (expression ivec4 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature ivec2\n" + " (parameters\n" + " (declare (in) ivec2 arg0)\n" + " (declare (in) int arg1))\n" + " ((return (expression ivec2 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature ivec3\n" + " (parameters\n" + " (declare (in) ivec3 arg0)\n" + " (declare (in) int arg1))\n" + " ((return (expression ivec3 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) ivec4 arg0)\n" + " (declare (in) int arg1))\n" + " ((return (expression ivec4 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature uint\n" + " (parameters\n" + " (declare (in) uint arg0)\n" + " (declare (in) uint arg1))\n" + " ((return (expression uint max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature uvec2\n" + " (parameters\n" + " (declare (in) uvec2 arg0)\n" + " (declare (in) uvec2 arg1))\n" + " ((return (expression uvec2 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature uvec3\n" + " (parameters\n" + " (declare (in) uvec3 arg0)\n" + " (declare (in) uvec3 arg1))\n" + " ((return (expression uvec3 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) uvec4 arg0)\n" + " (declare (in) uvec4 arg1))\n" + " ((return (expression uvec4 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature uvec2\n" + " (parameters\n" + " (declare (in) uvec2 arg0)\n" + " (declare (in) uint arg1))\n" + " ((return (expression uvec2 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature uvec3\n" + " (parameters\n" + " (declare (in) uvec3 arg0)\n" + " (declare (in) uint arg1))\n" + " ((return (expression uvec3 max (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) uvec4 arg0)\n" + " (declare (in) uint arg1))\n" + " ((return (expression uvec4 max (var_ref arg0) (var_ref arg1)))))\n" + "))\n" + "" +; +static const char builtin_min[] = + "((function min\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0)\n" + " (declare (in) float arg1))\n" + " ((return (expression float min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) vec2 arg1))\n" + " ((return (expression vec2 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) vec3 arg1))\n" + " ((return (expression vec3 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) vec4 arg1))\n" + " ((return (expression vec4 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) float arg1))\n" + " ((return (expression vec2 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) float arg1))\n" + " ((return (expression vec3 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) float arg1))\n" + " ((return (expression vec4 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature int\n" + " (parameters\n" + " (declare (in) int arg0)\n" + " (declare (in) int arg1))\n" + " ((return (expression int min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature ivec2\n" + " (parameters\n" + " (declare (in) ivec2 arg0)\n" + " (declare (in) ivec2 arg1))\n" + " ((return (expression ivec2 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature ivec3\n" + " (parameters\n" + " (declare (in) ivec3 arg0)\n" + " (declare (in) ivec3 arg1))\n" + " ((return (expression ivec3 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) ivec4 arg0)\n" + " (declare (in) ivec4 arg1))\n" + " ((return (expression ivec4 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature ivec2\n" + " (parameters\n" + " (declare (in) ivec2 arg0)\n" + " (declare (in) int arg1))\n" + " ((return (expression ivec2 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature ivec3\n" + " (parameters\n" + " (declare (in) ivec3 arg0)\n" + " (declare (in) int arg1))\n" + " ((return (expression ivec3 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) ivec4 arg0)\n" + " (declare (in) int arg1))\n" + " ((return (expression ivec4 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature uint\n" + " (parameters\n" + " (declare (in) uint arg0)\n" + " (declare (in) uint arg1))\n" + " ((return (expression uint min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature uvec2\n" + " (parameters\n" + " (declare (in) uvec2 arg0)\n" + " (declare (in) uvec2 arg1))\n" + " ((return (expression uvec2 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature uvec3\n" + " (parameters\n" + " (declare (in) uvec3 arg0)\n" + " (declare (in) uvec3 arg1))\n" + " ((return (expression uvec3 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) uvec4 arg0)\n" + " (declare (in) uvec4 arg1))\n" + " ((return (expression uvec4 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature uvec2\n" + " (parameters\n" + " (declare (in) uvec2 arg0)\n" + " (declare (in) uint arg1))\n" + " ((return (expression uvec2 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature uvec3\n" + " (parameters\n" + " (declare (in) uvec3 arg0)\n" + " (declare (in) uint arg1))\n" + " ((return (expression uvec3 min (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) uvec4 arg0)\n" + " (declare (in) uint arg1))\n" + " ((return (expression uvec4 min (var_ref arg0) (var_ref arg1)))))\n" + "))\n" + "" +; +static const char builtin_mix[] = + "((function mix\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0)\n" + " (declare (in) float arg1)\n" + " (declare (in) float arg2))\n" + " ((return (expression float + (expression float * (var_ref arg0) (expression float - (constant float (1.000000)) (var_ref arg2))) (expression float * (var_ref arg1) (var_ref arg2))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) vec2 arg1)\n" + " (declare (in) vec2 arg2))\n" + " ((return (expression vec2 + (expression vec2 * (var_ref arg0) (expression vec2 - (constant float (1.000000)) (var_ref arg2))) (expression vec2 * (var_ref arg1) (var_ref arg2))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) vec3 arg1)\n" + " (declare (in) vec3 arg2))\n" + " ((return (expression vec3 + (expression vec3 * (var_ref arg0) (expression vec3 - (constant float (1.000000)) (var_ref arg2))) (expression vec3 * (var_ref arg1) (var_ref arg2))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) vec4 arg1)\n" + " (declare (in) vec4 arg2))\n" + " ((return (expression vec4 + (expression vec4 * (var_ref arg0) (expression vec4 - (constant float (1.000000)) (var_ref arg2))) (expression vec4 * (var_ref arg1) (var_ref arg2))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) vec2 arg1)\n" + " (declare (in) float arg2))\n" + " ((return (expression vec2 + (expression vec2 * (var_ref arg0) (expression float - (constant float (1.000000)) (var_ref arg2))) (expression vec2 * (var_ref arg1) (var_ref arg2))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) vec3 arg1)\n" + " (declare (in) float arg2))\n" + " ((return (expression vec3 + (expression vec3 * (var_ref arg0) (expression float - (constant float (1.000000)) (var_ref arg2))) (expression vec3 * (var_ref arg1) (var_ref arg2))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) vec4 arg1)\n" + " (declare (in) float arg2))\n" + " ((return (expression vec4 + (expression vec4 * (var_ref arg0) (expression float - (constant float (1.000000)) (var_ref arg2))) (expression vec4 * (var_ref arg1) (var_ref arg2))))))\n" + "\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float v1)\n" + " (declare (in) float v2)\n" + " (declare (in) bool a))\n" + " ((assign (var_ref a) (var_ref v1) (var_ref v2))\n" + " (return (var_ref v1))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 v1)\n" + " (declare (in) vec2 v2)\n" + " (declare (in) bvec2 a))\n" + " ((assign (swiz x (var_ref a)) (x) (var_ref v1) (swiz x (var_ref v2)))\n" + " (assign (swiz y (var_ref a)) (y) (var_ref v1) (swiz y (var_ref v2)))\n" + " (return (var_ref v1))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 v1)\n" + " (declare (in) vec3 v2)\n" + " (declare (in) bvec3 a))\n" + " ((assign (swiz x (var_ref a)) (x) (var_ref v1) (swiz x (var_ref v2)))\n" + " (assign (swiz y (var_ref a)) (y) (var_ref v1) (swiz y (var_ref v2)))\n" + " (assign (swiz z (var_ref a)) (z) (var_ref v1) (swiz z (var_ref v2)))\n" + " (return (var_ref v1))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 v1)\n" + " (declare (in) vec4 v2)\n" + " (declare (in) bvec4 a))\n" + " ((assign (swiz x (var_ref a)) (x) (var_ref v1) (swiz x (var_ref v2)))\n" + " (assign (swiz y (var_ref a)) (y) (var_ref v1) (swiz y (var_ref v2)))\n" + " (assign (swiz z (var_ref a)) (z) (var_ref v1) (swiz z (var_ref v2)))\n" + " (assign (swiz w (var_ref a)) (w) (var_ref v1) (swiz w (var_ref v2)))\n" + " (return (var_ref v1))))\n" + "))\n" + "" +; +static const char builtin_mod[] = + "((function mod\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0)\n" + " (declare (in) float arg1))\n" + " ((return (expression float % (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) vec2 arg1))\n" + " ((return (expression vec2 % (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) vec3 arg1))\n" + " ((return (expression vec3 % (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) vec4 arg1))\n" + " ((return (expression vec4 % (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) float arg1))\n" + " ((return (expression vec2 % (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) float arg1))\n" + " ((return (expression vec3 % (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) float arg1))\n" + " ((return (expression vec4 % (var_ref arg0) (var_ref arg1)))))\n" + "))\n" + "" +; +static const char builtin_modf[] = + "((function modf\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (out) float i))\n" + " ((declare () float t)\n" + " (assign (constant bool (1)) (x) (var_ref t)\n" + " (expression float trunc (var_ref x)))\n" + " (assign (constant bool (1)) (x) (var_ref i) (var_ref t))\n" + " (return (expression float - (var_ref x) (var_ref t)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (out) vec2 i))\n" + " ((declare () vec2 t)\n" + " (assign (constant bool (1)) (xy) (var_ref t)\n" + " (expression vec2 trunc (var_ref x)))\n" + " (assign (constant bool (1)) (xy) (var_ref i) (var_ref t))\n" + " (return (expression vec2 - (var_ref x) (var_ref t)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (out) vec3 i))\n" + " ((declare () vec3 t)\n" + " (assign (constant bool (1)) (xyz) (var_ref t)\n" + " (expression vec3 trunc (var_ref x)))\n" + " (assign (constant bool (1)) (xyz) (var_ref i) (var_ref t))\n" + " (return (expression vec3 - (var_ref x) (var_ref t)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (out) vec4 i))\n" + " ((declare () vec4 t)\n" + " (assign (constant bool (1)) (xyzw) (var_ref t)\n" + " (expression vec4 trunc (var_ref x)))\n" + " (assign (constant bool (1)) (xyzw) (var_ref i) (var_ref t))\n" + " (return (expression vec4 - (var_ref x) (var_ref t)))))\n" + "))\n" + "" +; +static const char builtin_noise1[] = + "((function noise1\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ((return (expression float noise (var_ref x)))))\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ((return (expression float noise (var_ref x)))))\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ((return (expression float noise (var_ref x)))))\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ((return (expression float noise (var_ref x)))))\n" + "))\n" + "" +; +static const char builtin_noise2[] = + "((function noise2\n" + " (signature vec2\n" + " (parameters (declare (in) vec4 p))\n" + " (\n" + " (declare () float a)\n" + " (declare () float b)\n" + " (declare () vec2 t)\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p)))\n" + " (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression vec4 + (var_ref p) (constant vec4 (601.0 313.0 29.0 277.0)))))\n" + " (assign (constant bool (1)) (x) (var_ref t) (var_ref a))\n" + " (assign (constant bool (1)) (y) (var_ref t) (var_ref b))\n" + " (return (var_ref t))\n" + " ))\n" + "\n" + " (signature vec2\n" + " (parameters (declare (in) vec3 p))\n" + " (\n" + " (declare () float a)\n" + " (declare () float b)\n" + " (declare () vec2 t)\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p)))\n" + " (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression vec3 + (var_ref p) (constant vec3 (601.0 313.0 29.0)))))\n" + " (assign (constant bool (1)) (x) (var_ref t) (var_ref a))\n" + " (assign (constant bool (1)) (y) (var_ref t) (var_ref b))\n" + " (return (var_ref t))\n" + " ))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in ) vec2 p)\n" + " )\n" + " (\n" + " (declare () float a)\n" + " (declare () float b)\n" + " (declare () vec2 t)\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p)))\n" + " (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression vec2 + (var_ref p) (constant vec2 (601.0 313.0)))))\n" + " (assign (constant bool (1)) (x) (var_ref t) (var_ref a))\n" + " (assign (constant bool (1)) (y) (var_ref t) (var_ref b))\n" + " (return (var_ref t))\n" + " ))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in ) float p)\n" + " )\n" + " (\n" + " (declare () float a)\n" + " (declare () float b)\n" + " (declare () vec2 t)\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p)))\n" + " (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression float + (var_ref p) (constant float (601.0)))))\n" + " (assign (constant bool (1)) (x) (var_ref t) (var_ref a))\n" + " (assign (constant bool (1)) (y) (var_ref t) (var_ref b))\n" + " (return (var_ref t))\n" + " ))\n" + "))\n" + "" +; +static const char builtin_noise3[] = + "((function noise3\n" + " (signature vec3\n" + " (parameters (declare (in) vec4 p))\n" + " (\n" + " (declare () float a)\n" + " (declare () float b)\n" + " (declare () float c)\n" + " (declare () vec3 t)\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p)))\n" + " (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression vec4 + (var_ref p) (constant vec4 (601.0 313.0 29.0 277.0)))))\n" + " (assign (constant bool (1)) (x) (var_ref c) (expression float noise (expression vec4 + (var_ref p) (constant vec4 (1559.0 113.0 1861.0 797.0)))))\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref t) (var_ref a))\n" + " (assign (constant bool (1)) (y) (var_ref t) (var_ref b))\n" + " (assign (constant bool (1)) (z) (var_ref t) (var_ref c))\n" + " (return (var_ref t))\n" + " ))\n" + "\n" + " (signature vec3\n" + " (parameters (declare (in) vec3 p))\n" + " (\n" + " (declare () float a)\n" + " (declare () float b)\n" + " (declare () float c)\n" + " (declare () vec3 t)\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p)))\n" + " (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression vec3 + (var_ref p) (constant vec3 (601.0 313.0 29.0)))))\n" + " (assign (constant bool (1)) (x) (var_ref c) (expression float noise (expression vec3 + (var_ref p) (constant vec3 (1559.0 113.0 1861.0)))))\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref t) (var_ref a))\n" + " (assign (constant bool (1)) (y) (var_ref t) (var_ref b))\n" + " (assign (constant bool (1)) (z) (var_ref t) (var_ref c))\n" + " (return (var_ref t))\n" + " ))\n" + "\n" + " (signature vec3\n" + " (parameters (declare (in) vec2 p))\n" + " (\n" + " (declare () float a)\n" + " (declare () float b)\n" + " (declare () float c)\n" + " (declare () vec3 t)\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p)))\n" + " (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression vec2 + (var_ref p) (constant vec2 (601.0 313.0)))))\n" + " (assign (constant bool (1)) (x) (var_ref c) (expression float noise (expression vec2 + (var_ref p) (constant vec2 (1559.0 113.0)))))\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref t) (var_ref a))\n" + " (assign (constant bool (1)) (y) (var_ref t) (var_ref b))\n" + " (assign (constant bool (1)) (z) (var_ref t) (var_ref c))\n" + " (return (var_ref t))\n" + " ))\n" + "\n" + " (signature vec3\n" + " (parameters (declare (in) float p))\n" + " (\n" + " (declare () float a)\n" + " (declare () float b)\n" + " (declare () float c)\n" + " (declare () vec3 t)\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref a) (expression float noise (var_ref p)))\n" + " (assign (constant bool (1)) (x) (var_ref b) (expression float noise (expression float + (var_ref p) (constant float (601.0)))))\n" + " (assign (constant bool (1)) (x) (var_ref c) (expression float noise (expression float + (var_ref p) (constant float (1559.0)))))\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref t) (var_ref a))\n" + " (assign (constant bool (1)) (y) (var_ref t) (var_ref b))\n" + " (assign (constant bool (1)) (z) (var_ref t) (var_ref c))\n" + " (return (var_ref t))\n" + " ))\n" + "))\n" + "" +; +static const char builtin_noise4[] = + "((function noise4\n" + " (signature vec4\n" + " (parameters (declare (in) vec4 p))\n" + " (\n" + " (declare () float _x)\n" + " (declare () float _y)\n" + " (declare () float _z)\n" + " (declare () float _w)\n" + " (declare () vec4 _r)\n" + "\n" + " (declare () vec4 _p)\n" + " (assign (constant bool (1)) (xyzw) (var_ref _p) (expression vec4 + (var_ref p) (constant vec4 (1559.0 113.0 1861.0 797.0))) )\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref _x) (expression float noise(var_ref p)))\n" + " (assign (constant bool (1)) (x) (var_ref _y) (expression float noise(expression vec4 + (var_ref p) (constant vec4 (601.0 313.0 29.0 277.0)))))\n" + " (assign (constant bool (1)) (x) (var_ref _z) (expression float noise(var_ref _p)))\n" + " (assign (constant bool (1)) (x) (var_ref _w) (expression float noise(expression vec4 + (var_ref _p) (constant vec4 (601.0 313.0 29.0 277.0)))))\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref _r) (var_ref _x))\n" + " (assign (constant bool (1)) (y) (var_ref _r) (var_ref _y))\n" + " (assign (constant bool (1)) (z) (var_ref _r) (var_ref _z))\n" + " (assign (constant bool (1)) (w) (var_ref _r) (var_ref _w))\n" + " (return (var_ref _r))\n" + " ))\n" + "\n" + " (signature vec4\n" + " (parameters (declare (in) vec3 p))\n" + " (\n" + " (declare () float _x)\n" + " (declare () float _y)\n" + " (declare () float _z)\n" + " (declare () float _w)\n" + " (declare () vec4 _r)\n" + "\n" + " (declare () vec3 _p)\n" + " (assign (constant bool (1)) (xyz) (var_ref _p) (expression vec3 + (var_ref p) (constant vec3 (1559.0 113.0 1861.0))) )\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref _x) (expression float noise(var_ref p)))\n" + " (assign (constant bool (1)) (x) (var_ref _y) (expression float noise(expression vec3 + (var_ref p) (constant vec3 (601.0 313.0 29.0)))))\n" + " (assign (constant bool (1)) (x) (var_ref _z) (expression float noise(var_ref _p)))\n" + " (assign (constant bool (1)) (x) (var_ref _w) (expression float noise(expression vec3 + (var_ref _p) (constant vec3 (601.0 313.0 29.0)))))\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref _r) (var_ref _x))\n" + " (assign (constant bool (1)) (y) (var_ref _r) (var_ref _y))\n" + " (assign (constant bool (1)) (z) (var_ref _r) (var_ref _z))\n" + " (assign (constant bool (1)) (w) (var_ref _r) (var_ref _w))\n" + " (return (var_ref _r))\n" + " ))\n" + "\n" + " (signature vec4\n" + " (parameters (declare (in) vec2 p))\n" + " (\n" + " (declare () float _x)\n" + " (declare () float _y)\n" + " (declare () float _z)\n" + " (declare () float _w)\n" + " (declare () vec4 _r)\n" + "\n" + " (declare () vec2 _p)\n" + " (assign (constant bool (1)) (xy) (var_ref _p) (expression vec2 + (var_ref p) (constant vec2 (1559.0 113.0))) )\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref _x) (expression float noise(var_ref p)))\n" + " (assign (constant bool (1)) (x) (var_ref _y) (expression float noise(expression vec2 + (var_ref p) (constant vec2 (601.0 313.0)))))\n" + " (assign (constant bool (1)) (x) (var_ref _z) (expression float noise(var_ref _p)))\n" + " (assign (constant bool (1)) (x) (var_ref _w) (expression float noise(expression vec2 + (var_ref _p) (constant vec2 (601.0 313.0)))))\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref _r) (var_ref _x))\n" + " (assign (constant bool (1)) (y) (var_ref _r) (var_ref _y))\n" + " (assign (constant bool (1)) (z) (var_ref _r) (var_ref _z))\n" + " (assign (constant bool (1)) (w) (var_ref _r) (var_ref _w))\n" + " (return (var_ref _r))\n" + " ))\n" + "\n" + " (signature vec4\n" + " (parameters (declare (in) float p))\n" + " (\n" + " (declare () float _x)\n" + " (declare () float _y)\n" + " (declare () float _z)\n" + " (declare () float _w)\n" + " (declare () vec4 _r)\n" + "\n" + " (declare () float _p)\n" + " (assign (constant bool (1)) (x) (var_ref _p) (expression float + (var_ref p) (constant float (1559.0))) )\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref _x) (expression float noise(var_ref p)))\n" + " (assign (constant bool (1)) (x) (var_ref _y) (expression float noise(expression float + (var_ref p) (constant float (601.0 313.0 29.0 277.0)))))\n" + " (assign (constant bool (1)) (x) (var_ref _z) (expression float noise(var_ref _p)))\n" + " (assign (constant bool (1)) (x) (var_ref _w) (expression float noise(expression float + (var_ref _p) (constant float (601.0 313.0 29.0 277.0)))))\n" + "\n" + " (assign (constant bool (1)) (x) (var_ref _r) (var_ref _x))\n" + " (assign (constant bool (1)) (y) (var_ref _r) (var_ref _y))\n" + " (assign (constant bool (1)) (z) (var_ref _r) (var_ref _z))\n" + " (assign (constant bool (1)) (w) (var_ref _r) (var_ref _w))\n" + " (return (var_ref _r))\n" + " ))\n" + "))\n" + "" +; +static const char builtin_normalize[] = + "((function normalize\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float sign (var_ref arg0)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 * (var_ref arg0) (expression float rsq (expression float dot (var_ref arg0) (var_ref arg0)))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 * (var_ref arg0) (expression float rsq (expression float dot (var_ref arg0) (var_ref arg0)))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 * (var_ref arg0) (expression float rsq (expression float dot (var_ref arg0) (var_ref arg0)))))))\n" + "))\n" + "" +; +static const char builtin_not[] = + "((function not\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 arg0))\n" + " ((return (expression bvec2 ! (var_ref arg0)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 arg0))\n" + " ((return (expression bvec3 ! (var_ref arg0)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 arg0))\n" + " ((return (expression bvec4 ! (var_ref arg0)))))\n" + "))\n" + "" +; +static const char builtin_notEqual[] = + "((function notEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) vec2 arg1))\n" + " ((return (expression bvec2 != (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) vec3 arg1))\n" + " ((return (expression bvec3 != (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) vec4 arg1))\n" + " ((return (expression bvec4 != (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 arg0)\n" + " (declare (in) bvec2 arg1))\n" + " ((return (expression bvec2 != (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 arg0)\n" + " (declare (in) bvec3 arg1))\n" + " ((return (expression bvec3 != (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 arg0)\n" + " (declare (in) bvec4 arg1))\n" + " ((return (expression bvec4 != (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 arg0)\n" + " (declare (in) ivec2 arg1))\n" + " ((return (expression bvec2 != (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 arg0)\n" + " (declare (in) ivec3 arg1))\n" + " ((return (expression bvec3 != (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 arg0)\n" + " (declare (in) ivec4 arg1))\n" + " ((return (expression bvec4 != (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) uvec2 arg0)\n" + " (declare (in) uvec2 arg1))\n" + " ((return (expression bvec2 != (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) uvec3 arg0)\n" + " (declare (in) uvec3 arg1))\n" + " ((return (expression bvec3 != (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) uvec4 arg0)\n" + " (declare (in) uvec4 arg1))\n" + " ((return (expression bvec4 != (var_ref arg0) (var_ref arg1)))))\n" + "))\n" + "" +; +static const char builtin_outerProduct[] = + "((function outerProduct\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) vec2 u)\n" + " (declare (in) vec2 v))\n" + " ((declare () mat2 m)\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref u) (swiz x (var_ref v))))\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref u) (swiz y (var_ref v))))\n" + " (return (var_ref m))))\n" + "\n" + " (signature mat2x3\n" + " (parameters\n" + " (declare (in) vec3 u)\n" + " (declare (in) vec2 v))\n" + " ((declare () mat2x3 m)\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref u) (swiz x (var_ref v))))\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref u) (swiz y (var_ref v))))\n" + " (return (var_ref m))))\n" + "\n" + " (signature mat2x4\n" + " (parameters\n" + " (declare (in) vec4 u)\n" + " (declare (in) vec2 v))\n" + " ((declare () mat2x4 m)\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref u) (swiz x (var_ref v))))\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref u) (swiz y (var_ref v))))\n" + " (return (var_ref m))))\n" + "\n" + " (signature mat3x2\n" + " (parameters\n" + " (declare (in) vec2 u)\n" + " (declare (in) vec3 v))\n" + " ((declare () mat3x2 m)\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref u) (swiz x (var_ref v))))\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref u) (swiz y (var_ref v))))\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (2))) (expression vec2 * (var_ref u) (swiz z (var_ref v))))\n" + " (return (var_ref m))\n" + " ))\n" + "\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) vec3 u)\n" + " (declare (in) vec3 v))\n" + " ((declare () mat3 m)\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref u) (swiz x (var_ref v))))\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref u) (swiz y (var_ref v))))\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (2))) (expression vec3 * (var_ref u) (swiz z (var_ref v))))\n" + " (return (var_ref m))))\n" + "\n" + " (signature mat3x4\n" + " (parameters\n" + " (declare (in) vec4 u)\n" + " (declare (in) vec3 v))\n" + " ((declare () mat3x4 m)\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref u) (swiz x (var_ref v))))\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref u) (swiz y (var_ref v))))\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (2))) (expression vec4 * (var_ref u) (swiz z (var_ref v))))\n" + " (return (var_ref m))))\n" + "\n" + " (signature mat4x2\n" + " (parameters\n" + " (declare (in) vec2 u)\n" + " (declare (in) vec4 v))\n" + " ((declare () mat4x2 m)\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref u) (swiz x (var_ref v))))\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref u) (swiz y (var_ref v))))\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (2))) (expression vec2 * (var_ref u) (swiz z (var_ref v))))\n" + " (assign (constant bool (1)) (xy) (array_ref (var_ref m) (constant int (3))) (expression vec2 * (var_ref u) (swiz w (var_ref v))))\n" + " (return (var_ref m))))\n" + "\n" + " (signature mat4x3\n" + " (parameters\n" + " (declare (in) vec3 u)\n" + " (declare (in) vec4 v))\n" + " ((declare () mat4x3 m)\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref u) (swiz x (var_ref v))))\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref u) (swiz y (var_ref v))))\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (2))) (expression vec3 * (var_ref u) (swiz z (var_ref v))))\n" + " (assign (constant bool (1)) (xyz) (array_ref (var_ref m) (constant int (3))) (expression vec3 * (var_ref u) (swiz w (var_ref v))))\n" + " (return (var_ref m))))\n" + "\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) vec4 u)\n" + " (declare (in) vec4 v))\n" + " ((declare () mat4 m)\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref u) (swiz x (var_ref v))))\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref u) (swiz y (var_ref v))))\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (2))) (expression vec4 * (var_ref u) (swiz z (var_ref v))))\n" + " (assign (constant bool (1)) (xyzw) (array_ref (var_ref m) (constant int (3))) (expression vec4 * (var_ref u) (swiz w (var_ref v))))\n" + " (return (var_ref m))))\n" + "))\n" + "" +; +static const char builtin_pow[] = + "((function pow\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0)\n" + " (declare (in) float arg1))\n" + " ((return (expression float pow (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0)\n" + " (declare (in) vec2 arg1))\n" + " ((return (expression vec2 pow (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0)\n" + " (declare (in) vec3 arg1))\n" + " ((return (expression vec3 pow (var_ref arg0) (var_ref arg1)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0)\n" + " (declare (in) vec4 arg1))\n" + " ((return (expression vec4 pow (var_ref arg0) (var_ref arg1)))))\n" + "))\n" + "" +; +static const char builtin_radians[] = + "((function radians\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float * (var_ref arg0) (constant float (0.017453))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 * (var_ref arg0) (constant float (0.017453))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 * (var_ref arg0) (constant float (0.017453))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 * (var_ref arg0) (constant float (0.017453))))))\n" + "))\n" + "" +; +static const char builtin_reflect[] = + "((function reflect\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float i)\n" + " (declare (in) float n))\n" + " ((return (expression float -\n" + " (var_ref i)\n" + " (expression float *\n" + " (constant float (2.0))\n" + " (expression float *\n" + " (expression float *\n" + " (var_ref n)\n" + " (var_ref i))\n" + " (var_ref n)))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 i)\n" + " (declare (in) vec2 n))\n" + " ((return (expression vec2 -\n" + " (var_ref i)\n" + " (expression vec2 *\n" + " (constant float (2.0))\n" + " (expression vec2 *\n" + " (expression float dot\n" + " (var_ref n)\n" + " (var_ref i))\n" + " (var_ref n)))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 i)\n" + " (declare (in) vec3 n))\n" + " ((return (expression vec3 -\n" + " (var_ref i)\n" + " (expression vec3 *\n" + " (constant float (2.0))\n" + " (expression vec3 *\n" + " (expression float dot\n" + " (var_ref n)\n" + " (var_ref i))\n" + " (var_ref n)))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 i)\n" + " (declare (in) vec4 n))\n" + " ((return (expression vec4 -\n" + " (var_ref i)\n" + " (expression vec4 *\n" + " (constant float (2.0))\n" + " (expression vec4 *\n" + " (expression float dot\n" + " (var_ref n)\n" + " (var_ref i))\n" + " (var_ref n)))))))\n" + "\n" + "))\n" + "" +; +static const char builtin_refract[] = + "((function refract\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float i)\n" + " (declare (in) float n)\n" + " (declare (in) float eta))\n" + " ((declare () float k)\n" + " (assign (constant bool (1)) (x) (var_ref k)\n" + " (expression float - (constant float (1.0))\n" + " (expression float * (var_ref eta)\n" + " (expression float * (var_ref eta)\n" + " (expression float - (constant float (1.0))\n" + " (expression float * \n" + " (expression float * (var_ref n) (var_ref i))\n" + " (expression float * (var_ref n) (var_ref i))))))))\n" + " (if (expression bool < (var_ref k) (constant float (0.0)))\n" + " ((return (constant float (0.0))))\n" + " ((return (expression float -\n" + " (expression float * (var_ref eta) (var_ref i))\n" + " (expression float *\n" + " (expression float +\n" + " (expression float * (var_ref eta)\n" + " (expression float * (var_ref n) (var_ref i)))\n" + " (expression float sqrt (var_ref k)))\n" + " (var_ref n))))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 i)\n" + " (declare (in) vec2 n)\n" + " (declare (in) float eta))\n" + " ((declare () float k)\n" + " (assign (constant bool (1)) (x) (var_ref k)\n" + " (expression float - (constant float (1.0))\n" + " (expression float * (var_ref eta)\n" + " (expression float * (var_ref eta)\n" + " (expression float - (constant float (1.0))\n" + " (expression float * \n" + " (expression float dot (var_ref n) (var_ref i))\n" + " (expression float dot (var_ref n) (var_ref i))))))))\n" + " (if (expression bool < (var_ref k) (constant float (0.0)))\n" + " ((return (constant vec2 (0.0 0.0))))\n" + " ((return (expression vec2 -\n" + " (expression vec2 * (var_ref eta) (var_ref i))\n" + " (expression vec2 *\n" + " (expression float +\n" + " (expression float * (var_ref eta)\n" + " (expression float dot (var_ref n) (var_ref i)))\n" + " (expression float sqrt (var_ref k)))\n" + " (var_ref n))))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 i)\n" + " (declare (in) vec3 n)\n" + " (declare (in) float eta))\n" + " ((declare () float k)\n" + " (assign (constant bool (1)) (x) (var_ref k)\n" + " (expression float - (constant float (1.0))\n" + " (expression float * (var_ref eta)\n" + " (expression float * (var_ref eta)\n" + " (expression float - (constant float (1.0))\n" + " (expression float * \n" + " (expression float dot (var_ref n) (var_ref i))\n" + " (expression float dot (var_ref n) (var_ref i))))))))\n" + " (if (expression bool < (var_ref k) (constant float (0.0)))\n" + " ((return (constant vec3 (0.0 0.0 0.0))))\n" + " ((return (expression vec3 -\n" + " (expression vec3 * (var_ref eta) (var_ref i))\n" + " (expression vec3 *\n" + " (expression float +\n" + " (expression float * (var_ref eta)\n" + " (expression float dot (var_ref n) (var_ref i)))\n" + " (expression float sqrt (var_ref k)))\n" + " (var_ref n))))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 i)\n" + " (declare (in) vec4 n)\n" + " (declare (in) float eta))\n" + " ((declare () float k)\n" + " (assign (constant bool (1)) (x) (var_ref k)\n" + " (expression float - (constant float (1.0))\n" + " (expression float * (var_ref eta)\n" + " (expression float * (var_ref eta)\n" + " (expression float - (constant float (1.0))\n" + " (expression float * \n" + " (expression float dot (var_ref n) (var_ref i))\n" + " (expression float dot (var_ref n) (var_ref i))))))))\n" + " (if (expression bool < (var_ref k) (constant float (0.0)))\n" + " ((return (constant vec4 (0.0 0.0 0.0 0.0))))\n" + " ((return (expression vec4 -\n" + " (expression vec4 * (var_ref eta) (var_ref i))\n" + " (expression vec4 *\n" + " (expression float +\n" + " (expression float * (var_ref eta)\n" + " (expression float dot (var_ref n) (var_ref i)))\n" + " (expression float sqrt (var_ref k)))\n" + " (var_ref n))))))))\n" + "\n" + "))\n" + "" +; +static const char builtin_round[] = + "((function round\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float round_even (var_ref arg0)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 round_even (var_ref arg0)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 round_even (var_ref arg0)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 round_even (var_ref arg0)))))\n" + "))\n" + "" +; +static const char builtin_roundEven[] = + "((function roundEven\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float round_even (var_ref arg0)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 round_even (var_ref arg0)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 round_even (var_ref arg0)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 round_even (var_ref arg0)))))\n" + "))\n" + "" +; +static const char builtin_shadow1D[] = + "((function shadow1D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (swiz x (var_ref P)) (0 0 0) 1 (swiz z (var_ref P)) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz x (var_ref P)) (0 0 0) 1 (swiz z (var_ref P)) (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_shadow1DArray[] = + "((function shadow1DArray\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArrayShadow sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) 1 (swiz z (var_ref P)) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArrayShadow sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) 1 (swiz z (var_ref P)) (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_shadow1DArrayLod[] = + "((function shadow1DArrayLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArrayShadow sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) 1 (swiz z (var_ref P)) (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_shadow1DLod[] = + "((function shadow1DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz x (var_ref P)) (0 0 0) 1 (swiz z (var_ref P)) (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_shadow1DProj[] = + "((function shadow1DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) (swiz z (var_ref P)) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) (swiz z (var_ref P)) (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_shadow1DProjLod[] = + "((function shadow1DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) (swiz z (var_ref P)) (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_shadow2D[] = + "((function shadow2D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) 1 (swiz z (var_ref P)) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) 1 (swiz z (var_ref P)) (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_shadow2DArray[] = + "((function shadow2DArray\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArrayShadow sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) 1 (swiz w (var_ref P)) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_shadow2DLod[] = + "((function shadow2DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) 1 (swiz z (var_ref P)) (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_shadow2DProj[] = + "((function shadow2DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) (swiz z (var_ref P)) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) (swiz z (var_ref P)) (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_shadow2DProjLod[] = + "((function shadow2DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) (swiz z (var_ref P)) (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_shadow2DRect[] = + "((function shadow2DRect\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRectShadow sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) 1 (swiz z (var_ref P)) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_shadow2DRectProj[] = + "((function shadow2DRectProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRectShadow sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) (swiz z (var_ref P)) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_sign[] = + "((function sign\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ((return (expression float sign (var_ref x)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ((return (expression vec2 sign (var_ref x)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ((return (expression vec3 sign (var_ref x)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ((return (expression vec4 sign (var_ref x)))))\n" + "\n" + " (signature int\n" + " (parameters\n" + " (declare (in) int x))\n" + " ((return (expression int sign (var_ref x)))))\n" + "\n" + " (signature ivec2\n" + " (parameters\n" + " (declare (in) ivec2 x))\n" + " ((return (expression ivec2 sign (var_ref x)))))\n" + "\n" + " (signature ivec3\n" + " (parameters\n" + " (declare (in) ivec3 x))\n" + " ((return (expression ivec3 sign (var_ref x)))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) ivec4 x))\n" + " ((return (expression ivec4 sign (var_ref x)))))\n" + "))\n" + "\n" + "" +; +static const char builtin_sin[] = + "((function sin\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ((return (expression float sin (var_ref angle)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ((return (expression vec2 sin (var_ref angle)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ((return (expression vec3 sin (var_ref angle)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ((return (expression vec4 sin (var_ref angle)))))\n" + "))\n" + "" +; +static const char builtin_sinh[] = + "((function sinh\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ((return (expression float * (constant float (0.5))\n" + " (expression float -\n" + " (expression float exp (var_ref x))\n" + " (expression float exp (expression float neg (var_ref x))))))))\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ((return (expression vec2 * (constant vec2 (0.5))\n" + " (expression vec2 -\n" + " (expression vec2 exp (var_ref x))\n" + " (expression vec2 exp (expression vec2 neg (var_ref x))))))))\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ((return (expression vec3 * (constant vec3 (0.5))\n" + " (expression vec3 -\n" + " (expression vec3 exp (var_ref x))\n" + " (expression vec3 exp (expression vec3 neg (var_ref x))))))))\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ((return (expression vec4 * (constant vec4 (0.5))\n" + " (expression vec4 -\n" + " (expression vec4 exp (var_ref x))\n" + " (expression vec4 exp (expression vec4 neg (var_ref x))))))))\n" + "))\n" + "" +; +static const char builtin_smoothstep[] = + "((function smoothstep\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) float x))\n" + " ((declare () float t)\n" + " (assign (constant bool (1)) (x) (var_ref t)\n" + " (expression float max\n" + " (expression float min\n" + " (expression float / (expression float - (var_ref x) (var_ref edge0)) (expression float - (var_ref edge1) (var_ref edge0)))\n" + " (constant float (1.0)))\n" + " (constant float (0.0))))\n" + " (return (expression float * (var_ref t) (expression float * (var_ref t) (expression float - (constant float (3.0)) (expression float * (constant float (2.0)) (var_ref t))))))))\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec2 x))\n" + " ((declare () vec2 t)\n" + " (assign (constant bool (1)) (xy) (var_ref t)\n" + " (expression vec2 max\n" + " (expression vec2 min\n" + " (expression vec2 / (expression vec2 - (var_ref x) (var_ref edge0)) (expression float - (var_ref edge1) (var_ref edge0)))\n" + " (constant float (1.0)))\n" + " (constant float (0.0))))\n" + " (return (expression vec2 * (var_ref t) (expression vec2 * (var_ref t) (expression vec2 - (constant float (3.0)) (expression vec2 * (constant float (2.0)) (var_ref t))))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec3 x))\n" + " ((declare () vec3 t)\n" + " (assign (constant bool (1)) (xyz) (var_ref t)\n" + " (expression vec3 max\n" + " (expression vec3 min\n" + " (expression vec3 / (expression vec3 - (var_ref x) (var_ref edge0)) (expression float - (var_ref edge1) (var_ref edge0)))\n" + " (constant float (1.0)))\n" + " (constant float (0.0))))\n" + " (return (expression vec3 * (var_ref t) (expression vec3 * (var_ref t) (expression vec3 - (constant float (3.0)) (expression vec3 * (constant float (2.0)) (var_ref t))))))))\n" + "\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec4 x))\n" + " ((declare () vec4 t)\n" + " (assign (constant bool (1)) (xyzw) (var_ref t)\n" + " (expression vec4 max\n" + " (expression vec4 min\n" + " (expression vec4 / (expression vec4 - (var_ref x) (var_ref edge0)) (expression float - (var_ref edge1) (var_ref edge0)))\n" + " (constant float (1.0)))\n" + " (constant float (0.0))))\n" + " (return (expression vec4 * (var_ref t) (expression vec4 * (var_ref t) (expression vec4 - (constant float (3.0)) (expression vec4 * (constant float (2.0)) (var_ref t))))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 edge0)\n" + " (declare (in) vec2 edge1)\n" + " (declare (in) vec2 x))\n" + " ((declare () vec2 t)\n" + " (assign (constant bool (1)) (xy) (var_ref t)\n" + " (expression vec2 max\n" + " (expression vec2 min\n" + " (expression vec2 / (expression vec2 - (var_ref x) (var_ref edge0)) (expression vec2 - (var_ref edge1) (var_ref edge0)))\n" + " (constant float (1.0)))\n" + " (constant float (0.0))))\n" + " (return (expression vec2 * (var_ref t) (expression vec2 * (var_ref t) (expression vec2 - (constant float (3.0)) (expression vec2 * (constant float (2.0)) (var_ref t))))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 edge0)\n" + " (declare (in) vec3 edge1)\n" + " (declare (in) vec3 x))\n" + " ((declare () vec3 t)\n" + " (assign (constant bool (1)) (xyz) (var_ref t)\n" + " (expression vec3 max\n" + " (expression vec3 min\n" + " (expression vec3 / (expression vec3 - (var_ref x) (var_ref edge0)) (expression vec3 - (var_ref edge1) (var_ref edge0)))\n" + " (constant float (1.0)))\n" + " (constant float (0.0))))\n" + " (return (expression vec3 * (var_ref t) (expression vec3 * (var_ref t) (expression vec3 - (constant float (3.0)) (expression vec3 * (constant float (2.0)) (var_ref t))))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 edge0)\n" + " (declare (in) vec4 edge1)\n" + " (declare (in) vec4 x))\n" + " ((declare () vec4 t)\n" + " (assign (constant bool (1)) (xyzw) (var_ref t)\n" + " (expression vec4 max\n" + " (expression vec4 min\n" + " (expression vec4 / (expression vec4 - (var_ref x) (var_ref edge0)) (expression vec4 - (var_ref edge1) (var_ref edge0)))\n" + " (constant float (1.0)))\n" + " (constant float (0.0))))\n" + " (return (expression vec4 * (var_ref t) (expression vec4 * (var_ref t) (expression vec4 - (constant float (3.0)) (expression vec4 * (constant float (2.0)) (var_ref t))))))))\n" + "))\n" + "\n" + "" +; +static const char builtin_sqrt[] = + "((function sqrt\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float sqrt (var_ref arg0)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 sqrt (var_ref arg0)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 sqrt (var_ref arg0)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 sqrt (var_ref arg0)))))\n" + "))\n" + "" +; +static const char builtin_step[] = + "((function step\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) float x))\n" + " ((return (expression float b2f (expression bool >= (var_ref x) (var_ref edge))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec2 x))\n" + " ((declare () vec2 t)\n" + " (assign (constant bool (1)) (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(var_ref edge))))\n" + " (assign (constant bool (1)) (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(var_ref edge))))\n" + " (return (var_ref t))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec3 x))\n" + " ((declare () vec3 t)\n" + " (assign (constant bool (1)) (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(var_ref edge))))\n" + " (assign (constant bool (1)) (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(var_ref edge))))\n" + " (assign (constant bool (1)) (z) (var_ref t) (expression float b2f (expression bool >= (swiz z (var_ref x))(var_ref edge))))\n" + " (return (var_ref t))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec4 x))\n" + " ((declare () vec4 t)\n" + " (assign (constant bool (1)) (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(var_ref edge))))\n" + " (assign (constant bool (1)) (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(var_ref edge))))\n" + " (assign (constant bool (1)) (z) (var_ref t) (expression float b2f (expression bool >= (swiz z (var_ref x))(var_ref edge))))\n" + " (assign (constant bool (1)) (w) (var_ref t) (expression float b2f (expression bool >= (swiz w (var_ref x))(var_ref edge))))\n" + " (return (var_ref t))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 edge)\n" + " (declare (in) vec2 x))\n" + " ((declare () vec2 t)\n" + " (assign (constant bool (1)) (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(swiz x (var_ref edge)))))\n" + " (assign (constant bool (1)) (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(swiz y (var_ref edge)))))\n" + " (return (var_ref t))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 edge)\n" + " (declare (in) vec3 x))\n" + " ((declare () vec3 t)\n" + " (assign (constant bool (1)) (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(swiz x (var_ref edge)))))\n" + " (assign (constant bool (1)) (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(swiz y (var_ref edge)))))\n" + " (assign (constant bool (1)) (z) (var_ref t) (expression float b2f (expression bool >= (swiz z (var_ref x))(swiz z (var_ref edge)))))\n" + " (return (var_ref t))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 edge)\n" + " (declare (in) vec4 x))\n" + " ((declare () vec4 t)\n" + " (assign (constant bool (1)) (x) (var_ref t) (expression float b2f (expression bool >= (swiz x (var_ref x))(swiz x (var_ref edge)))))\n" + " (assign (constant bool (1)) (y) (var_ref t) (expression float b2f (expression bool >= (swiz y (var_ref x))(swiz y (var_ref edge)))))\n" + " (assign (constant bool (1)) (z) (var_ref t) (expression float b2f (expression bool >= (swiz z (var_ref x))(swiz z (var_ref edge)))))\n" + " (assign (constant bool (1)) (w) (var_ref t) (expression float b2f (expression bool >= (swiz w (var_ref x))(swiz w (var_ref edge)))))\n" + " (return (var_ref t))))\n" + "))\n" + "\n" + "" +; +static const char builtin_tan[] = + "((function tan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ((return (expression float / (expression float sin (var_ref angle)) (expression float cos (var_ref angle))))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ((return (expression vec2 / (expression vec2 sin (var_ref angle)) (expression vec2 cos (var_ref angle))))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ((return (expression vec3 / (expression vec3 sin (var_ref angle)) (expression vec3 cos (var_ref angle))))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ((return (expression vec4 / (expression vec4 sin (var_ref angle)) (expression vec4 cos (var_ref angle))))))\n" + "))\n" + "" +; +static const char builtin_tanh[] = + "((function tanh\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ((return (expression float /\n" + " (expression float -\n" + " (expression float exp (var_ref x))\n" + " (expression float exp (expression float neg (var_ref x))))\n" + " (expression float +\n" + " (expression float exp (var_ref x))\n" + " (expression float exp (expression float neg (var_ref x))))))))\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ((return (expression vec2 /\n" + " (expression vec2 -\n" + " (expression vec2 exp (var_ref x))\n" + " (expression vec2 exp (expression vec2 neg (var_ref x))))\n" + " (expression vec2 +\n" + " (expression vec2 exp (var_ref x))\n" + " (expression vec2 exp (expression vec2 neg (var_ref x))))))))\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ((return (expression vec3 /\n" + " (expression vec3 -\n" + " (expression vec3 exp (var_ref x))\n" + " (expression vec3 exp (expression vec3 neg (var_ref x))))\n" + " (expression vec3 +\n" + " (expression vec3 exp (var_ref x))\n" + " (expression vec3 exp (expression vec3 neg (var_ref x))))))))\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ((return (expression vec4 /\n" + " (expression vec4 -\n" + " (expression vec4 exp (var_ref x))\n" + " (expression vec4 exp (expression vec4 neg (var_ref x))))\n" + " (expression vec4 +\n" + " (expression vec4 exp (var_ref x))\n" + " (expression vec4 exp (expression vec4 neg (var_ref x))))))))\n" + "))\n" + "" +; +static const char builtin_texelFetch[] = + "((function texelFetch\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) int P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1D sampler)\n" + " (declare (in) int P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1D sampler)\n" + " (declare (in) int P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) ivec2 P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2D sampler)\n" + " (declare (in) ivec2 P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2D sampler)\n" + " (declare (in) ivec2 P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) ivec3 P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler3D sampler)\n" + " (declare (in) ivec3 P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler3D sampler)\n" + " (declare (in) ivec3 P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArray sampler)\n" + " (declare (in) ivec2 P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1DArray sampler)\n" + " (declare (in) ivec2 P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1DArray sampler)\n" + " (declare (in) ivec2 P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArray sampler)\n" + " (declare (in) ivec3 P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2DArray sampler)\n" + " (declare (in) ivec3 P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2DArray sampler)\n" + " (declare (in) ivec3 P) \n" + " (declare (in) int lod) )\n" + " ((return (txf (var_ref sampler) (var_ref P) (0 0 0) (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture[] = + "((function texture\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1D sampler)\n" + " (declare (in) float P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1D sampler)\n" + " (declare (in) float P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2D sampler)\n" + " (declare (in) vec2 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2D sampler)\n" + " (declare (in) vec2 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler3D sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler3D sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isamplerCube sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usamplerCube sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArray sampler)\n" + " (declare (in) vec2 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1DArray sampler)\n" + " (declare (in) vec2 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1DArray sampler)\n" + " (declare (in) vec2 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArray sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2DArray sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2DArray sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1D sampler)\n" + " (declare (in) float P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1D sampler)\n" + " (declare (in) float P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler3D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler3D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isamplerCube sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usamplerCube sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArray sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1DArray sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1DArray sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArray sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2DArray sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2DArray sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture1D[] = + "((function texture1D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture1DArray[] = + "((function texture1DArray\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArray sampler)\n" + " (declare (in) vec2 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArray sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture1DArrayLod[] = + "((function texture1DArrayLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArray sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture1DLod[] = + "((function texture1DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture1DProj[] = + "((function texture1DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 P) )\n" + " ((return (tex (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture1DProjLod[] = + "((function texture1DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture2D[] = + "((function texture2D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture2DArray[] = + "((function texture2DArray\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArray sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArray sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture2DArrayLod[] = + "((function texture2DArrayLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArray sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture2DLod[] = + "((function texture2DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture2DProj[] = + "((function texture2DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture2DProjLod[] = + "((function texture2DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture2DRect[] = + "((function texture2DRect\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRect sampler)\n" + " (declare (in) vec2 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture2DRectProj[] = + "((function texture2DRectProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRect sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRect sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture3D[] = + "((function texture3D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture3DLod[] = + "((function texture3DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture3DProj[] = + "((function texture3DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_texture3DProjLod[] = + "((function texture3DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_textureCube[] = + "((function textureCube\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (var_ref P) (0 0 0) 1 () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_textureCubeLod[] = + "((function textureCubeLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_textureGrad[] = + "((function textureGrad\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float P) \n" + " (declare (in) float dPdx) \n" + " (declare (in) float dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1D sampler)\n" + " (declare (in) float P) \n" + " (declare (in) float dPdx) \n" + " (declare (in) float dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1D sampler)\n" + " (declare (in) float P) \n" + " (declare (in) float dPdx) \n" + " (declare (in) float dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) vec2 dPdx) \n" + " (declare (in) vec2 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) vec2 dPdx) \n" + " (declare (in) vec2 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) vec2 dPdx) \n" + " (declare (in) vec2 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) vec3 dPdx) \n" + " (declare (in) vec3 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler3D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) vec3 dPdx) \n" + " (declare (in) vec3 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler3D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) vec3 dPdx) \n" + " (declare (in) vec3 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) vec3 dPdx) \n" + " (declare (in) vec3 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isamplerCube sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) vec3 dPdx) \n" + " (declare (in) vec3 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usamplerCube sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) vec3 dPdx) \n" + " (declare (in) vec3 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArray sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) vec2 dPdx) \n" + " (declare (in) vec2 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1DArray sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) vec2 dPdx) \n" + " (declare (in) vec2 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1DArray sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) vec2 dPdx) \n" + " (declare (in) vec2 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArray sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) vec3 dPdx) \n" + " (declare (in) vec3 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2DArray sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) vec3 dPdx) \n" + " (declare (in) vec3 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2DArray sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) vec3 dPdx) \n" + " (declare (in) vec3 dPdy) )\n" + " ((return (txd (var_ref sampler) (var_ref P) (0 0 0) 1 () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_textureLod[] = + "((function textureLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1D sampler)\n" + " (declare (in) float P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1D sampler)\n" + " (declare (in) float P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler3D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler3D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isamplerCube sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usamplerCube sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArray sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1DArray sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1DArray sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArray sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2DArray sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2DArray sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (var_ref P) (0 0 0) 1 () (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_textureProj[] = + "((function textureProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 P) )\n" + " ((return (tex (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1D sampler)\n" + " (declare (in) vec2 P) )\n" + " ((return (tex (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1D sampler)\n" + " (declare (in) vec2 P) )\n" + " ((return (tex (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1D sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1D sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2D sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2D sampler)\n" + " (declare (in) vec3 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2D sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2D sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler3D sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler3D sampler)\n" + " (declare (in) vec4 P) )\n" + " ((return (tex (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler3D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref bias) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler3D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float bias) )\n" + " ((return (txb (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref bias) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_textureProjGrad[] = + "((function textureProjGrad\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float dPdx) \n" + " (declare (in) float dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float dPdx) \n" + " (declare (in) float dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float dPdx) \n" + " (declare (in) float dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float dPdx) \n" + " (declare (in) float dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float dPdx) \n" + " (declare (in) float dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float dPdx) \n" + " (declare (in) float dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) vec2 dPdx) \n" + " (declare (in) vec2 dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) vec2 dPdx) \n" + " (declare (in) vec2 dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) vec2 dPdx) \n" + " (declare (in) vec2 dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) vec2 dPdx) \n" + " (declare (in) vec2 dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) vec2 dPdx) \n" + " (declare (in) vec2 dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) vec2 dPdx) \n" + " (declare (in) vec2 dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) vec3 dPdx) \n" + " (declare (in) vec3 dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler3D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) vec3 dPdx) \n" + " (declare (in) vec3 dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler3D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) vec3 dPdx) \n" + " (declare (in) vec3 dPdy) )\n" + " ((return (txd (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () ((var_ref dPdx) (var_ref dPdy)) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_textureProjLod[] = + "((function textureProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1D sampler)\n" + " (declare (in) vec2 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz y (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler1D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler1D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz x (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2D sampler)\n" + " (declare (in) vec3 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz z (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler2D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler2D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xy (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature ivec4\n" + " (parameters\n" + " (declare (in) isampler3D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref lod) ))))\n" + "\n" + " (signature uvec4\n" + " (parameters\n" + " (declare (in) usampler3D sampler)\n" + " (declare (in) vec4 P) \n" + " (declare (in) float lod) )\n" + " ((return (txl (var_ref sampler) (swiz xyz (var_ref P)) (0 0 0) (swiz w (var_ref P)) () (var_ref lod) ))))\n" + "\n" + "))\n" + "" +; +static const char builtin_transpose[] = + "((function transpose\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) mat2 m))\n" + " ((declare () mat2 t)\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1)))))\n" + "(return (var_ref t))))\n" + "\n" + " (signature mat3x2\n" + " (parameters\n" + " (declare (in) mat2x3 m))\n" + " ((declare () mat3x2 t)\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1)))))\n" + "(return (var_ref t))))\n" + "\n" + " (signature mat4x2\n" + " (parameters\n" + " (declare (in) mat2x4 m))\n" + " ((declare () mat4x2 t)\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (1)))))\n" + "(return (var_ref t))))\n" + "\n" + " (signature mat2x3\n" + " (parameters\n" + " (declare (in) mat3x2 m))\n" + " ((declare () mat2x3 t)\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2)))))\n" + "(return (var_ref t))))\n" + "\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) mat3 m))\n" + " ((declare () mat3 t)\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (2)))))\n" + "(return (var_ref t))))\n" + "\n" + " (signature mat4x3\n" + " (parameters\n" + " (declare (in) mat3x4 m))\n" + " ((declare () mat4x3 t)\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (2)))))\n" + "(return (var_ref t))))\n" + "\n" + " (signature mat2x4\n" + " (parameters\n" + " (declare (in) mat4x2 m))\n" + " ((declare () mat2x4 t)\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (3)))))\n" + " (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (3)))))\n" + "(return (var_ref t))))\n" + "\n" + " (signature mat3x4\n" + " (parameters\n" + " (declare (in) mat4x3 m))\n" + " ((declare () mat3x4 t)\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (3)))))\n" + " (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (3)))))\n" + " (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (3)))))\n" + "(return (var_ref t))))\n" + "\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) mat4 m))\n" + " ((declare () mat4 t)\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (x) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (0)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (y) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (1)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (z) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (2)))))\n" + " (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (0))) (swiz x (array_ref (var_ref m) (constant int (3)))))\n" + " (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (1))) (swiz y (array_ref (var_ref m) (constant int (3)))))\n" + " (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (2))) (swiz z (array_ref (var_ref m) (constant int (3)))))\n" + " (assign (constant bool (1)) (w) (array_ref (var_ref t) (constant int (3))) (swiz w (array_ref (var_ref m) (constant int (3)))))\n" + "(return (var_ref t))))\n" + ")\n" + "\n" + ")\n" + "\n" + "" +; +static const char builtin_trunc[] = + "((function trunc\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float arg0))\n" + " ((return (expression float trunc (var_ref arg0)))))\n" + "\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 arg0))\n" + " ((return (expression vec2 trunc (var_ref arg0)))))\n" + "\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 arg0))\n" + " ((return (expression vec3 trunc (var_ref arg0)))))\n" + "\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 arg0))\n" + " ((return (expression vec4 trunc (var_ref arg0)))))\n" + "))\n" + "" +; +static const char prototypes_for_100_frag[] = + "(\n" + "(function radians\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float degrees))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 degrees))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 degrees))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 degrees))\n" + " ()))\n" + "(function degrees\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float radians))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 radians))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 radians))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 radians))\n" + " ()))\n" + "(function sin\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function cos\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function tan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function asin\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function acos\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function atan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float y)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float y_over_x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y_over_x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y_over_x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y_over_x))\n" + " ()))\n" + "(function pow\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function exp\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function log\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function exp2\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function log2\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function sqrt\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function inversesqrt\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function abs\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function sign\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function floor\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function ceil\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function fract\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function mod\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function min\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ()))\n" + "(function max\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ()))\n" + "(function clamp\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 minVal)\n" + " (declare (in) vec2 maxVal))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 minVal)\n" + " (declare (in) vec3 maxVal))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 minVal)\n" + " (declare (in) vec4 maxVal))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ()))\n" + "(function mix\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y)\n" + " (declare (in) vec2 a))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y)\n" + " (declare (in) vec3 a))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y)\n" + " (declare (in) vec4 a))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y)\n" + " (declare (in) float a))\n" + " ()))\n" + "(function step\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 edge)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 edge)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 edge)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function smoothstep\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 edge0)\n" + " (declare (in) vec2 edge1)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 edge0)\n" + " (declare (in) vec3 edge1)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 edge0)\n" + " (declare (in) vec4 edge1)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function length\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function distance\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p0)\n" + " (declare (in) float p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 p0)\n" + " (declare (in) vec2 p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 p0)\n" + " (declare (in) vec3 p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 p0)\n" + " (declare (in) vec4 p1))\n" + " ()))\n" + "(function dot\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function cross\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ()))\n" + "(function normalize\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function faceforward\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float N)\n" + " (declare (in) float I)\n" + " (declare (in) float Nref))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 N)\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 Nref))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 N)\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 Nref))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 N)\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 Nref))\n" + " ()))\n" + "(function reflect\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float I)\n" + " (declare (in) float N))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 N))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 N))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 N))\n" + " ()))\n" + "(function refract\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float I)\n" + " (declare (in) float N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 N)\n" + " (declare (in) float eta))\n" + " ()))\n" + "(function matrixCompMult\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) mat2 x)\n" + " (declare (in) mat2 y))\n" + " ())\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) mat3 x)\n" + " (declare (in) mat3 y))\n" + " ())\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) mat4 x)\n" + " (declare (in) mat4 y))\n" + " ()))\n" + "(function lessThan\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function lessThanEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function greaterThan\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function greaterThanEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function equal\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x)\n" + " (declare (in) bvec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x)\n" + " (declare (in) bvec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x)\n" + " (declare (in) bvec4 y))\n" + " ()))\n" + "(function notEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x)\n" + " (declare (in) bvec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x)\n" + " (declare (in) bvec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x)\n" + " (declare (in) bvec4 y))\n" + " ()))\n" + "(function any\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function all\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function not\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function texture2D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function texture2DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float bias))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function textureCube\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float bias))\n" + " ())))" +; +static const char *functions_for_100_frag [] = { + builtin_abs, + builtin_acos, + builtin_all, + builtin_any, + builtin_asin, + builtin_atan, + builtin_ceil, + builtin_clamp, + builtin_cos, + builtin_cross, + builtin_degrees, + builtin_distance, + builtin_dot, + builtin_equal, + builtin_exp, + builtin_exp2, + builtin_faceforward, + builtin_floor, + builtin_fract, + builtin_greaterThan, + builtin_greaterThanEqual, + builtin_inversesqrt, + builtin_length, + builtin_lessThan, + builtin_lessThanEqual, + builtin_log, + builtin_log2, + builtin_matrixCompMult, + builtin_max, + builtin_min, + builtin_mix, + builtin_mod, + builtin_normalize, + builtin_not, + builtin_notEqual, + builtin_pow, + builtin_radians, + builtin_reflect, + builtin_refract, + builtin_sign, + builtin_sin, + builtin_smoothstep, + builtin_sqrt, + builtin_step, + builtin_tan, + builtin_texture2D, + builtin_texture2DProj, + builtin_textureCube, +}; +static const char prototypes_for_100_vert[] = + "(\n" + "(function radians\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float degrees))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 degrees))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 degrees))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 degrees))\n" + " ()))\n" + "(function degrees\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float radians))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 radians))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 radians))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 radians))\n" + " ()))\n" + "(function sin\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function cos\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function tan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function asin\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function acos\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function atan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float y)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float y_over_x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y_over_x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y_over_x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y_over_x))\n" + " ()))\n" + "(function pow\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function exp\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function log\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function exp2\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function log2\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function sqrt\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function inversesqrt\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function abs\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function sign\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function floor\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function ceil\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function fract\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function mod\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function min\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ()))\n" + "(function max\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ()))\n" + "(function clamp\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 minVal)\n" + " (declare (in) vec2 maxVal))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 minVal)\n" + " (declare (in) vec3 maxVal))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 minVal)\n" + " (declare (in) vec4 maxVal))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ()))\n" + "(function mix\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y)\n" + " (declare (in) vec2 a))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y)\n" + " (declare (in) vec3 a))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y)\n" + " (declare (in) vec4 a))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y)\n" + " (declare (in) float a))\n" + " ()))\n" + "(function step\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 edge)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 edge)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 edge)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function smoothstep\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 edge0)\n" + " (declare (in) vec2 edge1)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 edge0)\n" + " (declare (in) vec3 edge1)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 edge0)\n" + " (declare (in) vec4 edge1)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function length\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function distance\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p0)\n" + " (declare (in) float p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 p0)\n" + " (declare (in) vec2 p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 p0)\n" + " (declare (in) vec3 p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 p0)\n" + " (declare (in) vec4 p1))\n" + " ()))\n" + "(function dot\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function cross\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ()))\n" + "(function normalize\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function faceforward\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float N)\n" + " (declare (in) float I)\n" + " (declare (in) float Nref))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 N)\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 Nref))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 N)\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 Nref))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 N)\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 Nref))\n" + " ()))\n" + "(function reflect\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float I)\n" + " (declare (in) float N))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 N))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 N))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 N))\n" + " ()))\n" + "(function refract\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float I)\n" + " (declare (in) float N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 N)\n" + " (declare (in) float eta))\n" + " ()))\n" + "(function matrixCompMult\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) mat2 x)\n" + " (declare (in) mat2 y))\n" + " ())\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) mat3 x)\n" + " (declare (in) mat3 y))\n" + " ())\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) mat4 x)\n" + " (declare (in) mat4 y))\n" + " ()))\n" + "(function lessThan\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function lessThanEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function greaterThan\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function greaterThanEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function equal\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x)\n" + " (declare (in) bvec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x)\n" + " (declare (in) bvec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x)\n" + " (declare (in) bvec4 y))\n" + " ()))\n" + "(function notEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x)\n" + " (declare (in) bvec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x)\n" + " (declare (in) bvec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x)\n" + " (declare (in) bvec4 y))\n" + " ()))\n" + "(function any\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function all\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function not\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function texture2D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 coord))\n" + " ()))\n" + "(function texture2DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 coord))\n" + " ()))\n" + "(function texture2DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function texture2DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float lod))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function textureCube\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 coord))\n" + " ()))\n" + "(function textureCubeLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float lod))\n" + " ())))" +; +static const char *functions_for_100_vert [] = { + builtin_abs, + builtin_acos, + builtin_all, + builtin_any, + builtin_asin, + builtin_atan, + builtin_ceil, + builtin_clamp, + builtin_cos, + builtin_cross, + builtin_degrees, + builtin_distance, + builtin_dot, + builtin_equal, + builtin_exp, + builtin_exp2, + builtin_faceforward, + builtin_floor, + builtin_fract, + builtin_greaterThan, + builtin_greaterThanEqual, + builtin_inversesqrt, + builtin_length, + builtin_lessThan, + builtin_lessThanEqual, + builtin_log, + builtin_log2, + builtin_matrixCompMult, + builtin_max, + builtin_min, + builtin_mix, + builtin_mod, + builtin_normalize, + builtin_not, + builtin_notEqual, + builtin_pow, + builtin_radians, + builtin_reflect, + builtin_refract, + builtin_sign, + builtin_sin, + builtin_smoothstep, + builtin_sqrt, + builtin_step, + builtin_tan, + builtin_texture2D, + builtin_texture2DLod, + builtin_texture2DProj, + builtin_texture2DProjLod, + builtin_textureCube, + builtin_textureCubeLod, +}; +static const char prototypes_for_110_frag[] = + "(\n" + "(function radians\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float degrees))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 degrees))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 degrees))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 degrees))\n" + " ()))\n" + "(function degrees\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float radians))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 radians))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 radians))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 radians))\n" + " ()))\n" + "(function sin\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function cos\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function tan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function asin\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function acos\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function atan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float y)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float y_over_x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y_over_x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y_over_x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y_over_x))\n" + " ()))\n" + "(function pow\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function exp\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function log\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function exp2\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function log2\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function sqrt\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function inversesqrt\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function abs\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function sign\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function floor\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function ceil\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function fract\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function mod\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function min\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ()))\n" + "(function max\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ()))\n" + "(function clamp\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 minVal)\n" + " (declare (in) vec2 maxVal))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 minVal)\n" + " (declare (in) vec3 maxVal))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 minVal)\n" + " (declare (in) vec4 maxVal))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ()))\n" + "(function mix\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y)\n" + " (declare (in) vec2 a))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y)\n" + " (declare (in) vec3 a))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y)\n" + " (declare (in) vec4 a))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y)\n" + " (declare (in) float a))\n" + " ()))\n" + "(function step\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 edge)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 edge)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 edge)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function smoothstep\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 edge0)\n" + " (declare (in) vec2 edge1)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 edge0)\n" + " (declare (in) vec3 edge1)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 edge0)\n" + " (declare (in) vec4 edge1)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function length\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function distance\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p0)\n" + " (declare (in) float p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 p0)\n" + " (declare (in) vec2 p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 p0)\n" + " (declare (in) vec3 p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 p0)\n" + " (declare (in) vec4 p1))\n" + " ()))\n" + "(function dot\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function cross\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ()))\n" + "(function normalize\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function faceforward\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float N)\n" + " (declare (in) float I)\n" + " (declare (in) float Nref))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 N)\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 Nref))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 N)\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 Nref))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 N)\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 Nref))\n" + " ()))\n" + "(function reflect\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float I)\n" + " (declare (in) float N))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 N))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 N))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 N))\n" + " ()))\n" + "(function refract\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float I)\n" + " (declare (in) float N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 N)\n" + " (declare (in) float eta))\n" + " ()))\n" + "(function matrixCompMult\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) mat2 x)\n" + " (declare (in) mat2 y))\n" + " ())\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) mat3 x)\n" + " (declare (in) mat3 y))\n" + " ())\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) mat4 x)\n" + " (declare (in) mat4 y))\n" + " ()))\n" + "(function lessThan\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function lessThanEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function greaterThan\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function greaterThanEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function equal\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x)\n" + " (declare (in) bvec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x)\n" + " (declare (in) bvec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x)\n" + " (declare (in) bvec4 y))\n" + " ()))\n" + "(function notEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x)\n" + " (declare (in) bvec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x)\n" + " (declare (in) bvec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x)\n" + " (declare (in) bvec4 y))\n" + " ()))\n" + "(function any\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function all\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function not\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function texture1D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function texture1DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 coord)\n" + " (declare (in) float bias))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function texture2D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function texture2DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float bias))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function texture3D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function texture3DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function textureCube\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function shadow1D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function shadow2D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function shadow1DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec4 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function shadow2DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec4 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function dFdx\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 p))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 p))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 p))\n" + " ()))\n" + "(function dFdy\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 p))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 p))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 p))\n" + " ()))\n" + "(function fwidth\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 p))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 p))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 p))\n" + " ()))\n" + "(function noise1\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function noise2\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function noise3\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function noise4\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ())))" +; +static const char *functions_for_110_frag [] = { + builtin_abs, + builtin_acos, + builtin_all, + builtin_any, + builtin_asin, + builtin_atan, + builtin_ceil, + builtin_clamp, + builtin_cos, + builtin_cross, + builtin_dFdx, + builtin_dFdy, + builtin_degrees, + builtin_distance, + builtin_dot, + builtin_equal, + builtin_exp, + builtin_exp2, + builtin_faceforward, + builtin_floor, + builtin_fract, + builtin_fwidth, + builtin_greaterThan, + builtin_greaterThanEqual, + builtin_inversesqrt, + builtin_length, + builtin_lessThan, + builtin_lessThanEqual, + builtin_log, + builtin_log2, + builtin_matrixCompMult, + builtin_max, + builtin_min, + builtin_mix, + builtin_mod, + builtin_noise1, + builtin_noise2, + builtin_noise3, + builtin_noise4, + builtin_normalize, + builtin_not, + builtin_notEqual, + builtin_pow, + builtin_radians, + builtin_reflect, + builtin_refract, + builtin_shadow1D, + builtin_shadow1DProj, + builtin_shadow2D, + builtin_shadow2DProj, + builtin_sign, + builtin_sin, + builtin_smoothstep, + builtin_sqrt, + builtin_step, + builtin_tan, + builtin_texture1D, + builtin_texture1DProj, + builtin_texture2D, + builtin_texture2DProj, + builtin_texture3D, + builtin_texture3DProj, + builtin_textureCube, +}; +static const char prototypes_for_110_vert[] = + "(\n" + "(function radians\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float degrees))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 degrees))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 degrees))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 degrees))\n" + " ()))\n" + "(function degrees\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float radians))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 radians))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 radians))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 radians))\n" + " ()))\n" + "(function sin\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function cos\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function tan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function asin\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function acos\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function atan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float y)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float y_over_x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y_over_x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y_over_x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y_over_x))\n" + " ()))\n" + "(function pow\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function exp\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function log\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function exp2\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function log2\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function sqrt\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function inversesqrt\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function abs\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function sign\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function floor\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function ceil\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function fract\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function mod\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function min\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ()))\n" + "(function max\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ()))\n" + "(function clamp\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 minVal)\n" + " (declare (in) vec2 maxVal))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 minVal)\n" + " (declare (in) vec3 maxVal))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 minVal)\n" + " (declare (in) vec4 maxVal))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ()))\n" + "(function mix\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y)\n" + " (declare (in) vec2 a))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y)\n" + " (declare (in) vec3 a))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y)\n" + " (declare (in) vec4 a))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y)\n" + " (declare (in) float a))\n" + " ()))\n" + "(function step\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 edge)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 edge)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 edge)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function smoothstep\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 edge0)\n" + " (declare (in) vec2 edge1)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 edge0)\n" + " (declare (in) vec3 edge1)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 edge0)\n" + " (declare (in) vec4 edge1)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function length\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function distance\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p0)\n" + " (declare (in) float p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 p0)\n" + " (declare (in) vec2 p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 p0)\n" + " (declare (in) vec3 p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 p0)\n" + " (declare (in) vec4 p1))\n" + " ()))\n" + "(function dot\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function cross\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ()))\n" + "(function normalize\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function ftransform\n" + " (signature vec4\n" + " (parameters)\n" + " ()))\n" + "(function faceforward\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float N)\n" + " (declare (in) float I)\n" + " (declare (in) float Nref))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 N)\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 Nref))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 N)\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 Nref))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 N)\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 Nref))\n" + " ()))\n" + "(function reflect\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float I)\n" + " (declare (in) float N))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 N))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 N))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 N))\n" + " ()))\n" + "(function refract\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float I)\n" + " (declare (in) float N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 N)\n" + " (declare (in) float eta))\n" + " ()))\n" + "(function matrixCompMult\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) mat2 x)\n" + " (declare (in) mat2 y))\n" + " ())\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) mat3 x)\n" + " (declare (in) mat3 y))\n" + " ())\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) mat4 x)\n" + " (declare (in) mat4 y))\n" + " ()))\n" + "(function lessThan\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function lessThanEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function greaterThan\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function greaterThanEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function equal\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x)\n" + " (declare (in) bvec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x)\n" + " (declare (in) bvec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x)\n" + " (declare (in) bvec4 y))\n" + " ()))\n" + "(function notEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x)\n" + " (declare (in) bvec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x)\n" + " (declare (in) bvec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x)\n" + " (declare (in) bvec4 y))\n" + " ()))\n" + "(function any\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function all\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function not\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function texture1D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float coord))\n" + " ()))\n" + "(function texture1DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 coord))\n" + " ()))\n" + "(function texture1DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function texture1DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 coord)\n" + " (declare (in) float lod))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function texture2D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 coord))\n" + " ()))\n" + "(function texture2DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 coord))\n" + " ()))\n" + "(function texture2DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function texture2DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float lod))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function texture3D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 coord))\n" + " ()))\n" + "(function texture3DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 coord))\n" + " ()))\n" + "(function texture3DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function texture3DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function textureCube\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 coord))\n" + " ()))\n" + "(function textureCubeLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function shadow1D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec3 coord))\n" + " ()))\n" + "(function shadow2D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec3 coord))\n" + " ()))\n" + "(function shadow1DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec4 coord))\n" + " ()))\n" + "(function shadow2DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec4 coord))\n" + " ()))\n" + "(function shadow1DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function shadow2DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function shadow1DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function shadow2DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function noise1\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function noise2\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function noise3\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function noise4\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ())))" +; +static const char *functions_for_110_vert [] = { + builtin_abs, + builtin_acos, + builtin_all, + builtin_any, + builtin_asin, + builtin_atan, + builtin_ceil, + builtin_clamp, + builtin_cos, + builtin_cross, + builtin_degrees, + builtin_distance, + builtin_dot, + builtin_equal, + builtin_exp, + builtin_exp2, + builtin_faceforward, + builtin_floor, + builtin_fract, + builtin_ftransform, + builtin_greaterThan, + builtin_greaterThanEqual, + builtin_inversesqrt, + builtin_length, + builtin_lessThan, + builtin_lessThanEqual, + builtin_log, + builtin_log2, + builtin_matrixCompMult, + builtin_max, + builtin_min, + builtin_mix, + builtin_mod, + builtin_noise1, + builtin_noise2, + builtin_noise3, + builtin_noise4, + builtin_normalize, + builtin_not, + builtin_notEqual, + builtin_pow, + builtin_radians, + builtin_reflect, + builtin_refract, + builtin_shadow1D, + builtin_shadow1DLod, + builtin_shadow1DProj, + builtin_shadow1DProjLod, + builtin_shadow2D, + builtin_shadow2DLod, + builtin_shadow2DProj, + builtin_shadow2DProjLod, + builtin_sign, + builtin_sin, + builtin_smoothstep, + builtin_sqrt, + builtin_step, + builtin_tan, + builtin_texture1D, + builtin_texture1DLod, + builtin_texture1DProj, + builtin_texture1DProjLod, + builtin_texture2D, + builtin_texture2DLod, + builtin_texture2DProj, + builtin_texture2DProjLod, + builtin_texture3D, + builtin_texture3DLod, + builtin_texture3DProj, + builtin_texture3DProjLod, + builtin_textureCube, + builtin_textureCubeLod, +}; +static const char prototypes_for_120_frag[] = + "(\n" + "(function radians\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float degrees))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 degrees))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 degrees))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 degrees))\n" + " ()))\n" + "(function degrees\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float radians))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 radians))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 radians))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 radians))\n" + " ()))\n" + "(function sin\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function cos\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function tan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function asin\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function acos\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function atan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float y)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float y_over_x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y_over_x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y_over_x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y_over_x))\n" + " ()))\n" + "(function pow\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function exp\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function log\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function exp2\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function log2\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function sqrt\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function inversesqrt\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function abs\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function sign\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function floor\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function ceil\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function fract\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function mod\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function min\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ()))\n" + "(function max\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ()))\n" + "(function clamp\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 minVal)\n" + " (declare (in) vec2 maxVal))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 minVal)\n" + " (declare (in) vec3 maxVal))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 minVal)\n" + " (declare (in) vec4 maxVal))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ()))\n" + "(function mix\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y)\n" + " (declare (in) vec2 a))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y)\n" + " (declare (in) vec3 a))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y)\n" + " (declare (in) vec4 a))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y)\n" + " (declare (in) float a))\n" + " ()))\n" + "(function step\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 edge)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 edge)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 edge)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function smoothstep\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 edge0)\n" + " (declare (in) vec2 edge1)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 edge0)\n" + " (declare (in) vec3 edge1)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 edge0)\n" + " (declare (in) vec4 edge1)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function length\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function distance\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p0)\n" + " (declare (in) float p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 p0)\n" + " (declare (in) vec2 p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 p0)\n" + " (declare (in) vec3 p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 p0)\n" + " (declare (in) vec4 p1))\n" + " ()))\n" + "(function dot\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function cross\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ()))\n" + "(function normalize\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function faceforward\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float N)\n" + " (declare (in) float I)\n" + " (declare (in) float Nref))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 N)\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 Nref))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 N)\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 Nref))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 N)\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 Nref))\n" + " ()))\n" + "(function reflect\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float I)\n" + " (declare (in) float N))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 N))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 N))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 N))\n" + " ()))\n" + "(function refract\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float I)\n" + " (declare (in) float N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 N)\n" + " (declare (in) float eta))\n" + " ()))\n" + "(function matrixCompMult\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) mat2 x)\n" + " (declare (in) mat2 y))\n" + " ())\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) mat3 x)\n" + " (declare (in) mat3 y))\n" + " ())\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) mat4 x)\n" + " (declare (in) mat4 y))\n" + " ())\n" + " (signature mat2x3\n" + " (parameters\n" + " (declare (in) mat2x3 x)\n" + " (declare (in) mat2x3 y))\n" + " ())\n" + " (signature mat2x4\n" + " (parameters\n" + " (declare (in) mat2x4 x)\n" + " (declare (in) mat2x4 y))\n" + " ())\n" + " (signature mat3x2\n" + " (parameters\n" + " (declare (in) mat3x2 x)\n" + " (declare (in) mat3x2 y))\n" + " ())\n" + " (signature mat3x4\n" + " (parameters\n" + " (declare (in) mat3x4 x)\n" + " (declare (in) mat3x4 y))\n" + " ())\n" + " (signature mat4x2\n" + " (parameters\n" + " (declare (in) mat4x2 x)\n" + " (declare (in) mat4x2 y))\n" + " ())\n" + " (signature mat4x3\n" + " (parameters\n" + " (declare (in) mat4x3 x)\n" + " (declare (in) mat4x3 y))\n" + " ()))\n" + "(function outerProduct\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) vec2 c)\n" + " (declare (in) vec2 r))\n" + " ())\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) vec3 c)\n" + " (declare (in) vec3 r))\n" + " ())\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) vec4 c)\n" + " (declare (in) vec4 r))\n" + " ())\n" + " (signature mat2x3\n" + " (parameters\n" + " (declare (in) vec3 c)\n" + " (declare (in) vec2 r))\n" + " ())\n" + " (signature mat3x2\n" + " (parameters\n" + " (declare (in) vec2 c)\n" + " (declare (in) vec3 r))\n" + " ())\n" + " (signature mat2x4\n" + " (parameters\n" + " (declare (in) vec4 c)\n" + " (declare (in) vec2 r))\n" + " ())\n" + " (signature mat4x2\n" + " (parameters\n" + " (declare (in) vec2 c)\n" + " (declare (in) vec4 r))\n" + " ())\n" + " (signature mat3x4\n" + " (parameters\n" + " (declare (in) vec4 c)\n" + " (declare (in) vec3 r))\n" + " ())\n" + " (signature mat4x3\n" + " (parameters\n" + " (declare (in) vec3 c)\n" + " (declare (in) vec4 r))\n" + " ()))\n" + "(function transpose\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) mat2 m))\n" + " ())\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) mat3 m))\n" + " ())\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) mat4 m))\n" + " ())\n" + " (signature mat2x3\n" + " (parameters\n" + " (declare (in) mat3x2 m))\n" + " ())\n" + " (signature mat3x2\n" + " (parameters\n" + " (declare (in) mat2x3 m))\n" + " ())\n" + " (signature mat2x4\n" + " (parameters\n" + " (declare (in) mat4x2 m))\n" + " ())\n" + " (signature mat4x2\n" + " (parameters\n" + " (declare (in) mat2x4 m))\n" + " ())\n" + " (signature mat3x4\n" + " (parameters\n" + " (declare (in) mat4x3 m))\n" + " ())\n" + " (signature mat4x3\n" + " (parameters\n" + " (declare (in) mat3x4 m))\n" + " ()))\n" + "(function lessThan\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function lessThanEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function greaterThan\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function greaterThanEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function equal\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x)\n" + " (declare (in) bvec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x)\n" + " (declare (in) bvec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x)\n" + " (declare (in) bvec4 y))\n" + " ()))\n" + "(function notEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x)\n" + " (declare (in) bvec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x)\n" + " (declare (in) bvec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x)\n" + " (declare (in) bvec4 y))\n" + " ()))\n" + "(function any\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function all\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function not\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function texture1D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function texture1DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 coord)\n" + " (declare (in) float bias))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function texture2D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function texture2DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float bias))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function texture3D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function texture3DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function textureCube\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function shadow1D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function shadow2D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function shadow1DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec4 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function shadow2DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec4 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function dFdx\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 p))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 p))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 p))\n" + " ()))\n" + "(function dFdy\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 p))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 p))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 p))\n" + " ()))\n" + "(function fwidth\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 p))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 p))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 p))\n" + " ()))\n" + "(function noise1\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function noise2\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function noise3\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function noise4\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ())))" +; +static const char *functions_for_120_frag [] = { + builtin_abs, + builtin_acos, + builtin_all, + builtin_any, + builtin_asin, + builtin_atan, + builtin_ceil, + builtin_clamp, + builtin_cos, + builtin_cross, + builtin_dFdx, + builtin_dFdy, + builtin_degrees, + builtin_distance, + builtin_dot, + builtin_equal, + builtin_exp, + builtin_exp2, + builtin_faceforward, + builtin_floor, + builtin_fract, + builtin_fwidth, + builtin_greaterThan, + builtin_greaterThanEqual, + builtin_inversesqrt, + builtin_length, + builtin_lessThan, + builtin_lessThanEqual, + builtin_log, + builtin_log2, + builtin_matrixCompMult, + builtin_max, + builtin_min, + builtin_mix, + builtin_mod, + builtin_noise1, + builtin_noise2, + builtin_noise3, + builtin_noise4, + builtin_normalize, + builtin_not, + builtin_notEqual, + builtin_outerProduct, + builtin_pow, + builtin_radians, + builtin_reflect, + builtin_refract, + builtin_shadow1D, + builtin_shadow1DProj, + builtin_shadow2D, + builtin_shadow2DProj, + builtin_sign, + builtin_sin, + builtin_smoothstep, + builtin_sqrt, + builtin_step, + builtin_tan, + builtin_texture1D, + builtin_texture1DProj, + builtin_texture2D, + builtin_texture2DProj, + builtin_texture3D, + builtin_texture3DProj, + builtin_textureCube, + builtin_transpose, +}; +static const char prototypes_for_120_vert[] = + "(\n" + "(function radians\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float degrees))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 degrees))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 degrees))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 degrees))\n" + " ()))\n" + "(function degrees\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float radians))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 radians))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 radians))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 radians))\n" + " ()))\n" + "(function sin\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function cos\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function tan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function asin\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function acos\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float angle))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 angle))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 angle))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 angle))\n" + " ()))\n" + "(function atan\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float y)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float y_over_x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 y_over_x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 y_over_x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 y_over_x))\n" + " ()))\n" + "(function pow\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function exp\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function log\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function exp2\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function log2\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function sqrt\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function inversesqrt\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function abs\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function sign\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function floor\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function ceil\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function fract\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function mod\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function min\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ()))\n" + "(function max\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float y))\n" + " ()))\n" + "(function clamp\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 minVal)\n" + " (declare (in) vec2 maxVal))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 minVal)\n" + " (declare (in) vec3 maxVal))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 minVal)\n" + " (declare (in) vec4 maxVal))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) float minVal)\n" + " (declare (in) float maxVal))\n" + " ()))\n" + "(function mix\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y)\n" + " (declare (in) vec2 a))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y)\n" + " (declare (in) vec3 a))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y)\n" + " (declare (in) vec4 a))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y)\n" + " (declare (in) float a))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y)\n" + " (declare (in) float a))\n" + " ()))\n" + "(function step\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 edge)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 edge)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 edge)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float edge)\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function smoothstep\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 edge0)\n" + " (declare (in) vec2 edge1)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 edge0)\n" + " (declare (in) vec3 edge1)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 edge0)\n" + " (declare (in) vec4 edge1)\n" + " (declare (in) vec4 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float edge0)\n" + " (declare (in) float edge1)\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function length\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function distance\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float p0)\n" + " (declare (in) float p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 p0)\n" + " (declare (in) vec2 p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 p0)\n" + " (declare (in) vec3 p1))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 p0)\n" + " (declare (in) vec4 p1))\n" + " ()))\n" + "(function dot\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x)\n" + " (declare (in) float y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ()))\n" + "(function cross\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ()))\n" + "(function normalize\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function ftransform\n" + " (signature vec4\n" + " (parameters)\n" + " ()))\n" + "(function faceforward\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float N)\n" + " (declare (in) float I)\n" + " (declare (in) float Nref))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 N)\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 Nref))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 N)\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 Nref))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 N)\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 Nref))\n" + " ()))\n" + "(function reflect\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float I)\n" + " (declare (in) float N))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 N))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 N))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 N))\n" + " ()))\n" + "(function refract\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float I)\n" + " (declare (in) float N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 I)\n" + " (declare (in) vec2 N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 I)\n" + " (declare (in) vec3 N)\n" + " (declare (in) float eta))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 I)\n" + " (declare (in) vec4 N)\n" + " (declare (in) float eta))\n" + " ()))\n" + "(function matrixCompMult\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) mat2 x)\n" + " (declare (in) mat2 y))\n" + " ())\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) mat3 x)\n" + " (declare (in) mat3 y))\n" + " ())\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) mat4 x)\n" + " (declare (in) mat4 y))\n" + " ())\n" + " (signature mat2x3\n" + " (parameters\n" + " (declare (in) mat2x3 x)\n" + " (declare (in) mat2x3 y))\n" + " ())\n" + " (signature mat2x4\n" + " (parameters\n" + " (declare (in) mat2x4 x)\n" + " (declare (in) mat2x4 y))\n" + " ())\n" + " (signature mat3x2\n" + " (parameters\n" + " (declare (in) mat3x2 x)\n" + " (declare (in) mat3x2 y))\n" + " ())\n" + " (signature mat3x4\n" + " (parameters\n" + " (declare (in) mat3x4 x)\n" + " (declare (in) mat3x4 y))\n" + " ())\n" + " (signature mat4x2\n" + " (parameters\n" + " (declare (in) mat4x2 x)\n" + " (declare (in) mat4x2 y))\n" + " ())\n" + " (signature mat4x3\n" + " (parameters\n" + " (declare (in) mat4x3 x)\n" + " (declare (in) mat4x3 y))\n" + " ()))\n" + "(function outerProduct\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) vec2 c)\n" + " (declare (in) vec2 r))\n" + " ())\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) vec3 c)\n" + " (declare (in) vec3 r))\n" + " ())\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) vec4 c)\n" + " (declare (in) vec4 r))\n" + " ())\n" + " (signature mat2x3\n" + " (parameters\n" + " (declare (in) vec3 c)\n" + " (declare (in) vec2 r))\n" + " ())\n" + " (signature mat3x2\n" + " (parameters\n" + " (declare (in) vec2 c)\n" + " (declare (in) vec3 r))\n" + " ())\n" + " (signature mat2x4\n" + " (parameters\n" + " (declare (in) vec4 c)\n" + " (declare (in) vec2 r))\n" + " ())\n" + " (signature mat4x2\n" + " (parameters\n" + " (declare (in) vec2 c)\n" + " (declare (in) vec4 r))\n" + " ())\n" + " (signature mat3x4\n" + " (parameters\n" + " (declare (in) vec4 c)\n" + " (declare (in) vec3 r))\n" + " ())\n" + " (signature mat4x3\n" + " (parameters\n" + " (declare (in) vec3 c)\n" + " (declare (in) vec4 r))\n" + " ()))\n" + "(function transpose\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) mat2 m))\n" + " ())\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) mat3 m))\n" + " ())\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) mat4 m))\n" + " ())\n" + " (signature mat2x3\n" + " (parameters\n" + " (declare (in) mat3x2 m))\n" + " ())\n" + " (signature mat3x2\n" + " (parameters\n" + " (declare (in) mat2x3 m))\n" + " ())\n" + " (signature mat2x4\n" + " (parameters\n" + " (declare (in) mat4x2 m))\n" + " ())\n" + " (signature mat4x2\n" + " (parameters\n" + " (declare (in) mat2x4 m))\n" + " ())\n" + " (signature mat3x4\n" + " (parameters\n" + " (declare (in) mat4x3 m))\n" + " ())\n" + " (signature mat4x3\n" + " (parameters\n" + " (declare (in) mat3x4 m))\n" + " ()))\n" + "(function lessThan\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function lessThanEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function greaterThan\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function greaterThanEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ()))\n" + "(function equal\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x)\n" + " (declare (in) bvec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x)\n" + " (declare (in) bvec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x)\n" + " (declare (in) bvec4 y))\n" + " ()))\n" + "(function notEqual\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) vec2 x)\n" + " (declare (in) vec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) vec3 x)\n" + " (declare (in) vec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) vec4 x)\n" + " (declare (in) vec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) ivec2 x)\n" + " (declare (in) ivec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) ivec3 x)\n" + " (declare (in) ivec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) ivec4 x)\n" + " (declare (in) ivec4 y))\n" + " ())\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x)\n" + " (declare (in) bvec2 y))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x)\n" + " (declare (in) bvec3 y))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x)\n" + " (declare (in) bvec4 y))\n" + " ()))\n" + "(function any\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function all\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bool\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function not\n" + " (signature bvec2\n" + " (parameters\n" + " (declare (in) bvec2 x))\n" + " ())\n" + " (signature bvec3\n" + " (parameters\n" + " (declare (in) bvec3 x))\n" + " ())\n" + " (signature bvec4\n" + " (parameters\n" + " (declare (in) bvec4 x))\n" + " ()))\n" + "(function texture1D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float coord))\n" + " ()))\n" + "(function texture1DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 coord))\n" + " ()))\n" + "(function texture1DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) float coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function texture1DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec2 coord)\n" + " (declare (in) float lod))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1D sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function texture2D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 coord))\n" + " ()))\n" + "(function texture2DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 coord))\n" + " ()))\n" + "(function texture2DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec2 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function texture2DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float lod))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2D sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function texture3D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 coord))\n" + " ()))\n" + "(function texture3DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 coord))\n" + " ()))\n" + "(function texture3DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function texture3DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler3D sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function textureCube\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 coord))\n" + " ()))\n" + "(function textureCubeLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) samplerCube sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function shadow1D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec3 coord))\n" + " ()))\n" + "(function shadow2D\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec3 coord))\n" + " ()))\n" + "(function shadow1DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec4 coord))\n" + " ()))\n" + "(function shadow2DProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec4 coord))\n" + " ()))\n" + "(function shadow1DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function shadow2DLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function shadow1DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DShadow sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function shadow2DProjLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DShadow sampler)\n" + " (declare (in) vec4 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function noise1\n" + " (signature float\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature float\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function noise2\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec2\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function noise3\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec3\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ()))\n" + "(function noise4\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) float x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec2 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec3 x))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) vec4 x))\n" + " ())))" +; +static const char *functions_for_120_vert [] = { + builtin_abs, + builtin_acos, + builtin_all, + builtin_any, + builtin_asin, + builtin_atan, + builtin_ceil, + builtin_clamp, + builtin_cos, + builtin_cross, + builtin_degrees, + builtin_distance, + builtin_dot, + builtin_equal, + builtin_exp, + builtin_exp2, + builtin_faceforward, + builtin_floor, + builtin_fract, + builtin_ftransform, + builtin_greaterThan, + builtin_greaterThanEqual, + builtin_inversesqrt, + builtin_length, + builtin_lessThan, + builtin_lessThanEqual, + builtin_log, + builtin_log2, + builtin_matrixCompMult, + builtin_max, + builtin_min, + builtin_mix, + builtin_mod, + builtin_noise1, + builtin_noise2, + builtin_noise3, + builtin_noise4, + builtin_normalize, + builtin_not, + builtin_notEqual, + builtin_outerProduct, + builtin_pow, + builtin_radians, + builtin_reflect, + builtin_refract, + builtin_shadow1D, + builtin_shadow1DLod, + builtin_shadow1DProj, + builtin_shadow1DProjLod, + builtin_shadow2D, + builtin_shadow2DLod, + builtin_shadow2DProj, + builtin_shadow2DProjLod, + builtin_sign, + builtin_sin, + builtin_smoothstep, + builtin_sqrt, + builtin_step, + builtin_tan, + builtin_texture1D, + builtin_texture1DLod, + builtin_texture1DProj, + builtin_texture1DProjLod, + builtin_texture2D, + builtin_texture2DLod, + builtin_texture2DProj, + builtin_texture2DProjLod, + builtin_texture3D, + builtin_texture3DLod, + builtin_texture3DProj, + builtin_texture3DProjLod, + builtin_textureCube, + builtin_textureCubeLod, + builtin_transpose, +}; +static const char prototypes_for_130_frag[] = +{'(', +'(','f','u','n','c','t','i','o','n',' ','r','a','d','i','a','n','s',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','e','g','r','e','e','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','e','g','r','e','e','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','e','g','r','e','e','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','d','e','g','r','e','e','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','d','e','g','r','e','e','s',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','r','a','d','i','a','n','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','r','a','d','i','a','n','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','r','a','d','i','a','n','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','r','a','d','i','a','n','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','i','n',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','a','n','g','l','e',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','c','o','s',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','a','n','g','l','e',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','a','n',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','a','n','g','l','e',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','s','i','n',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','a','n','g','l','e',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','c','o','s',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','a','n','g','l','e',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','t','a','n',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y','_','o','v','e','r','_','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y','_','o','v','e','r','_','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y','_','o','v','e','r','_','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y','_','o','v','e','r','_','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','i','n','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','c','o','s','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','a','n','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','s','i','n','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','c','o','s','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','t','a','n','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','p','o','w',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','e','x','p',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','l','o','g',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','e','x','p','2',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','l','o','g','2',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','q','r','t',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','i','n','v','e','r','s','e','s','q','r','t',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','b','s',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','i','g','n',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','f','l','o','o','r',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','r','u','n','c',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','r','o','u','n','d',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','r','o','u','n','d','E','v','e','n',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','c','e','i','l',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','f','r','a','c','t',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','m','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','m','o','d','f',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','o','u','t',')',' ','f','l','o','a','t',' ','i',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','o','u','t',')',' ','v','e','c','2',' ','i',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','o','u','t',')',' ','v','e','c','3',' ','i',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','o','u','t',')',' ','v','e','c','4',' ','i',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','m','i','n',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','m','a','x',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','c','l','a','m','p',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','m','i','x',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','t','e','p',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','e','d','g','e',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','e','d','g','e',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','e','d','g','e',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','m','o','o','t','h','s','t','e','p',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','1',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','e','d','g','e','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','e','d','g','e','1',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','e','d','g','e','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','e','d','g','e','1',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','e','d','g','e','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','e','d','g','e','1',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','1',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','1',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','1',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','l','e','n','g','t','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','d','i','s','t','a','n','c','e',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','p','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','p','1',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','p','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','p','1',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','p','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','p','1',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','p','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','p','1',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','d','o','t',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','c','r','o','s','s',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','n','o','r','m','a','l','i','z','e',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','f','a','c','e','f','o','r','w','a','r','d',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','N','r','e','f',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','N','r','e','f',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','N','r','e','f',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','N','r','e','f',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','r','e','f','l','e','c','t',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','N',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','N',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','N',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','N',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','r','e','f','r','a','c','t',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','t','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','t','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','t','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','t','a',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','m','a','t','r','i','x','C','o','m','p','M','u','l','t',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2','x','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2','x','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2','x','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2','x','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2','x','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2','x','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3','x','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3','x','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3','x','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3','x','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3','x','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3','x','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4','x','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4','x','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4','x','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4','x','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4','x','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4','x','3',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','o','u','t','e','r','P','r','o','d','u','c','t',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2','x','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3','x','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2','x','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4','x','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3','x','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4','x','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','r',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','r','a','n','s','p','o','s','e',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2','x','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3','x','2',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3','x','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2','x','3',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2','x','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4','x','2',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4','x','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2','x','4',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3','x','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4','x','3',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4','x','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3','x','4',' ','m',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','l','e','s','s','T','h','a','n',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','l','e','s','s','T','h','a','n','E','q','u','a','l',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','g','r','e','a','t','e','r','T','h','a','n',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','g','r','e','a','t','e','r','T','h','a','n','E','q','u','a','l',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','e','q','u','a','l',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','n','o','t','E','q','u','a','l',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','n','y',' ','(','s','i','g','n','a','t','u','r','e',' ','b','o','o','l',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','o','o','l',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','o','o','l',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','l','l',' ','(','s','i','g','n','a','t','u','r','e',' ','b','o','o','l',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','o','o','l',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','o','o','l',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','n','o','t',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','A','r','r','a','y','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','P','r','o','j',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','e','l','F','e','t','c','h',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','P','r','o','j','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','G','r','a','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','A','r','r','a','y','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','P','r','o','j','G','r','a','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','1','D',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','1','D','P','r','o','j',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','1','D','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','1','D','P','r','o','j','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','2','D',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','2','D','P','r','o','j',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','2','D','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','2','D','P','r','o','j','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','3','D',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','3','D','P','r','o','j',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','3','D','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','3','D','P','r','o','j','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','C','u','b','e',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','C','u','b','e','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','1','D',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','2','D',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','1','D','P','r','o','j',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','2','D','P','r','o','j',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','1','D','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','2','D','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','1','D','P','r','o','j','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','2','D','P','r','o','j','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','d','F','d','x',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','p',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','p',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','p',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','p',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','d','F','d','y',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','p',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','p',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','p',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','p',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','f','w','i','d','t','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','p',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','p',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','p',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','p',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','n','o','i','s','e','1',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','n','o','i','s','e','2',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','n','o','i','s','e','3',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','n','o','i','s','e','4',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')',')'} ; +static const char *functions_for_130_frag [] = { + builtin_abs, + builtin_acos, + builtin_acosh, + builtin_all, + builtin_any, + builtin_asin, + builtin_asinh, + builtin_atan, + builtin_atanh, + builtin_ceil, + builtin_clamp, + builtin_cos, + builtin_cosh, + builtin_cross, + builtin_dFdx, + builtin_dFdy, + builtin_degrees, + builtin_distance, + builtin_dot, + builtin_equal, + builtin_exp, + builtin_exp2, + builtin_faceforward, + builtin_floor, + builtin_fract, + builtin_fwidth, + builtin_greaterThan, + builtin_greaterThanEqual, + builtin_inversesqrt, + builtin_length, + builtin_lessThan, + builtin_lessThanEqual, + builtin_log, + builtin_log2, + builtin_matrixCompMult, + builtin_max, + builtin_min, + builtin_mix, + builtin_mod, + builtin_modf, + builtin_noise1, + builtin_noise2, + builtin_noise3, + builtin_noise4, + builtin_normalize, + builtin_not, + builtin_notEqual, + builtin_outerProduct, + builtin_pow, + builtin_radians, + builtin_reflect, + builtin_refract, + builtin_round, + builtin_roundEven, + builtin_shadow1D, + builtin_shadow1DLod, + builtin_shadow1DProj, + builtin_shadow1DProjLod, + builtin_shadow2D, + builtin_shadow2DLod, + builtin_shadow2DProj, + builtin_shadow2DProjLod, + builtin_sign, + builtin_sin, + builtin_sinh, + builtin_smoothstep, + builtin_sqrt, + builtin_step, + builtin_tan, + builtin_tanh, + builtin_texelFetch, + builtin_texture, + builtin_texture1D, + builtin_texture1DLod, + builtin_texture1DProj, + builtin_texture1DProjLod, + builtin_texture2D, + builtin_texture2DLod, + builtin_texture2DProj, + builtin_texture2DProjLod, + builtin_texture3D, + builtin_texture3DLod, + builtin_texture3DProj, + builtin_texture3DProjLod, + builtin_textureCube, + builtin_textureCubeLod, + builtin_textureGrad, + builtin_textureLod, + builtin_textureProj, + builtin_textureProjGrad, + builtin_textureProjLod, + builtin_transpose, + builtin_trunc, +}; +static const char prototypes_for_130_vert[] = +{'(', +'(','f','u','n','c','t','i','o','n',' ','r','a','d','i','a','n','s',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','e','g','r','e','e','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','e','g','r','e','e','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','e','g','r','e','e','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','d','e','g','r','e','e','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','d','e','g','r','e','e','s',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','r','a','d','i','a','n','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','r','a','d','i','a','n','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','r','a','d','i','a','n','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','r','a','d','i','a','n','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','i','n',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','a','n','g','l','e',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','c','o','s',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','a','n','g','l','e',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','a','n',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','a','n','g','l','e',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','s','i','n',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','a','n','g','l','e',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','c','o','s',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','a','n','g','l','e',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','a','n','g','l','e',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','t','a','n',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y','_','o','v','e','r','_','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y','_','o','v','e','r','_','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y','_','o','v','e','r','_','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y','_','o','v','e','r','_','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','i','n','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','c','o','s','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','a','n','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','s','i','n','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','c','o','s','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','t','a','n','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','p','o','w',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','e','x','p',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','l','o','g',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','e','x','p','2',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','l','o','g','2',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','q','r','t',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','i','n','v','e','r','s','e','s','q','r','t',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','b','s',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','i','g','n',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','f','l','o','o','r',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','r','u','n','c',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','r','o','u','n','d',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','r','o','u','n','d','E','v','e','n',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','c','e','i','l',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','f','r','a','c','t',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','m','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','m','o','d','f',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','o','u','t',')',' ','f','l','o','a','t',' ','i',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','o','u','t',')',' ','v','e','c','2',' ','i',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','o','u','t',')',' ','v','e','c','3',' ','i',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','o','u','t',')',' ','v','e','c','4',' ','i',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','m','i','n',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','m','a','x',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','c','l','a','m','p',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','i','n','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','i','n','V','a','l',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','i','n','t',' ','m','a','x','V','a','l',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','m','i','x',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','a',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','t','e','p',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','e','d','g','e',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','e','d','g','e',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','e','d','g','e',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','m','o','o','t','h','s','t','e','p',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','1',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','e','d','g','e','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','e','d','g','e','1',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','e','d','g','e','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','e','d','g','e','1',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','e','d','g','e','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','e','d','g','e','1',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','1',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','1',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','d','g','e','1',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','l','e','n','g','t','h',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','d','i','s','t','a','n','c','e',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','p','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','p','1',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','p','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','p','1',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','p','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','p','1',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','p','0',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','p','1',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','d','o','t',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','c','r','o','s','s',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','n','o','r','m','a','l','i','z','e',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','f','t','r','a','n','s','f','o','r','m',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','f','a','c','e','f','o','r','w','a','r','d',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','N','r','e','f',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','N','r','e','f',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','N','r','e','f',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','N','r','e','f',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','r','e','f','l','e','c','t',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','N',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','N',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','N',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','N',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','r','e','f','r','a','c','t',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','t','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','t','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','t','a',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','I',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','N',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','e','t','a',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','m','a','t','r','i','x','C','o','m','p','M','u','l','t',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2','x','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2','x','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2','x','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2','x','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2','x','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2','x','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3','x','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3','x','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3','x','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3','x','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3','x','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3','x','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4','x','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4','x','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4','x','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4','x','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4','x','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4','x','3',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','o','u','t','e','r','P','r','o','d','u','c','t',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2','x','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3','x','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2','x','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4','x','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3','x','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','r',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4','x','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','r',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','r','a','n','s','p','o','s','e',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2','x','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3','x','2',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3','x','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2','x','3',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','2','x','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4','x','2',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4','x','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','2','x','4',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','3','x','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','4','x','3',' ','m',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','m','a','t','4','x','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','m','a','t','3','x','4',' ','m',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','l','e','s','s','T','h','a','n',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','l','e','s','s','T','h','a','n','E','q','u','a','l',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','g','r','e','a','t','e','r','T','h','a','n',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','g','r','e','a','t','e','r','T','h','a','n','E','q','u','a','l',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','e','q','u','a','l',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','n','o','t','E','q','u','a','l',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','v','e','c','4',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','2',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','2',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','3',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','3',' ','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','4',' ','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','4',' ','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','n','y',' ','(','s','i','g','n','a','t','u','r','e',' ','b','o','o','l',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','o','o','l',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','o','o','l',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','a','l','l',' ','(','s','i','g','n','a','t','u','r','e',' ','b','o','o','l',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','o','o','l',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','o','o','l',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','n','o','t',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','b','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','b','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','A','r','r','a','y','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','P','r','o','j',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','e','l','F','e','t','c','h',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','n','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','P','r','o','j','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','G','r','a','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D','A','r','r','a','y',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','A','r','r','a','y','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','A','r','r','a','y','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','P','r','o','j','G','r','a','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','i','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','i','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','u','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','u','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','d','P','d','y',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','P',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','x',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','d','P','d','y',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','1','D',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','1','D','P','r','o','j',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','1','D','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','1','D','P','r','o','j','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','2','D',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','2','D','P','r','o','j',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','2','D','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','2','D','P','r','o','j','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','3','D',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','3','D','P','r','o','j',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','3','D','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','3','D','P','r','o','j','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','3','D',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','C','u','b','e',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','t','e','x','t','u','r','e','C','u','b','e','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','C','u','b','e',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','1','D',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','2','D',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','1','D','P','r','o','j',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','2','D','P','r','o','j',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','b','i','a','s',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','1','D','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','2','D','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','1','D','P','r','o','j','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','1','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','s','h','a','d','o','w','2','D','P','r','o','j','L','o','d',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','s','a','m','p','l','e','r','2','D','S','h','a','d','o','w',' ','s','a','m','p','l','e','r',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','c','o','o','r','d',')',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','l','o','d',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','n','o','i','s','e','1',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','f','l','o','a','t',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','n','o','i','s','e','2',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','2',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','n','o','i','s','e','3',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','3',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')', +'(','f','u','n','c','t','i','o','n',' ','n','o','i','s','e','4',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','f','l','o','a','t',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','2',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','3',' ','x',')',')',' ','(',')',')',' ','(','s','i','g','n','a','t','u','r','e',' ','v','e','c','4',' ','(','p','a','r','a','m','e','t','e','r','s',' ','(','d','e','c','l','a','r','e',' ','(','i','n',')',' ','v','e','c','4',' ','x',')',')',' ','(',')',')',')',')'} ; +static const char *functions_for_130_vert [] = { + builtin_abs, + builtin_acos, + builtin_acosh, + builtin_all, + builtin_any, + builtin_asin, + builtin_asinh, + builtin_atan, + builtin_atanh, + builtin_ceil, + builtin_clamp, + builtin_cos, + builtin_cosh, + builtin_cross, + builtin_degrees, + builtin_distance, + builtin_dot, + builtin_equal, + builtin_exp, + builtin_exp2, + builtin_faceforward, + builtin_floor, + builtin_fract, + builtin_ftransform, + builtin_greaterThan, + builtin_greaterThanEqual, + builtin_inversesqrt, + builtin_length, + builtin_lessThan, + builtin_lessThanEqual, + builtin_log, + builtin_log2, + builtin_matrixCompMult, + builtin_max, + builtin_min, + builtin_mix, + builtin_mod, + builtin_modf, + builtin_noise1, + builtin_noise2, + builtin_noise3, + builtin_noise4, + builtin_normalize, + builtin_not, + builtin_notEqual, + builtin_outerProduct, + builtin_pow, + builtin_radians, + builtin_reflect, + builtin_refract, + builtin_round, + builtin_roundEven, + builtin_shadow1D, + builtin_shadow1DLod, + builtin_shadow1DProj, + builtin_shadow1DProjLod, + builtin_shadow2D, + builtin_shadow2DLod, + builtin_shadow2DProj, + builtin_shadow2DProjLod, + builtin_sign, + builtin_sin, + builtin_sinh, + builtin_smoothstep, + builtin_sqrt, + builtin_step, + builtin_tan, + builtin_tanh, + builtin_texelFetch, + builtin_texture, + builtin_texture1D, + builtin_texture1DLod, + builtin_texture1DProj, + builtin_texture1DProjLod, + builtin_texture2D, + builtin_texture2DLod, + builtin_texture2DProj, + builtin_texture2DProjLod, + builtin_texture3D, + builtin_texture3DLod, + builtin_texture3DProj, + builtin_texture3DProjLod, + builtin_textureCube, + builtin_textureCubeLod, + builtin_textureGrad, + builtin_textureLod, + builtin_textureProj, + builtin_textureProjGrad, + builtin_textureProjLod, + builtin_transpose, + builtin_trunc, +}; +static const char prototypes_for_ARB_texture_rectangle_frag[] = + "(\n" + "(function texture2DRect\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRect sampler)\n" + " (declare (in) vec2 coord))\n" + " ()))\n" + "(function texture2DRectProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRect sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRect sampler)\n" + " (declare (in) vec4 coord))\n" + " ()))\n" + "(function shadow2DRect\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRectShadow sampler)\n" + " (declare (in) vec3 coord))\n" + " ()))\n" + "(function shadow2DRectProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRectShadow sampler)\n" + " (declare (in) vec4 coord))\n" + " ())))" +; +static const char *functions_for_ARB_texture_rectangle_frag [] = { + builtin_shadow2DRect, + builtin_shadow2DRectProj, + builtin_texture2DRect, + builtin_texture2DRectProj, +}; +static const char prototypes_for_ARB_texture_rectangle_vert[] = + "(\n" + "(function texture2DRect\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRect sampler)\n" + " (declare (in) vec2 coord))\n" + " ()))\n" + "(function texture2DRectProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRect sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRect sampler)\n" + " (declare (in) vec4 coord))\n" + " ()))\n" + "(function shadow2DRect\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRectShadow sampler)\n" + " (declare (in) vec3 coord))\n" + " ()))\n" + "(function shadow2DRectProj\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DRectShadow sampler)\n" + " (declare (in) vec4 coord))\n" + " ())))" +; +static const char *functions_for_ARB_texture_rectangle_vert [] = { + builtin_shadow2DRect, + builtin_shadow2DRectProj, + builtin_texture2DRect, + builtin_texture2DRectProj, +}; +static const char prototypes_for_EXT_texture_array_frag[] = + "(\n" + "(function texture1DArray\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArray sampler)\n" + " (declare (in) vec2 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArray sampler)\n" + " (declare (in) vec2 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function texture2DArray\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArray sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArray sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function shadow1DArray\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArrayShadow sampler)\n" + " (declare (in) vec3 coord))\n" + " ())\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArrayShadow sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float bias))\n" + " ()))\n" + "(function shadow2DArray\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArrayShadow sampler)\n" + " (declare (in) vec4 coord))\n" + " ())))" +; +static const char *functions_for_EXT_texture_array_frag [] = { + builtin_shadow1DArray, + builtin_shadow2DArray, + builtin_texture1DArray, + builtin_texture2DArray, +}; +static const char prototypes_for_EXT_texture_array_vert[] = + "(\n" + "(function texture1DArray\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArray sampler)\n" + " (declare (in) vec2 coord))\n" + " ()))\n" + "(function texture1DArrayLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArray sampler)\n" + " (declare (in) vec2 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function texture2DArray\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArray sampler)\n" + " (declare (in) vec3 coord))\n" + " ()))\n" + "(function texture2DArrayLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArray sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function shadow1DArray\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArrayShadow sampler)\n" + " (declare (in) vec3 coord))\n" + " ()))\n" + "(function shadow1DArrayLod\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler1DArrayShadow sampler)\n" + " (declare (in) vec3 coord)\n" + " (declare (in) float lod))\n" + " ()))\n" + "(function shadow2DArray\n" + " (signature vec4\n" + " (parameters\n" + " (declare (in) sampler2DArrayShadow sampler)\n" + " (declare (in) vec4 coord))\n" + " ())))" +; +static const char *functions_for_EXT_texture_array_vert [] = { + builtin_shadow1DArray, + builtin_shadow1DArrayLod, + builtin_shadow2DArray, + builtin_texture1DArray, + builtin_texture1DArrayLod, + builtin_texture2DArray, + builtin_texture2DArrayLod, +}; +static gl_shader *builtin_profiles[12]; + +void *builtin_mem_ctx = NULL; + +void +_mesa_glsl_release_functions(void) +{ + ralloc_free(builtin_mem_ctx); + builtin_mem_ctx = NULL; + memset(builtin_profiles, 0, sizeof(builtin_profiles)); +} + +static void +_mesa_read_profile(struct _mesa_glsl_parse_state *state, + exec_list *instructions, + int profile_index, + const char *prototypes, + const char **functions, + int count) +{ + gl_shader *sh = builtin_profiles[profile_index]; + + if (sh == NULL) { + sh = read_builtins(GL_VERTEX_SHADER, prototypes, functions, count); + ralloc_steal(builtin_mem_ctx, sh); + builtin_profiles[profile_index] = sh; + } + + state->builtins_to_link[state->num_builtins_to_link] = sh; + state->num_builtins_to_link++; +} + +void +_mesa_glsl_initialize_functions(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + if (builtin_mem_ctx == NULL) { + builtin_mem_ctx = ralloc_context(NULL); // "GLSL built-in functions" + memset(&builtin_profiles, 0, sizeof(builtin_profiles)); + } + + state->num_builtins_to_link = 0; + + if (state->target == fragment_shader && state->language_version == 100) { + _mesa_read_profile(state, instructions, 0, + prototypes_for_100_frag, + functions_for_100_frag, + Elements(functions_for_100_frag)); + } + + if (state->target == vertex_shader && state->language_version == 100) { + _mesa_read_profile(state, instructions, 1, + prototypes_for_100_vert, + functions_for_100_vert, + Elements(functions_for_100_vert)); + } + + if (state->target == fragment_shader && state->language_version == 110) { + _mesa_read_profile(state, instructions, 2, + prototypes_for_110_frag, + functions_for_110_frag, + Elements(functions_for_110_frag)); + } + + if (state->target == vertex_shader && state->language_version == 110) { + _mesa_read_profile(state, instructions, 3, + prototypes_for_110_vert, + functions_for_110_vert, + Elements(functions_for_110_vert)); + } + + if (state->target == fragment_shader && state->language_version == 120) { + _mesa_read_profile(state, instructions, 4, + prototypes_for_120_frag, + functions_for_120_frag, + Elements(functions_for_120_frag)); + } + + if (state->target == vertex_shader && state->language_version == 120) { + _mesa_read_profile(state, instructions, 5, + prototypes_for_120_vert, + functions_for_120_vert, + Elements(functions_for_120_vert)); + } + + if (state->target == fragment_shader && state->language_version == 130) { + _mesa_read_profile(state, instructions, 6, + prototypes_for_130_frag, + functions_for_130_frag, + Elements(functions_for_130_frag)); + } + + if (state->target == vertex_shader && state->language_version == 130) { + _mesa_read_profile(state, instructions, 7, + prototypes_for_130_vert, + functions_for_130_vert, + Elements(functions_for_130_vert)); + } + + if (state->target == fragment_shader && state->ARB_texture_rectangle_enable) { + _mesa_read_profile(state, instructions, 8, + prototypes_for_ARB_texture_rectangle_frag, + functions_for_ARB_texture_rectangle_frag, + Elements(functions_for_ARB_texture_rectangle_frag)); + } + + if (state->target == vertex_shader && state->ARB_texture_rectangle_enable) { + _mesa_read_profile(state, instructions, 9, + prototypes_for_ARB_texture_rectangle_vert, + functions_for_ARB_texture_rectangle_vert, + Elements(functions_for_ARB_texture_rectangle_vert)); + } + + if (state->target == fragment_shader && state->EXT_texture_array_enable) { + _mesa_read_profile(state, instructions, 10, + prototypes_for_EXT_texture_array_frag, + functions_for_EXT_texture_array_frag, + Elements(functions_for_EXT_texture_array_frag)); + } + + if (state->target == vertex_shader && state->EXT_texture_array_enable) { + _mesa_read_profile(state, instructions, 11, + prototypes_for_EXT_texture_array_vert, + functions_for_EXT_texture_array_vert, + Elements(functions_for_EXT_texture_array_vert)); + } + +} diff --git a/src/glsl/builtin_types.h b/src/glsl/builtin_types.h new file mode 100644 index 0000000..8ccbf6e --- /dev/null +++ b/src/glsl/builtin_types.h @@ -0,0 +1,300 @@ +/* + * Copyright © 2009 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +const glsl_type glsl_type::_error_type = + glsl_type(GL_INVALID_ENUM, GLSL_TYPE_ERROR, 0, 0, ""); + +const glsl_type glsl_type::_void_type = + glsl_type(GL_INVALID_ENUM, GLSL_TYPE_VOID, 0, 0, "void"); + +const glsl_type *const glsl_type::error_type = & glsl_type::_error_type; +const glsl_type *const glsl_type::void_type = & glsl_type::_void_type; + +/** \name Core built-in types + * + * These types exist in all versions of GLSL. + */ +/*@{*/ + +const glsl_type glsl_type::builtin_core_types[] = { + glsl_type(GL_BOOL, GLSL_TYPE_BOOL, 1, 1, "bool"), + glsl_type(GL_BOOL_VEC2, GLSL_TYPE_BOOL, 2, 1, "bvec2"), + glsl_type(GL_BOOL_VEC3, GLSL_TYPE_BOOL, 3, 1, "bvec3"), + glsl_type(GL_BOOL_VEC4, GLSL_TYPE_BOOL, 4, 1, "bvec4"), + glsl_type(GL_INT, GLSL_TYPE_INT, 1, 1, "int"), + glsl_type(GL_INT_VEC2, GLSL_TYPE_INT, 2, 1, "ivec2"), + glsl_type(GL_INT_VEC3, GLSL_TYPE_INT, 3, 1, "ivec3"), + glsl_type(GL_INT_VEC4, GLSL_TYPE_INT, 4, 1, "ivec4"), + glsl_type(GL_FLOAT, GLSL_TYPE_FLOAT, 1, 1, "float"), + glsl_type(GL_FLOAT_VEC2, GLSL_TYPE_FLOAT, 2, 1, "vec2"), + glsl_type(GL_FLOAT_VEC3, GLSL_TYPE_FLOAT, 3, 1, "vec3"), + glsl_type(GL_FLOAT_VEC4, GLSL_TYPE_FLOAT, 4, 1, "vec4"), + glsl_type(GL_FLOAT_MAT2, GLSL_TYPE_FLOAT, 2, 2, "mat2"), + glsl_type(GL_FLOAT_MAT3, GLSL_TYPE_FLOAT, 3, 3, "mat3"), + glsl_type(GL_FLOAT_MAT4, GLSL_TYPE_FLOAT, 4, 4, "mat4"), + glsl_type(GL_SAMPLER_2D, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT, + "sampler2D"), + glsl_type(GL_SAMPLER_CUBE, GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_FLOAT, + "samplerCube"), +}; + +const glsl_type *const glsl_type::bool_type = & builtin_core_types[0]; +const glsl_type *const glsl_type::int_type = & builtin_core_types[4]; +const glsl_type *const glsl_type::ivec4_type = & builtin_core_types[7]; +const glsl_type *const glsl_type::float_type = & builtin_core_types[8]; +const glsl_type *const glsl_type::vec2_type = & builtin_core_types[9]; +const glsl_type *const glsl_type::vec3_type = & builtin_core_types[10]; +const glsl_type *const glsl_type::vec4_type = & builtin_core_types[11]; +const glsl_type *const glsl_type::mat2_type = & builtin_core_types[12]; +const glsl_type *const glsl_type::mat3_type = & builtin_core_types[13]; +const glsl_type *const glsl_type::mat4_type = & builtin_core_types[14]; +/*@}*/ + +/** \name GLSL structures that have not been deprecated. + */ +/*@{*/ + +static const struct glsl_struct_field gl_DepthRangeParameters_fields[] = { + { glsl_type::float_type, "near" }, + { glsl_type::float_type, "far" }, + { glsl_type::float_type, "diff" }, +}; + +const glsl_type glsl_type::builtin_structure_types[] = { + glsl_type(gl_DepthRangeParameters_fields, + Elements(gl_DepthRangeParameters_fields), + "gl_DepthRangeParameters"), +}; +/*@}*/ + +/** \name GLSL 1.00 / 1.10 structures that are deprecated in GLSL 1.30 + */ +/*@{*/ + +static const struct glsl_struct_field gl_PointParameters_fields[] = { + { glsl_type::float_type, "size" }, + { glsl_type::float_type, "sizeMin" }, + { glsl_type::float_type, "sizeMax" }, + { glsl_type::float_type, "fadeThresholdSize" }, + { glsl_type::float_type, "distanceConstantAttenuation" }, + { glsl_type::float_type, "distanceLinearAttenuation" }, + { glsl_type::float_type, "distanceQuadraticAttenuation" }, +}; + +static const struct glsl_struct_field gl_MaterialParameters_fields[] = { + { glsl_type::vec4_type, "emission" }, + { glsl_type::vec4_type, "ambient" }, + { glsl_type::vec4_type, "diffuse" }, + { glsl_type::vec4_type, "specular" }, + { glsl_type::float_type, "shininess" }, +}; + +static const struct glsl_struct_field gl_LightSourceParameters_fields[] = { + { glsl_type::vec4_type, "ambient" }, + { glsl_type::vec4_type, "diffuse" }, + { glsl_type::vec4_type, "specular" }, + { glsl_type::vec4_type, "position" }, + { glsl_type::vec4_type, "halfVector" }, + { glsl_type::vec3_type, "spotDirection" }, + { glsl_type::float_type, "spotExponent" }, + { glsl_type::float_type, "spotCutoff" }, + { glsl_type::float_type, "spotCosCutoff" }, + { glsl_type::float_type, "constantAttenuation" }, + { glsl_type::float_type, "linearAttenuation" }, + { glsl_type::float_type, "quadraticAttenuation" }, +}; + +static const struct glsl_struct_field gl_LightModelParameters_fields[] = { + { glsl_type::vec4_type, "ambient" }, +}; + +static const struct glsl_struct_field gl_LightModelProducts_fields[] = { + { glsl_type::vec4_type, "sceneColor" }, +}; + +static const struct glsl_struct_field gl_LightProducts_fields[] = { + { glsl_type::vec4_type, "ambient" }, + { glsl_type::vec4_type, "diffuse" }, + { glsl_type::vec4_type, "specular" }, +}; + +static const struct glsl_struct_field gl_FogParameters_fields[] = { + { glsl_type::vec4_type, "color" }, + { glsl_type::float_type, "density" }, + { glsl_type::float_type, "start" }, + { glsl_type::float_type, "end" }, + { glsl_type::float_type, "scale" }, +}; + +const glsl_type glsl_type::builtin_110_deprecated_structure_types[] = { + glsl_type(gl_PointParameters_fields, + Elements(gl_PointParameters_fields), + "gl_PointParameters"), + glsl_type(gl_MaterialParameters_fields, + Elements(gl_MaterialParameters_fields), + "gl_MaterialParameters"), + glsl_type(gl_LightSourceParameters_fields, + Elements(gl_LightSourceParameters_fields), + "gl_LightSourceParameters"), + glsl_type(gl_LightModelParameters_fields, + Elements(gl_LightModelParameters_fields), + "gl_LightModelParameters"), + glsl_type(gl_LightModelProducts_fields, + Elements(gl_LightModelProducts_fields), + "gl_LightModelProducts"), + glsl_type(gl_LightProducts_fields, + Elements(gl_LightProducts_fields), + "gl_LightProducts"), + glsl_type(gl_FogParameters_fields, + Elements(gl_FogParameters_fields), + "gl_FogParameters"), +}; +/*@}*/ + +/** \name Types in GLSL 1.10 (but not GLSL ES 1.00) + */ +/*@{*/ +const glsl_type glsl_type::builtin_110_types[] = { + glsl_type(GL_SAMPLER_1D, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT, + "sampler1D"), + glsl_type(GL_SAMPLER_1D_SHADOW, GLSL_SAMPLER_DIM_1D, 1, 0, GLSL_TYPE_FLOAT, + "sampler1DShadow"), + glsl_type(GL_SAMPLER_2D_SHADOW, GLSL_SAMPLER_DIM_2D, 1, 0, GLSL_TYPE_FLOAT, + "sampler2DShadow"), + glsl_type(GL_SAMPLER_3D, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_FLOAT, + "sampler3D"), +}; +/*@}*/ + +/** \name Types added in GLSL 1.20 + */ +/*@{*/ + +const glsl_type glsl_type::builtin_120_types[] = { + glsl_type(GL_FLOAT_MAT2x3, GLSL_TYPE_FLOAT, 3, 2, "mat2x3"), + glsl_type(GL_FLOAT_MAT2x4, GLSL_TYPE_FLOAT, 4, 2, "mat2x4"), + glsl_type(GL_FLOAT_MAT3x2, GLSL_TYPE_FLOAT, 2, 3, "mat3x2"), + glsl_type(GL_FLOAT_MAT3x4, GLSL_TYPE_FLOAT, 4, 3, "mat3x4"), + glsl_type(GL_FLOAT_MAT4x2, GLSL_TYPE_FLOAT, 2, 4, "mat4x2"), + glsl_type(GL_FLOAT_MAT4x3, GLSL_TYPE_FLOAT, 3, 4, "mat4x3"), +}; +const glsl_type *const glsl_type::mat2x3_type = & builtin_120_types[0]; +const glsl_type *const glsl_type::mat2x4_type = & builtin_120_types[1]; +const glsl_type *const glsl_type::mat3x2_type = & builtin_120_types[2]; +const glsl_type *const glsl_type::mat3x4_type = & builtin_120_types[3]; +const glsl_type *const glsl_type::mat4x2_type = & builtin_120_types[4]; +const glsl_type *const glsl_type::mat4x3_type = & builtin_120_types[5]; +/*@}*/ + +/** \name Types added in GLSL 1.30 + */ +/*@{*/ + +const glsl_type glsl_type::builtin_130_types[] = { + glsl_type(GL_UNSIGNED_INT, GLSL_TYPE_UINT, 1, 1, "uint"), + glsl_type(GL_UNSIGNED_INT_VEC2, GLSL_TYPE_UINT, 2, 1, "uvec2"), + glsl_type(GL_UNSIGNED_INT_VEC3, GLSL_TYPE_UINT, 3, 1, "uvec3"), + glsl_type(GL_UNSIGNED_INT_VEC4, GLSL_TYPE_UINT, 4, 1, "uvec4"), + + /* 1D and 2D texture arrays - several of these are included only in + * builtin_EXT_texture_array_types. + */ + glsl_type(GL_INT_SAMPLER_1D_ARRAY, + GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_INT, "isampler1DArray"), + glsl_type(GL_UNSIGNED_INT_SAMPLER_1D_ARRAY, + GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_UINT, "usampler1DArray"), + glsl_type(GL_INT_SAMPLER_2D_ARRAY, + GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_INT, "isampler2DArray"), + glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_ARRAY, + GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_UINT, "usampler2DArray"), + + /* cube shadow samplers */ + glsl_type(GL_SAMPLER_CUBE_SHADOW, + GLSL_SAMPLER_DIM_CUBE, 1, 0, GLSL_TYPE_FLOAT, "samplerCubeShadow"), + + /* signed and unsigned integer samplers */ + glsl_type(GL_INT_SAMPLER_1D, + GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_INT, "isampler1D"), + glsl_type(GL_UNSIGNED_INT_SAMPLER_1D, + GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_UINT, "usampler1D"), + glsl_type(GL_INT_SAMPLER_2D, + GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_INT, "isampler2D"), + glsl_type(GL_UNSIGNED_INT_SAMPLER_2D, + GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_UINT, "usampler2D"), + glsl_type(GL_INT_SAMPLER_3D, + GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_INT, "isampler3D"), + glsl_type(GL_UNSIGNED_INT_SAMPLER_3D, + GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_UINT, "usampler3D"), + glsl_type(GL_INT_SAMPLER_CUBE, + GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_INT, "isamplerCube"), + glsl_type(GL_INT_SAMPLER_CUBE, + GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_UINT, "usamplerCube"), +}; + +const glsl_type *const glsl_type::uint_type = & builtin_130_types[0]; +const glsl_type *const glsl_type::uvec2_type = & builtin_130_types[1]; +const glsl_type *const glsl_type::uvec3_type = & builtin_130_types[2]; +const glsl_type *const glsl_type::uvec4_type = & builtin_130_types[3]; +/*@}*/ + +/** \name Sampler types added by GL_ARB_texture_rectangle + */ +/*@{*/ + +const glsl_type glsl_type::builtin_ARB_texture_rectangle_types[] = { + glsl_type(GL_SAMPLER_2D_RECT, + GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_FLOAT, "sampler2DRect"), + glsl_type(GL_SAMPLER_2D_RECT_SHADOW, + GLSL_SAMPLER_DIM_RECT, 1, 0, GLSL_TYPE_FLOAT, "sampler2DRectShadow"), +}; +/*@}*/ + +/** \name Sampler types added by GL_EXT_texture_array + */ +/*@{*/ + +const glsl_type glsl_type::builtin_EXT_texture_array_types[] = { + glsl_type(GL_SAMPLER_1D_ARRAY, + GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_FLOAT, "sampler1DArray"), + glsl_type(GL_SAMPLER_2D_ARRAY, + GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_FLOAT, "sampler2DArray"), + glsl_type(GL_SAMPLER_1D_ARRAY_SHADOW, + GLSL_SAMPLER_DIM_1D, 1, 1, GLSL_TYPE_FLOAT, "sampler1DArrayShadow"), + glsl_type(GL_SAMPLER_2D_ARRAY_SHADOW, + GLSL_SAMPLER_DIM_2D, 1, 1, GLSL_TYPE_FLOAT, "sampler2DArrayShadow"), +}; +/*@}*/ + +/** \name Sampler types added by GL_EXT_texture_buffer_object + */ +/*@{*/ + +const glsl_type glsl_type::builtin_EXT_texture_buffer_object_types[] = { + glsl_type(GL_SAMPLER_BUFFER, + GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_FLOAT, "samplerBuffer"), + glsl_type(GL_INT_SAMPLER_BUFFER, + GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_INT, "isamplerBuffer"), + glsl_type(GL_UNSIGNED_INT_SAMPLER_BUFFER, + GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_UINT, "usamplerBuffer"), +}; +/*@}*/ diff --git a/src/glsl/builtin_variables.h b/src/glsl/builtin_variables.h new file mode 100644 index 0000000..a34c67e --- /dev/null +++ b/src/glsl/builtin_variables.h @@ -0,0 +1,105 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "main/core.h" /* for slot numbers */ + +struct builtin_variable { + enum ir_variable_mode mode; + int slot; + const char *type; + const char *name; +}; + +static const builtin_variable builtin_core_vs_variables[] = { + { ir_var_out, VERT_RESULT_HPOS, "vec4", "gl_Position" }, + { ir_var_out, VERT_RESULT_PSIZ, "float", "gl_PointSize" }, +}; + +static const builtin_variable builtin_core_fs_variables[] = { + { ir_var_in, FRAG_ATTRIB_WPOS, "vec4", "gl_FragCoord" }, + { ir_var_in, FRAG_ATTRIB_FACE, "bool", "gl_FrontFacing" }, + { ir_var_out, FRAG_RESULT_COLOR, "vec4", "gl_FragColor" }, +}; + +static const builtin_variable builtin_100ES_fs_variables[] = { + { ir_var_in, FRAG_ATTRIB_PNTC, "vec2", "gl_PointCoord" }, +}; + +static const builtin_variable builtin_110_fs_variables[] = { + { ir_var_out, FRAG_RESULT_DEPTH, "float", "gl_FragDepth" }, +}; + +static const builtin_variable builtin_110_deprecated_fs_variables[] = { + { ir_var_in, FRAG_ATTRIB_COL0, "vec4", "gl_Color" }, + { ir_var_in, FRAG_ATTRIB_COL1, "vec4", "gl_SecondaryColor" }, + { ir_var_in, FRAG_ATTRIB_FOGC, "float", "gl_FogFragCoord" }, +}; + +static const builtin_variable builtin_110_deprecated_vs_variables[] = { + { ir_var_in, VERT_ATTRIB_POS, "vec4", "gl_Vertex" }, + { ir_var_in, VERT_ATTRIB_NORMAL, "vec3", "gl_Normal" }, + { ir_var_in, VERT_ATTRIB_COLOR0, "vec4", "gl_Color" }, + { ir_var_in, VERT_ATTRIB_COLOR1, "vec4", "gl_SecondaryColor" }, + { ir_var_in, VERT_ATTRIB_TEX0, "vec4", "gl_MultiTexCoord0" }, + { ir_var_in, VERT_ATTRIB_TEX1, "vec4", "gl_MultiTexCoord1" }, + { ir_var_in, VERT_ATTRIB_TEX2, "vec4", "gl_MultiTexCoord2" }, + { ir_var_in, VERT_ATTRIB_TEX3, "vec4", "gl_MultiTexCoord3" }, + { ir_var_in, VERT_ATTRIB_TEX4, "vec4", "gl_MultiTexCoord4" }, + { ir_var_in, VERT_ATTRIB_TEX5, "vec4", "gl_MultiTexCoord5" }, + { ir_var_in, VERT_ATTRIB_TEX6, "vec4", "gl_MultiTexCoord6" }, + { ir_var_in, VERT_ATTRIB_TEX7, "vec4", "gl_MultiTexCoord7" }, + { ir_var_in, VERT_ATTRIB_FOG, "float", "gl_FogCoord" }, + { ir_var_out, VERT_RESULT_HPOS, "vec4", "gl_ClipVertex" }, + { ir_var_out, VERT_RESULT_COL0, "vec4", "gl_FrontColor" }, + { ir_var_out, VERT_RESULT_BFC0, "vec4", "gl_BackColor" }, + { ir_var_out, VERT_RESULT_COL1, "vec4", "gl_FrontSecondaryColor" }, + { ir_var_out, VERT_RESULT_BFC1, "vec4", "gl_BackSecondaryColor" }, + { ir_var_out, VERT_RESULT_FOGC, "float", "gl_FogFragCoord" }, +}; + +static const builtin_variable builtin_120_fs_variables[] = { + { ir_var_in, FRAG_ATTRIB_PNTC, "vec2", "gl_PointCoord" }, +}; + +static const builtin_variable builtin_130_vs_variables[] = { + { ir_var_in, -1, "int", "gl_VertexID" }, +}; + +static const builtin_variable builtin_110_deprecated_uniforms[] = { + { ir_var_uniform, -1, "mat4", "gl_ModelViewMatrix" }, + { ir_var_uniform, -1, "mat4", "gl_ProjectionMatrix" }, + { ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrix" }, + { ir_var_uniform, -1, "mat3", "gl_NormalMatrix" }, + { ir_var_uniform, -1, "mat4", "gl_ModelViewMatrixInverse" }, + { ir_var_uniform, -1, "mat4", "gl_ProjectionMatrixInverse" }, + { ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrixInverse" }, + { ir_var_uniform, -1, "mat4", "gl_ModelViewMatrixTranspose" }, + { ir_var_uniform, -1, "mat4", "gl_ProjectionMatrixTranspose" }, + { ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrixTranspose" }, + { ir_var_uniform, -1, "mat4", "gl_ModelViewMatrixInverseTranspose" }, + { ir_var_uniform, -1, "mat4", "gl_ProjectionMatrixInverseTranspose" }, + { ir_var_uniform, -1, "mat4", "gl_ModelViewProjectionMatrixInverseTranspose" }, + { ir_var_uniform, -1, "float", "gl_NormalScale" }, + { ir_var_uniform, -1, "gl_LightModelParameters", "gl_LightModel"}, +}; + diff --git a/src/glsl/glcpp/README b/src/glsl/glcpp/README new file mode 100644 index 0000000..0b5ef50 --- /dev/null +++ b/src/glsl/glcpp/README @@ -0,0 +1,32 @@ +glcpp -- GLSL "C" preprocessor + +This is a simple preprocessor designed to provide the preprocessing +needs of the GLSL language. The requirements for this preprocessor are +specified in the GLSL 1.30 specification availble from: + +http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.30.10.pdf + +This specification is not precise on some semantics, (for example, +#define and #if), defining these merely "as is standard for C++ +preprocessors". To fill in these details, I've been using a draft of +the C99 standard as available from: + +http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf + +Any downstream compiler accepting output from glcpp should be prepared +to encounter and deal with the following preprocessor macros: + + #line + #pragma + #extension + +All other macros will be handles according to the GLSL specification +and will not appear in the output. + +Known limitations +----------------- +The __LINE__ and __FILE__ macros are not yet supported. + +A file that ends with a function-like macro name as the last +non-whitespace token will result in a parse error, (where it should be +passed through as is). \ No newline at end of file diff --git a/src/glsl/glcpp/glcpp-lex.c b/src/glsl/glcpp/glcpp-lex.c new file mode 100644 index 0000000..3e1b918 --- /dev/null +++ b/src/glsl/glcpp/glcpp-lex.c @@ -0,0 +1,2613 @@ +#line 2 "glcpp/glcpp-lex.c" + +#line 4 "glcpp/glcpp-lex.c" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; +#endif /* ! C99 */ + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* An opaque pointer. */ +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif + +/* For convenience, these vars (plus the bison vars far below) + are macros in the reentrant scanner. */ +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yy_flex_debug yyg->yy_flex_debug_r + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN yyg->yy_start = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START ((yyg->yy_start - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE glcpp_restart(yyin ,yyscanner ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE 16384 +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = yyg->yy_hold_char; \ + YY_RESTORE_YY_MORE_OFFSET \ + yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via glcpp_restart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ + ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] + +void glcpp_restart (FILE *input_file ,yyscan_t yyscanner ); +void glcpp__switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); +YY_BUFFER_STATE glcpp__create_buffer (FILE *file,int size ,yyscan_t yyscanner ); +void glcpp__delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); +void glcpp__flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); +void glcpp_push_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); +void glcpp_pop_buffer_state (yyscan_t yyscanner ); + +static void glcpp_ensure_buffer_stack (yyscan_t yyscanner ); +static void glcpp__load_buffer_state (yyscan_t yyscanner ); +static void glcpp__init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner ); + +#define YY_FLUSH_BUFFER glcpp__flush_buffer(YY_CURRENT_BUFFER ,yyscanner) + +YY_BUFFER_STATE glcpp__scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); +YY_BUFFER_STATE glcpp__scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); +YY_BUFFER_STATE glcpp__scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner ); + +void *glcpp_alloc (yy_size_t ,yyscan_t yyscanner ); +void *glcpp_realloc (void *,yy_size_t ,yyscan_t yyscanner ); +void glcpp_free (void * ,yyscan_t yyscanner ); + +#define yy_new_buffer glcpp__create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + glcpp_ensure_buffer_stack (yyscanner); \ + YY_CURRENT_BUFFER_LVALUE = \ + glcpp__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + glcpp_ensure_buffer_stack (yyscanner); \ + YY_CURRENT_BUFFER_LVALUE = \ + glcpp__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +#define glcpp_wrap(n) 1 +#define YY_SKIP_YYWRAP + +typedef unsigned char YY_CHAR; + +typedef int yy_state_type; + +#define yytext_ptr yytext_r + +static yy_state_type yy_get_previous_state (yyscan_t yyscanner ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner); +static int yy_get_next_buffer (yyscan_t yyscanner ); +static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + yyg->yytext_ptr = yy_bp; \ + yyleng = (size_t) (yy_cp - yy_bp); \ + yyg->yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yyg->yy_c_buf_p = yy_cp; + +#define YY_NUM_RULES 43 +#define YY_END_OF_BUFFER 44 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_acclist[125] = + { 0, + 3, 3, 44, 39, 43, 40, 43, 41, 43, 43, + 38, 43, 43, 38, 43, 38, 43, 38, 43, 25, + 39, 43, 24, 39, 43, 38, 43, 38, 43, 38, + 43, 37, 39, 43, 37, 39, 43, 38, 43, 40, + 43, 23, 43, 3, 43, 4, 43, 5, 43, 42, + 43, 18, 43, 18, 43, 18, 43, 39, 40, 32, + 35, 33, 2, 1, 25, 39, 25, 39, 39, 24, + 39, 24, 39, 27, 29, 31, 30, 28, 37, 39, + 37, 39, 34, 40, 23, 23, 3, 4, 5, 6, + 5, 7, 1, 26, 39, 37, 39, 26, 39, 37, + + 39, 14, 37, 39, 15, 16, 37, 39, 17, 19, + 12, 22, 36, 37, 39, 21, 19, 13,16404, 11, + 9, 8, 8212, 10 + } ; + +static yyconst flex_int16_t yy_accept[155] = + { 0, + 1, 1, 1, 1, 1, 2, 3, 3, 3, 3, + 3, 4, 6, 8, 10, 11, 13, 14, 16, 18, + 20, 23, 26, 28, 30, 32, 35, 38, 40, 42, + 44, 46, 48, 50, 52, 54, 56, 58, 59, 60, + 61, 62, 63, 64, 65, 67, 69, 70, 72, 74, + 75, 76, 77, 78, 79, 81, 83, 84, 85, 86, + 87, 87, 87, 87, 87, 87, 87, 87, 88, 89, + 90, 91, 92, 93, 93, 93, 93, 93, 94, 96, + 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, + 98, 100, 102, 102, 102, 102, 102, 102, 102, 103, + + 103, 103, 103, 103, 103, 103, 105, 105, 106, 107, + 107, 107, 107, 107, 107, 107, 107, 107, 107, 109, + 109, 110, 111, 111, 112, 112, 112, 112, 113, 113, + 116, 117, 118, 118, 119, 119, 119, 119, 120, 120, + 120, 121, 121, 122, 123, 123, 123, 123, 124, 124, + 124, 125, 125, 125 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 5, 1, 6, 1, 7, 8, 1, 9, + 7, 10, 7, 7, 7, 7, 11, 12, 13, 13, + 13, 13, 13, 13, 13, 14, 14, 1, 7, 15, + 16, 17, 1, 1, 18, 18, 18, 18, 18, 18, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 20, 19, 19, 21, 19, 19, + 7, 1, 7, 7, 19, 1, 22, 18, 18, 23, + + 24, 25, 26, 19, 27, 19, 19, 28, 29, 30, + 31, 32, 19, 33, 34, 35, 36, 37, 19, 38, + 19, 19, 7, 39, 7, 7, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[40] = + { 0, + 1, 2, 3, 4, 4, 4, 4, 4, 5, 6, + 4, 7, 7, 7, 4, 4, 4, 8, 8, 8, + 8, 8, 9, 8, 8, 8, 8, 8, 8, 9, + 8, 8, 8, 8, 8, 8, 8, 8, 4 + } ; + +static yyconst flex_int16_t yy_base[168] = + { 0, + 0, 38, 0, 0, 38, 39, 328, 327, 326, 44, + 328, 0, 325, 332, 332, 310, 319, 332, 316, 41, + 41, 44, 44, 307, 49, 321, 44, 282, 61, 79, + 317, 332, 72, 332, 332, 67, 68, 0, 317, 332, + 332, 332, 332, 0, 34, 0, 105, 0, 0, 332, + 332, 332, 332, 332, 317, 73, 332, 82, 311, 310, + 291, 61, 289, 286, 279, 281, 286, 306, 332, 90, + 332, 94, 332, 84, 85, 108, 48, 0, 88, 95, + 283, 86, 284, 273, 270, 91, 274, 281, 279, 268, + 0, 124, 273, 274, 274, 270, 265, 271, 332, 267, + + 264, 262, 259, 260, 249, 125, 245, 332, 332, 241, + 229, 231, 223, 209, 222, 194, 197, 194, 130, 196, + 332, 0, 181, 332, 189, 131, 191, 332, 181, 210, + 162, 0, 136, 332, 134, 0, 130, 155, 111, 138, + 332, 153, 0, 332, 125, 41, 156, 332, 34, 136, + 332, 159, 332, 173, 182, 191, 200, 209, 218, 227, + 236, 245, 254, 263, 272, 280, 285 + } ; + +static yyconst flex_int16_t yy_def[168] = + { 0, + 153, 1, 154, 154, 155, 155, 156, 156, 157, 157, + 153, 158, 153, 153, 153, 153, 153, 153, 153, 153, + 158, 158, 153, 153, 153, 159, 159, 153, 153, 153, + 160, 153, 161, 153, 153, 153, 153, 158, 153, 153, + 153, 153, 153, 162, 21, 158, 158, 22, 158, 153, + 153, 153, 153, 153, 159, 159, 153, 153, 30, 30, + 153, 153, 153, 153, 153, 153, 153, 160, 153, 161, + 153, 161, 153, 153, 153, 153, 153, 162, 47, 159, + 153, 153, 153, 153, 153, 163, 153, 153, 153, 153, + 158, 159, 153, 153, 153, 153, 153, 153, 153, 153, + + 153, 153, 153, 153, 153, 159, 153, 153, 153, 153, + 153, 153, 153, 153, 153, 153, 153, 153, 159, 153, + 153, 164, 153, 153, 153, 153, 153, 153, 153, 159, + 153, 164, 153, 153, 153, 165, 153, 166, 153, 153, + 153, 153, 165, 153, 167, 153, 153, 153, 167, 153, + 153, 153, 0, 153, 153, 153, 153, 153, 153, 153, + 153, 153, 153, 153, 153, 153, 153 + } ; + +static yyconst flex_int16_t yy_nxt[372] = + { 0, + 12, 13, 14, 15, 16, 17, 18, 19, 18, 18, + 20, 21, 22, 22, 23, 24, 25, 26, 26, 26, + 26, 26, 27, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 28, 29, + 32, 32, 148, 30, 38, 36, 14, 33, 33, 37, + 43, 44, 45, 45, 38, 48, 48, 48, 50, 51, + 46, 47, 58, 49, 53, 54, 59, 56, 74, 76, + 136, 38, 75, 38, 71, 82, 46, 83, 47, 49, + 60, 72, 73, 58, 41, 74, 76, 59, 82, 75, + 83, 77, 71, 84, 63, 38, 71, 80, 85, 153, + + 153, 61, 62, 72, 73, 63, 64, 91, 77, 76, + 65, 63, 94, 100, 66, 67, 79, 79, 79, 95, + 101, 92, 79, 91, 38, 38, 79, 79, 79, 79, + 38, 77, 126, 148, 63, 140, 141, 150, 151, 140, + 141, 146, 135, 135, 135, 142, 142, 142, 119, 147, + 147, 147, 130, 106, 140, 141, 138, 150, 151, 144, + 150, 151, 139, 138, 142, 142, 142, 152, 152, 152, + 152, 152, 152, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 31, 31, 31, 31, 31, 31, 31, 31, + 31, 34, 34, 34, 34, 34, 34, 34, 34, 34, + + 35, 35, 35, 35, 35, 35, 35, 35, 35, 38, + 38, 137, 136, 134, 133, 38, 38, 38, 55, 131, + 129, 128, 127, 126, 55, 55, 55, 68, 68, 68, + 68, 68, 125, 68, 68, 68, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 78, 78, 124, 78, 78, + 78, 78, 78, 78, 99, 99, 99, 99, 99, 99, + 123, 122, 99, 132, 132, 121, 132, 132, 132, 132, + 132, 132, 143, 143, 120, 143, 143, 143, 143, 143, + 143, 145, 118, 117, 116, 115, 114, 145, 145, 149, + 113, 149, 149, 149, 112, 111, 110, 109, 108, 107, + + 105, 104, 103, 102, 98, 97, 96, 93, 69, 90, + 89, 88, 87, 86, 81, 153, 153, 38, 39, 69, + 57, 38, 52, 42, 41, 40, 39, 153, 14, 15, + 15, 11, 153, 153, 153, 153, 153, 153, 153, 153, + 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, + 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, + 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, + 153 + } ; + +static yyconst flex_int16_t yy_chk[372] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 5, 6, 149, 2, 27, 10, 10, 5, 6, 10, + 20, 20, 21, 21, 45, 22, 22, 22, 23, 23, + 21, 21, 29, 22, 25, 25, 29, 27, 36, 37, + 146, 45, 36, 56, 33, 77, 21, 77, 21, 22, + 30, 33, 33, 58, 30, 74, 75, 58, 62, 74, + 62, 37, 70, 62, 37, 80, 72, 56, 62, 70, + + 70, 30, 30, 72, 72, 30, 30, 79, 75, 76, + 30, 75, 82, 86, 30, 30, 47, 47, 47, 82, + 86, 80, 47, 79, 92, 106, 47, 47, 47, 47, + 119, 76, 126, 145, 76, 135, 135, 150, 150, 140, + 140, 139, 126, 126, 126, 135, 135, 135, 106, 140, + 140, 140, 119, 92, 142, 142, 138, 147, 147, 137, + 152, 152, 133, 131, 142, 142, 142, 147, 147, 147, + 152, 152, 152, 154, 154, 154, 154, 154, 154, 154, + 154, 154, 155, 155, 155, 155, 155, 155, 155, 155, + 155, 156, 156, 156, 156, 156, 156, 156, 156, 156, + + 157, 157, 157, 157, 157, 157, 157, 157, 157, 158, + 130, 129, 127, 125, 123, 158, 158, 158, 159, 120, + 118, 117, 116, 115, 159, 159, 159, 160, 160, 160, + 160, 160, 114, 160, 160, 160, 161, 161, 161, 161, + 161, 161, 161, 161, 161, 162, 162, 113, 162, 162, + 162, 162, 162, 162, 163, 163, 163, 163, 163, 163, + 112, 111, 163, 164, 164, 110, 164, 164, 164, 164, + 164, 164, 165, 165, 107, 165, 165, 165, 165, 165, + 165, 166, 105, 104, 103, 102, 101, 166, 166, 167, + 100, 167, 167, 167, 98, 97, 96, 95, 94, 93, + + 90, 89, 88, 87, 85, 84, 83, 81, 68, 67, + 66, 65, 64, 63, 61, 60, 59, 55, 39, 31, + 28, 26, 24, 19, 17, 16, 13, 11, 9, 8, + 7, 153, 153, 153, 153, 153, 153, 153, 153, 153, + 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, + 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, + 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, + 153 + } ; + +#define YY_TRAILING_MASK 0x2000 +#define YY_TRAILING_HEAD_MASK 0x4000 +#define REJECT \ +{ \ +*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */ \ +yy_cp = yyg->yy_full_match; /* restore poss. backed-over text */ \ +yyg->yy_lp = yyg->yy_full_lp; /* restore orig. accepting pos. */ \ +yyg->yy_state_ptr = yyg->yy_full_state; /* restore orig. state */ \ +yy_current_state = *yyg->yy_state_ptr; /* restore curr. state */ \ +++yyg->yy_lp; \ +goto find_rule; \ +} + +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +#line 1 "glcpp/glcpp-lex.l" +#line 2 "glcpp/glcpp-lex.l" +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include + +#include "glcpp.h" +#include "glcpp-parse.h" + +/* Flex annoyingly generates some functions without making them + * static. Let's declare them here. */ +int glcpp_get_column (yyscan_t yyscanner); +void glcpp_set_column (int column_no , yyscan_t yyscanner); + +#define YY_NO_INPUT + +#define YY_USER_ACTION \ + do { \ + yylloc->first_column = yycolumn + 1; \ + yylloc->first_line = yylineno; \ + yycolumn += yyleng; \ + } while(0); + +#define YY_USER_INIT \ + do { \ + yylineno = 1; \ + yycolumn = 1; \ + yylloc->source = 0; \ + } while(0) + +#line 644 "glcpp/glcpp-lex.c" + +#define INITIAL 0 +#define DONE 1 +#define COMMENT 2 +#define UNREACHABLE 3 +#define SKIP 4 + +#define YY_EXTRA_TYPE glcpp_parser_t * + +/* Holds the entire state of the reentrant scanner. */ +struct yyguts_t + { + + /* User-defined. Not touched by flex. */ + YY_EXTRA_TYPE yyextra_r; + + /* The rest are the same as the globals declared in the non-reentrant scanner. */ + FILE *yyin_r, *yyout_r; + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ + char yy_hold_char; + int yy_n_chars; + int yyleng_r; + char *yy_c_buf_p; + int yy_init; + int yy_start; + int yy_did_buffer_switch_on_eof; + int yy_start_stack_ptr; + int yy_start_stack_depth; + int *yy_start_stack; + yy_state_type yy_last_accepting_state; + char* yy_last_accepting_cpos; + + int yylineno_r; + int yy_flex_debug_r; + + yy_state_type *yy_state_buf; + yy_state_type *yy_state_ptr; + char *yy_full_match; + int yy_lp; + + /* These are only needed for trailing context rules, + * but there's no conditional variable for that yet. */ + int yy_looking_for_trail_begin; + int yy_full_lp; + int *yy_full_state; + + char *yytext_r; + int yy_more_flag; + int yy_more_len; + + YYSTYPE * yylval_r; + + YYLTYPE * yylloc_r; + + }; /* end struct yyguts_t */ + +static int yy_init_globals (yyscan_t yyscanner ); + + /* This must go here because YYSTYPE and YYLTYPE are included + * from bison output in section 1.*/ + # define yylval yyg->yylval_r + + # define yylloc yyg->yylloc_r + +int glcpp_lex_init (yyscan_t* scanner); + +int glcpp_lex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int glcpp_lex_destroy (yyscan_t yyscanner ); + +int glcpp_get_debug (yyscan_t yyscanner ); + +void glcpp_set_debug (int debug_flag ,yyscan_t yyscanner ); + +YY_EXTRA_TYPE glcpp_get_extra (yyscan_t yyscanner ); + +void glcpp_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); + +FILE *glcpp_get_in (yyscan_t yyscanner ); + +void glcpp_set_in (FILE * in_str ,yyscan_t yyscanner ); + +FILE *glcpp_get_out (yyscan_t yyscanner ); + +void glcpp_set_out (FILE * out_str ,yyscan_t yyscanner ); + +int glcpp_get_leng (yyscan_t yyscanner ); + +char *glcpp_get_text (yyscan_t yyscanner ); + +int glcpp_get_lineno (yyscan_t yyscanner ); + +void glcpp_set_lineno (int line_number ,yyscan_t yyscanner ); + +int glcpp_get_column (yyscan_t yyscanner ); + +void glcpp_set_column (int column_no ,yyscan_t yyscanner ); + +YYSTYPE * glcpp_get_lval (yyscan_t yyscanner ); + +void glcpp_set_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner ); + + YYLTYPE *glcpp_get_lloc (yyscan_t yyscanner ); + + void glcpp_set_lloc (YYLTYPE * yylloc_param ,yyscan_t yyscanner ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int glcpp_wrap (yyscan_t yyscanner ); +#else +extern int glcpp_wrap (yyscan_t yyscanner ); +#endif +#endif + + static void yyunput (int c,char *buf_ptr ,yyscan_t yyscanner); + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (yyscan_t yyscanner ); +#else +static int input (yyscan_t yyscanner ); +#endif + +#endif + + static void yy_push_state (int new_state ,yyscan_t yyscanner); + + static void yy_pop_state (yyscan_t yyscanner ); + + static int yy_top_state (yyscan_t yyscanner ); + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + unsigned n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int glcpp_lex \ + (YYSTYPE * yylval_param,YYLTYPE * yylloc_param ,yyscan_t yyscanner); + +#define YY_DECL int glcpp_lex \ + (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + if ( yyleng > 0 ) \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \ + (yytext[yyleng - 1] == '\n'); \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + +#line 76 "glcpp/glcpp-lex.l" + + /* Implicitly switch between SKIP and INITIAL (non-skipping); + * don't switch if some other state was explicitly set. + */ + glcpp_parser_t *parser = yyextra; + if (YY_START == 0 || YY_START == SKIP) { + if (parser->lexing_if || parser->skip_stack == NULL || parser->skip_stack->type == SKIP_NO_SKIP) { + BEGIN 0; + } else { + BEGIN SKIP; + } + } + + /* Single-line comments */ +#line 918 "glcpp/glcpp-lex.c" + + yylval = yylval_param; + + yylloc = yylloc_param; + + if ( !yyg->yy_init ) + { + yyg->yy_init = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + /* Create the reject buffer large enough to save one state per allowed character. */ + if ( ! yyg->yy_state_buf ) + yyg->yy_state_buf = (yy_state_type *)glcpp_alloc(YY_STATE_BUF_SIZE ,yyscanner); + if ( ! yyg->yy_state_buf ) + YY_FATAL_ERROR( "out of dynamic memory in glcpp_lex()" ); + + if ( ! yyg->yy_start ) + yyg->yy_start = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + glcpp_ensure_buffer_stack (yyscanner); + YY_CURRENT_BUFFER_LVALUE = + glcpp__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); + } + + glcpp__load_buffer_state(yyscanner ); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = yyg->yy_c_buf_p; + + /* Support of yytext. */ + *yy_cp = yyg->yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = yyg->yy_start; + yy_current_state += YY_AT_BOL(); + + yyg->yy_state_ptr = yyg->yy_state_buf; + *yyg->yy_state_ptr++ = yy_current_state; + +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 154 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + *yyg->yy_state_ptr++ = yy_current_state; + ++yy_cp; + } + while ( yy_current_state != 153 ); + +yy_find_action: + yy_current_state = *--yyg->yy_state_ptr; + yyg->yy_lp = yy_accept[yy_current_state]; +find_rule: /* we branch to this label when backing up */ + for ( ; ; ) /* until we find what rule we matched */ + { + if ( yyg->yy_lp && yyg->yy_lp < yy_accept[yy_current_state + 1] ) + { + yy_act = yy_acclist[yyg->yy_lp]; + if ( yy_act & YY_TRAILING_HEAD_MASK || + yyg->yy_looking_for_trail_begin ) + { + if ( yy_act == yyg->yy_looking_for_trail_begin ) + { + yyg->yy_looking_for_trail_begin = 0; + yy_act &= ~YY_TRAILING_HEAD_MASK; + break; + } + } + else if ( yy_act & YY_TRAILING_MASK ) + { + yyg->yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK; + yyg->yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK; + } + else + { + yyg->yy_full_match = yy_cp; + yyg->yy_full_state = yyg->yy_state_ptr; + yyg->yy_full_lp = yyg->yy_lp; + break; + } + ++yyg->yy_lp; + goto find_rule; + } + --yy_cp; + yy_current_state = *--yyg->yy_state_ptr; + yyg->yy_lp = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ +case 1: +YY_RULE_SETUP +#line 90 "glcpp/glcpp-lex.l" +{ +} + YY_BREAK +/* Multi-line comments */ +case 2: +YY_RULE_SETUP +#line 94 "glcpp/glcpp-lex.l" +{ yy_push_state(COMMENT, yyscanner); } + YY_BREAK +case 3: +YY_RULE_SETUP +#line 95 "glcpp/glcpp-lex.l" + + YY_BREAK +case 4: +/* rule 4 can match eol */ +YY_RULE_SETUP +#line 96 "glcpp/glcpp-lex.l" +{ yylineno++; yycolumn = 0; return NEWLINE; } + YY_BREAK +case 5: +YY_RULE_SETUP +#line 97 "glcpp/glcpp-lex.l" + + YY_BREAK +case 6: +/* rule 6 can match eol */ +YY_RULE_SETUP +#line 98 "glcpp/glcpp-lex.l" +{ yylineno++; yycolumn = 0; return NEWLINE; } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 99 "glcpp/glcpp-lex.l" +{ + yy_pop_state(yyscanner); + if (yyextra->space_tokens) + return SPACE; +} + YY_BREAK +case 8: +YY_RULE_SETUP +#line 105 "glcpp/glcpp-lex.l" +{ + yylval->str = ralloc_strdup (yyextra, yytext); + yyextra->space_tokens = 0; + return HASH_VERSION; +} + YY_BREAK +/* glcpp doesn't handle #extension, #version, or #pragma directives. + * Simply pass them through to the main compiler's lexer/parser. */ +case 9: +YY_RULE_SETUP +#line 113 "glcpp/glcpp-lex.l" +{ + yylval->str = ralloc_strdup (yyextra, yytext); + yylineno++; + yycolumn = 0; + return OTHER; +} + YY_BREAK +case 10: +*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */ +yyg->yy_c_buf_p = yy_cp -= 1; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 120 "glcpp/glcpp-lex.l" +{ + /* Eat characters until the first digit is + * encountered + */ + char *ptr = yytext; + while (!isdigit(*ptr)) + ptr++; + + /* Subtract one from the line number because + * yylineno is zero-based instead of + * one-based. + */ + yylineno = strtol(ptr, &ptr, 0) - 1; + yylloc->source = strtol(ptr, NULL, 0); +} + YY_BREAK +case 11: +*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */ +yyg->yy_c_buf_p = yy_cp -= 1; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 136 "glcpp/glcpp-lex.l" +{ + /* Eat characters until the first digit is + * encountered + */ + char *ptr = yytext; + while (!isdigit(*ptr)) + ptr++; + + /* Subtract one from the line number because + * yylineno is zero-based instead of + * one-based. + */ + yylineno = strtol(ptr, &ptr, 0) - 1; +} + YY_BREAK + +case 12: +YY_RULE_SETUP +#line 152 "glcpp/glcpp-lex.l" +{ + yyextra->lexing_if = 1; + yyextra->space_tokens = 0; + return HASH_IFDEF; +} + YY_BREAK +case 13: +YY_RULE_SETUP +#line 158 "glcpp/glcpp-lex.l" +{ + yyextra->lexing_if = 1; + yyextra->space_tokens = 0; + return HASH_IFNDEF; +} + YY_BREAK +case 14: +/* rule 14 can match eol */ +*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */ +yyg->yy_c_buf_p = yy_cp -= 1; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 164 "glcpp/glcpp-lex.l" +{ + yyextra->lexing_if = 1; + yyextra->space_tokens = 0; + return HASH_IF; +} + YY_BREAK +case 15: +YY_RULE_SETUP +#line 170 "glcpp/glcpp-lex.l" +{ + yyextra->lexing_if = 1; + yyextra->space_tokens = 0; + return HASH_ELIF; +} + YY_BREAK +case 16: +YY_RULE_SETUP +#line 176 "glcpp/glcpp-lex.l" +{ + yyextra->space_tokens = 0; + return HASH_ELSE; +} + YY_BREAK +case 17: +YY_RULE_SETUP +#line 181 "glcpp/glcpp-lex.l" +{ + yyextra->space_tokens = 0; + return HASH_ENDIF; +} + YY_BREAK + +case 18: +YY_RULE_SETUP +#line 187 "glcpp/glcpp-lex.l" +; + YY_BREAK +case 19: +YY_RULE_SETUP +#line 189 "glcpp/glcpp-lex.l" +{ + char *p; + for (p = yytext; !isalpha(p[0]); p++); /* skip " # " */ + p += 5; /* skip "error" */ + glcpp_error(yylloc, yyextra, "#error%s", p); +} + YY_BREAK +case 20: +YY_RULE_SETUP +#line 196 "glcpp/glcpp-lex.l" +{ + yyextra->space_tokens = 0; + return HASH_DEFINE_FUNC; +} + YY_BREAK +case 21: +YY_RULE_SETUP +#line 201 "glcpp/glcpp-lex.l" +{ + yyextra->space_tokens = 0; + return HASH_DEFINE_OBJ; +} + YY_BREAK +case 22: +YY_RULE_SETUP +#line 206 "glcpp/glcpp-lex.l" +{ + yyextra->space_tokens = 0; + return HASH_UNDEF; +} + YY_BREAK +case 23: +YY_RULE_SETUP +#line 211 "glcpp/glcpp-lex.l" +{ + yyextra->space_tokens = 0; + return HASH; +} + YY_BREAK +case 24: +YY_RULE_SETUP +#line 216 "glcpp/glcpp-lex.l" +{ + yylval->str = ralloc_strdup (yyextra, yytext); + return INTEGER_STRING; +} + YY_BREAK +case 25: +YY_RULE_SETUP +#line 221 "glcpp/glcpp-lex.l" +{ + yylval->str = ralloc_strdup (yyextra, yytext); + return INTEGER_STRING; +} + YY_BREAK +case 26: +YY_RULE_SETUP +#line 226 "glcpp/glcpp-lex.l" +{ + yylval->str = ralloc_strdup (yyextra, yytext); + return INTEGER_STRING; +} + YY_BREAK +case 27: +YY_RULE_SETUP +#line 231 "glcpp/glcpp-lex.l" +{ + return LEFT_SHIFT; +} + YY_BREAK +case 28: +YY_RULE_SETUP +#line 235 "glcpp/glcpp-lex.l" +{ + return RIGHT_SHIFT; +} + YY_BREAK +case 29: +YY_RULE_SETUP +#line 239 "glcpp/glcpp-lex.l" +{ + return LESS_OR_EQUAL; +} + YY_BREAK +case 30: +YY_RULE_SETUP +#line 243 "glcpp/glcpp-lex.l" +{ + return GREATER_OR_EQUAL; +} + YY_BREAK +case 31: +YY_RULE_SETUP +#line 247 "glcpp/glcpp-lex.l" +{ + return EQUAL; +} + YY_BREAK +case 32: +YY_RULE_SETUP +#line 251 "glcpp/glcpp-lex.l" +{ + return NOT_EQUAL; +} + YY_BREAK +case 33: +YY_RULE_SETUP +#line 255 "glcpp/glcpp-lex.l" +{ + return AND; +} + YY_BREAK +case 34: +YY_RULE_SETUP +#line 259 "glcpp/glcpp-lex.l" +{ + return OR; +} + YY_BREAK +case 35: +YY_RULE_SETUP +#line 263 "glcpp/glcpp-lex.l" +{ + return PASTE; +} + YY_BREAK +case 36: +YY_RULE_SETUP +#line 267 "glcpp/glcpp-lex.l" +{ + return DEFINED; +} + YY_BREAK +case 37: +YY_RULE_SETUP +#line 271 "glcpp/glcpp-lex.l" +{ + yylval->str = ralloc_strdup (yyextra, yytext); + return IDENTIFIER; +} + YY_BREAK +case 38: +YY_RULE_SETUP +#line 276 "glcpp/glcpp-lex.l" +{ + return yytext[0]; +} + YY_BREAK +case 39: +YY_RULE_SETUP +#line 280 "glcpp/glcpp-lex.l" +{ + yylval->str = ralloc_strdup (yyextra, yytext); + return OTHER; +} + YY_BREAK +case 40: +YY_RULE_SETUP +#line 285 "glcpp/glcpp-lex.l" +{ + if (yyextra->space_tokens) { + return SPACE; + } +} + YY_BREAK +case 41: +/* rule 41 can match eol */ +YY_RULE_SETUP +#line 291 "glcpp/glcpp-lex.l" +{ + yyextra->lexing_if = 0; + yylineno++; + yycolumn = 0; + return NEWLINE; +} + YY_BREAK +/* Handle missing newline at EOF. */ +case YY_STATE_EOF(INITIAL): +#line 299 "glcpp/glcpp-lex.l" +{ + BEGIN DONE; /* Don't keep matching this rule forever. */ + yyextra->lexing_if = 0; + return NEWLINE; +} + YY_BREAK +/* We don't actually use the UNREACHABLE start condition. We + only have this action here so that we can pretend to call some + generated functions, (to avoid "defined but not used" + warnings. */ +case 42: +YY_RULE_SETUP +#line 309 "glcpp/glcpp-lex.l" +{ + unput('.'); + yy_top_state(yyextra); +} + YY_BREAK +case 43: +YY_RULE_SETUP +#line 314 "glcpp/glcpp-lex.l" +ECHO; + YY_BREAK +#line 1410 "glcpp/glcpp-lex.c" + case YY_STATE_EOF(DONE): + case YY_STATE_EOF(COMMENT): + case YY_STATE_EOF(UNREACHABLE): + case YY_STATE_EOF(SKIP): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = yyg->yy_hold_char; + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * glcpp_lex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( yyscanner ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); + + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++yyg->yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yyg->yy_c_buf_p; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( yyscanner ) ) + { + case EOB_ACT_END_OF_FILE: + { + yyg->yy_did_buffer_switch_on_eof = 0; + + if ( glcpp_wrap(yyscanner ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! yyg->yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + yyg->yy_c_buf_p = + yyg->yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( yyscanner ); + + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yyg->yy_c_buf_p = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; + + yy_current_state = yy_get_previous_state( yyscanner ); + + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of glcpp_lex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = yyg->yytext_ptr; + register int number_to_move, i; + int ret_val; + + if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + YY_FATAL_ERROR( +"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + yyg->yy_n_chars, (size_t) num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + if ( yyg->yy_n_chars == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + glcpp_restart(yyin ,yyscanner); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) glcpp_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + yyg->yy_n_chars += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (yyscan_t yyscanner) +{ + register yy_state_type yy_current_state; + register char *yy_cp; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + yy_current_state = yyg->yy_start; + yy_current_state += YY_AT_BOL(); + + yyg->yy_state_ptr = yyg->yy_state_buf; + *yyg->yy_state_ptr++ = yy_current_state; + + for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 154 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + *yyg->yy_state_ptr++ = yy_current_state; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) +{ + register int yy_is_jam; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ + + register YY_CHAR yy_c = 1; + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 154 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 153); + if ( ! yy_is_jam ) + *yyg->yy_state_ptr++ = yy_current_state; + + return yy_is_jam ? 0 : yy_current_state; +} + + static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner) +{ + register char *yy_cp; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + yy_cp = yyg->yy_c_buf_p; + + /* undo effects of setting up yytext */ + *yy_cp = yyg->yy_hold_char; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register int number_to_move = yyg->yy_n_chars + 2; + register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + register char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + yyg->yytext_ptr = yy_bp; + yyg->yy_hold_char = *yy_cp; + yyg->yy_c_buf_p = yy_cp; +} + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (yyscan_t yyscanner) +#else + static int input (yyscan_t yyscanner) +#endif + +{ + int c; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + *yyg->yy_c_buf_p = yyg->yy_hold_char; + + if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) + /* This was really a NUL. */ + *yyg->yy_c_buf_p = '\0'; + + else + { /* need more input */ + int offset = yyg->yy_c_buf_p - yyg->yytext_ptr; + ++yyg->yy_c_buf_p; + + switch ( yy_get_next_buffer( yyscanner ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + glcpp_restart(yyin ,yyscanner); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( glcpp_wrap(yyscanner ) ) + return EOF; + + if ( ! yyg->yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(yyscanner); +#else + return input(yyscanner); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + yyg->yy_c_buf_p = yyg->yytext_ptr + offset; + break; + } + } + } + + c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ + *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ + yyg->yy_hold_char = *++yyg->yy_c_buf_p; + + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * @param yyscanner The scanner object. + * @note This function does not reset the start condition to @c INITIAL . + */ + void glcpp_restart (FILE * input_file , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if ( ! YY_CURRENT_BUFFER ){ + glcpp_ensure_buffer_stack (yyscanner); + YY_CURRENT_BUFFER_LVALUE = + glcpp__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); + } + + glcpp__init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner); + glcpp__load_buffer_state(yyscanner ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * @param yyscanner The scanner object. + */ + void glcpp__switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* TODO. We should be able to replace this entire function body + * with + * glcpp_pop_buffer_state(); + * glcpp_push_buffer_state(new_buffer); + */ + glcpp_ensure_buffer_stack (yyscanner); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + glcpp__load_buffer_state(yyscanner ); + + /* We don't actually know whether we did this switch during + * EOF (glcpp_wrap()) processing, but the only time this flag + * is looked at is after glcpp_wrap() is called, so it's safe + * to go ahead and always set it. + */ + yyg->yy_did_buffer_switch_on_eof = 1; +} + +static void glcpp__load_buffer_state (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + yyg->yy_hold_char = *yyg->yy_c_buf_p; +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * @param yyscanner The scanner object. + * @return the allocated buffer state. + */ + YY_BUFFER_STATE glcpp__create_buffer (FILE * file, int size , yyscan_t yyscanner) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) glcpp_alloc(sizeof( struct yy_buffer_state ) ,yyscanner ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in glcpp__create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) glcpp_alloc(b->yy_buf_size + 2 ,yyscanner ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in glcpp__create_buffer()" ); + + b->yy_is_our_buffer = 1; + + glcpp__init_buffer(b,file ,yyscanner); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with glcpp__create_buffer() + * @param yyscanner The scanner object. + */ + void glcpp__delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + glcpp_free((void *) b->yy_ch_buf ,yyscanner ); + + glcpp_free((void *) b ,yyscanner ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a glcpp_restart() or at EOF. + */ + static void glcpp__init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) + +{ + int oerrno = errno; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + glcpp__flush_buffer(b ,yyscanner); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then glcpp__init_buffer was _probably_ + * called from glcpp_restart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * @param yyscanner The scanner object. + */ + void glcpp__flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + glcpp__load_buffer_state(yyscanner ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * @param yyscanner The scanner object. + */ +void glcpp_push_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (new_buffer == NULL) + return; + + glcpp_ensure_buffer_stack(yyscanner); + + /* This block is copied from glcpp__switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + yyg->yy_buffer_stack_top++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from glcpp__switch_to_buffer. */ + glcpp__load_buffer_state(yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * @param yyscanner The scanner object. + */ +void glcpp_pop_buffer_state (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (!YY_CURRENT_BUFFER) + return; + + glcpp__delete_buffer(YY_CURRENT_BUFFER ,yyscanner); + YY_CURRENT_BUFFER_LVALUE = NULL; + if (yyg->yy_buffer_stack_top > 0) + --yyg->yy_buffer_stack_top; + + if (YY_CURRENT_BUFFER) { + glcpp__load_buffer_state(yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void glcpp_ensure_buffer_stack (yyscan_t yyscanner) +{ + int num_to_alloc; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (!yyg->yy_buffer_stack) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + yyg->yy_buffer_stack = (struct yy_buffer_state**)glcpp_alloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) + YY_FATAL_ERROR( "out of dynamic memory in glcpp_ensure_buffer_stack()" ); + + memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + yyg->yy_buffer_stack_max = num_to_alloc; + yyg->yy_buffer_stack_top = 0; + return; + } + + if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = yyg->yy_buffer_stack_max + grow_size; + yyg->yy_buffer_stack = (struct yy_buffer_state**)glcpp_realloc + (yyg->yy_buffer_stack, + num_to_alloc * sizeof(struct yy_buffer_state*) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) + YY_FATAL_ERROR( "out of dynamic memory in glcpp_ensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); + yyg->yy_buffer_stack_max = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * @param yyscanner The scanner object. + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE glcpp__scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) glcpp_alloc(sizeof( struct yy_buffer_state ) ,yyscanner ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in glcpp__scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + glcpp__switch_to_buffer(b ,yyscanner ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to glcpp_lex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * @param yyscanner The scanner object. + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * glcpp__scan_bytes() instead. + */ +YY_BUFFER_STATE glcpp__scan_string (yyconst char * yystr , yyscan_t yyscanner) +{ + + return glcpp__scan_bytes(yystr,strlen(yystr) ,yyscanner); +} + +/** Setup the input buffer state to scan the given bytes. The next call to glcpp_lex() will + * scan from a @e copy of @a bytes. + * @param bytes the byte buffer to scan + * @param len the number of bytes in the buffer pointed to by @a bytes. + * @param yyscanner The scanner object. + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE glcpp__scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) glcpp_alloc(n ,yyscanner ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in glcpp__scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = glcpp__scan_buffer(buf,n ,yyscanner); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in glcpp__scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + + static void yy_push_state (int new_state , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( yyg->yy_start_stack_ptr >= yyg->yy_start_stack_depth ) + { + yy_size_t new_size; + + yyg->yy_start_stack_depth += YY_START_STACK_INCR; + new_size = yyg->yy_start_stack_depth * sizeof( int ); + + if ( ! yyg->yy_start_stack ) + yyg->yy_start_stack = (int *) glcpp_alloc(new_size ,yyscanner ); + + else + yyg->yy_start_stack = (int *) glcpp_realloc((void *) yyg->yy_start_stack,new_size ,yyscanner ); + + if ( ! yyg->yy_start_stack ) + YY_FATAL_ERROR( "out of memory expanding start-condition stack" ); + } + + yyg->yy_start_stack[yyg->yy_start_stack_ptr++] = YY_START; + + BEGIN(new_state); +} + + static void yy_pop_state (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( --yyg->yy_start_stack_ptr < 0 ) + YY_FATAL_ERROR( "start-condition stack underflow" ); + + BEGIN(yyg->yy_start_stack[yyg->yy_start_stack_ptr]); +} + + static int yy_top_state (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyg->yy_start_stack[yyg->yy_start_stack_ptr - 1]; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = yyg->yy_hold_char; \ + yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ + yyg->yy_hold_char = *yyg->yy_c_buf_p; \ + *yyg->yy_c_buf_p = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the user-defined data for this scanner. + * @param yyscanner The scanner object. + */ +YY_EXTRA_TYPE glcpp_get_extra (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyextra; +} + +/** Get the current line number. + * @param yyscanner The scanner object. + */ +int glcpp_get_lineno (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; + + return yylineno; +} + +/** Get the current column number. + * @param yyscanner The scanner object. + */ +int glcpp_get_column (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; + + return yycolumn; +} + +/** Get the input stream. + * @param yyscanner The scanner object. + */ +FILE *glcpp_get_in (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyin; +} + +/** Get the output stream. + * @param yyscanner The scanner object. + */ +FILE *glcpp_get_out (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyout; +} + +/** Get the length of the current token. + * @param yyscanner The scanner object. + */ +int glcpp_get_leng (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyleng; +} + +/** Get the current token. + * @param yyscanner The scanner object. + */ + +char *glcpp_get_text (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yytext; +} + +/** Set the user-defined data. This data is never touched by the scanner. + * @param user_defined The data to be associated with this scanner. + * @param yyscanner The scanner object. + */ +void glcpp_set_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyextra = user_defined ; +} + +/** Set the current line number. + * @param line_number + * @param yyscanner The scanner object. + */ +void glcpp_set_lineno (int line_number , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* lineno is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + yy_fatal_error( "glcpp_set_lineno called with no buffer" , yyscanner); + + yylineno = line_number; +} + +/** Set the current column. + * @param line_number + * @param yyscanner The scanner object. + */ +void glcpp_set_column (int column_no , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* column is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + yy_fatal_error( "glcpp_set_column called with no buffer" , yyscanner); + + yycolumn = column_no; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * @param yyscanner The scanner object. + * @see glcpp__switch_to_buffer + */ +void glcpp_set_in (FILE * in_str , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyin = in_str ; +} + +void glcpp_set_out (FILE * out_str , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyout = out_str ; +} + +int glcpp_get_debug (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yy_flex_debug; +} + +void glcpp_set_debug (int bdebug , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yy_flex_debug = bdebug ; +} + +/* Accessor methods for yylval and yylloc */ + +YYSTYPE * glcpp_get_lval (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yylval; +} + +void glcpp_set_lval (YYSTYPE * yylval_param , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yylval = yylval_param; +} + +YYLTYPE *glcpp_get_lloc (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yylloc; +} + +void glcpp_set_lloc (YYLTYPE * yylloc_param , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yylloc = yylloc_param; +} + +/* User-visible API */ + +/* glcpp_lex_init is special because it creates the scanner itself, so it is + * the ONLY reentrant function that doesn't take the scanner as the last argument. + * That's why we explicitly handle the declaration, instead of using our macros. + */ + +int glcpp_lex_init(yyscan_t* ptr_yy_globals) + +{ + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) glcpp_alloc ( sizeof( struct yyguts_t ), NULL ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + return yy_init_globals ( *ptr_yy_globals ); +} + +/* glcpp_lex_init_extra has the same functionality as glcpp_lex_init, but follows the + * convention of taking the scanner as the last argument. Note however, that + * this is a *pointer* to a scanner, as it will be allocated by this call (and + * is the reason, too, why this function also must handle its own declaration). + * The user defined value in the first argument will be available to glcpp_alloc in + * the yyextra field. + */ + +int glcpp_lex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) + +{ + struct yyguts_t dummy_yyguts; + + glcpp_set_extra (yy_user_defined, &dummy_yyguts); + + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) glcpp_alloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + glcpp_set_extra (yy_user_defined, *ptr_yy_globals); + + return yy_init_globals ( *ptr_yy_globals ); +} + +static int yy_init_globals (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from glcpp_lex_destroy(), so don't allocate here. + */ + + yyg->yy_buffer_stack = 0; + yyg->yy_buffer_stack_top = 0; + yyg->yy_buffer_stack_max = 0; + yyg->yy_c_buf_p = (char *) 0; + yyg->yy_init = 0; + yyg->yy_start = 0; + + yyg->yy_start_stack_ptr = 0; + yyg->yy_start_stack_depth = 0; + yyg->yy_start_stack = NULL; + + yyg->yy_state_buf = 0; + yyg->yy_state_ptr = 0; + yyg->yy_full_match = 0; + yyg->yy_lp = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = (FILE *) 0; + yyout = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * glcpp_lex_init() + */ + return 0; +} + +/* glcpp_lex_destroy is for both reentrant and non-reentrant scanners. */ +int glcpp_lex_destroy (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + glcpp__delete_buffer(YY_CURRENT_BUFFER ,yyscanner ); + YY_CURRENT_BUFFER_LVALUE = NULL; + glcpp_pop_buffer_state(yyscanner); + } + + /* Destroy the stack itself. */ + glcpp_free(yyg->yy_buffer_stack ,yyscanner); + yyg->yy_buffer_stack = NULL; + + /* Destroy the start condition stack. */ + glcpp_free(yyg->yy_start_stack ,yyscanner ); + yyg->yy_start_stack = NULL; + + glcpp_free ( yyg->yy_state_buf , yyscanner); + yyg->yy_state_buf = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * glcpp_lex() is called, initialization will occur. */ + yy_init_globals( yyscanner); + + /* Destroy the main struct (reentrant only). */ + glcpp_free ( yyscanner , yyscanner ); + yyscanner = NULL; + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *glcpp_alloc (yy_size_t size , yyscan_t yyscanner) +{ + return (void *) malloc( size ); +} + +void *glcpp_realloc (void * ptr, yy_size_t size , yyscan_t yyscanner) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void glcpp_free (void * ptr , yyscan_t yyscanner) +{ + free( (char *) ptr ); /* see glcpp_realloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 314 "glcpp/glcpp-lex.l" + + + +void +glcpp_lex_set_source_string(glcpp_parser_t *parser, const char *shader) +{ + glcpp__scan_string(shader,parser->scanner); +} + diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l new file mode 100644 index 0000000..68e44eb --- /dev/null +++ b/src/glsl/glcpp/glcpp-lex.l @@ -0,0 +1,320 @@ +%{ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include + +#include "glcpp.h" +#include "glcpp-parse.h" + +/* Flex annoyingly generates some functions without making them + * static. Let's declare them here. */ +int glcpp_get_column (yyscan_t yyscanner); +void glcpp_set_column (int column_no , yyscan_t yyscanner); + +#define YY_NO_INPUT + +#define YY_USER_ACTION \ + do { \ + yylloc->first_column = yycolumn + 1; \ + yylloc->first_line = yylineno; \ + yycolumn += yyleng; \ + } while(0); + +#define YY_USER_INIT \ + do { \ + yylineno = 1; \ + yycolumn = 1; \ + yylloc->source = 0; \ + } while(0) +%} + +%option bison-bridge bison-locations reentrant noyywrap +%option extra-type="glcpp_parser_t *" +%option prefix="glcpp_" +%option stack +%option never-interactive + +%x DONE COMMENT UNREACHABLE SKIP + +SPACE [[:space:]] +NONSPACE [^[:space:]] +NEWLINE [\n] +HSPACE [ \t] +HASH ^{HSPACE}*#{HSPACE}* +IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]* +PUNCTUATION [][(){}.&*~!/%<>^|;,=+-] +OTHER [^][(){}.&*~!/%<>^|;,=#[:space:]+-]+ + +DIGITS [0-9][0-9]* +DECIMAL_INTEGER [1-9][0-9]*[uU]? +OCTAL_INTEGER 0[0-7]*[uU]? +HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? + +%% + /* Implicitly switch between SKIP and INITIAL (non-skipping); + * don't switch if some other state was explicitly set. + */ + glcpp_parser_t *parser = yyextra; + if (YY_START == 0 || YY_START == SKIP) { + if (parser->lexing_if || parser->skip_stack == NULL || parser->skip_stack->type == SKIP_NO_SKIP) { + BEGIN 0; + } else { + BEGIN SKIP; + } + } + + /* Single-line comments */ +"//"[^\n]* { +} + + /* Multi-line comments */ +"/*" { yy_push_state(COMMENT, yyscanner); } +[^*\n]* +[^*\n]*\n { yylineno++; yycolumn = 0; return NEWLINE; } +"*"+[^*/\n]* +"*"+[^*/\n]*\n { yylineno++; yycolumn = 0; return NEWLINE; } +"*"+"/" { + yy_pop_state(yyscanner); + if (yyextra->space_tokens) + return SPACE; +} + +{HASH}version { + yylval->str = ralloc_strdup (yyextra, yytext); + yyextra->space_tokens = 0; + return HASH_VERSION; +} + + /* glcpp doesn't handle #extension, #version, or #pragma directives. + * Simply pass them through to the main compiler's lexer/parser. */ +{HASH}(extension|pragma)[^\n]+ { + yylval->str = ralloc_strdup (yyextra, yytext); + yylineno++; + yycolumn = 0; + return OTHER; +} + +{HASH}line{HSPACE}+{DIGITS}{HSPACE}+{DIGITS}{HSPACE}*$ { + /* Eat characters until the first digit is + * encountered + */ + char *ptr = yytext; + while (!isdigit(*ptr)) + ptr++; + + /* Subtract one from the line number because + * yylineno is zero-based instead of + * one-based. + */ + yylineno = strtol(ptr, &ptr, 0) - 1; + yylloc->source = strtol(ptr, NULL, 0); +} + +{HASH}line{HSPACE}+{DIGITS}{HSPACE}*$ { + /* Eat characters until the first digit is + * encountered + */ + char *ptr = yytext; + while (!isdigit(*ptr)) + ptr++; + + /* Subtract one from the line number because + * yylineno is zero-based instead of + * one-based. + */ + yylineno = strtol(ptr, &ptr, 0) - 1; +} + +{ +{HASH}ifdef { + yyextra->lexing_if = 1; + yyextra->space_tokens = 0; + return HASH_IFDEF; +} + +{HASH}ifndef { + yyextra->lexing_if = 1; + yyextra->space_tokens = 0; + return HASH_IFNDEF; +} + +{HASH}if/[^_a-zA-Z0-9] { + yyextra->lexing_if = 1; + yyextra->space_tokens = 0; + return HASH_IF; +} + +{HASH}elif { + yyextra->lexing_if = 1; + yyextra->space_tokens = 0; + return HASH_ELIF; +} + +{HASH}else { + yyextra->space_tokens = 0; + return HASH_ELSE; +} + +{HASH}endif { + yyextra->space_tokens = 0; + return HASH_ENDIF; +} +} + +[^\n] ; + +{HASH}error.* { + char *p; + for (p = yytext; !isalpha(p[0]); p++); /* skip " # " */ + p += 5; /* skip "error" */ + glcpp_error(yylloc, yyextra, "#error%s", p); +} + +{HASH}define{HSPACE}+/{IDENTIFIER}"(" { + yyextra->space_tokens = 0; + return HASH_DEFINE_FUNC; +} + +{HASH}define { + yyextra->space_tokens = 0; + return HASH_DEFINE_OBJ; +} + +{HASH}undef { + yyextra->space_tokens = 0; + return HASH_UNDEF; +} + +{HASH} { + yyextra->space_tokens = 0; + return HASH; +} + +{DECIMAL_INTEGER} { + yylval->str = ralloc_strdup (yyextra, yytext); + return INTEGER_STRING; +} + +{OCTAL_INTEGER} { + yylval->str = ralloc_strdup (yyextra, yytext); + return INTEGER_STRING; +} + +{HEXADECIMAL_INTEGER} { + yylval->str = ralloc_strdup (yyextra, yytext); + return INTEGER_STRING; +} + +"<<" { + return LEFT_SHIFT; +} + +">>" { + return RIGHT_SHIFT; +} + +"<=" { + return LESS_OR_EQUAL; +} + +">=" { + return GREATER_OR_EQUAL; +} + +"==" { + return EQUAL; +} + +"!=" { + return NOT_EQUAL; +} + +"&&" { + return AND; +} + +"||" { + return OR; +} + +"##" { + return PASTE; +} + +"defined" { + return DEFINED; +} + +{IDENTIFIER} { + yylval->str = ralloc_strdup (yyextra, yytext); + return IDENTIFIER; +} + +{PUNCTUATION} { + return yytext[0]; +} + +{OTHER}+ { + yylval->str = ralloc_strdup (yyextra, yytext); + return OTHER; +} + +{HSPACE}+ { + if (yyextra->space_tokens) { + return SPACE; + } +} + +\n { + yyextra->lexing_if = 0; + yylineno++; + yycolumn = 0; + return NEWLINE; +} + + /* Handle missing newline at EOF. */ +<> { + BEGIN DONE; /* Don't keep matching this rule forever. */ + yyextra->lexing_if = 0; + return NEWLINE; +} + + /* We don't actually use the UNREACHABLE start condition. We + only have this action here so that we can pretend to call some + generated functions, (to avoid "defined but not used" + warnings. */ +. { + unput('.'); + yy_top_state(yyextra); +} + +%% + +void +glcpp_lex_set_source_string(glcpp_parser_t *parser, const char *shader) +{ + yy_scan_string(shader, parser->scanner); +} diff --git a/src/glsl/glcpp/glcpp-parse.c b/src/glsl/glcpp/glcpp-parse.c new file mode 100644 index 0000000..46e690d --- /dev/null +++ b/src/glsl/glcpp/glcpp-parse.c @@ -0,0 +1,4220 @@ +/* A Bison parser, made by GNU Bison 2.4.3. */ + +/* Skeleton implementation for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2009, 2010 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "2.4.3" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 1 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + +/* Using locations. */ +#define YYLSP_NEEDED 1 + + + +/* Copy the first part of user declarations. */ + +/* Line 189 of yacc.c */ +#line 1 "glcpp/glcpp-parse.y" + +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#include "glcpp.h" +#include "main/core.h" /* for struct gl_extensions */ +#include "main/mtypes.h" /* for gl_api enum */ + +static void +yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error); + +static void +_define_object_macro (glcpp_parser_t *parser, + YYLTYPE *loc, + const char *macro, + token_list_t *replacements); + +static void +_define_function_macro (glcpp_parser_t *parser, + YYLTYPE *loc, + const char *macro, + string_list_t *parameters, + token_list_t *replacements); + +static string_list_t * +_string_list_create (void *ctx); + +static void +_string_list_append_item (string_list_t *list, const char *str); + +static int +_string_list_contains (string_list_t *list, const char *member, int *index); + +static int +_string_list_length (string_list_t *list); + +static int +_string_list_equal (string_list_t *a, string_list_t *b); + +static argument_list_t * +_argument_list_create (void *ctx); + +static void +_argument_list_append (argument_list_t *list, token_list_t *argument); + +static int +_argument_list_length (argument_list_t *list); + +static token_list_t * +_argument_list_member_at (argument_list_t *list, int index); + +/* Note: This function ralloc_steal()s the str pointer. */ +static token_t * +_token_create_str (void *ctx, int type, char *str); + +static token_t * +_token_create_ival (void *ctx, int type, int ival); + +static token_list_t * +_token_list_create (void *ctx); + +/* Note: This function calls ralloc_steal on token. */ +static void +_token_list_append (token_list_t *list, token_t *token); + +static void +_token_list_append_list (token_list_t *list, token_list_t *tail); + +static int +_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b); + +static active_list_t * +_active_list_push (active_list_t *list, + const char *identifier, + token_node_t *marker); + +static active_list_t * +_active_list_pop (active_list_t *list); + +int +_active_list_contains (active_list_t *list, const char *identifier); + +static void +_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list); + +static void +_glcpp_parser_expand_token_list (glcpp_parser_t *parser, + token_list_t *list); + +static void +_glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser, + token_list_t *list); + +static void +_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc, + int condition); + +static void +_glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc, + const char *type, int condition); + +static void +_glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc); + +#define yylex glcpp_parser_lex + +static int +glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser); + +static void +glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list); + +static void +add_builtin_define(glcpp_parser_t *parser, const char *name, int value); + + + +/* Line 189 of yacc.c */ +#line 216 "glcpp/glcpp-parse.c" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 1 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + COMMA_FINAL = 258, + DEFINED = 259, + ELIF_EXPANDED = 260, + HASH = 261, + HASH_DEFINE_FUNC = 262, + HASH_DEFINE_OBJ = 263, + HASH_ELIF = 264, + HASH_ELSE = 265, + HASH_ENDIF = 266, + HASH_IF = 267, + HASH_IFDEF = 268, + HASH_IFNDEF = 269, + HASH_UNDEF = 270, + HASH_VERSION = 271, + IDENTIFIER = 272, + IF_EXPANDED = 273, + INTEGER = 274, + INTEGER_STRING = 275, + NEWLINE = 276, + OTHER = 277, + PLACEHOLDER = 278, + SPACE = 279, + PASTE = 280, + OR = 281, + AND = 282, + NOT_EQUAL = 283, + EQUAL = 284, + GREATER_OR_EQUAL = 285, + LESS_OR_EQUAL = 286, + RIGHT_SHIFT = 287, + LEFT_SHIFT = 288, + UNARY = 289 + }; +#endif + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED + +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + +/* Copy the second part of user declarations. */ + + +/* Line 264 of yacc.c */ +#line 304 "glcpp/glcpp-parse.c" + +#ifdef short +# undef short +#endif + +#ifdef YYTYPE_UINT8 +typedef YYTYPE_UINT8 yytype_uint8; +#else +typedef unsigned char yytype_uint8; +#endif + +#ifdef YYTYPE_INT8 +typedef YYTYPE_INT8 yytype_int8; +#elif (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +typedef signed char yytype_int8; +#else +typedef short int yytype_int8; +#endif + +#ifdef YYTYPE_UINT16 +typedef YYTYPE_UINT16 yytype_uint16; +#else +typedef unsigned short int yytype_uint16; +#endif + +#ifdef YYTYPE_INT16 +typedef YYTYPE_INT16 yytype_int16; +#else +typedef short int yytype_int16; +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned int +# endif +#endif + +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(e) ((void) (e)) +#else +# define YYUSE(e) /* empty */ +#endif + +/* Identity function, used to suppress warnings about constant conditions. */ +#ifndef lint +# define YYID(n) (n) +#else +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static int +YYID (int yyi) +#else +static int +YYID (yyi) + int yyi; +#endif +{ + return yyi; +} +#endif + +#if ! defined yyoverflow || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef _STDLIB_H +# define _STDLIB_H 1 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined _STDLIB_H \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef _STDLIB_H +# define _STDLIB_H 1 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ + && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yytype_int16 yyss_alloc; + YYSTYPE yyvs_alloc; + YYLTYPE yyls_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + + 2 * YYSTACK_GAP_MAXIMUM) + +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (YYID (0)) + +#endif + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 2 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 606 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 57 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 17 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 101 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 162 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 289 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const yytype_uint8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 47, 2, 2, 2, 43, 30, 2, + 45, 46, 41, 39, 49, 40, 54, 42, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 55, + 33, 56, 34, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 50, 2, 51, 29, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 52, 28, 53, 48, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 31, 32, 35, 36, 37, 38, 44 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const yytype_uint16 yyprhs[] = +{ + 0, 0, 3, 4, 7, 9, 11, 13, 16, 20, + 24, 29, 36, 44, 48, 52, 55, 60, 65, 69, + 72, 75, 78, 82, 85, 87, 89, 91, 95, 99, + 103, 107, 111, 115, 119, 123, 127, 131, 135, 139, + 143, 147, 151, 155, 159, 163, 166, 169, 172, 175, + 179, 181, 185, 187, 190, 193, 194, 196, 197, 199, + 202, 207, 209, 211, 214, 216, 219, 221, 223, 225, + 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, + 247, 249, 251, 253, 255, 257, 259, 261, 263, 265, + 267, 269, 271, 273, 275, 277, 279, 281, 283, 285, + 287, 289 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yytype_int8 yyrhs[] = +{ + 58, 0, -1, -1, 58, 59, -1, 61, -1, 65, + -1, 60, -1, 6, 66, -1, 18, 63, 21, -1, + 5, 63, 21, -1, 8, 17, 67, 21, -1, 7, + 17, 45, 46, 67, 21, -1, 7, 17, 45, 64, + 46, 67, 21, -1, 15, 17, 21, -1, 12, 70, + 21, -1, 12, 21, -1, 13, 17, 68, 21, -1, + 14, 17, 68, 21, -1, 9, 70, 21, -1, 9, + 21, -1, 10, 21, -1, 11, 21, -1, 16, 62, + 21, -1, 6, 21, -1, 20, -1, 19, -1, 62, + -1, 63, 26, 63, -1, 63, 27, 63, -1, 63, + 28, 63, -1, 63, 29, 63, -1, 63, 30, 63, + -1, 63, 31, 63, -1, 63, 32, 63, -1, 63, + 35, 63, -1, 63, 36, 63, -1, 63, 34, 63, + -1, 63, 33, 63, -1, 63, 37, 63, -1, 63, + 38, 63, -1, 63, 40, 63, -1, 63, 39, 63, + -1, 63, 43, 63, -1, 63, 42, 63, -1, 63, + 41, 63, -1, 47, 63, -1, 48, 63, -1, 40, + 63, -1, 39, 63, -1, 45, 63, 46, -1, 17, + -1, 64, 49, 17, -1, 21, -1, 71, 21, -1, + 71, 21, -1, -1, 71, -1, -1, 71, -1, 4, + 17, -1, 4, 45, 17, 46, -1, 72, -1, 69, + -1, 70, 69, -1, 72, -1, 71, 72, -1, 17, + -1, 20, -1, 73, -1, 22, -1, 24, -1, 50, + -1, 51, -1, 45, -1, 46, -1, 52, -1, 53, + -1, 54, -1, 30, -1, 41, -1, 39, -1, 40, + -1, 48, -1, 47, -1, 42, -1, 43, -1, 38, + -1, 37, -1, 33, -1, 34, -1, 36, -1, 35, + -1, 32, -1, 31, -1, 29, -1, 28, -1, 27, + -1, 26, -1, 55, -1, 49, -1, 56, -1, 25, + -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const yytype_uint16 yyrline[] = +{ + 0, 181, 181, 183, 187, 190, 195, 196, 200, 203, + 209, 212, 215, 218, 226, 245, 255, 260, 265, 284, + 299, 302, 305, 326, 330, 339, 344, 345, 348, 351, + 354, 357, 360, 363, 366, 369, 372, 375, 378, 381, + 384, 387, 390, 398, 406, 409, 412, 415, 418, 421, + 427, 432, 440, 441, 445, 451, 452, 455, 457, 464, + 468, 472, 477, 481, 488, 493, 500, 504, 508, 512, + 516, 523, 524, 525, 526, 527, 528, 529, 530, 531, + 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, + 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, + 552, 553 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "COMMA_FINAL", "DEFINED", + "ELIF_EXPANDED", "HASH", "HASH_DEFINE_FUNC", "HASH_DEFINE_OBJ", + "HASH_ELIF", "HASH_ELSE", "HASH_ENDIF", "HASH_IF", "HASH_IFDEF", + "HASH_IFNDEF", "HASH_UNDEF", "HASH_VERSION", "IDENTIFIER", "IF_EXPANDED", + "INTEGER", "INTEGER_STRING", "NEWLINE", "OTHER", "PLACEHOLDER", "SPACE", + "PASTE", "OR", "AND", "'|'", "'^'", "'&'", "NOT_EQUAL", "EQUAL", "'<'", + "'>'", "GREATER_OR_EQUAL", "LESS_OR_EQUAL", "RIGHT_SHIFT", "LEFT_SHIFT", + "'+'", "'-'", "'*'", "'/'", "'%'", "UNARY", "'('", "')'", "'!'", "'~'", + "','", "'['", "']'", "'{'", "'}'", "'.'", "';'", "'='", "$accept", + "input", "line", "expanded_line", "control_line", "integer_constant", + "expression", "identifier_list", "text_line", "non_directive", + "replacement_list", "junk", "conditional_token", "conditional_tokens", + "pp_tokens", "preprocessing_token", "operator", 0 +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const yytype_uint16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 124, 94, + 38, 283, 284, 60, 62, 285, 286, 287, 288, 43, + 45, 42, 47, 37, 289, 40, 41, 33, 126, 44, + 91, 93, 123, 125, 46, 59, 61 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = +{ + 0, 57, 58, 58, 59, 59, 59, 59, 60, 60, + 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, + 61, 61, 61, 61, 62, 62, 63, 63, 63, 63, + 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, + 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, + 64, 64, 65, 65, 66, 67, 67, 68, 68, 69, + 69, 69, 70, 70, 71, 71, 72, 72, 72, 72, + 72, 73, 73, 73, 73, 73, 73, 73, 73, 73, + 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, + 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, + 73, 73 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = +{ + 0, 2, 0, 2, 1, 1, 1, 2, 3, 3, + 4, 6, 7, 3, 3, 2, 4, 4, 3, 2, + 2, 2, 3, 2, 1, 1, 1, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 2, 2, 2, 2, 3, + 1, 3, 1, 2, 2, 0, 1, 0, 1, 2, + 4, 1, 1, 2, 1, 2, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1 +}; + +/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state + STATE-NUM when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 66, 0, 67, 52, 69, + 70, 101, 97, 96, 95, 94, 78, 93, 92, 88, + 89, 91, 90, 87, 86, 80, 81, 79, 84, 85, + 73, 74, 83, 82, 99, 71, 72, 75, 76, 77, + 98, 100, 3, 6, 4, 5, 0, 64, 68, 25, + 24, 0, 0, 0, 0, 0, 26, 0, 23, 7, + 0, 0, 55, 0, 19, 62, 0, 61, 20, 21, + 15, 0, 57, 57, 0, 0, 0, 53, 65, 48, + 47, 0, 45, 46, 9, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 54, 0, 0, 56, 59, 0, 18, + 63, 14, 0, 58, 0, 13, 22, 8, 49, 27, + 28, 29, 30, 31, 32, 33, 37, 36, 34, 35, + 38, 39, 41, 40, 44, 43, 42, 50, 55, 0, + 10, 0, 16, 17, 0, 55, 0, 60, 11, 0, + 51, 12 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = +{ + -1, 1, 52, 53, 54, 66, 67, 149, 55, 69, + 115, 122, 75, 76, 116, 57, 58 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -147 +static const yytype_int16 yypact[] = +{ + -147, 112, -147, 28, -10, 55, 62, 152, -15, 59, + 192, 85, 86, 87, 51, -147, 28, -147, -147, -147, + -147, -147, -147, -147, -147, -147, -147, -147, -147, -147, + -147, -147, -147, -147, -147, -147, -147, -147, -147, -147, + -147, -147, -147, -147, -147, -147, -147, -147, -147, -147, + -147, -147, -147, -147, -147, -147, 312, -147, -147, -147, + -147, 28, 28, 28, 28, 28, -147, 428, -147, -147, + 352, 63, 392, 17, -147, -147, 232, -147, -147, -147, + -147, 272, 392, 392, 84, 89, 451, -147, -147, -147, + -147, 469, -147, -147, -147, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, -147, 60, 90, 392, -147, 96, -147, + -147, -147, 93, 392, 94, -147, -147, -147, -147, 489, + 505, 520, 534, 547, 558, 558, 18, 18, 18, 18, + 563, 563, 23, 23, -147, -147, -147, -147, 392, 32, + -147, 61, -147, -147, 110, 392, 118, -147, -147, 149, + -147, -147 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int16 yypgoto[] = +{ + -147, -147, -147, -147, -147, 157, -11, -147, -147, -147, + -146, 92, -68, 200, 0, -7, -147 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. + If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -1 +static const yytype_uint8 yytable[] = +{ + 77, 56, 154, 77, 70, 86, 78, 15, 120, 159, + 17, 68, 19, 120, 20, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 117, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 59, 60, 88, + 89, 90, 91, 92, 93, 106, 107, 108, 109, 110, + 111, 112, 118, 88, 110, 111, 112, 61, 62, 77, + 59, 60, 71, 63, 77, 64, 65, 147, 155, 72, + 79, 156, 123, 123, 129, 130, 131, 132, 133, 134, + 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, + 145, 146, 82, 83, 84, 125, 148, 157, 114, 88, + 126, 150, 2, 151, 152, 153, 88, 3, 4, 5, + 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 158, 17, 18, 19, 160, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 73, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 15, + 161, 85, 17, 74, 19, 124, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 73, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 15, + 81, 0, 17, 80, 19, 0, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 73, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 15, + 0, 0, 17, 119, 19, 0, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 73, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 15, + 0, 0, 17, 121, 19, 0, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 0, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 15, + 0, 0, 17, 87, 19, 0, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 0, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 15, + 0, 0, 17, 113, 19, 0, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 0, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 15, + 0, 0, 17, 0, 19, 0, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 0, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 94, + 0, 0, 0, 0, 95, 96, 97, 98, 99, 100, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 127, 0, 0, 0, 0, 95, 96, 97, + 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, + 108, 109, 110, 111, 112, 95, 96, 97, 98, 99, + 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 0, 0, 128, 96, 97, 98, 99, + 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 97, 98, 99, 100, 101, 102, 103, + 104, 105, 106, 107, 108, 109, 110, 111, 112, 98, + 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, + 109, 110, 111, 112, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, 100, 101, + 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 108, 109, 110, 111, 112 +}; + +static const yytype_int16 yycheck[] = +{ + 7, 1, 148, 10, 4, 16, 21, 17, 76, 155, + 20, 21, 22, 81, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 17, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 19, 20, 56, + 61, 62, 63, 64, 65, 37, 38, 39, 40, 41, + 42, 43, 45, 70, 41, 42, 43, 39, 40, 76, + 19, 20, 17, 45, 81, 47, 48, 17, 46, 17, + 21, 49, 82, 83, 95, 96, 97, 98, 99, 100, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 17, 17, 17, 21, 46, 46, 45, 116, + 21, 21, 0, 17, 21, 21, 123, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 21, 20, 21, 22, 17, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40, 41, 42, 43, 4, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 17, + 21, 14, 20, 21, 22, 83, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40, 41, 42, 43, 4, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 17, + 10, -1, 20, 21, 22, -1, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40, 41, 42, 43, 4, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 17, + -1, -1, 20, 21, 22, -1, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40, 41, 42, 43, 4, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 17, + -1, -1, 20, 21, 22, -1, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40, 41, 42, 43, -1, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 17, + -1, -1, 20, 21, 22, -1, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40, 41, 42, 43, -1, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 17, + -1, -1, 20, 21, 22, -1, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40, 41, 42, 43, -1, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 17, + -1, -1, 20, -1, 22, -1, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40, 41, 42, 43, -1, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 21, + -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, + 42, 43, 21, -1, -1, -1, -1, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, + 39, 40, 41, 42, 43, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, -1, -1, 46, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, + 43, 33, 34, 35, 36, 37, 38, 39, 40, 41, + 42, 43, 39, 40, 41, 42, 43 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = +{ + 0, 58, 0, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 59, 60, 61, 65, 71, 72, 73, 19, + 20, 39, 40, 45, 47, 48, 62, 63, 21, 66, + 71, 17, 17, 4, 21, 69, 70, 72, 21, 21, + 21, 70, 17, 17, 17, 62, 63, 21, 72, 63, + 63, 63, 63, 63, 21, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 21, 45, 67, 71, 17, 45, 21, + 69, 21, 68, 71, 68, 21, 21, 21, 46, 63, + 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, + 63, 63, 63, 63, 63, 63, 63, 17, 46, 64, + 21, 17, 21, 21, 67, 46, 49, 46, 21, 67, + 17, 21 +}; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. However, + YYFAIL appears to be in use. Nevertheless, it is formally deprecated + in Bison 2.4.2's NEWS entry, where a plan to phase it out is + discussed. */ + +#define YYFAIL goto yyerrlab +#if defined YYFAIL + /* This is here to suppress warnings from the GCC cpp's + -Wunused-macros. Normally we don't worry about that warning, but + some users do, and we want to make it easy for users to remove + YYFAIL uses, which will produce warnings from Bison 2.5. */ +#endif + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + yytoken = YYTRANSLATE (yychar); \ + YYPOPSTACK (1); \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (&yylloc, parser, YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ +while (YYID (0)) + + +#define YYTERROR 1 +#define YYERRCODE 256 + + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (YYID (0)) +#endif + + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#ifndef YY_LOCATION_PRINT +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +#endif + + +/* YYLEX -- calling `yylex' with the right arguments. */ + +#ifdef YYLEX_PARAM +# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) +#else +# define YYLEX yylex (&yylval, &yylloc, parser) +#endif + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (YYID (0)) + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value, Location, parser); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (YYID (0)) + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, glcpp_parser_t *parser) +#else +static void +yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, parser) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; + YYLTYPE const * const yylocationp; + glcpp_parser_t *parser; +#endif +{ + if (!yyvaluep) + return; + YYUSE (yylocationp); + YYUSE (parser); +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# else + YYUSE (yyoutput); +# endif + switch (yytype) + { + default: + break; + } +} + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, glcpp_parser_t *parser) +#else +static void +yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, parser) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; + YYLTYPE const * const yylocationp; + glcpp_parser_t *parser; +#endif +{ + if (yytype < YYNTOKENS) + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + YY_LOCATION_PRINT (yyoutput, *yylocationp); + YYFPRINTF (yyoutput, ": "); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, parser); + YYFPRINTF (yyoutput, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +#else +static void +yy_stack_print (yybottom, yytop) + yytype_int16 *yybottom; + yytype_int16 *yytop; +#endif +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (YYID (0)) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, glcpp_parser_t *parser) +#else +static void +yy_reduce_print (yyvsp, yylsp, yyrule, parser) + YYSTYPE *yyvsp; + YYLTYPE *yylsp; + int yyrule; + glcpp_parser_t *parser; +#endif +{ + int yynrhs = yyr2[yyrule]; + int yyi; + unsigned long int yylno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], + &(yyvsp[(yyi + 1) - (yynrhs)]) + , &(yylsp[(yyi + 1) - (yynrhs)]) , parser); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyvsp, yylsp, Rule, parser); \ +} while (YYID (0)) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static YYSIZE_T +yystrlen (const char *yystr) +#else +static YYSIZE_T +yystrlen (yystr) + const char *yystr; +#endif +{ + YYSIZE_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; +} +# endif +# endif + +# ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static char * +yystpcpy (char *yydest, const char *yysrc) +#else +static char * +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +#endif +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYSIZE_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYSIZE_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return yystrlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +/* Copy into YYRESULT an error message about the unexpected token + YYCHAR while in state YYSTATE. Return the number of bytes copied, + including the terminating null byte. If YYRESULT is null, do not + copy anything; just return the number of bytes that would be + copied. As a special case, return 0 if an ordinary "syntax error" + message will do. Return YYSIZE_MAXIMUM if overflow occurs during + size calculation. */ +static YYSIZE_T +yysyntax_error (char *yyresult, int yystate, int yychar) +{ + int yyn = yypact[yystate]; + + if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) + return 0; + else + { + int yytype = YYTRANSLATE (yychar); + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + int yysize_overflow = 0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + int yyx; + +# if 0 + /* This is so xgettext sees the translatable formats that are + constructed on the fly. */ + YY_("syntax error, unexpected %s"); + YY_("syntax error, unexpected %s, expecting %s"); + YY_("syntax error, unexpected %s, expecting %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); +# endif + char *yyfmt; + char const *yyf; + static char const yyunexpected[] = "syntax error, unexpected %s"; + static char const yyexpecting[] = ", expecting %s"; + static char const yyor[] = " or %s"; + char yyformat[sizeof yyunexpected + + sizeof yyexpecting - 1 + + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) + * (sizeof yyor - 1))]; + char const *yyprefix = yyexpecting; + + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yycount = 1; + + yyarg[0] = yytname[yytype]; + yyfmt = yystpcpy (yyformat, yyunexpected); + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + yyformat[sizeof yyunexpected - 1] = '\0'; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + yyfmt = yystpcpy (yyfmt, yyprefix); + yyprefix = yyor; + } + + yyf = YY_(yyformat); + yysize1 = yysize + yystrlen (yyf); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + + if (yysize_overflow) + return YYSIZE_MAXIMUM; + + if (yyresult) + { + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + char *yyp = yyresult; + int yyi = 0; + while ((*yyp = *yyf) != '\0') + { + if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyf += 2; + } + else + { + yyp++; + yyf++; + } + } + } + return yysize; + } +} +#endif /* YYERROR_VERBOSE */ + + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, glcpp_parser_t *parser) +#else +static void +yydestruct (yymsg, yytype, yyvaluep, yylocationp, parser) + const char *yymsg; + int yytype; + YYSTYPE *yyvaluep; + YYLTYPE *yylocationp; + glcpp_parser_t *parser; +#endif +{ + YYUSE (yyvaluep); + YYUSE (yylocationp); + YYUSE (parser); + + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + + default: + break; + } +} + +/* Prevent warnings from -Wmissing-prototypes. */ +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (glcpp_parser_t *parser); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + + + + + +/*-------------------------. +| yyparse or yypush_parse. | +`-------------------------*/ + +#ifdef YYPARSE_PARAM +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void *YYPARSE_PARAM) +#else +int +yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +#endif +#else /* ! YYPARSE_PARAM */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (glcpp_parser_t *parser) +#else +int +yyparse (parser) + glcpp_parser_t *parser; +#endif +#endif +{ +/* The lookahead symbol. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; + +/* Location data for the lookahead symbol. */ +YYLTYPE yylloc; + + /* Number of syntax errors so far. */ + int yynerrs; + + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + + /* The stacks and their tools: + `yyss': related to states. + `yyvs': related to semantic values. + `yyls': related to locations. + + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + /* The location stack. */ + YYLTYPE yylsa[YYINITDEPTH]; + YYLTYPE *yyls; + YYLTYPE *yylsp; + + /* The locations where the error started and ended. */ + YYLTYPE yyerror_range[3]; + + YYSIZE_T yystacksize; + + int yyn; + int yyresult; + /* Lookahead token as an internal (translated) token number. */ + int yytoken; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + YYLTYPE yyloc; + +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYSIZE_T yymsg_alloc = sizeof yymsgbuf; +#endif + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + yytoken = 0; + yyss = yyssa; + yyvs = yyvsa; + yyls = yylsa; + yystacksize = YYINITDEPTH; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + yyssp = yyss; + yyvsp = yyvs; + yylsp = yyls; + +#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + /* Initialize the default location before parsing starts. */ + yylloc.first_line = yylloc.last_line = 1; + yylloc.first_column = yylloc.last_column = 1; +#endif + +/* User initialization code. */ + +/* Line 1251 of yacc.c */ +#line 148 "glcpp/glcpp-parse.y" +{ + yylloc.first_line = 1; + yylloc.first_column = 1; + yylloc.last_line = 1; + yylloc.last_column = 1; + yylloc.source = 0; +} + +/* Line 1251 of yacc.c */ +#line 1618 "glcpp/glcpp-parse.c" + yylsp[0] = yylloc; + + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + YYLTYPE *yyls1 = yyls; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yyls1, yysize * sizeof (*yylsp), + &yystacksize); + + yyls = yyls1; + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); + YYSTACK_RELOCATE (yyls_alloc, yyls); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + yylsp = yyls + yysize - 1; + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yyn == YYPACT_NINF) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yyn == 0 || yyn == YYTABLE_NINF) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the shifted token. */ + yychar = YYEMPTY; + + yystate = yyn; + *++yyvsp = yylval; + *++yylsp = yylloc; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + /* Default location. */ + YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 4: + +/* Line 1464 of yacc.c */ +#line 187 "glcpp/glcpp-parse.y" + { + ralloc_strcat (&parser->output, "\n"); + ;} + break; + + case 5: + +/* Line 1464 of yacc.c */ +#line 190 "glcpp/glcpp-parse.y" + { + _glcpp_parser_print_expanded_token_list (parser, (yyvsp[(1) - (1)].token_list)); + ralloc_strcat (&parser->output, "\n"); + ralloc_free ((yyvsp[(1) - (1)].token_list)); + ;} + break; + + case 8: + +/* Line 1464 of yacc.c */ +#line 200 "glcpp/glcpp-parse.y" + { + _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (3)]), (yyvsp[(2) - (3)].ival)); + ;} + break; + + case 9: + +/* Line 1464 of yacc.c */ +#line 203 "glcpp/glcpp-parse.y" + { + _glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (3)]), "elif", (yyvsp[(2) - (3)].ival)); + ;} + break; + + case 10: + +/* Line 1464 of yacc.c */ +#line 209 "glcpp/glcpp-parse.y" + { + _define_object_macro (parser, & (yylsp[(2) - (4)]), (yyvsp[(2) - (4)].str), (yyvsp[(3) - (4)].token_list)); + ;} + break; + + case 11: + +/* Line 1464 of yacc.c */ +#line 212 "glcpp/glcpp-parse.y" + { + _define_function_macro (parser, & (yylsp[(2) - (6)]), (yyvsp[(2) - (6)].str), NULL, (yyvsp[(5) - (6)].token_list)); + ;} + break; + + case 12: + +/* Line 1464 of yacc.c */ +#line 215 "glcpp/glcpp-parse.y" + { + _define_function_macro (parser, & (yylsp[(2) - (7)]), (yyvsp[(2) - (7)].str), (yyvsp[(4) - (7)].string_list), (yyvsp[(6) - (7)].token_list)); + ;} + break; + + case 13: + +/* Line 1464 of yacc.c */ +#line 218 "glcpp/glcpp-parse.y" + { + macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (3)].str)); + if (macro) { + hash_table_remove (parser->defines, (yyvsp[(2) - (3)].str)); + ralloc_free (macro); + } + ralloc_free ((yyvsp[(2) - (3)].str)); + ;} + break; + + case 14: + +/* Line 1464 of yacc.c */ +#line 226 "glcpp/glcpp-parse.y" + { + /* Be careful to only evaluate the 'if' expression if + * we are not skipping. When we are skipping, we + * simply push a new 0-valued 'if' onto the skip + * stack. + * + * This avoids generating diagnostics for invalid + * expressions that are being skipped. */ + if (parser->skip_stack == NULL || + parser->skip_stack->type == SKIP_NO_SKIP) + { + _glcpp_parser_expand_if (parser, IF_EXPANDED, (yyvsp[(2) - (3)].token_list)); + } + else + { + _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (3)]), 0); + parser->skip_stack->type = SKIP_TO_ENDIF; + } + ;} + break; + + case 15: + +/* Line 1464 of yacc.c */ +#line 245 "glcpp/glcpp-parse.y" + { + /* #if without an expression is only an error if we + * are not skipping */ + if (parser->skip_stack == NULL || + parser->skip_stack->type == SKIP_NO_SKIP) + { + glcpp_error(& (yylsp[(1) - (2)]), parser, "#if with no expression"); + } + _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (2)]), 0); + ;} + break; + + case 16: + +/* Line 1464 of yacc.c */ +#line 255 "glcpp/glcpp-parse.y" + { + macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (4)].str)); + ralloc_free ((yyvsp[(2) - (4)].str)); + _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (4)]), macro != NULL); + ;} + break; + + case 17: + +/* Line 1464 of yacc.c */ +#line 260 "glcpp/glcpp-parse.y" + { + macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (4)].str)); + ralloc_free ((yyvsp[(2) - (4)].str)); + _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (4)]), macro == NULL); + ;} + break; + + case 18: + +/* Line 1464 of yacc.c */ +#line 265 "glcpp/glcpp-parse.y" + { + /* Be careful to only evaluate the 'elif' expression + * if we are not skipping. When we are skipping, we + * simply change to a 0-valued 'elif' on the skip + * stack. + * + * This avoids generating diagnostics for invalid + * expressions that are being skipped. */ + if (parser->skip_stack && + parser->skip_stack->type == SKIP_TO_ELSE) + { + _glcpp_parser_expand_if (parser, ELIF_EXPANDED, (yyvsp[(2) - (3)].token_list)); + } + else + { + _glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (3)]), + "elif", 0); + } + ;} + break; + + case 19: + +/* Line 1464 of yacc.c */ +#line 284 "glcpp/glcpp-parse.y" + { + /* #elif without an expression is an error unless we + * are skipping. */ + if (parser->skip_stack && + parser->skip_stack->type == SKIP_TO_ELSE) + { + glcpp_error(& (yylsp[(1) - (2)]), parser, "#elif with no expression"); + } + else + { + _glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (2)]), + "elif", 0); + glcpp_warning(& (yylsp[(1) - (2)]), parser, "ignoring illegal #elif without expression"); + } + ;} + break; + + case 20: + +/* Line 1464 of yacc.c */ +#line 299 "glcpp/glcpp-parse.y" + { + _glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (2)]), "else", 1); + ;} + break; + + case 21: + +/* Line 1464 of yacc.c */ +#line 302 "glcpp/glcpp-parse.y" + { + _glcpp_parser_skip_stack_pop (parser, & (yylsp[(1) - (2)])); + ;} + break; + + case 22: + +/* Line 1464 of yacc.c */ +#line 305 "glcpp/glcpp-parse.y" + { + macro_t *macro = hash_table_find (parser->defines, "__VERSION__"); + if (macro) { + hash_table_remove (parser->defines, "__VERSION__"); + ralloc_free (macro); + } + add_builtin_define (parser, "__VERSION__", (yyvsp[(2) - (3)].ival)); + + if ((yyvsp[(2) - (3)].ival) == 100) + add_builtin_define (parser, "GL_ES", 1); + + /* Currently, all ES2 implementations support highp in the + * fragment shader, so we always define this macro in ES2. + * If we ever get a driver that doesn't support highp, we'll + * need to add a flag to the gl_context and check that here. + */ + if ((yyvsp[(2) - (3)].ival) >= 130 || (yyvsp[(2) - (3)].ival) == 100) + add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1); + + ralloc_asprintf_append (&parser->output, "#version %" PRIiMAX, (yyvsp[(2) - (3)].ival)); + ;} + break; + + case 24: + +/* Line 1464 of yacc.c */ +#line 330 "glcpp/glcpp-parse.y" + { + if (strlen ((yyvsp[(1) - (1)].str)) >= 3 && strncmp ((yyvsp[(1) - (1)].str), "0x", 2) == 0) { + (yyval.ival) = strtoll ((yyvsp[(1) - (1)].str) + 2, NULL, 16); + } else if ((yyvsp[(1) - (1)].str)[0] == '0') { + (yyval.ival) = strtoll ((yyvsp[(1) - (1)].str), NULL, 8); + } else { + (yyval.ival) = strtoll ((yyvsp[(1) - (1)].str), NULL, 10); + } + ;} + break; + + case 25: + +/* Line 1464 of yacc.c */ +#line 339 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (1)].ival); + ;} + break; + + case 27: + +/* Line 1464 of yacc.c */ +#line 345 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) || (yyvsp[(3) - (3)].ival); + ;} + break; + + case 28: + +/* Line 1464 of yacc.c */ +#line 348 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) && (yyvsp[(3) - (3)].ival); + ;} + break; + + case 29: + +/* Line 1464 of yacc.c */ +#line 351 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) | (yyvsp[(3) - (3)].ival); + ;} + break; + + case 30: + +/* Line 1464 of yacc.c */ +#line 354 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) ^ (yyvsp[(3) - (3)].ival); + ;} + break; + + case 31: + +/* Line 1464 of yacc.c */ +#line 357 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) & (yyvsp[(3) - (3)].ival); + ;} + break; + + case 32: + +/* Line 1464 of yacc.c */ +#line 360 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) != (yyvsp[(3) - (3)].ival); + ;} + break; + + case 33: + +/* Line 1464 of yacc.c */ +#line 363 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) == (yyvsp[(3) - (3)].ival); + ;} + break; + + case 34: + +/* Line 1464 of yacc.c */ +#line 366 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) >= (yyvsp[(3) - (3)].ival); + ;} + break; + + case 35: + +/* Line 1464 of yacc.c */ +#line 369 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) <= (yyvsp[(3) - (3)].ival); + ;} + break; + + case 36: + +/* Line 1464 of yacc.c */ +#line 372 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) > (yyvsp[(3) - (3)].ival); + ;} + break; + + case 37: + +/* Line 1464 of yacc.c */ +#line 375 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) < (yyvsp[(3) - (3)].ival); + ;} + break; + + case 38: + +/* Line 1464 of yacc.c */ +#line 378 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) >> (yyvsp[(3) - (3)].ival); + ;} + break; + + case 39: + +/* Line 1464 of yacc.c */ +#line 381 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) << (yyvsp[(3) - (3)].ival); + ;} + break; + + case 40: + +/* Line 1464 of yacc.c */ +#line 384 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) - (yyvsp[(3) - (3)].ival); + ;} + break; + + case 41: + +/* Line 1464 of yacc.c */ +#line 387 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) + (yyvsp[(3) - (3)].ival); + ;} + break; + + case 42: + +/* Line 1464 of yacc.c */ +#line 390 "glcpp/glcpp-parse.y" + { + if ((yyvsp[(3) - (3)].ival) == 0) { + yyerror (& (yylsp[(1) - (3)]), parser, + "zero modulus in preprocessor directive"); + } else { + (yyval.ival) = (yyvsp[(1) - (3)].ival) % (yyvsp[(3) - (3)].ival); + } + ;} + break; + + case 43: + +/* Line 1464 of yacc.c */ +#line 398 "glcpp/glcpp-parse.y" + { + if ((yyvsp[(3) - (3)].ival) == 0) { + yyerror (& (yylsp[(1) - (3)]), parser, + "division by 0 in preprocessor directive"); + } else { + (yyval.ival) = (yyvsp[(1) - (3)].ival) / (yyvsp[(3) - (3)].ival); + } + ;} + break; + + case 44: + +/* Line 1464 of yacc.c */ +#line 406 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(1) - (3)].ival) * (yyvsp[(3) - (3)].ival); + ;} + break; + + case 45: + +/* Line 1464 of yacc.c */ +#line 409 "glcpp/glcpp-parse.y" + { + (yyval.ival) = ! (yyvsp[(2) - (2)].ival); + ;} + break; + + case 46: + +/* Line 1464 of yacc.c */ +#line 412 "glcpp/glcpp-parse.y" + { + (yyval.ival) = ~ (yyvsp[(2) - (2)].ival); + ;} + break; + + case 47: + +/* Line 1464 of yacc.c */ +#line 415 "glcpp/glcpp-parse.y" + { + (yyval.ival) = - (yyvsp[(2) - (2)].ival); + ;} + break; + + case 48: + +/* Line 1464 of yacc.c */ +#line 418 "glcpp/glcpp-parse.y" + { + (yyval.ival) = + (yyvsp[(2) - (2)].ival); + ;} + break; + + case 49: + +/* Line 1464 of yacc.c */ +#line 421 "glcpp/glcpp-parse.y" + { + (yyval.ival) = (yyvsp[(2) - (3)].ival); + ;} + break; + + case 50: + +/* Line 1464 of yacc.c */ +#line 427 "glcpp/glcpp-parse.y" + { + (yyval.string_list) = _string_list_create (parser); + _string_list_append_item ((yyval.string_list), (yyvsp[(1) - (1)].str)); + ralloc_steal ((yyval.string_list), (yyvsp[(1) - (1)].str)); + ;} + break; + + case 51: + +/* Line 1464 of yacc.c */ +#line 432 "glcpp/glcpp-parse.y" + { + (yyval.string_list) = (yyvsp[(1) - (3)].string_list); + _string_list_append_item ((yyval.string_list), (yyvsp[(3) - (3)].str)); + ralloc_steal ((yyval.string_list), (yyvsp[(3) - (3)].str)); + ;} + break; + + case 52: + +/* Line 1464 of yacc.c */ +#line 440 "glcpp/glcpp-parse.y" + { (yyval.token_list) = NULL; ;} + break; + + case 54: + +/* Line 1464 of yacc.c */ +#line 445 "glcpp/glcpp-parse.y" + { + yyerror (& (yylsp[(1) - (2)]), parser, "Invalid tokens after #"); + ;} + break; + + case 55: + +/* Line 1464 of yacc.c */ +#line 451 "glcpp/glcpp-parse.y" + { (yyval.token_list) = NULL; ;} + break; + + case 58: + +/* Line 1464 of yacc.c */ +#line 457 "glcpp/glcpp-parse.y" + { + glcpp_warning(&(yylsp[(1) - (1)]), parser, "extra tokens at end of directive"); + ;} + break; + + case 59: + +/* Line 1464 of yacc.c */ +#line 464 "glcpp/glcpp-parse.y" + { + int v = hash_table_find (parser->defines, (yyvsp[(2) - (2)].str)) ? 1 : 0; + (yyval.token) = _token_create_ival (parser, INTEGER, v); + ;} + break; + + case 60: + +/* Line 1464 of yacc.c */ +#line 468 "glcpp/glcpp-parse.y" + { + int v = hash_table_find (parser->defines, (yyvsp[(3) - (4)].str)) ? 1 : 0; + (yyval.token) = _token_create_ival (parser, INTEGER, v); + ;} + break; + + case 62: + +/* Line 1464 of yacc.c */ +#line 477 "glcpp/glcpp-parse.y" + { + (yyval.token_list) = _token_list_create (parser); + _token_list_append ((yyval.token_list), (yyvsp[(1) - (1)].token)); + ;} + break; + + case 63: + +/* Line 1464 of yacc.c */ +#line 481 "glcpp/glcpp-parse.y" + { + (yyval.token_list) = (yyvsp[(1) - (2)].token_list); + _token_list_append ((yyval.token_list), (yyvsp[(2) - (2)].token)); + ;} + break; + + case 64: + +/* Line 1464 of yacc.c */ +#line 488 "glcpp/glcpp-parse.y" + { + parser->space_tokens = 1; + (yyval.token_list) = _token_list_create (parser); + _token_list_append ((yyval.token_list), (yyvsp[(1) - (1)].token)); + ;} + break; + + case 65: + +/* Line 1464 of yacc.c */ +#line 493 "glcpp/glcpp-parse.y" + { + (yyval.token_list) = (yyvsp[(1) - (2)].token_list); + _token_list_append ((yyval.token_list), (yyvsp[(2) - (2)].token)); + ;} + break; + + case 66: + +/* Line 1464 of yacc.c */ +#line 500 "glcpp/glcpp-parse.y" + { + (yyval.token) = _token_create_str (parser, IDENTIFIER, (yyvsp[(1) - (1)].str)); + (yyval.token)->location = yylloc; + ;} + break; + + case 67: + +/* Line 1464 of yacc.c */ +#line 504 "glcpp/glcpp-parse.y" + { + (yyval.token) = _token_create_str (parser, INTEGER_STRING, (yyvsp[(1) - (1)].str)); + (yyval.token)->location = yylloc; + ;} + break; + + case 68: + +/* Line 1464 of yacc.c */ +#line 508 "glcpp/glcpp-parse.y" + { + (yyval.token) = _token_create_ival (parser, (yyvsp[(1) - (1)].ival), (yyvsp[(1) - (1)].ival)); + (yyval.token)->location = yylloc; + ;} + break; + + case 69: + +/* Line 1464 of yacc.c */ +#line 512 "glcpp/glcpp-parse.y" + { + (yyval.token) = _token_create_str (parser, OTHER, (yyvsp[(1) - (1)].str)); + (yyval.token)->location = yylloc; + ;} + break; + + case 70: + +/* Line 1464 of yacc.c */ +#line 516 "glcpp/glcpp-parse.y" + { + (yyval.token) = _token_create_ival (parser, SPACE, SPACE); + (yyval.token)->location = yylloc; + ;} + break; + + case 71: + +/* Line 1464 of yacc.c */ +#line 523 "glcpp/glcpp-parse.y" + { (yyval.ival) = '['; ;} + break; + + case 72: + +/* Line 1464 of yacc.c */ +#line 524 "glcpp/glcpp-parse.y" + { (yyval.ival) = ']'; ;} + break; + + case 73: + +/* Line 1464 of yacc.c */ +#line 525 "glcpp/glcpp-parse.y" + { (yyval.ival) = '('; ;} + break; + + case 74: + +/* Line 1464 of yacc.c */ +#line 526 "glcpp/glcpp-parse.y" + { (yyval.ival) = ')'; ;} + break; + + case 75: + +/* Line 1464 of yacc.c */ +#line 527 "glcpp/glcpp-parse.y" + { (yyval.ival) = '{'; ;} + break; + + case 76: + +/* Line 1464 of yacc.c */ +#line 528 "glcpp/glcpp-parse.y" + { (yyval.ival) = '}'; ;} + break; + + case 77: + +/* Line 1464 of yacc.c */ +#line 529 "glcpp/glcpp-parse.y" + { (yyval.ival) = '.'; ;} + break; + + case 78: + +/* Line 1464 of yacc.c */ +#line 530 "glcpp/glcpp-parse.y" + { (yyval.ival) = '&'; ;} + break; + + case 79: + +/* Line 1464 of yacc.c */ +#line 531 "glcpp/glcpp-parse.y" + { (yyval.ival) = '*'; ;} + break; + + case 80: + +/* Line 1464 of yacc.c */ +#line 532 "glcpp/glcpp-parse.y" + { (yyval.ival) = '+'; ;} + break; + + case 81: + +/* Line 1464 of yacc.c */ +#line 533 "glcpp/glcpp-parse.y" + { (yyval.ival) = '-'; ;} + break; + + case 82: + +/* Line 1464 of yacc.c */ +#line 534 "glcpp/glcpp-parse.y" + { (yyval.ival) = '~'; ;} + break; + + case 83: + +/* Line 1464 of yacc.c */ +#line 535 "glcpp/glcpp-parse.y" + { (yyval.ival) = '!'; ;} + break; + + case 84: + +/* Line 1464 of yacc.c */ +#line 536 "glcpp/glcpp-parse.y" + { (yyval.ival) = '/'; ;} + break; + + case 85: + +/* Line 1464 of yacc.c */ +#line 537 "glcpp/glcpp-parse.y" + { (yyval.ival) = '%'; ;} + break; + + case 86: + +/* Line 1464 of yacc.c */ +#line 538 "glcpp/glcpp-parse.y" + { (yyval.ival) = LEFT_SHIFT; ;} + break; + + case 87: + +/* Line 1464 of yacc.c */ +#line 539 "glcpp/glcpp-parse.y" + { (yyval.ival) = RIGHT_SHIFT; ;} + break; + + case 88: + +/* Line 1464 of yacc.c */ +#line 540 "glcpp/glcpp-parse.y" + { (yyval.ival) = '<'; ;} + break; + + case 89: + +/* Line 1464 of yacc.c */ +#line 541 "glcpp/glcpp-parse.y" + { (yyval.ival) = '>'; ;} + break; + + case 90: + +/* Line 1464 of yacc.c */ +#line 542 "glcpp/glcpp-parse.y" + { (yyval.ival) = LESS_OR_EQUAL; ;} + break; + + case 91: + +/* Line 1464 of yacc.c */ +#line 543 "glcpp/glcpp-parse.y" + { (yyval.ival) = GREATER_OR_EQUAL; ;} + break; + + case 92: + +/* Line 1464 of yacc.c */ +#line 544 "glcpp/glcpp-parse.y" + { (yyval.ival) = EQUAL; ;} + break; + + case 93: + +/* Line 1464 of yacc.c */ +#line 545 "glcpp/glcpp-parse.y" + { (yyval.ival) = NOT_EQUAL; ;} + break; + + case 94: + +/* Line 1464 of yacc.c */ +#line 546 "glcpp/glcpp-parse.y" + { (yyval.ival) = '^'; ;} + break; + + case 95: + +/* Line 1464 of yacc.c */ +#line 547 "glcpp/glcpp-parse.y" + { (yyval.ival) = '|'; ;} + break; + + case 96: + +/* Line 1464 of yacc.c */ +#line 548 "glcpp/glcpp-parse.y" + { (yyval.ival) = AND; ;} + break; + + case 97: + +/* Line 1464 of yacc.c */ +#line 549 "glcpp/glcpp-parse.y" + { (yyval.ival) = OR; ;} + break; + + case 98: + +/* Line 1464 of yacc.c */ +#line 550 "glcpp/glcpp-parse.y" + { (yyval.ival) = ';'; ;} + break; + + case 99: + +/* Line 1464 of yacc.c */ +#line 551 "glcpp/glcpp-parse.y" + { (yyval.ival) = ','; ;} + break; + + case 100: + +/* Line 1464 of yacc.c */ +#line 552 "glcpp/glcpp-parse.y" + { (yyval.ival) = '='; ;} + break; + + case 101: + +/* Line 1464 of yacc.c */ +#line 553 "glcpp/glcpp-parse.y" + { (yyval.ival) = PASTE; ;} + break; + + + +/* Line 1464 of yacc.c */ +#line 2662 "glcpp/glcpp-parse.c" + default: break; + } + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + *++yylsp = yyloc; + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if ! YYERROR_VERBOSE + yyerror (&yylloc, parser, YY_("syntax error")); +#else + { + YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); + if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) + { + YYSIZE_T yyalloc = 2 * yysize; + if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) + yyalloc = YYSTACK_ALLOC_MAXIMUM; + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yyalloc); + if (yymsg) + yymsg_alloc = yyalloc; + else + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + } + } + + if (0 < yysize && yysize <= yymsg_alloc) + { + (void) yysyntax_error (yymsg, yystate, yychar); + yyerror (&yylloc, parser, yymsg); + } + else + { + yyerror (&yylloc, parser, YY_("syntax error")); + if (yysize != 0) + goto yyexhaustedlab; + } + } +#endif + } + + yyerror_range[1] = yylloc; + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval, &yylloc, parser); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (/*CONSTCOND*/ 0) + goto yyerrorlab; + + yyerror_range[1] = yylsp[1-yylen]; + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (yyn != YYPACT_NINF) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + yyerror_range[1] = *yylsp; + yydestruct ("Error: popping", + yystos[yystate], yyvsp, yylsp, parser); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + *++yyvsp = yylval; + + yyerror_range[2] = yylloc; + /* Using YYLLOC is tempting, but would change the location of + the lookahead. YYLOC is available though. */ + YYLLOC_DEFAULT (yyloc, yyerror_range, 2); + *++yylsp = yyloc; + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#if !defined(yyoverflow) || YYERROR_VERBOSE +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (&yylloc, parser, YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: + if (yychar != YYEMPTY) + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval, &yylloc, parser); + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[*yyssp], yyvsp, yylsp, parser); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif +#if YYERROR_VERBOSE + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); +#endif + /* Make sure YYID is used. */ + return YYID (yyresult); +} + + + +/* Line 1684 of yacc.c */ +#line 556 "glcpp/glcpp-parse.y" + + +string_list_t * +_string_list_create (void *ctx) +{ + string_list_t *list; + + list = ralloc (ctx, string_list_t); + list->head = NULL; + list->tail = NULL; + + return list; +} + +void +_string_list_append_item (string_list_t *list, const char *str) +{ + string_node_t *node; + + node = ralloc (list, string_node_t); + node->str = ralloc_strdup (node, str); + + node->next = NULL; + + if (list->head == NULL) { + list->head = node; + } else { + list->tail->next = node; + } + + list->tail = node; +} + +int +_string_list_contains (string_list_t *list, const char *member, int *index) +{ + string_node_t *node; + int i; + + if (list == NULL) + return 0; + + for (i = 0, node = list->head; node; i++, node = node->next) { + if (strcmp (node->str, member) == 0) { + if (index) + *index = i; + return 1; + } + } + + return 0; +} + +int +_string_list_length (string_list_t *list) +{ + int length = 0; + string_node_t *node; + + if (list == NULL) + return 0; + + for (node = list->head; node; node = node->next) + length++; + + return length; +} + +int +_string_list_equal (string_list_t *a, string_list_t *b) +{ + string_node_t *node_a, *node_b; + + if (a == NULL && b == NULL) + return 1; + + if (a == NULL || b == NULL) + return 0; + + for (node_a = a->head, node_b = b->head; + node_a && node_b; + node_a = node_a->next, node_b = node_b->next) + { + if (strcmp (node_a->str, node_b->str)) + return 0; + } + + /* Catch the case of lists being different lengths, (which + * would cause the loop above to terminate after the shorter + * list). */ + return node_a == node_b; +} + +argument_list_t * +_argument_list_create (void *ctx) +{ + argument_list_t *list; + + list = ralloc (ctx, argument_list_t); + list->head = NULL; + list->tail = NULL; + + return list; +} + +void +_argument_list_append (argument_list_t *list, token_list_t *argument) +{ + argument_node_t *node; + + node = ralloc (list, argument_node_t); + node->argument = argument; + + node->next = NULL; + + if (list->head == NULL) { + list->head = node; + } else { + list->tail->next = node; + } + + list->tail = node; +} + +int +_argument_list_length (argument_list_t *list) +{ + int length = 0; + argument_node_t *node; + + if (list == NULL) + return 0; + + for (node = list->head; node; node = node->next) + length++; + + return length; +} + +token_list_t * +_argument_list_member_at (argument_list_t *list, int index) +{ + argument_node_t *node; + int i; + + if (list == NULL) + return NULL; + + node = list->head; + for (i = 0; i < index; i++) { + node = node->next; + if (node == NULL) + break; + } + + if (node) + return node->argument; + + return NULL; +} + +/* Note: This function ralloc_steal()s the str pointer. */ +token_t * +_token_create_str (void *ctx, int type, char *str) +{ + token_t *token; + + token = ralloc (ctx, token_t); + token->type = type; + token->value.str = str; + + ralloc_steal (token, str); + + return token; +} + +token_t * +_token_create_ival (void *ctx, int type, int ival) +{ + token_t *token; + + token = ralloc (ctx, token_t); + token->type = type; + token->value.ival = ival; + + return token; +} + +token_list_t * +_token_list_create (void *ctx) +{ + token_list_t *list; + + list = ralloc (ctx, token_list_t); + list->head = NULL; + list->tail = NULL; + list->non_space_tail = NULL; + + return list; +} + +void +_token_list_append (token_list_t *list, token_t *token) +{ + token_node_t *node; + + node = ralloc (list, token_node_t); + node->token = token; + node->next = NULL; + + ralloc_steal (list, token); + + if (list->head == NULL) { + list->head = node; + } else { + list->tail->next = node; + } + + list->tail = node; + if (token->type != SPACE) + list->non_space_tail = node; +} + +void +_token_list_append_list (token_list_t *list, token_list_t *tail) +{ + if (tail == NULL || tail->head == NULL) + return; + + if (list->head == NULL) { + list->head = tail->head; + } else { + list->tail->next = tail->head; + } + + list->tail = tail->tail; + list->non_space_tail = tail->non_space_tail; +} + +static token_list_t * +_token_list_copy (void *ctx, token_list_t *other) +{ + token_list_t *copy; + token_node_t *node; + + if (other == NULL) + return NULL; + + copy = _token_list_create (ctx); + for (node = other->head; node; node = node->next) { + token_t *new_token = ralloc (copy, token_t); + *new_token = *node->token; + _token_list_append (copy, new_token); + } + + return copy; +} + +static void +_token_list_trim_trailing_space (token_list_t *list) +{ + token_node_t *tail, *next; + + if (list->non_space_tail) { + tail = list->non_space_tail->next; + list->non_space_tail->next = NULL; + list->tail = list->non_space_tail; + + while (tail) { + next = tail->next; + ralloc_free (tail); + tail = next; + } + } +} + +int +_token_list_is_empty_ignoring_space (token_list_t *l) +{ + token_node_t *n; + + if (l == NULL) + return 1; + + n = l->head; + while (n != NULL && n->token->type == SPACE) + n = n->next; + + return n == NULL; +} + +int +_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b) +{ + token_node_t *node_a, *node_b; + + if (a == NULL || b == NULL) { + int a_empty = _token_list_is_empty_ignoring_space(a); + int b_empty = _token_list_is_empty_ignoring_space(b); + return a_empty == b_empty; + } + + node_a = a->head; + node_b = b->head; + + while (1) + { + if (node_a == NULL && node_b == NULL) + break; + + if (node_a == NULL || node_b == NULL) + return 0; + + if (node_a->token->type == SPACE) { + node_a = node_a->next; + continue; + } + + if (node_b->token->type == SPACE) { + node_b = node_b->next; + continue; + } + + if (node_a->token->type != node_b->token->type) + return 0; + + switch (node_a->token->type) { + case INTEGER: + if (node_a->token->value.ival != + node_b->token->value.ival) + { + return 0; + } + break; + case IDENTIFIER: + case INTEGER_STRING: + case OTHER: + if (strcmp (node_a->token->value.str, + node_b->token->value.str)) + { + return 0; + } + break; + } + + node_a = node_a->next; + node_b = node_b->next; + } + + return 1; +} + +static void +_token_print (char **out, token_t *token) +{ + if (token->type < 256) { + ralloc_asprintf_append (out, "%c", token->type); + return; + } + + switch (token->type) { + case INTEGER: + ralloc_asprintf_append (out, "%" PRIiMAX, token->value.ival); + break; + case IDENTIFIER: + case INTEGER_STRING: + case OTHER: + ralloc_strcat (out, token->value.str); + break; + case SPACE: + ralloc_strcat (out, " "); + break; + case LEFT_SHIFT: + ralloc_strcat (out, "<<"); + break; + case RIGHT_SHIFT: + ralloc_strcat (out, ">>"); + break; + case LESS_OR_EQUAL: + ralloc_strcat (out, "<="); + break; + case GREATER_OR_EQUAL: + ralloc_strcat (out, ">="); + break; + case EQUAL: + ralloc_strcat (out, "=="); + break; + case NOT_EQUAL: + ralloc_strcat (out, "!="); + break; + case AND: + ralloc_strcat (out, "&&"); + break; + case OR: + ralloc_strcat (out, "||"); + break; + case PASTE: + ralloc_strcat (out, "##"); + break; + case COMMA_FINAL: + ralloc_strcat (out, ","); + break; + case PLACEHOLDER: + /* Nothing to print. */ + break; + default: + assert(!"Error: Don't know how to print token."); + break; + } +} + +/* Return a new token (ralloc()ed off of 'token') formed by pasting + * 'token' and 'other'. Note that this function may return 'token' or + * 'other' directly rather than allocating anything new. + * + * Caution: Only very cursory error-checking is performed to see if + * the final result is a valid single token. */ +static token_t * +_token_paste (glcpp_parser_t *parser, token_t *token, token_t *other) +{ + token_t *combined = NULL; + + /* Pasting a placeholder onto anything makes no change. */ + if (other->type == PLACEHOLDER) + return token; + + /* When 'token' is a placeholder, just return 'other'. */ + if (token->type == PLACEHOLDER) + return other; + + /* A very few single-character punctuators can be combined + * with another to form a multi-character punctuator. */ + switch (token->type) { + case '<': + if (other->type == '<') + combined = _token_create_ival (token, LEFT_SHIFT, LEFT_SHIFT); + else if (other->type == '=') + combined = _token_create_ival (token, LESS_OR_EQUAL, LESS_OR_EQUAL); + break; + case '>': + if (other->type == '>') + combined = _token_create_ival (token, RIGHT_SHIFT, RIGHT_SHIFT); + else if (other->type == '=') + combined = _token_create_ival (token, GREATER_OR_EQUAL, GREATER_OR_EQUAL); + break; + case '=': + if (other->type == '=') + combined = _token_create_ival (token, EQUAL, EQUAL); + break; + case '!': + if (other->type == '=') + combined = _token_create_ival (token, NOT_EQUAL, NOT_EQUAL); + break; + case '&': + if (other->type == '&') + combined = _token_create_ival (token, AND, AND); + break; + case '|': + if (other->type == '|') + combined = _token_create_ival (token, OR, OR); + break; + } + + if (combined != NULL) { + /* Inherit the location from the first token */ + combined->location = token->location; + return combined; + } + + /* Two string-valued tokens can usually just be mashed + * together. + * + * XXX: This isn't actually legitimate. Several things here + * should result in a diagnostic since the result cannot be a + * valid, single pre-processing token. For example, pasting + * "123" and "abc" is not legal, but we don't catch that + * here. */ + if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING) && + (other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING)) + { + char *str; + + str = ralloc_asprintf (token, "%s%s", token->value.str, + other->value.str); + combined = _token_create_str (token, token->type, str); + combined->location = token->location; + return combined; + } + + glcpp_error (&token->location, parser, ""); + ralloc_strcat (&parser->info_log, "Pasting \""); + _token_print (&parser->info_log, token); + ralloc_strcat (&parser->info_log, "\" and \""); + _token_print (&parser->info_log, other); + ralloc_strcat (&parser->info_log, "\" does not give a valid preprocessing token.\n"); + + return token; +} + +static void +_token_list_print (glcpp_parser_t *parser, token_list_t *list) +{ + token_node_t *node; + + if (list == NULL) + return; + + for (node = list->head; node; node = node->next) + _token_print (&parser->output, node->token); +} + +void +yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error) +{ + glcpp_error(locp, parser, "%s", error); +} + +static void add_builtin_define(glcpp_parser_t *parser, + const char *name, int value) +{ + token_t *tok; + token_list_t *list; + + tok = _token_create_ival (parser, INTEGER, value); + + list = _token_list_create(parser); + _token_list_append(list, tok); + _define_object_macro(parser, NULL, name, list); +} + +glcpp_parser_t * +glcpp_parser_create (const struct gl_extensions *extensions, int api) +{ + glcpp_parser_t *parser; + int language_version; + + parser = ralloc (NULL, glcpp_parser_t); + + glcpp_lex_init_extra (parser, &parser->scanner); + parser->defines = hash_table_ctor (32, hash_table_string_hash, + hash_table_string_compare); + parser->active = NULL; + parser->lexing_if = 0; + parser->space_tokens = 1; + parser->newline_as_space = 0; + parser->in_control_line = 0; + parser->paren_count = 0; + + parser->skip_stack = NULL; + + parser->lex_from_list = NULL; + parser->lex_from_node = NULL; + + parser->output = ralloc_strdup(parser, ""); + parser->info_log = ralloc_strdup(parser, ""); + parser->error = 0; + + /* Add pre-defined macros. */ + add_builtin_define(parser, "GL_ARB_draw_buffers", 1); + add_builtin_define(parser, "GL_ARB_texture_rectangle", 1); + + if (api == API_OPENGLES2) + add_builtin_define(parser, "GL_ES", 1); + + if (extensions != NULL) { + if (extensions->EXT_texture_array) { + add_builtin_define(parser, "GL_EXT_texture_array", 1); + } + + if (extensions->ARB_fragment_coord_conventions) + add_builtin_define(parser, "GL_ARB_fragment_coord_conventions", + 1); + + if (extensions->ARB_explicit_attrib_location) + add_builtin_define(parser, "GL_ARB_explicit_attrib_location", 1); + } + + language_version = 110; + add_builtin_define(parser, "__VERSION__", language_version); + + return parser; +} + +int +glcpp_parser_parse (glcpp_parser_t *parser) +{ + return yyparse (parser); +} + +void +glcpp_parser_destroy (glcpp_parser_t *parser) +{ + glcpp_lex_destroy (parser->scanner); + hash_table_dtor (parser->defines); + ralloc_free (parser); +} + +typedef enum function_status +{ + FUNCTION_STATUS_SUCCESS, + FUNCTION_NOT_A_FUNCTION, + FUNCTION_UNBALANCED_PARENTHESES +} function_status_t; + +/* Find a set of function-like macro arguments by looking for a + * balanced set of parentheses. + * + * When called, 'node' should be the opening-parenthesis token, (or + * perhaps preceeding SPACE tokens). Upon successful return *last will + * be the last consumed node, (corresponding to the closing right + * parenthesis). + * + * Return values: + * + * FUNCTION_STATUS_SUCCESS: + * + * Successfully parsed a set of function arguments. + * + * FUNCTION_NOT_A_FUNCTION: + * + * Macro name not followed by a '('. This is not an error, but + * simply that the macro name should be treated as a non-macro. + * + * FUNCTION_UNBALANCED_PARENTHESES + * + * Macro name is not followed by a balanced set of parentheses. + */ +static function_status_t +_arguments_parse (argument_list_t *arguments, + token_node_t *node, + token_node_t **last) +{ + token_list_t *argument; + int paren_count; + + node = node->next; + + /* Ignore whitespace before first parenthesis. */ + while (node && node->token->type == SPACE) + node = node->next; + + if (node == NULL || node->token->type != '(') + return FUNCTION_NOT_A_FUNCTION; + + node = node->next; + + argument = _token_list_create (arguments); + _argument_list_append (arguments, argument); + + for (paren_count = 1; node; node = node->next) { + if (node->token->type == '(') + { + paren_count++; + } + else if (node->token->type == ')') + { + paren_count--; + if (paren_count == 0) + break; + } + + if (node->token->type == ',' && + paren_count == 1) + { + _token_list_trim_trailing_space (argument); + argument = _token_list_create (arguments); + _argument_list_append (arguments, argument); + } + else { + if (argument->head == NULL) { + /* Don't treat initial whitespace as + * part of the arguement. */ + if (node->token->type == SPACE) + continue; + } + _token_list_append (argument, node->token); + } + } + + if (paren_count) + return FUNCTION_UNBALANCED_PARENTHESES; + + *last = node; + + return FUNCTION_STATUS_SUCCESS; +} + +static token_list_t * +_token_list_create_with_one_space (void *ctx) +{ + token_list_t *list; + token_t *space; + + list = _token_list_create (ctx); + space = _token_create_ival (list, SPACE, SPACE); + _token_list_append (list, space); + + return list; +} + +static void +_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list) +{ + token_list_t *expanded; + token_t *token; + + expanded = _token_list_create (parser); + token = _token_create_ival (parser, type, type); + _token_list_append (expanded, token); + _glcpp_parser_expand_token_list (parser, list); + _token_list_append_list (expanded, list); + glcpp_parser_lex_from (parser, expanded); +} + +/* This is a helper function that's essentially part of the + * implementation of _glcpp_parser_expand_node. It shouldn't be called + * except for by that function. + * + * Returns NULL if node is a simple token with no expansion, (that is, + * although 'node' corresponds to an identifier defined as a + * function-like macro, it is not followed with a parenthesized + * argument list). + * + * Compute the complete expansion of node (which is a function-like + * macro) and subsequent nodes which are arguments. + * + * Returns the token list that results from the expansion and sets + * *last to the last node in the list that was consumed by the + * expansion. Specifically, *last will be set as follows: as the + * token of the closing right parenthesis. + */ +static token_list_t * +_glcpp_parser_expand_function (glcpp_parser_t *parser, + token_node_t *node, + token_node_t **last) + +{ + macro_t *macro; + const char *identifier; + argument_list_t *arguments; + function_status_t status; + token_list_t *substituted; + int parameter_index; + + identifier = node->token->value.str; + + macro = hash_table_find (parser->defines, identifier); + + assert (macro->is_function); + + arguments = _argument_list_create (parser); + status = _arguments_parse (arguments, node, last); + + switch (status) { + case FUNCTION_STATUS_SUCCESS: + break; + case FUNCTION_NOT_A_FUNCTION: + return NULL; + case FUNCTION_UNBALANCED_PARENTHESES: + glcpp_error (&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identifier); + return NULL; + } + + /* Replace a macro defined as empty with a SPACE token. */ + if (macro->replacements == NULL) { + ralloc_free (arguments); + return _token_list_create_with_one_space (parser); + } + + if (! ((_argument_list_length (arguments) == + _string_list_length (macro->parameters)) || + (_string_list_length (macro->parameters) == 0 && + _argument_list_length (arguments) == 1 && + arguments->head->argument->head == NULL))) + { + glcpp_error (&node->token->location, parser, + "Error: macro %s invoked with %d arguments (expected %d)\n", + identifier, + _argument_list_length (arguments), + _string_list_length (macro->parameters)); + return NULL; + } + + /* Perform argument substitution on the replacement list. */ + substituted = _token_list_create (arguments); + + for (node = macro->replacements->head; node; node = node->next) + { + if (node->token->type == IDENTIFIER && + _string_list_contains (macro->parameters, + node->token->value.str, + ¶meter_index)) + { + token_list_t *argument; + argument = _argument_list_member_at (arguments, + parameter_index); + /* Before substituting, we expand the argument + * tokens, or append a placeholder token for + * an empty argument. */ + if (argument->head) { + token_list_t *expanded_argument; + expanded_argument = _token_list_copy (parser, + argument); + _glcpp_parser_expand_token_list (parser, + expanded_argument); + _token_list_append_list (substituted, + expanded_argument); + } else { + token_t *new_token; + + new_token = _token_create_ival (substituted, + PLACEHOLDER, + PLACEHOLDER); + _token_list_append (substituted, new_token); + } + } else { + _token_list_append (substituted, node->token); + } + } + + /* After argument substitution, and before further expansion + * below, implement token pasting. */ + + _token_list_trim_trailing_space (substituted); + + node = substituted->head; + while (node) + { + token_node_t *next_non_space; + + /* Look ahead for a PASTE token, skipping space. */ + next_non_space = node->next; + while (next_non_space && next_non_space->token->type == SPACE) + next_non_space = next_non_space->next; + + if (next_non_space == NULL) + break; + + if (next_non_space->token->type != PASTE) { + node = next_non_space; + continue; + } + + /* Now find the next non-space token after the PASTE. */ + next_non_space = next_non_space->next; + while (next_non_space && next_non_space->token->type == SPACE) + next_non_space = next_non_space->next; + + if (next_non_space == NULL) { + yyerror (&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n"); + return NULL; + } + + node->token = _token_paste (parser, node->token, next_non_space->token); + node->next = next_non_space->next; + if (next_non_space == substituted->tail) + substituted->tail = node; + + node = node->next; + } + + substituted->non_space_tail = substituted->tail; + + return substituted; +} + +/* Compute the complete expansion of node, (and subsequent nodes after + * 'node' in the case that 'node' is a function-like macro and + * subsequent nodes are arguments). + * + * Returns NULL if node is a simple token with no expansion. + * + * Otherwise, returns the token list that results from the expansion + * and sets *last to the last node in the list that was consumed by + * the expansion. Specifically, *last will be set as follows: + * + * As 'node' in the case of object-like macro expansion. + * + * As the token of the closing right parenthesis in the case of + * function-like macro expansion. + */ +static token_list_t * +_glcpp_parser_expand_node (glcpp_parser_t *parser, + token_node_t *node, + token_node_t **last) +{ + token_t *token = node->token; + const char *identifier; + macro_t *macro; + + /* We only expand identifiers */ + if (token->type != IDENTIFIER) { + /* We change any COMMA into a COMMA_FINAL to prevent + * it being mistaken for an argument separator + * later. */ + if (token->type == ',') { + token->type = COMMA_FINAL; + token->value.ival = COMMA_FINAL; + } + + return NULL; + } + + /* Look up this identifier in the hash table. */ + identifier = token->value.str; + macro = hash_table_find (parser->defines, identifier); + + /* Not a macro, so no expansion needed. */ + if (macro == NULL) + return NULL; + + /* Finally, don't expand this macro if we're already actively + * expanding it, (to avoid infinite recursion). */ + if (_active_list_contains (parser->active, identifier)) { + /* We change the token type here from IDENTIFIER to + * OTHER to prevent any future expansion of this + * unexpanded token. */ + char *str; + token_list_t *expansion; + token_t *final; + + str = ralloc_strdup (parser, token->value.str); + final = _token_create_str (parser, OTHER, str); + expansion = _token_list_create (parser); + _token_list_append (expansion, final); + *last = node; + return expansion; + } + + if (! macro->is_function) + { + *last = node; + + /* Replace a macro defined as empty with a SPACE token. */ + if (macro->replacements == NULL) + return _token_list_create_with_one_space (parser); + + return _token_list_copy (parser, macro->replacements); + } + + return _glcpp_parser_expand_function (parser, node, last); +} + +/* Push a new identifier onto the active list, returning the new list. + * + * Here, 'marker' is the token node that appears in the list after the + * expansion of 'identifier'. That is, when the list iterator begins + * examinging 'marker', then it is time to pop this node from the + * active stack. + */ +active_list_t * +_active_list_push (active_list_t *list, + const char *identifier, + token_node_t *marker) +{ + active_list_t *node; + + node = ralloc (list, active_list_t); + node->identifier = ralloc_strdup (node, identifier); + node->marker = marker; + node->next = list; + + return node; +} + +active_list_t * +_active_list_pop (active_list_t *list) +{ + active_list_t *node = list; + + if (node == NULL) + return NULL; + + node = list->next; + ralloc_free (list); + + return node; +} + +int +_active_list_contains (active_list_t *list, const char *identifier) +{ + active_list_t *node; + + if (list == NULL) + return 0; + + for (node = list; node; node = node->next) + if (strcmp (node->identifier, identifier) == 0) + return 1; + + return 0; +} + +/* Walk over the token list replacing nodes with their expansion. + * Whenever nodes are expanded the walking will walk over the new + * nodes, continuing to expand as necessary. The results are placed in + * 'list' itself; + */ +static void +_glcpp_parser_expand_token_list (glcpp_parser_t *parser, + token_list_t *list) +{ + token_node_t *node_prev; + token_node_t *node, *last = NULL; + token_list_t *expansion; + + if (list == NULL) + return; + + _token_list_trim_trailing_space (list); + + node_prev = NULL; + node = list->head; + + while (node) { + + while (parser->active && parser->active->marker == node) + parser->active = _active_list_pop (parser->active); + + /* Find the expansion for node, which will replace all + * nodes from node to last, inclusive. */ + expansion = _glcpp_parser_expand_node (parser, node, &last); + if (expansion) { + token_node_t *n; + + for (n = node; n != last->next; n = n->next) + while (parser->active && + parser->active->marker == n) + { + parser->active = _active_list_pop (parser->active); + } + + parser->active = _active_list_push (parser->active, + node->token->value.str, + last->next); + + /* Splice expansion into list, supporting a + * simple deletion if the expansion is + * empty. */ + if (expansion->head) { + if (node_prev) + node_prev->next = expansion->head; + else + list->head = expansion->head; + expansion->tail->next = last->next; + if (last == list->tail) + list->tail = expansion->tail; + } else { + if (node_prev) + node_prev->next = last->next; + else + list->head = last->next; + if (last == list->tail) + list->tail = NULL; + } + } else { + node_prev = node; + } + node = node_prev ? node_prev->next : list->head; + } + + while (parser->active) + parser->active = _active_list_pop (parser->active); + + list->non_space_tail = list->tail; +} + +void +_glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser, + token_list_t *list) +{ + if (list == NULL) + return; + + _glcpp_parser_expand_token_list (parser, list); + + _token_list_trim_trailing_space (list); + + _token_list_print (parser, list); +} + +static void +_check_for_reserved_macro_name (glcpp_parser_t *parser, YYLTYPE *loc, + const char *identifier) +{ + /* According to the GLSL specification, macro names starting with "__" + * or "GL_" are reserved for future use. So, don't allow them. + */ + if (strncmp(identifier, "__", 2) == 0) { + glcpp_error (loc, parser, "Macro names starting with \"__\" are reserved.\n"); + } + if (strncmp(identifier, "GL_", 3) == 0) { + glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n"); + } +} + +static int +_macro_equal (macro_t *a, macro_t *b) +{ + if (a->is_function != b->is_function) + return 0; + + if (a->is_function) { + if (! _string_list_equal (a->parameters, b->parameters)) + return 0; + } + + return _token_list_equal_ignoring_space (a->replacements, + b->replacements); +} + +void +_define_object_macro (glcpp_parser_t *parser, + YYLTYPE *loc, + const char *identifier, + token_list_t *replacements) +{ + macro_t *macro, *previous; + + if (loc != NULL) + _check_for_reserved_macro_name(parser, loc, identifier); + + macro = ralloc (parser, macro_t); + + macro->is_function = 0; + macro->parameters = NULL; + macro->identifier = ralloc_strdup (macro, identifier); + macro->replacements = replacements; + ralloc_steal (macro, replacements); + + previous = hash_table_find (parser->defines, identifier); + if (previous) { + if (_macro_equal (macro, previous)) { + ralloc_free (macro); + return; + } + glcpp_error (loc, parser, "Redefinition of macro %s\n", + identifier); + } + + hash_table_insert (parser->defines, macro, identifier); +} + +void +_define_function_macro (glcpp_parser_t *parser, + YYLTYPE *loc, + const char *identifier, + string_list_t *parameters, + token_list_t *replacements) +{ + macro_t *macro, *previous; + + _check_for_reserved_macro_name(parser, loc, identifier); + + macro = ralloc (parser, macro_t); + ralloc_steal (macro, parameters); + ralloc_steal (macro, replacements); + + macro->is_function = 1; + macro->parameters = parameters; + macro->identifier = ralloc_strdup (macro, identifier); + macro->replacements = replacements; + previous = hash_table_find (parser->defines, identifier); + if (previous) { + if (_macro_equal (macro, previous)) { + ralloc_free (macro); + return; + } + glcpp_error (loc, parser, "Redefinition of macro %s\n", + identifier); + } + + hash_table_insert (parser->defines, macro, identifier); +} + +static int +glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser) +{ + token_node_t *node; + int ret; + + if (parser->lex_from_list == NULL) { + ret = glcpp_lex (yylval, yylloc, parser->scanner); + + /* XXX: This ugly block of code exists for the sole + * purpose of converting a NEWLINE token into a SPACE + * token, but only in the case where we have seen a + * function-like macro name, but have not yet seen its + * closing parenthesis. + * + * There's perhaps a more compact way to do this with + * mid-rule actions in the grammar. + * + * I'm definitely not pleased with the complexity of + * this code here. + */ + if (parser->newline_as_space) + { + if (ret == '(') { + parser->paren_count++; + } else if (ret == ')') { + parser->paren_count--; + if (parser->paren_count == 0) + parser->newline_as_space = 0; + } else if (ret == NEWLINE) { + ret = SPACE; + } else if (ret != SPACE) { + if (parser->paren_count == 0) + parser->newline_as_space = 0; + } + } + else if (parser->in_control_line) + { + if (ret == NEWLINE) + parser->in_control_line = 0; + } + else if (ret == HASH_DEFINE_OBJ || ret == HASH_DEFINE_FUNC || + ret == HASH_UNDEF || ret == HASH_IF || + ret == HASH_IFDEF || ret == HASH_IFNDEF || + ret == HASH_ELIF || ret == HASH_ELSE || + ret == HASH_ENDIF || ret == HASH) + { + parser->in_control_line = 1; + } + else if (ret == IDENTIFIER) + { + macro_t *macro; + macro = hash_table_find (parser->defines, + yylval->str); + if (macro && macro->is_function) { + parser->newline_as_space = 1; + parser->paren_count = 0; + } + } + + return ret; + } + + node = parser->lex_from_node; + + if (node == NULL) { + ralloc_free (parser->lex_from_list); + parser->lex_from_list = NULL; + return NEWLINE; + } + + *yylval = node->token->value; + ret = node->token->type; + + parser->lex_from_node = node->next; + + return ret; +} + +static void +glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list) +{ + token_node_t *node; + + assert (parser->lex_from_list == NULL); + + /* Copy list, eliminating any space tokens. */ + parser->lex_from_list = _token_list_create (parser); + + for (node = list->head; node; node = node->next) { + if (node->token->type == SPACE) + continue; + _token_list_append (parser->lex_from_list, node->token); + } + + ralloc_free (list); + + parser->lex_from_node = parser->lex_from_list->head; + + /* It's possible the list consisted of nothing but whitespace. */ + if (parser->lex_from_node == NULL) { + ralloc_free (parser->lex_from_list); + parser->lex_from_list = NULL; + } +} + +static void +_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc, + int condition) +{ + skip_type_t current = SKIP_NO_SKIP; + skip_node_t *node; + + if (parser->skip_stack) + current = parser->skip_stack->type; + + node = ralloc (parser, skip_node_t); + node->loc = *loc; + + if (current == SKIP_NO_SKIP) { + if (condition) + node->type = SKIP_NO_SKIP; + else + node->type = SKIP_TO_ELSE; + } else { + node->type = SKIP_TO_ENDIF; + } + + node->next = parser->skip_stack; + parser->skip_stack = node; +} + +static void +_glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc, + const char *type, int condition) +{ + if (parser->skip_stack == NULL) { + glcpp_error (loc, parser, "%s without #if\n", type); + return; + } + + if (parser->skip_stack->type == SKIP_TO_ELSE) { + if (condition) + parser->skip_stack->type = SKIP_NO_SKIP; + } else { + parser->skip_stack->type = SKIP_TO_ENDIF; + } +} + +static void +_glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc) +{ + skip_node_t *node; + + if (parser->skip_stack == NULL) { + glcpp_error (loc, parser, "#endif without #if\n"); + return; + } + + node = parser->skip_stack; + parser->skip_stack = node->next; + ralloc_free (node); +} + diff --git a/src/glsl/glcpp/glcpp-parse.h b/src/glsl/glcpp/glcpp-parse.h new file mode 100644 index 0000000..4055685 --- /dev/null +++ b/src/glsl/glcpp/glcpp-parse.h @@ -0,0 +1,100 @@ +/* A Bison parser, made by GNU Bison 2.4.3. */ + +/* Skeleton interface for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2009, 2010 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + COMMA_FINAL = 258, + DEFINED = 259, + ELIF_EXPANDED = 260, + HASH = 261, + HASH_DEFINE_FUNC = 262, + HASH_DEFINE_OBJ = 263, + HASH_ELIF = 264, + HASH_ELSE = 265, + HASH_ENDIF = 266, + HASH_IF = 267, + HASH_IFDEF = 268, + HASH_IFNDEF = 269, + HASH_UNDEF = 270, + HASH_VERSION = 271, + IDENTIFIER = 272, + IF_EXPANDED = 273, + INTEGER = 274, + INTEGER_STRING = 275, + NEWLINE = 276, + OTHER = 277, + PLACEHOLDER = 278, + SPACE = 279, + PASTE = 280, + OR = 281, + AND = 282, + NOT_EQUAL = 283, + EQUAL = 284, + GREATER_OR_EQUAL = 285, + LESS_OR_EQUAL = 286, + RIGHT_SHIFT = 287, + LEFT_SHIFT = 288, + UNARY = 289 + }; +#endif + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED + +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + + + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + + diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y new file mode 100644 index 0000000..7c51299 --- /dev/null +++ b/src/glsl/glcpp/glcpp-parse.y @@ -0,0 +1,1894 @@ +%{ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#include "glcpp.h" +#include "main/core.h" /* for struct gl_extensions */ +#include "main/mtypes.h" /* for gl_api enum */ + +static void +yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error); + +static void +_define_object_macro (glcpp_parser_t *parser, + YYLTYPE *loc, + const char *macro, + token_list_t *replacements); + +static void +_define_function_macro (glcpp_parser_t *parser, + YYLTYPE *loc, + const char *macro, + string_list_t *parameters, + token_list_t *replacements); + +static string_list_t * +_string_list_create (void *ctx); + +static void +_string_list_append_item (string_list_t *list, const char *str); + +static int +_string_list_contains (string_list_t *list, const char *member, int *index); + +static int +_string_list_length (string_list_t *list); + +static int +_string_list_equal (string_list_t *a, string_list_t *b); + +static argument_list_t * +_argument_list_create (void *ctx); + +static void +_argument_list_append (argument_list_t *list, token_list_t *argument); + +static int +_argument_list_length (argument_list_t *list); + +static token_list_t * +_argument_list_member_at (argument_list_t *list, int index); + +/* Note: This function ralloc_steal()s the str pointer. */ +static token_t * +_token_create_str (void *ctx, int type, char *str); + +static token_t * +_token_create_ival (void *ctx, int type, int ival); + +static token_list_t * +_token_list_create (void *ctx); + +/* Note: This function calls ralloc_steal on token. */ +static void +_token_list_append (token_list_t *list, token_t *token); + +static void +_token_list_append_list (token_list_t *list, token_list_t *tail); + +static int +_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b); + +static active_list_t * +_active_list_push (active_list_t *list, + const char *identifier, + token_node_t *marker); + +static active_list_t * +_active_list_pop (active_list_t *list); + +int +_active_list_contains (active_list_t *list, const char *identifier); + +static void +_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list); + +static void +_glcpp_parser_expand_token_list (glcpp_parser_t *parser, + token_list_t *list); + +static void +_glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser, + token_list_t *list); + +static void +_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc, + int condition); + +static void +_glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc, + const char *type, int condition); + +static void +_glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc); + +#define yylex glcpp_parser_lex + +static int +glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser); + +static void +glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list); + +static void +add_builtin_define(glcpp_parser_t *parser, const char *name, int value); + +%} + +%pure-parser +%error-verbose + +%locations +%initial-action { + @$.first_line = 1; + @$.first_column = 1; + @$.last_line = 1; + @$.last_column = 1; + @$.source = 0; +} + +%parse-param {glcpp_parser_t *parser} +%lex-param {glcpp_parser_t *parser} + +%expect 0 +%token COMMA_FINAL DEFINED ELIF_EXPANDED HASH HASH_DEFINE_FUNC HASH_DEFINE_OBJ HASH_ELIF HASH_ELSE HASH_ENDIF HASH_IF HASH_IFDEF HASH_IFNDEF HASH_UNDEF HASH_VERSION IDENTIFIER IF_EXPANDED INTEGER INTEGER_STRING NEWLINE OTHER PLACEHOLDER SPACE +%token PASTE +%type expression INTEGER operator SPACE integer_constant +%type IDENTIFIER INTEGER_STRING OTHER +%type identifier_list +%type preprocessing_token conditional_token +%type pp_tokens replacement_list text_line conditional_tokens +%left OR +%left AND +%left '|' +%left '^' +%left '&' +%left EQUAL NOT_EQUAL +%left '<' '>' LESS_OR_EQUAL GREATER_OR_EQUAL +%left LEFT_SHIFT RIGHT_SHIFT +%left '+' '-' +%left '*' '/' '%' +%right UNARY + +%% + +input: + /* empty */ +| input line +; + +line: + control_line { + ralloc_strcat (&parser->output, "\n"); + } +| text_line { + _glcpp_parser_print_expanded_token_list (parser, $1); + ralloc_strcat (&parser->output, "\n"); + ralloc_free ($1); + } +| expanded_line +| HASH non_directive +; + +expanded_line: + IF_EXPANDED expression NEWLINE { + _glcpp_parser_skip_stack_push_if (parser, & @1, $2); + } +| ELIF_EXPANDED expression NEWLINE { + _glcpp_parser_skip_stack_change_if (parser, & @1, "elif", $2); + } +; + +control_line: + HASH_DEFINE_OBJ IDENTIFIER replacement_list NEWLINE { + _define_object_macro (parser, & @2, $2, $3); + } +| HASH_DEFINE_FUNC IDENTIFIER '(' ')' replacement_list NEWLINE { + _define_function_macro (parser, & @2, $2, NULL, $5); + } +| HASH_DEFINE_FUNC IDENTIFIER '(' identifier_list ')' replacement_list NEWLINE { + _define_function_macro (parser, & @2, $2, $4, $6); + } +| HASH_UNDEF IDENTIFIER NEWLINE { + macro_t *macro = hash_table_find (parser->defines, $2); + if (macro) { + hash_table_remove (parser->defines, $2); + ralloc_free (macro); + } + ralloc_free ($2); + } +| HASH_IF conditional_tokens NEWLINE { + /* Be careful to only evaluate the 'if' expression if + * we are not skipping. When we are skipping, we + * simply push a new 0-valued 'if' onto the skip + * stack. + * + * This avoids generating diagnostics for invalid + * expressions that are being skipped. */ + if (parser->skip_stack == NULL || + parser->skip_stack->type == SKIP_NO_SKIP) + { + _glcpp_parser_expand_if (parser, IF_EXPANDED, $2); + } + else + { + _glcpp_parser_skip_stack_push_if (parser, & @1, 0); + parser->skip_stack->type = SKIP_TO_ENDIF; + } + } +| HASH_IF NEWLINE { + /* #if without an expression is only an error if we + * are not skipping */ + if (parser->skip_stack == NULL || + parser->skip_stack->type == SKIP_NO_SKIP) + { + glcpp_error(& @1, parser, "#if with no expression"); + } + _glcpp_parser_skip_stack_push_if (parser, & @1, 0); + } +| HASH_IFDEF IDENTIFIER junk NEWLINE { + macro_t *macro = hash_table_find (parser->defines, $2); + ralloc_free ($2); + _glcpp_parser_skip_stack_push_if (parser, & @1, macro != NULL); + } +| HASH_IFNDEF IDENTIFIER junk NEWLINE { + macro_t *macro = hash_table_find (parser->defines, $2); + ralloc_free ($2); + _glcpp_parser_skip_stack_push_if (parser, & @1, macro == NULL); + } +| HASH_ELIF conditional_tokens NEWLINE { + /* Be careful to only evaluate the 'elif' expression + * if we are not skipping. When we are skipping, we + * simply change to a 0-valued 'elif' on the skip + * stack. + * + * This avoids generating diagnostics for invalid + * expressions that are being skipped. */ + if (parser->skip_stack && + parser->skip_stack->type == SKIP_TO_ELSE) + { + _glcpp_parser_expand_if (parser, ELIF_EXPANDED, $2); + } + else + { + _glcpp_parser_skip_stack_change_if (parser, & @1, + "elif", 0); + } + } +| HASH_ELIF NEWLINE { + /* #elif without an expression is an error unless we + * are skipping. */ + if (parser->skip_stack && + parser->skip_stack->type == SKIP_TO_ELSE) + { + glcpp_error(& @1, parser, "#elif with no expression"); + } + else + { + _glcpp_parser_skip_stack_change_if (parser, & @1, + "elif", 0); + glcpp_warning(& @1, parser, "ignoring illegal #elif without expression"); + } + } +| HASH_ELSE NEWLINE { + _glcpp_parser_skip_stack_change_if (parser, & @1, "else", 1); + } +| HASH_ENDIF NEWLINE { + _glcpp_parser_skip_stack_pop (parser, & @1); + } +| HASH_VERSION integer_constant NEWLINE { + macro_t *macro = hash_table_find (parser->defines, "__VERSION__"); + if (macro) { + hash_table_remove (parser->defines, "__VERSION__"); + ralloc_free (macro); + } + add_builtin_define (parser, "__VERSION__", $2); + + if ($2 == 100) + add_builtin_define (parser, "GL_ES", 1); + + /* Currently, all ES2 implementations support highp in the + * fragment shader, so we always define this macro in ES2. + * If we ever get a driver that doesn't support highp, we'll + * need to add a flag to the gl_context and check that here. + */ + if ($2 >= 130 || $2 == 100) + add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1); + + ralloc_asprintf_append (&parser->output, "#version %" PRIiMAX, $2); + } +| HASH NEWLINE +; + +integer_constant: + INTEGER_STRING { + if (strlen ($1) >= 3 && strncmp ($1, "0x", 2) == 0) { + $$ = strtoll ($1 + 2, NULL, 16); + } else if ($1[0] == '0') { + $$ = strtoll ($1, NULL, 8); + } else { + $$ = strtoll ($1, NULL, 10); + } + } +| INTEGER { + $$ = $1; + } + +expression: + integer_constant +| expression OR expression { + $$ = $1 || $3; + } +| expression AND expression { + $$ = $1 && $3; + } +| expression '|' expression { + $$ = $1 | $3; + } +| expression '^' expression { + $$ = $1 ^ $3; + } +| expression '&' expression { + $$ = $1 & $3; + } +| expression NOT_EQUAL expression { + $$ = $1 != $3; + } +| expression EQUAL expression { + $$ = $1 == $3; + } +| expression GREATER_OR_EQUAL expression { + $$ = $1 >= $3; + } +| expression LESS_OR_EQUAL expression { + $$ = $1 <= $3; + } +| expression '>' expression { + $$ = $1 > $3; + } +| expression '<' expression { + $$ = $1 < $3; + } +| expression RIGHT_SHIFT expression { + $$ = $1 >> $3; + } +| expression LEFT_SHIFT expression { + $$ = $1 << $3; + } +| expression '-' expression { + $$ = $1 - $3; + } +| expression '+' expression { + $$ = $1 + $3; + } +| expression '%' expression { + if ($3 == 0) { + yyerror (& @1, parser, + "zero modulus in preprocessor directive"); + } else { + $$ = $1 % $3; + } + } +| expression '/' expression { + if ($3 == 0) { + yyerror (& @1, parser, + "division by 0 in preprocessor directive"); + } else { + $$ = $1 / $3; + } + } +| expression '*' expression { + $$ = $1 * $3; + } +| '!' expression %prec UNARY { + $$ = ! $2; + } +| '~' expression %prec UNARY { + $$ = ~ $2; + } +| '-' expression %prec UNARY { + $$ = - $2; + } +| '+' expression %prec UNARY { + $$ = + $2; + } +| '(' expression ')' { + $$ = $2; + } +; + +identifier_list: + IDENTIFIER { + $$ = _string_list_create (parser); + _string_list_append_item ($$, $1); + ralloc_steal ($$, $1); + } +| identifier_list ',' IDENTIFIER { + $$ = $1; + _string_list_append_item ($$, $3); + ralloc_steal ($$, $3); + } +; + +text_line: + NEWLINE { $$ = NULL; } +| pp_tokens NEWLINE +; + +non_directive: + pp_tokens NEWLINE { + yyerror (& @1, parser, "Invalid tokens after #"); + } +; + +replacement_list: + /* empty */ { $$ = NULL; } +| pp_tokens +; + +junk: + /* empty */ +| pp_tokens { + glcpp_warning(&@1, parser, "extra tokens at end of directive"); + } +; + +conditional_token: + /* Handle "defined" operator */ + DEFINED IDENTIFIER { + int v = hash_table_find (parser->defines, $2) ? 1 : 0; + $$ = _token_create_ival (parser, INTEGER, v); + } +| DEFINED '(' IDENTIFIER ')' { + int v = hash_table_find (parser->defines, $3) ? 1 : 0; + $$ = _token_create_ival (parser, INTEGER, v); + } +| preprocessing_token +; + +conditional_tokens: + /* Exactly the same as pp_tokens, but using conditional_token */ + conditional_token { + $$ = _token_list_create (parser); + _token_list_append ($$, $1); + } +| conditional_tokens conditional_token { + $$ = $1; + _token_list_append ($$, $2); + } +; + +pp_tokens: + preprocessing_token { + parser->space_tokens = 1; + $$ = _token_list_create (parser); + _token_list_append ($$, $1); + } +| pp_tokens preprocessing_token { + $$ = $1; + _token_list_append ($$, $2); + } +; + +preprocessing_token: + IDENTIFIER { + $$ = _token_create_str (parser, IDENTIFIER, $1); + $$->location = yylloc; + } +| INTEGER_STRING { + $$ = _token_create_str (parser, INTEGER_STRING, $1); + $$->location = yylloc; + } +| operator { + $$ = _token_create_ival (parser, $1, $1); + $$->location = yylloc; + } +| OTHER { + $$ = _token_create_str (parser, OTHER, $1); + $$->location = yylloc; + } +| SPACE { + $$ = _token_create_ival (parser, SPACE, SPACE); + $$->location = yylloc; + } +; + +operator: + '[' { $$ = '['; } +| ']' { $$ = ']'; } +| '(' { $$ = '('; } +| ')' { $$ = ')'; } +| '{' { $$ = '{'; } +| '}' { $$ = '}'; } +| '.' { $$ = '.'; } +| '&' { $$ = '&'; } +| '*' { $$ = '*'; } +| '+' { $$ = '+'; } +| '-' { $$ = '-'; } +| '~' { $$ = '~'; } +| '!' { $$ = '!'; } +| '/' { $$ = '/'; } +| '%' { $$ = '%'; } +| LEFT_SHIFT { $$ = LEFT_SHIFT; } +| RIGHT_SHIFT { $$ = RIGHT_SHIFT; } +| '<' { $$ = '<'; } +| '>' { $$ = '>'; } +| LESS_OR_EQUAL { $$ = LESS_OR_EQUAL; } +| GREATER_OR_EQUAL { $$ = GREATER_OR_EQUAL; } +| EQUAL { $$ = EQUAL; } +| NOT_EQUAL { $$ = NOT_EQUAL; } +| '^' { $$ = '^'; } +| '|' { $$ = '|'; } +| AND { $$ = AND; } +| OR { $$ = OR; } +| ';' { $$ = ';'; } +| ',' { $$ = ','; } +| '=' { $$ = '='; } +| PASTE { $$ = PASTE; } +; + +%% + +string_list_t * +_string_list_create (void *ctx) +{ + string_list_t *list; + + list = ralloc (ctx, string_list_t); + list->head = NULL; + list->tail = NULL; + + return list; +} + +void +_string_list_append_item (string_list_t *list, const char *str) +{ + string_node_t *node; + + node = ralloc (list, string_node_t); + node->str = ralloc_strdup (node, str); + + node->next = NULL; + + if (list->head == NULL) { + list->head = node; + } else { + list->tail->next = node; + } + + list->tail = node; +} + +int +_string_list_contains (string_list_t *list, const char *member, int *index) +{ + string_node_t *node; + int i; + + if (list == NULL) + return 0; + + for (i = 0, node = list->head; node; i++, node = node->next) { + if (strcmp (node->str, member) == 0) { + if (index) + *index = i; + return 1; + } + } + + return 0; +} + +int +_string_list_length (string_list_t *list) +{ + int length = 0; + string_node_t *node; + + if (list == NULL) + return 0; + + for (node = list->head; node; node = node->next) + length++; + + return length; +} + +int +_string_list_equal (string_list_t *a, string_list_t *b) +{ + string_node_t *node_a, *node_b; + + if (a == NULL && b == NULL) + return 1; + + if (a == NULL || b == NULL) + return 0; + + for (node_a = a->head, node_b = b->head; + node_a && node_b; + node_a = node_a->next, node_b = node_b->next) + { + if (strcmp (node_a->str, node_b->str)) + return 0; + } + + /* Catch the case of lists being different lengths, (which + * would cause the loop above to terminate after the shorter + * list). */ + return node_a == node_b; +} + +argument_list_t * +_argument_list_create (void *ctx) +{ + argument_list_t *list; + + list = ralloc (ctx, argument_list_t); + list->head = NULL; + list->tail = NULL; + + return list; +} + +void +_argument_list_append (argument_list_t *list, token_list_t *argument) +{ + argument_node_t *node; + + node = ralloc (list, argument_node_t); + node->argument = argument; + + node->next = NULL; + + if (list->head == NULL) { + list->head = node; + } else { + list->tail->next = node; + } + + list->tail = node; +} + +int +_argument_list_length (argument_list_t *list) +{ + int length = 0; + argument_node_t *node; + + if (list == NULL) + return 0; + + for (node = list->head; node; node = node->next) + length++; + + return length; +} + +token_list_t * +_argument_list_member_at (argument_list_t *list, int index) +{ + argument_node_t *node; + int i; + + if (list == NULL) + return NULL; + + node = list->head; + for (i = 0; i < index; i++) { + node = node->next; + if (node == NULL) + break; + } + + if (node) + return node->argument; + + return NULL; +} + +/* Note: This function ralloc_steal()s the str pointer. */ +token_t * +_token_create_str (void *ctx, int type, char *str) +{ + token_t *token; + + token = ralloc (ctx, token_t); + token->type = type; + token->value.str = str; + + ralloc_steal (token, str); + + return token; +} + +token_t * +_token_create_ival (void *ctx, int type, int ival) +{ + token_t *token; + + token = ralloc (ctx, token_t); + token->type = type; + token->value.ival = ival; + + return token; +} + +token_list_t * +_token_list_create (void *ctx) +{ + token_list_t *list; + + list = ralloc (ctx, token_list_t); + list->head = NULL; + list->tail = NULL; + list->non_space_tail = NULL; + + return list; +} + +void +_token_list_append (token_list_t *list, token_t *token) +{ + token_node_t *node; + + node = ralloc (list, token_node_t); + node->token = token; + node->next = NULL; + + ralloc_steal (list, token); + + if (list->head == NULL) { + list->head = node; + } else { + list->tail->next = node; + } + + list->tail = node; + if (token->type != SPACE) + list->non_space_tail = node; +} + +void +_token_list_append_list (token_list_t *list, token_list_t *tail) +{ + if (tail == NULL || tail->head == NULL) + return; + + if (list->head == NULL) { + list->head = tail->head; + } else { + list->tail->next = tail->head; + } + + list->tail = tail->tail; + list->non_space_tail = tail->non_space_tail; +} + +static token_list_t * +_token_list_copy (void *ctx, token_list_t *other) +{ + token_list_t *copy; + token_node_t *node; + + if (other == NULL) + return NULL; + + copy = _token_list_create (ctx); + for (node = other->head; node; node = node->next) { + token_t *new_token = ralloc (copy, token_t); + *new_token = *node->token; + _token_list_append (copy, new_token); + } + + return copy; +} + +static void +_token_list_trim_trailing_space (token_list_t *list) +{ + token_node_t *tail, *next; + + if (list->non_space_tail) { + tail = list->non_space_tail->next; + list->non_space_tail->next = NULL; + list->tail = list->non_space_tail; + + while (tail) { + next = tail->next; + ralloc_free (tail); + tail = next; + } + } +} + +int +_token_list_is_empty_ignoring_space (token_list_t *l) +{ + token_node_t *n; + + if (l == NULL) + return 1; + + n = l->head; + while (n != NULL && n->token->type == SPACE) + n = n->next; + + return n == NULL; +} + +int +_token_list_equal_ignoring_space (token_list_t *a, token_list_t *b) +{ + token_node_t *node_a, *node_b; + + if (a == NULL || b == NULL) { + int a_empty = _token_list_is_empty_ignoring_space(a); + int b_empty = _token_list_is_empty_ignoring_space(b); + return a_empty == b_empty; + } + + node_a = a->head; + node_b = b->head; + + while (1) + { + if (node_a == NULL && node_b == NULL) + break; + + if (node_a == NULL || node_b == NULL) + return 0; + + if (node_a->token->type == SPACE) { + node_a = node_a->next; + continue; + } + + if (node_b->token->type == SPACE) { + node_b = node_b->next; + continue; + } + + if (node_a->token->type != node_b->token->type) + return 0; + + switch (node_a->token->type) { + case INTEGER: + if (node_a->token->value.ival != + node_b->token->value.ival) + { + return 0; + } + break; + case IDENTIFIER: + case INTEGER_STRING: + case OTHER: + if (strcmp (node_a->token->value.str, + node_b->token->value.str)) + { + return 0; + } + break; + } + + node_a = node_a->next; + node_b = node_b->next; + } + + return 1; +} + +static void +_token_print (char **out, token_t *token) +{ + if (token->type < 256) { + ralloc_asprintf_append (out, "%c", token->type); + return; + } + + switch (token->type) { + case INTEGER: + ralloc_asprintf_append (out, "%" PRIiMAX, token->value.ival); + break; + case IDENTIFIER: + case INTEGER_STRING: + case OTHER: + ralloc_strcat (out, token->value.str); + break; + case SPACE: + ralloc_strcat (out, " "); + break; + case LEFT_SHIFT: + ralloc_strcat (out, "<<"); + break; + case RIGHT_SHIFT: + ralloc_strcat (out, ">>"); + break; + case LESS_OR_EQUAL: + ralloc_strcat (out, "<="); + break; + case GREATER_OR_EQUAL: + ralloc_strcat (out, ">="); + break; + case EQUAL: + ralloc_strcat (out, "=="); + break; + case NOT_EQUAL: + ralloc_strcat (out, "!="); + break; + case AND: + ralloc_strcat (out, "&&"); + break; + case OR: + ralloc_strcat (out, "||"); + break; + case PASTE: + ralloc_strcat (out, "##"); + break; + case COMMA_FINAL: + ralloc_strcat (out, ","); + break; + case PLACEHOLDER: + /* Nothing to print. */ + break; + default: + assert(!"Error: Don't know how to print token."); + break; + } +} + +/* Return a new token (ralloc()ed off of 'token') formed by pasting + * 'token' and 'other'. Note that this function may return 'token' or + * 'other' directly rather than allocating anything new. + * + * Caution: Only very cursory error-checking is performed to see if + * the final result is a valid single token. */ +static token_t * +_token_paste (glcpp_parser_t *parser, token_t *token, token_t *other) +{ + token_t *combined = NULL; + + /* Pasting a placeholder onto anything makes no change. */ + if (other->type == PLACEHOLDER) + return token; + + /* When 'token' is a placeholder, just return 'other'. */ + if (token->type == PLACEHOLDER) + return other; + + /* A very few single-character punctuators can be combined + * with another to form a multi-character punctuator. */ + switch (token->type) { + case '<': + if (other->type == '<') + combined = _token_create_ival (token, LEFT_SHIFT, LEFT_SHIFT); + else if (other->type == '=') + combined = _token_create_ival (token, LESS_OR_EQUAL, LESS_OR_EQUAL); + break; + case '>': + if (other->type == '>') + combined = _token_create_ival (token, RIGHT_SHIFT, RIGHT_SHIFT); + else if (other->type == '=') + combined = _token_create_ival (token, GREATER_OR_EQUAL, GREATER_OR_EQUAL); + break; + case '=': + if (other->type == '=') + combined = _token_create_ival (token, EQUAL, EQUAL); + break; + case '!': + if (other->type == '=') + combined = _token_create_ival (token, NOT_EQUAL, NOT_EQUAL); + break; + case '&': + if (other->type == '&') + combined = _token_create_ival (token, AND, AND); + break; + case '|': + if (other->type == '|') + combined = _token_create_ival (token, OR, OR); + break; + } + + if (combined != NULL) { + /* Inherit the location from the first token */ + combined->location = token->location; + return combined; + } + + /* Two string-valued tokens can usually just be mashed + * together. + * + * XXX: This isn't actually legitimate. Several things here + * should result in a diagnostic since the result cannot be a + * valid, single pre-processing token. For example, pasting + * "123" and "abc" is not legal, but we don't catch that + * here. */ + if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING) && + (other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING)) + { + char *str; + + str = ralloc_asprintf (token, "%s%s", token->value.str, + other->value.str); + combined = _token_create_str (token, token->type, str); + combined->location = token->location; + return combined; + } + + glcpp_error (&token->location, parser, ""); + ralloc_strcat (&parser->info_log, "Pasting \""); + _token_print (&parser->info_log, token); + ralloc_strcat (&parser->info_log, "\" and \""); + _token_print (&parser->info_log, other); + ralloc_strcat (&parser->info_log, "\" does not give a valid preprocessing token.\n"); + + return token; +} + +static void +_token_list_print (glcpp_parser_t *parser, token_list_t *list) +{ + token_node_t *node; + + if (list == NULL) + return; + + for (node = list->head; node; node = node->next) + _token_print (&parser->output, node->token); +} + +void +yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error) +{ + glcpp_error(locp, parser, "%s", error); +} + +static void add_builtin_define(glcpp_parser_t *parser, + const char *name, int value) +{ + token_t *tok; + token_list_t *list; + + tok = _token_create_ival (parser, INTEGER, value); + + list = _token_list_create(parser); + _token_list_append(list, tok); + _define_object_macro(parser, NULL, name, list); +} + +glcpp_parser_t * +glcpp_parser_create (const struct gl_extensions *extensions, int api) +{ + glcpp_parser_t *parser; + int language_version; + + parser = ralloc (NULL, glcpp_parser_t); + + glcpp_lex_init_extra (parser, &parser->scanner); + parser->defines = hash_table_ctor (32, hash_table_string_hash, + hash_table_string_compare); + parser->active = NULL; + parser->lexing_if = 0; + parser->space_tokens = 1; + parser->newline_as_space = 0; + parser->in_control_line = 0; + parser->paren_count = 0; + + parser->skip_stack = NULL; + + parser->lex_from_list = NULL; + parser->lex_from_node = NULL; + + parser->output = ralloc_strdup(parser, ""); + parser->info_log = ralloc_strdup(parser, ""); + parser->error = 0; + + /* Add pre-defined macros. */ + add_builtin_define(parser, "GL_ARB_draw_buffers", 1); + add_builtin_define(parser, "GL_ARB_texture_rectangle", 1); + + if (api == API_OPENGLES2) + add_builtin_define(parser, "GL_ES", 1); + + if (extensions != NULL) { + if (extensions->EXT_texture_array) { + add_builtin_define(parser, "GL_EXT_texture_array", 1); + } + + if (extensions->ARB_fragment_coord_conventions) + add_builtin_define(parser, "GL_ARB_fragment_coord_conventions", + 1); + + if (extensions->ARB_explicit_attrib_location) + add_builtin_define(parser, "GL_ARB_explicit_attrib_location", 1); + } + + language_version = 110; + add_builtin_define(parser, "__VERSION__", language_version); + + return parser; +} + +int +glcpp_parser_parse (glcpp_parser_t *parser) +{ + return yyparse (parser); +} + +void +glcpp_parser_destroy (glcpp_parser_t *parser) +{ + glcpp_lex_destroy (parser->scanner); + hash_table_dtor (parser->defines); + ralloc_free (parser); +} + +typedef enum function_status +{ + FUNCTION_STATUS_SUCCESS, + FUNCTION_NOT_A_FUNCTION, + FUNCTION_UNBALANCED_PARENTHESES +} function_status_t; + +/* Find a set of function-like macro arguments by looking for a + * balanced set of parentheses. + * + * When called, 'node' should be the opening-parenthesis token, (or + * perhaps preceeding SPACE tokens). Upon successful return *last will + * be the last consumed node, (corresponding to the closing right + * parenthesis). + * + * Return values: + * + * FUNCTION_STATUS_SUCCESS: + * + * Successfully parsed a set of function arguments. + * + * FUNCTION_NOT_A_FUNCTION: + * + * Macro name not followed by a '('. This is not an error, but + * simply that the macro name should be treated as a non-macro. + * + * FUNCTION_UNBALANCED_PARENTHESES + * + * Macro name is not followed by a balanced set of parentheses. + */ +static function_status_t +_arguments_parse (argument_list_t *arguments, + token_node_t *node, + token_node_t **last) +{ + token_list_t *argument; + int paren_count; + + node = node->next; + + /* Ignore whitespace before first parenthesis. */ + while (node && node->token->type == SPACE) + node = node->next; + + if (node == NULL || node->token->type != '(') + return FUNCTION_NOT_A_FUNCTION; + + node = node->next; + + argument = _token_list_create (arguments); + _argument_list_append (arguments, argument); + + for (paren_count = 1; node; node = node->next) { + if (node->token->type == '(') + { + paren_count++; + } + else if (node->token->type == ')') + { + paren_count--; + if (paren_count == 0) + break; + } + + if (node->token->type == ',' && + paren_count == 1) + { + _token_list_trim_trailing_space (argument); + argument = _token_list_create (arguments); + _argument_list_append (arguments, argument); + } + else { + if (argument->head == NULL) { + /* Don't treat initial whitespace as + * part of the arguement. */ + if (node->token->type == SPACE) + continue; + } + _token_list_append (argument, node->token); + } + } + + if (paren_count) + return FUNCTION_UNBALANCED_PARENTHESES; + + *last = node; + + return FUNCTION_STATUS_SUCCESS; +} + +static token_list_t * +_token_list_create_with_one_space (void *ctx) +{ + token_list_t *list; + token_t *space; + + list = _token_list_create (ctx); + space = _token_create_ival (list, SPACE, SPACE); + _token_list_append (list, space); + + return list; +} + +static void +_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list) +{ + token_list_t *expanded; + token_t *token; + + expanded = _token_list_create (parser); + token = _token_create_ival (parser, type, type); + _token_list_append (expanded, token); + _glcpp_parser_expand_token_list (parser, list); + _token_list_append_list (expanded, list); + glcpp_parser_lex_from (parser, expanded); +} + +/* This is a helper function that's essentially part of the + * implementation of _glcpp_parser_expand_node. It shouldn't be called + * except for by that function. + * + * Returns NULL if node is a simple token with no expansion, (that is, + * although 'node' corresponds to an identifier defined as a + * function-like macro, it is not followed with a parenthesized + * argument list). + * + * Compute the complete expansion of node (which is a function-like + * macro) and subsequent nodes which are arguments. + * + * Returns the token list that results from the expansion and sets + * *last to the last node in the list that was consumed by the + * expansion. Specifically, *last will be set as follows: as the + * token of the closing right parenthesis. + */ +static token_list_t * +_glcpp_parser_expand_function (glcpp_parser_t *parser, + token_node_t *node, + token_node_t **last) + +{ + macro_t *macro; + const char *identifier; + argument_list_t *arguments; + function_status_t status; + token_list_t *substituted; + int parameter_index; + + identifier = node->token->value.str; + + macro = hash_table_find (parser->defines, identifier); + + assert (macro->is_function); + + arguments = _argument_list_create (parser); + status = _arguments_parse (arguments, node, last); + + switch (status) { + case FUNCTION_STATUS_SUCCESS: + break; + case FUNCTION_NOT_A_FUNCTION: + return NULL; + case FUNCTION_UNBALANCED_PARENTHESES: + glcpp_error (&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identifier); + return NULL; + } + + /* Replace a macro defined as empty with a SPACE token. */ + if (macro->replacements == NULL) { + ralloc_free (arguments); + return _token_list_create_with_one_space (parser); + } + + if (! ((_argument_list_length (arguments) == + _string_list_length (macro->parameters)) || + (_string_list_length (macro->parameters) == 0 && + _argument_list_length (arguments) == 1 && + arguments->head->argument->head == NULL))) + { + glcpp_error (&node->token->location, parser, + "Error: macro %s invoked with %d arguments (expected %d)\n", + identifier, + _argument_list_length (arguments), + _string_list_length (macro->parameters)); + return NULL; + } + + /* Perform argument substitution on the replacement list. */ + substituted = _token_list_create (arguments); + + for (node = macro->replacements->head; node; node = node->next) + { + if (node->token->type == IDENTIFIER && + _string_list_contains (macro->parameters, + node->token->value.str, + ¶meter_index)) + { + token_list_t *argument; + argument = _argument_list_member_at (arguments, + parameter_index); + /* Before substituting, we expand the argument + * tokens, or append a placeholder token for + * an empty argument. */ + if (argument->head) { + token_list_t *expanded_argument; + expanded_argument = _token_list_copy (parser, + argument); + _glcpp_parser_expand_token_list (parser, + expanded_argument); + _token_list_append_list (substituted, + expanded_argument); + } else { + token_t *new_token; + + new_token = _token_create_ival (substituted, + PLACEHOLDER, + PLACEHOLDER); + _token_list_append (substituted, new_token); + } + } else { + _token_list_append (substituted, node->token); + } + } + + /* After argument substitution, and before further expansion + * below, implement token pasting. */ + + _token_list_trim_trailing_space (substituted); + + node = substituted->head; + while (node) + { + token_node_t *next_non_space; + + /* Look ahead for a PASTE token, skipping space. */ + next_non_space = node->next; + while (next_non_space && next_non_space->token->type == SPACE) + next_non_space = next_non_space->next; + + if (next_non_space == NULL) + break; + + if (next_non_space->token->type != PASTE) { + node = next_non_space; + continue; + } + + /* Now find the next non-space token after the PASTE. */ + next_non_space = next_non_space->next; + while (next_non_space && next_non_space->token->type == SPACE) + next_non_space = next_non_space->next; + + if (next_non_space == NULL) { + yyerror (&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n"); + return NULL; + } + + node->token = _token_paste (parser, node->token, next_non_space->token); + node->next = next_non_space->next; + if (next_non_space == substituted->tail) + substituted->tail = node; + + node = node->next; + } + + substituted->non_space_tail = substituted->tail; + + return substituted; +} + +/* Compute the complete expansion of node, (and subsequent nodes after + * 'node' in the case that 'node' is a function-like macro and + * subsequent nodes are arguments). + * + * Returns NULL if node is a simple token with no expansion. + * + * Otherwise, returns the token list that results from the expansion + * and sets *last to the last node in the list that was consumed by + * the expansion. Specifically, *last will be set as follows: + * + * As 'node' in the case of object-like macro expansion. + * + * As the token of the closing right parenthesis in the case of + * function-like macro expansion. + */ +static token_list_t * +_glcpp_parser_expand_node (glcpp_parser_t *parser, + token_node_t *node, + token_node_t **last) +{ + token_t *token = node->token; + const char *identifier; + macro_t *macro; + + /* We only expand identifiers */ + if (token->type != IDENTIFIER) { + /* We change any COMMA into a COMMA_FINAL to prevent + * it being mistaken for an argument separator + * later. */ + if (token->type == ',') { + token->type = COMMA_FINAL; + token->value.ival = COMMA_FINAL; + } + + return NULL; + } + + /* Look up this identifier in the hash table. */ + identifier = token->value.str; + macro = hash_table_find (parser->defines, identifier); + + /* Not a macro, so no expansion needed. */ + if (macro == NULL) + return NULL; + + /* Finally, don't expand this macro if we're already actively + * expanding it, (to avoid infinite recursion). */ + if (_active_list_contains (parser->active, identifier)) { + /* We change the token type here from IDENTIFIER to + * OTHER to prevent any future expansion of this + * unexpanded token. */ + char *str; + token_list_t *expansion; + token_t *final; + + str = ralloc_strdup (parser, token->value.str); + final = _token_create_str (parser, OTHER, str); + expansion = _token_list_create (parser); + _token_list_append (expansion, final); + *last = node; + return expansion; + } + + if (! macro->is_function) + { + *last = node; + + /* Replace a macro defined as empty with a SPACE token. */ + if (macro->replacements == NULL) + return _token_list_create_with_one_space (parser); + + return _token_list_copy (parser, macro->replacements); + } + + return _glcpp_parser_expand_function (parser, node, last); +} + +/* Push a new identifier onto the active list, returning the new list. + * + * Here, 'marker' is the token node that appears in the list after the + * expansion of 'identifier'. That is, when the list iterator begins + * examinging 'marker', then it is time to pop this node from the + * active stack. + */ +active_list_t * +_active_list_push (active_list_t *list, + const char *identifier, + token_node_t *marker) +{ + active_list_t *node; + + node = ralloc (list, active_list_t); + node->identifier = ralloc_strdup (node, identifier); + node->marker = marker; + node->next = list; + + return node; +} + +active_list_t * +_active_list_pop (active_list_t *list) +{ + active_list_t *node = list; + + if (node == NULL) + return NULL; + + node = list->next; + ralloc_free (list); + + return node; +} + +int +_active_list_contains (active_list_t *list, const char *identifier) +{ + active_list_t *node; + + if (list == NULL) + return 0; + + for (node = list; node; node = node->next) + if (strcmp (node->identifier, identifier) == 0) + return 1; + + return 0; +} + +/* Walk over the token list replacing nodes with their expansion. + * Whenever nodes are expanded the walking will walk over the new + * nodes, continuing to expand as necessary. The results are placed in + * 'list' itself; + */ +static void +_glcpp_parser_expand_token_list (glcpp_parser_t *parser, + token_list_t *list) +{ + token_node_t *node_prev; + token_node_t *node, *last = NULL; + token_list_t *expansion; + + if (list == NULL) + return; + + _token_list_trim_trailing_space (list); + + node_prev = NULL; + node = list->head; + + while (node) { + + while (parser->active && parser->active->marker == node) + parser->active = _active_list_pop (parser->active); + + /* Find the expansion for node, which will replace all + * nodes from node to last, inclusive. */ + expansion = _glcpp_parser_expand_node (parser, node, &last); + if (expansion) { + token_node_t *n; + + for (n = node; n != last->next; n = n->next) + while (parser->active && + parser->active->marker == n) + { + parser->active = _active_list_pop (parser->active); + } + + parser->active = _active_list_push (parser->active, + node->token->value.str, + last->next); + + /* Splice expansion into list, supporting a + * simple deletion if the expansion is + * empty. */ + if (expansion->head) { + if (node_prev) + node_prev->next = expansion->head; + else + list->head = expansion->head; + expansion->tail->next = last->next; + if (last == list->tail) + list->tail = expansion->tail; + } else { + if (node_prev) + node_prev->next = last->next; + else + list->head = last->next; + if (last == list->tail) + list->tail = NULL; + } + } else { + node_prev = node; + } + node = node_prev ? node_prev->next : list->head; + } + + while (parser->active) + parser->active = _active_list_pop (parser->active); + + list->non_space_tail = list->tail; +} + +void +_glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser, + token_list_t *list) +{ + if (list == NULL) + return; + + _glcpp_parser_expand_token_list (parser, list); + + _token_list_trim_trailing_space (list); + + _token_list_print (parser, list); +} + +static void +_check_for_reserved_macro_name (glcpp_parser_t *parser, YYLTYPE *loc, + const char *identifier) +{ + /* According to the GLSL specification, macro names starting with "__" + * or "GL_" are reserved for future use. So, don't allow them. + */ + if (strncmp(identifier, "__", 2) == 0) { + glcpp_error (loc, parser, "Macro names starting with \"__\" are reserved.\n"); + } + if (strncmp(identifier, "GL_", 3) == 0) { + glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n"); + } +} + +static int +_macro_equal (macro_t *a, macro_t *b) +{ + if (a->is_function != b->is_function) + return 0; + + if (a->is_function) { + if (! _string_list_equal (a->parameters, b->parameters)) + return 0; + } + + return _token_list_equal_ignoring_space (a->replacements, + b->replacements); +} + +void +_define_object_macro (glcpp_parser_t *parser, + YYLTYPE *loc, + const char *identifier, + token_list_t *replacements) +{ + macro_t *macro, *previous; + + if (loc != NULL) + _check_for_reserved_macro_name(parser, loc, identifier); + + macro = ralloc (parser, macro_t); + + macro->is_function = 0; + macro->parameters = NULL; + macro->identifier = ralloc_strdup (macro, identifier); + macro->replacements = replacements; + ralloc_steal (macro, replacements); + + previous = hash_table_find (parser->defines, identifier); + if (previous) { + if (_macro_equal (macro, previous)) { + ralloc_free (macro); + return; + } + glcpp_error (loc, parser, "Redefinition of macro %s\n", + identifier); + } + + hash_table_insert (parser->defines, macro, identifier); +} + +void +_define_function_macro (glcpp_parser_t *parser, + YYLTYPE *loc, + const char *identifier, + string_list_t *parameters, + token_list_t *replacements) +{ + macro_t *macro, *previous; + + _check_for_reserved_macro_name(parser, loc, identifier); + + macro = ralloc (parser, macro_t); + ralloc_steal (macro, parameters); + ralloc_steal (macro, replacements); + + macro->is_function = 1; + macro->parameters = parameters; + macro->identifier = ralloc_strdup (macro, identifier); + macro->replacements = replacements; + previous = hash_table_find (parser->defines, identifier); + if (previous) { + if (_macro_equal (macro, previous)) { + ralloc_free (macro); + return; + } + glcpp_error (loc, parser, "Redefinition of macro %s\n", + identifier); + } + + hash_table_insert (parser->defines, macro, identifier); +} + +static int +glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser) +{ + token_node_t *node; + int ret; + + if (parser->lex_from_list == NULL) { + ret = glcpp_lex (yylval, yylloc, parser->scanner); + + /* XXX: This ugly block of code exists for the sole + * purpose of converting a NEWLINE token into a SPACE + * token, but only in the case where we have seen a + * function-like macro name, but have not yet seen its + * closing parenthesis. + * + * There's perhaps a more compact way to do this with + * mid-rule actions in the grammar. + * + * I'm definitely not pleased with the complexity of + * this code here. + */ + if (parser->newline_as_space) + { + if (ret == '(') { + parser->paren_count++; + } else if (ret == ')') { + parser->paren_count--; + if (parser->paren_count == 0) + parser->newline_as_space = 0; + } else if (ret == NEWLINE) { + ret = SPACE; + } else if (ret != SPACE) { + if (parser->paren_count == 0) + parser->newline_as_space = 0; + } + } + else if (parser->in_control_line) + { + if (ret == NEWLINE) + parser->in_control_line = 0; + } + else if (ret == HASH_DEFINE_OBJ || ret == HASH_DEFINE_FUNC || + ret == HASH_UNDEF || ret == HASH_IF || + ret == HASH_IFDEF || ret == HASH_IFNDEF || + ret == HASH_ELIF || ret == HASH_ELSE || + ret == HASH_ENDIF || ret == HASH) + { + parser->in_control_line = 1; + } + else if (ret == IDENTIFIER) + { + macro_t *macro; + macro = hash_table_find (parser->defines, + yylval->str); + if (macro && macro->is_function) { + parser->newline_as_space = 1; + parser->paren_count = 0; + } + } + + return ret; + } + + node = parser->lex_from_node; + + if (node == NULL) { + ralloc_free (parser->lex_from_list); + parser->lex_from_list = NULL; + return NEWLINE; + } + + *yylval = node->token->value; + ret = node->token->type; + + parser->lex_from_node = node->next; + + return ret; +} + +static void +glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list) +{ + token_node_t *node; + + assert (parser->lex_from_list == NULL); + + /* Copy list, eliminating any space tokens. */ + parser->lex_from_list = _token_list_create (parser); + + for (node = list->head; node; node = node->next) { + if (node->token->type == SPACE) + continue; + _token_list_append (parser->lex_from_list, node->token); + } + + ralloc_free (list); + + parser->lex_from_node = parser->lex_from_list->head; + + /* It's possible the list consisted of nothing but whitespace. */ + if (parser->lex_from_node == NULL) { + ralloc_free (parser->lex_from_list); + parser->lex_from_list = NULL; + } +} + +static void +_glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc, + int condition) +{ + skip_type_t current = SKIP_NO_SKIP; + skip_node_t *node; + + if (parser->skip_stack) + current = parser->skip_stack->type; + + node = ralloc (parser, skip_node_t); + node->loc = *loc; + + if (current == SKIP_NO_SKIP) { + if (condition) + node->type = SKIP_NO_SKIP; + else + node->type = SKIP_TO_ELSE; + } else { + node->type = SKIP_TO_ENDIF; + } + + node->next = parser->skip_stack; + parser->skip_stack = node; +} + +static void +_glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc, + const char *type, int condition) +{ + if (parser->skip_stack == NULL) { + glcpp_error (loc, parser, "%s without #if\n", type); + return; + } + + if (parser->skip_stack->type == SKIP_TO_ELSE) { + if (condition) + parser->skip_stack->type = SKIP_NO_SKIP; + } else { + parser->skip_stack->type = SKIP_TO_ENDIF; + } +} + +static void +_glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc) +{ + skip_node_t *node; + + if (parser->skip_stack == NULL) { + glcpp_error (loc, parser, "#endif without #if\n"); + return; + } + + node = parser->skip_stack; + parser->skip_stack = node->next; + ralloc_free (node); +} diff --git a/src/glsl/glcpp/glcpp.c b/src/glsl/glcpp/glcpp.c new file mode 100644 index 0000000..564194c --- /dev/null +++ b/src/glsl/glcpp/glcpp.c @@ -0,0 +1,131 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include "glcpp.h" +#include "main/mtypes.h" +#include "main/shaderobj.h" + +extern int yydebug; + +void +_mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr, + struct gl_shader *sh) +{ + *ptr = sh; +} + +/* Read from fd until EOF and return a string of everything read. + */ +static char * +load_text_fd (void *ctx, int fd) +{ +#define CHUNK 4096 + char *text = NULL; + ssize_t text_size = 0; + ssize_t total_read = 0; + ssize_t bytes; + + while (1) { + if (total_read + CHUNK + 1 > text_size) { + text_size = text_size ? text_size * 2 : CHUNK + 1; + text = reralloc_size (ctx, text, text_size); + if (text == NULL) { + fprintf (stderr, "Out of memory\n"); + return NULL; + } + } + bytes = read (fd, text + total_read, CHUNK); + if (bytes < 0) { + fprintf (stderr, "Error while reading: %s\n", + strerror (errno)); + ralloc_free (text); + return NULL; + } + + if (bytes == 0) { + break; + } + + total_read += bytes; + } + + text[total_read] = '\0'; + + return text; +} + +static char * +load_text_file(void *ctx, const char *filename) +{ + char *text; + int fd; + + if (filename == NULL || strcmp (filename, "-") == 0) + return load_text_fd (ctx, STDIN_FILENO); + + fd = open (filename, O_RDONLY); + if (fd < 0) { + fprintf (stderr, "Failed to open file %s: %s\n", + filename, strerror (errno)); + return NULL; + } + + text = load_text_fd (ctx, fd); + + close(fd); + + return text; +} + +int +main (int argc, char *argv[]) +{ + char *filename = NULL; + void *ctx = ralloc(NULL, void*); + char *info_log = ralloc_strdup(ctx, ""); + const char *shader; + int ret; + + if (argc) { + filename = argv[1]; + } + + shader = load_text_file (ctx, filename); + if (shader == NULL) + return 1; + + ret = preprocess(ctx, &shader, &info_log, NULL, API_OPENGL); + + printf("%s", shader); + fprintf(stderr, "%s", info_log); + + ralloc_free(ctx); + + return ret; +} diff --git a/src/glsl/glcpp/glcpp.h b/src/glsl/glcpp/glcpp.h new file mode 100644 index 0000000..dc816e9 --- /dev/null +++ b/src/glsl/glcpp/glcpp.h @@ -0,0 +1,222 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef GLCPP_H +#define GLCPP_H + +#include + +#include "../ralloc.h" + +#include "program/hash_table.h" + +#define yyscan_t void* + +/* Some data types used for parser values. */ + +typedef struct string_node { + const char *str; + struct string_node *next; +} string_node_t; + +typedef struct string_list { + string_node_t *head; + string_node_t *tail; +} string_list_t; + +typedef struct token token_t; +typedef struct token_list token_list_t; + +typedef union YYSTYPE +{ + intmax_t ival; + char *str; + string_list_t *string_list; + token_t *token; + token_list_t *token_list; +} YYSTYPE; + +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 + +typedef struct YYLTYPE { + int first_line; + int first_column; + int last_line; + int last_column; + unsigned source; +} YYLTYPE; +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 + +# define YYLLOC_DEFAULT(Current, Rhs, N) \ +do { \ + if (N) \ + { \ + (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC(Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC(Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC(Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC(Rhs, 0).last_column; \ + } \ + (Current).source = 0; \ +} while (0) + +struct token { + int type; + YYSTYPE value; + YYLTYPE location; +}; + +typedef struct token_node { + token_t *token; + struct token_node *next; +} token_node_t; + +struct token_list { + token_node_t *head; + token_node_t *tail; + token_node_t *non_space_tail; +}; + +typedef struct argument_node { + token_list_t *argument; + struct argument_node *next; +} argument_node_t; + +typedef struct argument_list { + argument_node_t *head; + argument_node_t *tail; +} argument_list_t; + +typedef struct glcpp_parser glcpp_parser_t; + +typedef enum { + TOKEN_CLASS_IDENTIFIER, + TOKEN_CLASS_IDENTIFIER_FINALIZED, + TOKEN_CLASS_FUNC_MACRO, + TOKEN_CLASS_OBJ_MACRO +} token_class_t; + +token_class_t +glcpp_parser_classify_token (glcpp_parser_t *parser, + const char *identifier, + int *parameter_index); + +typedef struct { + int is_function; + string_list_t *parameters; + const char *identifier; + token_list_t *replacements; +} macro_t; + +typedef struct expansion_node { + macro_t *macro; + token_node_t *replacements; + struct expansion_node *next; +} expansion_node_t; + +typedef enum skip_type { + SKIP_NO_SKIP, + SKIP_TO_ELSE, + SKIP_TO_ENDIF +} skip_type_t; + +typedef struct skip_node { + skip_type_t type; + YYLTYPE loc; /* location of the initial #if/#elif/... */ + struct skip_node *next; +} skip_node_t; + +typedef struct active_list { + const char *identifier; + token_node_t *marker; + struct active_list *next; +} active_list_t; + +struct glcpp_parser { + yyscan_t scanner; + struct hash_table *defines; + active_list_t *active; + int lexing_if; + int space_tokens; + int newline_as_space; + int in_control_line; + int paren_count; + skip_node_t *skip_stack; + token_list_t *lex_from_list; + token_node_t *lex_from_node; + char *output; + char *info_log; + int error; +}; + +struct gl_extensions; + +glcpp_parser_t * +glcpp_parser_create (const struct gl_extensions *extensions, int api); + +int +glcpp_parser_parse (glcpp_parser_t *parser); + +void +glcpp_parser_destroy (glcpp_parser_t *parser); + +int +preprocess(void *ralloc_ctx, const char **shader, char **info_log, + const struct gl_extensions *extensions, int api); + +/* Functions for writing to the info log */ + +void +glcpp_error (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...); + +void +glcpp_warning (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...); + +/* Generated by glcpp-lex.l to glcpp-lex.c */ + +int +glcpp_lex_init_extra (glcpp_parser_t *parser, yyscan_t* scanner); + +void +glcpp_lex_set_source_string(glcpp_parser_t *parser, const char *shader); + +int +glcpp_lex (YYSTYPE *lvalp, YYLTYPE *llocp, yyscan_t scanner); + +int +glcpp_lex_destroy (yyscan_t scanner); + +/* Generated by glcpp-parse.y to glcpp-parse.c */ + +int +yyparse (glcpp_parser_t *parser); + +#endif diff --git a/src/glsl/glcpp/pp.c b/src/glsl/glcpp/pp.c new file mode 100644 index 0000000..3640896 --- /dev/null +++ b/src/glsl/glcpp/pp.c @@ -0,0 +1,165 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include "glcpp.h" +#include "main/core.h" /* for isblank() on MSVC */ + +void +glcpp_error (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...) +{ + va_list ap; + + parser->error = 1; + ralloc_asprintf_append(&parser->info_log, "%u:%u(%u): " + "preprocessor error: ", + locp->source, + locp->first_line, + locp->first_column); + va_start(ap, fmt); + ralloc_vasprintf_append(&parser->info_log, fmt, ap); + va_end(ap); + ralloc_strcat(&parser->info_log, "\n"); +} + +void +glcpp_warning (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...) +{ + va_list ap; + + ralloc_asprintf_append(&parser->info_log, "%u:%u(%u): " + "preprocessor warning: ", + locp->source, + locp->first_line, + locp->first_column); + va_start(ap, fmt); + ralloc_vasprintf_append(&parser->info_log, fmt, ap); + va_end(ap); + ralloc_strcat(&parser->info_log, "\n"); +} + +/* Searches backwards for '^ *#' from a given starting point. */ +static int +in_directive(const char *shader, const char *ptr) +{ + assert(ptr >= shader); + + /* Search backwards for '#'. If we find a \n first, it doesn't count */ + for (; ptr >= shader && *ptr != '#'; ptr--) { + if (*ptr == '\n') + return 0; + } + if (ptr >= shader) { + /* Found '#'...look for spaces preceded by a newline */ + for (ptr--; ptr >= shader && isblank(*ptr); ptr--); + // FIXME: I don't think the '\n' case can happen + if (ptr < shader || *ptr == '\n') + return 1; + } + return 0; +} + +/* Remove any line continuation characters in preprocessing directives. + * However, ignore any in GLSL code, as "There is no line continuation + * character" (1.30 page 9) in GLSL. + */ +static char * +remove_line_continuations(glcpp_parser_t *ctx, const char *shader) +{ + int in_continued_line = 0; + int extra_newlines = 0; + char *clean = ralloc_strdup(ctx, ""); + const char *search_start = shader; + const char *newline; + while ((newline = strchr(search_start, '\n')) != NULL) { + const char *backslash = NULL; + + /* # of characters preceding the newline. */ + int n = newline - shader; + + /* Find the preceding '\', if it exists */ + if (n >= 1 && newline[-1] == '\\') + backslash = newline - 1; + else if (n >= 2 && newline[-1] == '\r' && newline[-2] == '\\') + backslash = newline - 2; + + /* Double backslashes don't count (the backslash is escaped) */ + if (backslash != NULL && backslash[-1] == '\\') { + backslash = NULL; + } + + if (backslash != NULL) { + /* We found a line continuation, but do we care? */ + if (!in_continued_line) { + if (in_directive(shader, backslash)) { + in_continued_line = 1; + extra_newlines = 0; + } + } + if (in_continued_line) { + /* Copy everything before the \ */ + ralloc_strncat(&clean, shader, backslash - shader); + shader = newline + 1; + extra_newlines++; + } + } else if (in_continued_line) { + /* Copy everything up to and including the \n */ + ralloc_strncat(&clean, shader, newline - shader + 1); + shader = newline + 1; + /* Output extra newlines to make line numbers match */ + for (; extra_newlines > 0; extra_newlines--) + ralloc_strcat(&clean, "\n"); + in_continued_line = 0; + } + search_start = newline + 1; + } + ralloc_strcat(&clean, shader); + return clean; +} + +int +preprocess(void *ralloc_ctx, const char **shader, char **info_log, + const struct gl_extensions *extensions, int api) +{ + int errors; + glcpp_parser_t *parser = glcpp_parser_create (extensions, api); + *shader = remove_line_continuations(parser, *shader); + + glcpp_lex_set_source_string (parser, *shader); + + glcpp_parser_parse (parser); + + if (parser->skip_stack) + glcpp_error (&parser->skip_stack->loc, parser, "Unterminated #if\n"); + + ralloc_strcat(info_log, parser->info_log); + + ralloc_steal(ralloc_ctx, parser->output); + *shader = parser->output; + + errors = parser->error; + glcpp_parser_destroy (parser); + return errors; +} diff --git a/src/glsl/glsl_lexer.cpp b/src/glsl/glsl_lexer.cpp new file mode 100644 index 0000000..08a2f70 --- /dev/null +++ b/src/glsl/glsl_lexer.cpp @@ -0,0 +1,3725 @@ +#line 2 "glsl_lexer.cpp" + +#line 4 "glsl_lexer.cpp" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; +#endif /* ! C99 */ + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* An opaque pointer. */ +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif + +/* For convenience, these vars (plus the bison vars far below) + are macros in the reentrant scanner. */ +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yy_flex_debug yyg->yy_flex_debug_r + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN yyg->yy_start = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START ((yyg->yy_start - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE _mesa_glsl_restart(yyin ,yyscanner ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE 16384 +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = yyg->yy_hold_char; \ + YY_RESTORE_YY_MORE_OFFSET \ + yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via _mesa_glsl_restart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ + ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] + +void _mesa_glsl_restart (FILE *input_file ,yyscan_t yyscanner ); +void _mesa_glsl__switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); +YY_BUFFER_STATE _mesa_glsl__create_buffer (FILE *file,int size ,yyscan_t yyscanner ); +void _mesa_glsl__delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); +void _mesa_glsl__flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); +void _mesa_glsl_push_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); +void _mesa_glsl_pop_buffer_state (yyscan_t yyscanner ); + +static void _mesa_glsl_ensure_buffer_stack (yyscan_t yyscanner ); +static void _mesa_glsl__load_buffer_state (yyscan_t yyscanner ); +static void _mesa_glsl__init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner ); + +#define YY_FLUSH_BUFFER _mesa_glsl__flush_buffer(YY_CURRENT_BUFFER ,yyscanner) + +YY_BUFFER_STATE _mesa_glsl__scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); +YY_BUFFER_STATE _mesa_glsl__scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); +YY_BUFFER_STATE _mesa_glsl__scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner ); + +void *_mesa_glsl_alloc (yy_size_t ,yyscan_t yyscanner ); +void *_mesa_glsl_realloc (void *,yy_size_t ,yyscan_t yyscanner ); +void _mesa_glsl_free (void * ,yyscan_t yyscanner ); + +#define yy_new_buffer _mesa_glsl__create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + _mesa_glsl_ensure_buffer_stack (yyscanner); \ + YY_CURRENT_BUFFER_LVALUE = \ + _mesa_glsl__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + _mesa_glsl_ensure_buffer_stack (yyscanner); \ + YY_CURRENT_BUFFER_LVALUE = \ + _mesa_glsl__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +#define _mesa_glsl_wrap(n) 1 +#define YY_SKIP_YYWRAP + +typedef unsigned char YY_CHAR; + +typedef int yy_state_type; + +#define yytext_ptr yytext_r + +static yy_state_type yy_get_previous_state (yyscan_t yyscanner ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner); +static int yy_get_next_buffer (yyscan_t yyscanner ); +static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + yyg->yytext_ptr = yy_bp; \ + yyleng = (size_t) (yy_cp - yy_bp); \ + yyg->yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yyg->yy_c_buf_p = yy_cp; + +#define YY_NUM_RULES 210 +#define YY_END_OF_BUFFER 211 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[836] = + { 0, + 0, 0, 16, 16, 0, 0, 211, 209, 1, 21, + 209, 209, 209, 209, 209, 209, 209, 209, 120, 118, + 209, 209, 209, 208, 209, 208, 208, 208, 208, 208, + 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, + 208, 208, 208, 208, 208, 209, 1, 209, 210, 16, + 20, 210, 19, 17, 18, 14, 13, 1, 102, 111, + 103, 114, 108, 97, 110, 98, 117, 122, 109, 123, + 120, 0, 0, 125, 120, 0, 118, 118, 106, 99, + 101, 100, 107, 208, 115, 105, 208, 208, 208, 208, + 208, 208, 208, 208, 208, 208, 208, 208, 30, 208, + + 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, + 208, 208, 34, 208, 208, 61, 208, 208, 208, 208, + 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, + 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, + 208, 208, 208, 208, 208, 208, 208, 208, 208, 116, + 104, 1, 0, 0, 2, 0, 0, 0, 0, 16, + 15, 19, 18, 0, 122, 121, 0, 123, 0, 124, + 119, 112, 113, 208, 128, 208, 208, 208, 208, 208, + 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, + 208, 208, 208, 208, 208, 208, 33, 208, 208, 208, + + 208, 208, 208, 208, 208, 208, 208, 26, 208, 208, + 208, 208, 208, 208, 208, 208, 208, 208, 208, 62, + 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, + 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, + 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, + 0, 0, 0, 0, 15, 0, 122, 0, 121, 0, + 123, 124, 119, 208, 208, 24, 208, 208, 175, 168, + 208, 208, 208, 208, 208, 208, 208, 208, 208, 32, + 131, 208, 208, 208, 208, 68, 208, 208, 136, 150, + 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, + + 208, 208, 147, 171, 49, 50, 51, 208, 208, 208, + 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, + 208, 208, 208, 208, 208, 208, 208, 134, 126, 208, + 208, 27, 208, 208, 208, 208, 208, 208, 208, 46, + 47, 48, 95, 208, 208, 0, 0, 0, 0, 0, + 121, 208, 208, 28, 37, 38, 39, 208, 129, 208, + 23, 208, 208, 208, 208, 158, 159, 160, 208, 127, + 208, 151, 25, 161, 162, 163, 173, 155, 156, 157, + 208, 208, 208, 63, 153, 208, 208, 208, 40, 41, + 42, 208, 208, 208, 208, 208, 208, 208, 208, 208, + + 208, 208, 208, 208, 208, 208, 208, 148, 208, 208, + 208, 208, 208, 208, 208, 208, 208, 208, 130, 208, + 208, 170, 43, 44, 45, 208, 208, 31, 0, 0, + 0, 0, 178, 208, 208, 176, 208, 208, 208, 149, + 144, 181, 208, 208, 208, 208, 208, 208, 139, 208, + 208, 208, 96, 52, 53, 54, 55, 56, 57, 58, + 59, 60, 208, 208, 208, 208, 154, 135, 208, 208, + 142, 36, 208, 208, 167, 69, 143, 94, 179, 137, + 208, 208, 208, 208, 208, 208, 208, 208, 0, 0, + 0, 0, 208, 208, 208, 138, 35, 208, 208, 208, + + 208, 208, 208, 182, 183, 184, 208, 208, 208, 208, + 208, 172, 208, 208, 208, 208, 208, 208, 208, 208, + 132, 208, 208, 208, 208, 208, 64, 208, 208, 65, + 208, 0, 0, 0, 0, 0, 208, 66, 29, 145, + 186, 187, 188, 208, 208, 208, 208, 208, 208, 208, + 208, 208, 208, 208, 208, 140, 208, 208, 208, 208, + 208, 208, 208, 208, 208, 133, 190, 191, 192, 208, + 208, 152, 208, 141, 0, 0, 6, 0, 0, 0, + 12, 3, 22, 208, 208, 208, 208, 208, 208, 208, + 208, 208, 185, 146, 67, 208, 208, 208, 208, 169, + + 208, 177, 174, 207, 71, 72, 73, 208, 208, 208, + 208, 208, 208, 208, 208, 208, 208, 0, 0, 0, + 0, 0, 0, 0, 208, 208, 208, 189, 208, 208, + 208, 208, 208, 82, 83, 84, 208, 208, 208, 208, + 208, 208, 208, 208, 208, 208, 208, 208, 208, 193, + 88, 89, 90, 208, 4, 0, 5, 0, 0, 0, + 0, 0, 0, 208, 208, 208, 208, 208, 208, 208, + 204, 208, 208, 208, 208, 208, 208, 208, 208, 208, + 208, 208, 74, 208, 208, 208, 208, 208, 208, 0, + 0, 0, 0, 208, 208, 205, 194, 208, 195, 208, + + 208, 208, 85, 208, 208, 208, 208, 208, 208, 208, + 208, 208, 208, 208, 206, 208, 208, 91, 0, 0, + 0, 196, 197, 208, 200, 208, 201, 208, 208, 70, + 208, 208, 208, 164, 208, 165, 180, 208, 198, 199, + 208, 208, 0, 0, 0, 208, 208, 208, 208, 75, + 208, 76, 208, 208, 208, 208, 208, 0, 0, 0, + 0, 208, 208, 86, 87, 208, 77, 208, 208, 78, + 208, 92, 93, 0, 0, 0, 0, 208, 208, 208, + 208, 208, 208, 0, 0, 0, 0, 208, 208, 208, + 208, 208, 79, 0, 0, 0, 7, 0, 0, 202, + + 203, 208, 208, 208, 0, 0, 8, 0, 0, 208, + 208, 166, 0, 0, 0, 80, 81, 0, 0, 0, + 9, 0, 0, 10, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 11, 0 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 5, 1, 6, 1, 7, 8, 1, 9, + 10, 11, 12, 1, 13, 14, 15, 16, 17, 18, + 19, 20, 21, 21, 21, 22, 22, 23, 1, 24, + 25, 26, 1, 1, 27, 28, 29, 30, 31, 32, + 33, 34, 34, 34, 34, 35, 34, 34, 34, 34, + 34, 36, 37, 38, 39, 34, 34, 40, 34, 34, + 1, 1, 1, 41, 42, 1, 43, 44, 45, 46, + + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + 57, 58, 34, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 1, 68, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[69] = + { 0, + 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, + 3, 3, 1, 1, 1, 1, 4, 4, 4, 4, + 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, + 1, 5, 4, 4, 4, 4, 3, 3, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 1 + } ; + +static yyconst flex_int16_t yy_base[845] = + { 0, + 0, 67, 73, 0, 1210, 1209, 1211, 1214, 68, 1214, + 1185, 1184, 134, 1183, 131, 132, 130, 1182, 146, 198, + 129, 1181, 144, 0, 130, 113, 124, 141, 150, 126, + 181, 1148, 159, 192, 118, 129, 146, 1142, 147, 174, + 206, 192, 203, 222, 1153, 203, 221, 231, 1214, 260, + 1214, 1187, 279, 1214, 0, 1214, 1214, 270, 1214, 1214, + 1214, 1214, 1214, 1214, 1214, 1214, 1214, 244, 1214, 255, + 139, 290, 307, 1214, 1214, 0, 0, 1214, 1176, 1214, + 1214, 1214, 1175, 0, 1214, 1214, 1138, 1143, 1136, 1139, + 1148, 1147, 1133, 1136, 1148, 144, 1142, 1129, 1126, 1140, + + 1126, 1123, 1123, 1129, 219, 193, 1123, 1134, 1119, 1125, + 1129, 1130, 0, 1121, 1132, 278, 1131, 1126, 1106, 224, + 1110, 1124, 1114, 232, 1107, 271, 1120, 1122, 1104, 1100, + 1108, 1105, 1094, 1103, 234, 1101, 1107, 1102, 1105, 1093, + 1096, 226, 145, 262, 1106, 1093, 1106, 263, 1099, 1214, + 1214, 338, 331, 343, 1214, 1084, 1097, 1088, 1099, 345, + 0, 334, 0, 345, 1214, 328, 391, 1214, 352, 398, + 338, 1214, 1214, 1094, 0, 1085, 1089, 1099, 1096, 332, + 1079, 1079, 1083, 320, 1094, 1091, 1091, 1089, 1086, 1077, + 1084, 1070, 1068, 1081, 1066, 1083, 0, 1080, 1067, 1075, + + 1072, 1076, 1077, 1070, 1067, 1055, 1054, 1068, 1071, 1058, + 1067, 1054, 1061, 1051, 364, 1057, 1060, 1050, 1058, 1046, + 1050, 1041, 1056, 1046, 1037, 1056, 1039, 1037, 1048, 1037, + 1032, 1030, 1044, 1029, 1031, 1028, 1040, 1039, 1042, 1023, + 338, 1032, 1027, 1025, 1035, 1013, 403, 1032, 1034, 1022, + 1014, 1018, 1030, 1013, 0, 415, 422, 439, 1214, 446, + 455, 1214, 1214, 1008, 1019, 0, 1016, 406, 0, 0, + 1009, 1007, 1009, 1004, 1013, 1001, 1019, 1007, 409, 0, + 0, 1001, 1012, 1011, 1011, 0, 995, 429, 0, 0, + 997, 460, 1005, 1006, 996, 990, 989, 990, 989, 989, + + 463, 984, 0, 0, 980, 979, 978, 980, 981, 986, + 980, 976, 990, 985, 984, 983, 974, 977, 977, 969, + 972, 967, 976, 981, 966, 979, 969, 0, 0, 976, + 972, 0, 963, 963, 969, 959, 967, 466, 964, 0, + 0, 0, 0, 953, 966, 965, 964, 961, 949, 472, + 479, 961, 963, 0, 0, 0, 0, 949, 0, 949, + 0, 948, 949, 943, 954, 0, 0, 0, 944, 0, + 940, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 951, 487, 950, 0, 0, 948, 944, 940, 0, 0, + 0, 932, 489, 494, 499, 937, 933, 939, 929, 927, + + 941, 925, 925, 939, 927, 939, 934, 0, 932, 929, + 933, 916, 918, 925, 931, 926, 925, 912, 0, 914, + 915, 0, 0, 0, 0, 912, 916, 0, 910, 963, + 909, 912, 0, 900, 910, 0, 898, 898, 912, 0, + 914, 0, 503, 926, 925, 924, 891, 890, 0, 908, + 907, 902, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 890, 904, 890, 887, 0, 0, 893, 892, + 0, 0, 890, 882, 0, 0, 0, 0, 0, 0, + 879, 891, 506, 883, 890, 889, 886, 880, 873, 524, + 889, 874, 869, 883, 881, 0, 0, 873, 896, 895, + + 894, 861, 860, 361, 365, 0, 873, 876, 874, 862, + 858, 0, 871, 868, 867, 856, 855, 854, 519, 863, + 0, 879, 878, 877, 844, 843, 0, 858, 844, 0, + 855, 850, 547, 553, 898, 843, 851, 0, 0, 0, + 870, 869, 0, 847, 850, 834, 842, 832, 840, 841, + 841, 840, 825, 559, 838, 0, 839, 827, 826, 822, + 850, 849, 848, 815, 814, 0, 848, 847, 0, 825, + 828, 0, 562, 0, 814, 580, 1214, 587, 0, 607, + 584, 1214, 0, 811, 810, 820, 820, 807, 822, 805, + 820, 815, 0, 0, 0, 831, 830, 829, 796, 0, + + 796, 0, 0, 0, 502, 524, 820, 807, 810, 794, + 793, 803, 803, 819, 818, 817, 784, 789, 615, 640, + 550, 806, 796, 784, 782, 781, 792, 0, 795, 791, + 793, 789, 775, 806, 805, 0, 787, 779, 770, 778, + 768, 779, 775, 777, 775, 775, 762, 761, 772, 0, + 791, 790, 0, 772, 1214, 555, 1214, 647, 0, 667, + 785, 770, 752, 769, 768, 751, 743, 751, 741, 749, + 0, 746, 745, 756, 739, 742, 757, 740, 753, 754, + 751, 748, 757, 750, 749, 732, 731, 730, 741, 582, + 754, 724, 734, 718, 717, 0, 745, 717, 743, 715, + + 719, 718, 0, 729, 732, 728, 730, 711, 725, 709, + 710, 718, 701, 700, 0, 706, 705, 0, 728, 713, + 706, 0, 0, 710, 0, 709, 0, 715, 714, 0, + 690, 698, 688, 716, 695, 0, 0, 708, 0, 0, + 707, 706, 746, 611, 696, 703, 702, 678, 677, 705, + 677, 703, 689, 674, 691, 670, 669, 190, 613, 557, + 667, 687, 686, 0, 0, 681, 0, 680, 686, 0, + 671, 0, 0, 671, 590, 343, 672, 645, 644, 654, + 635, 631, 612, 612, 604, 443, 635, 576, 575, 549, + 25, 87, 0, 183, 500, 552, 1214, 636, 591, 0, + + 0, 196, 258, 254, 272, 609, 1214, 614, 598, 279, + 284, 0, 336, 348, 671, 0, 0, 362, 672, 688, + 1214, 394, 689, 1214, 408, 670, 691, 649, 651, 474, + 476, 693, 694, 1214, 1214, 704, 707, 710, 530, 591, + 713, 717, 720, 722 + } ; + +static yyconst flex_int16_t yy_def[845] = + { 0, + 835, 1, 835, 3, 836, 836, 835, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 835, 835, 835, 837, 835, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 838, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 839, 835, 840, + 19, 835, 835, 835, 835, 841, 20, 835, 835, 835, + 835, 835, 835, 837, 835, 835, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 842, 835, 838, 835, 835, 840, 835, 835, 835, 835, + 841, 835, 835, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 835, 835, 835, 835, 842, 835, 835, 835, 835, 835, + 835, 835, 835, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 835, 835, 835, 835, 835, + 835, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 835, 835, + 835, 835, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 835, 835, + 835, 835, 837, 837, 837, 837, 837, 837, 837, 837, + + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 835, 835, 835, 835, 835, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 835, 835, 835, 835, 843, 835, + 835, 835, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 835, 835, 835, + 843, 835, 835, 835, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 835, 835, 835, 835, 844, 835, + 835, 835, 835, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 844, + 835, 835, 835, 837, 837, 837, 837, 837, 837, 837, + + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 835, 835, + 835, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 835, 835, 835, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 837, 837, 837, 835, 835, 835, + 835, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 835, 835, 835, 835, 837, 837, 837, + 837, 837, 837, 835, 835, 835, 835, 837, 837, 837, + 837, 837, 837, 835, 835, 835, 835, 835, 835, 837, + + 837, 837, 837, 837, 835, 835, 835, 835, 835, 837, + 837, 837, 835, 835, 835, 837, 837, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 0, 835, 835, 835, 835, 835, + 835, 835, 835, 835 + } ; + +static yyconst flex_int16_t yy_nxt[1283] = + { 0, + 8, 9, 10, 9, 11, 8, 12, 13, 8, 8, + 14, 15, 16, 17, 18, 19, 20, 20, 20, 20, + 20, 20, 8, 21, 22, 23, 24, 24, 24, 24, + 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, + 25, 24, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 24, 24, 35, 36, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 24, 24, 24, 46, 47, 58, + 803, 58, 48, 49, 50, 51, 50, 49, 49, 49, + 49, 49, 49, 49, 49, 49, 49, 52, 49, 53, + 53, 53, 53, 53, 53, 54, 49, 49, 49, 55, + + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 49, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 49, 61, 64, 804, 66, 68, 68, 68, 68, 68, + 68, 68, 79, 80, 85, 65, 67, 87, 62, 70, + 119, 71, 71, 71, 71, 71, 71, 72, 82, 83, + 86, 121, 88, 89, 120, 122, 73, 74, 835, 101, + 90, 102, 91, 93, 75, 76, 92, 94, 123, 126, + 103, 758, 73, 74, 95, 241, 97, 96, 183, 184, + + 98, 110, 124, 835, 242, 127, 99, 75, 128, 111, + 76, 70, 100, 77, 77, 77, 77, 77, 77, 77, + 129, 112, 152, 104, 58, 805, 153, 150, 73, 74, + 130, 105, 154, 155, 106, 195, 78, 107, 138, 113, + 774, 139, 114, 108, 73, 74, 115, 116, 131, 196, + 140, 117, 810, 142, 118, 132, 133, 141, 143, 78, + 134, 160, 144, 160, 146, 145, 135, 136, 147, 137, + 151, 58, 193, 58, 164, 165, 231, 156, 148, 213, + 239, 240, 218, 194, 157, 167, 168, 214, 158, 219, + 164, 165, 232, 159, 162, 162, 162, 162, 162, 162, + + 162, 167, 168, 70, 243, 72, 72, 72, 72, 72, + 72, 72, 244, 248, 811, 221, 249, 812, 169, 169, + 73, 74, 170, 170, 170, 170, 170, 170, 170, 222, + 813, 205, 154, 155, 206, 207, 73, 74, 208, 152, + 209, 58, 816, 153, 154, 155, 160, 817, 160, 162, + 162, 162, 162, 162, 162, 162, 256, 256, 258, 259, + 257, 257, 257, 257, 257, 257, 257, 170, 170, 170, + 170, 170, 170, 170, 258, 259, 263, 156, 269, 274, + 275, 305, 306, 307, 157, 333, 818, 546, 158, 156, + 785, 548, 270, 159, 334, 819, 157, 547, 786, 263, + + 158, 549, 260, 260, 822, 159, 261, 261, 261, 261, + 261, 261, 261, 170, 170, 170, 170, 170, 170, 170, + 340, 341, 342, 355, 356, 357, 366, 367, 368, 262, + 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, + 257, 257, 257, 257, 796, 262, 374, 375, 376, 825, + 350, 350, 797, 165, 351, 351, 351, 351, 351, 351, + 351, 261, 261, 261, 261, 261, 261, 261, 826, 165, + 261, 261, 261, 261, 261, 261, 261, 378, 379, 380, + 389, 390, 391, 423, 424, 425, 168, 351, 351, 351, + 351, 351, 351, 351, 351, 351, 351, 351, 351, 351, + + 351, 806, 168, 444, 445, 446, 454, 455, 456, 807, + 259, 457, 458, 459, 447, 448, 460, 461, 462, 499, + 500, 501, 522, 523, 524, 490, 259, 831, 639, 832, + 502, 503, 68, 525, 526, 561, 562, 563, 640, 533, + 534, 534, 534, 534, 534, 534, 564, 565, 576, 577, + 641, 576, 577, 796, 576, 577, 656, 657, 775, 642, + 643, 797, 578, 578, 578, 578, 578, 578, 580, 580, + 580, 580, 580, 580, 580, 596, 597, 598, 614, 615, + 616, 576, 577, 656, 657, 581, 579, 599, 576, 577, + 617, 775, 808, 166, 802, 619, 620, 620, 620, 620, + + 620, 620, 578, 578, 578, 578, 578, 578, 576, 577, + 806, 579, 759, 776, 759, 808, 656, 657, 807, 760, + 622, 760, 580, 580, 580, 580, 580, 580, 580, 623, + 658, 658, 658, 658, 658, 658, 798, 798, 801, 800, + 624, 656, 657, 799, 799, 814, 776, 809, 656, 657, + 829, 795, 829, 815, 659, 660, 660, 660, 660, 660, + 660, 660, 658, 658, 658, 658, 658, 658, 656, 657, + 809, 827, 820, 823, 794, 793, 792, 791, 828, 659, + 821, 824, 660, 660, 660, 660, 660, 660, 660, 820, + 823, 830, 827, 830, 833, 833, 790, 821, 824, 828, + + 789, 788, 834, 834, 56, 56, 56, 56, 56, 84, + 84, 84, 163, 163, 163, 171, 171, 255, 787, 255, + 255, 255, 621, 621, 690, 690, 784, 783, 782, 781, + 780, 779, 778, 777, 773, 772, 771, 770, 769, 768, + 767, 766, 765, 764, 763, 762, 761, 758, 757, 756, + 755, 754, 753, 752, 751, 750, 749, 748, 747, 746, + 745, 744, 743, 742, 741, 740, 739, 738, 737, 736, + 735, 734, 733, 732, 731, 730, 729, 728, 727, 726, + 725, 724, 723, 722, 721, 720, 719, 718, 717, 716, + 715, 714, 713, 712, 711, 710, 709, 708, 707, 706, + + 705, 704, 703, 702, 701, 700, 699, 698, 697, 696, + 695, 694, 693, 692, 691, 689, 688, 687, 686, 685, + 684, 683, 682, 681, 680, 679, 678, 677, 676, 675, + 674, 673, 672, 671, 670, 669, 668, 667, 666, 665, + 664, 663, 662, 661, 655, 654, 653, 652, 651, 650, + 649, 648, 647, 646, 645, 644, 638, 637, 636, 635, + 634, 633, 632, 631, 630, 629, 628, 627, 626, 625, + 618, 613, 612, 611, 610, 609, 608, 607, 606, 605, + 604, 603, 602, 601, 600, 595, 594, 593, 592, 591, + 590, 589, 588, 587, 586, 585, 584, 583, 582, 581, + + 575, 574, 573, 572, 571, 570, 569, 568, 567, 566, + 560, 559, 558, 557, 556, 555, 554, 553, 552, 551, + 550, 545, 544, 543, 542, 541, 540, 539, 538, 537, + 536, 535, 532, 531, 530, 529, 528, 527, 521, 520, + 519, 518, 517, 516, 515, 514, 513, 512, 511, 510, + 509, 508, 507, 506, 505, 504, 498, 497, 496, 495, + 494, 493, 492, 491, 490, 489, 488, 487, 486, 485, + 484, 483, 482, 481, 480, 479, 478, 477, 476, 475, + 474, 473, 472, 471, 470, 469, 468, 467, 466, 465, + 464, 463, 453, 452, 451, 450, 449, 443, 442, 441, + + 440, 439, 438, 437, 436, 435, 434, 433, 432, 431, + 430, 429, 428, 427, 426, 422, 421, 420, 419, 418, + 417, 416, 415, 414, 413, 412, 411, 410, 409, 408, + 407, 406, 405, 404, 403, 402, 401, 400, 399, 398, + 397, 396, 395, 394, 393, 392, 388, 387, 386, 385, + 384, 383, 382, 381, 377, 373, 372, 371, 370, 369, + 365, 364, 363, 362, 361, 360, 359, 358, 354, 353, + 352, 349, 348, 347, 346, 345, 344, 343, 339, 338, + 337, 336, 335, 332, 331, 330, 329, 328, 327, 326, + 325, 324, 323, 322, 321, 320, 319, 318, 317, 316, + + 315, 314, 313, 312, 311, 310, 309, 308, 304, 303, + 302, 301, 300, 299, 298, 297, 296, 295, 294, 293, + 292, 291, 290, 289, 288, 287, 286, 285, 284, 283, + 282, 281, 280, 279, 278, 277, 276, 273, 272, 271, + 268, 267, 266, 265, 264, 254, 253, 252, 251, 250, + 247, 246, 245, 238, 237, 236, 235, 234, 233, 230, + 229, 228, 227, 226, 225, 224, 223, 220, 217, 216, + 215, 212, 211, 210, 204, 203, 202, 201, 200, 199, + 198, 197, 192, 191, 190, 189, 188, 187, 186, 185, + 182, 181, 180, 179, 178, 177, 176, 175, 174, 173, + + 172, 161, 149, 125, 109, 81, 69, 63, 60, 59, + 835, 57, 57, 7, 835, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 835, 835 + } ; + +static yyconst flex_int16_t yy_chk[1283] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 9, + 791, 9, 2, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 13, 15, 792, 16, 17, 17, 17, 17, 17, + 17, 17, 21, 21, 25, 15, 16, 26, 13, 19, + 35, 19, 19, 19, 19, 19, 19, 19, 23, 23, + 25, 36, 26, 26, 35, 36, 19, 19, 71, 30, + 27, 30, 27, 28, 19, 19, 27, 28, 37, 39, + 30, 758, 19, 19, 28, 143, 29, 28, 96, 96, + + 29, 33, 37, 71, 143, 39, 29, 19, 39, 33, + 19, 20, 29, 20, 20, 20, 20, 20, 20, 20, + 40, 33, 47, 31, 47, 794, 47, 46, 20, 20, + 40, 31, 48, 48, 31, 106, 20, 31, 42, 34, + 758, 42, 34, 31, 20, 20, 34, 34, 41, 106, + 42, 34, 802, 43, 34, 41, 41, 42, 43, 20, + 41, 50, 43, 50, 44, 43, 41, 41, 44, 41, + 46, 58, 105, 58, 68, 68, 135, 48, 44, 120, + 142, 142, 124, 105, 48, 70, 70, 120, 48, 124, + 68, 68, 135, 48, 53, 53, 53, 53, 53, 53, + + 53, 70, 70, 72, 144, 72, 72, 72, 72, 72, + 72, 72, 144, 148, 803, 126, 148, 804, 73, 73, + 72, 72, 73, 73, 73, 73, 73, 73, 73, 126, + 805, 116, 153, 153, 116, 116, 72, 72, 116, 152, + 116, 152, 810, 152, 154, 154, 160, 811, 160, 162, + 162, 162, 162, 162, 162, 162, 164, 164, 166, 166, + 164, 164, 164, 164, 164, 164, 164, 169, 169, 169, + 169, 169, 169, 169, 166, 166, 171, 153, 180, 184, + 184, 215, 215, 215, 153, 241, 813, 504, 153, 154, + 776, 505, 180, 153, 241, 814, 154, 504, 776, 171, + + 154, 505, 167, 167, 818, 154, 167, 167, 167, 167, + 167, 167, 167, 170, 170, 170, 170, 170, 170, 170, + 247, 247, 247, 268, 268, 268, 279, 279, 279, 170, + 256, 256, 256, 256, 256, 256, 256, 257, 257, 257, + 257, 257, 257, 257, 786, 170, 288, 288, 288, 822, + 258, 258, 786, 257, 258, 258, 258, 258, 258, 258, + 258, 260, 260, 260, 260, 260, 260, 260, 825, 257, + 261, 261, 261, 261, 261, 261, 261, 292, 292, 292, + 301, 301, 301, 338, 338, 338, 261, 350, 350, 350, + 350, 350, 350, 350, 351, 351, 351, 351, 351, 351, + + 351, 795, 261, 382, 382, 382, 393, 393, 393, 795, + 351, 394, 394, 394, 382, 382, 395, 395, 395, 443, + 443, 443, 483, 483, 483, 490, 351, 830, 605, 831, + 443, 443, 839, 483, 483, 519, 519, 519, 605, 490, + 490, 490, 490, 490, 490, 490, 519, 519, 533, 533, + 606, 621, 621, 796, 534, 534, 656, 656, 760, 606, + 606, 796, 533, 533, 533, 533, 533, 533, 534, 534, + 534, 534, 534, 534, 534, 554, 554, 554, 573, 573, + 573, 576, 576, 690, 690, 581, 533, 554, 578, 578, + 573, 775, 799, 840, 790, 576, 576, 576, 576, 576, + + 576, 576, 578, 578, 578, 578, 578, 578, 580, 580, + 806, 533, 744, 760, 759, 808, 619, 619, 806, 744, + 581, 759, 580, 580, 580, 580, 580, 580, 580, 581, + 619, 619, 619, 619, 619, 619, 787, 798, 789, 788, + 581, 620, 620, 787, 798, 809, 775, 799, 658, 658, + 828, 785, 829, 809, 619, 620, 620, 620, 620, 620, + 620, 620, 658, 658, 658, 658, 658, 658, 660, 660, + 808, 826, 815, 819, 784, 783, 782, 781, 826, 619, + 815, 819, 660, 660, 660, 660, 660, 660, 660, 820, + 823, 828, 827, 829, 832, 833, 780, 820, 823, 827, + + 779, 778, 832, 833, 836, 836, 836, 836, 836, 837, + 837, 837, 838, 838, 838, 841, 841, 842, 777, 842, + 842, 842, 843, 843, 844, 844, 774, 771, 769, 768, + 766, 763, 762, 761, 757, 756, 755, 754, 753, 752, + 751, 750, 749, 748, 747, 746, 745, 743, 742, 741, + 738, 735, 734, 733, 732, 731, 729, 728, 726, 724, + 721, 720, 719, 717, 716, 714, 713, 712, 711, 710, + 709, 708, 707, 706, 705, 704, 702, 701, 700, 699, + 698, 697, 695, 694, 693, 692, 691, 689, 688, 687, + 686, 685, 684, 683, 682, 681, 680, 679, 678, 677, + + 676, 675, 674, 673, 672, 670, 669, 668, 667, 666, + 665, 664, 663, 662, 661, 654, 652, 651, 649, 648, + 647, 646, 645, 644, 643, 642, 641, 640, 639, 638, + 637, 635, 634, 633, 632, 631, 630, 629, 627, 626, + 625, 624, 623, 622, 618, 617, 616, 615, 614, 613, + 612, 611, 610, 609, 608, 607, 601, 599, 598, 597, + 596, 592, 591, 590, 589, 588, 587, 586, 585, 584, + 575, 571, 570, 568, 567, 565, 564, 563, 562, 561, + 560, 559, 558, 557, 555, 553, 552, 551, 550, 549, + 548, 547, 546, 545, 544, 542, 541, 537, 536, 535, + + 532, 531, 529, 528, 526, 525, 524, 523, 522, 520, + 518, 517, 516, 515, 514, 513, 511, 510, 509, 508, + 507, 503, 502, 501, 500, 499, 498, 495, 494, 493, + 492, 491, 489, 488, 487, 486, 485, 484, 482, 481, + 474, 473, 470, 469, 466, 465, 464, 463, 452, 451, + 450, 448, 447, 446, 445, 444, 441, 439, 438, 437, + 435, 434, 432, 431, 430, 429, 427, 426, 421, 420, + 418, 417, 416, 415, 414, 413, 412, 411, 410, 409, + 407, 406, 405, 404, 403, 402, 401, 400, 399, 398, + 397, 396, 392, 388, 387, 386, 383, 381, 371, 369, + + 365, 364, 363, 362, 360, 358, 353, 352, 349, 348, + 347, 346, 345, 344, 339, 337, 336, 335, 334, 333, + 331, 330, 327, 326, 325, 324, 323, 322, 321, 320, + 319, 318, 317, 316, 315, 314, 313, 312, 311, 310, + 309, 308, 307, 306, 305, 302, 300, 299, 298, 297, + 296, 295, 294, 293, 291, 287, 285, 284, 283, 282, + 278, 277, 276, 275, 274, 273, 272, 271, 267, 265, + 264, 254, 253, 252, 251, 250, 249, 248, 246, 245, + 244, 243, 242, 240, 239, 238, 237, 236, 235, 234, + 233, 232, 231, 230, 229, 228, 227, 226, 225, 224, + + 223, 222, 221, 220, 219, 218, 217, 216, 214, 213, + 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, + 202, 201, 200, 199, 198, 196, 195, 194, 193, 192, + 191, 190, 189, 188, 187, 186, 185, 183, 182, 181, + 179, 178, 177, 176, 174, 159, 158, 157, 156, 149, + 147, 146, 145, 141, 140, 139, 138, 137, 136, 134, + 133, 132, 131, 130, 129, 128, 127, 125, 123, 122, + 121, 119, 118, 117, 115, 114, 112, 111, 110, 109, + 108, 107, 104, 103, 102, 101, 100, 99, 98, 97, + 95, 94, 93, 92, 91, 90, 89, 88, 87, 83, + + 79, 52, 45, 38, 32, 22, 18, 14, 12, 11, + 7, 6, 5, 835, 835, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + 835, 835 + } ; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +#line 1 "glsl_lexer.lpp" +#line 2 "glsl_lexer.lpp" +/* + * Copyright © 2008, 2009 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#include +#include "strtod.h" +#include "ast.h" +#include "glsl_parser_extras.h" +#include "glsl_parser.h" + +static int classify_identifier(struct _mesa_glsl_parse_state *, const char *); + +#define YY_USER_ACTION \ + do { \ + yylloc->source = 0; \ + yylloc->first_column = yycolumn + 1; \ + yylloc->first_line = yylineno + 1; \ + yycolumn += yyleng; \ + } while(0); + +#define YY_USER_INIT yylineno = 0; yycolumn = 0; + +#define IS_UINT (yytext[yyleng - 1] == 'u' || yytext[yyleng - 1] == 'U') + +/* A macro for handling reserved words and keywords across language versions. + * + * Certain words start out as identifiers, become reserved words in + * later language revisions, and finally become language keywords. + * + * For example, consider the following lexer rule: + * samplerBuffer KEYWORD(130, 140, SAMPLERBUFFER) + * + * This means that "samplerBuffer" will be treated as: + * - a keyword (SAMPLERBUFFER token) ...in GLSL >= 1.40 + * - a reserved word - error ...in GLSL >= 1.30 + * - an identifier ...in GLSL < 1.30 + */ +#define KEYWORD(reserved_version, allowed_version, token) \ + do { \ + if (yyextra->language_version >= allowed_version) { \ + return token; \ + } else if (yyextra->language_version >= reserved_version) { \ + _mesa_glsl_error(yylloc, yyextra, \ + "Illegal use of reserved word `%s'", yytext); \ + return ERROR_TOK; \ + } else { \ + yylval->identifier = strdup(yytext); \ + return classify_identifier(yyextra, yytext); \ + } \ + } while (0) + +/* The ES macro can be used in KEYWORD checks: + * + * word KEYWORD(110 || ES, 400, TOKEN) + * ...means the word is reserved in GLSL ES 1.00, while + * + * word KEYWORD(110, 130 || ES, TOKEN) + * ...means the word is a legal keyword in GLSL ES 1.00. + */ +#define ES yyextra->es_shader + +#line 1073 "glsl_lexer.cpp" + +#define INITIAL 0 +#define PP 1 +#define PRAGMA 2 + +#define YY_EXTRA_TYPE struct _mesa_glsl_parse_state * + +/* Holds the entire state of the reentrant scanner. */ +struct yyguts_t + { + + /* User-defined. Not touched by flex. */ + YY_EXTRA_TYPE yyextra_r; + + /* The rest are the same as the globals declared in the non-reentrant scanner. */ + FILE *yyin_r, *yyout_r; + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ + char yy_hold_char; + int yy_n_chars; + int yyleng_r; + char *yy_c_buf_p; + int yy_init; + int yy_start; + int yy_did_buffer_switch_on_eof; + int yy_start_stack_ptr; + int yy_start_stack_depth; + int *yy_start_stack; + yy_state_type yy_last_accepting_state; + char* yy_last_accepting_cpos; + + int yylineno_r; + int yy_flex_debug_r; + + char *yytext_r; + int yy_more_flag; + int yy_more_len; + + YYSTYPE * yylval_r; + + YYLTYPE * yylloc_r; + + }; /* end struct yyguts_t */ + +static int yy_init_globals (yyscan_t yyscanner ); + + /* This must go here because YYSTYPE and YYLTYPE are included + * from bison output in section 1.*/ + # define yylval yyg->yylval_r + + # define yylloc yyg->yylloc_r + +int _mesa_glsl_lex_init (yyscan_t* scanner); + +int _mesa_glsl_lex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int _mesa_glsl_lex_destroy (yyscan_t yyscanner ); + +int _mesa_glsl_get_debug (yyscan_t yyscanner ); + +void _mesa_glsl_set_debug (int debug_flag ,yyscan_t yyscanner ); + +YY_EXTRA_TYPE _mesa_glsl_get_extra (yyscan_t yyscanner ); + +void _mesa_glsl_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); + +FILE *_mesa_glsl_get_in (yyscan_t yyscanner ); + +void _mesa_glsl_set_in (FILE * in_str ,yyscan_t yyscanner ); + +FILE *_mesa_glsl_get_out (yyscan_t yyscanner ); + +void _mesa_glsl_set_out (FILE * out_str ,yyscan_t yyscanner ); + +int _mesa_glsl_get_leng (yyscan_t yyscanner ); + +char *_mesa_glsl_get_text (yyscan_t yyscanner ); + +int _mesa_glsl_get_lineno (yyscan_t yyscanner ); + +void _mesa_glsl_set_lineno (int line_number ,yyscan_t yyscanner ); + +int _mesa_glsl_get_column (yyscan_t yyscanner ); + +void _mesa_glsl_set_column (int column_no ,yyscan_t yyscanner ); + +YYSTYPE * _mesa_glsl_get_lval (yyscan_t yyscanner ); + +void _mesa_glsl_set_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner ); + + YYLTYPE *_mesa_glsl_get_lloc (yyscan_t yyscanner ); + + void _mesa_glsl_set_lloc (YYLTYPE * yylloc_param ,yyscan_t yyscanner ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int _mesa_glsl_wrap (yyscan_t yyscanner ); +#else +extern int _mesa_glsl_wrap (yyscan_t yyscanner ); +#endif +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (yyscan_t yyscanner ); +#else +static int input (yyscan_t yyscanner ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + unsigned n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int _mesa_glsl_lex \ + (YYSTYPE * yylval_param,YYLTYPE * yylloc_param ,yyscan_t yyscanner); + +#define YY_DECL int _mesa_glsl_lex \ + (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + if ( yyleng > 0 ) \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \ + (yytext[yyleng - 1] == '\n'); \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + +#line 97 "glsl_lexer.lpp" + + +#line 1314 "glsl_lexer.cpp" + + yylval = yylval_param; + + yylloc = yylloc_param; + + if ( !yyg->yy_init ) + { + yyg->yy_init = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! yyg->yy_start ) + yyg->yy_start = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + _mesa_glsl_ensure_buffer_stack (yyscanner); + YY_CURRENT_BUFFER_LVALUE = + _mesa_glsl__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); + } + + _mesa_glsl__load_buffer_state(yyscanner ); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = yyg->yy_c_buf_p; + + /* Support of yytext. */ + *yy_cp = yyg->yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = yyg->yy_start; + yy_current_state += YY_AT_BOL(); +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 836 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_current_state != 835 ); + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yyg->yy_hold_char; + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 99 "glsl_lexer.lpp" +; + YY_BREAK +/* Preprocessor tokens. */ +case 2: +*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */ +yyg->yy_c_buf_p = yy_cp -= 1; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 102 "glsl_lexer.lpp" +; + YY_BREAK +case 3: +YY_RULE_SETUP +#line 103 "glsl_lexer.lpp" +{ BEGIN PP; return VERSION; } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 104 "glsl_lexer.lpp" +{ BEGIN PP; return EXTENSION; } + YY_BREAK +case 5: +*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */ +yyg->yy_c_buf_p = yy_cp -= 1; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 105 "glsl_lexer.lpp" +{ + /* Eat characters until the first digit is + * encountered + */ + char *ptr = yytext; + while (!isdigit(*ptr)) + ptr++; + + /* Subtract one from the line number because + * yylineno is zero-based instead of + * one-based. + */ + yylineno = strtol(ptr, &ptr, 0) - 1; + yylloc->source = strtol(ptr, NULL, 0); + } + YY_BREAK +case 6: +*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */ +yyg->yy_c_buf_p = yy_cp -= 1; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 120 "glsl_lexer.lpp" +{ + /* Eat characters until the first digit is + * encountered + */ + char *ptr = yytext; + while (!isdigit(*ptr)) + ptr++; + + /* Subtract one from the line number because + * yylineno is zero-based instead of + * one-based. + */ + yylineno = strtol(ptr, &ptr, 0) - 1; + } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 134 "glsl_lexer.lpp" +{ + BEGIN PP; + return PRAGMA_DEBUG_ON; + } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 138 "glsl_lexer.lpp" +{ + BEGIN PP; + return PRAGMA_DEBUG_OFF; + } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 142 "glsl_lexer.lpp" +{ + BEGIN PP; + return PRAGMA_OPTIMIZE_ON; + } + YY_BREAK +case 10: +YY_RULE_SETUP +#line 146 "glsl_lexer.lpp" +{ + BEGIN PP; + return PRAGMA_OPTIMIZE_OFF; + } + YY_BREAK +case 11: +YY_RULE_SETUP +#line 150 "glsl_lexer.lpp" +{ + BEGIN PP; + return PRAGMA_INVARIANT_ALL; + } + YY_BREAK +case 12: +YY_RULE_SETUP +#line 154 "glsl_lexer.lpp" +{ BEGIN PRAGMA; } + YY_BREAK +case 13: +/* rule 13 can match eol */ +YY_RULE_SETUP +#line 156 "glsl_lexer.lpp" +{ BEGIN 0; yylineno++; yycolumn = 0; } + YY_BREAK +case 14: +YY_RULE_SETUP +#line 157 "glsl_lexer.lpp" +{ } + YY_BREAK +case 15: +YY_RULE_SETUP +#line 159 "glsl_lexer.lpp" +{ } + YY_BREAK +case 16: +YY_RULE_SETUP +#line 160 "glsl_lexer.lpp" +{ } + YY_BREAK +case 17: +YY_RULE_SETUP +#line 161 "glsl_lexer.lpp" +return COLON; + YY_BREAK +case 18: +YY_RULE_SETUP +#line 162 "glsl_lexer.lpp" +{ + yylval->identifier = strdup(yytext); + return IDENTIFIER; + } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 166 "glsl_lexer.lpp" +{ + yylval->n = strtol(yytext, NULL, 10); + return INTCONSTANT; + } + YY_BREAK +case 20: +/* rule 20 can match eol */ +YY_RULE_SETUP +#line 170 "glsl_lexer.lpp" +{ BEGIN 0; yylineno++; yycolumn = 0; return EOL; } + YY_BREAK +case 21: +/* rule 21 can match eol */ +YY_RULE_SETUP +#line 172 "glsl_lexer.lpp" +{ yylineno++; yycolumn = 0; } + YY_BREAK +case 22: +YY_RULE_SETUP +#line 174 "glsl_lexer.lpp" +return ATTRIBUTE; + YY_BREAK +case 23: +YY_RULE_SETUP +#line 175 "glsl_lexer.lpp" +return CONST_TOK; + YY_BREAK +case 24: +YY_RULE_SETUP +#line 176 "glsl_lexer.lpp" +return BOOL_TOK; + YY_BREAK +case 25: +YY_RULE_SETUP +#line 177 "glsl_lexer.lpp" +return FLOAT_TOK; + YY_BREAK +case 26: +YY_RULE_SETUP +#line 178 "glsl_lexer.lpp" +return INT_TOK; + YY_BREAK +case 27: +YY_RULE_SETUP +#line 179 "glsl_lexer.lpp" +KEYWORD(130, 130, UINT_TOK); + YY_BREAK +case 28: +YY_RULE_SETUP +#line 181 "glsl_lexer.lpp" +return BREAK; + YY_BREAK +case 29: +YY_RULE_SETUP +#line 182 "glsl_lexer.lpp" +return CONTINUE; + YY_BREAK +case 30: +YY_RULE_SETUP +#line 183 "glsl_lexer.lpp" +return DO; + YY_BREAK +case 31: +YY_RULE_SETUP +#line 184 "glsl_lexer.lpp" +return WHILE; + YY_BREAK +case 32: +YY_RULE_SETUP +#line 185 "glsl_lexer.lpp" +return ELSE; + YY_BREAK +case 33: +YY_RULE_SETUP +#line 186 "glsl_lexer.lpp" +return FOR; + YY_BREAK +case 34: +YY_RULE_SETUP +#line 187 "glsl_lexer.lpp" +return IF; + YY_BREAK +case 35: +YY_RULE_SETUP +#line 188 "glsl_lexer.lpp" +return DISCARD; + YY_BREAK +case 36: +YY_RULE_SETUP +#line 189 "glsl_lexer.lpp" +return RETURN; + YY_BREAK +case 37: +YY_RULE_SETUP +#line 191 "glsl_lexer.lpp" +return BVEC2; + YY_BREAK +case 38: +YY_RULE_SETUP +#line 192 "glsl_lexer.lpp" +return BVEC3; + YY_BREAK +case 39: +YY_RULE_SETUP +#line 193 "glsl_lexer.lpp" +return BVEC4; + YY_BREAK +case 40: +YY_RULE_SETUP +#line 194 "glsl_lexer.lpp" +return IVEC2; + YY_BREAK +case 41: +YY_RULE_SETUP +#line 195 "glsl_lexer.lpp" +return IVEC3; + YY_BREAK +case 42: +YY_RULE_SETUP +#line 196 "glsl_lexer.lpp" +return IVEC4; + YY_BREAK +case 43: +YY_RULE_SETUP +#line 197 "glsl_lexer.lpp" +KEYWORD(130, 130, UVEC2); + YY_BREAK +case 44: +YY_RULE_SETUP +#line 198 "glsl_lexer.lpp" +KEYWORD(130, 130, UVEC3); + YY_BREAK +case 45: +YY_RULE_SETUP +#line 199 "glsl_lexer.lpp" +KEYWORD(130, 130, UVEC4); + YY_BREAK +case 46: +YY_RULE_SETUP +#line 200 "glsl_lexer.lpp" +return VEC2; + YY_BREAK +case 47: +YY_RULE_SETUP +#line 201 "glsl_lexer.lpp" +return VEC3; + YY_BREAK +case 48: +YY_RULE_SETUP +#line 202 "glsl_lexer.lpp" +return VEC4; + YY_BREAK +case 49: +YY_RULE_SETUP +#line 203 "glsl_lexer.lpp" +return MAT2X2; + YY_BREAK +case 50: +YY_RULE_SETUP +#line 204 "glsl_lexer.lpp" +return MAT3X3; + YY_BREAK +case 51: +YY_RULE_SETUP +#line 205 "glsl_lexer.lpp" +return MAT4X4; + YY_BREAK +case 52: +YY_RULE_SETUP +#line 206 "glsl_lexer.lpp" +KEYWORD(120, 120, MAT2X2); + YY_BREAK +case 53: +YY_RULE_SETUP +#line 207 "glsl_lexer.lpp" +KEYWORD(120, 120, MAT2X3); + YY_BREAK +case 54: +YY_RULE_SETUP +#line 208 "glsl_lexer.lpp" +KEYWORD(120, 120, MAT2X4); + YY_BREAK +case 55: +YY_RULE_SETUP +#line 209 "glsl_lexer.lpp" +KEYWORD(120, 120, MAT3X2); + YY_BREAK +case 56: +YY_RULE_SETUP +#line 210 "glsl_lexer.lpp" +KEYWORD(120, 120, MAT3X3); + YY_BREAK +case 57: +YY_RULE_SETUP +#line 211 "glsl_lexer.lpp" +KEYWORD(120, 120, MAT3X4); + YY_BREAK +case 58: +YY_RULE_SETUP +#line 212 "glsl_lexer.lpp" +KEYWORD(120, 120, MAT4X2); + YY_BREAK +case 59: +YY_RULE_SETUP +#line 213 "glsl_lexer.lpp" +KEYWORD(120, 120, MAT4X3); + YY_BREAK +case 60: +YY_RULE_SETUP +#line 214 "glsl_lexer.lpp" +KEYWORD(120, 120, MAT4X4); + YY_BREAK +case 61: +YY_RULE_SETUP +#line 216 "glsl_lexer.lpp" +return IN_TOK; + YY_BREAK +case 62: +YY_RULE_SETUP +#line 217 "glsl_lexer.lpp" +return OUT_TOK; + YY_BREAK +case 63: +YY_RULE_SETUP +#line 218 "glsl_lexer.lpp" +return INOUT_TOK; + YY_BREAK +case 64: +YY_RULE_SETUP +#line 219 "glsl_lexer.lpp" +return UNIFORM; + YY_BREAK +case 65: +YY_RULE_SETUP +#line 220 "glsl_lexer.lpp" +return VARYING; + YY_BREAK +case 66: +YY_RULE_SETUP +#line 221 "glsl_lexer.lpp" +KEYWORD(120, 120, CENTROID); + YY_BREAK +case 67: +YY_RULE_SETUP +#line 222 "glsl_lexer.lpp" +KEYWORD(120 || ES, 120 || ES, INVARIANT); + YY_BREAK +case 68: +YY_RULE_SETUP +#line 223 "glsl_lexer.lpp" +KEYWORD(130 || ES, 130, FLAT); + YY_BREAK +case 69: +YY_RULE_SETUP +#line 224 "glsl_lexer.lpp" +KEYWORD(130, 130, SMOOTH); + YY_BREAK +case 70: +YY_RULE_SETUP +#line 225 "glsl_lexer.lpp" +KEYWORD(130, 130, NOPERSPECTIVE); + YY_BREAK +case 71: +YY_RULE_SETUP +#line 227 "glsl_lexer.lpp" +return SAMPLER1D; + YY_BREAK +case 72: +YY_RULE_SETUP +#line 228 "glsl_lexer.lpp" +return SAMPLER2D; + YY_BREAK +case 73: +YY_RULE_SETUP +#line 229 "glsl_lexer.lpp" +return SAMPLER3D; + YY_BREAK +case 74: +YY_RULE_SETUP +#line 230 "glsl_lexer.lpp" +return SAMPLERCUBE; + YY_BREAK +case 75: +YY_RULE_SETUP +#line 231 "glsl_lexer.lpp" +KEYWORD(130, 130, SAMPLER1DARRAY); + YY_BREAK +case 76: +YY_RULE_SETUP +#line 232 "glsl_lexer.lpp" +KEYWORD(130, 130, SAMPLER2DARRAY); + YY_BREAK +case 77: +YY_RULE_SETUP +#line 233 "glsl_lexer.lpp" +return SAMPLER1DSHADOW; + YY_BREAK +case 78: +YY_RULE_SETUP +#line 234 "glsl_lexer.lpp" +return SAMPLER2DSHADOW; + YY_BREAK +case 79: +YY_RULE_SETUP +#line 235 "glsl_lexer.lpp" +KEYWORD(130, 130, SAMPLERCUBESHADOW); + YY_BREAK +case 80: +YY_RULE_SETUP +#line 236 "glsl_lexer.lpp" +KEYWORD(130, 130, SAMPLER1DARRAYSHADOW); + YY_BREAK +case 81: +YY_RULE_SETUP +#line 237 "glsl_lexer.lpp" +KEYWORD(130, 130, SAMPLER2DARRAYSHADOW); + YY_BREAK +case 82: +YY_RULE_SETUP +#line 238 "glsl_lexer.lpp" +KEYWORD(130, 130, ISAMPLER1D); + YY_BREAK +case 83: +YY_RULE_SETUP +#line 239 "glsl_lexer.lpp" +KEYWORD(130, 130, ISAMPLER2D); + YY_BREAK +case 84: +YY_RULE_SETUP +#line 240 "glsl_lexer.lpp" +KEYWORD(130, 130, ISAMPLER3D); + YY_BREAK +case 85: +YY_RULE_SETUP +#line 241 "glsl_lexer.lpp" +KEYWORD(130, 130, ISAMPLERCUBE); + YY_BREAK +case 86: +YY_RULE_SETUP +#line 242 "glsl_lexer.lpp" +KEYWORD(130, 130, ISAMPLER1DARRAY); + YY_BREAK +case 87: +YY_RULE_SETUP +#line 243 "glsl_lexer.lpp" +KEYWORD(130, 130, ISAMPLER2DARRAY); + YY_BREAK +case 88: +YY_RULE_SETUP +#line 244 "glsl_lexer.lpp" +KEYWORD(130, 130, USAMPLER1D); + YY_BREAK +case 89: +YY_RULE_SETUP +#line 245 "glsl_lexer.lpp" +KEYWORD(130, 130, USAMPLER2D); + YY_BREAK +case 90: +YY_RULE_SETUP +#line 246 "glsl_lexer.lpp" +KEYWORD(130, 130, USAMPLER3D); + YY_BREAK +case 91: +YY_RULE_SETUP +#line 247 "glsl_lexer.lpp" +KEYWORD(130, 130, USAMPLERCUBE); + YY_BREAK +case 92: +YY_RULE_SETUP +#line 248 "glsl_lexer.lpp" +KEYWORD(130, 130, USAMPLER1DARRAY); + YY_BREAK +case 93: +YY_RULE_SETUP +#line 249 "glsl_lexer.lpp" +KEYWORD(130, 130, USAMPLER2DARRAY); + YY_BREAK +case 94: +YY_RULE_SETUP +#line 252 "glsl_lexer.lpp" +return STRUCT; + YY_BREAK +case 95: +YY_RULE_SETUP +#line 253 "glsl_lexer.lpp" +return VOID_TOK; + YY_BREAK +case 96: +YY_RULE_SETUP +#line 255 "glsl_lexer.lpp" +{ + if ((yyextra->language_version >= 140) + || yyextra->ARB_explicit_attrib_location_enable + || (yyextra->ARB_fragment_coord_conventions_enable)){ + return LAYOUT_TOK; + } else { + yylval->identifier = strdup(yytext); + return IDENTIFIER; + } + } + YY_BREAK +case 97: +YY_RULE_SETUP +#line 266 "glsl_lexer.lpp" +return INC_OP; + YY_BREAK +case 98: +YY_RULE_SETUP +#line 267 "glsl_lexer.lpp" +return DEC_OP; + YY_BREAK +case 99: +YY_RULE_SETUP +#line 268 "glsl_lexer.lpp" +return LE_OP; + YY_BREAK +case 100: +YY_RULE_SETUP +#line 269 "glsl_lexer.lpp" +return GE_OP; + YY_BREAK +case 101: +YY_RULE_SETUP +#line 270 "glsl_lexer.lpp" +return EQ_OP; + YY_BREAK +case 102: +YY_RULE_SETUP +#line 271 "glsl_lexer.lpp" +return NE_OP; + YY_BREAK +case 103: +YY_RULE_SETUP +#line 272 "glsl_lexer.lpp" +return AND_OP; + YY_BREAK +case 104: +YY_RULE_SETUP +#line 273 "glsl_lexer.lpp" +return OR_OP; + YY_BREAK +case 105: +YY_RULE_SETUP +#line 274 "glsl_lexer.lpp" +return XOR_OP; + YY_BREAK +case 106: +YY_RULE_SETUP +#line 275 "glsl_lexer.lpp" +return LEFT_OP; + YY_BREAK +case 107: +YY_RULE_SETUP +#line 276 "glsl_lexer.lpp" +return RIGHT_OP; + YY_BREAK +case 108: +YY_RULE_SETUP +#line 278 "glsl_lexer.lpp" +return MUL_ASSIGN; + YY_BREAK +case 109: +YY_RULE_SETUP +#line 279 "glsl_lexer.lpp" +return DIV_ASSIGN; + YY_BREAK +case 110: +YY_RULE_SETUP +#line 280 "glsl_lexer.lpp" +return ADD_ASSIGN; + YY_BREAK +case 111: +YY_RULE_SETUP +#line 281 "glsl_lexer.lpp" +return MOD_ASSIGN; + YY_BREAK +case 112: +YY_RULE_SETUP +#line 282 "glsl_lexer.lpp" +return LEFT_ASSIGN; + YY_BREAK +case 113: +YY_RULE_SETUP +#line 283 "glsl_lexer.lpp" +return RIGHT_ASSIGN; + YY_BREAK +case 114: +YY_RULE_SETUP +#line 284 "glsl_lexer.lpp" +return AND_ASSIGN; + YY_BREAK +case 115: +YY_RULE_SETUP +#line 285 "glsl_lexer.lpp" +return XOR_ASSIGN; + YY_BREAK +case 116: +YY_RULE_SETUP +#line 286 "glsl_lexer.lpp" +return OR_ASSIGN; + YY_BREAK +case 117: +YY_RULE_SETUP +#line 287 "glsl_lexer.lpp" +return SUB_ASSIGN; + YY_BREAK +case 118: +YY_RULE_SETUP +#line 289 "glsl_lexer.lpp" +{ + yylval->n = strtol(yytext, NULL, 10); + return IS_UINT ? UINTCONSTANT : INTCONSTANT; + } + YY_BREAK +case 119: +YY_RULE_SETUP +#line 293 "glsl_lexer.lpp" +{ + yylval->n = strtol(yytext + 2, NULL, 16); + return IS_UINT ? UINTCONSTANT : INTCONSTANT; + } + YY_BREAK +case 120: +YY_RULE_SETUP +#line 297 "glsl_lexer.lpp" +{ + yylval->n = strtol(yytext, NULL, 8); + return IS_UINT ? UINTCONSTANT : INTCONSTANT; + } + YY_BREAK +case 121: +YY_RULE_SETUP +#line 302 "glsl_lexer.lpp" +{ + yylval->real = glsl_strtod(yytext, NULL); + return FLOATCONSTANT; + } + YY_BREAK +case 122: +YY_RULE_SETUP +#line 306 "glsl_lexer.lpp" +{ + yylval->real = glsl_strtod(yytext, NULL); + return FLOATCONSTANT; + } + YY_BREAK +case 123: +YY_RULE_SETUP +#line 310 "glsl_lexer.lpp" +{ + yylval->real = glsl_strtod(yytext, NULL); + return FLOATCONSTANT; + } + YY_BREAK +case 124: +YY_RULE_SETUP +#line 314 "glsl_lexer.lpp" +{ + yylval->real = glsl_strtod(yytext, NULL); + return FLOATCONSTANT; + } + YY_BREAK +case 125: +YY_RULE_SETUP +#line 318 "glsl_lexer.lpp" +{ + yylval->real = glsl_strtod(yytext, NULL); + return FLOATCONSTANT; + } + YY_BREAK +case 126: +YY_RULE_SETUP +#line 323 "glsl_lexer.lpp" +{ + yylval->n = 1; + return BOOLCONSTANT; + } + YY_BREAK +case 127: +YY_RULE_SETUP +#line 327 "glsl_lexer.lpp" +{ + yylval->n = 0; + return BOOLCONSTANT; + } + YY_BREAK +/* Reserved words in GLSL 1.10. */ +case 128: +YY_RULE_SETUP +#line 334 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, ASM); + YY_BREAK +case 129: +YY_RULE_SETUP +#line 335 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, CLASS); + YY_BREAK +case 130: +YY_RULE_SETUP +#line 336 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, UNION); + YY_BREAK +case 131: +YY_RULE_SETUP +#line 337 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, ENUM); + YY_BREAK +case 132: +YY_RULE_SETUP +#line 338 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, TYPEDEF); + YY_BREAK +case 133: +YY_RULE_SETUP +#line 339 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, TEMPLATE); + YY_BREAK +case 134: +YY_RULE_SETUP +#line 340 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, THIS); + YY_BREAK +case 135: +YY_RULE_SETUP +#line 341 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, PACKED_TOK); + YY_BREAK +case 136: +YY_RULE_SETUP +#line 342 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, GOTO); + YY_BREAK +case 137: +YY_RULE_SETUP +#line 343 "glsl_lexer.lpp" +KEYWORD(110 || ES, 130, SWITCH); + YY_BREAK +case 138: +YY_RULE_SETUP +#line 344 "glsl_lexer.lpp" +KEYWORD(110 || ES, 130, DEFAULT); + YY_BREAK +case 139: +YY_RULE_SETUP +#line 345 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, INLINE_TOK); + YY_BREAK +case 140: +YY_RULE_SETUP +#line 346 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, NOINLINE); + YY_BREAK +case 141: +YY_RULE_SETUP +#line 347 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, VOLATILE); + YY_BREAK +case 142: +YY_RULE_SETUP +#line 348 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, PUBLIC_TOK); + YY_BREAK +case 143: +YY_RULE_SETUP +#line 349 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, STATIC); + YY_BREAK +case 144: +YY_RULE_SETUP +#line 350 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, EXTERN); + YY_BREAK +case 145: +YY_RULE_SETUP +#line 351 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, EXTERNAL); + YY_BREAK +case 146: +YY_RULE_SETUP +#line 352 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, INTERFACE); + YY_BREAK +case 147: +YY_RULE_SETUP +#line 353 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, LONG_TOK); + YY_BREAK +case 148: +YY_RULE_SETUP +#line 354 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, SHORT_TOK); + YY_BREAK +case 149: +YY_RULE_SETUP +#line 355 "glsl_lexer.lpp" +KEYWORD(110 || ES, 400, DOUBLE_TOK); + YY_BREAK +case 150: +YY_RULE_SETUP +#line 356 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, HALF); + YY_BREAK +case 151: +YY_RULE_SETUP +#line 357 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, FIXED_TOK); + YY_BREAK +case 152: +YY_RULE_SETUP +#line 358 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, UNSIGNED); + YY_BREAK +case 153: +YY_RULE_SETUP +#line 359 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, INPUT_TOK); + YY_BREAK +case 154: +YY_RULE_SETUP +#line 360 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, OUTPUT); + YY_BREAK +case 155: +YY_RULE_SETUP +#line 361 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, HVEC2); + YY_BREAK +case 156: +YY_RULE_SETUP +#line 362 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, HVEC3); + YY_BREAK +case 157: +YY_RULE_SETUP +#line 363 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, HVEC4); + YY_BREAK +case 158: +YY_RULE_SETUP +#line 364 "glsl_lexer.lpp" +KEYWORD(110 || ES, 400, DVEC2); + YY_BREAK +case 159: +YY_RULE_SETUP +#line 365 "glsl_lexer.lpp" +KEYWORD(110 || ES, 400, DVEC3); + YY_BREAK +case 160: +YY_RULE_SETUP +#line 366 "glsl_lexer.lpp" +KEYWORD(110 || ES, 400, DVEC4); + YY_BREAK +case 161: +YY_RULE_SETUP +#line 367 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, FVEC2); + YY_BREAK +case 162: +YY_RULE_SETUP +#line 368 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, FVEC3); + YY_BREAK +case 163: +YY_RULE_SETUP +#line 369 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, FVEC4); + YY_BREAK +case 164: +YY_RULE_SETUP +#line 370 "glsl_lexer.lpp" +return SAMPLER2DRECT; + YY_BREAK +case 165: +YY_RULE_SETUP +#line 371 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, SAMPLER3DRECT); + YY_BREAK +case 166: +YY_RULE_SETUP +#line 372 "glsl_lexer.lpp" +return SAMPLER2DRECTSHADOW; + YY_BREAK +case 167: +YY_RULE_SETUP +#line 373 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, SIZEOF); + YY_BREAK +case 168: +YY_RULE_SETUP +#line 374 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, CAST); + YY_BREAK +case 169: +YY_RULE_SETUP +#line 375 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, NAMESPACE); + YY_BREAK +case 170: +YY_RULE_SETUP +#line 376 "glsl_lexer.lpp" +KEYWORD(110 || ES, 999, USING); + YY_BREAK +/* Additional reserved words in GLSL 1.20. */ +case 171: +YY_RULE_SETUP +#line 379 "glsl_lexer.lpp" +KEYWORD(120, 130 || ES, LOWP); + YY_BREAK +case 172: +YY_RULE_SETUP +#line 380 "glsl_lexer.lpp" +KEYWORD(120, 130 || ES, MEDIUMP); + YY_BREAK +case 173: +YY_RULE_SETUP +#line 381 "glsl_lexer.lpp" +KEYWORD(120, 130 || ES, HIGHP); + YY_BREAK +case 174: +YY_RULE_SETUP +#line 382 "glsl_lexer.lpp" +KEYWORD(120, 130 || ES, PRECISION); + YY_BREAK +/* Additional reserved words in GLSL 1.30. */ +case 175: +YY_RULE_SETUP +#line 385 "glsl_lexer.lpp" +KEYWORD(130, 130, CASE); + YY_BREAK +case 176: +YY_RULE_SETUP +#line 386 "glsl_lexer.lpp" +KEYWORD(130, 999, COMMON); + YY_BREAK +case 177: +YY_RULE_SETUP +#line 387 "glsl_lexer.lpp" +KEYWORD(130, 999, PARTITION); + YY_BREAK +case 178: +YY_RULE_SETUP +#line 388 "glsl_lexer.lpp" +KEYWORD(130, 999, ACTIVE); + YY_BREAK +case 179: +YY_RULE_SETUP +#line 389 "glsl_lexer.lpp" +KEYWORD(130 || ES, 999, SUPERP); + YY_BREAK +case 180: +YY_RULE_SETUP +#line 390 "glsl_lexer.lpp" +KEYWORD(130, 140, SAMPLERBUFFER); + YY_BREAK +case 181: +YY_RULE_SETUP +#line 391 "glsl_lexer.lpp" +KEYWORD(130, 999, FILTER); + YY_BREAK +case 182: +YY_RULE_SETUP +#line 392 "glsl_lexer.lpp" +KEYWORD(130, 999, IMAGE1D); + YY_BREAK +case 183: +YY_RULE_SETUP +#line 393 "glsl_lexer.lpp" +KEYWORD(130, 999, IMAGE2D); + YY_BREAK +case 184: +YY_RULE_SETUP +#line 394 "glsl_lexer.lpp" +KEYWORD(130, 999, IMAGE3D); + YY_BREAK +case 185: +YY_RULE_SETUP +#line 395 "glsl_lexer.lpp" +KEYWORD(130, 999, IMAGECUBE); + YY_BREAK +case 186: +YY_RULE_SETUP +#line 396 "glsl_lexer.lpp" +KEYWORD(130, 999, IIMAGE1D); + YY_BREAK +case 187: +YY_RULE_SETUP +#line 397 "glsl_lexer.lpp" +KEYWORD(130, 999, IIMAGE2D); + YY_BREAK +case 188: +YY_RULE_SETUP +#line 398 "glsl_lexer.lpp" +KEYWORD(130, 999, IIMAGE3D); + YY_BREAK +case 189: +YY_RULE_SETUP +#line 399 "glsl_lexer.lpp" +KEYWORD(130, 999, IIMAGECUBE); + YY_BREAK +case 190: +YY_RULE_SETUP +#line 400 "glsl_lexer.lpp" +KEYWORD(130, 999, UIMAGE1D); + YY_BREAK +case 191: +YY_RULE_SETUP +#line 401 "glsl_lexer.lpp" +KEYWORD(130, 999, UIMAGE2D); + YY_BREAK +case 192: +YY_RULE_SETUP +#line 402 "glsl_lexer.lpp" +KEYWORD(130, 999, UIMAGE3D); + YY_BREAK +case 193: +YY_RULE_SETUP +#line 403 "glsl_lexer.lpp" +KEYWORD(130, 999, UIMAGECUBE); + YY_BREAK +case 194: +YY_RULE_SETUP +#line 404 "glsl_lexer.lpp" +KEYWORD(130, 999, IMAGE1DARRAY); + YY_BREAK +case 195: +YY_RULE_SETUP +#line 405 "glsl_lexer.lpp" +KEYWORD(130, 999, IMAGE2DARRAY); + YY_BREAK +case 196: +YY_RULE_SETUP +#line 406 "glsl_lexer.lpp" +KEYWORD(130, 999, IIMAGE1DARRAY); + YY_BREAK +case 197: +YY_RULE_SETUP +#line 407 "glsl_lexer.lpp" +KEYWORD(130, 999, IIMAGE2DARRAY); + YY_BREAK +case 198: +YY_RULE_SETUP +#line 408 "glsl_lexer.lpp" +KEYWORD(130, 999, UIMAGE1DARRAY); + YY_BREAK +case 199: +YY_RULE_SETUP +#line 409 "glsl_lexer.lpp" +KEYWORD(130, 999, UIMAGE2DARRAY); + YY_BREAK +case 200: +YY_RULE_SETUP +#line 410 "glsl_lexer.lpp" +KEYWORD(130, 999, IMAGE1DSHADOW); + YY_BREAK +case 201: +YY_RULE_SETUP +#line 411 "glsl_lexer.lpp" +KEYWORD(130, 999, IMAGE2DSHADOW); + YY_BREAK +case 202: +YY_RULE_SETUP +#line 412 "glsl_lexer.lpp" +KEYWORD(130, 999, IMAGE1DARRAYSHADOW); + YY_BREAK +case 203: +YY_RULE_SETUP +#line 413 "glsl_lexer.lpp" +KEYWORD(130, 999, IMAGE2DARRAYSHADOW); + YY_BREAK +case 204: +YY_RULE_SETUP +#line 414 "glsl_lexer.lpp" +KEYWORD(130, 999, IMAGEBUFFER); + YY_BREAK +case 205: +YY_RULE_SETUP +#line 415 "glsl_lexer.lpp" +KEYWORD(130, 999, IIMAGEBUFFER); + YY_BREAK +case 206: +YY_RULE_SETUP +#line 416 "glsl_lexer.lpp" +KEYWORD(130, 999, UIMAGEBUFFER); + YY_BREAK +case 207: +YY_RULE_SETUP +#line 417 "glsl_lexer.lpp" +KEYWORD(130, 999, ROW_MAJOR); + YY_BREAK +case 208: +YY_RULE_SETUP +#line 419 "glsl_lexer.lpp" +{ + struct _mesa_glsl_parse_state *state = yyextra; + void *ctx = state; + yylval->identifier = ralloc_strdup(ctx, yytext); + return classify_identifier(state, yytext); + } + YY_BREAK +case 209: +YY_RULE_SETUP +#line 426 "glsl_lexer.lpp" +{ return yytext[0]; } + YY_BREAK +case 210: +YY_RULE_SETUP +#line 428 "glsl_lexer.lpp" +ECHO; + YY_BREAK +#line 2556 "glsl_lexer.cpp" +case YY_STATE_EOF(INITIAL): +case YY_STATE_EOF(PP): +case YY_STATE_EOF(PRAGMA): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = yyg->yy_hold_char; + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * _mesa_glsl_lex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( yyscanner ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); + + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++yyg->yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( yyscanner ) ) + { + case EOB_ACT_END_OF_FILE: + { + yyg->yy_did_buffer_switch_on_eof = 0; + + if ( _mesa_glsl_wrap(yyscanner ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! yyg->yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + yyg->yy_c_buf_p = + yyg->yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( yyscanner ); + + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yyg->yy_c_buf_p = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; + + yy_current_state = yy_get_previous_state( yyscanner ); + + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of _mesa_glsl_lex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = yyg->yytext_ptr; + register int number_to_move, i; + int ret_val; + + if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + + int yy_c_buf_p_offset = + (int) (yyg->yy_c_buf_p - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + _mesa_glsl_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + yyg->yy_n_chars, (size_t) num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + if ( yyg->yy_n_chars == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + _mesa_glsl_restart(yyin ,yyscanner); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) _mesa_glsl_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + yyg->yy_n_chars += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (yyscan_t yyscanner) +{ + register yy_state_type yy_current_state; + register char *yy_cp; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + yy_current_state = yyg->yy_start; + yy_current_state += YY_AT_BOL(); + + for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 836 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) +{ + register int yy_is_jam; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ + register char *yy_cp = yyg->yy_c_buf_p; + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 836 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 835); + + return yy_is_jam ? 0 : yy_current_state; +} + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (yyscan_t yyscanner) +#else + static int input (yyscan_t yyscanner) +#endif + +{ + int c; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + *yyg->yy_c_buf_p = yyg->yy_hold_char; + + if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) + /* This was really a NUL. */ + *yyg->yy_c_buf_p = '\0'; + + else + { /* need more input */ + int offset = yyg->yy_c_buf_p - yyg->yytext_ptr; + ++yyg->yy_c_buf_p; + + switch ( yy_get_next_buffer( yyscanner ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + _mesa_glsl_restart(yyin ,yyscanner); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( _mesa_glsl_wrap(yyscanner ) ) + return EOF; + + if ( ! yyg->yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(yyscanner); +#else + return input(yyscanner); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + yyg->yy_c_buf_p = yyg->yytext_ptr + offset; + break; + } + } + } + + c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ + *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ + yyg->yy_hold_char = *++yyg->yy_c_buf_p; + + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * @param yyscanner The scanner object. + * @note This function does not reset the start condition to @c INITIAL . + */ + void _mesa_glsl_restart (FILE * input_file , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if ( ! YY_CURRENT_BUFFER ){ + _mesa_glsl_ensure_buffer_stack (yyscanner); + YY_CURRENT_BUFFER_LVALUE = + _mesa_glsl__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); + } + + _mesa_glsl__init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner); + _mesa_glsl__load_buffer_state(yyscanner ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * @param yyscanner The scanner object. + */ + void _mesa_glsl__switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* TODO. We should be able to replace this entire function body + * with + * _mesa_glsl_pop_buffer_state(); + * _mesa_glsl_push_buffer_state(new_buffer); + */ + _mesa_glsl_ensure_buffer_stack (yyscanner); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + _mesa_glsl__load_buffer_state(yyscanner ); + + /* We don't actually know whether we did this switch during + * EOF (_mesa_glsl_wrap()) processing, but the only time this flag + * is looked at is after _mesa_glsl_wrap() is called, so it's safe + * to go ahead and always set it. + */ + yyg->yy_did_buffer_switch_on_eof = 1; +} + +static void _mesa_glsl__load_buffer_state (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + yyg->yy_hold_char = *yyg->yy_c_buf_p; +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * @param yyscanner The scanner object. + * @return the allocated buffer state. + */ + YY_BUFFER_STATE _mesa_glsl__create_buffer (FILE * file, int size , yyscan_t yyscanner) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) _mesa_glsl_alloc(sizeof( struct yy_buffer_state ) ,yyscanner ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in _mesa_glsl__create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) _mesa_glsl_alloc(b->yy_buf_size + 2 ,yyscanner ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in _mesa_glsl__create_buffer()" ); + + b->yy_is_our_buffer = 1; + + _mesa_glsl__init_buffer(b,file ,yyscanner); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with _mesa_glsl__create_buffer() + * @param yyscanner The scanner object. + */ + void _mesa_glsl__delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + _mesa_glsl_free((void *) b->yy_ch_buf ,yyscanner ); + + _mesa_glsl_free((void *) b ,yyscanner ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a _mesa_glsl_restart() or at EOF. + */ + static void _mesa_glsl__init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) + +{ + int oerrno = errno; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + _mesa_glsl__flush_buffer(b ,yyscanner); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then _mesa_glsl__init_buffer was _probably_ + * called from _mesa_glsl_restart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * @param yyscanner The scanner object. + */ + void _mesa_glsl__flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + _mesa_glsl__load_buffer_state(yyscanner ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * @param yyscanner The scanner object. + */ +void _mesa_glsl_push_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (new_buffer == NULL) + return; + + _mesa_glsl_ensure_buffer_stack(yyscanner); + + /* This block is copied from _mesa_glsl__switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + yyg->yy_buffer_stack_top++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from _mesa_glsl__switch_to_buffer. */ + _mesa_glsl__load_buffer_state(yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * @param yyscanner The scanner object. + */ +void _mesa_glsl_pop_buffer_state (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (!YY_CURRENT_BUFFER) + return; + + _mesa_glsl__delete_buffer(YY_CURRENT_BUFFER ,yyscanner); + YY_CURRENT_BUFFER_LVALUE = NULL; + if (yyg->yy_buffer_stack_top > 0) + --yyg->yy_buffer_stack_top; + + if (YY_CURRENT_BUFFER) { + _mesa_glsl__load_buffer_state(yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void _mesa_glsl_ensure_buffer_stack (yyscan_t yyscanner) +{ + int num_to_alloc; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (!yyg->yy_buffer_stack) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + yyg->yy_buffer_stack = (struct yy_buffer_state**)_mesa_glsl_alloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) + YY_FATAL_ERROR( "out of dynamic memory in _mesa_glsl_ensure_buffer_stack()" ); + + memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + yyg->yy_buffer_stack_max = num_to_alloc; + yyg->yy_buffer_stack_top = 0; + return; + } + + if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = yyg->yy_buffer_stack_max + grow_size; + yyg->yy_buffer_stack = (struct yy_buffer_state**)_mesa_glsl_realloc + (yyg->yy_buffer_stack, + num_to_alloc * sizeof(struct yy_buffer_state*) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) + YY_FATAL_ERROR( "out of dynamic memory in _mesa_glsl_ensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); + yyg->yy_buffer_stack_max = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * @param yyscanner The scanner object. + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE _mesa_glsl__scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) _mesa_glsl_alloc(sizeof( struct yy_buffer_state ) ,yyscanner ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in _mesa_glsl__scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + _mesa_glsl__switch_to_buffer(b ,yyscanner ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to _mesa_glsl_lex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * @param yyscanner The scanner object. + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * _mesa_glsl__scan_bytes() instead. + */ +YY_BUFFER_STATE _mesa_glsl__scan_string (yyconst char * yystr , yyscan_t yyscanner) +{ + + return _mesa_glsl__scan_bytes(yystr,strlen(yystr) ,yyscanner); +} + +/** Setup the input buffer state to scan the given bytes. The next call to _mesa_glsl_lex() will + * scan from a @e copy of @a bytes. + * @param bytes the byte buffer to scan + * @param len the number of bytes in the buffer pointed to by @a bytes. + * @param yyscanner The scanner object. + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE _mesa_glsl__scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) _mesa_glsl_alloc(n ,yyscanner ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in _mesa_glsl__scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = _mesa_glsl__scan_buffer(buf,n ,yyscanner); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in _mesa_glsl__scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = yyg->yy_hold_char; \ + yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ + yyg->yy_hold_char = *yyg->yy_c_buf_p; \ + *yyg->yy_c_buf_p = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the user-defined data for this scanner. + * @param yyscanner The scanner object. + */ +YY_EXTRA_TYPE _mesa_glsl_get_extra (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyextra; +} + +/** Get the current line number. + * @param yyscanner The scanner object. + */ +int _mesa_glsl_get_lineno (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; + + return yylineno; +} + +/** Get the current column number. + * @param yyscanner The scanner object. + */ +int _mesa_glsl_get_column (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; + + return yycolumn; +} + +/** Get the input stream. + * @param yyscanner The scanner object. + */ +FILE *_mesa_glsl_get_in (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyin; +} + +/** Get the output stream. + * @param yyscanner The scanner object. + */ +FILE *_mesa_glsl_get_out (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyout; +} + +/** Get the length of the current token. + * @param yyscanner The scanner object. + */ +int _mesa_glsl_get_leng (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyleng; +} + +/** Get the current token. + * @param yyscanner The scanner object. + */ + +char *_mesa_glsl_get_text (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yytext; +} + +/** Set the user-defined data. This data is never touched by the scanner. + * @param user_defined The data to be associated with this scanner. + * @param yyscanner The scanner object. + */ +void _mesa_glsl_set_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyextra = user_defined ; +} + +/** Set the current line number. + * @param line_number + * @param yyscanner The scanner object. + */ +void _mesa_glsl_set_lineno (int line_number , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* lineno is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + yy_fatal_error( "_mesa_glsl_set_lineno called with no buffer" , yyscanner); + + yylineno = line_number; +} + +/** Set the current column. + * @param line_number + * @param yyscanner The scanner object. + */ +void _mesa_glsl_set_column (int column_no , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* column is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + yy_fatal_error( "_mesa_glsl_set_column called with no buffer" , yyscanner); + + yycolumn = column_no; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * @param yyscanner The scanner object. + * @see _mesa_glsl__switch_to_buffer + */ +void _mesa_glsl_set_in (FILE * in_str , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyin = in_str ; +} + +void _mesa_glsl_set_out (FILE * out_str , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyout = out_str ; +} + +int _mesa_glsl_get_debug (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yy_flex_debug; +} + +void _mesa_glsl_set_debug (int bdebug , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yy_flex_debug = bdebug ; +} + +/* Accessor methods for yylval and yylloc */ + +YYSTYPE * _mesa_glsl_get_lval (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yylval; +} + +void _mesa_glsl_set_lval (YYSTYPE * yylval_param , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yylval = yylval_param; +} + +YYLTYPE *_mesa_glsl_get_lloc (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yylloc; +} + +void _mesa_glsl_set_lloc (YYLTYPE * yylloc_param , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yylloc = yylloc_param; +} + +/* User-visible API */ + +/* _mesa_glsl_lex_init is special because it creates the scanner itself, so it is + * the ONLY reentrant function that doesn't take the scanner as the last argument. + * That's why we explicitly handle the declaration, instead of using our macros. + */ + +int _mesa_glsl_lex_init(yyscan_t* ptr_yy_globals) + +{ + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) _mesa_glsl_alloc ( sizeof( struct yyguts_t ), NULL ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + return yy_init_globals ( *ptr_yy_globals ); +} + +/* _mesa_glsl_lex_init_extra has the same functionality as _mesa_glsl_lex_init, but follows the + * convention of taking the scanner as the last argument. Note however, that + * this is a *pointer* to a scanner, as it will be allocated by this call (and + * is the reason, too, why this function also must handle its own declaration). + * The user defined value in the first argument will be available to _mesa_glsl_alloc in + * the yyextra field. + */ + +int _mesa_glsl_lex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) + +{ + struct yyguts_t dummy_yyguts; + + _mesa_glsl_set_extra (yy_user_defined, &dummy_yyguts); + + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) _mesa_glsl_alloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + _mesa_glsl_set_extra (yy_user_defined, *ptr_yy_globals); + + return yy_init_globals ( *ptr_yy_globals ); +} + +static int yy_init_globals (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from _mesa_glsl_lex_destroy(), so don't allocate here. + */ + + yyg->yy_buffer_stack = 0; + yyg->yy_buffer_stack_top = 0; + yyg->yy_buffer_stack_max = 0; + yyg->yy_c_buf_p = (char *) 0; + yyg->yy_init = 0; + yyg->yy_start = 0; + + yyg->yy_start_stack_ptr = 0; + yyg->yy_start_stack_depth = 0; + yyg->yy_start_stack = NULL; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = (FILE *) 0; + yyout = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * _mesa_glsl_lex_init() + */ + return 0; +} + +/* _mesa_glsl_lex_destroy is for both reentrant and non-reentrant scanners. */ +int _mesa_glsl_lex_destroy (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + _mesa_glsl__delete_buffer(YY_CURRENT_BUFFER ,yyscanner ); + YY_CURRENT_BUFFER_LVALUE = NULL; + _mesa_glsl_pop_buffer_state(yyscanner); + } + + /* Destroy the stack itself. */ + _mesa_glsl_free(yyg->yy_buffer_stack ,yyscanner); + yyg->yy_buffer_stack = NULL; + + /* Destroy the start condition stack. */ + _mesa_glsl_free(yyg->yy_start_stack ,yyscanner ); + yyg->yy_start_stack = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * _mesa_glsl_lex() is called, initialization will occur. */ + yy_init_globals( yyscanner); + + /* Destroy the main struct (reentrant only). */ + _mesa_glsl_free ( yyscanner , yyscanner ); + yyscanner = NULL; + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *_mesa_glsl_alloc (yy_size_t size , yyscan_t yyscanner) +{ + return (void *) malloc( size ); +} + +void *_mesa_glsl_realloc (void * ptr, yy_size_t size , yyscan_t yyscanner) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void _mesa_glsl_free (void * ptr , yyscan_t yyscanner) +{ + free( (char *) ptr ); /* see _mesa_glsl_realloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 428 "glsl_lexer.lpp" + + + +int +classify_identifier(struct _mesa_glsl_parse_state *state, const char *name) +{ + if (state->symbols->get_variable(name) || state->symbols->get_function(name)) + return IDENTIFIER; + else if (state->symbols->get_type(name)) + return TYPE_IDENTIFIER; + else + return NEW_IDENTIFIER; +} + +void +_mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, const char *string) +{ + _mesa_glsl_lex_init_extra(state,& state->scanner); + _mesa_glsl__scan_string(string,state->scanner); +} + +void +_mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state) +{ + _mesa_glsl_lex_destroy(state->scanner); +} + diff --git a/src/glsl/glsl_lexer.lpp b/src/glsl/glsl_lexer.lpp new file mode 100644 index 0000000..4dc39d2 --- /dev/null +++ b/src/glsl/glsl_lexer.lpp @@ -0,0 +1,452 @@ +%{ +/* + * Copyright © 2008, 2009 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#include +#include "strtod.h" +#include "ast.h" +#include "glsl_parser_extras.h" +#include "glsl_parser.h" + +static int classify_identifier(struct _mesa_glsl_parse_state *, const char *); + +#define YY_USER_ACTION \ + do { \ + yylloc->source = 0; \ + yylloc->first_column = yycolumn + 1; \ + yylloc->first_line = yylineno + 1; \ + yycolumn += yyleng; \ + } while(0); + +#define YY_USER_INIT yylineno = 0; yycolumn = 0; + +#define IS_UINT (yytext[yyleng - 1] == 'u' || yytext[yyleng - 1] == 'U') + +/* A macro for handling reserved words and keywords across language versions. + * + * Certain words start out as identifiers, become reserved words in + * later language revisions, and finally become language keywords. + * + * For example, consider the following lexer rule: + * samplerBuffer KEYWORD(130, 140, SAMPLERBUFFER) + * + * This means that "samplerBuffer" will be treated as: + * - a keyword (SAMPLERBUFFER token) ...in GLSL >= 1.40 + * - a reserved word - error ...in GLSL >= 1.30 + * - an identifier ...in GLSL < 1.30 + */ +#define KEYWORD(reserved_version, allowed_version, token) \ + do { \ + if (yyextra->language_version >= allowed_version) { \ + return token; \ + } else if (yyextra->language_version >= reserved_version) { \ + _mesa_glsl_error(yylloc, yyextra, \ + "Illegal use of reserved word `%s'", yytext); \ + return ERROR_TOK; \ + } else { \ + yylval->identifier = strdup(yytext); \ + return classify_identifier(yyextra, yytext); \ + } \ + } while (0) + +/* The ES macro can be used in KEYWORD checks: + * + * word KEYWORD(110 || ES, 400, TOKEN) + * ...means the word is reserved in GLSL ES 1.00, while + * + * word KEYWORD(110, 130 || ES, TOKEN) + * ...means the word is a legal keyword in GLSL ES 1.00. + */ +#define ES yyextra->es_shader +%} + +%option bison-bridge bison-locations reentrant noyywrap +%option nounput noyy_top_state +%option never-interactive +%option prefix="_mesa_glsl_" +%option extra-type="struct _mesa_glsl_parse_state *" + +%x PP PRAGMA + +DEC_INT [1-9][0-9]* +HEX_INT 0[xX][0-9a-fA-F]+ +OCT_INT 0[0-7]* +INT ({DEC_INT}|{HEX_INT}|{OCT_INT}) +SPC [ \t]* +SPCP [ \t]+ +HASH ^{SPC}#{SPC} +%% + +[ \r\t]+ ; + + /* Preprocessor tokens. */ +^[ \t]*#[ \t]*$ ; +^[ \t]*#[ \t]*version { BEGIN PP; return VERSION; } +^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; } +{HASH}line{SPCP}{INT}{SPCP}{INT}{SPC}$ { + /* Eat characters until the first digit is + * encountered + */ + char *ptr = yytext; + while (!isdigit(*ptr)) + ptr++; + + /* Subtract one from the line number because + * yylineno is zero-based instead of + * one-based. + */ + yylineno = strtol(ptr, &ptr, 0) - 1; + yylloc->source = strtol(ptr, NULL, 0); + } +{HASH}line{SPCP}{INT}{SPC}$ { + /* Eat characters until the first digit is + * encountered + */ + char *ptr = yytext; + while (!isdigit(*ptr)) + ptr++; + + /* Subtract one from the line number because + * yylineno is zero-based instead of + * one-based. + */ + yylineno = strtol(ptr, &ptr, 0) - 1; + } +^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}on{SPC}\) { + BEGIN PP; + return PRAGMA_DEBUG_ON; + } +^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}off{SPC}\) { + BEGIN PP; + return PRAGMA_DEBUG_OFF; + } +^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}on{SPC}\) { + BEGIN PP; + return PRAGMA_OPTIMIZE_ON; + } +^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}off{SPC}\) { + BEGIN PP; + return PRAGMA_OPTIMIZE_OFF; + } +^{SPC}#{SPC}pragma{SPCP}STDGL{SPCP}invariant{SPC}\({SPC}all{SPC}\) { + BEGIN PP; + return PRAGMA_INVARIANT_ALL; + } +^{SPC}#{SPC}pragma{SPCP} { BEGIN PRAGMA; } + +\n { BEGIN 0; yylineno++; yycolumn = 0; } +. { } + +\/\/[^\n]* { } +[ \t\r]* { } +: return COLON; +[_a-zA-Z][_a-zA-Z0-9]* { + yylval->identifier = strdup(yytext); + return IDENTIFIER; + } +[1-9][0-9]* { + yylval->n = strtol(yytext, NULL, 10); + return INTCONSTANT; + } +\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; } + +\n { yylineno++; yycolumn = 0; } + +attribute return ATTRIBUTE; +const return CONST_TOK; +bool return BOOL_TOK; +float return FLOAT_TOK; +int return INT_TOK; +uint KEYWORD(130, 130, UINT_TOK); + +break return BREAK; +continue return CONTINUE; +do return DO; +while return WHILE; +else return ELSE; +for return FOR; +if return IF; +discard return DISCARD; +return return RETURN; + +bvec2 return BVEC2; +bvec3 return BVEC3; +bvec4 return BVEC4; +ivec2 return IVEC2; +ivec3 return IVEC3; +ivec4 return IVEC4; +uvec2 KEYWORD(130, 130, UVEC2); +uvec3 KEYWORD(130, 130, UVEC3); +uvec4 KEYWORD(130, 130, UVEC4); +vec2 return VEC2; +vec3 return VEC3; +vec4 return VEC4; +mat2 return MAT2X2; +mat3 return MAT3X3; +mat4 return MAT4X4; +mat2x2 KEYWORD(120, 120, MAT2X2); +mat2x3 KEYWORD(120, 120, MAT2X3); +mat2x4 KEYWORD(120, 120, MAT2X4); +mat3x2 KEYWORD(120, 120, MAT3X2); +mat3x3 KEYWORD(120, 120, MAT3X3); +mat3x4 KEYWORD(120, 120, MAT3X4); +mat4x2 KEYWORD(120, 120, MAT4X2); +mat4x3 KEYWORD(120, 120, MAT4X3); +mat4x4 KEYWORD(120, 120, MAT4X4); + +in return IN_TOK; +out return OUT_TOK; +inout return INOUT_TOK; +uniform return UNIFORM; +varying return VARYING; +centroid KEYWORD(120, 120, CENTROID); +invariant KEYWORD(120 || ES, 120 || ES, INVARIANT); +flat KEYWORD(130 || ES, 130, FLAT); +smooth KEYWORD(130, 130, SMOOTH); +noperspective KEYWORD(130, 130, NOPERSPECTIVE); + +sampler1D return SAMPLER1D; +sampler2D return SAMPLER2D; +sampler3D return SAMPLER3D; +samplerCube return SAMPLERCUBE; +sampler1DArray KEYWORD(130, 130, SAMPLER1DARRAY); +sampler2DArray KEYWORD(130, 130, SAMPLER2DARRAY); +sampler1DShadow return SAMPLER1DSHADOW; +sampler2DShadow return SAMPLER2DSHADOW; +samplerCubeShadow KEYWORD(130, 130, SAMPLERCUBESHADOW); +sampler1DArrayShadow KEYWORD(130, 130, SAMPLER1DARRAYSHADOW); +sampler2DArrayShadow KEYWORD(130, 130, SAMPLER2DARRAYSHADOW); +isampler1D KEYWORD(130, 130, ISAMPLER1D); +isampler2D KEYWORD(130, 130, ISAMPLER2D); +isampler3D KEYWORD(130, 130, ISAMPLER3D); +isamplerCube KEYWORD(130, 130, ISAMPLERCUBE); +isampler1DArray KEYWORD(130, 130, ISAMPLER1DARRAY); +isampler2DArray KEYWORD(130, 130, ISAMPLER2DARRAY); +usampler1D KEYWORD(130, 130, USAMPLER1D); +usampler2D KEYWORD(130, 130, USAMPLER2D); +usampler3D KEYWORD(130, 130, USAMPLER3D); +usamplerCube KEYWORD(130, 130, USAMPLERCUBE); +usampler1DArray KEYWORD(130, 130, USAMPLER1DARRAY); +usampler2DArray KEYWORD(130, 130, USAMPLER2DARRAY); + + +struct return STRUCT; +void return VOID_TOK; + +layout { + if ((yyextra->language_version >= 140) + || yyextra->ARB_explicit_attrib_location_enable + || (yyextra->ARB_fragment_coord_conventions_enable)){ + return LAYOUT_TOK; + } else { + yylval->identifier = strdup(yytext); + return IDENTIFIER; + } + } + +\+\+ return INC_OP; +-- return DEC_OP; +\<= return LE_OP; +>= return GE_OP; +== return EQ_OP; +!= return NE_OP; +&& return AND_OP; +\|\| return OR_OP; +"^^" return XOR_OP; +"<<" return LEFT_OP; +">>" return RIGHT_OP; + +\*= return MUL_ASSIGN; +\/= return DIV_ASSIGN; +\+= return ADD_ASSIGN; +\%= return MOD_ASSIGN; +\<\<= return LEFT_ASSIGN; +>>= return RIGHT_ASSIGN; +&= return AND_ASSIGN; +"^=" return XOR_ASSIGN; +\|= return OR_ASSIGN; +-= return SUB_ASSIGN; + +[1-9][0-9]*[uU]? { + yylval->n = strtol(yytext, NULL, 10); + return IS_UINT ? UINTCONSTANT : INTCONSTANT; + } +0[xX][0-9a-fA-F]+[uU]? { + yylval->n = strtol(yytext + 2, NULL, 16); + return IS_UINT ? UINTCONSTANT : INTCONSTANT; + } +0[0-7]*[uU]? { + yylval->n = strtol(yytext, NULL, 8); + return IS_UINT ? UINTCONSTANT : INTCONSTANT; + } + +[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? { + yylval->real = glsl_strtod(yytext, NULL); + return FLOATCONSTANT; + } +\.[0-9]+([eE][+-]?[0-9]+)?[fF]? { + yylval->real = glsl_strtod(yytext, NULL); + return FLOATCONSTANT; + } +[0-9]+\.([eE][+-]?[0-9]+)?[fF]? { + yylval->real = glsl_strtod(yytext, NULL); + return FLOATCONSTANT; + } +[0-9]+[eE][+-]?[0-9]+[fF]? { + yylval->real = glsl_strtod(yytext, NULL); + return FLOATCONSTANT; + } +[0-9]+[fF] { + yylval->real = glsl_strtod(yytext, NULL); + return FLOATCONSTANT; + } + +true { + yylval->n = 1; + return BOOLCONSTANT; + } +false { + yylval->n = 0; + return BOOLCONSTANT; + } + + + /* Reserved words in GLSL 1.10. */ +asm KEYWORD(110 || ES, 999, ASM); +class KEYWORD(110 || ES, 999, CLASS); +union KEYWORD(110 || ES, 999, UNION); +enum KEYWORD(110 || ES, 999, ENUM); +typedef KEYWORD(110 || ES, 999, TYPEDEF); +template KEYWORD(110 || ES, 999, TEMPLATE); +this KEYWORD(110 || ES, 999, THIS); +packed KEYWORD(110 || ES, 999, PACKED_TOK); +goto KEYWORD(110 || ES, 999, GOTO); +switch KEYWORD(110 || ES, 130, SWITCH); +default KEYWORD(110 || ES, 130, DEFAULT); +inline KEYWORD(110 || ES, 999, INLINE_TOK); +noinline KEYWORD(110 || ES, 999, NOINLINE); +volatile KEYWORD(110 || ES, 999, VOLATILE); +public KEYWORD(110 || ES, 999, PUBLIC_TOK); +static KEYWORD(110 || ES, 999, STATIC); +extern KEYWORD(110 || ES, 999, EXTERN); +external KEYWORD(110 || ES, 999, EXTERNAL); +interface KEYWORD(110 || ES, 999, INTERFACE); +long KEYWORD(110 || ES, 999, LONG_TOK); +short KEYWORD(110 || ES, 999, SHORT_TOK); +double KEYWORD(110 || ES, 400, DOUBLE_TOK); +half KEYWORD(110 || ES, 999, HALF); +fixed KEYWORD(110 || ES, 999, FIXED_TOK); +unsigned KEYWORD(110 || ES, 999, UNSIGNED); +input KEYWORD(110 || ES, 999, INPUT_TOK); +output KEYWORD(110 || ES, 999, OUTPUT); +hvec2 KEYWORD(110 || ES, 999, HVEC2); +hvec3 KEYWORD(110 || ES, 999, HVEC3); +hvec4 KEYWORD(110 || ES, 999, HVEC4); +dvec2 KEYWORD(110 || ES, 400, DVEC2); +dvec3 KEYWORD(110 || ES, 400, DVEC3); +dvec4 KEYWORD(110 || ES, 400, DVEC4); +fvec2 KEYWORD(110 || ES, 999, FVEC2); +fvec3 KEYWORD(110 || ES, 999, FVEC3); +fvec4 KEYWORD(110 || ES, 999, FVEC4); +sampler2DRect return SAMPLER2DRECT; +sampler3DRect KEYWORD(110 || ES, 999, SAMPLER3DRECT); +sampler2DRectShadow return SAMPLER2DRECTSHADOW; +sizeof KEYWORD(110 || ES, 999, SIZEOF); +cast KEYWORD(110 || ES, 999, CAST); +namespace KEYWORD(110 || ES, 999, NAMESPACE); +using KEYWORD(110 || ES, 999, USING); + + /* Additional reserved words in GLSL 1.20. */ +lowp KEYWORD(120, 130 || ES, LOWP); +mediump KEYWORD(120, 130 || ES, MEDIUMP); +highp KEYWORD(120, 130 || ES, HIGHP); +precision KEYWORD(120, 130 || ES, PRECISION); + + /* Additional reserved words in GLSL 1.30. */ +case KEYWORD(130, 130, CASE); +common KEYWORD(130, 999, COMMON); +partition KEYWORD(130, 999, PARTITION); +active KEYWORD(130, 999, ACTIVE); +superp KEYWORD(130 || ES, 999, SUPERP); +samplerBuffer KEYWORD(130, 140, SAMPLERBUFFER); +filter KEYWORD(130, 999, FILTER); +image1D KEYWORD(130, 999, IMAGE1D); +image2D KEYWORD(130, 999, IMAGE2D); +image3D KEYWORD(130, 999, IMAGE3D); +imageCube KEYWORD(130, 999, IMAGECUBE); +iimage1D KEYWORD(130, 999, IIMAGE1D); +iimage2D KEYWORD(130, 999, IIMAGE2D); +iimage3D KEYWORD(130, 999, IIMAGE3D); +iimageCube KEYWORD(130, 999, IIMAGECUBE); +uimage1D KEYWORD(130, 999, UIMAGE1D); +uimage2D KEYWORD(130, 999, UIMAGE2D); +uimage3D KEYWORD(130, 999, UIMAGE3D); +uimageCube KEYWORD(130, 999, UIMAGECUBE); +image1DArray KEYWORD(130, 999, IMAGE1DARRAY); +image2DArray KEYWORD(130, 999, IMAGE2DARRAY); +iimage1DArray KEYWORD(130, 999, IIMAGE1DARRAY); +iimage2DArray KEYWORD(130, 999, IIMAGE2DARRAY); +uimage1DArray KEYWORD(130, 999, UIMAGE1DARRAY); +uimage2DArray KEYWORD(130, 999, UIMAGE2DARRAY); +image1DShadow KEYWORD(130, 999, IMAGE1DSHADOW); +image2DShadow KEYWORD(130, 999, IMAGE2DSHADOW); +image1DArrayShadow KEYWORD(130, 999, IMAGE1DARRAYSHADOW); +image2DArrayShadow KEYWORD(130, 999, IMAGE2DARRAYSHADOW); +imageBuffer KEYWORD(130, 999, IMAGEBUFFER); +iimageBuffer KEYWORD(130, 999, IIMAGEBUFFER); +uimageBuffer KEYWORD(130, 999, UIMAGEBUFFER); +row_major KEYWORD(130, 999, ROW_MAJOR); + +[_a-zA-Z][_a-zA-Z0-9]* { + struct _mesa_glsl_parse_state *state = yyextra; + void *ctx = state; + yylval->identifier = ralloc_strdup(ctx, yytext); + return classify_identifier(state, yytext); + } + +. { return yytext[0]; } + +%% + +int +classify_identifier(struct _mesa_glsl_parse_state *state, const char *name) +{ + if (state->symbols->get_variable(name) || state->symbols->get_function(name)) + return IDENTIFIER; + else if (state->symbols->get_type(name)) + return TYPE_IDENTIFIER; + else + return NEW_IDENTIFIER; +} + +void +_mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, const char *string) +{ + yylex_init_extra(state, & state->scanner); + yy_scan_string(string, state->scanner); +} + +void +_mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state) +{ + yylex_destroy(state->scanner); +} diff --git a/src/glsl/glsl_parser.cpp b/src/glsl/glsl_parser.cpp new file mode 100644 index 0000000..70a0fdb --- /dev/null +++ b/src/glsl/glsl_parser.cpp @@ -0,0 +1,5433 @@ +/* A Bison parser, made by GNU Bison 2.4.3. */ + +/* Skeleton implementation for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2009, 2010 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "2.4.3" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 1 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + +/* Using locations. */ +#define YYLSP_NEEDED 1 + +/* Substitute the variable and function names. */ +#define yyparse _mesa_glsl_parse +#define yylex _mesa_glsl_lex +#define yyerror _mesa_glsl_error +#define yylval _mesa_glsl_lval +#define yychar _mesa_glsl_char +#define yydebug _mesa_glsl_debug +#define yynerrs _mesa_glsl_nerrs +#define yylloc _mesa_glsl_lloc + +/* Copy the first part of user declarations. */ + +/* Line 189 of yacc.c */ +#line 1 "glsl_parser.ypp" + +/* + * Copyright © 2008, 2009 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#include +#include +#include +#include + +#include "ast.h" +#include "glsl_parser_extras.h" +#include "glsl_types.h" + +#define YYLEX_PARAM state->scanner + + + +/* Line 189 of yacc.c */ +#line 117 "glsl_parser.cpp" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 1 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + ATTRIBUTE = 258, + CONST_TOK = 259, + BOOL_TOK = 260, + FLOAT_TOK = 261, + INT_TOK = 262, + UINT_TOK = 263, + BREAK = 264, + CONTINUE = 265, + DO = 266, + ELSE = 267, + FOR = 268, + IF = 269, + DISCARD = 270, + RETURN = 271, + SWITCH = 272, + CASE = 273, + DEFAULT = 274, + BVEC2 = 275, + BVEC3 = 276, + BVEC4 = 277, + IVEC2 = 278, + IVEC3 = 279, + IVEC4 = 280, + UVEC2 = 281, + UVEC3 = 282, + UVEC4 = 283, + VEC2 = 284, + VEC3 = 285, + VEC4 = 286, + CENTROID = 287, + IN_TOK = 288, + OUT_TOK = 289, + INOUT_TOK = 290, + UNIFORM = 291, + VARYING = 292, + NOPERSPECTIVE = 293, + FLAT = 294, + SMOOTH = 295, + MAT2X2 = 296, + MAT2X3 = 297, + MAT2X4 = 298, + MAT3X2 = 299, + MAT3X3 = 300, + MAT3X4 = 301, + MAT4X2 = 302, + MAT4X3 = 303, + MAT4X4 = 304, + SAMPLER1D = 305, + SAMPLER2D = 306, + SAMPLER3D = 307, + SAMPLERCUBE = 308, + SAMPLER1DSHADOW = 309, + SAMPLER2DSHADOW = 310, + SAMPLERCUBESHADOW = 311, + SAMPLER1DARRAY = 312, + SAMPLER2DARRAY = 313, + SAMPLER1DARRAYSHADOW = 314, + SAMPLER2DARRAYSHADOW = 315, + ISAMPLER1D = 316, + ISAMPLER2D = 317, + ISAMPLER3D = 318, + ISAMPLERCUBE = 319, + ISAMPLER1DARRAY = 320, + ISAMPLER2DARRAY = 321, + USAMPLER1D = 322, + USAMPLER2D = 323, + USAMPLER3D = 324, + USAMPLERCUBE = 325, + USAMPLER1DARRAY = 326, + USAMPLER2DARRAY = 327, + STRUCT = 328, + VOID_TOK = 329, + WHILE = 330, + IDENTIFIER = 331, + TYPE_IDENTIFIER = 332, + NEW_IDENTIFIER = 333, + FLOATCONSTANT = 334, + INTCONSTANT = 335, + UINTCONSTANT = 336, + BOOLCONSTANT = 337, + FIELD_SELECTION = 338, + LEFT_OP = 339, + RIGHT_OP = 340, + INC_OP = 341, + DEC_OP = 342, + LE_OP = 343, + GE_OP = 344, + EQ_OP = 345, + NE_OP = 346, + AND_OP = 347, + OR_OP = 348, + XOR_OP = 349, + MUL_ASSIGN = 350, + DIV_ASSIGN = 351, + ADD_ASSIGN = 352, + MOD_ASSIGN = 353, + LEFT_ASSIGN = 354, + RIGHT_ASSIGN = 355, + AND_ASSIGN = 356, + XOR_ASSIGN = 357, + OR_ASSIGN = 358, + SUB_ASSIGN = 359, + INVARIANT = 360, + LOWP = 361, + MEDIUMP = 362, + HIGHP = 363, + SUPERP = 364, + PRECISION = 365, + VERSION = 366, + EXTENSION = 367, + LINE = 368, + COLON = 369, + EOL = 370, + INTERFACE = 371, + OUTPUT = 372, + PRAGMA_DEBUG_ON = 373, + PRAGMA_DEBUG_OFF = 374, + PRAGMA_OPTIMIZE_ON = 375, + PRAGMA_OPTIMIZE_OFF = 376, + PRAGMA_INVARIANT_ALL = 377, + LAYOUT_TOK = 378, + ASM = 379, + CLASS = 380, + UNION = 381, + ENUM = 382, + TYPEDEF = 383, + TEMPLATE = 384, + THIS = 385, + PACKED_TOK = 386, + GOTO = 387, + INLINE_TOK = 388, + NOINLINE = 389, + VOLATILE = 390, + PUBLIC_TOK = 391, + STATIC = 392, + EXTERN = 393, + EXTERNAL = 394, + LONG_TOK = 395, + SHORT_TOK = 396, + DOUBLE_TOK = 397, + HALF = 398, + FIXED_TOK = 399, + UNSIGNED = 400, + INPUT_TOK = 401, + OUPTUT = 402, + HVEC2 = 403, + HVEC3 = 404, + HVEC4 = 405, + DVEC2 = 406, + DVEC3 = 407, + DVEC4 = 408, + FVEC2 = 409, + FVEC3 = 410, + FVEC4 = 411, + SAMPLER2DRECT = 412, + SAMPLER3DRECT = 413, + SAMPLER2DRECTSHADOW = 414, + SIZEOF = 415, + CAST = 416, + NAMESPACE = 417, + USING = 418, + ERROR_TOK = 419, + COMMON = 420, + PARTITION = 421, + ACTIVE = 422, + SAMPLERBUFFER = 423, + FILTER = 424, + IMAGE1D = 425, + IMAGE2D = 426, + IMAGE3D = 427, + IMAGECUBE = 428, + IMAGE1DARRAY = 429, + IMAGE2DARRAY = 430, + IIMAGE1D = 431, + IIMAGE2D = 432, + IIMAGE3D = 433, + IIMAGECUBE = 434, + IIMAGE1DARRAY = 435, + IIMAGE2DARRAY = 436, + UIMAGE1D = 437, + UIMAGE2D = 438, + UIMAGE3D = 439, + UIMAGECUBE = 440, + UIMAGE1DARRAY = 441, + UIMAGE2DARRAY = 442, + IMAGE1DSHADOW = 443, + IMAGE2DSHADOW = 444, + IMAGEBUFFER = 445, + IIMAGEBUFFER = 446, + UIMAGEBUFFER = 447, + IMAGE1DARRAYSHADOW = 448, + IMAGE2DARRAYSHADOW = 449, + ROW_MAJOR = 450 + }; +#endif + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ + +/* Line 214 of yacc.c */ +#line 52 "glsl_parser.ypp" + + int n; + float real; + char *identifier; + + struct ast_type_qualifier type_qualifier; + + ast_node *node; + ast_type_specifier *type_specifier; + ast_fully_specified_type *fully_specified_type; + ast_function *function; + ast_parameter_declarator *parameter_declarator; + ast_function_definition *function_definition; + ast_compound_statement *compound_statement; + ast_expression *expression; + ast_declarator_list *declarator_list; + ast_struct_specifier *struct_specifier; + ast_declaration *declaration; + + struct { + ast_node *cond; + ast_expression *rest; + } for_rest_statement; + + struct { + ast_node *then_statement; + ast_node *else_statement; + } selection_rest_statement; + + + +/* Line 214 of yacc.c */ +#line 380 "glsl_parser.cpp" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + +/* Copy the second part of user declarations. */ + + +/* Line 264 of yacc.c */ +#line 405 "glsl_parser.cpp" + +#ifdef short +# undef short +#endif + +#ifdef YYTYPE_UINT8 +typedef YYTYPE_UINT8 yytype_uint8; +#else +typedef unsigned char yytype_uint8; +#endif + +#ifdef YYTYPE_INT8 +typedef YYTYPE_INT8 yytype_int8; +#elif (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +typedef signed char yytype_int8; +#else +typedef short int yytype_int8; +#endif + +#ifdef YYTYPE_UINT16 +typedef YYTYPE_UINT16 yytype_uint16; +#else +typedef unsigned short int yytype_uint16; +#endif + +#ifdef YYTYPE_INT16 +typedef YYTYPE_INT16 yytype_int16; +#else +typedef short int yytype_int16; +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned int +# endif +#endif + +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(e) ((void) (e)) +#else +# define YYUSE(e) /* empty */ +#endif + +/* Identity function, used to suppress warnings about constant conditions. */ +#ifndef lint +# define YYID(n) (n) +#else +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static int +YYID (int yyi) +#else +static int +YYID (yyi) + int yyi; +#endif +{ + return yyi; +} +#endif + +#if ! defined yyoverflow || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef _STDLIB_H +# define _STDLIB_H 1 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined _STDLIB_H \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef _STDLIB_H +# define _STDLIB_H 1 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ + && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yytype_int16 yyss_alloc; + YYSTYPE yyvs_alloc; + YYLTYPE yyls_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + + 2 * YYSTACK_GAP_MAXIMUM) + +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (YYID (0)) + +#endif + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 5 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 3692 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 220 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 93 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 291 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 434 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 450 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const yytype_uint8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 204, 2, 2, 2, 208, 211, 2, + 196, 197, 206, 202, 201, 203, 200, 207, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 215, 217, + 209, 216, 210, 214, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 198, 2, 199, 212, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 218, 213, 219, 205, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, + 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, + 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, + 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, + 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, + 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, + 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, + 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, + 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, + 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, + 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, + 195 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const yytype_uint16 yyprhs[] = +{ + 0, 0, 3, 4, 9, 10, 14, 17, 20, 23, + 26, 29, 30, 33, 35, 37, 39, 45, 47, 50, + 52, 54, 56, 58, 60, 62, 64, 68, 70, 75, + 77, 81, 84, 87, 89, 91, 93, 97, 100, 103, + 106, 108, 111, 115, 118, 120, 122, 124, 127, 130, + 133, 135, 138, 142, 145, 147, 150, 153, 156, 158, + 160, 162, 164, 166, 170, 174, 178, 180, 184, 188, + 190, 194, 198, 200, 204, 208, 212, 216, 218, 222, + 226, 228, 232, 234, 238, 240, 244, 246, 250, 252, + 256, 258, 262, 264, 270, 272, 276, 278, 280, 282, + 284, 286, 288, 290, 292, 294, 296, 298, 300, 304, + 306, 309, 312, 317, 320, 322, 324, 327, 331, 335, + 338, 344, 348, 351, 355, 358, 359, 361, 363, 365, + 367, 369, 373, 379, 386, 394, 403, 409, 411, 414, + 419, 425, 432, 440, 445, 448, 450, 453, 458, 460, + 464, 466, 470, 472, 474, 476, 478, 480, 482, 485, + 487, 490, 493, 497, 499, 501, 503, 505, 508, 510, + 512, 515, 518, 520, 522, 525, 527, 531, 536, 538, + 540, 542, 544, 546, 548, 550, 552, 554, 556, 558, + 560, 562, 564, 566, 568, 570, 572, 574, 576, 578, + 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, + 600, 602, 604, 606, 608, 610, 612, 614, 616, 618, + 620, 622, 624, 626, 628, 630, 632, 634, 636, 638, + 640, 642, 644, 646, 648, 650, 656, 661, 663, 666, + 670, 672, 676, 678, 683, 685, 687, 689, 691, 693, + 695, 697, 699, 701, 703, 705, 708, 709, 714, 716, + 718, 721, 725, 727, 730, 732, 735, 741, 745, 747, + 749, 754, 760, 764, 767, 773, 781, 788, 790, 792, + 794, 795, 798, 802, 805, 808, 811, 815, 818, 820, + 822, 824 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yytype_int16 yyrhs[] = +{ + 221, 0, -1, -1, 223, 225, 222, 228, -1, -1, + 111, 80, 115, -1, 118, 115, -1, 119, 115, -1, + 120, 115, -1, 121, 115, -1, 122, 115, -1, -1, + 225, 227, -1, 76, -1, 77, -1, 78, -1, 112, + 226, 114, 226, 115, -1, 311, -1, 228, 311, -1, + 76, -1, 78, -1, 229, -1, 80, -1, 81, -1, + 79, -1, 82, -1, 196, 260, 197, -1, 230, -1, + 231, 198, 232, 199, -1, 233, -1, 231, 200, 226, + -1, 231, 86, -1, 231, 87, -1, 260, -1, 234, + -1, 235, -1, 231, 200, 240, -1, 237, 197, -1, + 236, 197, -1, 238, 74, -1, 238, -1, 238, 258, + -1, 237, 201, 258, -1, 239, 196, -1, 281, -1, + 229, -1, 83, -1, 242, 197, -1, 241, 197, -1, + 243, 74, -1, 243, -1, 243, 258, -1, 242, 201, + 258, -1, 229, 196, -1, 231, -1, 86, 244, -1, + 87, 244, -1, 245, 244, -1, 202, -1, 203, -1, + 204, -1, 205, -1, 244, -1, 246, 206, 244, -1, + 246, 207, 244, -1, 246, 208, 244, -1, 246, -1, + 247, 202, 246, -1, 247, 203, 246, -1, 247, -1, + 248, 84, 247, -1, 248, 85, 247, -1, 248, -1, + 249, 209, 248, -1, 249, 210, 248, -1, 249, 88, + 248, -1, 249, 89, 248, -1, 249, -1, 250, 90, + 249, -1, 250, 91, 249, -1, 250, -1, 251, 211, + 250, -1, 251, -1, 252, 212, 251, -1, 252, -1, + 253, 213, 252, -1, 253, -1, 254, 92, 253, -1, + 254, -1, 255, 94, 254, -1, 255, -1, 256, 93, + 255, -1, 256, -1, 256, 214, 260, 215, 258, -1, + 257, -1, 244, 259, 258, -1, 216, -1, 95, -1, + 96, -1, 98, -1, 97, -1, 104, -1, 99, -1, + 100, -1, 101, -1, 102, -1, 103, -1, 258, -1, + 260, 201, 258, -1, 257, -1, 263, 217, -1, 271, + 217, -1, 110, 285, 282, 217, -1, 264, 197, -1, + 266, -1, 265, -1, 266, 268, -1, 265, 201, 268, + -1, 273, 229, 196, -1, 281, 226, -1, 281, 226, + 198, 261, 199, -1, 278, 269, 267, -1, 269, 267, + -1, 278, 269, 270, -1, 269, 270, -1, -1, 33, + -1, 34, -1, 35, -1, 281, -1, 272, -1, 271, + 201, 226, -1, 271, 201, 226, 198, 199, -1, 271, + 201, 226, 198, 261, 199, -1, 271, 201, 226, 198, + 199, 216, 291, -1, 271, 201, 226, 198, 261, 199, + 216, 291, -1, 271, 201, 226, 216, 291, -1, 273, + -1, 273, 226, -1, 273, 226, 198, 199, -1, 273, + 226, 198, 261, 199, -1, 273, 226, 198, 199, 216, + 291, -1, 273, 226, 198, 261, 199, 216, 291, -1, + 273, 226, 216, 291, -1, 105, 229, -1, 281, -1, + 279, 281, -1, 123, 196, 275, 197, -1, 276, -1, + 275, 201, 276, -1, 226, -1, 226, 216, 80, -1, + 40, -1, 39, -1, 38, -1, 4, -1, 280, -1, + 274, -1, 274, 280, -1, 277, -1, 277, 280, -1, + 105, 280, -1, 105, 277, 280, -1, 105, -1, 4, + -1, 3, -1, 37, -1, 32, 37, -1, 33, -1, + 34, -1, 32, 33, -1, 32, 34, -1, 36, -1, + 282, -1, 285, 282, -1, 283, -1, 283, 198, 199, + -1, 283, 198, 261, 199, -1, 284, -1, 286, -1, + 77, -1, 74, -1, 6, -1, 7, -1, 8, -1, + 5, -1, 29, -1, 30, -1, 31, -1, 20, -1, + 21, -1, 22, -1, 23, -1, 24, -1, 25, -1, + 26, -1, 27, -1, 28, -1, 41, -1, 42, -1, + 43, -1, 44, -1, 45, -1, 46, -1, 47, -1, + 48, -1, 49, -1, 50, -1, 51, -1, 157, -1, + 52, -1, 53, -1, 54, -1, 55, -1, 159, -1, + 56, -1, 57, -1, 58, -1, 59, -1, 60, -1, + 61, -1, 62, -1, 63, -1, 64, -1, 65, -1, + 66, -1, 67, -1, 68, -1, 69, -1, 70, -1, + 71, -1, 72, -1, 108, -1, 107, -1, 106, -1, + 73, 226, 218, 287, 219, -1, 73, 218, 287, 219, + -1, 288, -1, 287, 288, -1, 281, 289, 217, -1, + 290, -1, 289, 201, 290, -1, 226, -1, 226, 198, + 261, 199, -1, 258, -1, 262, -1, 295, -1, 294, + -1, 292, -1, 300, -1, 301, -1, 304, -1, 305, + -1, 306, -1, 310, -1, 218, 219, -1, -1, 218, + 296, 299, 219, -1, 298, -1, 294, -1, 218, 219, + -1, 218, 299, 219, -1, 293, -1, 299, 293, -1, + 217, -1, 260, 217, -1, 14, 196, 260, 197, 302, + -1, 293, 12, 293, -1, 293, -1, 260, -1, 273, + 226, 216, 291, -1, 17, 196, 260, 197, 295, -1, + 18, 260, 215, -1, 19, 215, -1, 75, 196, 303, + 197, 297, -1, 11, 293, 75, 196, 260, 197, 217, + -1, 13, 196, 307, 309, 197, 297, -1, 300, -1, + 292, -1, 303, -1, -1, 308, 217, -1, 308, 217, + 260, -1, 10, 217, -1, 9, 217, -1, 16, 217, + -1, 16, 260, 217, -1, 15, 217, -1, 312, -1, + 262, -1, 224, -1, 263, 298, -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const yytype_uint16 yyrline[] = +{ + 0, 218, 218, 217, 229, 231, 271, 272, 273, 274, + 275, 287, 289, 293, 294, 295, 299, 308, 316, 327, + 328, 332, 339, 346, 353, 360, 367, 374, 375, 381, + 385, 392, 398, 407, 411, 415, 416, 425, 426, 430, + 431, 435, 441, 453, 457, 463, 470, 480, 481, 485, + 486, 490, 496, 508, 519, 520, 526, 532, 542, 543, + 544, 545, 549, 550, 556, 562, 571, 572, 578, 587, + 588, 594, 603, 604, 610, 616, 622, 631, 632, 638, + 647, 648, 657, 658, 667, 668, 677, 678, 687, 688, + 697, 698, 707, 708, 717, 718, 727, 728, 729, 730, + 731, 732, 733, 734, 735, 736, 737, 741, 745, 761, + 765, 770, 774, 783, 787, 788, 792, 797, 805, 819, + 829, 844, 851, 856, 867, 880, 883, 888, 893, 902, + 906, 907, 917, 927, 937, 947, 957, 971, 982, 991, + 1000, 1009, 1018, 1027, 1036, 1050, 1057, 1068, 1075, 1076, + 1095, 1124, 1165, 1170, 1175, 1183, 1191, 1192, 1193, 1198, + 1199, 1204, 1209, 1215, 1223, 1228, 1233, 1238, 1244, 1249, + 1254, 1259, 1264, 1272, 1276, 1284, 1285, 1291, 1300, 1306, + 1312, 1321, 1322, 1323, 1324, 1325, 1326, 1327, 1328, 1329, + 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337, 1338, 1339, + 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349, + 1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359, + 1360, 1361, 1362, 1363, 1364, 1365, 1366, 1367, 1368, 1369, + 1370, 1371, 1375, 1385, 1395, 1408, 1415, 1424, 1429, 1437, + 1452, 1457, 1465, 1472, 1481, 1485, 1491, 1492, 1496, 1497, + 1498, 1499, 1500, 1501, 1502, 1506, 1513, 1512, 1526, 1527, + 1531, 1537, 1546, 1556, 1568, 1574, 1583, 1592, 1597, 1605, + 1609, 1623, 1627, 1628, 1632, 1639, 1646, 1656, 1657, 1661, + 1663, 1669, 1674, 1683, 1689, 1695, 1701, 1707, 1716, 1717, + 1718, 1722 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "ATTRIBUTE", "CONST_TOK", "BOOL_TOK", + "FLOAT_TOK", "INT_TOK", "UINT_TOK", "BREAK", "CONTINUE", "DO", "ELSE", + "FOR", "IF", "DISCARD", "RETURN", "SWITCH", "CASE", "DEFAULT", "BVEC2", + "BVEC3", "BVEC4", "IVEC2", "IVEC3", "IVEC4", "UVEC2", "UVEC3", "UVEC4", + "VEC2", "VEC3", "VEC4", "CENTROID", "IN_TOK", "OUT_TOK", "INOUT_TOK", + "UNIFORM", "VARYING", "NOPERSPECTIVE", "FLAT", "SMOOTH", "MAT2X2", + "MAT2X3", "MAT2X4", "MAT3X2", "MAT3X3", "MAT3X4", "MAT4X2", "MAT4X3", + "MAT4X4", "SAMPLER1D", "SAMPLER2D", "SAMPLER3D", "SAMPLERCUBE", + "SAMPLER1DSHADOW", "SAMPLER2DSHADOW", "SAMPLERCUBESHADOW", + "SAMPLER1DARRAY", "SAMPLER2DARRAY", "SAMPLER1DARRAYSHADOW", + "SAMPLER2DARRAYSHADOW", "ISAMPLER1D", "ISAMPLER2D", "ISAMPLER3D", + "ISAMPLERCUBE", "ISAMPLER1DARRAY", "ISAMPLER2DARRAY", "USAMPLER1D", + "USAMPLER2D", "USAMPLER3D", "USAMPLERCUBE", "USAMPLER1DARRAY", + "USAMPLER2DARRAY", "STRUCT", "VOID_TOK", "WHILE", "IDENTIFIER", + "TYPE_IDENTIFIER", "NEW_IDENTIFIER", "FLOATCONSTANT", "INTCONSTANT", + "UINTCONSTANT", "BOOLCONSTANT", "FIELD_SELECTION", "LEFT_OP", "RIGHT_OP", + "INC_OP", "DEC_OP", "LE_OP", "GE_OP", "EQ_OP", "NE_OP", "AND_OP", + "OR_OP", "XOR_OP", "MUL_ASSIGN", "DIV_ASSIGN", "ADD_ASSIGN", + "MOD_ASSIGN", "LEFT_ASSIGN", "RIGHT_ASSIGN", "AND_ASSIGN", "XOR_ASSIGN", + "OR_ASSIGN", "SUB_ASSIGN", "INVARIANT", "LOWP", "MEDIUMP", "HIGHP", + "SUPERP", "PRECISION", "VERSION", "EXTENSION", "LINE", "COLON", "EOL", + "INTERFACE", "OUTPUT", "PRAGMA_DEBUG_ON", "PRAGMA_DEBUG_OFF", + "PRAGMA_OPTIMIZE_ON", "PRAGMA_OPTIMIZE_OFF", "PRAGMA_INVARIANT_ALL", + "LAYOUT_TOK", "ASM", "CLASS", "UNION", "ENUM", "TYPEDEF", "TEMPLATE", + "THIS", "PACKED_TOK", "GOTO", "INLINE_TOK", "NOINLINE", "VOLATILE", + "PUBLIC_TOK", "STATIC", "EXTERN", "EXTERNAL", "LONG_TOK", "SHORT_TOK", + "DOUBLE_TOK", "HALF", "FIXED_TOK", "UNSIGNED", "INPUT_TOK", "OUPTUT", + "HVEC2", "HVEC3", "HVEC4", "DVEC2", "DVEC3", "DVEC4", "FVEC2", "FVEC3", + "FVEC4", "SAMPLER2DRECT", "SAMPLER3DRECT", "SAMPLER2DRECTSHADOW", + "SIZEOF", "CAST", "NAMESPACE", "USING", "ERROR_TOK", "COMMON", + "PARTITION", "ACTIVE", "SAMPLERBUFFER", "FILTER", "IMAGE1D", "IMAGE2D", + "IMAGE3D", "IMAGECUBE", "IMAGE1DARRAY", "IMAGE2DARRAY", "IIMAGE1D", + "IIMAGE2D", "IIMAGE3D", "IIMAGECUBE", "IIMAGE1DARRAY", "IIMAGE2DARRAY", + "UIMAGE1D", "UIMAGE2D", "UIMAGE3D", "UIMAGECUBE", "UIMAGE1DARRAY", + "UIMAGE2DARRAY", "IMAGE1DSHADOW", "IMAGE2DSHADOW", "IMAGEBUFFER", + "IIMAGEBUFFER", "UIMAGEBUFFER", "IMAGE1DARRAYSHADOW", + "IMAGE2DARRAYSHADOW", "ROW_MAJOR", "'('", "')'", "'['", "']'", "'.'", + "','", "'+'", "'-'", "'!'", "'~'", "'*'", "'/'", "'%'", "'<'", "'>'", + "'&'", "'^'", "'|'", "'?'", "':'", "'='", "';'", "'{'", "'}'", "$accept", + "translation_unit", "$@1", "version_statement", "pragma_statement", + "extension_statement_list", "any_identifier", "extension_statement", + "external_declaration_list", "variable_identifier", "primary_expression", + "postfix_expression", "integer_expression", "function_call", + "function_call_or_method", "function_call_generic", + "function_call_header_no_parameters", + "function_call_header_with_parameters", "function_call_header", + "function_identifier", "method_call_generic", + "method_call_header_no_parameters", "method_call_header_with_parameters", + "method_call_header", "unary_expression", "unary_operator", + "multiplicative_expression", "additive_expression", "shift_expression", + "relational_expression", "equality_expression", "and_expression", + "exclusive_or_expression", "inclusive_or_expression", + "logical_and_expression", "logical_xor_expression", + "logical_or_expression", "conditional_expression", + "assignment_expression", "assignment_operator", "expression", + "constant_expression", "declaration", "function_prototype", + "function_declarator", "function_header_with_parameters", + "function_header", "parameter_declarator", "parameter_declaration", + "parameter_qualifier", "parameter_type_specifier", + "init_declarator_list", "single_declaration", "fully_specified_type", + "layout_qualifier", "layout_qualifier_id_list", "layout_qualifier_id", + "interpolation_qualifier", "parameter_type_qualifier", "type_qualifier", + "storage_qualifier", "type_specifier", "type_specifier_no_prec", + "type_specifier_nonarray", "basic_type_specifier_nonarray", + "precision_qualifier", "struct_specifier", "struct_declaration_list", + "struct_declaration", "struct_declarator_list", "struct_declarator", + "initializer", "declaration_statement", "statement", "simple_statement", + "compound_statement", "$@2", "statement_no_new_scope", + "compound_statement_no_new_scope", "statement_list", + "expression_statement", "selection_statement", + "selection_rest_statement", "condition", "switch_statement", + "case_label", "iteration_statement", "for_init_statement", + "conditionopt", "for_rest_statement", "jump_statement", + "external_declaration", "function_definition", 0 +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const yytype_uint16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, + 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, + 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, + 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, + 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, + 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, + 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, + 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, + 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, + 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, + 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, + 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, + 445, 446, 447, 448, 449, 450, 40, 41, 91, 93, + 46, 44, 43, 45, 33, 126, 42, 47, 37, 60, + 62, 38, 94, 124, 63, 58, 61, 59, 123, 125 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint16 yyr1[] = +{ + 0, 220, 222, 221, 223, 223, 224, 224, 224, 224, + 224, 225, 225, 226, 226, 226, 227, 228, 228, 229, + 229, 230, 230, 230, 230, 230, 230, 231, 231, 231, + 231, 231, 231, 232, 233, 234, 234, 235, 235, 236, + 236, 237, 237, 238, 239, 239, 239, 240, 240, 241, + 241, 242, 242, 243, 244, 244, 244, 244, 245, 245, + 245, 245, 246, 246, 246, 246, 247, 247, 247, 248, + 248, 248, 249, 249, 249, 249, 249, 250, 250, 250, + 251, 251, 252, 252, 253, 253, 254, 254, 255, 255, + 256, 256, 257, 257, 258, 258, 259, 259, 259, 259, + 259, 259, 259, 259, 259, 259, 259, 260, 260, 261, + 262, 262, 262, 263, 264, 264, 265, 265, 266, 267, + 267, 268, 268, 268, 268, 269, 269, 269, 269, 270, + 271, 271, 271, 271, 271, 271, 271, 272, 272, 272, + 272, 272, 272, 272, 272, 273, 273, 274, 275, 275, + 276, 276, 277, 277, 277, 278, 279, 279, 279, 279, + 279, 279, 279, 279, 280, 280, 280, 280, 280, 280, + 280, 280, 280, 281, 281, 282, 282, 282, 283, 283, + 283, 284, 284, 284, 284, 284, 284, 284, 284, 284, + 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, + 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, + 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, + 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, + 284, 284, 285, 285, 285, 286, 286, 287, 287, 288, + 289, 289, 290, 290, 291, 292, 293, 293, 294, 294, + 294, 294, 294, 294, 294, 295, 296, 295, 297, 297, + 298, 298, 299, 299, 300, 300, 301, 302, 302, 303, + 303, 304, 305, 305, 306, 306, 306, 307, 307, 308, + 308, 309, 309, 310, 310, 310, 310, 310, 311, 311, + 311, 312 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = +{ + 0, 2, 0, 4, 0, 3, 2, 2, 2, 2, + 2, 0, 2, 1, 1, 1, 5, 1, 2, 1, + 1, 1, 1, 1, 1, 1, 3, 1, 4, 1, + 3, 2, 2, 1, 1, 1, 3, 2, 2, 2, + 1, 2, 3, 2, 1, 1, 1, 2, 2, 2, + 1, 2, 3, 2, 1, 2, 2, 2, 1, 1, + 1, 1, 1, 3, 3, 3, 1, 3, 3, 1, + 3, 3, 1, 3, 3, 3, 3, 1, 3, 3, + 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, + 1, 3, 1, 5, 1, 3, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, + 2, 2, 4, 2, 1, 1, 2, 3, 3, 2, + 5, 3, 2, 3, 2, 0, 1, 1, 1, 1, + 1, 3, 5, 6, 7, 8, 5, 1, 2, 4, + 5, 6, 7, 4, 2, 1, 2, 4, 1, 3, + 1, 3, 1, 1, 1, 1, 1, 1, 2, 1, + 2, 2, 3, 1, 1, 1, 1, 2, 1, 1, + 2, 2, 1, 1, 2, 1, 3, 4, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 5, 4, 1, 2, 3, + 1, 3, 1, 4, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 2, 0, 4, 1, 1, + 2, 3, 1, 2, 1, 2, 5, 3, 1, 1, + 4, 5, 3, 2, 5, 7, 6, 1, 1, 1, + 0, 2, 3, 2, 2, 2, 3, 2, 1, 1, + 1, 2 +}; + +/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state + STATE-NUM when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const yytype_uint16 yydefact[] = +{ + 4, 0, 0, 11, 0, 1, 2, 5, 0, 0, + 12, 13, 14, 15, 0, 165, 164, 185, 182, 183, + 184, 189, 190, 191, 192, 193, 194, 195, 196, 197, + 186, 187, 188, 0, 168, 169, 172, 166, 154, 153, + 152, 198, 199, 200, 201, 202, 203, 204, 205, 206, + 207, 208, 210, 211, 212, 213, 215, 216, 217, 218, + 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, + 229, 230, 231, 0, 181, 180, 163, 234, 233, 232, + 0, 0, 0, 0, 0, 0, 0, 209, 214, 290, + 3, 289, 0, 0, 115, 125, 0, 130, 137, 157, + 159, 0, 156, 145, 173, 175, 178, 0, 179, 17, + 288, 0, 170, 171, 167, 0, 0, 19, 20, 144, + 0, 161, 0, 6, 7, 8, 9, 10, 0, 18, + 110, 0, 291, 113, 125, 155, 126, 127, 128, 116, + 0, 125, 0, 111, 13, 15, 138, 0, 158, 160, + 146, 0, 174, 0, 0, 0, 237, 0, 162, 0, + 150, 0, 148, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 24, 22, 23, 25, 46, 0, + 0, 0, 58, 59, 60, 61, 264, 256, 260, 21, + 27, 54, 29, 34, 35, 0, 0, 40, 0, 62, + 0, 66, 69, 72, 77, 80, 82, 84, 86, 88, + 90, 92, 94, 107, 0, 245, 0, 145, 248, 262, + 247, 246, 0, 249, 250, 251, 252, 253, 254, 117, + 122, 124, 129, 0, 131, 0, 0, 118, 176, 62, + 109, 0, 44, 16, 242, 0, 240, 236, 238, 0, + 112, 0, 147, 0, 284, 283, 0, 0, 0, 287, + 285, 0, 0, 0, 273, 0, 55, 56, 0, 255, + 0, 31, 32, 0, 0, 38, 37, 0, 181, 41, + 43, 97, 98, 100, 99, 102, 103, 104, 105, 106, + 101, 96, 0, 57, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 265, 261, 263, 119, 121, + 123, 0, 0, 139, 0, 244, 143, 177, 0, 0, + 239, 235, 151, 149, 0, 278, 277, 280, 0, 286, + 0, 272, 163, 269, 0, 0, 26, 0, 0, 33, + 30, 0, 36, 0, 0, 50, 42, 95, 63, 64, + 65, 67, 68, 70, 71, 75, 76, 73, 74, 78, + 79, 81, 83, 85, 87, 89, 91, 0, 108, 0, + 132, 0, 136, 0, 140, 0, 241, 0, 279, 0, + 0, 0, 0, 0, 0, 257, 28, 53, 48, 47, + 0, 181, 51, 0, 0, 0, 133, 141, 0, 243, + 0, 281, 0, 268, 266, 271, 0, 259, 274, 258, + 52, 93, 120, 134, 0, 142, 0, 282, 276, 0, + 270, 135, 275, 267 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = +{ + -1, 2, 9, 3, 89, 6, 160, 10, 90, 189, + 190, 191, 348, 192, 193, 194, 195, 196, 197, 198, + 352, 353, 354, 355, 199, 200, 201, 202, 203, 204, + 205, 206, 207, 208, 209, 210, 211, 212, 213, 292, + 214, 241, 215, 216, 93, 94, 95, 230, 139, 140, + 231, 96, 97, 98, 99, 161, 162, 100, 141, 101, + 102, 242, 104, 105, 106, 107, 108, 155, 156, 245, + 246, 326, 218, 219, 220, 221, 270, 418, 419, 222, + 223, 224, 414, 345, 225, 226, 227, 337, 389, 390, + 228, 109, 110 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -366 +static const yytype_int16 yypact[] = +{ + -57, -43, 62, -366, -50, -366, -30, -366, 67, 3341, + -366, -366, -366, -366, -6, -366, -366, -366, -366, -366, + -366, -366, -366, -366, -366, -366, -366, -366, -366, -366, + -366, -366, -366, 8, -366, -366, -366, -366, -366, -366, + -366, -366, -366, -366, -366, -366, -366, -366, -366, -366, + -366, -366, -366, -366, -366, -366, -366, -366, -366, -366, + -366, -366, -366, -366, -366, -366, -366, -366, -366, -366, + -366, -366, -366, -65, -366, -366, 226, -366, -366, -366, + 51, -31, -28, 6, 13, 15, -44, -366, -366, -366, + 3341, -366, -183, -47, -29, 18, -169, -366, 140, 24, + 24, 3460, -366, -366, -366, -24, -366, 3533, -366, -366, + -366, 67, -366, -366, -366, 3460, -48, -366, -366, -366, + 24, -366, 3533, -366, -366, -366, -366, -366, 67, -366, + -366, 408, -366, -366, 55, -366, -366, -366, -366, -366, + 3460, 200, 67, -366, -20, -18, -178, 23, -366, -366, + -366, 2225, -366, 72, 67, 1598, -366, 3460, -366, 4, + 10, -84, -366, 11, 14, 1059, 40, 42, 29, 1836, + 43, 2783, 34, 54, -366, -366, -366, -366, -366, 2783, + 2783, 2783, -366, -366, -366, -366, -366, 32, -366, 56, + -366, -71, -366, -366, -366, 57, -81, 2969, 61, -27, + 2783, 35, -88, -41, -70, 33, 60, 41, 59, 181, + 180, -89, -366, -366, -168, -366, 58, 80, -366, -366, + -366, -366, 625, -366, -366, -366, -366, -366, -366, -366, + -366, -366, 67, 3460, -177, 2411, 2783, -366, -366, -366, + -366, 78, -366, -366, 81, -137, -366, -366, -366, 1717, + -366, 201, -366, 67, -366, -366, 205, 1478, 2783, -366, + -366, -134, 2783, -115, -366, 2039, -366, -366, -60, -366, + 1059, -366, -366, 2783, 140, -366, -366, 2783, 85, -366, + -366, -366, -366, -366, -366, -366, -366, -366, -366, -366, + -366, -366, 2783, -366, 2783, 2783, 2783, 2783, 2783, 2783, + 2783, 2783, 2783, 2783, 2783, 2783, 2783, 2783, 2783, 2783, + 2783, 2783, 2783, 2783, 2783, -366, -366, -366, 86, -366, + -366, 2597, 2783, 69, 87, -366, -366, -366, 2783, 67, + -366, -366, -366, -366, 91, -366, -366, 2039, -59, -366, + -46, -366, 129, 88, 67, 93, -366, 842, 89, 88, + -366, 95, -366, 96, -37, 3155, -366, -366, -366, -366, + -366, 35, 35, -88, -88, -41, -41, -41, -41, -70, + -70, 33, 60, 41, 59, 181, 180, -96, -366, 2783, + 76, 97, -366, 2783, 79, 98, -366, 2783, -366, 77, + 101, 1059, 83, 90, 1275, -366, -366, -366, -366, -366, + 2783, 102, -366, 2783, 108, 2783, 94, -366, 2783, -366, + -26, 2783, 1275, 297, -366, -366, 2783, -366, -366, -366, + -366, -366, -366, -366, 2783, -366, 100, 88, -366, 1059, + -366, -366, -366, -366 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int16 yypgoto[] = +{ + -366, -366, -366, -366, -366, -366, -7, -366, -366, -62, + -366, -366, -366, -366, -366, -366, -366, -366, -366, -366, + -366, -366, -366, -366, -101, -366, -113, -109, -121, -61, + 5, 3, 9, 16, 2, 7, -366, -142, -100, -366, + -164, -225, 21, 22, -366, -366, -366, 82, 186, 173, + 92, -366, -366, -242, -366, -366, 68, -73, -366, -366, + -74, -9, -67, -366, -366, 243, -366, 170, -147, -366, + 0, -298, 73, -159, -365, -58, -366, -80, 239, 63, + 84, -366, -366, -2, -366, -366, -366, -366, -366, -366, + -366, 246, -366 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. + If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -115 +static const yytype_int16 yytable[] = +{ + 103, 14, 121, 120, 312, 261, 256, 263, 248, 240, + 324, 11, 12, 13, 119, 271, 272, 268, 301, 302, + 235, 321, 135, 344, 382, 148, 149, 15, 16, 417, + 91, 92, 142, 314, 130, 131, 147, 4, 236, 322, + 152, 112, 113, 299, 300, 114, 158, 417, 143, 315, + 239, 136, 137, 138, 1, 159, 33, 34, 35, 135, + 36, 37, 5, 317, 329, 7, 116, 314, 281, 282, + 283, 284, 285, 286, 287, 288, 289, 290, 266, 267, + 330, 103, 8, 339, 123, 407, 314, 124, 136, 137, + 138, 146, 150, 240, 338, 344, 381, 279, 340, 293, + 341, 343, 248, 385, 153, 314, 154, 423, 111, 349, + 425, 91, 92, 252, 297, 298, 276, 253, 430, 403, + 277, 125, 217, 305, 306, 313, 431, 273, 126, 274, + 127, 232, 15, 16, 239, 234, 325, 346, 391, 303, + 304, 314, 314, 11, 12, 13, 154, 244, 154, 377, + 133, 392, 128, 115, 404, 314, 217, 77, 78, 79, + 399, 33, 34, 35, 400, 36, 37, 38, 39, 40, + 157, 426, 134, 343, 151, 314, -19, 356, -20, 240, + 365, 366, 367, 368, 361, 362, 240, 243, 317, 291, + 363, 364, 357, 358, 359, 360, 239, 239, 239, 239, + 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, + 239, 239, 351, 217, 378, -114, 144, 12, 145, 237, + 239, 250, 325, 410, 232, 318, 251, 239, 254, 15, + 16, 255, 413, 136, 137, 138, 257, 240, 258, 262, + 154, 294, 295, 296, 369, 370, 259, 427, 217, 264, + 265, 269, -45, 308, 275, 402, 217, 280, 33, 34, + 35, 217, 36, 37, 38, 39, 40, 350, 121, 120, + 433, 307, 309, 310, 311, 130, -44, 327, 239, 328, + 334, 332, -39, 325, 379, 383, 384, 387, 396, 314, + 394, 397, 405, 398, 411, 408, 406, 409, 412, -49, + 420, 187, 117, 421, 118, 325, 416, 422, 325, 429, + 424, 372, 371, 375, 233, 319, 325, 432, 373, 376, + 229, 333, 244, 122, 325, 320, 374, 249, 217, 386, + 335, 132, 428, 347, 415, 388, 129, 393, 217, 0, + 0, 336, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 217, 0, 0, 217, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 217, 0, 0, 0, 0, 0, 0, + 0, 15, 16, 17, 18, 19, 20, 163, 164, 165, + 217, 166, 167, 168, 169, 170, 171, 172, 21, 22, + 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 0, 36, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 173, 117, 75, 118, 174, 175, 176, + 177, 178, 0, 0, 179, 180, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 76, 77, 78, 79, 0, 80, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 86, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 87, 0, 88, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 181, 0, 0, 0, 0, 0, + 182, 183, 184, 185, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 186, 187, 188, 15, 16, + 17, 18, 19, 20, 163, 164, 165, 0, 166, 167, + 168, 169, 170, 171, 172, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 0, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 173, 117, 75, 118, 174, 175, 176, 177, 178, 0, + 0, 179, 180, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 76, 77, 78, 79, 0, 80, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 86, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 87, 0, 88, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 181, 0, 0, 0, 0, 0, 182, 183, 184, + 185, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 186, 187, 316, 15, 16, 17, 18, 19, + 20, 163, 164, 165, 0, 166, 167, 168, 169, 170, + 171, 172, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 0, 36, 37, + 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, + 68, 69, 70, 71, 72, 73, 74, 173, 117, 75, + 118, 174, 175, 176, 177, 178, 0, 0, 179, 180, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 76, 77, 78, + 79, 0, 80, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 86, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 87, + 0, 88, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 181, 0, + 0, 0, 0, 0, 182, 183, 184, 185, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 186, + 187, 395, 15, 16, 17, 18, 19, 20, 163, 164, + 165, 0, 166, 167, 168, 169, 170, 171, 172, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 0, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, 74, 173, 117, 75, 118, 174, 175, + 176, 177, 178, 0, 0, 179, 180, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 76, 77, 78, 79, 0, 80, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 86, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 87, 0, 88, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 181, 0, 0, 0, 0, + 0, 182, 183, 184, 185, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 186, 187, 15, 16, + 17, 18, 19, 20, 163, 164, 165, 0, 166, 167, + 168, 169, 170, 171, 172, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 0, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 173, 117, 75, 118, 174, 175, 176, 177, 178, 0, + 0, 179, 180, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 76, 77, 78, 79, 0, 80, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 86, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 87, 0, 88, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 181, 0, 0, 0, 0, 0, 182, 183, 184, + 185, 15, 16, 17, 18, 19, 20, 0, 0, 0, + 0, 0, 186, 131, 0, 0, 0, 0, 21, 22, + 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 0, 36, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 0, 117, 75, 118, 174, 175, 176, + 177, 178, 0, 0, 179, 180, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 76, 77, 78, 79, 0, 80, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 86, 0, 17, 18, 19, 20, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 21, 22, + 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + 0, 0, 0, 0, 0, 87, 0, 88, 0, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 0, 181, 75, 0, 0, 0, 0, + 182, 183, 184, 185, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 186, 0, 0, 0, 0, + 0, 0, 0, 0, 77, 78, 79, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 17, 18, 19, 20, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 0, + 0, 0, 0, 0, 0, 87, 0, 88, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, + 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, + 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 0, 0, 75, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 247, 0, 0, + 0, 0, 0, 77, 78, 79, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 17, 18, 19, 20, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 0, 0, + 0, 0, 0, 0, 87, 0, 88, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, + 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, + 74, 0, 117, 75, 118, 174, 175, 176, 177, 178, + 0, 0, 179, 180, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 331, 0, 0, 0, + 0, 0, 77, 78, 79, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 87, 0, 88, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 181, 0, 0, 0, 0, 0, 182, 183, + 184, 185, 15, 16, 17, 18, 19, 20, 0, 0, + 0, 0, 0, 260, 0, 0, 0, 0, 0, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 0, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, 74, 0, 117, 75, 118, 174, 175, + 176, 177, 178, 0, 0, 179, 180, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 342, 77, 78, 79, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 86, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 87, 0, 88, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 17, 18, 19, 20, 0, 181, 0, 0, 0, 0, + 0, 182, 183, 184, 185, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 0, 117, 75, 118, 174, 175, 176, 177, 178, 0, + 0, 179, 180, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 77, 78, 79, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 87, 0, 88, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 17, 18, 19, 20, + 0, 181, 0, 0, 238, 0, 0, 182, 183, 184, + 185, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, + 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, + 69, 70, 71, 72, 73, 74, 0, 117, 75, 118, + 174, 175, 176, 177, 178, 0, 0, 179, 180, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 77, 78, 79, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 87, 0, + 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 17, 18, 19, 20, 0, 181, 0, 0, + 323, 0, 0, 182, 183, 184, 185, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, + 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, + 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 0, 117, 75, 118, 174, 175, 176, 177, + 178, 0, 0, 179, 180, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 77, 78, 79, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 87, 0, 88, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 17, 18, + 19, 20, 0, 181, 0, 0, 380, 0, 0, 182, + 183, 184, 185, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 41, 42, 43, 44, 45, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, + 67, 68, 69, 70, 71, 72, 73, 74, 0, 117, + 75, 118, 174, 175, 176, 177, 178, 0, 0, 179, + 180, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, + 78, 79, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 87, 0, 88, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 17, 18, 19, 20, 0, 181, + 0, 0, 0, 0, 0, 182, 183, 184, 185, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, 278, 0, 117, 75, 118, 174, 175, + 176, 177, 178, 0, 0, 179, 180, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 77, 78, 79, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 87, 0, 88, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 17, 18, 19, 20, 0, 181, 0, 0, 0, 0, + 0, 182, 183, 184, 185, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 401, + 0, 117, 75, 118, 174, 175, 176, 177, 178, 0, + 0, 179, 180, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 77, 78, 79, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 87, 0, 88, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 15, 16, 17, 18, 19, 20, + 0, 181, 0, 0, 0, 0, 0, 182, 183, 184, + 185, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 0, 36, 37, 38, + 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, + 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, + 69, 70, 71, 72, 73, 74, 0, 0, 75, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 76, 77, 78, 79, + 0, 80, 0, 0, 0, 0, 0, 0, 0, 81, + 82, 83, 84, 85, 86, 17, 18, 19, 20, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 0, 0, 0, 0, 0, 0, 87, 0, + 88, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 72, 73, 74, 0, 0, 75, 17, 18, + 19, 20, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 0, 77, 78, 79, 0, + 0, 0, 0, 0, 41, 42, 43, 44, 45, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, + 67, 68, 69, 70, 71, 72, 73, 74, 0, 0, + 75, 0, 0, 0, 0, 0, 0, 87, 0, 88, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 87, 0, 88 +}; + +static const yytype_int16 yycheck[] = +{ + 9, 8, 76, 76, 93, 169, 165, 171, 155, 151, + 235, 76, 77, 78, 76, 86, 87, 181, 88, 89, + 198, 198, 4, 265, 322, 99, 100, 3, 4, 394, + 9, 9, 201, 201, 217, 218, 98, 80, 216, 216, + 107, 33, 34, 84, 85, 37, 120, 412, 217, 217, + 151, 33, 34, 35, 111, 122, 32, 33, 34, 4, + 36, 37, 0, 222, 201, 115, 73, 201, 95, 96, + 97, 98, 99, 100, 101, 102, 103, 104, 179, 180, + 217, 90, 112, 217, 115, 383, 201, 115, 33, 34, + 35, 98, 101, 235, 258, 337, 321, 197, 262, 200, + 215, 265, 249, 328, 111, 201, 115, 405, 114, 273, + 408, 90, 90, 197, 202, 203, 197, 201, 416, 215, + 201, 115, 131, 90, 91, 214, 424, 198, 115, 200, + 115, 140, 3, 4, 235, 142, 236, 197, 197, 209, + 210, 201, 201, 76, 77, 78, 155, 154, 157, 313, + 197, 197, 196, 218, 379, 201, 165, 106, 107, 108, + 197, 32, 33, 34, 201, 36, 37, 38, 39, 40, + 218, 197, 201, 337, 198, 201, 196, 277, 196, 321, + 301, 302, 303, 304, 297, 298, 328, 115, 347, 216, + 299, 300, 292, 294, 295, 296, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 274, 222, 314, 197, 76, 77, 78, 196, + 321, 217, 322, 387, 233, 232, 216, 328, 217, 3, + 4, 217, 391, 33, 34, 35, 196, 379, 196, 196, + 249, 206, 207, 208, 305, 306, 217, 411, 257, 215, + 196, 219, 196, 212, 197, 355, 265, 196, 32, 33, + 34, 270, 36, 37, 38, 39, 40, 274, 342, 342, + 429, 211, 213, 92, 94, 217, 196, 199, 379, 198, + 75, 80, 197, 383, 198, 216, 199, 196, 199, 201, + 197, 196, 216, 197, 217, 216, 199, 199, 197, 197, + 400, 218, 76, 403, 78, 405, 216, 199, 408, 12, + 216, 308, 307, 311, 141, 233, 416, 217, 309, 312, + 134, 253, 329, 80, 424, 233, 310, 157, 337, 329, + 257, 92, 412, 270, 392, 337, 90, 344, 347, -1, + -1, 257, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 391, -1, -1, 394, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 412, -1, -1, -1, -1, -1, -1, + -1, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 429, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, -1, 36, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, + 82, 83, -1, -1, 86, 87, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 105, 106, 107, 108, -1, 110, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 123, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 157, -1, 159, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 196, -1, -1, -1, -1, -1, + 202, 203, 204, 205, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 217, 218, 219, 3, 4, + 5, 6, 7, 8, 9, 10, 11, -1, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + -1, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 75, 76, 77, 78, 79, 80, 81, 82, 83, -1, + -1, 86, 87, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 105, 106, 107, 108, -1, 110, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 123, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 157, -1, 159, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 196, -1, -1, -1, -1, -1, 202, 203, 204, + 205, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 217, 218, 219, 3, 4, 5, 6, 7, + 8, 9, 10, 11, -1, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, -1, 36, 37, + 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, + 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, + 78, 79, 80, 81, 82, 83, -1, -1, 86, 87, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 105, 106, 107, + 108, -1, 110, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 123, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 157, + -1, 159, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 196, -1, + -1, -1, -1, -1, 202, 203, 204, 205, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 217, + 218, 219, 3, 4, 5, 6, 7, 8, 9, 10, + 11, -1, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 34, -1, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, + 81, 82, 83, -1, -1, 86, 87, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 105, 106, 107, 108, -1, 110, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 123, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 157, -1, 159, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 196, -1, -1, -1, -1, + -1, 202, 203, 204, 205, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 217, 218, 3, 4, + 5, 6, 7, 8, 9, 10, 11, -1, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + -1, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 75, 76, 77, 78, 79, 80, 81, 82, 83, -1, + -1, 86, 87, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 105, 106, 107, 108, -1, 110, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 123, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 157, -1, 159, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 196, -1, -1, -1, -1, -1, 202, 203, 204, + 205, 3, 4, 5, 6, 7, 8, -1, -1, -1, + -1, -1, 217, 218, -1, -1, -1, -1, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, -1, 36, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, -1, 76, 77, 78, 79, 80, 81, + 82, 83, -1, -1, 86, 87, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 105, 106, 107, 108, -1, 110, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 123, -1, 5, 6, 7, 8, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + -1, -1, -1, -1, -1, 157, -1, 159, -1, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, -1, 196, 77, -1, -1, -1, -1, + 202, 203, 204, 205, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 217, -1, -1, -1, -1, + -1, -1, -1, -1, 106, 107, 108, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 5, 6, 7, 8, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29, 30, 31, -1, + -1, -1, -1, -1, -1, 157, -1, 159, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, + 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, + 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, -1, -1, 77, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 219, -1, -1, + -1, -1, -1, 106, 107, 108, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 5, 6, 7, 8, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, -1, -1, + -1, -1, -1, -1, 157, -1, 159, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, + 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, + 74, -1, 76, 77, 78, 79, 80, 81, 82, 83, + -1, -1, 86, 87, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 219, -1, -1, -1, + -1, -1, 106, 107, 108, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 157, -1, 159, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 196, -1, -1, -1, -1, -1, 202, 203, + 204, 205, 3, 4, 5, 6, 7, 8, -1, -1, + -1, -1, -1, 217, -1, -1, -1, -1, -1, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 34, -1, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, 74, -1, 76, 77, 78, 79, 80, + 81, 82, 83, -1, -1, 86, 87, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 105, 106, 107, 108, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 123, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 157, -1, 159, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 5, 6, 7, 8, -1, 196, -1, -1, -1, -1, + -1, 202, 203, 204, 205, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + -1, 76, 77, 78, 79, 80, 81, 82, 83, -1, + -1, 86, 87, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 106, 107, 108, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 157, -1, 159, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 5, 6, 7, 8, + -1, 196, -1, -1, 199, -1, -1, 202, 203, 204, + 205, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, + 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, + 69, 70, 71, 72, 73, 74, -1, 76, 77, 78, + 79, 80, 81, 82, 83, -1, -1, 86, 87, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 106, 107, 108, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 157, -1, + 159, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 5, 6, 7, 8, -1, 196, -1, -1, + 199, -1, -1, 202, 203, 204, 205, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29, 30, 31, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, + 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, + 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, -1, 76, 77, 78, 79, 80, 81, 82, + 83, -1, -1, 86, 87, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 106, 107, 108, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 157, -1, 159, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 5, 6, + 7, 8, -1, 196, -1, -1, 199, -1, -1, 202, + 203, 204, 205, 20, 21, 22, 23, 24, 25, 26, + 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 41, 42, 43, 44, 45, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, + 67, 68, 69, 70, 71, 72, 73, 74, -1, 76, + 77, 78, 79, 80, 81, 82, 83, -1, -1, 86, + 87, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 106, + 107, 108, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 157, -1, 159, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 5, 6, 7, 8, -1, 196, + -1, -1, -1, -1, -1, 202, 203, 204, 205, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, 74, -1, 76, 77, 78, 79, 80, + 81, 82, 83, -1, -1, 86, 87, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 106, 107, 108, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 157, -1, 159, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 5, 6, 7, 8, -1, 196, -1, -1, -1, -1, + -1, 202, 203, 204, 205, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + -1, 76, 77, 78, 79, 80, 81, 82, 83, -1, + -1, 86, 87, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 106, 107, 108, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 157, -1, 159, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 3, 4, 5, 6, 7, 8, + -1, 196, -1, -1, -1, -1, -1, 202, 203, 204, + 205, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, -1, 36, 37, 38, + 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, + 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, + 69, 70, 71, 72, 73, 74, -1, -1, 77, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 105, 106, 107, 108, + -1, 110, -1, -1, -1, -1, -1, -1, -1, 118, + 119, 120, 121, 122, 123, 5, 6, 7, 8, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, -1, -1, -1, -1, -1, -1, 157, -1, + 159, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 72, 73, 74, -1, -1, 77, 5, 6, + 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 20, 21, 22, 23, 24, 25, 26, + 27, 28, 29, 30, 31, -1, 106, 107, 108, -1, + -1, -1, -1, -1, 41, 42, 43, 44, 45, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, + 67, 68, 69, 70, 71, 72, 73, 74, -1, -1, + 77, -1, -1, -1, -1, -1, -1, 157, -1, 159, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 157, -1, 159 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint16 yystos[] = +{ + 0, 111, 221, 223, 80, 0, 225, 115, 112, 222, + 227, 76, 77, 78, 226, 3, 4, 5, 6, 7, + 8, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 72, 73, 74, 77, 105, 106, 107, 108, + 110, 118, 119, 120, 121, 122, 123, 157, 159, 224, + 228, 262, 263, 264, 265, 266, 271, 272, 273, 274, + 277, 279, 280, 281, 282, 283, 284, 285, 286, 311, + 312, 114, 33, 34, 37, 218, 226, 76, 78, 229, + 277, 280, 285, 115, 115, 115, 115, 115, 196, 311, + 217, 218, 298, 197, 201, 4, 33, 34, 35, 268, + 269, 278, 201, 217, 76, 78, 226, 229, 280, 280, + 281, 198, 282, 226, 281, 287, 288, 218, 280, 282, + 226, 275, 276, 9, 10, 11, 13, 14, 15, 16, + 17, 18, 19, 75, 79, 80, 81, 82, 83, 86, + 87, 196, 202, 203, 204, 205, 217, 218, 219, 229, + 230, 231, 233, 234, 235, 236, 237, 238, 239, 244, + 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, + 255, 256, 257, 258, 260, 262, 263, 281, 292, 293, + 294, 295, 299, 300, 301, 304, 305, 306, 310, 268, + 267, 270, 281, 269, 226, 198, 216, 196, 199, 244, + 257, 261, 281, 115, 226, 289, 290, 219, 288, 287, + 217, 216, 197, 201, 217, 217, 293, 196, 196, 217, + 217, 260, 196, 260, 215, 196, 244, 244, 260, 219, + 296, 86, 87, 198, 200, 197, 197, 201, 74, 258, + 196, 95, 96, 97, 98, 99, 100, 101, 102, 103, + 104, 216, 259, 244, 206, 207, 208, 202, 203, 84, + 85, 88, 89, 209, 210, 90, 91, 211, 212, 213, + 92, 94, 93, 214, 201, 217, 219, 293, 226, 267, + 270, 198, 216, 199, 261, 258, 291, 199, 198, 201, + 217, 219, 80, 276, 75, 292, 300, 307, 260, 217, + 260, 215, 105, 260, 273, 303, 197, 299, 232, 260, + 226, 229, 240, 241, 242, 243, 258, 258, 244, 244, + 244, 246, 246, 247, 247, 248, 248, 248, 248, 249, + 249, 250, 251, 252, 253, 254, 255, 260, 258, 198, + 199, 261, 291, 216, 199, 261, 290, 196, 303, 308, + 309, 197, 197, 226, 197, 219, 199, 196, 197, 197, + 201, 74, 258, 215, 261, 216, 199, 291, 216, 199, + 260, 217, 197, 293, 302, 295, 216, 294, 297, 298, + 258, 258, 199, 291, 216, 291, 197, 260, 297, 12, + 291, 291, 217, 293 +}; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. However, + YYFAIL appears to be in use. Nevertheless, it is formally deprecated + in Bison 2.4.2's NEWS entry, where a plan to phase it out is + discussed. */ + +#define YYFAIL goto yyerrlab +#if defined YYFAIL + /* This is here to suppress warnings from the GCC cpp's + -Wunused-macros. Normally we don't worry about that warning, but + some users do, and we want to make it easy for users to remove + YYFAIL uses, which will produce warnings from Bison 2.5. */ +#endif + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + yytoken = YYTRANSLATE (yychar); \ + YYPOPSTACK (1); \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (&yylloc, state, YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ +while (YYID (0)) + + +#define YYTERROR 1 +#define YYERRCODE 256 + + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (YYID (0)) +#endif + + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#ifndef YY_LOCATION_PRINT +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +#endif + + +/* YYLEX -- calling `yylex' with the right arguments. */ + +#ifdef YYLEX_PARAM +# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) +#else +# define YYLEX yylex (&yylval, &yylloc, scanner) +#endif + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (YYID (0)) + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value, Location, state); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (YYID (0)) + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, struct _mesa_glsl_parse_state *state) +#else +static void +yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, state) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; + YYLTYPE const * const yylocationp; + struct _mesa_glsl_parse_state *state; +#endif +{ + if (!yyvaluep) + return; + YYUSE (yylocationp); + YYUSE (state); +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# else + YYUSE (yyoutput); +# endif + switch (yytype) + { + default: + break; + } +} + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, struct _mesa_glsl_parse_state *state) +#else +static void +yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, state) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; + YYLTYPE const * const yylocationp; + struct _mesa_glsl_parse_state *state; +#endif +{ + if (yytype < YYNTOKENS) + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + YY_LOCATION_PRINT (yyoutput, *yylocationp); + YYFPRINTF (yyoutput, ": "); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, state); + YYFPRINTF (yyoutput, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +#else +static void +yy_stack_print (yybottom, yytop) + yytype_int16 *yybottom; + yytype_int16 *yytop; +#endif +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (YYID (0)) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, struct _mesa_glsl_parse_state *state) +#else +static void +yy_reduce_print (yyvsp, yylsp, yyrule, state) + YYSTYPE *yyvsp; + YYLTYPE *yylsp; + int yyrule; + struct _mesa_glsl_parse_state *state; +#endif +{ + int yynrhs = yyr2[yyrule]; + int yyi; + unsigned long int yylno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], + &(yyvsp[(yyi + 1) - (yynrhs)]) + , &(yylsp[(yyi + 1) - (yynrhs)]) , state); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyvsp, yylsp, Rule, state); \ +} while (YYID (0)) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static YYSIZE_T +yystrlen (const char *yystr) +#else +static YYSIZE_T +yystrlen (yystr) + const char *yystr; +#endif +{ + YYSIZE_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; +} +# endif +# endif + +# ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static char * +yystpcpy (char *yydest, const char *yysrc) +#else +static char * +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +#endif +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYSIZE_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYSIZE_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return yystrlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +/* Copy into YYRESULT an error message about the unexpected token + YYCHAR while in state YYSTATE. Return the number of bytes copied, + including the terminating null byte. If YYRESULT is null, do not + copy anything; just return the number of bytes that would be + copied. As a special case, return 0 if an ordinary "syntax error" + message will do. Return YYSIZE_MAXIMUM if overflow occurs during + size calculation. */ +static YYSIZE_T +yysyntax_error (char *yyresult, int yystate, int yychar) +{ + int yyn = yypact[yystate]; + + if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) + return 0; + else + { + int yytype = YYTRANSLATE (yychar); + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + int yysize_overflow = 0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + int yyx; + +# if 0 + /* This is so xgettext sees the translatable formats that are + constructed on the fly. */ + YY_("syntax error, unexpected %s"); + YY_("syntax error, unexpected %s, expecting %s"); + YY_("syntax error, unexpected %s, expecting %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); +# endif + char *yyfmt; + char const *yyf; + static char const yyunexpected[] = "syntax error, unexpected %s"; + static char const yyexpecting[] = ", expecting %s"; + static char const yyor[] = " or %s"; + char yyformat[sizeof yyunexpected + + sizeof yyexpecting - 1 + + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) + * (sizeof yyor - 1))]; + char const *yyprefix = yyexpecting; + + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yycount = 1; + + yyarg[0] = yytname[yytype]; + yyfmt = yystpcpy (yyformat, yyunexpected); + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + yyformat[sizeof yyunexpected - 1] = '\0'; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + yyfmt = yystpcpy (yyfmt, yyprefix); + yyprefix = yyor; + } + + yyf = YY_(yyformat); + yysize1 = yysize + yystrlen (yyf); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + + if (yysize_overflow) + return YYSIZE_MAXIMUM; + + if (yyresult) + { + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + char *yyp = yyresult; + int yyi = 0; + while ((*yyp = *yyf) != '\0') + { + if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyf += 2; + } + else + { + yyp++; + yyf++; + } + } + } + return yysize; + } +} +#endif /* YYERROR_VERBOSE */ + + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, struct _mesa_glsl_parse_state *state) +#else +static void +yydestruct (yymsg, yytype, yyvaluep, yylocationp, state) + const char *yymsg; + int yytype; + YYSTYPE *yyvaluep; + YYLTYPE *yylocationp; + struct _mesa_glsl_parse_state *state; +#endif +{ + YYUSE (yyvaluep); + YYUSE (yylocationp); + YYUSE (state); + + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + + default: + break; + } +} + +/* Prevent warnings from -Wmissing-prototypes. */ +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (struct _mesa_glsl_parse_state *state); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + + + + + +/*-------------------------. +| yyparse or yypush_parse. | +`-------------------------*/ + +#ifdef YYPARSE_PARAM +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void *YYPARSE_PARAM) +#else +int +yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +#endif +#else /* ! YYPARSE_PARAM */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (struct _mesa_glsl_parse_state *state) +#else +int +yyparse (state) + struct _mesa_glsl_parse_state *state; +#endif +#endif +{ +/* The lookahead symbol. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; + +/* Location data for the lookahead symbol. */ +YYLTYPE yylloc; + + /* Number of syntax errors so far. */ + int yynerrs; + + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + + /* The stacks and their tools: + `yyss': related to states. + `yyvs': related to semantic values. + `yyls': related to locations. + + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + /* The location stack. */ + YYLTYPE yylsa[YYINITDEPTH]; + YYLTYPE *yyls; + YYLTYPE *yylsp; + + /* The locations where the error started and ended. */ + YYLTYPE yyerror_range[3]; + + YYSIZE_T yystacksize; + + int yyn; + int yyresult; + /* Lookahead token as an internal (translated) token number. */ + int yytoken; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + YYLTYPE yyloc; + +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYSIZE_T yymsg_alloc = sizeof yymsgbuf; +#endif + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + yytoken = 0; + yyss = yyssa; + yyvs = yyvsa; + yyls = yylsa; + yystacksize = YYINITDEPTH; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + yyssp = yyss; + yyvsp = yyvs; + yylsp = yyls; + +#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + /* Initialize the default location before parsing starts. */ + yylloc.first_line = yylloc.last_line = 1; + yylloc.first_column = yylloc.last_column = 1; +#endif + +/* User initialization code. */ + +/* Line 1251 of yacc.c */ +#line 41 "glsl_parser.ypp" +{ + yylloc.first_line = 1; + yylloc.first_column = 1; + yylloc.last_line = 1; + yylloc.last_column = 1; + yylloc.source = 0; +} + +/* Line 1251 of yacc.c */ +#line 2657 "glsl_parser.cpp" + yylsp[0] = yylloc; + + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + YYLTYPE *yyls1 = yyls; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yyls1, yysize * sizeof (*yylsp), + &yystacksize); + + yyls = yyls1; + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); + YYSTACK_RELOCATE (yyls_alloc, yyls); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + yylsp = yyls + yysize - 1; + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yyn == YYPACT_NINF) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yyn == 0 || yyn == YYTABLE_NINF) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the shifted token. */ + yychar = YYEMPTY; + + yystate = yyn; + *++yyvsp = yylval; + *++yylsp = yylloc; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + /* Default location. */ + YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 2: + +/* Line 1464 of yacc.c */ +#line 218 "glsl_parser.ypp" + { + _mesa_glsl_initialize_types(state); + ;} + break; + + case 3: + +/* Line 1464 of yacc.c */ +#line 222 "glsl_parser.ypp" + { + delete state->symbols; + state->symbols = new(ralloc_parent(state)) glsl_symbol_table; + _mesa_glsl_initialize_types(state); + ;} + break; + + case 5: + +/* Line 1464 of yacc.c */ +#line 232 "glsl_parser.ypp" + { + bool supported = false; + + switch ((yyvsp[(2) - (3)].n)) { + case 100: + state->es_shader = true; + supported = state->Const.GLSL_100ES; + break; + case 110: + supported = state->Const.GLSL_110; + break; + case 120: + supported = state->Const.GLSL_120; + break; + case 130: + supported = state->Const.GLSL_130; + break; + default: + supported = false; + break; + } + + state->language_version = (yyvsp[(2) - (3)].n); + state->version_string = + ralloc_asprintf(state, "GLSL%s %d.%02d", + state->es_shader ? " ES" : "", + state->language_version / 100, + state->language_version % 100); + + if (!supported) { + _mesa_glsl_error(& (yylsp[(2) - (3)]), state, "%s is not supported. " + "Supported versions are: %s\n", + state->version_string, + state->supported_version_string); + } + ;} + break; + + case 10: + +/* Line 1464 of yacc.c */ +#line 276 "glsl_parser.ypp" + { + if (state->language_version < 120) { + _mesa_glsl_warning(& (yylsp[(1) - (2)]), state, + "pragma `invariant(all)' not supported in %s", + state->version_string); + } else { + state->all_invariant = true; + } + ;} + break; + + case 16: + +/* Line 1464 of yacc.c */ +#line 300 "glsl_parser.ypp" + { + if (!_mesa_glsl_process_extension((yyvsp[(2) - (5)].identifier), & (yylsp[(2) - (5)]), (yyvsp[(4) - (5)].identifier), & (yylsp[(4) - (5)]), state)) { + YYERROR; + } + ;} + break; + + case 17: + +/* Line 1464 of yacc.c */ +#line 309 "glsl_parser.ypp" + { + /* FINISHME: The NULL test is required because pragmas are set to + * FINISHME: NULL. (See production rule for external_declaration.) + */ + if ((yyvsp[(1) - (1)].node) != NULL) + state->translation_unit.push_tail(& (yyvsp[(1) - (1)].node)->link); + ;} + break; + + case 18: + +/* Line 1464 of yacc.c */ +#line 317 "glsl_parser.ypp" + { + /* FINISHME: The NULL test is required because pragmas are set to + * FINISHME: NULL. (See production rule for external_declaration.) + */ + if ((yyvsp[(2) - (2)].node) != NULL) + state->translation_unit.push_tail(& (yyvsp[(2) - (2)].node)->link); + ;} + break; + + case 21: + +/* Line 1464 of yacc.c */ +#line 333 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL); + (yyval.expression)->set_location(yylloc); + (yyval.expression)->primary_expression.identifier = (yyvsp[(1) - (1)].identifier); + ;} + break; + + case 22: + +/* Line 1464 of yacc.c */ +#line 340 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL); + (yyval.expression)->set_location(yylloc); + (yyval.expression)->primary_expression.int_constant = (yyvsp[(1) - (1)].n); + ;} + break; + + case 23: + +/* Line 1464 of yacc.c */ +#line 347 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL); + (yyval.expression)->set_location(yylloc); + (yyval.expression)->primary_expression.uint_constant = (yyvsp[(1) - (1)].n); + ;} + break; + + case 24: + +/* Line 1464 of yacc.c */ +#line 354 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL); + (yyval.expression)->set_location(yylloc); + (yyval.expression)->primary_expression.float_constant = (yyvsp[(1) - (1)].real); + ;} + break; + + case 25: + +/* Line 1464 of yacc.c */ +#line 361 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL); + (yyval.expression)->set_location(yylloc); + (yyval.expression)->primary_expression.bool_constant = (yyvsp[(1) - (1)].n); + ;} + break; + + case 26: + +/* Line 1464 of yacc.c */ +#line 368 "glsl_parser.ypp" + { + (yyval.expression) = (yyvsp[(2) - (3)].expression); + ;} + break; + + case 28: + +/* Line 1464 of yacc.c */ +#line 376 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression(ast_array_index, (yyvsp[(1) - (4)].expression), (yyvsp[(3) - (4)].expression), NULL); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 29: + +/* Line 1464 of yacc.c */ +#line 382 "glsl_parser.ypp" + { + (yyval.expression) = (yyvsp[(1) - (1)].expression); + ;} + break; + + case 30: + +/* Line 1464 of yacc.c */ +#line 386 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression(ast_field_selection, (yyvsp[(1) - (3)].expression), NULL, NULL); + (yyval.expression)->set_location(yylloc); + (yyval.expression)->primary_expression.identifier = (yyvsp[(3) - (3)].identifier); + ;} + break; + + case 31: + +/* Line 1464 of yacc.c */ +#line 393 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression(ast_post_inc, (yyvsp[(1) - (2)].expression), NULL, NULL); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 32: + +/* Line 1464 of yacc.c */ +#line 399 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression(ast_post_dec, (yyvsp[(1) - (2)].expression), NULL, NULL); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 36: + +/* Line 1464 of yacc.c */ +#line 417 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression(ast_field_selection, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression), NULL); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 41: + +/* Line 1464 of yacc.c */ +#line 436 "glsl_parser.ypp" + { + (yyval.expression) = (yyvsp[(1) - (2)].expression); + (yyval.expression)->set_location(yylloc); + (yyval.expression)->expressions.push_tail(& (yyvsp[(2) - (2)].expression)->link); + ;} + break; + + case 42: + +/* Line 1464 of yacc.c */ +#line 442 "glsl_parser.ypp" + { + (yyval.expression) = (yyvsp[(1) - (3)].expression); + (yyval.expression)->set_location(yylloc); + (yyval.expression)->expressions.push_tail(& (yyvsp[(3) - (3)].expression)->link); + ;} + break; + + case 44: + +/* Line 1464 of yacc.c */ +#line 458 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_function_expression((yyvsp[(1) - (1)].type_specifier)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 45: + +/* Line 1464 of yacc.c */ +#line 464 "glsl_parser.ypp" + { + void *ctx = state; + ast_expression *callee = new(ctx) ast_expression((yyvsp[(1) - (1)].identifier)); + (yyval.expression) = new(ctx) ast_function_expression(callee); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 46: + +/* Line 1464 of yacc.c */ +#line 471 "glsl_parser.ypp" + { + void *ctx = state; + ast_expression *callee = new(ctx) ast_expression((yyvsp[(1) - (1)].identifier)); + (yyval.expression) = new(ctx) ast_function_expression(callee); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 51: + +/* Line 1464 of yacc.c */ +#line 491 "glsl_parser.ypp" + { + (yyval.expression) = (yyvsp[(1) - (2)].expression); + (yyval.expression)->set_location(yylloc); + (yyval.expression)->expressions.push_tail(& (yyvsp[(2) - (2)].expression)->link); + ;} + break; + + case 52: + +/* Line 1464 of yacc.c */ +#line 497 "glsl_parser.ypp" + { + (yyval.expression) = (yyvsp[(1) - (3)].expression); + (yyval.expression)->set_location(yylloc); + (yyval.expression)->expressions.push_tail(& (yyvsp[(3) - (3)].expression)->link); + ;} + break; + + case 53: + +/* Line 1464 of yacc.c */ +#line 509 "glsl_parser.ypp" + { + void *ctx = state; + ast_expression *callee = new(ctx) ast_expression((yyvsp[(1) - (2)].identifier)); + (yyval.expression) = new(ctx) ast_function_expression(callee); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 55: + +/* Line 1464 of yacc.c */ +#line 521 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression(ast_pre_inc, (yyvsp[(2) - (2)].expression), NULL, NULL); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 56: + +/* Line 1464 of yacc.c */ +#line 527 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression(ast_pre_dec, (yyvsp[(2) - (2)].expression), NULL, NULL); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 57: + +/* Line 1464 of yacc.c */ +#line 533 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression((yyvsp[(1) - (2)].n), (yyvsp[(2) - (2)].expression), NULL, NULL); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 58: + +/* Line 1464 of yacc.c */ +#line 542 "glsl_parser.ypp" + { (yyval.n) = ast_plus; ;} + break; + + case 59: + +/* Line 1464 of yacc.c */ +#line 543 "glsl_parser.ypp" + { (yyval.n) = ast_neg; ;} + break; + + case 60: + +/* Line 1464 of yacc.c */ +#line 544 "glsl_parser.ypp" + { (yyval.n) = ast_logic_not; ;} + break; + + case 61: + +/* Line 1464 of yacc.c */ +#line 545 "glsl_parser.ypp" + { (yyval.n) = ast_bit_not; ;} + break; + + case 63: + +/* Line 1464 of yacc.c */ +#line 551 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_mul, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 64: + +/* Line 1464 of yacc.c */ +#line 557 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_div, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 65: + +/* Line 1464 of yacc.c */ +#line 563 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_mod, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 67: + +/* Line 1464 of yacc.c */ +#line 573 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_add, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 68: + +/* Line 1464 of yacc.c */ +#line 579 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_sub, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 70: + +/* Line 1464 of yacc.c */ +#line 589 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_lshift, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 71: + +/* Line 1464 of yacc.c */ +#line 595 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_rshift, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 73: + +/* Line 1464 of yacc.c */ +#line 605 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_less, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 74: + +/* Line 1464 of yacc.c */ +#line 611 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_greater, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 75: + +/* Line 1464 of yacc.c */ +#line 617 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_lequal, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 76: + +/* Line 1464 of yacc.c */ +#line 623 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_gequal, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 78: + +/* Line 1464 of yacc.c */ +#line 633 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_equal, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 79: + +/* Line 1464 of yacc.c */ +#line 639 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_nequal, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 81: + +/* Line 1464 of yacc.c */ +#line 649 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_bit_and, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 83: + +/* Line 1464 of yacc.c */ +#line 659 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_bit_xor, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 85: + +/* Line 1464 of yacc.c */ +#line 669 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_bit_or, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 87: + +/* Line 1464 of yacc.c */ +#line 679 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_logic_and, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 89: + +/* Line 1464 of yacc.c */ +#line 689 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_logic_xor, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 91: + +/* Line 1464 of yacc.c */ +#line 699 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression_bin(ast_logic_or, (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 93: + +/* Line 1464 of yacc.c */ +#line 709 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression(ast_conditional, (yyvsp[(1) - (5)].expression), (yyvsp[(3) - (5)].expression), (yyvsp[(5) - (5)].expression)); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 95: + +/* Line 1464 of yacc.c */ +#line 719 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.expression) = new(ctx) ast_expression((yyvsp[(2) - (3)].n), (yyvsp[(1) - (3)].expression), (yyvsp[(3) - (3)].expression), NULL); + (yyval.expression)->set_location(yylloc); + ;} + break; + + case 96: + +/* Line 1464 of yacc.c */ +#line 727 "glsl_parser.ypp" + { (yyval.n) = ast_assign; ;} + break; + + case 97: + +/* Line 1464 of yacc.c */ +#line 728 "glsl_parser.ypp" + { (yyval.n) = ast_mul_assign; ;} + break; + + case 98: + +/* Line 1464 of yacc.c */ +#line 729 "glsl_parser.ypp" + { (yyval.n) = ast_div_assign; ;} + break; + + case 99: + +/* Line 1464 of yacc.c */ +#line 730 "glsl_parser.ypp" + { (yyval.n) = ast_mod_assign; ;} + break; + + case 100: + +/* Line 1464 of yacc.c */ +#line 731 "glsl_parser.ypp" + { (yyval.n) = ast_add_assign; ;} + break; + + case 101: + +/* Line 1464 of yacc.c */ +#line 732 "glsl_parser.ypp" + { (yyval.n) = ast_sub_assign; ;} + break; + + case 102: + +/* Line 1464 of yacc.c */ +#line 733 "glsl_parser.ypp" + { (yyval.n) = ast_ls_assign; ;} + break; + + case 103: + +/* Line 1464 of yacc.c */ +#line 734 "glsl_parser.ypp" + { (yyval.n) = ast_rs_assign; ;} + break; + + case 104: + +/* Line 1464 of yacc.c */ +#line 735 "glsl_parser.ypp" + { (yyval.n) = ast_and_assign; ;} + break; + + case 105: + +/* Line 1464 of yacc.c */ +#line 736 "glsl_parser.ypp" + { (yyval.n) = ast_xor_assign; ;} + break; + + case 106: + +/* Line 1464 of yacc.c */ +#line 737 "glsl_parser.ypp" + { (yyval.n) = ast_or_assign; ;} + break; + + case 107: + +/* Line 1464 of yacc.c */ +#line 742 "glsl_parser.ypp" + { + (yyval.expression) = (yyvsp[(1) - (1)].expression); + ;} + break; + + case 108: + +/* Line 1464 of yacc.c */ +#line 746 "glsl_parser.ypp" + { + void *ctx = state; + if ((yyvsp[(1) - (3)].expression)->oper != ast_sequence) { + (yyval.expression) = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL); + (yyval.expression)->set_location(yylloc); + (yyval.expression)->expressions.push_tail(& (yyvsp[(1) - (3)].expression)->link); + } else { + (yyval.expression) = (yyvsp[(1) - (3)].expression); + } + + (yyval.expression)->expressions.push_tail(& (yyvsp[(3) - (3)].expression)->link); + ;} + break; + + case 110: + +/* Line 1464 of yacc.c */ +#line 766 "glsl_parser.ypp" + { + state->symbols->pop_scope(); + (yyval.node) = (yyvsp[(1) - (2)].function); + ;} + break; + + case 111: + +/* Line 1464 of yacc.c */ +#line 771 "glsl_parser.ypp" + { + (yyval.node) = (yyvsp[(1) - (2)].declarator_list); + ;} + break; + + case 112: + +/* Line 1464 of yacc.c */ +#line 775 "glsl_parser.ypp" + { + (yyvsp[(3) - (4)].type_specifier)->precision = (yyvsp[(2) - (4)].n); + (yyvsp[(3) - (4)].type_specifier)->is_precision_statement = true; + (yyval.node) = (yyvsp[(3) - (4)].type_specifier); + ;} + break; + + case 116: + +/* Line 1464 of yacc.c */ +#line 793 "glsl_parser.ypp" + { + (yyval.function) = (yyvsp[(1) - (2)].function); + (yyval.function)->parameters.push_tail(& (yyvsp[(2) - (2)].parameter_declarator)->link); + ;} + break; + + case 117: + +/* Line 1464 of yacc.c */ +#line 798 "glsl_parser.ypp" + { + (yyval.function) = (yyvsp[(1) - (3)].function); + (yyval.function)->parameters.push_tail(& (yyvsp[(3) - (3)].parameter_declarator)->link); + ;} + break; + + case 118: + +/* Line 1464 of yacc.c */ +#line 806 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.function) = new(ctx) ast_function(); + (yyval.function)->set_location(yylloc); + (yyval.function)->return_type = (yyvsp[(1) - (3)].fully_specified_type); + (yyval.function)->identifier = (yyvsp[(2) - (3)].identifier); + + state->symbols->add_function(new(state) ir_function((yyvsp[(2) - (3)].identifier))); + state->symbols->push_scope(); + ;} + break; + + case 119: + +/* Line 1464 of yacc.c */ +#line 820 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.parameter_declarator) = new(ctx) ast_parameter_declarator(); + (yyval.parameter_declarator)->set_location(yylloc); + (yyval.parameter_declarator)->type = new(ctx) ast_fully_specified_type(); + (yyval.parameter_declarator)->type->set_location(yylloc); + (yyval.parameter_declarator)->type->specifier = (yyvsp[(1) - (2)].type_specifier); + (yyval.parameter_declarator)->identifier = (yyvsp[(2) - (2)].identifier); + ;} + break; + + case 120: + +/* Line 1464 of yacc.c */ +#line 830 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.parameter_declarator) = new(ctx) ast_parameter_declarator(); + (yyval.parameter_declarator)->set_location(yylloc); + (yyval.parameter_declarator)->type = new(ctx) ast_fully_specified_type(); + (yyval.parameter_declarator)->type->set_location(yylloc); + (yyval.parameter_declarator)->type->specifier = (yyvsp[(1) - (5)].type_specifier); + (yyval.parameter_declarator)->identifier = (yyvsp[(2) - (5)].identifier); + (yyval.parameter_declarator)->is_array = true; + (yyval.parameter_declarator)->array_size = (yyvsp[(4) - (5)].expression); + ;} + break; + + case 121: + +/* Line 1464 of yacc.c */ +#line 845 "glsl_parser.ypp" + { + (yyvsp[(1) - (3)].type_qualifier).flags.i |= (yyvsp[(2) - (3)].type_qualifier).flags.i; + + (yyval.parameter_declarator) = (yyvsp[(3) - (3)].parameter_declarator); + (yyval.parameter_declarator)->type->qualifier = (yyvsp[(1) - (3)].type_qualifier); + ;} + break; + + case 122: + +/* Line 1464 of yacc.c */ +#line 852 "glsl_parser.ypp" + { + (yyval.parameter_declarator) = (yyvsp[(2) - (2)].parameter_declarator); + (yyval.parameter_declarator)->type->qualifier = (yyvsp[(1) - (2)].type_qualifier); + ;} + break; + + case 123: + +/* Line 1464 of yacc.c */ +#line 857 "glsl_parser.ypp" + { + void *ctx = state; + (yyvsp[(1) - (3)].type_qualifier).flags.i |= (yyvsp[(2) - (3)].type_qualifier).flags.i; + + (yyval.parameter_declarator) = new(ctx) ast_parameter_declarator(); + (yyval.parameter_declarator)->set_location(yylloc); + (yyval.parameter_declarator)->type = new(ctx) ast_fully_specified_type(); + (yyval.parameter_declarator)->type->qualifier = (yyvsp[(1) - (3)].type_qualifier); + (yyval.parameter_declarator)->type->specifier = (yyvsp[(3) - (3)].type_specifier); + ;} + break; + + case 124: + +/* Line 1464 of yacc.c */ +#line 868 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.parameter_declarator) = new(ctx) ast_parameter_declarator(); + (yyval.parameter_declarator)->set_location(yylloc); + (yyval.parameter_declarator)->type = new(ctx) ast_fully_specified_type(); + (yyval.parameter_declarator)->type->qualifier = (yyvsp[(1) - (2)].type_qualifier); + (yyval.parameter_declarator)->type->specifier = (yyvsp[(2) - (2)].type_specifier); + ;} + break; + + case 125: + +/* Line 1464 of yacc.c */ +#line 880 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + ;} + break; + + case 126: + +/* Line 1464 of yacc.c */ +#line 884 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.in = 1; + ;} + break; + + case 127: + +/* Line 1464 of yacc.c */ +#line 889 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.out = 1; + ;} + break; + + case 128: + +/* Line 1464 of yacc.c */ +#line 894 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.in = 1; + (yyval.type_qualifier).flags.q.out = 1; + ;} + break; + + case 131: + +/* Line 1464 of yacc.c */ +#line 908 "glsl_parser.ypp" + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration((yyvsp[(3) - (3)].identifier), false, NULL, NULL); + decl->set_location(yylloc); + + (yyval.declarator_list) = (yyvsp[(1) - (3)].declarator_list); + (yyval.declarator_list)->declarations.push_tail(&decl->link); + state->symbols->add_variable(new(state) ir_variable(NULL, (yyvsp[(3) - (3)].identifier), ir_var_auto)); + ;} + break; + + case 132: + +/* Line 1464 of yacc.c */ +#line 918 "glsl_parser.ypp" + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration((yyvsp[(3) - (5)].identifier), true, NULL, NULL); + decl->set_location(yylloc); + + (yyval.declarator_list) = (yyvsp[(1) - (5)].declarator_list); + (yyval.declarator_list)->declarations.push_tail(&decl->link); + state->symbols->add_variable(new(state) ir_variable(NULL, (yyvsp[(3) - (5)].identifier), ir_var_auto)); + ;} + break; + + case 133: + +/* Line 1464 of yacc.c */ +#line 928 "glsl_parser.ypp" + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration((yyvsp[(3) - (6)].identifier), true, (yyvsp[(5) - (6)].expression), NULL); + decl->set_location(yylloc); + + (yyval.declarator_list) = (yyvsp[(1) - (6)].declarator_list); + (yyval.declarator_list)->declarations.push_tail(&decl->link); + state->symbols->add_variable(new(state) ir_variable(NULL, (yyvsp[(3) - (6)].identifier), ir_var_auto)); + ;} + break; + + case 134: + +/* Line 1464 of yacc.c */ +#line 938 "glsl_parser.ypp" + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration((yyvsp[(3) - (7)].identifier), true, NULL, (yyvsp[(7) - (7)].expression)); + decl->set_location(yylloc); + + (yyval.declarator_list) = (yyvsp[(1) - (7)].declarator_list); + (yyval.declarator_list)->declarations.push_tail(&decl->link); + state->symbols->add_variable(new(state) ir_variable(NULL, (yyvsp[(3) - (7)].identifier), ir_var_auto)); + ;} + break; + + case 135: + +/* Line 1464 of yacc.c */ +#line 948 "glsl_parser.ypp" + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration((yyvsp[(3) - (8)].identifier), true, (yyvsp[(5) - (8)].expression), (yyvsp[(8) - (8)].expression)); + decl->set_location(yylloc); + + (yyval.declarator_list) = (yyvsp[(1) - (8)].declarator_list); + (yyval.declarator_list)->declarations.push_tail(&decl->link); + state->symbols->add_variable(new(state) ir_variable(NULL, (yyvsp[(3) - (8)].identifier), ir_var_auto)); + ;} + break; + + case 136: + +/* Line 1464 of yacc.c */ +#line 958 "glsl_parser.ypp" + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration((yyvsp[(3) - (5)].identifier), false, NULL, (yyvsp[(5) - (5)].expression)); + decl->set_location(yylloc); + + (yyval.declarator_list) = (yyvsp[(1) - (5)].declarator_list); + (yyval.declarator_list)->declarations.push_tail(&decl->link); + state->symbols->add_variable(new(state) ir_variable(NULL, (yyvsp[(3) - (5)].identifier), ir_var_auto)); + ;} + break; + + case 137: + +/* Line 1464 of yacc.c */ +#line 972 "glsl_parser.ypp" + { + void *ctx = state; + if ((yyvsp[(1) - (1)].fully_specified_type)->specifier->type_specifier != ast_struct) { + _mesa_glsl_error(& (yylsp[(1) - (1)]), state, "empty declaration list\n"); + YYERROR; + } else { + (yyval.declarator_list) = new(ctx) ast_declarator_list((yyvsp[(1) - (1)].fully_specified_type)); + (yyval.declarator_list)->set_location(yylloc); + } + ;} + break; + + case 138: + +/* Line 1464 of yacc.c */ +#line 983 "glsl_parser.ypp" + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration((yyvsp[(2) - (2)].identifier), false, NULL, NULL); + + (yyval.declarator_list) = new(ctx) ast_declarator_list((yyvsp[(1) - (2)].fully_specified_type)); + (yyval.declarator_list)->set_location(yylloc); + (yyval.declarator_list)->declarations.push_tail(&decl->link); + ;} + break; + + case 139: + +/* Line 1464 of yacc.c */ +#line 992 "glsl_parser.ypp" + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration((yyvsp[(2) - (4)].identifier), true, NULL, NULL); + + (yyval.declarator_list) = new(ctx) ast_declarator_list((yyvsp[(1) - (4)].fully_specified_type)); + (yyval.declarator_list)->set_location(yylloc); + (yyval.declarator_list)->declarations.push_tail(&decl->link); + ;} + break; + + case 140: + +/* Line 1464 of yacc.c */ +#line 1001 "glsl_parser.ypp" + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration((yyvsp[(2) - (5)].identifier), true, (yyvsp[(4) - (5)].expression), NULL); + + (yyval.declarator_list) = new(ctx) ast_declarator_list((yyvsp[(1) - (5)].fully_specified_type)); + (yyval.declarator_list)->set_location(yylloc); + (yyval.declarator_list)->declarations.push_tail(&decl->link); + ;} + break; + + case 141: + +/* Line 1464 of yacc.c */ +#line 1010 "glsl_parser.ypp" + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration((yyvsp[(2) - (6)].identifier), true, NULL, (yyvsp[(6) - (6)].expression)); + + (yyval.declarator_list) = new(ctx) ast_declarator_list((yyvsp[(1) - (6)].fully_specified_type)); + (yyval.declarator_list)->set_location(yylloc); + (yyval.declarator_list)->declarations.push_tail(&decl->link); + ;} + break; + + case 142: + +/* Line 1464 of yacc.c */ +#line 1019 "glsl_parser.ypp" + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration((yyvsp[(2) - (7)].identifier), true, (yyvsp[(4) - (7)].expression), (yyvsp[(7) - (7)].expression)); + + (yyval.declarator_list) = new(ctx) ast_declarator_list((yyvsp[(1) - (7)].fully_specified_type)); + (yyval.declarator_list)->set_location(yylloc); + (yyval.declarator_list)->declarations.push_tail(&decl->link); + ;} + break; + + case 143: + +/* Line 1464 of yacc.c */ +#line 1028 "glsl_parser.ypp" + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration((yyvsp[(2) - (4)].identifier), false, NULL, (yyvsp[(4) - (4)].expression)); + + (yyval.declarator_list) = new(ctx) ast_declarator_list((yyvsp[(1) - (4)].fully_specified_type)); + (yyval.declarator_list)->set_location(yylloc); + (yyval.declarator_list)->declarations.push_tail(&decl->link); + ;} + break; + + case 144: + +/* Line 1464 of yacc.c */ +#line 1037 "glsl_parser.ypp" + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration((yyvsp[(2) - (2)].identifier), false, NULL, NULL); + + (yyval.declarator_list) = new(ctx) ast_declarator_list(NULL); + (yyval.declarator_list)->set_location(yylloc); + (yyval.declarator_list)->invariant = true; + + (yyval.declarator_list)->declarations.push_tail(&decl->link); + ;} + break; + + case 145: + +/* Line 1464 of yacc.c */ +#line 1051 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.fully_specified_type) = new(ctx) ast_fully_specified_type(); + (yyval.fully_specified_type)->set_location(yylloc); + (yyval.fully_specified_type)->specifier = (yyvsp[(1) - (1)].type_specifier); + ;} + break; + + case 146: + +/* Line 1464 of yacc.c */ +#line 1058 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.fully_specified_type) = new(ctx) ast_fully_specified_type(); + (yyval.fully_specified_type)->set_location(yylloc); + (yyval.fully_specified_type)->qualifier = (yyvsp[(1) - (2)].type_qualifier); + (yyval.fully_specified_type)->specifier = (yyvsp[(2) - (2)].type_specifier); + ;} + break; + + case 147: + +/* Line 1464 of yacc.c */ +#line 1069 "glsl_parser.ypp" + { + (yyval.type_qualifier) = (yyvsp[(3) - (4)].type_qualifier); + ;} + break; + + case 149: + +/* Line 1464 of yacc.c */ +#line 1077 "glsl_parser.ypp" + { + if (((yyvsp[(1) - (3)].type_qualifier).flags.i & (yyvsp[(3) - (3)].type_qualifier).flags.i) != 0) { + _mesa_glsl_error(& (yylsp[(3) - (3)]), state, + "duplicate layout qualifiers used\n"); + YYERROR; + } + + (yyval.type_qualifier).flags.i = (yyvsp[(1) - (3)].type_qualifier).flags.i | (yyvsp[(3) - (3)].type_qualifier).flags.i; + + if ((yyvsp[(1) - (3)].type_qualifier).flags.q.explicit_location) + (yyval.type_qualifier).location = (yyvsp[(1) - (3)].type_qualifier).location; + + if ((yyvsp[(3) - (3)].type_qualifier).flags.q.explicit_location) + (yyval.type_qualifier).location = (yyvsp[(3) - (3)].type_qualifier).location; + ;} + break; + + case 150: + +/* Line 1464 of yacc.c */ +#line 1096 "glsl_parser.ypp" + { + bool got_one = false; + + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + + if (state->ARB_fragment_coord_conventions_enable) { + if (strcmp((yyvsp[(1) - (1)].identifier), "origin_upper_left") == 0) { + got_one = true; + (yyval.type_qualifier).flags.q.origin_upper_left = 1; + } else if (strcmp((yyvsp[(1) - (1)].identifier), "pixel_center_integer") == 0) { + got_one = true; + (yyval.type_qualifier).flags.q.pixel_center_integer = 1; + } + } + + /* If the identifier didn't match any known layout identifiers, + * emit an error. + */ + if (!got_one) { + _mesa_glsl_error(& (yylsp[(1) - (1)]), state, "unrecognized layout identifier " + "`%s'\n", (yyvsp[(1) - (1)].identifier)); + YYERROR; + } else if (state->ARB_fragment_coord_conventions_warn) { + _mesa_glsl_warning(& (yylsp[(1) - (1)]), state, + "GL_ARB_fragment_coord_conventions layout " + "identifier `%s' used\n", (yyvsp[(1) - (1)].identifier)); + } + ;} + break; + + case 151: + +/* Line 1464 of yacc.c */ +#line 1125 "glsl_parser.ypp" + { + bool got_one = false; + + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + + if (state->ARB_explicit_attrib_location_enable) { + /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and + * FINISHME: GLSL 1.30 (or later) are supported. + */ + if (strcmp("location", (yyvsp[(1) - (3)].identifier)) == 0) { + got_one = true; + + (yyval.type_qualifier).flags.q.explicit_location = 1; + + if ((yyvsp[(3) - (3)].n) >= 0) { + (yyval.type_qualifier).location = (yyvsp[(3) - (3)].n); + } else { + _mesa_glsl_error(& (yylsp[(3) - (3)]), state, + "invalid location %d specified\n", (yyvsp[(3) - (3)].n)); + YYERROR; + } + } + } + + /* If the identifier didn't match any known layout identifiers, + * emit an error. + */ + if (!got_one) { + _mesa_glsl_error(& (yylsp[(1) - (3)]), state, "unrecognized layout identifier " + "`%s'\n", (yyvsp[(1) - (3)].identifier)); + YYERROR; + } else if (state->ARB_explicit_attrib_location_warn) { + _mesa_glsl_warning(& (yylsp[(1) - (3)]), state, + "GL_ARB_explicit_attrib_location layout " + "identifier `%s' used\n", (yyvsp[(1) - (3)].identifier)); + } + ;} + break; + + case 152: + +/* Line 1464 of yacc.c */ +#line 1166 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.smooth = 1; + ;} + break; + + case 153: + +/* Line 1464 of yacc.c */ +#line 1171 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.flat = 1; + ;} + break; + + case 154: + +/* Line 1464 of yacc.c */ +#line 1176 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.noperspective = 1; + ;} + break; + + case 155: + +/* Line 1464 of yacc.c */ +#line 1184 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.constant = 1; + ;} + break; + + case 158: + +/* Line 1464 of yacc.c */ +#line 1194 "glsl_parser.ypp" + { + (yyval.type_qualifier) = (yyvsp[(1) - (2)].type_qualifier); + (yyval.type_qualifier).flags.i |= (yyvsp[(2) - (2)].type_qualifier).flags.i; + ;} + break; + + case 160: + +/* Line 1464 of yacc.c */ +#line 1200 "glsl_parser.ypp" + { + (yyval.type_qualifier) = (yyvsp[(1) - (2)].type_qualifier); + (yyval.type_qualifier).flags.i |= (yyvsp[(2) - (2)].type_qualifier).flags.i; + ;} + break; + + case 161: + +/* Line 1464 of yacc.c */ +#line 1205 "glsl_parser.ypp" + { + (yyval.type_qualifier) = (yyvsp[(2) - (2)].type_qualifier); + (yyval.type_qualifier).flags.q.invariant = 1; + ;} + break; + + case 162: + +/* Line 1464 of yacc.c */ +#line 1210 "glsl_parser.ypp" + { + (yyval.type_qualifier) = (yyvsp[(2) - (3)].type_qualifier); + (yyval.type_qualifier).flags.i |= (yyvsp[(3) - (3)].type_qualifier).flags.i; + (yyval.type_qualifier).flags.q.invariant = 1; + ;} + break; + + case 163: + +/* Line 1464 of yacc.c */ +#line 1216 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.invariant = 1; + ;} + break; + + case 164: + +/* Line 1464 of yacc.c */ +#line 1224 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.constant = 1; + ;} + break; + + case 165: + +/* Line 1464 of yacc.c */ +#line 1229 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.attribute = 1; + ;} + break; + + case 166: + +/* Line 1464 of yacc.c */ +#line 1234 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.varying = 1; + ;} + break; + + case 167: + +/* Line 1464 of yacc.c */ +#line 1239 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.centroid = 1; + (yyval.type_qualifier).flags.q.varying = 1; + ;} + break; + + case 168: + +/* Line 1464 of yacc.c */ +#line 1245 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.in = 1; + ;} + break; + + case 169: + +/* Line 1464 of yacc.c */ +#line 1250 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.out = 1; + ;} + break; + + case 170: + +/* Line 1464 of yacc.c */ +#line 1255 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.centroid = 1; (yyval.type_qualifier).flags.q.in = 1; + ;} + break; + + case 171: + +/* Line 1464 of yacc.c */ +#line 1260 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.centroid = 1; (yyval.type_qualifier).flags.q.out = 1; + ;} + break; + + case 172: + +/* Line 1464 of yacc.c */ +#line 1265 "glsl_parser.ypp" + { + memset(& (yyval.type_qualifier), 0, sizeof((yyval.type_qualifier))); + (yyval.type_qualifier).flags.q.uniform = 1; + ;} + break; + + case 173: + +/* Line 1464 of yacc.c */ +#line 1273 "glsl_parser.ypp" + { + (yyval.type_specifier) = (yyvsp[(1) - (1)].type_specifier); + ;} + break; + + case 174: + +/* Line 1464 of yacc.c */ +#line 1277 "glsl_parser.ypp" + { + (yyval.type_specifier) = (yyvsp[(2) - (2)].type_specifier); + (yyval.type_specifier)->precision = (yyvsp[(1) - (2)].n); + ;} + break; + + case 176: + +/* Line 1464 of yacc.c */ +#line 1286 "glsl_parser.ypp" + { + (yyval.type_specifier) = (yyvsp[(1) - (3)].type_specifier); + (yyval.type_specifier)->is_array = true; + (yyval.type_specifier)->array_size = NULL; + ;} + break; + + case 177: + +/* Line 1464 of yacc.c */ +#line 1292 "glsl_parser.ypp" + { + (yyval.type_specifier) = (yyvsp[(1) - (4)].type_specifier); + (yyval.type_specifier)->is_array = true; + (yyval.type_specifier)->array_size = (yyvsp[(3) - (4)].expression); + ;} + break; + + case 178: + +/* Line 1464 of yacc.c */ +#line 1301 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.type_specifier) = new(ctx) ast_type_specifier((yyvsp[(1) - (1)].n)); + (yyval.type_specifier)->set_location(yylloc); + ;} + break; + + case 179: + +/* Line 1464 of yacc.c */ +#line 1307 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.type_specifier) = new(ctx) ast_type_specifier((yyvsp[(1) - (1)].struct_specifier)); + (yyval.type_specifier)->set_location(yylloc); + ;} + break; + + case 180: + +/* Line 1464 of yacc.c */ +#line 1313 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.type_specifier) = new(ctx) ast_type_specifier((yyvsp[(1) - (1)].identifier)); + (yyval.type_specifier)->set_location(yylloc); + ;} + break; + + case 181: + +/* Line 1464 of yacc.c */ +#line 1321 "glsl_parser.ypp" + { (yyval.n) = ast_void; ;} + break; + + case 182: + +/* Line 1464 of yacc.c */ +#line 1322 "glsl_parser.ypp" + { (yyval.n) = ast_float; ;} + break; + + case 183: + +/* Line 1464 of yacc.c */ +#line 1323 "glsl_parser.ypp" + { (yyval.n) = ast_int; ;} + break; + + case 184: + +/* Line 1464 of yacc.c */ +#line 1324 "glsl_parser.ypp" + { (yyval.n) = ast_uint; ;} + break; + + case 185: + +/* Line 1464 of yacc.c */ +#line 1325 "glsl_parser.ypp" + { (yyval.n) = ast_bool; ;} + break; + + case 186: + +/* Line 1464 of yacc.c */ +#line 1326 "glsl_parser.ypp" + { (yyval.n) = ast_vec2; ;} + break; + + case 187: + +/* Line 1464 of yacc.c */ +#line 1327 "glsl_parser.ypp" + { (yyval.n) = ast_vec3; ;} + break; + + case 188: + +/* Line 1464 of yacc.c */ +#line 1328 "glsl_parser.ypp" + { (yyval.n) = ast_vec4; ;} + break; + + case 189: + +/* Line 1464 of yacc.c */ +#line 1329 "glsl_parser.ypp" + { (yyval.n) = ast_bvec2; ;} + break; + + case 190: + +/* Line 1464 of yacc.c */ +#line 1330 "glsl_parser.ypp" + { (yyval.n) = ast_bvec3; ;} + break; + + case 191: + +/* Line 1464 of yacc.c */ +#line 1331 "glsl_parser.ypp" + { (yyval.n) = ast_bvec4; ;} + break; + + case 192: + +/* Line 1464 of yacc.c */ +#line 1332 "glsl_parser.ypp" + { (yyval.n) = ast_ivec2; ;} + break; + + case 193: + +/* Line 1464 of yacc.c */ +#line 1333 "glsl_parser.ypp" + { (yyval.n) = ast_ivec3; ;} + break; + + case 194: + +/* Line 1464 of yacc.c */ +#line 1334 "glsl_parser.ypp" + { (yyval.n) = ast_ivec4; ;} + break; + + case 195: + +/* Line 1464 of yacc.c */ +#line 1335 "glsl_parser.ypp" + { (yyval.n) = ast_uvec2; ;} + break; + + case 196: + +/* Line 1464 of yacc.c */ +#line 1336 "glsl_parser.ypp" + { (yyval.n) = ast_uvec3; ;} + break; + + case 197: + +/* Line 1464 of yacc.c */ +#line 1337 "glsl_parser.ypp" + { (yyval.n) = ast_uvec4; ;} + break; + + case 198: + +/* Line 1464 of yacc.c */ +#line 1338 "glsl_parser.ypp" + { (yyval.n) = ast_mat2; ;} + break; + + case 199: + +/* Line 1464 of yacc.c */ +#line 1339 "glsl_parser.ypp" + { (yyval.n) = ast_mat2x3; ;} + break; + + case 200: + +/* Line 1464 of yacc.c */ +#line 1340 "glsl_parser.ypp" + { (yyval.n) = ast_mat2x4; ;} + break; + + case 201: + +/* Line 1464 of yacc.c */ +#line 1341 "glsl_parser.ypp" + { (yyval.n) = ast_mat3x2; ;} + break; + + case 202: + +/* Line 1464 of yacc.c */ +#line 1342 "glsl_parser.ypp" + { (yyval.n) = ast_mat3; ;} + break; + + case 203: + +/* Line 1464 of yacc.c */ +#line 1343 "glsl_parser.ypp" + { (yyval.n) = ast_mat3x4; ;} + break; + + case 204: + +/* Line 1464 of yacc.c */ +#line 1344 "glsl_parser.ypp" + { (yyval.n) = ast_mat4x2; ;} + break; + + case 205: + +/* Line 1464 of yacc.c */ +#line 1345 "glsl_parser.ypp" + { (yyval.n) = ast_mat4x3; ;} + break; + + case 206: + +/* Line 1464 of yacc.c */ +#line 1346 "glsl_parser.ypp" + { (yyval.n) = ast_mat4; ;} + break; + + case 207: + +/* Line 1464 of yacc.c */ +#line 1347 "glsl_parser.ypp" + { (yyval.n) = ast_sampler1d; ;} + break; + + case 208: + +/* Line 1464 of yacc.c */ +#line 1348 "glsl_parser.ypp" + { (yyval.n) = ast_sampler2d; ;} + break; + + case 209: + +/* Line 1464 of yacc.c */ +#line 1349 "glsl_parser.ypp" + { (yyval.n) = ast_sampler2drect; ;} + break; + + case 210: + +/* Line 1464 of yacc.c */ +#line 1350 "glsl_parser.ypp" + { (yyval.n) = ast_sampler3d; ;} + break; + + case 211: + +/* Line 1464 of yacc.c */ +#line 1351 "glsl_parser.ypp" + { (yyval.n) = ast_samplercube; ;} + break; + + case 212: + +/* Line 1464 of yacc.c */ +#line 1352 "glsl_parser.ypp" + { (yyval.n) = ast_sampler1dshadow; ;} + break; + + case 213: + +/* Line 1464 of yacc.c */ +#line 1353 "glsl_parser.ypp" + { (yyval.n) = ast_sampler2dshadow; ;} + break; + + case 214: + +/* Line 1464 of yacc.c */ +#line 1354 "glsl_parser.ypp" + { (yyval.n) = ast_sampler2drectshadow; ;} + break; + + case 215: + +/* Line 1464 of yacc.c */ +#line 1355 "glsl_parser.ypp" + { (yyval.n) = ast_samplercubeshadow; ;} + break; + + case 216: + +/* Line 1464 of yacc.c */ +#line 1356 "glsl_parser.ypp" + { (yyval.n) = ast_sampler1darray; ;} + break; + + case 217: + +/* Line 1464 of yacc.c */ +#line 1357 "glsl_parser.ypp" + { (yyval.n) = ast_sampler2darray; ;} + break; + + case 218: + +/* Line 1464 of yacc.c */ +#line 1358 "glsl_parser.ypp" + { (yyval.n) = ast_sampler1darrayshadow; ;} + break; + + case 219: + +/* Line 1464 of yacc.c */ +#line 1359 "glsl_parser.ypp" + { (yyval.n) = ast_sampler2darrayshadow; ;} + break; + + case 220: + +/* Line 1464 of yacc.c */ +#line 1360 "glsl_parser.ypp" + { (yyval.n) = ast_isampler1d; ;} + break; + + case 221: + +/* Line 1464 of yacc.c */ +#line 1361 "glsl_parser.ypp" + { (yyval.n) = ast_isampler2d; ;} + break; + + case 222: + +/* Line 1464 of yacc.c */ +#line 1362 "glsl_parser.ypp" + { (yyval.n) = ast_isampler3d; ;} + break; + + case 223: + +/* Line 1464 of yacc.c */ +#line 1363 "glsl_parser.ypp" + { (yyval.n) = ast_isamplercube; ;} + break; + + case 224: + +/* Line 1464 of yacc.c */ +#line 1364 "glsl_parser.ypp" + { (yyval.n) = ast_isampler1darray; ;} + break; + + case 225: + +/* Line 1464 of yacc.c */ +#line 1365 "glsl_parser.ypp" + { (yyval.n) = ast_isampler2darray; ;} + break; + + case 226: + +/* Line 1464 of yacc.c */ +#line 1366 "glsl_parser.ypp" + { (yyval.n) = ast_usampler1d; ;} + break; + + case 227: + +/* Line 1464 of yacc.c */ +#line 1367 "glsl_parser.ypp" + { (yyval.n) = ast_usampler2d; ;} + break; + + case 228: + +/* Line 1464 of yacc.c */ +#line 1368 "glsl_parser.ypp" + { (yyval.n) = ast_usampler3d; ;} + break; + + case 229: + +/* Line 1464 of yacc.c */ +#line 1369 "glsl_parser.ypp" + { (yyval.n) = ast_usamplercube; ;} + break; + + case 230: + +/* Line 1464 of yacc.c */ +#line 1370 "glsl_parser.ypp" + { (yyval.n) = ast_usampler1darray; ;} + break; + + case 231: + +/* Line 1464 of yacc.c */ +#line 1371 "glsl_parser.ypp" + { (yyval.n) = ast_usampler2darray; ;} + break; + + case 232: + +/* Line 1464 of yacc.c */ +#line 1375 "glsl_parser.ypp" + { + if (!state->es_shader && state->language_version < 130) + _mesa_glsl_error(& (yylsp[(1) - (1)]), state, + "precision qualifier forbidden " + "in %s (1.30 or later " + "required)\n", + state->version_string); + + (yyval.n) = ast_precision_high; + ;} + break; + + case 233: + +/* Line 1464 of yacc.c */ +#line 1385 "glsl_parser.ypp" + { + if (!state->es_shader && state->language_version < 130) + _mesa_glsl_error(& (yylsp[(1) - (1)]), state, + "precision qualifier forbidden " + "in %s (1.30 or later " + "required)\n", + state->version_string); + + (yyval.n) = ast_precision_medium; + ;} + break; + + case 234: + +/* Line 1464 of yacc.c */ +#line 1395 "glsl_parser.ypp" + { + if (!state->es_shader && state->language_version < 130) + _mesa_glsl_error(& (yylsp[(1) - (1)]), state, + "precision qualifier forbidden " + "in %s (1.30 or later " + "required)\n", + state->version_string); + + (yyval.n) = ast_precision_low; + ;} + break; + + case 235: + +/* Line 1464 of yacc.c */ +#line 1409 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.struct_specifier) = new(ctx) ast_struct_specifier((yyvsp[(2) - (5)].identifier), (yyvsp[(4) - (5)].node)); + (yyval.struct_specifier)->set_location(yylloc); + state->symbols->add_type((yyvsp[(2) - (5)].identifier), glsl_type::void_type); + ;} + break; + + case 236: + +/* Line 1464 of yacc.c */ +#line 1416 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.struct_specifier) = new(ctx) ast_struct_specifier(NULL, (yyvsp[(3) - (4)].node)); + (yyval.struct_specifier)->set_location(yylloc); + ;} + break; + + case 237: + +/* Line 1464 of yacc.c */ +#line 1425 "glsl_parser.ypp" + { + (yyval.node) = (ast_node *) (yyvsp[(1) - (1)].declarator_list); + (yyvsp[(1) - (1)].declarator_list)->link.self_link(); + ;} + break; + + case 238: + +/* Line 1464 of yacc.c */ +#line 1430 "glsl_parser.ypp" + { + (yyval.node) = (ast_node *) (yyvsp[(1) - (2)].node); + (yyval.node)->link.insert_before(& (yyvsp[(2) - (2)].declarator_list)->link); + ;} + break; + + case 239: + +/* Line 1464 of yacc.c */ +#line 1438 "glsl_parser.ypp" + { + void *ctx = state; + ast_fully_specified_type *type = new(ctx) ast_fully_specified_type(); + type->set_location(yylloc); + + type->specifier = (yyvsp[(1) - (3)].type_specifier); + (yyval.declarator_list) = new(ctx) ast_declarator_list(type); + (yyval.declarator_list)->set_location(yylloc); + + (yyval.declarator_list)->declarations.push_degenerate_list_at_head(& (yyvsp[(2) - (3)].declaration)->link); + ;} + break; + + case 240: + +/* Line 1464 of yacc.c */ +#line 1453 "glsl_parser.ypp" + { + (yyval.declaration) = (yyvsp[(1) - (1)].declaration); + (yyvsp[(1) - (1)].declaration)->link.self_link(); + ;} + break; + + case 241: + +/* Line 1464 of yacc.c */ +#line 1458 "glsl_parser.ypp" + { + (yyval.declaration) = (yyvsp[(1) - (3)].declaration); + (yyval.declaration)->link.insert_before(& (yyvsp[(3) - (3)].declaration)->link); + ;} + break; + + case 242: + +/* Line 1464 of yacc.c */ +#line 1466 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.declaration) = new(ctx) ast_declaration((yyvsp[(1) - (1)].identifier), false, NULL, NULL); + (yyval.declaration)->set_location(yylloc); + state->symbols->add_variable(new(state) ir_variable(NULL, (yyvsp[(1) - (1)].identifier), ir_var_auto)); + ;} + break; + + case 243: + +/* Line 1464 of yacc.c */ +#line 1473 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.declaration) = new(ctx) ast_declaration((yyvsp[(1) - (4)].identifier), true, (yyvsp[(3) - (4)].expression), NULL); + (yyval.declaration)->set_location(yylloc); + ;} + break; + + case 246: + +/* Line 1464 of yacc.c */ +#line 1491 "glsl_parser.ypp" + { (yyval.node) = (ast_node *) (yyvsp[(1) - (1)].compound_statement); ;} + break; + + case 251: + +/* Line 1464 of yacc.c */ +#line 1499 "glsl_parser.ypp" + { (yyval.node) = NULL; ;} + break; + + case 252: + +/* Line 1464 of yacc.c */ +#line 1500 "glsl_parser.ypp" + { (yyval.node) = NULL; ;} + break; + + case 255: + +/* Line 1464 of yacc.c */ +#line 1507 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.compound_statement) = new(ctx) ast_compound_statement(true, NULL); + (yyval.compound_statement)->set_location(yylloc); + ;} + break; + + case 256: + +/* Line 1464 of yacc.c */ +#line 1513 "glsl_parser.ypp" + { + state->symbols->push_scope(); + ;} + break; + + case 257: + +/* Line 1464 of yacc.c */ +#line 1517 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.compound_statement) = new(ctx) ast_compound_statement(true, (yyvsp[(3) - (4)].node)); + (yyval.compound_statement)->set_location(yylloc); + state->symbols->pop_scope(); + ;} + break; + + case 258: + +/* Line 1464 of yacc.c */ +#line 1526 "glsl_parser.ypp" + { (yyval.node) = (ast_node *) (yyvsp[(1) - (1)].compound_statement); ;} + break; + + case 260: + +/* Line 1464 of yacc.c */ +#line 1532 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.compound_statement) = new(ctx) ast_compound_statement(false, NULL); + (yyval.compound_statement)->set_location(yylloc); + ;} + break; + + case 261: + +/* Line 1464 of yacc.c */ +#line 1538 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.compound_statement) = new(ctx) ast_compound_statement(false, (yyvsp[(2) - (3)].node)); + (yyval.compound_statement)->set_location(yylloc); + ;} + break; + + case 262: + +/* Line 1464 of yacc.c */ +#line 1547 "glsl_parser.ypp" + { + if ((yyvsp[(1) - (1)].node) == NULL) { + _mesa_glsl_error(& (yylsp[(1) - (1)]), state, " statement\n"); + assert((yyvsp[(1) - (1)].node) != NULL); + } + + (yyval.node) = (yyvsp[(1) - (1)].node); + (yyval.node)->link.self_link(); + ;} + break; + + case 263: + +/* Line 1464 of yacc.c */ +#line 1557 "glsl_parser.ypp" + { + if ((yyvsp[(2) - (2)].node) == NULL) { + _mesa_glsl_error(& (yylsp[(2) - (2)]), state, " statement\n"); + assert((yyvsp[(2) - (2)].node) != NULL); + } + (yyval.node) = (yyvsp[(1) - (2)].node); + (yyval.node)->link.insert_before(& (yyvsp[(2) - (2)].node)->link); + ;} + break; + + case 264: + +/* Line 1464 of yacc.c */ +#line 1569 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.node) = new(ctx) ast_expression_statement(NULL); + (yyval.node)->set_location(yylloc); + ;} + break; + + case 265: + +/* Line 1464 of yacc.c */ +#line 1575 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.node) = new(ctx) ast_expression_statement((yyvsp[(1) - (2)].expression)); + (yyval.node)->set_location(yylloc); + ;} + break; + + case 266: + +/* Line 1464 of yacc.c */ +#line 1584 "glsl_parser.ypp" + { + (yyval.node) = new(state) ast_selection_statement((yyvsp[(3) - (5)].expression), (yyvsp[(5) - (5)].selection_rest_statement).then_statement, + (yyvsp[(5) - (5)].selection_rest_statement).else_statement); + (yyval.node)->set_location(yylloc); + ;} + break; + + case 267: + +/* Line 1464 of yacc.c */ +#line 1593 "glsl_parser.ypp" + { + (yyval.selection_rest_statement).then_statement = (yyvsp[(1) - (3)].node); + (yyval.selection_rest_statement).else_statement = (yyvsp[(3) - (3)].node); + ;} + break; + + case 268: + +/* Line 1464 of yacc.c */ +#line 1598 "glsl_parser.ypp" + { + (yyval.selection_rest_statement).then_statement = (yyvsp[(1) - (1)].node); + (yyval.selection_rest_statement).else_statement = NULL; + ;} + break; + + case 269: + +/* Line 1464 of yacc.c */ +#line 1606 "glsl_parser.ypp" + { + (yyval.node) = (ast_node *) (yyvsp[(1) - (1)].expression); + ;} + break; + + case 270: + +/* Line 1464 of yacc.c */ +#line 1610 "glsl_parser.ypp" + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration((yyvsp[(2) - (4)].identifier), false, NULL, (yyvsp[(4) - (4)].expression)); + ast_declarator_list *declarator = new(ctx) ast_declarator_list((yyvsp[(1) - (4)].fully_specified_type)); + decl->set_location(yylloc); + declarator->set_location(yylloc); + + declarator->declarations.push_tail(&decl->link); + (yyval.node) = declarator; + ;} + break; + + case 274: + +/* Line 1464 of yacc.c */ +#line 1633 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.node) = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while, + NULL, (yyvsp[(3) - (5)].node), NULL, (yyvsp[(5) - (5)].node)); + (yyval.node)->set_location(yylloc); + ;} + break; + + case 275: + +/* Line 1464 of yacc.c */ +#line 1640 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.node) = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while, + NULL, (yyvsp[(5) - (7)].expression), NULL, (yyvsp[(2) - (7)].node)); + (yyval.node)->set_location(yylloc); + ;} + break; + + case 276: + +/* Line 1464 of yacc.c */ +#line 1647 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.node) = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for, + (yyvsp[(3) - (6)].node), (yyvsp[(4) - (6)].for_rest_statement).cond, (yyvsp[(4) - (6)].for_rest_statement).rest, (yyvsp[(6) - (6)].node)); + (yyval.node)->set_location(yylloc); + ;} + break; + + case 280: + +/* Line 1464 of yacc.c */ +#line 1663 "glsl_parser.ypp" + { + (yyval.node) = NULL; + ;} + break; + + case 281: + +/* Line 1464 of yacc.c */ +#line 1670 "glsl_parser.ypp" + { + (yyval.for_rest_statement).cond = (yyvsp[(1) - (2)].node); + (yyval.for_rest_statement).rest = NULL; + ;} + break; + + case 282: + +/* Line 1464 of yacc.c */ +#line 1675 "glsl_parser.ypp" + { + (yyval.for_rest_statement).cond = (yyvsp[(1) - (3)].node); + (yyval.for_rest_statement).rest = (yyvsp[(3) - (3)].expression); + ;} + break; + + case 283: + +/* Line 1464 of yacc.c */ +#line 1684 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.node) = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL); + (yyval.node)->set_location(yylloc); + ;} + break; + + case 284: + +/* Line 1464 of yacc.c */ +#line 1690 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.node) = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL); + (yyval.node)->set_location(yylloc); + ;} + break; + + case 285: + +/* Line 1464 of yacc.c */ +#line 1696 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.node) = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL); + (yyval.node)->set_location(yylloc); + ;} + break; + + case 286: + +/* Line 1464 of yacc.c */ +#line 1702 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.node) = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, (yyvsp[(2) - (3)].expression)); + (yyval.node)->set_location(yylloc); + ;} + break; + + case 287: + +/* Line 1464 of yacc.c */ +#line 1708 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.node) = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL); + (yyval.node)->set_location(yylloc); + ;} + break; + + case 288: + +/* Line 1464 of yacc.c */ +#line 1716 "glsl_parser.ypp" + { (yyval.node) = (yyvsp[(1) - (1)].function_definition); ;} + break; + + case 289: + +/* Line 1464 of yacc.c */ +#line 1717 "glsl_parser.ypp" + { (yyval.node) = (yyvsp[(1) - (1)].node); ;} + break; + + case 290: + +/* Line 1464 of yacc.c */ +#line 1718 "glsl_parser.ypp" + { (yyval.node) = NULL; ;} + break; + + case 291: + +/* Line 1464 of yacc.c */ +#line 1723 "glsl_parser.ypp" + { + void *ctx = state; + (yyval.function_definition) = new(ctx) ast_function_definition(); + (yyval.function_definition)->set_location(yylloc); + (yyval.function_definition)->prototype = (yyvsp[(1) - (2)].function); + (yyval.function_definition)->body = (yyvsp[(2) - (2)].compound_statement); + + state->symbols->pop_scope(); + ;} + break; + + + +/* Line 1464 of yacc.c */ +#line 5217 "glsl_parser.cpp" + default: break; + } + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + *++yylsp = yyloc; + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if ! YYERROR_VERBOSE + yyerror (&yylloc, state, YY_("syntax error")); +#else + { + YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); + if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) + { + YYSIZE_T yyalloc = 2 * yysize; + if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) + yyalloc = YYSTACK_ALLOC_MAXIMUM; + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yyalloc); + if (yymsg) + yymsg_alloc = yyalloc; + else + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + } + } + + if (0 < yysize && yysize <= yymsg_alloc) + { + (void) yysyntax_error (yymsg, yystate, yychar); + yyerror (&yylloc, state, yymsg); + } + else + { + yyerror (&yylloc, state, YY_("syntax error")); + if (yysize != 0) + goto yyexhaustedlab; + } + } +#endif + } + + yyerror_range[1] = yylloc; + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval, &yylloc, state); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (/*CONSTCOND*/ 0) + goto yyerrorlab; + + yyerror_range[1] = yylsp[1-yylen]; + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (yyn != YYPACT_NINF) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + yyerror_range[1] = *yylsp; + yydestruct ("Error: popping", + yystos[yystate], yyvsp, yylsp, state); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + *++yyvsp = yylval; + + yyerror_range[2] = yylloc; + /* Using YYLLOC is tempting, but would change the location of + the lookahead. YYLOC is available though. */ + YYLLOC_DEFAULT (yyloc, yyerror_range, 2); + *++yylsp = yyloc; + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#if !defined(yyoverflow) || YYERROR_VERBOSE +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (&yylloc, state, YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: + if (yychar != YYEMPTY) + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval, &yylloc, state); + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[*yyssp], yyvsp, yylsp, state); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif +#if YYERROR_VERBOSE + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); +#endif + /* Make sure YYID is used. */ + return YYID (yyresult); +} + + + diff --git a/src/glsl/glsl_parser.h b/src/glsl/glsl_parser.h new file mode 100644 index 0000000..7f36492 --- /dev/null +++ b/src/glsl/glsl_parser.h @@ -0,0 +1,300 @@ +/* A Bison parser, made by GNU Bison 2.4.3. */ + +/* Skeleton interface for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2009, 2010 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + ATTRIBUTE = 258, + CONST_TOK = 259, + BOOL_TOK = 260, + FLOAT_TOK = 261, + INT_TOK = 262, + UINT_TOK = 263, + BREAK = 264, + CONTINUE = 265, + DO = 266, + ELSE = 267, + FOR = 268, + IF = 269, + DISCARD = 270, + RETURN = 271, + SWITCH = 272, + CASE = 273, + DEFAULT = 274, + BVEC2 = 275, + BVEC3 = 276, + BVEC4 = 277, + IVEC2 = 278, + IVEC3 = 279, + IVEC4 = 280, + UVEC2 = 281, + UVEC3 = 282, + UVEC4 = 283, + VEC2 = 284, + VEC3 = 285, + VEC4 = 286, + CENTROID = 287, + IN_TOK = 288, + OUT_TOK = 289, + INOUT_TOK = 290, + UNIFORM = 291, + VARYING = 292, + NOPERSPECTIVE = 293, + FLAT = 294, + SMOOTH = 295, + MAT2X2 = 296, + MAT2X3 = 297, + MAT2X4 = 298, + MAT3X2 = 299, + MAT3X3 = 300, + MAT3X4 = 301, + MAT4X2 = 302, + MAT4X3 = 303, + MAT4X4 = 304, + SAMPLER1D = 305, + SAMPLER2D = 306, + SAMPLER3D = 307, + SAMPLERCUBE = 308, + SAMPLER1DSHADOW = 309, + SAMPLER2DSHADOW = 310, + SAMPLERCUBESHADOW = 311, + SAMPLER1DARRAY = 312, + SAMPLER2DARRAY = 313, + SAMPLER1DARRAYSHADOW = 314, + SAMPLER2DARRAYSHADOW = 315, + ISAMPLER1D = 316, + ISAMPLER2D = 317, + ISAMPLER3D = 318, + ISAMPLERCUBE = 319, + ISAMPLER1DARRAY = 320, + ISAMPLER2DARRAY = 321, + USAMPLER1D = 322, + USAMPLER2D = 323, + USAMPLER3D = 324, + USAMPLERCUBE = 325, + USAMPLER1DARRAY = 326, + USAMPLER2DARRAY = 327, + STRUCT = 328, + VOID_TOK = 329, + WHILE = 330, + IDENTIFIER = 331, + TYPE_IDENTIFIER = 332, + NEW_IDENTIFIER = 333, + FLOATCONSTANT = 334, + INTCONSTANT = 335, + UINTCONSTANT = 336, + BOOLCONSTANT = 337, + FIELD_SELECTION = 338, + LEFT_OP = 339, + RIGHT_OP = 340, + INC_OP = 341, + DEC_OP = 342, + LE_OP = 343, + GE_OP = 344, + EQ_OP = 345, + NE_OP = 346, + AND_OP = 347, + OR_OP = 348, + XOR_OP = 349, + MUL_ASSIGN = 350, + DIV_ASSIGN = 351, + ADD_ASSIGN = 352, + MOD_ASSIGN = 353, + LEFT_ASSIGN = 354, + RIGHT_ASSIGN = 355, + AND_ASSIGN = 356, + XOR_ASSIGN = 357, + OR_ASSIGN = 358, + SUB_ASSIGN = 359, + INVARIANT = 360, + LOWP = 361, + MEDIUMP = 362, + HIGHP = 363, + SUPERP = 364, + PRECISION = 365, + VERSION = 366, + EXTENSION = 367, + LINE = 368, + COLON = 369, + EOL = 370, + INTERFACE = 371, + OUTPUT = 372, + PRAGMA_DEBUG_ON = 373, + PRAGMA_DEBUG_OFF = 374, + PRAGMA_OPTIMIZE_ON = 375, + PRAGMA_OPTIMIZE_OFF = 376, + PRAGMA_INVARIANT_ALL = 377, + LAYOUT_TOK = 378, + ASM = 379, + CLASS = 380, + UNION = 381, + ENUM = 382, + TYPEDEF = 383, + TEMPLATE = 384, + THIS = 385, + PACKED_TOK = 386, + GOTO = 387, + INLINE_TOK = 388, + NOINLINE = 389, + VOLATILE = 390, + PUBLIC_TOK = 391, + STATIC = 392, + EXTERN = 393, + EXTERNAL = 394, + LONG_TOK = 395, + SHORT_TOK = 396, + DOUBLE_TOK = 397, + HALF = 398, + FIXED_TOK = 399, + UNSIGNED = 400, + INPUT_TOK = 401, + OUPTUT = 402, + HVEC2 = 403, + HVEC3 = 404, + HVEC4 = 405, + DVEC2 = 406, + DVEC3 = 407, + DVEC4 = 408, + FVEC2 = 409, + FVEC3 = 410, + FVEC4 = 411, + SAMPLER2DRECT = 412, + SAMPLER3DRECT = 413, + SAMPLER2DRECTSHADOW = 414, + SIZEOF = 415, + CAST = 416, + NAMESPACE = 417, + USING = 418, + ERROR_TOK = 419, + COMMON = 420, + PARTITION = 421, + ACTIVE = 422, + SAMPLERBUFFER = 423, + FILTER = 424, + IMAGE1D = 425, + IMAGE2D = 426, + IMAGE3D = 427, + IMAGECUBE = 428, + IMAGE1DARRAY = 429, + IMAGE2DARRAY = 430, + IIMAGE1D = 431, + IIMAGE2D = 432, + IIMAGE3D = 433, + IIMAGECUBE = 434, + IIMAGE1DARRAY = 435, + IIMAGE2DARRAY = 436, + UIMAGE1D = 437, + UIMAGE2D = 438, + UIMAGE3D = 439, + UIMAGECUBE = 440, + UIMAGE1DARRAY = 441, + UIMAGE2DARRAY = 442, + IMAGE1DSHADOW = 443, + IMAGE2DSHADOW = 444, + IMAGEBUFFER = 445, + IIMAGEBUFFER = 446, + UIMAGEBUFFER = 447, + IMAGE1DARRAYSHADOW = 448, + IMAGE2DARRAYSHADOW = 449, + ROW_MAJOR = 450 + }; +#endif + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ + +/* Line 1685 of yacc.c */ +#line 52 "glsl_parser.ypp" + + int n; + float real; + char *identifier; + + struct ast_type_qualifier type_qualifier; + + ast_node *node; + ast_type_specifier *type_specifier; + ast_fully_specified_type *fully_specified_type; + ast_function *function; + ast_parameter_declarator *parameter_declarator; + ast_function_definition *function_definition; + ast_compound_statement *compound_statement; + ast_expression *expression; + ast_declarator_list *declarator_list; + ast_struct_specifier *struct_specifier; + ast_declaration *declaration; + + struct { + ast_node *cond; + ast_expression *rest; + } for_rest_statement; + + struct { + ast_node *then_statement; + ast_node *else_statement; + } selection_rest_statement; + + + +/* Line 1685 of yacc.c */ +#line 278 "glsl_parser.h" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + + + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + + diff --git a/src/glsl/glsl_parser.ypp b/src/glsl/glsl_parser.ypp new file mode 100644 index 0000000..eaace32 --- /dev/null +++ b/src/glsl/glsl_parser.ypp @@ -0,0 +1,1732 @@ +%{ +/* + * Copyright © 2008, 2009 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#include +#include +#include +#include + +#include "ast.h" +#include "glsl_parser_extras.h" +#include "glsl_types.h" + +#define YYLEX_PARAM state->scanner + +%} + +%pure-parser +%error-verbose + +%locations +%initial-action { + @$.first_line = 1; + @$.first_column = 1; + @$.last_line = 1; + @$.last_column = 1; + @$.source = 0; +} + +%lex-param {void *scanner} +%parse-param {struct _mesa_glsl_parse_state *state} + +%union { + int n; + float real; + char *identifier; + + struct ast_type_qualifier type_qualifier; + + ast_node *node; + ast_type_specifier *type_specifier; + ast_fully_specified_type *fully_specified_type; + ast_function *function; + ast_parameter_declarator *parameter_declarator; + ast_function_definition *function_definition; + ast_compound_statement *compound_statement; + ast_expression *expression; + ast_declarator_list *declarator_list; + ast_struct_specifier *struct_specifier; + ast_declaration *declaration; + + struct { + ast_node *cond; + ast_expression *rest; + } for_rest_statement; + + struct { + ast_node *then_statement; + ast_node *else_statement; + } selection_rest_statement; +} + +%token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK +%token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT +%token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4 +%token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING +%token NOPERSPECTIVE FLAT SMOOTH +%token MAT2X2 MAT2X3 MAT2X4 +%token MAT3X2 MAT3X3 MAT3X4 +%token MAT4X2 MAT4X3 MAT4X4 +%token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW +%token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW +%token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE +%token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D +%token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY +%token STRUCT VOID_TOK WHILE +%token IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER +%type any_identifier +%token FLOATCONSTANT +%token INTCONSTANT UINTCONSTANT BOOLCONSTANT +%token FIELD_SELECTION +%token LEFT_OP RIGHT_OP +%token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP +%token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN +%token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN +%token SUB_ASSIGN +%token INVARIANT +%token LOWP MEDIUMP HIGHP SUPERP PRECISION + +%token VERSION EXTENSION LINE COLON EOL INTERFACE OUTPUT +%token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF +%token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF +%token PRAGMA_INVARIANT_ALL +%token LAYOUT_TOK + + /* Reserved words that are not actually used in the grammar. + */ +%token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO +%token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL +%token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT +%token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4 +%token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW +%token SIZEOF CAST NAMESPACE USING + +%token ERROR_TOK + +%token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER +%token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY +%token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY +%token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY +%token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER +%token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW +%token ROW_MAJOR + +%type variable_identifier +%type statement +%type statement_list +%type simple_statement +%type precision_qualifier +%type type_qualifier +%type storage_qualifier +%type interpolation_qualifier +%type layout_qualifier +%type layout_qualifier_id_list layout_qualifier_id +%type type_specifier +%type type_specifier_no_prec +%type type_specifier_nonarray +%type basic_type_specifier_nonarray +%type fully_specified_type +%type function_prototype +%type function_header +%type function_header_with_parameters +%type function_declarator +%type parameter_declarator +%type parameter_declaration +%type parameter_qualifier +%type parameter_type_qualifier +%type parameter_type_specifier +%type function_definition +%type compound_statement_no_new_scope +%type compound_statement +%type statement_no_new_scope +%type expression_statement +%type expression +%type primary_expression +%type assignment_expression +%type conditional_expression +%type logical_or_expression +%type logical_xor_expression +%type logical_and_expression +%type inclusive_or_expression +%type exclusive_or_expression +%type and_expression +%type equality_expression +%type relational_expression +%type shift_expression +%type additive_expression +%type multiplicative_expression +%type unary_expression +%type constant_expression +%type integer_expression +%type postfix_expression +%type function_call_header_with_parameters +%type function_call_header_no_parameters +%type function_call_header +%type function_call_generic +%type function_call_or_method +%type function_call +%type method_call_generic +%type method_call_header_with_parameters +%type method_call_header_no_parameters +%type method_call_header +%type assignment_operator +%type unary_operator +%type function_identifier +%type external_declaration +%type init_declarator_list +%type single_declaration +%type initializer +%type declaration +%type declaration_statement +%type jump_statement +%type struct_specifier +%type struct_declaration_list +%type struct_declaration +%type struct_declarator +%type struct_declarator_list +%type selection_statement +%type selection_rest_statement +%type iteration_statement +%type condition +%type conditionopt +%type for_init_statement +%type for_rest_statement +%% + +translation_unit: + version_statement extension_statement_list + { + _mesa_glsl_initialize_types(state); + } + external_declaration_list + { + delete state->symbols; + state->symbols = new(ralloc_parent(state)) glsl_symbol_table; + _mesa_glsl_initialize_types(state); + } + ; + +version_statement: + /* blank - no #version specified: defaults are already set */ + | VERSION INTCONSTANT EOL + { + bool supported = false; + + switch ($2) { + case 100: + state->es_shader = true; + supported = state->Const.GLSL_100ES; + break; + case 110: + supported = state->Const.GLSL_110; + break; + case 120: + supported = state->Const.GLSL_120; + break; + case 130: + supported = state->Const.GLSL_130; + break; + default: + supported = false; + break; + } + + state->language_version = $2; + state->version_string = + ralloc_asprintf(state, "GLSL%s %d.%02d", + state->es_shader ? " ES" : "", + state->language_version / 100, + state->language_version % 100); + + if (!supported) { + _mesa_glsl_error(& @2, state, "%s is not supported. " + "Supported versions are: %s\n", + state->version_string, + state->supported_version_string); + } + } + ; + +pragma_statement: + PRAGMA_DEBUG_ON EOL + | PRAGMA_DEBUG_OFF EOL + | PRAGMA_OPTIMIZE_ON EOL + | PRAGMA_OPTIMIZE_OFF EOL + | PRAGMA_INVARIANT_ALL EOL + { + if (state->language_version < 120) { + _mesa_glsl_warning(& @1, state, + "pragma `invariant(all)' not supported in %s", + state->version_string); + } else { + state->all_invariant = true; + } + } + ; + +extension_statement_list: + + | extension_statement_list extension_statement + ; + +any_identifier: + IDENTIFIER + | TYPE_IDENTIFIER + | NEW_IDENTIFIER + ; + +extension_statement: + EXTENSION any_identifier COLON any_identifier EOL + { + if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) { + YYERROR; + } + } + ; + +external_declaration_list: + external_declaration + { + /* FINISHME: The NULL test is required because pragmas are set to + * FINISHME: NULL. (See production rule for external_declaration.) + */ + if ($1 != NULL) + state->translation_unit.push_tail(& $1->link); + } + | external_declaration_list external_declaration + { + /* FINISHME: The NULL test is required because pragmas are set to + * FINISHME: NULL. (See production rule for external_declaration.) + */ + if ($2 != NULL) + state->translation_unit.push_tail(& $2->link); + } + ; + +variable_identifier: + IDENTIFIER + | NEW_IDENTIFIER + ; + +primary_expression: + variable_identifier + { + void *ctx = state; + $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL); + $$->set_location(yylloc); + $$->primary_expression.identifier = $1; + } + | INTCONSTANT + { + void *ctx = state; + $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL); + $$->set_location(yylloc); + $$->primary_expression.int_constant = $1; + } + | UINTCONSTANT + { + void *ctx = state; + $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL); + $$->set_location(yylloc); + $$->primary_expression.uint_constant = $1; + } + | FLOATCONSTANT + { + void *ctx = state; + $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL); + $$->set_location(yylloc); + $$->primary_expression.float_constant = $1; + } + | BOOLCONSTANT + { + void *ctx = state; + $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL); + $$->set_location(yylloc); + $$->primary_expression.bool_constant = $1; + } + | '(' expression ')' + { + $$ = $2; + } + ; + +postfix_expression: + primary_expression + | postfix_expression '[' integer_expression ']' + { + void *ctx = state; + $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL); + $$->set_location(yylloc); + } + | function_call + { + $$ = $1; + } + | postfix_expression '.' any_identifier + { + void *ctx = state; + $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL); + $$->set_location(yylloc); + $$->primary_expression.identifier = $3; + } + | postfix_expression INC_OP + { + void *ctx = state; + $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL); + $$->set_location(yylloc); + } + | postfix_expression DEC_OP + { + void *ctx = state; + $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL); + $$->set_location(yylloc); + } + ; + +integer_expression: + expression + ; + +function_call: + function_call_or_method + ; + +function_call_or_method: + function_call_generic + | postfix_expression '.' method_call_generic + { + void *ctx = state; + $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL); + $$->set_location(yylloc); + } + ; + +function_call_generic: + function_call_header_with_parameters ')' + | function_call_header_no_parameters ')' + ; + +function_call_header_no_parameters: + function_call_header VOID_TOK + | function_call_header + ; + +function_call_header_with_parameters: + function_call_header assignment_expression + { + $$ = $1; + $$->set_location(yylloc); + $$->expressions.push_tail(& $2->link); + } + | function_call_header_with_parameters ',' assignment_expression + { + $$ = $1; + $$->set_location(yylloc); + $$->expressions.push_tail(& $3->link); + } + ; + + // Grammar Note: Constructors look like functions, but lexical + // analysis recognized most of them as keywords. They are now + // recognized through "type_specifier". +function_call_header: + function_identifier '(' + ; + +function_identifier: + type_specifier + { + void *ctx = state; + $$ = new(ctx) ast_function_expression($1); + $$->set_location(yylloc); + } + | variable_identifier + { + void *ctx = state; + ast_expression *callee = new(ctx) ast_expression($1); + $$ = new(ctx) ast_function_expression(callee); + $$->set_location(yylloc); + } + | FIELD_SELECTION + { + void *ctx = state; + ast_expression *callee = new(ctx) ast_expression($1); + $$ = new(ctx) ast_function_expression(callee); + $$->set_location(yylloc); + } + ; + +method_call_generic: + method_call_header_with_parameters ')' + | method_call_header_no_parameters ')' + ; + +method_call_header_no_parameters: + method_call_header VOID_TOK + | method_call_header + ; + +method_call_header_with_parameters: + method_call_header assignment_expression + { + $$ = $1; + $$->set_location(yylloc); + $$->expressions.push_tail(& $2->link); + } + | method_call_header_with_parameters ',' assignment_expression + { + $$ = $1; + $$->set_location(yylloc); + $$->expressions.push_tail(& $3->link); + } + ; + + // Grammar Note: Constructors look like methods, but lexical + // analysis recognized most of them as keywords. They are now + // recognized through "type_specifier". +method_call_header: + variable_identifier '(' + { + void *ctx = state; + ast_expression *callee = new(ctx) ast_expression($1); + $$ = new(ctx) ast_function_expression(callee); + $$->set_location(yylloc); + } + ; + + // Grammar Note: No traditional style type casts. +unary_expression: + postfix_expression + | INC_OP unary_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL); + $$->set_location(yylloc); + } + | DEC_OP unary_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL); + $$->set_location(yylloc); + } + | unary_operator unary_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression($1, $2, NULL, NULL); + $$->set_location(yylloc); + } + ; + + // Grammar Note: No '*' or '&' unary ops. Pointers are not supported. +unary_operator: + '+' { $$ = ast_plus; } + | '-' { $$ = ast_neg; } + | '!' { $$ = ast_logic_not; } + | '~' { $$ = ast_bit_not; } + ; + +multiplicative_expression: + unary_expression + | multiplicative_expression '*' unary_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3); + $$->set_location(yylloc); + } + | multiplicative_expression '/' unary_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_div, $1, $3); + $$->set_location(yylloc); + } + | multiplicative_expression '%' unary_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3); + $$->set_location(yylloc); + } + ; + +additive_expression: + multiplicative_expression + | additive_expression '+' multiplicative_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_add, $1, $3); + $$->set_location(yylloc); + } + | additive_expression '-' multiplicative_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3); + $$->set_location(yylloc); + } + ; + +shift_expression: + additive_expression + | shift_expression LEFT_OP additive_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3); + $$->set_location(yylloc); + } + | shift_expression RIGHT_OP additive_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3); + $$->set_location(yylloc); + } + ; + +relational_expression: + shift_expression + | relational_expression '<' shift_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_less, $1, $3); + $$->set_location(yylloc); + } + | relational_expression '>' shift_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3); + $$->set_location(yylloc); + } + | relational_expression LE_OP shift_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3); + $$->set_location(yylloc); + } + | relational_expression GE_OP shift_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3); + $$->set_location(yylloc); + } + ; + +equality_expression: + relational_expression + | equality_expression EQ_OP relational_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3); + $$->set_location(yylloc); + } + | equality_expression NE_OP relational_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3); + $$->set_location(yylloc); + } + ; + +and_expression: + equality_expression + | and_expression '&' equality_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3); + $$->set_location(yylloc); + } + ; + +exclusive_or_expression: + and_expression + | exclusive_or_expression '^' and_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3); + $$->set_location(yylloc); + } + ; + +inclusive_or_expression: + exclusive_or_expression + | inclusive_or_expression '|' exclusive_or_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3); + $$->set_location(yylloc); + } + ; + +logical_and_expression: + inclusive_or_expression + | logical_and_expression AND_OP inclusive_or_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3); + $$->set_location(yylloc); + } + ; + +logical_xor_expression: + logical_and_expression + | logical_xor_expression XOR_OP logical_and_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3); + $$->set_location(yylloc); + } + ; + +logical_or_expression: + logical_xor_expression + | logical_or_expression OR_OP logical_xor_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3); + $$->set_location(yylloc); + } + ; + +conditional_expression: + logical_or_expression + | logical_or_expression '?' expression ':' assignment_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5); + $$->set_location(yylloc); + } + ; + +assignment_expression: + conditional_expression + | unary_expression assignment_operator assignment_expression + { + void *ctx = state; + $$ = new(ctx) ast_expression($2, $1, $3, NULL); + $$->set_location(yylloc); + } + ; + +assignment_operator: + '=' { $$ = ast_assign; } + | MUL_ASSIGN { $$ = ast_mul_assign; } + | DIV_ASSIGN { $$ = ast_div_assign; } + | MOD_ASSIGN { $$ = ast_mod_assign; } + | ADD_ASSIGN { $$ = ast_add_assign; } + | SUB_ASSIGN { $$ = ast_sub_assign; } + | LEFT_ASSIGN { $$ = ast_ls_assign; } + | RIGHT_ASSIGN { $$ = ast_rs_assign; } + | AND_ASSIGN { $$ = ast_and_assign; } + | XOR_ASSIGN { $$ = ast_xor_assign; } + | OR_ASSIGN { $$ = ast_or_assign; } + ; + +expression: + assignment_expression + { + $$ = $1; + } + | expression ',' assignment_expression + { + void *ctx = state; + if ($1->oper != ast_sequence) { + $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL); + $$->set_location(yylloc); + $$->expressions.push_tail(& $1->link); + } else { + $$ = $1; + } + + $$->expressions.push_tail(& $3->link); + } + ; + +constant_expression: + conditional_expression + ; + +declaration: + function_prototype ';' + { + state->symbols->pop_scope(); + $$ = $1; + } + | init_declarator_list ';' + { + $$ = $1; + } + | PRECISION precision_qualifier type_specifier_no_prec ';' + { + $3->precision = $2; + $3->is_precision_statement = true; + $$ = $3; + } + ; + +function_prototype: + function_declarator ')' + ; + +function_declarator: + function_header + | function_header_with_parameters + ; + +function_header_with_parameters: + function_header parameter_declaration + { + $$ = $1; + $$->parameters.push_tail(& $2->link); + } + | function_header_with_parameters ',' parameter_declaration + { + $$ = $1; + $$->parameters.push_tail(& $3->link); + } + ; + +function_header: + fully_specified_type variable_identifier '(' + { + void *ctx = state; + $$ = new(ctx) ast_function(); + $$->set_location(yylloc); + $$->return_type = $1; + $$->identifier = $2; + + state->symbols->add_function(new(state) ir_function($2)); + state->symbols->push_scope(); + } + ; + +parameter_declarator: + type_specifier any_identifier + { + void *ctx = state; + $$ = new(ctx) ast_parameter_declarator(); + $$->set_location(yylloc); + $$->type = new(ctx) ast_fully_specified_type(); + $$->type->set_location(yylloc); + $$->type->specifier = $1; + $$->identifier = $2; + } + | type_specifier any_identifier '[' constant_expression ']' + { + void *ctx = state; + $$ = new(ctx) ast_parameter_declarator(); + $$->set_location(yylloc); + $$->type = new(ctx) ast_fully_specified_type(); + $$->type->set_location(yylloc); + $$->type->specifier = $1; + $$->identifier = $2; + $$->is_array = true; + $$->array_size = $4; + } + ; + +parameter_declaration: + parameter_type_qualifier parameter_qualifier parameter_declarator + { + $1.flags.i |= $2.flags.i; + + $$ = $3; + $$->type->qualifier = $1; + } + | parameter_qualifier parameter_declarator + { + $$ = $2; + $$->type->qualifier = $1; + } + | parameter_type_qualifier parameter_qualifier parameter_type_specifier + { + void *ctx = state; + $1.flags.i |= $2.flags.i; + + $$ = new(ctx) ast_parameter_declarator(); + $$->set_location(yylloc); + $$->type = new(ctx) ast_fully_specified_type(); + $$->type->qualifier = $1; + $$->type->specifier = $3; + } + | parameter_qualifier parameter_type_specifier + { + void *ctx = state; + $$ = new(ctx) ast_parameter_declarator(); + $$->set_location(yylloc); + $$->type = new(ctx) ast_fully_specified_type(); + $$->type->qualifier = $1; + $$->type->specifier = $2; + } + ; + +parameter_qualifier: + /* empty */ + { + memset(& $$, 0, sizeof($$)); + } + | IN_TOK + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.in = 1; + } + | OUT_TOK + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.out = 1; + } + | INOUT_TOK + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.in = 1; + $$.flags.q.out = 1; + } + ; + +parameter_type_specifier: + type_specifier + ; + +init_declarator_list: + single_declaration + | init_declarator_list ',' any_identifier + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL); + decl->set_location(yylloc); + + $$ = $1; + $$->declarations.push_tail(&decl->link); + state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); + } + | init_declarator_list ',' any_identifier '[' ']' + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL); + decl->set_location(yylloc); + + $$ = $1; + $$->declarations.push_tail(&decl->link); + state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); + } + | init_declarator_list ',' any_identifier '[' constant_expression ']' + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL); + decl->set_location(yylloc); + + $$ = $1; + $$->declarations.push_tail(&decl->link); + state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); + } + | init_declarator_list ',' any_identifier '[' ']' '=' initializer + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7); + decl->set_location(yylloc); + + $$ = $1; + $$->declarations.push_tail(&decl->link); + state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); + } + | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8); + decl->set_location(yylloc); + + $$ = $1; + $$->declarations.push_tail(&decl->link); + state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); + } + | init_declarator_list ',' any_identifier '=' initializer + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5); + decl->set_location(yylloc); + + $$ = $1; + $$->declarations.push_tail(&decl->link); + state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); + } + ; + + // Grammar Note: No 'enum', or 'typedef'. +single_declaration: + fully_specified_type + { + void *ctx = state; + if ($1->specifier->type_specifier != ast_struct) { + _mesa_glsl_error(& @1, state, "empty declaration list\n"); + YYERROR; + } else { + $$ = new(ctx) ast_declarator_list($1); + $$->set_location(yylloc); + } + } + | fully_specified_type any_identifier + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL); + + $$ = new(ctx) ast_declarator_list($1); + $$->set_location(yylloc); + $$->declarations.push_tail(&decl->link); + } + | fully_specified_type any_identifier '[' ']' + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL); + + $$ = new(ctx) ast_declarator_list($1); + $$->set_location(yylloc); + $$->declarations.push_tail(&decl->link); + } + | fully_specified_type any_identifier '[' constant_expression ']' + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL); + + $$ = new(ctx) ast_declarator_list($1); + $$->set_location(yylloc); + $$->declarations.push_tail(&decl->link); + } + | fully_specified_type any_identifier '[' ']' '=' initializer + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6); + + $$ = new(ctx) ast_declarator_list($1); + $$->set_location(yylloc); + $$->declarations.push_tail(&decl->link); + } + | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7); + + $$ = new(ctx) ast_declarator_list($1); + $$->set_location(yylloc); + $$->declarations.push_tail(&decl->link); + } + | fully_specified_type any_identifier '=' initializer + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4); + + $$ = new(ctx) ast_declarator_list($1); + $$->set_location(yylloc); + $$->declarations.push_tail(&decl->link); + } + | INVARIANT variable_identifier // Vertex only. + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL); + + $$ = new(ctx) ast_declarator_list(NULL); + $$->set_location(yylloc); + $$->invariant = true; + + $$->declarations.push_tail(&decl->link); + } + ; + +fully_specified_type: + type_specifier + { + void *ctx = state; + $$ = new(ctx) ast_fully_specified_type(); + $$->set_location(yylloc); + $$->specifier = $1; + } + | type_qualifier type_specifier + { + void *ctx = state; + $$ = new(ctx) ast_fully_specified_type(); + $$->set_location(yylloc); + $$->qualifier = $1; + $$->specifier = $2; + } + ; + +layout_qualifier: + LAYOUT_TOK '(' layout_qualifier_id_list ')' + { + $$ = $3; + } + ; + +layout_qualifier_id_list: + layout_qualifier_id + | layout_qualifier_id_list ',' layout_qualifier_id + { + if (($1.flags.i & $3.flags.i) != 0) { + _mesa_glsl_error(& @3, state, + "duplicate layout qualifiers used\n"); + YYERROR; + } + + $$.flags.i = $1.flags.i | $3.flags.i; + + if ($1.flags.q.explicit_location) + $$.location = $1.location; + + if ($3.flags.q.explicit_location) + $$.location = $3.location; + } + ; + +layout_qualifier_id: + any_identifier + { + bool got_one = false; + + memset(& $$, 0, sizeof($$)); + + if (state->ARB_fragment_coord_conventions_enable) { + if (strcmp($1, "origin_upper_left") == 0) { + got_one = true; + $$.flags.q.origin_upper_left = 1; + } else if (strcmp($1, "pixel_center_integer") == 0) { + got_one = true; + $$.flags.q.pixel_center_integer = 1; + } + } + + /* If the identifier didn't match any known layout identifiers, + * emit an error. + */ + if (!got_one) { + _mesa_glsl_error(& @1, state, "unrecognized layout identifier " + "`%s'\n", $1); + YYERROR; + } else if (state->ARB_fragment_coord_conventions_warn) { + _mesa_glsl_warning(& @1, state, + "GL_ARB_fragment_coord_conventions layout " + "identifier `%s' used\n", $1); + } + } + | any_identifier '=' INTCONSTANT + { + bool got_one = false; + + memset(& $$, 0, sizeof($$)); + + if (state->ARB_explicit_attrib_location_enable) { + /* FINISHME: Handle 'index' once GL_ARB_blend_func_exteneded and + * FINISHME: GLSL 1.30 (or later) are supported. + */ + if (strcmp("location", $1) == 0) { + got_one = true; + + $$.flags.q.explicit_location = 1; + + if ($3 >= 0) { + $$.location = $3; + } else { + _mesa_glsl_error(& @3, state, + "invalid location %d specified\n", $3); + YYERROR; + } + } + } + + /* If the identifier didn't match any known layout identifiers, + * emit an error. + */ + if (!got_one) { + _mesa_glsl_error(& @1, state, "unrecognized layout identifier " + "`%s'\n", $1); + YYERROR; + } else if (state->ARB_explicit_attrib_location_warn) { + _mesa_glsl_warning(& @1, state, + "GL_ARB_explicit_attrib_location layout " + "identifier `%s' used\n", $1); + } + } + ; + +interpolation_qualifier: + SMOOTH + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.smooth = 1; + } + | FLAT + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.flat = 1; + } + | NOPERSPECTIVE + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.noperspective = 1; + } + ; + +parameter_type_qualifier: + CONST_TOK + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.constant = 1; + } + ; + +type_qualifier: + storage_qualifier + | layout_qualifier + | layout_qualifier storage_qualifier + { + $$ = $1; + $$.flags.i |= $2.flags.i; + } + | interpolation_qualifier + | interpolation_qualifier storage_qualifier + { + $$ = $1; + $$.flags.i |= $2.flags.i; + } + | INVARIANT storage_qualifier + { + $$ = $2; + $$.flags.q.invariant = 1; + } + | INVARIANT interpolation_qualifier storage_qualifier + { + $$ = $2; + $$.flags.i |= $3.flags.i; + $$.flags.q.invariant = 1; + } + | INVARIANT + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.invariant = 1; + } + ; + +storage_qualifier: + CONST_TOK + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.constant = 1; + } + | ATTRIBUTE + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.attribute = 1; + } + | VARYING + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.varying = 1; + } + | CENTROID VARYING + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.centroid = 1; + $$.flags.q.varying = 1; + } + | IN_TOK + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.in = 1; + } + | OUT_TOK + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.out = 1; + } + | CENTROID IN_TOK + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.centroid = 1; $$.flags.q.in = 1; + } + | CENTROID OUT_TOK + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.centroid = 1; $$.flags.q.out = 1; + } + | UNIFORM + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.uniform = 1; + } + ; + +type_specifier: + type_specifier_no_prec + { + $$ = $1; + } + | precision_qualifier type_specifier_no_prec + { + $$ = $2; + $$->precision = $1; + } + ; + +type_specifier_no_prec: + type_specifier_nonarray + | type_specifier_nonarray '[' ']' + { + $$ = $1; + $$->is_array = true; + $$->array_size = NULL; + } + | type_specifier_nonarray '[' constant_expression ']' + { + $$ = $1; + $$->is_array = true; + $$->array_size = $3; + } + ; + +type_specifier_nonarray: + basic_type_specifier_nonarray + { + void *ctx = state; + $$ = new(ctx) ast_type_specifier($1); + $$->set_location(yylloc); + } + | struct_specifier + { + void *ctx = state; + $$ = new(ctx) ast_type_specifier($1); + $$->set_location(yylloc); + } + | TYPE_IDENTIFIER + { + void *ctx = state; + $$ = new(ctx) ast_type_specifier($1); + $$->set_location(yylloc); + } + ; + +basic_type_specifier_nonarray: + VOID_TOK { $$ = ast_void; } + | FLOAT_TOK { $$ = ast_float; } + | INT_TOK { $$ = ast_int; } + | UINT_TOK { $$ = ast_uint; } + | BOOL_TOK { $$ = ast_bool; } + | VEC2 { $$ = ast_vec2; } + | VEC3 { $$ = ast_vec3; } + | VEC4 { $$ = ast_vec4; } + | BVEC2 { $$ = ast_bvec2; } + | BVEC3 { $$ = ast_bvec3; } + | BVEC4 { $$ = ast_bvec4; } + | IVEC2 { $$ = ast_ivec2; } + | IVEC3 { $$ = ast_ivec3; } + | IVEC4 { $$ = ast_ivec4; } + | UVEC2 { $$ = ast_uvec2; } + | UVEC3 { $$ = ast_uvec3; } + | UVEC4 { $$ = ast_uvec4; } + | MAT2X2 { $$ = ast_mat2; } + | MAT2X3 { $$ = ast_mat2x3; } + | MAT2X4 { $$ = ast_mat2x4; } + | MAT3X2 { $$ = ast_mat3x2; } + | MAT3X3 { $$ = ast_mat3; } + | MAT3X4 { $$ = ast_mat3x4; } + | MAT4X2 { $$ = ast_mat4x2; } + | MAT4X3 { $$ = ast_mat4x3; } + | MAT4X4 { $$ = ast_mat4; } + | SAMPLER1D { $$ = ast_sampler1d; } + | SAMPLER2D { $$ = ast_sampler2d; } + | SAMPLER2DRECT { $$ = ast_sampler2drect; } + | SAMPLER3D { $$ = ast_sampler3d; } + | SAMPLERCUBE { $$ = ast_samplercube; } + | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; } + | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; } + | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; } + | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; } + | SAMPLER1DARRAY { $$ = ast_sampler1darray; } + | SAMPLER2DARRAY { $$ = ast_sampler2darray; } + | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; } + | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; } + | ISAMPLER1D { $$ = ast_isampler1d; } + | ISAMPLER2D { $$ = ast_isampler2d; } + | ISAMPLER3D { $$ = ast_isampler3d; } + | ISAMPLERCUBE { $$ = ast_isamplercube; } + | ISAMPLER1DARRAY { $$ = ast_isampler1darray; } + | ISAMPLER2DARRAY { $$ = ast_isampler2darray; } + | USAMPLER1D { $$ = ast_usampler1d; } + | USAMPLER2D { $$ = ast_usampler2d; } + | USAMPLER3D { $$ = ast_usampler3d; } + | USAMPLERCUBE { $$ = ast_usamplercube; } + | USAMPLER1DARRAY { $$ = ast_usampler1darray; } + | USAMPLER2DARRAY { $$ = ast_usampler2darray; } + ; + +precision_qualifier: + HIGHP { + if (!state->es_shader && state->language_version < 130) + _mesa_glsl_error(& @1, state, + "precision qualifier forbidden " + "in %s (1.30 or later " + "required)\n", + state->version_string); + + $$ = ast_precision_high; + } + | MEDIUMP { + if (!state->es_shader && state->language_version < 130) + _mesa_glsl_error(& @1, state, + "precision qualifier forbidden " + "in %s (1.30 or later " + "required)\n", + state->version_string); + + $$ = ast_precision_medium; + } + | LOWP { + if (!state->es_shader && state->language_version < 130) + _mesa_glsl_error(& @1, state, + "precision qualifier forbidden " + "in %s (1.30 or later " + "required)\n", + state->version_string); + + $$ = ast_precision_low; + } + ; + +struct_specifier: + STRUCT any_identifier '{' struct_declaration_list '}' + { + void *ctx = state; + $$ = new(ctx) ast_struct_specifier($2, $4); + $$->set_location(yylloc); + state->symbols->add_type($2, glsl_type::void_type); + } + | STRUCT '{' struct_declaration_list '}' + { + void *ctx = state; + $$ = new(ctx) ast_struct_specifier(NULL, $3); + $$->set_location(yylloc); + } + ; + +struct_declaration_list: + struct_declaration + { + $$ = (ast_node *) $1; + $1->link.self_link(); + } + | struct_declaration_list struct_declaration + { + $$ = (ast_node *) $1; + $$->link.insert_before(& $2->link); + } + ; + +struct_declaration: + type_specifier struct_declarator_list ';' + { + void *ctx = state; + ast_fully_specified_type *type = new(ctx) ast_fully_specified_type(); + type->set_location(yylloc); + + type->specifier = $1; + $$ = new(ctx) ast_declarator_list(type); + $$->set_location(yylloc); + + $$->declarations.push_degenerate_list_at_head(& $2->link); + } + ; + +struct_declarator_list: + struct_declarator + { + $$ = $1; + $1->link.self_link(); + } + | struct_declarator_list ',' struct_declarator + { + $$ = $1; + $$->link.insert_before(& $3->link); + } + ; + +struct_declarator: + any_identifier + { + void *ctx = state; + $$ = new(ctx) ast_declaration($1, false, NULL, NULL); + $$->set_location(yylloc); + state->symbols->add_variable(new(state) ir_variable(NULL, $1, ir_var_auto)); + } + | any_identifier '[' constant_expression ']' + { + void *ctx = state; + $$ = new(ctx) ast_declaration($1, true, $3, NULL); + $$->set_location(yylloc); + } + ; + +initializer: + assignment_expression + ; + +declaration_statement: + declaration + ; + + // Grammar Note: labeled statements for SWITCH only; 'goto' is not + // supported. +statement: + compound_statement { $$ = (ast_node *) $1; } + | simple_statement + ; + +simple_statement: + declaration_statement + | expression_statement + | selection_statement + | switch_statement { $$ = NULL; } + | case_label { $$ = NULL; } + | iteration_statement + | jump_statement + ; + +compound_statement: + '{' '}' + { + void *ctx = state; + $$ = new(ctx) ast_compound_statement(true, NULL); + $$->set_location(yylloc); + } + | '{' + { + state->symbols->push_scope(); + } + statement_list '}' + { + void *ctx = state; + $$ = new(ctx) ast_compound_statement(true, $3); + $$->set_location(yylloc); + state->symbols->pop_scope(); + } + ; + +statement_no_new_scope: + compound_statement_no_new_scope { $$ = (ast_node *) $1; } + | simple_statement + ; + +compound_statement_no_new_scope: + '{' '}' + { + void *ctx = state; + $$ = new(ctx) ast_compound_statement(false, NULL); + $$->set_location(yylloc); + } + | '{' statement_list '}' + { + void *ctx = state; + $$ = new(ctx) ast_compound_statement(false, $2); + $$->set_location(yylloc); + } + ; + +statement_list: + statement + { + if ($1 == NULL) { + _mesa_glsl_error(& @1, state, " statement\n"); + assert($1 != NULL); + } + + $$ = $1; + $$->link.self_link(); + } + | statement_list statement + { + if ($2 == NULL) { + _mesa_glsl_error(& @2, state, " statement\n"); + assert($2 != NULL); + } + $$ = $1; + $$->link.insert_before(& $2->link); + } + ; + +expression_statement: + ';' + { + void *ctx = state; + $$ = new(ctx) ast_expression_statement(NULL); + $$->set_location(yylloc); + } + | expression ';' + { + void *ctx = state; + $$ = new(ctx) ast_expression_statement($1); + $$->set_location(yylloc); + } + ; + +selection_statement: + IF '(' expression ')' selection_rest_statement + { + $$ = new(state) ast_selection_statement($3, $5.then_statement, + $5.else_statement); + $$->set_location(yylloc); + } + ; + +selection_rest_statement: + statement ELSE statement + { + $$.then_statement = $1; + $$.else_statement = $3; + } + | statement + { + $$.then_statement = $1; + $$.else_statement = NULL; + } + ; + +condition: + expression + { + $$ = (ast_node *) $1; + } + | fully_specified_type any_identifier '=' initializer + { + void *ctx = state; + ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4); + ast_declarator_list *declarator = new(ctx) ast_declarator_list($1); + decl->set_location(yylloc); + declarator->set_location(yylloc); + + declarator->declarations.push_tail(&decl->link); + $$ = declarator; + } + ; + +switch_statement: + SWITCH '(' expression ')' compound_statement + ; + +case_label: + CASE expression ':' + | DEFAULT ':' + ; + +iteration_statement: + WHILE '(' condition ')' statement_no_new_scope + { + void *ctx = state; + $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while, + NULL, $3, NULL, $5); + $$->set_location(yylloc); + } + | DO statement WHILE '(' expression ')' ';' + { + void *ctx = state; + $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while, + NULL, $5, NULL, $2); + $$->set_location(yylloc); + } + | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope + { + void *ctx = state; + $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for, + $3, $4.cond, $4.rest, $6); + $$->set_location(yylloc); + } + ; + +for_init_statement: + expression_statement + | declaration_statement + ; + +conditionopt: + condition + | /* empty */ + { + $$ = NULL; + } + ; + +for_rest_statement: + conditionopt ';' + { + $$.cond = $1; + $$.rest = NULL; + } + | conditionopt ';' expression + { + $$.cond = $1; + $$.rest = $3; + } + ; + + // Grammar Note: No 'goto'. Gotos are not supported. +jump_statement: + CONTINUE ';' + { + void *ctx = state; + $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL); + $$->set_location(yylloc); + } + | BREAK ';' + { + void *ctx = state; + $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL); + $$->set_location(yylloc); + } + | RETURN ';' + { + void *ctx = state; + $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL); + $$->set_location(yylloc); + } + | RETURN expression ';' + { + void *ctx = state; + $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2); + $$->set_location(yylloc); + } + | DISCARD ';' // Fragment shader only. + { + void *ctx = state; + $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL); + $$->set_location(yylloc); + } + ; + +external_declaration: + function_definition { $$ = $1; } + | declaration { $$ = $1; } + | pragma_statement { $$ = NULL; } + ; + +function_definition: + function_prototype compound_statement_no_new_scope + { + void *ctx = state; + $$ = new(ctx) ast_function_definition(); + $$->set_location(yylloc); + $$->prototype = $1; + $$->body = $2; + + state->symbols->pop_scope(); + } + ; diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp new file mode 100644 index 0000000..3a17db8 --- /dev/null +++ b/src/glsl/glsl_parser_extras.cpp @@ -0,0 +1,807 @@ +/* + * Copyright © 2008, 2009 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#include +#include +#include +#include + +extern "C" { +#include "main/core.h" /* for struct gl_context */ +} + +#include "ralloc.h" +#include "ast.h" +#include "glsl_parser_extras.h" +#include "glsl_parser.h" +#include "ir_optimization.h" +#include "loop_analysis.h" + +_mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *ctx, + GLenum target, void *mem_ctx) +{ + switch (target) { + case GL_VERTEX_SHADER: this->target = vertex_shader; break; + case GL_FRAGMENT_SHADER: this->target = fragment_shader; break; + case GL_GEOMETRY_SHADER: this->target = geometry_shader; break; + } + + this->scanner = NULL; + this->translation_unit.make_empty(); + this->symbols = new(mem_ctx) glsl_symbol_table; + this->info_log = ralloc_strdup(mem_ctx, ""); + this->error = false; + this->loop_or_switch_nesting = NULL; + + /* Set default language version and extensions */ + this->language_version = 110; + this->es_shader = false; + this->ARB_texture_rectangle_enable = true; + + /* OpenGL ES 2.0 has different defaults from desktop GL. */ + if (ctx->API == API_OPENGLES2) { + this->language_version = 100; + this->es_shader = true; + this->ARB_texture_rectangle_enable = false; + } + + this->extensions = &ctx->Extensions; + + this->Const.MaxLights = ctx->Const.MaxLights; + this->Const.MaxClipPlanes = ctx->Const.MaxClipPlanes; + this->Const.MaxTextureUnits = ctx->Const.MaxTextureUnits; + this->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits; + this->Const.MaxVertexAttribs = ctx->Const.VertexProgram.MaxAttribs; + this->Const.MaxVertexUniformComponents = ctx->Const.VertexProgram.MaxUniformComponents; + this->Const.MaxVaryingFloats = ctx->Const.MaxVarying * 4; + this->Const.MaxVertexTextureImageUnits = ctx->Const.MaxVertexTextureImageUnits; + this->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxCombinedTextureImageUnits; + this->Const.MaxTextureImageUnits = ctx->Const.MaxTextureImageUnits; + this->Const.MaxFragmentUniformComponents = ctx->Const.FragmentProgram.MaxUniformComponents; + + this->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers; + + /* Note: Once the OpenGL 3.0 'forward compatible' context or the OpenGL 3.2 + * Core context is supported, this logic will need change. Older versions of + * GLSL are no longer supported outside the compatibility contexts of 3.x. + */ + this->Const.GLSL_100ES = (ctx->API == API_OPENGLES2) + || ctx->Extensions.ARB_ES2_compatibility; + this->Const.GLSL_110 = (ctx->API == API_OPENGL); + this->Const.GLSL_120 = (ctx->API == API_OPENGL) + && (ctx->Const.GLSLVersion >= 120); + this->Const.GLSL_130 = (ctx->API == API_OPENGL) + && (ctx->Const.GLSLVersion >= 130); + + const unsigned lowest_version = + (ctx->API == API_OPENGLES2) || ctx->Extensions.ARB_ES2_compatibility + ? 100 : 110; + const unsigned highest_version = + (ctx->API == API_OPENGL) ? ctx->Const.GLSLVersion : 100; + char *supported = (char *) ralloc_context(this); + + for (unsigned ver = lowest_version; ver <= highest_version; ver += 10) { + const char *const prefix = (ver == lowest_version) + ? "" + : ((ver == highest_version) ? ", and " : ", "); + + ralloc_asprintf_append(& supported, "%s%d.%02d%s", + prefix, + ver / 100, ver % 100, + (ver == 100) ? " ES" : ""); + } + + this->supported_version_string = supported; +} + +const char * +_mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target) +{ + switch (target) { + case vertex_shader: return "vertex"; + case fragment_shader: return "fragment"; + case geometry_shader: return "geometry"; + } + + assert(!"Should not get here."); + return "unknown"; +} + + +void +_mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state, + const char *fmt, ...) +{ + va_list ap; + + state->error = true; + + assert(state->info_log != NULL); + ralloc_asprintf_append(&state->info_log, "%u:%u(%u): error: ", + locp->source, + locp->first_line, + locp->first_column); + va_start(ap, fmt); + ralloc_vasprintf_append(&state->info_log, fmt, ap); + va_end(ap); + ralloc_strcat(&state->info_log, "\n"); +} + + +void +_mesa_glsl_warning(const YYLTYPE *locp, _mesa_glsl_parse_state *state, + const char *fmt, ...) +{ + va_list ap; + + assert(state->info_log != NULL); + ralloc_asprintf_append(&state->info_log, "%u:%u(%u): warning: ", + locp->source, + locp->first_line, + locp->first_column); + va_start(ap, fmt); + ralloc_vasprintf_append(&state->info_log, fmt, ap); + va_end(ap); + ralloc_strcat(&state->info_log, "\n"); +} + + +bool +_mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp, + const char *behavior, YYLTYPE *behavior_locp, + _mesa_glsl_parse_state *state) +{ + enum { + extension_disable, + extension_enable, + extension_require, + extension_warn + } ext_mode; + + if (strcmp(behavior, "warn") == 0) { + ext_mode = extension_warn; + } else if (strcmp(behavior, "require") == 0) { + ext_mode = extension_require; + } else if (strcmp(behavior, "enable") == 0) { + ext_mode = extension_enable; + } else if (strcmp(behavior, "disable") == 0) { + ext_mode = extension_disable; + } else { + _mesa_glsl_error(behavior_locp, state, + "Unknown extension behavior `%s'", + behavior); + return false; + } + + bool unsupported = false; + + if (strcmp(name, "all") == 0) { + if ((ext_mode == extension_enable) || (ext_mode == extension_require)) { + _mesa_glsl_error(name_locp, state, "Cannot %s all extensions", + (ext_mode == extension_enable) + ? "enable" : "require"); + return false; + } + } else if (strcmp(name, "GL_ARB_draw_buffers") == 0) { + /* This extension is only supported in fragment shaders. + */ + if (state->target != fragment_shader) { + unsupported = true; + } else { + state->ARB_draw_buffers_enable = (ext_mode != extension_disable); + state->ARB_draw_buffers_warn = (ext_mode == extension_warn); + } + } else if (strcmp(name, "GL_ARB_explicit_attrib_location") == 0) { + state->ARB_explicit_attrib_location_enable = + (ext_mode != extension_disable); + state->ARB_explicit_attrib_location_warn = + (ext_mode == extension_warn); + + unsupported = !state->extensions->ARB_explicit_attrib_location; + } else if (strcmp(name, "GL_ARB_fragment_coord_conventions") == 0) { + state->ARB_fragment_coord_conventions_enable = + (ext_mode != extension_disable); + state->ARB_fragment_coord_conventions_warn = + (ext_mode == extension_warn); + + unsupported = !state->extensions->ARB_fragment_coord_conventions; + } else if (strcmp(name, "GL_ARB_texture_rectangle") == 0) { + state->ARB_texture_rectangle_enable = (ext_mode != extension_disable); + state->ARB_texture_rectangle_warn = (ext_mode == extension_warn); + } else if (strcmp(name, "GL_EXT_texture_array") == 0) { + state->EXT_texture_array_enable = (ext_mode != extension_disable); + state->EXT_texture_array_warn = (ext_mode == extension_warn); + + unsupported = !state->extensions->EXT_texture_array; + } else if (strcmp(name, "GL_ARB_shader_stencil_export") == 0) { + if (state->target != fragment_shader) { + unsupported = true; + } else { + state->ARB_shader_stencil_export_enable = (ext_mode != extension_disable); + state->ARB_shader_stencil_export_warn = (ext_mode == extension_warn); + unsupported = !state->extensions->ARB_shader_stencil_export; + } + } else { + unsupported = true; + } + + if (unsupported) { + static const char *const fmt = "extension `%s' unsupported in %s shader"; + + if (ext_mode == extension_require) { + _mesa_glsl_error(name_locp, state, fmt, + name, _mesa_glsl_shader_target_name(state->target)); + return false; + } else { + _mesa_glsl_warning(name_locp, state, fmt, + name, _mesa_glsl_shader_target_name(state->target)); + } + } + + return true; +} + +void +_mesa_ast_type_qualifier_print(const struct ast_type_qualifier *q) +{ + if (q->flags.q.constant) + printf("const "); + + if (q->flags.q.invariant) + printf("invariant "); + + if (q->flags.q.attribute) + printf("attribute "); + + if (q->flags.q.varying) + printf("varying "); + + if (q->flags.q.in && q->flags.q.out) + printf("inout "); + else { + if (q->flags.q.in) + printf("in "); + + if (q->flags.q.out) + printf("out "); + } + + if (q->flags.q.centroid) + printf("centroid "); + if (q->flags.q.uniform) + printf("uniform "); + if (q->flags.q.smooth) + printf("smooth "); + if (q->flags.q.flat) + printf("flat "); + if (q->flags.q.noperspective) + printf("noperspective "); +} + + +void +ast_node::print(void) const +{ + printf("unhandled node "); +} + + +ast_node::ast_node(void) +{ + this->location.source = 0; + this->location.line = 0; + this->location.column = 0; +} + + +static void +ast_opt_array_size_print(bool is_array, const ast_expression *array_size) +{ + if (is_array) { + printf("[ "); + + if (array_size) + array_size->print(); + + printf("] "); + } +} + + +void +ast_compound_statement::print(void) const +{ + printf("{\n"); + + foreach_list_const(n, &this->statements) { + ast_node *ast = exec_node_data(ast_node, n, link); + ast->print(); + } + + printf("}\n"); +} + + +ast_compound_statement::ast_compound_statement(int new_scope, + ast_node *statements) +{ + this->new_scope = new_scope; + + if (statements != NULL) { + this->statements.push_degenerate_list_at_head(&statements->link); + } +} + + +void +ast_expression::print(void) const +{ + switch (oper) { + case ast_assign: + case ast_mul_assign: + case ast_div_assign: + case ast_mod_assign: + case ast_add_assign: + case ast_sub_assign: + case ast_ls_assign: + case ast_rs_assign: + case ast_and_assign: + case ast_xor_assign: + case ast_or_assign: + subexpressions[0]->print(); + printf("%s ", operator_string(oper)); + subexpressions[1]->print(); + break; + + case ast_field_selection: + subexpressions[0]->print(); + printf(". %s ", primary_expression.identifier); + break; + + case ast_plus: + case ast_neg: + case ast_bit_not: + case ast_logic_not: + case ast_pre_inc: + case ast_pre_dec: + printf("%s ", operator_string(oper)); + subexpressions[0]->print(); + break; + + case ast_post_inc: + case ast_post_dec: + subexpressions[0]->print(); + printf("%s ", operator_string(oper)); + break; + + case ast_conditional: + subexpressions[0]->print(); + printf("? "); + subexpressions[1]->print(); + printf(": "); + subexpressions[1]->print(); + break; + + case ast_array_index: + subexpressions[0]->print(); + printf("[ "); + subexpressions[1]->print(); + printf("] "); + break; + + case ast_function_call: { + subexpressions[0]->print(); + printf("( "); + + foreach_list_const (n, &this->expressions) { + if (n != this->expressions.get_head()) + printf(", "); + + ast_node *ast = exec_node_data(ast_node, n, link); + ast->print(); + } + + printf(") "); + break; + } + + case ast_identifier: + printf("%s ", primary_expression.identifier); + break; + + case ast_int_constant: + printf("%d ", primary_expression.int_constant); + break; + + case ast_uint_constant: + printf("%u ", primary_expression.uint_constant); + break; + + case ast_float_constant: + printf("%f ", primary_expression.float_constant); + break; + + case ast_bool_constant: + printf("%s ", + primary_expression.bool_constant + ? "true" : "false"); + break; + + case ast_sequence: { + printf("( "); + foreach_list_const(n, & this->expressions) { + if (n != this->expressions.get_head()) + printf(", "); + + ast_node *ast = exec_node_data(ast_node, n, link); + ast->print(); + } + printf(") "); + break; + } + + default: + assert(0); + break; + } +} + +ast_expression::ast_expression(int oper, + ast_expression *ex0, + ast_expression *ex1, + ast_expression *ex2) +{ + this->oper = ast_operators(oper); + this->subexpressions[0] = ex0; + this->subexpressions[1] = ex1; + this->subexpressions[2] = ex2; +} + + +void +ast_expression_statement::print(void) const +{ + if (expression) + expression->print(); + + printf("; "); +} + + +ast_expression_statement::ast_expression_statement(ast_expression *ex) : + expression(ex) +{ + /* empty */ +} + + +void +ast_function::print(void) const +{ + return_type->print(); + printf(" %s (", identifier); + + foreach_list_const(n, & this->parameters) { + ast_node *ast = exec_node_data(ast_node, n, link); + ast->print(); + } + + printf(")"); +} + + +ast_function::ast_function(void) + : is_definition(false), signature(NULL) +{ + /* empty */ +} + + +void +ast_fully_specified_type::print(void) const +{ + _mesa_ast_type_qualifier_print(& qualifier); + specifier->print(); +} + + +void +ast_parameter_declarator::print(void) const +{ + type->print(); + if (identifier) + printf("%s ", identifier); + ast_opt_array_size_print(is_array, array_size); +} + + +void +ast_function_definition::print(void) const +{ + prototype->print(); + body->print(); +} + + +void +ast_declaration::print(void) const +{ + printf("%s ", identifier); + ast_opt_array_size_print(is_array, array_size); + + if (initializer) { + printf("= "); + initializer->print(); + } +} + + +ast_declaration::ast_declaration(char *identifier, int is_array, + ast_expression *array_size, + ast_expression *initializer) +{ + this->identifier = identifier; + this->is_array = is_array; + this->array_size = array_size; + this->initializer = initializer; +} + + +void +ast_declarator_list::print(void) const +{ + assert(type || invariant); + + if (type) + type->print(); + else + printf("invariant "); + + foreach_list_const (ptr, & this->declarations) { + if (ptr != this->declarations.get_head()) + printf(", "); + + ast_node *ast = exec_node_data(ast_node, ptr, link); + ast->print(); + } + + printf("; "); +} + + +ast_declarator_list::ast_declarator_list(ast_fully_specified_type *type) +{ + this->type = type; + this->invariant = false; +} + +void +ast_jump_statement::print(void) const +{ + switch (mode) { + case ast_continue: + printf("continue; "); + break; + case ast_break: + printf("break; "); + break; + case ast_return: + printf("return "); + if (opt_return_value) + opt_return_value->print(); + + printf("; "); + break; + case ast_discard: + printf("discard; "); + break; + } +} + + +ast_jump_statement::ast_jump_statement(int mode, ast_expression *return_value) +{ + this->mode = ast_jump_modes(mode); + + if (mode == ast_return) + opt_return_value = return_value; +} + + +void +ast_selection_statement::print(void) const +{ + printf("if ( "); + condition->print(); + printf(") "); + + then_statement->print(); + + if (else_statement) { + printf("else "); + else_statement->print(); + } + +} + + +ast_selection_statement::ast_selection_statement(ast_expression *condition, + ast_node *then_statement, + ast_node *else_statement) +{ + this->condition = condition; + this->then_statement = then_statement; + this->else_statement = else_statement; +} + + +void +ast_iteration_statement::print(void) const +{ + switch (mode) { + case ast_for: + printf("for( "); + if (init_statement) + init_statement->print(); + printf("; "); + + if (condition) + condition->print(); + printf("; "); + + if (rest_expression) + rest_expression->print(); + printf(") "); + + body->print(); + break; + + case ast_while: + printf("while ( "); + if (condition) + condition->print(); + printf(") "); + body->print(); + break; + + case ast_do_while: + printf("do "); + body->print(); + printf("while ( "); + if (condition) + condition->print(); + printf("); "); + break; + } +} + + +ast_iteration_statement::ast_iteration_statement(int mode, + ast_node *init, + ast_node *condition, + ast_expression *rest_expression, + ast_node *body) +{ + this->mode = ast_iteration_modes(mode); + this->init_statement = init; + this->condition = condition; + this->rest_expression = rest_expression; + this->body = body; +} + + +void +ast_struct_specifier::print(void) const +{ + printf("struct %s { ", name); + foreach_list_const(n, &this->declarations) { + ast_node *ast = exec_node_data(ast_node, n, link); + ast->print(); + } + printf("} "); +} + + +ast_struct_specifier::ast_struct_specifier(char *identifier, + ast_node *declarator_list) +{ + if (identifier == NULL) { + static unsigned anon_count = 1; + identifier = ralloc_asprintf(this, "#anon_struct_%04x", anon_count); + anon_count++; + } + name = identifier; + this->declarations.push_degenerate_list_at_head(&declarator_list->link); +} + +bool +do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iterations) +{ + GLboolean progress = GL_FALSE; + + progress = lower_instructions(ir, SUB_TO_ADD_NEG) || progress; + + if (linked) { + progress = do_function_inlining(ir) || progress; + progress = do_dead_functions(ir) || progress; + } + progress = do_structure_splitting(ir) || progress; + progress = do_if_simplification(ir) || progress; + progress = do_discard_simplification(ir) || progress; + progress = do_copy_propagation(ir) || progress; + if (linked) + progress = do_dead_code(ir) || progress; + else + progress = do_dead_code_unlinked(ir) || progress; + progress = do_dead_code_local(ir) || progress; + progress = do_tree_grafting(ir) || progress; + progress = do_constant_propagation(ir) || progress; + if (linked) + progress = do_constant_variable(ir) || progress; + else + progress = do_constant_variable_unlinked(ir) || progress; + progress = do_constant_folding(ir) || progress; + progress = do_algebraic(ir) || progress; + progress = do_lower_jumps(ir) || progress; + progress = do_vec_index_to_swizzle(ir) || progress; + progress = do_swizzle_swizzle(ir) || progress; + progress = do_noop_swizzle(ir) || progress; + + progress = optimize_redundant_jumps(ir) || progress; + + loop_state *ls = analyze_loop_variables(ir); + progress = set_loop_controls(ir, ls) || progress; + progress = unroll_loops(ir, ls, max_unroll_iterations) || progress; + delete ls; + + return progress; +} + +extern "C" { + +/** + * To be called at GL teardown time, this frees compiler datastructures. + * + * After calling this, any previously compiled shaders and shader + * programs would be invalid. So this should happen at approximately + * program exit. + */ +void +_mesa_destroy_shader_compiler(void) +{ + _mesa_destroy_shader_compiler_caches(); + + _mesa_glsl_release_types(); +} + +/** + * Releases compiler caches to trade off performance for memory. + * + * Intended to be used with glReleaseShaderCompiler(). + */ +void +_mesa_destroy_shader_compiler_caches(void) +{ + _mesa_glsl_release_functions(); +} + +} diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h new file mode 100644 index 0000000..819333d --- /dev/null +++ b/src/glsl/glsl_parser_extras.h @@ -0,0 +1,273 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#ifndef GLSL_PARSER_EXTRAS_H +#define GLSL_PARSER_EXTRAS_H + +/* + * Most of the definitions here only apply to C++ + */ +#ifdef __cplusplus + + +#include +#include "glsl_symbol_table.h" + +enum _mesa_glsl_parser_targets { + vertex_shader, + geometry_shader, + fragment_shader +}; + +struct gl_context; + +struct _mesa_glsl_parse_state { + _mesa_glsl_parse_state(struct gl_context *ctx, GLenum target, + void *mem_ctx); + + /* Callers of this ralloc-based new need not call delete. It's + * easier to just ralloc_free 'ctx' (or any of its ancestors). */ + static void* operator new(size_t size, void *ctx) + { + void *mem = rzalloc_size(ctx, size); + assert(mem != NULL); + + return mem; + } + + /* If the user *does* call delete, that's OK, we will just + * ralloc_free in that case. */ + static void operator delete(void *mem) + { + ralloc_free(mem); + } + + void *scanner; + exec_list translation_unit; + glsl_symbol_table *symbols; + + bool es_shader; + unsigned language_version; + const char *version_string; + enum _mesa_glsl_parser_targets target; + + /** + * Printable list of GLSL versions supported by the current context + * + * \note + * This string should probably be generated per-context instead of per + * invokation of the compiler. This should be changed when the method of + * tracking supported GLSL versions changes. + */ + const char *supported_version_string; + + /** + * Implementation defined limits that affect built-in variables, etc. + * + * \sa struct gl_constants (in mtypes.h) + */ + struct { + /* 1.10 */ + unsigned MaxLights; + unsigned MaxClipPlanes; + unsigned MaxTextureUnits; + unsigned MaxTextureCoords; + unsigned MaxVertexAttribs; + unsigned MaxVertexUniformComponents; + unsigned MaxVaryingFloats; + unsigned MaxVertexTextureImageUnits; + unsigned MaxCombinedTextureImageUnits; + unsigned MaxTextureImageUnits; + unsigned MaxFragmentUniformComponents; + + /* ARB_draw_buffers */ + unsigned MaxDrawBuffers; + + /** + * Set of GLSL versions supported by the current context + * + * Knowing that version X is supported doesn't mean that versions before + * X are also supported. Version 1.00 is only supported in an ES2 + * context or when GL_ARB_ES2_compatibility is supported. In an OpenGL + * 3.0 "forward compatible" context, GLSL 1.10 and 1.20 are \b not + * supported. + */ + /*@{*/ + unsigned GLSL_100ES:1; + unsigned GLSL_110:1; + unsigned GLSL_120:1; + unsigned GLSL_130:1; + /*@}*/ + } Const; + + /** + * During AST to IR conversion, pointer to current IR function + * + * Will be \c NULL whenever the AST to IR conversion is not inside a + * function definition. + */ + class ir_function_signature *current_function; + + /** Have we found a return statement in this function? */ + bool found_return; + + /** Was there an error during compilation? */ + bool error; + + /** + * Are all shader inputs / outputs invariant? + * + * This is set when the 'STDGL invariant(all)' pragma is used. + */ + bool all_invariant; + + /** Loop or switch statement containing the current instructions. */ + class ir_instruction *loop_or_switch_nesting; + class ast_iteration_statement *loop_or_switch_nesting_ast; + + /** List of structures defined in user code. */ + const glsl_type **user_structures; + unsigned num_user_structures; + + char *info_log; + + /** + * \name Enable bits for GLSL extensions + */ + /*@{*/ + unsigned ARB_draw_buffers_enable:1; + unsigned ARB_draw_buffers_warn:1; + unsigned ARB_explicit_attrib_location_enable:1; + unsigned ARB_explicit_attrib_location_warn:1; + unsigned ARB_fragment_coord_conventions_enable:1; + unsigned ARB_fragment_coord_conventions_warn:1; + unsigned ARB_texture_rectangle_enable:1; + unsigned ARB_texture_rectangle_warn:1; + unsigned EXT_texture_array_enable:1; + unsigned EXT_texture_array_warn:1; + unsigned ARB_shader_stencil_export_enable:1; + unsigned ARB_shader_stencil_export_warn:1; + /*@}*/ + + /** Extensions supported by the OpenGL implementation. */ + const struct gl_extensions *extensions; + + /** Shaders containing built-in functions that are used for linking. */ + struct gl_shader *builtins_to_link[16]; + unsigned num_builtins_to_link; +}; + +typedef struct YYLTYPE { + int first_line; + int first_column; + int last_line; + int last_column; + unsigned source; +} YYLTYPE; +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 + +# define YYLLOC_DEFAULT(Current, Rhs, N) \ +do { \ + if (N) \ + { \ + (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC(Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC(Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC(Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC(Rhs, 0).last_column; \ + } \ + (Current).source = 0; \ +} while (0) + +extern void _mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state, + const char *fmt, ...); + +/** + * Emit a warning to the shader log + * + * \sa _mesa_glsl_error + */ +extern void _mesa_glsl_warning(const YYLTYPE *locp, + _mesa_glsl_parse_state *state, + const char *fmt, ...); + +extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, + const char *string); + +extern void _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state); + +union YYSTYPE; +extern int _mesa_glsl_lex(union YYSTYPE *yylval, YYLTYPE *yylloc, + void *scanner); + +extern int _mesa_glsl_parse(struct _mesa_glsl_parse_state *); + +/** + * Process elements of the #extension directive + * + * \return + * If \c name and \c behavior are valid, \c true is returned. Otherwise + * \c false is returned. + */ +extern bool _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp, + const char *behavior, + YYLTYPE *behavior_locp, + _mesa_glsl_parse_state *state); + +/** + * Get the textual name of the specified shader target + */ +extern const char * +_mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target); + + +#endif /* __cplusplus */ + + +/* + * These definitions apply to C and C++ + */ +#ifdef __cplusplus +extern "C" { +#endif + +extern int preprocess(void *ctx, const char **shader, char **info_log, + const struct gl_extensions *extensions, int api); + +extern void _mesa_destroy_shader_compiler(); +extern void _mesa_destroy_shader_compiler_caches(); + +#ifdef __cplusplus +} +#endif + + +#endif /* GLSL_PARSER_EXTRAS_H */ diff --git a/src/glsl/glsl_symbol_table.cpp b/src/glsl/glsl_symbol_table.cpp new file mode 100644 index 0000000..2f291d4 --- /dev/null +++ b/src/glsl/glsl_symbol_table.cpp @@ -0,0 +1,164 @@ +/* -*- c++ -*- */ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "glsl_symbol_table.h" + +class symbol_table_entry { +public: + /* Callers of this ralloc-based new need not call delete. It's + * easier to just ralloc_free 'ctx' (or any of its ancestors). */ + static void* operator new(size_t size, void *ctx) + { + void *entry = ralloc_size(ctx, size); + assert(entry != NULL); + return entry; + } + + /* If the user *does* call delete, that's OK, we will just ralloc_free. */ + static void operator delete(void *entry) + { + ralloc_free(entry); + } + + symbol_table_entry(ir_variable *v) : v(v), f(0), t(0) {} + symbol_table_entry(ir_function *f) : v(0), f(f), t(0) {} + symbol_table_entry(const glsl_type *t) : v(0), f(0), t(t) {} + + ir_variable *v; + ir_function *f; + const glsl_type *t; +}; + +glsl_symbol_table::glsl_symbol_table() +{ + this->language_version = 120; + this->table = _mesa_symbol_table_ctor(); + this->mem_ctx = ralloc_context(NULL); +} + +glsl_symbol_table::~glsl_symbol_table() +{ + _mesa_symbol_table_dtor(table); + ralloc_free(mem_ctx); +} + +void glsl_symbol_table::push_scope() +{ + _mesa_symbol_table_push_scope(table); +} + +void glsl_symbol_table::pop_scope() +{ + _mesa_symbol_table_pop_scope(table); +} + +bool glsl_symbol_table::name_declared_this_scope(const char *name) +{ + return _mesa_symbol_table_symbol_scope(table, -1, name) == 0; +} + +bool glsl_symbol_table::add_variable(ir_variable *v) +{ + if (this->language_version == 110) { + /* In 1.10, functions and variables have separate namespaces. */ + symbol_table_entry *existing = get_entry(v->name); + if (name_declared_this_scope(v->name)) { + /* If there's already an existing function (not a constructor!) in + * the current scope, just update the existing entry to include 'v'. + */ + if (existing->v == NULL && existing->t == NULL) { + existing->v = v; + return true; + } + } else { + /* If not declared at this scope, add a new entry. But if an existing + * entry includes a function, propagate that to this block - otherwise + * the new variable declaration would shadow the function. + */ + symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(v); + if (existing != NULL) + entry->f = existing->f; + int added = _mesa_symbol_table_add_symbol(table, -1, v->name, entry); + assert(added == 0); + (void)added; + return true; + } + return false; + } + + /* 1.20+ rules: */ + symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(v); + return _mesa_symbol_table_add_symbol(table, -1, v->name, entry) == 0; +} + +bool glsl_symbol_table::add_type(const char *name, const glsl_type *t) +{ + symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(t); + return _mesa_symbol_table_add_symbol(table, -1, name, entry) == 0; +} + +bool glsl_symbol_table::add_function(ir_function *f) +{ + if (this->language_version == 110 && name_declared_this_scope(f->name)) { + /* In 1.10, functions and variables have separate namespaces. */ + symbol_table_entry *existing = get_entry(f->name); + if ((existing->f == NULL) && (existing->t == NULL)) { + existing->f = f; + return true; + } + } + symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(f); + return _mesa_symbol_table_add_symbol(table, -1, f->name, entry) == 0; +} + +void glsl_symbol_table::add_global_function(ir_function *f) +{ + symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(f); + int added = _mesa_symbol_table_add_global_symbol(table, -1, f->name, entry); + assert(added == 0); +} + +ir_variable *glsl_symbol_table::get_variable(const char *name) +{ + symbol_table_entry *entry = get_entry(name); + return entry != NULL ? entry->v : NULL; +} + +const glsl_type *glsl_symbol_table::get_type(const char *name) +{ + symbol_table_entry *entry = get_entry(name); + return entry != NULL ? entry->t : NULL; +} + +ir_function *glsl_symbol_table::get_function(const char *name) +{ + symbol_table_entry *entry = get_entry(name); + return entry != NULL ? entry->f : NULL; +} + +symbol_table_entry *glsl_symbol_table::get_entry(const char *name) +{ + return (symbol_table_entry *) + _mesa_symbol_table_find_symbol(table, -1, name); +} diff --git a/src/glsl/glsl_symbol_table.h b/src/glsl/glsl_symbol_table.h new file mode 100644 index 0000000..637bc03 --- /dev/null +++ b/src/glsl/glsl_symbol_table.h @@ -0,0 +1,124 @@ +/* -*- c++ -*- */ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#ifndef GLSL_SYMBOL_TABLE +#define GLSL_SYMBOL_TABLE + +#include + +extern "C" { +#include "program/symbol_table.h" +} +#include "ir.h" +#include "glsl_types.h" + +class symbol_table_entry; + +/** + * Facade class for _mesa_symbol_table + * + * Wraps the existing \c _mesa_symbol_table data structure to enforce some + * type safe and some symbol table invariants. + */ +struct glsl_symbol_table { +private: + static void + _glsl_symbol_table_destructor (glsl_symbol_table *table) + { + table->~glsl_symbol_table(); + } + +public: + /* Callers of this ralloc-based new need not call delete. It's + * easier to just ralloc_free 'ctx' (or any of its ancestors). */ + static void* operator new(size_t size, void *ctx) + { + void *table; + + table = ralloc_size(ctx, size); + assert(table != NULL); + + ralloc_set_destructor(table, (void (*)(void*)) _glsl_symbol_table_destructor); + + return table; + } + + /* If the user *does* call delete, that's OK, we will just + * ralloc_free in that case. Here, C++ will have already called the + * destructor so tell ralloc not to do that again. */ + static void operator delete(void *table) + { + ralloc_set_destructor(table, NULL); + ralloc_free(table); + } + + glsl_symbol_table(); + ~glsl_symbol_table(); + + unsigned int language_version; + + void push_scope(); + void pop_scope(); + + /** + * Determine whether a name was declared at the current scope + */ + bool name_declared_this_scope(const char *name); + + /** + * \name Methods to add symbols to the table + * + * There is some temptation to rename all these functions to \c add_symbol + * or similar. However, this breaks symmetry with the getter functions and + * reduces the clarity of the intention of code that uses these methods. + */ + /*@{*/ + bool add_variable(ir_variable *v); + bool add_type(const char *name, const glsl_type *t); + bool add_function(ir_function *f); + /*@}*/ + + /** + * Add an function at global scope without checking for scoping conflicts. + */ + void add_global_function(ir_function *f); + + /** + * \name Methods to get symbols from the table + */ + /*@{*/ + ir_variable *get_variable(const char *name); + const glsl_type *get_type(const char *name); + ir_function *get_function(const char *name); + /*@}*/ + +private: + symbol_table_entry *get_entry(const char *name); + + struct _mesa_symbol_table *table; + void *mem_ctx; +}; + +#endif /* GLSL_SYMBOL_TABLE */ diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp new file mode 100644 index 0000000..76b4f3e --- /dev/null +++ b/src/glsl/glsl_types.cpp @@ -0,0 +1,497 @@ +/* + * Copyright © 2009 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include "main/core.h" /* for Elements */ +#include "glsl_symbol_table.h" +#include "glsl_parser_extras.h" +#include "glsl_types.h" +#include "builtin_types.h" +extern "C" { +#include "program/hash_table.h" +} + +hash_table *glsl_type::array_types = NULL; +hash_table *glsl_type::record_types = NULL; +void *glsl_type::mem_ctx = NULL; + +void +glsl_type::init_ralloc_type_ctx(void) +{ + if (glsl_type::mem_ctx == NULL) { + glsl_type::mem_ctx = ralloc_autofree_context(); + assert(glsl_type::mem_ctx != NULL); + } +} + +glsl_type::glsl_type(GLenum gl_type, + glsl_base_type base_type, unsigned vector_elements, + unsigned matrix_columns, const char *name) : + gl_type(gl_type), + base_type(base_type), + sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), + sampler_type(0), + vector_elements(vector_elements), matrix_columns(matrix_columns), + length(0) +{ + init_ralloc_type_ctx(); + this->name = ralloc_strdup(this->mem_ctx, name); + /* Neither dimension is zero or both dimensions are zero. + */ + assert((vector_elements == 0) == (matrix_columns == 0)); + memset(& fields, 0, sizeof(fields)); +} + +glsl_type::glsl_type(GLenum gl_type, + enum glsl_sampler_dim dim, bool shadow, bool array, + unsigned type, const char *name) : + gl_type(gl_type), + base_type(GLSL_TYPE_SAMPLER), + sampler_dimensionality(dim), sampler_shadow(shadow), + sampler_array(array), sampler_type(type), + vector_elements(0), matrix_columns(0), + length(0) +{ + init_ralloc_type_ctx(); + this->name = ralloc_strdup(this->mem_ctx, name); + memset(& fields, 0, sizeof(fields)); +} + +glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, + const char *name) : + base_type(GLSL_TYPE_STRUCT), + sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), + sampler_type(0), + vector_elements(0), matrix_columns(0), + length(num_fields) +{ + unsigned int i; + + init_ralloc_type_ctx(); + this->name = ralloc_strdup(this->mem_ctx, name); + this->fields.structure = ralloc_array(this->mem_ctx, + glsl_struct_field, length); + for (i = 0; i < length; i++) { + this->fields.structure[i].type = fields[i].type; + this->fields.structure[i].name = ralloc_strdup(this->fields.structure, + fields[i].name); + } +} + +static void +add_types_to_symbol_table(glsl_symbol_table *symtab, + const struct glsl_type *types, + unsigned num_types, bool warn) +{ + (void) warn; + + for (unsigned i = 0; i < num_types; i++) { + symtab->add_type(types[i].name, & types[i]); + } +} + +void +glsl_type::generate_100ES_types(glsl_symbol_table *symtab) +{ + add_types_to_symbol_table(symtab, builtin_core_types, + Elements(builtin_core_types), + false); + add_types_to_symbol_table(symtab, builtin_structure_types, + Elements(builtin_structure_types), + false); + add_types_to_symbol_table(symtab, void_type, 1, false); +} + +void +glsl_type::generate_110_types(glsl_symbol_table *symtab) +{ + generate_100ES_types(symtab); + + add_types_to_symbol_table(symtab, builtin_110_types, + Elements(builtin_110_types), + false); + add_types_to_symbol_table(symtab, builtin_110_deprecated_structure_types, + Elements(builtin_110_deprecated_structure_types), + false); +} + + +void +glsl_type::generate_120_types(glsl_symbol_table *symtab) +{ + generate_110_types(symtab); + + add_types_to_symbol_table(symtab, builtin_120_types, + Elements(builtin_120_types), false); +} + + +void +glsl_type::generate_130_types(glsl_symbol_table *symtab) +{ + generate_120_types(symtab); + + add_types_to_symbol_table(symtab, builtin_130_types, + Elements(builtin_130_types), false); + generate_EXT_texture_array_types(symtab, false); +} + + +void +glsl_type::generate_ARB_texture_rectangle_types(glsl_symbol_table *symtab, + bool warn) +{ + add_types_to_symbol_table(symtab, builtin_ARB_texture_rectangle_types, + Elements(builtin_ARB_texture_rectangle_types), + warn); +} + + +void +glsl_type::generate_EXT_texture_array_types(glsl_symbol_table *symtab, + bool warn) +{ + add_types_to_symbol_table(symtab, builtin_EXT_texture_array_types, + Elements(builtin_EXT_texture_array_types), + warn); +} + + +void +_mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state) +{ + switch (state->language_version) { + case 100: + assert(state->es_shader); + glsl_type::generate_100ES_types(state->symbols); + break; + case 110: + glsl_type::generate_110_types(state->symbols); + break; + case 120: + glsl_type::generate_120_types(state->symbols); + break; + case 130: + glsl_type::generate_130_types(state->symbols); + break; + default: + /* error */ + break; + } + + if (state->ARB_texture_rectangle_enable) { + glsl_type::generate_ARB_texture_rectangle_types(state->symbols, + state->ARB_texture_rectangle_warn); + } + + if (state->EXT_texture_array_enable && state->language_version < 130) { + // These are already included in 130; don't create twice. + glsl_type::generate_EXT_texture_array_types(state->symbols, + state->EXT_texture_array_warn); + } +} + + +const glsl_type *glsl_type::get_base_type() const +{ + switch (base_type) { + case GLSL_TYPE_UINT: + return uint_type; + case GLSL_TYPE_INT: + return int_type; + case GLSL_TYPE_FLOAT: + return float_type; + case GLSL_TYPE_BOOL: + return bool_type; + default: + return error_type; + } +} + + +void +_mesa_glsl_release_types(void) +{ + if (glsl_type::array_types != NULL) { + hash_table_dtor(glsl_type::array_types); + glsl_type::array_types = NULL; + } + + if (glsl_type::record_types != NULL) { + hash_table_dtor(glsl_type::record_types); + glsl_type::record_types = NULL; + } +} + + +glsl_type::glsl_type(const glsl_type *array, unsigned length) : + base_type(GLSL_TYPE_ARRAY), + sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), + sampler_type(0), + vector_elements(0), matrix_columns(0), + name(NULL), length(length) +{ + this->fields.array = array; + /* Inherit the gl type of the base. The GL type is used for + * uniform/statevar handling in Mesa and the arrayness of the type + * is represented by the size rather than the type. + */ + this->gl_type = array->gl_type; + + /* Allow a maximum of 10 characters for the array size. This is enough + * for 32-bits of ~0. The extra 3 are for the '[', ']', and terminating + * NUL. + */ + const unsigned name_length = strlen(array->name) + 10 + 3; + char *const n = (char *) ralloc_size(this->mem_ctx, name_length); + + if (length == 0) + snprintf(n, name_length, "%s[]", array->name); + else + snprintf(n, name_length, "%s[%u]", array->name, length); + + this->name = n; +} + + +const glsl_type * +glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns) +{ + if (base_type == GLSL_TYPE_VOID) + return void_type; + + if ((rows < 1) || (rows > 4) || (columns < 1) || (columns > 4)) + return error_type; + + /* Treat GLSL vectors as Nx1 matrices. + */ + if (columns == 1) { + switch (base_type) { + case GLSL_TYPE_UINT: + return uint_type + (rows - 1); + case GLSL_TYPE_INT: + return int_type + (rows - 1); + case GLSL_TYPE_FLOAT: + return float_type + (rows - 1); + case GLSL_TYPE_BOOL: + return bool_type + (rows - 1); + default: + return error_type; + } + } else { + if ((base_type != GLSL_TYPE_FLOAT) || (rows == 1)) + return error_type; + + /* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following + * combinations are valid: + * + * 1 2 3 4 + * 1 + * 2 x x x + * 3 x x x + * 4 x x x + */ +#define IDX(c,r) (((c-1)*3) + (r-1)) + + switch (IDX(columns, rows)) { + case IDX(2,2): return mat2_type; + case IDX(2,3): return mat2x3_type; + case IDX(2,4): return mat2x4_type; + case IDX(3,2): return mat3x2_type; + case IDX(3,3): return mat3_type; + case IDX(3,4): return mat3x4_type; + case IDX(4,2): return mat4x2_type; + case IDX(4,3): return mat4x3_type; + case IDX(4,4): return mat4_type; + default: return error_type; + } + } + + assert(!"Should not get here."); + return error_type; +} + + +const glsl_type * +glsl_type::get_array_instance(const glsl_type *base, unsigned array_size) +{ + + if (array_types == NULL) { + array_types = hash_table_ctor(64, hash_table_string_hash, + hash_table_string_compare); + } + + /* Generate a name using the base type pointer in the key. This is + * done because the name of the base type may not be unique across + * shaders. For example, two shaders may have different record types + * named 'foo'. + */ + char key[128]; + snprintf(key, sizeof(key), "%p[%u]", (void *) base, array_size); + + const glsl_type *t = (glsl_type *) hash_table_find(array_types, key); + if (t == NULL) { + t = new glsl_type(base, array_size); + + hash_table_insert(array_types, (void *) t, ralloc_strdup(mem_ctx, key)); + } + + assert(t->base_type == GLSL_TYPE_ARRAY); + assert(t->length == array_size); + assert(t->fields.array == base); + + return t; +} + + +int +glsl_type::record_key_compare(const void *a, const void *b) +{ + const glsl_type *const key1 = (glsl_type *) a; + const glsl_type *const key2 = (glsl_type *) b; + + /* Return zero is the types match (there is zero difference) or non-zero + * otherwise. + */ + if (strcmp(key1->name, key2->name) != 0) + return 1; + + if (key1->length != key2->length) + return 1; + + for (unsigned i = 0; i < key1->length; i++) { + if (key1->fields.structure[i].type != key2->fields.structure[i].type) + return 1; + if (strcmp(key1->fields.structure[i].name, + key2->fields.structure[i].name) != 0) + return 1; + } + + return 0; +} + + +unsigned +glsl_type::record_key_hash(const void *a) +{ + const glsl_type *const key = (glsl_type *) a; + char hash_key[128]; + unsigned size = 0; + + size = snprintf(hash_key, sizeof(hash_key), "%08x", key->length); + + for (unsigned i = 0; i < key->length; i++) { + if (size >= sizeof(hash_key)) + break; + + size += snprintf(& hash_key[size], sizeof(hash_key) - size, + "%p", (void *) key->fields.structure[i].type); + } + + return hash_table_string_hash(& hash_key); +} + + +const glsl_type * +glsl_type::get_record_instance(const glsl_struct_field *fields, + unsigned num_fields, + const char *name) +{ + const glsl_type key(fields, num_fields, name); + + if (record_types == NULL) { + record_types = hash_table_ctor(64, record_key_hash, record_key_compare); + } + + const glsl_type *t = (glsl_type *) hash_table_find(record_types, & key); + if (t == NULL) { + t = new glsl_type(fields, num_fields, name); + + hash_table_insert(record_types, (void *) t, t); + } + + assert(t->base_type == GLSL_TYPE_STRUCT); + assert(t->length == num_fields); + assert(strcmp(t->name, name) == 0); + + return t; +} + + +const glsl_type * +glsl_type::field_type(const char *name) const +{ + if (this->base_type != GLSL_TYPE_STRUCT) + return error_type; + + for (unsigned i = 0; i < this->length; i++) { + if (strcmp(name, this->fields.structure[i].name) == 0) + return this->fields.structure[i].type; + } + + return error_type; +} + + +int +glsl_type::field_index(const char *name) const +{ + if (this->base_type != GLSL_TYPE_STRUCT) + return -1; + + for (unsigned i = 0; i < this->length; i++) { + if (strcmp(name, this->fields.structure[i].name) == 0) + return i; + } + + return -1; +} + + +unsigned +glsl_type::component_slots() const +{ + switch (this->base_type) { + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: + case GLSL_TYPE_FLOAT: + case GLSL_TYPE_BOOL: + return this->components(); + + case GLSL_TYPE_STRUCT: { + unsigned size = 0; + + for (unsigned i = 0; i < this->length; i++) + size += this->fields.structure[i].type->component_slots(); + + return size; + } + + case GLSL_TYPE_ARRAY: + return this->length * this->fields.array->component_slots(); + + default: + return 0; + } +} diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h new file mode 100644 index 0000000..61bf5e0 --- /dev/null +++ b/src/glsl/glsl_types.h @@ -0,0 +1,476 @@ +/* -*- c++ -*- */ +/* + * Copyright © 2009 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#ifndef GLSL_TYPES_H +#define GLSL_TYPES_H + +#include +#include + +extern "C" { +#include "GL/gl.h" +} + +#include "ralloc.h" + +struct _mesa_glsl_parse_state; +struct glsl_symbol_table; + +extern "C" void +_mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state); + +extern "C" void +_mesa_glsl_release_types(void); + +enum glsl_base_type { + GLSL_TYPE_UINT = 0, + GLSL_TYPE_INT, + GLSL_TYPE_FLOAT, + GLSL_TYPE_BOOL, + GLSL_TYPE_SAMPLER, + GLSL_TYPE_STRUCT, + GLSL_TYPE_ARRAY, + GLSL_TYPE_VOID, + GLSL_TYPE_ERROR +}; + +enum glsl_sampler_dim { + GLSL_SAMPLER_DIM_1D = 0, + GLSL_SAMPLER_DIM_2D, + GLSL_SAMPLER_DIM_3D, + GLSL_SAMPLER_DIM_CUBE, + GLSL_SAMPLER_DIM_RECT, + GLSL_SAMPLER_DIM_BUF +}; + + +struct glsl_type { + GLenum gl_type; + glsl_base_type base_type; + + unsigned sampler_dimensionality:3; + unsigned sampler_shadow:1; + unsigned sampler_array:1; + unsigned sampler_type:2; /**< Type of data returned using this sampler. + * only \c GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT, + * and \c GLSL_TYPE_UINT are valid. + */ + + /* Callers of this ralloc-based new need not call delete. It's + * easier to just ralloc_free 'mem_ctx' (or any of its ancestors). */ + static void* operator new(size_t size) + { + if (glsl_type::mem_ctx == NULL) { + glsl_type::mem_ctx = ralloc_context(NULL); + assert(glsl_type::mem_ctx != NULL); + } + + void *type; + + type = ralloc_size(glsl_type::mem_ctx, size); + assert(type != NULL); + + return type; + } + + /* If the user *does* call delete, that's OK, we will just + * ralloc_free in that case. */ + static void operator delete(void *type) + { + ralloc_free(type); + } + + /** + * \name Vector and matrix element counts + * + * For scalars, each of these values will be 1. For non-numeric types + * these will be 0. + */ + /*@{*/ + unsigned vector_elements:3; /**< 1, 2, 3, or 4 vector elements. */ + unsigned matrix_columns:3; /**< 1, 2, 3, or 4 matrix columns. */ + /*@}*/ + + /** + * Name of the data type + * + * This may be \c NULL for anonymous structures, for arrays, or for + * function types. + */ + const char *name; + + /** + * For \c GLSL_TYPE_ARRAY, this is the length of the array. For + * \c GLSL_TYPE_STRUCT, it is the number of elements in the structure and + * the number of values pointed to by \c fields.structure (below). + */ + unsigned length; + + /** + * Subtype of composite data types. + */ + union { + const struct glsl_type *array; /**< Type of array elements. */ + const struct glsl_type *parameters; /**< Parameters to function. */ + struct glsl_struct_field *structure; /**< List of struct fields. */ + } fields; + + + /** + * \name Pointers to various public type singletons + */ + /*@{*/ + static const glsl_type *const error_type; + static const glsl_type *const void_type; + static const glsl_type *const int_type; + static const glsl_type *const ivec4_type; + static const glsl_type *const uint_type; + static const glsl_type *const uvec2_type; + static const glsl_type *const uvec3_type; + static const glsl_type *const uvec4_type; + static const glsl_type *const float_type; + static const glsl_type *const vec2_type; + static const glsl_type *const vec3_type; + static const glsl_type *const vec4_type; + static const glsl_type *const bool_type; + static const glsl_type *const mat2_type; + static const glsl_type *const mat2x3_type; + static const glsl_type *const mat2x4_type; + static const glsl_type *const mat3x2_type; + static const glsl_type *const mat3_type; + static const glsl_type *const mat3x4_type; + static const glsl_type *const mat4x2_type; + static const glsl_type *const mat4x3_type; + static const glsl_type *const mat4_type; + /*@}*/ + + + /** + * For numeric and boolean derrived types returns the basic scalar type + * + * If the type is a numeric or boolean scalar, vector, or matrix type, + * this function gets the scalar type of the individual components. For + * all other types, including arrays of numeric or boolean types, the + * error type is returned. + */ + const glsl_type *get_base_type() const; + + /** + * Query the type of elements in an array + * + * \return + * Pointer to the type of elements in the array for array types, or \c NULL + * for non-array types. + */ + const glsl_type *element_type() const + { + return is_array() ? fields.array : NULL; + } + + /** + * Get the instance of a built-in scalar, vector, or matrix type + */ + static const glsl_type *get_instance(unsigned base_type, unsigned rows, + unsigned columns); + + /** + * Get the instance of an array type + */ + static const glsl_type *get_array_instance(const glsl_type *base, + unsigned elements); + + /** + * Get the instance of a record type + */ + static const glsl_type *get_record_instance(const glsl_struct_field *fields, + unsigned num_fields, + const char *name); + + /** + * Query the total number of scalars that make up a scalar, vector or matrix + */ + unsigned components() const + { + return vector_elements * matrix_columns; + } + + /** + * Calculate the number of components slots required to hold this type + * + * This is used to determine how many uniform or varying locations a type + * might occupy. + */ + unsigned component_slots() const; + + + /** + * Query whether or not a type is a scalar (non-vector and non-matrix). + */ + bool is_scalar() const + { + return (vector_elements == 1) + && (base_type >= GLSL_TYPE_UINT) + && (base_type <= GLSL_TYPE_BOOL); + } + + /** + * Query whether or not a type is a vector + */ + bool is_vector() const + { + return (vector_elements > 1) + && (matrix_columns == 1) + && (base_type >= GLSL_TYPE_UINT) + && (base_type <= GLSL_TYPE_BOOL); + } + + /** + * Query whether or not a type is a matrix + */ + bool is_matrix() const + { + /* GLSL only has float matrices. */ + return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT); + } + + /** + * Query whether or not a type is a non-array numeric type + */ + bool is_numeric() const + { + return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_FLOAT); + } + + /** + * Query whether or not a type is an integral type + */ + bool is_integer() const + { + return (base_type == GLSL_TYPE_UINT) || (base_type == GLSL_TYPE_INT); + } + + /** + * Query whether or not a type is a float type + */ + bool is_float() const + { + return base_type == GLSL_TYPE_FLOAT; + } + + /** + * Query whether or not a type is a non-array boolean type + */ + bool is_boolean() const + { + return base_type == GLSL_TYPE_BOOL; + } + + /** + * Query whether or not a type is a sampler + */ + bool is_sampler() const + { + return base_type == GLSL_TYPE_SAMPLER; + } + + /** + * Query whether or not a type is an array + */ + bool is_array() const + { + return base_type == GLSL_TYPE_ARRAY; + } + + /** + * Query whether or not a type is a record + */ + bool is_record() const + { + return base_type == GLSL_TYPE_STRUCT; + } + + /** + * Query whether or not a type is the void type singleton. + */ + bool is_void() const + { + return base_type == GLSL_TYPE_VOID; + } + + /** + * Query whether or not a type is the error type singleton. + */ + bool is_error() const + { + return base_type == GLSL_TYPE_ERROR; + } + + /** + * Query the full type of a matrix row + * + * \return + * If the type is not a matrix, \c glsl_type::error_type is returned. + * Otherwise a type matching the rows of the matrix is returned. + */ + const glsl_type *row_type() const + { + return is_matrix() + ? get_instance(base_type, matrix_columns, 1) + : error_type; + } + + /** + * Query the full type of a matrix column + * + * \return + * If the type is not a matrix, \c glsl_type::error_type is returned. + * Otherwise a type matching the columns of the matrix is returned. + */ + const glsl_type *column_type() const + { + return is_matrix() + ? get_instance(base_type, vector_elements, 1) + : error_type; + } + + + /** + * Get the type of a structure field + * + * \return + * Pointer to the type of the named field. If the type is not a structure + * or the named field does not exist, \c glsl_type::error_type is returned. + */ + const glsl_type *field_type(const char *name) const; + + + /** + * Get the location of a filed within a record type + */ + int field_index(const char *name) const; + + + /** + * Query the number of elements in an array type + * + * \return + * The number of elements in the array for array types or -1 for non-array + * types. If the number of elements in the array has not yet been declared, + * zero is returned. + */ + int array_size() const + { + return is_array() ? length : -1; + } + +private: + /** + * ralloc context for all glsl_type allocations + * + * Set on the first call to \c glsl_type::new. + */ + static void *mem_ctx; + + void init_ralloc_type_ctx(void); + + /** Constructor for vector and matrix types */ + glsl_type(GLenum gl_type, + glsl_base_type base_type, unsigned vector_elements, + unsigned matrix_columns, const char *name); + + /** Constructor for sampler types */ + glsl_type(GLenum gl_type, + enum glsl_sampler_dim dim, bool shadow, bool array, + unsigned type, const char *name); + + /** Constructor for record types */ + glsl_type(const glsl_struct_field *fields, unsigned num_fields, + const char *name); + + /** Constructor for array types */ + glsl_type(const glsl_type *array, unsigned length); + + /** Hash table containing the known array types. */ + static struct hash_table *array_types; + + /** Hash table containing the known record types. */ + static struct hash_table *record_types; + + static int record_key_compare(const void *a, const void *b); + static unsigned record_key_hash(const void *key); + + /** + * \name Pointers to various type singletons + */ + /*@{*/ + static const glsl_type _error_type; + static const glsl_type _void_type; + static const glsl_type builtin_core_types[]; + static const glsl_type builtin_structure_types[]; + static const glsl_type builtin_110_deprecated_structure_types[]; + static const glsl_type builtin_110_types[]; + static const glsl_type builtin_120_types[]; + static const glsl_type builtin_130_types[]; + static const glsl_type builtin_ARB_texture_rectangle_types[]; + static const glsl_type builtin_EXT_texture_array_types[]; + static const glsl_type builtin_EXT_texture_buffer_object_types[]; + /*@}*/ + + /** + * \name Methods to populate a symbol table with built-in types. + * + * \internal + * This is one of the truely annoying things about C++. Methods that are + * completely internal and private to a type still have to be advertised to + * the world in a public header file. + */ + /*@{*/ + static void generate_100ES_types(glsl_symbol_table *); + static void generate_110_types(glsl_symbol_table *); + static void generate_120_types(glsl_symbol_table *); + static void generate_130_types(glsl_symbol_table *); + static void generate_ARB_texture_rectangle_types(glsl_symbol_table *, bool); + static void generate_EXT_texture_array_types(glsl_symbol_table *, bool); + /*@}*/ + + /** + * \name Friend functions. + * + * These functions are friends because they must have C linkage and the + * need to call various private methods or access various private static + * data. + */ + /*@{*/ + friend void _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *); + friend void _mesa_glsl_release_types(void); + /*@}*/ +}; + +struct glsl_struct_field { + const struct glsl_type *type; + const char *name; +}; + +#endif /* GLSL_TYPES_H */ diff --git a/src/glsl/hir_field_selection.cpp b/src/glsl/hir_field_selection.cpp new file mode 100644 index 0000000..3c33127 --- /dev/null +++ b/src/glsl/hir_field_selection.cpp @@ -0,0 +1,102 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "ir.h" +#include "program/symbol_table.h" +#include "glsl_parser_extras.h" +#include "ast.h" +#include "glsl_types.h" + +ir_rvalue * +_mesa_ast_field_selection_to_hir(const ast_expression *expr, + exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + void *ctx = state; + ir_rvalue *result = NULL; + ir_rvalue *op; + + op = expr->subexpressions[0]->hir(instructions, state); + + /* There are two kinds of field selection. There is the selection of a + * specific field from a structure, and there is the selection of a + * swizzle / mask from a vector. Which is which is determined entirely + * by the base type of the thing to which the field selection operator is + * being applied. + */ + YYLTYPE loc = expr->get_location(); + if (op->type->is_error()) { + /* silently propagate the error */ + } else if (op->type->is_vector()) { + ir_swizzle *swiz = ir_swizzle::create(op, + expr->primary_expression.identifier, + op->type->vector_elements); + if (swiz != NULL) { + result = swiz; + } else { + /* FINISHME: Logging of error messages should be moved into + * FINISHME: ir_swizzle::create. This allows the generation of more + * FINISHME: specific error messages. + */ + _mesa_glsl_error(& loc, state, "Invalid swizzle / mask `%s'", + expr->primary_expression.identifier); + } + } else if (op->type->base_type == GLSL_TYPE_STRUCT) { + result = new(ctx) ir_dereference_record(op, + expr->primary_expression.identifier); + + if (result->type->is_error()) { + _mesa_glsl_error(& loc, state, "Cannot access field `%s' of " + "structure", + expr->primary_expression.identifier); + } + } else if (expr->subexpressions[1] != NULL) { + /* Handle "method calls" in GLSL 1.20 - namely, array.length() */ + if (state->language_version < 120) + _mesa_glsl_error(&loc, state, "Methods not supported in GLSL 1.10."); + + ast_expression *call = expr->subexpressions[1]; + assert(call->oper == ast_function_call); + + const char *method; + method = call->subexpressions[0]->primary_expression.identifier; + + if (op->type->is_array() && strcmp(method, "length") == 0) { + if (!call->expressions.is_empty()) + _mesa_glsl_error(&loc, state, "length method takes no arguments."); + + if (op->type->array_size() == 0) + _mesa_glsl_error(&loc, state, "length called on unsized array."); + + result = new(ctx) ir_constant(op->type->array_size()); + } else { + _mesa_glsl_error(&loc, state, "Unknown method: `%s'.", method); + } + } else { + _mesa_glsl_error(& loc, state, "Cannot access field `%s' of " + "non-structure / non-vector.", + expr->primary_expression.identifier); + } + + return result ? result : ir_call::get_error_instruction(ctx); +} diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp new file mode 100644 index 0000000..169e948 --- /dev/null +++ b/src/glsl/ir.cpp @@ -0,0 +1,1496 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#include +#include "main/core.h" /* for MAX2 */ +#include "ir.h" +#include "ir_visitor.h" +#include "glsl_types.h" + +ir_rvalue::ir_rvalue() +{ + this->type = glsl_type::error_type; +} + +bool ir_rvalue::is_zero() const +{ + return false; +} + +bool ir_rvalue::is_one() const +{ + return false; +} + +bool ir_rvalue::is_negative_one() const +{ + return false; +} + +/** + * Modify the swizzle make to move one component to another + * + * \param m IR swizzle to be modified + * \param from Component in the RHS that is to be swizzled + * \param to Desired swizzle location of \c from + */ +static void +update_rhs_swizzle(ir_swizzle_mask &m, unsigned from, unsigned to) +{ + switch (to) { + case 0: m.x = from; break; + case 1: m.y = from; break; + case 2: m.z = from; break; + case 3: m.w = from; break; + default: assert(!"Should not get here."); + } + + m.num_components = MAX2(m.num_components, (to + 1)); +} + +void +ir_assignment::set_lhs(ir_rvalue *lhs) +{ + void *mem_ctx = this; + bool swizzled = false; + + while (lhs != NULL) { + ir_swizzle *swiz = lhs->as_swizzle(); + + if (swiz == NULL) + break; + + unsigned write_mask = 0; + ir_swizzle_mask rhs_swiz = { 0, 0, 0, 0, 0, 0 }; + + for (unsigned i = 0; i < swiz->mask.num_components; i++) { + unsigned c = 0; + + switch (i) { + case 0: c = swiz->mask.x; break; + case 1: c = swiz->mask.y; break; + case 2: c = swiz->mask.z; break; + case 3: c = swiz->mask.w; break; + default: assert(!"Should not get here."); + } + + write_mask |= (((this->write_mask >> i) & 1) << c); + update_rhs_swizzle(rhs_swiz, i, c); + } + + this->write_mask = write_mask; + lhs = swiz->val; + + this->rhs = new(mem_ctx) ir_swizzle(this->rhs, rhs_swiz); + swizzled = true; + } + + if (swizzled) { + /* Now, RHS channels line up with the LHS writemask. Collapse it + * to just the channels that will be written. + */ + ir_swizzle_mask rhs_swiz = { 0, 0, 0, 0, 0, 0 }; + int rhs_chan = 0; + for (int i = 0; i < 4; i++) { + if (write_mask & (1 << i)) + update_rhs_swizzle(rhs_swiz, i, rhs_chan++); + } + this->rhs = new(mem_ctx) ir_swizzle(this->rhs, rhs_swiz); + } + + assert((lhs == NULL) || lhs->as_dereference()); + + this->lhs = (ir_dereference *) lhs; +} + +ir_variable * +ir_assignment::whole_variable_written() +{ + ir_variable *v = this->lhs->whole_variable_referenced(); + + if (v == NULL) + return NULL; + + if (v->type->is_scalar()) + return v; + + if (v->type->is_vector()) { + const unsigned mask = (1U << v->type->vector_elements) - 1; + + if (mask != this->write_mask) + return NULL; + } + + /* Either all the vector components are assigned or the variable is some + * composite type (and the whole thing is assigned. + */ + return v; +} + +ir_assignment::ir_assignment(ir_dereference *lhs, ir_rvalue *rhs, + ir_rvalue *condition, unsigned write_mask) +{ + this->ir_type = ir_type_assignment; + this->condition = condition; + this->rhs = rhs; + this->lhs = lhs; + this->write_mask = write_mask; + + if (lhs->type->is_scalar() || lhs->type->is_vector()) { + int lhs_components = 0; + for (int i = 0; i < 4; i++) { + if (write_mask & (1 << i)) + lhs_components++; + } + + assert(lhs_components == this->rhs->type->vector_elements); + } +} + +ir_assignment::ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, + ir_rvalue *condition) +{ + this->ir_type = ir_type_assignment; + this->condition = condition; + this->rhs = rhs; + + /* If the RHS is a vector type, assume that all components of the vector + * type are being written to the LHS. The write mask comes from the RHS + * because we can have a case where the LHS is a vec4 and the RHS is a + * vec3. In that case, the assignment is: + * + * (assign (...) (xyz) (var_ref lhs) (var_ref rhs)) + */ + if (rhs->type->is_vector()) + this->write_mask = (1U << rhs->type->vector_elements) - 1; + else if (rhs->type->is_scalar()) + this->write_mask = 1; + else + this->write_mask = 0; + + this->set_lhs(lhs); +} + + +ir_expression::ir_expression(int op, const struct glsl_type *type, + ir_rvalue *op0) +{ + assert(get_num_operands(ir_expression_operation(op)) == 1); + this->ir_type = ir_type_expression; + this->type = type; + this->operation = ir_expression_operation(op); + this->operands[0] = op0; + this->operands[1] = NULL; + this->operands[2] = NULL; + this->operands[3] = NULL; +} + +ir_expression::ir_expression(int op, const struct glsl_type *type, + ir_rvalue *op0, ir_rvalue *op1) +{ + assert(((op1 == NULL) && (get_num_operands(ir_expression_operation(op)) == 1)) + || (get_num_operands(ir_expression_operation(op)) == 2)); + this->ir_type = ir_type_expression; + this->type = type; + this->operation = ir_expression_operation(op); + this->operands[0] = op0; + this->operands[1] = op1; + this->operands[2] = NULL; + this->operands[3] = NULL; +} + +ir_expression::ir_expression(int op, const struct glsl_type *type, + ir_rvalue *op0, ir_rvalue *op1, + ir_rvalue *op2, ir_rvalue *op3) +{ + this->ir_type = ir_type_expression; + this->type = type; + this->operation = ir_expression_operation(op); + this->operands[0] = op0; + this->operands[1] = op1; + this->operands[2] = op2; + this->operands[3] = op3; +} + +ir_expression::ir_expression(int op, ir_rvalue *op0) +{ + this->ir_type = ir_type_expression; + + this->operation = ir_expression_operation(op); + this->operands[0] = op0; + this->operands[1] = NULL; + this->operands[2] = NULL; + this->operands[3] = NULL; + + assert(op <= ir_last_unop); + + switch (this->operation) { + case ir_unop_bit_not: + case ir_unop_logic_not: + case ir_unop_neg: + case ir_unop_abs: + case ir_unop_sign: + case ir_unop_rcp: + case ir_unop_rsq: + case ir_unop_sqrt: + case ir_unop_exp: + case ir_unop_log: + case ir_unop_exp2: + case ir_unop_log2: + case ir_unop_trunc: + case ir_unop_ceil: + case ir_unop_floor: + case ir_unop_fract: + case ir_unop_round_even: + case ir_unop_cos: + case ir_unop_dFdx: + case ir_unop_dFdy: + this->type = op0->type; + break; + + case ir_unop_any: + this->type = glsl_type::bool_type; + break; + + default: + assert(!"not reached: missing automatic type setup for ir_expression"); + this->type = op0->type; + break; + } +} + +ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1) +{ + this->ir_type = ir_type_expression; + + this->operation = ir_expression_operation(op); + this->operands[0] = op0; + this->operands[1] = op1; + this->operands[2] = NULL; + this->operands[3] = NULL; + + assert(op > ir_last_unop); + + switch (this->operation) { + case ir_binop_all_equal: + case ir_binop_any_nequal: + this->type = glsl_type::bool_type; + break; + + case ir_binop_add: + case ir_binop_sub: + case ir_binop_min: + case ir_binop_max: + case ir_binop_pow: + case ir_binop_mul: + if (op0->type->is_scalar()) { + this->type = op1->type; + } else if (op1->type->is_scalar()) { + this->type = op0->type; + } else { + /* FINISHME: matrix types */ + assert(!op0->type->is_matrix() && !op1->type->is_matrix()); + assert(op0->type == op1->type); + this->type = op0->type; + } + break; + + case ir_binop_logic_and: + case ir_binop_logic_or: + if (op0->type->is_scalar()) { + this->type = op1->type; + } else if (op1->type->is_scalar()) { + this->type = op0->type; + } + break; + + case ir_binop_dot: + this->type = glsl_type::float_type; + break; + + default: + assert(!"not reached: missing automatic type setup for ir_expression"); + this->type = glsl_type::float_type; + } +} + +unsigned int +ir_expression::get_num_operands(ir_expression_operation op) +{ + assert(op <= ir_last_opcode); + + if (op <= ir_last_unop) + return 1; + + if (op <= ir_last_binop) + return 2; + + if (op == ir_quadop_vector) + return 4; + + assert(false); + return 0; +} + +static const char *const operator_strs[] = { + "~", + "!", + "neg", + "abs", + "sign", + "rcp", + "rsq", + "sqrt", + "exp", + "log", + "exp2", + "log2", + "f2i", + "i2f", + "f2b", + "b2f", + "i2b", + "b2i", + "u2f", + "any", + "trunc", + "ceil", + "floor", + "fract", + "round_even", + "sin", + "cos", + "sin_reduced", + "cos_reduced", + "dFdx", + "dFdy", + "noise", + "+", + "-", + "*", + "/", + "%", + "<", + ">", + "<=", + ">=", + "==", + "!=", + "all_equal", + "any_nequal", + "<<", + ">>", + "&", + "^", + "|", + "&&", + "^^", + "||", + "dot", + "min", + "max", + "pow", + "vector", +}; + +const char *ir_expression::operator_string(ir_expression_operation op) +{ + assert((unsigned int) op < Elements(operator_strs)); + assert(Elements(operator_strs) == (ir_quadop_vector + 1)); + return operator_strs[op]; +} + +const char *ir_expression::operator_string() +{ + return operator_string(this->operation); +} + +ir_expression_operation +ir_expression::get_operator(const char *str) +{ + const int operator_count = sizeof(operator_strs) / sizeof(operator_strs[0]); + for (int op = 0; op < operator_count; op++) { + if (strcmp(str, operator_strs[op]) == 0) + return (ir_expression_operation) op; + } + return (ir_expression_operation) -1; +} + +ir_constant::ir_constant() +{ + this->ir_type = ir_type_constant; +} + +ir_constant::ir_constant(const struct glsl_type *type, + const ir_constant_data *data) +{ + assert((type->base_type >= GLSL_TYPE_UINT) + && (type->base_type <= GLSL_TYPE_BOOL)); + + this->ir_type = ir_type_constant; + this->type = type; + memcpy(& this->value, data, sizeof(this->value)); +} + +ir_constant::ir_constant(float f) +{ + this->ir_type = ir_type_constant; + this->type = glsl_type::float_type; + this->value.f[0] = f; + for (int i = 1; i < 16; i++) { + this->value.f[i] = 0; + } +} + +ir_constant::ir_constant(unsigned int u) +{ + this->ir_type = ir_type_constant; + this->type = glsl_type::uint_type; + this->value.u[0] = u; + for (int i = 1; i < 16; i++) { + this->value.u[i] = 0; + } +} + +ir_constant::ir_constant(int i) +{ + this->ir_type = ir_type_constant; + this->type = glsl_type::int_type; + this->value.i[0] = i; + for (int i = 1; i < 16; i++) { + this->value.i[i] = 0; + } +} + +ir_constant::ir_constant(bool b) +{ + this->ir_type = ir_type_constant; + this->type = glsl_type::bool_type; + this->value.b[0] = b; + for (int i = 1; i < 16; i++) { + this->value.b[i] = false; + } +} + +ir_constant::ir_constant(const ir_constant *c, unsigned i) +{ + this->ir_type = ir_type_constant; + this->type = c->type->get_base_type(); + + switch (this->type->base_type) { + case GLSL_TYPE_UINT: this->value.u[0] = c->value.u[i]; break; + case GLSL_TYPE_INT: this->value.i[0] = c->value.i[i]; break; + case GLSL_TYPE_FLOAT: this->value.f[0] = c->value.f[i]; break; + case GLSL_TYPE_BOOL: this->value.b[0] = c->value.b[i]; break; + default: assert(!"Should not get here."); break; + } +} + +ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list) +{ + this->ir_type = ir_type_constant; + this->type = type; + + assert(type->is_scalar() || type->is_vector() || type->is_matrix() + || type->is_record() || type->is_array()); + + if (type->is_array()) { + this->array_elements = ralloc_array(this, ir_constant *, type->length); + unsigned i = 0; + foreach_list(node, value_list) { + ir_constant *value = (ir_constant *) node; + assert(value->as_constant() != NULL); + + this->array_elements[i++] = value; + } + return; + } + + /* If the constant is a record, the types of each of the entries in + * value_list must be a 1-for-1 match with the structure components. Each + * entry must also be a constant. Just move the nodes from the value_list + * to the list in the ir_constant. + */ + /* FINISHME: Should there be some type checking and / or assertions here? */ + /* FINISHME: Should the new constant take ownership of the nodes from + * FINISHME: value_list, or should it make copies? + */ + if (type->is_record()) { + value_list->move_nodes_to(& this->components); + return; + } + + for (unsigned i = 0; i < 16; i++) { + this->value.u[i] = 0; + } + + ir_constant *value = (ir_constant *) (value_list->head); + + /* Constructors with exactly one scalar argument are special for vectors + * and matrices. For vectors, the scalar value is replicated to fill all + * the components. For matrices, the scalar fills the components of the + * diagonal while the rest is filled with 0. + */ + if (value->type->is_scalar() && value->next->is_tail_sentinel()) { + if (type->is_matrix()) { + /* Matrix - fill diagonal (rest is already set to 0) */ + assert(type->base_type == GLSL_TYPE_FLOAT); + for (unsigned i = 0; i < type->matrix_columns; i++) + this->value.f[i * type->vector_elements + i] = value->value.f[0]; + } else { + /* Vector or scalar - fill all components */ + switch (type->base_type) { + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: + for (unsigned i = 0; i < type->components(); i++) + this->value.u[i] = value->value.u[0]; + break; + case GLSL_TYPE_FLOAT: + for (unsigned i = 0; i < type->components(); i++) + this->value.f[i] = value->value.f[0]; + break; + case GLSL_TYPE_BOOL: + for (unsigned i = 0; i < type->components(); i++) + this->value.b[i] = value->value.b[0]; + break; + default: + assert(!"Should not get here."); + break; + } + } + return; + } + + if (type->is_matrix() && value->type->is_matrix()) { + assert(value->next->is_tail_sentinel()); + + /* From section 5.4.2 of the GLSL 1.20 spec: + * "If a matrix is constructed from a matrix, then each component + * (column i, row j) in the result that has a corresponding component + * (column i, row j) in the argument will be initialized from there." + */ + unsigned cols = MIN2(type->matrix_columns, value->type->matrix_columns); + unsigned rows = MIN2(type->vector_elements, value->type->vector_elements); + for (unsigned i = 0; i < cols; i++) { + for (unsigned j = 0; j < rows; j++) { + const unsigned src = i * value->type->vector_elements + j; + const unsigned dst = i * type->vector_elements + j; + this->value.f[dst] = value->value.f[src]; + } + } + + /* "All other components will be initialized to the identity matrix." */ + for (unsigned i = cols; i < type->matrix_columns; i++) + this->value.f[i * type->vector_elements + i] = 1.0; + + return; + } + + /* Use each component from each entry in the value_list to initialize one + * component of the constant being constructed. + */ + for (unsigned i = 0; i < type->components(); /* empty */) { + assert(value->as_constant() != NULL); + assert(!value->is_tail_sentinel()); + + for (unsigned j = 0; j < value->type->components(); j++) { + switch (type->base_type) { + case GLSL_TYPE_UINT: + this->value.u[i] = value->get_uint_component(j); + break; + case GLSL_TYPE_INT: + this->value.i[i] = value->get_int_component(j); + break; + case GLSL_TYPE_FLOAT: + this->value.f[i] = value->get_float_component(j); + break; + case GLSL_TYPE_BOOL: + this->value.b[i] = value->get_bool_component(j); + break; + default: + /* FINISHME: What to do? Exceptions are not the answer. + */ + break; + } + + i++; + if (i >= type->components()) + break; + } + + value = (ir_constant *) value->next; + } +} + +ir_constant * +ir_constant::zero(void *mem_ctx, const glsl_type *type) +{ + assert(type->is_numeric() || type->is_boolean()); + + ir_constant *c = new(mem_ctx) ir_constant; + c->type = type; + memset(&c->value, 0, sizeof(c->value)); + + return c; +} + +bool +ir_constant::get_bool_component(unsigned i) const +{ + switch (this->type->base_type) { + case GLSL_TYPE_UINT: return this->value.u[i] != 0; + case GLSL_TYPE_INT: return this->value.i[i] != 0; + case GLSL_TYPE_FLOAT: return ((int)this->value.f[i]) != 0; + case GLSL_TYPE_BOOL: return this->value.b[i]; + default: assert(!"Should not get here."); break; + } + + /* Must return something to make the compiler happy. This is clearly an + * error case. + */ + return false; +} + +float +ir_constant::get_float_component(unsigned i) const +{ + switch (this->type->base_type) { + case GLSL_TYPE_UINT: return (float) this->value.u[i]; + case GLSL_TYPE_INT: return (float) this->value.i[i]; + case GLSL_TYPE_FLOAT: return this->value.f[i]; + case GLSL_TYPE_BOOL: return this->value.b[i] ? 1.0 : 0.0; + default: assert(!"Should not get here."); break; + } + + /* Must return something to make the compiler happy. This is clearly an + * error case. + */ + return 0.0; +} + +int +ir_constant::get_int_component(unsigned i) const +{ + switch (this->type->base_type) { + case GLSL_TYPE_UINT: return this->value.u[i]; + case GLSL_TYPE_INT: return this->value.i[i]; + case GLSL_TYPE_FLOAT: return (int) this->value.f[i]; + case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0; + default: assert(!"Should not get here."); break; + } + + /* Must return something to make the compiler happy. This is clearly an + * error case. + */ + return 0; +} + +unsigned +ir_constant::get_uint_component(unsigned i) const +{ + switch (this->type->base_type) { + case GLSL_TYPE_UINT: return this->value.u[i]; + case GLSL_TYPE_INT: return this->value.i[i]; + case GLSL_TYPE_FLOAT: return (unsigned) this->value.f[i]; + case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0; + default: assert(!"Should not get here."); break; + } + + /* Must return something to make the compiler happy. This is clearly an + * error case. + */ + return 0; +} + +ir_constant * +ir_constant::get_array_element(unsigned i) const +{ + assert(this->type->is_array()); + + /* From page 35 (page 41 of the PDF) of the GLSL 1.20 spec: + * + * "Behavior is undefined if a shader subscripts an array with an index + * less than 0 or greater than or equal to the size the array was + * declared with." + * + * Most out-of-bounds accesses are removed before things could get this far. + * There are cases where non-constant array index values can get constant + * folded. + */ + if (int(i) < 0) + i = 0; + else if (i >= this->type->length) + i = this->type->length - 1; + + return array_elements[i]; +} + +ir_constant * +ir_constant::get_record_field(const char *name) +{ + int idx = this->type->field_index(name); + + if (idx < 0) + return NULL; + + if (this->components.is_empty()) + return NULL; + + exec_node *node = this->components.head; + for (int i = 0; i < idx; i++) { + node = node->next; + + /* If the end of the list is encountered before the element matching the + * requested field is found, return NULL. + */ + if (node->is_tail_sentinel()) + return NULL; + } + + return (ir_constant *) node; +} + + +bool +ir_constant::has_value(const ir_constant *c) const +{ + if (this->type != c->type) + return false; + + if (this->type->is_array()) { + for (unsigned i = 0; i < this->type->length; i++) { + if (!this->array_elements[i]->has_value(c->array_elements[i])) + return false; + } + return true; + } + + if (this->type->base_type == GLSL_TYPE_STRUCT) { + const exec_node *a_node = this->components.head; + const exec_node *b_node = c->components.head; + + while (!a_node->is_tail_sentinel()) { + assert(!b_node->is_tail_sentinel()); + + const ir_constant *const a_field = (ir_constant *) a_node; + const ir_constant *const b_field = (ir_constant *) b_node; + + if (!a_field->has_value(b_field)) + return false; + + a_node = a_node->next; + b_node = b_node->next; + } + + return true; + } + + for (unsigned i = 0; i < this->type->components(); i++) { + switch (this->type->base_type) { + case GLSL_TYPE_UINT: + if (this->value.u[i] != c->value.u[i]) + return false; + break; + case GLSL_TYPE_INT: + if (this->value.i[i] != c->value.i[i]) + return false; + break; + case GLSL_TYPE_FLOAT: + if (this->value.f[i] != c->value.f[i]) + return false; + break; + case GLSL_TYPE_BOOL: + if (this->value.b[i] != c->value.b[i]) + return false; + break; + default: + assert(!"Should not get here."); + return false; + } + } + + return true; +} + +bool +ir_constant::is_zero() const +{ + if (!this->type->is_scalar() && !this->type->is_vector()) + return false; + + for (unsigned c = 0; c < this->type->vector_elements; c++) { + switch (this->type->base_type) { + case GLSL_TYPE_FLOAT: + if (this->value.f[c] != 0.0) + return false; + break; + case GLSL_TYPE_INT: + if (this->value.i[c] != 0) + return false; + break; + case GLSL_TYPE_UINT: + if (this->value.u[c] != 0) + return false; + break; + case GLSL_TYPE_BOOL: + if (this->value.b[c] != false) + return false; + break; + default: + /* The only other base types are structures, arrays, and samplers. + * Samplers cannot be constants, and the others should have been + * filtered out above. + */ + assert(!"Should not get here."); + return false; + } + } + + return true; +} + +bool +ir_constant::is_one() const +{ + if (!this->type->is_scalar() && !this->type->is_vector()) + return false; + + for (unsigned c = 0; c < this->type->vector_elements; c++) { + switch (this->type->base_type) { + case GLSL_TYPE_FLOAT: + if (this->value.f[c] != 1.0) + return false; + break; + case GLSL_TYPE_INT: + if (this->value.i[c] != 1) + return false; + break; + case GLSL_TYPE_UINT: + if (this->value.u[c] != 1) + return false; + break; + case GLSL_TYPE_BOOL: + if (this->value.b[c] != true) + return false; + break; + default: + /* The only other base types are structures, arrays, and samplers. + * Samplers cannot be constants, and the others should have been + * filtered out above. + */ + assert(!"Should not get here."); + return false; + } + } + + return true; +} + +bool +ir_constant::is_negative_one() const +{ + if (!this->type->is_scalar() && !this->type->is_vector()) + return false; + + if (this->type->is_boolean()) + return false; + + for (unsigned c = 0; c < this->type->vector_elements; c++) { + switch (this->type->base_type) { + case GLSL_TYPE_FLOAT: + if (this->value.f[c] != -1.0) + return false; + break; + case GLSL_TYPE_INT: + if (this->value.i[c] != -1) + return false; + break; + case GLSL_TYPE_UINT: + if (int(this->value.u[c]) != -1) + return false; + break; + default: + /* The only other base types are structures, arrays, samplers, and + * booleans. Samplers cannot be constants, and the others should + * have been filtered out above. + */ + assert(!"Should not get here."); + return false; + } + } + + return true; +} + +ir_loop::ir_loop() +{ + this->ir_type = ir_type_loop; + this->cmp = ir_unop_neg; + this->from = NULL; + this->to = NULL; + this->increment = NULL; + this->counter = NULL; +} + + +ir_dereference_variable::ir_dereference_variable(ir_variable *var) +{ + this->ir_type = ir_type_dereference_variable; + this->var = var; + this->type = (var != NULL) ? var->type : glsl_type::error_type; +} + + +ir_dereference_array::ir_dereference_array(ir_rvalue *value, + ir_rvalue *array_index) +{ + this->ir_type = ir_type_dereference_array; + this->array_index = array_index; + this->set_array(value); +} + + +ir_dereference_array::ir_dereference_array(ir_variable *var, + ir_rvalue *array_index) +{ + void *ctx = ralloc_parent(var); + + this->ir_type = ir_type_dereference_array; + this->array_index = array_index; + this->set_array(new(ctx) ir_dereference_variable(var)); +} + + +void +ir_dereference_array::set_array(ir_rvalue *value) +{ + this->array = value; + this->type = glsl_type::error_type; + + if (this->array != NULL) { + const glsl_type *const vt = this->array->type; + + if (vt->is_array()) { + type = vt->element_type(); + } else if (vt->is_matrix()) { + type = vt->column_type(); + } else if (vt->is_vector()) { + type = vt->get_base_type(); + } + } +} + + +ir_dereference_record::ir_dereference_record(ir_rvalue *value, + const char *field) +{ + this->ir_type = ir_type_dereference_record; + this->record = value; + this->field = ralloc_strdup(this, field); + this->type = (this->record != NULL) + ? this->record->type->field_type(field) : glsl_type::error_type; +} + + +ir_dereference_record::ir_dereference_record(ir_variable *var, + const char *field) +{ + void *ctx = ralloc_parent(var); + + this->ir_type = ir_type_dereference_record; + this->record = new(ctx) ir_dereference_variable(var); + this->field = ralloc_strdup(this, field); + this->type = (this->record != NULL) + ? this->record->type->field_type(field) : glsl_type::error_type; +} + +bool type_contains_sampler(const glsl_type *type) +{ + if (type->is_array()) { + return type_contains_sampler(type->fields.array); + } else if (type->is_record()) { + for (unsigned int i = 0; i < type->length; i++) { + if (type_contains_sampler(type->fields.structure[i].type)) + return true; + } + return false; + } else { + return type->is_sampler(); + } +} + +bool +ir_dereference::is_lvalue() +{ + ir_variable *var = this->variable_referenced(); + + /* Every l-value derference chain eventually ends in a variable. + */ + if ((var == NULL) || var->read_only) + return false; + + if (this->type->is_array() && !var->array_lvalue) + return false; + + /* From page 17 (page 23 of the PDF) of the GLSL 1.20 spec: + * + * "Samplers cannot be treated as l-values; hence cannot be used + * as out or inout function parameters, nor can they be + * assigned into." + */ + if (type_contains_sampler(this->type)) + return false; + + return true; +} + + +const char *tex_opcode_strs[] = { "tex", "txb", "txl", "txd", "txf" }; + +const char *ir_texture::opcode_string() +{ + assert((unsigned int) op <= + sizeof(tex_opcode_strs) / sizeof(tex_opcode_strs[0])); + return tex_opcode_strs[op]; +} + +ir_texture_opcode +ir_texture::get_opcode(const char *str) +{ + const int count = sizeof(tex_opcode_strs) / sizeof(tex_opcode_strs[0]); + for (int op = 0; op < count; op++) { + if (strcmp(str, tex_opcode_strs[op]) == 0) + return (ir_texture_opcode) op; + } + return (ir_texture_opcode) -1; +} + + +void +ir_texture::set_sampler(ir_dereference *sampler) +{ + assert(sampler != NULL); + this->sampler = sampler; + + switch (sampler->type->sampler_type) { + case GLSL_TYPE_FLOAT: + this->type = glsl_type::vec4_type; + break; + case GLSL_TYPE_INT: + this->type = glsl_type::ivec4_type; + break; + case GLSL_TYPE_UINT: + this->type = glsl_type::uvec4_type; + break; + } +} + + +void +ir_swizzle::init_mask(const unsigned *comp, unsigned count) +{ + assert((count >= 1) && (count <= 4)); + + memset(&this->mask, 0, sizeof(this->mask)); + this->mask.num_components = count; + + unsigned dup_mask = 0; + switch (count) { + case 4: + assert(comp[3] <= 3); + dup_mask |= (1U << comp[3]) + & ((1U << comp[0]) | (1U << comp[1]) | (1U << comp[2])); + this->mask.w = comp[3]; + + case 3: + assert(comp[2] <= 3); + dup_mask |= (1U << comp[2]) + & ((1U << comp[0]) | (1U << comp[1])); + this->mask.z = comp[2]; + + case 2: + assert(comp[1] <= 3); + dup_mask |= (1U << comp[1]) + & ((1U << comp[0])); + this->mask.y = comp[1]; + + case 1: + assert(comp[0] <= 3); + this->mask.x = comp[0]; + } + + this->mask.has_duplicates = dup_mask != 0; + + /* Based on the number of elements in the swizzle and the base type + * (i.e., float, int, unsigned, or bool) of the vector being swizzled, + * generate the type of the resulting value. + */ + type = glsl_type::get_instance(val->type->base_type, mask.num_components, 1); +} + +ir_swizzle::ir_swizzle(ir_rvalue *val, unsigned x, unsigned y, unsigned z, + unsigned w, unsigned count) + : val(val) +{ + const unsigned components[4] = { x, y, z, w }; + this->ir_type = ir_type_swizzle; + this->init_mask(components, count); +} + +ir_swizzle::ir_swizzle(ir_rvalue *val, const unsigned *comp, + unsigned count) + : val(val) +{ + this->ir_type = ir_type_swizzle; + this->init_mask(comp, count); +} + +ir_swizzle::ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask) +{ + this->ir_type = ir_type_swizzle; + this->val = val; + this->mask = mask; + this->type = glsl_type::get_instance(val->type->base_type, + mask.num_components, 1); +} + +#define X 1 +#define R 5 +#define S 9 +#define I 13 + +ir_swizzle * +ir_swizzle::create(ir_rvalue *val, const char *str, unsigned vector_length) +{ + void *ctx = ralloc_parent(val); + + /* For each possible swizzle character, this table encodes the value in + * \c idx_map that represents the 0th element of the vector. For invalid + * swizzle characters (e.g., 'k'), a special value is used that will allow + * detection of errors. + */ + static const unsigned char base_idx[26] = { + /* a b c d e f g h i j k l m */ + R, R, I, I, I, I, R, I, I, I, I, I, I, + /* n o p q r s t u v w x y z */ + I, I, S, S, R, S, S, I, I, X, X, X, X + }; + + /* Each valid swizzle character has an entry in the previous table. This + * table encodes the base index encoded in the previous table plus the actual + * index of the swizzle character. When processing swizzles, the first + * character in the string is indexed in the previous table. Each character + * in the string is indexed in this table, and the value found there has the + * value form the first table subtracted. The result must be on the range + * [0,3]. + * + * For example, the string "wzyx" will get X from the first table. Each of + * the charcaters will get X+3, X+2, X+1, and X+0 from this table. After + * subtraction, the swizzle values are { 3, 2, 1, 0 }. + * + * The string "wzrg" will get X from the first table. Each of the characters + * will get X+3, X+2, R+0, and R+1 from this table. After subtraction, the + * swizzle values are { 3, 2, 4, 5 }. Since 4 and 5 are outside the range + * [0,3], the error is detected. + */ + static const unsigned char idx_map[26] = { + /* a b c d e f g h i j k l m */ + R+3, R+2, 0, 0, 0, 0, R+1, 0, 0, 0, 0, 0, 0, + /* n o p q r s t u v w x y z */ + 0, 0, S+2, S+3, R+0, S+0, S+1, 0, 0, X+3, X+0, X+1, X+2 + }; + + int swiz_idx[4] = { 0, 0, 0, 0 }; + unsigned i; + + + /* Validate the first character in the swizzle string and look up the base + * index value as described above. + */ + if ((str[0] < 'a') || (str[0] > 'z')) + return NULL; + + const unsigned base = base_idx[str[0] - 'a']; + + + for (i = 0; (i < 4) && (str[i] != '\0'); i++) { + /* Validate the next character, and, as described above, convert it to a + * swizzle index. + */ + if ((str[i] < 'a') || (str[i] > 'z')) + return NULL; + + swiz_idx[i] = idx_map[str[i] - 'a'] - base; + if ((swiz_idx[i] < 0) || (swiz_idx[i] >= (int) vector_length)) + return NULL; + } + + if (str[i] != '\0') + return NULL; + + return new(ctx) ir_swizzle(val, swiz_idx[0], swiz_idx[1], swiz_idx[2], + swiz_idx[3], i); +} + +#undef X +#undef R +#undef S +#undef I + +ir_variable * +ir_swizzle::variable_referenced() +{ + return this->val->variable_referenced(); +} + + +ir_variable::ir_variable(const struct glsl_type *type, const char *name, + ir_variable_mode mode) + : max_array_access(0), read_only(false), centroid(false), invariant(false), + mode(mode), interpolation(ir_var_smooth), array_lvalue(false) +{ + this->ir_type = ir_type_variable; + this->type = type; + this->name = ralloc_strdup(this, name); + this->explicit_location = false; + this->location = -1; + this->warn_extension = NULL; + this->constant_value = NULL; + this->origin_upper_left = false; + this->pixel_center_integer = false; + this->used = false; + + if (type && type->base_type == GLSL_TYPE_SAMPLER) + this->read_only = true; +} + + +const char * +ir_variable::interpolation_string() const +{ + switch (this->interpolation) { + case ir_var_smooth: return "smooth"; + case ir_var_flat: return "flat"; + case ir_var_noperspective: return "noperspective"; + } + + assert(!"Should not get here."); + return ""; +} + + +unsigned +ir_variable::component_slots() const +{ + /* FINISHME: Sparsely accessed arrays require fewer slots. */ + return this->type->component_slots(); +} + + +ir_function_signature::ir_function_signature(const glsl_type *return_type) + : return_type(return_type), is_defined(false), _function(NULL) +{ + this->ir_type = ir_type_function_signature; + this->is_builtin = false; +} + + +const char * +ir_function_signature::qualifiers_match(exec_list *params) +{ + exec_list_iterator iter_a = parameters.iterator(); + exec_list_iterator iter_b = params->iterator(); + + /* check that the qualifiers match. */ + while (iter_a.has_next()) { + ir_variable *a = (ir_variable *)iter_a.get(); + ir_variable *b = (ir_variable *)iter_b.get(); + + if (a->read_only != b->read_only || + a->mode != b->mode || + a->interpolation != b->interpolation || + a->centroid != b->centroid) { + + /* parameter a's qualifiers don't match */ + return a->name; + } + + iter_a.next(); + iter_b.next(); + } + return NULL; +} + + +void +ir_function_signature::replace_parameters(exec_list *new_params) +{ + /* Destroy all of the previous parameter information. If the previous + * parameter information comes from the function prototype, it may either + * specify incorrect parameter names or not have names at all. + */ + foreach_iter(exec_list_iterator, iter, parameters) { + assert(((ir_instruction *) iter.get())->as_variable() != NULL); + + iter.remove(); + } + + new_params->move_nodes_to(¶meters); +} + + +ir_function::ir_function(const char *name) +{ + this->ir_type = ir_type_function; + this->name = ralloc_strdup(this, name); +} + + +bool +ir_function::has_user_signature() +{ + foreach_list(n, &this->signatures) { + ir_function_signature *const sig = (ir_function_signature *) n; + if (!sig->is_builtin) + return true; + } + return false; +} + + +ir_call * +ir_call::get_error_instruction(void *ctx) +{ + ir_call *call = new(ctx) ir_call; + + call->type = glsl_type::error_type; + return call; +} + +void +ir_call::set_callee(ir_function_signature *sig) +{ + assert((this->type == NULL) || (this->type == sig->return_type)); + + this->callee = sig; +} + +void +visit_exec_list(exec_list *list, ir_visitor *visitor) +{ + foreach_iter(exec_list_iterator, iter, *list) { + ((ir_instruction *)iter.get())->accept(visitor); + } +} + + +static void +steal_memory(ir_instruction *ir, void *new_ctx) +{ + ir_variable *var = ir->as_variable(); + ir_constant *constant = ir->as_constant(); + if (var != NULL && var->constant_value != NULL) + steal_memory(var->constant_value, ir); + + /* The components of aggregate constants are not visited by the normal + * visitor, so steal their values by hand. + */ + if (constant != NULL) { + if (constant->type->is_record()) { + foreach_iter(exec_list_iterator, iter, constant->components) { + ir_constant *field = (ir_constant *)iter.get(); + steal_memory(field, ir); + } + } else if (constant->type->is_array()) { + for (unsigned int i = 0; i < constant->type->length; i++) { + steal_memory(constant->array_elements[i], ir); + } + } + } + + ralloc_steal(new_ctx, ir); +} + + +void +reparent_ir(exec_list *list, void *mem_ctx) +{ + foreach_list(node, list) { + visit_tree((ir_instruction *) node, steal_memory, mem_ctx); + } +} + + +static ir_rvalue * +try_min_one(ir_rvalue *ir) +{ + ir_expression *expr = ir->as_expression(); + + if (!expr || expr->operation != ir_binop_min) + return NULL; + + if (expr->operands[0]->is_one()) + return expr->operands[1]; + + if (expr->operands[1]->is_one()) + return expr->operands[0]; + + return NULL; +} + +static ir_rvalue * +try_max_zero(ir_rvalue *ir) +{ + ir_expression *expr = ir->as_expression(); + + if (!expr || expr->operation != ir_binop_max) + return NULL; + + if (expr->operands[0]->is_zero()) + return expr->operands[1]; + + if (expr->operands[1]->is_zero()) + return expr->operands[0]; + + return NULL; +} + +ir_rvalue * +ir_rvalue::as_rvalue_to_saturate() +{ + ir_expression *expr = this->as_expression(); + + if (!expr) + return NULL; + + ir_rvalue *max_zero = try_max_zero(expr); + if (max_zero) { + return try_min_one(max_zero); + } else { + ir_rvalue *min_one = try_min_one(expr); + if (min_one) { + return try_max_zero(min_one); + } + } + + return NULL; +} diff --git a/src/glsl/ir.h b/src/glsl/ir.h new file mode 100644 index 0000000..243723c --- /dev/null +++ b/src/glsl/ir.h @@ -0,0 +1,1612 @@ +/* -*- c++ -*- */ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#ifndef IR_H +#define IR_H + +#include +#include + +#include "ralloc.h" +#include "glsl_types.h" +#include "list.h" +#include "ir_visitor.h" +#include "ir_hierarchical_visitor.h" + +/** + * \defgroup IR Intermediate representation nodes + * + * @{ + */ + +/** + * Class tags + * + * Each concrete class derived from \c ir_instruction has a value in this + * enumerant. The value for the type is stored in \c ir_instruction::ir_type + * by the constructor. While using type tags is not very C++, it is extremely + * convenient. For example, during debugging you can simply inspect + * \c ir_instruction::ir_type to find out the actual type of the object. + * + * In addition, it is possible to use a switch-statement based on \c + * \c ir_instruction::ir_type to select different behavior for different object + * types. For functions that have only slight differences for several object + * types, this allows writing very straightforward, readable code. + */ +enum ir_node_type { + /** + * Zero is unused so that the IR validator can detect cases where + * \c ir_instruction::ir_type has not been initialized. + */ + ir_type_unset, + ir_type_variable, + ir_type_assignment, + ir_type_call, + ir_type_constant, + ir_type_dereference_array, + ir_type_dereference_record, + ir_type_dereference_variable, + ir_type_discard, + ir_type_expression, + ir_type_function, + ir_type_function_signature, + ir_type_if, + ir_type_loop, + ir_type_loop_jump, + ir_type_return, + ir_type_swizzle, + ir_type_texture, + ir_type_max /**< maximum ir_type enum number, for validation */ +}; + +/** + * Base class of all IR instructions + */ +class ir_instruction : public exec_node { +public: + enum ir_node_type ir_type; + const struct glsl_type *type; + + /** ir_print_visitor helper for debugging. */ + void print(void) const; + + virtual void accept(ir_visitor *) = 0; + virtual ir_visitor_status accept(ir_hierarchical_visitor *) = 0; + virtual ir_instruction *clone(void *mem_ctx, + struct hash_table *ht) const = 0; + + /** + * \name IR instruction downcast functions + * + * These functions either cast the object to a derived class or return + * \c NULL if the object's type does not match the specified derived class. + * Additional downcast functions will be added as needed. + */ + /*@{*/ + virtual class ir_variable * as_variable() { return NULL; } + virtual class ir_function * as_function() { return NULL; } + virtual class ir_dereference * as_dereference() { return NULL; } + virtual class ir_dereference_array * as_dereference_array() { return NULL; } + virtual class ir_dereference_variable *as_dereference_variable() { return NULL; } + virtual class ir_expression * as_expression() { return NULL; } + virtual class ir_rvalue * as_rvalue() { return NULL; } + virtual class ir_loop * as_loop() { return NULL; } + virtual class ir_assignment * as_assignment() { return NULL; } + virtual class ir_call * as_call() { return NULL; } + virtual class ir_return * as_return() { return NULL; } + virtual class ir_if * as_if() { return NULL; } + virtual class ir_swizzle * as_swizzle() { return NULL; } + virtual class ir_constant * as_constant() { return NULL; } + virtual class ir_discard * as_discard() { return NULL; } + /*@}*/ + +protected: + ir_instruction() + { + ir_type = ir_type_unset; + type = NULL; + } +}; + + +class ir_rvalue : public ir_instruction { +public: + virtual ir_rvalue *clone(void *mem_ctx, struct hash_table *) const = 0; + + virtual ir_constant *constant_expression_value() = 0; + + virtual ir_rvalue * as_rvalue() + { + return this; + } + + ir_rvalue *as_rvalue_to_saturate(); + + virtual bool is_lvalue() + { + return false; + } + + /** + * Get the variable that is ultimately referenced by an r-value + */ + virtual ir_variable *variable_referenced() + { + return NULL; + } + + + /** + * If an r-value is a reference to a whole variable, get that variable + * + * \return + * Pointer to a variable that is completely dereferenced by the r-value. If + * the r-value is not a dereference or the dereference does not access the + * entire variable (i.e., it's just one array element, struct field), \c NULL + * is returned. + */ + virtual ir_variable *whole_variable_referenced() + { + return NULL; + } + + /** + * Determine if an r-value has the value zero + * + * The base implementation of this function always returns \c false. The + * \c ir_constant class over-rides this function to return \c true \b only + * for vector and scalar types that have all elements set to the value + * zero (or \c false for booleans). + * + * \sa ir_constant::has_value, ir_rvalue::is_one, ir_rvalue::is_negative_one + */ + virtual bool is_zero() const; + + /** + * Determine if an r-value has the value one + * + * The base implementation of this function always returns \c false. The + * \c ir_constant class over-rides this function to return \c true \b only + * for vector and scalar types that have all elements set to the value + * one (or \c true for booleans). + * + * \sa ir_constant::has_value, ir_rvalue::is_zero, ir_rvalue::is_negative_one + */ + virtual bool is_one() const; + + /** + * Determine if an r-value has the value negative one + * + * The base implementation of this function always returns \c false. The + * \c ir_constant class over-rides this function to return \c true \b only + * for vector and scalar types that have all elements set to the value + * negative one. For boolean times, the result is always \c false. + * + * \sa ir_constant::has_value, ir_rvalue::is_zero, ir_rvalue::is_one + */ + virtual bool is_negative_one() const; + +protected: + ir_rvalue(); +}; + + +/** + * Variable storage classes + */ +enum ir_variable_mode { + ir_var_auto = 0, /**< Function local variables and globals. */ + ir_var_uniform, /**< Variable declared as a uniform. */ + ir_var_in, + ir_var_out, + ir_var_inout, + ir_var_temporary /**< Temporary variable generated during compilation. */ +}; + +enum ir_variable_interpolation { + ir_var_smooth = 0, + ir_var_flat, + ir_var_noperspective +}; + + +class ir_variable : public ir_instruction { +public: + ir_variable(const struct glsl_type *, const char *, ir_variable_mode); + + virtual ir_variable *clone(void *mem_ctx, struct hash_table *ht) const; + + virtual ir_variable *as_variable() + { + return this; + } + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + + /** + * Get the string value for the interpolation qualifier + * + * \return The string that would be used in a shader to specify \c + * mode will be returned. + * + * This function should only be used on a shader input or output variable. + */ + const char *interpolation_string() const; + + /** + * Calculate the number of slots required to hold this variable + * + * This is used to determine how many uniform or varying locations a variable + * occupies. The count is in units of floating point components. + */ + unsigned component_slots() const; + + /** + * Delcared name of the variable + */ + const char *name; + + /** + * Highest element accessed with a constant expression array index + * + * Not used for non-array variables. + */ + unsigned max_array_access; + + /** + * Is the variable read-only? + * + * This is set for variables declared as \c const, shader inputs, + * and uniforms. + */ + unsigned read_only:1; + unsigned centroid:1; + unsigned invariant:1; + + /** + * Has this variable been used for reading or writing? + * + * Several GLSL semantic checks require knowledge of whether or not a + * variable has been used. For example, it is an error to redeclare a + * variable as invariant after it has been used. + */ + unsigned used:1; + + /** + * Storage class of the variable. + * + * \sa ir_variable_mode + */ + unsigned mode:3; + + /** + * Interpolation mode for shader inputs / outputs + * + * \sa ir_variable_interpolation + */ + unsigned interpolation:2; + + /** + * Flag that the whole array is assignable + * + * In GLSL 1.20 and later whole arrays are assignable (and comparable for + * equality). This flag enables this behavior. + */ + unsigned array_lvalue:1; + + /** + * \name ARB_fragment_coord_conventions + * @{ + */ + unsigned origin_upper_left:1; + unsigned pixel_center_integer:1; + /*@}*/ + + /** + * Was the location explicitly set in the shader? + * + * If the location is explicitly set in the shader, it \b cannot be changed + * by the linker or by the API (e.g., calls to \c glBindAttribLocation have + * no effect). + */ + unsigned explicit_location:1; + + /** + * Storage location of the base of this variable + * + * The precise meaning of this field depends on the nature of the variable. + * + * - Vertex shader input: one of the values from \c gl_vert_attrib. + * - Vertex shader output: one of the values from \c gl_vert_result. + * - Fragment shader input: one of the values from \c gl_frag_attrib. + * - Fragment shader output: one of the values from \c gl_frag_result. + * - Uniforms: Per-stage uniform slot number. + * - Other: This field is not currently used. + * + * If the variable is a uniform, shader input, or shader output, and the + * slot has not been assigned, the value will be -1. + */ + int location; + + /** + * Emit a warning if this variable is accessed. + */ + const char *warn_extension; + + /** + * Value assigned in the initializer of a variable declared "const" + */ + ir_constant *constant_value; +}; + + +/*@{*/ +/** + * The representation of a function instance; may be the full definition or + * simply a prototype. + */ +class ir_function_signature : public ir_instruction { + /* An ir_function_signature will be part of the list of signatures in + * an ir_function. + */ +public: + ir_function_signature(const glsl_type *return_type); + + virtual ir_function_signature *clone(void *mem_ctx, + struct hash_table *ht) const; + ir_function_signature *clone_prototype(void *mem_ctx, + struct hash_table *ht) const; + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + /** + * Get the name of the function for which this is a signature + */ + const char *function_name() const; + + /** + * Get a handle to the function for which this is a signature + * + * There is no setter function, this function returns a \c const pointer, + * and \c ir_function_signature::_function is private for a reason. The + * only way to make a connection between a function and function signature + * is via \c ir_function::add_signature. This helps ensure that certain + * invariants (i.e., a function signature is in the list of signatures for + * its \c _function) are met. + * + * \sa ir_function::add_signature + */ + inline const class ir_function *function() const + { + return this->_function; + } + + /** + * Check whether the qualifiers match between this signature's parameters + * and the supplied parameter list. If not, returns the name of the first + * parameter with mismatched qualifiers (for use in error messages). + */ + const char *qualifiers_match(exec_list *params); + + /** + * Replace the current parameter list with the given one. This is useful + * if the current information came from a prototype, and either has invalid + * or missing parameter names. + */ + void replace_parameters(exec_list *new_params); + + /** + * Function return type. + * + * \note This discards the optional precision qualifier. + */ + const struct glsl_type *return_type; + + /** + * List of ir_variable of function parameters. + * + * This represents the storage. The paramaters passed in a particular + * call will be in ir_call::actual_paramaters. + */ + struct exec_list parameters; + + /** Whether or not this function has a body (which may be empty). */ + unsigned is_defined:1; + + /** Whether or not this function signature is a built-in. */ + unsigned is_builtin:1; + + /** Body of instructions in the function. */ + struct exec_list body; + +private: + /** Function of which this signature is one overload. */ + class ir_function *_function; + + friend class ir_function; +}; + + +/** + * Header for tracking multiple overloaded functions with the same name. + * Contains a list of ir_function_signatures representing each of the + * actual functions. + */ +class ir_function : public ir_instruction { +public: + ir_function(const char *name); + + virtual ir_function *clone(void *mem_ctx, struct hash_table *ht) const; + + virtual ir_function *as_function() + { + return this; + } + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + void add_signature(ir_function_signature *sig) + { + sig->_function = this; + this->signatures.push_tail(sig); + } + + /** + * Get an iterator for the set of function signatures + */ + exec_list_iterator iterator() + { + return signatures.iterator(); + } + + /** + * Find a signature that matches a set of actual parameters, taking implicit + * conversions into account. + */ + ir_function_signature *matching_signature(const exec_list *actual_param); + + /** + * Find a signature that exactly matches a set of actual parameters without + * any implicit type conversions. + */ + ir_function_signature *exact_matching_signature(const exec_list *actual_ps); + + /** + * Name of the function. + */ + const char *name; + + /** Whether or not this function has a signature that isn't a built-in. */ + bool has_user_signature(); + + /** + * List of ir_function_signature for each overloaded function with this name. + */ + struct exec_list signatures; +}; + +inline const char *ir_function_signature::function_name() const +{ + return this->_function->name; +} +/*@}*/ + + +/** + * IR instruction representing high-level if-statements + */ +class ir_if : public ir_instruction { +public: + ir_if(ir_rvalue *condition) + : condition(condition) + { + ir_type = ir_type_if; + } + + virtual ir_if *clone(void *mem_ctx, struct hash_table *ht) const; + + virtual ir_if *as_if() + { + return this; + } + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + ir_rvalue *condition; + /** List of ir_instruction for the body of the then branch */ + exec_list then_instructions; + /** List of ir_instruction for the body of the else branch */ + exec_list else_instructions; +}; + + +/** + * IR instruction representing a high-level loop structure. + */ +class ir_loop : public ir_instruction { +public: + ir_loop(); + + virtual ir_loop *clone(void *mem_ctx, struct hash_table *ht) const; + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + virtual ir_loop *as_loop() + { + return this; + } + + /** + * Get an iterator for the instructions of the loop body + */ + exec_list_iterator iterator() + { + return body_instructions.iterator(); + } + + /** List of ir_instruction that make up the body of the loop. */ + exec_list body_instructions; + + /** + * \name Loop counter and controls + * + * Represents a loop like a FORTRAN \c do-loop. + * + * \note + * If \c from and \c to are the same value, the loop will execute once. + */ + /*@{*/ + ir_rvalue *from; /** Value of the loop counter on the first + * iteration of the loop. + */ + ir_rvalue *to; /** Value of the loop counter on the last + * iteration of the loop. + */ + ir_rvalue *increment; + ir_variable *counter; + + /** + * Comparison operation in the loop terminator. + * + * If any of the loop control fields are non-\c NULL, this field must be + * one of \c ir_binop_less, \c ir_binop_greater, \c ir_binop_lequal, + * \c ir_binop_gequal, \c ir_binop_equal, or \c ir_binop_nequal. + */ + int cmp; + /*@}*/ +}; + + +class ir_assignment : public ir_instruction { +public: + ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition); + + /** + * Construct an assignment with an explicit write mask + * + * \note + * Since a write mask is supplied, the LHS must already be a bare + * \c ir_dereference. The cannot be any swizzles in the LHS. + */ + ir_assignment(ir_dereference *lhs, ir_rvalue *rhs, ir_rvalue *condition, + unsigned write_mask); + + virtual ir_assignment *clone(void *mem_ctx, struct hash_table *ht) const; + + virtual ir_constant *constant_expression_value(); + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + virtual ir_assignment * as_assignment() + { + return this; + } + + /** + * Get a whole variable written by an assignment + * + * If the LHS of the assignment writes a whole variable, the variable is + * returned. Otherwise \c NULL is returned. Examples of whole-variable + * assignment are: + * + * - Assigning to a scalar + * - Assigning to all components of a vector + * - Whole array (or matrix) assignment + * - Whole structure assignment + */ + ir_variable *whole_variable_written(); + + /** + * Set the LHS of an assignment + */ + void set_lhs(ir_rvalue *lhs); + + /** + * Left-hand side of the assignment. + * + * This should be treated as read only. If you need to set the LHS of an + * assignment, use \c ir_assignment::set_lhs. + */ + ir_dereference *lhs; + + /** + * Value being assigned + */ + ir_rvalue *rhs; + + /** + * Optional condition for the assignment. + */ + ir_rvalue *condition; + + + /** + * Component mask written + * + * For non-vector types in the LHS, this field will be zero. For vector + * types, a bit will be set for each component that is written. Note that + * for \c vec2 and \c vec3 types only the lower bits will ever be set. + * + * A partially-set write mask means that each enabled channel gets + * the value from a consecutive channel of the rhs. For example, + * to write just .xyw of gl_FrontColor with color: + * + * (assign (constant bool (1)) (xyw) + * (var_ref gl_FragColor) + * (swiz xyw (var_ref color))) + */ + unsigned write_mask:4; +}; + +/* Update ir_expression::num_operands() and operator_strs when + * updating this list. + */ +enum ir_expression_operation { + ir_unop_bit_not, + ir_unop_logic_not, + ir_unop_neg, + ir_unop_abs, + ir_unop_sign, + ir_unop_rcp, + ir_unop_rsq, + ir_unop_sqrt, + ir_unop_exp, /**< Log base e on gentype */ + ir_unop_log, /**< Natural log on gentype */ + ir_unop_exp2, + ir_unop_log2, + ir_unop_f2i, /**< Float-to-integer conversion. */ + ir_unop_i2f, /**< Integer-to-float conversion. */ + ir_unop_f2b, /**< Float-to-boolean conversion */ + ir_unop_b2f, /**< Boolean-to-float conversion */ + ir_unop_i2b, /**< int-to-boolean conversion */ + ir_unop_b2i, /**< Boolean-to-int conversion */ + ir_unop_u2f, /**< Unsigned-to-float conversion. */ + ir_unop_any, + + /** + * \name Unary floating-point rounding operations. + */ + /*@{*/ + ir_unop_trunc, + ir_unop_ceil, + ir_unop_floor, + ir_unop_fract, + ir_unop_round_even, + /*@}*/ + + /** + * \name Trigonometric operations. + */ + /*@{*/ + ir_unop_sin, + ir_unop_cos, + ir_unop_sin_reduced, /**< Reduced range sin. [-pi, pi] */ + ir_unop_cos_reduced, /**< Reduced range cos. [-pi, pi] */ + /*@}*/ + + /** + * \name Partial derivatives. + */ + /*@{*/ + ir_unop_dFdx, + ir_unop_dFdy, + /*@}*/ + + ir_unop_noise, + + /** + * A sentinel marking the last of the unary operations. + */ + ir_last_unop = ir_unop_noise, + + ir_binop_add, + ir_binop_sub, + ir_binop_mul, + ir_binop_div, + + /** + * Takes one of two combinations of arguments: + * + * - mod(vecN, vecN) + * - mod(vecN, float) + * + * Does not take integer types. + */ + ir_binop_mod, + + /** + * \name Binary comparison operators which return a boolean vector. + * The type of both operands must be equal. + */ + /*@{*/ + ir_binop_less, + ir_binop_greater, + ir_binop_lequal, + ir_binop_gequal, + ir_binop_equal, + ir_binop_nequal, + /** + * Returns single boolean for whether all components of operands[0] + * equal the components of operands[1]. + */ + ir_binop_all_equal, + /** + * Returns single boolean for whether any component of operands[0] + * is not equal to the corresponding component of operands[1]. + */ + ir_binop_any_nequal, + /*@}*/ + + /** + * \name Bit-wise binary operations. + */ + /*@{*/ + ir_binop_lshift, + ir_binop_rshift, + ir_binop_bit_and, + ir_binop_bit_xor, + ir_binop_bit_or, + /*@}*/ + + ir_binop_logic_and, + ir_binop_logic_xor, + ir_binop_logic_or, + + ir_binop_dot, + ir_binop_min, + ir_binop_max, + + ir_binop_pow, + + /** + * A sentinel marking the last of the binary operations. + */ + ir_last_binop = ir_binop_pow, + + ir_quadop_vector, + + /** + * A sentinel marking the last of all operations. + */ + ir_last_opcode = ir_last_binop +}; + +class ir_expression : public ir_rvalue { +public: + /** + * Constructor for unary operation expressions + */ + ir_expression(int op, const struct glsl_type *type, ir_rvalue *); + ir_expression(int op, ir_rvalue *); + + /** + * Constructor for binary operation expressions + */ + ir_expression(int op, const struct glsl_type *type, + ir_rvalue *, ir_rvalue *); + ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1); + + /** + * Constructor for quad operator expressions + */ + ir_expression(int op, const struct glsl_type *type, + ir_rvalue *, ir_rvalue *, ir_rvalue *, ir_rvalue *); + + virtual ir_expression *as_expression() + { + return this; + } + + virtual ir_expression *clone(void *mem_ctx, struct hash_table *ht) const; + + /** + * Attempt to constant-fold the expression + * + * If the expression cannot be constant folded, this method will return + * \c NULL. + */ + virtual ir_constant *constant_expression_value(); + + /** + * Determine the number of operands used by an expression + */ + static unsigned int get_num_operands(ir_expression_operation); + + /** + * Determine the number of operands used by an expression + */ + unsigned int get_num_operands() const + { + return (this->operation == ir_quadop_vector) + ? this->type->vector_elements : get_num_operands(operation); + } + + /** + * Return a string representing this expression's operator. + */ + const char *operator_string(); + + /** + * Return a string representing this expression's operator. + */ + static const char *operator_string(ir_expression_operation); + + + /** + * Do a reverse-lookup to translate the given string into an operator. + */ + static ir_expression_operation get_operator(const char *); + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + ir_expression_operation operation; + ir_rvalue *operands[4]; +}; + + +/** + * IR instruction representing a function call + */ +class ir_call : public ir_rvalue { +public: + ir_call(ir_function_signature *callee, exec_list *actual_parameters) + : callee(callee) + { + ir_type = ir_type_call; + assert(callee->return_type != NULL); + type = callee->return_type; + actual_parameters->move_nodes_to(& this->actual_parameters); + } + + virtual ir_call *clone(void *mem_ctx, struct hash_table *ht) const; + + virtual ir_constant *constant_expression_value(); + + virtual ir_call *as_call() + { + return this; + } + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + /** + * Get a generic ir_call object when an error occurs + * + * Any allocation will be performed with 'ctx' as ralloc owner. + */ + static ir_call *get_error_instruction(void *ctx); + + /** + * Get an iterator for the set of acutal parameters + */ + exec_list_iterator iterator() + { + return actual_parameters.iterator(); + } + + /** + * Get the name of the function being called. + */ + const char *callee_name() const + { + return callee->function_name(); + } + + /** + * Get the function signature bound to this function call + */ + ir_function_signature *get_callee() + { + return callee; + } + + /** + * Set the function call target + */ + void set_callee(ir_function_signature *sig); + + /** + * Generates an inline version of the function before @ir, + * returning the return value of the function. + */ + ir_rvalue *generate_inline(ir_instruction *ir); + + /* List of ir_rvalue of paramaters passed in this call. */ + exec_list actual_parameters; + +private: + ir_call() + : callee(NULL) + { + this->ir_type = ir_type_call; + } + + ir_function_signature *callee; +}; + + +/** + * \name Jump-like IR instructions. + * + * These include \c break, \c continue, \c return, and \c discard. + */ +/*@{*/ +class ir_jump : public ir_instruction { +protected: + ir_jump() + { + ir_type = ir_type_unset; + } +}; + +class ir_return : public ir_jump { +public: + ir_return() + : value(NULL) + { + this->ir_type = ir_type_return; + } + + ir_return(ir_rvalue *value) + : value(value) + { + this->ir_type = ir_type_return; + } + + virtual ir_return *clone(void *mem_ctx, struct hash_table *) const; + + virtual ir_return *as_return() + { + return this; + } + + ir_rvalue *get_value() const + { + return value; + } + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + ir_rvalue *value; +}; + + +/** + * Jump instructions used inside loops + * + * These include \c break and \c continue. The \c break within a loop is + * different from the \c break within a switch-statement. + * + * \sa ir_switch_jump + */ +class ir_loop_jump : public ir_jump { +public: + enum jump_mode { + jump_break, + jump_continue + }; + + ir_loop_jump(jump_mode mode) + { + this->ir_type = ir_type_loop_jump; + this->mode = mode; + this->loop = loop; + } + + virtual ir_loop_jump *clone(void *mem_ctx, struct hash_table *) const; + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + bool is_break() const + { + return mode == jump_break; + } + + bool is_continue() const + { + return mode == jump_continue; + } + + /** Mode selector for the jump instruction. */ + enum jump_mode mode; +private: + /** Loop containing this break instruction. */ + ir_loop *loop; +}; + +/** + * IR instruction representing discard statements. + */ +class ir_discard : public ir_jump { +public: + ir_discard() + { + this->ir_type = ir_type_discard; + this->condition = NULL; + } + + ir_discard(ir_rvalue *cond) + { + this->ir_type = ir_type_discard; + this->condition = cond; + } + + virtual ir_discard *clone(void *mem_ctx, struct hash_table *ht) const; + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + virtual ir_discard *as_discard() + { + return this; + } + + ir_rvalue *condition; +}; +/*@}*/ + + +/** + * Texture sampling opcodes used in ir_texture + */ +enum ir_texture_opcode { + ir_tex, /**< Regular texture look-up */ + ir_txb, /**< Texture look-up with LOD bias */ + ir_txl, /**< Texture look-up with explicit LOD */ + ir_txd, /**< Texture look-up with partial derivatvies */ + ir_txf /**< Texel fetch with explicit LOD */ +}; + + +/** + * IR instruction to sample a texture + * + * The specific form of the IR instruction depends on the \c mode value + * selected from \c ir_texture_opcodes. In the printed IR, these will + * appear as: + * + * Texel offset + * | Projection divisor + * | | Shadow comparitor + * | | | + * v v v + * (tex (sampler) (coordinate) (0 0 0) (1) ( )) + * (txb (sampler) (coordinate) (0 0 0) (1) ( ) (bias)) + * (txl (sampler) (coordinate) (0 0 0) (1) ( ) (lod)) + * (txd (sampler) (coordinate) (0 0 0) (1) ( ) (dPdx dPdy)) + * (txf (sampler) (coordinate) (0 0 0) (lod)) + */ +class ir_texture : public ir_rvalue { +public: + ir_texture(enum ir_texture_opcode op) + : op(op), projector(NULL), shadow_comparitor(NULL) + { + this->ir_type = ir_type_texture; + } + + virtual ir_texture *clone(void *mem_ctx, struct hash_table *) const; + + virtual ir_constant *constant_expression_value(); + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + /** + * Return a string representing the ir_texture_opcode. + */ + const char *opcode_string(); + + /** Set the sampler and infer the type. */ + void set_sampler(ir_dereference *sampler); + + /** + * Do a reverse-lookup to translate a string into an ir_texture_opcode. + */ + static ir_texture_opcode get_opcode(const char *); + + enum ir_texture_opcode op; + + /** Sampler to use for the texture access. */ + ir_dereference *sampler; + + /** Texture coordinate to sample */ + ir_rvalue *coordinate; + + /** + * Value used for projective divide. + * + * If there is no projective divide (the common case), this will be + * \c NULL. Optimization passes should check for this to point to a constant + * of 1.0 and replace that with \c NULL. + */ + ir_rvalue *projector; + + /** + * Coordinate used for comparison on shadow look-ups. + * + * If there is no shadow comparison, this will be \c NULL. For the + * \c ir_txf opcode, this *must* be \c NULL. + */ + ir_rvalue *shadow_comparitor; + + /** Explicit texel offsets. */ + signed char offsets[3]; + + union { + ir_rvalue *lod; /**< Floating point LOD */ + ir_rvalue *bias; /**< Floating point LOD bias */ + struct { + ir_rvalue *dPdx; /**< Partial derivative of coordinate wrt X */ + ir_rvalue *dPdy; /**< Partial derivative of coordinate wrt Y */ + } grad; + } lod_info; +}; + + +struct ir_swizzle_mask { + unsigned x:2; + unsigned y:2; + unsigned z:2; + unsigned w:2; + + /** + * Number of components in the swizzle. + */ + unsigned num_components:3; + + /** + * Does the swizzle contain duplicate components? + * + * L-value swizzles cannot contain duplicate components. + */ + unsigned has_duplicates:1; +}; + + +class ir_swizzle : public ir_rvalue { +public: + ir_swizzle(ir_rvalue *, unsigned x, unsigned y, unsigned z, unsigned w, + unsigned count); + + ir_swizzle(ir_rvalue *val, const unsigned *components, unsigned count); + + ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask); + + virtual ir_swizzle *clone(void *mem_ctx, struct hash_table *) const; + + virtual ir_constant *constant_expression_value(); + + virtual ir_swizzle *as_swizzle() + { + return this; + } + + /** + * Construct an ir_swizzle from the textual representation. Can fail. + */ + static ir_swizzle *create(ir_rvalue *, const char *, unsigned vector_length); + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + bool is_lvalue() + { + return val->is_lvalue() && !mask.has_duplicates; + } + + /** + * Get the variable that is ultimately referenced by an r-value + */ + virtual ir_variable *variable_referenced(); + + ir_rvalue *val; + ir_swizzle_mask mask; + +private: + /** + * Initialize the mask component of a swizzle + * + * This is used by the \c ir_swizzle constructors. + */ + void init_mask(const unsigned *components, unsigned count); +}; + + +class ir_dereference : public ir_rvalue { +public: + virtual ir_dereference *clone(void *mem_ctx, struct hash_table *) const = 0; + + virtual ir_dereference *as_dereference() + { + return this; + } + + bool is_lvalue(); + + /** + * Get the variable that is ultimately referenced by an r-value + */ + virtual ir_variable *variable_referenced() = 0; +}; + + +class ir_dereference_variable : public ir_dereference { +public: + ir_dereference_variable(ir_variable *var); + + virtual ir_dereference_variable *clone(void *mem_ctx, + struct hash_table *) const; + + virtual ir_constant *constant_expression_value(); + + virtual ir_dereference_variable *as_dereference_variable() + { + return this; + } + + /** + * Get the variable that is ultimately referenced by an r-value + */ + virtual ir_variable *variable_referenced() + { + return this->var; + } + + virtual ir_variable *whole_variable_referenced() + { + /* ir_dereference_variable objects always dereference the entire + * variable. However, if this dereference is dereferenced by anything + * else, the complete deferefernce chain is not a whole-variable + * dereference. This method should only be called on the top most + * ir_rvalue in a dereference chain. + */ + return this->var; + } + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + /** + * Object being dereferenced. + */ + ir_variable *var; +}; + + +class ir_dereference_array : public ir_dereference { +public: + ir_dereference_array(ir_rvalue *value, ir_rvalue *array_index); + + ir_dereference_array(ir_variable *var, ir_rvalue *array_index); + + virtual ir_dereference_array *clone(void *mem_ctx, + struct hash_table *) const; + + virtual ir_constant *constant_expression_value(); + + virtual ir_dereference_array *as_dereference_array() + { + return this; + } + + /** + * Get the variable that is ultimately referenced by an r-value + */ + virtual ir_variable *variable_referenced() + { + return this->array->variable_referenced(); + } + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + ir_rvalue *array; + ir_rvalue *array_index; + +private: + void set_array(ir_rvalue *value); +}; + + +class ir_dereference_record : public ir_dereference { +public: + ir_dereference_record(ir_rvalue *value, const char *field); + + ir_dereference_record(ir_variable *var, const char *field); + + virtual ir_dereference_record *clone(void *mem_ctx, + struct hash_table *) const; + + virtual ir_constant *constant_expression_value(); + + /** + * Get the variable that is ultimately referenced by an r-value + */ + virtual ir_variable *variable_referenced() + { + return this->record->variable_referenced(); + } + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + ir_rvalue *record; + const char *field; +}; + + +/** + * Data stored in an ir_constant + */ +union ir_constant_data { + unsigned u[16]; + int i[16]; + float f[16]; + bool b[16]; +}; + + +class ir_constant : public ir_rvalue { +public: + ir_constant(const struct glsl_type *type, const ir_constant_data *data); + ir_constant(bool b); + ir_constant(unsigned int u); + ir_constant(int i); + ir_constant(float f); + + /** + * Construct an ir_constant from a list of ir_constant values + */ + ir_constant(const struct glsl_type *type, exec_list *values); + + /** + * Construct an ir_constant from a scalar component of another ir_constant + * + * The new \c ir_constant inherits the type of the component from the + * source constant. + * + * \note + * In the case of a matrix constant, the new constant is a scalar, \b not + * a vector. + */ + ir_constant(const ir_constant *c, unsigned i); + + /** + * Return a new ir_constant of the specified type containing all zeros. + */ + static ir_constant *zero(void *mem_ctx, const glsl_type *type); + + virtual ir_constant *clone(void *mem_ctx, struct hash_table *) const; + + virtual ir_constant *constant_expression_value(); + + virtual ir_constant *as_constant() + { + return this; + } + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + /** + * Get a particular component of a constant as a specific type + * + * This is useful, for example, to get a value from an integer constant + * as a float or bool. This appears frequently when constructors are + * called with all constant parameters. + */ + /*@{*/ + bool get_bool_component(unsigned i) const; + float get_float_component(unsigned i) const; + int get_int_component(unsigned i) const; + unsigned get_uint_component(unsigned i) const; + /*@}*/ + + ir_constant *get_array_element(unsigned i) const; + + ir_constant *get_record_field(const char *name); + + /** + * Determine whether a constant has the same value as another constant + * + * \sa ir_constant::is_zero, ir_constant::is_one, + * ir_constant::is_negative_one + */ + bool has_value(const ir_constant *) const; + + virtual bool is_zero() const; + virtual bool is_one() const; + virtual bool is_negative_one() const; + + /** + * Value of the constant. + * + * The field used to back the values supplied by the constant is determined + * by the type associated with the \c ir_instruction. Constants may be + * scalars, vectors, or matrices. + */ + union ir_constant_data value; + + /* Array elements */ + ir_constant **array_elements; + + /* Structure fields */ + exec_list components; + +private: + /** + * Parameterless constructor only used by the clone method + */ + ir_constant(void); +}; + +/*@}*/ + +/** + * Apply a visitor to each IR node in a list + */ +void +visit_exec_list(exec_list *list, ir_visitor *visitor); + +/** + * Validate invariants on each IR node in a list + */ +void validate_ir_tree(exec_list *instructions); + +/** + * Make a clone of each IR instruction in a list + * + * \param in List of IR instructions that are to be cloned + * \param out List to hold the cloned instructions + */ +void +clone_ir_list(void *mem_ctx, exec_list *out, const exec_list *in); + +extern void +_mesa_glsl_initialize_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + +extern void +_mesa_glsl_initialize_functions(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + +extern void +_mesa_glsl_release_functions(void); + +extern void +reparent_ir(exec_list *list, void *mem_ctx); + +struct glsl_symbol_table; + +extern void +import_prototypes(const exec_list *source, exec_list *dest, + struct glsl_symbol_table *symbols, void *mem_ctx); + +extern bool +ir_has_call(ir_instruction *ir); + +extern void +do_set_program_inouts(exec_list *instructions, struct gl_program *prog); + +#endif /* IR_H */ diff --git a/src/glsl/ir_basic_block.cpp b/src/glsl/ir_basic_block.cpp new file mode 100644 index 0000000..a833825 --- /dev/null +++ b/src/glsl/ir_basic_block.cpp @@ -0,0 +1,149 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_basic_block.cpp + * + * Basic block analysis of instruction streams. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_basic_block.h" +#include "glsl_types.h" + +class ir_has_call_visitor : public ir_hierarchical_visitor { +public: + ir_has_call_visitor() + { + has_call = false; + } + + virtual ir_visitor_status visit_enter(ir_call *ir) + { + (void) ir; + has_call = true; + return visit_stop; + } + + bool has_call; +}; + +bool +ir_has_call(ir_instruction *ir) +{ + ir_has_call_visitor v; + ir->accept(&v); + return v.has_call; +} + +/** + * Calls a user function for every basic block in the instruction stream. + * + * Basic block analysis is pretty easy in our IR thanks to the lack of + * unstructured control flow. We've got: + * + * ir_loop (for () {}, while () {}, do {} while ()) + * ir_loop_jump ( + * ir_if () {} + * ir_return + * ir_call() + * + * Note that the basic blocks returned by this don't encompass all + * operations performed by the program -- for example, if conditions + * don't get returned, nor do the assignments that will be generated + * for ir_call parameters. + */ +void call_for_basic_blocks(exec_list *instructions, + void (*callback)(ir_instruction *first, + ir_instruction *last, + void *data), + void *data) +{ + ir_instruction *leader = NULL; + ir_instruction *last = NULL; + + foreach_iter(exec_list_iterator, iter, *instructions) { + ir_instruction *ir = (ir_instruction *)iter.get(); + ir_if *ir_if; + ir_loop *ir_loop; + ir_function *ir_function; + + if (!leader) + leader = ir; + + if ((ir_if = ir->as_if())) { + callback(leader, ir, data); + leader = NULL; + + call_for_basic_blocks(&ir_if->then_instructions, callback, data); + call_for_basic_blocks(&ir_if->else_instructions, callback, data); + } else if ((ir_loop = ir->as_loop())) { + callback(leader, ir, data); + leader = NULL; + call_for_basic_blocks(&ir_loop->body_instructions, callback, data); + } else if (ir->as_return() || ir->as_call()) { + callback(leader, ir, data); + leader = NULL; + } else if ((ir_function = ir->as_function())) { + /* A function definition doesn't interrupt our basic block + * since execution doesn't go into it. We should process the + * bodies of its signatures for BBs, though. + * + * Note that we miss an opportunity for producing more + * maximal BBs between the instructions that precede main() + * and the body of main(). Perhaps those instructions ought + * to live inside of main(). + */ + foreach_iter(exec_list_iterator, fun_iter, *ir_function) { + ir_function_signature *ir_sig; + + ir_sig = (ir_function_signature *)fun_iter.get(); + + call_for_basic_blocks(&ir_sig->body, callback, data); + } + } else if (ir->as_assignment()) { + /* If there's a call in the expression tree being assigned, + * then that ends the BB too. + * + * The assumption is that any consumer of the basic block + * walker is fine with the fact that the call is somewhere in + * the tree even if portions of the tree may be evaluated + * after the call. + * + * A consumer that has an issue with this could not process + * the last instruction of the basic block. If doing so, + * expression flattener may be useful before using the basic + * block finder to get more maximal basic blocks out. + */ + if (ir_has_call(ir)) { + callback(leader, ir, data); + leader = NULL; + } + } + last = ir; + } + if (leader) { + callback(leader, last, data); + } +} diff --git a/src/glsl/ir_basic_block.h b/src/glsl/ir_basic_block.h new file mode 100644 index 0000000..dbd678b --- /dev/null +++ b/src/glsl/ir_basic_block.h @@ -0,0 +1,28 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +void call_for_basic_blocks(exec_list *instructions, + void (*callback)(ir_instruction *first, + ir_instruction *last, + void *data), + void *data); diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp new file mode 100644 index 0000000..20a59b1 --- /dev/null +++ b/src/glsl/ir_clone.cpp @@ -0,0 +1,420 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include "main/compiler.h" +#include "ir.h" +#include "glsl_types.h" +extern "C" { +#include "program/hash_table.h" +} + +/** + * Duplicate an IR variable + * + * \note + * This will probably be made \c virtual and moved to the base class + * eventually. + */ +ir_variable * +ir_variable::clone(void *mem_ctx, struct hash_table *ht) const +{ + ir_variable *var = new(mem_ctx) ir_variable(this->type, this->name, + (ir_variable_mode) this->mode); + + var->max_array_access = this->max_array_access; + var->read_only = this->read_only; + var->centroid = this->centroid; + var->invariant = this->invariant; + var->interpolation = this->interpolation; + var->array_lvalue = this->array_lvalue; + var->location = this->location; + var->warn_extension = this->warn_extension; + var->origin_upper_left = this->origin_upper_left; + var->pixel_center_integer = this->pixel_center_integer; + var->explicit_location = this->explicit_location; + if (this->explicit_location) + var->location = this->location; + + if (this->constant_value) + var->constant_value = this->constant_value->clone(mem_ctx, ht); + + if (ht) { + hash_table_insert(ht, var, (void *)const_cast(this)); + } + + return var; +} + +ir_swizzle * +ir_swizzle::clone(void *mem_ctx, struct hash_table *ht) const +{ + return new(mem_ctx) ir_swizzle(this->val->clone(mem_ctx, ht), this->mask); +} + +ir_return * +ir_return::clone(void *mem_ctx, struct hash_table *ht) const +{ + ir_rvalue *new_value = NULL; + + if (this->value) + new_value = this->value->clone(mem_ctx, ht); + + return new(mem_ctx) ir_return(new_value); +} + +ir_discard * +ir_discard::clone(void *mem_ctx, struct hash_table *ht) const +{ + ir_rvalue *new_condition = NULL; + + if (this->condition != NULL) + new_condition = this->condition->clone(mem_ctx, ht); + + return new(mem_ctx) ir_discard(new_condition); +} + +ir_loop_jump * +ir_loop_jump::clone(void *mem_ctx, struct hash_table *ht) const +{ + (void)ht; + + return new(mem_ctx) ir_loop_jump(this->mode); +} + +ir_if * +ir_if::clone(void *mem_ctx, struct hash_table *ht) const +{ + ir_if *new_if = new(mem_ctx) ir_if(this->condition->clone(mem_ctx, ht)); + + foreach_iter(exec_list_iterator, iter, this->then_instructions) { + ir_instruction *ir = (ir_instruction *)iter.get(); + new_if->then_instructions.push_tail(ir->clone(mem_ctx, ht)); + } + + foreach_iter(exec_list_iterator, iter, this->else_instructions) { + ir_instruction *ir = (ir_instruction *)iter.get(); + new_if->else_instructions.push_tail(ir->clone(mem_ctx, ht)); + } + + return new_if; +} + +ir_loop * +ir_loop::clone(void *mem_ctx, struct hash_table *ht) const +{ + ir_loop *new_loop = new(mem_ctx) ir_loop(); + + if (this->from) + new_loop->from = this->from->clone(mem_ctx, ht); + if (this->to) + new_loop->to = this->to->clone(mem_ctx, ht); + if (this->increment) + new_loop->increment = this->increment->clone(mem_ctx, ht); + new_loop->counter = counter; + + foreach_iter(exec_list_iterator, iter, this->body_instructions) { + ir_instruction *ir = (ir_instruction *)iter.get(); + new_loop->body_instructions.push_tail(ir->clone(mem_ctx, ht)); + } + + new_loop->cmp = this->cmp; + return new_loop; +} + +ir_call * +ir_call::clone(void *mem_ctx, struct hash_table *ht) const +{ + if (this->type == glsl_type::error_type) + return ir_call::get_error_instruction(mem_ctx); + + exec_list new_parameters; + + foreach_iter(exec_list_iterator, iter, this->actual_parameters) { + ir_instruction *ir = (ir_instruction *)iter.get(); + new_parameters.push_tail(ir->clone(mem_ctx, ht)); + } + + return new(mem_ctx) ir_call(this->callee, &new_parameters); +} + +ir_expression * +ir_expression::clone(void *mem_ctx, struct hash_table *ht) const +{ + ir_rvalue *op[Elements(this->operands)] = { NULL, }; + unsigned int i; + + for (i = 0; i < get_num_operands(); i++) { + op[i] = this->operands[i]->clone(mem_ctx, ht); + } + + return new(mem_ctx) ir_expression(this->operation, this->type, + op[0], op[1], op[2], op[3]); +} + +ir_dereference_variable * +ir_dereference_variable::clone(void *mem_ctx, struct hash_table *ht) const +{ + ir_variable *new_var; + + if (ht) { + new_var = (ir_variable *)hash_table_find(ht, this->var); + if (!new_var) + new_var = this->var; + } else { + new_var = this->var; + } + + return new(mem_ctx) ir_dereference_variable(new_var); +} + +ir_dereference_array * +ir_dereference_array::clone(void *mem_ctx, struct hash_table *ht) const +{ + return new(mem_ctx) ir_dereference_array(this->array->clone(mem_ctx, ht), + this->array_index->clone(mem_ctx, + ht)); +} + +ir_dereference_record * +ir_dereference_record::clone(void *mem_ctx, struct hash_table *ht) const +{ + return new(mem_ctx) ir_dereference_record(this->record->clone(mem_ctx, ht), + this->field); +} + +ir_texture * +ir_texture::clone(void *mem_ctx, struct hash_table *ht) const +{ + ir_texture *new_tex = new(mem_ctx) ir_texture(this->op); + new_tex->type = this->type; + + new_tex->sampler = this->sampler->clone(mem_ctx, ht); + new_tex->coordinate = this->coordinate->clone(mem_ctx, ht); + if (this->projector) + new_tex->projector = this->projector->clone(mem_ctx, ht); + if (this->shadow_comparitor) { + new_tex->shadow_comparitor = this->shadow_comparitor->clone(mem_ctx, ht); + } + + for (int i = 0; i < 3; i++) + new_tex->offsets[i] = this->offsets[i]; + + switch (this->op) { + case ir_tex: + break; + case ir_txb: + new_tex->lod_info.bias = this->lod_info.bias->clone(mem_ctx, ht); + break; + case ir_txl: + case ir_txf: + new_tex->lod_info.lod = this->lod_info.lod->clone(mem_ctx, ht); + break; + case ir_txd: + new_tex->lod_info.grad.dPdx = this->lod_info.grad.dPdx->clone(mem_ctx, ht); + new_tex->lod_info.grad.dPdy = this->lod_info.grad.dPdy->clone(mem_ctx, ht); + break; + } + + return new_tex; +} + +ir_assignment * +ir_assignment::clone(void *mem_ctx, struct hash_table *ht) const +{ + ir_rvalue *new_condition = NULL; + + if (this->condition) + new_condition = this->condition->clone(mem_ctx, ht); + + return new(mem_ctx) ir_assignment(this->lhs->clone(mem_ctx, ht), + this->rhs->clone(mem_ctx, ht), + new_condition, + this->write_mask); +} + +ir_function * +ir_function::clone(void *mem_ctx, struct hash_table *ht) const +{ + ir_function *copy = new(mem_ctx) ir_function(this->name); + + foreach_list_const(node, &this->signatures) { + const ir_function_signature *const sig = + (const ir_function_signature *const) node; + + ir_function_signature *sig_copy = sig->clone(mem_ctx, ht); + copy->add_signature(sig_copy); + + if (ht != NULL) + hash_table_insert(ht, sig_copy, + (void *)const_cast(sig)); + } + + return copy; +} + +ir_function_signature * +ir_function_signature::clone(void *mem_ctx, struct hash_table *ht) const +{ + ir_function_signature *copy = this->clone_prototype(mem_ctx, ht); + + copy->is_defined = this->is_defined; + + /* Clone the instruction list. + */ + foreach_list_const(node, &this->body) { + const ir_instruction *const inst = (const ir_instruction *) node; + + ir_instruction *const inst_copy = inst->clone(mem_ctx, ht); + copy->body.push_tail(inst_copy); + } + + return copy; +} + +ir_function_signature * +ir_function_signature::clone_prototype(void *mem_ctx, struct hash_table *ht) const +{ + ir_function_signature *copy = + new(mem_ctx) ir_function_signature(this->return_type); + + copy->is_defined = false; + copy->is_builtin = this->is_builtin; + + /* Clone the parameter list, but NOT the body. + */ + foreach_list_const(node, &this->parameters) { + const ir_variable *const param = (const ir_variable *) node; + + assert(const_cast(param)->as_variable() != NULL); + + ir_variable *const param_copy = param->clone(mem_ctx, ht); + copy->parameters.push_tail(param_copy); + } + + return copy; +} + +ir_constant * +ir_constant::clone(void *mem_ctx, struct hash_table *ht) const +{ + (void)ht; + + switch (this->type->base_type) { + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: + case GLSL_TYPE_FLOAT: + case GLSL_TYPE_BOOL: + return new(mem_ctx) ir_constant(this->type, &this->value); + + case GLSL_TYPE_STRUCT: { + ir_constant *c = new(mem_ctx) ir_constant; + + c->type = this->type; + for (exec_node *node = this->components.head + ; !node->is_tail_sentinel() + ; node = node->next) { + ir_constant *const orig = (ir_constant *) node; + + c->components.push_tail(orig->clone(mem_ctx, NULL)); + } + + return c; + } + + case GLSL_TYPE_ARRAY: { + ir_constant *c = new(mem_ctx) ir_constant; + + c->type = this->type; + c->array_elements = ralloc_array(c, ir_constant *, this->type->length); + for (unsigned i = 0; i < this->type->length; i++) { + c->array_elements[i] = this->array_elements[i]->clone(mem_ctx, NULL); + } + return c; + } + + default: + assert(!"Should not get here."); + return NULL; + } +} + + +class fixup_ir_call_visitor : public ir_hierarchical_visitor { +public: + fixup_ir_call_visitor(struct hash_table *ht) + { + this->ht = ht; + } + + virtual ir_visitor_status visit_enter(ir_call *ir) + { + /* Try to find the function signature referenced by the ir_call in the + * table. If it is found, replace it with the value from the table. + */ + ir_function_signature *sig = + (ir_function_signature *) hash_table_find(this->ht, ir->get_callee()); + if (sig != NULL) + ir->set_callee(sig); + + /* Since this may be used before function call parameters are flattened, + * the children also need to be processed. + */ + return visit_continue; + } + +private: + struct hash_table *ht; +}; + + +static void +fixup_function_calls(struct hash_table *ht, exec_list *instructions) +{ + fixup_ir_call_visitor v(ht); + v.run(instructions); +} + + +void +clone_ir_list(void *mem_ctx, exec_list *out, const exec_list *in) +{ + struct hash_table *ht = + hash_table_ctor(0, hash_table_pointer_hash, hash_table_pointer_compare); + + foreach_list_const(node, in) { + const ir_instruction *const original = (ir_instruction *) node; + ir_instruction *copy = original->clone(mem_ctx, ht); + + out->push_tail(copy); + } + + /* Make a pass over the cloned tree to fix up ir_call nodes to point to the + * cloned ir_function_signature nodes. This cannot be done automatically + * during cloning because the ir_call might be a forward reference (i.e., + * the function signature that it references may not have been cloned yet). + */ + fixup_function_calls(ht, out); + + hash_table_dtor(ht); +} diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp new file mode 100644 index 0000000..b5850be --- /dev/null +++ b/src/glsl/ir_constant_expression.cpp @@ -0,0 +1,1370 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_constant_expression.cpp + * Evaluate and process constant valued expressions + * + * In GLSL, constant valued expressions are used in several places. These + * must be processed and evaluated very early in the compilation process. + * + * * Sizes of arrays + * * Initializers for uniforms + * * Initializers for \c const variables + */ + +#include +#include "main/core.h" /* for MAX2, MIN2, CLAMP */ +#include "ir.h" +#include "ir_visitor.h" +#include "glsl_types.h" + +static float +dot(ir_constant *op0, ir_constant *op1) +{ + assert(op0->type->is_float() && op1->type->is_float()); + + float result = 0; + for (unsigned c = 0; c < op0->type->components(); c++) + result += op0->value.f[c] * op1->value.f[c]; + + return result; +} + +ir_constant * +ir_expression::constant_expression_value() +{ + if (this->type->is_error()) + return NULL; + + ir_constant *op[Elements(this->operands)] = { NULL, }; + ir_constant_data data; + + memset(&data, 0, sizeof(data)); + + for (unsigned operand = 0; operand < this->get_num_operands(); operand++) { + op[operand] = this->operands[operand]->constant_expression_value(); + if (!op[operand]) + return NULL; + } + + if (op[1] != NULL) + assert(op[0]->type->base_type == op[1]->type->base_type); + + bool op0_scalar = op[0]->type->is_scalar(); + bool op1_scalar = op[1] != NULL && op[1]->type->is_scalar(); + + /* When iterating over a vector or matrix's components, we want to increase + * the loop counter. However, for scalars, we want to stay at 0. + */ + unsigned c0_inc = op0_scalar ? 0 : 1; + unsigned c1_inc = op1_scalar ? 0 : 1; + unsigned components; + if (op1_scalar || !op[1]) { + components = op[0]->type->components(); + } else { + components = op[1]->type->components(); + } + + void *ctx = ralloc_parent(this); + + /* Handle array operations here, rather than below. */ + if (op[0]->type->is_array()) { + assert(op[1] != NULL && op[1]->type->is_array()); + switch (this->operation) { + case ir_binop_all_equal: + return new(ctx) ir_constant(op[0]->has_value(op[1])); + case ir_binop_any_nequal: + return new(ctx) ir_constant(!op[0]->has_value(op[1])); + default: + break; + } + return NULL; + } + + switch (this->operation) { + case ir_unop_bit_not: + switch (op[0]->type->base_type) { + case GLSL_TYPE_INT: + for (unsigned c = 0; c < components; c++) + data.i[c] = ~ op[0]->value.i[c]; + break; + case GLSL_TYPE_UINT: + for (unsigned c = 0; c < components; c++) + data.u[c] = ~ op[0]->value.u[c]; + break; + default: + assert(0); + } + break; + + case ir_unop_logic_not: + assert(op[0]->type->base_type == GLSL_TYPE_BOOL); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.b[c] = !op[0]->value.b[c]; + break; + + case ir_unop_f2i: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.i[c] = (int) op[0]->value.f[c]; + } + break; + case ir_unop_i2f: + assert(op[0]->type->base_type == GLSL_TYPE_INT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = (float) op[0]->value.i[c]; + } + break; + case ir_unop_u2f: + assert(op[0]->type->base_type == GLSL_TYPE_UINT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = (float) op[0]->value.u[c]; + } + break; + case ir_unop_b2f: + assert(op[0]->type->base_type == GLSL_TYPE_BOOL); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = op[0]->value.b[c] ? 1.0F : 0.0F; + } + break; + case ir_unop_f2b: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.b[c] = op[0]->value.f[c] != 0.0F ? true : false; + } + break; + case ir_unop_b2i: + assert(op[0]->type->base_type == GLSL_TYPE_BOOL); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.u[c] = op[0]->value.b[c] ? 1 : 0; + } + break; + case ir_unop_i2b: + assert(op[0]->type->is_integer()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.b[c] = op[0]->value.u[c] ? true : false; + } + break; + + case ir_unop_any: + assert(op[0]->type->is_boolean()); + data.b[0] = false; + for (unsigned c = 0; c < op[0]->type->components(); c++) { + if (op[0]->value.b[c]) + data.b[0] = true; + } + break; + + case ir_unop_trunc: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = truncf(op[0]->value.f[c]); + } + break; + + case ir_unop_ceil: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = ceilf(op[0]->value.f[c]); + } + break; + + case ir_unop_floor: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = floorf(op[0]->value.f[c]); + } + break; + + case ir_unop_fract: + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (this->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = 0; + break; + case GLSL_TYPE_INT: + data.i[c] = 0; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = op[0]->value.f[c] - floor(op[0]->value.f[c]); + break; + default: + assert(0); + } + } + break; + + case ir_unop_sin: + case ir_unop_sin_reduced: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = sinf(op[0]->value.f[c]); + } + break; + + case ir_unop_cos: + case ir_unop_cos_reduced: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = cosf(op[0]->value.f[c]); + } + break; + + case ir_unop_neg: + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (this->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = -((int) op[0]->value.u[c]); + break; + case GLSL_TYPE_INT: + data.i[c] = -op[0]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = -op[0]->value.f[c]; + break; + default: + assert(0); + } + } + break; + + case ir_unop_abs: + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (this->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c]; + if (data.i[c] < 0) + data.i[c] = -data.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = fabs(op[0]->value.f[c]); + break; + default: + assert(0); + } + } + break; + + case ir_unop_sign: + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (this->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.i[c] > 0; + break; + case GLSL_TYPE_INT: + data.i[c] = (op[0]->value.i[c] > 0) - (op[0]->value.i[c] < 0); + break; + case GLSL_TYPE_FLOAT: + data.f[c] = float((op[0]->value.f[c] > 0)-(op[0]->value.f[c] < 0)); + break; + default: + assert(0); + } + } + break; + + case ir_unop_rcp: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (this->type->base_type) { + case GLSL_TYPE_UINT: + if (op[0]->value.u[c] != 0.0) + data.u[c] = 1 / op[0]->value.u[c]; + break; + case GLSL_TYPE_INT: + if (op[0]->value.i[c] != 0.0) + data.i[c] = 1 / op[0]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + if (op[0]->value.f[c] != 0.0) + data.f[c] = 1.0F / op[0]->value.f[c]; + break; + default: + assert(0); + } + } + break; + + case ir_unop_rsq: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = 1.0F / sqrtf(op[0]->value.f[c]); + } + break; + + case ir_unop_sqrt: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = sqrtf(op[0]->value.f[c]); + } + break; + + case ir_unop_exp: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = expf(op[0]->value.f[c]); + } + break; + + case ir_unop_exp2: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = exp2f(op[0]->value.f[c]); + } + break; + + case ir_unop_log: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = logf(op[0]->value.f[c]); + } + break; + + case ir_unop_log2: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = log2f(op[0]->value.f[c]); + } + break; + + case ir_unop_dFdx: + case ir_unop_dFdy: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = 0.0; + } + break; + + case ir_binop_pow: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = powf(op[0]->value.f[c], op[1]->value.f[c]); + } + break; + + case ir_binop_dot: + data.f[0] = dot(op[0], op[1]); + break; + + case ir_binop_min: + assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = MIN2(op[0]->value.u[c0], op[1]->value.u[c1]); + break; + case GLSL_TYPE_INT: + data.i[c] = MIN2(op[0]->value.i[c0], op[1]->value.i[c1]); + break; + case GLSL_TYPE_FLOAT: + data.f[c] = MIN2(op[0]->value.f[c0], op[1]->value.f[c1]); + break; + default: + assert(0); + } + } + + break; + case ir_binop_max: + assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = MAX2(op[0]->value.u[c0], op[1]->value.u[c1]); + break; + case GLSL_TYPE_INT: + data.i[c] = MAX2(op[0]->value.i[c0], op[1]->value.i[c1]); + break; + case GLSL_TYPE_FLOAT: + data.f[c] = MAX2(op[0]->value.f[c0], op[1]->value.f[c1]); + break; + default: + assert(0); + } + } + break; + + case ir_binop_add: + assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c0] + op[1]->value.u[c1]; + break; + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c0] + op[1]->value.i[c1]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = op[0]->value.f[c0] + op[1]->value.f[c1]; + break; + default: + assert(0); + } + } + + break; + case ir_binop_sub: + assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c0] - op[1]->value.u[c1]; + break; + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c0] - op[1]->value.i[c1]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = op[0]->value.f[c0] - op[1]->value.f[c1]; + break; + default: + assert(0); + } + } + + break; + case ir_binop_mul: + /* Check for equal types, or unequal types involving scalars */ + if ((op[0]->type == op[1]->type && !op[0]->type->is_matrix()) + || op0_scalar || op1_scalar) { + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c0] * op[1]->value.u[c1]; + break; + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c0] * op[1]->value.i[c1]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = op[0]->value.f[c0] * op[1]->value.f[c1]; + break; + default: + assert(0); + } + } + } else { + assert(op[0]->type->is_matrix() || op[1]->type->is_matrix()); + + /* Multiply an N-by-M matrix with an M-by-P matrix. Since either + * matrix can be a GLSL vector, either N or P can be 1. + * + * For vec*mat, the vector is treated as a row vector. This + * means the vector is a 1-row x M-column matrix. + * + * For mat*vec, the vector is treated as a column vector. Since + * matrix_columns is 1 for vectors, this just works. + */ + const unsigned n = op[0]->type->is_vector() + ? 1 : op[0]->type->vector_elements; + const unsigned m = op[1]->type->vector_elements; + const unsigned p = op[1]->type->matrix_columns; + for (unsigned j = 0; j < p; j++) { + for (unsigned i = 0; i < n; i++) { + for (unsigned k = 0; k < m; k++) { + data.f[i+n*j] += op[0]->value.f[i+n*k]*op[1]->value.f[k+m*j]; + } + } + } + } + + break; + case ir_binop_div: + assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + if (op[1]->value.u[c1] == 0) { + data.u[c] = 0; + } else { + data.u[c] = op[0]->value.u[c0] / op[1]->value.u[c1]; + } + break; + case GLSL_TYPE_INT: + if (op[1]->value.i[c1] == 0) { + data.i[c] = 0; + } else { + data.i[c] = op[0]->value.i[c0] / op[1]->value.i[c1]; + } + break; + case GLSL_TYPE_FLOAT: + data.f[c] = op[0]->value.f[c0] / op[1]->value.f[c1]; + break; + default: + assert(0); + } + } + + break; + case ir_binop_mod: + assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + if (op[1]->value.u[c1] == 0) { + data.u[c] = 0; + } else { + data.u[c] = op[0]->value.u[c0] % op[1]->value.u[c1]; + } + break; + case GLSL_TYPE_INT: + if (op[1]->value.i[c1] == 0) { + data.i[c] = 0; + } else { + data.i[c] = op[0]->value.i[c0] % op[1]->value.i[c1]; + } + break; + case GLSL_TYPE_FLOAT: + /* We don't use fmod because it rounds toward zero; GLSL specifies + * the use of floor. + */ + data.f[c] = op[0]->value.f[c0] - op[1]->value.f[c1] + * floorf(op[0]->value.f[c0] / op[1]->value.f[c1]); + break; + default: + assert(0); + } + } + + break; + + case ir_binop_logic_and: + assert(op[0]->type->base_type == GLSL_TYPE_BOOL); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.b[c] = op[0]->value.b[c] && op[1]->value.b[c]; + break; + case ir_binop_logic_xor: + assert(op[0]->type->base_type == GLSL_TYPE_BOOL); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.b[c] = op[0]->value.b[c] ^ op[1]->value.b[c]; + break; + case ir_binop_logic_or: + assert(op[0]->type->base_type == GLSL_TYPE_BOOL); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.b[c] = op[0]->value.b[c] || op[1]->value.b[c]; + break; + + case ir_binop_less: + assert(op[0]->type == op[1]->type); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[0] = op[0]->value.u[0] < op[1]->value.u[0]; + break; + case GLSL_TYPE_INT: + data.b[0] = op[0]->value.i[0] < op[1]->value.i[0]; + break; + case GLSL_TYPE_FLOAT: + data.b[0] = op[0]->value.f[0] < op[1]->value.f[0]; + break; + default: + assert(0); + } + } + break; + case ir_binop_greater: + assert(op[0]->type == op[1]->type); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] > op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] > op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] > op[1]->value.f[c]; + break; + default: + assert(0); + } + } + break; + case ir_binop_lequal: + assert(op[0]->type == op[1]->type); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[0] = op[0]->value.u[0] <= op[1]->value.u[0]; + break; + case GLSL_TYPE_INT: + data.b[0] = op[0]->value.i[0] <= op[1]->value.i[0]; + break; + case GLSL_TYPE_FLOAT: + data.b[0] = op[0]->value.f[0] <= op[1]->value.f[0]; + break; + default: + assert(0); + } + } + break; + case ir_binop_gequal: + assert(op[0]->type == op[1]->type); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[0] = op[0]->value.u[0] >= op[1]->value.u[0]; + break; + case GLSL_TYPE_INT: + data.b[0] = op[0]->value.i[0] >= op[1]->value.i[0]; + break; + case GLSL_TYPE_FLOAT: + data.b[0] = op[0]->value.f[0] >= op[1]->value.f[0]; + break; + default: + assert(0); + } + } + break; + case ir_binop_equal: + assert(op[0]->type == op[1]->type); + for (unsigned c = 0; c < components; c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] == op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] == op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] == op[1]->value.f[c]; + break; + default: + assert(0); + } + } + break; + case ir_binop_nequal: + assert(op[0]->type != op[1]->type); + for (unsigned c = 0; c < components; c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] != op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] != op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] != op[1]->value.f[c]; + break; + default: + assert(0); + } + } + break; + case ir_binop_all_equal: + data.b[0] = op[0]->has_value(op[1]); + break; + case ir_binop_any_nequal: + data.b[0] = !op[0]->has_value(op[1]); + break; + + case ir_binop_lshift: + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + if (op[0]->type->base_type == GLSL_TYPE_INT && + op[1]->type->base_type == GLSL_TYPE_INT) { + data.i[c] = op[0]->value.i[c0] << op[1]->value.i[c1]; + + } else if (op[0]->type->base_type == GLSL_TYPE_INT && + op[1]->type->base_type == GLSL_TYPE_UINT) { + data.i[c] = op[0]->value.i[c0] << op[1]->value.u[c1]; + + } else if (op[0]->type->base_type == GLSL_TYPE_UINT && + op[1]->type->base_type == GLSL_TYPE_INT) { + data.u[c] = op[0]->value.u[c0] << op[1]->value.i[c1]; + + } else if (op[0]->type->base_type == GLSL_TYPE_UINT && + op[1]->type->base_type == GLSL_TYPE_UINT) { + data.u[c] = op[0]->value.u[c0] << op[1]->value.u[c1]; + } + } + break; + + case ir_binop_rshift: + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + if (op[0]->type->base_type == GLSL_TYPE_INT && + op[1]->type->base_type == GLSL_TYPE_INT) { + data.i[c] = op[0]->value.i[c0] >> op[1]->value.i[c1]; + + } else if (op[0]->type->base_type == GLSL_TYPE_INT && + op[1]->type->base_type == GLSL_TYPE_UINT) { + data.i[c] = op[0]->value.i[c0] >> op[1]->value.u[c1]; + + } else if (op[0]->type->base_type == GLSL_TYPE_UINT && + op[1]->type->base_type == GLSL_TYPE_INT) { + data.u[c] = op[0]->value.u[c0] >> op[1]->value.i[c1]; + + } else if (op[0]->type->base_type == GLSL_TYPE_UINT && + op[1]->type->base_type == GLSL_TYPE_UINT) { + data.u[c] = op[0]->value.u[c0] >> op[1]->value.u[c1]; + } + } + break; + + case ir_binop_bit_and: + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (op[0]->type->base_type) { + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c0] & op[1]->value.i[c1]; + break; + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c0] & op[1]->value.u[c1]; + break; + default: + assert(0); + } + } + break; + + case ir_binop_bit_or: + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (op[0]->type->base_type) { + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c0] | op[1]->value.i[c1]; + break; + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c0] | op[1]->value.u[c1]; + break; + default: + assert(0); + } + } + break; + + case ir_binop_bit_xor: + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (op[0]->type->base_type) { + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c0] ^ op[1]->value.i[c1]; + break; + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c0] ^ op[1]->value.u[c1]; + break; + default: + assert(0); + } + } + break; + + case ir_quadop_vector: + for (unsigned c = 0; c < this->type->vector_elements; c++) { + switch (this->type->base_type) { + case GLSL_TYPE_INT: + data.i[c] = op[c]->value.i[0]; + break; + case GLSL_TYPE_UINT: + data.u[c] = op[c]->value.u[0]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = op[c]->value.f[0]; + break; + default: + assert(0); + } + } + break; + + default: + /* FINISHME: Should handle all expression types. */ + return NULL; + } + + return new(ctx) ir_constant(this->type, &data); +} + + +ir_constant * +ir_texture::constant_expression_value() +{ + /* texture lookups aren't constant expressions */ + return NULL; +} + + +ir_constant * +ir_swizzle::constant_expression_value() +{ + ir_constant *v = this->val->constant_expression_value(); + + if (v != NULL) { + ir_constant_data data = { { 0 } }; + + const unsigned swiz_idx[4] = { + this->mask.x, this->mask.y, this->mask.z, this->mask.w + }; + + for (unsigned i = 0; i < this->mask.num_components; i++) { + switch (v->type->base_type) { + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: data.u[i] = v->value.u[swiz_idx[i]]; break; + case GLSL_TYPE_FLOAT: data.f[i] = v->value.f[swiz_idx[i]]; break; + case GLSL_TYPE_BOOL: data.b[i] = v->value.b[swiz_idx[i]]; break; + default: assert(!"Should not get here."); break; + } + } + + void *ctx = ralloc_parent(this); + return new(ctx) ir_constant(this->type, &data); + } + return NULL; +} + + +ir_constant * +ir_dereference_variable::constant_expression_value() +{ + /* This may occur during compile and var->type is glsl_type::error_type */ + if (!var) + return NULL; + + /* The constant_value of a uniform variable is its initializer, + * not the lifetime constant value of the uniform. + */ + if (var->mode == ir_var_uniform) + return NULL; + + if (!var->constant_value) + return NULL; + + return var->constant_value->clone(ralloc_parent(var), NULL); +} + + +ir_constant * +ir_dereference_array::constant_expression_value() +{ + ir_constant *array = this->array->constant_expression_value(); + ir_constant *idx = this->array_index->constant_expression_value(); + + if ((array != NULL) && (idx != NULL)) { + void *ctx = ralloc_parent(this); + if (array->type->is_matrix()) { + /* Array access of a matrix results in a vector. + */ + const unsigned column = idx->value.u[0]; + + const glsl_type *const column_type = array->type->column_type(); + + /* Offset in the constant matrix to the first element of the column + * to be extracted. + */ + const unsigned mat_idx = column * column_type->vector_elements; + + ir_constant_data data = { { 0 } }; + + switch (column_type->base_type) { + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: + for (unsigned i = 0; i < column_type->vector_elements; i++) + data.u[i] = array->value.u[mat_idx + i]; + + break; + + case GLSL_TYPE_FLOAT: + for (unsigned i = 0; i < column_type->vector_elements; i++) + data.f[i] = array->value.f[mat_idx + i]; + + break; + + default: + assert(!"Should not get here."); + break; + } + + return new(ctx) ir_constant(column_type, &data); + } else if (array->type->is_vector()) { + const unsigned component = idx->value.u[0]; + + return new(ctx) ir_constant(array, component); + } else { + const unsigned index = idx->value.u[0]; + return array->get_array_element(index)->clone(ctx, NULL); + } + } + return NULL; +} + + +ir_constant * +ir_dereference_record::constant_expression_value() +{ + ir_constant *v = this->record->constant_expression_value(); + + return (v != NULL) ? v->get_record_field(this->field) : NULL; +} + + +ir_constant * +ir_assignment::constant_expression_value() +{ + /* FINISHME: Handle CEs involving assignment (return RHS) */ + return NULL; +} + + +ir_constant * +ir_constant::constant_expression_value() +{ + return this; +} + + +ir_constant * +ir_call::constant_expression_value() +{ + if (this->type == glsl_type::error_type) + return NULL; + + /* From the GLSL 1.20 spec, page 23: + * "Function calls to user-defined functions (non-built-in functions) + * cannot be used to form constant expressions." + */ + if (!this->callee->is_builtin) + return NULL; + + unsigned num_parameters = 0; + + /* Check if all parameters are constant */ + ir_constant *op[3]; + foreach_list(n, &this->actual_parameters) { + ir_constant *constant = ((ir_rvalue *) n)->constant_expression_value(); + if (constant == NULL) + return NULL; + + op[num_parameters] = constant; + + assert(num_parameters < 3); + num_parameters++; + } + + /* Individual cases below can either: + * - Assign "expr" a new ir_expression to evaluate (for basic opcodes) + * - Fill "data" with appopriate constant data + * - Return an ir_constant directly. + */ + void *mem_ctx = ralloc_parent(this); + ir_expression *expr = NULL; + + ir_constant_data data; + memset(&data, 0, sizeof(data)); + + const char *callee = this->callee_name(); + if (strcmp(callee, "abs") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_abs, type, op[0], NULL); + } else if (strcmp(callee, "all") == 0) { + assert(op[0]->type->is_boolean()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + if (!op[0]->value.b[c]) + return new(mem_ctx) ir_constant(false); + } + return new(mem_ctx) ir_constant(true); + } else if (strcmp(callee, "any") == 0) { + assert(op[0]->type->is_boolean()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + if (op[0]->value.b[c]) + return new(mem_ctx) ir_constant(true); + } + return new(mem_ctx) ir_constant(false); + } else if (strcmp(callee, "acos") == 0) { + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = acosf(op[0]->value.f[c]); + } else if (strcmp(callee, "acosh") == 0) { + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = acoshf(op[0]->value.f[c]); + } else if (strcmp(callee, "asin") == 0) { + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = asinf(op[0]->value.f[c]); + } else if (strcmp(callee, "asinh") == 0) { + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = asinhf(op[0]->value.f[c]); + } else if (strcmp(callee, "atan") == 0) { + assert(op[0]->type->is_float()); + if (num_parameters == 2) { + assert(op[1]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = atan2f(op[0]->value.f[c], op[1]->value.f[c]); + } else { + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = atanf(op[0]->value.f[c]); + } + } else if (strcmp(callee, "atanh") == 0) { + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = atanhf(op[0]->value.f[c]); + } else if (strcmp(callee, "dFdx") == 0 || strcmp(callee, "dFdy") == 0) { + return ir_constant::zero(mem_ctx, this->type); + } else if (strcmp(callee, "ceil") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_ceil, type, op[0], NULL); + } else if (strcmp(callee, "clamp") == 0) { + assert(num_parameters == 3); + unsigned c1_inc = op[1]->type->is_scalar() ? 0 : 1; + unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1; + for (unsigned c = 0, c1 = 0, c2 = 0; + c < op[0]->type->components(); + c1 += c1_inc, c2 += c2_inc, c++) { + + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = CLAMP(op[0]->value.u[c], op[1]->value.u[c1], + op[2]->value.u[c2]); + break; + case GLSL_TYPE_INT: + data.i[c] = CLAMP(op[0]->value.i[c], op[1]->value.i[c1], + op[2]->value.i[c2]); + break; + case GLSL_TYPE_FLOAT: + data.f[c] = CLAMP(op[0]->value.f[c], op[1]->value.f[c1], + op[2]->value.f[c2]); + break; + default: + assert(!"Should not get here."); + } + } + } else if (strcmp(callee, "cos") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_cos, type, op[0], NULL); + } else if (strcmp(callee, "cosh") == 0) { + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = coshf(op[0]->value.f[c]); + } else if (strcmp(callee, "cross") == 0) { + assert(op[0]->type == glsl_type::vec3_type); + assert(op[1]->type == glsl_type::vec3_type); + data.f[0] = (op[0]->value.f[1] * op[1]->value.f[2] - + op[1]->value.f[1] * op[0]->value.f[2]); + data.f[1] = (op[0]->value.f[2] * op[1]->value.f[0] - + op[1]->value.f[2] * op[0]->value.f[0]); + data.f[2] = (op[0]->value.f[0] * op[1]->value.f[1] - + op[1]->value.f[0] * op[0]->value.f[1]); + } else if (strcmp(callee, "degrees") == 0) { + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = 180.0F / M_PI * op[0]->value.f[c]; + } else if (strcmp(callee, "distance") == 0) { + assert(op[0]->type->is_float() && op[1]->type->is_float()); + float length_squared = 0.0; + for (unsigned c = 0; c < op[0]->type->components(); c++) { + float t = op[0]->value.f[c] - op[1]->value.f[c]; + length_squared += t * t; + } + return new(mem_ctx) ir_constant(sqrtf(length_squared)); + } else if (strcmp(callee, "dot") == 0) { + return new(mem_ctx) ir_constant(dot(op[0], op[1])); + } else if (strcmp(callee, "equal") == 0) { + assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] == op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] == op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] == op[1]->value.f[c]; + break; + case GLSL_TYPE_BOOL: + data.b[c] = op[0]->value.b[c] == op[1]->value.b[c]; + break; + default: + assert(!"Should not get here."); + } + } + } else if (strcmp(callee, "exp") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_exp, type, op[0], NULL); + } else if (strcmp(callee, "exp2") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_exp2, type, op[0], NULL); + } else if (strcmp(callee, "faceforward") == 0) { + if (dot(op[2], op[1]) < 0) + return op[0]; + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = -op[0]->value.f[c]; + } else if (strcmp(callee, "floor") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_floor, type, op[0], NULL); + } else if (strcmp(callee, "fract") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_fract, type, op[0], NULL); + } else if (strcmp(callee, "fwidth") == 0) { + return ir_constant::zero(mem_ctx, this->type); + } else if (strcmp(callee, "greaterThan") == 0) { + assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] > op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] > op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] > op[1]->value.f[c]; + break; + default: + assert(!"Should not get here."); + } + } + } else if (strcmp(callee, "greaterThanEqual") == 0) { + assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] >= op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] >= op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] >= op[1]->value.f[c]; + break; + default: + assert(!"Should not get here."); + } + } + } else if (strcmp(callee, "inversesqrt") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_rsq, type, op[0], NULL); + } else if (strcmp(callee, "length") == 0) { + return new(mem_ctx) ir_constant(sqrtf(dot(op[0], op[0]))); + } else if (strcmp(callee, "lessThan") == 0) { + assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] < op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] < op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] < op[1]->value.f[c]; + break; + default: + assert(!"Should not get here."); + } + } + } else if (strcmp(callee, "lessThanEqual") == 0) { + assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] <= op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] <= op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] <= op[1]->value.f[c]; + break; + default: + assert(!"Should not get here."); + } + } + } else if (strcmp(callee, "log") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_log, type, op[0], NULL); + } else if (strcmp(callee, "log2") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_log2, type, op[0], NULL); + } else if (strcmp(callee, "matrixCompMult") == 0) { + assert(op[0]->type->is_float() && op[1]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = op[0]->value.f[c] * op[1]->value.f[c]; + } else if (strcmp(callee, "max") == 0) { + expr = new(mem_ctx) ir_expression(ir_binop_max, type, op[0], op[1]); + } else if (strcmp(callee, "min") == 0) { + expr = new(mem_ctx) ir_expression(ir_binop_min, type, op[0], op[1]); + } else if (strcmp(callee, "mix") == 0) { + assert(op[0]->type->is_float() && op[1]->type->is_float()); + if (op[2]->type->is_float()) { + unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1; + unsigned components = op[0]->type->components(); + for (unsigned c = 0, c2 = 0; c < components; c2 += c2_inc, c++) { + data.f[c] = op[0]->value.f[c] * (1 - op[2]->value.f[c2]) + + op[1]->value.f[c] * op[2]->value.f[c2]; + } + } else { + assert(op[2]->type->is_boolean()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = op[op[2]->value.b[c] ? 1 : 0]->value.f[c]; + } + } else if (strcmp(callee, "mod") == 0) { + expr = new(mem_ctx) ir_expression(ir_binop_mod, type, op[0], op[1]); + } else if (strcmp(callee, "normalize") == 0) { + assert(op[0]->type->is_float()); + float length = sqrtf(dot(op[0], op[0])); + + if (length == 0) + return ir_constant::zero(mem_ctx, this->type); + + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = op[0]->value.f[c] / length; + } else if (strcmp(callee, "not") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_logic_not, type, op[0], NULL); + } else if (strcmp(callee, "notEqual") == 0) { + assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] != op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] != op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] != op[1]->value.f[c]; + break; + case GLSL_TYPE_BOOL: + data.b[c] = op[0]->value.b[c] != op[1]->value.b[c]; + break; + default: + assert(!"Should not get here."); + } + } + } else if (strcmp(callee, "outerProduct") == 0) { + assert(op[0]->type->is_vector() && op[1]->type->is_vector()); + const unsigned m = op[0]->type->vector_elements; + const unsigned n = op[1]->type->vector_elements; + for (unsigned j = 0; j < n; j++) { + for (unsigned i = 0; i < m; i++) { + data.f[i+m*j] = op[0]->value.f[i] * op[1]->value.f[j]; + } + } + } else if (strcmp(callee, "pow") == 0) { + expr = new(mem_ctx) ir_expression(ir_binop_pow, type, op[0], op[1]); + } else if (strcmp(callee, "radians") == 0) { + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = M_PI / 180.0F * op[0]->value.f[c]; + } else if (strcmp(callee, "reflect") == 0) { + assert(op[0]->type->is_float()); + float dot_NI = dot(op[1], op[0]); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = op[0]->value.f[c] - 2 * dot_NI * op[1]->value.f[c]; + } else if (strcmp(callee, "refract") == 0) { + const float eta = op[2]->value.f[0]; + const float dot_NI = dot(op[1], op[0]); + const float k = 1.0F - eta * eta * (1.0F - dot_NI * dot_NI); + if (k < 0.0) { + return ir_constant::zero(mem_ctx, this->type); + } else { + for (unsigned c = 0; c < type->components(); c++) { + data.f[c] = eta * op[0]->value.f[c] - (eta * dot_NI + sqrtf(k)) + * op[1]->value.f[c]; + } + } + } else if (strcmp(callee, "sign") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_sign, type, op[0], NULL); + } else if (strcmp(callee, "sin") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_sin, type, op[0], NULL); + } else if (strcmp(callee, "sinh") == 0) { + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = sinhf(op[0]->value.f[c]); + } else if (strcmp(callee, "smoothstep") == 0) { + assert(num_parameters == 3); + assert(op[1]->type == op[0]->type); + unsigned edge_inc = op[0]->type->is_scalar() ? 0 : 1; + for (unsigned c = 0, e = 0; c < type->components(); e += edge_inc, c++) { + const float edge0 = op[0]->value.f[e]; + const float edge1 = op[1]->value.f[e]; + if (edge0 == edge1) { + data.f[c] = 0.0; /* Avoid a crash - results are undefined anyway */ + } else { + const float numerator = op[2]->value.f[c] - edge0; + const float denominator = edge1 - edge0; + const float t = CLAMP(numerator/denominator, 0, 1); + data.f[c] = t * t * (3 - 2 * t); + } + } + } else if (strcmp(callee, "sqrt") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_sqrt, type, op[0], NULL); + } else if (strcmp(callee, "step") == 0) { + assert(op[0]->type->is_float() && op[1]->type->is_float()); + /* op[0] (edge) may be either a scalar or a vector */ + const unsigned c0_inc = op[0]->type->is_scalar() ? 0 : 1; + for (unsigned c = 0, c0 = 0; c < type->components(); c0 += c0_inc, c++) + data.f[c] = (op[1]->value.f[c] < op[0]->value.f[c0]) ? 0.0F : 1.0F; + } else if (strcmp(callee, "tan") == 0) { + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = tanf(op[0]->value.f[c]); + } else if (strcmp(callee, "tanh") == 0) { + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = tanhf(op[0]->value.f[c]); + } else if (strcmp(callee, "transpose") == 0) { + assert(op[0]->type->is_matrix()); + const unsigned n = op[0]->type->vector_elements; + const unsigned m = op[0]->type->matrix_columns; + for (unsigned j = 0; j < m; j++) { + for (unsigned i = 0; i < n; i++) { + data.f[m*i+j] += op[0]->value.f[i+n*j]; + } + } + } else { + /* Unsupported builtin - some are not allowed in constant expressions. */ + return NULL; + } + + if (expr != NULL) + return expr->constant_expression_value(); + + return new(mem_ctx) ir_constant(this->type, &data); +} diff --git a/src/glsl/ir_expression_flattening.cpp b/src/glsl/ir_expression_flattening.cpp new file mode 100644 index 0000000..0b7c537 --- /dev/null +++ b/src/glsl/ir_expression_flattening.cpp @@ -0,0 +1,92 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_expression_flattening.cpp + * + * Takes the leaves of expression trees and makes them dereferences of + * assignments of the leaves to temporaries, according to a predicate. + * + * This is used for automatic function inlining, where we want to take + * an expression containing a call and move the call out to its own + * assignment so that we can inline it at the appropriate place in the + * instruction stream. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_rvalue_visitor.h" +#include "ir_expression_flattening.h" +#include "glsl_types.h" + +class ir_expression_flattening_visitor : public ir_rvalue_visitor { +public: + ir_expression_flattening_visitor(bool (*predicate)(ir_instruction *ir)) + { + this->predicate = predicate; + } + + virtual ~ir_expression_flattening_visitor() + { + /* empty */ + } + + void handle_rvalue(ir_rvalue **rvalue); + bool (*predicate)(ir_instruction *ir); +}; + +void +do_expression_flattening(exec_list *instructions, + bool (*predicate)(ir_instruction *ir)) +{ + ir_expression_flattening_visitor v(predicate); + + foreach_iter(exec_list_iterator, iter, *instructions) { + ir_instruction *ir = (ir_instruction *)iter.get(); + + ir->accept(&v); + } +} + +void +ir_expression_flattening_visitor::handle_rvalue(ir_rvalue **rvalue) +{ + ir_variable *var; + ir_assignment *assign; + ir_rvalue *ir = *rvalue; + + if (!ir || !this->predicate(ir)) + return; + + void *ctx = ralloc_parent(ir); + + var = new(ctx) ir_variable(ir->type, "flattening_tmp", ir_var_temporary); + base_ir->insert_before(var); + + assign = new(ctx) ir_assignment(new(ctx) ir_dereference_variable(var), + ir, + NULL); + base_ir->insert_before(assign); + + *rvalue = new(ctx) ir_dereference_variable(var); +} diff --git a/src/glsl/ir_expression_flattening.h b/src/glsl/ir_expression_flattening.h new file mode 100644 index 0000000..2eda159 --- /dev/null +++ b/src/glsl/ir_expression_flattening.h @@ -0,0 +1,38 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + + +/** + * \file ir_expression_flattening.h + * + * Takes the leaves of expression trees and makes them dereferences of + * assignments of the leaves to temporaries, according to a predicate. + * + * This is used for automatic function inlining, where we want to take + * an expression containing a call and move the call out to its own + * assignment so that we can inline it at the appropriate place in the + * instruction stream. + */ + +void do_expression_flattening(exec_list *instructions, + bool (*predicate)(ir_instruction *ir)); diff --git a/src/glsl/ir_function.cpp b/src/glsl/ir_function.cpp new file mode 100644 index 0000000..8db7011 --- /dev/null +++ b/src/glsl/ir_function.cpp @@ -0,0 +1,226 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "glsl_types.h" +#include "ir.h" + +int +type_compare(const glsl_type *a, const glsl_type *b) +{ + /* If the types are the same, they trivially match. + */ + if (a == b) + return 0; + + switch (a->base_type) { + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: + case GLSL_TYPE_BOOL: + /* There is no implicit conversion to or from integer types or bool. + */ + if ((a->is_integer() != b->is_integer()) + || (a->is_boolean() != b->is_boolean())) + return -1; + + /* FALLTHROUGH */ + + case GLSL_TYPE_FLOAT: + if ((a->vector_elements != b->vector_elements) + || (a->matrix_columns != b->matrix_columns)) + return -1; + + return 1; + + case GLSL_TYPE_SAMPLER: + case GLSL_TYPE_STRUCT: + /* Samplers and structures must match exactly. + */ + return -1; + + case GLSL_TYPE_ARRAY: + if ((b->base_type != GLSL_TYPE_ARRAY) + || (a->length != b->length)) + return -1; + + /* From GLSL 1.50 spec, page 27 (page 33 of the PDF): + * "There are no implicit array or structure conversions." + * + * If the comparison of the array element types detects that a conversion + * would be required, the array types do not match. + */ + return (type_compare(a->fields.array, b->fields.array) == 0) ? 0 : -1; + + case GLSL_TYPE_VOID: + case GLSL_TYPE_ERROR: + default: + /* These are all error conditions. It is invalid for a parameter to + * a function to be declared as error, void, or a function. + */ + return -1; + } + + /* This point should be unreachable. + */ + assert(0); +} + + +static int +parameter_lists_match(const exec_list *list_a, const exec_list *list_b) +{ + const exec_node *node_a = list_a->head; + const exec_node *node_b = list_b->head; + int total_score = 0; + + for (/* empty */ + ; !node_a->is_tail_sentinel() + ; node_a = node_a->next, node_b = node_b->next) { + /* If all of the parameters from the other parameter list have been + * exhausted, the lists have different length and, by definition, + * do not match. + */ + if (node_b->is_tail_sentinel()) + return -1; + + + const ir_variable *const param = (ir_variable *) node_a; + const ir_instruction *const actual = (ir_instruction *) node_b; + + /* Determine whether or not the types match. If the types are an + * exact match, the match score is zero. If the types don't match + * but the actual parameter can be coerced to the type of the declared + * parameter, the match score is one. + */ + int score; + switch ((enum ir_variable_mode)(param->mode)) { + case ir_var_auto: + case ir_var_uniform: + case ir_var_temporary: + /* These are all error conditions. It is invalid for a parameter to + * a function to be declared as auto (not in, out, or inout) or + * as uniform. + */ + assert(0); + return -1; + + case ir_var_in: + score = type_compare(param->type, actual->type); + break; + + case ir_var_out: + score = type_compare(actual->type, param->type); + break; + + case ir_var_inout: + /* Since there are no bi-directional automatic conversions (e.g., + * there is int -> float but no float -> int), inout parameters must + * be exact matches. + */ + score = (type_compare(actual->type, param->type) == 0) ? 0 : -1; + break; + + default: + assert(false); + } + + if (score < 0) + return -1; + + total_score += score; + } + + /* If all of the parameters from the other parameter list have been + * exhausted, the lists have different length and, by definition, do not + * match. + */ + if (!node_b->is_tail_sentinel()) + return -1; + + return total_score; +} + + +ir_function_signature * +ir_function::matching_signature(const exec_list *actual_parameters) +{ + ir_function_signature *match = NULL; + + foreach_iter(exec_list_iterator, iter, signatures) { + ir_function_signature *const sig = + (ir_function_signature *) iter.get(); + + const int score = parameter_lists_match(& sig->parameters, + actual_parameters); + + if (score == 0) + return sig; + + if (score > 0) { + if (match != NULL) + return NULL; + + match = sig; + } + } + + return match; +} + + +static bool +parameter_lists_match_exact(const exec_list *list_a, const exec_list *list_b) +{ + const exec_node *node_a = list_a->head; + const exec_node *node_b = list_b->head; + + for (/* empty */ + ; !node_a->is_tail_sentinel() && !node_b->is_tail_sentinel() + ; node_a = node_a->next, node_b = node_b->next) { + ir_variable *a = (ir_variable *) node_a; + ir_variable *b = (ir_variable *) node_b; + + /* If the types of the parameters do not match, the parameters lists + * are different. + */ + if (a->type != b->type) + return false; + } + + /* Unless both lists are exhausted, they differ in length and, by + * definition, do not match. + */ + return (node_a->is_tail_sentinel() == node_b->is_tail_sentinel()); +} + +ir_function_signature * +ir_function::exact_matching_signature(const exec_list *actual_parameters) +{ + foreach_iter(exec_list_iterator, iter, signatures) { + ir_function_signature *const sig = + (ir_function_signature *) iter.get(); + + if (parameter_lists_match_exact(&sig->parameters, actual_parameters)) + return sig; + } + return NULL; +} diff --git a/src/glsl/ir_function_can_inline.cpp b/src/glsl/ir_function_can_inline.cpp new file mode 100644 index 0000000..c367c30 --- /dev/null +++ b/src/glsl/ir_function_can_inline.cpp @@ -0,0 +1,76 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_function_can_inline.cpp + * + * Determines if we can inline a function call using ir_function_inlining.cpp. + * + * The primary restriction is that we can't return from the function + * other than as the last instruction. We could potentially work + * around this for some constructs by flattening control flow and + * moving the return to the end, or by using breaks from a do {} while + * (0) loop surrounding the function body. + */ + +#include "ir.h" + +class ir_function_can_inline_visitor : public ir_hierarchical_visitor { +public: + ir_function_can_inline_visitor() + { + this->num_returns = 0; + } + + virtual ir_visitor_status visit_enter(ir_return *); + + int num_returns; +}; + +ir_visitor_status +ir_function_can_inline_visitor::visit_enter(ir_return *ir) +{ + (void) ir; + this->num_returns++; + return visit_continue; +} + +bool +can_inline(ir_call *call) +{ + ir_function_can_inline_visitor v; + const ir_function_signature *callee = call->get_callee(); + if (!callee->is_defined) + return false; + + v.run((exec_list *) &callee->body); + + /* If the function is empty (no last instruction) or does not end with a + * return statement, we need to count the implicit return. + */ + ir_instruction *last = (ir_instruction *)callee->body.get_tail(); + if (last == NULL || !last->as_return()) + v.num_returns++; + + return v.num_returns == 1; +} diff --git a/src/glsl/ir_function_inlining.h b/src/glsl/ir_function_inlining.h new file mode 100644 index 0000000..6db011b --- /dev/null +++ b/src/glsl/ir_function_inlining.h @@ -0,0 +1,30 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_function_inlining.h + * + * Replaces calls to functions with the body of the function. + */ + +bool can_inline(ir_call *call); diff --git a/src/glsl/ir_hierarchical_visitor.cpp b/src/glsl/ir_hierarchical_visitor.cpp new file mode 100644 index 0000000..b5eacd6 --- /dev/null +++ b/src/glsl/ir_hierarchical_visitor.cpp @@ -0,0 +1,297 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "ir.h" +#include "ir_hierarchical_visitor.h" + +ir_hierarchical_visitor::ir_hierarchical_visitor() +{ + this->base_ir = NULL; + this->callback = NULL; + this->data = NULL; + this->in_assignee = false; +} + +ir_visitor_status +ir_hierarchical_visitor::visit(ir_variable *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit(ir_constant *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit(ir_loop_jump *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit(ir_dereference_variable *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_loop *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_loop *ir) +{ + (void) ir; + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_function_signature *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_function_signature *ir) +{ + (void) ir; + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_function *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_function *ir) +{ + (void) ir; + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_expression *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_expression *ir) +{ + (void) ir; + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_texture *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_texture *ir) +{ + (void) ir; + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_swizzle *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_swizzle *ir) +{ + (void) ir; + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_dereference_array *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_dereference_array *ir) +{ + (void) ir; + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_dereference_record *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_dereference_record *ir) +{ + (void) ir; + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_assignment *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_assignment *ir) +{ + (void) ir; + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_call *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_call *ir) +{ + (void) ir; + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_return *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_return *ir) +{ + (void) ir; + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_discard *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_discard *ir) +{ + (void) ir; + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_if *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_if *ir) +{ + (void) ir; + return visit_continue; +} + +void +ir_hierarchical_visitor::run(exec_list *instructions) +{ + visit_list_elements(this, instructions); +} + + +void +visit_tree(ir_instruction *ir, + void (*callback)(class ir_instruction *ir, void *data), + void *data) +{ + ir_hierarchical_visitor v; + + v.callback = callback; + v.data = data; + + ir->accept(&v); +} diff --git a/src/glsl/ir_hierarchical_visitor.h b/src/glsl/ir_hierarchical_visitor.h new file mode 100644 index 0000000..dc177f5 --- /dev/null +++ b/src/glsl/ir_hierarchical_visitor.h @@ -0,0 +1,183 @@ +/* -*- c++ -*- */ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#ifndef IR_HIERARCHICAL_VISITOR_H +#define IR_HIERARCHICAL_VISITOR_H + +/** + * Enumeration values returned by visit methods to guide processing + */ +enum ir_visitor_status { + visit_continue, /**< Continue visiting as normal. */ + visit_continue_with_parent, /**< Don't visit siblings, continue w/parent. */ + visit_stop /**< Stop visiting immediately. */ +}; + + +/** + * Base class of hierarchical visitors of IR instruction trees + * + * Hierarchical visitors differ from traditional visitors in a couple of + * important ways. Rather than having a single \c visit method for each + * subclass in the composite, there are three kinds of visit methods. + * Leaf-node classes have a traditional \c visit method. Internal-node + * classes have a \c visit_enter method, which is invoked just before + * processing child nodes, and a \c visit_leave method which is invoked just + * after processing child nodes. + * + * In addition, each visit method and the \c accept methods in the composite + * have a return value which guides the navigation. Any of the visit methods + * can choose to continue visiting the tree as normal (by returning \c + * visit_continue), terminate visiting any further nodes immediately (by + * returning \c visit_stop), or stop visiting sibling nodes (by returning \c + * visit_continue_with_parent). + * + * These two changes combine to allow nagivation of children to be implemented + * in the composite's \c accept method. The \c accept method for a leaf-node + * class will simply call the \c visit method, as usual, and pass its return + * value on. The \c accept method for internal-node classes will call the \c + * visit_enter method, call the \c accpet method of each child node, and, + * finally, call the \c visit_leave method. If any of these return a value + * other that \c visit_continue, the correct action must be taken. + * + * The final benefit is that the hierarchical visitor base class need not be + * abstract. Default implementations of every \c visit, \c visit_enter, and + * \c visit_leave method can be provided. By default each of these methods + * simply returns \c visit_continue. This allows a significant reduction in + * derived class code. + * + * For more information about hierarchical visitors, see: + * + * http://c2.com/cgi/wiki?HierarchicalVisitorPattern + * http://c2.com/cgi/wiki?HierarchicalVisitorDiscussion + */ + +class ir_hierarchical_visitor { +public: + ir_hierarchical_visitor(); + + /** + * \name Visit methods for leaf-node classes + */ + /*@{*/ + virtual ir_visitor_status visit(class ir_variable *); + virtual ir_visitor_status visit(class ir_constant *); + virtual ir_visitor_status visit(class ir_loop_jump *); + + /** + * ir_dereference_variable isn't technically a leaf, but it is treated as a + * leaf here for a couple reasons. By not automatically visiting the one + * child ir_variable node from the ir_dereference_variable, ir_variable + * nodes can always be handled as variable declarations. Code that used + * non-hierarchical visitors had to set an "in a dereference" flag to + * determine how to handle an ir_variable. By forcing the visitor to + * handle the ir_variable within the ir_dereference_variable visitor, this + * kludge can be avoided. + * + * In addition, I can envision no use for having separate enter and leave + * methods. Anything that could be done in the enter and leave methods + * that couldn't just be done in the visit method. + */ + virtual ir_visitor_status visit(class ir_dereference_variable *); + /*@}*/ + + /** + * \name Visit methods for internal-node classes + */ + /*@{*/ + virtual ir_visitor_status visit_enter(class ir_loop *); + virtual ir_visitor_status visit_leave(class ir_loop *); + virtual ir_visitor_status visit_enter(class ir_function_signature *); + virtual ir_visitor_status visit_leave(class ir_function_signature *); + virtual ir_visitor_status visit_enter(class ir_function *); + virtual ir_visitor_status visit_leave(class ir_function *); + virtual ir_visitor_status visit_enter(class ir_expression *); + virtual ir_visitor_status visit_leave(class ir_expression *); + virtual ir_visitor_status visit_enter(class ir_texture *); + virtual ir_visitor_status visit_leave(class ir_texture *); + virtual ir_visitor_status visit_enter(class ir_swizzle *); + virtual ir_visitor_status visit_leave(class ir_swizzle *); + virtual ir_visitor_status visit_enter(class ir_dereference_array *); + virtual ir_visitor_status visit_leave(class ir_dereference_array *); + virtual ir_visitor_status visit_enter(class ir_dereference_record *); + virtual ir_visitor_status visit_leave(class ir_dereference_record *); + virtual ir_visitor_status visit_enter(class ir_assignment *); + virtual ir_visitor_status visit_leave(class ir_assignment *); + virtual ir_visitor_status visit_enter(class ir_call *); + virtual ir_visitor_status visit_leave(class ir_call *); + virtual ir_visitor_status visit_enter(class ir_return *); + virtual ir_visitor_status visit_leave(class ir_return *); + virtual ir_visitor_status visit_enter(class ir_discard *); + virtual ir_visitor_status visit_leave(class ir_discard *); + virtual ir_visitor_status visit_enter(class ir_if *); + virtual ir_visitor_status visit_leave(class ir_if *); + /*@}*/ + + + /** + * Utility function to process a linked list of instructions with a visitor + */ + void run(struct exec_list *instructions); + + /* Some visitors may need to insert new variable declarations and + * assignments for portions of a subtree, which means they need a + * pointer to the current instruction in the stream, not just their + * node in the tree rooted at that instruction. + * + * This is implemented by visit_list_elements -- if the visitor is + * not called by it, nothing good will happen. + */ + class ir_instruction *base_ir; + + /** + * Callback function that is invoked on entry to each node visited. + * + * \warning + * Visitor classes derived from \c ir_hierarchical_visitor \b may \b not + * invoke this function. This can be used, for example, to cause the + * callback to be invoked on every node type execpt one. + */ + void (*callback)(class ir_instruction *ir, void *data); + + /** + * Extra data parameter passed to the per-node callback function + */ + void *data; + + /** + * Currently in the LHS of an assignment? + * + * This is set and cleared by the \c ir_assignment::accept method. + */ + bool in_assignee; +}; + +void visit_tree(ir_instruction *ir, + void (*callback)(class ir_instruction *ir, void *data), + void *data); + +ir_visitor_status visit_list_elements(ir_hierarchical_visitor *v, exec_list *l); + +#endif /* IR_HIERARCHICAL_VISITOR_H */ diff --git a/src/glsl/ir_hv_accept.cpp b/src/glsl/ir_hv_accept.cpp new file mode 100644 index 0000000..be8b36a --- /dev/null +++ b/src/glsl/ir_hv_accept.cpp @@ -0,0 +1,378 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "ir.h" + +/** + * \file ir_hv_accept.cpp + * Implementations of all hierarchical visitor accept methods for IR + * instructions. + */ + +/** + * Process a list of nodes using a hierarchical vistor + * + * \warning + * This function will operate correctly if a node being processed is removed + * from the list. However, if nodes are added to the list after the node being + * processed, some of the added nodes may not be processed. + */ +ir_visitor_status +visit_list_elements(ir_hierarchical_visitor *v, exec_list *l) +{ + ir_instruction *prev_base_ir = v->base_ir; + + foreach_list_safe(n, l) { + ir_instruction *const ir = (ir_instruction *) n; + v->base_ir = ir; + ir_visitor_status s = ir->accept(v); + + if (s != visit_continue) + return s; + } + v->base_ir = prev_base_ir; + + return visit_continue; +} + + +ir_visitor_status +ir_variable::accept(ir_hierarchical_visitor *v) +{ + return v->visit(this); +} + + +ir_visitor_status +ir_loop::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + s = visit_list_elements(v, &this->body_instructions); + if (s == visit_stop) + return s; + + if (s != visit_continue_with_parent) { + if (this->from) { + s = this->from->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + } + + if (this->to) { + s = this->to->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + } + + if (this->increment) { + s = this->increment->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + } + } + + return v->visit_leave(this); +} + + +ir_visitor_status +ir_loop_jump::accept(ir_hierarchical_visitor *v) +{ + return v->visit(this); +} + + +ir_visitor_status +ir_function_signature::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + s = visit_list_elements(v, &this->parameters); + if (s == visit_stop) + return s; + + s = visit_list_elements(v, &this->body); + return (s == visit_stop) ? s : v->visit_leave(this); +} + + +ir_visitor_status +ir_function::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + s = visit_list_elements(v, &this->signatures); + return (s == visit_stop) ? s : v->visit_leave(this); +} + + +ir_visitor_status +ir_expression::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + for (unsigned i = 0; i < this->get_num_operands(); i++) { + switch (this->operands[i]->accept(v)) { + case visit_continue: + break; + + case visit_continue_with_parent: + // I wish for Java's labeled break-statement here. + goto done; + + case visit_stop: + return s; + } + } + +done: + return v->visit_leave(this); +} + +ir_visitor_status +ir_texture::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + s = this->sampler->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + s = this->coordinate->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + if (this->projector) { + s = this->projector->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + } + + if (this->shadow_comparitor) { + s = this->shadow_comparitor->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + } + + switch (this->op) { + case ir_tex: + break; + case ir_txb: + s = this->lod_info.bias->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + break; + case ir_txl: + case ir_txf: + s = this->lod_info.lod->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + break; + case ir_txd: + s = this->lod_info.grad.dPdx->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + s = this->lod_info.grad.dPdy->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + break; + } + + return (s == visit_stop) ? s : v->visit_leave(this); +} + + +ir_visitor_status +ir_swizzle::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + s = this->val->accept(v); + return (s == visit_stop) ? s : v->visit_leave(this); +} + + +ir_visitor_status +ir_dereference_variable::accept(ir_hierarchical_visitor *v) +{ + return v->visit(this); +} + + +ir_visitor_status +ir_dereference_array::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + /* The array index is not the target of the assignment, so clear the + * 'in_assignee' flag. Restore it after returning from the array index. + */ + const bool was_in_assignee = v->in_assignee; + v->in_assignee = false; + s = this->array_index->accept(v); + v->in_assignee = was_in_assignee; + + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + s = this->array->accept(v); + return (s == visit_stop) ? s : v->visit_leave(this); +} + + +ir_visitor_status +ir_dereference_record::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + s = this->record->accept(v); + return (s == visit_stop) ? s : v->visit_leave(this); +} + + +ir_visitor_status +ir_assignment::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + v->in_assignee = true; + s = this->lhs->accept(v); + v->in_assignee = false; + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + s = this->rhs->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + if (this->condition) + s = this->condition->accept(v); + + return (s == visit_stop) ? s : v->visit_leave(this); +} + + +ir_visitor_status +ir_constant::accept(ir_hierarchical_visitor *v) +{ + return v->visit(this); +} + + +ir_visitor_status +ir_call::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + s = visit_list_elements(v, &this->actual_parameters); + if (s == visit_stop) + return s; + + return v->visit_leave(this); +} + + +ir_visitor_status +ir_return::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + ir_rvalue *val = this->get_value(); + if (val) { + s = val->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + } + + return v->visit_leave(this); +} + + +ir_visitor_status +ir_discard::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + if (this->condition != NULL) { + s = this->condition->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + } + + return v->visit_leave(this); +} + + +ir_visitor_status +ir_if::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + s = this->condition->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + if (s != visit_continue_with_parent) { + s = visit_list_elements(v, &this->then_instructions); + if (s == visit_stop) + return s; + } + + if (s != visit_continue_with_parent) { + s = visit_list_elements(v, &this->else_instructions); + if (s == visit_stop) + return s; + } + + return v->visit_leave(this); +} diff --git a/src/glsl/ir_import_prototypes.cpp b/src/glsl/ir_import_prototypes.cpp new file mode 100644 index 0000000..50fe4ed --- /dev/null +++ b/src/glsl/ir_import_prototypes.cpp @@ -0,0 +1,123 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_import_prototypes.cpp + * Import function prototypes from one IR tree into another. + * + * \author Ian Romanick + */ +#include +#include "ir.h" +#include "glsl_symbol_table.h" + +/** + * Visitor used to import function prototypes + * + * Normally the \c clone method of either \c ir_function or + * \c ir_function_signature could be used. However, we don't want a complete + * clone of the \c ir_function_signature. We want everything \b except the + * body of the function. + */ +class import_prototype_visitor : public ir_hierarchical_visitor { +public: + /** + */ + import_prototype_visitor(exec_list *list, glsl_symbol_table *symbols, + void *mem_ctx) + { + this->mem_ctx = mem_ctx; + this->list = list; + this->symbols = symbols; + this->function = NULL; + } + + virtual ir_visitor_status visit_enter(ir_function *ir) + { + assert(this->function == NULL); + + this->function = this->symbols->get_function(ir->name); + if (!this->function) { + this->function = new(this->mem_ctx) ir_function(ir->name); + + list->push_tail(this->function); + + /* Add the new function to the symbol table. + */ + this->symbols->add_function(this->function); + } + return visit_continue; + } + + virtual ir_visitor_status visit_leave(ir_function *ir) + { + (void) ir; + assert(this->function != NULL); + + this->function = NULL; + return visit_continue; + } + + ir_visitor_status visit_enter(ir_function_signature *ir) + { + assert(this->function != NULL); + + ir_function_signature *copy = ir->clone_prototype(mem_ctx, NULL); + + this->function->add_signature(copy); + + /* Do not process child nodes of the ir_function_signature. There can + * never be any nodes inside the ir_function_signature that we care + * about. Instead continue with the next sibling. + */ + return visit_continue_with_parent; + } + +private: + exec_list *list; + ir_function *function; + glsl_symbol_table *symbols; + void *mem_ctx; +}; + + +/** + * Import function prototypes from one IR tree into another + * + * \param source Source instruction stream containing functions whose + * prototypes are to be imported + * \param dest Destination instruction stream where new \c ir_function and + * \c ir_function_signature nodes will be stored + * \param symbols Symbol table where new functions will be stored + * \param mem_ctx ralloc memory context used for new allocations + */ +void +import_prototypes(const exec_list *source, exec_list *dest, + glsl_symbol_table *symbols, void *mem_ctx) +{ + import_prototype_visitor v(dest, symbols, mem_ctx); + + /* Making source be const is just extra documentation. + */ + v.run(const_cast(source)); +} diff --git a/src/glsl/ir_optimization.h b/src/glsl/ir_optimization.h new file mode 100644 index 0000000..dbc9f4a --- /dev/null +++ b/src/glsl/ir_optimization.h @@ -0,0 +1,72 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + + +/** + * \file ir_optimization.h + * + * Prototypes for optimization passes to be called by the compiler and drivers. + */ + +/* Operations for lower_instructions() */ +#define SUB_TO_ADD_NEG 0x01 +#define DIV_TO_MUL_RCP 0x02 +#define EXP_TO_EXP2 0x04 +#define POW_TO_EXP2 0x08 +#define LOG_TO_LOG2 0x10 +#define MOD_TO_FRACT 0x20 + +bool do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iterations); + +bool do_algebraic(exec_list *instructions); +bool do_constant_folding(exec_list *instructions); +bool do_constant_variable(exec_list *instructions); +bool do_constant_variable_unlinked(exec_list *instructions); +bool do_copy_propagation(exec_list *instructions); +bool do_constant_propagation(exec_list *instructions); +bool do_dead_code(exec_list *instructions); +bool do_dead_code_local(exec_list *instructions); +bool do_dead_code_unlinked(exec_list *instructions); +bool do_dead_functions(exec_list *instructions); +bool do_function_inlining(exec_list *instructions); +bool do_lower_jumps(exec_list *instructions, bool pull_out_jumps = true, bool lower_sub_return = true, bool lower_main_return = false, bool lower_continue = false, bool lower_break = false); +bool do_lower_texture_projection(exec_list *instructions); +bool do_if_simplification(exec_list *instructions); +bool do_discard_simplification(exec_list *instructions); +bool lower_if_to_cond_assign(exec_list *instructions, unsigned max_depth = 0); +bool do_mat_op_to_vec(exec_list *instructions); +bool do_mod_to_fract(exec_list *instructions); +bool do_noop_swizzle(exec_list *instructions); +bool do_structure_splitting(exec_list *instructions); +bool do_sub_to_add_neg(exec_list *instructions); +bool do_swizzle_swizzle(exec_list *instructions); +bool do_tree_grafting(exec_list *instructions); +bool do_vec_index_to_cond_assign(exec_list *instructions); +bool do_vec_index_to_swizzle(exec_list *instructions); +bool lower_discard(exec_list *instructions); +bool lower_instructions(exec_list *instructions, unsigned what_to_lower); +bool lower_noise(exec_list *instructions); +bool lower_variable_index_to_cond_assign(exec_list *instructions, + bool lower_input, bool lower_output, bool lower_temp, bool lower_uniform); +bool lower_quadop_vector(exec_list *instructions, bool dont_lower_swz); +bool optimize_redundant_jumps(exec_list *instructions); diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp new file mode 100644 index 0000000..0aa0b0a --- /dev/null +++ b/src/glsl/ir_print_visitor.cpp @@ -0,0 +1,466 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "ir_print_visitor.h" +#include "glsl_types.h" +#include "glsl_parser_extras.h" + +static void print_type(const glsl_type *t); + +void +ir_instruction::print(void) const +{ + ir_instruction *deconsted = const_cast(this); + + ir_print_visitor v; + deconsted->accept(&v); +} + +void +_mesa_print_ir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + if (state) { + for (unsigned i = 0; i < state->num_user_structures; i++) { + const glsl_type *const s = state->user_structures[i]; + + printf("(structure (%s) (%s@%p) (%u) (\n", + s->name, s->name, (void *) s, s->length); + + for (unsigned j = 0; j < s->length; j++) { + printf("\t(("); + print_type(s->fields.structure[j].type); + printf(")(%s))\n", s->fields.structure[j].name); + } + + printf(")\n"); + } + } + + printf("(\n"); + foreach_iter(exec_list_iterator, iter, *instructions) { + ir_instruction *ir = (ir_instruction *)iter.get(); + ir->print(); + if (ir->ir_type != ir_type_function) + printf("\n"); + } + printf("\n)"); +} + + +void ir_print_visitor::indent(void) +{ + for (int i = 0; i < indentation; i++) + printf(" "); +} + +static void +print_type(const glsl_type *t) +{ + if (t->base_type == GLSL_TYPE_ARRAY) { + printf("(array "); + print_type(t->fields.array); + printf(" %u)", t->length); + } else if ((t->base_type == GLSL_TYPE_STRUCT) + && (strncmp("gl_", t->name, 3) != 0)) { + printf("%s@%p", t->name, (void *) t); + } else { + printf("%s", t->name); + } +} + + +void ir_print_visitor::visit(ir_variable *ir) +{ + printf("(declare "); + + const char *const cent = (ir->centroid) ? "centroid " : ""; + const char *const inv = (ir->invariant) ? "invariant " : ""; + const char *const mode[] = { "", "uniform ", "in ", "out ", "inout ", + "temporary " }; + const char *const interp[] = { "", "flat", "noperspective" }; + + printf("(%s%s%s%s) ", + cent, inv, mode[ir->mode], interp[ir->interpolation]); + + print_type(ir->type); + printf(" %s@%p)", ir->name, (void *) ir); +} + + +void ir_print_visitor::visit(ir_function_signature *ir) +{ + printf("(signature "); + indentation++; + + print_type(ir->return_type); + printf("\n"); + indent(); + + printf("(parameters\n"); + indentation++; + + foreach_iter(exec_list_iterator, iter, ir->parameters) { + ir_variable *const inst = (ir_variable *) iter.get(); + + indent(); + inst->accept(this); + printf("\n"); + } + indentation--; + + indent(); + printf(")\n"); + + indent(); + + printf("(\n"); + indentation++; + + foreach_iter(exec_list_iterator, iter, ir->body) { + ir_instruction *const inst = (ir_instruction *) iter.get(); + + indent(); + inst->accept(this); + printf("\n"); + } + indentation--; + indent(); + printf("))\n"); + indentation--; +} + + +void ir_print_visitor::visit(ir_function *ir) +{ + printf("(function %s\n", ir->name); + indentation++; + foreach_iter(exec_list_iterator, iter, *ir) { + ir_function_signature *const sig = (ir_function_signature *) iter.get(); + indent(); + sig->accept(this); + printf("\n"); + } + indentation--; + indent(); + printf(")\n\n"); +} + + +void ir_print_visitor::visit(ir_expression *ir) +{ + printf("(expression "); + + print_type(ir->type); + + printf(" %s ", ir->operator_string()); + + for (unsigned i = 0; i < ir->get_num_operands(); i++) { + ir->operands[i]->accept(this); + } + + printf(") "); +} + + +void ir_print_visitor::visit(ir_texture *ir) +{ + printf("(%s ", ir->opcode_string()); + + ir->sampler->accept(this); + printf(" "); + + ir->coordinate->accept(this); + + printf(" (%d %d %d) ", ir->offsets[0], ir->offsets[1], ir->offsets[2]); + + if (ir->op != ir_txf) { + if (ir->projector) + ir->projector->accept(this); + else + printf("1"); + + if (ir->shadow_comparitor) { + printf(" "); + ir->shadow_comparitor->accept(this); + } else { + printf(" ()"); + } + } + + printf(" "); + switch (ir->op) + { + case ir_tex: + break; + case ir_txb: + ir->lod_info.bias->accept(this); + break; + case ir_txl: + case ir_txf: + ir->lod_info.lod->accept(this); + break; + case ir_txd: + printf("("); + ir->lod_info.grad.dPdx->accept(this); + printf(" "); + ir->lod_info.grad.dPdy->accept(this); + printf(")"); + break; + }; + printf(")"); +} + + +void ir_print_visitor::visit(ir_swizzle *ir) +{ + const unsigned swiz[4] = { + ir->mask.x, + ir->mask.y, + ir->mask.z, + ir->mask.w, + }; + + printf("(swiz "); + for (unsigned i = 0; i < ir->mask.num_components; i++) { + printf("%c", "xyzw"[swiz[i]]); + } + printf(" "); + ir->val->accept(this); + printf(")"); +} + + +void ir_print_visitor::visit(ir_dereference_variable *ir) +{ + ir_variable *var = ir->variable_referenced(); + printf("(var_ref %s@%p) ", var->name, (void *) var); +} + + +void ir_print_visitor::visit(ir_dereference_array *ir) +{ + printf("(array_ref "); + ir->array->accept(this); + ir->array_index->accept(this); + printf(") "); +} + + +void ir_print_visitor::visit(ir_dereference_record *ir) +{ + printf("(record_ref "); + ir->record->accept(this); + printf(" %s) ", ir->field); +} + + +void ir_print_visitor::visit(ir_assignment *ir) +{ + printf("(assign "); + + if (ir->condition) + ir->condition->accept(this); + else + printf("(constant bool (1))"); + + + char mask[5]; + unsigned j = 0; + + for (unsigned i = 0; i < 4; i++) { + if ((ir->write_mask & (1 << i)) != 0) { + mask[j] = "xyzw"[i]; + j++; + } + } + mask[j] = '\0'; + + printf(" (%s) ", mask); + + ir->lhs->accept(this); + + printf(" "); + + ir->rhs->accept(this); + printf(") "); +} + + +void ir_print_visitor::visit(ir_constant *ir) +{ + const glsl_type *const base_type = ir->type->get_base_type(); + + printf("(constant "); + print_type(ir->type); + printf(" ("); + + if (ir->type->is_array()) { + for (unsigned i = 0; i < ir->type->length; i++) + ir->get_array_element(i)->accept(this); + } else if (ir->type->is_record()) { + ir_constant *value = (ir_constant *) ir->components.get_head(); + for (unsigned i = 0; i < ir->type->length; i++) { + printf("(%s ", ir->type->fields.structure->name); + value->accept(this); + printf(")"); + + value = (ir_constant *) value->next; + } + } else { + for (unsigned i = 0; i < ir->type->components(); i++) { + if (i != 0) + printf(" "); + switch (base_type->base_type) { + case GLSL_TYPE_UINT: printf("%u", ir->value.u[i]); break; + case GLSL_TYPE_INT: printf("%d", ir->value.i[i]); break; + case GLSL_TYPE_FLOAT: printf("%f", ir->value.f[i]); break; + case GLSL_TYPE_BOOL: printf("%d", ir->value.b[i]); break; + default: assert(0); + } + } + } + printf(")) "); +} + + +void +ir_print_visitor::visit(ir_call *ir) +{ + printf("(call %s (", ir->callee_name()); + foreach_iter(exec_list_iterator, iter, *ir) { + ir_instruction *const inst = (ir_instruction *) iter.get(); + + inst->accept(this); + } + printf("))\n"); +} + + +void +ir_print_visitor::visit(ir_return *ir) +{ + printf("(return"); + + ir_rvalue *const value = ir->get_value(); + if (value) { + printf(" "); + value->accept(this); + } + + printf(")"); +} + + +void +ir_print_visitor::visit(ir_discard *ir) +{ + printf("(discard "); + + if (ir->condition != NULL) { + printf(" "); + ir->condition->accept(this); + } + + printf(")"); +} + + +void +ir_print_visitor::visit(ir_if *ir) +{ + printf("(if "); + ir->condition->accept(this); + + printf("(\n"); + indentation++; + + foreach_iter(exec_list_iterator, iter, ir->then_instructions) { + ir_instruction *const inst = (ir_instruction *) iter.get(); + + indent(); + inst->accept(this); + printf("\n"); + } + + indentation--; + indent(); + printf(")\n"); + + indent(); + if (!ir->else_instructions.is_empty()) { + printf("(\n"); + indentation++; + + foreach_iter(exec_list_iterator, iter, ir->else_instructions) { + ir_instruction *const inst = (ir_instruction *) iter.get(); + + indent(); + inst->accept(this); + printf("\n"); + } + indentation--; + indent(); + printf("))\n"); + } else { + printf("())\n"); + } +} + + +void +ir_print_visitor::visit(ir_loop *ir) +{ + printf("(loop ("); + if (ir->counter != NULL) + ir->counter->accept(this); + printf(") ("); + if (ir->from != NULL) + ir->from->accept(this); + printf(") ("); + if (ir->to != NULL) + ir->to->accept(this); + printf(") ("); + if (ir->increment != NULL) + ir->increment->accept(this); + printf(") (\n"); + indentation++; + + foreach_iter(exec_list_iterator, iter, ir->body_instructions) { + ir_instruction *const inst = (ir_instruction *) iter.get(); + + indent(); + inst->accept(this); + printf("\n"); + } + indentation--; + indent(); + printf("))\n"); +} + + +void +ir_print_visitor::visit(ir_loop_jump *ir) +{ + printf("%s", ir->is_break() ? "break" : "continue"); +} diff --git a/src/glsl/ir_print_visitor.h b/src/glsl/ir_print_visitor.h new file mode 100644 index 0000000..4feeb8c --- /dev/null +++ b/src/glsl/ir_print_visitor.h @@ -0,0 +1,83 @@ +/* -*- c++ -*- */ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#ifndef IR_PRINT_VISITOR_H +#define IR_PRINT_VISITOR_H + +#include "ir.h" +#include "ir_visitor.h" + +extern void _mesa_print_ir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); + +/** + * Abstract base class of visitors of IR instruction trees + */ +class ir_print_visitor : public ir_visitor { +public: + ir_print_visitor() + { + indentation = 0; + } + + virtual ~ir_print_visitor() + { + /* empty */ + } + + void indent(void); + + /** + * \name Visit methods + * + * As typical for the visitor pattern, there must be one \c visit method for + * each concrete subclass of \c ir_instruction. Virtual base classes within + * the hierarchy should not have \c visit methods. + */ + /*@{*/ + virtual void visit(ir_variable *); + virtual void visit(ir_function_signature *); + virtual void visit(ir_function *); + virtual void visit(ir_expression *); + virtual void visit(ir_texture *); + virtual void visit(ir_swizzle *); + virtual void visit(ir_dereference_variable *); + virtual void visit(ir_dereference_array *); + virtual void visit(ir_dereference_record *); + virtual void visit(ir_assignment *); + virtual void visit(ir_constant *); + virtual void visit(ir_call *); + virtual void visit(ir_return *); + virtual void visit(ir_discard *); + virtual void visit(ir_if *); + virtual void visit(ir_loop *); + virtual void visit(ir_loop_jump *); + /*@}*/ + +private: + int indentation; +}; + +#endif /* IR_PRINT_VISITOR_H */ diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp new file mode 100644 index 0000000..0e18881 --- /dev/null +++ b/src/glsl/ir_reader.cpp @@ -0,0 +1,1137 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include + +#include "ir_reader.h" +#include "glsl_parser_extras.h" +#include "glsl_types.h" +#include "s_expression.h" + +const static bool debug = false; + +static void ir_read_error(_mesa_glsl_parse_state *, s_expression *, + const char *fmt, ...); +static const glsl_type *read_type(_mesa_glsl_parse_state *, s_expression *); + +static void scan_for_prototypes(_mesa_glsl_parse_state *, exec_list *, + s_expression *); +static ir_function *read_function(_mesa_glsl_parse_state *, s_list *, + bool skip_body); +static void read_function_sig(_mesa_glsl_parse_state *, ir_function *, + s_list *, bool skip_body); + +static void read_instructions(_mesa_glsl_parse_state *, exec_list *, + s_expression *, ir_loop *); +static ir_instruction *read_instruction(_mesa_glsl_parse_state *, + s_expression *, ir_loop *); +static ir_variable *read_declaration(_mesa_glsl_parse_state *, s_list *); +static ir_if *read_if(_mesa_glsl_parse_state *, s_list *, ir_loop *); +static ir_loop *read_loop(_mesa_glsl_parse_state *st, s_list *list); +static ir_return *read_return(_mesa_glsl_parse_state *, s_list *); + +static ir_rvalue *read_rvalue(_mesa_glsl_parse_state *, s_expression *); +static ir_assignment *read_assignment(_mesa_glsl_parse_state *, s_list *); +static ir_expression *read_expression(_mesa_glsl_parse_state *, s_list *); +static ir_call *read_call(_mesa_glsl_parse_state *, s_list *); +static ir_swizzle *read_swizzle(_mesa_glsl_parse_state *, s_list *); +static ir_constant *read_constant(_mesa_glsl_parse_state *, s_list *); +static ir_texture *read_texture(_mesa_glsl_parse_state *, s_list *); + +static ir_dereference *read_dereference(_mesa_glsl_parse_state *, + s_expression *); +static ir_dereference_variable * +read_var_ref(_mesa_glsl_parse_state *, s_list *); +static ir_dereference_array * +read_array_ref(_mesa_glsl_parse_state *, s_list *); +static ir_dereference_record * +read_record_ref(_mesa_glsl_parse_state *, s_list *); + +void +_mesa_glsl_read_ir(_mesa_glsl_parse_state *state, exec_list *instructions, + const char *src, bool scan_for_protos) +{ + s_expression *expr = s_expression::read_expression(state, src); + if (expr == NULL) { + ir_read_error(state, NULL, "couldn't parse S-Expression."); + return; + } + + if (scan_for_protos) { + scan_for_prototypes(state, instructions, expr); + if (state->error) + return; + } + + read_instructions(state, instructions, expr, NULL); + ralloc_free(expr); + + if (debug) + validate_ir_tree(instructions); +} + +static void +ir_read_error(_mesa_glsl_parse_state *state, s_expression *expr, + const char *fmt, ...) +{ + va_list ap; + + state->error = true; + + if (state->current_function != NULL) + ralloc_asprintf_append(&state->info_log, "In function %s:\n", + state->current_function->function_name()); + ralloc_strcat(&state->info_log, "error: "); + + va_start(ap, fmt); + ralloc_vasprintf_append(&state->info_log, fmt, ap); + va_end(ap); + ralloc_strcat(&state->info_log, "\n"); + + if (expr != NULL) { + ralloc_strcat(&state->info_log, "...in this context:\n "); + expr->print(); + ralloc_strcat(&state->info_log, "\n\n"); + } +} + +static const glsl_type * +read_type(_mesa_glsl_parse_state *st, s_expression *expr) +{ + s_list *list = SX_AS_LIST(expr); + if (list != NULL) { + s_symbol *type_sym = SX_AS_SYMBOL(list->subexpressions.get_head()); + if (type_sym == NULL) { + ir_read_error(st, expr, "expected type (array ...) or (struct ...)"); + return NULL; + } + if (strcmp(type_sym->value(), "array") == 0) { + if (list->length() != 3) { + ir_read_error(st, expr, "expected type (array )"); + return NULL; + } + + // Read base type + s_expression *base_expr = (s_expression*) type_sym->next; + const glsl_type *base_type = read_type(st, base_expr); + if (base_type == NULL) { + ir_read_error(st, NULL, "when reading base type of array"); + return NULL; + } + + // Read array size + s_int *size = SX_AS_INT(base_expr->next); + if (size == NULL) { + ir_read_error(st, expr, "found non-integer array size"); + return NULL; + } + + return glsl_type::get_array_instance(base_type, size->value()); + } else if (strcmp(type_sym->value(), "struct") == 0) { + assert(false); // FINISHME + } else { + ir_read_error(st, expr, "expected (array ...) or (struct ...); " + "found (%s ...)", type_sym->value()); + return NULL; + } + } + + s_symbol *type_sym = SX_AS_SYMBOL(expr); + if (type_sym == NULL) { + ir_read_error(st, expr, "expected (symbol or list)"); + return NULL; + } + + const glsl_type *type = st->symbols->get_type(type_sym->value()); + if (type == NULL) + ir_read_error(st, expr, "invalid type: %s", type_sym->value()); + + return type; +} + + +static void +scan_for_prototypes(_mesa_glsl_parse_state *st, exec_list *instructions, + s_expression *expr) +{ + s_list *list = SX_AS_LIST(expr); + if (list == NULL) { + ir_read_error(st, expr, "Expected ( ...); found an atom."); + return; + } + + foreach_iter(exec_list_iterator, it, list->subexpressions) { + s_list *sub = SX_AS_LIST(it.get()); + if (sub == NULL) + continue; // not a (function ...); ignore it. + + s_symbol *tag = SX_AS_SYMBOL(sub->subexpressions.get_head()); + if (tag == NULL || strcmp(tag->value(), "function") != 0) + continue; // not a (function ...); ignore it. + + ir_function *f = read_function(st, sub, true); + if (f == NULL) + return; + instructions->push_tail(f); + } +} + +static ir_function * +read_function(_mesa_glsl_parse_state *st, s_list *list, bool skip_body) +{ + void *ctx = st; + bool added = false; + if (list->length() < 3) { + ir_read_error(st, list, "Expected (function (signature ...) ...)"); + return NULL; + } + + s_symbol *name = SX_AS_SYMBOL(list->subexpressions.head->next); + if (name == NULL) { + ir_read_error(st, list, "Expected (function ...)"); + return NULL; + } + + ir_function *f = st->symbols->get_function(name->value()); + if (f == NULL) { + f = new(ctx) ir_function(name->value()); + added = st->symbols->add_function(f); + assert(added); + } + + exec_list_iterator it = list->subexpressions.iterator(); + it.next(); // skip "function" tag + it.next(); // skip function name + for (/* nothing */; it.has_next(); it.next()) { + s_list *siglist = SX_AS_LIST(it.get()); + if (siglist == NULL) { + ir_read_error(st, list, "Expected (function (signature ...) ...)"); + return NULL; + } + + s_symbol *tag = SX_AS_SYMBOL(siglist->subexpressions.get_head()); + if (tag == NULL || strcmp(tag->value(), "signature") != 0) { + ir_read_error(st, siglist, "Expected (signature ...)"); + return NULL; + } + + read_function_sig(st, f, siglist, skip_body); + } + return added ? f : NULL; +} + +static void +read_function_sig(_mesa_glsl_parse_state *st, ir_function *f, s_list *list, + bool skip_body) +{ + void *ctx = st; + if (list->length() != 4) { + ir_read_error(st, list, "Expected (signature (parameters ...) " + "( ...))"); + return; + } + + s_expression *type_expr = (s_expression*) list->subexpressions.head->next; + const glsl_type *return_type = read_type(st, type_expr); + if (return_type == NULL) + return; + + s_list *paramlist = SX_AS_LIST(type_expr->next); + s_list *body_list = SX_AS_LIST(type_expr->next->next); + if (paramlist == NULL || body_list == NULL) { + ir_read_error(st, list, "Expected (signature (parameters ...) " + "( ...))"); + return; + } + s_symbol *paramtag = SX_AS_SYMBOL(paramlist->subexpressions.get_head()); + if (paramtag == NULL || strcmp(paramtag->value(), "parameters") != 0) { + ir_read_error(st, paramlist, "Expected (parameters ...)"); + return; + } + + // Read the parameters list into a temporary place. + exec_list hir_parameters; + st->symbols->push_scope(); + + exec_list_iterator it = paramlist->subexpressions.iterator(); + for (it.next() /* skip "parameters" */; it.has_next(); it.next()) { + s_list *decl = SX_AS_LIST(it.get()); + ir_variable *var = read_declaration(st, decl); + if (var == NULL) + return; + + hir_parameters.push_tail(var); + } + + ir_function_signature *sig = f->exact_matching_signature(&hir_parameters); + if (sig == NULL && skip_body) { + /* If scanning for prototypes, generate a new signature. */ + sig = new(ctx) ir_function_signature(return_type); + sig->is_builtin = true; + f->add_signature(sig); + } else if (sig != NULL) { + const char *badvar = sig->qualifiers_match(&hir_parameters); + if (badvar != NULL) { + ir_read_error(st, list, "function `%s' parameter `%s' qualifiers " + "don't match prototype", f->name, badvar); + return; + } + + if (sig->return_type != return_type) { + ir_read_error(st, list, "function `%s' return type doesn't " + "match prototype", f->name); + return; + } + } else { + /* No prototype for this body exists - skip it. */ + st->symbols->pop_scope(); + return; + } + assert(sig != NULL); + + sig->replace_parameters(&hir_parameters); + + if (!skip_body && !body_list->subexpressions.is_empty()) { + if (sig->is_defined) { + ir_read_error(st, list, "function %s redefined", f->name); + return; + } + st->current_function = sig; + read_instructions(st, &sig->body, body_list, NULL); + st->current_function = NULL; + sig->is_defined = true; + } + + st->symbols->pop_scope(); +} + +static void +read_instructions(_mesa_glsl_parse_state *st, exec_list *instructions, + s_expression *expr, ir_loop *loop_ctx) +{ + // Read in a list of instructions + s_list *list = SX_AS_LIST(expr); + if (list == NULL) { + ir_read_error(st, expr, "Expected ( ...); found an atom."); + return; + } + + foreach_iter(exec_list_iterator, it, list->subexpressions) { + s_expression *sub = (s_expression*) it.get(); + ir_instruction *ir = read_instruction(st, sub, loop_ctx); + if (ir != NULL) { + /* Global variable declarations should be moved to the top, before + * any functions that might use them. Functions are added to the + * instruction stream when scanning for prototypes, so without this + * hack, they always appear before variable declarations. + */ + if (st->current_function == NULL && ir->as_variable() != NULL) + instructions->push_head(ir); + else + instructions->push_tail(ir); + } + } +} + + +static ir_instruction * +read_instruction(_mesa_glsl_parse_state *st, s_expression *expr, + ir_loop *loop_ctx) +{ + void *ctx = st; + s_symbol *symbol = SX_AS_SYMBOL(expr); + if (symbol != NULL) { + if (strcmp(symbol->value(), "break") == 0 && loop_ctx != NULL) + return new(ctx) ir_loop_jump(ir_loop_jump::jump_break); + if (strcmp(symbol->value(), "continue") == 0 && loop_ctx != NULL) + return new(ctx) ir_loop_jump(ir_loop_jump::jump_continue); + } + + s_list *list = SX_AS_LIST(expr); + if (list == NULL || list->subexpressions.is_empty()) { + ir_read_error(st, expr, "Invalid instruction.\n"); + return NULL; + } + + s_symbol *tag = SX_AS_SYMBOL(list->subexpressions.get_head()); + if (tag == NULL) { + ir_read_error(st, expr, "expected instruction tag"); + return NULL; + } + + ir_instruction *inst = NULL; + if (strcmp(tag->value(), "declare") == 0) { + inst = read_declaration(st, list); + } else if (strcmp(tag->value(), "assign") == 0) { + inst = read_assignment(st, list); + } else if (strcmp(tag->value(), "if") == 0) { + inst = read_if(st, list, loop_ctx); + } else if (strcmp(tag->value(), "loop") == 0) { + inst = read_loop(st, list); + } else if (strcmp(tag->value(), "return") == 0) { + inst = read_return(st, list); + } else if (strcmp(tag->value(), "function") == 0) { + inst = read_function(st, list, false); + } else { + inst = read_rvalue(st, list); + if (inst == NULL) + ir_read_error(st, NULL, "when reading instruction"); + } + return inst; +} + + +static ir_variable * +read_declaration(_mesa_glsl_parse_state *st, s_list *list) +{ + void *ctx = st; + if (list->length() != 4) { + ir_read_error(st, list, "expected (declare () " + ")"); + return NULL; + } + + s_list *quals = SX_AS_LIST(list->subexpressions.head->next); + if (quals == NULL) { + ir_read_error(st, list, "expected a list of variable qualifiers"); + return NULL; + } + + s_expression *type_expr = (s_expression*) quals->next; + const glsl_type *type = read_type(st, type_expr); + if (type == NULL) + return NULL; + + s_symbol *var_name = SX_AS_SYMBOL(type_expr->next); + if (var_name == NULL) { + ir_read_error(st, list, "expected variable name, found non-symbol"); + return NULL; + } + + ir_variable *var = new(ctx) ir_variable(type, var_name->value(), + ir_var_auto); + + foreach_iter(exec_list_iterator, it, quals->subexpressions) { + s_symbol *qualifier = SX_AS_SYMBOL(it.get()); + if (qualifier == NULL) { + ir_read_error(st, list, "qualifier list must contain only symbols"); + delete var; + return NULL; + } + + // FINISHME: Check for duplicate/conflicting qualifiers. + if (strcmp(qualifier->value(), "centroid") == 0) { + var->centroid = 1; + } else if (strcmp(qualifier->value(), "invariant") == 0) { + var->invariant = 1; + } else if (strcmp(qualifier->value(), "uniform") == 0) { + var->mode = ir_var_uniform; + } else if (strcmp(qualifier->value(), "auto") == 0) { + var->mode = ir_var_auto; + } else if (strcmp(qualifier->value(), "in") == 0) { + var->mode = ir_var_in; + } else if (strcmp(qualifier->value(), "out") == 0) { + var->mode = ir_var_out; + } else if (strcmp(qualifier->value(), "inout") == 0) { + var->mode = ir_var_inout; + } else if (strcmp(qualifier->value(), "smooth") == 0) { + var->interpolation = ir_var_smooth; + } else if (strcmp(qualifier->value(), "flat") == 0) { + var->interpolation = ir_var_flat; + } else if (strcmp(qualifier->value(), "noperspective") == 0) { + var->interpolation = ir_var_noperspective; + } else { + ir_read_error(st, list, "unknown qualifier: %s", qualifier->value()); + delete var; + return NULL; + } + } + + // Add the variable to the symbol table + st->symbols->add_variable(var); + + return var; +} + + +static ir_if * +read_if(_mesa_glsl_parse_state *st, s_list *list, ir_loop *loop_ctx) +{ + void *ctx = st; + if (list->length() != 4) { + ir_read_error(st, list, "expected (if ( ...) " + "( ...))"); + return NULL; + } + + s_expression *cond_expr = (s_expression*) list->subexpressions.head->next; + ir_rvalue *condition = read_rvalue(st, cond_expr); + if (condition == NULL) { + ir_read_error(st, NULL, "when reading condition of (if ...)"); + return NULL; + } + + s_expression *then_expr = (s_expression*) cond_expr->next; + s_expression *else_expr = (s_expression*) then_expr->next; + + ir_if *iff = new(ctx) ir_if(condition); + + read_instructions(st, &iff->then_instructions, then_expr, loop_ctx); + read_instructions(st, &iff->else_instructions, else_expr, loop_ctx); + if (st->error) { + delete iff; + iff = NULL; + } + return iff; +} + + +static ir_loop * +read_loop(_mesa_glsl_parse_state *st, s_list *list) +{ + void *ctx = st; + if (list->length() != 6) { + ir_read_error(st, list, "expected (loop " + " )"); + return NULL; + } + + s_expression *count_expr = (s_expression*) list->subexpressions.head->next; + s_expression *from_expr = (s_expression*) count_expr->next; + s_expression *to_expr = (s_expression*) from_expr->next; + s_expression *inc_expr = (s_expression*) to_expr->next; + s_expression *body_expr = (s_expression*) inc_expr->next; + + // FINISHME: actually read the count/from/to fields. + + ir_loop *loop = new(ctx) ir_loop; + read_instructions(st, &loop->body_instructions, body_expr, loop); + if (st->error) { + delete loop; + loop = NULL; + } + return loop; +} + + +static ir_return * +read_return(_mesa_glsl_parse_state *st, s_list *list) +{ + void *ctx = st; + if (list->length() != 2) { + ir_read_error(st, list, "expected (return )"); + return NULL; + } + + s_expression *expr = (s_expression*) list->subexpressions.head->next; + + ir_rvalue *retval = read_rvalue(st, expr); + if (retval == NULL) { + ir_read_error(st, NULL, "when reading return value"); + return NULL; + } + + return new(ctx) ir_return(retval); +} + + +static ir_rvalue * +read_rvalue(_mesa_glsl_parse_state *st, s_expression *expr) +{ + s_list *list = SX_AS_LIST(expr); + if (list == NULL || list->subexpressions.is_empty()) + return NULL; + + s_symbol *tag = SX_AS_SYMBOL(list->subexpressions.get_head()); + if (tag == NULL) { + ir_read_error(st, expr, "expected rvalue tag"); + return NULL; + } + + ir_rvalue *rvalue = read_dereference(st, list); + if (rvalue != NULL || st->error) + return rvalue; + else if (strcmp(tag->value(), "swiz") == 0) { + rvalue = read_swizzle(st, list); + } else if (strcmp(tag->value(), "expression") == 0) { + rvalue = read_expression(st, list); + } else if (strcmp(tag->value(), "call") == 0) { + rvalue = read_call(st, list); + } else if (strcmp(tag->value(), "constant") == 0) { + rvalue = read_constant(st, list); + } else { + rvalue = read_texture(st, list); + if (rvalue == NULL && !st->error) + ir_read_error(st, expr, "unrecognized rvalue tag: %s", tag->value()); + } + + return rvalue; +} + +static ir_assignment * +read_assignment(_mesa_glsl_parse_state *st, s_list *list) +{ + void *ctx = st; + if (list->length() != 5) { + ir_read_error(st, list, "expected (assign () " + " )"); + return NULL; + } + + s_expression *cond_expr = (s_expression*) list->subexpressions.head->next; + s_list *mask_list = SX_AS_LIST(cond_expr->next); + s_expression *lhs_expr = (s_expression*) cond_expr->next->next; + s_expression *rhs_expr = (s_expression*) lhs_expr->next; + + ir_rvalue *condition = read_rvalue(st, cond_expr); + if (condition == NULL) { + ir_read_error(st, NULL, "when reading condition of assignment"); + return NULL; + } + + if (mask_list == NULL || mask_list->length() > 1) { + ir_read_error(st, mask_list, "expected () or ()"); + return NULL; + } + + unsigned mask = 0; + if (mask_list->length() == 1) { + s_symbol *mask_symbol = SX_AS_SYMBOL(mask_list->subexpressions.head); + if (mask_symbol == NULL) { + ir_read_error(st, list, "expected a write mask; found non-symbol"); + return NULL; + } + + const char *mask_str = mask_symbol->value(); + unsigned mask_length = strlen(mask_str); + if (mask_length > 4) { + ir_read_error(st, list, "invalid write mask: %s", mask_str); + return NULL; + } + + const unsigned idx_map[] = { 3, 0, 1, 2 }; /* w=bit 3, x=0, y=1, z=2 */ + + for (unsigned i = 0; i < mask_length; i++) { + if (mask_str[i] < 'w' || mask_str[i] > 'z') { + ir_read_error(st, list, "write mask contains invalid character: %c", + mask_str[i]); + return NULL; + } + mask |= 1 << idx_map[mask_str[i] - 'w']; + } + } + + ir_dereference *lhs = read_dereference(st, lhs_expr); + if (lhs == NULL) { + ir_read_error(st, NULL, "when reading left-hand side of assignment"); + return NULL; + } + + ir_rvalue *rhs = read_rvalue(st, rhs_expr); + if (rhs == NULL) { + ir_read_error(st, NULL, "when reading right-hand side of assignment"); + return NULL; + } + + if (mask == 0 && (lhs->type->is_vector() || lhs->type->is_scalar())) { + ir_read_error(st, list, "non-zero write mask required."); + return NULL; + } + + return new(ctx) ir_assignment(lhs, rhs, condition, mask); +} + +static ir_call * +read_call(_mesa_glsl_parse_state *st, s_list *list) +{ + void *ctx = st; + if (list->length() != 3) { + ir_read_error(st, list, "expected (call ( ...))"); + return NULL; + } + + s_symbol *name = SX_AS_SYMBOL(list->subexpressions.head->next); + s_list *params = SX_AS_LIST(list->subexpressions.head->next->next); + if (name == NULL || params == NULL) { + ir_read_error(st, list, "expected (call ( ...))"); + return NULL; + } + + exec_list parameters; + + foreach_iter(exec_list_iterator, it, params->subexpressions) { + s_expression *expr = (s_expression*) it.get(); + ir_rvalue *param = read_rvalue(st, expr); + if (param == NULL) { + ir_read_error(st, list, "when reading parameter to function call"); + return NULL; + } + parameters.push_tail(param); + } + + ir_function *f = st->symbols->get_function(name->value()); + if (f == NULL) { + ir_read_error(st, list, "found call to undefined function %s", + name->value()); + return NULL; + } + + ir_function_signature *callee = f->matching_signature(¶meters); + if (callee == NULL) { + ir_read_error(st, list, "couldn't find matching signature for function " + "%s", name->value()); + return NULL; + } + + return new(ctx) ir_call(callee, ¶meters); +} + +static ir_expression * +read_expression(_mesa_glsl_parse_state *st, s_list *list) +{ + void *ctx = st; + const unsigned list_length = list->length(); + if (list_length < 4) { + ir_read_error(st, list, "expected (expression " + " [])"); + return NULL; + } + + s_expression *type_expr = (s_expression*) list->subexpressions.head->next; + const glsl_type *type = read_type(st, type_expr); + if (type == NULL) + return NULL; + + /* Read the operator */ + s_symbol *op_sym = SX_AS_SYMBOL(type_expr->next); + if (op_sym == NULL) { + ir_read_error(st, list, "expected operator, found non-symbol"); + return NULL; + } + + ir_expression_operation op = ir_expression::get_operator(op_sym->value()); + if (op == (ir_expression_operation) -1) { + ir_read_error(st, list, "invalid operator: %s", op_sym->value()); + return NULL; + } + + /* Now that we know the operator, check for the right number of operands */ + if (ir_expression::get_num_operands(op) == 2) { + if (list_length != 5) { + ir_read_error(st, list, "expected (expression %s " + " )", op_sym->value()); + return NULL; + } + } else { + if (list_length != 4) { + ir_read_error(st, list, "expected (expression %s )", + op_sym->value()); + return NULL; + } + } + + s_expression *exp1 = (s_expression*) (op_sym->next); + ir_rvalue *arg1 = read_rvalue(st, exp1); + if (arg1 == NULL) { + ir_read_error(st, NULL, "when reading first operand of %s", + op_sym->value()); + return NULL; + } + + ir_rvalue *arg2 = NULL; + if (ir_expression::get_num_operands(op) == 2) { + s_expression *exp2 = (s_expression*) (exp1->next); + arg2 = read_rvalue(st, exp2); + if (arg2 == NULL) { + ir_read_error(st, NULL, "when reading second operand of %s", + op_sym->value()); + return NULL; + } + } + + return new(ctx) ir_expression(op, type, arg1, arg2); +} + +static ir_swizzle * +read_swizzle(_mesa_glsl_parse_state *st, s_list *list) +{ + if (list->length() != 3) { + ir_read_error(st, list, "expected (swiz )"); + return NULL; + } + + s_symbol *swiz = SX_AS_SYMBOL(list->subexpressions.head->next); + if (swiz == NULL) { + ir_read_error(st, list, "expected a valid swizzle; found non-symbol"); + return NULL; + } + + if (strlen(swiz->value()) > 4) { + ir_read_error(st, list, "expected a valid swizzle; found %s", + swiz->value()); + return NULL; + } + + s_expression *sub = (s_expression*) swiz->next; + ir_rvalue *rvalue = read_rvalue(st, sub); + if (rvalue == NULL) + return NULL; + + ir_swizzle *ir = ir_swizzle::create(rvalue, swiz->value(), + rvalue->type->vector_elements); + if (ir == NULL) + ir_read_error(st, list, "invalid swizzle"); + + return ir; +} + +static ir_constant * +read_constant(_mesa_glsl_parse_state *st, s_list *list) +{ + void *ctx = st; + if (list->length() != 3) { + ir_read_error(st, list, "expected (constant (...))"); + return NULL; + } + + s_expression *type_expr = (s_expression*) list->subexpressions.head->next; + const glsl_type *type = read_type(st, type_expr); + if (type == NULL) + return NULL; + + s_list *values = SX_AS_LIST(type_expr->next); + if (values == NULL) { + ir_read_error(st, list, "expected (constant (...))"); + return NULL; + } + + if (type->is_array()) { + const unsigned elements_supplied = values->length(); + if (elements_supplied != type->length) { + ir_read_error(st, values, "expected exactly %u array elements, " + "given %u", type->length, elements_supplied); + return NULL; + } + + exec_list elements; + foreach_iter(exec_list_iterator, it, values->subexpressions) { + s_expression *expr = (s_expression *) it.get(); + s_list *elt = SX_AS_LIST(expr); + if (elt == NULL) { + ir_read_error(st, expr, "expected (constant ...) array element"); + return NULL; + } + + ir_constant *ir_elt = read_constant(st, elt); + if (ir_elt == NULL) + return NULL; + elements.push_tail(ir_elt); + } + return new(ctx) ir_constant(type, &elements); + } + + const glsl_type *const base_type = type->get_base_type(); + + ir_constant_data data = { { 0 } }; + + // Read in list of values (at most 16). + int k = 0; + foreach_iter(exec_list_iterator, it, values->subexpressions) { + if (k >= 16) { + ir_read_error(st, values, "expected at most 16 numbers"); + return NULL; + } + + s_expression *expr = (s_expression*) it.get(); + + if (base_type->base_type == GLSL_TYPE_FLOAT) { + s_number *value = SX_AS_NUMBER(expr); + if (value == NULL) { + ir_read_error(st, values, "expected numbers"); + return NULL; + } + data.f[k] = value->fvalue(); + } else { + s_int *value = SX_AS_INT(expr); + if (value == NULL) { + ir_read_error(st, values, "expected integers"); + return NULL; + } + + switch (base_type->base_type) { + case GLSL_TYPE_UINT: { + data.u[k] = value->value(); + break; + } + case GLSL_TYPE_INT: { + data.i[k] = value->value(); + break; + } + case GLSL_TYPE_BOOL: { + data.b[k] = value->value(); + break; + } + default: + ir_read_error(st, values, "unsupported constant type"); + return NULL; + } + } + ++k; + } + + return new(ctx) ir_constant(type, &data); +} + +static ir_dereference * +read_dereference(_mesa_glsl_parse_state *st, s_expression *expr) +{ + s_list *list = SX_AS_LIST(expr); + if (list == NULL || list->subexpressions.is_empty()) + return NULL; + + s_symbol *tag = SX_AS_SYMBOL(list->subexpressions.head); + assert(tag != NULL); + + if (strcmp(tag->value(), "var_ref") == 0) + return read_var_ref(st, list); + if (strcmp(tag->value(), "array_ref") == 0) + return read_array_ref(st, list); + if (strcmp(tag->value(), "record_ref") == 0) + return read_record_ref(st, list); + return NULL; +} + +static ir_dereference_variable * +read_var_ref(_mesa_glsl_parse_state *st, s_list *list) +{ + void *ctx = st; + if (list->length() != 2) { + ir_read_error(st, list, "expected (var_ref )"); + return NULL; + } + s_symbol *var_name = SX_AS_SYMBOL(list->subexpressions.head->next); + if (var_name == NULL) { + ir_read_error(st, list, "expected (var_ref )"); + return NULL; + } + + ir_variable *var = st->symbols->get_variable(var_name->value()); + if (var == NULL) { + ir_read_error(st, list, "undeclared variable: %s", var_name->value()); + return NULL; + } + + return new(ctx) ir_dereference_variable(var); +} + +static ir_dereference_array * +read_array_ref(_mesa_glsl_parse_state *st, s_list *list) +{ + void *ctx = st; + if (list->length() != 3) { + ir_read_error(st, list, "expected (array_ref )"); + return NULL; + } + + s_expression *subj_expr = (s_expression*) list->subexpressions.head->next; + ir_rvalue *subject = read_rvalue(st, subj_expr); + if (subject == NULL) { + ir_read_error(st, NULL, "when reading the subject of an array_ref"); + return NULL; + } + + s_expression *idx_expr = (s_expression*) subj_expr->next; + ir_rvalue *idx = read_rvalue(st, idx_expr); + return new(ctx) ir_dereference_array(subject, idx); +} + +static ir_dereference_record * +read_record_ref(_mesa_glsl_parse_state *st, s_list *list) +{ + void *ctx = st; + if (list->length() != 3) { + ir_read_error(st, list, "expected (record_ref )"); + return NULL; + } + + s_expression *subj_expr = (s_expression*) list->subexpressions.head->next; + ir_rvalue *subject = read_rvalue(st, subj_expr); + if (subject == NULL) { + ir_read_error(st, NULL, "when reading the subject of a record_ref"); + return NULL; + } + + s_symbol *field = SX_AS_SYMBOL(subj_expr->next); + if (field == NULL) { + ir_read_error(st, list, "expected (record_ref ... )"); + return NULL; + } + return new(ctx) ir_dereference_record(subject, field->value()); +} + +static bool +valid_texture_list_length(ir_texture_opcode op, s_list *list) +{ + unsigned required_length = 7; + if (op == ir_txf) + required_length = 5; + else if (op == ir_tex) + required_length = 6; + + return list->length() == required_length; +} + +static ir_texture * +read_texture(_mesa_glsl_parse_state *st, s_list *list) +{ + void *ctx = st; + s_symbol *tag = SX_AS_SYMBOL(list->subexpressions.head); + assert(tag != NULL); + + ir_texture_opcode op = ir_texture::get_opcode(tag->value()); + if (op == (ir_texture_opcode) -1) + return NULL; + + if (!valid_texture_list_length(op, list)) { + ir_read_error(st, NULL, "invalid list size in (%s ...)", tag->value()); + return NULL; + } + + ir_texture *tex = new(ctx) ir_texture(op); + + // Read sampler (must be a deref) + s_expression *sampler_expr = (s_expression *) tag->next; + ir_dereference *sampler = read_dereference(st, sampler_expr); + if (sampler == NULL) { + ir_read_error(st, NULL, "when reading sampler in (%s ...)", tag->value()); + return NULL; + } + tex->set_sampler(sampler); + + // Read coordinate (any rvalue) + s_expression *coordinate_expr = (s_expression *) sampler_expr->next; + tex->coordinate = read_rvalue(st, coordinate_expr); + if (tex->coordinate == NULL) { + ir_read_error(st, NULL, "when reading coordinate in (%s ...)", + tag->value()); + return NULL; + } + + // Read texel offset, i.e. (0 0 0) + s_list *offset_list = SX_AS_LIST(coordinate_expr->next); + if (offset_list == NULL || offset_list->length() != 3) { + ir_read_error(st, offset_list, "expected ( )"); + return NULL; + } + s_int *offset_x = SX_AS_INT(offset_list->subexpressions.head); + s_int *offset_y = SX_AS_INT(offset_list->subexpressions.head->next); + s_int *offset_z = SX_AS_INT(offset_list->subexpressions.head->next->next); + if (offset_x == NULL || offset_y == NULL || offset_z == NULL) { + ir_read_error(st, offset_list, "expected ( )"); + return NULL; + } + tex->offsets[0] = offset_x->value(); + tex->offsets[1] = offset_y->value(); + tex->offsets[2] = offset_z->value(); + + if (op == ir_txf) { + s_expression *lod_expr = (s_expression *) offset_list->next; + tex->lod_info.lod = read_rvalue(st, lod_expr); + if (tex->lod_info.lod == NULL) { + ir_read_error(st, NULL, "when reading LOD in (txf ...)"); + return NULL; + } + } else { + s_expression *proj_expr = (s_expression *) offset_list->next; + s_int *proj_as_int = SX_AS_INT(proj_expr); + if (proj_as_int && proj_as_int->value() == 1) { + tex->projector = NULL; + } else { + tex->projector = read_rvalue(st, proj_expr); + if (tex->projector == NULL) { + ir_read_error(st, NULL, "when reading projective divide in (%s ..)", + tag->value()); + return NULL; + } + } + + s_list *shadow_list = SX_AS_LIST(proj_expr->next); + if (shadow_list == NULL) { + ir_read_error(st, NULL, "shadow comparitor must be a list"); + return NULL; + } + if (shadow_list->subexpressions.is_empty()) { + tex->shadow_comparitor= NULL; + } else { + tex->shadow_comparitor = read_rvalue(st, shadow_list); + if (tex->shadow_comparitor == NULL) { + ir_read_error(st, NULL, "when reading shadow comparitor in (%s ..)", + tag->value()); + return NULL; + } + } + s_expression *lod_expr = (s_expression *) shadow_list->next; + + switch (op) { + case ir_txb: + tex->lod_info.bias = read_rvalue(st, lod_expr); + if (tex->lod_info.bias == NULL) { + ir_read_error(st, NULL, "when reading LOD bias in (txb ...)"); + return NULL; + } + break; + case ir_txl: + tex->lod_info.lod = read_rvalue(st, lod_expr); + if (tex->lod_info.lod == NULL) { + ir_read_error(st, NULL, "when reading LOD in (txl ...)"); + return NULL; + } + break; + case ir_txd: { + s_list *lod_list = SX_AS_LIST(lod_expr); + if (lod_list->length() != 2) { + ir_read_error(st, lod_expr, "expected (dPdx dPdy) in (txd ...)"); + return NULL; + } + s_expression *dx_expr = (s_expression *) lod_list->subexpressions.head; + s_expression *dy_expr = (s_expression *) dx_expr->next; + + tex->lod_info.grad.dPdx = read_rvalue(st, dx_expr); + if (tex->lod_info.grad.dPdx == NULL) { + ir_read_error(st, NULL, "when reading dPdx in (txd ...)"); + return NULL; + } + tex->lod_info.grad.dPdy = read_rvalue(st, dy_expr); + if (tex->lod_info.grad.dPdy == NULL) { + ir_read_error(st, NULL, "when reading dPdy in (txd ...)"); + return NULL; + } + break; + } + default: + // tex doesn't have any extra parameters and txf was handled earlier. + break; + }; + } + return tex; +} diff --git a/src/glsl/ir_reader.h b/src/glsl/ir_reader.h new file mode 100644 index 0000000..aef2ca2 --- /dev/null +++ b/src/glsl/ir_reader.h @@ -0,0 +1,34 @@ +/* -*- c++ -*- */ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#ifndef IR_READER_H +#define IR_READER_H + +#include "ir.h" + +void _mesa_glsl_read_ir(_mesa_glsl_parse_state *state, exec_list *instructions, + const char *src, bool scan_for_prototypes); + +#endif /* IR_READER_H */ diff --git a/src/glsl/ir_rvalue_visitor.cpp b/src/glsl/ir_rvalue_visitor.cpp new file mode 100644 index 0000000..773bfcf --- /dev/null +++ b/src/glsl/ir_rvalue_visitor.cpp @@ -0,0 +1,141 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_rvalue_visitor.cpp + * + * Generic class to implement the common pattern we have of wanting to + * visit each ir_rvalue * and possibly change that node to a different + * class. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_rvalue_visitor.h" +#include "ir_print_visitor.h" +#include "glsl_types.h" + +ir_visitor_status +ir_rvalue_visitor::visit_leave(ir_expression *ir) +{ + unsigned int operand; + + for (operand = 0; operand < ir->get_num_operands(); operand++) { + handle_rvalue(&ir->operands[operand]); + } + + return visit_continue; +} + +ir_visitor_status +ir_rvalue_visitor::visit_leave(ir_texture *ir) +{ + handle_rvalue(&ir->coordinate); + handle_rvalue(&ir->projector); + handle_rvalue(&ir->shadow_comparitor); + + switch (ir->op) { + case ir_tex: + break; + case ir_txb: + handle_rvalue(&ir->lod_info.bias); + break; + case ir_txf: + case ir_txl: + handle_rvalue(&ir->lod_info.lod); + break; + case ir_txd: + handle_rvalue(&ir->lod_info.grad.dPdx); + handle_rvalue(&ir->lod_info.grad.dPdy); + break; + } + + return visit_continue; +} + +ir_visitor_status +ir_rvalue_visitor::visit_leave(ir_swizzle *ir) +{ + handle_rvalue(&ir->val); + return visit_continue; +} + +ir_visitor_status +ir_rvalue_visitor::visit_leave(ir_dereference_array *ir) +{ + /* The array index is not the target of the assignment, so clear the + * 'in_assignee' flag. Restore it after returning from the array index. + */ + const bool was_in_assignee = this->in_assignee; + this->in_assignee = false; + handle_rvalue(&ir->array_index); + this->in_assignee = was_in_assignee; + + handle_rvalue(&ir->array); + return visit_continue; +} + +ir_visitor_status +ir_rvalue_visitor::visit_leave(ir_dereference_record *ir) +{ + handle_rvalue(&ir->record); + return visit_continue; +} + +ir_visitor_status +ir_rvalue_visitor::visit_leave(ir_assignment *ir) +{ + handle_rvalue(&ir->rhs); + handle_rvalue(&ir->condition); + + return visit_continue; +} + +ir_visitor_status +ir_rvalue_visitor::visit_leave(ir_call *ir) +{ + foreach_iter(exec_list_iterator, iter, *ir) { + ir_rvalue *param = (ir_rvalue *)iter.get(); + ir_rvalue *new_param = param; + handle_rvalue(&new_param); + + if (new_param != param) { + param->replace_with(new_param); + } + } + return visit_continue; +} + +ir_visitor_status +ir_rvalue_visitor::visit_leave(ir_return *ir) +{ + handle_rvalue(&ir->value);; + return visit_continue; +} + +ir_visitor_status +ir_rvalue_visitor::visit_leave(ir_if *ir) +{ + handle_rvalue(&ir->condition); + return visit_continue; +} diff --git a/src/glsl/ir_rvalue_visitor.h b/src/glsl/ir_rvalue_visitor.h new file mode 100644 index 0000000..31a56be --- /dev/null +++ b/src/glsl/ir_rvalue_visitor.h @@ -0,0 +1,47 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_rvalue_visitor.h + * + * Generic class to implement the common pattern we have of wanting to + * visit each ir_rvalue * and possibly change that node to a different + * class. Just implement handle_rvalue() and you will be called with + * a pointer to each rvalue in the tree. + */ + +class ir_rvalue_visitor : public ir_hierarchical_visitor { +public: + + virtual ir_visitor_status visit_leave(ir_assignment *); + virtual ir_visitor_status visit_leave(ir_call *); + virtual ir_visitor_status visit_leave(ir_dereference_array *); + virtual ir_visitor_status visit_leave(ir_dereference_record *); + virtual ir_visitor_status visit_leave(ir_expression *); + virtual ir_visitor_status visit_leave(ir_if *); + virtual ir_visitor_status visit_leave(ir_return *); + virtual ir_visitor_status visit_leave(ir_swizzle *); + virtual ir_visitor_status visit_leave(ir_texture *); + + virtual void handle_rvalue(ir_rvalue **rvalue) = 0; +}; diff --git a/src/glsl/ir_set_program_inouts.cpp b/src/glsl/ir_set_program_inouts.cpp new file mode 100644 index 0000000..7142815 --- /dev/null +++ b/src/glsl/ir_set_program_inouts.cpp @@ -0,0 +1,162 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_set_program_inouts.cpp + * + * Sets the InputsRead and OutputsWritten of Mesa programs. + * + * Mesa programs (gl_program, not gl_shader_program) have a set of + * flags indicating which varyings are read and written. Computing + * which are actually read from some sort of backend code can be + * tricky when variable array indexing involved. So this pass + * provides support for setting InputsRead and OutputsWritten right + * from the GLSL IR. + */ + +extern "C" { +#include "main/core.h" /* for struct gl_program */ +#include "program/hash_table.h" +} +#include "ir.h" +#include "ir_visitor.h" +#include "glsl_types.h" + +class ir_set_program_inouts_visitor : public ir_hierarchical_visitor { +public: + ir_set_program_inouts_visitor(struct gl_program *prog) + { + this->prog = prog; + this->ht = hash_table_ctor(0, + hash_table_pointer_hash, + hash_table_pointer_compare); + } + ~ir_set_program_inouts_visitor() + { + hash_table_dtor(this->ht); + } + + virtual ir_visitor_status visit_enter(ir_dereference_array *); + virtual ir_visitor_status visit_enter(ir_function_signature *); + virtual ir_visitor_status visit(ir_dereference_variable *); + virtual ir_visitor_status visit(ir_variable *); + + struct gl_program *prog; + struct hash_table *ht; +}; + +static void +mark(struct gl_program *prog, ir_variable *var, int offset, int len) +{ + /* As of GLSL 1.20, varyings can only be floats, floating-point + * vectors or matrices, or arrays of them. For Mesa programs using + * InputsRead/OutputsWritten, everything but matrices uses one + * slot, while matrices use a slot per column. Presumably + * something doing a more clever packing would use something other + * than InputsRead/OutputsWritten. + */ + + for (int i = 0; i < len; i++) { + if (var->mode == ir_var_in) + prog->InputsRead |= BITFIELD64_BIT(var->location + offset + i); + else + prog->OutputsWritten |= BITFIELD64_BIT(var->location + offset + i); + } +} + +/* Default handler: Mark all the locations in the variable as used. */ +ir_visitor_status +ir_set_program_inouts_visitor::visit(ir_dereference_variable *ir) +{ + if (hash_table_find(this->ht, ir->var) == NULL) + return visit_continue; + + if (ir->type->is_array()) { + for (unsigned int i = 0; i < ir->type->length; i++) { + mark(this->prog, ir->var, i, + ir->type->length * ir->type->fields.array->matrix_columns); + } + } else { + mark(this->prog, ir->var, 0, ir->type->matrix_columns); + } + + return visit_continue; +} + +ir_visitor_status +ir_set_program_inouts_visitor::visit_enter(ir_dereference_array *ir) +{ + ir_dereference_variable *deref_var; + ir_constant *index = ir->array_index->as_constant(); + deref_var = ir->array->as_dereference_variable(); + ir_variable *var = NULL; + + /* Check that we're dereferencing a shader in or out */ + if (deref_var) + var = (ir_variable *)hash_table_find(this->ht, deref_var->var); + + if (index && var) { + int width = 1; + + if (deref_var->type->is_array() && + deref_var->type->fields.array->is_matrix()) { + width = deref_var->type->fields.array->matrix_columns; + } + + mark(this->prog, var, index->value.i[0] * width, width); + return visit_continue_with_parent; + } + + return visit_continue; +} + +ir_visitor_status +ir_set_program_inouts_visitor::visit(ir_variable *ir) +{ + if (ir->mode == ir_var_in || + ir->mode == ir_var_out) { + hash_table_insert(this->ht, ir, ir); + } + + return visit_continue; +} + +ir_visitor_status +ir_set_program_inouts_visitor::visit_enter(ir_function_signature *ir) +{ + /* We don't want to descend into the function parameters and + * consider them as shader inputs or outputs. + */ + visit_list_elements(this, &ir->body); + return visit_continue_with_parent; +} + +void +do_set_program_inouts(exec_list *instructions, struct gl_program *prog) +{ + ir_set_program_inouts_visitor v(prog); + + prog->InputsRead = 0; + prog->OutputsWritten = 0; + visit_list_elements(&v, instructions); +} diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp new file mode 100644 index 0000000..0fc3baf --- /dev/null +++ b/src/glsl/ir_validate.cpp @@ -0,0 +1,562 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_validate.cpp + * + * Attempts to verify that various invariants of the IR tree are true. + * + * In particular, at the moment it makes sure that no single + * ir_instruction node except for ir_variable appears multiple times + * in the ir tree. ir_variable does appear multiple times: Once as a + * declaration in an exec_list, and multiple times as the endpoint of + * a dereference chain. + */ + +#include +#include "ir.h" +#include "ir_hierarchical_visitor.h" +#include "program/hash_table.h" +#include "glsl_types.h" + +class ir_validate : public ir_hierarchical_visitor { +public: + ir_validate() + { + this->ht = hash_table_ctor(0, hash_table_pointer_hash, + hash_table_pointer_compare); + + this->current_function = NULL; + + this->callback = ir_validate::validate_ir; + this->data = ht; + } + + ~ir_validate() + { + hash_table_dtor(this->ht); + } + + virtual ir_visitor_status visit(ir_variable *v); + virtual ir_visitor_status visit(ir_dereference_variable *ir); + virtual ir_visitor_status visit(ir_if *ir); + + virtual ir_visitor_status visit_leave(ir_loop *ir); + virtual ir_visitor_status visit_enter(ir_function *ir); + virtual ir_visitor_status visit_leave(ir_function *ir); + virtual ir_visitor_status visit_enter(ir_function_signature *ir); + + virtual ir_visitor_status visit_leave(ir_expression *ir); + virtual ir_visitor_status visit_leave(ir_swizzle *ir); + + virtual ir_visitor_status visit_enter(ir_assignment *ir); + virtual ir_visitor_status visit_enter(ir_call *ir); + + static void validate_ir(ir_instruction *ir, void *data); + + ir_function *current_function; + + struct hash_table *ht; +}; + + +ir_visitor_status +ir_validate::visit(ir_dereference_variable *ir) +{ + if ((ir->var == NULL) || (ir->var->as_variable() == NULL)) { + printf("ir_dereference_variable @ %p does not specify a variable %p\n", + (void *) ir, (void *) ir->var); + abort(); + } + + if (hash_table_find(ht, ir->var) == NULL) { + printf("ir_dereference_variable @ %p specifies undeclared variable " + "`%s' @ %p\n", + (void *) ir, ir->var->name, (void *) ir->var); + abort(); + } + + this->validate_ir(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_validate::visit(ir_if *ir) +{ + if (ir->condition->type != glsl_type::bool_type) { + printf("ir_if condition %s type instead of bool.\n", + ir->condition->type->name); + ir->print(); + printf("\n"); + abort(); + } + + return visit_continue; +} + + +ir_visitor_status +ir_validate::visit_leave(ir_loop *ir) +{ + if (ir->counter != NULL) { + if ((ir->from == NULL) || (ir->from == NULL) || (ir->increment == NULL)) { + printf("ir_loop has invalid loop controls:\n" + " counter: %p\n" + " from: %p\n" + " to: %p\n" + " increment: %p\n", + (void *) ir->counter, (void *) ir->from, (void *) ir->to, + (void *) ir->increment); + abort(); + } + + if ((ir->cmp < ir_binop_less) || (ir->cmp > ir_binop_nequal)) { + printf("ir_loop has invalid comparitor %d\n", ir->cmp); + abort(); + } + } else { + if ((ir->from != NULL) || (ir->from != NULL) || (ir->increment != NULL)) { + printf("ir_loop has invalid loop controls:\n" + " counter: %p\n" + " from: %p\n" + " to: %p\n" + " increment: %p\n", + (void *) ir->counter, (void *) ir->from, (void *) ir->to, + (void *) ir->increment); + abort(); + } + } + + return visit_continue; +} + + +ir_visitor_status +ir_validate::visit_enter(ir_function *ir) +{ + /* Function definitions cannot be nested. + */ + if (this->current_function != NULL) { + printf("Function definition nested inside another function " + "definition:\n"); + printf("%s %p inside %s %p\n", + ir->name, (void *) ir, + this->current_function->name, (void *) this->current_function); + abort(); + } + + /* Store the current function hierarchy being traversed. This is used + * by the function signature visitor to ensure that the signatures are + * linked with the correct functions. + */ + this->current_function = ir; + + this->validate_ir(ir, this->data); + + /* Verify that all of the things stored in the list of signatures are, + * in fact, function signatures. + */ + foreach_list(node, &ir->signatures) { + ir_instruction *sig = (ir_instruction *) node; + + if (sig->ir_type != ir_type_function_signature) { + printf("Non-signature in signature list of function `%s'\n", + ir->name); + abort(); + } + } + + return visit_continue; +} + +ir_visitor_status +ir_validate::visit_leave(ir_function *ir) +{ + assert(ralloc_parent(ir->name) == ir); + + this->current_function = NULL; + return visit_continue; +} + +ir_visitor_status +ir_validate::visit_enter(ir_function_signature *ir) +{ + if (this->current_function != ir->function()) { + printf("Function signature nested inside wrong function " + "definition:\n"); + printf("%p inside %s %p instead of %s %p\n", + (void *) ir, + this->current_function->name, (void *) this->current_function, + ir->function_name(), (void *) ir->function()); + abort(); + } + + if (ir->return_type == NULL) { + printf("Function signature %p for function %s has NULL return type.\n", + (void *) ir, ir->function_name()); + abort(); + } + + this->validate_ir(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_validate::visit_leave(ir_expression *ir) +{ + switch (ir->operation) { + case ir_unop_bit_not: + assert(ir->operands[0]->type == ir->type); + break; + case ir_unop_logic_not: + assert(ir->type->base_type == GLSL_TYPE_BOOL); + assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL); + break; + + case ir_unop_neg: + case ir_unop_abs: + case ir_unop_sign: + case ir_unop_rcp: + case ir_unop_rsq: + case ir_unop_sqrt: + assert(ir->type == ir->operands[0]->type); + break; + + case ir_unop_exp: + case ir_unop_log: + case ir_unop_exp2: + case ir_unop_log2: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); + assert(ir->type == ir->operands[0]->type); + break; + + case ir_unop_f2i: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); + assert(ir->type->base_type == GLSL_TYPE_INT); + break; + case ir_unop_i2f: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT); + assert(ir->type->base_type == GLSL_TYPE_FLOAT); + break; + case ir_unop_f2b: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); + assert(ir->type->base_type == GLSL_TYPE_BOOL); + break; + case ir_unop_b2f: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL); + assert(ir->type->base_type == GLSL_TYPE_FLOAT); + break; + case ir_unop_i2b: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT); + assert(ir->type->base_type == GLSL_TYPE_BOOL); + break; + case ir_unop_b2i: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL); + assert(ir->type->base_type == GLSL_TYPE_INT); + break; + case ir_unop_u2f: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT); + assert(ir->type->base_type == GLSL_TYPE_FLOAT); + break; + + case ir_unop_any: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL); + assert(ir->type == glsl_type::bool_type); + break; + + case ir_unop_trunc: + case ir_unop_round_even: + case ir_unop_ceil: + case ir_unop_floor: + case ir_unop_fract: + case ir_unop_sin: + case ir_unop_cos: + case ir_unop_sin_reduced: + case ir_unop_cos_reduced: + case ir_unop_dFdx: + case ir_unop_dFdy: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); + assert(ir->operands[0]->type == ir->type); + break; + + case ir_unop_noise: + /* XXX what can we assert here? */ + break; + + case ir_binop_add: + case ir_binop_sub: + case ir_binop_mul: + case ir_binop_div: + case ir_binop_mod: + case ir_binop_min: + case ir_binop_max: + case ir_binop_pow: + if (ir->operands[0]->type->is_scalar()) + assert(ir->operands[1]->type == ir->type); + else if (ir->operands[1]->type->is_scalar()) + assert(ir->operands[0]->type == ir->type); + else if (ir->operands[0]->type->is_vector() && + ir->operands[1]->type->is_vector()) { + assert(ir->operands[0]->type == ir->operands[1]->type); + assert(ir->operands[0]->type == ir->type); + } + break; + + case ir_binop_less: + case ir_binop_greater: + case ir_binop_lequal: + case ir_binop_gequal: + case ir_binop_equal: + case ir_binop_nequal: + /* The semantics of the IR operators differ from the GLSL <, >, <=, >=, + * ==, and != operators. The IR operators perform a component-wise + * comparison on scalar or vector types and return a boolean scalar or + * vector type of the same size. + */ + assert(ir->type->base_type == GLSL_TYPE_BOOL); + assert(ir->operands[0]->type == ir->operands[1]->type); + assert(ir->operands[0]->type->is_vector() + || ir->operands[0]->type->is_scalar()); + assert(ir->operands[0]->type->vector_elements + == ir->type->vector_elements); + break; + + case ir_binop_all_equal: + case ir_binop_any_nequal: + /* GLSL == and != operate on scalars, vectors, matrices and arrays, and + * return a scalar boolean. The IR matches that. + */ + assert(ir->type == glsl_type::bool_type); + assert(ir->operands[0]->type == ir->operands[1]->type); + break; + + case ir_binop_lshift: + case ir_binop_rshift: + assert(ir->operands[0]->type->is_integer() && + ir->operands[1]->type->is_integer()); + if (ir->operands[0]->type->is_scalar()) { + assert(ir->operands[1]->type->is_scalar()); + } + if (ir->operands[0]->type->is_vector() && + ir->operands[1]->type->is_vector()) { + assert(ir->operands[0]->type->components() == + ir->operands[1]->type->components()); + } + assert(ir->type == ir->operands[0]->type); + break; + + case ir_binop_bit_and: + case ir_binop_bit_xor: + case ir_binop_bit_or: + assert(ir->operands[0]->type->base_type == + ir->operands[1]->type->base_type); + assert(ir->type->is_integer()); + if (ir->operands[0]->type->is_vector() && + ir->operands[1]->type->is_vector()) { + assert(ir->operands[0]->type->vector_elements == + ir->operands[1]->type->vector_elements); + } + break; + + case ir_binop_logic_and: + case ir_binop_logic_xor: + case ir_binop_logic_or: + assert(ir->type == glsl_type::bool_type); + assert(ir->operands[0]->type == glsl_type::bool_type); + assert(ir->operands[1]->type == glsl_type::bool_type); + break; + + case ir_binop_dot: + assert(ir->type == glsl_type::float_type); + assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); + assert(ir->operands[0]->type->is_vector()); + assert(ir->operands[0]->type == ir->operands[1]->type); + break; + + case ir_quadop_vector: + /* The vector operator collects some number of scalars and generates a + * vector from them. + * + * - All of the operands must be scalar. + * - Number of operands must matche the size of the resulting vector. + * - Base type of the operands must match the base type of the result. + */ + assert(ir->type->is_vector()); + switch (ir->type->vector_elements) { + case 2: + assert(ir->operands[0]->type->is_scalar()); + assert(ir->operands[0]->type->base_type == ir->type->base_type); + assert(ir->operands[1]->type->is_scalar()); + assert(ir->operands[1]->type->base_type == ir->type->base_type); + assert(ir->operands[2] == NULL); + assert(ir->operands[3] == NULL); + break; + case 3: + assert(ir->operands[0]->type->is_scalar()); + assert(ir->operands[0]->type->base_type == ir->type->base_type); + assert(ir->operands[1]->type->is_scalar()); + assert(ir->operands[1]->type->base_type == ir->type->base_type); + assert(ir->operands[2]->type->is_scalar()); + assert(ir->operands[2]->type->base_type == ir->type->base_type); + assert(ir->operands[3] == NULL); + break; + case 4: + assert(ir->operands[0]->type->is_scalar()); + assert(ir->operands[0]->type->base_type == ir->type->base_type); + assert(ir->operands[1]->type->is_scalar()); + assert(ir->operands[1]->type->base_type == ir->type->base_type); + assert(ir->operands[2]->type->is_scalar()); + assert(ir->operands[2]->type->base_type == ir->type->base_type); + assert(ir->operands[3]->type->is_scalar()); + assert(ir->operands[3]->type->base_type == ir->type->base_type); + break; + default: + /* The is_vector assertion above should prevent execution from ever + * getting here. + */ + assert(!"Should not get here."); + break; + } + } + + return visit_continue; +} + +ir_visitor_status +ir_validate::visit_leave(ir_swizzle *ir) +{ + int chans[4] = {ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w}; + + for (unsigned int i = 0; i < ir->type->vector_elements; i++) { + if (chans[i] >= ir->val->type->vector_elements) { + printf("ir_swizzle @ %p specifies a channel not present " + "in the value.\n", (void *) ir); + ir->print(); + abort(); + } + } + + return visit_continue; +} + +ir_visitor_status +ir_validate::visit(ir_variable *ir) +{ + /* An ir_variable is the one thing that can (and will) appear multiple times + * in an IR tree. It is added to the hashtable so that it can be used + * in the ir_dereference_variable handler to ensure that a variable is + * declared before it is dereferenced. + */ + if (ir->name) + assert(ralloc_parent(ir->name) == ir); + + hash_table_insert(ht, ir, ir); + return visit_continue; +} + +ir_visitor_status +ir_validate::visit_enter(ir_assignment *ir) +{ + const ir_dereference *const lhs = ir->lhs; + if (lhs->type->is_scalar() || lhs->type->is_vector()) { + if (ir->write_mask == 0) { + printf("Assignment LHS is %s, but write mask is 0:\n", + lhs->type->is_scalar() ? "scalar" : "vector"); + ir->print(); + abort(); + } + + int lhs_components = 0; + for (int i = 0; i < 4; i++) { + if (ir->write_mask & (1 << i)) + lhs_components++; + } + + if (lhs_components != ir->rhs->type->vector_elements) { + printf("Assignment count of LHS write mask channels enabled not\n" + "matching RHS vector size (%d LHS, %d RHS).\n", + lhs_components, ir->rhs->type->vector_elements); + ir->print(); + abort(); + } + } + + this->validate_ir(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_validate::visit_enter(ir_call *ir) +{ + ir_function_signature *const callee = ir->get_callee(); + + if (callee->ir_type != ir_type_function_signature) { + printf("IR called by ir_call is not ir_function_signature!\n"); + abort(); + } + + return visit_continue; +} + +void +ir_validate::validate_ir(ir_instruction *ir, void *data) +{ + struct hash_table *ht = (struct hash_table *) data; + + if (hash_table_find(ht, ir)) { + printf("Instruction node present twice in ir tree:\n"); + ir->print(); + printf("\n"); + abort(); + } + hash_table_insert(ht, ir, ir); +} + +void +check_node_type(ir_instruction *ir, void *data) +{ + (void) data; + + if (ir->ir_type <= ir_type_unset || ir->ir_type >= ir_type_max) { + printf("Instruction node with unset type\n"); + ir->print(); printf("\n"); + } + assert(ir->type != glsl_type::error_type); +} + +void +validate_ir_tree(exec_list *instructions) +{ + ir_validate v; + + v.run(instructions); + + foreach_iter(exec_list_iterator, iter, *instructions) { + ir_instruction *ir = (ir_instruction *)iter.get(); + + visit_tree(ir, check_node_type, NULL); + } +} diff --git a/src/glsl/ir_variable.cpp b/src/glsl/ir_variable.cpp new file mode 100644 index 0000000..5b8281e --- /dev/null +++ b/src/glsl/ir_variable.cpp @@ -0,0 +1,508 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "ir.h" +#include "glsl_parser_extras.h" +#include "glsl_symbol_table.h" +#include "builtin_variables.h" + +static void generate_ARB_draw_buffers_variables(exec_list *, + struct _mesa_glsl_parse_state *, + bool, _mesa_glsl_parser_targets); + +static ir_variable * +add_variable(const char *name, enum ir_variable_mode mode, int slot, + const glsl_type *type, exec_list *instructions, + glsl_symbol_table *symtab) +{ + ir_variable *var = new(symtab) ir_variable(type, name, mode); + + switch (var->mode) { + case ir_var_auto: + case ir_var_in: + case ir_var_uniform: + var->read_only = true; + break; + case ir_var_inout: + case ir_var_out: + break; + default: + assert(0); + break; + } + + var->location = slot; + var->explicit_location = (slot >= 0); + + /* Once the variable is created an initialized, add it to the symbol table + * and add the declaration to the IR stream. + */ + instructions->push_tail(var); + + symtab->add_variable(var); + return var; +} + +static ir_variable * +add_uniform(exec_list *instructions, + struct _mesa_glsl_parse_state *state, + const char *name, const glsl_type *type) +{ + return add_variable(name, ir_var_uniform, -1, type, instructions, + state->symbols); +} + +static void +add_builtin_variable(const builtin_variable *proto, exec_list *instructions, + glsl_symbol_table *symtab) +{ + /* Create a new variable declaration from the description supplied by + * the caller. + */ + const glsl_type *const type = symtab->get_type(proto->type); + + assert(type != NULL); + + add_variable(proto->name, proto->mode, proto->slot, type, instructions, + symtab); +} + +static void +add_builtin_constant(exec_list *instructions, + struct _mesa_glsl_parse_state *state, + const char *name, int value) +{ + ir_variable *const var = add_variable(name, ir_var_auto, + -1, glsl_type::int_type, + instructions, state->symbols); + var->constant_value = new(var) ir_constant(value); +} + +/* Several constants in GLSL ES have different names than normal desktop GLSL. + * Therefore, this function should only be called on the ES path. + */ +static void +generate_100ES_uniforms(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + add_builtin_constant(instructions, state, "gl_MaxVertexAttribs", + state->Const.MaxVertexAttribs); + add_builtin_constant(instructions, state, "gl_MaxVertexUniformVectors", + state->Const.MaxVertexUniformComponents); + add_builtin_constant(instructions, state, "gl_MaxVaryingVectors", + state->Const.MaxVaryingFloats / 4); + add_builtin_constant(instructions, state, "gl_MaxVertexTextureImageUnits", + state->Const.MaxVertexTextureImageUnits); + add_builtin_constant(instructions, state, "gl_MaxCombinedTextureImageUnits", + state->Const.MaxCombinedTextureImageUnits); + add_builtin_constant(instructions, state, "gl_MaxTextureImageUnits", + state->Const.MaxTextureImageUnits); + add_builtin_constant(instructions, state, "gl_MaxFragmentUniformVectors", + state->Const.MaxFragmentUniformComponents); + + add_uniform(instructions, state, "gl_DepthRange", + state->symbols->get_type("gl_DepthRangeParameters")); +} + +static void +generate_110_uniforms(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + for (unsigned i = 0 + ; i < Elements(builtin_110_deprecated_uniforms) + ; i++) { + add_builtin_variable(& builtin_110_deprecated_uniforms[i], + instructions, state->symbols); + } + + add_builtin_constant(instructions, state, "gl_MaxLights", + state->Const.MaxLights); + add_builtin_constant(instructions, state, "gl_MaxClipPlanes", + state->Const.MaxClipPlanes); + add_builtin_constant(instructions, state, "gl_MaxTextureUnits", + state->Const.MaxTextureUnits); + add_builtin_constant(instructions, state, "gl_MaxTextureCoords", + state->Const.MaxTextureCoords); + add_builtin_constant(instructions, state, "gl_MaxVertexAttribs", + state->Const.MaxVertexAttribs); + add_builtin_constant(instructions, state, "gl_MaxVertexUniformComponents", + state->Const.MaxVertexUniformComponents); + add_builtin_constant(instructions, state, "gl_MaxVaryingFloats", + state->Const.MaxVaryingFloats); + add_builtin_constant(instructions, state, "gl_MaxVertexTextureImageUnits", + state->Const.MaxVertexTextureImageUnits); + add_builtin_constant(instructions, state, "gl_MaxCombinedTextureImageUnits", + state->Const.MaxCombinedTextureImageUnits); + add_builtin_constant(instructions, state, "gl_MaxTextureImageUnits", + state->Const.MaxTextureImageUnits); + add_builtin_constant(instructions, state, "gl_MaxFragmentUniformComponents", + state->Const.MaxFragmentUniformComponents); + + const glsl_type *const mat4_array_type = + glsl_type::get_array_instance(glsl_type::mat4_type, + state->Const.MaxTextureCoords); + + add_uniform(instructions, state, "gl_TextureMatrix", mat4_array_type); + add_uniform(instructions, state, "gl_TextureMatrixInverse", mat4_array_type); + add_uniform(instructions, state, "gl_TextureMatrixTranspose", mat4_array_type); + add_uniform(instructions, state, "gl_TextureMatrixInverseTranspose", mat4_array_type); + + add_uniform(instructions, state, "gl_DepthRange", + state->symbols->get_type("gl_DepthRangeParameters")); + + add_uniform(instructions, state, "gl_ClipPlane", + glsl_type::get_array_instance(glsl_type::vec4_type, + state->Const.MaxClipPlanes)); + add_uniform(instructions, state, "gl_Point", + state->symbols->get_type("gl_PointParameters")); + + const glsl_type *const material_parameters_type = + state->symbols->get_type("gl_MaterialParameters"); + add_uniform(instructions, state, "gl_FrontMaterial", material_parameters_type); + add_uniform(instructions, state, "gl_BackMaterial", material_parameters_type); + + const glsl_type *const light_source_array_type = + glsl_type::get_array_instance(state->symbols->get_type("gl_LightSourceParameters"), state->Const.MaxLights); + + add_uniform(instructions, state, "gl_LightSource", light_source_array_type); + + const glsl_type *const light_model_products_type = + state->symbols->get_type("gl_LightModelProducts"); + add_uniform(instructions, state, "gl_FrontLightModelProduct", + light_model_products_type); + add_uniform(instructions, state, "gl_BackLightModelProduct", + light_model_products_type); + + const glsl_type *const light_products_type = + glsl_type::get_array_instance(state->symbols->get_type("gl_LightProducts"), + state->Const.MaxLights); + add_uniform(instructions, state, "gl_FrontLightProduct", light_products_type); + add_uniform(instructions, state, "gl_BackLightProduct", light_products_type); + + add_uniform(instructions, state, "gl_TextureEnvColor", + glsl_type::get_array_instance(glsl_type::vec4_type, + state->Const.MaxTextureUnits)); + + const glsl_type *const texcoords_vec4 = + glsl_type::get_array_instance(glsl_type::vec4_type, + state->Const.MaxTextureCoords); + add_uniform(instructions, state, "gl_EyePlaneS", texcoords_vec4); + add_uniform(instructions, state, "gl_EyePlaneT", texcoords_vec4); + add_uniform(instructions, state, "gl_EyePlaneR", texcoords_vec4); + add_uniform(instructions, state, "gl_EyePlaneQ", texcoords_vec4); + add_uniform(instructions, state, "gl_ObjectPlaneS", texcoords_vec4); + add_uniform(instructions, state, "gl_ObjectPlaneT", texcoords_vec4); + add_uniform(instructions, state, "gl_ObjectPlaneR", texcoords_vec4); + add_uniform(instructions, state, "gl_ObjectPlaneQ", texcoords_vec4); + + add_uniform(instructions, state, "gl_Fog", + state->symbols->get_type("gl_FogParameters")); +} + +/* This function should only be called for ES, not desktop GL. */ +static void +generate_100ES_vs_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) { + add_builtin_variable(& builtin_core_vs_variables[i], + instructions, state->symbols); + } + + generate_100ES_uniforms(instructions, state); + + generate_ARB_draw_buffers_variables(instructions, state, false, + vertex_shader); +} + + +static void +generate_110_vs_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) { + add_builtin_variable(& builtin_core_vs_variables[i], + instructions, state->symbols); + } + + for (unsigned i = 0 + ; i < Elements(builtin_110_deprecated_vs_variables) + ; i++) { + add_builtin_variable(& builtin_110_deprecated_vs_variables[i], + instructions, state->symbols); + } + generate_110_uniforms(instructions, state); + + /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec: + * + * "As with all arrays, indices used to subscript gl_TexCoord must + * either be an integral constant expressions, or this array must be + * re-declared by the shader with a size. The size can be at most + * gl_MaxTextureCoords. Using indexes close to 0 may aid the + * implementation in preserving varying resources." + */ + const glsl_type *const vec4_array_type = + glsl_type::get_array_instance(glsl_type::vec4_type, 0); + + add_variable("gl_TexCoord", ir_var_out, VERT_RESULT_TEX0, vec4_array_type, + instructions, state->symbols); + + generate_ARB_draw_buffers_variables(instructions, state, false, + vertex_shader); +} + + +static void +generate_120_vs_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + /* GLSL version 1.20 did not add any built-in variables in the vertex + * shader. + */ + generate_110_vs_variables(instructions, state); +} + + +static void +generate_130_vs_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + generate_120_vs_variables(instructions, state); + + for (unsigned i = 0; i < Elements(builtin_130_vs_variables); i++) { + add_builtin_variable(& builtin_130_vs_variables[i], + instructions, state->symbols); + } + + const glsl_type *const clip_distance_array_type = + glsl_type::get_array_instance(glsl_type::float_type, + state->Const.MaxClipPlanes); + + /* FINISHME: gl_ClipDistance needs a real location assigned. */ + add_variable("gl_ClipDistance", ir_var_out, -1, clip_distance_array_type, + instructions, state->symbols); + +} + + +static void +initialize_vs_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + + switch (state->language_version) { + case 100: + generate_100ES_vs_variables(instructions, state); + break; + case 110: + generate_110_vs_variables(instructions, state); + break; + case 120: + generate_120_vs_variables(instructions, state); + break; + case 130: + generate_130_vs_variables(instructions, state); + break; + } +} + +/* This function should only be called for ES, not desktop GL. */ +static void +generate_100ES_fs_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) { + add_builtin_variable(& builtin_core_fs_variables[i], + instructions, state->symbols); + } + + for (unsigned i = 0; i < Elements(builtin_100ES_fs_variables); i++) { + add_builtin_variable(& builtin_100ES_fs_variables[i], + instructions, state->symbols); + } + + generate_100ES_uniforms(instructions, state); + + generate_ARB_draw_buffers_variables(instructions, state, false, + fragment_shader); +} + +static void +generate_110_fs_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) { + add_builtin_variable(& builtin_core_fs_variables[i], + instructions, state->symbols); + } + + for (unsigned i = 0; i < Elements(builtin_110_fs_variables); i++) { + add_builtin_variable(& builtin_110_fs_variables[i], + instructions, state->symbols); + } + + for (unsigned i = 0 + ; i < Elements(builtin_110_deprecated_fs_variables) + ; i++) { + add_builtin_variable(& builtin_110_deprecated_fs_variables[i], + instructions, state->symbols); + } + generate_110_uniforms(instructions, state); + + /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec: + * + * "As with all arrays, indices used to subscript gl_TexCoord must + * either be an integral constant expressions, or this array must be + * re-declared by the shader with a size. The size can be at most + * gl_MaxTextureCoords. Using indexes close to 0 may aid the + * implementation in preserving varying resources." + */ + const glsl_type *const vec4_array_type = + glsl_type::get_array_instance(glsl_type::vec4_type, 0); + + add_variable("gl_TexCoord", ir_var_in, FRAG_ATTRIB_TEX0, vec4_array_type, + instructions, state->symbols); + + generate_ARB_draw_buffers_variables(instructions, state, false, + fragment_shader); +} + + +static void +generate_ARB_draw_buffers_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state, + bool warn, _mesa_glsl_parser_targets target) +{ + /* gl_MaxDrawBuffers is available in all shader stages. + */ + ir_variable *const mdb = + add_variable("gl_MaxDrawBuffers", ir_var_auto, -1, + glsl_type::int_type, instructions, state->symbols); + + if (warn) + mdb->warn_extension = "GL_ARB_draw_buffers"; + + mdb->constant_value = new(mdb) + ir_constant(int(state->Const.MaxDrawBuffers)); + + + /* gl_FragData is only available in the fragment shader. + */ + if (target == fragment_shader) { + const glsl_type *const vec4_array_type = + glsl_type::get_array_instance(glsl_type::vec4_type, + state->Const.MaxDrawBuffers); + + ir_variable *const fd = + add_variable("gl_FragData", ir_var_out, FRAG_RESULT_DATA0, + vec4_array_type, instructions, state->symbols); + + if (warn) + fd->warn_extension = "GL_ARB_draw_buffers"; + } +} + +static void +generate_ARB_shader_stencil_export_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state, + bool warn) +{ + /* gl_FragStencilRefARB is only available in the fragment shader. + */ + ir_variable *const fd = + add_variable("gl_FragStencilRefARB", ir_var_out, FRAG_RESULT_STENCIL, + glsl_type::int_type, instructions, state->symbols); + + if (warn) + fd->warn_extension = "GL_ARB_shader_stencil_export"; +} + +static void +generate_120_fs_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + generate_110_fs_variables(instructions, state); + + for (unsigned i = 0 + ; i < Elements(builtin_120_fs_variables) + ; i++) { + add_builtin_variable(& builtin_120_fs_variables[i], + instructions, state->symbols); + } +} + +static void +generate_130_fs_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + generate_120_fs_variables(instructions, state); + + const glsl_type *const clip_distance_array_type = + glsl_type::get_array_instance(glsl_type::float_type, + state->Const.MaxClipPlanes); + + /* FINISHME: gl_ClipDistance needs a real location assigned. */ + add_variable("gl_ClipDistance", ir_var_in, -1, clip_distance_array_type, + instructions, state->symbols); +} + +static void +initialize_fs_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + + switch (state->language_version) { + case 100: + generate_100ES_fs_variables(instructions, state); + break; + case 110: + generate_110_fs_variables(instructions, state); + break; + case 120: + generate_120_fs_variables(instructions, state); + break; + case 130: + generate_130_fs_variables(instructions, state); + break; + } + + if (state->ARB_shader_stencil_export_enable) + generate_ARB_shader_stencil_export_variables(instructions, state, + state->ARB_shader_stencil_export_warn); +} + +void +_mesa_glsl_initialize_variables(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + switch (state->target) { + case vertex_shader: + initialize_vs_variables(instructions, state); + break; + case geometry_shader: + break; + case fragment_shader: + initialize_fs_variables(instructions, state); + break; + } +} diff --git a/src/glsl/ir_variable_refcount.cpp b/src/glsl/ir_variable_refcount.cpp new file mode 100644 index 0000000..7d39abb --- /dev/null +++ b/src/glsl/ir_variable_refcount.cpp @@ -0,0 +1,113 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_variable_refcount.cpp + * + * Provides a visitor which produces a list of variables referenced, + * how many times they were referenced and assigned, and whether they + * were defined in the scope. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_variable_refcount.h" +#include "glsl_types.h" + + +// constructor +variable_entry::variable_entry(ir_variable *var) +{ + this->var = var; + assign = NULL; + assigned_count = 0; + declaration = false; + referenced_count = 0; +} + + +variable_entry * +ir_variable_refcount_visitor::get_variable_entry(ir_variable *var) +{ + assert(var); + foreach_iter(exec_list_iterator, iter, this->variable_list) { + variable_entry *entry = (variable_entry *)iter.get(); + if (entry->var == var) + return entry; + } + + variable_entry *entry = new(mem_ctx) variable_entry(var); + assert(entry->referenced_count == 0); + this->variable_list.push_tail(entry); + return entry; +} + + +ir_visitor_status +ir_variable_refcount_visitor::visit(ir_variable *ir) +{ + variable_entry *entry = this->get_variable_entry(ir); + if (entry) + entry->declaration = true; + + return visit_continue; +} + + +ir_visitor_status +ir_variable_refcount_visitor::visit(ir_dereference_variable *ir) +{ + ir_variable *const var = ir->variable_referenced(); + variable_entry *entry = this->get_variable_entry(var); + + if (entry) + entry->referenced_count++; + + return visit_continue; +} + + +ir_visitor_status +ir_variable_refcount_visitor::visit_enter(ir_function_signature *ir) +{ + /* We don't want to descend into the function parameters and + * dead-code eliminate them, so just accept the body here. + */ + visit_list_elements(this, &ir->body); + return visit_continue_with_parent; +} + + +ir_visitor_status +ir_variable_refcount_visitor::visit_leave(ir_assignment *ir) +{ + variable_entry *entry; + entry = this->get_variable_entry(ir->lhs->variable_referenced()); + if (entry) { + entry->assigned_count++; + if (entry->assign == NULL) + entry->assign = ir; + } + + return visit_continue; +} diff --git a/src/glsl/ir_variable_refcount.h b/src/glsl/ir_variable_refcount.h new file mode 100644 index 0000000..906135a --- /dev/null +++ b/src/glsl/ir_variable_refcount.h @@ -0,0 +1,78 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_variable_refcount.h + * + * Provides a visitor which produces a list of variables referenced, + * how many times they were referenced and assigned, and whether they + * were defined in the scope. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "glsl_types.h" + +class variable_entry : public exec_node +{ +public: + variable_entry(ir_variable *var); + + ir_variable *var; /* The key: the variable's pointer. */ + ir_assignment *assign; /* An assignment to the variable, if any */ + + /** Number of times the variable is referenced, including assignments. */ + unsigned referenced_count; + + /** Number of times the variable is assigned. */ + unsigned assigned_count; + + bool declaration; /* If the variable had a decl in the instruction stream */ +}; + +class ir_variable_refcount_visitor : public ir_hierarchical_visitor { +public: + ir_variable_refcount_visitor(void) + { + this->mem_ctx = ralloc_context(NULL); + this->variable_list.make_empty(); + } + + ~ir_variable_refcount_visitor(void) + { + ralloc_free(this->mem_ctx); + } + + virtual ir_visitor_status visit(ir_variable *); + virtual ir_visitor_status visit(ir_dereference_variable *); + + virtual ir_visitor_status visit_enter(ir_function_signature *); + virtual ir_visitor_status visit_leave(ir_assignment *); + + variable_entry *get_variable_entry(ir_variable *var); + + /* List of variable_entry */ + exec_list variable_list; + + void *mem_ctx; +}; diff --git a/src/glsl/ir_visitor.h b/src/glsl/ir_visitor.h new file mode 100644 index 0000000..7dd35fe --- /dev/null +++ b/src/glsl/ir_visitor.h @@ -0,0 +1,84 @@ +/* -*- c++ -*- */ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#ifndef IR_VISITOR_H +#define IR_VISITOR_H + +/** + * Abstract base class of visitors of IR instruction trees + */ +class ir_visitor { +public: + virtual ~ir_visitor() + { + /* empty */ + } + + /** + * \name Visit methods + * + * As typical for the visitor pattern, there must be one \c visit method for + * each concrete subclass of \c ir_instruction. Virtual base classes within + * the hierarchy should not have \c visit methods. + */ + /*@{*/ + virtual void visit(class ir_variable *) = 0; + virtual void visit(class ir_function_signature *) = 0; + virtual void visit(class ir_function *) = 0; + virtual void visit(class ir_expression *) = 0; + virtual void visit(class ir_texture *) = 0; + virtual void visit(class ir_swizzle *) = 0; + virtual void visit(class ir_dereference_variable *) = 0; + virtual void visit(class ir_dereference_array *) = 0; + virtual void visit(class ir_dereference_record *) = 0; + virtual void visit(class ir_assignment *) = 0; + virtual void visit(class ir_constant *) = 0; + virtual void visit(class ir_call *) = 0; + virtual void visit(class ir_return *) = 0; + virtual void visit(class ir_discard *) = 0; + virtual void visit(class ir_if *) = 0; + virtual void visit(class ir_loop *) = 0; + virtual void visit(class ir_loop_jump *) = 0; + /*@}*/ +}; + +/* NOTE: function calls may never return due to discards inside them + * This is usually not an issue, but if it is, keep it in mind + */ +class ir_control_flow_visitor : public ir_visitor { +public: + virtual void visit(class ir_variable *) {} + virtual void visit(class ir_expression *) {} + virtual void visit(class ir_texture *) {} + virtual void visit(class ir_swizzle *) {} + virtual void visit(class ir_dereference_variable *) {} + virtual void visit(class ir_dereference_array *) {} + virtual void visit(class ir_dereference_record *) {} + virtual void visit(class ir_assignment *) {} + virtual void visit(class ir_constant *) {} + virtual void visit(class ir_call *) {} +}; + +#endif /* IR_VISITOR_H */ diff --git a/src/glsl/link_functions.cpp b/src/glsl/link_functions.cpp new file mode 100644 index 0000000..256652a --- /dev/null +++ b/src/glsl/link_functions.cpp @@ -0,0 +1,276 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include + +#include "main/core.h" +#include "glsl_symbol_table.h" +#include "glsl_parser_extras.h" +#include "ir.h" +#include "program.h" +#include "program/hash_table.h" +#include "linker.h" + +static ir_function_signature * +find_matching_signature(const char *name, const exec_list *actual_parameters, + gl_shader **shader_list, unsigned num_shaders); + +class call_link_visitor : public ir_hierarchical_visitor { +public: + call_link_visitor(gl_shader_program *prog, gl_shader *linked, + gl_shader **shader_list, unsigned num_shaders) + { + this->prog = prog; + this->shader_list = shader_list; + this->num_shaders = num_shaders; + this->success = true; + this->linked = linked; + + this->locals = hash_table_ctor(0, hash_table_pointer_hash, + hash_table_pointer_compare); + } + + ~call_link_visitor() + { + hash_table_dtor(this->locals); + } + + virtual ir_visitor_status visit(ir_variable *ir) + { + hash_table_insert(locals, ir, ir); + return visit_continue; + } + + virtual ir_visitor_status visit_enter(ir_call *ir) + { + /* If ir is an ir_call from a function that was imported from another + * shader callee will point to an ir_function_signature in the original + * shader. In this case the function signature MUST NOT BE MODIFIED. + * Doing so will modify the original shader. This may prevent that + * shader from being linkable in other programs. + */ + const ir_function_signature *const callee = ir->get_callee(); + assert(callee != NULL); + const char *const name = callee->function_name(); + + /* Determine if the requested function signature already exists in the + * final linked shader. If it does, use it as the target of the call. + */ + ir_function_signature *sig = + find_matching_signature(name, &callee->parameters, &linked, 1); + if (sig != NULL) { + ir->set_callee(sig); + return visit_continue; + } + + /* Try to find the signature in one of the other shaders that is being + * linked. If it's not found there, return an error. + */ + sig = find_matching_signature(name, &ir->actual_parameters, shader_list, + num_shaders); + if (sig == NULL) { + /* FINISHME: Log the full signature of unresolved function. + */ + linker_error_printf(this->prog, "unresolved reference to function " + "`%s'\n", name); + this->success = false; + return visit_stop; + } + + /* Find the prototype information in the linked shader. Generate any + * details that may be missing. + */ + ir_function *f = linked->symbols->get_function(name); + if (f == NULL) { + f = new(linked) ir_function(name); + + /* Add the new function to the linked IR. + */ + linked->symbols->add_function(f); + linked->ir->push_head(f); + } + + ir_function_signature *linked_sig = + f->exact_matching_signature(&callee->parameters); + if (linked_sig == NULL) { + linked_sig = new(linked) ir_function_signature(callee->return_type); + f->add_signature(linked_sig); + } + + /* At this point linked_sig and called may be the same. If ir is an + * ir_call from linked then linked_sig and callee will be + * ir_function_signatures that have no definitions (is_defined is false). + */ + assert(!linked_sig->is_defined); + assert(linked_sig->body.is_empty()); + + /* Create an in-place clone of the function definition. This multistep + * process introduces some complexity here, but it has some advantages. + * The parameter list and the and function body are cloned separately. + * The clone of the parameter list is used to prime the hashtable used + * to replace variable references in the cloned body. + * + * The big advantage is that the ir_function_signature does not change. + * This means that we don't have to process the rest of the IR tree to + * patch ir_call nodes. In addition, there is no way to remove or + * replace signature stored in a function. One could easily be added, + * but this avoids the need. + */ + struct hash_table *ht = hash_table_ctor(0, hash_table_pointer_hash, + hash_table_pointer_compare); + exec_list formal_parameters; + foreach_list_const(node, &sig->parameters) { + const ir_instruction *const original = (ir_instruction *) node; + assert(const_cast(original)->as_variable()); + + ir_instruction *copy = original->clone(linked, ht); + formal_parameters.push_tail(copy); + } + + linked_sig->replace_parameters(&formal_parameters); + + foreach_list_const(node, &sig->body) { + const ir_instruction *const original = (ir_instruction *) node; + + ir_instruction *copy = original->clone(linked, ht); + linked_sig->body.push_tail(copy); + } + + linked_sig->is_defined = true; + hash_table_dtor(ht); + + /* Patch references inside the function to things outside the function + * (i.e., function calls and global variables). + */ + linked_sig->accept(this); + + ir->set_callee(linked_sig); + + return visit_continue; + } + + virtual ir_visitor_status visit(ir_dereference_variable *ir) + { + if (hash_table_find(locals, ir->var) == NULL) { + /* The non-function variable must be a global, so try to find the + * variable in the shader's symbol table. If the variable is not + * found, then it's a global that *MUST* be defined in the original + * shader. + */ + ir_variable *var = linked->symbols->get_variable(ir->var->name); + if (var == NULL) { + /* Clone the ir_variable that the dereference already has and add + * it to the linked shader. + */ + var = ir->var->clone(linked, NULL); + linked->symbols->add_variable(var); + linked->ir->push_head(var); + } else if (var->type->is_array()) { + /* It is possible to have a global array declared in multiple + * shaders without a size. The array is implicitly sized by the + * maximal access to it in *any* shader. Because of this, we + * need to track the maximal access to the array as linking pulls + * more functions in that access the array. + */ + var->max_array_access = + MAX2(var->max_array_access, ir->var->max_array_access); + + if (var->type->length == 0 && ir->var->type->length != 0) + var->type = ir->var->type; + } + + ir->var = var; + } + + return visit_continue; + } + + /** Was function linking successful? */ + bool success; + +private: + /** + * Shader program being linked + * + * This is only used for logging error messages. + */ + gl_shader_program *prog; + + /** List of shaders available for linking. */ + gl_shader **shader_list; + + /** Number of shaders available for linking. */ + unsigned num_shaders; + + /** + * Final linked shader + * + * This is used two ways. It is used to find global variables in the + * linked shader that are accessed by the function. It is also used to add + * global variables from the shader where the function originated. + */ + gl_shader *linked; + + /** + * Table of variables local to the function. + */ + hash_table *locals; +}; + + +/** + * Searches a list of shaders for a particular function definition + */ +ir_function_signature * +find_matching_signature(const char *name, const exec_list *actual_parameters, + gl_shader **shader_list, unsigned num_shaders) +{ + for (unsigned i = 0; i < num_shaders; i++) { + ir_function *const f = shader_list[i]->symbols->get_function(name); + + if (f == NULL) + continue; + + ir_function_signature *sig = f->matching_signature(actual_parameters); + + if ((sig == NULL) || !sig->is_defined) + continue; + + return sig; + } + + return NULL; +} + + +bool +link_function_calls(gl_shader_program *prog, gl_shader *main, + gl_shader **shader_list, unsigned num_shaders) +{ + call_link_visitor v(prog, main, shader_list, num_shaders); + + v.run(main->ir); + return v.success; +} diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp new file mode 100644 index 0000000..f8d8eae --- /dev/null +++ b/src/glsl/linker.cpp @@ -0,0 +1,1686 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file linker.cpp + * GLSL linker implementation + * + * Given a set of shaders that are to be linked to generate a final program, + * there are three distinct stages. + * + * In the first stage shaders are partitioned into groups based on the shader + * type. All shaders of a particular type (e.g., vertex shaders) are linked + * together. + * + * - Undefined references in each shader are resolve to definitions in + * another shader. + * - Types and qualifiers of uniforms, outputs, and global variables defined + * in multiple shaders with the same name are verified to be the same. + * - Initializers for uniforms and global variables defined + * in multiple shaders with the same name are verified to be the same. + * + * The result, in the terminology of the GLSL spec, is a set of shader + * executables for each processing unit. + * + * After the first stage is complete, a series of semantic checks are performed + * on each of the shader executables. + * + * - Each shader executable must define a \c main function. + * - Each vertex shader executable must write to \c gl_Position. + * - Each fragment shader executable must write to either \c gl_FragData or + * \c gl_FragColor. + * + * In the final stage individual shader executables are linked to create a + * complete exectuable. + * + * - Types of uniforms defined in multiple shader stages with the same name + * are verified to be the same. + * - Initializers for uniforms defined in multiple shader stages with the + * same name are verified to be the same. + * - Types and qualifiers of outputs defined in one stage are verified to + * be the same as the types and qualifiers of inputs defined with the same + * name in a later stage. + * + * \author Ian Romanick + */ +#include +#include +#include +#include + +#include "main/core.h" +#include "glsl_symbol_table.h" +#include "ir.h" +#include "program.h" +#include "program/hash_table.h" +#include "linker.h" +#include "ir_optimization.h" + +extern "C" { +#include "main/shaderobj.h" +} + +/** + * Visitor that determines whether or not a variable is ever written. + */ +class find_assignment_visitor : public ir_hierarchical_visitor { +public: + find_assignment_visitor(const char *name) + : name(name), found(false) + { + /* empty */ + } + + virtual ir_visitor_status visit_enter(ir_assignment *ir) + { + ir_variable *const var = ir->lhs->variable_referenced(); + + if (strcmp(name, var->name) == 0) { + found = true; + return visit_stop; + } + + return visit_continue_with_parent; + } + + virtual ir_visitor_status visit_enter(ir_call *ir) + { + exec_list_iterator sig_iter = ir->get_callee()->parameters.iterator(); + foreach_iter(exec_list_iterator, iter, *ir) { + ir_rvalue *param_rval = (ir_rvalue *)iter.get(); + ir_variable *sig_param = (ir_variable *)sig_iter.get(); + + if (sig_param->mode == ir_var_out || + sig_param->mode == ir_var_inout) { + ir_variable *var = param_rval->variable_referenced(); + if (var && strcmp(name, var->name) == 0) { + found = true; + return visit_stop; + } + } + sig_iter.next(); + } + + return visit_continue_with_parent; + } + + bool variable_found() + { + return found; + } + +private: + const char *name; /**< Find writes to a variable with this name. */ + bool found; /**< Was a write to the variable found? */ +}; + + +/** + * Visitor that determines whether or not a variable is ever read. + */ +class find_deref_visitor : public ir_hierarchical_visitor { +public: + find_deref_visitor(const char *name) + : name(name), found(false) + { + /* empty */ + } + + virtual ir_visitor_status visit(ir_dereference_variable *ir) + { + if (strcmp(this->name, ir->var->name) == 0) { + this->found = true; + return visit_stop; + } + + return visit_continue; + } + + bool variable_found() const + { + return this->found; + } + +private: + const char *name; /**< Find writes to a variable with this name. */ + bool found; /**< Was a write to the variable found? */ +}; + + +void +linker_error_printf(gl_shader_program *prog, const char *fmt, ...) +{ + va_list ap; + + ralloc_strcat(&prog->InfoLog, "error: "); + va_start(ap, fmt); + ralloc_vasprintf_append(&prog->InfoLog, fmt, ap); + va_end(ap); +} + + +void +invalidate_variable_locations(gl_shader *sh, enum ir_variable_mode mode, + int generic_base) +{ + foreach_list(node, sh->ir) { + ir_variable *const var = ((ir_instruction *) node)->as_variable(); + + if ((var == NULL) || (var->mode != (unsigned) mode)) + continue; + + /* Only assign locations for generic attributes / varyings / etc. + */ + if ((var->location >= generic_base) && !var->explicit_location) + var->location = -1; + } +} + + +/** + * Determine the number of attribute slots required for a particular type + * + * This code is here because it implements the language rules of a specific + * GLSL version. Since it's a property of the language and not a property of + * types in general, it doesn't really belong in glsl_type. + */ +unsigned +count_attribute_slots(const glsl_type *t) +{ + /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec: + * + * "A scalar input counts the same amount against this limit as a vec4, + * so applications may want to consider packing groups of four + * unrelated float inputs together into a vector to better utilize the + * capabilities of the underlying hardware. A matrix input will use up + * multiple locations. The number of locations used will equal the + * number of columns in the matrix." + * + * The spec does not explicitly say how arrays are counted. However, it + * should be safe to assume the total number of slots consumed by an array + * is the number of entries in the array multiplied by the number of slots + * consumed by a single element of the array. + */ + + if (t->is_array()) + return t->array_size() * count_attribute_slots(t->element_type()); + + if (t->is_matrix()) + return t->matrix_columns; + + return 1; +} + + +/** + * Verify that a vertex shader executable meets all semantic requirements + * + * \param shader Vertex shader executable to be verified + */ +bool +validate_vertex_shader_executable(struct gl_shader_program *prog, + struct gl_shader *shader) +{ + if (shader == NULL) + return true; + + find_assignment_visitor find("gl_Position"); + find.run(shader->ir); + if (!find.variable_found()) { + linker_error_printf(prog, + "vertex shader does not write to `gl_Position'\n"); + return false; + } + + return true; +} + + +/** + * Verify that a fragment shader executable meets all semantic requirements + * + * \param shader Fragment shader executable to be verified + */ +bool +validate_fragment_shader_executable(struct gl_shader_program *prog, + struct gl_shader *shader) +{ + if (shader == NULL) + return true; + + find_assignment_visitor frag_color("gl_FragColor"); + find_assignment_visitor frag_data("gl_FragData"); + + frag_color.run(shader->ir); + frag_data.run(shader->ir); + + if (frag_color.variable_found() && frag_data.variable_found()) { + linker_error_printf(prog, "fragment shader writes to both " + "`gl_FragColor' and `gl_FragData'\n"); + return false; + } + + return true; +} + + +/** + * Generate a string describing the mode of a variable + */ +static const char * +mode_string(const ir_variable *var) +{ + switch (var->mode) { + case ir_var_auto: + return (var->read_only) ? "global constant" : "global variable"; + + case ir_var_uniform: return "uniform"; + case ir_var_in: return "shader input"; + case ir_var_out: return "shader output"; + case ir_var_inout: return "shader inout"; + + case ir_var_temporary: + default: + assert(!"Should not get here."); + return "invalid variable"; + } +} + + +/** + * Perform validation of global variables used across multiple shaders + */ +bool +cross_validate_globals(struct gl_shader_program *prog, + struct gl_shader **shader_list, + unsigned num_shaders, + bool uniforms_only) +{ + /* Examine all of the uniforms in all of the shaders and cross validate + * them. + */ + glsl_symbol_table variables; + for (unsigned i = 0; i < num_shaders; i++) { + if (shader_list[i] == NULL) + continue; + + foreach_list(node, shader_list[i]->ir) { + ir_variable *const var = ((ir_instruction *) node)->as_variable(); + + if (var == NULL) + continue; + + if (uniforms_only && (var->mode != ir_var_uniform)) + continue; + + /* Don't cross validate temporaries that are at global scope. These + * will eventually get pulled into the shaders 'main'. + */ + if (var->mode == ir_var_temporary) + continue; + + /* If a global with this name has already been seen, verify that the + * new instance has the same type. In addition, if the globals have + * initializers, the values of the initializers must be the same. + */ + ir_variable *const existing = variables.get_variable(var->name); + if (existing != NULL) { + if (var->type != existing->type) { + /* Consider the types to be "the same" if both types are arrays + * of the same type and one of the arrays is implicitly sized. + * In addition, set the type of the linked variable to the + * explicitly sized array. + */ + if (var->type->is_array() + && existing->type->is_array() + && (var->type->fields.array == existing->type->fields.array) + && ((var->type->length == 0) + || (existing->type->length == 0))) { + if (var->type->length != 0) { + existing->type = var->type; + } + } else { + linker_error_printf(prog, "%s `%s' declared as type " + "`%s' and type `%s'\n", + mode_string(var), + var->name, var->type->name, + existing->type->name); + return false; + } + } + + if (var->explicit_location) { + if (existing->explicit_location + && (var->location != existing->location)) { + linker_error_printf(prog, "explicit locations for %s " + "`%s' have differing values\n", + mode_string(var), var->name); + return false; + } + + existing->location = var->location; + existing->explicit_location = true; + } + + /* FINISHME: Handle non-constant initializers. + */ + if (var->constant_value != NULL) { + if (existing->constant_value != NULL) { + if (!var->constant_value->has_value(existing->constant_value)) { + linker_error_printf(prog, "initializers for %s " + "`%s' have differing values\n", + mode_string(var), var->name); + return false; + } + } else + /* If the first-seen instance of a particular uniform did not + * have an initializer but a later instance does, copy the + * initializer to the version stored in the symbol table. + */ + /* FINISHME: This is wrong. The constant_value field should + * FINISHME: not be modified! Imagine a case where a shader + * FINISHME: without an initializer is linked in two different + * FINISHME: programs with shaders that have differing + * FINISHME: initializers. Linking with the first will + * FINISHME: modify the shader, and linking with the second + * FINISHME: will fail. + */ + existing->constant_value = + var->constant_value->clone(ralloc_parent(existing), NULL); + } + + if (existing->invariant != var->invariant) { + linker_error_printf(prog, "declarations for %s `%s' have " + "mismatching invariant qualifiers\n", + mode_string(var), var->name); + return false; + } + if (existing->centroid != var->centroid) { + linker_error_printf(prog, "declarations for %s `%s' have " + "mismatching centroid qualifiers\n", + mode_string(var), var->name); + return false; + } + } else + variables.add_variable(var); + } + } + + return true; +} + + +/** + * Perform validation of uniforms used across multiple shader stages + */ +bool +cross_validate_uniforms(struct gl_shader_program *prog) +{ + return cross_validate_globals(prog, prog->_LinkedShaders, + MESA_SHADER_TYPES, true); +} + + +/** + * Validate that outputs from one stage match inputs of another + */ +bool +cross_validate_outputs_to_inputs(struct gl_shader_program *prog, + gl_shader *producer, gl_shader *consumer) +{ + glsl_symbol_table parameters; + /* FINISHME: Figure these out dynamically. */ + const char *const producer_stage = "vertex"; + const char *const consumer_stage = "fragment"; + + /* Find all shader outputs in the "producer" stage. + */ + foreach_list(node, producer->ir) { + ir_variable *const var = ((ir_instruction *) node)->as_variable(); + + /* FINISHME: For geometry shaders, this should also look for inout + * FINISHME: variables. + */ + if ((var == NULL) || (var->mode != ir_var_out)) + continue; + + parameters.add_variable(var); + } + + + /* Find all shader inputs in the "consumer" stage. Any variables that have + * matching outputs already in the symbol table must have the same type and + * qualifiers. + */ + foreach_list(node, consumer->ir) { + ir_variable *const input = ((ir_instruction *) node)->as_variable(); + + /* FINISHME: For geometry shaders, this should also look for inout + * FINISHME: variables. + */ + if ((input == NULL) || (input->mode != ir_var_in)) + continue; + + ir_variable *const output = parameters.get_variable(input->name); + if (output != NULL) { + /* Check that the types match between stages. + */ + if (input->type != output->type) { + /* There is a bit of a special case for gl_TexCoord. This + * built-in is unsized by default. Appliations that variable + * access it must redeclare it with a size. There is some + * language in the GLSL spec that implies the fragment shader + * and vertex shader do not have to agree on this size. Other + * driver behave this way, and one or two applications seem to + * rely on it. + * + * Neither declaration needs to be modified here because the array + * sizes are fixed later when update_array_sizes is called. + * + * From page 48 (page 54 of the PDF) of the GLSL 1.10 spec: + * + * "Unlike user-defined varying variables, the built-in + * varying variables don't have a strict one-to-one + * correspondence between the vertex language and the + * fragment language." + */ + if (!output->type->is_array() + || (strncmp("gl_", output->name, 3) != 0)) { + linker_error_printf(prog, + "%s shader output `%s' declared as " + "type `%s', but %s shader input declared " + "as type `%s'\n", + producer_stage, output->name, + output->type->name, + consumer_stage, input->type->name); + return false; + } + } + + /* Check that all of the qualifiers match between stages. + */ + if (input->centroid != output->centroid) { + linker_error_printf(prog, + "%s shader output `%s' %s centroid qualifier, " + "but %s shader input %s centroid qualifier\n", + producer_stage, + output->name, + (output->centroid) ? "has" : "lacks", + consumer_stage, + (input->centroid) ? "has" : "lacks"); + return false; + } + + if (input->invariant != output->invariant) { + linker_error_printf(prog, + "%s shader output `%s' %s invariant qualifier, " + "but %s shader input %s invariant qualifier\n", + producer_stage, + output->name, + (output->invariant) ? "has" : "lacks", + consumer_stage, + (input->invariant) ? "has" : "lacks"); + return false; + } + + if (input->interpolation != output->interpolation) { + linker_error_printf(prog, + "%s shader output `%s' specifies %s " + "interpolation qualifier, " + "but %s shader input specifies %s " + "interpolation qualifier\n", + producer_stage, + output->name, + output->interpolation_string(), + consumer_stage, + input->interpolation_string()); + return false; + } + } + } + + return true; +} + + +/** + * Populates a shaders symbol table with all global declarations + */ +static void +populate_symbol_table(gl_shader *sh) +{ + sh->symbols = new(sh) glsl_symbol_table; + + foreach_list(node, sh->ir) { + ir_instruction *const inst = (ir_instruction *) node; + ir_variable *var; + ir_function *func; + + if ((func = inst->as_function()) != NULL) { + sh->symbols->add_function(func); + } else if ((var = inst->as_variable()) != NULL) { + sh->symbols->add_variable(var); + } + } +} + + +/** + * Remap variables referenced in an instruction tree + * + * This is used when instruction trees are cloned from one shader and placed in + * another. These trees will contain references to \c ir_variable nodes that + * do not exist in the target shader. This function finds these \c ir_variable + * references and replaces the references with matching variables in the target + * shader. + * + * If there is no matching variable in the target shader, a clone of the + * \c ir_variable is made and added to the target shader. The new variable is + * added to \b both the instruction stream and the symbol table. + * + * \param inst IR tree that is to be processed. + * \param symbols Symbol table containing global scope symbols in the + * linked shader. + * \param instructions Instruction stream where new variable declarations + * should be added. + */ +void +remap_variables(ir_instruction *inst, struct gl_shader *target, + hash_table *temps) +{ + class remap_visitor : public ir_hierarchical_visitor { + public: + remap_visitor(struct gl_shader *target, + hash_table *temps) + { + this->target = target; + this->symbols = target->symbols; + this->instructions = target->ir; + this->temps = temps; + } + + virtual ir_visitor_status visit(ir_dereference_variable *ir) + { + if (ir->var->mode == ir_var_temporary) { + ir_variable *var = (ir_variable *) hash_table_find(temps, ir->var); + + assert(var != NULL); + ir->var = var; + return visit_continue; + } + + ir_variable *const existing = + this->symbols->get_variable(ir->var->name); + if (existing != NULL) + ir->var = existing; + else { + ir_variable *copy = ir->var->clone(this->target, NULL); + + this->symbols->add_variable(copy); + this->instructions->push_head(copy); + ir->var = copy; + } + + return visit_continue; + } + + private: + struct gl_shader *target; + glsl_symbol_table *symbols; + exec_list *instructions; + hash_table *temps; + }; + + remap_visitor v(target, temps); + + inst->accept(&v); +} + + +/** + * Move non-declarations from one instruction stream to another + * + * The intended usage pattern of this function is to pass the pointer to the + * head sentinel of a list (i.e., a pointer to the list cast to an \c exec_node + * pointer) for \c last and \c false for \c make_copies on the first + * call. Successive calls pass the return value of the previous call for + * \c last and \c true for \c make_copies. + * + * \param instructions Source instruction stream + * \param last Instruction after which new instructions should be + * inserted in the target instruction stream + * \param make_copies Flag selecting whether instructions in \c instructions + * should be copied (via \c ir_instruction::clone) into the + * target list or moved. + * + * \return + * The new "last" instruction in the target instruction stream. This pointer + * is suitable for use as the \c last parameter of a later call to this + * function. + */ +exec_node * +move_non_declarations(exec_list *instructions, exec_node *last, + bool make_copies, gl_shader *target) +{ + hash_table *temps = NULL; + + if (make_copies) + temps = hash_table_ctor(0, hash_table_pointer_hash, + hash_table_pointer_compare); + + foreach_list_safe(node, instructions) { + ir_instruction *inst = (ir_instruction *) node; + + if (inst->as_function()) + continue; + + ir_variable *var = inst->as_variable(); + if ((var != NULL) && (var->mode != ir_var_temporary)) + continue; + + assert(inst->as_assignment() + || ((var != NULL) && (var->mode == ir_var_temporary))); + + if (make_copies) { + inst = inst->clone(target, NULL); + + if (var != NULL) + hash_table_insert(temps, inst, var); + else + remap_variables(inst, target, temps); + } else { + inst->remove(); + } + + last->insert_after(inst); + last = inst; + } + + if (make_copies) + hash_table_dtor(temps); + + return last; +} + +/** + * Get the function signature for main from a shader + */ +static ir_function_signature * +get_main_function_signature(gl_shader *sh) +{ + ir_function *const f = sh->symbols->get_function("main"); + if (f != NULL) { + exec_list void_parameters; + + /* Look for the 'void main()' signature and ensure that it's defined. + * This keeps the linker from accidentally pick a shader that just + * contains a prototype for main. + * + * We don't have to check for multiple definitions of main (in multiple + * shaders) because that would have already been caught above. + */ + ir_function_signature *sig = f->matching_signature(&void_parameters); + if ((sig != NULL) && sig->is_defined) { + return sig; + } + } + + return NULL; +} + + +/** + * Combine a group of shaders for a single stage to generate a linked shader + * + * \note + * If this function is supplied a single shader, it is cloned, and the new + * shader is returned. + */ +static struct gl_shader * +link_intrastage_shaders(void *mem_ctx, + struct gl_context *ctx, + struct gl_shader_program *prog, + struct gl_shader **shader_list, + unsigned num_shaders) +{ + /* Check that global variables defined in multiple shaders are consistent. + */ + if (!cross_validate_globals(prog, shader_list, num_shaders, false)) + return NULL; + + /* Check that there is only a single definition of each function signature + * across all shaders. + */ + for (unsigned i = 0; i < (num_shaders - 1); i++) { + foreach_list(node, shader_list[i]->ir) { + ir_function *const f = ((ir_instruction *) node)->as_function(); + + if (f == NULL) + continue; + + for (unsigned j = i + 1; j < num_shaders; j++) { + ir_function *const other = + shader_list[j]->symbols->get_function(f->name); + + /* If the other shader has no function (and therefore no function + * signatures) with the same name, skip to the next shader. + */ + if (other == NULL) + continue; + + foreach_iter (exec_list_iterator, iter, *f) { + ir_function_signature *sig = + (ir_function_signature *) iter.get(); + + if (!sig->is_defined || sig->is_builtin) + continue; + + ir_function_signature *other_sig = + other->exact_matching_signature(& sig->parameters); + + if ((other_sig != NULL) && other_sig->is_defined + && !other_sig->is_builtin) { + linker_error_printf(prog, + "function `%s' is multiply defined", + f->name); + return NULL; + } + } + } + } + } + + /* Find the shader that defines main, and make a clone of it. + * + * Starting with the clone, search for undefined references. If one is + * found, find the shader that defines it. Clone the reference and add + * it to the shader. Repeat until there are no undefined references or + * until a reference cannot be resolved. + */ + gl_shader *main = NULL; + for (unsigned i = 0; i < num_shaders; i++) { + if (get_main_function_signature(shader_list[i]) != NULL) { + main = shader_list[i]; + break; + } + } + + if (main == NULL) { + linker_error_printf(prog, "%s shader lacks `main'\n", + (shader_list[0]->Type == GL_VERTEX_SHADER) + ? "vertex" : "fragment"); + return NULL; + } + + gl_shader *linked = ctx->Driver.NewShader(NULL, 0, main->Type); + linked->ir = new(linked) exec_list; + clone_ir_list(mem_ctx, linked->ir, main->ir); + + populate_symbol_table(linked); + + /* The a pointer to the main function in the final linked shader (i.e., the + * copy of the original shader that contained the main function). + */ + ir_function_signature *const main_sig = get_main_function_signature(linked); + + /* Move any instructions other than variable declarations or function + * declarations into main. + */ + exec_node *insertion_point = + move_non_declarations(linked->ir, (exec_node *) &main_sig->body, false, + linked); + + for (unsigned i = 0; i < num_shaders; i++) { + if (shader_list[i] == main) + continue; + + insertion_point = move_non_declarations(shader_list[i]->ir, + insertion_point, true, linked); + } + + /* Resolve initializers for global variables in the linked shader. + */ + unsigned num_linking_shaders = num_shaders; + for (unsigned i = 0; i < num_shaders; i++) + num_linking_shaders += shader_list[i]->num_builtins_to_link; + + gl_shader **linking_shaders = + (gl_shader **) calloc(num_linking_shaders, sizeof(gl_shader *)); + + memcpy(linking_shaders, shader_list, + sizeof(linking_shaders[0]) * num_shaders); + + unsigned idx = num_shaders; + for (unsigned i = 0; i < num_shaders; i++) { + memcpy(&linking_shaders[idx], shader_list[i]->builtins_to_link, + sizeof(linking_shaders[0]) * shader_list[i]->num_builtins_to_link); + idx += shader_list[i]->num_builtins_to_link; + } + + assert(idx == num_linking_shaders); + + if (!link_function_calls(prog, linked, linking_shaders, + num_linking_shaders)) { + ctx->Driver.DeleteShader(ctx, linked); + linked = NULL; + } + + free(linking_shaders); + + /* Make a pass over all variable declarations to ensure that arrays with + * unspecified sizes have a size specified. The size is inferred from the + * max_array_access field. + */ + if (linked != NULL) { + class array_sizing_visitor : public ir_hierarchical_visitor { + public: + virtual ir_visitor_status visit(ir_variable *var) + { + if (var->type->is_array() && (var->type->length == 0)) { + const glsl_type *type = + glsl_type::get_array_instance(var->type->fields.array, + var->max_array_access + 1); + + assert(type != NULL); + var->type = type; + } + + return visit_continue; + } + } v; + + v.run(linked->ir); + } + + return linked; +} + + +struct uniform_node { + exec_node link; + struct gl_uniform *u; + unsigned slots; +}; + +/** + * Update the sizes of linked shader uniform arrays to the maximum + * array index used. + * + * From page 81 (page 95 of the PDF) of the OpenGL 2.1 spec: + * + * If one or more elements of an array are active, + * GetActiveUniform will return the name of the array in name, + * subject to the restrictions listed above. The type of the array + * is returned in type. The size parameter contains the highest + * array element index used, plus one. The compiler or linker + * determines the highest index used. There will be only one + * active uniform reported by the GL per uniform array. + + */ +static void +update_array_sizes(struct gl_shader_program *prog) +{ + for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { + if (prog->_LinkedShaders[i] == NULL) + continue; + + foreach_list(node, prog->_LinkedShaders[i]->ir) { + ir_variable *const var = ((ir_instruction *) node)->as_variable(); + + if ((var == NULL) || (var->mode != ir_var_uniform && + var->mode != ir_var_in && + var->mode != ir_var_out) || + !var->type->is_array()) + continue; + + unsigned int size = var->max_array_access; + for (unsigned j = 0; j < MESA_SHADER_TYPES; j++) { + if (prog->_LinkedShaders[j] == NULL) + continue; + + foreach_list(node2, prog->_LinkedShaders[j]->ir) { + ir_variable *other_var = ((ir_instruction *) node2)->as_variable(); + if (!other_var) + continue; + + if (strcmp(var->name, other_var->name) == 0 && + other_var->max_array_access > size) { + size = other_var->max_array_access; + } + } + } + + if (size + 1 != var->type->fields.array->length) { + var->type = glsl_type::get_array_instance(var->type->fields.array, + size + 1); + /* FINISHME: We should update the types of array + * dereferences of this variable now. + */ + } + } + } +} + +static void +add_uniform(void *mem_ctx, exec_list *uniforms, struct hash_table *ht, + const char *name, const glsl_type *type, GLenum shader_type, + unsigned *next_shader_pos, unsigned *total_uniforms) +{ + if (type->is_record()) { + for (unsigned int i = 0; i < type->length; i++) { + const glsl_type *field_type = type->fields.structure[i].type; + char *field_name = ralloc_asprintf(mem_ctx, "%s.%s", name, + type->fields.structure[i].name); + + add_uniform(mem_ctx, uniforms, ht, field_name, field_type, + shader_type, next_shader_pos, total_uniforms); + } + } else { + uniform_node *n = (uniform_node *) hash_table_find(ht, name); + unsigned int vec4_slots; + const glsl_type *array_elem_type = NULL; + + if (type->is_array()) { + array_elem_type = type->fields.array; + /* Array of structures. */ + if (array_elem_type->is_record()) { + for (unsigned int i = 0; i < type->length; i++) { + char *elem_name = ralloc_asprintf(mem_ctx, "%s[%d]", name, i); + add_uniform(mem_ctx, uniforms, ht, elem_name, array_elem_type, + shader_type, next_shader_pos, total_uniforms); + } + return; + } + } + + /* Fix the storage size of samplers at 1 vec4 each. Be sure to pad out + * vectors to vec4 slots. + */ + if (type->is_array()) { + if (array_elem_type->is_sampler()) + vec4_slots = type->length; + else + vec4_slots = type->length * array_elem_type->matrix_columns; + } else if (type->is_sampler()) { + vec4_slots = 1; + } else { + vec4_slots = type->matrix_columns; + } + + if (n == NULL) { + n = (uniform_node *) calloc(1, sizeof(struct uniform_node)); + n->u = (gl_uniform *) calloc(1, sizeof(struct gl_uniform)); + n->slots = vec4_slots; + + n->u->Name = strdup(name); + n->u->Type = type; + n->u->VertPos = -1; + n->u->FragPos = -1; + n->u->GeomPos = -1; + (*total_uniforms)++; + + hash_table_insert(ht, n, name); + uniforms->push_tail(& n->link); + } + + switch (shader_type) { + case GL_VERTEX_SHADER: + n->u->VertPos = *next_shader_pos; + break; + case GL_FRAGMENT_SHADER: + n->u->FragPos = *next_shader_pos; + break; + case GL_GEOMETRY_SHADER: + n->u->GeomPos = *next_shader_pos; + break; + } + + (*next_shader_pos) += vec4_slots; + } +} + +void +assign_uniform_locations(struct gl_shader_program *prog) +{ + /* */ + exec_list uniforms; + unsigned total_uniforms = 0; + hash_table *ht = hash_table_ctor(32, hash_table_string_hash, + hash_table_string_compare); + void *mem_ctx = ralloc_context(NULL); + + for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { + if (prog->_LinkedShaders[i] == NULL) + continue; + + unsigned next_position = 0; + + foreach_list(node, prog->_LinkedShaders[i]->ir) { + ir_variable *const var = ((ir_instruction *) node)->as_variable(); + + if ((var == NULL) || (var->mode != ir_var_uniform)) + continue; + + if (strncmp(var->name, "gl_", 3) == 0) { + /* At the moment, we don't allocate uniform locations for + * builtin uniforms. It's permitted by spec, and we'll + * likely switch to doing that at some point, but not yet. + */ + continue; + } + + var->location = next_position; + add_uniform(mem_ctx, &uniforms, ht, var->name, var->type, + prog->_LinkedShaders[i]->Type, + &next_position, &total_uniforms); + } + } + + ralloc_free(mem_ctx); + + gl_uniform_list *ul = (gl_uniform_list *) + calloc(1, sizeof(gl_uniform_list)); + + ul->Size = total_uniforms; + ul->NumUniforms = total_uniforms; + ul->Uniforms = (gl_uniform *) calloc(total_uniforms, sizeof(gl_uniform)); + + unsigned idx = 0; + uniform_node *next; + for (uniform_node *node = (uniform_node *) uniforms.head + ; node->link.next != NULL + ; node = next) { + next = (uniform_node *) node->link.next; + + node->link.remove(); + memcpy(&ul->Uniforms[idx], node->u, sizeof(gl_uniform)); + idx++; + + free(node->u); + free(node); + } + + hash_table_dtor(ht); + + prog->Uniforms = ul; +} + + +/** + * Find a contiguous set of available bits in a bitmask + * + * \param used_mask Bits representing used (1) and unused (0) locations + * \param needed_count Number of contiguous bits needed. + * + * \return + * Base location of the available bits on success or -1 on failure. + */ +int +find_available_slots(unsigned used_mask, unsigned needed_count) +{ + unsigned needed_mask = (1 << needed_count) - 1; + const int max_bit_to_test = (8 * sizeof(used_mask)) - needed_count; + + /* The comparison to 32 is redundant, but without it GCC emits "warning: + * cannot optimize possibly infinite loops" for the loop below. + */ + if ((needed_count == 0) || (max_bit_to_test < 0) || (max_bit_to_test > 32)) + return -1; + + for (int i = 0; i <= max_bit_to_test; i++) { + if ((needed_mask & ~used_mask) == needed_mask) + return i; + + needed_mask <<= 1; + } + + return -1; +} + + +bool +assign_attribute_locations(gl_shader_program *prog, unsigned max_attribute_index) +{ + /* Mark invalid attribute locations as being used. + */ + unsigned used_locations = (max_attribute_index >= 32) + ? ~0 : ~((1 << max_attribute_index) - 1); + + gl_shader *const sh = prog->_LinkedShaders[0]; + assert(sh->Type == GL_VERTEX_SHADER); + + /* Operate in a total of four passes. + * + * 1. Invalidate the location assignments for all vertex shader inputs. + * + * 2. Assign locations for inputs that have user-defined (via + * glBindVertexAttribLocation) locatoins. + * + * 3. Sort the attributes without assigned locations by number of slots + * required in decreasing order. Fragmentation caused by attribute + * locations assigned by the application may prevent large attributes + * from having enough contiguous space. + * + * 4. Assign locations to any inputs without assigned locations. + */ + + invalidate_variable_locations(sh, ir_var_in, VERT_ATTRIB_GENERIC0); + + if (prog->Attributes != NULL) { + for (unsigned i = 0; i < prog->Attributes->NumParameters; i++) { + ir_variable *const var = + sh->symbols->get_variable(prog->Attributes->Parameters[i].Name); + + /* Note: attributes that occupy multiple slots, such as arrays or + * matrices, may appear in the attrib array multiple times. + */ + if ((var == NULL) || (var->location != -1)) + continue; + + /* From page 61 of the OpenGL 4.0 spec: + * + * "LinkProgram will fail if the attribute bindings assigned by + * BindAttribLocation do not leave not enough space to assign a + * location for an active matrix attribute or an active attribute + * array, both of which require multiple contiguous generic + * attributes." + * + * Previous versions of the spec contain similar language but omit the + * bit about attribute arrays. + * + * Page 61 of the OpenGL 4.0 spec also says: + * + * "It is possible for an application to bind more than one + * attribute name to the same location. This is referred to as + * aliasing. This will only work if only one of the aliased + * attributes is active in the executable program, or if no path + * through the shader consumes more than one attribute of a set + * of attributes aliased to the same location. A link error can + * occur if the linker determines that every path through the + * shader consumes multiple aliased attributes, but + * implementations are not required to generate an error in this + * case." + * + * These two paragraphs are either somewhat contradictory, or I don't + * fully understand one or both of them. + */ + /* FINISHME: The code as currently written does not support attribute + * FINISHME: location aliasing (see comment above). + */ + const int attr = prog->Attributes->Parameters[i].StateIndexes[0]; + const unsigned slots = count_attribute_slots(var->type); + + /* Mask representing the contiguous slots that will be used by this + * attribute. + */ + const unsigned use_mask = (1 << slots) - 1; + + /* Generate a link error if the set of bits requested for this + * attribute overlaps any previously allocated bits. + */ + if ((~(use_mask << attr) & used_locations) != used_locations) { + linker_error_printf(prog, + "insufficient contiguous attribute locations " + "available for vertex shader input `%s'", + var->name); + return false; + } + + var->location = VERT_ATTRIB_GENERIC0 + attr; + used_locations |= (use_mask << attr); + } + } + + /* Temporary storage for the set of attributes that need locations assigned. + */ + struct temp_attr { + unsigned slots; + ir_variable *var; + + /* Used below in the call to qsort. */ + static int compare(const void *a, const void *b) + { + const temp_attr *const l = (const temp_attr *) a; + const temp_attr *const r = (const temp_attr *) b; + + /* Reversed because we want a descending order sort below. */ + return r->slots - l->slots; + } + } to_assign[16]; + + unsigned num_attr = 0; + + foreach_list(node, sh->ir) { + ir_variable *const var = ((ir_instruction *) node)->as_variable(); + + if ((var == NULL) || (var->mode != ir_var_in)) + continue; + + if (var->explicit_location) { + const unsigned slots = count_attribute_slots(var->type); + const unsigned use_mask = (1 << slots) - 1; + const int attr = var->location - VERT_ATTRIB_GENERIC0; + + if ((var->location >= (int)(max_attribute_index + VERT_ATTRIB_GENERIC0)) + || (var->location < 0)) { + linker_error_printf(prog, + "invalid explicit location %d specified for " + "`%s'\n", + (var->location < 0) ? var->location : attr, + var->name); + return false; + } else if (var->location >= VERT_ATTRIB_GENERIC0) { + used_locations |= (use_mask << attr); + } + } + + /* The location was explicitly assigned, nothing to do here. + */ + if (var->location != -1) + continue; + + to_assign[num_attr].slots = count_attribute_slots(var->type); + to_assign[num_attr].var = var; + num_attr++; + } + + /* If all of the attributes were assigned locations by the application (or + * are built-in attributes with fixed locations), return early. This should + * be the common case. + */ + if (num_attr == 0) + return true; + + qsort(to_assign, num_attr, sizeof(to_assign[0]), temp_attr::compare); + + /* VERT_ATTRIB_GENERIC0 is a psdueo-alias for VERT_ATTRIB_POS. It can only + * be explicitly assigned by via glBindAttribLocation. Mark it as reserved + * to prevent it from being automatically allocated below. + */ + find_deref_visitor find("gl_Vertex"); + find.run(sh->ir); + if (find.variable_found()) + used_locations |= (1 << 0); + + for (unsigned i = 0; i < num_attr; i++) { + /* Mask representing the contiguous slots that will be used by this + * attribute. + */ + const unsigned use_mask = (1 << to_assign[i].slots) - 1; + + int location = find_available_slots(used_locations, to_assign[i].slots); + + if (location < 0) { + linker_error_printf(prog, + "insufficient contiguous attribute locations " + "available for vertex shader input `%s'", + to_assign[i].var->name); + return false; + } + + to_assign[i].var->location = VERT_ATTRIB_GENERIC0 + location; + used_locations |= (use_mask << location); + } + + return true; +} + + +/** + * Demote shader inputs and outputs that are not used in other stages + */ +void +demote_shader_inputs_and_outputs(gl_shader *sh, enum ir_variable_mode mode) +{ + foreach_list(node, sh->ir) { + ir_variable *const var = ((ir_instruction *) node)->as_variable(); + + if ((var == NULL) || (var->mode != int(mode))) + continue; + + /* A shader 'in' or 'out' variable is only really an input or output if + * its value is used by other shader stages. This will cause the variable + * to have a location assigned. + */ + if (var->location == -1) { + var->mode = ir_var_auto; + } + } +} + + +void +assign_varying_locations(struct gl_shader_program *prog, + gl_shader *producer, gl_shader *consumer) +{ + /* FINISHME: Set dynamically when geometry shader support is added. */ + unsigned output_index = VERT_RESULT_VAR0; + unsigned input_index = FRAG_ATTRIB_VAR0; + + /* Operate in a total of three passes. + * + * 1. Assign locations for any matching inputs and outputs. + * + * 2. Mark output variables in the producer that do not have locations as + * not being outputs. This lets the optimizer eliminate them. + * + * 3. Mark input variables in the consumer that do not have locations as + * not being inputs. This lets the optimizer eliminate them. + */ + + invalidate_variable_locations(producer, ir_var_out, VERT_RESULT_VAR0); + invalidate_variable_locations(consumer, ir_var_in, FRAG_ATTRIB_VAR0); + + foreach_list(node, producer->ir) { + ir_variable *const output_var = ((ir_instruction *) node)->as_variable(); + + if ((output_var == NULL) || (output_var->mode != ir_var_out) + || (output_var->location != -1)) + continue; + + ir_variable *const input_var = + consumer->symbols->get_variable(output_var->name); + + if ((input_var == NULL) || (input_var->mode != ir_var_in)) + continue; + + assert(input_var->location == -1); + + output_var->location = output_index; + input_var->location = input_index; + + /* FINISHME: Support for "varying" records in GLSL 1.50. */ + assert(!output_var->type->is_record()); + + if (output_var->type->is_array()) { + const unsigned slots = output_var->type->length + * output_var->type->fields.array->matrix_columns; + + output_index += slots; + input_index += slots; + } else { + const unsigned slots = output_var->type->matrix_columns; + + output_index += slots; + input_index += slots; + } + } + + foreach_list(node, consumer->ir) { + ir_variable *const var = ((ir_instruction *) node)->as_variable(); + + if ((var == NULL) || (var->mode != ir_var_in)) + continue; + + if (var->location == -1) { + if (prog->Version <= 120) { + /* On page 25 (page 31 of the PDF) of the GLSL 1.20 spec: + * + * Only those varying variables used (i.e. read) in + * the fragment shader executable must be written to + * by the vertex shader executable; declaring + * superfluous varying variables in a vertex shader is + * permissible. + * + * We interpret this text as meaning that the VS must + * write the variable for the FS to read it. See + * "glsl1-varying read but not written" in piglit. + */ + + linker_error_printf(prog, "fragment shader varying %s not written " + "by vertex shader\n.", var->name); + prog->LinkStatus = false; + } + + /* An 'in' variable is only really a shader input if its + * value is written by the previous stage. + */ + var->mode = ir_var_auto; + } + } +} + + +void +link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) +{ + void *mem_ctx = ralloc_context(NULL); // temporary linker context + + prog->LinkStatus = false; + prog->Validated = false; + prog->_Used = false; + + if (prog->InfoLog != NULL) + ralloc_free(prog->InfoLog); + + prog->InfoLog = ralloc_strdup(NULL, ""); + + /* Separate the shaders into groups based on their type. + */ + struct gl_shader **vert_shader_list; + unsigned num_vert_shaders = 0; + struct gl_shader **frag_shader_list; + unsigned num_frag_shaders = 0; + + vert_shader_list = (struct gl_shader **) + calloc(2 * prog->NumShaders, sizeof(struct gl_shader *)); + frag_shader_list = &vert_shader_list[prog->NumShaders]; + + unsigned min_version = UINT_MAX; + unsigned max_version = 0; + for (unsigned i = 0; i < prog->NumShaders; i++) { + min_version = MIN2(min_version, prog->Shaders[i]->Version); + max_version = MAX2(max_version, prog->Shaders[i]->Version); + + switch (prog->Shaders[i]->Type) { + case GL_VERTEX_SHADER: + vert_shader_list[num_vert_shaders] = prog->Shaders[i]; + num_vert_shaders++; + break; + case GL_FRAGMENT_SHADER: + frag_shader_list[num_frag_shaders] = prog->Shaders[i]; + num_frag_shaders++; + break; + case GL_GEOMETRY_SHADER: + /* FINISHME: Support geometry shaders. */ + assert(prog->Shaders[i]->Type != GL_GEOMETRY_SHADER); + break; + } + } + + /* Previous to GLSL version 1.30, different compilation units could mix and + * match shading language versions. With GLSL 1.30 and later, the versions + * of all shaders must match. + */ + assert(min_version >= 100); + assert(max_version <= 130); + if ((max_version >= 130 || min_version == 100) + && min_version != max_version) { + linker_error_printf(prog, "all shaders must use same shading " + "language version\n"); + goto done; + } + + prog->Version = max_version; + + for (unsigned int i = 0; i < MESA_SHADER_TYPES; i++) { + if (prog->_LinkedShaders[i] != NULL) + ctx->Driver.DeleteShader(ctx, prog->_LinkedShaders[i]); + + prog->_LinkedShaders[i] = NULL; + } + + /* Link all shaders for a particular stage and validate the result. + */ + if (num_vert_shaders > 0) { + gl_shader *const sh = + link_intrastage_shaders(mem_ctx, ctx, prog, vert_shader_list, + num_vert_shaders); + + if (sh == NULL) + goto done; + + if (!validate_vertex_shader_executable(prog, sh)) + goto done; + + _mesa_reference_shader(ctx, &prog->_LinkedShaders[MESA_SHADER_VERTEX], + sh); + } + + if (num_frag_shaders > 0) { + gl_shader *const sh = + link_intrastage_shaders(mem_ctx, ctx, prog, frag_shader_list, + num_frag_shaders); + + if (sh == NULL) + goto done; + + if (!validate_fragment_shader_executable(prog, sh)) + goto done; + + _mesa_reference_shader(ctx, &prog->_LinkedShaders[MESA_SHADER_FRAGMENT], + sh); + } + + /* Here begins the inter-stage linking phase. Some initial validation is + * performed, then locations are assigned for uniforms, attributes, and + * varyings. + */ + if (cross_validate_uniforms(prog)) { + unsigned prev; + + for (prev = 0; prev < MESA_SHADER_TYPES; prev++) { + if (prog->_LinkedShaders[prev] != NULL) + break; + } + + /* Validate the inputs of each stage with the output of the preceeding + * stage. + */ + for (unsigned i = prev + 1; i < MESA_SHADER_TYPES; i++) { + if (prog->_LinkedShaders[i] == NULL) + continue; + + if (!cross_validate_outputs_to_inputs(prog, + prog->_LinkedShaders[prev], + prog->_LinkedShaders[i])) + goto done; + + prev = i; + } + + prog->LinkStatus = true; + } + + /* Do common optimization before assigning storage for attributes, + * uniforms, and varyings. Later optimization could possibly make + * some of that unused. + */ + for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { + if (prog->_LinkedShaders[i] == NULL) + continue; + + while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, 32)) + ; + } + + update_array_sizes(prog); + + assign_uniform_locations(prog); + + if (prog->_LinkedShaders[MESA_SHADER_VERTEX] != NULL) { + /* FINISHME: The value of the max_attribute_index parameter is + * FINISHME: implementation dependent based on the value of + * FINISHME: GL_MAX_VERTEX_ATTRIBS. GL_MAX_VERTEX_ATTRIBS must be + * FINISHME: at least 16, so hardcode 16 for now. + */ + if (!assign_attribute_locations(prog, 16)) { + prog->LinkStatus = false; + goto done; + } + } + + unsigned prev; + for (prev = 0; prev < MESA_SHADER_TYPES; prev++) { + if (prog->_LinkedShaders[prev] != NULL) + break; + } + + for (unsigned i = prev + 1; i < MESA_SHADER_TYPES; i++) { + if (prog->_LinkedShaders[i] == NULL) + continue; + + assign_varying_locations(prog, + prog->_LinkedShaders[prev], + prog->_LinkedShaders[i]); + prev = i; + } + + if (prog->_LinkedShaders[MESA_SHADER_VERTEX] != NULL) { + demote_shader_inputs_and_outputs(prog->_LinkedShaders[MESA_SHADER_VERTEX], + ir_var_out); + } + + if (prog->_LinkedShaders[MESA_SHADER_GEOMETRY] != NULL) { + gl_shader *const sh = prog->_LinkedShaders[MESA_SHADER_GEOMETRY]; + + demote_shader_inputs_and_outputs(sh, ir_var_in); + demote_shader_inputs_and_outputs(sh, ir_var_inout); + demote_shader_inputs_and_outputs(sh, ir_var_out); + } + + if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT] != NULL) { + gl_shader *const sh = prog->_LinkedShaders[MESA_SHADER_FRAGMENT]; + + demote_shader_inputs_and_outputs(sh, ir_var_in); + } + + /* OpenGL ES requires that a vertex shader and a fragment shader both be + * present in a linked program. By checking for use of shading language + * version 1.00, we also catch the GL_ARB_ES2_compatibility case. + */ + if (ctx->API == API_OPENGLES2 || prog->Version == 100) { + if (prog->_LinkedShaders[MESA_SHADER_VERTEX] == NULL) { + linker_error_printf(prog, "program lacks a vertex shader\n"); + prog->LinkStatus = false; + } else if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT] == NULL) { + linker_error_printf(prog, "program lacks a fragment shader\n"); + prog->LinkStatus = false; + } + } + + /* FINISHME: Assign fragment shader output locations. */ + +done: + free(vert_shader_list); + + for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { + if (prog->_LinkedShaders[i] == NULL) + continue; + + /* Retain any live IR, but trash the rest. */ + reparent_ir(prog->_LinkedShaders[i]->ir, prog->_LinkedShaders[i]->ir); + } + + ralloc_free(mem_ctx); +} diff --git a/src/glsl/linker.h b/src/glsl/linker.h new file mode 100644 index 0000000..a8ce16a --- /dev/null +++ b/src/glsl/linker.h @@ -0,0 +1,35 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#ifndef GLSL_LINKER_H +#define GLSL_LINKER_H + +extern void +linker_error_printf(gl_shader_program *prog, const char *fmt, ...); + +extern bool +link_function_calls(gl_shader_program *prog, gl_shader *main, + gl_shader **shader_list, unsigned num_shaders); + +#endif /* GLSL_LINKER_H */ diff --git a/src/glsl/list.h b/src/glsl/list.h new file mode 100644 index 0000000..1d46365 --- /dev/null +++ b/src/glsl/list.h @@ -0,0 +1,501 @@ +/* + * Copyright © 2008, 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file list.h + * \brief Doubly-linked list abstract container type. + * + * Each doubly-linked list has a sentinel head and tail node. These nodes + * contain no data. The head sentinel can be identified by its \c prev + * pointer being \c NULL. The tail sentinel can be identified by its + * \c next pointer being \c NULL. + * + * A list is empty if either the head sentinel's \c next pointer points to the + * tail sentinel or the tail sentinel's \c prev poiner points to the head + * sentinel. + * + * Instead of tracking two separate \c node structures and a \c list structure + * that points to them, the sentinel nodes are in a single structure. Noting + * that each sentinel node always has one \c NULL pointer, the \c NULL + * pointers occupy the same memory location. In the \c list structure + * contains a the following: + * + * - A \c head pointer that represents the \c next pointer of the + * head sentinel node. + * - A \c tail pointer that represents the \c prev pointer of the head + * sentinel node and the \c next pointer of the tail sentinel node. This + * pointer is \b always \c NULL. + * - A \c tail_prev pointer that represents the \c prev pointer of the + * tail sentinel node. + * + * Therefore, if \c head->next is \c NULL or \c tail_prev->prev is \c NULL, + * the list is empty. + * + * To anyone familiar with "exec lists" on the Amiga, this structure should + * be immediately recognizable. See the following link for the original Amiga + * operating system documentation on the subject. + * + * http://www.natami.net/dev/Libraries_Manual_guide/node02D7.html + * + * \author Ian Romanick + */ + +#pragma once +#ifndef LIST_CONTAINER_H +#define LIST_CONTAINER_H + +#ifndef __cplusplus +#include +#endif +#include + +#include "ralloc.h" + +struct exec_node { + struct exec_node *next; + struct exec_node *prev; + +#ifdef __cplusplus + /* Callers of this ralloc-based new need not call delete. It's + * easier to just ralloc_free 'ctx' (or any of its ancestors). */ + static void* operator new(size_t size, void *ctx) + { + void *node; + + node = ralloc_size(ctx, size); + assert(node != NULL); + + return node; + } + + /* If the user *does* call delete, that's OK, we will just + * ralloc_free in that case. */ + static void operator delete(void *node) + { + ralloc_free(node); + } + + exec_node() : next(NULL), prev(NULL) + { + /* empty */ + } + + const exec_node *get_next() const + { + return next; + } + + exec_node *get_next() + { + return next; + } + + const exec_node *get_prev() const + { + return prev; + } + + exec_node *get_prev() + { + return prev; + } + + void remove() + { + next->prev = prev; + prev->next = next; + next = NULL; + prev = NULL; + } + + /** + * Link a node with itself + * + * This creates a sort of degenerate list that is occasionally useful. + */ + void self_link() + { + next = this; + prev = this; + } + + /** + * Insert a node in the list after the current node + */ + void insert_after(exec_node *after) + { + after->next = this->next; + after->prev = this; + + this->next->prev = after; + this->next = after; + } + /** + * Insert a node in the list before the current node + */ + void insert_before(exec_node *before) + { + before->next = this; + before->prev = this->prev; + + this->prev->next = before; + this->prev = before; + } + + /** + * Insert another list in the list before the current node + */ + void insert_before(struct exec_list *before); + + /** + * Replace the current node with the given node. + */ + void replace_with(exec_node *replacement) + { + replacement->prev = this->prev; + replacement->next = this->next; + + this->prev->next = replacement; + this->next->prev = replacement; + } + + /** + * Is this the sentinel at the tail of the list? + */ + bool is_tail_sentinel() const + { + return this->next == NULL; + } + + /** + * Is this the sentinel at the head of the list? + */ + bool is_head_sentinel() const + { + return this->prev == NULL; + } +#endif +}; + + +#ifdef __cplusplus +/* This macro will not work correctly if `t' uses virtual inheritance. If you + * are using virtual inheritance, you deserve a slow and painful death. Enjoy! + */ +#define exec_list_offsetof(t, f, p) \ + (((char *) &((t *) p)->f) - ((char *) p)) +#else +#define exec_list_offsetof(t, f, p) offsetof(t, f) +#endif + +/** + * Get a pointer to the structure containing an exec_node + * + * Given a pointer to an \c exec_node embedded in a structure, get a pointer to + * the containing structure. + * + * \param type Base type of the structure containing the node + * \param node Pointer to the \c exec_node + * \param field Name of the field in \c type that is the embedded \c exec_node + */ +#define exec_node_data(type, node, field) \ + ((type *) (((char *) node) - exec_list_offsetof(type, field, node))) + +#ifdef __cplusplus +struct exec_node; + +class iterator { +public: + void next() + { + } + + void *get() + { + return NULL; + } + + bool has_next() const + { + return false; + } +}; + +class exec_list_iterator : public iterator { +public: + exec_list_iterator(exec_node *n) : node(n), _next(n->next) + { + /* empty */ + } + + void next() + { + node = _next; + _next = node->next; + } + + void remove() + { + node->remove(); + } + + exec_node *get() + { + return node; + } + + bool has_next() const + { + return _next != NULL; + } + +private: + exec_node *node; + exec_node *_next; +}; + +#define foreach_iter(iter_type, iter, container) \ + for (iter_type iter = (container) . iterator(); iter.has_next(); iter.next()) +#endif + + +struct exec_list { + struct exec_node *head; + struct exec_node *tail; + struct exec_node *tail_pred; + +#ifdef __cplusplus + /* Callers of this ralloc-based new need not call delete. It's + * easier to just ralloc_free 'ctx' (or any of its ancestors). */ + static void* operator new(size_t size, void *ctx) + { + void *node; + + node = ralloc_size(ctx, size); + assert(node != NULL); + + return node; + } + + /* If the user *does* call delete, that's OK, we will just + * ralloc_free in that case. */ + static void operator delete(void *node) + { + ralloc_free(node); + } + + exec_list() + { + make_empty(); + } + + void make_empty() + { + head = (exec_node *) & tail; + tail = NULL; + tail_pred = (exec_node *) & head; + } + + bool is_empty() const + { + /* There are three ways to test whether a list is empty or not. + * + * - Check to see if the \c head points to the \c tail. + * - Check to see if the \c tail_pred points to the \c head. + * - Check to see if the \c head is the sentinel node by test whether its + * \c next pointer is \c NULL. + * + * The first two methods tend to generate better code on modern systems + * because they save a pointer dereference. + */ + return head == (exec_node *) &tail; + } + + const exec_node *get_head() const + { + return !is_empty() ? head : NULL; + } + + exec_node *get_head() + { + return !is_empty() ? head : NULL; + } + + const exec_node *get_tail() const + { + return !is_empty() ? tail_pred : NULL; + } + + exec_node *get_tail() + { + return !is_empty() ? tail_pred : NULL; + } + + void push_head(exec_node *n) + { + n->next = head; + n->prev = (exec_node *) &head; + + n->next->prev = n; + head = n; + } + + void push_tail(exec_node *n) + { + n->next = (exec_node *) &tail; + n->prev = tail_pred; + + n->prev->next = n; + tail_pred = n; + } + + void push_degenerate_list_at_head(exec_node *n) + { + assert(n->prev->next == n); + + n->prev->next = head; + head->prev = n->prev; + n->prev = (exec_node *) &head; + head = n; + } + + /** + * Remove the first node from a list and return it + * + * \return + * The first node in the list or \c NULL if the list is empty. + * + * \sa exec_list::get_head + */ + exec_node *pop_head() + { + exec_node *const n = this->get_head(); + if (n != NULL) + n->remove(); + + return n; + } + + /** + * Move all of the nodes from this list to the target list + */ + void move_nodes_to(exec_list *target) + { + if (is_empty()) { + target->make_empty(); + } else { + target->head = head; + target->tail = NULL; + target->tail_pred = tail_pred; + + target->head->prev = (exec_node *) &target->head; + target->tail_pred->next = (exec_node *) &target->tail; + + make_empty(); + } + } + + /** + * Append all nodes from the source list to the target list + */ + void + append_list(exec_list *source) + { + if (source->is_empty()) + return; + + /* Link the first node of the source with the last node of the target list. + */ + this->tail_pred->next = source->head; + source->head->prev = this->tail_pred; + + /* Make the tail of the source list be the tail of the target list. + */ + this->tail_pred = source->tail_pred; + this->tail_pred->next = (exec_node *) &this->tail; + + /* Make the source list empty for good measure. + */ + source->make_empty(); + } + + exec_list_iterator iterator() + { + return exec_list_iterator(head); + } + + exec_list_iterator iterator() const + { + return exec_list_iterator((exec_node *) head); + } +#endif +}; + + +#ifdef __cplusplus +inline void exec_node::insert_before(exec_list *before) +{ + if (before->is_empty()) + return; + + before->tail_pred->next = this; + before->head->prev = this->prev; + + this->prev->next = before->head; + this->prev = before->tail_pred; + + before->make_empty(); +} +#endif + +/** + * This version is safe even if the current node is removed. + */ +#define foreach_list_safe(__node, __list) \ + for (exec_node * __node = (__list)->head, * __next = __node->next \ + ; __next != NULL \ + ; __node = __next, __next = __next->next) + +#define foreach_list(__node, __list) \ + for (exec_node * __node = (__list)->head \ + ; (__node)->next != NULL \ + ; (__node) = (__node)->next) + +#define foreach_list_const(__node, __list) \ + for (const exec_node * __node = (__list)->head \ + ; (__node)->next != NULL \ + ; (__node) = (__node)->next) + +#define foreach_list_typed(__type, __node, __field, __list) \ + for (__type * __node = \ + exec_node_data(__type, (__list)->head, __field); \ + (__node)->__field.next != NULL; \ + (__node) = exec_node_data(__type, (__node)->__field.next, __field)) + +#define foreach_list_typed_const(__type, __node, __field, __list) \ + for (const __type * __node = \ + exec_node_data(__type, (__list)->head, __field); \ + (__node)->__field.next != NULL; \ + (__node) = exec_node_data(__type, (__node)->__field.next, __field)) + +#endif /* LIST_CONTAINER_H */ diff --git a/src/glsl/loop_analysis.cpp b/src/glsl/loop_analysis.cpp new file mode 100644 index 0000000..a15f6e1 --- /dev/null +++ b/src/glsl/loop_analysis.cpp @@ -0,0 +1,497 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "glsl_types.h" +#include "loop_analysis.h" +#include "ir_hierarchical_visitor.h" + +static bool is_loop_terminator(ir_if *ir); + +static bool all_expression_operands_are_loop_constant(ir_rvalue *, + hash_table *); + +static ir_rvalue *get_basic_induction_increment(ir_assignment *, hash_table *); + + +loop_state::loop_state() +{ + this->ht = hash_table_ctor(0, hash_table_pointer_hash, + hash_table_pointer_compare); + this->mem_ctx = ralloc_context(NULL); +} + + +loop_state::~loop_state() +{ + hash_table_dtor(this->ht); + ralloc_free(this->mem_ctx); +} + + +loop_variable_state * +loop_state::insert(ir_loop *ir) +{ + loop_variable_state *ls = new(this->mem_ctx) loop_variable_state; + hash_table_insert(this->ht, ls, ir); + + return ls; +} + + +loop_variable_state * +loop_state::get(const ir_loop *ir) +{ + return (loop_variable_state *) hash_table_find(this->ht, ir); +} + + +loop_variable * +loop_variable_state::get(const ir_variable *ir) +{ + return (loop_variable *) hash_table_find(this->var_hash, ir); +} + + +loop_variable * +loop_variable_state::insert(ir_variable *var) +{ + void *mem_ctx = ralloc_parent(this); + loop_variable *lv = rzalloc(mem_ctx, loop_variable); + + lv->var = var; + + hash_table_insert(this->var_hash, lv, lv->var); + this->variables.push_tail(lv); + + return lv; +} + + +loop_terminator * +loop_variable_state::insert(ir_if *if_stmt) +{ + void *mem_ctx = ralloc_parent(this); + loop_terminator *t = rzalloc(mem_ctx, loop_terminator); + + t->ir = if_stmt; + this->terminators.push_tail(t); + + return t; +} + + +class loop_analysis : public ir_hierarchical_visitor { +public: + loop_analysis(); + + virtual ir_visitor_status visit(ir_loop_jump *); + virtual ir_visitor_status visit(ir_dereference_variable *); + + virtual ir_visitor_status visit_enter(ir_loop *); + virtual ir_visitor_status visit_leave(ir_loop *); + virtual ir_visitor_status visit_enter(ir_assignment *); + virtual ir_visitor_status visit_leave(ir_assignment *); + virtual ir_visitor_status visit_enter(ir_if *); + virtual ir_visitor_status visit_leave(ir_if *); + + loop_state *loops; + + int if_statement_depth; + + ir_assignment *current_assignment; + + exec_list state; +}; + + +loop_analysis::loop_analysis() +{ + this->loops = new loop_state; + + this->if_statement_depth = 0; + this->current_assignment = NULL; +} + + +ir_visitor_status +loop_analysis::visit(ir_loop_jump *ir) +{ + (void) ir; + + assert(!this->state.is_empty()); + + loop_variable_state *const ls = + (loop_variable_state *) this->state.get_head(); + + ls->num_loop_jumps++; + + return visit_continue; +} + + +ir_visitor_status +loop_analysis::visit(ir_dereference_variable *ir) +{ + /* If we're not somewhere inside a loop, there's nothing to do. + */ + if (this->state.is_empty()) + return visit_continue; + + loop_variable_state *const ls = + (loop_variable_state *) this->state.get_head(); + + ir_variable *var = ir->variable_referenced(); + loop_variable *lv = ls->get(var); + + if (lv == NULL) { + lv = ls->insert(var); + lv->read_before_write = !this->in_assignee; + } + + if (this->in_assignee) { + assert(this->current_assignment != NULL); + + lv->conditional_assignment = (this->if_statement_depth > 0) + || (this->current_assignment->condition != NULL); + + if (lv->first_assignment == NULL) { + assert(lv->num_assignments == 0); + + lv->first_assignment = this->current_assignment; + } + + lv->num_assignments++; + } else if (lv->first_assignment == this->current_assignment) { + /* This catches the case where the variable is used in the RHS of an + * assignment where it is also in the LHS. + */ + lv->read_before_write = true; + } + + return visit_continue; +} + +ir_visitor_status +loop_analysis::visit_enter(ir_loop *ir) +{ + loop_variable_state *ls = this->loops->insert(ir); + this->state.push_head(ls); + + return visit_continue; +} + +ir_visitor_status +loop_analysis::visit_leave(ir_loop *ir) +{ + loop_variable_state *const ls = + (loop_variable_state *) this->state.pop_head(); + + + foreach_list(node, &ir->body_instructions) { + /* Skip over declarations at the start of a loop. + */ + if (((ir_instruction *) node)->as_variable()) + continue; + + ir_if *if_stmt = ((ir_instruction *) node)->as_if(); + + if ((if_stmt != NULL) && is_loop_terminator(if_stmt)) + ls->insert(if_stmt); + else + break; + } + + + foreach_list_safe(node, &ls->variables) { + loop_variable *lv = (loop_variable *) node; + + /* Move variables that are already marked as being loop constant to + * a separate list. These trivially don't need to be tested. + */ + if (lv->is_loop_constant()) { + lv->remove(); + ls->constants.push_tail(lv); + } + } + + /* Each variable assigned in the loop that isn't already marked as being loop + * constant might still be loop constant. The requirements at this point + * are: + * + * - Variable is written before it is read. + * + * - Only one assignment to the variable. + * + * - All operands on the RHS of the assignment are also loop constants. + * + * The last requirement is the reason for the progress loop. A variable + * marked as a loop constant on one pass may allow other variables to be + * marked as loop constant on following passes. + */ + bool progress; + do { + progress = false; + + foreach_list_safe(node, &ls->variables) { + loop_variable *lv = (loop_variable *) node; + + if (lv->conditional_assignment || (lv->num_assignments > 1)) + continue; + + /* Process the RHS of the assignment. If all of the variables + * accessed there are loop constants, then add this + */ + ir_rvalue *const rhs = lv->first_assignment->rhs; + if (all_expression_operands_are_loop_constant(rhs, ls->var_hash)) { + lv->rhs_clean = true; + + if (lv->is_loop_constant()) { + progress = true; + + lv->remove(); + ls->constants.push_tail(lv); + } + } + } + } while (progress); + + /* The remaining variables that are not loop invariant might be loop + * induction variables. + */ + foreach_list_safe(node, &ls->variables) { + loop_variable *lv = (loop_variable *) node; + + /* If there is more than one assignment to a variable, it cannot be a + * loop induction variable. This isn't strictly true, but this is a + * very simple induction variable detector, and it can't handle more + * complex cases. + */ + if (lv->num_assignments > 1) + continue; + + /* All of the variables with zero assignments in the loop are loop + * invariant, and they should have already been filtered out. + */ + assert(lv->num_assignments == 1); + assert(lv->first_assignment != NULL); + + /* The assignmnet to the variable in the loop must be unconditional. + */ + if (lv->conditional_assignment) + continue; + + /* Basic loop induction variables have a single assignment in the loop + * that has the form 'VAR = VAR + i' or 'VAR = VAR - i' where i is a + * loop invariant. + */ + ir_rvalue *const inc = + get_basic_induction_increment(lv->first_assignment, ls->var_hash); + if (inc != NULL) { + lv->iv_scale = NULL; + lv->biv = lv->var; + lv->increment = inc; + + lv->remove(); + ls->induction_variables.push_tail(lv); + } + } + + return visit_continue; +} + +ir_visitor_status +loop_analysis::visit_enter(ir_if *ir) +{ + (void) ir; + + if (!this->state.is_empty()) + this->if_statement_depth++; + + return visit_continue; +} + +ir_visitor_status +loop_analysis::visit_leave(ir_if *ir) +{ + (void) ir; + + if (!this->state.is_empty()) + this->if_statement_depth--; + + return visit_continue; +} + +ir_visitor_status +loop_analysis::visit_enter(ir_assignment *ir) +{ + /* If we're not somewhere inside a loop, there's nothing to do. + */ + if (this->state.is_empty()) + return visit_continue_with_parent; + + this->current_assignment = ir; + + return visit_continue; +} + +ir_visitor_status +loop_analysis::visit_leave(ir_assignment *ir) +{ + /* Since the visit_enter exits with visit_continue_with_parent for this + * case, the loop state stack should never be empty here. + */ + assert(!this->state.is_empty()); + + assert(this->current_assignment == ir); + this->current_assignment = NULL; + + return visit_continue; +} + + +class examine_rhs : public ir_hierarchical_visitor { +public: + examine_rhs(hash_table *loop_variables) + { + this->only_uses_loop_constants = true; + this->loop_variables = loop_variables; + } + + virtual ir_visitor_status visit(ir_dereference_variable *ir) + { + loop_variable *lv = + (loop_variable *) hash_table_find(this->loop_variables, ir->var); + + assert(lv != NULL); + + if (lv->is_loop_constant()) { + return visit_continue; + } else { + this->only_uses_loop_constants = false; + return visit_stop; + } + } + + hash_table *loop_variables; + bool only_uses_loop_constants; +}; + + +bool +all_expression_operands_are_loop_constant(ir_rvalue *ir, hash_table *variables) +{ + examine_rhs v(variables); + + ir->accept(&v); + + return v.only_uses_loop_constants; +} + + +ir_rvalue * +get_basic_induction_increment(ir_assignment *ir, hash_table *var_hash) +{ + /* The RHS must be a binary expression. + */ + ir_expression *const rhs = ir->rhs->as_expression(); + if ((rhs == NULL) + || ((rhs->operation != ir_binop_add) + && (rhs->operation != ir_binop_sub))) + return NULL; + + /* One of the of operands of the expression must be the variable assigned. + * If the operation is subtraction, the variable in question must be the + * "left" operand. + */ + ir_variable *const var = ir->lhs->variable_referenced(); + + ir_variable *const op0 = rhs->operands[0]->variable_referenced(); + ir_variable *const op1 = rhs->operands[1]->variable_referenced(); + + if (((op0 != var) && (op1 != var)) + || ((op1 == var) && (rhs->operation == ir_binop_sub))) + return NULL; + + ir_rvalue *inc = (op0 == var) ? rhs->operands[1] : rhs->operands[0]; + + if (inc->as_constant() == NULL) { + ir_variable *const inc_var = inc->variable_referenced(); + if (inc_var != NULL) { + loop_variable *lv = + (loop_variable *) hash_table_find(var_hash, inc_var); + + if (!lv->is_loop_constant()) + inc = NULL; + } else + inc = NULL; + } + + if ((inc != NULL) && (rhs->operation == ir_binop_sub)) { + void *mem_ctx = ralloc_parent(ir); + + inc = new(mem_ctx) ir_expression(ir_unop_neg, + inc->type, + inc->clone(mem_ctx, NULL), + NULL); + } + + return inc; +} + + +/** + * Detect whether an if-statement is a loop terminating condition + * + * Detects if-statements of the form + * + * (if (expression bool ...) (break)) + */ +bool +is_loop_terminator(ir_if *ir) +{ + if (!ir->else_instructions.is_empty()) + return false; + + ir_instruction *const inst = + (ir_instruction *) ir->then_instructions.get_head(); + assert(inst != NULL); + + if (inst->ir_type != ir_type_loop_jump) + return false; + + ir_loop_jump *const jump = (ir_loop_jump *) inst; + if (jump->mode != ir_loop_jump::jump_break) + return false; + + return true; +} + + +loop_state * +analyze_loop_variables(exec_list *instructions) +{ + loop_analysis v; + + v.run(instructions); + return v.loops; +} diff --git a/src/glsl/loop_analysis.h b/src/glsl/loop_analysis.h new file mode 100644 index 0000000..7b0511f --- /dev/null +++ b/src/glsl/loop_analysis.h @@ -0,0 +1,230 @@ +/* -*- c++ -*- */ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#ifndef LOOP_ANALYSIS_H +#define LOOP_ANALYSIS_H + +#include "ir.h" +#include "program/hash_table.h" + +/** + * Analyze and classify all variables used in all loops in the instruction list + */ +extern class loop_state * +analyze_loop_variables(exec_list *instructions); + + +/** + * Fill in loop control fields + * + * Based on analysis of loop variables, this function tries to remove sequences + * in the loop of the form + * + * (if (expression bool ...) (break)) + * + * and fill in the \c ir_loop::from, \c ir_loop::to, and \c ir_loop::counter + * fields of the \c ir_loop. + * + * In this process, some conditional break-statements may be eliminated + * altogether. For example, if it is provable that one loop exit condition will + * always be satisfied before another, the unnecessary exit condition will be + * removed. + */ +extern bool +set_loop_controls(exec_list *instructions, loop_state *ls); + + +extern bool +unroll_loops(exec_list *instructions, loop_state *ls, unsigned max_iterations); + + +/** + * Tracking for all variables used in a loop + */ +class loop_variable_state : public exec_node { +public: + class loop_variable *get(const ir_variable *); + class loop_variable *insert(ir_variable *); + class loop_terminator *insert(ir_if *); + + + /** + * Loop whose variable state is being tracked by this structure + */ + ir_loop *loop; + + /** + * Variables that have not yet been classified + */ + exec_list variables; + + /** + * Variables whose values are constant within the body of the loop + * + * This list contains \c loop_variable objects. + */ + exec_list constants; + + /** + * Induction variables for this loop + * + * This list contains \c loop_variable objects. + */ + exec_list induction_variables; + + /** + * Simple if-statements that lead to the termination of the loop + * + * This list contains \c loop_terminator objects. + * + * \sa is_loop_terminator + */ + exec_list terminators; + + /** + * Hash table containing all variables accessed in this loop + */ + hash_table *var_hash; + + /** + * Maximum number of loop iterations. + * + * If this value is negative, then the loop may be infinite. This actually + * means that analysis was unable to determine an upper bound on the number + * of loop iterations. + */ + int max_iterations; + + /** + * Number of ir_loop_jump instructions that operate on this loop + */ + unsigned num_loop_jumps; + + loop_variable_state() + { + this->max_iterations = -1; + this->num_loop_jumps = 0; + this->var_hash = hash_table_ctor(0, hash_table_pointer_hash, + hash_table_pointer_compare); + } + + ~loop_variable_state() + { + hash_table_dtor(this->var_hash); + } +}; + + +class loop_variable : public exec_node { +public: + /** The variable in question. */ + ir_variable *var; + + /** Is the variable read in the loop before it is written? */ + bool read_before_write; + + /** Are all variables in the RHS of the assignment loop constants? */ + bool rhs_clean; + + /** Is there an assignment to the variable that is conditional? */ + bool conditional_assignment; + + /** Reference to the first assignment to the variable in the loop body. */ + ir_assignment *first_assignment; + + /** Number of assignments to the variable in the loop body. */ + unsigned num_assignments; + + /** + * Increment values for loop induction variables + * + * Loop induction variables have a single increment of the form + * \c b * \c biv + \c c, where \c b and \c c are loop constants and \c i + * is a basic loop induction variable. + * + * If \c iv_scale is \c NULL, 1 is used. If \c biv is the same as \c var, + * then \c var is a basic loop induction variable. + */ + /*@{*/ + ir_rvalue *iv_scale; + ir_variable *biv; + ir_rvalue *increment; + /*@}*/ + + + inline bool is_loop_constant() const + { + const bool is_const = (this->num_assignments == 0) + || ((this->num_assignments == 1) + && !this->conditional_assignment + && !this->read_before_write + && this->rhs_clean); + + /* If the RHS of *the* assignment is clean, then there must be exactly + * one assignment of the variable. + */ + assert((this->rhs_clean && (this->num_assignments == 1)) + || !this->rhs_clean); + + /* Variables that are marked read-only *MUST* be loop constant. + */ + assert(!this->var->read_only || (this->var->read_only && is_const)); + + return is_const; + } +}; + + +class loop_terminator : public exec_node { +public: + ir_if *ir; +}; + + +class loop_state { +public: + ~loop_state(); + + /** + * Get the loop variable state data for a particular loop + */ + loop_variable_state *get(const ir_loop *); + + loop_variable_state *insert(ir_loop *ir); + +private: + loop_state(); + + /** + * Hash table containing all loops that have been analyzed. + */ + hash_table *ht; + + void *mem_ctx; + + friend class loop_analysis; +}; + +#endif /* LOOP_ANALYSIS_H */ diff --git a/src/glsl/loop_controls.cpp b/src/glsl/loop_controls.cpp new file mode 100644 index 0000000..9acbadc --- /dev/null +++ b/src/glsl/loop_controls.cpp @@ -0,0 +1,304 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include "main/compiler.h" +#include "glsl_types.h" +#include "loop_analysis.h" +#include "ir_hierarchical_visitor.h" + +/** + * Find an initializer of a variable outside a loop + * + * Works backwards from the loop to find the pre-loop value of the variable. + * This is used, for example, to find the initial value of loop induction + * variables. + * + * \param loop Loop where \c var is an induction variable + * \param var Variable whose initializer is to be found + * + * \return + * The \c ir_rvalue assigned to the variable outside the loop. May return + * \c NULL if no initializer can be found. + */ +ir_rvalue * +find_initial_value(ir_loop *loop, ir_variable *var) +{ + for (exec_node *node = loop->prev; + !node->is_head_sentinel(); + node = node->prev) { + ir_instruction *ir = (ir_instruction *) node; + + switch (ir->ir_type) { + case ir_type_call: + case ir_type_loop: + case ir_type_loop_jump: + case ir_type_return: + case ir_type_if: + return NULL; + + case ir_type_function: + case ir_type_function_signature: + assert(!"Should not get here."); + return NULL; + + case ir_type_assignment: { + ir_assignment *assign = ir->as_assignment(); + ir_variable *assignee = assign->lhs->whole_variable_referenced(); + + if (assignee == var) + return (assign->condition != NULL) ? NULL : assign->rhs; + + break; + } + + default: + break; + } + } + + return NULL; +} + + +int +calculate_iterations(ir_rvalue *from, ir_rvalue *to, ir_rvalue *increment, + enum ir_expression_operation op) +{ + if (from == NULL || to == NULL || increment == NULL) + return -1; + + void *mem_ctx = ralloc_context(NULL); + + ir_expression *const sub = + new(mem_ctx) ir_expression(ir_binop_sub, from->type, to, from); + + ir_expression *const div = + new(mem_ctx) ir_expression(ir_binop_div, sub->type, sub, increment); + + ir_constant *iter = div->constant_expression_value(); + + if (iter == NULL) + return -1; + + if (!iter->type->is_integer()) { + ir_rvalue *cast = + new(mem_ctx) ir_expression(ir_unop_f2i, glsl_type::int_type, iter, + NULL); + + iter = cast->constant_expression_value(); + } + + int iter_value = iter->get_int_component(0); + + /* Make sure that the calculated number of iterations satisfies the exit + * condition. This is needed to catch off-by-one errors and some types of + * ill-formed loops. For example, we need to detect that the following + * loop does not have a maximum iteration count. + * + * for (float x = 0.0; x != 0.9; x += 0.2) + * ; + */ + const int bias[] = { -1, 0, 1 }; + bool valid_loop = false; + + for (unsigned i = 0; i < Elements(bias); i++) { + iter = (increment->type->is_integer()) + ? new(mem_ctx) ir_constant(iter_value + bias[i]) + : new(mem_ctx) ir_constant(float(iter_value + bias[i])); + + ir_expression *const mul = + new(mem_ctx) ir_expression(ir_binop_mul, increment->type, iter, + increment); + + ir_expression *const add = + new(mem_ctx) ir_expression(ir_binop_add, mul->type, mul, from); + + ir_expression *const cmp = + new(mem_ctx) ir_expression(op, glsl_type::bool_type, add, to); + + ir_constant *const cmp_result = cmp->constant_expression_value(); + + assert(cmp_result != NULL); + if (cmp_result->get_bool_component(0)) { + iter_value += bias[i]; + valid_loop = true; + break; + } + } + + ralloc_free(mem_ctx); + return (valid_loop) ? iter_value : -1; +} + + +class loop_control_visitor : public ir_hierarchical_visitor { +public: + loop_control_visitor(loop_state *state) + { + this->state = state; + this->progress = false; + } + + virtual ir_visitor_status visit_leave(ir_loop *ir); + + loop_state *state; + + bool progress; +}; + + +ir_visitor_status +loop_control_visitor::visit_leave(ir_loop *ir) +{ + loop_variable_state *const ls = this->state->get(ir); + + /* If we've entered a loop that hasn't been analyzed, something really, + * really bad has happened. + */ + if (ls == NULL) { + assert(ls != NULL); + return visit_continue; + } + + /* Search the loop terminating conditions for one of the form 'i < c' where + * i is a loop induction variable, c is a constant, and < is any relative + * operator. + */ + int max_iterations = ls->max_iterations; + + if(ir->from && ir->to && ir->increment) + max_iterations = calculate_iterations(ir->from, ir->to, ir->increment, (ir_expression_operation)ir->cmp); + + if(max_iterations < 0) + max_iterations = INT_MAX; + + foreach_list(node, &ls->terminators) { + loop_terminator *t = (loop_terminator *) node; + ir_if *if_stmt = t->ir; + + /* If-statements can be either 'if (expr)' or 'if (deref)'. We only care + * about the former here. + */ + ir_expression *cond = if_stmt->condition->as_expression(); + if (cond == NULL) + continue; + + switch (cond->operation) { + case ir_binop_less: + case ir_binop_greater: + case ir_binop_lequal: + case ir_binop_gequal: { + /* The expressions that we care about will either be of the form + * 'counter < limit' or 'limit < counter'. Figure out which is + * which. + */ + ir_rvalue *counter = cond->operands[0]->as_dereference_variable(); + ir_constant *limit = cond->operands[1]->as_constant(); + enum ir_expression_operation cmp = cond->operation; + + if (limit == NULL) { + counter = cond->operands[1]->as_dereference_variable(); + limit = cond->operands[0]->as_constant(); + + switch (cmp) { + case ir_binop_less: cmp = ir_binop_gequal; break; + case ir_binop_greater: cmp = ir_binop_lequal; break; + case ir_binop_lequal: cmp = ir_binop_greater; break; + case ir_binop_gequal: cmp = ir_binop_less; break; + default: assert(!"Should not get here."); + } + } + + if ((counter == NULL) || (limit == NULL)) + break; + + ir_variable *var = counter->variable_referenced(); + + ir_rvalue *init = find_initial_value(ir, var); + + foreach_list(iv_node, &ls->induction_variables) { + loop_variable *lv = (loop_variable *) iv_node; + + if (lv->var == var) { + const int iterations = calculate_iterations(init, limit, + lv->increment, + cmp); + if (iterations >= 0) { + /* If the new iteration count is lower than the previously + * believed iteration count, update the loop control values. + */ + if (iterations < max_iterations) { + ir->from = init->clone(ir, NULL); + ir->to = limit->clone(ir, NULL); + ir->increment = lv->increment->clone(ir, NULL); + ir->counter = lv->var; + ir->cmp = cmp; + + max_iterations = iterations; + } + + /* Remove the conditional break statement. The loop + * controls are now set such that the exit condition will be + * satisfied. + */ + if_stmt->remove(); + + assert(ls->num_loop_jumps > 0); + ls->num_loop_jumps--; + + this->progress = true; + } + + break; + } + } + break; + } + + default: + break; + } + } + + /* If we have proven the one of the loop exit conditions is satisifed before + * running the loop once, remove the loop. + */ + if (max_iterations == 0) + ir->remove(); + else + ls->max_iterations = max_iterations; + + return visit_continue; +} + + +bool +set_loop_controls(exec_list *instructions, loop_state *ls) +{ + loop_control_visitor v(ls); + + v.run(instructions); + + return v.progress; +} diff --git a/src/glsl/loop_unroll.cpp b/src/glsl/loop_unroll.cpp new file mode 100644 index 0000000..5b84e10 --- /dev/null +++ b/src/glsl/loop_unroll.cpp @@ -0,0 +1,214 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "glsl_types.h" +#include "loop_analysis.h" +#include "ir_hierarchical_visitor.h" + +class loop_unroll_visitor : public ir_hierarchical_visitor { +public: + loop_unroll_visitor(loop_state *state, unsigned max_iterations) + { + this->state = state; + this->progress = false; + this->max_iterations = max_iterations; + } + + virtual ir_visitor_status visit_leave(ir_loop *ir); + + loop_state *state; + + bool progress; + unsigned max_iterations; +}; + + +static bool +is_break(ir_instruction *ir) +{ + return ir != NULL && ir->ir_type == ir_type_loop_jump + && ((ir_loop_jump *) ir)->is_break(); +} + + +ir_visitor_status +loop_unroll_visitor::visit_leave(ir_loop *ir) +{ + loop_variable_state *const ls = this->state->get(ir); + int iterations; + + /* If we've entered a loop that hasn't been analyzed, something really, + * really bad has happened. + */ + if (ls == NULL) { + assert(ls != NULL); + return visit_continue; + } + + iterations = ls->max_iterations; + + /* Don't try to unroll loops where the number of iterations is not known + * at compile-time. + */ + if (iterations < 0) + return visit_continue; + + /* Don't try to unroll loops that have zillions of iterations either. + */ + if (iterations > (int) max_iterations) + return visit_continue; + + if (ls->num_loop_jumps > 1) + return visit_continue; + else if (ls->num_loop_jumps) { + ir_instruction *last_ir = (ir_instruction *) ir->body_instructions.get_tail(); + assert(last_ir != NULL); + + if (is_break(last_ir)) { + /* If the only loop-jump is a break at the end of the loop, the loop + * will execute exactly once. Remove the break, set the iteration + * count, and fall through to the normal unroller. + */ + last_ir->remove(); + iterations = 1; + + this->progress = true; + } else { + ir_if *ir_if = NULL; + ir_instruction *break_ir = NULL; + bool continue_from_then_branch = false; + + foreach_list(node, &ir->body_instructions) { + /* recognize loops in the form produced by ir_lower_jumps */ + ir_instruction *cur_ir = (ir_instruction *) node; + + ir_if = cur_ir->as_if(); + if (ir_if != NULL) { + /* Determine which if-statement branch, if any, ends with a + * break. The branch that did *not* have the break will get a + * temporary continue inserted in each iteration of the loop + * unroll. + * + * Note that since ls->num_loop_jumps is <= 1, it is impossible + * for both branches to end with a break. + */ + ir_instruction *ir_if_last = + (ir_instruction *) ir_if->then_instructions.get_tail(); + + if (is_break(ir_if_last)) { + continue_from_then_branch = false; + break_ir = ir_if_last; + break; + } else { + ir_if_last = + (ir_instruction *) ir_if->else_instructions.get_tail(); + + if (is_break(ir_if_last)) { + break_ir = ir_if_last; + continue_from_then_branch = true; + break; + } + } + } + } + + if (break_ir == NULL) + return visit_continue; + + /* move instructions after then if in the continue branch */ + while (!ir_if->get_next()->is_tail_sentinel()) { + ir_instruction *move_ir = (ir_instruction *) ir_if->get_next(); + + move_ir->remove(); + if (continue_from_then_branch) + ir_if->then_instructions.push_tail(move_ir); + else + ir_if->else_instructions.push_tail(move_ir); + } + + /* Remove the break from the if-statement. + */ + break_ir->remove(); + + void *const mem_ctx = ralloc_parent(ir); + ir_instruction *ir_to_replace = ir; + + for (int i = 0; i < iterations; i++) { + exec_list copy_list; + + copy_list.make_empty(); + clone_ir_list(mem_ctx, ©_list, &ir->body_instructions); + + ir_if = ((ir_instruction *) copy_list.get_tail())->as_if(); + assert(ir_if != NULL); + + ir_to_replace->insert_before(©_list); + ir_to_replace->remove(); + + /* placeholder that will be removed in the next iteration */ + ir_to_replace = + new(mem_ctx) ir_loop_jump(ir_loop_jump::jump_continue); + + exec_list *const list = (continue_from_then_branch) + ? &ir_if->then_instructions : &ir_if->else_instructions; + + list->push_tail(ir_to_replace); + } + + ir_to_replace->remove(); + + this->progress = true; + return visit_continue; + } + } + + void *const mem_ctx = ralloc_parent(ir); + + for (int i = 0; i < iterations; i++) { + exec_list copy_list; + + copy_list.make_empty(); + clone_ir_list(mem_ctx, ©_list, &ir->body_instructions); + + ir->insert_before(©_list); + } + + /* The loop has been replaced by the unrolled copies. Remove the original + * loop from the IR sequence. + */ + ir->remove(); + + this->progress = true; + return visit_continue; +} + + +bool +unroll_loops(exec_list *instructions, loop_state *ls, unsigned max_iterations) +{ + loop_unroll_visitor v(ls, max_iterations); + + v.run(instructions); + + return v.progress; +} diff --git a/src/glsl/lower_discard.cpp b/src/glsl/lower_discard.cpp new file mode 100644 index 0000000..cafd2dd --- /dev/null +++ b/src/glsl/lower_discard.cpp @@ -0,0 +1,198 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file lower_discard.cpp + * + * This pass moves discards out of if-statements. + * + * Case 1: The "then" branch contains a conditional discard: + * --------------------------------------------------------- + * + * if (cond1) { + * s1; + * discard cond2; + * s2; + * } else { + * s3; + * } + * + * becomes: + * + * temp = false; + * if (cond1) { + * s1; + * temp = cond2; + * s2; + * } else { + * s3; + * } + * discard temp; + * + * Case 2: The "else" branch contains a conditional discard: + * --------------------------------------------------------- + * + * if (cond1) { + * s1; + * } else { + * s2; + * discard cond2; + * s3; + * } + * + * becomes: + * + * temp = false; + * if (cond1) { + * s1; + * } else { + * s2; + * temp = cond2; + * s3; + * } + * discard temp; + * + * Case 3: Both branches contain a conditional discard: + * ---------------------------------------------------- + * + * if (cond1) { + * s1; + * discard cond2; + * s2; + * } else { + * s3; + * discard cond3; + * s4; + * } + * + * becomes: + * + * temp = false; + * if (cond1) { + * s1; + * temp = cond2; + * s2; + * } else { + * s3; + * temp = cond3; + * s4; + * } + * discard temp; + * + * If there are multiple conditional discards, we need only deal with one of + * them. Repeatedly applying this pass will take care of the others. + * + * Unconditional discards are treated as having a condition of "true". + */ + +#include "glsl_types.h" +#include "ir.h" + +class lower_discard_visitor : public ir_hierarchical_visitor { +public: + lower_discard_visitor() + { + this->progress = false; + } + + ir_visitor_status visit_leave(ir_if *); + + bool progress; +}; + + +bool +lower_discard(exec_list *instructions) +{ + lower_discard_visitor v; + + visit_list_elements(&v, instructions); + + return v.progress; +} + + +static ir_discard * +find_discard(exec_list &instructions) +{ + foreach_list(n, &instructions) { + ir_discard *ir = ((ir_instruction *) n)->as_discard(); + if (ir != NULL) + return ir; + } + return NULL; +} + + +static void +replace_discard(void *mem_ctx, ir_variable *var, ir_discard *ir) +{ + ir_rvalue *condition = ir->condition; + + /* For unconditional discards, use "true" as the condition. */ + if (condition == NULL) + condition = new(mem_ctx) ir_constant(true); + + ir_assignment *assignment = + new(mem_ctx) ir_assignment(new(mem_ctx) ir_dereference_variable(var), + condition, NULL); + + ir->replace_with(assignment); +} + + +ir_visitor_status +lower_discard_visitor::visit_leave(ir_if *ir) +{ + ir_discard *then_discard = find_discard(ir->then_instructions); + ir_discard *else_discard = find_discard(ir->else_instructions); + + if (then_discard == NULL && else_discard == NULL) + return visit_continue; + + void *mem_ctx = ralloc_parent(ir); + + ir_variable *temp = new(mem_ctx) ir_variable(glsl_type::bool_type, + "discard_cond_temp", + ir_var_temporary); + ir_assignment *temp_initializer = + new(mem_ctx) ir_assignment(new(mem_ctx) ir_dereference_variable(temp), + new(mem_ctx) ir_constant(false), NULL); + + ir->insert_before(temp); + ir->insert_before(temp_initializer); + + if (then_discard != NULL) + replace_discard(mem_ctx, temp, then_discard); + + if (else_discard != NULL) + replace_discard(mem_ctx, temp, else_discard); + + ir_discard *discard = then_discard != NULL ? then_discard : else_discard; + discard->condition = new(mem_ctx) ir_dereference_variable(temp); + ir->insert_after(discard); + + this->progress = true; + + return visit_continue; +} diff --git a/src/glsl/lower_if_to_cond_assign.cpp b/src/glsl/lower_if_to_cond_assign.cpp new file mode 100644 index 0000000..e3a1065 --- /dev/null +++ b/src/glsl/lower_if_to_cond_assign.cpp @@ -0,0 +1,200 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file lower_if_to_cond_assign.cpp + * + * This attempts to flatten if-statements to conditional assignments for + * GPUs with limited or no flow control support. + * + * It can't handle other control flow being inside of its block, such + * as calls or loops. Hopefully loop unrolling and inlining will take + * care of those. + * + * Drivers for GPUs with no control flow support should simply call + * + * lower_if_to_cond_assign(instructions) + * + * to attempt to flatten all if-statements. + * + * Some GPUs (such as i965 prior to gen6) do support control flow, but have a + * maximum nesting depth N. Drivers for such hardware can call + * + * lower_if_to_cond_assign(instructions, N) + * + * to attempt to flatten any if-statements appearing at depth > N. + */ + +#include "glsl_types.h" +#include "ir.h" + +class ir_if_to_cond_assign_visitor : public ir_hierarchical_visitor { +public: + ir_if_to_cond_assign_visitor(unsigned max_depth) + { + this->progress = false; + this->max_depth = max_depth; + this->depth = 0; + } + + ir_visitor_status visit_enter(ir_if *); + ir_visitor_status visit_leave(ir_if *); + + bool progress; + unsigned max_depth; + unsigned depth; +}; + +bool +lower_if_to_cond_assign(exec_list *instructions, unsigned max_depth) +{ + ir_if_to_cond_assign_visitor v(max_depth); + + visit_list_elements(&v, instructions); + + return v.progress; +} + +void +check_control_flow(ir_instruction *ir, void *data) +{ + bool *found_control_flow = (bool *)data; + switch (ir->ir_type) { + case ir_type_call: + case ir_type_discard: + case ir_type_loop: + case ir_type_loop_jump: + case ir_type_return: + *found_control_flow = true; + break; + default: + break; + } +} + +void +move_block_to_cond_assign(void *mem_ctx, + ir_if *if_ir, ir_variable *cond_var, bool then) +{ + exec_list *instructions; + + if (then) { + instructions = &if_ir->then_instructions; + } else { + instructions = &if_ir->else_instructions; + } + + foreach_iter(exec_list_iterator, iter, *instructions) { + ir_instruction *ir = (ir_instruction *)iter.get(); + + if (ir->ir_type == ir_type_assignment) { + ir_assignment *assign = (ir_assignment *)ir; + ir_rvalue *cond_expr; + ir_dereference *deref = new(mem_ctx) ir_dereference_variable(cond_var); + + if (then) { + cond_expr = deref; + } else { + cond_expr = new(mem_ctx) ir_expression(ir_unop_logic_not, + glsl_type::bool_type, + deref, + NULL); + } + + if (!assign->condition) { + assign->condition = cond_expr; + } else { + assign->condition = new(mem_ctx) ir_expression(ir_binop_logic_and, + glsl_type::bool_type, + cond_expr, + assign->condition); + } + } + + /* Now, move from the if block to the block surrounding it. */ + ir->remove(); + if_ir->insert_before(ir); + } +} + +ir_visitor_status +ir_if_to_cond_assign_visitor::visit_enter(ir_if *ir) +{ + (void) ir; + this->depth++; + return visit_continue; +} + +ir_visitor_status +ir_if_to_cond_assign_visitor::visit_leave(ir_if *ir) +{ + /* Only flatten when beyond the GPU's maximum supported nesting depth. */ + if (this->depth <= this->max_depth) + return visit_continue; + + this->depth--; + + bool found_control_flow = false; + ir_variable *cond_var; + ir_assignment *assign; + ir_dereference_variable *deref; + + /* Check that both blocks don't contain anything we can't support. */ + foreach_iter(exec_list_iterator, then_iter, ir->then_instructions) { + ir_instruction *then_ir = (ir_instruction *)then_iter.get(); + visit_tree(then_ir, check_control_flow, &found_control_flow); + } + foreach_iter(exec_list_iterator, else_iter, ir->else_instructions) { + ir_instruction *else_ir = (ir_instruction *)else_iter.get(); + visit_tree(else_ir, check_control_flow, &found_control_flow); + } + if (found_control_flow) + return visit_continue; + + void *mem_ctx = ralloc_parent(ir); + + /* Store the condition to a variable so the assignment conditions are + * simpler. + */ + cond_var = new(mem_ctx) ir_variable(glsl_type::bool_type, + "if_to_cond_assign_condition", + ir_var_temporary); + ir->insert_before(cond_var); + + deref = new(mem_ctx) ir_dereference_variable(cond_var); + assign = new(mem_ctx) ir_assignment(deref, + ir->condition, NULL); + ir->insert_before(assign); + + /* Now, move all of the instructions out of the if blocks, putting + * conditions on assignments. + */ + move_block_to_cond_assign(mem_ctx, ir, cond_var, true); + move_block_to_cond_assign(mem_ctx, ir, cond_var, false); + + ir->remove(); + + this->progress = true; + + return visit_continue; +} diff --git a/src/glsl/lower_instructions.cpp b/src/glsl/lower_instructions.cpp new file mode 100644 index 0000000..a5f61f2 --- /dev/null +++ b/src/glsl/lower_instructions.cpp @@ -0,0 +1,288 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file lower_instructions.cpp + * + * Many GPUs lack native instructions for certain expression operations, and + * must replace them with some other expression tree. This pass lowers some + * of the most common cases, allowing the lowering code to be implemented once + * rather than in each driver backend. + * + * Currently supported transformations: + * - SUB_TO_ADD_NEG + * - DIV_TO_MUL_RCP + * - EXP_TO_EXP2 + * - POW_TO_EXP2 + * - LOG_TO_LOG2 + * - MOD_TO_FRACT + * + * SUB_TO_ADD_NEG: + * --------------- + * Breaks an ir_binop_sub expression down to add(op0, neg(op1)) + * + * This simplifies expression reassociation, and for many backends + * there is no subtract operation separate from adding the negation. + * For backends with native subtract operations, they will probably + * want to recognize add(op0, neg(op1)) or the other way around to + * produce a subtract anyway. + * + * DIV_TO_MUL_RCP: + * --------------- + * Breaks an ir_unop_div expression down to op0 * (rcp(op1)). + * + * Many GPUs don't have a divide instruction (945 and 965 included), + * but they do have an RCP instruction to compute an approximate + * reciprocal. By breaking the operation down, constant reciprocals + * can get constant folded. + * + * EXP_TO_EXP2 and LOG_TO_LOG2: + * ---------------------------- + * Many GPUs don't have a base e log or exponent instruction, but they + * do have base 2 versions, so this pass converts exp and log to exp2 + * and log2 operations. + * + * POW_TO_EXP2: + * ----------- + * Many older GPUs don't have an x**y instruction. For these GPUs, convert + * x**y to 2**(y * log2(x)). + * + * MOD_TO_FRACT: + * ------------- + * Breaks an ir_unop_mod expression down to (op1 * fract(op0 / op1)) + * + * Many GPUs don't have a MOD instruction (945 and 965 included), and + * if we have to break it down like this anyway, it gives an + * opportunity to do things like constant fold the (1.0 / op1) easily. + */ + +#include "main/core.h" /* for M_LOG2E */ +#include "glsl_types.h" +#include "ir.h" +#include "ir_optimization.h" + +class lower_instructions_visitor : public ir_hierarchical_visitor { +public: + lower_instructions_visitor(unsigned lower) + : progress(false), lower(lower) { } + + ir_visitor_status visit_leave(ir_expression *); + + bool progress; + +private: + unsigned lower; /** Bitfield of which operations to lower */ + + void sub_to_add_neg(ir_expression *); + void div_to_mul_rcp(ir_expression *); + void mod_to_fract(ir_expression *); + void exp_to_exp2(ir_expression *); + void pow_to_exp2(ir_expression *); + void log_to_log2(ir_expression *); +}; + +/** + * Determine if a particular type of lowering should occur + */ +#define lowering(x) (this->lower & x) + +bool +lower_instructions(exec_list *instructions, unsigned what_to_lower) +{ + lower_instructions_visitor v(what_to_lower); + + visit_list_elements(&v, instructions); + return v.progress; +} + +void +lower_instructions_visitor::sub_to_add_neg(ir_expression *ir) +{ + ir->operation = ir_binop_add; + ir->operands[1] = new(ir) ir_expression(ir_unop_neg, ir->operands[1]->type, + ir->operands[1], NULL); + this->progress = true; +} + +void +lower_instructions_visitor::div_to_mul_rcp(ir_expression *ir) +{ + if (!ir->operands[1]->type->is_integer()) { + /* New expression for the 1.0 / op1 */ + ir_rvalue *expr; + expr = new(ir) ir_expression(ir_unop_rcp, + ir->operands[1]->type, + ir->operands[1], + NULL); + + /* op0 / op1 -> op0 * (1.0 / op1) */ + ir->operation = ir_binop_mul; + ir->operands[1] = expr; + } else { + /* Be careful with integer division -- we need to do it as a + * float and re-truncate, since rcp(n > 1) of an integer would + * just be 0. + */ + ir_rvalue *op0, *op1; + const struct glsl_type *vec_type; + + vec_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, + ir->operands[1]->type->vector_elements, + ir->operands[1]->type->matrix_columns); + + if (ir->operands[1]->type->base_type == GLSL_TYPE_INT) + op1 = new(ir) ir_expression(ir_unop_i2f, vec_type, ir->operands[1], NULL); + else + op1 = new(ir) ir_expression(ir_unop_u2f, vec_type, ir->operands[1], NULL); + + op1 = new(ir) ir_expression(ir_unop_rcp, op1->type, op1, NULL); + + vec_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, + ir->operands[0]->type->vector_elements, + ir->operands[0]->type->matrix_columns); + + if (ir->operands[0]->type->base_type == GLSL_TYPE_INT) + op0 = new(ir) ir_expression(ir_unop_i2f, vec_type, ir->operands[0], NULL); + else + op0 = new(ir) ir_expression(ir_unop_u2f, vec_type, ir->operands[0], NULL); + + op0 = new(ir) ir_expression(ir_binop_mul, vec_type, op0, op1); + + ir->operation = ir_unop_f2i; + ir->operands[0] = op0; + ir->operands[1] = NULL; + } + + this->progress = true; +} + +void +lower_instructions_visitor::exp_to_exp2(ir_expression *ir) +{ + ir_constant *log2_e = new(ir) ir_constant(float(M_LOG2E)); + + ir->operation = ir_unop_exp2; + ir->operands[0] = new(ir) ir_expression(ir_binop_mul, ir->operands[0]->type, + ir->operands[0], log2_e); + this->progress = true; +} + +void +lower_instructions_visitor::pow_to_exp2(ir_expression *ir) +{ + ir_expression *const log2_x = + new(ir) ir_expression(ir_unop_log2, ir->operands[0]->type, + ir->operands[0]); + + ir->operation = ir_unop_exp2; + ir->operands[0] = new(ir) ir_expression(ir_binop_mul, ir->operands[1]->type, + ir->operands[1], log2_x); + ir->operands[1] = NULL; + this->progress = true; +} + +void +lower_instructions_visitor::log_to_log2(ir_expression *ir) +{ + ir->operation = ir_binop_mul; + ir->operands[0] = new(ir) ir_expression(ir_unop_log2, ir->operands[0]->type, + ir->operands[0], NULL); + ir->operands[1] = new(ir) ir_constant(float(1.0 / M_LOG2E)); + this->progress = true; +} + +void +lower_instructions_visitor::mod_to_fract(ir_expression *ir) +{ + ir_variable *temp = new(ir) ir_variable(ir->operands[1]->type, "mod_b", + ir_var_temporary); + this->base_ir->insert_before(temp); + + ir_assignment *const assign = + new(ir) ir_assignment(new(ir) ir_dereference_variable(temp), + ir->operands[1], NULL); + + this->base_ir->insert_before(assign); + + ir_expression *const div_expr = + new(ir) ir_expression(ir_binop_div, ir->operands[0]->type, + ir->operands[0], + new(ir) ir_dereference_variable(temp)); + + /* Don't generate new IR that would need to be lowered in an additional + * pass. + */ + if (lowering(DIV_TO_MUL_RCP)) + div_to_mul_rcp(div_expr); + + ir_rvalue *expr = new(ir) ir_expression(ir_unop_fract, + ir->operands[0]->type, + div_expr, + NULL); + + ir->operation = ir_binop_mul; + ir->operands[0] = new(ir) ir_dereference_variable(temp); + ir->operands[1] = expr; + this->progress = true; +} + +ir_visitor_status +lower_instructions_visitor::visit_leave(ir_expression *ir) +{ + switch (ir->operation) { + case ir_binop_sub: + if (lowering(SUB_TO_ADD_NEG)) + sub_to_add_neg(ir); + break; + + case ir_binop_div: + if (lowering(DIV_TO_MUL_RCP)) + div_to_mul_rcp(ir); + break; + + case ir_unop_exp: + if (lowering(EXP_TO_EXP2)) + exp_to_exp2(ir); + break; + + case ir_unop_log: + if (lowering(LOG_TO_LOG2)) + log_to_log2(ir); + break; + + case ir_binop_mod: + if (lowering(MOD_TO_FRACT)) + mod_to_fract(ir); + break; + + case ir_binop_pow: + if (lowering(POW_TO_EXP2)) + pow_to_exp2(ir); + break; + + default: + return visit_continue; + } + + return visit_continue; +} diff --git a/src/glsl/lower_jumps.cpp b/src/glsl/lower_jumps.cpp new file mode 100644 index 0000000..d99e0aa --- /dev/null +++ b/src/glsl/lower_jumps.cpp @@ -0,0 +1,570 @@ +/* + * Copyright © 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file lower_jumps.cpp + * + * This pass lowers jumps (break, continue, and return) to if/else structures. + * + * It can be asked to: + * 1. Pull jumps out of ifs where possible + * 2. Remove all "continue"s, replacing them with an "execute flag" + * 3. Replace all "break" with a single conditional one at the end of the loop + * 4. Replace all "return"s with a single return at the end of the function, + * for the main function and/or other functions + * + * Applying this pass gives several benefits: + * 1. All functions can be inlined. + * 2. nv40 and other pre-DX10 chips without "continue" can be supported + * 3. nv30 and other pre-DX10 chips with no control flow at all are better + * supported + * + * Continues are lowered by adding a per-loop "execute flag", initialized to + * true, that when cleared inhibits all execution until the end of the loop. + * + * Breaks are lowered to continues, plus setting a "break flag" that is checked + * at the end of the loop, and trigger the unique "break". + * + * Returns are lowered to breaks/continues, plus adding a "return flag" that + * causes loops to break again out of their enclosing loops until all the + * loops are exited: then the "execute flag" logic will ignore everything + * until the end of the function. + * + * Note that "continue" and "return" can also be implemented by adding + * a dummy loop and using break. + * However, this is bad for hardware with limited nesting depth, and + * prevents further optimization, and thus is not currently performed. + */ + +#include "glsl_types.h" +#include +#include "ir.h" + +enum jump_strength +{ + strength_none, + strength_always_clears_execute_flag, + strength_continue, + strength_break, + strength_return, +}; + +struct block_record +{ + /* minimum jump strength (of lowered IR, not pre-lowering IR) + * + * If the block ends with a jump, must be the strength of the jump. + * Otherwise, the jump would be dead and have been deleted before) + * + * If the block doesn't end with a jump, it can be different than strength_none if all paths before it lead to some jump + * (e.g. an if with a return in one branch, and a break in the other, while not lowering them) + * Note that identical jumps are usually unified though. + */ + jump_strength min_strength; + + /* can anything clear the execute flag? */ + bool may_clear_execute_flag; + + block_record() + { + this->min_strength = strength_none; + this->may_clear_execute_flag = false; + } +}; + +struct loop_record +{ + ir_function_signature* signature; + ir_loop* loop; + + /* used to avoid lowering the break used to represent lowered breaks */ + unsigned nesting_depth; + bool in_if_at_the_end_of_the_loop; + + bool may_set_return_flag; + + ir_variable* break_flag; + ir_variable* execute_flag; /* cleared to emulate continue */ + + loop_record(ir_function_signature* p_signature = 0, ir_loop* p_loop = 0) + { + this->signature = p_signature; + this->loop = p_loop; + this->nesting_depth = 0; + this->in_if_at_the_end_of_the_loop = false; + this->may_set_return_flag = false; + this->break_flag = 0; + this->execute_flag = 0; + } + + ir_variable* get_execute_flag() + { + /* also supported for the "function loop" */ + if(!this->execute_flag) { + exec_list& list = this->loop ? this->loop->body_instructions : signature->body; + this->execute_flag = new(this->signature) ir_variable(glsl_type::bool_type, "execute_flag", ir_var_temporary); + list.push_head(new(this->signature) ir_assignment(new(this->signature) ir_dereference_variable(execute_flag), new(this->signature) ir_constant(true), 0)); + list.push_head(this->execute_flag); + } + return this->execute_flag; + } + + ir_variable* get_break_flag() + { + assert(this->loop); + if(!this->break_flag) { + this->break_flag = new(this->signature) ir_variable(glsl_type::bool_type, "break_flag", ir_var_temporary); + this->loop->insert_before(this->break_flag); + this->loop->insert_before(new(this->signature) ir_assignment(new(this->signature) ir_dereference_variable(break_flag), new(this->signature) ir_constant(false), 0)); + } + return this->break_flag; + } +}; + +struct function_record +{ + ir_function_signature* signature; + ir_variable* return_flag; /* used to break out of all loops and then jump to the return instruction */ + ir_variable* return_value; + bool is_main; + unsigned nesting_depth; + + function_record(ir_function_signature* p_signature = 0) + { + this->signature = p_signature; + this->return_flag = 0; + this->return_value = 0; + this->nesting_depth = 0; + this->is_main = this->signature && (strcmp(this->signature->function_name(), "main") == 0); + } + + ir_variable* get_return_flag() + { + if(!this->return_flag) { + this->return_flag = new(this->signature) ir_variable(glsl_type::bool_type, "return_flag", ir_var_temporary); + this->signature->body.push_head(new(this->signature) ir_assignment(new(this->signature) ir_dereference_variable(return_flag), new(this->signature) ir_constant(false), 0)); + this->signature->body.push_head(this->return_flag); + } + return this->return_flag; + } + + ir_variable* get_return_value() + { + if(!this->return_value) { + assert(!this->signature->return_type->is_void()); + return_value = new(this->signature) ir_variable(this->signature->return_type, "return_value", ir_var_temporary); + this->signature->body.push_head(this->return_value); + } + return this->return_value; + } +}; + +struct ir_lower_jumps_visitor : public ir_control_flow_visitor { + bool progress; + + struct function_record function; + struct loop_record loop; + struct block_record block; + + bool pull_out_jumps; + bool lower_continue; + bool lower_break; + bool lower_sub_return; + bool lower_main_return; + + ir_lower_jumps_visitor() + { + this->progress = false; + } + + void truncate_after_instruction(exec_node *ir) + { + if (!ir) + return; + + while (!ir->get_next()->is_tail_sentinel()) { + ((ir_instruction *)ir->get_next())->remove(); + this->progress = true; + } + } + + void move_outer_block_inside(ir_instruction *ir, exec_list *inner_block) + { + while (!ir->get_next()->is_tail_sentinel()) { + ir_instruction *move_ir = (ir_instruction *)ir->get_next(); + + move_ir->remove(); + inner_block->push_tail(move_ir); + } + } + + virtual void visit(class ir_loop_jump * ir) + { + truncate_after_instruction(ir); + this->block.min_strength = ir->is_break() ? strength_break : strength_continue; + } + + virtual void visit(class ir_return * ir) + { + truncate_after_instruction(ir); + this->block.min_strength = strength_return; + } + + virtual void visit(class ir_discard * ir) + { + } + + enum jump_strength get_jump_strength(ir_instruction* ir) + { + if(!ir) + return strength_none; + else if(ir->ir_type == ir_type_loop_jump) { + if(((ir_loop_jump*)ir)->is_break()) + return strength_break; + else + return strength_continue; + } else if(ir->ir_type == ir_type_return) + return strength_return; + else + return strength_none; + } + + bool should_lower_jump(ir_jump* ir) + { + unsigned strength = get_jump_strength(ir); + bool lower; + switch(strength) + { + case strength_none: + lower = false; /* don't change this, code relies on it */ + break; + case strength_continue: + lower = lower_continue; + break; + case strength_break: + assert(this->loop.loop); + /* never lower "canonical break" */ + if(ir->get_next()->is_tail_sentinel() && (this->loop.nesting_depth == 0 + || (this->loop.nesting_depth == 1 && this->loop.in_if_at_the_end_of_the_loop))) + lower = false; + else + lower = lower_break; + break; + case strength_return: + /* never lower return at the end of a this->function */ + if(this->function.nesting_depth == 0 && ir->get_next()->is_tail_sentinel()) + lower = false; + else if (this->function.is_main) + lower = lower_main_return; + else + lower = lower_sub_return; + break; + } + return lower; + } + + block_record visit_block(exec_list* list) + { + block_record saved_block = this->block; + this->block = block_record(); + visit_exec_list(list, this); + block_record ret = this->block; + this->block = saved_block; + return ret; + } + + virtual void visit(ir_if *ir) + { + if(this->loop.nesting_depth == 0 && ir->get_next()->is_tail_sentinel()) + this->loop.in_if_at_the_end_of_the_loop = true; + + ++this->function.nesting_depth; + ++this->loop.nesting_depth; + + block_record block_records[2]; + ir_jump* jumps[2]; + + block_records[0] = visit_block(&ir->then_instructions); + block_records[1] = visit_block(&ir->else_instructions); + +retry: /* we get here if we put code after the if inside a branch */ + for(unsigned i = 0; i < 2; ++i) { + exec_list& list = i ? ir->else_instructions : ir->then_instructions; + jumps[i] = 0; + if(!list.is_empty() && get_jump_strength((ir_instruction*)list.get_tail())) + jumps[i] = (ir_jump*)list.get_tail(); + } + + for(;;) { + jump_strength jump_strengths[2]; + + for(unsigned i = 0; i < 2; ++i) { + if(jumps[i]) { + jump_strengths[i] = block_records[i].min_strength; + assert(jump_strengths[i] == get_jump_strength(jumps[i])); + } else + jump_strengths[i] = strength_none; + } + + /* move both jumps out if possible */ + if(pull_out_jumps && jump_strengths[0] == jump_strengths[1]) { + bool unify = true; + if(jump_strengths[0] == strength_continue) + ir->insert_after(new(ir) ir_loop_jump(ir_loop_jump::jump_continue)); + else if(jump_strengths[0] == strength_break) + ir->insert_after(new(ir) ir_loop_jump(ir_loop_jump::jump_break)); + /* FINISHME: unify returns with identical expressions */ + else if(jump_strengths[0] == strength_return && this->function.signature->return_type->is_void()) + ir->insert_after(new(ir) ir_return(NULL)); + else + unify = false; + + if(unify) { + jumps[0]->remove(); + jumps[1]->remove(); + this->progress = true; + + jumps[0] = 0; + jumps[1] = 0; + block_records[0].min_strength = strength_none; + block_records[1].min_strength = strength_none; + break; + } + } + + /* lower a jump: if both need to lowered, start with the strongest one, so that + * we might later unify the lowered version with the other one + */ + bool should_lower[2]; + for(unsigned i = 0; i < 2; ++i) + should_lower[i] = should_lower_jump(jumps[i]); + + int lower; + if(should_lower[1] && should_lower[0]) + lower = jump_strengths[1] > jump_strengths[0]; + else if(should_lower[0]) + lower = 0; + else if(should_lower[1]) + lower = 1; + else + break; + + if(jump_strengths[lower] == strength_return) { + ir_variable* return_flag = this->function.get_return_flag(); + if(!this->function.signature->return_type->is_void()) { + ir_variable* return_value = this->function.get_return_value(); + jumps[lower]->insert_before(new(ir) ir_assignment(new (ir) ir_dereference_variable(return_value), ((ir_return*)jumps[lower])->value, NULL)); + } + jumps[lower]->insert_before(new(ir) ir_assignment(new (ir) ir_dereference_variable(return_flag), new (ir) ir_constant(true), NULL)); + this->loop.may_set_return_flag = true; + if(this->loop.loop) { + ir_loop_jump* lowered = 0; + lowered = new(ir) ir_loop_jump(ir_loop_jump::jump_break); + block_records[lower].min_strength = strength_break; + jumps[lower]->replace_with(lowered); + jumps[lower] = lowered; + } else + goto lower_continue; + this->progress = true; + } else if(jump_strengths[lower] == strength_break) { + /* We can't lower to an actual continue because that would execute the increment. + * + * In the lowered code, we instead put the break check between the this->loop body and the increment, + * which is impossible with a real continue as defined by the GLSL IR currently. + * + * Smarter options (such as undoing the increment) are possible but it's not worth implementing them, + * because if break is lowered, continue is almost surely lowered too. + */ + jumps[lower]->insert_before(new(ir) ir_assignment(new (ir) ir_dereference_variable(this->loop.get_break_flag()), new (ir) ir_constant(true), 0)); + goto lower_continue; + } else if(jump_strengths[lower] == strength_continue) { +lower_continue: + ir_variable* execute_flag = this->loop.get_execute_flag(); + jumps[lower]->replace_with(new(ir) ir_assignment(new (ir) ir_dereference_variable(execute_flag), new (ir) ir_constant(false), 0)); + jumps[lower] = 0; + block_records[lower].min_strength = strength_always_clears_execute_flag; + block_records[lower].may_clear_execute_flag = true; + this->progress = true; + break; + } + } + + /* move out a jump out if possible */ + if(pull_out_jumps) { + int move_out = -1; + if(jumps[0] && block_records[1].min_strength >= strength_continue) + move_out = 0; + else if(jumps[1] && block_records[0].min_strength >= strength_continue) + move_out = 1; + + if(move_out >= 0) + { + jumps[move_out]->remove(); + ir->insert_after(jumps[move_out]); + jumps[move_out] = 0; + block_records[move_out].min_strength = strength_none; + this->progress = true; + } + } + + if(block_records[0].min_strength < block_records[1].min_strength) + this->block.min_strength = block_records[0].min_strength; + else + this->block.min_strength = block_records[1].min_strength; + this->block.may_clear_execute_flag = this->block.may_clear_execute_flag || block_records[0].may_clear_execute_flag || block_records[1].may_clear_execute_flag; + + if(this->block.min_strength) + truncate_after_instruction(ir); + else if(this->block.may_clear_execute_flag) + { + int move_into = -1; + if(block_records[0].min_strength && !block_records[1].may_clear_execute_flag) + move_into = 1; + else if(block_records[1].min_strength && !block_records[0].may_clear_execute_flag) + move_into = 0; + + if(move_into >= 0) { + assert(!block_records[move_into].min_strength && !block_records[move_into].may_clear_execute_flag); /* otherwise, we just truncated */ + + exec_list* list = move_into ? &ir->else_instructions : &ir->then_instructions; + exec_node* next = ir->get_next(); + if(!next->is_tail_sentinel()) { + move_outer_block_inside(ir, list); + + exec_list list; + list.head = next; + block_records[move_into] = visit_block(&list); + + this->progress = true; + goto retry; + } + } else { + ir_instruction* ir_after; + for(ir_after = (ir_instruction*)ir->get_next(); !ir_after->is_tail_sentinel();) + { + ir_if* ir_if = ir_after->as_if(); + if(ir_if && ir_if->else_instructions.is_empty()) { + ir_dereference_variable* ir_if_cond_deref = ir_if->condition->as_dereference_variable(); + if(ir_if_cond_deref && ir_if_cond_deref->var == this->loop.execute_flag) { + ir_instruction* ir_next = (ir_instruction*)ir_after->get_next(); + ir_after->insert_before(&ir_if->then_instructions); + ir_after->remove(); + ir_after = ir_next; + continue; + } + } + ir_after = (ir_instruction*)ir_after->get_next(); + + /* only set this if we find any unprotected instruction */ + this->progress = true; + } + + if(!ir->get_next()->is_tail_sentinel()) { + assert(this->loop.execute_flag); + ir_if* if_execute = new(ir) ir_if(new(ir) ir_dereference_variable(this->loop.execute_flag)); + move_outer_block_inside(ir, &if_execute->then_instructions); + ir->insert_after(if_execute); + } + } + } + --this->loop.nesting_depth; + --this->function.nesting_depth; + } + + virtual void visit(ir_loop *ir) + { + ++this->function.nesting_depth; + loop_record saved_loop = this->loop; + this->loop = loop_record(this->function.signature, ir); + + block_record body = visit_block(&ir->body_instructions); + + if(body.min_strength >= strength_break) { + /* FINISHME: turn the this->loop into an if, or replace it with its body */ + } + + if(this->loop.break_flag) { + ir_if* break_if = new(ir) ir_if(new(ir) ir_dereference_variable(this->loop.break_flag)); + break_if->then_instructions.push_tail(new(ir) ir_loop_jump(ir_loop_jump::jump_break)); + ir->body_instructions.push_tail(break_if); + } + + if(this->loop.may_set_return_flag) { + assert(this->function.return_flag); + ir_if* return_if = new(ir) ir_if(new(ir) ir_dereference_variable(this->function.return_flag)); + saved_loop.may_set_return_flag = true; + if(saved_loop.loop) + return_if->then_instructions.push_tail(new(ir) ir_loop_jump(ir_loop_jump::jump_break)); + else + move_outer_block_inside(ir, &return_if->else_instructions); + ir->insert_after(return_if); + } + + this->loop = saved_loop; + --this->function.nesting_depth; + } + + virtual void visit(ir_function_signature *ir) + { + /* these are not strictly necessary */ + assert(!this->function.signature); + assert(!this->loop.loop); + + function_record saved_function = this->function; + loop_record saved_loop = this->loop; + this->function = function_record(ir); + this->loop = loop_record(ir); + + assert(!this->loop.loop); + visit_block(&ir->body); + + if(this->function.return_value) + ir->body.push_tail(new(ir) ir_return(new (ir) ir_dereference_variable(this->function.return_value))); + + this->loop = saved_loop; + this->function = saved_function; + } + + virtual void visit(class ir_function * ir) + { + visit_block(&ir->signatures); + } +}; + +bool +do_lower_jumps(exec_list *instructions, bool pull_out_jumps, bool lower_sub_return, bool lower_main_return, bool lower_continue, bool lower_break) +{ + ir_lower_jumps_visitor v; + v.pull_out_jumps = pull_out_jumps; + v.lower_continue = lower_continue; + v.lower_break = lower_break; + v.lower_sub_return = lower_sub_return; + v.lower_main_return = lower_main_return; + + do { + v.progress = false; + visit_exec_list(instructions, &v); + } while (v.progress); + + return v.progress; +} diff --git a/src/glsl/lower_mat_op_to_vec.cpp b/src/glsl/lower_mat_op_to_vec.cpp new file mode 100644 index 0000000..8cbbfa7 --- /dev/null +++ b/src/glsl/lower_mat_op_to_vec.cpp @@ -0,0 +1,490 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file lower_mat_op_to_vec.cpp + * + * Breaks matrix operation expressions down to a series of vector operations. + * + * Generally this is how we have to codegen matrix operations for a + * GPU, so this gives us the chance to constant fold operations on a + * column or row. + */ + +#include "ir.h" +#include "ir_expression_flattening.h" +#include "glsl_types.h" + +class ir_mat_op_to_vec_visitor : public ir_hierarchical_visitor { +public: + ir_mat_op_to_vec_visitor() + { + this->made_progress = false; + this->mem_ctx = NULL; + } + + ir_visitor_status visit_leave(ir_assignment *); + + ir_dereference *get_column(ir_variable *var, int col); + ir_rvalue *get_element(ir_variable *var, int col, int row); + + void do_mul_mat_mat(ir_variable *result_var, + ir_variable *a_var, ir_variable *b_var); + void do_mul_mat_vec(ir_variable *result_var, + ir_variable *a_var, ir_variable *b_var); + void do_mul_vec_mat(ir_variable *result_var, + ir_variable *a_var, ir_variable *b_var); + void do_mul_mat_scalar(ir_variable *result_var, + ir_variable *a_var, ir_variable *b_var); + void do_equal_mat_mat(ir_variable *result_var, ir_variable *a_var, + ir_variable *b_var, bool test_equal); + + void *mem_ctx; + bool made_progress; +}; + +static bool +mat_op_to_vec_predicate(ir_instruction *ir) +{ + ir_expression *expr = ir->as_expression(); + unsigned int i; + + if (!expr) + return false; + + for (i = 0; i < expr->get_num_operands(); i++) { + if (expr->operands[i]->type->is_matrix()) + return true; + } + + return false; +} + +bool +do_mat_op_to_vec(exec_list *instructions) +{ + ir_mat_op_to_vec_visitor v; + + /* Pull out any matrix expression to a separate assignment to a + * temp. This will make our handling of the breakdown to + * operations on the matrix's vector components much easier. + */ + do_expression_flattening(instructions, mat_op_to_vec_predicate); + + visit_list_elements(&v, instructions); + + return v.made_progress; +} + +ir_rvalue * +ir_mat_op_to_vec_visitor::get_element(ir_variable *var, int col, int row) +{ + ir_dereference *deref; + + deref = new(mem_ctx) ir_dereference_variable(var); + + if (var->type->is_matrix()) { + deref = new(mem_ctx) ir_dereference_array(var, + new(mem_ctx) ir_constant(col)); + } else { + assert(col == 0); + } + + return new(mem_ctx) ir_swizzle(deref, row, 0, 0, 0, 1); +} + +ir_dereference * +ir_mat_op_to_vec_visitor::get_column(ir_variable *var, int row) +{ + ir_dereference *deref; + + if (!var->type->is_matrix()) { + deref = new(mem_ctx) ir_dereference_variable(var); + } else { + deref = new(mem_ctx) ir_dereference_variable(var); + deref = new(mem_ctx) ir_dereference_array(deref, + new(mem_ctx) ir_constant(row)); + } + + return deref; +} + +void +ir_mat_op_to_vec_visitor::do_mul_mat_mat(ir_variable *result_var, + ir_variable *a_var, + ir_variable *b_var) +{ + int b_col, i; + ir_assignment *assign; + ir_expression *expr; + + for (b_col = 0; b_col < b_var->type->matrix_columns; b_col++) { + ir_rvalue *a = get_column(a_var, 0); + ir_rvalue *b = get_element(b_var, b_col, 0); + + /* first column */ + expr = new(mem_ctx) ir_expression(ir_binop_mul, + a->type, + a, + b); + + /* following columns */ + for (i = 1; i < a_var->type->matrix_columns; i++) { + ir_expression *mul_expr; + + a = get_column(a_var, i); + b = get_element(b_var, b_col, i); + + mul_expr = new(mem_ctx) ir_expression(ir_binop_mul, + a->type, + a, + b); + expr = new(mem_ctx) ir_expression(ir_binop_add, + a->type, + expr, + mul_expr); + } + + ir_rvalue *result = get_column(result_var, b_col); + assign = new(mem_ctx) ir_assignment(result, + expr, + NULL); + base_ir->insert_before(assign); + } +} + +void +ir_mat_op_to_vec_visitor::do_mul_mat_vec(ir_variable *result_var, + ir_variable *a_var, + ir_variable *b_var) +{ + int i; + ir_rvalue *a = get_column(a_var, 0); + ir_rvalue *b = get_element(b_var, 0, 0); + ir_assignment *assign; + ir_expression *expr; + + /* first column */ + expr = new(mem_ctx) ir_expression(ir_binop_mul, + result_var->type, + a, + b); + + /* following columns */ + for (i = 1; i < a_var->type->matrix_columns; i++) { + ir_expression *mul_expr; + + a = get_column(a_var, i); + b = get_element(b_var, 0, i); + + mul_expr = new(mem_ctx) ir_expression(ir_binop_mul, + result_var->type, + a, + b); + expr = new(mem_ctx) ir_expression(ir_binop_add, + result_var->type, + expr, + mul_expr); + } + + ir_rvalue *result = new(mem_ctx) ir_dereference_variable(result_var); + assign = new(mem_ctx) ir_assignment(result, + expr, + NULL); + base_ir->insert_before(assign); +} + +void +ir_mat_op_to_vec_visitor::do_mul_vec_mat(ir_variable *result_var, + ir_variable *a_var, + ir_variable *b_var) +{ + int i; + + for (i = 0; i < b_var->type->matrix_columns; i++) { + ir_rvalue *a = new(mem_ctx) ir_dereference_variable(a_var); + ir_rvalue *b = get_column(b_var, i); + ir_rvalue *result; + ir_expression *column_expr; + ir_assignment *column_assign; + + result = new(mem_ctx) ir_dereference_variable(result_var); + result = new(mem_ctx) ir_swizzle(result, i, 0, 0, 0, 1); + + column_expr = new(mem_ctx) ir_expression(ir_binop_dot, + result->type, + a, + b); + + column_assign = new(mem_ctx) ir_assignment(result, + column_expr, + NULL); + base_ir->insert_before(column_assign); + } +} + +void +ir_mat_op_to_vec_visitor::do_mul_mat_scalar(ir_variable *result_var, + ir_variable *a_var, + ir_variable *b_var) +{ + int i; + + for (i = 0; i < a_var->type->matrix_columns; i++) { + ir_rvalue *a = get_column(a_var, i); + ir_rvalue *b = new(mem_ctx) ir_dereference_variable(b_var); + ir_rvalue *result = get_column(result_var, i); + ir_expression *column_expr; + ir_assignment *column_assign; + + column_expr = new(mem_ctx) ir_expression(ir_binop_mul, + result->type, + a, + b); + + column_assign = new(mem_ctx) ir_assignment(result, + column_expr, + NULL); + base_ir->insert_before(column_assign); + } +} + +void +ir_mat_op_to_vec_visitor::do_equal_mat_mat(ir_variable *result_var, + ir_variable *a_var, + ir_variable *b_var, + bool test_equal) +{ + /* This essentially implements the following GLSL: + * + * bool equal(mat4 a, mat4 b) + * { + * return !any(bvec4(a[0] != b[0], + * a[1] != b[1], + * a[2] != b[2], + * a[3] != b[3]); + * } + * + * bool nequal(mat4 a, mat4 b) + * { + * return any(bvec4(a[0] != b[0], + * a[1] != b[1], + * a[2] != b[2], + * a[3] != b[3]); + * } + */ + const unsigned columns = a_var->type->matrix_columns; + const glsl_type *const bvec_type = + glsl_type::get_instance(GLSL_TYPE_BOOL, columns, 1); + + ir_variable *const tmp_bvec = + new(this->mem_ctx) ir_variable(bvec_type, "mat_cmp_bvec", + ir_var_temporary); + this->base_ir->insert_before(tmp_bvec); + + for (unsigned i = 0; i < columns; i++) { + ir_dereference *const op0 = get_column(a_var, i); + ir_dereference *const op1 = get_column(b_var, i); + + ir_expression *const cmp = + new(this->mem_ctx) ir_expression(ir_binop_any_nequal, + glsl_type::bool_type, op0, op1); + + ir_dereference *const lhs = + new(this->mem_ctx) ir_dereference_variable(tmp_bvec); + + ir_assignment *const assign = + new(this->mem_ctx) ir_assignment(lhs, cmp, NULL, (1U << i)); + + this->base_ir->insert_before(assign); + } + + ir_rvalue *const val = + new(this->mem_ctx) ir_dereference_variable(tmp_bvec); + + ir_expression *any = + new(this->mem_ctx) ir_expression(ir_unop_any, glsl_type::bool_type, + val, NULL); + + if (test_equal) + any = new(this->mem_ctx) ir_expression(ir_unop_logic_not, + glsl_type::bool_type, + any, NULL); + + ir_rvalue *const result = + new(this->mem_ctx) ir_dereference_variable(result_var); + + ir_assignment *const assign = + new(mem_ctx) ir_assignment(result, any, NULL); + base_ir->insert_before(assign); +} + +static bool +has_matrix_operand(const ir_expression *expr, unsigned &columns) +{ + for (unsigned i = 0; i < expr->get_num_operands(); i++) { + if (expr->operands[i]->type->is_matrix()) { + columns = expr->operands[i]->type->matrix_columns; + return true; + } + } + + return false; +} + + +ir_visitor_status +ir_mat_op_to_vec_visitor::visit_leave(ir_assignment *orig_assign) +{ + ir_expression *orig_expr = orig_assign->rhs->as_expression(); + unsigned int i, matrix_columns = 1; + ir_variable *op_var[2]; + + if (!orig_expr) + return visit_continue; + + if (!has_matrix_operand(orig_expr, matrix_columns)) + return visit_continue; + + assert(orig_expr->get_num_operands() <= 2); + + mem_ctx = ralloc_parent(orig_assign); + + ir_dereference_variable *lhs_deref = + orig_assign->lhs->as_dereference_variable(); + assert(lhs_deref); + + ir_variable *result_var = lhs_deref->var; + + /* Store the expression operands in temps so we can use them + * multiple times. + */ + for (i = 0; i < orig_expr->get_num_operands(); i++) { + ir_assignment *assign; + + op_var[i] = new(mem_ctx) ir_variable(orig_expr->operands[i]->type, + "mat_op_to_vec", + ir_var_temporary); + base_ir->insert_before(op_var[i]); + + lhs_deref = new(mem_ctx) ir_dereference_variable(op_var[i]); + assign = new(mem_ctx) ir_assignment(lhs_deref, + orig_expr->operands[i], + NULL); + base_ir->insert_before(assign); + } + + /* OK, time to break down this matrix operation. */ + switch (orig_expr->operation) { + case ir_unop_neg: { + const unsigned mask = (1U << result_var->type->vector_elements) - 1; + + /* Apply the operation to each column.*/ + for (i = 0; i < matrix_columns; i++) { + ir_rvalue *op0 = get_column(op_var[0], i); + ir_dereference *result = get_column(result_var, i); + ir_expression *column_expr; + ir_assignment *column_assign; + + column_expr = new(mem_ctx) ir_expression(orig_expr->operation, + result->type, + op0, + NULL); + + column_assign = new(mem_ctx) ir_assignment(result, + column_expr, + NULL, + mask); + assert(column_assign->write_mask != 0); + base_ir->insert_before(column_assign); + } + break; + } + case ir_binop_add: + case ir_binop_sub: + case ir_binop_div: + case ir_binop_mod: { + const unsigned mask = (1U << result_var->type->vector_elements) - 1; + + /* For most operations, the matrix version is just going + * column-wise through and applying the operation to each column + * if available. + */ + for (i = 0; i < matrix_columns; i++) { + ir_rvalue *op0 = get_column(op_var[0], i); + ir_rvalue *op1 = get_column(op_var[1], i); + ir_dereference *result = get_column(result_var, i); + ir_expression *column_expr; + ir_assignment *column_assign; + + column_expr = new(mem_ctx) ir_expression(orig_expr->operation, + result->type, + op0, + op1); + + column_assign = new(mem_ctx) ir_assignment(result, + column_expr, + NULL, + mask); + assert(column_assign->write_mask != 0); + base_ir->insert_before(column_assign); + } + break; + } + case ir_binop_mul: + if (op_var[0]->type->is_matrix()) { + if (op_var[1]->type->is_matrix()) { + do_mul_mat_mat(result_var, op_var[0], op_var[1]); + } else if (op_var[1]->type->is_vector()) { + do_mul_mat_vec(result_var, op_var[0], op_var[1]); + } else { + assert(op_var[1]->type->is_scalar()); + do_mul_mat_scalar(result_var, op_var[0], op_var[1]); + } + } else { + assert(op_var[1]->type->is_matrix()); + if (op_var[0]->type->is_vector()) { + do_mul_vec_mat(result_var, op_var[0], op_var[1]); + } else { + assert(op_var[0]->type->is_scalar()); + do_mul_mat_scalar(result_var, op_var[1], op_var[0]); + } + } + break; + + case ir_binop_all_equal: + case ir_binop_any_nequal: + do_equal_mat_mat(result_var, op_var[1], op_var[0], + (orig_expr->operation == ir_binop_all_equal)); + break; + + default: + printf("FINISHME: Handle matrix operation for %s\n", + orig_expr->operator_string()); + abort(); + } + orig_assign->remove(); + this->made_progress = true; + + return visit_continue; +} diff --git a/src/glsl/lower_noise.cpp b/src/glsl/lower_noise.cpp new file mode 100644 index 0000000..85f59b6 --- /dev/null +++ b/src/glsl/lower_noise.cpp @@ -0,0 +1,71 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file lower_noise.cpp + * IR lower pass to remove noise opcodes. + * + * \author Ian Romanick + */ + +#include "ir.h" +#include "ir_rvalue_visitor.h" + +class lower_noise_visitor : public ir_rvalue_visitor { +public: + lower_noise_visitor() : progress(false) + { + /* empty */ + } + + void handle_rvalue(ir_rvalue **rvalue) + { + if (!*rvalue) + return; + + ir_expression *expr = (*rvalue)->as_expression(); + if (!expr) + return; + + /* In the future, ir_unop_noise may be replaced by a call to a function + * that implements noise. No hardware has a noise instruction. + */ + if (expr->operation == ir_unop_noise) { + *rvalue = ir_constant::zero(ralloc_parent(expr), expr->type); + this->progress = true; + } + } + + bool progress; +}; + + +bool +lower_noise(exec_list *instructions) +{ + lower_noise_visitor v; + + visit_list_elements(&v, instructions); + + return v.progress; +} diff --git a/src/glsl/lower_texture_projection.cpp b/src/glsl/lower_texture_projection.cpp new file mode 100644 index 0000000..6e3aaec --- /dev/null +++ b/src/glsl/lower_texture_projection.cpp @@ -0,0 +1,99 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file lower_texture_projection.cpp + * + * IR lower pass to perform the division of texture coordinates by the texture + * projector if present. + * + * Many GPUs have a texture sampling opcode that takes the projector + * and does the divide internally, thus the presence of the projector + * in the IR. For GPUs that don't, this saves the driver needing the + * logic for handling the divide. + * + * \author Eric Anholt + */ + +#include "ir.h" + +class lower_texture_projection_visitor : public ir_hierarchical_visitor { +public: + lower_texture_projection_visitor() + { + progress = false; + } + + ir_visitor_status visit_leave(ir_texture *ir); + + bool progress; +}; + +ir_visitor_status +lower_texture_projection_visitor::visit_leave(ir_texture *ir) +{ + if (!ir->projector) + return visit_continue; + + void *mem_ctx = ralloc_parent(ir); + + ir_variable *var = new(mem_ctx) ir_variable(ir->projector->type, + "projector", ir_var_auto); + base_ir->insert_before(var); + ir_dereference *deref = new(mem_ctx) ir_dereference_variable(var); + ir_expression *expr = new(mem_ctx) ir_expression(ir_unop_rcp, + ir->projector->type, + ir->projector, + NULL); + ir_assignment *assign = new(mem_ctx) ir_assignment(deref, expr, NULL); + base_ir->insert_before(assign); + + deref = new(mem_ctx) ir_dereference_variable(var); + ir->coordinate = new(mem_ctx) ir_expression(ir_binop_mul, + ir->coordinate->type, + ir->coordinate, + deref); + + if (ir->shadow_comparitor) { + deref = new(mem_ctx) ir_dereference_variable(var); + ir->shadow_comparitor = new(mem_ctx) ir_expression(ir_binop_mul, + ir->shadow_comparitor->type, + ir->shadow_comparitor, + deref); + } + + ir->projector = NULL; + + progress = true; + return visit_continue; +} + +bool +do_lower_texture_projection(exec_list *instructions) +{ + lower_texture_projection_visitor v; + + visit_list_elements(&v, instructions); + + return v.progress; +} diff --git a/src/glsl/lower_variable_index_to_cond_assign.cpp b/src/glsl/lower_variable_index_to_cond_assign.cpp new file mode 100644 index 0000000..147a6ae --- /dev/null +++ b/src/glsl/lower_variable_index_to_cond_assign.cpp @@ -0,0 +1,382 @@ +/* + * Copyright © 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file lower_variable_index_to_cond_assign.cpp + * + * Turns non-constant indexing into array types to a series of + * conditional moves of each element into a temporary. + * + * Pre-DX10 GPUs often don't have a native way to do this operation, + * and this works around that. + */ + +#include "ir.h" +#include "ir_rvalue_visitor.h" +#include "ir_optimization.h" +#include "glsl_types.h" +#include "main/macros.h" + +struct assignment_generator +{ + ir_instruction* base_ir; + ir_rvalue* array; + bool is_write; + unsigned int write_mask; + ir_variable* var; + + assignment_generator() + { + } + + void generate(unsigned i, ir_rvalue* condition, exec_list *list) const + { + /* Just clone the rest of the deref chain when trying to get at the + * underlying variable. + */ + void *mem_ctx = ralloc_parent(base_ir); + ir_dereference *element = + new(mem_ctx) ir_dereference_array(this->array->clone(mem_ctx, NULL), + new(mem_ctx) ir_constant(i)); + ir_rvalue *variable = new(mem_ctx) ir_dereference_variable(this->var); + + ir_assignment *assignment; + if (is_write) { + assignment = new(mem_ctx) ir_assignment(element, variable, condition, + write_mask); + } else { + assignment = new(mem_ctx) ir_assignment(variable, element, condition); + } + + list->push_tail(assignment); + } +}; + +struct switch_generator +{ + /* make TFunction a template parameter if you need to use other generators */ + typedef assignment_generator TFunction; + const TFunction& generator; + + ir_variable* index; + unsigned linear_sequence_max_length; + unsigned condition_components; + + void *mem_ctx; + + switch_generator(const TFunction& generator, ir_variable *index, + unsigned linear_sequence_max_length, + unsigned condition_components) + : generator(generator), index(index), + linear_sequence_max_length(linear_sequence_max_length), + condition_components(condition_components) + { + this->mem_ctx = ralloc_parent(index); + } + + void linear_sequence(unsigned begin, unsigned end, exec_list *list) + { + if (begin == end) + return; + + /* If the array access is a read, read the first element of this subregion + * unconditionally. The remaining tests will possibly overwrite this + * value with one of the other array elements. + * + * This optimization cannot be done for writes because it will cause the + * first element of the subregion to be written possibly *in addition* to + * one of the other elements. + */ + unsigned first; + if (!this->generator.is_write) { + this->generator.generate(begin, 0, list); + first = begin + 1; + } else { + first = begin; + } + + for (unsigned i = first; i < end; i += 4) { + const unsigned comps = MIN2(condition_components, end - i); + + ir_rvalue *broadcast_index = + new(this->mem_ctx) ir_dereference_variable(index); + + if (comps) { + const ir_swizzle_mask m = { 0, 0, 0, 0, comps, false }; + broadcast_index = new(this->mem_ctx) ir_swizzle(broadcast_index, m); + } + + /* Compare the desired index value with the next block of four indices. + */ + ir_constant_data test_indices_data; + memset(&test_indices_data, 0, sizeof(test_indices_data)); + test_indices_data.i[0] = i; + test_indices_data.i[1] = i + 1; + test_indices_data.i[2] = i + 2; + test_indices_data.i[3] = i + 3; + ir_constant *const test_indices = + new(this->mem_ctx) ir_constant(broadcast_index->type, + &test_indices_data); + + ir_rvalue *const condition_val = + new(this->mem_ctx) ir_expression(ir_binop_equal, + &glsl_type::bool_type[comps - 1], + broadcast_index, + test_indices); + + ir_variable *const condition = + new(this->mem_ctx) ir_variable(condition_val->type, + "dereference_array_condition", + ir_var_temporary); + list->push_tail(condition); + + ir_rvalue *const cond_deref = + new(this->mem_ctx) ir_dereference_variable(condition); + list->push_tail(new(this->mem_ctx) ir_assignment(cond_deref, + condition_val, 0)); + + if (comps == 1) { + ir_rvalue *const cond_deref = + new(this->mem_ctx) ir_dereference_variable(condition); + + this->generator.generate(i, cond_deref, list); + } else { + for (unsigned j = 0; j < comps; j++) { + ir_rvalue *const cond_deref = + new(this->mem_ctx) ir_dereference_variable(condition); + ir_rvalue *const cond_swiz = + new(this->mem_ctx) ir_swizzle(cond_deref, j, 0, 0, 0, 1); + + this->generator.generate(i + j, cond_swiz, list); + } + } + } + } + + void bisect(unsigned begin, unsigned end, exec_list *list) + { + unsigned middle = (begin + end) >> 1; + + assert(index->type->is_integer()); + + ir_constant *const middle_c = (index->type->base_type == GLSL_TYPE_UINT) + ? new(this->mem_ctx) ir_constant((unsigned)middle) + : new(this->mem_ctx) ir_constant((int)middle); + + + ir_dereference_variable *deref = + new(this->mem_ctx) ir_dereference_variable(this->index); + + ir_expression *less = + new(this->mem_ctx) ir_expression(ir_binop_less, glsl_type::bool_type, + deref, middle_c); + + ir_if *if_less = new(this->mem_ctx) ir_if(less); + + generate(begin, middle, &if_less->then_instructions); + generate(middle, end, &if_less->else_instructions); + + list->push_tail(if_less); + } + + void generate(unsigned begin, unsigned end, exec_list *list) + { + unsigned length = end - begin; + if (length <= this->linear_sequence_max_length) + return linear_sequence(begin, end, list); + else + return bisect(begin, end, list); + } +}; + +/** + * Visitor class for replacing expressions with ir_constant values. + */ + +class variable_index_to_cond_assign_visitor : public ir_rvalue_visitor { +public: + variable_index_to_cond_assign_visitor(bool lower_input, + bool lower_output, + bool lower_temp, + bool lower_uniform) + { + this->progress = false; + this->lower_inputs = lower_input; + this->lower_outputs = lower_output; + this->lower_temps = lower_temp; + this->lower_uniforms = lower_uniform; + } + + bool progress; + bool lower_inputs; + bool lower_outputs; + bool lower_temps; + bool lower_uniforms; + + bool is_array_or_matrix(const ir_instruction *ir) const + { + return (ir->type->is_array() || ir->type->is_matrix()); + } + + bool needs_lowering(ir_dereference_array *deref) const + { + if (deref == NULL || deref->array_index->as_constant() + || !is_array_or_matrix(deref->array)) + return false; + + if (deref->array->ir_type == ir_type_constant) + return this->lower_temps; + + const ir_variable *const var = deref->array->variable_referenced(); + switch (var->mode) { + case ir_var_auto: + case ir_var_temporary: + return this->lower_temps; + case ir_var_uniform: + return this->lower_uniforms; + case ir_var_in: + return (var->location == -1) ? this->lower_temps : this->lower_inputs; + case ir_var_out: + return (var->location == -1) ? this->lower_temps : this->lower_outputs; + case ir_var_inout: + return this->lower_temps; + } + + assert(!"Should not get here."); + return false; + } + + ir_variable *convert_dereference_array(ir_dereference_array *orig_deref, + ir_assignment* orig_assign) + { + assert(is_array_or_matrix(orig_deref->array)); + + const unsigned length = (orig_deref->array->type->is_array()) + ? orig_deref->array->type->length + : orig_deref->array->type->matrix_columns; + + void *const mem_ctx = ralloc_parent(base_ir); + + /* Temporary storage for either the result of the dereference of + * the array, or the RHS that's being assigned into the + * dereference of the array. + */ + ir_variable *var; + + if (orig_assign) { + var = new(mem_ctx) ir_variable(orig_assign->rhs->type, + "dereference_array_value", + ir_var_temporary); + base_ir->insert_before(var); + + ir_dereference *lhs = new(mem_ctx) ir_dereference_variable(var); + ir_assignment *assign = new(mem_ctx) ir_assignment(lhs, + orig_assign->rhs, + NULL); + + base_ir->insert_before(assign); + } else { + var = new(mem_ctx) ir_variable(orig_deref->type, + "dereference_array_value", + ir_var_temporary); + base_ir->insert_before(var); + } + + /* Store the index to a temporary to avoid reusing its tree. */ + ir_variable *index = + new(mem_ctx) ir_variable(orig_deref->array_index->type, + "dereference_array_index", ir_var_temporary); + base_ir->insert_before(index); + + ir_dereference *lhs = new(mem_ctx) ir_dereference_variable(index); + ir_assignment *assign = + new(mem_ctx) ir_assignment(lhs, orig_deref->array_index, NULL); + base_ir->insert_before(assign); + + assignment_generator ag; + ag.array = orig_deref->array; + ag.base_ir = base_ir; + ag.var = var; + if (orig_assign) { + ag.is_write = true; + ag.write_mask = orig_assign->write_mask; + } else { + ag.is_write = false; + } + + switch_generator sg(ag, index, 4, 4); + + exec_list list; + sg.generate(0, length, &list); + base_ir->insert_before(&list); + + return var; + } + + virtual void handle_rvalue(ir_rvalue **pir) + { + if (!*pir) + return; + + ir_dereference_array* orig_deref = (*pir)->as_dereference_array(); + if (needs_lowering(orig_deref)) { + ir_variable* var = convert_dereference_array(orig_deref, 0); + assert(var); + *pir = new(ralloc_parent(base_ir)) ir_dereference_variable(var); + this->progress = true; + } + } + + ir_visitor_status + visit_leave(ir_assignment *ir) + { + ir_rvalue_visitor::visit_leave(ir); + + ir_dereference_array *orig_deref = ir->lhs->as_dereference_array(); + + if (needs_lowering(orig_deref)) { + convert_dereference_array(orig_deref, ir); + ir->remove(); + this->progress = true; + } + + return visit_continue; + } +}; + +bool +lower_variable_index_to_cond_assign(exec_list *instructions, + bool lower_input, + bool lower_output, + bool lower_temp, + bool lower_uniform) +{ + variable_index_to_cond_assign_visitor v(lower_input, + lower_output, + lower_temp, + lower_uniform); + + visit_list_elements(&v, instructions); + + return v.progress; +} diff --git a/src/glsl/lower_vec_index_to_cond_assign.cpp b/src/glsl/lower_vec_index_to_cond_assign.cpp new file mode 100644 index 0000000..3c4d932 --- /dev/null +++ b/src/glsl/lower_vec_index_to_cond_assign.cpp @@ -0,0 +1,258 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file lower_vec_index_to_cond_assign.cpp + * + * Turns indexing into vector types to a series of conditional moves + * of each channel's swizzle into a temporary. + * + * Most GPUs don't have a native way to do this operation, and this + * works around that. For drivers using both this pass and + * ir_vec_index_to_swizzle, there's a risk that this pass will happen + * before sufficient constant folding to find that the array index is + * constant. However, we hope that other optimization passes, + * particularly constant folding of assignment conditions and copy + * propagation, will result in the same code in the end. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_optimization.h" +#include "glsl_types.h" + +/** + * Visitor class for replacing expressions with ir_constant values. + */ + +class ir_vec_index_to_cond_assign_visitor : public ir_hierarchical_visitor { +public: + ir_vec_index_to_cond_assign_visitor() + { + progress = false; + } + + ir_rvalue *convert_vec_index_to_cond_assign(ir_rvalue *val); + + virtual ir_visitor_status visit_enter(ir_expression *); + virtual ir_visitor_status visit_enter(ir_swizzle *); + virtual ir_visitor_status visit_leave(ir_assignment *); + virtual ir_visitor_status visit_enter(ir_return *); + virtual ir_visitor_status visit_enter(ir_call *); + virtual ir_visitor_status visit_enter(ir_if *); + + bool progress; +}; + +ir_rvalue * +ir_vec_index_to_cond_assign_visitor::convert_vec_index_to_cond_assign(ir_rvalue *ir) +{ + ir_dereference_array *orig_deref = ir->as_dereference_array(); + ir_assignment *assign; + ir_variable *index, *var; + ir_dereference *deref; + ir_expression *condition; + ir_swizzle *swizzle; + int i; + + if (!orig_deref) + return ir; + + if (orig_deref->array->type->is_matrix() || + orig_deref->array->type->is_array()) + return ir; + + void *mem_ctx = ralloc_parent(ir); + + assert(orig_deref->array_index->type->base_type == GLSL_TYPE_INT); + + /* Store the index to a temporary to avoid reusing its tree. */ + index = new(base_ir) ir_variable(glsl_type::int_type, + "vec_index_tmp_i", + ir_var_temporary); + base_ir->insert_before(index); + deref = new(base_ir) ir_dereference_variable(index); + assign = new(base_ir) ir_assignment(deref, orig_deref->array_index, NULL); + base_ir->insert_before(assign); + + /* Temporary where we store whichever value we swizzle out. */ + var = new(base_ir) ir_variable(ir->type, "vec_index_tmp_v", + ir_var_temporary); + base_ir->insert_before(var); + + /* Generate a conditional move of each vector element to the temp. */ + for (i = 0; i < orig_deref->array->type->vector_elements; i++) { + deref = new(base_ir) ir_dereference_variable(index); + condition = new(base_ir) ir_expression(ir_binop_equal, + glsl_type::bool_type, + deref, + new(base_ir) ir_constant(i)); + + /* Just clone the rest of the deref chain when trying to get at the + * underlying variable. + */ + swizzle = new(base_ir) ir_swizzle(orig_deref->array->clone(mem_ctx, NULL), + i, 0, 0, 0, 1); + + deref = new(base_ir) ir_dereference_variable(var); + assign = new(base_ir) ir_assignment(deref, swizzle, condition); + base_ir->insert_before(assign); + } + + this->progress = true; + return new(base_ir) ir_dereference_variable(var); +} + +ir_visitor_status +ir_vec_index_to_cond_assign_visitor::visit_enter(ir_expression *ir) +{ + unsigned int i; + + for (i = 0; i < ir->get_num_operands(); i++) { + ir->operands[i] = convert_vec_index_to_cond_assign(ir->operands[i]); + } + + return visit_continue; +} + +ir_visitor_status +ir_vec_index_to_cond_assign_visitor::visit_enter(ir_swizzle *ir) +{ + /* Can't be hit from normal GLSL, since you can't swizzle a scalar (which + * the result of indexing a vector is. But maybe at some point we'll end up + * using swizzling of scalars for vector construction. + */ + ir->val = convert_vec_index_to_cond_assign(ir->val); + + return visit_continue; +} + +ir_visitor_status +ir_vec_index_to_cond_assign_visitor::visit_leave(ir_assignment *ir) +{ + ir_variable *index, *var; + ir_dereference_variable *deref; + ir_assignment *assign; + int i; + + ir->rhs = convert_vec_index_to_cond_assign(ir->rhs); + if (ir->condition) + ir->condition = convert_vec_index_to_cond_assign(ir->condition); + + /* Last, handle the LHS */ + ir_dereference_array *orig_deref = ir->lhs->as_dereference_array(); + + if (!orig_deref || + orig_deref->array->type->is_matrix() || + orig_deref->array->type->is_array()) + return visit_continue; + + void *mem_ctx = ralloc_parent(ir); + + assert(orig_deref->array_index->type->base_type == GLSL_TYPE_INT); + + /* Store the index to a temporary to avoid reusing its tree. */ + index = new(ir) ir_variable(glsl_type::int_type, "vec_index_tmp_i", + ir_var_temporary); + ir->insert_before(index); + deref = new(ir) ir_dereference_variable(index); + assign = new(ir) ir_assignment(deref, orig_deref->array_index, NULL); + ir->insert_before(assign); + + /* Store the RHS to a temporary to avoid reusing its tree. */ + var = new(ir) ir_variable(ir->rhs->type, "vec_index_tmp_v", + ir_var_temporary); + ir->insert_before(var); + deref = new(ir) ir_dereference_variable(var); + assign = new(ir) ir_assignment(deref, ir->rhs, NULL); + ir->insert_before(assign); + + /* Generate a conditional move of each vector element to the temp. */ + for (i = 0; i < orig_deref->array->type->vector_elements; i++) { + ir_rvalue *condition, *swizzle; + + deref = new(ir) ir_dereference_variable(index); + condition = new(ir) ir_expression(ir_binop_equal, + glsl_type::bool_type, + deref, + new(ir) ir_constant(i)); + + /* Just clone the rest of the deref chain when trying to get at the + * underlying variable. + */ + swizzle = new(ir) ir_swizzle(orig_deref->array->clone(mem_ctx, NULL), + i, 0, 0, 0, 1); + + deref = new(ir) ir_dereference_variable(var); + assign = new(ir) ir_assignment(swizzle, deref, condition); + ir->insert_before(assign); + } + ir->remove(); + + this->progress = true; + + return visit_continue; +} + +ir_visitor_status +ir_vec_index_to_cond_assign_visitor::visit_enter(ir_call *ir) +{ + foreach_iter(exec_list_iterator, iter, *ir) { + ir_rvalue *param = (ir_rvalue *)iter.get(); + ir_rvalue *new_param = convert_vec_index_to_cond_assign(param); + + if (new_param != param) { + param->replace_with(new_param); + } + } + + return visit_continue; +} + +ir_visitor_status +ir_vec_index_to_cond_assign_visitor::visit_enter(ir_return *ir) +{ + if (ir->value) { + ir->value = convert_vec_index_to_cond_assign(ir->value); + } + + return visit_continue; +} + +ir_visitor_status +ir_vec_index_to_cond_assign_visitor::visit_enter(ir_if *ir) +{ + ir->condition = convert_vec_index_to_cond_assign(ir->condition); + + return visit_continue; +} + +bool +do_vec_index_to_cond_assign(exec_list *instructions) +{ + ir_vec_index_to_cond_assign_visitor v; + + visit_list_elements(&v, instructions); + + return v.progress; +} diff --git a/src/glsl/lower_vec_index_to_swizzle.cpp b/src/glsl/lower_vec_index_to_swizzle.cpp new file mode 100644 index 0000000..c7630c2 --- /dev/null +++ b/src/glsl/lower_vec_index_to_swizzle.cpp @@ -0,0 +1,157 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file lower_vec_index_to_swizzle.cpp + * + * Turns constant indexing into vector types to swizzles. This will + * let other swizzle-aware optimization passes catch these constructs, + * and codegen backends not have to worry about this case. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_optimization.h" +#include "glsl_types.h" + +/** + * Visitor class for replacing expressions with ir_constant values. + */ + +class ir_vec_index_to_swizzle_visitor : public ir_hierarchical_visitor { +public: + ir_vec_index_to_swizzle_visitor() + { + progress = false; + } + + ir_rvalue *convert_vec_index_to_swizzle(ir_rvalue *val); + + virtual ir_visitor_status visit_enter(ir_expression *); + virtual ir_visitor_status visit_enter(ir_swizzle *); + virtual ir_visitor_status visit_enter(ir_assignment *); + virtual ir_visitor_status visit_enter(ir_return *); + virtual ir_visitor_status visit_enter(ir_call *); + virtual ir_visitor_status visit_enter(ir_if *); + + bool progress; +}; + +ir_rvalue * +ir_vec_index_to_swizzle_visitor::convert_vec_index_to_swizzle(ir_rvalue *ir) +{ + ir_dereference_array *deref = ir->as_dereference_array(); + ir_constant *ir_constant; + + if (!deref) + return ir; + + if (deref->array->type->is_matrix() || deref->array->type->is_array()) + return ir; + + assert(deref->array_index->type->base_type == GLSL_TYPE_INT); + ir_constant = deref->array_index->constant_expression_value(); + if (!ir_constant) + return ir; + + void *ctx = ralloc_parent(ir); + this->progress = true; + return new(ctx) ir_swizzle(deref->array, + ir_constant->value.i[0], 0, 0, 0, 1); +} + +ir_visitor_status +ir_vec_index_to_swizzle_visitor::visit_enter(ir_expression *ir) +{ + unsigned int i; + + for (i = 0; i < ir->get_num_operands(); i++) { + ir->operands[i] = convert_vec_index_to_swizzle(ir->operands[i]); + } + + return visit_continue; +} + +ir_visitor_status +ir_vec_index_to_swizzle_visitor::visit_enter(ir_swizzle *ir) +{ + /* Can't be hit from normal GLSL, since you can't swizzle a scalar (which + * the result of indexing a vector is. But maybe at some point we'll end up + * using swizzling of scalars for vector construction. + */ + ir->val = convert_vec_index_to_swizzle(ir->val); + + return visit_continue; +} + +ir_visitor_status +ir_vec_index_to_swizzle_visitor::visit_enter(ir_assignment *ir) +{ + ir->set_lhs(convert_vec_index_to_swizzle(ir->lhs)); + ir->rhs = convert_vec_index_to_swizzle(ir->rhs); + + return visit_continue; +} + +ir_visitor_status +ir_vec_index_to_swizzle_visitor::visit_enter(ir_call *ir) +{ + foreach_iter(exec_list_iterator, iter, *ir) { + ir_rvalue *param = (ir_rvalue *)iter.get(); + ir_rvalue *new_param = convert_vec_index_to_swizzle(param); + + if (new_param != param) { + param->replace_with(new_param); + } + } + + return visit_continue; +} + +ir_visitor_status +ir_vec_index_to_swizzle_visitor::visit_enter(ir_return *ir) +{ + if (ir->value) { + ir->value = convert_vec_index_to_swizzle(ir->value); + } + + return visit_continue; +} + +ir_visitor_status +ir_vec_index_to_swizzle_visitor::visit_enter(ir_if *ir) +{ + ir->condition = convert_vec_index_to_swizzle(ir->condition); + + return visit_continue; +} + +bool +do_vec_index_to_swizzle(exec_list *instructions) +{ + ir_vec_index_to_swizzle_visitor v; + + v.run(instructions); + + return v.progress; +} diff --git a/src/glsl/lower_vector.cpp b/src/glsl/lower_vector.cpp new file mode 100644 index 0000000..57963a1 --- /dev/null +++ b/src/glsl/lower_vector.cpp @@ -0,0 +1,224 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file lower_vector.cpp + * IR lowering pass to remove some types of ir_quadop_vector + * + * \author Ian Romanick + */ + +#include "ir.h" +#include "ir_rvalue_visitor.h" + +class lower_vector_visitor : public ir_rvalue_visitor { +public: + lower_vector_visitor() : progress(false) + { + /* empty */ + } + + void handle_rvalue(ir_rvalue **rvalue); + + /** + * Should SWZ-like expressions be lowered? + */ + bool dont_lower_swz; + + bool progress; +}; + +/** + * Determine if an IR expression tree looks like an extended swizzle + * + * Extended swizzles consist of access of a single vector source (with possible + * per component negation) and the constants -1, 0, or 1. + */ +bool +is_extended_swizzle(ir_expression *ir) +{ + /* Track any variables that are accessed by this expression. + */ + ir_variable *var = NULL; + + assert(ir->operation == ir_quadop_vector); + + for (unsigned i = 0; i < ir->type->vector_elements; i++) { + ir_rvalue *op = ir->operands[i]; + + while (op != NULL) { + switch (op->ir_type) { + case ir_type_constant: { + const ir_constant *const c = op->as_constant(); + + if (!c->is_one() && !c->is_zero() && !c->is_negative_one()) + return false; + + op = NULL; + break; + } + + case ir_type_dereference_variable: { + ir_dereference_variable *const d = (ir_dereference_variable *) op; + + if ((var != NULL) && (var != d->var)) + return false; + + var = d->var; + op = NULL; + break; + } + + case ir_type_expression: { + ir_expression *const ex = (ir_expression *) op; + + if (ex->operation != ir_unop_neg) + return false; + + op = ex->operands[0]; + break; + } + + case ir_type_swizzle: + op = ((ir_swizzle *) op)->val; + break; + + default: + return false; + } + } + } + + return true; +} + +void +lower_vector_visitor::handle_rvalue(ir_rvalue **rvalue) +{ + if (!*rvalue) + return; + + ir_expression *expr = (*rvalue)->as_expression(); + if ((expr == NULL) || (expr->operation != ir_quadop_vector)) + return; + + if (this->dont_lower_swz && is_extended_swizzle(expr)) + return; + + /* FINISHME: Is this the right thing to use for the ralloc context? + */ + void *const mem_ctx = expr; + + assert(expr->type->vector_elements == expr->get_num_operands()); + + /* Generate a temporary with the same type as the ir_quadop_operation. + */ + ir_variable *const temp = + new(mem_ctx) ir_variable(expr->type, "vecop_tmp", ir_var_temporary); + + this->base_ir->insert_before(temp); + + /* Counter of the number of components collected so far. + */ + unsigned assigned; + + /* Write-mask in the destination that receives counted by 'assigned'. + */ + unsigned write_mask; + + + /* Generate upto four assignments to that variable. Try to group component + * assignments together: + * + * - All constant components can be assigned at once. + * - All assigments of components from a single variable with the same + * unary operator can be assigned at once. + */ + ir_constant_data d = { { 0 } }; + + assigned = 0; + write_mask = 0; + for (unsigned i = 0; i < expr->type->vector_elements; i++) { + const ir_constant *const c = expr->operands[i]->as_constant(); + + if (c == NULL) + continue; + + switch (expr->type->base_type) { + case GLSL_TYPE_UINT: d.u[assigned] = c->value.u[0]; break; + case GLSL_TYPE_INT: d.i[assigned] = c->value.i[0]; break; + case GLSL_TYPE_FLOAT: d.f[assigned] = c->value.f[0]; break; + case GLSL_TYPE_BOOL: d.b[assigned] = c->value.b[0]; break; + default: assert(!"Should not get here."); break; + } + + write_mask |= (1U << i); + assigned++; + } + + assert((write_mask == 0) == (assigned == 0)); + + /* If there were constant values, generate an assignment. + */ + if (assigned > 0) { + ir_constant *const c = + new(mem_ctx) ir_constant(glsl_type::get_instance(expr->type->base_type, + assigned, 0), + &d); + ir_dereference *const lhs = new(mem_ctx) ir_dereference_variable(temp); + ir_assignment *const assign = + new(mem_ctx) ir_assignment(lhs, c, NULL, write_mask); + + this->base_ir->insert_before(assign); + } + + /* FINISHME: This should try to coalesce assignments. + */ + for (unsigned i = 0; i < expr->type->vector_elements; i++) { + if (expr->operands[i]->ir_type == ir_type_constant) + continue; + + ir_dereference *const lhs = new(mem_ctx) ir_dereference_variable(temp); + ir_assignment *const assign = + new(mem_ctx) ir_assignment(lhs, expr->operands[i], NULL, (1U << i)); + + this->base_ir->insert_before(assign); + assigned++; + } + + assert(assigned == expr->type->vector_elements); + + *rvalue = new(mem_ctx) ir_dereference_variable(temp); + this->progress = true; +} + +bool +lower_quadop_vector(exec_list *instructions, bool dont_lower_swz) +{ + lower_vector_visitor v; + + v.dont_lower_swz = dont_lower_swz; + visit_list_elements(&v, instructions); + + return v.progress; +} diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp new file mode 100644 index 0000000..1820e19 --- /dev/null +++ b/src/glsl/main.cpp @@ -0,0 +1,338 @@ +/* + * Copyright © 2008, 2009 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#include +#include +#include + +#include +#include +#include +#include + +#include "ast.h" +#include "glsl_parser_extras.h" +#include "glsl_parser.h" +#include "ir_optimization.h" +#include "ir_print_visitor.h" +#include "program.h" +#include "loop_analysis.h" + +extern "C" struct gl_shader * +_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type); + +extern "C" void +_mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr, + struct gl_shader *sh); + +/* Copied from shader_api.c for the stand-alone compiler. + */ +void +_mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr, + struct gl_shader *sh) +{ + *ptr = sh; +} + +struct gl_shader * +_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type) +{ + struct gl_shader *shader; + + (void) ctx; + + assert(type == GL_FRAGMENT_SHADER || type == GL_VERTEX_SHADER); + shader = rzalloc(NULL, struct gl_shader); + if (shader) { + shader->Type = type; + shader->Name = name; + shader->RefCount = 1; + } + return shader; +} + +static void +initialize_context(struct gl_context *ctx, gl_api api) +{ + memset(ctx, 0, sizeof(*ctx)); + + ctx->API = api; + + ctx->Extensions.ARB_ES2_compatibility = GL_TRUE; + ctx->Extensions.ARB_draw_buffers = GL_TRUE; + ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE; + ctx->Extensions.EXT_texture_array = GL_TRUE; + ctx->Extensions.NV_texture_rectangle = GL_TRUE; + + /* GLSL 1.30 isn't fully supported, but we need to advertise 1.30 so that + * the built-in functions for 1.30 can be built. + */ + ctx->Const.GLSLVersion = 130; + + /* 1.10 minimums. */ + ctx->Const.MaxLights = 8; + ctx->Const.MaxClipPlanes = 8; + ctx->Const.MaxTextureUnits = 2; + + /* More than the 1.10 minimum to appease parser tests taken from + * apps that (hopefully) already checked the number of coords. + */ + ctx->Const.MaxTextureCoordUnits = 4; + + ctx->Const.VertexProgram.MaxAttribs = 16; + ctx->Const.VertexProgram.MaxUniformComponents = 512; + ctx->Const.MaxVarying = 8; + ctx->Const.MaxVertexTextureImageUnits = 0; + ctx->Const.MaxCombinedTextureImageUnits = 2; + ctx->Const.MaxTextureImageUnits = 2; + ctx->Const.FragmentProgram.MaxUniformComponents = 64; + + ctx->Const.MaxDrawBuffers = 2; + + ctx->Driver.NewShader = _mesa_new_shader; +} + +/* Returned string will have 'ctx' as its ralloc owner. */ +static char * +load_text_file(void *ctx, const char *file_name) +{ + char *text = NULL; + struct stat st; + ssize_t total_read = 0; + int fd = open(file_name, O_RDONLY); + + if (fd < 0) { + return NULL; + } + + if (fstat(fd, & st) == 0) { + text = (char *) ralloc_size(ctx, st.st_size + 1); + if (text != NULL) { + do { + ssize_t bytes = read(fd, text + total_read, + st.st_size - total_read); + if (bytes < 0) { + free(text); + text = NULL; + break; + } + + if (bytes == 0) { + break; + } + + total_read += bytes; + } while (total_read < st.st_size); + + text[total_read] = '\0'; + } + } + + close(fd); + + return text; +} + +int glsl_es = 0; +int dump_ast = 0; +int dump_hir = 0; +int dump_lir = 0; +int do_link = 0; + +const struct option compiler_opts[] = { + { "glsl-es", 0, &glsl_es, 1 }, + { "dump-ast", 0, &dump_ast, 1 }, + { "dump-hir", 0, &dump_hir, 1 }, + { "dump-lir", 0, &dump_lir, 1 }, + { "link", 0, &do_link, 1 }, + { NULL, 0, NULL, 0 } +}; + +/** + * \brief Print proper usage and exit with failure. + */ +void +usage_fail(const char *name) +{ + + const char *header = + "usage: %s [options] \n" + "\n" + "Possible options are:\n"; + printf(header, name, name); + for (const struct option *o = compiler_opts; o->name != 0; ++o) { + printf(" --%s\n", o->name); + } + exit(EXIT_FAILURE); +} + + +void +compile_shader(struct gl_context *ctx, struct gl_shader *shader) +{ + struct _mesa_glsl_parse_state *state = + new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader); + + const char *source = shader->Source; + state->error = preprocess(state, &source, &state->info_log, + state->extensions, ctx->API); + + if (!state->error) { + _mesa_glsl_lexer_ctor(state, source); + _mesa_glsl_parse(state); + _mesa_glsl_lexer_dtor(state); + } + + if (dump_ast) { + foreach_list_const(n, &state->translation_unit) { + ast_node *ast = exec_node_data(ast_node, n, link); + ast->print(); + } + printf("\n\n"); + } + + shader->ir = new(shader) exec_list; + if (!state->error && !state->translation_unit.is_empty()) + _mesa_ast_to_hir(shader->ir, state); + + /* Print out the unoptimized IR. */ + if (!state->error && dump_hir) { + validate_ir_tree(shader->ir); + _mesa_print_ir(shader->ir, state); + } + + /* Optimization passes */ + if (!state->error && !shader->ir->is_empty()) { + bool progress; + do { + progress = do_common_optimization(shader->ir, false, 32); + } while (progress); + + validate_ir_tree(shader->ir); + } + + + /* Print out the resulting IR */ + if (!state->error && dump_lir) { + _mesa_print_ir(shader->ir, state); + } + + shader->symbols = state->symbols; + shader->CompileStatus = !state->error; + shader->Version = state->language_version; + memcpy(shader->builtins_to_link, state->builtins_to_link, + sizeof(shader->builtins_to_link[0]) * state->num_builtins_to_link); + shader->num_builtins_to_link = state->num_builtins_to_link; + + if (shader->InfoLog) + ralloc_free(shader->InfoLog); + + shader->InfoLog = state->info_log; + + /* Retain any live IR, but trash the rest. */ + reparent_ir(shader->ir, shader); + + ralloc_free(state); + + return; +} + +int +main(int argc, char **argv) +{ + int status = EXIT_SUCCESS; + struct gl_context local_ctx; + struct gl_context *ctx = &local_ctx; + + int c; + int idx = 0; + while ((c = getopt_long(argc, argv, "", compiler_opts, &idx)) != -1) + /* empty */ ; + + + if (argc <= optind) + usage_fail(argv[0]); + + initialize_context(ctx, (glsl_es) ? API_OPENGLES2 : API_OPENGL); + + struct gl_shader_program *whole_program; + + whole_program = rzalloc (NULL, struct gl_shader_program); + assert(whole_program != NULL); + + for (/* empty */; argc > optind; optind++) { + whole_program->Shaders = + reralloc(whole_program, whole_program->Shaders, + struct gl_shader *, whole_program->NumShaders + 1); + assert(whole_program->Shaders != NULL); + + struct gl_shader *shader = rzalloc(whole_program, gl_shader); + + whole_program->Shaders[whole_program->NumShaders] = shader; + whole_program->NumShaders++; + + const unsigned len = strlen(argv[optind]); + if (len < 6) + usage_fail(argv[0]); + + const char *const ext = & argv[optind][len - 5]; + if (strncmp(".vert", ext, 5) == 0) + shader->Type = GL_VERTEX_SHADER; + else if (strncmp(".geom", ext, 5) == 0) + shader->Type = GL_GEOMETRY_SHADER; + else if (strncmp(".frag", ext, 5) == 0) + shader->Type = GL_FRAGMENT_SHADER; + else + usage_fail(argv[0]); + + shader->Source = load_text_file(whole_program, argv[optind]); + if (shader->Source == NULL) { + printf("File \"%s\" does not exist.\n", argv[optind]); + exit(EXIT_FAILURE); + } + + compile_shader(ctx, shader); + + if (!shader->CompileStatus) { + printf("Info log for %s:\n%s\n", argv[optind], shader->InfoLog); + status = EXIT_FAILURE; + break; + } + } + + if ((status == EXIT_SUCCESS) && do_link) { + link_shaders(ctx, whole_program); + status = (whole_program->LinkStatus) ? EXIT_SUCCESS : EXIT_FAILURE; + + if (strlen(whole_program->InfoLog) > 0) + printf("Info log for linking:\n%s\n", whole_program->InfoLog); + } + + for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) + ralloc_free(whole_program->_LinkedShaders[i]); + + ralloc_free(whole_program); + _mesa_glsl_release_types(); + _mesa_glsl_release_functions(); + + return status; +} diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp new file mode 100644 index 0000000..cade961 --- /dev/null +++ b/src/glsl/opt_algebraic.cpp @@ -0,0 +1,411 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_algebraic.cpp + * + * Takes advantage of association, commutivity, and other algebraic + * properties to simplify expressions. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_rvalue_visitor.h" +#include "ir_optimization.h" +#include "glsl_types.h" + +/** + * Visitor class for replacing expressions with ir_constant values. + */ + +class ir_algebraic_visitor : public ir_rvalue_visitor { +public: + ir_algebraic_visitor() + { + this->progress = false; + this->mem_ctx = NULL; + } + + virtual ~ir_algebraic_visitor() + { + } + + ir_rvalue *handle_expression(ir_expression *ir); + void handle_rvalue(ir_rvalue **rvalue); + bool reassociate_constant(ir_expression *ir1, + int const_index, + ir_constant *constant, + ir_expression *ir2); + void reassociate_operands(ir_expression *ir1, + int op1, + ir_expression *ir2, + int op2); + ir_rvalue *swizzle_if_required(ir_expression *expr, + ir_rvalue *operand); + + void *mem_ctx; + + bool progress; +}; + +static inline bool +is_vec_zero(ir_constant *ir) +{ + return (ir == NULL) ? false : ir->is_zero(); +} + +static inline bool +is_vec_one(ir_constant *ir) +{ + return (ir == NULL) ? false : ir->is_one(); +} + +static void +update_type(ir_expression *ir) +{ + if (ir->operands[0]->type->is_vector()) + ir->type = ir->operands[0]->type; + else + ir->type = ir->operands[1]->type; +} + +void +ir_algebraic_visitor::reassociate_operands(ir_expression *ir1, + int op1, + ir_expression *ir2, + int op2) +{ + ir_rvalue *temp = ir2->operands[op2]; + ir2->operands[op2] = ir1->operands[op1]; + ir1->operands[op1] = temp; + + /* Update the type of ir2. The type of ir1 won't have changed -- + * base types matched, and at least one of the operands of the 2 + * binops is still a vector if any of them were. + */ + update_type(ir2); + + this->progress = true; +} + +/** + * Reassociates a constant down a tree of adds or multiplies. + * + * Consider (2 * (a * (b * 0.5))). We want to send up with a * b. + */ +bool +ir_algebraic_visitor::reassociate_constant(ir_expression *ir1, int const_index, + ir_constant *constant, + ir_expression *ir2) +{ + if (!ir2 || ir1->operation != ir2->operation) + return false; + + /* Don't want to even think about matrices. */ + if (ir1->operands[0]->type->is_matrix() || + ir1->operands[1]->type->is_matrix() || + ir2->operands[0]->type->is_matrix() || + ir2->operands[1]->type->is_matrix()) + return false; + + ir_constant *ir2_const[2]; + ir2_const[0] = ir2->operands[0]->constant_expression_value(); + ir2_const[1] = ir2->operands[1]->constant_expression_value(); + + if (ir2_const[0] && ir2_const[1]) + return false; + + if (ir2_const[0]) { + reassociate_operands(ir1, const_index, ir2, 1); + return true; + } else if (ir2_const[1]) { + reassociate_operands(ir1, const_index, ir2, 0); + return true; + } + + if (reassociate_constant(ir1, const_index, constant, + ir2->operands[0]->as_expression())) { + update_type(ir2); + return true; + } + + if (reassociate_constant(ir1, const_index, constant, + ir2->operands[1]->as_expression())) { + update_type(ir2); + return true; + } + + return false; +} + +/* When eliminating an expression and just returning one of its operands, + * we may need to swizzle that operand out to a vector if the expression was + * vector type. + */ +ir_rvalue * +ir_algebraic_visitor::swizzle_if_required(ir_expression *expr, + ir_rvalue *operand) +{ + if (expr->type->is_vector() && operand->type->is_scalar()) { + return new(mem_ctx) ir_swizzle(operand, 0, 0, 0, 0, + expr->type->vector_elements); + } else + return operand; +} + +ir_rvalue * +ir_algebraic_visitor::handle_expression(ir_expression *ir) +{ + ir_constant *op_const[2] = {NULL, NULL}; + ir_expression *op_expr[2] = {NULL, NULL}; + ir_expression *temp; + unsigned int i; + + assert(ir->get_num_operands() <= 2); + for (i = 0; i < ir->get_num_operands(); i++) { + if (ir->operands[i]->type->is_matrix()) + return ir; + + op_const[i] = ir->operands[i]->constant_expression_value(); + op_expr[i] = ir->operands[i]->as_expression(); + } + + if (this->mem_ctx == NULL) + this->mem_ctx = ralloc_parent(ir); + + switch (ir->operation) { + case ir_unop_logic_not: { + enum ir_expression_operation new_op = ir_unop_logic_not; + + if (op_expr[0] == NULL) + break; + + switch (op_expr[0]->operation) { + case ir_binop_less: new_op = ir_binop_gequal; break; + case ir_binop_greater: new_op = ir_binop_lequal; break; + case ir_binop_lequal: new_op = ir_binop_greater; break; + case ir_binop_gequal: new_op = ir_binop_less; break; + case ir_binop_equal: new_op = ir_binop_nequal; break; + case ir_binop_nequal: new_op = ir_binop_equal; break; + case ir_binop_all_equal: new_op = ir_binop_any_nequal; break; + case ir_binop_any_nequal: new_op = ir_binop_all_equal; break; + + default: + /* The default case handler is here to silence a warning from GCC. + */ + break; + } + + if (new_op != ir_unop_logic_not) { + this->progress = true; + return new(mem_ctx) ir_expression(new_op, + ir->type, + op_expr[0]->operands[0], + op_expr[0]->operands[1]); + } + + break; + } + + case ir_binop_add: + if (is_vec_zero(op_const[0])) { + this->progress = true; + return swizzle_if_required(ir, ir->operands[1]); + } + if (is_vec_zero(op_const[1])) { + this->progress = true; + return swizzle_if_required(ir, ir->operands[0]); + } + + /* Reassociate addition of constants so that we can do constant + * folding. + */ + if (op_const[0] && !op_const[1]) + reassociate_constant(ir, 0, op_const[0], + ir->operands[1]->as_expression()); + if (op_const[1] && !op_const[0]) + reassociate_constant(ir, 1, op_const[1], + ir->operands[0]->as_expression()); + break; + + case ir_binop_sub: + if (is_vec_zero(op_const[0])) { + this->progress = true; + temp = new(mem_ctx) ir_expression(ir_unop_neg, + ir->operands[1]->type, + ir->operands[1], + NULL); + return swizzle_if_required(ir, temp); + } + if (is_vec_zero(op_const[1])) { + this->progress = true; + return swizzle_if_required(ir, ir->operands[0]); + } + break; + + case ir_binop_mul: + if (is_vec_one(op_const[0])) { + this->progress = true; + return swizzle_if_required(ir, ir->operands[1]); + } + if (is_vec_one(op_const[1])) { + this->progress = true; + return swizzle_if_required(ir, ir->operands[0]); + } + + if (is_vec_zero(op_const[0]) || is_vec_zero(op_const[1])) { + this->progress = true; + return ir_constant::zero(ir, ir->type); + } + + /* Reassociate multiplication of constants so that we can do + * constant folding. + */ + if (op_const[0] && !op_const[1]) + reassociate_constant(ir, 0, op_const[0], + ir->operands[1]->as_expression()); + if (op_const[1] && !op_const[0]) + reassociate_constant(ir, 1, op_const[1], + ir->operands[0]->as_expression()); + + break; + + case ir_binop_div: + if (is_vec_one(op_const[0]) && ir->type->base_type == GLSL_TYPE_FLOAT) { + this->progress = true; + temp = new(mem_ctx) ir_expression(ir_unop_rcp, + ir->operands[1]->type, + ir->operands[1], + NULL); + return swizzle_if_required(ir, temp); + } + if (is_vec_one(op_const[1])) { + this->progress = true; + return swizzle_if_required(ir, ir->operands[0]); + } + break; + + case ir_binop_logic_and: + /* FINISHME: Also simplify (a && a) to (a). */ + if (is_vec_one(op_const[0])) { + this->progress = true; + return ir->operands[1]; + } else if (is_vec_one(op_const[1])) { + this->progress = true; + return ir->operands[0]; + } else if (is_vec_zero(op_const[0]) || is_vec_zero(op_const[1])) { + this->progress = true; + return ir_constant::zero(mem_ctx, ir->type); + } + break; + + case ir_binop_logic_xor: + /* FINISHME: Also simplify (a ^^ a) to (false). */ + if (is_vec_zero(op_const[0])) { + this->progress = true; + return ir->operands[1]; + } else if (is_vec_zero(op_const[1])) { + this->progress = true; + return ir->operands[0]; + } else if (is_vec_one(op_const[0])) { + this->progress = true; + return new(mem_ctx) ir_expression(ir_unop_logic_not, ir->type, + ir->operands[1], NULL); + } else if (is_vec_one(op_const[1])) { + this->progress = true; + return new(mem_ctx) ir_expression(ir_unop_logic_not, ir->type, + ir->operands[0], NULL); + } + break; + + case ir_binop_logic_or: + /* FINISHME: Also simplify (a || a) to (a). */ + if (is_vec_zero(op_const[0])) { + this->progress = true; + return ir->operands[1]; + } else if (is_vec_zero(op_const[1])) { + this->progress = true; + return ir->operands[0]; + } else if (is_vec_one(op_const[0]) || is_vec_one(op_const[1])) { + ir_constant_data data; + + for (unsigned i = 0; i < 16; i++) + data.b[i] = true; + + this->progress = true; + return new(mem_ctx) ir_constant(ir->type, &data); + } + break; + + case ir_unop_rcp: + if (op_expr[0] && op_expr[0]->operation == ir_unop_rcp) { + this->progress = true; + return op_expr[0]->operands[0]; + } + + /* FINISHME: We should do rcp(rsq(x)) -> sqrt(x) for some + * backends, except that some backends will have done sqrt -> + * rcp(rsq(x)) and we don't want to undo it for them. + */ + + /* As far as we know, all backends are OK with rsq. */ + if (op_expr[0] && op_expr[0]->operation == ir_unop_sqrt) { + this->progress = true; + temp = new(mem_ctx) ir_expression(ir_unop_rsq, + op_expr[0]->operands[0]->type, + op_expr[0]->operands[0], + NULL); + return swizzle_if_required(ir, temp); + } + + break; + + default: + break; + } + + return ir; +} + +void +ir_algebraic_visitor::handle_rvalue(ir_rvalue **rvalue) +{ + if (!*rvalue) + return; + + ir_expression *expr = (*rvalue)->as_expression(); + if (!expr || expr->operation == ir_quadop_vector) + return; + + *rvalue = handle_expression(expr); +} + +bool +do_algebraic(exec_list *instructions) +{ + ir_algebraic_visitor v; + + visit_list_elements(&v, instructions); + + return v.progress; +} diff --git a/src/glsl/opt_constant_folding.cpp b/src/glsl/opt_constant_folding.cpp new file mode 100644 index 0000000..d69ca75 --- /dev/null +++ b/src/glsl/opt_constant_folding.cpp @@ -0,0 +1,147 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_constant_folding.cpp + * Replace constant-valued expressions with references to constant values. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_rvalue_visitor.h" +#include "ir_optimization.h" +#include "glsl_types.h" + +/** + * Visitor class for replacing expressions with ir_constant values. + */ + +class ir_constant_folding_visitor : public ir_rvalue_visitor { +public: + ir_constant_folding_visitor() + { + this->progress = false; + } + + virtual ~ir_constant_folding_visitor() + { + /* empty */ + } + + virtual ir_visitor_status visit_enter(ir_assignment *ir); + virtual ir_visitor_status visit_enter(ir_call *ir); + + virtual void handle_rvalue(ir_rvalue **rvalue); + + bool progress; +}; + +void +ir_constant_folding_visitor::handle_rvalue(ir_rvalue **rvalue) +{ + if (*rvalue == NULL || (*rvalue)->ir_type == ir_type_constant) + return; + + /* Note that we do rvalue visitoring on leaving. So if an + * expression has a non-constant operand, no need to go looking + * down it to find if it's constant. This cuts the time of this + * pass down drastically. + */ + ir_expression *expr = (*rvalue)->as_expression(); + if (expr) { + for (unsigned int i = 0; i < expr->get_num_operands(); i++) { + if (!expr->operands[i]->as_constant()) + return; + } + } + + ir_constant *constant = (*rvalue)->constant_expression_value(); + if (constant) { + *rvalue = constant; + this->progress = true; + } else { + (*rvalue)->accept(this); + } +} + +ir_visitor_status +ir_constant_folding_visitor::visit_enter(ir_assignment *ir) +{ + ir->rhs->accept(this); + handle_rvalue(&ir->rhs); + + if (ir->condition) { + ir->condition->accept(this); + handle_rvalue(&ir->condition); + + ir_constant *const_val = ir->condition->as_constant(); + /* If the condition is constant, either remove the condition or + * remove the never-executed assignment. + */ + if (const_val) { + if (const_val->value.b[0]) + ir->condition = NULL; + else + ir->remove(); + this->progress = true; + } + } + + /* Don't descend into the LHS because we want it to stay as a + * variable dereference. FINISHME: We probably should to get array + * indices though. + */ + return visit_continue_with_parent; +} + +ir_visitor_status +ir_constant_folding_visitor::visit_enter(ir_call *ir) +{ + exec_list_iterator sig_iter = ir->get_callee()->parameters.iterator(); + foreach_iter(exec_list_iterator, iter, *ir) { + ir_rvalue *param_rval = (ir_rvalue *)iter.get(); + ir_variable *sig_param = (ir_variable *)sig_iter.get(); + + if (sig_param->mode == ir_var_in) { + ir_rvalue *new_param = param_rval; + + handle_rvalue(&new_param); + if (new_param != param_rval) { + param_rval->replace_with(new_param); + } + } + sig_iter.next(); + } + + return visit_continue_with_parent; +} + +bool +do_constant_folding(exec_list *instructions) +{ + ir_constant_folding_visitor constant_folding; + + visit_list_elements(&constant_folding, instructions); + + return constant_folding.progress; +} diff --git a/src/glsl/opt_constant_propagation.cpp b/src/glsl/opt_constant_propagation.cpp new file mode 100644 index 0000000..e1f6889 --- /dev/null +++ b/src/glsl/opt_constant_propagation.cpp @@ -0,0 +1,437 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * constant of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, constant, 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 constantright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR CONSTANTRIGHT 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 opt_constant_propagation.cpp + * + * Tracks assignments of constants to channels of variables, and + * usage of those constant channels with direct usage of the constants. + * + * This can lead to constant folding and algebraic optimizations in + * those later expressions, while causing no increase in instruction + * count (due to constants being generally free to load from a + * constant push buffer or as instruction immediate values) and + * possibly reducing register pressure. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_rvalue_visitor.h" +#include "ir_basic_block.h" +#include "ir_optimization.h" +#include "glsl_types.h" + +class acp_entry : public exec_node +{ +public: + acp_entry(ir_variable *var, unsigned write_mask, ir_constant *constant) + { + assert(var); + assert(constant); + this->var = var; + this->write_mask = write_mask; + this->constant = constant; + } + + ir_variable *var; + ir_constant *constant; + unsigned write_mask; +}; + + +class kill_entry : public exec_node +{ +public: + kill_entry(ir_variable *var, unsigned write_mask) + { + assert(var); + this->var = var; + this->write_mask = write_mask; + } + + ir_variable *var; + unsigned write_mask; +}; + +class ir_constant_propagation_visitor : public ir_rvalue_visitor { +public: + ir_constant_propagation_visitor() + { + progress = false; + mem_ctx = ralloc_context(0); + this->acp = new(mem_ctx) exec_list; + this->kills = new(mem_ctx) exec_list; + } + ~ir_constant_propagation_visitor() + { + ralloc_free(mem_ctx); + } + + virtual ir_visitor_status visit_enter(class ir_loop *); + virtual ir_visitor_status visit_enter(class ir_function_signature *); + virtual ir_visitor_status visit_enter(class ir_function *); + virtual ir_visitor_status visit_leave(class ir_assignment *); + virtual ir_visitor_status visit_enter(class ir_call *); + virtual ir_visitor_status visit_enter(class ir_if *); + + void add_constant(ir_assignment *ir); + void kill(ir_variable *ir, unsigned write_mask); + void handle_if_block(exec_list *instructions); + void handle_rvalue(ir_rvalue **rvalue); + + /** List of acp_entry: The available constants to propagate */ + exec_list *acp; + + /** + * List of kill_entry: The masks of variables whose values were + * killed in this block. + */ + exec_list *kills; + + bool progress; + + bool killed_all; + + void *mem_ctx; +}; + + +void +ir_constant_propagation_visitor::handle_rvalue(ir_rvalue **rvalue) +{ + if (this->in_assignee || !*rvalue) + return; + + const glsl_type *type = (*rvalue)->type; + if (!type->is_scalar() && !type->is_vector()) + return; + + ir_swizzle *swiz = NULL; + ir_dereference_variable *deref = (*rvalue)->as_dereference_variable(); + if (!deref) { + swiz = (*rvalue)->as_swizzle(); + if (!swiz) + return; + + deref = swiz->val->as_dereference_variable(); + if (!deref) + return; + } + + ir_constant_data data; + memset(&data, 0, sizeof(data)); + + for (unsigned int i = 0; i < type->components(); i++) { + int channel; + acp_entry *found = NULL; + + if (swiz) { + switch (i) { + case 0: channel = swiz->mask.x; break; + case 1: channel = swiz->mask.y; break; + case 2: channel = swiz->mask.z; break; + case 3: channel = swiz->mask.w; break; + default: assert(!"shouldn't be reached"); channel = 0; break; + } + } else { + channel = i; + } + + foreach_iter(exec_list_iterator, iter, *this->acp) { + acp_entry *entry = (acp_entry *)iter.get(); + if (entry->var == deref->var && entry->write_mask & (1 << channel)) { + found = entry; + break; + } + } + + if (!found) + return; + + int rhs_channel = 0; + for (int j = 0; j < 4; j++) { + if (j == channel) + break; + if (found->write_mask & (1 << j)) + rhs_channel++; + } + + switch (type->base_type) { + case GLSL_TYPE_FLOAT: + data.f[i] = found->constant->value.f[rhs_channel]; + break; + case GLSL_TYPE_INT: + data.i[i] = found->constant->value.i[rhs_channel]; + break; + case GLSL_TYPE_UINT: + data.u[i] = found->constant->value.u[rhs_channel]; + break; + case GLSL_TYPE_BOOL: + data.b[i] = found->constant->value.b[rhs_channel]; + break; + default: + assert(!"not reached"); + break; + } + } + + *rvalue = new(ralloc_parent(deref)) ir_constant(type, &data); + this->progress = true; +} + +ir_visitor_status +ir_constant_propagation_visitor::visit_enter(ir_function_signature *ir) +{ + /* Treat entry into a function signature as a completely separate + * block. Any instructions at global scope will be shuffled into + * main() at link time, so they're irrelevant to us. + */ + exec_list *orig_acp = this->acp; + exec_list *orig_kills = this->kills; + bool orig_killed_all = this->killed_all; + + this->acp = new(mem_ctx) exec_list; + this->kills = new(mem_ctx) exec_list; + this->killed_all = false; + + visit_list_elements(this, &ir->body); + + this->kills = orig_kills; + this->acp = orig_acp; + this->killed_all = orig_killed_all; + + return visit_continue_with_parent; +} + +ir_visitor_status +ir_constant_propagation_visitor::visit_leave(ir_assignment *ir) +{ + if (this->in_assignee) + return visit_continue; + + kill(ir->lhs->variable_referenced(), ir->write_mask); + + add_constant(ir); + + return visit_continue; +} + +ir_visitor_status +ir_constant_propagation_visitor::visit_enter(ir_function *ir) +{ + (void) ir; + return visit_continue; +} + +ir_visitor_status +ir_constant_propagation_visitor::visit_enter(ir_call *ir) +{ + /* Do constant propagation on call parameters, but skip any out params */ + exec_list_iterator sig_param_iter = ir->get_callee()->parameters.iterator(); + foreach_iter(exec_list_iterator, iter, ir->actual_parameters) { + ir_variable *sig_param = (ir_variable *)sig_param_iter.get(); + ir_rvalue *param = (ir_rvalue *)iter.get(); + if (sig_param->mode != ir_var_out && sig_param->mode != ir_var_inout) { + ir_rvalue *new_param = param; + handle_rvalue(&new_param); + if (new_param != param) + param->replace_with(new_param); + else + param->accept(this); + } + sig_param_iter.next(); + } + + /* Since we're unlinked, we don't (necssarily) know the side effects of + * this call. So kill all copies. + */ + acp->make_empty(); + this->killed_all = true; + + return visit_continue_with_parent; +} + +void +ir_constant_propagation_visitor::handle_if_block(exec_list *instructions) +{ + exec_list *orig_acp = this->acp; + exec_list *orig_kills = this->kills; + bool orig_killed_all = this->killed_all; + + this->acp = new(mem_ctx) exec_list; + this->kills = new(mem_ctx) exec_list; + this->killed_all = false; + + /* Populate the initial acp with a constant of the original */ + foreach_iter(exec_list_iterator, iter, *orig_acp) { + acp_entry *a = (acp_entry *)iter.get(); + this->acp->push_tail(new(this->mem_ctx) acp_entry(a->var, a->write_mask, + a->constant)); + } + + visit_list_elements(this, instructions); + + if (this->killed_all) { + orig_acp->make_empty(); + } + + exec_list *new_kills = this->kills; + this->kills = orig_kills; + this->acp = orig_acp; + this->killed_all = this->killed_all || orig_killed_all; + + foreach_iter(exec_list_iterator, iter, *new_kills) { + kill_entry *k = (kill_entry *)iter.get(); + kill(k->var, k->write_mask); + } +} + +ir_visitor_status +ir_constant_propagation_visitor::visit_enter(ir_if *ir) +{ + ir->condition->accept(this); + handle_rvalue(&ir->condition); + + handle_if_block(&ir->then_instructions); + handle_if_block(&ir->else_instructions); + + /* handle_if_block() already descended into the children. */ + return visit_continue_with_parent; +} + +ir_visitor_status +ir_constant_propagation_visitor::visit_enter(ir_loop *ir) +{ + exec_list *orig_acp = this->acp; + exec_list *orig_kills = this->kills; + bool orig_killed_all = this->killed_all; + + /* FINISHME: For now, the initial acp for loops is totally empty. + * We could go through once, then go through again with the acp + * cloned minus the killed entries after the first run through. + */ + this->acp = new(mem_ctx) exec_list; + this->kills = new(mem_ctx) exec_list; + this->killed_all = false; + + visit_list_elements(this, &ir->body_instructions); + + if (this->killed_all) { + orig_acp->make_empty(); + } + + exec_list *new_kills = this->kills; + this->kills = orig_kills; + this->acp = orig_acp; + this->killed_all = this->killed_all || orig_killed_all; + + foreach_iter(exec_list_iterator, iter, *new_kills) { + kill_entry *k = (kill_entry *)iter.get(); + kill(k->var, k->write_mask); + } + + /* already descended into the children. */ + return visit_continue_with_parent; +} + +void +ir_constant_propagation_visitor::kill(ir_variable *var, unsigned write_mask) +{ + assert(var != NULL); + + /* We don't track non-vectors. */ + if (!var->type->is_vector() && !var->type->is_scalar()) + return; + + /* Remove any entries currently in the ACP for this kill. */ + foreach_iter(exec_list_iterator, iter, *this->acp) { + acp_entry *entry = (acp_entry *)iter.get(); + + if (entry->var == var) { + entry->write_mask &= ~write_mask; + if (entry->write_mask == 0) + entry->remove(); + } + } + + /* Add this writemask of the variable to the list of killed + * variables in this block. + */ + foreach_iter(exec_list_iterator, iter, *this->kills) { + kill_entry *entry = (kill_entry *)iter.get(); + + if (entry->var == var) { + entry->write_mask |= write_mask; + return; + } + } + /* Not already in the list. Make new entry. */ + this->kills->push_tail(new(this->mem_ctx) kill_entry(var, write_mask)); +} + +/** + * Adds an entry to the available constant list if it's a plain assignment + * of a variable to a variable. + */ +void +ir_constant_propagation_visitor::add_constant(ir_assignment *ir) +{ + acp_entry *entry; + + if (ir->condition) { + ir_constant *condition = ir->condition->as_constant(); + if (!condition || !condition->value.b[0]) + return; + } + + if (!ir->write_mask) + return; + + ir_dereference_variable *deref = ir->lhs->as_dereference_variable(); + ir_constant *constant = ir->rhs->as_constant(); + + if (!deref || !constant) + return; + + /* Only do constant propagation on vectors. Constant matrices, + * arrays, or structures would require more work elsewhere. + */ + if (!deref->var->type->is_vector() && !deref->var->type->is_scalar()) + return; + + entry = new(this->mem_ctx) acp_entry(deref->var, ir->write_mask, constant); + this->acp->push_tail(entry); +} + +/** + * Does a constant propagation pass on the code present in the instruction stream. + */ +bool +do_constant_propagation(exec_list *instructions) +{ + ir_constant_propagation_visitor v; + + visit_list_elements(&v, instructions); + + return v.progress; +} diff --git a/src/glsl/opt_constant_variable.cpp b/src/glsl/opt_constant_variable.cpp new file mode 100644 index 0000000..8068d0c --- /dev/null +++ b/src/glsl/opt_constant_variable.cpp @@ -0,0 +1,198 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_constant_variable.cpp + * + * Marks variables assigned a single constant value over the course + * of the program as constant. + * + * The goal here is to trigger further constant folding and then dead + * code elimination. This is common with vector/matrix constructors + * and calls to builtin functions. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_optimization.h" +#include "glsl_types.h" + +struct assignment_entry { + exec_node link; + int assignment_count; + ir_variable *var; + ir_constant *constval; + bool our_scope; +}; + +class ir_constant_variable_visitor : public ir_hierarchical_visitor { +public: + virtual ir_visitor_status visit_enter(ir_dereference_variable *); + virtual ir_visitor_status visit(ir_variable *); + virtual ir_visitor_status visit_enter(ir_assignment *); + virtual ir_visitor_status visit_enter(ir_call *); + + exec_list list; +}; + +static struct assignment_entry * +get_assignment_entry(ir_variable *var, exec_list *list) +{ + struct assignment_entry *entry; + + foreach_list_typed(struct assignment_entry, entry, link, list) { + if (entry->var == var) + return entry; + } + + entry = (struct assignment_entry *)calloc(1, sizeof(*entry)); + entry->var = var; + list->push_head(&entry->link); + return entry; +} + +ir_visitor_status +ir_constant_variable_visitor::visit(ir_variable *ir) +{ + struct assignment_entry *entry = get_assignment_entry(ir, &this->list); + entry->our_scope = true; + return visit_continue; +} + +/* Skip derefs of variables so that we can detect declarations. */ +ir_visitor_status +ir_constant_variable_visitor::visit_enter(ir_dereference_variable *ir) +{ + (void)ir; + return visit_continue_with_parent; +} + +ir_visitor_status +ir_constant_variable_visitor::visit_enter(ir_assignment *ir) +{ + ir_constant *constval; + struct assignment_entry *entry; + + entry = get_assignment_entry(ir->lhs->variable_referenced(), &this->list); + assert(entry); + entry->assignment_count++; + + /* If it's already constant, don't do the work. */ + if (entry->var->constant_value) + return visit_continue; + + /* OK, now find if we actually have all the right conditions for + * this to be a constant value assigned to the var. + */ + if (ir->condition) { + constval = ir->condition->constant_expression_value(); + if (!constval || !constval->value.b[0]) + return visit_continue; + } + + ir_variable *var = ir->whole_variable_written(); + if (!var) + return visit_continue; + + constval = ir->rhs->constant_expression_value(); + if (!constval) + return visit_continue; + + /* Mark this entry as having a constant assignment (if the + * assignment count doesn't go >1). do_constant_variable will fix + * up the variable with the constant value later. + */ + entry->constval = constval; + + return visit_continue; +} + +ir_visitor_status +ir_constant_variable_visitor::visit_enter(ir_call *ir) +{ + exec_list_iterator sig_iter = ir->get_callee()->parameters.iterator(); + foreach_iter(exec_list_iterator, iter, *ir) { + ir_rvalue *param_rval = (ir_rvalue *)iter.get(); + ir_variable *param = (ir_variable *)sig_iter.get(); + + if (param->mode == ir_var_out || + param->mode == ir_var_inout) { + ir_variable *var = param_rval->variable_referenced(); + struct assignment_entry *entry; + + assert(var); + entry = get_assignment_entry(var, &this->list); + entry->assignment_count++; + } + sig_iter.next(); + } + return visit_continue; +} + +/** + * Does a copy propagation pass on the code present in the instruction stream. + */ +bool +do_constant_variable(exec_list *instructions) +{ + bool progress = false; + ir_constant_variable_visitor v; + + v.run(instructions); + + while (!v.list.is_empty()) { + + struct assignment_entry *entry; + entry = exec_node_data(struct assignment_entry, v.list.head, link); + + if (entry->assignment_count == 1 && entry->constval && entry->our_scope) { + entry->var->constant_value = entry->constval; + progress = true; + } + entry->link.remove(); + free(entry); + } + + return progress; +} + +bool +do_constant_variable_unlinked(exec_list *instructions) +{ + bool progress = false; + + foreach_iter(exec_list_iterator, iter, *instructions) { + ir_instruction *ir = (ir_instruction *)iter.get(); + ir_function *f = ir->as_function(); + if (f) { + foreach_iter(exec_list_iterator, sigiter, *f) { + ir_function_signature *sig = + (ir_function_signature *) sigiter.get(); + if (do_constant_variable(&sig->body)) + progress = true; + } + } + } + + return progress; +} diff --git a/src/glsl/opt_copy_propagation.cpp b/src/glsl/opt_copy_propagation.cpp new file mode 100644 index 0000000..4ab23bf --- /dev/null +++ b/src/glsl/opt_copy_propagation.cpp @@ -0,0 +1,348 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_copy_propagation.cpp + * + * Moves usage of recently-copied variables to the previous copy of + * the variable. + * + * This should reduce the number of MOV instructions in the generated + * programs unless copy propagation is also done on the LIR, and may + * help anyway by triggering other optimizations that live in the HIR. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_basic_block.h" +#include "ir_optimization.h" +#include "glsl_types.h" + +class acp_entry : public exec_node +{ +public: + acp_entry(ir_variable *lhs, ir_variable *rhs) + { + assert(lhs); + assert(rhs); + this->lhs = lhs; + this->rhs = rhs; + } + + ir_variable *lhs; + ir_variable *rhs; +}; + + +class kill_entry : public exec_node +{ +public: + kill_entry(ir_variable *var) + { + assert(var); + this->var = var; + } + + ir_variable *var; +}; + +class ir_copy_propagation_visitor : public ir_hierarchical_visitor { +public: + ir_copy_propagation_visitor() + { + progress = false; + mem_ctx = ralloc_context(0); + this->acp = new(mem_ctx) exec_list; + this->kills = new(mem_ctx) exec_list; + } + ~ir_copy_propagation_visitor() + { + ralloc_free(mem_ctx); + } + + virtual ir_visitor_status visit(class ir_dereference_variable *); + virtual ir_visitor_status visit_enter(class ir_loop *); + virtual ir_visitor_status visit_enter(class ir_function_signature *); + virtual ir_visitor_status visit_enter(class ir_function *); + virtual ir_visitor_status visit_leave(class ir_assignment *); + virtual ir_visitor_status visit_enter(class ir_call *); + virtual ir_visitor_status visit_enter(class ir_if *); + + void add_copy(ir_assignment *ir); + void kill(ir_variable *ir); + void handle_if_block(exec_list *instructions); + + /** List of acp_entry: The available copies to propagate */ + exec_list *acp; + /** + * List of kill_entry: The variables whose values were killed in this + * block. + */ + exec_list *kills; + + bool progress; + + bool killed_all; + + void *mem_ctx; +}; + +ir_visitor_status +ir_copy_propagation_visitor::visit_enter(ir_function_signature *ir) +{ + /* Treat entry into a function signature as a completely separate + * block. Any instructions at global scope will be shuffled into + * main() at link time, so they're irrelevant to us. + */ + exec_list *orig_acp = this->acp; + exec_list *orig_kills = this->kills; + bool orig_killed_all = this->killed_all; + + this->acp = new(mem_ctx) exec_list; + this->kills = new(mem_ctx) exec_list; + this->killed_all = false; + + visit_list_elements(this, &ir->body); + + this->kills = orig_kills; + this->acp = orig_acp; + this->killed_all = orig_killed_all; + + return visit_continue_with_parent; +} + +ir_visitor_status +ir_copy_propagation_visitor::visit_leave(ir_assignment *ir) +{ + kill(ir->lhs->variable_referenced()); + + add_copy(ir); + + return visit_continue; +} + +ir_visitor_status +ir_copy_propagation_visitor::visit_enter(ir_function *ir) +{ + (void) ir; + return visit_continue; +} + +/** + * Replaces dereferences of ACP RHS variables with ACP LHS variables. + * + * This is where the actual copy propagation occurs. Note that the + * rewriting of ir_dereference means that the ir_dereference instance + * must not be shared by multiple IR operations! + */ +ir_visitor_status +ir_copy_propagation_visitor::visit(ir_dereference_variable *ir) +{ + if (this->in_assignee) + return visit_continue; + + ir_variable *var = ir->var; + + foreach_iter(exec_list_iterator, iter, *this->acp) { + acp_entry *entry = (acp_entry *)iter.get(); + + if (var == entry->lhs) { + ir->var = entry->rhs; + this->progress = true; + break; + } + } + + return visit_continue; +} + + +ir_visitor_status +ir_copy_propagation_visitor::visit_enter(ir_call *ir) +{ + /* Do copy propagation on call parameters, but skip any out params */ + exec_list_iterator sig_param_iter = ir->get_callee()->parameters.iterator(); + foreach_iter(exec_list_iterator, iter, ir->actual_parameters) { + ir_variable *sig_param = (ir_variable *)sig_param_iter.get(); + ir_instruction *ir = (ir_instruction *)iter.get(); + if (sig_param->mode != ir_var_out && sig_param->mode != ir_var_inout) { + ir->accept(this); + } + sig_param_iter.next(); + } + + /* Since we're unlinked, we don't (necssarily) know the side effects of + * this call. So kill all copies. + */ + acp->make_empty(); + this->killed_all = true; + + return visit_continue_with_parent; +} + +void +ir_copy_propagation_visitor::handle_if_block(exec_list *instructions) +{ + exec_list *orig_acp = this->acp; + exec_list *orig_kills = this->kills; + bool orig_killed_all = this->killed_all; + + this->acp = new(mem_ctx) exec_list; + this->kills = new(mem_ctx) exec_list; + this->killed_all = false; + + /* Populate the initial acp with a copy of the original */ + foreach_iter(exec_list_iterator, iter, *orig_acp) { + acp_entry *a = (acp_entry *)iter.get(); + this->acp->push_tail(new(this->mem_ctx) acp_entry(a->lhs, a->rhs)); + } + + visit_list_elements(this, instructions); + + if (this->killed_all) { + orig_acp->make_empty(); + } + + exec_list *new_kills = this->kills; + this->kills = orig_kills; + this->acp = orig_acp; + this->killed_all = this->killed_all || orig_killed_all; + + foreach_iter(exec_list_iterator, iter, *new_kills) { + kill_entry *k = (kill_entry *)iter.get(); + kill(k->var); + } +} + +ir_visitor_status +ir_copy_propagation_visitor::visit_enter(ir_if *ir) +{ + ir->condition->accept(this); + + handle_if_block(&ir->then_instructions); + handle_if_block(&ir->else_instructions); + + /* handle_if_block() already descended into the children. */ + return visit_continue_with_parent; +} + +ir_visitor_status +ir_copy_propagation_visitor::visit_enter(ir_loop *ir) +{ + exec_list *orig_acp = this->acp; + exec_list *orig_kills = this->kills; + bool orig_killed_all = this->killed_all; + + /* FINISHME: For now, the initial acp for loops is totally empty. + * We could go through once, then go through again with the acp + * cloned minus the killed entries after the first run through. + */ + this->acp = new(mem_ctx) exec_list; + this->kills = new(mem_ctx) exec_list; + this->killed_all = false; + + visit_list_elements(this, &ir->body_instructions); + + if (this->killed_all) { + orig_acp->make_empty(); + } + + exec_list *new_kills = this->kills; + this->kills = orig_kills; + this->acp = orig_acp; + this->killed_all = this->killed_all || orig_killed_all; + + foreach_iter(exec_list_iterator, iter, *new_kills) { + kill_entry *k = (kill_entry *)iter.get(); + kill(k->var); + } + + /* already descended into the children. */ + return visit_continue_with_parent; +} + +void +ir_copy_propagation_visitor::kill(ir_variable *var) +{ + assert(var != NULL); + + /* Remove any entries currently in the ACP for this kill. */ + foreach_iter(exec_list_iterator, iter, *acp) { + acp_entry *entry = (acp_entry *)iter.get(); + + if (entry->lhs == var || entry->rhs == var) { + entry->remove(); + } + } + + /* Add the LHS variable to the list of killed variables in this block. + */ + this->kills->push_tail(new(this->mem_ctx) kill_entry(var)); +} + +/** + * Adds an entry to the available copy list if it's a plain assignment + * of a variable to a variable. + */ +void +ir_copy_propagation_visitor::add_copy(ir_assignment *ir) +{ + acp_entry *entry; + + if (ir->condition) { + ir_constant *condition = ir->condition->as_constant(); + if (!condition || !condition->value.b[0]) + return; + } + + ir_variable *lhs_var = ir->whole_variable_written(); + ir_variable *rhs_var = ir->rhs->whole_variable_referenced(); + + if ((lhs_var != NULL) && (rhs_var != NULL)) { + if (lhs_var == rhs_var) { + /* This is a dumb assignment, but we've conveniently noticed + * it here. Removing it now would mess up the loop iteration + * calling us. Just flag it to not execute, and someone else + * will clean up the mess. + */ + ir->condition = new(ralloc_parent(ir)) ir_constant(false); + this->progress = true; + } else { + entry = new(this->mem_ctx) acp_entry(lhs_var, rhs_var); + this->acp->push_tail(entry); + } + } +} + +/** + * Does a copy propagation pass on the code present in the instruction stream. + */ +bool +do_copy_propagation(exec_list *instructions) +{ + ir_copy_propagation_visitor v; + + visit_list_elements(&v, instructions); + + return v.progress; +} diff --git a/src/glsl/opt_dead_code.cpp b/src/glsl/opt_dead_code.cpp new file mode 100644 index 0000000..cb500d2 --- /dev/null +++ b/src/glsl/opt_dead_code.cpp @@ -0,0 +1,142 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_dead_code.cpp + * + * Eliminates dead assignments and variable declarations from the code. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_variable_refcount.h" +#include "glsl_types.h" + +static bool debug = false; + +/** + * Do a dead code pass over instructions and everything that instructions + * references. + * + * Note that this will remove assignments to globals, so it is not suitable + * for usage on an unlinked instruction stream. + */ +bool +do_dead_code(exec_list *instructions) +{ + ir_variable_refcount_visitor v; + bool progress = false; + + v.run(instructions); + + foreach_iter(exec_list_iterator, iter, v.variable_list) { + variable_entry *entry = (variable_entry *)iter.get(); + + /* Since each assignment is a reference, the refereneced count must be + * greater than or equal to the assignment count. If they are equal, + * then all of the references are assignments, and the variable is + * dead. + * + * Note that if the variable is neither assigned nor referenced, both + * counts will be zero and will be caught by the equality test. + */ + assert(entry->referenced_count >= entry->assigned_count); + + if (debug) { + printf("%s@%p: %d refs, %d assigns, %sdeclared in our scope\n", + entry->var->name, (void *) entry->var, + entry->referenced_count, entry->assigned_count, + entry->declaration ? "" : "not "); + } + + if ((entry->referenced_count > entry->assigned_count) + || !entry->declaration) + continue; + + if (entry->assign) { + /* Remove a single dead assignment to the variable we found. + * Don't do so if it's a shader output, though. + */ + if (entry->var->mode != ir_var_out && + entry->var->mode != ir_var_inout && + !ir_has_call(entry->assign)) { + entry->assign->remove(); + progress = true; + + if (debug) { + printf("Removed assignment to %s@%p\n", + entry->var->name, (void *) entry->var); + } + } + } else { + /* If there are no assignments or references to the variable left, + * then we can remove its declaration. + */ + + /* uniform initializers are precious, and could get used by another + * stage. + */ + if (entry->var->mode == ir_var_uniform && + entry->var->constant_value) + continue; + + entry->var->remove(); + progress = true; + + if (debug) { + printf("Removed declaration of %s@%p\n", + entry->var->name, (void *) entry->var); + } + } + } + + return progress; +} + +/** + * Does a dead code pass on the functions present in the instruction stream. + * + * This is suitable for use while the program is not linked, as it will + * ignore variable declarations (and the assignments to them) for variables + * with global scope. + */ +bool +do_dead_code_unlinked(exec_list *instructions) +{ + bool progress = false; + + foreach_iter(exec_list_iterator, iter, *instructions) { + ir_instruction *ir = (ir_instruction *)iter.get(); + ir_function *f = ir->as_function(); + if (f) { + foreach_iter(exec_list_iterator, sigiter, *f) { + ir_function_signature *sig = + (ir_function_signature *) sigiter.get(); + if (do_dead_code(&sig->body)) + progress = true; + } + } + } + + return progress; +} diff --git a/src/glsl/opt_dead_code_local.cpp b/src/glsl/opt_dead_code_local.cpp new file mode 100644 index 0000000..2610b69 --- /dev/null +++ b/src/glsl/opt_dead_code_local.cpp @@ -0,0 +1,229 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_dead_code_local.cpp + * + * Eliminates local dead assignments from the code. + * + * This operates on basic blocks, tracking assignments and finding if + * they're used before the variable is completely reassigned. + * + * Compare this to ir_dead_code.cpp, which operates globally looking + * for assignments to variables that are never read. + */ + +#include "ir.h" +#include "ir_basic_block.h" +#include "ir_optimization.h" +#include "glsl_types.h" + +static bool debug = false; + +class assignment_entry : public exec_node +{ +public: + assignment_entry(ir_variable *lhs, ir_instruction *ir) + { + assert(lhs); + assert(ir); + this->lhs = lhs; + this->ir = ir; + } + + ir_variable *lhs; + ir_instruction *ir; +}; + +class kill_for_derefs_visitor : public ir_hierarchical_visitor { +public: + kill_for_derefs_visitor(exec_list *assignments) + { + this->assignments = assignments; + } + + virtual ir_visitor_status visit(ir_dereference_variable *ir) + { + ir_variable *const var = ir->variable_referenced(); + + foreach_iter(exec_list_iterator, iter, *this->assignments) { + assignment_entry *entry = (assignment_entry *)iter.get(); + + if (entry->lhs == var) { + if (debug) + printf("kill %s\n", entry->lhs->name); + entry->remove(); + } + } + + return visit_continue; + } + +private: + exec_list *assignments; +}; + +class array_index_visit : public ir_hierarchical_visitor { +public: + array_index_visit(ir_hierarchical_visitor *v) + { + this->visitor = v; + } + + virtual ir_visitor_status visit_enter(class ir_dereference_array *ir) + { + ir->array_index->accept(visitor); + return visit_continue; + } + + static void run(ir_instruction *ir, ir_hierarchical_visitor *v) + { + array_index_visit top_visit(v); + ir->accept(& top_visit); + } + + ir_hierarchical_visitor *visitor; +}; + + +/** + * Adds an entry to the available copy list if it's a plain assignment + * of a variable to a variable. + */ +static bool +process_assignment(void *ctx, ir_assignment *ir, exec_list *assignments) +{ + ir_variable *var = NULL; + bool progress = false; + kill_for_derefs_visitor v(assignments); + + /* Kill assignment entries for things used to produce this assignment. */ + ir->rhs->accept(&v); + if (ir->condition) { + ir->condition->accept(&v); + } + + /* Kill assignment enties used as array indices. + */ + array_index_visit::run(ir->lhs, &v); + var = ir->lhs->variable_referenced(); + assert(var); + + bool always_assign = true; + if (ir->condition) { + ir_constant *condition = ir->condition->as_constant(); + if (!condition || !condition->value.b[0]) + always_assign = false; + } + + /* Now, check if we did a whole-variable assignment. */ + if (always_assign && (ir->whole_variable_written() != NULL)) { + /* We did a whole-variable assignment. So, any instruction in + * the assignment list with the same LHS is dead. + */ + if (debug) + printf("looking for %s to remove\n", var->name); + foreach_iter(exec_list_iterator, iter, *assignments) { + assignment_entry *entry = (assignment_entry *)iter.get(); + + if (entry->lhs == var) { + if (debug) + printf("removing %s\n", var->name); + entry->ir->remove(); + entry->remove(); + progress = true; + } + } + } + + /* Add this instruction to the assignment list available to be removed. + * But not if the assignment has other side effects. + */ + if (ir_has_call(ir)) + return progress; + + assignment_entry *entry = new(ctx) assignment_entry(var, ir); + assignments->push_tail(entry); + + if (debug) { + printf("add %s\n", var->name); + + printf("current entries\n"); + foreach_iter(exec_list_iterator, iter, *assignments) { + assignment_entry *entry = (assignment_entry *)iter.get(); + + printf(" %s\n", entry->lhs->name); + } + } + + return progress; +} + +static void +dead_code_local_basic_block(ir_instruction *first, + ir_instruction *last, + void *data) +{ + ir_instruction *ir, *ir_next; + /* List of avaialble_copy */ + exec_list assignments; + bool *out_progress = (bool *)data; + bool progress = false; + + void *ctx = ralloc_context(NULL); + /* Safe looping, since process_assignment */ + for (ir = first, ir_next = (ir_instruction *)first->next;; + ir = ir_next, ir_next = (ir_instruction *)ir->next) { + ir_assignment *ir_assign = ir->as_assignment(); + + if (debug) { + ir->print(); + printf("\n"); + } + + if (ir_assign) { + progress = process_assignment(ctx, ir_assign, &assignments) || progress; + } else { + kill_for_derefs_visitor kill(&assignments); + ir->accept(&kill); + } + + if (ir == last) + break; + } + *out_progress = progress; + ralloc_free(ctx); +} + +/** + * Does a copy propagation pass on the code present in the instruction stream. + */ +bool +do_dead_code_local(exec_list *instructions) +{ + bool progress = false; + + call_for_basic_blocks(instructions, dead_code_local_basic_block, &progress); + + return progress; +} diff --git a/src/glsl/opt_dead_functions.cpp b/src/glsl/opt_dead_functions.cpp new file mode 100644 index 0000000..ceb7908 --- /dev/null +++ b/src/glsl/opt_dead_functions.cpp @@ -0,0 +1,153 @@ + /* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + + /** + * \file opt_dead_functions.cpp + * + * Eliminates unused functions from the linked program. + */ + + #include "ir.h" + #include "ir_visitor.h" + #include "ir_expression_flattening.h" + #include "glsl_types.h" + + class signature_entry : public exec_node + { + public: + signature_entry(ir_function_signature *sig) + { + this->signature = sig; + this->used = false; + } + + ir_function_signature *signature; + bool used; + }; + + class ir_dead_functions_visitor : public ir_hierarchical_visitor { + public: + ir_dead_functions_visitor() + { + this->mem_ctx = ralloc_context(NULL); + } + + ~ir_dead_functions_visitor() + { + ralloc_free(this->mem_ctx); + } + + virtual ir_visitor_status visit_enter(ir_function_signature *); + virtual ir_visitor_status visit_enter(ir_call *); + + signature_entry *get_signature_entry(ir_function_signature *var); + + bool (*predicate)(ir_instruction *ir); + + /* List of signature_entry */ + exec_list signature_list; + void *mem_ctx; + }; + + + signature_entry * + ir_dead_functions_visitor::get_signature_entry(ir_function_signature *sig) + { + foreach_iter(exec_list_iterator, iter, this->signature_list) { + signature_entry *entry = (signature_entry *)iter.get(); + if (entry->signature == sig) + return entry; + } + + signature_entry *entry = new(mem_ctx) signature_entry(sig); + this->signature_list.push_tail(entry); + return entry; + } + + + ir_visitor_status + ir_dead_functions_visitor::visit_enter(ir_function_signature *ir) + { + signature_entry *entry = this->get_signature_entry(ir); + + if (strcmp(ir->function_name(), "main") == 0) { + entry->used = true; + } + + return visit_continue; + } + + + ir_visitor_status + ir_dead_functions_visitor::visit_enter(ir_call *ir) + { + signature_entry *entry = this->get_signature_entry(ir->get_callee()); + + entry->used = true; + + return visit_continue; +} + +bool +do_dead_functions(exec_list *instructions) +{ + ir_dead_functions_visitor v; + bool progress = false; + + visit_list_elements(&v, instructions); + + /* Now that we've figured out which function signatures are used, remove + * the unused ones, and remove function definitions that have no more + * signatures. + */ + foreach_iter(exec_list_iterator, iter, v.signature_list) { + signature_entry *entry = (signature_entry *)iter.get(); + + if (!entry->used) { + entry->signature->remove(); + delete entry->signature; + progress = true; + } + delete(entry); + } + + /* We don't just do this above when we nuked a signature because of + * const pointers. + */ + foreach_iter(exec_list_iterator, iter, *instructions) { + ir_instruction *ir = (ir_instruction *)iter.get(); + ir_function *func = ir->as_function(); + + if (func && func->signatures.is_empty()) { + /* At this point (post-linking), the symbol table is no + * longer in use, so not removing the function from the + * symbol table should be OK. + */ + func->remove(); + delete func; + progress = true; + } + } + + return progress; +} diff --git a/src/glsl/opt_discard_simplification.cpp b/src/glsl/opt_discard_simplification.cpp new file mode 100644 index 0000000..0e577c4 --- /dev/null +++ b/src/glsl/opt_discard_simplification.cpp @@ -0,0 +1,180 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_discard_simplification.cpp + * + * This pass simplifies if-statements and loops containing unconditional + * discards. + * + * Case 1: Both branches contain unconditional discards: + * ----------------------------------------------------- + * + * if (cond) { + * s1; + * discard; + * s2; + * } else { + * s3; + * discard; + * s4; + * } + * + * becomes: + * + * discard + * + * Case 2: The "then" clause contains an unconditional discard: + * ------------------------------------------------------------ + * + * if (cond) { + * s1; + * discard; + * s2; + * } else { + * s3; + * } + * + * becomes: + * + * if (cond) { + * discard; + * } else { + * s3; + * } + * + * Case 3: The "else" clause contains an unconditional discard: + * ------------------------------------------------------------ + * + * if (cond) { + * s1; + * } else { + * s2; + * discard; + * s3; + * } + * + * becomes: + * + * if (cond) { + * s1; + * } else { + * discard; + * } + */ + +#include "glsl_types.h" +#include "ir.h" + +class discard_simplifier : public ir_hierarchical_visitor { +public: + discard_simplifier() + { + this->progress = false; + } + + ir_visitor_status visit_enter(ir_if *); + ir_visitor_status visit_enter(ir_loop *); + + bool progress; +}; + +static ir_discard * +find_unconditional_discard(exec_list &instructions) +{ + foreach_list(n, &instructions) { + ir_discard *ir = ((ir_instruction *) n)->as_discard(); + if (ir != NULL && ir->condition == NULL) + return ir; + } + return NULL; +} + +static bool +is_only_instruction(ir_discard *discard) +{ + return (discard->prev->is_head_sentinel() && + discard->next->is_tail_sentinel()); +} + +ir_visitor_status +discard_simplifier::visit_enter(ir_if *ir) +{ + ir_discard *then_discard = find_unconditional_discard(ir->then_instructions); + ir_discard *else_discard = find_unconditional_discard(ir->else_instructions); + + if (then_discard == NULL && else_discard == NULL) + return visit_continue; + + /* If both branches result in discard, replace whole if with discard. */ + if (then_discard != NULL && else_discard != NULL) { + this->progress = true; + ir->replace_with(then_discard); + return visit_continue_with_parent; + } + + /* Otherwise, one branch has a discard. */ + if (then_discard != NULL && !is_only_instruction(then_discard)) { + this->progress = true; + ir->then_instructions.make_empty(); + ir->then_instructions.push_tail(then_discard); + } else if (else_discard != NULL && !is_only_instruction(else_discard)) { + this->progress = true; + ir->else_instructions.make_empty(); + ir->else_instructions.push_tail(else_discard); + } + + visit_list_elements(this, &ir->then_instructions); + return visit_continue_with_parent; +} + +ir_visitor_status +discard_simplifier::visit_enter(ir_loop *ir) +{ + ir_discard *discard = find_unconditional_discard(ir->body_instructions); + + if (discard) { + ir->replace_with(discard); + return visit_continue_with_parent; + } + + return visit_continue; +} + +bool +do_discard_simplification(exec_list *instructions) +{ + /* Look for a top-level unconditional discard */ + ir_discard *discard = find_unconditional_discard(*instructions); + if (discard != NULL) { + instructions->make_empty(); + instructions->push_tail(discard); + return true; + } + + discard_simplifier v; + + visit_list_elements(&v, instructions); + + return v.progress; +} diff --git a/src/glsl/opt_function_inlining.cpp b/src/glsl/opt_function_inlining.cpp new file mode 100644 index 0000000..53c2f82 --- /dev/null +++ b/src/glsl/opt_function_inlining.cpp @@ -0,0 +1,421 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_function_inlining.cpp + * + * Replaces calls to functions with the body of the function. + */ + +#include +#include "ir.h" +#include "ir_visitor.h" +#include "ir_function_inlining.h" +#include "ir_expression_flattening.h" +#include "glsl_types.h" +#include "program/hash_table.h" + +static void +do_sampler_replacement(exec_list *instructions, + ir_variable *sampler, + ir_dereference *deref); + +class ir_function_inlining_visitor : public ir_hierarchical_visitor { +public: + ir_function_inlining_visitor() + { + progress = false; + } + + virtual ~ir_function_inlining_visitor() + { + /* empty */ + } + + virtual ir_visitor_status visit_enter(ir_expression *); + virtual ir_visitor_status visit_enter(ir_call *); + virtual ir_visitor_status visit_enter(ir_assignment *); + virtual ir_visitor_status visit_enter(ir_return *); + virtual ir_visitor_status visit_enter(ir_texture *); + virtual ir_visitor_status visit_enter(ir_swizzle *); + + bool progress; +}; + + +bool +automatic_inlining_predicate(ir_instruction *ir) +{ + ir_call *call = ir->as_call(); + + if (call && can_inline(call)) + return true; + + return false; +} + +bool +do_function_inlining(exec_list *instructions) +{ + ir_function_inlining_visitor v; + + do_expression_flattening(instructions, automatic_inlining_predicate); + + v.run(instructions); + + return v.progress; +} + +static void +replace_return_with_assignment(ir_instruction *ir, void *data) +{ + void *ctx = ralloc_parent(ir); + ir_variable *retval = (ir_variable *)data; + ir_return *ret = ir->as_return(); + + if (ret) { + if (ret->value) { + ir_rvalue *lhs = new(ctx) ir_dereference_variable(retval); + ret->replace_with(new(ctx) ir_assignment(lhs, ret->value, NULL)); + } else { + /* un-valued return has to be the last return, or we shouldn't + * have reached here. (see can_inline()). + */ + assert(ret->next->is_tail_sentinel()); + ret->remove(); + } + } +} + +ir_rvalue * +ir_call::generate_inline(ir_instruction *next_ir) +{ + void *ctx = ralloc_parent(this); + ir_variable **parameters; + int num_parameters; + int i; + ir_variable *retval = NULL; + struct hash_table *ht; + + ht = hash_table_ctor(0, hash_table_pointer_hash, hash_table_pointer_compare); + + num_parameters = 0; + foreach_iter(exec_list_iterator, iter_sig, this->callee->parameters) + num_parameters++; + + parameters = new ir_variable *[num_parameters]; + + /* Generate storage for the return value. */ + if (!this->callee->return_type->is_void()) { + retval = new(ctx) ir_variable(this->callee->return_type, "_ret_val", + ir_var_auto); + next_ir->insert_before(retval); + } + + /* Generate the declarations for the parameters to our inlined code, + * and set up the mapping of real function body variables to ours. + */ + i = 0; + exec_list_iterator sig_param_iter = this->callee->parameters.iterator(); + exec_list_iterator param_iter = this->actual_parameters.iterator(); + for (i = 0; i < num_parameters; i++) { + ir_variable *sig_param = (ir_variable *) sig_param_iter.get(); + ir_rvalue *param = (ir_rvalue *) param_iter.get(); + + /* Generate a new variable for the parameter. */ + if (sig_param->type->base_type == GLSL_TYPE_SAMPLER) { + /* For samplers, we want the inlined sampler references + * referencing the passed in sampler variable, since that + * will have the location information, which an assignment of + * a sampler wouldn't. Fix it up below. + */ + parameters[i] = NULL; + } else { + parameters[i] = sig_param->clone(ctx, ht); + parameters[i]->mode = ir_var_auto; + + /* Remove the read-only decoration becuase we're going to write + * directly to this variable. If the cloned variable is left + * read-only and the inlined function is inside a loop, the loop + * analysis code will get confused. + */ + parameters[i]->read_only = false; + next_ir->insert_before(parameters[i]); + } + + /* Move the actual param into our param variable if it's an 'in' type. */ + if (parameters[i] && (sig_param->mode == ir_var_in || + sig_param->mode == ir_var_inout)) { + ir_assignment *assign; + + assign = new(ctx) ir_assignment(new(ctx) ir_dereference_variable(parameters[i]), + param, NULL); + next_ir->insert_before(assign); + } + + sig_param_iter.next(); + param_iter.next(); + } + + exec_list new_instructions; + + /* Generate the inlined body of the function to a new list */ + foreach_iter(exec_list_iterator, iter, callee->body) { + ir_instruction *ir = (ir_instruction *)iter.get(); + ir_instruction *new_ir = ir->clone(ctx, ht); + + new_instructions.push_tail(new_ir); + visit_tree(new_ir, replace_return_with_assignment, retval); + } + + /* If any samplers were passed in, replace any deref of the sampler + * with a deref of the sampler argument. + */ + param_iter = this->actual_parameters.iterator(); + sig_param_iter = this->callee->parameters.iterator(); + for (i = 0; i < num_parameters; i++) { + ir_instruction *const param = (ir_instruction *) param_iter.get(); + ir_variable *sig_param = (ir_variable *) sig_param_iter.get(); + + if (sig_param->type->base_type == GLSL_TYPE_SAMPLER) { + ir_dereference *deref = param->as_dereference(); + + assert(deref); + do_sampler_replacement(&new_instructions, sig_param, deref); + } + param_iter.next(); + sig_param_iter.next(); + } + + /* Now push those new instructions in. */ + next_ir->insert_before(&new_instructions); + + /* Copy back the value of any 'out' parameters from the function body + * variables to our own. + */ + i = 0; + param_iter = this->actual_parameters.iterator(); + sig_param_iter = this->callee->parameters.iterator(); + for (i = 0; i < num_parameters; i++) { + ir_instruction *const param = (ir_instruction *) param_iter.get(); + const ir_variable *const sig_param = (ir_variable *) sig_param_iter.get(); + + /* Move our param variable into the actual param if it's an 'out' type. */ + if (parameters[i] && (sig_param->mode == ir_var_out || + sig_param->mode == ir_var_inout)) { + ir_assignment *assign; + + assign = new(ctx) ir_assignment(param->clone(ctx, NULL)->as_rvalue(), + new(ctx) ir_dereference_variable(parameters[i]), + NULL); + next_ir->insert_before(assign); + } + + param_iter.next(); + sig_param_iter.next(); + } + + delete [] parameters; + + hash_table_dtor(ht); + + if (retval) + return new(ctx) ir_dereference_variable(retval); + else + return NULL; +} + + +ir_visitor_status +ir_function_inlining_visitor::visit_enter(ir_expression *ir) +{ + (void) ir; + return visit_continue_with_parent; +} + + +ir_visitor_status +ir_function_inlining_visitor::visit_enter(ir_return *ir) +{ + (void) ir; + return visit_continue_with_parent; +} + + +ir_visitor_status +ir_function_inlining_visitor::visit_enter(ir_texture *ir) +{ + (void) ir; + return visit_continue_with_parent; +} + + +ir_visitor_status +ir_function_inlining_visitor::visit_enter(ir_swizzle *ir) +{ + (void) ir; + return visit_continue_with_parent; +} + + +ir_visitor_status +ir_function_inlining_visitor::visit_enter(ir_call *ir) +{ + if (can_inline(ir)) { + /* If the call was part of some tree, then it should have been + * flattened out or we shouldn't have seen it because of a + * visit_continue_with_parent in this visitor. + */ + assert(ir == base_ir); + + (void) ir->generate_inline(ir); + ir->remove(); + this->progress = true; + } + + return visit_continue; +} + + +ir_visitor_status +ir_function_inlining_visitor::visit_enter(ir_assignment *ir) +{ + ir_call *call = ir->rhs->as_call(); + if (!call || !can_inline(call)) + return visit_continue; + + /* generates the parameter setup, function body, and returns the return + * value of the function + */ + ir_rvalue *rhs = call->generate_inline(ir); + assert(rhs); + + ir->rhs = rhs; + this->progress = true; + + return visit_continue; +} + +/** + * Replaces references to the "sampler" variable with a clone of "deref." + * + * From the spec, samplers can appear in the tree as function + * (non-out) parameters and as the result of array indexing and + * structure field selection. In our builtin implementation, they + * also appear in the sampler field of an ir_tex instruction. + */ + +class ir_sampler_replacement_visitor : public ir_hierarchical_visitor { +public: + ir_sampler_replacement_visitor(ir_variable *sampler, ir_dereference *deref) + { + this->sampler = sampler; + this->deref = deref; + } + + virtual ~ir_sampler_replacement_visitor() + { + } + + virtual ir_visitor_status visit_leave(ir_call *); + virtual ir_visitor_status visit_leave(ir_dereference_array *); + virtual ir_visitor_status visit_leave(ir_dereference_record *); + virtual ir_visitor_status visit_leave(ir_texture *); + + void replace_deref(ir_dereference **deref); + void replace_rvalue(ir_rvalue **rvalue); + + ir_variable *sampler; + ir_dereference *deref; +}; + +void +ir_sampler_replacement_visitor::replace_deref(ir_dereference **deref) +{ + ir_dereference_variable *deref_var = (*deref)->as_dereference_variable(); + if (deref_var && deref_var->var == this->sampler) { + *deref = this->deref->clone(ralloc_parent(*deref), NULL); + } +} + +void +ir_sampler_replacement_visitor::replace_rvalue(ir_rvalue **rvalue) +{ + if (!*rvalue) + return; + + ir_dereference *deref = (*rvalue)->as_dereference(); + + if (!deref) + return; + + replace_deref(&deref); + *rvalue = deref; +} + +ir_visitor_status +ir_sampler_replacement_visitor::visit_leave(ir_texture *ir) +{ + replace_deref(&ir->sampler); + + return visit_continue; +} + +ir_visitor_status +ir_sampler_replacement_visitor::visit_leave(ir_dereference_array *ir) +{ + replace_rvalue(&ir->array); + return visit_continue; +} + +ir_visitor_status +ir_sampler_replacement_visitor::visit_leave(ir_dereference_record *ir) +{ + replace_rvalue(&ir->record); + return visit_continue; +} + +ir_visitor_status +ir_sampler_replacement_visitor::visit_leave(ir_call *ir) +{ + foreach_iter(exec_list_iterator, iter, *ir) { + ir_rvalue *param = (ir_rvalue *)iter.get(); + ir_rvalue *new_param = param; + replace_rvalue(&new_param); + + if (new_param != param) { + param->replace_with(new_param); + } + } + return visit_continue; +} + +static void +do_sampler_replacement(exec_list *instructions, + ir_variable *sampler, + ir_dereference *deref) +{ + ir_sampler_replacement_visitor v(sampler, deref); + + visit_list_elements(&v, instructions); +} diff --git a/src/glsl/opt_if_simplification.cpp b/src/glsl/opt_if_simplification.cpp new file mode 100644 index 0000000..618bacf --- /dev/null +++ b/src/glsl/opt_if_simplification.cpp @@ -0,0 +1,84 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_if_simplification.cpp + * + * Moves constant branches of if statements out to the surrounding + * instruction stream. + */ + +#include "ir.h" + +class ir_if_simplification_visitor : public ir_hierarchical_visitor { +public: + ir_if_simplification_visitor() + { + this->made_progress = false; + } + + ir_visitor_status visit_leave(ir_if *); + + bool made_progress; +}; + +bool +do_if_simplification(exec_list *instructions) +{ + ir_if_simplification_visitor v; + + v.run(instructions); + return v.made_progress; +} + + +ir_visitor_status +ir_if_simplification_visitor::visit_leave(ir_if *ir) +{ + /* FINISHME: Ideally there would be a way to note that the condition results + * FINISHME: in a constant before processing both of the other subtrees. + * FINISHME: This can probably be done with some flags, but it would take + * FINISHME: some work to get right. + */ + ir_constant *condition_constant = ir->condition->constant_expression_value(); + if (condition_constant) { + /* Move the contents of the one branch of the conditional + * that matters out. + */ + if (condition_constant->value.b[0]) { + foreach_iter(exec_list_iterator, then_iter, ir->then_instructions) { + ir_instruction *then_ir = (ir_instruction *)then_iter.get(); + ir->insert_before(then_ir); + } + } else { + foreach_iter(exec_list_iterator, else_iter, ir->else_instructions) { + ir_instruction *else_ir = (ir_instruction *)else_iter.get(); + ir->insert_before(else_ir); + } + } + ir->remove(); + this->made_progress = true; + } + + return visit_continue; +} diff --git a/src/glsl/opt_noop_swizzle.cpp b/src/glsl/opt_noop_swizzle.cpp new file mode 100644 index 0000000..0a906aa --- /dev/null +++ b/src/glsl/opt_noop_swizzle.cpp @@ -0,0 +1,80 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_noop_swizzle.cpp + * + * If a swizzle doesn't change the order or count of components, then + * remove the swizzle so that other optimization passes see the value + * behind it. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_rvalue_visitor.h" +#include "ir_print_visitor.h" +#include "glsl_types.h" + +class ir_noop_swizzle_visitor : public ir_rvalue_visitor { +public: + ir_noop_swizzle_visitor() + { + this->progress = false; + } + + void handle_rvalue(ir_rvalue **rvalue); + bool progress; +}; + +void +ir_noop_swizzle_visitor::handle_rvalue(ir_rvalue **rvalue) +{ + if (!*rvalue) + return; + + ir_swizzle *swiz = (*rvalue)->as_swizzle(); + if (!swiz || swiz->type != swiz->val->type) + return; + + int elems = swiz->val->type->vector_elements; + if (swiz->mask.x != 0) + return; + if (elems >= 2 && swiz->mask.y != 1) + return; + if (elems >= 3 && swiz->mask.z != 2) + return; + if (elems >= 4 && swiz->mask.w != 3) + return; + + this->progress = true; + *rvalue = swiz->val; +} + +bool +do_noop_swizzle(exec_list *instructions) +{ + ir_noop_swizzle_visitor v; + visit_list_elements(&v, instructions); + + return v.progress; +} diff --git a/src/glsl/opt_redundant_jumps.cpp b/src/glsl/opt_redundant_jumps.cpp new file mode 100644 index 0000000..edf4bb6 --- /dev/null +++ b/src/glsl/opt_redundant_jumps.cpp @@ -0,0 +1,111 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_redundant_jumps.cpp + * Remove certain types of redundant jumps + */ + +#include "ir.h" + +class redundant_jumps_visitor : public ir_hierarchical_visitor { +public: + redundant_jumps_visitor() + { + this->progress = false; + } + + virtual ir_visitor_status visit_leave(ir_if *); + virtual ir_visitor_status visit_leave(ir_loop *); + + bool progress; +}; + + +ir_visitor_status +redundant_jumps_visitor::visit_leave(ir_if *ir) +{ + /* If the last instruction in both branches is a 'break' or a 'continue', + * pull it out of the branches and insert it after the if-statment. Note + * that both must be the same type (either 'break' or 'continue'). + */ + ir_instruction *const last_then = + (ir_instruction *) ir->then_instructions.get_tail(); + ir_instruction *const last_else = + (ir_instruction *) ir->else_instructions.get_tail(); + + if ((last_then == NULL) || (last_else == NULL)) + return visit_continue; + + if ((last_then->ir_type != ir_type_loop_jump) + || (last_else->ir_type != ir_type_loop_jump)) + return visit_continue; + + ir_loop_jump *const then_jump = (ir_loop_jump *) last_then; + ir_loop_jump *const else_jump = (ir_loop_jump *) last_else; + + if (then_jump->mode != else_jump->mode) + return visit_continue; + + then_jump->remove(); + else_jump->remove(); + this->progress = true; + + ir->insert_after(then_jump); + + /* If both branchs of the if-statement are now empty, remove the + * if-statement. + */ + if (ir->then_instructions.is_empty() && ir->else_instructions.is_empty()) + ir->remove(); + + return visit_continue; +} + + +ir_visitor_status +redundant_jumps_visitor::visit_leave(ir_loop *ir) +{ + /* If the last instruction of a loop body is a 'continue', remove it. + */ + ir_instruction *const last = + (ir_instruction *) ir->body_instructions.get_tail(); + + if (last && (last->ir_type == ir_type_loop_jump) + && (((ir_loop_jump *) last)->mode == ir_loop_jump::jump_continue)) { + last->remove(); + this->progress = true; + } + + return visit_continue; +} + + +bool +optimize_redundant_jumps(exec_list *instructions) +{ + redundant_jumps_visitor v; + + v.run(instructions); + return v.progress; +} diff --git a/src/glsl/opt_structure_splitting.cpp b/src/glsl/opt_structure_splitting.cpp new file mode 100644 index 0000000..014407c --- /dev/null +++ b/src/glsl/opt_structure_splitting.cpp @@ -0,0 +1,361 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_structure_splitting.cpp + * + * If a structure is only ever referenced by its components, then + * split those components out to individual variables so they can be + * handled normally by other optimization passes. + * + * This skips structures like uniforms, which need to be accessible as + * structures for their access by the GL. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_print_visitor.h" +#include "ir_rvalue_visitor.h" +#include "glsl_types.h" + +static bool debug = false; + +// XXX using variable_entry2 here to avoid collision (MSVC multiply-defined +// function) with the variable_entry class seen in ir_variable_refcount.h +// Perhaps we can use the one in ir_variable_refcount.h and make this class +// here go away? +class variable_entry2 : public exec_node +{ +public: + variable_entry2(ir_variable *var) + { + this->var = var; + this->whole_structure_access = 0; + this->declaration = false; + this->components = NULL; + this->mem_ctx = NULL; + } + + ir_variable *var; /* The key: the variable's pointer. */ + + /** Number of times the variable is referenced, including assignments. */ + unsigned whole_structure_access; + + bool declaration; /* If the variable had a decl in the instruction stream */ + + ir_variable **components; + + /** ralloc_parent(this->var) -- the shader's ralloc context. */ + void *mem_ctx; +}; + + +class ir_structure_reference_visitor : public ir_hierarchical_visitor { +public: + ir_structure_reference_visitor(void) + { + this->mem_ctx = ralloc_context(NULL); + this->variable_list.make_empty(); + } + + ~ir_structure_reference_visitor(void) + { + ralloc_free(mem_ctx); + } + + virtual ir_visitor_status visit(ir_variable *); + virtual ir_visitor_status visit(ir_dereference_variable *); + virtual ir_visitor_status visit_enter(ir_dereference_record *); + virtual ir_visitor_status visit_enter(ir_assignment *); + virtual ir_visitor_status visit_enter(ir_function_signature *); + + variable_entry2 *get_variable_entry2(ir_variable *var); + + /* List of variable_entry */ + exec_list variable_list; + + void *mem_ctx; +}; + +variable_entry2 * +ir_structure_reference_visitor::get_variable_entry2(ir_variable *var) +{ + assert(var); + + if (!var->type->is_record() || var->mode == ir_var_uniform) + return NULL; + + foreach_iter(exec_list_iterator, iter, this->variable_list) { + variable_entry2 *entry = (variable_entry2 *)iter.get(); + if (entry->var == var) + return entry; + } + + variable_entry2 *entry = new(mem_ctx) variable_entry2(var); + this->variable_list.push_tail(entry); + return entry; +} + + +ir_visitor_status +ir_structure_reference_visitor::visit(ir_variable *ir) +{ + variable_entry2 *entry = this->get_variable_entry2(ir); + + if (entry) + entry->declaration = true; + + return visit_continue; +} + +ir_visitor_status +ir_structure_reference_visitor::visit(ir_dereference_variable *ir) +{ + ir_variable *const var = ir->variable_referenced(); + variable_entry2 *entry = this->get_variable_entry2(var); + + if (entry) + entry->whole_structure_access++; + + return visit_continue; +} + +ir_visitor_status +ir_structure_reference_visitor::visit_enter(ir_dereference_record *ir) +{ + (void) ir; + /* Don't descend into the ir_dereference_variable below. */ + return visit_continue_with_parent; +} + +ir_visitor_status +ir_structure_reference_visitor::visit_enter(ir_assignment *ir) +{ + if (ir->lhs->as_dereference_variable() && + ir->rhs->as_dereference_variable() && + !ir->condition) { + /* We'll split copies of a structure to copies of components, so don't + * descend to the ir_dereference_variables. + */ + return visit_continue_with_parent; + } + return visit_continue; +} + +ir_visitor_status +ir_structure_reference_visitor::visit_enter(ir_function_signature *ir) +{ + /* We don't want to descend into the function parameters and + * dead-code eliminate them, so just accept the body here. + */ + visit_list_elements(this, &ir->body); + return visit_continue_with_parent; +} + +class ir_structure_splitting_visitor : public ir_rvalue_visitor { +public: + ir_structure_splitting_visitor(exec_list *vars) + { + this->variable_list = vars; + } + + virtual ~ir_structure_splitting_visitor() + { + } + + virtual ir_visitor_status visit_leave(ir_assignment *); + + void split_deref(ir_dereference **deref); + void handle_rvalue(ir_rvalue **rvalue); + variable_entry2 *get_splitting_entry(ir_variable *var); + + exec_list *variable_list; + void *mem_ctx; +}; + +variable_entry2 * +ir_structure_splitting_visitor::get_splitting_entry(ir_variable *var) +{ + assert(var); + + if (!var->type->is_record()) + return NULL; + + foreach_iter(exec_list_iterator, iter, *this->variable_list) { + variable_entry2 *entry = (variable_entry2 *)iter.get(); + if (entry->var == var) { + return entry; + } + } + + return NULL; +} + +void +ir_structure_splitting_visitor::split_deref(ir_dereference **deref) +{ + if ((*deref)->ir_type != ir_type_dereference_record) + return; + + ir_dereference_record *deref_record = (ir_dereference_record *)*deref; + ir_dereference_variable *deref_var = deref_record->record->as_dereference_variable(); + if (!deref_var) + return; + + variable_entry2 *entry = get_splitting_entry(deref_var->var); + if (!entry) + return; + + unsigned int i; + for (i = 0; i < entry->var->type->length; i++) { + if (strcmp(deref_record->field, + entry->var->type->fields.structure[i].name) == 0) + break; + } + assert(i != entry->var->type->length); + + *deref = new(entry->mem_ctx) ir_dereference_variable(entry->components[i]); +} + +void +ir_structure_splitting_visitor::handle_rvalue(ir_rvalue **rvalue) +{ + if (!*rvalue) + return; + + ir_dereference *deref = (*rvalue)->as_dereference(); + + if (!deref) + return; + + split_deref(&deref); + *rvalue = deref; +} + +ir_visitor_status +ir_structure_splitting_visitor::visit_leave(ir_assignment *ir) +{ + ir_dereference_variable *lhs_deref = ir->lhs->as_dereference_variable(); + ir_dereference_variable *rhs_deref = ir->rhs->as_dereference_variable(); + variable_entry2 *lhs_entry = lhs_deref ? get_splitting_entry(lhs_deref->var) : NULL; + variable_entry2 *rhs_entry = rhs_deref ? get_splitting_entry(rhs_deref->var) : NULL; + const glsl_type *type = ir->rhs->type; + + if ((lhs_entry || rhs_entry) && !ir->condition) { + for (unsigned int i = 0; i < type->length; i++) { + ir_dereference *new_lhs, *new_rhs; + void *mem_ctx = lhs_entry ? lhs_entry->mem_ctx : rhs_entry->mem_ctx; + + if (lhs_entry) { + new_lhs = new(mem_ctx) ir_dereference_variable(lhs_entry->components[i]); + } else { + new_lhs = new(mem_ctx) + ir_dereference_record(ir->lhs->clone(mem_ctx, NULL), + type->fields.structure[i].name); + } + + if (rhs_entry) { + new_rhs = new(mem_ctx) ir_dereference_variable(rhs_entry->components[i]); + } else { + new_rhs = new(mem_ctx) + ir_dereference_record(ir->rhs->clone(mem_ctx, NULL), + type->fields.structure[i].name); + } + + ir->insert_before(new(mem_ctx) ir_assignment(new_lhs, + new_rhs, + NULL)); + } + ir->remove(); + } else { + handle_rvalue(&ir->rhs); + split_deref(&ir->lhs); + } + + handle_rvalue(&ir->condition); + + return visit_continue; +} + +bool +do_structure_splitting(exec_list *instructions) +{ + ir_structure_reference_visitor refs; + + visit_list_elements(&refs, instructions); + + /* Trim out variables we can't split. */ + foreach_iter(exec_list_iterator, iter, refs.variable_list) { + variable_entry2 *entry = (variable_entry2 *)iter.get(); + + if (debug) { + printf("structure %s@%p: decl %d, whole_access %d\n", + entry->var->name, (void *) entry->var, entry->declaration, + entry->whole_structure_access); + } + + if (!entry->declaration || entry->whole_structure_access) { + entry->remove(); + } + } + + if (refs.variable_list.is_empty()) + return false; + + void *mem_ctx = ralloc_context(NULL); + + /* Replace the decls of the structures to be split with their split + * components. + */ + foreach_iter(exec_list_iterator, iter, refs.variable_list) { + variable_entry2 *entry = (variable_entry2 *)iter.get(); + const struct glsl_type *type = entry->var->type; + + entry->mem_ctx = ralloc_parent(entry->var); + + entry->components = ralloc_array(mem_ctx, + ir_variable *, + type->length); + + for (unsigned int i = 0; i < entry->var->type->length; i++) { + const char *name = ralloc_asprintf(mem_ctx, "%s_%s", + entry->var->name, + type->fields.structure[i].name); + + entry->components[i] = + new(entry->mem_ctx) ir_variable(type->fields.structure[i].type, + name, + ir_var_temporary); + entry->var->insert_before(entry->components[i]); + } + + entry->var->remove(); + } + + ir_structure_splitting_visitor split(&refs.variable_list); + visit_list_elements(&split, instructions); + + ralloc_free(mem_ctx); + + return true; +} diff --git a/src/glsl/opt_swizzle_swizzle.cpp b/src/glsl/opt_swizzle_swizzle.cpp new file mode 100644 index 0000000..bc442fa --- /dev/null +++ b/src/glsl/opt_swizzle_swizzle.cpp @@ -0,0 +1,93 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_swizzle_swizzle.cpp + * + * Eliminates the second swizzle in a swizzle chain. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_optimization.h" +#include "glsl_types.h" + +class ir_swizzle_swizzle_visitor : public ir_hierarchical_visitor { +public: + ir_swizzle_swizzle_visitor() + { + progress = false; + } + + virtual ir_visitor_status visit_enter(ir_swizzle *); + + bool progress; +}; + +ir_visitor_status +ir_swizzle_swizzle_visitor::visit_enter(ir_swizzle *ir) +{ + int mask2[4]; + + ir_swizzle *swiz2 = ir->val->as_swizzle(); + if (!swiz2) + return visit_continue; + + memset(&mask2, 0, sizeof(mask2)); + if (swiz2->mask.num_components >= 1) + mask2[0] = swiz2->mask.x; + if (swiz2->mask.num_components >= 2) + mask2[1] = swiz2->mask.y; + if (swiz2->mask.num_components >= 3) + mask2[2] = swiz2->mask.z; + if (swiz2->mask.num_components >= 4) + mask2[3] = swiz2->mask.w; + + if (ir->mask.num_components >= 1) + ir->mask.x = mask2[ir->mask.x]; + if (ir->mask.num_components >= 2) + ir->mask.y = mask2[ir->mask.y]; + if (ir->mask.num_components >= 3) + ir->mask.z = mask2[ir->mask.z]; + if (ir->mask.num_components >= 4) + ir->mask.w = mask2[ir->mask.w]; + + ir->val = swiz2->val; + + this->progress = true; + + return visit_continue; +} + +/** + * Does a copy propagation pass on the code present in the instruction stream. + */ +bool +do_swizzle_swizzle(exec_list *instructions) +{ + ir_swizzle_swizzle_visitor v; + + v.run(instructions); + + return v.progress; +} diff --git a/src/glsl/opt_tree_grafting.cpp b/src/glsl/opt_tree_grafting.cpp new file mode 100644 index 0000000..9917c04 --- /dev/null +++ b/src/glsl/opt_tree_grafting.cpp @@ -0,0 +1,367 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_tree_grafting.cpp + * + * Takes assignments to variables that are dereferenced only once and + * pastes the RHS expression into where the variable is dereferenced. + * + * In the process of various operations like function inlining and + * tertiary op handling, we'll end up with our expression trees having + * been chopped up into a series of assignments of short expressions + * to temps. Other passes like ir_algebraic.cpp would prefer to see + * the deepest expression trees they can to try to optimize them. + * + * This is a lot like copy propagaton. In comparison, copy + * propagation only acts on plain copies, not arbitrary expressions on + * the RHS. Generally, we wouldn't want to go pasting some + * complicated expression everywhere it got used, though, so we don't + * handle expressions in that pass. + * + * The hard part is making sure we don't move an expression across + * some other assignments that would change the value of the + * expression. So we split this into two passes: First, find the + * variables in our scope which are written to once and read once, and + * then go through basic blocks seeing if we find an opportunity to + * move those expressions safely. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_variable_refcount.h" +#include "ir_basic_block.h" +#include "ir_optimization.h" +#include "glsl_types.h" + +static bool debug = false; + +class ir_tree_grafting_visitor : public ir_hierarchical_visitor { +public: + ir_tree_grafting_visitor(ir_assignment *graft_assign, + ir_variable *graft_var) + { + this->progress = false; + this->graft_assign = graft_assign; + this->graft_var = graft_var; + } + + virtual ir_visitor_status visit_leave(class ir_assignment *); + virtual ir_visitor_status visit_enter(class ir_call *); + virtual ir_visitor_status visit_enter(class ir_expression *); + virtual ir_visitor_status visit_enter(class ir_function *); + virtual ir_visitor_status visit_enter(class ir_function_signature *); + virtual ir_visitor_status visit_enter(class ir_if *); + virtual ir_visitor_status visit_enter(class ir_loop *); + virtual ir_visitor_status visit_enter(class ir_swizzle *); + virtual ir_visitor_status visit_enter(class ir_texture *); + + bool do_graft(ir_rvalue **rvalue); + + bool progress; + ir_variable *graft_var; + ir_assignment *graft_assign; +}; + +struct find_deref_info { + ir_variable *var; + bool found; +}; + +void +dereferences_variable_callback(ir_instruction *ir, void *data) +{ + struct find_deref_info *info = (struct find_deref_info *)data; + ir_dereference_variable *deref = ir->as_dereference_variable(); + + if (deref && deref->var == info->var) + info->found = true; +} + +static bool +dereferences_variable(ir_instruction *ir, ir_variable *var) +{ + struct find_deref_info info; + + info.var = var; + info.found = false; + + visit_tree(ir, dereferences_variable_callback, &info); + + return info.found; +} + +bool +ir_tree_grafting_visitor::do_graft(ir_rvalue **rvalue) +{ + if (!*rvalue) + return false; + + ir_dereference_variable *deref = (*rvalue)->as_dereference_variable(); + + if (!deref || deref->var != this->graft_var) + return false; + + if (debug) { + printf("GRAFTING:\n"); + this->graft_assign->print(); + printf("\n"); + printf("TO:\n"); + (*rvalue)->print(); + printf("\n"); + } + + this->graft_assign->remove(); + *rvalue = this->graft_assign->rhs; + + this->progress = true; + return true; +} + +ir_visitor_status +ir_tree_grafting_visitor::visit_enter(ir_loop *ir) +{ + (void)ir; + /* Do not traverse into the body of the loop since that is a + * different basic block. + */ + return visit_stop; +} + +ir_visitor_status +ir_tree_grafting_visitor::visit_leave(ir_assignment *ir) +{ + if (do_graft(&ir->rhs) || + do_graft(&ir->condition)) + return visit_stop; + + /* If this assignment updates a variable used in the assignment + * we're trying to graft, then we're done. + */ + if (dereferences_variable(this->graft_assign->rhs, + ir->lhs->variable_referenced())) { + if (debug) { + printf("graft killed by: "); + ir->print(); + printf("\n"); + } + return visit_stop; + } + + return visit_continue; +} + +ir_visitor_status +ir_tree_grafting_visitor::visit_enter(ir_function *ir) +{ + (void) ir; + return visit_continue_with_parent; +} + +ir_visitor_status +ir_tree_grafting_visitor::visit_enter(ir_function_signature *ir) +{ + (void)ir; + return visit_continue_with_parent; +} + +ir_visitor_status +ir_tree_grafting_visitor::visit_enter(ir_call *ir) +{ + exec_list_iterator sig_iter = ir->get_callee()->parameters.iterator(); + /* Reminder: iterating ir_call iterates its parameters. */ + foreach_iter(exec_list_iterator, iter, *ir) { + ir_variable *sig_param = (ir_variable *)sig_iter.get(); + ir_rvalue *ir = (ir_rvalue *)iter.get(); + ir_rvalue *new_ir = ir; + + if (sig_param->mode != ir_var_in) + continue; + + if (do_graft(&new_ir)) { + ir->replace_with(new_ir); + return visit_stop; + } + sig_iter.next(); + } + + return visit_continue; +} + +ir_visitor_status +ir_tree_grafting_visitor::visit_enter(ir_expression *ir) +{ + for (unsigned int i = 0; i < ir->get_num_operands(); i++) { + if (do_graft(&ir->operands[i])) + return visit_stop; + } + + return visit_continue; +} + +ir_visitor_status +ir_tree_grafting_visitor::visit_enter(ir_if *ir) +{ + if (do_graft(&ir->condition)) + return visit_stop; + + /* Do not traverse into the body of the if-statement since that is a + * different basic block. + */ + return visit_continue_with_parent; +} + +ir_visitor_status +ir_tree_grafting_visitor::visit_enter(ir_swizzle *ir) +{ + if (do_graft(&ir->val)) + return visit_stop; + + return visit_continue; +} + +ir_visitor_status +ir_tree_grafting_visitor::visit_enter(ir_texture *ir) +{ + if (do_graft(&ir->coordinate) || + do_graft(&ir->projector) || + do_graft(&ir->shadow_comparitor)) + return visit_stop; + + switch (ir->op) { + case ir_tex: + break; + case ir_txb: + if (do_graft(&ir->lod_info.bias)) + return visit_stop; + break; + case ir_txf: + case ir_txl: + if (do_graft(&ir->lod_info.lod)) + return visit_stop; + break; + case ir_txd: + if (do_graft(&ir->lod_info.grad.dPdx) || + do_graft(&ir->lod_info.grad.dPdy)) + return visit_stop; + break; + } + + return visit_continue; +} + +struct tree_grafting_info { + ir_variable_refcount_visitor *refs; + bool progress; +}; + +static bool +try_tree_grafting(ir_assignment *start, + ir_variable *lhs_var, + ir_instruction *bb_last) +{ + ir_tree_grafting_visitor v(start, lhs_var); + + if (debug) { + printf("trying to graft: "); + lhs_var->print(); + printf("\n"); + } + + for (ir_instruction *ir = (ir_instruction *)start->next; + ir != bb_last->next; + ir = (ir_instruction *)ir->next) { + + if (debug) { + printf("- "); + ir->print(); + printf("\n"); + } + + ir_visitor_status s = ir->accept(&v); + if (s == visit_stop) + return v.progress; + } + + return false; +} + +static void +tree_grafting_basic_block(ir_instruction *bb_first, + ir_instruction *bb_last, + void *data) +{ + struct tree_grafting_info *info = (struct tree_grafting_info *)data; + ir_instruction *ir, *next; + + for (ir = bb_first, next = (ir_instruction *)ir->next; + ir != bb_last->next; + ir = next, next = (ir_instruction *)ir->next) { + ir_assignment *assign = ir->as_assignment(); + + if (!assign) + continue; + + ir_variable *lhs_var = assign->whole_variable_written(); + if (!lhs_var) + continue; + + if (lhs_var->mode == ir_var_out || + lhs_var->mode == ir_var_inout) + continue; + + variable_entry *entry = info->refs->get_variable_entry(lhs_var); + + if (!entry->declaration || + entry->assigned_count != 1 || + entry->referenced_count != 2) + continue; + + assert(assign == entry->assign); + + /* Found a possibly graftable assignment. Now, walk through the + * rest of the BB seeing if the deref is here, and if nothing interfered with + * pasting its expression's values in between. + */ + info->progress |= try_tree_grafting(assign, lhs_var, bb_last); + } +} + +/** + * Does a copy propagation pass on the code present in the instruction stream. + */ +bool +do_tree_grafting(exec_list *instructions) +{ + ir_variable_refcount_visitor refs; + struct tree_grafting_info info; + + info.progress = false; + info.refs = &refs; + + visit_list_elements(info.refs, instructions); + + call_for_basic_blocks(instructions, tree_grafting_basic_block, &info); + + return info.progress; +} diff --git a/src/glsl/program.h b/src/glsl/program.h new file mode 100644 index 0000000..db602fa --- /dev/null +++ b/src/glsl/program.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (C) 2009 VMware, Inc. All Rights Reserved. + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice 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. + */ + +#include "main/core.h" + +extern void +link_shaders(struct gl_context *ctx, struct gl_shader_program *prog); diff --git a/src/glsl/ralloc.c b/src/glsl/ralloc.c new file mode 100644 index 0000000..f7edff6 --- /dev/null +++ b/src/glsl/ralloc.c @@ -0,0 +1,442 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include + +#include "ralloc.h" + +#ifdef __GNUC__ +#define likely(x) __builtin_expect(!!(x),1) +#define unlikely(x) __builtin_expect(!!(x),0) +#else +#define likely(x) !!(x) +#define unlikely(x) !!(x) +#endif + +#define CANARY 0x5A1106 + +struct ralloc_header +{ + /* A canary value used to determine whether a pointer is ralloc'd. */ + unsigned canary; + + struct ralloc_header *parent; + + /* The first child (head of a linked list) */ + struct ralloc_header *child; + + /* Linked list of siblings */ + struct ralloc_header *prev; + struct ralloc_header *next; + + void (*destructor)(void *); +}; + +typedef struct ralloc_header ralloc_header; + +static void unlink_block(ralloc_header *info); +static void unsafe_free(ralloc_header *info); + +static ralloc_header * +get_header(const void *ptr) +{ + ralloc_header *info = (ralloc_header *) (((char *) ptr) - + sizeof(ralloc_header)); + assert(info->canary == CANARY); + return info; +} + +#define PTR_FROM_HEADER(info) (((char *) info) + sizeof(ralloc_header)) + +static void +add_child(ralloc_header *parent, ralloc_header *info) +{ + if (parent != NULL) { + info->parent = parent; + info->next = parent->child; + parent->child = info; + + if (info->next != NULL) + info->next->prev = info; + } +} + +void * +ralloc_context(const void *ctx) +{ + return ralloc_size(ctx, 0); +} + +void * +ralloc_size(const void *ctx, size_t size) +{ + void *block = calloc(1, size + sizeof(ralloc_header)); + + ralloc_header *info = (ralloc_header *) block; + ralloc_header *parent = ctx != NULL ? get_header(ctx) : NULL; + + add_child(parent, info); + + info->canary = CANARY; + + return PTR_FROM_HEADER(info); +} + +void * +rzalloc_size(const void *ctx, size_t size) +{ + void *ptr = ralloc_size(ctx, size); + if (likely(ptr != NULL)) + memset(ptr, 0, size); + return ptr; +} + +/* helper function - assumes ptr != NULL */ +static void * +resize(void *ptr, size_t size) +{ + ralloc_header *child, *old, *info; + + old = get_header(ptr); + info = realloc(old, size + sizeof(ralloc_header)); + + if (info == NULL) + return NULL; + + /* Update parent and sibling's links to the reallocated node. */ + if (info != old && info->parent != NULL) { + if (info->parent->child == old) + info->parent->child = info; + + if (info->prev != NULL) + info->prev->next = info; + + if (info->next != NULL) + info->next->prev = info; + } + + /* Update child->parent links for all children */ + for (child = info->child; child != NULL; child = child->next) + child->parent = info; + + return PTR_FROM_HEADER(info); +} + +void * +reralloc_size(const void *ctx, void *ptr, size_t size) +{ + if (unlikely(ptr == NULL)) + return ralloc_size(ctx, size); + + assert(ralloc_parent(ptr) == ctx); + return resize(ptr, size); +} + +void * +ralloc_array_size(const void *ctx, size_t size, unsigned count) +{ + if (count > SIZE_MAX/size) + return NULL; + + return ralloc_size(ctx, size * count); +} + +void * +rzalloc_array_size(const void *ctx, size_t size, unsigned count) +{ + if (count > SIZE_MAX/size) + return NULL; + + return rzalloc_size(ctx, size * count); +} + +void * +reralloc_array_size(const void *ctx, void *ptr, size_t size, unsigned count) +{ + if (count > SIZE_MAX/size) + return NULL; + + return reralloc_size(ctx, ptr, size * count); +} + +void +ralloc_free(void *ptr) +{ + ralloc_header *info; + + if (ptr == NULL) + return; + + info = get_header(ptr); + unlink_block(info); + unsafe_free(info); +} + +static void +unlink_block(ralloc_header *info) +{ + /* Unlink from parent & siblings */ + if (info->parent != NULL) { + if (info->parent->child == info) + info->parent->child = info->next; + + if (info->prev != NULL) + info->prev->next = info->next; + + if (info->next != NULL) + info->next->prev = info->prev; + } + info->parent = NULL; + info->prev = NULL; + info->next = NULL; +} + +static void +unsafe_free(ralloc_header *info) +{ + /* Recursively free any children...don't waste time unlinking them. */ + ralloc_header *temp; + while (info->child != NULL) { + temp = info->child; + info->child = temp->next; + unsafe_free(temp); + } + + /* Free the block itself. Call the destructor first, if any. */ + if (info->destructor != NULL) + info->destructor(PTR_FROM_HEADER(info)); + + free(info); +} + +void +ralloc_steal(const void *new_ctx, void *ptr) +{ + ralloc_header *info, *parent; + + if (unlikely(ptr == NULL)) + return; + + info = get_header(ptr); + parent = get_header(new_ctx); + + unlink_block(info); + + add_child(parent, info); +} + +void * +ralloc_parent(const void *ptr) +{ + ralloc_header *info; + + if (unlikely(ptr == NULL)) + return NULL; + + info = get_header(ptr); + return PTR_FROM_HEADER(info->parent); +} + +static void *autofree_context = NULL; + +static void +autofree(void) +{ + ralloc_free(autofree_context); +} + +void * +ralloc_autofree_context(void) +{ + if (unlikely(autofree_context == NULL)) { + autofree_context = ralloc_context(NULL); + atexit(autofree); + } + return autofree_context; +} + +void +ralloc_set_destructor(const void *ptr, void(*destructor)(void *)) +{ + ralloc_header *info = get_header(ptr); + info->destructor = destructor; +} + +char * +ralloc_strdup(const void *ctx, const char *str) +{ + size_t n; + char *ptr; + + if (unlikely(str == NULL)) + return NULL; + + n = strlen(str); + ptr = ralloc_array(ctx, char, n + 1); + memcpy(ptr, str, n); + ptr[n] = '\0'; + return ptr; +} + +char * +ralloc_strndup(const void *ctx, const char *str, size_t max) +{ + size_t n; + char *ptr; + + if (unlikely(str == NULL)) + return NULL; + + n = strlen(str); + if (n > max) + n = max; + + ptr = ralloc_array(ctx, char, n + 1); + memcpy(ptr, str, n); + ptr[n] = '\0'; + return ptr; +} + +/* helper routine for strcat/strncat - n is the exact amount to copy */ +static bool +cat(char **dest, const char *str, size_t n) +{ + char *both; + size_t existing_length; + assert(dest != NULL && *dest != NULL); + + existing_length = strlen(*dest); + both = resize(*dest, existing_length + n + 1); + if (unlikely(both == NULL)) + return false; + + memcpy(both + existing_length, str, n); + both[existing_length + n] = '\0'; + + *dest = both; + return true; +} + + +bool +ralloc_strcat(char **dest, const char *str) +{ + return cat(dest, str, strlen(str)); +} + +bool +ralloc_strncat(char **dest, const char *str, size_t n) +{ + /* Clamp n to the string length */ + size_t str_length = strlen(str); + if (str_length < n) + n = str_length; + + return cat(dest, str, n); +} + +char * +ralloc_asprintf(const void *ctx, const char *fmt, ...) +{ + char *ptr; + va_list args; + va_start(args, fmt); + ptr = ralloc_vasprintf(ctx, fmt, args); + va_end(args); + return ptr; +} + +/* Return the length of the string that would be generated by a printf-style + * format and argument list, not including the \0 byte. + */ +static size_t +printf_length(const char *fmt, va_list untouched_args) +{ + int size; + char junk; + + /* Make a copy of the va_list so the original caller can still use it */ + va_list args; + va_copy(args, untouched_args); + + size = vsnprintf(&junk, 1, fmt, args); + assert(size >= 0); + + va_end(args); + + return size; +} + +char * +ralloc_vasprintf(const void *ctx, const char *fmt, va_list args) +{ + size_t size = printf_length(fmt, args) + 1; + + char *ptr = ralloc_size(ctx, size); + if (ptr != NULL) + vsnprintf(ptr, size, fmt, args); + + return ptr; +} + +bool +ralloc_asprintf_append(char **str, const char *fmt, ...) +{ + bool success; + va_list args; + va_start(args, fmt); + success = ralloc_vasprintf_append(str, fmt, args); + va_end(args); + return success; +} + +bool +ralloc_vasprintf_append(char **str, const char *fmt, va_list args) +{ + size_t existing_length, new_length; + char *ptr; + + assert(str != NULL); + + if (unlikely(*str == NULL)) { + // Assuming a NULL context is probably bad, but it's expected behavior. + *str = ralloc_vasprintf(NULL, fmt, args); + return true; + } + + existing_length = strlen(*str); + new_length = printf_length(fmt, args); + + ptr = resize(*str, existing_length + new_length + 1); + if (unlikely(ptr == NULL)) + return false; + + vsnprintf(ptr + existing_length, new_length + 1, fmt, args); + *str = ptr; + return true; +} diff --git a/src/glsl/ralloc.h b/src/glsl/ralloc.h new file mode 100644 index 0000000..d533815 --- /dev/null +++ b/src/glsl/ralloc.h @@ -0,0 +1,345 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ralloc.h + * + * ralloc: a recursive memory allocator + * + * The ralloc memory allocator creates a hierarchy of allocated + * objects. Every allocation is in reference to some parent, and + * every allocated object can in turn be used as the parent of a + * subsequent allocation. This allows for extremely convenient + * discarding of an entire tree/sub-tree of allocations by calling + * ralloc_free on any particular object to free it and all of its + * children. + * + * The conceptual working of ralloc was directly inspired by Andrew + * Tridgell's talloc, but ralloc is an independent implementation + * released under the MIT license and tuned for Mesa. + * + * The talloc implementation is available under the GNU Lesser + * General Public License (GNU LGPL), version 3 or later. It is + * more sophisticated than ralloc in that it includes reference + * counting and debugging features. See: http://talloc.samba.org/ + */ + +#ifndef RALLOC_H +#define RALLOC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/** + * \def ralloc(ctx, type) + * Allocate a new object chained off of the given context. + * + * This is equivalent to: + * \code + * ((type *) ralloc_size(ctx, sizeof(type)) + * \endcode + */ +#define ralloc(ctx, type) ((type *) ralloc_size(ctx, sizeof(type))) + +/** + * \def rzalloc(ctx, type) + * Allocate a new object out of the given context and initialize it to zero. + * + * This is equivalent to: + * \code + * ((type *) rzalloc_size(ctx, sizeof(type)) + * \endcode + */ +#define rzalloc(ctx, type) ((type *) rzalloc_size(ctx, sizeof(type))) + +/** + * Allocate a new ralloc context. + * + * While any ralloc'd pointer can be used as a context, sometimes it is useful + * to simply allocate a context with no associated memory. + * + * It is equivalent to: + * \code + * ((type *) ralloc_size(ctx, 0) + * \endcode + */ +void *ralloc_context(const void *ctx); + +/** + * Allocate memory chained off of the given context. + * + * This is the core allocation routine which is used by all others. It + * simply allocates storage for \p size bytes and returns the pointer, + * similar to \c malloc. + */ +void *ralloc_size(const void *ctx, size_t size); + +/** + * Allocate zero-initialized memory chained off of the given context. + * + * This is similar to \c calloc with a size of 1. + */ +void *rzalloc_size(const void *ctx, size_t size); + +/** + * Resize a piece of ralloc-managed memory, preserving data. + * + * Similar to \c realloc. Unlike C89, passing 0 for \p size does not free the + * memory. Instead, it resizes it to a 0-byte ralloc context, just like + * calling ralloc_size(ctx, 0). This is different from talloc. + * + * \param ctx The context to use for new allocation. If \p ptr != NULL, + * it must be the same as ralloc_parent(\p ptr). + * \param ptr Pointer to the memory to be resized. May be NULL. + * \param size The amount of memory to allocate, in bytes. + */ +void *reralloc_size(const void *ctx, void *ptr, size_t size); + +/// \defgroup array Array Allocators @{ + +/** + * \def ralloc_array(ctx, type, count) + * Allocate an array of objects chained off the given context. + * + * Similar to \c calloc, but does not initialize the memory to zero. + * + * More than a convenience function, this also checks for integer overflow when + * multiplying \c sizeof(type) and \p count. This is necessary for security. + * + * This is equivalent to: + * \code + * ((type *) ralloc_array_size(ctx, sizeof(type), count) + * \endcode + */ +#define ralloc_array(ctx, type, count) \ + ((type *) ralloc_array_size(ctx, sizeof(type), count)) + +/** + * \def rzalloc_array(ctx, type, count) + * Allocate a zero-initialized array chained off the given context. + * + * Similar to \c calloc. + * + * More than a convenience function, this also checks for integer overflow when + * multiplying \c sizeof(type) and \p count. This is necessary for security. + * + * This is equivalent to: + * \code + * ((type *) rzalloc_array_size(ctx, sizeof(type), count) + * \endcode + */ +#define rzalloc_array(ctx, type, count) \ + ((type *) rzalloc_array_size(ctx, sizeof(type), count)) + +/** + * \def reralloc(ctx, ptr, type, count) + * Resize a ralloc-managed array, preserving data. + * + * Similar to \c realloc. Unlike C89, passing 0 for \p size does not free the + * memory. Instead, it resizes it to a 0-byte ralloc context, just like + * calling ralloc_size(ctx, 0). This is different from talloc. + * + * More than a convenience function, this also checks for integer overflow when + * multiplying \c sizeof(type) and \p count. This is necessary for security. + * + * \param ctx The context to use for new allocation. If \p ptr != NULL, + * it must be the same as ralloc_parent(\p ptr). + * \param ptr Pointer to the array to be resized. May be NULL. + * \param type The element type. + * \param count The number of elements to allocate. + */ +#define reralloc(ctx, ptr, type, count) \ + ((type *) reralloc_array_size(ctx, ptr, sizeof(type), count)) + +/** + * Allocate memory for an array chained off the given context. + * + * Similar to \c calloc, but does not initialize the memory to zero. + * + * More than a convenience function, this also checks for integer overflow when + * multiplying \p size and \p count. This is necessary for security. + */ +void *ralloc_array_size(const void *ctx, size_t size, unsigned count); + +/** + * Allocate a zero-initialized array chained off the given context. + * + * Similar to \c calloc. + * + * More than a convenience function, this also checks for integer overflow when + * multiplying \p size and \p count. This is necessary for security. + */ +void *rzalloc_array_size(const void *ctx, size_t size, unsigned count); + +/** + * Resize a ralloc-managed array, preserving data. + * + * Similar to \c realloc. Unlike C89, passing 0 for \p size does not free the + * memory. Instead, it resizes it to a 0-byte ralloc context, just like + * calling ralloc_size(ctx, 0). This is different from talloc. + * + * More than a convenience function, this also checks for integer overflow when + * multiplying \c sizeof(type) and \p count. This is necessary for security. + * + * \param ctx The context to use for new allocation. If \p ptr != NULL, + * it must be the same as ralloc_parent(\p ptr). + * \param ptr Pointer to the array to be resized. May be NULL. + * \param size The size of an individual element. + * \param count The number of elements to allocate. + * + * \return True unless allocation failed. + */ +void *reralloc_array_size(const void *ctx, void *ptr, size_t size, + unsigned count); +/// @} + +/** + * Free a piece of ralloc-managed memory. + * + * This will also free the memory of any children allocated this context. + */ +void ralloc_free(void *ptr); + +/** + * "Steal" memory from one context, changing it to another. + * + * This changes \p ptr's context to \p new_ctx. This is quite useful if + * memory is allocated out of a temporary context. + */ +void ralloc_steal(const void *new_ctx, void *ptr); + +/** + * Return the given pointer's ralloc context. + */ +void *ralloc_parent(const void *ptr); + +/** + * Return a context whose memory will be automatically freed at program exit. + * + * The first call to this function creates a context and registers a handler + * to free it using \c atexit. This may cause trouble if used in a library + * loaded with \c dlopen. + */ +void *ralloc_autofree_context(void); + +/** + * Set a callback to occur just before an object is freed. + */ +void ralloc_set_destructor(const void *ptr, void(*destructor)(void *)); + +/// \defgroup array String Functions @{ +/** + * Duplicate a string, allocating the memory from the given context. + */ +char *ralloc_strdup(const void *ctx, const char *str); + +/** + * Duplicate a string, allocating the memory from the given context. + * + * Like \c strndup, at most \p n characters are copied. If \p str is longer + * than \p n characters, \p n are copied, and a termining \c '\0' byte is added. + */ +char *ralloc_strndup(const void *ctx, const char *str, size_t n); + +/** + * Concatenate two strings, allocating the necessary space. + * + * This appends \p str to \p *dest, similar to \c strcat, using ralloc_resize + * to expand \p *dest to the appropriate size. \p dest will be updated to the + * new pointer unless allocation fails. + * + * The result will always be null-terminated. + * + * \return True unless allocation failed. + */ +bool ralloc_strcat(char **dest, const char *str); + +/** + * Concatenate two strings, allocating the necessary space. + * + * This appends at most \p n bytes of \p str to \p *dest, using ralloc_resize + * to expand \p *dest to the appropriate size. \p dest will be updated to the + * new pointer unless allocation fails. + * + * The result will always be null-terminated; \p str does not need to be null + * terminated if it is longer than \p n. + * + * \return True unless allocation failed. + */ +bool ralloc_strncat(char **dest, const char *str, size_t n); + +/** + * Print to a string. + * + * This is analogous to \c sprintf, but allocates enough space (using \p ctx + * as the context) for the resulting string. + * + * \return The newly allocated string. + */ +char *ralloc_asprintf (const void *ctx, const char *fmt, ...); + +/** + * Print to a string, given a va_list. + * + * This is analogous to \c vsprintf, but allocates enough space (using \p ctx + * as the context) for the resulting string. + * + * \return The newly allocated string. + */ +char *ralloc_vasprintf(const void *ctx, const char *fmt, va_list args); + +/** + * Append formatted text to the supplied string. + * + * \sa ralloc_asprintf + * \sa ralloc_strcat + * + * \p str will be updated to the new pointer unless allocation fails. + * + * \return True unless allocation failed. + */ +bool ralloc_asprintf_append (char **str, const char *fmt, ...); + +/** + * Append formatted text to the supplied string, given a va_list. + * + * \sa ralloc_vasprintf + * \sa ralloc_strcat + * + * \p str will be updated to the new pointer unless allocation fails. + * + * \return True unless allocation failed. + */ +bool ralloc_vasprintf_append(char **str, const char *fmt, va_list args); +/// @} + +#ifdef __cplusplus +} /* end of extern "C" */ +#endif + +#endif diff --git a/src/glsl/s_expression.cpp b/src/glsl/s_expression.cpp new file mode 100644 index 0000000..34e503f --- /dev/null +++ b/src/glsl/s_expression.cpp @@ -0,0 +1,141 @@ +/* -*- c++ -*- */ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include "s_expression.h" + +s_symbol::s_symbol(const char *tmp, size_t n) +{ + this->str = ralloc_strndup (this, tmp, n); + assert(this->str != NULL); +} + +s_list::s_list() +{ +} + +unsigned +s_list::length() const +{ + unsigned i = 0; + foreach_iter(exec_list_iterator, it, this->subexpressions) { + i++; + } + return i; +} + +static s_expression * +read_atom(void *ctx, const char *& src) +{ + s_expression *expr = NULL; + + // Skip leading spaces. + src += strspn(src, " \v\t\r\n"); + + size_t n = strcspn(src, "( \v\t\r\n)"); + if (n == 0) + return NULL; // no atom + + // Check if the atom is a number. + char *float_end = NULL; + double f = glsl_strtod(src, &float_end); + if (float_end != src) { + char *int_end = NULL; + int i = strtol(src, &int_end, 10); + // If strtod matched more characters, it must have a decimal part + if (float_end > int_end) + expr = new(ctx) s_float(f); + else + expr = new(ctx) s_int(i); + } else { + // Not a number; return a symbol. + expr = new(ctx) s_symbol(src, n); + } + + src += n; + + return expr; +} + +s_expression * +s_expression::read_expression(void *ctx, const char *&src) +{ + assert(src != NULL); + + s_expression *atom = read_atom(ctx, src); + if (atom != NULL) + return atom; + + // Skip leading spaces. + src += strspn(src, " \v\t\r\n"); + if (src[0] == '(') { + ++src; + + s_list *list = new(ctx) s_list; + s_expression *expr; + + while ((expr = read_expression(ctx, src)) != NULL) { + list->subexpressions.push_tail(expr); + } + src += strspn(src, " \v\t\r\n"); + if (src[0] != ')') { + printf("Unclosed expression (check your parenthesis).\n"); + return NULL; + } + ++src; + return list; + } + return NULL; +} + +void s_int::print() +{ + printf("%d", this->val); +} + +void s_float::print() +{ + printf("%f", this->val); +} + +void s_symbol::print() +{ + printf("%s", this->str); +} + +void s_list::print() +{ + printf("("); + foreach_iter(exec_list_iterator, it, this->subexpressions) { + s_expression *expr = (s_expression*) it.get(); + expr->print(); + if (!expr->next->is_tail_sentinel()) + printf(" "); + } + printf(")"); +} + diff --git a/src/glsl/s_expression.h b/src/glsl/s_expression.h new file mode 100644 index 0000000..37f1d04 --- /dev/null +++ b/src/glsl/s_expression.h @@ -0,0 +1,143 @@ +/* -*- c++ -*- */ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#ifndef S_EXPRESSION_H +#define S_EXPRESSION_H + +#include "strtod.h" +#include "list.h" + +#define SX_AS_(t,x) ((x) && ((s_expression*) x)->is_##t()) ? ((s_##t*) (x)) \ + : NULL +#define SX_AS_LIST(x) SX_AS_(list, x) +#define SX_AS_SYMBOL(x) SX_AS_(symbol, x) +#define SX_AS_NUMBER(x) SX_AS_(number, x) +#define SX_AS_INT(x) SX_AS_(int, x) + +/* For our purposes, S-Expressions are: + * - + * - + * - symbol + * - (expr1 expr2 ... exprN) where exprN is an S-Expression + * + * Unlike LISP/Scheme, we do not support (foo . bar) pairs. + */ +class s_expression : public exec_node +{ +public: + /** + * Read an S-Expression from the given string. + * Advances the supplied pointer to just after the expression read. + * + * Any allocation will be performed with 'ctx' as the ralloc owner. + */ + static s_expression *read_expression(void *ctx, const char *&src); + + /** + * Print out an S-Expression. Useful for debugging. + */ + virtual void print() = 0; + + virtual bool is_list() const { return false; } + virtual bool is_symbol() const { return false; } + virtual bool is_number() const { return false; } + virtual bool is_int() const { return false; } + +protected: + s_expression() { } +}; + +/* Atoms */ + +class s_number : public s_expression +{ +public: + bool is_number() const { return true; } + + virtual float fvalue() = 0; + +protected: + s_number() { } +}; + +class s_int : public s_number +{ +public: + s_int(int x) : val(x) { } + + bool is_int() const { return true; } + + float fvalue() { return float(this->val); } + int value() { return this->val; } + + void print(); + +private: + int val; +}; + +class s_float : public s_number +{ +public: + s_float(float x) : val(x) { } + + float fvalue() { return this->val; } + + void print(); + +private: + float val; +}; + +class s_symbol : public s_expression +{ +public: + s_symbol(const char *, size_t); + + bool is_symbol() const { return true; } + + const char *value() { return this->str; } + + void print(); + +private: + char *str; +}; + +/* Lists of expressions: (expr1 ... exprN) */ +class s_list : public s_expression +{ +public: + s_list(); + + virtual bool is_list() const { return true; } + unsigned length() const; + + void print(); + + exec_list subexpressions; +}; + +#endif /* S_EXPRESSION_H */ diff --git a/src/glsl/strtod.c b/src/glsl/strtod.c new file mode 100644 index 0000000..ff34591 --- /dev/null +++ b/src/glsl/strtod.c @@ -0,0 +1,56 @@ +/* + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#include + +#ifdef _GNU_SOURCE +#include +#ifdef __APPLE__ +#include +#endif +#endif + +#include "strtod.h" + + + +/** + * Wrapper around strtod which uses the "C" locale so the decimal + * point is always '.' + */ +double +glsl_strtod(const char *s, char **end) +{ +#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) + static locale_t loc = NULL; + if (!loc) { + loc = newlocale(LC_CTYPE_MASK, "C", NULL); + } + return strtod_l(s, end, loc); +#else + return strtod(s, end); +#endif +} diff --git a/src/glsl/strtod.h b/src/glsl/strtod.h new file mode 100644 index 0000000..0cf6409 --- /dev/null +++ b/src/glsl/strtod.h @@ -0,0 +1,43 @@ +/* + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#ifndef STRTOD_H +#define STRTOD_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern double +glsl_strtod(const char *s, char **end); + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/src/glu/Makefile b/src/glu/Makefile new file mode 100644 index 0000000..b268265 --- /dev/null +++ b/src/glu/Makefile @@ -0,0 +1,40 @@ +# src/glu/Makefile + +TOP = ../.. + +include $(TOP)/configs/current + + +SUBDIRS = $(GLU_DIRS) + + +default: $(TOP)/configs/current + @for dir in $(SUBDIRS) ; do \ + (cd $$dir && $(MAKE)) || exit 1 ; \ + done + +# GLU pkg-config file +pcedit = sed \ + -e 's,@INSTALL_DIR@,$(INSTALL_DIR),' \ + -e 's,@INSTALL_LIB_DIR@,$(INSTALL_LIB_DIR),' \ + -e 's,@INSTALL_INC_DIR@,$(INSTALL_INC_DIR),' \ + -e 's,@VERSION@,$(MESA_MAJOR).$(MESA_MINOR).$(MESA_TINY),' \ + -e 's,@GLU_PC_REQ@,$(GLU_PC_REQ),' \ + -e 's,@GLU_PC_REQ_PRIV@,$(GLU_PC_REQ_PRIV),' \ + -e 's,@GLU_PC_LIB_PRIV@,$(GLU_PC_LIB_PRIV),' \ + -e 's,@GLU_PC_CFLAGS@,$(GLU_PC_CFLAGS),' \ + -e 's,@GLU_LIB@,$(GLU_LIB),' +glu.pc: glu.pc.in + $(pcedit) $< > $@ + +install: glu.pc + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR) + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig + $(MINSTALL) $(TOP)/$(LIB_DIR)/$(GLU_LIB_GLOB) $(DESTDIR)$(INSTALL_LIB_DIR) + $(INSTALL) -m 644 glu.pc $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig + +clean: + -@for dir in $(SUBDIRS) ; do \ + (cd $$dir && $(MAKE) clean) ; \ + done + -rm -f *.pc diff --git a/src/glu/glu.pc.in b/src/glu/glu.pc.in new file mode 100644 index 0000000..f7d9109 --- /dev/null +++ b/src/glu/glu.pc.in @@ -0,0 +1,13 @@ +prefix=@INSTALL_DIR@ +exec_prefix=${prefix} +libdir=@INSTALL_LIB_DIR@ +includedir=@INSTALL_INC_DIR@ + +Name: glu +Description: Mesa OpenGL Utility library +Requires: @GLU_PC_REQ@ +Requires.private: @GLU_PC_REQ_PRIV@ +Version: @VERSION@ +Libs: -L${libdir} -l@GLU_LIB@ +Libs.private: @GLU_PC_LIB_PRIV@ +Cflags: -I${includedir} @GLU_PC_CFLAGS@ diff --git a/src/glu/sgi/Makefile b/src/glu/sgi/Makefile new file mode 100644 index 0000000..c8b29ed --- /dev/null +++ b/src/glu/sgi/Makefile @@ -0,0 +1,149 @@ +# src/glu/sgi/Makefile + +.SUFFIXES : .cc + +TOP = ../../.. + +include $(TOP)/configs/current + +GLU_MAJOR = 1 +GLU_MINOR = 3 +GLU_TINY = 0$(MESA_MAJOR)$(MESA_MINOR)0$(MESA_TINY) + +INCDIRS = -I$(TOP)/include -Iinclude -Iinternals -Ilibnurbs/internals -Ilibnurbs/interface -Ilibnurbs/nurbtess + +C_SOURCES = \ + libutil/error.c \ + libutil/glue.c \ + libutil/mipmap.c \ + libutil/project.c \ + libutil/quad.c \ + libutil/registry.c \ + libtess/dict.c \ + libtess/geom.c \ + libtess/memalloc.c \ + libtess/mesh.c \ + libtess/normal.c \ + libtess/priorityq.c \ + libtess/render.c \ + libtess/sweep.c \ + libtess/tess.c \ + libtess/tessmono.c + +CC_SOURCES = \ + libnurbs/interface/bezierEval.cc \ + libnurbs/interface/bezierPatch.cc \ + libnurbs/interface/bezierPatchMesh.cc \ + libnurbs/interface/glcurveval.cc \ + libnurbs/interface/glinterface.cc \ + libnurbs/interface/glrenderer.cc \ + libnurbs/interface/glsurfeval.cc \ + libnurbs/interface/incurveeval.cc \ + libnurbs/interface/insurfeval.cc \ + libnurbs/internals/arc.cc \ + libnurbs/internals/arcsorter.cc \ + libnurbs/internals/arctess.cc \ + libnurbs/internals/backend.cc \ + libnurbs/internals/basiccrveval.cc \ + libnurbs/internals/basicsurfeval.cc \ + libnurbs/internals/bin.cc \ + libnurbs/internals/bufpool.cc \ + libnurbs/internals/cachingeval.cc \ + libnurbs/internals/ccw.cc \ + libnurbs/internals/coveandtiler.cc \ + libnurbs/internals/curve.cc \ + libnurbs/internals/curvelist.cc \ + libnurbs/internals/curvesub.cc \ + libnurbs/internals/dataTransform.cc \ + libnurbs/internals/displaylist.cc \ + libnurbs/internals/flist.cc \ + libnurbs/internals/flistsorter.cc \ + libnurbs/internals/hull.cc \ + libnurbs/internals/intersect.cc \ + libnurbs/internals/knotvector.cc \ + libnurbs/internals/mapdesc.cc \ + libnurbs/internals/mapdescv.cc \ + libnurbs/internals/maplist.cc \ + libnurbs/internals/mesher.cc \ + libnurbs/internals/monoTriangulationBackend.cc \ + libnurbs/internals/monotonizer.cc \ + libnurbs/internals/mycode.cc \ + libnurbs/internals/nurbsinterfac.cc \ + libnurbs/internals/nurbstess.cc \ + libnurbs/internals/patch.cc \ + libnurbs/internals/patchlist.cc \ + libnurbs/internals/quilt.cc \ + libnurbs/internals/reader.cc \ + libnurbs/internals/renderhints.cc \ + libnurbs/internals/slicer.cc \ + libnurbs/internals/sorter.cc \ + libnurbs/internals/splitarcs.cc \ + libnurbs/internals/subdivider.cc \ + libnurbs/internals/tobezier.cc \ + libnurbs/internals/trimline.cc \ + libnurbs/internals/trimregion.cc \ + libnurbs/internals/trimvertpool.cc \ + libnurbs/internals/uarray.cc \ + libnurbs/internals/varray.cc \ + libnurbs/nurbtess/directedLine.cc \ + libnurbs/nurbtess/gridWrap.cc \ + libnurbs/nurbtess/monoChain.cc \ + libnurbs/nurbtess/monoPolyPart.cc \ + libnurbs/nurbtess/monoTriangulation.cc \ + libnurbs/nurbtess/partitionX.cc \ + libnurbs/nurbtess/partitionY.cc \ + libnurbs/nurbtess/polyDBG.cc \ + libnurbs/nurbtess/polyUtil.cc \ + libnurbs/nurbtess/primitiveStream.cc \ + libnurbs/nurbtess/quicksort.cc \ + libnurbs/nurbtess/rectBlock.cc \ + libnurbs/nurbtess/sampleComp.cc \ + libnurbs/nurbtess/sampleCompBot.cc \ + libnurbs/nurbtess/sampleCompRight.cc \ + libnurbs/nurbtess/sampleCompTop.cc \ + libnurbs/nurbtess/sampleMonoPoly.cc \ + libnurbs/nurbtess/sampledLine.cc \ + libnurbs/nurbtess/searchTree.cc + +SOURCES = $(C_SOURCES) $(CC_SOURCES) + +C_OBJECTS = $(C_SOURCES:.c=.o) +CC_OBJECTS = $(CC_SOURCES:.cc=.o) +OBJECTS = $(C_OBJECTS) $(CC_OBJECTS) + + +##### RULES ##### + +.c.o: + $(CC) -c $(INCDIRS) $(CFLAGS) -DNDEBUG -DLIBRARYBUILD $< -o $@ + +.cc.o: + $(CXX) -c $(INCDIRS) $(CXXFLAGS) -DNDEBUG -DLIBRARYBUILD $< -o $@ + + +##### TARGETS ##### + +default: + @if [ "${CONFIG_NAME}" = "beos" ] ; then \ + echo "$(GLU_LIB_NAME) not build under BeOS, but integrated into ${GL_LIB_NAME}." ; \ + exit 0 ; \ + else \ + $(MAKE) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) || exit 1 ; \ + fi + +$(TOP)/$(LIB_DIR): + -mkdir $(TOP)/$(LIB_DIR) + +# Make the library: +$(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME): $(OBJECTS) + $(MKLIB) -o $(GLU_LIB) -linker '$(CXX)' -ldflags '$(LDFLAGS)' \ + -major $(GLU_MAJOR) -minor $(GLU_MINOR) -patch $(GLU_TINY) \ + -cplusplus $(MKLIB_OPTIONS) -install $(TOP)/$(LIB_DIR) \ + -exports glu.exports -id $(INSTALL_LIB_DIR)/lib$(GLU_LIB).$(GLU_MAJOR).dylib \ + $(GLU_LIB_DEPS) $(OBJECTS) + + +clean: + -rm -f *.o */*.o */*/*.o + -rm -f *.lo */*.lo */*/*.lo + -rm -f *.la */*.la */*/*.la diff --git a/src/glu/sgi/Makefile.mgw b/src/glu/sgi/Makefile.mgw new file mode 100644 index 0000000..d00d97a --- /dev/null +++ b/src/glu/sgi/Makefile.mgw @@ -0,0 +1,230 @@ +# Mesa 3-D graphics library +# Version: 5.1 +# +# Copyright (C) 1999-2003 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. + +# MinGW core makefile v1.4 for Mesa +# +# Copyright (C) 2002 - Daniel Borca +# Email : dborca@users.sourceforge.net +# Web : http://www.geocities.com/dborca + +# MinGW core-glu makefile updated for Mesa 7.0 +# +# Updated : by Heromyth, on 2007-7-21 +# Email : zxpmyth@yahoo.com.cn +# Bugs : 1) All the default settings work fine. But the setting X86=1 can't work. +# The others havn't been tested yet. +# 2) The generated DLLs are *not* compatible with the ones built +# with the other compilers like VC8, especially for GLUT. +# 3) Although more tests are needed, it can be used individually! + +# +# Available options: +# +# Environment variables: +# CFLAGS +# +# GLIDE path to Glide3 SDK; used with FX. +# default = $(TOP)/glide3 +# FX=1 build for 3dfx Glide3. Note that this disables +# compilation of most WMesa code and requires fxMesa. +# As a consequence, you'll need the Win32 Glide3 +# library to build any application. +# default = no +# ICD=1 build the installable client driver interface +# (windows opengl driver interface) +# default = no +# X86=1 optimize for x86 (if possible, use MMX, SSE, 3DNow). +# default = no +# +# Targets: +# all: build GL +# clean: remove object files +# + + + +.PHONY: all clean +.INTERMEDIATE: x86/gen_matypes.exe +.SUFFIXES: .rc .res + +# Set this to the prefix of your build tools, i.e. mingw32- +TOOLS_PREFIX = mingw32- + +TOP = ../../.. +LIBDIR = $(TOP)/lib + +LIB_NAME = glu32 +DLL_EXT = .dll +IMP_EXT = .a +LIB_PRE = lib +STRIP = -s + +AR = ar +ARFLAGS = crus +DLLTOOL = dlltool + +GLU_DLL = $(LIB_NAME)$(DLL_EXT) +GLU_IMP = $(LIB_PRE)$(LIB_NAME)$(IMP_EXT) +GLU_DEF = $(LIB_NAME).def + +LDLIBS = -L$(LIBDIR) -lopengl32 +LDFLAGS = $(STRIP) -shared -fPIC -Wl,--kill-at + +CFLAGS += -DBUILD_GLU32 -D_DLL + + +CC = $(TOOLS_PREFIX)gcc +CFLAGS += -DNDEBUG -DLIBRARYBUILD -I$(TOP)/include -Iinclude +CXX = $(TOOLS_PREFIX)g++ +CXXFLAGS = $(CFLAGS) -Ilibnurbs/internals -Ilibnurbs/interface -Ilibnurbs/nurbtess + +AR = ar +ARFLAGS = crus + +UNLINK = del $(subst /,\,$(1)) +ifneq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),) +UNLINK = $(RM) $(1) +endif +ifneq ($(wildcard $(addsuffix /rm,$(subst :, ,$(PATH)))),) +UNLINK = $(RM) $(1) +endif + +C_SOURCES = \ + libutil/error.c \ + libutil/glue.c \ + libutil/mipmap.c \ + libutil/project.c \ + libutil/quad.c \ + libutil/registry.c \ + libtess/dict.c \ + libtess/geom.c \ + libtess/memalloc.c \ + libtess/mesh.c \ + libtess/normal.c \ + libtess/priorityq.c \ + libtess/render.c \ + libtess/sweep.c \ + libtess/tess.c \ + libtess/tessmono.c + +CC_SOURCES = \ + libnurbs/interface/bezierEval.cc \ + libnurbs/interface/bezierPatch.cc \ + libnurbs/interface/bezierPatchMesh.cc \ + libnurbs/interface/glcurveval.cc \ + libnurbs/interface/glinterface.cc \ + libnurbs/interface/glrenderer.cc \ + libnurbs/interface/glsurfeval.cc \ + libnurbs/interface/incurveeval.cc \ + libnurbs/interface/insurfeval.cc \ + libnurbs/internals/arc.cc \ + libnurbs/internals/arcsorter.cc \ + libnurbs/internals/arctess.cc \ + libnurbs/internals/backend.cc \ + libnurbs/internals/basiccrveval.cc \ + libnurbs/internals/basicsurfeval.cc \ + libnurbs/internals/bin.cc \ + libnurbs/internals/bufpool.cc \ + libnurbs/internals/cachingeval.cc \ + libnurbs/internals/ccw.cc \ + libnurbs/internals/coveandtiler.cc \ + libnurbs/internals/curve.cc \ + libnurbs/internals/curvelist.cc \ + libnurbs/internals/curvesub.cc \ + libnurbs/internals/dataTransform.cc \ + libnurbs/internals/displaylist.cc \ + libnurbs/internals/flist.cc \ + libnurbs/internals/flistsorter.cc \ + libnurbs/internals/hull.cc \ + libnurbs/internals/intersect.cc \ + libnurbs/internals/knotvector.cc \ + libnurbs/internals/mapdesc.cc \ + libnurbs/internals/mapdescv.cc \ + libnurbs/internals/maplist.cc \ + libnurbs/internals/mesher.cc \ + libnurbs/internals/monoTriangulationBackend.cc \ + libnurbs/internals/monotonizer.cc \ + libnurbs/internals/mycode.cc \ + libnurbs/internals/nurbsinterfac.cc \ + libnurbs/internals/nurbstess.cc \ + libnurbs/internals/patch.cc \ + libnurbs/internals/patchlist.cc \ + libnurbs/internals/quilt.cc \ + libnurbs/internals/reader.cc \ + libnurbs/internals/renderhints.cc \ + libnurbs/internals/slicer.cc \ + libnurbs/internals/sorter.cc \ + libnurbs/internals/splitarcs.cc \ + libnurbs/internals/subdivider.cc \ + libnurbs/internals/tobezier.cc \ + libnurbs/internals/trimline.cc \ + libnurbs/internals/trimregion.cc \ + libnurbs/internals/trimvertpool.cc \ + libnurbs/internals/uarray.cc \ + libnurbs/internals/varray.cc \ + libnurbs/nurbtess/directedLine.cc \ + libnurbs/nurbtess/gridWrap.cc \ + libnurbs/nurbtess/monoChain.cc \ + libnurbs/nurbtess/monoPolyPart.cc \ + libnurbs/nurbtess/monoTriangulation.cc \ + libnurbs/nurbtess/partitionX.cc \ + libnurbs/nurbtess/partitionY.cc \ + libnurbs/nurbtess/polyDBG.cc \ + libnurbs/nurbtess/polyUtil.cc \ + libnurbs/nurbtess/primitiveStream.cc \ + libnurbs/nurbtess/quicksort.cc \ + libnurbs/nurbtess/rectBlock.cc \ + libnurbs/nurbtess/sampleComp.cc \ + libnurbs/nurbtess/sampleCompBot.cc \ + libnurbs/nurbtess/sampleCompRight.cc \ + libnurbs/nurbtess/sampleCompTop.cc \ + libnurbs/nurbtess/sampleMonoPoly.cc \ + libnurbs/nurbtess/sampledLine.cc \ + libnurbs/nurbtess/searchTree.cc + +SOURCES = $(C_SOURCES) $(CC_SOURCES) + +OBJECTS = $(addsuffix .o,$(basename $(SOURCES))) + +.c.o: + $(CC) -o $@ $(CFLAGS) -c $< +.cc.o: + $(CXX) -o $@ $(CXXFLAGS) -c $< + + +all: $(LIBDIR) $(LIBDIR)/$(GLU_DLL) $(LIBDIR)/$(GLU_IMP) + +$(LIBDIR): + mkdir -p $(LIBDIR) + +$(LIBDIR)/$(GLU_DLL) $(LIBDIR)/$(GLU_IMP): $(OBJECTS) + $(CXX) $(LDFLAGS) -o $(LIBDIR)/$(GLU_DLL) $^ $(LDLIBS) + $(DLLTOOL) --as=as --dllname $(LIB_NAME) --output-def $(LIBDIR)/$(GLU_DEF) $^ + $(DLLTOOL) --as=as -k --dllname $(LIB_NAME) --output-lib $(LIBDIR)/$(GLU_IMP) --def $(LIBDIR)/$(GLU_DEF) + + +clean: + -$(call UNLINK,libutil/*.o) + -$(call UNLINK,libtess/*.o) + -$(call UNLINK,libnurbs/interface/*.o) + -$(call UNLINK,libnurbs/internals/*.o) + -$(call UNLINK,libnurbs/nurbtess/*.o) diff --git a/src/glu/sgi/Makefile.win b/src/glu/sgi/Makefile.win new file mode 100644 index 0000000..9321732 --- /dev/null +++ b/src/glu/sgi/Makefile.win @@ -0,0 +1,149 @@ +# Makefile for Win32 + +!include + +.SUFFIXES : .cc + +TOP = .. + +GLU_SRCS_CC = \ + libnurbs\interface\bezierEval.cc \ + libnurbs\interface\bezierPatch.cc \ + libnurbs\interface\bezierPatchMesh.cc \ + libnurbs\interface\glcurveval.cc \ + libnurbs\interface\glinterface.cc \ + libnurbs\interface\glrenderer.cc \ + libnurbs\interface\glsurfeval.cc \ + libnurbs\interface\incurveeval.cc \ + libnurbs\interface\insurfeval.cc \ + libnurbs\internals\arc.cc \ + libnurbs\internals\arcsorter.cc \ + libnurbs\internals\arctess.cc \ + libnurbs\internals\backend.cc \ + libnurbs\internals\basiccrveval.cc \ + libnurbs\internals\basicsurfeval.cc \ + libnurbs\internals\bin.cc \ + libnurbs\internals\bufpool.cc \ + libnurbs\internals\cachingeval.cc \ + libnurbs\internals\ccw.cc \ + libnurbs\internals\coveandtiler.cc \ + libnurbs\internals\curve.cc \ + libnurbs\internals\curvelist.cc \ + libnurbs\internals\curvesub.cc \ + libnurbs\internals\dataTransform.cc \ + libnurbs\internals\displaylist.cc \ + libnurbs\internals\flist.cc \ + libnurbs\internals\flistsorter.cc \ + libnurbs\internals\hull.cc \ + libnurbs\internals\intersect.cc \ + libnurbs\internals\knotvector.cc \ + libnurbs\internals\mapdesc.cc \ + libnurbs\internals\mapdescv.cc \ + libnurbs\internals\maplist.cc \ + libnurbs\internals\mesher.cc \ + libnurbs\internals\monoTriangulationBackend.cc \ + libnurbs\internals\monotonizer.cc \ + libnurbs\internals\mycode.cc \ + libnurbs\internals\nurbsinterfac.cc \ + libnurbs\internals\nurbstess.cc \ + libnurbs\internals\patch.cc \ + libnurbs\internals\patchlist.cc \ + libnurbs\internals\quilt.cc \ + libnurbs\internals\reader.cc \ + libnurbs\internals\renderhints.cc \ + libnurbs\internals\slicer.cc \ + libnurbs\internals\sorter.cc \ + libnurbs\internals\splitarcs.cc \ + libnurbs\internals\subdivider.cc \ + libnurbs\internals\tobezier.cc \ + libnurbs\internals\trimline.cc \ + libnurbs\internals\trimregion.cc \ + libnurbs\internals\trimvertpool.cc \ + libnurbs\internals\uarray.cc \ + libnurbs\internals\varray.cc \ + libnurbs\nurbtess\directedLine.cc \ + libnurbs\nurbtess\gridWrap.cc \ + libnurbs\nurbtess\monoChain.cc \ + libnurbs\nurbtess\monoPolyPart.cc \ + libnurbs\nurbtess\monoTriangulation.cc \ + libnurbs\nurbtess\partitionX.cc \ + libnurbs\nurbtess\partitionY.cc \ + libnurbs\nurbtess\polyDBG.cc \ + libnurbs\nurbtess\polyUtil.cc \ + libnurbs\nurbtess\primitiveStream.cc \ + libnurbs\nurbtess\quicksort.cc \ + libnurbs\nurbtess\rectBlock.cc \ + libnurbs\nurbtess\sampleComp.cc \ + libnurbs\nurbtess\sampleCompBot.cc \ + libnurbs\nurbtess\sampleCompRight.cc \ + libnurbs\nurbtess\sampleCompTop.cc \ + libnurbs\nurbtess\sampleMonoPoly.cc \ + libnurbs\nurbtess\sampledLine.cc \ + libnurbs\nurbtess\searchTree.cc + +GLU_SRCS = \ + libtess\dict.c \ + libtess\geom.c \ + libtess\memalloc.c \ + libtess\mesh.c \ + libtess\normal.c \ + libtess\priorityq.c \ + libtess\render.c \ + libtess\sweep.c \ + libtess\tess.c \ + libtess\tessmono.c \ + libutil\error.c \ + libutil\glue.c \ + libutil\mipmap.c \ + libutil\project.c \ + libutil\quad.c \ + libutil\registry.c + +SRCS = $(GLU_SRCS) + +all : gludll + +!include "$(TOP)/mesawin32.mak" + +gludll : $(GLUDLL) + +CFLAGS = $(cvarsdll) $(CFLAGS) -D_OPENGL32_ -Iinclude -DBUILD_GL32 -DLIBRARYBUILD +LFLAGS = $(dlllflags) $(lcommon) $(LFLAGS) + +LIBS = ../lib/$(MESALIB) winmm.lib $(guilibsdll) + +OBJS = $(GLU_SRCS_CC:.cc=.obj) $(GLU_SRCS:.c=.obj) +NURBSINC = -Ilibnurbs\interface -Ilibnurbs\internals -Ilibnurbs\nurbtess +CFLAGS = $(CFLAGS) $(NURBSINC) + +$(GLUDLL): $(OBJS) glu.def + $(link) $(LFLAGS) -out:$(GLUDLL) -def:glu.def $(OBJS) $(LIBS) + @echo "copying Mesa GLU dynamic link library to library directory..." + -copy $(GLUDLL) $(TOP)\lib + @echo "copying Mesa GLU import library to library directory..." + -copy $(GLULIB) $(TOP)\lib + +install : $(GLUDLL) $(GLULIB) + @echo "copying Mesa GLU dynamic link library to system directory..." + -copy $(GLUDLL) $(DLLINSTALL) + @echo "copying Mesa GLU header files to include directory..." + -copy ..\..\include\GL\glu.h $(INCLUDEINSTALL) + @echo "copying Mesa GLU import library to system library directory..." + -copy $(GLULIB) $(LIBINSTALL) + +clean :: + @del /f libtess\*.obj libutil\*.obj + @del /f libnurbs\interface\*.obj libnurbs\internals\*.obj + @del /f libnurbs\nurbtess\*.obj + +# override default inference rule with one that writes the object to +# the same subdir as the c file. + +.c.obj : + $(cc) $(CFLAGS) -I. $< /Fo$*.obj + +# /TP is needed for C++ files because MS compiler +# does not recognize .cc as a C++ file. + +.cc.obj : + $(cc) $(CFLAGS) -I. $< /TP /Fo$*.obj diff --git a/src/glu/sgi/dummy.cc b/src/glu/sgi/dummy.cc new file mode 100644 index 0000000..bd905a2 --- /dev/null +++ b/src/glu/sgi/dummy.cc @@ -0,0 +1,4 @@ +/* + * This file contains nothing. It's just there so there's at least a single + * source file for libGLU.la in this directory. + */ diff --git a/src/glu/sgi/glu.def b/src/glu/sgi/glu.def new file mode 100644 index 0000000..0c8b021 --- /dev/null +++ b/src/glu/sgi/glu.def @@ -0,0 +1,88 @@ +;DESCRIPTION 'Mesa GLU (OpenGL work-alike) for Win32' +VERSION 5.1 +; +; Module definition file for GLU (GLU32.DLL) +; +; Note: The GLU functions use the STDCALL +; function calling convention. Microsoft's +; GLU32 uses this convention and so must the +; Mesa GLU32 so that the Mesa DLL can be used +; as a drop-in replacement. +; +; The linker exports STDCALL entry points with +; 'decorated' names; e.g., _glBegin@0, where the +; trailing number is the number of bytes of +; parameter data pushed onto the stack. The +; callee is responsible for popping this data +; off the stack, usually via a RETF n instruction. +; +; However, the Microsoft GLU32.DLL does not export +; the decorated names, even though the calling convention +; is STDCALL. So, this module definition file is +; needed to force the Mesa GLU32.DLL to export the +; symbols in the same manner as the Microsoft DLL. +; Were it not for this problem, this file would not +; be needed (for the glu* functions) since the entry +; points are compiled with dllexport declspec. +; + +EXPORTS + gluBeginCurve + gluBeginPolygon + gluBeginSurface + gluBeginTrim + gluBuild1DMipmapLevels + gluBuild1DMipmaps + gluBuild2DMipmapLevels + gluBuild2DMipmaps + gluBuild3DMipmapLevels + gluBuild3DMipmaps + gluCheckExtension + gluCylinder + gluDeleteNurbsRenderer + gluDeleteQuadric + gluDeleteTess + gluDisk + gluEndCurve + gluEndPolygon + gluEndSurface + gluEndTrim + gluErrorString + gluGetNurbsProperty + gluGetString + gluGetTessProperty + gluLoadSamplingMatrices + gluLookAt + gluNewNurbsRenderer + gluNewQuadric + gluNewTess + gluNextContour + gluNurbsCallback + gluNurbsCallbackData + gluNurbsCallbackDataEXT + gluNurbsCurve + gluNurbsProperty + gluNurbsSurface + gluOrtho2D + gluPartialDisk + gluPerspective + gluPickMatrix + gluProject + gluPwlCurve + gluQuadricCallback + gluQuadricDrawStyle + gluQuadricNormals + gluQuadricOrientation + gluQuadricTexture + gluScaleImage + gluSphere + gluTessBeginContour + gluTessBeginPolygon + gluTessCallback + gluTessEndContour + gluTessEndPolygon + gluTessNormal + gluTessProperty + gluTessVertex + gluUnProject + gluUnProject4 diff --git a/src/glu/sgi/glu.exports b/src/glu/sgi/glu.exports new file mode 100644 index 0000000..aeb7272 --- /dev/null +++ b/src/glu/sgi/glu.exports @@ -0,0 +1,118 @@ + gluBeginCurve + gluBeginPolygon + gluBeginSurface + gluBeginTrim + gluBuild1DMipmapLevels + gluBuild1DMipmaps + gluBuild2DMipmapLevels + gluBuild2DMipmaps + gluBuild3DMipmapLevels + gluBuild3DMipmaps + gluCheckExtension + gluCylinder + gluDeleteNurbsRenderer + gluDeleteQuadric + gluDeleteTess + gluDisk + gluEndCurve + gluEndPolygon + gluEndSurface + gluEndTrim + gluErrorString + gluGetNurbsProperty + gluGetString + gluGetTessProperty + gluLoadSamplingMatrices + gluLookAt + gluNewNurbsRenderer + gluNewQuadric + gluNewTess + gluNextContour + gluNurbsCallback + gluNurbsCallbackData + gluNurbsCallbackDataEXT + gluNurbsCurve + gluNurbsProperty + gluNurbsSurface + gluOrtho2D + gluPartialDisk + gluPerspective + gluPickMatrix + gluProject + gluPwlCurve + gluQuadricCallback + gluQuadricDrawStyle + gluQuadricNormals + gluQuadricOrientation + gluQuadricTexture + gluScaleImage + gluSphere + gluTessBeginContour + gluTessBeginPolygon + gluTessCallback + gluTessEndContour + gluTessEndPolygon + gluTessNormal + gluTessProperty + gluTessVertex + gluUnProject + gluUnProject4 + mgluBeginCurve + mgluBeginPolygon + mgluBeginSurface + mgluBeginTrim + mgluBuild1DMipmapLevels + mgluBuild1DMipmaps + mgluBuild2DMipmapLevels + mgluBuild2DMipmaps + mgluBuild3DMipmapLevels + mgluBuild3DMipmaps + mgluCheckExtension + mgluCylinder + mgluDeleteNurbsRenderer + mgluDeleteQuadric + mgluDeleteTess + mgluDisk + mgluEndCurve + mgluEndPolygon + mgluEndSurface + mgluEndTrim + mgluErrorString + mgluGetNurbsProperty + mgluGetString + mgluGetTessProperty + mgluLoadSamplingMatrices + mgluLookAt + mgluNewNurbsRenderer + mgluNewQuadric + mgluNewTess + mgluNextContour + mgluNurbsCallback + mgluNurbsCallbackData + mgluNurbsCallbackDataEXT + mgluNurbsCurve + mgluNurbsProperty + mgluNurbsSurface + mgluOrtho2D + mgluPartialDisk + mgluPerspective + mgluPickMatrix + mgluProject + mgluPwlCurve + mgluQuadricCallback + mgluQuadricDrawStyle + mgluQuadricNormals + mgluQuadricOrientation + mgluQuadricTexture + mgluScaleImage + mgluSphere + mgluTessBeginContour + mgluTessBeginPolygon + mgluTessCallback + mgluTessEndContour + mgluTessEndPolygon + mgluTessNormal + mgluTessProperty + mgluTessVertex + mgluUnProject + mgluUnProject4 diff --git a/src/glu/sgi/glu.exports.darwin b/src/glu/sgi/glu.exports.darwin new file mode 100644 index 0000000..4f56e36 --- /dev/null +++ b/src/glu/sgi/glu.exports.darwin @@ -0,0 +1,59 @@ +_*gluBeginCurve +_*gluBeginPolygon +_*gluBeginSurface +_*gluBeginTrim +_*gluBuild1DMipmapLevels +_*gluBuild1DMipmaps +_*gluBuild2DMipmapLevels +_*gluBuild2DMipmaps +_*gluBuild3DMipmapLevels +_*gluBuild3DMipmaps +_*gluCheckExtension +_*gluCylinder +_*gluDeleteNurbsRenderer +_*gluDeleteQuadric +_*gluDeleteTess +_*gluDisk +_*gluEndCurve +_*gluEndPolygon +_*gluEndSurface +_*gluEndTrim +_*gluErrorString +_*gluGetNurbsProperty +_*gluGetString +_*gluGetTessProperty +_*gluLoadSamplingMatrices +_*gluLookAt +_*gluNewNurbsRenderer +_*gluNewQuadric +_*gluNewTess +_*gluNextContour +_*gluNurbsCallback +_*gluNurbsCallbackData +_*gluNurbsCallbackDataEXT +_*gluNurbsCurve +_*gluNurbsProperty +_*gluNurbsSurface +_*gluOrtho2D +_*gluPartialDisk +_*gluPerspective +_*gluPickMatrix +_*gluProject +_*gluPwlCurve +_*gluQuadricCallback +_*gluQuadricDrawStyle +_*gluQuadricNormals +_*gluQuadricOrientation +_*gluQuadricTexture +_*gluScaleImage +_*gluSphere +_*gluTessBeginContour +_*gluTessBeginPolygon +_*gluTessCallback +_*gluTessEndContour +_*gluTessEndPolygon +_*gluTessNormal +_*gluTessProperty +_*gluTessVertex +_*gluUnProject +_*gluUnProject4 diff --git a/src/glu/sgi/include/gluos.h b/src/glu/sgi/include/gluos.h new file mode 100644 index 0000000..8eaa7a1 --- /dev/null +++ b/src/glu/sgi/include/gluos.h @@ -0,0 +1,72 @@ +/* +** gluos.h - operating system dependencies for GLU +** +*/ +#ifdef __VMS +#ifdef __cplusplus +#pragma message disable nocordel +#pragma message disable codeunreachable +#pragma message disable codcauunr +#endif +#endif + +#ifdef __WATCOMC__ +/* Disable *lots* of warnings to get a clean build. I can't be bothered fixing the + * code at the moment, as it is pretty ugly. + */ +#pragma warning 7 10 +#pragma warning 13 10 +#pragma warning 14 10 +#pragma warning 367 10 +#pragma warning 379 10 +#pragma warning 726 10 +#pragma warning 836 10 +#endif + +#ifdef BUILD_FOR_SNAP + +#include +#include +#include + +#elif defined(_WIN32) + +#include /* For _MAX_PATH definition */ +#include +#include + +#define WIN32_LEAN_AND_MEAN +#define NOGDI +#define NOIME +#define NOMINMAX + +#define _WIN32_WINNT 0x0400 +#ifndef STRICT + #define STRICT 1 +#endif + +#include + +/* Disable warnings */ +#pragma warning(disable : 4101) +#pragma warning(disable : 4244) +#pragma warning(disable : 4761) + +#if defined(_MSC_VER) && _MSC_VER >= 1200 && _MSC_VER < 1300 +#pragma comment(linker, "/OPT:NOWIN98") +#endif + +#elif defined(__OS2__) + +#include +#include +#include +#define WINGDIAPI + +#else + +/* Disable Microsoft-specific keywords */ +#define GLAPIENTRY +#define WINGDIAPI + +#endif diff --git a/src/glu/sgi/libnurbs/interface/bezierEval.cc b/src/glu/sgi/libnurbs/interface/bezierEval.cc new file mode 100644 index 0000000..b414f53 --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/bezierEval.cc @@ -0,0 +1,260 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include +#include +#include +#include "bezierEval.h" + +#ifdef __WATCOMC__ +#pragma warning 14 10 +#endif + +#define TOLERANCE 0.0001 + +#ifndef MAX_ORDER +#define MAX_ORDER 16 +#endif + +#ifndef MAX_DIMENSION +#define MAX_DIMENSION 4 +#endif + +static void normalize(float vec[3]); +static void crossProduct(float x[3], float y[3], float ret[3]); +#if 0 // UNUSED +static void bezierCurveEvalfast(float u0, float u1, int order, float *ctlpoints, int stride, int dimension, float u, float retpoint[]); +#endif + +static float binomialCoefficients[8][8] = { + {1,0,0,0,0,0,0,0}, + {1,1,0,0,0,0,0,0}, + {1,2,1,0,0,0,0,0}, + {1,3,3,1,0,0,0,0}, + {1,4,6,4,1,0,0,0}, + {1,5,10,10,5,1,0,0}, + {1,6,15,20,15,6,1,0}, + {1,7,21,35,35,21,7,1} +}; + +void bezierCurveEval(float u0, float u1, int order, float *ctlpoints, int stride, int dimension, float u, float retpoint[]) +{ + float uprime = (u-u0)/(u1-u0); + float *ctlptr = ctlpoints; + float oneMinusX = 1.0f-uprime; + float XPower = 1.0f; + + int i,k; + for(k=0; k=1. + */ +void bezierCurveEvalfast(float u0, float u1, int order, float *ctlpoints, int stride, int dimension, float u, float retpoint[]) +{ + float uprime = (u-u0)/(u1-u0); + float buf[MAX_ORDER][MAX_ORDER][MAX_DIMENSION]; + float* ctlptr = ctlpoints; + int r, i,j; + for(i=0; i=1. + */ +void bezierCurveEvalDer(float u0, float u1, int order, float *ctlpoints, int stride, int dimension, float u, float retDer[]) +{ + int i,k; + float width = u1-u0; + float *ctlptr = ctlpoints; + + float buf[MAX_ORDER][MAX_DIMENSION]; + if(order == 1){ + for(k=0; k=3 && dimension <=4); + bezierSurfEvalDerGen(1,0, u0, u1, uorder, v0, v1, vorder, dimension, ctlpoints, ustride, vstride, u, v, partialU); + bezierSurfEvalDerGen(0,1, u0, u1, uorder, v0, v1, vorder, dimension, ctlpoints, ustride, vstride, u, v, partialV); + + if(dimension == 3){/*inhomogeneous*/ + crossProduct(partialU, partialV, retNormal); + + normalize(retNormal); + + return; + } + else { /*homogeneous*/ + float val[4]; /*the point coordinates (without derivative)*/ + float newPartialU[MAX_DIMENSION]; + float newPartialV[MAX_DIMENSION]; + int i; + bezierSurfEvalDerGen(0,0, u0, u1, uorder, v0, v1, vorder, dimension, ctlpoints, ustride, vstride, u, v, val); + + for(i=0; i<=2; i++){ + newPartialU[i] = partialU[i] * val[3] - val[i] * partialU[3]; + newPartialV[i] = partialV[i] * val[3] - val[i] * partialV[3]; + } + crossProduct(newPartialU, newPartialV, retNormal); + normalize(retNormal); + } +} + +/*if size is 0, then nothing is done*/ +static void normalize(float vec[3]) +{ + float size = (float)sqrt(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]); + + if(size < TOLERANCE) + { +#ifdef DEBUG + fprintf(stderr, "Warning: in oglBSpline.c normal is 0\n"); +#endif + return; + } + else { + vec[0] = vec[0]/size; + vec[1] = vec[1]/size; + vec[2] = vec[2]/size; + } +} + + +static void crossProduct(float x[3], float y[3], float ret[3]) +{ + ret[0] = x[1]*y[2] - y[1]*x[2]; + ret[1] = x[2]*y[0] - y[2]*x[0]; + ret[2] = x[0]*y[1] - y[0]*x[1]; + +} + diff --git a/src/glu/sgi/libnurbs/interface/bezierEval.h b/src/glu/sgi/libnurbs/interface/bezierEval.h new file mode 100644 index 0000000..93e8c69 --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/bezierEval.h @@ -0,0 +1,48 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _BEZIEREVAL_H +#define _BEZIEREVAL_H + +void bezierCurveEval(float u0, float u1, int order, float *ctlpoints, int stride, int dimension, float u, float retpoint[]); +void bezierCurveEvalDer(float u0, float u1, int order, float *ctlpoints, int stride, int dimension, float u, float retDer[]); +void bezierCurveEvalDerGen(int der, float u0, float u1, int order, float *ctlpoints, int stride, int dimension, float u, float retDer[]); + + +void bezierSurfEvalDerGen(int uder, int vder, float u0, float u1, int uorder, float v0, float v1, int vorder, int dimension, float *ctlpoints, int ustride, int vstride, float u, float v, float ret[]); + +void bezierSurfEval(float u0, float u1, int uorder, float v0, float v1, int vorder, int dimension, float *ctlpoints, int ustride, int vstride, float u, float v, float ret[]); + +void bezierSurfEvalNormal(float u0, float u1, int uorder, float v0, float v1, int vorder, int dimension, float *ctlpoints, int ustride, int vstride, float u, float v, float retNormal[]); + + +#endif diff --git a/src/glu/sgi/libnurbs/interface/bezierPatch.cc b/src/glu/sgi/libnurbs/interface/bezierPatch.cc new file mode 100644 index 0000000..dbab3a1 --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/bezierPatch.cc @@ -0,0 +1,206 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include "gluos.h" +#include +#include +#include +#include /*for drawing bzier patch*/ +#include "bezierPatch.h" +#include "bezierEval.h" + +/* + *allocate an instance of bezierPatch. The control points are unknown. But + *the space of this array is allocated with size of + * uorder*vorder*dimension + * + */ +bezierPatch* bezierPatchMake(float umin, float vmin, float umax, float vmax, int uorder, int vorder, int dimension) +{ + bezierPatch* ret = (bezierPatch*) malloc(sizeof(bezierPatch)); + assert(ret); + ret->umin = umin; + ret->vmin = vmin; + ret->umax = umax; + ret->vmax = vmax; + ret->uorder = uorder; + ret->vorder = vorder; + ret->dimension = dimension; + ret->ctlpoints = (float*) malloc(sizeof(float) * dimension * uorder * vorder); + assert(ret->ctlpoints); + + ret->next = NULL; + + return ret; +} + +bezierPatch* bezierPatchMake2(float umin, float vmin, float umax, float vmax, int uorder, int vorder, int dimension, int ustride, int vstride, float* ctlpoints) +{ + bezierPatch* ret = (bezierPatch*) malloc(sizeof(bezierPatch)); + assert(ret); + ret->umin = umin; + ret->vmin = vmin; + ret->umax = umax; + ret->vmax = vmax; + ret->uorder = uorder; + ret->vorder = vorder; + ret->dimension = dimension; + ret->ctlpoints = (float*) malloc(sizeof(float) * dimension * uorder * vorder); + assert(ret->ctlpoints); + + /*copy the control points there*/ + int the_ustride = vorder * dimension; + int the_vstride = dimension; + for(int i=0; ictlpoints[i * the_ustride + j*the_vstride+k] = ctlpoints[i*ustride+j*vstride+k]; + + ret->next = NULL; + + return ret; +} + +/* + *deallocate the space as allocated by Make + */ +void bezierPatchDelete(bezierPatch *b) +{ + free(b->ctlpoints); + free(b); +} + +/*delete the whole linked list + */ +void bezierPatchDeleteList(bezierPatch *b) +{ + bezierPatch *temp; + while (b != NULL) { + temp = b; + b = b->next; + bezierPatchDelete(temp); + } +} + +bezierPatch* bezierPatchInsert(bezierPatch *list, bezierPatch *b) +{ + b->next = list; + return b; +} + +/*print the data stored in this patch*/ +void bezierPatchPrint(bezierPatch *b) +{ + printf("bezierPatch:\n"); + printf("umin,umax=(%f,%f), (vmin, vmax)=(%f,%f)\n", b->umin, b->umax, b->vmin, b->vmax); + printf("uorder=%i, vorder=%i\n", b->uorder, b->vorder); + printf("idmension = %i\n", b->dimension); +} + +/*print the whole list*/ +void bezierPatchPrintList(bezierPatch *list) +{ + bezierPatch* temp; + for(temp=list; temp != NULL; temp = temp->next) + bezierPatchPrint(temp); +} + +void bezierPatchEval(bezierPatch *b, float u, float v, float ret[]) +{ + if( u >= b->umin && u<= b->umax + && v >= b->vmin && v<= b->vmax) + { + + bezierSurfEval(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension * b->vorder, b->dimension, u, v, ret); + + } + else if(b->next != NULL) + bezierPatchEval(b->next, u,v, ret); + else + bezierSurfEval(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension * b->vorder, b->dimension, u, v, ret); +} + +/*the returned normal is normlized + */ +void bezierPatchEvalNormal(bezierPatch *b, float u, float v, float ret[]) +{ + bezierSurfEvalNormal(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension * b->vorder, b->dimension, u, v, ret); + + if( u >= b->umin && u<= b->umax + && v >= b->vmin && v<= b->vmax) + { + bezierSurfEvalNormal(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension * b->vorder, b->dimension, u, v, ret); + } + else if(b->next != NULL) + bezierPatchEvalNormal(b->next, u,v, ret); + else + bezierSurfEvalNormal(b->umin, b->umax, b->uorder, b->vmin, b->vmax, b->vorder, b->dimension, b->ctlpoints, b->dimension * b->vorder, b->dimension, u, v, ret); + +} + +void bezierPatchDraw(bezierPatch *bpatch, int u_reso, int v_reso) +{ + if(bpatch->dimension == 3) + glMap2f(GL_MAP2_VERTEX_3, bpatch->umin, bpatch->umax, 3*bpatch->vorder, bpatch->uorder, bpatch->vmin, bpatch->vmax,3, bpatch->vorder, (GLfloat*) bpatch->ctlpoints); + else + glMap2f(GL_MAP2_VERTEX_4, bpatch->umin, bpatch->umax, 4*bpatch->vorder, bpatch->uorder, bpatch->vmin, bpatch->vmax,3, bpatch->vorder, (GLfloat*) bpatch->ctlpoints); + + glMapGrid2f(u_reso, bpatch->umin, bpatch->umax, + v_reso, bpatch->vmin, bpatch->vmax); + glEvalMesh2(GL_LINE, 0, u_reso, 0, v_reso); +} + +void bezierPatchListDraw(bezierPatch *list, int u_reso, int v_reso) +{ + bezierPatch *temp; +glEnable(GL_LIGHTING); +glEnable(GL_LIGHT0); +glEnable(GL_MAP2_VERTEX_3); +glEnable(GL_AUTO_NORMAL); +glEnable(GL_NORMALIZE); +glColor3f(1,0,0); +#ifdef DEBUG +printf("mapmap\n"); +#endif + + + for(temp = list; temp != NULL; temp = temp->next) + bezierPatchDraw(temp, u_reso, v_reso); +} + + + diff --git a/src/glu/sgi/libnurbs/interface/bezierPatch.h b/src/glu/sgi/libnurbs/interface/bezierPatch.h new file mode 100644 index 0000000..981183a --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/bezierPatch.h @@ -0,0 +1,104 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _BEZIERPATCH_H +#define _BEZIERPATCH_H + +typedef struct bezierPatch{ + float umin, vmin, umax, vmax; + int uorder; /*order= degree + 1*/ + int vorder; + + /* + *the control points are stored in a one dimensional array. + *the surface is defined as: + * s(u,v) = sum_{i,j} P(i,j) * B_i(u) * B_j(v). + *where P(i,j) are the control points, B_i(.) are Bezier + *basis functions. + *Each control point can have dimension 3 or 4: (x,y,z,w). + *The components of P(i,j) are stored in a one dimensional + *array: + * ctlpoints[] + *in the order of: + * P[0,0], P[0,1], ..., P[0,vorder-1], + * P[1,0], P[1,1], ..., P[1,vorder-1], + * ... + * P[uorder-1,0], P[uorder-1,1], ..., P[uorder-1,vorder-1]. + */ + int dimension; + float* ctlpoints; + + /* + *in case we have to manage multiple bezierPatches. + */ + struct bezierPatch *next; + +} bezierPatch; + +#ifdef __cplusplus +extern "C" { +#endif + +bezierPatch* bezierPatchMake(float umin, float vmin, float umax, float vmax, int urder, int vorder, int dimension); + +bezierPatch* bezierPatchMake2(float umin, float vmin, float umax, float vmax, int urder, int vorder, int dimension, int ustride, int vstride, float *ctlpoints); + + +bezierPatch* bezierPatchInsert(bezierPatch *list, bezierPatch *b); + +void bezierPatchDelete(bezierPatch *b); + +void bezierPatchDeleteList(bezierPatch *b); + +void bezierPatchPrint(bezierPatch *b); + +void bezierPatchPrintList(bezierPatch *list); + +void bezierPatchEval(bezierPatch *b, float u, float v, float ret[]); + +void bezierPatchEvalNormal(bezierPatch *b, float u, float v, float retNormal[]); + +void bezierPatchEval(bezierPatch *b, float u, float v, float ret[]); + +void bezierPatchEvalNormal(bezierPatch *b, float u, float v, float ret[]); + + +void bezierPatchDraw(bezierPatch *bpatch, int u_reso, int v_reso); + +void bezierPatchListDraw(bezierPatch *list, int u_reso, int v_reso); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/src/glu/sgi/libnurbs/interface/bezierPatchMesh.cc b/src/glu/sgi/libnurbs/interface/bezierPatchMesh.cc new file mode 100644 index 0000000..ac7ff84 --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/bezierPatchMesh.cc @@ -0,0 +1,610 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include "gluos.h" +#include +#include +#include +#include +#include "bezierEval.h" +#include "bezierPatchMesh.h" + +static int isDegenerate(float A[2], float B[2], float C[2]); + +void drawStrips(float *vertex_array, float *normal_array, int *length_array, GLenum *type_array, int num_strips) +{ + int i,j,k; + k=0; + /*k is the index of the first component of the current vertex*/ + for(i=0; inext) + { + bezierPatchMeshDelDeg(temp); + } +} + +void bezierPatchMeshListDelete(bezierPatchMesh *list) +{ + if(list == NULL) return; + bezierPatchMeshListDelete(list->next); + bezierPatchMeshDelete(list); +} + + + + +bezierPatchMesh* bezierPatchMeshListReverse(bezierPatchMesh* list) +{ + bezierPatchMesh* ret=NULL; + bezierPatchMesh* temp; + bezierPatchMesh* nextone; + for(temp = list; temp != NULL; temp = nextone) + { + nextone = temp->next; + ret=bezierPatchMeshListInsert(ret, temp); + } + return ret; +} + +/*maptype is either GL_MAP2_VERTEX_3 or GL_MAP2_VERTEX_4 + */ +bezierPatchMesh *bezierPatchMeshMake(int maptype, float umin, float umax, int ustride, int uorder, float vmin, float vmax, int vstride, int vorder, float *ctlpoints, int size_UVarray, int size_length_array) +{ + int i,j,k; + int dimension; + int the_ustride; + int the_vstride; + + if(maptype == GL_MAP2_VERTEX_3) dimension = 3; + else if (maptype==GL_MAP2_VERTEX_4) dimension = 4; + else { + fprintf(stderr, "error in inMap2f, maptype=%i is wrong, maptype,map is invalid\n", maptype); + return NULL; + } + + bezierPatchMesh *ret = (bezierPatchMesh*) malloc(sizeof(bezierPatchMesh)); + assert(ret); + + ret->bpatch_normal = NULL; + ret->bpatch_color = NULL; + ret->bpatch_texcoord = NULL; + ret->bpatch = bezierPatchMake(umin, vmin, umax, vmax, uorder, vorder, dimension); + + /*copy the control points there*/ + the_ustride = vorder * dimension; + the_vstride = dimension; + for(i=0; ibpatch->ctlpoints[i * the_ustride + j*the_vstride+k] = ctlpoints[i*ustride+j*vstride+k]; + + + ret->size_UVarray = size_UVarray; + ret->size_length_array = size_length_array; + ret->UVarray = (float*) malloc(sizeof(float) * size_UVarray); + assert(ret->UVarray); + ret->length_array = (int *)malloc(sizeof(int) * size_length_array); + assert(ret->length_array); + ret->type_array = (GLenum *)malloc(sizeof(GLenum) * size_length_array); + assert(ret->type_array); + + ret->index_UVarray = 0; + ret->index_length_array = 0; + + ret->vertex_array = NULL; + ret->normal_array = NULL; + ret->color_array = NULL; + ret->texcoord_array = NULL; + + ret->next = NULL; + return ret; +} + +bezierPatchMesh *bezierPatchMeshMake2(int size_UVarray, int size_length_array) +{ + bezierPatchMesh *ret = (bezierPatchMesh*) malloc(sizeof(bezierPatchMesh)); + assert(ret); + + ret->bpatch = NULL; + ret->bpatch_normal = NULL; + ret->bpatch_color = NULL; + ret->bpatch_texcoord = NULL; + + ret->size_UVarray = size_UVarray; + ret->size_length_array = size_length_array; + ret->UVarray = (float*) malloc(sizeof(float) * size_UVarray); + assert(ret->UVarray); + ret->length_array = (int *)malloc(sizeof(int) * size_length_array); + assert(ret->length_array); + ret->type_array = (GLenum *)malloc(sizeof(GLenum) * size_length_array); + assert(ret->type_array); + + ret->index_UVarray = 0; + ret->index_length_array = 0; + + ret->vertex_array = NULL; + ret->normal_array = NULL; + ret->color_array = NULL; + ret->texcoord_array = NULL; + + ret->next = NULL; + return ret; +} + +void bezierPatchMeshPutPatch(bezierPatchMesh *bpm, int maptype, float umin, float umax, int ustride, int uorder, float vmin, float vmax, int vstride, int vorder, float *ctlpoints) +{ + switch(maptype){ + case GL_MAP2_VERTEX_3: + bpm->bpatch = bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 3, ustride, vstride, ctlpoints); + break; + case GL_MAP2_VERTEX_4: + bpm->bpatch = bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 4,ustride, vstride, ctlpoints ); + break; + case GL_MAP2_NORMAL: + bpm->bpatch_normal = bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 3, ustride, vstride, ctlpoints); + break; + case GL_MAP2_INDEX: + bpm->bpatch_color = bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 1, ustride, vstride, ctlpoints); + break; + case GL_MAP2_COLOR_4: + bpm->bpatch_color = bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 4, ustride, vstride, ctlpoints); + break; + case GL_MAP2_TEXTURE_COORD_1: + bpm->bpatch_texcoord = bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 1, ustride, vstride, ctlpoints); + break; + case GL_MAP2_TEXTURE_COORD_2: + bpm->bpatch_texcoord = bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 2, ustride, vstride, ctlpoints); + break; + case GL_MAP2_TEXTURE_COORD_3: + bpm->bpatch_texcoord = bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 3, ustride, vstride, ctlpoints); + break; + case GL_MAP2_TEXTURE_COORD_4: + bpm->bpatch_texcoord = bezierPatchMake2(umin, vmin, umax, vmax, uorder, vorder, 4, ustride, vstride, ctlpoints); + break; + default: + fprintf(stderr, "error in bezierPatchMeshPutPatch, maptype=%i is wrong, maptype,map is invalid\n", maptype); + } +} + + +/*delete everything including the arrays. So if you want to output the + *pointers of the arrays, you should not use this function to deallocate space. + *you should dealocate manually + */ +void bezierPatchMeshDelete(bezierPatchMesh *bpm) +{ + if(bpm->bpatch != NULL) + bezierPatchDelete(bpm->bpatch); + if(bpm->bpatch_normal != NULL) + bezierPatchDelete(bpm->bpatch_normal); + if(bpm->bpatch_color != NULL) + bezierPatchDelete(bpm->bpatch_color); + if(bpm->bpatch_texcoord != NULL) + bezierPatchDelete(bpm->bpatch_texcoord); + + free(bpm->UVarray); + free(bpm->length_array); + free(bpm->vertex_array); + free(bpm->normal_array); + free(bpm->type_array); + free(bpm); +} + +/*begin a strip + *type is the primitive type: + */ +void bezierPatchMeshBeginStrip(bezierPatchMesh *bpm, GLenum type) +{ + bpm->counter = 0; + bpm->type = type; +} + +/*signal the end of the current strip*/ +void bezierPatchMeshEndStrip(bezierPatchMesh *bpm) +{ + int i; + + /*if there are no vertices in this strip, then nothing needs to be done*/ + if(bpm->counter == 0) return; + + /*if the length_array is full, it should be expanded*/ + if(bpm->index_length_array >= bpm->size_length_array) + { + int *temp = (int*) malloc(sizeof(int) * (bpm->size_length_array*2 + 1)); + assert(temp); + GLenum *temp_type = (GLenum*) malloc(sizeof(GLenum) * (bpm->size_length_array*2 + 1)); + assert(temp_type); + /*update the size*/ + bpm->size_length_array = bpm->size_length_array*2 + 1; + + /*copy*/ + for(i=0; iindex_length_array; i++) + { + temp[i] = bpm->length_array[i]; + temp_type[i] = bpm->type_array[i]; + } + + /*deallocate old array*/ + free(bpm->length_array); + free(bpm->type_array); + + /*point to the new array which is twice as bigger*/ + bpm->length_array = temp; + bpm->type_array = temp_type; + } + bpm->type_array[bpm->index_length_array] = bpm->type; + bpm->length_array[bpm->index_length_array++] = bpm->counter; + +} + +/*insert (u,v) */ +void bezierPatchMeshInsertUV(bezierPatchMesh *bpm, float u, float v) +{ + int i; + /*if the UVarray is full, it should be expanded*/ + if(bpm->index_UVarray+1 >= bpm->size_UVarray) + { + float *temp = (float*) malloc(sizeof(float) * (bpm->size_UVarray * 2 + 2)); + assert(temp); + + /*update the size*/ + bpm->size_UVarray = bpm->size_UVarray*2 + 2; + + /*copy*/ + for(i=0; iindex_UVarray; i++) + { + temp[i] = bpm->UVarray[i]; + } + + /*deallocate old array*/ + free(bpm->UVarray); + + /*pointing to the new arrays*/ + bpm->UVarray = temp; + } + /*insert the new UV*/ + bpm->UVarray[bpm->index_UVarray] = u; + bpm->index_UVarray++; + bpm->UVarray[bpm->index_UVarray] = v; + bpm->index_UVarray++; + + /*update counter: one more vertex*/ + bpm->counter++; + + +} + +void bezierPatchMeshPrint(bezierPatchMesh *bpm) +{ + int i; + printf("the bezier patch is\n"); + bezierPatchPrint(bpm->bpatch); + printf("index_length_array= %i\n", bpm->index_length_array); + printf("size_length_array =%i\n", bpm->size_length_array); + printf("index_UVarray =%i\n", bpm->index_UVarray); + printf("size_UVarray =%i\n", bpm->size_UVarray); + printf("UVarray is\n"); + for(i=0; iindex_UVarray; i++) + printf("%f ", bpm->UVarray[i]); + + printf("length_array is\n"); + for(i=0; iindex_length_array; i++) + printf("%i ", bpm->length_array[i]); + printf("\n"); + +} + +/*insert a new patch in front of the current linked list and return the new list*/ +bezierPatchMesh* bezierPatchMeshListInsert(bezierPatchMesh* list, bezierPatchMesh* bpm) +{ + bpm->next=list; + return bpm; +} + +/*print all the patches*/ +void bezierPatchMeshListPrint(bezierPatchMesh* list) +{ + bezierPatchMesh *temp; + for(temp = list; temp != NULL; temp = temp->next) + { + bezierPatchMeshPrint(temp); + } +} + +int bezierPatchMeshListTotalStrips(bezierPatchMesh* list) +{ + int sum=0; + bezierPatchMesh *temp; + for(temp=list; temp != NULL; temp = temp->next) + { + sum += temp->index_length_array; + } + return sum; +} + +int bezierPatchMeshListTotalVert(bezierPatchMesh* list) +{ + int sum=0; + bezierPatchMesh *temp; + for(temp=list; temp != NULL; temp = temp->next) + { + sum += temp->index_UVarray; + } + return sum/2; +} + +int bezierPatchMeshListNumTriangles(bezierPatchMesh* list) +{ + int sum=0; + bezierPatchMesh* temp; + for(temp=list; temp != NULL; temp = temp->next) + { + sum += bezierPatchMeshNumTriangles(temp); + } + return sum; +} + +int bezierPatchMeshNumTriangles(bezierPatchMesh* bpm) +{ + int i; + int sum=0; + for(i=0; iindex_length_array; i++) + { + switch(bpm->type_array[i]) + { + case GL_TRIANGLES: + sum += bpm->length_array[i]/3; + break; + case GL_TRIANGLE_FAN: + if(bpm->length_array[i] > 2) + sum += bpm->length_array[i]-2; + break; + case GL_TRIANGLE_STRIP: + if(bpm->length_array[i] > 2) + sum += bpm->length_array[i]-2; + break; + case GL_QUAD_STRIP: + if(bpm->length_array[i]>2) + sum += (bpm->length_array[i]-2); + break; + default: + fprintf(stderr,"error in bezierPatchMeshListNumTriangles, type invalid\n"); + } + } + return sum; +} + +/*delete degenerate triangles*/ +void bezierPatchMeshDelDeg(bezierPatchMesh* bpm) +{ + if(bpm == NULL) return; + int i,j,k; + int *new_length_array; + GLenum *new_type_array; + int index_new_length_array; + float *new_UVarray; + int index_new_UVarray; + + new_length_array = (int*)malloc(sizeof(int) * bpm->index_length_array); + assert(new_length_array); + new_type_array = (GLenum*)malloc(sizeof(GLenum) * bpm->index_length_array); + assert(new_length_array); + new_UVarray = (float*) malloc(sizeof(float) * bpm->index_UVarray); + assert(new_UVarray); + + index_new_length_array = 0; + index_new_UVarray=0; + k=0; + for(i=0; iindex_length_array; i++){ + + /*(if not degenerate, we have to copy*/ + if( (bpm->length_array[i] != 3) || (!isDegenerate(bpm->UVarray+k, bpm->UVarray+k+2, bpm->UVarray+k+4))) + { + for(j=0; j<2* bpm->length_array[i]; j++) + new_UVarray[index_new_UVarray++] = bpm->UVarray[k++]; + + new_length_array[index_new_length_array] = bpm->length_array[i]; + new_type_array[index_new_length_array] = bpm->type_array[i]; + index_new_length_array++; + } + else + { + k += 6; + } + } + free(bpm->UVarray); + free(bpm->length_array); + free(bpm->type_array); + bpm->UVarray=new_UVarray; + bpm->length_array=new_length_array; + bpm->type_array=new_type_array; + bpm->index_UVarray = index_new_UVarray; + bpm->index_length_array = index_new_length_array; + +} + +/*(u,v) to XYZ + *the xyz and normals are stored in vertex_array, + *and normal_array. the spaces of both are allocated here + */ +void bezierPatchMeshEval(bezierPatchMesh* bpm) +{ + int i,j,k,l; + float u,v; + float u0 = bpm->bpatch->umin; + float u1 = bpm->bpatch->umax; + int uorder = bpm->bpatch->uorder; + float v0 = bpm->bpatch->vmin; + float v1 = bpm->bpatch->vmax; + int vorder = bpm->bpatch->vorder; + int dimension = bpm->bpatch->dimension; + int ustride = dimension * vorder; + int vstride = dimension; + float *ctlpoints = bpm->bpatch->ctlpoints; + + bpm->vertex_array = (float*) malloc(sizeof(float)* (bpm->index_UVarray/2) * 3); + assert(bpm->vertex_array); + bpm->normal_array = (float*) malloc(sizeof(float)* (bpm->index_UVarray/2) * 3); + assert(bpm->normal_array); + + k=0; + l=0; + for(i=0; iindex_length_array; i++) + { + for(j=0; jlength_array[i]; j++) + { + u = bpm->UVarray[k]; + v = bpm->UVarray[k+1]; + bezierSurfEval(u0,u1,uorder, v0, v1, vorder, dimension, ctlpoints, ustride, vstride, u,v, bpm->vertex_array+l); + bezierSurfEvalNormal(u0,u1,uorder, v0, v1, vorder, dimension, ctlpoints, ustride, vstride, u,v, bpm->normal_array+l); + k += 2; + l += 3; + } + } +} + +void bezierPatchMeshListEval(bezierPatchMesh* list) +{ + bezierPatchMesh* temp; + for(temp = list; temp != NULL; temp = temp->next) + { + bezierPatchMeshEval(temp); + } +} + +void bezierPatchMeshDraw(bezierPatchMesh* bpm) +{ + int i,j,k; + k=0; + /*k is the index of the first component of the current vertex*/ + for(i=0; iindex_length_array; i++) + { + glBegin(bpm->type_array[i]); + for(j=0; jlength_array[i]; j++) + { + glNormal3fv(bpm->normal_array+k); + glVertex3fv(bpm->vertex_array+k); + k+= 3; + } + glEnd(); + } +} + +void bezierPatchMeshListDraw(bezierPatchMesh* list) +{ + bezierPatchMesh* temp; + for(temp = list; temp != NULL; temp = temp->next) + { + bezierPatchMeshDraw(temp); + } +} + +void bezierPatchMeshListCollect(bezierPatchMesh* list, float **vertex_array, float **normal_array, int **length_array, GLenum **type_array, int *num_strips) +{ + int i,j,k,l; + bezierPatchMesh *temp; + int total_num_vertices = bezierPatchMeshListTotalVert(list); + (*vertex_array) = (float *) malloc(sizeof(float) * total_num_vertices*3); + assert(*vertex_array); + (*normal_array) = (float *) malloc(sizeof(float) * total_num_vertices*3); + assert(*normal_array); + + *num_strips = bezierPatchMeshListTotalStrips(list); + + *length_array = (int*) malloc(sizeof(int) * (*num_strips)); + assert(*length_array); + + *type_array = (GLenum*) malloc(sizeof(GLenum) * (*num_strips)); + assert(*type_array); + + k=0; + l=0; + for(temp = list; temp != NULL; temp = temp->next) + { + int x=0; + for(i=0; iindex_length_array; i++) + { + for(j=0; jlength_array[i]; j++) + { + (*vertex_array)[k] = temp->vertex_array[x]; + (*vertex_array)[k+1] = temp->vertex_array[x+1]; + (*vertex_array)[k+2] = temp->vertex_array[x+2]; + + (*normal_array)[k] = temp->normal_array[x]; + (*normal_array)[k+1] = temp->normal_array[x+1]; + (*normal_array)[k+2] = temp->normal_array[x+2]; + + x += 3; + k += 3; + } + (*type_array)[l] = temp->type_array[i]; + (*length_array)[l++] = temp->length_array[i]; + } + } +} + + + +static int isDegenerate(float A[2], float B[2], float C[2]) +{ + if( (A[0] == B[0] && A[1]==B[1]) || + (A[0] == C[0] && A[1]==C[1]) || + (B[0] == C[0] && B[1]==C[1]) + ) + return 1; + else + return 0; +} + + + + diff --git a/src/glu/sgi/libnurbs/interface/bezierPatchMesh.h b/src/glu/sgi/libnurbs/interface/bezierPatchMesh.h new file mode 100644 index 0000000..ba6868a --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/bezierPatchMesh.h @@ -0,0 +1,121 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _BEZIERPATCHMESH_H +#define _BEZIERPATCHMESH_H + +#include +#include "bezierPatch.h" + +typedef struct bezierPatchMesh{ + bezierPatch *bpatch; /*vertex*/ + bezierPatch *bpatch_normal; + bezierPatch *bpatch_texcoord; /*s,t,r,q*/ + bezierPatch *bpatch_color; /*RGBA*/ + + float *UVarray; /*all UV components of all vertices of all strips*/ + int *length_array; /*[i] is the number of vertices in the ith strip*/ + GLenum *type_array; /*[i] is the type of the ith primitive*/ + + /*to support dynamic insertion*/ + int size_UVarray; + int index_UVarray; + int size_length_array; + int index_length_array; + + int counter; /*track the current strip size*/ + GLenum type; /*track the current type: 0: GL_TRIANGLES, 1: GL_TRIANGLE_STRIP*/ + + /*we eventually want to evaluate from (u,v) to (x,y,z) and draw them*/ + float *vertex_array; /*each vertex contains three components*/ + float *normal_array; /*each normal contains three components*/ + float *color_array; + float *texcoord_array; + + /*in case we need a linked list*/ + struct bezierPatchMesh *next; +} bezierPatchMesh; + +#ifdef __cplusplus +extern "C" { +#endif + + + +bezierPatchMesh *bezierPatchMeshMake(int maptype, float umin, float umax, int ustride, int uorder, float vmin, float vmax, int vstride, int vorder, float *ctlpoints, int size_UVarray, int size_length_array); + +/*initilize patches to be null*/ +bezierPatchMesh *bezierPatchMeshMake2(int size_UVarray, int size_length_array); + +void bezierPatchMeshPutPatch(bezierPatchMesh *bpm, int maptype, float umin, float umax, int ustride, int uorder, float vmin, float vmax, int vstride, int vorder, float *ctlpoints); + +void bezierPatchMeshDelete(bezierPatchMesh *bpm); + +void bezierPatchMeshBeginStrip(bezierPatchMesh *bpm, GLenum type); + +void bezierPatchMeshEndStrip(bezierPatchMesh *bpm); + +void bezierPatchMeshInsertUV(bezierPatchMesh *bpm, float u, float v); + +void bezierPatchMeshPrint(bezierPatchMesh *bpm); + +bezierPatchMesh* bezierPatchMeshListInsert(bezierPatchMesh* list, bezierPatchMesh* bpm); + +void bezierPatchMeshListPrint(bezierPatchMesh* list); + +int bezierPatchMeshListTotalStrips(bezierPatchMesh* list); + +int bezierPatchMeshListTotalVert(bezierPatchMesh* list); +int bezierPatchMeshNumTriangles(bezierPatchMesh* bpm); +int bezierPatchMeshListNumTriangles(bezierPatchMesh* list); + +void bezierPatchMeshDelDeg(bezierPatchMesh* bpm); + + +void bezierPatchMeshEval(bezierPatchMesh* bpm); + +void bezierPatchMeshDraw(bezierPatchMesh* bpm); + +void bezierPatchMeshListDraw(bezierPatchMesh* list); +void bezierPatchMeshListEval(bezierPatchMesh* list); +void bezierPatchMeshListCollect(bezierPatchMesh* list, float **vertex_array, float **normal_array, int **length_array, GLenum **type_array, int *num_strips); + +void bezierPatchMeshListDelDeg(bezierPatchMesh* list); +void bezierPatchMeshListDelete(bezierPatchMesh *list); +bezierPatchMesh* bezierPatchMeshListReverse(bezierPatchMesh* list); +void drawStrips(float *vertex_array, float *normal_array, int *length_array, GLenum *type_array, int num_strips); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/glu/sgi/libnurbs/interface/glcurveval.cc b/src/glu/sgi/libnurbs/interface/glcurveval.cc new file mode 100644 index 0000000..b6591db --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/glcurveval.cc @@ -0,0 +1,402 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * glcurveval.c++ + * + */ + +/* Polynomial Evaluator Interface */ + +#include "gluos.h" +#include "glimports.h" +#include "glrenderer.h" +#include "glcurveval.h" +#include "nurbsconsts.h" + +OpenGLCurveEvaluator::OpenGLCurveEvaluator(void) +{ + //no default callback functions + beginCallBackN = NULL; + endCallBackN = NULL; + vertexCallBackN = NULL; + normalCallBackN = NULL; + colorCallBackN = NULL; + texcoordCallBackN = NULL; + beginCallBackData = NULL; + endCallBackData = NULL; + vertexCallBackData = NULL; + normalCallBackData = NULL; + colorCallBackData = NULL; + texcoordCallBackData = NULL; + + userData = NULL; + + vertex_flag = 0; + normal_flag = 0; + color_flag = 0; + texcoord_flag = 0; + + em_vertex.uprime = -1.0; + em_normal.uprime = -1.0; + em_color.uprime = -1.0; + em_texcoord.uprime = -1.0; + output_triangles = 0; // don't output triangles by default +} + +OpenGLCurveEvaluator::~OpenGLCurveEvaluator(void) +{ +} + +/* added nonsense to avoid the warning messages at compile time */ +void +OpenGLCurveEvaluator::addMap(CurveMap *m) +{ + m = m; +} + +void +OpenGLCurveEvaluator::range1f(long type, REAL *from, REAL *to) +{ + type = type; + from = from; + to = to; +} + +void +OpenGLCurveEvaluator::domain1f(REAL ulo, REAL uhi) +{ + ulo = ulo; + uhi = uhi; +} + +void +OpenGLCurveEvaluator::bgnline(void) +{ + if(output_triangles) + beginCallBack(GL_LINE_STRIP, userData); + else + glBegin((GLenum) GL_LINE_STRIP); +} + +void +OpenGLCurveEvaluator::endline(void) +{ + if(output_triangles) + endCallBack(userData); + else + glEnd(); +} + +/*--------------------------------------------------------------------------- + * disable - turn off a curve map + *--------------------------------------------------------------------------- + */ +void +OpenGLCurveEvaluator::disable(long type) +{ + glDisable((GLenum) type); +} + +/*--------------------------------------------------------------------------- + * enable - turn on a curve map + *--------------------------------------------------------------------------- + */ +void +OpenGLCurveEvaluator::enable(long type) +{ + glEnable((GLenum) type); +} + +/*------------------------------------------------------------------------- + * mapgrid1f - define a lattice of points with origin and offset + *------------------------------------------------------------------------- + */ +void +OpenGLCurveEvaluator::mapgrid1f(long nu, REAL u0, REAL u1) +{ + if(output_triangles) + { + global_grid_u0 = u0; + global_grid_u1 = u1; + global_grid_nu = (int) nu; + } + else + glMapGrid1f((GLint) nu, (GLfloat) u0, (GLfloat) u1); +} + +/*------------------------------------------------------------------------- + * bgnmap1 - preamble to curve definition and evaluations + *------------------------------------------------------------------------- + */ +void +OpenGLCurveEvaluator::bgnmap1f(long) +{ + if(output_triangles) + { + //initialized so that no maps are set initially + vertex_flag = 0; + normal_flag = 0; + color_flag = 0; + texcoord_flag = 0; + //no need to worry about gl states when doing callback + } + else + glPushAttrib((GLbitfield) GL_EVAL_BIT); +} + +/*------------------------------------------------------------------------- + * endmap1 - postamble to a curve map + *------------------------------------------------------------------------- + */ +void +OpenGLCurveEvaluator::endmap1f(void) +{ + if(output_triangles) + { + + } + else + glPopAttrib(); +} + +/*------------------------------------------------------------------------- + * map1f - pass a desription of a curve map + *------------------------------------------------------------------------- + */ +void +OpenGLCurveEvaluator::map1f( + long type, /* map type */ + REAL ulo, /* lower parametric bound */ + REAL uhi, /* upper parametric bound */ + long stride, /* distance to next point in REALS */ + long order, /* parametric order */ + REAL *pts /* control points */ +) +{ + if(output_triangles) + { + int dimension = 0; + int which = 0; + switch(type){ + case GL_MAP1_VERTEX_3: + which = 0; + dimension = 3; + break; + case GL_MAP1_VERTEX_4: + which=0; + dimension = 4; + break; + case GL_MAP1_INDEX: + which=2; + dimension = 1; + break; + case GL_MAP1_COLOR_4: + which=2; + dimension = 4; + break; + case GL_MAP1_NORMAL: + which=1; + dimension = 3; + break; + case GL_MAP1_TEXTURE_COORD_1: + which=3; + dimension = 1; + break; + case GL_MAP1_TEXTURE_COORD_2: + which=3; + dimension = 2; + break; + + case GL_MAP1_TEXTURE_COORD_3: + which=3; + dimension = 3; + break; + case GL_MAP1_TEXTURE_COORD_4: + which=3; + dimension = 4; + break; + } + inMap1f(which, dimension, ulo, uhi, stride, order, pts); + } + else + glMap1f((GLenum) type, (GLfloat) ulo, (GLfloat) uhi, (GLint) stride, + (GLint) order, (const GLfloat *) pts); +} + +/*------------------------------------------------------------------------- + * mapmesh1f - evaluate a mesh of points on lattice + *------------------------------------------------------------------------- + */ +void OpenGLCurveEvaluator::mapmesh1f(long style, long from, long to) +{ + if(output_triangles) + { + inMapMesh1f((int) from, (int) to); + } + else + { + switch(style) { + default: + case N_MESHFILL: + case N_MESHLINE: + glEvalMesh1((GLenum) GL_LINE, (GLint) from, (GLint) to); + break; + case N_MESHPOINT: + glEvalMesh1((GLenum) GL_POINT, (GLint) from, (GLint) to); + break; + } + } +} + +/*------------------------------------------------------------------------- + * evalpoint1i - evaluate a point on a curve + *------------------------------------------------------------------------- + */ +void OpenGLCurveEvaluator::evalpoint1i(long i) +{ + glEvalPoint1((GLint) i); +} + +/*------------------------------------------------------------------------- + * evalcoord1f - evaluate a point on a curve + *------------------------------------------------------------------------- + */ +void OpenGLCurveEvaluator::evalcoord1f(long, REAL u) +{ + glEvalCoord1f((GLfloat) u); +} + +void +#ifdef _WIN32 +OpenGLCurveEvaluator::putCallBack(GLenum which, void (GLAPIENTRY *fn)()) +#else +OpenGLCurveEvaluator::putCallBack(GLenum which, _GLUfuncptr fn) +#endif +{ + switch(which) + { + case GLU_NURBS_BEGIN: + beginCallBackN = (void (GLAPIENTRY *) (GLenum)) fn; + break; + case GLU_NURBS_END: + endCallBackN = (void (GLAPIENTRY *) (void)) fn; + break; + case GLU_NURBS_VERTEX: + vertexCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn; + break; + case GLU_NURBS_NORMAL: + normalCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn; + break; + case GLU_NURBS_COLOR: + colorCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn; + break; + case GLU_NURBS_TEXTURE_COORD: + texcoordCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn; + break; + case GLU_NURBS_BEGIN_DATA: + beginCallBackData = (void (GLAPIENTRY *) (GLenum, void*)) fn; + break; + case GLU_NURBS_END_DATA: + endCallBackData = (void (GLAPIENTRY *) (void*)) fn; + break; + case GLU_NURBS_VERTEX_DATA: + vertexCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn; + break; + case GLU_NURBS_NORMAL_DATA: + normalCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn; + break; + case GLU_NURBS_COLOR_DATA: + colorCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn; + break; + case GLU_NURBS_TEXTURE_COORD_DATA: + texcoordCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn; + break; + } +} + +void +OpenGLCurveEvaluator::beginCallBack(GLenum which, void *data) +{ + if(beginCallBackData) + beginCallBackData(which, data); + else if(beginCallBackN) + beginCallBackN(which); +} + +void +OpenGLCurveEvaluator::endCallBack(void *data) +{ + if(endCallBackData) + endCallBackData(data); + else if(endCallBackN) + endCallBackN(); +} + +void +OpenGLCurveEvaluator::vertexCallBack(const GLfloat *vert, void* data) +{ + if(vertexCallBackData) + vertexCallBackData(vert, data); + else if(vertexCallBackN) + vertexCallBackN(vert); +} + + +void +OpenGLCurveEvaluator::normalCallBack(const GLfloat *normal, void* data) +{ + if(normalCallBackData) + normalCallBackData(normal, data); + else if(normalCallBackN) + normalCallBackN(normal); +} + +void +OpenGLCurveEvaluator::colorCallBack(const GLfloat *color, void* data) +{ + if(colorCallBackData) + colorCallBackData(color, data); + else if(colorCallBackN) + colorCallBackN(color); +} + +void +OpenGLCurveEvaluator::texcoordCallBack(const GLfloat *texcoord, void* data) +{ + if(texcoordCallBackData) + texcoordCallBackData(texcoord, data); + else if(texcoordCallBackN) + texcoordCallBackN(texcoord); +} diff --git a/src/glu/sgi/libnurbs/interface/glcurveval.h b/src/glu/sgi/libnurbs/interface/glcurveval.h new file mode 100644 index 0000000..8fa4930 --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/glcurveval.h @@ -0,0 +1,157 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * glcurveval.h + * + */ + +#ifndef __gluglcurveval_h_ +#define __gluglcurveval_h_ + +#include "gluos.h" +#include +#include +#include "basiccrveval.h" + +class CurveMap; + +/*for internal evaluator callback stuff*/ +#ifndef IN_MAX_BEZIER_ORDER +#define IN_MAX_BEZIER_ORDER 40 /*XXX should be bigger than machine order*/ +#endif + +#ifndef IN_MAX_DIMENSION +#define IN_MAX_DIMENSION 4 +#endif + +typedef struct curveEvalMachine{ + REAL uprime; //cached previously evaluated uprime + int k; //the dimension + REAL u1; + REAL u2; + int ustride; + int uorder; + REAL ctlpoints[IN_MAX_BEZIER_ORDER*IN_MAX_DIMENSION]; + REAL ucoeff[IN_MAX_BEZIER_ORDER];//cache the polynomial values +} curveEvalMachine; + +class OpenGLCurveEvaluator : public BasicCurveEvaluator { +public: + OpenGLCurveEvaluator(void); + virtual ~OpenGLCurveEvaluator(void); + void range1f(long, REAL *, REAL *); + void domain1f(REAL, REAL); + void addMap(CurveMap *); + + void enable(long); + void disable(long); + void bgnmap1f(long); + void map1f(long, REAL, REAL, long, long, REAL *); + void mapgrid1f(long, REAL, REAL); + void mapmesh1f(long, long, long); + void evalpoint1i(long); + void evalcoord1f(long, REAL); + void endmap1f(void); + + void bgnline(void); + void endline(void); + + void put_vertices_call_back(int flag) + { + output_triangles = flag; + } +#ifdef _WIN32 + void putCallBack(GLenum which, void (GLAPIENTRY *fn)() ); +#else + void putCallBack(GLenum which, _GLUfuncptr fn ); +#endif + void set_callback_userData(void *data) + { + userData = data; + } + +/*------------------begin for curveEvalMachine------------*/ +curveEvalMachine em_vertex; +curveEvalMachine em_normal; +curveEvalMachine em_color; +curveEvalMachine em_texcoord; +int vertex_flag; //whether there is a vertex map or not +int normal_flag; //whether there is a normal map or not +int color_flag; //whether there is a color map or not +int texcoord_flag; //whether there is a texture map or not + +REAL global_grid_u0; +REAL global_grid_u1; +int global_grid_nu; + +void inMap1f(int which, //0: vert, 1: norm, 2: color, 3: tex + int dimension, + REAL ulower, + REAL uupper, + int ustride, + int uorder, + REAL *ctlpoints); + +void inPreEvaluate(int order, REAL vprime, REAL *coeff); +void inDoDomain1(curveEvalMachine *em, REAL u, REAL *retPoint); +void inDoEvalCoord1(REAL u); +void inMapMesh1f(int umin, int umax); + +void (GLAPIENTRY *beginCallBackN) (GLenum type); +void (GLAPIENTRY *endCallBackN) (void); +void (GLAPIENTRY *vertexCallBackN) (const GLfloat *vert); +void (GLAPIENTRY *normalCallBackN) (const GLfloat *normal); +void (GLAPIENTRY *colorCallBackN) (const GLfloat *color); +void (GLAPIENTRY *texcoordCallBackN) (const GLfloat *texcoord); + +void (GLAPIENTRY *beginCallBackData) (GLenum type, void* data); +void (GLAPIENTRY *endCallBackData) (void* data); +void (GLAPIENTRY *vertexCallBackData) (const GLfloat *vert, void* data); +void (GLAPIENTRY *normalCallBackData) (const GLfloat *normal, void* data); +void (GLAPIENTRY *colorCallBackData) (const GLfloat *color, void* data); +void (GLAPIENTRY *texcoordCallBackData) (const GLfloat *texcoord, void* data); + +void* userData; //the opaque pointer for Data callback functions +void beginCallBack(GLenum type, void* data); +void endCallBack(void* data); +void vertexCallBack(const GLfloat *vert, void *data); +void normalCallBack(const GLfloat *normal, void* data); +void colorCallBack(const GLfloat *color, void* data); +void texcoordCallBack(const GLfloat *texcoord, void* data); + + +/*------------------end for curveEvalMachine------------*/ + +private: + int output_triangles; //true 1; false 0 +}; + +#endif /* __gluglcurveval_h_ */ diff --git a/src/glu/sgi/libnurbs/interface/glimports.h b/src/glu/sgi/libnurbs/interface/glimports.h new file mode 100644 index 0000000..6e69feb --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/glimports.h @@ -0,0 +1,42 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * glimports.h + * + */ + +#ifndef __gluimports_h_ +#define __gluimports_h_ + +#include "mystdlib.h" +#include "mystdio.h" + +#endif /* __gluimports_h_ */ diff --git a/src/glu/sgi/libnurbs/interface/glinterface.cc b/src/glu/sgi/libnurbs/interface/glinterface.cc new file mode 100644 index 0000000..ba64bcd --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/glinterface.cc @@ -0,0 +1,469 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include "gluos.h" +#include +#include +#include +#include "glimports.h" +#include "glrenderer.h" +#include "nurbsconsts.h" + +//#define DOWN_LOAD_NURBS +#ifdef DOWN_LOAD_NURBS + +#include "oglTrimNurbs.h" +static int surfcount = 0; +static oglTrimNurbs* otn = NULL; +nurbSurf* tempNurb = NULL; +oglTrimLoops* tempTrim = NULL; +#endif + + +//for LOD +extern "C" {void glu_LOD_eval_list(GLUnurbs *nurb, int level);} + +void glu_LOD_eval_list(GLUnurbs *nurb, int level) +{ + nurb->LOD_eval_list(level); +} + +GLUnurbs * GLAPIENTRY +gluNewNurbsRenderer(void) +{ + GLUnurbs *t; + + t = new GLUnurbs(); + return t; +} + +void GLAPIENTRY +gluDeleteNurbsRenderer(GLUnurbs *r) +{ + delete r; +} + +extern "C" +void GLAPIENTRY + +gluDeleteNurbsTessellatorEXT(GLUnurbsObj *r) +{ + delete r; +} + +void GLAPIENTRY +gluBeginSurface(GLUnurbs *r) +{ +#ifdef DOWN_LOAD_NURBS +surfcount++; +tempTrim = OTL_make(10,10); +#endif + r->bgnsurface(0); +} + +void GLAPIENTRY +gluBeginCurve(GLUnurbs *r) +{ + r->bgncurve(0); +} + +void GLAPIENTRY +gluEndCurve(GLUnurbs *r) +{ + r->endcurve(); +} + +void GLAPIENTRY +gluEndSurface(GLUnurbs *r) +{ +#ifdef DOWN_LOAD_NURBS +if(surfcount == 1) + otn = OTN_make(1); +OTN_insert(otn, tempNurb, tempTrim); +if(surfcount >= 1) +{ +#ifdef DEBUG +printf("write file\n"); +#endif +OTN_write(otn, "out.otn"); + +} +#endif + + r->endsurface(); +} + +void GLAPIENTRY +gluBeginTrim(GLUnurbs *r) +{ +#ifdef DOWN_LOAD_NURBS +OTL_bgnTrim(tempTrim); +#endif + + r->bgntrim(); +} + +void GLAPIENTRY +gluEndTrim(GLUnurbs *r) +{ +#ifdef DOWN_LOAD_NURBS +OTL_endTrim(tempTrim); +#endif + r->endtrim(); +} + +void GLAPIENTRY +gluPwlCurve(GLUnurbs *r, GLint count, INREAL array[], + GLint stride, GLenum type) +{ +#ifdef DOWN_LOAD_NURBS +OTL_pwlCurve(tempTrim, count, array, stride, type); +#endif + + int realType; + switch(type) { + case GLU_MAP1_TRIM_2: + realType = N_P2D; + break; + case GLU_MAP1_TRIM_3: + realType = N_P2DR; + break; + default: + realType = type; + break; + } + r->pwlcurve(count, array, sizeof(INREAL) * stride, realType); +} + +void GLAPIENTRY +gluNurbsCurve(GLUnurbs *r, GLint nknots, INREAL knot[], GLint stride, + INREAL ctlarray[], GLint order, GLenum type) +{ +#ifdef DOWN_LOAD_NURBS +OTL_nurbsCurve(tempTrim, nknots, knot, stride, ctlarray, order, type); +#endif + + int realType; + + switch(type) { + case GLU_MAP1_TRIM_2: + realType = N_P2D; + break; + case GLU_MAP1_TRIM_3: + realType = N_P2DR; + break; + default: + realType = type; + break; + } + + r->nurbscurve(nknots, knot, sizeof(INREAL) * stride, ctlarray, order, + realType); +} + +void GLAPIENTRY +gluNurbsSurface(GLUnurbs *r, GLint sknot_count, GLfloat *sknot, + GLint tknot_count, GLfloat *tknot, + GLint s_stride, GLint t_stride, + GLfloat *ctlarray, GLint sorder, GLint torder, + GLenum type) +{ +#ifdef DOWN_LOAD_NURBS + { + int dimension; + switch(type){ + case GL_MAP2_VERTEX_3: + dimension = 3; + break; + case GL_MAP2_VERTEX_4: + dimension = 4; + break; + default: + fprintf(stderr, "error in glinterface.c++, type no implemented\n"); + exit(1); + } +tempNurb = nurbSurfMake(sknot_count, sknot, + tknot_count, tknot, + sorder, torder, + dimension, + ctlarray, + s_stride, t_stride); + + } +#endif + + r->nurbssurface(sknot_count, sknot, tknot_count, tknot, + sizeof(INREAL) * s_stride, sizeof(INREAL) * t_stride, + ctlarray, sorder, torder, type); +} + +void GLAPIENTRY +gluLoadSamplingMatrices(GLUnurbs *r, const GLfloat modelMatrix[16], + const GLfloat projMatrix[16], + const GLint viewport[4]) +{ + r->useGLMatrices(modelMatrix, projMatrix, viewport); +} + +void GLAPIENTRY +gluNurbsProperty(GLUnurbs *r, GLenum property, GLfloat value) +{ + GLfloat nurbsValue; + + switch (property) { + case GLU_AUTO_LOAD_MATRIX: + r->setautoloadmode(value); + return; + + case GLU_CULLING: + if (value != 0.0) { + nurbsValue = N_CULLINGON; + } else { + nurbsValue = N_NOCULLING; + } + r->setnurbsproperty(GL_MAP2_VERTEX_3, N_CULLING, nurbsValue); + r->setnurbsproperty(GL_MAP2_VERTEX_4, N_CULLING, nurbsValue); + r->setnurbsproperty(GL_MAP1_VERTEX_3, N_CULLING, nurbsValue); + r->setnurbsproperty(GL_MAP1_VERTEX_4, N_CULLING, nurbsValue); + return; + + case GLU_SAMPLING_METHOD: + if (value == GLU_PATH_LENGTH) { + nurbsValue = N_PATHLENGTH; + } else if (value == GLU_PARAMETRIC_ERROR) { + nurbsValue = N_PARAMETRICDISTANCE; + } else if (value == GLU_DOMAIN_DISTANCE) { + nurbsValue = N_DOMAINDISTANCE; + r->set_is_domain_distance_sampling(1); //optimzing untrimmed case + + } else if (value == GLU_OBJECT_PARAMETRIC_ERROR) { + nurbsValue = N_OBJECTSPACE_PARA; + r->setautoloadmode( 0.0 ); + r->setSamplingMatrixIdentity(); + } else if (value == GLU_OBJECT_PATH_LENGTH) { + nurbsValue = N_OBJECTSPACE_PATH; + r->setautoloadmode( 0.0 ); + r->setSamplingMatrixIdentity(); + } else { + r->postError(GLU_INVALID_VALUE); + return; + } + + r->setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMETHOD, nurbsValue); + r->setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMETHOD, nurbsValue); + r->setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMETHOD, nurbsValue); + r->setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMETHOD, nurbsValue); + return; + + case GLU_SAMPLING_TOLERANCE: + r->setnurbsproperty(GL_MAP2_VERTEX_3, N_PIXEL_TOLERANCE, value); + r->setnurbsproperty(GL_MAP2_VERTEX_4, N_PIXEL_TOLERANCE, value); + r->setnurbsproperty(GL_MAP1_VERTEX_3, N_PIXEL_TOLERANCE, value); + r->setnurbsproperty(GL_MAP1_VERTEX_4, N_PIXEL_TOLERANCE, value); + return; + + case GLU_PARAMETRIC_TOLERANCE: + r->setnurbsproperty(GL_MAP2_VERTEX_3, N_ERROR_TOLERANCE, value); + r->setnurbsproperty(GL_MAP2_VERTEX_4, N_ERROR_TOLERANCE, value); + r->setnurbsproperty(GL_MAP1_VERTEX_3, N_ERROR_TOLERANCE, value); + r->setnurbsproperty(GL_MAP1_VERTEX_4, N_ERROR_TOLERANCE, value); + return; + + + case GLU_DISPLAY_MODE: + + if (value == GLU_FILL) { + nurbsValue = N_FILL; + } else if (value == GLU_OUTLINE_POLYGON) { + nurbsValue = N_OUTLINE_POLY; + } else if (value == GLU_OUTLINE_PATCH) { + nurbsValue = N_OUTLINE_PATCH; + } else { + r->postError(GLU_INVALID_VALUE); + return; + } + r->setnurbsproperty(N_DISPLAY, nurbsValue); + + break; + + case GLU_U_STEP: + r->setnurbsproperty(GL_MAP1_VERTEX_3, N_S_STEPS, value); + r->setnurbsproperty(GL_MAP1_VERTEX_4, N_S_STEPS, value); + r->setnurbsproperty(GL_MAP2_VERTEX_3, N_S_STEPS, value); + r->setnurbsproperty(GL_MAP2_VERTEX_4, N_S_STEPS, value); + + //added for optimizing untrimmed case + r->set_domain_distance_u_rate(value); + break; + + case GLU_V_STEP: + r->setnurbsproperty(GL_MAP1_VERTEX_3, N_T_STEPS, value); + r->setnurbsproperty(GL_MAP1_VERTEX_4, N_T_STEPS, value); + r->setnurbsproperty(GL_MAP2_VERTEX_3, N_T_STEPS, value); + r->setnurbsproperty(GL_MAP2_VERTEX_4, N_T_STEPS, value); + + //added for optimizing untrimmed case + r->set_domain_distance_v_rate(value); + break; + + case GLU_NURBS_MODE: + if(value == GLU_NURBS_RENDERER) + r->put_callbackFlag(0); + else if(value == GLU_NURBS_TESSELLATOR) + r->put_callbackFlag(1); + else + r->postError(GLU_INVALID_ENUM); + break; + + default: + r->postError(GLU_INVALID_ENUM); + return; + } +} + +void GLAPIENTRY +gluGetNurbsProperty(GLUnurbs *r, GLenum property, GLfloat *value) +{ + GLfloat nurbsValue; + + switch(property) { + case GLU_AUTO_LOAD_MATRIX: + if (r->getautoloadmode()) { + *value = GL_TRUE; + } else { + *value = GL_FALSE; + } + break; + case GLU_CULLING: + r->getnurbsproperty(GL_MAP2_VERTEX_3, N_CULLING, &nurbsValue); + if (nurbsValue == N_CULLINGON) { + *value = GL_TRUE; + } else { + *value = GL_FALSE; + } + break; + case GLU_SAMPLING_METHOD: + r->getnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMETHOD, value); + if(*value == N_PATHLENGTH) + *value = GLU_PATH_LENGTH; + else if(*value == N_PARAMETRICDISTANCE) + *value = GLU_PARAMETRIC_ERROR; + else if(*value == N_DOMAINDISTANCE) + *value = GLU_DOMAIN_DISTANCE; + else if(*value == N_OBJECTSPACE_PATH) + *value = GLU_OBJECT_PATH_LENGTH; + else if(*value == N_OBJECTSPACE_PARA) + *value = GLU_OBJECT_PARAMETRIC_ERROR; + break; + case GLU_SAMPLING_TOLERANCE: + r->getnurbsproperty(GL_MAP2_VERTEX_3, N_PIXEL_TOLERANCE, value); + break; + case GLU_PARAMETRIC_TOLERANCE: + r->getnurbsproperty(GL_MAP2_VERTEX_3, N_ERROR_TOLERANCE, value); + break; + + case GLU_U_STEP: + r->getnurbsproperty(GL_MAP2_VERTEX_3, N_S_STEPS, value); + break; + case GLU_V_STEP: + r->getnurbsproperty(GL_MAP2_VERTEX_3, N_T_STEPS, value); + break; + case GLU_DISPLAY_MODE: + r->getnurbsproperty(N_DISPLAY, &nurbsValue); + if (nurbsValue == N_FILL) { + *value = GLU_FILL; + } else if (nurbsValue == N_OUTLINE_POLY) { + *value = GLU_OUTLINE_POLYGON; + } else { + *value = GLU_OUTLINE_PATCH; + } + break; + + case GLU_NURBS_MODE: + if(r->is_callback()) + *value = GLU_NURBS_TESSELLATOR; + else + *value = GLU_NURBS_RENDERER; + break; + + default: + r->postError(GLU_INVALID_ENUM); + return; + } +} + +extern "C" void GLAPIENTRY +gluNurbsCallback(GLUnurbs *r, GLenum which, _GLUfuncptr fn ) +{ + switch (which) { + case GLU_NURBS_BEGIN: + case GLU_NURBS_END: + case GLU_NURBS_VERTEX: + case GLU_NURBS_NORMAL: + case GLU_NURBS_TEXTURE_COORD: + case GLU_NURBS_COLOR: + case GLU_NURBS_BEGIN_DATA: + case GLU_NURBS_END_DATA: + case GLU_NURBS_VERTEX_DATA: + case GLU_NURBS_NORMAL_DATA: + case GLU_NURBS_TEXTURE_COORD_DATA: + case GLU_NURBS_COLOR_DATA: + r->putSurfCallBack(which, fn); + break; + + case GLU_NURBS_ERROR: + r->errorCallback = (void (APIENTRY *)( GLenum e )) fn; + break; + default: + r->postError(GLU_INVALID_ENUM); + return; + } +} + +extern "C" +void GLAPIENTRY +gluNurbsCallbackDataEXT(GLUnurbs* r, void* userData) +{ + r->setNurbsCallbackData(userData); +} + +extern "C" +void GLAPIENTRY +gluNurbsCallbackData(GLUnurbs* r, void* userData) +{ + gluNurbsCallbackDataEXT(r,userData); +} diff --git a/src/glu/sgi/libnurbs/interface/glrenderer.cc b/src/glu/sgi/libnurbs/interface/glrenderer.cc new file mode 100644 index 0000000..17123fb --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/glrenderer.cc @@ -0,0 +1,301 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include "gluos.h" +#include "glimports.h" +#include "glrenderer.h" + +GLUnurbs::GLUnurbs() + : NurbsTessellator(curveEvaluator, surfaceEvaluator) +{ + redefineMaps(); + defineMap(GL_MAP2_NORMAL, 0, 3); + defineMap(GL_MAP1_NORMAL, 0, 3); + defineMap(GL_MAP2_TEXTURE_COORD_1, 0, 1); + defineMap(GL_MAP1_TEXTURE_COORD_1, 0, 1); + defineMap(GL_MAP2_TEXTURE_COORD_2, 0, 2); + defineMap(GL_MAP1_TEXTURE_COORD_2, 0, 2); + defineMap(GL_MAP2_TEXTURE_COORD_3, 0, 3); + defineMap(GL_MAP1_TEXTURE_COORD_3, 0, 3); + defineMap(GL_MAP2_TEXTURE_COORD_4, 1, 4); + defineMap(GL_MAP1_TEXTURE_COORD_4, 1, 4); + defineMap(GL_MAP2_VERTEX_4, 1, 4); + defineMap(GL_MAP1_VERTEX_4, 1, 4); + defineMap(GL_MAP2_VERTEX_3, 0, 3); + defineMap(GL_MAP1_VERTEX_3, 0, 3); + defineMap(GL_MAP2_COLOR_4, 0, 4); + defineMap(GL_MAP1_COLOR_4, 0, 4); + defineMap(GL_MAP2_INDEX, 0, 1); + defineMap(GL_MAP1_INDEX, 0, 1); + + setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMETHOD, (float) N_PATHLENGTH); + setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMETHOD, (float) N_PATHLENGTH); + setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMETHOD, (float) N_PATHLENGTH); + setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMETHOD, (float) N_PATHLENGTH); + + setnurbsproperty(GL_MAP1_VERTEX_3, N_PIXEL_TOLERANCE, (float) 50.0); + setnurbsproperty(GL_MAP1_VERTEX_4, N_PIXEL_TOLERANCE, (float) 50.0); + setnurbsproperty(GL_MAP2_VERTEX_3, N_PIXEL_TOLERANCE, (float) 50.0); + setnurbsproperty(GL_MAP2_VERTEX_4, N_PIXEL_TOLERANCE, (float) 50.0); + + setnurbsproperty(GL_MAP1_VERTEX_3, N_ERROR_TOLERANCE, (float) 0.50); + setnurbsproperty(GL_MAP1_VERTEX_4, N_ERROR_TOLERANCE, (float) 0.50); + setnurbsproperty(GL_MAP2_VERTEX_3, N_ERROR_TOLERANCE, (float) 0.50); + setnurbsproperty(GL_MAP2_VERTEX_4, N_ERROR_TOLERANCE, (float) 0.50); + + setnurbsproperty(GL_MAP1_VERTEX_3, N_S_STEPS, (float) 100.0); + setnurbsproperty(GL_MAP1_VERTEX_4, N_S_STEPS, (float) 100.0); + setnurbsproperty(GL_MAP2_VERTEX_3, N_S_STEPS, (float) 100.0); + setnurbsproperty(GL_MAP2_VERTEX_4, N_S_STEPS, (float) 100.0); + + //added for optimizing untrimmed case + set_domain_distance_u_rate(100.0); + + setnurbsproperty(GL_MAP1_VERTEX_3, N_T_STEPS, (float) 100.0); + setnurbsproperty(GL_MAP1_VERTEX_4, N_T_STEPS, (float) 100.0); + setnurbsproperty(GL_MAP2_VERTEX_3, N_T_STEPS, (float) 100.0); + setnurbsproperty(GL_MAP2_VERTEX_4, N_T_STEPS, (float) 100.0); + + //added for optimizing untrimmed case + set_domain_distance_v_rate(100.0); + set_is_domain_distance_sampling(0); //since the default is path_length + + //default autoloadmode is true + autoloadmode = 1; + + //default callbackFlag is 0 + callbackFlag = 0; + + errorCallback = NULL; +} + +void +GLUnurbs::bgnrender(void) +{ + if (autoloadmode) { + loadGLMatrices(); + } +} + +void +GLUnurbs::endrender(void) +{ +} + +void +GLUnurbs::errorHandler(int i) +{ + int gluError; + + gluError = i + (GLU_NURBS_ERROR1 - 1); + postError( gluError ); +} + +void +GLUnurbs::loadGLMatrices(void) +{ + GLfloat vmat[4][4]; + GLint viewport[4]; + + grabGLMatrix((GLfloat (*)[4]) vmat); + loadCullingMatrix((GLfloat (*)[4]) vmat); + ::glGetIntegerv((GLenum) GL_VIEWPORT, (GLint *) viewport); + loadSamplingMatrix((const GLfloat (*)[4]) vmat, (const GLint *) viewport); +} + +void +GLUnurbs::useGLMatrices(const GLfloat modelMatrix[16], + const GLfloat projMatrix[16], + const GLint viewport[4]) +{ + GLfloat vmat[4][4]; + + multmatrix4d(vmat, (const GLfloat (*)[4]) modelMatrix, + (const GLfloat (*)[4]) projMatrix); + loadCullingMatrix((GLfloat (*)[4]) vmat); + loadSamplingMatrix((const GLfloat (*)[4]) vmat, (const GLint *) viewport); +} + +/*-------------------------------------------------------------------------- + * grabGLMatrix + *-------------------------------------------------------------------------- + */ + +void +GLUnurbs::grabGLMatrix(GLfloat vmat[4][4]) +{ + GLfloat m1[4][4], m2[4][4]; + + ::glGetFloatv((GLenum) GL_MODELVIEW_MATRIX, (GLfloat *) &(m1[0][0])); + ::glGetFloatv((GLenum) GL_PROJECTION_MATRIX, (GLfloat *) &(m2[0][0])); + multmatrix4d((GLfloat (*)[4]) vmat, + (const GLfloat (*)[4]) m1, (const GLfloat (*)[4]) m2); +} + +//for object space tesselation: view independent +void +GLUnurbs::setSamplingMatrixIdentity( void ) +{ + INREAL smat[4][4] = { + {1,0,0,0}, + {0,1,0,0}, + {0,0,1,0}, + {0,0,0,1} + }; + const long rstride = sizeof(smat[0]) / sizeof(smat[0][0]); + const long cstride = 1; + + setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride, + cstride); + setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride, + cstride); + setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride, + cstride); + setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride, + cstride); +} + + +void +GLUnurbs::loadSamplingMatrix(const GLfloat vmat[4][4], + const GLint viewport[4]) +{ + + /* rescale the mapping to correspond to pixels in x/y */ + REAL xsize = 0.5 * (REAL) (viewport[2]); + REAL ysize = 0.5 * (REAL) (viewport[3]); + + INREAL smat[4][4]; + smat[0][0] = vmat[0][0] * xsize; + smat[1][0] = vmat[1][0] * xsize; + smat[2][0] = vmat[2][0] * xsize; + smat[3][0] = vmat[3][0] * xsize; + + smat[0][1] = vmat[0][1] * ysize; + smat[1][1] = vmat[1][1] * ysize; + smat[2][1] = vmat[2][1] * ysize; + smat[3][1] = vmat[3][1] * ysize; + + smat[0][2] = 0.0; + smat[1][2] = 0.0; + smat[2][2] = 0.0; + smat[3][2] = 0.0; + + smat[0][3] = vmat[0][3]; + smat[1][3] = vmat[1][3]; + smat[2][3] = vmat[2][3]; + smat[3][3] = vmat[3][3]; + + const long rstride = sizeof(smat[0]) / sizeof(smat[0][0]); + const long cstride = 1; + + setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride, + cstride); + setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride, + cstride); + setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride, + cstride); + setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride, + cstride); +} + +void +GLUnurbs::loadCullingMatrix(GLfloat vmat[4][4]) +{ + INREAL cmat[4][4]; + + cmat[0][0] = vmat[0][0]; + cmat[0][1] = vmat[0][1]; + cmat[0][2] = vmat[0][2]; + cmat[0][3] = vmat[0][3]; + + cmat[1][0] = vmat[1][0]; + cmat[1][1] = vmat[1][1]; + cmat[1][2] = vmat[1][2]; + cmat[1][3] = vmat[1][3]; + + cmat[2][0] = vmat[2][0]; + cmat[2][1] = vmat[2][1]; + cmat[2][2] = vmat[2][2]; + cmat[2][3] = vmat[2][3]; + + cmat[3][0] = vmat[3][0]; + cmat[3][1] = vmat[3][1]; + cmat[3][2] = vmat[3][2]; + cmat[3][3] = vmat[3][3]; + + const long rstride = sizeof(cmat[0]) / sizeof(cmat[0][0]); + const long cstride = 1; + + setnurbsproperty(GL_MAP2_VERTEX_3, N_CULLINGMATRIX, &cmat[0][0], rstride, + cstride); + setnurbsproperty(GL_MAP2_VERTEX_4, N_CULLINGMATRIX, &cmat[0][0], rstride, + cstride); + //added for curves by zl + setnurbsproperty(GL_MAP1_VERTEX_3, N_CULLINGMATRIX, &cmat[0][0], rstride, + cstride); + setnurbsproperty(GL_MAP1_VERTEX_4, N_CULLINGMATRIX, &cmat[0][0], rstride, + cstride); +} + +/*--------------------------------------------------------------------- + * A = B * MAT ; transform a 4d vector through a 4x4 matrix + *--------------------------------------------------------------------- + */ +void +GLUnurbs::transform4d(GLfloat A[4], GLfloat B[4], GLfloat mat[4][4]) +{ + + A[0] = B[0]*mat[0][0] + B[1]*mat[1][0] + B[2]*mat[2][0] + B[3]*mat[3][0]; + A[1] = B[0]*mat[0][1] + B[1]*mat[1][1] + B[2]*mat[2][1] + B[3]*mat[3][1]; + A[2] = B[0]*mat[0][2] + B[1]*mat[1][2] + B[2]*mat[2][2] + B[3]*mat[3][2]; + A[3] = B[0]*mat[0][3] + B[1]*mat[1][3] + B[2]*mat[2][3] + B[3]*mat[3][3]; +} + +/*--------------------------------------------------------------------- + * new = [left][right] ; multiply two matrices together + *--------------------------------------------------------------------- + */ +void +GLUnurbs::multmatrix4d (GLfloat n[4][4], const GLfloat left[4][4], + const GLfloat right[4][4]) +{ + transform4d ((GLfloat *) n[0],(GLfloat *) left[0],(GLfloat (*)[4]) right); + transform4d ((GLfloat *) n[1],(GLfloat *) left[1],(GLfloat (*)[4]) right); + transform4d ((GLfloat *) n[2],(GLfloat *) left[2],(GLfloat (*)[4]) right); + transform4d ((GLfloat *) n[3],(GLfloat *) left[3],(GLfloat (*)[4]) right); +} diff --git a/src/glu/sgi/libnurbs/interface/glrenderer.h b/src/glu/sgi/libnurbs/interface/glrenderer.h new file mode 100644 index 0000000..3b72d44 --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/glrenderer.h @@ -0,0 +1,146 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * glrenderer.h + * + */ + +#ifndef __gluglrenderer_h_ +#define __gluglrenderer_h_ + +#include +#include +#include "nurbstess.h" +#include "glsurfeval.h" +#include "glcurveval.h" + +extern "C" { + typedef void (APIENTRY *errorCallbackType)( GLenum ); +} + +class GLUnurbs : public NurbsTessellator { + +public: + GLUnurbs( void ); + void loadGLMatrices( void ); + void useGLMatrices( const GLfloat modelMatrix[16], + const GLfloat projMatrix[16], + const GLint viewport[4] ); + void setSamplingMatrixIdentity( void ); + + void errorHandler( int ); + void bgnrender( void ); + void endrender( void ); + void setautoloadmode( INREAL value ) + { + + if (value) autoloadmode = GL_TRUE; + else autoloadmode = GL_FALSE; + + } + GLboolean getautoloadmode( void ) { return autoloadmode; } + + errorCallbackType errorCallback; + void postError( int which ) + { if (errorCallback) (errorCallback)( (GLenum)which ); } +#ifdef _WIN32 + void putSurfCallBack(GLenum which, void (GLAPIENTRY *fn)() ) +#else + void putSurfCallBack(GLenum which, _GLUfuncptr fn ) +#endif + { + curveEvaluator.putCallBack(which, fn); + surfaceEvaluator.putCallBack(which, fn); + } + + int get_vertices_call_back() + { + return surfaceEvaluator.get_vertices_call_back(); + } + + void put_vertices_call_back(int flag) + { + surfaceEvaluator.put_vertices_call_back(flag); + } + + int get_callback_auto_normal() + { + return surfaceEvaluator.get_callback_auto_normal(); + } + + void put_callback_auto_normal(int flag) + { + surfaceEvaluator.put_callback_auto_normal(flag); + } + + void setNurbsCallbackData(void* userData) + { + curveEvaluator.set_callback_userData(userData); + surfaceEvaluator.set_callback_userData(userData); + } + + + //for LOD + void LOD_eval_list(int level) + { + surfaceEvaluator.LOD_eval_list(level); + } + + //NEWCALLBACK + int is_callback() + { + return callbackFlag; + } + void put_callbackFlag(int flag) + { + callbackFlag = flag; + surfaceEvaluator.put_vertices_call_back(flag); + curveEvaluator.put_vertices_call_back(flag); + } + +private: + GLboolean autoloadmode; + OpenGLSurfaceEvaluator surfaceEvaluator; + OpenGLCurveEvaluator curveEvaluator; + + void loadSamplingMatrix( const GLfloat vmat[4][4], + const GLint viewport[4] ); + void loadCullingMatrix( GLfloat vmat[4][4] ); + static void grabGLMatrix( GLfloat vmat[4][4] ); + static void transform4d( GLfloat A[4], GLfloat B[4], + GLfloat mat[4][4] ); + static void multmatrix4d( GLfloat n[4][4], const GLfloat left[4][4], + const GLfloat right[4][4] ); + + int callbackFlag; +}; + +#endif /* __gluglrenderer_h_ */ diff --git a/src/glu/sgi/libnurbs/interface/glsurfeval.cc b/src/glu/sgi/libnurbs/interface/glsurfeval.cc new file mode 100644 index 0000000..b5bfab1 --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/glsurfeval.cc @@ -0,0 +1,1293 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * glsurfeval.c++ + * + */ + +/* Polynomial Evaluator Interface */ +#include "gluos.h" +#include +#include "glimports.h" +#include "glrenderer.h" +#include "glsurfeval.h" +#include "nurbsconsts.h" +#include "bezierPatchMesh.h" + + +//extern int surfcount; +//int surfcount=0; + +/*#define USE_INTERNAL_EVAL*/ //use internal evaluator + +/*whether do evaluation or not*/ +/*#define NO_EVALUATION*/ + +//#define USE_LOD //for LOD test, have to turn on USE_LOD in insurfeval.c++ too + +/*for statistics*/ +//#define STATISTICS +#ifdef STATISTICS +static int STAT_num_of_triangles=0; +static int STAT_num_of_eval_vertices=0; +static int STAT_num_of_quad_strips=0; +#endif + +/*for output triangles*/ +/*#define OUTPUT_TRIANGLES*/ + + +/*#define FOR_CHRIS*/ +#ifdef FOR_CHRIS +extern "C" { void evalUStripExt(int n_upper, REAL v_upper, REAL* upper_val, + int n_lower, REAL v_lower, REAL* lower_val);} + +extern "C" { void evalVStripExt(int n_left, REAL u_left, REAL* left_val, + int n_right, REAL u_right, REAL* right_val); + } +#endif + + +/**************begin for LOD_eval_list***********/ +void OpenGLSurfaceEvaluator::LOD_eval_list(int level) +{ + if(level == 0) + LOD_eval_level = 1; + else if(level == 1) + LOD_eval_level = 2; + else if(level == 2) + LOD_eval_level = 4; + else + LOD_eval_level = 8; + + inBPMListEvalEM(global_bpm); +} + + +OpenGLSurfaceEvaluator::OpenGLSurfaceEvaluator() +{ + int i; + + for (i=0; i= n_upper) /*case1: no more in upper*/ + { + if(j= n_lower) /*case2: no more in lower*/ + { + if(i=i; k--) /*reverse order for two-side lighting*/ + { + coord2f(upper_val[k], v_upper); +// glNormal3fv(upperNormal[k]); +// glVertex3fv(upperXYZ[k]); + } + + endtfan(); + } + break; /*exit the main loop*/ + } + else /* case3: neither is empty, plus the leftMostV, there is at least one triangle to output*/ + { + if(upper_val[i] <= lower_val[j]) + { + bgntfan(); + coord2f(lower_val[j], v_lower); +// glNormal3fv(lowerNormal[j]); +// glVertex3fv(lowerXYZ[j]); + + /*find the last k>=i such that + *upperverts[k][0] <= lowerverts[j][0] + */ + k=i; + + while(k lower_val[j]) + break; + k++; + + } + k--; + + + for(l=k; l>=i; l--)/*the reverse is for two-side lighting*/ + { + coord2f(upper_val[l], v_upper); +// glNormal3fv(upperNormal[l]); +// glVertex3fv(upperXYZ[l]); + + } + coord2f(leftMostV[0], leftMostV[1]); +// glNormal3fv(leftMostNormal); +// glVertex3fv(leftMostXYZ); + + endtfan(); + + /*update i and leftMostV for next loop + */ + i = k+1; + + leftMostV[0] = upper_val[k]; + leftMostV[1] = v_upper; +// leftMostNormal = upperNormal[k]; +// leftMostXYZ = upperXYZ[k]; + } + else /*upperVerts[i][0] > lowerVerts[j][0]*/ + { + bgntfan(); + coord2f(upper_val[i], v_upper); +// glNormal3fv(upperNormal[i]); +// glVertex3fv(upperXYZ[i]); + + coord2f(leftMostV[0], leftMostV[1]); +// glNormal3fv(leftMostNormal); +// glVertex3fv(leftMostXYZ); + + + /*find the last k>=j such that + *lowerverts[k][0] < upperverts[i][0] + */ + k=j; + while(k< n_lower) + { + if(lower_val[k] >= upper_val[i]) + break; + coord2f(lower_val[k], v_lower); +// glNormal3fv(lowerNormal[k]); +// glVertex3fv(lowerXYZ[k]); + + k++; + } + endtfan(); + + /*update j and leftMostV for next loop + */ + j=k; + leftMostV[0] = lower_val[j-1]; + leftMostV[1] = v_lower; + +// leftMostNormal = lowerNormal[j-1]; +// leftMostXYZ = lowerXYZ[j-1]; + } + } + } + //clean up +// free(upperXYZ); +// free(lowerXYZ); +// free(upperNormal); +// free(lowerNormal); +#endif + +} + + +void +OpenGLSurfaceEvaluator::evalVStrip(int n_left, REAL u_left, REAL* left_val, int n_right, REAL u_right, REAL* right_val) +{ +#ifdef USE_INTERNAL_EVAL + inEvalVStrip(n_left, u_left, left_val, + n_right, u_right, right_val); +#else + +#ifdef FOR_CHRIS + evalVStripExt(n_left, u_left, left_val, + n_right, u_right, right_val); + return; + +#endif + + int i,j,k,l; + REAL botMostV[2]; + /* + *the algorithm works by scanning from bot to top. + *botMostV: the bot most of the remaining verteces (on both left and right). + * it could an element of leftVerts or rightVerts. + *i: leftVerts[i] is the first vertex to the top of botMostV on left line + *j: rightVerts[j] is the first vertex to the top of botMostV on rightline + */ + + /*initialize i,j,and botMostV + */ + if(left_val[0] <= right_val[0]) + { + i=1; + j=0; + + botMostV[0] = u_left; + botMostV[1] = left_val[0]; + } + else + { + i=0; + j=1; + + botMostV[0] = u_right; + botMostV[1] = right_val[0]; + } + + /*the main loop. + *the invariance is that: + *at the beginning of each loop, the meaning of i,j,and botMostV are + *maintained + */ + while(1) + { + if(i >= n_left) /*case1: no more in left*/ + { + if(j= n_right) /*case2: no more in right*/ + { + if(i=i; k--) /*reverse order for two-side lighting*/ + { + coord2f(u_left, left_val[k]); +// glNormal3fv(leftNormal[k]); +// glVertex3fv(leftXYZ[k]); + } + + endtfan(); + } + break; /*exit the main loop*/ + } + else /* case3: neither is empty, plus the botMostV, there is at least one triangle to output*/ + { + if(left_val[i] <= right_val[j]) + { + bgntfan(); + coord2f(u_right, right_val[j]); +// glNormal3fv(rightNormal[j]); +// glVertex3fv(rightXYZ[j]); + + /*find the last k>=i such that + *leftverts[k][0] <= rightverts[j][0] + */ + k=i; + + while(k right_val[j]) + break; + k++; + + } + k--; + + + for(l=k; l>=i; l--)/*the reverse is for two-side lighting*/ + { + coord2f(u_left, left_val[l]); +// glNormal3fv(leftNormal[l]); +// glVertex3fv(leftXYZ[l]); + + } + coord2f(botMostV[0], botMostV[1]); +// glNormal3fv(botMostNormal); +// glVertex3fv(botMostXYZ); + + endtfan(); + + /*update i and botMostV for next loop + */ + i = k+1; + + botMostV[0] = u_left; + botMostV[1] = left_val[k]; +// botMostNormal = leftNormal[k]; +// botMostXYZ = leftXYZ[k]; + } + else /*left_val[i] > right_val[j])*/ + { + bgntfan(); + coord2f(u_left, left_val[i]); +// glNormal3fv(leftNormal[i]); +// glVertex3fv(leftXYZ[i]); + + coord2f(botMostV[0], botMostV[1]); +// glNormal3fv(botMostNormal); +// glVertex3fv(botMostXYZ); + + + /*find the last k>=j such that + *rightverts[k][0] < leftverts[i][0] + */ + k=j; + while(k< n_right) + { + if(right_val[k] >= left_val[i]) + break; + coord2f(u_right, right_val[k]); +// glNormal3fv(rightNormal[k]); +// glVertex3fv(rightXYZ[k]); + + k++; + } + endtfan(); + + /*update j and botMostV for next loop + */ + j=k; + botMostV[0] = u_right; + botMostV[1] = right_val[j-1]; + +// botMostNormal = rightNormal[j-1]; +// botMostXYZ = rightXYZ[j-1]; + } + } + } + //clean up +// free(leftXYZ); +// free(leftNormal); +// free(rightXYZ); +// free(rightNormal); +#endif +} + + +void +OpenGLSurfaceEvaluator::bgnqstrip(void) +{ + if(output_triangles) + bezierPatchMeshBeginStrip(global_bpm, GL_QUAD_STRIP); + else + glBegin((GLenum) GL_QUAD_STRIP); + +#ifdef STATISTICS + STAT_num_of_quad_strips++; +#endif +} + +void +OpenGLSurfaceEvaluator::endqstrip(void) +{ + if(output_triangles) + bezierPatchMeshEndStrip(global_bpm); + else + glEnd(); + +} + +/*------------------------------------------------------------------------- + * bgnmap2f - preamble to surface definition and evaluations + *------------------------------------------------------------------------- + */ +void +OpenGLSurfaceEvaluator::bgnmap2f(long) +{ + if(output_triangles) + { + /*deallocate the space which may has been + *allocated by global_bpm previously + */ + if(global_bpm != NULL) { + bezierPatchMeshListDelete(global_bpm); + global_bpm = NULL; + } + + + /* + auto_normal_flag = 1; //always output normal in callback mode. + //we could have used the following code, + //but Inspector doesn't have gl context + //before it calls tessellator. + //this way is temporary. + */ + //NEWCALLBACK + //if one of the two normal callback functions are set, + //then set + if(normalCallBackN != NULL || + normalCallBackData != NULL) + auto_normal_flag = 1; + else + auto_normal_flag = 0; + + //initialize so that no maps initially + vertex_flag = 0; + normal_flag = 0; + color_flag = 0; + texcoord_flag = 0; + + /* + if(glIsEnabled(GL_AUTO_NORMAL) == GL_TRUE) + auto_normal_flag = 1; + else if (callback_auto_normal == 1) + auto_normal_flag = 1; + else + auto_normal_flag = 0; + */ + glPushAttrib((GLbitfield) GL_EVAL_BIT); + + } + else + { + glPushAttrib((GLbitfield) GL_EVAL_BIT); + + /*to avoid side effect, we restor the opengl state for GL_POLYGON_MODE + */ + glGetIntegerv(GL_POLYGON_MODE, gl_polygon_mode); + } + +} + +/*------------------------------------------------------------------------- + * endmap2f - postamble to a map + *------------------------------------------------------------------------- + */ +void +OpenGLSurfaceEvaluator::endmap2f(void) +{ + + if(output_triangles) + { + //bezierPatchMeshListDelDeg(global_bpm); + + // bezierPatchMeshListEval(global_bpm); + + //surfcount++; + //printf("surfcount=%i\n", surfcount); + //if(surfcount == 8) exit(0); + + inBPMListEvalEM(global_bpm); + + + +/* + global_bpm = bezierPatchMeshListReverse(global_bpm); + { + float *vertex_array; + float *normal_array; + int *length_array; + int *type_array; + int num_strips; + bezierPatchMeshListCollect(global_bpm, &vertex_array, &normal_array, &length_array, &type_array, &num_strips); + drawStrips(vertex_array, normal_array, length_array, type_array, num_strips); + free(vertex_array); + free(normal_array); + free(length_array); + free(type_array); + } +*/ + + //bezierPatchMeshListPrint(global_bpm); + //bezierPatchMeshListDraw(global_bpm); + +// printf("num triangles=%i\n", bezierPatchMeshListNumTriangles(global_bpm)); + +#ifdef USE_LOD +#else + bezierPatchMeshListDelete(global_bpm); + global_bpm = NULL; +#endif + glPopAttrib(); + } +else + { +#ifndef USE_LOD + glPopAttrib(); +#endif + +#ifdef STATISTICS + fprintf(stderr, "num_vertices=%i,num_triangles=%i,num_quads_strips=%i\n", STAT_num_of_eval_vertices,STAT_num_of_triangles,STAT_num_of_quad_strips); +#endif + + /*to restore the gl_polygon_mode + */ +#ifndef USE_LOD + glPolygonMode( GL_FRONT, (GLenum) gl_polygon_mode[0]); + glPolygonMode( GL_BACK, (GLenum) gl_polygon_mode[1]); +#endif +} + +} + +/*------------------------------------------------------------------------- + * map2f - pass a desription of a surface map + *------------------------------------------------------------------------- + */ +void +OpenGLSurfaceEvaluator::map2f( + long _type, + REAL _ulower, /* u lower domain coord */ + REAL _uupper, /* u upper domain coord */ + long _ustride, /* interpoint distance */ + long _uorder, /* parametric order */ + REAL _vlower, /* v lower domain coord */ + REAL _vupper, /* v upper domain coord */ + long _vstride, /* interpoint distance */ + long _vorder, /* parametric order */ + REAL *pts) /* control points */ +{ +#ifdef USE_INTERNAL_EVAL + inMap2f((int) _type, (REAL) _ulower, (REAL) _uupper, + (int) _ustride, (int) _uorder, (REAL) _vlower, + (REAL) _vupper, (int) _vstride, (int) _vorder, + (REAL *) pts); +#else + + + + if(output_triangles) + { + if(global_bpm == NULL) + global_bpm = bezierPatchMeshMake2(10,10); + if( + (global_bpm->bpatch == NULL && + (_type == GL_MAP2_VERTEX_3 || _type == GL_MAP2_VERTEX_4)) + || + (global_bpm->bpatch_normal == NULL && + (_type == GL_MAP2_NORMAL)) + || + (global_bpm->bpatch_color == NULL && + (_type == GL_MAP2_INDEX || _type == GL_MAP2_COLOR_4)) + || + (global_bpm->bpatch_texcoord == NULL && + (_type == GL_MAP2_TEXTURE_COORD_1 || + _type == GL_MAP2_TEXTURE_COORD_2 || + _type == GL_MAP2_TEXTURE_COORD_3 || + _type == GL_MAP2_TEXTURE_COORD_4 ) + )) + { + bezierPatchMeshPutPatch(global_bpm, (int) _type, _ulower, _uupper,(int) _ustride,(int) _uorder,_vlower, _vupper, (int) _vstride, (int) _vorder, pts); + } + else /*new surface patch (with multiple maps) starts*/ + { + bezierPatchMesh *temp = bezierPatchMeshMake2(10,10); + bezierPatchMeshPutPatch(temp, (int) _type, _ulower, _uupper,(int) _ustride,(int) _uorder,_vlower, _vupper, (int) _vstride, (int) _vorder, pts); + global_bpm = bezierPatchMeshListInsert(global_bpm, temp); + + /* + global_bpm = bezierPatchMeshListInsert(global_bpm, + bezierPatchMeshMake( + (int) _type, _ulower, _uupper,(int) _ustride, (int) _uorder, _vlower, _vupper, (int) _vstride, (int) _vorder, pts, 10, 10)); + */ + } + } + else /*not output triangles*/ + { + glMap2f((GLenum) _type, (GLfloat) _ulower, (GLfloat) _uupper, + (GLint) _ustride, (GLint) _uorder, (GLfloat) _vlower, + (GLfloat) _vupper, (GLint) _vstride, (GLint) _vorder, + (const GLfloat *) pts); + } + +#endif +} + + +/*------------------------------------------------------------------------- + * mapmesh2f - evaluate a mesh of points on lattice + *------------------------------------------------------------------------- + */ +void +OpenGLSurfaceEvaluator::mapmesh2f(long style, long umin, long umax, long vmin, long vmax) +{ +#ifdef NO_EVALUATION +return; +#endif + +#ifdef USE_INTERNAL_EVAL + inEvalMesh2((int)umin, (int)vmin, (int)umax, (int)vmax); +#else + + + +if(output_triangles) +{ +#ifdef USE_LOD + bezierPatchMeshBeginStrip(global_bpm, GL_POLYGON); + bezierPatchMeshInsertUV(global_bpm, global_grid_u0, global_grid_v0); + bezierPatchMeshInsertUV(global_bpm, global_grid_u1, global_grid_v1); + bezierPatchMeshInsertUV(global_bpm, (REAL)global_grid_nu, (REAL)global_grid_nv); + bezierPatchMeshInsertUV(global_bpm, (REAL)umin, (REAL)vmin); + bezierPatchMeshInsertUV(global_bpm, (REAL)umax, (REAL)vmax); + bezierPatchMeshEndStrip(global_bpm); + +#else + + REAL du, dv; + long i,j; + if(global_grid_nu == 0 || global_grid_nv == 0) + return; /*no points need to be output*/ + du = (global_grid_u1 - global_grid_u0) / (REAL)global_grid_nu; + dv = (global_grid_v1 - global_grid_v0) / (REAL)global_grid_nv; + + if(global_grid_nu >= global_grid_nv){ + + for(i=umin; i=vmin; j--){ + REAL v1 = (j == global_grid_nv)? global_grid_v1: (global_grid_v0 +j*dv); + + coord2f(u1, v1); + coord2f(u2, v1); + } + endqstrip(); + } + } + else{ + + for(i=vmin; i=umin; j--){ + REAL u1 = (j == global_grid_nu)? global_grid_u1: (global_grid_u0 +j*du); + coord2f(u1, v2); + coord2f(u1, v1); + } + endqstrip(); + } + } +#endif +} +else +{ + switch(style) { + default: + case N_MESHFILL: + glEvalMesh2((GLenum) GL_FILL, (GLint) umin, (GLint) umax, + (GLint) vmin, (GLint) vmax); + break; + case N_MESHLINE: + glEvalMesh2((GLenum) GL_LINE, (GLint) umin, (GLint) umax, + (GLint) vmin, (GLint) vmax); + break; + case N_MESHPOINT: + glEvalMesh2((GLenum) GL_POINT, (GLint) umin, (GLint) umax, + (GLint) vmin, (GLint) vmax); + break; + } + } + +#endif + +#ifdef STATISTICS + STAT_num_of_quad_strips += (umax-umin)*(vmax-vmin); +#endif +} + +/*------------------------------------------------------------------------- + * evalcoord2f - evaluate a point on a surface + *------------------------------------------------------------------------- + */ +void +OpenGLSurfaceEvaluator::evalcoord2f(long, REAL u, REAL v) +{ + + +#ifdef NO_EVALUATION +return; +#endif + + + newtmeshvert(u, v); +} + +/*------------------------------------------------------------------------- + * evalpoint2i - evaluate a grid point + *------------------------------------------------------------------------- + */ +void +OpenGLSurfaceEvaluator::evalpoint2i(long u, long v) +{ +#ifdef NO_EVALUATION +return; +#endif + + newtmeshvert(u, v); +} + +void +OpenGLSurfaceEvaluator::point2i( long u, long v ) +{ +#ifdef NO_EVALUATION +return; +#else + +#ifdef USE_INTERNAL_EVAL + inEvalPoint2( (int)u, (int)v); +#else + + +if(output_triangles) +{ + + REAL du, dv; + REAL fu,fv; + du = (global_grid_u1 - global_grid_u0) / (REAL)global_grid_nu; + dv = (global_grid_v1 - global_grid_v0) / (REAL)global_grid_nv; + fu = (u==global_grid_nu)? global_grid_u1:(global_grid_u0 + u*du); + fv = (v == global_grid_nv)? global_grid_v1: (global_grid_v0 +v*dv); + coord2f(fu,fv); +} +else + glEvalPoint2((GLint) u, (GLint) v); + + +#endif + +#ifdef STATISTICS + STAT_num_of_eval_vertices++; +#endif + +#endif + +} + +void +OpenGLSurfaceEvaluator::coord2f( REAL u, REAL v ) +{ +#ifdef NO_EVALUATION +return; +#else + +#ifdef USE_INTERNAL_EVAL + inEvalCoord2f( u, v); +#else + + +if(output_triangles) + bezierPatchMeshInsertUV(global_bpm, u,v); +else + glEvalCoord2f((GLfloat) u, (GLfloat) v); + + +#endif + + +#ifdef STATISTICS + STAT_num_of_eval_vertices++; +#endif + +#endif +} + +void +OpenGLSurfaceEvaluator::newtmeshvert( long u, long v ) +{ +#ifdef NO_EVALUATION +return; +#else + + if (tmeshing) { + + if (vcount == 2) { + vertexCache[0]->invoke(this); + vertexCache[1]->invoke(this); + point2i( u, v); + + } else { + vcount++; + } + + vertexCache[which]->saveEvalPoint(u, v); + which = 1 - which; + } else { + point2i( u, v); + } +#endif +} + +void +OpenGLSurfaceEvaluator::newtmeshvert( REAL u, REAL v ) +{ +#ifdef NO_EVALUATION +return; +#else + if (tmeshing) { + + + if (vcount == 2) { + vertexCache[0]->invoke(this); + vertexCache[1]->invoke(this); + coord2f(u,v); + + } else { + vcount++; + } + + vertexCache[which]->saveEvalCoord(u, v); + which = 1 - which; + } else { + + coord2f( u, v); + } +#endif + +} + +#ifdef _WIN32 +void OpenGLSurfaceEvaluator::putCallBack(GLenum which, void (GLAPIENTRY *fn)() ) +#else +void OpenGLSurfaceEvaluator::putCallBack(GLenum which, _GLUfuncptr fn ) +#endif +{ + switch(which) + { + case GLU_NURBS_BEGIN: + beginCallBackN = (void (GLAPIENTRY *) (GLenum)) fn; + break; + case GLU_NURBS_END: + endCallBackN = (void (GLAPIENTRY *) (void)) fn; + break; + case GLU_NURBS_VERTEX: + vertexCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn; + break; + case GLU_NURBS_NORMAL: + normalCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn; + break; + case GLU_NURBS_COLOR: + colorCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn; + break; + case GLU_NURBS_TEXTURE_COORD: + texcoordCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn; + break; + case GLU_NURBS_BEGIN_DATA: + beginCallBackData = (void (GLAPIENTRY *) (GLenum, void*)) fn; + break; + case GLU_NURBS_END_DATA: + endCallBackData = (void (GLAPIENTRY *) (void*)) fn; + break; + case GLU_NURBS_VERTEX_DATA: + vertexCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn; + break; + case GLU_NURBS_NORMAL_DATA: + normalCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn; + break; + case GLU_NURBS_COLOR_DATA: + colorCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn; + break; + case GLU_NURBS_TEXTURE_COORD_DATA: + texcoordCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn; + break; + + } +} + + +void +OpenGLSurfaceEvaluator::beginCallBack(GLenum which, void *data) +{ + if(beginCallBackData) + beginCallBackData(which, data); + else if(beginCallBackN) + beginCallBackN(which); +} + +void +OpenGLSurfaceEvaluator::endCallBack(void *data) +{ + if(endCallBackData) + endCallBackData(data); + else if(endCallBackN) + endCallBackN(); +} + +void +OpenGLSurfaceEvaluator::vertexCallBack(const GLfloat *vert, void* data) +{ + if(vertexCallBackData) + vertexCallBackData(vert, data); + else if(vertexCallBackN) + vertexCallBackN(vert); +} + + +void +OpenGLSurfaceEvaluator::normalCallBack(const GLfloat *normal, void* data) +{ + if(normalCallBackData) + normalCallBackData(normal, data); + else if(normalCallBackN) + normalCallBackN(normal); +} + +void +OpenGLSurfaceEvaluator::colorCallBack(const GLfloat *color, void* data) +{ + if(colorCallBackData) + colorCallBackData(color, data); + else if(colorCallBackN) + colorCallBackN(color); +} + +void +OpenGLSurfaceEvaluator::texcoordCallBack(const GLfloat *texcoord, void* data) +{ + if(texcoordCallBackData) + texcoordCallBackData(texcoord, data); + else if(texcoordCallBackN) + texcoordCallBackN(texcoord); +} + + + + diff --git a/src/glu/sgi/libnurbs/interface/glsurfeval.h b/src/glu/sgi/libnurbs/interface/glsurfeval.h new file mode 100644 index 0000000..621e593 --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/glsurfeval.h @@ -0,0 +1,404 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * glsurfeval.h + * + */ + +#ifndef __gluglsurfeval_h_ +#define __gluglsurfeval_h_ + +#include "basicsurfeval.h" +#include "bezierPatchMesh.h" //in case output triangles +#include +#include + +class SurfaceMap; +class OpenGLSurfaceEvaluator; +class StoredVertex; + +#define TYPECOORD 1 +#define TYPEPOINT 2 + +/* Cache up to 3 vertices from tmeshes */ +#define VERTEX_CACHE_SIZE 3 + +/*for internal evaluator callback stuff*/ +#ifndef IN_MAX_BEZIER_ORDER +#define IN_MAX_BEZIER_ORDER 40 /*XXX should be bigger than machine order*/ +#endif + +#ifndef IN_MAX_DIMENSION +#define IN_MAX_DIMENSION 4 +#endif + +typedef struct surfEvalMachine{ + REAL uprime;//cached previusly evaluated uprime. + REAL vprime; + int k; /*the dimension*/ + REAL u1; + REAL u2; + int ustride; + int uorder; + REAL v1; + REAL v2; + int vstride; + int vorder; + REAL ctlPoints[IN_MAX_BEZIER_ORDER*IN_MAX_BEZIER_ORDER*IN_MAX_DIMENSION]; + REAL ucoeff[IN_MAX_BEZIER_ORDER]; /*cache the polynomial values*/ + REAL vcoeff[IN_MAX_BEZIER_ORDER]; + REAL ucoeffDeriv[IN_MAX_BEZIER_ORDER]; /*cache the polynomial derivatives*/ + REAL vcoeffDeriv[IN_MAX_BEZIER_ORDER]; +} surfEvalMachine; + + + +class StoredVertex { +public: + StoredVertex() { type = 0; coord[0] = 0; coord[1] = 0; point[0] = 0; point[1] = 0; } + ~StoredVertex(void) {} + void saveEvalCoord(REAL x, REAL y) + {coord[0] = x; coord[1] = y; type = TYPECOORD; } + void saveEvalPoint(long x, long y) + {point[0] = x; point[1] = y; type = TYPEPOINT; } + void invoke(OpenGLSurfaceEvaluator *eval); + +private: + int type; + REAL coord[2]; + long point[2]; +}; + +class OpenGLSurfaceEvaluator : public BasicSurfaceEvaluator { +public: + OpenGLSurfaceEvaluator(); + virtual ~OpenGLSurfaceEvaluator( void ); + void polymode( long style ); + void range2f( long, REAL *, REAL * ); + void domain2f( REAL, REAL, REAL, REAL ); + void addMap( SurfaceMap * ) { } + + void enable( long ); + void disable( long ); + void bgnmap2f( long ); + void map2f( long, REAL, REAL, long, long, + REAL, REAL, long, long, REAL * ); + void mapgrid2f( long, REAL, REAL, long, REAL, REAL ); + void mapmesh2f( long, long, long, long, long ); + void evalcoord2f( long, REAL, REAL ); + void evalpoint2i( long, long ); + void endmap2f( void ); + + void bgnline( void ); + void endline( void ); + void bgnclosedline( void ); + void endclosedline( void ); + void bgntmesh( void ); + void swaptmesh( void ); + void endtmesh( void ); + void bgnqstrip( void ); + void endqstrip( void ); + + void bgntfan( void ); + void endtfan( void ); + void evalUStrip(int n_upper, REAL v_upper, REAL* upper_val, + int n_lower, REAL v_lower, REAL* lower_val); + void evalVStrip(int n_left, REAL u_left, REAL* left_val, + int n_right, REAL u_right, REAL* right_val); + + void coord2f( REAL, REAL ); + void point2i( long, long ); + + void newtmeshvert( REAL, REAL ); + void newtmeshvert( long, long ); + +#ifdef _WIN32 + void putCallBack(GLenum which, void (GLAPIENTRY *fn)() ); +#else + void putCallBack(GLenum which, _GLUfuncptr fn ); +#endif + + int get_vertices_call_back() + { + return output_triangles; + } + void put_vertices_call_back(int flag) + { + output_triangles = flag; + } + + void put_callback_auto_normal(int flag) + { + callback_auto_normal = flag; + } + + int get_callback_auto_normal() + { + return callback_auto_normal; + } + + void set_callback_userData(void* data) + { + userData = data; + } + + /**************begin for LOD_eval_list***********/ + void LOD_eval_list(int level); + + + + +private: + StoredVertex *vertexCache[VERTEX_CACHE_SIZE]; + int tmeshing; + int which; + int vcount; + + GLint gl_polygon_mode[2];/*to save and restore so that + *no side effect + */ + bezierPatchMesh *global_bpm; //for output triangles + int output_triangles; //true 1 or false 0 + + + + void (GLAPIENTRY *beginCallBackN) (GLenum type); + void (GLAPIENTRY *endCallBackN) (void); + void (GLAPIENTRY *vertexCallBackN) (const GLfloat *vert); + void (GLAPIENTRY *normalCallBackN) (const GLfloat *normal); + void (GLAPIENTRY *colorCallBackN) (const GLfloat *color); + void (GLAPIENTRY *texcoordCallBackN) (const GLfloat *texcoord); + + void (GLAPIENTRY *beginCallBackData) (GLenum type, void* data); + void (GLAPIENTRY *endCallBackData) (void* data); + void (GLAPIENTRY *vertexCallBackData) (const GLfloat *vert, void* data); + void (GLAPIENTRY *normalCallBackData) (const GLfloat *normal, void* data); + void (GLAPIENTRY *colorCallBackData) (const GLfloat *color, void* data); + void (GLAPIENTRY *texcoordCallBackData) (const GLfloat *texcoord, void* data); + + void beginCallBack (GLenum type, void* data); + void endCallBack (void* data); + void vertexCallBack (const GLfloat *vert, void* data); + void normalCallBack (const GLfloat *normal, void* data); + void colorCallBack (const GLfloat *color, void* data); + void texcoordCallBack (const GLfloat *texcoord, void* data); + + + void* userData; //the opaque pointer for Data callback functions. + + /*LOD evaluation*/ + void LOD_triangle(REAL A[2], REAL B[2], REAL C[2], + int level); + void LOD_eval(int num_vert, REAL* verts, int type, int level); + + int LOD_eval_level; //set by LOD_eval_list() + + /*************begin for internal evaluators*****************/ + + /*the following global variables are only defined in this file. + *They are used to cache the precomputed Bezier polynomial values. + *These calues may be used consecutively in which case we don't have + *recompute these values again. + */ + int global_uorder; /*store the uorder in the previous evaluation*/ + int global_vorder; /*store the vorder in the previous evaluation*/ + REAL global_uprime; + REAL global_vprime; + REAL global_vprime_BV; + REAL global_uprime_BU; + int global_uorder_BV; /*store the uorder in the previous evaluation*/ + int global_vorder_BV; /*store the vorder in the previous evaluation*/ + int global_uorder_BU; /*store the uorder in the previous evaluation*/ + int global_vorder_BU; /*store the vorder in the previous evaluation*/ + + REAL global_ucoeff[IN_MAX_BEZIER_ORDER]; /*cache the polynomial values*/ + REAL global_vcoeff[IN_MAX_BEZIER_ORDER]; + REAL global_ucoeffDeriv[IN_MAX_BEZIER_ORDER]; /*cache the polynomial derivatives*/ + REAL global_vcoeffDeriv[IN_MAX_BEZIER_ORDER]; + + REAL global_BV[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION]; + REAL global_PBV[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION]; + REAL global_BU[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION]; + REAL global_PBU[IN_MAX_BEZIER_ORDER][IN_MAX_DIMENSION]; + REAL* global_baseData; + + int global_ev_k; /*the dimension*/ + REAL global_ev_u1; + REAL global_ev_u2; + int global_ev_ustride; + int global_ev_uorder; + REAL global_ev_v1; + REAL global_ev_v2; + int global_ev_vstride; + int global_ev_vorder; + REAL global_ev_ctlPoints[IN_MAX_BEZIER_ORDER*IN_MAX_BEZIER_ORDER*IN_MAX_DIMENSION]; + + REAL global_grid_u0; + REAL global_grid_u1; + int global_grid_nu; + REAL global_grid_v0; + REAL global_grid_v1; + int global_grid_nv; + +/*functions*/ + void inDoDomain2WithDerivs(int k, REAL u, REAL v, + REAL u1, REAL u2, int uorder, + REAL v1, REAL v2, int vorder, + REAL *baseData, + REAL *retPoint, REAL *retdu, REAL *retdv); + void inPreEvaluate(int order, REAL vprime, REAL *coeff); + void inPreEvaluateWithDeriv(int order, REAL vprime, REAL *coeff, REAL *coeffDeriv); + void inComputeFirstPartials(REAL *p, REAL *pu, REAL *pv); + void inComputeNormal2(REAL *pu, REAL *pv, REAL *n); + void inDoEvalCoord2(REAL u, REAL v, + REAL *retPoint, REAL *retNormal); + void inDoEvalCoord2NOGE(REAL u, REAL v, + REAL *retPoint, REAL *retNormal); + void inMap2f(int k, + REAL ulower, + REAL uupper, + int ustride, + int uorder, + REAL vlower, + REAL vupper, + int vstride, + int vorder, + REAL *ctlPoints); + + void inMapGrid2f(int nu, REAL u0, REAL u1, + int nv, REAL v0, REAL v1); + + void inEvalMesh2(int lowU, int lowV, int highU, int highV); + void inEvalPoint2(int i, int j); + void inEvalCoord2f(REAL u, REAL v); + +void inEvalULine(int n_points, REAL v, REAL* u_vals, + int stride, REAL ret_points[][3], REAL ret_normals[][3]); + +void inEvalVLine(int n_points, REAL u, REAL* v_vals, + int stride, REAL ret_points[][3], REAL ret_normals[][3]); + +void inEvalUStrip(int n_upper, REAL v_upper, REAL* upper_val, + int n_lower, REAL v_lower, REAL* lower_val + ); +void inEvalVStrip(int n_left, REAL u_left, REAL* left_val, int n_right, REAL u_right, REAL* right_val); + +void inPreEvaluateBV(int k, int uorder, int vorder, REAL vprime, REAL *baseData); +void inPreEvaluateBU(int k, int uorder, int vorder, REAL uprime, REAL *baseData); +void inPreEvaluateBV_intfac(REAL v ) + { + inPreEvaluateBV(global_ev_k, global_ev_uorder, global_ev_vorder, (v-global_ev_v1)/(global_ev_v2-global_ev_v1), global_ev_ctlPoints); + } + +void inPreEvaluateBU_intfac(REAL u) + { + inPreEvaluateBU(global_ev_k, global_ev_uorder, global_ev_vorder, (u-global_ev_u1)/(global_ev_u2-global_ev_u1), global_ev_ctlPoints); + } + +void inDoDomain2WithDerivsBV(int k, REAL u, REAL v, + REAL u1, REAL u2, int uorder, + REAL v1, REAL v2, int vorder, + REAL *baseData, + REAL *retPoint, REAL* retdu, REAL *retdv); + +void inDoDomain2WithDerivsBU(int k, REAL u, REAL v, + REAL u1, REAL u2, int uorder, + REAL v1, REAL v2, int vorder, + REAL *baseData, + REAL *retPoint, REAL* retdu, REAL *retdv); + + +void inDoEvalCoord2NOGE_BV(REAL u, REAL v, + REAL *retPoint, REAL *retNormal); + +void inDoEvalCoord2NOGE_BU(REAL u, REAL v, + REAL *retPoint, REAL *retNormal); + +void inBPMEval(bezierPatchMesh* bpm); +void inBPMListEval(bezierPatchMesh* list); + +/*-------------begin for surfEvalMachine -------------*/ +surfEvalMachine em_vertex; +surfEvalMachine em_normal; +surfEvalMachine em_color; +surfEvalMachine em_texcoord; + +int auto_normal_flag; //whether to output normla or not in callback + //determined by GL_AUTO_NORMAL and callback_auto_normal +int callback_auto_normal; //GLU_CALLBACK_AUTO_NORMAL_EXT +int vertex_flag; +int normal_flag; +int color_flag; +int texcoord_flag; + +void inMap2fEM(int which, //0:vert,1:norm,2:color,3:tex + int dimension, + REAL ulower, + REAL uupper, + int ustride, + int uorder, + REAL vlower, + REAL vupper, + int vstride, + int vorder, + REAL *ctlPoints); + +void inDoDomain2WithDerivsEM(surfEvalMachine *em, REAL u, REAL v, + REAL *retPoint, REAL *retdu, REAL *retdv); +void inDoDomain2EM(surfEvalMachine *em, REAL u, REAL v, + REAL *retPoint); + void inDoEvalCoord2EM(REAL u, REAL v); + +void inBPMEvalEM(bezierPatchMesh* bpm); +void inBPMListEvalEM(bezierPatchMesh* list); + +/*-------------end for surfEvalMachine -------------*/ + + + /*************end for internal evaluators*****************/ + +}; + +inline void StoredVertex::invoke(OpenGLSurfaceEvaluator *eval) +{ + switch(type) { + case TYPECOORD: + eval->coord2f(coord[0], coord[1]); + break; + case TYPEPOINT: + eval->point2i(point[0], point[1]); + break; + default: + break; + } +} + +#endif /* __gluglsurfeval_h_ */ diff --git a/src/glu/sgi/libnurbs/interface/incurveeval.cc b/src/glu/sgi/libnurbs/interface/incurveeval.cc new file mode 100644 index 0000000..96ea889 --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/incurveeval.cc @@ -0,0 +1,206 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include + +#include "glcurveval.h" + + +/* + *compute the Bezier polynomials C[n,j](v) for all j at v with + *return values stored in coeff[], where + * C[n,j](v) = (n,j) * v^j * (1-v)^(n-j), + * j=0,1,2,...,n. + *order : n+1 + *vprime: v + *coeff : coeff[j]=C[n,j](v), this array store the returned values. + *The algorithm is a recursive scheme: + * C[0,0]=1; + * C[n,j](v) = (1-v)*C[n-1,j](v) + v*C[n-1,j-1](v), n>=1 + *This code is copied from opengl/soft/so_eval.c:PreEvaluate + */ +void OpenGLCurveEvaluator::inPreEvaluate(int order, REAL vprime, REAL *coeff) +{ + int i, j; + REAL oldval, temp; + REAL oneMinusvprime; + + /* + * Minor optimization + * Compute orders 1 and 2 outright, and set coeff[0], coeff[1] to + * their i==1 loop values to avoid the initialization and the i==1 loop. + */ + if (order == 1) { + coeff[0] = 1.0; + return; + } + + oneMinusvprime = 1-vprime; + coeff[0] = oneMinusvprime; + coeff[1] = vprime; + if (order == 2) return; + + for (i = 2; i < order; i++) { + oldval = coeff[0] * vprime; + coeff[0] = oneMinusvprime * coeff[0]; + for (j = 1; j < i; j++) { + temp = oldval; + oldval = coeff[j] * vprime; + coeff[j] = temp + oneMinusvprime * coeff[j]; + } + coeff[j] = oldval; + } +} + +void OpenGLCurveEvaluator::inMap1f(int which, //0: vert, 1: norm, 2: color, 3: tex + int k, //dimension + REAL ulower, + REAL uupper, + int ustride, + int uorder, + REAL *ctlpoints) +{ + int i,x; + curveEvalMachine *temp_em; + switch(which){ + case 0: //vertex + vertex_flag = 1; + temp_em = &em_vertex; + break; + case 1: //normal + normal_flag = 1; + temp_em = &em_normal; + break; + case 2: //color + color_flag = 1; + temp_em = &em_color; + break; + default: + texcoord_flag = 1; + temp_em = &em_texcoord; + break; + } + + REAL *data = temp_em->ctlpoints; + temp_em->uprime = -1; //initialized + temp_em->k = k; + temp_em->u1 = ulower; + temp_em->u2 = uupper; + temp_em->ustride = ustride; + temp_em->uorder = uorder; + /*copy the control points*/ + for(i=0; iu2 == em->u1) + return; + the_uprime = (u-em->u1) / (em->u2-em->u1); + /*use already cached values if possible*/ + if(em->uprime != the_uprime){ + inPreEvaluate(em->uorder, the_uprime, em->ucoeff); + em->uprime = the_uprime; + } + + for(j=0; jk; j++){ + data = em->ctlpoints+j; + retPoint[j] = 0.0; + for(row=0; rowuorder; row++) + { + retPoint[j] += em->ucoeff[row] * (*data); + data += em->k; + } + } +} + +void OpenGLCurveEvaluator::inDoEvalCoord1(REAL u) +{ + REAL temp_vertex[4]; + REAL temp_normal[3]; + REAL temp_color[4]; + REAL temp_texcoord[4]; + if(texcoord_flag) //there is a texture map + { + inDoDomain1(&em_texcoord, u, temp_texcoord); + texcoordCallBack(temp_texcoord, userData); + } +#ifdef DEBUG +printf("color_flag = %i\n", color_flag); +#endif + if(color_flag) //there is a color map + { + inDoDomain1(&em_color, u, temp_color); + colorCallBack(temp_color, userData); + } + if(normal_flag) //there is a normal map + { + inDoDomain1(&em_normal, u, temp_normal); + normalCallBack(temp_normal, userData); + } + if(vertex_flag) + { + inDoDomain1(&em_vertex, u, temp_vertex); + vertexCallBack(temp_vertex, userData); + } +} + +void OpenGLCurveEvaluator::inMapMesh1f(int umin, int umax) +{ + REAL du, u; + int i; + if(global_grid_nu == 0) + return; //no points to output + du = (global_grid_u1 - global_grid_u0) / (REAL) global_grid_nu; + bgnline(); + for(i=umin; i<= umax; i++){ + u = (i==global_grid_nu)? global_grid_u1: global_grid_u0 + i*du; + inDoEvalCoord1(u); + } + endline(); +} diff --git a/src/glu/sgi/libnurbs/interface/insurfeval.cc b/src/glu/sgi/libnurbs/interface/insurfeval.cc new file mode 100644 index 0000000..9d0c82a --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/insurfeval.cc @@ -0,0 +1,2064 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include "gluos.h" +#include +#include +#include +#include +#include + +#include "glsurfeval.h" + +//extern int surfcount; + +//#define CRACK_TEST + +#define AVOID_ZERO_NORMAL + +#ifdef AVOID_ZERO_NORMAL +#define myabs(x) ((x>0)? x: (-x)) +#define MYZERO 0.000001 +#define MYDELTA 0.001 +#endif + +//#define USE_LOD +#ifdef USE_LOD +//#define LOD_EVAL_COORD(u,v) inDoEvalCoord2EM(u,v) +#define LOD_EVAL_COORD(u,v) glEvalCoord2f(u,v) + +static void LOD_interpolate(REAL A[2], REAL B[2], REAL C[2], int j, int k, int pow2_level, + REAL& u, REAL& v) +{ + REAL a,a1,b,b1; + + a = ((REAL) j) / ((REAL) pow2_level); + a1 = 1-a; + + if(j != 0) + { + b = ((REAL) k) / ((REAL)j); + b1 = 1-b; + } + REAL x,y,z; + x = a1; + if(j==0) + { + y=0; z=0; + } + else{ + y = b1*a; + z = b *a; + } + + u = x*A[0] + y*B[0] + z*C[0]; + v = x*A[1] + y*B[1] + z*C[1]; +} + +void OpenGLSurfaceEvaluator::LOD_triangle(REAL A[2], REAL B[2], REAL C[2], + int level) +{ + int k,j; + int pow2_level; + /*compute 2^level*/ + pow2_level = 1; + + for(j=0; jnext) + { + inBPMEval(temp); + } +} + +void OpenGLSurfaceEvaluator::inBPMEval(bezierPatchMesh* bpm) +{ + int i,j,k,l; + float u,v; + + int ustride = bpm->bpatch->dimension * bpm->bpatch->vorder; + int vstride = bpm->bpatch->dimension; + inMap2f( + (bpm->bpatch->dimension == 3)? GL_MAP2_VERTEX_3 : GL_MAP2_VERTEX_4, + bpm->bpatch->umin, + bpm->bpatch->umax, + ustride, + bpm->bpatch->uorder, + bpm->bpatch->vmin, + bpm->bpatch->vmax, + vstride, + bpm->bpatch->vorder, + bpm->bpatch->ctlpoints); + + bpm->vertex_array = (float*) malloc(sizeof(float)* (bpm->index_UVarray/2) * 3+1); /*in case the origional dimenion is 4, then we need 4 space to pass to evaluator.*/ + assert(bpm->vertex_array); + bpm->normal_array = (float*) malloc(sizeof(float)* (bpm->index_UVarray/2) * 3); + assert(bpm->normal_array); +#ifdef CRACK_TEST +if( global_ev_u1 ==2 && global_ev_u2 == 3 + && global_ev_v1 ==2 && global_ev_v2 == 3) +{ +REAL vertex[4]; +REAL normal[4]; +#ifdef DEBUG +printf("***number 1\n"); +#endif + +beginCallBack(GL_QUAD_STRIP, NULL); +inEvalCoord2f(3.0, 3.0); +inEvalCoord2f(2.0, 3.0); +inEvalCoord2f(3.0, 2.7); +inEvalCoord2f(2.0, 2.7); +inEvalCoord2f(3.0, 2.0); +inEvalCoord2f(2.0, 2.0); +endCallBack(NULL); + + +beginCallBack(GL_TRIANGLE_STRIP, NULL); +inEvalCoord2f(2.0, 3.0); +inEvalCoord2f(2.0, 2.0); +inEvalCoord2f(2.0, 2.7); +endCallBack(NULL); + +} + +/* +if( global_ev_u1 ==2 && global_ev_u2 == 3 + && global_ev_v1 ==1 && global_ev_v2 == 2) +{ +#ifdef DEBUG +printf("***number 2\n"); +#endif +beginCallBack(GL_QUAD_STRIP); +inEvalCoord2f(2.0, 2.0); +inEvalCoord2f(2.0, 1.0); +inEvalCoord2f(3.0, 2.0); +inEvalCoord2f(3.0, 1.0); +endCallBack(); +} +*/ +if( global_ev_u1 ==1 && global_ev_u2 == 2 + && global_ev_v1 ==2 && global_ev_v2 == 3) +{ +#ifdef DEBUG +printf("***number 3\n"); +#endif +beginCallBack(GL_QUAD_STRIP, NULL); +inEvalCoord2f(2.0, 3.0); +inEvalCoord2f(1.0, 3.0); +inEvalCoord2f(2.0, 2.3); +inEvalCoord2f(1.0, 2.3); +inEvalCoord2f(2.0, 2.0); +inEvalCoord2f(1.0, 2.0); +endCallBack(NULL); + +beginCallBack(GL_TRIANGLE_STRIP, NULL); +inEvalCoord2f(2.0, 2.3); +inEvalCoord2f(2.0, 2.0); +inEvalCoord2f(2.0, 3.0); +endCallBack(NULL); + +} +return; +#endif + + k=0; + l=0; + + for(i=0; iindex_length_array; i++) + { + beginCallBack(bpm->type_array[i], userData); + for(j=0; jlength_array[i]; j++) + { + u = bpm->UVarray[k]; + v = bpm->UVarray[k+1]; + inDoEvalCoord2NOGE(u,v, + bpm->vertex_array+l, + bpm->normal_array+l); + + normalCallBack(bpm->normal_array+l, userData); + vertexCallBack(bpm->vertex_array+l, userData); + + k += 2; + l += 3; + } + endCallBack(userData); + } +} + +void OpenGLSurfaceEvaluator::inEvalPoint2(int i, int j) +{ + REAL du, dv; + REAL point[4]; + REAL normal[3]; + REAL u,v; + du = (global_grid_u1 - global_grid_u0) / (REAL)global_grid_nu; + dv = (global_grid_v1 - global_grid_v0) / (REAL)global_grid_nv; + u = (i==global_grid_nu)? global_grid_u1:(global_grid_u0 + i*du); + v = (j == global_grid_nv)? global_grid_v1: (global_grid_v0 +j*dv); + inDoEvalCoord2(u,v,point,normal); +} + +void OpenGLSurfaceEvaluator::inEvalCoord2f(REAL u, REAL v) +{ + + REAL point[4]; + REAL normal[3]; + inDoEvalCoord2(u,v,point, normal); +} + + + +/*define a grid. store the values into the global variabls: + * global_grid_* + *These values will be used later by evaluating functions + */ +void OpenGLSurfaceEvaluator::inMapGrid2f(int nu, REAL u0, REAL u1, + int nv, REAL v0, REAL v1) +{ + global_grid_u0 = u0; + global_grid_u1 = u1; + global_grid_nu = nu; + global_grid_v0 = v0; + global_grid_v1 = v1; + global_grid_nv = nv; +} + +void OpenGLSurfaceEvaluator::inEvalMesh2(int lowU, int lowV, int highU, int highV) +{ + REAL du, dv; + int i,j; + REAL point[4]; + REAL normal[3]; + if(global_grid_nu == 0 || global_grid_nv == 0) + return; /*no points need to be output*/ + du = (global_grid_u1 - global_grid_u0) / (REAL)global_grid_nu; + dv = (global_grid_v1 - global_grid_v0) / (REAL)global_grid_nv; + + if(global_grid_nu >= global_grid_nv){ + for(i=lowU; i=lowV; j--){ + REAL v1 = (j == global_grid_nv)? global_grid_v1: (global_grid_v0 +j*dv); + + inDoEvalCoord2(u1, v1, point, normal); + inDoEvalCoord2(u2, v1, point, normal); + } + endqstrip(); + } + } + + else{ + for(i=lowV; i=lowU; j--){ + REAL u1 = (j == global_grid_nu)? global_grid_u1: (global_grid_u0 +j*du); + inDoEvalCoord2(u1, v2, point, normal); + inDoEvalCoord2(u1, v1, point, normal); + } + endqstrip(); + } + } + +} + +void OpenGLSurfaceEvaluator::inMap2f(int k, + REAL ulower, + REAL uupper, + int ustride, + int uorder, + REAL vlower, + REAL vupper, + int vstride, + int vorder, + REAL *ctlPoints) +{ + int i,j,x; + REAL *data = global_ev_ctlPoints; + + + + if(k == GL_MAP2_VERTEX_3) k=3; + else if (k==GL_MAP2_VERTEX_4) k =4; + else { + printf("error in inMap2f, maptype=%i is wrong, k,map is not updated\n", k); + return; + } + + global_ev_k = k; + global_ev_u1 = ulower; + global_ev_u2 = uupper; + global_ev_ustride = ustride; + global_ev_uorder = uorder; + global_ev_v1 = vlower; + global_ev_v2 = vupper; + global_ev_vstride = vstride; + global_ev_vorder = vorder; + + /*copy the contrl points from ctlPoints to global_ev_ctlPoints*/ + for (i=0; i 0.0) { + n[0] /= mag; + n[1] /= mag; + n[2] /= mag; + } +} + + + +/*Compute point and normal + *see the head of inDoDomain2WithDerivs + *for the meaning of the arguments + */ +void OpenGLSurfaceEvaluator::inDoEvalCoord2(REAL u, REAL v, + REAL *retPoint, REAL *retNormal) +{ + + REAL du[4]; + REAL dv[4]; + + + assert(global_ev_k>=3 && global_ev_k <= 4); + /*compute homegeneous point and partial derivatives*/ + inDoDomain2WithDerivs(global_ev_k, u, v, global_ev_u1, global_ev_u2, global_ev_uorder, global_ev_v1, global_ev_v2, global_ev_vorder, global_ev_ctlPoints, retPoint, du, dv); + +#ifdef AVOID_ZERO_NORMAL + + if(myabs(dv[0]) <= MYZERO && myabs(dv[1]) <= MYZERO && myabs(dv[2]) <= MYZERO) + { + + REAL tempdu[4]; + REAL tempdata[4]; + REAL u1 = global_ev_u1; + REAL u2 = global_ev_u2; + if(u-MYDELTA*(u2-u1) < u1) + u = u+ MYDELTA*(u2-u1); + else + u = u-MYDELTA*(u2-u1); + inDoDomain2WithDerivs(global_ev_k, u,v,global_ev_u1, global_ev_u2, global_ev_uorder, global_ev_v1, global_ev_v2, global_ev_vorder, global_ev_ctlPoints, tempdata, tempdu, dv); + } + if(myabs(du[0]) <= MYZERO && myabs(du[1]) <= MYZERO && myabs(du[2]) <= MYZERO) + { + REAL tempdv[4]; + REAL tempdata[4]; + REAL v1 = global_ev_v1; + REAL v2 = global_ev_v2; + if(v-MYDELTA*(v2-v1) < v1) + v = v+ MYDELTA*(v2-v1); + else + v = v-MYDELTA*(v2-v1); + inDoDomain2WithDerivs(global_ev_k, u,v,global_ev_u1, global_ev_u2, global_ev_uorder, global_ev_v1, global_ev_v2, global_ev_vorder, global_ev_ctlPoints, tempdata, du, tempdv); + } +#endif + + + /*compute normal*/ + switch(global_ev_k){ + case 3: + inComputeNormal2(du, dv, retNormal); + + break; + case 4: + inComputeFirstPartials(retPoint, du, dv); + inComputeNormal2(du, dv, retNormal); + /*transform the homegeneous coordinate of retPoint into inhomogenous one*/ + retPoint[0] /= retPoint[3]; + retPoint[1] /= retPoint[3]; + retPoint[2] /= retPoint[3]; + break; + } + /*output this vertex*/ +/* inMeshStreamInsert(global_ms, retPoint, retNormal);*/ + + + + glNormal3fv(retNormal); + glVertex3fv(retPoint); + + + + + #ifdef DEBUG + printf("vertex(%f,%f,%f)\n", retPoint[0],retPoint[1],retPoint[2]); + #endif + + + +} + +/*Compute point and normal + *see the head of inDoDomain2WithDerivs + *for the meaning of the arguments + */ +void OpenGLSurfaceEvaluator::inDoEvalCoord2NOGE_BU(REAL u, REAL v, + REAL *retPoint, REAL *retNormal) +{ + + REAL du[4]; + REAL dv[4]; + + + assert(global_ev_k>=3 && global_ev_k <= 4); + /*compute homegeneous point and partial derivatives*/ +// inPreEvaluateBU(global_ev_k, global_ev_uorder, global_ev_vorder, (u-global_ev_u1)/(global_ev_u2-global_ev_u1), global_ev_ctlPoints); + inDoDomain2WithDerivsBU(global_ev_k, u, v, global_ev_u1, global_ev_u2, global_ev_uorder, global_ev_v1, global_ev_v2, global_ev_vorder, global_ev_ctlPoints, retPoint, du, dv); + + +#ifdef AVOID_ZERO_NORMAL + + if(myabs(dv[0]) <= MYZERO && myabs(dv[1]) <= MYZERO && myabs(dv[2]) <= MYZERO) + { + + REAL tempdu[4]; + REAL tempdata[4]; + REAL u1 = global_ev_u1; + REAL u2 = global_ev_u2; + if(u-MYDELTA*(u2-u1) < u1) + u = u+ MYDELTA*(u2-u1); + else + u = u-MYDELTA*(u2-u1); + inDoDomain2WithDerivs(global_ev_k, u,v,global_ev_u1, global_ev_u2, global_ev_uorder, global_ev_v1, global_ev_v2, global_ev_vorder, global_ev_ctlPoints, tempdata, tempdu, dv); + } + if(myabs(du[0]) <= MYZERO && myabs(du[1]) <= MYZERO && myabs(du[2]) <= MYZERO) + { + REAL tempdv[4]; + REAL tempdata[4]; + REAL v1 = global_ev_v1; + REAL v2 = global_ev_v2; + if(v-MYDELTA*(v2-v1) < v1) + v = v+ MYDELTA*(v2-v1); + else + v = v-MYDELTA*(v2-v1); + inDoDomain2WithDerivs(global_ev_k, u,v,global_ev_u1, global_ev_u2, global_ev_uorder, global_ev_v1, global_ev_v2, global_ev_vorder, global_ev_ctlPoints, tempdata, du, tempdv); + } +#endif + + /*compute normal*/ + switch(global_ev_k){ + case 3: + inComputeNormal2(du, dv, retNormal); + break; + case 4: + inComputeFirstPartials(retPoint, du, dv); + inComputeNormal2(du, dv, retNormal); + /*transform the homegeneous coordinate of retPoint into inhomogenous one*/ + retPoint[0] /= retPoint[3]; + retPoint[1] /= retPoint[3]; + retPoint[2] /= retPoint[3]; + break; + } +} + +/*Compute point and normal + *see the head of inDoDomain2WithDerivs + *for the meaning of the arguments + */ +void OpenGLSurfaceEvaluator::inDoEvalCoord2NOGE_BV(REAL u, REAL v, + REAL *retPoint, REAL *retNormal) +{ + + REAL du[4]; + REAL dv[4]; + + + assert(global_ev_k>=3 && global_ev_k <= 4); + /*compute homegeneous point and partial derivatives*/ +// inPreEvaluateBV(global_ev_k, global_ev_uorder, global_ev_vorder, (v-global_ev_v1)/(global_ev_v2-global_ev_v1), global_ev_ctlPoints); + + inDoDomain2WithDerivsBV(global_ev_k, u, v, global_ev_u1, global_ev_u2, global_ev_uorder, global_ev_v1, global_ev_v2, global_ev_vorder, global_ev_ctlPoints, retPoint, du, dv); + + +#ifdef AVOID_ZERO_NORMAL + + if(myabs(dv[0]) <= MYZERO && myabs(dv[1]) <= MYZERO && myabs(dv[2]) <= MYZERO) + { + + REAL tempdu[4]; + REAL tempdata[4]; + REAL u1 = global_ev_u1; + REAL u2 = global_ev_u2; + if(u-MYDELTA*(u2-u1) < u1) + u = u+ MYDELTA*(u2-u1); + else + u = u-MYDELTA*(u2-u1); + inDoDomain2WithDerivs(global_ev_k, u,v,global_ev_u1, global_ev_u2, global_ev_uorder, global_ev_v1, global_ev_v2, global_ev_vorder, global_ev_ctlPoints, tempdata, tempdu, dv); + } + if(myabs(du[0]) <= MYZERO && myabs(du[1]) <= MYZERO && myabs(du[2]) <= MYZERO) + { + REAL tempdv[4]; + REAL tempdata[4]; + REAL v1 = global_ev_v1; + REAL v2 = global_ev_v2; + if(v-MYDELTA*(v2-v1) < v1) + v = v+ MYDELTA*(v2-v1); + else + v = v-MYDELTA*(v2-v1); + inDoDomain2WithDerivs(global_ev_k, u,v,global_ev_u1, global_ev_u2, global_ev_uorder, global_ev_v1, global_ev_v2, global_ev_vorder, global_ev_ctlPoints, tempdata, du, tempdv); + } +#endif + + /*compute normal*/ + switch(global_ev_k){ + case 3: + inComputeNormal2(du, dv, retNormal); + break; + case 4: + inComputeFirstPartials(retPoint, du, dv); + inComputeNormal2(du, dv, retNormal); + /*transform the homegeneous coordinate of retPoint into inhomogenous one*/ + retPoint[0] /= retPoint[3]; + retPoint[1] /= retPoint[3]; + retPoint[2] /= retPoint[3]; + break; + } +} + + +/*Compute point and normal + *see the head of inDoDomain2WithDerivs + *for the meaning of the arguments + */ +void OpenGLSurfaceEvaluator::inDoEvalCoord2NOGE(REAL u, REAL v, + REAL *retPoint, REAL *retNormal) +{ + + REAL du[4]; + REAL dv[4]; + + + assert(global_ev_k>=3 && global_ev_k <= 4); + /*compute homegeneous point and partial derivatives*/ + inDoDomain2WithDerivs(global_ev_k, u, v, global_ev_u1, global_ev_u2, global_ev_uorder, global_ev_v1, global_ev_v2, global_ev_vorder, global_ev_ctlPoints, retPoint, du, dv); + + +#ifdef AVOID_ZERO_NORMAL + + if(myabs(dv[0]) <= MYZERO && myabs(dv[1]) <= MYZERO && myabs(dv[2]) <= MYZERO) + { + + REAL tempdu[4]; + REAL tempdata[4]; + REAL u1 = global_ev_u1; + REAL u2 = global_ev_u2; + if(u-MYDELTA*(u2-u1) < u1) + u = u+ MYDELTA*(u2-u1); + else + u = u-MYDELTA*(u2-u1); + inDoDomain2WithDerivs(global_ev_k, u,v,global_ev_u1, global_ev_u2, global_ev_uorder, global_ev_v1, global_ev_v2, global_ev_vorder, global_ev_ctlPoints, tempdata, tempdu, dv); + } + if(myabs(du[0]) <= MYZERO && myabs(du[1]) <= MYZERO && myabs(du[2]) <= MYZERO) + { + REAL tempdv[4]; + REAL tempdata[4]; + REAL v1 = global_ev_v1; + REAL v2 = global_ev_v2; + if(v-MYDELTA*(v2-v1) < v1) + v = v+ MYDELTA*(v2-v1); + else + v = v-MYDELTA*(v2-v1); + inDoDomain2WithDerivs(global_ev_k, u,v,global_ev_u1, global_ev_u2, global_ev_uorder, global_ev_v1, global_ev_v2, global_ev_vorder, global_ev_ctlPoints, tempdata, du, tempdv); + } +#endif + + /*compute normal*/ + switch(global_ev_k){ + case 3: + inComputeNormal2(du, dv, retNormal); + break; + case 4: + inComputeFirstPartials(retPoint, du, dv); + inComputeNormal2(du, dv, retNormal); + /*transform the homegeneous coordinate of retPoint into inhomogenous one*/ + retPoint[0] /= retPoint[3]; + retPoint[1] /= retPoint[3]; + retPoint[2] /= retPoint[3]; + break; + } +// glNormal3fv(retNormal); +// glVertex3fv(retPoint); +} + +void OpenGLSurfaceEvaluator::inPreEvaluateBV(int k, int uorder, int vorder, REAL vprime, REAL *baseData) +{ + int j,row,col; + REAL p, pdv; + REAL *data; + + if(global_vprime != vprime || global_vorder != vorder) { + inPreEvaluateWithDeriv(vorder, vprime, global_vcoeff, global_vcoeffDeriv); + global_vprime = vprime; + global_vorder = vorder; + } + + for(j=0; j=1 + *This code is copied from opengl/soft/so_eval.c:PreEvaluate + */ +void OpenGLSurfaceEvaluator::inPreEvaluate(int order, REAL vprime, REAL *coeff) +{ + int i, j; + REAL oldval, temp; + REAL oneMinusvprime; + + /* + * Minor optimization + * Compute orders 1 and 2 outright, and set coeff[0], coeff[1] to + * their i==1 loop values to avoid the initialization and the i==1 loop. + */ + if (order == 1) { + coeff[0] = 1.0; + return; + } + + oneMinusvprime = 1-vprime; + coeff[0] = oneMinusvprime; + coeff[1] = vprime; + if (order == 2) return; + + for (i = 2; i < order; i++) { + oldval = coeff[0] * vprime; + coeff[0] = oneMinusvprime * coeff[0]; + for (j = 1; j < i; j++) { + temp = oldval; + oldval = coeff[j] * vprime; + coeff[j] = temp + oneMinusvprime * coeff[j]; + } + coeff[j] = oldval; + } +} + +/* + *compute the Bezier polynomials C[n,j](v) and derivatives for all j at v with + *return values stored in coeff[] and coeffDeriv[]. + *see the head of function inPreEvaluate for the definition of C[n,j](v) + *and how to compute the values. + *The algorithm to compute the derivative is: + * dC[0,0](v) = 0. + * dC[n,j](v) = n*(dC[n-1,j-1](v) - dC[n-1,j](v)). + * + *This code is copied from opengl/soft/so_eval.c:PreEvaluateWidthDeriv + */ +void OpenGLSurfaceEvaluator::inPreEvaluateWithDeriv(int order, REAL vprime, + REAL *coeff, REAL *coeffDeriv) +{ + int i, j; + REAL oldval, temp; + REAL oneMinusvprime; + + oneMinusvprime = 1-vprime; + /* + * Minor optimization + * Compute orders 1 and 2 outright, and set coeff[0], coeff[1] to + * their i==1 loop values to avoid the initialization and the i==1 loop. + */ + if (order == 1) { + coeff[0] = 1.0; + coeffDeriv[0] = 0.0; + return; + } else if (order == 2) { + coeffDeriv[0] = -1.0; + coeffDeriv[1] = 1.0; + coeff[0] = oneMinusvprime; + coeff[1] = vprime; + return; + } + coeff[0] = oneMinusvprime; + coeff[1] = vprime; + for (i = 2; i < order - 1; i++) { + oldval = coeff[0] * vprime; + coeff[0] = oneMinusvprime * coeff[0]; + for (j = 1; j < i; j++) { + temp = oldval; + oldval = coeff[j] * vprime; + coeff[j] = temp + oneMinusvprime * coeff[j]; + } + coeff[j] = oldval; + } + coeffDeriv[0] = -coeff[0]; + /* + ** Minor optimization: + ** Would make this a "for (j=1; j=1 + *n_lower >=1 + */ +void OpenGLSurfaceEvaluator::inEvalUStrip(int n_upper, REAL v_upper, REAL* upper_val, int n_lower, REAL v_lower, REAL* lower_val) +{ + int i,j,k,l; + REAL leftMostV[2]; + typedef REAL REAL3[3]; + + REAL3* upperXYZ = (REAL3*) malloc(sizeof(REAL3)*n_upper); + assert(upperXYZ); + REAL3* upperNormal = (REAL3*) malloc(sizeof(REAL3) * n_upper); + assert(upperNormal); + REAL3* lowerXYZ = (REAL3*) malloc(sizeof(REAL3)*n_lower); + assert(lowerXYZ); + REAL3* lowerNormal = (REAL3*) malloc(sizeof(REAL3) * n_lower); + assert(lowerNormal); + + inEvalULine(n_upper, v_upper, upper_val, 1, upperXYZ, upperNormal); + inEvalULine(n_lower, v_lower, lower_val, 1, lowerXYZ, lowerNormal); + + + + REAL* leftMostXYZ; + REAL* leftMostNormal; + + /* + *the algorithm works by scanning from left to right. + *leftMostV: the left most of the remaining verteces (on both upper and lower). + * it could an element of upperVerts or lowerVerts. + *i: upperVerts[i] is the first vertex to the right of leftMostV on upper line *j: lowerVerts[j] is the first vertex to the right of leftMostV on lower line */ + + /*initialize i,j,and leftMostV + */ + if(upper_val[0] <= lower_val[0]) + { + i=1; + j=0; + + leftMostV[0] = upper_val[0]; + leftMostV[1] = v_upper; + leftMostXYZ = upperXYZ[0]; + leftMostNormal = upperNormal[0]; + } + else + { + i=0; + j=1; + + leftMostV[0] = lower_val[0]; + leftMostV[1] = v_lower; + + leftMostXYZ = lowerXYZ[0]; + leftMostNormal = lowerNormal[0]; + } + + /*the main loop. + *the invariance is that: + *at the beginning of each loop, the meaning of i,j,and leftMostV are + *maintained + */ + while(1) + { + if(i >= n_upper) /*case1: no more in upper*/ + { + if(j= n_lower) /*case2: no more in lower*/ + { + if(i=i; k--) /*reverse order for two-side lighting*/ + { + glNormal3fv(upperNormal[k]); + glVertex3fv(upperXYZ[k]); + } + + endtfan(); + } + break; /*exit the main loop*/ + } + else /* case3: neither is empty, plus the leftMostV, there is at least one triangle to output*/ + { + if(upper_val[i] <= lower_val[j]) + { + bgntfan(); + + glNormal3fv(lowerNormal[j]); + glVertex3fv(lowerXYZ[j]); + + /*find the last k>=i such that + *upperverts[k][0] <= lowerverts[j][0] + */ + k=i; + + while(k lower_val[j]) + break; + k++; + + } + k--; + + + for(l=k; l>=i; l--)/*the reverse is for two-side lighting*/ + { + glNormal3fv(upperNormal[l]); + glVertex3fv(upperXYZ[l]); + + } + glNormal3fv(leftMostNormal); + glVertex3fv(leftMostXYZ); + + endtfan(); + + /*update i and leftMostV for next loop + */ + i = k+1; + + leftMostV[0] = upper_val[k]; + leftMostV[1] = v_upper; + leftMostNormal = upperNormal[k]; + leftMostXYZ = upperXYZ[k]; + } + else /*upperVerts[i][0] > lowerVerts[j][0]*/ + { + bgntfan(); + glNormal3fv(upperNormal[i]); + glVertex3fv(upperXYZ[i]); + + glNormal3fv(leftMostNormal); + glVertex3fv(leftMostXYZ); + + + /*find the last k>=j such that + *lowerverts[k][0] < upperverts[i][0] + */ + k=j; + while(k< n_lower) + { + if(lower_val[k] >= upper_val[i]) + break; + glNormal3fv(lowerNormal[k]); + glVertex3fv(lowerXYZ[k]); + + k++; + } + endtfan(); + + /*update j and leftMostV for next loop + */ + j=k; + leftMostV[0] = lower_val[j-1]; + leftMostV[1] = v_lower; + + leftMostNormal = lowerNormal[j-1]; + leftMostXYZ = lowerXYZ[j-1]; + } + } + } + //clean up + free(upperXYZ); + free(lowerXYZ); + free(upperNormal); + free(lowerNormal); +} + +/*triangulate a strip bounded by two lines which are parallel to V-axis + *leftVerts: the verteces on the left line + *rightVertx: the verteces on the right line + *n_left >=1 + *n_right >=1 + */ +void OpenGLSurfaceEvaluator::inEvalVStrip(int n_left, REAL u_left, REAL* left_val, int n_right, REAL u_right, REAL* right_val) +{ + int i,j,k,l; + REAL botMostV[2]; + typedef REAL REAL3[3]; + + REAL3* leftXYZ = (REAL3*) malloc(sizeof(REAL3)*n_left); + assert(leftXYZ); + REAL3* leftNormal = (REAL3*) malloc(sizeof(REAL3) * n_left); + assert(leftNormal); + REAL3* rightXYZ = (REAL3*) malloc(sizeof(REAL3)*n_right); + assert(rightXYZ); + REAL3* rightNormal = (REAL3*) malloc(sizeof(REAL3) * n_right); + assert(rightNormal); + + inEvalVLine(n_left, u_left, left_val, 1, leftXYZ, leftNormal); + inEvalVLine(n_right, u_right, right_val, 1, rightXYZ, rightNormal); + + + + REAL* botMostXYZ; + REAL* botMostNormal; + + /* + *the algorithm works by scanning from bot to top. + *botMostV: the bot most of the remaining verteces (on both left and right). + * it could an element of leftVerts or rightVerts. + *i: leftVerts[i] is the first vertex to the top of botMostV on left line + *j: rightVerts[j] is the first vertex to the top of botMostV on rightline */ + + /*initialize i,j,and botMostV + */ + if(left_val[0] <= right_val[0]) + { + i=1; + j=0; + + botMostV[0] = u_left; + botMostV[1] = left_val[0]; + botMostXYZ = leftXYZ[0]; + botMostNormal = leftNormal[0]; + } + else + { + i=0; + j=1; + + botMostV[0] = u_right; + botMostV[1] = right_val[0]; + + botMostXYZ = rightXYZ[0]; + botMostNormal = rightNormal[0]; + } + + /*the main loop. + *the invariance is that: + *at the beginning of each loop, the meaning of i,j,and botMostV are + *maintained + */ + while(1) + { + if(i >= n_left) /*case1: no more in left*/ + { + if(j= n_right) /*case2: no more in right*/ + { + if(i=i; k--) /*reverse order for two-side lighting*/ + { + glNormal3fv(leftNormal[k]); + glVertex3fv(leftXYZ[k]); + } + + endtfan(); + } + break; /*exit the main loop*/ + } + else /* case3: neither is empty, plus the botMostV, there is at least one triangle to output*/ + { + if(left_val[i] <= right_val[j]) + { + bgntfan(); + + glNormal3fv(rightNormal[j]); + glVertex3fv(rightXYZ[j]); + + /*find the last k>=i such that + *leftverts[k][0] <= rightverts[j][0] + */ + k=i; + + while(k right_val[j]) + break; + k++; + + } + k--; + + + for(l=k; l>=i; l--)/*the reverse is for two-side lighting*/ + { + glNormal3fv(leftNormal[l]); + glVertex3fv(leftXYZ[l]); + + } + glNormal3fv(botMostNormal); + glVertex3fv(botMostXYZ); + + endtfan(); + + /*update i and botMostV for next loop + */ + i = k+1; + + botMostV[0] = u_left; + botMostV[1] = left_val[k]; + botMostNormal = leftNormal[k]; + botMostXYZ = leftXYZ[k]; + } + else /*left_val[i] > right_val[j])*/ + { + bgntfan(); + glNormal3fv(leftNormal[i]); + glVertex3fv(leftXYZ[i]); + + glNormal3fv(botMostNormal); + glVertex3fv(botMostXYZ); + + + /*find the last k>=j such that + *rightverts[k][0] < leftverts[i][0] + */ + k=j; + while(k< n_right) + { + if(right_val[k] >= left_val[i]) + break; + glNormal3fv(rightNormal[k]); + glVertex3fv(rightXYZ[k]); + + k++; + } + endtfan(); + + /*update j and botMostV for next loop + */ + j=k; + botMostV[0] = u_right; + botMostV[1] = right_val[j-1]; + + botMostNormal = rightNormal[j-1]; + botMostXYZ = rightXYZ[j-1]; + } + } + } + //clean up + free(leftXYZ); + free(rightXYZ); + free(leftNormal); + free(rightNormal); +} + +/*-----------------------begin evalMachine-------------------*/ +void OpenGLSurfaceEvaluator::inMap2fEM(int which, int k, + REAL ulower, + REAL uupper, + int ustride, + int uorder, + REAL vlower, + REAL vupper, + int vstride, + int vorder, + REAL *ctlPoints) +{ + int i,j,x; + surfEvalMachine *temp_em; + switch(which){ + case 0: //vertex + vertex_flag = 1; + temp_em = &em_vertex; + break; + case 1: //normal + normal_flag = 1; + temp_em = &em_normal; + break; + case 2: //color + color_flag = 1; + temp_em = &em_color; + break; + default: + texcoord_flag = 1; + temp_em = &em_texcoord; + break; + } + + REAL *data = temp_em->ctlPoints; + + temp_em->uprime = -1;//initilized + temp_em->vprime = -1; + + temp_em->k = k; + temp_em->u1 = ulower; + temp_em->u2 = uupper; + temp_em->ustride = ustride; + temp_em->uorder = uorder; + temp_em->v1 = vlower; + temp_em->v2 = vupper; + temp_em->vstride = vstride; + temp_em->vorder = vorder; + + /*copy the contrl points from ctlPoints to global_ev_ctlPoints*/ + for (i=0; iu2 == em->u1) || (em->v2 == em->v1)) + return; + the_uprime = (u - em->u1) / (em->u2 - em->u1); + the_vprime = (v - em->v1) / (em->v2 - em->v1); + + /* Compute coefficients for values and derivs */ + + /* Use already cached values if possible */ + if(em->uprime != the_uprime) { + inPreEvaluateWithDeriv(em->uorder, the_uprime, em->ucoeff, em->ucoeffDeriv); + em->uprime = the_uprime; + } + if (em->vprime != the_vprime) { + inPreEvaluateWithDeriv(em->vorder, the_vprime, em->vcoeff, em->vcoeffDeriv); + em->vprime = the_vprime; + } + + for (j = 0; j < em->k; j++) { + data=em->ctlPoints+j; + retPoint[j] = retdu[j] = retdv[j] = 0.0; + for (row = 0; row < em->uorder; row++) { + /* + ** Minor optimization. + ** The col == 0 part of the loop is extracted so we don't + ** have to initialize p and pdv to 0. + */ + p = em->vcoeff[0] * (*data); + pdv = em->vcoeffDeriv[0] * (*data); + data += em->k; + for (col = 1; col < em->vorder; col++) { + /* Incrementally build up p, pdv value */ + p += em->vcoeff[col] * (*data); + pdv += em->vcoeffDeriv[col] * (*data); + data += em->k; + } + /* Use p, pdv value to incrementally add up r, du, dv */ + retPoint[j] += em->ucoeff[row] * p; + retdu[j] += em->ucoeffDeriv[row] * p; + retdv[j] += em->ucoeff[row] * pdv; + } + } +} + +void OpenGLSurfaceEvaluator::inDoDomain2EM(surfEvalMachine *em, REAL u, REAL v, + REAL *retPoint) +{ + int j, row, col; + REAL the_uprime; + REAL the_vprime; + REAL p; + REAL *data; + + if((em->u2 == em->u1) || (em->v2 == em->v1)) + return; + the_uprime = (u - em->u1) / (em->u2 - em->u1); + the_vprime = (v - em->v1) / (em->v2 - em->v1); + + /* Compute coefficients for values and derivs */ + + /* Use already cached values if possible */ + if(em->uprime != the_uprime) { + inPreEvaluate(em->uorder, the_uprime, em->ucoeff); + em->uprime = the_uprime; + } + if (em->vprime != the_vprime) { + inPreEvaluate(em->vorder, the_vprime, em->vcoeff); + em->vprime = the_vprime; + } + + for (j = 0; j < em->k; j++) { + data=em->ctlPoints+j; + retPoint[j] = 0.0; + for (row = 0; row < em->uorder; row++) { + /* + ** Minor optimization. + ** The col == 0 part of the loop is extracted so we don't + ** have to initialize p and pdv to 0. + */ + p = em->vcoeff[0] * (*data); + data += em->k; + for (col = 1; col < em->vorder; col++) { + /* Incrementally build up p, pdv value */ + p += em->vcoeff[col] * (*data); + data += em->k; + } + /* Use p, pdv value to incrementally add up r, du, dv */ + retPoint[j] += em->ucoeff[row] * p; + } + } +} + + +void OpenGLSurfaceEvaluator::inDoEvalCoord2EM(REAL u, REAL v) +{ + REAL temp_vertex[5]; + REAL temp_normal[3]; + REAL temp_color[4]; + REAL temp_texcoord[4]; + + if(texcoord_flag) + { + inDoDomain2EM(&em_texcoord, u,v, temp_texcoord); + texcoordCallBack(temp_texcoord, userData); + } + if(color_flag) + { + inDoDomain2EM(&em_color, u,v, temp_color); + colorCallBack(temp_color, userData); + } + + if(normal_flag) //there is a normla map + { + inDoDomain2EM(&em_normal, u,v, temp_normal); + normalCallBack(temp_normal, userData); + + if(vertex_flag) + { + inDoDomain2EM(&em_vertex, u,v,temp_vertex); + if(em_vertex.k == 4) + { + temp_vertex[0] /= temp_vertex[3]; + temp_vertex[1] /= temp_vertex[3]; + temp_vertex[2] /= temp_vertex[3]; + } + temp_vertex[3]=u; + temp_vertex[4]=v; + vertexCallBack(temp_vertex, userData); + } + } + else if(auto_normal_flag) //no normal map but there is a normal callbackfunctin + { + REAL du[4]; + REAL dv[4]; + + /*compute homegeneous point and partial derivatives*/ + inDoDomain2WithDerivsEM(&em_vertex, u,v,temp_vertex,du,dv); + + if(em_vertex.k ==4) + inComputeFirstPartials(temp_vertex, du, dv); + +#ifdef AVOID_ZERO_NORMAL + if(myabs(dv[0]) <= MYZERO && myabs(dv[1]) <= MYZERO && myabs(dv[2]) <= MYZERO) + { + + REAL tempdu[4]; + REAL tempdata[4]; + REAL u1 = em_vertex.u1; + REAL u2 = em_vertex.u2; + if(u-MYDELTA*(u2-u1) < u1) + u = u+ MYDELTA*(u2-u1); + else + u = u-MYDELTA*(u2-u1); + inDoDomain2WithDerivsEM(&em_vertex,u,v, tempdata, tempdu, dv); + + if(em_vertex.k ==4) + inComputeFirstPartials(temp_vertex, du, dv); + } + else if(myabs(du[0]) <= MYZERO && myabs(du[1]) <= MYZERO && myabs(du[2]) <= MYZERO) + { + REAL tempdv[4]; + REAL tempdata[4]; + REAL v1 = em_vertex.v1; + REAL v2 = em_vertex.v2; + if(v-MYDELTA*(v2-v1) < v1) + v = v+ MYDELTA*(v2-v1); + else + v = v-MYDELTA*(v2-v1); + inDoDomain2WithDerivsEM(&em_vertex,u,v, tempdata, du, tempdv); + + if(em_vertex.k ==4) + inComputeFirstPartials(temp_vertex, du, dv); + } +#endif + + /*compute normal*/ + switch(em_vertex.k){ + case 3: + + inComputeNormal2(du, dv, temp_normal); + break; + case 4: + +// inComputeFirstPartials(temp_vertex, du, dv); + inComputeNormal2(du, dv, temp_normal); + + /*transform the homegeneous coordinate of retPoint into inhomogenous one*/ + temp_vertex[0] /= temp_vertex[3]; + temp_vertex[1] /= temp_vertex[3]; + temp_vertex[2] /= temp_vertex[3]; + break; + } + normalCallBack(temp_normal, userData); + temp_vertex[3] = u; + temp_vertex[4] = v; + vertexCallBack(temp_vertex, userData); + + }/*end if auto_normal*/ + else //no normal map, and no normal callback function + { + if(vertex_flag) + { + inDoDomain2EM(&em_vertex, u,v,temp_vertex); + if(em_vertex.k == 4) + { + temp_vertex[0] /= temp_vertex[3]; + temp_vertex[1] /= temp_vertex[3]; + temp_vertex[2] /= temp_vertex[3]; + } + temp_vertex[3] = u; + temp_vertex[4] = v; + vertexCallBack(temp_vertex, userData); + } + } +} + + +void OpenGLSurfaceEvaluator::inBPMEvalEM(bezierPatchMesh* bpm) +{ + int i,j,k; + float u,v; + + int ustride; + int vstride; + +#ifdef USE_LOD + if(bpm->bpatch != NULL) + { + bezierPatch* p=bpm->bpatch; + ustride = p->dimension * p->vorder; + vstride = p->dimension; + + glMap2f( (p->dimension == 3)? GL_MAP2_VERTEX_3 : GL_MAP2_VERTEX_4, + p->umin, + p->umax, + ustride, + p->uorder, + p->vmin, + p->vmax, + vstride, + p->vorder, + p->ctlpoints); + + +/* + inMap2fEM(0, p->dimension, + p->umin, + p->umax, + ustride, + p->uorder, + p->vmin, + p->vmax, + vstride, + p->vorder, + p->ctlpoints); +*/ + } +#else + + if(bpm->bpatch != NULL){ + bezierPatch* p = bpm->bpatch; + ustride = p->dimension * p->vorder; + vstride = p->dimension; + inMap2fEM(0, p->dimension, + p->umin, + p->umax, + ustride, + p->uorder, + p->vmin, + p->vmax, + vstride, + p->vorder, + p->ctlpoints); + } + if(bpm->bpatch_normal != NULL){ + bezierPatch* p = bpm->bpatch_normal; + ustride = p->dimension * p->vorder; + vstride = p->dimension; + inMap2fEM(1, p->dimension, + p->umin, + p->umax, + ustride, + p->uorder, + p->vmin, + p->vmax, + vstride, + p->vorder, + p->ctlpoints); + } + if(bpm->bpatch_color != NULL){ + bezierPatch* p = bpm->bpatch_color; + ustride = p->dimension * p->vorder; + vstride = p->dimension; + inMap2fEM(2, p->dimension, + p->umin, + p->umax, + ustride, + p->uorder, + p->vmin, + p->vmax, + vstride, + p->vorder, + p->ctlpoints); + } + if(bpm->bpatch_texcoord != NULL){ + bezierPatch* p = bpm->bpatch_texcoord; + ustride = p->dimension * p->vorder; + vstride = p->dimension; + inMap2fEM(3, p->dimension, + p->umin, + p->umax, + ustride, + p->uorder, + p->vmin, + p->vmax, + vstride, + p->vorder, + p->ctlpoints); + } +#endif + + + k=0; + for(i=0; iindex_length_array; i++) + { +#ifdef USE_LOD + if(bpm->type_array[i] == GL_POLYGON) //a mesh + { + GLfloat *temp = bpm->UVarray+k; + GLfloat u0 = temp[0]; + GLfloat v0 = temp[1]; + GLfloat u1 = temp[2]; + GLfloat v1 = temp[3]; + GLint nu = (GLint) ( temp[4]); + GLint nv = (GLint) ( temp[5]); + GLint umin = (GLint) ( temp[6]); + GLint vmin = (GLint) ( temp[7]); + GLint umax = (GLint) ( temp[8]); + GLint vmax = (GLint) ( temp[9]); + + glMapGrid2f(LOD_eval_level*nu, u0, u1, LOD_eval_level*nv, v0, v1); + glEvalMesh2(GL_FILL, LOD_eval_level*umin, LOD_eval_level*umax, LOD_eval_level*vmin, LOD_eval_level*vmax); + } + else + { + LOD_eval(bpm->length_array[i], bpm->UVarray+k, bpm->type_array[i], + 0 + ); + } + k+= 2*bpm->length_array[i]; + +#else //undef USE_LOD + +#ifdef CRACK_TEST +if( bpm->bpatch->umin == 2 && bpm->bpatch->umax == 3 + && bpm->bpatch->vmin ==2 && bpm->bpatch->vmax == 3) +{ +REAL vertex[4]; +REAL normal[4]; +#ifdef DEBUG +printf("***number ****1\n"); +#endif + +beginCallBack(GL_QUAD_STRIP, NULL); +inDoEvalCoord2EM(3.0, 3.0); +inDoEvalCoord2EM(2.0, 3.0); +inDoEvalCoord2EM(3.0, 2.7); +inDoEvalCoord2EM(2.0, 2.7); +inDoEvalCoord2EM(3.0, 2.0); +inDoEvalCoord2EM(2.0, 2.0); +endCallBack(NULL); + +beginCallBack(GL_TRIANGLE_STRIP, NULL); +inDoEvalCoord2EM(2.0, 3.0); +inDoEvalCoord2EM(2.0, 2.0); +inDoEvalCoord2EM(2.0, 2.7); +endCallBack(NULL); + +} +if( bpm->bpatch->umin == 1 && bpm->bpatch->umax == 2 + && bpm->bpatch->vmin ==2 && bpm->bpatch->vmax == 3) +{ +#ifdef DEBUG +printf("***number 3\n"); +#endif +beginCallBack(GL_QUAD_STRIP, NULL); +inDoEvalCoord2EM(2.0, 3.0); +inDoEvalCoord2EM(1.0, 3.0); +inDoEvalCoord2EM(2.0, 2.3); +inDoEvalCoord2EM(1.0, 2.3); +inDoEvalCoord2EM(2.0, 2.0); +inDoEvalCoord2EM(1.0, 2.0); +endCallBack(NULL); + +beginCallBack(GL_TRIANGLE_STRIP, NULL); +inDoEvalCoord2EM(2.0, 2.3); +inDoEvalCoord2EM(2.0, 2.0); +inDoEvalCoord2EM(2.0, 3.0); +endCallBack(NULL); + +} +return; +#endif //CRACK_TEST + + beginCallBack(bpm->type_array[i], userData); + + for(j=0; jlength_array[i]; j++) + { + u = bpm->UVarray[k]; + v = bpm->UVarray[k+1]; +#ifdef USE_LOD + LOD_EVAL_COORD(u,v); +// glEvalCoord2f(u,v); +#else + +#ifdef GENERIC_TEST + float temp_normal[3]; + float temp_vertex[3]; + if(temp_signal == 0) + { + gTessVertexSphere(u,v, temp_normal, temp_vertex); +//printf("normal=(%f,%f,%f)\n", temp_normal[0], temp_normal[1], temp_normal[2])//printf("veretx=(%f,%f,%f)\n", temp_vertex[0], temp_vertex[1], temp_vertex[2]); + normalCallBack(temp_normal, userData); + vertexCallBack(temp_vertex, userData); + } + else if(temp_signal == 1) + { + gTessVertexCyl(u,v, temp_normal, temp_vertex); +//printf("normal=(%f,%f,%f)\n", temp_normal[0], temp_normal[1], temp_normal[2])//printf("veretx=(%f,%f,%f)\n", temp_vertex[0], temp_vertex[1], temp_vertex[2]); + normalCallBack(temp_normal, userData); + vertexCallBack(temp_vertex, userData); + } + else +#endif //GENERIC_TEST + + inDoEvalCoord2EM(u,v); + +#endif //USE_LOD + + k += 2; + } + endCallBack(userData); + +#endif //USE_LOD + } +} + +void OpenGLSurfaceEvaluator::inBPMListEvalEM(bezierPatchMesh* list) +{ + bezierPatchMesh* temp; + for(temp = list; temp != NULL; temp = temp->next) + { + inBPMEvalEM(temp); + } +} + diff --git a/src/glu/sgi/libnurbs/interface/mystdio.h b/src/glu/sgi/libnurbs/interface/mystdio.h new file mode 100644 index 0000000..5ab49ef --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/mystdio.h @@ -0,0 +1,60 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * mystdio.h + * + */ + +#ifndef __glumystdio_h_ +#define __glumystdio_h_ + +#ifdef STANDALONE +inline void _glu_dprintf( const char *, ... ) { } +#endif + +#ifdef LIBRARYBUILD +#ifndef NDEBUG +#include +#define _glu_dprintf printf +#else +inline void _glu_dprintf( const char *, ... ) { } +#endif +#endif + +#ifdef GLBUILD +inline void _glu_dprintf( const char *, ... ) { } +#endif + +#ifndef NULL +#define NULL 0 +#endif + +#endif /* __glumystdio_h_ */ diff --git a/src/glu/sgi/libnurbs/interface/mystdlib.h b/src/glu/sgi/libnurbs/interface/mystdlib.h new file mode 100644 index 0000000..ab7a3b2 --- /dev/null +++ b/src/glu/sgi/libnurbs/interface/mystdlib.h @@ -0,0 +1,57 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * mystdlib.h + * + */ + +#ifndef __glumystdlib_h_ +#define __glumystdlib_h_ + +#ifdef STANDALONE +typedef unsigned int size_t; +extern "C" void abort( void ); +extern "C" void * malloc( size_t ); +extern "C" void free( void * ); +#endif + +#ifdef LIBRARYBUILD +#include +#endif + +#ifdef GLBUILD +typedef unsigned int size_t; +extern "C" void abort( void ); +extern "C" void * malloc( size_t ); +extern "C" void free( void * ); +#endif + +#endif /* __glumystdlib_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/arc.cc b/src/glu/sgi/libnurbs/internals/arc.cc new file mode 100644 index 0000000..cd4c404 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/arc.cc @@ -0,0 +1,346 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * arc.c++ + * + */ + +#include +#include "glimports.h" +#include "mystdio.h" +#include "myassert.h" +#include "arc.h" +#include "bin.h" +#include "pwlarc.h" +#include "simplemath.h" + +/* local preprocessor definitions */ +#define ZERO 0.00001/*0.000001*/ + +const int Arc::bezier_tag = (1<<13); +const int Arc::arc_tag = (1<<3); +const int Arc::tail_tag = (1<<6); + +/*-------------------------------------------------------------------------- + * makeSide - attach a pwl arc to an arc and mark it as a border arc + *-------------------------------------------------------------------------- + */ + +void +Arc::makeSide( PwlArc *pwl, arc_side side ) +{ + assert( pwl != 0); + assert( pwlArc == 0 ); + assert( pwl->npts > 0 ); + assert( pwl->pts != 0); + pwlArc = pwl; + clearbezier(); + setside( side ); +} + + +/*-------------------------------------------------------------------------- + * numpts - count number of points on arc loop + *-------------------------------------------------------------------------- + */ + +int +Arc::numpts( void ) +{ + Arc_ptr jarc = this; + int npts = 0; + do { + npts += jarc->pwlArc->npts; + jarc = jarc->next; + } while( jarc != this ); + return npts; +} + +/*-------------------------------------------------------------------------- + * markverts - mark each point with id of arc + *-------------------------------------------------------------------------- + */ + +void +Arc::markverts( void ) +{ + Arc_ptr jarc = this; + + do { + TrimVertex *p = jarc->pwlArc->pts; + for( int i=0; ipwlArc->npts; i++ ) + p[i].nuid = jarc->nuid; + jarc = jarc->next; + } while( jarc != this ); +} + +/*-------------------------------------------------------------------------- + * getextrema - find axis extrema on arc loop + *-------------------------------------------------------------------------- + */ + +void +Arc::getextrema( Arc_ptr extrema[4] ) +{ + REAL leftpt, botpt, rightpt, toppt; + + extrema[0] = extrema[1] = extrema[2] = extrema[3] = this; + + leftpt = rightpt = this->tail()[0]; + botpt = toppt = this->tail()[1]; + + for( Arc_ptr jarc = this->next; jarc != this; jarc = jarc->next ) { + if ( jarc->tail()[0] < leftpt || + (jarc->tail()[0] <= leftpt && jarc->rhead()[0]<=leftpt)) { + leftpt = jarc->pwlArc->pts->param[0]; + extrema[1] = jarc; + } + if ( jarc->tail()[0] > rightpt || + (jarc->tail()[0] >= rightpt && jarc->rhead()[0] >= rightpt)) { + rightpt = jarc->pwlArc->pts->param[0]; + extrema[3] = jarc; + } + if ( jarc->tail()[1] < botpt || + (jarc->tail()[1] <= botpt && jarc->rhead()[1] <= botpt )) { + botpt = jarc->pwlArc->pts->param[1]; + extrema[2] = jarc; + } + if ( jarc->tail()[1] > toppt || + (jarc->tail()[1] >= toppt && jarc->rhead()[1] >= toppt)) { + toppt = jarc->pwlArc->pts->param[1]; + extrema[0] = jarc; + } + } +} + + +/*------------------------------------------------------------------------- + * show - print to the stdout the vertices of a pwl arc + *------------------------------------------------------------------------- + */ + +void +Arc::show() +{ +#ifndef NDEBUG + _glu_dprintf( "\tPWLARC NP: %d FL: 1\n", pwlArc->npts ); + for( int i = 0; i < pwlArc->npts; i++ ) { + _glu_dprintf( "\t\tVERTEX %f %f\n", pwlArc->pts[i].param[0], + pwlArc->pts[i].param[1] ); + } +#endif +} + +/*------------------------------------------------------------------------- + * print - print out the vertices of all pwl arcs on a loop + *------------------------------------------------------------------------- + */ + +void +Arc::print( void ) +{ + Arc_ptr jarc = this; + +#ifndef NDEBUG + _glu_dprintf( "BGNTRIM\n" ); +#endif + do { + jarc->show( ); + jarc = jarc->next; + } while (jarc != this); +#ifndef NDEBUG + _glu_dprintf("ENDTRIM\n" ); +#endif +} + +/*------------------------------------------------------------------------- + * isDisconnected - check if tail of arc and head of prev meet + *------------------------------------------------------------------------- + */ + +int +Arc::isDisconnected( void ) +{ + if( pwlArc == 0 ) return 0; + if( prev->pwlArc == 0 ) return 0; + + REAL *p0 = tail(); + REAL *p1 = prev->rhead(); + + if( ((p0[0] - p1[0]) > ZERO) || ((p1[0] - p0[0]) > ZERO) || + ((p0[1] - p1[1]) > ZERO) || ((p1[1] - p0[1]) > ZERO) ) { +#ifndef NDEBUG + _glu_dprintf( "x coord = %f %f %f\n", p0[0], p1[0], p0[0] - p1[0] ); + _glu_dprintf( "y coord = %f %f %f\n", p0[1], p1[1], p0[1] - p1[1] ); +#endif + return 1; + } else { + /* average two points together */ + p0[0] = p1[0] = (p1[0] + p0[0]) * 0.5; + p0[1] = p1[1] = (p1[1] + p0[1]) * 0.5; + return 0; + } +} + +/*------------------------------------------------------------------------- + * neq_vert - assert that two 2D vertices are not equal + *------------------------------------------------------------------------- + */ + +inline static int +neq_vert( REAL *v1, REAL *v2 ) +{ + return ((v1[0] != v2[0]) || (v1[1] != v2[1] )) ? 1 : 0; +} + +/*------------------------------------------------------------------------- + * check - verify consistency of a loop, including + * 1) if pwl, no two consecutive vertices are identical + * 2) the circular link pointers are valid + * 3) the geometric info at the head and tail are consistent + *------------------------------------------------------------------------- + */ + +int +Arc::check( void ) +{ + if( this == 0 ) return 1; + Arc_ptr jarc = this; + do { + assert( (jarc->pwlArc != 0) || (jarc->bezierArc != 0) ); + + if (jarc->prev == 0 || jarc->next == 0) { +#ifndef NDEBUG + _glu_dprintf( "checkjarc:null next/prev pointer\n"); + jarc->print( ); +#endif + return 0; + } + + if (jarc->next->prev != jarc) { +#ifndef NDEBUG + _glu_dprintf( "checkjarc: pointer linkage screwed up\n"); + jarc->print( ); +#endif + return 0; + } + + if( jarc->pwlArc ) { +#ifndef NDEBUG + assert( jarc->pwlArc->npts >= 1 ); + assert( jarc->pwlArc->npts < 100000 ); +/* + for( int i=0; i < jarc->pwlArc->npts-1; i++ ) + assert( neq_vert( jarc->pwlArc->pts[i].param, + jarc->pwlArc->pts[i+1].param) ); +*/ +#endif + if( jarc->prev->pwlArc ) { + if( jarc->tail()[1] != jarc->prev->rhead()[1] ) { +#ifndef NDEBUG + _glu_dprintf( "checkjarc: geometric linkage screwed up 1\n"); + jarc->prev->show(); + jarc->show(); +#endif + return 0; + } + if( jarc->tail()[0] != jarc->prev->rhead()[0] ) { + +#ifndef NDEBUG + _glu_dprintf( "checkjarc: geometric linkage screwed up 2\n"); + jarc->prev->show(); + jarc->show(); +#endif + return 0; + } + } + if( jarc->next->pwlArc ) { + if( jarc->next->tail()[0] != jarc->rhead()[0] ) { +#ifndef NDEBUG + _glu_dprintf( "checkjarc: geometric linkage screwed up 3\n"); + jarc->show(); + jarc->next->show(); +#endif + return 0; + } + if( jarc->next->tail()[1] != jarc->rhead()[1] ) { +#ifndef NDEBUG + _glu_dprintf( "checkjarc: geometric linkage screwed up 4\n"); + jarc->show(); + jarc->next->show(); +#endif + return 0; + } + } + if( jarc->isbezier() ) { + assert( jarc->pwlArc->npts == 2 ); + assert( (jarc->pwlArc->pts[0].param[0] == \ + jarc->pwlArc->pts[1].param[0]) ||\ + (jarc->pwlArc->pts[0].param[1] == \ + jarc->pwlArc->pts[1].param[1]) ); + } + } + jarc = jarc->next; + } while (jarc != this); + return 1; +} + + +#define TOL 0.00001 + +inline long tooclose( REAL x, REAL y ) +{ + return (glu_abs(x-y) < TOL) ? 1 : 0; +} + + +/*-------------------------------------------------------------------------- + * append - append a jordan arc to a circularly linked list + *-------------------------------------------------------------------------- + */ + +Arc_ptr +Arc::append( Arc_ptr jarc ) +{ + if( jarc != 0 ) { + next = jarc->next; + prev = jarc; + next->prev = prev->next = this; + } else { + next = prev = this; + } + return this; +} + diff --git a/src/glu/sgi/libnurbs/internals/arc.h b/src/glu/sgi/libnurbs/internals/arc.h new file mode 100644 index 0000000..ca397f3 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/arc.h @@ -0,0 +1,139 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * arc.h + * + */ + +#ifndef __gluarc_h_ +#define __gluarc_h_ + +#include "myassert.h" +#include "bufpool.h" +#include "mystdio.h" +#include "types.h" +#include "pwlarc.h" +#include "trimvertex.h" + +class Bin; +class Arc; +struct BezierArc; + +typedef class Arc *Arc_ptr; + +enum arc_side { arc_none = 0, arc_right, arc_top, arc_left, arc_bottom }; + + +class Arc: public PooledObj { /* an arc, in two list, the trim list and bin */ + +public: + static const int bezier_tag; + static const int arc_tag; + static const int tail_tag; + Arc_ptr prev; /* trim list pointer */ + Arc_ptr next; /* trim list pointer */ + Arc_ptr link; /* bin pointers */ + BezierArc * bezierArc; /* associated bezier arc */ + PwlArc * pwlArc; /* associated pwl arc */ + long type; /* curve type */ + long nuid; + + inline Arc( Arc *, PwlArc * ); + inline Arc( arc_side, long ); + + Arc_ptr append( Arc_ptr ); + int check( void ); + int isMonotone( void ); + int isDisconnected( void ); + int numpts( void ); + void markverts( void ); + void getextrema( Arc_ptr[4] ); + void print( void ); + void show( void ); + void makeSide( PwlArc *, arc_side ); + inline int isTessellated() { return pwlArc ? 1 : 0; } + inline long isbezier() { return type & bezier_tag; } + inline void setbezier() { type |= bezier_tag; } + inline void clearbezier() { type &= ~bezier_tag; } + inline long npts() { return pwlArc->npts; } + inline TrimVertex * pts() { return pwlArc->pts; } + inline REAL * tail() { return pwlArc->pts[0].param; } + inline REAL * head() { return next->pwlArc->pts[0].param; } + inline REAL * rhead() { return pwlArc->pts[pwlArc->npts-1].param; } + inline long ismarked() { return type & arc_tag; } + inline void setmark() { type |= arc_tag; } + inline void clearmark() { type &= (~arc_tag); } + inline void clearside() { type &= ~(0x7 << 8); } + inline void setside( arc_side s ) { clearside(); type |= (((long)s)<<8); } + inline arc_side getside() { return (arc_side) ((type>>8) & 0x7); } + inline int getitail() { return type & tail_tag; } + inline void setitail() { type |= tail_tag; } + inline void clearitail() { type &= (~tail_tag); } +}; + +/*-------------------------------------------------------------------------- + * Arc - initialize a new Arc with the same type and uid of + * a given Arc and a given pwl arc + *-------------------------------------------------------------------------- + */ + +inline +Arc::Arc( Arc *j, PwlArc *p ) +{ + prev = NULL; + next = NULL; + link = NULL; + bezierArc = NULL; + pwlArc = p; + type = j->type; + nuid = j->nuid; +} + +/*-------------------------------------------------------------------------- + * Arc - initialize a new Arc with the same type and uid of + * a given Arc and a given pwl arc + *-------------------------------------------------------------------------- + */ + +inline +Arc::Arc( arc_side side, long _nuid ) +{ + prev = NULL; + next = NULL; + link = NULL; + bezierArc = NULL; + pwlArc = NULL; + type = 0; + setside( side ); + nuid = _nuid; +} + +#endif /* __gluarc_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/arcsorter.cc b/src/glu/sgi/libnurbs/internals/arcsorter.cc new file mode 100644 index 0000000..1f85cb7 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/arcsorter.cc @@ -0,0 +1,172 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * arcsorter.c++ + * + */ + +#ifndef __gluarcsorter_c_ +#define __gluarcsorter_c_ + +#include "glimports.h" +#include "arc.h" +#include "arcsorter.h" +#include "subdivider.h" + +ArcSorter::ArcSorter(Subdivider &s) : Sorter( sizeof( Arc ** ) ), subdivider(s) +{ +} + +int +ArcSorter::qscmp( char *, char * ) +{ + _glu_dprintf( "ArcSorter::qscmp: pure virtual called\n" ); + return 0; +} + +void +ArcSorter::qsort( Arc **a, int n ) +{ + Sorter::qsort( (void *) a, n ); +} + +void +ArcSorter::qsexc( char *i, char *j )// i<-j, j<-i +{ + Arc **jarc1 = (Arc **) i; + Arc **jarc2 = (Arc **) j; + Arc *tmp = *jarc1; + *jarc1 = *jarc2; + *jarc2 = tmp; +} + +void +ArcSorter::qstexc( char *i, char *j, char *k )// i<-k, k<-j, j<-i +{ + Arc **jarc1 = (Arc **) i; + Arc **jarc2 = (Arc **) j; + Arc **jarc3 = (Arc **) k; + Arc *tmp = *jarc1; + *jarc1 = *jarc3; + *jarc3 = *jarc2; + *jarc2 = tmp; +} + + +ArcSdirSorter::ArcSdirSorter( Subdivider &s ) : ArcSorter(s) +{ +} + +int +ArcSdirSorter::qscmp( char *i, char *j ) +{ + Arc *jarc1 = *(Arc **) i; + Arc *jarc2 = *(Arc **) j; + + int v1 = (jarc1->getitail() ? 0 : (jarc1->pwlArc->npts - 1)); + int v2 = (jarc2->getitail() ? 0 : (jarc2->pwlArc->npts - 1)); + + REAL diff = jarc1->pwlArc->pts[v1].param[1] - + jarc2->pwlArc->pts[v2].param[1]; + + if( diff < 0.0) + return -1; + else if( diff > 0.0) + return 1; + else { + if( v1 == 0 ) { + if( jarc2->tail()[0] < jarc1->tail()[0] ) { + return subdivider.ccwTurn_sl( jarc2, jarc1 ) ? 1 : -1; + } else { + return subdivider.ccwTurn_sr( jarc2, jarc1 ) ? -1 : 1; + } + } else { + if( jarc2->head()[0] < jarc1->head()[0] ) { + return subdivider.ccwTurn_sl( jarc1, jarc2 ) ? -1 : 1; + } else { + return subdivider.ccwTurn_sr( jarc1, jarc2 ) ? 1 : -1; + } + } + } +} + +ArcTdirSorter::ArcTdirSorter( Subdivider &s ) : ArcSorter(s) +{ +} + +/*---------------------------------------------------------------------------- + * ArcTdirSorter::qscmp - + * compare two axis monotone arcs that are incident + * to the line T == compare_value. Determine which of the + * two intersects that line with a LESSER S value. If + * jarc1 does, return 1. If jarc2 does, return -1. + *---------------------------------------------------------------------------- + */ +int +ArcTdirSorter::qscmp( char *i, char *j ) +{ + Arc *jarc1 = *(Arc **) i; + Arc *jarc2 = *(Arc **) j; + + int v1 = (jarc1->getitail() ? 0 : (jarc1->pwlArc->npts - 1)); + int v2 = (jarc2->getitail() ? 0 : (jarc2->pwlArc->npts - 1)); + + REAL diff = jarc1->pwlArc->pts[v1].param[0] - + jarc2->pwlArc->pts[v2].param[0]; + + if( diff < 0.0) + return 1; + else if( diff > 0.0) + return -1; + else { + if( v1 == 0 ) { + if (jarc2->tail()[1] < jarc1->tail()[1]) { + return subdivider.ccwTurn_tl( jarc2, jarc1 ) ? 1 : -1; + } else { + return subdivider.ccwTurn_tr( jarc2, jarc1 ) ? -1 : 1; + } + } else { + if( jarc2->head()[1] < jarc1->head()[1] ) { + return subdivider.ccwTurn_tl( jarc1, jarc2 ) ? -1 : 1; + } else { + return subdivider.ccwTurn_tr( jarc1, jarc2 ) ? 1 : -1; + } + } + } +} + + + +#endif /* __gluarcsorter_c_ */ diff --git a/src/glu/sgi/libnurbs/internals/arcsorter.h b/src/glu/sgi/libnurbs/internals/arcsorter.h new file mode 100644 index 0000000..a55df92 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/arcsorter.h @@ -0,0 +1,72 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * arcsorter.h + * + */ + +#ifndef __gluarcsorter_h_ +#define __gluarcsorter_h_ + +#include "sorter.h" + +class Arc; +class Subdivider; + +class ArcSorter : private Sorter { +public: + ArcSorter(Subdivider &); + void qsort( Arc **a, int n ); +protected: + virtual int qscmp( char *, char * ); + Subdivider& subdivider; +private: + void qsexc( char *i, char *j ); // i<-j, j<-i + void qstexc( char *i, char *j, char *k ); // i<-k, k<-j, j<-i +}; + + +class ArcSdirSorter : public ArcSorter { +public: + ArcSdirSorter( Subdivider & ); +private: + int qscmp( char *, char * ); +}; + + +class ArcTdirSorter : public ArcSorter { +public: + ArcTdirSorter( Subdivider & ); +private: + int qscmp( char *, char * ); +}; + +#endif /* __gluarcsorter_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/arctess.cc b/src/glu/sgi/libnurbs/internals/arctess.cc new file mode 100644 index 0000000..29e7cf4 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/arctess.cc @@ -0,0 +1,611 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * arctessellator.c++ + * + */ + +#include "glimports.h" +#include "mystdio.h" +#include "myassert.h" +#include "arctess.h" +#include "bufpool.h" +#include "simplemath.h" +#include "bezierarc.h" +#include "trimvertex.h" +#include "trimvertpool.h" + +#define NOELIMINATION + +#define steps_function(large, small, rate) (max(1, 1+ (int) ((large-small)/rate))); + +/*----------------------------------------------------------------------------- + * ArcTessellator - construct an ArcTessellator + *----------------------------------------------------------------------------- + */ + +ArcTessellator::ArcTessellator( TrimVertexPool& t, Pool& p ) + : pwlarcpool(p), trimvertexpool(t) +{ +} + +/*----------------------------------------------------------------------------- + * ~ArcTessellator - destroy an ArcTessellator + *----------------------------------------------------------------------------- + */ + +ArcTessellator::~ArcTessellator( void ) +{ +} + +/*----------------------------------------------------------------------------- + * bezier - construct a bezier arc and attach it to an Arc + *----------------------------------------------------------------------------- + */ + +void +ArcTessellator::bezier( Arc *arc, REAL s1, REAL s2, REAL t1, REAL t2 ) +{ + assert( arc != 0 ); + assert( ! arc->isTessellated() ); + +#ifndef NDEBUG + switch( arc->getside() ) { + case arc_left: + assert( s1 == s2 ); + assert( t2 < t1 ); + break; + case arc_right: + assert( s1 == s2 ); + assert( t1 < t2 ); + break; + case arc_top: + assert( t1 == t2 ); + assert( s2 < s1 ); + break; + case arc_bottom: + assert( t1 == t2 ); + assert( s1 < s2 ); + break; + case arc_none: + (void) abort(); + break; + } +#endif + + TrimVertex *p = trimvertexpool.get(2); + arc->pwlArc = new(pwlarcpool) PwlArc( 2, p ); + p[0].param[0] = s1; + p[0].param[1] = t1; + p[1].param[0] = s2; + p[1].param[1] = t2; + assert( (s1 == s2) || (t1 == t2) ); + arc->setbezier(); +} + + +/*----------------------------------------------------------------------------- + * pwl_left - construct a left boundary pwl arc and attach it to an arc + *----------------------------------------------------------------------------- + */ + +void +ArcTessellator::pwl_left( Arc *arc, REAL s, REAL t1, REAL t2, REAL rate ) +{ + assert( t2 < t1 ); + +/* if(rate <= 0.06) rate = 0.06;*/ +/* int nsteps = 1 + (int) ((t1 - t2) / rate ); */ + int nsteps = steps_function(t1, t2, rate); + + + REAL stepsize = (t1 - t2) / (REAL) nsteps; + + TrimVertex *newvert = trimvertexpool.get( nsteps+1 ); + int i; + for( i = nsteps; i > 0; i-- ) { + newvert[i].param[0] = s; + newvert[i].param[1] = t2; + t2 += stepsize; + } + newvert[i].param[0] = s; + newvert[i].param[1] = t1; + + arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_left ); +} + +/*----------------------------------------------------------------------------- + * pwl_right - construct a right boundary pwl arc and attach it to an arc + *----------------------------------------------------------------------------- + */ + +void +ArcTessellator::pwl_right( Arc *arc, REAL s, REAL t1, REAL t2, REAL rate ) +{ + assert( t1 < t2 ); + +/* if(rate <= 0.06) rate = 0.06;*/ + +/* int nsteps = 1 + (int) ((t2 - t1) / rate ); */ + int nsteps = steps_function(t2,t1,rate); + REAL stepsize = (t2 - t1) / (REAL) nsteps; + + TrimVertex *newvert = trimvertexpool.get( nsteps+1 ); + int i; + for( i = 0; i < nsteps; i++ ) { + newvert[i].param[0] = s; + newvert[i].param[1] = t1; + t1 += stepsize; + } + newvert[i].param[0] = s; + newvert[i].param[1] = t2; + + arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_right ); +} + + +/*----------------------------------------------------------------------------- + * pwl_top - construct a top boundary pwl arc and attach it to an arc + *----------------------------------------------------------------------------- + */ + +void +ArcTessellator::pwl_top( Arc *arc, REAL t, REAL s1, REAL s2, REAL rate ) +{ + assert( s2 < s1 ); + +/* if(rate <= 0.06) rate = 0.06;*/ + +/* int nsteps = 1 + (int) ((s1 - s2) / rate ); */ + int nsteps = steps_function(s1,s2,rate); + REAL stepsize = (s1 - s2) / (REAL) nsteps; + + TrimVertex *newvert = trimvertexpool.get( nsteps+1 ); + int i; + for( i = nsteps; i > 0; i-- ) { + newvert[i].param[0] = s2; + newvert[i].param[1] = t; + s2 += stepsize; + } + newvert[i].param[0] = s1; + newvert[i].param[1] = t; + + arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_top ); +} + +/*----------------------------------------------------------------------------- + * pwl_bottom - construct a bottom boundary pwl arc and attach it to an arc + *----------------------------------------------------------------------------- + */ + +void +ArcTessellator::pwl_bottom( Arc *arc, REAL t, REAL s1, REAL s2, REAL rate ) +{ + assert( s1 < s2 ); + +/* if(rate <= 0.06) rate = 0.06;*/ + +/* int nsteps = 1 + (int) ((s2 - s1) / rate ); */ + int nsteps = steps_function(s2,s1,rate); + REAL stepsize = (s2 - s1) / (REAL) nsteps; + + TrimVertex *newvert = trimvertexpool.get( nsteps+1 ); + int i; + for( i = 0; i < nsteps; i++ ) { + newvert[i].param[0] = s1; + newvert[i].param[1] = t; + s1 += stepsize; + } + newvert[i].param[0] = s2; + newvert[i].param[1] = t; + + arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_bottom ); +} + +/*----------------------------------------------------------------------------- + * pwl - construct a pwl arc and attach it to an arc + *----------------------------------------------------------------------------- + */ + +void +ArcTessellator::pwl( Arc *arc, REAL s1, REAL s2, REAL t1, REAL t2, REAL rate ) +{ + +/* if(rate <= 0.06) rate = 0.06;*/ + + int snsteps = 1 + (int) (glu_abs(s2 - s1) / rate ); + int tnsteps = 1 + (int) (glu_abs(t2 - t1) / rate ); + int nsteps = max(1,max( snsteps, tnsteps )); + + REAL sstepsize = (s2 - s1) / (REAL) nsteps; + REAL tstepsize = (t2 - t1) / (REAL) nsteps; + TrimVertex *newvert = trimvertexpool.get( nsteps+1 ); + long i; + for( i = 0; i < nsteps; i++ ) { + newvert[i].param[0] = s1; + newvert[i].param[1] = t1; + s1 += sstepsize; + t1 += tstepsize; + } + newvert[i].param[0] = s2; + newvert[i].param[1] = t2; + + /* arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_bottom ); */ + arc->pwlArc = new(pwlarcpool) PwlArc( nsteps+1, newvert ); + + arc->clearbezier(); + arc->clearside( ); +} + + +/*----------------------------------------------------------------------------- + * tessellateLinear - constuct a linear pwl arc and attach it to an Arc + *----------------------------------------------------------------------------- + */ + +void +ArcTessellator::tessellateLinear( Arc *arc, REAL geo_stepsize, REAL arc_stepsize, int isrational ) +{ + assert( arc->pwlArc == NULL ); + REAL s1, s2, t1, t2; + + //we don't need to scale by arc_stepsize if the trim curve + //is piecewise linear. Reason: In pwl_right, pwl_left, pwl_top, pwl_left, + //and pwl, the nsteps is computed by deltaU (or V) /stepsize. + //The quantity deltaU/arc_stepsize doesn't have any meaning. And + //it causes problems: see bug 517641 + REAL stepsize = geo_stepsize; /* * arc_stepsize*/; + + BezierArc *b = arc->bezierArc; + + if( isrational ) { + s1 = b->cpts[0] / b->cpts[2]; + t1 = b->cpts[1] / b->cpts[2]; + s2 = b->cpts[b->stride+0] / b->cpts[b->stride+2]; + t2 = b->cpts[b->stride+1] / b->cpts[b->stride+2]; + } else { + s1 = b->cpts[0]; + t1 = b->cpts[1]; + s2 = b->cpts[b->stride+0]; + t2 = b->cpts[b->stride+1]; + } + if( s1 == s2 ) + if( t1 < t2 ) + pwl_right( arc, s1, t1, t2, stepsize ); + else + pwl_left( arc, s1, t1, t2, stepsize ); + else if( t1 == t2 ) + if( s1 < s2 ) + pwl_bottom( arc, t1, s1, s2, stepsize ); + else + pwl_top( arc, t1, s1, s2, stepsize ); + else + pwl( arc, s1, s2, t1, t2, stepsize ); +} + +/*----------------------------------------------------------------------------- + * tessellateNonlinear - constuct a nonlinear pwl arc and attach it to an Arc + *----------------------------------------------------------------------------- + */ + +void +ArcTessellator::tessellateNonlinear( Arc *arc, REAL geo_stepsize, REAL arc_stepsize, int isrational ) +{ + assert( arc->pwlArc == NULL ); + + REAL stepsize = geo_stepsize * arc_stepsize; + + BezierArc *bezierArc = arc->bezierArc; + + REAL size; //bounding box size of the curve in UV + { + int i,j; + REAL min_u, min_v, max_u,max_v; + min_u = max_u = bezierArc->cpts[0]; + min_v = max_v = bezierArc->cpts[1]; + for(i=1, j=bezierArc->stride; iorder; i++, j+= bezierArc->stride) + { + if(bezierArc->cpts[j] < min_u) + min_u = bezierArc->cpts[j]; + if(bezierArc->cpts[j] > max_u) + max_u = bezierArc->cpts[j]; + if(bezierArc->cpts[j+1] < min_v) + min_v = bezierArc->cpts[j+1]; + if(bezierArc->cpts[j+1] > max_v) + max_v = bezierArc->cpts[j+1]; + } + + size = max_u - min_u; + if(size < max_v - min_v) + size = max_v - min_v; + } + + /*int nsteps = 1 + (int) (1.0/stepsize);*/ + + int nsteps = (int) (size/stepsize); + if(nsteps <=0) + nsteps=1; + + TrimVertex *vert = trimvertexpool.get( nsteps+1 ); + REAL dp = 1.0/nsteps; + + + arc->pwlArc = new(pwlarcpool) PwlArc(); + arc->pwlArc->pts = vert; + + if( isrational ) { + REAL pow_u[MAXORDER], pow_v[MAXORDER], pow_w[MAXORDER]; + trim_power_coeffs( bezierArc, pow_u, 0 ); + trim_power_coeffs( bezierArc, pow_v, 1 ); + trim_power_coeffs( bezierArc, pow_w, 2 ); + + /* compute first point exactly */ + REAL *b = bezierArc->cpts; + vert->param[0] = b[0]/b[2]; + vert->param[1] = b[1]/b[2]; + + /* strength reduction on p = dp * step would introduce error */ + int step; +#ifndef NOELIMINATION + int ocanremove = 0; +#endif + register long order = bezierArc->order; + for( step=1, ++vert; stepparam[0] = u/w; + vert->param[1] = v/w; +#ifndef NOELIMINATION + REAL ds = glu_abs(vert[0].param[0] - vert[-1].param[0]); + REAL dt = glu_abs(vert[0].param[1] - vert[-1].param[1]); + int canremove = (dsstride; + vert->param[0] = b[0]/b[2]; + vert->param[1] = b[1]/b[2]; + + } else { + REAL pow_u[MAXORDER], pow_v[MAXORDER]; + trim_power_coeffs( bezierArc, pow_u, 0 ); + trim_power_coeffs( bezierArc, pow_v, 1 ); + + /* compute first point exactly */ + REAL *b = bezierArc->cpts; + vert->param[0] = b[0]; + vert->param[1] = b[1]; + + /* strength reduction on p = dp * step would introduce error */ + int step; +#ifndef NOELIMINATION + int ocanremove = 0; +#endif + register long order = bezierArc->order; + for( step=1, ++vert; steporder; i++ ) { + u = u * p + pow_u[i]; + v = v * p + pow_v[i]; + } + vert->param[0] = u; + vert->param[1] = v; +#ifndef NOELIMINATION + REAL ds = glu_abs(vert[0].param[0] - vert[-1].param[0]); + REAL dt = glu_abs(vert[0].param[1] - vert[-1].param[1]); + int canremove = (dsstride; + vert->param[0] = b[0]; + vert->param[1] = b[1]; + } + arc->pwlArc->npts = vert - arc->pwlArc->pts + 1; +/* + for( TrimVertex *vt=pwlArc->pts; vt != vert-1; vt++ ) { + if( tooclose( vt[0].param[0], vt[1].param[0] ) ) + vt[1].param[0] = vt[0].param[0]; + if( tooclose( vt[0].param[1], vt[1].param[1] ) ) + vt[1].param[1] = vt[0].param[1]; + } +*/ +} + +const REAL ArcTessellator::gl_Bernstein[][MAXORDER][MAXORDER] = { + { + {1, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 } + }, + { + {-1, 1, 0, 0, 0, 0, 0, 0 }, + {1, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 } + }, + { + {1, -2, 1, 0, 0, 0, 0, 0 }, + {-2, 2, 0, 0, 0, 0, 0, 0 }, + {1, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 } + }, + { + {-1, 3, -3, 1, 0, 0, 0, 0 }, + {3, -6, 3, 0, 0, 0, 0, 0 }, + {-3, 3, 0, 0, 0, 0, 0, 0 }, + {1, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 } + }, + { + {1, -4, 6, -4, 1, 0, 0, 0 }, + {-4, 12, -12, 4, 0, 0, 0, 0 }, + {6, -12, 6, 0, 0, 0, 0, 0 }, + {-4, 4, 0, 0, 0, 0, 0, 0 }, + {1, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 } + }, + { + {-1, 5, -10, 10, -5, 1, 0, 0 }, + {5, -20, 30, -20, 5, 0, 0, 0 }, + {-10, 30, -30, 10, 0, 0, 0, 0 }, + {10, -20, 10, 0, 0, 0, 0, 0 }, + {-5, 5, 0, 0, 0, 0, 0, 0 }, + {1, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 } + }, + { + {1, -6, 15, -20, 15, -6, 1, 0 }, + {-6, 30, -60, 60, -30, 6, 0, 0 }, + {15, -60, 90, -60, 15, 0, 0, 0 }, + {-20, 60, -60, 20, 0, 0, 0, 0 }, + {15, -30, 15, 0, 0, 0, 0, 0 }, + {-6, 6, 0, 0, 0, 0, 0, 0 }, + {1, 0, 0, 0, 0, 0, 0, 0 }, + {0, 0, 0, 0, 0, 0, 0, 0 } + }, + { + {-1, 7, -21, 35, -35, 21, -7, 1 }, + {7, -42, 105, -140, 105, -42, 7, 0 }, + {-21, 105, -210, 210, -105, 21, 0, 0 }, + {35, -140, 210, -140, 35, 0, 0, 0 }, + {-35, 105, -105, 35, 0, 0, 0, 0 }, + {21, -42, 21, 0, 0, 0, 0, 0 }, + {-7, 7, 0, 0, 0, 0, 0, 0 }, + {1, 0, 0, 0, 0, 0, 0, 0 } + }}; + + +/*----------------------------------------------------------------------------- + * trim_power_coeffs - compute power basis coefficients from bezier coeffients + *----------------------------------------------------------------------------- + */ +void +ArcTessellator::trim_power_coeffs( BezierArc *bez_arc, REAL *p, int coord ) +{ + register int stride = bez_arc->stride; + register int order = bez_arc->order; + register REAL *base = bez_arc->cpts + coord; + + REAL const (*mat)[MAXORDER][MAXORDER] = &gl_Bernstein[order-1]; + REAL const (*lrow)[MAXORDER] = &(*mat)[order]; + + /* WIN32 didn't like the following line within the for-loop */ + REAL const (*row)[MAXORDER] = &(*mat)[0]; + for( ; row != lrow; row++ ) { + register REAL s = 0.0; + register REAL *point = base; + register REAL const *mlast = *row + order; + for( REAL const *m = *row; m != mlast; m++, point += stride ) + s += *(m) * (*point); + *(p++) = s; + } +} diff --git a/src/glu/sgi/libnurbs/internals/arctess.h b/src/glu/sgi/libnurbs/internals/arctess.h new file mode 100644 index 0000000..7802af9 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/arctess.h @@ -0,0 +1,66 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * arctess.h + * + */ + +#ifndef __gluarctess_h_ +#define __gluarctess_h_ + +#include "defines.h" +#include "types.h" +#include "arc.h" + +struct BezierArc; +class Pool; +class TrimVertexPool; + +class ArcTessellator { +public: + ArcTessellator( TrimVertexPool&, Pool& ); + ~ArcTessellator( void ); + void bezier( Arc_ptr, REAL, REAL, REAL, REAL ); + void pwl( Arc_ptr, REAL, REAL, REAL, REAL, REAL ); + void pwl_left( Arc_ptr, REAL, REAL, REAL, REAL ); + void pwl_right( Arc_ptr, REAL, REAL, REAL, REAL ); + void pwl_top( Arc_ptr, REAL, REAL, REAL, REAL ); + void pwl_bottom( Arc_ptr, REAL, REAL, REAL, REAL ); + void tessellateLinear( Arc_ptr, REAL, REAL, int ); + void tessellateNonlinear( Arc_ptr, REAL, REAL, int ); +private: + static const REAL gl_Bernstein[][MAXORDER][MAXORDER]; + Pool& pwlarcpool; + TrimVertexPool& trimvertexpool; + static void trim_power_coeffs( BezierArc *, REAL[MAXORDER], int ); +}; + +#endif /* __gluarctess_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/backend.cc b/src/glu/sgi/libnurbs/internals/backend.cc new file mode 100644 index 0000000..27b41eb --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/backend.cc @@ -0,0 +1,588 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * backend.c++ + * + */ + +/* Bezier surface backend + - interprets display mode (wireframe,shaded,...) +*/ +#include +#include "glimports.h" +#include "mystdio.h" +#include "backend.h" +#include "basiccrveval.h" +#include "basicsurfeval.h" + +#define NOWIREFRAME + + +/*------------------------------------------------------------------------- + * bgnsurf - preamble to surface definition and evaluations + *------------------------------------------------------------------------- + */ +void +Backend::bgnsurf( int wiretris, int wirequads, long nuid ) +{ +/*#ifndef NOWIREFRAME*/ //need this for old version + wireframetris = wiretris; + wireframequads = wirequads; +/*#endif*/ + + /*in the spec, GLU_DISPLAY_MODE is either + * GLU_FILL + * GLU_OUTLINE_POLY + * GLU_OUTLINE_PATCH. + *In fact, GLU_FLL is has the same effect as + * set GL_FRONT_AND_BACK to be GL_FILL + * and GLU_OUTLINE_POLY is the same as set + * GL_FRONT_AND_BACK to be GL_LINE + *It is more efficient to do this once at the beginning of + *each surface than to do it for each primitive. + * The internal has more options: outline_triangle and outline_quad + *can be seperated. But since this is not in spec, and more importantly, + *this is not so useful, so we don't need to keep this option. + */ + + surfaceEvaluator.bgnmap2f( nuid ); + + if(wiretris) + surfaceEvaluator.polymode(N_MESHLINE); + else + surfaceEvaluator.polymode(N_MESHFILL); +} + +void +Backend::patch( REAL ulo, REAL uhi, REAL vlo, REAL vhi ) +{ + surfaceEvaluator.domain2f( ulo, uhi, vlo, vhi ); +} + +void +Backend::surfbbox( long type, REAL *from, REAL *to ) +{ + surfaceEvaluator.range2f( type, from, to ); +} + +/*------------------------------------------------------------------------- + * surfpts - pass a desription of a surface map + *------------------------------------------------------------------------- + */ +void +Backend::surfpts( + long type, /* geometry, color, texture, normal */ + REAL *pts, /* control points */ + long ustride, /* distance to next point in u direction */ + long vstride, /* distance to next point in v direction */ + int uorder, /* u parametric order */ + int vorder, /* v parametric order */ + REAL ulo, /* u lower bound */ + REAL uhi, /* u upper bound */ + REAL vlo, /* v lower bound */ + REAL vhi ) /* v upper bound */ +{ + surfaceEvaluator.map2f( type,ulo,uhi,ustride,uorder,vlo,vhi,vstride,vorder,pts ); + surfaceEvaluator.enable( type ); +} + +/*------------------------------------------------------------------------- + * surfgrid - define a lattice of points with origin and offset + *------------------------------------------------------------------------- + */ +void +Backend::surfgrid( REAL u0, REAL u1, long nu, REAL v0, REAL v1, long nv ) +{ + surfaceEvaluator.mapgrid2f( nu, u0, u1, nv, v0, v1 ); +} + +/*------------------------------------------------------------------------- + * surfmesh - evaluate a mesh of points on lattice + *------------------------------------------------------------------------- + */ +void +Backend::surfmesh( long u, long v, long n, long m ) +{ +#ifndef NOWIREFRAME + if( wireframequads ) { + long v0, v1; + long u0f = u, u1f = u+n; + long v0f = v, v1f = v+m; + long parity = (u & 1); + + for( v0 = v0f, v1 = v0f++ ; v0isGridVert() ) { + tmeshvert( v->g ); + } else { + tmeshvert( v->t ); + } +} + +void +Backend::tmeshvertNOGE(TrimVertex *t) +{ +// surfaceEvaluator.inDoEvalCoord2NOGE( t->param[0], t->param[1], temp, ttt); +#ifdef USE_OPTTT + surfaceEvaluator.inDoEvalCoord2NOGE( t->param[0], t->param[1], t->cache_point, t->cache_normal); +#endif +} + +//opt for a line with the same u. +void +Backend::tmeshvertNOGE_BU(TrimVertex *t) +{ +#ifdef USE_OPTTT + surfaceEvaluator.inDoEvalCoord2NOGE_BU( t->param[0], t->param[1], t->cache_point, t->cache_normal); +#endif +} + +//opt for a line with the same v. +void +Backend::tmeshvertNOGE_BV(TrimVertex *t) +{ +#ifdef USE_OPTTT + surfaceEvaluator.inDoEvalCoord2NOGE_BV( t->param[0], t->param[1], t->cache_point, t->cache_normal); +#endif +} + +void +Backend::preEvaluateBU(REAL u) +{ + surfaceEvaluator.inPreEvaluateBU_intfac(u); +} + +void +Backend::preEvaluateBV(REAL v) +{ + surfaceEvaluator.inPreEvaluateBV_intfac(v); +} + + +/*------------------------------------------------------------------------- + * tmeshvert - evaluate a point on a triangle mesh + *------------------------------------------------------------------------- + */ +void +Backend::tmeshvert( TrimVertex *t ) +{ + +#ifndef NOWIREFRAME + const long nuid = t->nuid; +#endif + const REAL u = t->param[0]; + const REAL v = t->param[1]; + +#ifndef NOWIREFRAME + npts++; + if( wireframetris ) { + if( npts >= 3 ) { + surfaceEvaluator.bgnclosedline(); + if( mesh[0][2] == 0 ) + surfaceEvaluator.evalcoord2f( mesh[0][3], mesh[0][0], mesh[0][1] ); + else + surfaceEvaluator.evalpoint2i( (long) mesh[0][0], (long) mesh[0][1] ); + if( mesh[1][2] == 0 ) + surfaceEvaluator.evalcoord2f( mesh[1][3], mesh[1][0], mesh[1][1] ); + else + surfaceEvaluator.evalpoint2i( (long) mesh[1][0], (long) mesh[1][1] ); + surfaceEvaluator.evalcoord2f( nuid, u, v ); + surfaceEvaluator.endclosedline(); + } + mesh[meshindex][0] = u; + mesh[meshindex][1] = v; + mesh[meshindex][2] = 0; + mesh[meshindex][3] = nuid; + meshindex = (meshindex+1) % 2; + } else { + surfaceEvaluator.evalcoord2f( nuid, u, v ); + } +#else + + surfaceEvaluator.evalcoord2f( 0, u, v ); +//for uninitial memory read surfaceEvaluator.evalcoord2f( nuid, u, v ); +#endif +} + +//the same as tmeshvert(trimvertex), for efficiency purpose +void +Backend::tmeshvert( REAL u, REAL v ) +{ +#ifndef NOWIREFRAME + const long nuid = 0; + + npts++; + if( wireframetris ) { + if( npts >= 3 ) { + surfaceEvaluator.bgnclosedline(); + if( mesh[0][2] == 0 ) + surfaceEvaluator.evalcoord2f( mesh[0][3], mesh[0][0], mesh[0][1] ); + else + surfaceEvaluator.evalpoint2i( (long) mesh[0][0], (long) mesh[0][1] ); + if( mesh[1][2] == 0 ) + surfaceEvaluator.evalcoord2f( mesh[1][3], mesh[1][0], mesh[1][1] ); + else + surfaceEvaluator.evalpoint2i( (long) mesh[1][0], (long) mesh[1][1] ); + surfaceEvaluator.evalcoord2f( nuid, u, v ); + surfaceEvaluator.endclosedline(); + } + mesh[meshindex][0] = u; + mesh[meshindex][1] = v; + mesh[meshindex][2] = 0; + mesh[meshindex][3] = nuid; + meshindex = (meshindex+1) % 2; + } else { + surfaceEvaluator.evalcoord2f( nuid, u, v ); + } +#else + + surfaceEvaluator.evalcoord2f( 0, u, v ); +#endif +} + +/*------------------------------------------------------------------------- + * tmeshvert - evaluate a grid point of a triangle mesh + *------------------------------------------------------------------------- + */ +void +Backend::tmeshvert( GridVertex *g ) +{ + const long u = g->gparam[0]; + const long v = g->gparam[1]; + +#ifndef NOWIREFRAME + npts++; + if( wireframetris ) { + if( npts >= 3 ) { + surfaceEvaluator.bgnclosedline(); + if( mesh[0][2] == 0 ) + surfaceEvaluator.evalcoord2f( (long) mesh[0][3], mesh[0][0], mesh[0][1] ); + else + surfaceEvaluator.evalpoint2i( (long) mesh[0][0], (long) mesh[0][1] ); + if( mesh[1][2] == 0 ) + surfaceEvaluator.evalcoord2f( (long) mesh[1][3], mesh[1][0], mesh[1][1] ); + else + surfaceEvaluator.evalpoint2i( (long) mesh[1][0], (long) mesh[1][1] ); + surfaceEvaluator.evalpoint2i( u, v ); + surfaceEvaluator.endclosedline(); + } + mesh[meshindex][0] = u; + mesh[meshindex][1] = v; + mesh[meshindex][2] = 1; + meshindex = (meshindex+1) % 2; + } else { + surfaceEvaluator.evalpoint2i( u, v ); + } +#else + surfaceEvaluator.evalpoint2i( u, v ); +#endif +} + +/*------------------------------------------------------------------------- + * swaptmesh - perform a swap of the triangle mesh pointers + *------------------------------------------------------------------------- + */ +void +Backend::swaptmesh( void ) +{ +#ifndef NOWIREFRAME + if( wireframetris ) { + meshindex = 1 - meshindex; + } else { + surfaceEvaluator.swaptmesh(); + } +#else + surfaceEvaluator.swaptmesh(); +#endif +} + +/*------------------------------------------------------------------------- + * endtmesh - postamble to triangle mesh + *------------------------------------------------------------------------- + */ +void +Backend::endtmesh( void ) +{ +#ifndef NOWIREFRAME + if( ! wireframetris ) + surfaceEvaluator.endtmesh(); +#else + surfaceEvaluator.endtmesh(); +/* surfaceEvaluator.polymode( N_MESHFILL );*/ +#endif +} + + +/*------------------------------------------------------------------------- + * bgnoutline - preamble to outlined rendering + *------------------------------------------------------------------------- + */ +void +Backend::bgnoutline( void ) +{ + surfaceEvaluator.bgnline(); +} + +/*------------------------------------------------------------------------- + * linevert - evaluate a point on an outlined contour + *------------------------------------------------------------------------- + */ +void +Backend::linevert( TrimVertex *t ) +{ + surfaceEvaluator.evalcoord2f( t->nuid, t->param[0], t->param[1] ); +} + +/*------------------------------------------------------------------------- + * linevert - evaluate a grid point of an outlined contour + *------------------------------------------------------------------------- + */ +void +Backend::linevert( GridVertex *g ) +{ + surfaceEvaluator.evalpoint2i( g->gparam[0], g->gparam[1] ); +} + +/*------------------------------------------------------------------------- + * endoutline - postamble to outlined rendering + *------------------------------------------------------------------------- + */ +void +Backend::endoutline( void ) +{ + surfaceEvaluator.endline(); +} + +/*------------------------------------------------------------------------- + * triangle - output a triangle + *------------------------------------------------------------------------- + */ +void +Backend::triangle( TrimVertex *a, TrimVertex *b, TrimVertex *c ) +{ +/* bgntmesh( "spittriangle" );*/ + bgntfan(); + tmeshvert( a ); + tmeshvert( b ); + tmeshvert( c ); + endtfan(); +/* endtmesh();*/ +} + +void +Backend::bgncurv( void ) +{ + curveEvaluator.bgnmap1f( 0 ); +} + +void +Backend::segment( REAL ulo, REAL uhi ) +{ + curveEvaluator.domain1f( ulo, uhi ); +} + +void +Backend::curvpts( + long type, /* geometry, color, texture, normal */ + REAL *pts, /* control points */ + long stride, /* distance to next point */ + int order, /* parametric order */ + REAL ulo, /* lower parametric bound */ + REAL uhi ) /* upper parametric bound */ + +{ + curveEvaluator.map1f( type, ulo, uhi, stride, order, pts ); + curveEvaluator.enable( type ); +} + +void +Backend::curvgrid( REAL u0, REAL u1, long nu ) +{ + curveEvaluator.mapgrid1f( nu, u0, u1 ); +} + +void +Backend::curvmesh( long from, long n ) +{ + curveEvaluator.mapmesh1f( N_MESHFILL, from, from+n ); +} + +void +Backend::curvpt(REAL u) +{ + curveEvaluator.evalcoord1f( 0, u ); +} + +void +Backend::bgnline( void ) +{ + curveEvaluator.bgnline(); +} + +void +Backend::endline( void ) +{ + curveEvaluator.endline(); +} + +void +Backend::endcurv( void ) +{ + curveEvaluator.endmap1f(); +} diff --git a/src/glu/sgi/libnurbs/internals/backend.h b/src/glu/sgi/libnurbs/internals/backend.h new file mode 100644 index 0000000..6840cb1 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/backend.h @@ -0,0 +1,113 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * backend.h + * + */ + +#ifndef __glubackend_h_ +#define __glubackend_h_ + +#include "trimvertex.h" +#include "gridvertex.h" +#include "gridtrimvertex.h" + +class BasicCurveEvaluator; +class BasicSurfaceEvaluator; + +class Backend { +private: + BasicCurveEvaluator& curveEvaluator; + BasicSurfaceEvaluator& surfaceEvaluator; +public: + Backend( BasicCurveEvaluator &c, BasicSurfaceEvaluator& e ) + : curveEvaluator(c), surfaceEvaluator(e) {} + + /* surface backend routines */ + void bgnsurf( int, int, long ); + void patch( REAL, REAL, REAL, REAL ); + void surfpts( long, REAL *, long, long, int, int, + REAL, REAL, REAL, REAL ); + void surfbbox( long, REAL *, REAL * ); + void surfgrid( REAL, REAL, long, REAL, REAL, long ); + void surfmesh( long, long, long, long ); + void bgntmesh( const char * ); + void endtmesh( void ); + void swaptmesh( void ); + void tmeshvert( GridTrimVertex * ); + void tmeshvert( TrimVertex * ); + void tmeshvert( GridVertex * ); + void tmeshvert( REAL u, REAL v ); + void linevert( TrimVertex * ); + void linevert( GridVertex * ); + void bgnoutline( void ); + void endoutline( void ); + void endsurf( void ); + void triangle( TrimVertex*, TrimVertex*, TrimVertex* ); + + void bgntfan(); + void endtfan(); + void bgnqstrip(); + void endqstrip(); + void evalUStrip(int n_upper, REAL v_upper, REAL* upper_val, + int n_lower, REAL v_lower, REAL* lower_val + ); + void evalVStrip(int n_left, REAL u_left, REAL* left_val, + int n_right, REAL v_right, REAL* right_val + ); + void tmeshvertNOGE(TrimVertex *t); + void tmeshvertNOGE_BU(TrimVertex *t); + void tmeshvertNOGE_BV(TrimVertex *t); + void preEvaluateBU(REAL u); + void preEvaluateBV(REAL v); + + + /* curve backend routines */ + void bgncurv( void ); + void segment( REAL, REAL ); + void curvpts( long, REAL *, long, int, REAL, REAL ); + void curvgrid( REAL, REAL, long ); + void curvmesh( long, long ); + void curvpt( REAL ); + void bgnline( void ); + void endline( void ); + void endcurv( void ); +private: +#ifndef NOWIREFRAME + int wireframetris; + int wireframequads; + int npts; + REAL mesh[3][4]; + int meshindex; +#endif +}; + +#endif /* __glubackend_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/basiccrveval.cc b/src/glu/sgi/libnurbs/internals/basiccrveval.cc new file mode 100644 index 0000000..cc473e4 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/basiccrveval.cc @@ -0,0 +1,138 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * basiccrveval.c++ + * + */ + +#include "mystdio.h" +#include "types.h" +#include "basiccrveval.h" + +void +BasicCurveEvaluator::domain1f( REAL, REAL ) +{ +#ifndef NDEBUG + _glu_dprintf( "domain1f\n" ); +#endif +} + +void +BasicCurveEvaluator::range1f( long , REAL *, REAL * ) +{ +#ifndef NDEBUG + _glu_dprintf( "range1f\n" ); +#endif +} + +void +BasicCurveEvaluator::enable( long ) +{ +#ifndef NDEBUG + _glu_dprintf( "enable\n" ); +#endif +} + +void +BasicCurveEvaluator::disable( long ) +{ +#ifndef NDEBUG + _glu_dprintf( "disable\n" ); +#endif +} + +void +BasicCurveEvaluator::bgnmap1f( long ) +{ +#ifndef NDEBUG + _glu_dprintf( "bgnmap1f\n" ); +#endif +} + +void +BasicCurveEvaluator::map1f( long, REAL, REAL, long, long, REAL * ) +{ +#ifndef NDEBUG + _glu_dprintf( "map1f\n" ); +#endif +} + +void +BasicCurveEvaluator::mapgrid1f( long, REAL, REAL ) +{ +#ifndef NDEBUG + _glu_dprintf( "mapgrid1f\n" ); +#endif +} + +void +BasicCurveEvaluator::mapmesh1f( long, long, long ) +{ +#ifndef NDEBUG + _glu_dprintf( "mapmesh1f\n" ); +#endif +} + +void +BasicCurveEvaluator::evalcoord1f( long, REAL ) +{ +#ifndef NDEBUG + _glu_dprintf( "evalcoord1f\n" ); +#endif +} + +void +BasicCurveEvaluator::endmap1f( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "endmap1f\n" ); +#endif +} + +void +BasicCurveEvaluator::bgnline( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "bgnline\n" ); +#endif +} + +void +BasicCurveEvaluator::endline( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "endline\n" ); +#endif +} diff --git a/src/glu/sgi/libnurbs/internals/basiccrveval.h b/src/glu/sgi/libnurbs/internals/basiccrveval.h new file mode 100644 index 0000000..277dc8d --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/basiccrveval.h @@ -0,0 +1,62 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * basiccurveeval.h + * + */ + +#ifndef __glubasiccrveval_h_ +#define __glubasiccrveval_h_ + +#include "types.h" +#include "displaymode.h" +#include "cachingeval.h" + +class BasicCurveEvaluator : public CachingEvaluator { +public: + virtual ~BasicCurveEvaluator() { /* silence warning*/ } + virtual void domain1f( REAL, REAL ); + virtual void range1f( long, REAL *, REAL * ); + + virtual void enable( long ); + virtual void disable( long ); + virtual void bgnmap1f( long ); + virtual void map1f( long, REAL, REAL, long, long, REAL * ); + virtual void mapgrid1f( long, REAL, REAL ); + virtual void mapmesh1f( long, long, long ); + virtual void evalcoord1f( long, REAL ); + virtual void endmap1f( void ); + + virtual void bgnline( void ); + virtual void endline( void ); +}; + +#endif /* __glubasiccrveval_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/basicsurfeval.cc b/src/glu/sgi/libnurbs/internals/basicsurfeval.cc new file mode 100644 index 0000000..fad5dd0 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/basicsurfeval.cc @@ -0,0 +1,232 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * basicsurfaceevaluator.c++ + * + */ + +#include "mystdio.h" +#include "types.h" +#include "basicsurfeval.h" + +#ifdef __WATCOMC__ +#pragma warning 726 10 +#endif + +void +BasicSurfaceEvaluator::domain2f( REAL, REAL, REAL, REAL ) +{ +#ifndef NDEBUG + _glu_dprintf( "domain2f\n" ); +#endif +} + +void +BasicSurfaceEvaluator::polymode( long ) +{ +#ifndef NDEBUG + _glu_dprintf( "polymode\n" ); +#endif +} + +void +BasicSurfaceEvaluator::range2f( long type, REAL *from, REAL *to ) +{ +#ifndef NDEBUG + _glu_dprintf( "range2f type %ld, from (%g,%g), to (%g,%g)\n", + type, from[0], from[1], to[0], to[1] ); +#endif +} + +void +BasicSurfaceEvaluator::enable( long ) +{ +#ifndef NDEBUG + _glu_dprintf( "enable\n" ); +#endif +} + +void +BasicSurfaceEvaluator::disable( long ) +{ +#ifndef NDEBUG + _glu_dprintf( "disable\n" ); +#endif +} + +void +BasicSurfaceEvaluator::bgnmap2f( long ) +{ +#ifndef NDEBUG + _glu_dprintf( "bgnmap2f\n" ); +#endif +} + +void +BasicSurfaceEvaluator::endmap2f( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "endmap2f\n" ); +#endif +} + +void +BasicSurfaceEvaluator::map2f( long, REAL, REAL, long, long, + REAL, REAL, long, long, + REAL * ) +{ +#ifndef NDEBUG + _glu_dprintf( "map2f\n" ); +#endif +} + +void +BasicSurfaceEvaluator::mapgrid2f( long, REAL, REAL, long, REAL, REAL ) +{ +#ifndef NDEBUG + _glu_dprintf( "mapgrid2f\n" ); +#endif +} + +void +BasicSurfaceEvaluator::mapmesh2f( long, long, long, long, long ) +{ +#ifndef NDEBUG + _glu_dprintf( "mapmesh2f\n" ); +#endif +} + +void +BasicSurfaceEvaluator::evalcoord2f( long, REAL, REAL ) +{ +#ifndef NDEBUG + _glu_dprintf( "evalcoord2f\n" ); +#endif +} + +void +BasicSurfaceEvaluator::evalpoint2i( long, long ) +{ +#ifndef NDEBUG + _glu_dprintf( "evalpoint2i\n" ); +#endif +} + +void +BasicSurfaceEvaluator::bgnline( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "bgnline\n" ); +#endif +} + +void +BasicSurfaceEvaluator::endline( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "endline\n" ); +#endif +} + +void +BasicSurfaceEvaluator::bgnclosedline( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "bgnclosedline\n" ); +#endif +} + +void +BasicSurfaceEvaluator::endclosedline( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "endclosedline\n" ); +#endif +} + +void +BasicSurfaceEvaluator::bgntfan( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "bgntfan\n" ); +#endif +} + +void +BasicSurfaceEvaluator::endtfan( void ) +{ +} + + +void +BasicSurfaceEvaluator::bgntmesh( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "bgntmesh\n" ); +#endif +} + +void +BasicSurfaceEvaluator::swaptmesh( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "swaptmesh\n" ); +#endif +} + +void +BasicSurfaceEvaluator::endtmesh( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "endtmesh\n" ); +#endif +} + +void +BasicSurfaceEvaluator::bgnqstrip( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "bgnqstrip\n" ); +#endif +} + +void +BasicSurfaceEvaluator::endqstrip( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "endqstrip\n" ); +#endif +} + diff --git a/src/glu/sgi/libnurbs/internals/basicsurfeval.h b/src/glu/sgi/libnurbs/internals/basicsurfeval.h new file mode 100644 index 0000000..8fe18a6 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/basicsurfeval.h @@ -0,0 +1,90 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * basicsurfeval.h + * + */ + +#ifndef __glubasicsurfeval_h_ +#define __glubasicsurfeval_h_ + +#include "types.h" +#include "displaymode.h" +#include "cachingeval.h" + +class BasicSurfaceEvaluator : public CachingEvaluator { +public: + virtual ~BasicSurfaceEvaluator() { /* silence warning*/ } + virtual void range2f( long, REAL *, REAL * ); + virtual void domain2f( REAL, REAL, REAL, REAL ); + + virtual void enable( long ); + virtual void disable( long ); + virtual void bgnmap2f( long ); + virtual void map2f( long, REAL, REAL, long, long, + REAL, REAL, long, long, + REAL * ); + virtual void mapgrid2f( long, REAL, REAL, long, REAL, REAL ); + virtual void mapmesh2f( long, long, long, long, long ); + virtual void evalcoord2f( long, REAL, REAL ); + virtual void evalpoint2i( long, long ); + virtual void endmap2f( void ); + + virtual void polymode( long ); + virtual void bgnline( void ); + virtual void endline( void ); + virtual void bgnclosedline( void ); + virtual void endclosedline( void ); + virtual void bgntmesh( void ); + virtual void swaptmesh( void ); + virtual void endtmesh( void ); + virtual void bgnqstrip( void ); + virtual void endqstrip( void ); + + virtual void bgntfan( void ); + virtual void endtfan( void ); + + virtual void evalUStrip(int n_upper, REAL v_upper, REAL* upper_val, + int n_lower, REAL v_lower, REAL* lower_val + ) = 0; + + virtual void evalVStrip(int n_left, REAL u_left, REAL* left_val, + int n_right, REAL u_right, REAL* right_val + ) = 0; + virtual void inDoEvalCoord2NOGE(REAL u, REAL v, REAL* ret_point, REAL* ret_normal) = 0; + virtual void inDoEvalCoord2NOGE_BU(REAL u, REAL v, REAL* ret_point, REAL* ret_normal) = 0; + virtual void inDoEvalCoord2NOGE_BV(REAL u, REAL v, REAL* ret_point, REAL* ret_normal) = 0; + virtual void inPreEvaluateBV_intfac(REAL v ) = 0; + virtual void inPreEvaluateBU_intfac(REAL u ) = 0; + +}; + +#endif /* __glubasicsurfeval_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/bezierarc.h b/src/glu/sgi/libnurbs/internals/bezierarc.h new file mode 100644 index 0000000..4acfb09 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/bezierarc.h @@ -0,0 +1,51 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * bezierarc.h + * + */ + +#ifndef __glubezierarc_h +#define __glubezierarc_h + +#include "myassert.h" + +class Mapdesc; + +struct BezierArc : public PooledObj { /* a bezier arc */ + REAL * cpts; /* control points of arc */ + int order; /* order of arc */ + int stride; /* REAL distance between points */ + long type; /* curve type */ + Mapdesc * mapdesc; +}; + +#endif /* __glubezierarc_h */ diff --git a/src/glu/sgi/libnurbs/internals/bin.cc b/src/glu/sgi/libnurbs/internals/bin.cc new file mode 100644 index 0000000..ff75b86 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/bin.cc @@ -0,0 +1,167 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * bin.c++ + * + */ + +#include "glimports.h" +#include "mystdio.h" +#include "myassert.h" +#include "bin.h" + +/*---------------------------------------------------------------------------- + * Constructor and destructor + *---------------------------------------------------------------------------- + */ +Bin::Bin() +{ + head = NULL; + current = NULL; +} + +Bin::~Bin() +{ + assert( head == NULL); +} + +/*---------------------------------------------------------------------------- + * remove_this_arc - remove given Arc_ptr from bin + *---------------------------------------------------------------------------- + */ + +void +Bin::remove_this_arc( Arc_ptr arc ) +{ + Arc_ptr *j; + for( j = &(head); (*j != 0) && (*j != arc); j = &((*j)->link) ); + + if( *j != 0 ) { + if( *j == current ) + current = (*j)->link; + *j = (*j)->link; + } +} + +/*---------------------------------------------------------------------------- + * numarcs - count number of arcs in bin + *---------------------------------------------------------------------------- + */ + +int +Bin::numarcs() +{ + long count = 0; + for( Arc_ptr jarc = firstarc(); jarc; jarc = nextarc() ) + count++; + return count; +} + +/*---------------------------------------------------------------------------- + * adopt - place an orphaned arcs into their new parents bin + *---------------------------------------------------------------------------- + */ + +void +Bin::adopt() +{ + markall(); + + Arc_ptr orphan; + while( (orphan = removearc()) != NULL ) { + for( Arc_ptr parent = orphan->next; parent != orphan; parent = parent->next ) { + if (! parent->ismarked() ) { + orphan->link = parent->link; + parent->link = orphan; + orphan->clearmark(); + break; + } + } + } +} + + +/*---------------------------------------------------------------------------- + * show - print out descriptions of the arcs in the bin + *---------------------------------------------------------------------------- + */ + +void +Bin::show( char *name ) +{ +#ifndef NDEBUG + _glu_dprintf( "%s\n", name ); + for( Arc_ptr jarc = firstarc(); jarc; jarc = nextarc() ) + jarc->show( ); +#endif +} + + + +/*---------------------------------------------------------------------------- + * markall - mark all arcs with an identifying tag + *---------------------------------------------------------------------------- + */ + +void +Bin::markall() +{ + for( Arc_ptr jarc=firstarc(); jarc; jarc=nextarc() ) + jarc->setmark(); +} + +/*---------------------------------------------------------------------------- + * listBezier - print out all arcs that are untessellated border arcs + *---------------------------------------------------------------------------- + */ + +void +Bin::listBezier( void ) +{ + for( Arc_ptr jarc=firstarc(); jarc; jarc=nextarc() ) { + if( jarc->isbezier( ) ) { + assert( jarc->pwlArc->npts == 2 ); +#ifndef NDEBUG + TrimVertex *pts = jarc->pwlArc->pts; + REAL s1 = pts[0].param[0]; + REAL t1 = pts[0].param[1]; + REAL s2 = pts[1].param[0]; + REAL t2 = pts[1].param[1]; + _glu_dprintf( "arc (%g,%g) (%g,%g)\n", s1, t1, s2, t2 ); +#endif + } + } +} + diff --git a/src/glu/sgi/libnurbs/internals/bin.h b/src/glu/sgi/libnurbs/internals/bin.h new file mode 100644 index 0000000..2f976eb --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/bin.h @@ -0,0 +1,121 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * bin.h + * + */ + +#ifndef __glubin_h_ +#define __glubin_h_ + +#include "myassert.h" +#include "arc.h" +#include "defines.h" + +class Bin +{ /* a linked list of jordan arcs */ +private: + Arc_ptr head;/*first arc on list */ + Arc_ptr current; /* current arc on list */ +public: + Bin(); + ~Bin(); + inline Arc_ptr firstarc( void ); + inline Arc_ptr nextarc( void ); + inline Arc_ptr removearc( void ); + inline int isnonempty( void ) { return (head ? 1 : 0); } + inline void addarc( Arc_ptr ); + void remove_this_arc( Arc_ptr ); + int numarcs( void ); + void adopt( void ); + void markall( void ); + void show( char * ); + void listBezier( void ); +}; + +/*---------------------------------------------------------------------------- + * Bin::addarc - add an Arc_ptr to head of linked list of Arc_ptr + *---------------------------------------------------------------------------- + */ + +inline void +Bin::addarc( Arc_ptr jarc ) +{ + jarc->link = head; + head = jarc; +} + +/*---------------------------------------------------------------------------- + * Bin::removearc - remove first Arc_ptr from bin + *---------------------------------------------------------------------------- + */ + +inline Arc_ptr +Bin::removearc( void ) +{ + Arc_ptr jarc = head; + + if( jarc ) head = jarc->link; + return jarc; +} + + +/*---------------------------------------------------------------------------- + * BinIter::nextarc - return current arc in bin and advance pointer to next arc + *---------------------------------------------------------------------------- + */ + +inline Arc_ptr +Bin::nextarc( void ) +{ + Arc_ptr jarc = current; + +#ifdef DEBUG + assert( jarc->check() != 0 ); +#endif + + if( jarc ) current = jarc->link; + return jarc; +} + +/*---------------------------------------------------------------------------- + * BinIter::firstarc - set current arc to first arc of bin advance to next arc + *---------------------------------------------------------------------------- + */ + +inline Arc_ptr +Bin::firstarc( void ) +{ + current = head; + return nextarc( ); +} + +#endif /* __glubin_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/bufpool.cc b/src/glu/sgi/libnurbs/internals/bufpool.cc new file mode 100644 index 0000000..53ac1a5 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/bufpool.cc @@ -0,0 +1,113 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * bufpool.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "bufpool.h" + + +/*----------------------------------------------------------------------------- + * Pool - allocate a new pool of buffers + *----------------------------------------------------------------------------- + */ +Pool::Pool( int _buffersize, int initpoolsize, const char *n ) +{ + if((unsigned)_buffersize < sizeof(Buffer)) + buffersize = sizeof(Buffer); + else + buffersize = _buffersize; + initsize = initpoolsize * buffersize; + nextsize = initsize; + name = n; + magic = is_allocated; + nextblock = 0; + curblock = 0; + freelist = 0; + nextfree = 0; + for (int i = 0; i < NBLOCKS; i++) { + blocklist[i] = 0; + } +} + +/*----------------------------------------------------------------------------- + * ~Pool - free a pool of buffers and the pool itself + *----------------------------------------------------------------------------- + */ + +Pool::~Pool( void ) +{ + assert( (this != 0) && (magic == is_allocated) ); + + while( nextblock ) { + delete [] blocklist[--nextblock]; + blocklist[nextblock] = 0; + } + magic = is_free; +} + + +void Pool::grow( void ) +{ + assert( (this != 0) && (magic == is_allocated) ); + curblock = new char[nextsize]; + blocklist[nextblock++] = curblock; + nextfree = nextsize; + nextsize *= 2; +} + +/*----------------------------------------------------------------------------- + * Pool::clear - free buffers associated with pool but keep pool + *----------------------------------------------------------------------------- + */ + +void +Pool::clear( void ) +{ + assert( (this != 0) && (magic == is_allocated) ); + + while( nextblock ) { + delete [] blocklist[--nextblock]; + blocklist[nextblock] = 0; + } + curblock = 0; + freelist = 0; + nextfree = 0; + if( nextsize > initsize ) + nextsize /= 2; +} diff --git a/src/glu/sgi/libnurbs/internals/bufpool.h b/src/glu/sgi/libnurbs/internals/bufpool.h new file mode 100644 index 0000000..0fa9433 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/bufpool.h @@ -0,0 +1,141 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * bufpool.h + * + */ + +#ifndef __glubufpool_h_ +#define __glubufpool_h_ + +#include "gluos.h" +#include "myassert.h" +#include "mystdlib.h" + +#define NBLOCKS 32 + +class Buffer { + friend class Pool; + Buffer * next; /* next buffer on free list */ +}; + +class Pool { +public: + Pool( int, int, const char * ); + ~Pool( void ); + inline void* new_buffer( void ); + inline void free_buffer( void * ); + void clear( void ); + +private: + void grow( void ); + +protected: + Buffer *freelist; /* linked list of free buffers */ + char *blocklist[NBLOCKS]; /* blocks of malloced memory */ + int nextblock; /* next free block index */ + char *curblock; /* last malloced block */ + int buffersize; /* bytes per buffer */ + int nextsize; /* size of next block of memory */ + int nextfree; /* byte offset past next free buffer */ + int initsize; + enum Magic { is_allocated = 0xf3a1, is_free = 0xf1a2 }; + const char *name; /* name of the pool */ + Magic magic; /* marker for valid pool */ +}; + +/*----------------------------------------------------------------------------- + * Pool::free_buffer - return a buffer to a pool + *----------------------------------------------------------------------------- + */ + +inline void +Pool::free_buffer( void *b ) +{ + assert( (this != 0) && (magic == is_allocated) ); + + /* add buffer to singly connected free list */ + + ((Buffer *) b)->next = freelist; + freelist = (Buffer *) b; +} + + +/*----------------------------------------------------------------------------- + * Pool::new_buffer - allocate a buffer from a pool + *----------------------------------------------------------------------------- + */ + +inline void * +Pool::new_buffer( void ) +{ + void *buffer; + + assert( (this != 0) && (magic == is_allocated) ); + + /* find free buffer */ + + if( freelist ) { + buffer = (void *) freelist; + freelist = freelist->next; + } else { + if( ! nextfree ) + grow( ); + nextfree -= buffersize;; + buffer = (void *) (curblock + nextfree); + } + return buffer; +} + +class PooledObj { +public: + inline void * operator new( size_t, Pool & ); + inline void * operator new( size_t, void *); + inline void * operator new( size_t s) + { return ::new char[s]; } + inline void operator delete( void * ) { assert( 0 ); } + inline void operator delete( void *, Pool & ) { assert( 0 ); } + inline void deleteMe( Pool & ); +}; + +inline void * +PooledObj::operator new( size_t, Pool& pool ) +{ + return pool.new_buffer(); +} + +inline void +PooledObj::deleteMe( Pool& pool ) +{ + pool.free_buffer( (void *) this ); +} + +#endif /* __glubufpool_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/cachingeval.cc b/src/glu/sgi/libnurbs/internals/cachingeval.cc new file mode 100644 index 0000000..3fab38c --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/cachingeval.cc @@ -0,0 +1,78 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * cachingeval.c++ + * + */ + +#include "cachingeval.h" + +int +CachingEvaluator::canRecord( void ) +{ + return 0; +} + +int +CachingEvaluator::canPlayAndRecord( void ) +{ + return 0; +} + +int +CachingEvaluator::createHandle( int ) +{ + return 0; +} + +void +CachingEvaluator::beginOutput( ServiceMode, int ) +{ +} + +void +CachingEvaluator::endOutput( void ) +{ +} + +void +CachingEvaluator::discardRecording( int ) +{ +} + +void +CachingEvaluator::playRecording( int ) +{ +} diff --git a/src/glu/sgi/libnurbs/internals/cachingeval.h b/src/glu/sgi/libnurbs/internals/cachingeval.h new file mode 100644 index 0000000..b390067 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/cachingeval.h @@ -0,0 +1,51 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * cachingeval.h + * + */ + +#ifndef __glucachingval_h_ +#define __glucachingval_h_ + +class CachingEvaluator { +public: + virtual ~CachingEvaluator() { /* silence warning*/ } + enum ServiceMode { play, record, playAndRecord }; + virtual int canRecord( void ); + virtual int canPlayAndRecord( void ); + virtual int createHandle( int handle ); + virtual void beginOutput( ServiceMode, int handle ); + virtual void endOutput( void ); + virtual void discardRecording( int handle ); + virtual void playRecording( int handle ); +}; +#endif /* __glucachingval_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/ccw.cc b/src/glu/sgi/libnurbs/internals/ccw.cc new file mode 100644 index 0000000..eb01b77 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/ccw.cc @@ -0,0 +1,565 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * ccw.c++ + * + */ + +#include "glimports.h" +#include "mystdio.h" +#include "myassert.h" +#include "subdivider.h" +#include "types.h" +#include "arc.h" +#include "trimvertex.h" +#include "simplemath.h" + +inline int +Subdivider::bbox( TrimVertex *a, TrimVertex *b, TrimVertex *c, int p ) +{ + return bbox( a->param[p], b->param[p], c->param[p], + a->param[1-p], b->param[1-p], c->param[1-p] ); +} + +int +Subdivider::ccwTurn_sr( Arc_ptr j1, Arc_ptr j2 ) // dir = 1 +{ + register TrimVertex *v1 = &j1->pwlArc->pts[j1->pwlArc->npts-1]; + register TrimVertex *v1last = &j1->pwlArc->pts[0]; + register TrimVertex *v2 = &j2->pwlArc->pts[0]; + register TrimVertex *v2last = &j2->pwlArc->pts[j2->pwlArc->npts-1]; + register TrimVertex *v1next = v1-1; + register TrimVertex *v2next = v2+1; + int sgn; + + assert( v1 != v1last ); + assert( v2 != v2last ); + +#ifndef NDEBUG + _glu_dprintf( "arc_ccw_turn, p = %d\n", 0 ); +#endif + + // the arcs lie on the line (0 == v1->param[0]) + if( v1->param[0] == v1next->param[0] && v2->param[0] == v2next->param[0] ) + return 0; + + if( v2next->param[0] < v2->param[0] || v1next->param[0] < v1->param[0] ) + ::mylongjmp( jumpbuffer, 28 ); + + if( v1->param[1] < v2->param[1] ) + return 0; + else if( v1->param[1] > v2->param[1] ) + return 1; + + while( 1 ) { + if( v1next->param[0] < v2next->param[0] ) { +#ifndef NDEBUG + _glu_dprintf( "case a\n" ); +#endif + assert( v1->param[0] <= v1next->param[0] ); + assert( v2->param[0] <= v1next->param[0] ); + switch( bbox( v2, v2next, v1next, 1 ) ) { + case -1: + return 0; + case 0: + sgn = ccw( v1next, v2, v2next ); + if( sgn != -1 ) { + return sgn; + } else { +#ifdef DEBUG + _glu_dprintf( "decr\n" ); +#endif + v1 = v1next--; + if( v1 == v1last ) { +#ifdef DEBUG + _glu_dprintf( "no good results\n" ); +#endif + return 0; // ill-conditioned, guess answer + } + } + break; + case 1: + return 1; + } + } else if( v1next->param[0] > v2next->param[0] ) { +#ifndef NDEBUG + _glu_dprintf( "case b\n" ); +#endif + assert( v1->param[0] <= v2next->param[0] ); + assert( v2->param[0] <= v2next->param[0] ); + switch( bbox( v1, v1next, v2next, 1 ) ) { + case -1: + return 1; + case 0: + sgn = ccw( v1next, v1, v2next ); + if( sgn != -1 ) { + return sgn; + } else { +#ifdef DEBUG + _glu_dprintf( "incr\n" ); +#endif + v2 = v2next++; + if( v2 == v2last ) { +#ifdef DEBUG + _glu_dprintf( "no good results\n" ); +#endif + return 0; // ill-conditioned, guess answer + } + } + break; + case 1: + return 0; + } + } else { +#ifndef NDEBUG + _glu_dprintf( "case ab\n" ); +#endif + if( v1next->param[1] < v2next->param[1] ) + return 0; + else if( v1next->param[1] > v2next->param[1] ) + return 1; + else { +#ifdef DEBUG + _glu_dprintf( "incr\n" ); +#endif + v2 = v2next++; + if( v2 == v2last ) { +#ifdef DEBUG + _glu_dprintf( "no good results\n" ); +#endif + return 0; // ill-conditioned, guess answer + } + } + } + } +} + +int +Subdivider::ccwTurn_sl( Arc_ptr j1, Arc_ptr j2 ) // dir = 0 +{ + register TrimVertex *v1 = &j1->pwlArc->pts[j1->pwlArc->npts-1]; + register TrimVertex *v1last = &j1->pwlArc->pts[0]; + register TrimVertex *v2 = &j2->pwlArc->pts[0]; + register TrimVertex *v2last = &j2->pwlArc->pts[j2->pwlArc->npts-1]; + register TrimVertex *v1next = v1-1; + register TrimVertex *v2next = v2+1; + int sgn; + + assert( v1 != v1last ); + assert( v2 != v2last ); + +#ifndef NDEBUG + _glu_dprintf( "arc_ccw_turn, p = %d\n", 0 ); +#endif + + // the arcs lie on the line (0 == v1->param[0]) + if( v1->param[0] == v1next->param[0] && v2->param[0] == v2next->param[0] ) + return 0; + + if( v2next->param[0] > v2->param[0] || v1next->param[0] > v1->param[0] ) + ::mylongjmp( jumpbuffer, 28 ); + + if( v1->param[1] < v2->param[1] ) + return 1; + else if( v1->param[1] > v2->param[1] ) + return 0; + + while( 1 ) { + if( v1next->param[0] > v2next->param[0] ) { +#ifndef NDEBUG + _glu_dprintf( "case c\n" ); +#endif + assert( v1->param[0] >= v1next->param[0] ); + assert( v2->param[0] >= v1next->param[0] ); + switch( bbox( v2next, v2, v1next, 1 ) ) { + case -1: + return 1; + case 0: + sgn = ccw( v1next, v2, v2next ); + if( sgn != -1 ) + return sgn; + else { + v1 = v1next--; +#ifdef DEBUG + _glu_dprintf( "decr\n" ); +#endif + if( v1 == v1last ) { +#ifdef DEBUG + _glu_dprintf( "no good results\n" ); +#endif + return 0; // ill-conditioned, guess answer + } + } + break; + case 1: + return 0; + } + } else if( v1next->param[0] < v2next->param[0] ) { +#ifndef NDEBUG + _glu_dprintf( "case d\n" ); +#endif + assert( v1->param[0] >= v2next->param[0] ); + assert( v2->param[0] >= v2next->param[0] ); + switch( bbox( v1next, v1, v2next, 1 ) ) { + case -1: + return 0; + case 0: + sgn = ccw( v1next, v1, v2next ); + if( sgn != -1 ) + return sgn; + else { + v2 = v2next++; +#ifdef DEBUG + _glu_dprintf( "incr\n" ); +#endif + if( v2 == v2last ) { +#ifdef DEBUG + _glu_dprintf( "no good results\n" ); +#endif + return 0; // ill-conditioned, guess answer + } + } + break; + case 1: + return 1; + } + } else { +#ifdef DEBUG + _glu_dprintf( "case cd\n" ); +#endif + if( v1next->param[1] < v2next->param[1] ) + return 1; + else if( v1next->param[1] > v2next->param[1] ) + return 0; + else { + v2 = v2next++; +#ifdef DEBUG + _glu_dprintf( "incr\n" ); +#endif + if( v2 == v2last ) { +#ifdef DEBUG + _glu_dprintf( "no good results\n" ); +#endif + return 0; // ill-conditioned, guess answer + } + } + } + } +} + +int +Subdivider::ccwTurn_tr( Arc_ptr j1, Arc_ptr j2 ) // dir = 1 +{ + register TrimVertex *v1 = &j1->pwlArc->pts[j1->pwlArc->npts-1]; + register TrimVertex *v1last = &j1->pwlArc->pts[0]; + register TrimVertex *v2 = &j2->pwlArc->pts[0]; + register TrimVertex *v2last = &j2->pwlArc->pts[j2->pwlArc->npts-1]; + register TrimVertex *v1next = v1-1; + register TrimVertex *v2next = v2+1; + int sgn; + + assert( v1 != v1last ); + assert( v2 != v2last ); + +#ifndef NDEBUG + _glu_dprintf( "arc_ccw_turn, p = %d\n", 1 ); +#endif + + // the arcs lie on the line (1 == v1->param[1]) + if( v1->param[1] == v1next->param[1] && v2->param[1] == v2next->param[1] ) + return 0; + + if( v2next->param[1] < v2->param[1] || v1next->param[1] < v1->param[1] ) + ::mylongjmp( jumpbuffer, 28 ); + + if( v1->param[0] < v2->param[0] ) + return 1; + else if( v1->param[0] > v2->param[0] ) + return 0; + + while( 1 ) { + if( v1next->param[1] < v2next->param[1] ) { +#ifndef NDEBUG + _glu_dprintf( "case a\n" ); +#endif + assert( v1->param[1] <= v1next->param[1] ); + assert( v2->param[1] <= v1next->param[1] ); + switch( bbox( v2, v2next, v1next, 0 ) ) { + case -1: + return 1; + case 0: + sgn = ccw( v1next, v2, v2next ); + if( sgn != -1 ) { + return sgn; + } else { +#ifdef DEBUG + _glu_dprintf( "decr\n" ); +#endif + v1 = v1next--; + if( v1 == v1last ) { +#ifdef DEBUG + _glu_dprintf( "no good results\n" ); +#endif + return 0; // ill-conditioned, guess answer + } + } + break; + case 1: + return 0; + } + } else if( v1next->param[1] > v2next->param[1] ) { +#ifndef NDEBUG + _glu_dprintf( "case b\n" ); +#endif + assert( v1->param[1] <= v2next->param[1] ); + assert( v2->param[1] <= v2next->param[1] ); + switch( bbox( v1, v1next, v2next, 0 ) ) { + case -1: + return 0; + case 0: + sgn = ccw( v1next, v1, v2next ); + if( sgn != -1 ) { + return sgn; + } else { +#ifdef DEBUG + _glu_dprintf( "incr\n" ); +#endif + v2 = v2next++; + if( v2 == v2last ) { +#ifdef DEBUG + _glu_dprintf( "no good results\n" ); +#endif + return 0; // ill-conditioned, guess answer + } + } + break; + case 1: + return 1; + } + } else { +#ifdef DEBUG + _glu_dprintf( "case ab\n" ); +#endif + if( v1next->param[0] < v2next->param[0] ) + return 1; + else if( v1next->param[0] > v2next->param[0] ) + return 0; + else { +#ifdef DEBUG + _glu_dprintf( "incr\n" ); +#endif + v2 = v2next++; + if( v2 == v2last ) { +#ifdef DEBUG + _glu_dprintf( "no good results\n" ); +#endif + return 0; // ill-conditioned, guess answer + } + } + } + } +} + +int +Subdivider::ccwTurn_tl( Arc_ptr j1, Arc_ptr j2 ) +{ + register TrimVertex *v1 = &j1->pwlArc->pts[j1->pwlArc->npts-1]; + register TrimVertex *v1last = &j1->pwlArc->pts[0]; + register TrimVertex *v2 = &j2->pwlArc->pts[0]; + register TrimVertex *v2last = &j2->pwlArc->pts[j2->pwlArc->npts-1]; + register TrimVertex *v1next = v1-1; + register TrimVertex *v2next = v2+1; + int sgn; + + assert( v1 != v1last ); + assert( v2 != v2last ); + +#ifndef NDEBUG + _glu_dprintf( "arc_ccw_turn, p = %d\n", 1 ); +#endif + + // the arcs lie on the line (1 == v1->param[1]) + if( v1->param[1] == v1next->param[1] && v2->param[1] == v2next->param[1] ) + return 0; + + if( v2next->param[1] > v2->param[1] || v1next->param[1] > v1->param[1] ) + ::mylongjmp( jumpbuffer, 28 ); + + if( v1->param[0] < v2->param[0] ) + return 0; + else if( v1->param[0] > v2->param[0] ) + return 1; + + while( 1 ) { + if( v1next->param[1] > v2next->param[1] ) { +#ifndef NDEBUG + _glu_dprintf( "case c\n" ); +#endif + assert( v1->param[1] >= v1next->param[1] ); + assert( v2->param[1] >= v1next->param[1] ); + switch( bbox( v2next, v2, v1next, 0 ) ) { + case -1: + return 0; + case 0: + sgn = ccw( v1next, v2, v2next ); + if( sgn != -1 ) + return sgn; + else { + v1 = v1next--; +#ifdef DEBUG + _glu_dprintf( "decr\n" ); +#endif + if( v1 == v1last ) { +#ifdef DEBUG + _glu_dprintf( "no good results\n" ); +#endif + return 0; // ill-conditioned, guess answer + } + } + break; + case 1: + return 1; + } + } else if( v1next->param[1] < v2next->param[1] ) { +#ifndef NDEBUG + _glu_dprintf( "case d\n" ); + assert( v1->param[1] >= v2next->param[1] ); + assert( v2->param[1] >= v2next->param[1] ); +#endif + switch( bbox( v1next, v1, v2next, 0 ) ) { + case -1: + return 1; + case 0: + sgn = ccw( v1next, v1, v2next ); + if( sgn != -1 ) + return sgn; + else { + v2 = v2next++; +#ifdef DEBUG + _glu_dprintf( "incr\n" ); +#endif + if( v2 == v2last ) { +#ifdef DEBUG + _glu_dprintf( "no good results\n" ); +#endif + return 0; // ill-conditioned, guess answer + } + } + break; + case 1: + return 0; + } + } else { +#ifdef DEBUG + _glu_dprintf( "case cd\n" ); +#endif + if( v1next->param[0] < v2next->param[0] ) + return 0; + else if( v1next->param[0] > v2next->param[0] ) + return 1; + else { + v2 = v2next++; +#ifdef DEBUG + _glu_dprintf( "incr\n" ); +#endif + if( v2 == v2last ) { +#ifdef DEBUG + _glu_dprintf( "no good results\n" ); +#endif + return 0; // ill-conditioned, guess answer + } + } + } + } +} + + +#ifndef NDEBUG +int +Subdivider::bbox( register REAL sa, register REAL sb, register REAL sc, + register REAL ta, register REAL tb, register REAL tc ) +#else +int +Subdivider::bbox( register REAL sa, register REAL sb, register REAL sc, + register REAL , register REAL , register REAL ) +#endif +{ +#ifndef NDEBUG + assert( tc >= ta ); + assert( tc <= tb ); +#endif + + if( sa < sb ) { + if( sc <= sa ) { + return -1; + } else if( sb <= sc ) { + return 1; + } else { + return 0; + } + } else if( sa > sb ) { + if( sc >= sa ) { + return 1; + } else if( sb >= sc ) { + return -1; + } else { + return 0; + } + } else { + if( sc > sa ) { + return 1; + } else if( sb > sc ) { + return -1; + } else { + return 0; + } + } +} + +/*---------------------------------------------------------------------------- + * ccw - determine how three points are oriented by computing their + * determinant. + * Return 1 if the vertices are ccw oriented, + * 0 if they are cw oriented, or + * -1 if the computation is ill-conditioned. + *---------------------------------------------------------------------------- + */ +int +Subdivider::ccw( TrimVertex *a, TrimVertex *b, TrimVertex *c ) +{ + REAL d = det3( a, b, c ); + if( glu_abs(d) < 0.0001 ) return -1; + return (d < 0.0) ? 0 : 1; +} diff --git a/src/glu/sgi/libnurbs/internals/coveandtiler.cc b/src/glu/sgi/libnurbs/internals/coveandtiler.cc new file mode 100644 index 0000000..ca5bf36 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/coveandtiler.cc @@ -0,0 +1,440 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * coveandtiler.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "coveandtiler.h" +#include "gridvertex.h" +#include "gridtrimvertex.h" +#include "uarray.h" +#include "backend.h" + + +const int CoveAndTiler::MAXSTRIPSIZE = 1000; + +CoveAndTiler::CoveAndTiler( Backend& b ) + : backend( b ) +{ } + +CoveAndTiler::~CoveAndTiler( void ) +{ } + +inline void +CoveAndTiler::output( GridVertex &gv ) +{ + backend.tmeshvert( &gv ); +} + +inline void +CoveAndTiler::output( TrimVertex *tv ) +{ + backend.tmeshvert( tv ); +} + +inline void +CoveAndTiler::output( GridTrimVertex& g ) +{ + backend.tmeshvert( &g ); +} + +void +CoveAndTiler::coveAndTile( void ) +{ + long ustart = (top.ustart >= bot.ustart) ? top.ustart : bot.ustart; + long uend = (top.uend <= bot.uend) ? top.uend : bot.uend; + if( ustart <= uend ) { + tile( bot.vindex, ustart, uend ); + if( top.ustart >= bot.ustart ) + coveUpperLeft(); + else + coveLowerLeft(); + + if( top.uend <= bot.uend ) + coveUpperRight(); + else + coveLowerRight(); + } else { + TrimVertex blv, tlv, *bl, *tl; + GridTrimVertex bllv, tllv; + TrimVertex *lf = left.first(); + TrimVertex *ll = left.last(); + if( lf->param[0] >= ll->param[0] ) { + blv.param[0] = lf->param[0]; + blv.param[1] = ll->param[1]; + blv.nuid = 0; // XXX + assert( blv.param[1] == bot.vval ); + bl = &blv; + tl = lf; + tllv.set( lf ); + if( ll->param[0] > uarray.uarray[top.ustart-1] ) { + bllv.set( ll ); + assert( ll->param[0] <= uarray.uarray[bot.ustart] ); + } else { + bllv.set( top.ustart-1, bot.vindex ); + } + coveUpperLeftNoGrid( bl ); + } else { + tlv.param[0] = ll->param[0]; + tlv.param[1] = lf->param[1]; + tlv.nuid = 0; // XXX + assert( tlv.param[1] == top.vval ); + tl = &tlv; + bl = ll; + bllv.set( ll ); + if( lf->param[0] > uarray.uarray[bot.ustart-1] ) { + assert( lf->param[0] <= uarray.uarray[bot.ustart] ); + tllv.set( lf ); + } else { + tllv.set( bot.ustart-1, top.vindex ); + } + coveLowerLeftNoGrid( tl ); + } + + TrimVertex brv, trv, *br, *tr; + GridTrimVertex brrv, trrv; + TrimVertex *rf = right.first(); + TrimVertex *rl = right.last(); + + if( rf->param[0] <= rl->param[0] ) { + brv.param[0] = rf->param[0]; + brv.param[1] = rl->param[1]; + brv.nuid = 0; // XXX + assert( brv.param[1] == bot.vval ); + br = &brv; + tr = rf; + trrv.set( rf ); + if( rl->param[0] < uarray.uarray[top.uend+1] ) { + assert( rl->param[0] >= uarray.uarray[top.uend] ); + brrv.set( rl ); + } else { + brrv.set( top.uend+1, bot.vindex ); + } + coveUpperRightNoGrid( br ); + } else { + trv.param[0] = rl->param[0]; + trv.param[1] = rf->param[1]; + trv.nuid = 0; // XXX + assert( trv.param[1] == top.vval ); + tr = &trv; + br = rl; + brrv.set( rl ); + if( rf->param[0] < uarray.uarray[bot.uend+1] ) { + assert( rf->param[0] >= uarray.uarray[bot.uend] ); + trrv.set( rf ); + } else { + trrv.set( bot.uend+1, top.vindex ); + } + coveLowerRightNoGrid( tr ); + } + + backend.bgntmesh( "doit" ); + output(trrv); + output(tllv); + output( tr ); + output( tl ); + output( br ); + output( bl ); + output(brrv); + output(bllv); + backend.endtmesh(); + } +} + +void +CoveAndTiler::tile( long vindex, long ustart, long uend ) +{ + long numsteps = uend - ustart; + + if( numsteps == 0 ) return; + + if( numsteps > MAXSTRIPSIZE ) { + long umid = ustart + (uend - ustart) / 2; + tile( vindex, ustart, umid ); + tile( vindex, umid, uend ); + } else { + backend.surfmesh( ustart, vindex-1, numsteps, 1 ); + } +} + +void +CoveAndTiler::coveUpperRight( void ) +{ + GridVertex tgv( top.uend, top.vindex ); + GridVertex gv( top.uend, bot.vindex ); + + right.first(); + backend.bgntmesh( "coveUpperRight" ); + output( right.next() ); + output( tgv ); + backend.swaptmesh(); + output( gv ); + coveUR(); + backend.endtmesh(); +} + +void +CoveAndTiler::coveUpperRightNoGrid( TrimVertex* br ) +{ + backend.bgntmesh( "coveUpperRight" ); + output( right.first() ); + output( right.next() ); + backend.swaptmesh(); + output( br ); + coveUR(); + backend.endtmesh(); +} + +void +CoveAndTiler::coveUR( ) +{ + GridVertex gv( top.uend, bot.vindex ); + TrimVertex *vert = right.next(); + if( vert == NULL ) return; + + assert( vert->param[0] >= uarray.uarray[gv.gparam[0]] ); + + if( gv.nextu() >= bot.uend ) { + for( ; vert; vert = right.next() ) { + output( vert ); + backend.swaptmesh(); + } + } else while( 1 ) { + if( vert->param[0] < uarray.uarray[gv.gparam[0]] ) { + output( vert ); + backend.swaptmesh(); + vert = right.next(); + if( vert == NULL ) break; + } else { + backend.swaptmesh(); + output( gv ); + if( gv.nextu() == bot.uend ) { + for( ; vert; vert = right.next() ) { + output( vert ); + backend.swaptmesh(); + } + break; + } + } + } +} + +void +CoveAndTiler::coveUpperLeft( void ) +{ + GridVertex tgv( top.ustart, top.vindex ); + GridVertex gv( top.ustart, bot.vindex ); + + left.first(); + backend.bgntmesh( "coveUpperLeft" ); + output( tgv ); + output( left.next() ); + output( gv ); + backend.swaptmesh(); + coveUL(); + backend.endtmesh(); +} + +void +CoveAndTiler::coveUpperLeftNoGrid( TrimVertex* bl ) +{ + backend.bgntmesh( "coveUpperLeftNoGrid" ); + output( left.first() ); + output( left.next() ); + output( bl ); + backend.swaptmesh(); + coveUL(); + backend.endtmesh(); +} + +void +CoveAndTiler::coveUL() +{ + GridVertex gv( top.ustart, bot.vindex ); + TrimVertex *vert = left.next(); + if( vert == NULL ) return; + assert( vert->param[0] <= uarray.uarray[gv.gparam[0]] ); + + if( gv.prevu() <= bot.ustart ) { + for( ; vert; vert = left.next() ) { + backend.swaptmesh(); + output( vert ); + } + } else while( 1 ) { + if( vert->param[0] > uarray.uarray[gv.gparam[0]] ) { + backend.swaptmesh(); + output( vert ); + vert = left.next(); + if( vert == NULL ) break; + } else { + output( gv ); + backend.swaptmesh(); + if( gv.prevu() == bot.ustart ) { + for( ; vert; vert = left.next() ) { + backend.swaptmesh(); + output( vert ); + } + break; + } + } + } +} + +void +CoveAndTiler::coveLowerLeft( void ) +{ + GridVertex bgv( bot.ustart, bot.vindex ); + GridVertex gv( bot.ustart, top.vindex ); + + left.last(); + backend.bgntmesh( "coveLowerLeft" ); + output( left.prev() ); + output( bgv ); + backend.swaptmesh(); + output( gv ); + coveLL(); + backend.endtmesh(); +} + +void +CoveAndTiler::coveLowerLeftNoGrid( TrimVertex* tl ) +{ + backend.bgntmesh( "coveLowerLeft" ); + output( left.last() ); + output( left.prev() ); + backend.swaptmesh(); + output( tl ); + coveLL( ); + backend.endtmesh(); +} + +void +CoveAndTiler::coveLL() +{ + GridVertex gv( bot.ustart, top.vindex ); + TrimVertex *vert = left.prev(); + if( vert == NULL ) return; + assert( vert->param[0] <= uarray.uarray[gv.gparam[0]] ); + + if( gv.prevu() <= top.ustart ) { + for( ; vert; vert = left.prev() ) { + output( vert ); + backend.swaptmesh(); + } + } else while( 1 ) { + if( vert->param[0] > uarray.uarray[gv.gparam[0]] ){ + output( vert ); + backend.swaptmesh(); + vert = left.prev(); + if( vert == NULL ) break; + } else { + backend.swaptmesh(); + output( gv ); + if( gv.prevu() == top.ustart ) { + for( ; vert; vert = left.prev() ) { + output( vert ); + backend.swaptmesh(); + } + break; + } + } + } +} + +void +CoveAndTiler::coveLowerRight( void ) +{ + GridVertex bgv( bot.uend, bot.vindex ); + GridVertex gv( bot.uend, top.vindex ); + + right.last(); + backend.bgntmesh( "coveLowerRight" ); + output( bgv ); + output( right.prev() ); + output( gv ); + backend.swaptmesh(); + coveLR(); + backend.endtmesh( ); +} + +void +CoveAndTiler::coveLowerRightNoGrid( TrimVertex* tr ) +{ + backend.bgntmesh( "coveLowerRIght" ); + output( right.last() ); + output( right.prev() ); + output( tr ); + backend.swaptmesh(); + coveLR(); + backend.endtmesh(); +} + +void +CoveAndTiler::coveLR( ) +{ + GridVertex gv( bot.uend, top.vindex ); + TrimVertex *vert = right.prev(); + if( vert == NULL ) return; + assert( vert->param[0] >= uarray.uarray[gv.gparam[0]] ); + + if( gv.nextu() >= top.uend ) { + for( ; vert; vert = right.prev() ) { + backend.swaptmesh(); + output( vert ); + } + } else while( 1 ) { + if( vert->param[0] < uarray.uarray[gv.gparam[0]] ) { + backend.swaptmesh(); + output( vert ); + vert = right.prev(); + if( vert == NULL ) break; + } else { + output( gv ); + backend.swaptmesh(); + if( gv.nextu() == top.uend ) { + for( ; vert; vert = right.prev() ) { + backend.swaptmesh(); + output( vert ); + } + break; + } + } + } +} + diff --git a/src/glu/sgi/libnurbs/internals/coveandtiler.h b/src/glu/sgi/libnurbs/internals/coveandtiler.h new file mode 100644 index 0000000..d454202 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/coveandtiler.h @@ -0,0 +1,72 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * coveandtiler.h + * + */ + +#ifndef __glucoveandtiler_h +#define __glucoveandtiler_h + +#include "trimregion.h" +#include "trimvertex.h" +#include "gridvertex.h" + +class Backend; +class GridTrimVertex; + +class CoveAndTiler : virtual public TrimRegion { +public: + CoveAndTiler( Backend& ); + ~CoveAndTiler( void ); + void coveAndTile( void ); +private: + Backend& backend; + static const int MAXSTRIPSIZE; + void tile( long, long, long ); + void coveLowerLeft( void ); + void coveLowerRight( void ); + void coveUpperLeft( void ); + void coveUpperRight( void ); + void coveUpperLeftNoGrid( TrimVertex * ); + void coveUpperRightNoGrid( TrimVertex * ); + void coveLowerLeftNoGrid( TrimVertex * ); + void coveLowerRightNoGrid( TrimVertex * ); + void coveLL( void ); + void coveLR( void ); + void coveUL( void ); + void coveUR( void ); + inline void output( GridTrimVertex& ); + inline void output( GridVertex& ); + inline void output( TrimVertex* ); +}; + +#endif /* __glucoveandtiler_h */ diff --git a/src/glu/sgi/libnurbs/internals/curve.cc b/src/glu/sgi/libnurbs/internals/curve.cc new file mode 100644 index 0000000..b7c4d4a --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/curve.cc @@ -0,0 +1,204 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * curve.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "mymath.h" +#include "curve.h" +#include "mapdesc.h" +#include "types.h" +#include "quilt.h" +#include "nurbsconsts.h" + +/*-------------------------------------------------------------------------- + * Curve::Curve - copy curve from quilt and transform control points + *-------------------------------------------------------------------------- + */ + +Curve::Curve( Quilt_ptr geo, REAL pta, REAL ptb, Curve *c ) +{ + mapdesc = geo->mapdesc; + next = c; + needsSampling = mapdesc->isRangeSampling() ? 1 : 0; + cullval = mapdesc->isCulling() ? CULL_ACCEPT : CULL_TRIVIAL_ACCEPT; + order = geo->qspec[0].order; + stride = MAXCOORDS; + for( int i = 0; i < MAXORDER * MAXCOORDS; i++ ) { + cpts[i] = 0; + spts[i] = 0; + } + stepsize = 0; + minstepsize = 0; + + REAL *ps = geo->cpts; + Quiltspec_ptr qs = geo->qspec; + ps += qs->offset; + ps += qs->index * qs->order * qs->stride; + + if( needsSampling ) + mapdesc->xformSampling( ps, qs->order, qs->stride, spts, stride ); + + if( cullval == CULL_ACCEPT ) + mapdesc->xformCulling( ps, qs->order, qs->stride, cpts, stride ); + + /* set untrimmed curve range */ + range[0] = qs->breakpoints[qs->index]; + range[1] = qs->breakpoints[qs->index+1]; + range[2] = range[1] - range[0]; + + if( range[0] != pta ) { + Curve lower( *this, pta, 0 ); + lower.next = next; + *this = lower; + } + if( range[1] != ptb ) { + Curve lower( *this, ptb, 0 ); + } +} + +/*-------------------------------------------------------------------------- + * Curve::Curve - subdivide a curve along an isoparametric line + *-------------------------------------------------------------------------- + */ + +Curve::Curve( Curve& upper, REAL value, Curve *c ) +{ + Curve &lower = *this; + + lower.next = c; + lower.mapdesc = upper.mapdesc; + lower.needsSampling = upper.needsSampling; + lower.order = upper.order; + lower.stride = upper.stride; + lower.cullval = upper.cullval; + + REAL d = (value - upper.range[0]) / upper.range[2]; + + if( needsSampling ) + mapdesc->subdivide( upper.spts, lower.spts, d, upper.stride, upper.order ); + + if( cullval == CULL_ACCEPT ) + mapdesc->subdivide( upper.cpts, lower.cpts, d, upper.stride, upper.order ); + + lower.range[0] = upper.range[0]; + lower.range[1] = value; + lower.range[2] = value - upper.range[0]; + upper.range[0] = value; + upper.range[2] = upper.range[1] - value; +} + + +/*-------------------------------------------------------------------------- + * Curve::clamp - clamp the sampling rate to a given maximum + *-------------------------------------------------------------------------- + */ + +void +Curve::clamp( void ) +{ + if( stepsize < minstepsize ) + stepsize = mapdesc->clampfactor * minstepsize; +} + +void +Curve::setstepsize( REAL max ) +{ + stepsize = ( max >= 1.0 ) ? (range[2] / max) : range[2]; + minstepsize = stepsize; +} + +void +Curve::getstepsize( void ) +{ + minstepsize= 0; + + if( mapdesc->isConstantSampling() ) { + // fixed number of samples per patch in each direction + // maxrate is number of s samples per patch + setstepsize( mapdesc->maxrate ); + } else if( mapdesc->isDomainSampling() ) { + // maxrate is number of s samples per unit s length of domain + setstepsize( mapdesc->maxrate * range[2] ); + } else { + // upper bound on path length between sample points + + assert( order <= MAXORDER ); + + /* points have been transformed, therefore they are homogeneous */ + REAL tmp[MAXORDER][MAXCOORDS]; + const int tstride = sizeof(tmp[0]) / sizeof(REAL); + int val = mapdesc->project( spts, stride, &tmp[0][0], tstride, order ); + + if( val == 0 ) { + // control points cross infinity, therefore derivatives are undefined + setstepsize( mapdesc->maxrate ); + } else { + REAL t = mapdesc->getProperty( N_PIXEL_TOLERANCE ); + if( mapdesc->isParametricDistanceSampling() ) { + REAL d = mapdesc->calcPartialVelocity( &tmp[0][0], tstride, order, 2, range[2] ); + stepsize = (d > 0.0) ? sqrtf( 8.0 * t / d ) : range[2]; + minstepsize = ( mapdesc->maxrate > 0.0 ) ? (range[2] / mapdesc->maxrate) : 0.0; + } else if( mapdesc->isPathLengthSampling() ) { + // t is upper bound on path (arc) length + REAL d = mapdesc->calcPartialVelocity( &tmp[0][0], tstride, order, 1, range[2] ); + stepsize = ( d > 0.0 ) ? (t / d) : range[2]; + minstepsize = ( mapdesc->maxrate > 0.0 ) ? (range[2] / mapdesc->maxrate) : 0.0; + } else { + // control points cross infinity, therefore partials are undefined + setstepsize( mapdesc->maxrate ); + } + } + } +} + +int +Curve::needsSamplingSubdivision( void ) +{ + return ( stepsize < minstepsize ) ? 1 : 0; +} + +int +Curve::cullCheck( void ) +{ + if( cullval == CULL_ACCEPT ) + cullval = mapdesc->cullCheck( cpts, order, stride ); + return cullval; +} + diff --git a/src/glu/sgi/libnurbs/internals/curve.h b/src/glu/sgi/libnurbs/internals/curve.h new file mode 100644 index 0000000..0da81c7 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/curve.h @@ -0,0 +1,70 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * curve.h + * + */ + +#ifndef __glucurve_h_ +#define __glucurve_h_ + +#include "types.h" +#include "defines.h" + +class Mapdesc; +class Quilt; + + +class Curve { +public: +friend class Curvelist; + Curve( Quilt *, REAL, REAL, Curve * ); + Curve( Curve&, REAL, Curve * ); + Curve * next; +private: + Mapdesc * mapdesc; + int stride; + int order; + int cullval; + int needsSampling; + REAL cpts[MAXORDER*MAXCOORDS]; + REAL spts[MAXORDER*MAXCOORDS]; + REAL stepsize; + REAL minstepsize; + REAL range[3]; + + void clamp( void ); + void setstepsize( REAL ); + void getstepsize( void ); + int cullCheck( void ); + int needsSamplingSubdivision( void ); +}; +#endif /* __glucurve_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/curvelist.cc b/src/glu/sgi/libnurbs/internals/curvelist.cc new file mode 100644 index 0000000..8f2ee46 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/curvelist.cc @@ -0,0 +1,112 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * curvelist.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "quilt.h" +#include "curvelist.h" +#include "curve.h" +#include "types.h" + +Curvelist::Curvelist( Quilt *quilts, REAL pta, REAL ptb ) +{ + curve = 0; + for( Quilt *q = quilts; q; q = q->next ) + curve = new Curve( q, pta, ptb, curve ); + range[0] = pta; + range[1] = ptb; + range[2] = ptb - pta; + needsSubdivision = 0; + stepsize = 0; +} + +Curvelist::Curvelist( Curvelist &upper, REAL value ) +{ + curve = 0; + for( Curve *c = upper.curve; c; c = c->next ) + curve = new Curve( *c, value, curve ); + + range[0] = upper.range[0]; + range[1] = value; + range[2] = value - upper.range[0]; + upper.range[0] = value; + upper.range[2] = upper.range[1] - value; + needsSubdivision = 0; + stepsize = 0; +} + +Curvelist::~Curvelist() +{ + while( curve ) { + Curve *c = curve; + curve = curve->next; + delete c; + } +} + +int +Curvelist::cullCheck( void ) +{ + for( Curve *c = curve; c; c = c->next ) + if( c->cullCheck() == CULL_TRIVIAL_REJECT ) + return CULL_TRIVIAL_REJECT; + return CULL_ACCEPT; +} + +void +Curvelist::getstepsize( void ) +{ + stepsize = range[2]; + Curve *c; + for( c = curve; c; c = c->next ) { + c->getstepsize(); + c->clamp(); + stepsize = ((c->stepsize < stepsize) ? c->stepsize : stepsize); + if( c->needsSamplingSubdivision() ) break; + } + needsSubdivision = ( c ) ? 1 : 0; +} + +int +Curvelist::needsSamplingSubdivision( void ) +{ + return needsSubdivision; +} + diff --git a/src/glu/sgi/libnurbs/internals/curvelist.h b/src/glu/sgi/libnurbs/internals/curvelist.h new file mode 100644 index 0000000..733a511 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/curvelist.h @@ -0,0 +1,62 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * curvelist.h + * + */ + +#ifndef __glucurvelist_h_ +#define __glucurvelist_h_ + +#include "types.h" +#include "defines.h" + +class Mapdesc; +class Quilt; +class Curve; + +class Curvelist +{ +friend class Subdivider; +public: + Curvelist( Quilt *, REAL, REAL ); + Curvelist( Curvelist &, REAL ); + ~Curvelist( void ); + int cullCheck( void ); + void getstepsize( void ); + int needsSamplingSubdivision(); +private: + Curve *curve; + float range[3]; + int needsSubdivision; + float stepsize; +}; +#endif /* __glucurvelist_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/curvesub.cc b/src/glu/sgi/libnurbs/internals/curvesub.cc new file mode 100644 index 0000000..91f2ca8 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/curvesub.cc @@ -0,0 +1,102 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * curvesub.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "subdivider.h" +#include "renderhints.h" +#include "backend.h" +#include "quilt.h" +#include "curvelist.h" +#include "nurbsconsts.h" + +/*-------------------------------------------------------------------------- + * drawCurves - main curve rendering entry point + *-------------------------------------------------------------------------- + */ + +void +Subdivider::drawCurves( void ) +{ + REAL from[1], to[1]; + Flist bpts; + qlist->getRange( from, to, bpts ); + + renderhints.init( ); + + backend.bgncurv(); + for( int i=bpts.start; idownloadAll( &pta, &ptb, backend ); + + Curvelist curvelist( qlist, pta, ptb ); + samplingSplit( curvelist, renderhints.maxsubdivisions ); + } + backend.endcurv(); +} + + +/*-------------------------------------------------------------------------- + * samplingSplit - recursively subdivide patch, cull check each subpatch + *-------------------------------------------------------------------------- + */ + +void +Subdivider::samplingSplit( Curvelist& curvelist, int subdivisions ) +{ + if( curvelist.cullCheck() == CULL_TRIVIAL_REJECT ) return; + + curvelist.getstepsize(); + + if( curvelist.needsSamplingSubdivision() && (subdivisions > 0) ) { + REAL mid = ( curvelist.range[0] + curvelist.range[1] ) * 0.5; + Curvelist lowerlist( curvelist, mid ); + samplingSplit( lowerlist, subdivisions-1 ); // lower + samplingSplit( curvelist, subdivisions-1 ); // upper + } else { + long nu = 1 + ((long) (curvelist.range[2] / curvelist.stepsize)); + backend.curvgrid( curvelist.range[0], curvelist.range[1], nu ); + backend.curvmesh( 0, nu ); + } +} + diff --git a/src/glu/sgi/libnurbs/internals/dataTransform.cc b/src/glu/sgi/libnurbs/internals/dataTransform.cc new file mode 100644 index 0000000..55c0fbb --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/dataTransform.cc @@ -0,0 +1,209 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include +#include "glimports.h" +#include "myassert.h" +#include "nurbsconsts.h" +#include "trimvertex.h" +#include "dataTransform.h" + +extern directedLine* arcLoopToDLineLoop(Arc_ptr loop); + +#if 0 // UNUSED +static directedLine* copy_loop(Arc_ptr loop, Real2* vertArray, int& index, directedLine dline_buf[], sampledLine sline_buf[], int& index_dline) +{ + directedLine *ret; + int old_index = index; + int i = index; + int j; + for(j=0; jpwlArc->npts-1; j++, i++) + { + vertArray[i][0] = loop->pwlArc->pts[j].param[0]; + vertArray[i][1] = loop->pwlArc->pts[j].param[1]; + } + loop->clearmark(); + + for(Arc_ptr jarc = loop->next; jarc != loop; jarc=jarc->next) + { + for(j=0; jpwlArc->npts-1; j++, i++) + { + vertArray[i][0] = jarc->pwlArc->pts[j].param[0]; + vertArray[i][1] = jarc->pwlArc->pts[j].param[1]; + } + jarc->clearmark(); + } + //copy the first vertex again + vertArray[i][0] = loop->pwlArc->pts[0].param[0]; + vertArray[i][1] = loop->pwlArc->pts[0].param[1]; + i++; + index=i; + + directedLine* dline; + sampledLine* sline; + sline = &sline_buf[index_dline]; + dline = &dline_buf[index_dline]; + sline->init(2, &vertArray[old_index]); + dline->init(INCREASING, sline); + ret = dline; + index_dline++; + + for(i=old_index+1; i<= index-2; i++) + { + sline = &sline_buf[index_dline]; + dline = &dline_buf[index_dline]; + sline->init(2, &vertArray[i]); + dline->init(INCREASING, sline); + ret->insert(dline); + index_dline++; + } + return ret; +} +#endif + +#if 0 // UNUSED +static int num_edges(Bin& bin) +{ + int sum=0; + for(Arc_ptr jarc = bin.firstarc(); jarc; jarc=bin.nextarc()) + sum += jarc->pwlArc->npts-1; + return sum; +} +#endif + +/* +directedLine* bin_to_DLineLoops(Bin& bin) +{ + directedLine *ret=NULL; + directedLine *temp; + + int numedges = num_edges(bin); + directedLine* dline_buf = new directedLine[numedges]; //not work for N32? + sampledLine* sline_buf=new sampledLine[numedges]; + + Real2* vertArray = new Real2[numedges*2]; + int index = 0; + int index_dline = 0; + bin.markall(); + + for(Arc_ptr jarc = bin.firstarc(); jarc; jarc=bin.nextarc()) + { + if(jarc->ismarked()) + { + assert(jarc->check() != 0); + Arc_ptr jarchead = jarc; + do { + jarc->clearmark(); + jarc = jarc->next; + } while(jarc != jarchead); + temp=copy_loop(jarchead, vertArray, index, dline_buf, sline_buf, index_dline); + ret = temp->insertPolygon(ret); + } + } + + return ret; +} +*/ + + +directedLine* bin_to_DLineLoops(Bin& bin) +{ + directedLine *ret=NULL; + directedLine *temp; + bin.markall(); + for(Arc_ptr jarc=bin.firstarc(); jarc; jarc=bin.nextarc()){ + if(jarc->ismarked()) { + assert(jarc->check() != 0); + Arc_ptr jarchead = jarc; + do { + jarc->clearmark(); + jarc = jarc->next; + } while(jarc != jarchead); + temp = arcLoopToDLineLoop(jarc); + ret = temp->insertPolygon(ret); + } + } + return ret; +} + +directedLine* o_pwlcurve_to_DLines(directedLine* original, O_pwlcurve* pwl) +{ + directedLine* ret = original; + for(Int i=0; inpts-1; i++) + { + sampledLine* sline = new sampledLine(2); + sline->setPoint(0, pwl->pts[i].param); + sline->setPoint(1, pwl->pts[i+1].param); + directedLine* dline = new directedLine(INCREASING, sline); + if(ret == NULL) + ret = dline; + else + ret->insert(dline); + } + return ret; +} + +directedLine* o_curve_to_DLineLoop(O_curve* cur) +{ + directedLine *ret; + if(cur == NULL) + return NULL; + assert(cur->curvetype == ct_pwlcurve); + ret = o_pwlcurve_to_DLines(NULL, cur->curve.o_pwlcurve); + for(O_curve* temp = cur->next; temp != NULL; temp = temp->next) + { + assert(temp->curvetype == ct_pwlcurve); + ret = o_pwlcurve_to_DLines(ret, temp->curve.o_pwlcurve); + } + return ret; +} + +directedLine* o_trim_to_DLineLoops(O_trim* trim) +{ + O_trim* temp; + directedLine *ret; + if(trim == NULL) + return NULL; + ret = o_curve_to_DLineLoop(trim->o_curve); + + for(temp=trim->next; temp != NULL; temp = temp->next) + { + ret = ret->insertPolygon(o_curve_to_DLineLoop(temp->o_curve)); + } + return ret; +} diff --git a/src/glu/sgi/libnurbs/internals/dataTransform.h b/src/glu/sgi/libnurbs/internals/dataTransform.h new file mode 100644 index 0000000..7898df7 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/dataTransform.h @@ -0,0 +1,59 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _DATA_TRANSFORM_H +#define _DATA_TRANSFORM_H + +#include "reader.h" +#include "directedLine.h" +#include "bin.h" +directedLine* bin_to_DLineLoops(Bin& bin); + +/*transform the pwlcurve into a number of directedline lines + *insert these directedlines into orignal which is supposed to be + *the part of the trimming loop obtained so far. + *return the updated trimkming loop. + */ +directedLine* o_pwlcurve_to_DLines(directedLine* original, O_pwlcurve* pwl); + +/*transform a trim loop (curve) into a directedLine loop + */ +directedLine* o_curve_to_DLineLoop(O_curve* curve); + +/*transform a list of trim loops (trim) into + *a list of polygons represented as directedLine*. + */ +directedLine* o_trim_to_DLineLoops(O_trim* trim); + + +#endif + diff --git a/src/glu/sgi/libnurbs/internals/defines.h b/src/glu/sgi/libnurbs/internals/defines.h new file mode 100644 index 0000000..32950d6 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/defines.h @@ -0,0 +1,50 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * defines.h + * + */ + +#ifndef __gludefines_h_ +#define __gludefines_h_ + +/* culling constants */ +#define CULL_TRIVIAL_REJECT 0 +#define CULL_TRIVIAL_ACCEPT 1 +#define CULL_ACCEPT 2 + +/* maximum order of a B-Spline */ +#define MAXORDER 24 + +/* maximum dimension of any B-spline range space */ +#define MAXCOORDS 5 + +#endif /* __gludefines_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/displaylist.cc b/src/glu/sgi/libnurbs/internals/displaylist.cc new file mode 100644 index 0000000..48593c6 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/displaylist.cc @@ -0,0 +1,82 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * displaylist.c++ + * + */ + +#include "glimports.h" +#include "mystdio.h" +#include "nurbstess.h" +#include "displaylist.h" + + +DisplayList::DisplayList( NurbsTessellator *_nt ) : + dlnodePool( sizeof( Dlnode ), 1, "dlnodepool" ) +{ + lastNode = &nodes; + nt = _nt; +} + +DisplayList::~DisplayList( void ) +{ + for( Dlnode *nextNode; nodes; nodes = nextNode ) { + nextNode = nodes->next; + if( nodes->cleanup != 0 ) (nt->*nodes->cleanup)( nodes->arg ); + //nodes->deleteMe(dlnodePool); + } +} + +void +DisplayList::play( void ) +{ + for( Dlnode *node = nodes; node; node = node->next ) + if( node->work != 0 ) (nt->*node->work)( node->arg ); +} + +void +DisplayList::endList( void ) +{ + *lastNode = 0; +} + +void +DisplayList::append( PFVS work, void *arg, PFVS cleanup ) +{ + Dlnode *node = new(dlnodePool) Dlnode( work, arg, cleanup ); + *lastNode = node; + lastNode = &(node->next); +} + diff --git a/src/glu/sgi/libnurbs/internals/displaylist.h b/src/glu/sgi/libnurbs/internals/displaylist.h new file mode 100644 index 0000000..d009a42 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/displaylist.h @@ -0,0 +1,79 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * displaylist.h + * + */ + +#ifndef __gludisplaylist_h_ +#define __gludisplaylist_h_ + +#include "glimports.h" +#include "mysetjmp.h" +#include "mystdio.h" +#include "bufpool.h" + +class NurbsTessellator; + +typedef void (NurbsTessellator::*PFVS)( void * ); + +struct Dlnode : public PooledObj { + Dlnode( PFVS, void *, PFVS ); + PFVS work; + void * arg; + PFVS cleanup; + Dlnode * next; +}; + +inline +Dlnode::Dlnode( PFVS _work, void *_arg, PFVS _cleanup ) +{ + work = _work; + arg = _arg; + cleanup = _cleanup; + next = 0; +} + +class DisplayList { +public: + DisplayList( NurbsTessellator * ); + ~DisplayList( void ); + void play( void ); + void append( PFVS work, void *arg, PFVS cleanup ); + void endList( void ); +private: + Dlnode *nodes; + Pool dlnodePool; + Dlnode **lastNode; + NurbsTessellator *nt; +}; + +#endif /* __gludisplaylist_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/displaymode.h b/src/glu/sgi/libnurbs/internals/displaymode.h new file mode 100644 index 0000000..53968b2 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/displaymode.h @@ -0,0 +1,40 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef __gludisplaymode_h_ +#define __gludisplaymode_h_ + +#define N_MESHFILL 0 +#define N_MESHLINE 1 +#define N_MESHPOINT 2 + +#endif /* __gludisplaymode_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/flist.cc b/src/glu/sgi/libnurbs/internals/flist.cc new file mode 100644 index 0000000..d3162b9 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/flist.cc @@ -0,0 +1,118 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * flist.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "flist.h" + +/*---------------------------------------------------------------------------- + * Flist::Flist - initialize a REAL number array + *---------------------------------------------------------------------------- + */ +Flist::Flist( void ) +{ + npts = 0; + pts = 0; + start = end = 0; +} + +/*---------------------------------------------------------------------------- + * Flist::~Flist - free a REAL number array + *---------------------------------------------------------------------------- + */ +Flist::~Flist( void ) +{ + if( npts ) delete[] pts; +} + +void +Flist::add( REAL x ) +{ + pts[end++] = x; + assert( end <= npts ); +} + +/*---------------------------------------------------------------------------- + * Flist::filter - remove duplicate numbers from array + *---------------------------------------------------------------------------- + */ +void Flist::filter( void ) +{ + sorter.qsort( pts, end ); + start = 0; + + int j = 0; + for( int i = 1; i < end; i++ ) { + if( pts[i] == pts[i-j-1] ) + j++; + pts[i-j] = pts[i]; + } + end -= j; +} + +/*---------------------------------------------------------------------------- + * Flist::grow - ensure that array is large enough + *---------------------------------------------------------------------------- + */ +void Flist::grow( int maxpts ) +{ + if( npts < maxpts ) { + if( npts ) delete[] pts; + npts = 2 * maxpts; + pts = new REAL[npts]; + assert( pts != 0 ); + } + start = end = 0; +} + +/*---------------------------------------------------------------------------- + * Flist::taper - ignore head and tail of array + *---------------------------------------------------------------------------- + */ +void Flist::taper( REAL from, REAL to ) +{ + while( pts[start] != from ) + start++; + + while( pts[end-1] != to ) + end--; +} + + diff --git a/src/glu/sgi/libnurbs/internals/flist.h b/src/glu/sgi/libnurbs/internals/flist.h new file mode 100644 index 0000000..014273e --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/flist.h @@ -0,0 +1,59 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * flist.h + * + */ + +#ifndef __gluflist_h_ +#define __gluflist_h_ + +#include "types.h" +#include "flistsorter.h" + +class Flist { +public: + REAL * pts; /* head of array */ + int npts; /* number of points in array */ + int start; /* first important point index */ + int end; /* last important point index */ + + Flist( void ); + ~Flist( void ); + void add( REAL x ); + void filter( void ); + void grow( int); + void taper( REAL , REAL ); +protected: + FlistSorter sorter; +}; + +#endif /* __gluflist_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/flistsorter.cc b/src/glu/sgi/libnurbs/internals/flistsorter.cc new file mode 100644 index 0000000..d49bdea --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/flistsorter.cc @@ -0,0 +1,81 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * flistsorter.c++ + * + */ + +#include "glimports.h" +#include "flistsorter.h" + +FlistSorter::FlistSorter( void ) : Sorter( sizeof( REAL ) ) +{ +} + +void +FlistSorter::qsort( REAL *p, int n ) +{ + Sorter::qsort( (char *)p, n ); +} + +int +FlistSorter::qscmp( char *i, char *j ) +{ + REAL f0 = *(REAL *)i; + REAL f1 = *(REAL *)j; + return (f0 < f1) ? -1 : 1; +} + +void +FlistSorter::qsexc( char *i, char *j ) +{ + REAL *f0 = (REAL *)i; + REAL *f1 = (REAL *)j; + REAL tmp = *f0; + *f0 = *f1; + *f1 = tmp; +} + +void +FlistSorter::qstexc( char *i, char *j, char *k ) +{ + REAL *f0 = (REAL *)i; + REAL *f1 = (REAL *)j; + REAL *f2 = (REAL *)k; + REAL tmp = *f0; + *f0 = *f2; + *f2 = *f1; + *f1 = tmp; +} diff --git a/src/glu/sgi/libnurbs/internals/flistsorter.h b/src/glu/sgi/libnurbs/internals/flistsorter.h new file mode 100644 index 0000000..65e6a57 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/flistsorter.h @@ -0,0 +1,53 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * flistsorter.h + * + */ + +#ifndef __gluflistsorter_h_ +#define __gluflistsorter_h_ + +#include "sorter.h" +#include "types.h" + +class FlistSorter : public Sorter { +public: + FlistSorter(void); + virtual ~FlistSorter() { /* silence warning*/ } + void qsort( REAL *a, int n ); + +protected: + virtual int qscmp( char *, char * ); + virtual void qsexc( char *i, char *j ); // i<-j, j<-i + virtual void qstexc( char *i, char *j, char *k ); // i<-k, k<-j, j<-i +}; +#endif /* __gluflistsorter_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/gridline.h b/src/glu/sgi/libnurbs/internals/gridline.h new file mode 100644 index 0000000..1a92e3b --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/gridline.h @@ -0,0 +1,46 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * gridline.h + * + */ + +#ifndef __glugridline_h_ +#define __glugridline_h_ + +struct Gridline { + long v; + REAL vval; + long vindex; + long ustart; + long uend; + }; +#endif /* __glugridline_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/gridtrimvertex.h b/src/glu/sgi/libnurbs/internals/gridtrimvertex.h new file mode 100644 index 0000000..707f649 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/gridtrimvertex.h @@ -0,0 +1,89 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * gridtrimvertex.h + * + */ + +#ifndef __glugridtrimvertex_h_ +#define __glugridtrimvertex_h_ + +#include "mystdlib.h" +#include "bufpool.h" +#include "trimvertex.h" +#include "gridvertex.h" + +class GridTrimVertex : public PooledObj +{ +private: + TrimVertex dummyt; + GridVertex dummyg; +public: + GridTrimVertex() { g = 0; t = 0; } + TrimVertex *t; + GridVertex *g; + + inline void set( long, long ); + inline void set( REAL, REAL ); + inline void set( TrimVertex * ); + inline void clear( void ) { t = 0; g = 0; }; + inline int isGridVert() { return g ? 1 : 0 ; } + inline int isTrimVert() { return t ? 1 : 0 ; } + inline void output(); +}; + +inline void +GridTrimVertex::set( long x, long y ) +{ + g = &dummyg; + dummyg.gparam[0] = x; + dummyg.gparam[1] = y; +} + +inline void +GridTrimVertex::set( REAL x, REAL y ) +{ + g = 0; + t = &dummyt; + dummyt.param[0] = x; + dummyt.param[1] = y; + dummyt.nuid = 0; +} + +inline void +GridTrimVertex::set( TrimVertex *v ) +{ + g = 0; + t = v; +} + +typedef GridTrimVertex *GridTrimVertex_p; +#endif /* __glugridtrimvertex_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/gridvertex.h b/src/glu/sgi/libnurbs/internals/gridvertex.h new file mode 100644 index 0000000..2e27436 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/gridvertex.h @@ -0,0 +1,48 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * gridvertex.h + * + */ + +#ifndef __glugridvertex_h_ +#define __glugridvertex_h_ + +struct GridVertex { + long gparam[2]; + GridVertex( void ) { gparam[0] = 0, gparam[1] = 0; } + GridVertex( long u, long v ) { gparam[0] = u, gparam[1] = v; } + void set( long u, long v ) { gparam[0] = u, gparam[1] = v; } + long nextu() { return gparam[0]++; } + long prevu() { return gparam[0]--; } +}; + +#endif /* __glugridvertex_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/hull.cc b/src/glu/sgi/libnurbs/internals/hull.cc new file mode 100644 index 0000000..389ba66 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/hull.cc @@ -0,0 +1,165 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * hull.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "hull.h" +#include "gridvertex.h" +#include "gridtrimvertex.h" +#include "gridline.h" +#include "trimline.h" +#include "uarray.h" +#include "trimregion.h" + +Hull::Hull( void ) +{} + +Hull::~Hull( void ) +{} + +/*---------------------------------------------------------------------- + * Hull:init - this routine does the initialization needed before any + * calls to nextupper or nextlower can be made. + *---------------------------------------------------------------------- + */ +void +Hull::init( void ) +{ + TrimVertex *lfirst = left.first(); + TrimVertex *llast = left.last(); + if( lfirst->param[0] <= llast->param[0] ) { + fakeleft.init( left.first() ); + upper.left = &fakeleft; + lower.left = &left; + } else { + fakeleft.init( left.last() ); + lower.left = &fakeleft; + upper.left = &left; + } + upper.left->last(); + lower.left->first(); + + if( top.ustart <= top.uend ) { + upper.line = ⊤ + upper.index = top.ustart; + } else + upper.line = 0; + + if( bot.ustart <= bot.uend ) { + lower.line = ⊥ + lower.index = bot.ustart; + } else + lower.line = 0; + + TrimVertex *rfirst = right.first(); + TrimVertex *rlast = right.last(); + if( rfirst->param[0] <= rlast->param[0] ) { + fakeright.init( right.last() ); + lower.right = &fakeright; + upper.right = &right; + } else { + fakeright.init( right.first() ); + upper.right = &fakeright; + lower.right = &right; + } + upper.right->first(); + lower.right->last(); +} + +/*---------------------------------------------------------------------- + * nextupper - find next vertex on upper hull of trim region. + * - if vertex is on trim curve, set vtop point to + * that vertex. if vertex is on grid, set vtop to + * point to temporary area and stuff coordinants into + * temporary vertex. Also, place grid coords in temporary + * grid vertex. + *---------------------------------------------------------------------- + */ +GridTrimVertex * +Hull::nextupper( GridTrimVertex *gv ) +{ + if( upper.left ) { + gv->set( upper.left->prev() ); + if( gv->isTrimVert() ) return gv; + upper.left = 0; + } + + if( upper.line ) { + assert( upper.index <= upper.line->uend ); + gv->set( uarray.uarray[upper.index], upper.line->vval ); + gv->set( upper.index, upper.line->vindex ); + if( upper.index++ == upper.line->uend ) upper.line = 0; + return gv; + } + + if( upper.right ) { + gv->set( upper.right->next() ); + if( gv->isTrimVert() ) return gv; + upper.right = 0; + } + + return 0; +} + +GridTrimVertex * +Hull::nextlower( register GridTrimVertex *gv ) +{ + if( lower.left ) { + gv->set( lower.left->next() ); + if( gv->isTrimVert() ) return gv; + lower.left = 0; + } + + if( lower.line ) { + gv->set( uarray.uarray[lower.index], lower.line->vval ); + gv->set( lower.index, lower.line->vindex ); + if( lower.index++ == lower.line->uend ) lower.line = 0; + return gv; + } + + if( lower.right ) { + gv->set( lower.right->prev() ); + if( gv->isTrimVert() ) return gv; + lower.right = 0; + } + + return 0; +} + diff --git a/src/glu/sgi/libnurbs/internals/hull.h b/src/glu/sgi/libnurbs/internals/hull.h new file mode 100644 index 0000000..dfe8652 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/hull.h @@ -0,0 +1,69 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * hull.h + * + */ + +#ifndef __gluhull_h_ +#define __gluhull_h_ + +#include "trimline.h" +#include "trimregion.h" +#include "trimvertex.h" +#include "gridtrimvertex.h" + +struct Gridline; +class Uarray; + +class Hull : virtual public TrimRegion { +public: + Hull( void ); + ~Hull( void ); + void init( void ); + GridTrimVertex * nextlower( GridTrimVertex * ); + GridTrimVertex * nextupper( GridTrimVertex * ); +private: + struct Side { + Trimline *left; + Gridline *line; + Trimline *right; + long index; + }; + + Side lower; + Side upper; + Trimline fakeleft; + Trimline fakeright; +}; + + +#endif /* __gluhull_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/intersect.cc b/src/glu/sgi/libnurbs/internals/intersect.cc new file mode 100644 index 0000000..b39ea21 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/intersect.cc @@ -0,0 +1,665 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * intersect.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "subdivider.h" +#include "arc.h" +#include "bin.h" +#include "backend.h" +#include "trimvertpool.h" + +/*#define NOTDEF*/ + +enum i_result { INTERSECT_VERTEX, INTERSECT_EDGE }; + +/* local functions */ +#ifndef NDEBUG // for asserts only +static int arc_classify( Arc_ptr, int, REAL ); +#endif +static enum i_result pwlarc_intersect( PwlArc *, int, REAL, int, int[3] ); + + +void +Subdivider::partition( Bin & bin, Bin & left, Bin & intersections, + Bin & right, Bin & unknown, int param, REAL value ) +{ + Bin headonleft, headonright, tailonleft, tailonright; + + for( Arc_ptr jarc = bin.removearc(); jarc; jarc = bin.removearc() ) { + + REAL tdiff = jarc->tail()[param] - value; + REAL hdiff = jarc->head()[param] - value; + + if( tdiff > 0.0 ) { + if( hdiff > 0.0 ) { + right.addarc( jarc ); + } else if( hdiff == 0.0 ) { + tailonright.addarc( jarc ); + } else { + Arc_ptr jtemp; + switch( arc_split(jarc, param, value, 0) ) { + case 2: + tailonright.addarc( jarc ); + headonleft.addarc( jarc->next ); + break; + case 31: + assert( jarc->head()[param] > value ); + right.addarc( jarc ); + tailonright.addarc( jtemp = jarc->next ); + headonleft.addarc( jtemp->next ); + break; + case 32: + assert( jarc->head()[param] <= value ); + tailonright .addarc( jarc ); + headonleft.addarc( jtemp = jarc->next ); + left.addarc( jtemp->next ); + break; + case 4: + right.addarc( jarc ); + tailonright.addarc( jtemp = jarc->next ); + headonleft.addarc( jtemp = jtemp->next ); + left.addarc( jtemp->next ); + } + } + } else if( tdiff == 0.0 ) { + if( hdiff > 0.0 ) { + headonright.addarc( jarc ); + } else if( hdiff == 0.0 ) { + unknown.addarc( jarc ); + } else { + headonleft.addarc( jarc ); + } + } else { + if( hdiff > 0.0 ) { + Arc_ptr jtemp; + switch( arc_split(jarc, param, value, 1) ) { + case 2: + tailonleft.addarc( jarc ); + headonright.addarc( jarc->next ); + break; + case 31: + assert( jarc->head()[param] < value ); + left.addarc( jarc ); + tailonleft.addarc( jtemp = jarc->next ); + headonright.addarc( jtemp->next ); + break; + case 32: + assert( jarc->head()[param] >= value ); + tailonleft.addarc( jarc ); + headonright.addarc( jtemp = jarc->next ); + right.addarc( jtemp->next ); + break; + case 4: + left.addarc( jarc ); + tailonleft.addarc( jtemp = jarc->next ); + headonright.addarc( jtemp = jtemp->next ); + right.addarc( jtemp->next ); + } + } else if( hdiff == 0.0 ) { + tailonleft.addarc( jarc ); + } else { + left.addarc( jarc ); + } + } + } + if( param == 0 ) { + classify_headonleft_s( headonleft, intersections, left, value ); + classify_tailonleft_s( tailonleft, intersections, left, value ); + classify_headonright_s( headonright, intersections, right, value ); + classify_tailonright_s( tailonright, intersections, right, value ); + } else { + classify_headonleft_t( headonleft, intersections, left, value ); + classify_tailonleft_t( tailonleft, intersections, left, value ); + classify_headonright_t( headonright, intersections, right, value ); + classify_tailonright_t( tailonright, intersections, right, value ); + } +} + +inline static void +vert_interp( TrimVertex *n, TrimVertex *l, TrimVertex *r, int p, REAL val ) +{ + assert( val > l->param[p]); + assert( val < r->param[p]); + + n->nuid = l->nuid; + + n->param[p] = val; + if( l->param[1-p] != r->param[1-p] ) { + REAL ratio = (val - l->param[p]) / (r->param[p] - l->param[p]); + n->param[1-p] = l->param[1-p] + + ratio * (r->param[1-p] - l->param[1-p]); + } else { + n->param[1-p] = l->param[1-p]; + } +} + +int +Subdivider::arc_split( Arc_ptr jarc, int param, REAL value, int dir ) +{ + int maxvertex = jarc->pwlArc->npts; + Arc_ptr jarc1; + TrimVertex* v = jarc->pwlArc->pts; + + int loc[3]; + switch( pwlarc_intersect( jarc->pwlArc, param, value, dir, loc ) ) { + + // When the parameter value lands on a vertex, life is sweet + case INTERSECT_VERTEX: { + jarc1 = new(arcpool) Arc( jarc, new( pwlarcpool) PwlArc( maxvertex-loc[1], &v[loc[1]] ) ); + jarc->pwlArc->npts = loc[1] + 1; + jarc1->next = jarc->next; + jarc1->next->prev = jarc1; + jarc->next = jarc1; + jarc1->prev = jarc; + assert(jarc->check() != 0); + return 2; + } + + // When the parameter value intersects an edge, we have to + // interpolate a new vertex. There are special cases + // if the new vertex is adjacent to one or both of the + // endpoints of the arc. + case INTERSECT_EDGE: { + int i, j; + if( dir == 0 ) { + i = loc[0]; + j = loc[2]; + } else { + i = loc[2]; + j = loc[0]; + } + +#ifndef NOTDEF + // The split is between vertices at index j and i, in that + // order (j < i) + + // JEB: This code is my idea of how to do the split without + // increasing the number of links. I'm doing this so that + // the is_rect routine can recognize rectangles created by + // subdivision. In exchange for simplifying the curve list, + // however, it costs in allocated space and vertex copies. + + TrimVertex *newjunk = trimvertexpool.get(maxvertex -i+1 /*-j*/); + int k; + for(k=0; knuid; + } + + TrimVertex *vcopy = trimvertexpool.get(maxvertex); + for(k=0; kpwlArc->pts=vcopy; + + v[i].nuid = jarc->nuid; + v[j].nuid = jarc->nuid; + vert_interp( &newjunk[0], &v[loc[0]], &v[loc[2]], param, value ); + + if( showingDegenerate() ) + backend.triangle( &v[i], &newjunk[0], &v[j] ); + + vcopy[j+1].param[0]=newjunk[0].param[0]; + vcopy[j+1].param[1]=newjunk[0].param[1]; + + + jarc1 = new(arcpool) Arc( jarc, + new(pwlarcpool) PwlArc(maxvertex-i+1 , newjunk ) ); + + jarc->pwlArc->npts = j+2; + jarc1->next = jarc->next; + jarc1->next->prev = jarc1; + jarc->next = jarc1; + jarc1->prev = jarc; + assert(jarc->check() != 0); + + return 2; +#endif //not NOTDEF + // JEB: This is the original version: +#ifdef NOTDEF + Arc_ptr jarc2, jarc3; + + TrimVertex *newjunk = trimvertexpool.get(3); + v[i].nuid = jarc->nuid; + v[j].nuid = jarc->nuid; + newjunk[0] = v[j]; + newjunk[2] = v[i]; + vert_interp( &newjunk[1], &v[loc[0]], &v[loc[2]], param, value ); + + if( showingDegenerate() ) + backend.triangle( &newjunk[2], &newjunk[1], &newjunk[0] ); + + // New vertex adjacent to both endpoints + if (maxvertex == 2) { + jarc1 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk+1 ) ); + jarc->pwlArc->npts = 2; + jarc->pwlArc->pts = newjunk; + jarc1->next = jarc->next; + jarc1->next->prev = jarc1; + jarc->next = jarc1; + jarc1->prev = jarc; + assert(jarc->check() != 0); + + return 2; + + // New vertex adjacent to ending point of arc + } else if (maxvertex - j == 2) { + jarc1 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk ) ); + jarc2 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk+1 ) ); + jarc->pwlArc->npts = maxvertex-1; + jarc2->next = jarc->next; + jarc2->next->prev = jarc2; + jarc->next = jarc1; + jarc1->prev = jarc; + jarc1->next = jarc2; + jarc2->prev = jarc1; + assert(jarc->check() != 0); + return 31; + + // New vertex adjacent to starting point of arc + } else if (i == 1) { + jarc1 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk+1 ) ); + jarc2 = new(arcpool) Arc( jarc, + new(pwlarcpool) PwlArc( maxvertex-1, &jarc->pwlArc->pts[1] ) ); + jarc->pwlArc->npts = 2; + jarc->pwlArc->pts = newjunk; + jarc2->next = jarc->next; + jarc2->next->prev = jarc2; + jarc->next = jarc1; + jarc1->prev = jarc; + jarc1->next = jarc2; + jarc2->prev = jarc1; + assert(jarc->check() != 0); + return 32; + + // It's somewhere in the middle + } else { + jarc1 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk ) ); + jarc2 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk+1 ) ); + jarc3 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( maxvertex-i, v+i ) ); + jarc->pwlArc->npts = j + 1; + jarc3->next = jarc->next; + jarc3->next->prev = jarc3; + jarc->next = jarc1; + jarc1->prev = jarc; + jarc1->next = jarc2; + jarc2->prev = jarc1; + jarc2->next = jarc3; + jarc3->prev = jarc2; + assert(jarc->check() != 0); + return 4; + } +#endif // NOTDEF + } + default: + return -1; //picked -1 since it's not used + } +} + +/*---------------------------------------------------------------------------- + * pwlarc_intersect - find intersection of pwlArc and isoparametric line + *---------------------------------------------------------------------------- + */ + +static enum i_result +pwlarc_intersect( + PwlArc *pwlArc, + int param, + REAL value, + int dir, + int loc[3] ) +{ + assert( pwlArc->npts > 0 ); + + if( dir ) { + TrimVertex *v = pwlArc->pts; + int imin = 0; + int imax = pwlArc->npts - 1; + assert( value > v[imin].param[param] ); + assert( value < v[imax].param[param] ); + while( (imax - imin) > 1 ) { + int imid = (imax + imin)/2; + if( v[imid].param[param] > value ) + imax = imid; + else if( v[imid].param[param] < value ) + imin = imid; + else { + loc[1] = imid; + return INTERSECT_VERTEX; + } + } + loc[0] = imin; + loc[2] = imax; + return INTERSECT_EDGE; + } else { + TrimVertex *v = pwlArc->pts; + int imax = 0; + int imin = pwlArc->npts - 1; + assert( value > v[imin].param[param] ); + assert( value < v[imax].param[param] ); + while( (imin - imax) > 1 ) { + int imid = (imax + imin)/2; + if( v[imid].param[param] > value ) + imax = imid; + else if( v[imid].param[param] < value ) + imin = imid; + else { + loc[1] = imid; + return INTERSECT_VERTEX; + } + } + loc[0] = imin; + loc[2] = imax; + return INTERSECT_EDGE; + } +} + +/*---------------------------------------------------------------------------- + * arc_classify - determine which side of a line a jarc lies + *---------------------------------------------------------------------------- + */ + +#ifndef NDEBUG // for asserts only +static int +arc_classify( Arc_ptr jarc, int param, REAL value ) +{ + REAL tdiff, hdiff; + if( param == 0 ) { + tdiff = jarc->tail()[0] - value; + hdiff = jarc->head()[0] - value; + } else { + tdiff = jarc->tail()[1] - value; + hdiff = jarc->head()[1] - value; + } + + if( tdiff > 0.0 ) { + if( hdiff > 0.0 ) { + return 0x11; + } else if( hdiff == 0.0 ) { + return 0x12; + } else { + return 0x10; + } + } else if( tdiff == 0.0 ) { + if( hdiff > 0.0 ) { + return 0x21; + } else if( hdiff == 0.0 ) { + return 0x22; + } else { + return 0x20; + } + } else { + if( hdiff > 0.0 ) { + return 0x01; + } else if( hdiff == 0.0 ) { + return 0x02; + } else { + return 0; + } + } +} +#endif + +void +Subdivider::classify_tailonleft_s( Bin& bin, Bin& in, Bin& out, REAL val ) +{ + /* tail at left, head on line */ + Arc_ptr j; + + while( (j = bin.removearc()) != NULL ) { + assert( arc_classify( j, 0, val ) == 0x02 ); + j->clearitail(); + + REAL diff = j->next->head()[0] - val; + if( diff > 0.0 ) { + in.addarc( j ); + } else if( diff < 0.0 ) { + if( ccwTurn_sl( j, j->next ) ) + out.addarc( j ); + else + in.addarc( j ); + } else { + if( j->next->tail()[1] > j->next->head()[1] ) + in.addarc(j); + else + out.addarc(j); + } + } +} + +void +Subdivider::classify_tailonleft_t( Bin& bin, Bin& in, Bin& out, REAL val ) +{ + /* tail at left, head on line */ + Arc_ptr j; + + while( (j = bin.removearc()) != NULL ) { + assert( arc_classify( j, 1, val ) == 0x02 ); + j->clearitail(); + + REAL diff = j->next->head()[1] - val; + if( diff > 0.0 ) { + in.addarc( j ); + } else if( diff < 0.0 ) { + if( ccwTurn_tl( j, j->next ) ) + out.addarc( j ); + else + in.addarc( j ); + } else { + if (j->next->tail()[0] > j->next->head()[0] ) + out.addarc( j ); + else + in.addarc( j ); + } + } +} + +void +Subdivider::classify_headonleft_s( Bin& bin, Bin& in, Bin& out, REAL val ) +{ + /* tail on line, head at left */ + Arc_ptr j; + + while( (j = bin.removearc()) != NULL ) { + assert( arc_classify( j, 0, val ) == 0x20 ); + + j->setitail(); + + REAL diff = j->prev->tail()[0] - val; + if( diff > 0.0 ) { + out.addarc( j ); + } else if( diff < 0.0 ) { + if( ccwTurn_sl( j->prev, j ) ) + out.addarc( j ); + else + in.addarc( j ); + } else { + if( j->prev->tail()[1] > j->prev->head()[1] ) + in.addarc( j ); + else + out.addarc( j ); + } + } +} + +void +Subdivider::classify_headonleft_t( Bin& bin, Bin& in, Bin& out, REAL val ) +{ + /* tail on line, head at left */ + Arc_ptr j; + + while( (j = bin.removearc()) != NULL ) { + assert( arc_classify( j, 1, val ) == 0x20 ); + j->setitail(); + + REAL diff = j->prev->tail()[1] - val; + if( diff > 0.0 ) { + out.addarc( j ); + } else if( diff < 0.0 ) { + if( ccwTurn_tl( j->prev, j ) ) + out.addarc( j ); + else + in.addarc( j ); + } else { + if( j->prev->tail()[0] > j->prev->head()[0] ) + out.addarc( j ); + else + in.addarc( j ); + } + } +} + + +void +Subdivider::classify_tailonright_s( Bin& bin, Bin& in, Bin& out, REAL val ) +{ + /* tail at right, head on line */ + Arc_ptr j; + + while( (j = bin.removearc()) != NULL ) { + assert( arc_classify( j, 0, val ) == 0x12); + + j->clearitail(); + + REAL diff = j->next->head()[0] - val; + if( diff > 0.0 ) { + if( ccwTurn_sr( j, j->next ) ) + out.addarc( j ); + else + in.addarc( j ); + } else if( diff < 0.0 ) { + in.addarc( j ); + } else { + if( j->next->tail()[1] > j->next->head()[1] ) + out.addarc( j ); + else + in.addarc( j ); + } + } +} + +void +Subdivider::classify_tailonright_t( Bin& bin, Bin& in, Bin& out, REAL val ) +{ + /* tail at right, head on line */ + Arc_ptr j; + + while( (j = bin.removearc()) != NULL ) { + assert( arc_classify( j, 1, val ) == 0x12); + + j->clearitail(); + + REAL diff = j->next->head()[1] - val; + if( diff > 0.0 ) { + if( ccwTurn_tr( j, j->next ) ) + out.addarc( j ); + else + in.addarc( j ); + } else if( diff < 0.0 ) { + in.addarc( j ); + } else { + if( j->next->tail()[0] > j->next->head()[0] ) + in.addarc( j ); + else + out.addarc( j ); + } + } +} + +void +Subdivider::classify_headonright_s( Bin& bin, Bin& in, Bin& out, REAL val ) +{ + /* tail on line, head at right */ + Arc_ptr j; + + while( (j = bin.removearc()) != NULL ) { + assert( arc_classify( j, 0, val ) == 0x21 ); + + j->setitail(); + + REAL diff = j->prev->tail()[0] - val; + if( diff > 0.0 ) { + if( ccwTurn_sr( j->prev, j ) ) + out.addarc( j ); + else + in.addarc( j ); + } else if( diff < 0.0 ) { + out.addarc( j ); + } else { + if( j->prev->tail()[1] > j->prev->head()[1] ) + out.addarc( j ); + else + in.addarc( j ); + } + } +} + +void +Subdivider::classify_headonright_t( Bin& bin, Bin& in, Bin& out, REAL val ) +{ + /* tail on line, head at right */ + Arc_ptr j; + + while( (j = bin.removearc()) != NULL ) { + assert( arc_classify( j, 1, val ) == 0x21 ); + + j->setitail(); + + REAL diff = j->prev->tail()[1] - val; + if( diff > 0.0 ) { + if( ccwTurn_tr( j->prev, j ) ) + out.addarc( j ); + else + in.addarc( j ); + } else if( diff < 0.0 ) { + out.addarc( j ); + } else { + if( j->prev->tail()[0] > j->prev->head()[0] ) + in.addarc( j ); + else + out.addarc( j ); + } + } +} + diff --git a/src/glu/sgi/libnurbs/internals/jarcloc.h b/src/glu/sgi/libnurbs/internals/jarcloc.h new file mode 100644 index 0000000..5297036 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/jarcloc.h @@ -0,0 +1,87 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * jarcloc.h + * + */ + +#ifndef __glujarcloc_h_ +#define __glujarcloc_h_ + +#include "arc.h" + +class Jarcloc { +private: + Arc_ptr arc; + TrimVertex *p; + TrimVertex *plast; +public: + inline void init( Arc_ptr a, long first, long last ) { arc = a; p=&a->pwlArc->pts[first]; plast = &a->pwlArc->pts[last]; } + inline TrimVertex * getnextpt( void ); + inline TrimVertex * getprevpt( void ); + inline void reverse(); +}; + +inline void +Jarcloc::reverse() +{ + if( plast == &arc->pwlArc->pts[0] ) + plast = &arc->pwlArc->pts[arc->pwlArc->npts - 1]; + else + plast = &arc->pwlArc->pts[0]; +} + +inline TrimVertex * +Jarcloc::getnextpt() +{ + assert( p <= plast ); + if( p == plast ) { + arc = arc->next; + p = &arc->pwlArc->pts[0]; + plast = &arc->pwlArc->pts[arc->pwlArc->npts - 1]; + assert( p < plast ); + } + return p++; +} + +inline TrimVertex * +Jarcloc::getprevpt() +{ + assert( p >= plast ); + if( p == plast ) { + arc = arc->prev; + p = &arc->pwlArc->pts[arc->pwlArc->npts - 1]; + plast = &arc->pwlArc->pts[0]; + assert( p > plast ); + } + return p--; +} +#endif /* __glujarcloc_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/knotvector.cc b/src/glu/sgi/libnurbs/internals/knotvector.cc new file mode 100644 index 0000000..dcbf006 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/knotvector.cc @@ -0,0 +1,142 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * knotvector.c++ + * + */ + +#include "glimports.h" +#include "mystdio.h" +#include "myassert.h" +#include "knotvector.h" +#include "defines.h" + +#ifdef __WATCOMC__ +#pragma warning 726 10 +#endif + +void Knotvector::init( long _knotcount, long _stride, long _order, INREAL *_knotlist ) +{ + knotcount = _knotcount; + stride = _stride; + order = _order; + knotlist = new Knot[_knotcount]; + assert( knotlist != 0 ); + + for( int i = 0; i != _knotcount; i++ ) + knotlist[i] = (Knot) _knotlist[i]; +} + +Knotvector::Knotvector( void ) +{ + knotcount = 0; + stride = 0; + order = 0; + knotlist = 0; +} + +Knotvector::~Knotvector( void ) +{ + if( knotlist ) delete[] knotlist; +} + +int Knotvector::validate( void ) +{ + /* kindex is used as an array index so subtract one first, + * this propagates throughout the code so study carefully */ + long kindex = knotcount-1; + + if( order < 1 || order > MAXORDER ) { + // spline order un-supported + return( 1 ); + } + + if( knotcount < (2 * order) ) { + // too few knots + return( 2 ); + } + + if( identical( knotlist[kindex-(order-1)], knotlist[order-1]) ) { + // valid knot range is empty + return( 3 ); + } + + for( long i = 0; i < kindex; i++) + if( knotlist[i] > knotlist[i+1] ) { + // decreasing knot sequence + return( 4 ); + } + + /* check for valid multiplicity */ + + /* kindex is currently the index of the last knot. + * In the next loop it is decremented to ignore the last knot + * and the loop stops when kindex is 2 so as to ignore the first + * knot as well. These knots are not used in computing + * knot multiplicities. + */ + + long multi = 1; + for( ; kindex >= 1; kindex-- ) { + if( knotlist[kindex] - knotlist[kindex-1] < TOLERANCE ) { + multi++; + continue; + } + if ( multi > order ) { + // knot multiplicity greater than order of spline + return( 5 ); + } + multi = 1; + } + + if ( multi > order ) { + // knot multiplicity greater than order of spline + return( 5 ); + } + + return 0; +} + +void Knotvector::show( const char *msg ) +{ +#ifndef NDEBUG + _glu_dprintf( "%s\n", msg ); + _glu_dprintf( "order = %ld, count = %ld\n", order, knotcount ); + + for( int i=0; i +#include "glimports.h" +#include "mystdio.h" +#include "myassert.h" +#include "mystring.h" +#include "mymath.h" +#include "backend.h" +#include "nurbsconsts.h" +#include "mapdesc.h" + +Mapdesc::Mapdesc( long _type, int _israt, int _ncoords, Backend& b ) + : backend( b ) +{ + type = _type; + isrational = _israt; + ncoords = _ncoords; + hcoords = _ncoords + (_israt ? 0 : 1 ); + inhcoords = _ncoords - (_israt ? 1 : 0 ); + mask = ((1<<(inhcoords*2))-1); + next = 0; + + assert( hcoords <= MAXCOORDS ); + assert( inhcoords >= 1 ); + + pixel_tolerance = 1.0; + error_tolerance = 1.0; + bbox_subdividing = N_NOBBOXSUBDIVISION; + culling_method = N_NOCULLING; + sampling_method = N_NOSAMPLING; + clampfactor = N_NOCLAMPING; + minsavings = N_NOSAVINGSSUBDIVISION; + s_steps = 0.0; + t_steps = 0.0; + maxrate = ( s_steps < 0.0 ) ? 0.0 : s_steps; + maxsrate = ( s_steps < 0.0 ) ? 0.0 : s_steps; + maxtrate = ( t_steps < 0.0 ) ? 0.0 : t_steps; + identify( bmat ); + identify( cmat ); + identify( smat ); + for( int i = 0; i != inhcoords; i++ ) + bboxsize[i] = 1.0; +} + +void +Mapdesc::setBboxsize( INREAL *mat ) +{ + for( int i = 0; i != inhcoords; i++ ) + bboxsize[i] = (REAL) mat[i]; +} + +void +Mapdesc::identify( REAL dest[MAXCOORDS][MAXCOORDS] ) +{ + memset( dest, 0, sizeof( dest ) ); + for( int i=0; i != hcoords; i++ ) + dest[i][i] = 1.0; +} + +void +Mapdesc::surfbbox( REAL bb[2][MAXCOORDS] ) +{ + backend.surfbbox( type, bb[0], bb[1] ); +} + +void +Mapdesc::copy( REAL dest[MAXCOORDS][MAXCOORDS], long n, INREAL *src, + long rstride, long cstride ) +{ + assert( n >= 0 ); + for( int i=0; i != n; i++ ) + for( int j=0; j != n; j++ ) + dest[i][j] = src[i*rstride + j*cstride]; +} + +/*-------------------------------------------------------------------------- + * copyPt - copy a homogeneous point + *-------------------------------------------------------------------------- + */ +void +Mapdesc::copyPt( REAL *d, REAL *s ) +{ + assert( hcoords > 0 ); + switch( hcoords ) { + case 4: + d[3] = s[3]; + d[2] = s[2]; + d[1] = s[1]; + d[0] = s[0]; + break; + case 3: + d[2] = s[2]; + d[1] = s[1]; + d[0] = s[0]; + break; + case 2: + d[1] = s[1]; + d[0] = s[0]; + break; + case 1: + d[0] = s[0]; + break; + case 5: + d[4] = s[4]; + d[3] = s[3]; + d[2] = s[2]; + d[1] = s[1]; + d[0] = s[0]; + break; + default: + memcpy( d, s, hcoords * sizeof( REAL ) ); + break; + } +} + +/*-------------------------------------------------------------------------- + * sumPt - compute affine combination of two homogeneous points + *-------------------------------------------------------------------------- + */ +void +Mapdesc::sumPt( REAL *dst, REAL *src1, REAL *src2, register REAL alpha, register REAL beta ) +{ + assert( hcoords > 0 ); + switch( hcoords ) { + case 4: + dst[3] = src1[3] * alpha + src2[3] * beta; + dst[2] = src1[2] * alpha + src2[2] * beta; + dst[1] = src1[1] * alpha + src2[1] * beta; + dst[0] = src1[0] * alpha + src2[0] * beta; + break; + case 3: + dst[2] = src1[2] * alpha + src2[2] * beta; + dst[1] = src1[1] * alpha + src2[1] * beta; + dst[0] = src1[0] * alpha + src2[0] * beta; + break; + case 2: + dst[1] = src1[1] * alpha + src2[1] * beta; + dst[0] = src1[0] * alpha + src2[0] * beta; + break; + case 1: + dst[0] = src1[0] * alpha + src2[0] * beta; + break; + case 5: + dst[4] = src1[4] * alpha + src2[4] * beta; + dst[3] = src1[3] * alpha + src2[3] * beta; + dst[2] = src1[2] * alpha + src2[2] * beta; + dst[1] = src1[1] * alpha + src2[1] * beta; + dst[0] = src1[0] * alpha + src2[0] * beta; + break; + default: { + for( int i = 0; i != hcoords; i++ ) + dst[i] = src1[i] * alpha + src2[i] * beta; + } + break; + } +} + +/*-------------------------------------------------------------------------- + * clipbits - compute bit-vector indicating point/window position + * of a (transformed) homogeneous point + *-------------------------------------------------------------------------- + */ +unsigned int +Mapdesc::clipbits( REAL *p ) +{ + assert( inhcoords >= 0 ); + assert( inhcoords <= 3 ); + + register int nc = inhcoords; + register REAL pw = p[nc]; + register REAL nw = -pw; + register unsigned int bits = 0; + + if( pw == 0.0 ) return mask; + + if( pw > 0.0 ) { + switch( nc ) { + case 3: + if( p[2] <= pw ) bits |= (1<<5); + if( p[2] >= nw ) bits |= (1<<4); + if( p[1] <= pw ) bits |= (1<<3); + if( p[1] >= nw ) bits |= (1<<2); + if( p[0] <= pw ) bits |= (1<<1); + if( p[0] >= nw ) bits |= (1<<0); + return bits; + case 2: + if( p[1] <= pw ) bits |= (1<<3); + if( p[1] >= nw ) bits |= (1<<2); + if( p[0] <= pw ) bits |= (1<<1); + if( p[0] >= nw ) bits |= (1<<0); + return bits; + case 1: + if( p[0] <= pw ) bits |= (1<<1); + if( p[0] >= nw ) bits |= (1<<0); + return bits; + default: { + int bit = 1; + for( int i=0; i= nw ) bits |= bit; + bit <<= 1; + if( p[i] <= pw ) bits |= bit; + bit <<= 1; + } + abort(); + break; + } + } + } else { + switch( nc ) { + case 3: + if( p[2] <= nw ) bits |= (1<<5); + if( p[2] >= pw ) bits |= (1<<4); + if( p[1] <= nw ) bits |= (1<<3); + if( p[1] >= pw ) bits |= (1<<2); + if( p[0] <= nw ) bits |= (1<<1); + if( p[0] >= pw ) bits |= (1<<0); + return bits; + case 2: + if( p[1] <= nw ) bits |= (1<<3); + if( p[1] >= pw ) bits |= (1<<2); + if( p[0] <= nw ) bits |= (1<<1); + if( p[0] >= pw ) bits |= (1<<0); + return bits; + case 1: + if( p[0] <= nw ) bits |= (1<<1); + if( p[0] >= pw ) bits |= (1<<0); + return bits; + default: { + int bit = 1; + for( int i=0; i= pw ) bits |= bit; + bit <<= 1; + if( p[i] <= nw ) bits |= bit; + bit <<= 1; + } + abort(); + break; + } + } + } + return bits; +} + +/*-------------------------------------------------------------------------- + * xformRational - transform a homogeneous point + *-------------------------------------------------------------------------- + */ +void +Mapdesc::xformRational( Maxmatrix mat, REAL *d, REAL *s ) +{ + assert( hcoords >= 0 ); + + if( hcoords == 3 ) { + REAL x = s[0]; + REAL y = s[1]; + REAL z = s[2]; + d[0] = x*mat[0][0]+y*mat[1][0]+z*mat[2][0]; + d[1] = x*mat[0][1]+y*mat[1][1]+z*mat[2][1]; + d[2] = x*mat[0][2]+y*mat[1][2]+z*mat[2][2]; + } else if( hcoords == 4 ) { + REAL x = s[0]; + REAL y = s[1]; + REAL z = s[2]; + REAL w = s[3]; + d[0] = x*mat[0][0]+y*mat[1][0]+z*mat[2][0]+w*mat[3][0]; + d[1] = x*mat[0][1]+y*mat[1][1]+z*mat[2][1]+w*mat[3][1]; + d[2] = x*mat[0][2]+y*mat[1][2]+z*mat[2][2]+w*mat[3][2]; + d[3] = x*mat[0][3]+y*mat[1][3]+z*mat[2][3]+w*mat[3][3]; + } else { + for( int i=0; i != hcoords; i++ ) { + d[i] = 0; + for( int j = 0; j != hcoords; j++ ) + d[i] += s[j] * mat[j][i]; + } + } +} + +/*-------------------------------------------------------------------------- + * xformNonrational - transform a inhomogeneous point to a homogeneous point + *-------------------------------------------------------------------------- + */ +void +Mapdesc::xformNonrational( Maxmatrix mat, REAL *d, REAL *s ) +{ + if( inhcoords == 2 ) { + REAL x = s[0]; + REAL y = s[1]; + d[0] = x*mat[0][0]+y*mat[1][0]+mat[2][0]; + d[1] = x*mat[0][1]+y*mat[1][1]+mat[2][1]; + d[2] = x*mat[0][2]+y*mat[1][2]+mat[2][2]; + } else if( inhcoords == 3 ) { + REAL x = s[0]; + REAL y = s[1]; + REAL z = s[2]; + d[0] = x*mat[0][0]+y*mat[1][0]+z*mat[2][0]+mat[3][0]; + d[1] = x*mat[0][1]+y*mat[1][1]+z*mat[2][1]+mat[3][1]; + d[2] = x*mat[0][2]+y*mat[1][2]+z*mat[2][2]+mat[3][2]; + d[3] = x*mat[0][3]+y*mat[1][3]+z*mat[2][3]+mat[3][3]; + } else { + assert( inhcoords >= 0 ); + for( int i=0; i != hcoords; i++ ) { + d[i] = mat[inhcoords][i]; + for( int j = 0; j < inhcoords; j++ ) + d[i] += s[j] * mat[j][i]; + } + } +} + +/*-------------------------------------------------------------------------- + * xformAndCullCheck - transform a set of points that may be EITHER + * homogeneous or inhomogeneous depending on the map description and + * check if they are either completely inside, completely outside, + * or intersecting the viewing frustrum. + *-------------------------------------------------------------------------- + */ +int +Mapdesc::xformAndCullCheck( + REAL *pts, int uorder, int ustride, int vorder, int vstride ) +{ + assert( uorder > 0 ); + assert( vorder > 0 ); + + unsigned int inbits = mask; + unsigned int outbits = 0; + + REAL *p = pts; + for( REAL *pend = p + uorder * ustride; p != pend; p += ustride ) { + REAL *q = p; + for( REAL *qend = q + vorder * vstride; q != qend; q += vstride ) { + REAL cpts[MAXCOORDS]; + xformCulling( cpts, q ); + unsigned int bits = clipbits( cpts ); + outbits |= bits; + inbits &= bits; + if( ( outbits == (unsigned int)mask ) && ( inbits != (unsigned int)mask ) ) return CULL_ACCEPT; + } + } + + if( outbits != (unsigned int)mask ) { + return CULL_TRIVIAL_REJECT; + } else if( inbits == (unsigned int)mask ) { + return CULL_TRIVIAL_ACCEPT; + } else { + return CULL_ACCEPT; + } +} + +/*-------------------------------------------------------------------------- + * cullCheck - check if a set of homogeneous transformed points are + * either completely inside, completely outside, + * or intersecting the viewing frustrum. + *-------------------------------------------------------------------------- + */ +int +Mapdesc::cullCheck( REAL *pts, int uorder, int ustride, int vorder, int vstride ) +{ + unsigned int inbits = mask; + unsigned int outbits = 0; + + REAL *p = pts; + for( REAL *pend = p + uorder * ustride; p != pend; p += ustride ) { + REAL *q = p; + for( REAL *qend = q + vorder * vstride; q != qend; q += vstride ) { + unsigned int bits = clipbits( q ); + outbits |= bits; + inbits &= bits; + if( ( outbits == (unsigned int)mask ) && ( inbits != (unsigned int)mask ) ) return CULL_ACCEPT; + } + } + + if( outbits != (unsigned int)mask ) { + return CULL_TRIVIAL_REJECT; + } else if( inbits == (unsigned int)mask ) { + return CULL_TRIVIAL_ACCEPT; + } else { + return CULL_ACCEPT; + } +} + +/*-------------------------------------------------------------------------- + * cullCheck - check if a set of homogeneous transformed points are + * either completely inside, completely outside, + * or intersecting the viewing frustrum. + *-------------------------------------------------------------------------- + */ +int +Mapdesc::cullCheck( REAL *pts, int order, int stride ) +{ + unsigned int inbits = mask; + unsigned int outbits = 0; + + REAL *p = pts; + for( REAL *pend = p + order * stride; p != pend; p += stride ) { + unsigned int bits = clipbits( p ); + outbits |= bits; + inbits &= bits; + if( ( outbits == (unsigned int)mask ) && ( inbits != (unsigned int)mask ) ) return CULL_ACCEPT; + } + + if( outbits != (unsigned int)mask ) { + return CULL_TRIVIAL_REJECT; + } else if( inbits == (unsigned int)mask ) { + return CULL_TRIVIAL_ACCEPT; + } else { + return CULL_ACCEPT; + } +} + +/*-------------------------------------------------------------------------- + * xformSampling - transform a set of points that may be EITHER + * homogeneous or inhomogeneous depending on the map description + * into sampling space + *-------------------------------------------------------------------------- + */ +void +Mapdesc::xformSampling( REAL *pts, int order, int stride, REAL *sp, int outstride ) +{ + xformMat( smat, pts, order, stride, sp, outstride ); +} + +void +Mapdesc::xformBounding( REAL *pts, int order, int stride, REAL *sp, int outstride ) +{ + xformMat( bmat, pts, order, stride, sp, outstride ); +} + +/*-------------------------------------------------------------------------- + * xformCulling - transform a set of points that may be EITHER + * homogeneous or inhomogeneous depending on the map description + * into culling space + *-------------------------------------------------------------------------- + */ +void +Mapdesc::xformCulling( REAL *pts, int order, int stride, REAL *cp, int outstride ) +{ + xformMat( cmat, pts, order, stride, cp, outstride ); +} + +/*-------------------------------------------------------------------------- + * xformCulling - transform a set of points that may be EITHER + * homogeneous or inhomogeneous depending on the map description + * into culling space + *-------------------------------------------------------------------------- + */ +void +Mapdesc::xformCulling( REAL *pts, + int uorder, int ustride, + int vorder, int vstride, + REAL *cp, int outustride, int outvstride ) +{ + xformMat( cmat, pts, uorder, ustride, vorder, vstride, cp, outustride, outvstride ); +} + +/*-------------------------------------------------------------------------- + * xformSampling - transform a set of points that may be EITHER + * homogeneous or inhomogeneous depending on the map description + * into sampling space + *-------------------------------------------------------------------------- + */ +void +Mapdesc::xformSampling( REAL *pts, + int uorder, int ustride, + int vorder, int vstride, + REAL *sp, int outustride, int outvstride ) +{ + xformMat( smat, pts, uorder, ustride, vorder, vstride, sp, outustride, outvstride ); +} + +void +Mapdesc::xformBounding( REAL *pts, + int uorder, int ustride, + int vorder, int vstride, + REAL *sp, int outustride, int outvstride ) +{ + xformMat( bmat, pts, uorder, ustride, vorder, vstride, sp, outustride, outvstride ); +} + +void +Mapdesc::xformMat( + Maxmatrix mat, + REAL * pts, + int order, + int stride, + REAL * cp, + int outstride ) +{ + if( isrational ) { + REAL *pend = pts + order * stride; + for( REAL *p = pts ; p != pend; p += stride ) { + xformRational( mat, cp, p ); + cp += outstride; + } + } else { + REAL *pend = pts + order * stride; + for( REAL *p = pts ; p != pend; p += stride ) { + xformNonrational( mat, cp, p ); + cp += outstride; + } + } +} + +void +Mapdesc::xformMat( Maxmatrix mat, REAL *pts, + int uorder, int ustride, + int vorder, int vstride, + REAL *cp, int outustride, int outvstride ) +{ + if( isrational ) { + REAL *pend = pts + uorder * ustride; + for( REAL *p = pts ; p != pend; p += ustride ) { + REAL *cpts2 = cp; + REAL *qend = p + vorder * vstride; + for( REAL *q = p; q != qend; q += vstride ) { + xformRational( mat, cpts2, q ); + cpts2 += outvstride; + } + cp += outustride; + } + } else { + REAL *pend = pts + uorder * ustride; + for( REAL *p = pts ; p != pend; p += ustride ) { + REAL *cpts2 = cp; + REAL *qend = p + vorder * vstride; + for( REAL *q = p; q != qend; q += vstride ) { + xformNonrational( mat, cpts2, q ); + cpts2 += outvstride; + } + cp += outustride; + } + } +} + +/*-------------------------------------------------------------------------- + * subdivide - subdivide a curve along an isoparametric line + *-------------------------------------------------------------------------- + */ + +void +Mapdesc::subdivide( REAL *src, REAL *dst, REAL v, int stride, int order ) +{ + REAL mv = 1.0 - v; + + for( REAL *send=src+stride*order; src!=send; send-=stride, dst+=stride ) { + copyPt( dst, src ); + REAL *qpnt = src + stride; + for( REAL *qp=src; qpnt!=send; qp=qpnt, qpnt+=stride ) + sumPt( qp, qp, qpnt, mv, v ); + } +} + +/*-------------------------------------------------------------------------- + * subdivide - subdivide a patch along an isoparametric line + *-------------------------------------------------------------------------- + */ + +void +Mapdesc::subdivide( REAL *src, REAL *dst, REAL v, + int so, int ss, int to, int ts ) +{ + REAL mv = 1.0 - v; + + for( REAL *slast = src+ss*so; src != slast; src += ss, dst += ss ) { + REAL *sp = src; + REAL *dp = dst; + for( REAL *send = src+ts*to; sp != send; send -= ts, dp += ts ) { + copyPt( dp, sp ); + REAL *qp = sp; + for( REAL *qpnt = sp+ts; qpnt != send; qp = qpnt, qpnt += ts ) + sumPt( qp, qp, qpnt, mv, v ); + } + } +} + + +#define sign(x) ((x > 0) ? 1 : ((x < 0.0) ? -1 : 0)) + +/*-------------------------------------------------------------------------- + * project - project a set of homogeneous coordinates into inhomogeneous ones + *-------------------------------------------------------------------------- + */ +int +Mapdesc::project( REAL *src, int rstride, int cstride, + REAL *dest, int trstride, int tcstride, + int nrows, int ncols ) +{ + int s = sign( src[inhcoords] ); + REAL *rlast = src + nrows * rstride; + REAL *trptr = dest; + for( REAL *rptr=src; rptr != rlast; rptr+=rstride, trptr+=trstride ) { + REAL *clast = rptr + ncols * cstride; + REAL *tcptr = trptr; + for( REAL *cptr = rptr; cptr != clast; cptr+=cstride, tcptr+=tcstride ) { + REAL *coordlast = cptr + inhcoords; + if( sign( *coordlast ) != s ) return 0; + REAL *tcoord = tcptr; + for( REAL *coord = cptr; coord != coordlast; coord++, tcoord++ ) { + *tcoord = *coord / *coordlast; + } + } + } + return 1; +} + +/*-------------------------------------------------------------------------- + * project - project a set of homogeneous coordinates into inhomogeneous ones + *-------------------------------------------------------------------------- + */ +int +Mapdesc::project( REAL *src, int stride, REAL *dest, int tstride, int ncols ) +{ + int s = sign( src[inhcoords] ); + + REAL *clast = src + ncols * stride; + for( REAL *cptr = src, *tcptr = dest; cptr != clast; cptr+=stride, tcptr+=tstride ) { + REAL *coordlast = cptr + inhcoords; + if( sign( *coordlast ) != s ) return 0; + for( REAL *coord = cptr, *tcoord = tcptr; coord != coordlast; coord++, tcoord++ ) + *tcoord = *coord / *coordlast; + } + + return 1; +} + +int +Mapdesc::bboxTooBig( + REAL *p, + int rstride, + int cstride, + int nrows, + int ncols, + REAL bb[2][MAXCOORDS] ) +{ + REAL bbpts[MAXORDER][MAXORDER][MAXCOORDS]; + const int trstride = sizeof(bbpts[0]) / sizeof(REAL); + const int tcstride = sizeof(bbpts[0][0]) / sizeof(REAL); + + // points have been transformed, therefore they are homogeneous + // project points + int val = project( p, rstride, cstride, + &bbpts[0][0][0], trstride, tcstride, nrows, ncols ); + if( val == 0 ) return -1; + + // compute bounding box + bbox( bb, &bbpts[0][0][0], trstride, tcstride, nrows, ncols ); + + // find out if bounding box can't fit in unit cube + if( bbox_subdividing == N_BBOXROUND ) { + for( int k=0; k != inhcoords; k++ ) + if( ceilf(bb[1][k]) - floorf(bb[0][k]) > bboxsize[k] ) return 1; + } else { + for( int k=0; k != inhcoords; k++ ) + if( bb[1][k] - bb[0][k] > bboxsize[k] ) return 1; + } + return 0; +} + +void +Mapdesc::bbox( + REAL bb[2][MAXCOORDS], + REAL *p, + int rstride, + int cstride, + int nrows, + int ncols ) +{ + int k; + for( k=0; k != inhcoords; k++ ) + bb[0][k] = bb[1][k] = p[k]; + + for( int i=0; i != nrows; i++ ) + for( int j=0; j != ncols; j++ ) + for( k=0; k != inhcoords; k++ ) { + REAL x = p[i*rstride + j*cstride + k]; + if( x < bb[0][k] ) bb[0][k] = x; + else if( x > bb[1][k] ) bb[1][k] = x; + } +} + +/*-------------------------------------------------------------------------- + * calcVelocityRational - calculate upper bound on first partial derivative + * of a homogeneous set of points and bounds on each row of points. + *-------------------------------------------------------------------------- + */ +REAL +Mapdesc::calcVelocityRational( REAL *p, int stride, int ncols ) +{ + REAL tmp[MAXORDER][MAXCOORDS]; + + assert( ncols <= MAXORDER ); + + const int tstride = sizeof(tmp[0]) / sizeof(REAL); + + if( project( p, stride, &tmp[0][0], tstride, ncols ) ) { + return calcPartialVelocity( &tmp[0][0], tstride, ncols, 1, 1.0 ); + } else { /* XXX */ + return calcPartialVelocity( &tmp[0][0], tstride, ncols, 1, 1.0 ); + } +} + +/*-------------------------------------------------------------------------- + * calcVelocityNonrational - calculate upper bound on first partial + * derivative of a inhomogeneous set of points. + *-------------------------------------------------------------------------- + */ +REAL +Mapdesc::calcVelocityNonrational( REAL *pts, int stride, int ncols ) +{ + return calcPartialVelocity( pts, stride, ncols, 1, 1.0 ); +} + +int +Mapdesc::isProperty( long property ) +{ + switch ( property ) { + case N_PIXEL_TOLERANCE: + case N_ERROR_TOLERANCE: + case N_CULLING: + case N_BBOX_SUBDIVIDING: + case N_S_STEPS: + case N_T_STEPS: + case N_SAMPLINGMETHOD: + case N_CLAMPFACTOR: + case N_MINSAVINGS: + return 1; + default: + return 0; + } +} + +REAL +Mapdesc::getProperty( long property ) +{ + switch ( property ) { + case N_PIXEL_TOLERANCE: + return pixel_tolerance; + case N_ERROR_TOLERANCE: + return error_tolerance; + case N_CULLING: + return culling_method; + case N_BBOX_SUBDIVIDING: + return bbox_subdividing; + case N_S_STEPS: + return s_steps; + case N_T_STEPS: + return t_steps; + case N_SAMPLINGMETHOD: + return sampling_method; + case N_CLAMPFACTOR: + return clampfactor; + case N_MINSAVINGS: + return minsavings; + default: + abort(); + return -1; //not necessary, needed to shut up compiler + } +} + +void +Mapdesc::setProperty( long property, REAL value ) +{ + + switch ( property ) { + case N_PIXEL_TOLERANCE: + pixel_tolerance = value; + break; + case N_ERROR_TOLERANCE: + error_tolerance = value; + break; + case N_CULLING: + culling_method = value; + break; + case N_BBOX_SUBDIVIDING: + if( value <= 0.0 ) value = N_NOBBOXSUBDIVISION; + bbox_subdividing = value; + break; + case N_S_STEPS: + if( value < 0.0 ) value = 0.0; + s_steps = value; + maxrate = ( value < 0.0 ) ? 0.0 : value; + maxsrate = ( value < 0.0 ) ? 0.0 : value; + break; + case N_T_STEPS: + if( value < 0.0 ) value = 0.0; + t_steps = value; + maxtrate = ( value < 0.0 ) ? 0.0 : value; + break; + case N_SAMPLINGMETHOD: + sampling_method = value; + break; + case N_CLAMPFACTOR: + if( value <= 0.0 ) value = N_NOCLAMPING; + clampfactor = value; + break; + case N_MINSAVINGS: + if( value <= 0.0 ) value = N_NOSAVINGSSUBDIVISION; + minsavings = value; + break; + default: + abort(); + break; + } +} + diff --git a/src/glu/sgi/libnurbs/internals/mapdesc.h b/src/glu/sgi/libnurbs/internals/mapdesc.h new file mode 100644 index 0000000..6f06154 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/mapdesc.h @@ -0,0 +1,271 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * mapdesc.h + * + */ + +#ifndef __glumapdesc_h_ +#define __glumapdesc_h_ + +#include "mystdio.h" +#include "types.h" +#include "defines.h" +#include "bufpool.h" +#include "nurbsconsts.h" + +typedef REAL Maxmatrix[MAXCOORDS][MAXCOORDS]; + +class Backend; + +class Mapdesc : public PooledObj { + friend class Maplist; + +public: + Mapdesc( long, int, int, Backend & ); + int isProperty( long ); + REAL getProperty( long ); + void setProperty( long, REAL ); + int isConstantSampling( void ); + int isDomainSampling( void ); + int isRangeSampling( void ); + int isSampling( void ); + int isParametricDistanceSampling( void ); + int isObjectSpaceParaSampling( void ); + int isObjectSpacePathSampling( void ); + int isSurfaceAreaSampling( void ); + int isPathLengthSampling( void ); + int isCulling( void ); + int isBboxSubdividing( void ); + long getType( void ); + + /* curve routines */ + void subdivide( REAL *, REAL *, REAL, int, int ); + int cullCheck( REAL *, int, int ); + void xformBounding( REAL *, int, int, REAL *, int ); + void xformCulling( REAL *, int, int, REAL *, int ); + void xformSampling( REAL *, int, int, REAL *, int ); + void xformMat( Maxmatrix, REAL *, int, int, REAL *, int ); + REAL calcPartialVelocity ( REAL *, int, int, int, REAL ); + int project( REAL *, int, REAL *, int, int ); + REAL calcVelocityRational( REAL *, int, int ); + REAL calcVelocityNonrational( REAL *, int, int ); + + /* surface routines */ + void subdivide( REAL *, REAL *, REAL, int, int, int, int ); + int cullCheck( REAL *, int, int, int, int ); + void xformBounding( REAL *, int, int, int, int, REAL *, int, int ); + void xformCulling( REAL *, int, int, int, int, REAL *, int, int ); + void xformSampling( REAL *, int, int, int, int, REAL *, int, int ); + void xformMat( Maxmatrix, REAL *, int, int, int, int, REAL *, int, int ); + REAL calcPartialVelocity ( REAL *, REAL *, int, int, int, int, int, int, REAL, REAL, int ); + int project( REAL *, int, int, REAL *, int, int, int, int); + void surfbbox( REAL bb[2][MAXCOORDS] ); + + int bboxTooBig( REAL *, int, int, int, int, REAL [2][MAXCOORDS] ); + int xformAndCullCheck( REAL *, int, int, int, int ); + + void identify( REAL[MAXCOORDS][MAXCOORDS] ); + void setBboxsize( INREAL *); + inline void setBmat( INREAL*, long, long ); + inline void setCmat( INREAL*, long, long ); + inline void setSmat( INREAL*, long, long ); + inline int isRational( void ); + inline int getNcoords( void ); + + REAL pixel_tolerance; /* pathlength sampling tolerance */ + REAL error_tolerance; /* parametric error sampling tolerance*/ + REAL object_space_error_tolerance; /* object space tess*/ + REAL clampfactor; + REAL minsavings; + REAL maxrate; + REAL maxsrate; + REAL maxtrate; + REAL bboxsize[MAXCOORDS]; + +private: + long type; + int isrational; + int ncoords; + int hcoords; + int inhcoords; + int mask; + Maxmatrix bmat; + Maxmatrix cmat; + Maxmatrix smat; + REAL s_steps; /* max samples in s direction */ + REAL t_steps; /* max samples in t direction */ + REAL sampling_method; + REAL culling_method; /* check for culling */ + REAL bbox_subdividing; + Mapdesc * next; + Backend & backend; + + void bbox( REAL [2][MAXCOORDS], REAL *, int, int, int, int ); + REAL maxDifference( int, REAL *, int ); + static void copy( Maxmatrix, long, INREAL *, long, long ); + + /* individual control point routines */ + static void transform4d( float[4], float[4], float[4][4] ); + static void multmatrix4d ( float[4][4], const float[4][4], + const float[4][4] ); + void copyPt( REAL *, REAL * ); + void sumPt( REAL *, REAL *, REAL *, REAL, REAL ); + void xformSampling( REAL *, REAL * ); + void xformCulling( REAL *, REAL * ); + void xformRational( Maxmatrix, REAL *, REAL * ); + void xformNonrational( Maxmatrix, REAL *, REAL * ); + unsigned int clipbits( REAL * ); +}; + +inline void +Mapdesc::setBmat( INREAL *mat, long rstride, long cstride ) +{ + copy( bmat, hcoords, mat, rstride, cstride ); +} + +inline void +Mapdesc::setCmat( INREAL *mat, long rstride, long cstride ) +{ + copy( cmat, hcoords, mat, rstride, cstride ); +} + +inline void +Mapdesc::setSmat( INREAL *mat, long rstride, long cstride ) +{ + copy( smat, hcoords, mat, rstride, cstride ); +} + +inline long +Mapdesc::getType( void ) +{ + return type; +} + +inline void +Mapdesc::xformCulling( REAL *d, REAL *s ) +{ + if( isrational ) + xformRational( cmat, d, s ); + else + xformNonrational( cmat, d, s ); +} + +inline void +Mapdesc::xformSampling( REAL *d, REAL *s ) +{ + if( isrational ) + xformRational( smat, d, s ); + else + xformNonrational( smat, d, s ); +} + +inline int +Mapdesc::isRational( void ) +{ + return isrational ? 1 : 0; +} + +inline int +Mapdesc::getNcoords( void ) +{ + return ncoords; +} + +inline int +Mapdesc::isConstantSampling( void ) +{ + return ((sampling_method == N_FIXEDRATE) ? 1 : 0); +} + +inline int +Mapdesc::isDomainSampling( void ) +{ + return ((sampling_method == N_DOMAINDISTANCE) ? 1 : 0); +} + +inline int +Mapdesc::isParametricDistanceSampling( void ) +{ + return ((sampling_method == N_PARAMETRICDISTANCE) ? 1 : 0); +} + +inline int +Mapdesc::isObjectSpaceParaSampling( void ) +{ + return ((sampling_method == N_OBJECTSPACE_PARA) ? 1 : 0); +} + +inline int +Mapdesc::isObjectSpacePathSampling( void ) +{ + return ((sampling_method == N_OBJECTSPACE_PATH) ? 1 : 0); +} + +inline int +Mapdesc::isSurfaceAreaSampling( void ) +{ + return ((sampling_method == N_SURFACEAREA) ? 1 : 0); +} + +inline int +Mapdesc::isPathLengthSampling( void ) +{ + return ((sampling_method == N_PATHLENGTH) ? 1 : 0); +} + +inline int +Mapdesc::isRangeSampling( void ) +{ + return ( isParametricDistanceSampling() || isPathLengthSampling() || + isSurfaceAreaSampling() || + isObjectSpaceParaSampling() || + isObjectSpacePathSampling()); +} + +inline int +Mapdesc::isSampling( void ) +{ + return isRangeSampling() || isConstantSampling() || isDomainSampling(); +} + +inline int +Mapdesc::isCulling( void ) +{ + return ((culling_method != N_NOCULLING) ? 1 : 0); +} + +inline int +Mapdesc::isBboxSubdividing( void ) +{ + return ((bbox_subdividing != N_NOBBOXSUBDIVISION) ? 1 : 0); +} +#endif /* __glumapdesc_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/mapdescv.cc b/src/glu/sgi/libnurbs/internals/mapdescv.cc new file mode 100644 index 0000000..35b38b1 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/mapdescv.cc @@ -0,0 +1,243 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * mapdescv.c++ + * + */ + +#include "glimports.h" +#include "mystdio.h" +#include "myassert.h" +#include "mystring.h" +#include "mymath.h" +#include "nurbsconsts.h" +#include "mapdesc.h" + +/*-------------------------------------------------------------------------- + * calcPartialVelocity - calculate maximum magnitude of a given partial + * derivative + *-------------------------------------------------------------------------- + */ +REAL +Mapdesc::calcPartialVelocity ( + REAL *p, + int stride, + int ncols, + int partial, + REAL range ) +{ + REAL tmp[MAXORDER][MAXCOORDS]; + REAL mag[MAXORDER]; + + assert( ncols <= MAXORDER ); + + int j, k, t; + // copy inhomogeneous control points into temporary array + for( j=0; j != ncols; j++ ) + for( k=0; k != inhcoords; k++ ) + tmp[j][k] = p[j*stride + k]; + + for( t=0; t != partial; t++ ) + for( j=0; j != ncols-t-1; j++ ) + for( k=0; k != inhcoords; k++ ) + tmp[j][k] = tmp[j+1][k] - tmp[j][k]; + + // compute magnitude and store in mag array + for( j=0; j != ncols-partial; j++ ) { + mag[j] = 0.0; + for( k=0; k != inhcoords; k++ ) + mag[j] += tmp[j][k] * tmp[j][k]; + } + + // compute scale factor + REAL fac = 1; + REAL invt = 1.0 / range; + for( t = ncols-1; t != ncols-1-partial; t-- ) + fac *= t * invt; + + // compute max magnitude of all entries in array + REAL max = 0.0; + for( j=0; j != ncols-partial; j++ ) + if( mag[j] > max ) max = mag[j]; + max = fac * sqrtf( (float) max ); + + return max; +} + +/*-------------------------------------------------------------------------- + * calcPartialVelocity - calculate maximum magnitude of a given partial + * derivative + *-------------------------------------------------------------------------- + */ +REAL +Mapdesc::calcPartialVelocity ( + REAL *dist, + REAL *p, + int rstride, + int cstride, + int nrows, + int ncols, + int spartial, + int tpartial, + REAL srange, + REAL trange, + int side ) +{ + REAL tmp[MAXORDER][MAXORDER][MAXCOORDS]; + REAL mag[MAXORDER][MAXORDER]; + + assert( nrows <= MAXORDER ); + assert( ncols <= MAXORDER ); + + REAL *tp = &tmp[0][0][0]; + REAL *mp = &mag[0][0]; + const int istride = sizeof( tmp[0]) / sizeof( tmp[0][0][0] ); + const int jstride = sizeof( tmp[0][0]) / sizeof( tmp[0][0][0] ); + /* + const int kstride = sizeof( tmp[0][0][0]) / sizeof( tmp[0][0][0] ); + */ + const int mistride = sizeof( mag[0]) / sizeof( mag[0][0] ); + const int mjstride = sizeof( mag[0][0]) / sizeof( mag[0][0] ); + const int idist = nrows * istride; + const int jdist = ncols * jstride; + /* + const int kdist = inhcoords * kstride; + */ + const int id = idist - spartial * istride; + const int jd = jdist - tpartial * jstride; + + { + // copy control points + REAL *ti = tp; + REAL *qi = p; + REAL *til = tp + idist; + for( ; ti != til; ) { + REAL *tj = ti; + REAL *qj = qi; + REAL *tjl = ti + jdist; + for( ; tj != tjl; ) { + for( int k=0; k != inhcoords; k++ ) { + tj[k] = qj[k]; + } + tj += jstride; + qj += cstride; + } + ti += istride; + qi += rstride; + } + } + + { + // compute (s)-partial derivative control points + REAL *til = tp + idist - istride; + const REAL *till = til - ( spartial * istride ); + for( ; til != till; til -= istride ) + for( REAL *ti = tp; ti != til; ti += istride ) + for( REAL *tj = ti, *tjl = tj + jdist; tj != tjl; tj += jstride ) + for( int k=0; k != inhcoords; k++ ) + tj[k] = tj[k+istride] - tj[k]; + } + + { + // compute (s,t)-partial derivative control points + REAL *tjl = tp + jdist - jstride; + const REAL *tjll = tjl - ( tpartial * jstride ); + for( ; tjl != tjll; tjl -= jstride ) + for( REAL *tj = tp; tj != tjl; tj += jstride ) + for( REAL *ti = tj, *til = ti + id; ti != til; ti += istride ) + for( int k=0; k != inhcoords; k++ ) + ti[k] = ti[k+jstride] - ti[k]; + + } + + REAL max = 0.0; + { + // compute magnitude and store in mag array + memset( (void *) mp, 0, sizeof( mag ) ); + for( REAL *ti = tp, *mi = mp, *til = tp + id; ti != til; ti += istride, mi += mistride ) + for( REAL *tj = ti, *mj = mi, *tjl = ti + jd; tj != tjl; tj += jstride, mj += mjstride ) { + for( int k=0; k != inhcoords; k++ ) + *mj += tj[k] * tj[k]; + if( *mj > max ) max = *mj; + } + + } + + int i, j; + + // compute scale factor + REAL fac = 1.0; + { + REAL invs = 1.0 / srange; + REAL invt = 1.0 / trange; + for( int s = nrows-1, slast = s-spartial; s != slast; s-- ) + fac *= s * invs; + for( int t = ncols-1, tlast = t-tpartial; t != tlast; t-- ) + fac *= t * invt; + } + + if( side == 0 ) { + // compute max magnitude of first and last column + dist[0] = 0.0; + dist[1] = 0.0; + for( i=0; i != nrows-spartial; i++ ) { + j = 0; + if( mag[i][j] > dist[0] ) dist[0] = mag[i][j]; + + j = ncols-tpartial-1; + if( mag[i][j] > dist[1] ) dist[1] = mag[i][j]; + } + dist[0] = fac * sqrtf( dist[0] ); + dist[1] = fac * sqrtf( dist[1] ); + } else if( side == 1 ) { + // compute max magnitude of first and last row + dist[0] = 0.0; + dist[1] = 0.0; + for( j=0; j != ncols-tpartial; j++ ) { + i = 0; + if( mag[i][j] > dist[0] ) dist[0] = mag[i][j]; + + i = nrows-spartial-1; + if( mag[i][j] > dist[1] ) dist[1] = mag[i][j]; + } + dist[0] = fac * sqrtf( dist[0] ); + dist[1] = fac * sqrtf( dist[1] ); + } + + max = fac * sqrtf( (float) max ); + + return max; +} + diff --git a/src/glu/sgi/libnurbs/internals/maplist.cc b/src/glu/sgi/libnurbs/internals/maplist.cc new file mode 100644 index 0000000..e51a3e8 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/maplist.cc @@ -0,0 +1,116 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * maplist.c++ + * + */ + +#include "glimports.h" +#include "mystdio.h" +#include "myassert.h" +#include "mymath.h" +#include "nurbsconsts.h" +#include "maplist.h" +#include "mapdesc.h" + +Maplist::Maplist( Backend& b ) + : mapdescPool( sizeof( Mapdesc ), 10, "mapdesc pool" ), + backend( b ) +{ + maps = 0; lastmap = &maps; +} + +void +Maplist::initialize( void ) +{ + freeMaps(); + define( N_P2D, 0, 2 ); + define( N_P2DR, 1, 3 ); +} + +void +Maplist::add( long type, int israt, int ncoords ) +{ + *lastmap = new(mapdescPool) Mapdesc( type, israt, ncoords, backend ); + lastmap = &((*lastmap)->next); +} + +void +Maplist::define( long type, int israt, int ncoords ) +{ +#ifndef NDEBUG // to avoid warning + Mapdesc *m = locate( type ); + assert( m == NULL || ( m->isrational == israt && m->ncoords == ncoords ) ); +#endif + add( type, israt, ncoords ); +} + +void +Maplist::remove( Mapdesc *m ) +{ + for( Mapdesc **curmap = &maps; *curmap; curmap = &((*curmap)->next) ) { + if( *curmap == m ) { + *curmap = m->next; + m->deleteMe( mapdescPool ); + return; + } + } + abort(); +} + +void +Maplist::freeMaps( void ) +{ + mapdescPool.clear(); + maps = 0; + lastmap = &maps; +} + +Mapdesc * +Maplist::find( long type ) +{ + Mapdesc *val = locate( type ); + assert( val != 0 ); + return val; +} + +Mapdesc * +Maplist::locate( long type ) +{ + Mapdesc *m; + for( m = maps; m; m = m->next ) + if( m->getType() == type ) break; + return m; +} diff --git a/src/glu/sgi/libnurbs/internals/maplist.h b/src/glu/sgi/libnurbs/internals/maplist.h new file mode 100644 index 0000000..49720e4 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/maplist.h @@ -0,0 +1,81 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * maplist.h + * + */ + +#ifndef __glumaplist_h_ +#define __glumaplist_h_ + +#include "types.h" +#include "defines.h" +#include "bufpool.h" + +class Backend; +class Mapdesc; + +class Maplist { +public: + Maplist( Backend & ); + void define( long, int, int ); + inline void undefine( long ); + inline int isMap( long ); + + void initialize( void ); + Mapdesc * find( long ); + Mapdesc * locate( long ); + +private: + Pool mapdescPool; + Mapdesc * maps; + Mapdesc ** lastmap; + Backend & backend; + + void add( long, int, int ); + void remove( Mapdesc * ); + void freeMaps( void ); +}; + +inline int +Maplist::isMap( long type ) +{ + return (locate( type ) ? 1 : 0); +} + +inline void +Maplist::undefine( long type ) +{ + Mapdesc *m = locate( type ); + assert( m != 0 ); + remove( m ); +} +#endif /* __glumaplist_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/mesher.cc b/src/glu/sgi/libnurbs/internals/mesher.cc new file mode 100644 index 0000000..b2d83f4 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/mesher.cc @@ -0,0 +1,489 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * mesher.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "gridvertex.h" +#include "gridtrimvertex.h" +#include "jarcloc.h" +#include "gridline.h" +#include "trimline.h" +#include "uarray.h" +#include "backend.h" +#include "mesher.h" + + +const float Mesher::ZERO = 0.0; + +Mesher::Mesher( Backend& b ) + : backend( b ), + p( sizeof( GridTrimVertex ), 100, "GridTrimVertexPool" ) +{ + stacksize = 0; + vdata = 0; + last[0] = 0; + last[1] = 0; + itop = 0; + lastedge = 0; //needed to prevent purify UMR +} + +Mesher::~Mesher( void ) +{ + if( vdata ) delete[] vdata; +} + +void +Mesher::init( unsigned int npts ) +{ + p.clear(); + if( stacksize < npts ) { + stacksize = 2 * npts; + if( vdata ) delete[] vdata; + vdata = new GridTrimVertex_p[stacksize]; + } +} + +inline void +Mesher::push( GridTrimVertex *gt ) +{ + assert( itop+1 != (int)stacksize ); + vdata[++itop] = gt; +} + +inline void +Mesher::pop( long ) +{ +} + +inline void +Mesher::openMesh() +{ + backend.bgntmesh( "addedge" ); +} + +inline void +Mesher::closeMesh() +{ + backend.endtmesh(); +} + +inline void +Mesher::swapMesh() +{ + backend.swaptmesh(); +} + +inline void +Mesher::clearStack() +{ + itop = -1; + last[0] = 0; +} + +void +Mesher::finishLower( GridTrimVertex *gtlower ) +{ + for( push(gtlower); + nextlower( gtlower=new(p) GridTrimVertex ); + push(gtlower) ) + addLower(); + addLast(); +} + +void +Mesher::finishUpper( GridTrimVertex *gtupper ) +{ + for( push(gtupper); + nextupper( gtupper=new(p) GridTrimVertex ); + push(gtupper) ) + addUpper(); + addLast(); +} + +void +Mesher::mesh( void ) +{ + GridTrimVertex *gtlower, *gtupper; + + Hull::init( ); + nextupper( gtupper = new(p) GridTrimVertex ); + nextlower( gtlower = new(p) GridTrimVertex ); + + clearStack(); + openMesh(); + push(gtupper); + + nextupper( gtupper = new(p) GridTrimVertex ); + nextlower( gtlower ); + + assert( gtupper->t && gtlower->t ); + + if( gtupper->t->param[0] < gtlower->t->param[0] ) { + push(gtupper); + lastedge = 1; + if( nextupper( gtupper=new(p) GridTrimVertex ) == 0 ) { + finishLower(gtlower); + return; + } + } else if( gtupper->t->param[0] > gtlower->t->param[0] ) { + push(gtlower); + lastedge = 0; + if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) { + finishUpper(gtupper); + return; + } + } else { + if( lastedge == 0 ) { + push(gtupper); + lastedge = 1; + if( nextupper(gtupper=new(p) GridTrimVertex) == 0 ) { + finishLower(gtlower); + return; + } + } else { + push(gtlower); + lastedge = 0; + if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) { + finishUpper(gtupper); + return; + } + } + } + + while ( 1 ) { + if( gtupper->t->param[0] < gtlower->t->param[0] ) { + push(gtupper); + addUpper(); + if( nextupper( gtupper=new(p) GridTrimVertex ) == 0 ) { + finishLower(gtlower); + return; + } + } else if( gtupper->t->param[0] > gtlower->t->param[0] ) { + push(gtlower); + addLower(); + if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) { + finishUpper(gtupper); + return; + } + } else { + if( lastedge == 0 ) { + push(gtupper); + addUpper(); + if( nextupper( gtupper=new(p) GridTrimVertex ) == 0 ) { + finishLower(gtlower); + return; + } + } else { + push(gtlower); + addLower(); + if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) { + finishUpper(gtupper); + return; + } + } + } + } +} + +inline int +Mesher::isCcw( int ilast ) +{ + REAL area = det3( vdata[ilast]->t, vdata[itop-1]->t, vdata[itop-2]->t ); + return (area < ZERO) ? 0 : 1; +} + +inline int +Mesher::isCw( int ilast ) +{ + REAL area = det3( vdata[ilast]->t, vdata[itop-1]->t, vdata[itop-2]->t ); + return (area > -ZERO) ? 0 : 1; +} + +inline int +Mesher::equal( int x, int y ) +{ + return( last[0] == vdata[x] && last[1] == vdata[y] ); +} + +inline void +Mesher::copy( int x, int y ) +{ + last[0] = vdata[x]; last[1] = vdata[y]; +} + +inline void +Mesher::move( int x, int y ) +{ + vdata[x] = vdata[y]; +} + +inline void +Mesher::output( int x ) +{ + backend.tmeshvert( vdata[x] ); +} + +/*--------------------------------------------------------------------------- + * addedge - addedge an edge to the triangulation + * + * This code has been re-written to generate large triangle meshes + * from a monotone polygon. Although smaller triangle meshes + * could be generated faster and with less code, larger meshes + * actually give better SYSTEM performance. This is because + * vertices are processed in the backend slower than they are + * generated by this code and any decrease in the number of vertices + * results in a decrease in the time spent in the backend. + *--------------------------------------------------------------------------- + */ + +void +Mesher::addLast( ) +{ + register int ilast = itop; + + if( lastedge == 0 ) { + if( equal( 0, 1 ) ) { + output( ilast ); + swapMesh(); + for( register int i = 2; i < ilast; i++ ) { + swapMesh(); + output( i ); + } + copy( ilast, ilast-1 ); + } else if( equal( ilast-2, ilast-1) ) { + swapMesh(); + output( ilast ); + for( register int i = ilast-3; i >= 0; i-- ) { + output( i ); + swapMesh(); + } + copy( 0, ilast ); + } else { + closeMesh(); openMesh(); + output( ilast ); + output( 0 ); + for( register int i = 1; i < ilast; i++ ) { + swapMesh(); + output( i ); + } + copy( ilast, ilast-1 ); + } + } else { + if( equal( 1, 0) ) { + swapMesh(); + output( ilast ); + for( register int i = 2; i < ilast; i++ ) { + output( i ); + swapMesh(); + } + copy( ilast-1, ilast ); + } else if( equal( ilast-1, ilast-2) ) { + output( ilast ); + swapMesh(); + for( register int i = ilast-3; i >= 0; i-- ) { + swapMesh(); + output( i ); + } + copy( ilast, 0 ); + } else { + closeMesh(); openMesh(); + output( 0 ); + output( ilast ); + for( register int i = 1; i < ilast; i++ ) { + output( i ); + swapMesh(); + } + copy( ilast-1, ilast ); + } + } + closeMesh(); + //for( register long k=0; k<=ilast; k++ ) pop( k ); +} + +void +Mesher::addUpper( ) +{ + register int ilast = itop; + + if( lastedge == 0 ) { + if( equal( 0, 1 ) ) { + output( ilast ); + swapMesh(); + for( register int i = 2; i < ilast; i++ ) { + swapMesh(); + output( i ); + } + copy( ilast, ilast-1 ); + } else if( equal( ilast-2, ilast-1) ) { + swapMesh(); + output( ilast ); + for( register int i = ilast-3; i >= 0; i-- ) { + output( i ); + swapMesh(); + } + copy( 0, ilast ); + } else { + closeMesh(); openMesh(); + output( ilast ); + output( 0 ); + for( register int i = 1; i < ilast; i++ ) { + swapMesh(); + output( i ); + } + copy( ilast, ilast-1 ); + } + lastedge = 1; + //for( register long k=0; k 1) && isCcw( ilast ) ); + + if( equal( ilast-1, ilast-2 ) ) { + output( ilast ); + swapMesh(); + for( register int i=ilast-3; i>=itop-1; i-- ) { + swapMesh(); + output( i ); + } + copy( ilast, itop-1 ); + } else if( equal( itop, itop-1 ) ) { + swapMesh(); + output( ilast ); + for( register int i = itop+1; i < ilast; i++ ) { + output( i ); + swapMesh(); + } + copy( ilast-1, ilast ); + } else { + closeMesh(); openMesh(); + output( ilast ); + output( ilast-1 ); + for( register int i=ilast-2; i>=itop-1; i-- ) { + swapMesh(); + output( i ); + } + copy( ilast, itop-1 ); + } + //for( register int k=itop; k= 0; i-- ) { + swapMesh(); + output( i ); + } + copy( ilast, 0 ); + } else { + closeMesh(); openMesh(); + output( 0 ); + output( ilast ); + for( register int i = 1; i < ilast; i++ ) { + output( i ); + swapMesh(); + } + copy( ilast-1, ilast ); + } + + lastedge = 0; + //for( register long k=0; k 1) && isCw( ilast ) ); + + if( equal( ilast-2, ilast-1) ) { + swapMesh(); + output( ilast ); + for( register int i=ilast-3; i>=itop-1; i--) { + output( i ); + swapMesh( ); + } + copy( itop-1, ilast ); + } else if( equal( itop-1, itop) ) { + output( ilast ); + swapMesh(); + for( register int i=itop+1; i=itop-1; i-- ) { + output( i ); + swapMesh( ); + } + copy( itop-1, ilast ); + } + //for( register int k=itop; kbgntfan(); + + /* + trimVert.param[0]=v[0]; + trimVert.param[1]=v[1]; + backend->tmeshvert(&trimVert); + */ + backend->tmeshvert(v[0], v[1]); + + if(isIncreasing) { + for(i=0; itmeshvert(&trimVert); + */ + backend->tmeshvert(queue[i][0], queue[i][1]); + } + } + else { + for(i=index_queue-1; i>=0; i--) + { + /* + trimVert.param[0]=queue[i][0]; + trimVert.param[1]=queue[i][1]; + backend->tmeshvert(&trimVert); + */ + backend->tmeshvert(queue[i][0], queue[i][1]); + } + } + backend->endtfan(); +} + +void reflexChain::processNewVertex(Real v[2], Backend* backend) +{ + Int i,j,k; + Int isReflex; + /*TrimVertex trimVert;*/ + /*if there are at most one vertex in the queue, then simply insert + */ + if(index_queue <=1){ + insert(v); + return; + } + + /*there are at least two vertices in the queue*/ + j=index_queue-1; + + for(i=j; i>=1; i--) { + if(isIncreasing) { + isReflex = (area(queue[i-1], queue[i], v) <= 0.0); + } + else /*decreasing*/{ + isReflex = (area(v, queue[i], queue[i-1]) <= 0.0); + } + if(isReflex) { + break; + } + } + + /* + *if ibgntfan(); + /* + trimVert.param[0]=v[0]; + trimVert.param[1]=v[1]; + backend->tmeshvert(& trimVert); + */ + backend->tmeshvert(v[0], v[1]); + + if(isIncreasing) { + for(k=i; k<=j; k++) + { + /* + trimVert.param[0]=queue[k][0]; + trimVert.param[1]=queue[k][1]; + backend->tmeshvert(& trimVert); + */ + backend->tmeshvert(queue[k][0], queue[k][1]); + } + } + else { + for(k=j; k>=i; k--) + { + /* + trimVert.param[0]=queue[k][0]; + trimVert.param[1]=queue[k][1]; + backend->tmeshvert(& trimVert); + */ + backend->tmeshvert(queue[k][0], queue[k][1]); + } + } + + backend->endtfan(); + } + + /*delete vertices i+1--j from the queue*/ + index_queue = i+1; + /*finally insert v at the end of the queue*/ + insert(v); + +} + + +void monoTriangulationRec(Real* topVertex, Real* botVertex, + vertexArray* inc_chain, Int inc_current, + vertexArray* dec_chain, Int dec_current, + Backend* backend) +{ + assert( inc_chain != NULL && dec_chain != NULL); + assert( ! (inc_current>=inc_chain->getNumElements() && + dec_current>=dec_chain->getNumElements())); + Int inc_nVertices; + Int dec_nVertices; + Real** inc_array ; + Real** dec_array ; + Int i; + assert( ! ( (inc_chain==NULL) && (dec_chain==NULL))); + + if(inc_current>=inc_chain->getNumElements()) /*no more vertices on inc_chain*/ + { + + dec_array = dec_chain->getArray(); + dec_nVertices = dec_chain->getNumElements(); + reflexChain rChain(20,0); + /*put the top vertex into the reflex chain*/ + rChain.processNewVertex(topVertex, backend); + /*process all the vertices on the dec_chain*/ + for(i=dec_current; i= dec_chain->getNumElements()) /*no more vertices on dec_chain*/ + { + inc_array = inc_chain->getArray(); + inc_nVertices= inc_chain->getNumElements(); + reflexChain rChain(20,1); + /*put the top vertex into the reflex chain*/ + rChain.processNewVertex(topVertex, backend); + /*process all the vertices on the inc_chain*/ + for(i=inc_current; i getArray(); + dec_array = dec_chain -> getArray(); + inc_nVertices= inc_chain->getNumElements(); + dec_nVertices= dec_chain->getNumElements(); + /*if top of inc_chain is 'lower' than top of dec_chain, process all the + *vertices on the dec_chain which are higher than top of inc_chain + */ + if(compV2InY(inc_array[inc_current], dec_array[dec_current]) <= 0) + { + + reflexChain rChain(20, 0); + rChain.processNewVertex(topVertex, backend); + for(i=dec_current; i 0*/ + { + + reflexChain rChain(20, 1); + rChain.processNewVertex(topVertex, backend); + for(i=inc_current; i0) + rChain.processNewVertex(inc_array[i], backend); + else + break; + } + rChain.outputFan(dec_array[dec_current], backend); + monoTriangulationRec(inc_array[i-1], botVertex, + inc_chain, i, + dec_chain, dec_current, + backend); + } + }/*end case neither is empty*/ +} + + +void monoTriangulationFunBackend(Arc_ptr loop, Int (*compFun)(Real*, Real*), Backend* backend) +{ + Int i; + /*find the top vertex, bottom vertex, inccreasing chain, and decreasing chain, + *then call monoTriangulationRec + */ + Arc_ptr tempV; + Arc_ptr topV; + Arc_ptr botV; + topV = botV = loop; + for(tempV = loop->next; tempV != loop; tempV = tempV->next) + { + if(compFun(topV->tail(), tempV->tail())<0) { + topV = tempV; + } + if(compFun(botV->tail(), tempV->tail())>0) { + botV = tempV; + } + } + + /*creat increase and decrease chains*/ + vertexArray inc_chain(20); /*this is a dynamic array*/ + for(i=1; i<=topV->pwlArc->npts-2; i++) { /*the first vertex is the top vertex which doesn't belong to inc_chain*/ + inc_chain.appendVertex(topV->pwlArc->pts[i].param); + } + for(tempV = topV->next; tempV != botV; tempV = tempV->next) + { + for(i=0; i<=tempV->pwlArc->npts-2; i++){ + inc_chain.appendVertex(tempV->pwlArc->pts[i].param); + } + } + + vertexArray dec_chain(20); + for(tempV = topV->prev; tempV != botV; tempV = tempV->prev) + { + for(i=tempV->pwlArc->npts-2; i>=0; i--){ + dec_chain.appendVertex(tempV->pwlArc->pts[i].param); + } + } + for(i=botV->pwlArc->npts-2; i>=1; i--){ + dec_chain.appendVertex(tempV->pwlArc->pts[i].param); + } + + monoTriangulationRecFunBackend(topV->tail(), botV->tail(), &inc_chain, 0, &dec_chain, 0, compFun, backend); + +} + +/*if compFun == compV2InY, top to bottom: V-monotone + *if compFun == compV2InX, right to left: U-monotone + */ +void monoTriangulationRecFunBackend(Real* topVertex, Real* botVertex, + vertexArray* inc_chain, Int inc_current, + vertexArray* dec_chain, Int dec_current, + Int (*compFun)(Real*, Real*), + Backend* backend) +{ + assert( inc_chain != NULL && dec_chain != NULL); + assert( ! (inc_current>=inc_chain->getNumElements() && + dec_current>=dec_chain->getNumElements())); + Int inc_nVertices; + Int dec_nVertices; + Real** inc_array ; + Real** dec_array ; + Int i; + assert( ! ( (inc_chain==NULL) && (dec_chain==NULL))); + + if(inc_current>=inc_chain->getNumElements()) /*no more vertices on inc_chain*/ + { + + dec_array = dec_chain->getArray(); + dec_nVertices = dec_chain->getNumElements(); + reflexChain rChain(20,0); + /*put the top vertex into the reflex chain*/ + rChain.processNewVertex(topVertex, backend); + /*process all the vertices on the dec_chain*/ + for(i=dec_current; i= dec_chain->getNumElements()) /*no more vertices on dec_chain*/ + { + inc_array = inc_chain->getArray(); + inc_nVertices= inc_chain->getNumElements(); + reflexChain rChain(20,1); + /*put the top vertex into the reflex chain*/ + rChain.processNewVertex(topVertex, backend); + /*process all the vertices on the inc_chain*/ + for(i=inc_current; i getArray(); + dec_array = dec_chain -> getArray(); + inc_nVertices= inc_chain->getNumElements(); + dec_nVertices= dec_chain->getNumElements(); + /*if top of inc_chain is 'lower' than top of dec_chain, process all the + *vertices on the dec_chain which are higher than top of inc_chain + */ + if(compFun(inc_array[inc_current], dec_array[dec_current]) <= 0) + { + + reflexChain rChain(20, 0); + rChain.processNewVertex(topVertex, backend); + for(i=dec_current; i 0*/ + { + + reflexChain rChain(20, 1); + rChain.processNewVertex(topVertex, backend); + for(i=inc_current; i0) + rChain.processNewVertex(inc_array[i], backend); + else + break; + } + rChain.outputFan(dec_array[dec_current], backend); + monoTriangulationRecFunBackend(inc_array[i-1], botVertex, + inc_chain, i, + dec_chain, dec_current, + compFun, + backend); + } + }/*end case neither is empty*/ +} diff --git a/src/glu/sgi/libnurbs/internals/monotonizer.cc b/src/glu/sgi/libnurbs/internals/monotonizer.cc new file mode 100644 index 0000000..5845d31 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/monotonizer.cc @@ -0,0 +1,260 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * monotonizer.c++ + * + */ + +#include "glimports.h" +#include "mystdio.h" +#include "myassert.h" +#include "arc.h" +#include "arctess.h" +#include "bezierarc.h" +#include "bin.h" +#include "mapdesc.h" +#include "nurbsconsts.h" +#include "subdivider.h" + +/*----------------------------------------------------------------------------- + * Subdivider::decompose - break all curves into monotone arcs + *----------------------------------------------------------------------------- + */ +int +Subdivider::decompose( Bin& bin, REAL geo_stepsize ) +{ + Arc_ptr jarc; + for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) { + if( ! jarc->isTessellated() ) { + /* points have not been transformed, therefore they may be either + homogeneous or inhomogeneous */ + tessellate( jarc, geo_stepsize ); + if( jarc->isDisconnected() || jarc->next->isDisconnected() ) + return 1; + } + } + + for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) { + monotonize( jarc, bin ); + } + +#ifndef NDEBUG + for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) { + assert( isMonotone( jarc ) != 0 ); + } +#endif + + return 0; +} + +void +Subdivider::tessellate( Arc_ptr jarc, REAL geo_stepsize ) +{ + BezierArc *b = jarc->bezierArc; + Mapdesc *mapdesc = b->mapdesc; + + if( mapdesc->isRational() ) { + REAL max = mapdesc->calcVelocityRational( b->cpts, b->stride, b->order ); + REAL arc_stepsize = (max > 1.0) ? (1.0/max) : 1.0; + if( jarc->bezierArc->order != 2 ) + arctessellator.tessellateNonlinear( jarc, geo_stepsize, arc_stepsize, 1 ); + else { + arctessellator.tessellateLinear( jarc, geo_stepsize, arc_stepsize, 1 ); + } + } else { + REAL max = mapdesc->calcVelocityNonrational( b->cpts, b->stride, b->order ); + REAL arc_stepsize = (max > 1.0) ? (1.0/max) : 1.0; + if( jarc->bezierArc->order != 2 ) + arctessellator.tessellateNonlinear( jarc, geo_stepsize, arc_stepsize, 0 ); + else { + arctessellator.tessellateLinear( jarc, geo_stepsize, arc_stepsize, 0 ); + } + } +} + +/*------------------------------------------------------------------------- + * Subdivider::monotonize - break up a jordan arc into s,t-monotone + * components. This code will remove degenerate segments, including + * arcs of only a single point. + *------------------------------------------------------------------------- + */ +void +Subdivider::monotonize( Arc_ptr jarc, Bin& bin ) +{ + TrimVertex *firstvert = jarc->pwlArc->pts; + TrimVertex *lastvert = firstvert + (jarc->pwlArc->npts - 1); + long uid = jarc->nuid; + arc_side side = jarc->getside(); + dir sdir = none; + dir tdir = none; + int degenerate = 1; + + int nudegenerate; + int change; + + TrimVertex *vert; + for( vert = firstvert; vert != lastvert; vert++ ) { + + nudegenerate = 1; + change = 0; + + /* check change relative to s axis, clear degenerate bit if needed */ + REAL sdiff = vert[1].param[0] - vert[0].param[0]; + if( sdiff == 0 ) { + if( sdir != same ) { + sdir = same; + change = 1; + } + } else if( sdiff < 0.0 ) { + if( sdir != down ) { + sdir = down; + change = 1; + } + nudegenerate = 0; + } else { + if( sdir != up ) { + sdir = up; + change = 1; + } + nudegenerate = 0; + } + + /* check change relative to t axis, clear degenerate bit if needed */ + REAL tdiff = vert[1].param[1] - vert[0].param[1]; + if( tdiff == 0 ) { + if( tdir != same ) { + tdir = same; + change = 1; + } + } else if( tdiff < 0.0 ) { + if( tdir != down ) { + tdir = down; + change = 1; + } + nudegenerate = 0; + } else { + if( tdir != up ) { + tdir = up; + change = 1; + } + nudegenerate = 0; + } + + if( change ) { + if( ! degenerate ) { + /* make last segment into separate pwl curve */ + jarc->pwlArc->npts = vert - firstvert + 1; + jarc = (new(arcpool) Arc( side, uid ))->append( jarc ); + jarc->pwlArc = new(pwlarcpool) PwlArc(); + bin.addarc( jarc ); + } + firstvert = jarc->pwlArc->pts = vert; + degenerate = nudegenerate; + } + } + jarc->pwlArc->npts = vert - firstvert + 1; + + if( degenerate ) { + /* remove jarc from circularly linked list */ + jarc->prev->next = jarc->next; + jarc->next->prev = jarc->prev; + + assert( jarc->prev->check( ) != 0 ); + assert( jarc->next->check( ) != 0 ); + + /* remove jarc from bin */ + bin.remove_this_arc( jarc ); + + jarc->pwlArc->deleteMe( pwlarcpool ); jarc->pwlArc = 0; + jarc->deleteMe( arcpool ); + } +} + +/*------------------------------------------------------------------------- + * Subdivider::isMonotone - return true if arc is monotone AND non-degenerate + *------------------------------------------------------------------------- + */ +int +Subdivider::isMonotone( Arc_ptr jarc ) +{ + TrimVertex *firstvert = jarc->pwlArc->pts; + TrimVertex *lastvert = firstvert + (jarc->pwlArc->npts - 1); + + if( firstvert == lastvert ) return 1; + + TrimVertex *vert = firstvert; + enum dir sdir; + enum dir tdir; + + REAL diff = vert[1].param[0] - vert[0].param[0]; + if( diff == 0.0 ) + sdir = same; + else if( diff < 0.0 ) + sdir = down; + else + sdir = up; + + diff = vert[1].param[1] - vert[0].param[1]; + if( diff == 0.0 ) + tdir = same; + else if( diff < 0.0 ) + tdir = down; + else + tdir = up; + + if( (sdir == same) && (tdir == same) ) return 0; + + for( ++vert ; vert != lastvert; vert++ ) { + diff = vert[1].param[0] - vert[0].param[0]; + if( diff == 0.0 ) { + if( sdir != same ) return 0; + } else if( diff < 0.0 ) { + if( sdir != down ) return 0; + } else { + if( sdir != up ) return 0; + } + + diff = vert[1].param[1] - vert[0].param[1]; + if( diff == 0.0 ) { + if( tdir != same ) return 0; + } else if( diff < 0.0 ) { + if( tdir != down ) return 0; + } else { + if( tdir != up ) return 0; + } + } + return 1; +} + diff --git a/src/glu/sgi/libnurbs/internals/monotonizer.h b/src/glu/sgi/libnurbs/internals/monotonizer.h new file mode 100644 index 0000000..e951084 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/monotonizer.h @@ -0,0 +1,64 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * monotonizer.h + * + */ + +#ifndef __glumonotonizer_h_ +#define __glumonotonizer_h_ + +#include "mysetjmp.h" +#include "types.h" + +class Arc; +class ArcTessellator; +class Pool; +class Bin; +class PwlArcPool; +class Mapdesc; + +class Monotonizer { + ArcTessellator& arctessellator; + Pool& arcpool; + Pool& pwlarcpool; + jmp_buf& nurbsJmpBuf; + + enum dir { down, same, up, none }; + void tessellate( Arc *, REAL ); + void monotonize( Arc *, Bin & ); + int isMonotone( Arc * ); +public: + Monotonizer( ArcTessellator& at, Pool& ap, Pool& p, jmp_buf& j ) + : arctessellator(at), arcpool(ap), pwlarcpool(p), nurbsJmpBuf(j) {} + int decompose( Bin &, REAL ); +}; +#endif /* __glumonotonizer_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/myassert.h b/src/glu/sgi/libnurbs/internals/myassert.h new file mode 100644 index 0000000..cbd6006 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/myassert.h @@ -0,0 +1,51 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * myassert.h + * + */ + +#ifndef __glumyassert_h_ +#define __glumyassert_h_ + +#ifdef STANDALONE +#define assert(EX) ((void)0) +#endif + +#ifdef LIBRARYBUILD +#include +#endif + +#ifdef GLBUILD +#define assert(EX) ((void)0) +#endif + +#endif /* __glumyassert_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/mycode.cc b/src/glu/sgi/libnurbs/internals/mycode.cc new file mode 100644 index 0000000..3625cac --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/mycode.cc @@ -0,0 +1,67 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include "mymath.h" + +#ifdef NEEDCEILF + +float ceilf( float x ) +{ + if( x < 0 ) { + float nx = -x; + int ix = (int) nx; + return (float) -ix; + } else { + int ix = (int) x; + if( x == (float) ix ) return x; + return (float) (ix+1); + } +} + +float floorf( float x ) +{ + if( x < 0 ) { + float nx = -x; + int ix = (int) nx; + if( nx == (float) ix ) return x; + return (float) -(ix+1); + } else { + int ix = (int) x; + return (float) ix; + } +} +#endif diff --git a/src/glu/sgi/libnurbs/internals/mymath.h b/src/glu/sgi/libnurbs/internals/mymath.h new file mode 100644 index 0000000..17ef723 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/mymath.h @@ -0,0 +1,68 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * mymath.h + * + */ + +#ifndef __glumymath_h_ +#define __glumymath_h_ + +#ifdef GLBUILD +#define sqrtf gl_fsqrt +#endif + +#if defined(GLBUILD) || defined(STANDALONE) +#define M_SQRT2 1.41421356237309504880 +#define ceilf myceilf +#define floorf myfloorf +#define sqrtf sqrt +extern "C" double sqrt(double); +extern "C" float ceilf(float); +extern "C" float floorf(float); +#define NEEDCEILF +#endif + +#ifdef LIBRARYBUILD +#include +#endif + +#if !defined sqrtf +# define sqrtf(x) ((float)sqrt(x)) +#endif +#if !defined ceilf +# define ceilf(x) ((float)ceil(x)) +#endif +#if !defined floorf +# define floorf(x) ((float)floor(x)) +#endif + +#endif /* __glumymath_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/mysetjmp.h b/src/glu/sgi/libnurbs/internals/mysetjmp.h new file mode 100644 index 0000000..2a3f6a8 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/mysetjmp.h @@ -0,0 +1,85 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * mysetjmp.h + * + */ + +#ifndef __glumysetjmp_h_ +#define __glumysetjmp_h_ + +#ifdef STANDALONE +struct JumpBuffer; +extern "C" JumpBuffer *newJumpbuffer( void ); +extern "C" void deleteJumpbuffer(JumpBuffer *); +extern "C" void mylongjmp( JumpBuffer *, int ); +extern "C" int mysetjmp( JumpBuffer * ); +#endif + +#ifdef GLBUILD +#define setjmp gl_setjmp +#define longjmp gl_longjmp +#endif + +#if defined(LIBRARYBUILD) || defined(GLBUILD) +#include +#include + +struct JumpBuffer { + jmp_buf buf; +}; + +inline JumpBuffer * +newJumpbuffer( void ) +{ + return (JumpBuffer *) malloc( sizeof( JumpBuffer ) ); +} + +inline void +deleteJumpbuffer(JumpBuffer *jb) +{ + free( (void *) jb); +} + +inline void +mylongjmp( JumpBuffer *j, int code ) +{ + ::longjmp( j->buf, code ); +} + +inline int +mysetjmp( JumpBuffer *j ) +{ + return setjmp( j->buf ); +} +#endif + +#endif /* __glumysetjmp_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/mystring.h b/src/glu/sgi/libnurbs/internals/mystring.h new file mode 100644 index 0000000..d2952da --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/mystring.h @@ -0,0 +1,56 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * mystring.h + * + */ + +#ifndef __glumystring_h_ +#define __glumystring_h_ + +#ifdef STANDALONE +typedef unsigned int size_t; +extern "C" void * memcpy(void *, const void *, size_t); +extern "C" void * memset(void *, int, size_t); +#endif + +#ifdef GLBUILD +#define memcpy(a,b,c) bcopy(b,a,c) +#define memset(a,b,c) bzero(a,c) +extern "C" void bcopy(const void *, void *, int); +extern "C" void bzero(void *, int); +#endif + +#ifdef LIBRARYBUILD +#include +#endif + +#endif /* __glumystring_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/nurbsconsts.h b/src/glu/sgi/libnurbs/internals/nurbsconsts.h new file mode 100644 index 0000000..acc5d7f --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/nurbsconsts.h @@ -0,0 +1,120 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * nurbsconsts.h + * + */ + +#ifndef __glunurbsconsts_h_ +#define __glunurbsconsts_h_ + +/* NURBS Properties - one set per map, + each takes a single INREAL arg */ +#define N_SAMPLING_TOLERANCE 1 +#define N_S_RATE 6 +#define N_T_RATE 7 +#define N_CLAMPFACTOR 13 +#define N_NOCLAMPING 0.0 +#define N_MINSAVINGS 14 +#define N_NOSAVINGSSUBDIVISION 0.0 + +/* NURBS Properties - one set per map, + each takes an enumerated value */ +#define N_CULLING 2 +#define N_NOCULLING 0.0 +#define N_CULLINGON 1.0 +#define N_SAMPLINGMETHOD 10 +#define N_NOSAMPLING 0.0 +#define N_FIXEDRATE 3.0 +#define N_DOMAINDISTANCE 2.0 +#define N_PARAMETRICDISTANCE 5.0 +#define N_PATHLENGTH 6.0 +#define N_SURFACEAREA 7.0 +#define N_OBJECTSPACE_PARA 8.0 +#define N_OBJECTSPACE_PATH 9.0 +#define N_BBOX_SUBDIVIDING 17 +#define N_NOBBOXSUBDIVISION 0.0 +#define N_BBOXTIGHT 1.0 +#define N_BBOXROUND 2.0 + +/* NURBS Rendering Properties - one set per renderer + each takes an enumerated value */ +#define N_DISPLAY 3 +#define N_FILL 1.0 +#define N_OUTLINE_POLY 2.0 +#define N_OUTLINE_TRI 3.0 +#define N_OUTLINE_QUAD 4.0 +#define N_OUTLINE_PATCH 5.0 +#define N_OUTLINE_PARAM 6.0 +#define N_OUTLINE_PARAM_S 7.0 +#define N_OUTLINE_PARAM_ST 8.0 +#define N_OUTLINE_SUBDIV 9.0 +#define N_OUTLINE_SUBDIV_S 10.0 +#define N_OUTLINE_SUBDIV_ST 11.0 +#define N_ISOLINE_S 12.0 +#define N_ERRORCHECKING 4 +#define N_NOMSG 0.0 +#define N_MSG 1.0 + +/* GL 4.0 propeties not defined above */ +#ifndef N_PIXEL_TOLERANCE +#define N_PIXEL_TOLERANCE N_SAMPLING_TOLERANCE +#define N_ERROR_TOLERANCE 20 +#define N_SUBDIVISIONS 5 +#define N_TILES 8 +#define N_TMP1 9 +#define N_TMP2 N_SAMPLINGMETHOD +#define N_TMP3 11 +#define N_TMP4 12 +#define N_TMP5 N_CLAMPFACTOR +#define N_TMP6 N_MINSAVINGS +#define N_S_STEPS N_S_RATE +#define N_T_STEPS N_T_RATE +#endif + +/* NURBS Rendering Properties - one set per map, + each takes an INREAL matrix argument */ +#define N_CULLINGMATRIX 1 +#define N_SAMPLINGMATRIX 2 +#define N_BBOXMATRIX 3 + + +/* NURBS Rendering Properties - one set per map, + each takes an INREAL vector argument */ +#define N_BBOXSIZE 4 + +/* type argument for trimming curves */ +#ifndef N_P2D +#define N_P2D 0x8 +#define N_P2DR 0xd +#endif + +#endif /* __glunurbsconsts_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/nurbsinterfac.cc b/src/glu/sgi/libnurbs/internals/nurbsinterfac.cc new file mode 100644 index 0000000..520bd41 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/nurbsinterfac.cc @@ -0,0 +1,537 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * nurbsinterfac.c++ + * + */ + +#include "glimports.h" +#include "mystdio.h" +#include "nurbsconsts.h" +#include "nurbstess.h" +#include "bufpool.h" +#include "quilt.h" +#include "displaylist.h" +#include "knotvector.h" +#include "mapdesc.h" + +#define THREAD( work, arg, cleanup ) \ + if( dl ) {\ + arg->save = 1;\ + dl->append( (PFVS)&NurbsTessellator::work, (void *) arg, (PFVS)&NurbsTessellator::cleanup );\ + } else {\ + arg->save = 0;\ + work( arg );\ + } + +#define THREAD2( work ) \ + if( dl ) {\ + dl->append( (PFVS)&NurbsTessellator::work, 0, 0 );\ + } else {\ + work( );\ + } + +NurbsTessellator::NurbsTessellator( BasicCurveEvaluator &c, BasicSurfaceEvaluator& e) + : maplist( backend ), + backend( c, e ), + subdivider( renderhints, backend ), + o_pwlcurvePool( sizeof( O_pwlcurve ), 32, "o_pwlcurvePool" ), + o_nurbscurvePool( sizeof( O_nurbscurve ), 32, "o_nurbscurvePool"), + o_curvePool( sizeof( O_curve ), 32, "o_curvePool" ), + o_trimPool( sizeof( O_trim ), 32, "o_trimPool" ), + o_surfacePool( sizeof( O_surface ), 1, "o_surfacePool" ), + o_nurbssurfacePool( sizeof( O_nurbssurface ), 4, "o_nurbssurfacePool" ), + propertyPool( sizeof( Property ), 32, "propertyPool" ), + quiltPool( sizeof( Quilt ), 32, "quiltPool" ) +{ + dl = 0; + inSurface = 0; + inCurve = 0; + inTrim = 0; + playBack = 0; + jumpbuffer = newJumpbuffer(); + subdivider.setJumpbuffer( jumpbuffer ); +} + +NurbsTessellator::~NurbsTessellator( void ) +{ + if( inTrim ) { + do_nurbserror( 12 ); + endtrim(); + } + + if( inSurface ) { + *nextNurbssurface = 0; + do_freeall(); + } + + if (jumpbuffer) { + deleteJumpbuffer(jumpbuffer); + jumpbuffer= 0; + } +} + +/*----------------------------------------------------------------------------- + * bgnsurface - allocate and initialize an o_surface structure + * + * Client: GL user + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::bgnsurface( long nuid ) +{ + O_surface *o_surface = new(o_surfacePool) O_surface; + o_surface->nuid = nuid; + THREAD( do_bgnsurface, o_surface, do_freebgnsurface ); +} + +/*----------------------------------------------------------------------------- + * bgncurve - allocate an initialize an o_curve structure + * + * Client: GL user + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::bgncurve( long nuid ) +{ + O_curve *o_curve = new(o_curvePool) O_curve; + o_curve->nuid = nuid; + THREAD( do_bgncurve, o_curve, do_freebgncurve ); +} +/*----------------------------------------------------------------------------- + * endcurve - + * + * Client: + *----------------------------------------------------------------------------- + */ + +void +NurbsTessellator::endcurve( void ) +{ + THREAD2( do_endcurve ); +} + +/*----------------------------------------------------------------------------- + * endsurface - user level end of surface call + * + * Client: GL user + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::endsurface( void ) +{ + THREAD2( do_endsurface ); +} + + +/*----------------------------------------------------------------------------- + * bgntrim - allocate and initialize a new trim loop structure (o_trim ) + * + * Client: GL user + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::bgntrim( void ) +{ + O_trim *o_trim = new(o_trimPool) O_trim; + THREAD( do_bgntrim, o_trim, do_freebgntrim ); +} + +/*----------------------------------------------------------------------------- + * endtrim - + * + * Client: GL user + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::endtrim( void ) +{ + THREAD2( do_endtrim ); +} + + +/*----------------------------------------------------------------------------- + * pwlcurve - + * + * count - number of points on curve + * array - array of points on curve + * byte_stride - distance between points in bytes + * type - valid data flag + * + * Client: Gl user + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::pwlcurve( long count, INREAL array[], long byte_stride, long type ) +{ + Mapdesc *mapdesc = maplist.locate( type ); + + if( mapdesc == 0 ) { + do_nurbserror( 35 ); + isDataValid = 0; + return; + } + + if ( (type != N_P2D) && (type != N_P2DR) ) { + do_nurbserror( 22 ); + isDataValid = 0; + return; + } + if( count < 0 ) { + do_nurbserror( 33 ); + isDataValid = 0; + return; + } + if( byte_stride < 0 ) { + do_nurbserror( 34 ); + isDataValid = 0; + return; + } + +#ifdef NOTDEF + if( mapdesc->isRational() ) { + INREAL *p = array; + INREAL x = p[0]; INREAL y = p[1]; INREAL w = p[2]; + p = (INREAL *) (((char *) p) + byte_stride); + for( long i = 1; i != count; i++ ) { + if( p[0] == x && p[1] == y && p[2] == w ) break; + x = p[0]; y = p[1]; w = p[2]; + p = (INREAL *) (((char *) p) + byte_stride); + } + if( i != count ) { + do_nurbserror( 37 ); + _glu_dprintf( "point %d (%f,%f)\n", i, x, y ); + isDataValid = 0; + return; + } + } else { + INREAL *p = array; + INREAL x = p[0]; INREAL y = p[1]; + p = (INREAL *) (((char *) p) + byte_stride); + for( long i = 1; i != count; i++ ) { + if( p[0] == x && p[1] == y ) break; + x = p[0]; y = p[1]; + p = (INREAL *) (((char *) p) + byte_stride); + } + if( i != count ) { + do_nurbserror( 37 ); + _glu_dprintf( "point %d (%f,%f)\n", i, x, y ); + isDataValid = 0; + return; + } + } +#endif + + O_pwlcurve *o_pwlcurve = new(o_pwlcurvePool) O_pwlcurve( type, count, array, byte_stride, extTrimVertexPool.get((int)count) ); + THREAD( do_pwlcurve, o_pwlcurve, do_freepwlcurve ); +} + + +/*----------------------------------------------------------------------------- + * nurbscurve - + * + * Client: GL user + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::nurbscurve( + long nknots, /* number of p knots */ + INREAL knot[], /* nondecreasing knot values in p */ + long byte_stride, /* distance in bytes between control points */ + INREAL ctlarray[], /* pointer to first control point */ + long order, /* order of spline */ + long type ) /* description of range space */ +{ + + Mapdesc *mapdesc = maplist.locate( type ); + + if( mapdesc == 0 ) { + do_nurbserror( 35 ); + isDataValid = 0; + return; + } + + if( ctlarray == 0 ) { + do_nurbserror( 36 ); + isDataValid = 0; + return; + } + + if( byte_stride < 0 ) { + do_nurbserror( 34 ); + isDataValid = 0; + return; + } + + Knotvector knots; + + knots.init( nknots, byte_stride, order, knot ); + if( do_check_knots( &knots, "curve" ) ) return; + + O_nurbscurve *o_nurbscurve = new(o_nurbscurvePool) O_nurbscurve(type); + o_nurbscurve->bezier_curves = new(quiltPool) Quilt(mapdesc); + o_nurbscurve->bezier_curves->toBezier( knots,ctlarray, mapdesc->getNcoords() ); + + THREAD( do_nurbscurve, o_nurbscurve, do_freenurbscurve ); +} + + +/*----------------------------------------------------------------------------- + * nurbssurface - + * + * Client: User routine + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::nurbssurface( + long sknot_count, /* number of s knots */ + INREAL sknot[], /* nondecreasing knot values in s */ + long tknot_count, /* number of t knots */ + INREAL tknot[], /* nondecreasing knot values in t */ + long s_byte_stride, /* s step size in memory bytes */ + long t_byte_stride, /* t step size in memory bytes */ + INREAL ctlarray[], /* pointer to first control point */ + long sorder, /* order of the spline in s parameter */ + long torder, /* order of the spline in t parameter */ + long type) /* description of range space */ +{ + Mapdesc *mapdesc = maplist.locate( type ); + + if( mapdesc == 0 ) { + do_nurbserror( 35 ); + isDataValid = 0; + return; + } + + if( s_byte_stride < 0 ) { + do_nurbserror( 34 ); + isDataValid = 0; + return; + } + + if( t_byte_stride < 0 ) { + do_nurbserror( 34 ); + isDataValid = 0; + return; + } + + Knotvector sknotvector, tknotvector; + + sknotvector.init( sknot_count, s_byte_stride, sorder, sknot ); + if( do_check_knots( &sknotvector, "surface" ) ) return; + + tknotvector.init( tknot_count, t_byte_stride, torder, tknot ); + if( do_check_knots( &tknotvector, "surface" ) ) return; + + O_nurbssurface *o_nurbssurface = new(o_nurbssurfacePool) O_nurbssurface(type); + o_nurbssurface->bezier_patches = new(quiltPool) Quilt(mapdesc); + + o_nurbssurface->bezier_patches->toBezier( sknotvector, tknotvector, + ctlarray, mapdesc->getNcoords() ); + THREAD( do_nurbssurface, o_nurbssurface, do_freenurbssurface ); +} + + +/*----------------------------------------------------------------------------- + * setnurbsproperty - + * + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::setnurbsproperty( long tag, INREAL value ) +{ + if( ! renderhints.isProperty( tag ) ) { + do_nurbserror( 26 ); + } else { + Property *prop = new(propertyPool) Property( tag, value ); + THREAD( do_setnurbsproperty, prop, do_freenurbsproperty ); + } +} + +/*----------------------------------------------------------------------------- + * setnurbsproperty - + * + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::setnurbsproperty( long type, long tag, INREAL value ) +{ + Mapdesc *mapdesc = maplist.locate( type ); + + if( mapdesc == 0 ) { + do_nurbserror( 35 ); + return; + } + + if( ! mapdesc->isProperty( tag ) ) { + do_nurbserror( 26 ); + return; + } + + Property *prop = new(propertyPool) Property( type, tag, value ); + THREAD( do_setnurbsproperty2, prop, do_freenurbsproperty ); +} + + +/*----------------------------------------------------------------------------- + * getnurbsproperty - + * + *----------------------------------------------------------------------------- + */ + +void +NurbsTessellator::getnurbsproperty( long tag, INREAL *value ) +{ + if( renderhints.isProperty( tag ) ) { + *value = renderhints.getProperty( tag ); + } else { + do_nurbserror( 26 ); + } +} + +/*----------------------------------------------------------------------------- + * getnurbsproperty - + * + *----------------------------------------------------------------------------- + */ + +void +NurbsTessellator::getnurbsproperty( long type, long tag, INREAL *value ) +{ + Mapdesc *mapdesc = maplist.locate( type ); + + if( mapdesc == 0 ) + do_nurbserror( 35 ); + + if( mapdesc->isProperty( tag ) ) { + *value = mapdesc->getProperty( tag ); + } else { + do_nurbserror( 26 ); + } +} + +/*-------------------------------------------------------------------------- + * setnurbsproperty - accept a user supplied matrix as culling or sampling mat + *-------------------------------------------------------------------------- + */ + +void +NurbsTessellator::setnurbsproperty( long type, long purpose, INREAL *mat ) +{ + // XXX - cannot be put in display list + Mapdesc *mapdesc = maplist.locate( type ); + + if( mapdesc == 0 ) { + do_nurbserror( 35 ); + isDataValid = 0; + } else if( purpose == N_BBOXSIZE ) { + mapdesc->setBboxsize( mat ); + } else { +#ifndef NDEBUG + _glu_dprintf( "ERRORRORRORR!!!\n"); +#endif + } +} + +/*-------------------------------------------------------------------------- + * setnurbsproperty - accept a user supplied matrix as culling or sampling mat + *-------------------------------------------------------------------------- + */ + +void +NurbsTessellator::setnurbsproperty( long type, long purpose, INREAL *mat, + long rstride, long cstride ) +{ + // XXX - cannot be put in display list + Mapdesc *mapdesc = maplist.locate( type ); + + if( mapdesc == 0 ) { + do_nurbserror( 35 ); + isDataValid = 0; + } else if( purpose == N_CULLINGMATRIX ) { + mapdesc->setCmat( mat, rstride, cstride ); + } else if( purpose == N_SAMPLINGMATRIX ) { + mapdesc->setSmat( mat, rstride, cstride ); + } else if( purpose == N_BBOXMATRIX ) { + mapdesc->setBmat( mat, rstride, cstride ); + } else { +#ifndef NDEBUG + _glu_dprintf( "ERRORRORRORR!!!\n"); +#endif + } +} + +void +NurbsTessellator::redefineMaps( void ) +{ + maplist.initialize(); +} + +void +NurbsTessellator::defineMap( long type, long rational, long ncoords ) +{ + maplist.define( type, (int) rational, (int) ncoords ); +} + +void +NurbsTessellator::discardRecording( void *_dl ) +{ + delete (DisplayList *) _dl; +} + +void * +NurbsTessellator::beginRecording( void ) +{ + dl = new DisplayList( this ); + return (void *) dl; +} + +void +NurbsTessellator::endRecording( void ) +{ + dl->endList(); + dl = 0; +} + +void +NurbsTessellator::playRecording( void *_dl ) +{ + playBack = 1; + bgnrender(); + ((DisplayList *)_dl)->play(); + endrender(); + playBack = 0; +} + diff --git a/src/glu/sgi/libnurbs/internals/nurbstess.cc b/src/glu/sgi/libnurbs/internals/nurbstess.cc new file mode 100644 index 0000000..68dfd95 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/nurbstess.cc @@ -0,0 +1,691 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * nurbstess.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mysetjmp.h" +#include "mystdio.h" +#include "nurbsconsts.h" +#include "nurbstess.h" +#include "bufpool.h" +#include "quilt.h" +#include "knotvector.h" +#include "mapdesc.h" +#include "maplist.h" + +void +NurbsTessellator::set_domain_distance_u_rate(REAL u_rate) +{ + subdivider.set_domain_distance_u_rate(u_rate); +} + +void +NurbsTessellator::set_domain_distance_v_rate(REAL v_rate) +{ + subdivider.set_domain_distance_v_rate(v_rate); +} + +void +NurbsTessellator::set_is_domain_distance_sampling(int flag) +{ + subdivider.set_is_domain_distance_sampling(flag); +} + +void +NurbsTessellator::resetObjects( void ) +{ + subdivider.clear(); +} + +void +NurbsTessellator::makeobj( int ) +{ +#ifndef NDEBUG + _glu_dprintf( "makeobj\n" ); +#endif +} + +void +NurbsTessellator::closeobj( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "closeobj\n" ); +#endif +} + +void +NurbsTessellator::bgnrender( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "bgnrender\n" ); +#endif +} + +void +NurbsTessellator::endrender( void ) +{ +#ifndef NDEBUG + _glu_dprintf( "endrender\n" ); +#endif +} + +/*----------------------------------------------------------------------------- + * do_freebgnsurface - free o_surface structure + * + * Client: do_freeall(), bgnsurface() + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::do_freebgnsurface( O_surface *o_surface ) +{ + o_surface->deleteMe( o_surfacePool ); +} + + +/*----------------------------------------------------------------------------- + * do_bgnsurface - begin the display of a surface + * + * Client: bgnsurface() + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::do_bgnsurface( O_surface *o_surface ) +{ + if( inSurface ) { + do_nurbserror( 27 ); + endsurface(); + } + inSurface = 1; + + if( ! playBack ) bgnrender(); + + isTrimModified = 0; + isSurfaceModified = 0; + isDataValid = 1; + numTrims = 0; + currentSurface = o_surface; + nextTrim = &( currentSurface->o_trim ); + nextNurbssurface = &( currentSurface->o_nurbssurface ); +} + +/*----------------------------------------------------------------------------- + * do_bgncurve - begin the display of a curve + * + * Client: bgncurve() + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::do_bgncurve( O_curve *o_curve ) +{ + if ( inCurve ) { + do_nurbserror( 6 ); + endcurve(); + } + + inCurve = 1; + currentCurve = o_curve; + currentCurve->curvetype = ct_none; + + if( inTrim ) { + if( *nextCurve != o_curve ) { + isCurveModified = 1; + *nextCurve = o_curve; + } + } else { + if( ! playBack ) bgnrender(); + isDataValid = 1; + } + nextCurve = &(o_curve->next); + nextPwlcurve = &(o_curve->curve.o_pwlcurve); + nextNurbscurve = &(o_curve->curve.o_nurbscurve); +} + +/*----------------------------------------------------------------------------- + * do_endcurve - + * + * Client: endcurve() + *----------------------------------------------------------------------------- + */ + +void +NurbsTessellator::do_endcurve( void ) +{ + if( ! inCurve ) { + do_nurbserror( 7 ); + return; + } + inCurve = 0; + + *nextCurve = 0; + if (currentCurve->curvetype == ct_nurbscurve) + *nextNurbscurve = 0; + else + *nextPwlcurve = 0; + + if ( ! inTrim ) { + if( ! isDataValid ) { + do_freecurveall( currentCurve ); + return; + } + + int errval; + errval = ::mysetjmp( jumpbuffer ); + if( errval == 0 ) { + if( currentCurve->curvetype == ct_nurbscurve ) { + subdivider.beginQuilts(); + for( O_nurbscurve *n = currentCurve->curve.o_nurbscurve; n != 0; n = n->next ) + subdivider.addQuilt( n->bezier_curves ); + subdivider.endQuilts(); + subdivider.drawCurves(); + if( ! playBack ) endrender(); + } else { + /* XXX */ + if( ! playBack ) endrender(); + /*do_draw_pwlcurve( currentCurve->curve.o_pwlcurve ) */; + do_nurbserror( 9 ); + } + } else { + if( ! playBack ) endrender(); + do_nurbserror( errval ); + } + do_freecurveall( currentCurve ); + resetObjects(); + } +} + +/*----------------------------------------------------------------------------- + * do_endsurface - mark end of surface, display surface, free immediate data + * + * Client: + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::do_endsurface( void ) +{ + if( inTrim ) { + do_nurbserror( 12 ); + endtrim(); + } + + if( ! inSurface ) { + do_nurbserror( 13 ); + return; + } + inSurface = 0; + + *nextNurbssurface = 0; + + if( ! isDataValid ) { + do_freeall( ); + return; + } + + if( *nextTrim != 0 ) { + isTrimModified = 1; + *nextTrim = 0; + } + + int errval; + + errval = ::mysetjmp( jumpbuffer ); + if( errval == 0 ) { + if( numTrims > 0 ) { + + subdivider.beginTrims(); + for( O_trim *trim = currentSurface->o_trim; trim; trim = trim->next ) { + subdivider.beginLoop(); + for( O_curve *curve = trim->o_curve; curve; curve = curve->next ) { + curve->used = 0; + assert( curve->curvetype != ct_none ); + if (curve->curvetype == ct_pwlcurve) { + O_pwlcurve *c = curve->curve.o_pwlcurve; + subdivider.addArc( c->npts, c->pts, curve->nuid ); + } else { + Quilt *quilt = curve->curve.o_nurbscurve->bezier_curves; + Quiltspec *qspec = quilt->qspec; + REAL *cpts = quilt->cpts + qspec->offset; + REAL *cptsend = cpts + (qspec->width * qspec->order * qspec->stride); + for( ; cpts != cptsend; cpts += qspec->order*qspec->stride ) + subdivider.addArc( cpts, quilt, curve->nuid ); + } + } + subdivider.endLoop(); + } + subdivider.endTrims(); + } + + subdivider.beginQuilts(); + for( O_nurbssurface *n = currentSurface->o_nurbssurface; n; n = n->next ) + subdivider.addQuilt( n->bezier_patches ); + subdivider.endQuilts(); + subdivider.drawSurfaces( currentSurface->nuid ); + if( ! playBack ) endrender(); + } else { + if( ! playBack ) endrender(); + do_nurbserror( errval ); + } + + do_freeall( ); + resetObjects(); +} + +/*----------------------------------------------------------------------------- + * do_freeall - free all data allocated in immediate mode + * + * Client: + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::do_freeall( void ) +{ + for( O_trim *o_trim = currentSurface->o_trim; o_trim; ) { + O_trim *next_o_trim = o_trim->next; + for( O_curve *curve = o_trim->o_curve; curve; ) { + O_curve *next_o_curve = curve->next; + do_freecurveall( curve ); + curve = next_o_curve; + } + if( o_trim->save == 0 ) do_freebgntrim( o_trim ); + o_trim = next_o_trim; + } + + O_nurbssurface *nurbss, *next_nurbss; + for( nurbss= currentSurface->o_nurbssurface; nurbss; nurbss = next_nurbss) { + next_nurbss = nurbss->next; + if( nurbss->save == 0 ) + do_freenurbssurface( nurbss ); + else + nurbss->used = 0; + } + + if( currentSurface->save == 0 ) do_freebgnsurface( currentSurface ); +} + +void +NurbsTessellator::do_freecurveall( O_curve *curve ) +{ + assert( curve->curvetype != ct_none ); + + if( curve->curvetype == ct_nurbscurve ) { + O_nurbscurve *ncurve, *next_ncurve; + for( ncurve=curve->curve.o_nurbscurve; ncurve; ncurve=next_ncurve ) { + next_ncurve = ncurve->next; + if( ncurve->save == 0 ) + do_freenurbscurve( ncurve ); + else + ncurve->used = 0; + } + } else { + O_pwlcurve *pcurve, *next_pcurve; + for( pcurve=curve->curve.o_pwlcurve; pcurve; pcurve=next_pcurve ) { + next_pcurve = pcurve->next; + if( pcurve->save == 0 ) + do_freepwlcurve( pcurve ); + else + pcurve->used = 0; + } + } + if( curve->save == 0 ) + do_freebgncurve( curve ); +} + + +/*----------------------------------------------------------------------------- + * do_freebgntrim - free the space allocated for a trim loop + * + * Client: + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::do_freebgntrim( O_trim *o_trim ) +{ + o_trim->deleteMe( o_trimPool ); +} + + +/*----------------------------------------------------------------------------- + * do_bgntrim - link in a trim loop to the current trimmed surface description + * + * Client: bgntrim() + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::do_bgntrim( O_trim *o_trim ) +{ + + if( ! inSurface ) { + do_nurbserror( 15 ); + bgnsurface( 0 ); + inSurface = 2; + } + + if( inTrim ) { + do_nurbserror( 16 ); + endtrim(); + } + inTrim = 1; + + if( *nextTrim != o_trim ) { + isTrimModified = 1; + *nextTrim = o_trim; + } + + currentTrim = o_trim; + nextTrim = &(o_trim->next); + nextCurve = &(o_trim->o_curve); +} + + +/*----------------------------------------------------------------------------- + * do_endtrim - mark the end of the current trim loop + * + * Client: endtrim() + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::do_endtrim( void ) +{ + if( ! inTrim ) { + do_nurbserror( 17 ); + return; + } + inTrim = 0; + + if( currentTrim->o_curve == 0 ) { + do_nurbserror( 18 ); + isDataValid = 0; + } + + numTrims++; + + if( *nextCurve != 0 ) { + isTrimModified = 1; + *nextCurve = 0; + } +} + +/*----------------------------------------------------------------------------- + * do_freepwlcurve - + * + * Client: + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::do_freepwlcurve( O_pwlcurve *o_pwlcurve ) +{ + o_pwlcurve->deleteMe( o_pwlcurvePool ); +} + +void +NurbsTessellator::do_freebgncurve( O_curve *o_curve ) +{ + o_curve->deleteMe( o_curvePool ); +} + +/*----------------------------------------------------------------------------- + * do_pwlcurve - link in pwl trim loop to the current surface description + * + * Client: pwlcurve() + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::do_pwlcurve( O_pwlcurve *o_pwlcurve ) +{ + if( ! inTrim ) { + do_nurbserror( 19 ); + if( o_pwlcurve->save == 0 ) + do_freepwlcurve(o_pwlcurve ); + return; + } + + if( ! inCurve ) { + bgncurve( 0 ); + inCurve = 2; + } + + if( o_pwlcurve->used ) { + do_nurbserror( 20 ); + isDataValid = 0; + return; + } else + o_pwlcurve->used = 1; + + if( currentCurve->curvetype == ct_none ) { + currentCurve->curvetype = ct_pwlcurve; + } else if( currentCurve->curvetype != ct_pwlcurve ) { + do_nurbserror( 21 ); + isDataValid = 0; + return; + } + + if( *nextPwlcurve != o_pwlcurve ) { + isCurveModified = 1; + *nextPwlcurve = o_pwlcurve; + } + nextPwlcurve = &(o_pwlcurve->next); + + if( o_pwlcurve->owner != currentCurve ) { + isCurveModified = 1; + o_pwlcurve->owner = currentCurve; + } + + if( (inCurve == 2) ) + endcurve(); +} + + +/*----------------------------------------------------------------------------- + * do_freenurbscurve - + * + * Client: + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::do_freenurbscurve( O_nurbscurve *o_nurbscurve ) +{ + o_nurbscurve->bezier_curves->deleteMe( quiltPool ); + o_nurbscurve->deleteMe( o_nurbscurvePool ); +} + + +/*----------------------------------------------------------------------------- + * do_nurbscurve - + * + * Client: nurbscurve() + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::do_nurbscurve( O_nurbscurve *o_nurbscurve ) +{ + if ( ! inCurve ) { + bgncurve( 0 ); + inCurve = 2; + } + + if( o_nurbscurve->used ) { + /* error - curve was already called in current surface */ + do_nurbserror( 23 ); + isDataValid = 0; + return; + } else + o_nurbscurve->used = 1; + + if( currentCurve->curvetype == ct_none ) { + currentCurve->curvetype = ct_nurbscurve; + } else if( currentCurve->curvetype != ct_nurbscurve ) { + do_nurbserror( 24 ); + isDataValid = 0; + return; + } + + if( *nextNurbscurve != o_nurbscurve ) { + isCurveModified = 1; + *nextNurbscurve = o_nurbscurve; + } + + nextNurbscurve = &(o_nurbscurve->next); + + if( o_nurbscurve->owner != currentCurve ) { + isCurveModified = 1; + o_nurbscurve->owner = currentCurve; + } + + if( o_nurbscurve->owner == 0 ) + isCurveModified = 1; + + if( inCurve == 2 ) + endcurve(); +} + + +/*----------------------------------------------------------------------------- + * do_freenurbssurface - + * + * Client: + *----------------------------------------------------------------------------- + */ + +void +NurbsTessellator::do_freenurbssurface( O_nurbssurface *o_nurbssurface ) +{ + o_nurbssurface->bezier_patches->deleteMe( quiltPool ); + o_nurbssurface->deleteMe( o_nurbssurfacePool ); +} + +/*----------------------------------------------------------------------------- + * do_nurbssurface - + * + * Client: nurbssurface() + *----------------------------------------------------------------------------- + */ +void +NurbsTessellator::do_nurbssurface( O_nurbssurface *o_nurbssurface ) +{ + if( ! inSurface ) { + bgnsurface( 0 ); + inSurface = 2; + } + + if( o_nurbssurface->used ) { + /* error - surface was already called in current block */ + do_nurbserror( 25 ); + isDataValid = 0; + return; + } else + o_nurbssurface->used = 1; + + if( *nextNurbssurface != o_nurbssurface ) { + isSurfaceModified = 1; + *nextNurbssurface = o_nurbssurface; + } + + if( o_nurbssurface->owner != currentSurface ) { + isSurfaceModified = 1; + o_nurbssurface->owner = currentSurface; + } + nextNurbssurface = &(o_nurbssurface->next); + + if( inSurface == 2 ) + endsurface(); +} + + +/*----------------------------------------------------------------------------- + * do_freenurbsproperty + * + *----------------------------------------------------------------------------- + */ + +void +NurbsTessellator::do_freenurbsproperty( Property *prop ) +{ + prop->deleteMe( propertyPool ); +} + + +/*----------------------------------------------------------------------------- + * do_setnurbsproperty - + * + *----------------------------------------------------------------------------- + */ + +void +NurbsTessellator::do_setnurbsproperty( Property *prop ) +{ + renderhints.setProperty( prop->tag, prop->value ); + if( prop->save == 0 ) + do_freenurbsproperty( prop ); +} + +void +NurbsTessellator::do_setnurbsproperty2( Property *prop ) +{ + Mapdesc *mapdesc = maplist.find( prop->type ); + + mapdesc->setProperty( prop->tag, prop->value ); + if( prop->save == 0 ) + do_freenurbsproperty( prop ); +} + +void +NurbsTessellator::errorHandler( int ) +{ +} + +void +NurbsTessellator::do_nurbserror( int msg ) +{ + errorHandler( msg ); +} + +int +NurbsTessellator::do_check_knots( Knotvector *knots, const char *msg ) +{ + int status = knots->validate(); + if( status ) { + do_nurbserror( status ); + if( renderhints.errorchecking != N_NOMSG ) knots->show( msg ); + } + return status; +} + + + + + diff --git a/src/glu/sgi/libnurbs/internals/nurbstess.h b/src/glu/sgi/libnurbs/internals/nurbstess.h new file mode 100644 index 0000000..a686900 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/nurbstess.h @@ -0,0 +1,172 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * nurbstess.h + * + */ + +#ifndef __glunurbstess_h_ +#define __glunurbstess_h_ + +#include "mysetjmp.h" +#include "subdivider.h" +#include "renderhints.h" +#include "backend.h" +#include "maplist.h" +#include "reader.h" +#include "nurbsconsts.h" + +struct Knotvector; +class Quilt; +class DisplayList; +class BasicCurveEvaluator; +class BasicSurfaceEvaluator; + +class NurbsTessellator { +public: + NurbsTessellator( BasicCurveEvaluator &c, + BasicSurfaceEvaluator &e ); + virtual ~NurbsTessellator( void ); + + void getnurbsproperty( long, INREAL * ); + void getnurbsproperty( long, long, INREAL * ); + void setnurbsproperty( long, INREAL ); + void setnurbsproperty( long, long, INREAL ); + void setnurbsproperty( long, long, INREAL * ); + void setnurbsproperty( long, long, INREAL *, long, long ); + + // called before a tessellation begins/ends + virtual void bgnrender( void ); + virtual void endrender( void ); + + // called to make a display list of the output vertices + virtual void makeobj( int n ); + virtual void closeobj( void ); + + // called when a error occurs + virtual void errorHandler( int ); + + void bgnsurface( long ); + void endsurface( void ); + void bgntrim( void ); + void endtrim( void ); + void bgncurve( long ); + void endcurve( void ); + void pwlcurve( long, INREAL[], long, long ); + void nurbscurve( long, INREAL[], long, INREAL[], long, long ); + void nurbssurface( long, INREAL[], long, INREAL[], long, long, + INREAL[], long, long, long ); + + void defineMap( long, long, long ); + void redefineMaps( void ); + + // recording of input description + void discardRecording( void * ); + void * beginRecording( void ); + void endRecording( void ); + void playRecording( void * ); + + //for optimizing untrimmed nurbs in the case of domain distance sampling + void set_domain_distance_u_rate(REAL u_rate); + void set_domain_distance_v_rate(REAL v_rate); + void set_is_domain_distance_sampling(int flag); + + +protected: + Renderhints renderhints; + Maplist maplist; + Backend backend; + +private: + + void resetObjects( void ); + int do_check_knots( Knotvector *, const char * ); + void do_nurbserror( int ); + void do_bgncurve( O_curve * ); + void do_endcurve( void ); + void do_freeall( void ); + void do_freecurveall( O_curve * ); + void do_freebgntrim( O_trim * ); + void do_freebgncurve( O_curve * ); + void do_freepwlcurve( O_pwlcurve * ); + void do_freenurbscurve( O_nurbscurve * ); + void do_freenurbssurface( O_nurbssurface * ); + void do_freebgnsurface( O_surface * ); + void do_bgnsurface( O_surface * ); + void do_endsurface( void ); + void do_bgntrim( O_trim * ); + void do_endtrim( void ); + void do_pwlcurve( O_pwlcurve * ); + void do_nurbscurve( O_nurbscurve * ); + void do_nurbssurface( O_nurbssurface * ); + void do_freenurbsproperty( Property * ); + void do_setnurbsproperty( Property * ); + void do_setnurbsproperty2( Property * ); + + Subdivider subdivider; + JumpBuffer* jumpbuffer; + Pool o_pwlcurvePool; + Pool o_nurbscurvePool; + Pool o_curvePool; + Pool o_trimPool; + Pool o_surfacePool; + Pool o_nurbssurfacePool; + Pool propertyPool; +public: + Pool quiltPool; +private: + TrimVertexPool extTrimVertexPool; + + int inSurface; /* bgnsurface seen */ + int inCurve; /* bgncurve seen */ + int inTrim; /* bgntrim seen */ + int isCurveModified; /* curve changed */ + int isTrimModified; /* trim curves changed */ + int isSurfaceModified; /* surface changed */ + int isDataValid; /* all data is good */ + int numTrims; /* valid trim regions */ + int playBack; + + O_trim** nextTrim; /* place to link o_trim */ + O_curve** nextCurve; /* place to link o_curve */ + O_nurbscurve** nextNurbscurve; /* place to link o_nurbscurve */ + O_pwlcurve** nextPwlcurve; /* place to link o_pwlcurve */ + O_nurbssurface** nextNurbssurface; /* place to link o_nurbssurface */ + + O_surface* currentSurface; + O_trim* currentTrim; + O_curve* currentCurve; + + DisplayList *dl; + +}; + +#endif /* __glunurbstess_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/patch.cc b/src/glu/sgi/libnurbs/internals/patch.cc new file mode 100644 index 0000000..808baa6 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/patch.cc @@ -0,0 +1,504 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * patch.c++ + * + */ + +#include +#include "glimports.h" +#include "mystdio.h" +#include "myassert.h" +#include "mymath.h" +#include "mystring.h" +#include "patch.h" +#include "mapdesc.h" +#include "quilt.h" +#include "nurbsconsts.h" +#include "simplemath.h" //for glu_abs function in ::singleStep(); + + +/*-------------------------------------------------------------------------- + * Patch - copy patch from quilt and transform control points + *-------------------------------------------------------------------------- + */ + +Patch::Patch( Quilt_ptr geo, REAL *pta, REAL *ptb, Patch *n ) +{ +/* pspec[i].range is uninit here */ + mapdesc = geo->mapdesc; + cullval = mapdesc->isCulling() ? CULL_ACCEPT : CULL_TRIVIAL_ACCEPT; + notInBbox = mapdesc->isBboxSubdividing() ? 1 : 0; + needsSampling = mapdesc->isRangeSampling() ? 1 : 0; + pspec[0].order = geo->qspec[0].order; + pspec[1].order = geo->qspec[1].order; + pspec[0].stride = pspec[1].order * MAXCOORDS; + pspec[1].stride = MAXCOORDS; + + /* transform control points to sampling and culling spaces */ + REAL *ps = geo->cpts; + geo->select( pta, ptb ); + ps += geo->qspec[0].offset; + ps += geo->qspec[1].offset; + ps += geo->qspec[0].index * geo->qspec[0].order * geo->qspec[0].stride; + ps += geo->qspec[1].index * geo->qspec[1].order * geo->qspec[1].stride; + + if( needsSampling ) { + mapdesc->xformSampling( ps, geo->qspec[0].order, geo->qspec[0].stride, + geo->qspec[1].order, geo->qspec[1].stride, + spts, pspec[0].stride, pspec[1].stride ); + } + + if( cullval == CULL_ACCEPT ) { + mapdesc->xformCulling( ps, geo->qspec[0].order, geo->qspec[0].stride, + geo->qspec[1].order, geo->qspec[1].stride, + cpts, pspec[0].stride, pspec[1].stride ); + } + + if( notInBbox ) { + mapdesc->xformBounding( ps, geo->qspec[0].order, geo->qspec[0].stride, + geo->qspec[1].order, geo->qspec[1].stride, + bpts, pspec[0].stride, pspec[1].stride ); + } + + /* set scale range */ + pspec[0].range[0] = geo->qspec[0].breakpoints[geo->qspec[0].index]; + pspec[0].range[1] = geo->qspec[0].breakpoints[geo->qspec[0].index+1]; + pspec[0].range[2] = pspec[0].range[1] - pspec[0].range[0]; + + pspec[1].range[0] = geo->qspec[1].breakpoints[geo->qspec[1].index]; + pspec[1].range[1] = geo->qspec[1].breakpoints[geo->qspec[1].index+1]; + pspec[1].range[2] = pspec[1].range[1] - pspec[1].range[0]; + + // may need to subdivide to match range of sub-patch + if( pspec[0].range[0] != pta[0] ) { + assert( pspec[0].range[0] < pta[0] ); + Patch lower( *this, 0, pta[0], 0 ); + *this = lower; + } + + if( pspec[0].range[1] != ptb[0] ) { + assert( pspec[0].range[1] > ptb[0] ); + Patch upper( *this, 0, ptb[0], 0 ); + } + + if( pspec[1].range[0] != pta[1] ) { + assert( pspec[1].range[0] < pta[1] ); + Patch lower( *this, 1, pta[1], 0 ); + *this = lower; + } + + if( pspec[1].range[1] != ptb[1] ) { + assert( pspec[1].range[1] > ptb[1] ); + Patch upper( *this, 1, ptb[1], 0 ); + } + checkBboxConstraint(); + next = n; +} + +/*-------------------------------------------------------------------------- + * Patch - subdivide a patch along an isoparametric line + *-------------------------------------------------------------------------- + */ + +Patch::Patch( Patch& upper, int param, REAL value, Patch *n ) +{ + Patch& lower = *this; + + lower.cullval = upper.cullval; + lower.mapdesc = upper.mapdesc; + lower.notInBbox = upper.notInBbox; + lower.needsSampling = upper.needsSampling; + lower.pspec[0].order = upper.pspec[0].order; + lower.pspec[1].order = upper.pspec[1].order; + lower.pspec[0].stride = upper.pspec[0].stride; + lower.pspec[1].stride = upper.pspec[1].stride; + lower.next = n; + + /* reset scale range */ + switch( param ) { + case 0: { + REAL d = (value-upper.pspec[0].range[0]) / upper.pspec[0].range[2]; + if( needsSampling ) + mapdesc->subdivide( upper.spts, lower.spts, d, pspec[1].order, + pspec[1].stride, pspec[0].order, pspec[0].stride ); + + if( cullval == CULL_ACCEPT ) + mapdesc->subdivide( upper.cpts, lower.cpts, d, pspec[1].order, + pspec[1].stride, pspec[0].order, pspec[0].stride ); + + if( notInBbox ) + mapdesc->subdivide( upper.bpts, lower.bpts, d, pspec[1].order, + pspec[1].stride, pspec[0].order, pspec[0].stride ); + + lower.pspec[0].range[0] = upper.pspec[0].range[0]; + lower.pspec[0].range[1] = value; + lower.pspec[0].range[2] = value - upper.pspec[0].range[0]; + upper.pspec[0].range[0] = value; + upper.pspec[0].range[2] = upper.pspec[0].range[1] - value; + + lower.pspec[1].range[0] = upper.pspec[1].range[0]; + lower.pspec[1].range[1] = upper.pspec[1].range[1]; + lower.pspec[1].range[2] = upper.pspec[1].range[2]; + break; + } + case 1: { + REAL d = (value-upper.pspec[1].range[0]) / upper.pspec[1].range[2]; + if( needsSampling ) + mapdesc->subdivide( upper.spts, lower.spts, d, pspec[0].order, + pspec[0].stride, pspec[1].order, pspec[1].stride ); + if( cullval == CULL_ACCEPT ) + mapdesc->subdivide( upper.cpts, lower.cpts, d, pspec[0].order, + pspec[0].stride, pspec[1].order, pspec[1].stride ); + if( notInBbox ) + mapdesc->subdivide( upper.bpts, lower.bpts, d, pspec[0].order, + pspec[0].stride, pspec[1].order, pspec[1].stride ); + lower.pspec[0].range[0] = upper.pspec[0].range[0]; + lower.pspec[0].range[1] = upper.pspec[0].range[1]; + lower.pspec[0].range[2] = upper.pspec[0].range[2]; + + lower.pspec[1].range[0] = upper.pspec[1].range[0]; + lower.pspec[1].range[1] = value; + lower.pspec[1].range[2] = value - upper.pspec[1].range[0]; + upper.pspec[1].range[0] = value; + upper.pspec[1].range[2] = upper.pspec[1].range[1] - value; + break; + } + } + + // inherit bounding box + if( mapdesc->isBboxSubdividing() && ! notInBbox ) + memcpy( lower.bb, upper.bb, sizeof( bb ) ); + + lower.checkBboxConstraint(); + upper.checkBboxConstraint(); +} + +/*-------------------------------------------------------------------------- + * clamp - clamp the sampling rate to a given maximum + *-------------------------------------------------------------------------- + */ + +void +Patch::clamp( void ) +{ + if( mapdesc->clampfactor != N_NOCLAMPING ) { + pspec[0].clamp( mapdesc->clampfactor ); + pspec[1].clamp( mapdesc->clampfactor ); + } +} + +void +Patchspec::clamp( REAL clampfactor ) +{ + if( sidestep[0] < minstepsize ) + sidestep[0] = clampfactor * minstepsize; + if( sidestep[1] < minstepsize ) + sidestep[1] = clampfactor * minstepsize; + if( stepsize < minstepsize ) + stepsize = clampfactor * minstepsize; +} + +void +Patch::checkBboxConstraint( void ) +{ + if( notInBbox && + mapdesc->bboxTooBig( bpts, pspec[0].stride, pspec[1].stride, + pspec[0].order, pspec[1].order, bb ) != 1 ) { + notInBbox = 0; + } +} + +void +Patch::bbox( void ) +{ + if( mapdesc->isBboxSubdividing() ) + mapdesc->surfbbox( bb ); +} + +/*-------------------------------------------------------------------------- + * getstepsize - compute the sampling density across the patch + * and determine if patch needs to be subdivided + *-------------------------------------------------------------------------- + */ + +void +Patch::getstepsize( void ) +{ + pspec[0].minstepsize = pspec[1].minstepsize = 0; + pspec[0].needsSubdivision = pspec[1].needsSubdivision = 0; + + if( mapdesc->isConstantSampling() ) { + // fixed number of samples per patch in each direction + // maxsrate is number of s samples per patch + // maxtrate is number of t samples per patch + pspec[0].getstepsize( mapdesc->maxsrate ); + pspec[1].getstepsize( mapdesc->maxtrate ); + + } else if( mapdesc->isDomainSampling() ) { + // maxsrate is number of s samples per unit s length of domain + // maxtrate is number of t samples per unit t length of domain + pspec[0].getstepsize( mapdesc->maxsrate * pspec[0].range[2] ); + pspec[1].getstepsize( mapdesc->maxtrate * pspec[1].range[2] ); + + } else if( ! needsSampling ) { + pspec[0].singleStep(); + pspec[1].singleStep(); + } else { + // upper bound on path length between sample points + REAL tmp[MAXORDER][MAXORDER][MAXCOORDS]; + const int trstride = sizeof(tmp[0]) / sizeof(REAL); + const int tcstride = sizeof(tmp[0][0]) / sizeof(REAL); + + assert( pspec[0].order <= MAXORDER ); + + /* points have been transformed, therefore they are homogeneous */ + + int val = mapdesc->project( spts, pspec[0].stride, pspec[1].stride, + &tmp[0][0][0], trstride, tcstride, + pspec[0].order, pspec[1].order ); + if( val == 0 ) { + // control points cross infinity, therefore partials are undefined + pspec[0].getstepsize( mapdesc->maxsrate ); + pspec[1].getstepsize( mapdesc->maxtrate ); + } else { + REAL t1 = mapdesc->getProperty( N_PIXEL_TOLERANCE ); +// REAL t2 = mapdesc->getProperty( N_ERROR_TOLERANCE ); + pspec[0].minstepsize = ( mapdesc->maxsrate > 0.0 ) ? + (pspec[0].range[2] / mapdesc->maxsrate) : 0.0; + pspec[1].minstepsize = ( mapdesc->maxtrate > 0.0 ) ? + (pspec[1].range[2] / mapdesc->maxtrate) : 0.0; + if( mapdesc->isParametricDistanceSampling() || + mapdesc->isObjectSpaceParaSampling() ) { + + REAL t2; + t2 = mapdesc->getProperty( N_ERROR_TOLERANCE ); + + // t2 is upper bound on the distance between surface and tessellant + REAL ssv[2], ttv[2]; + REAL ss = mapdesc->calcPartialVelocity( ssv, &tmp[0][0][0], trstride, tcstride, pspec[0].order, pspec[1].order, 2, 0, pspec[0].range[2], pspec[1].range[2], 0 ); + REAL st = mapdesc->calcPartialVelocity( 0, &tmp[0][0][0], trstride, tcstride, pspec[0].order, pspec[1].order, 1, 1, pspec[0].range[2], pspec[1].range[2], -1 ); + REAL tt = mapdesc->calcPartialVelocity( ttv, &tmp[0][0][0], trstride, tcstride, pspec[0].order, pspec[1].order, 0, 2, pspec[0].range[2], pspec[1].range[2], 1 ); + //make sure that ss st and tt are nonnegative: + if(ss <0) ss = -ss; + if(st <0) st = -st; + if(tt <0) tt = -tt; + + if( ss != 0.0 && tt != 0.0 ) { + /* printf( "ssv[0] %g ssv[1] %g ttv[0] %g ttv[1] %g\n", + ssv[0], ssv[1], ttv[0], ttv[1] ); */ + REAL ttq = sqrtf( (float) ss ); + REAL ssq = sqrtf( (float) tt ); + REAL ds = sqrtf( 4 * t2 * ttq / ( ss * ttq + st * ssq ) ); + REAL dt = sqrtf( 4 * t2 * ssq / ( tt * ssq + st * ttq ) ); + pspec[0].stepsize = ( ds < pspec[0].range[2] ) ? ds : pspec[0].range[2]; + REAL scutoff = 2.0 * t2 / ( pspec[0].range[2] * pspec[0].range[2]); + pspec[0].sidestep[0] = (ssv[0] > scutoff) ? sqrtf( 2.0 * t2 / ssv[0] ) : pspec[0].range[2]; + pspec[0].sidestep[1] = (ssv[1] > scutoff) ? sqrtf( 2.0 * t2 / ssv[1] ) : pspec[0].range[2]; + + pspec[1].stepsize = ( dt < pspec[1].range[2] ) ? dt : pspec[1].range[2]; + REAL tcutoff = 2.0 * t2 / ( pspec[1].range[2] * pspec[1].range[2]); + pspec[1].sidestep[0] = (ttv[0] > tcutoff) ? sqrtf( 2.0 * t2 / ttv[0] ) : pspec[1].range[2]; + pspec[1].sidestep[1] = (ttv[1] > tcutoff) ? sqrtf( 2.0 * t2 / ttv[1] ) : pspec[1].range[2]; + } else if( ss != 0.0 ) { + REAL x = pspec[1].range[2] * st; + REAL ds = ( sqrtf( x * x + 8.0 * t2 * ss ) - x ) / ss; + pspec[0].stepsize = ( ds < pspec[0].range[2] ) ? ds : pspec[0].range[2]; + REAL scutoff = 2.0 * t2 / ( pspec[0].range[2] * pspec[0].range[2]); + pspec[0].sidestep[0] = (ssv[0] > scutoff) ? sqrtf( 2.0 * t2 / ssv[0] ) : pspec[0].range[2]; + pspec[0].sidestep[1] = (ssv[1] > scutoff) ? sqrtf( 2.0 * t2 / ssv[1] ) : pspec[0].range[2]; + pspec[1].singleStep(); + } else if( tt != 0.0 ) { + REAL x = pspec[0].range[2] * st; + REAL dt = ( sqrtf( x * x + 8.0 * t2 * tt ) - x ) / tt; + pspec[0].singleStep(); + REAL tcutoff = 2.0 * t2 / ( pspec[1].range[2] * pspec[1].range[2]); + pspec[1].stepsize = ( dt < pspec[1].range[2] ) ? dt : pspec[1].range[2]; + pspec[1].sidestep[0] = (ttv[0] > tcutoff) ? sqrtf( 2.0 * t2 / ttv[0] ) : pspec[1].range[2]; + pspec[1].sidestep[1] = (ttv[1] > tcutoff) ? sqrtf( 2.0 * t2 / ttv[1] ) : pspec[1].range[2]; + } else { + if( 4.0 * t2 > st * pspec[0].range[2] * pspec[1].range[2] ) { + pspec[0].singleStep(); + pspec[1].singleStep(); + } else { + REAL area = 4.0 * t2 / st; + REAL ds = sqrtf( area * pspec[0].range[2] / pspec[1].range[2] ); + REAL dt = sqrtf( area * pspec[1].range[2] / pspec[0].range[2] ); + pspec[0].stepsize = ( ds < pspec[0].range[2] ) ? ds : pspec[0].range[2]; + pspec[0].sidestep[0] = pspec[0].range[2]; + pspec[0].sidestep[1] = pspec[0].range[2]; + + pspec[1].stepsize = ( dt < pspec[1].range[2] ) ? dt : pspec[1].range[2]; + pspec[1].sidestep[0] = pspec[1].range[2]; + pspec[1].sidestep[1] = pspec[1].range[2]; + } + } + } else if( mapdesc->isPathLengthSampling() || + mapdesc->isObjectSpacePathSampling()) { + // t1 is upper bound on path length + REAL msv[2], mtv[2]; + REAL ms = mapdesc->calcPartialVelocity( msv, &tmp[0][0][0], trstride, tcstride, pspec[0].order, pspec[1].order, 1, 0, pspec[0].range[2], pspec[1].range[2], 0 ); + REAL mt = mapdesc->calcPartialVelocity( mtv, &tmp[0][0][0], trstride, tcstride, pspec[0].order, pspec[1].order, 0, 1, pspec[0].range[2], pspec[1].range[2], 1 ); + REAL side_scale = 1.0; + + if( ms != 0.0 ) { + if( mt != 0.0 ) { +/* REAL d = t1 / ( ms * ms + mt * mt );*/ +/* REAL ds = mt * d;*/ + REAL ds = t1 / (2.0*ms); +/* REAL dt = ms * d;*/ + REAL dt = t1 / (2.0*mt); + pspec[0].stepsize = ( ds < pspec[0].range[2] ) ? ds : pspec[0].range[2]; + pspec[0].sidestep[0] = ( msv[0] * pspec[0].range[2] > t1 ) ? (side_scale* t1 / msv[0]) : pspec[0].range[2]; + pspec[0].sidestep[1] = ( msv[1] * pspec[0].range[2] > t1 ) ? (side_scale* t1 / msv[1]) : pspec[0].range[2]; + + pspec[1].stepsize = ( dt < pspec[1].range[2] ) ? dt : pspec[1].range[2]; + pspec[1].sidestep[0] = ( mtv[0] * pspec[1].range[2] > t1 ) ? (side_scale*t1 / mtv[0]) : pspec[1].range[2]; + pspec[1].sidestep[1] = ( mtv[1] * pspec[1].range[2] > t1 ) ? (side_scale*t1 / mtv[1]) : pspec[1].range[2]; + } else { + pspec[0].stepsize = ( t1 < ms * pspec[0].range[2] ) ? (t1 / ms) : pspec[0].range[2]; + pspec[0].sidestep[0] = ( msv[0] * pspec[0].range[2] > t1 ) ? (t1 / msv[0]) : pspec[0].range[2]; + pspec[0].sidestep[1] = ( msv[1] * pspec[0].range[2] > t1 ) ? (t1 / msv[1]) : pspec[0].range[2]; + + pspec[1].singleStep(); + } + } else { + if( mt != 0.0 ) { + pspec[0].singleStep(); + + pspec[1].stepsize = ( t1 < mt * pspec[1].range[2] ) ? (t1 / mt) : pspec[1].range[2]; + pspec[1].sidestep[0] = ( mtv[0] * pspec[1].range[2] > t1 ) ? (t1 / mtv[0]) : pspec[1].range[2]; + pspec[1].sidestep[1] = ( mtv[1] * pspec[1].range[2] > t1 ) ? (t1 / mtv[1]) : pspec[1].range[2]; + } else { + pspec[0].singleStep(); + pspec[1].singleStep(); + } + } + } else if( mapdesc->isSurfaceAreaSampling() ) { + // t is the square root of area +/* + REAL msv[2], mtv[2]; + REAL ms = mapdesc->calcPartialVelocity( msv, &tmp[0][0][0], trstride, tcstride, pspec[0].order, pspec[1].order, 1, 0, pspec[0].range[2], pspec[1].range[2], 0 ); + REAL mt = mapdesc->calcPartialVelocity( mtv, &tmp[0][0][0], trstride, tcstride, pspec[0].order, pspec[1].order, 0, 1, pspec[0].range[2], pspec[1].range[2], 1 ); + if( ms != 0.0 && mt != 0.0 ) { + REAL d = 1.0 / (ms * mt); + t *= M_SQRT2; + REAL ds = t * sqrtf( d * pspec[0].range[2] / pspec[1].range[2] ); + REAL dt = t * sqrtf( d * pspec[1].range[2] / pspec[0].range[2] ); + pspec[0].stepsize = ( ds < pspec[0].range[2] ) ? ds : pspec[0].range[2]; + pspec[0].sidestep[0] = ( msv[0] * pspec[0].range[2] > t ) ? (t / msv[0]) : pspec[0].range[2]; + pspec[0].sidestep[1] = ( msv[1] * pspec[0].range[2] > t ) ? (t / msv[1]) : pspec[0].range[2]; + + pspec[1].stepsize = ( dt < pspec[1].range[2] ) ? dt : pspec[1].range[2]; + pspec[1].sidestep[0] = ( mtv[0] * pspec[1].range[2] > t ) ? (t / mtv[0]) : pspec[1].range[2]; + pspec[1].sidestep[1] = ( mtv[1] * pspec[1].range[2] > t ) ? (t / mtv[1]) : pspec[1].range[2]; + } else { + pspec[0].singleStep(); + pspec[1].singleStep(); + } +*/ + } else { + pspec[0].singleStep(); + pspec[1].singleStep(); + } + } + } + +#ifdef DEBUG + _glu_dprintf( "sidesteps %g %g %g %g, stepsize %g %g\n", + pspec[0].sidestep[0], pspec[0].sidestep[1], + pspec[1].sidestep[0], pspec[1].sidestep[1], + pspec[0].stepsize, pspec[1].stepsize ); +#endif + + if( mapdesc->minsavings != N_NOSAVINGSSUBDIVISION ) { + REAL savings = 1./(pspec[0].stepsize * pspec[1].stepsize) ; + savings-= (2./( pspec[0].sidestep[0] + pspec[0].sidestep[1] )) * + (2./( pspec[1].sidestep[0] + pspec[1].sidestep[1] )); + + savings *= pspec[0].range[2] * pspec[1].range[2]; + if( savings > mapdesc->minsavings ) { + pspec[0].needsSubdivision = pspec[1].needsSubdivision = 1; + } + } + + if( pspec[0].stepsize < pspec[0].minstepsize ) pspec[0].needsSubdivision = 1; + if( pspec[1].stepsize < pspec[1].minstepsize ) pspec[1].needsSubdivision = 1; + needsSampling = (needsSampling ? needsSamplingSubdivision() : 0); +} + +void +Patchspec::singleStep() +{ + stepsize = sidestep[0] = sidestep[1] = glu_abs(range[2]); +} + +void +Patchspec::getstepsize( REAL max ) // max is number of samples for entire patch +{ + stepsize = ( max >= 1.0 ) ? range[2] / max : range[2]; + if (stepsize < 0.0) { + stepsize = -stepsize; + } + sidestep[0] = sidestep[1] = minstepsize = stepsize; +} + +int +Patch::needsSamplingSubdivision( void ) +{ + return (pspec[0].needsSubdivision || pspec[1].needsSubdivision) ? 1 : 0; +} + +int +Patch::needsNonSamplingSubdivision( void ) +{ + return notInBbox; +} + +int +Patch::needsSubdivision( int param ) +{ + return pspec[param].needsSubdivision; +} + +int +Patch::cullCheck( void ) +{ + if( cullval == CULL_ACCEPT ) + cullval = mapdesc->cullCheck( cpts, pspec[0].order, pspec[0].stride, + pspec[1].order, pspec[1].stride ); + return cullval; +} + diff --git a/src/glu/sgi/libnurbs/internals/patch.h b/src/glu/sgi/libnurbs/internals/patch.h new file mode 100644 index 0000000..324a259 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/patch.h @@ -0,0 +1,94 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * patch.h + * + */ + +#ifndef __glupatch_h_ +#define __glupatch_h_ + +#include "types.h" +#include "defines.h" + +class Quilt; +class Mapdesc; + + +struct Pspec { + REAL range[3]; + REAL sidestep[2]; + REAL stepsize; + REAL minstepsize; + int needsSubdivision; +}; + +struct Patchspec : public Pspec { + int order; + int stride; + void clamp( REAL ); + void getstepsize( REAL ); + void singleStep( void ); +}; + +class Patch { +public: +friend class Subdivider; +friend class Quilt; +friend class Patchlist; + Patch( Quilt *, REAL*, REAL *, Patch * ); + Patch( Patch &, int, REAL, Patch * ); + void bbox( void ); + void clamp( void ); + void getstepsize( void ); + int cullCheck( void ); + int needsSubdivision( int ); + int needsSamplingSubdivision( void ); + int needsNonSamplingSubdivision( void ); + + int get_uorder() {return pspec[0].order;} + int get_vorder() {return pspec[1].order;} + +private: + + Mapdesc* mapdesc; + Patch* next; + int cullval; + int notInBbox; + int needsSampling; + REAL cpts[MAXORDER*MAXORDER*MAXCOORDS]; //culling pts + REAL spts[MAXORDER*MAXORDER*MAXCOORDS]; //sampling pts + REAL bpts[MAXORDER*MAXORDER*MAXCOORDS]; //bbox pts + Patchspec pspec[2]; + void checkBboxConstraint( void ); + REAL bb[2][MAXCOORDS]; +}; +#endif /* __glupatch_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/patchlist.cc b/src/glu/sgi/libnurbs/internals/patchlist.cc new file mode 100644 index 0000000..6a400ab --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/patchlist.cc @@ -0,0 +1,169 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * patchlist.c++ + * + */ + +#include +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "quilt.h" +#include "patchlist.h" +#include "patch.h" + +Patchlist::Patchlist( Quilt *quilts, REAL *pta, REAL *ptb ) +{ + patch = 0; + for( Quilt *q = quilts; q; q = q->next ) + patch = new Patch( q, pta, ptb, patch ); + pspec[0].range[0] = pta[0]; + pspec[0].range[1] = ptb[0]; + pspec[0].range[2] = ptb[0] - pta[0]; + + pspec[1].range[0] = pta[1]; + pspec[1].range[1] = ptb[1]; + pspec[1].range[2] = ptb[1] - pta[1]; +} + +Patchlist::Patchlist( Patchlist &upper, int param, REAL value) +{ + Patchlist &lower = *this; + patch = 0; + for( Patch *p = upper.patch; p; p = p->next ) + patch = new Patch( *p, param, value, patch ); + + if( param == 0 ) { + lower.pspec[0].range[0] = upper.pspec[0].range[0]; + lower.pspec[0].range[1] = value; + lower.pspec[0].range[2] = value - upper.pspec[0].range[0]; + upper.pspec[0].range[0] = value; + upper.pspec[0].range[2] = upper.pspec[0].range[1] - value; + lower.pspec[1] = upper.pspec[1]; + } else { + lower.pspec[0] = upper.pspec[0]; + lower.pspec[1].range[0] = upper.pspec[1].range[0]; + lower.pspec[1].range[1] = value; + lower.pspec[1].range[2] = value - upper.pspec[1].range[0]; + upper.pspec[1].range[0] = value; + upper.pspec[1].range[2] = upper.pspec[1].range[1] - value; + } +} + +Patchlist::~Patchlist() +{ + while( patch ) { + Patch *p = patch; + patch = patch->next; + delete p; + } +} + +int +Patchlist::cullCheck( void ) +{ + for( Patch *p = patch; p; p = p->next ) + if( p->cullCheck() == CULL_TRIVIAL_REJECT ) + return CULL_TRIVIAL_REJECT; + return CULL_ACCEPT; +} + +void +Patchlist::getRanges(REAL ranges[4]) +{ + ranges[0] = pspec[0].range[0]; + ranges[1] = pspec[0].range[1]; + ranges[2] = pspec[1].range[0]; + ranges[3] = pspec[1].range[1]; +} + +void +Patchlist::getstepsize( void ) +{ + pspec[0].stepsize = pspec[0].range[2]; + pspec[0].sidestep[0] = pspec[0].range[2]; + pspec[0].sidestep[1] = pspec[0].range[2]; + + pspec[1].stepsize = pspec[1].range[2]; + pspec[1].sidestep[0] = pspec[1].range[2]; + pspec[1].sidestep[1] = pspec[1].range[2]; + + for( Patch *p = patch; p; p = p->next ) { + p->getstepsize(); + p->clamp(); + pspec[0].stepsize = ((p->pspec[0].stepsize < pspec[0].stepsize) ? p->pspec[0].stepsize : pspec[0].stepsize); + pspec[0].sidestep[0] = ((p->pspec[0].sidestep[0] < pspec[0].sidestep[0]) ? p->pspec[0].sidestep[0] : pspec[0].sidestep[0]); + pspec[0].sidestep[1] = ((p->pspec[0].sidestep[1] < pspec[0].sidestep[1]) ? p->pspec[0].sidestep[1] : pspec[0].sidestep[1]); + pspec[1].stepsize = ((p->pspec[1].stepsize < pspec[1].stepsize) ? p->pspec[1].stepsize : pspec[1].stepsize); + pspec[1].sidestep[0] = ((p->pspec[1].sidestep[0] < pspec[1].sidestep[0]) ? p->pspec[1].sidestep[0] : pspec[1].sidestep[0]); + pspec[1].sidestep[1] = ((p->pspec[1].sidestep[1] < pspec[1].sidestep[1]) ? p->pspec[1].sidestep[1] : pspec[1].sidestep[1]); + } +} + +void +Patchlist::bbox( void ) +{ + for( Patch *p = patch; p; p = p->next ) + p->bbox(); +} + +int +Patchlist::needsNonSamplingSubdivision( void ) +{ + notInBbox = 0; + for( Patch *p = patch; p; p = p->next ) + notInBbox |= p->needsNonSamplingSubdivision(); + return notInBbox; +} + +int +Patchlist::needsSamplingSubdivision( void ) +{ + pspec[0].needsSubdivision = 0; + pspec[1].needsSubdivision = 0; + + for( Patch *p = patch; p; p = p->next ) { + pspec[0].needsSubdivision |= p->pspec[0].needsSubdivision; + pspec[1].needsSubdivision |= p->pspec[0].needsSubdivision; + } + return (pspec[0].needsSubdivision || pspec[1].needsSubdivision) ? 1 : 0; +} + +int +Patchlist::needsSubdivision( int param ) +{ + return pspec[param].needsSubdivision; +} diff --git a/src/glu/sgi/libnurbs/internals/patchlist.h b/src/glu/sgi/libnurbs/internals/patchlist.h new file mode 100644 index 0000000..9bfc5b4 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/patchlist.h @@ -0,0 +1,92 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * patchlist.h + * + */ + +#ifndef __glupatchlist_h_ +#define __glupatchlist_h_ + +#include "types.h" +#include "defines.h" +#include "patch.h" + +class Quilt; + +class Patchlist { +friend class Subdivider; +public: + Patchlist( Quilt *, REAL *, REAL * ); + Patchlist( Patchlist &, int , REAL ); + ~Patchlist(); + void bbox(); + int cullCheck( void ); + void getstepsize( void ); + int needsNonSamplingSubdivision( void ); + int needsSamplingSubdivision( void ); + int needsSubdivision( int ); + REAL getStepsize( int ); + void getRanges(REAL ranges[4]); + + int get_uorder(); + int get_vorder(); +private: + Patch *patch; + int notInBbox; + int needsSampling; + Pspec pspec[2]; +}; + +inline REAL +Patchlist::getStepsize( int param ) +{ + return pspec[param].stepsize; +} + +inline int +Patchlist::get_uorder() +{ + return patch->get_uorder(); + +} + +inline int + Patchlist::get_vorder() +{ + return patch->get_vorder(); +} + + + + + +#endif /* __glupatchlist_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/pwlarc.h b/src/glu/sgi/libnurbs/internals/pwlarc.h new file mode 100644 index 0000000..2e5175a --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/pwlarc.h @@ -0,0 +1,78 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * pwlarc.h + * + */ + +#ifndef __glupwlarc_h_ +#define __glupwlarc_h_ + +#include "myassert.h" +#include "nurbsconsts.h" + +class TrimVertex; + +class PwlArc : public PooledObj { /* a piecewise-linear arc */ +public: + TrimVertex * pts; /* sample points */ + int npts; /* number of sample points */ + long type; /* curve type */ + inline PwlArc( void ); + inline PwlArc( int, TrimVertex * ); + inline PwlArc( int, TrimVertex *, long ); +}; + +inline +PwlArc::PwlArc( void ) +{ + type = N_P2D; + pts = 0; + npts = -1; +} + +inline +PwlArc::PwlArc( int _npts, TrimVertex *_pts ) +{ + pts = _pts; + npts = _npts; + type = N_P2D; +} + +inline +PwlArc::PwlArc( int _npts, TrimVertex *_pts, long _type ) +{ + pts = _pts; + npts = _npts; + type = _type; +} + +#endif /* __glupwlarc_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/quilt.cc b/src/glu/sgi/libnurbs/internals/quilt.cc new file mode 100644 index 0000000..d16f4bf --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/quilt.cc @@ -0,0 +1,274 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * quilt.c++ + * + */ + +#include "glimports.h" +#include "mystdio.h" +#include "myassert.h" +#include "quilt.h" +#include "backend.h" +#include "mapdesc.h" +#include "flist.h" +#include "patchlist.h" +#include "simplemath.h" //min() + +/* local preprocessor definitions */ +#define DEF_PATCH_STEPSIZE .4 +#define fsizeof(x) (sizeof(x)/sizeof(REAL)) + + +Quilt::Quilt( Mapdesc *_mapdesc ) +{ + mapdesc = _mapdesc; +} + +void +Quilt::deleteMe( Pool& p ) +{ + for( Quiltspec *q=qspec; q != eqspec; q++ ) { +#if 1 + if( q->breakpoints) delete[] q->breakpoints; q->breakpoints = 0; +#else + if( q->breakpoints) { + delete[] q->breakpoints; + q->breakpoints = 0; +printf("in here\n"); + } +#endif + } + if( cpts ) delete[] cpts; + cpts = 0; + PooledObj::deleteMe( p ); +} + +void +Quilt::show( void ) +{ +#ifndef NDEBUG + int nc = mapdesc->getNcoords(); + REAL *ps = cpts; + ps += qspec[0].offset; + ps += qspec[1].offset; + for( int i=0; i!= qspec[0].order * qspec[0].width; i++ ) { + for( int j = 0; j!= qspec[1].order * qspec[1].width; j++ ) { + for( int k=0; k < nc; k++ ) + _glu_dprintf( "%g ", ps[i*qspec[0].stride + j*qspec[1].stride + k] ); + _glu_dprintf( "\n" ); + } + _glu_dprintf( "\n" ); + } + _glu_dprintf( "\n" ); +#endif +} + +/*-------------------------------------------------------------------------- + * Quilt::select - find which map in each quilt contains the points + * pta and ptb with pta[i] < ptb[i] + *-------------------------------------------------------------------------- + */ + +void +Quilt::select( REAL *pta, REAL *ptb ) +{ + int dim = eqspec - qspec; + int i, j; + for( i=0; i=0; j-- ) + if( (qspec[i].breakpoints[j] <= pta[i] ) && + (ptb[i] <= qspec[i].breakpoints[j+1] ) ) + break; + assert( j != -1 ); + qspec[i].index = j; + } +} + +void +Quilt::download( Backend &backend ) +{ + if( getDimension() == 2 ) { + REAL *ps = cpts; + ps += qspec[0].offset; + ps += qspec[1].offset; + ps += qspec[0].index * qspec[0].order * qspec[0].stride; + ps += qspec[1].index * qspec[1].order * qspec[1].stride; + backend.surfpts( mapdesc->getType(), ps, + qspec[0].stride, + qspec[1].stride, + qspec[0].order, + qspec[1].order, + qspec[0].breakpoints[qspec[0].index], + qspec[0].breakpoints[qspec[0].index+1], + qspec[1].breakpoints[qspec[1].index], + qspec[1].breakpoints[qspec[1].index+1] ); + } else { + REAL *ps = cpts; + ps += qspec[0].offset; + ps += qspec[0].index * qspec[0].order * qspec[0].stride; + backend.curvpts( mapdesc->getType(), ps, + qspec[0].stride, + qspec[0].order, + qspec[0].breakpoints[qspec[0].index], + qspec[0].breakpoints[qspec[0].index+1] ); + } +} + +/*-------------------------------------------------------------------------- + * Quilt::downloadAll - download each map that contains the current patch + *-------------------------------------------------------------------------- + */ + +void +Quilt::downloadAll( REAL *pta, REAL *ptb, Backend &backend ) +{ + for( Quilt *m = this; m; m=m->next ) { + m->select( pta, ptb ); + m->download( backend ); + } +} + +/*-------------------------------------------------------------------------- + * Quilt::isCulled - determine if an entire quilt is trivially rejected. + *-------------------------------------------------------------------------- + */ + +int +Quilt::isCulled( void ) +{ + if( mapdesc->isCulling() ) + return mapdesc->xformAndCullCheck( cpts + qspec[0].offset + qspec[1].offset, + qspec[0].order * qspec[0].width, qspec[0].stride, + qspec[1].order * qspec[1].width, qspec[1].stride ); + else + return CULL_ACCEPT; +} + +/*--------------------------------------------------------------------------- + * Quilt::getRange - retrieve the valid paramater range of a set of quilts + *--------------------------------------------------------------------------- + */ +void +Quilt::getRange( REAL *from, REAL *to, Flist& slist, Flist &tlist ) +{ + getRange( from, to, 0, slist ); + getRange( from, to, 1, tlist ); +} + +/*--------------------------------------------------------------------------- + * Quilt::getRange - retrieve the valid paramater range of a set of quilts + *--------------------------------------------------------------------------- + */ +void +Quilt::getRange( REAL *from, REAL *to, int i, Flist &list ) +{ + Quilt *maps = this; + from[i] = maps->qspec[i].breakpoints[0]; + to[i] = maps->qspec[i].breakpoints[maps->qspec[i].width]; + int maxpts = 0; + Quilt_ptr m; + for( m=maps; m; m=m->next ) { + if( m->qspec[i].breakpoints[0] > from[i] ) + from[i] = m->qspec[i].breakpoints[0]; + if( m->qspec[i].breakpoints[m->qspec[i].width] < to[i] ) + to[i] = m->qspec[i].breakpoints[m->qspec[i].width]; + maxpts += m->qspec[i].width + 1; + } + + list.grow( maxpts ); + + for( m=maps; m; m=m->next ) + for( int j=0; j<=m->qspec[i].width; j++ ) { + list.add( m->qspec[i].breakpoints[j] ); + } + + list.filter( ); + list.taper( from[i], to[i] ); +} + +void +Quilt::getRange( REAL *from, REAL *to, Flist& slist ) +{ + getRange( from, to, 0, slist ); +} + +void +Quilt::findRates( Flist& slist, Flist& tlist, REAL rate[2] ) +{ + findSampleRates( slist, tlist ); + rate[0] = qspec[0].step_size; + rate[1] = qspec[1].step_size; + + for( Quilt *q = next; q; q = q->next ) { + q->findSampleRates( slist, tlist ); + if( q->qspec[0].step_size < rate[0] ) + rate[0] = q->qspec[0].step_size; + if( q->qspec[1].step_size < rate[1] ) + rate[1] = q->qspec[1].step_size; + } +} + +void +Quilt::findSampleRates( Flist& slist, Flist& tlist ) +{ + qspec[0].step_size = DEF_PATCH_STEPSIZE * + (qspec[0].breakpoints[qspec[0].width] - qspec[0].breakpoints[0]); + qspec[1].step_size = DEF_PATCH_STEPSIZE * + (qspec[1].breakpoints[qspec[1].width] - qspec[1].breakpoints[0]); + + for( int i = slist.start; i < slist.end-1; i++ ) { + for( int j = tlist.start; j < tlist.end-1; j++ ) { + + REAL pta[2], ptb[2]; + pta[0] = slist.pts[i]; + ptb[0] = slist.pts[i+1]; + pta[1] = tlist.pts[j]; + ptb[1] = tlist.pts[j+1]; + Patchlist patchlist( this, pta, ptb ); + patchlist.getstepsize(); + + { + float edge_len_s = min(glu_abs(ptb[0]-pta[0]),1.0); + float edge_len_t = min(glu_abs(ptb[1]-pta[1]),1.0); + + if( patchlist.getStepsize(0)/edge_len_s < qspec[0].step_size ) + qspec[0].step_size = patchlist.getStepsize(0)/edge_len_s; + if( patchlist.getStepsize(1)/edge_len_t < qspec[1].step_size ) + qspec[1].step_size = patchlist.getStepsize(1)/edge_len_t; + } + } + } +} diff --git a/src/glu/sgi/libnurbs/internals/quilt.h b/src/glu/sgi/libnurbs/internals/quilt.h new file mode 100644 index 0000000..fe1e330 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/quilt.h @@ -0,0 +1,92 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * quilt.h + * + */ + +#ifndef __gluquilt_h_ +#define __gluquilt_h_ + +#include "defines.h" +#include "bufpool.h" +#include "types.h" + +class Backend; +class Mapdesc; +class Flist; +struct Knotvector; + +/* constants for memory allocation of NURBS to Bezier conversion */ +#define MAXDIM 2 + +struct Quiltspec { /* a specification for a dimension of a quilt */ + int stride; /* words between points */ + int width; /* number of segments */ + int offset; /* words to first point */ + int order; /* order */ + int index; /* current segment number */ + int bdry[2]; /* boundary edge flag */ + REAL step_size; + Knot * breakpoints; +}; + +typedef Quiltspec *Quiltspec_ptr; + +class Quilt : public PooledObj { /* an array of bezier patches */ +public: + Quilt( Mapdesc * ); + Mapdesc * mapdesc; /* map descriptor */ + REAL * cpts; /* control points */ + Quiltspec qspec[MAXDIM]; /* the dimensional data */ + Quiltspec_ptr eqspec; /* qspec trailer */ + Quilt *next; /* next quilt in linked list */ + +public: + void deleteMe( Pool& ); + void toBezier( Knotvector &, INREAL *, long ); + void toBezier( Knotvector &, Knotvector &, INREAL *, long ); + void select( REAL *, REAL * ); + int getDimension( void ) { return eqspec - qspec; } + void download( Backend & ); + void downloadAll( REAL *, REAL *, Backend & ); + int isCulled( void ); + void getRange( REAL *, REAL *, Flist&, Flist & ); + void getRange( REAL *, REAL *, int, Flist & ); + void getRange( REAL *, REAL *, Flist& ); + void findRates( Flist& slist, Flist& tlist, REAL[2] ); + void findSampleRates( Flist& slist, Flist& tlist ); + void show(); +}; + +typedef class Quilt *Quilt_ptr; + +#endif /* __gluquilt_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/reader.cc b/src/glu/sgi/libnurbs/internals/reader.cc new file mode 100644 index 0000000..c59240d --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/reader.cc @@ -0,0 +1,148 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * reader.c++ + * + */ + +#include +#include "glimports.h" +#include "nurbsconsts.h" +#include "reader.h" +#include "trimvertex.h" +#include "simplemath.h" + +//when read a pwlCurve, if two consecutive points are the same, then +//eliminate one of them. This makes the tessellator more robust. The spec +//assumes the application makes sure there are no redundant points. +//but in Inspector, the trim curves seem to have redundant points a lot. +//I guess other similar users may have the same problem. + +#define ELIMINATE_REDUNDANT_POINTS + +#ifdef ELIMINATE_REDUNDANT_POINTS +#define equal(x,y) ( glu_abs(x-y) <= 0.00001) +#endif + +#ifdef ELIMINATE_REDUNDANT_POINTS +O_pwlcurve::O_pwlcurve( long _type, long count, INREAL *array, long byte_stride, TrimVertex *trimpts ) +{ + next = 0; + used = 0; + owner = 0; + pts = trimpts; + npts = (int) count; + save = 0; + int i; + + /* copy user data into internal trimming data structures */ + switch( _type ) { + case N_P2D: { + TrimVertex *v = pts; + TrimVertex *prev = NULL; + int num = 0; + int doit; + for(i=0; iparam[0], array[0]) && equal(prev->param[1], array[1])) + { + doit = 0; + } + } + + if(doit) + { + v->param[0] = (REAL) array[0]; + v->param[1] = (REAL) array[1]; + prev = v; + v++; + num++; + } + array = (INREAL *) (((char *) array) + byte_stride); + } + npts = num; + break; + } + case N_P2DR: { + TrimVertex *v = pts; + for( TrimVertex *lastv = v + count; v != lastv; v++ ) { + v->param[0] = (REAL) array[0] / (REAL) array[2]; + v->param[1] = (REAL) array[1] / (REAL) array[2]; + array = (INREAL *) (((char *) array) + byte_stride); + } + break; + } + } +} +#else +O_pwlcurve::O_pwlcurve( long _type, long count, INREAL *array, long byte_stride, TrimVertex *trimpts ) +{ + next = 0; + used = 0; + owner = 0; + pts = trimpts; + npts = (int) count; + save = 0; + + /* copy user data into internal trimming data structures */ + switch( _type ) { + case N_P2D: { + TrimVertex *v = pts; + for( TrimVertex *lastv = v + count; v != lastv; v++ ) { + v->param[0] = (REAL) array[0]; + v->param[1] = (REAL) array[1]; + array = (INREAL *) (((char *) array) + byte_stride); + } + break; + } + case N_P2DR: { + TrimVertex *v = pts; + for( TrimVertex *lastv = v + count; v != lastv; v++ ) { + v->param[0] = (REAL) array[0] / (REAL) array[2]; + v->param[1] = (REAL) array[1] / (REAL) array[2]; + array = (INREAL *) (((char *) array) + byte_stride); + } + break; + } + } +} +#endif + + + + + diff --git a/src/glu/sgi/libnurbs/internals/reader.h b/src/glu/sgi/libnurbs/internals/reader.h new file mode 100644 index 0000000..cae6cad --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/reader.h @@ -0,0 +1,132 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * reader.h + * + */ + +#ifndef __glureader_h_ +#define __glureader_h_ + +#include "bufpool.h" +#include "types.h" + +enum Curvetype { ct_nurbscurve, ct_pwlcurve, ct_none }; + +struct Property; +struct O_surface; +struct O_nurbssurface; +struct O_trim; +class O_pwlcurve; +struct O_nurbscurve; +struct O_curve; +class Quilt; +class TrimVertex; + + +struct O_curve : public PooledObj { + union { + O_nurbscurve *o_nurbscurve; + O_pwlcurve *o_pwlcurve; + } curve; + Curvetype curvetype; /* arc type: pwl or nurbs */ + O_curve * next; /* next arc in loop */ + O_surface * owner; /* owning surface */ + int used; /* curve called in cur surf */ + int save; /* 1 if in display list */ + long nuid; + O_curve() { next = 0; used = 0; owner = 0; + curve.o_pwlcurve = 0; curvetype = ct_none; save = 0; nuid = 0; } + }; + +struct O_nurbscurve : public PooledObj { + Quilt *bezier_curves; /* array of bezier curves */ + long type; /* range descriptor */ + REAL tesselation; /* tesselation tolerance */ + int method; /* tesselation method */ + O_nurbscurve * next; /* next curve in list */ + int used; /* curve called in cur surf */ + int save; /* 1 if in display list */ + O_curve * owner; /* owning curve */ + O_nurbscurve( long _type ) + { bezier_curves = 0; type = _type; tesselation = 0; method = 0; next = 0; used = 0; save = 0; owner = 0; } + }; + +class O_pwlcurve : public PooledObj { +public: + TrimVertex *pts; /* array of trim vertices */ + int npts; /* number of trim vertices */ + O_pwlcurve * next; /* next curve in list */ + int used; /* curve called in cur surf */ + int save; /* 1 if in display list */ + O_curve * owner; /* owning curve */ + O_pwlcurve( long, long, INREAL *, long, TrimVertex * ); + }; + +struct O_trim : public PooledObj { + O_curve *o_curve; /* closed trim loop */ + O_trim * next; /* next loop along trim */ + int save; /* 1 if in display list */ + O_trim() { next = 0; o_curve = 0; save = 0; } + }; + +struct O_nurbssurface : public PooledObj { + Quilt * bezier_patches;/* array of bezier patches */ + long type; /* range descriptor */ + O_surface * owner; /* owning surface */ + O_nurbssurface * next; /* next surface in chain */ + int save; /* 1 if in display list */ + int used; /* 1 if prev called in block */ + O_nurbssurface( long _type ) + { bezier_patches = 0; type = _type; owner = 0; next = 0; save = 0; used = 0; } + }; + +struct O_surface : public PooledObj { + O_nurbssurface * o_nurbssurface; /* linked list of surfaces */ + O_trim * o_trim; /* list of trim loops */ + int save; /* 1 if in display list */ + long nuid; + O_surface() { o_trim = 0; o_nurbssurface = 0; save = 0; nuid = 0; } + }; + +struct Property : public PooledObj { + long type; + long tag; + REAL value; + int save; /* 1 if in display list */ + Property( long _type, long _tag, INREAL _value ) + { type = _type; tag = _tag; value = (REAL) _value; save = 0; } + Property( long _tag, INREAL _value ) + { type = 0; tag = _tag; value = (REAL) _value; save = 0; } + }; + +class NurbsTessellator; +#endif /* __glureader_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/renderhints.cc b/src/glu/sgi/libnurbs/internals/renderhints.cc new file mode 100644 index 0000000..4b347eb --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/renderhints.cc @@ -0,0 +1,136 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * renderhints.c++ + * + */ + +#include "glimports.h" +#include "mystdio.h" +#include "renderhints.h" +#include "nurbsconsts.h" + + +/*-------------------------------------------------------------------------- + * Renderhints::Renderhints - set all window specific options + *-------------------------------------------------------------------------- + */ +Renderhints::Renderhints() +{ + display_method = N_FILL; + errorchecking = N_MSG; + subdivisions = 6.0; + tmp1 = 0.0; + displaydomain = 0; + maxsubdivisions = (int) subdivisions; + wiretris = 0; + wirequads = 0; +} + +void +Renderhints::init( void ) +{ + maxsubdivisions = (int) subdivisions; + if( maxsubdivisions < 0 ) maxsubdivisions = 0; + + + if( display_method == N_FILL ) { + wiretris = 0; + wirequads = 0; + } else if( display_method == N_OUTLINE_TRI ) { + wiretris = 1; + wirequads = 0; + } else if( display_method == N_OUTLINE_QUAD ) { + wiretris = 0; + wirequads = 1; + } else { + wiretris = 1; + wirequads = 1; + } +} + +int +Renderhints::isProperty( long property ) +{ + switch ( property ) { + case N_DISPLAY: + case N_ERRORCHECKING: + case N_SUBDIVISIONS: + case N_TMP1: + return 1; + default: + return 0; + } +} + +REAL +Renderhints::getProperty( long property ) +{ + switch ( property ) { + case N_DISPLAY: + return display_method; + case N_ERRORCHECKING: + return errorchecking; + case N_SUBDIVISIONS: + return subdivisions; + case N_TMP1: + return tmp1; + default: + abort(); + return -1; //not necessary, needed to shut up compiler + } +} + +void +Renderhints::setProperty( long property, REAL value ) +{ + switch ( property ) { + case N_DISPLAY: + display_method = value; + break; + case N_ERRORCHECKING: + errorchecking = value; + break; + case N_SUBDIVISIONS: + subdivisions = value; + break; + case N_TMP1: /* unused */ + tmp1 = value; + break; + default: + abort(); + break; + } +} diff --git a/src/glu/sgi/libnurbs/internals/renderhints.h b/src/glu/sgi/libnurbs/internals/renderhints.h new file mode 100644 index 0000000..444f649 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/renderhints.h @@ -0,0 +1,60 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * renderhints.h + * + */ + +#ifndef __glurenderhints_h_ +#define __glurenderhints_h_ + +#include "types.h" + +class Renderhints { +public: + Renderhints( void ); + void init( void ); + int isProperty( long ); + REAL getProperty( long ); + void setProperty( long, REAL ); + + REAL display_method; /* display mode */ + REAL errorchecking; /* activate error checking */ + REAL subdivisions; /* maximum number of subdivisions per patch */ + REAL tmp1; /* unused */ + + int displaydomain; + int maxsubdivisions; + int wiretris; + int wirequads; +}; + +#endif /* __glurenderhints_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/simplemath.h b/src/glu/sgi/libnurbs/internals/simplemath.h new file mode 100644 index 0000000..d00062d --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/simplemath.h @@ -0,0 +1,52 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * simplemath.h + * + */ + +#ifndef __glusimplemath_h_ +#define __glusimplemath_h_ + +/* simple inline routines */ + +#include "types.h" + +inline int +max( int x, int y ) { return ( x < y ) ? y : x; } + +inline REAL +min( REAL x, REAL y ) { return ( x > y ) ? y : x; } + +inline REAL +glu_abs( REAL x ) { return ( x < 0.0 ) ? -x : x; } + +#endif /* __glusimplemath_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/slicer.cc b/src/glu/sgi/libnurbs/internals/slicer.cc new file mode 100644 index 0000000..1b18d73 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/slicer.cc @@ -0,0 +1,1304 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * slicer.c++ + * + */ + +#include +#include +#include +#include "glimports.h" +#include "mystdio.h" +#include "myassert.h" +#include "bufpool.h" +#include "slicer.h" +#include "backend.h" +#include "arc.h" +#include "gridtrimvertex.h" +#include "simplemath.h" +#include "trimvertex.h" +#include "varray.h" + +#include "polyUtil.h" //for area() + +//static int count=0; + +/*USE_OPTTT is initiated in trimvertex.h*/ + +#ifdef USE_OPTTT + #include +#endif + +//#define USE_READ_FLAG //whether to use new or old tesselator + //if defined, it reads "flagFile", + // if the number is 1, then use new tess + // otherwise, use the old tess. + //if not defined, then use new tess. +#ifdef USE_READ_FLAG +static Int read_flag(char* name); +Int newtess_flag = read_flag("flagFile"); +#endif + +//#define COUNT_TRIANGLES +#ifdef COUNT_TRIANGLES +Int num_triangles = 0; +Int num_quads = 0; +#endif + +#define max(a,b) ((a>b)? a:b) +#define ZERO 0.00001 /*determing whether a loop is a rectngle or not*/ +#define equalRect(a,b) ((glu_abs(a-b) <= ZERO)? 1:0) //only used in tessellating a rectangle + +#if 0 // UNUSED +static Int is_Convex(Arc_ptr loop) +{ + if(area(loop->tail(), loop->head(), loop->next->head()) <0 ) + return 0; + for(Arc_ptr jarc = loop->next; jarc != loop; jarc = jarc->next) + { + if(area(jarc->tail(), jarc->head(), jarc->next->head()) < 0) + return 0; + } + return 1; +} +#endif + +/******triangulate a monotone polygon**************/ +#include "monoTriangulation.h" +#if 0 // UNUSED +static int is_U_monotone(Arc_ptr loop) +{ + int n_changes=0; + int prev_sign; + int cur_sign; + Arc_ptr temp; + + cur_sign = compV2InX(loop->head(), loop->tail()); + + n_changes = (compV2InX(loop->prev->head(), loop->prev->tail()) + != cur_sign); + + for(temp=loop->next; temp != loop; temp = temp->next) + { + prev_sign = cur_sign; + cur_sign = compV2InX(temp->head(), temp->tail()); + if(cur_sign != prev_sign) + { +#ifdef DEBUG + printf("***change signe\n"); +#endif + n_changes++; + } + } + if(n_changes == 2) return 1; + else + return 0; +} +#endif + +inline int compInY(REAL a[2], REAL b[2]) +{ + if(a[1] < b[1]) + return -1; + else if (a[1] > b[1]) + return 1; + else if(a[0] > b[0]) + return 1; + else return -1; +} + +void monoTriangulationLoop(Arc_ptr loop, Backend& backend, primStream* pStream) +{ + int i; + //find the top, bottom, increasing and decreasing chain + //then call monoTrianulation + Arc_ptr jarc, temp; + Arc_ptr top; + Arc_ptr bot; + top = bot = loop; + if(compInY(loop->tail(), loop->prev->tail()) < 0) + { + //first find bot + for(temp = loop->next; temp != loop; temp = temp->next) + { + if(compInY(temp->tail(), temp->prev->tail()) > 0) + break; + } + bot = temp->prev; + //then find top + for(temp=loop->prev; temp != loop; temp = temp->prev) + { + if(compInY(temp->tail(), temp->prev->tail()) > 0) + break; + } + top = temp; + } + else //loop > loop->prev + { + for(temp=loop->next; temp != loop; temp = temp->next) + { + if(compInY(temp->tail(), temp->prev->tail()) < 0) + break; + } + top = temp->prev; + for(temp=loop->prev; temp != loop; temp = temp->prev) + { + if(compInY(temp->tail(), temp->prev->tail()) < 0) + break; + } + bot = temp; + } + //creat increase and decrease chains + vertexArray inc_chain(50); //this is a dynamci array + for(i=1; i<=top->pwlArc->npts-2; i++) + { + //the first vertex is the top which doesn't below to inc_chain + inc_chain.appendVertex(top->pwlArc->pts[i].param); + } + for(jarc=top->next; jarc != bot; jarc = jarc->next) + { + for(i=0; i<=jarc->pwlArc->npts-2; i++) + { + inc_chain.appendVertex(jarc->pwlArc->pts[i].param); + } + + } + vertexArray dec_chain(50); + for(jarc = top->prev; jarc != bot; jarc = jarc->prev) + { + for(i=jarc->pwlArc->npts-2; i>=0; i--) + { + dec_chain.appendVertex(jarc->pwlArc->pts[i].param); + } + } + for(i=bot->pwlArc->npts-2; i>=1; i--) + { + dec_chain.appendVertex(jarc->pwlArc->pts[i].param); + } + + monoTriangulationRec(top->tail(), bot->tail(), &inc_chain, 0, + &dec_chain, 0, &backend); + +} + +/********tesselate a rectanlge (OPTIMIZATION**************/ +static void triangulateRectGen(Arc_ptr loop, int n_ulines, int n_vlines, Backend& backend); + +static Int is_rect(Arc_ptr loop) +{ + Int nlines =1; + for(Arc_ptr jarc = loop->next; jarc != loop; jarc = jarc->next) + { + nlines++; + if(nlines == 5) + break; + } + if(nlines != 4) + return 0; + + +/* +printf("here1\n"); +printf("loop->tail=(%f,%f)\n", loop->tail()[0], loop->tail()[1]); +printf("loop->head=(%f,%f)\n", loop->head()[0], loop->head()[1]); +printf("loop->next->tail=(%f,%f)\n", loop->next->tail()[0], loop->next->tail()[1]); +printf("loop->next->head=(%f,%f)\n", loop->next->head()[0], loop->next->head()[1]); +if(fglu_abs(loop->tail()[0] - loop->head()[0])<0.000001) + printf("equal 1\n"); +if(loop->next->tail()[1] == loop->next->head()[1]) + printf("equal 2\n"); +*/ + + if( (glu_abs(loop->tail()[0] - loop->head()[0])<=ZERO) && + (glu_abs(loop->next->tail()[1] - loop->next->head()[1])<=ZERO) && + (glu_abs(loop->prev->tail()[1] - loop->prev->head()[1])<=ZERO) && + (glu_abs(loop->prev->prev->tail()[0] - loop->prev->prev->head()[0])<=ZERO) + ) + return 1; + else if + ( (glu_abs(loop->tail()[1] - loop->head()[1]) <= ZERO) && + (glu_abs(loop->next->tail()[0] - loop->next->head()[0]) <= ZERO) && + (glu_abs(loop->prev->tail()[0] - loop->prev->head()[0]) <= ZERO) && + (glu_abs(loop->prev->prev->tail()[1] - loop->prev->prev->head()[1]) <= ZERO) + ) + return 1; + else + return 0; +} + + +//a line with the same u for opt +#ifdef USE_OPTTT +static void evalLineNOGE_BU(TrimVertex *verts, int n, Backend& backend) +{ + int i; + backend.preEvaluateBU(verts[0].param[0]); + for(i=0; itail()[1] == loop->head()[1]) + { + if(loop->tail()[1] > loop->prev->prev->tail()[1]) + { + + top = loop; + } + else{ + + top = loop->prev->prev; + } + } + else + { + if(loop->tail()[0] > loop->prev->prev->tail()[0]) + { + //loop is the right arc + + top = loop->next; + } + else + { + + top = loop->prev; + } + } + left = top->next; + bot = left->next; + right= bot->next; + + //if u, v are both nonlinear, then if the + //boundary is tessellated dense, we also + //sample the inside to get a better tesslletant. + if( (!ulinear) && (!vlinear)) + { + int nu = top->pwlArc->npts; + if(nu < bot->pwlArc->npts) + nu = bot->pwlArc->npts; + int nv = left->pwlArc->npts; + if(nv < right->pwlArc->npts) + nv = right->pwlArc->npts; +/* + if(nu > 2 && nv > 2) + { + triangulateRectGen(top, nu-2, nv-2, backend); + return; + } +*/ + } + + if(TB_or_LR == 1) + triangulateRectAux(top->pwlArc, bot->pwlArc, left->pwlArc, right->pwlArc, backend); + else if(TB_or_LR == -1) + triangulateRectAux(left->pwlArc, right->pwlArc, bot->pwlArc, top->pwlArc, backend); + else + { + Int maxPointsTB = top->pwlArc->npts + bot->pwlArc->npts; + Int maxPointsLR = left->pwlArc->npts + right->pwlArc->npts; + + if(maxPointsTB < maxPointsLR) + triangulateRectAux(left->pwlArc, right->pwlArc, bot->pwlArc, top->pwlArc, backend); + else + triangulateRectAux(top->pwlArc, bot->pwlArc, left->pwlArc, right->pwlArc, backend); + } +} + +static void triangulateRectAux(PwlArc* top, PwlArc* bot, PwlArc* left, PwlArc* right, Backend& backend) +{ //if(maxPointsTB >= maxPointsLR) + { + + Int d, topd_left, topd_right, botd_left, botd_right, i,j; + d = left->npts /2; + +#ifdef USE_OPTTT + evalLineNOGE(top->pts, top->npts, backend); + evalLineNOGE(bot->pts, bot->npts, backend); + evalLineNOGE(left->pts, left->npts, backend); + evalLineNOGE(right->pts, right->npts, backend); +#endif + + if(top->npts == 2) { + backend.bgntfan(); + OPT_OUTVERT(top->pts[0], backend);//the root + for(i=0; inpts; i++){ + OPT_OUTVERT(left->pts[i], backend); + } + for(i=1; i<= bot->npts-2; i++){ + OPT_OUTVERT(bot->pts[i], backend); + } + backend.endtfan(); + + backend.bgntfan(); + OPT_OUTVERT(bot->pts[bot->npts-2], backend); + for(i=0; inpts; i++){ + OPT_OUTVERT(right->pts[i], backend); + } + backend.endtfan(); + } + else if(bot->npts == 2) { + backend.bgntfan(); + OPT_OUTVERT(bot->pts[0], backend);//the root + for(i=0; inpts; i++){ + OPT_OUTVERT(right->pts[i], backend); + } + for(i=1; i<= top->npts-2; i++){ + OPT_OUTVERT(top->pts[i], backend); + } + backend.endtfan(); + + backend.bgntfan(); + OPT_OUTVERT(top->pts[top->npts-2], backend); + for(i=0; inpts; i++){ + OPT_OUTVERT(left->pts[i], backend); + } + backend.endtfan(); + } + else { //both top and bot have >=3 points + + backend.bgntfan(); + + OPT_OUTVERT(top->pts[top->npts-2], backend); + + for(i=0; i<=d; i++) + { + OPT_OUTVERT(left->pts[i], backend); + } + backend.endtfan(); + + backend.bgntfan(); + + OPT_OUTVERT(bot->pts[1], backend); + + OPT_OUTVERT(top->pts[top->npts-2], backend); + + for(i=d; i< left->npts; i++) + { + OPT_OUTVERT(left->pts[i], backend); + } + backend.endtfan(); + + d = right->npts/2; + //output only when dnpts-1 and + // + if(dnpts-1) + { + backend.bgntfan(); + // backend.tmeshvert(& top->pts[1]); + OPT_OUTVERT(top->pts[1], backend); + for(i=d; i< right->npts; i++) + { + // backend.tmeshvert(& right->pts[i]); + + OPT_OUTVERT(right->pts[i], backend); + + } + backend.endtfan(); + } + + backend.bgntfan(); + // backend.tmeshvert(& bot->pts[bot->npts-2]); + OPT_OUTVERT( bot->pts[bot->npts-2], backend); + for(i=0; i<=d; i++) + { + // backend.tmeshvert(& right->pts[i]); + OPT_OUTVERT(right->pts[i], backend); + + } + + // backend.tmeshvert(& top->pts[1]); + OPT_OUTVERT(top->pts[1], backend); + + backend.endtfan(); + + + topd_left = top->npts-2; + topd_right = 1; //topd_left>= topd_right + + botd_left = 1; + botd_right = bot->npts-2; //botd_left<= bot_dright + + + if(top->npts < bot->npts) + { + int delta=bot->npts - top->npts; + int u = delta/2; + botd_left = 1+ u; + botd_right = bot->npts-2-( delta-u); + + if(botd_left >1) + { + backend.bgntfan(); + // backend.tmeshvert(& top->pts[top->npts-2]); + OPT_OUTVERT(top->pts[top->npts-2], backend); + for(i=1; i<= botd_left; i++) + { + // backend.tmeshvert(& bot->pts[i]); + OPT_OUTVERT(bot->pts[i] , backend); + } + backend.endtfan(); + } + if(botd_right < bot->npts-2) + { + backend.bgntfan(); + OPT_OUTVERT(top->pts[1], backend); + for(i=botd_right; i<= bot->npts-2; i++) + OPT_OUTVERT(bot->pts[i], backend); + backend.endtfan(); + } + } + else if(top->npts> bot->npts) + { + int delta=top->npts-bot->npts; + int u = delta/2; + topd_left = top->npts-2 - u; + topd_right = 1+delta-u; + + if(topd_left < top->npts-2) + { + backend.bgntfan(); + // backend.tmeshvert(& bot->pts[1]); + OPT_OUTVERT(bot->pts[1], backend); + for(i=topd_left; i<= top->npts-2; i++) + { + // backend.tmeshvert(& top->pts[i]); + OPT_OUTVERT(top->pts[i], backend); + } + backend.endtfan(); + } + if(topd_right > 1) + { + backend.bgntfan(); + OPT_OUTVERT(bot->pts[bot->npts-2], backend); + for(i=1; i<= topd_right; i++) + OPT_OUTVERT(top->pts[i], backend); + backend.endtfan(); + } + } + + if(topd_left <= topd_right) + return; + + backend.bgnqstrip(); + for(j=botd_left, i=topd_left; i>=topd_right; i--,j++) + { + // backend.tmeshvert(& top->pts[i]); + // backend.tmeshvert(& bot->pts[j]); + OPT_OUTVERT(top->pts[i], backend); + OPT_OUTVERT(bot->pts[j], backend); + } + backend.endqstrip(); + + } + } +} + + +static void triangulateRectCenter(int n_ulines, REAL* u_val, + int n_vlines, REAL* v_val, + Backend& backend) +{ + + // XXX this code was patched by Diego Santa Cruz + // to fix a problem in which glMapGrid2f() was called with bad parameters. + // This has beens submitted to SGI but not integrated as of May 1, 2001. + if(n_ulines>1 && n_vlines>1) { + backend.surfgrid(u_val[0], u_val[n_ulines-1], n_ulines-1, + v_val[n_vlines-1], v_val[0], n_vlines-1); + backend.surfmesh(0,0,n_ulines-1,n_vlines-1); + } + + return; + + /* + for(i=0; ipwlArc->npts); + assert(upper_val); + if(dir) + { + for(k=0,i=arc->pwlArc->npts-1; i>=0; i--,k++) + { + upper_val[k] = arc->pwlArc->pts[i].param[0]; + } + backend.evalUStrip(arc->pwlArc->npts, arc->pwlArc->pts[0].param[1], + upper_val, + n_ulines, v, u_val); + } + else + { + for(k=0,i=0; ipwlArc->npts; i++,k++) + { + upper_val[k] = arc->pwlArc->pts[i].param[0]; + + } + + backend.evalUStrip( + n_ulines, v, u_val, + arc->pwlArc->npts, arc->pwlArc->pts[0].param[1], upper_val + ); + } + + free(upper_val); + return; + } + else //is_v + { + int i,k; + REAL* left_val = (REAL*) malloc(sizeof(REAL) * arc->pwlArc->npts); + assert(left_val); + if(dir) + { + for(k=0,i=arc->pwlArc->npts-1; i>=0; i--,k++) + { + left_val[k] = arc->pwlArc->pts[i].param[1]; + } + backend.evalVStrip(arc->pwlArc->npts, arc->pwlArc->pts[0].param[0], + left_val, + n_ulines, v, u_val); + } + else + { + for(k=0,i=0; ipwlArc->npts; i++,k++) + { + left_val[k] = arc->pwlArc->pts[i].param[1]; + } + backend.evalVStrip( + n_ulines, v, u_val, + arc->pwlArc->npts, arc->pwlArc->pts[0].param[0], left_val + ); + } + free(left_val); + return; + } + + //the following is a different version of the above code. If you comment + //the above code, the following code will still work. The reason to leave + //the folliwng code here is purely for testing purpose. + /* + int i,j; + PwlArc* parc = arc->pwlArc; + int d1 = parc->npts-1; + int d2 = 0; + TrimVertex trimVert; + trimVert.nuid = 0;//???? + REAL* temp_u_val = u_val; + if(dir ==0) //have to reverse u_val + { + temp_u_val = (REAL*) malloc(sizeof(REAL) * n_ulines); + assert(temp_u_val); + for(i=0; inpts > n_ulines) + { + d1 = n_ulines-1; + + backend.bgntfan(); + if(is_u){ + trimVert.param[0] = u_val[0]; + trimVert.param[1] = v; + } + else + { + trimVert.param[1] = u_val[0]; + trimVert.param[0] = v; + } + + backend.tmeshvert(& trimVert); + for(i=d1; i< parc->npts; i++) + backend.tmeshvert(& parc->pts[i]); + backend.endtfan(); + + + } + else if(parc->npts < n_ulines) + { + d2 = n_ulines-parc->npts; + + + backend.bgntfan(); + backend.tmeshvert(& parc->pts[parc->npts-1]); + for(i=0; i<= d2; i++) + { + if(is_u){ + trimVert.param[0] = u_val[i]; + trimVert.param[1] = v; + } + else + { + trimVert.param[1] = u_val[i]; + trimVert.param[0] = v; + } + backend.tmeshvert(&trimVert); + } + backend.endtfan(); + + } + if(d1>0){ + + + backend.bgnqstrip(); + for(i=d1, j=d2; i>=0; i--, j++) + { + backend.tmeshvert(& parc->pts[i]); + + if(is_u){ + trimVert.param[0] = u_val[j]; + trimVert.param[1] = v; + } + else{ + trimVert.param[1] = u_val[j]; + trimVert.param[0] = v; + } + backend.tmeshvert(&trimVert); + + + + } + backend.endqstrip(); + + + } + if(dir == 0) //temp_u_val was mallocated + free(temp_u_val); + */ +} + +//n_ulines is the number of ulines inside, and n_vlines is the number of vlines +//inside, different from meanings elsewhere!!! +static void triangulateRectGen(Arc_ptr loop, int n_ulines, int n_vlines, Backend& backend) +{ + + int i; + //we know the loop is a rectangle, but not sure which is top + Arc_ptr top, bot, left, right; + + if(equalRect(loop->tail()[1] , loop->head()[1])) + { + + if(loop->tail()[1] > loop->prev->prev->tail()[1]) + { + + top = loop; + } + else{ + + top = loop->prev->prev; + } + } + else + { + if(loop->tail()[0] > loop->prev->prev->tail()[0]) + { + //loop is the right arc + + top = loop->next; + } + else + { + + top = loop->prev; + } + } + + left = top->next; + bot = left->next; + right= bot->next; + +#ifdef COUNT_TRIANGLES + num_triangles += loop->pwlArc->npts + + left->pwlArc->npts + + bot->pwlArc->npts + + right->pwlArc->npts + + 2*n_ulines + 2*n_vlines + -8; + num_quads += (n_ulines-1)*(n_vlines-1); +#endif +/* + backend.surfgrid(left->tail()[0], right->tail()[0], n_ulines+1, + top->tail()[1], bot->tail()[1], n_vlines+1); +// if(n_ulines>1 && n_vlines>1) + backend.surfmesh(0,0,n_ulines+1,n_vlines+1); +return; +*/ + REAL* u_val=(REAL*) malloc(sizeof(REAL)*n_ulines); + assert(u_val); + REAL* v_val=(REAL*)malloc(sizeof(REAL) * n_vlines); + assert(v_val); + REAL u_stepsize = (right->tail()[0] - left->tail()[0])/( (REAL) n_ulines+1); + REAL v_stepsize = (top->tail()[1] - bot->tail()[1])/( (REAL) n_vlines+1); + Real temp=left->tail()[0]+u_stepsize; + for(i=0; itail()[1] + v_stepsize; + for(i=0; ipwlArc->npts); + for(i=0; ipwlArc->npts; i++) + { + vert[0] = arc->pwlArc->pts[i].param[0]; + vert[1] = arc->pwlArc->pts[i].param[1]; + sline->setPoint(i, vert); + } + ret = new directedLine(INCREASING, sline); + return ret; +} + +/*an pwlArc may not be a straight line*/ +directedLine* arcToMultDLines(directedLine* original, Arc_ptr arc) +{ + directedLine* ret = original; + int is_linear = 0; + if(arc->pwlArc->npts == 2 ) + is_linear = 1; + else if(area(arc->pwlArc->pts[0].param, arc->pwlArc->pts[1].param, arc->pwlArc->pts[arc->pwlArc->npts-1].param) == 0.0) + is_linear = 1; + + if(is_linear) + { + directedLine *dline = arcToDLine(arc); + if(ret == NULL) + ret = dline; + else + ret->insert(dline); + return ret; + } + else /*not linear*/ + { + for(Int i=0; ipwlArc->npts-1; i++) + { + Real vert[2][2]; + vert[0][0] = arc->pwlArc->pts[i].param[0]; + vert[0][1] = arc->pwlArc->pts[i].param[1]; + vert[1][0] = arc->pwlArc->pts[i+1].param[0]; + vert[1][1] = arc->pwlArc->pts[i+1].param[1]; + + sampledLine *sline = new sampledLine(2, vert); + directedLine *dline = new directedLine(INCREASING, sline); + if(ret == NULL) + ret = dline; + else + ret->insert(dline); + } + return ret; + } +} + + + +directedLine* arcLoopToDLineLoop(Arc_ptr loop) +{ + directedLine* ret; + + if(loop == NULL) + return NULL; + ret = arcToMultDLines(NULL, loop); +//ret->printSingle(); + for(Arc_ptr temp = loop->next; temp != loop; temp = temp->next){ + ret = arcToMultDLines(ret, temp); +//ret->printSingle(); + } + + return ret; +} + +/* +void Slicer::evalRBArray(rectBlockArray* rbArray, gridWrap* grid) +{ + TrimVertex *trimVert = (TrimVertex*)malloc(sizeof(TrimVertex)); + trimVert -> nuid = 0;//???? + + Real* u_values = grid->get_u_values(); + Real* v_values = grid->get_v_values(); + + Int i,j,k,l; + + for(l=0; lget_n_elements(); l++) + { + rectBlock* block = rbArray->get_element(l); + for(k=0, i=block->get_upGridLineIndex(); i>block->get_lowGridLineIndex(); i--, k++) + { + + backend.bgnqstrip(); + for(j=block->get_leftIndices()[k+1]; j<= block->get_rightIndices()[k+1]; j++) + { + trimVert->param[0] = u_values[j]; + trimVert->param[1] = v_values[i]; + backend.tmeshvert(trimVert); + + trimVert->param[1] = v_values[i-1]; + backend.tmeshvert(trimVert); + + } + backend.endqstrip(); + + } + } + + free(trimVert); +} +*/ + +void Slicer::evalRBArray(rectBlockArray* rbArray, gridWrap* grid) +{ + Int i,j,k; + + Int n_vlines=grid->get_n_vlines(); + //the reason to switch the position of v_max and v_min is because of the + //the orientation problem. glEvalMesh generates quad_strip clockwise, but + //we need counter-clockwise. + backend.surfgrid(grid->get_u_min(), grid->get_u_max(), grid->get_n_ulines()-1, + grid->get_v_max(), grid->get_v_min(), n_vlines-1); + + + for(j=0; jget_n_elements(); j++) + { + rectBlock* block = rbArray->get_element(j); + Int low = block->get_lowGridLineIndex(); + Int high = block->get_upGridLineIndex(); + + for(k=0, i=high; i>low; i--, k++) + { + backend.surfmesh(block->get_leftIndices()[k+1], n_vlines-1-i, block->get_rightIndices()[k+1]-block->get_leftIndices()[k+1], 1); + } + } +} + + +void Slicer::evalStream(primStream* pStream) +{ + Int i,j,k; + k=0; +/* TrimVertex X;*/ + TrimVertex *trimVert =/*&X*/ (TrimVertex*)malloc(sizeof(TrimVertex)); + trimVert -> nuid = 0;//??? + Real* vertices = pStream->get_vertices(); //for efficiency + for(i=0; iget_n_prims(); i++) + { + + //ith primitive has #vertices = lengths[i], type=types[i] + switch(pStream->get_type(i)){ + case PRIMITIVE_STREAM_FAN: + + backend.bgntfan(); + + for(j=0; jget_length(i); j++) + { + trimVert->param[0] = vertices[k]; + trimVert->param[1] = vertices[k+1]; + backend.tmeshvert(trimVert); + +// backend.tmeshvert(vertices[k], vertices[k+1]); + k += 2; + } + backend.endtfan(); + break; + + default: + fprintf(stderr, "evalStream: not implemented yet\n"); + exit(1); + + } + } + free(trimVert); +} + + + + +void Slicer::slice_new(Arc_ptr loop) +{ +//count++; +//if(count == 78) count=1; +//printf("count=%i\n", count); +//if( ! (4<= count && count <=4)) return; + + + Int num_ulines; + Int num_vlines; + Real uMin, uMax, vMin, vMax; + Real mydu, mydv; + uMin = uMax = loop->tail()[0]; + vMin = vMax = loop->tail()[1]; + mydu = (du>0)? du: -du; + mydv = (dv>0)? dv: -dv; + + for(Arc_ptr jarc=loop->next; jarc != loop; jarc = jarc->next) + { + + if(jarc->tail()[0] < uMin) + uMin = jarc->tail()[0]; + if(jarc->tail()[0] > uMax) + uMax = jarc->tail()[0]; + if(jarc->tail()[1] < vMin) + vMin = jarc->tail()[1]; + if(jarc->tail()[1] > vMax) + vMax = jarc->tail()[1]; + } + + if (uMax == uMin) + return; // prevent divide-by-zero. Jon Perry. 17 June 2002 + + if(mydu > uMax - uMin) + num_ulines = 2; + else + { + num_ulines = 3 + (Int) ((uMax-uMin)/mydu); + } + if(mydv>=vMax-vMin) + num_vlines = 2; + else + { + num_vlines = 2+(Int)((vMax-vMin)/mydv); + } + + Int isRect = is_rect(loop); + + if(isRect && (num_ulines<=2 || num_vlines<=2)) + { + if(vlinear) + triangulateRect(loop, backend, 1, ulinear, vlinear); + else if(ulinear) + triangulateRect(loop, backend, -1, ulinear, vlinear); + else + triangulateRect(loop, backend, 0, ulinear, vlinear); + } + + else if(isRect) + { + triangulateRectGen(loop, num_ulines-2, num_vlines-2, backend); + } + else if( (num_ulines<=2 || num_vlines <=2) && ulinear) + { + monoTriangulationFunBackend(loop, compV2InY, &backend); + } + else if( (!ulinear) && (!vlinear) && (num_ulines == 2) && (num_vlines > 2)) + { + monoTriangulationFunBackend(loop, compV2InY, &backend); + } + else + { + directedLine* poly = arcLoopToDLineLoop(loop); + + gridWrap grid(num_ulines, num_vlines, uMin, uMax, vMin, vMax); + primStream pStream(20, 20); + rectBlockArray rbArray(20); + + sampleMonoPoly(poly, &grid, ulinear, vlinear, &pStream, &rbArray); + + evalStream(&pStream); + + evalRBArray(&rbArray, &grid); + +#ifdef COUNT_TRIANGLES + num_triangles += pStream.num_triangles(); + num_quads += rbArray.num_quads(); +#endif + poly->deleteSinglePolygonWithSline(); + } + +#ifdef COUNT_TRIANGLES + printf("num_triangles=%i\n", num_triangles); + printf("num_quads = %i\n", num_quads); +#endif +} + +void Slicer::slice(Arc_ptr loop) +{ +#ifdef USE_READ_FLAG + if(read_flag("flagFile")) + slice_new(loop); + else + slice_old(loop); + +#else + slice_new(loop); +#endif + +} + + + +Slicer::Slicer( Backend &b ) + : CoveAndTiler( b ), Mesher( b ), backend( b ) +{ + oneOverDu = 0; + du = 0; + dv = 0; + isolines = 0; + ulinear = 0; + vlinear = 0; +} + +Slicer::~Slicer() +{ +} + +void +Slicer::setisolines( int x ) +{ + isolines = x; +} + +void +Slicer::setstriptessellation( REAL x, REAL y ) +{ + assert(x > 0 && y > 0); + du = x; + dv = y; + setDu( du ); +} + +void +Slicer::slice_old( Arc_ptr loop ) +{ + loop->markverts(); + + Arc_ptr extrema[4]; + loop->getextrema( extrema ); + + unsigned int npts = loop->numpts(); + TrimRegion::init( npts, extrema[0] ); + + Mesher::init( npts ); + + long ulines = uarray.init( du, extrema[1], extrema[3] ); +//printf("ulines = %i\n", ulines); + Varray varray; + long vlines = varray.init( dv, extrema[0], extrema[2] ); +//printf("vlines = %i\n", vlines); + long botv = 0; + long topv; + TrimRegion::init( varray.varray[botv] ); + getGridExtent( &extrema[0]->pwlArc->pts[0], &extrema[0]->pwlArc->pts[0] ); + + for( long quad=0; quadmarkverts(); + + if( jarc->pwlArc->npts >= 2 ) { + backend.bgnoutline(); + for( int j = jarc->pwlArc->npts-1; j >= 0; j-- ) + backend.linevert( &(jarc->pwlArc->pts[j]) ); + backend.endoutline(); + } +} + + diff --git a/src/glu/sgi/libnurbs/internals/slicer.h b/src/glu/sgi/libnurbs/internals/slicer.h new file mode 100644 index 0000000..e1f5d22 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/slicer.h @@ -0,0 +1,84 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * slicer.h + * + */ + +#ifndef __gluslicer_h_ +#define __gluslicer_h_ + +#include "trimregion.h" +#include "mesher.h" +#include "coveandtiler.h" +#include "primitiveStream.h" +#include "rectBlock.h" + +class Backend; +class Arc; +class TrimVertex; + +class Slicer : public CoveAndTiler, public Mesher { +public: + Slicer( Backend & ); + ~Slicer( void ); + void slice( Arc_ptr ); + void slice_old( Arc_ptr); + void slice_new( Arc_ptr ); + void evalStream(primStream* ); + void evalRBArray(rectBlockArray* rbArray, gridWrap* grid); + + void outline( Arc_ptr ); + void setstriptessellation( REAL, REAL ); + void setisolines( int ); + + void set_ulinear(int ulinear_flag) + { + ulinear = ulinear_flag; + } + void set_vlinear(int vlinear_flag) + { + vlinear = vlinear_flag; + } +private: + Backend& backend; + REAL oneOverDu; + REAL du, dv; + int isolines; + + void outline( void ); + void initGridlines( void ); + void advanceGridlines( long ); + + int ulinear; //indicate whether uorder is 2 or not + int vlinear; //indicate whether vorder is 2 or not +}; +#endif /* __gluslicer_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/sorter.cc b/src/glu/sgi/libnurbs/internals/sorter.cc new file mode 100644 index 0000000..7a79941 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/sorter.cc @@ -0,0 +1,139 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * sorter.c++ + * + */ + +#include "glimports.h" +#include "sorter.h" +#include "mystdio.h" + +Sorter::Sorter( int _es ) +{ + es = _es; +} + +void +Sorter::qsort( void *a, int n ) +{ + qs1( (char *)a, ((char *)a)+n*es); +} + +int +Sorter::qscmp( char *, char * ) +{ + _glu_dprintf( "Sorter::qscmp: pure virtual called\n" ); + return 0; +} + + +void +Sorter::qsexc( char *, char * ) +{ + _glu_dprintf( "Sorter::qsexc: pure virtual called\n" ); +} + + +void +Sorter::qstexc( char *, char *, char * ) +{ + _glu_dprintf( "Sorter::qstexc: pure virtual called\n" ); +} + +void +Sorter::qs1( char *a, char *l ) +{ + char *i, *j; + char *lp, *hp; + int c; + unsigned int n; + +start: + if((n=l-a) <= (unsigned int)es) + return; + n = es * (n / (2*es)); + hp = lp = a+n; + i = a; + j = l-es; + while(1) { + if(i < lp) { + if((c = qscmp(i, lp)) == 0) { + qsexc(i, lp -= es); + continue; + } + if(c < 0) { + i += es; + continue; + } + } + +loop: + if(j > hp) { + if((c = qscmp(hp, j)) == 0) { + qsexc(hp += es, j); + goto loop; + } + if(c > 0) { + if(i == lp) { + qstexc(i, hp += es, j); + i = lp += es; + goto loop; + } + qsexc(i, j); + j -= es; + i += es; + continue; + } + j -= es; + goto loop; + } + + if(i == lp) { + if(lp-a >= l-hp) { + qs1(hp+es, l); + l = lp; + } else { + qs1(a, lp); + a = hp+es; + } + goto start; + } + + qstexc(j, lp -= es, i); + j = hp -= es; + } +} + diff --git a/src/glu/sgi/libnurbs/internals/sorter.h b/src/glu/sgi/libnurbs/internals/sorter.h new file mode 100644 index 0000000..57ea121 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/sorter.h @@ -0,0 +1,51 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef __glusorter_h_ +#define __glusorter_h_ + +class Sorter { +public: + Sorter( int es ); + virtual ~Sorter() { /* silence warning*/ } + void qsort( void *a, int n ); + +protected: + virtual int qscmp( char *, char * ); + virtual void qsexc( char *i, char *j ); // i<-j, j<-i + virtual void qstexc( char *i, char *j, char *k ); // i<-k, k<-j, j<-i + +private: + void qs1( char *, char * ); + int es; +}; +#endif /* __glusorter_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/splitarcs.cc b/src/glu/sgi/libnurbs/internals/splitarcs.cc new file mode 100644 index 0000000..1f79d54 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/splitarcs.cc @@ -0,0 +1,293 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * splitarcs.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mysetjmp.h" +#include "mystdio.h" +#include "subdivider.h" +#include "arcsorter.h" +#include "arc.h" +#include "bin.h" + +/* local preprocessor definitions */ +#define MAXARCS 10 + +/*---------------------------------------------------------------------------- + * Subdivider::split - split trim regions in source bin by line (param == value). + *---------------------------------------------------------------------------- + */ + +void +Subdivider::split( Bin& bin, Bin& left, Bin& right, int param, REAL value ) +{ + Bin intersections, unknown; + + partition( bin, left, intersections, right, unknown, param, value ); + + int count = intersections.numarcs(); + if( count % 2 ) { +#ifndef NDEBUG + left.show( "left" ); + intersections.show( "intersections" ); + right.show( "right" ); +#endif + ::mylongjmp( jumpbuffer, 29 ); + } + + Arc_ptr arclist[MAXARCS], *list; + if( count >= MAXARCS ) { + list = new Arc_ptr[count]; + } else { + list = arclist; + } + + Arc_ptr jarc, *last, *lptr; + for( last = list; (jarc=intersections.removearc()) != NULL; last++ ) + *last = jarc; + + if( param == 0 ) { /* sort into increasing t order */ + ArcSdirSorter sorter(*this); + sorter.qsort( list, count ); + + //::qsort ((void *)list, count, sizeof(Arc_ptr), (cmpfunc)compare_s); + for( lptr=list; lptrhead()[0] <= value) && ((*lptr)->tail()[0] <= value) ) + left.addarc( *lptr ); + else + right.addarc( *lptr ); + } + } else { /* sort into decreasing s order */ + ArcTdirSorter sorter(*this); + sorter.qsort( list, count ); + //::qsort ((void *)list, count, sizeof(Arc_ptr), (cmpfunc)compare_t); + for( lptr=list; lptrhead()[1] <= value) && ((*lptr)->tail()[1] <= value) ) + left.addarc( *lptr ); + else + right.addarc( *lptr ); + } + } + + if( list != arclist ) delete[] list; + unknown.adopt(); +} + + +void +Subdivider::check_s( Arc_ptr jarc1, Arc_ptr jarc2 ) +{ + assert( jarc1->check( ) != 0 ); + assert( jarc2->check( ) != 0 ); + assert( jarc1->next->check( ) != 0 ); + assert( jarc2->next->check( ) != 0 ); + assert( jarc1 != jarc2 ); + + /* XXX - if these assertions fail, it is due to user error or + undersampling */ + if( ! ( jarc1->tail()[0] < (jarc1)->head()[0] ) ) { +#ifndef NDEBUG + _glu_dprintf( "s difference %f\n", (jarc1)->tail()[0] - (jarc1)->head()[0] ); +#endif + ::mylongjmp( jumpbuffer, 28 ); + } + + if( ! ( jarc2->tail()[0] > (jarc2)->head()[0] ) ) { +#ifndef NDEBUG + _glu_dprintf( "s difference %f\n", (jarc2)->tail()[0] - (jarc2)->head()[0] ); +#endif + ::mylongjmp( jumpbuffer, 28 ); + } +} + +inline void +Subdivider::link( Arc_ptr jarc1, Arc_ptr jarc2, Arc_ptr up, Arc_ptr down ) +{ + up->nuid = down->nuid = 0; // XXX + + up->next = jarc2; + down->next = jarc1; + up->prev = jarc1->prev; + down->prev = jarc2->prev; + + down->next->prev = down; + up->next->prev = up; + down->prev->next = down; + up->prev->next = up; +} + +inline void +Subdivider::simple_link( Arc_ptr jarc1, Arc_ptr jarc2 ) +{ + Arc_ptr tmp = jarc2->prev; + jarc2->prev = jarc1->prev; + jarc1->prev = tmp; + jarc2->prev->next = jarc2; + jarc1->prev->next = jarc1; +} + + +/*---------------------------------------------------------------------------- + * join - add a pair of oppositely directed jordan arcs between two arcs + *---------------------------------------------------------------------------- + */ + +void +Subdivider::join_s( Bin& left, Bin& right, Arc_ptr jarc1, Arc_ptr jarc2 ) +{ + assert( jarc1->check( ) != 0); + assert( jarc2->check( ) != 0); + assert( jarc1 != jarc2 ); + + if( ! jarc1->getitail() ) + jarc1 = jarc1->next; + + if( ! jarc2->getitail() ) + jarc2 = jarc2->next; + + REAL s = jarc1->tail()[0]; + REAL t1 = jarc1->tail()[1]; + REAL t2 = jarc2->tail()[1]; + + if( t1 == t2 ) { + simple_link( jarc1, jarc2 ); + } else { + Arc_ptr newright = new(arcpool) Arc( arc_right, 0 ); + Arc_ptr newleft = new(arcpool) Arc( arc_left, 0 ); + assert( t1 < t2 ); + if( isBezierArcType() ) { + arctessellator.bezier( newright, s, s, t1, t2 ); + arctessellator.bezier( newleft, s, s, t2, t1 ); + } else { + arctessellator.pwl_right( newright, s, t1, t2, stepsizes[0] ); + arctessellator.pwl_left( newleft, s, t2, t1, stepsizes[2] ); + } + link( jarc1, jarc2, newright, newleft ); + left.addarc( newright ); + right.addarc( newleft ); + } + + assert( jarc1->check( ) != 0 ); + assert( jarc2->check( ) != 0 ); + assert( jarc1->next->check( ) != 0); + assert( jarc2->next->check( ) != 0); +} + +void +Subdivider::check_t( Arc_ptr jarc1, Arc_ptr jarc2 ) +{ + assert( jarc1->check( ) != 0 ); + assert( jarc2->check( ) != 0 ); + assert( jarc1->next->check( ) != 0 ); + assert( jarc2->next->check( ) != 0 ); + assert( jarc1 != jarc2 ); + + /* XXX - if these assertions fail, it is due to user error or + undersampling */ + if( ! ( jarc1->tail()[1] < (jarc1)->head()[1] ) ) { +#ifndef NDEBUG + _glu_dprintf( "t difference %f\n", jarc1->tail()[1] - (jarc1)->head()[1] ); +#endif + ::mylongjmp( jumpbuffer, 28 ); + } + + if( ! ( jarc2->tail()[1] > (jarc2)->head()[1] ) ) { +#ifndef NDEBUG + _glu_dprintf( "t difference %f\n", jarc2->tail()[1] - (jarc2)->head()[1] ); +#endif + ::mylongjmp( jumpbuffer, 28 ); + } +} + +/*---------------------------------------------------------------------------- + * join_t - add a pair of oppositely directed jordan arcs between two arcs + *---------------------------------------------------------------------------- + */ + +void +Subdivider::join_t( Bin& bottom, Bin& top, Arc_ptr jarc1, Arc_ptr jarc2 ) +{ + assert( jarc1->check( ) != 0 ); + assert( jarc2->check( ) != 0 ); + assert( jarc1->next->check( ) != 0 ); + assert( jarc2->next->check( ) != 0 ); + assert( jarc1 != jarc2 ); + + if( ! jarc1->getitail() ) + jarc1 = jarc1->next; + + if( ! jarc2->getitail() ) + jarc2 = jarc2->next; + + REAL s1 = jarc1->tail()[0]; + REAL s2 = jarc2->tail()[0]; + REAL t = jarc1->tail()[1]; + + if( s1 == s2 ) { + simple_link( jarc1, jarc2 ); + } else { + Arc_ptr newtop = new(arcpool) Arc( arc_top, 0 ); + Arc_ptr newbot = new(arcpool) Arc( arc_bottom, 0 ); + assert( s1 > s2 ); + if( isBezierArcType() ) { + arctessellator.bezier( newtop, s1, s2, t, t ); + arctessellator.bezier( newbot, s2, s1, t, t ); + } else { + arctessellator.pwl_top( newtop, t, s1, s2, stepsizes[1] ); + arctessellator.pwl_bottom( newbot, t, s2, s1, stepsizes[3] ); + } + link( jarc1, jarc2, newtop, newbot ); + bottom.addarc( newtop ); + top.addarc( newbot ); + } + + assert( jarc1->check( ) != 0 ); + assert( jarc2->check( ) != 0 ); + assert( jarc1->next->check( ) != 0 ); + assert( jarc2->next->check( ) != 0 ); +} + diff --git a/src/glu/sgi/libnurbs/internals/subdivider.cc b/src/glu/sgi/libnurbs/internals/subdivider.cc new file mode 100644 index 0000000..ccddc27 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/subdivider.cc @@ -0,0 +1,912 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * subdivider.cxx + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "subdivider.h" +#include "arc.h" +#include "bezierarc.h" +#include "bin.h" +#include "renderhints.h" +#include "backend.h" +#include "mapdesc.h" +#include "quilt.h" +#include "patchlist.h" +#include "patch.h" +#include "nurbsconsts.h" +#include "trimvertpool.h" +#include "simplemath.h" + +#include "polyUtil.h" //for function area() + +//#define PARTITION_TEST +#ifdef PARTITION_TEST +#include "partitionY.h" +#include "monoTriangulation.h" +#include "dataTransform.h" +#include "monoChain.h" + +#endif + + +#define OPTIMIZE_UNTRIMED_CASE + + +Bin* +Subdivider::makePatchBoundary( const REAL *from, const REAL *to ) +{ + Bin* ret = new Bin(); + REAL smin = from[0]; + REAL smax = to[0]; + REAL tmin = from[1]; + REAL tmax = to[1]; + + pjarc = 0; + + Arc_ptr jarc = new(arcpool) Arc( arc_bottom, 0 ); + arctessellator.bezier( jarc, smin, smax, tmin, tmin ); + ret->addarc( jarc ); + pjarc = jarc->append( pjarc ); + + jarc = new(arcpool) Arc( arc_right, 0 ); + arctessellator.bezier( jarc, smax, smax, tmin, tmax ); + ret->addarc( jarc ); + pjarc = jarc->append( pjarc ); + + jarc = new(arcpool) Arc( arc_top, 0 ); + arctessellator.bezier( jarc, smax, smin, tmax, tmax ); + ret->addarc( jarc ); + pjarc = jarc->append( pjarc ); + + jarc = new(arcpool) Arc( arc_left, 0 ); + arctessellator.bezier( jarc, smin, smin, tmax, tmin ); + ret->addarc( jarc ); + jarc->append( pjarc ); + + assert( jarc->check() != 0 ); + return ret; +} + +/*--------------------------------------------------------------------------- + * Subdivider - construct a subdivider + *--------------------------------------------------------------------------- + */ + +Subdivider::Subdivider( Renderhints& r, Backend& b ) + : slicer( b ), + arctessellator( trimvertexpool, pwlarcpool ), + arcpool( sizeof( Arc), 1, "arcpool" ), + bezierarcpool( sizeof( BezierArc ), 1, "Bezarcpool" ), + pwlarcpool( sizeof( PwlArc ), 1, "Pwlarcpool" ), + renderhints( r ), + backend( b ) +{ +} + +void +Subdivider::setJumpbuffer( JumpBuffer *j ) +{ + jumpbuffer = j; +} + +/*--------------------------------------------------------------------------- + * clear - reset all state after possible error condition + *--------------------------------------------------------------------------- + */ + +void +Subdivider::clear( void ) +{ + trimvertexpool.clear(); + arcpool.clear(); + pwlarcpool.clear(); + bezierarcpool.clear(); +} + +/*--------------------------------------------------------------------------- + * ~Subdivider - destroy a subdivider + *--------------------------------------------------------------------------- + */ + +Subdivider::~Subdivider( void ) +{ +} + +/*--------------------------------------------------------------------------- + * addArc - add a bezier arc to a trim loop and to a bin + *--------------------------------------------------------------------------- + */ +void +Subdivider::addArc( REAL *cpts, Quilt *quilt, long _nuid ) +{ + BezierArc *bezierArc = new(bezierarcpool) BezierArc; + Arc *jarc = new(arcpool) Arc( arc_none, _nuid ); + jarc->pwlArc = 0; + jarc->bezierArc = bezierArc; + bezierArc->order = quilt->qspec->order; + bezierArc->stride = quilt->qspec->stride; + bezierArc->mapdesc = quilt->mapdesc; + bezierArc->cpts = cpts; + initialbin.addarc( jarc ); + pjarc = jarc->append( pjarc ); +} + +/*--------------------------------------------------------------------------- + * addArc - add a pwl arc to a trim loop and to a bin + *--------------------------------------------------------------------------- + */ + +void +Subdivider::addArc( int npts, TrimVertex *pts, long _nuid ) +{ + Arc *jarc = new(arcpool) Arc( arc_none, _nuid ); + jarc->pwlArc = new(pwlarcpool) PwlArc( npts, pts ); + initialbin.addarc( jarc ); + pjarc = jarc->append( pjarc ); +} + +void +Subdivider::beginQuilts( void ) +{ + qlist = 0; +} + +void +Subdivider::addQuilt( Quilt *quilt ) +{ + quilt->next = qlist; + qlist = quilt; +} + +/*--------------------------------------------------------------------------- + * drawSurfaces - main entry point for surface tessellation + *--------------------------------------------------------------------------- + */ + +void +Subdivider::drawSurfaces( long nuid ) +{ + renderhints.init( ); + + if (qlist == NULL) + { + //initialbin could be nonempty due to some errors + freejarcs(initialbin); + return; + } + + for( Quilt *q = qlist; q; q = q->next ) { + if( q->isCulled( ) == CULL_TRIVIAL_REJECT ) { + freejarcs( initialbin ); + return; + } + } + + + REAL from[2], to[2]; + qlist->getRange( from, to, spbrkpts, tpbrkpts ); +#ifdef OPTIMIZE_UNTRIMED_CASE + //perform optimization only when the samplng method is + //DOMAIN_DISTANCE and the display methdo is either + //fill or outline_polygon. + int optimize = (is_domain_distance_sampling && (renderhints.display_method != N_OUTLINE_PATCH)); +#endif + + if( ! initialbin.isnonempty() ) { +#ifdef OPTIMIZE_UNTRIMED_CASE + if(! optimize ) + { + + makeBorderTrim( from, to ); + } +#else + makeBorderTrim( from, to ); +#endif + } else { + REAL rate[2]; + qlist->findRates( spbrkpts, tpbrkpts, rate ); + + if( decompose( initialbin, min(rate[0], rate[1]) ) ) + mylongjmp( jumpbuffer, 31 ); + } + + backend.bgnsurf( renderhints.wiretris, renderhints.wirequads, nuid ); + +#ifdef PARTITION_TEST + if( initialbin.isnonempty() && spbrkpts.end-2 == spbrkpts.start && + tpbrkpts.end-2 == tpbrkpts.start) +{ + for(int i=spbrkpts.start; idownloadAll(pta, ptb, backend); + + directedLine *poly; + + { + + poly = bin_to_DLineLoops(initialbin); + + poly=poly->deleteDegenerateLinesAllPolygons(); + + sampledLine* retSampledLines; +//printf("before MC_partition\n"); + poly = MC_partitionY(poly, &retSampledLines); +//printf("after MC_partition\n"); + + } + + + { + primStream pStream(5000,5000); + directedLine* temp; + + for(temp=poly; temp != NULL; temp=temp->getNextPolygon()) + + monoTriangulation(temp, &pStream); + + slicer.evalStream(&pStream); + + } + //need to clean up space + } + } + freejarcs( initialbin ); + backend.endsurf(); + return; + + /* + printf("num_polygons=%i\n", poly->numPolygons()); + printf("num_edges=%i\n", poly->numEdgesAllPolygons()); + poly->writeAllPolygons("zloutputFile"); + return; + { + primStream pStream(20,20); + for(directedLine* tempD = poly; tempD != NULL; tempD = tempD->getNextPolygon()) + monoTriangulation(tempD, &pStream); + } + return; + */ +} +#endif //PARTITION_TEST + + +#ifdef OPTIMIZE_UNTRIMED_CASE + if( (!initialbin.isnonempty()) && optimize ) + { + int i,j; + int num_u_steps; + int num_v_steps; + for(i=spbrkpts.start; idownloadAll(pta, ptb, backend); + + num_u_steps = (int) (domain_distance_u_rate * (ptb[0]-pta[0])); + num_v_steps = (int) (domain_distance_v_rate * (ptb[1]-pta[1])); + + if(num_u_steps <= 0) num_u_steps = 1; + if(num_v_steps <= 0) num_v_steps = 1; + + backend.surfgrid(pta[0], ptb[0], num_u_steps, + ptb[1], pta[1], num_v_steps); + backend.surfmesh(0,0,num_u_steps,num_v_steps); + + + + continue; + /* the following is left for reference purpose, don't delete + { + Bin* tempSource; + Patchlist patchlist(qlist, pta, ptb); + patchlist.getstepsize(); + + tempSource=makePatchBoundary(pta, ptb); + + tessellation(*tempSource, patchlist); + + render(*tempSource); + delete tempSource; + } + */ + } + } + } + else + subdivideInS( initialbin ); +#else + + subdivideInS( initialbin ); +#endif + + backend.endsurf(); + +} + +void +Subdivider::subdivideInS( Bin& source ) +{ + if( renderhints.display_method == N_OUTLINE_PARAM ) { + outline( source ); + freejarcs( source ); + } else { + setArcTypeBezier(); + setNonDegenerate(); + splitInS( source, spbrkpts.start, spbrkpts.end ); + } +} + + +/*--------------------------------------------------------------------------- + * splitInS - split a patch and a bin by an isoparametric line + *--------------------------------------------------------------------------- + */ + +void +Subdivider::splitInS( Bin& source, int start, int end ) +{ + if( source.isnonempty() ) { + if( start != end ) { + int i = start + (end - start) / 2; + Bin left, right; + split( source, left, right, 0, spbrkpts.pts[i] ); + splitInS( left, start, i ); + splitInS( right, i+1, end ); + } else { + if( start == spbrkpts.start || start == spbrkpts.end ) { + freejarcs( source ); + } else if( renderhints.display_method == N_OUTLINE_PARAM_S ) { + outline( source ); + freejarcs( source ); + } else { + setArcTypeBezier(); + setNonDegenerate(); + s_index = start; + splitInT( source, tpbrkpts.start, tpbrkpts.end ); + } + } + } +} + +/*--------------------------------------------------------------------------- + * splitInT - split a patch and a bin by an isoparametric line + *--------------------------------------------------------------------------- + */ + +void +Subdivider::splitInT( Bin& source, int start, int end ) +{ + if( source.isnonempty() ) { + if( start != end ) { + int i = start + (end - start) / 2; + Bin left, right; + split( source, left, right, 1, tpbrkpts.pts[i] ); + splitInT( left, start, i ); + splitInT( right, i+1, end ); + } else { + if( start == tpbrkpts.start || start == tpbrkpts.end ) { + freejarcs( source ); + } else if( renderhints.display_method == N_OUTLINE_PARAM_ST ) { + outline( source ); + freejarcs( source ); + } else { + t_index = start; + setArcTypeBezier(); + setDegenerate(); + + REAL pta[2], ptb[2]; + pta[0] = spbrkpts.pts[s_index-1]; + pta[1] = tpbrkpts.pts[t_index-1]; + + ptb[0] = spbrkpts.pts[s_index]; + ptb[1] = tpbrkpts.pts[t_index]; + qlist->downloadAll( pta, ptb, backend ); + + Patchlist patchlist( qlist, pta, ptb ); +/* +printf("-------samplingSplit-----\n"); +source.show("samplingSplit source"); +*/ + samplingSplit( source, patchlist, renderhints.maxsubdivisions, 0 ); + setNonDegenerate(); + setArcTypeBezier(); + } + } + } +} + +/*-------------------------------------------------------------------------- + * samplingSplit - recursively subdivide patch, cull check each subpatch + *-------------------------------------------------------------------------- + */ + +void +Subdivider::samplingSplit( + Bin& source, + Patchlist& patchlist, + int subdivisions, + int param ) +{ + if( ! source.isnonempty() ) return; + + if( patchlist.cullCheck() == CULL_TRIVIAL_REJECT ) { + freejarcs( source ); + return; + } + + patchlist.getstepsize(); + + if( renderhints.display_method == N_OUTLINE_PATCH ) { + tessellation( source, patchlist ); + outline( source ); + freejarcs( source ); + return; + } + + //patchlist.clamp(); + + tessellation( source, patchlist ); + + if( patchlist.needsSamplingSubdivision() && (subdivisions > 0) ) { + if( ! patchlist.needsSubdivision( 0 ) ) + param = 1; + else if( ! patchlist.needsSubdivision( 1 ) ) + param = 0; + else + param = 1 - param; + + Bin left, right; + REAL mid = ( patchlist.pspec[param].range[0] + + patchlist.pspec[param].range[1] ) * 0.5; + split( source, left, right, param, mid ); + Patchlist subpatchlist( patchlist, param, mid ); + samplingSplit( left, subpatchlist, subdivisions-1, param ); + samplingSplit( right, patchlist, subdivisions-1, param ); + } else { + setArcTypePwl(); + setDegenerate(); + nonSamplingSplit( source, patchlist, subdivisions, param ); + setDegenerate(); + setArcTypeBezier(); + } +} + +void +Subdivider::nonSamplingSplit( + Bin& source, + Patchlist& patchlist, + int subdivisions, + int param ) +{ + if( patchlist.needsNonSamplingSubdivision() && (subdivisions > 0) ) { + param = 1 - param; + + Bin left, right; + REAL mid = ( patchlist.pspec[param].range[0] + + patchlist.pspec[param].range[1] ) * 0.5; + split( source, left, right, param, mid ); + Patchlist subpatchlist( patchlist, param, mid ); + if( left.isnonempty() ) { + if( subpatchlist.cullCheck() == CULL_TRIVIAL_REJECT ) + freejarcs( left ); + else + nonSamplingSplit( left, subpatchlist, subdivisions-1, param ); + } + if( right.isnonempty() ) { + if( patchlist.cullCheck() == CULL_TRIVIAL_REJECT ) + freejarcs( right ); + else + nonSamplingSplit( right, patchlist, subdivisions-1, param ); + } + + } else { + // make bbox calls + patchlist.bbox(); + backend.patch( patchlist.pspec[0].range[0], patchlist.pspec[0].range[1], + patchlist.pspec[1].range[0], patchlist.pspec[1].range[1] ); + + if( renderhints.display_method == N_OUTLINE_SUBDIV ) { + outline( source ); + freejarcs( source ); + } else { + setArcTypePwl(); + setDegenerate(); + findIrregularS( source ); + monosplitInS( source, smbrkpts.start, smbrkpts.end ); + } + } +} + +/*-------------------------------------------------------------------------- + * tessellation - set tessellation of interior and boundary of patch + *-------------------------------------------------------------------------- + */ + +void +Subdivider::tessellation( Bin& bin, Patchlist &patchlist ) +{ + // tessellate unsampled trim curves + tessellate( bin, patchlist.pspec[1].sidestep[1], patchlist.pspec[0].sidestep[1], + patchlist.pspec[1].sidestep[0], patchlist.pspec[0].sidestep[0] ); + + // set interior sampling rates + slicer.setstriptessellation( patchlist.pspec[0].stepsize, patchlist.pspec[1].stepsize ); + + //added by zl: set the order which will be used in slicer.c++ + slicer.set_ulinear( (patchlist.get_uorder() == 2)); + slicer.set_vlinear( (patchlist.get_vorder() == 2)); + + // set boundary sampling rates + stepsizes[0] = patchlist.pspec[1].stepsize; + stepsizes[1] = patchlist.pspec[0].stepsize; + stepsizes[2] = patchlist.pspec[1].stepsize; + stepsizes[3] = patchlist.pspec[0].stepsize; +} + +/*--------------------------------------------------------------------------- + * monosplitInS - split a patch and a bin by an isoparametric line + *--------------------------------------------------------------------------- + */ + +void +Subdivider::monosplitInS( Bin& source, int start, int end ) +{ + if( source.isnonempty() ) { + if( start != end ) { + int i = start + (end - start) / 2; + Bin left, right; + split( source, left, right, 0, smbrkpts.pts[i] ); + monosplitInS( left, start, i ); + monosplitInS( right, i+1, end ); + } else { + if( renderhints.display_method == N_OUTLINE_SUBDIV_S ) { + outline( source ); + freejarcs( source ); + } else { + setArcTypePwl(); + setDegenerate(); + findIrregularT( source ); + monosplitInT( source, tmbrkpts.start, tmbrkpts.end ); + } + } + } +} + +/*--------------------------------------------------------------------------- + * monosplitInT - split a patch and a bin by an isoparametric line + *--------------------------------------------------------------------------- + */ + +void +Subdivider::monosplitInT( Bin& source, int start, int end ) +{ + if( source.isnonempty() ) { + if( start != end ) { + int i = start + (end - start) / 2; + Bin left, right; + split( source, left, right, 1, tmbrkpts.pts[i] ); + monosplitInT( left, start, i ); + monosplitInT( right, i+1, end ); + } else { + if( renderhints.display_method == N_OUTLINE_SUBDIV_ST ) { + outline( source ); + freejarcs( source ); + } else { +/* +printf("*******render\n"); +source.show("source\n"); +*/ + render( source ); + freejarcs( source ); + } + } + } +} + + +/*---------------------------------------------------------------------------- + * findIrregularS - determine points of non-monotonicity is s direction + *---------------------------------------------------------------------------- + */ + +void +Subdivider::findIrregularS( Bin& bin ) +{ + assert( bin.firstarc()->check() != 0 ); + + smbrkpts.grow( bin.numarcs() ); + + for( Arc_ptr jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) { + REAL *a = jarc->prev->tail(); + REAL *b = jarc->tail(); + REAL *c = jarc->head(); + + if( b[1] == a[1] && b[1] == c[1] ) continue; + + //corrected code + if((b[1]<=a[1] && b[1] <= c[1]) || + (b[1]>=a[1] && b[1] >= c[1])) + { + //each arc (jarc, jarc->prev, jarc->next) is a + //monotone arc consisting of multiple line segements. + //it may happen that jarc->prev and jarc->next are the same, + //that is, jarc->prev and jarc form a closed loop. + //In such case, a and c will be the same. + if(a[0]==c[0] && a[1] == c[1]) + { + if(jarc->pwlArc->npts >2) + { + c = jarc->pwlArc->pts[jarc->pwlArc->npts-2].param; + } + else + { + assert(jarc->prev->pwlArc->npts>2); + a = jarc->prev->pwlArc->pts[jarc->prev->pwlArc->npts-2].param; + } + + } + if(area(a,b,c) < 0) + { + smbrkpts.add(b[0]); + } + + } + + /* old code, + if( b[1] <= a[1] && b[1] <= c[1] ) { + if( ! ccwTurn_tr( jarc->prev, jarc ) ) + smbrkpts.add( b[0] ); + } else if( b[1] >= a[1] && b[1] >= c[1] ) { + if( ! ccwTurn_tl( jarc->prev, jarc ) ) + smbrkpts.add( b[0] ); + } + */ + + } + + smbrkpts.filter(); +} + +/*---------------------------------------------------------------------------- + * findIrregularT - determine points of non-monotonicity in t direction + * where one arc is parallel to the s axis. + *---------------------------------------------------------------------------- + */ + +void +Subdivider::findIrregularT( Bin& bin ) +{ + assert( bin.firstarc()->check() != 0 ); + + tmbrkpts.grow( bin.numarcs() ); + + for( Arc_ptr jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) { + REAL *a = jarc->prev->tail(); + REAL *b = jarc->tail(); + REAL *c = jarc->head(); + + if( b[0] == a[0] && b[0] == c[0] ) continue; + + if( b[0] <= a[0] && b[0] <= c[0] ) { + if( a[1] != b[1] && b[1] != c[1] ) continue; + if( ! ccwTurn_sr( jarc->prev, jarc ) ) + tmbrkpts.add( b[1] ); + } else if ( b[0] >= a[0] && b[0] >= c[0] ) { + if( a[1] != b[1] && b[1] != c[1] ) continue; + if( ! ccwTurn_sl( jarc->prev, jarc ) ) + tmbrkpts.add( b[1] ); + } + } + tmbrkpts.filter( ); +} + +/*----------------------------------------------------------------------------- + * makeBorderTrim - if no user input trimming data then create + * a trimming curve around the boundaries of the Quilt. The curve consists of + * four Jordan arcs, one for each side of the Quilt, connected, of course, + * head to tail. + *----------------------------------------------------------------------------- + */ + +void +Subdivider::makeBorderTrim( const REAL *from, const REAL *to ) +{ + REAL smin = from[0]; + REAL smax = to[0]; + REAL tmin = from[1]; + REAL tmax = to[1]; + + pjarc = 0; + + Arc_ptr jarc = new(arcpool) Arc( arc_bottom, 0 ); + arctessellator.bezier( jarc, smin, smax, tmin, tmin ); + initialbin.addarc( jarc ); + pjarc = jarc->append( pjarc ); + + jarc = new(arcpool) Arc( arc_right, 0 ); + arctessellator.bezier( jarc, smax, smax, tmin, tmax ); + initialbin.addarc( jarc ); + pjarc = jarc->append( pjarc ); + + jarc = new(arcpool) Arc( arc_top, 0 ); + arctessellator.bezier( jarc, smax, smin, tmax, tmax ); + initialbin.addarc( jarc ); + pjarc = jarc->append( pjarc ); + + jarc = new(arcpool) Arc( arc_left, 0 ); + arctessellator.bezier( jarc, smin, smin, tmax, tmin ); + initialbin.addarc( jarc ); + jarc->append( pjarc ); + + assert( jarc->check() != 0 ); +} + +/*---------------------------------------------------------------------------- + * render - renders all monotone regions in a bin and frees the bin + *---------------------------------------------------------------------------- + */ + +void +Subdivider::render( Bin& bin ) +{ + bin.markall(); + +#ifdef N_ISOLINE_S + slicer.setisolines( ( renderhints.display_method == N_ISOLINE_S ) ? 1 : 0 ); +#else + slicer.setisolines( 0 ); +#endif + + for( Arc_ptr jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) { + if( jarc->ismarked() ) { + assert( jarc->check( ) != 0 ); + Arc_ptr jarchead = jarc; + do { + jarc->clearmark(); + jarc = jarc->next; + } while (jarc != jarchead); + slicer.slice( jarc ); + } + } +} + +/*--------------------------------------------------------------------------- + * outline - render the trimmed patch by outlining the boundary + *--------------------------------------------------------------------------- + */ + +void +Subdivider::outline( Bin& bin ) +{ + bin.markall(); + for( Arc_ptr jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) { + if( jarc->ismarked() ) { + assert( jarc->check( ) != 0 ); + Arc_ptr jarchead = jarc; + do { + slicer.outline( jarc ); + jarc->clearmark(); + jarc = jarc->prev; + } while (jarc != jarchead); + } + } +} + +/*--------------------------------------------------------------------------- + * freejarcs - free all arcs in a bin + *--------------------------------------------------------------------------- + */ + +void +Subdivider::freejarcs( Bin& bin ) +{ + bin.adopt(); /* XXX - should not be necessary */ + + Arc_ptr jarc; + while( (jarc = bin.removearc()) != NULL ) { + if( jarc->pwlArc ) jarc->pwlArc->deleteMe( pwlarcpool ); jarc->pwlArc = 0; + if( jarc->bezierArc) jarc->bezierArc->deleteMe( bezierarcpool ); jarc->bezierArc = 0; + jarc->deleteMe( arcpool ); + } +} + +/*---------------------------------------------------------------------------- + * tessellate - tessellate all Bezier arcs in a bin + * 1) only accepts linear Bezier arcs as input + * 2) the Bezier arcs are stored in the pwlArc structure + * 3) only vertical or horizontal lines work + * -- should + * 1) represent Bezier arcs in BezierArc structure + * (this requires a multitude of changes to the code) + * 2) accept high degree Bezier arcs (hard) + * 3) map the curve onto the surface to determine tessellation + * 4) work for curves of arbitrary geometry + *---------------------------------------------------------------------------- + */ + + +void +Subdivider::tessellate( Bin& bin, REAL rrate, REAL trate, REAL lrate, REAL brate ) +{ + for( Arc_ptr jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) { + if( jarc->isbezier( ) ) { + assert( jarc->pwlArc->npts == 2 ); + TrimVertex *pts = jarc->pwlArc->pts; + REAL s1 = pts[0].param[0]; + REAL t1 = pts[0].param[1]; + REAL s2 = pts[1].param[0]; + REAL t2 = pts[1].param[1]; + + jarc->pwlArc->deleteMe( pwlarcpool ); jarc->pwlArc = 0; + + switch( jarc->getside() ) { + case arc_left: + assert( s1 == s2 ); + arctessellator.pwl_left( jarc, s1, t1, t2, lrate ); + break; + case arc_right: + assert( s1 == s2 ); + arctessellator.pwl_right( jarc, s1, t1, t2, rrate ); + break; + case arc_top: + assert( t1 == t2 ); + arctessellator.pwl_top( jarc, t1, s1, s2, trate ); + break; + case arc_bottom: + assert( t1 == t2 ); + arctessellator.pwl_bottom( jarc, t1, s1, s2, brate ); + break; + case arc_none: + (void) abort(); + break; + } + assert( ! jarc->isbezier() ); + assert( jarc->check() != 0 ); + } + } +} diff --git a/src/glu/sgi/libnurbs/internals/subdivider.h b/src/glu/sgi/libnurbs/internals/subdivider.h new file mode 100644 index 0000000..4d53951 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/subdivider.h @@ -0,0 +1,200 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * subdivider.h + * + */ + +#ifndef __glusubdivider_h_ +#define __glusubdivider_h_ + +#include "mysetjmp.h" +#include "bin.h" +#include "flist.h" +#include "slicer.h" +#include "arctess.h" +#include "trimvertex.h" +#include "trimvertpool.h" + +class Arc; +class Pool; +class Renderhints; +class Quilt; +class Patchlist; +class Curvelist; +struct JumpBuffer; + +class Subdivider { +public: + Subdivider( Renderhints&, Backend& ); + ~Subdivider( void ); + void clear( void ); + + void beginTrims( void ) {} + void beginLoop( void ); + void addArc( REAL *, Quilt *, long ); + void addArc( int, TrimVertex *, long ); + void endLoop( void ) {} + void endTrims( void ) {} + + void beginQuilts( void ); + void addQuilt( Quilt * ); + void endQuilts( void ) {} + + void drawCurves( void ); + void drawSurfaces( long ); + + int ccwTurn_sl( Arc_ptr, Arc_ptr ); + int ccwTurn_sr( Arc_ptr , Arc_ptr ); + int ccwTurn_tl( Arc_ptr , Arc_ptr ); + int ccwTurn_tr( Arc_ptr , Arc_ptr ); + + void setJumpbuffer( JumpBuffer * ); + + void set_domain_distance_u_rate(REAL u_rate) + { + domain_distance_u_rate = u_rate; + } + void set_domain_distance_v_rate(REAL v_rate) + { + domain_distance_v_rate = v_rate; + } + void set_is_domain_distance_sampling(int flag) + { + is_domain_distance_sampling = flag; + } + +private: + void classify_headonleft_s( Bin &, Bin &, Bin &, REAL ); + void classify_tailonleft_s( Bin &, Bin &, Bin &, REAL ); + void classify_headonright_s( Bin &, Bin &, Bin &, REAL ); + void classify_tailonright_s( Bin &, Bin &, Bin &, REAL ); + void classify_headonleft_t( Bin &, Bin &, Bin &, REAL ); + void classify_tailonleft_t( Bin &, Bin &, Bin &, REAL ); + void classify_headonright_t( Bin &, Bin &, Bin &, REAL ); + void classify_tailonright_t( Bin &, Bin &, Bin &, REAL ); + + enum dir { down, same, up, none }; + void tessellate( Arc_ptr, REAL ); + void monotonize( Arc_ptr , Bin & ); + int isMonotone( Arc_ptr ); + int decompose( Bin &, REAL ); + + + Slicer slicer; + ArcTessellator arctessellator; + Pool arcpool; + Pool bezierarcpool; + Pool pwlarcpool; + TrimVertexPool trimvertexpool; + + JumpBuffer* jumpbuffer; + Renderhints& renderhints; + Backend& backend; + + Bin initialbin; + Arc_ptr pjarc; + int s_index; + int t_index; + Quilt * qlist; + Flist spbrkpts; + Flist tpbrkpts; + Flist smbrkpts; + Flist tmbrkpts; + REAL stepsizes[4]; + int showDegenerate; + int isArcTypeBezier; + + void samplingSplit( Curvelist&, int ); + + void subdivideInS( Bin& ); + void splitInS( Bin&, int, int ); + void splitInT( Bin&, int, int ); + void samplingSplit( Bin&, Patchlist&, int, int ); + void nonSamplingSplit( Bin&, Patchlist&, int, int ); + void tessellation( Bin&, Patchlist& ); + void monosplitInS( Bin&, int, int ); + void monosplitInT( Bin&, int, int ); + + void outline( Bin & ); + void freejarcs( Bin & ); + void render( Bin & ); + void split( Bin &, Bin &, Bin &, int, REAL ); + void tessellate( Bin &, REAL, REAL, REAL, REAL ); + + inline void setDegenerate( void ) { showDegenerate = 1; } + inline void setNonDegenerate( void ) { showDegenerate = 0; } + inline int showingDegenerate( void ) { return showDegenerate; } + inline void setArcTypeBezier( void ) { isArcTypeBezier = 1; } + inline void setArcTypePwl( void ) { isArcTypeBezier = 0; } + inline int isBezierArcType( void ) { return isArcTypeBezier; } + + void makeBorderTrim( const REAL *, const REAL * ); + void split( Bin &, int, const REAL *, int, int ); + void partition( Bin &, Bin &, Bin &, Bin &, Bin &, int, REAL ); + void findIrregularS( Bin & ); + void findIrregularT( Bin & ); + + + inline int bbox( TrimVertex *, TrimVertex *, TrimVertex *, int ); + static int bbox( REAL, REAL, REAL, REAL, REAL, REAL ); + static int ccw( TrimVertex *, TrimVertex *, TrimVertex * ); + void join_s( Bin &, Bin &, Arc_ptr, Arc_ptr ); + void join_t( Bin &, Bin &, Arc_ptr , Arc_ptr ); + int arc_split( Arc_ptr , int, REAL, int ); + void check_s( Arc_ptr , Arc_ptr ); + void check_t( Arc_ptr , Arc_ptr ); + inline void link( Arc_ptr , Arc_ptr , Arc_ptr , Arc_ptr ); + inline void simple_link( Arc_ptr , Arc_ptr ); + + Bin* makePatchBoundary( const REAL *from, const REAL *to ); + + /*in domain distance method, the tessellation is controled by two numbers: + *GLU_U_STEP: number of u-segments per unit u length of domain + *GLU_V_STEP: number of v-segments per unit v length of domain + *These two numbers are normally stored in mapdesc->maxs(t)rate. + *I (ZL) put these two numbers here so that I can optimize the untrimmed + *case in the case of domain distance sampling. + *These two numbers are set by set_domain_distance_u_rate() and ..._v_..(). + */ + REAL domain_distance_u_rate; + REAL domain_distance_v_rate; + int is_domain_distance_sampling; +}; + +inline void +Subdivider::beginLoop( void ) +{ + pjarc = 0; +} + + +#endif /* __glusubdivider_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/tobezier.cc b/src/glu/sgi/libnurbs/internals/tobezier.cc new file mode 100644 index 0000000..531f26b --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/tobezier.cc @@ -0,0 +1,687 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * tobezier.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "mystring.h" +#include "quilt.h" +#include "knotvector.h" + +/* local type definitions */ +struct Breakpt { /* breakpoints */ + Knot value; /* value */ + int multi; /* multiplicity */ + int def; /* deficit */ +}; + +struct Knotspec { /* knotvector format */ + long order; /* order of spline */ + Knot_ptr inkbegin; /* input knot sequence */ + Knot_ptr inkend; /* location after last knot */ + Knot_ptr outkbegin; /* in-process knot subsequence */ + Knot_ptr outkend; /* location after last knot */ + Knot_ptr kleft; /* */ + Knot_ptr kright; /* */ + Knot_ptr kfirst; /* */ + Knot_ptr klast; /* */ + Knot_ptr sbegin; /* conversion factor values */ + Breakpt * bbegin; /* in-process breakpoints */ + Breakpt * bend; /* last breakpoint */ + int ncoords; /* coordinates per control point */ + int prestride; /* stride between input points */ + int poststride; /* stride between output points */ + int preoffset; /* scaled point offset */ + int postoffset; /* scaled point offset */ + int prewidth; /* width of dimension */ + int postwidth; /* width of dimension */ + int istransformed; /* was dimension transformed */ + Knotspec * next; /* next knotspec */ + Knotspec * kspectotrans; /* knotspec in transformation direction */ + + Knotspec( void ); + ~Knotspec( void ); + void factors( void ); + void insert( REAL * ); + void preselect(); + void select( void ); + void copy( INREAL *, REAL * ); + void breakpoints( void ); + void knots( void ); + void transform( REAL * ); + void showpts( REAL * ); + + void pt_io_copy( REAL *, INREAL * ); + void pt_oo_copy( REAL *, REAL * ); + void pt_oo_sum( REAL*, REAL*, REAL*, Knot, Knot ); +}; + +struct Splinespec { /* a non-uniform tensor element */ + Splinespec( int ); + ~Splinespec(void); + Knotspec *kspec; /* format of each param. dir. */ + int dim; /* domain dimension */ + REAL * outcpts; /* Bezier control points */ + + void kspecinit( Knotvector & ); + void kspecinit( Knotvector &, Knotvector & ); + void select( void ); + void layout( long ); + void setupquilt( Quilt_ptr ); + void copy( INREAL * ); + void transform( void ); +}; + +/*----------------------------------------------------------------------------- + * Quilt::toBezier - convert from NURBS to rational Bezier + *----------------------------------------------------------------------------- + */ + +void +Quilt::toBezier( + Knotvector& knotvector, /* a knot vector */ + INREAL *ctlpts, /* input contol points */ + long ncoords ) /* number of coordinates per control point */ +{ + Splinespec spline( 1 ); + spline.kspecinit( knotvector ); + spline.select(); + spline.layout( ncoords ); + spline.setupquilt( this ); + spline.copy( ctlpts ); + spline.transform(); +} + +void +Quilt::toBezier( + Knotvector& sknotvector, /* a knot vector */ + Knotvector& tknotvector, /* a knot vector */ + INREAL *ctlpts, /* input contol points */ + long ncoords ) /* number of coordinates per control point */ +{ + Splinespec spline( 2 ); + spline.kspecinit( sknotvector, tknotvector ); + spline.select(); + spline.layout( ncoords ); + spline.setupquilt( this ); + spline.copy( ctlpts ); + spline.transform(); +} +Splinespec::Splinespec( int dimen ) +{ + dim = dimen; +} + +Splinespec::~Splinespec( void ) +{ + /* Note: do NOT delete 'outcpts' here since its address (not contents) + * is copied in 'cpts' in this file in function Splinespec::setupquilt(). + * This block of memory will eventually be deleted in file quilt.c++ in + * function Quilt::deleteMe() through 'cpts' so do NOT delete it here! + */ + Knotspec *ktrav= kspec; //start at beginning of list + while (ktrav != 0) { //any items to delete? + Knotspec *deleteThis= ktrav; //remember to delete this + ktrav= ktrav->next; //go to next item if any + delete deleteThis; //delete it + } +} /* ~Splinespec() */ + +/*----------------------------------------------------------------------------- + * Splinespec::kspecinit - initialize Splinespec structure + * + * Client: Quilt::toBezier + *----------------------------------------------------------------------------- + */ + +void +Splinespec::kspecinit( Knotvector& knotvector ) +{ + kspec = new Knotspec; + kspec->inkbegin = knotvector.knotlist; + kspec->inkend = knotvector.knotlist + knotvector.knotcount; + kspec->prestride = (int) knotvector.stride; + kspec->order = knotvector.order; + kspec->next = NULL; +} + +void +Splinespec::kspecinit( Knotvector& sknotvector, Knotvector& tknotvector ) +{ + kspec = new Knotspec; + Knotspec *tkspec = new Knotspec; + + kspec->inkbegin = sknotvector.knotlist; + kspec->inkend = sknotvector.knotlist + sknotvector.knotcount; + kspec->prestride = (int) sknotvector.stride; + kspec->order = sknotvector.order; + kspec->next = tkspec; + + tkspec->inkbegin = tknotvector.knotlist; + tkspec->inkend = tknotvector.knotlist + tknotvector.knotcount; + tkspec->prestride = (int) tknotvector.stride; + tkspec->order = tknotvector.order; + tkspec->next = NULL; +} + + +/*----------------------------------------------------------------------------- + * Splinespec::select - select the subsegments to copy + * + * Client: gl_quilt_to_bezier + *----------------------------------------------------------------------------- + */ + +void +Splinespec::select( ) +{ + for( Knotspec *knotspec = kspec; knotspec; knotspec = knotspec->next ) { + knotspec->preselect(); + knotspec->select(); + } +} + +/*----------------------------------------------------------------------------- + * Splinespec::layout - + * + * Client: gl_quilt_to_bezier + *----------------------------------------------------------------------------- + */ + +void +Splinespec::layout( long ncoords ) +{ + + long stride = ncoords; + for( Knotspec *knotspec = kspec; knotspec; knotspec=knotspec->next ) { + knotspec->poststride = (int) stride; + stride *= ((knotspec->bend-knotspec->bbegin)*knotspec->order + knotspec->postoffset); + knotspec->preoffset *= knotspec->prestride; + knotspec->prewidth *= knotspec->poststride; + knotspec->postwidth *= knotspec->poststride; + knotspec->postoffset *= knotspec->poststride; + knotspec->ncoords = (int) ncoords; + } + outcpts = new REAL[stride]; + assert( outcpts != 0 ); +} + +/*----------------------------------------------------------------------------- + * Splinespec::copy - copy the control points of current subobject + * + * Client: gl_quilt_to_bezier + *----------------------------------------------------------------------------- + */ + +void +Splinespec::copy( INREAL *incpts ) +{ + kspec->copy( incpts, outcpts ); +} + +/*----------------------------------------------------------------------------- + * Splinespec::setupquilt - assign all quilt variables from knotspec + * + * Client: gl_quilt_to_bezier + *----------------------------------------------------------------------------- + */ + +void +Splinespec::setupquilt( Quilt_ptr quilt ) +{ + Quiltspec_ptr qspec = quilt->qspec; + quilt->eqspec = qspec + dim; + for( Knotspec *knotspec = kspec; knotspec; knotspec=knotspec->next, qspec++ ) { + qspec->stride = knotspec->poststride; + qspec->width = knotspec->bend - knotspec->bbegin; + qspec->order = (int) knotspec->order; + qspec->offset = knotspec->postoffset; + qspec->index = 0; + qspec->bdry[0] = (knotspec->kleft == knotspec->kfirst) ? 1 : 0; + qspec->bdry[1] = (knotspec->kright == knotspec->klast) ? 1 : 0; + qspec->breakpoints = new Knot[qspec->width+1]; + Knot_ptr k = qspec->breakpoints; + for( Breakpt *bk = knotspec->bbegin; bk <= knotspec->bend; bk++ ) + *(k++) = bk->value; + } + quilt->cpts = outcpts; + quilt->next = 0; +} + +/*----------------------------------------------------------------------------- + * Splinespec::transform - convert a spline to Bezier format + * + * Client: gl_quilt_to_bezier + *----------------------------------------------------------------------------- + */ + +void +Splinespec::transform( void ) +{ + Knotspec *knotspec; + for( knotspec = kspec; knotspec; knotspec=knotspec->next ) + knotspec->istransformed = 0; + + for( knotspec = kspec; knotspec; knotspec=knotspec->next ) { + for( Knotspec *kspec2 = kspec; kspec2; kspec2=kspec2->next ) + kspec2->kspectotrans = knotspec; + kspec->transform( outcpts ); + knotspec->istransformed = 1; + } +} + + +/*----------------------------------------------------------------------------- + * Knotspec::Knotspec - constuct a knot spec + *----------------------------------------------------------------------------- + */ + +Knotspec::Knotspec( void ) +{ + bbegin = 0; + sbegin = 0; + outkbegin = 0; +} + +/*----------------------------------------------------------------------------- + * Knotspec::copy - copy the control points along minor direction + * + * Client: Splinespec::copy + *----------------------------------------------------------------------------- + */ + +void +Knotspec::copy( INREAL *inpt, REAL *outpt ) +{ + inpt = (INREAL *) (((char *) inpt) + preoffset); + + if( next ) { + for( REAL *lpt=outpt+prewidth; outpt != lpt; outpt += poststride ) { + next->copy( inpt, outpt ); + inpt = (INREAL *) (((char *) inpt) + prestride); + } + } else { + for( REAL *lpt=outpt+prewidth; outpt != lpt; outpt += poststride ) { + pt_io_copy( outpt, inpt ); + inpt = (INREAL *) (((char *) inpt) + prestride); + } + } +} + +/*----------------------------------------------------------------------------- + * Knotspec::showpts - print out points before transformation + * + * Client: Knotspec::select + *----------------------------------------------------------------------------- + */ +void +Knotspec::showpts( REAL *outpt ) +{ + if( next ) { + for( REAL *lpt=outpt+prewidth; outpt != lpt; outpt += poststride ) + next->showpts( outpt ); + } else { + for( REAL *lpt=outpt+prewidth; outpt != lpt; outpt += poststride ) + _glu_dprintf( "show %g %g %g\n", outpt[0], outpt[1], outpt[2] ); + } +} + +/*----------------------------------------------------------------------------- + * Knotspec::factors - precompute scale factors + * - overwrites knot vector, actual new knot vector is NOT produced + * + * Client: Knotspec::select + *----------------------------------------------------------------------------- + */ + +void +Knotspec::factors( void ) +{ + Knot *mid = (outkend - 1) - order + bend->multi; + Knot_ptr fptr = sbegin; + + for( Breakpt *bpt = bend; bpt >= bbegin; bpt-- ) { + mid -= bpt->multi; // last knot less than knot to insert + int def = bpt->def - 1; // number of knots to insert + if( def <= 0 ) continue; + Knot kv = bpt->value; // knot to insert + + Knot *kf = (mid-def) + (order-1); + for( Knot *kl = kf + def; kl != kf; kl-- ) { + Knot *kh, *kt; + for( kt=kl, kh=mid; kt != kf; kh--, kt-- ) + *(fptr++) = (kv - *kh) / (*kt - *kh); + *kl = kv; + } + } +} + +/*----------------------------------------------------------------------------- + * Knotspec::insert - convert subobject in direction of kspec into Bezier + * + * Client: Knotspec::transform + *----------------------------------------------------------------------------- + */ + +void +Knotspec::insert( REAL *p ) +{ + Knot_ptr fptr = sbegin; + REAL *srcpt = p + prewidth - poststride; + REAL *dstpt = p + postwidth + postoffset - poststride; + Breakpt *bpt = bend; + + for( REAL *pend = srcpt - poststride*bpt->def; srcpt != pend; pend +=poststride ) { + REAL *p1 = srcpt; + for( REAL *p2 = srcpt-poststride; p2 != pend; p1 = p2, p2 -= poststride ) { + pt_oo_sum( p1, p1, p2, *fptr, 1.0-*fptr ); + fptr++; + } + } + + for( --bpt; bpt >= bbegin; bpt-- ) { + + for( int multi = bpt->multi; multi > 0; multi-- ) { + pt_oo_copy( dstpt, srcpt ); + dstpt -= poststride; + srcpt -= poststride; + } + + for( REAL *pend = srcpt - poststride*bpt->def; srcpt != pend; pend +=poststride, dstpt-=poststride ) { + pt_oo_copy( dstpt, srcpt ); + REAL *p1 = srcpt; + + for( REAL *p2 = srcpt-poststride; p2 != pend; p1=p2, p2 -= poststride ) { + pt_oo_sum( p1, p1, p2, *fptr, 1.0-*fptr ); + fptr++; + } + } + } +} + +/*----------------------------------------------------------------------------- + * Knotspec::preselect - initialize kspec for processing + * + * Client: Splinespec::select + *----------------------------------------------------------------------------- + */ + +void +Knotspec::preselect( void ) +{ + Knot kval; + + /* position klast after last knot of "last" breakpoint */ + for( klast = inkend - order, kval = *klast; klast != inkend; klast++ ) + if( ! identical( *klast, kval ) ) break; + + /* position kfirst after last knot of "first" breakpoint */ + for( kfirst = inkbegin+order-1, kval= *kfirst; kfirst != inkend; kfirst++ ) + if( ! identical( *kfirst, kval ) ) break; + + /* compute multiplicity of first breakpoint */ + Knot_ptr k; + for( k = kfirst - 1; k >= inkbegin; k-- ) + if( ! identical( kval, *k ) ) break; + k++; + + /* allocate space for breakpoints - + use worst case estimate on number of breakpoints */ + + bbegin = new Breakpt[(klast - kfirst)+1]; + /* record multiplicity and value of first breakpoint */ + bbegin->multi = kfirst - k; + bbegin->value = kval; + bend = bbegin; + + kleft = kright = kfirst; +} + + +/*----------------------------------------------------------------------------- + * Knotspec::select - Knotspec::select segments and precompute scale factors + * + * Client: Splinespec::select + *----------------------------------------------------------------------------- + */ + +void +Knotspec::select( void ) +{ + breakpoints(); + knots(); + factors(); + + preoffset = kleft - (inkbegin + order); + postwidth = (int)((bend - bbegin) * order); + prewidth = (int)((outkend - outkbegin) - order); + postoffset = (bbegin->def > 1) ? (bbegin->def-1) : 0; +} + +/*----------------------------------------------------------------------------- + * Knotspec::breakpoints - compute breakpoints for knotspec + * + * Client: Knotspec::select + *----------------------------------------------------------------------------- + */ + +void +Knotspec::breakpoints( void ) +{ + Breakpt *ubpt = bbegin; + Breakpt *ubend = bend; + long nfactors = 0; + + ubpt->value = ubend->value; + ubpt->multi = ubend->multi; + + kleft = kright; + + for( ; kright != klast; kright++ ) { + if ( identical(*kright,ubpt->value) ) { + (ubpt->multi)++; + } else { + ubpt->def = (int) (order - ubpt->multi); + nfactors += (ubpt->def * (ubpt->def - 1)) / 2; + (++ubpt)->value = *kright; + ubpt->multi = 1; + } + } + ubpt->def = (int) (order - ubpt->multi); + nfactors += (ubpt->def * (ubpt->def - 1)) / 2; + + bend = ubpt; + + if( nfactors ) { + sbegin = new Knot[nfactors]; + } else { + sbegin = NULL; + } +} + + +/*----------------------------------------------------------------------------- + * Knotspec::knots - copy relevant subsequence of knots into temporary area + * + * Client: Knotspec::select + *----------------------------------------------------------------------------- + */ + +void +Knotspec::knots( void ) +{ + Knot_ptr inkpt = kleft - order; + Knot_ptr inkend = kright + bend->def; + + /* allocate space for knots and factors */ + outkbegin = new Knot[inkend-inkpt]; + Knot_ptr outkpt; + for( outkpt = outkbegin; inkpt != inkend; inkpt++, outkpt++ ) + *outkpt = *inkpt; + + outkend = outkpt; +} + + +/*----------------------------------------------------------------------------- + * Knotspec::transform - convert a spline along a given direction + * + * Client: Splienspec::transform + *----------------------------------------------------------------------------- + */ + +void +Knotspec::transform( REAL *p ) +{ + if( next ) { + if( this == kspectotrans ) { + next->transform( p ); + } else { + if( istransformed ) { + p += postoffset; + for( REAL *pend = p + postwidth; p != pend; p += poststride ) + next->transform( p ); + } else { + REAL *pend = p + prewidth; + for( ; p != pend; p += poststride ) + next->transform( p ); + } + } + } else { + if( this == kspectotrans ) { + insert( p ); + } else { + if( istransformed ) { + p += postoffset; + for( REAL *pend = p + postwidth; p != pend; p += poststride ) + kspectotrans->insert( p ); + } else { + REAL *pend = p + prewidth; + for( ; p != pend; p += poststride ) + kspectotrans->insert( p ); + } + } + } +} + +/*----------------------------------------------------------------------------- + * Knotspec::~Knotspec - free space alocated for knotspec + *----------------------------------------------------------------------------- + */ + +Knotspec::~Knotspec( void ) +{ + if( bbegin ) delete[] bbegin; + if( sbegin ) delete[] sbegin; + if( outkbegin ) delete[] outkbegin; +} + + +/*----------------------------------------------------------------------------- + * pt_io_copy - make internal copy of input cntrl pt. of x coords + *----------------------------------------------------------------------------- + */ + +void +Knotspec::pt_io_copy( REAL *topt, INREAL *frompt ) +{ + switch( ncoords ) { + case 4: + topt[3] = (REAL) frompt[3]; + case 3: + topt[2] = (REAL) frompt[2]; + case 2: + topt[1] = (REAL) frompt[1]; + case 1: + topt[0] = (REAL) frompt[0]; + break; + default: { + for( int i = 0; i < ncoords; i++ ) + *topt++ = (REAL) *frompt++; + } + } +} + +/*----------------------------------------------------------------------------- + * pt_oo_copy - make internal copy of internal cntrl pt. of x coords + *----------------------------------------------------------------------------- + */ + +void +Knotspec::pt_oo_copy( REAL *topt, REAL *frompt ) +{ + switch( ncoords ) { + case 4: + topt[3] = frompt[3]; + case 3: + topt[2] = frompt[2]; + case 2: + topt[1] = frompt[1]; + case 1: + topt[0] = frompt[0]; + break; + default: + memcpy( topt, frompt, ncoords * sizeof( REAL ) ); + } +} + +/*----------------------------------------------------------------------------- + * pt_oo_sum - compute affine combination of internal cntrl pts + *----------------------------------------------------------------------------- + */ + +void +Knotspec::pt_oo_sum( REAL *x, REAL *y, REAL *z, Knot a, Knot b ) +{ + switch( ncoords ) { + case 4: + x[3] = a * y[3] + b * z[3]; + case 3: + x[2] = a * y[2] + b * z[2]; + case 2: + x[1] = a * y[1] + b * z[1]; + case 1: + x[0] = a * y[0] + b * z[0]; + break; + default: { + for( int i = 0; i < ncoords; i++ ) + *x++ = a * *y++ + b * *z++; + } + } +} diff --git a/src/glu/sgi/libnurbs/internals/trimline.cc b/src/glu/sgi/libnurbs/internals/trimline.cc new file mode 100644 index 0000000..61f34cd --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/trimline.cc @@ -0,0 +1,223 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * trimline.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "trimline.h" +#include "backend.h" + +Trimline::Trimline() +{ + size = 0; pts = 0; numverts = 0; + tinterp = &t; binterp = &b; +} + +Trimline::~Trimline() +{ + if( pts ) delete[] pts; +} + +void +Trimline::init( TrimVertex *v ) +{ + reset(); + grow(1); + append(v); +} + +inline void +Trimline::grow( long npts ) +{ + if( size < npts ) { + size = 2 * npts; + if( pts ) delete[] pts; + pts = new TrimVertex_p[size]; + } +} + +inline void +Trimline::append( TrimVertex *v ) +{ + assert( numverts != size ); + pts[numverts++] = v; +} + +void +Trimline::init( long npts, Arc_ptr jarc, long last ) +{ + jarcl.init( jarc, 0, last ); + grow( npts + 2 ); +} + +inline void +Trimline::swap() +{ + TrimVertex *tmp=tinterp; + tinterp=binterp; + binterp=tmp; +} + +void +Trimline::getNextPt() +{ + *binterp = *jarcl.getnextpt(); +} + +void +Trimline::getPrevPt() +{ + *binterp = *jarcl.getprevpt(); +} + +/*---------------------------------------------------------------------- + * getNextPts - make arrays of pointers to trim points on left and right + * hulls of trim strip. + *---------------------------------------------------------------------- + */ +void +Trimline::getNextPts( REAL vval, Backend& backend ) +{ + reset(); swap(); append( tinterp ); + assert( tinterp->param[1] >= vval ); + + register TrimVertex *p; + for( p=jarcl.getnextpt() ; p->param[1] >= vval; p=jarcl.getnextpt() ) { + append( p ); + } + + /* compute and copy pointer to final point on left hull */ + if( interpvert( last(), p, binterp, vval ) ) { + binterp->nuid = p->nuid; + backend.triangle( p, binterp, last() ); + append( binterp ); + } + jarcl.reverse(); + (void) jarcl.getprevpt(); /* reset jarcl to proper position */ + jarcl.reverse(); +} + +void +Trimline::getPrevPts( REAL vval, Backend& backend ) +{ + reset(); swap(); append( tinterp ); + assert( tinterp->param[1] >= vval ); + + register TrimVertex *q; + for( q=jarcl.getprevpt(); q->param[1] >= vval; q=jarcl.getprevpt() ) { + append( q ); + } + + /* compute and copy pointer to final point on right hull */ + if( interpvert( q, last(), binterp, vval ) ) { + binterp->nuid = q->nuid; + backend.triangle( last(), binterp, q ); + append( binterp ); + } + jarcl.reverse(); + (void) jarcl.getnextpt(); /* reset jarcl to proper position */ + jarcl.reverse(); +} + +void +Trimline::getNextPts( Arc_ptr botarc ) +{ + reset(); swap(); append( tinterp ); + +#ifndef NDEBUG + PwlArc *lastpwl = botarc->prev->pwlArc; + TrimVertex *lastpt1 = &lastpwl->pts[lastpwl->npts-1]; +#endif + TrimVertex *lastpt2 = botarc->pwlArc->pts; + register TrimVertex *p = jarcl.getnextpt(); + for( append( p ); p != lastpt2; append( p ) ) { + assert( p != lastpt1 ); + p = jarcl.getnextpt(); + } +} + +void +Trimline::getPrevPts( Arc_ptr botarc ) +{ + reset(); swap(); append( tinterp ); + + PwlArc *lastpwl = botarc->prev->pwlArc; + TrimVertex *lastpt1 = &lastpwl->pts[lastpwl->npts-1]; +#ifndef NDEBUG + TrimVertex *lastpt2 = botarc->pwlArc->pts; +#endif + + register TrimVertex *q = jarcl.getprevpt(); + for( append( q ); q != lastpt1; append( q ) ) { + assert( q != lastpt2 ); + q = jarcl.getprevpt(); + } +} + + +long +Trimline::interpvert( TrimVertex *a, TrimVertex *b, TrimVertex *c, REAL vval ) +{ + REAL denom = a->param[1] - b->param[1]; + + if(denom != 0) { + if( vval == a->param[1] ) { + c->param[0] = a->param[0]; + c->param[1] = a->param[1]; + c->nuid = a->nuid; + return 0; + } else if( vval == b->param[1] ) { + c->param[0] = b->param[0]; + c->param[1] = b->param[1]; + c->nuid = b->nuid; + return 0; + } else { + REAL r = (a->param[1] - vval)/denom; + c->param[0] = a->param[0] - r * (a->param[0] - b->param[0]); + c->param[1] = vval; + return 1; + } + } else { + c->param[0] = a->param[0]; + c->param[1] = a->param[1]; + c->nuid = a->nuid; + return 0; + } +} + diff --git a/src/glu/sgi/libnurbs/internals/trimline.h b/src/glu/sgi/libnurbs/internals/trimline.h new file mode 100644 index 0000000..ecc8842 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/trimline.h @@ -0,0 +1,103 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * trimline.h + * + */ + +#ifndef __glutrimline_h_ +#define __glutrimline_h_ + +class Arc; +class Backend; + +#include "trimvertex.h" +#include "jarcloc.h" + + +class Trimline { +private: + TrimVertex** pts; + long numverts; + long i; + long size; + Jarcloc jarcl; + TrimVertex t, b; + TrimVertex *tinterp, *binterp; + void reset( void ) { numverts = 0; } + inline void grow( long ); + inline void swap( void ); + inline void append( TrimVertex * ); + static long interpvert( TrimVertex *, TrimVertex *, TrimVertex *, REAL ); + + + +public: + Trimline(); + ~Trimline(); + void init( TrimVertex * ); + void init( long, Arc_ptr, long ); + void getNextPt( void ); + void getPrevPt( void ); + void getNextPts( REAL, Backend & ); + void getPrevPts( REAL, Backend & ); + void getNextPts( Arc_ptr ); + void getPrevPts( Arc_ptr ); + inline TrimVertex * next( void ); + inline TrimVertex * prev( void ); + inline TrimVertex * first( void ); + inline TrimVertex * last( void ); +}; + +inline TrimVertex * +Trimline::next( void ) +{ + if( i < numverts) return pts[i++]; else return 0; +} + +inline TrimVertex * +Trimline::prev( void ) +{ + if( i >= 0 ) return pts[i--]; else return 0; +} + +inline TrimVertex * +Trimline::first( void ) +{ + i = 0; return pts[i]; +} + +inline TrimVertex * +Trimline::last( void ) +{ + i = numverts; return pts[--i]; +} +#endif /* __glutrimline_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/trimregion.cc b/src/glu/sgi/libnurbs/internals/trimregion.cc new file mode 100644 index 0000000..4aeb5ee --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/trimregion.cc @@ -0,0 +1,113 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * trimregion.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "trimregion.h" + +TrimRegion::TrimRegion( void ) +{ +} + +void +TrimRegion::setDu( REAL du ) +{ + oneOverDu = 1.0/du; +} + +void +TrimRegion::init( long npts, Arc_ptr extrema ) +{ + left.init( npts, extrema, extrema->pwlArc->npts - 1 ); + left.getNextPt(); + + right.init( npts, extrema, 0 ); + right.getPrevPt(); +} + +void +TrimRegion::getPts( Arc_ptr extrema ) +{ + left.getNextPts( extrema ); + right.getPrevPts( extrema ); +} + +void +TrimRegion::getPts( Backend &backend ) +{ + left.getNextPts( bot.vval, backend ); + right.getPrevPts( bot.vval, backend ); +} + +void +TrimRegion::getGridExtent( void ) +{ + getGridExtent( left.last(), right.last() ); +} + +void +TrimRegion::getGridExtent( TrimVertex *l, TrimVertex *r ) +{ + bot.ustart = (long) ((l->param[0] - uarray.uarray[0])*oneOverDu); + if( l->param[0] >= uarray.uarray[bot.ustart] ) bot.ustart++; +// if( l->param[0] > uarray.uarray[bot.ustart] ) bot.ustart++; + assert( l->param[0] <= uarray.uarray[bot.ustart] ); + assert( l->param[0] >= uarray.uarray[bot.ustart-1] ); + + bot.uend = (long) ((r->param[0] - uarray.uarray[0])*oneOverDu); + if( uarray.uarray[bot.uend] >= r->param[0] ) bot.uend--; +// if( uarray.uarray[bot.uend] > r->param[0] ) bot.uend--; + assert( r->param[0] >= uarray.uarray[bot.uend] ); + assert( r->param[0] <= uarray.uarray[bot.uend+1] ); +} + +int +TrimRegion::canTile( void ) +{ + TrimVertex *lf = left.first(); + TrimVertex *ll = left.last(); + TrimVertex *l = ( ll->param[0] > lf->param[0] ) ? ll : lf; + + TrimVertex *rf = right.first(); + TrimVertex *rl = right.last(); + TrimVertex *r = ( rl->param[0] < rf->param[0] ) ? rl : rf; + return (l->param[0] <= r->param[0]) ? 1 : 0; +} + diff --git a/src/glu/sgi/libnurbs/internals/trimregion.h b/src/glu/sgi/libnurbs/internals/trimregion.h new file mode 100644 index 0000000..ee15d7b --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/trimregion.h @@ -0,0 +1,84 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * trimregion.h + * + */ + +#ifndef __glutrimregion_h_ +#define __glutrimregion_h_ + +#include "trimline.h" +#include "gridline.h" +#include "uarray.h" + +class Arc; +class Backend; + +class TrimRegion { +public: + TrimRegion(); + Trimline left; + Trimline right; + Gridline top; + Gridline bot; + Uarray uarray; + + void init( REAL ); + void advance( REAL, REAL, REAL ); + void setDu( REAL ); + void init( long, Arc_ptr ); + void getPts( Arc_ptr ); + void getPts( Backend & ); + void getGridExtent( TrimVertex *, TrimVertex * ); + void getGridExtent( void ); + int canTile( void ); +private: + REAL oneOverDu; +}; + +inline void +TrimRegion::init( REAL vval ) +{ + bot.vval = vval; +} + +inline void +TrimRegion::advance( REAL topVindex, REAL botVindex, REAL botVval ) +{ + top.vindex = (long) topVindex; + bot.vindex = (long) botVindex; + top.vval = bot.vval; + bot.vval = botVval; + top.ustart = bot.ustart; + top.uend = bot.uend; +} +#endif /* __glutrimregion_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/trimvertex.h b/src/glu/sgi/libnurbs/internals/trimvertex.h new file mode 100644 index 0000000..2780b76 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/trimvertex.h @@ -0,0 +1,63 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * trimvertex.h + * + */ + +#ifndef __glutrimvertex_h_ +#define __glutrimvertex_h_ + +#include "types.h" + +/*#define USE_OPTTT*/ + +class TrimVertex { /* a vertex on a trim curve */ +public: + REAL param[2]; /* parametric space coords */ +#ifdef USE_OPTTT + REAL cache_point[4]; //only when USE_OPTTT is on in slicer.c++ + REAL cache_normal[3]; +#endif + long nuid; +}; + +typedef class TrimVertex *TrimVertex_p; + +inline REAL +det3( TrimVertex *a, TrimVertex *b, TrimVertex *c ) +{ + return a->param[0] * (b->param[1]-c->param[1]) + + b->param[0] * (c->param[1]-a->param[1]) + + c->param[0] * (a->param[1]-b->param[1]); +} + +#endif /* __glutrimvertex_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/trimvertpool.cc b/src/glu/sgi/libnurbs/internals/trimvertpool.cc new file mode 100644 index 0000000..3e5bd70 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/trimvertpool.cc @@ -0,0 +1,119 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * trimvertexpool.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "mystring.h" +#include "trimvertex.h" +#include "trimvertpool.h" +#include "bufpool.h" + +/*---------------------------------------------------------------------------- + * TrimVertexPool::TrimVertexPool + *---------------------------------------------------------------------------- + */ +TrimVertexPool::TrimVertexPool( void ) + : pool( sizeof(TrimVertex)*3, 32, "Threevertspool" ) +{ + // initialize array of pointers to vertex lists + nextvlistslot = 0; + vlistsize = INIT_VERTLISTSIZE; + vlist = new TrimVertex_p[vlistsize]; +} + +/*---------------------------------------------------------------------------- + * TrimVertexPool::~TrimVertexPool + *---------------------------------------------------------------------------- + */ +TrimVertexPool::~TrimVertexPool( void ) +{ + // free all arrays of TrimVertices vertices + while( nextvlistslot ) { + delete [] vlist[--nextvlistslot]; + } + + // reallocate space for array of pointers to vertex lists + if( vlist ) delete[] vlist; +} + +/*---------------------------------------------------------------------------- + * TrimVertexPool::clear + *---------------------------------------------------------------------------- + */ +void +TrimVertexPool::clear( void ) +{ + // reinitialize pool of 3 vertex arrays + pool.clear(); + + // free all arrays of TrimVertices vertices + while( nextvlistslot ) { + delete [] vlist[--nextvlistslot]; + vlist[nextvlistslot] = 0; + } + + // reallocate space for array of pointers to vertex lists + if( vlist ) delete[] vlist; + vlist = new TrimVertex_p[vlistsize]; +} + + +/*---------------------------------------------------------------------------- + * TrimVertexPool::get - allocate a vertex list + *---------------------------------------------------------------------------- + */ +TrimVertex * +TrimVertexPool::get( int n ) +{ + TrimVertex *v; + if( n == 3 ) { + v = (TrimVertex *) pool.new_buffer(); + } else { + if( nextvlistslot == vlistsize ) { + vlistsize *= 2; + TrimVertex_p *nvlist = new TrimVertex_p[vlistsize]; + memcpy( nvlist, vlist, nextvlistslot * sizeof(TrimVertex_p) ); + if( vlist ) delete[] vlist; + vlist = nvlist; + } + v = vlist[nextvlistslot++] = new TrimVertex[n]; + } + return v; +} diff --git a/src/glu/sgi/libnurbs/internals/trimvertpool.h b/src/glu/sgi/libnurbs/internals/trimvertpool.h new file mode 100644 index 0000000..ebd3c04 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/trimvertpool.h @@ -0,0 +1,57 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * trimvertexpool.h + * + */ + +#ifndef __glutrimvertpool_h_ +#define __glutrimvertpool_h_ + +#include "bufpool.h" + +class TrimVertex; + +#define INIT_VERTLISTSIZE 200 + +class TrimVertexPool { +public: + TrimVertexPool( void ); + ~TrimVertexPool( void ); + void clear( void ); + TrimVertex * get( int ); +private: + Pool pool; + TrimVertex ** vlist; + int nextvlistslot; + int vlistsize; +}; +#endif /* __glutrimvertpool_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/types.h b/src/glu/sgi/libnurbs/internals/types.h new file mode 100644 index 0000000..8b59625 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/types.h @@ -0,0 +1,47 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * types.h + * + */ + +#ifndef __glutypes_h_ +#define __glutypes_h_ + +//typedef double INREAL; +#define INREAL float +typedef float REAL; +typedef void (*Pfvv)( void ); +typedef void (*Pfvf)( float * ); +typedef int (*cmpfunc)(const void *, const void *); +typedef REAL Knot, *Knot_ptr;/* knot values */ + +#endif /* __glutypes_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/uarray.cc b/src/glu/sgi/libnurbs/internals/uarray.cc new file mode 100644 index 0000000..4b3329c --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/uarray.cc @@ -0,0 +1,73 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * uarray.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "uarray.h" +#include "arc.h" + +Uarray::Uarray( void ) +{ + uarray = 0; + size = 0; + ulines = 0; +} + +Uarray::~Uarray( void ) +{ + if( uarray ) delete[] uarray; +} + +long +Uarray::init( REAL delta, Arc_ptr lo, Arc_ptr hi ) +{ + ulines = (long) ((hi->tail()[0] - lo->tail()[0])/delta) + 3; + if( size < ulines ) { + size = ulines * 2; + if( uarray ) delete[] uarray; + uarray = new REAL[size]; + assert( uarray != 0); + } + uarray[0] = lo->tail()[0] - delta/2.0; + for( long i = 1 ; i != ulines; i++ ) + uarray[i] = uarray[0] + i*delta; + return ulines; +} + diff --git a/src/glu/sgi/libnurbs/internals/uarray.h b/src/glu/sgi/libnurbs/internals/uarray.h new file mode 100644 index 0000000..cc6fae1 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/uarray.h @@ -0,0 +1,55 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * uarray.h + * + */ + +#ifndef __gluuarray_h_ +#define __gluuarray_h_ + +#include "types.h" + +class Arc; +typedef class Arc *Arc_ptr; + +class Uarray { +private: + long size; + long ulines; +public: + Uarray(); + ~Uarray(); + long init( REAL, Arc_ptr, Arc_ptr ); + REAL * uarray; +}; + +#endif /* __gluuarray_h_ */ diff --git a/src/glu/sgi/libnurbs/internals/varray.cc b/src/glu/sgi/libnurbs/internals/varray.cc new file mode 100644 index 0000000..1cb2354 --- /dev/null +++ b/src/glu/sgi/libnurbs/internals/varray.cc @@ -0,0 +1,152 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +*/ + +/* + * varray.c++ + * + */ + +#include "glimports.h" +#include "myassert.h" +#include "mystdio.h" +#include "varray.h" +#include "arc.h" +#include "simplemath.h" // glu_abs() + +#define TINY 0.0001 +inline long sgn( REAL x ) +{ + return (x < -TINY) ? -1 : ((x > TINY) ? 1 : 0 ); +} + + +Varray::Varray( void ) +{ + int i; + + varray = 0; + size = 0; + numquads = 0; + + for (i = 0; i < 1000; i++) { + vval[i] = 0; + voffset[i] = 0; + } +} + +Varray::~Varray( void ) +{ + if( varray ) delete[] varray; +} + +inline void +Varray::update( Arc_ptr arc, long dir[2], REAL val ) +{ + register long ds = sgn(arc->tail()[0] - arc->prev->tail()[0]); + register long dt = sgn(arc->tail()[1] - arc->prev->tail()[1]); + + if( dir[0] != ds || dir[1] != dt ) { + dir[0] = ds; + dir[1] = dt; + append( val ); + } +} + +void +Varray::grow( long guess ) +{ + if( size < guess ) { + size = guess * 2; + if( varray ) delete[] varray; + varray = new REAL[size]; + assert( varray != 0 ); + } +} + +long +Varray::init( REAL delta, Arc_ptr toparc, Arc_ptr botarc ) +{ + Arc_ptr left = toparc->next; + Arc_ptr right = toparc; + long ldir[2], rdir[2]; + + ldir[0] = sgn( left->tail()[0] - left->prev->tail()[0] ); + ldir[1] = sgn( left->tail()[1] - left->prev->tail()[1] ); + rdir[0] = sgn( right->tail()[0] - right->prev->tail()[0] ); + rdir[1] = sgn( right->tail()[1] - right->prev->tail()[1] ); + + vval[0] = toparc->tail()[1]; + numquads = 0; + + while( 1 ) { + switch( sgn( left->tail()[1] - right->prev->tail()[1] ) ) { + case 1: + left = left->next; + update( left, ldir, left->prev->tail()[1] ); + break; + case -1: + right = right->prev; + update( right, rdir, right->tail()[1] ); + break; + case 0: + if( glu_abs(left->tail()[1] - botarc->tail()[1]) < TINY) goto end; + if( glu_abs(left->tail()[0]-right->prev->tail()[0]) < TINY && + glu_abs(left->tail()[1]-right->prev->tail()[1]) < TINY) goto end; + left = left->next; + break; + } + } + +end: + append( botarc->tail()[1] ); + + grow( ((long) ((vval[0] - vval[numquads])/delta)) + numquads + 2 ); + + long i, index = 0; + for( i=0; i delta ) { + long steps = ((long) (dist/delta)) +1; + float deltav = - dist / (REAL) steps; + for( long j=1; j +#include +#include +#include "glimports.h" +#include "zlassert.h" + +#include "quicksort.h" +#include "directedLine.h" +#include "polyDBG.h" + +#ifdef __WATCOMC__ +#pragma warning 726 10 +#endif + +//we must return the newLine +directedLine* directedLine::deleteChain(directedLine* begin, directedLine* end) +{ + if(begin->head()[0] == end->tail()[0] && + begin->head()[1] == end->tail()[1] + ) + { + directedLine *ret = begin->prev; + begin->prev->next = end->next; + end->next->prev = begin->prev; + delete begin->sline; + delete end->sline; + delete begin; + delete end; + + return ret; + } + + directedLine* newLine; + sampledLine* sline = new sampledLine(begin->head(), end->tail()); + newLine = new directedLine(INCREASING, sline); + directedLine *p = begin->prev; + directedLine *n = end->next; + p->next = newLine; + n->prev = newLine; + newLine->prev = p; + newLine->next = n; + + delete begin->sline; + delete end->sline; + delete begin; + delete end; + return newLine; +} + + +void directedLine::deleteSingleLine(directedLine* dline) +{ + //make sure that dline->prev->tail is the same as + //dline->next->head. This is for numerical erros. + //for example, if we delete a line which is almost degeneate + //within (epsilon), then we want to make that the polygon after deletion + //is still a valid polygon + + dline->next->head()[0] = dline->prev->tail()[0]; + dline->next->head()[1] = dline->prev->tail()[1]; + + dline->prev->next = dline->next; + dline->next->prev = dline->prev; + + delete dline; + +} + +static Int myequal(Real a[2], Real b[2]) +{ + /* + if(a[0]==b[0] && a[1] == b[1]) + return 1; + else + return 0; + */ + + + if(fabs(a[0]-b[0]) < 0.00001 && + fabs(a[1]-b[1]) < 0.00001) + return 1; + else + return 0; + +} + +directedLine* directedLine::deleteDegenerateLines() +{ + //if there is only one edge or two edges, don't do anything + if(this->next == this) + return this; + if(this->next == this->prev) + return this; + + //find a nondegenerate line + directedLine* temp; + directedLine* first = NULL; + if(! myequal(head(), tail())) + /* + if(head()[0] != tail()[0] || + head()[1] != tail()[1]) + */ + first = this; + else + { + for(temp = this->next; temp != this; temp = temp->next) + { + /* + if(temp->head()[0] != temp->tail()[0] || + temp->head()[1] != temp->tail()[1]) + */ + if(! myequal(temp->head(), temp->tail())) + { + first = temp; + break; + } + + } + } + + //if there are no non-degenerate lines, then we simply return NULL. + if(first == NULL) + { + deleteSinglePolygonWithSline(); + return NULL; + } + + directedLine* tempNext = NULL; + for(temp =first->next; temp != first; temp = tempNext) + { + tempNext = temp->getNext(); +/* + if(temp->head()[0] == temp->tail()[0] && + temp->head()[1] == temp->tail()[1]) +*/ + + if(myequal(temp->head(), temp->tail())) + deleteSingleLine(temp); + } + return first; +} + +directedLine* directedLine::deleteDegenerateLinesAllPolygons() +{ + directedLine* temp; + directedLine *tempNext = NULL; + directedLine* ret= NULL; + directedLine* retEnd = NULL; + for(temp=this; temp != NULL; temp = tempNext) + { + tempNext = temp->nextPolygon; + temp->nextPolygon = NULL; + if(ret == NULL) + { + ret = retEnd = temp->deleteDegenerateLines(); + + } + else + { + directedLine *newPolygon = temp->deleteDegenerateLines(); + if(newPolygon != NULL) + { + retEnd->nextPolygon = temp->deleteDegenerateLines(); + retEnd = retEnd->nextPolygon; + } + } + } + return ret; +} + +directedLine* directedLine::cutIntersectionAllPoly(int &cutOccur) +{ + directedLine* temp; + directedLine *tempNext = NULL; + directedLine* ret= NULL; + directedLine* retEnd = NULL; + cutOccur = 0; + for(temp=this; temp != NULL; temp = tempNext) + { + int eachCutOccur=0; + tempNext = temp->nextPolygon; + temp->nextPolygon = NULL; + if(ret == NULL) + { + + ret = retEnd = DBG_cutIntersectionPoly(temp, eachCutOccur); + if(eachCutOccur) + cutOccur = 1; + } + else + { + + retEnd->nextPolygon = DBG_cutIntersectionPoly(temp, eachCutOccur); + retEnd = retEnd->nextPolygon; + if(eachCutOccur) + cutOccur = 1; + } + } + return ret; +} + + +void directedLine::deleteSinglePolygonWithSline() +{ + directedLine *temp, *tempNext; + prev->next = NULL; + for(temp=this; temp != NULL; temp = tempNext) + { + tempNext = temp->next; + delete temp->sline; + delete temp; + } +} + +void directedLine::deletePolygonListWithSline() +{ + directedLine *temp, *tempNext; + for(temp=this; temp != NULL; temp=tempNext) + { + tempNext = temp->nextPolygon; + temp->deleteSinglePolygonWithSline(); + } +} + +void directedLine::deleteSinglePolygon() +{ + directedLine *temp, *tempNext; + prev->next = NULL; + for(temp=this; temp != NULL; temp = tempNext) + { + tempNext = temp->next; + delete temp; + } +} + +void directedLine::deletePolygonList() +{ + directedLine *temp, *tempNext; + for(temp=this; temp != NULL; temp=tempNext) + { + tempNext = temp->nextPolygon; + temp->deleteSinglePolygon(); + } +} + + +/*a loop by itself*/ +directedLine::directedLine(short dir, sampledLine* sl) +{ + direction = dir; + sline = sl; + next = this; + prev = this; + nextPolygon = NULL; +// prevPolygon = NULL; + rootBit = 0;/*important to initilzae to 0 meaning not root yet*/ + + rootLink = NULL; + +} + +void directedLine::init(short dir, sampledLine* sl) +{ + direction = dir; + sline = sl; +} + +directedLine::directedLine() +{ + next = this; + prev = this; + nextPolygon = NULL; + rootBit = 0;/*important to initilzae to 0 meaning not root yet*/ + rootLink = NULL; + direction = INCREASING; + sline = NULL; +} + +directedLine::~directedLine() +{ +} + +Real* directedLine::head() +{ + + return (direction==INCREASING)? (sline->get_points())[0] : (sline->get_points())[sline->get_npoints()-1]; +} + +/*inline*/ Real* directedLine::getVertex(Int i) +{ + return (direction==INCREASING)? (sline->get_points())[i] : (sline->get_points())[sline->get_npoints() - 1 -i]; +} + +Real* directedLine::tail() +{ + return (direction==DECREASING)? (sline->get_points())[0] : (sline->get_points())[sline->get_npoints()-1]; +} + + /*insert a new line between prev and this*/ +void directedLine::insert(directedLine* nl) +{ + nl->next = this; + nl->prev = prev; + prev->next = nl; + prev = nl; + nl->rootLink = this; /*assuming that 'this' is the root!!!*/ +} + +Int directedLine::numEdges() +{ + Int ret=0; + directedLine* temp; + if(next == this) return 1; + + ret = 1; + for(temp = next; temp != this; temp = temp->next) + ret++; + return ret; +} + +Int directedLine::numEdgesAllPolygons() +{ + Int ret=0; + directedLine* temp; + for(temp=this; temp!= NULL; temp=temp->nextPolygon) + { + ret += temp->numEdges(); + } + return ret; +} + +/*return 1 if the double linked list forms a polygon. + */ +short directedLine::isPolygon() +{ + directedLine* temp; + + /*a polygon contains at least 3 edges*/ + if(numEdges() <=2) return 0; + + /*check this edge*/ + if(! isConnected()) return 0; + + /*check all other edges*/ + for(temp=next; temp != this; temp = temp->next){ + if(!isConnected()) return 0; + } + return 1; +} + +/*check if the head of this edge is connected to + *the tail of the prev + */ +short directedLine::isConnected() +{ + if( (head()[0] == prev->tail()[0]) && (head()[1] == prev->tail()[1])) + return 1; + else + return 0; +} + +Int compV2InY(Real A[2], Real B[2]) +{ + if(A[1] < B[1]) return -1; + if(A[1] == B[1] && A[0] < B[0]) return -1; + if(A[1] == B[1] && A[0] == B[0]) return 0; + return 1; +} + +Int compV2InX(Real A[2], Real B[2]) +{ + if(A[0] < B[0]) return -1; + if(A[0] == B[0] && A[1] < B[1]) return -1; + if(A[0] == B[0] && A[1] == B[1]) return 0; + return 1; +} + +/*compare two vertices NOT lines! + *A vertex is the head of a directed line. + *(x_1, y_1) <= (x_2, y_2) if + *either y_1 < y_2 + *or y_1 == y_2 && x_1 < x_2. + *return -1 if this->head() <= nl->head(), + *return 1 otherwise + */ +Int directedLine::compInY(directedLine* nl) +{ + if(head()[1] < nl->head()[1]) return -1; + if(head()[1] == nl->head()[1] && head()[0] < nl->head()[0]) return -1; + return 1; +} + +/*compare two vertices NOT lines! + *A vertex is the head of a directed line. + *(x_1, y_1) <= (x_2, y_2) if + *either x_1 < x_2 + *or x_1 == x_2 && y_1 < y_2. + *return -1 if this->head() <= nl->head(), + *return 1 otherwise + */ +Int directedLine::compInX(directedLine* nl) +{ + if(head()[0] < nl->head()[0]) return -1; + if(head()[0] == nl->head()[0] && head()[1] < nl->head()[1]) return -1; + return 1; +} + +/*used by sort precedures + */ +static Int compInY2(directedLine* v1, directedLine* v2) +{ + return v1->compInY(v2); +} +#ifdef NOT_USED +static Int compInX(directedLine* v1, directedLine* v2) +{ + return v1->compInX(v2); +} +#endif + +/*sort all the vertices NOT the lines! + *a vertex is the head of a directed line + */ +directedLine** directedLine::sortAllPolygons() +{ + Int total_num_edges = 0; + directedLine** array = toArrayAllPolygons(total_num_edges); + quicksort( (void**)array, 0, total_num_edges-1, (Int (*)(void *, void *)) compInY2); + + return array; +} + +void directedLine::printSingle() +{ + if(direction == INCREASING) + printf("direction is INCREASING\n"); + else + printf("direction is DECREASING\n"); + printf("head=%f,%f)\n", head()[0], head()[1]); + sline->print(); +} + +/*print one polygon*/ +void directedLine::printList() +{ + directedLine* temp; + printSingle(); + for(temp = next; temp!=this; temp=temp->next) + temp->printSingle(); +} + +/*print all the polygons*/ +void directedLine::printAllPolygons() +{ + directedLine *temp; + for(temp = this; temp!=NULL; temp = temp->nextPolygon) + { + printf("polygon:\n"); + temp->printList(); + } +} + +/*insert this polygon into the head of the old polygon List*/ +directedLine* directedLine::insertPolygon(directedLine* oldList) +{ + /*this polygon is a root*/ + setRootBit(); + if(oldList == NULL) return this; + nextPolygon = oldList; +/* oldList->prevPolygon = this;*/ + return this; +} + +/*cutoff means delete. but we don't deallocate any space, + *so we use cutoff instead of delete + */ +directedLine* directedLine::cutoffPolygon(directedLine *p) +{ + directedLine* temp; + directedLine* prev_polygon = NULL; + if(p == NULL) return this; + + for(temp=this; temp != p; temp = temp->nextPolygon) + { + if(temp == NULL) + { + fprintf(stderr, "in cutoffPolygon, not found\n"); + exit(1); + } + prev_polygon = temp; + } + +/* prev_polygon = p->prevPolygon;*/ + + p->resetRootBit(); + if(prev_polygon == NULL) /*this is the one to cutoff*/ + return nextPolygon; + else { + prev_polygon->nextPolygon = p->nextPolygon; + return this; + } +} + +Int directedLine::numPolygons() +{ + if(nextPolygon == NULL) return 1; + else return 1+nextPolygon->numPolygons(); +} + + +/*let array[index ...] denote + *all the edges in this polygon + *return the next available index of array. + */ +Int directedLine::toArraySinglePolygon(directedLine** array, Int index) +{ + directedLine *temp; + array[index++] = this; + for(temp = next; temp != this; temp = temp->next) + { + array[index++] = temp; + } + return index; +} + +/*the space is allocated. The caller is responsible for + *deallocate the space. + *total_num_edges is set to be the total number of edges of all polygons + */ +directedLine** directedLine::toArrayAllPolygons(Int& total_num_edges) +{ + total_num_edges=numEdgesAllPolygons(); + directedLine** ret = (directedLine**) malloc(sizeof(directedLine*) * total_num_edges); + assert(ret); + + directedLine *temp; + Int index = 0; + for(temp=this; temp != NULL; temp=temp->nextPolygon) { + index = temp->toArraySinglePolygon(ret, index); + } + return ret; +} + +/*assume the polygon is a simple polygon, return + *the area enclosed by it. + *if thee order is counterclock wise, the area is positive. + */ +Real directedLine::polyArea() +{ + directedLine* temp; + Real ret=0.0; + Real x1,y1,x2,y2; + x1 = this->head()[0]; + y1 = this->head()[1]; + x2 = this->next->head()[0]; + y2 = this->next->head()[1]; + ret = -(x2*y1-x1*y2); + for(temp=this->next; temp!=this; temp = temp->next) + { + x1 = temp->head()[0]; + y1 = temp->head()[1]; + x2 = temp->next->head()[0]; + y2 = temp->next->head()[1]; + ret += -( x2*y1-x1*y2); + } + return Real(0.5)*ret; +} + +/*******************split or combine polygons begin********************/ +/*conect a diagonal of a single simple polygon or two simple polygons. + *If the two vertices v1 (head) and v2 (head) are in the same simple polygon, + *then we actually split the simple polygon into two polygons. + *If instead two vertices velong to two difference polygons, + *then we combine the two polygons into one polygon. + *It is upto the caller to decide whether this is a split or a + *combination. + * + *Case Split: + *split a single simple polygon into two simple polygons by + *connecting a diagonal (two vertices). + *v1, v2: the two vertices are the head() of the two directedLines. + * this routine generates one new sampledLine which is returned in + *generatedLine, + *and it generates two directedLines returned in ret_p1 and ret_p2. + *ret_p1 and ret_p2 are used as the entry to the two new polygons. + *Notice the caller should not deallocate the space of v2 and v2 after + *calling this function, since all of the edges are connected to + *ret_p1 or ret_p2. + * + *combine: + *combine two simpolygons into one by connecting one diagonal. + *the returned polygon is returned in ret_p1. + */ +/*ARGSUSED*/ +void directedLine::connectDiagonal(directedLine* v1, directedLine* v2, + directedLine** ret_p1, + directedLine** ret_p2, + sampledLine** generatedLine, + directedLine* polygonList ) +{ + sampledLine *nsline = new sampledLine(2); + + + + nsline->setPoint(0, v1->head()); + nsline->setPoint(1, v2->head()); + + + + /*the increasing line is from v1 head to v2 head*/ + directedLine* newLineInc = new directedLine(INCREASING, nsline); + + + + directedLine* newLineDec = new directedLine(DECREASING, nsline); + + + directedLine* v1Prev = v1->prev; + directedLine* v2Prev = v2->prev; + + v1 ->prev = newLineDec; + v2Prev ->next = newLineDec; + newLineDec->next = v1; + newLineDec->prev = v2Prev; + + v2 ->prev = newLineInc; + v1Prev ->next = newLineInc; + newLineInc->next = v2; + newLineInc->prev = v1Prev; + + *ret_p1 = newLineDec; + *ret_p2 = newLineInc; + *generatedLine = nsline; +} + +//see the function connectDiangle +/*ARGSUSED*/ +void directedLine::connectDiagonal_2slines(directedLine* v1, directedLine* v2, + directedLine** ret_p1, + directedLine** ret_p2, + directedLine* polygonList ) +{ + sampledLine *nsline = new sampledLine(2); + sampledLine *nsline2 = new sampledLine(2); + + nsline->setPoint(0, v1->head()); + nsline->setPoint(1, v2->head()); + nsline2->setPoint(0, v1->head()); + nsline2->setPoint(1, v2->head()); + + /*the increasing line is from v1 head to v2 head*/ + directedLine* newLineInc = new directedLine(INCREASING, nsline); + + directedLine* newLineDec = new directedLine(DECREASING, nsline2); + + directedLine* v1Prev = v1->prev; + directedLine* v2Prev = v2->prev; + + v1 ->prev = newLineDec; + v2Prev ->next = newLineDec; + newLineDec->next = v1; + newLineDec->prev = v2Prev; + + v2 ->prev = newLineInc; + v1Prev ->next = newLineInc; + newLineInc->next = v2; + newLineInc->prev = v1Prev; + + *ret_p1 = newLineDec; + *ret_p2 = newLineInc; + +} + +Int directedLine::samePolygon(directedLine* v1, directedLine* v2) +{ + if(v1 == v2) return 1; + directedLine *temp; + for(temp = v1->next; temp != v1; temp = temp->next) + { + if(temp == v2) return 1; + } + return 0; +} + +directedLine* directedLine::findRoot() +{ + if(rootBit) return this; + directedLine* temp; + for(temp = next; temp != this; temp = temp->next) + if(temp -> rootBit ) return temp; + return NULL; /*should not happen*/ +} + +directedLine* directedLine::rootLinkFindRoot() +{ + directedLine* tempRoot; + directedLine* tempLink; + tempRoot = this; + tempLink = rootLink; + while(tempLink != NULL){ + tempRoot = tempLink; + tempLink = tempRoot->rootLink; + } + return tempRoot; +} + +/*******************split or combine polygons end********************/ + +/*****************IO stuff begin*******************/ + +/*format: + *#polygons + * #vertices + * vertices + * #vertices + * vertices + *... + */ +void directedLine::writeAllPolygons(char* filename) +{ + FILE* fp = fopen(filename, "w"); + assert(fp); + Int nPolygons = numPolygons(); + directedLine *root; + fprintf(fp, "%i\n", nPolygons); + for(root = this; root != NULL; root = root->nextPolygon) + { + directedLine *temp; + Int npoints=0; + npoints = root->get_npoints()-1; + for(temp = root->next; temp != root; temp=temp->next) + npoints += temp->get_npoints()-1; + fprintf(fp, "%i\n", npoints/*root->numEdges()*/); + + + for(Int i=0; iget_npoints()-1; i++){ + fprintf(fp, "%f ", root->getVertex(i)[0]); + fprintf(fp, "%f ", root->getVertex(i)[1]); + } + + for(temp=root->next; temp != root; temp = temp->next) + { + for(Int i=0; iget_npoints()-1; i++){ + + fprintf(fp, "%f ", temp->getVertex(i)[0]); + fprintf(fp, "%f ", temp->getVertex(i)[1]); + } + fprintf(fp,"\n"); + } + fprintf(fp, "\n"); + } + fclose(fp); +} + +directedLine* readAllPolygons(char* filename) +{ + Int i,j; + FILE* fp = fopen(filename, "r"); + Int nPolygons; + int result; + + assert(fp); + result = fscanf(fp, "%i", &nPolygons); + assert(result != EOF); + directedLine *ret = NULL; + + for(i=0; irootLinkSet(NULL); + + directedLine *dLine; + for(j=2; jrootLinkSet(thisPoly); + thisPoly->insert(dLine); + } + + VV[0][0]=vert[1][0]; + VV[0][1]=vert[1][1]; + sLine = new sampledLine(2,VV); + dLine = new directedLine(INCREASING, sLine); +dLine->rootLinkSet(thisPoly); + thisPoly->insert(dLine); + + ret = thisPoly->insertPolygon(ret); + } + fclose(fp); + return ret; +} + + + + + + + + diff --git a/src/glu/sgi/libnurbs/nurbtess/directedLine.h b/src/glu/sgi/libnurbs/nurbtess/directedLine.h new file mode 100644 index 0000000..4ed0128 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/directedLine.h @@ -0,0 +1,171 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _DIRECTEDLINE_H +#define _DIRECTEDLINE_H + +#include "definitions.h" +#include "sampledLine.h" + +enum {INCREASING, DECREASING}; + +class directedLine { + short direction; /*INCREASING or DECREASING*/ + sampledLine* sline; + directedLine* next; /*double linked list*/ + directedLine* prev; /*double linked list*/ + + /*in case we need a list of polygons each + *consisting of a double linked list + */ + directedLine* nextPolygon; + + /*optimization make cutoff polygon faster*/ +/* directedLine* prevPolygon;*/ + + Int rootBit; /*1 if this is a root of the polygon, set by setRootBit*/ + /*and reset by resetRootBit()*/ + + directedLine* rootLink; /*fast root-finding*/ + + + +public: + directedLine(short dir, sampledLine* sl); + directedLine(); + ~directedLine(); + + void init(short dir, sampledLine* sl); + + Real* head(); /*points[0] if INCREASING, points[n-1] otherwise*/ + Real* tail(); /*points[n-1] if INCREASING, points[0] otherwise*/ + Real* getVertex(Int i); /*points[i] if INCREASING, points[n-1-i] otherwise*/ + Int get_npoints() {return sline->get_npoints();} + directedLine* getPrev() {return prev;} + directedLine* getNext() {return next;} + directedLine* getNextPolygon() {return nextPolygon;} + sampledLine* getSampledLine() {return sline;} + + short getDirection(){return direction;} + void putDirection(short dir) {direction = dir;} + void putPrev(directedLine *p) {prev = p;} + void putNext(directedLine *p) {next = p;} + + /*insert a new line between prev and this*/ + void insert(directedLine* nl); + + /*delete all the polygons following the link: nextPolygon. + *notice that sampledLine is not deleted. The caller is + *responsible for that + */ + void deletePolygonList(); + void deleteSinglePolygon(); + + void deleteSinglePolygonWithSline(); //also delete sanmpled line + void deletePolygonListWithSline(); //also delete sanmpled line + + void deleteSingleLine(directedLine* dline); + directedLine* deleteDegenerateLines(); + directedLine* deleteDegenerateLinesAllPolygons(); + directedLine* cutIntersectionAllPoly(int& cutOccur); + + /*check to see if the list forms a closed polygon + *return 1 if yes + */ + short isPolygon(); + + Int compInY(directedLine* nl); + Int compInX(directedLine* nl); + + /*return an array of pointers. + *the + */ + directedLine** sortAllPolygons(); + + Int numEdges(); + Int numEdgesAllPolygons(); + Int numPolygons(); + + /*check if the head of this edge is connected to + *the tail of the prev + */ + short isConnected(); + + Real polyArea(); + + void printSingle(); + void printList(); + void printAllPolygons(); + void writeAllPolygons(char* filename); + + + /*insert a polygon: using nextPolygon*/ + directedLine* insertPolygon(directedLine* newpolygon); + directedLine* cutoffPolygon(directedLine *p); + + Int toArraySinglePolygon(directedLine** array, Int index); + directedLine** toArrayAllPolygons(Int& total_num_edges); + + void connectDiagonal(directedLine* v1, directedLine* v2, + directedLine** ret_p1, + directedLine** ret_p2, + sampledLine** generatedLine, directedLine* list); + + /*generate two slines + */ + void connectDiagonal_2slines(directedLine* v1, directedLine* v2, + directedLine** ret_p1, + directedLine** ret_p2, + directedLine* list); + + Int samePolygon(directedLine* v1, directedLine* v2); + void setRootBit() {rootBit = 1;} + void resetRootBit() {rootBit = 0;} + directedLine* findRoot(); + + void rootLinkSet(directedLine* r) {rootLink = r;} + directedLine* rootLinkFindRoot(); + + //the chain from begin to end is deleted (the space is deallocated) + //and a new edge(which connectes the head of begin and the tail of end) + // is inserted. The new polygon is returned. + //notice that "this" is arbitrary + directedLine* deleteChain(directedLine* begin, directedLine* end); +}; + +directedLine* readAllPolygons(char* filename); + +extern Int compV2InY(Real A[2], Real B[2]); +extern Int compV2InX(Real A[2], Real B[2]); + +#endif + diff --git a/src/glu/sgi/libnurbs/nurbtess/glimports.h b/src/glu/sgi/libnurbs/nurbtess/glimports.h new file mode 100644 index 0000000..6e69feb --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/glimports.h @@ -0,0 +1,42 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * glimports.h + * + */ + +#ifndef __gluimports_h_ +#define __gluimports_h_ + +#include "mystdlib.h" +#include "mystdio.h" + +#endif /* __gluimports_h_ */ diff --git a/src/glu/sgi/libnurbs/nurbtess/gridWrap.cc b/src/glu/sgi/libnurbs/nurbtess/gridWrap.cc new file mode 100644 index 0000000..3c92039 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/gridWrap.cc @@ -0,0 +1,293 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include "gluos.h" +#include +#include +#include +#include "zlassert.h" +#include "gridWrap.h" + + +/*******************grid structure****************************/ +void gridWrap::print() +{ + printf("n_ulines = %i\n", n_ulines); + printf("n_vlines = %i\n", n_vlines); + printf("u_min=%f, umax=%f, vmin=%f, vmax=%f\n", u_min, u_max, v_min, v_max); +} + +gridWrap::gridWrap(Int nUlines, Real* uvals, + Int nVlines, Real* vvals) +{ + assert(nUlines>=2); + assert(nVlines>=2); + + is_uniform = 0; + n_ulines = nUlines; + n_vlines = nVlines; + u_min = uvals[0]; + u_max = uvals[nUlines-1]; + v_min = vvals[0]; + v_max = vvals[nVlines-1]; + u_values = (Real*) malloc(sizeof(Real) * n_ulines); + assert(u_values); + v_values = (Real*) malloc(sizeof(Real) * n_vlines); + assert(v_values); + + Int i; + for(i=0; i=2); + assert(nVlines>=2); + Real du = (uMax-uMin)/(nUlines-1); + Real dv = (vMax-vMin)/(nVlines-1); + + float tempu=uMin; + u_values[0] = tempu; + for(i=1; i= uright) + return; //no triangles to output. + + pStream->begin(); + pStream->insert(vert); + + assert(vert[1] != v_values[v]); //don't output degenerate triangles + + if(vert[1] > v_values[v]) //vertex is above this grid line: notice the orientation + { + for(i=uleft; i<=uright; i++) + pStream->insert(u_values[i], v_values[v]); + } + else //vertex is below the grid line + { + for(i=uright; i>= uleft; i--) + pStream->insert(u_values[i], v_values[v]); + } + + pStream->end(PRIMITIVE_STREAM_FAN); +} + + + +/*each chain stores a number of consecutive + *V-lines within a grid. + *There is one grid vertex on each V-line. + * The total number of V-lines is: + * nVlines. + * with respect to the grid, the index of the first V-line is + * firstVlineIndex. + * So with respect to the grid, the index of the ith V-line is + * firstVlineIndex-i. + * the grid-index of the uline at the ith vline (recall that each vline has one grid point) + * is ulineIndices[i]. The u_value is cached in ulineValues[i], that is, + * ulineValues[i] = grid->get_u_value(ulineIndices[i]) + */ +gridBoundaryChain::gridBoundaryChain( + gridWrap* gr, + Int first_vline_index, + Int n_vlines, + Int* uline_indices, + Int* inner_indices + ) +: grid(gr), firstVlineIndex(first_vline_index), nVlines(n_vlines) +{ + ulineIndices = (Int*) malloc(sizeof(Int) * n_vlines); + assert(ulineIndices); + + innerIndices = (Int*) malloc(sizeof(Int) * n_vlines); + assert(innerIndices); + + vertices = (Real2*) malloc(sizeof(Real2) * n_vlines); + assert(vertices); + + + + Int i; + for(i=0; iget_u_value(ulineIndices[i]); + vertices[i][1] = gr->get_v_value(first_vline_index-i); + } +} + +void gridBoundaryChain::draw() +{ + Int i; + glBegin(GL_LINE_STRIP); + for(i=0; iget_u_value(innerIndices[i]), get_v_value(i-1) ); + glVertex2f(grid->get_u_value(innerIndices[i]), get_v_value(i) ); + glEnd(); + } +} + +Int gridBoundaryChain::lookfor(Real v, Int i1, Int i2) +{ + Int mid; + while(i1 < i2-1) + { + mid = (i1+i2)/2; + if(v > vertices[mid][1]) + { + i2 = mid; + } + else + i1 = mid; + } + return i1; +} + +/*output the fan of the right end between grid line i-1 and grid line i*/ +void gridBoundaryChain::rightEndFan(Int i, primStream* pStream) +{ + Int j; + if(getUlineIndex(i) > getUlineIndex(i-1)) + { + pStream->begin(); + pStream->insert(get_vertex(i-1)); + for(j=getUlineIndex(i-1); j<= getUlineIndex(i); j++) + pStream->insert(grid->get_u_value(j), get_v_value(i)); + pStream->end(PRIMITIVE_STREAM_FAN); + } + else if(getUlineIndex(i) < getUlineIndex(i-1)) + { + pStream->begin(); + pStream->insert(get_vertex(i)); + for(j=getUlineIndex(i-1); j>= getUlineIndex(i); j--) + pStream->insert(grid->get_u_value(j), get_v_value(i-1)); + pStream->end(PRIMITIVE_STREAM_FAN); + } + //otherside, the two are equal, so there is no fan to output +} + + +/*output the fan of the left end between grid line i-1 and grid line i*/ +void gridBoundaryChain::leftEndFan(Int i, primStream* pStream) +{ + Int j; + if(getUlineIndex(i) < getUlineIndex(i-1)) + { + pStream->begin(); + pStream->insert(get_vertex(i-1)); + for(j=getUlineIndex(i); j<= getUlineIndex(i-1); j++) + pStream->insert(grid->get_u_value(j), get_v_value(i)); + pStream->end(PRIMITIVE_STREAM_FAN); + } + else if(getUlineIndex(i) > getUlineIndex(i-1)) + { + pStream->begin(); + pStream->insert(get_vertex(i)); + for(j=getUlineIndex(i); j>= getUlineIndex(i-1); j--) + pStream->insert(grid->get_u_value(j), get_v_value(i-1)); + pStream->end(PRIMITIVE_STREAM_FAN); + } + /*otherwisem, the two are equal, so there is no fan to outout*/ +} diff --git a/src/glu/sgi/libnurbs/nurbtess/gridWrap.h b/src/glu/sgi/libnurbs/nurbtess/gridWrap.h new file mode 100644 index 0000000..b642848 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/gridWrap.h @@ -0,0 +1,137 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _GRIDWRAP_H +#define _GRIDWRAP_H + +#include +#include "definitions.h" + +#include "primitiveStream.h" +#include "zlassert.h" + +class gridWrap{ + Int n_ulines; + Int n_vlines; + Real u_min, u_max; + Real v_min, v_max; + + /*cache the coordinate values for efficiency. + *these are redundant information when + *the grid is uniform. + */ + Real* u_values; /*size is n_ulines*/ + Real* v_values; /*size is n_vlines*/ + + Int is_uniform; + +public: + //uniform grid constructor + gridWrap(Int nUlines, Int nVlines, + Real uMin, Real uMax, + Real vMin, Real vMax + ); + + //nonuniform grid constructor. + gridWrap(Int nUlines, Real *uvals, + Int nVlines, Real *vvlas + ); + ~gridWrap(); + + void print(); + Int get_n_ulines() {return n_ulines;} + Int get_n_vlines() {return n_vlines;} + Real get_u_min() {return u_min;} + Real get_u_max() {return u_max;} + Real get_v_min() {return v_min;} + Real get_v_max() {return v_max;} + + Real get_u_value(Int i) + { + assert(i=n_ulines){printf("ERROR, n_ulines=%i,i=%i\n",n_ulines,i);exit(0);}*/ + return u_values[i];} + Real get_v_value(Int j) {return v_values[j];} + + Real* get_u_values() {return u_values;} + Real* get_v_values() {return v_values;} + + void outputFanWithPoint(Int v, Int uleft, Int uright, + Real vert[2], primStream* pStream); + + void draw(); + + Int isUniform() {return is_uniform;} +}; + +class gridBoundaryChain{ + gridWrap* grid; + Int firstVlineIndex; + Int nVlines; + Int* ulineIndices; /*each v line has a boundary*/ + Int* innerIndices; /*the segment of the vertical gridline from */ + /*(innerIndices[i], i) to (innerIndices[i+1], i-1) */ + /*is inside the polygon: i=1,...,nVlines-1*/ + + Real2* vertices; /*one grid point at each grid V-line, cached for efficiency*/ + +public: + gridBoundaryChain(gridWrap* gr, Int first_vline_index, Int n_vlines, Int* uline_indices, Int* inner_indices); + + ~gridBoundaryChain() + { + free(innerIndices); + free(ulineIndices); + free(vertices); + } + + /*i indexes the vlines in this chain. + */ + Int getVlineIndex(Int i) {return firstVlineIndex-i;} + Int getUlineIndex(Int i) {return ulineIndices[i];} + Real get_u_value(Int i) {return vertices[i][0];} + Real get_v_value(Int i) {return vertices[i][1];} + Int get_nVlines() {return nVlines;} + Int getInnerIndex(Int i) {return innerIndices[i];} + Real getInner_u_value(Int i) {return grid->get_u_value(innerIndices[i]);} + + Real* get_vertex(Int i) {return vertices[i];} + gridWrap* getGrid() {return grid;} + void leftEndFan(Int i, primStream* pStream); + void rightEndFan(Int i, primStream* pStream); + + Int lookfor(Real v, Int i1, Int i2); //find i in [i1,i2] so that vertices[i][1]>= v > vertices[i+1][1] + void draw(); + void drawInner(); +}; + +#endif diff --git a/src/glu/sgi/libnurbs/nurbtess/monoChain.cc b/src/glu/sgi/libnurbs/nurbtess/monoChain.cc new file mode 100644 index 0000000..cb28129 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/monoChain.cc @@ -0,0 +1,936 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include "gluos.h" +#include +#include +#include + +#include "glimports.h" +#include "zlassert.h" + +#include "monoChain.h" +#include "quicksort.h" +#include "searchTree.h" +#include "polyUtil.h" + +#ifndef max +#define max(a,b) ((a>b)? a:b) +#endif +#ifndef min +#define min(a,b) ((a>b)? b:a) +#endif + +extern Int isCusp(directedLine *v); +extern Int deleteRepeatDiagonals(Int num_diagonals, directedLine** diagonal_vertices, directedLine** new_vertices); + +//for debug purpose only +#if 0 // UNUSED +static void drawDiagonals(Int num_diagonals, directedLine** diagonal_vertices) +{ + Int i; + for(i=0; ihead()); + glVertex2fv(diagonal_vertices[2*i+1]->head()); + glEnd(); + } +} +#endif + +/*given (x_1, y_1) and (x_2, y_2), and y + *return x such that (x,y) is on the line + */ +inline Real intersectHoriz(Real x1, Real y1, Real x2, Real y2, Real y) +{ + return ((y2==y1)? (x1+x2)*0.5 : x1 + ((y-y1)/(y2-y1)) * (x2-x1)); +} + +//compare the heads of the two chains +static int compChainHeadInY(monoChain* mc1, monoChain* mc2) +{ + return compV2InY(mc1->getHead()->head(), mc2->getHead()->head()); +} + +monoChain::monoChain(directedLine* cHead, directedLine* cTail) +{ + chainHead = cHead; + chainTail = cTail; + next = this; + prev = this; + + nextPolygon = NULL; + + //compute bounding box + directedLine* temp; + minX = maxX = chainTail->head()[0]; + minY = maxY = chainTail->head()[1]; + + for(temp=chainHead; temp!=cTail; temp = temp->getNext()) + { + if(temp->head()[0] < minX) + minX = temp->head()[0]; + if(temp->head()[0] > maxX) + maxX = temp->head()[0]; + + if(temp->head()[1] < minY) + minY = temp->head()[1]; + if(temp->head()[1] > maxY) + maxY = temp->head()[1]; + } + + //check whether the chain is increasing or decreasing + if(chainHead->compInY(chainTail) <0) + isIncrease = 1; + else + isIncrease = 0; + + //initilize currrent, this is used for accelerating search + if(isIncrease) + current = chainHead; + else + current = chainTail; + + isKey = 0; + keyY = 0; +} + +//insert a new line between prev and this +void monoChain::insert(monoChain* nc) +{ + nc->next = this; + nc->prev = prev; + prev->next = nc; + prev = nc; +} + +void monoChain::deleteLoop() +{ + monoChain *temp, *tempNext; + prev->next = NULL; + for(temp=this; temp != NULL; temp = tempNext) + { + tempNext = temp->next; + delete temp; + } +} + +void monoChain::deleteLoopList() +{ + monoChain *temp, *tempNext; + for(temp=this; temp != NULL; temp = tempNext) + { + tempNext = temp->nextPolygon; + temp->deleteLoop(); + } +} + +Int monoChain::toArraySingleLoop(monoChain** array, Int index) +{ + monoChain *temp; + array[index++] = this; + for(temp = next; temp != this; temp = temp->next) + { + array[index++] = temp; + } + return index; +} + +monoChain** monoChain::toArrayAllLoops(Int& num_chains) +{ + num_chains = numChainsAllLoops(); + monoChain **ret = (monoChain**) malloc(sizeof(monoChain*) * num_chains); + assert(ret); + monoChain *temp; + Int index = 0; + for(temp = this; temp != NULL; temp=temp->nextPolygon){ + index = temp->toArraySingleLoop(ret, index); + } + return ret; +} + +Int monoChain::numChainsSingleLoop() +{ + Int ret=0; + monoChain* temp; + if(next == this) return 1; + ret = 1; + for(temp=next; temp != this; temp = temp->next) + ret++; + return ret; +} + +Int monoChain::numChainsAllLoops() +{ + Int ret=0; + monoChain *temp; + for(temp =this; temp != NULL; temp = temp->nextPolygon) + ret += temp->numChainsSingleLoop(); + return ret; +} + +//update 'current' +Real monoChain::chainIntersectHoriz(Real y) +{ + directedLine* temp; + if(isIncrease) + { + for(temp= current; temp != chainTail; temp = temp->getNext()) + { + if(temp->head()[1] > y) + break; + } + current = temp->getPrev(); + } + else + { + for(temp = current; temp != chainHead; temp = temp->getPrev()) + { + if(temp->head()[1] > y) + break; + } + current = temp->getNext(); + } + return intersectHoriz(current->head()[0], current->head()[1], current->tail()[0], current->tail()[1], y); +} + +monoChain* directedLineLoopToMonoChainLoop(directedLine* loop) +{ + directedLine *temp; + monoChain *ret=NULL; + + //find the first cusp + directedLine *prevCusp=NULL; + directedLine *firstCusp; + + if(isCusp(loop)) + prevCusp = loop; + else + { + for(temp = loop->getNext(); temp != loop; temp = temp->getNext()) + if(isCusp(temp)) + break; + prevCusp = temp; + } + firstCusp = prevCusp; +//printf("first cusp is (%f,%f), (%f,%f), (%f,%f)\n", prevCusp->getPrev()->head()[0], prevCusp->getPrev()->head()[1], prevCusp->head()[0], prevCusp->head()[1], prevCusp->tail()[0], prevCusp->tail()[1]); + + for(temp = prevCusp->getNext(); temp != loop; temp = temp->getNext()) + { + if(isCusp(temp)) + { +//printf("the cusp is (%f,%f), (%f,%f), (%f,%f)\n", temp->getPrev()->head()[0], temp->getPrev()->head()[1], temp->head()[0], temp->head()[1], temp->tail()[0], temp->tail()[1]); + if(ret == NULL) + { + ret = new monoChain(prevCusp, temp); + } + else + ret->insert(new monoChain(prevCusp, temp)); + prevCusp = temp; + } + } + assert(ret); + ret->insert(new monoChain(prevCusp, firstCusp)); + + return ret; +} + +monoChain* directedLineLoopListToMonoChainLoopList(directedLine* list) +{ + directedLine* temp; + monoChain* mc; + monoChain* mcEnd; + mc = directedLineLoopToMonoChainLoop(list); + mcEnd = mc; + for(temp = list->getNextPolygon(); temp != NULL; temp = temp->getNextPolygon()) + { + monoChain *newLoop = directedLineLoopToMonoChainLoop(temp); + mcEnd->setNextPolygon(newLoop); + mcEnd = newLoop; + } + return mc; +} + +/*compare two edges of a polygon. + *edge A < edge B if there is a horizontal line so that the intersection + *with A is to the left of the intersection with B. + *This function is used in sweepY for the dynamic search tree insertion to + *order the edges. + * Implementation: (x_1,y_1) and (x_2, y_2) + */ +static Int compEdges(directedLine *e1, directedLine *e2) +{ + Real* head1 = e1->head(); + Real* tail1 = e1->tail(); + Real* head2 = e2->head(); + Real* tail2 = e2->tail(); +/* + Real h10 = head1[0]; + Real h11 = head1[1]; + Real t10 = tail1[0]; + Real t11 = tail1[1]; + Real h20 = head2[0]; + Real h21 = head2[1]; + Real t20 = tail2[0]; + Real t21 = tail2[1]; +*/ + Real e1_Ymax, e1_Ymin, e2_Ymax, e2_Ymin; +/* + if(h11>t11) { + e1_Ymax= h11; + e1_Ymin= t11; + } + else{ + e1_Ymax = t11; + e1_Ymin = h11; + } + + if(h21>t21) { + e2_Ymax= h21; + e2_Ymin= t21; + } + else{ + e2_Ymax = t21; + e2_Ymin = h21; + } +*/ + + if(head1[1]>tail1[1]) { + e1_Ymax= head1[1]; + e1_Ymin= tail1[1]; + } + else{ + e1_Ymax = tail1[1]; + e1_Ymin = head1[1]; + } + + if(head2[1]>tail2[1]) { + e2_Ymax= head2[1]; + e2_Ymin= tail2[1]; + } + else{ + e2_Ymax = tail2[1]; + e2_Ymin = head2[1]; + } + + + /*Real e1_Ymax = max(head1[1], tail1[1]);*/ /*max(e1->head()[1], e1->tail()[1]);*/ + /*Real e1_Ymin = min(head1[1], tail1[1]);*/ /*min(e1->head()[1], e1->tail()[1]);*/ + /*Real e2_Ymax = max(head2[1], tail2[1]);*/ /*max(e2->head()[1], e2->tail()[1]);*/ + /*Real e2_Ymin = min(head2[1], tail2[1]);*/ /*min(e2->head()[1], e2->tail()[1]);*/ + + Real Ymax = min(e1_Ymax, e2_Ymax); + Real Ymin = max(e1_Ymin, e2_Ymin); + + Real y = 0.5*(Ymax + Ymin); + +/* Real x1 = intersectHoriz(e1->head()[0], e1->head()[1], e1->tail()[0], e1->tail()[1], y); + Real x2 = intersectHoriz(e2->head()[0], e2->head()[1], e2->tail()[0], e2->tail()[1], y); +*/ +/* + Real x1 = intersectHoriz(h10, h11, t10, t11, y); + Real x2 = intersectHoriz(h20, h21, t20, t21, y); +*/ + Real x1 = intersectHoriz(head1[0], head1[1], tail1[0], tail1[1], y); + Real x2 = intersectHoriz(head2[0], head2[1], tail2[0], tail2[1], y); + + if(x1<= x2) return -1; + else return 1; +} + +Int compChains(monoChain* mc1, monoChain* mc2) +{ + Real y; + assert(mc1->isKey || mc2->isKey); + if(mc1->isKey) + y = mc1->keyY; + else + y = mc2->keyY; + directedLine *d1 = mc1->find(y); + directedLine *d2 = mc2->find(y); + mc2->find(y); +// Real x1 = mc1->chainIntersectHoriz(y); +// Real x2 = mc2->chainIntersectHoriz(y); + return compEdges(d1, d2); +} + +//this function modifies current for efficiency +directedLine* monoChain::find(Real y) +{ + directedLine *ret; + directedLine *temp; + assert(current->head()[1] <= y); + if(isIncrease) + { + assert(chainTail->head()[1] >=y); + for(temp=current; temp!=chainTail; temp = temp->getNext()) + { + if(temp->head()[1] > y) + break; + } + current = temp->getPrev(); + ret = current; + } + else + { + for(temp=current; temp != chainHead; temp = temp->getPrev()) + { + if(temp->head()[1] > y) + break; + } + current = temp->getNext(); + ret = temp; + } + return ret; +} + +void monoChain::printOneChain() +{ + directedLine* temp; + for(temp = chainHead; temp != chainTail; temp = temp->getNext()) + { + printf("(%f,%f) ", temp->head()[0], temp->head()[1]); + } + printf("(%f,%f) \n", chainTail->head()[0], chainTail->head()[1]); +} + +void monoChain::printChainLoop() +{ + monoChain* temp; + this->printOneChain(); + for(temp = next; temp != this; temp = temp->next) + { + temp->printOneChain(); + } + printf("\n"); +} + +void monoChain::printAllLoops() +{ + monoChain* temp; + for(temp=this; temp != NULL; temp = temp->nextPolygon) + temp->printChainLoop(); +} + +//return 1 if error occures +Int MC_sweepY(Int nVertices, monoChain** sortedVertices, sweepRange** ret_ranges) +{ + Int i; + Real keyY; + Int errOccur=0; +//printf("enter MC_sweepY\n"); +//printf("nVertices=%i\n", nVertices); + /*for each vertex in the sorted list, update the binary search tree. + *and store the range information for each vertex. + */ + treeNode* searchTree = NULL; +//printf("nVertices=%i\n", nVertices); + for(i=0; igetHead()->head()[1]; //the sweep line + directedLine *dline = vert->getHead(); + directedLine *dlinePrev = dline->getPrev(); + if(isBelow(dline, dline) && isBelow(dline, dlinePrev)) + { +//printf("case 1\n"); + //thisisKey = 1; + vert->keyY = keyY; + treeNode* thisNode = TreeNodeFind(searchTree, vert, (Int (*) (void *, void *))compChains); + vert->isKey = 0; + + vert->getPrev()->isKey = 1; + vert->getPrev()->keyY = keyY; + treeNode* prevNode = TreeNodeFind(searchTree, vert->getPrev(), (Int (*) (void *, void *))compChains); + vert->getPrev()->isKey = 0; + + if(cuspType(dline) == 1)//interior cusp + { + + treeNode* leftEdge = TreeNodePredecessor(prevNode); + treeNode* rightEdge = TreeNodeSuccessor(thisNode); + if(leftEdge == NULL || rightEdge == NULL) + { + errOccur = 1; + goto JUMP_HERE; + } + + directedLine* leftEdgeDline = ((monoChain* ) leftEdge->key)->find(keyY); + + + + directedLine* rightEdgeDline = ((monoChain* ) rightEdge->key)->find(keyY); + + ret_ranges[i] = sweepRangeMake(leftEdgeDline, 1, rightEdgeDline, 1); + } + else /*exterior cusp*/ + { + ret_ranges[i] = sweepRangeMake( dline, 1, dlinePrev, 1); + } + + searchTree = TreeNodeDeleteSingleNode(searchTree, thisNode); + searchTree = TreeNodeDeleteSingleNode(searchTree, prevNode); + + } + else if(isAbove(dline, dline) && isAbove(dline, dlinePrev)) + { +//printf("case 2\n"); + //insert both edges + treeNode* thisNode = TreeNodeMake(vert); + treeNode* prevNode = TreeNodeMake(vert->getPrev()); + + vert->isKey = 1; + vert->keyY = keyY; + searchTree = TreeNodeInsert(searchTree, thisNode, (Int (*) (void *, void *))compChains); + vert->isKey = 0; + + vert->getPrev()->isKey = 1; + vert->getPrev()->keyY = keyY; + searchTree = TreeNodeInsert(searchTree, prevNode, (Int (*) (void *, void *))compChains); + vert->getPrev()->isKey = 0; + + if(cuspType(dline) == 1) //interior cusp + { +//printf("cuspType is 1\n"); + treeNode* leftEdge = TreeNodePredecessor(thisNode); + treeNode* rightEdge = TreeNodeSuccessor(prevNode); + if(leftEdge == NULL || rightEdge == NULL) + { + errOccur = 1; + goto JUMP_HERE; + } +//printf("leftEdge is %i, rightEdge is %i\n", leftEdge, rightEdge); + directedLine* leftEdgeDline = ((monoChain*) leftEdge->key)->find(keyY); + directedLine* rightEdgeDline = ((monoChain*) rightEdge->key)->find(keyY); + ret_ranges[i] = sweepRangeMake( leftEdgeDline, 1, rightEdgeDline, 1); + } + else //exterior cusp + { +//printf("cuspType is not 1\n"); + ret_ranges[i] = sweepRangeMake(dlinePrev, 1, dline, 1); + } + } + else + { +//printf("%i,%i\n", isAbove(dline, dline), isAbove(dline, dlinePrev)); + errOccur = 1; + goto JUMP_HERE; + + fprintf(stderr, "error in MC_sweepY\n"); + exit(1); + } + } + + JUMP_HERE: + //finally clean up space: delete the search tree + TreeNodeDeleteWholeTree(searchTree); + return errOccur; +} + +void MC_findDiagonals(Int total_num_edges, monoChain** sortedVertices, + sweepRange** ranges, Int& num_diagonals, + directedLine** diagonal_vertices) +{ + Int i,j,k; + k=0; + //reset 'current' of all the monoChains + for(i=0; iresetCurrent(); + + for(i=0; igetHead(); + directedLine* thisEdge = vert; + directedLine* prevEdge = vert->getPrev(); + if(isBelow(vert, thisEdge) && isBelow(vert, prevEdge) && compEdges(prevEdge, thisEdge)<0) + { + //this is an upward interior cusp + diagonal_vertices[k++] = vert; + + directedLine* leftEdge = ranges[i]->left; + directedLine* rightEdge = ranges[i]->right; + + directedLine* leftVert = leftEdge; + directedLine* rightVert = rightEdge->getNext(); + assert(leftVert->head()[1] >= vert->head()[1]); + assert(rightVert->head()[1] >= vert->head()[1]); + directedLine* minVert = (leftVert->head()[1] <= rightVert->head()[1])?leftVert:rightVert; + Int found = 0; + for(j=i+1; jgetHead()->head()[1] > minVert->head()[1]) + break; + + if(sweepRangeEqual(ranges[i], ranges[j])) + { + found = 1; + break; + } + } + + if(found) + diagonal_vertices[k++] = sortedVertices[j]->getHead(); + else + diagonal_vertices[k++] = minVert; + } + else if(isAbove(vert, thisEdge) && isAbove(vert, prevEdge) && compEdges(prevEdge, thisEdge)>0) + { + //downward interior cusp + diagonal_vertices[k++] = vert; + directedLine* leftEdge = ranges[i]->left; + directedLine* rightEdge = ranges[i]->right; + directedLine* leftVert = leftEdge->getNext(); + directedLine* rightVert = rightEdge; + assert(leftVert->head()[1] <= vert->head()[1]); + assert(rightVert->head()[1] <= vert->head()[1]); + directedLine* maxVert = (leftVert->head()[1] > rightVert->head()[1])? leftVert:rightVert; + Int found=0; + for(j=i-1; j>=0; j--) + { + if(sortedVertices[j]->getHead()->head()[1] < maxVert->head()[1]) + break; + if(sweepRangeEqual(ranges[i], ranges[j])) + { + found = 1; + break; + } + } + if(found) + diagonal_vertices[k++] = sortedVertices[j]->getHead(); + else + diagonal_vertices[k++] = maxVert; + } + } + num_diagonals = k/2; +} + + + + +directedLine* MC_partitionY(directedLine *polygons, sampledLine **retSampledLines) +{ +//printf("enter mc_partitionY\n"); + Int total_num_chains = 0; + monoChain* loopList = directedLineLoopListToMonoChainLoopList(polygons); + monoChain** array = loopList->toArrayAllLoops(total_num_chains); + + if(total_num_chains<=2) //there is just one single monotone polygon + { + loopList->deleteLoopList(); + free(array); + *retSampledLines = NULL; + return polygons; + } + +//loopList->printAllLoops(); +//printf("total_num_chains=%i\n", total_num_chains); + quicksort( (void**)array, 0, total_num_chains-1, (Int (*)(void*, void*))compChainHeadInY); +//printf("after quicksort\n"); + + sweepRange** ranges = (sweepRange**)malloc(sizeof(sweepRange*) * (total_num_chains)); + assert(ranges); + + if(MC_sweepY(total_num_chains, array, ranges)) + { + loopList->deleteLoopList(); + free(array); + *retSampledLines = NULL; + return NULL; + } +//printf("after MC_sweepY\n"); + + + Int num_diagonals; + /*number diagonals is < total_num_edges*total_num_edges*/ + directedLine** diagonal_vertices = (directedLine**) malloc(sizeof(directedLine*) * total_num_chains*2/*total_num_edges*/); + assert(diagonal_vertices); + +//printf("before call MC_findDiagonales\n"); + + MC_findDiagonals(total_num_chains, array, ranges, num_diagonals, diagonal_vertices); +//printf("after call MC_findDia, num_diagnla=%i\n", num_diagonals); + + directedLine* ret_polygons = polygons; + sampledLine* newSampledLines = NULL; + Int i,k; + + num_diagonals=deleteRepeatDiagonals(num_diagonals, diagonal_vertices, diagonal_vertices); + + + +//drawDiagonals(num_diagonals, diagonal_vertices); +//printf("diagoanls are \n"); +//for(i=0; ihead()[0], diagonal_vertices[2*i]->head()[1]); +// printf("**(%f,%f)\n", diagonal_vertices[2*i+1]->head()[0], diagonal_vertices[2*i+1]->head()[1]); +// } + + Int *removedDiagonals=(Int*)malloc(sizeof(Int) * num_diagonals); + for(i=0; ifindRoot(); + directedLine *root2 = v2->findRoot(); + assert(root1); + assert(root2); +*/ + +directedLine* root1 = v1->rootLinkFindRoot(); +directedLine* root2 = v2->rootLinkFindRoot(); + + if(root1 != root2) + { + + removedDiagonals[i] = 1; + sampledLine* generatedLine; + + + + v1->connectDiagonal(v1,v2, &ret_p1, &ret_p2, &generatedLine, ret_polygons); + + + + newSampledLines = generatedLine->insert(newSampledLines); +/* + ret_polygons = ret_polygons->cutoffPolygon(root1); + + ret_polygons = ret_polygons->cutoffPolygon(root2); + ret_polygons = ret_p1->insertPolygon(ret_polygons); +root1->rootLinkSet(ret_p1); +root2->rootLinkSet(ret_p1); +ret_p1->rootLinkSet(NULL); +ret_p2->rootLinkSet(ret_p1); +*/ + ret_polygons = ret_polygons->cutoffPolygon(root2); + + + +root2->rootLinkSet(root1); +ret_p1->rootLinkSet(root1); +ret_p2->rootLinkSet(root1); + + /*now that we have connected the diagonal v1 and v2, + *we have to check those unprocessed diagonals which + *have v1 or v2 as an end point. Notice that the head of v1 + *has the same coodinates as the head of v2->prev, and the head of + *v2 has the same coordinate as the head of v1->prev. + *Suppose these is a diagonal (v1, x). If (v1,x) is still a valid + *diagonal, then x should be on the left hand side of the directed line: *v1->prev->head -- v1->head -- v1->tail. Otherwise, (v1,x) should be + *replaced by (v2->prev, x), that is, x is on the left of + * v2->prev->prev->head, v2->prev->head, v2->prev->tail. + */ + Int ii, kk; + for(ii=0, kk=0; iiprev->head:v1->head:v1->tail*/ + if(! pointLeft2Lines(v1->getPrev()->head(), + v1->head(), v1->tail(), d2->head())) + { +/* + assert(pointLeft2Lines(v2->getPrev()->getPrev()->head(), + v2->getPrev()->head(), + v2->getPrev()->tail(), d2->head())); +*/ + diagonal_vertices[kk] = v2->getPrev(); + } + } + if(d1 == v2) { + /*check if d2 is to left of v2->prev->head:v2->head:v2->tail*/ + if(! pointLeft2Lines(v2->getPrev()->head(), + v2->head(), v2->tail(), d2->head())) + { +/* + assert(pointLeft2Lines(v1->getPrev()->getPrev()->head(), + v1->getPrev()->head(), + v1->getPrev()->tail(), d2->head())); +*/ + diagonal_vertices[kk] = v1->getPrev(); + } + } + /*check d2 and replace diagonal_vertices[k+1] if necessary*/ + if(d2 == v1) { + /*check if d1 is to left of v1->prev->head:v1->head:v1->tail*/ + if(! pointLeft2Lines(v1->getPrev()->head(), + v1->head(), v1->tail(), d1->head())) + { +/* assert(pointLeft2Lines(v2->getPrev()->getPrev()->head(), + v2->getPrev()->head(), + v2->getPrev()->tail(), d1->head())); +*/ + diagonal_vertices[kk+1] = v2->getPrev(); + } + } + if(d2 == v2) { + /*check if d1 is to left of v2->prev->head:v2->head:v2->tail*/ + if(! pointLeft2Lines(v2->getPrev()->head(), + v2->head(), v2->tail(), d1->head())) + { +/* assert(pointLeft2Lines(v1->getPrev()->getPrev()->head(), + v1->getPrev()->head(), + v1->getPrev()->tail(), d1->head())); +*/ + diagonal_vertices[kk+1] = v1->getPrev(); + } + } + } +}/*end if (root1 not equal to root 2)*/ +} + + /*second pass, now all diagoals should belong to the same polygon*/ +//printf("second pass: \n"); + +// for(i=0; ifindRoot(); +/* + directedLine *root2 = v2->findRoot(); + + + + assert(root1); + assert(root2); + assert(root1 == root2); + */ + sampledLine* generatedLine; + + + + v1->connectDiagonal(v1,v2, &ret_p1, &ret_p2, &generatedLine, ret_polygons); + newSampledLines = generatedLine->insert(newSampledLines); + + ret_polygons = ret_polygons->cutoffPolygon(root1); + + ret_polygons = ret_p1->insertPolygon(ret_polygons); + + ret_polygons = ret_p2->insertPolygon(ret_polygons); + + + + for(Int j=i+1; jsamePolygon(temp1, temp2)) + { + /*if temp1 and temp2 are in different polygons, + *then one of them must be v1 or v2. + */ + + + + assert(temp1==v1 || temp1 == v2 || temp2==v1 || temp2 ==v2); + if(temp1==v1) + { + diagonal_vertices[2*j] = v2->getPrev(); + } + if(temp2==v1) + { + diagonal_vertices[2*j+1] = v2->getPrev(); + } + if(temp1==v2) + { + diagonal_vertices[2*j] = v1->getPrev(); + } + if(temp2==v2) + { + diagonal_vertices[2*j+1] = v1->getPrev(); + } + } + } + } + + } + + + //clean up + loopList->deleteLoopList(); + free(array); + free(ranges); + free(diagonal_vertices); + free(removedDiagonals); + + *retSampledLines = newSampledLines; + return ret_polygons; +} + + diff --git a/src/glu/sgi/libnurbs/nurbtess/monoChain.h b/src/glu/sgi/libnurbs/nurbtess/monoChain.h new file mode 100644 index 0000000..999f163 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/monoChain.h @@ -0,0 +1,103 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _MONO_CHAIN_H +#define _MONO_CHAIN_H + +#include "directedLine.h" +#include "partitionY.h" + +class monoChain; + +class monoChain{ + directedLine* chainHead; + directedLine* chainTail; + monoChain* next; + monoChain* prev; + monoChain* nextPolygon; //a list of polygons + + //cached informatin + //bounding box + Real minX, maxX, minY, maxY; + Int isIncrease; + + //for efficiently comparing two chains + + directedLine* current; + +public: + monoChain(directedLine* cHead, directedLine* cTail); + ~monoChain() {} + + inline void setNext(monoChain* n) {next = n;} + inline void setPrev(monoChain* p) {prev = p;} + inline void setNextPolygon(monoChain* np) {nextPolygon = np;} + inline monoChain* getNext() {return next;} + inline monoChain* getPrev() {return prev;} + inline directedLine* getHead() {return chainHead;} + inline directedLine* getTail() {return chainTail;} + + inline void resetCurrent() { current = ((isIncrease==1)? chainHead:chainTail);} + + void deleteLoop(); + void deleteLoopList(); + + //insert a new chain between prev and this + void insert(monoChain* nc); + + Int numChainsSingleLoop(); + Int numChainsAllLoops(); + monoChain** toArrayAllLoops(Int& num_chains); + Int toArraySingleLoop(monoChain** array, Int index); + + Int isKey; + Real keyY; //the current horizotal line + Real chainIntersectHoriz(Real y); //updates current incrementally for efficiency + directedLine* find(Real y);//find dline so that y intersects dline. + + void printOneChain(); + void printChainLoop(); + void printAllLoops(); + +}; + +monoChain* directedLineLoopToMonoChainLoop(directedLine* loop); +monoChain* directedLineLoopListToMonoChainLoopList(directedLine* list); +Int MC_sweepY(Int nVertices, monoChain** sortedVertices, sweepRange** ret_ranges); + +void MC_findDiagonals(Int total_num_edges, monoChain** sortedVertices, + sweepRange** ranges, Int& num_diagonals, + directedLine** diagonal_vertices); + +directedLine* MC_partitionY(directedLine *polygons, sampledLine **retSampledLines); + +#endif diff --git a/src/glu/sgi/libnurbs/nurbtess/monoPolyPart.cc b/src/glu/sgi/libnurbs/nurbtess/monoPolyPart.cc new file mode 100644 index 0000000..8391205 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/monoPolyPart.cc @@ -0,0 +1,299 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* + *monoPolyPart.C + * + *To partition a v-monotone polygon into some uv-monotone polygons. + *The algorithm is different from the general monotone partition algorithm. + *while the general monotone partition algorithm works for this special case, + *but it is more expensive (O(nlogn)). The algorithm implemented here takes + *advantage of the fact that the input is a v-monotone polygon and it is + *conceptually simpler and computationally cheaper (a linear time algorithm). + *The algorithm is described in Zicheng Liu's paper + * "Quality-Oriented Linear Time Tessellation". + */ + +#include +#include +#include "directedLine.h" +#include "monoPolyPart.h" + +/*a vertex is u_maximal if both of its two neightbors are to the left of this + *vertex + */ +static Int is_u_maximal(directedLine* v) +{ + if (compV2InX(v->getPrev()->head(), v->head()) == -1 && + compV2InX(v->getNext()->head(), v->head()) == -1) + return 1; + else + return 0; +} + +/*a vertex is u_minimal if both of its two neightbors are to the right of this + *vertex + */ +static Int is_u_minimal(directedLine* v) +{ + if (compV2InX(v->getPrev()->head(), v->head()) == 1 && + compV2InX(v->getNext()->head(), v->head()) == 1) + return 1; + else + return 0; +} + +/*poly: a v-monotone polygon + *return: a linked list of uv-monotone polygons. + */ +directedLine* monoPolyPart(directedLine* polygon) +{ + //handle special cases: + if(polygon == NULL) + return NULL; + if(polygon->getPrev() == polygon) + return polygon; + if(polygon->getPrev() == polygon->getNext()) + return polygon; + if(polygon->getPrev()->getPrev() == polygon->getNext()) + return polygon; + + //find the top and bottom vertexes + directedLine *tempV, *topV, *botV; + topV = botV = polygon; + for(tempV = polygon->getNext(); tempV != polygon; tempV = tempV->getNext()) + { + if(compV2InY(topV->head(), tempV->head())<0) { + topV = tempV; + } + if(compV2InY(botV->head(), tempV->head())>0) { + botV = tempV; + } + } + + //initilization + directedLine *A, *B, *C, *D, *G, *H; + //find A:the first u_maximal vertex on the left chain + //and C: the left most vertex between top and A + A = NULL; + C = topV; + for(tempV=topV->getNext(); tempV != botV; tempV = tempV->getNext()) + { + if(tempV->head()[0] < C->head()[0]) + C = tempV; + + if(is_u_maximal(tempV)) + { + A = tempV; + break; + } + } + if(A == NULL) + { + A = botV; + if(A->head()[0] < C->head()[0]) + C = A; + } + + //find B: the first u_minimal vertex on the right chain + //and D: the right most vertex between top and B + B = NULL; + D = topV; + for(tempV=topV->getPrev(); tempV != botV; tempV = tempV->getPrev()) + { + if(tempV->head()[0] > D->head()[0]) + D = tempV; + if(is_u_minimal(tempV)) + { + B = tempV; + break; + } + } + if(B == NULL) + { + B = botV; + if(B->head()[0] > D->head()[0]) + D = B; + } + + //error checking XXX + if(C->head()[0] >= D->head()[0]) + return polygon; + + //find G on the left chain that is right above B + for(tempV=topV; compV2InY(tempV->head(), B->head()) == 1; tempV=tempV->getNext()); + G = tempV->getPrev(); + //find H on the right chain that is right above A + for(tempV=topV; compV2InY(tempV->head(), A->head()) == 1; tempV = tempV->getPrev()); + H = tempV->getNext(); + + //Main Loop + directedLine* ret = NULL; + directedLine* currentPolygon = polygon; + while(1) + { + //if both B and D are equal to botV, then this polygon is already + //u-monotone + if(A == botV && B == botV) + { + ret = currentPolygon->insertPolygon(ret); + return ret; + } + else //not u-monotone + { + directedLine *ret_p1, *ret_p2; + if(compV2InY(A->head(),B->head()) == 1) //A is above B + { + directedLine* E = NULL; + for(tempV = C; tempV != D; tempV = tempV->getPrev()) + { + if(tempV->head()[0] >= A->head()[0]) + { + E = tempV; + break; + } + } + + if(E == NULL) + E = D; + if(E->head()[0]> H->head()[0]) + E = H; + //connect AE and output polygon ECA + polygon->connectDiagonal_2slines(A, E, + &ret_p1, + &ret_p2, + NULL); + ret = ret_p2->insertPolygon(ret); + currentPolygon = ret_p1; + + if(E == D) + D = ret_p1; + if(E == H) + H = ret_p1; + if(G->head()[1] >= A->head()[1]) + G = A; + //update A to be the next u-maxiaml vertex on left chain + //and C the leftmost vertex between the old A and the new A + C = A; + for(tempV = A->getNext(); tempV != botV; tempV = tempV->getNext()) + { + + if(tempV->head()[0] < C->head()[0]) + C = tempV; + if(is_u_maximal(tempV)) + { + A = tempV; + break; + } + } + + if(tempV == botV) + { + A = botV; + if(botV->head()[0] < C->head()[0]) + C = botV; + } + //update H + + if(A == botV) + H = botV; + else + { + for(tempV = H; compV2InY(tempV->head(), A->head()) == 1; tempV = tempV->getPrev()); + H = tempV->getNext(); + } + + } + else //A is below B + { + + directedLine* F = NULL; + for(tempV = D; tempV != C; tempV = tempV->getNext()) + { + if(tempV->head()[0] <= B->head()[0]) + { + F = tempV; + break; + } + } + if(F == NULL) + F = C; + if(F->head()[0] < G->head()[0]) + F = G; + + //connect FB + polygon->connectDiagonal_2slines(F, B, + &ret_p1, + &ret_p2, + NULL); + ret = ret_p2->insertPolygon(ret); + currentPolygon = ret_p1; + B = ret_p1; + if(H ->head()[1] >= B->head()[1]) + H = ret_p1; + + //update B to be the next u-minimal vertex on right chain + //and D the rightmost vertex between the old B and the new B + D = B; + for(tempV = B->getPrev(); tempV != botV; tempV = tempV->getPrev()) + { + if(tempV->head()[0] > D->head()[0]) + D = tempV; + if(is_u_minimal(tempV)) + { + B = tempV; + break; + } + } + if(tempV == botV) + { + B = botV; + if(botV->head()[0] > D->head()[0]) + D = botV; + } + //update G + if(B == botV) + G = botV; + else + { + for(tempV = G; compV2InY(tempV->head(), B->head()) == 1; tempV = tempV->getNext()); + G = tempV->getPrev(); + } + } //end of A is below B + } //end not u-monotone + } //end of main loop +} + + + diff --git a/src/glu/sgi/libnurbs/nurbtess/monoPolyPart.h b/src/glu/sgi/libnurbs/nurbtess/monoPolyPart.h new file mode 100644 index 0000000..6877a59 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/monoPolyPart.h @@ -0,0 +1,41 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* + *monoPolyPart.h + */ + +#ifndef _MONO_POLY_PART_H +#define _MONO_POLY_PART_H + +class directedLine; + +directedLine* monoPolyPart(directedLine* polygon); + +#endif diff --git a/src/glu/sgi/libnurbs/nurbtess/monoTriangulation.cc b/src/glu/sgi/libnurbs/nurbtess/monoTriangulation.cc new file mode 100644 index 0000000..8e8d49d --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/monoTriangulation.cc @@ -0,0 +1,1482 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include +#include "gluos.h" +#include "glimports.h" +#include "zlassert.h" + +#include "monoTriangulation.h" +#include "polyUtil.h" /*for area*/ +#include "partitionX.h" +#include "monoPolyPart.h" + + + +extern directedLine* polygonConvert(directedLine* polygon); + +/*poly is NOT deleted + */ +void monoTriangulationOpt(directedLine* poly, primStream* pStream) +{ + Int n_cusps; + Int n_edges = poly->numEdges(); + directedLine** cusps = (directedLine**) malloc(sizeof(directedLine*)*n_edges); + assert(cusps); + findInteriorCuspsX(poly, n_cusps, cusps); + if(n_cusps ==0) //u monotine + { + monoTriangulationFun(poly, compV2InX, pStream); + } + else if(n_cusps == 1) // one interior cusp + { + directedLine* new_polygon = polygonConvert(cusps[0]); + directedLine* other = findDiagonal_singleCuspX(new_polygon); + // should NOT be null unless there are self-intersecting + //trim curves. In that case, we don't want to core dump, instead, + //we triangulate anyway, and print out error message. + if(other == NULL) + { + monoTriangulationFun(poly, compV2InX, pStream); + } + else + { + directedLine* ret_p1; + directedLine* ret_p2; + + new_polygon->connectDiagonal_2slines(new_polygon, other, + &ret_p1, + &ret_p2, + new_polygon); + + monoTriangulationFun(ret_p1, compV2InX, pStream); + monoTriangulationFun(ret_p2, compV2InX, pStream); + + ret_p1->deleteSinglePolygonWithSline(); + ret_p2->deleteSinglePolygonWithSline(); + } + } + else + { + //we need a general partitionX funtion (supposed to be in partitionX.C, + //not implemented yet. XXX + monoTriangulationFun(poly, compV2InY, pStream); + } + + free(cusps); +} + +void monoTriangulationRecOpt(Real* topVertex, Real* botVertex, + vertexArray* left_chain, Int left_current, + vertexArray* right_chain, Int right_current, + primStream* pStream) +{ + Int i,j; + Int n_left = left_chain->getNumElements(); + Int n_right = right_chain->getNumElements(); + if(left_current>= n_left-1 || + right_current>= n_right-1) + { + monoTriangulationRec(topVertex, botVertex, left_chain, left_current, + right_chain, right_current, pStream); + return; + } + //now both left and right have at least two vertices each. + Real left_v = left_chain->getVertex(left_current)[1]; + Real right_v = right_chain->getVertex(right_current)[1]; + + if(left_v <= right_v) //first left vertex is below right + { + //find the last vertex of right which is above or equal to left + for(j=right_current; j<=n_right-1; j++) + { + if(right_chain->getVertex(j)[1] < left_v) + break; + } + monoTriangulationRecGen(topVertex, left_chain->getVertex(left_current), + left_chain, left_current, left_current, + right_chain, right_current, j-1, + pStream); + monoTriangulationRecOpt(right_chain->getVertex(j-1), + botVertex, + left_chain, left_current, + right_chain, j, + pStream); + } + else //first right vertex is strictly below left + { + //find the last vertex of left which is strictly above right + for(i=left_current; i<=n_left-1; i++) + { + if(left_chain->getVertex(i)[1] <= right_v) + break; + } + monoTriangulationRecGen(topVertex, right_chain->getVertex(right_current), + left_chain, left_current, i-1, + right_chain, right_current, right_current, + pStream); + monoTriangulationRecOpt(left_chain->getVertex(i-1), + botVertex, + left_chain, i, + right_chain, right_current, + pStream); + } +} + + +void monoTriangulationRecGenTBOpt(Real* topVertex, Real* botVertex, + vertexArray* inc_chain, Int inc_current, Int inc_end, + vertexArray* dec_chain, Int dec_current, Int dec_end, + primStream* pStream) +{ + pStream->triangle(topVertex, inc_chain->getVertex(inc_current), dec_chain->getVertex(dec_current)); + +/*printf("**(%f,%f)\n", inc_chain->getArray()[0][0],inc_chain->getArray()[0][1]);*/ + triangulateXYMonoTB(inc_end-inc_current+1, inc_chain->getArray()+inc_current, dec_end-dec_current+1, dec_chain->getArray()+dec_current, pStream); + + pStream->triangle(botVertex, dec_chain->getVertex(dec_end), inc_chain->getVertex(inc_end)); +} + + +/*n_left>=1 + *n_right>=1 + *the strip is going top to bottom. compared to the funtion + * triangulateXYmono() + */ +void triangulateXYMonoTB(Int n_left, Real** leftVerts, + Int n_right, Real** rightVerts, + primStream* pStream) +{ + + + Int i,j,k,l; + Real* topMostV; + + assert(n_left>=1 && n_right>=1); + if(leftVerts[0][1] >= rightVerts[0][1]) + { + i=1; + j=0; + topMostV = leftVerts[0]; + } + else + { + i=0; + j=1; + topMostV = rightVerts[0]; + } + + while(1) + { + if(i >= n_left) /*case1: no more in left*/ + { + + if(jbegin(); + pStream->insert(topMostV); + for(k=n_right-1; k>=j; k--) + pStream->insert(rightVerts[j]); + + pStream->end(PRIMITIVE_STREAM_FAN); + + } + + break; + } + else if(j>= n_right) /*case2: no more in right*/ + { + + if(ibegin(); + pStream->insert(topMostV); + + for(k=i; kinsert(leftVerts[k]); + + pStream->end(PRIMITIVE_STREAM_FAN); + } + + break; + } + else /* case3: neither is empty, plus the topMostV, there is at least one triangle to output*/ + { + + if(leftVerts[i][1] >= rightVerts[j][1]) + { + pStream->begin(); + pStream->insert(rightVerts[j]); /*the origin of this fan*/ + + pStream->insert(topMostV); + + /*find the last k>=i such that + *leftverts[k][1] >= rightverts[j][1] + */ + k=i; + while(kinsert(leftVerts[l]); + } + + pStream->end(PRIMITIVE_STREAM_FAN); + //update i for next loop + i = k+1; + topMostV = leftVerts[k]; + + } + else /*leftVerts[i][1] < rightVerts[j][1]*/ + { + pStream->begin(); + pStream->insert(leftVerts[i]);/*the origion of this fan*/ + + /*find the last k>=j such that + *rightverts[k][1] > leftverts[i][1]*/ + k=j; + while(k< n_right) + { + if(rightVerts[k][1] <= leftVerts[i][1]) + break; + k++; + } + k--; + + for(l=k; l>= j; l--) + pStream->insert(rightVerts[l]); + + pStream->insert(topMostV); + pStream->end(PRIMITIVE_STREAM_FAN); + j=k+1; + topMostV = rightVerts[j-1]; + } + } + } +} + +static int chainConvex(vertexArray* inc_chain, Int inc_current, Int inc_end) +{ + Int i; + //if there are no more than 2 vertices, return 1 + if(inc_current >= inc_end-1) return 1; + for(i=inc_current; i<= inc_end-2; i++) + { + if(area(inc_chain->getVertex(i), inc_chain->getVertex(i+1), inc_chain->getVertex(i+2)) <0) + return 0; + } + return 1; +} + +static int chainConcave(vertexArray* dec_chain, Int dec_current, Int dec_end) +{ + Int i; + //if there are no more than 2 vertices, return 1 + if(dec_current >= dec_end -1) return 1; + for(i=dec_current; i<=dec_end-2; i++) + { + if(area(dec_chain->getVertex(i), dec_chain->getVertex(i+1), dec_chain->getVertex(i+2)) >0) + return 0; + } + return 1; +} + +void monoTriangulationRecGenInU(Real* topVertex, Real* botVertex, + vertexArray* inc_chain, Int inc_current, Int inc_end, + vertexArray* dec_chain, Int dec_current, Int dec_end, + primStream* pStream) +{ + +} + +void monoTriangulationRecGenOpt(Real* topVertex, Real* botVertex, + vertexArray* inc_chain, Int inc_current, Int inc_end, + vertexArray* dec_chain, Int dec_current, Int dec_end, + primStream* pStream) +{ + Int i; + //copy this to a polygon: directedLine Lioop + sampledLine* sline; + directedLine* dline; + directedLine* poly; + + if(inc_current <= inc_end) //at least one vertex in inc_chain + { + sline = new sampledLine(topVertex, inc_chain->getVertex(inc_current)); + poly = new directedLine(INCREASING, sline); + for(i=inc_current; i<=inc_end-1; i++) + { + sline = new sampledLine(inc_chain->getVertex(i), inc_chain->getVertex(i+1)); + dline = new directedLine(INCREASING, sline); + poly->insert(dline); + } + sline = new sampledLine(inc_chain->getVertex(inc_end), botVertex); + dline = new directedLine(INCREASING, sline); + poly->insert(dline); + } + else //inc_chian is empty + { + sline = new sampledLine(topVertex, botVertex); + dline = new directedLine(INCREASING, sline); + poly = dline; + } + + assert(poly != NULL); + + if(dec_current <= dec_end) //at least on vertex in dec_Chain + { + sline = new sampledLine(botVertex, dec_chain->getVertex(dec_end)); + dline = new directedLine(INCREASING, sline); + poly->insert(dline); + for(i=dec_end; i>dec_current; i--) + { + sline = new sampledLine(dec_chain->getVertex(i), dec_chain->getVertex(i-1)); + dline = new directedLine(INCREASING, sline); + poly->insert(dline); + } + sline = new sampledLine(dec_chain->getVertex(dec_current), topVertex); + dline = new directedLine(INCREASING, sline); + poly->insert(dline); + } + else //dec_chain is empty + { + sline = new sampledLine(botVertex, topVertex); + dline = new directedLine(INCREASING, sline); + poly->insert(dline); + } + + { + Int n_cusps; + Int n_edges = poly->numEdges(); + directedLine** cusps = (directedLine**) malloc(sizeof(directedLine*)*n_edges); + assert(cusps); + findInteriorCuspsX(poly, n_cusps, cusps); + + if(n_cusps ==0) //u monotine + { + monoTriangulationFun(poly, compV2InX, pStream); + } + else if(n_cusps == 1) // one interior cusp + { + directedLine* new_polygon = polygonConvert(cusps[0]); + directedLine* other = findDiagonal_singleCuspX(new_polygon); + // should NOT be null unless there are self-intersecting + //trim curves. In that case, we don't want to core dump, instead, + //we triangulate anyway, and print out error message. + if(other == NULL) + { + monoTriangulationFun(poly, compV2InX, pStream); + } + else + { + directedLine* ret_p1; + directedLine* ret_p2; + + new_polygon->connectDiagonal_2slines(new_polygon, other, + &ret_p1, + &ret_p2, + new_polygon); + + monoTriangulationFun(ret_p1, compV2InX, pStream); + monoTriangulationFun(ret_p2, compV2InX, pStream); + + ret_p1->deleteSinglePolygonWithSline(); + ret_p2->deleteSinglePolygonWithSline(); + } + } + else + { + //we need a general partitionX funtion (supposed to be in partitionX.C, + //not implemented yet. XXX + //monoTriangulationFun(poly, compV2InY, pStream); + + directedLine* new_polygon = polygonConvert(poly); + directedLine* list = monoPolyPart(new_polygon); + for(directedLine* temp = list; temp != NULL; temp = temp->getNextPolygon()) + { + monoTriangulationFun(temp, compV2InX, pStream); + } + //clean up + list->deletePolygonListWithSline(); + + } + + free(cusps); + /* + if(numInteriorCuspsX(poly) == 0) //is u monotone + monoTriangulationFun(poly, compV2InX, pStream); + else //it is not u motone + monoTriangulationFun(poly, compV2InY, pStream); + */ + //clean up space + poly->deleteSinglePolygonWithSline(); + return; + } + + //apparently the following code is not reachable, + //it is for test purpose + if(inc_current > inc_end || dec_current>dec_end) + { + monoTriangulationRecGen(topVertex, botVertex, inc_chain, inc_current, inc_end, + dec_chain, dec_current, dec_end, + pStream); + return; + } + + + if( + area(dec_chain->getVertex(dec_current), + topVertex, + inc_chain->getVertex(inc_current)) >=0 + && chainConvex(inc_chain, inc_current, inc_end) + && chainConcave(dec_chain, dec_current, dec_end) + && area(inc_chain->getVertex(inc_end), botVertex, dec_chain->getVertex(dec_end)) >=0 + ) + { + monoTriangulationRecFunGen(topVertex, botVertex, + inc_chain, inc_current, inc_end, + dec_chain, dec_current, dec_end, + compV2InX, pStream); + } + else + { + monoTriangulationRecGen(topVertex, botVertex, inc_chain, inc_current, inc_end, + dec_chain, dec_current, dec_end, + pStream); + } +} + +/*if inc_current>inc_end, then inc_chain has no points to be considered + *same for dec_chain + */ +void monoTriangulationRecGen(Real* topVertex, Real* botVertex, + vertexArray* inc_chain, Int inc_current, Int inc_end, + vertexArray* dec_chain, Int dec_current, Int dec_end, + primStream* pStream) +{ + Real** inc_array ; + Real** dec_array ; + Int i; + + if(inc_current > inc_end && dec_current>dec_end) + return; + else if(inc_current>inc_end) /*no more vertices on inc_chain*/ + { + dec_array = dec_chain->getArray(); + reflexChain rChain(100,0); + /*put the top vertex into the reflex chain*/ + rChain.processNewVertex(topVertex, pStream); + /*process all the vertices on the dec_chain*/ + for(i=dec_current; i<=dec_end; i++){ + rChain.processNewVertex(dec_array[i], pStream); + } + /*process the bottom vertex*/ + rChain.processNewVertex(botVertex, pStream); + } + else if(dec_current> dec_end) /*no more vertices on dec_chain*/ + { + inc_array = inc_chain->getArray(); + + reflexChain rChain(100,1); + /*put the top vertex into the reflex chain*/ + rChain.processNewVertex(topVertex, pStream); + /*process all the vertices on the inc_chain*/ + for(i=inc_current; i<=inc_end; i++){ + rChain.processNewVertex(inc_array[i], pStream); + } + /*process the bottom vertex*/ + rChain.processNewVertex(botVertex, pStream); + } + else /*neither chain is empty*/ + { + inc_array = inc_chain -> getArray(); + dec_array = dec_chain -> getArray(); + + /*if top of inc_chain is 'lower' than top of dec_chain, process all the + *vertices on the dec_chain which are higher than top of inc_chain + */ + if(compV2InY(inc_array[inc_current], dec_array[dec_current]) <= 0) + { + + reflexChain rChain(100, 0); + rChain.processNewVertex(topVertex, pStream); + for(i=dec_current; i<=dec_end; i++) + { + if(compV2InY(inc_array[inc_current], dec_array[i]) <= 0) + rChain.processNewVertex(dec_array[i], pStream); + else + break; + } + rChain.outputFan(inc_array[inc_current], pStream); + monoTriangulationRecGen(dec_array[i-1], botVertex, + inc_chain, inc_current, inc_end, + dec_chain, i, dec_end, + pStream); + } + else /*compV2InY(inc_array[inc_current], dec_array[dec_current]) > 0*/ + { + + reflexChain rChain(100, 1); + rChain.processNewVertex(topVertex, pStream); + for(i=inc_current; i<=inc_end; i++) + { + if(compV2InY(inc_array[i], dec_array[dec_current]) >0) + rChain.processNewVertex(inc_array[i], pStream); + else + break; + } + rChain.outputFan(dec_array[dec_current], pStream); + monoTriangulationRecGen(inc_array[i-1], botVertex, + inc_chain, i, inc_end, + dec_chain, dec_current,dec_end, + pStream); + } + }/*end case neither is empty*/ +} + +void monoTriangulationFun(directedLine* monoPolygon, Int (*compFun)(Real*, Real*), primStream* pStream) +{ + Int i; + /*find the top vertex, bottom vertex, inccreasing chain, and decreasing chain, + *then call monoTriangulationRec + */ + directedLine* tempV; + directedLine* topV; + directedLine* botV; + topV = botV = monoPolygon; + for(tempV = monoPolygon->getNext(); tempV != monoPolygon; tempV = tempV->getNext()) + { + if(compFun(topV->head(), tempV->head())<0) { + topV = tempV; + } + if(compFun(botV->head(), tempV->head())>0) { + botV = tempV; + } + } + + /*creat increase and decrease chains*/ + vertexArray inc_chain(20); /*this is a dynamic array*/ + for(i=1; i<=topV->get_npoints()-2; i++) { /*the first vertex is the top vertex which doesn't belong to inc_chain*/ + inc_chain.appendVertex(topV->getVertex(i)); + } + for(tempV = topV->getNext(); tempV != botV; tempV = tempV->getNext()) + { + for(i=0; i<=tempV->get_npoints()-2; i++){ + inc_chain.appendVertex(tempV->getVertex(i)); + } + } + + vertexArray dec_chain(20); + for(tempV = topV->getPrev(); tempV != botV; tempV = tempV->getPrev()) + { + for(i=tempV->get_npoints()-2; i>=0; i--){ + dec_chain.appendVertex(tempV->getVertex(i)); + } + } + for(i=botV->get_npoints()-2; i>=1; i--){ + dec_chain.appendVertex(tempV->getVertex(i)); + } + + if (!(0 == inc_chain.getNumElements() && 0 == dec_chain.getNumElements())) { + monoTriangulationRecFun(topV->head(), botV->head(), &inc_chain, 0, + &dec_chain, 0, compFun, pStream); + } +} + +void monoTriangulation(directedLine* monoPolygon, primStream* pStream) +{ + Int i; + /*find the top vertex, bottom vertex, inccreasing chain, and decreasing chain, + *then call monoTriangulationRec + */ + directedLine* tempV; + directedLine* topV; + directedLine* botV; + topV = botV = monoPolygon; + for(tempV = monoPolygon->getNext(); tempV != monoPolygon; tempV = tempV->getNext()) + { + if(compV2InY(topV->head(), tempV->head())<0) { + topV = tempV; + } + if(compV2InY(botV->head(), tempV->head())>0) { + botV = tempV; + } + } + /*creat increase and decrease chains*/ + vertexArray inc_chain(20); /*this is a dynamic array*/ + for(i=1; i<=topV->get_npoints()-2; i++) { /*the first vertex is the top vertex which doesn't belong to inc_chain*/ + inc_chain.appendVertex(topV->getVertex(i)); + } + for(tempV = topV->getNext(); tempV != botV; tempV = tempV->getNext()) + { + for(i=0; i<=tempV->get_npoints()-2; i++){ + inc_chain.appendVertex(tempV->getVertex(i)); + } + } + + vertexArray dec_chain(20); + for(tempV = topV->getPrev(); tempV != botV; tempV = tempV->getPrev()) + { + for(i=tempV->get_npoints()-2; i>=0; i--){ + dec_chain.appendVertex(tempV->getVertex(i)); + } + } + for(i=botV->get_npoints()-2; i>=1; i--){ + dec_chain.appendVertex(tempV->getVertex(i)); + } + + monoTriangulationRec(topV->head(), botV->head(), &inc_chain, 0, &dec_chain, 0, pStream); + +} + +/*the chain could be increasing or decreasing, although we use the + * name inc_chain. + *the argument is_increase_chain indicates whether this chain + *is increasing (left chain in V-monotone case) or decreaing (right chain + *in V-monotone case). + */ +void monoTriangulation2(Real* topVertex, Real* botVertex, + vertexArray* inc_chain, Int inc_smallIndex, + Int inc_largeIndex, + Int is_increase_chain, + primStream* pStream) +{ + assert( inc_chain != NULL); + Real** inc_array ; + + if(inc_smallIndex > inc_largeIndex) + return; //no triangles + if(inc_smallIndex == inc_largeIndex) + { + if(is_increase_chain) + pStream->triangle(inc_chain->getVertex(inc_smallIndex), botVertex, topVertex); + else + pStream->triangle(inc_chain->getVertex(inc_smallIndex), topVertex, botVertex); + return; + } + Int i; + + if(is_increase_chain && botVertex[1] == inc_chain->getVertex(inc_largeIndex)[1]) + { + pStream->triangle(botVertex, inc_chain->getVertex(inc_largeIndex-1), + inc_chain->getVertex(inc_largeIndex)); + monoTriangulation2(topVertex, botVertex, inc_chain, inc_smallIndex, + inc_largeIndex-1, + is_increase_chain, + pStream); + return; + } + else if( (!is_increase_chain) && topVertex[1] == inc_chain->getVertex(inc_smallIndex)[1]) + { + pStream->triangle(topVertex, inc_chain->getVertex(inc_smallIndex+1), + inc_chain->getVertex(inc_smallIndex)); + monoTriangulation2(topVertex, botVertex, inc_chain, inc_smallIndex+1, + inc_largeIndex, is_increase_chain, pStream); + return ; + } + + inc_array = inc_chain->getArray(); + + reflexChain rChain(20,is_increase_chain); /*1 means the chain is increasing*/ + + rChain.processNewVertex(topVertex, pStream); + + for(i=inc_smallIndex; i<=inc_largeIndex; i++){ + rChain.processNewVertex(inc_array[i], pStream); + } + rChain.processNewVertex(botVertex, pStream); + +} + +/*if compFun == compV2InY, top to bottom: V-monotone + *if compFun == compV2InX, right to left: U-monotone + */ +void monoTriangulationRecFunGen(Real* topVertex, Real* botVertex, + vertexArray* inc_chain, Int inc_current, Int inc_end, + vertexArray* dec_chain, Int dec_current, Int dec_end, + Int (*compFun)(Real*, Real*), + primStream* pStream) +{ + assert( inc_chain != NULL && dec_chain != NULL); + assert( ! (inc_current> inc_end && + dec_current> dec_end)); + /* + Int inc_nVertices; + Int dec_nVertices; + */ + Real** inc_array ; + Real** dec_array ; + Int i; + assert( ! ( (inc_chain==NULL) && (dec_chain==NULL))); + + if(inc_current> inc_end) /*no more vertices on inc_chain*/ + { + + dec_array = dec_chain->getArray(); + reflexChain rChain(20,0); + /*put the top vertex into the reflex chain*/ + rChain.processNewVertex(topVertex, pStream); + /*process all the vertices on the dec_chain*/ + for(i=dec_current; i<=dec_end; i++){ + rChain.processNewVertex(dec_array[i], pStream); + } + /*process the bottom vertex*/ + rChain.processNewVertex(botVertex, pStream); + + } + else if(dec_current> dec_end) /*no more vertices on dec_chain*/ + { + inc_array = inc_chain->getArray(); + reflexChain rChain(20,1); + /*put the top vertex into the reflex chain*/ + rChain.processNewVertex(topVertex, pStream); + /*process all the vertices on the inc_chain*/ + for(i=inc_current; i<=inc_end; i++){ + rChain.processNewVertex(inc_array[i], pStream); + } + /*process the bottom vertex*/ + rChain.processNewVertex(botVertex, pStream); + } + else /*neither chain is empty*/ + { + inc_array = inc_chain -> getArray(); + dec_array = dec_chain -> getArray(); + + /*if top of inc_chain is 'lower' than top of dec_chain, process all the + *vertices on the dec_chain which are higher than top of inc_chain + */ + if(compFun(inc_array[inc_current], dec_array[dec_current]) <= 0) + { + + reflexChain rChain(20, 0); + rChain.processNewVertex(topVertex, pStream); + for(i=dec_current; i<=dec_end; i++) + { + if(compFun(inc_array[inc_current], dec_array[i]) <= 0) + rChain.processNewVertex(dec_array[i], pStream); + else + break; + } + rChain.outputFan(inc_array[inc_current], pStream); + monoTriangulationRecFunGen(dec_array[i-1], botVertex, + inc_chain, inc_current, inc_end, + dec_chain, i, dec_end, + compFun, + pStream); + } + else /*compFun(inc_array[inc_current], dec_array[dec_current]) > 0*/ + { + + reflexChain rChain(20, 1); + rChain.processNewVertex(topVertex, pStream); + for(i=inc_current; i<=inc_end; i++) + { + if(compFun(inc_array[i], dec_array[dec_current]) >0) + rChain.processNewVertex(inc_array[i], pStream); + else + break; + } + rChain.outputFan(dec_array[dec_current], pStream); + monoTriangulationRecFunGen(inc_array[i-1], botVertex, + inc_chain, i,inc_end, + dec_chain, dec_current,dec_end, + compFun, + pStream); + } + }/*end case neither is empty*/ +} + +/*if compFun == compV2InY, top to bottom: V-monotone + *if compFun == compV2InX, right to left: U-monotone + */ +void monoTriangulationRecFun(Real* topVertex, Real* botVertex, + vertexArray* inc_chain, Int inc_current, + vertexArray* dec_chain, Int dec_current, + Int (*compFun)(Real*, Real*), + primStream* pStream) +{ + assert( inc_chain != NULL && dec_chain != NULL); + assert( ! (inc_current>=inc_chain->getNumElements() && + dec_current>=dec_chain->getNumElements())); + Int inc_nVertices; + Int dec_nVertices; + Real** inc_array ; + Real** dec_array ; + Int i; + assert( ! ( (inc_chain==NULL) && (dec_chain==NULL))); + + if(inc_current>=inc_chain->getNumElements()) /*no more vertices on inc_chain*/ + { + + dec_array = dec_chain->getArray(); + dec_nVertices = dec_chain->getNumElements(); + reflexChain rChain(20,0); + /*put the top vertex into the reflex chain*/ + rChain.processNewVertex(topVertex, pStream); + /*process all the vertices on the dec_chain*/ + for(i=dec_current; i= dec_chain->getNumElements()) /*no more vertices on dec_chain*/ + { + inc_array = inc_chain->getArray(); + inc_nVertices= inc_chain->getNumElements(); + reflexChain rChain(20,1); + /*put the top vertex into the reflex chain*/ + rChain.processNewVertex(topVertex, pStream); + /*process all the vertices on the inc_chain*/ + for(i=inc_current; i getArray(); + dec_array = dec_chain -> getArray(); + inc_nVertices= inc_chain->getNumElements(); + dec_nVertices= dec_chain->getNumElements(); + /*if top of inc_chain is 'lower' than top of dec_chain, process all the + *vertices on the dec_chain which are higher than top of inc_chain + */ + if(compFun(inc_array[inc_current], dec_array[dec_current]) <= 0) + { + + reflexChain rChain(20, 0); + rChain.processNewVertex(topVertex, pStream); + for(i=dec_current; i 0*/ + { + + reflexChain rChain(20, 1); + rChain.processNewVertex(topVertex, pStream); + for(i=inc_current; i0) + rChain.processNewVertex(inc_array[i], pStream); + else + break; + } + rChain.outputFan(dec_array[dec_current], pStream); + monoTriangulationRecFun(inc_array[i-1], botVertex, + inc_chain, i, + dec_chain, dec_current, + compFun, + pStream); + } + }/*end case neither is empty*/ +} + + +void monoTriangulationRec(Real* topVertex, Real* botVertex, + vertexArray* inc_chain, Int inc_current, + vertexArray* dec_chain, Int dec_current, + primStream* pStream) +{ + assert( inc_chain != NULL && dec_chain != NULL); + assert( ! (inc_current>=inc_chain->getNumElements() && + dec_current>=dec_chain->getNumElements())); + Int inc_nVertices; + Int dec_nVertices; + Real** inc_array ; + Real** dec_array ; + Int i; + assert( ! ( (inc_chain==NULL) && (dec_chain==NULL))); + + if(inc_current>=inc_chain->getNumElements()) /*no more vertices on inc_chain*/ + { + + dec_array = dec_chain->getArray(); + dec_nVertices = dec_chain->getNumElements(); + reflexChain rChain(20,0); + /*put the top vertex into the reflex chain*/ + rChain.processNewVertex(topVertex, pStream); + /*process all the vertices on the dec_chain*/ + for(i=dec_current; i= dec_chain->getNumElements()) /*no more vertices on dec_chain*/ + { + inc_array = inc_chain->getArray(); + inc_nVertices= inc_chain->getNumElements(); + reflexChain rChain(20,1); + /*put the top vertex into the reflex chain*/ + rChain.processNewVertex(topVertex, pStream); + /*process all the vertices on the inc_chain*/ + for(i=inc_current; i getArray(); + dec_array = dec_chain -> getArray(); + inc_nVertices= inc_chain->getNumElements(); + dec_nVertices= dec_chain->getNumElements(); + /*if top of inc_chain is 'lower' than top of dec_chain, process all the + *vertices on the dec_chain which are higher than top of inc_chain + */ + if(compV2InY(inc_array[inc_current], dec_array[dec_current]) <= 0) + { + + reflexChain rChain(20, 0); + rChain.processNewVertex(topVertex, pStream); + for(i=dec_current; i 0*/ + { + + reflexChain rChain(20, 1); + rChain.processNewVertex(topVertex, pStream); + for(i=inc_current; i0) + rChain.processNewVertex(inc_array[i], pStream); + else + break; + } + rChain.outputFan(dec_array[dec_current], pStream); + monoTriangulationRec(inc_array[i-1], botVertex, + inc_chain, i, + dec_chain, dec_current, + pStream); + } + }/*end case neither is empty*/ +} + + + +/* the name here assumes that the polygon is Y-monotone, but + *this function also works for X-monotone polygons. + * a monotne polygon consists of two extrem verteices: topVertex and botVertex, and + *two monotone chains: inc_chain, and dec_chain. The edges of the increasing chain (inc_chain) + *is ordered by following pointer: next, while the edges of the decreasing chain (dec_chain) + *is ordered by following pointer: prev + * inc_index index the vertex which is the toppest of the inc_chain which we are handling currently. + * dec_index index the vertex which is the toppest of the dec_chain which we are handling currently. + */ +void monoTriangulationRec(directedLine* inc_chain, Int inc_index, + directedLine* dec_chain, Int dec_index, + directedLine* topVertex, Int top_index, + directedLine* botVertex, + primStream* pStream) +{ + Int i; + directedLine *temp, *oldtemp = NULL; + Int tempIndex, oldtempIndex = 0; + + assert(inc_chain != NULL && dec_chain != NULL); + + if(inc_chain == botVertex) { + reflexChain rChain(20, 0); + rChain.processNewVertex(topVertex->getVertex(top_index), pStream); + for(i=dec_index; i< dec_chain->get_npoints(); i++){ + rChain.processNewVertex(dec_chain->getVertex(i), pStream); + } + for(temp = dec_chain->getPrev(); temp != botVertex; temp = temp->getPrev()) + { + for(i=0; iget_npoints(); i++){ + rChain.processNewVertex(temp->getVertex(i), pStream); + } + } + } + else if(dec_chain==botVertex) { + reflexChain rChain(20, 1); + rChain.processNewVertex(topVertex->getVertex(top_index), pStream); + for(i=inc_index; i< inc_chain->get_npoints(); i++){ + rChain.processNewVertex(inc_chain->getVertex(i), pStream); + } + for(temp = inc_chain->getPrev(); temp != botVertex; temp = temp->getNext()) + { + for(i=0; iget_npoints(); i++){ + rChain.processNewVertex(temp->getVertex(i), pStream); + } + } + } + else /*neither reached the bottom*/{ + if(compV2InY(inc_chain->getVertex(inc_index), dec_chain->getVertex(dec_index)) <=0) { + reflexChain rChain(20, 0); + rChain.processNewVertex(topVertex -> getVertex(top_index), pStream); + temp = dec_chain; + tempIndex = dec_index; + while( compV2InY(inc_chain->getVertex(inc_index), temp->getVertex(tempIndex))<=0) { + oldtemp = temp; + oldtempIndex = tempIndex; + rChain.processNewVertex(temp->getVertex(tempIndex), pStream); + + if(tempIndex == temp->get_npoints()-1){ + tempIndex = 0; + temp = temp->getPrev(); + } + else{ + tempIndex++; + } + } + rChain.outputFan(inc_chain->getVertex(inc_index), pStream); + monoTriangulationRec(inc_chain, inc_index, temp, tempIndex, oldtemp, oldtempIndex, botVertex, pStream); + } + else /* >0*/ { + reflexChain rChain(20, 1); + rChain.processNewVertex(topVertex -> getVertex(top_index), pStream); + temp = inc_chain; + tempIndex = inc_index; + while( compV2InY(temp->getVertex(tempIndex), dec_chain->getVertex(dec_index))>0){ + oldtemp = temp; + oldtempIndex = tempIndex; + rChain.processNewVertex(temp->getVertex(tempIndex), pStream); + + if(tempIndex == temp->get_npoints()-1){ + tempIndex = 0; + temp = temp->getNext(); + } + else{ + tempIndex++; + } + } + rChain.outputFan(dec_chain->getVertex(dec_index), pStream); + monoTriangulationRec(temp, tempIndex, dec_chain, dec_index, oldtemp, oldtempIndex, botVertex, pStream); + } + } /*end case neither reached the bottom*/ +} + +/***************************vertexArray begin here**********************************/ +vertexArray::vertexArray(Real2* vertices, Int nVertices) +{ + Int i; + size = index = nVertices; + array = (Real**) malloc(sizeof(Real*) * nVertices); + assert(array); + for(i=0; i= size){ + Real** temp = (Real**) malloc(sizeof(Real*) * (2*size +1)); + assert(temp); + for(i=0; i= v + * and array[i+1][1] v + *if sartIndex>endIndex, then return endIndex+1. + *otherwise, startIndex<=endIndex, it is assumed that + * 0<=startIndex<=endIndex endIndex) + return endIndex+1; + else if(array[endIndex][1] > v) + return endIndex+1; + else //now array[endIndex][1] <= v + { + for(i=endIndex-1; i>=startIndex; i--) + { + if(array[i][1] > v) + break; + } + return i+1; + } +} + +/*find the first i<=endIndex such that array[i-1][1] >= v + * and array[i][1] < v + *if sartIndex>endIndex, then return endIndex+1. + *otherwise, startIndex<=endIndex, it is assumed that + * 0<=startIndex<=endIndex endIndex) + return endIndex+1; + else if(array[endIndex][1] >= v) + return endIndex+1; + else //now array[endIndex][1] < v + { + for(i=endIndex-1; i>=startIndex; i--) + { + if(array[i][1] >= v) + break; + } + return i+1; + } +} + +/*find the first i>startIndex such that array[i-1][1] > v + * and array[i][1] >=v + *if sartIndex>endIndex, then return startIndex-1. + *otherwise, startIndex<=endIndex, it is assumed that + * 0<=startIndex<=endIndex endIndex) + return startIndex-1; + else if(array[startIndex][1] < v) + return startIndex-1; + else //now array[startIndex][1] >= v + { + + for(i=startIndex; i<=endIndex; i++) + { + if(array[i][1] <= v) + break; + } + if(i>endIndex) // v is strictly below all + return endIndex; + else if(array[i][1] == v) + return i; + else + return i-1; + } + +} + + +/*find the first i>=startIndex such that array[i][1] >= v + * and array[i+1][1] endIndex, then return startIndex-1. + *otherwise, startIndex<=endIndex, it is assumed that + * 0<=startIndex<=endIndex endIndex) + return startIndex-1; + else if(array[startIndex][1] < v) + return startIndex-1; + else //now array[startIndex][1] >= v + { + for(i=startIndex+1; i<=endIndex; i++) + { + if(array[i][1] < v) + break; + } + return i-1; + } +} + +Int vertexArray::findDecreaseChainFromEnd(Int begin, Int end) +{ + Int i = end; + Real prevU = array[i][0]; + Real thisU; + for(i=end-1; i>=begin; i--){ + thisU = array[i][0]; + if(thisU < prevU) + prevU = thisU; + else + break; + } + return i; +} + +//if(V(start) == v, return start, other wise return the +//last i so that V(i)==v +Int vertexArray::skipEqualityFromStart(Real v, Int start, Int end) +{ + Int i; + if(array[start][1] != v) + return start; + //now array[start][1] == v + for(i=start+1; i<= end; i++) + if(array[i][1] != v) + break; + return i-1; +} + + +/***************************vertexArray end****************************************/ + + + +/***************************relfex chain stuff begin here*****************************/ + +reflexChain::reflexChain(Int size, Int is_increasing) +{ + queue = (Real2*) malloc(sizeof(Real2) * size); + assert(queue); + index_queue = 0; + size_queue = size; + isIncreasing = is_increasing; +} + +reflexChain::~reflexChain() +{ + free(queue); +} + +/*put (u,v) at the end of the queue + *pay attention to space + */ +void reflexChain::insert(Real u, Real v) +{ + Int i; + if(index_queue >= size_queue) { + Real2 *temp = (Real2*) malloc(sizeof(Real2) * (2*size_queue+1)); + assert(temp); + + /*copy*/ + for(i=0; ibegin(); + pStream->insert(v); + if(isIncreasing) { + for(i=0; iinsert(queue[i]); + } + else { + for(i=index_queue-1; i>=0; i--) + pStream->insert(queue[i]); + } + pStream->end(PRIMITIVE_STREAM_FAN); +} + +void reflexChain::processNewVertex(Real v[2], primStream* pStream) +{ + Int i,j,k; + Int isReflex; + /*if there are at most one vertex in the queue, then simply insert + */ + if(index_queue <=1){ + insert(v); + return; + } + + /*there are at least two vertices in the queue*/ + j=index_queue-1; + + for(i=j; i>=1; i--) { + if(isIncreasing) { + isReflex = (area(queue[i-1], queue[i], v) <= 0.0); + } + else /*decreasing*/{ + isReflex = (area(v, queue[i], queue[i-1]) <= 0.0); + } + if(isReflex) { + break; + } + } + + /* + *if ibegin(); + pStream->insert(v); + if(isIncreasing) { + for(k=i; k<=j; k++) + pStream->insert(queue[k]); + } + else { + for(k=j; k>=i; k--) + pStream->insert(queue[k]); + } + + pStream->end(PRIMITIVE_STREAM_FAN); + } + + /*delete vertices i+1--j from the queue*/ + index_queue = i+1; + /*finally insert v at the end of the queue*/ + insert(v); + +} + +void reflexChain::print() +{ + Int i; + printf("reflex chain: isIncreasing=%i\n", isIncreasing); + for(i=0; i +#define _glu_dprintf printf +#else +inline void _glu_dprintf( char *, ... ) { } +#endif +#endif + +#ifdef GLBUILD +inline void _glu_dprintf( char *, ... ) { } +#endif + +#ifndef NULL +#define NULL 0 +#endif + +#endif /* __glumystdio_h_ */ diff --git a/src/glu/sgi/libnurbs/nurbtess/mystdlib.h b/src/glu/sgi/libnurbs/nurbtess/mystdlib.h new file mode 100644 index 0000000..ab7a3b2 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/mystdlib.h @@ -0,0 +1,57 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * mystdlib.h + * + */ + +#ifndef __glumystdlib_h_ +#define __glumystdlib_h_ + +#ifdef STANDALONE +typedef unsigned int size_t; +extern "C" void abort( void ); +extern "C" void * malloc( size_t ); +extern "C" void free( void * ); +#endif + +#ifdef LIBRARYBUILD +#include +#endif + +#ifdef GLBUILD +typedef unsigned int size_t; +extern "C" void abort( void ); +extern "C" void * malloc( size_t ); +extern "C" void free( void * ); +#endif + +#endif /* __glumystdlib_h_ */ diff --git a/src/glu/sgi/libnurbs/nurbtess/partitionX.cc b/src/glu/sgi/libnurbs/nurbtess/partitionX.cc new file mode 100644 index 0000000..e25e30b --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/partitionX.cc @@ -0,0 +1,162 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include + +#include "partitionX.h" + +#define CONCAVITY_ZERO 1.0e-6 //this number is used to test whether a vertex is concave (refelx) + //or not. The test needs to compute the area of the three adjacent + //vertices to see if the are is positive or negative. + +Int isCuspX(directedLine *v) +{ + //if v->prev <= v && v->next <= v + //|| v->prev >= v && v->next >= v + Real* T = v->head(); + Real* P = v->getPrev()->head(); + Real* N = v->getNext()->head(); + if( + (compV2InX(T,P) != -1 && + compV2InX(T,N) != -1 + ) || + (compV2InX(T,P) != 1 && + compV2InX(T,N) != 1 + ) + ) + return 1; + else + return 0; +} + +Int isReflexX(directedLine* v) +{ + Real* A = v->getPrev()->head(); + Real* B = v->head(); + Real* C = v->tail(); + Real Bx,By, Cx, Cy; + //scale them in case they are too small + Bx = 10*(B[0] - A[0]); + By = 10*(B[1] - A[1]); + Cx = 10*(C[0] - A[0]); + Cy = 10*(C[1] - A[1]); + + if(Bx*Cy - Cx*By < -CONCAVITY_ZERO) return 1; + else return 0; +} + + +/*return + *0: not-cusp + *1: interior cusp + *2: exterior cusp + */ +Int cuspTypeX(directedLine *v) +{ + if(! isCuspX(v)) return 0; + else + { +//printf("isCusp,%f,%f\n", v->head()[0], v->head()[1]); + if(isReflexX(v)) + { +// printf("isReflex\n"); + return 1; + } + else + { +// printf("not isReflex\n"); + return 2; + } + } +} + +Int numInteriorCuspsX(directedLine *polygon) +{ + directedLine *temp; + int ret = 0; + if(cuspTypeX(polygon) == 1) + ret++; + for(temp = polygon->getNext(); temp != polygon; temp = temp->getNext()) + if(cuspTypeX(temp) == 1) + ret++; + return ret; +} + + +void findInteriorCuspsX(directedLine *polygon, Int& ret_n_interior_cusps, + directedLine** ret_interior_cusps) +{ + directedLine *temp; + ret_n_interior_cusps = 0; + if(cuspTypeX(polygon) == 1) + { + ret_interior_cusps[ret_n_interior_cusps++] = polygon; + } + for(temp = polygon->getNext(); temp != polygon; temp = temp->getNext()) + if(cuspTypeX(temp) == 1) + { + ret_interior_cusps[ret_n_interior_cusps++] = temp; + } +} + +directedLine* findDiagonal_singleCuspX(directedLine* cusp) +{ + directedLine* temp; + Int is_minimal = ((compV2InX(cusp->head(), cusp->tail()) == -1)? 1:0); + + if(is_minimal) + for(temp = cusp->getNext(); temp != cusp; temp = temp->getNext()) + { + if(compV2InX(cusp->head(), temp->head()) == 1) + { + return temp; + } + } + else //is maxmal + for(temp = cusp->getNext(); temp != cusp; temp = temp->getNext()) + { + if(compV2InX(cusp->head(), temp->head()) == -1) + { + return temp; + } + } + return NULL; +} + + + diff --git a/src/glu/sgi/libnurbs/nurbtess/partitionX.h b/src/glu/sgi/libnurbs/nurbtess/partitionX.h new file mode 100644 index 0000000..69f2b2d --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/partitionX.h @@ -0,0 +1,54 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _PARTITIONX_H +#define _PARTITIONX_H + +#include "directedLine.h" + +Int isCuspX(directedLine *v); +Int isReflexX(directedLine *v); +Int cuspTypeX(directedLine *v); + +//assuming the array of ret_interior_cusps has been allocated +void findInteriorCuspsX(directedLine* polygon, Int& ret_n_interior_cusps, + directedLine** ret_interior_cusps); + +Int numInteriorCuspsX(directedLine* polygon); + +/*a single polygon with a single cusp + *return the diagonal vertex corresponding to this cusp + */ +directedLine* findDiagonal_singleCuspX(directedLine* cusp); + +#endif + diff --git a/src/glu/sgi/libnurbs/nurbtess/partitionY.cc b/src/glu/sgi/libnurbs/nurbtess/partitionY.cc new file mode 100644 index 0000000..e097461 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/partitionY.cc @@ -0,0 +1,836 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include +#include + +#include "zlassert.h" +#include "partitionY.h" +#include "searchTree.h" +#include "quicksort.h" +#include "polyUtil.h" + + +#define max(a,b) ((a>b)? a:b) +#define min(a,b) ((a>b)? b:a) + + +/*retrurn + *-1: if A < B (YaB + */ +static Int compVertInY(Real A[2], Real B[2]) +{ + if( (A[1] < B[1]) || (A[1]==B[1] && A[0]head(); + if( compVertInY(e->head(), vert) != 1 + && compVertInY(e->tail(), vert) != 1 + ) + return 1; + else + return 0; +} + +/*v is a vertex: the head of en edge, + *e is an edge, + *return 1 if e is below v: assume v1 and v2 are the two endpoints of e: + * v1>= v, v2>=v. + */ +Int isAbove(directedLine *v, directedLine *e) +{ + Real* vert = v->head(); + if( compVertInY(e->head(), vert) != -1 + && compVertInY(e->tail(), vert) != -1 + ) + return 1; + else + return 0; +} + +Int isCusp(directedLine *v) +{ + Real *A=v->getPrev()->head(); + Real *B=v->head(); + Real *C=v->tail(); + if(A[1] < B[1] && B[1] < C[1]) + return 0; + else if(A[1] > B[1] && B[1] > C[1]) + return 0; + else if(A[1] < B[1] && C[1] < B[1]) + return 1; + else if(A[1] > B[1] && C[1] > B[1]) + return 1; + + if((isAbove(v, v) && isAbove(v, v->getPrev())) || + (isBelow(v, v) && isBelow(v, v->getPrev()))) + return 1; + else + return 0; +} + +/*crossproduct is strictly less than 0*/ +Int isReflex(directedLine *v) +{ + Real* A = v->getPrev()->head(); + Real* B = v->head(); + Real* C = v->tail(); + Real Bx,By, Cx, Cy; + Bx = B[0] - A[0]; + By = B[1] - A[1]; + Cx = C[0] - A[0]; + Cy = C[1] - A[1]; + + if(Bx*Cy - Cx*By < 0) return 1; + else return 0; +} + + /*return + *0: not-cusp + *1: interior cusp + *2: exterior cusp + */ +Int cuspType(directedLine *v) +{ + if(! isCusp(v)) return 0; + else if(isReflex(v)) return 1; + else + return 2; +} + +sweepRange* sweepRangeMake(directedLine* left, Int leftType, + directedLine* right, Int rightType) +{ + sweepRange* ret = (sweepRange*)malloc(sizeof(sweepRange)); + assert(ret); + ret->left = left; + ret->leftType = leftType; + ret->right = right; + ret->rightType = rightType; + return ret; +} + +void sweepRangeDelete(sweepRange* range) +{ + free(range); +} + +Int sweepRangeEqual(sweepRange* src1, sweepRange* src2) +{ + Int leftEqual; + Int rightEqual; + + + /*The case when both are vertices should not happen*/ + assert(! (src1->leftType == 0 && src2->leftType == 0)); + if(src1->leftType == 0 && src2->leftType == 1){ + if(src1->left == src2->left || + src1->left->getPrev() == src2->left + ) + leftEqual = 1; + else + leftEqual = 0; + } + else if(src1->leftType == 1 && src2->leftType == 1){ + if(src1->left == src2->left) + leftEqual = 1; + else + leftEqual = 0; + } + else /*src1->leftType == 1 && src2->leftType == 0*/{ + if(src1->left == src2->left || + src1->left == src2->left->getPrev() + ) + leftEqual = 1; + else + leftEqual = 0; + } + + /*the same thing for right*/ + /*The case when both are vertices should not happen*/ + assert(! (src1->rightType == 0 && src2->rightType == 0)); + if(src1->rightType == 0 && src2->rightType == 1){ + if(src1->right == src2->right || + src1->right->getPrev() == src2->right + ) + rightEqual = 1; + else + rightEqual = 0; + } + else if(src1->rightType == 1 && src2->rightType == 1){ + if(src1->right == src2->right) + rightEqual = 1; + else + rightEqual = 0; + } + else /*src1->rightType == 1 && src2->rightType == 0*/{ + if(src1->right == src2->right || + src1->right == src2->right->getPrev() + ) + rightEqual = 1; + else + rightEqual = 0; + } + + return (leftEqual == 1 || rightEqual == 1); +} + +/*given (x_1, y_1) and (x_2, y_2), and y + *return x such that (x,y) is on the line + */ +inline/*static*/ Real intersectHoriz(Real x1, Real y1, Real x2, Real y2, Real y) +{ + return ((y2==y1)? (x1+x2)*Real(0.5) : x1 + ((y-y1)/(y2-y1)) * (x2-x1)); +/* + if(y2 == y1) return (x1+x2)*0.5; + else return x1 + ((y-y1)/(y2-y1)) * (x2-x1); +*/ +} + +/*compare two edges of a polygon. + *edge A < edge B if there is a horizontal line so that the intersection + *with A is to the left of the intersection with B. + *This function is used in sweepY for the dynamic search tree insertion to + *order the edges. + * Implementation: (x_1,y_1) and (x_2, y_2) + */ +static Int compEdges(directedLine *e1, directedLine *e2) +{ + Real* head1 = e1->head(); + Real* tail1 = e1->tail(); + Real* head2 = e2->head(); + Real* tail2 = e2->tail(); +/* + Real h10 = head1[0]; + Real h11 = head1[1]; + Real t10 = tail1[0]; + Real t11 = tail1[1]; + Real h20 = head2[0]; + Real h21 = head2[1]; + Real t20 = tail2[0]; + Real t21 = tail2[1]; +*/ + Real e1_Ymax, e1_Ymin, e2_Ymax, e2_Ymin; +/* + if(h11>t11) { + e1_Ymax= h11; + e1_Ymin= t11; + } + else{ + e1_Ymax = t11; + e1_Ymin = h11; + } + + if(h21>t21) { + e2_Ymax= h21; + e2_Ymin= t21; + } + else{ + e2_Ymax = t21; + e2_Ymin = h21; + } +*/ + + if(head1[1]>tail1[1]) { + e1_Ymax= head1[1]; + e1_Ymin= tail1[1]; + } + else{ + e1_Ymax = tail1[1]; + e1_Ymin = head1[1]; + } + + if(head2[1]>tail2[1]) { + e2_Ymax= head2[1]; + e2_Ymin= tail2[1]; + } + else{ + e2_Ymax = tail2[1]; + e2_Ymin = head2[1]; + } + + + /*Real e1_Ymax = max(head1[1], tail1[1]);*/ /*max(e1->head()[1], e1->tail()[1]);*/ + /*Real e1_Ymin = min(head1[1], tail1[1]);*/ /*min(e1->head()[1], e1->tail()[1]);*/ + /*Real e2_Ymax = max(head2[1], tail2[1]);*/ /*max(e2->head()[1], e2->tail()[1]);*/ + /*Real e2_Ymin = min(head2[1], tail2[1]);*/ /*min(e2->head()[1], e2->tail()[1]);*/ + + Real Ymax = min(e1_Ymax, e2_Ymax); + Real Ymin = max(e1_Ymin, e2_Ymin); + + Real y = Real(0.5)*(Ymax + Ymin); + +/* Real x1 = intersectHoriz(e1->head()[0], e1->head()[1], e1->tail()[0], e1->tail()[1], y); + Real x2 = intersectHoriz(e2->head()[0], e2->head()[1], e2->tail()[0], e2->tail()[1], y); +*/ +/* + Real x1 = intersectHoriz(h10, h11, t10, t11, y); + Real x2 = intersectHoriz(h20, h21, t20, t21, y); +*/ + Real x1 = intersectHoriz(head1[0], head1[1], tail1[0], tail1[1], y); + Real x2 = intersectHoriz(head2[0], head2[1], tail2[0], tail2[1], y); + + if(x1<= x2) return -1; + else return 1; +} + +/*used by sort precedures + */ +static Int compInY(directedLine* v1, directedLine* v2) +{ + return v1->compInY(v2); +} + +void findDiagonals(Int total_num_edges, directedLine** sortedVertices, sweepRange** ranges, Int& num_diagonals, directedLine** diagonal_vertices) +{ + Int i,j,k; + + k=0; + + for(i=0; igetPrev(); +/* +printf("find i=%i\n", i); +printf("the vertex is\n"); +vert->printSingle(); +*/ + if(isBelow(vert, thisEdge) && isBelow(vert, prevEdge) && compEdges(prevEdge, thisEdge)<0) + { + /*this is an upward interior cusp*/ + diagonal_vertices[k++] = vert; + + for(j=i+1; j0) + { + /*this is an downward interior cusp*/ + diagonal_vertices[k++] = vert; + for(j=i-1; j>=0; j--) + if(sweepRangeEqual(ranges[i], ranges[j])) + { + diagonal_vertices[k++] = sortedVertices[j]; + break; + } +/* printf("j=%i\n", j);*/ + assert(j>=0); + + + + } + } + num_diagonals = k/2; +} + +/*get rid of repeated diagonlas so that each diagonal appears only once in the array + */ +Int deleteRepeatDiagonals(Int num_diagonals, directedLine** diagonal_vertices, directedLine** new_vertices) +{ + Int i,k; + Int j,l; + Int index; + index=0; + for(i=0,k=0; itoArrayAllPolygons(total_num_edges); + quicksort( (void**)array, 0, total_num_edges-1, (Int (*)(void*, void*)) compInY); + sweepRange** ranges = (sweepRange**) malloc(sizeof(sweepRange*) * total_num_edges); + assert(ranges); + + sweepY(total_num_edges, array, ranges); + + directedLine** diagonal_vertices = (directedLine**) malloc(sizeof(directedLine*) * total_num_edges); + assert(diagonal_vertices); + findDiagonals(total_num_edges, array, ranges, num_diagonals, diagonal_vertices); + + num_diagonals=deleteRepeatDiagonals(num_diagonals, diagonal_vertices, diagonal_vertices); + return diagonal_vertices; + +} + + +/*partition into Y-monotone polygons*/ +directedLine* partitionY(directedLine *polygons, sampledLine **retSampledLines) +{ + Int total_num_edges = 0; + directedLine** array = polygons->toArrayAllPolygons(total_num_edges); + + quicksort( (void**)array, 0, total_num_edges-1, (Int (*)(void*, void*)) compInY); + + sweepRange** ranges = (sweepRange**) malloc(sizeof(sweepRange*) * (total_num_edges)); + assert(ranges); + + + + sweepY(total_num_edges, array, ranges); + + + + /*the diagonal vertices are stored as: + *v0-v1: 1st diagonal + *v2-v3: 2nd diagonal + *v5-v5: 3rd diagonal + *... + */ + + + Int num_diagonals; + /*number diagonals is < total_num_edges*total_num_edges*/ + directedLine** diagonal_vertices = (directedLine**) malloc(sizeof(directedLine*) * total_num_edges*2/*total_num_edges*/); + assert(diagonal_vertices); + + + + findDiagonals(total_num_edges, array, ranges, num_diagonals, diagonal_vertices); + + + + directedLine* ret_polygons = polygons; + sampledLine* newSampledLines = NULL; + Int i,k; + +num_diagonals=deleteRepeatDiagonals(num_diagonals, diagonal_vertices, diagonal_vertices); + + + + Int *removedDiagonals=(Int*)malloc(sizeof(Int) * num_diagonals); + for(i=0; ifindRoot(); + directedLine *root2 = v2->findRoot(); + assert(root1); + assert(root2); +*/ + +directedLine* root1 = v1->rootLinkFindRoot(); +directedLine* root2 = v2->rootLinkFindRoot(); + + if(root1 != root2) + { + + removedDiagonals[i] = 1; + sampledLine* generatedLine; + + + + v1->connectDiagonal(v1,v2, &ret_p1, &ret_p2, &generatedLine, ret_polygons); + + + + newSampledLines = generatedLine->insert(newSampledLines); +/* + ret_polygons = ret_polygons->cutoffPolygon(root1); + + ret_polygons = ret_polygons->cutoffPolygon(root2); + ret_polygons = ret_p1->insertPolygon(ret_polygons); +root1->rootLinkSet(ret_p1); +root2->rootLinkSet(ret_p1); +ret_p1->rootLinkSet(NULL); +ret_p2->rootLinkSet(ret_p1); +*/ + ret_polygons = ret_polygons->cutoffPolygon(root2); + + + +root2->rootLinkSet(root1); +ret_p1->rootLinkSet(root1); +ret_p2->rootLinkSet(root1); + + /*now that we have connected the diagonal v1 and v2, + *we have to check those unprocessed diagonals which + *have v1 or v2 as an end point. Notice that the head of v1 + *has the same coodinates as the head of v2->prev, and the head of + *v2 has the same coordinate as the head of v1->prev. + *Suppose these is a diagonal (v1, x). If (v1,x) is still a valid + *diagonal, then x should be on the left hand side of the directed line: *v1->prev->head -- v1->head -- v1->tail. Otherwise, (v1,x) should be + *replaced by (v2->prev, x), that is, x is on the left of + * v2->prev->prev->head, v2->prev->head, v2->prev->tail. + */ + Int ii, kk; + for(ii=0, kk=0; iiprev->head:v1->head:v1->tail*/ + if(! pointLeft2Lines(v1->getPrev()->head(), + v1->head(), v1->tail(), d2->head())) + { +/* + assert(pointLeft2Lines(v2->getPrev()->getPrev()->head(), + v2->getPrev()->head(), + v2->getPrev()->tail(), d2->head())); +*/ + diagonal_vertices[kk] = v2->getPrev(); + } + } + if(d1 == v2) { + /*check if d2 is to left of v2->prev->head:v2->head:v2->tail*/ + if(! pointLeft2Lines(v2->getPrev()->head(), + v2->head(), v2->tail(), d2->head())) + { +/* + assert(pointLeft2Lines(v1->getPrev()->getPrev()->head(), + v1->getPrev()->head(), + v1->getPrev()->tail(), d2->head())); +*/ + diagonal_vertices[kk] = v1->getPrev(); + } + } + /*check d2 and replace diagonal_vertices[k+1] if necessary*/ + if(d2 == v1) { + /*check if d1 is to left of v1->prev->head:v1->head:v1->tail*/ + if(! pointLeft2Lines(v1->getPrev()->head(), + v1->head(), v1->tail(), d1->head())) + { +/* assert(pointLeft2Lines(v2->getPrev()->getPrev()->head(), + v2->getPrev()->head(), + v2->getPrev()->tail(), d1->head())); +*/ + diagonal_vertices[kk+1] = v2->getPrev(); + } + } + if(d2 == v2) { + /*check if d1 is to left of v2->prev->head:v2->head:v2->tail*/ + if(! pointLeft2Lines(v2->getPrev()->head(), + v2->head(), v2->tail(), d1->head())) + { +/* assert(pointLeft2Lines(v1->getPrev()->getPrev()->head(), + v1->getPrev()->head(), + v1->getPrev()->tail(), d1->head())); +*/ + diagonal_vertices[kk+1] = v1->getPrev(); + } + } + } +}/*end if (root1 not equal to root 2)*/ +} + + /*second pass, now all diagoals should belong to the same polygon*/ + + + + for(i=0,k=0; ifindRoot(); +/* + directedLine *root2 = v2->findRoot(); + + + + assert(root1); + assert(root2); + assert(root1 == root2); + */ + sampledLine* generatedLine; + + + + v1->connectDiagonal(v1,v2, &ret_p1, &ret_p2, &generatedLine, ret_polygons); + newSampledLines = generatedLine->insert(newSampledLines); + + ret_polygons = ret_polygons->cutoffPolygon(root1); + + ret_polygons = ret_p1->insertPolygon(ret_polygons); + + ret_polygons = ret_p2->insertPolygon(ret_polygons); + + + + for(Int j=i+1; jsamePolygon(temp1, temp2)) + { + /*if temp1 and temp2 are in different polygons, + *then one of them must be v1 or v2. + */ + + + + assert(temp1==v1 || temp1 == v2 || temp2==v1 || temp2 ==v2); + if(temp1==v1) + { + diagonal_vertices[2*j] = v2->getPrev(); + } + if(temp2==v1) + { + diagonal_vertices[2*j+1] = v2->getPrev(); + } + if(temp1==v2) + { + diagonal_vertices[2*j] = v1->getPrev(); + } + if(temp2==v2) + { + diagonal_vertices[2*j+1] = v1->getPrev(); + } + } + } + } + + } + + /*clean up spaces*/ + free(array); + free(ranges); + free(diagonal_vertices); + free(removedDiagonals); + + *retSampledLines = newSampledLines; + return ret_polygons; +} + +/*given a set of simple polygons where the interior + *is decided by left-hand principle, + *return a range (sight) for each vertex. This is called + *Trapezoidalization. + */ +void sweepY(Int nVertices, directedLine** sortedVertices, sweepRange** ret_ranges) +{ + Int i; + /*for each vertex in the sorted list, update the binary search tree. + *and store the range information for each vertex. + */ + treeNode* searchTree = NULL; + for(i=0; igetPrev(); + + if(isBelow(vert, thisEdge) && isAbove(vert, prevEdge)) + { + + /*case 1: this < v < prev + *the polygon is going down at v, the interior is to + *the right hand side. + * find the edge to the right of thisEdge for right range. + * delete thisEdge + * insert prevEdge + */ + treeNode* thisNode = TreeNodeFind(searchTree, thisEdge, ( Int (*) (void *, void *))compEdges); + assert(thisNode); + + treeNode* succ = TreeNodeSuccessor(thisNode); + assert(succ); + searchTree = TreeNodeDeleteSingleNode(searchTree, thisNode); + searchTree = TreeNodeInsert(searchTree, TreeNodeMake(prevEdge), ( Int (*) (void *, void *))compEdges); + + + ret_ranges[i] = sweepRangeMake(vert, 0, (directedLine*) (succ->key), 1); + + } + else if(isAbove(vert, thisEdge) && isBelow(vert, prevEdge)) + { + + /*case 2: this > v > prev + *the polygon is going up at v, the interior is to + *the left hand side. + * find the edge to the left of thisEdge for left range. + * delete prevEdge + * insert thisEdge + */ + treeNode* prevNode = TreeNodeFind(searchTree, prevEdge, ( Int (*) (void *, void *))compEdges); + assert(prevNode); + treeNode* pred = TreeNodePredecessor(prevNode); + searchTree = TreeNodeDeleteSingleNode(searchTree, prevNode); + searchTree = TreeNodeInsert(searchTree, TreeNodeMake(thisEdge), ( Int (*) (void *, void *))compEdges); + ret_ranges[i] = sweepRangeMake((directedLine*)(pred->key), 1, vert, 0); + } + else if(isAbove(vert, thisEdge) && isAbove(vert, prevEdge)) + { + + /*case 3: insert both edges*/ + treeNode* thisNode = TreeNodeMake(thisEdge); + treeNode* prevNode = TreeNodeMake(prevEdge); + searchTree = TreeNodeInsert(searchTree, thisNode, ( Int (*) (void *, void *))compEdges); + searchTree = TreeNodeInsert(searchTree, prevNode, ( Int (*) (void *, void *))compEdges); + if(compEdges(thisEdge, prevEdge)<0) /*interior cusp*/ + { + + treeNode* leftEdge = TreeNodePredecessor(thisNode); + treeNode* rightEdge = TreeNodeSuccessor(prevNode); + ret_ranges[i] = sweepRangeMake( (directedLine*) leftEdge->key, 1, + (directedLine*) rightEdge->key, 1 + ); + } + else /*exterior cusp*/ + { + + ret_ranges[i] = sweepRangeMake( prevEdge, 1, thisEdge, 1); + } + } + else if(isBelow(vert, thisEdge) && isBelow(vert, prevEdge)) + { + + /*case 4: delete both edges*/ + treeNode* thisNode = TreeNodeFind(searchTree, thisEdge, ( Int (*) (void *, void *))compEdges); + treeNode* prevNode = TreeNodeFind(searchTree, prevEdge, ( Int (*) (void *, void *))compEdges); + if(compEdges(thisEdge, prevEdge)>0) /*interior cusp*/ + { + treeNode* leftEdge = TreeNodePredecessor(prevNode); + treeNode* rightEdge = TreeNodeSuccessor(thisNode); + ret_ranges[i] = sweepRangeMake( (directedLine*) leftEdge->key, 1, + (directedLine*) rightEdge->key, 1 + ); + } + else /*exterior cusp*/ + { + ret_ranges[i] = sweepRangeMake( thisEdge, 1, prevEdge, 1); + } + searchTree = TreeNodeDeleteSingleNode(searchTree, thisNode); + searchTree = TreeNodeDeleteSingleNode(searchTree, prevNode); + } + else + { + fprintf(stderr,"error in partitionY.C, invalid case\n"); + printf("vert is\n"); + vert->printSingle(); + printf("thisEdge is\n"); + thisEdge->printSingle(); + printf("prevEdge is\n"); + prevEdge->printSingle(); + + exit(1); + } + } + + /*finaly clean up space: delete the search tree*/ + TreeNodeDeleteWholeTree(searchTree); +} diff --git a/src/glu/sgi/libnurbs/nurbtess/partitionY.h b/src/glu/sgi/libnurbs/nurbtess/partitionY.h new file mode 100644 index 0000000..5570c18 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/partitionY.h @@ -0,0 +1,97 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* + *partitionY.h: + *partition a polygon into a Y-monotone polygon: + * A polygon is Y-monotone if the boundary can be split into two polygon chains + *A and B such that each chain is Y-monotonic that is the intersection of any + *horizontal line intersects each chain has at most one connected componenets + * (empty, single point or a single line). + * + * A vertex is a cusp if both its ajacent vertices are either at or above v, + *or both at or below v. In addition, at least one of the ajacent verteces is + *strictly below or above v. + * A vertex is a relex vertex if the internals angle is strictly greater than + *180. In other words, if the signed area is negative: + *(x1, y1), (x2, y2), (x3, y3) are the three vertices along a polygon, the + *order is such that left hand side is inside the polygon. Then (x2,y2) is + *reflex if: + * (x2-x1, y2-y1) cross (x3-x1, y3-y1) <0. + *A vertex is an interior cusp if it is a cusp and a reflex. + *A vertex is an exterior cusp if it is a cusp but not a reflex. + * + */ + +#ifndef _PARTITIONY_H +#define _PARTITIONY_H + +#include "directedLine.h" + +/*whether an edge is below a vertex*/ +Int isBelow(directedLine *v, directedLine *e); + +/*whether an edge is above a vertex*/ +Int isAbove(directedLine *v, directedLine *e); + +/*not-cusp, + *inerior cusp + *exterior cusp + */ +Int cuspType(directedLine *v); + +/*used in trapezoidalization*/ +typedef struct sweepRange{ + directedLine *left; + Int leftType; /*either a vertex (leftType=0) or an edge (leftType =1) */ + directedLine *right; + Int rightType; /*either a vertex (rightType=0) or an edge (rightType =1) */ +} sweepRange; + +sweepRange* sweepRangeMake(directedLine* left, Int leftType, + directedLine* right, Int rightType); + +void sweepRangeDelete(sweepRange* range); +Int sweepRangeEqual(sweepRange* sr1, sweepRange* sr2); + +/*given a set of simple polygons where the interior + *is decided by left-hand principle, + *return a range (sight) for each vertex. This is called + *Trapezoidalization. + */ +void sweepY(Int nVertices, directedLine **sortedVerteces, sweepRange** ret_ranges); + + +directedLine* partitionY(directedLine *polygons, sampledLine **retSampledLines); + +void findDiagonals(Int total_num_edges, directedLine** sortedVertices, sweepRange** ranges, Int& num_diagonals, directedLine** diagonal_vertices); + +directedLine** DBGfindDiagonals(directedLine *polygons, Int& num_diagonals); + +#endif diff --git a/src/glu/sgi/libnurbs/nurbtess/polyDBG.cc b/src/glu/sgi/libnurbs/nurbtess/polyDBG.cc new file mode 100644 index 0000000..4d04df7 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/polyDBG.cc @@ -0,0 +1,734 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include +#include +#include "zlassert.h" +#include "polyDBG.h" + +#ifdef __WATCOMC__ +#pragma warning 14 10 +#pragma warning 391 10 +#pragma warning 726 10 +#endif + +static Real area(Real A[2], Real B[2], Real C[2]) +{ + Real Bx, By, Cx, Cy; + Bx = B[0] - A[0]; + By = B[1] - A[1]; + Cx = C[0] - A[0]; + Cy = C[1] - A[1]; + return Bx*Cy - Cx*By; +} + +Int DBG_isConvex(directedLine *poly) +{ + directedLine* temp; + if(area(poly->head(), poly->tail(), poly->getNext()->tail()) < 0.00000) + return 0; + for(temp = poly->getNext(); temp != poly; temp = temp->getNext()) + { + if(area(temp->head(), temp->tail(), temp->getNext()->tail()) < 0.00000) + return 0; + } + return 1; +} + +Int DBG_is_U_monotone(directedLine* poly) +{ + Int n_changes = 0; + Int prev_sign; + Int cur_sign; + directedLine* temp; + cur_sign = compV2InX(poly->tail(), poly->head()); + + n_changes = (compV2InX(poly->getPrev()->tail(), poly->getPrev()->head()) + != cur_sign); + + for(temp = poly->getNext(); temp != poly; temp = temp->getNext()) + { + prev_sign = cur_sign; + cur_sign = compV2InX(temp->tail(), temp->head()); + + if(cur_sign != prev_sign) + n_changes++; + } + + if(n_changes ==2) return 1; + else return 0; +} + +/*if u-monotone, and there is a long horizontal edge*/ +Int DBG_is_U_direction(directedLine* poly) +{ +/* + if(! DBG_is_U_monotone(poly)) + return 0; +*/ + Int V_count = 0; + Int U_count = 0; + directedLine* temp; + if( fabs(poly->head()[0] - poly->tail()[0]) <= fabs(poly->head()[1]-poly->tail()[1])) + V_count += poly->get_npoints(); + else + U_count += poly->get_npoints(); + /* + else if(poly->head()[1] == poly->tail()[1]) + U_count += poly->get_npoints(); + */ + for(temp = poly->getNext(); temp != poly; temp = temp->getNext()) + { + if( fabs(temp->head()[0] - temp->tail()[0]) <= fabs(temp->head()[1]-temp->tail()[1])) + V_count += temp->get_npoints(); + else + U_count += temp->get_npoints(); + /* + if(temp->head()[0] == temp->tail()[0]) + V_count += temp->get_npoints(); + else if(temp->head()[1] == temp->tail()[1]) + U_count += temp->get_npoints(); + */ + } + + if(U_count > V_count) return 1; + else return 0; +} + +/*given two line segments, determine whether + *they intersect each other or not. + *return 1 if they do, + *return 0 otherwise + */ +Int DBG_edgesIntersect(directedLine* l1, directedLine* l2) +{ + if(l1->getNext() == l2) + { + if(area(l1->head(), l1->tail(), l2->tail()) == 0) //colinear + { + if( (l1->tail()[0] - l1->head()[0])*(l2->tail()[0]-l2->head()[0]) + + (l1->tail()[1] - l1->head()[1])*(l2->tail()[1]-l2->head()[1]) >=0) + return 0; //not intersect + else + return 1; + } + //else we use the normal code + } + else if(l1->getPrev() == l2) + { + if(area(l2->head(), l2->tail(), l1->tail()) == 0) //colinear + { + if( (l2->tail()[0] - l2->head()[0])*(l1->tail()[0]-l1->head()[0]) + + (l2->tail()[1] - l2->head()[1])*(l1->tail()[1]-l1->head()[1]) >=0) + return 0; //not intersect + else + return 1; + } + //else we use the normal code + } + else //the two edges are not connected + { + if((l1->head()[0] == l2->head()[0] && + l1->head()[1] == l2->head()[1]) || + (l1->tail()[0] == l2->tail()[0] && + l1->tail()[1] == l2->tail()[1])) + return 1; + + } + + + if( + ( + area(l1->head(), l1->tail(), l2->head()) + * + area(l1->head(), l1->tail(), l2->tail()) + < 0 + ) + && + ( + area(l2->head(), l2->tail(), l1->head()) + *area(l2->head(), l2->tail(), l1->tail()) + < 0 + ) + ) + return 1; + else + return 0; +} + +/*whether AB and CD intersect + *return 1 if they do + *retur 0 otheriwse + */ +Int DBG_edgesIntersectGen(Real A[2], Real B[2], Real C[2], Real D[2]) +{ + if( + ( + area(A, B, C) * area(A,B,D) <0 + ) + && + ( + area(C,D,A) * area(C,D,B) < 0 + ) + ) + return 1; + else + return 0; +} + +/*determien whether (A,B) interesect chain[start] to [end] + */ +Int DBG_intersectChain(vertexArray* chain, Int start, Int end, Real A[2], Real B[2]) +{ + Int i; + for(i=start; i<=end-2; i++) + if(DBG_edgesIntersectGen(chain->getVertex(i), chain->getVertex(i+1), A, B)) + return 1; + + return 0; +} + +/*determine whether a polygon intersect itself or not + *return 1 is it does, + * 0 otherwise + */ +Int DBG_polygonSelfIntersect(directedLine* poly) +{ + directedLine* temp1; + directedLine* temp2; + temp1=poly; + for(temp2=temp1->getNext(); temp2 != temp1; temp2=temp2->getNext()) + { + if(DBG_edgesIntersect(temp1, temp2)) + { + return 1; + } + + } + + for(temp1=poly->getNext(); temp1 != poly; temp1 = temp1->getNext()) + for(temp2=temp1->getNext(); temp2 != temp1; temp2=temp2->getNext()) + { + if(DBG_edgesIntersect(temp1, temp2)) + { + return 1; + } + } + return 0; +} + +/*check whether a line segment intersects a polygon + */ +Int DBG_edgeIntersectPoly(directedLine* edge, directedLine* poly) +{ + directedLine* temp; + if(DBG_edgesIntersect(edge, poly)) + return 1; + for(temp=poly->getNext(); temp != poly; temp=temp->getNext()) + if(DBG_edgesIntersect(edge, temp)) + return 1; + return 0; +} + +/*check whether two polygons intersect + */ +Int DBG_polygonsIntersect(directedLine* p1, directedLine* p2) +{ + directedLine* temp; + if(DBG_edgeIntersectPoly(p1, p2)) + return 1; + for(temp=p1->getNext(); temp!= p1; temp = temp->getNext()) + if(DBG_edgeIntersectPoly(temp, p2)) + return 1; + return 0; +} + +/*check whether there are polygons intersecting each other in + *a list of polygons + */ +Int DBG_polygonListIntersect(directedLine* pList) +{ + directedLine *temp; + for(temp=pList; temp != NULL; temp = temp->getNextPolygon()) + if(DBG_polygonSelfIntersect(temp)) + return 1; + directedLine* temp2; + for(temp=pList; temp!=NULL; temp=temp->getNextPolygon()) + { + for(temp2=temp->getNextPolygon(); temp2 != NULL; temp2=temp2->getNextPolygon()) + if(DBG_polygonsIntersect(temp, temp2)) + return 1; + } + + return 0; +} + + +Int DBG_isCounterclockwise(directedLine* poly) +{ + return (poly->polyArea() > 0); +} + +/*ray: v0 with direction (dx,dy). + *edge: v1-v2. + * the extra point v10[2] is given for the information at + *v1. Basically this edge is connectd to edge + * v10-v1. If v1 is on the ray, + * then we need v10 to determine whether this ray intersects + * the edge or not (that is, return 1 or return 0). + * If v1 is on the ray, then if v2 and v10 are on the same side of the ray, + * we return 0, otherwise return 1. + *For v2, if v2 is on the ray, we always return 0. + *Notice that v1 and v2 are not symmetric. So the edge is directed!!! + * The purpose for this convention is such that: a point is inside a polygon + * if and only if it intersets with odd number of edges. + */ +Int DBG_rayIntersectEdge(Real v0[2], Real dx, Real dy, Real v10[2], Real v1[2], Real v2[2]) +{ +/* +if( (v1[1] >= v0[1] && v2[1]<= v0[1] ) + ||(v2[1] >= v0[1] && v1[1]<= v0[1] ) + ) + printf("rayIntersectEdge, *********\n"); +*/ + + Real denom = (v2[0]-v1[0])*(-dy) - (v2[1]-v1[1]) * (-dx); + Real nomRay = (v2[0]-v1[0]) * (v0[1] - v1[1]) - (v2[1]-v1[1])*(v0[0]-v1[0]); + Real nomEdge = (v0[0]-v1[0]) * (-dy) - (v0[1]-v1[1])*(-dx); + + + /*if the ray is parallel to the edge, return 0: not intersect*/ + if(denom == 0.0) + return 0; + + /*if v0 is on the edge, return 0: not intersect*/ + if(nomRay == 0.0) + return 0; + + /*if v1 is on the positive ray, and the neighbor of v1 crosses the ray + *return 1: intersect + */ + if(nomEdge == 0) + { /*v1 is on the positive or negative ray*/ + +/* + printf("v1 is on the ray\n"); +*/ + + if(dx*(v1[0]-v0[0])>=0 && dy*(v1[1]-v0[1])>=0) /*v1 on positive ray*/ + { + if(area(v0, v1, v10) * area(v0, v1, v2) >0) + return 0; + else + return 1; + } + else /*v1 on negative ray*/ + return 0; + } + + /*if v2 is on the ray, always return 0: not intersect*/ + if(nomEdge == denom) { +/* printf("v2 is on the ray\n");*/ + return 0; + } + + /*finally */ + if(denom*nomRay>0 && denom*nomEdge>0 && nomEdge/denom <=1.0) + return 1; + return 0; +} + + +/*return the number of intersections*/ +Int DBG_rayIntersectPoly(Real v0[2], Real dx, Real dy, directedLine* poly) +{ + directedLine* temp; + Int count=0; + if(DBG_rayIntersectEdge(v0, dx, dy, poly->getPrev()->head(), poly->head(), poly->tail())) + count++; + + for(temp=poly->getNext(); temp != poly; temp = temp->getNext()) + if(DBG_rayIntersectEdge(v0, dx, dy, temp->getPrev()->head(), temp->head(), temp->tail())) + count++; +/*printf("ray intersect poly: count=%i\n", count);*/ + return count; +} + +Int DBG_pointInsidePoly(Real v[2], directedLine* poly) +{ +/* +printf("enter pointInsidePoly , v=(%f,%f)\n", v[0], v[1]); +printf("the polygon is\n"); +poly->printList(); +*/ + /*for debug purpose*/ + assert( (DBG_rayIntersectPoly(v,1,0,poly) % 2 ) + == (DBG_rayIntersectPoly(v,1,Real(0.1234), poly) % 2 ) + ); + if(DBG_rayIntersectPoly(v, 1, 0, poly) % 2 == 1) + return 1; + else + return 0; +} + +/*return the number of polygons which contain thie polygon + * as a subset + */ +Int DBG_enclosingPolygons(directedLine* poly, directedLine* list) +{ + directedLine* temp; + Int count=0; +/* +printf("%i\n", DBG_pointInsidePoly(poly->head(), + list->getNextPolygon() + ->getNextPolygon() + ->getNextPolygon() + ->getNextPolygon() +)); +*/ + + for(temp = list; temp != NULL; temp = temp->getNextPolygon()) + { + if(poly != temp) + if(DBG_pointInsidePoly(poly->head(), temp)) + count++; +/* printf("count=%i\n", count);*/ + } + return count; +} + +void DBG_reverse(directedLine* poly) +{ + if(poly->getDirection() == INCREASING) + poly->putDirection(DECREASING); + else + poly->putDirection(INCREASING); + + directedLine* oldNext = poly->getNext(); + poly->putNext(poly->getPrev()); + poly->putPrev(oldNext); + + directedLine* temp; + for(temp=oldNext; temp!=poly; temp = oldNext) + { + if(temp->getDirection() == INCREASING) + temp->putDirection(DECREASING); + else + temp->putDirection(INCREASING); + + oldNext = temp->getNext(); + temp->putNext(temp->getPrev()); + temp->putPrev(oldNext); + } + printf("reverse done\n"); +} + +Int DBG_checkConnectivity(directedLine *polygon) +{ + if(polygon == NULL) return 1; + directedLine* temp; + if(polygon->head()[0] != polygon->getPrev()->tail()[0] || + polygon->head()[1] != polygon->getPrev()->tail()[1]) + return 0; + for(temp=polygon->getNext(); temp != polygon; temp=temp->getNext()) + { + if(temp->head()[0] != temp->getPrev()->tail()[0] || + temp->head()[1] != temp->getPrev()->tail()[1]) + return 0; + } + return 1; +} + +/*print out error message. + *If it cannot modify the polygon list to make it satify the + *requirements, return 1. + *otherwise modify the polygon list, and return 0 + */ +Int DBG_check(directedLine *polyList) +{ + directedLine* temp; + if(polyList == NULL) return 0; + + /*if there are intersections, print out error message + */ + if(DBG_polygonListIntersect(polyList)) + { + fprintf(stderr, "DBG_check: there are self intersections, don't know to modify the polygons\n"); + return 1; + } + + /*check the connectivity of each polygon*/ + for(temp = polyList; temp!= NULL; temp = temp ->getNextPolygon()) + { + if(! DBG_checkConnectivity(temp)) + { + fprintf(stderr, "DBG_check, polygon not connected\n"); + return 1; + } + } + + /*check the orientation of each polygon*/ + for(temp = polyList; temp!= NULL; temp = temp ->getNextPolygon()) + { + + + Int correctDir; + + if( DBG_enclosingPolygons(temp, polyList) % 2 == 0) + correctDir = 1; /*counterclockwise*/ + else + correctDir = 0; /*clockwise*/ + + Int actualDir = DBG_isCounterclockwise(temp); + + if(correctDir != actualDir) + { + fprintf(stderr, "DBG_check: polygon with incorrect orientations. reversed\n"); + + DBG_reverse(temp); + } + + } + return 0; +} + +/**************handle self intersections*****************/ +//determine whether e interects [begin, end] or not +static directedLine* DBG_edgeIntersectChainD(directedLine *e, + directedLine *begin, directedLine *end) +{ + directedLine *temp; + for(temp=begin; temp != end; temp = temp->getNext()) + { + if(DBG_edgesIntersect(e, temp)) + return temp; + } + if(DBG_edgesIntersect(e, end)) + return end; + return NULL; +} + +//given a polygon, cut the edges off and finally obtain a +//a polygon without intersections. The cut-off edges are +//dealloated. The new polygon is returned. +directedLine* DBG_cutIntersectionPoly(directedLine *polygon, int& cutOccur) +{ + directedLine *begin, *end, *next; + begin = polygon; + end = polygon; + cutOccur = 0; + while( (next = end->getNext()) != begin) + { + directedLine *interc = NULL; + if( (interc = DBG_edgeIntersectChainD(next, begin, end))) + { + int fixed = 0; + if(DBG_edgesIntersect(next, interc->getNext())) + { + //trying to fix it + Real buf[2]; + int i; + Int n=5; + buf[0] = interc->tail()[0]; + buf[1] = interc->tail()[1]; + + for(i=1; ihead()[0] + r * interc->tail()[0]; + Real v = (1-r) * interc->head()[1] + r * interc->tail()[1]; + interc->tail()[0] = interc->getNext()->head()[0] = u; + interc->tail()[1] = interc->getNext()->head()[1] = v; + if( (! DBG_edgesIntersect(next, interc)) && + (! DBG_edgesIntersect(next, interc->getNext()))) + break; //we fixed it + } + if(i==n) // we didn't fix it + { + fixed = 0; + //back to original + interc->tail()[0] = interc->getNext()->head()[0] = buf[0]; + interc->tail()[1] = interc->getNext()->head()[1] = buf[1]; + } + else + { + fixed = 1; + } + } + if(fixed == 0) + { + cutOccur = 1; + begin->deleteSingleLine(next); + + if(begin != end) + { + if(DBG_polygonSelfIntersect(begin)) + { + directedLine* newEnd = end->getPrev(); + begin->deleteSingleLine(end); + end = newEnd; + } + } + } + else + { + end = end->getNext(); + } + } + else + { + end = end->getNext(); + } + } + return begin; +} + +//given a polygon, cut the edges off and finally obtain a +//a polygon without intersections. The cut-off edges are +//dealloated. The new polygon is returned. +#if 0 // UNUSED +static directedLine* DBG_cutIntersectionPoly_notwork(directedLine *polygon) +{ + directedLine *crt;//current polygon + directedLine *begin; + directedLine *end; + directedLine *temp; + crt = polygon; + int find=0; + while(1) + { +//printf("loop\n"); + //if there are less than 3 edges, we should stop + if(crt->getPrev()->getPrev() == crt) + return NULL; + + if(DBG_edgesIntersect(crt, crt->getNext()) || + (crt->head()[0] == crt->getNext()->tail()[0] && + crt->head()[1] == crt->getNext()->tail()[1]) + ) + { + find = 1; + crt=crt->deleteChain(crt, crt->getNext()); + } + else + { + //now we know crt and crt->getNext do not intersect + begin = crt; + end = crt->getNext(); +//printf("begin=(%f,%f)\n", begin->head()[0], begin->head()[1]); +//printf("end=(%f,%f)\n", end->head()[0], end->head()[1]); + for(temp=end->getNext(); temp!=begin; temp= temp->getNext()) + { +//printf("temp=(%f,%f)\n", temp->head()[0], temp->head()[1]); + directedLine *intersect = DBG_edgeIntersectChainD(temp, begin, end); + if(intersect != NULL) + { + crt = crt->deleteChain(intersect, temp); + find=1; + break; //the for loop + } + else + { + end = temp; + } + } + } + if(find == 0) + return crt; + else + find = 0; //go to next loop +} +} +#endif + +directedLine* DBG_cutIntersectionAllPoly(directedLine* list) +{ + directedLine* temp; + directedLine* tempNext=NULL; + directedLine* ret = NULL; + int cutOccur=0; + for(temp=list; temp != NULL; temp = tempNext) + { + directedLine *left; + tempNext = temp->getNextPolygon(); + + left = DBG_cutIntersectionPoly(temp, cutOccur); + if(left != NULL) + ret=left->insertPolygon(ret); + } + return ret; +} + +sampledLine* DBG_collectSampledLinesAllPoly(directedLine *polygonList) +{ + directedLine *temp; + sampledLine* tempHead = NULL; + sampledLine* tempTail = NULL; + sampledLine* cHead = NULL; + sampledLine* cTail = NULL; + + if(polygonList == NULL) + return NULL; + + DBG_collectSampledLinesPoly(polygonList, cHead, cTail); + + assert(cHead); + assert(cTail); + for(temp = polygonList->getNextPolygon(); temp != NULL; temp = temp->getNextPolygon()) + { + DBG_collectSampledLinesPoly(temp, tempHead, tempTail); + cTail->insert(tempHead); + cTail = tempTail; + } + return cHead; +} + +void DBG_collectSampledLinesPoly(directedLine *polygon, sampledLine*& retHead, sampledLine*& retTail) +{ + directedLine *temp; + retHead = NULL; + retTail = NULL; + if(polygon == NULL) + return; + + retHead = retTail = polygon->getSampledLine(); + for(temp = polygon->getNext(); temp != polygon; temp=temp->getNext()) + { + retHead = temp->getSampledLine()->insert(retHead); + } +} diff --git a/src/glu/sgi/libnurbs/nurbtess/polyDBG.h b/src/glu/sgi/libnurbs/nurbtess/polyDBG.h new file mode 100644 index 0000000..74843d8 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/polyDBG.h @@ -0,0 +1,68 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _POLYDBG_H +#define _POLYDBG_H + +#include "definitions.h" +#include "directedLine.h" +#include "monoTriangulation.h" + +Int DBG_edgesIntersectGen(Real A[2], Real B[2], Real C[2], Real D[2]); +Int DBG_intersectChain(vertexArray* chain, Int start, Int end, Real A[2], Real B[2]); + + +Int DBG_edgesIntersect(directedLine* l1, directedLine* l2); +Int DBG_polygonSelfIntersect(directedLine* poly); +Int DBG_edgeIntersectPoly(directedLine* edge, directedLine* poly); +Int DBG_polygonsIntersect(directedLine* p1, directedLine* p2); +Int DBG_polygonListIntersect(directedLine* pList); + +Int DBG_isCounterclockwise(directedLine* poly); +Int DBG_rayIntersectEdge(Real v0[2], Real dx, Real dy, Real v10[2], Real v1[2], Real v2[2]); +Int DBG_pointInsidePoly(Real v[2], directedLine* poly); +Int DBG_enclosingPolygons(directedLine* poly, directedLine* list); +void DBG_reverse(directedLine* poly); +Int DBG_check(directedLine *polyList); + +Int DBG_isConvex(directedLine *poly); +Int DBG_is_U_direction(directedLine *poly); +Int DBG_is_U_monotone(directedLine* poly); + +directedLine* DBG_cutIntersectionAllPoly(directedLine* list); +directedLine* DBG_cutIntersectionPoly(directedLine *polygon, int& cutOccur); + +sampledLine* DBG_collectSampledLinesAllPoly(directedLine *polygonList); + +void DBG_collectSampledLinesPoly(directedLine *polygon, sampledLine*& retHead, sampledLine*& retTail); + +#endif diff --git a/src/glu/sgi/libnurbs/nurbtess/polyUtil.cc b/src/glu/sgi/libnurbs/nurbtess/polyUtil.cc new file mode 100644 index 0000000..f9a27f4 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/polyUtil.cc @@ -0,0 +1,90 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include + +#include "polyUtil.h" + +Real area(Real A[2], Real B[2], Real C[2]) +{ + Real Bx, By, Cx, Cy; + Bx = B[0] - A[0]; + By = B[1] - A[1]; + Cx = C[0] - A[0]; + Cy = C[1] - A[1]; + return Bx*Cy - Cx*By; + +/* return (B[0]-A[0])*(C[1]-A[1]) - (C[0]-A[0])*(B[1]-A[1]);*/ +} + +/*given a directed line A->B, and a point P, + *determine whether P is to the left of AB. + *the line A->B (imagine it has beedn extended both + *end to the infinity) divides the plan into two + *half planes. When we walk from A to B, one + *half is to the left and the other half is to the right. + *return 1 if P is to the left. + *if P is on AB, 0 is returned. + */ +Int pointLeftLine(Real A[2], Real B[2], Real P[2]) +{ + if(area(A, B, P) >0) return 1; + else return 0; +} + +/*given two directed line: A -> B -> C, and another point P. + *determine whether P is to the left hand side of A->B->C. + *Think of BA and BC extended as two rays. So that the plane is + * divided into two parts. One part is to the left we walk from A + *to B and to C, the other part is to the right. + * In order for P to be the left, P must be either to the left + *of + */ +Int pointLeft2Lines(Real A[2], Real B[2], Real C[2], Real P[2]) +{ + Int C_left_AB = (area(A, B, C)>0); + Int P_left_AB = (area(A, B, P)>0); + Int P_left_BC = (area(B, C, P)>0); + + if(C_left_AB) + { + return (P_left_AB && P_left_BC); + } + else + return (P_left_AB || P_left_BC); +} diff --git a/src/glu/sgi/libnurbs/nurbtess/polyUtil.h b/src/glu/sgi/libnurbs/nurbtess/polyUtil.h new file mode 100644 index 0000000..1ca2ebc --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/polyUtil.h @@ -0,0 +1,47 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _POLYUTIL_H +#define _POLYUTIL_H + +#include "definitions.h" +#ifdef __cplusplus +extern "C" { +#endif +Real area(Real A[2], Real B[2], Real C[2]); + +Int pointLeftLine(Real A[2], Real B[2], Real P[2]); +Int pointLeft2Lines(Real A[2], Real B[2], Real C[2], Real P[2]); +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/glu/sgi/libnurbs/nurbtess/primitiveStream.cc b/src/glu/sgi/libnurbs/nurbtess/primitiveStream.cc new file mode 100644 index 0000000..dfdbd4e --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/primitiveStream.cc @@ -0,0 +1,192 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include "gluos.h" +#include +#include +#include +#include + +#include "primitiveStream.h" + +Int primStream::num_triangles() +{ + Int i; + Int ret=0; + for(i=0; i= size_vertices) { + Real* temp = (Real*) malloc (sizeof(Real) * (2*size_vertices + 2)); + assert(temp); + + /*copy*/ + for(Int i=0; i= size_lengths){ + Int* temp = (Int*) malloc(sizeof(Int) * (2*size_lengths + 2)); + assert(temp); + Int* tempTypes = (Int*) malloc(sizeof(Int) * (2*size_lengths + 2)); + assert(tempTypes); + + /*copy*/ + for(i=0; i + */ + +#ifndef _PRIMITIVE_STREAM_H +#define _PRIMITIVE_STREAM_H + +enum {PRIMITIVE_STREAM_FAN, PRIMITIVE_STREAM_STRIP}; + +#include "definitions.h" + +class primStream { + Int *lengths; /*length[i]=number of vertices of ith primitive*/ + Int *types; /*each primive has a type: FAN or STREAM*/ + Real *vertices; /*the size >= 2 * num_vertices, each vertex (u,v)*/ + + /*the following size information are used for dynamic arrays*/ + Int index_lengths; /*the current available entry*/ + Int size_lengths; /*the allocated size of the array: lengths*/ + Int index_vertices; + Int size_vertices; + + /*the vertex is inserted one by one. counter is used to + *count the number of vertices which have been inserted so far in + *the current primitive + */ + Int counter; + +public: + primStream(Int sizeLengths, Int sizeVertices); + ~primStream(); + + Int get_n_prims() //num of primitives + { + return index_lengths; + } + Int get_type(Int i) //the type of ith primitive + { + return types[i]; + } + Int get_length(Int i) //the length of the ith primitive + { + return lengths[i]; + } + Real* get_vertices() {return vertices;} + + /*the begining of inserting a new primitive. + *reset counter to be 0. + */ + void begin(); + void insert(Real u, Real v); + void insert(Real v[2]) {insert(v[0], v[1]);} + void end(Int type); + + Int num_triangles(); + + void triangle(Real A[2], Real B[2], Real C[2]) + { + begin(); + insert(A); + insert(B); + insert(C); + end(PRIMITIVE_STREAM_FAN); + } + void print(); + void draw(); /*using GL to draw the primitives*/ +}; + + + + + + + + +#endif + diff --git a/src/glu/sgi/libnurbs/nurbtess/quicksort.cc b/src/glu/sgi/libnurbs/nurbtess/quicksort.cc new file mode 100644 index 0000000..9d0b290 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/quicksort.cc @@ -0,0 +1,77 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include + + +static void swap(void *v[], int i, int j) +{ + void *temp; + temp = v[i]; + v[i] = v[j]; + v[j] = temp; +} + +/*as an example to use this function to + *sort integers, you need to supply the function + *int comp(int *i1, int *i2) + *{ + * if( *i1 < * i2) return -1; + * else return 1; + *} + *and an array of pointers to integers: + * int *v[100] (allocate space for where each v[i] points to). + *then you can call: + * quicksort( (void**)v, left, right, (int (*)(void *, void *))comp) + */ +void quicksort(void *v[], int left, int right, + int (*comp) (void *, void *)) +{ + int i, last; + if(left >= right) /*do nothing if array contains */ + return; /*fewer than two elements*/ + + swap(v, left, (left+right)/2); + last = left; + for(i=left+1; i<=right; i++) + if((*comp)(v[i], v[left])<0) + swap(v, ++last, i); + swap(v, left, last); + quicksort(v, left, last-1, comp); + quicksort(v, last+1, right, comp); +} diff --git a/src/glu/sgi/libnurbs/nurbtess/quicksort.h b/src/glu/sgi/libnurbs/nurbtess/quicksort.h new file mode 100644 index 0000000..3a8dcd6 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/quicksort.h @@ -0,0 +1,42 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _QUICKSORT_H +#define _QUICKSORT_H + +#include +#include + +void quicksort(void *v[], int left, int right, + int (*comp) (void *, void *)); + +#endif diff --git a/src/glu/sgi/libnurbs/nurbtess/rectBlock.cc b/src/glu/sgi/libnurbs/nurbtess/rectBlock.cc new file mode 100644 index 0000000..f457b15 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/rectBlock.cc @@ -0,0 +1,196 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include "gluos.h" +#include +#include +#include "glimports.h" +#include "zlassert.h" +#include + +#include "rectBlock.h" + +rectBlock::rectBlock(gridBoundaryChain* left, gridBoundaryChain* right, Int beginVline, Int endVline) +{ + Int i; + + + upGridLineIndex = left->getVlineIndex(beginVline); + + lowGridLineIndex = left->getVlineIndex(endVline); + + Int n = upGridLineIndex-lowGridLineIndex+1; //number of grid lines + leftIndices = (Int*) malloc(sizeof(Int) * n); + assert(leftIndices); + rightIndices = (Int*) malloc(sizeof(Int) * n); + assert(rightIndices); + for(i=0; igetInnerIndex(i+beginVline); + rightIndices[i] = right->getInnerIndex(i+beginVline); + } +} + + +rectBlock::~rectBlock() +{ + free(leftIndices); + free(rightIndices); +} + +void rectBlock::print() +{ + Int i; + printf("block:\n"); + for(i=upGridLineIndex; i >= lowGridLineIndex; i--) + { + printf("gridline %i, (%i,%i)\n", i, leftIndices[upGridLineIndex-i], rightIndices[upGridLineIndex-i]); + } +} + + + +void rectBlock::draw(Real* u_values, Real* v_values) +{ + Int i,j,k; + //upgrid line to bot grid line +#ifdef DEBUG +printf("upGridLineIndex=%i, lowGridLineIndex=%i\n", upGridLineIndex, lowGridLineIndex); +#endif + for(k=0, i=upGridLineIndex; i > lowGridLineIndex; i--, k++) + { + glBegin(GL_QUAD_STRIP); + + for(j=leftIndices[k+1]; j<= rightIndices[k+1]; j++) + { + glVertex2f(u_values[j], v_values[i]); + glVertex2f(u_values[j], v_values[i-1]); + } + glEnd(); + } +} + + +Int rectBlock::num_quads() +{ + Int ret=0; + Int k,i; + for(k=0, i=upGridLineIndex; i>lowGridLineIndex; i--, k++) + { + ret += (rightIndices[k+1]-leftIndices[k+1]); + } + return ret; +} + +Int rectBlockArray::num_quads() +{ + Int ret=0; + for(Int i=0; inum_quads(); + return ret; +} + +rectBlockArray::rectBlockArray(Int s) +{ + Int i; + n_elements = 0; + size = s; + array = (rectBlock**) malloc(sizeof(rectBlock*) * s); + assert(array); +//initialization + for(i=0; iprint(); +} + +void rectBlockArray::draw(Real* u_values, Real* v_values) +{ + Int i; + for(i=0; idraw(u_values, v_values); +} + + + + + + + + + + diff --git a/src/glu/sgi/libnurbs/nurbtess/rectBlock.h b/src/glu/sgi/libnurbs/nurbtess/rectBlock.h new file mode 100644 index 0000000..8dbd7eb --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/rectBlock.h @@ -0,0 +1,82 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _RECTBLOCK_H +#define _RECTBLOCK_H + +#include "definitions.h" +#include "gridWrap.h" + +class rectBlock{ + Int upGridLineIndex; + Int lowGridLineIndex; + Int* leftIndices; //up to bottome + Int* rightIndices; //up to bottom +public: + //the arrays are copies. + rectBlock(gridBoundaryChain* left, gridBoundaryChain* right, Int beginVline, Int endVline); + ~rectBlock(); //free the two arrays + + Int get_upGridLineIndex() {return upGridLineIndex;} + Int get_lowGridLineIndex() {return lowGridLineIndex;} + Int* get_leftIndices() {return leftIndices;} + Int* get_rightIndices() {return rightIndices;} + + Int num_quads(); + + void print(); + void draw(Real* u_values, Real* v_values); +}; + + +class rectBlockArray{ + rectBlock** array; + Int n_elements; + Int size; +public: + rectBlockArray(Int s); + ~rectBlockArray();//delete avarything including the blocks + + Int get_n_elements() {return n_elements;} + rectBlock* get_element(Int i) {return array[i];} + void insert(rectBlock* newBlock); //only take the pointer, not ther cotent + + Int num_quads(); + + void print(); + void draw(Real* u_values, Real* v_values); +}; + + + +#endif + diff --git a/src/glu/sgi/libnurbs/nurbtess/sampleComp.cc b/src/glu/sgi/libnurbs/nurbtess/sampleComp.cc new file mode 100644 index 0000000..861c71b --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/sampleComp.cc @@ -0,0 +1,371 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include +#include "glimports.h" +#include "sampleComp.h" +#include "sampleCompTop.h" +#include "sampleCompBot.h" +#include "sampleCompRight.h" + + + +#define max(a,b) ((a>b)? a:b) +#define min(a,b) ((a>b)? b:a) + +void sampleConnectedComp(Real* topVertex, Real* botVertex, + vertexArray* leftChain, + Int leftStartIndex, Int leftEndIndex, + vertexArray* rightChain, + Int rightStartIndex, Int rightEndIndex, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridIndex1, Int gridIndex2, + Int up_leftCornerWhere, + Int up_leftCornerIndex, + Int up_rightCornerWhere, + Int up_rightCornerIndex, + Int down_leftCornerWhere, + Int down_leftCornerIndex, + Int down_rightCornerWhere, + Int down_rightCornerIndex, + primStream* pStream, + rectBlockArray* rbArray + ) +{ + + sampleCompLeft(topVertex, botVertex, + leftChain, + leftStartIndex, leftEndIndex, + rightChain, + rightStartIndex, rightEndIndex, + leftGridChain, + gridIndex1, + gridIndex2, + up_leftCornerWhere, + up_leftCornerIndex, + down_leftCornerWhere, + down_leftCornerIndex, + pStream); + + + sampleCompRight(topVertex, botVertex, + leftChain, + leftStartIndex, leftEndIndex, + rightChain, + rightStartIndex, + rightEndIndex, + rightGridChain, + gridIndex1, gridIndex2, + up_rightCornerWhere, + up_rightCornerIndex, + down_rightCornerWhere, + down_rightCornerIndex, + pStream); + + + sampleCompTop(topVertex, + leftChain, + leftStartIndex, + rightChain, + rightStartIndex, + leftGridChain, + rightGridChain, + gridIndex1, + up_leftCornerWhere, + up_leftCornerIndex, + up_rightCornerWhere, + up_rightCornerIndex, + pStream); + + sampleCompBot(botVertex, + leftChain, + leftEndIndex, + rightChain, + rightEndIndex, + leftGridChain, + rightGridChain, + gridIndex2, + down_leftCornerWhere, + down_leftCornerIndex, + down_rightCornerWhere, + down_rightCornerIndex, + pStream); + + + //the center + + rbArray->insert(new rectBlock(leftGridChain, rightGridChain, gridIndex1, gridIndex2)); + + +} + +/*notice that we need rightChain because the + *corners could be on the rightChain. + *here comp means component. + */ +void sampleCompLeft(Real* topVertex, Real* botVertex, + vertexArray* leftChain, + Int leftStartIndex, Int leftEndIndex, + vertexArray* rightChain, + Int rightStartIndex, Int rightEndIndex, + gridBoundaryChain* leftGridChain, + Int gridIndex1, Int gridIndex2, + Int up_leftCornerWhere, + Int up_leftCornerIndex, + Int down_leftCornerWhere, + Int down_leftCornerIndex, + primStream* pStream) +{ + /*find out whether there is a trim vertex which is + *inbetween the top and bot grid lines or not. + */ + Int midIndex1; + Int midIndex2; + Int gridMidIndex1 = 0, gridMidIndex2 = 0; + //midIndex1: array[i] <= v, array[i-1] > v + //midIndex2: array[i] >= v, array[i+1] < v + // v(gridMidIndex1) >= v(midindex1) > v(gridMidIndex1+1) + // v(gridMidIndex2-1) >= v(midIndex2) > v(gridMidIndex2) ?? + midIndex1 = leftChain->findIndexBelowGen( + leftGridChain->get_v_value(gridIndex1), + leftStartIndex, + leftEndIndex); + + midIndex2 = -1; /*initilization*/ + if(midIndex1<= leftEndIndex && gridIndex1getVertex(midIndex1)[1] >= leftGridChain->get_v_value(gridIndex2)) + { + midIndex2 = leftChain->findIndexAboveGen( + leftGridChain->get_v_value(gridIndex2), + midIndex1, //midIndex1 <= midIndex2. + leftEndIndex); + gridMidIndex1 = leftGridChain->lookfor(leftChain->getVertex(midIndex1)[1], + gridIndex1, gridIndex2); + gridMidIndex2 = 1+leftGridChain->lookfor(leftChain->getVertex(midIndex2)[1], + gridMidIndex1, gridIndex2); + } + + + /*to interprete the corner information*/ + Real* cornerTop; + Real* cornerBot; + Int cornerLeftStart; + Int cornerLeftEnd; + Int cornerRightUpEnd; + Int cornerRightDownStart; + if(up_leftCornerWhere == 0) /*left corner is on left chain*/ + { + cornerTop = leftChain->getVertex(up_leftCornerIndex); + cornerLeftStart = up_leftCornerIndex+1; + cornerRightUpEnd = -1; /*no right*/ + } + else if(up_leftCornerWhere == 1) /*left corner is on top*/ + { + cornerTop = topVertex; + cornerLeftStart = leftStartIndex; + cornerRightUpEnd = -1; /*no right*/ + } + else /*left corner is on right chain*/ + { + cornerTop = topVertex; + cornerLeftStart = leftStartIndex; + cornerRightUpEnd = up_leftCornerIndex; + } + + if(down_leftCornerWhere == 0) /*left corner is on left chain*/ + { + cornerBot = leftChain->getVertex(down_leftCornerIndex); + cornerLeftEnd = down_leftCornerIndex-1; + cornerRightDownStart = rightEndIndex+1; /*no right*/ + } + else if(down_leftCornerWhere == 1) /*left corner is on bot*/ + { + cornerBot = botVertex; + cornerLeftEnd = leftEndIndex; + cornerRightDownStart = rightEndIndex+1; /*no right*/ + } + else /*left corner is on the right chian*/ + { + cornerBot = botVertex; + cornerLeftEnd = leftEndIndex; + cornerRightDownStart = down_leftCornerIndex; + } + + + + + /*sample*/ + if(midIndex2 >= 0) /*there is a trim point inbewteen grid lines*/ + { + + sampleLeftSingleTrimEdgeRegionGen(cornerTop, leftChain->getVertex(midIndex1), + leftChain, + cornerLeftStart, + midIndex1-1, + leftGridChain, + gridIndex1, + gridMidIndex1, + rightChain, + rightStartIndex, + cornerRightUpEnd, + 0, //no right down section + -1, + pStream); + + sampleLeftSingleTrimEdgeRegionGen(leftChain->getVertex(midIndex2), + cornerBot, + leftChain, + midIndex2+1, + cornerLeftEnd, + leftGridChain, + gridMidIndex2, + gridIndex2, + rightChain, + 0, //no right up section + -1, + cornerRightDownStart, + rightEndIndex, + pStream); + + + sampleLeftStripRecF(leftChain, + midIndex1, + midIndex2, + leftGridChain, + gridMidIndex1, + gridMidIndex2, + pStream); + } + else + { + sampleLeftSingleTrimEdgeRegionGen(cornerTop, cornerBot, + leftChain, + cornerLeftStart, + cornerLeftEnd, + leftGridChain, + gridIndex1, + gridIndex2, + rightChain, + rightStartIndex, + cornerRightUpEnd, + cornerRightDownStart, + rightEndIndex, + pStream); + } +} + +void sampleLeftSingleTrimEdgeRegionGen(Real topVert[2], Real botVert[2], + vertexArray* leftChain, + Int leftStart, + Int leftEnd, + gridBoundaryChain* gridChain, + Int gridBeginIndex, + Int gridEndIndex, + vertexArray* rightChain, + Int rightUpBegin, + Int rightUpEnd, + Int rightDownBegin, + Int rightDownEnd, + primStream* pStream) +{ + Int i,j,k; + + /*creat an array to store all the up and down secments of the right chain, + *and the left end grid points + * + *although vertex array is a dynamic array, but to gain efficiency, + *it is better to initiliza the exact array size + */ + vertexArray vArray(gridEndIndex-gridBeginIndex+1 + + max(0,rightUpEnd - rightUpBegin+1)+ + max(0,rightDownEnd - rightDownBegin+1)); + + /*append the vertices on the up section of thr right chain*/ + for(i=rightUpBegin; i<= rightUpEnd; i++) + vArray.appendVertex(rightChain->getVertex(i)); + + /*append the vertices of the left extremal grid points, + *and at the same time, perform triangulation for the stair cases + */ + vArray.appendVertex(gridChain->get_vertex(gridBeginIndex)); + + for(k=1, i=gridBeginIndex+1; i<=gridEndIndex; i++, k++) + { + vArray.appendVertex(gridChain->get_vertex(i)); + + /*output the fan of the grid points of the (i)th and (i-1)th grid line. + */ + if(gridChain->getUlineIndex(i) < gridChain->getUlineIndex(i-1)) + { + pStream->begin(); + pStream->insert(gridChain->get_vertex(i-1)); + for(j=gridChain->getUlineIndex(i); j<= gridChain->getUlineIndex(i-1); j++) + pStream->insert(gridChain->getGrid()->get_u_value(j), gridChain->get_v_value(i)); + pStream->end(PRIMITIVE_STREAM_FAN); + } + else if(gridChain->getUlineIndex(i) > gridChain->getUlineIndex(i-1)) + { + pStream->begin(); + pStream->insert(gridChain->get_vertex(i)); + for(j=gridChain->getUlineIndex(i); j>= gridChain->getUlineIndex(i-1); j--) + pStream->insert(gridChain->getGrid()->get_u_value(j), gridChain->get_v_value(i-1)); + pStream->end(PRIMITIVE_STREAM_FAN); + } + /*otherwisem, the two are equal, so there is no fan to outout*/ + } + + /*then append all the vertices on the down section of the right chain*/ + for(i=rightDownBegin; i<= rightDownEnd; i++) + vArray.appendVertex(rightChain->getVertex(i)); + + monoTriangulationRecGen(topVert, botVert, + leftChain, leftStart, leftEnd, + &vArray, 0, vArray.getNumElements()-1, + pStream); + +} + + + + + + + + + diff --git a/src/glu/sgi/libnurbs/nurbtess/sampleComp.h b/src/glu/sgi/libnurbs/nurbtess/sampleComp.h new file mode 100644 index 0000000..a3c1790 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/sampleComp.h @@ -0,0 +1,86 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _SAMPLECOMP_H +#define _SAMPLECOMP_H + +#include "sampleMonoPoly.h" +#include "rectBlock.h" + +void sampleConnectedComp(Real* topVertex, Real* botVertex, + vertexArray* leftChain, + Int leftStartIndex, Int botLeftIndex, + vertexArray* rightChain, + Int rightStartIndex, Int botRightIndex, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridIndex1, Int gridIndex2, + Int up_leftCornerWhere, + Int up_leftCornerIndex, + Int up_rightCornerWhere, + Int up_rightCornerIndex, + Int down_leftCornerWhere, + Int down_leftCornerIndex, + Int down_rightCornerWhere, + Int down_rightCornerIndex, + primStream* pStream, + rectBlockArray* rbArray + ); + +void sampleCompLeft(Real* topVertex, Real* botVertex, + vertexArray* leftChain, + Int leftStartIndex, Int leftEndIndex, + vertexArray* rightChain, + Int rightStartIndex, Int rightEndIndex, + gridBoundaryChain* leftGridChain, + Int gridIndex1, Int gridIndex2, + Int up_leftCornerWhere, + Int up_leftCornerIndex, + Int down_leftCornerWhere, + Int down_leftCornerIndex, + primStream* pStream); + +void sampleLeftSingleTrimEdgeRegionGen(Real topVert[2], Real botVert[2], + vertexArray* leftChain, + Int leftStart, + Int leftEnd, + gridBoundaryChain* gridChain, + Int gridBegindex, + Int gridEndIndex, + vertexArray* rightChain, + Int rightUpBegin, + Int rightUpEnd, + Int rightDownBegin, + Int rightDownEnd, + primStream* pStream); + +#endif diff --git a/src/glu/sgi/libnurbs/nurbtess/sampleCompBot.cc b/src/glu/sgi/libnurbs/nurbtess/sampleCompBot.cc new file mode 100644 index 0000000..2e70f83 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/sampleCompBot.cc @@ -0,0 +1,844 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include +#include "zlassert.h" +#include "sampleCompBot.h" +#include "sampleCompRight.h" + +#define max(a,b) ((a>b)? a:b) + +//return: index_mono, index_pass +//from [pass, mono] is strictly U-monotone +//from [corner, pass] is = u +//if everybost is getVertex(i)[0] >= u) + break; + ret_index_pass = i; + if(ret_index_pass <= leftEnd) + { + for(i=ret_index_pass; i< leftEnd; i++) + { + if(leftChain->getVertex(i+1)[0] <= leftChain->getVertex(i)[0]) + break; + } + ret_index_mono = i; + } + +} + +void findBotRightSegment(vertexArray* rightChain, + Int rightEnd, + Int rightCorner, + Real u, + Int& ret_index_mono, + Int& ret_index_pass) +{ + Int i; + assert(rightCorner <= rightEnd); + for(i=rightCorner; i<= rightEnd; i++) + if(rightChain->getVertex(i)[0] <= u) + break; + + + + ret_index_pass = i; + + if(ret_index_pass <= rightEnd) + { + for(i=ret_index_pass; i< rightEnd; i++) + { + if(rightChain->getVertex(i+1)[0] >= rightChain->getVertex(i)[0]) + break; + } + ret_index_mono = i; + } +} + + +void sampleBotRightWithGridLinePost(Real* botVertex, + vertexArray* rightChain, + Int rightEnd, + Int segIndexMono, + Int segIndexPass, + Int rightCorner, + gridWrap* grid, + Int gridV, + Int leftU, + Int rightU, + primStream* pStream) +{ + //the possible section which is to the right of rightU + if(segIndexPass > rightCorner) //from corner to pass-1 is > u. + { + Real *tempBot; + if(segIndexPass <= rightEnd) //there is a point to the left of u + tempBot = rightChain->getVertex(segIndexPass); + else //nothing is to the left of u. + tempBot = botVertex; + Real tempTop[2]; + tempTop[0] = grid->get_u_value(rightU); + tempTop[1] = grid->get_v_value(gridV); + + monoTriangulation2(tempTop, tempBot, + rightChain, + rightCorner, + segIndexPass-1, + 0, // a decrease chain + pStream); + } + + //the possible section which is strictly Umonotone + if(segIndexPass <= rightEnd) //segIndex pass and mono exist + { + //if there are grid points which are to the left of botVertex + //then we should use botVertex to form a fan with these points to + //optimize the triangulation + int do_optimize = 1; + if(botVertex[0] <= grid->get_u_value(leftU)) + do_optimize = 0; + else + { + //we also have to make sure that botVertex is the left most vertex on the chain + int i; + for(i=segIndexMono; i<=rightEnd; i++) + if(rightChain->getVertex(i)[0] <= botVertex[0]) + { + do_optimize = 0; + break; + } + } + + if(do_optimize) + { + //find midU so that grid->get_u_value(midU) <= botVertex[0] + //and grid->get_u_value(midU) > botVertex[0] + int midU = leftU; + while(grid->get_u_value(midU) <= botVertex[0]) + { + midU++; + if(midU > rightU) + break; + } + midU--; + + grid->outputFanWithPoint(gridV, leftU, midU, botVertex, pStream); + stripOfFanRight(rightChain, segIndexMono, segIndexPass, grid, gridV, midU, rightU, pStream, 1); + Real tempTop[2]; + tempTop[0] = grid->get_u_value(midU); + tempTop[1] = grid->get_v_value(gridV); + monoTriangulation2(tempTop, botVertex, rightChain, segIndexMono, rightEnd, 0, pStream); + } + else //not optimize + { + stripOfFanRight(rightChain, segIndexMono, segIndexPass, grid, gridV, leftU, rightU, pStream, 1); + Real tempTop[2]; + tempTop[0] = grid->get_u_value(leftU); + tempTop[1] = grid->get_v_value(gridV); + monoTriangulation2(tempTop, botVertex, rightChain, segIndexMono, rightEnd, 0, pStream); + } + } + else //the botVertex forms a fan witht eh grid points + grid->outputFanWithPoint(gridV, leftU, rightU, botVertex, pStream); +} + +void sampleBotRightWithGridLine(Real* botVertex, + vertexArray* rightChain, + Int rightEnd, + Int rightCorner, + gridWrap* grid, + Int gridV, + Int leftU, + Int rightU, + primStream* pStream) +{ + //if right chaain is empty, then there is only one bot vertex with + //one grid line + if(rightEndoutputFanWithPoint(gridV, leftU, rightU, botVertex, pStream); + return; + } + + Int segIndexMono = 0, segIndexPass; + findBotRightSegment(rightChain, + rightEnd, + rightCorner, + grid->get_u_value(rightU), + segIndexMono, + segIndexPass); + + sampleBotRightWithGridLinePost(botVertex, + rightChain, + rightEnd, + segIndexMono, + segIndexPass, + rightCorner, + grid, + gridV, + leftU, + rightU, + pStream); +} + + +void sampleBotLeftWithGridLinePost(Real* botVertex, + vertexArray* leftChain, + Int leftEnd, + Int segIndexMono, + Int segIndexPass, + Int leftCorner, + gridWrap* grid, + Int gridV, + Int leftU, + Int rightU, + primStream* pStream) +{ + + //the possible section which is to the left of leftU + if(segIndexPass > leftCorner) //at least leftCorner is to the left of leftU + { + Real *tempBot; + if(segIndexPass <= leftEnd) //from corner to pass-1 is getVertex(segIndexPass); + else //nothing is to the rigth of u + tempBot = botVertex; + Real tempTop[2]; + tempTop[0] = grid->get_u_value(leftU); + tempTop[1] = grid->get_v_value(gridV); + monoTriangulation2(tempTop, tempBot, leftChain, leftCorner, segIndexPass-1, + 1, //a increase chain, + pStream); + } + //the possible section which is strictly Umonotone + if(segIndexPass <= leftEnd) //segIndexpass and mono exist + { + stripOfFanLeft(leftChain, segIndexMono, segIndexPass, grid, gridV, leftU, rightU, pStream, 1); + Real tempTop[2]; + tempTop[0] = grid->get_u_value(rightU); + tempTop[1] = grid->get_v_value(gridV); + + monoTriangulation2(tempTop, botVertex, leftChain, segIndexMono, leftEnd, + 1, //increase chain + pStream); + } + else //the botVertex forms a fan with the grid points + { + grid->outputFanWithPoint(gridV, leftU, rightU, botVertex, pStream); + } + +} + +void sampleBotLeftWithGridLine(Real* botVertex, + vertexArray* leftChain, + Int leftEnd, + Int leftCorner, + gridWrap* grid, + Int gridV, + Int leftU, + Int rightU, + primStream* pStream) +{ + + //if leftChain is empty, then there is only one botVertex with one grid line + if(leftEnd< leftCorner){ + grid->outputFanWithPoint(gridV, leftU, rightU, botVertex, pStream); + return; + } + + Int segIndexPass, segIndexMono = 0; + findBotLeftSegment(leftChain, leftEnd, leftCorner, grid->get_u_value(leftU), segIndexMono, segIndexPass); + + sampleBotLeftWithGridLinePost(botVertex, + leftChain, + leftEnd, + segIndexMono, + segIndexPass, + leftCorner, + grid, + gridV, + leftU, rightU, pStream); +} + +//return 1 if separator exists, 0 otherwise +Int findBotSeparator(vertexArray* leftChain, + Int leftEnd, + Int leftCorner, + vertexArray* rightChain, + Int rightEnd, + Int rightCorner, + Int& ret_sep_left, + Int& ret_sep_right) +{ + Int oldLeftI, oldRightI, newLeftI, newRightI; + Int i,j,k; + Real leftMax /*= leftChain->getVertex(leftCorner)[0]*/; + Real rightMin /*= rightChain->getVertex(rightCorner)[0]*/; + if(leftChain->getVertex(leftCorner)[1] < rightChain->getVertex(rightCorner)[1])//leftlower + { + oldLeftI = leftCorner-1; + oldRightI = rightCorner; + leftMax = leftChain->getVertex(leftCorner)[0] - Real(1.0) ; //initilize to be left of leftCorner + rightMin = rightChain->getVertex(rightCorner)[0]; + } + else //rightlower + { + oldLeftI = leftCorner; + oldRightI = rightCorner-1; + leftMax = leftChain->getVertex(leftCorner)[0]; + rightMin = rightChain->getVertex(rightCorner)[0] + Real(1.0); + } + + //i: the current working leftChain Index + //j: the curent working right chian index + //if(left(i) is lower than right(j), then the two chains above right(j) are separated. + //else the two chains below left(i) are separated. + i = leftCorner; + j = rightCorner; + while(1) + { + newLeftI = oldLeftI; + newRightI = oldRightI; + if(i> leftEnd) //left chain is doen , go through remaining right chain + { + for(k=j+1; k<= rightEnd; k++) + { + if(rightChain->getVertex(k)[0] > leftMax) //no conflict + { + //update oldRightI if necessary + if(rightChain->getVertex(k)[0] < rightMin) + { + rightMin = rightChain->getVertex(k)[0]; + oldRightI = k; + } + } + else //there is a conflict + break; //the for-loop, above right(k+1) is separated: oldLeftI, oldRightI + } + break; //the while loop + } + else if(j > rightEnd) //right Chain is doen + { + for(k=i+1; k<= leftEnd; k++) + { + if(leftChain->getVertex(k)[0] < rightMin) //no conflict + { + //update oldLeftI if necessary + if(leftChain->getVertex(k)[0] > leftMax) + { + leftMax = leftChain->getVertex(k)[0]; + oldLeftI = k; + } + } + else //there is a conflict + break; //the for-loop, above left(k+1) is separated: oldLeftI, oldRightI + } + break; //the while loop + } + else if(leftChain->getVertex(i)[1] < rightChain->getVertex(j)[1]) //left lower + { + + if(leftChain->getVertex(i)[0] > leftMax) //update leftMax amd newLeftI + { + leftMax = leftChain->getVertex(i)[0]; + newLeftI = i; + } + for(k=j+1; k<= rightEnd; k++) //update rightMin and newRightI; + { + if(rightChain->getVertex(k)[1] < leftChain->getVertex(i)[1]) //right gets lower + break; + if(rightChain->getVertex(k)[0] < rightMin) + { + rightMin = rightChain->getVertex(k)[0]; + newRightI = k; + } + } + j = k; //next working j, since j will he lower than i in next loop + if(leftMax >= rightMin) //there is a conflict + break; + else //still no conflict + { + oldLeftI = newLeftI; + oldRightI = newRightI; + + } + } + else //right lower + { + if(rightChain->getVertex(j)[0] < rightMin) + { + rightMin = rightChain->getVertex(j)[0]; + newRightI = j; + } + for(k=i+1; k<= leftEnd; k++) + { + if(leftChain->getVertex(k)[1] < rightChain->getVertex(j)[1]) + break; + if(leftChain->getVertex(k)[0] > leftMax) + { + leftMax = leftChain->getVertex(k)[0]; + newLeftI = k; + } + } + i=k; //nexct working i, since i will be lower than j next loop + if(leftMax >= rightMin) //there is conflict + break; + else //still no conflict + { + oldLeftI = newLeftI; + oldRightI = newRightI; + } + } + }//end of while loop + //now oldLeftI and oldRight I are the desired separator index notice that they are not + //necessarily valid + if(oldLeftI < leftCorner || oldRightI < rightCorner) + return 0; //no separator + else + { + ret_sep_left = oldLeftI; + ret_sep_right = oldRightI; + return 1; + } +} + +void sampleCompBot(Real* botVertex, + vertexArray* leftChain, + Int leftEnd, + vertexArray* rightChain, + Int rightEnd, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridIndex, + Int down_leftCornerWhere, + Int down_leftCornerIndex, + Int down_rightCornerWhere, + Int down_rightCornerIndex, + primStream* pStream) +{ + + if(down_leftCornerWhere == 1 && down_rightCornerWhere == 1) //the bot is botVertex with possible grid points + { + + leftGridChain->getGrid()->outputFanWithPoint(leftGridChain->getVlineIndex(gridIndex), + leftGridChain->getUlineIndex(gridIndex), + rightGridChain->getUlineIndex(gridIndex), + botVertex, + pStream); + return; + } + else if(down_leftCornerWhere != 0) + { + + Real* tempBot; + Int tempRightEnd; + if(down_leftCornerWhere == 1){ + tempRightEnd = rightEnd; + tempBot = botVertex; + } + else + { + tempRightEnd = down_leftCornerIndex-1; + tempBot = rightChain->getVertex(down_leftCornerIndex); + } + + sampleBotRightWithGridLine(tempBot, + rightChain, + tempRightEnd, + down_rightCornerIndex, + rightGridChain->getGrid(), + leftGridChain->getVlineIndex(gridIndex), + leftGridChain->getUlineIndex(gridIndex), + rightGridChain->getUlineIndex(gridIndex), + pStream); + } + else if(down_rightCornerWhere != 2) + { + + Real* tempBot; + Int tempLeftEnd; + if(down_rightCornerWhere == 1){ + tempLeftEnd = leftEnd; + tempBot = botVertex; + } + else //right corner is on left chain + { + tempLeftEnd = down_rightCornerIndex-1; + tempBot = leftChain->getVertex(down_rightCornerIndex); + } + + + sampleBotLeftWithGridLine(tempBot, leftChain, tempLeftEnd, down_leftCornerIndex, + leftGridChain->getGrid(), + leftGridChain->getVlineIndex(gridIndex), + leftGridChain->getUlineIndex(gridIndex), + rightGridChain->getUlineIndex(gridIndex), + pStream); + + } + else //down_leftCornereWhere == 0, down_rightCornerwhere == 2 + { + sampleCompBotSimple(botVertex, + leftChain, + leftEnd, + rightChain, + rightEnd, + leftGridChain, + rightGridChain, + gridIndex, + down_leftCornerWhere, + down_leftCornerIndex, + down_rightCornerWhere, + down_rightCornerIndex, + pStream); + + return; + +#ifdef NOT_REACHABLE + //the following code is trying to do some optimization, but not quite working. so it is not reachable, but leave it here for reference + Int sep_left, sep_right; + if(findBotSeparator(leftChain, leftEnd, down_leftCornerIndex, + rightChain, rightEnd, down_rightCornerIndex, + sep_left, sep_right) + )//separator exiosts + { + + if(leftChain->getVertex(sep_left)[0] >= leftGridChain->get_u_value(gridIndex) && + rightChain->getVertex(sep_right)[0] <= rightGridChain->get_u_value(gridIndex)) + { + Int gridSep; + Int segLeftMono, segLeftPass, segRightMono, segRightPass; + findBotLeftSegment(leftChain, + sep_left, + down_leftCornerIndex, + leftGridChain->get_u_value(gridIndex), + segLeftMono, + segLeftPass); + findBotRightSegment(rightChain, + sep_right, + down_rightCornerIndex, + rightGridChain->get_u_value(gridIndex), + segRightMono, + segRightPass); + if(leftChain->getVertex(segLeftMono)[1] <= rightChain->getVertex(segRightMono)[1]) + { + gridSep = rightGridChain->getUlineIndex(gridIndex); + while(leftGridChain->getGrid()->get_u_value(gridSep) > leftChain->getVertex(segLeftMono)[0]) + gridSep--; + } + else + { + gridSep = leftGridChain->getUlineIndex(gridIndex); + while(leftGridChain->getGrid()->get_u_value(gridSep) < rightChain->getVertex(segRightMono)[0]) + gridSep++; + } + + sampleBotLeftWithGridLinePost(leftChain->getVertex(segLeftMono), + leftChain, + segLeftMono-1, + segLeftMono-1, + segLeftPass, + down_leftCornerIndex, + leftGridChain->getGrid(), + leftGridChain->getVlineIndex(gridIndex), + leftGridChain->getUlineIndex(gridIndex), + gridSep, + pStream); + sampleBotRightWithGridLinePost(rightChain->getVertex(segRightMono), + rightChain, + segRightMono-1, + segRightMono-1, + segRightPass, + down_rightCornerIndex, + rightGridChain->getGrid(), + rightGridChain->getVlineIndex(gridIndex), + gridSep, + rightGridChain->getUlineIndex(gridIndex), + pStream); + Real tempTop[2]; + tempTop[0] = leftGridChain->getGrid()->get_u_value(gridSep); + tempTop[1] = leftGridChain->get_v_value(gridIndex); + monoTriangulationRecGen(tempTop, botVertex, + leftChain, segLeftMono, leftEnd, + rightChain, segRightMono, rightEnd, + pStream); + }//end if both sides have vertices inside the gridboundary points + else if(leftChain->getVertex(sep_left)[0] >= leftGridChain->get_u_value(gridIndex)) //left n right out + + { + Int segLeftMono, segLeftPass; + findBotLeftSegment(leftChain, + sep_left, + down_leftCornerIndex, + leftGridChain->get_u_value(gridIndex), + segLeftMono, + segLeftPass); + assert(segLeftPass <= sep_left); //make sure there is a point to the right of u. + monoTriangulation2(leftGridChain->get_vertex(gridIndex), + leftChain->getVertex(segLeftPass), + leftChain, + down_leftCornerIndex, + segLeftPass-1, + 1, //a increase chain + pStream); + stripOfFanLeft(leftChain, segLeftMono, segLeftPass, + leftGridChain->getGrid(), + leftGridChain->getVlineIndex(gridIndex), + leftGridChain->getUlineIndex(gridIndex), + rightGridChain->getUlineIndex(gridIndex), + pStream,1 ); +/* + sampleBotLeftWithGridLinePost(leftChain->getVertex(segLeftMono), + leftChain, + segLeftMono-1, + segLeftMono-1, + segLeftPass, + down_leftCornerIndex, + leftGridChain->getGrid(), + leftGridChain->getVlineIndex(gridIndex), + leftGridChain->getUlineIndex(gridIndex), + rightGridChain->getUlineIndex(gridIndex), + pStream); +*/ + + monoTriangulationRecGen(rightGridChain->get_vertex(gridIndex), + botVertex, + leftChain, segLeftMono, leftEnd, + rightChain, down_rightCornerIndex, rightEnd, + pStream); + }//end left in right out + else if(rightChain->getVertex(sep_right)[0] <= rightGridChain->get_u_value(gridIndex))//left out right in + { + Int segRightMono, segRightPass; + findBotRightSegment(rightChain, sep_right, down_rightCornerIndex, + rightGridChain->get_u_value(gridIndex), + segRightMono, + segRightPass); + + assert(segRightPass <= sep_right); //make sure there is a point to the left of u. + monoTriangulation2(rightGridChain->get_vertex(gridIndex), + rightChain->getVertex(segRightPass), + rightChain, + down_rightCornerIndex, + segRightPass-1, + 0, // a decrease chain + pStream); + + stripOfFanRight(rightChain, segRightMono, segRightPass, + rightGridChain->getGrid(), + rightGridChain->getVlineIndex(gridIndex), + leftGridChain->getUlineIndex(gridIndex), + rightGridChain->getUlineIndex(gridIndex), + pStream, 1); + + + monoTriangulationRecGen(leftGridChain->get_vertex(gridIndex), + botVertex, + leftChain, down_leftCornerIndex, leftEnd, + rightChain, segRightMono, rightEnd, + pStream); + + }//end left out right in + else //left out, right out + { + sampleCompBotSimple(botVertex, + leftChain, + leftEnd, + rightChain, + rightEnd, + leftGridChain, + rightGridChain, + gridIndex, + down_leftCornerWhere, + down_leftCornerIndex, + down_rightCornerWhere, + down_rightCornerIndex, + pStream); + + }//end leftout right out + }//end if separator exists + else //no separator + { + + sampleCompBotSimple(botVertex, + leftChain, + leftEnd, + rightChain, + rightEnd, + leftGridChain, + rightGridChain, + gridIndex, + down_leftCornerWhere, + down_leftCornerIndex, + down_rightCornerWhere, + down_rightCornerIndex, + pStream); + } +#endif + }//end id 0 2 +}//end if the functin + + +void sampleCompBotSimple(Real* botVertex, + vertexArray* leftChain, + Int leftEnd, + vertexArray* rightChain, + Int rightEnd, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridIndex, + Int down_leftCornerWhere, + Int down_leftCornerIndex, + Int down_rightCornerWhere, + Int down_rightCornerIndex, + primStream* pStream) +{ + //the plan is to use monotriangulation algorithm. + Int i,k; + Real* ActualTop; + Real* ActualBot; + Int ActualLeftStart, ActualLeftEnd; + Int ActualRightStart, ActualRightEnd; + + //creat an array to store the points on the grid line + gridWrap* grid = leftGridChain->getGrid(); + Int gridV = leftGridChain->getVlineIndex(gridIndex); + Int gridLeftU = leftGridChain->getUlineIndex(gridIndex); + Int gridRightU = rightGridChain->getUlineIndex(gridIndex); + Real2* gridPoints = (Real2*) malloc(sizeof(Real2) * (gridRightU - gridLeftU +1)); + assert(gridPoints); + + for(k=0, i=gridRightU; i>= gridLeftU; i--, k++) + { + gridPoints[k][0] = grid->get_u_value(i); + gridPoints[k][1] = grid->get_v_value(gridV); + } + + if(down_rightCornerWhere != 0) //rightCorner is not on lef + ActualLeftEnd = leftEnd; + else + ActualLeftEnd = down_rightCornerIndex-1; //down_rightCornerIndex will be th actualBot + + if(down_leftCornerWhere != 0) //left corner is not on let chian + ActualLeftStart = leftEnd+1; //meaning that there is no actual left section + else + ActualLeftStart = down_leftCornerIndex; + + vertexArray ActualLeftChain(max(0, ActualLeftEnd - ActualLeftStart +1) + gridRightU - gridLeftU +1); + + for(i=0; igetVertex(i)); + + //determine ActualRightStart + if(down_rightCornerWhere != 2) //right is not on right + ActualRightStart = rightEnd +1; //meaning no section on right + else + ActualRightStart = down_rightCornerIndex; + + //determine actualrightEnd + if(down_leftCornerWhere != 2) //left is not on right + { + + ActualRightEnd = rightEnd; + } + else //left corner is on right + { + ActualRightEnd = down_leftCornerIndex-1; //down_leftCornerIndex will be the bot + + } + + //actual bot + if(down_rightCornerWhere == 2) + { + if(down_leftCornerWhere == 2) + ActualBot = rightChain->getVertex(down_leftCornerIndex); + else + ActualBot = botVertex; + } + else if(down_rightCornerWhere == 1) //right corner bot + ActualBot = botVertex; + else //down_rightCornerWhere == 0 + ActualBot = leftChain->getVertex(down_rightCornerIndex); + + ActualTop = gridPoints[0]; +/* +printf("in bot simple, actual leftChain is \n"); +ActualLeftChain.print(); +printf("Actual Top = %f,%f\n", ActualTop[0],ActualTop[1]); +printf("Actual Bot = %f,%f\n", ActualBot[0],ActualBot[1]); +printf("Actual right start = %i, end=%i\n",ActualRightStart, ActualRightEnd); +*/ + if(rightChain->getVertex(ActualRightStart)[1] == ActualTop[1]) + monoTriangulationRecGenOpt(rightChain->getVertex(ActualRightStart), + ActualBot, + &ActualLeftChain, + 0, + ActualLeftChain.getNumElements()-1, + rightChain, + ActualRightStart+1, + ActualRightEnd, + pStream); + else + monoTriangulationRecGenOpt(ActualTop, ActualBot, + &ActualLeftChain, + 1, //the first one is the top vertex + ActualLeftChain.getNumElements()-1, + rightChain, + ActualRightStart, + ActualRightEnd, + pStream); + free(gridPoints); +} + + + + diff --git a/src/glu/sgi/libnurbs/nurbtess/sampleCompBot.h b/src/glu/sgi/libnurbs/nurbtess/sampleCompBot.h new file mode 100644 index 0000000..7b98279 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/sampleCompBot.h @@ -0,0 +1,138 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _SAMPLECOMPBOT_H +#define _SAMPLECOMPBOT_H + +#include "sampleMonoPoly.h" + +void findBotLeftSegment(vertexArray* leftChain, + Int leftEnd, + Int leftCorner, + Real u, + Int& ret_index_mono, + Int& ret_index_pass); + +void findBotRightSegment(vertexArray* rightChain, + Int rightEnd, + Int rightCorner, + Real u, + Int& ret_index_mono, + Int& ret_index_pass); + + +void sampleBotRightWithGridLinePost(Real* botVertex, + vertexArray* rightChain, + Int rightEnd, + Int segIndexMono, + Int segIndexPass, + Int rightCorner, + gridWrap* grid, + Int gridV, + Int leftU, + Int rightU, + primStream* pStream); + + +void sampleBotRightWithGridLine(Real* botVertex, + vertexArray* rightChain, + Int rightEnd, + Int rightCorner, + gridWrap* grid, + Int gridV, + Int leftU, + Int rightU, + primStream* pStream); + + +void sampleBotLeftWithGridLinePost(Real* botVertex, + vertexArray* leftChain, + Int leftEnd, + Int segIndexMono, + Int segIndexPass, + Int leftCorner, + gridWrap* grid, + Int gridV, + Int leftU, + Int rightU, + primStream* pStream); + + +void sampleBotLeftWithGridLine(Real* botVertex, + vertexArray* leftChain, + Int leftEnd, + Int leftCorner, + gridWrap* grid, + Int gridV, + Int leftU, + Int rightU, + primStream* pStream); + + +Int findBotSeparator(vertexArray* leftChain, + Int leftEnd, + Int leftCorner, + vertexArray* rightChain, + Int rightEnd, + Int rightCorner, + Int& ret_sep_left, + Int& ret_sep_right); + +void sampleCompBot(Real* botVertex, + vertexArray* leftChain, + Int leftEnd, + vertexArray* rightChain, + Int rightEnd, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridIndex, + Int down_leftCornerWhere, + Int down_leftCornerIndex, + Int down_rightCornerWhere, + Int down_rightCornerIndex, + primStream* pStream); + +void sampleCompBotSimple(Real* botVertex, + vertexArray* leftChain, + Int leftEnd, + vertexArray* rightChain, + Int rightEnd, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridIndex, + Int down_leftCornerWhere, + Int down_leftCornerIndex, + Int down_rightCornerWhere, + Int down_rightCornerIndex, + primStream* pStream); + +#endif diff --git a/src/glu/sgi/libnurbs/nurbtess/sampleCompRight.cc b/src/glu/sgi/libnurbs/nurbtess/sampleCompRight.cc new file mode 100644 index 0000000..d01e500 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/sampleCompRight.cc @@ -0,0 +1,644 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include +#include "gluos.h" +#include "glimports.h" +#include "zlassert.h" +#include "sampleCompRight.h" + +#define max(a,b) ((a>b)? a:b) +#define min(a,b) ((a>b)? b:a) + + + +#ifdef NOT_TAKEOUT + +/*notice that we need leftChain because the + *corners could be on the leftChain. + */ +void sampleCompRight(Real* topVertex, Real* botVertex, + vertexArray* leftChain, + Int leftStartIndex, Int leftEndIndex, + vertexArray* rightChain, + Int rightStartIndex, Int rightEndIndex, + gridBoundaryChain* rightGridChain, + Int gridIndex1, Int gridIndex2, + Int up_rightCornerWhere, + Int up_rightCornerIndex, + Int down_rightCornerWhere, + Int down_rightCornerIndex, + primStream* pStream) +{ + /*find out whether there is a trim vertex which is + *inbetween the top and bot grid lines or not. + */ + Int midIndex1; + Int midIndex2; + Int gridMidIndex1 = 0, gridMidIndex2 = 0; + //midIndex1: array[i] <= v, array[i+1] > v + //midIndex2: array[i] >= v, array[i+1] < v + midIndex1 = rightChain->findIndexBelowGen(rightGridChain->get_v_value(gridIndex1), + rightStartIndex, + rightEndIndex); + midIndex2 = -1; //initilization + if(midIndex1 <= rightEndIndex && gridIndex1 < gridIndex2) + if(rightChain->getVertex(midIndex1)[1] >= rightGridChain->get_v_value(gridIndex2)) + { + //midIndex2 must exist: + midIndex2 = rightChain->findIndexAboveGen(rightGridChain->get_v_value(gridIndex2), + midIndex1, //midIndex1<=midIndex2 + rightEndIndex); + //find gridMidIndex1 so that either it=gridIndex1 when the gridline is + // at the same height as trim vertex midIndex1, or it is the last one + //which is strictly above midIndex1. + { + Real temp = rightChain->getVertex(midIndex1)[1]; + if(rightGridChain->get_v_value(gridIndex1) == temp) + gridMidIndex1 = gridIndex1; + else + { + gridMidIndex1 = gridIndex1; + while(rightGridChain->get_v_value(gridMidIndex1) > temp) + gridMidIndex1++; + gridMidIndex1--; + } + }//end of find gridMindIndex1 + //find gridMidIndex2 so that it is the (first one below or equal + //midIndex) last one above or equal midIndex2 + { + Real temp = rightChain->getVertex(midIndex2)[1]; + for(gridMidIndex2 = gridMidIndex1+1; gridMidIndex2 <= gridIndex2; gridMidIndex2++) + if(rightGridChain->get_v_value(gridMidIndex2) <= temp) + break; + + assert(gridMidIndex2 <= gridIndex2); + }//end of find gridMidIndex2 + } + + + + //to interprete the corner information + Real* cornerTop; + Real* cornerBot; + Int cornerRightStart; + Int cornerRightEnd; + Int cornerLeftUpEnd; + Int cornerLeftDownStart; + if(up_rightCornerWhere == 2) //right corner is on right chain + { + cornerTop = rightChain->getVertex(up_rightCornerIndex); + cornerRightStart = up_rightCornerIndex+1; + cornerLeftUpEnd = -1; //no left + } + else if(up_rightCornerWhere == 1) //right corner is on top + { + cornerTop = topVertex; + cornerRightStart = rightStartIndex; + cornerLeftUpEnd = -1; //no left + } + else //right corner is on left chain + { + cornerTop = topVertex; + cornerRightStart = rightStartIndex; + cornerLeftUpEnd = up_rightCornerIndex; + } + + if(down_rightCornerWhere == 2) //right corner is on right chan + { + cornerBot = rightChain->getVertex(down_rightCornerIndex); + cornerRightEnd = down_rightCornerIndex-1; + cornerLeftDownStart = leftEndIndex+1; //no left + } + else if (down_rightCornerWhere == 1) //right corner is at bot + { + cornerBot = botVertex; + cornerRightEnd = rightEndIndex; + cornerLeftDownStart = leftEndIndex+1; //no left + } + else //right corner is on the left chain + { + cornerBot = botVertex; + cornerRightEnd = rightEndIndex; + cornerLeftDownStart = down_rightCornerIndex; + } + + //sample + if(midIndex2 >= 0) //there is a trm point between grid lines + { + + sampleRightSingleTrimEdgeRegionGen(cornerTop, rightChain->getVertex(midIndex1), + rightChain, + cornerRightStart, + midIndex1-1, + rightGridChain, + gridIndex1, + gridMidIndex1, + leftChain, + leftStartIndex, + cornerLeftUpEnd, + 0, //no left down section, + -1, + pStream); + + sampleRightSingleTrimEdgeRegionGen(rightChain->getVertex(midIndex2), + cornerBot, + rightChain, + midIndex2+1, + cornerRightEnd, + rightGridChain, + gridMidIndex2, + gridIndex2, + leftChain, + 0, //no left up section + -1, + cornerLeftDownStart, + leftEndIndex, + pStream); + + sampleRightStripRecF(rightChain, + midIndex1, + midIndex2, + rightGridChain, + gridMidIndex1, + gridMidIndex2, + pStream); + + } + else + { + sampleRightSingleTrimEdgeRegionGen(cornerTop, cornerBot, + rightChain, + cornerRightStart, + cornerRightEnd, + rightGridChain, + gridIndex1, + gridIndex2, + leftChain, + leftStartIndex, + cornerLeftUpEnd, + cornerLeftDownStart, + leftEndIndex, + pStream); + } +} + +void sampleRightSingleTrimEdgeRegionGen(Real topVertex[2], Real botVertex[2], + vertexArray* rightChain, + Int rightStart, + Int rightEnd, + gridBoundaryChain* gridChain, + Int gridBeginIndex, + Int gridEndIndex, + vertexArray* leftChain, + Int leftUpBegin, + Int leftUpEnd, + Int leftDownBegin, + Int leftDownEnd, + primStream* pStream) +{ + Int i,k; + /*creat an array to store all the up and down secments of the left chain, + *and the right end grid points + * + *although vertex array is a dynamic array, but to gain efficiency, + *it is better to initiliza the exact array size + */ + vertexArray vArray(gridEndIndex-gridBeginIndex+1 + + max(0,leftUpEnd - leftUpBegin+1)+ + max(0,leftDownEnd - leftDownBegin+1)); + //append the vertices on the up section of the left chain + for(i=leftUpBegin; i<= leftUpEnd; i++) + vArray.appendVertex(leftChain->getVertex(i)); + + //append the vertices of the right extremal grid points, + //and at the same time, perform triangulation for the stair cases + vArray.appendVertex(gridChain->get_vertex(gridBeginIndex)); + + for(k=1, i=gridBeginIndex+1; i<= gridEndIndex; i++, k++) + { + vArray.appendVertex(gridChain->get_vertex(i)); + + //output the fan of the grid points of the (i)th and (i-1)th grid line. + gridChain->rightEndFan(i, pStream); + } + + //append all the vertices on the down section of the left chain + for(i=leftDownBegin; i<= leftDownEnd; i++) + vArray.appendVertex(leftChain->getVertex(i)); + monoTriangulationRecGen(topVertex, botVertex, + &vArray, 0, vArray.getNumElements()-1, + rightChain, rightStart, rightEnd, + pStream); +} + +void sampleRightSingleTrimEdgeRegion(Real upperVert[2], Real lowerVert[2], + gridBoundaryChain* gridChain, + Int beginIndex, + Int endIndex, + primStream* pStream) +{ + Int i,k; + vertexArray vArray(endIndex-beginIndex+1); + vArray.appendVertex(gridChain->get_vertex(beginIndex)); + for(k=1, i=beginIndex+1; i<= endIndex; i++, k++) + { + vArray.appendVertex(gridChain->get_vertex(i)); + //output the fan of the grid points of the (i)_th and i-1th gridLine + gridChain->rightEndFan(i, pStream); + } + monoTriangulation2(upperVert, lowerVert, &vArray, 0, endIndex-beginIndex, + 1, //increase chain (to the left) + pStream); +} + + +/*the gridlines from rightGridChainStartIndex to + *rightGridChainEndIndex are assumed to form a + *connected componenet + *the trm vertex of topRightIndex is assumed to be below + *or equal the first gridLine, and the trm vertex of + *botRightIndex is assumed to be above or equal the last gridline + **there could be multipe trm vertices equal to the last gridline, but + **only one could be equal to top gridline. shape: ____| (recall that + **for left chain recF, we allow shape: |---- + *if botRightIndex= topRightIndex, there is at least one triangles to + *output + */ +void sampleRightStripRecF(vertexArray* rightChain, + Int topRightIndex, + Int botRightIndex, + gridBoundaryChain* rightGridChain, + Int rightGridChainStartIndex, + Int rightGridChainEndIndex, + primStream* pStream + ) +{ + + //sstop conditionL: if topRightIndex > botRightIndex, then stop + if(topRightIndex > botRightIndex) + return; + + //if there is only one grid line, return + if(rightGridChainStartIndex >= rightGridChainEndIndex) + return; + + + assert(rightChain->getVertex(topRightIndex)[1] <= rightGridChain->get_v_value(rightGridChainStartIndex) && + rightChain->getVertex(botRightIndex)[1] >= rightGridChain->get_v_value(rightGridChainEndIndex)); + + //firstfind the first trim vertex which is strictly below the second top + //grid line: index1. + Real secondGridChainV = rightGridChain->get_v_value(rightGridChainStartIndex+1); + Int index1 = topRightIndex; + while(rightChain->getVertex(index1)[1] >= secondGridChainV){ + index1++; + if(index1 > botRightIndex) + break; + } + //now rightChain->getVertex(index1-1)[1] >= secondGridChainV and + //rightChain->getVertex(index1)[1] < secondGridChainV and + //we should include index1-1 to perform a gridStep + index1--; + + //now we have rightChain->getVertex(index1)[1] >= secondGridChainV, and + //rightChain->getVertex(index1+1)[1] < secondGridChainV + sampleRightOneGridStep(rightChain, topRightIndex, index1, rightGridChain, rightGridChainStartIndex, pStream); + + //if rightChain->getVertex(index1)[1] ==secondGridChainV then we can + //recurvesively to the rest + if(rightChain->getVertex(index1)[1] == secondGridChainV) + { + + + sampleRightStripRecF(rightChain, index1, botRightIndex, rightGridChain, rightGridChainStartIndex+1, rightGridChainEndIndex, pStream); + } + else if(index1 < botRightIndex) + { + //otherwise, we have rightChain->getVertex(index1)[1] > secondV + //let the next trim vertex be nextTrimVertex, (which should be strictly + //below the second grid line). Find the last grid line index2 which is STRICTLY ABOVE + //nextTrimVertex. + //sample one trm edge region. + Real *uppervert, *lowervert; + uppervert = rightChain->getVertex(index1); + lowervert = rightChain->getVertex(index1+1); //okay since index1get_v_value(index2) > lowervert[1]) + { + index2++; + if(index2 > rightGridChainEndIndex) + break; + } + index2--; + + sampleRightSingleTrimEdgeRegion(uppervert, lowervert, rightGridChain, rightGridChainStartIndex+1, index2, pStream); + + //recursion + sampleRightStripRecF(rightChain, index1+1, botRightIndex, rightGridChain, index2, rightGridChainEndIndex, pStream); + } +} + +//the degenerate case of sampleRightOneGridStep +void sampleRightOneGridStepNoMiddle(vertexArray* rightChain, + Int beginRightIndex, + Int endRightIndex, + gridBoundaryChain* rightGridChain, + Int rightGridChainStartIndex, + primStream* pStream) +{ + /*since there is no middle, there is at most one point which is on the + *second grid line, there could be multiple points on the first (top) + *grid line. + */ + rightGridChain->rightEndFan(rightGridChainStartIndex+1, pStream); + monoTriangulation2(rightGridChain->get_vertex(rightGridChainStartIndex), + rightGridChain->get_vertex(rightGridChainStartIndex+1), + rightChain, + beginRightIndex, + endRightIndex, + 0, //decrease chain + pStream); +} + +//sampling the right area in between two grid lines +//shape: _________| +void sampleRightOneGridStep(vertexArray* rightChain, + Int beginRightIndex, + Int endRightIndex, + gridBoundaryChain* rightGridChain, + Int rightGridChainStartIndex, + primStream* pStream) +{ + if(checkMiddle(rightChain, beginRightIndex, endRightIndex, + rightGridChain->get_v_value(rightGridChainStartIndex), + rightGridChain->get_v_value(rightGridChainStartIndex+1))<0) + { + sampleRightOneGridStepNoMiddle(rightChain, beginRightIndex, endRightIndex, rightGridChain, rightGridChainStartIndex, pStream); + return; + } + + //copy into a polygn + { + directedLine* poly = NULL; + sampledLine* sline; + directedLine* dline; + gridWrap* grid = rightGridChain->getGrid(); + float vert1[2]; + float vert2[2]; + Int i; + + Int innerInd = rightGridChain->getInnerIndex(rightGridChainStartIndex+1); + Int upperInd = rightGridChain->getUlineIndex(rightGridChainStartIndex); + Int lowerInd = rightGridChain->getUlineIndex(rightGridChainStartIndex+1); + Real upperV = rightGridChain->get_v_value(rightGridChainStartIndex); + Real lowerV = rightGridChain->get_v_value(rightGridChainStartIndex+1); + + //the upper gridline + vert1[1]=vert2[1]=upperV; + for(i=upperInd; + i>innerInd; + i--) + { + vert1[0]=grid->get_u_value(i); + vert2[0]=grid->get_u_value(i-1); + sline = new sampledLine(vert1, vert2); + dline = new directedLine(INCREASING, sline); + if(poly == NULL) + poly = dline; + else + poly->insert(dline); + } + + //the vertical grid line segment + vert1[0]=vert2[0] = grid->get_u_value(innerInd); + vert1[1]=upperV; + vert2[1]=lowerV; + sline=new sampledLine(vert1, vert2); + dline=new directedLine(INCREASING, sline); + if(poly == NULL) + poly = dline; + else + poly->insert(dline); + + //the lower grid line + vert1[1]=vert2[1]=lowerV; + for(i=innerInd; iget_u_value(i); + vert2[0] = grid->get_u_value(i+1); + sline = new sampledLine(vert1, vert2); + dline = new directedLine(INCREASING, sline); + poly->insert(dline); + } + + //the edge connecting lower grid to right chain + vert1[0]=grid->get_u_value(lowerInd); + sline = new sampledLine(vert1, rightChain->getVertex(endRightIndex)); + dline = new directedLine(INCREASING, sline); + poly->insert(dline); + + + //the right Chain + for(i=endRightIndex; i>beginRightIndex; i--) + { + sline = new sampledLine(rightChain->getVertex(i), rightChain->getVertex(i-1)); + dline = new directedLine(INCREASING, sline); + poly->insert(dline); + } + + //the edge connecting right chain with upper grid + vert2[1]=upperV; + vert2[0]=grid->get_u_value(upperInd); + sline = new sampledLine(rightChain->getVertex(beginRightIndex), vert2); + dline = new directedLine(INCREASING, sline); + poly->insert(dline); + monoTriangulationOpt(poly, pStream); + //clean up + poly->deleteSinglePolygonWithSline(); + + return; + } + + //this following code cannot be reached, but leave it for debuggig purpose. + Int i; + //find the maximal U-monotone chain of beginRightIndex, beginRightIndex+1,... + i=beginRightIndex; + Real prevU = rightChain->getVertex(i)[0]; + for(i=beginRightIndex+1; i<= endRightIndex; i++){ + Real thisU = rightChain->getVertex(i)[0]; + if(thisU < prevU) + prevU = thisU; + else + break; + } + //from beginRightIndex to i-1 is strictly U-monotne + //if(i-1==beginRightIndex and the vertex of rightchain is on the first + //gridline, then we should use 2 vertices on the right chain. Of we only + //use one (begin), we would output degenrate triangles. + if(i-1 == beginRightIndex && rightChain->getVertex(beginRightIndex)[1] == rightGridChain->get_v_value(rightGridChainStartIndex)) + i++; + + Int j = endRightIndex -1; + if(rightGridChain->getInnerIndex(rightGridChainStartIndex+1) < rightGridChain->getUlineIndex(rightGridChainStartIndex+1)) + { + j = rightChain->findDecreaseChainFromEnd(i-1/*beginRightIndex*/, endRightIndex); + Int temp = endRightIndex; + //now from j+1 to end is strictly U-monotone. + //if j+1 is on the last grid line, then we wat to skip to the vertex + //whcih is strictly above the second grid line. This vertex must exist + //since there is a middle vertex + if(j+1 == endRightIndex) + { + while(rightChain->getVertex(j+1)[1] == rightGridChain->get_v_value(rightGridChainStartIndex+1)) + j--; + + monoTriangulation2(rightChain->getVertex(j+1), + rightGridChain->get_vertex(rightGridChainStartIndex+1), + rightChain, + j+2, + endRightIndex, + 0, //a decrease chain + pStream); + + temp = j+1; + } + + stripOfFanRight(rightChain, temp, j+1, rightGridChain->getGrid(), + rightGridChain->getVlineIndex(rightGridChainStartIndex+1), + rightGridChain->getInnerIndex(rightGridChainStartIndex+1), + rightGridChain->getUlineIndex(rightGridChainStartIndex+1), + pStream, + 0 //the grid line is below the trim line + ); + + } + + + stripOfFanRight(rightChain, i-1, beginRightIndex, rightGridChain->getGrid(), + rightGridChain->getVlineIndex(rightGridChainStartIndex), + rightGridChain->getInnerIndex(rightGridChainStartIndex+1), + rightGridChain->getUlineIndex(rightGridChainStartIndex), + pStream, + 1 //the grid line is above the trm lines + ); + + //monotone triangulate the remaining rightchain together with the + //two vertices on the two grid v-lines + Real vert[2][2]; + vert[0][0] = vert[1][0] = rightGridChain->getInner_u_value(rightGridChainStartIndex+1); + vert[0][1] = rightGridChain->get_v_value(rightGridChainStartIndex); + vert[1][1] = rightGridChain->get_v_value(rightGridChainStartIndex+1); + + monoTriangulation2(&vert[0][0], + &vert[1][0], + rightChain, + i-1, + j+1, + 0, ///a decreae chain + pStream); +} + +#endif + +void stripOfFanRight(vertexArray* rightChain, + Int largeIndex, + Int smallIndex, + gridWrap* grid, + Int vlineIndex, + Int ulineSmallIndex, + Int ulineLargeIndex, + primStream* pStream, + Int gridLineUp /*1 if the grid line is above the trim lines*/ + ) +{ + assert(largeIndex >= smallIndex); + + Real grid_v_value; + grid_v_value = grid->get_v_value(vlineIndex); + + Real2* trimVerts=(Real2*) malloc(sizeof(Real2)* (largeIndex-smallIndex+1)); + assert(trimVerts); + + + Real2* gridVerts=(Real2*) malloc(sizeof(Real2)* (ulineLargeIndex-ulineSmallIndex+1)); + assert(gridVerts); + + Int k,i; + if(! gridLineUp) /*trim line is above grid line, so trim vertices are going right when index increases*/ + for(k=0, i=smallIndex; i<=largeIndex; i++, k++) + { + trimVerts[k][0] = rightChain->getVertex(i)[0]; + trimVerts[k][1] = rightChain->getVertex(i)[1]; + } + else + for(k=0, i=largeIndex; i>=smallIndex; i--, k++) + { + trimVerts[k][0] = rightChain->getVertex(i)[0]; + trimVerts[k][1] = rightChain->getVertex(i)[1]; + } + + for(k=0, i=ulineSmallIndex; i<= ulineLargeIndex; i++, k++) + { + gridVerts[k][0] = grid->get_u_value(i); + gridVerts[k][1] = grid_v_value; + } + + if(gridLineUp) + triangulateXYMono( + ulineLargeIndex-ulineSmallIndex+1, gridVerts, + largeIndex-smallIndex+1, trimVerts, + pStream); + else + triangulateXYMono(largeIndex-smallIndex+1, trimVerts, + ulineLargeIndex-ulineSmallIndex+1, gridVerts, + pStream); + free(trimVerts); + free(gridVerts); +} + + + + + + + + + diff --git a/src/glu/sgi/libnurbs/nurbtess/sampleCompRight.h b/src/glu/sgi/libnurbs/nurbtess/sampleCompRight.h new file mode 100644 index 0000000..4670b87 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/sampleCompRight.h @@ -0,0 +1,117 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _SAMPLECOMPRIGHT_H +#define _SAMPLECOMPRIGHT_H + +#define NOT_TAKEOUT + +#include "sampleMonoPoly.h" +void stripOfFanRight(vertexArray* rightChain, + Int largeIndex, + Int smallIndex, + gridWrap* grid, + Int vlineIndex, + Int ulineSmallIndex, + Int ulineLargeIndex, + primStream* pStream, + Int gridLineUp /*1 if grid line is above the trim lines */ + ); + +#ifdef NOT_TAKEOUT +void sampleRightStripRecF(vertexArray* rightChain, + Int topRightIndex, + Int botRightIndex, + gridBoundaryChain* rightGridChain, + Int rightGridChainStartIndex, + Int rightGridChainEndIndex, + primStream* pStream + ); +//the degenerate case of sampleRightOneGridStep +void sampleRightOneGridStepNoMiddle(vertexArray* rightChain, + Int beginRightIndex, + Int endRightIndex, + gridBoundaryChain* rightGridChain, + Int rightGridChainStartIndex, + primStream* pStream); +//sampling the right area in between two grid lines +//shape: _________| +void sampleRightOneGridStep(vertexArray* rightChain, + Int beginRightIndex, + Int endRightIndex, + gridBoundaryChain* rightGridChain, + Int rightGridChainStartIndex, + primStream* pStream); +void sampleRightSingleTrimEdgeRegion(Real upperVert[2], Real lowerVert[2], + gridBoundaryChain* gridChain, + Int beginIndex, + Int endIndex, + primStream* pStream); +//the degenerate case of sampleRightOneGridStep +void sampleRightOneGridStepNoMiddle(vertexArray* rightChain, + Int beginRightIndex, + Int endRightIndex, + gridBoundaryChain* rightGridChain, + Int rightGridChainStartIndex, + primStream* pStream); + +void sampleCompRight(Real* topVertex, Real* botVertex, + vertexArray* leftChain, + Int leftStartIndex, Int leftEndIndex, + vertexArray* rightChain, + Int rightStartIndex, Int rightEndIndex, + gridBoundaryChain* rightGridChain, + Int gridIndex1, Int gridIndex2, + Int up_leftCornerWhere, + Int up_leftCornerIndex, + Int down_leftCornerWhere, + Int down_leftCornerIndex, + primStream* pStream); + +void sampleRightSingleTrimEdgeRegionGen(Real topVert[2], Real botVert[2], + vertexArray* rightChain, + Int rightStart, + Int rightEnd, + gridBoundaryChain* gridChain, + Int gridBegindex, + Int gridEndIndex, + vertexArray* leftChain, + Int leftUpBegin, + Int leftUpEnd, + Int leftDownBegin, + Int leftDownEnd, + primStream* pStream); +#endif + +#endif + + diff --git a/src/glu/sgi/libnurbs/nurbtess/sampleCompTop.cc b/src/glu/sgi/libnurbs/nurbtess/sampleCompTop.cc new file mode 100644 index 0000000..951e937 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/sampleCompTop.cc @@ -0,0 +1,1030 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include +#include +#include "zlassert.h" +#include "sampleCompTop.h" +#include "sampleCompRight.h" + +#define max(a,b) ((a>b)? a:b) + +//return : index_small, and index_large, +//from [small, large] is strictly U-monotne, +//from [large+1, end] is = u +//if eveybody is = leftStart; i--) + { + if(leftChain->getVertex(i)[0] >= u) + break; + } + ret_index_large = i; + if(ret_index_large >= leftStart) + { + for(i=ret_index_large; i>leftStart; i--) + { + if(leftChain->getVertex(i-1)[0] <= leftChain->getVertex(i)[0]) + break; + } + ret_index_small = i; + } +} + +void findTopRightSegment(vertexArray* rightChain, + Int rightStart, + Int rightEnd, + Real u, + Int& ret_index_small, + Int& ret_index_large) +{ + Int i; + assert(rightStart<=rightEnd); + for(i=rightEnd; i>=rightStart; i--) + { + if(rightChain->getVertex(i)[0] <= u) + break; + } + ret_index_large = i; + if(ret_index_large >= rightStart) + { + for(i=ret_index_large; i>rightStart;i--) + { + if(rightChain->getVertex(i-1)[0] >= rightChain->getVertex(i)[0]) + break; + } + ret_index_small = i; + } +} + + +void sampleTopRightWithGridLinePost(Real* topVertex, + vertexArray* rightChain, + Int rightStart, + Int segIndexSmall, + Int segIndexLarge, + Int rightEnd, + gridWrap* grid, + Int gridV, + Int leftU, + Int rightU, + primStream* pStream) +{ + //the possible section which is to the right of rightU + if(segIndexLarge < rightEnd) + { + Real *tempTop; + if(segIndexLarge >= rightStart) + tempTop = rightChain->getVertex(segIndexLarge); + else + tempTop = topVertex; + Real tempBot[2]; + tempBot[0] = grid->get_u_value(rightU); + tempBot[1] = grid->get_v_value(gridV); +monoTriangulationRecGenOpt(tempTop, tempBot, + NULL, 1,0, + rightChain, segIndexLarge+1, rightEnd, + pStream); +/* + monoTriangulation2(tempTop, tempBot, + rightChain, + segIndexLarge+1, + rightEnd, + 0, //a decrease chian + pStream); +*/ + + } + + //the possible section which is strictly Umonotone + if(segIndexLarge >= rightStart) + { + stripOfFanRight(rightChain, segIndexLarge, segIndexSmall, grid, gridV, leftU, rightU, pStream, 0); + Real tempBot[2]; + tempBot[0] = grid->get_u_value(leftU); + tempBot[1] = grid->get_v_value(gridV); + monoTriangulation2(topVertex, tempBot, rightChain, rightStart, segIndexSmall, 0, pStream); + } + else //the topVertex forms a fan with the grid points + grid->outputFanWithPoint(gridV, leftU, rightU, topVertex, pStream); +} + +void sampleTopRightWithGridLine(Real* topVertex, + vertexArray* rightChain, + Int rightStart, + Int rightEnd, + gridWrap* grid, + Int gridV, + Int leftU, + Int rightU, + primStream* pStream + ) +{ + //if right chian is empty, then there is only one topVertex with one grid line + if(rightEnd < rightStart){ + grid->outputFanWithPoint(gridV, leftU, rightU, topVertex, pStream); + return; + } + + Int segIndexSmall = 0, segIndexLarge; + findTopRightSegment(rightChain, + rightStart, + rightEnd, + grid->get_u_value(rightU), + segIndexSmall, + segIndexLarge + ); + sampleTopRightWithGridLinePost(topVertex, rightChain, + rightStart, + segIndexSmall, + segIndexLarge, + rightEnd, + grid, + gridV, + leftU, + rightU, + pStream); +} + + +void sampleTopLeftWithGridLinePost(Real* topVertex, + vertexArray* leftChain, + Int leftStart, + Int segIndexSmall, + Int segIndexLarge, + Int leftEnd, + gridWrap* grid, + Int gridV, + Int leftU, + Int rightU, + primStream* pStream) +{ + //the possible section which is to the left of leftU + + if(segIndexLarge < leftEnd) + { + Real *tempTop; + if(segIndexLarge >= leftStart) + tempTop = leftChain->getVertex(segIndexLarge); + else + tempTop = topVertex; + Real tempBot[2]; + tempBot[0] = grid->get_u_value(leftU); + tempBot[1] = grid->get_v_value(gridV); + + monoTriangulation2(tempTop, tempBot, + leftChain, + segIndexLarge+1, + leftEnd, + 1, //a increase chian + pStream); + } + + //the possible section which is strictly Umonotone + if(segIndexLarge >= leftStart) + { + //if there are grid points which are to the right of topV, + //then we should use topVertex to form a fan with these points to + //optimize the triangualtion + int do_optimize=1; + if(topVertex[0] >= grid->get_u_value(rightU)) + do_optimize = 0; + else + { + //we also have to make sure that topVertex are the right most vertex + //on the chain. + int i; + for(i=leftStart; i<=segIndexSmall; i++) + if(leftChain->getVertex(i)[0] >= topVertex[0]) + { + do_optimize = 0; + break; + } + } + + if(do_optimize) + { + //find midU so that grid->get_u_value(midU) >= topVertex[0] + //and grid->get_u_value(midU-1) < topVertex[0] + int midU=rightU; + while(grid->get_u_value(midU) >= topVertex[0]) + { + midU--; + if(midU < leftU) + break; + } + midU++; + + grid->outputFanWithPoint(gridV, midU, rightU, topVertex, pStream); + stripOfFanLeft(leftChain, segIndexLarge, segIndexSmall, grid, gridV, leftU, midU, pStream, 0); + Real tempBot[2]; + tempBot[0] = grid->get_u_value(midU); + tempBot[1] = grid->get_v_value(gridV); + monoTriangulation2(topVertex, tempBot, leftChain, leftStart, segIndexSmall, 1, pStream); + } + else //not optimize + { + + stripOfFanLeft(leftChain, segIndexLarge, segIndexSmall, grid, gridV, leftU, rightU, pStream, 0); + Real tempBot[2]; + tempBot[0] = grid->get_u_value(rightU); + tempBot[1] = grid->get_v_value(gridV); + monoTriangulation2(topVertex, tempBot, leftChain, leftStart, segIndexSmall, 1, pStream); + } + } + else //the topVertex forms a fan with the grid points + grid->outputFanWithPoint(gridV, leftU, rightU, topVertex, pStream); +} + + +void sampleTopLeftWithGridLine(Real* topVertex, + vertexArray* leftChain, + Int leftStart, + Int leftEnd, + gridWrap* grid, + Int gridV, + Int leftU, + Int rightU, + primStream* pStream + ) +{ + Int segIndexSmall = 0, segIndexLarge; + //if left chain is empty, then there is only one top vertex with one grid + // line + if(leftEnd < leftStart) { + grid->outputFanWithPoint(gridV, leftU, rightU, topVertex, pStream); + return; + } + findTopLeftSegment(leftChain, + leftStart, + leftEnd, + grid->get_u_value(leftU), + segIndexSmall, + segIndexLarge + ); + sampleTopLeftWithGridLinePost(topVertex, + leftChain, + leftStart, + segIndexSmall, + segIndexLarge, + leftEnd, + grid, + gridV, + leftU, + rightU, + pStream); +} + + +//return 1 if saprator exits, 0 otherwise +Int findTopSeparator(vertexArray* leftChain, + Int leftStartIndex, + Int leftEndIndex, + vertexArray* rightChain, + Int rightStartIndex, + Int rightEndIndex, + Int& ret_sep_left, + Int& ret_sep_right) +{ + + Int oldLeftI, oldRightI, newLeftI, newRightI; + Int i,j,k; + Real leftMax /*= leftChain->getVertex(leftEndIndex)[0]*/; + Real rightMin /*= rightChain->getVertex(rightEndIndex)[0]*/; + if(leftChain->getVertex(leftEndIndex)[1] > rightChain->getVertex(rightEndIndex)[1]) //left higher + { + oldLeftI = leftEndIndex+1; + oldRightI = rightEndIndex; + leftMax = leftChain->getVertex(leftEndIndex)[0] - Real(1.0); //initilza to left of leftU + rightMin = rightChain->getVertex(rightEndIndex)[0]; + } + else + { + oldLeftI = leftEndIndex; + oldRightI = rightEndIndex+1; + leftMax = leftChain->getVertex(leftEndIndex)[0]; + rightMin = rightChain->getVertex(rightEndIndex)[0] + Real(1.0); + } + + //i: the current working leftChain index, + //j: the current working rightChain index, + //if left(i) is higher than right(j), then the two chains beloew right(j) are separated. + //else the two chains below left(i) are separeated. + i=leftEndIndex; + j=rightEndIndex; + while(1) + { + newLeftI = oldLeftI; + newRightI = oldRightI; + + if(i= rightStartIndex; k--) + { + if(rightChain->getVertex(k)[0] > leftMax) //no conflict + { + //update oldRightI if necessary + if(rightChain->getVertex(k)[0] < rightMin) + { + rightMin = rightChain->getVertex(k)[0]; + oldRightI = k; + } + } + else //there is a conflict + break; //the for-loop. below right(k-1) is seperated: oldLeftI, oldRightI. + } + break; //the while loop + } + else if(j= leftStartIndex; k--) + { + if(leftChain->getVertex(k)[0] < rightMin) //no conflict + { + //update oldLeftI if necessary + if(leftChain->getVertex(k)[0] > leftMax) + { + leftMax = leftChain->getVertex(k)[0]; + oldLeftI = k; + } + } + else //there is a conflict + break; //the for loop + } + break; //the while loop + } + else if(leftChain->getVertex(i)[1] > rightChain->getVertex(j)[1]) //left hgiher + { + if(leftChain->getVertex(i)[0] > leftMax) //update leftMax and newLeftI. + { + leftMax = leftChain->getVertex(i)[0]; + newLeftI = i; + } + for(k=j-1; k>= rightStartIndex; k--) //update rightMin and newRightI. + { + if(rightChain->getVertex(k)[1] > leftChain->getVertex(i)[1]) + break; + if(rightChain->getVertex(k)[0] < rightMin) + { + rightMin = rightChain->getVertex(k)[0]; + newRightI = k; + } + } + j = k; //next working j, since j will be higher than i in next loop + if(leftMax >= rightMin) //there is a conflict + break; + else //still no conflict + { + oldLeftI = newLeftI; + oldRightI = newRightI; + } + } + else //right higher + { + if(rightChain->getVertex(j)[0] < rightMin) + { + rightMin = rightChain->getVertex(j)[0]; + newRightI = j; + } + for(k=i-1; k>= leftStartIndex; k--) + { + if(leftChain->getVertex(k)[1] > rightChain->getVertex(j)[1]) + break; + if(leftChain->getVertex(k)[0] > leftMax) + { + leftMax = leftChain->getVertex(k)[0]; + newLeftI = k; + } + } + i = k; //next working i, since i will be higher than j next loop + + if(leftMax >= rightMin) //there is a conflict + break; + else //still no conflict + { + oldLeftI = newLeftI; + oldRightI = newRightI; + } + } + }//end of while loop + //now oldLeftI and oldRightI are the desired separeator index, notice that there are not necessarily valid + if(oldLeftI > leftEndIndex || oldRightI > rightEndIndex) + return 0; + else + { + ret_sep_left = oldLeftI; + ret_sep_right = oldRightI; + return 1; + } +} + + +void sampleCompTop(Real* topVertex, + vertexArray* leftChain, + Int leftStartIndex, + vertexArray* rightChain, + Int rightStartIndex, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridIndex1, + Int up_leftCornerWhere, + Int up_leftCornerIndex, + Int up_rightCornerWhere, + Int up_rightCornerIndex, + primStream* pStream) +{ + if(up_leftCornerWhere == 1 && up_rightCornerWhere == 1) //the top is topVertex with possible grid points + { + leftGridChain->getGrid()->outputFanWithPoint(leftGridChain->getVlineIndex(gridIndex1), + leftGridChain->getUlineIndex(gridIndex1), + rightGridChain->getUlineIndex(gridIndex1), + topVertex, + pStream); + return; + } + + else if(up_leftCornerWhere != 0) + { + Real* tempTop; + Int tempRightStart; + if(up_leftCornerWhere == 1){ + tempRightStart = rightStartIndex; + tempTop = topVertex; + } + else + { + tempRightStart = up_leftCornerIndex+1; + tempTop = rightChain->getVertex(up_leftCornerIndex); + } + sampleTopRightWithGridLine(tempTop, rightChain, tempRightStart, up_rightCornerIndex, + rightGridChain->getGrid(), + leftGridChain->getVlineIndex(gridIndex1), + leftGridChain->getUlineIndex(gridIndex1), + rightGridChain->getUlineIndex(gridIndex1), + pStream); + } + else if(up_rightCornerWhere != 2) + { + Real* tempTop; + Int tempLeftStart; + if(up_rightCornerWhere == 1) + { + tempLeftStart = leftStartIndex; + tempTop = topVertex; + } + else //0 + { + tempLeftStart = up_rightCornerIndex+1; + tempTop = leftChain->getVertex(up_rightCornerIndex); + } +/* + sampleTopLeftWithGridLine(tempTop, leftChain, tempLeftStart, up_leftCornerIndex, + leftGridChain->getGrid(), + leftGridChain->getVlineIndex(gridIndex1), + leftGridChain->getUlineIndex(gridIndex1), + rightGridChain->getUlineIndex(gridIndex1), + pStream); +*/ + sampleCompTopSimple(topVertex, + leftChain, + leftStartIndex, + rightChain, + rightStartIndex, + leftGridChain, + rightGridChain, + gridIndex1, + up_leftCornerWhere, + up_leftCornerIndex, + up_rightCornerWhere, + up_rightCornerIndex, + pStream); + } + else //up_leftCornerWhere == 0, up_rightCornerWhere == 2. + { + sampleCompTopSimple(topVertex, + leftChain, + leftStartIndex, + rightChain, + rightStartIndex, + leftGridChain, + rightGridChain, + gridIndex1, + up_leftCornerWhere, + up_leftCornerIndex, + up_rightCornerWhere, + up_rightCornerIndex, + pStream); + return; +#ifdef NOT_REACHABLE //code is not reachable, for test purpose only + //the following code is trying to do some optimization, but not quite working, also see sampleCompBot.C: + Int sep_left, sep_right; + if(findTopSeparator(leftChain, + leftStartIndex, + up_leftCornerIndex, + rightChain, + rightStartIndex, + up_rightCornerIndex, + sep_left, + sep_right) + ) //separator exists + { + + if( leftChain->getVertex(sep_left)[0] >= leftGridChain->get_u_value(gridIndex1) && + rightChain->getVertex(sep_right)[0] <= rightGridChain->get_u_value(gridIndex1)) + { + Int gridSep; + Int segLeftSmall, segLeftLarge, segRightSmall, segRightLarge; + Int valid=1; //whether the gridStep is valid or not. + findTopLeftSegment(leftChain, + sep_left, + up_leftCornerIndex, + leftGridChain->get_u_value(gridIndex1), + segLeftSmall, + segLeftLarge); + findTopRightSegment(rightChain, + sep_right, + up_rightCornerIndex, + rightGridChain->get_u_value(gridIndex1), + segRightSmall, + segRightLarge); + if(leftChain->getVertex(segLeftSmall)[1] >= rightChain->getVertex(segRightSmall)[1]) + { + gridSep = rightGridChain->getUlineIndex(gridIndex1); + while(leftGridChain->getGrid()->get_u_value(gridSep) > leftChain->getVertex(segLeftSmall)[0]) + gridSep--; + if(segLeftSmallgetGrid()->get_u_value(gridSep) < leftChain->getVertex(segLeftSmall+1)[0]) + { + valid = 0; + } + } + else + { + gridSep = leftGridChain->getUlineIndex(gridIndex1); + while(leftGridChain->getGrid()->get_u_value(gridSep) < rightChain->getVertex(segRightSmall)[0]) + gridSep++; + if(segRightSmallgetGrid()->get_u_value(gridSep) > rightChain->getVertex(segRightSmall+1)[0]) + { + valid = 0; + } + } + + if(! valid) + { + sampleCompTopSimple(topVertex, + leftChain, + leftStartIndex, + rightChain, + rightStartIndex, + leftGridChain, + rightGridChain, + gridIndex1, + up_leftCornerWhere, + up_leftCornerIndex, + up_rightCornerWhere, + up_rightCornerIndex, + pStream); + } + else + { + sampleTopLeftWithGridLinePost(leftChain->getVertex(segLeftSmall), + leftChain, + segLeftSmall+1, + segLeftSmall+1, + segLeftLarge, + up_leftCornerIndex, + leftGridChain->getGrid(), + leftGridChain->getVlineIndex(gridIndex1), + leftGridChain->getUlineIndex(gridIndex1), + gridSep, + pStream); + sampleTopRightWithGridLinePost(rightChain->getVertex(segRightSmall), + rightChain, + segRightSmall+1, + segRightSmall+1, + segRightLarge, + up_rightCornerIndex, + leftGridChain->getGrid(), + leftGridChain->getVlineIndex(gridIndex1), + gridSep, + rightGridChain->getUlineIndex(gridIndex1), + pStream); + Real tempBot[2]; + tempBot[0] = leftGridChain->getGrid()->get_u_value(gridSep); + tempBot[1] = leftGridChain->get_v_value(gridIndex1); + monoTriangulationRecGen(topVertex, tempBot, + leftChain, leftStartIndex, segLeftSmall, + rightChain, rightStartIndex, segRightSmall, + pStream); + } + }//end if both sides have vetices inside the gridboundary points + else if(leftChain->getVertex(sep_left)[0] >= leftGridChain->get_u_value(gridIndex1)) //left is in, right is nout + { + + Int segLeftSmall, segLeftLarge; + findTopLeftSegment(leftChain, + sep_left, + up_leftCornerIndex, + leftGridChain->get_u_value(gridIndex1), + segLeftSmall, + segLeftLarge); + assert(segLeftLarge >= sep_left); + monoTriangulation2(leftChain->getVertex(segLeftLarge), + leftGridChain->get_vertex(gridIndex1), + leftChain, + segLeftLarge+1, + up_leftCornerIndex, + 1, //a increase chain, + pStream); + + stripOfFanLeft(leftChain, segLeftLarge, segLeftSmall, + leftGridChain->getGrid(), + leftGridChain->getVlineIndex(gridIndex1), + leftGridChain->getUlineIndex(gridIndex1), + rightGridChain->getUlineIndex(gridIndex1), + pStream, 0); + + + monoTriangulationRecGen(topVertex, rightGridChain->get_vertex(gridIndex1), + leftChain, leftStartIndex, segLeftSmall, + rightChain, rightStartIndex, up_rightCornerIndex, + pStream); + }//end left in right out + else if(rightChain->getVertex(sep_right)[0] <= rightGridChain->get_u_value(gridIndex1)) + { + Int segRightSmall, segRightLarge; + findTopRightSegment(rightChain, + sep_right, + up_rightCornerIndex, + rightGridChain->get_u_value(gridIndex1), + segRightSmall, + segRightLarge); + assert(segRightLarge>=sep_right); + monoTriangulation2(rightChain->getVertex(segRightLarge), + rightGridChain->get_vertex(gridIndex1), + rightChain, + segRightLarge+1, + up_rightCornerIndex, + 0, //a decrease chain + pStream); + stripOfFanRight(rightChain, segRightLarge, segRightSmall, + rightGridChain->getGrid(), + rightGridChain->getVlineIndex(gridIndex1), + leftGridChain->getUlineIndex(gridIndex1), + rightGridChain->getUlineIndex(gridIndex1), + pStream, 0); + + + monoTriangulationRecGen(topVertex, leftGridChain->get_vertex(gridIndex1), + leftChain, leftStartIndex, up_leftCornerIndex, + rightChain, rightStartIndex,segRightSmall, + pStream); + + }//end left out rigth in + else //left out , right out + { + + sampleCompTopSimple(topVertex, + leftChain, + leftStartIndex, + rightChain, + rightStartIndex, + leftGridChain, + rightGridChain, + gridIndex1, + up_leftCornerWhere, + up_leftCornerIndex, + up_rightCornerWhere, + up_rightCornerIndex, + pStream); + }//end leftout, right out + }//end if separator exixts. + else //no separator + { + + sampleCompTopSimple(topVertex, + leftChain, + leftStartIndex, + rightChain, + rightStartIndex, + leftGridChain, + rightGridChain, + gridIndex1, + up_leftCornerWhere, + up_leftCornerIndex, + up_rightCornerWhere, + up_rightCornerIndex, + pStream); + } +#endif + }//end if 0,2 +}//end if the function + + +static void sampleCompTopSimpleOpt(gridWrap* grid, + Int gridV, + Real* topVertex, Real* botVertex, + vertexArray* inc_chain, Int inc_current, Int inc_end, + vertexArray* dec_chain, Int dec_current, Int dec_end, + primStream* pStream) +{ + if(gridV <= 0 || dec_endget_v_value(gridV+1) >= topVertex[1]) + { + monoTriangulationRecGenOpt(topVertex, botVertex, + inc_chain, inc_current, inc_end, + dec_chain, dec_current, dec_end, + pStream); + return; + } + Int i,j,k; + Real currentV = grid->get_v_value(gridV+1); + if(inc_chain->getVertex(inc_end)[1] <= currentV && + dec_chain->getVertex(dec_end)[1] < currentV) + { + //find i bottom up so that inc_chain[i]<= curentV and inc_chain[i-1] > currentV, + //find j botom up so that dec_chain[j] < currentV and dec_chain[j-1] >= currentV + for(i=inc_end; i >= inc_current; i--) + { + if(inc_chain->getVertex(i)[1] > currentV) + break; + } + i++; + for(j=dec_end; j >= dec_current; j--) + { + if(dec_chain->getVertex(j)[1] >= currentV) + break; + } + j++; + if(inc_chain->getVertex(i)[1] <= dec_chain->getVertex(j)[1]) + { + //find the k so that dec_chain[k][1] < inc_chain[i][1] + for(k=j; k<=dec_end; k++) + { + if(dec_chain->getVertex(k)[1] < inc_chain->getVertex(i)[1]) + break; + } + //we know that dec_chain[j][1] >= inc_chian[i][1] + //we know that dec_chain[k-1][1]>=inc_chain[i][1] + //we know that dec_chian[k][1] < inc_chain[i][1] + //find l in [j, k-1] so that dec_chain[l][0] 0 is closest to + // inc_chain[i] + int l; + Real tempI = Real(j); + Real tempMin = (Real)fabs(inc_chain->getVertex(i)[0] - dec_chain->getVertex(j)[0]); + for(l=j+1; l<= k-1; l++) + { + if(fabs(inc_chain->getVertex(i)[0] - dec_chain->getVertex(l)[0]) + <= tempMin) + { + tempMin = (Real)fabs(inc_chain->getVertex(i)[0] - dec_chain->getVertex(l)[0]); + tempI = (Real)l; + } + } + //inc_chain[i] and dec_chain[tempI] are connected. + monoTriangulationRecGenOpt(dec_chain->getVertex((int)tempI), + botVertex, + inc_chain, i, inc_end, + dec_chain, (int)(tempI+1), dec_end, + pStream); + //recursively do the rest + sampleCompTopSimpleOpt(grid, + gridV+1, + topVertex, inc_chain->getVertex(i), + inc_chain, inc_current, i-1, + dec_chain, dec_current, (int)tempI, + pStream); + } + else + { + //find the k so that inc_chain[k][1] <= dec_chain[j][1] + for(k=i; k<=inc_end; k++) + { + if(inc_chain->getVertex(k)[1] <= dec_chain->getVertex(j)[1]) + break; + } + //we know that inc_chain[i] > dec_chain[j] + //we know that inc_chain[k-1][1] > dec_chain[j][1] + //we know that inc_chain[k][1] <= dec_chain[j][1] + //so we find l between [i,k-1] so that + //inc_chain[l][0] is the closet to dec_chain[j][0] + int tempI = i; + int l; + Real tempMin = (Real)fabs(inc_chain->getVertex(i)[0] - dec_chain->getVertex(j)[0]); + for(l=i+1; l<=k-1; l++) + { + if(fabs(inc_chain->getVertex(l)[0] - dec_chain->getVertex(j)[0]) <= tempMin) + { + tempMin = (Real)fabs(inc_chain->getVertex(l)[0] - dec_chain->getVertex(j)[0]); + tempI = l; + } + } + + //inc_chain[tempI] and dec_chain[j] are connected + + monoTriangulationRecGenOpt(inc_chain->getVertex(tempI), + botVertex, + inc_chain, tempI+1, inc_end, + dec_chain, j, dec_end, + pStream); + + //recurvesily do the rest + sampleCompTopSimpleOpt(grid, gridV+1, + topVertex, dec_chain->getVertex(j), + inc_chain, inc_current, tempI, + dec_chain, dec_current, j-1, + pStream); + } + } + else //go to the next higher gridV + { + sampleCompTopSimpleOpt(grid, + gridV+1, + topVertex, botVertex, + inc_chain, inc_current, inc_end, + dec_chain, dec_current, dec_end, + pStream); + } +} + +void sampleCompTopSimple(Real* topVertex, + vertexArray* leftChain, + Int leftStartIndex, + vertexArray* rightChain, + Int rightStartIndex, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridIndex1, + Int up_leftCornerWhere, + Int up_leftCornerIndex, + Int up_rightCornerWhere, + Int up_rightCornerIndex, + primStream* pStream) +{ + //the plan is to use monotriangulation algortihm. + Int i,k; + Real* ActualTop; + Real* ActualBot; + Int ActualLeftStart, ActualLeftEnd; + Int ActualRightStart, ActualRightEnd; + + //creat an array to store the points on the grid line + gridWrap* grid = leftGridChain->getGrid(); + Int gridV = leftGridChain->getVlineIndex(gridIndex1); + Int gridLeftU = leftGridChain->getUlineIndex(gridIndex1); + Int gridRightU = rightGridChain->getUlineIndex(gridIndex1); + + Real2* gridPoints = (Real2*) malloc(sizeof(Real2) * (gridRightU - gridLeftU +1)); + assert(gridPoints); + + for(k=0, i=gridRightU; i>= gridLeftU; i--, k++) + { + gridPoints[k][0] = grid->get_u_value(i); + gridPoints[k][1] = grid->get_v_value(gridV); + } + + if(up_leftCornerWhere != 2) + ActualRightStart = rightStartIndex; + else + ActualRightStart = up_leftCornerIndex+1; //up_leftCornerIndex will be the ActualTop + + if(up_rightCornerWhere != 2) //right corner is not on right chain + ActualRightEnd = rightStartIndex-1; //meaning that there is no actual rigth section + else + ActualRightEnd = up_rightCornerIndex; + + vertexArray ActualRightChain(max(0, ActualRightEnd-ActualRightStart+1) + gridRightU-gridLeftU+1); + + for(i=ActualRightStart; i<= ActualRightEnd; i++) + ActualRightChain.appendVertex(rightChain->getVertex(i)); + for(i=0; igetVertex(up_rightCornerIndex); + else + ActualTop = topVertex; + } + else if(up_leftCornerWhere == 1) + ActualTop = topVertex; + else //up_leftCornerWhere == 2 + ActualTop = rightChain->getVertex(up_leftCornerIndex); + + ActualBot = gridPoints[gridRightU - gridLeftU]; + + + + + if(leftChain->getVertex(ActualLeftEnd)[1] == ActualBot[1]) + { +/* + monoTriangulationRecGenOpt(ActualTop, leftChain->getVertex(ActualLeftEnd), + leftChain, + ActualLeftStart, ActualLeftEnd-1, + &ActualRightChain, + 0, + ActualRightChain.getNumElements()-1, + pStream); +*/ + + sampleCompTopSimpleOpt(grid, gridV, + ActualTop, leftChain->getVertex(ActualLeftEnd), + leftChain, + ActualLeftStart, ActualLeftEnd-1, + &ActualRightChain, + 0, + ActualRightChain.getNumElements()-1, + pStream); + + } + else + { +/* + monoTriangulationRecGenOpt(ActualTop, ActualBot, leftChain, + ActualLeftStart, ActualLeftEnd, + &ActualRightChain, + 0, ActualRightChain.getNumElements()-2, //the last is the bot. + pStream); +*/ + + sampleCompTopSimpleOpt(grid, gridV, + ActualTop, ActualBot, leftChain, + ActualLeftStart, ActualLeftEnd, + &ActualRightChain, + 0, ActualRightChain.getNumElements()-2, //the last is the bot. + pStream); + + + } + + free(gridPoints); + +} + diff --git a/src/glu/sgi/libnurbs/nurbtess/sampleCompTop.h b/src/glu/sgi/libnurbs/nurbtess/sampleCompTop.h new file mode 100644 index 0000000..95598d6 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/sampleCompTop.h @@ -0,0 +1,67 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _SAMPLECOMPTOP_H +#define _SAMPLECOMPTOP_H + +#include "sampleMonoPoly.h" + +void sampleCompTop(Real* topVertex, + vertexArray* leftChain, + Int leftStartIndex, + vertexArray* rightChain, + Int rightStartIndex, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridIndex1, + Int up_leftCornerWhere, + Int up_leftCornerIndex, + Int up_rightCornerWhere, + Int up_rightCornerIndex, + primStream* pStream); + +void sampleCompTopSimple(Real* topVertex, + vertexArray* leftChain, + Int leftStartIndex, + vertexArray* rightChain, + Int rightStartIndex, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridIndex1, + Int up_leftCornerWhere, + Int up_leftCornerIndex, + Int up_rightCornerWhere, + Int up_rightCornerIndex, + primStream* pStream); + +#endif + diff --git a/src/glu/sgi/libnurbs/nurbtess/sampleMonoPoly.cc b/src/glu/sgi/libnurbs/nurbtess/sampleMonoPoly.cc new file mode 100644 index 0000000..051f241 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/sampleMonoPoly.cc @@ -0,0 +1,2427 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include "gluos.h" +#include +#include +#include + +#ifndef max +#define max(a,b) ((a>b)? a:b) +#endif +#ifndef min +#define min(a,b) ((a>b)? b:a) +#endif + +#include + +#include "glimports.h" +#include "zlassert.h" +#include "sampleMonoPoly.h" +#include "sampleComp.h" +#include "polyDBG.h" +#include "partitionX.h" + + +#define ZERO 0.00001 + +//#define MYDEBUG + +//#define SHORTEN_GRID_LINE +//see work/newtess/internal/test/problems + + +/*split a polygon so that each vertex correcpond to one edge + *the head of the first edge of the returned plygon must be the head of the first + *edge of the origianl polygon. This is crucial for the code in sampleMonoPoly function + */ + directedLine* polygonConvert(directedLine* polygon) +{ + int i; + directedLine* ret; + sampledLine* sline; + sline = new sampledLine(2); + sline->setPoint(0, polygon->getVertex(0)); + sline->setPoint(1, polygon->getVertex(1)); + ret=new directedLine(INCREASING, sline); + for(i=1; i<= polygon->get_npoints()-2; i++) + { + sline = new sampledLine(2); + sline->setPoint(0, polygon->getVertex(i)); + sline->setPoint(1, polygon->getVertex(i+1)); + ret->insert(new directedLine(INCREASING, sline)); + } + + for(directedLine *temp = polygon->getNext(); temp != polygon; temp = temp->getNext()) + { + for(i=0; i<= temp->get_npoints()-2; i++) + { + sline = new sampledLine(2); + sline->setPoint(0, temp->getVertex(i)); + sline->setPoint(1, temp->getVertex(i+1)); + ret->insert(new directedLine(INCREASING, sline)); + } + } + return ret; +} + +void triangulateConvexPolyVertical(directedLine* topV, directedLine* botV, primStream *pStream) +{ + Int i,j; + Int n_leftVerts; + Int n_rightVerts; + Real** leftVerts; + Real** rightVerts; + directedLine* tempV; + n_leftVerts = 0; + for(tempV = topV; tempV != botV; tempV = tempV->getNext()) + { + n_leftVerts += tempV->get_npoints(); + } + n_rightVerts=0; + for(tempV = botV; tempV != topV; tempV = tempV->getNext()) + { + n_rightVerts += tempV->get_npoints(); + } + + Real2* temp_leftVerts = (Real2 *) malloc(sizeof(Real2) * n_leftVerts); + assert(temp_leftVerts); + Real2* temp_rightVerts = (Real2 *) malloc(sizeof(Real2) * n_rightVerts); + assert(temp_rightVerts); + + leftVerts = (Real**) malloc(sizeof(Real2*) * n_leftVerts); + assert(leftVerts); + rightVerts = (Real**) malloc(sizeof(Real2*) * n_rightVerts); + assert(rightVerts); + for(i=0; igetNext()) + { + for(j=1; jget_npoints(); j++) + { + leftVerts[i][0] = tempV->getVertex(j)[0]; + leftVerts[i][1] = tempV->getVertex(j)[1]; + i++; + } + } + n_leftVerts = i; + i=0; + for(tempV = topV->getPrev(); tempV != botV->getPrev(); tempV = tempV->getPrev()) + { + for(j=tempV->get_npoints()-1; j>=1; j--) + { + rightVerts[i][0] = tempV->getVertex(j)[0]; + rightVerts[i][1] = tempV->getVertex(j)[1]; + i++; + } + } + n_rightVerts = i; + triangulateXYMonoTB(n_leftVerts, leftVerts, n_rightVerts, rightVerts, pStream); + free(leftVerts); + free(rightVerts); + free(temp_leftVerts); + free(temp_rightVerts); +} + +void triangulateConvexPolyHoriz(directedLine* leftV, directedLine* rightV, primStream *pStream) +{ + Int i,j; + Int n_lowerVerts; + Int n_upperVerts; + Real2 *lowerVerts; + Real2 *upperVerts; + directedLine* tempV; + n_lowerVerts=0; + for(tempV = leftV; tempV != rightV; tempV = tempV->getNext()) + { + n_lowerVerts += tempV->get_npoints(); + } + n_upperVerts=0; + for(tempV = rightV; tempV != leftV; tempV = tempV->getNext()) + { + n_upperVerts += tempV->get_npoints(); + } + lowerVerts = (Real2 *) malloc(sizeof(Real2) * n_lowerVerts); + assert(n_lowerVerts); + upperVerts = (Real2 *) malloc(sizeof(Real2) * n_upperVerts); + assert(n_upperVerts); + i=0; + for(tempV = leftV; tempV != rightV; tempV = tempV->getNext()) + { + for(j=0; jget_npoints(); j++) + { + lowerVerts[i][0] = tempV->getVertex(j)[0]; + lowerVerts[i][1] = tempV->getVertex(j)[1]; + i++; + } + } + i=0; + for(tempV = leftV->getPrev(); tempV != rightV->getPrev(); tempV = tempV->getPrev()) + { + for(j=tempV->get_npoints()-1; j>=0; j--) + { + upperVerts[i][0] = tempV->getVertex(j)[0]; + upperVerts[i][1] = tempV->getVertex(j)[1]; + i++; + } + } + triangulateXYMono(n_upperVerts, upperVerts, n_lowerVerts, lowerVerts, pStream); + free(lowerVerts); + free(upperVerts); +} +void triangulateConvexPoly(directedLine* polygon, Int ulinear, Int vlinear, primStream* pStream) +{ + /*find left, right, top , bot + */ + directedLine* tempV; + directedLine* topV; + directedLine* botV; + directedLine* leftV; + directedLine* rightV; + topV = botV = polygon; + + for(tempV = polygon->getNext(); tempV != polygon; tempV = tempV->getNext()) + { + if(compV2InY(topV->head(), tempV->head())<0) { + + topV = tempV; + } + if(compV2InY(botV->head(), tempV->head())>0) { + + botV = tempV; + } + } + //find leftV + for(tempV = topV; tempV != botV; tempV = tempV->getNext()) + { + if(tempV->tail()[0] >= tempV->head()[0]) + break; + } + leftV = tempV; + //find rightV + for(tempV = botV; tempV != topV; tempV = tempV->getNext()) + { + if(tempV->tail()[0] <= tempV->head()[0]) + break; + } + rightV = tempV; + if(vlinear) + { + triangulateConvexPolyHoriz( leftV, rightV, pStream); + } + else if(ulinear) + { + triangulateConvexPolyVertical(topV, botV, pStream); + } + else + { + if(DBG_is_U_direction(polygon)) + { + triangulateConvexPolyHoriz( leftV, rightV, pStream); + } + else + triangulateConvexPolyVertical(topV, botV, pStream); + } +} + +/*for debug purpose*/ +void drawCorners( + Real* topV, Real* botV, + vertexArray* leftChain, + vertexArray* rightChain, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridIndex1, + Int gridIndex2, + Int leftCornerWhere, + Int leftCornerIndex, + Int rightCornerWhere, + Int rightCornerIndex, + Int bot_leftCornerWhere, + Int bot_leftCornerIndex, + Int bot_rightCornerWhere, + Int bot_rightCornerIndex) +{ + Real* leftCornerV; + Real* rightCornerV; + Real* bot_leftCornerV; + Real* bot_rightCornerV; + + if(leftCornerWhere == 1) + leftCornerV = topV; + else if(leftCornerWhere == 0) + leftCornerV = leftChain->getVertex(leftCornerIndex); + else + leftCornerV = rightChain->getVertex(leftCornerIndex); + + if(rightCornerWhere == 1) + rightCornerV = topV; + else if(rightCornerWhere == 0) + rightCornerV = leftChain->getVertex(rightCornerIndex); + else + rightCornerV = rightChain->getVertex(rightCornerIndex); + + if(bot_leftCornerWhere == 1) + bot_leftCornerV = botV; + else if(bot_leftCornerWhere == 0) + bot_leftCornerV = leftChain->getVertex(bot_leftCornerIndex); + else + bot_leftCornerV = rightChain->getVertex(bot_leftCornerIndex); + + if(bot_rightCornerWhere == 1) + bot_rightCornerV = botV; + else if(bot_rightCornerWhere == 0) + bot_rightCornerV = leftChain->getVertex(bot_rightCornerIndex); + else + bot_rightCornerV = rightChain->getVertex(bot_rightCornerIndex); + + Real topGridV = leftGridChain->get_v_value(gridIndex1); + Real topGridU1 = leftGridChain->get_u_value(gridIndex1); + Real topGridU2 = rightGridChain->get_u_value(gridIndex1); + Real botGridV = leftGridChain->get_v_value(gridIndex2); + Real botGridU1 = leftGridChain->get_u_value(gridIndex2); + Real botGridU2 = rightGridChain->get_u_value(gridIndex2); + + glBegin(GL_LINE_STRIP); + glVertex2fv(leftCornerV); + glVertex2f(topGridU1, topGridV); + glEnd(); + + glBegin(GL_LINE_STRIP); + glVertex2fv(rightCornerV); + glVertex2f(topGridU2, topGridV); + glEnd(); + + glBegin(GL_LINE_STRIP); + glVertex2fv(bot_leftCornerV); + glVertex2f(botGridU1, botGridV); + glEnd(); + + glBegin(GL_LINE_STRIP); + glVertex2fv(bot_rightCornerV); + glVertex2f(botGridU2, botGridV); + glEnd(); + + +} + +void toVertexArrays(directedLine* topV, directedLine* botV, vertexArray& leftChain, vertexArray& rightChain) +{ + Int i; + directedLine* tempV; + for(i=1; i<=topV->get_npoints()-2; i++) { /*the first vertex is the top vertex which doesn't belong to inc_chain*/ + leftChain.appendVertex(topV->getVertex(i)); + } + for(tempV = topV->getNext(); tempV != botV; tempV = tempV->getNext()) + { + for(i=0; i<=tempV->get_npoints()-2; i++){ + leftChain.appendVertex(tempV->getVertex(i)); + } + } + + for(tempV = topV->getPrev(); tempV != botV; tempV = tempV->getPrev()) + { + for(i=tempV->get_npoints()-2; i>=0; i--){ + rightChain.appendVertex(tempV->getVertex(i)); + } + } + for(i=botV->get_npoints()-2; i>=1; i--){ + rightChain.appendVertex(tempV->getVertex(i)); + } +} + + +void findTopAndBot(directedLine* polygon, directedLine*& topV, directedLine*& botV) +{ + assert(polygon); + directedLine* tempV; + topV = botV = polygon; + for(tempV = polygon->getNext(); tempV != polygon; tempV = tempV->getNext()) + { + if(compV2InY(topV->head(), tempV->head())<0) { + topV = tempV; + } + if(compV2InY(botV->head(), tempV->head())>0) { + botV = tempV; + } + } +} + +void findGridChains(directedLine* topV, directedLine* botV, + gridWrap* grid, + gridBoundaryChain*& leftGridChain, + gridBoundaryChain*& rightGridChain) +{ + /*find the first(top) and the last (bottom) grid line which intersect the + *this polygon + */ + Int firstGridIndex; /*the index in the grid*/ + Int lastGridIndex; + + firstGridIndex = (Int) ((topV->head()[1] - grid->get_v_min()) / (grid->get_v_max() - grid->get_v_min()) * (grid->get_n_vlines()-1)); + + if(botV->head()[1] < grid->get_v_min()) + lastGridIndex = 0; + else + lastGridIndex = (Int) ((botV->head()[1] - grid->get_v_min()) / (grid->get_v_max() - grid->get_v_min()) * (grid->get_n_vlines()-1)) + 1; + + /*find the interval inside the polygon for each gridline*/ + Int *leftGridIndices = (Int*) malloc(sizeof(Int) * (firstGridIndex - lastGridIndex +1)); + assert(leftGridIndices); + Int *rightGridIndices = (Int*) malloc(sizeof(Int) * (firstGridIndex - lastGridIndex +1)); + assert(rightGridIndices); + Int *leftGridInnerIndices = (Int*) malloc(sizeof(Int) * (firstGridIndex - lastGridIndex +1)); + assert(leftGridInnerIndices); + Int *rightGridInnerIndices = (Int*) malloc(sizeof(Int) * (firstGridIndex - lastGridIndex +1)); + assert(rightGridInnerIndices); + + findLeftGridIndices(topV, firstGridIndex, lastGridIndex, grid, leftGridIndices, leftGridInnerIndices); + + findRightGridIndices(topV, firstGridIndex, lastGridIndex, grid, rightGridIndices, rightGridInnerIndices); + + leftGridChain = new gridBoundaryChain(grid, firstGridIndex, firstGridIndex-lastGridIndex+1, leftGridIndices, leftGridInnerIndices); + + rightGridChain = new gridBoundaryChain(grid, firstGridIndex, firstGridIndex-lastGridIndex+1, rightGridIndices, rightGridInnerIndices); + + free(leftGridIndices); + free(rightGridIndices); + free(leftGridInnerIndices); + free(rightGridInnerIndices); +} + +void findDownCorners(Real *botVertex, + vertexArray *leftChain, Int leftChainStartIndex, Int leftChainEndIndex, + vertexArray *rightChain, Int rightChainStartIndex, Int rightChainEndIndex, + Real v, + Real uleft, + Real uright, + Int& ret_leftCornerWhere, /*0: left chain, 1: topvertex, 2: rightchain*/ + Int& ret_leftCornerIndex, /*useful when ret_leftCornerWhere == 0 or 2*/ + Int& ret_rightCornerWhere, /*0: left chain, 1: topvertex, 2: rightchain*/ + Int& ret_rightCornerIndex /*useful when ret_leftCornerWhere == 0 or 2*/ + ) +{ +#ifdef MYDEBUG +printf("*************enter find donw corner\n"); +printf("finddownCorner: v=%f, uleft=%f, uright=%f\n", v, uleft, uright); +printf("(%i,%i,%i,%i)\n", leftChainStartIndex, leftChainEndIndex,rightChainStartIndex, rightChainEndIndex); +printf("left chain is\n"); +leftChain->print(); +printf("right chain is\n"); +rightChain->print(); +#endif + + assert(v > botVertex[1]); + Real leftGridPoint[2]; + leftGridPoint[0] = uleft; + leftGridPoint[1] = v; + Real rightGridPoint[2]; + rightGridPoint[0] = uright; + rightGridPoint[1] = v; + + Int i; + Int index1, index2; + + index1 = leftChain->findIndexBelowGen(v, leftChainStartIndex, leftChainEndIndex); + index2 = rightChain->findIndexBelowGen(v, rightChainStartIndex, rightChainEndIndex); + + if(index2 <= rightChainEndIndex) //index2 was found above + index2 = rightChain->skipEqualityFromStart(v, index2, rightChainEndIndex); + + if(index1>leftChainEndIndex && index2 > rightChainEndIndex) /*no point below v on left chain or right chain*/ + { + + /*the botVertex is the only vertex below v*/ + ret_leftCornerWhere = 1; + ret_rightCornerWhere = 1; + } + else if(index1>leftChainEndIndex ) /*index2 <= rightChainEndIndex*/ + { + + ret_rightCornerWhere = 2; /*on right chain*/ + ret_rightCornerIndex = index2; + + + Real tempMin = rightChain->getVertex(index2)[0]; + Int tempI = index2; + for(i=index2+1; i<= rightChainEndIndex; i++) + if(rightChain->getVertex(i)[0] < tempMin) + { + tempI = i; + tempMin = rightChain->getVertex(i)[0]; + } + + + //we consider whether we can use botVertex as left corner. First check + //if (leftGirdPoint, botVertex) interesects right chian or not. + if(DBG_intersectChain(rightChain, rightChainStartIndex,rightChainEndIndex, + leftGridPoint, botVertex)) + { + ret_leftCornerWhere = 2;//right + ret_leftCornerIndex = index2; //should use tempI??? + } + else if(botVertex[0] < tempMin) + ret_leftCornerWhere = 1; //bot + else + { + ret_leftCornerWhere = 2; //right + ret_leftCornerIndex = tempI; + } + } + else if(index2> rightChainEndIndex) /*index1<=leftChainEndIndex*/ + { + ret_leftCornerWhere = 0; /*left chain*/ + ret_leftCornerIndex = index1; + + /*find the vertex on the left chain with the maximum u, + *either this vertex or the botvertex can be used as the right corner + */ + + Int tempI; + //skip those points which are equal to v. (avoid degeneratcy) + for(tempI = index1; tempI <= leftChainEndIndex; tempI++) + if(leftChain->getVertex(tempI)[1] < v) + break; + if(tempI > leftChainEndIndex) + ret_rightCornerWhere = 1; + else + { + Real tempMax = leftChain->getVertex(tempI)[0]; + for(i=tempI; i<= leftChainEndIndex; i++) + if(leftChain->getVertex(i)[0] > tempMax) + { + tempI = i; + tempMax = leftChain->getVertex(i)[0]; + } + + + + //we consider whether we can use botVertex as a corner. So first we check + //whether (rightGridPoint, botVertex) interescts the left chain or not. + if(DBG_intersectChain(leftChain, leftChainStartIndex,leftChainEndIndex, + rightGridPoint, botVertex)) + { + ret_rightCornerWhere = 0; + ret_rightCornerIndex = index1; //should use tempI??? + } + else if(botVertex[0] > tempMax) + { + + ret_rightCornerWhere = 1; + } + else + { + ret_rightCornerWhere = 0; + ret_rightCornerIndex = tempI; + } + } + + } + else /*index1<=leftChainEndIndex and index2 <=rightChainEndIndex*/ + { + if(leftChain->getVertex(index1)[1] >= rightChain->getVertex(index2)[1]) /*left point above right point*/ + { + ret_leftCornerWhere = 0; /*on left chain*/ + ret_leftCornerIndex = index1; + + Real tempMax; + Int tempI; + + tempI = index1; + tempMax = leftChain->getVertex(index1)[0]; + + /*find the maximum u for all the points on the left above the right point index2*/ + for(i=index1+1; i<= leftChainEndIndex; i++) + { + if(leftChain->getVertex(i)[1] < rightChain->getVertex(index2)[1]) + break; + + if(leftChain->getVertex(i)[0]>tempMax) + { + tempI = i; + tempMax = leftChain->getVertex(i)[0]; + } + } + //we consider if we can use rightChain(index2) as right corner + //we check if (rightChain(index2), rightGidPoint) intersecs left chain or not. + if(DBG_intersectChain(leftChain, leftChainStartIndex,leftChainEndIndex, rightGridPoint, rightChain->getVertex(index2))) + { + ret_rightCornerWhere = 0; + ret_rightCornerIndex = index1; //should use tempI??? + } + else if(tempMax >= rightChain->getVertex(index2)[0] || + tempMax >= uright + ) + { + + ret_rightCornerWhere = 0; /*on left Chain*/ + ret_rightCornerIndex = tempI; + } + else + { + ret_rightCornerWhere = 2; /*on right chain*/ + ret_rightCornerIndex = index2; + } + } + else /*left below right*/ + { + ret_rightCornerWhere = 2; /*on the right*/ + ret_rightCornerIndex = index2; + + Real tempMin; + Int tempI; + + tempI = index2; + tempMin = rightChain->getVertex(index2)[0]; + + /*find the minimum u for all the points on the right above the left poitn index1*/ + for(i=index2+1; i<= rightChainEndIndex; i++) + { + if( rightChain->getVertex(i)[1] < leftChain->getVertex(index1)[1]) + break; + if(rightChain->getVertex(i)[0] < tempMin) + { + tempI = i; + tempMin = rightChain->getVertex(i)[0]; + } + } + + //we consider if we can use leftchain(index1) as left corner. + //we check if (leftChain(index1) intersects right chian or not + if(DBG_intersectChain(rightChain, rightChainStartIndex, rightChainEndIndex, leftGridPoint, leftChain->getVertex(index1))) + { + ret_leftCornerWhere = 2; + ret_leftCornerIndex = index2; //should use tempI??? + } + else if(tempMin <= leftChain->getVertex(index1)[0] || + tempMin <= uleft) + { + ret_leftCornerWhere = 2; /* on right chain*/ + ret_leftCornerIndex = tempI; + } + else + { + ret_leftCornerWhere = 0; /*on left chain*/ + ret_leftCornerIndex = index1; + } + } + } + +} + + +void findUpCorners(Real *topVertex, + vertexArray *leftChain, Int leftChainStartIndex, Int leftChainEndIndex, + vertexArray *rightChain, Int rightChainStartIndex, Int rightChainEndIndex, + Real v, + Real uleft, + Real uright, + Int& ret_leftCornerWhere, /*0: left chain, 1: topvertex, 2: rightchain*/ + Int& ret_leftCornerIndex, /*useful when ret_leftCornerWhere == 0 or 2*/ + Int& ret_rightCornerWhere, /*0: left chain, 1: topvertex, 2: rightchain*/ + Int& ret_rightCornerIndex /*useful when ret_leftCornerWhere == 0 or 2*/ + ) +{ +#ifdef MYDEBUG +printf("***********enter findUpCorners\n"); +#endif + + assert(v < topVertex[1]); + Real leftGridPoint[2]; + leftGridPoint[0] = uleft; + leftGridPoint[1] = v; + Real rightGridPoint[2]; + rightGridPoint[0] = uright; + rightGridPoint[1] = v; + + Int i; + Int index1, index2; + + index1 = leftChain->findIndexFirstAboveEqualGen(v, leftChainStartIndex, leftChainEndIndex); + + + index2 = rightChain->findIndexFirstAboveEqualGen(v, rightChainStartIndex, rightChainEndIndex); + + if(index2>= leftChainStartIndex) //index2 was found above + index2 = rightChain->skipEqualityFromStart(v, index2, rightChainEndIndex); + + if(index1= rightChainStartIndex*/ + { + ret_rightCornerWhere = 2; /*on right chain*/ + ret_rightCornerIndex = index2; + + //find the minimum u on right top, either that, or top, or right[index2] is the left corner + Real tempMin = rightChain->getVertex(index2)[0]; + Int tempI = index2; + for(i=index2-1; i>=rightChainStartIndex; i--) + if(rightChain->getVertex(i)[0] < tempMin) + { + tempMin = rightChain->getVertex(i)[0]; + tempI = i; + } + //chech whether (leftGridPoint, top) intersects rightchai, + //if yes, use right corner as left corner + //if not, use top or right[tempI] as left corner + if(DBG_intersectChain(rightChain, rightChainStartIndex, rightChainEndIndex, + leftGridPoint, topVertex)) + { + ret_leftCornerWhere = 2; //rightChain + ret_leftCornerIndex = index2; + } + else if(topVertex[0] < tempMin) + ret_leftCornerWhere = 1; /*topvertex*/ + else + { + ret_leftCornerWhere = 2; //right chain + ret_leftCornerIndex = tempI; + } + + } + else if(index2< rightChainStartIndex) /*index1>=leftChainStartIndex*/ + { + ret_leftCornerWhere = 0; /*left chain*/ + ret_leftCornerIndex = index1; + + //find the maximum u on the left top section. either that or topvertex, or left[index1] is the right corner + Real tempMax = leftChain->getVertex(index1)[0]; + Int tempI = index1; + + for(i=index1-1; i>=leftChainStartIndex; i--){ + + if(leftChain->getVertex(i)[0] > tempMax) + { + + tempMax = leftChain->getVertex(i)[0]; + tempI = i; + } + } + //check whether (rightGridPoint, top) intersects leftChain or not + //if yes, we use leftCorner as the right corner + //if not, we use either top or left[tempI] as the right corner + if(DBG_intersectChain(leftChain, leftChainStartIndex,leftChainEndIndex, + rightGridPoint, topVertex)) + { + ret_rightCornerWhere = 0; //left chan + ret_rightCornerIndex = index1; + } + else if(topVertex[0] > tempMax) + ret_rightCornerWhere = 1;//topVertex + else + { + ret_rightCornerWhere = 0;//left chain + ret_rightCornerIndex = tempI; + } + } + else /*index1>=leftChainStartIndex and index2 >=rightChainStartIndex*/ + { + if(leftChain->getVertex(index1)[1] <= rightChain->getVertex(index2)[1]) /*left point below right point*/ + { + ret_leftCornerWhere = 0; /*on left chain*/ + ret_leftCornerIndex = index1; + + Real tempMax; + Int tempI; + + tempI = index1; + tempMax = leftChain->getVertex(index1)[0]; + + /*find the maximum u for all the points on the left below the right point index2*/ + for(i=index1-1; i>= leftChainStartIndex; i--) + { + if(leftChain->getVertex(i)[1] > rightChain->getVertex(index2)[1]) + break; + + if(leftChain->getVertex(i)[0]>tempMax) + { + tempI = i; + tempMax = leftChain->getVertex(i)[0]; + } + } + //chek whether (rightChain(index2), rightGridPoint) intersects leftchian or not + if(DBG_intersectChain(leftChain, leftChainStartIndex, leftChainEndIndex, rightGridPoint, rightChain->getVertex(index2))) + { + ret_rightCornerWhere = 0; + ret_rightCornerIndex = index1; + } + else if(tempMax >= rightChain->getVertex(index2)[0] || + tempMax >= uright) + { + ret_rightCornerWhere = 0; /*on left Chain*/ + ret_rightCornerIndex = tempI; + } + else + { + ret_rightCornerWhere = 2; /*on right chain*/ + ret_rightCornerIndex = index2; + } + } + else /*left above right*/ + { + ret_rightCornerWhere = 2; /*on the right*/ + ret_rightCornerIndex = index2; + + Real tempMin; + Int tempI; + + tempI = index2; + tempMin = rightChain->getVertex(index2)[0]; + + /*find the minimum u for all the points on the right below the left poitn index1*/ + for(i=index2-1; i>= rightChainStartIndex; i--) + { + if( rightChain->getVertex(i)[1] > leftChain->getVertex(index1)[1]) + break; + if(rightChain->getVertex(i)[0] < tempMin) + { + tempI = i; + tempMin = rightChain->getVertex(i)[0]; + } + } + //check whether (leftGRidPoint,left(index1)) interesect right chain + if(DBG_intersectChain(rightChain, rightChainStartIndex, rightChainEndIndex, + leftGridPoint, leftChain->getVertex(index1))) + { + ret_leftCornerWhere = 2; //right + ret_leftCornerIndex = index2; + } + else if(tempMin <= leftChain->getVertex(index1)[0] || + tempMin <= uleft) + { + ret_leftCornerWhere = 2; /* on right chain*/ + ret_leftCornerIndex = tempI; + } + else + { + ret_leftCornerWhere = 0; /*on left chain*/ + ret_leftCornerIndex = index1; + } + } + } +#ifdef MYDEBUG +printf("***********leave findUpCorners\n"); +#endif +} + +//return 1 if neck exists, 0 othewise +Int findNeckF(vertexArray *leftChain, Int botLeftIndex, + vertexArray *rightChain, Int botRightIndex, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridStartIndex, + Int& neckLeft, + Int& neckRight) +{ +/* +printf("enter findNeckF, botleft, botright=%i,%i,gstartindex=%i\n",botLeftIndex,botRightIndex,gridStartIndex); +printf("leftChain is\n"); +leftChain->print(); +printf("rightChain is\n"); +rightChain->print(); +*/ + + Int lowerGridIndex; //the grid below leftChain and rightChian vertices + Int i; + Int n_vlines = leftGridChain->get_nVlines(); + Real v; + if(botLeftIndex >= leftChain->getNumElements() || + botRightIndex >= rightChain->getNumElements()) + return 0; //no neck exists + + v=min(leftChain->getVertex(botLeftIndex)[1], rightChain->getVertex(botRightIndex)[1]); + + + + + for(i=gridStartIndex; iget_v_value(i) <= v && + leftGridChain->getUlineIndex(i)<= rightGridChain->getUlineIndex(i)) + break; + + lowerGridIndex = i; + + if(lowerGridIndex == n_vlines) //the two trm vertex are higher than all gridlines + return 0; + else + { + Int botLeft2, botRight2; +/* +printf("leftGridChain->get_v_)value=%f\n",leftGridChain->get_v_value(lowerGridIndex), botLeftIndex); +printf("leftChain->get_vertex(0)=(%f,%f)\n", leftChain->getVertex(0)[0],leftChain->getVertex(0)[1]); +printf("leftChain->get_vertex(1)=(%f,%f)\n", leftChain->getVertex(1)[0],leftChain->getVertex(1)[1]); +printf("leftChain->get_vertex(2)=(%f,%f)\n", leftChain->getVertex(2)[0],leftChain->getVertex(2)[1]); +*/ + botLeft2 = leftChain->findIndexFirstAboveEqualGen(leftGridChain->get_v_value(lowerGridIndex), botLeftIndex, leftChain->getNumElements()-1) -1 ; + +/* +printf("botLeft2=%i\n", botLeft2); +printf("leftChain->getNumElements=%i\n", leftChain->getNumElements()); +*/ + + botRight2 = rightChain->findIndexFirstAboveEqualGen(leftGridChain->get_v_value(lowerGridIndex), botRightIndex, rightChain->getNumElements()-1) -1; + if(botRight2 < botRightIndex) botRight2=botRightIndex; + + if(botLeft2 < botLeftIndex) botLeft2 = botLeftIndex; + + assert(botLeft2 >= botLeftIndex); + assert(botRight2 >= botRightIndex); + //find nectLeft so that it is th erightmost vertex on letChain + + Int tempI = botLeftIndex; + Real temp = leftChain->getVertex(tempI)[0]; + for(i=botLeftIndex+1; i<= botLeft2; i++) + if(leftChain->getVertex(i)[0] > temp) + { + temp = leftChain->getVertex(i)[0]; + tempI = i; + } + neckLeft = tempI; + + tempI = botRightIndex; + temp = rightChain->getVertex(tempI)[0]; + for(i=botRightIndex+1; i<= botRight2; i++) + if(rightChain->getVertex(i)[0] < temp) + { + temp = rightChain->getVertex(i)[0]; + tempI = i; + } + neckRight = tempI; + return 1; + } +} + + + +/*find i>=botLeftIndex,j>=botRightIndex so that + *(leftChain[i], rightChain[j]) is a neck. + */ +void findNeck(vertexArray *leftChain, Int botLeftIndex, + vertexArray *rightChain, Int botRightIndex, + Int& leftLastIndex, /*left point of the neck*/ + Int& rightLastIndex /*right point of the neck*/ + ) +{ + assert(botLeftIndex < leftChain->getNumElements() && + botRightIndex < rightChain->getNumElements()); + + /*now the neck exists for sure*/ + + if(leftChain->getVertex(botLeftIndex)[1] <= rightChain->getVertex(botRightIndex)[1]) //left below right + { + + leftLastIndex = botLeftIndex; + + /*find i so that rightChain[i][1] >= leftchainbotverte[1], and i+1< + */ + rightLastIndex=rightChain->findIndexAboveGen(leftChain->getVertex(botLeftIndex)[1], botRightIndex+1, rightChain->getNumElements()-1); + } + else //left above right + { + + rightLastIndex = botRightIndex; + + leftLastIndex = leftChain->findIndexAboveGen(rightChain->getVertex(botRightIndex)[1], + botLeftIndex+1, + leftChain->getNumElements()-1); + } +} + + + +void findLeftGridIndices(directedLine* topEdge, Int firstGridIndex, Int lastGridIndex, gridWrap* grid, Int* ret_indices, Int* ret_innerIndices) +{ + + Int i,k,isHoriz = 0; + Int n_ulines = grid->get_n_ulines(); + Real uMin = grid->get_u_min(); + Real uMax = grid->get_u_max(); + /* + Real vMin = grid->get_v_min(); + Real vMax = grid->get_v_max(); + */ + Real slop = 0.0, uinterc; + +#ifdef SHORTEN_GRID_LINE + //uintercBuf stores all the interction u value for each grid line + //notice that lastGridIndex<= firstGridIndex + Real *uintercBuf = (Real *) malloc (sizeof(Real) * (firstGridIndex-lastGridIndex+1)); + assert(uintercBuf); +#endif + + /*initialization to make vtail bigger than grid->...*/ + directedLine* dLine = topEdge; + Real vtail = grid->get_v_value(firstGridIndex) + 1.0; + Real tempMaxU = grid->get_u_min(); + + + /*for each grid line*/ + for(k=0, i=firstGridIndex; i>=lastGridIndex; i--, k++) + { + + Real grid_v_value = grid->get_v_value(i); + + /*check whether this grid line is below the current trim edge.*/ + if(vtail > grid_v_value) + { + /*since the grid line is below the trim edge, we + *find the trim edge which will contain the trim line + */ + while( (vtail=dLine->tail()[1]) > grid_v_value){ + + tempMaxU = max(tempMaxU, dLine->tail()[0]); + dLine = dLine -> getNext(); + } + + if( fabs(dLine->head()[1] - vtail) < ZERO) + isHoriz = 1; + else + { + isHoriz = 0; + slop = (dLine->head()[0] - dLine->tail()[0]) / (dLine->head()[1]-vtail); + } + } + + if(isHoriz) + { + uinterc = max(dLine->head()[0], dLine->tail()[0]); + } + else + { + uinterc = slop * (grid_v_value - vtail) + dLine->tail()[0]; + } + + tempMaxU = max(tempMaxU, uinterc); + + if(uinterc < uMin && uinterc >= uMin - ZERO) + uinterc = uMin; + if(uinterc > uMax && uinterc <= uMax + ZERO) + uinterc = uMax; + +#ifdef SHORTEN_GRID_LINE + uintercBuf[k] = uinterc; +#endif + + assert(uinterc >= uMin && uinterc <= uMax); + if(uinterc == uMax) + ret_indices[k] = n_ulines-1; + else + ret_indices[k] = (Int)(((uinterc-uMin)/(uMax - uMin)) * (n_ulines-1)) + 1; + if(ret_indices[k] >= n_ulines) + ret_indices[k] = n_ulines-1; + + + ret_innerIndices[k] = (Int)(((tempMaxU-uMin)/(uMax - uMin)) * (n_ulines-1)) + 1; + + /*reinitialize tempMaxU for next grdiLine*/ + tempMaxU = uinterc; + } +#ifdef SHORTEN_GRID_LINE + //for each grid line, compare the left grid point with the + //intersection point. If the two points are too close, then + //we should move the grid point one grid to the right + //and accordingly we should update the inner index. + for(k=0, i=firstGridIndex; i>=lastGridIndex; i--, k++) + { + //check gridLine i + //check ret_indices[k] + Real a = grid->get_u_value(ret_indices[k]-1); + Real b = grid->get_u_value(ret_indices[k]); + assert(uintercBuf[k] >= a && uintercBuf < b); + if( (b-uintercBuf[k]) <= 0.2 * (b-a)) //interc is very close to b + { + ret_indices[k]++; + } + + //check ret_innerIndices[k] + if(k>0) + { + if(ret_innerIndices[k] < ret_indices[k-1]) + ret_innerIndices[k] = ret_indices[k-1]; + if(ret_innerIndices[k] < ret_indices[k]) + ret_innerIndices[k] = ret_indices[k]; + } + } + //clean up + free(uintercBuf); +#endif +} + +void findRightGridIndices(directedLine* topEdge, Int firstGridIndex, Int lastGridIndex, gridWrap* grid, Int* ret_indices, Int* ret_innerIndices) +{ + + Int i,k; + Int n_ulines = grid->get_n_ulines(); + Real uMin = grid->get_u_min(); + Real uMax = grid->get_u_max(); + /* + Real vMin = grid->get_v_min(); + Real vMax = grid->get_v_max(); + */ + Real slop = 0.0, uinterc; + +#ifdef SHORTEN_GRID_LINE + //uintercBuf stores all the interction u value for each grid line + //notice that firstGridIndex >= lastGridIndex + Real *uintercBuf = (Real *) malloc (sizeof(Real) * (firstGridIndex-lastGridIndex+1)); + assert(uintercBuf); +#endif + + /*initialization to make vhead bigger than grid->v_value...*/ + directedLine* dLine = topEdge->getPrev(); + Real vhead = dLine->tail()[1]; + Real tempMinU = grid->get_u_max(); + + /*for each grid line*/ + for(k=0, i=firstGridIndex; i>=lastGridIndex; i--, k++) + { + + Real grid_v_value = grid->get_v_value(i); + + + /*check whether this grid line is below the current trim edge.*/ + if(vhead >= grid_v_value) + { + /*since the grid line is below the tail of the trim edge, we + *find the trim edge which will contain the trim line + */ + while( (vhead=dLine->head()[1]) > grid_v_value){ + tempMinU = min(tempMinU, dLine->head()[0]); + dLine = dLine -> getPrev(); + } + + /*skip the equality in the case of degenerat case: horizontal */ + while(dLine->head()[1] == grid_v_value) + dLine = dLine->getPrev(); + + assert( dLine->tail()[1] != dLine->head()[1]); + slop = (dLine->tail()[0] - dLine->head()[0]) / (dLine->tail()[1]-dLine->head()[1]); + /* + if(dLine->tail()[1] == vhead) + isHoriz = 1; + else + { + isHoriz = 0; + slop = (dLine->tail()[0] - dLine->head()[0]) / (dLine->tail()[1]-vhead); + } + */ + } + uinterc = slop * (grid_v_value - dLine->head()[1]) + dLine->head()[0]; + + //in case unterc is outside of the grid due to floating point + if(uinterc < uMin) + uinterc = uMin; + else if(uinterc > uMax) + uinterc = uMax; + +#ifdef SHORTEN_GRID_LINE + uintercBuf[k] = uinterc; +#endif + + tempMinU = min(tempMinU, uinterc); + + assert(uinterc >= uMin && uinterc <= uMax); + + if(uinterc == uMin) + ret_indices[k] = 0; + else + ret_indices[k] = (int)ceil((((uinterc-uMin)/(uMax - uMin)) * (n_ulines-1))) -1; +/* +if(ret_indices[k] >= grid->get_n_ulines()) + { + printf("ERROR3\n"); + exit(0); +} +if(ret_indices[k] < 0) + { + printf("ERROR4\n"); + exit(0); +} +*/ + ret_innerIndices[k] = (int)ceil ((((tempMinU-uMin)/(uMax - uMin)) * (n_ulines-1))) -1; + + tempMinU = uinterc; + } +#ifdef SHORTEN_GRID_LINE + //for each grid line, compare the left grid point with the + //intersection point. If the two points are too close, then + //we should move the grid point one grid to the right + //and accordingly we should update the inner index. + for(k=0, i=firstGridIndex; i>=lastGridIndex; i--, k++) + { + //check gridLine i + //check ret_indices[k] + Real a = grid->get_u_value(ret_indices[k]); + Real b = grid->get_u_value(ret_indices[k]+1); + assert(uintercBuf[k] > a && uintercBuf <= b); + if( (uintercBuf[k]-a) <= 0.2 * (b-a)) //interc is very close to a + { + ret_indices[k]--; + } + + //check ret_innerIndices[k] + if(k>0) + { + if(ret_innerIndices[k] > ret_indices[k-1]) + ret_innerIndices[k] = ret_indices[k-1]; + if(ret_innerIndices[k] > ret_indices[k]) + ret_innerIndices[k] = ret_indices[k]; + } + } + //clean up + free(uintercBuf); +#endif +} + + +void sampleMonoPoly(directedLine* polygon, gridWrap* grid, Int ulinear, Int vlinear, primStream* pStream, rectBlockArray* rbArray) +{ +/* +{ +grid->print(); +polygon->writeAllPolygons("zloutputFile"); +exit(0); +} +*/ + +if(grid->get_n_ulines() == 2 || + grid->get_n_vlines() == 2) +{ + if(ulinear && grid->get_n_ulines() == 2) + { + monoTriangulationFun(polygon, compV2InY, pStream); + return; + } + else if(DBG_isConvex(polygon) && polygon->numEdges() >=4) + { + triangulateConvexPoly(polygon, ulinear, vlinear, pStream); + return; + } + else if(vlinear || DBG_is_U_direction(polygon)) + { + Int n_cusps;//num interior cusps + Int n_edges = polygon->numEdges(); + directedLine** cusps = (directedLine**) malloc(sizeof(directedLine*) * n_edges); + assert(cusps); + findInteriorCuspsX(polygon, n_cusps, cusps); + + if(n_cusps == 0) //u_monotone + { + + monoTriangulationFun(polygon, compV2InX, pStream); + + free(cusps); + return; + } + else if(n_cusps == 1) //one interior cusp + { + + directedLine* new_polygon = polygonConvert(cusps[0]); + + directedLine* other = findDiagonal_singleCuspX( new_polygon); + + + + // should NOT be null unless there are self-intersecting + //trim curves. In that case, we don't want to core dump, instead, + //we triangulate anyway, and print out error message. + if(other == NULL) + { + monoTriangulationFun(polygon, compV2InX, pStream); + free(cusps); + return; + } + + directedLine* ret_p1; + directedLine* ret_p2; + + new_polygon->connectDiagonal_2slines(new_polygon, other, + &ret_p1, + &ret_p2, + new_polygon); + + monoTriangulationFun(ret_p1, compV2InX, pStream); + monoTriangulationFun(ret_p2, compV2InX, pStream); + + ret_p1->deleteSinglePolygonWithSline(); + ret_p2->deleteSinglePolygonWithSline(); + + free(cusps); + return; + } + free(cusps); + } +} + + /*find the top and bottom of the polygon. It is supposed to be + *a V-monotone polygon + */ + + directedLine* tempV; + directedLine* topV; + directedLine* botV; + topV = botV = polygon; + + for(tempV = polygon->getNext(); tempV != polygon; tempV = tempV->getNext()) + { + if(compV2InY(topV->head(), tempV->head())<0) { + + topV = tempV; + } + if(compV2InY(botV->head(), tempV->head())>0) { + + botV = tempV; + } + } + + /*find the first(top) and the last (bottom) grid line which intersect the + *this polygon + */ + Int firstGridIndex; /*the index in the grid*/ + Int lastGridIndex; + firstGridIndex = (Int) ((topV->head()[1] - grid->get_v_min()) / (grid->get_v_max() - grid->get_v_min()) * (grid->get_n_vlines()-1)); + lastGridIndex = (Int) ((botV->head()[1] - grid->get_v_min()) / (grid->get_v_max() - grid->get_v_min()) * (grid->get_n_vlines()-1)) + 1; + + + /*find the interval inside the polygon for each gridline*/ + Int *leftGridIndices = (Int*) malloc(sizeof(Int) * (firstGridIndex - lastGridIndex +1)); + assert(leftGridIndices); + Int *rightGridIndices = (Int*) malloc(sizeof(Int) * (firstGridIndex - lastGridIndex +1)); + assert(rightGridIndices); + Int *leftGridInnerIndices = (Int*) malloc(sizeof(Int) * (firstGridIndex - lastGridIndex +1)); + assert(leftGridInnerIndices); + Int *rightGridInnerIndices = (Int*) malloc(sizeof(Int) * (firstGridIndex - lastGridIndex +1)); + assert(rightGridInnerIndices); + + findLeftGridIndices(topV, firstGridIndex, lastGridIndex, grid, leftGridIndices, leftGridInnerIndices); + + findRightGridIndices(topV, firstGridIndex, lastGridIndex, grid, rightGridIndices, rightGridInnerIndices); + + gridBoundaryChain leftGridChain(grid, firstGridIndex, firstGridIndex-lastGridIndex+1, leftGridIndices, leftGridInnerIndices); + + gridBoundaryChain rightGridChain(grid, firstGridIndex, firstGridIndex-lastGridIndex+1, rightGridIndices, rightGridInnerIndices); + + + +// leftGridChain.draw(); +// leftGridChain.drawInner(); +// rightGridChain.draw(); +// rightGridChain.drawInner(); + /*(1) determine the grid boundaries (left and right). + *(2) process polygon into two monotone chaines: use vertexArray + *(3) call sampleMonoPolyRec + */ + + /*copy the two chains into vertexArray datastructure*/ + Int i; + vertexArray leftChain(20); /*this is a dynamic array*/ + for(i=1; i<=topV->get_npoints()-2; i++) { /*the first vertex is the top vertex which doesn't belong to inc_chain*/ + leftChain.appendVertex(topV->getVertex(i)); + } + for(tempV = topV->getNext(); tempV != botV; tempV = tempV->getNext()) + { + for(i=0; i<=tempV->get_npoints()-2; i++){ + leftChain.appendVertex(tempV->getVertex(i)); + } + } + + vertexArray rightChain(20); + for(tempV = topV->getPrev(); tempV != botV; tempV = tempV->getPrev()) + { + for(i=tempV->get_npoints()-2; i>=0; i--){ + rightChain.appendVertex(tempV->getVertex(i)); + } + } + for(i=botV->get_npoints()-2; i>=1; i--){ + rightChain.appendVertex(tempV->getVertex(i)); + } + + sampleMonoPolyRec(topV->head(), + botV->head(), + &leftChain, + 0, + &rightChain, + 0, + &leftGridChain, + &rightGridChain, + 0, + pStream, + rbArray); + + + /*cleanup space*/ + free(leftGridIndices); + free(rightGridIndices); + free(leftGridInnerIndices); + free(rightGridInnerIndices); +} + +void sampleMonoPolyRec( + Real* topVertex, + Real* botVertex, + vertexArray* leftChain, + Int leftStartIndex, + vertexArray* rightChain, + Int rightStartIndex, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridStartIndex, + primStream* pStream, + rectBlockArray* rbArray) +{ + + /*find the first connected component, and the four corners. + */ + Int index1, index2; /*the first and last grid line of the first connected component*/ + + if(topVertex[1] <= botVertex[1]) + return; + + /*find i so that the grid line is below the top vertex*/ + Int i=gridStartIndex; + while (i < leftGridChain->get_nVlines()) + { + if(leftGridChain->get_v_value(i) < topVertex[1]) + break; + i++; + } + + /*find the first connected component starting with i*/ + /*find index1 so that left_uline_index <= right_uline_index, that is, this + *grid line contains at least one inner grid point + */ + index1=i; + int num_skipped_grid_lines=0; + while(index1 < leftGridChain->get_nVlines()) + { + if(leftGridChain->getUlineIndex(index1) <= rightGridChain->getUlineIndex(index1)) + break; + num_skipped_grid_lines++; + index1++; + } + + + + if(index1 >= leftGridChain->get_nVlines()) /*no grid line exists which has inner point*/ + { + /*stop recursion, ...*/ + /*monotone triangulate it...*/ +// printf("no grid line exists\n"); +/* + monoTriangulationRecOpt(topVertex, botVertex, leftChain, leftStartIndex, + rightChain, rightStartIndex, pStream); +*/ + +if(num_skipped_grid_lines <2) + { + monoTriangulationRecGenOpt(topVertex, botVertex, leftChain, leftStartIndex, + leftChain->getNumElements()-1, + rightChain, rightStartIndex, + rightChain->getNumElements()-1, + pStream); + } +else + { + //the optimum way to triangulate is top-down since this polygon + //is narrow-long. + monoTriangulationRec(topVertex, botVertex, leftChain, leftStartIndex, + rightChain, rightStartIndex, pStream); + } + +/* + monoTriangulationRec(topVertex, botVertex, leftChain, leftStartIndex, + rightChain, rightStartIndex, pStream); +*/ + +/* monoTriangulationRecGenTBOpt(topVertex, botVertex, + leftChain, leftStartIndex, leftChain->getNumElements()-1, + rightChain, rightStartIndex, rightChain->getNumElements()-1, + pStream);*/ + + + + } + else + { + + /*find index2 so that left_inner_index <= right_inner_index holds until index2*/ + index2=index1+1; + if(index2 < leftGridChain->get_nVlines()) + while(leftGridChain->getInnerIndex(index2) <= rightGridChain->getInnerIndex(index2)) + { + index2++; + if(index2 >= leftGridChain->get_nVlines()) + break; + } + + index2--; + + + + /*the neck*/ + Int neckLeftIndex; + Int neckRightIndex; + + /*the four corners*/ + Int up_leftCornerWhere; + Int up_leftCornerIndex; + Int up_rightCornerWhere; + Int up_rightCornerIndex; + Int down_leftCornerWhere; + Int down_leftCornerIndex; + Int down_rightCornerWhere; + Int down_rightCornerIndex; + + Real* tempBotVertex; /*the bottom vertex for this component*/ + Real* nextTopVertex=NULL; /*for the recursion*/ + Int nextLeftStartIndex=0; + Int nextRightStartIndex=0; + + /*find the points below the grid line index2 on both chains*/ + Int botLeftIndex = leftChain->findIndexStrictBelowGen( + leftGridChain->get_v_value(index2), + leftStartIndex, + leftChain->getNumElements()-1); + Int botRightIndex = rightChain->findIndexStrictBelowGen( + rightGridChain->get_v_value(index2), + rightStartIndex, + rightChain->getNumElements()-1); + /*if either botLeftIndex>= numelements, + * or botRightIndex >= numelemnet, + *then there is no neck exists. the bottom vertex is botVertex, + */ + if(! findNeckF(leftChain, botLeftIndex, rightChain, botRightIndex, + leftGridChain, rightGridChain, index2, neckLeftIndex, neckRightIndex)) + /* + if(botLeftIndex == leftChain->getNumElements() || + botRightIndex == rightChain->getNumElements()) + */ + { +#ifdef MYDEBUG + printf("neck NOT exists, botRightIndex=%i\n", botRightIndex); +#endif + + tempBotVertex = botVertex; + nextTopVertex = botVertex; + botLeftIndex = leftChain->getNumElements()-1; + botRightIndex = rightChain->getNumElements()-1; + } + else /*neck exists*/ + { +#ifdef MYDEBUG + printf("neck exists\n"); +#endif + + /* + findNeck(leftChain, botLeftIndex, + rightChain, botRightIndex, + neckLeftIndex, + neckRightIndex); + */ +#ifdef MYDEBUG +printf("neck is found, neckLeftIndex=%i, neckRightIndex=%i\n", neckLeftIndex, neckRightIndex); +glBegin(GL_LINES); +glVertex2fv(leftChain->getVertex(neckLeftIndex)); +glVertex2fv(rightChain->getVertex(neckRightIndex)); +glEnd(); +#endif + + if(leftChain->getVertex(neckLeftIndex)[1] <= rightChain->getVertex(neckRightIndex)[1]) + { + tempBotVertex = leftChain->getVertex(neckLeftIndex); + botLeftIndex = neckLeftIndex-1; + botRightIndex = neckRightIndex; + nextTopVertex = rightChain->getVertex(neckRightIndex); + nextLeftStartIndex = neckLeftIndex; + nextRightStartIndex = neckRightIndex+1; + } + else + { + tempBotVertex = rightChain->getVertex(neckRightIndex); + botLeftIndex = neckLeftIndex; + botRightIndex = neckRightIndex-1; + nextTopVertex = leftChain->getVertex(neckLeftIndex); + nextLeftStartIndex = neckLeftIndex+1; + nextRightStartIndex = neckRightIndex; + } + } + + findUpCorners(topVertex, + leftChain, + leftStartIndex, botLeftIndex, + rightChain, + rightStartIndex, botRightIndex, + leftGridChain->get_v_value(index1), + leftGridChain->get_u_value(index1), + rightGridChain->get_u_value(index1), + up_leftCornerWhere, + up_leftCornerIndex, + up_rightCornerWhere, + up_rightCornerIndex); + + findDownCorners(tempBotVertex, + leftChain, + leftStartIndex, botLeftIndex, + rightChain, + rightStartIndex, botRightIndex, + leftGridChain->get_v_value(index2), + leftGridChain->get_u_value(index2), + rightGridChain->get_u_value(index2), + down_leftCornerWhere, + down_leftCornerIndex, + down_rightCornerWhere, + down_rightCornerIndex); +#ifdef MYDEBUG + printf("find corners done, down_leftwhere=%i, down_righwhere=%i,\n",down_leftCornerWhere, down_rightCornerWhere ); + printf("find corners done, up_leftwhere=%i, up_righwhere=%i,\n",up_leftCornerWhere, up_rightCornerWhere ); + printf("find corners done, up_leftindex=%i, up_righindex=%i,\n",up_leftCornerIndex, up_rightCornerIndex ); + printf("find corners done, down_leftindex=%i, down_righindex=%i,\n",down_leftCornerIndex, down_rightCornerIndex ); +#endif + +/* + drawCorners(topVertex, + tempBotVertex, + leftChain, + rightChain, + leftGridChain, + rightGridChain, + index1, + index2, + up_leftCornerWhere, + up_leftCornerIndex, + up_rightCornerWhere, + up_rightCornerIndex, + down_leftCornerWhere, + down_leftCornerIndex, + down_rightCornerWhere, + down_rightCornerIndex); +*/ + + + sampleConnectedComp(topVertex, tempBotVertex, + leftChain, + leftStartIndex, botLeftIndex, + rightChain, + rightStartIndex, botRightIndex, + leftGridChain, + rightGridChain, + index1, index2, + up_leftCornerWhere, + up_leftCornerIndex, + up_rightCornerWhere, + up_rightCornerIndex, + down_leftCornerWhere, + down_leftCornerIndex, + down_rightCornerWhere, + down_rightCornerIndex, + pStream, + rbArray + ); + + /*recursion*/ + + sampleMonoPolyRec( + nextTopVertex, + botVertex, + leftChain, + nextLeftStartIndex, + rightChain, + nextRightStartIndex, + leftGridChain, + rightGridChain, + index2+1, + pStream, rbArray); + + + } + +} + +void sampleLeftStrip(vertexArray* leftChain, + Int topLeftIndex, + Int botLeftIndex, + gridBoundaryChain* leftGridChain, + Int leftGridChainStartIndex, + Int leftGridChainEndIndex, + primStream* pStream + ) +{ + assert(leftChain->getVertex(topLeftIndex)[1] > leftGridChain->get_v_value(leftGridChainStartIndex)); + assert(leftChain->getVertex(topLeftIndex+1)[1] <= leftGridChain->get_v_value(leftGridChainStartIndex)); + assert(leftChain->getVertex(botLeftIndex)[1] <= leftGridChain->get_v_value(leftGridChainEndIndex)); + assert(leftChain->getVertex(botLeftIndex-1)[1] > leftGridChain->get_v_value(leftGridChainEndIndex)); + + /* + *(1)find the last grid line which doesn'; pass below + * this first edge, sample this region: one trim edge and + * possily multiple grid lines. + */ + Real *upperVert, *lowerVert; /*the end points of the first trim edge*/ + upperVert = leftChain->getVertex(topLeftIndex); + lowerVert = leftChain->getVertex(topLeftIndex+1); + + Int index = leftGridChainStartIndex; + while(leftGridChain->get_v_value(index) >= lowerVert[1]){ + index++; + if(index > leftGridChainEndIndex) + break; + } + index--; + + sampleLeftSingleTrimEdgeRegion(upperVert, lowerVert, + leftGridChain, + leftGridChainStartIndex, + index, + pStream); + sampleLeftStripRec(leftChain, topLeftIndex+1, botLeftIndex, + leftGridChain, index, leftGridChainEndIndex, + pStream); + +} + +void sampleLeftStripRec(vertexArray* leftChain, + Int topLeftIndex, + Int botLeftIndex, + gridBoundaryChain* leftGridChain, + Int leftGridChainStartIndex, + Int leftGridChainEndIndex, + primStream* pStream + ) +{ + /*now top left trim vertex is below the top grid line. + */ + /*stop condition: if topLeftIndex >= botLeftIndex, then stop. + */ + if(topLeftIndex >= botLeftIndex) + return; + + /*find the last trim vertex which is above the second top grid line: + * index1. + *and sampleLeftOneGridStep(leftchain, topLeftIndex, index1, leftGridChain, + * leftGridChainStartIndex). + * index1 could be equal to topLeftIndex. + */ + Real secondGridChainV = leftGridChain->get_v_value(leftGridChainStartIndex+1); + assert(leftGridChainStartIndex < leftGridChainEndIndex); + Int index1 = topLeftIndex; + while(leftChain->getVertex(index1)[1] > secondGridChainV) + index1++; + index1--; + + sampleLeftOneGridStep(leftChain, topLeftIndex, index1, leftGridChain, leftGridChainStartIndex, pStream); + + + /* + * Let the next trim vertex be nextTrimVertIndex (which should be + * below the second grid line). + * Find the last grid line index2 which is above nextTrimVert. + * sampleLeftSingleTrimEdgeRegion(uppervert[2], lowervert[2], + * leftGridChain, leftGridChainStartIndex+1, index2). + */ + Real *uppervert, *lowervert; + uppervert = leftChain->getVertex(index1); + lowervert = leftChain->getVertex(index1+1); + Int index2 = leftGridChainStartIndex+1; + + while(leftGridChain->get_v_value(index2) >= lowervert[1]) + { + index2++; + if(index2 > leftGridChainEndIndex) + break; + } + index2--; + sampleLeftSingleTrimEdgeRegion(uppervert, lowervert, leftGridChain, leftGridChainStartIndex+1, index2, pStream); + + /* sampleLeftStripRec(leftChain, + nextTrimVertIndex, + botLeftIndex, + leftGridChain, + index2, + leftGridChainEndIndex + ) + * + */ + sampleLeftStripRec(leftChain, index1+1, botLeftIndex, leftGridChain, index2, leftGridChainEndIndex, pStream); + +} + + +/***************begin RecF***********************/ +/* the gridlines from leftGridChainStartIndex to + * leftGridChainEndIndex are assumed to form a + * connected component. + * the trim vertex of topLeftIndex is assumed to + * be below the first gridline, and the tim vertex + * of botLeftIndex is assumed to be above the last + * grid line. + * If botLeftIndex < topLeftIndex, then no connected componeent exists, and this funcion returns without + * outputing any triangles. + * Otherwise botLeftIndex >= topLeftIndex, there is at least one triangle to output. + */ +void sampleLeftStripRecF(vertexArray* leftChain, + Int topLeftIndex, + Int botLeftIndex, + gridBoundaryChain* leftGridChain, + Int leftGridChainStartIndex, + Int leftGridChainEndIndex, + primStream* pStream + ) +{ + /*now top left trim vertex is below the top grid line. + */ + /*stop condition: if topLeftIndex > botLeftIndex, then stop. + */ + if(topLeftIndex > botLeftIndex) + return; + + /*if there is only one grid Line, return.*/ + + if(leftGridChainStartIndex>=leftGridChainEndIndex) + return; + + + assert(leftChain->getVertex(topLeftIndex)[1] <= leftGridChain->get_v_value(leftGridChainStartIndex) && + leftChain->getVertex(botLeftIndex)[1] >= leftGridChain->get_v_value(leftGridChainEndIndex)); + + /*firs find the first trim vertex which is below or equal to the second top grid line: + * index1. + */ + Real secondGridChainV = leftGridChain->get_v_value(leftGridChainStartIndex+1); + + + Int index1 = topLeftIndex; + + while(leftChain->getVertex(index1)[1] > secondGridChainV){ + index1++; + if(index1>botLeftIndex) + break; + } + + /*now leftChain->getVertex(index-1)[1] > secondGridChainV and + * leftChain->getVertex(index)[1] <= secondGridChainV + *If equality holds, then we should include the vertex index1, otherwise we include only index1-1, to + *perform sampleOneGridStep. + */ + if(index1>botLeftIndex) + index1--; + else if(leftChain->getVertex(index1)[1] < secondGridChainV) + index1--; + + /*now we have leftChain->getVertex(index1)[1] >= secondGridChainV, and + * leftChain->getVertex(index1+1)[1] <= secondGridChainV + */ + + + sampleLeftOneGridStep(leftChain, topLeftIndex, index1, leftGridChain, leftGridChainStartIndex, pStream); + + + /*if leftChain->getVertex(index1)[1] == secondGridChainV, then we can recursively do the rest. + */ + if(leftChain->getVertex(index1)[1] == secondGridChainV) + { + + sampleLeftStripRecF(leftChain, index1, botLeftIndex,leftGridChain, leftGridChainStartIndex+1, leftGridChainEndIndex, pStream); + } + else if(index1 < botLeftIndex) + { + + /* Otherwise, we have leftChain->getVertex(index1)[1] > secondGridChainV, + * let the next trim vertex be nextTrimVertIndex (which should be strictly + * below the second grid line). + * Find the last grid line index2 which is above nextTrimVert. + * sampleLeftSingleTrimEdgeRegion(uppervert[2], lowervert[2], + * leftGridChain, leftGridChainStartIndex+1, index2). + */ + Real *uppervert, *lowervert; + uppervert = leftChain->getVertex(index1); + lowervert = leftChain->getVertex(index1+1); //okay since index1get_v_value(index2) >= lowervert[1]) + { + index2++; + if(index2 > leftGridChainEndIndex) + break; + } + index2--; + + + sampleLeftSingleTrimEdgeRegion(uppervert, lowervert, leftGridChain, leftGridChainStartIndex+1, index2, pStream); + + /*recursion*/ + + sampleLeftStripRecF(leftChain, index1+1, botLeftIndex, leftGridChain, index2, leftGridChainEndIndex, pStream); + } + +} + +/***************End RecF***********************/ + +/*sample the left area in between one trim edge and multiple grid lines. + * all the grid lines should be in between the two end poins of the + *trim edge. + */ +void sampleLeftSingleTrimEdgeRegion(Real upperVert[2], Real lowerVert[2], + gridBoundaryChain* gridChain, + Int beginIndex, + Int endIndex, + primStream* pStream) +{ + Int i,j,k; + + vertexArray vArray(endIndex-beginIndex+1); + vArray.appendVertex(gridChain->get_vertex(beginIndex)); + + for(k=1, i=beginIndex+1; i<=endIndex; i++, k++) + { + vArray.appendVertex(gridChain->get_vertex(i)); + + /*output the fan of the grid points of the (i)th and (i-1)th grid line. + */ + if(gridChain->getUlineIndex(i) < gridChain->getUlineIndex(i-1)) + { + pStream->begin(); + pStream->insert(gridChain->get_vertex(i-1)); + for(j=gridChain->getUlineIndex(i); j<= gridChain->getUlineIndex(i-1); j++) + pStream->insert(gridChain->getGrid()->get_u_value(j), gridChain->get_v_value(i)); + pStream->end(PRIMITIVE_STREAM_FAN); + } + else if(gridChain->getUlineIndex(i) > gridChain->getUlineIndex(i-1)) + { + pStream->begin(); + pStream->insert(gridChain->get_vertex(i)); + for(j=gridChain->getUlineIndex(i); j>= gridChain->getUlineIndex(i-1); j--) + pStream->insert(gridChain->getGrid()->get_u_value(j), gridChain->get_v_value(i-1)); + pStream->end(PRIMITIVE_STREAM_FAN); + } + /*otherwisem, the two are equal, so there is no fan to outout*/ + } + + monoTriangulation2(upperVert, lowerVert, &vArray, 0, endIndex-beginIndex, + 0, /*decreasing chain*/ + pStream); +} + +/*return i, such that from begin to i-1 the chain is strictly u-monotone. + */ +Int findIncreaseChainFromBegin(vertexArray* chain, Int begin ,Int end) +{ + Int i=begin; + Real prevU = chain->getVertex(i)[0]; + Real thisU; + for(i=begin+1; i<=end; i++){ + thisU = chain->getVertex(i)[0]; + + if(prevU < thisU){ + prevU = thisU; + } + else + break; + } + return i; +} + +/*check whether there is a vertex whose v value is strictly + *inbetween vup vbelow + *if no middle exists return -1, else return the idnex. + */ +Int checkMiddle(vertexArray* chain, Int begin, Int end, + Real vup, Real vbelow) +{ + Int i; + for(i=begin; i<=end; i++) + { + if(chain->getVertex(i)[1] < vup && chain->getVertex(i)[1]>vbelow) + return i; + } + return -1; +} + +/*the degenerat case of sampleLeftOneGridStep*/ +void sampleLeftOneGridStepNoMiddle(vertexArray* leftChain, + Int beginLeftIndex, + Int endLeftIndex, + gridBoundaryChain* leftGridChain, + Int leftGridChainStartIndex, + primStream* pStream) +{ + /*since there is no middle, there is at most one point which is on the + *second grid line, there could be multiple points on the first (top) + *grid line. + */ + + leftGridChain->leftEndFan(leftGridChainStartIndex+1, pStream); + + monoTriangulation2(leftGridChain->get_vertex(leftGridChainStartIndex), + leftGridChain->get_vertex(leftGridChainStartIndex+1), + leftChain, + beginLeftIndex, + endLeftIndex, + 1, //is increase chain. + pStream); +} + + + +/*sampling the left area in between two grid lines. + */ +void sampleLeftOneGridStep(vertexArray* leftChain, + Int beginLeftIndex, + Int endLeftIndex, + gridBoundaryChain* leftGridChain, + Int leftGridChainStartIndex, + primStream* pStream + ) +{ + if(checkMiddle(leftChain, beginLeftIndex, endLeftIndex, + leftGridChain->get_v_value(leftGridChainStartIndex), + leftGridChain->get_v_value(leftGridChainStartIndex+1))<0) + + { + + sampleLeftOneGridStepNoMiddle(leftChain, beginLeftIndex, endLeftIndex, leftGridChain, leftGridChainStartIndex, pStream); + return; + } + + //copy into a polygon + { + directedLine* poly = NULL; + sampledLine* sline; + directedLine* dline; + gridWrap* grid = leftGridChain->getGrid(); + Real vert1[2]; + Real vert2[2]; + Int i; + + Int innerInd = leftGridChain->getInnerIndex(leftGridChainStartIndex+1); + Int upperInd = leftGridChain->getUlineIndex(leftGridChainStartIndex); + Int lowerInd = leftGridChain->getUlineIndex(leftGridChainStartIndex+1); + Real upperV = leftGridChain->get_v_value(leftGridChainStartIndex); + Real lowerV = leftGridChain->get_v_value(leftGridChainStartIndex+1); + + //the upper gridline + vert1[1] = vert2[1] = upperV; + for(i=innerInd; i>upperInd; i--) + { + vert1[0]=grid->get_u_value(i); + vert2[0]=grid->get_u_value(i-1); + sline = new sampledLine(vert1, vert2); + dline = new directedLine(INCREASING, sline); + if(poly == NULL) + poly = dline; + else + poly->insert(dline); + } + + //the edge connecting upper grid with left chain + vert1[0] = grid->get_u_value(upperInd); + vert1[1] = upperV; + sline = new sampledLine(vert1, leftChain->getVertex(beginLeftIndex)); + dline = new directedLine(INCREASING, sline); + if(poly == NULL) + poly = dline; + else + poly->insert(dline); + + //the left chain + for(i=beginLeftIndex; igetVertex(i), leftChain->getVertex(i+1)); + dline = new directedLine(INCREASING, sline); + poly->insert(dline); + } + + //the edge connecting left chain with lower gridline + vert2[0] = grid->get_u_value(lowerInd); + vert2[1] = lowerV; + sline = new sampledLine(leftChain->getVertex(endLeftIndex), vert2); + dline = new directedLine(INCREASING, sline); + poly->insert(dline); + + //the lower grid line + vert1[1] = vert2[1] = lowerV; + for(i=lowerInd; iget_u_value(i); + vert2[0] = grid->get_u_value(i+1); + sline = new sampledLine(vert1, vert2); + dline = new directedLine(INCREASING, sline); + poly->insert(dline); + } + + //the vertical grid line segement + vert1[0]=vert2[0] = grid->get_u_value(innerInd); + vert2[1]=upperV; + vert1[1]=lowerV; + sline=new sampledLine(vert1, vert2); + dline=new directedLine(INCREASING, sline); + poly->insert(dline); + monoTriangulationOpt(poly, pStream); + //cleanup + poly->deleteSinglePolygonWithSline(); + return; + } + + + + + + Int i; + if(1/*leftGridChain->getUlineIndex(leftGridChainStartIndex) >= + leftGridChain->getUlineIndex(leftGridChainStartIndex+1)*/ + ) /*the second grid line is beyond the first one to the left*/ + { + /*find the maximal U-monotone chain + * of endLeftIndex, endLeftIndex-1, ..., + */ + i=endLeftIndex; + Real prevU = leftChain->getVertex(i)[0]; + for(i=endLeftIndex-1; i>=beginLeftIndex; i--){ + Real thisU = leftChain->getVertex(i)[0]; + if( prevU < thisU){ + prevU = thisU; + } + else + break; + } + /*from endLeftIndex to i+1 is strictly U- monotone */ + /*if i+1==endLeftIndex and the vertex and leftchain is on the second gridline, then + *we should use 2 vertices on the leftchain. If we only use one (endLeftIndex), then we + *we would output degenerate triangles + */ + if(i+1 == endLeftIndex && leftChain->getVertex(endLeftIndex)[1] == leftGridChain->get_v_value(1+leftGridChainStartIndex)) + i--; + + Int j = beginLeftIndex/*endLeftIndex*/+1; + + + if(leftGridChain->getInnerIndex(leftGridChainStartIndex+1) > leftGridChain->getUlineIndex(leftGridChainStartIndex)) + { + j = findIncreaseChainFromBegin(leftChain, beginLeftIndex, i+1/*endLeftIndex*/); + + Int temp = beginLeftIndex; + /*now from begin to j-1 is strictly u-monotone*/ + /*if j-1 is on the first grid line, then we want to skip to the vertex which is strictly + *below the grid line. This vertexmust exist since there is a 'corner turn' inbetween the two grid lines + */ + if(j-1 == beginLeftIndex) + { + while(leftChain->getVertex(j-1)[1] == leftGridChain->get_v_value(leftGridChainStartIndex)) + j++; + + Real vert[2]; + vert[0] = leftGridChain->get_u_value(leftGridChainStartIndex); + vert[1] = leftGridChain->get_v_value(leftGridChainStartIndex); + + monoTriangulation2( + vert/*leftChain->getVertex(beginLeftIndex)*/, + leftChain->getVertex(j-1), + leftChain, + beginLeftIndex, + j-2, + 1, + pStream //increase chain + ); + + temp = j-1; + } + + stripOfFanLeft(leftChain, j-1, temp/*beginLeftIndex*/, leftGridChain->getGrid(), + leftGridChain->getVlineIndex(leftGridChainStartIndex), + leftGridChain->getUlineIndex(leftGridChainStartIndex), + leftGridChain->getInnerIndex(leftGridChainStartIndex+1), + pStream, + 1 /*the grid line is above the trim line*/ + ); + } + + stripOfFanLeft(leftChain, endLeftIndex, i+1, leftGridChain->getGrid(), + leftGridChain->getVlineIndex(leftGridChainStartIndex+1), + leftGridChain->getUlineIndex(leftGridChainStartIndex+1), + leftGridChain->getInnerIndex(leftGridChainStartIndex+1), + pStream, + 0 /*the grid line is below the trim lines*/ + ); + + /*monotone triangulate the remaining left chain togther with the + *two vertices on the two grid v-lines. + */ + Real vert[2][2]; + vert[0][0]=vert[1][0] = leftGridChain->getInner_u_value(leftGridChainStartIndex+1); + vert[0][1] = leftGridChain->get_v_value(leftGridChainStartIndex); + vert[1][1] = leftGridChain->get_v_value(leftGridChainStartIndex+1); + +// vertexArray right(vert, 2); + + monoTriangulation2( + &vert[0][0], /*top vertex */ + &vert[1][0], /*bottom vertex*/ + leftChain, + /*beginLeftIndex*/j-1, + i+1, + 1, /*an increasing chain*/ + pStream); + } + else /*the second one is shorter than the first one to the left*/ + { + /*find the maximal U-monotone chain of beginLeftIndex, beginLeftIndex+1,..., + */ + i=beginLeftIndex; + Real prevU = leftChain->getVertex(i)[0]; + for(i=beginLeftIndex+1; i<=endLeftIndex; i++){ + Real thisU = leftChain->getVertex(i)[0]; + + if(prevU < thisU){ + prevU = thisU; + } + else + break; + } + /*from beginLeftIndex to i-1 is strictly U-monotone*/ + + + stripOfFanLeft(leftChain, i-1, beginLeftIndex, leftGridChain->getGrid(), + leftGridChain->getVlineIndex(leftGridChainStartIndex), + leftGridChain->getUlineIndex(leftGridChainStartIndex), + leftGridChain->getUlineIndex(leftGridChainStartIndex+1), + pStream, + 1 /*the grid line is above the trim lines*/ + ); + /*monotone triangulate the remaining left chain together with the + *two vertices on the two grid v-lines. + */ + Real vert[2][2]; + vert[0][0]=vert[1][0] = leftGridChain->get_u_value(leftGridChainStartIndex+1); + vert[0][1] = leftGridChain->get_v_value(leftGridChainStartIndex); + vert[1][1] = leftGridChain->get_v_value(leftGridChainStartIndex+1); + + vertexArray right(vert, 2); + + monoTriangulation2( + &vert[0][0], //top vertex + &vert[1][0], //bottom vertex + leftChain, + i-1, + endLeftIndex, + 1, /*an increase chain*/ + pStream); + + } +} + +/*n_upper>=1 + *n_lower>=1 + */ +void triangulateXYMono(Int n_upper, Real upperVerts[][2], + Int n_lower, Real lowerVerts[][2], + primStream* pStream) +{ + Int i,j,k,l; + Real* leftMostV; + + assert(n_upper>=1 && n_lower>=1); + if(upperVerts[0][0] <= lowerVerts[0][0]) + { + i=1; + j=0; + leftMostV = upperVerts[0]; + } + else + { + i=0; + j=1; + leftMostV = lowerVerts[0]; + } + + while(1) + { + if(i >= n_upper) /*case1: no more in upper*/ + { + + if(jbegin(); + pStream->insert(leftMostV); + while(jinsert(lowerVerts[j]); + j++; + } + pStream->end(PRIMITIVE_STREAM_FAN); + } + + break; + } + else if(j>= n_lower) /*case2: no more in lower*/ + { + + if(ibegin(); + pStream->insert(leftMostV); + + for(k=n_upper-1; k>=i; k--) + pStream->insert(upperVerts[k]); + + pStream->end(PRIMITIVE_STREAM_FAN); + } + + break; + } + else /* case3: neither is empty, plus the leftMostV, there is at least one triangle to output*/ + { + + if(upperVerts[i][0] <= lowerVerts[j][0]) + { + pStream->begin(); + pStream->insert(lowerVerts[j]); /*the origin of this fan*/ + + /*find the last k>=i such that + *upperverts[k][0] <= lowerverts[j][0] + */ + k=i; + while(k lowerVerts[j][0]) + break; + k++; + } + k--; + for(l=k; l>=i; l--)/*the reverse is for two-face lighting*/ + { + pStream->insert(upperVerts[l]); + } + pStream->insert(leftMostV); + + pStream->end(PRIMITIVE_STREAM_FAN); + //update i for next loop + i = k+1; + leftMostV = upperVerts[k]; + + } + else /*upperVerts[i][0] > lowerVerts[j][0]*/ + { + pStream->begin(); + pStream->insert(upperVerts[i]);/*the origion of this fan*/ + pStream->insert(leftMostV); + /*find the last k>=j such that + *lowerverts[k][0] < upperverts[i][0]*/ + k=j; + while(k< n_lower) + { + if(lowerVerts[k][0] >= upperVerts[i][0]) + break; + pStream->insert(lowerVerts[k]); + k++; + } + pStream->end(PRIMITIVE_STREAM_FAN); + j=k; + leftMostV = lowerVerts[j-1]; + } + } + } +} + + +void stripOfFanLeft(vertexArray* leftChain, + Int largeIndex, + Int smallIndex, + gridWrap* grid, + Int vlineIndex, + Int ulineSmallIndex, + Int ulineLargeIndex, + primStream* pStream, + Int gridLineUp /*1 if the grid line is above the trim lines*/ + ) +{ + assert(largeIndex >= smallIndex); + + Real grid_v_value; + grid_v_value = grid->get_v_value(vlineIndex); + + Real2* trimVerts=(Real2*) malloc(sizeof(Real2)* (largeIndex-smallIndex+1)); + assert(trimVerts); + + + Real2* gridVerts=(Real2*) malloc(sizeof(Real2)* (ulineLargeIndex-ulineSmallIndex+1)); + assert(gridVerts); + + Int k,i; + if(gridLineUp) /*trim line is below grid line, so trim vertices are going right when index increases*/ + for(k=0, i=smallIndex; i<=largeIndex; i++, k++) + { + trimVerts[k][0] = leftChain->getVertex(i)[0]; + trimVerts[k][1] = leftChain->getVertex(i)[1]; + } + else + for(k=0, i=largeIndex; i>=smallIndex; i--, k++) + { + trimVerts[k][0] = leftChain->getVertex(i)[0]; + trimVerts[k][1] = leftChain->getVertex(i)[1]; + } + + for(k=0, i=ulineSmallIndex; i<= ulineLargeIndex; i++, k++) + { + gridVerts[k][0] = grid->get_u_value(i); + gridVerts[k][1] = grid_v_value; + } + + if(gridLineUp) + triangulateXYMono( + ulineLargeIndex-ulineSmallIndex+1, gridVerts, + largeIndex-smallIndex+1, trimVerts, + pStream); + else + triangulateXYMono(largeIndex-smallIndex+1, trimVerts, + ulineLargeIndex-ulineSmallIndex+1, gridVerts, + pStream); + free(trimVerts); + free(gridVerts); +} + + + + + diff --git a/src/glu/sgi/libnurbs/nurbtess/sampleMonoPoly.h b/src/glu/sgi/libnurbs/nurbtess/sampleMonoPoly.h new file mode 100644 index 0000000..3a5fa6c --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/sampleMonoPoly.h @@ -0,0 +1,184 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _SAMPLEMONOPOLY_H +#define _SAMPLEMONOPOLY_H + +#include "monoTriangulation.h" +#include "gridWrap.h" +#include "rectBlock.h" + + +void triangulateXYMono(Int n_upper, Real upperVerts[][2], + Int n_lower, Real lowerVerts[][2], + primStream* pStream); + +void stripOfFanLeft(vertexArray* leftChain, + Int largeIndex, + Int smallIndex, + gridWrap* grid, + Int vlineIndex, + Int ulineSmallIndex, + Int ulineLargeIndex, + primStream* pStream, + Int gridLineUp + ); +void sampleLeftOneGridStep(vertexArray* leftChain, + Int beginLeftIndex, + Int endLeftIndex, + gridBoundaryChain* leftGridChain, + Int leftGridChainStartIndex, + primStream* pStream + ); + +void sampleLeftSingleTrimEdgeRegion(Real upperVert[2], Real lowerVert[2], + gridBoundaryChain* gridChain, + Int beginIndex, + Int endIndex, + primStream* pStream); + +void sampleLeftStripRec(vertexArray* leftChain, + Int topLeftIndex, + Int botLeftIndex, + gridBoundaryChain* leftGridChain, + Int leftGridChainStartIndex, + Int leftGridChainEndIndex, + primStream* pStream + ); + +void sampleLeftStrip(vertexArray* leftChain, + Int topLeftIndex, + Int botLeftIndex, + gridBoundaryChain* leftGridChain, + Int leftGridChainStartIndex, + Int leftGridChainEndIndex, + primStream* pStream + ); + +void findLeftGridIndices(directedLine* topEdge, Int firstGridIndex, Int lastGridIndex, gridWrap* grid, Int* ret_indices, Int* ret_inner); + +void findRightGridIndices(directedLine* topEdge, Int firstGridIndex, Int lastGridIndex, gridWrap* grid, Int* ret_indices, Int* ret_inner); + +void sampleMonoPoly(directedLine* polygon, gridWrap* grid, Int ulinear, Int vlinear, primStream *pStream, rectBlockArray* rbArray); + +void sampleMonoPolyRec( + Real* topVertex, + Real* botVertex, + vertexArray* leftChain, + Int leftStartIndex, + vertexArray* rightChain, + Int rightStartIndex, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridStartIndex, + primStream* pStream, + rectBlockArray* rbArray + ); + +void sampleLeftStripRecF(vertexArray* leftChain, + Int topLeftIndex, + Int botLeftIndex, + gridBoundaryChain* leftGridChain, + Int leftGridChainStartIndex, + Int leftGridChainEndIndex, + primStream* pStream + ); + +void findUpCorners(Real *topVertex, + vertexArray *leftChain, + Int leftChainStartIndex, Int leftChainEndIndex, + vertexArray *rightChain, + Int rightChainStartIndex, Int rightChainEndIndex, + Real v, + Real uleft, + Real uright, + Int& ret_leftCornerWhere, + Int& ret_leftCornerIndex, + Int& ret_rightCornerWhere, + Int& ret_rightCornerIndex + ); +void findDownCorners(Real *botVertex, + vertexArray *leftChain, Int leftChainStartIndex, Int leftChainEndIndex, + vertexArray *rightChain, Int rightChainStartIndex, Int rightChainEndIndex, + Real v, + Real uleft, + Real uright, + Int& ret_leftCornerWhere, + Int& ret_leftCornerIndex, + Int& ret_rightCornerWhere, + Int& ret_rightCornerIndex + ); +void findNeck(vertexArray *leftChain, Int botLeftIndex, + vertexArray *rightChain, Int botRightIndex, + Int& leftLastIndex, /*left point of the neck*/ + Int& rightLastIndex /*right point of the neck*/ + ); + +Int findNeckF(vertexArray *leftChain, Int botLeftIndex, + vertexArray *rightChain, Int botRightIndex, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridStartIndex, + Int& neckLeft, + Int& neckRight); + +void findTopAndBot(directedLine* polygon, + directedLine*& topV, + directedLine*& botV); +void findGridChains(directedLine* top, directedLine* bot, + gridWrap* grid, + gridBoundaryChain*& leftGridChain, + gridBoundaryChain*& rightGridChain); +void toVertexArrays(directedLine* topV, directedLine* botV, vertexArray& leftChain, vertexArray& rightChain); + +void drawCorners( + Real* topV, Real* botV, + vertexArray* leftChain, + vertexArray* rightChain, + gridBoundaryChain* leftGridChain, + gridBoundaryChain* rightGridChain, + Int gridIndex1, + Int gridIndex2, + Int leftCornerWhere, + Int leftCornerIndex, + Int rightCornerWhere, + Int rightCornerIndex, + Int bot_leftCornerWhere, + Int bot_leftCornerIndex, + Int bot_rightCornerWhere, + Int bot_rightCornerIndex); + +Int checkMiddle(vertexArray* chain, Int begin, Int end, + Real vup, Real vbelow); + +#endif + diff --git a/src/glu/sgi/libnurbs/nurbtess/sampledLine.cc b/src/glu/sgi/libnurbs/nurbtess/sampledLine.cc new file mode 100644 index 0000000..89f6c6e --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/sampledLine.cc @@ -0,0 +1,182 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include +#include //for fabs() +#include "glimports.h" +#include "zlassert.h" +#include "sampledLine.h" + +void sampledLine::setPoint(Int i, Real p[2]) +{ + points[i][0]=p[0]; + points[i][1]=p[1]; +} + + +/*insert this single line in front of the oldList*/ +sampledLine* sampledLine::insert(sampledLine *oldList) +{ + next = oldList; + return this; +} + +void sampledLine::deleteList() +{ + sampledLine *temp, *tempNext; + for(temp = this; temp != NULL; temp = tempNext) + { + tempNext = temp->next; + delete temp; + } +} + + +/*space of points[][2] is allocated*/ +sampledLine::sampledLine(Int n_points) +{ + npoints = n_points; + points = (Real2*) malloc(sizeof(Real2) * n_points); + assert(points); + next = NULL; +} + +/*space of points[][2] is allocated and + *points are copied + */ +sampledLine::sampledLine(Int n_points, Real2 pts[]) +{ + int i; + npoints = n_points; + points = (Real2*) malloc(sizeof(Real2) * n_points); + assert(points); + for(i=0; i nv) n = nu; + else + n = nv; + if(n<1) + n = 1; + //du dv could be negative + Real du = (points[npoints-1][0] - points[0][0])/n; + Real dv = (points[npoints-1][1] - points[0][1])/n; + Real2 *temp = (Real2*) malloc(sizeof(Real2) * (n+1)); + assert(temp); + + Real u,v; + for(i=0, u=points[0][0], v=points[0][1]; inext) + { + temp->tessellate(u_reso, v_reso); + } +} diff --git a/src/glu/sgi/libnurbs/nurbtess/sampledLine.h b/src/glu/sgi/libnurbs/nurbtess/sampledLine.h new file mode 100644 index 0000000..2cc7269 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/sampledLine.h @@ -0,0 +1,71 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _SAMPLEDLINE_H +#define _SAMPLEDLINE_H + +#include "definitions.h" + +class sampledLine{ + Int npoints; + Real2 *points; + +public: + sampledLine(Int n_points); + sampledLine(Int n_points, Real pts[][2]); + sampledLine(Real pt1[2], Real pt2[2]); + sampledLine(); //special, careful about memory + ~sampledLine(); + + void init(Int n_points, Real2 *pts);//special, careful about memory + + void setPoint(Int i, Real p[2]) ; + + sampledLine* insert(sampledLine *nline); + void deleteList(); + + Int get_npoints() {return npoints;} + Real2* get_points() {return points;} + + //u_reso is number of segments (may not be integer) per unit u + void tessellate(Real u_reso, Real v_reso);//n segments + void tessellateAll(Real u_reso, Real v_reso); + + void print(); + + sampledLine* next; +}; + + + + +#endif diff --git a/src/glu/sgi/libnurbs/nurbtess/searchTree.cc b/src/glu/sgi/libnurbs/nurbtess/searchTree.cc new file mode 100644 index 0000000..1865755 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/searchTree.cc @@ -0,0 +1,282 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +*/ +/* +*/ + +#include +#include +#include "zlassert.h" + +#include "searchTree.h" + +#define max(a,b) ((a>b)? a:b) + +treeNode* TreeNodeMake(void *key) +{ + treeNode *ret = (treeNode*) malloc(sizeof(treeNode)); + assert(ret); + ret->key = key; + ret->parent = NULL; + ret->left = NULL; + ret->right = NULL; + return ret; +} + +void TreeNodeDeleteSingleNode(treeNode* node) +{ + free(node); +} + +void TreeNodeDeleteWholeTree(treeNode* node) +{ + if(node == NULL) return; + TreeNodeDeleteWholeTree(node->left); + TreeNodeDeleteWholeTree(node->right); + TreeNodeDeleteSingleNode(node); +} + +void TreeNodePrint(treeNode* node, + void (*keyPrint) (void*)) +{ + if(node ==NULL) return; + TreeNodePrint(node->left, keyPrint); + keyPrint(node->key); + TreeNodePrint(node->right, keyPrint); +} + +int TreeNodeDepth(treeNode* root) +{ + if(root == NULL) return 0; + else{ + int leftdepth = TreeNodeDepth(root->left); + int rightdepth = TreeNodeDepth(root->right); + return 1 + max(leftdepth, rightdepth); + } +} + +/*return the node with the key. + *NULL is returned if not found + */ +treeNode* TreeNodeFind(treeNode* tree, void* key, + int (*compkey) (void*, void*)) +{ + if(tree == NULL) + return NULL; + if(key == tree->key) + return tree; + else if(compkey(key, tree->key) < 0) + return TreeNodeFind(tree->left, key, compkey); + else + return TreeNodeFind(tree->right, key, compkey); +} + + +treeNode* TreeNodeInsert(treeNode* root, treeNode* newnode, + int (*compkey) (void *, void *)) +{ + treeNode *y = NULL; + treeNode *x = root; + /*going down the tree from the root. + *x traces the path, y is the parent of x. + */ + while (x != NULL){ + y = x; + if(compkey(newnode->key,x->key) < 0) /*if newnode < x*/ + x = x->left; + else + x = x->right; + } + + /*now y has the property that + * if newnode < y, then y->left is NULL + * if newnode > y, then y->right is NULL. + *So we want to isnert newnode to be the child of y + */ + newnode->parent = y; + if(y == NULL) + return newnode; + else if( compkey(newnode->key, y->key) <0) + { + y->left = newnode; + } + else + { + y->right = newnode; + } + + return root; +} + +treeNode* TreeNodeDeleteSingleNode(treeNode* tree, treeNode* node) +{ + treeNode* y; + treeNode* x; + treeNode* ret; + if(node==NULL) return tree; + + if(node->left == NULL || node->right == NULL) { + + y = node; + if(y->left != NULL) + x = y->left; + else + x = y->right; + + if( x != NULL) + x->parent = y->parent; + + if(y->parent == NULL) /*y is the root which has at most one child x*/ + ret = x; + else /*y is not the root*/ + { + if(y == y->parent->left) + y->parent->left = x; + else + y->parent->right = x; + ret = tree; + } + } + else { /*node has two children*/ + + y = TreeNodeSuccessor(node); + assert(y->left == NULL); + + if(y == node->right) /*y is the right child if node*/ + { + y->parent = node->parent; + y->left = node->left; + node->left->parent = y; + + } + else /*y != node->right*/ + { + x = y->right; + if(x!= NULL) + x->parent = y->parent; + + assert(y->parent != NULL); + if(y == y->parent->left) + y->parent->left = x; + else + y->parent->right = x; + /*move y to the position of node*/ + y->parent = node->parent; + y->left = node->left; + y->right = node->right; + node->left->parent = y; + node->right->parent = y; + } + if(node->parent != NULL) { + if(node->parent->left == node) + node->parent->left = y; + else + node->parent->right = y; + ret = tree; /*the root if the tree doesn't change*/ + } + else /*node->parent is NULL: node is the root*/ + ret = y; + } + + /*finally free the node, and return the new root*/ + TreeNodeDeleteSingleNode(node); + return ret; +} + + +/*the minimum node in the tree rooted by node + */ +treeNode* TreeNodeMinimum(treeNode* node) +{ + treeNode* temp = node; + if(temp == NULL) return NULL; + while(temp->left != NULL) { + temp = temp->left; + } + return temp; +} + +/*the maximum node in the tree rooted by node + */ +treeNode* TreeNodeMaximum(treeNode* node) +{ + treeNode* temp = node; + if(temp == NULL) return NULL; + while(temp->right != NULL) { + temp = temp->right; + } + return temp; +} + +/*return the first node (in sorted order) which is to the right of this node + */ +treeNode* TreeNodeSuccessor(treeNode* node) +{ + if(node == NULL) return NULL; + if(node->right != NULL) + return TreeNodeMinimum(node->right); + else{ /*node->right is NULL*/ + + /*find the first right-ancestor*/ + treeNode *y = node->parent; + treeNode* x = node; + while(y != NULL && x == y->right) /*if y is a left parent of x*/ + { + + x = y; + y = y->parent; + } + return y; + } +} + +/*return the first node (in sorted order) which is to the left of this node + */ +treeNode* TreeNodePredecessor(treeNode* node) +{ + if(node == NULL) return NULL; + if(node->left != NULL) + return TreeNodeMaximum(node->left); + else{ /*node->left is NULL*/ + /*find the first left-ancestor*/ + treeNode *y = node->parent; + treeNode *x = node; + while(y != NULL && x == y->left) /*if y is a right parent of x*/ + { + x = y; + y = y->parent; + } + return y; + } +} diff --git a/src/glu/sgi/libnurbs/nurbtess/searchTree.h b/src/glu/sgi/libnurbs/nurbtess/searchTree.h new file mode 100644 index 0000000..d5e3331 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/searchTree.h @@ -0,0 +1,61 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +#ifndef _SEARCHTREE_H +#define _SEARCHTREE_H + +typedef struct treeNode{ + void *key; + struct treeNode* parent; + struct treeNode* left; /*children*/ + struct treeNode* right; +} treeNode; + +treeNode* TreeNodeMake(void *key); +void TreeNodeDeleteSingleNode(treeNode* node); +void TreeNodeDeleteWholeTree(treeNode* node); +void TreeNodePrint(treeNode* node, + void (*keyPrint) (void*)); +int TreeNodeDepth(treeNode* root); +treeNode* TreeNodeMinimum(treeNode* node); +treeNode* TreeNodeMaximum(treeNode* node); +treeNode* TreeNodePredecessor(treeNode* node); +treeNode* TreeNodeSuccessor(treeNode* node); +treeNode* TreeNodeFind(treeNode* tree, void* key, + int (*compkey) (void*, void*)); + +treeNode* TreeNodeInsert(treeNode* root, treeNode* newnode, + int (*comp) (void *, void *)); +treeNode* TreeNodeDeleteSingleNode(treeNode* tree, treeNode* node); + + +#endif diff --git a/src/glu/sgi/libnurbs/nurbtess/zlassert.h b/src/glu/sgi/libnurbs/nurbtess/zlassert.h new file mode 100644 index 0000000..b9c0732 --- /dev/null +++ b/src/glu/sgi/libnurbs/nurbtess/zlassert.h @@ -0,0 +1,34 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +*/ + +/*XXXblythe this file should be deleted*/ +#include diff --git a/src/glu/sgi/libtess/README b/src/glu/sgi/libtess/README new file mode 100644 index 0000000..66a6011 --- /dev/null +++ b/src/glu/sgi/libtess/README @@ -0,0 +1,446 @@ +/* +*/ + +General Polygon Tesselation +--------------------------- + + This note describes a tesselator for polygons consisting of one or + more closed contours. It is backward-compatible with the current + OpenGL Utilities tesselator, and is intended to replace it. Here is + a summary of the major differences: + + - input contours can be intersecting, self-intersecting, or degenerate. + + - supports a choice of several winding rules for determining which parts + of the polygon are on the "interior". This makes it possible to do + CSG operations on polygons. + + - boundary extraction: instead of tesselating the polygon, returns a + set of closed contours which separate the interior from the exterior. + + - returns the output as a small number of triangle fans and strips, + rather than a list of independent triangles (when possible). + + - output is available as an explicit mesh (a quad-edge structure), + in addition to the normal callback interface. + + - the algorithm used is extremely robust. + + +The interface +------------- + + The tesselator state is maintained in a "tesselator object". + These are allocated and destroyed using + + GLUtesselator *gluNewTess( void ); + void gluDeleteTess( GLUtesselator *tess ); + + Several tesselator objects may be used simultaneously. + + Inputs + ------ + + The input contours are specified with the following routines: + + void gluTessBeginPolygon( GLUtesselator *tess ); + void gluTessBeginContour( GLUtesselator *tess ); + void gluTessVertex( GLUtesselator *tess, GLUcoord coords[3], void *data ); + void gluTessEndContour( GLUtesselator *tess ); + void gluTessEndPolygon( GLUtesselator *tess ); + + Within each BeginPolygon/EndPolygon pair, there can be zero or more + calls to BeginContour/EndContour. Within each contour, there are zero + or more calls to gluTessVertex(). The vertices specify a closed + contour (the last vertex of each contour is automatically linked to + the first). + + "coords" give the coordinates of the vertex in 3-space. For useful + results, all vertices should lie in some plane, since the vertices + are projected onto a plane before tesselation. "data" is a pointer + to a user-defined vertex structure, which typically contains other + information such as color, texture coordinates, normal, etc. It is + used to refer to the vertex during rendering. + + The library can be compiled in single- or double-precision; the type + GLUcoord represents either "float" or "double" accordingly. The GLU + version will be available in double-precision only. Compile with + GLU_TESS_API_FLOAT defined to get the single-precision version. + + When EndPolygon is called, the tesselation algorithm determines + which regions are interior to the given contours, according to one + of several "winding rules" described below. The interior regions + are then tesselated, and the output is provided as callbacks. + + + Rendering Callbacks + ------------------- + + Callbacks are specified by the client using + + void gluTessCallback( GLUtesselator *tess, GLenum which, void (*fn)()); + + If "fn" is NULL, any previously defined callback is discarded. + + The callbacks used to provide output are: /* which == */ + + void begin( GLenum type ); /* GLU_TESS_BEGIN */ + void edgeFlag( GLboolean flag ); /* GLU_TESS_EDGE_FLAG */ + void vertex( void *data ); /* GLU_TESS_VERTEX */ + void end( void ); /* GLU_TESS_END */ + + Any of the callbacks may be left undefined; if so, the corresponding + information will not be supplied during rendering. + + The "begin" callback indicates the start of a primitive; type is one + of GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, or GL_TRIANGLES (but see the + notes on "boundary extraction" below). + + It is followed by any number of "vertex" callbacks, which supply the + vertices in the same order as expected by the corresponding glBegin() + call. After the last vertex of a given primitive, there is a callback + to "end". + + If the "edgeFlag" callback is provided, no triangle fans or strips + will be used. When edgeFlag is called, if "flag" is GL_TRUE then each + vertex which follows begins an edge which lies on the polygon boundary + (ie. an edge which separates an interior region from an exterior one). + If "flag" is GL_FALSE, each vertex which follows begins an edge which lies + in the polygon interior. "edgeFlag" will be called before the first + call to "vertex". + + Other Callbacks + --------------- + + void mesh( GLUmesh *mesh ); /* GLU_TESS_MESH */ + + - Returns an explicit mesh, represented using the quad-edge structure + (Guibas/Stolfi '85). Other implementations of this interface might + use a different mesh structure, so this is available only only as an + SGI extension. When the mesh is no longer needed, it should be freed + using + + void gluDeleteMesh( GLUmesh *mesh ); + + There is a brief description of this data structure in the include + file "mesh.h". For the full details, see L. Guibas and J. Stolfi, + Primitives for the manipulation of general subdivisions and the + computation of Voronoi diagrams, ACM Transactions on Graphics, + 4(2):74-123, April 1985. For an introduction, see the course notes + for CS348a, "Mathematical Foundations of Computer Graphics", + available at the Stanford bookstore (and taught during the fall + quarter). + + void error( GLenum errno ); /* GLU_TESS_ERROR */ + + - errno is one of GLU_TESS_MISSING_BEGIN_POLYGON, + GLU_TESS_MISSING_END_POLYGON, + GLU_TESS_MISSING_BEGIN_CONTOUR, + GLU_TESS_MISSING_END_CONTOUR, + GLU_TESS_COORD_TOO_LARGE, + GLU_TESS_NEED_COMBINE_CALLBACK + + The first four are obvious. The interface recovers from these + errors by inserting the missing call(s). + + GLU_TESS_COORD_TOO_LARGE says that some vertex coordinate exceeded + the predefined constant GLU_TESS_MAX_COORD in absolute value, and + that the value has been clamped. (Coordinate values must be small + enough so that two can be multiplied together without overflow.) + + GLU_TESS_NEED_COMBINE_CALLBACK says that the algorithm detected an + intersection between two edges in the input data, and the "combine" + callback (below) was not provided. No output will be generated. + + + void combine( GLUcoord coords[3], void *data[4], /* GLU_TESS_COMBINE */ + GLUcoord weight[4], void **outData ); + + - When the algorithm detects an intersection, or wishes to merge + features, it needs to create a new vertex. The vertex is defined + as a linear combination of up to 4 existing vertices, referenced + by data[0..3]. The coefficients of the linear combination are + given by weight[0..3]; these weights always sum to 1.0. All vertex + pointers are valid even when some of the weights are zero. + "coords" gives the location of the new vertex. + + The user must allocate another vertex, interpolate parameters + using "data" and "weights", and return the new vertex pointer in + "outData". This handle is supplied during rendering callbacks. + For example, if the polygon lies in an arbitrary plane in 3-space, + and we associate a color with each vertex, the combine callback might + look like this: + + void myCombine( GLUcoord coords[3], VERTEX *d[4], + GLUcoord w[4], VERTEX **dataOut ) + { + VERTEX *new = new_vertex(); + + new->x = coords[0]; + new->y = coords[1]; + new->z = coords[2]; + new->r = w[0]*d[0]->r + w[1]*d[1]->r + w[2]*d[2]->r + w[3]*d[3]->r; + new->g = w[0]*d[0]->g + w[1]*d[1]->g + w[2]*d[2]->g + w[3]*d[3]->g; + new->b = w[0]*d[0]->b + w[1]*d[1]->b + w[2]*d[2]->b + w[3]*d[3]->b; + new->a = w[0]*d[0]->a + w[1]*d[1]->a + w[2]*d[2]->a + w[3]*d[3]->a; + *dataOut = new; + } + + If the algorithm detects an intersection, then the "combine" callback + must be defined, and must write a non-NULL pointer into "dataOut". + Otherwise the GLU_TESS_NEED_COMBINE_CALLBACK error occurs, and no + output is generated. This is the only error that can occur during + tesselation and rendering. + + + Control over Tesselation + ------------------------ + + void gluTessProperty( GLUtesselator *tess, GLenum which, GLUcoord value ); + + Properties defined: + + - GLU_TESS_WINDING_RULE. Possible values: + + GLU_TESS_WINDING_ODD + GLU_TESS_WINDING_NONZERO + GLU_TESS_WINDING_POSITIVE + GLU_TESS_WINDING_NEGATIVE + GLU_TESS_WINDING_ABS_GEQ_TWO + + The input contours parition the plane into regions. A winding + rule determines which of these regions are inside the polygon. + + For a single contour C, the winding number of a point x is simply + the signed number of revolutions we make around x as we travel + once around C (where CCW is positive). When there are several + contours, the individual winding numbers are summed. This + procedure associates a signed integer value with each point x in + the plane. Note that the winding number is the same for all + points in a single region. + + The winding rule classifies a region as "inside" if its winding + number belongs to the chosen category (odd, nonzero, positive, + negative, or absolute value of at least two). The current GLU + tesselator implements the "odd" rule. The "nonzero" rule is another + common way to define the interior. The other three rules are + useful for polygon CSG operations (see below). + + - GLU_TESS_BOUNDARY_ONLY. Values: TRUE (non-zero) or FALSE (zero). + + If TRUE, returns a set of closed contours which separate the + polygon interior and exterior (rather than a tesselation). + Exterior contours are oriented CCW with respect to the normal, + interior contours are oriented CW. The GLU_TESS_BEGIN callback + uses the type GL_LINE_LOOP for each contour. + + - GLU_TESS_TOLERANCE. Value: a real number between 0.0 and 1.0. + + This specifies a tolerance for merging features to reduce the size + of the output. For example, two vertices which are very close to + each other might be replaced by a single vertex. The tolerance + is multiplied by the largest coordinate magnitude of any input vertex; + this specifies the maximum distance that any feature can move as the + result of a single merge operation. If a single feature takes part + in several merge operations, the total distance moved could be larger. + + Feature merging is completely optional; the tolerance is only a hint. + The implementation is free to merge in some cases and not in others, + or to never merge features at all. The default tolerance is zero. + + The current implementation merges vertices only if they are exactly + coincident, regardless of the current tolerance. A vertex is + spliced into an edge only if the implementation is unable to + distinguish which side of the edge the vertex lies on. + Two edges are merged only when both endpoints are identical. + + + void gluTessNormal( GLUtesselator *tess, + GLUcoord x, GLUcoord y, GLUcoord z ) + + - Lets the user supply the polygon normal, if known. All input data + is projected into a plane perpendicular to the normal before + tesselation. All output triangles are oriented CCW with + respect to the normal (CW orientation can be obtained by + reversing the sign of the supplied normal). For example, if + you know that all polygons lie in the x-y plane, call + "gluTessNormal(tess, 0.0, 0.0, 1.0)" before rendering any polygons. + + - If the supplied normal is (0,0,0) (the default value), the + normal is determined as follows. The direction of the normal, + up to its sign, is found by fitting a plane to the vertices, + without regard to how the vertices are connected. It is + expected that the input data lies approximately in plane; + otherwise projection perpendicular to the computed normal may + substantially change the geometry. The sign of the normal is + chosen so that the sum of the signed areas of all input contours + is non-negative (where a CCW contour has positive area). + + - The supplied normal persists until it is changed by another + call to gluTessNormal. + + + Backward compatibility with the GLU tesselator + ---------------------------------------------- + + The preferred interface is the one described above. The following + routines are obsolete, and are provided only for backward compatibility: + + typedef GLUtesselator GLUtriangulatorObj; /* obsolete name */ + + void gluBeginPolygon( GLUtesselator *tess ); + void gluNextContour( GLUtesselator *tess, GLenum type ); + void gluEndPolygon( GLUtesselator *tess ); + + "type" is one of GLU_EXTERIOR, GLU_INTERIOR, GLU_CCW, GLU_CW, or + GLU_UNKNOWN. It is ignored by the current GLU tesselator. + + GLU_BEGIN, GLU_VERTEX, GLU_END, GLU_ERROR, and GLU_EDGE_FLAG are defined + as synonyms for GLU_TESS_BEGIN, GLU_TESS_VERTEX, GLU_TESS_END, + GLU_TESS_ERROR, and GLU_TESS_EDGE_FLAG. + + +Polygon CSG operations +---------------------- + + The features of the tesselator make it easy to find the union, difference, + or intersection of several polygons. + + First, assume that each polygon is defined so that the winding number + is 0 for each exterior region, and 1 for each interior region. Under + this model, CCW contours define the outer boundary of the polygon, and + CW contours define holes. Contours may be nested, but a nested + contour must be oriented oppositely from the contour that contains it. + + If the original polygons do not satisfy this description, they can be + converted to this form by first running the tesselator with the + GLU_TESS_BOUNDARY_ONLY property turned on. This returns a list of + contours satisfying the restriction above. By allocating two + tesselator objects, the callbacks from one tesselator can be fed + directly to the input of another. + + Given two or more polygons of the form above, CSG operations can be + implemented as follows: + + Union + Draw all the input contours as a single polygon. The winding number + of each resulting region is the number of original polygons + which cover it. The union can be extracted using the + GLU_TESS_WINDING_NONZERO or GLU_TESS_WINDING_POSITIVE winding rules. + Note that with the nonzero rule, we would get the same result if + all contour orientations were reversed. + + Intersection (two polygons at a time only) + Draw a single polygon using the contours from both input polygons. + Extract the result using GLU_TESS_WINDING_ABS_GEQ_TWO. (Since this + winding rule looks at the absolute value, reversing all contour + orientations does not change the result.) + + Difference + + Suppose we want to compute A \ (B union C union D). Draw a single + polygon consisting of the unmodified contours from A, followed by + the contours of B,C,D with the vertex order reversed (this changes + the winding number of the interior regions to -1). To extract the + result, use the GLU_TESS_WINDING_POSITIVE rule. + + If B,C,D are the result of a GLU_TESS_BOUNDARY_ONLY call, an + alternative to reversing the vertex order is to reverse the sign of + the supplied normal. For example in the x-y plane, call + gluTessNormal( tess, 0.0, 0.0, -1.0 ). + + +Performance +----------- + + The tesselator is not intended for immediate-mode rendering; when + possible the output should be cached in a user structure or display + list. General polygon tesselation is an inherently difficult problem, + especially given the goal of extreme robustness. + + The implementation makes an effort to output a small number of fans + and strips; this should improve the rendering performance when the + output is used in a display list. + + Single-contour input polygons are first tested to see whether they can + be rendered as a triangle fan with respect to the first vertex (to + avoid running the full decomposition algorithm on convex polygons). + Non-convex polygons may be rendered by this "fast path" as well, if + the algorithm gets lucky in its choice of a starting vertex. + + For best performance follow these guidelines: + + - supply the polygon normal, if available, using gluTessNormal(). + This represents about 10% of the computation time. For example, + if all polygons lie in the x-y plane, use gluTessNormal(tess,0,0,1). + + - render many polygons using the same tesselator object, rather than + allocating a new tesselator for each one. (In a multi-threaded, + multi-processor environment you may get better performance using + several tesselators.) + + +Comparison with the GLU tesselator +---------------------------------- + + On polygons which make it through the "fast path", the tesselator is + 3 to 5 times faster than the GLU tesselator. + + On polygons which don't make it through the fast path (but which don't + have self-intersections or degeneracies), it is about 2 times slower. + + On polygons with self-intersections or degeneraces, there is nothing + to compare against. + + The new tesselator generates many more fans and strips, reducing the + number of vertices that need to be sent to the hardware. + + Key to the statistics: + + vert number of input vertices on all contours + cntr number of input contours + tri number of triangles in all output primitives + strip number of triangle strips + fan number of triangle fans + ind number of independent triangles + ms number of milliseconds for tesselation + (on a 150MHz R4400 Indy) + + Convex polygon examples: + +New: 3 vert, 1 cntr, 1 tri, 0 strip, 0 fan, 1 ind, 0.0459 ms +Old: 3 vert, 1 cntr, 1 tri, 0 strip, 0 fan, 1 ind, 0.149 ms +New: 4 vert, 1 cntr, 2 tri, 0 strip, 1 fan, 0 ind, 0.0459 ms +Old: 4 vert, 1 cntr, 2 tri, 0 strip, 0 fan, 2 ind, 0.161 ms +New: 36 vert, 1 cntr, 34 tri, 0 strip, 1 fan, 0 ind, 0.153 ms +Old: 36 vert, 1 cntr, 34 tri, 0 strip, 0 fan, 34 ind, 0.621 ms + + Concave single-contour polygons: + +New: 5 vert, 1 cntr, 3 tri, 0 strip, 1 fan, 0 ind, 0.052 ms +Old: 5 vert, 1 cntr, 3 tri, 0 strip, 0 fan, 3 ind, 0.252 ms +New: 19 vert, 1 cntr, 17 tri, 2 strip, 2 fan, 1 ind, 0.911 ms +Old: 19 vert, 1 cntr, 17 tri, 0 strip, 0 fan, 17 ind, 0.529 ms +New: 151 vert, 1 cntr, 149 tri, 13 strip, 18 fan, 3 ind, 6.82 ms +Old: 151 vert, 1 cntr, 149 tri, 0 strip, 3 fan, 143 ind, 2.7 ms +New: 574 vert, 1 cntr, 572 tri, 59 strip, 54 fan, 11 ind, 26.6 ms +Old: 574 vert, 1 cntr, 572 tri, 0 strip, 31 fan, 499 ind, 12.4 ms + + Multiple contours, but no intersections: + +New: 7 vert, 2 cntr, 7 tri, 1 strip, 0 fan, 0 ind, 0.527 ms +Old: 7 vert, 2 cntr, 7 tri, 0 strip, 0 fan, 7 ind, 0.274 ms +New: 81 vert, 6 cntr, 89 tri, 9 strip, 7 fan, 6 ind, 3.88 ms +Old: 81 vert, 6 cntr, 89 tri, 0 strip, 13 fan, 61 ind, 2.2 ms +New: 391 vert, 19 cntr, 413 tri, 37 strip, 32 fan, 26 ind, 20.2 ms +Old: 391 vert, 19 cntr, 413 tri, 0 strip, 25 fan, 363 ind, 8.68 ms + + Self-intersecting and degenerate examples: + +Bowtie: 4 vert, 1 cntr, 2 tri, 0 strip, 0 fan, 2 ind, 0.483 ms +Star: 5 vert, 1 cntr, 5 tri, 0 strip, 0 fan, 5 ind, 0.91 ms +Random: 24 vert, 7 cntr, 46 tri, 2 strip, 12 fan, 7 ind, 5.32 ms +Font: 333 vert, 2 cntr, 331 tri, 32 strip, 16 fan, 3 ind, 14.1 ms +: 167 vert, 35 cntr, 254 tri, 8 strip, 56 fan, 52 ind, 46.3 ms +: 78 vert, 1 cntr, 2675 tri, 148 strip, 207 fan, 180 ind, 243 ms +: 12480 vert, 2 cntr, 12478 tri, 736 strip,1275 fan, 5 ind, 1010 ms diff --git a/src/glu/sgi/libtess/alg-outline b/src/glu/sgi/libtess/alg-outline new file mode 100644 index 0000000..33fd697 --- /dev/null +++ b/src/glu/sgi/libtess/alg-outline @@ -0,0 +1,228 @@ +/* +*/ + +This is only a very brief overview. There is quite a bit of +additional documentation in the source code itself. + + +Goals of robust tesselation +--------------------------- + +The tesselation algorithm is fundamentally a 2D algorithm. We +initially project all data into a plane; our goal is to robustly +tesselate the projected data. The same topological tesselation is +then applied to the input data. + +Topologically, the output should always be a tesselation. If the +input is even slightly non-planar, then some triangles will +necessarily be back-facing when viewed from some angles, but the goal +is to minimize this effect. + +The algorithm needs some capability of cleaning up the input data as +well as the numerical errors in its own calculations. One way to do +this is to specify a tolerance as defined above, and clean up the +input and output during the line sweep process. At the very least, +the algorithm must handle coincident vertices, vertices incident to an +edge, and coincident edges. + + +Phases of the algorithm +----------------------- + +1. Find the polygon normal N. +2. Project the vertex data onto a plane. It does not need to be + perpendicular to the normal, eg. we can project onto the plane + perpendicular to the coordinate axis whose dot product with N + is largest. +3. Using a line-sweep algorithm, partition the plane into x-monotone + regions. Any vertical line intersects an x-monotone region in + at most one interval. +4. Triangulate the x-monotone regions. +5. Group the triangles into strips and fans. + + +Finding the normal vector +------------------------- + +A common way to find a polygon normal is to compute the signed area +when the polygon is projected along the three coordinate axes. We +can't do this, since contours can have zero area without being +degenerate (eg. a bowtie). + +We fit a plane to the vertex data, ignoring how they are connected +into contours. Ideally this would be a least-squares fit; however for +our purpose the accuracy of the normal is not important. Instead we +find three vertices which are widely separated, and compute the normal +to the triangle they form. The vertices are chosen so that the +triangle has an area at least 1/sqrt(3) times the largest area of any +triangle formed using the input vertices. + +The contours do affect the orientation of the normal; after computing +the normal, we check that the sum of the signed contour areas is +non-negative, and reverse the normal if necessary. + + +Projecting the vertices +----------------------- + +We project the vertices onto a plane perpendicular to one of the three +coordinate axes. This helps numerical accuracy by removing a +transformation step between the original input data and the data +processed by the algorithm. The projection also compresses the input +data; the 2D distance between vertices after projection may be smaller +than the original 2D distance. However by choosing the coordinate +axis whose dot product with the normal is greatest, the compression +factor is at most 1/sqrt(3). + +Even though the *accuracy* of the normal is not that important (since +we are projecting perpendicular to a coordinate axis anyway), the +*robustness* of the computation is important. For example, if there +are many vertices which lie almost along a line, and one vertex V +which is well-separated from the line, then our normal computation +should involve V otherwise the results will be garbage. + +The advantage of projecting perpendicular to the polygon normal is +that computed intersection points will be as close as possible to +their ideal locations. To get this behavior, define TRUE_PROJECT. + + +The Line Sweep +-------------- + +There are three data structures: the mesh, the event queue, and the +edge dictionary. + +The mesh is a "quad-edge" data structure which records the topology of +the current decomposition; for details see the include file "mesh.h". + +The event queue simply holds all vertices (both original and computed +ones), organized so that we can quickly extract the vertex with the +minimum x-coord (and among those, the one with the minimum y-coord). + +The edge dictionary describes the current intersection of the sweep +line with the regions of the polygon. This is just an ordering of the +edges which intersect the sweep line, sorted by their current order of +intersection. For each pair of edges, we store some information about +the monotone region between them -- these are call "active regions" +(since they are crossed by the current sweep line). + +The basic algorithm is to sweep from left to right, processing each +vertex. The processed portion of the mesh (left of the sweep line) is +a planar decomposition. As we cross each vertex, we update the mesh +and the edge dictionary, then we check any newly adjacent pairs of +edges to see if they intersect. + +A vertex can have any number of edges. Vertices with many edges can +be created as vertices are merged and intersection points are +computed. For unprocessed vertices (right of the sweep line), these +edges are in no particular order around the vertex; for processed +vertices, the topological ordering should match the geometric ordering. + +The vertex processing happens in two phases: first we process are the +left-going edges (all these edges are currently in the edge +dictionary). This involves: + + - deleting the left-going edges from the dictionary; + - relinking the mesh if necessary, so that the order of these edges around + the event vertex matches the order in the dictionary; + - marking any terminated regions (regions which lie between two left-going + edges) as either "inside" or "outside" according to their winding number. + +When there are no left-going edges, and the event vertex is in an +"interior" region, we need to add an edge (to split the region into +monotone pieces). To do this we simply join the event vertex to the +rightmost left endpoint of the upper or lower edge of the containing +region. + +Then we process the right-going edges. This involves: + + - inserting the edges in the edge dictionary; + - computing the winding number of any newly created active regions. + We can compute this incrementally using the winding of each edge + that we cross as we walk through the dictionary. + - relinking the mesh if necessary, so that the order of these edges around + the event vertex matches the order in the dictionary; + - checking any newly adjacent edges for intersection and/or merging. + +If there are no right-going edges, again we need to add one to split +the containing region into monotone pieces. In our case it is most +convenient to add an edge to the leftmost right endpoint of either +containing edge; however we may need to change this later (see the +code for details). + + +Invariants +---------- + +These are the most important invariants maintained during the sweep. +We define a function VertLeq(v1,v2) which defines the order in which +vertices cross the sweep line, and a function EdgeLeq(e1,e2; loc) +which says whether e1 is below e2 at the sweep event location "loc". +This function is defined only at sweep event locations which lie +between the rightmost left endpoint of {e1,e2}, and the leftmost right +endpoint of {e1,e2}. + +Invariants for the Edge Dictionary. + + - Each pair of adjacent edges e2=Succ(e1) satisfies EdgeLeq(e1,e2) + at any valid location of the sweep event. + - If EdgeLeq(e2,e1) as well (at any valid sweep event), then e1 and e2 + share a common endpoint. + - For each e in the dictionary, e->Dst has been processed but not e->Org. + - Each edge e satisfies VertLeq(e->Dst,event) && VertLeq(event,e->Org) + where "event" is the current sweep line event. + - No edge e has zero length. + - No two edges have identical left and right endpoints. + +Invariants for the Mesh (the processed portion). + + - The portion of the mesh left of the sweep line is a planar graph, + ie. there is *some* way to embed it in the plane. + - No processed edge has zero length. + - No two processed vertices have identical coordinates. + - Each "inside" region is monotone, ie. can be broken into two chains + of monotonically increasing vertices according to VertLeq(v1,v2) + - a non-invariant: these chains may intersect (slightly) due to + numerical errors, but this does not affect the algorithm's operation. + +Invariants for the Sweep. + + - If a vertex has any left-going edges, then these must be in the edge + dictionary at the time the vertex is processed. + - If an edge is marked "fixUpperEdge" (it is a temporary edge introduced + by ConnectRightVertex), then it is the only right-going edge from + its associated vertex. (This says that these edges exist only + when it is necessary.) + + +Robustness +---------- + +The key to the robustness of the algorithm is maintaining the +invariants above, especially the correct ordering of the edge +dictionary. We achieve this by: + + 1. Writing the numerical computations for maximum precision rather + than maximum speed. + + 2. Making no assumptions at all about the results of the edge + intersection calculations -- for sufficiently degenerate inputs, + the computed location is not much better than a random number. + + 3. When numerical errors violate the invariants, restore them + by making *topological* changes when necessary (ie. relinking + the mesh structure). + + +Triangulation and Grouping +-------------------------- + +We finish the line sweep before doing any triangulation. This is +because even after a monotone region is complete, there can be further +changes to its vertex data because of further vertex merging. + +After triangulating all monotone regions, we want to group the +triangles into fans and strips. We do this using a greedy approach. +The triangulation itself is not optimized to reduce the number of +primitives; we just try to get a reasonable decomposition of the +computed triangulation. diff --git a/src/glu/sgi/libtess/dict-list.h b/src/glu/sgi/libtess/dict-list.h new file mode 100644 index 0000000..11331a7 --- /dev/null +++ b/src/glu/sgi/libtess/dict-list.h @@ -0,0 +1,100 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#ifndef __dict_list_h_ +#define __dict_list_h_ + +/* Use #define's so that another heap implementation can use this one */ + +#define DictKey DictListKey +#define Dict DictList +#define DictNode DictListNode + +#define dictNewDict(frame,leq) __gl_dictListNewDict(frame,leq) +#define dictDeleteDict(dict) __gl_dictListDeleteDict(dict) + +#define dictSearch(dict,key) __gl_dictListSearch(dict,key) +#define dictInsert(dict,key) __gl_dictListInsert(dict,key) +#define dictInsertBefore(dict,node,key) __gl_dictListInsertBefore(dict,node,key) +#define dictDelete(dict,node) __gl_dictListDelete(dict,node) + +#define dictKey(n) __gl_dictListKey(n) +#define dictSucc(n) __gl_dictListSucc(n) +#define dictPred(n) __gl_dictListPred(n) +#define dictMin(d) __gl_dictListMin(d) +#define dictMax(d) __gl_dictListMax(d) + + + +typedef void *DictKey; +typedef struct Dict Dict; +typedef struct DictNode DictNode; + +Dict *dictNewDict( + void *frame, + int (*leq)(void *frame, DictKey key1, DictKey key2) ); + +void dictDeleteDict( Dict *dict ); + +/* Search returns the node with the smallest key greater than or equal + * to the given key. If there is no such key, returns a node whose + * key is NULL. Similarly, Succ(Max(d)) has a NULL key, etc. + */ +DictNode *dictSearch( Dict *dict, DictKey key ); +DictNode *dictInsertBefore( Dict *dict, DictNode *node, DictKey key ); +void dictDelete( Dict *dict, DictNode *node ); + +#define __gl_dictListKey(n) ((n)->key) +#define __gl_dictListSucc(n) ((n)->next) +#define __gl_dictListPred(n) ((n)->prev) +#define __gl_dictListMin(d) ((d)->head.next) +#define __gl_dictListMax(d) ((d)->head.prev) +#define __gl_dictListInsert(d,k) (dictInsertBefore((d),&(d)->head,(k))) + + +/*** Private data structures ***/ + +struct DictNode { + DictKey key; + DictNode *next; + DictNode *prev; +}; + +struct Dict { + DictNode head; + void *frame; + int (*leq)(void *frame, DictKey key1, DictKey key2); +}; + +#endif diff --git a/src/glu/sgi/libtess/dict.c b/src/glu/sgi/libtess/dict.c new file mode 100644 index 0000000..49d4f75 --- /dev/null +++ b/src/glu/sgi/libtess/dict.c @@ -0,0 +1,111 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#include +#include "dict-list.h" +#include "memalloc.h" + +/* really __gl_dictListNewDict */ +Dict *dictNewDict( void *frame, + int (*leq)(void *frame, DictKey key1, DictKey key2) ) +{ + Dict *dict = (Dict *) memAlloc( sizeof( Dict )); + DictNode *head; + + if (dict == NULL) return NULL; + + head = &dict->head; + + head->key = NULL; + head->next = head; + head->prev = head; + + dict->frame = frame; + dict->leq = leq; + + return dict; +} + +/* really __gl_dictListDeleteDict */ +void dictDeleteDict( Dict *dict ) +{ + DictNode *node, *next; + + for( node = dict->head.next; node != &dict->head; node = next ) { + next = node->next; + memFree( node ); + } + memFree( dict ); +} + +/* really __gl_dictListInsertBefore */ +DictNode *dictInsertBefore( Dict *dict, DictNode *node, DictKey key ) +{ + DictNode *newNode; + + do { + node = node->prev; + } while( node->key != NULL && ! (*dict->leq)(dict->frame, node->key, key)); + + newNode = (DictNode *) memAlloc( sizeof( DictNode )); + if (newNode == NULL) return NULL; + + newNode->key = key; + newNode->next = node->next; + node->next->prev = newNode; + newNode->prev = node; + node->next = newNode; + + return newNode; +} + +/* really __gl_dictListDelete */ +void dictDelete( Dict *dict, DictNode *node ) /*ARGSUSED*/ +{ + node->next->prev = node->prev; + node->prev->next = node->next; + memFree( node ); +} + +/* really __gl_dictListSearch */ +DictNode *dictSearch( Dict *dict, DictKey key ) +{ + DictNode *node = &dict->head; + + do { + node = node->next; + } while( node->key != NULL && ! (*dict->leq)(dict->frame, key, node->key)); + + return node; +} diff --git a/src/glu/sgi/libtess/dict.h b/src/glu/sgi/libtess/dict.h new file mode 100644 index 0000000..11331a7 --- /dev/null +++ b/src/glu/sgi/libtess/dict.h @@ -0,0 +1,100 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#ifndef __dict_list_h_ +#define __dict_list_h_ + +/* Use #define's so that another heap implementation can use this one */ + +#define DictKey DictListKey +#define Dict DictList +#define DictNode DictListNode + +#define dictNewDict(frame,leq) __gl_dictListNewDict(frame,leq) +#define dictDeleteDict(dict) __gl_dictListDeleteDict(dict) + +#define dictSearch(dict,key) __gl_dictListSearch(dict,key) +#define dictInsert(dict,key) __gl_dictListInsert(dict,key) +#define dictInsertBefore(dict,node,key) __gl_dictListInsertBefore(dict,node,key) +#define dictDelete(dict,node) __gl_dictListDelete(dict,node) + +#define dictKey(n) __gl_dictListKey(n) +#define dictSucc(n) __gl_dictListSucc(n) +#define dictPred(n) __gl_dictListPred(n) +#define dictMin(d) __gl_dictListMin(d) +#define dictMax(d) __gl_dictListMax(d) + + + +typedef void *DictKey; +typedef struct Dict Dict; +typedef struct DictNode DictNode; + +Dict *dictNewDict( + void *frame, + int (*leq)(void *frame, DictKey key1, DictKey key2) ); + +void dictDeleteDict( Dict *dict ); + +/* Search returns the node with the smallest key greater than or equal + * to the given key. If there is no such key, returns a node whose + * key is NULL. Similarly, Succ(Max(d)) has a NULL key, etc. + */ +DictNode *dictSearch( Dict *dict, DictKey key ); +DictNode *dictInsertBefore( Dict *dict, DictNode *node, DictKey key ); +void dictDelete( Dict *dict, DictNode *node ); + +#define __gl_dictListKey(n) ((n)->key) +#define __gl_dictListSucc(n) ((n)->next) +#define __gl_dictListPred(n) ((n)->prev) +#define __gl_dictListMin(d) ((d)->head.next) +#define __gl_dictListMax(d) ((d)->head.prev) +#define __gl_dictListInsert(d,k) (dictInsertBefore((d),&(d)->head,(k))) + + +/*** Private data structures ***/ + +struct DictNode { + DictKey key; + DictNode *next; + DictNode *prev; +}; + +struct Dict { + DictNode head; + void *frame; + int (*leq)(void *frame, DictKey key1, DictKey key2); +}; + +#endif diff --git a/src/glu/sgi/libtess/geom.c b/src/glu/sgi/libtess/geom.c new file mode 100644 index 0000000..35b36a3 --- /dev/null +++ b/src/glu/sgi/libtess/geom.c @@ -0,0 +1,264 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#include "gluos.h" +#include +#include "mesh.h" +#include "geom.h" + +int __gl_vertLeq( GLUvertex *u, GLUvertex *v ) +{ + /* Returns TRUE if u is lexicographically <= v. */ + + return VertLeq( u, v ); +} + +GLdouble __gl_edgeEval( GLUvertex *u, GLUvertex *v, GLUvertex *w ) +{ + /* Given three vertices u,v,w such that VertLeq(u,v) && VertLeq(v,w), + * evaluates the t-coord of the edge uw at the s-coord of the vertex v. + * Returns v->t - (uw)(v->s), ie. the signed distance from uw to v. + * If uw is vertical (and thus passes thru v), the result is zero. + * + * The calculation is extremely accurate and stable, even when v + * is very close to u or w. In particular if we set v->t = 0 and + * let r be the negated result (this evaluates (uw)(v->s)), then + * r is guaranteed to satisfy MIN(u->t,w->t) <= r <= MAX(u->t,w->t). + */ + GLdouble gapL, gapR; + + assert( VertLeq( u, v ) && VertLeq( v, w )); + + gapL = v->s - u->s; + gapR = w->s - v->s; + + if( gapL + gapR > 0 ) { + if( gapL < gapR ) { + return (v->t - u->t) + (u->t - w->t) * (gapL / (gapL + gapR)); + } else { + return (v->t - w->t) + (w->t - u->t) * (gapR / (gapL + gapR)); + } + } + /* vertical line */ + return 0; +} + +GLdouble __gl_edgeSign( GLUvertex *u, GLUvertex *v, GLUvertex *w ) +{ + /* Returns a number whose sign matches EdgeEval(u,v,w) but which + * is cheaper to evaluate. Returns > 0, == 0 , or < 0 + * as v is above, on, or below the edge uw. + */ + GLdouble gapL, gapR; + + assert( VertLeq( u, v ) && VertLeq( v, w )); + + gapL = v->s - u->s; + gapR = w->s - v->s; + + if( gapL + gapR > 0 ) { + return (v->t - w->t) * gapL + (v->t - u->t) * gapR; + } + /* vertical line */ + return 0; +} + + +/*********************************************************************** + * Define versions of EdgeSign, EdgeEval with s and t transposed. + */ + +GLdouble __gl_transEval( GLUvertex *u, GLUvertex *v, GLUvertex *w ) +{ + /* Given three vertices u,v,w such that TransLeq(u,v) && TransLeq(v,w), + * evaluates the t-coord of the edge uw at the s-coord of the vertex v. + * Returns v->s - (uw)(v->t), ie. the signed distance from uw to v. + * If uw is vertical (and thus passes thru v), the result is zero. + * + * The calculation is extremely accurate and stable, even when v + * is very close to u or w. In particular if we set v->s = 0 and + * let r be the negated result (this evaluates (uw)(v->t)), then + * r is guaranteed to satisfy MIN(u->s,w->s) <= r <= MAX(u->s,w->s). + */ + GLdouble gapL, gapR; + + assert( TransLeq( u, v ) && TransLeq( v, w )); + + gapL = v->t - u->t; + gapR = w->t - v->t; + + if( gapL + gapR > 0 ) { + if( gapL < gapR ) { + return (v->s - u->s) + (u->s - w->s) * (gapL / (gapL + gapR)); + } else { + return (v->s - w->s) + (w->s - u->s) * (gapR / (gapL + gapR)); + } + } + /* vertical line */ + return 0; +} + +GLdouble __gl_transSign( GLUvertex *u, GLUvertex *v, GLUvertex *w ) +{ + /* Returns a number whose sign matches TransEval(u,v,w) but which + * is cheaper to evaluate. Returns > 0, == 0 , or < 0 + * as v is above, on, or below the edge uw. + */ + GLdouble gapL, gapR; + + assert( TransLeq( u, v ) && TransLeq( v, w )); + + gapL = v->t - u->t; + gapR = w->t - v->t; + + if( gapL + gapR > 0 ) { + return (v->s - w->s) * gapL + (v->s - u->s) * gapR; + } + /* vertical line */ + return 0; +} + + +int __gl_vertCCW( GLUvertex *u, GLUvertex *v, GLUvertex *w ) +{ + /* For almost-degenerate situations, the results are not reliable. + * Unless the floating-point arithmetic can be performed without + * rounding errors, *any* implementation will give incorrect results + * on some degenerate inputs, so the client must have some way to + * handle this situation. + */ + return (u->s*(v->t - w->t) + v->s*(w->t - u->t) + w->s*(u->t - v->t)) >= 0; +} + +/* Given parameters a,x,b,y returns the value (b*x+a*y)/(a+b), + * or (x+y)/2 if a==b==0. It requires that a,b >= 0, and enforces + * this in the rare case that one argument is slightly negative. + * The implementation is extremely stable numerically. + * In particular it guarantees that the result r satisfies + * MIN(x,y) <= r <= MAX(x,y), and the results are very accurate + * even when a and b differ greatly in magnitude. + */ +#define RealInterpolate(a,x,b,y) \ + (a = (a < 0) ? 0 : a, b = (b < 0) ? 0 : b, \ + ((a <= b) ? ((b == 0) ? ((x+y) / 2) \ + : (x + (y-x) * (a/(a+b)))) \ + : (y + (x-y) * (b/(a+b))))) + +#ifndef FOR_TRITE_TEST_PROGRAM +#define Interpolate(a,x,b,y) RealInterpolate(a,x,b,y) +#else + +/* Claim: the ONLY property the sweep algorithm relies on is that + * MIN(x,y) <= r <= MAX(x,y). This is a nasty way to test that. + */ +#include +extern int RandomInterpolate; + +GLdouble Interpolate( GLdouble a, GLdouble x, GLdouble b, GLdouble y) +{ +printf("*********************%d\n",RandomInterpolate); + if( RandomInterpolate ) { + a = 1.2 * drand48() - 0.1; + a = (a < 0) ? 0 : ((a > 1) ? 1 : a); + b = 1.0 - a; + } + return RealInterpolate(a,x,b,y); +} + +#endif + +#define Swap(a,b) do { GLUvertex *t = a; a = b; b = t; } while (0) + +void __gl_edgeIntersect( GLUvertex *o1, GLUvertex *d1, + GLUvertex *o2, GLUvertex *d2, + GLUvertex *v ) +/* Given edges (o1,d1) and (o2,d2), compute their point of intersection. + * The computed point is guaranteed to lie in the intersection of the + * bounding rectangles defined by each edge. + */ +{ + GLdouble z1, z2; + + /* This is certainly not the most efficient way to find the intersection + * of two line segments, but it is very numerically stable. + * + * Strategy: find the two middle vertices in the VertLeq ordering, + * and interpolate the intersection s-value from these. Then repeat + * using the TransLeq ordering to find the intersection t-value. + */ + + if( ! VertLeq( o1, d1 )) { Swap( o1, d1 ); } + if( ! VertLeq( o2, d2 )) { Swap( o2, d2 ); } + if( ! VertLeq( o1, o2 )) { Swap( o1, o2 ); Swap( d1, d2 ); } + + if( ! VertLeq( o2, d1 )) { + /* Technically, no intersection -- do our best */ + v->s = (o2->s + d1->s) / 2; + } else if( VertLeq( d1, d2 )) { + /* Interpolate between o2 and d1 */ + z1 = EdgeEval( o1, o2, d1 ); + z2 = EdgeEval( o2, d1, d2 ); + if( z1+z2 < 0 ) { z1 = -z1; z2 = -z2; } + v->s = Interpolate( z1, o2->s, z2, d1->s ); + } else { + /* Interpolate between o2 and d2 */ + z1 = EdgeSign( o1, o2, d1 ); + z2 = -EdgeSign( o1, d2, d1 ); + if( z1+z2 < 0 ) { z1 = -z1; z2 = -z2; } + v->s = Interpolate( z1, o2->s, z2, d2->s ); + } + + /* Now repeat the process for t */ + + if( ! TransLeq( o1, d1 )) { Swap( o1, d1 ); } + if( ! TransLeq( o2, d2 )) { Swap( o2, d2 ); } + if( ! TransLeq( o1, o2 )) { Swap( o1, o2 ); Swap( d1, d2 ); } + + if( ! TransLeq( o2, d1 )) { + /* Technically, no intersection -- do our best */ + v->t = (o2->t + d1->t) / 2; + } else if( TransLeq( d1, d2 )) { + /* Interpolate between o2 and d1 */ + z1 = TransEval( o1, o2, d1 ); + z2 = TransEval( o2, d1, d2 ); + if( z1+z2 < 0 ) { z1 = -z1; z2 = -z2; } + v->t = Interpolate( z1, o2->t, z2, d1->t ); + } else { + /* Interpolate between o2 and d2 */ + z1 = TransSign( o1, o2, d1 ); + z2 = -TransSign( o1, d2, d1 ); + if( z1+z2 < 0 ) { z1 = -z1; z2 = -z2; } + v->t = Interpolate( z1, o2->t, z2, d2->t ); + } +} diff --git a/src/glu/sgi/libtess/geom.h b/src/glu/sgi/libtess/geom.h new file mode 100644 index 0000000..5cb76c7 --- /dev/null +++ b/src/glu/sgi/libtess/geom.h @@ -0,0 +1,84 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#ifndef __geom_h_ +#define __geom_h_ + +#include "mesh.h" + +#ifdef NO_BRANCH_CONDITIONS +/* MIPS architecture has special instructions to evaluate boolean + * conditions -- more efficient than branching, IF you can get the + * compiler to generate the right instructions (SGI compiler doesn't) + */ +#define VertEq(u,v) (((u)->s == (v)->s) & ((u)->t == (v)->t)) +#define VertLeq(u,v) (((u)->s < (v)->s) | \ + ((u)->s == (v)->s & (u)->t <= (v)->t)) +#else +#define VertEq(u,v) ((u)->s == (v)->s && (u)->t == (v)->t) +#define VertLeq(u,v) (((u)->s < (v)->s) || \ + ((u)->s == (v)->s && (u)->t <= (v)->t)) +#endif + +#define EdgeEval(u,v,w) __gl_edgeEval(u,v,w) +#define EdgeSign(u,v,w) __gl_edgeSign(u,v,w) + +/* Versions of VertLeq, EdgeSign, EdgeEval with s and t transposed. */ + +#define TransLeq(u,v) (((u)->t < (v)->t) || \ + ((u)->t == (v)->t && (u)->s <= (v)->s)) +#define TransEval(u,v,w) __gl_transEval(u,v,w) +#define TransSign(u,v,w) __gl_transSign(u,v,w) + + +#define EdgeGoesLeft(e) VertLeq( (e)->Dst, (e)->Org ) +#define EdgeGoesRight(e) VertLeq( (e)->Org, (e)->Dst ) + +#undef ABS +#define ABS(x) ((x) < 0 ? -(x) : (x)) +#define VertL1dist(u,v) (ABS(u->s - v->s) + ABS(u->t - v->t)) + +#define VertCCW(u,v,w) __gl_vertCCW(u,v,w) + +int __gl_vertLeq( GLUvertex *u, GLUvertex *v ); +GLdouble __gl_edgeEval( GLUvertex *u, GLUvertex *v, GLUvertex *w ); +GLdouble __gl_edgeSign( GLUvertex *u, GLUvertex *v, GLUvertex *w ); +GLdouble __gl_transEval( GLUvertex *u, GLUvertex *v, GLUvertex *w ); +GLdouble __gl_transSign( GLUvertex *u, GLUvertex *v, GLUvertex *w ); +int __gl_vertCCW( GLUvertex *u, GLUvertex *v, GLUvertex *w ); +void __gl_edgeIntersect( GLUvertex *o1, GLUvertex *d1, + GLUvertex *o2, GLUvertex *d2, + GLUvertex *v ); + +#endif diff --git a/src/glu/sgi/libtess/memalloc.c b/src/glu/sgi/libtess/memalloc.c new file mode 100644 index 0000000..81879ef --- /dev/null +++ b/src/glu/sgi/libtess/memalloc.c @@ -0,0 +1,55 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#include "memalloc.h" +#include "string.h" + +int __gl_memInit( size_t maxFast ) +{ +#ifndef NO_MALLOPT +/* mallopt( M_MXFAST, maxFast );*/ +#ifdef MEMORY_DEBUG + mallopt( M_DEBUG, 1 ); +#endif +#endif + return 1; +} + +#ifdef MEMORY_DEBUG +void *__gl_memAlloc( size_t n ) +{ + return memset( malloc( n ), 0xa5, n ); +} +#endif + diff --git a/src/glu/sgi/libtess/memalloc.h b/src/glu/sgi/libtess/memalloc.h new file mode 100644 index 0000000..c2f969b --- /dev/null +++ b/src/glu/sgi/libtess/memalloc.h @@ -0,0 +1,54 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#ifndef __memalloc_simple_h_ +#define __memalloc_simple_h_ + +#include + +#define memRealloc realloc +#define memFree free + +#define memInit __gl_memInit +/*extern void __gl_memInit( size_t );*/ +extern int __gl_memInit( size_t ); + +#ifndef MEMORY_DEBUG +#define memAlloc malloc +#else +#define memAlloc __gl_memAlloc +extern void * __gl_memAlloc( size_t ); +#endif + +#endif diff --git a/src/glu/sgi/libtess/mesh.c b/src/glu/sgi/libtess/mesh.c new file mode 100644 index 0000000..36cb3a7 --- /dev/null +++ b/src/glu/sgi/libtess/mesh.c @@ -0,0 +1,798 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#include "gluos.h" +#include +#include +#include "mesh.h" +#include "memalloc.h" + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +static GLUvertex *allocVertex() +{ + return (GLUvertex *)memAlloc( sizeof( GLUvertex )); +} + +static GLUface *allocFace() +{ + return (GLUface *)memAlloc( sizeof( GLUface )); +} + +/************************ Utility Routines ************************/ + +/* Allocate and free half-edges in pairs for efficiency. + * The *only* place that should use this fact is allocation/free. + */ +typedef struct { GLUhalfEdge e, eSym; } EdgePair; + +/* MakeEdge creates a new pair of half-edges which form their own loop. + * No vertex or face structures are allocated, but these must be assigned + * before the current edge operation is completed. + */ +static GLUhalfEdge *MakeEdge( GLUhalfEdge *eNext ) +{ + GLUhalfEdge *e; + GLUhalfEdge *eSym; + GLUhalfEdge *ePrev; + EdgePair *pair = (EdgePair *)memAlloc( sizeof( EdgePair )); + if (pair == NULL) return NULL; + + e = &pair->e; + eSym = &pair->eSym; + + /* Make sure eNext points to the first edge of the edge pair */ + if( eNext->Sym < eNext ) { eNext = eNext->Sym; } + + /* Insert in circular doubly-linked list before eNext. + * Note that the prev pointer is stored in Sym->next. + */ + ePrev = eNext->Sym->next; + eSym->next = ePrev; + ePrev->Sym->next = e; + e->next = eNext; + eNext->Sym->next = eSym; + + e->Sym = eSym; + e->Onext = e; + e->Lnext = eSym; + e->Org = NULL; + e->Lface = NULL; + e->winding = 0; + e->activeRegion = NULL; + + eSym->Sym = e; + eSym->Onext = eSym; + eSym->Lnext = e; + eSym->Org = NULL; + eSym->Lface = NULL; + eSym->winding = 0; + eSym->activeRegion = NULL; + + return e; +} + +/* Splice( a, b ) is best described by the Guibas/Stolfi paper or the + * CS348a notes (see mesh.h). Basically it modifies the mesh so that + * a->Onext and b->Onext are exchanged. This can have various effects + * depending on whether a and b belong to different face or vertex rings. + * For more explanation see __gl_meshSplice() below. + */ +static void Splice( GLUhalfEdge *a, GLUhalfEdge *b ) +{ + GLUhalfEdge *aOnext = a->Onext; + GLUhalfEdge *bOnext = b->Onext; + + aOnext->Sym->Lnext = b; + bOnext->Sym->Lnext = a; + a->Onext = bOnext; + b->Onext = aOnext; +} + +/* MakeVertex( newVertex, eOrig, vNext ) attaches a new vertex and makes it the + * origin of all edges in the vertex loop to which eOrig belongs. "vNext" gives + * a place to insert the new vertex in the global vertex list. We insert + * the new vertex *before* vNext so that algorithms which walk the vertex + * list will not see the newly created vertices. + */ +static void MakeVertex( GLUvertex *newVertex, + GLUhalfEdge *eOrig, GLUvertex *vNext ) +{ + GLUhalfEdge *e; + GLUvertex *vPrev; + GLUvertex *vNew = newVertex; + + assert(vNew != NULL); + + /* insert in circular doubly-linked list before vNext */ + vPrev = vNext->prev; + vNew->prev = vPrev; + vPrev->next = vNew; + vNew->next = vNext; + vNext->prev = vNew; + + vNew->anEdge = eOrig; + vNew->data = NULL; + /* leave coords, s, t undefined */ + + /* fix other edges on this vertex loop */ + e = eOrig; + do { + e->Org = vNew; + e = e->Onext; + } while( e != eOrig ); +} + +/* MakeFace( newFace, eOrig, fNext ) attaches a new face and makes it the left + * face of all edges in the face loop to which eOrig belongs. "fNext" gives + * a place to insert the new face in the global face list. We insert + * the new face *before* fNext so that algorithms which walk the face + * list will not see the newly created faces. + */ +static void MakeFace( GLUface *newFace, GLUhalfEdge *eOrig, GLUface *fNext ) +{ + GLUhalfEdge *e; + GLUface *fPrev; + GLUface *fNew = newFace; + + assert(fNew != NULL); + + /* insert in circular doubly-linked list before fNext */ + fPrev = fNext->prev; + fNew->prev = fPrev; + fPrev->next = fNew; + fNew->next = fNext; + fNext->prev = fNew; + + fNew->anEdge = eOrig; + fNew->data = NULL; + fNew->trail = NULL; + fNew->marked = FALSE; + + /* The new face is marked "inside" if the old one was. This is a + * convenience for the common case where a face has been split in two. + */ + fNew->inside = fNext->inside; + + /* fix other edges on this face loop */ + e = eOrig; + do { + e->Lface = fNew; + e = e->Lnext; + } while( e != eOrig ); +} + +/* KillEdge( eDel ) destroys an edge (the half-edges eDel and eDel->Sym), + * and removes from the global edge list. + */ +static void KillEdge( GLUhalfEdge *eDel ) +{ + GLUhalfEdge *ePrev, *eNext; + + /* Half-edges are allocated in pairs, see EdgePair above */ + if( eDel->Sym < eDel ) { eDel = eDel->Sym; } + + /* delete from circular doubly-linked list */ + eNext = eDel->next; + ePrev = eDel->Sym->next; + eNext->Sym->next = ePrev; + ePrev->Sym->next = eNext; + + memFree( eDel ); +} + + +/* KillVertex( vDel ) destroys a vertex and removes it from the global + * vertex list. It updates the vertex loop to point to a given new vertex. + */ +static void KillVertex( GLUvertex *vDel, GLUvertex *newOrg ) +{ + GLUhalfEdge *e, *eStart = vDel->anEdge; + GLUvertex *vPrev, *vNext; + + /* change the origin of all affected edges */ + e = eStart; + do { + e->Org = newOrg; + e = e->Onext; + } while( e != eStart ); + + /* delete from circular doubly-linked list */ + vPrev = vDel->prev; + vNext = vDel->next; + vNext->prev = vPrev; + vPrev->next = vNext; + + memFree( vDel ); +} + +/* KillFace( fDel ) destroys a face and removes it from the global face + * list. It updates the face loop to point to a given new face. + */ +static void KillFace( GLUface *fDel, GLUface *newLface ) +{ + GLUhalfEdge *e, *eStart = fDel->anEdge; + GLUface *fPrev, *fNext; + + /* change the left face of all affected edges */ + e = eStart; + do { + e->Lface = newLface; + e = e->Lnext; + } while( e != eStart ); + + /* delete from circular doubly-linked list */ + fPrev = fDel->prev; + fNext = fDel->next; + fNext->prev = fPrev; + fPrev->next = fNext; + + memFree( fDel ); +} + + +/****************** Basic Edge Operations **********************/ + +/* __gl_meshMakeEdge creates one edge, two vertices, and a loop (face). + * The loop consists of the two new half-edges. + */ +GLUhalfEdge *__gl_meshMakeEdge( GLUmesh *mesh ) +{ + GLUvertex *newVertex1= allocVertex(); + GLUvertex *newVertex2= allocVertex(); + GLUface *newFace= allocFace(); + GLUhalfEdge *e; + + /* if any one is null then all get freed */ + if (newVertex1 == NULL || newVertex2 == NULL || newFace == NULL) { + if (newVertex1 != NULL) memFree(newVertex1); + if (newVertex2 != NULL) memFree(newVertex2); + if (newFace != NULL) memFree(newFace); + return NULL; + } + + e = MakeEdge( &mesh->eHead ); + if (e == NULL) { + memFree(newVertex1); + memFree(newVertex2); + memFree(newFace); + return NULL; + } + + MakeVertex( newVertex1, e, &mesh->vHead ); + MakeVertex( newVertex2, e->Sym, &mesh->vHead ); + MakeFace( newFace, e, &mesh->fHead ); + return e; +} + + +/* __gl_meshSplice( eOrg, eDst ) is the basic operation for changing the + * mesh connectivity and topology. It changes the mesh so that + * eOrg->Onext <- OLD( eDst->Onext ) + * eDst->Onext <- OLD( eOrg->Onext ) + * where OLD(...) means the value before the meshSplice operation. + * + * This can have two effects on the vertex structure: + * - if eOrg->Org != eDst->Org, the two vertices are merged together + * - if eOrg->Org == eDst->Org, the origin is split into two vertices + * In both cases, eDst->Org is changed and eOrg->Org is untouched. + * + * Similarly (and independently) for the face structure, + * - if eOrg->Lface == eDst->Lface, one loop is split into two + * - if eOrg->Lface != eDst->Lface, two distinct loops are joined into one + * In both cases, eDst->Lface is changed and eOrg->Lface is unaffected. + * + * Some special cases: + * If eDst == eOrg, the operation has no effect. + * If eDst == eOrg->Lnext, the new face will have a single edge. + * If eDst == eOrg->Lprev, the old face will have a single edge. + * If eDst == eOrg->Onext, the new vertex will have a single edge. + * If eDst == eOrg->Oprev, the old vertex will have a single edge. + */ +int __gl_meshSplice( GLUhalfEdge *eOrg, GLUhalfEdge *eDst ) +{ + int joiningLoops = FALSE; + int joiningVertices = FALSE; + + if( eOrg == eDst ) return 1; + + if( eDst->Org != eOrg->Org ) { + /* We are merging two disjoint vertices -- destroy eDst->Org */ + joiningVertices = TRUE; + KillVertex( eDst->Org, eOrg->Org ); + } + if( eDst->Lface != eOrg->Lface ) { + /* We are connecting two disjoint loops -- destroy eDst->Lface */ + joiningLoops = TRUE; + KillFace( eDst->Lface, eOrg->Lface ); + } + + /* Change the edge structure */ + Splice( eDst, eOrg ); + + if( ! joiningVertices ) { + GLUvertex *newVertex= allocVertex(); + if (newVertex == NULL) return 0; + + /* We split one vertex into two -- the new vertex is eDst->Org. + * Make sure the old vertex points to a valid half-edge. + */ + MakeVertex( newVertex, eDst, eOrg->Org ); + eOrg->Org->anEdge = eOrg; + } + if( ! joiningLoops ) { + GLUface *newFace= allocFace(); + if (newFace == NULL) return 0; + + /* We split one loop into two -- the new loop is eDst->Lface. + * Make sure the old face points to a valid half-edge. + */ + MakeFace( newFace, eDst, eOrg->Lface ); + eOrg->Lface->anEdge = eOrg; + } + + return 1; +} + + +/* __gl_meshDelete( eDel ) removes the edge eDel. There are several cases: + * if (eDel->Lface != eDel->Rface), we join two loops into one; the loop + * eDel->Lface is deleted. Otherwise, we are splitting one loop into two; + * the newly created loop will contain eDel->Dst. If the deletion of eDel + * would create isolated vertices, those are deleted as well. + * + * This function could be implemented as two calls to __gl_meshSplice + * plus a few calls to memFree, but this would allocate and delete + * unnecessary vertices and faces. + */ +int __gl_meshDelete( GLUhalfEdge *eDel ) +{ + GLUhalfEdge *eDelSym = eDel->Sym; + int joiningLoops = FALSE; + + /* First step: disconnect the origin vertex eDel->Org. We make all + * changes to get a consistent mesh in this "intermediate" state. + */ + if( eDel->Lface != eDel->Rface ) { + /* We are joining two loops into one -- remove the left face */ + joiningLoops = TRUE; + KillFace( eDel->Lface, eDel->Rface ); + } + + if( eDel->Onext == eDel ) { + KillVertex( eDel->Org, NULL ); + } else { + /* Make sure that eDel->Org and eDel->Rface point to valid half-edges */ + eDel->Rface->anEdge = eDel->Oprev; + eDel->Org->anEdge = eDel->Onext; + + Splice( eDel, eDel->Oprev ); + if( ! joiningLoops ) { + GLUface *newFace= allocFace(); + if (newFace == NULL) return 0; + + /* We are splitting one loop into two -- create a new loop for eDel. */ + MakeFace( newFace, eDel, eDel->Lface ); + } + } + + /* Claim: the mesh is now in a consistent state, except that eDel->Org + * may have been deleted. Now we disconnect eDel->Dst. + */ + if( eDelSym->Onext == eDelSym ) { + KillVertex( eDelSym->Org, NULL ); + KillFace( eDelSym->Lface, NULL ); + } else { + /* Make sure that eDel->Dst and eDel->Lface point to valid half-edges */ + eDel->Lface->anEdge = eDelSym->Oprev; + eDelSym->Org->anEdge = eDelSym->Onext; + Splice( eDelSym, eDelSym->Oprev ); + } + + /* Any isolated vertices or faces have already been freed. */ + KillEdge( eDel ); + + return 1; +} + + +/******************** Other Edge Operations **********************/ + +/* All these routines can be implemented with the basic edge + * operations above. They are provided for convenience and efficiency. + */ + + +/* __gl_meshAddEdgeVertex( eOrg ) creates a new edge eNew such that + * eNew == eOrg->Lnext, and eNew->Dst is a newly created vertex. + * eOrg and eNew will have the same left face. + */ +GLUhalfEdge *__gl_meshAddEdgeVertex( GLUhalfEdge *eOrg ) +{ + GLUhalfEdge *eNewSym; + GLUhalfEdge *eNew = MakeEdge( eOrg ); + if (eNew == NULL) return NULL; + + eNewSym = eNew->Sym; + + /* Connect the new edge appropriately */ + Splice( eNew, eOrg->Lnext ); + + /* Set the vertex and face information */ + eNew->Org = eOrg->Dst; + { + GLUvertex *newVertex= allocVertex(); + if (newVertex == NULL) return NULL; + + MakeVertex( newVertex, eNewSym, eNew->Org ); + } + eNew->Lface = eNewSym->Lface = eOrg->Lface; + + return eNew; +} + + +/* __gl_meshSplitEdge( eOrg ) splits eOrg into two edges eOrg and eNew, + * such that eNew == eOrg->Lnext. The new vertex is eOrg->Dst == eNew->Org. + * eOrg and eNew will have the same left face. + */ +GLUhalfEdge *__gl_meshSplitEdge( GLUhalfEdge *eOrg ) +{ + GLUhalfEdge *eNew; + GLUhalfEdge *tempHalfEdge= __gl_meshAddEdgeVertex( eOrg ); + if (tempHalfEdge == NULL) return NULL; + + eNew = tempHalfEdge->Sym; + + /* Disconnect eOrg from eOrg->Dst and connect it to eNew->Org */ + Splice( eOrg->Sym, eOrg->Sym->Oprev ); + Splice( eOrg->Sym, eNew ); + + /* Set the vertex and face information */ + eOrg->Dst = eNew->Org; + eNew->Dst->anEdge = eNew->Sym; /* may have pointed to eOrg->Sym */ + eNew->Rface = eOrg->Rface; + eNew->winding = eOrg->winding; /* copy old winding information */ + eNew->Sym->winding = eOrg->Sym->winding; + + return eNew; +} + + +/* __gl_meshConnect( eOrg, eDst ) creates a new edge from eOrg->Dst + * to eDst->Org, and returns the corresponding half-edge eNew. + * If eOrg->Lface == eDst->Lface, this splits one loop into two, + * and the newly created loop is eNew->Lface. Otherwise, two disjoint + * loops are merged into one, and the loop eDst->Lface is destroyed. + * + * If (eOrg == eDst), the new face will have only two edges. + * If (eOrg->Lnext == eDst), the old face is reduced to a single edge. + * If (eOrg->Lnext->Lnext == eDst), the old face is reduced to two edges. + */ +GLUhalfEdge *__gl_meshConnect( GLUhalfEdge *eOrg, GLUhalfEdge *eDst ) +{ + GLUhalfEdge *eNewSym; + int joiningLoops = FALSE; + GLUhalfEdge *eNew = MakeEdge( eOrg ); + if (eNew == NULL) return NULL; + + eNewSym = eNew->Sym; + + if( eDst->Lface != eOrg->Lface ) { + /* We are connecting two disjoint loops -- destroy eDst->Lface */ + joiningLoops = TRUE; + KillFace( eDst->Lface, eOrg->Lface ); + } + + /* Connect the new edge appropriately */ + Splice( eNew, eOrg->Lnext ); + Splice( eNewSym, eDst ); + + /* Set the vertex and face information */ + eNew->Org = eOrg->Dst; + eNewSym->Org = eDst->Org; + eNew->Lface = eNewSym->Lface = eOrg->Lface; + + /* Make sure the old face points to a valid half-edge */ + eOrg->Lface->anEdge = eNewSym; + + if( ! joiningLoops ) { + GLUface *newFace= allocFace(); + if (newFace == NULL) return NULL; + + /* We split one loop into two -- the new loop is eNew->Lface */ + MakeFace( newFace, eNew, eOrg->Lface ); + } + return eNew; +} + + +/******************** Other Operations **********************/ + +/* __gl_meshZapFace( fZap ) destroys a face and removes it from the + * global face list. All edges of fZap will have a NULL pointer as their + * left face. Any edges which also have a NULL pointer as their right face + * are deleted entirely (along with any isolated vertices this produces). + * An entire mesh can be deleted by zapping its faces, one at a time, + * in any order. Zapped faces cannot be used in further mesh operations! + */ +void __gl_meshZapFace( GLUface *fZap ) +{ + GLUhalfEdge *eStart = fZap->anEdge; + GLUhalfEdge *e, *eNext, *eSym; + GLUface *fPrev, *fNext; + + /* walk around face, deleting edges whose right face is also NULL */ + eNext = eStart->Lnext; + do { + e = eNext; + eNext = e->Lnext; + + e->Lface = NULL; + if( e->Rface == NULL ) { + /* delete the edge -- see __gl_MeshDelete above */ + + if( e->Onext == e ) { + KillVertex( e->Org, NULL ); + } else { + /* Make sure that e->Org points to a valid half-edge */ + e->Org->anEdge = e->Onext; + Splice( e, e->Oprev ); + } + eSym = e->Sym; + if( eSym->Onext == eSym ) { + KillVertex( eSym->Org, NULL ); + } else { + /* Make sure that eSym->Org points to a valid half-edge */ + eSym->Org->anEdge = eSym->Onext; + Splice( eSym, eSym->Oprev ); + } + KillEdge( e ); + } + } while( e != eStart ); + + /* delete from circular doubly-linked list */ + fPrev = fZap->prev; + fNext = fZap->next; + fNext->prev = fPrev; + fPrev->next = fNext; + + memFree( fZap ); +} + + +/* __gl_meshNewMesh() creates a new mesh with no edges, no vertices, + * and no loops (what we usually call a "face"). + */ +GLUmesh *__gl_meshNewMesh( void ) +{ + GLUvertex *v; + GLUface *f; + GLUhalfEdge *e; + GLUhalfEdge *eSym; + GLUmesh *mesh = (GLUmesh *)memAlloc( sizeof( GLUmesh )); + if (mesh == NULL) { + return NULL; + } + + v = &mesh->vHead; + f = &mesh->fHead; + e = &mesh->eHead; + eSym = &mesh->eHeadSym; + + v->next = v->prev = v; + v->anEdge = NULL; + v->data = NULL; + + f->next = f->prev = f; + f->anEdge = NULL; + f->data = NULL; + f->trail = NULL; + f->marked = FALSE; + f->inside = FALSE; + + e->next = e; + e->Sym = eSym; + e->Onext = NULL; + e->Lnext = NULL; + e->Org = NULL; + e->Lface = NULL; + e->winding = 0; + e->activeRegion = NULL; + + eSym->next = eSym; + eSym->Sym = e; + eSym->Onext = NULL; + eSym->Lnext = NULL; + eSym->Org = NULL; + eSym->Lface = NULL; + eSym->winding = 0; + eSym->activeRegion = NULL; + + return mesh; +} + + +/* __gl_meshUnion( mesh1, mesh2 ) forms the union of all structures in + * both meshes, and returns the new mesh (the old meshes are destroyed). + */ +GLUmesh *__gl_meshUnion( GLUmesh *mesh1, GLUmesh *mesh2 ) +{ + GLUface *f1 = &mesh1->fHead; + GLUvertex *v1 = &mesh1->vHead; + GLUhalfEdge *e1 = &mesh1->eHead; + GLUface *f2 = &mesh2->fHead; + GLUvertex *v2 = &mesh2->vHead; + GLUhalfEdge *e2 = &mesh2->eHead; + + /* Add the faces, vertices, and edges of mesh2 to those of mesh1 */ + if( f2->next != f2 ) { + f1->prev->next = f2->next; + f2->next->prev = f1->prev; + f2->prev->next = f1; + f1->prev = f2->prev; + } + + if( v2->next != v2 ) { + v1->prev->next = v2->next; + v2->next->prev = v1->prev; + v2->prev->next = v1; + v1->prev = v2->prev; + } + + if( e2->next != e2 ) { + e1->Sym->next->Sym->next = e2->next; + e2->next->Sym->next = e1->Sym->next; + e2->Sym->next->Sym->next = e1; + e1->Sym->next = e2->Sym->next; + } + + memFree( mesh2 ); + return mesh1; +} + + +#ifdef DELETE_BY_ZAPPING + +/* __gl_meshDeleteMesh( mesh ) will free all storage for any valid mesh. + */ +void __gl_meshDeleteMesh( GLUmesh *mesh ) +{ + GLUface *fHead = &mesh->fHead; + + while( fHead->next != fHead ) { + __gl_meshZapFace( fHead->next ); + } + assert( mesh->vHead.next == &mesh->vHead ); + + memFree( mesh ); +} + +#else + +/* __gl_meshDeleteMesh( mesh ) will free all storage for any valid mesh. + */ +void __gl_meshDeleteMesh( GLUmesh *mesh ) +{ + GLUface *f, *fNext; + GLUvertex *v, *vNext; + GLUhalfEdge *e, *eNext; + + for( f = mesh->fHead.next; f != &mesh->fHead; f = fNext ) { + fNext = f->next; + memFree( f ); + } + + for( v = mesh->vHead.next; v != &mesh->vHead; v = vNext ) { + vNext = v->next; + memFree( v ); + } + + for( e = mesh->eHead.next; e != &mesh->eHead; e = eNext ) { + /* One call frees both e and e->Sym (see EdgePair above) */ + eNext = e->next; + memFree( e ); + } + + memFree( mesh ); +} + +#endif + +#ifndef NDEBUG + +/* __gl_meshCheckMesh( mesh ) checks a mesh for self-consistency. + */ +void __gl_meshCheckMesh( GLUmesh *mesh ) +{ + GLUface *fHead = &mesh->fHead; + GLUvertex *vHead = &mesh->vHead; + GLUhalfEdge *eHead = &mesh->eHead; + GLUface *f, *fPrev; + GLUvertex *v, *vPrev; + GLUhalfEdge *e, *ePrev; + + fPrev = fHead; + for( fPrev = fHead ; (f = fPrev->next) != fHead; fPrev = f) { + assert( f->prev == fPrev ); + e = f->anEdge; + do { + assert( e->Sym != e ); + assert( e->Sym->Sym == e ); + assert( e->Lnext->Onext->Sym == e ); + assert( e->Onext->Sym->Lnext == e ); + assert( e->Lface == f ); + e = e->Lnext; + } while( e != f->anEdge ); + } + assert( f->prev == fPrev && f->anEdge == NULL && f->data == NULL ); + + vPrev = vHead; + for( vPrev = vHead ; (v = vPrev->next) != vHead; vPrev = v) { + assert( v->prev == vPrev ); + e = v->anEdge; + do { + assert( e->Sym != e ); + assert( e->Sym->Sym == e ); + assert( e->Lnext->Onext->Sym == e ); + assert( e->Onext->Sym->Lnext == e ); + assert( e->Org == v ); + e = e->Onext; + } while( e != v->anEdge ); + } + assert( v->prev == vPrev && v->anEdge == NULL && v->data == NULL ); + + ePrev = eHead; + for( ePrev = eHead ; (e = ePrev->next) != eHead; ePrev = e) { + assert( e->Sym->next == ePrev->Sym ); + assert( e->Sym != e ); + assert( e->Sym->Sym == e ); + assert( e->Org != NULL ); + assert( e->Dst != NULL ); + assert( e->Lnext->Onext->Sym == e ); + assert( e->Onext->Sym->Lnext == e ); + } + assert( e->Sym->next == ePrev->Sym + && e->Sym == &mesh->eHeadSym + && e->Sym->Sym == e + && e->Org == NULL && e->Dst == NULL + && e->Lface == NULL && e->Rface == NULL ); +} + +#endif diff --git a/src/glu/sgi/libtess/mesh.h b/src/glu/sgi/libtess/mesh.h new file mode 100644 index 0000000..690c5f2 --- /dev/null +++ b/src/glu/sgi/libtess/mesh.h @@ -0,0 +1,266 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#ifndef __mesh_h_ +#define __mesh_h_ + +#include + +typedef struct GLUmesh GLUmesh; + +typedef struct GLUvertex GLUvertex; +typedef struct GLUface GLUface; +typedef struct GLUhalfEdge GLUhalfEdge; + +typedef struct ActiveRegion ActiveRegion; /* Internal data */ + +/* The mesh structure is similar in spirit, notation, and operations + * to the "quad-edge" structure (see L. Guibas and J. Stolfi, Primitives + * for the manipulation of general subdivisions and the computation of + * Voronoi diagrams, ACM Transactions on Graphics, 4(2):74-123, April 1985). + * For a simplified description, see the course notes for CS348a, + * "Mathematical Foundations of Computer Graphics", available at the + * Stanford bookstore (and taught during the fall quarter). + * The implementation also borrows a tiny subset of the graph-based approach + * use in Mantyla's Geometric Work Bench (see M. Mantyla, An Introduction + * to Sold Modeling, Computer Science Press, Rockville, Maryland, 1988). + * + * The fundamental data structure is the "half-edge". Two half-edges + * go together to make an edge, but they point in opposite directions. + * Each half-edge has a pointer to its mate (the "symmetric" half-edge Sym), + * its origin vertex (Org), the face on its left side (Lface), and the + * adjacent half-edges in the CCW direction around the origin vertex + * (Onext) and around the left face (Lnext). There is also a "next" + * pointer for the global edge list (see below). + * + * The notation used for mesh navigation: + * Sym = the mate of a half-edge (same edge, but opposite direction) + * Onext = edge CCW around origin vertex (keep same origin) + * Dnext = edge CCW around destination vertex (keep same dest) + * Lnext = edge CCW around left face (dest becomes new origin) + * Rnext = edge CCW around right face (origin becomes new dest) + * + * "prev" means to substitute CW for CCW in the definitions above. + * + * The mesh keeps global lists of all vertices, faces, and edges, + * stored as doubly-linked circular lists with a dummy header node. + * The mesh stores pointers to these dummy headers (vHead, fHead, eHead). + * + * The circular edge list is special; since half-edges always occur + * in pairs (e and e->Sym), each half-edge stores a pointer in only + * one direction. Starting at eHead and following the e->next pointers + * will visit each *edge* once (ie. e or e->Sym, but not both). + * e->Sym stores a pointer in the opposite direction, thus it is + * always true that e->Sym->next->Sym->next == e. + * + * Each vertex has a pointer to next and previous vertices in the + * circular list, and a pointer to a half-edge with this vertex as + * the origin (NULL if this is the dummy header). There is also a + * field "data" for client data. + * + * Each face has a pointer to the next and previous faces in the + * circular list, and a pointer to a half-edge with this face as + * the left face (NULL if this is the dummy header). There is also + * a field "data" for client data. + * + * Note that what we call a "face" is really a loop; faces may consist + * of more than one loop (ie. not simply connected), but there is no + * record of this in the data structure. The mesh may consist of + * several disconnected regions, so it may not be possible to visit + * the entire mesh by starting at a half-edge and traversing the edge + * structure. + * + * The mesh does NOT support isolated vertices; a vertex is deleted along + * with its last edge. Similarly when two faces are merged, one of the + * faces is deleted (see __gl_meshDelete below). For mesh operations, + * all face (loop) and vertex pointers must not be NULL. However, once + * mesh manipulation is finished, __gl_MeshZapFace can be used to delete + * faces of the mesh, one at a time. All external faces can be "zapped" + * before the mesh is returned to the client; then a NULL face indicates + * a region which is not part of the output polygon. + */ + +struct GLUvertex { + GLUvertex *next; /* next vertex (never NULL) */ + GLUvertex *prev; /* previous vertex (never NULL) */ + GLUhalfEdge *anEdge; /* a half-edge with this origin */ + void *data; /* client's data */ + + /* Internal data (keep hidden) */ + GLdouble coords[3]; /* vertex location in 3D */ + GLdouble s, t; /* projection onto the sweep plane */ + long pqHandle; /* to allow deletion from priority queue */ +}; + +struct GLUface { + GLUface *next; /* next face (never NULL) */ + GLUface *prev; /* previous face (never NULL) */ + GLUhalfEdge *anEdge; /* a half edge with this left face */ + void *data; /* room for client's data */ + + /* Internal data (keep hidden) */ + GLUface *trail; /* "stack" for conversion to strips */ + GLboolean marked; /* flag for conversion to strips */ + GLboolean inside; /* this face is in the polygon interior */ +}; + +struct GLUhalfEdge { + GLUhalfEdge *next; /* doubly-linked list (prev==Sym->next) */ + GLUhalfEdge *Sym; /* same edge, opposite direction */ + GLUhalfEdge *Onext; /* next edge CCW around origin */ + GLUhalfEdge *Lnext; /* next edge CCW around left face */ + GLUvertex *Org; /* origin vertex (Overtex too long) */ + GLUface *Lface; /* left face */ + + /* Internal data (keep hidden) */ + ActiveRegion *activeRegion; /* a region with this upper edge (sweep.c) */ + int winding; /* change in winding number when crossing + from the right face to the left face */ +}; + +#define Rface Sym->Lface +#define Dst Sym->Org + +#define Oprev Sym->Lnext +#define Lprev Onext->Sym +#define Dprev Lnext->Sym +#define Rprev Sym->Onext +#define Dnext Rprev->Sym /* 3 pointers */ +#define Rnext Oprev->Sym /* 3 pointers */ + + +struct GLUmesh { + GLUvertex vHead; /* dummy header for vertex list */ + GLUface fHead; /* dummy header for face list */ + GLUhalfEdge eHead; /* dummy header for edge list */ + GLUhalfEdge eHeadSym; /* and its symmetric counterpart */ +}; + +/* The mesh operations below have three motivations: completeness, + * convenience, and efficiency. The basic mesh operations are MakeEdge, + * Splice, and Delete. All the other edge operations can be implemented + * in terms of these. The other operations are provided for convenience + * and/or efficiency. + * + * When a face is split or a vertex is added, they are inserted into the + * global list *before* the existing vertex or face (ie. e->Org or e->Lface). + * This makes it easier to process all vertices or faces in the global lists + * without worrying about processing the same data twice. As a convenience, + * when a face is split, the "inside" flag is copied from the old face. + * Other internal data (v->data, v->activeRegion, f->data, f->marked, + * f->trail, e->winding) is set to zero. + * + * ********************** Basic Edge Operations ************************** + * + * __gl_meshMakeEdge( mesh ) creates one edge, two vertices, and a loop. + * The loop (face) consists of the two new half-edges. + * + * __gl_meshSplice( eOrg, eDst ) is the basic operation for changing the + * mesh connectivity and topology. It changes the mesh so that + * eOrg->Onext <- OLD( eDst->Onext ) + * eDst->Onext <- OLD( eOrg->Onext ) + * where OLD(...) means the value before the meshSplice operation. + * + * This can have two effects on the vertex structure: + * - if eOrg->Org != eDst->Org, the two vertices are merged together + * - if eOrg->Org == eDst->Org, the origin is split into two vertices + * In both cases, eDst->Org is changed and eOrg->Org is untouched. + * + * Similarly (and independently) for the face structure, + * - if eOrg->Lface == eDst->Lface, one loop is split into two + * - if eOrg->Lface != eDst->Lface, two distinct loops are joined into one + * In both cases, eDst->Lface is changed and eOrg->Lface is unaffected. + * + * __gl_meshDelete( eDel ) removes the edge eDel. There are several cases: + * if (eDel->Lface != eDel->Rface), we join two loops into one; the loop + * eDel->Lface is deleted. Otherwise, we are splitting one loop into two; + * the newly created loop will contain eDel->Dst. If the deletion of eDel + * would create isolated vertices, those are deleted as well. + * + * ********************** Other Edge Operations ************************** + * + * __gl_meshAddEdgeVertex( eOrg ) creates a new edge eNew such that + * eNew == eOrg->Lnext, and eNew->Dst is a newly created vertex. + * eOrg and eNew will have the same left face. + * + * __gl_meshSplitEdge( eOrg ) splits eOrg into two edges eOrg and eNew, + * such that eNew == eOrg->Lnext. The new vertex is eOrg->Dst == eNew->Org. + * eOrg and eNew will have the same left face. + * + * __gl_meshConnect( eOrg, eDst ) creates a new edge from eOrg->Dst + * to eDst->Org, and returns the corresponding half-edge eNew. + * If eOrg->Lface == eDst->Lface, this splits one loop into two, + * and the newly created loop is eNew->Lface. Otherwise, two disjoint + * loops are merged into one, and the loop eDst->Lface is destroyed. + * + * ************************ Other Operations ***************************** + * + * __gl_meshNewMesh() creates a new mesh with no edges, no vertices, + * and no loops (what we usually call a "face"). + * + * __gl_meshUnion( mesh1, mesh2 ) forms the union of all structures in + * both meshes, and returns the new mesh (the old meshes are destroyed). + * + * __gl_meshDeleteMesh( mesh ) will free all storage for any valid mesh. + * + * __gl_meshZapFace( fZap ) destroys a face and removes it from the + * global face list. All edges of fZap will have a NULL pointer as their + * left face. Any edges which also have a NULL pointer as their right face + * are deleted entirely (along with any isolated vertices this produces). + * An entire mesh can be deleted by zapping its faces, one at a time, + * in any order. Zapped faces cannot be used in further mesh operations! + * + * __gl_meshCheckMesh( mesh ) checks a mesh for self-consistency. + */ + +GLUhalfEdge *__gl_meshMakeEdge( GLUmesh *mesh ); +int __gl_meshSplice( GLUhalfEdge *eOrg, GLUhalfEdge *eDst ); +int __gl_meshDelete( GLUhalfEdge *eDel ); + +GLUhalfEdge *__gl_meshAddEdgeVertex( GLUhalfEdge *eOrg ); +GLUhalfEdge *__gl_meshSplitEdge( GLUhalfEdge *eOrg ); +GLUhalfEdge *__gl_meshConnect( GLUhalfEdge *eOrg, GLUhalfEdge *eDst ); + +GLUmesh *__gl_meshNewMesh( void ); +GLUmesh *__gl_meshUnion( GLUmesh *mesh1, GLUmesh *mesh2 ); +void __gl_meshDeleteMesh( GLUmesh *mesh ); +void __gl_meshZapFace( GLUface *fZap ); + +#ifdef NDEBUG +#define __gl_meshCheckMesh( mesh ) +#else +void __gl_meshCheckMesh( GLUmesh *mesh ); +#endif + +#endif diff --git a/src/glu/sgi/libtess/normal.c b/src/glu/sgi/libtess/normal.c new file mode 100644 index 0000000..9a3bd43 --- /dev/null +++ b/src/glu/sgi/libtess/normal.c @@ -0,0 +1,257 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#include "gluos.h" +#include "mesh.h" +#include "tess.h" +#include "normal.h" +#include +#include + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +#define Dot(u,v) (u[0]*v[0] + u[1]*v[1] + u[2]*v[2]) + +#if 0 +static void Normalize( GLdouble v[3] ) +{ + GLdouble len = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; + + assert( len > 0 ); + len = sqrt( len ); + v[0] /= len; + v[1] /= len; + v[2] /= len; +} +#endif + +#undef ABS +#define ABS(x) ((x) < 0 ? -(x) : (x)) + +static int LongAxis( GLdouble v[3] ) +{ + int i = 0; + + if( ABS(v[1]) > ABS(v[0]) ) { i = 1; } + if( ABS(v[2]) > ABS(v[i]) ) { i = 2; } + return i; +} + +static void ComputeNormal( GLUtesselator *tess, GLdouble norm[3] ) +{ + GLUvertex *v, *v1, *v2; + GLdouble c, tLen2, maxLen2; + GLdouble maxVal[3], minVal[3], d1[3], d2[3], tNorm[3]; + GLUvertex *maxVert[3], *minVert[3]; + GLUvertex *vHead = &tess->mesh->vHead; + int i; + + maxVal[0] = maxVal[1] = maxVal[2] = -2 * GLU_TESS_MAX_COORD; + minVal[0] = minVal[1] = minVal[2] = 2 * GLU_TESS_MAX_COORD; + + for( v = vHead->next; v != vHead; v = v->next ) { + for( i = 0; i < 3; ++i ) { + c = v->coords[i]; + if( c < minVal[i] ) { minVal[i] = c; minVert[i] = v; } + if( c > maxVal[i] ) { maxVal[i] = c; maxVert[i] = v; } + } + } + + /* Find two vertices separated by at least 1/sqrt(3) of the maximum + * distance between any two vertices + */ + i = 0; + if( maxVal[1] - minVal[1] > maxVal[0] - minVal[0] ) { i = 1; } + if( maxVal[2] - minVal[2] > maxVal[i] - minVal[i] ) { i = 2; } + if( minVal[i] >= maxVal[i] ) { + /* All vertices are the same -- normal doesn't matter */ + norm[0] = 0; norm[1] = 0; norm[2] = 1; + return; + } + + /* Look for a third vertex which forms the triangle with maximum area + * (Length of normal == twice the triangle area) + */ + maxLen2 = 0; + v1 = minVert[i]; + v2 = maxVert[i]; + d1[0] = v1->coords[0] - v2->coords[0]; + d1[1] = v1->coords[1] - v2->coords[1]; + d1[2] = v1->coords[2] - v2->coords[2]; + for( v = vHead->next; v != vHead; v = v->next ) { + d2[0] = v->coords[0] - v2->coords[0]; + d2[1] = v->coords[1] - v2->coords[1]; + d2[2] = v->coords[2] - v2->coords[2]; + tNorm[0] = d1[1]*d2[2] - d1[2]*d2[1]; + tNorm[1] = d1[2]*d2[0] - d1[0]*d2[2]; + tNorm[2] = d1[0]*d2[1] - d1[1]*d2[0]; + tLen2 = tNorm[0]*tNorm[0] + tNorm[1]*tNorm[1] + tNorm[2]*tNorm[2]; + if( tLen2 > maxLen2 ) { + maxLen2 = tLen2; + norm[0] = tNorm[0]; + norm[1] = tNorm[1]; + norm[2] = tNorm[2]; + } + } + + if( maxLen2 <= 0 ) { + /* All points lie on a single line -- any decent normal will do */ + norm[0] = norm[1] = norm[2] = 0; + norm[LongAxis(d1)] = 1; + } +} + + +static void CheckOrientation( GLUtesselator *tess ) +{ + GLdouble area; + GLUface *f, *fHead = &tess->mesh->fHead; + GLUvertex *v, *vHead = &tess->mesh->vHead; + GLUhalfEdge *e; + + /* When we compute the normal automatically, we choose the orientation + * so that the sum of the signed areas of all contours is non-negative. + */ + area = 0; + for( f = fHead->next; f != fHead; f = f->next ) { + e = f->anEdge; + if( e->winding <= 0 ) continue; + do { + area += (e->Org->s - e->Dst->s) * (e->Org->t + e->Dst->t); + e = e->Lnext; + } while( e != f->anEdge ); + } + if( area < 0 ) { + /* Reverse the orientation by flipping all the t-coordinates */ + for( v = vHead->next; v != vHead; v = v->next ) { + v->t = - v->t; + } + tess->tUnit[0] = - tess->tUnit[0]; + tess->tUnit[1] = - tess->tUnit[1]; + tess->tUnit[2] = - tess->tUnit[2]; + } +} + +#ifdef FOR_TRITE_TEST_PROGRAM +#include +extern int RandomSweep; +#define S_UNIT_X (RandomSweep ? (2*drand48()-1) : 1.0) +#define S_UNIT_Y (RandomSweep ? (2*drand48()-1) : 0.0) +#else +#if defined(SLANTED_SWEEP) +/* The "feature merging" is not intended to be complete. There are + * special cases where edges are nearly parallel to the sweep line + * which are not implemented. The algorithm should still behave + * robustly (ie. produce a reasonable tesselation) in the presence + * of such edges, however it may miss features which could have been + * merged. We could minimize this effect by choosing the sweep line + * direction to be something unusual (ie. not parallel to one of the + * coordinate axes). + */ +#define S_UNIT_X 0.50941539564955385 /* Pre-normalized */ +#define S_UNIT_Y 0.86052074622010633 +#else +#define S_UNIT_X 1.0 +#define S_UNIT_Y 0.0 +#endif +#endif + +/* Determine the polygon normal and project vertices onto the plane + * of the polygon. + */ +void __gl_projectPolygon( GLUtesselator *tess ) +{ + GLUvertex *v, *vHead = &tess->mesh->vHead; + GLdouble norm[3]; + GLdouble *sUnit, *tUnit; + int i, computedNormal = FALSE; + + norm[0] = tess->normal[0]; + norm[1] = tess->normal[1]; + norm[2] = tess->normal[2]; + if( norm[0] == 0 && norm[1] == 0 && norm[2] == 0 ) { + ComputeNormal( tess, norm ); + computedNormal = TRUE; + } + sUnit = tess->sUnit; + tUnit = tess->tUnit; + i = LongAxis( norm ); + +#if defined(FOR_TRITE_TEST_PROGRAM) || defined(TRUE_PROJECT) + /* Choose the initial sUnit vector to be approximately perpendicular + * to the normal. + */ + Normalize( norm ); + + sUnit[i] = 0; + sUnit[(i+1)%3] = S_UNIT_X; + sUnit[(i+2)%3] = S_UNIT_Y; + + /* Now make it exactly perpendicular */ + w = Dot( sUnit, norm ); + sUnit[0] -= w * norm[0]; + sUnit[1] -= w * norm[1]; + sUnit[2] -= w * norm[2]; + Normalize( sUnit ); + + /* Choose tUnit so that (sUnit,tUnit,norm) form a right-handed frame */ + tUnit[0] = norm[1]*sUnit[2] - norm[2]*sUnit[1]; + tUnit[1] = norm[2]*sUnit[0] - norm[0]*sUnit[2]; + tUnit[2] = norm[0]*sUnit[1] - norm[1]*sUnit[0]; + Normalize( tUnit ); +#else + /* Project perpendicular to a coordinate axis -- better numerically */ + sUnit[i] = 0; + sUnit[(i+1)%3] = S_UNIT_X; + sUnit[(i+2)%3] = S_UNIT_Y; + + tUnit[i] = 0; + tUnit[(i+1)%3] = (norm[i] > 0) ? -S_UNIT_Y : S_UNIT_Y; + tUnit[(i+2)%3] = (norm[i] > 0) ? S_UNIT_X : -S_UNIT_X; +#endif + + /* Project the vertices onto the sweep plane */ + for( v = vHead->next; v != vHead; v = v->next ) { + v->s = Dot( v->coords, sUnit ); + v->t = Dot( v->coords, tUnit ); + } + if( computedNormal ) { + CheckOrientation( tess ); + } +} diff --git a/src/glu/sgi/libtess/normal.h b/src/glu/sgi/libtess/normal.h new file mode 100644 index 0000000..c376ca4 --- /dev/null +++ b/src/glu/sgi/libtess/normal.h @@ -0,0 +1,45 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#ifndef __normal_h_ +#define __normal_h_ + +#include "tess.h" + +/* __gl_projectPolygon( tess ) determines the polygon normal + * and project vertices onto the plane of the polygon. + */ +void __gl_projectPolygon( GLUtesselator *tess ); + +#endif diff --git a/src/glu/sgi/libtess/priorityq-heap.c b/src/glu/sgi/libtess/priorityq-heap.c new file mode 100644 index 0000000..52698b5 --- /dev/null +++ b/src/glu/sgi/libtess/priorityq-heap.c @@ -0,0 +1,256 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#include +#include +#include "priorityq-heap.h" +#include "memalloc.h" + +#define INIT_SIZE 32 + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +#ifdef FOR_TRITE_TEST_PROGRAM +#define LEQ(x,y) (*pq->leq)(x,y) +#else +/* Violates modularity, but a little faster */ +#include "geom.h" +#define LEQ(x,y) VertLeq((GLUvertex *)x, (GLUvertex *)y) +#endif + +/* really __gl_pqHeapNewPriorityQ */ +PriorityQ *pqNewPriorityQ( int (*leq)(PQkey key1, PQkey key2) ) +{ + PriorityQ *pq = (PriorityQ *)memAlloc( sizeof( PriorityQ )); + if (pq == NULL) return NULL; + + pq->size = 0; + pq->max = INIT_SIZE; + pq->nodes = (PQnode *)memAlloc( (INIT_SIZE + 1) * sizeof(pq->nodes[0]) ); + if (pq->nodes == NULL) { + memFree(pq); + return NULL; + } + + pq->handles = (PQhandleElem *)memAlloc( (INIT_SIZE + 1) * sizeof(pq->handles[0]) ); + if (pq->handles == NULL) { + memFree(pq->nodes); + memFree(pq); + return NULL; + } + + pq->initialized = FALSE; + pq->freeList = 0; + pq->leq = leq; + + pq->nodes[1].handle = 1; /* so that Minimum() returns NULL */ + pq->handles[1].key = NULL; + return pq; +} + +/* really __gl_pqHeapDeletePriorityQ */ +void pqDeletePriorityQ( PriorityQ *pq ) +{ + memFree( pq->handles ); + memFree( pq->nodes ); + memFree( pq ); +} + + +static void FloatDown( PriorityQ *pq, long curr ) +{ + PQnode *n = pq->nodes; + PQhandleElem *h = pq->handles; + PQhandle hCurr, hChild; + long child; + + hCurr = n[curr].handle; + for( ;; ) { + child = curr << 1; + if( child < pq->size && LEQ( h[n[child+1].handle].key, + h[n[child].handle].key )) { + ++child; + } + + assert(child <= pq->max); + + hChild = n[child].handle; + if( child > pq->size || LEQ( h[hCurr].key, h[hChild].key )) { + n[curr].handle = hCurr; + h[hCurr].node = curr; + break; + } + n[curr].handle = hChild; + h[hChild].node = curr; + curr = child; + } +} + + +static void FloatUp( PriorityQ *pq, long curr ) +{ + PQnode *n = pq->nodes; + PQhandleElem *h = pq->handles; + PQhandle hCurr, hParent; + long parent; + + hCurr = n[curr].handle; + for( ;; ) { + parent = curr >> 1; + hParent = n[parent].handle; + if( parent == 0 || LEQ( h[hParent].key, h[hCurr].key )) { + n[curr].handle = hCurr; + h[hCurr].node = curr; + break; + } + n[curr].handle = hParent; + h[hParent].node = curr; + curr = parent; + } +} + +/* really __gl_pqHeapInit */ +void pqInit( PriorityQ *pq ) +{ + long i; + + /* This method of building a heap is O(n), rather than O(n lg n). */ + + for( i = pq->size; i >= 1; --i ) { + FloatDown( pq, i ); + } + pq->initialized = TRUE; +} + +/* really __gl_pqHeapInsert */ +/* returns LONG_MAX iff out of memory */ +PQhandle pqInsert( PriorityQ *pq, PQkey keyNew ) +{ + long curr; + PQhandle free_handle; + + curr = ++ pq->size; + if( (curr*2) > pq->max ) { + PQnode *saveNodes= pq->nodes; + PQhandleElem *saveHandles= pq->handles; + + /* If the heap overflows, double its size. */ + pq->max <<= 1; + pq->nodes = (PQnode *)memRealloc( pq->nodes, + (size_t) + ((pq->max + 1) * sizeof( pq->nodes[0] ))); + if (pq->nodes == NULL) { + pq->nodes = saveNodes; /* restore ptr to free upon return */ + return LONG_MAX; + } + pq->handles = (PQhandleElem *)memRealloc( pq->handles, + (size_t) + ((pq->max + 1) * + sizeof( pq->handles[0] ))); + if (pq->handles == NULL) { + pq->handles = saveHandles; /* restore ptr to free upon return */ + return LONG_MAX; + } + } + + if( pq->freeList == 0 ) { + free_handle = curr; + } else { + free_handle = pq->freeList; + pq->freeList = pq->handles[free_handle].node; + } + + pq->nodes[curr].handle = free_handle; + pq->handles[free_handle].node = curr; + pq->handles[free_handle].key = keyNew; + + if( pq->initialized ) { + FloatUp( pq, curr ); + } + assert(free_handle != LONG_MAX); + return free_handle; +} + +/* really __gl_pqHeapExtractMin */ +PQkey pqExtractMin( PriorityQ *pq ) +{ + PQnode *n = pq->nodes; + PQhandleElem *h = pq->handles; + PQhandle hMin = n[1].handle; + PQkey min = h[hMin].key; + + if( pq->size > 0 ) { + n[1].handle = n[pq->size].handle; + h[n[1].handle].node = 1; + + h[hMin].key = NULL; + h[hMin].node = pq->freeList; + pq->freeList = hMin; + + if( -- pq->size > 0 ) { + FloatDown( pq, 1 ); + } + } + return min; +} + +/* really __gl_pqHeapDelete */ +void pqDelete( PriorityQ *pq, PQhandle hCurr ) +{ + PQnode *n = pq->nodes; + PQhandleElem *h = pq->handles; + long curr; + + assert( hCurr >= 1 && hCurr <= pq->max && h[hCurr].key != NULL ); + + curr = h[hCurr].node; + n[curr].handle = n[pq->size].handle; + h[n[curr].handle].node = curr; + + if( curr <= -- pq->size ) { + if( curr <= 1 || LEQ( h[n[curr>>1].handle].key, h[n[curr].handle].key )) { + FloatDown( pq, curr ); + } else { + FloatUp( pq, curr ); + } + } + h[hCurr].key = NULL; + h[hCurr].node = pq->freeList; + pq->freeList = hCurr; +} diff --git a/src/glu/sgi/libtess/priorityq-heap.h b/src/glu/sgi/libtess/priorityq-heap.h new file mode 100644 index 0000000..dc9aaef --- /dev/null +++ b/src/glu/sgi/libtess/priorityq-heap.h @@ -0,0 +1,107 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#ifndef __priorityq_heap_h_ +#define __priorityq_heap_h_ + +/* Use #define's so that another heap implementation can use this one */ + +#define PQkey PQHeapKey +#define PQhandle PQHeapHandle +#define PriorityQ PriorityQHeap + +#define pqNewPriorityQ(leq) __gl_pqHeapNewPriorityQ(leq) +#define pqDeletePriorityQ(pq) __gl_pqHeapDeletePriorityQ(pq) + +/* The basic operations are insertion of a new key (pqInsert), + * and examination/extraction of a key whose value is minimum + * (pqMinimum/pqExtractMin). Deletion is also allowed (pqDelete); + * for this purpose pqInsert returns a "handle" which is supplied + * as the argument. + * + * An initial heap may be created efficiently by calling pqInsert + * repeatedly, then calling pqInit. In any case pqInit must be called + * before any operations other than pqInsert are used. + * + * If the heap is empty, pqMinimum/pqExtractMin will return a NULL key. + * This may also be tested with pqIsEmpty. + */ +#define pqInit(pq) __gl_pqHeapInit(pq) +#define pqInsert(pq,key) __gl_pqHeapInsert(pq,key) +#define pqMinimum(pq) __gl_pqHeapMinimum(pq) +#define pqExtractMin(pq) __gl_pqHeapExtractMin(pq) +#define pqDelete(pq,handle) __gl_pqHeapDelete(pq,handle) +#define pqIsEmpty(pq) __gl_pqHeapIsEmpty(pq) + + +/* Since we support deletion the data structure is a little more + * complicated than an ordinary heap. "nodes" is the heap itself; + * active nodes are stored in the range 1..pq->size. When the + * heap exceeds its allocated size (pq->max), its size doubles. + * The children of node i are nodes 2i and 2i+1. + * + * Each node stores an index into an array "handles". Each handle + * stores a key, plus a pointer back to the node which currently + * represents that key (ie. nodes[handles[i].node].handle == i). + */ + +typedef void *PQkey; +typedef long PQhandle; +typedef struct PriorityQ PriorityQ; + +typedef struct { PQhandle handle; } PQnode; +typedef struct { PQkey key; PQhandle node; } PQhandleElem; + +struct PriorityQ { + PQnode *nodes; + PQhandleElem *handles; + long size, max; + PQhandle freeList; + int initialized; + int (*leq)(PQkey key1, PQkey key2); +}; + +PriorityQ *pqNewPriorityQ( int (*leq)(PQkey key1, PQkey key2) ); +void pqDeletePriorityQ( PriorityQ *pq ); + +void pqInit( PriorityQ *pq ); +PQhandle pqInsert( PriorityQ *pq, PQkey key ); +PQkey pqExtractMin( PriorityQ *pq ); +void pqDelete( PriorityQ *pq, PQhandle handle ); + + +#define __gl_pqHeapMinimum(pq) ((pq)->handles[(pq)->nodes[1].handle].key) +#define __gl_pqHeapIsEmpty(pq) ((pq)->size == 0) + +#endif diff --git a/src/glu/sgi/libtess/priorityq-sort.h b/src/glu/sgi/libtess/priorityq-sort.h new file mode 100644 index 0000000..746cf5f --- /dev/null +++ b/src/glu/sgi/libtess/priorityq-sort.h @@ -0,0 +1,117 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#ifndef __priorityq_sort_h_ +#define __priorityq_sort_h_ + +#include "priorityq-heap.h" + +#undef PQkey +#undef PQhandle +#undef PriorityQ +#undef pqNewPriorityQ +#undef pqDeletePriorityQ +#undef pqInit +#undef pqInsert +#undef pqMinimum +#undef pqExtractMin +#undef pqDelete +#undef pqIsEmpty + +/* Use #define's so that another heap implementation can use this one */ + +#define PQkey PQSortKey +#define PQhandle PQSortHandle +#define PriorityQ PriorityQSort + +#define pqNewPriorityQ(leq) __gl_pqSortNewPriorityQ(leq) +#define pqDeletePriorityQ(pq) __gl_pqSortDeletePriorityQ(pq) + +/* The basic operations are insertion of a new key (pqInsert), + * and examination/extraction of a key whose value is minimum + * (pqMinimum/pqExtractMin). Deletion is also allowed (pqDelete); + * for this purpose pqInsert returns a "handle" which is supplied + * as the argument. + * + * An initial heap may be created efficiently by calling pqInsert + * repeatedly, then calling pqInit. In any case pqInit must be called + * before any operations other than pqInsert are used. + * + * If the heap is empty, pqMinimum/pqExtractMin will return a NULL key. + * This may also be tested with pqIsEmpty. + */ +#define pqInit(pq) __gl_pqSortInit(pq) +#define pqInsert(pq,key) __gl_pqSortInsert(pq,key) +#define pqMinimum(pq) __gl_pqSortMinimum(pq) +#define pqExtractMin(pq) __gl_pqSortExtractMin(pq) +#define pqDelete(pq,handle) __gl_pqSortDelete(pq,handle) +#define pqIsEmpty(pq) __gl_pqSortIsEmpty(pq) + + +/* Since we support deletion the data structure is a little more + * complicated than an ordinary heap. "nodes" is the heap itself; + * active nodes are stored in the range 1..pq->size. When the + * heap exceeds its allocated size (pq->max), its size doubles. + * The children of node i are nodes 2i and 2i+1. + * + * Each node stores an index into an array "handles". Each handle + * stores a key, plus a pointer back to the node which currently + * represents that key (ie. nodes[handles[i].node].handle == i). + */ + +typedef PQHeapKey PQkey; +typedef PQHeapHandle PQhandle; +typedef struct PriorityQ PriorityQ; + +struct PriorityQ { + PriorityQHeap *heap; + PQkey *keys; + PQkey **order; + PQhandle size, max; + int initialized; + int (*leq)(PQkey key1, PQkey key2); +}; + +PriorityQ *pqNewPriorityQ( int (*leq)(PQkey key1, PQkey key2) ); +void pqDeletePriorityQ( PriorityQ *pq ); + +int pqInit( PriorityQ *pq ); +PQhandle pqInsert( PriorityQ *pq, PQkey key ); +PQkey pqExtractMin( PriorityQ *pq ); +void pqDelete( PriorityQ *pq, PQhandle handle ); + +PQkey pqMinimum( PriorityQ *pq ); +int pqIsEmpty( PriorityQ *pq ); + +#endif diff --git a/src/glu/sgi/libtess/priorityq.c b/src/glu/sgi/libtess/priorityq.c new file mode 100644 index 0000000..c6b99cc --- /dev/null +++ b/src/glu/sgi/libtess/priorityq.c @@ -0,0 +1,260 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#include "gluos.h" +#include +#include +#include /* LONG_MAX */ +#include "memalloc.h" + +/* Include all the code for the regular heap-based queue here. */ + +#include "priorityq-heap.c" + +/* Now redefine all the function names to map to their "Sort" versions. */ + +#include "priorityq-sort.h" + +/* really __gl_pqSortNewPriorityQ */ +PriorityQ *pqNewPriorityQ( int (*leq)(PQkey key1, PQkey key2) ) +{ + PriorityQ *pq = (PriorityQ *)memAlloc( sizeof( PriorityQ )); + if (pq == NULL) return NULL; + + pq->heap = __gl_pqHeapNewPriorityQ( leq ); + if (pq->heap == NULL) { + memFree(pq); + return NULL; + } + + pq->keys = (PQHeapKey *)memAlloc( INIT_SIZE * sizeof(pq->keys[0]) ); + if (pq->keys == NULL) { + __gl_pqHeapDeletePriorityQ(pq->heap); + memFree(pq); + return NULL; + } + + pq->size = 0; + pq->max = INIT_SIZE; + pq->initialized = FALSE; + pq->leq = leq; + return pq; +} + +/* really __gl_pqSortDeletePriorityQ */ +void pqDeletePriorityQ( PriorityQ *pq ) +{ + assert(pq != NULL); + if (pq->heap != NULL) __gl_pqHeapDeletePriorityQ( pq->heap ); + if (pq->order != NULL) memFree( pq->order ); + if (pq->keys != NULL) memFree( pq->keys ); + memFree( pq ); +} + + +#define LT(x,y) (! LEQ(y,x)) +#define GT(x,y) (! LEQ(x,y)) +#define Swap(a,b) do{PQkey *tmp = *a; *a = *b; *b = tmp;}while(0) + +/* really __gl_pqSortInit */ +int pqInit( PriorityQ *pq ) +{ + PQkey **p, **r, **i, **j, *piv; + struct { PQkey **p, **r; } Stack[50], *top = Stack; + unsigned long seed = 2016473283; + + /* Create an array of indirect pointers to the keys, so that we + * the handles we have returned are still valid. + */ +/* + pq->order = (PQHeapKey **)memAlloc( (size_t) + (pq->size * sizeof(pq->order[0])) ); +*/ + pq->order = (PQHeapKey **)memAlloc( (size_t) + ((pq->size+1) * sizeof(pq->order[0])) ); +/* the previous line is a patch to compensate for the fact that IBM */ +/* machines return a null on a malloc of zero bytes (unlike SGI), */ +/* so we have to put in this defense to guard against a memory */ +/* fault four lines down. from fossum@austin.ibm.com. */ + if (pq->order == NULL) return 0; + + p = pq->order; + r = p + pq->size - 1; + for( piv = pq->keys, i = p; i <= r; ++piv, ++i ) { + *i = piv; + } + + /* Sort the indirect pointers in descending order, + * using randomized Quicksort + */ + top->p = p; top->r = r; ++top; + while( --top >= Stack ) { + p = top->p; + r = top->r; + while( r > p + 10 ) { + seed = seed * 1539415821 + 1; + i = p + seed % (r - p + 1); + piv = *i; + *i = *p; + *p = piv; + i = p - 1; + j = r + 1; + do { + do { ++i; } while( GT( **i, *piv )); + do { --j; } while( LT( **j, *piv )); + Swap( i, j ); + } while( i < j ); + Swap( i, j ); /* Undo last swap */ + if( i - p < r - j ) { + top->p = j+1; top->r = r; ++top; + r = i-1; + } else { + top->p = p; top->r = i-1; ++top; + p = j+1; + } + } + /* Insertion sort small lists */ + for( i = p+1; i <= r; ++i ) { + piv = *i; + for( j = i; j > p && LT( **(j-1), *piv ); --j ) { + *j = *(j-1); + } + *j = piv; + } + } + pq->max = pq->size; + pq->initialized = TRUE; + __gl_pqHeapInit( pq->heap ); /* always succeeds */ + +#ifndef NDEBUG + p = pq->order; + r = p + pq->size - 1; + for( i = p; i < r; ++i ) { + assert( LEQ( **(i+1), **i )); + } +#endif + + return 1; +} + +/* really __gl_pqSortInsert */ +/* returns LONG_MAX iff out of memory */ +PQhandle pqInsert( PriorityQ *pq, PQkey keyNew ) +{ + long curr; + + if( pq->initialized ) { + return __gl_pqHeapInsert( pq->heap, keyNew ); + } + curr = pq->size; + if( ++ pq->size >= pq->max ) { + PQkey *saveKey= pq->keys; + + /* If the heap overflows, double its size. */ + pq->max <<= 1; + pq->keys = (PQHeapKey *)memRealloc( pq->keys, + (size_t) + (pq->max * sizeof( pq->keys[0] ))); + if (pq->keys == NULL) { + pq->keys = saveKey; /* restore ptr to free upon return */ + return LONG_MAX; + } + } + assert(curr != LONG_MAX); + pq->keys[curr] = keyNew; + + /* Negative handles index the sorted array. */ + return -(curr+1); +} + +/* really __gl_pqSortExtractMin */ +PQkey pqExtractMin( PriorityQ *pq ) +{ + PQkey sortMin, heapMin; + + if( pq->size == 0 ) { + return __gl_pqHeapExtractMin( pq->heap ); + } + sortMin = *(pq->order[pq->size-1]); + if( ! __gl_pqHeapIsEmpty( pq->heap )) { + heapMin = __gl_pqHeapMinimum( pq->heap ); + if( LEQ( heapMin, sortMin )) { + return __gl_pqHeapExtractMin( pq->heap ); + } + } + do { + -- pq->size; + } while( pq->size > 0 && *(pq->order[pq->size-1]) == NULL ); + return sortMin; +} + +/* really __gl_pqSortMinimum */ +PQkey pqMinimum( PriorityQ *pq ) +{ + PQkey sortMin, heapMin; + + if( pq->size == 0 ) { + return __gl_pqHeapMinimum( pq->heap ); + } + sortMin = *(pq->order[pq->size-1]); + if( ! __gl_pqHeapIsEmpty( pq->heap )) { + heapMin = __gl_pqHeapMinimum( pq->heap ); + if( LEQ( heapMin, sortMin )) { + return heapMin; + } + } + return sortMin; +} + +/* really __gl_pqSortIsEmpty */ +int pqIsEmpty( PriorityQ *pq ) +{ + return (pq->size == 0) && __gl_pqHeapIsEmpty( pq->heap ); +} + +/* really __gl_pqSortDelete */ +void pqDelete( PriorityQ *pq, PQhandle curr ) +{ + if( curr >= 0 ) { + __gl_pqHeapDelete( pq->heap, curr ); + return; + } + curr = -(curr+1); + assert( curr < pq->max && pq->keys[curr] != NULL ); + + pq->keys[curr] = NULL; + while( pq->size > 0 && *(pq->order[pq->size-1]) == NULL ) { + -- pq->size; + } +} diff --git a/src/glu/sgi/libtess/priorityq.h b/src/glu/sgi/libtess/priorityq.h new file mode 100644 index 0000000..746cf5f --- /dev/null +++ b/src/glu/sgi/libtess/priorityq.h @@ -0,0 +1,117 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#ifndef __priorityq_sort_h_ +#define __priorityq_sort_h_ + +#include "priorityq-heap.h" + +#undef PQkey +#undef PQhandle +#undef PriorityQ +#undef pqNewPriorityQ +#undef pqDeletePriorityQ +#undef pqInit +#undef pqInsert +#undef pqMinimum +#undef pqExtractMin +#undef pqDelete +#undef pqIsEmpty + +/* Use #define's so that another heap implementation can use this one */ + +#define PQkey PQSortKey +#define PQhandle PQSortHandle +#define PriorityQ PriorityQSort + +#define pqNewPriorityQ(leq) __gl_pqSortNewPriorityQ(leq) +#define pqDeletePriorityQ(pq) __gl_pqSortDeletePriorityQ(pq) + +/* The basic operations are insertion of a new key (pqInsert), + * and examination/extraction of a key whose value is minimum + * (pqMinimum/pqExtractMin). Deletion is also allowed (pqDelete); + * for this purpose pqInsert returns a "handle" which is supplied + * as the argument. + * + * An initial heap may be created efficiently by calling pqInsert + * repeatedly, then calling pqInit. In any case pqInit must be called + * before any operations other than pqInsert are used. + * + * If the heap is empty, pqMinimum/pqExtractMin will return a NULL key. + * This may also be tested with pqIsEmpty. + */ +#define pqInit(pq) __gl_pqSortInit(pq) +#define pqInsert(pq,key) __gl_pqSortInsert(pq,key) +#define pqMinimum(pq) __gl_pqSortMinimum(pq) +#define pqExtractMin(pq) __gl_pqSortExtractMin(pq) +#define pqDelete(pq,handle) __gl_pqSortDelete(pq,handle) +#define pqIsEmpty(pq) __gl_pqSortIsEmpty(pq) + + +/* Since we support deletion the data structure is a little more + * complicated than an ordinary heap. "nodes" is the heap itself; + * active nodes are stored in the range 1..pq->size. When the + * heap exceeds its allocated size (pq->max), its size doubles. + * The children of node i are nodes 2i and 2i+1. + * + * Each node stores an index into an array "handles". Each handle + * stores a key, plus a pointer back to the node which currently + * represents that key (ie. nodes[handles[i].node].handle == i). + */ + +typedef PQHeapKey PQkey; +typedef PQHeapHandle PQhandle; +typedef struct PriorityQ PriorityQ; + +struct PriorityQ { + PriorityQHeap *heap; + PQkey *keys; + PQkey **order; + PQhandle size, max; + int initialized; + int (*leq)(PQkey key1, PQkey key2); +}; + +PriorityQ *pqNewPriorityQ( int (*leq)(PQkey key1, PQkey key2) ); +void pqDeletePriorityQ( PriorityQ *pq ); + +int pqInit( PriorityQ *pq ); +PQhandle pqInsert( PriorityQ *pq, PQkey key ); +PQkey pqExtractMin( PriorityQ *pq ); +void pqDelete( PriorityQ *pq, PQhandle handle ); + +PQkey pqMinimum( PriorityQ *pq ); +int pqIsEmpty( PriorityQ *pq ); + +#endif diff --git a/src/glu/sgi/libtess/render.c b/src/glu/sgi/libtess/render.c new file mode 100644 index 0000000..bca836f --- /dev/null +++ b/src/glu/sgi/libtess/render.c @@ -0,0 +1,502 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#include "gluos.h" +#include +#include +#include "mesh.h" +#include "tess.h" +#include "render.h" + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +/* This structure remembers the information we need about a primitive + * to be able to render it later, once we have determined which + * primitive is able to use the most triangles. + */ +struct FaceCount { + long size; /* number of triangles used */ + GLUhalfEdge *eStart; /* edge where this primitive starts */ + void (*render)(GLUtesselator *, GLUhalfEdge *, long); + /* routine to render this primitive */ +}; + +static struct FaceCount MaximumFan( GLUhalfEdge *eOrig ); +static struct FaceCount MaximumStrip( GLUhalfEdge *eOrig ); + +static void RenderFan( GLUtesselator *tess, GLUhalfEdge *eStart, long size ); +static void RenderStrip( GLUtesselator *tess, GLUhalfEdge *eStart, long size ); +static void RenderTriangle( GLUtesselator *tess, GLUhalfEdge *eStart, + long size ); + +static void RenderMaximumFaceGroup( GLUtesselator *tess, GLUface *fOrig ); +static void RenderLonelyTriangles( GLUtesselator *tess, GLUface *head ); + + + +/************************ Strips and Fans decomposition ******************/ + +/* __gl_renderMesh( tess, mesh ) takes a mesh and breaks it into triangle + * fans, strips, and separate triangles. A substantial effort is made + * to use as few rendering primitives as possible (ie. to make the fans + * and strips as large as possible). + * + * The rendering output is provided as callbacks (see the api). + */ +void __gl_renderMesh( GLUtesselator *tess, GLUmesh *mesh ) +{ + GLUface *f; + + /* Make a list of separate triangles so we can render them all at once */ + tess->lonelyTriList = NULL; + + for( f = mesh->fHead.next; f != &mesh->fHead; f = f->next ) { + f->marked = FALSE; + } + for( f = mesh->fHead.next; f != &mesh->fHead; f = f->next ) { + + /* We examine all faces in an arbitrary order. Whenever we find + * an unprocessed face F, we output a group of faces including F + * whose size is maximum. + */ + if( f->inside && ! f->marked ) { + RenderMaximumFaceGroup( tess, f ); + assert( f->marked ); + } + } + if( tess->lonelyTriList != NULL ) { + RenderLonelyTriangles( tess, tess->lonelyTriList ); + tess->lonelyTriList = NULL; + } +} + + +static void RenderMaximumFaceGroup( GLUtesselator *tess, GLUface *fOrig ) +{ + /* We want to find the largest triangle fan or strip of unmarked faces + * which includes the given face fOrig. There are 3 possible fans + * passing through fOrig (one centered at each vertex), and 3 possible + * strips (one for each CCW permutation of the vertices). Our strategy + * is to try all of these, and take the primitive which uses the most + * triangles (a greedy approach). + */ + GLUhalfEdge *e = fOrig->anEdge; + struct FaceCount max, newFace; + + max.size = 1; + max.eStart = e; + max.render = &RenderTriangle; + + if( ! tess->flagBoundary ) { + newFace = MaximumFan( e ); if( newFace.size > max.size ) { max = newFace; } + newFace = MaximumFan( e->Lnext ); if( newFace.size > max.size ) { max = newFace; } + newFace = MaximumFan( e->Lprev ); if( newFace.size > max.size ) { max = newFace; } + + newFace = MaximumStrip( e ); if( newFace.size > max.size ) { max = newFace; } + newFace = MaximumStrip( e->Lnext ); if( newFace.size > max.size ) { max = newFace; } + newFace = MaximumStrip( e->Lprev ); if( newFace.size > max.size ) { max = newFace; } + } + (*(max.render))( tess, max.eStart, max.size ); +} + + +/* Macros which keep track of faces we have marked temporarily, and allow + * us to backtrack when necessary. With triangle fans, this is not + * really necessary, since the only awkward case is a loop of triangles + * around a single origin vertex. However with strips the situation is + * more complicated, and we need a general tracking method like the + * one here. + */ +#define Marked(f) (! (f)->inside || (f)->marked) + +#define AddToTrail(f,t) ((f)->trail = (t), (t) = (f), (f)->marked = TRUE) + +#define FreeTrail(t) do { \ + while( (t) != NULL ) { \ + (t)->marked = FALSE; t = (t)->trail; \ + } \ + } while(0) /* absorb trailing semicolon */ + + + +static struct FaceCount MaximumFan( GLUhalfEdge *eOrig ) +{ + /* eOrig->Lface is the face we want to render. We want to find the size + * of a maximal fan around eOrig->Org. To do this we just walk around + * the origin vertex as far as possible in both directions. + */ + struct FaceCount newFace = { 0, NULL, &RenderFan }; + GLUface *trail = NULL; + GLUhalfEdge *e; + + for( e = eOrig; ! Marked( e->Lface ); e = e->Onext ) { + AddToTrail( e->Lface, trail ); + ++newFace.size; + } + for( e = eOrig; ! Marked( e->Rface ); e = e->Oprev ) { + AddToTrail( e->Rface, trail ); + ++newFace.size; + } + newFace.eStart = e; + /*LINTED*/ + FreeTrail( trail ); + return newFace; +} + + +#define IsEven(n) (((n) & 1) == 0) + +static struct FaceCount MaximumStrip( GLUhalfEdge *eOrig ) +{ + /* Here we are looking for a maximal strip that contains the vertices + * eOrig->Org, eOrig->Dst, eOrig->Lnext->Dst (in that order or the + * reverse, such that all triangles are oriented CCW). + * + * Again we walk forward and backward as far as possible. However for + * strips there is a twist: to get CCW orientations, there must be + * an *even* number of triangles in the strip on one side of eOrig. + * We walk the strip starting on a side with an even number of triangles; + * if both side have an odd number, we are forced to shorten one side. + */ + struct FaceCount newFace = { 0, NULL, &RenderStrip }; + long headSize = 0, tailSize = 0; + GLUface *trail = NULL; + GLUhalfEdge *e, *eTail, *eHead; + + for( e = eOrig; ! Marked( e->Lface ); ++tailSize, e = e->Onext ) { + AddToTrail( e->Lface, trail ); + ++tailSize; + e = e->Dprev; + if( Marked( e->Lface )) break; + AddToTrail( e->Lface, trail ); + } + eTail = e; + + for( e = eOrig; ! Marked( e->Rface ); ++headSize, e = e->Dnext ) { + AddToTrail( e->Rface, trail ); + ++headSize; + e = e->Oprev; + if( Marked( e->Rface )) break; + AddToTrail( e->Rface, trail ); + } + eHead = e; + + newFace.size = tailSize + headSize; + if( IsEven( tailSize )) { + newFace.eStart = eTail->Sym; + } else if( IsEven( headSize )) { + newFace.eStart = eHead; + } else { + /* Both sides have odd length, we must shorten one of them. In fact, + * we must start from eHead to guarantee inclusion of eOrig->Lface. + */ + --newFace.size; + newFace.eStart = eHead->Onext; + } + /*LINTED*/ + FreeTrail( trail ); + return newFace; +} + + +static void RenderTriangle( GLUtesselator *tess, GLUhalfEdge *e, long size ) +{ + /* Just add the triangle to a triangle list, so we can render all + * the separate triangles at once. + */ + assert( size == 1 ); + AddToTrail( e->Lface, tess->lonelyTriList ); +} + + +static void RenderLonelyTriangles( GLUtesselator *tess, GLUface *f ) +{ + /* Now we render all the separate triangles which could not be + * grouped into a triangle fan or strip. + */ + GLUhalfEdge *e; + int newState; + int edgeState = -1; /* force edge state output for first vertex */ + + CALL_BEGIN_OR_BEGIN_DATA( GL_TRIANGLES ); + + for( ; f != NULL; f = f->trail ) { + /* Loop once for each edge (there will always be 3 edges) */ + + e = f->anEdge; + do { + if( tess->flagBoundary ) { + /* Set the "edge state" to TRUE just before we output the + * first vertex of each edge on the polygon boundary. + */ + newState = ! e->Rface->inside; + if( edgeState != newState ) { + edgeState = newState; + CALL_EDGE_FLAG_OR_EDGE_FLAG_DATA( edgeState ); + } + } + CALL_VERTEX_OR_VERTEX_DATA( e->Org->data ); + + e = e->Lnext; + } while( e != f->anEdge ); + } + CALL_END_OR_END_DATA(); +} + + +static void RenderFan( GLUtesselator *tess, GLUhalfEdge *e, long size ) +{ + /* Render as many CCW triangles as possible in a fan starting from + * edge "e". The fan *should* contain exactly "size" triangles + * (otherwise we've goofed up somewhere). + */ + CALL_BEGIN_OR_BEGIN_DATA( GL_TRIANGLE_FAN ); + CALL_VERTEX_OR_VERTEX_DATA( e->Org->data ); + CALL_VERTEX_OR_VERTEX_DATA( e->Dst->data ); + + while( ! Marked( e->Lface )) { + e->Lface->marked = TRUE; + --size; + e = e->Onext; + CALL_VERTEX_OR_VERTEX_DATA( e->Dst->data ); + } + + assert( size == 0 ); + CALL_END_OR_END_DATA(); +} + + +static void RenderStrip( GLUtesselator *tess, GLUhalfEdge *e, long size ) +{ + /* Render as many CCW triangles as possible in a strip starting from + * edge "e". The strip *should* contain exactly "size" triangles + * (otherwise we've goofed up somewhere). + */ + CALL_BEGIN_OR_BEGIN_DATA( GL_TRIANGLE_STRIP ); + CALL_VERTEX_OR_VERTEX_DATA( e->Org->data ); + CALL_VERTEX_OR_VERTEX_DATA( e->Dst->data ); + + while( ! Marked( e->Lface )) { + e->Lface->marked = TRUE; + --size; + e = e->Dprev; + CALL_VERTEX_OR_VERTEX_DATA( e->Org->data ); + if( Marked( e->Lface )) break; + + e->Lface->marked = TRUE; + --size; + e = e->Onext; + CALL_VERTEX_OR_VERTEX_DATA( e->Dst->data ); + } + + assert( size == 0 ); + CALL_END_OR_END_DATA(); +} + + +/************************ Boundary contour decomposition ******************/ + +/* __gl_renderBoundary( tess, mesh ) takes a mesh, and outputs one + * contour for each face marked "inside". The rendering output is + * provided as callbacks (see the api). + */ +void __gl_renderBoundary( GLUtesselator *tess, GLUmesh *mesh ) +{ + GLUface *f; + GLUhalfEdge *e; + + for( f = mesh->fHead.next; f != &mesh->fHead; f = f->next ) { + if( f->inside ) { + CALL_BEGIN_OR_BEGIN_DATA( GL_LINE_LOOP ); + e = f->anEdge; + do { + CALL_VERTEX_OR_VERTEX_DATA( e->Org->data ); + e = e->Lnext; + } while( e != f->anEdge ); + CALL_END_OR_END_DATA(); + } + } +} + + +/************************ Quick-and-dirty decomposition ******************/ + +#define SIGN_INCONSISTENT 2 + +static int ComputeNormal( GLUtesselator *tess, GLdouble norm[3], int check ) +/* + * If check==FALSE, we compute the polygon normal and place it in norm[]. + * If check==TRUE, we check that each triangle in the fan from v0 has a + * consistent orientation with respect to norm[]. If triangles are + * consistently oriented CCW, return 1; if CW, return -1; if all triangles + * are degenerate return 0; otherwise (no consistent orientation) return + * SIGN_INCONSISTENT. + */ +{ + CachedVertex *v0 = tess->cache; + CachedVertex *vn = v0 + tess->cacheCount; + CachedVertex *vc; + GLdouble dot, xc, yc, zc, xp, yp, zp, n[3]; + int sign = 0; + + /* Find the polygon normal. It is important to get a reasonable + * normal even when the polygon is self-intersecting (eg. a bowtie). + * Otherwise, the computed normal could be very tiny, but perpendicular + * to the true plane of the polygon due to numerical noise. Then all + * the triangles would appear to be degenerate and we would incorrectly + * decompose the polygon as a fan (or simply not render it at all). + * + * We use a sum-of-triangles normal algorithm rather than the more + * efficient sum-of-trapezoids method (used in CheckOrientation() + * in normal.c). This lets us explicitly reverse the signed area + * of some triangles to get a reasonable normal in the self-intersecting + * case. + */ + if( ! check ) { + norm[0] = norm[1] = norm[2] = 0.0; + } + + vc = v0 + 1; + xc = vc->coords[0] - v0->coords[0]; + yc = vc->coords[1] - v0->coords[1]; + zc = vc->coords[2] - v0->coords[2]; + while( ++vc < vn ) { + xp = xc; yp = yc; zp = zc; + xc = vc->coords[0] - v0->coords[0]; + yc = vc->coords[1] - v0->coords[1]; + zc = vc->coords[2] - v0->coords[2]; + + /* Compute (vp - v0) cross (vc - v0) */ + n[0] = yp*zc - zp*yc; + n[1] = zp*xc - xp*zc; + n[2] = xp*yc - yp*xc; + + dot = n[0]*norm[0] + n[1]*norm[1] + n[2]*norm[2]; + if( ! check ) { + /* Reverse the contribution of back-facing triangles to get + * a reasonable normal for self-intersecting polygons (see above) + */ + if( dot >= 0 ) { + norm[0] += n[0]; norm[1] += n[1]; norm[2] += n[2]; + } else { + norm[0] -= n[0]; norm[1] -= n[1]; norm[2] -= n[2]; + } + } else if( dot != 0 ) { + /* Check the new orientation for consistency with previous triangles */ + if( dot > 0 ) { + if( sign < 0 ) return SIGN_INCONSISTENT; + sign = 1; + } else { + if( sign > 0 ) return SIGN_INCONSISTENT; + sign = -1; + } + } + } + return sign; +} + +/* __gl_renderCache( tess ) takes a single contour and tries to render it + * as a triangle fan. This handles convex polygons, as well as some + * non-convex polygons if we get lucky. + * + * Returns TRUE if the polygon was successfully rendered. The rendering + * output is provided as callbacks (see the api). + */ +GLboolean __gl_renderCache( GLUtesselator *tess ) +{ + CachedVertex *v0 = tess->cache; + CachedVertex *vn = v0 + tess->cacheCount; + CachedVertex *vc; + GLdouble norm[3]; + int sign; + + if( tess->cacheCount < 3 ) { + /* Degenerate contour -- no output */ + return TRUE; + } + + norm[0] = tess->normal[0]; + norm[1] = tess->normal[1]; + norm[2] = tess->normal[2]; + if( norm[0] == 0 && norm[1] == 0 && norm[2] == 0 ) { + ComputeNormal( tess, norm, FALSE ); + } + + sign = ComputeNormal( tess, norm, TRUE ); + if( sign == SIGN_INCONSISTENT ) { + /* Fan triangles did not have a consistent orientation */ + return FALSE; + } + if( sign == 0 ) { + /* All triangles were degenerate */ + return TRUE; + } + + /* Make sure we do the right thing for each winding rule */ + switch( tess->windingRule ) { + case GLU_TESS_WINDING_ODD: + case GLU_TESS_WINDING_NONZERO: + break; + case GLU_TESS_WINDING_POSITIVE: + if( sign < 0 ) return TRUE; + break; + case GLU_TESS_WINDING_NEGATIVE: + if( sign > 0 ) return TRUE; + break; + case GLU_TESS_WINDING_ABS_GEQ_TWO: + return TRUE; + } + + CALL_BEGIN_OR_BEGIN_DATA( tess->boundaryOnly ? GL_LINE_LOOP + : (tess->cacheCount > 3) ? GL_TRIANGLE_FAN + : GL_TRIANGLES ); + + CALL_VERTEX_OR_VERTEX_DATA( v0->data ); + if( sign > 0 ) { + for( vc = v0+1; vc < vn; ++vc ) { + CALL_VERTEX_OR_VERTEX_DATA( vc->data ); + } + } else { + for( vc = vn-1; vc > v0; --vc ) { + CALL_VERTEX_OR_VERTEX_DATA( vc->data ); + } + } + CALL_END_OR_END_DATA(); + return TRUE; +} diff --git a/src/glu/sgi/libtess/render.h b/src/glu/sgi/libtess/render.h new file mode 100644 index 0000000..a298c9a --- /dev/null +++ b/src/glu/sgi/libtess/render.h @@ -0,0 +1,52 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#ifndef __render_h_ +#define __render_h_ + +#include "mesh.h" + +/* __gl_renderMesh( tess, mesh ) takes a mesh and breaks it into triangle + * fans, strips, and separate triangles. A substantial effort is made + * to use as few rendering primitives as possible (ie. to make the fans + * and strips as large as possible). + * + * The rendering output is provided as callbacks (see the api). + */ +void __gl_renderMesh( GLUtesselator *tess, GLUmesh *mesh ); +void __gl_renderBoundary( GLUtesselator *tess, GLUmesh *mesh ); + +GLboolean __gl_renderCache( GLUtesselator *tess ); + +#endif diff --git a/src/glu/sgi/libtess/sweep.c b/src/glu/sgi/libtess/sweep.c new file mode 100644 index 0000000..eca828f --- /dev/null +++ b/src/glu/sgi/libtess/sweep.c @@ -0,0 +1,1361 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#include "gluos.h" +#include +#include +#include /* longjmp */ +#include /* LONG_MAX */ + +#include "mesh.h" +#include "geom.h" +#include "tess.h" +#include "dict.h" +#include "priorityq.h" +#include "memalloc.h" +#include "sweep.h" + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +#ifdef FOR_TRITE_TEST_PROGRAM +extern void DebugEvent( GLUtesselator *tess ); +#else +#define DebugEvent( tess ) +#endif + +/* + * Invariants for the Edge Dictionary. + * - each pair of adjacent edges e2=Succ(e1) satisfies EdgeLeq(e1,e2) + * at any valid location of the sweep event + * - if EdgeLeq(e2,e1) as well (at any valid sweep event), then e1 and e2 + * share a common endpoint + * - for each e, e->Dst has been processed, but not e->Org + * - each edge e satisfies VertLeq(e->Dst,event) && VertLeq(event,e->Org) + * where "event" is the current sweep line event. + * - no edge e has zero length + * + * Invariants for the Mesh (the processed portion). + * - the portion of the mesh left of the sweep line is a planar graph, + * ie. there is *some* way to embed it in the plane + * - no processed edge has zero length + * - no two processed vertices have identical coordinates + * - each "inside" region is monotone, ie. can be broken into two chains + * of monotonically increasing vertices according to VertLeq(v1,v2) + * - a non-invariant: these chains may intersect (very slightly) + * + * Invariants for the Sweep. + * - if none of the edges incident to the event vertex have an activeRegion + * (ie. none of these edges are in the edge dictionary), then the vertex + * has only right-going edges. + * - if an edge is marked "fixUpperEdge" (it is a temporary edge introduced + * by ConnectRightVertex), then it is the only right-going edge from + * its associated vertex. (This says that these edges exist only + * when it is necessary.) + */ + +#undef MAX +#undef MIN +#define MAX(x,y) ((x) >= (y) ? (x) : (y)) +#define MIN(x,y) ((x) <= (y) ? (x) : (y)) + +/* When we merge two edges into one, we need to compute the combined + * winding of the new edge. + */ +#define AddWinding(eDst,eSrc) (eDst->winding += eSrc->winding, \ + eDst->Sym->winding += eSrc->Sym->winding) + +static void SweepEvent( GLUtesselator *tess, GLUvertex *vEvent ); +static void WalkDirtyRegions( GLUtesselator *tess, ActiveRegion *regUp ); +static int CheckForRightSplice( GLUtesselator *tess, ActiveRegion *regUp ); + +static int EdgeLeq( GLUtesselator *tess, ActiveRegion *reg1, + ActiveRegion *reg2 ) +/* + * Both edges must be directed from right to left (this is the canonical + * direction for the upper edge of each region). + * + * The strategy is to evaluate a "t" value for each edge at the + * current sweep line position, given by tess->event. The calculations + * are designed to be very stable, but of course they are not perfect. + * + * Special case: if both edge destinations are at the sweep event, + * we sort the edges by slope (they would otherwise compare equally). + */ +{ + GLUvertex *event = tess->event; + GLUhalfEdge *e1, *e2; + GLdouble t1, t2; + + e1 = reg1->eUp; + e2 = reg2->eUp; + + if( e1->Dst == event ) { + if( e2->Dst == event ) { + /* Two edges right of the sweep line which meet at the sweep event. + * Sort them by slope. + */ + if( VertLeq( e1->Org, e2->Org )) { + return EdgeSign( e2->Dst, e1->Org, e2->Org ) <= 0; + } + return EdgeSign( e1->Dst, e2->Org, e1->Org ) >= 0; + } + return EdgeSign( e2->Dst, event, e2->Org ) <= 0; + } + if( e2->Dst == event ) { + return EdgeSign( e1->Dst, event, e1->Org ) >= 0; + } + + /* General case - compute signed distance *from* e1, e2 to event */ + t1 = EdgeEval( e1->Dst, event, e1->Org ); + t2 = EdgeEval( e2->Dst, event, e2->Org ); + return (t1 >= t2); +} + + +static void DeleteRegion( GLUtesselator *tess, ActiveRegion *reg ) +{ + if( reg->fixUpperEdge ) { + /* It was created with zero winding number, so it better be + * deleted with zero winding number (ie. it better not get merged + * with a real edge). + */ + assert( reg->eUp->winding == 0 ); + } + reg->eUp->activeRegion = NULL; + dictDelete( tess->dict, reg->nodeUp ); /* __gl_dictListDelete */ + memFree( reg ); +} + + +static int FixUpperEdge( ActiveRegion *reg, GLUhalfEdge *newEdge ) +/* + * Replace an upper edge which needs fixing (see ConnectRightVertex). + */ +{ + assert( reg->fixUpperEdge ); + if ( !__gl_meshDelete( reg->eUp ) ) return 0; + reg->fixUpperEdge = FALSE; + reg->eUp = newEdge; + newEdge->activeRegion = reg; + + return 1; +} + +static ActiveRegion *TopLeftRegion( ActiveRegion *reg ) +{ + GLUvertex *org = reg->eUp->Org; + GLUhalfEdge *e; + + /* Find the region above the uppermost edge with the same origin */ + do { + reg = RegionAbove( reg ); + } while( reg->eUp->Org == org ); + + /* If the edge above was a temporary edge introduced by ConnectRightVertex, + * now is the time to fix it. + */ + if( reg->fixUpperEdge ) { + e = __gl_meshConnect( RegionBelow(reg)->eUp->Sym, reg->eUp->Lnext ); + if (e == NULL) return NULL; + if ( !FixUpperEdge( reg, e ) ) return NULL; + reg = RegionAbove( reg ); + } + return reg; +} + +static ActiveRegion *TopRightRegion( ActiveRegion *reg ) +{ + GLUvertex *dst = reg->eUp->Dst; + + /* Find the region above the uppermost edge with the same destination */ + do { + reg = RegionAbove( reg ); + } while( reg->eUp->Dst == dst ); + return reg; +} + +static ActiveRegion *AddRegionBelow( GLUtesselator *tess, + ActiveRegion *regAbove, + GLUhalfEdge *eNewUp ) +/* + * Add a new active region to the sweep line, *somewhere* below "regAbove" + * (according to where the new edge belongs in the sweep-line dictionary). + * The upper edge of the new region will be "eNewUp". + * Winding number and "inside" flag are not updated. + */ +{ + ActiveRegion *regNew = (ActiveRegion *)memAlloc( sizeof( ActiveRegion )); + if (regNew == NULL) longjmp(tess->env,1); + + regNew->eUp = eNewUp; + /* __gl_dictListInsertBefore */ + regNew->nodeUp = dictInsertBefore( tess->dict, regAbove->nodeUp, regNew ); + if (regNew->nodeUp == NULL) longjmp(tess->env,1); + regNew->fixUpperEdge = FALSE; + regNew->sentinel = FALSE; + regNew->dirty = FALSE; + + eNewUp->activeRegion = regNew; + return regNew; +} + +static GLboolean IsWindingInside( GLUtesselator *tess, int n ) +{ + switch( tess->windingRule ) { + case GLU_TESS_WINDING_ODD: + return (n & 1); + case GLU_TESS_WINDING_NONZERO: + return (n != 0); + case GLU_TESS_WINDING_POSITIVE: + return (n > 0); + case GLU_TESS_WINDING_NEGATIVE: + return (n < 0); + case GLU_TESS_WINDING_ABS_GEQ_TWO: + return (n >= 2) || (n <= -2); + } + /*LINTED*/ + assert( FALSE ); + /*NOTREACHED*/ + return GL_FALSE; /* avoid compiler complaints */ +} + + +static void ComputeWinding( GLUtesselator *tess, ActiveRegion *reg ) +{ + reg->windingNumber = RegionAbove(reg)->windingNumber + reg->eUp->winding; + reg->inside = IsWindingInside( tess, reg->windingNumber ); +} + + +static void FinishRegion( GLUtesselator *tess, ActiveRegion *reg ) +/* + * Delete a region from the sweep line. This happens when the upper + * and lower chains of a region meet (at a vertex on the sweep line). + * The "inside" flag is copied to the appropriate mesh face (we could + * not do this before -- since the structure of the mesh is always + * changing, this face may not have even existed until now). + */ +{ + GLUhalfEdge *e = reg->eUp; + GLUface *f = e->Lface; + + f->inside = reg->inside; + f->anEdge = e; /* optimization for __gl_meshTessellateMonoRegion() */ + DeleteRegion( tess, reg ); +} + + +static GLUhalfEdge *FinishLeftRegions( GLUtesselator *tess, + ActiveRegion *regFirst, ActiveRegion *regLast ) +/* + * We are given a vertex with one or more left-going edges. All affected + * edges should be in the edge dictionary. Starting at regFirst->eUp, + * we walk down deleting all regions where both edges have the same + * origin vOrg. At the same time we copy the "inside" flag from the + * active region to the face, since at this point each face will belong + * to at most one region (this was not necessarily true until this point + * in the sweep). The walk stops at the region above regLast; if regLast + * is NULL we walk as far as possible. At the same time we relink the + * mesh if necessary, so that the ordering of edges around vOrg is the + * same as in the dictionary. + */ +{ + ActiveRegion *reg, *regPrev; + GLUhalfEdge *e, *ePrev; + + regPrev = regFirst; + ePrev = regFirst->eUp; + while( regPrev != regLast ) { + regPrev->fixUpperEdge = FALSE; /* placement was OK */ + reg = RegionBelow( regPrev ); + e = reg->eUp; + if( e->Org != ePrev->Org ) { + if( ! reg->fixUpperEdge ) { + /* Remove the last left-going edge. Even though there are no further + * edges in the dictionary with this origin, there may be further + * such edges in the mesh (if we are adding left edges to a vertex + * that has already been processed). Thus it is important to call + * FinishRegion rather than just DeleteRegion. + */ + FinishRegion( tess, regPrev ); + break; + } + /* If the edge below was a temporary edge introduced by + * ConnectRightVertex, now is the time to fix it. + */ + e = __gl_meshConnect( ePrev->Lprev, e->Sym ); + if (e == NULL) longjmp(tess->env,1); + if ( !FixUpperEdge( reg, e ) ) longjmp(tess->env,1); + } + + /* Relink edges so that ePrev->Onext == e */ + if( ePrev->Onext != e ) { + if ( !__gl_meshSplice( e->Oprev, e ) ) longjmp(tess->env,1); + if ( !__gl_meshSplice( ePrev, e ) ) longjmp(tess->env,1); + } + FinishRegion( tess, regPrev ); /* may change reg->eUp */ + ePrev = reg->eUp; + regPrev = reg; + } + return ePrev; +} + + +static void AddRightEdges( GLUtesselator *tess, ActiveRegion *regUp, + GLUhalfEdge *eFirst, GLUhalfEdge *eLast, GLUhalfEdge *eTopLeft, + GLboolean cleanUp ) +/* + * Purpose: insert right-going edges into the edge dictionary, and update + * winding numbers and mesh connectivity appropriately. All right-going + * edges share a common origin vOrg. Edges are inserted CCW starting at + * eFirst; the last edge inserted is eLast->Oprev. If vOrg has any + * left-going edges already processed, then eTopLeft must be the edge + * such that an imaginary upward vertical segment from vOrg would be + * contained between eTopLeft->Oprev and eTopLeft; otherwise eTopLeft + * should be NULL. + */ +{ + ActiveRegion *reg, *regPrev; + GLUhalfEdge *e, *ePrev; + int firstTime = TRUE; + + /* Insert the new right-going edges in the dictionary */ + e = eFirst; + do { + assert( VertLeq( e->Org, e->Dst )); + AddRegionBelow( tess, regUp, e->Sym ); + e = e->Onext; + } while ( e != eLast ); + + /* Walk *all* right-going edges from e->Org, in the dictionary order, + * updating the winding numbers of each region, and re-linking the mesh + * edges to match the dictionary ordering (if necessary). + */ + if( eTopLeft == NULL ) { + eTopLeft = RegionBelow( regUp )->eUp->Rprev; + } + regPrev = regUp; + ePrev = eTopLeft; + for( ;; ) { + reg = RegionBelow( regPrev ); + e = reg->eUp->Sym; + if( e->Org != ePrev->Org ) break; + + if( e->Onext != ePrev ) { + /* Unlink e from its current position, and relink below ePrev */ + if ( !__gl_meshSplice( e->Oprev, e ) ) longjmp(tess->env,1); + if ( !__gl_meshSplice( ePrev->Oprev, e ) ) longjmp(tess->env,1); + } + /* Compute the winding number and "inside" flag for the new regions */ + reg->windingNumber = regPrev->windingNumber - e->winding; + reg->inside = IsWindingInside( tess, reg->windingNumber ); + + /* Check for two outgoing edges with same slope -- process these + * before any intersection tests (see example in __gl_computeInterior). + */ + regPrev->dirty = TRUE; + if( ! firstTime && CheckForRightSplice( tess, regPrev )) { + AddWinding( e, ePrev ); + DeleteRegion( tess, regPrev ); + if ( !__gl_meshDelete( ePrev ) ) longjmp(tess->env,1); + } + firstTime = FALSE; + regPrev = reg; + ePrev = e; + } + regPrev->dirty = TRUE; + assert( regPrev->windingNumber - e->winding == reg->windingNumber ); + + if( cleanUp ) { + /* Check for intersections between newly adjacent edges. */ + WalkDirtyRegions( tess, regPrev ); + } +} + + +static void CallCombine( GLUtesselator *tess, GLUvertex *isect, + void *data[4], GLfloat weights[4], int needed ) +{ + GLdouble coords[3]; + + /* Copy coord data in case the callback changes it. */ + coords[0] = isect->coords[0]; + coords[1] = isect->coords[1]; + coords[2] = isect->coords[2]; + + isect->data = NULL; + CALL_COMBINE_OR_COMBINE_DATA( coords, data, weights, &isect->data ); + if( isect->data == NULL ) { + if( ! needed ) { + isect->data = data[0]; + } else if( ! tess->fatalError ) { + /* The only way fatal error is when two edges are found to intersect, + * but the user has not provided the callback necessary to handle + * generated intersection points. + */ + CALL_ERROR_OR_ERROR_DATA( GLU_TESS_NEED_COMBINE_CALLBACK ); + tess->fatalError = TRUE; + } + } +} + +static void SpliceMergeVertices( GLUtesselator *tess, GLUhalfEdge *e1, + GLUhalfEdge *e2 ) +/* + * Two vertices with idential coordinates are combined into one. + * e1->Org is kept, while e2->Org is discarded. + */ +{ + void *data[4] = { NULL, NULL, NULL, NULL }; + GLfloat weights[4] = { 0.5, 0.5, 0.0, 0.0 }; + + data[0] = e1->Org->data; + data[1] = e2->Org->data; + CallCombine( tess, e1->Org, data, weights, FALSE ); + if ( !__gl_meshSplice( e1, e2 ) ) longjmp(tess->env,1); +} + +static void VertexWeights( GLUvertex *isect, GLUvertex *org, GLUvertex *dst, + GLfloat *weights ) +/* + * Find some weights which describe how the intersection vertex is + * a linear combination of "org" and "dest". Each of the two edges + * which generated "isect" is allocated 50% of the weight; each edge + * splits the weight between its org and dst according to the + * relative distance to "isect". + */ +{ + GLdouble t1 = VertL1dist( org, isect ); + GLdouble t2 = VertL1dist( dst, isect ); + + weights[0] = 0.5 * t2 / (t1 + t2); + weights[1] = 0.5 * t1 / (t1 + t2); + isect->coords[0] += weights[0]*org->coords[0] + weights[1]*dst->coords[0]; + isect->coords[1] += weights[0]*org->coords[1] + weights[1]*dst->coords[1]; + isect->coords[2] += weights[0]*org->coords[2] + weights[1]*dst->coords[2]; +} + + +static void GetIntersectData( GLUtesselator *tess, GLUvertex *isect, + GLUvertex *orgUp, GLUvertex *dstUp, + GLUvertex *orgLo, GLUvertex *dstLo ) +/* + * We've computed a new intersection point, now we need a "data" pointer + * from the user so that we can refer to this new vertex in the + * rendering callbacks. + */ +{ + void *data[4]; + GLfloat weights[4]; + + data[0] = orgUp->data; + data[1] = dstUp->data; + data[2] = orgLo->data; + data[3] = dstLo->data; + + isect->coords[0] = isect->coords[1] = isect->coords[2] = 0; + VertexWeights( isect, orgUp, dstUp, &weights[0] ); + VertexWeights( isect, orgLo, dstLo, &weights[2] ); + + CallCombine( tess, isect, data, weights, TRUE ); +} + +static int CheckForRightSplice( GLUtesselator *tess, ActiveRegion *regUp ) +/* + * Check the upper and lower edge of "regUp", to make sure that the + * eUp->Org is above eLo, or eLo->Org is below eUp (depending on which + * origin is leftmost). + * + * The main purpose is to splice right-going edges with the same + * dest vertex and nearly identical slopes (ie. we can't distinguish + * the slopes numerically). However the splicing can also help us + * to recover from numerical errors. For example, suppose at one + * point we checked eUp and eLo, and decided that eUp->Org is barely + * above eLo. Then later, we split eLo into two edges (eg. from + * a splice operation like this one). This can change the result of + * our test so that now eUp->Org is incident to eLo, or barely below it. + * We must correct this condition to maintain the dictionary invariants. + * + * One possibility is to check these edges for intersection again + * (ie. CheckForIntersect). This is what we do if possible. However + * CheckForIntersect requires that tess->event lies between eUp and eLo, + * so that it has something to fall back on when the intersection + * calculation gives us an unusable answer. So, for those cases where + * we can't check for intersection, this routine fixes the problem + * by just splicing the offending vertex into the other edge. + * This is a guaranteed solution, no matter how degenerate things get. + * Basically this is a combinatorial solution to a numerical problem. + */ +{ + ActiveRegion *regLo = RegionBelow(regUp); + GLUhalfEdge *eUp = regUp->eUp; + GLUhalfEdge *eLo = regLo->eUp; + + if( VertLeq( eUp->Org, eLo->Org )) { + if( EdgeSign( eLo->Dst, eUp->Org, eLo->Org ) > 0 ) return FALSE; + + /* eUp->Org appears to be below eLo */ + if( ! VertEq( eUp->Org, eLo->Org )) { + /* Splice eUp->Org into eLo */ + if ( __gl_meshSplitEdge( eLo->Sym ) == NULL) longjmp(tess->env,1); + if ( !__gl_meshSplice( eUp, eLo->Oprev ) ) longjmp(tess->env,1); + regUp->dirty = regLo->dirty = TRUE; + + } else if( eUp->Org != eLo->Org ) { + /* merge the two vertices, discarding eUp->Org */ + pqDelete( tess->pq, eUp->Org->pqHandle ); /* __gl_pqSortDelete */ + SpliceMergeVertices( tess, eLo->Oprev, eUp ); + } + } else { + if( EdgeSign( eUp->Dst, eLo->Org, eUp->Org ) < 0 ) return FALSE; + + /* eLo->Org appears to be above eUp, so splice eLo->Org into eUp */ + RegionAbove(regUp)->dirty = regUp->dirty = TRUE; + if (__gl_meshSplitEdge( eUp->Sym ) == NULL) longjmp(tess->env,1); + if ( !__gl_meshSplice( eLo->Oprev, eUp ) ) longjmp(tess->env,1); + } + return TRUE; +} + +static int CheckForLeftSplice( GLUtesselator *tess, ActiveRegion *regUp ) +/* + * Check the upper and lower edge of "regUp", to make sure that the + * eUp->Dst is above eLo, or eLo->Dst is below eUp (depending on which + * destination is rightmost). + * + * Theoretically, this should always be true. However, splitting an edge + * into two pieces can change the results of previous tests. For example, + * suppose at one point we checked eUp and eLo, and decided that eUp->Dst + * is barely above eLo. Then later, we split eLo into two edges (eg. from + * a splice operation like this one). This can change the result of + * the test so that now eUp->Dst is incident to eLo, or barely below it. + * We must correct this condition to maintain the dictionary invariants + * (otherwise new edges might get inserted in the wrong place in the + * dictionary, and bad stuff will happen). + * + * We fix the problem by just splicing the offending vertex into the + * other edge. + */ +{ + ActiveRegion *regLo = RegionBelow(regUp); + GLUhalfEdge *eUp = regUp->eUp; + GLUhalfEdge *eLo = regLo->eUp; + GLUhalfEdge *e; + + assert( ! VertEq( eUp->Dst, eLo->Dst )); + + if( VertLeq( eUp->Dst, eLo->Dst )) { + if( EdgeSign( eUp->Dst, eLo->Dst, eUp->Org ) < 0 ) return FALSE; + + /* eLo->Dst is above eUp, so splice eLo->Dst into eUp */ + RegionAbove(regUp)->dirty = regUp->dirty = TRUE; + e = __gl_meshSplitEdge( eUp ); + if (e == NULL) longjmp(tess->env,1); + if ( !__gl_meshSplice( eLo->Sym, e ) ) longjmp(tess->env,1); + e->Lface->inside = regUp->inside; + } else { + if( EdgeSign( eLo->Dst, eUp->Dst, eLo->Org ) > 0 ) return FALSE; + + /* eUp->Dst is below eLo, so splice eUp->Dst into eLo */ + regUp->dirty = regLo->dirty = TRUE; + e = __gl_meshSplitEdge( eLo ); + if (e == NULL) longjmp(tess->env,1); + if ( !__gl_meshSplice( eUp->Lnext, eLo->Sym ) ) longjmp(tess->env,1); + e->Rface->inside = regUp->inside; + } + return TRUE; +} + + +static int CheckForIntersect( GLUtesselator *tess, ActiveRegion *regUp ) +/* + * Check the upper and lower edges of the given region to see if + * they intersect. If so, create the intersection and add it + * to the data structures. + * + * Returns TRUE if adding the new intersection resulted in a recursive + * call to AddRightEdges(); in this case all "dirty" regions have been + * checked for intersections, and possibly regUp has been deleted. + */ +{ + ActiveRegion *regLo = RegionBelow(regUp); + GLUhalfEdge *eUp = regUp->eUp; + GLUhalfEdge *eLo = regLo->eUp; + GLUvertex *orgUp = eUp->Org; + GLUvertex *orgLo = eLo->Org; + GLUvertex *dstUp = eUp->Dst; + GLUvertex *dstLo = eLo->Dst; + GLdouble tMinUp, tMaxLo; + GLUvertex isect, *orgMin; + GLUhalfEdge *e; + + assert( ! VertEq( dstLo, dstUp )); + assert( EdgeSign( dstUp, tess->event, orgUp ) <= 0 ); + assert( EdgeSign( dstLo, tess->event, orgLo ) >= 0 ); + assert( orgUp != tess->event && orgLo != tess->event ); + assert( ! regUp->fixUpperEdge && ! regLo->fixUpperEdge ); + + if( orgUp == orgLo ) return FALSE; /* right endpoints are the same */ + + tMinUp = MIN( orgUp->t, dstUp->t ); + tMaxLo = MAX( orgLo->t, dstLo->t ); + if( tMinUp > tMaxLo ) return FALSE; /* t ranges do not overlap */ + + if( VertLeq( orgUp, orgLo )) { + if( EdgeSign( dstLo, orgUp, orgLo ) > 0 ) return FALSE; + } else { + if( EdgeSign( dstUp, orgLo, orgUp ) < 0 ) return FALSE; + } + + /* At this point the edges intersect, at least marginally */ + DebugEvent( tess ); + + __gl_edgeIntersect( dstUp, orgUp, dstLo, orgLo, &isect ); + /* The following properties are guaranteed: */ + assert( MIN( orgUp->t, dstUp->t ) <= isect.t ); + assert( isect.t <= MAX( orgLo->t, dstLo->t )); + assert( MIN( dstLo->s, dstUp->s ) <= isect.s ); + assert( isect.s <= MAX( orgLo->s, orgUp->s )); + + if( VertLeq( &isect, tess->event )) { + /* The intersection point lies slightly to the left of the sweep line, + * so move it until it''s slightly to the right of the sweep line. + * (If we had perfect numerical precision, this would never happen + * in the first place). The easiest and safest thing to do is + * replace the intersection by tess->event. + */ + isect.s = tess->event->s; + isect.t = tess->event->t; + } + /* Similarly, if the computed intersection lies to the right of the + * rightmost origin (which should rarely happen), it can cause + * unbelievable inefficiency on sufficiently degenerate inputs. + * (If you have the test program, try running test54.d with the + * "X zoom" option turned on). + */ + orgMin = VertLeq( orgUp, orgLo ) ? orgUp : orgLo; + if( VertLeq( orgMin, &isect )) { + isect.s = orgMin->s; + isect.t = orgMin->t; + } + + if( VertEq( &isect, orgUp ) || VertEq( &isect, orgLo )) { + /* Easy case -- intersection at one of the right endpoints */ + (void) CheckForRightSplice( tess, regUp ); + return FALSE; + } + + if( (! VertEq( dstUp, tess->event ) + && EdgeSign( dstUp, tess->event, &isect ) >= 0) + || (! VertEq( dstLo, tess->event ) + && EdgeSign( dstLo, tess->event, &isect ) <= 0 )) + { + /* Very unusual -- the new upper or lower edge would pass on the + * wrong side of the sweep event, or through it. This can happen + * due to very small numerical errors in the intersection calculation. + */ + if( dstLo == tess->event ) { + /* Splice dstLo into eUp, and process the new region(s) */ + if (__gl_meshSplitEdge( eUp->Sym ) == NULL) longjmp(tess->env,1); + if ( !__gl_meshSplice( eLo->Sym, eUp ) ) longjmp(tess->env,1); + regUp = TopLeftRegion( regUp ); + if (regUp == NULL) longjmp(tess->env,1); + eUp = RegionBelow(regUp)->eUp; + FinishLeftRegions( tess, RegionBelow(regUp), regLo ); + AddRightEdges( tess, regUp, eUp->Oprev, eUp, eUp, TRUE ); + return TRUE; + } + if( dstUp == tess->event ) { + /* Splice dstUp into eLo, and process the new region(s) */ + if (__gl_meshSplitEdge( eLo->Sym ) == NULL) longjmp(tess->env,1); + if ( !__gl_meshSplice( eUp->Lnext, eLo->Oprev ) ) longjmp(tess->env,1); + regLo = regUp; + regUp = TopRightRegion( regUp ); + e = RegionBelow(regUp)->eUp->Rprev; + regLo->eUp = eLo->Oprev; + eLo = FinishLeftRegions( tess, regLo, NULL ); + AddRightEdges( tess, regUp, eLo->Onext, eUp->Rprev, e, TRUE ); + return TRUE; + } + /* Special case: called from ConnectRightVertex. If either + * edge passes on the wrong side of tess->event, split it + * (and wait for ConnectRightVertex to splice it appropriately). + */ + if( EdgeSign( dstUp, tess->event, &isect ) >= 0 ) { + RegionAbove(regUp)->dirty = regUp->dirty = TRUE; + if (__gl_meshSplitEdge( eUp->Sym ) == NULL) longjmp(tess->env,1); + eUp->Org->s = tess->event->s; + eUp->Org->t = tess->event->t; + } + if( EdgeSign( dstLo, tess->event, &isect ) <= 0 ) { + regUp->dirty = regLo->dirty = TRUE; + if (__gl_meshSplitEdge( eLo->Sym ) == NULL) longjmp(tess->env,1); + eLo->Org->s = tess->event->s; + eLo->Org->t = tess->event->t; + } + /* leave the rest for ConnectRightVertex */ + return FALSE; + } + + /* General case -- split both edges, splice into new vertex. + * When we do the splice operation, the order of the arguments is + * arbitrary as far as correctness goes. However, when the operation + * creates a new face, the work done is proportional to the size of + * the new face. We expect the faces in the processed part of + * the mesh (ie. eUp->Lface) to be smaller than the faces in the + * unprocessed original contours (which will be eLo->Oprev->Lface). + */ + if (__gl_meshSplitEdge( eUp->Sym ) == NULL) longjmp(tess->env,1); + if (__gl_meshSplitEdge( eLo->Sym ) == NULL) longjmp(tess->env,1); + if ( !__gl_meshSplice( eLo->Oprev, eUp ) ) longjmp(tess->env,1); + eUp->Org->s = isect.s; + eUp->Org->t = isect.t; + eUp->Org->pqHandle = pqInsert( tess->pq, eUp->Org ); /* __gl_pqSortInsert */ + if (eUp->Org->pqHandle == LONG_MAX) { + pqDeletePriorityQ(tess->pq); /* __gl_pqSortDeletePriorityQ */ + tess->pq = NULL; + longjmp(tess->env,1); + } + GetIntersectData( tess, eUp->Org, orgUp, dstUp, orgLo, dstLo ); + RegionAbove(regUp)->dirty = regUp->dirty = regLo->dirty = TRUE; + return FALSE; +} + +static void WalkDirtyRegions( GLUtesselator *tess, ActiveRegion *regUp ) +/* + * When the upper or lower edge of any region changes, the region is + * marked "dirty". This routine walks through all the dirty regions + * and makes sure that the dictionary invariants are satisfied + * (see the comments at the beginning of this file). Of course + * new dirty regions can be created as we make changes to restore + * the invariants. + */ +{ + ActiveRegion *regLo = RegionBelow(regUp); + GLUhalfEdge *eUp, *eLo; + + for( ;; ) { + /* Find the lowest dirty region (we walk from the bottom up). */ + while( regLo->dirty ) { + regUp = regLo; + regLo = RegionBelow(regLo); + } + if( ! regUp->dirty ) { + regLo = regUp; + regUp = RegionAbove( regUp ); + if( regUp == NULL || ! regUp->dirty ) { + /* We've walked all the dirty regions */ + return; + } + } + regUp->dirty = FALSE; + eUp = regUp->eUp; + eLo = regLo->eUp; + + if( eUp->Dst != eLo->Dst ) { + /* Check that the edge ordering is obeyed at the Dst vertices. */ + if( CheckForLeftSplice( tess, regUp )) { + + /* If the upper or lower edge was marked fixUpperEdge, then + * we no longer need it (since these edges are needed only for + * vertices which otherwise have no right-going edges). + */ + if( regLo->fixUpperEdge ) { + DeleteRegion( tess, regLo ); + if ( !__gl_meshDelete( eLo ) ) longjmp(tess->env,1); + regLo = RegionBelow( regUp ); + eLo = regLo->eUp; + } else if( regUp->fixUpperEdge ) { + DeleteRegion( tess, regUp ); + if ( !__gl_meshDelete( eUp ) ) longjmp(tess->env,1); + regUp = RegionAbove( regLo ); + eUp = regUp->eUp; + } + } + } + if( eUp->Org != eLo->Org ) { + if( eUp->Dst != eLo->Dst + && ! regUp->fixUpperEdge && ! regLo->fixUpperEdge + && (eUp->Dst == tess->event || eLo->Dst == tess->event) ) + { + /* When all else fails in CheckForIntersect(), it uses tess->event + * as the intersection location. To make this possible, it requires + * that tess->event lie between the upper and lower edges, and also + * that neither of these is marked fixUpperEdge (since in the worst + * case it might splice one of these edges into tess->event, and + * violate the invariant that fixable edges are the only right-going + * edge from their associated vertex). + */ + if( CheckForIntersect( tess, regUp )) { + /* WalkDirtyRegions() was called recursively; we're done */ + return; + } + } else { + /* Even though we can't use CheckForIntersect(), the Org vertices + * may violate the dictionary edge ordering. Check and correct this. + */ + (void) CheckForRightSplice( tess, regUp ); + } + } + if( eUp->Org == eLo->Org && eUp->Dst == eLo->Dst ) { + /* A degenerate loop consisting of only two edges -- delete it. */ + AddWinding( eLo, eUp ); + DeleteRegion( tess, regUp ); + if ( !__gl_meshDelete( eUp ) ) longjmp(tess->env,1); + regUp = RegionAbove( regLo ); + } + } +} + + +static void ConnectRightVertex( GLUtesselator *tess, ActiveRegion *regUp, + GLUhalfEdge *eBottomLeft ) +/* + * Purpose: connect a "right" vertex vEvent (one where all edges go left) + * to the unprocessed portion of the mesh. Since there are no right-going + * edges, two regions (one above vEvent and one below) are being merged + * into one. "regUp" is the upper of these two regions. + * + * There are two reasons for doing this (adding a right-going edge): + * - if the two regions being merged are "inside", we must add an edge + * to keep them separated (the combined region would not be monotone). + * - in any case, we must leave some record of vEvent in the dictionary, + * so that we can merge vEvent with features that we have not seen yet. + * For example, maybe there is a vertical edge which passes just to + * the right of vEvent; we would like to splice vEvent into this edge. + * + * However, we don't want to connect vEvent to just any vertex. We don''t + * want the new edge to cross any other edges; otherwise we will create + * intersection vertices even when the input data had no self-intersections. + * (This is a bad thing; if the user's input data has no intersections, + * we don't want to generate any false intersections ourselves.) + * + * Our eventual goal is to connect vEvent to the leftmost unprocessed + * vertex of the combined region (the union of regUp and regLo). + * But because of unseen vertices with all right-going edges, and also + * new vertices which may be created by edge intersections, we don''t + * know where that leftmost unprocessed vertex is. In the meantime, we + * connect vEvent to the closest vertex of either chain, and mark the region + * as "fixUpperEdge". This flag says to delete and reconnect this edge + * to the next processed vertex on the boundary of the combined region. + * Quite possibly the vertex we connected to will turn out to be the + * closest one, in which case we won''t need to make any changes. + */ +{ + GLUhalfEdge *eNew; + GLUhalfEdge *eTopLeft = eBottomLeft->Onext; + ActiveRegion *regLo = RegionBelow(regUp); + GLUhalfEdge *eUp = regUp->eUp; + GLUhalfEdge *eLo = regLo->eUp; + int degenerate = FALSE; + + if( eUp->Dst != eLo->Dst ) { + (void) CheckForIntersect( tess, regUp ); + } + + /* Possible new degeneracies: upper or lower edge of regUp may pass + * through vEvent, or may coincide with new intersection vertex + */ + if( VertEq( eUp->Org, tess->event )) { + if ( !__gl_meshSplice( eTopLeft->Oprev, eUp ) ) longjmp(tess->env,1); + regUp = TopLeftRegion( regUp ); + if (regUp == NULL) longjmp(tess->env,1); + eTopLeft = RegionBelow( regUp )->eUp; + FinishLeftRegions( tess, RegionBelow(regUp), regLo ); + degenerate = TRUE; + } + if( VertEq( eLo->Org, tess->event )) { + if ( !__gl_meshSplice( eBottomLeft, eLo->Oprev ) ) longjmp(tess->env,1); + eBottomLeft = FinishLeftRegions( tess, regLo, NULL ); + degenerate = TRUE; + } + if( degenerate ) { + AddRightEdges( tess, regUp, eBottomLeft->Onext, eTopLeft, eTopLeft, TRUE ); + return; + } + + /* Non-degenerate situation -- need to add a temporary, fixable edge. + * Connect to the closer of eLo->Org, eUp->Org. + */ + if( VertLeq( eLo->Org, eUp->Org )) { + eNew = eLo->Oprev; + } else { + eNew = eUp; + } + eNew = __gl_meshConnect( eBottomLeft->Lprev, eNew ); + if (eNew == NULL) longjmp(tess->env,1); + + /* Prevent cleanup, otherwise eNew might disappear before we've even + * had a chance to mark it as a temporary edge. + */ + AddRightEdges( tess, regUp, eNew, eNew->Onext, eNew->Onext, FALSE ); + eNew->Sym->activeRegion->fixUpperEdge = TRUE; + WalkDirtyRegions( tess, regUp ); +} + +/* Because vertices at exactly the same location are merged together + * before we process the sweep event, some degenerate cases can't occur. + * However if someone eventually makes the modifications required to + * merge features which are close together, the cases below marked + * TOLERANCE_NONZERO will be useful. They were debugged before the + * code to merge identical vertices in the main loop was added. + */ +#define TOLERANCE_NONZERO FALSE + +static void ConnectLeftDegenerate( GLUtesselator *tess, + ActiveRegion *regUp, GLUvertex *vEvent ) +/* + * The event vertex lies exacty on an already-processed edge or vertex. + * Adding the new vertex involves splicing it into the already-processed + * part of the mesh. + */ +{ + GLUhalfEdge *e, *eTopLeft, *eTopRight, *eLast; + ActiveRegion *reg; + + e = regUp->eUp; + if( VertEq( e->Org, vEvent )) { + /* e->Org is an unprocessed vertex - just combine them, and wait + * for e->Org to be pulled from the queue + */ + assert( TOLERANCE_NONZERO ); + SpliceMergeVertices( tess, e, vEvent->anEdge ); + return; + } + + if( ! VertEq( e->Dst, vEvent )) { + /* General case -- splice vEvent into edge e which passes through it */ + if (__gl_meshSplitEdge( e->Sym ) == NULL) longjmp(tess->env,1); + if( regUp->fixUpperEdge ) { + /* This edge was fixable -- delete unused portion of original edge */ + if ( !__gl_meshDelete( e->Onext ) ) longjmp(tess->env,1); + regUp->fixUpperEdge = FALSE; + } + if ( !__gl_meshSplice( vEvent->anEdge, e ) ) longjmp(tess->env,1); + SweepEvent( tess, vEvent ); /* recurse */ + return; + } + + /* vEvent coincides with e->Dst, which has already been processed. + * Splice in the additional right-going edges. + */ + assert( TOLERANCE_NONZERO ); + regUp = TopRightRegion( regUp ); + reg = RegionBelow( regUp ); + eTopRight = reg->eUp->Sym; + eTopLeft = eLast = eTopRight->Onext; + if( reg->fixUpperEdge ) { + /* Here e->Dst has only a single fixable edge going right. + * We can delete it since now we have some real right-going edges. + */ + assert( eTopLeft != eTopRight ); /* there are some left edges too */ + DeleteRegion( tess, reg ); + if ( !__gl_meshDelete( eTopRight ) ) longjmp(tess->env,1); + eTopRight = eTopLeft->Oprev; + } + if ( !__gl_meshSplice( vEvent->anEdge, eTopRight ) ) longjmp(tess->env,1); + if( ! EdgeGoesLeft( eTopLeft )) { + /* e->Dst had no left-going edges -- indicate this to AddRightEdges() */ + eTopLeft = NULL; + } + AddRightEdges( tess, regUp, eTopRight->Onext, eLast, eTopLeft, TRUE ); +} + + +static void ConnectLeftVertex( GLUtesselator *tess, GLUvertex *vEvent ) +/* + * Purpose: connect a "left" vertex (one where both edges go right) + * to the processed portion of the mesh. Let R be the active region + * containing vEvent, and let U and L be the upper and lower edge + * chains of R. There are two possibilities: + * + * - the normal case: split R into two regions, by connecting vEvent to + * the rightmost vertex of U or L lying to the left of the sweep line + * + * - the degenerate case: if vEvent is close enough to U or L, we + * merge vEvent into that edge chain. The subcases are: + * - merging with the rightmost vertex of U or L + * - merging with the active edge of U or L + * - merging with an already-processed portion of U or L + */ +{ + ActiveRegion *regUp, *regLo, *reg; + GLUhalfEdge *eUp, *eLo, *eNew; + ActiveRegion tmp; + + /* assert( vEvent->anEdge->Onext->Onext == vEvent->anEdge ); */ + + /* Get a pointer to the active region containing vEvent */ + tmp.eUp = vEvent->anEdge->Sym; + /* __GL_DICTLISTKEY */ /* __gl_dictListSearch */ + regUp = (ActiveRegion *)dictKey( dictSearch( tess->dict, &tmp )); + regLo = RegionBelow( regUp ); + eUp = regUp->eUp; + eLo = regLo->eUp; + + /* Try merging with U or L first */ + if( EdgeSign( eUp->Dst, vEvent, eUp->Org ) == 0 ) { + ConnectLeftDegenerate( tess, regUp, vEvent ); + return; + } + + /* Connect vEvent to rightmost processed vertex of either chain. + * e->Dst is the vertex that we will connect to vEvent. + */ + reg = VertLeq( eLo->Dst, eUp->Dst ) ? regUp : regLo; + + if( regUp->inside || reg->fixUpperEdge) { + if( reg == regUp ) { + eNew = __gl_meshConnect( vEvent->anEdge->Sym, eUp->Lnext ); + if (eNew == NULL) longjmp(tess->env,1); + } else { + GLUhalfEdge *tempHalfEdge= __gl_meshConnect( eLo->Dnext, vEvent->anEdge); + if (tempHalfEdge == NULL) longjmp(tess->env,1); + + eNew = tempHalfEdge->Sym; + } + if( reg->fixUpperEdge ) { + if ( !FixUpperEdge( reg, eNew ) ) longjmp(tess->env,1); + } else { + ComputeWinding( tess, AddRegionBelow( tess, regUp, eNew )); + } + SweepEvent( tess, vEvent ); + } else { + /* The new vertex is in a region which does not belong to the polygon. + * We don''t need to connect this vertex to the rest of the mesh. + */ + AddRightEdges( tess, regUp, vEvent->anEdge, vEvent->anEdge, NULL, TRUE ); + } +} + + +static void SweepEvent( GLUtesselator *tess, GLUvertex *vEvent ) +/* + * Does everything necessary when the sweep line crosses a vertex. + * Updates the mesh and the edge dictionary. + */ +{ + ActiveRegion *regUp, *reg; + GLUhalfEdge *e, *eTopLeft, *eBottomLeft; + + tess->event = vEvent; /* for access in EdgeLeq() */ + DebugEvent( tess ); + + /* Check if this vertex is the right endpoint of an edge that is + * already in the dictionary. In this case we don't need to waste + * time searching for the location to insert new edges. + */ + e = vEvent->anEdge; + while( e->activeRegion == NULL ) { + e = e->Onext; + if( e == vEvent->anEdge ) { + /* All edges go right -- not incident to any processed edges */ + ConnectLeftVertex( tess, vEvent ); + return; + } + } + + /* Processing consists of two phases: first we "finish" all the + * active regions where both the upper and lower edges terminate + * at vEvent (ie. vEvent is closing off these regions). + * We mark these faces "inside" or "outside" the polygon according + * to their winding number, and delete the edges from the dictionary. + * This takes care of all the left-going edges from vEvent. + */ + regUp = TopLeftRegion( e->activeRegion ); + if (regUp == NULL) longjmp(tess->env,1); + reg = RegionBelow( regUp ); + eTopLeft = reg->eUp; + eBottomLeft = FinishLeftRegions( tess, reg, NULL ); + + /* Next we process all the right-going edges from vEvent. This + * involves adding the edges to the dictionary, and creating the + * associated "active regions" which record information about the + * regions between adjacent dictionary edges. + */ + if( eBottomLeft->Onext == eTopLeft ) { + /* No right-going edges -- add a temporary "fixable" edge */ + ConnectRightVertex( tess, regUp, eBottomLeft ); + } else { + AddRightEdges( tess, regUp, eBottomLeft->Onext, eTopLeft, eTopLeft, TRUE ); + } +} + + +/* Make the sentinel coordinates big enough that they will never be + * merged with real input features. (Even with the largest possible + * input contour and the maximum tolerance of 1.0, no merging will be + * done with coordinates larger than 3 * GLU_TESS_MAX_COORD). + */ +#define SENTINEL_COORD (4 * GLU_TESS_MAX_COORD) + +static void AddSentinel( GLUtesselator *tess, GLdouble t ) +/* + * We add two sentinel edges above and below all other edges, + * to avoid special cases at the top and bottom. + */ +{ + GLUhalfEdge *e; + ActiveRegion *reg = (ActiveRegion *)memAlloc( sizeof( ActiveRegion )); + if (reg == NULL) longjmp(tess->env,1); + + e = __gl_meshMakeEdge( tess->mesh ); + if (e == NULL) longjmp(tess->env,1); + + e->Org->s = SENTINEL_COORD; + e->Org->t = t; + e->Dst->s = -SENTINEL_COORD; + e->Dst->t = t; + tess->event = e->Dst; /* initialize it */ + + reg->eUp = e; + reg->windingNumber = 0; + reg->inside = FALSE; + reg->fixUpperEdge = FALSE; + reg->sentinel = TRUE; + reg->dirty = FALSE; + reg->nodeUp = dictInsert( tess->dict, reg ); /* __gl_dictListInsertBefore */ + if (reg->nodeUp == NULL) longjmp(tess->env,1); +} + + +static void InitEdgeDict( GLUtesselator *tess ) +/* + * We maintain an ordering of edge intersections with the sweep line. + * This order is maintained in a dynamic dictionary. + */ +{ + /* __gl_dictListNewDict */ + tess->dict = dictNewDict( tess, (int (*)(void *, DictKey, DictKey)) EdgeLeq ); + if (tess->dict == NULL) longjmp(tess->env,1); + + AddSentinel( tess, -SENTINEL_COORD ); + AddSentinel( tess, SENTINEL_COORD ); +} + + +static void DoneEdgeDict( GLUtesselator *tess ) +{ + ActiveRegion *reg; +#ifndef NDEBUG + int fixedEdges = 0; +#endif + + /* __GL_DICTLISTKEY */ /* __GL_DICTLISTMIN */ + while( (reg = (ActiveRegion *)dictKey( dictMin( tess->dict ))) != NULL ) { + /* + * At the end of all processing, the dictionary should contain + * only the two sentinel edges, plus at most one "fixable" edge + * created by ConnectRightVertex(). + */ + if( ! reg->sentinel ) { + assert( reg->fixUpperEdge ); + assert( ++fixedEdges == 1 ); + } + assert( reg->windingNumber == 0 ); + DeleteRegion( tess, reg ); +/* __gl_meshDelete( reg->eUp );*/ + } + dictDeleteDict( tess->dict ); /* __gl_dictListDeleteDict */ +} + + +static void RemoveDegenerateEdges( GLUtesselator *tess ) +/* + * Remove zero-length edges, and contours with fewer than 3 vertices. + */ +{ + GLUhalfEdge *e, *eNext, *eLnext; + GLUhalfEdge *eHead = &tess->mesh->eHead; + + /*LINTED*/ + for( e = eHead->next; e != eHead; e = eNext ) { + eNext = e->next; + eLnext = e->Lnext; + + if( VertEq( e->Org, e->Dst ) && e->Lnext->Lnext != e ) { + /* Zero-length edge, contour has at least 3 edges */ + + SpliceMergeVertices( tess, eLnext, e ); /* deletes e->Org */ + if ( !__gl_meshDelete( e ) ) longjmp(tess->env,1); /* e is a self-loop */ + e = eLnext; + eLnext = e->Lnext; + } + if( eLnext->Lnext == e ) { + /* Degenerate contour (one or two edges) */ + + if( eLnext != e ) { + if( eLnext == eNext || eLnext == eNext->Sym ) { eNext = eNext->next; } + if ( !__gl_meshDelete( eLnext ) ) longjmp(tess->env,1); + } + if( e == eNext || e == eNext->Sym ) { eNext = eNext->next; } + if ( !__gl_meshDelete( e ) ) longjmp(tess->env,1); + } + } +} + +static int InitPriorityQ( GLUtesselator *tess ) +/* + * Insert all vertices into the priority queue which determines the + * order in which vertices cross the sweep line. + */ +{ + PriorityQ *pq; + GLUvertex *v, *vHead; + + /* __gl_pqSortNewPriorityQ */ + pq = tess->pq = pqNewPriorityQ( (int (*)(PQkey, PQkey)) __gl_vertLeq ); + if (pq == NULL) return 0; + + vHead = &tess->mesh->vHead; + for( v = vHead->next; v != vHead; v = v->next ) { + v->pqHandle = pqInsert( pq, v ); /* __gl_pqSortInsert */ + if (v->pqHandle == LONG_MAX) break; + } + if (v != vHead || !pqInit( pq ) ) { /* __gl_pqSortInit */ + pqDeletePriorityQ(tess->pq); /* __gl_pqSortDeletePriorityQ */ + tess->pq = NULL; + return 0; + } + + return 1; +} + + +static void DonePriorityQ( GLUtesselator *tess ) +{ + pqDeletePriorityQ( tess->pq ); /* __gl_pqSortDeletePriorityQ */ +} + + +static int RemoveDegenerateFaces( GLUmesh *mesh ) +/* + * Delete any degenerate faces with only two edges. WalkDirtyRegions() + * will catch almost all of these, but it won't catch degenerate faces + * produced by splice operations on already-processed edges. + * The two places this can happen are in FinishLeftRegions(), when + * we splice in a "temporary" edge produced by ConnectRightVertex(), + * and in CheckForLeftSplice(), where we splice already-processed + * edges to ensure that our dictionary invariants are not violated + * by numerical errors. + * + * In both these cases it is *very* dangerous to delete the offending + * edge at the time, since one of the routines further up the stack + * will sometimes be keeping a pointer to that edge. + */ +{ + GLUface *f, *fNext; + GLUhalfEdge *e; + + /*LINTED*/ + for( f = mesh->fHead.next; f != &mesh->fHead; f = fNext ) { + fNext = f->next; + e = f->anEdge; + assert( e->Lnext != e ); + + if( e->Lnext->Lnext == e ) { + /* A face with only two edges */ + AddWinding( e->Onext, e ); + if ( !__gl_meshDelete( e ) ) return 0; + } + } + return 1; +} + +int __gl_computeInterior( GLUtesselator *tess ) +/* + * __gl_computeInterior( tess ) computes the planar arrangement specified + * by the given contours, and further subdivides this arrangement + * into regions. Each region is marked "inside" if it belongs + * to the polygon, according to the rule given by tess->windingRule. + * Each interior region is guaranteed be monotone. + */ +{ + GLUvertex *v, *vNext; + + tess->fatalError = FALSE; + + /* Each vertex defines an event for our sweep line. Start by inserting + * all the vertices in a priority queue. Events are processed in + * lexicographic order, ie. + * + * e1 < e2 iff e1.x < e2.x || (e1.x == e2.x && e1.y < e2.y) + */ + RemoveDegenerateEdges( tess ); + if ( !InitPriorityQ( tess ) ) return 0; /* if error */ + InitEdgeDict( tess ); + + /* __gl_pqSortExtractMin */ + while( (v = (GLUvertex *)pqExtractMin( tess->pq )) != NULL ) { + for( ;; ) { + vNext = (GLUvertex *)pqMinimum( tess->pq ); /* __gl_pqSortMinimum */ + if( vNext == NULL || ! VertEq( vNext, v )) break; + + /* Merge together all vertices at exactly the same location. + * This is more efficient than processing them one at a time, + * simplifies the code (see ConnectLeftDegenerate), and is also + * important for correct handling of certain degenerate cases. + * For example, suppose there are two identical edges A and B + * that belong to different contours (so without this code they would + * be processed by separate sweep events). Suppose another edge C + * crosses A and B from above. When A is processed, we split it + * at its intersection point with C. However this also splits C, + * so when we insert B we may compute a slightly different + * intersection point. This might leave two edges with a small + * gap between them. This kind of error is especially obvious + * when using boundary extraction (GLU_TESS_BOUNDARY_ONLY). + */ + vNext = (GLUvertex *)pqExtractMin( tess->pq ); /* __gl_pqSortExtractMin*/ + SpliceMergeVertices( tess, v->anEdge, vNext->anEdge ); + } + SweepEvent( tess, v ); + } + + /* Set tess->event for debugging purposes */ + /* __GL_DICTLISTKEY */ /* __GL_DICTLISTMIN */ + tess->event = ((ActiveRegion *) dictKey( dictMin( tess->dict )))->eUp->Org; + DebugEvent( tess ); + DoneEdgeDict( tess ); + DonePriorityQ( tess ); + + if ( !RemoveDegenerateFaces( tess->mesh ) ) return 0; + __gl_meshCheckMesh( tess->mesh ); + + return 1; +} diff --git a/src/glu/sgi/libtess/sweep.h b/src/glu/sgi/libtess/sweep.h new file mode 100644 index 0000000..feb68b0 --- /dev/null +++ b/src/glu/sgi/libtess/sweep.h @@ -0,0 +1,77 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#ifndef __sweep_h_ +#define __sweep_h_ + +#include "mesh.h" + +/* __gl_computeInterior( tess ) computes the planar arrangement specified + * by the given contours, and further subdivides this arrangement + * into regions. Each region is marked "inside" if it belongs + * to the polygon, according to the rule given by tess->windingRule. + * Each interior region is guaranteed be monotone. + */ +int __gl_computeInterior( GLUtesselator *tess ); + + +/* The following is here *only* for access by debugging routines */ + +#include "dict.h" + +/* For each pair of adjacent edges crossing the sweep line, there is + * an ActiveRegion to represent the region between them. The active + * regions are kept in sorted order in a dynamic dictionary. As the + * sweep line crosses each vertex, we update the affected regions. + */ + +struct ActiveRegion { + GLUhalfEdge *eUp; /* upper edge, directed right to left */ + DictNode *nodeUp; /* dictionary node corresponding to eUp */ + int windingNumber; /* used to determine which regions are + * inside the polygon */ + GLboolean inside; /* is this region inside the polygon? */ + GLboolean sentinel; /* marks fake edges at t = +/-infinity */ + GLboolean dirty; /* marks regions where the upper or lower + * edge has changed, but we haven't checked + * whether they intersect yet */ + GLboolean fixUpperEdge; /* marks temporary edges introduced when + * we process a "right vertex" (one without + * any edges leaving to the right) */ +}; + +#define RegionBelow(r) ((ActiveRegion *) dictKey(dictPred((r)->nodeUp))) +#define RegionAbove(r) ((ActiveRegion *) dictKey(dictSucc((r)->nodeUp))) + +#endif diff --git a/src/glu/sgi/libtess/tess.c b/src/glu/sgi/libtess/tess.c new file mode 100644 index 0000000..4a0e8de --- /dev/null +++ b/src/glu/sgi/libtess/tess.c @@ -0,0 +1,632 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#include "gluos.h" +#include +#include +#include +#include "memalloc.h" +#include "tess.h" +#include "mesh.h" +#include "normal.h" +#include "sweep.h" +#include "tessmono.h" +#include "render.h" + +#define GLU_TESS_DEFAULT_TOLERANCE 0.0 +#define GLU_TESS_MESH 100112 /* void (*)(GLUmesh *mesh) */ + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +/*ARGSUSED*/ static void GLAPIENTRY noBegin( GLenum type ) {} +/*ARGSUSED*/ static void GLAPIENTRY noEdgeFlag( GLboolean boundaryEdge ) {} +/*ARGSUSED*/ static void GLAPIENTRY noVertex( void *data ) {} +/*ARGSUSED*/ static void GLAPIENTRY noEnd( void ) {} +/*ARGSUSED*/ static void GLAPIENTRY noError( GLenum errnum ) {} +/*ARGSUSED*/ static void GLAPIENTRY noCombine( GLdouble coords[3], void *data[4], + GLfloat weight[4], void **dataOut ) {} +/*ARGSUSED*/ static void GLAPIENTRY noMesh( GLUmesh *mesh ) {} + + +/*ARGSUSED*/ void GLAPIENTRY __gl_noBeginData( GLenum type, + void *polygonData ) {} +/*ARGSUSED*/ void GLAPIENTRY __gl_noEdgeFlagData( GLboolean boundaryEdge, + void *polygonData ) {} +/*ARGSUSED*/ void GLAPIENTRY __gl_noVertexData( void *data, + void *polygonData ) {} +/*ARGSUSED*/ void GLAPIENTRY __gl_noEndData( void *polygonData ) {} +/*ARGSUSED*/ void GLAPIENTRY __gl_noErrorData( GLenum errnum, + void *polygonData ) {} +/*ARGSUSED*/ void GLAPIENTRY __gl_noCombineData( GLdouble coords[3], + void *data[4], + GLfloat weight[4], + void **outData, + void *polygonData ) {} + +/* Half-edges are allocated in pairs (see mesh.c) */ +typedef struct { GLUhalfEdge e, eSym; } EdgePair; + +#undef MAX +#define MAX(a,b) ((a) > (b) ? (a) : (b)) +#define MAX_FAST_ALLOC (MAX(sizeof(EdgePair), \ + MAX(sizeof(GLUvertex),sizeof(GLUface)))) + + +GLUtesselator * GLAPIENTRY +gluNewTess( void ) +{ + GLUtesselator *tess; + + /* Only initialize fields which can be changed by the api. Other fields + * are initialized where they are used. + */ + + if (memInit( MAX_FAST_ALLOC ) == 0) { + return 0; /* out of memory */ + } + tess = (GLUtesselator *)memAlloc( sizeof( GLUtesselator )); + if (tess == NULL) { + return 0; /* out of memory */ + } + + tess->state = T_DORMANT; + + tess->normal[0] = 0; + tess->normal[1] = 0; + tess->normal[2] = 0; + + tess->relTolerance = GLU_TESS_DEFAULT_TOLERANCE; + tess->windingRule = GLU_TESS_WINDING_ODD; + tess->flagBoundary = FALSE; + tess->boundaryOnly = FALSE; + + tess->callBegin = &noBegin; + tess->callEdgeFlag = &noEdgeFlag; + tess->callVertex = &noVertex; + tess->callEnd = &noEnd; + + tess->callError = &noError; + tess->callCombine = &noCombine; + tess->callMesh = &noMesh; + + tess->callBeginData= &__gl_noBeginData; + tess->callEdgeFlagData= &__gl_noEdgeFlagData; + tess->callVertexData= &__gl_noVertexData; + tess->callEndData= &__gl_noEndData; + tess->callErrorData= &__gl_noErrorData; + tess->callCombineData= &__gl_noCombineData; + + tess->polygonData= NULL; + + return tess; +} + +static void MakeDormant( GLUtesselator *tess ) +{ + /* Return the tessellator to its original dormant state. */ + + if( tess->mesh != NULL ) { + __gl_meshDeleteMesh( tess->mesh ); + } + tess->state = T_DORMANT; + tess->lastEdge = NULL; + tess->mesh = NULL; +} + +#define RequireState( tess, s ) if( tess->state != s ) GotoState(tess,s) + +static void GotoState( GLUtesselator *tess, enum TessState newState ) +{ + while( tess->state != newState ) { + /* We change the current state one level at a time, to get to + * the desired state. + */ + if( tess->state < newState ) { + switch( tess->state ) { + case T_DORMANT: + CALL_ERROR_OR_ERROR_DATA( GLU_TESS_MISSING_BEGIN_POLYGON ); + gluTessBeginPolygon( tess, NULL ); + break; + case T_IN_POLYGON: + CALL_ERROR_OR_ERROR_DATA( GLU_TESS_MISSING_BEGIN_CONTOUR ); + gluTessBeginContour( tess ); + break; + default: + ; + } + } else { + switch( tess->state ) { + case T_IN_CONTOUR: + CALL_ERROR_OR_ERROR_DATA( GLU_TESS_MISSING_END_CONTOUR ); + gluTessEndContour( tess ); + break; + case T_IN_POLYGON: + CALL_ERROR_OR_ERROR_DATA( GLU_TESS_MISSING_END_POLYGON ); + /* gluTessEndPolygon( tess ) is too much work! */ + MakeDormant( tess ); + break; + default: + ; + } + } + } +} + + +void GLAPIENTRY +gluDeleteTess( GLUtesselator *tess ) +{ + RequireState( tess, T_DORMANT ); + memFree( tess ); +} + + +void GLAPIENTRY +gluTessProperty( GLUtesselator *tess, GLenum which, GLdouble value ) +{ + GLenum windingRule; + + switch( which ) { + case GLU_TESS_TOLERANCE: + if( value < 0.0 || value > 1.0 ) break; + tess->relTolerance = value; + return; + + case GLU_TESS_WINDING_RULE: + windingRule = (GLenum) value; + if( windingRule != value ) break; /* not an integer */ + + switch( windingRule ) { + case GLU_TESS_WINDING_ODD: + case GLU_TESS_WINDING_NONZERO: + case GLU_TESS_WINDING_POSITIVE: + case GLU_TESS_WINDING_NEGATIVE: + case GLU_TESS_WINDING_ABS_GEQ_TWO: + tess->windingRule = windingRule; + return; + default: + break; + } + + case GLU_TESS_BOUNDARY_ONLY: + tess->boundaryOnly = (value != 0); + return; + + default: + CALL_ERROR_OR_ERROR_DATA( GLU_INVALID_ENUM ); + return; + } + CALL_ERROR_OR_ERROR_DATA( GLU_INVALID_VALUE ); +} + +/* Returns tessellator property */ +void GLAPIENTRY +gluGetTessProperty( GLUtesselator *tess, GLenum which, GLdouble *value ) +{ + switch (which) { + case GLU_TESS_TOLERANCE: + /* tolerance should be in range [0..1] */ + assert(0.0 <= tess->relTolerance && tess->relTolerance <= 1.0); + *value= tess->relTolerance; + break; + case GLU_TESS_WINDING_RULE: + assert(tess->windingRule == GLU_TESS_WINDING_ODD || + tess->windingRule == GLU_TESS_WINDING_NONZERO || + tess->windingRule == GLU_TESS_WINDING_POSITIVE || + tess->windingRule == GLU_TESS_WINDING_NEGATIVE || + tess->windingRule == GLU_TESS_WINDING_ABS_GEQ_TWO); + *value= tess->windingRule; + break; + case GLU_TESS_BOUNDARY_ONLY: + assert(tess->boundaryOnly == TRUE || tess->boundaryOnly == FALSE); + *value= tess->boundaryOnly; + break; + default: + *value= 0.0; + CALL_ERROR_OR_ERROR_DATA( GLU_INVALID_ENUM ); + break; + } +} /* gluGetTessProperty() */ + +void GLAPIENTRY +gluTessNormal( GLUtesselator *tess, GLdouble x, GLdouble y, GLdouble z ) +{ + tess->normal[0] = x; + tess->normal[1] = y; + tess->normal[2] = z; +} + +void GLAPIENTRY +gluTessCallback( GLUtesselator *tess, GLenum which, _GLUfuncptr fn) +{ + switch( which ) { + case GLU_TESS_BEGIN: + tess->callBegin = (fn == NULL) ? &noBegin : (void (GLAPIENTRY *)(GLenum)) fn; + return; + case GLU_TESS_BEGIN_DATA: + tess->callBeginData = (fn == NULL) ? + &__gl_noBeginData : (void (GLAPIENTRY *)(GLenum, void *)) fn; + return; + case GLU_TESS_EDGE_FLAG: + tess->callEdgeFlag = (fn == NULL) ? &noEdgeFlag : + (void (GLAPIENTRY *)(GLboolean)) fn; + /* If the client wants boundary edges to be flagged, + * we render everything as separate triangles (no strips or fans). + */ + tess->flagBoundary = (fn != NULL); + return; + case GLU_TESS_EDGE_FLAG_DATA: + tess->callEdgeFlagData= (fn == NULL) ? + &__gl_noEdgeFlagData : (void (GLAPIENTRY *)(GLboolean, void *)) fn; + /* If the client wants boundary edges to be flagged, + * we render everything as separate triangles (no strips or fans). + */ + tess->flagBoundary = (fn != NULL); + return; + case GLU_TESS_VERTEX: + tess->callVertex = (fn == NULL) ? &noVertex : + (void (GLAPIENTRY *)(void *)) fn; + return; + case GLU_TESS_VERTEX_DATA: + tess->callVertexData = (fn == NULL) ? + &__gl_noVertexData : (void (GLAPIENTRY *)(void *, void *)) fn; + return; + case GLU_TESS_END: + tess->callEnd = (fn == NULL) ? &noEnd : (void (GLAPIENTRY *)(void)) fn; + return; + case GLU_TESS_END_DATA: + tess->callEndData = (fn == NULL) ? &__gl_noEndData : + (void (GLAPIENTRY *)(void *)) fn; + return; + case GLU_TESS_ERROR: + tess->callError = (fn == NULL) ? &noError : (void (GLAPIENTRY *)(GLenum)) fn; + return; + case GLU_TESS_ERROR_DATA: + tess->callErrorData = (fn == NULL) ? + &__gl_noErrorData : (void (GLAPIENTRY *)(GLenum, void *)) fn; + return; + case GLU_TESS_COMBINE: + tess->callCombine = (fn == NULL) ? &noCombine : + (void (GLAPIENTRY *)(GLdouble [3],void *[4], GLfloat [4], void ** )) fn; + return; + case GLU_TESS_COMBINE_DATA: + tess->callCombineData = (fn == NULL) ? &__gl_noCombineData : + (void (GLAPIENTRY *)(GLdouble [3], + void *[4], + GLfloat [4], + void **, + void *)) fn; + return; + case GLU_TESS_MESH: + tess->callMesh = (fn == NULL) ? &noMesh : (void (GLAPIENTRY *)(GLUmesh *)) fn; + return; + default: + CALL_ERROR_OR_ERROR_DATA( GLU_INVALID_ENUM ); + return; + } +} + +static int AddVertex( GLUtesselator *tess, GLdouble coords[3], void *data ) +{ + GLUhalfEdge *e; + + e = tess->lastEdge; + if( e == NULL ) { + /* Make a self-loop (one vertex, one edge). */ + + e = __gl_meshMakeEdge( tess->mesh ); + if (e == NULL) return 0; + if ( !__gl_meshSplice( e, e->Sym ) ) return 0; + } else { + /* Create a new vertex and edge which immediately follow e + * in the ordering around the left face. + */ + if (__gl_meshSplitEdge( e ) == NULL) return 0; + e = e->Lnext; + } + + /* The new vertex is now e->Org. */ + e->Org->data = data; + e->Org->coords[0] = coords[0]; + e->Org->coords[1] = coords[1]; + e->Org->coords[2] = coords[2]; + + /* The winding of an edge says how the winding number changes as we + * cross from the edge''s right face to its left face. We add the + * vertices in such an order that a CCW contour will add +1 to + * the winding number of the region inside the contour. + */ + e->winding = 1; + e->Sym->winding = -1; + + tess->lastEdge = e; + + return 1; +} + + +static void CacheVertex( GLUtesselator *tess, GLdouble coords[3], void *data ) +{ + CachedVertex *v = &tess->cache[tess->cacheCount]; + + v->data = data; + v->coords[0] = coords[0]; + v->coords[1] = coords[1]; + v->coords[2] = coords[2]; + ++tess->cacheCount; +} + + +static int EmptyCache( GLUtesselator *tess ) +{ + CachedVertex *v = tess->cache; + CachedVertex *vLast; + + tess->mesh = __gl_meshNewMesh(); + if (tess->mesh == NULL) return 0; + + for( vLast = v + tess->cacheCount; v < vLast; ++v ) { + if ( !AddVertex( tess, v->coords, v->data ) ) return 0; + } + tess->cacheCount = 0; + tess->emptyCache = FALSE; + + return 1; +} + + +void GLAPIENTRY +gluTessVertex( GLUtesselator *tess, GLdouble coords[3], void *data ) +{ + int i, tooLarge = FALSE; + GLdouble x, clamped[3]; + + RequireState( tess, T_IN_CONTOUR ); + + if( tess->emptyCache ) { + if ( !EmptyCache( tess ) ) { + CALL_ERROR_OR_ERROR_DATA( GLU_OUT_OF_MEMORY ); + return; + } + tess->lastEdge = NULL; + } + for( i = 0; i < 3; ++i ) { + x = coords[i]; + if( x < - GLU_TESS_MAX_COORD ) { + x = - GLU_TESS_MAX_COORD; + tooLarge = TRUE; + } + if( x > GLU_TESS_MAX_COORD ) { + x = GLU_TESS_MAX_COORD; + tooLarge = TRUE; + } + clamped[i] = x; + } + if( tooLarge ) { + CALL_ERROR_OR_ERROR_DATA( GLU_TESS_COORD_TOO_LARGE ); + } + + if( tess->mesh == NULL ) { + if( tess->cacheCount < TESS_MAX_CACHE ) { + CacheVertex( tess, clamped, data ); + return; + } + if ( !EmptyCache( tess ) ) { + CALL_ERROR_OR_ERROR_DATA( GLU_OUT_OF_MEMORY ); + return; + } + } + if ( !AddVertex( tess, clamped, data ) ) { + CALL_ERROR_OR_ERROR_DATA( GLU_OUT_OF_MEMORY ); + } +} + + +void GLAPIENTRY +gluTessBeginPolygon( GLUtesselator *tess, void *data ) +{ + RequireState( tess, T_DORMANT ); + + tess->state = T_IN_POLYGON; + tess->cacheCount = 0; + tess->emptyCache = FALSE; + tess->mesh = NULL; + + tess->polygonData= data; +} + + +void GLAPIENTRY +gluTessBeginContour( GLUtesselator *tess ) +{ + RequireState( tess, T_IN_POLYGON ); + + tess->state = T_IN_CONTOUR; + tess->lastEdge = NULL; + if( tess->cacheCount > 0 ) { + /* Just set a flag so we don't get confused by empty contours + * -- these can be generated accidentally with the obsolete + * NextContour() interface. + */ + tess->emptyCache = TRUE; + } +} + + +void GLAPIENTRY +gluTessEndContour( GLUtesselator *tess ) +{ + RequireState( tess, T_IN_CONTOUR ); + tess->state = T_IN_POLYGON; +} + +void GLAPIENTRY +gluTessEndPolygon( GLUtesselator *tess ) +{ + GLUmesh *mesh; + + if (setjmp(tess->env) != 0) { + /* come back here if out of memory */ + CALL_ERROR_OR_ERROR_DATA( GLU_OUT_OF_MEMORY ); + return; + } + + RequireState( tess, T_IN_POLYGON ); + tess->state = T_DORMANT; + + if( tess->mesh == NULL ) { + if( ! tess->flagBoundary && tess->callMesh == &noMesh ) { + + /* Try some special code to make the easy cases go quickly + * (eg. convex polygons). This code does NOT handle multiple contours, + * intersections, edge flags, and of course it does not generate + * an explicit mesh either. + */ + if( __gl_renderCache( tess )) { + tess->polygonData= NULL; + return; + } + } + if ( !EmptyCache( tess ) ) longjmp(tess->env,1); /* could've used a label*/ + } + + /* Determine the polygon normal and project vertices onto the plane + * of the polygon. + */ + __gl_projectPolygon( tess ); + + /* __gl_computeInterior( tess ) computes the planar arrangement specified + * by the given contours, and further subdivides this arrangement + * into regions. Each region is marked "inside" if it belongs + * to the polygon, according to the rule given by tess->windingRule. + * Each interior region is guaranteed be monotone. + */ + if ( !__gl_computeInterior( tess ) ) { + longjmp(tess->env,1); /* could've used a label */ + } + + mesh = tess->mesh; + if( ! tess->fatalError ) { + int rc = 1; + + /* If the user wants only the boundary contours, we throw away all edges + * except those which separate the interior from the exterior. + * Otherwise we tessellate all the regions marked "inside". + */ + if( tess->boundaryOnly ) { + rc = __gl_meshSetWindingNumber( mesh, 1, TRUE ); + } else { + rc = __gl_meshTessellateInterior( mesh ); + } + if (rc == 0) longjmp(tess->env,1); /* could've used a label */ + + __gl_meshCheckMesh( mesh ); + + if( tess->callBegin != &noBegin || tess->callEnd != &noEnd + || tess->callVertex != &noVertex || tess->callEdgeFlag != &noEdgeFlag + || tess->callBeginData != &__gl_noBeginData + || tess->callEndData != &__gl_noEndData + || tess->callVertexData != &__gl_noVertexData + || tess->callEdgeFlagData != &__gl_noEdgeFlagData ) + { + if( tess->boundaryOnly ) { + __gl_renderBoundary( tess, mesh ); /* output boundary contours */ + } else { + __gl_renderMesh( tess, mesh ); /* output strips and fans */ + } + } + if( tess->callMesh != &noMesh ) { + + /* Throw away the exterior faces, so that all faces are interior. + * This way the user doesn't have to check the "inside" flag, + * and we don't need to even reveal its existence. It also leaves + * the freedom for an implementation to not generate the exterior + * faces in the first place. + */ + __gl_meshDiscardExterior( mesh ); + (*tess->callMesh)( mesh ); /* user wants the mesh itself */ + tess->mesh = NULL; + tess->polygonData= NULL; + return; + } + } + __gl_meshDeleteMesh( mesh ); + tess->polygonData= NULL; + tess->mesh = NULL; +} + + +/*XXXblythe unused function*/ +#if 0 +void GLAPIENTRY +gluDeleteMesh( GLUmesh *mesh ) +{ + __gl_meshDeleteMesh( mesh ); +} +#endif + + + +/*******************************************************/ + +/* Obsolete calls -- for backward compatibility */ + +void GLAPIENTRY +gluBeginPolygon( GLUtesselator *tess ) +{ + gluTessBeginPolygon( tess, NULL ); + gluTessBeginContour( tess ); +} + + +/*ARGSUSED*/ +void GLAPIENTRY +gluNextContour( GLUtesselator *tess, GLenum type ) +{ + gluTessEndContour( tess ); + gluTessBeginContour( tess ); +} + + +void GLAPIENTRY +gluEndPolygon( GLUtesselator *tess ) +{ + gluTessEndContour( tess ); + gluTessEndPolygon( tess ); +} diff --git a/src/glu/sgi/libtess/tess.h b/src/glu/sgi/libtess/tess.h new file mode 100644 index 0000000..1624960 --- /dev/null +++ b/src/glu/sgi/libtess/tess.h @@ -0,0 +1,165 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#ifndef __tess_h_ +#define __tess_h_ + +#include +#include +#include "mesh.h" +#include "dict.h" +#include "priorityq.h" + +/* The begin/end calls must be properly nested. We keep track of + * the current state to enforce the ordering. + */ +enum TessState { T_DORMANT, T_IN_POLYGON, T_IN_CONTOUR }; + +/* We cache vertex data for single-contour polygons so that we can + * try a quick-and-dirty decomposition first. + */ +#define TESS_MAX_CACHE 100 + +typedef struct CachedVertex { + GLdouble coords[3]; + void *data; +} CachedVertex; + +struct GLUtesselator { + + /*** state needed for collecting the input data ***/ + + enum TessState state; /* what begin/end calls have we seen? */ + + GLUhalfEdge *lastEdge; /* lastEdge->Org is the most recent vertex */ + GLUmesh *mesh; /* stores the input contours, and eventually + the tessellation itself */ + + void (GLAPIENTRY *callError)( GLenum errnum ); + + /*** state needed for projecting onto the sweep plane ***/ + + GLdouble normal[3]; /* user-specified normal (if provided) */ + GLdouble sUnit[3]; /* unit vector in s-direction (debugging) */ + GLdouble tUnit[3]; /* unit vector in t-direction (debugging) */ + + /*** state needed for the line sweep ***/ + + GLdouble relTolerance; /* tolerance for merging features */ + GLenum windingRule; /* rule for determining polygon interior */ + GLboolean fatalError; /* fatal error: needed combine callback */ + + Dict *dict; /* edge dictionary for sweep line */ + PriorityQ *pq; /* priority queue of vertex events */ + GLUvertex *event; /* current sweep event being processed */ + + void (GLAPIENTRY *callCombine)( GLdouble coords[3], void *data[4], + GLfloat weight[4], void **outData ); + + /*** state needed for rendering callbacks (see render.c) ***/ + + GLboolean flagBoundary; /* mark boundary edges (use EdgeFlag) */ + GLboolean boundaryOnly; /* Extract contours, not triangles */ + GLUface *lonelyTriList; + /* list of triangles which could not be rendered as strips or fans */ + + void (GLAPIENTRY *callBegin)( GLenum type ); + void (GLAPIENTRY *callEdgeFlag)( GLboolean boundaryEdge ); + void (GLAPIENTRY *callVertex)( void *data ); + void (GLAPIENTRY *callEnd)( void ); + void (GLAPIENTRY *callMesh)( GLUmesh *mesh ); + + + /*** state needed to cache single-contour polygons for renderCache() */ + + GLboolean emptyCache; /* empty cache on next vertex() call */ + int cacheCount; /* number of cached vertices */ + CachedVertex cache[TESS_MAX_CACHE]; /* the vertex data */ + + /*** rendering callbacks that also pass polygon data ***/ + void (GLAPIENTRY *callBeginData)( GLenum type, void *polygonData ); + void (GLAPIENTRY *callEdgeFlagData)( GLboolean boundaryEdge, + void *polygonData ); + void (GLAPIENTRY *callVertexData)( void *data, void *polygonData ); + void (GLAPIENTRY *callEndData)( void *polygonData ); + void (GLAPIENTRY *callErrorData)( GLenum errnum, void *polygonData ); + void (GLAPIENTRY *callCombineData)( GLdouble coords[3], void *data[4], + GLfloat weight[4], void **outData, + void *polygonData ); + + jmp_buf env; /* place to jump to when memAllocs fail */ + + void *polygonData; /* client data for current polygon */ +}; + +void GLAPIENTRY __gl_noBeginData( GLenum type, void *polygonData ); +void GLAPIENTRY __gl_noEdgeFlagData( GLboolean boundaryEdge, void *polygonData ); +void GLAPIENTRY __gl_noVertexData( void *data, void *polygonData ); +void GLAPIENTRY __gl_noEndData( void *polygonData ); +void GLAPIENTRY __gl_noErrorData( GLenum errnum, void *polygonData ); +void GLAPIENTRY __gl_noCombineData( GLdouble coords[3], void *data[4], + GLfloat weight[4], void **outData, + void *polygonData ); + +#define CALL_BEGIN_OR_BEGIN_DATA(a) \ + if (tess->callBeginData != &__gl_noBeginData) \ + (*tess->callBeginData)((a),tess->polygonData); \ + else (*tess->callBegin)((a)); + +#define CALL_VERTEX_OR_VERTEX_DATA(a) \ + if (tess->callVertexData != &__gl_noVertexData) \ + (*tess->callVertexData)((a),tess->polygonData); \ + else (*tess->callVertex)((a)); + +#define CALL_EDGE_FLAG_OR_EDGE_FLAG_DATA(a) \ + if (tess->callEdgeFlagData != &__gl_noEdgeFlagData) \ + (*tess->callEdgeFlagData)((a),tess->polygonData); \ + else (*tess->callEdgeFlag)((a)); + +#define CALL_END_OR_END_DATA() \ + if (tess->callEndData != &__gl_noEndData) \ + (*tess->callEndData)(tess->polygonData); \ + else (*tess->callEnd)(); + +#define CALL_COMBINE_OR_COMBINE_DATA(a,b,c,d) \ + if (tess->callCombineData != &__gl_noCombineData) \ + (*tess->callCombineData)((a),(b),(c),(d),tess->polygonData); \ + else (*tess->callCombine)((a),(b),(c),(d)); + +#define CALL_ERROR_OR_ERROR_DATA(a) \ + if (tess->callErrorData != &__gl_noErrorData) \ + (*tess->callErrorData)((a),tess->polygonData); \ + else (*tess->callError)((a)); + +#endif diff --git a/src/glu/sgi/libtess/tessmono.c b/src/glu/sgi/libtess/tessmono.c new file mode 100644 index 0000000..4d08440 --- /dev/null +++ b/src/glu/sgi/libtess/tessmono.c @@ -0,0 +1,201 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#include "gluos.h" +#include +#include "geom.h" +#include "mesh.h" +#include "tessmono.h" +#include + +#define AddWinding(eDst,eSrc) (eDst->winding += eSrc->winding, \ + eDst->Sym->winding += eSrc->Sym->winding) + +/* __gl_meshTessellateMonoRegion( face ) tessellates a monotone region + * (what else would it do??) The region must consist of a single + * loop of half-edges (see mesh.h) oriented CCW. "Monotone" in this + * case means that any vertical line intersects the interior of the + * region in a single interval. + * + * Tessellation consists of adding interior edges (actually pairs of + * half-edges), to split the region into non-overlapping triangles. + * + * The basic idea is explained in Preparata and Shamos (which I don''t + * have handy right now), although their implementation is more + * complicated than this one. The are two edge chains, an upper chain + * and a lower chain. We process all vertices from both chains in order, + * from right to left. + * + * The algorithm ensures that the following invariant holds after each + * vertex is processed: the untessellated region consists of two + * chains, where one chain (say the upper) is a single edge, and + * the other chain is concave. The left vertex of the single edge + * is always to the left of all vertices in the concave chain. + * + * Each step consists of adding the rightmost unprocessed vertex to one + * of the two chains, and forming a fan of triangles from the rightmost + * of two chain endpoints. Determining whether we can add each triangle + * to the fan is a simple orientation test. By making the fan as large + * as possible, we restore the invariant (check it yourself). + */ +int __gl_meshTessellateMonoRegion( GLUface *face ) +{ + GLUhalfEdge *up, *lo; + + /* All edges are oriented CCW around the boundary of the region. + * First, find the half-edge whose origin vertex is rightmost. + * Since the sweep goes from left to right, face->anEdge should + * be close to the edge we want. + */ + up = face->anEdge; + assert( up->Lnext != up && up->Lnext->Lnext != up ); + + for( ; VertLeq( up->Dst, up->Org ); up = up->Lprev ) + ; + for( ; VertLeq( up->Org, up->Dst ); up = up->Lnext ) + ; + lo = up->Lprev; + + while( up->Lnext != lo ) { + if( VertLeq( up->Dst, lo->Org )) { + /* up->Dst is on the left. It is safe to form triangles from lo->Org. + * The EdgeGoesLeft test guarantees progress even when some triangles + * are CW, given that the upper and lower chains are truly monotone. + */ + while( lo->Lnext != up && (EdgeGoesLeft( lo->Lnext ) + || EdgeSign( lo->Org, lo->Dst, lo->Lnext->Dst ) <= 0 )) { + GLUhalfEdge *tempHalfEdge= __gl_meshConnect( lo->Lnext, lo ); + if (tempHalfEdge == NULL) return 0; + lo = tempHalfEdge->Sym; + } + lo = lo->Lprev; + } else { + /* lo->Org is on the left. We can make CCW triangles from up->Dst. */ + while( lo->Lnext != up && (EdgeGoesRight( up->Lprev ) + || EdgeSign( up->Dst, up->Org, up->Lprev->Org ) >= 0 )) { + GLUhalfEdge *tempHalfEdge= __gl_meshConnect( up, up->Lprev ); + if (tempHalfEdge == NULL) return 0; + up = tempHalfEdge->Sym; + } + up = up->Lnext; + } + } + + /* Now lo->Org == up->Dst == the leftmost vertex. The remaining region + * can be tessellated in a fan from this leftmost vertex. + */ + assert( lo->Lnext != up ); + while( lo->Lnext->Lnext != up ) { + GLUhalfEdge *tempHalfEdge= __gl_meshConnect( lo->Lnext, lo ); + if (tempHalfEdge == NULL) return 0; + lo = tempHalfEdge->Sym; + } + + return 1; +} + + +/* __gl_meshTessellateInterior( mesh ) tessellates each region of + * the mesh which is marked "inside" the polygon. Each such region + * must be monotone. + */ +int __gl_meshTessellateInterior( GLUmesh *mesh ) +{ + GLUface *f, *next; + + /*LINTED*/ + for( f = mesh->fHead.next; f != &mesh->fHead; f = next ) { + /* Make sure we don''t try to tessellate the new triangles. */ + next = f->next; + if( f->inside ) { + if ( !__gl_meshTessellateMonoRegion( f ) ) return 0; + } + } + + return 1; +} + + +/* __gl_meshDiscardExterior( mesh ) zaps (ie. sets to NULL) all faces + * which are not marked "inside" the polygon. Since further mesh operations + * on NULL faces are not allowed, the main purpose is to clean up the + * mesh so that exterior loops are not represented in the data structure. + */ +void __gl_meshDiscardExterior( GLUmesh *mesh ) +{ + GLUface *f, *next; + + /*LINTED*/ + for( f = mesh->fHead.next; f != &mesh->fHead; f = next ) { + /* Since f will be destroyed, save its next pointer. */ + next = f->next; + if( ! f->inside ) { + __gl_meshZapFace( f ); + } + } +} + +#define MARKED_FOR_DELETION 0x7fffffff + +/* __gl_meshSetWindingNumber( mesh, value, keepOnlyBoundary ) resets the + * winding numbers on all edges so that regions marked "inside" the + * polygon have a winding number of "value", and regions outside + * have a winding number of 0. + * + * If keepOnlyBoundary is TRUE, it also deletes all edges which do not + * separate an interior region from an exterior one. + */ +int __gl_meshSetWindingNumber( GLUmesh *mesh, int value, + GLboolean keepOnlyBoundary ) +{ + GLUhalfEdge *e, *eNext; + + for( e = mesh->eHead.next; e != &mesh->eHead; e = eNext ) { + eNext = e->next; + if( e->Rface->inside != e->Lface->inside ) { + + /* This is a boundary edge (one side is interior, one is exterior). */ + e->winding = (e->Lface->inside) ? value : -value; + } else { + + /* Both regions are interior, or both are exterior. */ + if( ! keepOnlyBoundary ) { + e->winding = 0; + } else { + if ( !__gl_meshDelete( e ) ) return 0; + } + } + } + return 1; +} diff --git a/src/glu/sgi/libtess/tessmono.h b/src/glu/sgi/libtess/tessmono.h new file mode 100644 index 0000000..8ee1b2f --- /dev/null +++ b/src/glu/sgi/libtess/tessmono.h @@ -0,0 +1,71 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ +/* +** Author: Eric Veach, July 1994. +** +*/ + +#ifndef __tessmono_h_ +#define __tessmono_h_ + +/* __gl_meshTessellateMonoRegion( face ) tessellates a monotone region + * (what else would it do??) The region must consist of a single + * loop of half-edges (see mesh.h) oriented CCW. "Monotone" in this + * case means that any vertical line intersects the interior of the + * region in a single interval. + * + * Tessellation consists of adding interior edges (actually pairs of + * half-edges), to split the region into non-overlapping triangles. + * + * __gl_meshTessellateInterior( mesh ) tessellates each region of + * the mesh which is marked "inside" the polygon. Each such region + * must be monotone. + * + * __gl_meshDiscardExterior( mesh ) zaps (ie. sets to NULL) all faces + * which are not marked "inside" the polygon. Since further mesh operations + * on NULL faces are not allowed, the main purpose is to clean up the + * mesh so that exterior loops are not represented in the data structure. + * + * __gl_meshSetWindingNumber( mesh, value, keepOnlyBoundary ) resets the + * winding numbers on all edges so that regions marked "inside" the + * polygon have a winding number of "value", and regions outside + * have a winding number of 0. + * + * If keepOnlyBoundary is TRUE, it also deletes all edges which do not + * separate an interior region from an exterior one. + */ + +int __gl_meshTessellateMonoRegion( GLUface *face ); +int __gl_meshTessellateInterior( GLUmesh *mesh ); +void __gl_meshDiscardExterior( GLUmesh *mesh ); +int __gl_meshSetWindingNumber( GLUmesh *mesh, int value, + GLboolean keepOnlyBoundary ); + +#endif diff --git a/src/glu/sgi/libutil/error.c b/src/glu/sgi/libutil/error.c new file mode 100644 index 0000000..7212748 --- /dev/null +++ b/src/glu/sgi/libutil/error.c @@ -0,0 +1,81 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "gluos.h" +#include "gluint.h" +#include + + +struct token_string +{ + GLuint Token; + const char *String; +}; + +static const struct token_string Errors[] = { + { GL_NO_ERROR, "no error" }, + { GL_INVALID_ENUM, "invalid enumerant" }, + { GL_INVALID_VALUE, "invalid value" }, + { GL_INVALID_OPERATION, "invalid operation" }, + { GL_STACK_OVERFLOW, "stack overflow" }, + { GL_STACK_UNDERFLOW, "stack underflow" }, + { GL_OUT_OF_MEMORY, "out of memory" }, + { GL_TABLE_TOO_LARGE, "table too large" }, +#ifdef GL_EXT_framebuffer_object + { GL_INVALID_FRAMEBUFFER_OPERATION_EXT, "invalid framebuffer operation" }, +#endif + /* GLU */ + { GLU_INVALID_ENUM, "invalid enumerant" }, + { GLU_INVALID_VALUE, "invalid value" }, + { GLU_OUT_OF_MEMORY, "out of memory" }, + { GLU_INCOMPATIBLE_GL_VERSION, "incompatible gl version" }, + { GLU_INVALID_OPERATION, "invalid operation" }, + { ~0, NULL } /* end of list indicator */ +}; + + + +const GLubyte* GLAPIENTRY +gluErrorString(GLenum errorCode) +{ + int i; + for (i = 0; Errors[i].String; i++) { + if (Errors[i].Token == errorCode) + return (const GLubyte *) Errors[i].String; + } + if ((errorCode >= GLU_NURBS_ERROR1) && (errorCode <= GLU_NURBS_ERROR37)) { + return (const GLubyte *) __gluNURBSErrorString(errorCode - (GLU_NURBS_ERROR1 - 1)); + } + if ((errorCode >= GLU_TESS_ERROR1) && (errorCode <= GLU_TESS_ERROR6)) { + return (const GLubyte *) __gluTessErrorString(errorCode - (GLU_TESS_ERROR1 - 1)); + } + return (const GLubyte *) 0; +} + diff --git a/src/glu/sgi/libutil/glue.c b/src/glu/sgi/libutil/glue.c new file mode 100644 index 0000000..cd65d65 --- /dev/null +++ b/src/glu/sgi/libutil/glue.c @@ -0,0 +1,93 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include +#include "gluint.h" + +static unsigned char *__gluNurbsErrors[] = { + (unsigned char*) " ", + (unsigned char*) "spline order un-supported", + (unsigned char*) "too few knots", + (unsigned char*) "valid knot range is empty", + (unsigned char*) "decreasing knot sequence knot", + (unsigned char*) "knot multiplicity greater than order of spline", + (unsigned char*) "gluEndCurve() must follow gluBeginCurve()", + (unsigned char*) "gluBeginCurve() must precede gluEndCurve()", + (unsigned char*) "missing or extra geometric data", + (unsigned char*) "can't draw piecewise linear trimming curves", + (unsigned char*) "missing or extra domain data", + (unsigned char*) "missing or extra domain data", + (unsigned char*) "gluEndTrim() must precede gluEndSurface()", + (unsigned char*) "gluBeginSurface() must precede gluEndSurface()", + (unsigned char*) "curve of improper type passed as trim curve", + (unsigned char*) "gluBeginSurface() must precede gluBeginTrim()", + (unsigned char*) "gluEndTrim() must follow gluBeginTrim()", + (unsigned char*) "gluBeginTrim() must precede gluEndTrim()", + (unsigned char*) "invalid or missing trim curve", + (unsigned char*) "gluBeginTrim() must precede gluPwlCurve()", + (unsigned char*) "piecewise linear trimming curve referenced twice", + (unsigned char*) "piecewise linear trimming curve and nurbs curve mixed", + (unsigned char*) "improper usage of trim data type", + (unsigned char*) "nurbs curve referenced twice", + (unsigned char*) "nurbs curve and piecewise linear trimming curve mixed", + (unsigned char*) "nurbs surface referenced twice", + (unsigned char*) "invalid property", + (unsigned char*) "gluEndSurface() must follow gluBeginSurface()", + (unsigned char*) "intersecting or misoriented trim curves", + (unsigned char*) "intersecting trim curves", + (unsigned char*) "UNUSED", + (unsigned char*) "unconnected trim curves", + (unsigned char*) "unknown knot error", + (unsigned char*) "negative vertex count encountered", + (unsigned char*) "negative byte-stride encounteed", + (unsigned char*) "unknown type descriptor", + (unsigned char*) "null control point reference", + (unsigned char*) "duplicate point on piecewise linear trimming curve", +}; + +const unsigned char *__gluNURBSErrorString( int errnum ) +{ + return __gluNurbsErrors[errnum]; +} + +static unsigned char *__gluTessErrors[] = { + (unsigned char*) " ", + (unsigned char*) "gluTessBeginPolygon() must precede a gluTessEndPolygon()", + (unsigned char*) "gluTessBeginContour() must precede a gluTessEndContour()", + (unsigned char*) "gluTessEndPolygon() must follow a gluTessBeginPolygon()", + (unsigned char*) "gluTessEndContour() must follow a gluTessBeginContour()", + (unsigned char*) "a coordinate is too large", + (unsigned char*) "need combine callback", +}; + +const unsigned char *__gluTessErrorString( int errnum ) +{ + return __gluTessErrors[errnum]; +} /* __glTessErrorString() */ diff --git a/src/glu/sgi/libutil/gluint.h b/src/glu/sgi/libutil/gluint.h new file mode 100644 index 0000000..fd513ca --- /dev/null +++ b/src/glu/sgi/libutil/gluint.h @@ -0,0 +1,48 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#ifndef __gluint_h__ +#define __gluint_h__ + +extern const unsigned char *__gluNURBSErrorString( int errnum ); + +extern const unsigned char *__gluTessErrorString( int errnum ); + +#ifdef _EXTENSIONS_ +#define COS cosf +#define SIN sinf +#define SQRT sqrtf +#else +#define COS cos +#define SIN sin +#define SQRT sqrt +#endif + +#endif /* __gluint_h__ */ diff --git a/src/glu/sgi/libutil/mipmap.c b/src/glu/sgi/libutil/mipmap.c new file mode 100644 index 0000000..026ab84 --- /dev/null +++ b/src/glu/sgi/libutil/mipmap.c @@ -0,0 +1,8940 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "gluos.h" +#include +#include +#include +#include +#include +#include /* UINT_MAX */ +#include + +typedef union { + unsigned char ub[4]; + unsigned short us[2]; + unsigned int ui; + char b[4]; + short s[2]; + int i; + float f; +} Type_Widget; + +/* Pixel storage modes */ +typedef struct { + GLint pack_alignment; + GLint pack_row_length; + GLint pack_skip_rows; + GLint pack_skip_pixels; + GLint pack_lsb_first; + GLint pack_swap_bytes; + GLint pack_skip_images; + GLint pack_image_height; + + GLint unpack_alignment; + GLint unpack_row_length; + GLint unpack_skip_rows; + GLint unpack_skip_pixels; + GLint unpack_lsb_first; + GLint unpack_swap_bytes; + GLint unpack_skip_images; + GLint unpack_image_height; +} PixelStorageModes; + +static int gluBuild1DMipmapLevelsCore(GLenum, GLint, + GLsizei, + GLsizei, + GLenum, GLenum, GLint, GLint, GLint, + const void *); +static int gluBuild2DMipmapLevelsCore(GLenum, GLint, + GLsizei, GLsizei, + GLsizei, GLsizei, + GLenum, GLenum, GLint, GLint, GLint, + const void *); +static int gluBuild3DMipmapLevelsCore(GLenum, GLint, + GLsizei, GLsizei, GLsizei, + GLsizei, GLsizei, GLsizei, + GLenum, GLenum, GLint, GLint, GLint, + const void *); + +/* + * internal function declarations + */ +static GLfloat bytes_per_element(GLenum type); +static GLint elements_per_group(GLenum format, GLenum type); +static GLint is_index(GLenum format); +static GLint image_size(GLint width, GLint height, GLenum format, GLenum type); +static void fill_image(const PixelStorageModes *, + GLint width, GLint height, GLenum format, + GLenum type, GLboolean index_format, + const void *userdata, GLushort *newimage); +static void empty_image(const PixelStorageModes *, + GLint width, GLint height, GLenum format, + GLenum type, GLboolean index_format, + const GLushort *oldimage, void *userdata); +static void scale_internal(GLint components, GLint widthin, GLint heightin, + const GLushort *datain, + GLint widthout, GLint heightout, + GLushort *dataout); + +static void scale_internal_ubyte(GLint components, GLint widthin, + GLint heightin, const GLubyte *datain, + GLint widthout, GLint heightout, + GLubyte *dataout, GLint element_size, + GLint ysize, GLint group_size); +static void scale_internal_byte(GLint components, GLint widthin, + GLint heightin, const GLbyte *datain, + GLint widthout, GLint heightout, + GLbyte *dataout, GLint element_size, + GLint ysize, GLint group_size); +static void scale_internal_ushort(GLint components, GLint widthin, + GLint heightin, const GLushort *datain, + GLint widthout, GLint heightout, + GLushort *dataout, GLint element_size, + GLint ysize, GLint group_size, + GLint myswap_bytes); +static void scale_internal_short(GLint components, GLint widthin, + GLint heightin, const GLshort *datain, + GLint widthout, GLint heightout, + GLshort *dataout, GLint element_size, + GLint ysize, GLint group_size, + GLint myswap_bytes); +static void scale_internal_uint(GLint components, GLint widthin, + GLint heightin, const GLuint *datain, + GLint widthout, GLint heightout, + GLuint *dataout, GLint element_size, + GLint ysize, GLint group_size, + GLint myswap_bytes); +static void scale_internal_int(GLint components, GLint widthin, + GLint heightin, const GLint *datain, + GLint widthout, GLint heightout, + GLint *dataout, GLint element_size, + GLint ysize, GLint group_size, + GLint myswap_bytes); +static void scale_internal_float(GLint components, GLint widthin, + GLint heightin, const GLfloat *datain, + GLint widthout, GLint heightout, + GLfloat *dataout, GLint element_size, + GLint ysize, GLint group_size, + GLint myswap_bytes); + +static int checkMipmapArgs(GLenum, GLenum, GLenum); +static GLboolean legalFormat(GLenum); +static GLboolean legalType(GLenum); +static GLboolean isTypePackedPixel(GLenum); +static GLboolean isLegalFormatForPackedPixelType(GLenum, GLenum); +static GLboolean isLegalLevels(GLint, GLint, GLint, GLint); +static void closestFit(GLenum, GLint, GLint, GLint, GLenum, GLenum, + GLint *, GLint *); + +/* all extract/shove routines must return double to handle unsigned ints */ +static GLdouble extractUbyte(int, const void *); +static void shoveUbyte(GLdouble, int, void *); +static GLdouble extractSbyte(int, const void *); +static void shoveSbyte(GLdouble, int, void *); +static GLdouble extractUshort(int, const void *); +static void shoveUshort(GLdouble, int, void *); +static GLdouble extractSshort(int, const void *); +static void shoveSshort(GLdouble, int, void *); +static GLdouble extractUint(int, const void *); +static void shoveUint(GLdouble, int, void *); +static GLdouble extractSint(int, const void *); +static void shoveSint(GLdouble, int, void *); +static GLdouble extractFloat(int, const void *); +static void shoveFloat(GLdouble, int, void *); +static void halveImageSlice(int, GLdouble (*)(int, const void *), + void (*)(GLdouble, int, void *), + GLint, GLint, GLint, + const void *, void *, + GLint, GLint, GLint, GLint, GLint); +static void halveImage3D(int, GLdouble (*)(int, const void *), + void (*)(GLdouble, int, void *), + GLint, GLint, GLint, + const void *, void *, + GLint, GLint, GLint, GLint, GLint); + +/* packedpixel type scale routines */ +static void extract332(int,const void *, GLfloat []); +static void shove332(const GLfloat [],int ,void *); +static void extract233rev(int,const void *, GLfloat []); +static void shove233rev(const GLfloat [],int ,void *); +static void extract565(int,const void *, GLfloat []); +static void shove565(const GLfloat [],int ,void *); +static void extract565rev(int,const void *, GLfloat []); +static void shove565rev(const GLfloat [],int ,void *); +static void extract4444(int,const void *, GLfloat []); +static void shove4444(const GLfloat [],int ,void *); +static void extract4444rev(int,const void *, GLfloat []); +static void shove4444rev(const GLfloat [],int ,void *); +static void extract5551(int,const void *, GLfloat []); +static void shove5551(const GLfloat [],int ,void *); +static void extract1555rev(int,const void *, GLfloat []); +static void shove1555rev(const GLfloat [],int ,void *); +static void extract8888(int,const void *, GLfloat []); +static void shove8888(const GLfloat [],int ,void *); +static void extract8888rev(int,const void *, GLfloat []); +static void shove8888rev(const GLfloat [],int ,void *); +static void extract1010102(int,const void *, GLfloat []); +static void shove1010102(const GLfloat [],int ,void *); +static void extract2101010rev(int,const void *, GLfloat []); +static void shove2101010rev(const GLfloat [],int ,void *); +static void scaleInternalPackedPixel(int, + void (*)(int, const void *,GLfloat []), + void (*)(const GLfloat [],int, void *), + GLint,GLint, const void *, + GLint,GLint,void *,GLint,GLint,GLint); +static void halveImagePackedPixel(int, + void (*)(int, const void *,GLfloat []), + void (*)(const GLfloat [],int, void *), + GLint, GLint, const void *, + void *, GLint, GLint, GLint); +static void halve1DimagePackedPixel(int, + void (*)(int, const void *,GLfloat []), + void (*)(const GLfloat [],int, void *), + GLint, GLint, const void *, + void *, GLint, GLint, GLint); + +static void halve1Dimage_ubyte(GLint, GLuint, GLuint,const GLubyte *, + GLubyte *, GLint, GLint, GLint); +static void halve1Dimage_byte(GLint, GLuint, GLuint,const GLbyte *, GLbyte *, + GLint, GLint, GLint); +static void halve1Dimage_ushort(GLint, GLuint, GLuint, const GLushort *, + GLushort *, GLint, GLint, GLint, GLint); +static void halve1Dimage_short(GLint, GLuint, GLuint,const GLshort *, GLshort *, + GLint, GLint, GLint, GLint); +static void halve1Dimage_uint(GLint, GLuint, GLuint, const GLuint *, GLuint *, + GLint, GLint, GLint, GLint); +static void halve1Dimage_int(GLint, GLuint, GLuint, const GLint *, GLint *, + GLint, GLint, GLint, GLint); +static void halve1Dimage_float(GLint, GLuint, GLuint, const GLfloat *, GLfloat *, + GLint, GLint, GLint, GLint); + +static GLint imageSize3D(GLint, GLint, GLint, GLenum,GLenum); +static void fillImage3D(const PixelStorageModes *, GLint, GLint, GLint,GLenum, + GLenum, GLboolean, const void *, GLushort *); +static void emptyImage3D(const PixelStorageModes *, + GLint, GLint, GLint, GLenum, + GLenum, GLboolean, + const GLushort *, void *); +static void scaleInternal3D(GLint, GLint, GLint, GLint, const GLushort *, + GLint, GLint, GLint, GLushort *); + +static void retrieveStoreModes(PixelStorageModes *psm) +{ + glGetIntegerv(GL_UNPACK_ALIGNMENT, &psm->unpack_alignment); + glGetIntegerv(GL_UNPACK_ROW_LENGTH, &psm->unpack_row_length); + glGetIntegerv(GL_UNPACK_SKIP_ROWS, &psm->unpack_skip_rows); + glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &psm->unpack_skip_pixels); + glGetIntegerv(GL_UNPACK_LSB_FIRST, &psm->unpack_lsb_first); + glGetIntegerv(GL_UNPACK_SWAP_BYTES, &psm->unpack_swap_bytes); + + glGetIntegerv(GL_PACK_ALIGNMENT, &psm->pack_alignment); + glGetIntegerv(GL_PACK_ROW_LENGTH, &psm->pack_row_length); + glGetIntegerv(GL_PACK_SKIP_ROWS, &psm->pack_skip_rows); + glGetIntegerv(GL_PACK_SKIP_PIXELS, &psm->pack_skip_pixels); + glGetIntegerv(GL_PACK_LSB_FIRST, &psm->pack_lsb_first); + glGetIntegerv(GL_PACK_SWAP_BYTES, &psm->pack_swap_bytes); +} + +static void retrieveStoreModes3D(PixelStorageModes *psm) +{ + glGetIntegerv(GL_UNPACK_ALIGNMENT, &psm->unpack_alignment); + glGetIntegerv(GL_UNPACK_ROW_LENGTH, &psm->unpack_row_length); + glGetIntegerv(GL_UNPACK_SKIP_ROWS, &psm->unpack_skip_rows); + glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &psm->unpack_skip_pixels); + glGetIntegerv(GL_UNPACK_LSB_FIRST, &psm->unpack_lsb_first); + glGetIntegerv(GL_UNPACK_SWAP_BYTES, &psm->unpack_swap_bytes); + glGetIntegerv(GL_UNPACK_SKIP_IMAGES, &psm->unpack_skip_images); + glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, &psm->unpack_image_height); + + glGetIntegerv(GL_PACK_ALIGNMENT, &psm->pack_alignment); + glGetIntegerv(GL_PACK_ROW_LENGTH, &psm->pack_row_length); + glGetIntegerv(GL_PACK_SKIP_ROWS, &psm->pack_skip_rows); + glGetIntegerv(GL_PACK_SKIP_PIXELS, &psm->pack_skip_pixels); + glGetIntegerv(GL_PACK_LSB_FIRST, &psm->pack_lsb_first); + glGetIntegerv(GL_PACK_SWAP_BYTES, &psm->pack_swap_bytes); + glGetIntegerv(GL_PACK_SKIP_IMAGES, &psm->pack_skip_images); + glGetIntegerv(GL_PACK_IMAGE_HEIGHT, &psm->pack_image_height); +} + +static int computeLog(GLuint value) +{ + int i; + + i = 0; + + /* Error! */ + if (value == 0) return -1; + + for (;;) { + if (value & 1) { + /* Error ! */ + if (value != 1) return -1; + return i; + } + value = value >> 1; + i++; + } +} + +/* +** Compute the nearest power of 2 number. This algorithm is a little +** strange, but it works quite well. +*/ +static int nearestPower(GLuint value) +{ + int i; + + i = 1; + + /* Error! */ + if (value == 0) return -1; + + for (;;) { + if (value == 1) { + return i; + } else if (value == 3) { + return i*4; + } + value = value >> 1; + i *= 2; + } +} + +#define __GLU_SWAP_2_BYTES(s)\ +(GLushort)(((GLushort)((const GLubyte*)(s))[1])<<8 | ((const GLubyte*)(s))[0]) + +#define __GLU_SWAP_4_BYTES(s)\ +(GLuint)(((GLuint)((const GLubyte*)(s))[3])<<24 | \ + ((GLuint)((const GLubyte*)(s))[2])<<16 | \ + ((GLuint)((const GLubyte*)(s))[1])<<8 | ((const GLubyte*)(s))[0]) + +static void halveImage(GLint components, GLuint width, GLuint height, + const GLushort *datain, GLushort *dataout) +{ + int i, j, k; + int newwidth, newheight; + int delta; + GLushort *s; + const GLushort *t; + + newwidth = width / 2; + newheight = height / 2; + delta = width * components; + s = dataout; + t = datain; + + /* Piece o' cake! */ + for (i = 0; i < newheight; i++) { + for (j = 0; j < newwidth; j++) { + for (k = 0; k < components; k++) { + s[0] = (t[0] + t[components] + t[delta] + + t[delta+components] + 2) / 4; + s++; t++; + } + t += components; + } + t += delta; + } +} + +static void halveImage_ubyte(GLint components, GLuint width, GLuint height, + const GLubyte *datain, GLubyte *dataout, + GLint element_size, GLint ysize, GLint group_size) +{ + int i, j, k; + int newwidth, newheight; + int padBytes; + GLubyte *s; + const char *t; + + /* handle case where there is only 1 column/row */ + if (width == 1 || height == 1) { + assert( !(width == 1 && height == 1) ); /* can't be 1x1 */ + halve1Dimage_ubyte(components,width,height,datain,dataout, + element_size,ysize,group_size); + return; + } + + newwidth = width / 2; + newheight = height / 2; + padBytes = ysize - (width*group_size); + s = dataout; + t = (const char *)datain; + + /* Piece o' cake! */ + for (i = 0; i < newheight; i++) { + for (j = 0; j < newwidth; j++) { + for (k = 0; k < components; k++) { + s[0] = (*(const GLubyte*)t + + *(const GLubyte*)(t+group_size) + + *(const GLubyte*)(t+ysize) + + *(const GLubyte*)(t+ysize+group_size) + 2) / 4; + s++; t += element_size; + } + t += group_size; + } + t += padBytes; + t += ysize; + } +} + +/* */ +static void halve1Dimage_ubyte(GLint components, GLuint width, GLuint height, + const GLubyte *dataIn, GLubyte *dataOut, + GLint element_size, GLint ysize, + GLint group_size) +{ + GLint halfWidth= width / 2; + GLint halfHeight= height / 2; + const char *src= (const char *) dataIn; + GLubyte *dest= dataOut; + int jj; + + assert(width == 1 || height == 1); /* must be 1D */ + assert(width != height); /* can't be square */ + + if (height == 1) { /* 1 row */ + assert(width != 1); /* widthxheight can't be 1x1 */ + halfHeight= 1; + + for (jj= 0; jj< halfWidth; jj++) { + int kk; + for (kk= 0; kk< components; kk++) { + *dest= (*(const GLubyte*)src + + *(const GLubyte*)(src+group_size)) / 2; + + src+= element_size; + dest++; + } + src+= group_size; /* skip to next 2 */ + } + { + int padBytes= ysize - (width*group_size); + src+= padBytes; /* for assertion only */ + } + } + else if (width == 1) { /* 1 column */ + int padBytes= ysize - (width * group_size); + assert(height != 1); /* widthxheight can't be 1x1 */ + halfWidth= 1; + /* one vertical column with possible pad bytes per row */ + /* average two at a time */ + + for (jj= 0; jj< halfHeight; jj++) { + int kk; + for (kk= 0; kk< components; kk++) { + *dest= (*(const GLubyte*)src + *(const GLubyte*)(src+ysize)) / 2; + + src+= element_size; + dest++; + } + src+= padBytes; /* add pad bytes, if any, to get to end to row */ + src+= ysize; + } + } + + assert(src == &((const char *)dataIn)[ysize*height]); + assert((char *)dest == &((char *)dataOut) + [components * element_size * halfWidth * halfHeight]); +} /* halve1Dimage_ubyte() */ + +static void halveImage_byte(GLint components, GLuint width, GLuint height, + const GLbyte *datain, GLbyte *dataout, + GLint element_size, + GLint ysize, GLint group_size) +{ + int i, j, k; + int newwidth, newheight; + int padBytes; + GLbyte *s; + const char *t; + + /* handle case where there is only 1 column/row */ + if (width == 1 || height == 1) { + assert( !(width == 1 && height == 1) ); /* can't be 1x1 */ + halve1Dimage_byte(components,width,height,datain,dataout, + element_size,ysize,group_size); + return; + } + + newwidth = width / 2; + newheight = height / 2; + padBytes = ysize - (width*group_size); + s = dataout; + t = (const char *)datain; + + /* Piece o' cake! */ + for (i = 0; i < newheight; i++) { + for (j = 0; j < newwidth; j++) { + for (k = 0; k < components; k++) { + s[0] = (*(const GLbyte*)t + + *(const GLbyte*)(t+group_size) + + *(const GLbyte*)(t+ysize) + + *(const GLbyte*)(t+ysize+group_size) + 2) / 4; + s++; t += element_size; + } + t += group_size; + } + t += padBytes; + t += ysize; + } +} + +static void halve1Dimage_byte(GLint components, GLuint width, GLuint height, + const GLbyte *dataIn, GLbyte *dataOut, + GLint element_size,GLint ysize, GLint group_size) +{ + GLint halfWidth= width / 2; + GLint halfHeight= height / 2; + const char *src= (const char *) dataIn; + GLbyte *dest= dataOut; + int jj; + + assert(width == 1 || height == 1); /* must be 1D */ + assert(width != height); /* can't be square */ + + if (height == 1) { /* 1 row */ + assert(width != 1); /* widthxheight can't be 1x1 */ + halfHeight= 1; + + for (jj= 0; jj< halfWidth; jj++) { + int kk; + for (kk= 0; kk< components; kk++) { + *dest= (*(const GLbyte*)src + *(const GLbyte*)(src+group_size)) / 2; + + src+= element_size; + dest++; + } + src+= group_size; /* skip to next 2 */ + } + { + int padBytes= ysize - (width*group_size); + src+= padBytes; /* for assertion only */ + } + } + else if (width == 1) { /* 1 column */ + int padBytes= ysize - (width * group_size); + assert(height != 1); /* widthxheight can't be 1x1 */ + halfWidth= 1; + /* one vertical column with possible pad bytes per row */ + /* average two at a time */ + + for (jj= 0; jj< halfHeight; jj++) { + int kk; + for (kk= 0; kk< components; kk++) { + *dest= (*(const GLbyte*)src + *(const GLbyte*)(src+ysize)) / 2; + + src+= element_size; + dest++; + } + src+= padBytes; /* add pad bytes, if any, to get to end to row */ + src+= ysize; + } + + assert(src == &((const char *)dataIn)[ysize*height]); + } + + assert((char *)dest == &((char *)dataOut) + [components * element_size * halfWidth * halfHeight]); +} /* halve1Dimage_byte() */ + +static void halveImage_ushort(GLint components, GLuint width, GLuint height, + const GLushort *datain, GLushort *dataout, + GLint element_size, GLint ysize, GLint group_size, + GLint myswap_bytes) +{ + int i, j, k; + int newwidth, newheight; + int padBytes; + GLushort *s; + const char *t; + + /* handle case where there is only 1 column/row */ + if (width == 1 || height == 1) { + assert( !(width == 1 && height == 1) ); /* can't be 1x1 */ + halve1Dimage_ushort(components,width,height,datain,dataout, + element_size,ysize,group_size, myswap_bytes); + return; + } + + newwidth = width / 2; + newheight = height / 2; + padBytes = ysize - (width*group_size); + s = dataout; + t = (const char *)datain; + + /* Piece o' cake! */ + if (!myswap_bytes) + for (i = 0; i < newheight; i++) { + for (j = 0; j < newwidth; j++) { + for (k = 0; k < components; k++) { + s[0] = (*(const GLushort*)t + + *(const GLushort*)(t+group_size) + + *(const GLushort*)(t+ysize) + + *(const GLushort*)(t+ysize+group_size) + 2) / 4; + s++; t += element_size; + } + t += group_size; + } + t += padBytes; + t += ysize; + } + else + for (i = 0; i < newheight; i++) { + for (j = 0; j < newwidth; j++) { + for (k = 0; k < components; k++) { + s[0] = (__GLU_SWAP_2_BYTES(t) + + __GLU_SWAP_2_BYTES(t+group_size) + + __GLU_SWAP_2_BYTES(t+ysize) + + __GLU_SWAP_2_BYTES(t+ysize+group_size)+ 2)/4; + s++; t += element_size; + } + t += group_size; + } + t += padBytes; + t += ysize; + } +} + +static void halve1Dimage_ushort(GLint components, GLuint width, GLuint height, + const GLushort *dataIn, GLushort *dataOut, + GLint element_size, GLint ysize, + GLint group_size, GLint myswap_bytes) +{ + GLint halfWidth= width / 2; + GLint halfHeight= height / 2; + const char *src= (const char *) dataIn; + GLushort *dest= dataOut; + int jj; + + assert(width == 1 || height == 1); /* must be 1D */ + assert(width != height); /* can't be square */ + + if (height == 1) { /* 1 row */ + assert(width != 1); /* widthxheight can't be 1x1 */ + halfHeight= 1; + + for (jj= 0; jj< halfWidth; jj++) { + int kk; + for (kk= 0; kk< components; kk++) { +#define BOX2 2 + GLushort ushort[BOX2]; + if (myswap_bytes) { + ushort[0]= __GLU_SWAP_2_BYTES(src); + ushort[1]= __GLU_SWAP_2_BYTES(src+group_size); + } + else { + ushort[0]= *(const GLushort*)src; + ushort[1]= *(const GLushort*)(src+group_size); + } + + *dest= (ushort[0] + ushort[1]) / 2; + src+= element_size; + dest++; + } + src+= group_size; /* skip to next 2 */ + } + { + int padBytes= ysize - (width*group_size); + src+= padBytes; /* for assertion only */ + } + } + else if (width == 1) { /* 1 column */ + int padBytes= ysize - (width * group_size); + assert(height != 1); /* widthxheight can't be 1x1 */ + halfWidth= 1; + /* one vertical column with possible pad bytes per row */ + /* average two at a time */ + + for (jj= 0; jj< halfHeight; jj++) { + int kk; + for (kk= 0; kk< components; kk++) { +#define BOX2 2 + GLushort ushort[BOX2]; + if (myswap_bytes) { + ushort[0]= __GLU_SWAP_2_BYTES(src); + ushort[1]= __GLU_SWAP_2_BYTES(src+ysize); + } + else { + ushort[0]= *(const GLushort*)src; + ushort[1]= *(const GLushort*)(src+ysize); + } + *dest= (ushort[0] + ushort[1]) / 2; + + src+= element_size; + dest++; + } + src+= padBytes; /* add pad bytes, if any, to get to end to row */ + src+= ysize; + } + + assert(src == &((const char *)dataIn)[ysize*height]); + } + + assert((char *)dest == &((char *)dataOut) + [components * element_size * halfWidth * halfHeight]); + +} /* halve1Dimage_ushort() */ + + +static void halveImage_short(GLint components, GLuint width, GLuint height, + const GLshort *datain, GLshort *dataout, + GLint element_size, GLint ysize, GLint group_size, + GLint myswap_bytes) +{ + int i, j, k; + int newwidth, newheight; + int padBytes; + GLshort *s; + const char *t; + + /* handle case where there is only 1 column/row */ + if (width == 1 || height == 1) { + assert( !(width == 1 && height == 1) ); /* can't be 1x1 */ + halve1Dimage_short(components,width,height,datain,dataout, + element_size,ysize,group_size, myswap_bytes); + return; + } + + newwidth = width / 2; + newheight = height / 2; + padBytes = ysize - (width*group_size); + s = dataout; + t = (const char *)datain; + + /* Piece o' cake! */ + if (!myswap_bytes) + for (i = 0; i < newheight; i++) { + for (j = 0; j < newwidth; j++) { + for (k = 0; k < components; k++) { + s[0] = (*(const GLshort*)t + + *(const GLshort*)(t+group_size) + + *(const GLshort*)(t+ysize) + + *(const GLshort*)(t+ysize+group_size) + 2) / 4; + s++; t += element_size; + } + t += group_size; + } + t += padBytes; + t += ysize; + } + else + for (i = 0; i < newheight; i++) { + for (j = 0; j < newwidth; j++) { + for (k = 0; k < components; k++) { + GLushort b; + GLint buf; + b = __GLU_SWAP_2_BYTES(t); + buf = *(const GLshort*)&b; + b = __GLU_SWAP_2_BYTES(t+group_size); + buf += *(const GLshort*)&b; + b = __GLU_SWAP_2_BYTES(t+ysize); + buf += *(const GLshort*)&b; + b = __GLU_SWAP_2_BYTES(t+ysize+group_size); + buf += *(const GLshort*)&b; + s[0] = (GLshort)((buf+2)/4); + s++; t += element_size; + } + t += group_size; + } + t += padBytes; + t += ysize; + } +} + +static void halve1Dimage_short(GLint components, GLuint width, GLuint height, + const GLshort *dataIn, GLshort *dataOut, + GLint element_size, GLint ysize, + GLint group_size, GLint myswap_bytes) +{ + GLint halfWidth= width / 2; + GLint halfHeight= height / 2; + const char *src= (const char *) dataIn; + GLshort *dest= dataOut; + int jj; + + assert(width == 1 || height == 1); /* must be 1D */ + assert(width != height); /* can't be square */ + + if (height == 1) { /* 1 row */ + assert(width != 1); /* widthxheight can't be 1x1 */ + halfHeight= 1; + + for (jj= 0; jj< halfWidth; jj++) { + int kk; + for (kk= 0; kk< components; kk++) { +#define BOX2 2 + GLshort sshort[BOX2]; + if (myswap_bytes) { + sshort[0]= __GLU_SWAP_2_BYTES(src); + sshort[1]= __GLU_SWAP_2_BYTES(src+group_size); + } + else { + sshort[0]= *(const GLshort*)src; + sshort[1]= *(const GLshort*)(src+group_size); + } + + *dest= (sshort[0] + sshort[1]) / 2; + src+= element_size; + dest++; + } + src+= group_size; /* skip to next 2 */ + } + { + int padBytes= ysize - (width*group_size); + src+= padBytes; /* for assertion only */ + } + } + else if (width == 1) { /* 1 column */ + int padBytes= ysize - (width * group_size); + assert(height != 1); /* widthxheight can't be 1x1 */ + halfWidth= 1; + /* one vertical column with possible pad bytes per row */ + /* average two at a time */ + + for (jj= 0; jj< halfHeight; jj++) { + int kk; + for (kk= 0; kk< components; kk++) { +#define BOX2 2 + GLshort sshort[BOX2]; + if (myswap_bytes) { + sshort[0]= __GLU_SWAP_2_BYTES(src); + sshort[1]= __GLU_SWAP_2_BYTES(src+ysize); + } + else { + sshort[0]= *(const GLshort*)src; + sshort[1]= *(const GLshort*)(src+ysize); + } + *dest= (sshort[0] + sshort[1]) / 2; + + src+= element_size; + dest++; + } + src+= padBytes; /* add pad bytes, if any, to get to end to row */ + src+= ysize; + } + + assert(src == &((const char *)dataIn)[ysize*height]); + } + + assert((char *)dest == &((char *)dataOut) + [components * element_size * halfWidth * halfHeight]); + +} /* halve1Dimage_short() */ + + +static void halveImage_uint(GLint components, GLuint width, GLuint height, + const GLuint *datain, GLuint *dataout, + GLint element_size, GLint ysize, GLint group_size, + GLint myswap_bytes) +{ + int i, j, k; + int newwidth, newheight; + int padBytes; + GLuint *s; + const char *t; + + /* handle case where there is only 1 column/row */ + if (width == 1 || height == 1) { + assert( !(width == 1 && height == 1) ); /* can't be 1x1 */ + halve1Dimage_uint(components,width,height,datain,dataout, + element_size,ysize,group_size, myswap_bytes); + return; + } + + newwidth = width / 2; + newheight = height / 2; + padBytes = ysize - (width*group_size); + s = dataout; + t = (const char *)datain; + + /* Piece o' cake! */ + if (!myswap_bytes) + for (i = 0; i < newheight; i++) { + for (j = 0; j < newwidth; j++) { + for (k = 0; k < components; k++) { + /* need to cast to double to hold large unsigned ints */ + s[0] = ((double)*(const GLuint*)t + + (double)*(const GLuint*)(t+group_size) + + (double)*(const GLuint*)(t+ysize) + + (double)*(const GLuint*)(t+ysize+group_size))/4 + 0.5; + s++; t += element_size; + + } + t += group_size; + } + t += padBytes; + t += ysize; + } + else + for (i = 0; i < newheight; i++) { + for (j = 0; j < newwidth; j++) { + for (k = 0; k < components; k++) { + /* need to cast to double to hold large unsigned ints */ + GLdouble buf; + buf = (GLdouble)__GLU_SWAP_4_BYTES(t) + + (GLdouble)__GLU_SWAP_4_BYTES(t+group_size) + + (GLdouble)__GLU_SWAP_4_BYTES(t+ysize) + + (GLdouble)__GLU_SWAP_4_BYTES(t+ysize+group_size); + s[0] = (GLuint)(buf/4 + 0.5); + + s++; t += element_size; + } + t += group_size; + } + t += padBytes; + t += ysize; + } +} + +/* */ +static void halve1Dimage_uint(GLint components, GLuint width, GLuint height, + const GLuint *dataIn, GLuint *dataOut, + GLint element_size, GLint ysize, + GLint group_size, GLint myswap_bytes) +{ + GLint halfWidth= width / 2; + GLint halfHeight= height / 2; + const char *src= (const char *) dataIn; + GLuint *dest= dataOut; + int jj; + + assert(width == 1 || height == 1); /* must be 1D */ + assert(width != height); /* can't be square */ + + if (height == 1) { /* 1 row */ + assert(width != 1); /* widthxheight can't be 1x1 */ + halfHeight= 1; + + for (jj= 0; jj< halfWidth; jj++) { + int kk; + for (kk= 0; kk< components; kk++) { +#define BOX2 2 + GLuint uint[BOX2]; + if (myswap_bytes) { + uint[0]= __GLU_SWAP_4_BYTES(src); + uint[1]= __GLU_SWAP_4_BYTES(src+group_size); + } + else { + uint[0]= *(const GLuint*)src; + uint[1]= *(const GLuint*)(src+group_size); + } + *dest= ((double)uint[0]+(double)uint[1])/2.0; + + src+= element_size; + dest++; + } + src+= group_size; /* skip to next 2 */ + } + { + int padBytes= ysize - (width*group_size); + src+= padBytes; /* for assertion only */ + } + } + else if (width == 1) { /* 1 column */ + int padBytes= ysize - (width * group_size); + assert(height != 1); /* widthxheight can't be 1x1 */ + halfWidth= 1; + /* one vertical column with possible pad bytes per row */ + /* average two at a time */ + + for (jj= 0; jj< halfHeight; jj++) { + int kk; + for (kk= 0; kk< components; kk++) { +#define BOX2 2 + GLuint uint[BOX2]; + if (myswap_bytes) { + uint[0]= __GLU_SWAP_4_BYTES(src); + uint[1]= __GLU_SWAP_4_BYTES(src+ysize); + } + else { + uint[0]= *(const GLuint*)src; + uint[1]= *(const GLuint*)(src+ysize); + } + *dest= ((double)uint[0]+(double)uint[1])/2.0; + + src+= element_size; + dest++; + } + src+= padBytes; /* add pad bytes, if any, to get to end to row */ + src+= ysize; + } + + assert(src == &((const char *)dataIn)[ysize*height]); + } + + assert((char *)dest == &((char *)dataOut) + [components * element_size * halfWidth * halfHeight]); + +} /* halve1Dimage_uint() */ + +static void halveImage_int(GLint components, GLuint width, GLuint height, + const GLint *datain, GLint *dataout, GLint element_size, + GLint ysize, GLint group_size, GLint myswap_bytes) +{ + int i, j, k; + int newwidth, newheight; + int padBytes; + GLint *s; + const char *t; + + /* handle case where there is only 1 column/row */ + if (width == 1 || height == 1) { + assert( !(width == 1 && height == 1) ); /* can't be 1x1 */ + halve1Dimage_int(components,width,height,datain,dataout, + element_size,ysize,group_size, myswap_bytes); + return; + } + + newwidth = width / 2; + newheight = height / 2; + padBytes = ysize - (width*group_size); + s = dataout; + t = (const char *)datain; + + /* Piece o' cake! */ + if (!myswap_bytes) + for (i = 0; i < newheight; i++) { + for (j = 0; j < newwidth; j++) { + for (k = 0; k < components; k++) { + s[0] = ((float)*(const GLint*)t + + (float)*(const GLint*)(t+group_size) + + (float)*(const GLint*)(t+ysize) + + (float)*(const GLint*)(t+ysize+group_size))/4 + 0.5; + s++; t += element_size; + } + t += group_size; + } + t += padBytes; + t += ysize; + } + else + for (i = 0; i < newheight; i++) { + for (j = 0; j < newwidth; j++) { + for (k = 0; k < components; k++) { + GLuint b; + GLfloat buf; + b = __GLU_SWAP_4_BYTES(t); + buf = *(GLint*)&b; + b = __GLU_SWAP_4_BYTES(t+group_size); + buf += *(GLint*)&b; + b = __GLU_SWAP_4_BYTES(t+ysize); + buf += *(GLint*)&b; + b = __GLU_SWAP_4_BYTES(t+ysize+group_size); + buf += *(GLint*)&b; + s[0] = (GLint)(buf/4 + 0.5); + + s++; t += element_size; + } + t += group_size; + } + t += padBytes; + t += ysize; + } +} + +/* */ +static void halve1Dimage_int(GLint components, GLuint width, GLuint height, + const GLint *dataIn, GLint *dataOut, + GLint element_size, GLint ysize, + GLint group_size, GLint myswap_bytes) +{ + GLint halfWidth= width / 2; + GLint halfHeight= height / 2; + const char *src= (const char *) dataIn; + GLint *dest= dataOut; + int jj; + + assert(width == 1 || height == 1); /* must be 1D */ + assert(width != height); /* can't be square */ + + if (height == 1) { /* 1 row */ + assert(width != 1); /* widthxheight can't be 1x1 */ + halfHeight= 1; + + for (jj= 0; jj< halfWidth; jj++) { + int kk; + for (kk= 0; kk< components; kk++) { +#define BOX2 2 + GLuint uint[BOX2]; + if (myswap_bytes) { + uint[0]= __GLU_SWAP_4_BYTES(src); + uint[1]= __GLU_SWAP_4_BYTES(src+group_size); + } + else { + uint[0]= *(const GLuint*)src; + uint[1]= *(const GLuint*)(src+group_size); + } + *dest= ((float)uint[0]+(float)uint[1])/2.0; + + src+= element_size; + dest++; + } + src+= group_size; /* skip to next 2 */ + } + { + int padBytes= ysize - (width*group_size); + src+= padBytes; /* for assertion only */ + } + } + else if (width == 1) { /* 1 column */ + int padBytes= ysize - (width * group_size); + assert(height != 1); /* widthxheight can't be 1x1 */ + halfWidth= 1; + /* one vertical column with possible pad bytes per row */ + /* average two at a time */ + + for (jj= 0; jj< halfHeight; jj++) { + int kk; + for (kk= 0; kk< components; kk++) { +#define BOX2 2 + GLuint uint[BOX2]; + if (myswap_bytes) { + uint[0]= __GLU_SWAP_4_BYTES(src); + uint[1]= __GLU_SWAP_4_BYTES(src+ysize); + } + else { + uint[0]= *(const GLuint*)src; + uint[1]= *(const GLuint*)(src+ysize); + } + *dest= ((float)uint[0]+(float)uint[1])/2.0; + + src+= element_size; + dest++; + } + src+= padBytes; /* add pad bytes, if any, to get to end to row */ + src+= ysize; + } + + assert(src == &((const char *)dataIn)[ysize*height]); + } + + assert((char *)dest == &((char *)dataOut) + [components * element_size * halfWidth * halfHeight]); + +} /* halve1Dimage_int() */ + + +static void halveImage_float(GLint components, GLuint width, GLuint height, + const GLfloat *datain, GLfloat *dataout, + GLint element_size, GLint ysize, GLint group_size, + GLint myswap_bytes) +{ + int i, j, k; + int newwidth, newheight; + int padBytes; + GLfloat *s; + const char *t; + + /* handle case where there is only 1 column/row */ + if (width == 1 || height == 1) { + assert( !(width == 1 && height == 1) ); /* can't be 1x1 */ + halve1Dimage_float(components,width,height,datain,dataout, + element_size,ysize,group_size, myswap_bytes); + return; + } + + newwidth = width / 2; + newheight = height / 2; + padBytes = ysize - (width*group_size); + s = dataout; + t = (const char *)datain; + + /* Piece o' cake! */ + if (!myswap_bytes) + for (i = 0; i < newheight; i++) { + for (j = 0; j < newwidth; j++) { + for (k = 0; k < components; k++) { + s[0] = (*(const GLfloat*)t + + *(const GLfloat*)(t+group_size) + + *(const GLfloat*)(t+ysize) + + *(const GLfloat*)(t+ysize+group_size)) / 4; + s++; t += element_size; + } + t += group_size; + } + t += padBytes; + t += ysize; + } + else + for (i = 0; i < newheight; i++) { + for (j = 0; j < newwidth; j++) { + for (k = 0; k < components; k++) { + union { GLuint b; GLfloat f; } swapbuf; + swapbuf.b = __GLU_SWAP_4_BYTES(t); + s[0] = swapbuf.f; + swapbuf.b = __GLU_SWAP_4_BYTES(t+group_size); + s[0] += swapbuf.f; + swapbuf.b = __GLU_SWAP_4_BYTES(t+ysize); + s[0] += swapbuf.f; + swapbuf.b = __GLU_SWAP_4_BYTES(t+ysize+group_size); + s[0] += swapbuf.f; + s[0] /= 4; + s++; t += element_size; + } + t += group_size; + } + t += padBytes; + t += ysize; + } +} + +/* */ +static void halve1Dimage_float(GLint components, GLuint width, GLuint height, + const GLfloat *dataIn, GLfloat *dataOut, + GLint element_size, GLint ysize, + GLint group_size, GLint myswap_bytes) +{ + GLint halfWidth= width / 2; + GLint halfHeight= height / 2; + const char *src= (const char *) dataIn; + GLfloat *dest= dataOut; + int jj; + + assert(width == 1 || height == 1); /* must be 1D */ + assert(width != height); /* can't be square */ + + if (height == 1) { /* 1 row */ + assert(width != 1); /* widthxheight can't be 1x1 */ + halfHeight= 1; + + for (jj= 0; jj< halfWidth; jj++) { + int kk; + for (kk= 0; kk< components; kk++) { +#define BOX2 2 + GLfloat sfloat[BOX2]; + if (myswap_bytes) { + sfloat[0]= __GLU_SWAP_4_BYTES(src); + sfloat[1]= __GLU_SWAP_4_BYTES(src+group_size); + } + else { + sfloat[0]= *(const GLfloat*)src; + sfloat[1]= *(const GLfloat*)(src+group_size); + } + + *dest= (sfloat[0] + sfloat[1]) / 2.0; + src+= element_size; + dest++; + } + src+= group_size; /* skip to next 2 */ + } + { + int padBytes= ysize - (width*group_size); + src+= padBytes; /* for assertion only */ + } + } + else if (width == 1) { /* 1 column */ + int padBytes= ysize - (width * group_size); + assert(height != 1); /* widthxheight can't be 1x1 */ + halfWidth= 1; + /* one vertical column with possible pad bytes per row */ + /* average two at a time */ + + for (jj= 0; jj< halfHeight; jj++) { + int kk; + for (kk= 0; kk< components; kk++) { +#define BOX2 2 + GLfloat sfloat[BOX2]; + if (myswap_bytes) { + sfloat[0]= __GLU_SWAP_4_BYTES(src); + sfloat[1]= __GLU_SWAP_4_BYTES(src+ysize); + } + else { + sfloat[0]= *(const GLfloat*)src; + sfloat[1]= *(const GLfloat*)(src+ysize); + } + *dest= (sfloat[0] + sfloat[1]) / 2.0; + + src+= element_size; + dest++; + } + src+= padBytes; /* add pad bytes, if any, to get to end to row */ + src+= ysize; /* skip to odd row */ + } + } + + assert(src == &((const char *)dataIn)[ysize*height]); + assert((char *)dest == &((char *)dataOut) + [components * element_size * halfWidth * halfHeight]); +} /* halve1Dimage_float() */ + +static void scale_internal(GLint components, GLint widthin, GLint heightin, + const GLushort *datain, + GLint widthout, GLint heightout, + GLushort *dataout) +{ + float x, lowx, highx, convx, halfconvx; + float y, lowy, highy, convy, halfconvy; + float xpercent,ypercent; + float percent; + /* Max components in a format is 4, so... */ + float totals[4]; + float area; + int i,j,k,yint,xint,xindex,yindex; + int temp; + + if (widthin == widthout*2 && heightin == heightout*2) { + halveImage(components, widthin, heightin, datain, dataout); + return; + } + convy = (float) heightin/heightout; + convx = (float) widthin/widthout; + halfconvx = convx/2; + halfconvy = convy/2; + for (i = 0; i < heightout; i++) { + y = convy * (i+0.5); + if (heightin > heightout) { + highy = y + halfconvy; + lowy = y - halfconvy; + } else { + highy = y + 0.5; + lowy = y - 0.5; + } + for (j = 0; j < widthout; j++) { + x = convx * (j+0.5); + if (widthin > widthout) { + highx = x + halfconvx; + lowx = x - halfconvx; + } else { + highx = x + 0.5; + lowx = x - 0.5; + } + + /* + ** Ok, now apply box filter to box that goes from (lowx, lowy) + ** to (highx, highy) on input data into this pixel on output + ** data. + */ + totals[0] = totals[1] = totals[2] = totals[3] = 0.0; + area = 0.0; + + y = lowy; + yint = floor(y); + while (y < highy) { + yindex = (yint + heightin) % heightin; + if (highy < yint+1) { + ypercent = highy - y; + } else { + ypercent = yint+1 - y; + } + + x = lowx; + xint = floor(x); + + while (x < highx) { + xindex = (xint + widthin) % widthin; + if (highx < xint+1) { + xpercent = highx - x; + } else { + xpercent = xint+1 - x; + } + + percent = xpercent * ypercent; + area += percent; + temp = (xindex + (yindex * widthin)) * components; + for (k = 0; k < components; k++) { + totals[k] += datain[temp + k] * percent; + } + + xint++; + x = xint; + } + yint++; + y = yint; + } + + temp = (j + (i * widthout)) * components; + for (k = 0; k < components; k++) { + /* totals[] should be rounded in the case of enlarging an RGB + * ramp when the type is 332 or 4444 + */ + dataout[temp + k] = (totals[k]+0.5)/area; + } + } + } +} + +static void scale_internal_ubyte(GLint components, GLint widthin, + GLint heightin, const GLubyte *datain, + GLint widthout, GLint heightout, + GLubyte *dataout, GLint element_size, + GLint ysize, GLint group_size) +{ + float convx; + float convy; + float percent; + /* Max components in a format is 4, so... */ + float totals[4]; + float area; + int i,j,k,xindex; + + const char *temp, *temp0; + const char *temp_index; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + const char *left, *right; + + if (widthin == widthout*2 && heightin == heightout*2) { + halveImage_ubyte(components, widthin, heightin, + (const GLubyte *)datain, (GLubyte *)dataout, + element_size, ysize, group_size); + return; + } + convy = (float) heightin/heightout; + convx = (float) widthin/widthout; + convy_int = floor(convy); + convy_float = convy - convy_int; + convx_int = floor(convx); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0; + highy_int = convy_int; + highy_float = convy_float; + + for (i = 0; i < heightout; i++) { + /* Clamp here to be sure we don't read beyond input buffer. */ + if (highy_int >= heightin) + highy_int = heightin - 1; + lowx_int = 0; + lowx_float = 0; + highx_int = convx_int; + highx_float = convx_float; + + for (j = 0; j < widthout; j++) { + + /* + ** Ok, now apply box filter to box that goes from (lowx, lowy) + ** to (highx, highy) on input data into this pixel on output + ** data. + */ + totals[0] = totals[1] = totals[2] = totals[3] = 0.0; + + /* calculate the value for pixels in the 1st row */ + xindex = lowx_int*group_size; + if((highy_int>lowy_int) && (highx_int>lowx_int)) { + + y_percent = 1-lowy_float; + temp = (const char *)datain + xindex + lowy_int * ysize; + percent = y_percent * (1-lowx_float); + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLubyte)(*(temp_index)) * percent; + } + left = temp; + for(l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLubyte)(*(temp_index)) * y_percent; + } + } + temp += group_size; + right = temp; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLubyte)(*(temp_index)) * percent; + } + + /* calculate the value for pixels in the last row */ + y_percent = highy_float; + percent = y_percent * (1-lowx_float); + temp = (const char *)datain + xindex + highy_int * ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLubyte)(*(temp_index)) * percent; + } + for(l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLubyte)(*(temp_index)) * y_percent; + } + } + temp += group_size; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLubyte)(*(temp_index)) * percent; + } + + + /* calculate the value for pixels in the 1st and last column */ + for(m = lowy_int+1; m < highy_int; m++) { + left += ysize; + right += ysize; + for (k = 0; k < components; + k++, left += element_size, right += element_size) { + totals[k] += (GLubyte)(*(left))*(1-lowx_float) + +(GLubyte)(*(right))*highx_float; + } + } + } else if (highy_int > lowy_int) { + x_percent = highx_float - lowx_float; + percent = (1-lowy_float)*x_percent; + temp = (const char *)datain + xindex + lowy_int*ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLubyte)(*(temp_index)) * percent; + } + for(m = lowy_int+1; m < highy_int; m++) { + temp += ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLubyte)(*(temp_index)) * x_percent; + } + } + percent = x_percent * highy_float; + temp += ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLubyte)(*(temp_index)) * percent; + } + } else if (highx_int > lowx_int) { + y_percent = highy_float - lowy_float; + percent = (1-lowx_float)*y_percent; + temp = (const char *)datain + xindex + lowy_int*ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLubyte)(*(temp_index)) * percent; + } + for (l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLubyte)(*(temp_index)) * y_percent; + } + } + temp += group_size; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLubyte)(*(temp_index)) * percent; + } + } else { + percent = (highy_float-lowy_float)*(highx_float-lowx_float); + temp = (const char *)datain + xindex + lowy_int * ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLubyte)(*(temp_index)) * percent; + } + } + + + + /* this is for the pixels in the body */ + temp0 = (const char *)datain + xindex + group_size + + (lowy_int+1)*ysize; + for (m = lowy_int+1; m < highy_int; m++) { + temp = temp0; + for(l = lowx_int+1; l < highx_int; l++) { + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLubyte)(*(temp_index)); + } + temp += group_size; + } + temp0 += ysize; + } + + outindex = (j + (i * widthout)) * components; + for (k = 0; k < components; k++) { + dataout[outindex + k] = totals[k]/area; + /*printf("totals[%d] = %f\n", k, totals[k]);*/ + } + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if(highx_float > 1) { + highx_float -= 1.0; + highx_int++; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if(highy_float > 1) { + highy_float -= 1.0; + highy_int++; + } + } +} + +static void scale_internal_byte(GLint components, GLint widthin, + GLint heightin, const GLbyte *datain, + GLint widthout, GLint heightout, + GLbyte *dataout, GLint element_size, + GLint ysize, GLint group_size) +{ + float convx; + float convy; + float percent; + /* Max components in a format is 4, so... */ + float totals[4]; + float area; + int i,j,k,xindex; + + const char *temp, *temp0; + const char *temp_index; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + const char *left, *right; + + if (widthin == widthout*2 && heightin == heightout*2) { + halveImage_byte(components, widthin, heightin, + (const GLbyte *)datain, (GLbyte *)dataout, + element_size, ysize, group_size); + return; + } + convy = (float) heightin/heightout; + convx = (float) widthin/widthout; + convy_int = floor(convy); + convy_float = convy - convy_int; + convx_int = floor(convx); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0; + highy_int = convy_int; + highy_float = convy_float; + + for (i = 0; i < heightout; i++) { + /* Clamp here to be sure we don't read beyond input buffer. */ + if (highy_int >= heightin) + highy_int = heightin - 1; + lowx_int = 0; + lowx_float = 0; + highx_int = convx_int; + highx_float = convx_float; + + for (j = 0; j < widthout; j++) { + + /* + ** Ok, now apply box filter to box that goes from (lowx, lowy) + ** to (highx, highy) on input data into this pixel on output + ** data. + */ + totals[0] = totals[1] = totals[2] = totals[3] = 0.0; + + /* calculate the value for pixels in the 1st row */ + xindex = lowx_int*group_size; + if((highy_int>lowy_int) && (highx_int>lowx_int)) { + + y_percent = 1-lowy_float; + temp = (const char *)datain + xindex + lowy_int * ysize; + percent = y_percent * (1-lowx_float); + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLbyte)(*(temp_index)) * percent; + } + left = temp; + for(l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLbyte)(*(temp_index)) * y_percent; + } + } + temp += group_size; + right = temp; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLbyte)(*(temp_index)) * percent; + } + + /* calculate the value for pixels in the last row */ + y_percent = highy_float; + percent = y_percent * (1-lowx_float); + temp = (const char *)datain + xindex + highy_int * ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLbyte)(*(temp_index)) * percent; + } + for(l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLbyte)(*(temp_index)) * y_percent; + } + } + temp += group_size; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLbyte)(*(temp_index)) * percent; + } + + + /* calculate the value for pixels in the 1st and last column */ + for(m = lowy_int+1; m < highy_int; m++) { + left += ysize; + right += ysize; + for (k = 0; k < components; + k++, left += element_size, right += element_size) { + totals[k] += (GLbyte)(*(left))*(1-lowx_float) + +(GLbyte)(*(right))*highx_float; + } + } + } else if (highy_int > lowy_int) { + x_percent = highx_float - lowx_float; + percent = (1-lowy_float)*x_percent; + temp = (const char *)datain + xindex + lowy_int*ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLbyte)(*(temp_index)) * percent; + } + for(m = lowy_int+1; m < highy_int; m++) { + temp += ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLbyte)(*(temp_index)) * x_percent; + } + } + percent = x_percent * highy_float; + temp += ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLbyte)(*(temp_index)) * percent; + } + } else if (highx_int > lowx_int) { + y_percent = highy_float - lowy_float; + percent = (1-lowx_float)*y_percent; + temp = (const char *)datain + xindex + lowy_int*ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLbyte)(*(temp_index)) * percent; + } + for (l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLbyte)(*(temp_index)) * y_percent; + } + } + temp += group_size; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLbyte)(*(temp_index)) * percent; + } + } else { + percent = (highy_float-lowy_float)*(highx_float-lowx_float); + temp = (const char *)datain + xindex + lowy_int * ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLbyte)(*(temp_index)) * percent; + } + } + + + + /* this is for the pixels in the body */ + temp0 = (const char *)datain + xindex + group_size + + (lowy_int+1)*ysize; + for (m = lowy_int+1; m < highy_int; m++) { + temp = temp0; + for(l = lowx_int+1; l < highx_int; l++) { + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + totals[k] += (GLbyte)(*(temp_index)); + } + temp += group_size; + } + temp0 += ysize; + } + + outindex = (j + (i * widthout)) * components; + for (k = 0; k < components; k++) { + dataout[outindex + k] = totals[k]/area; + /*printf("totals[%d] = %f\n", k, totals[k]);*/ + } + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if(highx_float > 1) { + highx_float -= 1.0; + highx_int++; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if(highy_float > 1) { + highy_float -= 1.0; + highy_int++; + } + } +} + +static void scale_internal_ushort(GLint components, GLint widthin, + GLint heightin, const GLushort *datain, + GLint widthout, GLint heightout, + GLushort *dataout, GLint element_size, + GLint ysize, GLint group_size, + GLint myswap_bytes) +{ + float convx; + float convy; + float percent; + /* Max components in a format is 4, so... */ + float totals[4]; + float area; + int i,j,k,xindex; + + const char *temp, *temp0; + const char *temp_index; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + const char *left, *right; + + if (widthin == widthout*2 && heightin == heightout*2) { + halveImage_ushort(components, widthin, heightin, + (const GLushort *)datain, (GLushort *)dataout, + element_size, ysize, group_size, myswap_bytes); + return; + } + convy = (float) heightin/heightout; + convx = (float) widthin/widthout; + convy_int = floor(convy); + convy_float = convy - convy_int; + convx_int = floor(convx); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0; + highy_int = convy_int; + highy_float = convy_float; + + for (i = 0; i < heightout; i++) { + /* Clamp here to be sure we don't read beyond input buffer. */ + if (highy_int >= heightin) + highy_int = heightin - 1; + lowx_int = 0; + lowx_float = 0; + highx_int = convx_int; + highx_float = convx_float; + + for (j = 0; j < widthout; j++) { + /* + ** Ok, now apply box filter to box that goes from (lowx, lowy) + ** to (highx, highy) on input data into this pixel on output + ** data. + */ + totals[0] = totals[1] = totals[2] = totals[3] = 0.0; + + /* calculate the value for pixels in the 1st row */ + xindex = lowx_int*group_size; + if((highy_int>lowy_int) && (highx_int>lowx_int)) { + + y_percent = 1-lowy_float; + temp = (const char *)datain + xindex + lowy_int * ysize; + percent = y_percent * (1-lowx_float); + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } + left = temp; + for(l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_2_BYTES(temp_index) * y_percent; + } else { + totals[k] += *(const GLushort*)temp_index * y_percent; + } + } + } + temp += group_size; + right = temp; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } + + /* calculate the value for pixels in the last row */ + y_percent = highy_float; + percent = y_percent * (1-lowx_float); + temp = (const char *)datain + xindex + highy_int * ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } + for(l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_2_BYTES(temp_index) * y_percent; + } else { + totals[k] += *(const GLushort*)temp_index * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } + + /* calculate the value for pixels in the 1st and last column */ + for(m = lowy_int+1; m < highy_int; m++) { + left += ysize; + right += ysize; + for (k = 0; k < components; + k++, left += element_size, right += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_2_BYTES(left) * (1-lowx_float) + + __GLU_SWAP_2_BYTES(right) * highx_float; + } else { + totals[k] += *(const GLushort*)left * (1-lowx_float) + + *(const GLushort*)right * highx_float; + } + } + } + } else if (highy_int > lowy_int) { + x_percent = highx_float - lowx_float; + percent = (1-lowy_float)*x_percent; + temp = (const char *)datain + xindex + lowy_int*ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } + for(m = lowy_int+1; m < highy_int; m++) { + temp += ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_2_BYTES(temp_index) * x_percent; + } else { + totals[k] += *(const GLushort*)temp_index * x_percent; + } + } + } + percent = x_percent * highy_float; + temp += ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } + } else if (highx_int > lowx_int) { + y_percent = highy_float - lowy_float; + percent = (1-lowx_float)*y_percent; + temp = (const char *)datain + xindex + lowy_int*ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } + for (l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_2_BYTES(temp_index) * y_percent; + } else { + totals[k] += *(const GLushort*)temp_index * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } + } else { + percent = (highy_float-lowy_float)*(highx_float-lowx_float); + temp = (const char *)datain + xindex + lowy_int * ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } + } + + /* this is for the pixels in the body */ + temp0 = (const char *)datain + xindex + group_size + + (lowy_int+1)*ysize; + for (m = lowy_int+1; m < highy_int; m++) { + temp = temp0; + for(l = lowx_int+1; l < highx_int; l++) { + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index); + } else { + totals[k] += *(const GLushort*)temp_index; + } + } + temp += group_size; + } + temp0 += ysize; + } + + outindex = (j + (i * widthout)) * components; + for (k = 0; k < components; k++) { + dataout[outindex + k] = totals[k]/area; + /*printf("totals[%d] = %f\n", k, totals[k]);*/ + } + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if(highx_float > 1) { + highx_float -= 1.0; + highx_int++; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if(highy_float > 1) { + highy_float -= 1.0; + highy_int++; + } + } +} + +static void scale_internal_short(GLint components, GLint widthin, + GLint heightin, const GLshort *datain, + GLint widthout, GLint heightout, + GLshort *dataout, GLint element_size, + GLint ysize, GLint group_size, + GLint myswap_bytes) +{ + float convx; + float convy; + float percent; + /* Max components in a format is 4, so... */ + float totals[4]; + float area; + int i,j,k,xindex; + + const char *temp, *temp0; + const char *temp_index; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + const char *left, *right; + + GLushort swapbuf; /* unsigned buffer */ + + if (widthin == widthout*2 && heightin == heightout*2) { + halveImage_short(components, widthin, heightin, + (const GLshort *)datain, (GLshort *)dataout, + element_size, ysize, group_size, myswap_bytes); + return; + } + convy = (float) heightin/heightout; + convx = (float) widthin/widthout; + convy_int = floor(convy); + convy_float = convy - convy_int; + convx_int = floor(convx); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0; + highy_int = convy_int; + highy_float = convy_float; + + for (i = 0; i < heightout; i++) { + /* Clamp here to be sure we don't read beyond input buffer. */ + if (highy_int >= heightin) + highy_int = heightin - 1; + lowx_int = 0; + lowx_float = 0; + highx_int = convx_int; + highx_float = convx_float; + + for (j = 0; j < widthout; j++) { + /* + ** Ok, now apply box filter to box that goes from (lowx, lowy) + ** to (highx, highy) on input data into this pixel on output + ** data. + */ + totals[0] = totals[1] = totals[2] = totals[3] = 0.0; + + /* calculate the value for pixels in the 1st row */ + xindex = lowx_int*group_size; + if((highy_int>lowy_int) && (highx_int>lowx_int)) { + + y_percent = 1-lowy_float; + temp = (const char *)datain + xindex + lowy_int * ysize; + percent = y_percent * (1-lowx_float); + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(temp_index); + totals[k] += *(const GLshort*)&swapbuf * percent; + } else { + totals[k] += *(const GLshort*)temp_index * percent; + } + } + left = temp; + for(l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(temp_index); + totals[k] += *(const GLshort*)&swapbuf * y_percent; + } else { + totals[k] += *(const GLshort*)temp_index * y_percent; + } + } + } + temp += group_size; + right = temp; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(temp_index); + totals[k] += *(const GLshort*)&swapbuf * percent; + } else { + totals[k] += *(const GLshort*)temp_index * percent; + } + } + + /* calculate the value for pixels in the last row */ + y_percent = highy_float; + percent = y_percent * (1-lowx_float); + temp = (const char *)datain + xindex + highy_int * ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(temp_index); + totals[k] += *(const GLshort*)&swapbuf * percent; + } else { + totals[k] += *(const GLshort*)temp_index * percent; + } + } + for(l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(temp_index); + totals[k] += *(const GLshort*)&swapbuf * y_percent; + } else { + totals[k] += *(const GLshort*)temp_index * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(temp_index); + totals[k] += *(const GLshort*)&swapbuf * percent; + } else { + totals[k] += *(const GLshort*)temp_index * percent; + } + } + + /* calculate the value for pixels in the 1st and last column */ + for(m = lowy_int+1; m < highy_int; m++) { + left += ysize; + right += ysize; + for (k = 0; k < components; + k++, left += element_size, right += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(left); + totals[k] += *(const GLshort*)&swapbuf * (1-lowx_float); + swapbuf = __GLU_SWAP_2_BYTES(right); + totals[k] += *(const GLshort*)&swapbuf * highx_float; + } else { + totals[k] += *(const GLshort*)left * (1-lowx_float) + + *(const GLshort*)right * highx_float; + } + } + } + } else if (highy_int > lowy_int) { + x_percent = highx_float - lowx_float; + percent = (1-lowy_float)*x_percent; + temp = (const char *)datain + xindex + lowy_int*ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(temp_index); + totals[k] += *(const GLshort*)&swapbuf * percent; + } else { + totals[k] += *(const GLshort*)temp_index * percent; + } + } + for(m = lowy_int+1; m < highy_int; m++) { + temp += ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(temp_index); + totals[k] += *(const GLshort*)&swapbuf * x_percent; + } else { + totals[k] += *(const GLshort*)temp_index * x_percent; + } + } + } + percent = x_percent * highy_float; + temp += ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(temp_index); + totals[k] += *(const GLshort*)&swapbuf * percent; + } else { + totals[k] += *(const GLshort*)temp_index * percent; + } + } + } else if (highx_int > lowx_int) { + y_percent = highy_float - lowy_float; + percent = (1-lowx_float)*y_percent; + + temp = (const char *)datain + xindex + lowy_int*ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(temp_index); + totals[k] += *(const GLshort*)&swapbuf * percent; + } else { + totals[k] += *(const GLshort*)temp_index * percent; + } + } + for (l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(temp_index); + totals[k] += *(const GLshort*)&swapbuf * y_percent; + } else { + totals[k] += *(const GLshort*)temp_index * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(temp_index); + totals[k] += *(const GLshort*)&swapbuf * percent; + } else { + totals[k] += *(const GLshort*)temp_index * percent; + } + } + } else { + percent = (highy_float-lowy_float)*(highx_float-lowx_float); + temp = (const char *)datain + xindex + lowy_int * ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(temp_index); + totals[k] += *(const GLshort*)&swapbuf * percent; + } else { + totals[k] += *(const GLshort*)temp_index * percent; + } + } + } + + /* this is for the pixels in the body */ + temp0 = (const char *)datain + xindex + group_size + + (lowy_int+1)*ysize; + for (m = lowy_int+1; m < highy_int; m++) { + temp = temp0; + for(l = lowx_int+1; l < highx_int; l++) { + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_2_BYTES(temp_index); + totals[k] += *(const GLshort*)&swapbuf; + } else { + totals[k] += *(const GLshort*)temp_index; + } + } + temp += group_size; + } + temp0 += ysize; + } + + outindex = (j + (i * widthout)) * components; + for (k = 0; k < components; k++) { + dataout[outindex + k] = totals[k]/area; + /*printf("totals[%d] = %f\n", k, totals[k]);*/ + } + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if(highx_float > 1) { + highx_float -= 1.0; + highx_int++; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if(highy_float > 1) { + highy_float -= 1.0; + highy_int++; + } + } +} + +static void scale_internal_uint(GLint components, GLint widthin, + GLint heightin, const GLuint *datain, + GLint widthout, GLint heightout, + GLuint *dataout, GLint element_size, + GLint ysize, GLint group_size, + GLint myswap_bytes) +{ + float convx; + float convy; + float percent; + /* Max components in a format is 4, so... */ + float totals[4]; + float area; + int i,j,k,xindex; + + const char *temp, *temp0; + const char *temp_index; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + const char *left, *right; + + if (widthin == widthout*2 && heightin == heightout*2) { + halveImage_uint(components, widthin, heightin, + (const GLuint *)datain, (GLuint *)dataout, + element_size, ysize, group_size, myswap_bytes); + return; + } + convy = (float) heightin/heightout; + convx = (float) widthin/widthout; + convy_int = floor(convy); + convy_float = convy - convy_int; + convx_int = floor(convx); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0; + highy_int = convy_int; + highy_float = convy_float; + + for (i = 0; i < heightout; i++) { + /* Clamp here to be sure we don't read beyond input buffer. */ + if (highy_int >= heightin) + highy_int = heightin - 1; + lowx_int = 0; + lowx_float = 0; + highx_int = convx_int; + highx_float = convx_float; + + for (j = 0; j < widthout; j++) { + /* + ** Ok, now apply box filter to box that goes from (lowx, lowy) + ** to (highx, highy) on input data into this pixel on output + ** data. + */ + totals[0] = totals[1] = totals[2] = totals[3] = 0.0; + + /* calculate the value for pixels in the 1st row */ + xindex = lowx_int*group_size; + if((highy_int>lowy_int) && (highx_int>lowx_int)) { + + y_percent = 1-lowy_float; + temp = (const char *)datain + xindex + lowy_int * ysize; + percent = y_percent * (1-lowx_float); + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_4_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLuint*)temp_index * percent; + } + } + left = temp; + for(l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_4_BYTES(temp_index) * y_percent; + } else { + totals[k] += *(const GLuint*)temp_index * y_percent; + } + } + } + temp += group_size; + right = temp; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_4_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLuint*)temp_index * percent; + } + } + + /* calculate the value for pixels in the last row */ + y_percent = highy_float; + percent = y_percent * (1-lowx_float); + temp = (const char *)datain + xindex + highy_int * ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_4_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLuint*)temp_index * percent; + } + } + for(l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_4_BYTES(temp_index) * y_percent; + } else { + totals[k] += *(const GLuint*)temp_index * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_4_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLuint*)temp_index * percent; + } + } + + /* calculate the value for pixels in the 1st and last column */ + for(m = lowy_int+1; m < highy_int; m++) { + left += ysize; + right += ysize; + for (k = 0; k < components; + k++, left += element_size, right += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_4_BYTES(left) * (1-lowx_float) + + __GLU_SWAP_4_BYTES(right) * highx_float; + } else { + totals[k] += *(const GLuint*)left * (1-lowx_float) + + *(const GLuint*)right * highx_float; + } + } + } + } else if (highy_int > lowy_int) { + x_percent = highx_float - lowx_float; + percent = (1-lowy_float)*x_percent; + temp = (const char *)datain + xindex + lowy_int*ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_4_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLuint*)temp_index * percent; + } + } + for(m = lowy_int+1; m < highy_int; m++) { + temp += ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_4_BYTES(temp_index) * x_percent; + } else { + totals[k] += *(const GLuint*)temp_index * x_percent; + } + } + } + percent = x_percent * highy_float; + temp += ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_4_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLuint*)temp_index * percent; + } + } + } else if (highx_int > lowx_int) { + y_percent = highy_float - lowy_float; + percent = (1-lowx_float)*y_percent; + + temp = (const char *)datain + xindex + lowy_int*ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_4_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLuint*)temp_index * percent; + } + } + for (l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_4_BYTES(temp_index) * y_percent; + } else { + totals[k] += *(const GLuint*)temp_index * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_4_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLuint*)temp_index * percent; + } + } + } else { + percent = (highy_float-lowy_float)*(highx_float-lowx_float); + temp = (const char *)datain + xindex + lowy_int * ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_4_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLuint*)temp_index * percent; + } + } + } + + /* this is for the pixels in the body */ + temp0 = (const char *)datain + xindex + group_size + + (lowy_int+1)*ysize; + for (m = lowy_int+1; m < highy_int; m++) { + temp = temp0; + for(l = lowx_int+1; l < highx_int; l++) { + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_4_BYTES(temp_index); + } else { + totals[k] += *(const GLuint*)temp_index; + } + } + temp += group_size; + } + temp0 += ysize; + } + + outindex = (j + (i * widthout)) * components; + for (k = 0; k < components; k++) { + /* clamp at UINT_MAX */ + float value= totals[k]/area; + if (value >= (float) UINT_MAX) { /* need '=' */ + dataout[outindex + k] = UINT_MAX; + } + else dataout[outindex + k] = value; + } + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if(highx_float > 1) { + highx_float -= 1.0; + highx_int++; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if(highy_float > 1) { + highy_float -= 1.0; + highy_int++; + } + } +} + + + +static void scale_internal_int(GLint components, GLint widthin, + GLint heightin, const GLint *datain, + GLint widthout, GLint heightout, + GLint *dataout, GLint element_size, + GLint ysize, GLint group_size, + GLint myswap_bytes) +{ + float convx; + float convy; + float percent; + /* Max components in a format is 4, so... */ + float totals[4]; + float area; + int i,j,k,xindex; + + const char *temp, *temp0; + const char *temp_index; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + const char *left, *right; + + GLuint swapbuf; /* unsigned buffer */ + + if (widthin == widthout*2 && heightin == heightout*2) { + halveImage_int(components, widthin, heightin, + (const GLint *)datain, (GLint *)dataout, + element_size, ysize, group_size, myswap_bytes); + return; + } + convy = (float) heightin/heightout; + convx = (float) widthin/widthout; + convy_int = floor(convy); + convy_float = convy - convy_int; + convx_int = floor(convx); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0; + highy_int = convy_int; + highy_float = convy_float; + + for (i = 0; i < heightout; i++) { + /* Clamp here to be sure we don't read beyond input buffer. */ + if (highy_int >= heightin) + highy_int = heightin - 1; + lowx_int = 0; + lowx_float = 0; + highx_int = convx_int; + highx_float = convx_float; + + for (j = 0; j < widthout; j++) { + /* + ** Ok, now apply box filter to box that goes from (lowx, lowy) + ** to (highx, highy) on input data into this pixel on output + ** data. + */ + totals[0] = totals[1] = totals[2] = totals[3] = 0.0; + + /* calculate the value for pixels in the 1st row */ + xindex = lowx_int*group_size; + if((highy_int>lowy_int) && (highx_int>lowx_int)) { + + y_percent = 1-lowy_float; + temp = (const char *)datain + xindex + lowy_int * ysize; + percent = y_percent * (1-lowx_float); + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += *(const GLint*)&swapbuf * percent; + } else { + totals[k] += *(const GLint*)temp_index * percent; + } + } + left = temp; + for(l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += *(const GLint*)&swapbuf * y_percent; + } else { + totals[k] += *(const GLint*)temp_index * y_percent; + } + } + } + temp += group_size; + right = temp; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += *(const GLint*)&swapbuf * percent; + } else { + totals[k] += *(const GLint*)temp_index * percent; + } + } + + /* calculate the value for pixels in the last row */ + y_percent = highy_float; + percent = y_percent * (1-lowx_float); + temp = (const char *)datain + xindex + highy_int * ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += *(const GLint*)&swapbuf * percent; + } else { + totals[k] += *(const GLint*)temp_index * percent; + } + } + for(l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += *(const GLint*)&swapbuf * y_percent; + } else { + totals[k] += *(const GLint*)temp_index * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += *(const GLint*)&swapbuf * percent; + } else { + totals[k] += *(const GLint*)temp_index * percent; + } + } + + /* calculate the value for pixels in the 1st and last column */ + for(m = lowy_int+1; m < highy_int; m++) { + left += ysize; + right += ysize; + for (k = 0; k < components; + k++, left += element_size, right += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(left); + totals[k] += *(const GLint*)&swapbuf * (1-lowx_float); + swapbuf = __GLU_SWAP_4_BYTES(right); + totals[k] += *(const GLint*)&swapbuf * highx_float; + } else { + totals[k] += *(const GLint*)left * (1-lowx_float) + + *(const GLint*)right * highx_float; + } + } + } + } else if (highy_int > lowy_int) { + x_percent = highx_float - lowx_float; + percent = (1-lowy_float)*x_percent; + temp = (const char *)datain + xindex + lowy_int*ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += *(const GLint*)&swapbuf * percent; + } else { + totals[k] += *(const GLint*)temp_index * percent; + } + } + for(m = lowy_int+1; m < highy_int; m++) { + temp += ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += *(const GLint*)&swapbuf * x_percent; + } else { + totals[k] += *(const GLint*)temp_index * x_percent; + } + } + } + percent = x_percent * highy_float; + temp += ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += *(const GLint*)&swapbuf * percent; + } else { + totals[k] += *(const GLint*)temp_index * percent; + } + } + } else if (highx_int > lowx_int) { + y_percent = highy_float - lowy_float; + percent = (1-lowx_float)*y_percent; + + temp = (const char *)datain + xindex + lowy_int*ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += *(const GLint*)&swapbuf * percent; + } else { + totals[k] += *(const GLint*)temp_index * percent; + } + } + for (l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += *(const GLint*)&swapbuf * y_percent; + } else { + totals[k] += *(const GLint*)temp_index * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += *(const GLint*)&swapbuf * percent; + } else { + totals[k] += *(const GLint*)temp_index * percent; + } + } + } else { + percent = (highy_float-lowy_float)*(highx_float-lowx_float); + temp = (const char *)datain + xindex + lowy_int * ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += *(const GLint*)&swapbuf * percent; + } else { + totals[k] += *(const GLint*)temp_index * percent; + } + } + } + + /* this is for the pixels in the body */ + temp0 = (const char *)datain + xindex + group_size + + (lowy_int+1)*ysize; + for (m = lowy_int+1; m < highy_int; m++) { + temp = temp0; + for(l = lowx_int+1; l < highx_int; l++) { + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += *(const GLint*)&swapbuf; + } else { + totals[k] += *(const GLint*)temp_index; + } + } + temp += group_size; + } + temp0 += ysize; + } + + outindex = (j + (i * widthout)) * components; + for (k = 0; k < components; k++) { + dataout[outindex + k] = totals[k]/area; + /*printf("totals[%d] = %f\n", k, totals[k]);*/ + } + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if(highx_float > 1) { + highx_float -= 1.0; + highx_int++; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if(highy_float > 1) { + highy_float -= 1.0; + highy_int++; + } + } +} + + + +static void scale_internal_float(GLint components, GLint widthin, + GLint heightin, const GLfloat *datain, + GLint widthout, GLint heightout, + GLfloat *dataout, GLint element_size, + GLint ysize, GLint group_size, + GLint myswap_bytes) +{ + float convx; + float convy; + float percent; + /* Max components in a format is 4, so... */ + float totals[4]; + float area; + int i,j,k,xindex; + + const char *temp, *temp0; + const char *temp_index; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + const char *left, *right; + + union { GLuint b; GLfloat f; } swapbuf; + + if (widthin == widthout*2 && heightin == heightout*2) { + halveImage_float(components, widthin, heightin, + (const GLfloat *)datain, (GLfloat *)dataout, + element_size, ysize, group_size, myswap_bytes); + return; + } + convy = (float) heightin/heightout; + convx = (float) widthin/widthout; + convy_int = floor(convy); + convy_float = convy - convy_int; + convx_int = floor(convx); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0; + highy_int = convy_int; + highy_float = convy_float; + + for (i = 0; i < heightout; i++) { + /* Clamp here to be sure we don't read beyond input buffer. */ + if (highy_int >= heightin) + highy_int = heightin - 1; + lowx_int = 0; + lowx_float = 0; + highx_int = convx_int; + highx_float = convx_float; + + for (j = 0; j < widthout; j++) { + /* + ** Ok, now apply box filter to box that goes from (lowx, lowy) + ** to (highx, highy) on input data into this pixel on output + ** data. + */ + totals[0] = totals[1] = totals[2] = totals[3] = 0.0; + + /* calculate the value for pixels in the 1st row */ + xindex = lowx_int*group_size; + if((highy_int>lowy_int) && (highx_int>lowx_int)) { + + y_percent = 1-lowy_float; + temp = (const char *)datain + xindex + lowy_int * ysize; + percent = y_percent * (1-lowx_float); + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += swapbuf.f * percent; + } else { + totals[k] += *(const GLfloat*)temp_index * percent; + } + } + left = temp; + for(l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += swapbuf.f * y_percent; + } else { + totals[k] += *(const GLfloat*)temp_index * y_percent; + } + } + } + temp += group_size; + right = temp; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += swapbuf.f * percent; + } else { + totals[k] += *(const GLfloat*)temp_index * percent; + } + } + + /* calculate the value for pixels in the last row */ + y_percent = highy_float; + percent = y_percent * (1-lowx_float); + temp = (const char *)datain + xindex + highy_int * ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += swapbuf.f * percent; + } else { + totals[k] += *(const GLfloat*)temp_index * percent; + } + } + for(l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += swapbuf.f * y_percent; + } else { + totals[k] += *(const GLfloat*)temp_index * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += swapbuf.f * percent; + } else { + totals[k] += *(const GLfloat*)temp_index * percent; + } + } + + /* calculate the value for pixels in the 1st and last column */ + for(m = lowy_int+1; m < highy_int; m++) { + left += ysize; + right += ysize; + for (k = 0; k < components; + k++, left += element_size, right += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(left); + totals[k] += swapbuf.f * (1-lowx_float); + swapbuf.b = __GLU_SWAP_4_BYTES(right); + totals[k] += swapbuf.f * highx_float; + } else { + totals[k] += *(const GLfloat*)left * (1-lowx_float) + + *(const GLfloat*)right * highx_float; + } + } + } + } else if (highy_int > lowy_int) { + x_percent = highx_float - lowx_float; + percent = (1-lowy_float)*x_percent; + temp = (const char *)datain + xindex + lowy_int*ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += swapbuf.f * percent; + } else { + totals[k] += *(const GLfloat*)temp_index * percent; + } + } + for(m = lowy_int+1; m < highy_int; m++) { + temp += ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += swapbuf.f * x_percent; + } else { + totals[k] += *(const GLfloat*)temp_index * x_percent; + } + } + } + percent = x_percent * highy_float; + temp += ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += swapbuf.f * percent; + } else { + totals[k] += *(const GLfloat*)temp_index * percent; + } + } + } else if (highx_int > lowx_int) { + y_percent = highy_float - lowy_float; + percent = (1-lowx_float)*y_percent; + + temp = (const char *)datain + xindex + lowy_int*ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += swapbuf.f * percent; + } else { + totals[k] += *(const GLfloat*)temp_index * percent; + } + } + for (l = lowx_int+1; l < highx_int; l++) { + temp += group_size; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += swapbuf.f * y_percent; + } else { + totals[k] += *(const GLfloat*)temp_index * y_percent; + } + } + } + temp += group_size; + percent = y_percent * highx_float; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += swapbuf.f * percent; + } else { + totals[k] += *(const GLfloat*)temp_index * percent; + } + } + } else { + percent = (highy_float-lowy_float)*(highx_float-lowx_float); + temp = (const char *)datain + xindex + lowy_int * ysize; + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += swapbuf.f * percent; + } else { + totals[k] += *(const GLfloat*)temp_index * percent; + } + } + } + + /* this is for the pixels in the body */ + temp0 = (const char *)datain + xindex + group_size + + (lowy_int+1)*ysize; + for (m = lowy_int+1; m < highy_int; m++) { + temp = temp0; + for(l = lowx_int+1; l < highx_int; l++) { + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + swapbuf.b = __GLU_SWAP_4_BYTES(temp_index); + totals[k] += swapbuf.f; + } else { + totals[k] += *(const GLfloat*)temp_index; + } + } + temp += group_size; + } + temp0 += ysize; + } + + outindex = (j + (i * widthout)) * components; + for (k = 0; k < components; k++) { + dataout[outindex + k] = totals[k]/area; + /*printf("totals[%d] = %f\n", k, totals[k]);*/ + } + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if(highx_float > 1) { + highx_float -= 1.0; + highx_int++; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if(highy_float > 1) { + highy_float -= 1.0; + highy_int++; + } + } +} + +static int checkMipmapArgs(GLenum internalFormat, GLenum format, GLenum type) +{ + if (!legalFormat(format) || !legalType(type)) { + return GLU_INVALID_ENUM; + } + if (format == GL_STENCIL_INDEX) { + return GLU_INVALID_ENUM; + } + + if (!isLegalFormatForPackedPixelType(format, type)) { + return GLU_INVALID_OPERATION; + } + + return 0; +} /* checkMipmapArgs() */ + +static GLboolean legalFormat(GLenum format) +{ + switch(format) { + case GL_COLOR_INDEX: + case GL_STENCIL_INDEX: + case GL_DEPTH_COMPONENT: + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_RGB: + case GL_RGBA: + case GL_LUMINANCE: + case GL_LUMINANCE_ALPHA: + case GL_BGR: + case GL_BGRA: + return GL_TRUE; + default: + return GL_FALSE; + } +} + + +static GLboolean legalType(GLenum type) +{ + switch(type) { + case GL_BITMAP: + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + return GL_TRUE; + default: + return GL_FALSE; + } +} + +/* */ +static GLboolean isTypePackedPixel(GLenum type) +{ + assert(legalType(type)); + + if (type == GL_UNSIGNED_BYTE_3_3_2 || + type == GL_UNSIGNED_BYTE_2_3_3_REV || + type == GL_UNSIGNED_SHORT_5_6_5 || + type == GL_UNSIGNED_SHORT_5_6_5_REV || + type == GL_UNSIGNED_SHORT_4_4_4_4 || + type == GL_UNSIGNED_SHORT_4_4_4_4_REV || + type == GL_UNSIGNED_SHORT_5_5_5_1 || + type == GL_UNSIGNED_SHORT_1_5_5_5_REV || + type == GL_UNSIGNED_INT_8_8_8_8 || + type == GL_UNSIGNED_INT_8_8_8_8_REV || + type == GL_UNSIGNED_INT_10_10_10_2 || + type == GL_UNSIGNED_INT_2_10_10_10_REV) { + return 1; + } + else return 0; +} /* isTypePackedPixel() */ + +/* Determines if the packed pixel type is compatible with the format */ +static GLboolean isLegalFormatForPackedPixelType(GLenum format, GLenum type) +{ + /* if not a packed pixel type then return true */ + if (!isTypePackedPixel(type)) { + return GL_TRUE; + } + + /* 3_3_2/2_3_3_REV & 5_6_5/5_6_5_REV are only compatible with RGB */ + if ((type == GL_UNSIGNED_BYTE_3_3_2 || type == GL_UNSIGNED_BYTE_2_3_3_REV|| + type == GL_UNSIGNED_SHORT_5_6_5|| type == GL_UNSIGNED_SHORT_5_6_5_REV) + && format != GL_RGB) + return GL_FALSE; + + /* 4_4_4_4/4_4_4_4_REV & 5_5_5_1/1_5_5_5_REV & 8_8_8_8/8_8_8_8_REV & + * 10_10_10_2/2_10_10_10_REV are only compatible with RGBA, BGRA & ABGR_EXT. + */ + if ((type == GL_UNSIGNED_SHORT_4_4_4_4 || + type == GL_UNSIGNED_SHORT_4_4_4_4_REV || + type == GL_UNSIGNED_SHORT_5_5_5_1 || + type == GL_UNSIGNED_SHORT_1_5_5_5_REV || + type == GL_UNSIGNED_INT_8_8_8_8 || + type == GL_UNSIGNED_INT_8_8_8_8_REV || + type == GL_UNSIGNED_INT_10_10_10_2 || + type == GL_UNSIGNED_INT_2_10_10_10_REV) && + (format != GL_RGBA && + format != GL_BGRA)) { + return GL_FALSE; + } + + return GL_TRUE; +} /* isLegalFormatForPackedPixelType() */ + +static GLboolean isLegalLevels(GLint userLevel,GLint baseLevel,GLint maxLevel, + GLint totalLevels) +{ + if (baseLevel < 0 || baseLevel < userLevel || maxLevel < baseLevel || + totalLevels < maxLevel) + return GL_FALSE; + else return GL_TRUE; +} /* isLegalLevels() */ + +/* Given user requested texture size, determine if it fits. If it + * doesn't then halve both sides and make the determination again + * until it does fit (for IR only). + * Note that proxy textures are not implemented in RE* even though + * they advertise the texture extension. + * Note that proxy textures are implemented but not according to spec in + * IMPACT*. + */ +static void closestFit(GLenum target, GLint width, GLint height, + GLint internalFormat, GLenum format, GLenum type, + GLint *newWidth, GLint *newHeight) +{ + /* Use proxy textures if OpenGL version is >= 1.1 */ + if ( (strtod((const char *)glGetString(GL_VERSION),NULL) >= 1.1) + ) { + GLint widthPowerOf2= nearestPower(width); + GLint heightPowerOf2= nearestPower(height); + GLint proxyWidth; + + do { + /* compute level 1 width & height, clamping each at 1 */ + GLint widthAtLevelOne= (widthPowerOf2 > 1) ? + widthPowerOf2 >> 1 : + widthPowerOf2; + GLint heightAtLevelOne= (heightPowerOf2 > 1) ? + heightPowerOf2 >> 1 : + heightPowerOf2; + GLenum proxyTarget; + assert(widthAtLevelOne > 0); assert(heightAtLevelOne > 0); + + /* does width x height at level 1 & all their mipmaps fit? */ + if (target == GL_TEXTURE_2D || target == GL_PROXY_TEXTURE_2D) { + proxyTarget = GL_PROXY_TEXTURE_2D; + glTexImage2D(proxyTarget, 1, /* must be non-zero */ + internalFormat, + widthAtLevelOne,heightAtLevelOne,0,format,type,NULL); + } else +#if defined(GL_ARB_texture_cube_map) + if ((target == GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB) || + (target == GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB) || + (target == GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB) || + (target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB) || + (target == GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB) || + (target == GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { + proxyTarget = GL_PROXY_TEXTURE_CUBE_MAP_ARB; + glTexImage2D(proxyTarget, 1, /* must be non-zero */ + internalFormat, + widthAtLevelOne,heightAtLevelOne,0,format,type,NULL); + } else +#endif /* GL_ARB_texture_cube_map */ + { + assert(target == GL_TEXTURE_1D || target == GL_PROXY_TEXTURE_1D); + proxyTarget = GL_PROXY_TEXTURE_1D; + glTexImage1D(proxyTarget, 1, /* must be non-zero */ + internalFormat,widthAtLevelOne,0,format,type,NULL); + } + glGetTexLevelParameteriv(proxyTarget, 1,GL_TEXTURE_WIDTH,&proxyWidth); + /* does it fit??? */ + if (proxyWidth == 0) { /* nope, so try again with these sizes */ + if (widthPowerOf2 == 1 && heightPowerOf2 == 1) { + /* An 1x1 texture couldn't fit for some reason, so + * break out. This should never happen. But things + * happen. The disadvantage with this if-statement is + * that we will never be aware of when this happens + * since it will silently branch out. + */ + goto noProxyTextures; + } + widthPowerOf2= widthAtLevelOne; + heightPowerOf2= heightAtLevelOne; + } + /* else it does fit */ + } while (proxyWidth == 0); + /* loop must terminate! */ + + /* return the width & height at level 0 that fits */ + *newWidth= widthPowerOf2; + *newHeight= heightPowerOf2; +/*printf("Proxy Textures\n");*/ + } /* if gluCheckExtension() */ + else { /* no texture extension, so do this instead */ + GLint maxsize; + +noProxyTextures: + + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxsize); + /* clamp user's texture sizes to maximum sizes, if necessary */ + *newWidth = nearestPower(width); + if (*newWidth > maxsize) *newWidth = maxsize; + *newHeight = nearestPower(height); + if (*newHeight > maxsize) *newHeight = maxsize; +/*printf("NO proxy textures\n");*/ + } +} /* closestFit() */ + +GLint GLAPIENTRY +gluScaleImage(GLenum format, GLsizei widthin, GLsizei heightin, + GLenum typein, const void *datain, + GLsizei widthout, GLsizei heightout, GLenum typeout, + void *dataout) +{ + int components; + GLushort *beforeImage; + GLushort *afterImage; + PixelStorageModes psm; + + if (widthin == 0 || heightin == 0 || widthout == 0 || heightout == 0) { + return 0; + } + if (widthin < 0 || heightin < 0 || widthout < 0 || heightout < 0) { + return GLU_INVALID_VALUE; + } + if (!legalFormat(format) || !legalType(typein) || !legalType(typeout)) { + return GLU_INVALID_ENUM; + } + if (!isLegalFormatForPackedPixelType(format, typein)) { + return GLU_INVALID_OPERATION; + } + if (!isLegalFormatForPackedPixelType(format, typeout)) { + return GLU_INVALID_OPERATION; + } + beforeImage = + malloc(image_size(widthin, heightin, format, GL_UNSIGNED_SHORT)); + afterImage = + malloc(image_size(widthout, heightout, format, GL_UNSIGNED_SHORT)); + if (beforeImage == NULL || afterImage == NULL) { + free(beforeImage); + free(afterImage); + return GLU_OUT_OF_MEMORY; + } + + retrieveStoreModes(&psm); + fill_image(&psm,widthin, heightin, format, typein, is_index(format), + datain, beforeImage); + components = elements_per_group(format, 0); + scale_internal(components, widthin, heightin, beforeImage, + widthout, heightout, afterImage); + empty_image(&psm,widthout, heightout, format, typeout, + is_index(format), afterImage, dataout); + free((GLbyte *) beforeImage); + free((GLbyte *) afterImage); + + return 0; +} + +int gluBuild1DMipmapLevelsCore(GLenum target, GLint internalFormat, + GLsizei width, + GLsizei widthPowerOf2, + GLenum format, GLenum type, + GLint userLevel, GLint baseLevel,GLint maxLevel, + const void *data) +{ + GLint newwidth; + GLint level, levels; + GLushort *newImage; + GLint newImage_width; + GLushort *otherImage; + GLushort *imageTemp; + GLint memreq; + GLint cmpts; + PixelStorageModes psm; + + assert(checkMipmapArgs(internalFormat,format,type) == 0); + assert(width >= 1); + + otherImage = NULL; + + newwidth= widthPowerOf2; + levels = computeLog(newwidth); + + levels+= userLevel; + + retrieveStoreModes(&psm); + newImage = (GLushort *) + malloc(image_size(width, 1, format, GL_UNSIGNED_SHORT)); + newImage_width = width; + if (newImage == NULL) { + return GLU_OUT_OF_MEMORY; + } + fill_image(&psm,width, 1, format, type, is_index(format), + data, newImage); + cmpts = elements_per_group(format,type); + glPixelStorei(GL_UNPACK_ALIGNMENT, 2); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + /* + ** If swap_bytes was set, swapping occurred in fill_image. + */ + glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); + + for (level = userLevel; level <= levels; level++) { + if (newImage_width == newwidth) { + /* Use newImage for this level */ + if (baseLevel <= level && level <= maxLevel) { + glTexImage1D(target, level, internalFormat, newImage_width, + 0, format, GL_UNSIGNED_SHORT, (void *) newImage); + } + } else { + if (otherImage == NULL) { + memreq = image_size(newwidth, 1, format, GL_UNSIGNED_SHORT); + otherImage = (GLushort *) malloc(memreq); + if (otherImage == NULL) { + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS,psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + free(newImage); + return GLU_OUT_OF_MEMORY; + } + } + scale_internal(cmpts, newImage_width, 1, newImage, + newwidth, 1, otherImage); + /* Swap newImage and otherImage */ + imageTemp = otherImage; + otherImage = newImage; + newImage = imageTemp; + + newImage_width = newwidth; + if (baseLevel <= level && level <= maxLevel) { + glTexImage1D(target, level, internalFormat, newImage_width, + 0, format, GL_UNSIGNED_SHORT, (void *) newImage); + } + } + if (newwidth > 1) newwidth /= 2; + } + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + + free((GLbyte *) newImage); + if (otherImage) { + free((GLbyte *) otherImage); + } + return 0; +} + +GLint GLAPIENTRY +gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, + GLsizei width, + GLenum format, GLenum type, + GLint userLevel, GLint baseLevel, GLint maxLevel, + const void *data) +{ + int levels; + + int rc= checkMipmapArgs(internalFormat,format,type); + if (rc != 0) return rc; + + if (width < 1) { + return GLU_INVALID_VALUE; + } + + levels = computeLog(width); + + levels+= userLevel; + if (!isLegalLevels(userLevel,baseLevel,maxLevel,levels)) + return GLU_INVALID_VALUE; + + return gluBuild1DMipmapLevelsCore(target, internalFormat, + width, + width,format, type, + userLevel, baseLevel, maxLevel, + data); +} /* gluBuild1DMipmapLevels() */ + +GLint GLAPIENTRY +gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, + GLenum format, GLenum type, + const void *data) +{ + GLint widthPowerOf2; + int levels; + GLint dummy; + + int rc= checkMipmapArgs(internalFormat,format,type); + if (rc != 0) return rc; + + if (width < 1) { + return GLU_INVALID_VALUE; + } + + closestFit(target,width,1,internalFormat,format,type,&widthPowerOf2,&dummy); + levels = computeLog(widthPowerOf2); + + return gluBuild1DMipmapLevelsCore(target,internalFormat, + width, + widthPowerOf2, + format,type,0,0,levels,data); +} + +static int bitmapBuild2DMipmaps(GLenum target, GLint internalFormat, + GLint width, GLint height, GLenum format, + GLenum type, const void *data) +{ + GLint newwidth, newheight; + GLint level, levels; + GLushort *newImage; + GLint newImage_width; + GLint newImage_height; + GLushort *otherImage; + GLushort *imageTemp; + GLint memreq; + GLint cmpts; + PixelStorageModes psm; + + retrieveStoreModes(&psm); + +#if 0 + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxsize); + newwidth = nearestPower(width); + if (newwidth > maxsize) newwidth = maxsize; + newheight = nearestPower(height); + if (newheight > maxsize) newheight = maxsize; +#else + closestFit(target,width,height,internalFormat,format,type, + &newwidth,&newheight); +#endif + levels = computeLog(newwidth); + level = computeLog(newheight); + if (level > levels) levels=level; + + otherImage = NULL; + newImage = (GLushort *) + malloc(image_size(width, height, format, GL_UNSIGNED_SHORT)); + newImage_width = width; + newImage_height = height; + if (newImage == NULL) { + return GLU_OUT_OF_MEMORY; + } + + fill_image(&psm,width, height, format, type, is_index(format), + data, newImage); + + cmpts = elements_per_group(format,type); + glPixelStorei(GL_UNPACK_ALIGNMENT, 2); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + /* + ** If swap_bytes was set, swapping occurred in fill_image. + */ + glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); + + for (level = 0; level <= levels; level++) { + if (newImage_width == newwidth && newImage_height == newheight) { /* Use newImage for this level */ + glTexImage2D(target, level, internalFormat, newImage_width, + newImage_height, 0, format, GL_UNSIGNED_SHORT, + (void *) newImage); + } else { + if (otherImage == NULL) { + memreq = + image_size(newwidth, newheight, format, GL_UNSIGNED_SHORT); + otherImage = (GLushort *) malloc(memreq); + if (otherImage == NULL) { + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS,psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + free(newImage); + return GLU_OUT_OF_MEMORY; + } + } + scale_internal(cmpts, newImage_width, newImage_height, newImage, + newwidth, newheight, otherImage); + /* Swap newImage and otherImage */ + imageTemp = otherImage; + otherImage = newImage; + newImage = imageTemp; + + newImage_width = newwidth; + newImage_height = newheight; + glTexImage2D(target, level, internalFormat, newImage_width, + newImage_height, 0, format, GL_UNSIGNED_SHORT, + (void *) newImage); + } + if (newwidth > 1) newwidth /= 2; + if (newheight > 1) newheight /= 2; + } + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + + free((GLbyte *) newImage); + if (otherImage) { + free((GLbyte *) otherImage); + } + return 0; +} + +/* To make swapping images less error prone */ +#define __GLU_INIT_SWAP_IMAGE void *tmpImage +#define __GLU_SWAP_IMAGE(a,b) tmpImage = a; a = b; b = tmpImage; + +static int gluBuild2DMipmapLevelsCore(GLenum target, GLint internalFormat, + GLsizei width, GLsizei height, + GLsizei widthPowerOf2, + GLsizei heightPowerOf2, + GLenum format, GLenum type, + GLint userLevel, + GLint baseLevel,GLint maxLevel, + const void *data) +{ + GLint newwidth, newheight; + GLint level, levels; + const void *usersImage; /* passed from user. Don't touch! */ + void *srcImage, *dstImage; /* scratch area to build mipmapped images */ + __GLU_INIT_SWAP_IMAGE; + GLint memreq; + GLint cmpts; + + GLint myswap_bytes, groups_per_line, element_size, group_size; + GLint rowsize, padding; + PixelStorageModes psm; + + assert(checkMipmapArgs(internalFormat,format,type) == 0); + assert(width >= 1 && height >= 1); + + if(type == GL_BITMAP) { + return bitmapBuild2DMipmaps(target, internalFormat, width, height, + format, type, data); + } + + srcImage = dstImage = NULL; + + newwidth= widthPowerOf2; + newheight= heightPowerOf2; + levels = computeLog(newwidth); + level = computeLog(newheight); + if (level > levels) levels=level; + + levels+= userLevel; + + retrieveStoreModes(&psm); + myswap_bytes = psm.unpack_swap_bytes; + cmpts = elements_per_group(format,type); + if (psm.unpack_row_length > 0) { + groups_per_line = psm.unpack_row_length; + } else { + groups_per_line = width; + } + + element_size = bytes_per_element(type); + group_size = element_size * cmpts; + if (element_size == 1) myswap_bytes = 0; + + rowsize = groups_per_line * group_size; + padding = (rowsize % psm.unpack_alignment); + if (padding) { + rowsize += psm.unpack_alignment - padding; + } + usersImage = (const GLubyte *) data + psm.unpack_skip_rows * rowsize + + psm.unpack_skip_pixels * group_size; + + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + + level = userLevel; + + /* already power-of-two square */ + if (width == newwidth && height == newheight) { + /* Use usersImage for level userLevel */ + if (baseLevel <= level && level <= maxLevel) { + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glTexImage2D(target, level, internalFormat, width, + height, 0, format, type, + usersImage); + } + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + if(levels == 0) { /* we're done. clean up and return */ + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + return 0; + } + { + int nextWidth= newwidth/2; + int nextHeight= newheight/2; + + /* clamp to 1 */ + if (nextWidth < 1) nextWidth= 1; + if (nextHeight < 1) nextHeight= 1; + memreq = image_size(nextWidth, nextHeight, format, type); + } + + switch(type) { + case GL_UNSIGNED_BYTE: + dstImage = (GLubyte *)malloc(memreq); + break; + case GL_BYTE: + dstImage = (GLbyte *)malloc(memreq); + break; + case GL_UNSIGNED_SHORT: + dstImage = (GLushort *)malloc(memreq); + break; + case GL_SHORT: + dstImage = (GLshort *)malloc(memreq); + break; + case GL_UNSIGNED_INT: + dstImage = (GLuint *)malloc(memreq); + break; + case GL_INT: + dstImage = (GLint *)malloc(memreq); + break; + case GL_FLOAT: + dstImage = (GLfloat *)malloc(memreq); + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + dstImage = (GLubyte *)malloc(memreq); + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + dstImage = (GLushort *)malloc(memreq); + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + dstImage = (GLuint *)malloc(memreq); + break; + default: + return GLU_INVALID_ENUM; + } + if (dstImage == NULL) { + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + return GLU_OUT_OF_MEMORY; + } + else + switch(type) { + case GL_UNSIGNED_BYTE: + halveImage_ubyte(cmpts, width, height, + (const GLubyte *)usersImage, (GLubyte *)dstImage, + element_size, rowsize, group_size); + break; + case GL_BYTE: + halveImage_byte(cmpts, width, height, + (const GLbyte *)usersImage, (GLbyte *)dstImage, + element_size, rowsize, group_size); + break; + case GL_UNSIGNED_SHORT: + halveImage_ushort(cmpts, width, height, + (const GLushort *)usersImage, (GLushort *)dstImage, + element_size, rowsize, group_size, myswap_bytes); + break; + case GL_SHORT: + halveImage_short(cmpts, width, height, + (const GLshort *)usersImage, (GLshort *)dstImage, + element_size, rowsize, group_size, myswap_bytes); + break; + case GL_UNSIGNED_INT: + halveImage_uint(cmpts, width, height, + (const GLuint *)usersImage, (GLuint *)dstImage, + element_size, rowsize, group_size, myswap_bytes); + break; + case GL_INT: + halveImage_int(cmpts, width, height, + (const GLint *)usersImage, (GLint *)dstImage, + element_size, rowsize, group_size, myswap_bytes); + break; + case GL_FLOAT: + halveImage_float(cmpts, width, height, + (const GLfloat *)usersImage, (GLfloat *)dstImage, + element_size, rowsize, group_size, myswap_bytes); + break; + case GL_UNSIGNED_BYTE_3_3_2: + assert(format == GL_RGB); + halveImagePackedPixel(3,extract332,shove332, + width,height,usersImage,dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_BYTE_2_3_3_REV: + assert(format == GL_RGB); + halveImagePackedPixel(3,extract233rev,shove233rev, + width,height,usersImage,dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_SHORT_5_6_5: + halveImagePackedPixel(3,extract565,shove565, + width,height,usersImage,dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_SHORT_5_6_5_REV: + halveImagePackedPixel(3,extract565rev,shove565rev, + width,height,usersImage,dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_SHORT_4_4_4_4: + halveImagePackedPixel(4,extract4444,shove4444, + width,height,usersImage,dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + halveImagePackedPixel(4,extract4444rev,shove4444rev, + width,height,usersImage,dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_SHORT_5_5_5_1: + halveImagePackedPixel(4,extract5551,shove5551, + width,height,usersImage,dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + halveImagePackedPixel(4,extract1555rev,shove1555rev, + width,height,usersImage,dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_INT_8_8_8_8: + halveImagePackedPixel(4,extract8888,shove8888, + width,height,usersImage,dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_INT_8_8_8_8_REV: + halveImagePackedPixel(4,extract8888rev,shove8888rev, + width,height,usersImage,dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_INT_10_10_10_2: + halveImagePackedPixel(4,extract1010102,shove1010102, + width,height,usersImage,dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_INT_2_10_10_10_REV: + halveImagePackedPixel(4,extract2101010rev,shove2101010rev, + width,height,usersImage,dstImage, + element_size,rowsize,myswap_bytes); + break; + default: + assert(0); + break; + } + newwidth = width/2; + newheight = height/2; + /* clamp to 1 */ + if (newwidth < 1) newwidth= 1; + if (newheight < 1) newheight= 1; + + myswap_bytes = 0; + rowsize = newwidth * group_size; + memreq = image_size(newwidth, newheight, format, type); + /* Swap srcImage and dstImage */ + __GLU_SWAP_IMAGE(srcImage,dstImage); + switch(type) { + case GL_UNSIGNED_BYTE: + dstImage = (GLubyte *)malloc(memreq); + break; + case GL_BYTE: + dstImage = (GLbyte *)malloc(memreq); + break; + case GL_UNSIGNED_SHORT: + dstImage = (GLushort *)malloc(memreq); + break; + case GL_SHORT: + dstImage = (GLshort *)malloc(memreq); + break; + case GL_UNSIGNED_INT: + dstImage = (GLuint *)malloc(memreq); + break; + case GL_INT: + dstImage = (GLint *)malloc(memreq); + break; + case GL_FLOAT: + dstImage = (GLfloat *)malloc(memreq); + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + dstImage = (GLubyte *)malloc(memreq); + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + dstImage = (GLushort *)malloc(memreq); + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + dstImage = (GLuint *)malloc(memreq); + break; + default: + return GLU_INVALID_ENUM; + } + if (dstImage == NULL) { + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + free(srcImage); + return GLU_OUT_OF_MEMORY; + } + /* level userLevel+1 is in srcImage; level userLevel already saved */ + level = userLevel+1; + } else { /* user's image is *not* nice power-of-2 sized square */ + memreq = image_size(newwidth, newheight, format, type); + switch(type) { + case GL_UNSIGNED_BYTE: + dstImage = (GLubyte *)malloc(memreq); + break; + case GL_BYTE: + dstImage = (GLbyte *)malloc(memreq); + break; + case GL_UNSIGNED_SHORT: + dstImage = (GLushort *)malloc(memreq); + break; + case GL_SHORT: + dstImage = (GLshort *)malloc(memreq); + break; + case GL_UNSIGNED_INT: + dstImage = (GLuint *)malloc(memreq); + break; + case GL_INT: + dstImage = (GLint *)malloc(memreq); + break; + case GL_FLOAT: + dstImage = (GLfloat *)malloc(memreq); + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + dstImage = (GLubyte *)malloc(memreq); + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + dstImage = (GLushort *)malloc(memreq); + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + dstImage = (GLuint *)malloc(memreq); + break; + default: + return GLU_INVALID_ENUM; + } + + if (dstImage == NULL) { + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + return GLU_OUT_OF_MEMORY; + } + + switch(type) { + case GL_UNSIGNED_BYTE: + scale_internal_ubyte(cmpts, width, height, + (const GLubyte *)usersImage, newwidth, newheight, + (GLubyte *)dstImage, element_size, + rowsize, group_size); + break; + case GL_BYTE: + scale_internal_byte(cmpts, width, height, + (const GLbyte *)usersImage, newwidth, newheight, + (GLbyte *)dstImage, element_size, + rowsize, group_size); + break; + case GL_UNSIGNED_SHORT: + scale_internal_ushort(cmpts, width, height, + (const GLushort *)usersImage, newwidth, newheight, + (GLushort *)dstImage, element_size, + rowsize, group_size, myswap_bytes); + break; + case GL_SHORT: + scale_internal_short(cmpts, width, height, + (const GLshort *)usersImage, newwidth, newheight, + (GLshort *)dstImage, element_size, + rowsize, group_size, myswap_bytes); + break; + case GL_UNSIGNED_INT: + scale_internal_uint(cmpts, width, height, + (const GLuint *)usersImage, newwidth, newheight, + (GLuint *)dstImage, element_size, + rowsize, group_size, myswap_bytes); + break; + case GL_INT: + scale_internal_int(cmpts, width, height, + (const GLint *)usersImage, newwidth, newheight, + (GLint *)dstImage, element_size, + rowsize, group_size, myswap_bytes); + break; + case GL_FLOAT: + scale_internal_float(cmpts, width, height, + (const GLfloat *)usersImage, newwidth, newheight, + (GLfloat *)dstImage, element_size, + rowsize, group_size, myswap_bytes); + break; + case GL_UNSIGNED_BYTE_3_3_2: + scaleInternalPackedPixel(3,extract332,shove332, + width, height,usersImage, + newwidth,newheight,(void *)dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_BYTE_2_3_3_REV: + scaleInternalPackedPixel(3,extract233rev,shove233rev, + width, height,usersImage, + newwidth,newheight,(void *)dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_SHORT_5_6_5: + scaleInternalPackedPixel(3,extract565,shove565, + width, height,usersImage, + newwidth,newheight,(void *)dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_SHORT_5_6_5_REV: + scaleInternalPackedPixel(3,extract565rev,shove565rev, + width, height,usersImage, + newwidth,newheight,(void *)dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_SHORT_4_4_4_4: + scaleInternalPackedPixel(4,extract4444,shove4444, + width, height,usersImage, + newwidth,newheight,(void *)dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + scaleInternalPackedPixel(4,extract4444rev,shove4444rev, + width, height,usersImage, + newwidth,newheight,(void *)dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_SHORT_5_5_5_1: + scaleInternalPackedPixel(4,extract5551,shove5551, + width, height,usersImage, + newwidth,newheight,(void *)dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + scaleInternalPackedPixel(4,extract1555rev,shove1555rev, + width, height,usersImage, + newwidth,newheight,(void *)dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_INT_8_8_8_8: + scaleInternalPackedPixel(4,extract8888,shove8888, + width, height,usersImage, + newwidth,newheight,(void *)dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_INT_8_8_8_8_REV: + scaleInternalPackedPixel(4,extract8888rev,shove8888rev, + width, height,usersImage, + newwidth,newheight,(void *)dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_INT_10_10_10_2: + scaleInternalPackedPixel(4,extract1010102,shove1010102, + width, height,usersImage, + newwidth,newheight,(void *)dstImage, + element_size,rowsize,myswap_bytes); + break; + case GL_UNSIGNED_INT_2_10_10_10_REV: + scaleInternalPackedPixel(4,extract2101010rev,shove2101010rev, + width, height,usersImage, + newwidth,newheight,(void *)dstImage, + element_size,rowsize,myswap_bytes); + break; + default: + assert(0); + break; + } + myswap_bytes = 0; + rowsize = newwidth * group_size; + /* Swap dstImage and srcImage */ + __GLU_SWAP_IMAGE(srcImage,dstImage); + + if(levels != 0) { /* use as little memory as possible */ + { + int nextWidth= newwidth/2; + int nextHeight= newheight/2; + if (nextWidth < 1) nextWidth= 1; + if (nextHeight < 1) nextHeight= 1; + + memreq = image_size(nextWidth, nextHeight, format, type); + } + + switch(type) { + case GL_UNSIGNED_BYTE: + dstImage = (GLubyte *)malloc(memreq); + break; + case GL_BYTE: + dstImage = (GLbyte *)malloc(memreq); + break; + case GL_UNSIGNED_SHORT: + dstImage = (GLushort *)malloc(memreq); + break; + case GL_SHORT: + dstImage = (GLshort *)malloc(memreq); + break; + case GL_UNSIGNED_INT: + dstImage = (GLuint *)malloc(memreq); + break; + case GL_INT: + dstImage = (GLint *)malloc(memreq); + break; + case GL_FLOAT: + dstImage = (GLfloat *)malloc(memreq); + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + dstImage = (GLubyte *)malloc(memreq); + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + dstImage = (GLushort *)malloc(memreq); + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + dstImage = (GLuint *)malloc(memreq); + break; + default: + return GLU_INVALID_ENUM; + } + if (dstImage == NULL) { + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + free(srcImage); + return GLU_OUT_OF_MEMORY; + } + } + /* level userLevel is in srcImage; nothing saved yet */ + level = userLevel; + } + + glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); + if (baseLevel <= level && level <= maxLevel) { + glTexImage2D(target, level, internalFormat, newwidth, newheight, 0, + format, type, (void *)srcImage); + } + + level++; /* update current level for the loop */ + for (; level <= levels; level++) { + switch(type) { + case GL_UNSIGNED_BYTE: + halveImage_ubyte(cmpts, newwidth, newheight, + (GLubyte *)srcImage, (GLubyte *)dstImage, element_size, + rowsize, group_size); + break; + case GL_BYTE: + halveImage_byte(cmpts, newwidth, newheight, + (GLbyte *)srcImage, (GLbyte *)dstImage, element_size, + rowsize, group_size); + break; + case GL_UNSIGNED_SHORT: + halveImage_ushort(cmpts, newwidth, newheight, + (GLushort *)srcImage, (GLushort *)dstImage, element_size, + rowsize, group_size, myswap_bytes); + break; + case GL_SHORT: + halveImage_short(cmpts, newwidth, newheight, + (GLshort *)srcImage, (GLshort *)dstImage, element_size, + rowsize, group_size, myswap_bytes); + break; + case GL_UNSIGNED_INT: + halveImage_uint(cmpts, newwidth, newheight, + (GLuint *)srcImage, (GLuint *)dstImage, element_size, + rowsize, group_size, myswap_bytes); + break; + case GL_INT: + halveImage_int(cmpts, newwidth, newheight, + (GLint *)srcImage, (GLint *)dstImage, element_size, + rowsize, group_size, myswap_bytes); + break; + case GL_FLOAT: + halveImage_float(cmpts, newwidth, newheight, + (GLfloat *)srcImage, (GLfloat *)dstImage, element_size, + rowsize, group_size, myswap_bytes); + break; + case GL_UNSIGNED_BYTE_3_3_2: + halveImagePackedPixel(3,extract332,shove332, + newwidth,newheight, + srcImage,dstImage,element_size,rowsize, + myswap_bytes); + break; + case GL_UNSIGNED_BYTE_2_3_3_REV: + halveImagePackedPixel(3,extract233rev,shove233rev, + newwidth,newheight, + srcImage,dstImage,element_size,rowsize, + myswap_bytes); + break; + case GL_UNSIGNED_SHORT_5_6_5: + halveImagePackedPixel(3,extract565,shove565, + newwidth,newheight, + srcImage,dstImage,element_size,rowsize, + myswap_bytes); + break; + case GL_UNSIGNED_SHORT_5_6_5_REV: + halveImagePackedPixel(3,extract565rev,shove565rev, + newwidth,newheight, + srcImage,dstImage,element_size,rowsize, + myswap_bytes); + break; + case GL_UNSIGNED_SHORT_4_4_4_4: + halveImagePackedPixel(4,extract4444,shove4444, + newwidth,newheight, + srcImage,dstImage,element_size,rowsize, + myswap_bytes); + break; + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + halveImagePackedPixel(4,extract4444rev,shove4444rev, + newwidth,newheight, + srcImage,dstImage,element_size,rowsize, + myswap_bytes); + break; + case GL_UNSIGNED_SHORT_5_5_5_1: + halveImagePackedPixel(4,extract5551,shove5551, + newwidth,newheight, + srcImage,dstImage,element_size,rowsize, + myswap_bytes); + break; + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + halveImagePackedPixel(4,extract1555rev,shove1555rev, + newwidth,newheight, + srcImage,dstImage,element_size,rowsize, + myswap_bytes); + break; + case GL_UNSIGNED_INT_8_8_8_8: + halveImagePackedPixel(4,extract8888,shove8888, + newwidth,newheight, + srcImage,dstImage,element_size,rowsize, + myswap_bytes); + break; + case GL_UNSIGNED_INT_8_8_8_8_REV: + halveImagePackedPixel(4,extract8888rev,shove8888rev, + newwidth,newheight, + srcImage,dstImage,element_size,rowsize, + myswap_bytes); + break; + case GL_UNSIGNED_INT_10_10_10_2: + halveImagePackedPixel(4,extract1010102,shove1010102, + newwidth,newheight, + srcImage,dstImage,element_size,rowsize, + myswap_bytes); + break; + case GL_UNSIGNED_INT_2_10_10_10_REV: + halveImagePackedPixel(4,extract2101010rev,shove2101010rev, + newwidth,newheight, + srcImage,dstImage,element_size,rowsize, + myswap_bytes); + break; + default: + assert(0); + break; + } + + __GLU_SWAP_IMAGE(srcImage,dstImage); + + if (newwidth > 1) { newwidth /= 2; rowsize /= 2;} + if (newheight > 1) newheight /= 2; + { + /* compute amount to pad per row, if any */ + int rowPad= rowsize % psm.unpack_alignment; + + /* should row be padded? */ + if (rowPad == 0) { /* nope, row should not be padded */ + /* call tex image with srcImage untouched since it's not padded */ + if (baseLevel <= level && level <= maxLevel) { + glTexImage2D(target, level, internalFormat, newwidth, newheight, 0, + format, type, (void *) srcImage); + } + } + else { /* yes, row should be padded */ + /* compute length of new row in bytes, including padding */ + int newRowLength= rowsize + psm.unpack_alignment - rowPad; + int ii; unsigned char *dstTrav, *srcTrav; /* indices for copying */ + + /* allocate new image for mipmap of size newRowLength x newheight */ + void *newMipmapImage= malloc((size_t) (newRowLength*newheight)); + if (newMipmapImage == NULL) { + /* out of memory so return */ + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + return GLU_OUT_OF_MEMORY; + } + + /* copy image from srcImage into newMipmapImage by rows */ + for (ii= 0, + dstTrav= (unsigned char *) newMipmapImage, + srcTrav= (unsigned char *) srcImage; + ii< newheight; + ii++, + dstTrav+= newRowLength, /* make sure the correct distance... */ + srcTrav+= rowsize) { /* ...is skipped */ + memcpy(dstTrav,srcTrav,rowsize); + /* note that the pad bytes are not visited and will contain + * garbage, which is ok. + */ + } + + /* ...and use this new image for mipmapping instead */ + if (baseLevel <= level && level <= maxLevel) { + glTexImage2D(target, level, internalFormat, newwidth, newheight, 0, + format, type, newMipmapImage); + } + free(newMipmapImage); /* don't forget to free it! */ + } /* else */ + } + } /* for level */ + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + + free(srcImage); /*if you get to here, a srcImage has always been malloc'ed*/ + if (dstImage) { /* if it's non-rectangular and only 1 level */ + free(dstImage); + } + return 0; +} /* gluBuild2DMipmapLevelsCore() */ + +GLint GLAPIENTRY +gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + GLint userLevel, GLint baseLevel, GLint maxLevel, + const void *data) +{ + int level, levels; + + int rc= checkMipmapArgs(internalFormat,format,type); + if (rc != 0) return rc; + + if (width < 1 || height < 1) { + return GLU_INVALID_VALUE; + } + + levels = computeLog(width); + level = computeLog(height); + if (level > levels) levels=level; + + levels+= userLevel; + if (!isLegalLevels(userLevel,baseLevel,maxLevel,levels)) + return GLU_INVALID_VALUE; + + return gluBuild2DMipmapLevelsCore(target, internalFormat, + width, height, + width, height, + format, type, + userLevel, baseLevel, maxLevel, + data); +} /* gluBuild2DMipmapLevels() */ + +GLint GLAPIENTRY +gluBuild2DMipmaps(GLenum target, GLint internalFormat, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const void *data) +{ + GLint widthPowerOf2, heightPowerOf2; + int level, levels; + + int rc= checkMipmapArgs(internalFormat,format,type); + if (rc != 0) return rc; + + if (width < 1 || height < 1) { + return GLU_INVALID_VALUE; + } + + closestFit(target,width,height,internalFormat,format,type, + &widthPowerOf2,&heightPowerOf2); + + levels = computeLog(widthPowerOf2); + level = computeLog(heightPowerOf2); + if (level > levels) levels=level; + + return gluBuild2DMipmapLevelsCore(target,internalFormat, + width, height, + widthPowerOf2,heightPowerOf2, + format,type, + 0,0,levels,data); +} /* gluBuild2DMipmaps() */ + +#if 0 +/* +** This routine is for the limited case in which +** type == GL_UNSIGNED_BYTE && format != index && +** unpack_alignment = 1 && unpack_swap_bytes == false +** +** so all of the work data can be kept as ubytes instead of shorts. +*/ +static int fastBuild2DMipmaps(const PixelStorageModes *psm, + GLenum target, GLint components, GLint width, + GLint height, GLenum format, + GLenum type, void *data) +{ + GLint newwidth, newheight; + GLint level, levels; + GLubyte *newImage; + GLint newImage_width; + GLint newImage_height; + GLubyte *otherImage; + GLubyte *imageTemp; + GLint memreq; + GLint cmpts; + + +#if 0 + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxsize); + newwidth = nearestPower(width); + if (newwidth > maxsize) newwidth = maxsize; + newheight = nearestPower(height); + if (newheight > maxsize) newheight = maxsize; +#else + closestFit(target,width,height,components,format,type, + &newwidth,&newheight); +#endif + levels = computeLog(newwidth); + level = computeLog(newheight); + if (level > levels) levels=level; + + cmpts = elements_per_group(format,type); + + otherImage = NULL; + /** + ** No need to copy the user data if its in the packed correctly. + ** Make sure that later routines don't change that data. + */ + if (psm->unpack_skip_rows == 0 && psm->unpack_skip_pixels == 0) { + newImage = (GLubyte *)data; + newImage_width = width; + newImage_height = height; + } else { + GLint rowsize; + GLint groups_per_line; + GLint elements_per_line; + const GLubyte *start; + const GLubyte *iter; + GLubyte *iter2; + GLint i, j; + + newImage = (GLubyte *) + malloc(image_size(width, height, format, GL_UNSIGNED_BYTE)); + newImage_width = width; + newImage_height = height; + if (newImage == NULL) { + return GLU_OUT_OF_MEMORY; + } + + /* + ** Abbreviated version of fill_image for this restricted case. + */ + if (psm->unpack_row_length > 0) { + groups_per_line = psm->unpack_row_length; + } else { + groups_per_line = width; + } + rowsize = groups_per_line * cmpts; + elements_per_line = width * cmpts; + start = (const GLubyte *) data + psm->unpack_skip_rows * rowsize + + psm->unpack_skip_pixels * cmpts; + iter2 = newImage; + + for (i = 0; i < height; i++) { + iter = start; + for (j = 0; j < elements_per_line; j++) { + *iter2 = *iter; + iter++; + iter2++; + } + start += rowsize; + } + } + + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); + + for (level = 0; level <= levels; level++) { + if (newImage_width == newwidth && newImage_height == newheight) { + /* Use newImage for this level */ + glTexImage2D(target, level, components, newImage_width, + newImage_height, 0, format, GL_UNSIGNED_BYTE, + (void *) newImage); + } else { + if (otherImage == NULL) { + memreq = + image_size(newwidth, newheight, format, GL_UNSIGNED_BYTE); + otherImage = (GLubyte *) malloc(memreq); + if (otherImage == NULL) { + glPixelStorei(GL_UNPACK_ALIGNMENT, psm->unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm->unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm->unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH,psm->unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES,psm->unpack_swap_bytes); + return GLU_OUT_OF_MEMORY; + } + } +/* + scale_internal_ubyte(cmpts, newImage_width, newImage_height, + newImage, newwidth, newheight, otherImage); +*/ + /* Swap newImage and otherImage */ + imageTemp = otherImage; + otherImage = newImage; + newImage = imageTemp; + + newImage_width = newwidth; + newImage_height = newheight; + glTexImage2D(target, level, components, newImage_width, + newImage_height, 0, format, GL_UNSIGNED_BYTE, + (void *) newImage); + } + if (newwidth > 1) newwidth /= 2; + if (newheight > 1) newheight /= 2; + } + glPixelStorei(GL_UNPACK_ALIGNMENT, psm->unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm->unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm->unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm->unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm->unpack_swap_bytes); + + if (newImage != (const GLubyte *)data) { + free((GLbyte *) newImage); + } + if (otherImage && otherImage != (const GLubyte *)data) { + free((GLbyte *) otherImage); + } + return 0; +} +#endif + +/* + * Utility Routines + */ +static GLint elements_per_group(GLenum format, GLenum type) +{ + /* + * Return the number of elements per group of a specified format + */ + + /* If the type is packedpixels then answer is 1 (ignore format) */ + if (type == GL_UNSIGNED_BYTE_3_3_2 || + type == GL_UNSIGNED_BYTE_2_3_3_REV || + type == GL_UNSIGNED_SHORT_5_6_5 || + type == GL_UNSIGNED_SHORT_5_6_5_REV || + type == GL_UNSIGNED_SHORT_4_4_4_4 || + type == GL_UNSIGNED_SHORT_4_4_4_4_REV || + type == GL_UNSIGNED_SHORT_5_5_5_1 || + type == GL_UNSIGNED_SHORT_1_5_5_5_REV || + type == GL_UNSIGNED_INT_8_8_8_8 || + type == GL_UNSIGNED_INT_8_8_8_8_REV || + type == GL_UNSIGNED_INT_10_10_10_2 || + type == GL_UNSIGNED_INT_2_10_10_10_REV) { + return 1; + } + + /* Types are not packed pixels, so get elements per group */ + switch(format) { + case GL_RGB: + case GL_BGR: + return 3; + case GL_LUMINANCE_ALPHA: + return 2; + case GL_RGBA: + case GL_BGRA: + return 4; + default: + return 1; + } +} + +static GLfloat bytes_per_element(GLenum type) +{ + /* + * Return the number of bytes per element, based on the element type + */ + switch(type) { + case GL_BITMAP: + return 1.0 / 8.0; + case GL_UNSIGNED_SHORT: + return(sizeof(GLushort)); + case GL_SHORT: + return(sizeof(GLshort)); + case GL_UNSIGNED_BYTE: + return(sizeof(GLubyte)); + case GL_BYTE: + return(sizeof(GLbyte)); + case GL_INT: + return(sizeof(GLint)); + case GL_UNSIGNED_INT: + return(sizeof(GLuint)); + case GL_FLOAT: + return(sizeof(GLfloat)); + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + return(sizeof(GLubyte)); + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + return(sizeof(GLushort)); + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + return(sizeof(GLuint)); + default: + return 4; + } +} + +static GLint is_index(GLenum format) +{ + return format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX; +} + +/* +** Compute memory required for internal packed array of data of given type +** and format. +*/ +static GLint image_size(GLint width, GLint height, GLenum format, GLenum type) +{ + int bytes_per_row; + int components; + +assert(width > 0); +assert(height > 0); + components = elements_per_group(format,type); + if (type == GL_BITMAP) { + bytes_per_row = (width + 7) / 8; + } else { + bytes_per_row = bytes_per_element(type) * width; + } + return bytes_per_row * height * components; +} + +/* +** Extract array from user's data applying all pixel store modes. +** The internal format used is an array of unsigned shorts. +*/ +static void fill_image(const PixelStorageModes *psm, + GLint width, GLint height, GLenum format, + GLenum type, GLboolean index_format, + const void *userdata, GLushort *newimage) +{ + GLint components; + GLint element_size; + GLint rowsize; + GLint padding; + GLint groups_per_line; + GLint group_size; + GLint elements_per_line; + const GLubyte *start; + const GLubyte *iter; + GLushort *iter2; + GLint i, j, k; + GLint myswap_bytes; + + myswap_bytes = psm->unpack_swap_bytes; + components = elements_per_group(format,type); + if (psm->unpack_row_length > 0) { + groups_per_line = psm->unpack_row_length; + } else { + groups_per_line = width; + } + + /* All formats except GL_BITMAP fall out trivially */ + if (type == GL_BITMAP) { + GLint bit_offset; + GLint current_bit; + + rowsize = (groups_per_line * components + 7) / 8; + padding = (rowsize % psm->unpack_alignment); + if (padding) { + rowsize += psm->unpack_alignment - padding; + } + start = (const GLubyte *) userdata + psm->unpack_skip_rows * rowsize + + (psm->unpack_skip_pixels * components / 8); + elements_per_line = width * components; + iter2 = newimage; + for (i = 0; i < height; i++) { + iter = start; + bit_offset = (psm->unpack_skip_pixels * components) % 8; + for (j = 0; j < elements_per_line; j++) { + /* Retrieve bit */ + if (psm->unpack_lsb_first) { + current_bit = iter[0] & (1 << bit_offset); + } else { + current_bit = iter[0] & (1 << (7 - bit_offset)); + } + if (current_bit) { + if (index_format) { + *iter2 = 1; + } else { + *iter2 = 65535; + } + } else { + *iter2 = 0; + } + bit_offset++; + if (bit_offset == 8) { + bit_offset = 0; + iter++; + } + iter2++; + } + start += rowsize; + } + } else { + element_size = bytes_per_element(type); + group_size = element_size * components; + if (element_size == 1) myswap_bytes = 0; + + rowsize = groups_per_line * group_size; + padding = (rowsize % psm->unpack_alignment); + if (padding) { + rowsize += psm->unpack_alignment - padding; + } + start = (const GLubyte *) userdata + psm->unpack_skip_rows * rowsize + + psm->unpack_skip_pixels * group_size; + elements_per_line = width * components; + + iter2 = newimage; + for (i = 0; i < height; i++) { + iter = start; + for (j = 0; j < elements_per_line; j++) { + Type_Widget widget; + float extractComponents[4]; + + switch(type) { + case GL_UNSIGNED_BYTE_3_3_2: + extract332(0,iter,extractComponents); + for (k = 0; k < 3; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_BYTE_2_3_3_REV: + extract233rev(0,iter,extractComponents); + for (k = 0; k < 3; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_BYTE: + if (index_format) { + *iter2++ = *iter; + } else { + *iter2++ = (*iter) * 257; + } + break; + case GL_BYTE: + if (index_format) { + *iter2++ = *((const GLbyte *) iter); + } else { + /* rough approx */ + *iter2++ = (*((const GLbyte *) iter)) * 516; + } + break; + case GL_UNSIGNED_SHORT_5_6_5: + extract565(myswap_bytes,iter,extractComponents); + for (k = 0; k < 3; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_SHORT_5_6_5_REV: + extract565rev(myswap_bytes,iter,extractComponents); + for (k = 0; k < 3; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_SHORT_4_4_4_4: + extract4444(myswap_bytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + extract4444rev(myswap_bytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_SHORT_5_5_5_1: + extract5551(myswap_bytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + extract1555rev(myswap_bytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_SHORT: + case GL_SHORT: + if (myswap_bytes) { + widget.ub[0] = iter[1]; + widget.ub[1] = iter[0]; + } else { + widget.ub[0] = iter[0]; + widget.ub[1] = iter[1]; + } + if (type == GL_SHORT) { + if (index_format) { + *iter2++ = widget.s[0]; + } else { + /* rough approx */ + *iter2++ = widget.s[0]*2; + } + } else { + *iter2++ = widget.us[0]; + } + break; + case GL_UNSIGNED_INT_8_8_8_8: + extract8888(myswap_bytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_INT_8_8_8_8_REV: + extract8888rev(myswap_bytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_INT_10_10_10_2: + extract1010102(myswap_bytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_INT_2_10_10_10_REV: + extract2101010rev(myswap_bytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + if (myswap_bytes) { + widget.ub[0] = iter[3]; + widget.ub[1] = iter[2]; + widget.ub[2] = iter[1]; + widget.ub[3] = iter[0]; + } else { + widget.ub[0] = iter[0]; + widget.ub[1] = iter[1]; + widget.ub[2] = iter[2]; + widget.ub[3] = iter[3]; + } + if (type == GL_FLOAT) { + if (index_format) { + *iter2++ = widget.f; + } else { + *iter2++ = 65535 * widget.f; + } + } else if (type == GL_UNSIGNED_INT) { + if (index_format) { + *iter2++ = widget.ui; + } else { + *iter2++ = widget.ui >> 16; + } + } else { + if (index_format) { + *iter2++ = widget.i; + } else { + *iter2++ = widget.i >> 15; + } + } + break; + } + iter += element_size; + } /* for j */ + start += rowsize; +#if 1 + /* want 'iter' pointing at start, not within, row for assertion + * purposes + */ + iter= start; +#endif + } /* for i */ + + /* iterators should be one byte past end */ + if (!isTypePackedPixel(type)) { + assert(iter2 == &newimage[width*height*components]); + } + else { + assert(iter2 == &newimage[width*height* + elements_per_group(format,0)]); + } + assert( iter == &((const GLubyte *)userdata)[rowsize*height + + psm->unpack_skip_rows * rowsize + + psm->unpack_skip_pixels * group_size] ); + + } /* else */ +} /* fill_image() */ + +/* +** Insert array into user's data applying all pixel store modes. +** The internal format is an array of unsigned shorts. +** empty_image() because it is the opposite of fill_image(). +*/ +static void empty_image(const PixelStorageModes *psm, + GLint width, GLint height, GLenum format, + GLenum type, GLboolean index_format, + const GLushort *oldimage, void *userdata) +{ + GLint components; + GLint element_size; + GLint rowsize; + GLint padding; + GLint groups_per_line; + GLint group_size; + GLint elements_per_line; + GLubyte *start; + GLubyte *iter; + const GLushort *iter2; + GLint i, j, k; + GLint myswap_bytes; + + myswap_bytes = psm->pack_swap_bytes; + components = elements_per_group(format,type); + if (psm->pack_row_length > 0) { + groups_per_line = psm->pack_row_length; + } else { + groups_per_line = width; + } + + /* All formats except GL_BITMAP fall out trivially */ + if (type == GL_BITMAP) { + GLint bit_offset; + GLint current_bit; + + rowsize = (groups_per_line * components + 7) / 8; + padding = (rowsize % psm->pack_alignment); + if (padding) { + rowsize += psm->pack_alignment - padding; + } + start = (GLubyte *) userdata + psm->pack_skip_rows * rowsize + + (psm->pack_skip_pixels * components / 8); + elements_per_line = width * components; + iter2 = oldimage; + for (i = 0; i < height; i++) { + iter = start; + bit_offset = (psm->pack_skip_pixels * components) % 8; + for (j = 0; j < elements_per_line; j++) { + if (index_format) { + current_bit = iter2[0] & 1; + } else { + if (iter2[0] > 32767) { + current_bit = 1; + } else { + current_bit = 0; + } + } + + if (current_bit) { + if (psm->pack_lsb_first) { + *iter |= (1 << bit_offset); + } else { + *iter |= (1 << (7 - bit_offset)); + } + } else { + if (psm->pack_lsb_first) { + *iter &= ~(1 << bit_offset); + } else { + *iter &= ~(1 << (7 - bit_offset)); + } + } + + bit_offset++; + if (bit_offset == 8) { + bit_offset = 0; + iter++; + } + iter2++; + } + start += rowsize; + } + } else { + float shoveComponents[4]; + + element_size = bytes_per_element(type); + group_size = element_size * components; + if (element_size == 1) myswap_bytes = 0; + + rowsize = groups_per_line * group_size; + padding = (rowsize % psm->pack_alignment); + if (padding) { + rowsize += psm->pack_alignment - padding; + } + start = (GLubyte *) userdata + psm->pack_skip_rows * rowsize + + psm->pack_skip_pixels * group_size; + elements_per_line = width * components; + + iter2 = oldimage; + for (i = 0; i < height; i++) { + iter = start; + for (j = 0; j < elements_per_line; j++) { + Type_Widget widget; + + switch(type) { + case GL_UNSIGNED_BYTE_3_3_2: + for (k = 0; k < 3; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove332(shoveComponents,0,(void *)iter); + break; + case GL_UNSIGNED_BYTE_2_3_3_REV: + for (k = 0; k < 3; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove233rev(shoveComponents,0,(void *)iter); + break; + case GL_UNSIGNED_BYTE: + if (index_format) { + *iter = *iter2++; + } else { + *iter = *iter2++ >> 8; + } + break; + case GL_BYTE: + if (index_format) { + *((GLbyte *) iter) = *iter2++; + } else { + *((GLbyte *) iter) = *iter2++ >> 9; + } + break; + case GL_UNSIGNED_SHORT_5_6_5: + for (k = 0; k < 3; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove565(shoveComponents,0,(void *)&widget.us[0]); + if (myswap_bytes) { + iter[0] = widget.ub[1]; + iter[1] = widget.ub[0]; + } + else { + *(GLushort *)iter = widget.us[0]; + } + break; + case GL_UNSIGNED_SHORT_5_6_5_REV: + for (k = 0; k < 3; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove565rev(shoveComponents,0,(void *)&widget.us[0]); + if (myswap_bytes) { + iter[0] = widget.ub[1]; + iter[1] = widget.ub[0]; + } + else { + *(GLushort *)iter = widget.us[0]; + } + break; + case GL_UNSIGNED_SHORT_4_4_4_4: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove4444(shoveComponents,0,(void *)&widget.us[0]); + if (myswap_bytes) { + iter[0] = widget.ub[1]; + iter[1] = widget.ub[0]; + } else { + *(GLushort *)iter = widget.us[0]; + } + break; + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove4444rev(shoveComponents,0,(void *)&widget.us[0]); + if (myswap_bytes) { + iter[0] = widget.ub[1]; + iter[1] = widget.ub[0]; + } else { + *(GLushort *)iter = widget.us[0]; + } + break; + case GL_UNSIGNED_SHORT_5_5_5_1: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove5551(shoveComponents,0,(void *)&widget.us[0]); + if (myswap_bytes) { + iter[0] = widget.ub[1]; + iter[1] = widget.ub[0]; + } else { + *(GLushort *)iter = widget.us[0]; + } + break; + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove1555rev(shoveComponents,0,(void *)&widget.us[0]); + if (myswap_bytes) { + iter[0] = widget.ub[1]; + iter[1] = widget.ub[0]; + } else { + *(GLushort *)iter = widget.us[0]; + } + break; + case GL_UNSIGNED_SHORT: + case GL_SHORT: + if (type == GL_SHORT) { + if (index_format) { + widget.s[0] = *iter2++; + } else { + widget.s[0] = *iter2++ >> 1; + } + } else { + widget.us[0] = *iter2++; + } + if (myswap_bytes) { + iter[0] = widget.ub[1]; + iter[1] = widget.ub[0]; + } else { + iter[0] = widget.ub[0]; + iter[1] = widget.ub[1]; + } + break; + case GL_UNSIGNED_INT_8_8_8_8: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove8888(shoveComponents,0,(void *)&widget.ui); + if (myswap_bytes) { + iter[3] = widget.ub[0]; + iter[2] = widget.ub[1]; + iter[1] = widget.ub[2]; + iter[0] = widget.ub[3]; + } else { + *(GLuint *)iter= widget.ui; + } + + break; + case GL_UNSIGNED_INT_8_8_8_8_REV: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove8888rev(shoveComponents,0,(void *)&widget.ui); + if (myswap_bytes) { + iter[3] = widget.ub[0]; + iter[2] = widget.ub[1]; + iter[1] = widget.ub[2]; + iter[0] = widget.ub[3]; + } else { + *(GLuint *)iter= widget.ui; + } + break; + case GL_UNSIGNED_INT_10_10_10_2: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove1010102(shoveComponents,0,(void *)&widget.ui); + if (myswap_bytes) { + iter[3] = widget.ub[0]; + iter[2] = widget.ub[1]; + iter[1] = widget.ub[2]; + iter[0] = widget.ub[3]; + } else { + *(GLuint *)iter= widget.ui; + } + break; + case GL_UNSIGNED_INT_2_10_10_10_REV: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove2101010rev(shoveComponents,0,(void *)&widget.ui); + if (myswap_bytes) { + iter[3] = widget.ub[0]; + iter[2] = widget.ub[1]; + iter[1] = widget.ub[2]; + iter[0] = widget.ub[3]; + } else { + *(GLuint *)iter= widget.ui; + } + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + if (type == GL_FLOAT) { + if (index_format) { + widget.f = *iter2++; + } else { + widget.f = *iter2++ / (float) 65535.0; + } + } else if (type == GL_UNSIGNED_INT) { + if (index_format) { + widget.ui = *iter2++; + } else { + widget.ui = (unsigned int) *iter2++ * 65537; + } + } else { + if (index_format) { + widget.i = *iter2++; + } else { + widget.i = ((unsigned int) *iter2++ * 65537)/2; + } + } + if (myswap_bytes) { + iter[3] = widget.ub[0]; + iter[2] = widget.ub[1]; + iter[1] = widget.ub[2]; + iter[0] = widget.ub[3]; + } else { + iter[0] = widget.ub[0]; + iter[1] = widget.ub[1]; + iter[2] = widget.ub[2]; + iter[3] = widget.ub[3]; + } + break; + } + iter += element_size; + } /* for j */ + start += rowsize; +#if 1 + /* want 'iter' pointing at start, not within, row for assertion + * purposes + */ + iter= start; +#endif + } /* for i */ + + /* iterators should be one byte past end */ + if (!isTypePackedPixel(type)) { + assert(iter2 == &oldimage[width*height*components]); + } + else { + assert(iter2 == &oldimage[width*height* + elements_per_group(format,0)]); + } + assert( iter == &((GLubyte *)userdata)[rowsize*height + + psm->pack_skip_rows * rowsize + + psm->pack_skip_pixels * group_size] ); + + } /* else */ +} /* empty_image() */ + +/*-------------------------------------------------------------------------- + * Decimation of packed pixel types + *-------------------------------------------------------------------------- + */ +static void extract332(int isSwap, + const void *packedPixel, GLfloat extractComponents[]) +{ + GLubyte ubyte= *(const GLubyte *)packedPixel; + + isSwap= isSwap; /* turn off warnings */ + + /* 11100000 == 0xe0 */ + /* 00011100 == 0x1c */ + /* 00000011 == 0x03 */ + + extractComponents[0]= (float)((ubyte & 0xe0) >> 5) / 7.0; + extractComponents[1]= (float)((ubyte & 0x1c) >> 2) / 7.0; /* 7 = 2^3-1 */ + extractComponents[2]= (float)((ubyte & 0x03) ) / 3.0; /* 3 = 2^2-1 */ +} /* extract332() */ + +static void shove332(const GLfloat shoveComponents[], + int index, void *packedPixel) +{ + /* 11100000 == 0xe0 */ + /* 00011100 == 0x1c */ + /* 00000011 == 0x03 */ + + assert(0.0 <= shoveComponents[0] && shoveComponents[0] <= 1.0); + assert(0.0 <= shoveComponents[1] && shoveComponents[1] <= 1.0); + assert(0.0 <= shoveComponents[2] && shoveComponents[2] <= 1.0); + + /* due to limited precision, need to round before shoving */ + ((GLubyte *)packedPixel)[index] = + ((GLubyte)((shoveComponents[0] * 7)+0.5) << 5) & 0xe0; + ((GLubyte *)packedPixel)[index] |= + ((GLubyte)((shoveComponents[1] * 7)+0.5) << 2) & 0x1c; + ((GLubyte *)packedPixel)[index] |= + ((GLubyte)((shoveComponents[2] * 3)+0.5) ) & 0x03; +} /* shove332() */ + +static void extract233rev(int isSwap, + const void *packedPixel, GLfloat extractComponents[]) +{ + GLubyte ubyte= *(const GLubyte *)packedPixel; + + isSwap= isSwap; /* turn off warnings */ + + /* 0000,0111 == 0x07 */ + /* 0011,1000 == 0x38 */ + /* 1100,0000 == 0xC0 */ + + extractComponents[0]= (float)((ubyte & 0x07) ) / 7.0; + extractComponents[1]= (float)((ubyte & 0x38) >> 3) / 7.0; + extractComponents[2]= (float)((ubyte & 0xC0) >> 6) / 3.0; +} /* extract233rev() */ + +static void shove233rev(const GLfloat shoveComponents[], + int index, void *packedPixel) +{ + /* 0000,0111 == 0x07 */ + /* 0011,1000 == 0x38 */ + /* 1100,0000 == 0xC0 */ + + assert(0.0 <= shoveComponents[0] && shoveComponents[0] <= 1.0); + assert(0.0 <= shoveComponents[1] && shoveComponents[1] <= 1.0); + assert(0.0 <= shoveComponents[2] && shoveComponents[2] <= 1.0); + + /* due to limited precision, need to round before shoving */ + ((GLubyte *)packedPixel)[index] = + ((GLubyte)((shoveComponents[0] * 7.0)+0.5) ) & 0x07; + ((GLubyte *)packedPixel)[index]|= + ((GLubyte)((shoveComponents[1] * 7.0)+0.5) << 3) & 0x38; + ((GLubyte *)packedPixel)[index]|= + ((GLubyte)((shoveComponents[2] * 3.0)+0.5) << 6) & 0xC0; +} /* shove233rev() */ + +static void extract565(int isSwap, + const void *packedPixel, GLfloat extractComponents[]) +{ + GLushort ushort; + + if (isSwap) { + ushort= __GLU_SWAP_2_BYTES(packedPixel); + } + else { + ushort= *(const GLushort *)packedPixel; + } + + /* 11111000,00000000 == 0xf800 */ + /* 00000111,11100000 == 0x07e0 */ + /* 00000000,00011111 == 0x001f */ + + extractComponents[0]=(float)((ushort & 0xf800) >> 11) / 31.0;/* 31 = 2^5-1*/ + extractComponents[1]=(float)((ushort & 0x07e0) >> 5) / 63.0;/* 63 = 2^6-1*/ + extractComponents[2]=(float)((ushort & 0x001f) ) / 31.0; +} /* extract565() */ + +static void shove565(const GLfloat shoveComponents[], + int index,void *packedPixel) +{ + /* 11111000,00000000 == 0xf800 */ + /* 00000111,11100000 == 0x07e0 */ + /* 00000000,00011111 == 0x001f */ + + assert(0.0 <= shoveComponents[0] && shoveComponents[0] <= 1.0); + assert(0.0 <= shoveComponents[1] && shoveComponents[1] <= 1.0); + assert(0.0 <= shoveComponents[2] && shoveComponents[2] <= 1.0); + + /* due to limited precision, need to round before shoving */ + ((GLushort *)packedPixel)[index] = + ((GLushort)((shoveComponents[0] * 31)+0.5) << 11) & 0xf800; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[1] * 63)+0.5) << 5) & 0x07e0; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[2] * 31)+0.5) ) & 0x001f; +} /* shove565() */ + +static void extract565rev(int isSwap, + const void *packedPixel, GLfloat extractComponents[]) +{ + GLushort ushort; + + if (isSwap) { + ushort= __GLU_SWAP_2_BYTES(packedPixel); + } + else { + ushort= *(const GLushort *)packedPixel; + } + + /* 00000000,00011111 == 0x001f */ + /* 00000111,11100000 == 0x07e0 */ + /* 11111000,00000000 == 0xf800 */ + + extractComponents[0]= (float)((ushort & 0x001F) ) / 31.0; + extractComponents[1]= (float)((ushort & 0x07E0) >> 5) / 63.0; + extractComponents[2]= (float)((ushort & 0xF800) >> 11) / 31.0; +} /* extract565rev() */ + +static void shove565rev(const GLfloat shoveComponents[], + int index,void *packedPixel) +{ + /* 00000000,00011111 == 0x001f */ + /* 00000111,11100000 == 0x07e0 */ + /* 11111000,00000000 == 0xf800 */ + + assert(0.0 <= shoveComponents[0] && shoveComponents[0] <= 1.0); + assert(0.0 <= shoveComponents[1] && shoveComponents[1] <= 1.0); + assert(0.0 <= shoveComponents[2] && shoveComponents[2] <= 1.0); + + /* due to limited precision, need to round before shoving */ + ((GLushort *)packedPixel)[index] = + ((GLushort)((shoveComponents[0] * 31.0)+0.5) ) & 0x001F; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[1] * 63.0)+0.5) << 5) & 0x07E0; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[2] * 31.0)+0.5) << 11) & 0xF800; +} /* shove565rev() */ + +static void extract4444(int isSwap,const void *packedPixel, + GLfloat extractComponents[]) +{ + GLushort ushort; + + if (isSwap) { + ushort= __GLU_SWAP_2_BYTES(packedPixel); + } + else { + ushort= *(const GLushort *)packedPixel; + } + + /* 11110000,00000000 == 0xf000 */ + /* 00001111,00000000 == 0x0f00 */ + /* 00000000,11110000 == 0x00f0 */ + /* 00000000,00001111 == 0x000f */ + + extractComponents[0]= (float)((ushort & 0xf000) >> 12) / 15.0;/* 15=2^4-1 */ + extractComponents[1]= (float)((ushort & 0x0f00) >> 8) / 15.0; + extractComponents[2]= (float)((ushort & 0x00f0) >> 4) / 15.0; + extractComponents[3]= (float)((ushort & 0x000f) ) / 15.0; +} /* extract4444() */ + +static void shove4444(const GLfloat shoveComponents[], + int index,void *packedPixel) +{ + assert(0.0 <= shoveComponents[0] && shoveComponents[0] <= 1.0); + assert(0.0 <= shoveComponents[1] && shoveComponents[1] <= 1.0); + assert(0.0 <= shoveComponents[2] && shoveComponents[2] <= 1.0); + assert(0.0 <= shoveComponents[3] && shoveComponents[3] <= 1.0); + + /* due to limited precision, need to round before shoving */ + ((GLushort *)packedPixel)[index] = + ((GLushort)((shoveComponents[0] * 15)+0.5) << 12) & 0xf000; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[1] * 15)+0.5) << 8) & 0x0f00; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[2] * 15)+0.5) << 4) & 0x00f0; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[3] * 15)+0.5) ) & 0x000f; +} /* shove4444() */ + +static void extract4444rev(int isSwap,const void *packedPixel, + GLfloat extractComponents[]) +{ + GLushort ushort; + + if (isSwap) { + ushort= __GLU_SWAP_2_BYTES(packedPixel); + } + else { + ushort= *(const GLushort *)packedPixel; + } + + /* 00000000,00001111 == 0x000f */ + /* 00000000,11110000 == 0x00f0 */ + /* 00001111,00000000 == 0x0f00 */ + /* 11110000,00000000 == 0xf000 */ + + /* 15 = 2^4-1 */ + extractComponents[0]= (float)((ushort & 0x000F) ) / 15.0; + extractComponents[1]= (float)((ushort & 0x00F0) >> 4) / 15.0; + extractComponents[2]= (float)((ushort & 0x0F00) >> 8) / 15.0; + extractComponents[3]= (float)((ushort & 0xF000) >> 12) / 15.0; +} /* extract4444rev() */ + +static void shove4444rev(const GLfloat shoveComponents[], + int index,void *packedPixel) +{ + /* 00000000,00001111 == 0x000f */ + /* 00000000,11110000 == 0x00f0 */ + /* 00001111,00000000 == 0x0f00 */ + /* 11110000,00000000 == 0xf000 */ + + assert(0.0 <= shoveComponents[0] && shoveComponents[0] <= 1.0); + assert(0.0 <= shoveComponents[1] && shoveComponents[1] <= 1.0); + assert(0.0 <= shoveComponents[2] && shoveComponents[2] <= 1.0); + assert(0.0 <= shoveComponents[3] && shoveComponents[3] <= 1.0); + + /* due to limited precision, need to round before shoving */ + ((GLushort *)packedPixel)[index] = + ((GLushort)((shoveComponents[0] * 15)+0.5) ) & 0x000F; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[1] * 15)+0.5) << 4) & 0x00F0; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[2] * 15)+0.5) << 8) & 0x0F00; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[3] * 15)+0.5) << 12) & 0xF000; +} /* shove4444rev() */ + +static void extract5551(int isSwap,const void *packedPixel, + GLfloat extractComponents[]) +{ + GLushort ushort; + + if (isSwap) { + ushort= __GLU_SWAP_2_BYTES(packedPixel); + } + else { + ushort= *(const GLushort *)packedPixel; + } + + /* 11111000,00000000 == 0xf800 */ + /* 00000111,11000000 == 0x07c0 */ + /* 00000000,00111110 == 0x003e */ + /* 00000000,00000001 == 0x0001 */ + + extractComponents[0]=(float)((ushort & 0xf800) >> 11) / 31.0;/* 31 = 2^5-1*/ + extractComponents[1]=(float)((ushort & 0x07c0) >> 6) / 31.0; + extractComponents[2]=(float)((ushort & 0x003e) >> 1) / 31.0; + extractComponents[3]=(float)((ushort & 0x0001) ); +} /* extract5551() */ + +static void shove5551(const GLfloat shoveComponents[], + int index,void *packedPixel) +{ + /* 11111000,00000000 == 0xf800 */ + /* 00000111,11000000 == 0x07c0 */ + /* 00000000,00111110 == 0x003e */ + /* 00000000,00000001 == 0x0001 */ + + assert(0.0 <= shoveComponents[0] && shoveComponents[0] <= 1.0); + assert(0.0 <= shoveComponents[1] && shoveComponents[1] <= 1.0); + assert(0.0 <= shoveComponents[2] && shoveComponents[2] <= 1.0); + assert(0.0 <= shoveComponents[3] && shoveComponents[3] <= 1.0); + + /* due to limited precision, need to round before shoving */ + ((GLushort *)packedPixel)[index] = + ((GLushort)((shoveComponents[0] * 31)+0.5) << 11) & 0xf800; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[1] * 31)+0.5) << 6) & 0x07c0; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[2] * 31)+0.5) << 1) & 0x003e; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[3])+0.5) ) & 0x0001; +} /* shove5551() */ + +static void extract1555rev(int isSwap,const void *packedPixel, + GLfloat extractComponents[]) +{ + GLushort ushort; + + if (isSwap) { + ushort= __GLU_SWAP_2_BYTES(packedPixel); + } + else { + ushort= *(const GLushort *)packedPixel; + } + + /* 00000000,00011111 == 0x001F */ + /* 00000011,11100000 == 0x03E0 */ + /* 01111100,00000000 == 0x7C00 */ + /* 10000000,00000000 == 0x8000 */ + + /* 31 = 2^5-1 */ + extractComponents[0]= (float)((ushort & 0x001F) ) / 31.0; + extractComponents[1]= (float)((ushort & 0x03E0) >> 5) / 31.0; + extractComponents[2]= (float)((ushort & 0x7C00) >> 10) / 31.0; + extractComponents[3]= (float)((ushort & 0x8000) >> 15); +} /* extract1555rev() */ + +static void shove1555rev(const GLfloat shoveComponents[], + int index,void *packedPixel) +{ + /* 00000000,00011111 == 0x001F */ + /* 00000011,11100000 == 0x03E0 */ + /* 01111100,00000000 == 0x7C00 */ + /* 10000000,00000000 == 0x8000 */ + + assert(0.0 <= shoveComponents[0] && shoveComponents[0] <= 1.0); + assert(0.0 <= shoveComponents[1] && shoveComponents[1] <= 1.0); + assert(0.0 <= shoveComponents[2] && shoveComponents[2] <= 1.0); + assert(0.0 <= shoveComponents[3] && shoveComponents[3] <= 1.0); + + /* due to limited precision, need to round before shoving */ + ((GLushort *)packedPixel)[index] = + ((GLushort)((shoveComponents[0] * 31)+0.5) ) & 0x001F; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[1] * 31)+0.5) << 5) & 0x03E0; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[2] * 31)+0.5) << 10) & 0x7C00; + ((GLushort *)packedPixel)[index]|= + ((GLushort)((shoveComponents[3])+0.5) << 15) & 0x8000; +} /* shove1555rev() */ + +static void extract8888(int isSwap, + const void *packedPixel, GLfloat extractComponents[]) +{ + GLuint uint; + + if (isSwap) { + uint= __GLU_SWAP_4_BYTES(packedPixel); + } + else { + uint= *(const GLuint *)packedPixel; + } + + /* 11111111,00000000,00000000,00000000 == 0xff000000 */ + /* 00000000,11111111,00000000,00000000 == 0x00ff0000 */ + /* 00000000,00000000,11111111,00000000 == 0x0000ff00 */ + /* 00000000,00000000,00000000,11111111 == 0x000000ff */ + + /* 255 = 2^8-1 */ + extractComponents[0]= (float)((uint & 0xff000000) >> 24) / 255.0; + extractComponents[1]= (float)((uint & 0x00ff0000) >> 16) / 255.0; + extractComponents[2]= (float)((uint & 0x0000ff00) >> 8) / 255.0; + extractComponents[3]= (float)((uint & 0x000000ff) ) / 255.0; +} /* extract8888() */ + +static void shove8888(const GLfloat shoveComponents[], + int index,void *packedPixel) +{ + /* 11111111,00000000,00000000,00000000 == 0xff000000 */ + /* 00000000,11111111,00000000,00000000 == 0x00ff0000 */ + /* 00000000,00000000,11111111,00000000 == 0x0000ff00 */ + /* 00000000,00000000,00000000,11111111 == 0x000000ff */ + + assert(0.0 <= shoveComponents[0] && shoveComponents[0] <= 1.0); + assert(0.0 <= shoveComponents[1] && shoveComponents[1] <= 1.0); + assert(0.0 <= shoveComponents[2] && shoveComponents[2] <= 1.0); + assert(0.0 <= shoveComponents[3] && shoveComponents[3] <= 1.0); + + /* due to limited precision, need to round before shoving */ + ((GLuint *)packedPixel)[index] = + ((GLuint)((shoveComponents[0] * 255)+0.5) << 24) & 0xff000000; + ((GLuint *)packedPixel)[index]|= + ((GLuint)((shoveComponents[1] * 255)+0.5) << 16) & 0x00ff0000; + ((GLuint *)packedPixel)[index]|= + ((GLuint)((shoveComponents[2] * 255)+0.5) << 8) & 0x0000ff00; + ((GLuint *)packedPixel)[index]|= + ((GLuint)((shoveComponents[3] * 255)+0.5) ) & 0x000000ff; +} /* shove8888() */ + +static void extract8888rev(int isSwap, + const void *packedPixel,GLfloat extractComponents[]) +{ + GLuint uint; + + if (isSwap) { + uint= __GLU_SWAP_4_BYTES(packedPixel); + } + else { + uint= *(const GLuint *)packedPixel; + } + + /* 00000000,00000000,00000000,11111111 == 0x000000ff */ + /* 00000000,00000000,11111111,00000000 == 0x0000ff00 */ + /* 00000000,11111111,00000000,00000000 == 0x00ff0000 */ + /* 11111111,00000000,00000000,00000000 == 0xff000000 */ + + /* 255 = 2^8-1 */ + extractComponents[0]= (float)((uint & 0x000000FF) ) / 255.0; + extractComponents[1]= (float)((uint & 0x0000FF00) >> 8) / 255.0; + extractComponents[2]= (float)((uint & 0x00FF0000) >> 16) / 255.0; + extractComponents[3]= (float)((uint & 0xFF000000) >> 24) / 255.0; +} /* extract8888rev() */ + +static void shove8888rev(const GLfloat shoveComponents[], + int index,void *packedPixel) +{ + /* 00000000,00000000,00000000,11111111 == 0x000000ff */ + /* 00000000,00000000,11111111,00000000 == 0x0000ff00 */ + /* 00000000,11111111,00000000,00000000 == 0x00ff0000 */ + /* 11111111,00000000,00000000,00000000 == 0xff000000 */ + + assert(0.0 <= shoveComponents[0] && shoveComponents[0] <= 1.0); + assert(0.0 <= shoveComponents[1] && shoveComponents[1] <= 1.0); + assert(0.0 <= shoveComponents[2] && shoveComponents[2] <= 1.0); + assert(0.0 <= shoveComponents[3] && shoveComponents[3] <= 1.0); + + /* due to limited precision, need to round before shoving */ + ((GLuint *)packedPixel)[index] = + ((GLuint)((shoveComponents[0] * 255)+0.5) ) & 0x000000FF; + ((GLuint *)packedPixel)[index]|= + ((GLuint)((shoveComponents[1] * 255)+0.5) << 8) & 0x0000FF00; + ((GLuint *)packedPixel)[index]|= + ((GLuint)((shoveComponents[2] * 255)+0.5) << 16) & 0x00FF0000; + ((GLuint *)packedPixel)[index]|= + ((GLuint)((shoveComponents[3] * 255)+0.5) << 24) & 0xFF000000; +} /* shove8888rev() */ + +static void extract1010102(int isSwap, + const void *packedPixel,GLfloat extractComponents[]) +{ + GLuint uint; + + if (isSwap) { + uint= __GLU_SWAP_4_BYTES(packedPixel); + } + else { + uint= *(const GLuint *)packedPixel; + } + + /* 11111111,11000000,00000000,00000000 == 0xffc00000 */ + /* 00000000,00111111,11110000,00000000 == 0x003ff000 */ + /* 00000000,00000000,00001111,11111100 == 0x00000ffc */ + /* 00000000,00000000,00000000,00000011 == 0x00000003 */ + + /* 1023 = 2^10-1 */ + extractComponents[0]= (float)((uint & 0xffc00000) >> 22) / 1023.0; + extractComponents[1]= (float)((uint & 0x003ff000) >> 12) / 1023.0; + extractComponents[2]= (float)((uint & 0x00000ffc) >> 2) / 1023.0; + extractComponents[3]= (float)((uint & 0x00000003) ) / 3.0; +} /* extract1010102() */ + +static void shove1010102(const GLfloat shoveComponents[], + int index,void *packedPixel) +{ + /* 11111111,11000000,00000000,00000000 == 0xffc00000 */ + /* 00000000,00111111,11110000,00000000 == 0x003ff000 */ + /* 00000000,00000000,00001111,11111100 == 0x00000ffc */ + /* 00000000,00000000,00000000,00000011 == 0x00000003 */ + + assert(0.0 <= shoveComponents[0] && shoveComponents[0] <= 1.0); + assert(0.0 <= shoveComponents[1] && shoveComponents[1] <= 1.0); + assert(0.0 <= shoveComponents[2] && shoveComponents[2] <= 1.0); + assert(0.0 <= shoveComponents[3] && shoveComponents[3] <= 1.0); + + /* due to limited precision, need to round before shoving */ + ((GLuint *)packedPixel)[index] = + ((GLuint)((shoveComponents[0] * 1023)+0.5) << 22) & 0xffc00000; + ((GLuint *)packedPixel)[index]|= + ((GLuint)((shoveComponents[1] * 1023)+0.5) << 12) & 0x003ff000; + ((GLuint *)packedPixel)[index]|= + ((GLuint)((shoveComponents[2] * 1023)+0.5) << 2) & 0x00000ffc; + ((GLuint *)packedPixel)[index]|= + ((GLuint)((shoveComponents[3] * 3)+0.5) ) & 0x00000003; +} /* shove1010102() */ + +static void extract2101010rev(int isSwap, + const void *packedPixel, + GLfloat extractComponents[]) +{ + GLuint uint; + + if (isSwap) { + uint= __GLU_SWAP_4_BYTES(packedPixel); + } + else { + uint= *(const GLuint *)packedPixel; + } + + /* 00000000,00000000,00000011,11111111 == 0x000003FF */ + /* 00000000,00001111,11111100,00000000 == 0x000FFC00 */ + /* 00111111,11110000,00000000,00000000 == 0x3FF00000 */ + /* 11000000,00000000,00000000,00000000 == 0xC0000000 */ + + /* 1023 = 2^10-1 */ + extractComponents[0]= (float)((uint & 0x000003FF) ) / 1023.0; + extractComponents[1]= (float)((uint & 0x000FFC00) >> 10) / 1023.0; + extractComponents[2]= (float)((uint & 0x3FF00000) >> 20) / 1023.0; + extractComponents[3]= (float)((uint & 0xC0000000) >> 30) / 3.0; + /* 3 = 2^2-1 */ +} /* extract2101010rev() */ + +static void shove2101010rev(const GLfloat shoveComponents[], + int index,void *packedPixel) +{ + /* 00000000,00000000,00000011,11111111 == 0x000003FF */ + /* 00000000,00001111,11111100,00000000 == 0x000FFC00 */ + /* 00111111,11110000,00000000,00000000 == 0x3FF00000 */ + /* 11000000,00000000,00000000,00000000 == 0xC0000000 */ + + assert(0.0 <= shoveComponents[0] && shoveComponents[0] <= 1.0); + assert(0.0 <= shoveComponents[1] && shoveComponents[1] <= 1.0); + assert(0.0 <= shoveComponents[2] && shoveComponents[2] <= 1.0); + assert(0.0 <= shoveComponents[3] && shoveComponents[3] <= 1.0); + + /* due to limited precision, need to round before shoving */ + ((GLuint *)packedPixel)[index] = + ((GLuint)((shoveComponents[0] * 1023)+0.5) ) & 0x000003FF; + ((GLuint *)packedPixel)[index]|= + ((GLuint)((shoveComponents[1] * 1023)+0.5) << 10) & 0x000FFC00; + ((GLuint *)packedPixel)[index]|= + ((GLuint)((shoveComponents[2] * 1023)+0.5) << 20) & 0x3FF00000; + ((GLuint *)packedPixel)[index]|= + ((GLuint)((shoveComponents[3] * 3)+0.5) << 30) & 0xC0000000; +} /* shove2101010rev() */ + +static void scaleInternalPackedPixel(int components, + void (*extractPackedPixel) + (int, const void *,GLfloat []), + void (*shovePackedPixel) + (const GLfloat [], int, void *), + GLint widthIn,GLint heightIn, + const void *dataIn, + GLint widthOut,GLint heightOut, + void *dataOut, + GLint pixelSizeInBytes, + GLint rowSizeInBytes,GLint isSwap) +{ + float convx; + float convy; + float percent; + + /* Max components in a format is 4, so... */ + float totals[4]; + float extractTotals[4], extractMoreTotals[4], shoveTotals[4]; + + float area; + int i,j,k,xindex; + + const char *temp, *temp0; + int outindex; + + int lowx_int, highx_int, lowy_int, highy_int; + float x_percent, y_percent; + float lowx_float, highx_float, lowy_float, highy_float; + float convy_float, convx_float; + int convy_int, convx_int; + int l, m; + const char *left, *right; + + if (widthIn == widthOut*2 && heightIn == heightOut*2) { + halveImagePackedPixel(components,extractPackedPixel,shovePackedPixel, + widthIn, heightIn, dataIn, dataOut, + pixelSizeInBytes,rowSizeInBytes,isSwap); + return; + } + convy = (float) heightIn/heightOut; + convx = (float) widthIn/widthOut; + convy_int = floor(convy); + convy_float = convy - convy_int; + convx_int = floor(convx); + convx_float = convx - convx_int; + + area = convx * convy; + + lowy_int = 0; + lowy_float = 0; + highy_int = convy_int; + highy_float = convy_float; + + for (i = 0; i < heightOut; i++) { + lowx_int = 0; + lowx_float = 0; + highx_int = convx_int; + highx_float = convx_float; + + for (j = 0; j < widthOut; j++) { + /* + ** Ok, now apply box filter to box that goes from (lowx, lowy) + ** to (highx, highy) on input data into this pixel on output + ** data. + */ + totals[0] = totals[1] = totals[2] = totals[3] = 0.0; + + /* calculate the value for pixels in the 1st row */ + xindex = lowx_int*pixelSizeInBytes; + if((highy_int>lowy_int) && (highx_int>lowx_int)) { + + y_percent = 1-lowy_float; + temp = (const char *)dataIn + xindex + lowy_int * rowSizeInBytes; + percent = y_percent * (1-lowx_float); +#if 0 + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } +#else + (*extractPackedPixel)(isSwap,temp,extractTotals); + for (k = 0; k < components; k++) { + totals[k]+= extractTotals[k] * percent; + } +#endif + left = temp; + for(l = lowx_int+1; l < highx_int; l++) { + temp += pixelSizeInBytes; +#if 0 + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_2_BYTES(temp_index) * y_percent; + } else { + totals[k] += *(const GLushort*)temp_index * y_percent; + } + } +#else + (*extractPackedPixel)(isSwap,temp,extractTotals); + for (k = 0; k < components; k++) { + totals[k]+= extractTotals[k] * y_percent; + } +#endif + } + temp += pixelSizeInBytes; + right = temp; + percent = y_percent * highx_float; +#if 0 + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } +#else + (*extractPackedPixel)(isSwap,temp,extractTotals); + for (k = 0; k < components; k++) { + totals[k]+= extractTotals[k] * percent; + } +#endif + + /* calculate the value for pixels in the last row */ + + y_percent = highy_float; + percent = y_percent * (1-lowx_float); + temp = (const char *)dataIn + xindex + highy_int * rowSizeInBytes; +#if 0 + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } +#else + (*extractPackedPixel)(isSwap,temp,extractTotals); + for (k = 0; k < components; k++) { + totals[k]+= extractTotals[k] * percent; + } +#endif + for(l = lowx_int+1; l < highx_int; l++) { + temp += pixelSizeInBytes; +#if 0 + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_2_BYTES(temp_index) * y_percent; + } else { + totals[k] += *(const GLushort*)temp_index * y_percent; + } + } +#else + (*extractPackedPixel)(isSwap,temp,extractTotals); + for (k = 0; k < components; k++) { + totals[k]+= extractTotals[k] * y_percent; + } +#endif + + } + temp += pixelSizeInBytes; + percent = y_percent * highx_float; +#if 0 + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } +#else + (*extractPackedPixel)(isSwap,temp,extractTotals); + for (k = 0; k < components; k++) { + totals[k]+= extractTotals[k] * percent; + } +#endif + + /* calculate the value for pixels in the 1st and last column */ + for(m = lowy_int+1; m < highy_int; m++) { + left += rowSizeInBytes; + right += rowSizeInBytes; +#if 0 + for (k = 0; k < components; + k++, left += element_size, right += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_2_BYTES(left) * (1-lowx_float) + + __GLU_SWAP_2_BYTES(right) * highx_float; + } else { + totals[k] += *(const GLushort*)left * (1-lowx_float) + + *(const GLushort*)right * highx_float; + } + } +#else + (*extractPackedPixel)(isSwap,left,extractTotals); + (*extractPackedPixel)(isSwap,right,extractMoreTotals); + for (k = 0; k < components; k++) { + totals[k]+= (extractTotals[k]*(1-lowx_float) + + extractMoreTotals[k]*highx_float); + } +#endif + } + } else if (highy_int > lowy_int) { + x_percent = highx_float - lowx_float; + percent = (1-lowy_float)*x_percent; + temp = (const char *)dataIn + xindex + lowy_int*rowSizeInBytes; +#if 0 + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } +#else + (*extractPackedPixel)(isSwap,temp,extractTotals); + for (k = 0; k < components; k++) { + totals[k]+= extractTotals[k] * percent; + } +#endif + for(m = lowy_int+1; m < highy_int; m++) { + temp += rowSizeInBytes; +#if 0 + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_2_BYTES(temp_index) * x_percent; + } else { + totals[k] += *(const GLushort*)temp_index * x_percent; + } + } +#else + (*extractPackedPixel)(isSwap,temp,extractTotals); + for (k = 0; k < components; k++) { + totals[k]+= extractTotals[k] * x_percent; + } +#endif + } + percent = x_percent * highy_float; + temp += rowSizeInBytes; +#if 0 + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } +#else + (*extractPackedPixel)(isSwap,temp,extractTotals); + for (k = 0; k < components; k++) { + totals[k]+= extractTotals[k] * percent; + } +#endif + } else if (highx_int > lowx_int) { + y_percent = highy_float - lowy_float; + percent = (1-lowx_float)*y_percent; + temp = (const char *)dataIn + xindex + lowy_int*rowSizeInBytes; +#if 0 + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } +#else + (*extractPackedPixel)(isSwap,temp,extractTotals); + for (k = 0; k < components; k++) { + totals[k]+= extractTotals[k] * percent; + } +#endif + for (l = lowx_int+1; l < highx_int; l++) { + temp += pixelSizeInBytes; +#if 0 + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += + __GLU_SWAP_2_BYTES(temp_index) * y_percent; + } else { + totals[k] += *(const GLushort*)temp_index * y_percent; + } + } +#else + (*extractPackedPixel)(isSwap,temp,extractTotals); + for (k = 0; k < components; k++) { + totals[k]+= extractTotals[k] * y_percent; + } +#endif + } + temp += pixelSizeInBytes; + percent = y_percent * highx_float; +#if 0 + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } +#else + (*extractPackedPixel)(isSwap,temp,extractTotals); + for (k = 0; k < components; k++) { + totals[k]+= extractTotals[k] * percent; + } +#endif + } else { + percent = (highy_float-lowy_float)*(highx_float-lowx_float); + temp = (const char *)dataIn + xindex + lowy_int * rowSizeInBytes; +#if 0 + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index) * percent; + } else { + totals[k] += *(const GLushort*)temp_index * percent; + } + } +#else + (*extractPackedPixel)(isSwap,temp,extractTotals); + for (k = 0; k < components; k++) { + totals[k]+= extractTotals[k] * percent; + } +#endif + } + + /* this is for the pixels in the body */ + temp0 = (const char *)dataIn + xindex + pixelSizeInBytes + (lowy_int+1)*rowSizeInBytes; + for (m = lowy_int+1; m < highy_int; m++) { + temp = temp0; + for(l = lowx_int+1; l < highx_int; l++) { +#if 0 + for (k = 0, temp_index = temp; k < components; + k++, temp_index += element_size) { + if (myswap_bytes) { + totals[k] += __GLU_SWAP_2_BYTES(temp_index); + } else { + totals[k] += *(const GLushort*)temp_index; + } + } +#else + (*extractPackedPixel)(isSwap,temp,extractTotals); + for (k = 0; k < components; k++) { + totals[k]+= extractTotals[k]; + } +#endif + temp += pixelSizeInBytes; + } + temp0 += rowSizeInBytes; + } + + outindex = (j + (i * widthOut)); /* * (components == 1) */ +#if 0 + for (k = 0; k < components; k++) { + dataout[outindex + k] = totals[k]/area; + /*printf("totals[%d] = %f\n", k, totals[k]);*/ + } +#else + for (k = 0; k < components; k++) { + shoveTotals[k]= totals[k]/area; + } + (*shovePackedPixel)(shoveTotals,outindex,(void *)dataOut); +#endif + lowx_int = highx_int; + lowx_float = highx_float; + highx_int += convx_int; + highx_float += convx_float; + if(highx_float > 1) { + highx_float -= 1.0; + highx_int++; + } + } + lowy_int = highy_int; + lowy_float = highy_float; + highy_int += convy_int; + highy_float += convy_float; + if(highy_float > 1) { + highy_float -= 1.0; + highy_int++; + } + } + + assert(outindex == (widthOut*heightOut - 1)); +} /* scaleInternalPackedPixel() */ + +/* rowSizeInBytes is at least the width (in bytes) due to padding on + * inputs; not always equal. Output NEVER has row padding. + */ +static void halveImagePackedPixel(int components, + void (*extractPackedPixel) + (int, const void *,GLfloat []), + void (*shovePackedPixel) + (const GLfloat [],int, void *), + GLint width, GLint height, + const void *dataIn, void *dataOut, + GLint pixelSizeInBytes, + GLint rowSizeInBytes, GLint isSwap) +{ + /* handle case where there is only 1 column/row */ + if (width == 1 || height == 1) { + assert(!(width == 1 && height == 1)); /* can't be 1x1 */ + halve1DimagePackedPixel(components,extractPackedPixel,shovePackedPixel, + width,height,dataIn,dataOut,pixelSizeInBytes, + rowSizeInBytes,isSwap); + return; + } + + { + int ii, jj; + + int halfWidth= width / 2; + int halfHeight= height / 2; + const char *src= (const char *) dataIn; + int padBytes= rowSizeInBytes - (width*pixelSizeInBytes); + int outIndex= 0; + + for (ii= 0; ii< halfHeight; ii++) { + for (jj= 0; jj< halfWidth; jj++) { +#define BOX4 4 + float totals[4]; /* 4 is maximum components */ + float extractTotals[BOX4][4]; /* 4 is maximum components */ + int cc; + + (*extractPackedPixel)(isSwap,src, + &extractTotals[0][0]); + (*extractPackedPixel)(isSwap,(src+pixelSizeInBytes), + &extractTotals[1][0]); + (*extractPackedPixel)(isSwap,(src+rowSizeInBytes), + &extractTotals[2][0]); + (*extractPackedPixel)(isSwap, + (src+rowSizeInBytes+pixelSizeInBytes), + &extractTotals[3][0]); + for (cc = 0; cc < components; cc++) { + int kk; + + /* grab 4 pixels to average */ + totals[cc]= 0.0; + /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+ + * extractTotals[2][RED]+extractTotals[3][RED]; + * totals[RED]/= 4.0; + */ + for (kk = 0; kk < BOX4; kk++) { + totals[cc]+= extractTotals[kk][cc]; + } + totals[cc]/= (float)BOX4; + } + (*shovePackedPixel)(totals,outIndex,dataOut); + + outIndex++; + /* skip over to next square of 4 */ + src+= pixelSizeInBytes + pixelSizeInBytes; + } + /* skip past pad bytes, if any, to get to next row */ + src+= padBytes; + + /* src is at beginning of a row here, but it's the second row of + * the square block of 4 pixels that we just worked on so we + * need to go one more row. + * i.e., + * OO... + * here -->OO... + * but want -->OO... + * OO... + * ... + */ + src+= rowSizeInBytes; + } + + /* both pointers must reach one byte after the end */ + assert(src == &((const char *)dataIn)[rowSizeInBytes*height]); + assert(outIndex == halfWidth * halfHeight); + } +} /* halveImagePackedPixel() */ + +static void halve1DimagePackedPixel(int components, + void (*extractPackedPixel) + (int, const void *,GLfloat []), + void (*shovePackedPixel) + (const GLfloat [],int, void *), + GLint width, GLint height, + const void *dataIn, void *dataOut, + GLint pixelSizeInBytes, + GLint rowSizeInBytes, GLint isSwap) +{ + int halfWidth= width / 2; + int halfHeight= height / 2; + const char *src= (const char *) dataIn; + int jj; + + assert(width == 1 || height == 1); /* must be 1D */ + assert(width != height); /* can't be square */ + + if (height == 1) { /* 1 row */ + int outIndex= 0; + + assert(width != 1); /* widthxheight can't be 1x1 */ + halfHeight= 1; + + /* one horizontal row with possible pad bytes */ + + for (jj= 0; jj< halfWidth; jj++) { +#define BOX2 2 + float totals[4]; /* 4 is maximum components */ + float extractTotals[BOX2][4]; /* 4 is maximum components */ + int cc; + + /* average two at a time, instead of four */ + (*extractPackedPixel)(isSwap,src, + &extractTotals[0][0]); + (*extractPackedPixel)(isSwap,(src+pixelSizeInBytes), + &extractTotals[1][0]); + for (cc = 0; cc < components; cc++) { + int kk; + + /* grab 2 pixels to average */ + totals[cc]= 0.0; + /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]; + * totals[RED]/= 2.0; + */ + for (kk = 0; kk < BOX2; kk++) { + totals[cc]+= extractTotals[kk][cc]; + } + totals[cc]/= (float)BOX2; + } + (*shovePackedPixel)(totals,outIndex,dataOut); + + outIndex++; + /* skip over to next group of 2 */ + src+= pixelSizeInBytes + pixelSizeInBytes; + } + + { + int padBytes= rowSizeInBytes - (width*pixelSizeInBytes); + src+= padBytes; /* for assertion only */ + } + assert(src == &((const char *)dataIn)[rowSizeInBytes]); + assert(outIndex == halfWidth * halfHeight); + } + else if (width == 1) { /* 1 column */ + int outIndex= 0; + + assert(height != 1); /* widthxheight can't be 1x1 */ + halfWidth= 1; + /* one vertical column with possible pad bytes per row */ + /* average two at a time */ + + for (jj= 0; jj< halfHeight; jj++) { +#define BOX2 2 + float totals[4]; /* 4 is maximum components */ + float extractTotals[BOX2][4]; /* 4 is maximum components */ + int cc; + + /* average two at a time, instead of four */ + (*extractPackedPixel)(isSwap,src, + &extractTotals[0][0]); + (*extractPackedPixel)(isSwap,(src+rowSizeInBytes), + &extractTotals[1][0]); + for (cc = 0; cc < components; cc++) { + int kk; + + /* grab 2 pixels to average */ + totals[cc]= 0.0; + /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]; + * totals[RED]/= 2.0; + */ + for (kk = 0; kk < BOX2; kk++) { + totals[cc]+= extractTotals[kk][cc]; + } + totals[cc]/= (float)BOX2; + } + (*shovePackedPixel)(totals,outIndex,dataOut); + + outIndex++; + src+= rowSizeInBytes + rowSizeInBytes; /* go to row after next */ + } + + assert(src == &((const char *)dataIn)[rowSizeInBytes*height]); + assert(outIndex == halfWidth * halfHeight); + } +} /* halve1DimagePackedPixel() */ + +/*===========================================================================*/ + +#ifdef RESOLVE_3D_TEXTURE_SUPPORT +/* + * This section ensures that GLU 1.3 will load and run on + * a GL 1.1 implementation. It dynamically resolves the + * call to glTexImage3D() which might not be available. + * Or is it might be supported as an extension. + * Contributed by Gerk Huisma . + */ + +typedef void (GLAPIENTRY *TexImage3Dproc)( GLenum target, GLint level, + GLenum internalFormat, + GLsizei width, GLsizei height, + GLsizei depth, GLint border, + GLenum format, GLenum type, + const GLvoid *pixels ); + +static TexImage3Dproc pTexImage3D = 0; + +#if !defined(_WIN32) && !defined(__WIN32__) +# include +# include +#else + WINGDIAPI PROC WINAPI wglGetProcAddress(LPCSTR); +#endif + +static void gluTexImage3D( GLenum target, GLint level, + GLenum internalFormat, + GLsizei width, GLsizei height, + GLsizei depth, GLint border, + GLenum format, GLenum type, + const GLvoid *pixels ) +{ + if (!pTexImage3D) { +#if defined(_WIN32) || defined(__WIN32__) + pTexImage3D = (TexImage3Dproc) wglGetProcAddress("glTexImage3D"); + if (!pTexImage3D) + pTexImage3D = (TexImage3Dproc) wglGetProcAddress("glTexImage3DEXT"); +#else + void *libHandle = dlopen("libgl.so", RTLD_LAZY); + pTexImage3D = TexImage3Dproc) dlsym(libHandle, "glTexImage3D" ); + if (!pTexImage3D) + pTexImage3D = (TexImage3Dproc) dlsym(libHandle,"glTexImage3DEXT"); + dlclose(libHandle); +#endif + } + + /* Now call glTexImage3D */ + if (pTexImage3D) + pTexImage3D(target, level, internalFormat, width, height, + depth, border, format, type, pixels); +} + +#else + +/* Only bind to a GL 1.2 implementation: */ +#define gluTexImage3D glTexImage3D + +#endif + +static GLint imageSize3D(GLint width, GLint height, GLint depth, + GLenum format, GLenum type) +{ + int components= elements_per_group(format,type); + int bytes_per_row= bytes_per_element(type) * width; + +assert(width > 0 && height > 0 && depth > 0); +assert(type != GL_BITMAP); + + return bytes_per_row * height * depth * components; +} /* imageSize3D() */ + +static void fillImage3D(const PixelStorageModes *psm, + GLint width, GLint height, GLint depth, GLenum format, + GLenum type, GLboolean indexFormat, + const void *userImage, GLushort *newImage) +{ + int myswapBytes; + int components; + int groupsPerLine; + int elementSize; + int groupSize; + int rowSize; + int padding; + int elementsPerLine; + int rowsPerImage; + int imageSize; + const GLubyte *start, *rowStart, *iter; + GLushort *iter2; + int ww, hh, dd, k; + + myswapBytes= psm->unpack_swap_bytes; + components= elements_per_group(format,type); + if (psm->unpack_row_length > 0) { + groupsPerLine= psm->unpack_row_length; + } + else { + groupsPerLine= width; + } + elementSize= bytes_per_element(type); + groupSize= elementSize * components; + if (elementSize == 1) myswapBytes= 0; + + /* 3dstuff begin */ + if (psm->unpack_image_height > 0) { + rowsPerImage= psm->unpack_image_height; + } + else { + rowsPerImage= height; + } + /* 3dstuff end */ + + rowSize= groupsPerLine * groupSize; + padding= rowSize % psm->unpack_alignment; + if (padding) { + rowSize+= psm->unpack_alignment - padding; + } + + imageSize= rowsPerImage * rowSize; /* 3dstuff */ + + start= (const GLubyte *)userImage + psm->unpack_skip_rows * rowSize + + psm->unpack_skip_pixels * groupSize + + /*3dstuff*/ + psm->unpack_skip_images * imageSize; + elementsPerLine = width * components; + + iter2= newImage; + for (dd= 0; dd < depth; dd++) { + rowStart= start; + + for (hh= 0; hh < height; hh++) { + iter= rowStart; + + for (ww= 0; ww < elementsPerLine; ww++) { + Type_Widget widget; + float extractComponents[4]; + + switch(type) { + case GL_UNSIGNED_BYTE: + if (indexFormat) { + *iter2++ = *iter; + } else { + *iter2++ = (*iter) * 257; + } + break; + case GL_BYTE: + if (indexFormat) { + *iter2++ = *((const GLbyte *) iter); + } else { + /* rough approx */ + *iter2++ = (*((const GLbyte *) iter)) * 516; + } + break; + case GL_UNSIGNED_BYTE_3_3_2: + extract332(0,iter,extractComponents); + for (k = 0; k < 3; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_BYTE_2_3_3_REV: + extract233rev(0,iter,extractComponents); + for (k = 0; k < 3; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_SHORT_5_6_5: + extract565(myswapBytes,iter,extractComponents); + for (k = 0; k < 3; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_SHORT_5_6_5_REV: + extract565rev(myswapBytes,iter,extractComponents); + for (k = 0; k < 3; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_SHORT_4_4_4_4: + extract4444(myswapBytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + extract4444rev(myswapBytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_SHORT_5_5_5_1: + extract5551(myswapBytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + extract1555rev(myswapBytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_SHORT: + case GL_SHORT: + if (myswapBytes) { + widget.ub[0] = iter[1]; + widget.ub[1] = iter[0]; + } else { + widget.ub[0] = iter[0]; + widget.ub[1] = iter[1]; + } + if (type == GL_SHORT) { + if (indexFormat) { + *iter2++ = widget.s[0]; + } else { + /* rough approx */ + *iter2++ = widget.s[0]*2; + } + } else { + *iter2++ = widget.us[0]; + } + break; + case GL_UNSIGNED_INT_8_8_8_8: + extract8888(myswapBytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_INT_8_8_8_8_REV: + extract8888rev(myswapBytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_INT_10_10_10_2: + extract1010102(myswapBytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_UNSIGNED_INT_2_10_10_10_REV: + extract2101010rev(myswapBytes,iter,extractComponents); + for (k = 0; k < 4; k++) { + *iter2++ = (GLushort)(extractComponents[k]*65535); + } + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + if (myswapBytes) { + widget.ub[0] = iter[3]; + widget.ub[1] = iter[2]; + widget.ub[2] = iter[1]; + widget.ub[3] = iter[0]; + } else { + widget.ub[0] = iter[0]; + widget.ub[1] = iter[1]; + widget.ub[2] = iter[2]; + widget.ub[3] = iter[3]; + } + if (type == GL_FLOAT) { + if (indexFormat) { + *iter2++ = widget.f; + } else { + *iter2++ = 65535 * widget.f; + } + } else if (type == GL_UNSIGNED_INT) { + if (indexFormat) { + *iter2++ = widget.ui; + } else { + *iter2++ = widget.ui >> 16; + } + } else { + if (indexFormat) { + *iter2++ = widget.i; + } else { + *iter2++ = widget.i >> 15; + } + } + break; + default: + assert(0); + } + + iter+= elementSize; + } /* for ww */ + rowStart+= rowSize; + + iter= rowStart; /* for assertion purposes */ + } /* for hh */ + + start+= imageSize; + } /* for dd */ + + /* iterators should be one byte past end */ + if (!isTypePackedPixel(type)) { + assert(iter2 == &newImage[width*height*depth*components]); + } + else { + assert(iter2 == &newImage[width*height*depth* + elements_per_group(format,0)]); + } + assert( iter == &((const GLubyte *)userImage)[rowSize*height*depth + + psm->unpack_skip_rows * rowSize + + psm->unpack_skip_pixels * groupSize + + /*3dstuff*/ + psm->unpack_skip_images * imageSize] ); +} /* fillImage3D () */ + +static void scaleInternal3D(GLint components, + GLint widthIn, GLint heightIn, GLint depthIn, + const GLushort *dataIn, + GLint widthOut, GLint heightOut, GLint depthOut, + GLushort *dataOut) +{ + float x, lowx, highx, convx, halfconvx; + float y, lowy, highy, convy, halfconvy; + float z, lowz, highz, convz, halfconvz; + float xpercent,ypercent,zpercent; + float percent; + /* Max components in a format is 4, so... */ + float totals[4]; + float volume; + int i,j,d,k,zint,yint,xint,xindex,yindex,zindex; + int temp; + + convz = (float) depthIn/depthOut; + convy = (float) heightIn/heightOut; + convx = (float) widthIn/widthOut; + halfconvx = convx/2; + halfconvy = convy/2; + halfconvz = convz/2; + for (d = 0; d < depthOut; d++) { + z = convz * (d+0.5); + if (depthIn > depthOut) { + highz = z + halfconvz; + lowz = z - halfconvz; + } else { + highz = z + 0.5; + lowz = z - 0.5; + } + for (i = 0; i < heightOut; i++) { + y = convy * (i+0.5); + if (heightIn > heightOut) { + highy = y + halfconvy; + lowy = y - halfconvy; + } else { + highy = y + 0.5; + lowy = y - 0.5; + } + for (j = 0; j < widthOut; j++) { + x = convx * (j+0.5); + if (widthIn > widthOut) { + highx = x + halfconvx; + lowx = x - halfconvx; + } else { + highx = x + 0.5; + lowx = x - 0.5; + } + + /* + ** Ok, now apply box filter to box that goes from (lowx, lowy, + ** lowz) to (highx, highy, highz) on input data into this pixel + ** on output data. + */ + totals[0] = totals[1] = totals[2] = totals[3] = 0.0; + volume = 0.0; + + z = lowz; + zint = floor(z); + while (z < highz) { + zindex = (zint + depthIn) % depthIn; + if (highz < zint+1) { + zpercent = highz - z; + } else { + zpercent = zint+1 - z; + } + + y = lowy; + yint = floor(y); + while (y < highy) { + yindex = (yint + heightIn) % heightIn; + if (highy < yint+1) { + ypercent = highy - y; + } else { + ypercent = yint+1 - y; + } + + x = lowx; + xint = floor(x); + + while (x < highx) { + xindex = (xint + widthIn) % widthIn; + if (highx < xint+1) { + xpercent = highx - x; + } else { + xpercent = xint+1 - x; + } + + percent = xpercent * ypercent * zpercent; + volume += percent; + + temp = (xindex + (yindex*widthIn) + + (zindex*widthIn*heightIn)) * components; + for (k = 0; k < components; k++) { + assert(0 <= (temp+k) && + (temp+k) < + (widthIn*heightIn*depthIn*components)); + totals[k] += dataIn[temp + k] * percent; + } + + xint++; + x = xint; + } /* while x */ + + yint++; + y = yint; + } /* while y */ + + zint++; + z = zint; + } /* while z */ + + temp = (j + (i * widthOut) + + (d*widthOut*heightOut)) * components; + for (k = 0; k < components; k++) { + /* totals[] should be rounded in the case of enlarging an + * RGB ramp when the type is 332 or 4444 + */ + assert(0 <= (temp+k) && + (temp+k) < (widthOut*heightOut*depthOut*components)); + dataOut[temp + k] = (totals[k]+0.5)/volume; + } + } /* for j */ + } /* for i */ + } /* for d */ +} /* scaleInternal3D() */ + +static void emptyImage3D(const PixelStorageModes *psm, + GLint width, GLint height, GLint depth, + GLenum format, GLenum type, GLboolean indexFormat, + const GLushort *oldImage, void *userImage) +{ + int myswapBytes; + int components; + int groupsPerLine; + int elementSize; + int groupSize; + int rowSize; + int padding; + GLubyte *start, *rowStart, *iter; + int elementsPerLine; + const GLushort *iter2; + int ii, jj, dd, k; + int rowsPerImage; + int imageSize; + + myswapBytes= psm->pack_swap_bytes; + components = elements_per_group(format,type); + if (psm->pack_row_length > 0) { + groupsPerLine = psm->pack_row_length; + } + else { + groupsPerLine = width; + } + + elementSize= bytes_per_element(type); + groupSize= elementSize * components; + if (elementSize == 1) myswapBytes= 0; + + /* 3dstuff begin */ + if (psm->pack_image_height > 0) { + rowsPerImage= psm->pack_image_height; + } + else { + rowsPerImage= height; + } + + /* 3dstuff end */ + + rowSize = groupsPerLine * groupSize; + padding = rowSize % psm->pack_alignment; + if (padding) { + rowSize+= psm->pack_alignment - padding; + } + + imageSize= rowsPerImage * rowSize; /* 3dstuff */ + + start = (GLubyte *)userImage + psm->pack_skip_rows * rowSize + + psm->pack_skip_pixels * groupSize + + /*3dstuff*/ + psm->pack_skip_images * imageSize; + elementsPerLine= width * components; + + iter2 = oldImage; + for (dd= 0; dd < depth; dd++) { + rowStart= start; + + for (ii= 0; ii< height; ii++) { + iter = rowStart; + + for (jj = 0; jj < elementsPerLine; jj++) { + Type_Widget widget; + float shoveComponents[4]; + + switch(type){ + case GL_UNSIGNED_BYTE: + if (indexFormat) { + *iter = *iter2++; + } else { + *iter = *iter2++ >> 8; + } + break; + case GL_BYTE: + if (indexFormat) { + *((GLbyte *) iter) = *iter2++; + } else { + *((GLbyte *) iter) = *iter2++ >> 9; + } + break; + case GL_UNSIGNED_BYTE_3_3_2: + for (k = 0; k < 3; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove332(shoveComponents,0,(void *)iter); + break; + case GL_UNSIGNED_BYTE_2_3_3_REV: + for (k = 0; k < 3; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove233rev(shoveComponents,0,(void *)iter); + break; + case GL_UNSIGNED_SHORT_5_6_5: + for (k = 0; k < 3; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove565(shoveComponents,0,(void *)&widget.us[0]); + if (myswapBytes) { + iter[0] = widget.ub[1]; + iter[1] = widget.ub[0]; + } + else { + *(GLushort *)iter = widget.us[0]; + } + break; + case GL_UNSIGNED_SHORT_5_6_5_REV: + for (k = 0; k < 3; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove565rev(shoveComponents,0,(void *)&widget.us[0]); + if (myswapBytes) { + iter[0] = widget.ub[1]; + iter[1] = widget.ub[0]; + } + else { + *(GLushort *)iter = widget.us[0]; + } + break; + case GL_UNSIGNED_SHORT_4_4_4_4: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove4444(shoveComponents,0,(void *)&widget.us[0]); + if (myswapBytes) { + iter[0] = widget.ub[1]; + iter[1] = widget.ub[0]; + } else { + *(GLushort *)iter = widget.us[0]; + } + break; + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove4444rev(shoveComponents,0,(void *)&widget.us[0]); + if (myswapBytes) { + iter[0] = widget.ub[1]; + iter[1] = widget.ub[0]; + } else { + *(GLushort *)iter = widget.us[0]; + } + break; + case GL_UNSIGNED_SHORT_5_5_5_1: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove5551(shoveComponents,0,(void *)&widget.us[0]); + if (myswapBytes) { + iter[0] = widget.ub[1]; + iter[1] = widget.ub[0]; + } else { + *(GLushort *)iter = widget.us[0]; + } + break; + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove1555rev(shoveComponents,0,(void *)&widget.us[0]); + if (myswapBytes) { + iter[0] = widget.ub[1]; + iter[1] = widget.ub[0]; + } else { + *(GLushort *)iter = widget.us[0]; + } + break; + case GL_UNSIGNED_SHORT: + case GL_SHORT: + if (type == GL_SHORT) { + if (indexFormat) { + widget.s[0] = *iter2++; + } else { + widget.s[0] = *iter2++ >> 1; + } + } else { + widget.us[0] = *iter2++; + } + if (myswapBytes) { + iter[0] = widget.ub[1]; + iter[1] = widget.ub[0]; + } else { + iter[0] = widget.ub[0]; + iter[1] = widget.ub[1]; + } + break; + case GL_UNSIGNED_INT_8_8_8_8: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove8888(shoveComponents,0,(void *)&widget.ui); + if (myswapBytes) { + iter[3] = widget.ub[0]; + iter[2] = widget.ub[1]; + iter[1] = widget.ub[2]; + iter[0] = widget.ub[3]; + } else { + *(GLuint *)iter= widget.ui; + } + break; + case GL_UNSIGNED_INT_8_8_8_8_REV: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove8888rev(shoveComponents,0,(void *)&widget.ui); + if (myswapBytes) { + iter[3] = widget.ub[0]; + iter[2] = widget.ub[1]; + iter[1] = widget.ub[2]; + iter[0] = widget.ub[3]; + } else { + *(GLuint *)iter= widget.ui; + } + break; + case GL_UNSIGNED_INT_10_10_10_2: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove1010102(shoveComponents,0,(void *)&widget.ui); + if (myswapBytes) { + iter[3] = widget.ub[0]; + iter[2] = widget.ub[1]; + iter[1] = widget.ub[2]; + iter[0] = widget.ub[3]; + } else { + *(GLuint *)iter= widget.ui; + } + break; + case GL_UNSIGNED_INT_2_10_10_10_REV: + for (k = 0; k < 4; k++) { + shoveComponents[k]= *iter2++ / 65535.0; + } + shove2101010rev(shoveComponents,0,(void *)&widget.ui); + if (myswapBytes) { + iter[3] = widget.ub[0]; + iter[2] = widget.ub[1]; + iter[1] = widget.ub[2]; + iter[0] = widget.ub[3]; + } else { + *(GLuint *)iter= widget.ui; + } + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + if (type == GL_FLOAT) { + if (indexFormat) { + widget.f = *iter2++; + } else { + widget.f = *iter2++ / (float) 65535.0; + } + } else if (type == GL_UNSIGNED_INT) { + if (indexFormat) { + widget.ui = *iter2++; + } else { + widget.ui = (unsigned int) *iter2++ * 65537; + } + } else { + if (indexFormat) { + widget.i = *iter2++; + } else { + widget.i = ((unsigned int) *iter2++ * 65537)/2; + } + } + if (myswapBytes) { + iter[3] = widget.ub[0]; + iter[2] = widget.ub[1]; + iter[1] = widget.ub[2]; + iter[0] = widget.ub[3]; + } else { + iter[0] = widget.ub[0]; + iter[1] = widget.ub[1]; + iter[2] = widget.ub[2]; + iter[3] = widget.ub[3]; + } + break; + default: + assert(0); + } + + iter+= elementSize; + } /* for jj */ + + rowStart+= rowSize; + } /* for ii */ + + start+= imageSize; + } /* for dd */ + + /* iterators should be one byte past end */ + if (!isTypePackedPixel(type)) { + assert(iter2 == &oldImage[width*height*depth*components]); + } + else { + assert(iter2 == &oldImage[width*height*depth* + elements_per_group(format,0)]); + } + assert( iter == &((GLubyte *)userImage)[rowSize*height*depth + + psm->unpack_skip_rows * rowSize + + psm->unpack_skip_pixels * groupSize + + /*3dstuff*/ + psm->unpack_skip_images * imageSize] ); +} /* emptyImage3D() */ + +static +int gluScaleImage3D(GLenum format, + GLint widthIn, GLint heightIn, GLint depthIn, + GLenum typeIn, const void *dataIn, + GLint widthOut, GLint heightOut, GLint depthOut, + GLenum typeOut, void *dataOut) +{ + int components; + GLushort *beforeImage, *afterImage; + PixelStorageModes psm; + + if (widthIn == 0 || heightIn == 0 || depthIn == 0 || + widthOut == 0 || heightOut == 0 || depthOut == 0) { + return 0; + } + + if (widthIn < 0 || heightIn < 0 || depthIn < 0 || + widthOut < 0 || heightOut < 0 || depthOut < 0) { + return GLU_INVALID_VALUE; + } + + if (!legalFormat(format) || !legalType(typeIn) || !legalType(typeOut) || + typeIn == GL_BITMAP || typeOut == GL_BITMAP) { + return GLU_INVALID_ENUM; + } + if (!isLegalFormatForPackedPixelType(format, typeIn)) { + return GLU_INVALID_OPERATION; + } + if (!isLegalFormatForPackedPixelType(format, typeOut)) { + return GLU_INVALID_OPERATION; + } + + beforeImage = malloc(imageSize3D(widthIn, heightIn, depthIn, format, + GL_UNSIGNED_SHORT)); + afterImage = malloc(imageSize3D(widthOut, heightOut, depthOut, format, + GL_UNSIGNED_SHORT)); + if (beforeImage == NULL || afterImage == NULL) { + free(beforeImage); + free(afterImage); + return GLU_OUT_OF_MEMORY; + } + retrieveStoreModes3D(&psm); + + fillImage3D(&psm,widthIn,heightIn,depthIn,format,typeIn, is_index(format), + dataIn, beforeImage); + components = elements_per_group(format,0); + scaleInternal3D(components,widthIn,heightIn,depthIn,beforeImage, + widthOut,heightOut,depthOut,afterImage); + emptyImage3D(&psm,widthOut,heightOut,depthOut,format,typeOut, + is_index(format),afterImage, dataOut); + free((void *) beforeImage); + free((void *) afterImage); + + return 0; +} /* gluScaleImage3D() */ + + +static void closestFit3D(GLenum target, GLint width, GLint height, GLint depth, + GLint internalFormat, GLenum format, GLenum type, + GLint *newWidth, GLint *newHeight, GLint *newDepth) +{ + GLint widthPowerOf2= nearestPower(width); + GLint heightPowerOf2= nearestPower(height); + GLint depthPowerOf2= nearestPower(depth); + GLint proxyWidth; + + do { + /* compute level 1 width & height & depth, clamping each at 1 */ + GLint widthAtLevelOne= (widthPowerOf2 > 1) ? + widthPowerOf2 >> 1 : + widthPowerOf2; + GLint heightAtLevelOne= (heightPowerOf2 > 1) ? + heightPowerOf2 >> 1 : + heightPowerOf2; + GLint depthAtLevelOne= (depthPowerOf2 > 1) ? + depthPowerOf2 >> 1 : + depthPowerOf2; + GLenum proxyTarget = GL_PROXY_TEXTURE_3D; + assert(widthAtLevelOne > 0); + assert(heightAtLevelOne > 0); + assert(depthAtLevelOne > 0); + + /* does width x height x depth at level 1 & all their mipmaps fit? */ + assert(target == GL_TEXTURE_3D || target == GL_PROXY_TEXTURE_3D); + gluTexImage3D(proxyTarget, 1, /* must be non-zero */ + internalFormat, + widthAtLevelOne,heightAtLevelOne,depthAtLevelOne, + 0,format,type,NULL); + glGetTexLevelParameteriv(proxyTarget, 1,GL_TEXTURE_WIDTH,&proxyWidth); + /* does it fit??? */ + if (proxyWidth == 0) { /* nope, so try again with these sizes */ + if (widthPowerOf2 == 1 && heightPowerOf2 == 1 && + depthPowerOf2 == 1) { + *newWidth= *newHeight= *newDepth= 1; /* must fit 1x1x1 texture */ + return; + } + widthPowerOf2= widthAtLevelOne; + heightPowerOf2= heightAtLevelOne; + depthPowerOf2= depthAtLevelOne; + } + /* else it does fit */ + } while (proxyWidth == 0); + /* loop must terminate! */ + + /* return the width & height at level 0 that fits */ + *newWidth= widthPowerOf2; + *newHeight= heightPowerOf2; + *newDepth= depthPowerOf2; +/*printf("Proxy Textures\n");*/ +} /* closestFit3D() */ + +static void halveImagePackedPixelSlice(int components, + void (*extractPackedPixel) + (int, const void *,GLfloat []), + void (*shovePackedPixel) + (const GLfloat [],int, void *), + GLint width, GLint height, GLint depth, + const void *dataIn, void *dataOut, + GLint pixelSizeInBytes, + GLint rowSizeInBytes, + GLint imageSizeInBytes, + GLint isSwap) +{ + int ii, jj; + int halfWidth= width / 2; + int halfHeight= height / 2; + int halfDepth= depth / 2; + const char *src= (const char *)dataIn; + int outIndex= 0; + + assert((width == 1 || height == 1) && depth >= 2); + + if (width == height) { /* a 1-pixel column viewed from top */ + assert(width == 1 && height == 1); + assert(depth >= 2); + + for (ii= 0; ii< halfDepth; ii++) { + float totals[4]; + float extractTotals[BOX2][4]; + int cc; + + (*extractPackedPixel)(isSwap,src,&extractTotals[0][0]); + (*extractPackedPixel)(isSwap,(src+imageSizeInBytes), + &extractTotals[1][0]); + for (cc = 0; cc < components; cc++) { + int kk; + + /* average 2 pixels since only a column */ + totals[cc]= 0.0; + /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]; + * totals[RED]/= 2.0; + */ + for (kk = 0; kk < BOX2; kk++) { + totals[cc]+= extractTotals[kk][cc]; + } + totals[cc]/= (float)BOX2; + } /* for cc */ + + (*shovePackedPixel)(totals,outIndex,dataOut); + outIndex++; + /* skip over to next group of 2 */ + src+= imageSizeInBytes + imageSizeInBytes; + } /* for ii */ + } + else if (height == 1) { /* horizontal slice viewed from top */ + assert(width != 1); + + for (ii= 0; ii< halfDepth; ii++) { + for (jj= 0; jj< halfWidth; jj++) { + float totals[4]; + float extractTotals[BOX4][4]; + int cc; + + (*extractPackedPixel)(isSwap,src, + &extractTotals[0][0]); + (*extractPackedPixel)(isSwap,(src+pixelSizeInBytes), + &extractTotals[1][0]); + (*extractPackedPixel)(isSwap,(src+imageSizeInBytes), + &extractTotals[2][0]); + (*extractPackedPixel)(isSwap, + (src+imageSizeInBytes+pixelSizeInBytes), + &extractTotals[3][0]); + for (cc = 0; cc < components; cc++) { + int kk; + + /* grab 4 pixels to average */ + totals[cc]= 0.0; + /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+ + * extractTotals[2][RED]+extractTotals[3][RED]; + * totals[RED]/= 4.0; + */ + for (kk = 0; kk < BOX4; kk++) { + totals[cc]+= extractTotals[kk][cc]; + } + totals[cc]/= (float)BOX4; + } + (*shovePackedPixel)(totals,outIndex,dataOut); + + outIndex++; + /* skip over to next horizontal square of 4 */ + src+= imageSizeInBytes + imageSizeInBytes; + } + } + + /* assert() */ + } + else if (width == 1) { /* vertical slice viewed from top */ + assert(height != 1); + + for (ii= 0; ii< halfDepth; ii++) { + for (jj= 0; jj< halfHeight; jj++) { + float totals[4]; + float extractTotals[BOX4][4]; + int cc; + + (*extractPackedPixel)(isSwap,src, + &extractTotals[0][0]); + (*extractPackedPixel)(isSwap,(src+rowSizeInBytes), + &extractTotals[1][0]); + (*extractPackedPixel)(isSwap,(src+imageSizeInBytes), + &extractTotals[2][0]); + (*extractPackedPixel)(isSwap, + (src+imageSizeInBytes+rowSizeInBytes), + &extractTotals[3][0]); + for (cc = 0; cc < components; cc++) { + int kk; + + /* grab 4 pixels to average */ + totals[cc]= 0.0; + /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+ + * extractTotals[2][RED]+extractTotals[3][RED]; + * totals[RED]/= 4.0; + */ + for (kk = 0; kk < BOX4; kk++) { + totals[cc]+= extractTotals[kk][cc]; + } + totals[cc]/= (float)BOX4; + } + (*shovePackedPixel)(totals,outIndex,dataOut); + + outIndex++; + + /* skip over to next vertical square of 4 */ + src+= imageSizeInBytes + imageSizeInBytes; + } + } + /* assert() */ + } + +} /* halveImagePackedPixelSlice() */ + +static void halveImagePackedPixel3D(int components, + void (*extractPackedPixel) + (int, const void *,GLfloat []), + void (*shovePackedPixel) + (const GLfloat [],int, void *), + GLint width, GLint height, GLint depth, + const void *dataIn, void *dataOut, + GLint pixelSizeInBytes, + GLint rowSizeInBytes, + GLint imageSizeInBytes, + GLint isSwap) +{ + if (depth == 1) { + assert(1 <= width && 1 <= height); + + halveImagePackedPixel(components,extractPackedPixel,shovePackedPixel, + width,height,dataIn,dataOut,pixelSizeInBytes, + rowSizeInBytes,isSwap); + return; + } + /* a horizontal or vertical slice viewed from top */ + else if (width == 1 || height == 1) { + assert(1 <= depth); + + halveImagePackedPixelSlice(components, + extractPackedPixel,shovePackedPixel, + width, height, depth, dataIn, dataOut, + pixelSizeInBytes, rowSizeInBytes, + imageSizeInBytes, isSwap); + return; + } + { + int ii, jj, dd; + + int halfWidth= width / 2; + int halfHeight= height / 2; + int halfDepth= depth / 2; + const char *src= (const char *) dataIn; + int padBytes= rowSizeInBytes - (width*pixelSizeInBytes); + int outIndex= 0; + + for (dd= 0; dd < halfDepth; dd++) { + for (ii= 0; ii< halfHeight; ii++) { + for (jj= 0; jj< halfWidth; jj++) { +#define BOX8 8 + float totals[4]; /* 4 is maximum components */ + float extractTotals[BOX8][4]; /* 4 is maximum components */ + int cc; + + (*extractPackedPixel)(isSwap,src, + &extractTotals[0][0]); + (*extractPackedPixel)(isSwap,(src+pixelSizeInBytes), + &extractTotals[1][0]); + (*extractPackedPixel)(isSwap,(src+rowSizeInBytes), + &extractTotals[2][0]); + (*extractPackedPixel)(isSwap, + (src+rowSizeInBytes+pixelSizeInBytes), + &extractTotals[3][0]); + + (*extractPackedPixel)(isSwap,(src+imageSizeInBytes), + &extractTotals[4][0]); + (*extractPackedPixel)(isSwap,(src+pixelSizeInBytes+imageSizeInBytes), + &extractTotals[5][0]); + (*extractPackedPixel)(isSwap,(src+rowSizeInBytes+imageSizeInBytes), + &extractTotals[6][0]); + (*extractPackedPixel)(isSwap, + (src+rowSizeInBytes+pixelSizeInBytes+imageSizeInBytes), + &extractTotals[7][0]); + for (cc = 0; cc < components; cc++) { + int kk; + + /* grab 8 pixels to average */ + totals[cc]= 0.0; + /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+ + * extractTotals[2][RED]+extractTotals[3][RED]+ + * extractTotals[4][RED]+extractTotals[5][RED]+ + * extractTotals[6][RED]+extractTotals[7][RED]; + * totals[RED]/= 8.0; + */ + for (kk = 0; kk < BOX8; kk++) { + totals[cc]+= extractTotals[kk][cc]; + } + totals[cc]/= (float)BOX8; + } + (*shovePackedPixel)(totals,outIndex,dataOut); + + outIndex++; + /* skip over to next square of 4 */ + src+= pixelSizeInBytes + pixelSizeInBytes; + } + /* skip past pad bytes, if any, to get to next row */ + src+= padBytes; + + /* src is at beginning of a row here, but it's the second row of + * the square block of 4 pixels that we just worked on so we + * need to go one more row. + * i.e., + * OO... + * here -->OO... + * but want -->OO... + * OO... + * ... + */ + src+= rowSizeInBytes; + } + + src+= imageSizeInBytes; + } /* for dd */ + + /* both pointers must reach one byte after the end */ + assert(src == &((const char *)dataIn)[rowSizeInBytes*height*depth]); + assert(outIndex == halfWidth * halfHeight * halfDepth); + } /* for dd */ + +} /* halveImagePackedPixel3D() */ + +static int gluBuild3DMipmapLevelsCore(GLenum target, GLint internalFormat, + GLsizei width, + GLsizei height, + GLsizei depth, + GLsizei widthPowerOf2, + GLsizei heightPowerOf2, + GLsizei depthPowerOf2, + GLenum format, GLenum type, + GLint userLevel, + GLint baseLevel,GLint maxLevel, + const void *data) +{ + GLint newWidth, newHeight, newDepth; + GLint level, levels; + const void *usersImage; + void *srcImage, *dstImage; + __GLU_INIT_SWAP_IMAGE; + GLint memReq; + GLint cmpts; + + GLint myswapBytes, groupsPerLine, elementSize, groupSize; + GLint rowsPerImage, imageSize; + GLint rowSize, padding; + PixelStorageModes psm; + + assert(checkMipmapArgs(internalFormat,format,type) == 0); + assert(width >= 1 && height >= 1 && depth >= 1); + assert(type != GL_BITMAP); + + srcImage = dstImage = NULL; + + newWidth= widthPowerOf2; + newHeight= heightPowerOf2; + newDepth= depthPowerOf2; + levels = computeLog(newWidth); + level = computeLog(newHeight); + if (level > levels) levels=level; + level = computeLog(newDepth); + if (level > levels) levels=level; + + levels+= userLevel; + + retrieveStoreModes3D(&psm); + myswapBytes = psm.unpack_swap_bytes; + cmpts = elements_per_group(format,type); + if (psm.unpack_row_length > 0) { + groupsPerLine = psm.unpack_row_length; + } else { + groupsPerLine = width; + } + + elementSize = bytes_per_element(type); + groupSize = elementSize * cmpts; + if (elementSize == 1) myswapBytes = 0; + + /* 3dstuff begin */ + if (psm.unpack_image_height > 0) { + rowsPerImage= psm.unpack_image_height; + } + else { + rowsPerImage= height; + } + + /* 3dstuff end */ + rowSize = groupsPerLine * groupSize; + padding = (rowSize % psm.unpack_alignment); + if (padding) { + rowSize += psm.unpack_alignment - padding; + } + + imageSize= rowsPerImage * rowSize; /* 3dstuff */ + + usersImage = (const GLubyte *)data + psm.unpack_skip_rows * rowSize + + psm.unpack_skip_pixels * groupSize + + /* 3dstuff */ + psm.unpack_skip_images * imageSize; + + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_SKIP_IMAGES, 0); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0); + + level = userLevel; + + if (width == newWidth && height == newHeight && depth == newDepth) { + /* Use usersImage for level userLevel */ + if (baseLevel <= level && level <= maxLevel) { + gluTexImage3D(target, level, internalFormat, width, + height, depth, 0, format, type, + usersImage); + } + if(levels == 0) { /* we're done. clean up and return */ + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + glPixelStorei(GL_UNPACK_SKIP_IMAGES, psm.unpack_skip_images); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, psm.unpack_image_height); + return 0; + } + { + int nextWidth= newWidth/2; + int nextHeight= newHeight/2; + int nextDepth= newDepth/2; + + /* clamp to 1 */ + if (nextWidth < 1) nextWidth= 1; + if (nextHeight < 1) nextHeight= 1; + if (nextDepth < 1) nextDepth= 1; + memReq = imageSize3D(nextWidth, nextHeight, nextDepth, format, type); + } + switch(type) { + case GL_UNSIGNED_BYTE: + dstImage = (GLubyte *)malloc(memReq); + break; + case GL_BYTE: + dstImage = (GLbyte *)malloc(memReq); + break; + case GL_UNSIGNED_SHORT: + dstImage = (GLushort *)malloc(memReq); + break; + case GL_SHORT: + dstImage = (GLshort *)malloc(memReq); + break; + case GL_UNSIGNED_INT: + dstImage = (GLuint *)malloc(memReq); + break; + case GL_INT: + dstImage = (GLint *)malloc(memReq); + break; + case GL_FLOAT: + dstImage = (GLfloat *)malloc(memReq); + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + dstImage = (GLubyte *)malloc(memReq); + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + dstImage = (GLushort *)malloc(memReq); + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + dstImage = (GLuint *)malloc(memReq); + break; + default: + return GLU_INVALID_ENUM; /* assertion */ + } + if (dstImage == NULL) { + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + glPixelStorei(GL_UNPACK_SKIP_IMAGES, psm.unpack_skip_images); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, psm.unpack_image_height); + return GLU_OUT_OF_MEMORY; + } + else + switch(type) { + case GL_UNSIGNED_BYTE: + if (depth > 1) { + halveImage3D(cmpts,extractUbyte,shoveUbyte, + width,height,depth, + usersImage,dstImage,elementSize,groupSize,rowSize, + imageSize,myswapBytes); + } + else { + halveImage_ubyte(cmpts,width,height,usersImage,dstImage, + elementSize,rowSize,groupSize); + } + break; + case GL_BYTE: + if (depth > 1) { + halveImage3D(cmpts,extractSbyte,shoveSbyte, + width,height,depth, + usersImage,dstImage,elementSize,groupSize,rowSize, + imageSize,myswapBytes); + } + else { + halveImage_byte(cmpts,width,height,usersImage,dstImage, + elementSize,rowSize,groupSize); + } + break; + case GL_UNSIGNED_SHORT: + if (depth > 1) { + halveImage3D(cmpts,extractUshort,shoveUshort, + width,height,depth, + usersImage,dstImage,elementSize,groupSize,rowSize, + imageSize,myswapBytes); + } + else { + halveImage_ushort(cmpts,width,height,usersImage,dstImage, + elementSize,rowSize,groupSize,myswapBytes); + } + break; + case GL_SHORT: + if (depth > 1) { + halveImage3D(cmpts,extractSshort,shoveSshort, + width,height,depth, + usersImage,dstImage,elementSize,groupSize,rowSize, + imageSize,myswapBytes); + } + else { + halveImage_short(cmpts,width,height,usersImage,dstImage, + elementSize,rowSize,groupSize,myswapBytes); + } + break; + case GL_UNSIGNED_INT: + if (depth > 1) { + halveImage3D(cmpts,extractUint,shoveUint, + width,height,depth, + usersImage,dstImage,elementSize,groupSize,rowSize, + imageSize,myswapBytes); + } + else { + halveImage_uint(cmpts,width,height,usersImage,dstImage, + elementSize,rowSize,groupSize,myswapBytes); + } + break; + case GL_INT: + if (depth > 1) { + halveImage3D(cmpts,extractSint,shoveSint, + width,height,depth, + usersImage,dstImage,elementSize,groupSize,rowSize, + imageSize,myswapBytes); + } + else { + halveImage_int(cmpts,width,height,usersImage,dstImage, + elementSize,rowSize,groupSize,myswapBytes); + } + break; + case GL_FLOAT: + if (depth > 1 ) { + halveImage3D(cmpts,extractFloat,shoveFloat, + width,height,depth, + usersImage,dstImage,elementSize,groupSize,rowSize, + imageSize,myswapBytes); + } + else { + halveImage_float(cmpts,width,height,usersImage,dstImage, + elementSize,rowSize,groupSize,myswapBytes); + } + break; + case GL_UNSIGNED_BYTE_3_3_2: + assert(format == GL_RGB); + halveImagePackedPixel3D(3,extract332,shove332, + width,height,depth,usersImage,dstImage, + elementSize,rowSize,imageSize,myswapBytes); + break; + case GL_UNSIGNED_BYTE_2_3_3_REV: + assert(format == GL_RGB); + halveImagePackedPixel3D(3,extract233rev,shove233rev, + width,height,depth,usersImage,dstImage, + elementSize,rowSize,imageSize,myswapBytes); + break; + case GL_UNSIGNED_SHORT_5_6_5: + halveImagePackedPixel3D(3,extract565,shove565, + width,height,depth,usersImage,dstImage, + elementSize,rowSize,imageSize,myswapBytes); + break; + case GL_UNSIGNED_SHORT_5_6_5_REV: + halveImagePackedPixel3D(3,extract565rev,shove565rev, + width,height,depth,usersImage,dstImage, + elementSize,rowSize,imageSize,myswapBytes); + break; + case GL_UNSIGNED_SHORT_4_4_4_4: + halveImagePackedPixel3D(4,extract4444,shove4444, + width,height,depth,usersImage,dstImage, + elementSize,rowSize,imageSize,myswapBytes); + break; + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + halveImagePackedPixel3D(4,extract4444rev,shove4444rev, + width,height,depth,usersImage,dstImage, + elementSize,rowSize,imageSize,myswapBytes); + break; + case GL_UNSIGNED_SHORT_5_5_5_1: + halveImagePackedPixel3D(4,extract5551,shove5551, + width,height,depth,usersImage,dstImage, + elementSize,rowSize,imageSize,myswapBytes); + break; + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + halveImagePackedPixel3D(4,extract1555rev,shove1555rev, + width,height,depth,usersImage,dstImage, + elementSize,rowSize,imageSize,myswapBytes); + break; + case GL_UNSIGNED_INT_8_8_8_8: + halveImagePackedPixel3D(4,extract8888,shove8888, + width,height,depth,usersImage,dstImage, + elementSize,rowSize,imageSize,myswapBytes); + break; + case GL_UNSIGNED_INT_8_8_8_8_REV: + halveImagePackedPixel3D(4,extract8888rev,shove8888rev, + width,height,depth,usersImage,dstImage, + elementSize,rowSize,imageSize,myswapBytes); + break; + case GL_UNSIGNED_INT_10_10_10_2: + halveImagePackedPixel3D(4,extract1010102,shove1010102, + width,height,depth,usersImage,dstImage, + elementSize,rowSize,imageSize,myswapBytes); + break; + case GL_UNSIGNED_INT_2_10_10_10_REV: + halveImagePackedPixel3D(4,extract2101010rev,shove2101010rev, + width,height,depth,usersImage,dstImage, + elementSize,rowSize,imageSize,myswapBytes); + break; + default: + assert(0); + break; + } + newWidth = width/2; + newHeight = height/2; + newDepth = depth/2; + /* clamp to 1 */ + if (newWidth < 1) newWidth= 1; + if (newHeight < 1) newHeight= 1; + if (newDepth < 1) newDepth= 1; + + myswapBytes = 0; + rowSize = newWidth * groupSize; + imageSize= rowSize * newHeight; /* 3dstuff */ + memReq = imageSize3D(newWidth, newHeight, newDepth, format, type); + /* Swap srcImage and dstImage */ + __GLU_SWAP_IMAGE(srcImage,dstImage); + switch(type) { + case GL_UNSIGNED_BYTE: + dstImage = (GLubyte *)malloc(memReq); + break; + case GL_BYTE: + dstImage = (GLbyte *)malloc(memReq); + break; + case GL_UNSIGNED_SHORT: + dstImage = (GLushort *)malloc(memReq); + break; + case GL_SHORT: + dstImage = (GLshort *)malloc(memReq); + break; + case GL_UNSIGNED_INT: + dstImage = (GLuint *)malloc(memReq); + break; + case GL_INT: + dstImage = (GLint *)malloc(memReq); + break; + case GL_FLOAT: + dstImage = (GLfloat *)malloc(memReq); + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + dstImage = (GLubyte *)malloc(memReq); + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + dstImage = (GLushort *)malloc(memReq); + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + dstImage = (GLuint *)malloc(memReq); + break; + default: + return GLU_INVALID_ENUM; /* assertion */ + } + if (dstImage == NULL) { + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + glPixelStorei(GL_UNPACK_SKIP_IMAGES, psm.unpack_skip_images); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, psm.unpack_image_height); + free(srcImage); + return GLU_OUT_OF_MEMORY; + } + /* level userLevel+1 is in srcImage; level userLevel already saved */ + level = userLevel+1; + } else {/* user's image is *not* nice power-of-2 sized square */ + memReq = imageSize3D(newWidth, newHeight, newDepth, format, type); + switch(type) { + case GL_UNSIGNED_BYTE: + dstImage = (GLubyte *)malloc(memReq); + break; + case GL_BYTE: + dstImage = (GLbyte *)malloc(memReq); + break; + case GL_UNSIGNED_SHORT: + dstImage = (GLushort *)malloc(memReq); + break; + case GL_SHORT: + dstImage = (GLshort *)malloc(memReq); + break; + case GL_UNSIGNED_INT: + dstImage = (GLuint *)malloc(memReq); + break; + case GL_INT: + dstImage = (GLint *)malloc(memReq); + break; + case GL_FLOAT: + dstImage = (GLfloat *)malloc(memReq); + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + dstImage = (GLubyte *)malloc(memReq); + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + dstImage = (GLushort *)malloc(memReq); + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + dstImage = (GLuint *)malloc(memReq); + break; + default: + return GLU_INVALID_ENUM; /* assertion */ + } + + if (dstImage == NULL) { + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + glPixelStorei(GL_UNPACK_SKIP_IMAGES, psm.unpack_skip_images); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, psm.unpack_image_height); + return GLU_OUT_OF_MEMORY; + } + /*printf("Build3DMipmaps(): ScaleImage3D %d %d %d->%d %d %d\n", + width,height,depth,newWidth,newHeight,newDepth);*/ + + gluScaleImage3D(format, width, height, depth, type, usersImage, + newWidth, newHeight, newDepth, type, dstImage); + + myswapBytes = 0; + rowSize = newWidth * groupSize; + imageSize = rowSize * newHeight; /* 3dstuff */ + /* Swap dstImage and srcImage */ + __GLU_SWAP_IMAGE(srcImage,dstImage); + + if(levels != 0) { /* use as little memory as possible */ + { + int nextWidth= newWidth/2; + int nextHeight= newHeight/2; + int nextDepth= newDepth/2; + if (nextWidth < 1) nextWidth= 1; + if (nextHeight < 1) nextHeight= 1; + if (nextDepth < 1) nextDepth= 1; + + memReq = imageSize3D(nextWidth, nextHeight, nextDepth, format, type); + } + switch(type) { + case GL_UNSIGNED_BYTE: + dstImage = (GLubyte *)malloc(memReq); + break; + case GL_BYTE: + dstImage = (GLbyte *)malloc(memReq); + break; + case GL_UNSIGNED_SHORT: + dstImage = (GLushort *)malloc(memReq); + break; + case GL_SHORT: + dstImage = (GLshort *)malloc(memReq); + break; + case GL_UNSIGNED_INT: + dstImage = (GLuint *)malloc(memReq); + break; + case GL_INT: + dstImage = (GLint *)malloc(memReq); + break; + case GL_FLOAT: + dstImage = (GLfloat *)malloc(memReq); + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + dstImage = (GLubyte *)malloc(memReq); + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + dstImage = (GLushort *)malloc(memReq); + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + dstImage = (GLuint *)malloc(memReq); + break; + default: + return GLU_INVALID_ENUM; /* assertion */ + } + if (dstImage == NULL) { + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + glPixelStorei(GL_UNPACK_SKIP_IMAGES, psm.unpack_skip_images); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, psm.unpack_image_height); + free(srcImage); + return GLU_OUT_OF_MEMORY; + } + } + /* level userLevel is in srcImage; nothing saved yet */ + level = userLevel; + } + + glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); + if (baseLevel <= level && level <= maxLevel) { + gluTexImage3D(target, level, internalFormat, newWidth, newHeight, newDepth, + 0,format, type, (void *)srcImage); + } + level++; /* update current level for the loop */ + for (; level <= levels; level++) { + switch(type) { + case GL_UNSIGNED_BYTE: + if (newDepth > 1) { + halveImage3D(cmpts,extractUbyte,shoveUbyte, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,groupSize,rowSize, + imageSize,myswapBytes); + } + else { + halveImage_ubyte(cmpts,newWidth,newHeight,srcImage,dstImage, + elementSize,rowSize,groupSize); + } + break; + case GL_BYTE: + if (newDepth > 1) { + halveImage3D(cmpts,extractSbyte,shoveSbyte, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,groupSize,rowSize, + imageSize,myswapBytes); + } + else { + halveImage_byte(cmpts,newWidth,newHeight,srcImage,dstImage, + elementSize,rowSize,groupSize); + } + break; + case GL_UNSIGNED_SHORT: + if (newDepth > 1) { + halveImage3D(cmpts,extractUshort,shoveUshort, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,groupSize,rowSize, + imageSize,myswapBytes); + } + else { + halveImage_ushort(cmpts,newWidth,newHeight,srcImage,dstImage, + elementSize,rowSize,groupSize,myswapBytes); + } + break; + case GL_SHORT: + if (newDepth > 1) { + halveImage3D(cmpts,extractSshort,shoveSshort, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,groupSize,rowSize, + imageSize,myswapBytes); + } + else { + halveImage_short(cmpts,newWidth,newHeight,srcImage,dstImage, + elementSize,rowSize,groupSize,myswapBytes); + } + break; + case GL_UNSIGNED_INT: + if (newDepth > 1) { + halveImage3D(cmpts,extractUint,shoveUint, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,groupSize,rowSize, + imageSize,myswapBytes); + } + else { + halveImage_uint(cmpts,newWidth,newHeight,srcImage,dstImage, + elementSize,rowSize,groupSize,myswapBytes); + } + break; + case GL_INT: + if (newDepth > 1) { + halveImage3D(cmpts,extractSint,shoveSint, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,groupSize,rowSize, + imageSize,myswapBytes); + } + else { + halveImage_int(cmpts,newWidth,newHeight,srcImage,dstImage, + elementSize,rowSize,groupSize,myswapBytes); + } + break; + case GL_FLOAT: + if (newDepth > 1) { + halveImage3D(cmpts,extractFloat,shoveFloat, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,groupSize,rowSize, + imageSize,myswapBytes); + } + else { + halveImage_float(cmpts,newWidth,newHeight,srcImage,dstImage, + elementSize,rowSize,groupSize,myswapBytes); + } + break; + case GL_UNSIGNED_BYTE_3_3_2: + halveImagePackedPixel3D(3,extract332,shove332, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,rowSize, + imageSize,myswapBytes); + break; + case GL_UNSIGNED_BYTE_2_3_3_REV: + halveImagePackedPixel3D(3,extract233rev,shove233rev, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,rowSize, + imageSize,myswapBytes); + break; + case GL_UNSIGNED_SHORT_5_6_5: + halveImagePackedPixel3D(3,extract565,shove565, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,rowSize, + imageSize,myswapBytes); + break; + case GL_UNSIGNED_SHORT_5_6_5_REV: + halveImagePackedPixel3D(3,extract565rev,shove565rev, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,rowSize, + imageSize,myswapBytes); + break; + case GL_UNSIGNED_SHORT_4_4_4_4: + halveImagePackedPixel3D(4,extract4444,shove4444, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,rowSize, + imageSize,myswapBytes); + break; + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + halveImagePackedPixel3D(4,extract4444rev,shove4444rev, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,rowSize, + imageSize,myswapBytes); + break; + case GL_UNSIGNED_SHORT_5_5_5_1: + halveImagePackedPixel3D(4,extract5551,shove5551, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,rowSize, + imageSize,myswapBytes); + break; + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + halveImagePackedPixel3D(4,extract1555rev,shove1555rev, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,rowSize, + imageSize,myswapBytes); + break; + case GL_UNSIGNED_INT_8_8_8_8: + halveImagePackedPixel3D(4,extract8888,shove8888, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,rowSize, + imageSize,myswapBytes); + break; + case GL_UNSIGNED_INT_8_8_8_8_REV: + halveImagePackedPixel3D(4,extract8888rev,shove8888rev, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,rowSize, + imageSize,myswapBytes); + break; + case GL_UNSIGNED_INT_10_10_10_2: + halveImagePackedPixel3D(4,extract1010102,shove1010102, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,rowSize, + imageSize,myswapBytes); + break; + case GL_UNSIGNED_INT_2_10_10_10_REV: + halveImagePackedPixel3D(4,extract2101010rev,shove2101010rev, + newWidth,newHeight,newDepth, + srcImage,dstImage,elementSize,rowSize, + imageSize,myswapBytes); + break; + default: + assert(0); + break; + } + + __GLU_SWAP_IMAGE(srcImage,dstImage); + + if (newWidth > 1) { newWidth /= 2; rowSize /= 2;} + if (newHeight > 1) { newHeight /= 2; imageSize = rowSize * newHeight; } + if (newDepth > 1) newDepth /= 2; + { + /* call tex image with srcImage untouched since it's not padded */ + if (baseLevel <= level && level <= maxLevel) { + gluTexImage3D(target, level, internalFormat, newWidth, newHeight, + newDepth,0, format, type, (void *) srcImage); + } + } + } /* for level */ + glPixelStorei(GL_UNPACK_ALIGNMENT, psm.unpack_alignment); + glPixelStorei(GL_UNPACK_SKIP_ROWS, psm.unpack_skip_rows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length); + glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes); + glPixelStorei(GL_UNPACK_SKIP_IMAGES, psm.unpack_skip_images); + glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, psm.unpack_image_height); + + free(srcImage); /*if you get to here, a srcImage has always been malloc'ed*/ + if (dstImage) { /* if it's non-rectangular and only 1 level */ + free(dstImage); + } + return 0; +} /* gluBuild3DMipmapLevelsCore() */ + +GLint GLAPIENTRY +gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, + GLint userLevel, GLint baseLevel, GLint maxLevel, + const void *data) +{ + int level, levels; + + int rc= checkMipmapArgs(internalFormat,format,type); + if (rc != 0) return rc; + + if (width < 1 || height < 1 || depth < 1) { + return GLU_INVALID_VALUE; + } + + if(type == GL_BITMAP) { + return GLU_INVALID_ENUM; + } + + levels = computeLog(width); + level = computeLog(height); + if (level > levels) levels=level; + level = computeLog(depth); + if (level > levels) levels=level; + + levels+= userLevel; + if (!isLegalLevels(userLevel,baseLevel,maxLevel,levels)) + return GLU_INVALID_VALUE; + + return gluBuild3DMipmapLevelsCore(target, internalFormat, + width, height, depth, + width, height, depth, + format, type, + userLevel, baseLevel, maxLevel, + data); +} /* gluBuild3DMipmapLevels() */ + +GLint GLAPIENTRY +gluBuild3DMipmaps(GLenum target, GLint internalFormat, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, const void *data) +{ + GLint widthPowerOf2, heightPowerOf2, depthPowerOf2; + int level, levels; + + int rc= checkMipmapArgs(internalFormat,format,type); + if (rc != 0) return rc; + + if (width < 1 || height < 1 || depth < 1) { + return GLU_INVALID_VALUE; + } + + if(type == GL_BITMAP) { + return GLU_INVALID_ENUM; + } + + closestFit3D(target,width,height,depth,internalFormat,format,type, + &widthPowerOf2,&heightPowerOf2,&depthPowerOf2); + + levels = computeLog(widthPowerOf2); + level = computeLog(heightPowerOf2); + if (level > levels) levels=level; + level = computeLog(depthPowerOf2); + if (level > levels) levels=level; + + return gluBuild3DMipmapLevelsCore(target, internalFormat, + width, height, depth, + widthPowerOf2, heightPowerOf2, + depthPowerOf2, + format, type, 0, 0, levels, + data); +} /* gluBuild3DMipmaps() */ + +static GLdouble extractUbyte(int isSwap, const void *ubyte) +{ + isSwap= isSwap; /* turn off warnings */ + + assert(*((const GLubyte *)ubyte) <= 255); + + return (GLdouble)(*((const GLubyte *)ubyte)); +} /* extractUbyte() */ + +static void shoveUbyte(GLdouble value, int index, void *data) +{ + assert(0.0 <= value && value < 256.0); + + ((GLubyte *)data)[index]= (GLubyte)value; +} /* shoveUbyte() */ + +static GLdouble extractSbyte(int isSwap, const void *sbyte) +{ + isSwap= isSwap; /* turn off warnings */ + + assert(*((const GLbyte *)sbyte) <= 127); + + return (GLdouble)(*((const GLbyte *)sbyte)); +} /* extractSbyte() */ + +static void shoveSbyte(GLdouble value, int index, void *data) +{ + ((GLbyte *)data)[index]= (GLbyte)value; +} /* shoveSbyte() */ + +static GLdouble extractUshort(int isSwap, const void *uitem) +{ + GLushort ushort; + + if (isSwap) { + ushort= __GLU_SWAP_2_BYTES(uitem); + } + else { + ushort= *(const GLushort *)uitem; + } + + assert(ushort <= 65535); + + return (GLdouble)ushort; +} /* extractUshort() */ + +static void shoveUshort(GLdouble value, int index, void *data) +{ + assert(0.0 <= value && value < 65536.0); + + ((GLushort *)data)[index]= (GLushort)value; +} /* shoveUshort() */ + +static GLdouble extractSshort(int isSwap, const void *sitem) +{ + GLshort sshort; + + if (isSwap) { + sshort= __GLU_SWAP_2_BYTES(sitem); + } + else { + sshort= *(const GLshort *)sitem; + } + + assert(sshort <= 32767); + + return (GLdouble)sshort; +} /* extractSshort() */ + +static void shoveSshort(GLdouble value, int index, void *data) +{ + assert(0.0 <= value && value < 32768.0); + + ((GLshort *)data)[index]= (GLshort)value; +} /* shoveSshort() */ + +static GLdouble extractUint(int isSwap, const void *uitem) +{ + GLuint uint; + + if (isSwap) { + uint= __GLU_SWAP_4_BYTES(uitem); + } + else { + uint= *(const GLuint *)uitem; + } + + assert(uint <= 0xffffffff); + + return (GLdouble)uint; +} /* extractUint() */ + +static void shoveUint(GLdouble value, int index, void *data) +{ + assert(0.0 <= value && value <= (GLdouble) UINT_MAX); + + ((GLuint *)data)[index]= (GLuint)value; +} /* shoveUint() */ + +static GLdouble extractSint(int isSwap, const void *sitem) +{ + GLint sint; + + if (isSwap) { + sint= __GLU_SWAP_4_BYTES(sitem); + } + else { + sint= *(const GLint *)sitem; + } + + assert(sint <= 0x7fffffff); + + return (GLdouble)sint; +} /* extractSint() */ + +static void shoveSint(GLdouble value, int index, void *data) +{ + assert(0.0 <= value && value <= (GLdouble) INT_MAX); + + ((GLint *)data)[index]= (GLint)value; +} /* shoveSint() */ + +static GLdouble extractFloat(int isSwap, const void *item) +{ + GLfloat ffloat; + + if (isSwap) { + ffloat= __GLU_SWAP_4_BYTES(item); + } + else { + ffloat= *(const GLfloat *)item; + } + + assert(ffloat <= 1.0); + + return (GLdouble)ffloat; +} /* extractFloat() */ + +static void shoveFloat(GLdouble value, int index, void *data) +{ + assert(0.0 <= value && value <= 1.0); + + ((GLfloat *)data)[index]= value; +} /* shoveFloat() */ + +static void halveImageSlice(int components, + GLdouble (*extract)(int, const void *), + void (*shove)(GLdouble, int, void *), + GLint width, GLint height, GLint depth, + const void *dataIn, void *dataOut, + GLint elementSizeInBytes, + GLint groupSizeInBytes, + GLint rowSizeInBytes, + GLint imageSizeInBytes, + GLint isSwap) +{ + int ii, jj; + int halfWidth= width / 2; + int halfHeight= height / 2; + int halfDepth= depth / 2; + const char *src= (const char *)dataIn; + int rowPadBytes= rowSizeInBytes - (width * groupSizeInBytes); + int imagePadBytes= imageSizeInBytes - (width*height*groupSizeInBytes); + int outIndex= 0; + + assert((width == 1 || height == 1) && depth >= 2); + + if (width == height) { /* a 1-pixel column viewed from top */ + /* printf("1-column\n");*/ + assert(width == 1 && height == 1); + assert(depth >= 2); + + for (ii= 0; ii< halfDepth; ii++) { + int cc; + + for (cc = 0; cc < components; cc++) { + double totals[4]; + double extractTotals[BOX2][4]; + int kk; + + extractTotals[0][cc]= (*extract)(isSwap,src); + extractTotals[1][cc]= (*extract)(isSwap,(src+imageSizeInBytes)); + + /* average 2 pixels since only a column */ + totals[cc]= 0.0; + /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]; + * totals[RED]/= 2.0; + */ + for (kk = 0; kk < BOX2; kk++) { + totals[cc]+= extractTotals[kk][cc]; + } + totals[cc]/= (double)BOX2; + + (*shove)(totals[cc],outIndex,dataOut); + outIndex++; + src+= elementSizeInBytes; + } /* for cc */ + + /* skip over to next group of 2 */ + src+= rowSizeInBytes; + } /* for ii */ + + assert(src == &((const char *)dataIn)[rowSizeInBytes*height*depth]); + assert(outIndex == halfDepth * components); + } + else if (height == 1) { /* horizontal slice viewed from top */ + /* printf("horizontal slice\n"); */ + assert(width != 1); + + for (ii= 0; ii< halfDepth; ii++) { + for (jj= 0; jj< halfWidth; jj++) { + int cc; + + for (cc = 0; cc < components; cc++) { + int kk; + double totals[4]; + double extractTotals[BOX4][4]; + + extractTotals[0][cc]=(*extract)(isSwap,src); + extractTotals[1][cc]=(*extract)(isSwap, + (src+groupSizeInBytes)); + extractTotals[2][cc]=(*extract)(isSwap, + (src+imageSizeInBytes)); + extractTotals[3][cc]=(*extract)(isSwap, + (src+imageSizeInBytes+groupSizeInBytes)); + + /* grab 4 pixels to average */ + totals[cc]= 0.0; + /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+ + * extractTotals[2][RED]+extractTotals[3][RED]; + * totals[RED]/= 4.0; + */ + for (kk = 0; kk < BOX4; kk++) { + totals[cc]+= extractTotals[kk][cc]; + } + totals[cc]/= (double)BOX4; + + (*shove)(totals[cc],outIndex,dataOut); + outIndex++; + + src+= elementSizeInBytes; + } /* for cc */ + + /* skip over to next horizontal square of 4 */ + src+= groupSizeInBytes; + } /* for jj */ + src+= rowPadBytes; + + src+= rowSizeInBytes; + } /* for ii */ + + assert(src == &((const char *)dataIn)[rowSizeInBytes*height*depth]); + assert(outIndex == halfWidth * halfDepth * components); + } + else if (width == 1) { /* vertical slice viewed from top */ + /* printf("vertical slice\n"); */ + assert(height != 1); + + for (ii= 0; ii< halfDepth; ii++) { + for (jj= 0; jj< halfHeight; jj++) { + int cc; + + for (cc = 0; cc < components; cc++) { + int kk; + double totals[4]; + double extractTotals[BOX4][4]; + + extractTotals[0][cc]=(*extract)(isSwap,src); + extractTotals[1][cc]=(*extract)(isSwap, + (src+rowSizeInBytes)); + extractTotals[2][cc]=(*extract)(isSwap, + (src+imageSizeInBytes)); + extractTotals[3][cc]=(*extract)(isSwap, + (src+imageSizeInBytes+rowSizeInBytes)); + + /* grab 4 pixels to average */ + totals[cc]= 0.0; + /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+ + * extractTotals[2][RED]+extractTotals[3][RED]; + * totals[RED]/= 4.0; + */ + for (kk = 0; kk < BOX4; kk++) { + totals[cc]+= extractTotals[kk][cc]; + } + totals[cc]/= (double)BOX4; + + (*shove)(totals[cc],outIndex,dataOut); + outIndex++; + + src+= elementSizeInBytes; + } /* for cc */ + src+= rowPadBytes; + + /* skip over to next vertical square of 4 */ + src+= rowSizeInBytes; + } /* for jj */ + src+= imagePadBytes; + + src+= imageSizeInBytes; + } /* for ii */ + + assert(src == &((const char *)dataIn)[rowSizeInBytes*height*depth]); + assert(outIndex == halfHeight * halfDepth * components); + } + +} /* halveImageSlice() */ + +static void halveImage3D(int components, + GLdouble (*extract)(int, const void *), + void (*shove)(GLdouble, int, void *), + GLint width, GLint height, GLint depth, + const void *dataIn, void *dataOut, + GLint elementSizeInBytes, + GLint groupSizeInBytes, + GLint rowSizeInBytes, + GLint imageSizeInBytes, + GLint isSwap) +{ + assert(depth > 1); + + /* a horizontal/vertical/one-column slice viewed from top */ + if (width == 1 || height == 1) { + assert(1 <= depth); + + halveImageSlice(components,extract,shove, width, height, depth, + dataIn, dataOut, elementSizeInBytes, groupSizeInBytes, + rowSizeInBytes, imageSizeInBytes, isSwap); + return; + } + { + int ii, jj, dd; + + int halfWidth= width / 2; + int halfHeight= height / 2; + int halfDepth= depth / 2; + const char *src= (const char *) dataIn; + int rowPadBytes= rowSizeInBytes - (width*groupSizeInBytes); + int imagePadBytes= imageSizeInBytes - (width*height*groupSizeInBytes); + int outIndex= 0; + + for (dd= 0; dd < halfDepth; dd++) { + for (ii= 0; ii< halfHeight; ii++) { + for (jj= 0; jj< halfWidth; jj++) { + int cc; + + for (cc= 0; cc < components; cc++) { + int kk; +#define BOX8 8 + double totals[4]; /* 4 is maximum components */ + double extractTotals[BOX8][4]; /* 4 is maximum components */ + + extractTotals[0][cc]= (*extract)(isSwap,src); + extractTotals[1][cc]= (*extract)(isSwap, + (src+groupSizeInBytes)); + extractTotals[2][cc]= (*extract)(isSwap, + (src+rowSizeInBytes)); + extractTotals[3][cc]= (*extract)(isSwap, + (src+rowSizeInBytes+groupSizeInBytes)); + + extractTotals[4][cc]= (*extract)(isSwap, + (src+imageSizeInBytes)); + + extractTotals[5][cc]= (*extract)(isSwap, + (src+groupSizeInBytes+imageSizeInBytes)); + extractTotals[6][cc]= (*extract)(isSwap, + (src+rowSizeInBytes+imageSizeInBytes)); + extractTotals[7][cc]= (*extract)(isSwap, + (src+rowSizeInBytes+groupSizeInBytes+imageSizeInBytes)); + + totals[cc]= 0.0; + + /* totals[RED]= extractTotals[0][RED]+extractTotals[1][RED]+ + * extractTotals[2][RED]+extractTotals[3][RED]+ + * extractTotals[4][RED]+extractTotals[5][RED]+ + * extractTotals[6][RED]+extractTotals[7][RED]; + * totals[RED]/= 8.0; + */ + for (kk = 0; kk < BOX8; kk++) { + totals[cc]+= extractTotals[kk][cc]; + } + totals[cc]/= (double)BOX8; + + (*shove)(totals[cc],outIndex,dataOut); + + outIndex++; + + src+= elementSizeInBytes; /* go to next component */ + } /* for cc */ + + /* skip over to next square of 4 */ + src+= groupSizeInBytes; + } /* for jj */ + /* skip past pad bytes, if any, to get to next row */ + src+= rowPadBytes; + + /* src is at beginning of a row here, but it's the second row of + * the square block of 4 pixels that we just worked on so we + * need to go one more row. + * i.e., + * OO... + * here -->OO... + * but want -->OO... + * OO... + * ... + */ + src+= rowSizeInBytes; + } /* for ii */ + + /* skip past pad bytes, if any, to get to next image */ + src+= imagePadBytes; + + src+= imageSizeInBytes; + } /* for dd */ + + /* both pointers must reach one byte after the end */ + assert(src == &((const char *)dataIn)[rowSizeInBytes*height*depth]); + assert(outIndex == halfWidth * halfHeight * halfDepth * components); + } +} /* halveImage3D() */ + + + +/*** mipmap.c ***/ + diff --git a/src/glu/sgi/libutil/project.c b/src/glu/sgi/libutil/project.c new file mode 100644 index 0000000..f4bf883 --- /dev/null +++ b/src/glu/sgi/libutil/project.c @@ -0,0 +1,359 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "gluos.h" +#include +#include +#include +#include "gluint.h" + +/* +** Make m an identity matrix +*/ +static void __gluMakeIdentityd(GLdouble m[16]) +{ + m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0; + m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0; + m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0; + m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1; +} + +static void __gluMakeIdentityf(GLfloat m[16]) +{ + m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0; + m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0; + m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0; + m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1; +} + +void GLAPIENTRY +gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top) +{ + glOrtho(left, right, bottom, top, -1, 1); +} + +#define __glPi 3.14159265358979323846 + +void GLAPIENTRY +gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) +{ + GLdouble m[4][4]; + double sine, cotangent, deltaZ; + double radians = fovy / 2 * __glPi / 180; + + deltaZ = zFar - zNear; + sine = sin(radians); + if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) { + return; + } + cotangent = COS(radians) / sine; + + __gluMakeIdentityd(&m[0][0]); + m[0][0] = cotangent / aspect; + m[1][1] = cotangent; + m[2][2] = -(zFar + zNear) / deltaZ; + m[2][3] = -1; + m[3][2] = -2 * zNear * zFar / deltaZ; + m[3][3] = 0; + glMultMatrixd(&m[0][0]); +} + +static void normalize(float v[3]) +{ + float r; + + r = sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ); + if (r == 0.0) return; + + v[0] /= r; + v[1] /= r; + v[2] /= r; +} + +static void cross(float v1[3], float v2[3], float result[3]) +{ + result[0] = v1[1]*v2[2] - v1[2]*v2[1]; + result[1] = v1[2]*v2[0] - v1[0]*v2[2]; + result[2] = v1[0]*v2[1] - v1[1]*v2[0]; +} + +void GLAPIENTRY +gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, + GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, + GLdouble upz) +{ + float forward[3], side[3], up[3]; + GLfloat m[4][4]; + + forward[0] = centerx - eyex; + forward[1] = centery - eyey; + forward[2] = centerz - eyez; + + up[0] = upx; + up[1] = upy; + up[2] = upz; + + normalize(forward); + + /* Side = forward x up */ + cross(forward, up, side); + normalize(side); + + /* Recompute up as: up = side x forward */ + cross(side, forward, up); + + __gluMakeIdentityf(&m[0][0]); + m[0][0] = side[0]; + m[1][0] = side[1]; + m[2][0] = side[2]; + + m[0][1] = up[0]; + m[1][1] = up[1]; + m[2][1] = up[2]; + + m[0][2] = -forward[0]; + m[1][2] = -forward[1]; + m[2][2] = -forward[2]; + + glMultMatrixf(&m[0][0]); + glTranslated(-eyex, -eyey, -eyez); +} + +static void __gluMultMatrixVecd(const GLdouble matrix[16], const GLdouble in[4], + GLdouble out[4]) +{ + int i; + + for (i=0; i<4; i++) { + out[i] = + in[0] * matrix[0*4+i] + + in[1] * matrix[1*4+i] + + in[2] * matrix[2*4+i] + + in[3] * matrix[3*4+i]; + } +} + +/* +** Invert 4x4 matrix. +** Contributed by David Moore (See Mesa bug #6748) +*/ +static int __gluInvertMatrixd(const GLdouble m[16], GLdouble invOut[16]) +{ + double inv[16], det; + int i; + + inv[0] = m[5]*m[10]*m[15] - m[5]*m[11]*m[14] - m[9]*m[6]*m[15] + + m[9]*m[7]*m[14] + m[13]*m[6]*m[11] - m[13]*m[7]*m[10]; + inv[4] = -m[4]*m[10]*m[15] + m[4]*m[11]*m[14] + m[8]*m[6]*m[15] + - m[8]*m[7]*m[14] - m[12]*m[6]*m[11] + m[12]*m[7]*m[10]; + inv[8] = m[4]*m[9]*m[15] - m[4]*m[11]*m[13] - m[8]*m[5]*m[15] + + m[8]*m[7]*m[13] + m[12]*m[5]*m[11] - m[12]*m[7]*m[9]; + inv[12] = -m[4]*m[9]*m[14] + m[4]*m[10]*m[13] + m[8]*m[5]*m[14] + - m[8]*m[6]*m[13] - m[12]*m[5]*m[10] + m[12]*m[6]*m[9]; + inv[1] = -m[1]*m[10]*m[15] + m[1]*m[11]*m[14] + m[9]*m[2]*m[15] + - m[9]*m[3]*m[14] - m[13]*m[2]*m[11] + m[13]*m[3]*m[10]; + inv[5] = m[0]*m[10]*m[15] - m[0]*m[11]*m[14] - m[8]*m[2]*m[15] + + m[8]*m[3]*m[14] + m[12]*m[2]*m[11] - m[12]*m[3]*m[10]; + inv[9] = -m[0]*m[9]*m[15] + m[0]*m[11]*m[13] + m[8]*m[1]*m[15] + - m[8]*m[3]*m[13] - m[12]*m[1]*m[11] + m[12]*m[3]*m[9]; + inv[13] = m[0]*m[9]*m[14] - m[0]*m[10]*m[13] - m[8]*m[1]*m[14] + + m[8]*m[2]*m[13] + m[12]*m[1]*m[10] - m[12]*m[2]*m[9]; + inv[2] = m[1]*m[6]*m[15] - m[1]*m[7]*m[14] - m[5]*m[2]*m[15] + + m[5]*m[3]*m[14] + m[13]*m[2]*m[7] - m[13]*m[3]*m[6]; + inv[6] = -m[0]*m[6]*m[15] + m[0]*m[7]*m[14] + m[4]*m[2]*m[15] + - m[4]*m[3]*m[14] - m[12]*m[2]*m[7] + m[12]*m[3]*m[6]; + inv[10] = m[0]*m[5]*m[15] - m[0]*m[7]*m[13] - m[4]*m[1]*m[15] + + m[4]*m[3]*m[13] + m[12]*m[1]*m[7] - m[12]*m[3]*m[5]; + inv[14] = -m[0]*m[5]*m[14] + m[0]*m[6]*m[13] + m[4]*m[1]*m[14] + - m[4]*m[2]*m[13] - m[12]*m[1]*m[6] + m[12]*m[2]*m[5]; + inv[3] = -m[1]*m[6]*m[11] + m[1]*m[7]*m[10] + m[5]*m[2]*m[11] + - m[5]*m[3]*m[10] - m[9]*m[2]*m[7] + m[9]*m[3]*m[6]; + inv[7] = m[0]*m[6]*m[11] - m[0]*m[7]*m[10] - m[4]*m[2]*m[11] + + m[4]*m[3]*m[10] + m[8]*m[2]*m[7] - m[8]*m[3]*m[6]; + inv[11] = -m[0]*m[5]*m[11] + m[0]*m[7]*m[9] + m[4]*m[1]*m[11] + - m[4]*m[3]*m[9] - m[8]*m[1]*m[7] + m[8]*m[3]*m[5]; + inv[15] = m[0]*m[5]*m[10] - m[0]*m[6]*m[9] - m[4]*m[1]*m[10] + + m[4]*m[2]*m[9] + m[8]*m[1]*m[6] - m[8]*m[2]*m[5]; + + det = m[0]*inv[0] + m[1]*inv[4] + m[2]*inv[8] + m[3]*inv[12]; + if (det == 0) + return GL_FALSE; + + det = 1.0 / det; + + for (i = 0; i < 16; i++) + invOut[i] = inv[i] * det; + + return GL_TRUE; +} + +static void __gluMultMatricesd(const GLdouble a[16], const GLdouble b[16], + GLdouble r[16]) +{ + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + r[i*4+j] = + a[i*4+0]*b[0*4+j] + + a[i*4+1]*b[1*4+j] + + a[i*4+2]*b[2*4+j] + + a[i*4+3]*b[3*4+j]; + } + } +} + +GLint GLAPIENTRY +gluProject(GLdouble objx, GLdouble objy, GLdouble objz, + const GLdouble modelMatrix[16], + const GLdouble projMatrix[16], + const GLint viewport[4], + GLdouble *winx, GLdouble *winy, GLdouble *winz) +{ + double in[4]; + double out[4]; + + in[0]=objx; + in[1]=objy; + in[2]=objz; + in[3]=1.0; + __gluMultMatrixVecd(modelMatrix, in, out); + __gluMultMatrixVecd(projMatrix, out, in); + if (in[3] == 0.0) return(GL_FALSE); + in[0] /= in[3]; + in[1] /= in[3]; + in[2] /= in[3]; + /* Map x, y and z to range 0-1 */ + in[0] = in[0] * 0.5 + 0.5; + in[1] = in[1] * 0.5 + 0.5; + in[2] = in[2] * 0.5 + 0.5; + + /* Map x,y to viewport */ + in[0] = in[0] * viewport[2] + viewport[0]; + in[1] = in[1] * viewport[3] + viewport[1]; + + *winx=in[0]; + *winy=in[1]; + *winz=in[2]; + return(GL_TRUE); +} + +GLint GLAPIENTRY +gluUnProject(GLdouble winx, GLdouble winy, GLdouble winz, + const GLdouble modelMatrix[16], + const GLdouble projMatrix[16], + const GLint viewport[4], + GLdouble *objx, GLdouble *objy, GLdouble *objz) +{ + double finalMatrix[16]; + double in[4]; + double out[4]; + + __gluMultMatricesd(modelMatrix, projMatrix, finalMatrix); + if (!__gluInvertMatrixd(finalMatrix, finalMatrix)) return(GL_FALSE); + + in[0]=winx; + in[1]=winy; + in[2]=winz; + in[3]=1.0; + + /* Map x and y from window coordinates */ + in[0] = (in[0] - viewport[0]) / viewport[2]; + in[1] = (in[1] - viewport[1]) / viewport[3]; + + /* Map to range -1 to 1 */ + in[0] = in[0] * 2 - 1; + in[1] = in[1] * 2 - 1; + in[2] = in[2] * 2 - 1; + + __gluMultMatrixVecd(finalMatrix, in, out); + if (out[3] == 0.0) return(GL_FALSE); + out[0] /= out[3]; + out[1] /= out[3]; + out[2] /= out[3]; + *objx = out[0]; + *objy = out[1]; + *objz = out[2]; + return(GL_TRUE); +} + +GLint GLAPIENTRY +gluUnProject4(GLdouble winx, GLdouble winy, GLdouble winz, GLdouble clipw, + const GLdouble modelMatrix[16], + const GLdouble projMatrix[16], + const GLint viewport[4], + GLclampd nearVal, GLclampd farVal, + GLdouble *objx, GLdouble *objy, GLdouble *objz, + GLdouble *objw) +{ + double finalMatrix[16]; + double in[4]; + double out[4]; + + __gluMultMatricesd(modelMatrix, projMatrix, finalMatrix); + if (!__gluInvertMatrixd(finalMatrix, finalMatrix)) return(GL_FALSE); + + in[0]=winx; + in[1]=winy; + in[2]=winz; + in[3]=clipw; + + /* Map x and y from window coordinates */ + in[0] = (in[0] - viewport[0]) / viewport[2]; + in[1] = (in[1] - viewport[1]) / viewport[3]; + in[2] = (in[2] - nearVal) / (farVal - nearVal); + + /* Map to range -1 to 1 */ + in[0] = in[0] * 2 - 1; + in[1] = in[1] * 2 - 1; + in[2] = in[2] * 2 - 1; + + __gluMultMatrixVecd(finalMatrix, in, out); + if (out[3] == 0.0) return(GL_FALSE); + *objx = out[0]; + *objy = out[1]; + *objz = out[2]; + *objw = out[3]; + return(GL_TRUE); +} + +void GLAPIENTRY +gluPickMatrix(GLdouble x, GLdouble y, GLdouble deltax, GLdouble deltay, + GLint viewport[4]) +{ + if (deltax <= 0 || deltay <= 0) { + return; + } + + /* Translate and scale the picked region to the entire window */ + glTranslatef((viewport[2] - 2 * (x - viewport[0])) / deltax, + (viewport[3] - 2 * (y - viewport[1])) / deltay, 0); + glScalef(viewport[2] / deltax, viewport[3] / deltay, 1.0); +} diff --git a/src/glu/sgi/libutil/quad.c b/src/glu/sgi/libutil/quad.c new file mode 100644 index 0000000..d88b20f --- /dev/null +++ b/src/glu/sgi/libutil/quad.c @@ -0,0 +1,1155 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "gluos.h" +#include "gluint.h" +#include +#include +#include +#include +#include + +/* Make it not a power of two to avoid cache thrashing on the chip */ +#define CACHE_SIZE 240 + +#undef PI +#define PI 3.14159265358979323846 + +struct GLUquadric { + GLint normals; + GLboolean textureCoords; + GLint orientation; + GLint drawStyle; + void (GLAPIENTRY *errorCallback)( GLint ); +}; + +GLUquadric * GLAPIENTRY +gluNewQuadric(void) +{ + GLUquadric *newstate; + + newstate = (GLUquadric *) malloc(sizeof(GLUquadric)); + if (newstate == NULL) { + /* Can't report an error at this point... */ + return NULL; + } + newstate->normals = GLU_SMOOTH; + newstate->textureCoords = GL_FALSE; + newstate->orientation = GLU_OUTSIDE; + newstate->drawStyle = GLU_FILL; + newstate->errorCallback = NULL; + return newstate; +} + + +void GLAPIENTRY +gluDeleteQuadric(GLUquadric *state) +{ + free(state); +} + +static void gluQuadricError(GLUquadric *qobj, GLenum which) +{ + if (qobj->errorCallback) { + qobj->errorCallback(which); + } +} + +void GLAPIENTRY +gluQuadricCallback(GLUquadric *qobj, GLenum which, _GLUfuncptr fn) +{ + switch (which) { + case GLU_ERROR: + qobj->errorCallback = (void (GLAPIENTRY *)(GLint)) fn; + break; + default: + gluQuadricError(qobj, GLU_INVALID_ENUM); + return; + } +} + +void GLAPIENTRY +gluQuadricNormals(GLUquadric *qobj, GLenum normals) +{ + switch (normals) { + case GLU_SMOOTH: + case GLU_FLAT: + case GLU_NONE: + break; + default: + gluQuadricError(qobj, GLU_INVALID_ENUM); + return; + } + qobj->normals = normals; +} + +void GLAPIENTRY +gluQuadricTexture(GLUquadric *qobj, GLboolean textureCoords) +{ + qobj->textureCoords = textureCoords; +} + +void GLAPIENTRY +gluQuadricOrientation(GLUquadric *qobj, GLenum orientation) +{ + switch(orientation) { + case GLU_OUTSIDE: + case GLU_INSIDE: + break; + default: + gluQuadricError(qobj, GLU_INVALID_ENUM); + return; + } + qobj->orientation = orientation; +} + +void GLAPIENTRY +gluQuadricDrawStyle(GLUquadric *qobj, GLenum drawStyle) +{ + switch(drawStyle) { + case GLU_POINT: + case GLU_LINE: + case GLU_FILL: + case GLU_SILHOUETTE: + break; + default: + gluQuadricError(qobj, GLU_INVALID_ENUM); + return; + } + qobj->drawStyle = drawStyle; +} + +void GLAPIENTRY +gluCylinder(GLUquadric *qobj, GLdouble baseRadius, GLdouble topRadius, + GLdouble height, GLint slices, GLint stacks) +{ + GLint i,j; + GLfloat sinCache[CACHE_SIZE]; + GLfloat cosCache[CACHE_SIZE]; + GLfloat sinCache2[CACHE_SIZE]; + GLfloat cosCache2[CACHE_SIZE]; + GLfloat sinCache3[CACHE_SIZE]; + GLfloat cosCache3[CACHE_SIZE]; + GLfloat angle; + GLfloat zLow, zHigh; + GLfloat sintemp, costemp; + GLfloat length; + GLfloat deltaRadius; + GLfloat zNormal; + GLfloat xyNormalRatio; + GLfloat radiusLow, radiusHigh; + int needCache2, needCache3; + + if (slices >= CACHE_SIZE) slices = CACHE_SIZE-1; + + if (slices < 2 || stacks < 1 || baseRadius < 0.0 || topRadius < 0.0 || + height < 0.0) { + gluQuadricError(qobj, GLU_INVALID_VALUE); + return; + } + + /* Compute length (needed for normal calculations) */ + deltaRadius = baseRadius - topRadius; + length = SQRT(deltaRadius*deltaRadius + height*height); + if (length == 0.0) { + gluQuadricError(qobj, GLU_INVALID_VALUE); + return; + } + + /* Cache is the vertex locations cache */ + /* Cache2 is the various normals at the vertices themselves */ + /* Cache3 is the various normals for the faces */ + needCache2 = needCache3 = 0; + if (qobj->normals == GLU_SMOOTH) { + needCache2 = 1; + } + + if (qobj->normals == GLU_FLAT) { + if (qobj->drawStyle != GLU_POINT) { + needCache3 = 1; + } + if (qobj->drawStyle == GLU_LINE) { + needCache2 = 1; + } + } + + zNormal = deltaRadius / length; + xyNormalRatio = height / length; + + for (i = 0; i < slices; i++) { + angle = 2 * PI * i / slices; + if (needCache2) { + if (qobj->orientation == GLU_OUTSIDE) { + sinCache2[i] = xyNormalRatio * SIN(angle); + cosCache2[i] = xyNormalRatio * COS(angle); + } else { + sinCache2[i] = -xyNormalRatio * SIN(angle); + cosCache2[i] = -xyNormalRatio * COS(angle); + } + } + sinCache[i] = SIN(angle); + cosCache[i] = COS(angle); + } + + if (needCache3) { + for (i = 0; i < slices; i++) { + angle = 2 * PI * (i-0.5) / slices; + if (qobj->orientation == GLU_OUTSIDE) { + sinCache3[i] = xyNormalRatio * SIN(angle); + cosCache3[i] = xyNormalRatio * COS(angle); + } else { + sinCache3[i] = -xyNormalRatio * SIN(angle); + cosCache3[i] = -xyNormalRatio * COS(angle); + } + } + } + + sinCache[slices] = sinCache[0]; + cosCache[slices] = cosCache[0]; + if (needCache2) { + sinCache2[slices] = sinCache2[0]; + cosCache2[slices] = cosCache2[0]; + } + if (needCache3) { + sinCache3[slices] = sinCache3[0]; + cosCache3[slices] = cosCache3[0]; + } + + switch (qobj->drawStyle) { + case GLU_FILL: + /* Note: + ** An argument could be made for using a TRIANGLE_FAN for the end + ** of the cylinder of either radii is 0.0 (a cone). However, a + ** TRIANGLE_FAN would not work in smooth shading mode (the common + ** case) because the normal for the apex is different for every + ** triangle (and TRIANGLE_FAN doesn't let me respecify that normal). + ** Now, my choice is GL_TRIANGLES, or leave the GL_QUAD_STRIP and + ** just let the GL trivially reject one of the two triangles of the + ** QUAD. GL_QUAD_STRIP is probably faster, so I will leave this code + ** alone. + */ + for (j = 0; j < stacks; j++) { + zLow = j * height / stacks; + zHigh = (j + 1) * height / stacks; + radiusLow = baseRadius - deltaRadius * ((float) j / stacks); + radiusHigh = baseRadius - deltaRadius * ((float) (j + 1) / stacks); + + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= slices; i++) { + switch(qobj->normals) { + case GLU_FLAT: + glNormal3f(sinCache3[i], cosCache3[i], zNormal); + break; + case GLU_SMOOTH: + glNormal3f(sinCache2[i], cosCache2[i], zNormal); + break; + case GLU_NONE: + default: + break; + } + if (qobj->orientation == GLU_OUTSIDE) { + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + (float) j / stacks); + } + glVertex3f(radiusLow * sinCache[i], + radiusLow * cosCache[i], zLow); + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + (float) (j+1) / stacks); + } + glVertex3f(radiusHigh * sinCache[i], + radiusHigh * cosCache[i], zHigh); + } else { + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + (float) (j+1) / stacks); + } + glVertex3f(radiusHigh * sinCache[i], + radiusHigh * cosCache[i], zHigh); + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + (float) j / stacks); + } + glVertex3f(radiusLow * sinCache[i], + radiusLow * cosCache[i], zLow); + } + } + glEnd(); + } + break; + case GLU_POINT: + glBegin(GL_POINTS); + for (i = 0; i < slices; i++) { + switch(qobj->normals) { + case GLU_FLAT: + case GLU_SMOOTH: + glNormal3f(sinCache2[i], cosCache2[i], zNormal); + break; + case GLU_NONE: + default: + break; + } + sintemp = sinCache[i]; + costemp = cosCache[i]; + for (j = 0; j <= stacks; j++) { + zLow = j * height / stacks; + radiusLow = baseRadius - deltaRadius * ((float) j / stacks); + + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + (float) j / stacks); + } + glVertex3f(radiusLow * sintemp, + radiusLow * costemp, zLow); + } + } + glEnd(); + break; + case GLU_LINE: + for (j = 1; j < stacks; j++) { + zLow = j * height / stacks; + radiusLow = baseRadius - deltaRadius * ((float) j / stacks); + + glBegin(GL_LINE_STRIP); + for (i = 0; i <= slices; i++) { + switch(qobj->normals) { + case GLU_FLAT: + glNormal3f(sinCache3[i], cosCache3[i], zNormal); + break; + case GLU_SMOOTH: + glNormal3f(sinCache2[i], cosCache2[i], zNormal); + break; + case GLU_NONE: + default: + break; + } + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + (float) j / stacks); + } + glVertex3f(radiusLow * sinCache[i], + radiusLow * cosCache[i], zLow); + } + glEnd(); + } + /* Intentionally fall through here... */ + case GLU_SILHOUETTE: + for (j = 0; j <= stacks; j += stacks) { + zLow = j * height / stacks; + radiusLow = baseRadius - deltaRadius * ((float) j / stacks); + + glBegin(GL_LINE_STRIP); + for (i = 0; i <= slices; i++) { + switch(qobj->normals) { + case GLU_FLAT: + glNormal3f(sinCache3[i], cosCache3[i], zNormal); + break; + case GLU_SMOOTH: + glNormal3f(sinCache2[i], cosCache2[i], zNormal); + break; + case GLU_NONE: + default: + break; + } + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + (float) j / stacks); + } + glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], + zLow); + } + glEnd(); + } + for (i = 0; i < slices; i++) { + switch(qobj->normals) { + case GLU_FLAT: + case GLU_SMOOTH: + glNormal3f(sinCache2[i], cosCache2[i], 0.0); + break; + case GLU_NONE: + default: + break; + } + sintemp = sinCache[i]; + costemp = cosCache[i]; + glBegin(GL_LINE_STRIP); + for (j = 0; j <= stacks; j++) { + zLow = j * height / stacks; + radiusLow = baseRadius - deltaRadius * ((float) j / stacks); + + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + (float) j / stacks); + } + glVertex3f(radiusLow * sintemp, + radiusLow * costemp, zLow); + } + glEnd(); + } + break; + default: + break; + } +} + +void GLAPIENTRY +gluDisk(GLUquadric *qobj, GLdouble innerRadius, GLdouble outerRadius, + GLint slices, GLint loops) +{ + gluPartialDisk(qobj, innerRadius, outerRadius, slices, loops, 0.0, 360.0); +} + +void GLAPIENTRY +gluPartialDisk(GLUquadric *qobj, GLdouble innerRadius, + GLdouble outerRadius, GLint slices, GLint loops, + GLdouble startAngle, GLdouble sweepAngle) +{ + GLint i,j; + GLfloat sinCache[CACHE_SIZE]; + GLfloat cosCache[CACHE_SIZE]; + GLfloat angle; + GLfloat sintemp, costemp; + GLfloat deltaRadius; + GLfloat radiusLow, radiusHigh; + GLfloat texLow = 0.0, texHigh = 0.0; + GLfloat angleOffset; + GLint slices2; + GLint finish; + + if (slices >= CACHE_SIZE) slices = CACHE_SIZE-1; + if (slices < 2 || loops < 1 || outerRadius <= 0.0 || innerRadius < 0.0 || + innerRadius > outerRadius) { + gluQuadricError(qobj, GLU_INVALID_VALUE); + return; + } + + if (sweepAngle < -360.0) sweepAngle = 360.0; + if (sweepAngle > 360.0) sweepAngle = 360.0; + if (sweepAngle < 0) { + startAngle += sweepAngle; + sweepAngle = -sweepAngle; + } + + if (sweepAngle == 360.0) { + slices2 = slices; + } else { + slices2 = slices + 1; + } + + /* Compute length (needed for normal calculations) */ + deltaRadius = outerRadius - innerRadius; + + /* Cache is the vertex locations cache */ + + angleOffset = startAngle / 180.0 * PI; + for (i = 0; i <= slices; i++) { + angle = angleOffset + ((PI * sweepAngle) / 180.0) * i / slices; + sinCache[i] = SIN(angle); + cosCache[i] = COS(angle); + } + + if (sweepAngle == 360.0) { + sinCache[slices] = sinCache[0]; + cosCache[slices] = cosCache[0]; + } + + switch(qobj->normals) { + case GLU_FLAT: + case GLU_SMOOTH: + if (qobj->orientation == GLU_OUTSIDE) { + glNormal3f(0.0, 0.0, 1.0); + } else { + glNormal3f(0.0, 0.0, -1.0); + } + break; + default: + case GLU_NONE: + break; + } + + switch (qobj->drawStyle) { + case GLU_FILL: + if (innerRadius == 0.0) { + finish = loops - 1; + /* Triangle strip for inner polygons */ + glBegin(GL_TRIANGLE_FAN); + if (qobj->textureCoords) { + glTexCoord2f(0.5, 0.5); + } + glVertex3f(0.0, 0.0, 0.0); + radiusLow = outerRadius - + deltaRadius * ((float) (loops-1) / loops); + if (qobj->textureCoords) { + texLow = radiusLow / outerRadius / 2; + } + + if (qobj->orientation == GLU_OUTSIDE) { + for (i = slices; i >= 0; i--) { + if (qobj->textureCoords) { + glTexCoord2f(texLow * sinCache[i] + 0.5, + texLow * cosCache[i] + 0.5); + } + glVertex3f(radiusLow * sinCache[i], + radiusLow * cosCache[i], 0.0); + } + } else { + for (i = 0; i <= slices; i++) { + if (qobj->textureCoords) { + glTexCoord2f(texLow * sinCache[i] + 0.5, + texLow * cosCache[i] + 0.5); + } + glVertex3f(radiusLow * sinCache[i], + radiusLow * cosCache[i], 0.0); + } + } + glEnd(); + } else { + finish = loops; + } + for (j = 0; j < finish; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + radiusHigh = outerRadius - deltaRadius * ((float) (j + 1) / loops); + if (qobj->textureCoords) { + texLow = radiusLow / outerRadius / 2; + texHigh = radiusHigh / outerRadius / 2; + } + + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= slices; i++) { + if (qobj->orientation == GLU_OUTSIDE) { + if (qobj->textureCoords) { + glTexCoord2f(texLow * sinCache[i] + 0.5, + texLow * cosCache[i] + 0.5); + } + glVertex3f(radiusLow * sinCache[i], + radiusLow * cosCache[i], 0.0); + + if (qobj->textureCoords) { + glTexCoord2f(texHigh * sinCache[i] + 0.5, + texHigh * cosCache[i] + 0.5); + } + glVertex3f(radiusHigh * sinCache[i], + radiusHigh * cosCache[i], 0.0); + } else { + if (qobj->textureCoords) { + glTexCoord2f(texHigh * sinCache[i] + 0.5, + texHigh * cosCache[i] + 0.5); + } + glVertex3f(radiusHigh * sinCache[i], + radiusHigh * cosCache[i], 0.0); + + if (qobj->textureCoords) { + glTexCoord2f(texLow * sinCache[i] + 0.5, + texLow * cosCache[i] + 0.5); + } + glVertex3f(radiusLow * sinCache[i], + radiusLow * cosCache[i], 0.0); + } + } + glEnd(); + } + break; + case GLU_POINT: + glBegin(GL_POINTS); + for (i = 0; i < slices2; i++) { + sintemp = sinCache[i]; + costemp = cosCache[i]; + for (j = 0; j <= loops; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + + if (qobj->textureCoords) { + texLow = radiusLow / outerRadius / 2; + + glTexCoord2f(texLow * sinCache[i] + 0.5, + texLow * cosCache[i] + 0.5); + } + glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0); + } + } + glEnd(); + break; + case GLU_LINE: + if (innerRadius == outerRadius) { + glBegin(GL_LINE_STRIP); + + for (i = 0; i <= slices; i++) { + if (qobj->textureCoords) { + glTexCoord2f(sinCache[i] / 2 + 0.5, + cosCache[i] / 2 + 0.5); + } + glVertex3f(innerRadius * sinCache[i], + innerRadius * cosCache[i], 0.0); + } + glEnd(); + break; + } + for (j = 0; j <= loops; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + if (qobj->textureCoords) { + texLow = radiusLow / outerRadius / 2; + } + + glBegin(GL_LINE_STRIP); + for (i = 0; i <= slices; i++) { + if (qobj->textureCoords) { + glTexCoord2f(texLow * sinCache[i] + 0.5, + texLow * cosCache[i] + 0.5); + } + glVertex3f(radiusLow * sinCache[i], + radiusLow * cosCache[i], 0.0); + } + glEnd(); + } + for (i=0; i < slices2; i++) { + sintemp = sinCache[i]; + costemp = cosCache[i]; + glBegin(GL_LINE_STRIP); + for (j = 0; j <= loops; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + if (qobj->textureCoords) { + texLow = radiusLow / outerRadius / 2; + } + + if (qobj->textureCoords) { + glTexCoord2f(texLow * sinCache[i] + 0.5, + texLow * cosCache[i] + 0.5); + } + glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0); + } + glEnd(); + } + break; + case GLU_SILHOUETTE: + if (sweepAngle < 360.0) { + for (i = 0; i <= slices; i+= slices) { + sintemp = sinCache[i]; + costemp = cosCache[i]; + glBegin(GL_LINE_STRIP); + for (j = 0; j <= loops; j++) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + + if (qobj->textureCoords) { + texLow = radiusLow / outerRadius / 2; + glTexCoord2f(texLow * sinCache[i] + 0.5, + texLow * cosCache[i] + 0.5); + } + glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0); + } + glEnd(); + } + } + for (j = 0; j <= loops; j += loops) { + radiusLow = outerRadius - deltaRadius * ((float) j / loops); + if (qobj->textureCoords) { + texLow = radiusLow / outerRadius / 2; + } + + glBegin(GL_LINE_STRIP); + for (i = 0; i <= slices; i++) { + if (qobj->textureCoords) { + glTexCoord2f(texLow * sinCache[i] + 0.5, + texLow * cosCache[i] + 0.5); + } + glVertex3f(radiusLow * sinCache[i], + radiusLow * cosCache[i], 0.0); + } + glEnd(); + if (innerRadius == outerRadius) break; + } + break; + default: + break; + } +} + +void GLAPIENTRY +gluSphere(GLUquadric *qobj, GLdouble radius, GLint slices, GLint stacks) +{ + GLint i,j; + GLfloat sinCache1a[CACHE_SIZE]; + GLfloat cosCache1a[CACHE_SIZE]; + GLfloat sinCache2a[CACHE_SIZE]; + GLfloat cosCache2a[CACHE_SIZE]; + GLfloat sinCache3a[CACHE_SIZE]; + GLfloat cosCache3a[CACHE_SIZE]; + GLfloat sinCache1b[CACHE_SIZE]; + GLfloat cosCache1b[CACHE_SIZE]; + GLfloat sinCache2b[CACHE_SIZE]; + GLfloat cosCache2b[CACHE_SIZE]; + GLfloat sinCache3b[CACHE_SIZE]; + GLfloat cosCache3b[CACHE_SIZE]; + GLfloat angle; + GLfloat zLow, zHigh; + GLfloat sintemp1 = 0.0, sintemp2 = 0.0, sintemp3 = 0.0, sintemp4 = 0.0; + GLfloat costemp1 = 0.0, costemp2 = 0.0, costemp3 = 0.0, costemp4 = 0.0; + GLboolean needCache2, needCache3; + GLint start, finish; + + if (slices >= CACHE_SIZE) slices = CACHE_SIZE-1; + if (stacks >= CACHE_SIZE) stacks = CACHE_SIZE-1; + if (slices < 2 || stacks < 1 || radius < 0.0) { + gluQuadricError(qobj, GLU_INVALID_VALUE); + return; + } + + /* Cache is the vertex locations cache */ + /* Cache2 is the various normals at the vertices themselves */ + /* Cache3 is the various normals for the faces */ + needCache2 = needCache3 = GL_FALSE; + + if (qobj->normals == GLU_SMOOTH) { + needCache2 = GL_TRUE; + } + + if (qobj->normals == GLU_FLAT) { + if (qobj->drawStyle != GLU_POINT) { + needCache3 = GL_TRUE; + } + if (qobj->drawStyle == GLU_LINE) { + needCache2 = GL_TRUE; + } + } + + for (i = 0; i < slices; i++) { + angle = 2 * PI * i / slices; + sinCache1a[i] = SIN(angle); + cosCache1a[i] = COS(angle); + if (needCache2) { + sinCache2a[i] = sinCache1a[i]; + cosCache2a[i] = cosCache1a[i]; + } + } + + for (j = 0; j <= stacks; j++) { + angle = PI * j / stacks; + if (needCache2) { + if (qobj->orientation == GLU_OUTSIDE) { + sinCache2b[j] = SIN(angle); + cosCache2b[j] = COS(angle); + } else { + sinCache2b[j] = -SIN(angle); + cosCache2b[j] = -COS(angle); + } + } + sinCache1b[j] = radius * SIN(angle); + cosCache1b[j] = radius * COS(angle); + } + /* Make sure it comes to a point */ + sinCache1b[0] = 0; + sinCache1b[stacks] = 0; + + if (needCache3) { + for (i = 0; i < slices; i++) { + angle = 2 * PI * (i-0.5) / slices; + sinCache3a[i] = SIN(angle); + cosCache3a[i] = COS(angle); + } + for (j = 0; j <= stacks; j++) { + angle = PI * (j - 0.5) / stacks; + if (qobj->orientation == GLU_OUTSIDE) { + sinCache3b[j] = SIN(angle); + cosCache3b[j] = COS(angle); + } else { + sinCache3b[j] = -SIN(angle); + cosCache3b[j] = -COS(angle); + } + } + } + + sinCache1a[slices] = sinCache1a[0]; + cosCache1a[slices] = cosCache1a[0]; + if (needCache2) { + sinCache2a[slices] = sinCache2a[0]; + cosCache2a[slices] = cosCache2a[0]; + } + if (needCache3) { + sinCache3a[slices] = sinCache3a[0]; + cosCache3a[slices] = cosCache3a[0]; + } + + switch (qobj->drawStyle) { + case GLU_FILL: + /* Do ends of sphere as TRIANGLE_FAN's (if not texturing) + ** We don't do it when texturing because we need to respecify the + ** texture coordinates of the apex for every adjacent vertex (because + ** it isn't a constant for that point) + */ + if (!(qobj->textureCoords)) { + start = 1; + finish = stacks - 1; + + /* Low end first (j == 0 iteration) */ + sintemp2 = sinCache1b[1]; + zHigh = cosCache1b[1]; + switch(qobj->normals) { + case GLU_FLAT: + sintemp3 = sinCache3b[1]; + costemp3 = cosCache3b[1]; + break; + case GLU_SMOOTH: + sintemp3 = sinCache2b[1]; + costemp3 = cosCache2b[1]; + glNormal3f(sinCache2a[0] * sinCache2b[0], + cosCache2a[0] * sinCache2b[0], + cosCache2b[0]); + break; + default: + break; + } + glBegin(GL_TRIANGLE_FAN); + glVertex3f(0.0, 0.0, radius); + if (qobj->orientation == GLU_OUTSIDE) { + for (i = slices; i >= 0; i--) { + switch(qobj->normals) { + case GLU_SMOOTH: + glNormal3f(sinCache2a[i] * sintemp3, + cosCache2a[i] * sintemp3, + costemp3); + break; + case GLU_FLAT: + if (i != slices) { + glNormal3f(sinCache3a[i+1] * sintemp3, + cosCache3a[i+1] * sintemp3, + costemp3); + } + break; + case GLU_NONE: + default: + break; + } + glVertex3f(sintemp2 * sinCache1a[i], + sintemp2 * cosCache1a[i], zHigh); + } + } else { + for (i = 0; i <= slices; i++) { + switch(qobj->normals) { + case GLU_SMOOTH: + glNormal3f(sinCache2a[i] * sintemp3, + cosCache2a[i] * sintemp3, + costemp3); + break; + case GLU_FLAT: + glNormal3f(sinCache3a[i] * sintemp3, + cosCache3a[i] * sintemp3, + costemp3); + break; + case GLU_NONE: + default: + break; + } + glVertex3f(sintemp2 * sinCache1a[i], + sintemp2 * cosCache1a[i], zHigh); + } + } + glEnd(); + + /* High end next (j == stacks-1 iteration) */ + sintemp2 = sinCache1b[stacks-1]; + zHigh = cosCache1b[stacks-1]; + switch(qobj->normals) { + case GLU_FLAT: + sintemp3 = sinCache3b[stacks]; + costemp3 = cosCache3b[stacks]; + break; + case GLU_SMOOTH: + sintemp3 = sinCache2b[stacks-1]; + costemp3 = cosCache2b[stacks-1]; + glNormal3f(sinCache2a[stacks] * sinCache2b[stacks], + cosCache2a[stacks] * sinCache2b[stacks], + cosCache2b[stacks]); + break; + default: + break; + } + glBegin(GL_TRIANGLE_FAN); + glVertex3f(0.0, 0.0, -radius); + if (qobj->orientation == GLU_OUTSIDE) { + for (i = 0; i <= slices; i++) { + switch(qobj->normals) { + case GLU_SMOOTH: + glNormal3f(sinCache2a[i] * sintemp3, + cosCache2a[i] * sintemp3, + costemp3); + break; + case GLU_FLAT: + glNormal3f(sinCache3a[i] * sintemp3, + cosCache3a[i] * sintemp3, + costemp3); + break; + case GLU_NONE: + default: + break; + } + glVertex3f(sintemp2 * sinCache1a[i], + sintemp2 * cosCache1a[i], zHigh); + } + } else { + for (i = slices; i >= 0; i--) { + switch(qobj->normals) { + case GLU_SMOOTH: + glNormal3f(sinCache2a[i] * sintemp3, + cosCache2a[i] * sintemp3, + costemp3); + break; + case GLU_FLAT: + if (i != slices) { + glNormal3f(sinCache3a[i+1] * sintemp3, + cosCache3a[i+1] * sintemp3, + costemp3); + } + break; + case GLU_NONE: + default: + break; + } + glVertex3f(sintemp2 * sinCache1a[i], + sintemp2 * cosCache1a[i], zHigh); + } + } + glEnd(); + } else { + start = 0; + finish = stacks; + } + for (j = start; j < finish; j++) { + zLow = cosCache1b[j]; + zHigh = cosCache1b[j+1]; + sintemp1 = sinCache1b[j]; + sintemp2 = sinCache1b[j+1]; + switch(qobj->normals) { + case GLU_FLAT: + sintemp4 = sinCache3b[j+1]; + costemp4 = cosCache3b[j+1]; + break; + case GLU_SMOOTH: + if (qobj->orientation == GLU_OUTSIDE) { + sintemp3 = sinCache2b[j+1]; + costemp3 = cosCache2b[j+1]; + sintemp4 = sinCache2b[j]; + costemp4 = cosCache2b[j]; + } else { + sintemp3 = sinCache2b[j]; + costemp3 = cosCache2b[j]; + sintemp4 = sinCache2b[j+1]; + costemp4 = cosCache2b[j+1]; + } + break; + default: + break; + } + + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= slices; i++) { + switch(qobj->normals) { + case GLU_SMOOTH: + glNormal3f(sinCache2a[i] * sintemp3, + cosCache2a[i] * sintemp3, + costemp3); + break; + case GLU_FLAT: + case GLU_NONE: + default: + break; + } + if (qobj->orientation == GLU_OUTSIDE) { + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + 1 - (float) (j+1) / stacks); + } + glVertex3f(sintemp2 * sinCache1a[i], + sintemp2 * cosCache1a[i], zHigh); + } else { + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + 1 - (float) j / stacks); + } + glVertex3f(sintemp1 * sinCache1a[i], + sintemp1 * cosCache1a[i], zLow); + } + switch(qobj->normals) { + case GLU_SMOOTH: + glNormal3f(sinCache2a[i] * sintemp4, + cosCache2a[i] * sintemp4, + costemp4); + break; + case GLU_FLAT: + glNormal3f(sinCache3a[i] * sintemp4, + cosCache3a[i] * sintemp4, + costemp4); + break; + case GLU_NONE: + default: + break; + } + if (qobj->orientation == GLU_OUTSIDE) { + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + 1 - (float) j / stacks); + } + glVertex3f(sintemp1 * sinCache1a[i], + sintemp1 * cosCache1a[i], zLow); + } else { + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + 1 - (float) (j+1) / stacks); + } + glVertex3f(sintemp2 * sinCache1a[i], + sintemp2 * cosCache1a[i], zHigh); + } + } + glEnd(); + } + break; + case GLU_POINT: + glBegin(GL_POINTS); + for (j = 0; j <= stacks; j++) { + sintemp1 = sinCache1b[j]; + costemp1 = cosCache1b[j]; + switch(qobj->normals) { + case GLU_FLAT: + case GLU_SMOOTH: + sintemp2 = sinCache2b[j]; + costemp2 = cosCache2b[j]; + break; + default: + break; + } + for (i = 0; i < slices; i++) { + switch(qobj->normals) { + case GLU_FLAT: + case GLU_SMOOTH: + glNormal3f(sinCache2a[i] * sintemp2, + cosCache2a[i] * sintemp2, + costemp2); + break; + case GLU_NONE: + default: + break; + } + + zLow = j * radius / stacks; + + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + 1 - (float) j / stacks); + } + glVertex3f(sintemp1 * sinCache1a[i], + sintemp1 * cosCache1a[i], costemp1); + } + } + glEnd(); + break; + case GLU_LINE: + case GLU_SILHOUETTE: + for (j = 1; j < stacks; j++) { + sintemp1 = sinCache1b[j]; + costemp1 = cosCache1b[j]; + switch(qobj->normals) { + case GLU_FLAT: + case GLU_SMOOTH: + sintemp2 = sinCache2b[j]; + costemp2 = cosCache2b[j]; + break; + default: + break; + } + + glBegin(GL_LINE_STRIP); + for (i = 0; i <= slices; i++) { + switch(qobj->normals) { + case GLU_FLAT: + glNormal3f(sinCache3a[i] * sintemp2, + cosCache3a[i] * sintemp2, + costemp2); + break; + case GLU_SMOOTH: + glNormal3f(sinCache2a[i] * sintemp2, + cosCache2a[i] * sintemp2, + costemp2); + break; + case GLU_NONE: + default: + break; + } + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + 1 - (float) j / stacks); + } + glVertex3f(sintemp1 * sinCache1a[i], + sintemp1 * cosCache1a[i], costemp1); + } + glEnd(); + } + for (i = 0; i < slices; i++) { + sintemp1 = sinCache1a[i]; + costemp1 = cosCache1a[i]; + switch(qobj->normals) { + case GLU_FLAT: + case GLU_SMOOTH: + sintemp2 = sinCache2a[i]; + costemp2 = cosCache2a[i]; + break; + default: + break; + } + + glBegin(GL_LINE_STRIP); + for (j = 0; j <= stacks; j++) { + switch(qobj->normals) { + case GLU_FLAT: + glNormal3f(sintemp2 * sinCache3b[j], + costemp2 * sinCache3b[j], + cosCache3b[j]); + break; + case GLU_SMOOTH: + glNormal3f(sintemp2 * sinCache2b[j], + costemp2 * sinCache2b[j], + cosCache2b[j]); + break; + case GLU_NONE: + default: + break; + } + + if (qobj->textureCoords) { + glTexCoord2f(1 - (float) i / slices, + 1 - (float) j / stacks); + } + glVertex3f(sintemp1 * sinCache1b[j], + costemp1 * sinCache1b[j], cosCache1b[j]); + } + glEnd(); + } + break; + default: + break; + } +} diff --git a/src/glu/sgi/libutil/registry.c b/src/glu/sgi/libutil/registry.c new file mode 100644 index 0000000..2e3b574 --- /dev/null +++ b/src/glu/sgi/libutil/registry.c @@ -0,0 +1,91 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "gluos.h" +#include +#include +#include +#include + +static const GLubyte versionString[] = "1.3"; +static const GLubyte extensionString[] = + "GLU_EXT_nurbs_tessellator " + "GLU_EXT_object_space_tess " + ; + +const GLubyte * GLAPIENTRY +gluGetString(GLenum name) +{ + + if (name == GLU_VERSION) { + return versionString; + } else if (name == GLU_EXTENSIONS) { + return extensionString; + } + return NULL; +} + +/* extName is an extension name. + * extString is a string of extensions separated by blank(s). There may or + * may not be leading or trailing blank(s) in extString. + * This works in cases of extensions being prefixes of another like + * GL_EXT_texture and GL_EXT_texture3D. + * Returns GL_TRUE if extName is found otherwise it returns GL_FALSE. + */ +GLboolean GLAPIENTRY +gluCheckExtension(const GLubyte *extName, const GLubyte *extString) +{ + GLboolean flag = GL_FALSE; + char *word; + char *lookHere; + char *deleteThis; + + if (extString == NULL) return GL_FALSE; + + deleteThis = lookHere = (char *)malloc(strlen((const char *)extString)+1); + if (lookHere == NULL) + return GL_FALSE; + /* strtok() will modify string, so copy it somewhere */ + strcpy(lookHere,(const char *)extString); + + while ((word= strtok(lookHere," ")) != NULL) { + if (strcmp(word,(const char *)extName) == 0) { + flag = GL_TRUE; + break; + } + lookHere = NULL; /* get next token */ + } + free((void *)deleteThis); + return flag; +} /* gluCheckExtension() */ + + + +/*** registry.c ***/ diff --git a/src/glu/sgi/mesaglu.opt b/src/glu/sgi/mesaglu.opt new file mode 100644 index 0000000..9bac432 --- /dev/null +++ b/src/glu/sgi/mesaglu.opt @@ -0,0 +1,67 @@ +! +! ### UNIVERSAL procedures and global definitions extracted from MESAGL.MAP +! +case_sensitive=YES +symbol_vector = (gluErrorString = PROCEDURE) +symbol_vector = (__gluNURBSErrorString = PROCEDURE) +symbol_vector = (__gluTessErrorString = PROCEDURE) +symbol_vector = (gluBuild3DMipmaps = PROCEDURE) +symbol_vector = (gluBuild3DMipmapLevels = PROCEDURE) +symbol_vector = (gluBuild2DMipmaps = PROCEDURE) +symbol_vector = (gluBuild2DMipmapLevels = PROCEDURE) +symbol_vector = (gluBuild1DMipmaps = PROCEDURE) +symbol_vector = (gluBuild1DMipmapLevels = PROCEDURE) +symbol_vector = (gluScaleImage = PROCEDURE) +symbol_vector = (gluPickMatrix = PROCEDURE) +symbol_vector = (gluUnProject4 = PROCEDURE) +symbol_vector = (gluUnProject = PROCEDURE) +symbol_vector = (gluProject = PROCEDURE) +symbol_vector = (gluLookAt = PROCEDURE) +symbol_vector = (gluPerspective = PROCEDURE) +symbol_vector = (gluOrtho2D = PROCEDURE) +symbol_vector = (gluNewQuadric = PROCEDURE) +symbol_vector = (gluSphere = PROCEDURE) +symbol_vector = (gluPartialDisk = PROCEDURE) +symbol_vector = (gluDisk = PROCEDURE) +symbol_vector = (gluCylinder = PROCEDURE) +symbol_vector = (gluQuadricDrawStyle = PROCEDURE) +symbol_vector = (gluQuadricOrientation = PROCEDURE) +symbol_vector = (gluQuadricTexture = PROCEDURE) +symbol_vector = (gluQuadricNormals = PROCEDURE) +symbol_vector = (gluQuadricCallback = PROCEDURE) +symbol_vector = (gluDeleteQuadric = PROCEDURE) +symbol_vector = (gluGetString = PROCEDURE) +symbol_vector = (gluCheckExtension = PROCEDURE) +symbol_vector = (gluTessEndContour = PROCEDURE) +symbol_vector = (gluTessBeginContour = PROCEDURE) +symbol_vector = (gluTessBeginPolygon = PROCEDURE) +symbol_vector = (gluTessEndPolygon = PROCEDURE) +symbol_vector = (gluEndPolygon = PROCEDURE) +symbol_vector = (gluNextContour = PROCEDURE) +symbol_vector = (gluBeginPolygon = PROCEDURE) +symbol_vector = (gluTessVertex = PROCEDURE) +symbol_vector = (gluTessCallback = PROCEDURE) +symbol_vector = (gluTessNormal = PROCEDURE) +symbol_vector = (gluGetTessProperty = PROCEDURE) +symbol_vector = (gluTessProperty = PROCEDURE) +symbol_vector = (gluDeleteTess = PROCEDURE) +symbol_vector = (gluNewTess = PROCEDURE) +symbol_vector = (gluNurbsCallbackDataEXT = PROCEDURE) +symbol_vector = (gluNurbsCallbackData = PROCEDURE) +symbol_vector = (gluNurbsCallback = PROCEDURE) +symbol_vector = (gluGetNurbsProperty = PROCEDURE) +symbol_vector = (gluNurbsProperty = PROCEDURE) +symbol_vector = (gluLoadSamplingMatrices = PROCEDURE) +symbol_vector = (gluNurbsSurface = PROCEDURE) +symbol_vector = (gluNurbsCurve = PROCEDURE) +symbol_vector = (gluPwlCurve = PROCEDURE) +symbol_vector = (gluEndTrim = PROCEDURE) +symbol_vector = (gluBeginTrim = PROCEDURE) +symbol_vector = (gluEndSurface = PROCEDURE) +symbol_vector = (gluEndCurve = PROCEDURE) +symbol_vector = (gluBeginCurve = PROCEDURE) +symbol_vector = (gluBeginSurface = PROCEDURE) +symbol_vector = (gluDeleteNurbsTessellatorEXT = PROCEDURE) +symbol_vector = (gluDeleteNurbsRenderer = PROCEDURE) +symbol_vector = (gluNewNurbsRenderer = PROCEDURE) +symbol_vector = (glu_LOD_eval_list = PROCEDURE) diff --git a/src/glw/GLwDrawA.c b/src/glw/GLwDrawA.c new file mode 100644 index 0000000..30304a4 --- /dev/null +++ b/src/glw/GLwDrawA.c @@ -0,0 +1,684 @@ +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ + +/* + * + * This file has been slightly modified from the original for use with Mesa + * + * Jeroen van der Zijp + * + * jvz@cyberia.cfdrc.com + * + */ +#include +#include +#include +#include +#ifdef __GLX_MOTIF +#include +#include "GLwMDrawAP.h" +#else +#include "GLwDrawAP.h" +#endif +#include +#include + +#ifdef __GLX_MOTIF +#define GLwDrawingAreaWidget GLwMDrawingAreaWidget +#define GLwDrawingAreaClassRec GLwMDrawingAreaClassRec +#define glwDrawingAreaClassRec glwMDrawingAreaClassRec +#define glwDrawingAreaWidgetClass glwMDrawingAreaWidgetClass +#define GLwDrawingAreaRec GLwMDrawingAreaRec +#endif + +#define ATTRIBLIST_SIZE 32 + +#define offset(field) XtOffset(GLwDrawingAreaWidget,glwDrawingArea.field) + + +/* forward definitions */ +static void createColormap(GLwDrawingAreaWidget w,int offset,XrmValue *value); +static void Initialize(GLwDrawingAreaWidget req,GLwDrawingAreaWidget neww,ArgList args,Cardinal *num_args); +static void Realize(Widget w,Mask *valueMask,XSetWindowAttributes *attributes); +static void Redraw(GLwDrawingAreaWidget w,XEvent *event,Region region); +static void Resize(GLwDrawingAreaWidget glw); +static void Destroy(GLwDrawingAreaWidget glw); +static void glwInput(GLwDrawingAreaWidget glw,XEvent *event,String *params,Cardinal *numParams); + + + +static char defaultTranslations[] = +#ifdef __GLX_MOTIF + "osfHelp:PrimitiveHelp() \n" +#endif + ": glwInput() \n\ + : glwInput() \n\ + : glwInput() \n\ + : glwInput() \n\ + : glwInput() "; + + +static XtActionsRec actions[] = { + {"glwInput",(XtActionProc)glwInput}, /* key or mouse input */ + }; + + +/* + * There is a bit of unusual handling of the resources here. + * Because Xt insists on allocating the colormap resource when it is + * processing the core resources (even if we redeclare the colormap + * resource here, we need to do a little trick. When Xt first allocates + * the colormap, we allow it to allocate the default one, since we have + * not yet determined the appropriate visual (which is determined from + * resources parsed after the colormap). We also let it allocate colors + * in that default colormap. + * + * In the initialize proc we calculate the actual visual. Then, we + * reobtain the colormap resource using XtGetApplicationResources in + * the initialize proc. If requested, we also reallocate colors in + * that colormap using the same method. + */ + +static XtResource resources[] = { + /* The GLX attributes. Add any new attributes here */ + + {GLwNbufferSize, GLwCBufferSize, XtRInt, sizeof (int), + offset(bufferSize), XtRImmediate, (XtPointer) 0}, + + {GLwNlevel, GLwCLevel, XtRInt, sizeof (int), + offset(level), XtRImmediate, (XtPointer) 0}, + + {GLwNrgba, GLwCRgba, XtRBoolean, sizeof (Boolean), + offset(rgba), XtRImmediate, (XtPointer) FALSE}, + + {GLwNdoublebuffer, GLwCDoublebuffer, XtRBoolean, sizeof (Boolean), + offset(doublebuffer), XtRImmediate, (XtPointer) FALSE}, + + {GLwNstereo, GLwCStereo, XtRBoolean, sizeof (Boolean), + offset(stereo), XtRImmediate, (XtPointer) FALSE}, + + {GLwNauxBuffers, GLwCAuxBuffers, XtRInt, sizeof (int), + offset(auxBuffers), XtRImmediate, (XtPointer) 0}, + + {GLwNredSize, GLwCColorSize, XtRInt, sizeof (int), + offset(redSize), XtRImmediate, (XtPointer) 1}, + + {GLwNgreenSize, GLwCColorSize, XtRInt, sizeof (int), + offset(greenSize), XtRImmediate, (XtPointer) 1}, + + {GLwNblueSize, GLwCColorSize, XtRInt, sizeof (int), + offset(blueSize), XtRImmediate, (XtPointer) 1}, + + {GLwNalphaSize, GLwCAlphaSize, XtRInt, sizeof (int), + offset(alphaSize), XtRImmediate, (XtPointer) 0}, + + {GLwNdepthSize, GLwCDepthSize, XtRInt, sizeof (int), + offset(depthSize), XtRImmediate, (XtPointer) 0}, + + {GLwNstencilSize, GLwCStencilSize, XtRInt, sizeof (int), + offset(stencilSize), XtRImmediate, (XtPointer) 0}, + + {GLwNaccumRedSize, GLwCAccumColorSize, XtRInt, sizeof (int), + offset(accumRedSize), XtRImmediate, (XtPointer) 0}, + + {GLwNaccumGreenSize, GLwCAccumColorSize, XtRInt, sizeof (int), + offset(accumGreenSize), XtRImmediate, (XtPointer) 0}, + + {GLwNaccumBlueSize, GLwCAccumColorSize, XtRInt, sizeof (int), + offset(accumBlueSize), XtRImmediate, (XtPointer) 0}, + + {GLwNaccumAlphaSize, GLwCAccumAlphaSize, XtRInt, sizeof (int), + offset(accumAlphaSize), XtRImmediate, (XtPointer) 0}, + + /* the attribute list */ + {GLwNattribList, GLwCAttribList, XtRPointer, sizeof(int *), + offset(attribList), XtRImmediate, (XtPointer) NULL}, + + /* the visual info */ + {GLwNvisualInfo, GLwCVisualInfo, GLwRVisualInfo, sizeof (XVisualInfo *), + offset(visualInfo), XtRImmediate, (XtPointer) NULL}, + + /* miscellaneous resources */ + {GLwNinstallColormap, GLwCInstallColormap, XtRBoolean, sizeof (Boolean), + offset(installColormap), XtRImmediate, (XtPointer) TRUE}, + + {GLwNallocateBackground, GLwCAllocateColors, XtRBoolean, sizeof (Boolean), + offset(allocateBackground), XtRImmediate, (XtPointer) FALSE}, + + {GLwNallocateOtherColors, GLwCAllocateColors, XtRBoolean, sizeof (Boolean), + offset(allocateOtherColors), XtRImmediate, (XtPointer) FALSE}, + + {GLwNinstallBackground, GLwCInstallBackground, XtRBoolean, sizeof (Boolean), + offset(installBackground), XtRImmediate, (XtPointer) TRUE}, + + {GLwNginitCallback, GLwCCallback, XtRCallback, sizeof (XtCallbackList), + offset(ginitCallback), XtRImmediate, (XtPointer) NULL}, + + {GLwNinputCallback, GLwCCallback, XtRCallback, sizeof (XtCallbackList), + offset(inputCallback), XtRImmediate, (XtPointer) NULL}, + + {GLwNresizeCallback, GLwCCallback, XtRCallback, sizeof (XtCallbackList), + offset(resizeCallback), XtRImmediate, (XtPointer) NULL}, + + {GLwNexposeCallback, GLwCCallback, XtRCallback, sizeof (XtCallbackList), + offset(exposeCallback), XtRImmediate, (XtPointer) NULL}, + + /* Changes to Motif primitive resources */ +#ifdef __GLX_MOTIF + {XmNtraversalOn, XmCTraversalOn, XmRBoolean, sizeof (Boolean), + XtOffset (GLwDrawingAreaWidget, primitive.traversal_on), XmRImmediate, + (XtPointer)FALSE}, + + /* highlighting is normally disabled, as when Motif tries to disable + * highlighting, it tries to reset the color back to the parent's + * background (usually Motif blue). Unfortunately, that is in a + * different colormap, and doesn't work too well. + */ + {XmNhighlightOnEnter, XmCHighlightOnEnter, XmRBoolean, sizeof (Boolean), + XtOffset (GLwDrawingAreaWidget, primitive.highlight_on_enter), + XmRImmediate, (XtPointer) FALSE}, + + {XmNhighlightThickness, XmCHighlightThickness, XmRHorizontalDimension, + sizeof (Dimension), + XtOffset (GLwDrawingAreaWidget, primitive.highlight_thickness), + XmRImmediate, (XtPointer) 0}, +#endif + }; + + +/* +** The following resources are reobtained using XtGetApplicationResources +** in the initialize proc. +*/ + +/* The colormap */ +static XtResource initializeResources[] = { + /* reobtain the colormap with the new visual */ + {XtNcolormap, XtCColormap, XtRColormap, sizeof(Colormap), + XtOffset(GLwDrawingAreaWidget, core.colormap), + XtRCallProc,(XtPointer) createColormap}, + }; + + +/* reallocate any colors we need in the new colormap */ + +/* The background is obtained only if the allocateBackground resource is TRUE*/ +static XtResource backgroundResources[] = { +#ifdef __GLX_MOTIF + {XmNbackground, XmCBackground,XmRPixel, + sizeof(Pixel),XtOffset(GLwDrawingAreaWidget,core.background_pixel), + XmRString,(XtPointer)"lightgrey"}, + /*XmRCallProc,(XtPointer)_XmBackgroundColorDefault},*/ + + {XmNbackgroundPixmap,XmCPixmap,XmRXmBackgroundPixmap, + sizeof(Pixmap),XtOffset(GLwDrawingAreaWidget,core.background_pixmap), + XmRImmediate,(XtPointer)XmUNSPECIFIED_PIXMAP}, + +#else + {XtNbackground,XtCBackground,XtRPixel,sizeof(Pixel), + XtOffset(GLwDrawingAreaWidget,core.background_pixel), + XtRString,(XtPointer)"lightgrey"}, + /*XtRString,(XtPointer)"XtDefaultBackground"},*/ + + {XtNbackgroundPixmap, XtCPixmap, XtRPixmap, sizeof(Pixmap), + XtOffset(GLwDrawingAreaWidget,core.background_pixmap), + XtRImmediate,(XtPointer)XtUnspecifiedPixmap}, +#endif + }; + + + +/* The other colors such as the foreground are allocated only if + * allocateOtherColors are set. These resources only exist in Motif. + */ +#ifdef __GLX_MOTIF +static XtResource otherColorResources[] = { + {XmNforeground,XmCForeground,XmRPixel, + sizeof(Pixel),XtOffset(GLwDrawingAreaWidget,primitive.foreground), + XmRString,(XtPointer)"lighgrey"}, + /*XmRCallProc, (XtPointer) _XmForegroundColorDefault},*/ + + {XmNhighlightColor,XmCHighlightColor,XmRPixel,sizeof(Pixel), + XtOffset(GLwDrawingAreaWidget,primitive.highlight_color), + XmRString,(XtPointer)"lightgrey"}, + /*XmRCallProc,(XtPointer)_XmHighlightColorDefault},*/ + + {XmNhighlightPixmap,XmCHighlightPixmap,XmRPrimHighlightPixmap, + sizeof(Pixmap), + XtOffset(GLwDrawingAreaWidget,primitive.highlight_pixmap), + XmRImmediate,(XtPointer)XmUNSPECIFIED_PIXMAP}, + /*XmRCallProc,(XtPointer)_XmPrimitiveHighlightPixmapDefault},*/ + }; +#endif + + +#undef offset + + +GLwDrawingAreaClassRec glwDrawingAreaClassRec = { + { /* core fields */ +#ifdef __GLX_MOTIF + /* superclass */ (WidgetClass) &xmPrimitiveClassRec, + /* class_name */ "GLwMDrawingArea", +#else /* not __GLX_MOTIF */ + /* superclass */ (WidgetClass) &widgetClassRec, + /* class_name */ "GLwDrawingArea", +#endif /* __GLX_MOTIF */ + /* widget_size */ sizeof(GLwDrawingAreaRec), + /* class_initialize */ NULL, + /* class_part_initialize */ NULL, + /* class_inited */ FALSE, + /* initialize */ (XtInitProc) Initialize, + /* initialize_hook */ NULL, + /* realize */ Realize, + /* actions */ actions, + /* num_actions */ XtNumber(actions), + /* resources */ resources, + /* num_resources */ XtNumber(resources), + /* xrm_class */ NULLQUARK, + /* compress_motion */ TRUE, + /* compress_exposure */ TRUE, + /* compress_enterleave */ TRUE, + /* visible_interest */ TRUE, + /* destroy */ (XtWidgetProc) Destroy, + /* resize */ (XtWidgetProc) Resize, + /* expose */ (XtExposeProc) Redraw, + /* set_values */ NULL, + /* set_values_hook */ NULL, + /* set_values_almost */ XtInheritSetValuesAlmost, + /* get_values_hook */ NULL, + /* accept_focus */ NULL, + /* version */ XtVersion, + /* callback_private */ NULL, + /* tm_table */ defaultTranslations, + /* query_geometry */ XtInheritQueryGeometry, + /* display_accelerator */ XtInheritDisplayAccelerator, + /* extension */ NULL + }, +#ifdef __GLX_MOTIF /* primitive resources */ + { + /* border_highlight */ XmInheritBorderHighlight, + /* border_unhighlight */ XmInheritBorderUnhighlight, + /* translations */ XtInheritTranslations, + /* arm_and_activate */ NULL, + /* get_resources */ NULL, + /* num get_resources */ 0, + /* extension */ NULL, + } +#endif + }; + +WidgetClass glwDrawingAreaWidgetClass=(WidgetClass)&glwDrawingAreaClassRec; + + + +static void error(Widget w,char* string){ + char buf[100]; +#ifdef __GLX_MOTIF + sprintf(buf,"GLwMDrawingArea: %s\n",string); +#else + sprintf(buf,"GLwDrawingArea: %s\n",string); +#endif + XtAppError(XtWidgetToApplicationContext(w),buf); + } + + +static void warning(Widget w,char* string){ + char buf[100]; +#ifdef __GLX_MOTIF + sprintf (buf, "GLwMDraw: %s\n", string); +#else + sprintf (buf, "GLwDraw: %s\n", string); +#endif + XtAppWarning(XtWidgetToApplicationContext(w), buf); + } + + + +/* Initialize the attribList based on the attributes */ +static void createAttribList(GLwDrawingAreaWidget w){ + int *ptr; + w->glwDrawingArea.attribList = (int*)XtMalloc(ATTRIBLIST_SIZE*sizeof(int)); + if(!w->glwDrawingArea.attribList){ + error((Widget)w,"Unable to allocate attribute list"); + } + ptr = w->glwDrawingArea.attribList; + *ptr++ = GLX_BUFFER_SIZE; + *ptr++ = w->glwDrawingArea.bufferSize; + *ptr++ = GLX_LEVEL; + *ptr++ = w->glwDrawingArea.level; + if(w->glwDrawingArea.rgba) *ptr++ = GLX_RGBA; + if(w->glwDrawingArea.doublebuffer) *ptr++ = GLX_DOUBLEBUFFER; + if(w->glwDrawingArea.stereo) *ptr++ = GLX_STEREO; + *ptr++ = GLX_AUX_BUFFERS; + *ptr++ = w->glwDrawingArea.auxBuffers; + *ptr++ = GLX_RED_SIZE; + *ptr++ = w->glwDrawingArea.redSize; + *ptr++ = GLX_GREEN_SIZE; + *ptr++ = w->glwDrawingArea.greenSize; + *ptr++ = GLX_BLUE_SIZE; + *ptr++ = w->glwDrawingArea.blueSize; + *ptr++ = GLX_ALPHA_SIZE; + *ptr++ = w->glwDrawingArea.alphaSize; + *ptr++ = GLX_DEPTH_SIZE; + *ptr++ = w->glwDrawingArea.depthSize; + *ptr++ = GLX_STENCIL_SIZE; + *ptr++ = w->glwDrawingArea.stencilSize; + *ptr++ = GLX_ACCUM_RED_SIZE; + *ptr++ = w->glwDrawingArea.accumRedSize; + *ptr++ = GLX_ACCUM_GREEN_SIZE; + *ptr++ = w->glwDrawingArea.accumGreenSize; + *ptr++ = GLX_ACCUM_BLUE_SIZE; + *ptr++ = w->glwDrawingArea.accumBlueSize; + *ptr++ = GLX_ACCUM_ALPHA_SIZE; + *ptr++ = w->glwDrawingArea.accumAlphaSize; + *ptr++ = None; + assert((ptr-w->glwDrawingArea.attribList)glwDrawingArea.attribList); + w->glwDrawingArea.visualInfo=glXChooseVisual(XtDisplay(w),XScreenNumberOfScreen(XtScreen(w)),w->glwDrawingArea.attribList); + if(!w->glwDrawingArea.visualInfo) error((Widget)w,"requested visual not supported"); + } + + + +/* Initialize the colormap based on the visual info. + * This routine maintains a cache of visual-infos to colormaps. If two + * widgets share the same visual info, they share the same colormap. + * This function is called by the callProc of the colormap resource entry. + */ +static void createColormap(GLwDrawingAreaWidget w,int offset,XrmValue *value){ + static struct cmapCache { Visual *visual; Colormap cmap; } *cmapCache; + static int cacheEntries=0; + static int cacheMalloced=0; + register int i; + + assert(w->glwDrawingArea.visualInfo); + + /* see if we can find it in the cache */ + for(i=0; iglwDrawingArea.visualInfo->visual){ + value->addr=(XtPointer)(&cmapCache[i].cmap); + return; + } + } + + /* not in the cache, create a new entry */ + if(cacheEntries >= cacheMalloced){ + /* need to malloc a new one. Since we are likely to have only a + * few colormaps, we allocate one the first time, and double + * each subsequent time. + */ + if(cacheMalloced==0){ + cacheMalloced=1; + cmapCache=(struct cmapCache*)XtMalloc(sizeof(struct cmapCache)); + } + else{ + cacheMalloced<<=1; + cmapCache=(struct cmapCache*)XtRealloc((char*)cmapCache,sizeof(struct cmapCache)*cacheMalloced); + } + } + + cmapCache[cacheEntries].cmap=XCreateColormap(XtDisplay(w), + RootWindow(XtDisplay(w), + w->glwDrawingArea.visualInfo->screen), + w->glwDrawingArea.visualInfo->visual, + AllocNone); + cmapCache[cacheEntries].visual=w->glwDrawingArea.visualInfo->visual; + value->addr=(XtPointer)(&cmapCache[cacheEntries++].cmap); + } + + + +static void Initialize(GLwDrawingAreaWidget req,GLwDrawingAreaWidget neww,ArgList args,Cardinal *num_args){ + + /* fix size */ + if(req->core.width==0) neww->core.width=100; + if(req->core.height==0) neww->core.width=100; + + /* create the attribute list if needed */ + neww->glwDrawingArea.myList=FALSE; + if(neww->glwDrawingArea.attribList==NULL){ + neww->glwDrawingArea.myList=TRUE; + createAttribList(neww); + } + + /* Gotta have it */ + assert(neww->glwDrawingArea.attribList); + + /* determine the visual info if needed */ + neww->glwDrawingArea.myVisual=FALSE; + if(neww->glwDrawingArea.visualInfo==NULL){ + neww->glwDrawingArea.myVisual=TRUE; + createVisualInfo(neww); + } + + /* Gotta have that too */ + assert(neww->glwDrawingArea.visualInfo); + + neww->core.depth=neww->glwDrawingArea.visualInfo->depth; + + /* Reobtain the colormap and colors in it using XtGetApplicationResources*/ + XtGetApplicationResources((Widget)neww,neww,initializeResources,XtNumber(initializeResources),args,*num_args); + + /* obtain the color resources if appropriate */ + if(req->glwDrawingArea.allocateBackground){ + XtGetApplicationResources((Widget)neww,neww,backgroundResources,XtNumber(backgroundResources),args,*num_args); + } + +#ifdef __GLX_MOTIF + if(req->glwDrawingArea.allocateOtherColors){ + XtGetApplicationResources((Widget)neww,neww,otherColorResources,XtNumber(otherColorResources),args,*num_args); + } +#endif + } + + + +static void Realize(Widget w,Mask *valueMask,XSetWindowAttributes *attributes){ + register GLwDrawingAreaWidget glw=(GLwDrawingAreaWidget)w; + GLwDrawingAreaCallbackStruct cb; + Widget parentShell; + Status status; + Window windows[2],*windowsReturn,*windowList; + int countReturn,i; + + /* if we haven't requested that the background be both installed and + * allocated, don't install it. + */ + if(!(glw->glwDrawingArea.installBackground && glw->glwDrawingArea.allocateBackground)){ + *valueMask&=~CWBackPixel; + } + + XtCreateWindow(w,(unsigned int)InputOutput,glw->glwDrawingArea.visualInfo->visual,*valueMask,attributes); + + /* if appropriate, call XSetWMColormapWindows to install the colormap */ + if(glw->glwDrawingArea.installColormap){ + + /* Get parent shell */ + for(parentShell=XtParent(w); parentShell&&!XtIsShell(parentShell); parentShell=XtParent(parentShell)); + + if(parentShell && XtWindow(parentShell)){ + + /* check to see if there is already a property */ + status=XGetWMColormapWindows(XtDisplay(parentShell),XtWindow(parentShell),&windowsReturn,&countReturn); + + /* if no property, just create one */ + if(!status){ + windows[0]=XtWindow(w); + windows[1]=XtWindow(parentShell); + XSetWMColormapWindows(XtDisplay(parentShell),XtWindow(parentShell),windows,2); + } + + /* there was a property, add myself to the beginning */ + else{ + windowList=(Window *)XtMalloc((sizeof(Window))*(countReturn+1)); + windowList[0]=XtWindow(w); + for(i=0; icore.width; + cb.height=glw->core.height; + XtCallCallbackList((Widget)glw,glw->glwDrawingArea.ginitCallback,&cb); + } + + + +static void Redraw(GLwDrawingAreaWidget w,XEvent *event,Region region){ + GLwDrawingAreaCallbackStruct cb; + if(!XtIsRealized((Widget)w)) return; + cb.reason=GLwCR_EXPOSE; + cb.event=event; + cb.width=w->core.width; + cb.height=w->core.height; + XtCallCallbackList((Widget)w,w->glwDrawingArea.exposeCallback,&cb); + } + + + +static void Resize(GLwDrawingAreaWidget glw){ + GLwDrawingAreaCallbackStruct cb; + if(!XtIsRealized((Widget)glw)) return; + cb.reason=GLwCR_RESIZE; + cb.event=NULL; + cb.width=glw->core.width; + cb.height=glw->core.height; + XtCallCallbackList((Widget)glw,glw->glwDrawingArea.resizeCallback,&cb); + } + + + +static void Destroy(GLwDrawingAreaWidget glw){ + Window *windowsReturn; + Widget parentShell; + Status status; + int countReturn; + register int i; + + if(glw->glwDrawingArea.myList && glw->glwDrawingArea.attribList){ + XtFree((XtPointer)glw->glwDrawingArea.attribList); + } + + if(glw->glwDrawingArea.myVisual && glw->glwDrawingArea.visualInfo){ + XtFree((XtPointer)glw->glwDrawingArea.visualInfo); + } + + /* if my colormap was installed, remove it */ + if(glw->glwDrawingArea.installColormap){ + + /* Get parent shell */ + for(parentShell=XtParent(glw); parentShell&&!XtIsShell(parentShell); parentShell=XtParent(parentShell)); + + if(parentShell && XtWindow(parentShell)){ + + /* make sure there is a property */ + status=XGetWMColormapWindows(XtDisplay(parentShell),XtWindow(parentShell),&windowsReturn,&countReturn); + + /* if no property, just return. If there was a property, continue */ + if(status){ + + /* search for a match */ + for(i=0; icore.width; + cb.height=glw->core.height; + XtCallCallbackList((Widget)glw,glw->glwDrawingArea.inputCallback,&cb); + } + + +#ifdef __GLX_MOTIF + +/* Create routine */ +Widget GLwCreateMDrawingArea(Widget parent, char *name,ArgList arglist,Cardinal argcount){ + return XtCreateWidget(name,glwMDrawingAreaWidgetClass, parent, arglist,argcount); + } + +#endif + + +#ifndef __GLX_MOTIF + +/* Make context current */ +void GLwDrawingAreaMakeCurrent(Widget w,GLXContext ctx){ + glXMakeCurrent(XtDisplay(w),XtWindow(w),ctx); + } + + +/* Swap buffers convenience function */ +void GLwDrawingAreaSwapBuffers(Widget w){ + glXSwapBuffers(XtDisplay(w),XtWindow(w)); + } + +#endif diff --git a/src/glw/GLwDrawA.h b/src/glw/GLwDrawA.h new file mode 100644 index 0000000..cd631b4 --- /dev/null +++ b/src/glw/GLwDrawA.h @@ -0,0 +1,195 @@ +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +#ifndef _GLwDrawA_h +#define _GLwDrawA_h + +#include +#include + +/**************************************************************** + * + * GLwDrawingArea widgets + * + ****************************************************************/ + +/* Resources: + + Name Class RepType Default Value + ---- ----- ------- ------------- + attribList AttribList int * NULL + visualInfo VisualInfo VisualInfo NULL + installColormap InstallColormap Boolean TRUE + allocateBackground AllocateColors Boolean FALSE + allocateOtherColors AllocateColors Boolean FALSE + installBackground InstallBackground Boolean TRUE + exposeCallback Callback Pointer NULL + ginitCallback Callback Pointer NULL + inputCallback Callback Pointer NULL + resizeCallback Callback Pointer NULL + +*** The following resources all correspond to the GLX configuration +*** attributes and are used to create the attribList if it is NULL + bufferSize BufferSize int 0 + level Level int 0 + rgba Rgba Boolean FALSE + doublebuffer Doublebuffer Boolean FALSE + stereo Stereo Boolean FALSE + auxBuffers AuxBuffers int 0 + redSize ColorSize int 1 + greenSize ColorSize int 1 + blueSize ColorSize int 1 + alphaSize AlphaSize int 0 + depthSize DepthSize int 0 + stencilSize StencilSize int 0 + accumRedSize AccumColorSize int 0 + accumGreenSize AccumColorSize int 0 + accumBlueSize AccumColorSize int 0 + accumAlphaSize AccumAlphaSize int 0 +*/ + +#define GLwNattribList "attribList" +#define GLwCAttribList "AttribList" +#define GLwNvisualInfo "visualInfo" +#define GLwCVisualInfo "VisualInfo" +#define GLwRVisualInfo "VisualInfo" + +#define GLwNinstallColormap "installColormap" +#define GLwCInstallColormap "InstallColormap" +#define GLwNallocateBackground "allocateBackground" +#define GLwNallocateOtherColors "allocateOtherColors" +#define GLwCAllocateColors "AllocateColors" +#define GLwNinstallBackground "installBackground" +#define GLwCInstallBackground "InstallBackground" + +#define GLwCCallback "Callback" +#define GLwNexposeCallback "exposeCallback" +#define GLwNginitCallback "ginitCallback" +#define GLwNresizeCallback "resizeCallback" +#define GLwNinputCallback "inputCallback" + +#define GLwNbufferSize "bufferSize" +#define GLwCBufferSize "BufferSize" +#define GLwNlevel "level" +#define GLwCLevel "Level" +#define GLwNrgba "rgba" +#define GLwCRgba "Rgba" +#define GLwNdoublebuffer "doublebuffer" +#define GLwCDoublebuffer "Doublebuffer" +#define GLwNstereo "stereo" +#define GLwCStereo "Stereo" +#define GLwNauxBuffers "auxBuffers" +#define GLwCAuxBuffers "AuxBuffers" +#define GLwNredSize "redSize" +#define GLwNgreenSize "greenSize" +#define GLwNblueSize "blueSize" +#define GLwCColorSize "ColorSize" +#define GLwNalphaSize "alphaSize" +#define GLwCAlphaSize "AlphaSize" +#define GLwNdepthSize "depthSize" +#define GLwCDepthSize "DepthSize" +#define GLwNstencilSize "stencilSize" +#define GLwCStencilSize "StencilSize" +#define GLwNaccumRedSize "accumRedSize" +#define GLwNaccumGreenSize "accumGreenSize" +#define GLwNaccumBlueSize "accumBlueSize" +#define GLwCAccumColorSize "AccumColorSize" +#define GLwNaccumAlphaSize "accumAlphaSize" +#define GLwCAccumAlphaSize "AccumAlphaSize" + +#ifdef __GLX_MOTIF + +typedef struct _GLwMDrawingAreaClassRec *GLwMDrawingAreaWidgetClass; +typedef struct _GLwMDrawingAreaRec *GLwMDrawingAreaWidget; + +extern WidgetClass glwMDrawingAreaWidgetClass; + + +#else + +typedef struct _GLwDrawingAreaClassRec *GLwDrawingAreaWidgetClass; +typedef struct _GLwDrawingAreaRec *GLwDrawingAreaWidget; + +extern WidgetClass glwDrawingAreaWidgetClass; + + +#endif + + +/* Callback reasons */ +#ifdef __GLX_MOTIF +#define GLwCR_EXPOSE XmCR_EXPOSE +#define GLwCR_RESIZE XmCR_RESIZE +#define GLwCR_INPUT XmCR_INPUT +#else +/* The same values as Motif, but don't use Motif constants */ +#define GLwCR_EXPOSE 38 +#define GLwCR_RESIZE 39 +#define GLwCR_INPUT 40 +#endif + +#define GLwCR_GINIT 32135 /* Arbitrary number that should neverr clash */ + +typedef struct + { + int reason; + XEvent *event; + Dimension width,height; + } + GLwDrawingAreaCallbackStruct; + +#if defined(__cplusplus) || defined(c_plusplus) +extern "C" { +#endif + +/* front ends to glXMakeCurrent and glXSwapBuffers */ +extern void GLwDrawingAreaMakeCurrent(Widget w,GLXContext ctx); +extern void GLwDrawingAreaSwapBuffers(Widget w); + +#ifdef __GLX_MOTIF +#ifdef _NO_PROTO +GLAPI Widget GLwCreateMDrawingArea(); +#else +GLAPI Widget GLwCreateMDrawingArea(Widget parent,char *name,ArgList arglist,Cardinal argcount); +#endif +#endif + +#if defined(__cplusplus) || defined(c_plusplus) +} +#endif + +#endif diff --git a/src/glw/GLwDrawAP.h b/src/glw/GLwDrawAP.h new file mode 100644 index 0000000..f121701 --- /dev/null +++ b/src/glw/GLwDrawAP.h @@ -0,0 +1,130 @@ +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +#ifndef _GLwDrawAP_h +#define _GLwDrawAP_h + + +/* MOTIF */ +#ifdef __GLX_MOTIF +#include "GLwMDrawA.h" +#else +#include "GLwDrawA.h" +#endif + +typedef struct _GLwDrawingAreaClassPart { + caddr_t extension; + } GLwDrawingAreaClassPart; + + +#ifdef __GLX_MOTIF +typedef struct _GLwMDrawingAreaClassRec { + CoreClassPart core_class; + XmPrimitiveClassPart primitive_class; + GLwDrawingAreaClassPart glwDrawingArea_class; + } GLwMDrawingAreaClassRec; + + +extern GLwMDrawingAreaClassRec glwMDrawingAreaClassRec; + + +/* XT */ +#else + +typedef struct _GLwDrawingAreaClassRec { + CoreClassPart core_class; + GLwDrawingAreaClassPart glwDrawingArea_class; + } GLwDrawingAreaClassRec; + +extern GLwDrawingAreaClassRec glwDrawingAreaClassRec; + + +#endif + + + +typedef struct { + /* resources */ + int * attribList; + XVisualInfo * visualInfo; + Boolean myList; /* TRUE if we malloced the attribList*/ + Boolean myVisual; /* TRUE if we created the visualInfo*/ + Boolean installColormap; + Boolean allocateBackground; + Boolean allocateOtherColors; + Boolean installBackground; + XtCallbackList ginitCallback; + XtCallbackList resizeCallback; + XtCallbackList exposeCallback; + XtCallbackList inputCallback; + /* specific attributes; add as we get new attributes */ + int bufferSize; + int level; + Boolean rgba; + Boolean doublebuffer; + Boolean stereo; + int auxBuffers; + int redSize; + int greenSize; + int blueSize; + int alphaSize; + int depthSize; + int stencilSize; + int accumRedSize; + int accumGreenSize; + int accumBlueSize; + int accumAlphaSize; + } GLwDrawingAreaPart; + +#ifdef __GLX_MOTIF + +typedef struct _GLwMDrawingAreaRec { + CorePart core; + XmPrimitivePart primitive; + GLwDrawingAreaPart glwDrawingArea; + } GLwMDrawingAreaRec; + +#else + +typedef struct _GLwDrawingAreaRec { + CorePart core; + GLwDrawingAreaPart glwDrawingArea; + } GLwDrawingAreaRec; + +#endif + +#endif diff --git a/src/glw/GLwMDrawA.c b/src/glw/GLwMDrawA.c new file mode 100644 index 0000000..bdefe92 --- /dev/null +++ b/src/glw/GLwMDrawA.c @@ -0,0 +1,41 @@ +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +#ifndef __GLX_MOTIF +#define __GLX_MOTIF 1 +#endif +#include "GLwDrawA.c" diff --git a/src/glw/GLwMDrawA.h b/src/glw/GLwMDrawA.h new file mode 100644 index 0000000..2e24589 --- /dev/null +++ b/src/glw/GLwMDrawA.h @@ -0,0 +1,41 @@ +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +#ifndef __GLX_MOTIF +#define __GLX_MOTIF 1 +#endif +#include "GLwDrawA.h" diff --git a/src/glw/GLwMDrawAP.h b/src/glw/GLwMDrawAP.h new file mode 100644 index 0000000..a0a689b --- /dev/null +++ b/src/glw/GLwMDrawAP.h @@ -0,0 +1,41 @@ +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +#ifndef __GLX_MOTIF +#define __GLX_MOTIF 1 +#endif +#include "GLwDrawAP.h" diff --git a/src/glw/Makefile b/src/glw/Makefile new file mode 100644 index 0000000..776b1aa --- /dev/null +++ b/src/glw/Makefile @@ -0,0 +1,74 @@ +# src/glw/Makefile + +TOP = ../.. +include $(TOP)/configs/current + +MAJOR = 1 +MINOR = 0 +TINY = 0 + +INCDIRS = -I$(TOP)/include $(MOTIF_CFLAGS) $(X11_INCLUDES) + + +OBJECTS = $(GLW_SOURCES:.c=.o) + + + +##### RULES ##### + +.c.o: + $(CC) -c $(INCDIRS) $(CFLAGS) $(GLW_CFLAGS) $< + + + +##### TARGETS ##### + +default: $(TOP)/$(LIB_DIR)/$(GLW_LIB_NAME) + +# GLU pkg-config file +pcedit = sed \ + -e 's,@INSTALL_DIR@,$(INSTALL_DIR),' \ + -e 's,@INSTALL_LIB_DIR@,$(INSTALL_LIB_DIR),' \ + -e 's,@INSTALL_INC_DIR@,$(INSTALL_INC_DIR),' \ + -e 's,@VERSION@,$(MAJOR).$(MINOR).$(TINY),' \ + -e 's,@GLW_PC_REQ_PRIV@,$(GLW_PC_REQ_PRIV),' \ + -e 's,@GLW_PC_LIB_PRIV@,$(GLW_PC_LIB_PRIV),' \ + -e 's,@GLW_PC_CFLAGS@,$(GLW_PC_CFLAGS),' \ + -e 's,@GLW_LIB@,$(GLW_LIB),' +glw.pc: glw.pc.in + $(pcedit) $< > $@ + +install: glw.pc + $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/GL + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR) + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig + $(INSTALL) -m 644 *.h $(DESTDIR)$(INSTALL_INC_DIR)/GL + $(MINSTALL) $(TOP)/$(LIB_DIR)/$(GLW_LIB_GLOB) $(DESTDIR)$(INSTALL_LIB_DIR) + $(INSTALL) -m 644 glw.pc $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig + +clean: + -rm -f depend depend.bak + -rm -f *.o *.pc *~ + + +# Make the library +$(TOP)/$(LIB_DIR)/$(GLW_LIB_NAME): $(OBJECTS) + $(MKLIB) -o $(GLW_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + -major $(MAJOR) -minor $(MINOR) -patch $(TINY) \ + $(MKLIB_OPTIONS) -install $(TOP)/$(LIB_DIR) \ + -id $(INSTALL_LIB_DIR)/lib$(GLW_LIB).$(MAJOR).dylib \ + $(GLW_LIB_DEPS) $(OBJECTS) + + +# +# Run 'make depend' to update the dependencies if you change what's included +# by any source file. +# +depend: $(GLW_SOURCES) + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) -I$(TOP)/include $(GLW_SOURCES) \ + $(X11_INCLUDES) > /dev/null + + +-include depend diff --git a/src/glw/README b/src/glw/README new file mode 100644 index 0000000..70f4f7b --- /dev/null +++ b/src/glw/README @@ -0,0 +1,56 @@ + + widgets README file + + +This directory contains the source code for SGI's OpenGL Xt/Motif widgets, +slightly modified by Jeroen van der Zijp to work better with Mesa. + +To compile the widget code (producing lib/libGLw.a) cd to the widgets/ +directory and type 'make ' where is the system configuration +you used to compile Mesa (like 'make linux'). This hasn't been tested on +many systems so let us know if you have trouble. + +If you want to make a Linux ELF shared lib instead of the non-shared .a +file see the notes in the Makefile. + +If you want to build with Motif support, edit Makefile.X11, looking +for the "Motif" information. + +The SGI copyright is as follows. + + + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. diff --git a/src/glw/depend b/src/glw/depend new file mode 100644 index 0000000..e69de29 diff --git a/src/glw/glw.pc.in b/src/glw/glw.pc.in new file mode 100644 index 0000000..19a7c30 --- /dev/null +++ b/src/glw/glw.pc.in @@ -0,0 +1,13 @@ +prefix=@INSTALL_DIR@ +exec_prefix=${prefix} +libdir=@INSTALL_LIB_DIR@ +includedir=@INSTALL_INC_DIR@ + +Name: glw +Description: Mesa OpenGL widget library +Requires: gl +Requires.private: @GLW_PC_REQ_PRIV@ +Version: @VERSION@ +Libs: -L${libdir} -l@GLW_LIB@ +Libs.private: @GLW_PC_LIB_PRIV@ +Cflags: -I${includedir} @GLW_PC_CFLAGS@ diff --git a/src/glx/Makefile b/src/glx/Makefile new file mode 100644 index 0000000..2c94ef1 --- /dev/null +++ b/src/glx/Makefile @@ -0,0 +1,106 @@ +TOP = ../.. +include $(TOP)/configs/current + +ifeq ($(HAVE_XF86VIDMODE),yes) +EXTRA_DEFINES_XF86VIDMODE = -DXF86VIDMODE +endif + +EXTRA_DEFINES = $(EXTRA_DEFINES_XF86VIDMODE) -D_REENTRANT \ + -DDEFAULT_DRIVER_DIR=\"$(DRI_DRIVER_SEARCH_DIR)\" + +SOURCES = \ + clientattrib.c \ + compsize.c \ + eval.c \ + glxconfig.c \ + glxcmds.c \ + glxcurrent.c \ + glxext.c \ + glxextensions.c \ + indirect_glx.c \ + indirect.c \ + indirect_init.c \ + indirect_size.c \ + indirect_window_pos.c \ + indirect_texture_compression.c \ + indirect_transpose_matrix.c \ + indirect_vertex_array.c \ + indirect_vertex_program.c \ + pixel.c \ + pixelstore.c \ + render2.c \ + renderpix.c \ + single2.c \ + singlepix.c \ + vertarr.c \ + xfont.c \ + glx_pbuffer.c \ + glx_query.c \ + drisw_glx.c \ + dri_common.c \ + dri_glx.c \ + XF86dri.c \ + glxhash.c \ + dri2_glx.c \ + dri2.c \ + applegl_glx.c + + +GLAPI_LIB = $(TOP)/src/mapi/glapi/libglapi.a + +OBJECTS = $(SOURCES:.c=.o) + +INCLUDES = -I. \ + -I$(TOP)/include \ + -I$(TOP)/include/GL/internal \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/mapi \ + -I$(TOP)/src/mapi/glapi \ + $(LIBDRM_CFLAGS) \ + $(DRI2PROTO_CFLAGS) \ + $(X11_INCLUDES) + + +##### RULES ##### + +.c.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(EXTRA_DEFINES) $< -o $@ + +.S.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(EXTRA_DEFINES) $< -o $@ + +##### TARGETS ##### + +default: depend $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) + +# Make libGL +$(TOP)/$(LIB_DIR)/$(GL_LIB_NAME): $(OBJECTS) $(GLAPI_LIB) Makefile + $(MKLIB) -o $(GL_LIB) -linker '$(CXX)' -ldflags '$(LDFLAGS)' \ + -major 1 -minor 2 \ + -cplusplus $(MKLIB_OPTIONS) \ + -install $(TOP)/$(LIB_DIR) -id $(INSTALL_LIB_DIR)/lib$(GL_LIB).1.dylib \ + $(GL_LIB_DEPS) $(OBJECTS) $(GLAPI_LIB) + +$(GLAPI_LIB): + @$(MAKE) -C $(TOP)/src/mapi/glapi + +depend: $(SOURCES) Makefile + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(SOURCES) + + +# Emacs tags +tags: + etags `find . -name \*.[ch]` `find $(TOP)/include` + +install: $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) + $(MAKE) -C $(TOP)/src/mesa install-libgl + +# Remove .o and backup files +clean: + -rm -f $(TOP)/$(LIB_DIR)/$(GL_LIB_GLOB) + -rm -f *.o *~ + -rm -f depend depend.bak + +-include depend diff --git a/src/glx/XF86dri.c b/src/glx/XF86dri.c new file mode 100644 index 0000000..5c181d6 --- /dev/null +++ b/src/glx/XF86dri.c @@ -0,0 +1,626 @@ +/************************************************************************** + +Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. +Copyright 2000 VA Linux Systems, 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 PRECISION INSIGHT 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. + +**************************************************************************/ + +/* + * Authors: + * Kevin E. Martin + * Jens Owen + * Rickard E. (Rik) Faith + * + */ + +/* THIS IS NOT AN X CONSORTIUM STANDARD */ + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + +#include +#include +#include +#include +#include "xf86dristr.h" + +static XExtensionInfo _xf86dri_info_data; +static XExtensionInfo *xf86dri_info = &_xf86dri_info_data; +static char xf86dri_extension_name[] = XF86DRINAME; + +#define XF86DRICheckExtension(dpy,i,val) \ + XextCheckExtension (dpy, i, xf86dri_extension_name, val) + +/***************************************************************************** + * * + * private utility routines * + * * + *****************************************************************************/ + +static int close_display(Display * dpy, XExtCodes * extCodes); +static /* const */ XExtensionHooks xf86dri_extension_hooks = { + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + close_display, /* close_display */ + NULL, /* wire_to_event */ + NULL, /* event_to_wire */ + NULL, /* error */ + NULL, /* error_string */ +}; + +static +XEXT_GENERATE_FIND_DISPLAY(find_display, xf86dri_info, + xf86dri_extension_name, + &xf86dri_extension_hooks, 0, NULL) + +static +XEXT_GENERATE_CLOSE_DISPLAY(close_display, xf86dri_info) + + +/***************************************************************************** + * * + * public XFree86-DRI Extension routines * + * * + *****************************************************************************/ +#if 0 +#include +#define TRACE(msg) fprintf(stderr,"XF86DRI%s\n", msg); +#else +#define TRACE(msg) +#endif + +Bool +XF86DRIQueryExtension(Display * dpy, int *event_basep, + int *error_basep) +{ + XExtDisplayInfo *info = find_display(dpy); + + TRACE("QueryExtension..."); + if (XextHasExtension(info)) { + *event_basep = info->codes->first_event; + *error_basep = info->codes->first_error; + TRACE("QueryExtension... return True"); + return True; + } + else { + TRACE("QueryExtension... return False"); + return False; + } +} + +Bool +XF86DRIQueryVersion(Display * dpy, int *majorVersion, int *minorVersion, + int *patchVersion) +{ + XExtDisplayInfo *info = find_display(dpy); + xXF86DRIQueryVersionReply rep; + xXF86DRIQueryVersionReq *req; + + TRACE("QueryVersion..."); + XF86DRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(XF86DRIQueryVersion, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_XF86DRIQueryVersion; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + TRACE("QueryVersion... return False"); + return False; + } + *majorVersion = rep.majorVersion; + *minorVersion = rep.minorVersion; + *patchVersion = rep.patchVersion; + UnlockDisplay(dpy); + SyncHandle(); + TRACE("QueryVersion... return True"); + return True; +} + +Bool +XF86DRIQueryDirectRenderingCapable(Display * dpy, int screen, + Bool * isCapable) +{ + XExtDisplayInfo *info = find_display(dpy); + xXF86DRIQueryDirectRenderingCapableReply rep; + xXF86DRIQueryDirectRenderingCapableReq *req; + + TRACE("QueryDirectRenderingCapable..."); + XF86DRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(XF86DRIQueryDirectRenderingCapable, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_XF86DRIQueryDirectRenderingCapable; + req->screen = screen; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + TRACE("QueryDirectRenderingCapable... return False"); + return False; + } + *isCapable = rep.isCapable; + UnlockDisplay(dpy); + SyncHandle(); + TRACE("QueryDirectRenderingCapable... return True"); + return True; +} + +Bool +XF86DRIOpenConnection(Display * dpy, int screen, drm_handle_t * hSAREA, + char **busIdString) +{ + XExtDisplayInfo *info = find_display(dpy); + xXF86DRIOpenConnectionReply rep; + xXF86DRIOpenConnectionReq *req; + + TRACE("OpenConnection..."); + XF86DRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(XF86DRIOpenConnection, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_XF86DRIOpenConnection; + req->screen = screen; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + TRACE("OpenConnection... return False"); + return False; + } + + *hSAREA = rep.hSAREALow; + if (sizeof(drm_handle_t) == 8) { + int shift = 32; /* var to prevent warning on next line */ + *hSAREA |= ((drm_handle_t) rep.hSAREAHigh) << shift; + } + + if (rep.length) { + if (!(*busIdString = (char *) Xcalloc(rep.busIdStringLength + 1, 1))) { + _XEatData(dpy, ((rep.busIdStringLength + 3) & ~3)); + UnlockDisplay(dpy); + SyncHandle(); + TRACE("OpenConnection... return False"); + return False; + } + _XReadPad(dpy, *busIdString, rep.busIdStringLength); + } + else { + *busIdString = NULL; + } + UnlockDisplay(dpy); + SyncHandle(); + TRACE("OpenConnection... return True"); + return True; +} + +Bool +XF86DRIAuthConnection(Display * dpy, int screen, drm_magic_t magic) +{ + XExtDisplayInfo *info = find_display(dpy); + xXF86DRIAuthConnectionReq *req; + xXF86DRIAuthConnectionReply rep; + + TRACE("AuthConnection..."); + XF86DRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(XF86DRIAuthConnection, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_XF86DRIAuthConnection; + req->screen = screen; + req->magic = magic; + rep.authenticated = 0; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse) || !rep.authenticated) { + UnlockDisplay(dpy); + SyncHandle(); + TRACE("AuthConnection... return False"); + return False; + } + UnlockDisplay(dpy); + SyncHandle(); + TRACE("AuthConnection... return True"); + return True; +} + +Bool +XF86DRICloseConnection(Display * dpy, int screen) +{ + XExtDisplayInfo *info = find_display(dpy); + xXF86DRICloseConnectionReq *req; + + TRACE("CloseConnection..."); + + XF86DRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(XF86DRICloseConnection, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_XF86DRICloseConnection; + req->screen = screen; + UnlockDisplay(dpy); + SyncHandle(); + TRACE("CloseConnection... return True"); + return True; +} + +Bool +XF86DRIGetClientDriverName(Display * dpy, int screen, + int *ddxDriverMajorVersion, + int *ddxDriverMinorVersion, + int *ddxDriverPatchVersion, + char **clientDriverName) +{ + XExtDisplayInfo *info = find_display(dpy); + xXF86DRIGetClientDriverNameReply rep; + xXF86DRIGetClientDriverNameReq *req; + + TRACE("GetClientDriverName..."); + XF86DRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(XF86DRIGetClientDriverName, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_XF86DRIGetClientDriverName; + req->screen = screen; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + TRACE("GetClientDriverName... return False"); + return False; + } + + *ddxDriverMajorVersion = rep.ddxDriverMajorVersion; + *ddxDriverMinorVersion = rep.ddxDriverMinorVersion; + *ddxDriverPatchVersion = rep.ddxDriverPatchVersion; + + if (rep.length) { + if (! + (*clientDriverName = + (char *) Xcalloc(rep.clientDriverNameLength + 1, 1))) { + _XEatData(dpy, ((rep.clientDriverNameLength + 3) & ~3)); + UnlockDisplay(dpy); + SyncHandle(); + TRACE("GetClientDriverName... return False"); + return False; + } + _XReadPad(dpy, *clientDriverName, rep.clientDriverNameLength); + } + else { + *clientDriverName = NULL; + } + UnlockDisplay(dpy); + SyncHandle(); + TRACE("GetClientDriverName... return True"); + return True; +} + +Bool +XF86DRICreateContextWithConfig(Display * dpy, int screen, int configID, + XID * context, drm_context_t * hHWContext) +{ + XExtDisplayInfo *info = find_display(dpy); + xXF86DRICreateContextReply rep; + xXF86DRICreateContextReq *req; + + TRACE("CreateContext..."); + XF86DRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(XF86DRICreateContext, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_XF86DRICreateContext; + req->visual = configID; + req->screen = screen; + *context = XAllocID(dpy); + req->context = *context; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + TRACE("CreateContext... return False"); + return False; + } + *hHWContext = rep.hHWContext; + UnlockDisplay(dpy); + SyncHandle(); + TRACE("CreateContext... return True"); + return True; +} + +Bool +XF86DRICreateContext(Display * dpy, int screen, Visual * visual, + XID * context, drm_context_t * hHWContext) +{ + return XF86DRICreateContextWithConfig(dpy, screen, visual->visualid, + context, hHWContext); +} + +Bool +XF86DRIDestroyContext(Display * dpy, int screen, XID context) +{ + XExtDisplayInfo *info = find_display(dpy); + xXF86DRIDestroyContextReq *req; + + TRACE("DestroyContext..."); + XF86DRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(XF86DRIDestroyContext, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_XF86DRIDestroyContext; + req->screen = screen; + req->context = context; + UnlockDisplay(dpy); + SyncHandle(); + TRACE("DestroyContext... return True"); + return True; +} + +Bool +XF86DRICreateDrawable(Display * dpy, int screen, + XID drawable, drm_drawable_t * hHWDrawable) +{ + XExtDisplayInfo *info = find_display(dpy); + xXF86DRICreateDrawableReply rep; + xXF86DRICreateDrawableReq *req; + + TRACE("CreateDrawable..."); + XF86DRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(XF86DRICreateDrawable, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_XF86DRICreateDrawable; + req->screen = screen; + req->drawable = drawable; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + TRACE("CreateDrawable... return False"); + return False; + } + *hHWDrawable = rep.hHWDrawable; + UnlockDisplay(dpy); + SyncHandle(); + TRACE("CreateDrawable... return True"); + return True; +} + +static int +noopErrorHandler(Display * dpy, XErrorEvent * xerr) +{ + return 0; +} + +Bool +XF86DRIDestroyDrawable(Display * dpy, int screen, XID drawable) +{ + XExtDisplayInfo *info = find_display(dpy); + xXF86DRIDestroyDrawableReq *req; + int (*oldXErrorHandler) (Display *, XErrorEvent *); + + TRACE("DestroyDrawable..."); + XF86DRICheckExtension(dpy, info, False); + + /* This is called from the DRI driver, which used call it like this + * + * if (windowExists(drawable)) + * destroyDrawable(drawable); + * + * which is a textbook race condition - the window may disappear + * from the server between checking for its existance and + * destroying it. Instead we change the semantics of + * __DRIinterfaceMethodsRec::destroyDrawable() to succeed even if + * the windows is gone, by wrapping the destroy call in an error + * handler. */ + + XSync(dpy, False); + oldXErrorHandler = XSetErrorHandler(noopErrorHandler); + + LockDisplay(dpy); + GetReq(XF86DRIDestroyDrawable, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_XF86DRIDestroyDrawable; + req->screen = screen; + req->drawable = drawable; + UnlockDisplay(dpy); + SyncHandle(); + + XSetErrorHandler(oldXErrorHandler); + + TRACE("DestroyDrawable... return True"); + return True; +} + +Bool +XF86DRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable, + unsigned int *index, unsigned int *stamp, + int *X, int *Y, int *W, int *H, + int *numClipRects, drm_clip_rect_t ** pClipRects, + int *backX, int *backY, + int *numBackClipRects, + drm_clip_rect_t ** pBackClipRects) +{ + XExtDisplayInfo *info = find_display(dpy); + xXF86DRIGetDrawableInfoReply rep; + xXF86DRIGetDrawableInfoReq *req; + int total_rects; + + TRACE("GetDrawableInfo..."); + XF86DRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(XF86DRIGetDrawableInfo, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_XF86DRIGetDrawableInfo; + req->screen = screen; + req->drawable = drawable; + + if (!_XReply(dpy, (xReply *) & rep, 1, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + TRACE("GetDrawableInfo... return False"); + return False; + } + *index = rep.drawableTableIndex; + *stamp = rep.drawableTableStamp; + *X = (int) rep.drawableX; + *Y = (int) rep.drawableY; + *W = (int) rep.drawableWidth; + *H = (int) rep.drawableHeight; + *numClipRects = rep.numClipRects; + total_rects = *numClipRects; + + *backX = rep.backX; + *backY = rep.backY; + *numBackClipRects = rep.numBackClipRects; + total_rects += *numBackClipRects; + +#if 0 + /* Because of the fix in Xserver/GL/dri/xf86dri.c, this check breaks + * backwards compatibility (Because of the >> 2 shift) but the fix + * enables multi-threaded apps to work. + */ + if (rep.length != ((((SIZEOF(xXF86DRIGetDrawableInfoReply) - + SIZEOF(xGenericReply) + + total_rects * sizeof(drm_clip_rect_t)) + + 3) & ~3) >> 2)) { + _XEatData(dpy, rep.length); + UnlockDisplay(dpy); + SyncHandle(); + TRACE("GetDrawableInfo... return False"); + return False; + } +#endif + + if (*numClipRects) { + int len = sizeof(drm_clip_rect_t) * (*numClipRects); + + *pClipRects = (drm_clip_rect_t *) Xcalloc(len, 1); + if (*pClipRects) + _XRead(dpy, (char *) *pClipRects, len); + } + else { + *pClipRects = NULL; + } + + if (*numBackClipRects) { + int len = sizeof(drm_clip_rect_t) * (*numBackClipRects); + + *pBackClipRects = (drm_clip_rect_t *) Xcalloc(len, 1); + if (*pBackClipRects) + _XRead(dpy, (char *) *pBackClipRects, len); + } + else { + *pBackClipRects = NULL; + } + + UnlockDisplay(dpy); + SyncHandle(); + TRACE("GetDrawableInfo... return True"); + return True; +} + +Bool +XF86DRIGetDeviceInfo(Display * dpy, int screen, drm_handle_t * hFrameBuffer, + int *fbOrigin, int *fbSize, int *fbStride, + int *devPrivateSize, void **pDevPrivate) +{ + XExtDisplayInfo *info = find_display(dpy); + xXF86DRIGetDeviceInfoReply rep; + xXF86DRIGetDeviceInfoReq *req; + + TRACE("GetDeviceInfo..."); + XF86DRICheckExtension(dpy, info, False); + + LockDisplay(dpy); + GetReq(XF86DRIGetDeviceInfo, req); + req->reqType = info->codes->major_opcode; + req->driReqType = X_XF86DRIGetDeviceInfo; + req->screen = screen; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + TRACE("GetDeviceInfo... return False"); + return False; + } + + *hFrameBuffer = rep.hFrameBufferLow; + if (sizeof(drm_handle_t) == 8) { + int shift = 32; /* var to prevent warning on next line */ + *hFrameBuffer |= ((drm_handle_t) rep.hFrameBufferHigh) << shift; + } + + *fbOrigin = rep.framebufferOrigin; + *fbSize = rep.framebufferSize; + *fbStride = rep.framebufferStride; + *devPrivateSize = rep.devPrivateSize; + + if (rep.length) { + if (!(*pDevPrivate = (void *) Xcalloc(rep.devPrivateSize, 1))) { + _XEatData(dpy, ((rep.devPrivateSize + 3) & ~3)); + UnlockDisplay(dpy); + SyncHandle(); + TRACE("GetDeviceInfo... return False"); + return False; + } + _XRead(dpy, (char *) *pDevPrivate, rep.devPrivateSize); + } + else { + *pDevPrivate = NULL; + } + + UnlockDisplay(dpy); + SyncHandle(); + TRACE("GetDeviceInfo... return True"); + return True; +} + +Bool +XF86DRIOpenFullScreen(Display * dpy, int screen, Drawable drawable) +{ + /* This function and the underlying X protocol are deprecated. + */ + (void) dpy; + (void) screen; + (void) drawable; + return False; +} + +Bool +XF86DRICloseFullScreen(Display * dpy, int screen, Drawable drawable) +{ + /* This function and the underlying X protocol are deprecated. + */ + (void) dpy; + (void) screen; + (void) drawable; + return True; +} + +#endif /* GLX_DIRECT_RENDERING */ diff --git a/src/glx/applegl_glx.c b/src/glx/applegl_glx.c new file mode 100644 index 0000000..3da1f19 --- /dev/null +++ b/src/glx/applegl_glx.c @@ -0,0 +1,155 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Soft- + * ware"), to deal in the Software without restriction, including without + * limitation the rights to use, copy, modify, merge, publish, distribute, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, provided that the above copyright + * notice(s) and this permission notice appear in all copies of the Soft- + * ware and that both the above copyright notice(s) and this permission + * notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- + * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY + * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN + * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- + * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR- + * MANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder shall + * not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization of + * the copyright holder. + * + * Authors: + * Kristian Høgsberg (krh@bitplanet.net) + */ + +#if defined(GLX_USE_APPLEGL) + +static void +applegl_destroy_context(struct glx_context *gc) +{ + apple_glx_destroy_context(&gc->driContext, gc->currentDpy); +} + +static int +applegl_bind_context(struct glx_context *gc, struct glx_context *old, + GLXDrawable draw, GLXDrawable read) +{ + bool error = apple_glx_make_current_context(dpy, + (oldGC && oldGC != &dummyContext) ? oldGC->driContext : NUL~ + gc ? gc->driContext : NULL, draw); + + apple_glx_diagnostic("%s: error %s\n", __func__, error ? "YES" : "NO"); + if (error) + return GLXBadContext; + + return Success; +} + +static void +applegl_unbind_context(struct glx_context *gc, struct glx_context *new) +{ +} + +static void +applegl_wait_gl(struct glx_context *gc) +{ + glFinish(); +} + +static void +applegl_wait_x(struct glx_context *gc) +{ + apple_glx_waitx(gc->dpy, gc->driContext); +} + +static const struct glx_context_vtable applegl_context_vtable = { + applegl_destroy_context, + applegl_bind_context, + applegl_unbind_context, + applegl_wait_gl, + applegl_wait_x, + DRI_glXUseXFont, + NULL, /* bind_tex_image, */ + NULL, /* release_tex_image, */ +}; + +static struct glx_context * +applegl_create_context(struct glx_screen *psc, + struct glx_config *mode, + struct glx_context *shareList, int renderType) +{ + struct glx_context *gc; + int errorcode; + bool x11error; + + /* TODO: Integrate this with apple_glx_create_context and make + * struct apple_glx_context inherit from struct glx_context. */ + + gc = Xmalloc(sizeof *gc); + if (pcp == NULL) + return NULL; + + memset(gc, 0, sizeof *gc); + if (!glx_context_init(&gc->base, &psc->base, mode)) { + Xfree(gc); + return NULL; + } + + gc->vtable = &applegl_context_vtable; + gc->driContext = NULL; + gc->do_destroy = False; + + /* TODO: darwin: Integrate with above to do indirect */ + if(apple_glx_create_context(&gc->driContext, dpy, screen, fbconfig, + shareList ? shareList->driContext : NULL, + &errorcode, &x11error)) { + __glXSendError(dpy, errorcode, 0, X_GLXCreateContext, x11error); + gc->vtable->destroy(gc); + return NULL; + } + + gc->currentContextTag = -1; + gc->mode = fbconfig; + gc->isDirect = allowDirect; + gc->xid = 1; /* Just something not None, so we know when to destroy + * it in MakeContextCurrent. */ + + return gc; +} + +struct glx_screen_vtable appegl_screen_vtable = { + applegl_create_context +}; + +_X_HIDDEN struct glx_screen * +applegl_create_screen(int screen, struct glx_display * priv) +{ + struct glx_screen *psc; + + psc = Xmalloc(sizeof *psc); + if (psc == NULL) + return NULL; + + memset(psc, 0, sizeof *psc); + glx_screen_init(psc, screen, priv); + psc->vtable = &applegl_screen_vtable; + + return psc; +} + +_X_HIDDEN int +applegl_create_display(struct glx_display *display) +{ + /* create applegl display and stuff in display->appleglDisplay */ + apple_init_glx(display); +} + +#endif diff --git a/src/glx/clientattrib.c b/src/glx/clientattrib.c new file mode 100644 index 0000000..7792fa3 --- /dev/null +++ b/src/glx/clientattrib.c @@ -0,0 +1,144 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include +#include "glxclient.h" +#include "indirect.h" +#include "indirect_vertex_array.h" + +/*****************************************************************************/ + +#ifndef GLX_USE_APPLEGL +static void +do_enable_disable(GLenum array, GLboolean val) +{ + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + unsigned index = 0; + + if (array == GL_TEXTURE_COORD_ARRAY) { + index = __glXGetActiveTextureUnit(state); + } + + if (!__glXSetArrayEnable(state, array, index, val)) { + __glXSetError(gc, GL_INVALID_ENUM); + } +} + +void +__indirect_glEnableClientState(GLenum array) +{ + do_enable_disable(array, GL_TRUE); +} + +void +__indirect_glDisableClientState(GLenum array) +{ + do_enable_disable(array, GL_FALSE); +} + +/************************************************************************/ + +void +__indirect_glPushClientAttrib(GLuint mask) +{ + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + __GLXattribute **spp = gc->attributes.stackPointer, *sp; + + if (spp < &gc->attributes.stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]) { + if (!(sp = *spp)) { + sp = (__GLXattribute *) Xmalloc(sizeof(__GLXattribute)); + *spp = sp; + } + sp->mask = mask; + gc->attributes.stackPointer = spp + 1; + if (mask & GL_CLIENT_PIXEL_STORE_BIT) { + sp->storePack = state->storePack; + sp->storeUnpack = state->storeUnpack; + } + if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) { + __glXPushArrayState(state); + } + } + else { + __glXSetError(gc, GL_STACK_OVERFLOW); + return; + } +} + +void +__indirect_glPopClientAttrib(void) +{ + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + __GLXattribute **spp = gc->attributes.stackPointer, *sp; + GLuint mask; + + if (spp > &gc->attributes.stack[0]) { + --spp; + sp = *spp; + assert(sp != 0); + mask = sp->mask; + gc->attributes.stackPointer = spp; + + if (mask & GL_CLIENT_PIXEL_STORE_BIT) { + state->storePack = sp->storePack; + state->storeUnpack = sp->storeUnpack; + } + if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) { + __glXPopArrayState(state); + } + + sp->mask = 0; + } + else { + __glXSetError(gc, GL_STACK_UNDERFLOW); + return; + } +} +#endif + +void +__glFreeAttributeState(struct glx_context * gc) +{ + __GLXattribute *sp, **spp; + + for (spp = &gc->attributes.stack[0]; + spp < &gc->attributes.stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]; spp++) { + sp = *spp; + if (sp) { + XFree((char *) sp); + } + else { + break; + } + } +} diff --git a/src/glx/compsize.c b/src/glx/compsize.c new file mode 100644 index 0000000..f69ffab --- /dev/null +++ b/src/glx/compsize.c @@ -0,0 +1,182 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include +#include "glxclient.h" + +/* +** Return the number of elements per group of a specified format +*/ +GLint +__glElementsPerGroup(GLenum format, GLenum type) +{ + /* + ** To make row length computation valid for image extraction, + ** packed pixel types assume elements per group equals one. + */ + switch (type) { + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + case GL_UNSIGNED_SHORT_8_8_APPLE: + case GL_UNSIGNED_SHORT_8_8_REV_APPLE: + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + case GL_UNSIGNED_INT_24_8_NV: + return 1; + default: + break; + } + + switch (format) { + case GL_RGB: + case GL_BGR: + return 3; + case GL_RG: + case GL_422_EXT: + case GL_422_REV_EXT: + case GL_422_AVERAGE_EXT: + case GL_422_REV_AVERAGE_EXT: + case GL_YCBCR_422_APPLE: + case GL_LUMINANCE_ALPHA: + return 2; + case GL_RGBA: + case GL_BGRA: + case GL_ABGR_EXT: + return 4; + case GL_COLOR_INDEX: + case GL_STENCIL_INDEX: + case GL_DEPTH_COMPONENT: + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + case GL_INTENSITY: + return 1; + default: + return 0; + } +} + +/* +** Return the number of bytes per element, based on the element type (other +** than GL_BITMAP). +*/ +GLint +__glBytesPerElement(GLenum type) +{ + switch (type) { + case GL_UNSIGNED_SHORT: + case GL_SHORT: + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + case GL_UNSIGNED_SHORT_8_8_APPLE: + case GL_UNSIGNED_SHORT_8_8_REV_APPLE: + return 2; + case GL_UNSIGNED_BYTE: + case GL_BYTE: + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + return 1; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + case GL_UNSIGNED_INT_24_8_NV: + return 4; + default: + return 0; + } +} + +/* +** Compute memory required for internal packed array of data of given type +** and format. +*/ +GLint +__glImageSize(GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, GLenum target) +{ + int bytes_per_row; + int components; + + switch (target) { + case GL_PROXY_TEXTURE_1D: + case GL_PROXY_TEXTURE_2D: + case GL_PROXY_TEXTURE_3D: + case GL_PROXY_TEXTURE_4D_SGIS: + case GL_PROXY_TEXTURE_CUBE_MAP: + case GL_PROXY_TEXTURE_RECTANGLE_ARB: + case GL_PROXY_HISTOGRAM: + case GL_PROXY_COLOR_TABLE: + case GL_PROXY_TEXTURE_COLOR_TABLE_SGI: + case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE: + case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE: + case GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP: + return 0; + } + + if (width < 0 || height < 0 || depth < 0) { + return 0; + } + + /* + ** Zero is returned if either format or type are invalid. + */ + components = __glElementsPerGroup(format, type); + if (type == GL_BITMAP) { + if (format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX) { + bytes_per_row = (width + 7) >> 3; + } + else { + return 0; + } + } + else { + bytes_per_row = __glBytesPerElement(type) * width; + } + + return bytes_per_row * height * depth * components; +} diff --git a/src/glx/dri2.c b/src/glx/dri2.c new file mode 100644 index 0000000..adfd3d1 --- /dev/null +++ b/src/glx/dri2.c @@ -0,0 +1,693 @@ +/* + * Copyright © 2008 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Soft- + * ware"), to deal in the Software without restriction, including without + * limitation the rights to use, copy, modify, merge, publish, distribute, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, provided that the above copyright + * notice(s) and this permission notice appear in all copies of the Soft- + * ware and that both the above copyright notice(s) and this permission + * notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- + * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY + * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN + * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- + * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR- + * MANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder shall + * not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization of + * the copyright holder. + * + * Authors: + * Kristian Høgsberg (krh@redhat.com) + */ + + +#ifdef GLX_DIRECT_RENDERING + +#include +#include +#include +#include +#include +#include "xf86drm.h" +#include "dri2.h" +#include "glxclient.h" +#include "GL/glxext.h" + +/* Allow the build to work with an older versions of dri2proto.h and + * dri2tokens.h. + */ +#if DRI2_MINOR < 1 +#undef DRI2_MINOR +#define DRI2_MINOR 1 +#define X_DRI2GetBuffersWithFormat 7 +#endif + + +static char dri2ExtensionName[] = DRI2_NAME; +static XExtensionInfo *dri2Info; +static XEXT_GENERATE_CLOSE_DISPLAY (DRI2CloseDisplay, dri2Info) + +static Bool +DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire); +static Status +DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire); +static int +DRI2Error(Display *display, xError *err, XExtCodes *codes, int *ret_code); + +static /* const */ XExtensionHooks dri2ExtensionHooks = { + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + DRI2CloseDisplay, /* close_display */ + DRI2WireToEvent, /* wire_to_event */ + DRI2EventToWire, /* event_to_wire */ + DRI2Error, /* error */ + NULL, /* error_string */ +}; + +static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay, + dri2Info, + dri2ExtensionName, + &dri2ExtensionHooks, + 0, NULL) + +static Bool +DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + + XextCheckExtension(dpy, info, dri2ExtensionName, False); + + switch ((wire->u.u.type & 0x7f) - info->codes->first_event) { + +#ifdef X_DRI2SwapBuffers + case DRI2_BufferSwapComplete: + { + GLXBufferSwapComplete *aevent = (GLXBufferSwapComplete *)event; + xDRI2BufferSwapComplete *awire = (xDRI2BufferSwapComplete *)wire; + + /* Ignore swap events if we're not looking for them */ + aevent->type = dri2GetSwapEventType(dpy, awire->drawable); + if(!aevent->type) + return False; + + aevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *) wire); + aevent->send_event = (awire->type & 0x80) != 0; + aevent->display = dpy; + aevent->drawable = awire->drawable; + switch (awire->event_type) { + case DRI2_EXCHANGE_COMPLETE: + aevent->event_type = GLX_EXCHANGE_COMPLETE_INTEL; + break; + case DRI2_BLIT_COMPLETE: + aevent->event_type = GLX_COPY_COMPLETE_INTEL; + break; + case DRI2_FLIP_COMPLETE: + aevent->event_type = GLX_FLIP_COMPLETE_INTEL; + break; + default: + /* unknown swap completion type */ + return False; + } + aevent->ust = ((CARD64)awire->ust_hi << 32) | awire->ust_lo; + aevent->msc = ((CARD64)awire->msc_hi << 32) | awire->msc_lo; + aevent->sbc = ((CARD64)awire->sbc_hi << 32) | awire->sbc_lo; + return True; + } +#endif +#ifdef DRI2_InvalidateBuffers + case DRI2_InvalidateBuffers: + { + xDRI2InvalidateBuffers *awire = (xDRI2InvalidateBuffers *)wire; + + dri2InvalidateBuffers(dpy, awire->drawable); + return False; + } +#endif + default: + /* client doesn't support server event */ + break; + } + + return False; +} + +/* We don't actually support this. It doesn't make sense for clients to + * send each other DRI2 events. + */ +static Status +DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + + XextCheckExtension(dpy, info, dri2ExtensionName, False); + + switch (event->type) { + default: + /* client doesn't support server event */ + break; + } + + return Success; +} + +static int +DRI2Error(Display *display, xError *err, XExtCodes *codes, int *ret_code) +{ + if (err->majorCode == codes->major_opcode && + err->errorCode == BadDrawable && + err->minorCode == X_DRI2CopyRegion) + return True; + + /* If the X drawable was destroyed before the GLX drawable, the + * DRI2 drawble will be gone by the time we call + * DRI2DestroyDrawable. So just ignore BadDrawable here. */ + if (err->majorCode == codes->major_opcode && + err->errorCode == BadDrawable && + err->minorCode == X_DRI2DestroyDrawable) + return True; + + return False; +} + +Bool +DRI2QueryExtension(Display * dpy, int *eventBase, int *errorBase) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + + if (XextHasExtension(info)) { + *eventBase = info->codes->first_event; + *errorBase = info->codes->first_error; + return True; + } + + return False; +} + +Bool +DRI2QueryVersion(Display * dpy, int *major, int *minor) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2QueryVersionReply rep; + xDRI2QueryVersionReq *req; + int i, nevents; + + XextCheckExtension(dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2QueryVersion, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2QueryVersion; + req->majorVersion = DRI2_MAJOR; + req->minorVersion = DRI2_MINOR; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + *major = rep.majorVersion; + *minor = rep.minorVersion; + UnlockDisplay(dpy); + SyncHandle(); + + switch (rep.minorVersion) { + case 1: + nevents = 0; + break; + case 2: + nevents = 1; + break; + case 3: + default: + nevents = 2; + break; + } + + for (i = 0; i < nevents; i++) { + XESetWireToEvent (dpy, info->codes->first_event + i, DRI2WireToEvent); + XESetEventToWire (dpy, info->codes->first_event + i, DRI2EventToWire); + } + + return True; +} + +Bool +DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2ConnectReply rep; + xDRI2ConnectReq *req; + + XextCheckExtension(dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2Connect, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2Connect; + req->window = window; + req->driverType = DRI2DriverDRI; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + + if (rep.driverNameLength == 0 && rep.deviceNameLength == 0) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + + *driverName = Xmalloc(rep.driverNameLength + 1); + if (*driverName == NULL) { + _XEatData(dpy, + ((rep.driverNameLength + 3) & ~3) + + ((rep.deviceNameLength + 3) & ~3)); + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + _XReadPad(dpy, *driverName, rep.driverNameLength); + (*driverName)[rep.driverNameLength] = '\0'; + + *deviceName = Xmalloc(rep.deviceNameLength + 1); + if (*deviceName == NULL) { + Xfree(*driverName); + _XEatData(dpy, ((rep.deviceNameLength + 3) & ~3)); + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + _XReadPad(dpy, *deviceName, rep.deviceNameLength); + (*deviceName)[rep.deviceNameLength] = '\0'; + + UnlockDisplay(dpy); + SyncHandle(); + + return True; +} + +Bool +DRI2Authenticate(Display * dpy, XID window, drm_magic_t magic) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2AuthenticateReq *req; + xDRI2AuthenticateReply rep; + + XextCheckExtension(dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2Authenticate, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2Authenticate; + req->window = window; + req->magic = magic; + + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + + UnlockDisplay(dpy); + SyncHandle(); + + return rep.authenticated; +} + +void +DRI2CreateDrawable(Display * dpy, XID drawable) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2CreateDrawableReq *req; + + XextSimpleCheckExtension(dpy, info, dri2ExtensionName); + + LockDisplay(dpy); + GetReq(DRI2CreateDrawable, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2CreateDrawable; + req->drawable = drawable; + UnlockDisplay(dpy); + SyncHandle(); +} + +void +DRI2DestroyDrawable(Display * dpy, XID drawable) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2DestroyDrawableReq *req; + + XextSimpleCheckExtension(dpy, info, dri2ExtensionName); + + XSync(dpy, False); + + LockDisplay(dpy); + GetReq(DRI2DestroyDrawable, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2DestroyDrawable; + req->drawable = drawable; + UnlockDisplay(dpy); + SyncHandle(); +} + +DRI2Buffer * +DRI2GetBuffers(Display * dpy, XID drawable, + int *width, int *height, + unsigned int *attachments, int count, int *outCount) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2GetBuffersReply rep; + xDRI2GetBuffersReq *req; + DRI2Buffer *buffers; + xDRI2Buffer repBuffer; + CARD32 *p; + int i; + + XextCheckExtension(dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReqExtra(DRI2GetBuffers, count * 4, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2GetBuffers; + req->drawable = drawable; + req->count = count; + p = (CARD32 *) & req[1]; + for (i = 0; i < count; i++) + p[i] = attachments[i]; + + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return NULL; + } + + *width = rep.width; + *height = rep.height; + *outCount = rep.count; + + buffers = Xmalloc(rep.count * sizeof buffers[0]); + if (buffers == NULL) { + _XEatData(dpy, rep.count * sizeof repBuffer); + UnlockDisplay(dpy); + SyncHandle(); + return NULL; + } + + for (i = 0; i < rep.count; i++) { + _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer); + buffers[i].attachment = repBuffer.attachment; + buffers[i].name = repBuffer.name; + buffers[i].pitch = repBuffer.pitch; + buffers[i].cpp = repBuffer.cpp; + buffers[i].flags = repBuffer.flags; + } + + UnlockDisplay(dpy); + SyncHandle(); + + return buffers; +} + + +DRI2Buffer * +DRI2GetBuffersWithFormat(Display * dpy, XID drawable, + int *width, int *height, + unsigned int *attachments, int count, int *outCount) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2GetBuffersReply rep; + xDRI2GetBuffersReq *req; + DRI2Buffer *buffers; + xDRI2Buffer repBuffer; + CARD32 *p; + int i; + + XextCheckExtension(dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReqExtra(DRI2GetBuffers, count * (4 * 2), req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2GetBuffersWithFormat; + req->drawable = drawable; + req->count = count; + p = (CARD32 *) & req[1]; + for (i = 0; i < (count * 2); i++) + p[i] = attachments[i]; + + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return NULL; + } + + *width = rep.width; + *height = rep.height; + *outCount = rep.count; + + buffers = Xmalloc(rep.count * sizeof buffers[0]); + if (buffers == NULL) { + _XEatData(dpy, rep.count * sizeof repBuffer); + UnlockDisplay(dpy); + SyncHandle(); + return NULL; + } + + for (i = 0; i < rep.count; i++) { + _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer); + buffers[i].attachment = repBuffer.attachment; + buffers[i].name = repBuffer.name; + buffers[i].pitch = repBuffer.pitch; + buffers[i].cpp = repBuffer.cpp; + buffers[i].flags = repBuffer.flags; + } + + UnlockDisplay(dpy); + SyncHandle(); + + return buffers; +} + + +void +DRI2CopyRegion(Display * dpy, XID drawable, XserverRegion region, + CARD32 dest, CARD32 src) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2CopyRegionReq *req; + xDRI2CopyRegionReply rep; + + XextSimpleCheckExtension(dpy, info, dri2ExtensionName); + + LockDisplay(dpy); + GetReq(DRI2CopyRegion, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2CopyRegion; + req->drawable = drawable; + req->region = region; + req->dest = dest; + req->src = src; + + _XReply(dpy, (xReply *) & rep, 0, xFalse); + + UnlockDisplay(dpy); + SyncHandle(); +} + +#ifdef X_DRI2SwapBuffers +static void +load_swap_req(xDRI2SwapBuffersReq *req, CARD64 target, CARD64 divisor, + CARD64 remainder) +{ + req->target_msc_hi = target >> 32; + req->target_msc_lo = target & 0xffffffff; + req->divisor_hi = divisor >> 32; + req->divisor_lo = divisor & 0xffffffff; + req->remainder_hi = remainder >> 32; + req->remainder_lo = remainder & 0xffffffff; +} + +static CARD64 +vals_to_card64(CARD32 lo, CARD32 hi) +{ + return (CARD64)hi << 32 | lo; +} + +void DRI2SwapBuffers(Display *dpy, XID drawable, CARD64 target_msc, + CARD64 divisor, CARD64 remainder, CARD64 *count) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2SwapBuffersReq *req; + xDRI2SwapBuffersReply rep; + + XextSimpleCheckExtension (dpy, info, dri2ExtensionName); + + LockDisplay(dpy); + GetReq(DRI2SwapBuffers, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2SwapBuffers; + req->drawable = drawable; + load_swap_req(req, target_msc, divisor, remainder); + + _XReply(dpy, (xReply *)&rep, 0, xFalse); + + *count = vals_to_card64(rep.swap_lo, rep.swap_hi); + + UnlockDisplay(dpy); + SyncHandle(); +} +#endif + +#ifdef X_DRI2GetMSC +Bool DRI2GetMSC(Display *dpy, XID drawable, CARD64 *ust, CARD64 *msc, + CARD64 *sbc) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2GetMSCReq *req; + xDRI2MSCReply rep; + + XextCheckExtension (dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2GetMSC, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2GetMSC; + req->drawable = drawable; + + if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + + *ust = vals_to_card64(rep.ust_lo, rep.ust_hi); + *msc = vals_to_card64(rep.msc_lo, rep.msc_hi); + *sbc = vals_to_card64(rep.sbc_lo, rep.sbc_hi); + + UnlockDisplay(dpy); + SyncHandle(); + + return True; +} +#endif + +#ifdef X_DRI2WaitMSC +static void +load_msc_req(xDRI2WaitMSCReq *req, CARD64 target, CARD64 divisor, + CARD64 remainder) +{ + req->target_msc_hi = target >> 32; + req->target_msc_lo = target & 0xffffffff; + req->divisor_hi = divisor >> 32; + req->divisor_lo = divisor & 0xffffffff; + req->remainder_hi = remainder >> 32; + req->remainder_lo = remainder & 0xffffffff; +} + +Bool DRI2WaitMSC(Display *dpy, XID drawable, CARD64 target_msc, CARD64 divisor, + CARD64 remainder, CARD64 *ust, CARD64 *msc, CARD64 *sbc) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2WaitMSCReq *req; + xDRI2MSCReply rep; + + XextCheckExtension (dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2WaitMSC, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2WaitMSC; + req->drawable = drawable; + load_msc_req(req, target_msc, divisor, remainder); + + if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + + *ust = ((CARD64)rep.ust_hi << 32) | (CARD64)rep.ust_lo; + *msc = ((CARD64)rep.msc_hi << 32) | (CARD64)rep.msc_lo; + *sbc = ((CARD64)rep.sbc_hi << 32) | (CARD64)rep.sbc_lo; + + UnlockDisplay(dpy); + SyncHandle(); + + return True; +} +#endif + +#ifdef X_DRI2WaitSBC +static void +load_sbc_req(xDRI2WaitSBCReq *req, CARD64 target) +{ + req->target_sbc_hi = target >> 32; + req->target_sbc_lo = target & 0xffffffff; +} + +Bool DRI2WaitSBC(Display *dpy, XID drawable, CARD64 target_sbc, CARD64 *ust, + CARD64 *msc, CARD64 *sbc) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2WaitSBCReq *req; + xDRI2MSCReply rep; + + XextCheckExtension (dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2WaitSBC, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2WaitSBC; + req->drawable = drawable; + load_sbc_req(req, target_sbc); + + if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + + *ust = ((CARD64)rep.ust_hi << 32) | rep.ust_lo; + *msc = ((CARD64)rep.msc_hi << 32) | rep.msc_lo; + *sbc = ((CARD64)rep.sbc_hi << 32) | rep.sbc_lo; + + UnlockDisplay(dpy); + SyncHandle(); + + return True; +} +#endif + +#ifdef X_DRI2SwapInterval +void DRI2SwapInterval(Display *dpy, XID drawable, int interval) +{ + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2SwapIntervalReq *req; + + XextSimpleCheckExtension (dpy, info, dri2ExtensionName); + + LockDisplay(dpy); + GetReq(DRI2SwapInterval, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2SwapInterval; + req->drawable = drawable; + req->interval = interval; + UnlockDisplay(dpy); + SyncHandle(); +} +#endif + +#endif /* GLX_DIRECT_RENDERING */ diff --git a/src/glx/dri2.h b/src/glx/dri2.h new file mode 100644 index 0000000..114e9f8 --- /dev/null +++ b/src/glx/dri2.h @@ -0,0 +1,106 @@ +/* + * Copyright © 2007,2008 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Soft- + * ware"), to deal in the Software without restriction, including without + * limitation the rights to use, copy, modify, merge, publish, distribute, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, provided that the above copyright + * notice(s) and this permission notice appear in all copies of the Soft- + * ware and that both the above copyright notice(s) and this permission + * notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- + * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY + * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN + * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- + * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR- + * MANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder shall + * not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization of + * the copyright holder. + * + * Authors: + * Kristian Høgsberg (krh@redhat.com) + */ + +#ifndef _DRI2_H_ +#define _DRI2_H_ + +#include +#include + +typedef struct +{ + unsigned int attachment; + unsigned int name; + unsigned int pitch; + unsigned int cpp; + unsigned int flags; +} DRI2Buffer; + +extern Bool +DRI2QueryExtension(Display * display, int *eventBase, int *errorBase); + +extern Bool +DRI2QueryVersion(Display * display, int *major, int *minor); + +extern Bool +DRI2Connect(Display * display, XID window, + char **driverName, char **deviceName); + +extern Bool +DRI2Authenticate(Display * display, XID window, drm_magic_t magic); + +extern void +DRI2CreateDrawable(Display * display, XID drawable); + +extern void +DRI2DestroyDrawable(Display * display, XID handle); + +extern DRI2Buffer* +DRI2GetBuffers(Display * dpy, XID drawable, + int *width, int *height, + unsigned int *attachments, int count, + int *outCount); + +/** + * \note + * This function is only supported with DRI2 version 1.1 or later. + */ +extern DRI2Buffer* +DRI2GetBuffersWithFormat(Display * dpy, XID drawable, + int *width, int *height, + unsigned int *attachments, + int count, int *outCount); + +extern void +DRI2CopyRegion(Display * dpy, XID drawable, + XserverRegion region, + CARD32 dest, CARD32 src); + +extern void +DRI2SwapBuffers(Display *dpy, XID drawable, CARD64 target_msc, CARD64 divisor, + CARD64 remainder, CARD64 *count); + +extern Bool +DRI2GetMSC(Display *dpy, XID drawable, CARD64 *ust, CARD64 *msc, CARD64 *sbc); + +extern Bool +DRI2WaitMSC(Display *dpy, XID drawable, CARD64 target_msc, CARD64 divisor, + CARD64 remainder, CARD64 *ust, CARD64 *msc, CARD64 *sbc); + +extern Bool +DRI2WaitSBC(Display *dpy, XID drawable, CARD64 target_sbc, CARD64 *ust, + CARD64 *msc, CARD64 *sbc); + +extern void +DRI2SwapInterval(Display *dpy, XID drawable, int interval); + +#endif diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c new file mode 100644 index 0000000..b0559b2 --- /dev/null +++ b/src/glx/dri2_glx.c @@ -0,0 +1,982 @@ +/* + * Copyright © 2008 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Soft- + * ware"), to deal in the Software without restriction, including without + * limitation the rights to use, copy, modify, merge, publish, distribute, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, provided that the above copyright + * notice(s) and this permission notice appear in all copies of the Soft- + * ware and that both the above copyright notice(s) and this permission + * notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- + * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY + * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN + * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- + * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR- + * MANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder shall + * not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization of + * the copyright holder. + * + * Authors: + * Kristian Høgsberg (krh@redhat.com) + */ + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + +#include +#include +#include +#include "glapi.h" +#include "glxclient.h" +#include +#include "xf86dri.h" +#include +#include +#include +#include +#include +#include "xf86drm.h" +#include "dri2.h" +#include "dri_common.h" + +/* From xmlpool/options.h, user exposed so should be stable */ +#define DRI_CONF_VBLANK_NEVER 0 +#define DRI_CONF_VBLANK_DEF_INTERVAL_0 1 +#define DRI_CONF_VBLANK_DEF_INTERVAL_1 2 +#define DRI_CONF_VBLANK_ALWAYS_SYNC 3 + +#undef DRI2_MINOR +#define DRI2_MINOR 1 + +struct dri2_display +{ + __GLXDRIdisplay base; + + /* + ** XFree86-DRI version information + */ + int driMajor; + int driMinor; + int driPatch; + int swapAvailable; + int invalidateAvailable; + + __glxHashTable *dri2Hash; + + const __DRIextension *loader_extensions[4]; +}; + +struct dri2_screen { + struct glx_screen base; + + __DRIscreen *driScreen; + __GLXDRIscreen vtable; + const __DRIdri2Extension *dri2; + const __DRIcoreExtension *core; + + const __DRI2flushExtension *f; + const __DRI2configQueryExtension *config; + const __DRItexBufferExtension *texBuffer; + const __DRIconfig **driver_configs; + + void *driver; + int fd; +}; + +struct dri2_context +{ + struct glx_context base; + __DRIcontext *driContext; +}; + +struct dri2_drawable +{ + __GLXDRIdrawable base; + __DRIdrawable *driDrawable; + __DRIbuffer buffers[5]; + int bufferCount; + int width, height; + int have_back; + int have_fake_front; + int swap_interval; +}; + +static const struct glx_context_vtable dri2_context_vtable; + +static void +dri2_destroy_context(struct glx_context *context) +{ + struct dri2_context *pcp = (struct dri2_context *) context; + struct dri2_screen *psc = (struct dri2_screen *) context->psc; + + driReleaseDrawables(&pcp->base); + + if (context->xid) + glx_send_destroy_context(psc->base.dpy, context->xid); + + if (context->extensions) + XFree((char *) context->extensions); + + (*psc->core->destroyContext) (pcp->driContext); + + Xfree(pcp); +} + +static Bool +dri2_bind_context(struct glx_context *context, struct glx_context *old, + GLXDrawable draw, GLXDrawable read) +{ + struct dri2_context *pcp = (struct dri2_context *) context; + struct dri2_screen *psc = (struct dri2_screen *) pcp->base.psc; + struct dri2_drawable *pdraw, *pread; + struct dri2_display *pdp; + + pdraw = (struct dri2_drawable *) driFetchDrawable(context, draw); + pread = (struct dri2_drawable *) driFetchDrawable(context, read); + + if (pdraw == NULL || pread == NULL) + return GLXBadDrawable; + + if (!(*psc->core->bindContext) (pcp->driContext, + pdraw->driDrawable, pread->driDrawable)) + return GLXBadContext; + + /* If the server doesn't send invalidate events, we may miss a + * resize before the rendering starts. Invalidate the buffers now + * so the driver will recheck before rendering starts. */ + pdp = (struct dri2_display *) psc->base.display; + if (!pdp->invalidateAvailable) { + dri2InvalidateBuffers(psc->base.dpy, pdraw->base.xDrawable); + if (pread != pdraw) + dri2InvalidateBuffers(psc->base.dpy, pread->base.xDrawable); + } + + return Success; +} + +static void +dri2_unbind_context(struct glx_context *context, struct glx_context *new) +{ + struct dri2_context *pcp = (struct dri2_context *) context; + struct dri2_screen *psc = (struct dri2_screen *) pcp->base.psc; + + (*psc->core->unbindContext) (pcp->driContext); + + if (context == new) + driReleaseDrawables(&pcp->base); +} + +static struct glx_context * +dri2_create_context(struct glx_screen *base, + struct glx_config *config_base, + struct glx_context *shareList, int renderType) +{ + struct dri2_context *pcp, *pcp_shared; + struct dri2_screen *psc = (struct dri2_screen *) base; + __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base; + __DRIcontext *shared = NULL; + + if (shareList) { + pcp_shared = (struct dri2_context *) shareList; + shared = pcp_shared->driContext; + } + + pcp = Xmalloc(sizeof *pcp); + if (pcp == NULL) + return NULL; + + memset(pcp, 0, sizeof *pcp); + if (!glx_context_init(&pcp->base, &psc->base, &config->base)) { + Xfree(pcp); + return NULL; + } + + pcp->driContext = + (*psc->dri2->createNewContext) (psc->driScreen, + config->driConfig, shared, pcp); + + if (pcp->driContext == NULL) { + Xfree(pcp); + return NULL; + } + + pcp->base.vtable = &dri2_context_vtable; + + return &pcp->base; +} + +static void +dri2DestroyDrawable(__GLXDRIdrawable *base) +{ + struct dri2_screen *psc = (struct dri2_screen *) base->psc; + struct dri2_drawable *pdraw = (struct dri2_drawable *) base; + struct glx_display *dpyPriv = psc->base.display; + struct dri2_display *pdp = (struct dri2_display *)dpyPriv->dri2Display; + + __glxHashDelete(pdp->dri2Hash, pdraw->base.xDrawable); + (*psc->core->destroyDrawable) (pdraw->driDrawable); + + /* If it's a GLX 1.3 drawables, we can destroy the DRI2 drawable + * now, as the application explicitly asked to destroy the GLX + * drawable. Otherwise, for legacy drawables, we let the DRI2 + * drawable linger on the server, since there's no good way of + * knowing when the application is done with it. The server will + * destroy the DRI2 drawable when it destroys the X drawable or the + * client exits anyway. */ + if (pdraw->base.xDrawable != pdraw->base.drawable) + DRI2DestroyDrawable(psc->base.dpy, pdraw->base.xDrawable); + + Xfree(pdraw); +} + +static __GLXDRIdrawable * +dri2CreateDrawable(struct glx_screen *base, XID xDrawable, + GLXDrawable drawable, struct glx_config *config_base) +{ + struct dri2_drawable *pdraw; + struct dri2_screen *psc = (struct dri2_screen *) base; + __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base; + struct glx_display *dpyPriv; + struct dri2_display *pdp; + GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1; + + pdraw = Xmalloc(sizeof(*pdraw)); + if (!pdraw) + return NULL; + + memset(pdraw, 0, sizeof *pdraw); + pdraw->base.destroyDrawable = dri2DestroyDrawable; + pdraw->base.xDrawable = xDrawable; + pdraw->base.drawable = drawable; + pdraw->base.psc = &psc->base; + pdraw->bufferCount = 0; + pdraw->swap_interval = 1; /* default may be overridden below */ + pdraw->have_back = 0; + + if (psc->config) + psc->config->configQueryi(psc->driScreen, + "vblank_mode", &vblank_mode); + + switch (vblank_mode) { + case DRI_CONF_VBLANK_NEVER: + case DRI_CONF_VBLANK_DEF_INTERVAL_0: + pdraw->swap_interval = 0; + break; + case DRI_CONF_VBLANK_DEF_INTERVAL_1: + case DRI_CONF_VBLANK_ALWAYS_SYNC: + default: + pdraw->swap_interval = 1; + break; + } + + DRI2CreateDrawable(psc->base.dpy, xDrawable); + + dpyPriv = __glXInitialize(psc->base.dpy); + pdp = (struct dri2_display *)dpyPriv->dri2Display;; + /* Create a new drawable */ + pdraw->driDrawable = + (*psc->dri2->createNewDrawable) (psc->driScreen, + config->driConfig, pdraw); + + if (!pdraw->driDrawable) { + DRI2DestroyDrawable(psc->base.dpy, xDrawable); + Xfree(pdraw); + return NULL; + } + + if (__glxHashInsert(pdp->dri2Hash, xDrawable, pdraw)) { + (*psc->core->destroyDrawable) (pdraw->driDrawable); + DRI2DestroyDrawable(psc->base.dpy, xDrawable); + Xfree(pdraw); + return None; + } + + +#ifdef X_DRI2SwapInterval + /* + * Make sure server has the same swap interval we do for the new + * drawable. + */ + if (pdp->swapAvailable) + DRI2SwapInterval(psc->base.dpy, xDrawable, pdraw->swap_interval); +#endif + + return &pdraw->base; +} + +#ifdef X_DRI2GetMSC + +static int +dri2DrawableGetMSC(struct glx_screen *psc, __GLXDRIdrawable *pdraw, + int64_t *ust, int64_t *msc, int64_t *sbc) +{ + CARD64 dri2_ust, dri2_msc, dri2_sbc; + int ret; + + ret = DRI2GetMSC(psc->dpy, pdraw->xDrawable, + &dri2_ust, &dri2_msc, &dri2_sbc); + *ust = dri2_ust; + *msc = dri2_msc; + *sbc = dri2_sbc; + + return ret; +} + +#endif + + +#ifdef X_DRI2WaitMSC + +static int +dri2WaitForMSC(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor, + int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc) +{ + CARD64 dri2_ust, dri2_msc, dri2_sbc; + int ret; + + ret = DRI2WaitMSC(pdraw->psc->dpy, pdraw->xDrawable, target_msc, divisor, + remainder, &dri2_ust, &dri2_msc, &dri2_sbc); + *ust = dri2_ust; + *msc = dri2_msc; + *sbc = dri2_sbc; + + return ret; +} + +static int +dri2WaitForSBC(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust, + int64_t *msc, int64_t *sbc) +{ + CARD64 dri2_ust, dri2_msc, dri2_sbc; + int ret; + + ret = DRI2WaitSBC(pdraw->psc->dpy, pdraw->xDrawable, + target_sbc, &dri2_ust, &dri2_msc, &dri2_sbc); + *ust = dri2_ust; + *msc = dri2_msc; + *sbc = dri2_sbc; + + return ret; +} + +#endif /* X_DRI2WaitMSC */ + +static void +dri2CopySubBuffer(__GLXDRIdrawable *pdraw, int x, int y, int width, int height) +{ + struct dri2_drawable *priv = (struct dri2_drawable *) pdraw; + struct dri2_screen *psc = (struct dri2_screen *) pdraw->psc; + XRectangle xrect; + XserverRegion region; + + /* Check we have the right attachments */ + if (!priv->have_back) + return; + + xrect.x = x; + xrect.y = priv->height - y - height; + xrect.width = width; + xrect.height = height; + +#ifdef __DRI2_FLUSH + if (psc->f) + (*psc->f->flush) (priv->driDrawable); +#endif + + region = XFixesCreateRegion(psc->base.dpy, &xrect, 1); + DRI2CopyRegion(psc->base.dpy, pdraw->xDrawable, region, + DRI2BufferFrontLeft, DRI2BufferBackLeft); + + /* Refresh the fake front (if present) after we just damaged the real + * front. + */ + if (priv->have_fake_front) + DRI2CopyRegion(psc->base.dpy, pdraw->xDrawable, region, + DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft); + + XFixesDestroyRegion(psc->base.dpy, region); +} + +static void +dri2_copy_drawable(struct dri2_drawable *priv, int dest, int src) +{ + XRectangle xrect; + XserverRegion region; + struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc; + + xrect.x = 0; + xrect.y = 0; + xrect.width = priv->width; + xrect.height = priv->height; + +#ifdef __DRI2_FLUSH + if (psc->f) + (*psc->f->flush) (priv->driDrawable); +#endif + + region = XFixesCreateRegion(psc->base.dpy, &xrect, 1); + DRI2CopyRegion(psc->base.dpy, priv->base.xDrawable, region, dest, src); + XFixesDestroyRegion(psc->base.dpy, region); + +} + +static void +dri2_wait_x(struct glx_context *gc) +{ + struct dri2_drawable *priv = (struct dri2_drawable *) + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable); + + if (priv == NULL || !priv->have_fake_front) + return; + + dri2_copy_drawable(priv, DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft); +} + +static void +dri2_wait_gl(struct glx_context *gc) +{ + struct dri2_drawable *priv = (struct dri2_drawable *) + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable); + + if (priv == NULL || !priv->have_fake_front) + return; + + dri2_copy_drawable(priv, DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft); +} + +static void +dri2FlushFrontBuffer(__DRIdrawable *driDrawable, void *loaderPrivate) +{ + struct dri2_drawable *pdraw = loaderPrivate; + struct glx_display *priv = __glXInitialize(pdraw->base.psc->dpy); + struct dri2_display *pdp = (struct dri2_display *)priv->dri2Display; + struct glx_context *gc = __glXGetCurrentContext(); + + /* Old servers don't send invalidate events */ + if (!pdp->invalidateAvailable) + dri2InvalidateBuffers(priv->dpy, pdraw->base.xDrawable); + + dri2_wait_gl(gc); +} + + +static void +dri2DestroyScreen(struct glx_screen *base) +{ + struct dri2_screen *psc = (struct dri2_screen *) base; + + /* Free the direct rendering per screen data */ + (*psc->core->destroyScreen) (psc->driScreen); + driDestroyConfigs(psc->driver_configs); + close(psc->fd); + Xfree(psc); +} + +/** + * Process list of buffer received from the server + * + * Processes the list of buffers received in a reply from the server to either + * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat. + */ +static void +process_buffers(struct dri2_drawable * pdraw, DRI2Buffer * buffers, + unsigned count) +{ + int i; + + pdraw->bufferCount = count; + pdraw->have_fake_front = 0; + pdraw->have_back = 0; + + /* This assumes the DRI2 buffer attachment tokens matches the + * __DRIbuffer tokens. */ + for (i = 0; i < count; i++) { + pdraw->buffers[i].attachment = buffers[i].attachment; + pdraw->buffers[i].name = buffers[i].name; + pdraw->buffers[i].pitch = buffers[i].pitch; + pdraw->buffers[i].cpp = buffers[i].cpp; + pdraw->buffers[i].flags = buffers[i].flags; + if (pdraw->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT) + pdraw->have_fake_front = 1; + if (pdraw->buffers[i].attachment == __DRI_BUFFER_BACK_LEFT) + pdraw->have_back = 1; + } + +} + +unsigned dri2GetSwapEventType(Display* dpy, XID drawable) +{ + struct glx_display *glx_dpy = __glXInitialize(dpy); + __GLXDRIdrawable *pdraw; + pdraw = dri2GetGlxDrawableFromXDrawableId(dpy, drawable); + if (!pdraw || !(pdraw->eventMask & GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK)) + return 0; + return glx_dpy->codes->first_event + GLX_BufferSwapComplete; +} + +static int64_t +dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor, + int64_t remainder) +{ + struct dri2_drawable *priv = (struct dri2_drawable *) pdraw; + struct glx_display *dpyPriv = __glXInitialize(priv->base.psc->dpy); + struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc; + struct dri2_display *pdp = + (struct dri2_display *)dpyPriv->dri2Display; + CARD64 ret = 0; + +#ifdef __DRI2_FLUSH + if (psc->f) + (*psc->f->flush)(priv->driDrawable); +#endif + + /* Old servers don't send invalidate events */ + if (!pdp->invalidateAvailable) + dri2InvalidateBuffers(dpyPriv->dpy, pdraw->xDrawable); + + /* Old servers can't handle swapbuffers */ + if (!pdp->swapAvailable) { + dri2CopySubBuffer(pdraw, 0, 0, priv->width, priv->height); + return 0; + } + +#ifdef X_DRI2SwapBuffers + DRI2SwapBuffers(psc->base.dpy, pdraw->xDrawable, target_msc, divisor, + remainder, &ret); +#endif + + return ret; +} + +static __DRIbuffer * +dri2GetBuffers(__DRIdrawable * driDrawable, + int *width, int *height, + unsigned int *attachments, int count, + int *out_count, void *loaderPrivate) +{ + struct dri2_drawable *pdraw = loaderPrivate; + DRI2Buffer *buffers; + + buffers = DRI2GetBuffers(pdraw->base.psc->dpy, pdraw->base.xDrawable, + width, height, attachments, count, out_count); + if (buffers == NULL) + return NULL; + + pdraw->width = *width; + pdraw->height = *height; + process_buffers(pdraw, buffers, *out_count); + + Xfree(buffers); + + return pdraw->buffers; +} + +static __DRIbuffer * +dri2GetBuffersWithFormat(__DRIdrawable * driDrawable, + int *width, int *height, + unsigned int *attachments, int count, + int *out_count, void *loaderPrivate) +{ + struct dri2_drawable *pdraw = loaderPrivate; + DRI2Buffer *buffers; + + buffers = DRI2GetBuffersWithFormat(pdraw->base.psc->dpy, + pdraw->base.xDrawable, + width, height, attachments, + count, out_count); + if (buffers == NULL) + return NULL; + + pdraw->width = *width; + pdraw->height = *height; + process_buffers(pdraw, buffers, *out_count); + + Xfree(buffers); + + return pdraw->buffers; +} + +#ifdef X_DRI2SwapInterval + +static int +dri2SetSwapInterval(__GLXDRIdrawable *pdraw, int interval) +{ + struct dri2_drawable *priv = (struct dri2_drawable *) pdraw; + GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1; + struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc; + + if (psc->config) + psc->config->configQueryi(psc->driScreen, + "vblank_mode", &vblank_mode); + + switch (vblank_mode) { + case DRI_CONF_VBLANK_NEVER: + return GLX_BAD_VALUE; + case DRI_CONF_VBLANK_ALWAYS_SYNC: + if (interval <= 0) + return GLX_BAD_VALUE; + break; + default: + break; + } + + DRI2SwapInterval(priv->base.psc->dpy, priv->base.xDrawable, interval); + priv->swap_interval = interval; + + return 0; +} + +static int +dri2GetSwapInterval(__GLXDRIdrawable *pdraw) +{ + struct dri2_drawable *priv = (struct dri2_drawable *) pdraw; + + return priv->swap_interval; +} + +#endif /* X_DRI2SwapInterval */ + +static const __DRIdri2LoaderExtension dri2LoaderExtension = { + {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION}, + dri2GetBuffers, + dri2FlushFrontBuffer, + dri2GetBuffersWithFormat, +}; + +static const __DRIdri2LoaderExtension dri2LoaderExtension_old = { + {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION}, + dri2GetBuffers, + dri2FlushFrontBuffer, + NULL, +}; + +#ifdef __DRI_USE_INVALIDATE +static const __DRIuseInvalidateExtension dri2UseInvalidate = { + { __DRI_USE_INVALIDATE, __DRI_USE_INVALIDATE_VERSION } +}; +#endif + +_X_HIDDEN void +dri2InvalidateBuffers(Display *dpy, XID drawable) +{ + __GLXDRIdrawable *pdraw = + dri2GetGlxDrawableFromXDrawableId(dpy, drawable); + struct dri2_screen *psc = (struct dri2_screen *) pdraw->psc; + struct dri2_drawable *pdp = (struct dri2_drawable *) pdraw; + +#if __DRI2_FLUSH_VERSION >= 3 + if (pdraw && psc->f) + psc->f->invalidate(pdp->driDrawable); +#endif +} + +static void +dri2_bind_tex_image(Display * dpy, + GLXDrawable drawable, + int buffer, const int *attrib_list) +{ + struct glx_context *gc = __glXGetCurrentContext(); + struct dri2_context *pcp = (struct dri2_context *) gc; + __GLXDRIdrawable *base = GetGLXDRIDrawable(dpy, drawable); + struct glx_display *dpyPriv = __glXInitialize(dpy); + struct dri2_drawable *pdraw = (struct dri2_drawable *) base; + struct dri2_display *pdp = + (struct dri2_display *) dpyPriv->dri2Display; + struct dri2_screen *psc; + + if (pdraw != NULL) { + psc = (struct dri2_screen *) base->psc; + +#if __DRI2_FLUSH_VERSION >= 3 + if (!pdp->invalidateAvailable && psc->f) + psc->f->invalidate(pdraw->driDrawable); +#endif + + if (psc->texBuffer->base.version >= 2 && + psc->texBuffer->setTexBuffer2 != NULL) { + (*psc->texBuffer->setTexBuffer2) (pcp->driContext, + pdraw->base.textureTarget, + pdraw->base.textureFormat, + pdraw->driDrawable); + } + else { + (*psc->texBuffer->setTexBuffer) (pcp->driContext, + pdraw->base.textureTarget, + pdraw->driDrawable); + } + } +} + +static void +dri2_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer) +{ +} + +static const struct glx_context_vtable dri2_context_vtable = { + dri2_destroy_context, + dri2_bind_context, + dri2_unbind_context, + dri2_wait_gl, + dri2_wait_x, + DRI_glXUseXFont, + dri2_bind_tex_image, + dri2_release_tex_image, +}; + +static void +dri2BindExtensions(struct dri2_screen *psc, const __DRIextension **extensions) +{ + int i; + + __glXEnableDirectExtension(&psc->base, "GLX_SGI_video_sync"); + __glXEnableDirectExtension(&psc->base, "GLX_SGI_swap_control"); + __glXEnableDirectExtension(&psc->base, "GLX_MESA_swap_control"); + __glXEnableDirectExtension(&psc->base, "GLX_SGI_make_current_read"); + + /* FIXME: if DRI2 version supports it... */ + __glXEnableDirectExtension(&psc->base, "INTEL_swap_event"); + + for (i = 0; extensions[i]; i++) { + if ((strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0)) { + psc->texBuffer = (__DRItexBufferExtension *) extensions[i]; + __glXEnableDirectExtension(&psc->base, "GLX_EXT_texture_from_pixmap"); + } + + if ((strcmp(extensions[i]->name, __DRI2_FLUSH) == 0)) { + psc->f = (__DRI2flushExtension *) extensions[i]; + /* internal driver extension, no GL extension exposed */ + } + + if ((strcmp(extensions[i]->name, __DRI2_CONFIG_QUERY) == 0)) + psc->config = (__DRI2configQueryExtension *) extensions[i]; + } +} + +static const struct glx_screen_vtable dri2_screen_vtable = { + dri2_create_context +}; + +static struct glx_screen * +dri2CreateScreen(int screen, struct glx_display * priv) +{ + const __DRIconfig **driver_configs; + const __DRIextension **extensions; + const struct dri2_display *const pdp = (struct dri2_display *) + priv->dri2Display; + struct dri2_screen *psc; + __GLXDRIscreen *psp; + char *driverName, *deviceName; + drm_magic_t magic; + int i; + + psc = Xmalloc(sizeof *psc); + if (psc == NULL) + return NULL; + + memset(psc, 0, sizeof *psc); + if (!glx_screen_init(&psc->base, screen, priv)) + return NULL; + + if (!DRI2Connect(priv->dpy, RootWindow(priv->dpy, screen), + &driverName, &deviceName)) { + XFree(psc); + return NULL; + } + + psc->driver = driOpenDriver(driverName); + if (psc->driver == NULL) { + ErrorMessageF("driver pointer missing\n"); + goto handle_error; + } + + extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS); + if (extensions == NULL) { + ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); + goto handle_error; + } + + for (i = 0; extensions[i]; i++) { + if (strcmp(extensions[i]->name, __DRI_CORE) == 0) + psc->core = (__DRIcoreExtension *) extensions[i]; + if (strcmp(extensions[i]->name, __DRI_DRI2) == 0) + psc->dri2 = (__DRIdri2Extension *) extensions[i]; + } + + if (psc->core == NULL || psc->dri2 == NULL) { + ErrorMessageF("core dri or dri2 extension not found\n"); + goto handle_error; + } + + psc->fd = open(deviceName, O_RDWR); + if (psc->fd < 0) { + ErrorMessageF("failed to open drm device: %s\n", strerror(errno)); + goto handle_error; + } + + if (drmGetMagic(psc->fd, &magic)) { + ErrorMessageF("failed to get magic\n"); + goto handle_error; + } + + if (!DRI2Authenticate(priv->dpy, RootWindow(priv->dpy, screen), magic)) { + ErrorMessageF("failed to authenticate magic %d\n", magic); + goto handle_error; + } + + + /* If the server does not support the protocol for + * DRI2GetBuffersWithFormat, don't supply that interface to the driver. + */ + psc->driScreen = + psc->dri2->createNewScreen(screen, psc->fd, + (const __DRIextension **) + &pdp->loader_extensions[0], + &driver_configs, psc); + + if (psc->driScreen == NULL) { + ErrorMessageF("failed to create dri screen\n"); + goto handle_error; + } + + extensions = psc->core->getExtensions(psc->driScreen); + dri2BindExtensions(psc, extensions); + + psc->base.configs = + driConvertConfigs(psc->core, psc->base.configs, driver_configs); + psc->base.visuals = + driConvertConfigs(psc->core, psc->base.visuals, driver_configs); + + psc->driver_configs = driver_configs; + + psc->base.vtable = &dri2_screen_vtable; + psp = &psc->vtable; + psc->base.driScreen = psp; + psp->destroyScreen = dri2DestroyScreen; + psp->createDrawable = dri2CreateDrawable; + psp->swapBuffers = dri2SwapBuffers; + psp->getDrawableMSC = NULL; + psp->waitForMSC = NULL; + psp->waitForSBC = NULL; + psp->setSwapInterval = NULL; + psp->getSwapInterval = NULL; + + if (pdp->driMinor >= 2) { +#ifdef X_DRI2GetMSC + psp->getDrawableMSC = dri2DrawableGetMSC; +#endif +#ifdef X_DRI2WaitMSC + psp->waitForMSC = dri2WaitForMSC; + psp->waitForSBC = dri2WaitForSBC; +#endif +#ifdef X_DRI2SwapInterval + psp->setSwapInterval = dri2SetSwapInterval; + psp->getSwapInterval = dri2GetSwapInterval; +#endif +#if defined(X_DRI2GetMSC) && defined(X_DRI2WaitMSC) && defined(X_DRI2SwapInterval) + __glXEnableDirectExtension(&psc->base, "GLX_OML_sync_control"); +#endif + } + + /* DRI2 suports SubBuffer through DRI2CopyRegion, so it's always + * available.*/ + psp->copySubBuffer = dri2CopySubBuffer; + __glXEnableDirectExtension(&psc->base, "GLX_MESA_copy_sub_buffer"); + + Xfree(driverName); + Xfree(deviceName); + + return &psc->base; + +handle_error: + Xfree(driverName); + Xfree(deviceName); + XFree(psc); + + /* FIXME: clean up here */ + + return NULL; +} + +/* Called from __glXFreeDisplayPrivate. + */ +static void +dri2DestroyDisplay(__GLXDRIdisplay * dpy) +{ + Xfree(dpy); +} + +_X_HIDDEN __GLXDRIdrawable * +dri2GetGlxDrawableFromXDrawableId(Display *dpy, XID id) +{ + struct glx_display *d = __glXInitialize(dpy); + struct dri2_display *pdp = (struct dri2_display *) d->dri2Display; + __GLXDRIdrawable *pdraw; + + if (__glxHashLookup(pdp->dri2Hash, id, (void *) &pdraw) == 0) + return pdraw; + + return NULL; +} + +/* + * Allocate, initialize and return a __DRIdisplayPrivate object. + * This is called from __glXInitialize() when we are given a new + * display pointer. + */ +_X_HIDDEN __GLXDRIdisplay * +dri2CreateDisplay(Display * dpy) +{ + struct dri2_display *pdp; + int eventBase, errorBase, i; + + if (!DRI2QueryExtension(dpy, &eventBase, &errorBase)) + return NULL; + + pdp = Xmalloc(sizeof *pdp); + if (pdp == NULL) + return NULL; + + if (!DRI2QueryVersion(dpy, &pdp->driMajor, &pdp->driMinor)) { + Xfree(pdp); + return NULL; + } + + pdp->driPatch = 0; + pdp->swapAvailable = (pdp->driMinor >= 2); + pdp->invalidateAvailable = (pdp->driMinor >= 3); + + pdp->base.destroyDisplay = dri2DestroyDisplay; + pdp->base.createScreen = dri2CreateScreen; + + i = 0; + if (pdp->driMinor < 1) + pdp->loader_extensions[i++] = &dri2LoaderExtension_old.base; + else + pdp->loader_extensions[i++] = &dri2LoaderExtension.base; + + pdp->loader_extensions[i++] = &systemTimeExtension.base; + +#ifdef __DRI_USE_INVALIDATE + pdp->loader_extensions[i++] = &dri2UseInvalidate.base; +#endif + pdp->loader_extensions[i++] = NULL; + + pdp->dri2Hash = __glxHashCreate(); + if (pdp->dri2Hash == NULL) { + Xfree(pdp); + return NULL; + } + + return &pdp->base; +} + +#endif /* GLX_DIRECT_RENDERING */ diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c new file mode 100644 index 0000000..83d6e3c --- /dev/null +++ b/src/glx/dri_common.c @@ -0,0 +1,410 @@ +/* + * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. + * Copyright © 2008 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Soft- + * ware"), to deal in the Software without restriction, including without + * limitation the rights to use, copy, modify, merge, publish, distribute, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, provided that the above copyright + * notice(s) and this permission notice appear in all copies of the Soft- + * ware and that both the above copyright notice(s) and this permission + * notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- + * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY + * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN + * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- + * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR- + * MANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder shall + * not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization of + * the copyright holder. + * + * Authors: + * Kevin E. Martin + * Brian Paul + * Kristian Høgsberg (krh@redhat.com) + */ + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + +#include +#include +#include +#include "glxclient.h" +#include "dri_common.h" + +#ifndef RTLD_NOW +#define RTLD_NOW 0 +#endif +#ifndef RTLD_GLOBAL +#define RTLD_GLOBAL 0 +#endif + +_X_HIDDEN void +InfoMessageF(const char *f, ...) +{ + va_list args; + const char *env; + + if ((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose")) { + fprintf(stderr, "libGL: "); + va_start(args, f); + vfprintf(stderr, f, args); + va_end(args); + } +} + +/** + * Print error to stderr, unless LIBGL_DEBUG=="quiet". + */ +_X_HIDDEN void +ErrorMessageF(const char *f, ...) +{ + va_list args; + const char *env; + + if ((env = getenv("LIBGL_DEBUG")) && !strstr(env, "quiet")) { + fprintf(stderr, "libGL error: "); + va_start(args, f); + vfprintf(stderr, f, args); + va_end(args); + } +} + +#ifndef DEFAULT_DRIVER_DIR +/* this is normally defined in Mesa/configs/default with DRI_DRIVER_SEARCH_PATH */ +#define DEFAULT_DRIVER_DIR "/usr/local/lib/dri" +#endif + +/** + * Try to \c dlopen the named driver. + * + * This function adds the "_dri.so" suffix to the driver name and searches the + * directories specified by the \c LIBGL_DRIVERS_PATH environment variable in + * order to find the driver. + * + * \param driverName - a name like "tdfx", "i810", "mga", etc. + * + * \returns + * A handle from \c dlopen, or \c NULL if driver file not found. + */ +_X_HIDDEN void * +driOpenDriver(const char *driverName) +{ + void *glhandle, *handle; + const char *libPaths, *p, *next; + char realDriverName[200]; + int len; + + /* Attempt to make sure libGL symbols will be visible to the driver */ + glhandle = dlopen("libGL.so.1", RTLD_NOW | RTLD_GLOBAL); + + libPaths = NULL; + if (geteuid() == getuid()) { + /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */ + libPaths = getenv("LIBGL_DRIVERS_PATH"); + if (!libPaths) + libPaths = getenv("LIBGL_DRIVERS_DIR"); /* deprecated */ + } + if (libPaths == NULL) + libPaths = DEFAULT_DRIVER_DIR; + + handle = NULL; + for (p = libPaths; *p; p = next) { + next = strchr(p, ':'); + if (next == NULL) { + len = strlen(p); + next = p + len; + } + else { + len = next - p; + next++; + } + +#ifdef GLX_USE_TLS + snprintf(realDriverName, sizeof realDriverName, + "%.*s/tls/%s_dri.so", len, p, driverName); + InfoMessageF("OpenDriver: trying %s\n", realDriverName); + handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL); +#endif + + if (handle == NULL) { + snprintf(realDriverName, sizeof realDriverName, + "%.*s/%s_dri.so", len, p, driverName); + InfoMessageF("OpenDriver: trying %s\n", realDriverName); + handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL); + } + + if (handle != NULL) + break; + else + ErrorMessageF("dlopen %s failed (%s)\n", realDriverName, dlerror()); + } + + if (!handle) + ErrorMessageF("unable to load driver: %s_dri.so\n", driverName); + + if (glhandle) + dlclose(glhandle); + + return handle; +} + +static GLboolean +__driGetMSCRate(__DRIdrawable *draw, + int32_t * numerator, int32_t * denominator, + void *loaderPrivate) +{ + __GLXDRIdrawable *glxDraw = loaderPrivate; + + return __glxGetMscRate(glxDraw, numerator, denominator); +} + +_X_HIDDEN const __DRIsystemTimeExtension systemTimeExtension = { + {__DRI_SYSTEM_TIME, __DRI_SYSTEM_TIME_VERSION}, + __glXGetUST, + __driGetMSCRate +}; + +#define __ATTRIB(attrib, field) \ + { attrib, offsetof(struct glx_config, field) } + +static const struct +{ + unsigned int attrib, offset; +} attribMap[] = { + __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits), + __ATTRIB(__DRI_ATTRIB_LEVEL, level), + __ATTRIB(__DRI_ATTRIB_RED_SIZE, redBits), + __ATTRIB(__DRI_ATTRIB_GREEN_SIZE, greenBits), + __ATTRIB(__DRI_ATTRIB_BLUE_SIZE, blueBits), + __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE, alphaBits), + __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE, depthBits), + __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE, stencilBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE, accumRedBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE, accumGreenBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE, accumBlueBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE, accumAlphaBits), + __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS, sampleBuffers), + __ATTRIB(__DRI_ATTRIB_SAMPLES, samples), + __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER, doubleBufferMode), + __ATTRIB(__DRI_ATTRIB_STEREO, stereoMode), + __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS, numAuxBuffers), +#if 0 + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE, transparentPixel), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE, transparentIndex), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE, transparentRed), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE, transparentGreen), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha), + __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask), + __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask), + __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask), + __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask), +#endif + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth), + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight), + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels), + __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth), + __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight), +#if 0 + __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod), +#endif +__ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb), + __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba), + __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE, + bindToMipmapTexture), + __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted),}; + +static int +scalarEqual(struct glx_config *mode, unsigned int attrib, unsigned int value) +{ + unsigned int glxValue; + int i; + + for (i = 0; i < ARRAY_SIZE(attribMap); i++) + if (attribMap[i].attrib == attrib) { + glxValue = *(unsigned int *) ((char *) mode + attribMap[i].offset); + return glxValue == GLX_DONT_CARE || glxValue == value; + } + + return GL_TRUE; /* Is a non-existing attribute equal to value? */ +} + +static int +driConfigEqual(const __DRIcoreExtension *core, + struct glx_config *config, const __DRIconfig *driConfig) +{ + unsigned int attrib, value, glxValue; + int i; + + i = 0; + while (core->indexConfigAttrib(driConfig, i++, &attrib, &value)) { + switch (attrib) { + case __DRI_ATTRIB_RENDER_TYPE: + glxValue = 0; + if (value & __DRI_ATTRIB_RGBA_BIT) { + glxValue |= GLX_RGBA_BIT; + } + else if (value & __DRI_ATTRIB_COLOR_INDEX_BIT) { + glxValue |= GLX_COLOR_INDEX_BIT; + } + if (glxValue != config->renderType) + return GL_FALSE; + break; + + case __DRI_ATTRIB_CONFIG_CAVEAT: + if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG) + glxValue = GLX_NON_CONFORMANT_CONFIG; + else if (value & __DRI_ATTRIB_SLOW_BIT) + glxValue = GLX_SLOW_CONFIG; + else + glxValue = GLX_NONE; + if (glxValue != config->visualRating) + return GL_FALSE; + break; + + case __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS: + glxValue = 0; + if (value & __DRI_ATTRIB_TEXTURE_1D_BIT) + glxValue |= GLX_TEXTURE_1D_BIT_EXT; + if (value & __DRI_ATTRIB_TEXTURE_2D_BIT) + glxValue |= GLX_TEXTURE_2D_BIT_EXT; + if (value & __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT) + glxValue |= GLX_TEXTURE_RECTANGLE_BIT_EXT; + if (config->bindToTextureTargets != GLX_DONT_CARE && + glxValue != config->bindToTextureTargets) + return GL_FALSE; + break; + + default: + if (!scalarEqual(config, attrib, value)) + return GL_FALSE; + } + } + + return GL_TRUE; +} + +static struct glx_config * +createDriMode(const __DRIcoreExtension * core, + struct glx_config *config, const __DRIconfig **driConfigs) +{ + __GLXDRIconfigPrivate *driConfig; + int i; + + for (i = 0; driConfigs[i]; i++) { + if (driConfigEqual(core, config, driConfigs[i])) + break; + } + + if (driConfigs[i] == NULL) + return NULL; + + driConfig = Xmalloc(sizeof *driConfig); + if (driConfig == NULL) + return NULL; + + driConfig->base = *config; + driConfig->driConfig = driConfigs[i]; + + return &driConfig->base; +} + +_X_HIDDEN struct glx_config * +driConvertConfigs(const __DRIcoreExtension * core, + struct glx_config *configs, const __DRIconfig **driConfigs) +{ + struct glx_config head, *tail, *m; + + tail = &head; + head.next = NULL; + for (m = configs; m; m = m->next) { + tail->next = createDriMode(core, m, driConfigs); + if (tail->next == NULL) { + /* no matching dri config for m */ + continue; + } + + + tail = tail->next; + } + + glx_config_destroy_list(configs); + + return head.next; +} + +_X_HIDDEN void +driDestroyConfigs(const __DRIconfig **configs) +{ + int i; + + for (i = 0; configs[i]; i++) + free((__DRIconfig *) configs[i]); + free(configs); +} + +_X_HIDDEN __GLXDRIdrawable * +driFetchDrawable(struct glx_context *gc, GLXDrawable glxDrawable) +{ + struct glx_display *const priv = __glXInitialize(gc->psc->dpy); + __GLXDRIdrawable *pdraw; + struct glx_screen *psc; + + if (priv == NULL) + return NULL; + + psc = priv->screens[gc->screen]; + if (priv->drawHash == NULL) + return NULL; + + if (__glxHashLookup(priv->drawHash, glxDrawable, (void *) &pdraw) == 0) + return pdraw; + + pdraw = psc->driScreen->createDrawable(psc, glxDrawable, + glxDrawable, gc->config); + if (__glxHashInsert(priv->drawHash, glxDrawable, pdraw)) { + (*pdraw->destroyDrawable) (pdraw); + return NULL; + } + + return pdraw; +} + +_X_HIDDEN void +driReleaseDrawables(struct glx_context *gc) +{ + struct glx_display *const priv = __glXInitialize(gc->psc->dpy); + __GLXDRIdrawable *pdraw; + + if (priv == NULL) + return; + + if (__glxHashLookup(priv->drawHash, + gc->currentDrawable, (void *) &pdraw) == 0) { + if (pdraw->drawable == pdraw->xDrawable) { + (*pdraw->destroyDrawable)(pdraw); + __glxHashDelete(priv->drawHash, gc->currentDrawable); + } + } + + if (gc->currentDrawable != gc->currentReadable && + __glxHashLookup(priv->drawHash, + gc->currentReadable, (void *) &pdraw) == 0) { + if (pdraw->drawable == pdraw->xDrawable) { + (*pdraw->destroyDrawable)(pdraw); + __glxHashDelete(priv->drawHash, gc->currentReadable); + } + } +} + +#endif /* GLX_DIRECT_RENDERING */ diff --git a/src/glx/dri_common.h b/src/glx/dri_common.h new file mode 100644 index 0000000..13b5ae4 --- /dev/null +++ b/src/glx/dri_common.h @@ -0,0 +1,69 @@ +/* + * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. + * Copyright © 2008 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Soft- + * ware"), to deal in the Software without restriction, including without + * limitation the rights to use, copy, modify, merge, publish, distribute, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, provided that the above copyright + * notice(s) and this permission notice appear in all copies of the Soft- + * ware and that both the above copyright notice(s) and this permission + * notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- + * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY + * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN + * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- + * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR- + * MANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder shall + * not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization of + * the copyright holder. + * + * Authors: + * Kevin E. Martin + * Brian Paul + * Kristian Høgsberg (krh@redhat.com) + */ + +#ifndef _DRI_COMMON_H +#define _DRI_COMMON_H + +#include + +typedef struct __GLXDRIconfigPrivateRec __GLXDRIconfigPrivate; + +struct __GLXDRIconfigPrivateRec +{ + struct glx_config base; + const __DRIconfig *driConfig; +}; + +extern struct glx_config *driConvertConfigs(const __DRIcoreExtension * core, + struct glx_config * modes, + const __DRIconfig ** configs); + +extern void driDestroyConfigs(const __DRIconfig **configs); + +extern __GLXDRIdrawable * +driFetchDrawable(struct glx_context *gc, GLXDrawable glxDrawable); + +extern void +driReleaseDrawables(struct glx_context *gc); + +extern const __DRIsystemTimeExtension systemTimeExtension; + +extern void InfoMessageF(const char *f, ...); + +extern void ErrorMessageF(const char *f, ...); + +extern void *driOpenDriver(const char *driverName); + +#endif /* _DRI_COMMON_H */ diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c new file mode 100644 index 0000000..42b263c --- /dev/null +++ b/src/glx/dri_glx.c @@ -0,0 +1,950 @@ +/************************************************************************** + +Copyright 1998-1999 Precision Insight, 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 PRECISION INSIGHT 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. + +**************************************************************************/ + +/* + * Authors: + * Kevin E. Martin + * Brian Paul + * + */ + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + +#include +#include +#include +#include "glxclient.h" +#include "xf86dri.h" +#include "dri2.h" +#include "sarea.h" +#include +#include +#include +#include "xf86drm.h" +#include "dri_common.h" + +struct dri_display +{ + __GLXDRIdisplay base; + + /* + ** XFree86-DRI version information + */ + int driMajor; + int driMinor; + int driPatch; +}; + +struct dri_screen +{ + struct glx_screen base; + + __DRIscreen *driScreen; + __GLXDRIscreen vtable; + const __DRIlegacyExtension *legacy; + const __DRIcoreExtension *core; + const __DRIswapControlExtension *swapControl; + const __DRImediaStreamCounterExtension *msc; + const __DRIconfig **driver_configs; + const __DRIcopySubBufferExtension *driCopySubBuffer; + + void *driver; + int fd; +}; + +struct dri_context +{ + struct glx_context base; + __DRIcontext *driContext; + XID hwContextID; +}; + +struct dri_drawable +{ + __GLXDRIdrawable base; + + __DRIdrawable *driDrawable; +}; + +static const struct glx_context_vtable dri_context_vtable; + +/* + * Given a display pointer and screen number, determine the name of + * the DRI driver for the screen. (I.e. "r128", "tdfx", etc). + * Return True for success, False for failure. + */ +static Bool +driGetDriverName(Display * dpy, int scrNum, char **driverName) +{ + int directCapable; + Bool b; + int event, error; + int driverMajor, driverMinor, driverPatch; + + *driverName = NULL; + + if (XF86DRIQueryExtension(dpy, &event, &error)) { /* DRI1 */ + if (!XF86DRIQueryDirectRenderingCapable(dpy, scrNum, &directCapable)) { + ErrorMessageF("XF86DRIQueryDirectRenderingCapable failed\n"); + return False; + } + if (!directCapable) { + ErrorMessageF("XF86DRIQueryDirectRenderingCapable returned false\n"); + return False; + } + + b = XF86DRIGetClientDriverName(dpy, scrNum, &driverMajor, &driverMinor, + &driverPatch, driverName); + if (!b) { + ErrorMessageF("Cannot determine driver name for screen %d\n", + scrNum); + return False; + } + + InfoMessageF("XF86DRIGetClientDriverName: %d.%d.%d %s (screen %d)\n", + driverMajor, driverMinor, driverPatch, *driverName, + scrNum); + + return True; + } + else if (DRI2QueryExtension(dpy, &event, &error)) { /* DRI2 */ + char *dev; + Bool ret = DRI2Connect(dpy, RootWindow(dpy, scrNum), driverName, &dev); + + if (ret) + Xfree(dev); + + return ret; + } + + return False; +} + +/* + * Exported function for querying the DRI driver for a given screen. + * + * The returned char pointer points to a static array that will be + * overwritten by subsequent calls. + */ +_X_EXPORT const char * +glXGetScreenDriver(Display * dpy, int scrNum) +{ + static char ret[32]; + char *driverName; + if (driGetDriverName(dpy, scrNum, &driverName)) { + int len; + if (!driverName) + return NULL; + len = strlen(driverName); + if (len >= 31) + return NULL; + memcpy(ret, driverName, len + 1); + Xfree(driverName); + return ret; + } + return NULL; +} + +/* + * Exported function for obtaining a driver's option list (UTF-8 encoded XML). + * + * The returned char pointer points directly into the driver. Therefore + * it should be treated as a constant. + * + * If the driver was not found or does not support configuration NULL is + * returned. + * + * Note: The driver remains opened after this function returns. + */ +_X_EXPORT const char * +glXGetDriverConfig(const char *driverName) +{ + void *handle = driOpenDriver(driverName); + if (handle) + return dlsym(handle, "__driConfigOptions"); + else + return NULL; +} + +#ifdef XDAMAGE_1_1_INTERFACE + +static GLboolean +has_damage_post(Display * dpy) +{ + static GLboolean inited = GL_FALSE; + static GLboolean has_damage; + + if (!inited) { + int major, minor; + + if (XDamageQueryVersion(dpy, &major, &minor) && + major == 1 && minor >= 1) { + has_damage = GL_TRUE; + } + else { + has_damage = GL_FALSE; + } + inited = GL_TRUE; + } + + return has_damage; +} + +static void +__glXReportDamage(__DRIdrawable * driDraw, + int x, int y, + drm_clip_rect_t * rects, int num_rects, + GLboolean front_buffer, void *loaderPrivate) +{ + XRectangle *xrects; + XserverRegion region; + int i; + int x_off, y_off; + __GLXDRIdrawable *glxDraw = loaderPrivate; + struct glx_screen *psc = glxDraw->psc; + Display *dpy = psc->dpy; + Drawable drawable; + + if (!has_damage_post(dpy)) + return; + + if (front_buffer) { + x_off = x; + y_off = y; + drawable = RootWindow(dpy, psc->scr); + } + else { + x_off = 0; + y_off = 0; + drawable = glxDraw->xDrawable; + } + + xrects = malloc(sizeof(XRectangle) * num_rects); + if (xrects == NULL) + return; + + for (i = 0; i < num_rects; i++) { + xrects[i].x = rects[i].x1 + x_off; + xrects[i].y = rects[i].y1 + y_off; + xrects[i].width = rects[i].x2 - rects[i].x1; + xrects[i].height = rects[i].y2 - rects[i].y1; + } + region = XFixesCreateRegion(dpy, xrects, num_rects); + free(xrects); + XDamageAdd(dpy, drawable, region); + XFixesDestroyRegion(dpy, region); +} + +static const __DRIdamageExtension damageExtension = { + {__DRI_DAMAGE, __DRI_DAMAGE_VERSION}, + __glXReportDamage, +}; + +#endif + +static GLboolean +__glXDRIGetDrawableInfo(__DRIdrawable * drawable, + unsigned int *index, unsigned int *stamp, + int *X, int *Y, int *W, int *H, + int *numClipRects, drm_clip_rect_t ** pClipRects, + int *backX, int *backY, + int *numBackClipRects, + drm_clip_rect_t ** pBackClipRects, + void *loaderPrivate) +{ + __GLXDRIdrawable *glxDraw = loaderPrivate; + struct glx_screen *psc = glxDraw->psc; + Display *dpy = psc->dpy; + + return XF86DRIGetDrawableInfo(dpy, psc->scr, glxDraw->drawable, + index, stamp, X, Y, W, H, + numClipRects, pClipRects, + backX, backY, + numBackClipRects, pBackClipRects); +} + +static const __DRIgetDrawableInfoExtension getDrawableInfoExtension = { + {__DRI_GET_DRAWABLE_INFO, __DRI_GET_DRAWABLE_INFO_VERSION}, + __glXDRIGetDrawableInfo +}; + +static const __DRIextension *loader_extensions[] = { + &systemTimeExtension.base, + &getDrawableInfoExtension.base, +#ifdef XDAMAGE_1_1_INTERFACE + &damageExtension.base, +#endif + NULL +}; + +/** + * Perform the required libGL-side initialization and call the client-side + * driver's \c __driCreateNewScreen function. + * + * \param dpy Display pointer. + * \param scrn Screen number on the display. + * \param psc DRI screen information. + * \param driDpy DRI display information. + * \param createNewScreen Pointer to the client-side driver's + * \c __driCreateNewScreen function. + * \returns A pointer to the \c __DRIscreen structure returned by + * the client-side driver on success, or \c NULL on failure. + */ +static void * +CallCreateNewScreen(Display *dpy, int scrn, struct dri_screen *psc, + struct dri_display * driDpy) +{ + void *psp = NULL; + drm_handle_t hSAREA; + drmAddress pSAREA = MAP_FAILED; + char *BusID; + __DRIversion ddx_version; + __DRIversion dri_version; + __DRIversion drm_version; + __DRIframebuffer framebuffer; + int fd = -1; + int status; + + drm_magic_t magic; + drmVersionPtr version; + int newlyopened; + char *driverName; + drm_handle_t hFB; + int junk; + const __DRIconfig **driver_configs; + struct glx_config *visual; + + /* DRI protocol version. */ + dri_version.major = driDpy->driMajor; + dri_version.minor = driDpy->driMinor; + dri_version.patch = driDpy->driPatch; + + framebuffer.base = MAP_FAILED; + framebuffer.dev_priv = NULL; + framebuffer.size = 0; + + if (!XF86DRIOpenConnection(dpy, scrn, &hSAREA, &BusID)) { + ErrorMessageF("XF86DRIOpenConnection failed\n"); + goto handle_error; + } + + fd = drmOpenOnce(NULL, BusID, &newlyopened); + + Xfree(BusID); /* No longer needed */ + + if (fd < 0) { + ErrorMessageF("drmOpenOnce failed (%s)\n", strerror(-fd)); + goto handle_error; + } + + if (drmGetMagic(fd, &magic)) { + ErrorMessageF("drmGetMagic failed\n"); + goto handle_error; + } + + version = drmGetVersion(fd); + if (version) { + drm_version.major = version->version_major; + drm_version.minor = version->version_minor; + drm_version.patch = version->version_patchlevel; + drmFreeVersion(version); + } + else { + drm_version.major = -1; + drm_version.minor = -1; + drm_version.patch = -1; + } + + if (newlyopened && !XF86DRIAuthConnection(dpy, scrn, magic)) { + ErrorMessageF("XF86DRIAuthConnection failed\n"); + goto handle_error; + } + + /* Get device name (like "tdfx") and the ddx version numbers. + * We'll check the version in each DRI driver's "createNewScreen" + * function. */ + if (!XF86DRIGetClientDriverName(dpy, scrn, + &ddx_version.major, + &ddx_version.minor, + &ddx_version.patch, &driverName)) { + ErrorMessageF("XF86DRIGetClientDriverName failed\n"); + goto handle_error; + } + + Xfree(driverName); /* No longer needed. */ + + /* + * Get device-specific info. pDevPriv will point to a struct + * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h) that + * has information about the screen size, depth, pitch, ancilliary + * buffers, DRM mmap handles, etc. + */ + if (!XF86DRIGetDeviceInfo(dpy, scrn, &hFB, &junk, + &framebuffer.size, &framebuffer.stride, + &framebuffer.dev_priv_size, + &framebuffer.dev_priv)) { + ErrorMessageF("XF86DRIGetDeviceInfo failed"); + goto handle_error; + } + + framebuffer.width = DisplayWidth(dpy, scrn); + framebuffer.height = DisplayHeight(dpy, scrn); + + /* Map the framebuffer region. */ + status = drmMap(fd, hFB, framebuffer.size, + (drmAddressPtr) & framebuffer.base); + if (status != 0) { + ErrorMessageF("drmMap of framebuffer failed (%s)", strerror(-status)); + goto handle_error; + } + + /* Map the SAREA region. Further mmap regions may be setup in + * each DRI driver's "createNewScreen" function. + */ + status = drmMap(fd, hSAREA, SAREA_MAX, &pSAREA); + if (status != 0) { + ErrorMessageF("drmMap of SAREA failed (%s)", strerror(-status)); + goto handle_error; + } + + psp = (*psc->legacy->createNewScreen) (scrn, + &ddx_version, + &dri_version, + &drm_version, + &framebuffer, + pSAREA, + fd, + loader_extensions, + &driver_configs, psc); + + if (psp == NULL) { + ErrorMessageF("Calling driver entry point failed"); + goto handle_error; + } + + psc->base.configs = + driConvertConfigs(psc->core, psc->base.configs, driver_configs); + psc->base.visuals = + driConvertConfigs(psc->core, psc->base.visuals, driver_configs); + + psc->driver_configs = driver_configs; + + /* Visuals with depth != screen depth are subject to automatic compositing + * in the X server, so DRI1 can't render to them properly. Mark them as + * non-conformant to prevent apps from picking them up accidentally. + */ + for (visual = psc->base.visuals; visual; visual = visual->next) { + XVisualInfo template; + XVisualInfo *visuals; + int num_visuals; + long mask; + + template.visualid = visual->visualID; + mask = VisualIDMask; + visuals = XGetVisualInfo(dpy, mask, &template, &num_visuals); + + if (visuals) { + if (num_visuals > 0 && visuals->depth != DefaultDepth(dpy, scrn)) + visual->visualRating = GLX_NON_CONFORMANT_CONFIG; + + XFree(visuals); + } + } + + return psp; + + handle_error: + if (pSAREA != MAP_FAILED) + drmUnmap(pSAREA, SAREA_MAX); + + if (framebuffer.base != MAP_FAILED) + drmUnmap((drmAddress) framebuffer.base, framebuffer.size); + + if (framebuffer.dev_priv != NULL) + Xfree(framebuffer.dev_priv); + + if (fd >= 0) + drmCloseOnce(fd); + + XF86DRICloseConnection(dpy, scrn); + + ErrorMessageF("reverting to software direct rendering\n"); + + return NULL; +} + +static void +dri_destroy_context(struct glx_context * context) +{ + struct dri_context *pcp = (struct dri_context *) context; + struct dri_screen *psc = (struct dri_screen *) context->psc; + + if (context->xid) + glx_send_destroy_context(psc->base.dpy, context->xid); + + if (context->extensions) + XFree((char *) context->extensions); + + (*psc->core->destroyContext) (pcp->driContext); + + XF86DRIDestroyContext(psc->base.dpy, psc->base.scr, pcp->hwContextID); + Xfree(pcp); +} + +static int +dri_bind_context(struct glx_context *context, struct glx_context *old, + GLXDrawable draw, GLXDrawable read) +{ + struct dri_context *pcp = (struct dri_context *) context; + struct dri_screen *psc = (struct dri_screen *) pcp->base.psc; + struct dri_drawable *pdraw, *pread; + + pdraw = (struct dri_drawable *) driFetchDrawable(context, draw); + pread = (struct dri_drawable *) driFetchDrawable(context, read); + + if (pdraw == NULL || pread == NULL) + return GLXBadDrawable; + + if ((*psc->core->bindContext) (pcp->driContext, + pdraw->driDrawable, pread->driDrawable)) + return Success; + + return GLXBadContext; +} + +static void +dri_unbind_context(struct glx_context *context, struct glx_context *new) +{ + struct dri_context *pcp = (struct dri_context *) context; + struct dri_screen *psc = (struct dri_screen *) pcp->base.psc; + + (*psc->core->unbindContext) (pcp->driContext); + + driReleaseDrawables(&pcp->base); +} + +static const struct glx_context_vtable dri_context_vtable = { + dri_destroy_context, + dri_bind_context, + dri_unbind_context, + NULL, + NULL, + DRI_glXUseXFont, + NULL, + NULL, +}; + +static struct glx_context * +dri_create_context(struct glx_screen *base, + struct glx_config *config_base, + struct glx_context *shareList, int renderType) +{ + struct dri_context *pcp, *pcp_shared; + struct dri_screen *psc = (struct dri_screen *) base; + drm_context_t hwContext; + __DRIcontext *shared = NULL; + __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base; + + if (!psc->base.driScreen) + return NULL; + + if (shareList) { + pcp_shared = (struct dri_context *) shareList; + shared = pcp_shared->driContext; + } + + pcp = Xmalloc(sizeof *pcp); + if (pcp == NULL) + return NULL; + + memset(pcp, 0, sizeof *pcp); + if (!glx_context_init(&pcp->base, &psc->base, &config->base)) { + Xfree(pcp); + return NULL; + } + + if (!XF86DRICreateContextWithConfig(psc->base.dpy, psc->base.scr, + config->base.visualID, + &pcp->hwContextID, &hwContext)) { + Xfree(pcp); + return NULL; + } + + pcp->driContext = + (*psc->legacy->createNewContext) (psc->driScreen, + config->driConfig, + renderType, shared, hwContext, pcp); + if (pcp->driContext == NULL) { + XF86DRIDestroyContext(psc->base.dpy, psc->base.scr, pcp->hwContextID); + Xfree(pcp); + return NULL; + } + + pcp->base.vtable = &dri_context_vtable; + + return &pcp->base; +} + +static void +driDestroyDrawable(__GLXDRIdrawable * pdraw) +{ + struct dri_screen *psc = (struct dri_screen *) pdraw->psc; + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; + + (*psc->core->destroyDrawable) (pdp->driDrawable); + XF86DRIDestroyDrawable(psc->base.dpy, psc->base.scr, pdraw->drawable); + Xfree(pdraw); +} + +static __GLXDRIdrawable * +driCreateDrawable(struct glx_screen *base, + XID xDrawable, + GLXDrawable drawable, struct glx_config *config_base) +{ + drm_drawable_t hwDrawable; + void *empty_attribute_list = NULL; + __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base; + struct dri_screen *psc = (struct dri_screen *) base; + struct dri_drawable *pdp; + + /* Old dri can't handle GLX 1.3+ drawable constructors. */ + if (xDrawable != drawable) + return NULL; + + pdp = Xmalloc(sizeof *pdp); + if (!pdp) + return NULL; + + memset(pdp, 0, sizeof *pdp); + pdp->base.drawable = drawable; + pdp->base.psc = &psc->base; + + if (!XF86DRICreateDrawable(psc->base.dpy, psc->base.scr, + drawable, &hwDrawable)) { + Xfree(pdp); + return NULL; + } + + /* Create a new drawable */ + pdp->driDrawable = + (*psc->legacy->createNewDrawable) (psc->driScreen, + config->driConfig, + hwDrawable, + GLX_WINDOW_BIT, + empty_attribute_list, pdp); + + if (!pdp->driDrawable) { + XF86DRIDestroyDrawable(psc->base.dpy, psc->base.scr, drawable); + Xfree(pdp); + return NULL; + } + + pdp->base.destroyDrawable = driDestroyDrawable; + + return &pdp->base; +} + +static int64_t +driSwapBuffers(__GLXDRIdrawable * pdraw, int64_t unused1, int64_t unused2, + int64_t unused3) +{ + struct dri_screen *psc = (struct dri_screen *) pdraw->psc; + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; + + (*psc->core->swapBuffers) (pdp->driDrawable); + return 0; +} + +static void +driCopySubBuffer(__GLXDRIdrawable * pdraw, + int x, int y, int width, int height) +{ + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; + struct dri_screen *psc = (struct dri_screen *) pdp->base.psc; + + (*psc->driCopySubBuffer->copySubBuffer) (pdp->driDrawable, + x, y, width, height); +} + +static void +driDestroyScreen(struct glx_screen *base) +{ + struct dri_screen *psc = (struct dri_screen *) base; + + /* Free the direct rendering per screen data */ + if (psc->driScreen) + (*psc->core->destroyScreen) (psc->driScreen); + driDestroyConfigs(psc->driver_configs); + psc->driScreen = NULL; + if (psc->driver) + dlclose(psc->driver); +} + +#ifdef __DRI_SWAP_BUFFER_COUNTER + +static int +driDrawableGetMSC(struct glx_screen *base, __GLXDRIdrawable *pdraw, + int64_t *ust, int64_t *msc, int64_t *sbc) +{ + struct dri_screen *psc = (struct dri_screen *) base; + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; + + if (pdp && psc->sbc && psc->msc) + return ( (*psc->msc->getMSC)(psc->driScreen, msc) == 0 && + (*psc->sbc->getSBC)(pdp->driDrawable, sbc) == 0 && + __glXGetUST(ust) == 0 ); +} + +static int +driWaitForMSC(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor, + int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc) +{ + struct dri_screen *psc = (struct dri_screen *) pdraw->psc; + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; + + if (pdp != NULL && psc->msc != NULL) { + ret = (*psc->msc->waitForMSC) (pdp->driDrawable, target_msc, + divisor, remainder, msc, sbc); + + /* __glXGetUST returns zero on success and non-zero on failure. + * This function returns True on success and False on failure. + */ + return ret == 0 && __glXGetUST(ust) == 0; + } +} + +static int +driWaitForSBC(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust, + int64_t *msc, int64_t *sbc) +{ + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; + + if (pdp != NULL && psc->sbc != NULL) { + ret = + (*psc->sbc->waitForSBC) (pdp->driDrawable, target_sbc, msc, sbc); + + /* __glXGetUST returns zero on success and non-zero on failure. + * This function returns True on success and False on failure. + */ + return ((ret == 0) && (__glXGetUST(ust) == 0)); + } + + return DRI2WaitSBC(pdp->base.psc->dpy, + pdp->base.xDrawable, target_sbc, ust, msc, sbc); +} + +#endif + +static int +driSetSwapInterval(__GLXDRIdrawable *pdraw, int interval) +{ + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; + struct dri_screen *psc = (struct dri_screen *) pdraw->psc; + + if (psc->swapControl != NULL && pdraw != NULL) { + psc->swapControl->setSwapInterval(pdp->driDrawable, interval); + return 0; + } + + return GLX_BAD_CONTEXT; +} + +static int +driGetSwapInterval(__GLXDRIdrawable *pdraw) +{ + struct dri_drawable *pdp = (struct dri_drawable *) pdraw; + struct dri_screen *psc = (struct dri_screen *) pdraw->psc; + + if (psc->swapControl != NULL && pdraw != NULL) + return psc->swapControl->getSwapInterval(pdp->driDrawable); + + return 0; +} + +/* Bind DRI1 specific extensions */ +static void +driBindExtensions(struct dri_screen *psc, const __DRIextension **extensions) +{ + int i; + + for (i = 0; extensions[i]; i++) { + /* No DRI2 support for swap_control at the moment, since SwapBuffers + * is done by the X server */ + if (strcmp(extensions[i]->name, __DRI_SWAP_CONTROL) == 0) { + psc->swapControl = (__DRIswapControlExtension *) extensions[i]; + __glXEnableDirectExtension(&psc->base, "GLX_SGI_swap_control"); + __glXEnableDirectExtension(&psc->base, "GLX_MESA_swap_control"); + } + + if (strcmp(extensions[i]->name, __DRI_MEDIA_STREAM_COUNTER) == 0) { + psc->msc = (__DRImediaStreamCounterExtension *) extensions[i]; + __glXEnableDirectExtension(&psc->base, "GLX_SGI_video_sync"); + } + + if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) { + psc->driCopySubBuffer = (__DRIcopySubBufferExtension *) extensions[i]; + __glXEnableDirectExtension(&psc->base, "GLX_MESA_copy_sub_buffer"); + } + + if (strcmp(extensions[i]->name, __DRI_READ_DRAWABLE) == 0) { + __glXEnableDirectExtension(&psc->base, "GLX_SGI_make_current_read"); + } + /* Ignore unknown extensions */ + } +} + +static const struct glx_screen_vtable dri_screen_vtable = { + dri_create_context +}; + +static struct glx_screen * +driCreateScreen(int screen, struct glx_display *priv) +{ + struct dri_display *pdp; + __GLXDRIscreen *psp; + const __DRIextension **extensions; + struct dri_screen *psc; + char *driverName; + int i; + + psc = Xcalloc(1, sizeof *psc); + if (psc == NULL) + return NULL; + + memset(psc, 0, sizeof *psc); + if (!glx_screen_init(&psc->base, screen, priv)) + return NULL; + + if (!driGetDriverName(priv->dpy, screen, &driverName)) { + Xfree(psc); + return NULL; + } + + psc->driver = driOpenDriver(driverName); + Xfree(driverName); + if (psc->driver == NULL) { + Xfree(psc); + return NULL; + } + + extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS); + if (extensions == NULL) { + ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); + Xfree(psc); + return NULL; + } + + for (i = 0; extensions[i]; i++) { + if (strcmp(extensions[i]->name, __DRI_CORE) == 0) + psc->core = (__DRIcoreExtension *) extensions[i]; + if (strcmp(extensions[i]->name, __DRI_LEGACY) == 0) + psc->legacy = (__DRIlegacyExtension *) extensions[i]; + } + + if (psc->core == NULL || psc->legacy == NULL) { + Xfree(psc); + return NULL; + } + + pdp = (struct dri_display *) priv->driDisplay; + psc->driScreen = + CallCreateNewScreen(psc->base.dpy, screen, psc, pdp); + if (psc->driScreen == NULL) { + dlclose(psc->driver); + Xfree(psc); + return NULL; + } + + extensions = psc->core->getExtensions(psc->driScreen); + driBindExtensions(psc, extensions); + + psc->base.vtable = &dri_screen_vtable; + psp = &psc->vtable; + psc->base.driScreen = psp; + if (psc->driCopySubBuffer) + psp->copySubBuffer = driCopySubBuffer; + + psp->destroyScreen = driDestroyScreen; + psp->createDrawable = driCreateDrawable; + psp->swapBuffers = driSwapBuffers; + +#ifdef __DRI_SWAP_BUFFER_COUNTER + psp->getDrawableMSC = driDrawableGetMSC; + psp->waitForMSC = driWaitForMSC; + psp->waitForSBC = driWaitForSBC; +#endif + + psp->setSwapInterval = driSetSwapInterval; + psp->getSwapInterval = driGetSwapInterval; + + return &psc->base; +} + +/* Called from __glXFreeDisplayPrivate. + */ +static void +driDestroyDisplay(__GLXDRIdisplay * dpy) +{ + Xfree(dpy); +} + +/* + * Allocate, initialize and return a __DRIdisplayPrivate object. + * This is called from __glXInitialize() when we are given a new + * display pointer. + */ +_X_HIDDEN __GLXDRIdisplay * +driCreateDisplay(Display * dpy) +{ + struct dri_display *pdpyp; + int eventBase, errorBase; + int major, minor, patch; + + if (!XF86DRIQueryExtension(dpy, &eventBase, &errorBase)) { + return NULL; + } + + if (!XF86DRIQueryVersion(dpy, &major, &minor, &patch)) { + return NULL; + } + + pdpyp = Xmalloc(sizeof *pdpyp); + if (!pdpyp) { + return NULL; + } + + pdpyp->driMajor = major; + pdpyp->driMinor = minor; + pdpyp->driPatch = patch; + + pdpyp->base.destroyDisplay = driDestroyDisplay; + pdpyp->base.createScreen = driCreateScreen; + + return &pdpyp->base; +} + +#endif /* GLX_DIRECT_RENDERING */ diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c new file mode 100644 index 0000000..237ce17 --- /dev/null +++ b/src/glx/drisw_glx.c @@ -0,0 +1,542 @@ +/* + * Copyright 2008 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, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + +#include +#include "glxclient.h" +#include +#include "dri_common.h" + +struct drisw_display +{ + __GLXDRIdisplay base; +}; + +struct drisw_context +{ + struct glx_context base; + __DRIcontext *driContext; + +}; + +struct drisw_screen +{ + struct glx_screen base; + + __DRIscreen *driScreen; + __GLXDRIscreen vtable; + const __DRIcoreExtension *core; + const __DRIswrastExtension *swrast; + const __DRIconfig **driver_configs; + + void *driver; +}; + +struct drisw_drawable +{ + __GLXDRIdrawable base; + + GC gc; + GC swapgc; + + __DRIdrawable *driDrawable; + XVisualInfo *visinfo; + XImage *ximage; +}; + +static Bool +XCreateDrawable(struct drisw_drawable * pdp, + Display * dpy, XID drawable, int visualid) +{ + XGCValues gcvalues; + long visMask; + XVisualInfo visTemp; + int num_visuals; + + /* create GC's */ + pdp->gc = XCreateGC(dpy, drawable, 0, NULL); + pdp->swapgc = XCreateGC(dpy, drawable, 0, NULL); + + gcvalues.function = GXcopy; + gcvalues.graphics_exposures = False; + XChangeGC(dpy, pdp->gc, GCFunction, &gcvalues); + XChangeGC(dpy, pdp->swapgc, GCFunction, &gcvalues); + XChangeGC(dpy, pdp->swapgc, GCGraphicsExposures, &gcvalues); + + /* visual */ + visTemp.screen = DefaultScreen(dpy); + visTemp.visualid = visualid; + visMask = (VisualScreenMask | VisualIDMask); + pdp->visinfo = XGetVisualInfo(dpy, visMask, &visTemp, &num_visuals); + + /* create XImage */ + pdp->ximage = XCreateImage(dpy, + pdp->visinfo->visual, + pdp->visinfo->depth, + ZPixmap, 0, /* format, offset */ + NULL, /* data */ + 0, 0, /* width, height */ + 32, /* bitmap_pad */ + 0); /* bytes_per_line */ + + return True; +} + +static void +XDestroyDrawable(struct drisw_drawable * pdp, Display * dpy, XID drawable) +{ + XDestroyImage(pdp->ximage); + XFree(pdp->visinfo); + + XFreeGC(dpy, pdp->gc); + XFreeGC(dpy, pdp->swapgc); +} + +/** + * swrast loader functions + */ + +static void +swrastGetDrawableInfo(__DRIdrawable * draw, + int *x, int *y, int *w, int *h, + void *loaderPrivate) +{ + struct drisw_drawable *pdp = loaderPrivate; + __GLXDRIdrawable *pdraw = &(pdp->base); + Display *dpy = pdraw->psc->dpy; + Drawable drawable; + + Window root; + Status stat; + unsigned uw, uh, bw, depth; + + drawable = pdraw->xDrawable; + + stat = XGetGeometry(dpy, drawable, &root, + x, y, &uw, &uh, &bw, &depth); + *w = uw; + *h = uh; +} + +/** + * Align renderbuffer pitch. + * + * This should be chosen by the driver and the loader (libGL, xserver/glx) + * should use the driver provided pitch. + * + * It seems that the xorg loader (that is the xserver loading swrast_dri for + * indirect rendering, not client-side libGL) requires that the pitch is + * exactly the image width padded to 32 bits. XXX + * + * The above restriction can probably be overcome by using ScratchPixmap and + * CopyArea in the xserver, similar to ShmPutImage, and setting the width of + * the scratch pixmap to 'pitch / cpp'. + */ +static inline int +bytes_per_line(unsigned pitch_bits, unsigned mul) +{ + unsigned mask = mul - 1; + + return ((pitch_bits + mask) & ~mask) / 8; +} + +static void +swrastPutImage(__DRIdrawable * draw, int op, + int x, int y, int w, int h, + char *data, void *loaderPrivate) +{ + struct drisw_drawable *pdp = loaderPrivate; + __GLXDRIdrawable *pdraw = &(pdp->base); + Display *dpy = pdraw->psc->dpy; + Drawable drawable; + XImage *ximage; + GC gc; + + switch (op) { + case __DRI_SWRAST_IMAGE_OP_DRAW: + gc = pdp->gc; + break; + case __DRI_SWRAST_IMAGE_OP_SWAP: + gc = pdp->swapgc; + break; + default: + return; + } + + drawable = pdraw->xDrawable; + + ximage = pdp->ximage; + ximage->data = data; + ximage->width = w; + ximage->height = h; + ximage->bytes_per_line = bytes_per_line(w * ximage->bits_per_pixel, 32); + + XPutImage(dpy, drawable, gc, ximage, 0, 0, x, y, w, h); + + ximage->data = NULL; +} + +static void +swrastGetImage(__DRIdrawable * read, + int x, int y, int w, int h, + char *data, void *loaderPrivate) +{ + struct drisw_drawable *prp = loaderPrivate; + __GLXDRIdrawable *pread = &(prp->base); + Display *dpy = pread->psc->dpy; + Drawable readable; + XImage *ximage; + + readable = pread->xDrawable; + + ximage = prp->ximage; + ximage->data = data; + ximage->width = w; + ximage->height = h; + ximage->bytes_per_line = bytes_per_line(w * ximage->bits_per_pixel, 32); + + XGetSubImage(dpy, readable, x, y, w, h, ~0L, ZPixmap, ximage, 0, 0); + + ximage->data = NULL; +} + +static const __DRIswrastLoaderExtension swrastLoaderExtension = { + {__DRI_SWRAST_LOADER, __DRI_SWRAST_LOADER_VERSION}, + swrastGetDrawableInfo, + swrastPutImage, + swrastGetImage +}; + +static const __DRIextension *loader_extensions[] = { + &systemTimeExtension.base, + &swrastLoaderExtension.base, + NULL +}; + +/** + * GLXDRI functions + */ + +static void +drisw_destroy_context(struct glx_context *context) +{ + struct drisw_context *pcp = (struct drisw_context *) context; + struct drisw_screen *psc = (struct drisw_screen *) context->psc; + + if (context->xid) + glx_send_destroy_context(psc->base.dpy, context->xid); + + if (context->extensions) + XFree((char *) context->extensions); + + (*psc->core->destroyContext) (pcp->driContext); + + Xfree(pcp); +} + +static int +drisw_bind_context(struct glx_context *context, struct glx_context *old, + GLXDrawable draw, GLXDrawable read) +{ + struct drisw_context *pcp = (struct drisw_context *) context; + struct drisw_screen *psc = (struct drisw_screen *) pcp->base.psc; + struct drisw_drawable *pdraw, *pread; + + pdraw = (struct drisw_drawable *) driFetchDrawable(context, draw); + pread = (struct drisw_drawable *) driFetchDrawable(context, read); + + if (pdraw == NULL || pread == NULL) + return GLXBadDrawable; + + if ((*psc->core->bindContext) (pcp->driContext, + pdraw->driDrawable, pread->driDrawable)) + return Success; + + return GLXBadContext; +} + +static void +drisw_unbind_context(struct glx_context *context, struct glx_context *new) +{ + struct drisw_context *pcp = (struct drisw_context *) context; + struct drisw_screen *psc = (struct drisw_screen *) pcp->base.psc; + + (*psc->core->unbindContext) (pcp->driContext); + + driReleaseDrawables(&pcp->base); +} + +static const struct glx_context_vtable drisw_context_vtable = { + drisw_destroy_context, + drisw_bind_context, + drisw_unbind_context, + NULL, + NULL, + DRI_glXUseXFont, + NULL, + NULL, +}; + +static struct glx_context * +drisw_create_context(struct glx_screen *base, + struct glx_config *config_base, + struct glx_context *shareList, int renderType) +{ + struct drisw_context *pcp, *pcp_shared; + __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base; + struct drisw_screen *psc = (struct drisw_screen *) base; + __DRIcontext *shared = NULL; + + if (!psc->base.driScreen) + return NULL; + + if (shareList) { + pcp_shared = (struct drisw_context *) shareList; + shared = pcp_shared->driContext; + } + + pcp = Xmalloc(sizeof *pcp); + if (pcp == NULL) + return NULL; + + memset(pcp, 0, sizeof *pcp); + if (!glx_context_init(&pcp->base, &psc->base, &config->base)) { + Xfree(pcp); + return NULL; + } + + pcp->driContext = + (*psc->core->createNewContext) (psc->driScreen, + config->driConfig, shared, pcp); + if (pcp->driContext == NULL) { + Xfree(pcp); + return NULL; + } + + pcp->base.vtable = &drisw_context_vtable; + + return &pcp->base; +} + +static void +driDestroyDrawable(__GLXDRIdrawable * pdraw) +{ + struct drisw_drawable *pdp = (struct drisw_drawable *) pdraw; + struct drisw_screen *psc = (struct drisw_screen *) pdp->base.psc; + + (*psc->core->destroyDrawable) (pdp->driDrawable); + + XDestroyDrawable(pdp, pdraw->psc->dpy, pdraw->drawable); + Xfree(pdp); +} + +static __GLXDRIdrawable * +driCreateDrawable(struct glx_screen *base, XID xDrawable, + GLXDrawable drawable, struct glx_config *modes) +{ + struct drisw_drawable *pdp; + __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes; + struct drisw_screen *psc = (struct drisw_screen *) base; + + const __DRIswrastExtension *swrast = psc->swrast; + + /* Old dri can't handle GLX 1.3+ drawable constructors. */ + if (xDrawable != drawable) + return NULL; + + pdp = Xmalloc(sizeof(*pdp)); + if (!pdp) + return NULL; + + memset(pdp, 0, sizeof *pdp); + pdp->base.xDrawable = xDrawable; + pdp->base.drawable = drawable; + pdp->base.psc = &psc->base; + + XCreateDrawable(pdp, psc->base.dpy, xDrawable, modes->visualID); + + /* Create a new drawable */ + pdp->driDrawable = + (*swrast->createNewDrawable) (psc->driScreen, config->driConfig, pdp); + + if (!pdp->driDrawable) { + XDestroyDrawable(pdp, psc->base.dpy, xDrawable); + Xfree(pdp); + return NULL; + } + + pdp->base.destroyDrawable = driDestroyDrawable; + + return &pdp->base; +} + +static int64_t +driSwapBuffers(__GLXDRIdrawable * pdraw, + int64_t target_msc, int64_t divisor, int64_t remainder) +{ + struct drisw_drawable *pdp = (struct drisw_drawable *) pdraw; + struct drisw_screen *psc = (struct drisw_screen *) pdp->base.psc; + + (void) target_msc; + (void) divisor; + (void) remainder; + + (*psc->core->swapBuffers) (pdp->driDrawable); + + return 0; +} + +static void +driDestroyScreen(struct glx_screen *base) +{ + struct drisw_screen *psc = (struct drisw_screen *) base; + + /* Free the direct rendering per screen data */ + (*psc->core->destroyScreen) (psc->driScreen); + driDestroyConfigs(psc->driver_configs); + psc->driScreen = NULL; + if (psc->driver) + dlclose(psc->driver); +} + +static void * +driOpenSwrast(void) +{ + void *driver = NULL; + + if (driver == NULL) + driver = driOpenDriver("swrast"); + + if (driver == NULL) + driver = driOpenDriver("swrastg"); + + return driver; +} + +static const struct glx_screen_vtable drisw_screen_vtable = { + drisw_create_context +}; + +static struct glx_screen * +driCreateScreen(int screen, struct glx_display *priv) +{ + __GLXDRIscreen *psp; + const __DRIconfig **driver_configs; + const __DRIextension **extensions; + struct drisw_screen *psc; + int i; + + psc = Xcalloc(1, sizeof *psc); + if (psc == NULL) + return NULL; + + memset(psc, 0, sizeof *psc); + if (!glx_screen_init(&psc->base, screen, priv)) + return NULL; + + psc->driver = driOpenSwrast(); + if (psc->driver == NULL) + goto handle_error; + + extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS); + if (extensions == NULL) { + ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); + goto handle_error; + } + + for (i = 0; extensions[i]; i++) { + if (strcmp(extensions[i]->name, __DRI_CORE) == 0) + psc->core = (__DRIcoreExtension *) extensions[i]; + if (strcmp(extensions[i]->name, __DRI_SWRAST) == 0) + psc->swrast = (__DRIswrastExtension *) extensions[i]; + } + + if (psc->core == NULL || psc->swrast == NULL) { + ErrorMessageF("core dri extension not found\n"); + goto handle_error; + } + + psc->driScreen = + psc->swrast->createNewScreen(screen, loader_extensions, + &driver_configs, psc); + if (psc->driScreen == NULL) { + ErrorMessageF("failed to create dri screen\n"); + goto handle_error; + } + + psc->base.configs = + driConvertConfigs(psc->core, psc->base.configs, driver_configs); + psc->base.visuals = + driConvertConfigs(psc->core, psc->base.visuals, driver_configs); + + psc->driver_configs = driver_configs; + + psc->base.vtable = &drisw_screen_vtable; + psp = &psc->vtable; + psc->base.driScreen = psp; + psp->destroyScreen = driDestroyScreen; + psp->createDrawable = driCreateDrawable; + psp->swapBuffers = driSwapBuffers; + + return &psc->base; + + handle_error: + if (psc->driver) + dlclose(psc->driver); + Xfree(psc); + + ErrorMessageF("reverting to indirect rendering\n"); + + return NULL; +} + +/* Called from __glXFreeDisplayPrivate. + */ +static void +driDestroyDisplay(__GLXDRIdisplay * dpy) +{ + Xfree(dpy); +} + +/* + * Allocate, initialize and return a __DRIdisplayPrivate object. + * This is called from __glXInitialize() when we are given a new + * display pointer. + */ +_X_HIDDEN __GLXDRIdisplay * +driswCreateDisplay(Display * dpy) +{ + struct drisw_display *pdpyp; + + pdpyp = Xmalloc(sizeof *pdpyp); + if (pdpyp == NULL) + return NULL; + + pdpyp->base.destroyDisplay = driDestroyDisplay; + pdpyp->base.createScreen = driCreateScreen; + + return &pdpyp->base; +} + +#endif /* GLX_DIRECT_RENDERING */ diff --git a/src/glx/eval.c b/src/glx/eval.c new file mode 100644 index 0000000..226fb7d --- /dev/null +++ b/src/glx/eval.c @@ -0,0 +1,132 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "packrender.h" + +/* +** Routines to pack evaluator maps into the transport buffer. Maps are +** allowed to have extra arbitrary data, so these routines extract just +** the information that the GL needs. +*/ + +void +__glFillMap1f(GLint k, GLint order, GLint stride, + const GLfloat * points, GLubyte * pc) +{ + if (stride == k) { + /* Just copy the data */ + __GLX_PUT_FLOAT_ARRAY(0, points, order * k); + } + else { + GLint i; + + for (i = 0; i < order; i++) { + __GLX_PUT_FLOAT_ARRAY(0, points, k); + points += stride; + pc += k * __GLX_SIZE_FLOAT32; + } + } +} + +void +__glFillMap1d(GLint k, GLint order, GLint stride, + const GLdouble * points, GLubyte * pc) +{ + if (stride == k) { + /* Just copy the data */ + __GLX_PUT_DOUBLE_ARRAY(0, points, order * k); + } + else { + GLint i; + for (i = 0; i < order; i++) { + __GLX_PUT_DOUBLE_ARRAY(0, points, k); + points += stride; + pc += k * __GLX_SIZE_FLOAT64; + } + } +} + +void +__glFillMap2f(GLint k, GLint majorOrder, GLint minorOrder, + GLint majorStride, GLint minorStride, + const GLfloat * points, GLfloat * data) +{ + GLint i, j, x; + + if ((minorStride == k) && (majorStride == minorOrder * k)) { + /* Just copy the data */ + __GLX_MEM_COPY(data, points, majorOrder * majorStride * + __GLX_SIZE_FLOAT32); + return; + } + for (i = 0; i < majorOrder; i++) { + for (j = 0; j < minorOrder; j++) { + for (x = 0; x < k; x++) { + data[x] = points[x]; + } + points += minorStride; + data += k; + } + points += majorStride - minorStride * minorOrder; + } +} + +void +__glFillMap2d(GLint k, GLint majorOrder, GLint minorOrder, + GLint majorStride, GLint minorStride, + const GLdouble * points, GLdouble * data) +{ + int i, j, x; + + if ((minorStride == k) && (majorStride == minorOrder * k)) { + /* Just copy the data */ + __GLX_MEM_COPY(data, points, majorOrder * majorStride * + __GLX_SIZE_FLOAT64); + return; + } + +#ifdef __GLX_ALIGN64 + x = k * __GLX_SIZE_FLOAT64; +#endif + for (i = 0; i < majorOrder; i++) { + for (j = 0; j < minorOrder; j++) { +#ifdef __GLX_ALIGN64 + __GLX_MEM_COPY(data, points, x); +#else + for (x = 0; x < k; x++) { + data[x] = points[x]; + } +#endif + points += minorStride; + data += k; + } + points += majorStride - minorStride * minorOrder; + } +} diff --git a/src/glx/glx_pbuffer.c b/src/glx/glx_pbuffer.c new file mode 100644 index 0000000..5f91bc6 --- /dev/null +++ b/src/glx/glx_pbuffer.c @@ -0,0 +1,932 @@ +/* + * (C) Copyright IBM Corporation 2004 + * 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 + * 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 + * IBM 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. + */ + +/** + * \file glx_pbuffer.c + * Implementation of pbuffer related functions. + * + * \author Ian Romanick + */ + +#include +#include "glxclient.h" +#include +#include +#include +#include +#include "glxextensions.h" + +#ifdef GLX_USE_APPLEGL +#include +#include "apple_glx_drawable.h" +#include "glx_error.h" +#endif + +#define WARN_ONCE_GLX_1_3(a, b) { \ + static int warned=1; \ + if(warned) { \ + warn_GLX_1_3((a), b ); \ + warned=0; \ + } \ + } + +/** + * Emit a warning when clients use GLX 1.3 functions on pre-1.3 systems. + */ +static void +warn_GLX_1_3(Display * dpy, const char *function_name) +{ + struct glx_display *priv = __glXInitialize(dpy); + + if (priv->minorVersion < 3) { + fprintf(stderr, + "WARNING: Application calling GLX 1.3 function \"%s\" " + "when GLX 1.3 is not supported! This is an application bug!\n", + function_name); + } +} + +#ifndef GLX_USE_APPLEGL +/** + * Change a drawable's attribute. + * + * This function is used to implement \c glXSelectEvent and + * \c glXSelectEventSGIX. + * + * \note + * This function dynamically determines whether to use the SGIX_pbuffer + * version of the protocol or the GLX 1.3 version of the protocol. + * + * \todo + * This function needs to be modified to work with direct-rendering drivers. + */ +static void +ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable, + const CARD32 * attribs, size_t num_attribs) +{ + struct glx_display *priv = __glXInitialize(dpy); +#ifdef GLX_DIRECT_RENDERING + __GLXDRIdrawable *pdraw; +#endif + CARD32 *output; + CARD8 opcode; + int i; + + if ((dpy == NULL) || (drawable == 0)) { + return; + } + + opcode = __glXSetupForCommand(dpy); + if (!opcode) + return; + + LockDisplay(dpy); + + if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { + xGLXChangeDrawableAttributesReq *req; + + GetReqExtra(GLXChangeDrawableAttributes, 8 * num_attribs, req); + output = (CARD32 *) (req + 1); + + req->reqType = opcode; + req->glxCode = X_GLXChangeDrawableAttributes; + req->drawable = drawable; + req->numAttribs = (CARD32) num_attribs; + } + else { + xGLXVendorPrivateWithReplyReq *vpreq; + + GetReqExtra(GLXVendorPrivateWithReply, 8 + (8 * num_attribs), vpreq); + output = (CARD32 *) (vpreq + 1); + + vpreq->reqType = opcode; + vpreq->glxCode = X_GLXVendorPrivateWithReply; + vpreq->vendorCode = X_GLXvop_ChangeDrawableAttributesSGIX; + + output[0] = (CARD32) drawable; + output[1] = num_attribs; + output += 2; + } + + (void) memcpy(output, attribs, sizeof(CARD32) * 2 * num_attribs); + + UnlockDisplay(dpy); + SyncHandle(); + +#ifdef GLX_DIRECT_RENDERING + pdraw = GetGLXDRIDrawable(dpy, drawable); + + for (i = 0; i < num_attribs; i++) { + switch(attribs[i * 2]) { + case GLX_EVENT_MASK: + /* Keep a local copy for masking out DRI2 proto events as needed */ + pdraw->eventMask = attribs[i * 2 + 1]; + break; + } + } +#endif + + return; +} + + +#ifdef GLX_DIRECT_RENDERING +static GLenum +determineTextureTarget(const int *attribs, int numAttribs) +{ + GLenum target = 0; + int i; + + for (i = 0; i < numAttribs; i++) { + if (attribs[2 * i] == GLX_TEXTURE_TARGET_EXT) { + switch (attribs[2 * i + 1]) { + case GLX_TEXTURE_2D_EXT: + target = GL_TEXTURE_2D; + break; + case GLX_TEXTURE_RECTANGLE_EXT: + target = GL_TEXTURE_RECTANGLE_ARB; + break; + } + } + } + + return target; +} + +static GLenum +determineTextureFormat(const int *attribs, int numAttribs) +{ + int i; + + for (i = 0; i < numAttribs; i++) { + if (attribs[2 * i] == GLX_TEXTURE_FORMAT_EXT) + return attribs[2 * i + 1]; + } + + return 0; +} + +static void +CreateDRIDrawable(Display *dpy, struct glx_config *config, + XID drawable, XID glxdrawable, + const int *attrib_list, size_t num_attribs) +{ + struct glx_display *const priv = __glXInitialize(dpy); + __GLXDRIdrawable *pdraw; + struct glx_screen *psc; + + psc = priv->screens[config->screen]; + if (psc->driScreen == NULL) + return; + + pdraw = psc->driScreen->createDrawable(psc, drawable, + glxdrawable, config); + if (pdraw == NULL) { + fprintf(stderr, "failed to create drawable\n"); + return; + } + + if (__glxHashInsert(priv->drawHash, glxdrawable, pdraw)) { + (*pdraw->destroyDrawable) (pdraw); + return; /* FIXME: Check what we're supposed to do here... */ + } + + pdraw->textureTarget = determineTextureTarget(attrib_list, num_attribs); + pdraw->textureFormat = determineTextureFormat(attrib_list, num_attribs); +} + +static void +DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable) +{ + struct glx_display *const priv = __glXInitialize(dpy); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable); + XID xid; + + if (pdraw != NULL) { + xid = pdraw->xDrawable; + (*pdraw->destroyDrawable) (pdraw); + __glxHashDelete(priv->drawHash, drawable); + if (destroy_xdrawable) + XFreePixmap(priv->dpy, xid); + } +} + +#else + +static void +CreateDRIDrawable(Display *dpy, const struct glx_config * fbconfig, + XID drawable, XID glxdrawable, + const int *attrib_list, size_t num_attribs) +{ +} + +static void +DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable) +{ +} + +#endif + +/** + * Get a drawable's attribute. + * + * This function is used to implement \c glXGetSelectedEvent and + * \c glXGetSelectedEventSGIX. + * + * \note + * This function dynamically determines whether to use the SGIX_pbuffer + * version of the protocol or the GLX 1.3 version of the protocol. + * + * \todo + * The number of attributes returned is likely to be small, probably less than + * 10. Given that, this routine should try to use an array on the stack to + * capture the reply rather than always calling Xmalloc. + * + * \todo + * This function needs to be modified to work with direct-rendering drivers. + */ +static int +GetDrawableAttribute(Display * dpy, GLXDrawable drawable, + int attribute, unsigned int *value) +{ + struct glx_display *priv; + xGLXGetDrawableAttributesReply reply; + CARD32 *data; + CARD8 opcode; + unsigned int length; + unsigned int i; + unsigned int num_attributes; + GLboolean use_glx_1_3; + + if ((dpy == NULL) || (drawable == 0)) { + return 0; + } + + priv = __glXInitialize(dpy); + use_glx_1_3 = ((priv->majorVersion > 1) || (priv->minorVersion >= 3)); + + *value = 0; + + + opcode = __glXSetupForCommand(dpy); + if (!opcode) + return 0; + + LockDisplay(dpy); + + if (use_glx_1_3) { + xGLXGetDrawableAttributesReq *req; + + GetReq(GLXGetDrawableAttributes, req); + req->reqType = opcode; + req->glxCode = X_GLXGetDrawableAttributes; + req->drawable = drawable; + } + else { + xGLXVendorPrivateWithReplyReq *vpreq; + + GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq); + data = (CARD32 *) (vpreq + 1); + data[0] = (CARD32) drawable; + + vpreq->reqType = opcode; + vpreq->glxCode = X_GLXVendorPrivateWithReply; + vpreq->vendorCode = X_GLXvop_GetDrawableAttributesSGIX; + } + + _XReply(dpy, (xReply *) & reply, 0, False); + + if (reply.type == X_Error) { + UnlockDisplay(dpy); + SyncHandle(); + return 0; + } + + length = reply.length; + if (length) { + num_attributes = (use_glx_1_3) ? reply.numAttribs : length / 2; + data = (CARD32 *) Xmalloc(length * sizeof(CARD32)); + if (data == NULL) { + /* Throw data on the floor */ + _XEatData(dpy, length); + } + else { + _XRead(dpy, (char *) data, length * sizeof(CARD32)); + + /* Search the set of returned attributes for the attribute requested by + * the caller. + */ + for (i = 0; i < num_attributes; i++) { + if (data[i * 2] == attribute) { + *value = data[(i * 2) + 1]; + break; + } + } + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + { + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable); + + if (pdraw != NULL && !pdraw->textureTarget) + pdraw->textureTarget = + determineTextureTarget((const int *) data, num_attributes); + if (pdraw != NULL && !pdraw->textureFormat) + pdraw->textureFormat = + determineTextureFormat((const int *) data, num_attributes); + } +#endif + + Xfree(data); + } + } + + UnlockDisplay(dpy); + SyncHandle(); + + return 0; +} + +/** + * Create a non-pbuffer GLX drawable. + * + * \todo + * This function needs to be modified to work with direct-rendering drivers. + */ +static GLXDrawable +CreateDrawable(Display *dpy, struct glx_config *config, + Drawable drawable, const int *attrib_list, CARD8 glxCode) +{ + xGLXCreateWindowReq *req; + CARD32 *data; + unsigned int i; + CARD8 opcode; + + i = 0; + if (attrib_list) { + while (attrib_list[i * 2] != None) + i++; + } + + opcode = __glXSetupForCommand(dpy); + if (!opcode) + return None; + + LockDisplay(dpy); + GetReqExtra(GLXCreateWindow, 8 * i, req); + data = (CARD32 *) (req + 1); + + req->reqType = opcode; + req->glxCode = glxCode; + req->screen = config->screen; + req->fbconfig = config->fbconfigID; + req->window = drawable; + req->glxwindow = XAllocID(dpy); + req->numAttribs = i; + + if (attrib_list) + memcpy(data, attrib_list, 8 * i); + + UnlockDisplay(dpy); + SyncHandle(); + + CreateDRIDrawable(dpy, config, drawable, req->glxwindow, attrib_list, i); + + return req->glxwindow; +} + + +/** + * Destroy a non-pbuffer GLX drawable. + */ +static void +DestroyDrawable(Display * dpy, GLXDrawable drawable, CARD32 glxCode) +{ + xGLXDestroyPbufferReq *req; + CARD8 opcode; + + if ((dpy == NULL) || (drawable == 0)) { + return; + } + + + opcode = __glXSetupForCommand(dpy); + if (!opcode) + return; + + LockDisplay(dpy); + + GetReq(GLXDestroyPbuffer, req); + req->reqType = opcode; + req->glxCode = glxCode; + req->pbuffer = (GLXPbuffer) drawable; + + UnlockDisplay(dpy); + SyncHandle(); + + DestroyDRIDrawable(dpy, drawable, GL_FALSE); + + return; +} + + +/** + * Create a pbuffer. + * + * This function is used to implement \c glXCreatePbuffer and + * \c glXCreateGLXPbufferSGIX. + * + * \note + * This function dynamically determines whether to use the SGIX_pbuffer + * version of the protocol or the GLX 1.3 version of the protocol. + * + * \todo + * This function needs to be modified to work with direct-rendering drivers. + */ +static GLXDrawable +CreatePbuffer(Display * dpy, struct glx_config *config, + unsigned int width, unsigned int height, + const int *attrib_list, GLboolean size_in_attribs) +{ + struct glx_display *priv = __glXInitialize(dpy); + GLXDrawable id = 0; + CARD32 *data; + CARD8 opcode; + unsigned int i; + Pixmap pixmap; + + i = 0; + if (attrib_list) { + while (attrib_list[i * 2]) + i++; + } + + opcode = __glXSetupForCommand(dpy); + if (!opcode) + return None; + + LockDisplay(dpy); + id = XAllocID(dpy); + + if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { + xGLXCreatePbufferReq *req; + unsigned int extra = (size_in_attribs) ? 0 : 2; + + GetReqExtra(GLXCreatePbuffer, (8 * (i + extra)), req); + data = (CARD32 *) (req + 1); + + req->reqType = opcode; + req->glxCode = X_GLXCreatePbuffer; + req->screen = config->screen; + req->fbconfig = config->fbconfigID; + req->pbuffer = id; + req->numAttribs = i + extra; + + if (!size_in_attribs) { + data[(2 * i) + 0] = GLX_PBUFFER_WIDTH; + data[(2 * i) + 1] = width; + data[(2 * i) + 2] = GLX_PBUFFER_HEIGHT; + data[(2 * i) + 3] = height; + data += 4; + } + } + else { + xGLXVendorPrivateReq *vpreq; + + GetReqExtra(GLXVendorPrivate, 20 + (8 * i), vpreq); + data = (CARD32 *) (vpreq + 1); + + vpreq->reqType = opcode; + vpreq->glxCode = X_GLXVendorPrivate; + vpreq->vendorCode = X_GLXvop_CreateGLXPbufferSGIX; + + data[0] = config->screen; + data[1] = config->fbconfigID; + data[2] = id; + data[3] = width; + data[4] = height; + data += 5; + } + + (void) memcpy(data, attrib_list, sizeof(CARD32) * 2 * i); + + UnlockDisplay(dpy); + SyncHandle(); + + pixmap = XCreatePixmap(dpy, RootWindow(dpy, config->screen), + width, height, config->rgbBits); + + CreateDRIDrawable(dpy, config, pixmap, id, attrib_list, i); + + return id; +} + +/** + * Destroy a pbuffer. + * + * This function is used to implement \c glXDestroyPbuffer and + * \c glXDestroyGLXPbufferSGIX. + * + * \note + * This function dynamically determines whether to use the SGIX_pbuffer + * version of the protocol or the GLX 1.3 version of the protocol. + */ +static void +DestroyPbuffer(Display * dpy, GLXDrawable drawable) +{ + struct glx_display *priv = __glXInitialize(dpy); + CARD8 opcode; + + if ((dpy == NULL) || (drawable == 0)) { + return; + } + + opcode = __glXSetupForCommand(dpy); + if (!opcode) + return; + + LockDisplay(dpy); + + if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { + xGLXDestroyPbufferReq *req; + + GetReq(GLXDestroyPbuffer, req); + req->reqType = opcode; + req->glxCode = X_GLXDestroyPbuffer; + req->pbuffer = (GLXPbuffer) drawable; + } + else { + xGLXVendorPrivateWithReplyReq *vpreq; + CARD32 *data; + + GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq); + data = (CARD32 *) (vpreq + 1); + + data[0] = (CARD32) drawable; + + vpreq->reqType = opcode; + vpreq->glxCode = X_GLXVendorPrivateWithReply; + vpreq->vendorCode = X_GLXvop_DestroyGLXPbufferSGIX; + } + + UnlockDisplay(dpy); + SyncHandle(); + + DestroyDRIDrawable(dpy, drawable, GL_TRUE); + + return; +} + +/** + * Create a new pbuffer. + */ +_X_EXPORT GLXPbufferSGIX +glXCreateGLXPbufferSGIX(Display * dpy, GLXFBConfigSGIX config, + unsigned int width, unsigned int height, + int *attrib_list) +{ + return (GLXPbufferSGIX) CreatePbuffer(dpy, (struct glx_config *) config, + width, height, + attrib_list, GL_FALSE); +} + +#endif /* GLX_USE_APPLEGL */ + +/** + * Create a new pbuffer. + */ +_X_EXPORT GLXPbuffer +glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int *attrib_list) +{ + int i, width, height; +#ifdef GLX_USE_APPLEGL + GLXPbuffer result; + int errorcode; +#endif + + width = 0; + height = 0; + + WARN_ONCE_GLX_1_3(dpy, __func__); + +#ifdef GLX_USE_APPLEGL + for (i = 0; attrib_list[i]; ++i) { + switch (attrib_list[i]) { + case GLX_PBUFFER_WIDTH: + width = attrib_list[i + 1]; + ++i; + break; + + case GLX_PBUFFER_HEIGHT: + height = attrib_list[i + 1]; + ++i; + break; + + case GLX_LARGEST_PBUFFER: + /* This is a hint we should probably handle, but how? */ + ++i; + break; + + case GLX_PRESERVED_CONTENTS: + /* The contents are always preserved with AppleSGLX with CGL. */ + ++i; + break; + + default: + return None; + } + } + + if (apple_glx_pbuffer_create(dpy, config, width, height, &errorcode, + &result)) { + /* + * apple_glx_pbuffer_create only sets the errorcode to core X11 + * errors. + */ + __glXSendError(dpy, errorcode, 0, X_GLXCreatePbuffer, true); + + return None; + } + + return result; +#else + for (i = 0; attrib_list[i * 2]; i++) { + switch (attrib_list[i * 2]) { + case GLX_PBUFFER_WIDTH: + width = attrib_list[i * 2 + 1]; + break; + case GLX_PBUFFER_HEIGHT: + height = attrib_list[i * 2 + 1]; + break; + } + } + + return (GLXPbuffer) CreatePbuffer(dpy, (struct glx_config *) config, + width, height, attrib_list, GL_TRUE); +#endif +} + + +/** + * Destroy an existing pbuffer. + */ +_X_EXPORT void +glXDestroyPbuffer(Display * dpy, GLXPbuffer pbuf) +{ +#ifdef GLX_USE_APPLEGL + if (apple_glx_pbuffer_destroy(dpy, pbuf)) { + __glXSendError(dpy, GLXBadPbuffer, pbuf, X_GLXDestroyPbuffer, false); + } +#else + DestroyPbuffer(dpy, pbuf); +#endif +} + + +/** + * Query an attribute of a drawable. + */ +_X_EXPORT void +glXQueryDrawable(Display * dpy, GLXDrawable drawable, + int attribute, unsigned int *value) +{ + WARN_ONCE_GLX_1_3(dpy, __func__); +#ifdef GLX_USE_APPLEGL + Window root; + int x, y; + unsigned int width, height, bd, depth; + + if (apple_glx_pixmap_query(drawable, attribute, value)) + return; /*done */ + + if (apple_glx_pbuffer_query(drawable, attribute, value)) + return; /*done */ + + /* + * The OpenGL spec states that we should report GLXBadDrawable if + * the drawable is invalid, however doing so would require that we + * use XSetErrorHandler(), which is known to not be thread safe. + * If we use a round-trip call to validate the drawable, there could + * be a race, so instead we just opt in favor of letting the + * XGetGeometry request fail with a GetGeometry request X error + * rather than GLXBadDrawable, in what is hoped to be a rare + * case of an invalid drawable. In practice most and possibly all + * X11 apps using GLX shouldn't notice a difference. + */ + if (XGetGeometry + (dpy, drawable, &root, &x, &y, &width, &height, &bd, &depth)) { + switch (attribute) { + case GLX_WIDTH: + *value = width; + break; + + case GLX_HEIGHT: + *value = height; + break; + } + } +#else + GetDrawableAttribute(dpy, drawable, attribute, value); +#endif +} + + +#ifndef GLX_USE_APPLEGL +/** + * Query an attribute of a pbuffer. + */ +_X_EXPORT int +glXQueryGLXPbufferSGIX(Display * dpy, GLXPbufferSGIX drawable, + int attribute, unsigned int *value) +{ + return GetDrawableAttribute(dpy, drawable, attribute, value); +} +#endif + +/** + * Select the event mask for a drawable. + */ +_X_EXPORT void +glXSelectEvent(Display * dpy, GLXDrawable drawable, unsigned long mask) +{ +#ifdef GLX_USE_APPLEGL + XWindowAttributes xwattr; + + if (apple_glx_pbuffer_set_event_mask(drawable, mask)) + return; /*done */ + + /* + * The spec allows a window, but currently there are no valid + * events for a window, so do nothing. + */ + if (XGetWindowAttributes(dpy, drawable, &xwattr)) + return; /*done */ + /* The drawable seems to be invalid. Report an error. */ + + __glXSendError(dpy, GLXBadDrawable, drawable, + X_GLXChangeDrawableAttributes, false); +#else + CARD32 attribs[2]; + + attribs[0] = (CARD32) GLX_EVENT_MASK; + attribs[1] = (CARD32) mask; + + ChangeDrawableAttribute(dpy, drawable, attribs, 1); +#endif +} + + +/** + * Get the selected event mask for a drawable. + */ +_X_EXPORT void +glXGetSelectedEvent(Display * dpy, GLXDrawable drawable, unsigned long *mask) +{ +#ifdef GLX_USE_APPLEGL + XWindowAttributes xwattr; + + if (apple_glx_pbuffer_get_event_mask(drawable, mask)) + return; /*done */ + + /* + * The spec allows a window, but currently there are no valid + * events for a window, so do nothing, but set the mask to 0. + */ + if (XGetWindowAttributes(dpy, drawable, &xwattr)) { + /* The window is valid, so set the mask to 0. */ + *mask = 0; + return; /*done */ + } + /* The drawable seems to be invalid. Report an error. */ + + __glXSendError(dpy, GLXBadDrawable, drawable, X_GLXGetDrawableAttributes, + true); +#else + unsigned int value; + + + /* The non-sense with value is required because on LP64 platforms + * sizeof(unsigned int) != sizeof(unsigned long). On little-endian + * we could just type-cast the pointer, but why? + */ + + GetDrawableAttribute(dpy, drawable, GLX_EVENT_MASK_SGIX, &value); + *mask = value; +#endif +} + + +_X_EXPORT GLXPixmap +glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap, + const int *attrib_list) +{ + WARN_ONCE_GLX_1_3(dpy, __func__); + +#ifdef GLX_USE_APPLEGL + const struct glx_config *modes = (const __GLcontextModes *) config; + + if (apple_glx_pixmap_create(dpy, modes->screen, pixmap, modes)) + return None; + + return pixmap; +#else + return CreateDrawable(dpy, (struct glx_config *) config, + (Drawable) pixmap, attrib_list, X_GLXCreatePixmap); +#endif +} + + +_X_EXPORT GLXWindow +glXCreateWindow(Display * dpy, GLXFBConfig config, Window win, + const int *attrib_list) +{ + WARN_ONCE_GLX_1_3(dpy, __func__); +#ifdef GLX_USE_APPLEGL + XWindowAttributes xwattr; + XVisualInfo *visinfo; + + (void) attrib_list; /*unused according to GLX 1.4 */ + + XGetWindowAttributes(dpy, win, &xwattr); + + visinfo = glXGetVisualFromFBConfig(dpy, config); + + if (NULL == visinfo) { + __glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateWindow, false); + return None; + } + + if (visinfo->visualid != XVisualIDFromVisual(xwattr.visual)) { + __glXSendError(dpy, BadMatch, 0, X_GLXCreateWindow, true); + return None; + } + + XFree(visinfo); + + return win; +#else + return CreateDrawable(dpy, (struct glx_config *) config, + (Drawable) win, attrib_list, X_GLXCreateWindow); +#endif +} + + +_X_EXPORT void +glXDestroyPixmap(Display * dpy, GLXPixmap pixmap) +{ + WARN_ONCE_GLX_1_3(dpy, __func__); +#ifdef GLX_USE_APPLEGL + if (apple_glx_pixmap_destroy(dpy, pixmap)) + __glXSendError(dpy, GLXBadPixmap, pixmap, X_GLXDestroyPixmap, false); +#else + DestroyDrawable(dpy, (GLXDrawable) pixmap, X_GLXDestroyPixmap); +#endif +} + + +_X_EXPORT void +glXDestroyWindow(Display * dpy, GLXWindow win) +{ + WARN_ONCE_GLX_1_3(dpy, __func__); +#ifndef GLX_USE_APPLEGL + DestroyDrawable(dpy, (GLXDrawable) win, X_GLXDestroyWindow); +#endif +} + +#ifndef GLX_USE_APPLEGL +_X_EXPORT +GLX_ALIAS_VOID(glXDestroyGLXPbufferSGIX, + (Display * dpy, GLXPbufferSGIX pbuf), + (dpy, pbuf), glXDestroyPbuffer) + +_X_EXPORT +GLX_ALIAS_VOID(glXSelectEventSGIX, + (Display * dpy, GLXDrawable drawable, + unsigned long mask), (dpy, drawable, mask), glXSelectEvent) + +_X_EXPORT +GLX_ALIAS_VOID(glXGetSelectedEventSGIX, + (Display * dpy, GLXDrawable drawable, + unsigned long *mask), (dpy, drawable, mask), + glXGetSelectedEvent) +#endif diff --git a/src/glx/glx_query.c b/src/glx/glx_query.c new file mode 100644 index 0000000..efad13d --- /dev/null +++ b/src/glx/glx_query.c @@ -0,0 +1,177 @@ +/* + * (C) Copyright IBM Corporation 2004 + * 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 + * 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 + * IBM 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. + */ + +/** + * \file glx_query.c + * Generic utility functions to query internal data from the server. + * + * \author Ian Romanick + */ + +#include "glxclient.h" + +#if defined(USE_XCB) +# include +# include +# include +#endif + +#ifdef USE_XCB + +/** + * Exchange a protocol request for glXQueryServerString. + */ +char * +__glXQueryServerString(Display * dpy, int opcode, CARD32 screen, CARD32 name) +{ + xcb_connection_t *c = XGetXCBConnection(dpy); + xcb_glx_query_server_string_reply_t *reply = + xcb_glx_query_server_string_reply(c, + xcb_glx_query_server_string(c, + screen, + name), + NULL); + + /* The spec doesn't mention this, but the Xorg server replies with + * a string already terminated with '\0'. */ + uint32_t len = xcb_glx_query_server_string_string_length(reply); + char *buf = Xmalloc(len); + memcpy(buf, xcb_glx_query_server_string_string(reply), len); + free(reply); + + return buf; +} + +/** + * Exchange a protocol request for glGetString. + */ +char * +__glXGetString(Display * dpy, int opcode, CARD32 contextTag, CARD32 name) +{ + xcb_connection_t *c = XGetXCBConnection(dpy); + xcb_glx_get_string_reply_t *reply = xcb_glx_get_string_reply(c, + xcb_glx_get_string + (c, + contextTag, + name), + NULL); + + /* The spec doesn't mention this, but the Xorg server replies with + * a string already terminated with '\0'. */ + uint32_t len = xcb_glx_get_string_string_length(reply); + char *buf = Xmalloc(len); + memcpy(buf, xcb_glx_get_string_string(reply), len); + free(reply); + + return buf; +} + +#else + +/** + * GLX protocol structure for the ficticious "GXLGenericGetString" request. + * + * This is a non-existant protocol packet. It just so happens that all of + * the real protocol packets used to request a string from the server have + * an identical binary layout. The only difference between them is the + * meaning of the \c for_whom field and the value of the \c glxCode. + */ +typedef struct GLXGenericGetString +{ + CARD8 reqType; + CARD8 glxCode; + CARD16 length B16; + CARD32 for_whom B32; + CARD32 name B32; +} xGLXGenericGetStringReq; + +/* These defines are only needed to make the GetReq macro happy. + */ +#define sz_xGLXGenericGetStringReq 12 +#define X_GLXGenericGetString 0 + +/** + * Query the Server GLX string. + * This routine will allocate the necessay space for the string. + */ +static char * +__glXGetStringFromServer(Display * dpy, int opcode, CARD32 glxCode, + CARD32 for_whom, CARD32 name) +{ + xGLXGenericGetStringReq *req; + xGLXSingleReply reply; + int length; + int numbytes; + char *buf; + + + LockDisplay(dpy); + + + /* All of the GLX protocol requests for getting a string from the server + * look the same. The exact meaning of the for_whom field is usually + * either the screen number (for glXQueryServerString) or the context tag + * (for GLXSingle). + */ + + GetReq(GLXGenericGetString, req); + req->reqType = opcode; + req->glxCode = glxCode; + req->for_whom = for_whom; + req->name = name; + + _XReply(dpy, (xReply *) & reply, 0, False); + + length = reply.length * 4; + numbytes = reply.size; + + buf = (char *) Xmalloc(numbytes); + if (buf != NULL) { + _XRead(dpy, buf, numbytes); + length -= numbytes; + } + + _XEatData(dpy, length); + + UnlockDisplay(dpy); + SyncHandle(); + + return buf; +} + +char * +__glXQueryServerString(Display * dpy, int opcode, CARD32 screen, CARD32 name) +{ + return __glXGetStringFromServer(dpy, opcode, + X_GLXQueryServerString, screen, name); +} + +char * +__glXGetString(Display * dpy, int opcode, CARD32 contextTag, CARD32 name) +{ + return __glXGetStringFromServer(dpy, opcode, X_GLsop_GetString, + contextTag, name); +} + +#endif /* USE_XCB */ diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h new file mode 100644 index 0000000..36a0808 --- /dev/null +++ b/src/glx/glxclient.h @@ -0,0 +1,785 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/** + * \file glxclient.h + * Direct rendering support added by Precision Insight, Inc. + * + * \author Kevin E. Martin + */ + +#ifndef _GLX_client_h_ +#define _GLX_client_h_ +#include +#include +#include +#include +#define GLX_GLXEXT_PROTOTYPES +#include +#include +#include +#include +#include +#ifdef WIN32 +#include +#endif +#include "GL/glxproto.h" +#include "glapi/glapitable.h" +#include "glxconfig.h" +#include "glxhash.h" +#if defined( PTHREADS ) +# include +#endif + +#include "glxextensions.h" + +#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) + +#define GLX_MAJOR_VERSION 1 /* current version numbers */ +#define GLX_MINOR_VERSION 4 + +#define __GLX_MAX_TEXTURE_UNITS 32 + +struct glx_display; +struct glx_context; + +/************************************************************************/ + +#ifdef GLX_DIRECT_RENDERING + +extern void DRI_glXUseXFont(struct glx_context *ctx, + Font font, int first, int count, int listbase); + +#endif + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + +/** + * Display dependent methods. This structure is initialized during the + * \c driCreateDisplay call. + */ +typedef struct __GLXDRIdisplayRec __GLXDRIdisplay; +typedef struct __GLXDRIscreenRec __GLXDRIscreen; +typedef struct __GLXDRIdrawableRec __GLXDRIdrawable; + +struct __GLXDRIdisplayRec +{ + /** + * Method to destroy the private DRI display data. + */ + void (*destroyDisplay) (__GLXDRIdisplay * display); + + struct glx_screen *(*createScreen)(int screen, struct glx_display * priv); +}; + +struct __GLXDRIscreenRec { + + void (*destroyScreen)(struct glx_screen *psc); + + struct glx_context *(*createContext)(struct glx_screen *psc, + struct glx_config *config, + struct glx_context *shareList, + int renderType); + + __GLXDRIdrawable *(*createDrawable)(struct glx_screen *psc, + XID drawable, + GLXDrawable glxDrawable, + struct glx_config *config); + + int64_t (*swapBuffers)(__GLXDRIdrawable *pdraw, int64_t target_msc, + int64_t divisor, int64_t remainder); + void (*copySubBuffer)(__GLXDRIdrawable *pdraw, + int x, int y, int width, int height); + int (*getDrawableMSC)(struct glx_screen *psc, __GLXDRIdrawable *pdraw, + int64_t *ust, int64_t *msc, int64_t *sbc); + int (*waitForMSC)(__GLXDRIdrawable *pdraw, int64_t target_msc, + int64_t divisor, int64_t remainder, int64_t *ust, + int64_t *msc, int64_t *sbc); + int (*waitForSBC)(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust, + int64_t *msc, int64_t *sbc); + int (*setSwapInterval)(__GLXDRIdrawable *pdraw, int interval); + int (*getSwapInterval)(__GLXDRIdrawable *pdraw); +}; + +struct __GLXDRIdrawableRec +{ + void (*destroyDrawable) (__GLXDRIdrawable * drawable); + + XID xDrawable; + XID drawable; + struct glx_screen *psc; + GLenum textureTarget; + GLenum textureFormat; /* EXT_texture_from_pixmap support */ + unsigned long eventMask; +}; + +/* +** Function to create and DRI display data and initialize the display +** dependent methods. +*/ +extern __GLXDRIdisplay *driswCreateDisplay(Display * dpy); +extern __GLXDRIdisplay *driCreateDisplay(Display * dpy); +extern __GLXDRIdisplay *dri2CreateDisplay(Display * dpy); +extern void dri2InvalidateBuffers(Display *dpy, XID drawable); +extern unsigned dri2GetSwapEventType(Display *dpy, XID drawable); + + +/* +** Functions to obtain driver configuration information from a direct +** rendering client application +*/ +extern const char *glXGetScreenDriver(Display * dpy, int scrNum); + +extern const char *glXGetDriverConfig(const char *driverName); + +#endif + +/************************************************************************/ + +#define __GL_CLIENT_ATTRIB_STACK_DEPTH 16 + +typedef struct __GLXpixelStoreModeRec +{ + GLboolean swapEndian; + GLboolean lsbFirst; + GLuint rowLength; + GLuint imageHeight; + GLuint imageDepth; + GLuint skipRows; + GLuint skipPixels; + GLuint skipImages; + GLuint alignment; +} __GLXpixelStoreMode; + + +typedef struct __GLXattributeRec +{ + GLuint mask; + + /** + * Pixel storage state. Most of the pixel store mode state is kept + * here and used by the client code to manage the packing and + * unpacking of data sent to/received from the server. + */ + __GLXpixelStoreMode storePack, storeUnpack; + + /** + * Is EXT_vertex_array / GL 1.1 DrawArrays protocol specifically + * disabled? + */ + GLboolean NoDrawArraysProtocol; + + /** + * Vertex Array storage state. The vertex array component + * state is stored here and is used to manage the packing of + * DrawArrays data sent to the server. + */ + struct array_state_vector *array_state; +} __GLXattribute; + +typedef struct __GLXattributeMachineRec +{ + __GLXattribute *stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]; + __GLXattribute **stackPointer; +} __GLXattributeMachine; + +struct glx_context_vtable { + void (*destroy)(struct glx_context *ctx); + int (*bind)(struct glx_context *context, struct glx_context *old, + GLXDrawable draw, GLXDrawable read); + void (*unbind)(struct glx_context *context, struct glx_context *new); + void (*wait_gl)(struct glx_context *ctx); + void (*wait_x)(struct glx_context *ctx); + void (*use_x_font)(struct glx_context *ctx, + Font font, int first, int count, int listBase); + void (*bind_tex_image)(Display * dpy, + GLXDrawable drawable, + int buffer, const int *attrib_list); + void (*release_tex_image)(Display * dpy, GLXDrawable drawable, int buffer); + +}; + +extern void +glx_send_destroy_context(Display *dpy, XID xid); + +/** + * GLX state that needs to be kept on the client. One of these records + * exist for each context that has been made current by this client. + */ +struct glx_context +{ + /** + * \name Drawing command buffer. + * + * Drawing commands are packed into this buffer before being sent as a + * single GLX protocol request. The buffer is sent when it overflows or + * is flushed by \c __glXFlushRenderBuffer. \c pc is the next location + * in the buffer to be filled. \c limit is described above in the buffer + * slop discussion. + * + * Commands that require large amounts of data to be transfered will + * also use this buffer to hold a header that describes the large + * command. + * + * These must be the first 6 fields since they are static initialized + * in the dummy context in glxext.c + */ + /*@{ */ + GLubyte *buf; + GLubyte *pc; + GLubyte *limit; + GLubyte *bufEnd; + GLint bufSize; + /*@} */ + + const struct glx_context_vtable *vtable; + + /** + * The XID of this rendering context. When the context is created a + * new XID is allocated. This is set to None when the context is + * destroyed but is still current to some thread. In this case the + * context will be freed on next MakeCurrent. + */ + XID xid; + + /** + * The XID of the \c shareList context. + */ + XID share_xid; + + /** + * Screen number. + */ + GLint screen; + struct glx_screen *psc; + + /** + * \c GL_TRUE if the context was created with ImportContext, which + * means the server-side context was created by another X client. + */ + GLboolean imported; + + /** + * The context tag returned by MakeCurrent when this context is made + * current. This tag is used to identify the context that a thread has + * current so that proper server context management can be done. It is + * used for all context specific commands (i.e., \c Render, \c RenderLarge, + * \c WaitX, \c WaitGL, \c UseXFont, and \c MakeCurrent (for the old + * context)). + */ + GLXContextTag currentContextTag; + + /** + * \name Rendering mode + * + * The rendering mode is kept on the client as well as the server. + * When \c glRenderMode is called, the buffer associated with the + * previous rendering mode (feedback or select) is filled. + */ + /*@{ */ + GLenum renderMode; + GLfloat *feedbackBuf; + GLuint *selectBuf; + /*@} */ + + /** + * This is \c GL_TRUE if the pixel unpack modes are such that an image + * can be unpacked from the clients memory by just copying. It may + * still be true that the server will have to do some work. This + * just promises that a straight copy will fetch the correct bytes. + */ + GLboolean fastImageUnpack; + + /** + * Fill newImage with the unpacked form of \c oldImage getting it + * ready for transport to the server. + */ + void (*fillImage) (struct glx_context *, GLint, GLint, GLint, GLint, GLenum, + GLenum, const GLvoid *, GLubyte *, GLubyte *); + + /** + * Client side attribs. + */ + __GLXattributeMachine attributes; + + /** + * Client side error code. This is set when client side gl API + * routines need to set an error because of a bad enumerant or + * running out of memory, etc. + */ + GLenum error; + + /** + * Whether this context does direct rendering. + */ + Bool isDirect; + + /** + * \c dpy of current display for this context. Will be \c NULL if not + * current to any display, or if this is the "dummy context". + */ + Display *currentDpy; + + /** + * The current drawable for this context. Will be None if this + * context is not current to any drawable. currentReadable is below. + */ + GLXDrawable currentDrawable; + + /** + * \name GL Constant Strings + * + * Constant strings that describe the server implementation + * These pertain to GL attributes, not to be confused with + * GLX versioning attributes. + */ + /*@{ */ + GLubyte *vendor; + GLubyte *renderer; + GLubyte *version; + GLubyte *extensions; + /*@} */ + + /** + * Maximum small render command size. This is the smaller of 64k and + * the size of the above buffer. + */ + GLint maxSmallRenderCommandSize; + + /** + * Major opcode for the extension. Copied here so a lookup isn't + * needed. + */ + GLint majorOpcode; + + /** + * Pointer to the config used to create this context. + */ + struct glx_config *config; + + /** + * The current read-drawable for this context. Will be None if this + * context is not current to any drawable. + * + * \since Internal API version 20030606. + */ + GLXDrawable currentReadable; + + /** + * Pointer to client-state data that is private to libGL. This is only + * used for indirect rendering contexts. + * + * No internal API version change was made for this change. Client-side + * drivers should NEVER use this data or even care that it exists. + */ + void *client_state_private; + + /** + * Stored value for \c glXQueryContext attribute \c GLX_RENDER_TYPE. + */ + int renderType; + + /** + * \name Raw server GL version + * + * True core GL version supported by the server. This is the raw value + * returned by the server, and it may not reflect what is actually + * supported (or reported) by the client-side library. + */ + /*@{ */ + int server_major; /**< Major version number. */ + int server_minor; /**< Minor version number. */ + /*@} */ + + /** + * Thread ID we're currently current in. Zero if none. + */ + unsigned long thread_id; + + char gl_extension_bits[__GL_EXT_BYTES]; +}; + +extern Bool +glx_context_init(struct glx_context *gc, + struct glx_screen *psc, struct glx_config *fbconfig); + +#define __glXSetError(gc,code) \ + if (!(gc)->error) { \ + (gc)->error = code; \ + } + +extern void __glFreeAttributeState(struct glx_context *); + +/************************************************************************/ + +/** + * The size of the largest drawing command known to the implementation + * that will use the GLXRender GLX command. In this case it is + * \c glPolygonStipple. + */ +#define __GLX_MAX_SMALL_RENDER_CMD_SIZE 156 + +/** + * To keep the implementation fast, the code uses a "limit" pointer + * to determine when the drawing command buffer is too full to hold + * another fixed size command. This constant defines the amount of + * space that must always be available in the drawing command buffer + * at all times for the implementation to work. It is important that + * the number be just large enough, but not so large as to reduce the + * efficacy of the buffer. The "+32" is just to keep the code working + * in case somebody counts wrong. + */ +#define __GLX_BUFFER_LIMIT_SIZE (__GLX_MAX_SMALL_RENDER_CMD_SIZE + 32) + +/** + * This implementation uses a smaller threshold for switching + * to the RenderLarge protocol than the protcol requires so that + * large copies don't occur. + */ +#define __GLX_RENDER_CMD_SIZE_LIMIT 4096 + +/** + * One of these records exists per screen of the display. It contains + * a pointer to the config data for that screen (if the screen supports GL). + */ +struct glx_screen_vtable { + struct glx_context *(*create_context)(struct glx_screen *psc, + struct glx_config *config, + struct glx_context *shareList, + int renderType); +}; + +struct glx_screen +{ + const struct glx_screen_vtable *vtable; + + /** + * GLX extension string reported by the X-server. + */ + const char *serverGLXexts; + + /** + * GLX extension string to be reported to applications. This is the + * set of extensions that the application can actually use. + */ + char *effectiveGLXexts; + + struct glx_display *display; + + Display *dpy; + int scr; + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + /** + * Per screen direct rendering interface functions and data. + */ + __GLXDRIscreen *driScreen; +#endif + + /** + * Linked list of glx visuals and fbconfigs for this screen. + */ + struct glx_config *visuals, *configs; + + /** + * Per-screen dynamic GLX extension tracking. The \c direct_support + * field only contains enough bits for 64 extensions. Should libGL + * ever need to track more than 64 GLX extensions, we can safely grow + * this field. The \c struct glx_screen structure is not used outside + * libGL. + */ + /*@{ */ + unsigned char direct_support[8]; + GLboolean ext_list_first_time; + /*@} */ + +}; + +/** + * Per display private data. One of these records exists for each display + * that is using the OpenGL (GLX) extension. + */ +struct glx_display +{ + /* The extension protocol codes */ + XExtCodes *codes; + struct glx_display *next; + + /** + * Back pointer to the display + */ + Display *dpy; + + /** + * The \c majorOpcode is common to all connections to the same server. + * It is also copied into the context structure. + */ + int majorOpcode; + + /** + * \name Server Version + * + * Major and minor version returned by the server during initialization. + */ + /*@{ */ + int majorVersion, minorVersion; + /*@} */ + + /** + * \name Storage for the servers GLX vendor and versions strings. + * + * These are the same for all screens on this display. These fields will + * be filled in on demand. + */ + /*@{ */ + const char *serverGLXvendor; + const char *serverGLXversion; + /*@} */ + + /** + * Configurations of visuals for all screens on this display. + * Also, per screen data which now includes the server \c GLX_EXTENSION + * string. + */ + struct glx_screen **screens; + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + __glxHashTable *drawHash; + + /** + * Per display direct rendering interface functions and data. + */ + __GLXDRIdisplay *driswDisplay; + __GLXDRIdisplay *driDisplay; + __GLXDRIdisplay *dri2Display; +#endif +}; + +extern int +glx_screen_init(struct glx_screen *psc, + int screen, struct glx_display * priv); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +extern __GLXDRIdrawable * +dri2GetGlxDrawableFromXDrawableId(Display *dpy, XID id); +#endif + +extern GLubyte *__glXFlushRenderBuffer(struct glx_context *, GLubyte *); + +extern void __glXSendLargeChunk(struct glx_context * gc, GLint requestNumber, + GLint totalRequests, + const GLvoid * data, GLint dataLen); + +extern void __glXSendLargeCommand(struct glx_context *, const GLvoid *, GLint, + const GLvoid *, GLint); + +/* Initialize the GLX extension for dpy */ +extern struct glx_display *__glXInitialize(Display *); + +extern void __glXPreferEGL(int state); + +/************************************************************************/ + +extern int __glXDebug; + +/* This is per-thread storage in an MT environment */ +#if defined( PTHREADS ) + +extern void __glXSetCurrentContext(struct glx_context * c); + +# if defined( GLX_USE_TLS ) + +extern __thread void *__glX_tls_Context + __attribute__ ((tls_model("initial-exec"))); + +# define __glXGetCurrentContext() __glX_tls_Context + +# else + +extern struct glx_context *__glXGetCurrentContext(void); + +# endif /* defined( GLX_USE_TLS ) */ + +#else + +extern struct glx_context *__glXcurrentContext; +#define __glXGetCurrentContext() __glXcurrentContext +#define __glXSetCurrentContext(gc) __glXcurrentContext = gc + +#endif /* defined( PTHREADS ) */ + +extern void __glXSetCurrentContextNull(void); + + +/* +** Global lock for all threads in this address space using the GLX +** extension +*/ +#if defined( PTHREADS ) +extern pthread_mutex_t __glXmutex; +#define __glXLock() pthread_mutex_lock(&__glXmutex) +#define __glXUnlock() pthread_mutex_unlock(&__glXmutex) +#else +#define __glXLock() +#define __glXUnlock() +#endif + +/* +** Setup for a command. Initialize the extension for dpy if necessary. +*/ +extern CARD8 __glXSetupForCommand(Display * dpy); + +/************************************************************************/ + +/* +** Data conversion and packing support. +*/ + +extern const GLuint __glXDefaultPixelStore[9]; + +/* Send an image to the server using RenderLarge. */ +extern void __glXSendLargeImage(struct glx_context * gc, GLint compsize, GLint dim, + GLint width, GLint height, GLint depth, + GLenum format, GLenum type, + const GLvoid * src, GLubyte * pc, + GLubyte * modes); + +/* Return the size, in bytes, of some pixel data */ +extern GLint __glImageSize(GLint, GLint, GLint, GLenum, GLenum, GLenum); + +/* Return the number of elements per group of a specified format*/ +extern GLint __glElementsPerGroup(GLenum format, GLenum type); + +/* Return the number of bytes per element, based on the element type (other +** than GL_BITMAP). +*/ +extern GLint __glBytesPerElement(GLenum type); + +/* +** Fill the transport buffer with the data from the users buffer, +** applying some of the pixel store modes (unpack modes) to the data +** first. As a side effect of this call, the "modes" field is +** updated to contain the modes needed by the server to decode the +** sent data. +*/ +extern void __glFillImage(struct glx_context *, GLint, GLint, GLint, GLint, GLenum, + GLenum, const GLvoid *, GLubyte *, GLubyte *); + +/* Copy map data with a stride into a packed buffer */ +extern void __glFillMap1f(GLint, GLint, GLint, const GLfloat *, GLubyte *); +extern void __glFillMap1d(GLint, GLint, GLint, const GLdouble *, GLubyte *); +extern void __glFillMap2f(GLint, GLint, GLint, GLint, GLint, + const GLfloat *, GLfloat *); +extern void __glFillMap2d(GLint, GLint, GLint, GLint, GLint, + const GLdouble *, GLdouble *); + +/* +** Empty an image out of the reply buffer into the clients memory applying +** the pack modes to pack back into the clients requested format. +*/ +extern void __glEmptyImage(struct glx_context *, GLint, GLint, GLint, GLint, GLenum, + GLenum, const GLubyte *, GLvoid *); + + +/* +** Allocate and Initialize Vertex Array client state, and free. +*/ +extern void __glXInitVertexArrayState(struct glx_context *); +extern void __glXFreeVertexArrayState(struct glx_context *); + +/* +** Inform the Server of the major and minor numbers and of the client +** libraries extension string. +*/ +extern void __glXClientInfo(Display * dpy, int opcode); + +/************************************************************************/ + +/* +** Declarations that should be in Xlib +*/ +#ifdef __GL_USE_OUR_PROTOTYPES +extern void _XFlush(Display *); +extern Status _XReply(Display *, xReply *, int, Bool); +extern void _XRead(Display *, void *, long); +extern void _XSend(Display *, const void *, long); +#endif + + +extern void __glXInitializeVisualConfigFromTags(struct glx_config * config, + int count, const INT32 * bp, + Bool tagged_only, + Bool fbconfig_style_tags); + +extern char *__glXQueryServerString(Display * dpy, int opcode, + CARD32 screen, CARD32 name); +extern char *__glXGetString(Display * dpy, int opcode, + CARD32 screen, CARD32 name); + +extern char *__glXstrdup(const char *str); + + +extern const char __glXGLClientVersion[]; +extern const char __glXGLClientExtensions[]; + +/* Get the unadjusted system time */ +extern int __glXGetUST(int64_t * ust); + +extern GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable, + int32_t * numerator, + int32_t * denominator); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +extern GLboolean +__glxGetMscRate(__GLXDRIdrawable *glxDraw, + int32_t * numerator, int32_t * denominator); + +/* So that dri2.c:DRI2WireToEvent() can access + * glx_info->codes->first_event */ +XExtDisplayInfo *__glXFindDisplay (Display *dpy); + +extern void +GarbageCollectDRIDrawables(struct glx_screen *psc); + +extern __GLXDRIdrawable * +GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable); + +#endif + +extern struct glx_context dummyContext; + +extern struct glx_screen * +indirect_create_screen(int screen, struct glx_display * priv); +extern struct glx_context * +indirect_create_context(struct glx_screen *psc, + struct glx_config *mode, + struct glx_context *shareList, int renderType); + +#endif /* !__GLX_client_h__ */ diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c new file mode 100644 index 0000000..d9ca3f5 --- /dev/null +++ b/src/glx/glxcmds.c @@ -0,0 +1,2578 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/** + * \file glxcmds.c + * Client-side GLX interface. + */ + +#include "glxclient.h" +#include "glapi.h" +#include "glxextensions.h" + +#ifdef GLX_DIRECT_RENDERING +#ifdef GLX_USE_APPLEGL +#include "apple_glx_context.h" +#include "apple_glx.h" +#include "glx_error.h" +#else +#include +#ifdef XF86VIDMODE +#include +#endif +#include "xf86dri.h" +#endif +#else +#endif + +#if defined(USE_XCB) +#include +#include +#include +#endif + +static const char __glXGLXClientVendorName[] = "Mesa Project and SGI"; +static const char __glXGLXClientVersion[] = "1.4"; + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + +/** + * Get the __DRIdrawable for the drawable associated with a GLXContext + * + * \param dpy The display associated with \c drawable. + * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved. + * \param scrn_num If non-NULL, the drawables screen is stored there + * \returns A pointer to the context's __DRIdrawable on success, or NULL if + * the drawable is not associated with a direct-rendering context. + */ +_X_HIDDEN __GLXDRIdrawable * +GetGLXDRIDrawable(Display * dpy, GLXDrawable drawable) +{ + struct glx_display *priv = __glXInitialize(dpy); + __GLXDRIdrawable *pdraw; + + if (priv == NULL) + return NULL; + + if (__glxHashLookup(priv->drawHash, drawable, (void *) &pdraw) == 0) + return pdraw; + + return NULL; +} + +#endif + + +/** + * Get the GLX per-screen data structure associated with a GLX context. + * + * \param dpy Display for which the GLX per-screen information is to be + * retrieved. + * \param scrn Screen on \c dpy for which the GLX per-screen information is + * to be retrieved. + * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn + * specify a valid GLX screen, or NULL otherwise. + * + * \todo Should this function validate that \c scrn is within the screen + * number range for \c dpy? + */ + +static struct glx_screen * +GetGLXScreenConfigs(Display * dpy, int scrn) +{ + struct glx_display *const priv = __glXInitialize(dpy); + + return (priv + && priv->screens != + NULL) ? priv->screens[scrn] : NULL; +} + + +static int +GetGLXPrivScreenConfig(Display * dpy, int scrn, struct glx_display ** ppriv, + struct glx_screen ** ppsc) +{ + /* Initialize the extension, if needed . This has the added value + * of initializing/allocating the display private + */ + + if (dpy == NULL) { + return GLX_NO_EXTENSION; + } + + *ppriv = __glXInitialize(dpy); + if (*ppriv == NULL) { + return GLX_NO_EXTENSION; + } + + /* Check screen number to see if its valid */ + if ((scrn < 0) || (scrn >= ScreenCount(dpy))) { + return GLX_BAD_SCREEN; + } + + /* Check to see if the GL is supported on this screen */ + *ppsc = (*ppriv)->screens[scrn]; + if ((*ppsc)->configs == NULL) { + /* No support for GL on this screen regardless of visual */ + return GLX_BAD_VISUAL; + } + + return Success; +} + + +/** + * Determine if a \c GLXFBConfig supplied by the application is valid. + * + * \param dpy Application supplied \c Display pointer. + * \param config Application supplied \c GLXFBConfig. + * + * \returns If the \c GLXFBConfig is valid, the a pointer to the matching + * \c struct glx_config structure is returned. Otherwise, \c NULL + * is returned. + */ +static struct glx_config * +ValidateGLXFBConfig(Display * dpy, GLXFBConfig fbconfig) +{ + struct glx_display *const priv = __glXInitialize(dpy); + int num_screens = ScreenCount(dpy); + unsigned i; + struct glx_config *config; + + if (priv != NULL) { + for (i = 0; i < num_screens; i++) { + for (config = priv->screens[i]->configs; config != NULL; + config = config->next) { + if (config == (struct glx_config *) fbconfig) { + return config; + } + } + } + } + + return NULL; +} + +_X_HIDDEN Bool +glx_context_init(struct glx_context *gc, + struct glx_screen *psc, struct glx_config *config) +{ + gc->majorOpcode = __glXSetupForCommand(psc->display->dpy); + if (!gc->majorOpcode) + return GL_FALSE; + + gc->screen = psc->scr; + gc->psc = psc; + gc->config = config; + gc->isDirect = GL_TRUE; + gc->currentContextTag = -1; + + return GL_TRUE; +} + + +/** + * Create a new context. Exactly one of \c vis and \c fbconfig should be + * non-NULL. + * + * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or + * SGIX_fbconfig protocol be used? + * \param renderType For FBConfigs, what is the rendering type? + */ + +static GLXContext +CreateContext(Display * dpy, int generic_id, + struct glx_config *config, + GLXContext shareList_user, + Bool allowDirect, + unsigned code, int renderType, int screen) +{ + struct glx_context *gc; + struct glx_screen *psc; + struct glx_context *shareList = (struct glx_context *) shareList_user; + if (dpy == NULL) + return NULL; + + psc = GetGLXScreenConfigs(dpy, screen); + if (psc == NULL) + return NULL; + + if (generic_id == None) + return NULL; + + gc = NULL; + if (allowDirect && psc->vtable->create_context) + gc = psc->vtable->create_context(psc, config, shareList, renderType); + if (!gc) + gc = indirect_create_context(psc, config, shareList, renderType); + if (!gc) + return NULL; + + LockDisplay(dpy); + switch (code) { + case X_GLXCreateContext: { + xGLXCreateContextReq *req; + + /* Send the glXCreateContext request */ + GetReq(GLXCreateContext, req); + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXCreateContext; + req->context = gc->xid = XAllocID(dpy); + req->visual = generic_id; + req->screen = screen; + req->shareList = shareList ? shareList->xid : None; + req->isDirect = gc->isDirect; + break; + } + + case X_GLXCreateNewContext: { + xGLXCreateNewContextReq *req; + + /* Send the glXCreateNewContext request */ + GetReq(GLXCreateNewContext, req); + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXCreateNewContext; + req->context = gc->xid = XAllocID(dpy); + req->fbconfig = generic_id; + req->screen = screen; + req->renderType = renderType; + req->shareList = shareList ? shareList->xid : None; + req->isDirect = gc->isDirect; + break; + } + + case X_GLXvop_CreateContextWithConfigSGIX: { + xGLXVendorPrivateWithReplyReq *vpreq; + xGLXCreateContextWithConfigSGIXReq *req; + + /* Send the glXCreateNewContext request */ + GetReqExtra(GLXVendorPrivateWithReply, + sz_xGLXCreateContextWithConfigSGIXReq - + sz_xGLXVendorPrivateWithReplyReq, vpreq); + req = (xGLXCreateContextWithConfigSGIXReq *) vpreq; + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXVendorPrivateWithReply; + req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX; + req->context = gc->xid = XAllocID(dpy); + req->fbconfig = generic_id; + req->screen = screen; + req->renderType = renderType; + req->shareList = shareList ? shareList->xid : None; + req->isDirect = gc->isDirect; + break; + } + + default: + /* What to do here? This case is the sign of an internal error. It + * should never be reachable. + */ + break; + } + + UnlockDisplay(dpy); + SyncHandle(); + + gc->imported = GL_FALSE; + gc->renderType = renderType; + + return (GLXContext) gc; +} + +_X_EXPORT GLXContext +glXCreateContext(Display * dpy, XVisualInfo * vis, + GLXContext shareList, Bool allowDirect) +{ + struct glx_config *config = NULL; + int renderType = 0; + +#if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL) + struct glx_screen *const psc = GetGLXScreenConfigs(dpy, vis->screen); + + config = glx_config_find_visual(psc->visuals, vis->visualid); + if (config == NULL) { + xError error; + + error.errorCode = BadValue; + error.resourceID = vis->visualid; + error.sequenceNumber = dpy->request; + error.type = X_Error; + error.majorCode = __glXSetupForCommand(dpy); + error.minorCode = X_GLXCreateContext; + _XError(dpy, &error); + return None; + } + + renderType = config->rgbMode ? GLX_RGBA_TYPE : GLX_COLOR_INDEX_TYPE; +#endif + + return CreateContext(dpy, vis->visualid, config, shareList, allowDirect, + X_GLXCreateContext, renderType, vis->screen); +} + +_X_HIDDEN void +glx_send_destroy_context(Display *dpy, XID xid) +{ + CARD8 opcode = __glXSetupForCommand(dpy); + xGLXDestroyContextReq *req; + + LockDisplay(dpy); + GetReq(GLXDestroyContext, req); + req->reqType = opcode; + req->glxCode = X_GLXDestroyContext; + req->context = xid; + UnlockDisplay(dpy); + SyncHandle(); +} + +/* +** Destroy the named context +*/ +static void +DestroyContext(Display * dpy, GLXContext ctx) +{ + struct glx_context *gc = (struct glx_context *) ctx; + + if (!gc) + return; + + __glXLock(); + if (gc->currentDpy) { + /* This context is bound to some thread. According to the man page, + * we should not actually delete the context until it's unbound. + * Note that we set gc->xid = None above. In MakeContextCurrent() + * we check for that and delete the context there. + */ + if (!gc->imported) + glx_send_destroy_context(dpy, gc->xid); + gc->xid = None; + __glXUnlock(); + return; + } + __glXUnlock(); + + if (gc->vtable->destroy) + gc->vtable->destroy(gc); +} + +_X_EXPORT void +glXDestroyContext(Display * dpy, GLXContext gc) +{ + DestroyContext(dpy, gc); +} + +/* +** Return the major and minor version #s for the GLX extension +*/ +_X_EXPORT Bool +glXQueryVersion(Display * dpy, int *major, int *minor) +{ + struct glx_display *priv; + + /* Init the extension. This fetches the major and minor version. */ + priv = __glXInitialize(dpy); + if (!priv) + return GL_FALSE; + + if (major) + *major = priv->majorVersion; + if (minor) + *minor = priv->minorVersion; + return GL_TRUE; +} + +/* +** Query the existance of the GLX extension +*/ +_X_EXPORT Bool +glXQueryExtension(Display * dpy, int *errorBase, int *eventBase) +{ + int major_op, erb, evb; + Bool rv; + + rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb); + if (rv) { + if (errorBase) + *errorBase = erb; + if (eventBase) + *eventBase = evb; + } + return rv; +} + +/* +** Put a barrier in the token stream that forces the GL to finish its +** work before X can proceed. +*/ +_X_EXPORT void +glXWaitGL(void) +{ + struct glx_context *gc = __glXGetCurrentContext(); + + if (gc && gc->vtable->wait_gl) + gc->vtable->wait_gl(gc); +} + +/* +** Put a barrier in the token stream that forces X to finish its +** work before GL can proceed. +*/ +_X_EXPORT void +glXWaitX(void) +{ + struct glx_context *gc = __glXGetCurrentContext(); + + if (gc && gc->vtable->wait_x) + gc->vtable->wait_x(gc); +} + +_X_EXPORT void +glXUseXFont(Font font, int first, int count, int listBase) +{ + struct glx_context *gc = __glXGetCurrentContext(); + + if (gc && gc->vtable->use_x_font) + gc->vtable->use_x_font(gc, font, first, count, listBase); +} + +/************************************************************************/ + +/* +** Copy the source context to the destination context using the +** attribute "mask". +*/ +_X_EXPORT void +glXCopyContext(Display * dpy, GLXContext source_user, + GLXContext dest_user, unsigned long mask) +{ + struct glx_context *source = (struct glx_context *) source_user; + struct glx_context *dest = (struct glx_context *) dest_user; +#ifdef GLX_USE_APPLEGL + struct glx_context *gc = __glXGetCurrentContext(); + int errorcode; + bool x11error; + + if(apple_glx_copy_context(gc->driContext, source->driContext, dest->driContext, + mask, &errorcode, &x11error)) { + __glXSendError(dpy, errorcode, 0, X_GLXCopyContext, x11error); + } + +#else + xGLXCopyContextReq *req; + struct glx_context *gc = __glXGetCurrentContext(); + GLXContextTag tag; + CARD8 opcode; + + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return; + } + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + /* NOT_DONE: This does not work yet */ + } +#endif + + /* + ** If the source is the current context, send its tag so that the context + ** can be flushed before the copy. + */ + if (source == gc && dpy == gc->currentDpy) { + tag = gc->currentContextTag; + } + else { + tag = 0; + } + + /* Send the glXCopyContext request */ + LockDisplay(dpy); + GetReq(GLXCopyContext, req); + req->reqType = opcode; + req->glxCode = X_GLXCopyContext; + req->source = source ? source->xid : None; + req->dest = dest ? dest->xid : None; + req->mask = mask; + req->contextTag = tag; + UnlockDisplay(dpy); + SyncHandle(); +#endif /* GLX_USE_APPLEGL */ +} + + +/** + * Determine if a context uses direct rendering. + * + * \param dpy Display where the context was created. + * \param contextID ID of the context to be tested. + * + * \returns \c GL_TRUE if the context is direct rendering or not. + */ +static Bool +__glXIsDirect(Display * dpy, GLXContextID contextID) +{ +#if !defined(USE_XCB) + xGLXIsDirectReq *req; + xGLXIsDirectReply reply; +#endif + CARD8 opcode; + + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return GL_FALSE; + } + +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + xcb_glx_is_direct_reply_t *reply = xcb_glx_is_direct_reply(c, + xcb_glx_is_direct + (c, contextID), + NULL); + + const Bool is_direct = reply->is_direct ? True : False; + free(reply); + + return is_direct; +#else + /* Send the glXIsDirect request */ + LockDisplay(dpy); + GetReq(GLXIsDirect, req); + req->reqType = opcode; + req->glxCode = X_GLXIsDirect; + req->context = contextID; + _XReply(dpy, (xReply *) & reply, 0, False); + UnlockDisplay(dpy); + SyncHandle(); + + return reply.isDirect; +#endif /* USE_XCB */ +} + +/** + * \todo + * Shouldn't this function \b always return \c GL_FALSE when + * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with + * the GLX protocol here at all? + */ +_X_EXPORT Bool +glXIsDirect(Display * dpy, GLXContext gc_user) +{ + struct glx_context *gc = (struct glx_context *) gc_user; + + if (!gc) { + return GL_FALSE; + } + else if (gc->isDirect) { + return GL_TRUE; + } +#ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */ + return GL_FALSE; +#else + return __glXIsDirect(dpy, gc->xid); +#endif +} + +_X_EXPORT GLXPixmap +glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap) +{ +#ifdef GLX_USE_APPLEGL + int screen = vis->screen; + struct glx_screen *const psc = GetGLXScreenConfigs(dpy, screen); + const struct glx_config *config; + + config = _gl_context_modes_find_visual(psc->visuals, vis->visualid); + + if(apple_glx_pixmap_create(dpy, vis->screen, pixmap, config)) + return None; + + return pixmap; +#else + xGLXCreateGLXPixmapReq *req; + GLXPixmap xid; + CARD8 opcode; + + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return None; + } + + /* Send the glXCreateGLXPixmap request */ + LockDisplay(dpy); + GetReq(GLXCreateGLXPixmap, req); + req->reqType = opcode; + req->glxCode = X_GLXCreateGLXPixmap; + req->screen = vis->screen; + req->visual = vis->visualid; + req->pixmap = pixmap; + req->glxpixmap = xid = XAllocID(dpy); + UnlockDisplay(dpy); + SyncHandle(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + do { + /* FIXME: Maybe delay __DRIdrawable creation until the drawable + * is actually bound to a context... */ + + struct glx_display *const priv = __glXInitialize(dpy); + __GLXDRIdrawable *pdraw; + struct glx_screen *psc; + struct glx_config *config; + + psc = priv->screens[vis->screen]; + if (psc->driScreen == NULL) + break; + config = glx_config_find_visual(psc->visuals, vis->visualid); + pdraw = psc->driScreen->createDrawable(psc, pixmap, req->glxpixmap, config); + if (pdraw == NULL) { + fprintf(stderr, "failed to create pixmap\n"); + break; + } + + if (__glxHashInsert(priv->drawHash, req->glxpixmap, pdraw)) { + (*pdraw->destroyDrawable) (pdraw); + return None; /* FIXME: Check what we're supposed to do here... */ + } + } while (0); +#endif + + return xid; +#endif +} + +/* +** Destroy the named pixmap +*/ +_X_EXPORT void +glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap) +{ +#ifdef GLX_USE_APPLEGL + if(apple_glx_pixmap_destroy(dpy, glxpixmap)) + __glXSendError(dpy, GLXBadPixmap, glxpixmap, X_GLXDestroyPixmap, false); +#else + xGLXDestroyGLXPixmapReq *req; + CARD8 opcode; + + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return; + } + + /* Send the glXDestroyGLXPixmap request */ + LockDisplay(dpy); + GetReq(GLXDestroyGLXPixmap, req); + req->reqType = opcode; + req->glxCode = X_GLXDestroyGLXPixmap; + req->glxpixmap = glxpixmap; + UnlockDisplay(dpy); + SyncHandle(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + { + struct glx_display *const priv = __glXInitialize(dpy); + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, glxpixmap); + + if (pdraw != NULL) { + (*pdraw->destroyDrawable) (pdraw); + __glxHashDelete(priv->drawHash, glxpixmap); + } + } +#endif +#endif /* GLX_USE_APPLEGL */ +} + +_X_EXPORT void +glXSwapBuffers(Display * dpy, GLXDrawable drawable) +{ +#ifdef GLX_USE_APPLEGL + GLXContext gc = glXGetCurrentContext(); + if(gc && apple_glx_is_current_drawable(dpy, gc->driContext, drawable)) { + apple_glx_swap_buffers(gc->driContext); + } else { + __glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, false); + } +#else + struct glx_context *gc; + GLXContextTag tag; + CARD8 opcode; +#ifdef USE_XCB + xcb_connection_t *c; +#else + xGLXSwapBuffersReq *req; +#endif + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable); + + if (pdraw != NULL) { + glFlush(); + (*pdraw->psc->driScreen->swapBuffers)(pdraw, 0, 0, 0); + return; + } +#endif + + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return; + } + + /* + ** The calling thread may or may not have a current context. If it + ** does, send the context tag so the server can do a flush. + */ + gc = __glXGetCurrentContext(); + if ((gc != NULL) && (dpy == gc->currentDpy) && + ((drawable == gc->currentDrawable) + || (drawable == gc->currentReadable))) { + tag = gc->currentContextTag; + } + else { + tag = 0; + } + +#ifdef USE_XCB + c = XGetXCBConnection(dpy); + xcb_glx_swap_buffers(c, tag, drawable); + xcb_flush(c); +#else + /* Send the glXSwapBuffers request */ + LockDisplay(dpy); + GetReq(GLXSwapBuffers, req); + req->reqType = opcode; + req->glxCode = X_GLXSwapBuffers; + req->drawable = drawable; + req->contextTag = tag; + UnlockDisplay(dpy); + SyncHandle(); + XFlush(dpy); +#endif /* USE_XCB */ +#endif /* GLX_USE_APPLEGL */ +} + + +/* +** Return configuration information for the given display, screen and +** visual combination. +*/ +_X_EXPORT int +glXGetConfig(Display * dpy, XVisualInfo * vis, int attribute, + int *value_return) +{ + struct glx_display *priv; + struct glx_screen *psc; + struct glx_config *config; + int status; + + status = GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc); + if (status == Success) { + config = glx_config_find_visual(psc->visuals, vis->visualid); + + /* Lookup attribute after first finding a match on the visual */ + if (config != NULL) { + return glx_config_get(config, attribute, value_return); + } + + status = GLX_BAD_VISUAL; + } + + /* + ** If we can't find the config for this visual, this visual is not + ** supported by the OpenGL implementation on the server. + */ + if ((status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL)) { + *value_return = GL_FALSE; + status = Success; + } + + return status; +} + +/************************************************************************/ + +static void +init_fbconfig_for_chooser(struct glx_config * config, + GLboolean fbconfig_style_tags) +{ + memset(config, 0, sizeof(struct glx_config)); + config->visualID = (XID) GLX_DONT_CARE; + config->visualType = GLX_DONT_CARE; + + /* glXChooseFBConfig specifies different defaults for these two than + * glXChooseVisual. + */ + if (fbconfig_style_tags) { + config->rgbMode = GL_TRUE; + config->doubleBufferMode = GLX_DONT_CARE; + } + + config->visualRating = GLX_DONT_CARE; + config->transparentPixel = GLX_NONE; + config->transparentRed = GLX_DONT_CARE; + config->transparentGreen = GLX_DONT_CARE; + config->transparentBlue = GLX_DONT_CARE; + config->transparentAlpha = GLX_DONT_CARE; + config->transparentIndex = GLX_DONT_CARE; + + config->drawableType = GLX_WINDOW_BIT; + config->renderType = + (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT; + config->xRenderable = GLX_DONT_CARE; + config->fbconfigID = (GLXFBConfigID) (GLX_DONT_CARE); + + config->swapMethod = GLX_DONT_CARE; +} + +#define MATCH_DONT_CARE( param ) \ + do { \ + if ( ((int) a-> param != (int) GLX_DONT_CARE) \ + && (a-> param != b-> param) ) { \ + return False; \ + } \ + } while ( 0 ) + +#define MATCH_MINIMUM( param ) \ + do { \ + if ( ((int) a-> param != (int) GLX_DONT_CARE) \ + && (a-> param > b-> param) ) { \ + return False; \ + } \ + } while ( 0 ) + +#define MATCH_EXACT( param ) \ + do { \ + if ( a-> param != b-> param) { \ + return False; \ + } \ + } while ( 0 ) + +/* Test that all bits from a are contained in b */ +#define MATCH_MASK(param) \ + do { \ + if ((a->param & ~b->param) != 0) \ + return False; \ + } while (0); + +/** + * Determine if two GLXFBConfigs are compatible. + * + * \param a Application specified config to test. + * \param b Server specified config to test against \c a. + */ +static Bool +fbconfigs_compatible(const struct glx_config * const a, + const struct glx_config * const b) +{ + MATCH_DONT_CARE(doubleBufferMode); + MATCH_DONT_CARE(visualType); + MATCH_DONT_CARE(visualRating); + MATCH_DONT_CARE(xRenderable); + MATCH_DONT_CARE(fbconfigID); + MATCH_DONT_CARE(swapMethod); + + MATCH_MINIMUM(rgbBits); + MATCH_MINIMUM(numAuxBuffers); + MATCH_MINIMUM(redBits); + MATCH_MINIMUM(greenBits); + MATCH_MINIMUM(blueBits); + MATCH_MINIMUM(alphaBits); + MATCH_MINIMUM(depthBits); + MATCH_MINIMUM(stencilBits); + MATCH_MINIMUM(accumRedBits); + MATCH_MINIMUM(accumGreenBits); + MATCH_MINIMUM(accumBlueBits); + MATCH_MINIMUM(accumAlphaBits); + MATCH_MINIMUM(sampleBuffers); + MATCH_MINIMUM(maxPbufferWidth); + MATCH_MINIMUM(maxPbufferHeight); + MATCH_MINIMUM(maxPbufferPixels); + MATCH_MINIMUM(samples); + + MATCH_DONT_CARE(stereoMode); + MATCH_EXACT(level); + + MATCH_MASK(drawableType); + MATCH_MASK(renderType); + + /* There is a bug in a few of the XFree86 DDX drivers. They contain + * visuals with a "transparent type" of 0 when they really mean GLX_NONE. + * Technically speaking, it is a bug in the DDX driver, but there is + * enough of an installed base to work around the problem here. In any + * case, 0 is not a valid value of the transparent type, so we'll treat 0 + * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and + * 0 from the server to be a match to maintain backward compatibility with + * the (broken) drivers. + */ + + if (a->transparentPixel != (int) GLX_DONT_CARE && a->transparentPixel != 0) { + if (a->transparentPixel == GLX_NONE) { + if (b->transparentPixel != GLX_NONE && b->transparentPixel != 0) + return False; + } + else { + MATCH_EXACT(transparentPixel); + } + + switch (a->transparentPixel) { + case GLX_TRANSPARENT_RGB: + MATCH_DONT_CARE(transparentRed); + MATCH_DONT_CARE(transparentGreen); + MATCH_DONT_CARE(transparentBlue); + MATCH_DONT_CARE(transparentAlpha); + break; + + case GLX_TRANSPARENT_INDEX: + MATCH_DONT_CARE(transparentIndex); + break; + + default: + break; + } + } + + return True; +} + + +/* There's some trickly language in the GLX spec about how this is supposed + * to work. Basically, if a given component size is either not specified + * or the requested size is zero, it is supposed to act like PERFER_SMALLER. + * Well, that's really hard to do with the code as-is. This behavior is + * closer to correct, but still not technically right. + */ +#define PREFER_LARGER_OR_ZERO(comp) \ + do { \ + if ( ((*a)-> comp) != ((*b)-> comp) ) { \ + if ( ((*a)-> comp) == 0 ) { \ + return -1; \ + } \ + else if ( ((*b)-> comp) == 0 ) { \ + return 1; \ + } \ + else { \ + return ((*b)-> comp) - ((*a)-> comp) ; \ + } \ + } \ + } while( 0 ) + +#define PREFER_LARGER(comp) \ + do { \ + if ( ((*a)-> comp) != ((*b)-> comp) ) { \ + return ((*b)-> comp) - ((*a)-> comp) ; \ + } \ + } while( 0 ) + +#define PREFER_SMALLER(comp) \ + do { \ + if ( ((*a)-> comp) != ((*b)-> comp) ) { \ + return ((*a)-> comp) - ((*b)-> comp) ; \ + } \ + } while( 0 ) + +/** + * Compare two GLXFBConfigs. This function is intended to be used as the + * compare function passed in to qsort. + * + * \returns If \c a is a "better" config, according to the specification of + * SGIX_fbconfig, a number less than zero is returned. If \c b is + * better, then a number greater than zero is return. If both are + * equal, zero is returned. + * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX + */ +static int +fbconfig_compare(struct glx_config **a, struct glx_config **b) +{ + /* The order of these comparisons must NOT change. It is defined by + * the GLX 1.3 spec and ARB_multisample. + */ + + PREFER_SMALLER(visualSelectGroup); + + /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and + * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the + * numerical sort order of the enums (0x8000, 0x8001, and 0x800D). + */ + PREFER_SMALLER(visualRating); + + /* This isn't quite right. It is supposed to compare the sum of the + * components the user specifically set minimums for. + */ + PREFER_LARGER_OR_ZERO(redBits); + PREFER_LARGER_OR_ZERO(greenBits); + PREFER_LARGER_OR_ZERO(blueBits); + PREFER_LARGER_OR_ZERO(alphaBits); + + PREFER_SMALLER(rgbBits); + + if (((*a)->doubleBufferMode != (*b)->doubleBufferMode)) { + /* Prefer single-buffer. + */ + return (!(*a)->doubleBufferMode) ? -1 : 1; + } + + PREFER_SMALLER(numAuxBuffers); + + PREFER_LARGER_OR_ZERO(depthBits); + PREFER_SMALLER(stencilBits); + + /* This isn't quite right. It is supposed to compare the sum of the + * components the user specifically set minimums for. + */ + PREFER_LARGER_OR_ZERO(accumRedBits); + PREFER_LARGER_OR_ZERO(accumGreenBits); + PREFER_LARGER_OR_ZERO(accumBlueBits); + PREFER_LARGER_OR_ZERO(accumAlphaBits); + + PREFER_SMALLER(visualType); + + /* None of the multisample specs say where this comparison should happen, + * so I put it near the end. + */ + PREFER_SMALLER(sampleBuffers); + PREFER_SMALLER(samples); + + /* None of the pbuffer or fbconfig specs say that this comparison needs + * to happen at all, but it seems like it should. + */ + PREFER_LARGER(maxPbufferWidth); + PREFER_LARGER(maxPbufferHeight); + PREFER_LARGER(maxPbufferPixels); + + return 0; +} + + +/** + * Selects and sorts a subset of the supplied configs based on the attributes. + * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig, + * and \c glXChooseFBConfigSGIX. + * + * \param configs Array of pointers to possible configs. The elements of + * this array that do not meet the criteria will be set to + * NULL. The remaining elements will be sorted according to + * the various visual / FBConfig selection rules. + * \param num_configs Number of elements in the \c configs array. + * \param attribList Attributes used select from \c configs. This array is + * terminated by a \c None tag. The array can either take + * the form expected by \c glXChooseVisual (where boolean + * tags do not have a value) or by \c glXChooseFBConfig + * (where every tag has a value). + * \param fbconfig_style_tags Selects whether \c attribList is in + * \c glXChooseVisual style or + * \c glXChooseFBConfig style. + * \returns The number of valid elements left in \c configs. + * + * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX + */ +static int +choose_visual(struct glx_config ** configs, int num_configs, + const int *attribList, GLboolean fbconfig_style_tags) +{ + struct glx_config test_config; + int base; + int i; + + /* This is a fairly direct implementation of the selection method + * described by GLX_SGIX_fbconfig. Start by culling out all the + * configs that are not compatible with the selected parameter + * list. + */ + + init_fbconfig_for_chooser(&test_config, fbconfig_style_tags); + __glXInitializeVisualConfigFromTags(&test_config, 512, + (const INT32 *) attribList, + GL_TRUE, fbconfig_style_tags); + + base = 0; + for (i = 0; i < num_configs; i++) { + if (fbconfigs_compatible(&test_config, configs[i])) { + configs[base] = configs[i]; + base++; + } + } + + if (base == 0) { + return 0; + } + + if (base < num_configs) { + (void) memset(&configs[base], 0, sizeof(void *) * (num_configs - base)); + } + + /* After the incompatible configs are removed, the resulting + * list is sorted according to the rules set out in the various + * specifications. + */ + + qsort(configs, base, sizeof(struct glx_config *), + (int (*)(const void *, const void *)) fbconfig_compare); + return base; +} + + + + +/* +** Return the visual that best matches the template. Return None if no +** visual matches the template. +*/ +_X_EXPORT XVisualInfo * +glXChooseVisual(Display * dpy, int screen, int *attribList) +{ + XVisualInfo *visualList = NULL; + struct glx_display *priv; + struct glx_screen *psc; + struct glx_config test_config; + struct glx_config *config; + struct glx_config *best_config = NULL; + + /* + ** Get a list of all visuals, return if list is empty + */ + if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) { + return None; + } + + + /* + ** Build a template from the defaults and the attribute list + ** Free visual list and return if an unexpected token is encountered + */ + init_fbconfig_for_chooser(&test_config, GL_FALSE); + __glXInitializeVisualConfigFromTags(&test_config, 512, + (const INT32 *) attribList, + GL_TRUE, GL_FALSE); + + /* + ** Eliminate visuals that don't meet minimum requirements + ** Compute a score for those that do + ** Remember which visual, if any, got the highest score + ** If no visual is acceptable, return None + ** Otherwise, create an XVisualInfo list with just the selected X visual + ** and return this. + */ + for (config = psc->visuals; config != NULL; config = config->next) { + if (fbconfigs_compatible(&test_config, config) + && ((best_config == NULL) || + (fbconfig_compare (&config, &best_config) < 0))) { + XVisualInfo visualTemplate; + XVisualInfo *newList; + int i; + + visualTemplate.screen = screen; + visualTemplate.visualid = config->visualID; + newList = XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask, + &visualTemplate, &i); + + if (newList) { + Xfree(visualList); + visualList = newList; + best_config = config; + } + } + } + +#ifdef GLX_USE_APPLEGL + if(visualList && getenv("LIBGL_DUMP_VISUALID")) { + printf("visualid 0x%lx\n", visualList[0].visualid); + } +#endif + + return visualList; +} + + +_X_EXPORT const char * +glXQueryExtensionsString(Display * dpy, int screen) +{ + struct glx_screen *psc; + struct glx_display *priv; + + if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) { + return NULL; + } + + if (!psc->effectiveGLXexts) { + if (!psc->serverGLXexts) { + psc->serverGLXexts = + __glXQueryServerString(dpy, priv->majorOpcode, screen, + GLX_EXTENSIONS); + } + + __glXCalculateUsableExtensions(psc, +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + (psc->driScreen != NULL), +#else + GL_FALSE, +#endif + priv->minorVersion); + } + + return psc->effectiveGLXexts; +} + +_X_EXPORT const char * +glXGetClientString(Display * dpy, int name) +{ + (void) dpy; + + switch (name) { + case GLX_VENDOR: + return (__glXGLXClientVendorName); + case GLX_VERSION: + return (__glXGLXClientVersion); + case GLX_EXTENSIONS: + return (__glXGetClientExtensions()); + default: + return NULL; + } +} + +_X_EXPORT const char * +glXQueryServerString(Display * dpy, int screen, int name) +{ + struct glx_screen *psc; + struct glx_display *priv; + const char **str; + + + if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) { + return NULL; + } + + switch (name) { + case GLX_VENDOR: + str = &priv->serverGLXvendor; + break; + case GLX_VERSION: + str = &priv->serverGLXversion; + break; + case GLX_EXTENSIONS: + str = &psc->serverGLXexts; + break; + default: + return NULL; + } + + if (*str == NULL) { + *str = __glXQueryServerString(dpy, priv->majorOpcode, screen, name); + } + + return *str; +} + +void +__glXClientInfo(Display * dpy, int opcode) +{ + char *ext_str = __glXGetClientGLExtensionString(); + int size = strlen(ext_str) + 1; + +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + xcb_glx_client_info(c, + GLX_MAJOR_VERSION, GLX_MINOR_VERSION, size, ext_str); +#else + xGLXClientInfoReq *req; + + /* Send the glXClientInfo request */ + LockDisplay(dpy); + GetReq(GLXClientInfo, req); + req->reqType = opcode; + req->glxCode = X_GLXClientInfo; + req->major = GLX_MAJOR_VERSION; + req->minor = GLX_MINOR_VERSION; + + req->length += (size + 3) >> 2; + req->numbytes = size; + Data(dpy, ext_str, size); + + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + + Xfree(ext_str); +} + + +/* +** EXT_import_context +*/ + +_X_EXPORT Display * +glXGetCurrentDisplay(void) +{ + struct glx_context *gc = __glXGetCurrentContext(); + if (NULL == gc) + return NULL; + return gc->currentDpy; +} + +_X_EXPORT +GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (), + glXGetCurrentDisplay) + +#ifndef GLX_USE_APPLEGL +_X_EXPORT GLXContext +glXImportContextEXT(Display *dpy, GLXContextID contextID) +{ + struct glx_display *priv = __glXInitialize(dpy); + struct glx_screen *psc; + xGLXQueryContextReply reply; + CARD8 opcode; + struct glx_context *ctx; + int propList[__GLX_MAX_CONTEXT_PROPS * 2], *pProp, nPropListBytes; + int i, renderType; + XID share; + struct glx_config *mode; + + if (contextID == None || __glXIsDirect(dpy, contextID)) + return NULL; + + opcode = __glXSetupForCommand(dpy); + if (!opcode) + return 0; + + /* Send the glXQueryContextInfoEXT request */ + LockDisplay(dpy); + + if (priv->majorVersion > 1 || priv->minorVersion >= 3) { + xGLXQueryContextReq *req; + + GetReq(GLXQueryContext, req); + + req->reqType = opcode; + req->glxCode = X_GLXQueryContext; + req->context = contextID; + } + else { + xGLXVendorPrivateReq *vpreq; + xGLXQueryContextInfoEXTReq *req; + + GetReqExtra(GLXVendorPrivate, + sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq, + vpreq); + req = (xGLXQueryContextInfoEXTReq *) vpreq; + req->reqType = opcode; + req->glxCode = X_GLXVendorPrivateWithReply; + req->vendorCode = X_GLXvop_QueryContextInfoEXT; + req->context = contextID; + } + + _XReply(dpy, (xReply *) & reply, 0, False); + + if (reply.n <= __GLX_MAX_CONTEXT_PROPS) + nPropListBytes = reply.n * 2 * sizeof propList[0]; + else + nPropListBytes = 0; + _XRead(dpy, (char *) propList, nPropListBytes); + UnlockDisplay(dpy); + SyncHandle(); + + /* Look up screen first so we can look up visuals/fbconfigs later */ + psc = NULL; + for (i = 0, pProp = propList; i < reply.n; i++, pProp += 2) + if (pProp[0] == GLX_SCREEN) + psc = GetGLXScreenConfigs(dpy, pProp[1]); + if (psc == NULL) + return NULL; + + share = None; + mode = NULL; + renderType = 0; + pProp = propList; + + for (i = 0, pProp = propList; i < reply.n; i++, pProp += 2) + switch (pProp[0]) { + case GLX_SHARE_CONTEXT_EXT: + share = pProp[1]; + break; + case GLX_VISUAL_ID_EXT: + mode = glx_config_find_visual(psc->visuals, pProp[1]); + break; + case GLX_FBCONFIG_ID: + mode = glx_config_find_fbconfig(psc->configs, pProp[1]); + break; + case GLX_RENDER_TYPE: + renderType = pProp[1]; + break; + } + + if (mode == NULL) + return NULL; + + ctx = indirect_create_context(psc, mode, NULL, renderType); + if (ctx == NULL) + return NULL; + + ctx->xid = contextID; + ctx->imported = GL_TRUE; + ctx->share_xid = share; + + return (GLXContext) ctx; +} + +#endif + +_X_EXPORT int +glXQueryContext(Display * dpy, GLXContext ctx_user, int attribute, int *value) +{ + struct glx_context *ctx = (struct glx_context *) ctx_user; + + switch (attribute) { + case GLX_SHARE_CONTEXT_EXT: + *value = ctx->share_xid; + break; + case GLX_VISUAL_ID_EXT: + *value = ctx->config ? ctx->config->visualID : None; + break; + case GLX_SCREEN: + *value = ctx->screen; + break; + case GLX_FBCONFIG_ID: + *value = ctx->config ? ctx->config->fbconfigID : None; + break; + case GLX_RENDER_TYPE: + *value = ctx->renderType; + break; + default: + return GLX_BAD_ATTRIBUTE; + } + return Success; +} + +_X_EXPORT +GLX_ALIAS(int, glXQueryContextInfoEXT, + (Display * dpy, GLXContext ctx, int attribute, int *value), + (dpy, ctx, attribute, value), glXQueryContext) + +_X_EXPORT GLXContextID glXGetContextIDEXT(const GLXContext ctx_user) +{ + struct glx_context *ctx = (struct glx_context *) ctx_user; + + return ctx->xid; +} + +_X_EXPORT void +glXFreeContextEXT(Display * dpy, GLXContext ctx) +{ + DestroyContext(dpy, ctx); +} + + +_X_EXPORT GLXFBConfig * +glXChooseFBConfig(Display * dpy, int screen, + const int *attribList, int *nitems) +{ + struct glx_config **config_list; + int list_size; + + + config_list = (struct glx_config **) + glXGetFBConfigs(dpy, screen, &list_size); + + if ((config_list != NULL) && (list_size > 0) && (attribList != NULL)) { + list_size = choose_visual(config_list, list_size, attribList, GL_TRUE); + if (list_size == 0) { + XFree(config_list); + config_list = NULL; + } + } + + *nitems = list_size; + return (GLXFBConfig *) config_list; +} + + +_X_EXPORT GLXContext +glXCreateNewContext(Display * dpy, GLXFBConfig fbconfig, + int renderType, GLXContext shareList, Bool allowDirect) +{ + struct glx_config *config = (struct glx_config *) fbconfig; + + return CreateContext(dpy, config->fbconfigID, config, shareList, + allowDirect, X_GLXCreateNewContext, renderType, + config->screen); +} + + +_X_EXPORT GLXDrawable +glXGetCurrentReadDrawable(void) +{ + struct glx_context *gc = __glXGetCurrentContext(); + + return gc->currentReadable; +} + + +_X_EXPORT GLXFBConfig * +glXGetFBConfigs(Display * dpy, int screen, int *nelements) +{ + struct glx_display *priv = __glXInitialize(dpy); + struct glx_config **config_list = NULL; + struct glx_config *config; + unsigned num_configs = 0; + int i; + + *nelements = 0; + if (priv && (priv->screens != NULL) + && (screen >= 0) && (screen <= ScreenCount(dpy)) + && (priv->screens[screen]->configs != NULL) + && (priv->screens[screen]->configs->fbconfigID + != (int) GLX_DONT_CARE)) { + + for (config = priv->screens[screen]->configs; config != NULL; + config = config->next) { + if (config->fbconfigID != (int) GLX_DONT_CARE) { + num_configs++; + } + } + + config_list = Xmalloc(num_configs * sizeof *config_list); + if (config_list != NULL) { + *nelements = num_configs; + i = 0; + for (config = priv->screens[screen]->configs; config != NULL; + config = config->next) { + if (config->fbconfigID != (int) GLX_DONT_CARE) { + config_list[i] = config; + i++; + } + } + } + } + + return (GLXFBConfig *) config_list; +} + + +_X_EXPORT int +glXGetFBConfigAttrib(Display * dpy, GLXFBConfig fbconfig, + int attribute, int *value) +{ + struct glx_config *config = ValidateGLXFBConfig(dpy, fbconfig); + + if (config == NULL) + return GLXBadFBConfig; + + return glx_config_get(config, attribute, value); +} + + +_X_EXPORT XVisualInfo * +glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig fbconfig) +{ + XVisualInfo visualTemplate; + struct glx_config *config = (struct glx_config *) fbconfig; + int count; + + /* + ** Get a list of all visuals, return if list is empty + */ + visualTemplate.visualid = config->visualID; + return XGetVisualInfo(dpy, VisualIDMask, &visualTemplate, &count); +} + +#ifndef GLX_USE_APPLEGL +/* +** GLX_SGI_swap_control +*/ +static int +__glXSwapIntervalSGI(int interval) +{ + xGLXVendorPrivateReq *req; + struct glx_context *gc = __glXGetCurrentContext(); + struct glx_screen *psc; + Display *dpy; + CARD32 *interval_ptr; + CARD8 opcode; + + if (gc == NULL) { + return GLX_BAD_CONTEXT; + } + + if (interval <= 0) { + return GLX_BAD_VALUE; + } + + psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen); + +#ifdef GLX_DIRECT_RENDERING + if (gc->isDirect && psc->driScreen && psc->driScreen->setSwapInterval) { + __GLXDRIdrawable *pdraw = + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable); + psc->driScreen->setSwapInterval(pdraw, interval); + return 0; + } +#endif + + dpy = gc->currentDpy; + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return 0; + } + + /* Send the glXSwapIntervalSGI request */ + LockDisplay(dpy); + GetReqExtra(GLXVendorPrivate, sizeof(CARD32), req); + req->reqType = opcode; + req->glxCode = X_GLXVendorPrivate; + req->vendorCode = X_GLXvop_SwapIntervalSGI; + req->contextTag = gc->currentContextTag; + + interval_ptr = (CARD32 *) (req + 1); + *interval_ptr = interval; + + UnlockDisplay(dpy); + SyncHandle(); + XFlush(dpy); + + return 0; +} + + +/* +** GLX_MESA_swap_control +*/ +static int +__glXSwapIntervalMESA(unsigned int interval) +{ +#ifdef GLX_DIRECT_RENDERING + struct glx_context *gc = __glXGetCurrentContext(); + + if (gc != NULL && gc->isDirect) { + struct glx_screen *psc; + + psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen); + if (psc->driScreen && psc->driScreen->setSwapInterval) { + __GLXDRIdrawable *pdraw = + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable); + return psc->driScreen->setSwapInterval(pdraw, interval); + } + } +#endif + + return GLX_BAD_CONTEXT; +} + + +static int +__glXGetSwapIntervalMESA(void) +{ +#ifdef GLX_DIRECT_RENDERING + struct glx_context *gc = __glXGetCurrentContext(); + + if (gc != NULL && gc->isDirect) { + struct glx_screen *psc; + + psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen); + if (psc->driScreen && psc->driScreen->getSwapInterval) { + __GLXDRIdrawable *pdraw = + GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable); + return psc->driScreen->getSwapInterval(pdraw); + } + } +#endif + + return 0; +} + + +/* +** GLX_SGI_video_sync +*/ +static int +__glXGetVideoSyncSGI(unsigned int *count) +{ + int64_t ust, msc, sbc; + int ret; + struct glx_context *gc = __glXGetCurrentContext(); + struct glx_screen *psc; +#ifdef GLX_DIRECT_RENDERING + __GLXDRIdrawable *pdraw; +#endif + + if (!gc) + return GLX_BAD_CONTEXT; + +#ifdef GLX_DIRECT_RENDERING + if (!gc->isDirect) + return GLX_BAD_CONTEXT; +#endif + + psc = GetGLXScreenConfigs(gc->currentDpy, gc->screen); +#ifdef GLX_DIRECT_RENDERING + pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable); +#endif + + /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry, + * FIXME: there should be a GLX encoding for this call. I can find no + * FIXME: documentation for the GLX encoding. + */ +#ifdef GLX_DIRECT_RENDERING + if (psc->driScreen && psc->driScreen->getDrawableMSC) { + ret = psc->driScreen->getDrawableMSC(psc, pdraw, &ust, &msc, &sbc); + *count = (unsigned) msc; + return (ret == True) ? 0 : GLX_BAD_CONTEXT; + } +#endif + + return GLX_BAD_CONTEXT; +} + +static int +__glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count) +{ + struct glx_context *gc = __glXGetCurrentContext(); + struct glx_screen *psc; +#ifdef GLX_DIRECT_RENDERING + __GLXDRIdrawable *pdraw; +#endif + int64_t ust, msc, sbc; + int ret; + + if (divisor <= 0 || remainder < 0) + return GLX_BAD_VALUE; + + if (!gc) + return GLX_BAD_CONTEXT; + +#ifdef GLX_DIRECT_RENDERING + if (!gc->isDirect) + return GLX_BAD_CONTEXT; +#endif + + psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen); +#ifdef GLX_DIRECT_RENDERING + pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable); +#endif + +#ifdef GLX_DIRECT_RENDERING + if (psc->driScreen && psc->driScreen->waitForMSC) { + ret = psc->driScreen->waitForMSC(pdraw, 0, divisor, remainder, &ust, &msc, + &sbc); + *count = (unsigned) msc; + return (ret == True) ? 0 : GLX_BAD_CONTEXT; + } +#endif + + return GLX_BAD_CONTEXT; +} + +#endif /* GLX_USE_APPLEGL */ + +/* +** GLX_SGIX_fbconfig +** Many of these functions are aliased to GLX 1.3 entry points in the +** GLX_functions table. +*/ + +_X_EXPORT +GLX_ALIAS(int, glXGetFBConfigAttribSGIX, + (Display * dpy, GLXFBConfigSGIX config, int attribute, int *value), + (dpy, config, attribute, value), glXGetFBConfigAttrib) + +_X_EXPORT GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX, + (Display * dpy, int screen, int *attrib_list, + int *nelements), (dpy, screen, attrib_list, nelements), + glXChooseFBConfig) + +_X_EXPORT GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX, + (Display * dpy, GLXFBConfigSGIX config), + (dpy, config), glXGetVisualFromFBConfig) + +_X_EXPORT GLXPixmap +glXCreateGLXPixmapWithConfigSGIX(Display * dpy, + GLXFBConfigSGIX fbconfig, + Pixmap pixmap) +{ +#ifndef GLX_USE_APPLEGL + xGLXVendorPrivateWithReplyReq *vpreq; + xGLXCreateGLXPixmapWithConfigSGIXReq *req; + GLXPixmap xid = None; + CARD8 opcode; + struct glx_screen *psc; +#endif + struct glx_config *config = (struct glx_config *) fbconfig; + + + if ((dpy == NULL) || (config == NULL)) { + return None; + } +#ifdef GLX_USE_APPLEGL + if(apple_glx_pixmap_create(dpy, config->screen, pixmap, config)) + return None; + return pixmap; +#else + + psc = GetGLXScreenConfigs(dpy, config->screen); + if ((psc != NULL) + && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) { + opcode = __glXSetupForCommand(dpy); + if (!opcode) { + return None; + } + + /* Send the glXCreateGLXPixmapWithConfigSGIX request */ + LockDisplay(dpy); + GetReqExtra(GLXVendorPrivateWithReply, + sz_xGLXCreateGLXPixmapWithConfigSGIXReq - + sz_xGLXVendorPrivateWithReplyReq, vpreq); + req = (xGLXCreateGLXPixmapWithConfigSGIXReq *) vpreq; + req->reqType = opcode; + req->glxCode = X_GLXVendorPrivateWithReply; + req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX; + req->screen = config->screen; + req->fbconfig = config->fbconfigID; + req->pixmap = pixmap; + req->glxpixmap = xid = XAllocID(dpy); + UnlockDisplay(dpy); + SyncHandle(); + } + + return xid; +#endif +} + +_X_EXPORT GLXContext +glXCreateContextWithConfigSGIX(Display * dpy, + GLXFBConfigSGIX fbconfig, int renderType, + GLXContext shareList, Bool allowDirect) +{ + GLXContext gc = NULL; + struct glx_config *config = (struct glx_config *) fbconfig; + struct glx_screen *psc; + + + if ((dpy == NULL) || (config == NULL)) { + return None; + } + + psc = GetGLXScreenConfigs(dpy, config->screen); + if ((psc != NULL) + && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) { + gc = CreateContext(dpy, config->fbconfigID, config, shareList, + allowDirect, + X_GLXvop_CreateContextWithConfigSGIX, renderType, + config->screen); + } + + return gc; +} + + +_X_EXPORT GLXFBConfigSGIX +glXGetFBConfigFromVisualSGIX(Display * dpy, XVisualInfo * vis) +{ + struct glx_display *priv; + struct glx_screen *psc = NULL; + + if ((GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc) != Success) + && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit) + && (psc->configs->fbconfigID != (int) GLX_DONT_CARE)) { + return (GLXFBConfigSGIX) glx_config_find_visual(psc->configs, + vis->visualid); + } + + return NULL; +} + +#ifndef GLX_USE_APPLEGL +/* +** GLX_SGIX_swap_group +*/ +static void +__glXJoinSwapGroupSGIX(Display * dpy, GLXDrawable drawable, + GLXDrawable member) +{ + (void) dpy; + (void) drawable; + (void) member; +} + + +/* +** GLX_SGIX_swap_barrier +*/ +static void +__glXBindSwapBarrierSGIX(Display * dpy, GLXDrawable drawable, int barrier) +{ + (void) dpy; + (void) drawable; + (void) barrier; +} + +static Bool +__glXQueryMaxSwapBarriersSGIX(Display * dpy, int screen, int *max) +{ + (void) dpy; + (void) screen; + (void) max; + return False; +} + + +/* +** GLX_OML_sync_control +*/ +static Bool +__glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable, + int64_t * ust, int64_t * msc, int64_t * sbc) +{ + struct glx_display * const priv = __glXInitialize(dpy); + int ret; +#ifdef GLX_DIRECT_RENDERING + __GLXDRIdrawable *pdraw; +#endif + struct glx_screen *psc; + + if (!priv) + return False; + +#ifdef GLX_DIRECT_RENDERING + pdraw = GetGLXDRIDrawable(dpy, drawable); + psc = pdraw ? pdraw->psc : NULL; + if (pdraw && psc->driScreen->getDrawableMSC) { + ret = psc->driScreen->getDrawableMSC(psc, pdraw, ust, msc, sbc); + return ret; + } +#endif + + return False; +} + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +_X_HIDDEN GLboolean +__glxGetMscRate(__GLXDRIdrawable *glxDraw, + int32_t * numerator, int32_t * denominator) +{ +#ifdef XF86VIDMODE + struct glx_screen *psc; + XF86VidModeModeLine mode_line; + int dot_clock; + int i; + + psc = glxDraw->psc; + if (XF86VidModeQueryVersion(psc->dpy, &i, &i) && + XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line)) { + unsigned n = dot_clock * 1000; + unsigned d = mode_line.vtotal * mode_line.htotal; + +# define V_INTERLACE 0x010 +# define V_DBLSCAN 0x020 + + if (mode_line.flags & V_INTERLACE) + n *= 2; + else if (mode_line.flags & V_DBLSCAN) + d *= 2; + + /* The OML_sync_control spec requires that if the refresh rate is a + * whole number, that the returned numerator be equal to the refresh + * rate and the denominator be 1. + */ + + if (n % d == 0) { + n /= d; + d = 1; + } + else { + static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 }; + + /* This is a poor man's way to reduce a fraction. It's far from + * perfect, but it will work well enough for this situation. + */ + + for (i = 0; f[i] != 0; i++) { + while (n % f[i] == 0 && d % f[i] == 0) { + d /= f[i]; + n /= f[i]; + } + } + } + + *numerator = n; + *denominator = d; + + return True; + } + else +#endif + + return False; +} +#endif + +/** + * Determine the refresh rate of the specified drawable and display. + * + * \param dpy Display whose refresh rate is to be determined. + * \param drawable Drawable whose refresh rate is to be determined. + * \param numerator Numerator of the refresh rate. + * \param demoninator Denominator of the refresh rate. + * \return If the refresh rate for the specified display and drawable could + * be calculated, True is returned. Otherwise False is returned. + * + * \note This function is implemented entirely client-side. A lot of other + * functionality is required to export GLX_OML_sync_control, so on + * XFree86 this function can be called for direct-rendering contexts + * when GLX_OML_sync_control appears in the client extension string. + */ + +_X_HIDDEN GLboolean +__glXGetMscRateOML(Display * dpy, GLXDrawable drawable, + int32_t * numerator, int32_t * denominator) +{ +#if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE ) + __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable); + + if (draw == NULL) + return False; + + return __glxGetMscRate(draw, numerator, denominator); +#else + (void) dpy; + (void) drawable; + (void) numerator; + (void) denominator; +#endif + return False; +} + + +static int64_t +__glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable, + int64_t target_msc, int64_t divisor, int64_t remainder) +{ + struct glx_context *gc = __glXGetCurrentContext(); +#ifdef GLX_DIRECT_RENDERING + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable); + struct glx_screen *psc = pdraw ? pdraw->psc : NULL; +#endif + + if (!gc) /* no GLX for this */ + return -1; + +#ifdef GLX_DIRECT_RENDERING + if (!pdraw || !gc->isDirect) + return -1; +#endif + + /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE + * error", but it also says "It [glXSwapBuffersMscOML] will return a value + * of -1 if the function failed because of errors detected in the input + * parameters" + */ + if (divisor < 0 || remainder < 0 || target_msc < 0) + return -1; + if (divisor > 0 && remainder >= divisor) + return -1; + + if (target_msc == 0 && divisor == 0 && remainder == 0) + remainder = 1; + +#ifdef GLX_DIRECT_RENDERING + if (psc->driScreen && psc->driScreen->swapBuffers) + return (*psc->driScreen->swapBuffers)(pdraw, target_msc, divisor, + remainder); +#endif + + return -1; +} + + +static Bool +__glXWaitForMscOML(Display * dpy, GLXDrawable drawable, + int64_t target_msc, int64_t divisor, + int64_t remainder, int64_t * ust, + int64_t * msc, int64_t * sbc) +{ +#ifdef GLX_DIRECT_RENDERING + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable); + struct glx_screen *psc = pdraw ? pdraw->psc : NULL; + int ret; +#endif + + + /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE + * error", but the return type in the spec is Bool. + */ + if (divisor < 0 || remainder < 0 || target_msc < 0) + return False; + if (divisor > 0 && remainder >= divisor) + return False; + +#ifdef GLX_DIRECT_RENDERING + if (pdraw && psc->driScreen && psc->driScreen->waitForMSC) { + ret = psc->driScreen->waitForMSC(pdraw, target_msc, divisor, remainder, + ust, msc, sbc); + return ret; + } +#endif + + return False; +} + + +static Bool +__glXWaitForSbcOML(Display * dpy, GLXDrawable drawable, + int64_t target_sbc, int64_t * ust, + int64_t * msc, int64_t * sbc) +{ +#ifdef GLX_DIRECT_RENDERING + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable); + struct glx_screen *psc = pdraw ? pdraw->psc : NULL; + int ret; +#endif + + /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE + * error", but the return type in the spec is Bool. + */ + if (target_sbc < 0) + return False; + +#ifdef GLX_DIRECT_RENDERING + if (pdraw && psc->driScreen && psc->driScreen->waitForSBC) { + ret = psc->driScreen->waitForSBC(pdraw, target_sbc, ust, msc, sbc); + return ret; + } +#endif + + return False; +} + +/*@}*/ + + +/** + * Mesa extension stubs. These will help reduce portability problems. + */ +/*@{*/ + +/** + * Release all buffers associated with the specified GLX drawable. + * + * \todo + * This function was intended for stand-alone Mesa. The issue there is that + * the library doesn't get any notification when a window is closed. In + * DRI there is a similar but slightly different issue. When GLX 1.3 is + * supported, there are 3 different functions to destroy a drawable. It + * should be possible to create GLX protocol (or have it determine which + * protocol to use based on the type of the drawable) to have one function + * do the work of 3. For the direct-rendering case, this function could + * just call the driver's \c __DRIdrawableRec::destroyDrawable function. + * This would reduce the frequency with which \c __driGarbageCollectDrawables + * would need to be used. This really should be done as part of the new DRI + * interface work. + * + * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt + * __driGarbageCollectDrawables + * glXDestroyGLXPixmap + * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow + * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX + */ +static Bool +__glXReleaseBuffersMESA(Display * dpy, GLXDrawable d) +{ + (void) dpy; + (void) d; + return False; +} + + +_X_EXPORT GLXPixmap +glXCreateGLXPixmapMESA(Display * dpy, XVisualInfo * visual, + Pixmap pixmap, Colormap cmap) +{ + (void) dpy; + (void) visual; + (void) pixmap; + (void) cmap; + return 0; +} + +/*@}*/ + + +/** + * GLX_MESA_copy_sub_buffer + */ +#define X_GLXvop_CopySubBufferMESA 5154 /* temporary */ +static void +__glXCopySubBufferMESA(Display * dpy, GLXDrawable drawable, + int x, int y, int width, int height) +{ + xGLXVendorPrivateReq *req; + struct glx_context *gc; + GLXContextTag tag; + CARD32 *drawable_ptr; + INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr; + CARD8 opcode; + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable); + if (pdraw != NULL) { + struct glx_screen *psc = pdraw->psc; + if (psc->driScreen->copySubBuffer != NULL) { + glFlush(); + (*psc->driScreen->copySubBuffer) (pdraw, x, y, width, height); + } + + return; + } +#endif + + opcode = __glXSetupForCommand(dpy); + if (!opcode) + return; + + /* + ** The calling thread may or may not have a current context. If it + ** does, send the context tag so the server can do a flush. + */ + gc = __glXGetCurrentContext(); + if ((gc != NULL) && (dpy == gc->currentDpy) && + ((drawable == gc->currentDrawable) || + (drawable == gc->currentReadable))) { + tag = gc->currentContextTag; + } + else { + tag = 0; + } + + LockDisplay(dpy); + GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4, req); + req->reqType = opcode; + req->glxCode = X_GLXVendorPrivate; + req->vendorCode = X_GLXvop_CopySubBufferMESA; + req->contextTag = tag; + + drawable_ptr = (CARD32 *) (req + 1); + x_ptr = (INT32 *) (drawable_ptr + 1); + y_ptr = (INT32 *) (drawable_ptr + 2); + w_ptr = (INT32 *) (drawable_ptr + 3); + h_ptr = (INT32 *) (drawable_ptr + 4); + + *drawable_ptr = drawable; + *x_ptr = x; + *y_ptr = y; + *w_ptr = width; + *h_ptr = height; + + UnlockDisplay(dpy); + SyncHandle(); +} + +/*@{*/ +static void +__glXBindTexImageEXT(Display * dpy, + GLXDrawable drawable, int buffer, const int *attrib_list) +{ + struct glx_context *gc = __glXGetCurrentContext(); + + if (gc == NULL || gc->vtable->bind_tex_image == NULL) + return; + + gc->vtable->bind_tex_image(dpy, drawable, buffer, attrib_list); +} + +static void +__glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer) +{ + struct glx_context *gc = __glXGetCurrentContext(); + + if (gc == NULL || gc->vtable->release_tex_image == NULL) + return; + + gc->vtable->release_tex_image(dpy, drawable, buffer); +} + +/*@}*/ + +#endif /* GLX_USE_APPLEGL */ + +/** + * \c strdup is actually not a standard ANSI C or POSIX routine. + * Irix will not define it if ANSI mode is in effect. + * + * \sa strdup + */ +_X_HIDDEN char * +__glXstrdup(const char *str) +{ + char *copy; + copy = (char *) Xmalloc(strlen(str) + 1); + if (!copy) + return NULL; + strcpy(copy, str); + return copy; +} + +/* +** glXGetProcAddress support +*/ + +struct name_address_pair +{ + const char *Name; + GLvoid *Address; +}; + +#define GLX_FUNCTION(f) { # f, (GLvoid *) f } +#define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f } + +static const struct name_address_pair GLX_functions[] = { + /*** GLX_VERSION_1_0 ***/ + GLX_FUNCTION(glXChooseVisual), + GLX_FUNCTION(glXCopyContext), + GLX_FUNCTION(glXCreateContext), + GLX_FUNCTION(glXCreateGLXPixmap), + GLX_FUNCTION(glXDestroyContext), + GLX_FUNCTION(glXDestroyGLXPixmap), + GLX_FUNCTION(glXGetConfig), + GLX_FUNCTION(glXGetCurrentContext), + GLX_FUNCTION(glXGetCurrentDrawable), + GLX_FUNCTION(glXIsDirect), + GLX_FUNCTION(glXMakeCurrent), + GLX_FUNCTION(glXQueryExtension), + GLX_FUNCTION(glXQueryVersion), + GLX_FUNCTION(glXSwapBuffers), + GLX_FUNCTION(glXUseXFont), + GLX_FUNCTION(glXWaitGL), + GLX_FUNCTION(glXWaitX), + + /*** GLX_VERSION_1_1 ***/ + GLX_FUNCTION(glXGetClientString), + GLX_FUNCTION(glXQueryExtensionsString), + GLX_FUNCTION(glXQueryServerString), + + /*** GLX_VERSION_1_2 ***/ + GLX_FUNCTION(glXGetCurrentDisplay), + + /*** GLX_VERSION_1_3 ***/ + GLX_FUNCTION(glXChooseFBConfig), + GLX_FUNCTION(glXCreateNewContext), + GLX_FUNCTION(glXCreatePbuffer), + GLX_FUNCTION(glXCreatePixmap), + GLX_FUNCTION(glXCreateWindow), + GLX_FUNCTION(glXDestroyPbuffer), + GLX_FUNCTION(glXDestroyPixmap), + GLX_FUNCTION(glXDestroyWindow), + GLX_FUNCTION(glXGetCurrentReadDrawable), + GLX_FUNCTION(glXGetFBConfigAttrib), + GLX_FUNCTION(glXGetFBConfigs), + GLX_FUNCTION(glXGetSelectedEvent), + GLX_FUNCTION(glXGetVisualFromFBConfig), + GLX_FUNCTION(glXMakeContextCurrent), + GLX_FUNCTION(glXQueryContext), + GLX_FUNCTION(glXQueryDrawable), + GLX_FUNCTION(glXSelectEvent), + +#ifndef GLX_USE_APPLEGL + /*** GLX_SGI_swap_control ***/ + GLX_FUNCTION2(glXSwapIntervalSGI, __glXSwapIntervalSGI), + + /*** GLX_SGI_video_sync ***/ + GLX_FUNCTION2(glXGetVideoSyncSGI, __glXGetVideoSyncSGI), + GLX_FUNCTION2(glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI), + + /*** GLX_SGI_make_current_read ***/ + GLX_FUNCTION2(glXMakeCurrentReadSGI, glXMakeContextCurrent), + GLX_FUNCTION2(glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable), + + /*** GLX_EXT_import_context ***/ + GLX_FUNCTION(glXFreeContextEXT), + GLX_FUNCTION(glXGetContextIDEXT), + GLX_FUNCTION2(glXGetCurrentDisplayEXT, glXGetCurrentDisplay), + GLX_FUNCTION(glXImportContextEXT), + GLX_FUNCTION2(glXQueryContextInfoEXT, glXQueryContext), +#endif + + /*** GLX_SGIX_fbconfig ***/ + GLX_FUNCTION2(glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib), + GLX_FUNCTION2(glXChooseFBConfigSGIX, glXChooseFBConfig), + GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX), + GLX_FUNCTION(glXCreateContextWithConfigSGIX), + GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig), + GLX_FUNCTION(glXGetFBConfigFromVisualSGIX), + +#ifndef GLX_USE_APPLEGL + /*** GLX_SGIX_pbuffer ***/ + GLX_FUNCTION(glXCreateGLXPbufferSGIX), + GLX_FUNCTION(glXDestroyGLXPbufferSGIX), + GLX_FUNCTION(glXQueryGLXPbufferSGIX), + GLX_FUNCTION(glXSelectEventSGIX), + GLX_FUNCTION(glXGetSelectedEventSGIX), + + /*** GLX_SGIX_swap_group ***/ + GLX_FUNCTION2(glXJoinSwapGroupSGIX, __glXJoinSwapGroupSGIX), + + /*** GLX_SGIX_swap_barrier ***/ + GLX_FUNCTION2(glXBindSwapBarrierSGIX, __glXBindSwapBarrierSGIX), + GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX, __glXQueryMaxSwapBarriersSGIX), + + /*** GLX_MESA_copy_sub_buffer ***/ + GLX_FUNCTION2(glXCopySubBufferMESA, __glXCopySubBufferMESA), + + /*** GLX_MESA_pixmap_colormap ***/ + GLX_FUNCTION(glXCreateGLXPixmapMESA), + + /*** GLX_MESA_release_buffers ***/ + GLX_FUNCTION2(glXReleaseBuffersMESA, __glXReleaseBuffersMESA), + + /*** GLX_MESA_swap_control ***/ + GLX_FUNCTION2(glXSwapIntervalMESA, __glXSwapIntervalMESA), + GLX_FUNCTION2(glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA), +#endif + + /*** GLX_ARB_get_proc_address ***/ + GLX_FUNCTION(glXGetProcAddressARB), + + /*** GLX 1.4 ***/ + GLX_FUNCTION2(glXGetProcAddress, glXGetProcAddressARB), + +#ifndef GLX_USE_APPLEGL + /*** GLX_OML_sync_control ***/ + GLX_FUNCTION2(glXWaitForSbcOML, __glXWaitForSbcOML), + GLX_FUNCTION2(glXWaitForMscOML, __glXWaitForMscOML), + GLX_FUNCTION2(glXSwapBuffersMscOML, __glXSwapBuffersMscOML), + GLX_FUNCTION2(glXGetMscRateOML, __glXGetMscRateOML), + GLX_FUNCTION2(glXGetSyncValuesOML, __glXGetSyncValuesOML), + + /*** GLX_EXT_texture_from_pixmap ***/ + GLX_FUNCTION2(glXBindTexImageEXT, __glXBindTexImageEXT), + GLX_FUNCTION2(glXReleaseTexImageEXT, __glXReleaseTexImageEXT), +#endif + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + /*** DRI configuration ***/ + GLX_FUNCTION(glXGetScreenDriver), + GLX_FUNCTION(glXGetDriverConfig), +#endif + + {NULL, NULL} /* end of list */ +}; + +#ifndef GLX_USE_APPLEGL +static const GLvoid * +get_glx_proc_address(const char *funcName) +{ + GLuint i; + + /* try static functions */ + for (i = 0; GLX_functions[i].Name; i++) { + if (strcmp(GLX_functions[i].Name, funcName) == 0) + return GLX_functions[i].Address; + } + + return NULL; +} +#endif + +/** + * Get the address of a named GL function. This is the pre-GLX 1.4 name for + * \c glXGetProcAddress. + * + * \param procName Name of a GL or GLX function. + * \returns A pointer to the named function + * + * \sa glXGetProcAddress + */ +_X_EXPORT void (*glXGetProcAddressARB(const GLubyte * procName)) (void) +{ + typedef void (*gl_function) (void); + gl_function f; + + + /* Search the table of GLX and internal functions first. If that + * fails and the supplied name could be a valid core GL name, try + * searching the core GL function table. This check is done to prevent + * DRI based drivers from searching the core GL function table for + * internal API functions. + */ +#ifdef GLX_USE_APPLEGL + f = (gl_function) apple_glx_get_proc_address(procName); +#else + f = (gl_function) get_glx_proc_address((const char *) procName); + if ((f == NULL) && (procName[0] == 'g') && (procName[1] == 'l') + && (procName[2] != 'X')) { + f = (gl_function) _glapi_get_proc_address((const char *) procName); + } +#endif + return f; +} + +/** + * Get the address of a named GL function. This is the GLX 1.4 name for + * \c glXGetProcAddressARB. + * + * \param procName Name of a GL or GLX function. + * \returns A pointer to the named function + * + * \sa glXGetProcAddressARB + */ +_X_EXPORT void (*glXGetProcAddress(const GLubyte * procName)) (void) +#if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED) + __attribute__ ((alias("glXGetProcAddressARB"))); +#else +{ + return glXGetProcAddressARB(procName); +} +#endif /* __GNUC__ */ + + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +/** + * Get the unadjusted system time (UST). Currently, the UST is measured in + * microseconds since Epoc. The actual resolution of the UST may vary from + * system to system, and the units may vary from release to release. + * Drivers should not call this function directly. They should instead use + * \c glXGetProcAddress to obtain a pointer to the function. + * + * \param ust Location to store the 64-bit UST + * \returns Zero on success or a negative errno value on failure. + * + * \sa glXGetProcAddress, PFNGLXGETUSTPROC + * + * \since Internal API version 20030317. + */ +_X_HIDDEN int +__glXGetUST(int64_t * ust) +{ + struct timeval tv; + + if (ust == NULL) { + return -EFAULT; + } + + if (gettimeofday(&tv, NULL) == 0) { + ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec; + return 0; + } + else { + return -errno; + } +} +#endif /* GLX_DIRECT_RENDERING */ diff --git a/src/glx/glxconfig.c b/src/glx/glxconfig.c new file mode 100644 index 0000000..1d9678f --- /dev/null +++ b/src/glx/glxconfig.c @@ -0,0 +1,304 @@ +/* + * (C) Copyright IBM Corporation 2003 + * 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 + * 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 + * VA LINUX SYSTEM, IBM 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. + */ + +/** + * \file glxconfig.c + * Utility routines for working with \c struct glx_config structures. At + * some point most or all of these functions will be moved to the Mesa + * code base. + * + * \author Ian Romanick + */ + +#include +#include "GL/glxint.h" +#include +#include + +#include "glxconfig.h" + +#define NUM_VISUAL_TYPES 6 + +/** + * Get data from a GLX config + * + * \param mode GL context mode whose data is to be returned. + * \param attribute Attribute of \c mode that is to be returned. + * \param value_return Location to store the data member of \c mode. + * \return If \c attribute is a valid attribute of \c mode, zero is + * returned. Otherwise \c GLX_BAD_ATTRIBUTE is returned. + */ +_X_HIDDEN int +glx_config_get(struct glx_config * mode, int attribute, int *value_return) +{ + switch (attribute) { + case GLX_USE_GL: + *value_return = GL_TRUE; + return 0; + case GLX_BUFFER_SIZE: + *value_return = mode->rgbBits; + return 0; + case GLX_RGBA: + *value_return = mode->rgbMode; + return 0; + case GLX_RED_SIZE: + *value_return = mode->redBits; + return 0; + case GLX_GREEN_SIZE: + *value_return = mode->greenBits; + return 0; + case GLX_BLUE_SIZE: + *value_return = mode->blueBits; + return 0; + case GLX_ALPHA_SIZE: + *value_return = mode->alphaBits; + return 0; + case GLX_DOUBLEBUFFER: + *value_return = mode->doubleBufferMode; + return 0; + case GLX_STEREO: + *value_return = mode->stereoMode; + return 0; + case GLX_AUX_BUFFERS: + *value_return = mode->numAuxBuffers; + return 0; + case GLX_DEPTH_SIZE: + *value_return = mode->depthBits; + return 0; + case GLX_STENCIL_SIZE: + *value_return = mode->stencilBits; + return 0; + case GLX_ACCUM_RED_SIZE: + *value_return = mode->accumRedBits; + return 0; + case GLX_ACCUM_GREEN_SIZE: + *value_return = mode->accumGreenBits; + return 0; + case GLX_ACCUM_BLUE_SIZE: + *value_return = mode->accumBlueBits; + return 0; + case GLX_ACCUM_ALPHA_SIZE: + *value_return = mode->accumAlphaBits; + return 0; + case GLX_LEVEL: + *value_return = mode->level; + return 0; +#ifndef GLX_USE_APPLEGL /* This isn't supported by CGL. */ + case GLX_TRANSPARENT_TYPE_EXT: + *value_return = mode->transparentPixel; + return 0; +#endif + case GLX_TRANSPARENT_RED_VALUE: + *value_return = mode->transparentRed; + return 0; + case GLX_TRANSPARENT_GREEN_VALUE: + *value_return = mode->transparentGreen; + return 0; + case GLX_TRANSPARENT_BLUE_VALUE: + *value_return = mode->transparentBlue; + return 0; + case GLX_TRANSPARENT_ALPHA_VALUE: + *value_return = mode->transparentAlpha; + return 0; + case GLX_TRANSPARENT_INDEX_VALUE: + *value_return = mode->transparentIndex; + return 0; + case GLX_X_VISUAL_TYPE: + *value_return = mode->visualType; + return 0; + case GLX_CONFIG_CAVEAT: + *value_return = mode->visualRating; + return 0; + case GLX_VISUAL_ID: + *value_return = mode->visualID; + return 0; + case GLX_DRAWABLE_TYPE: + *value_return = mode->drawableType; + return 0; + case GLX_RENDER_TYPE: + *value_return = mode->renderType; + return 0; + case GLX_X_RENDERABLE: + *value_return = mode->xRenderable; + return 0; + case GLX_FBCONFIG_ID: + *value_return = mode->fbconfigID; + return 0; + case GLX_MAX_PBUFFER_WIDTH: + *value_return = mode->maxPbufferWidth; + return 0; + case GLX_MAX_PBUFFER_HEIGHT: + *value_return = mode->maxPbufferHeight; + return 0; + case GLX_MAX_PBUFFER_PIXELS: + *value_return = mode->maxPbufferPixels; + return 0; +#ifndef GLX_USE_APPLEGL /* These aren't supported by CGL. */ + case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX: + *value_return = mode->optimalPbufferWidth; + return 0; + case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX: + *value_return = mode->optimalPbufferHeight; + return 0; + case GLX_SWAP_METHOD_OML: + *value_return = mode->swapMethod; + return 0; +#endif + case GLX_SAMPLE_BUFFERS_SGIS: + *value_return = mode->sampleBuffers; + return 0; + case GLX_SAMPLES_SGIS: + *value_return = mode->samples; + return 0; + case GLX_BIND_TO_TEXTURE_RGB_EXT: + *value_return = mode->bindToTextureRgb; + return 0; + case GLX_BIND_TO_TEXTURE_RGBA_EXT: + *value_return = mode->bindToTextureRgba; + return 0; + case GLX_BIND_TO_MIPMAP_TEXTURE_EXT: + *value_return = mode->bindToMipmapTexture == GL_TRUE ? GL_TRUE : + GL_FALSE; + return 0; + case GLX_BIND_TO_TEXTURE_TARGETS_EXT: + *value_return = mode->bindToTextureTargets; + return 0; + case GLX_Y_INVERTED_EXT: + *value_return = mode->yInverted; + return 0; + + /* Applications are NOT allowed to query GLX_VISUAL_SELECT_GROUP_SGIX. + * It is ONLY for communication between the GLX client and the GLX + * server. + */ + case GLX_VISUAL_SELECT_GROUP_SGIX: + default: + return GLX_BAD_ATTRIBUTE; + } +} + + +/** + * Allocate a linked list of \c struct glx_config structures. The fields of + * each structure will be initialized to "reasonable" default values. In + * most cases this is the default value defined by table 3.4 of the GLX + * 1.3 specification. This means that most values are either initialized to + * zero or \c GLX_DONT_CARE (which is -1). As support for additional + * extensions is added, the new values will be initialized to appropriate + * values from the extension specification. + * + * \param count Number of structures to allocate. + * \param minimum_size Minimum size of a structure to allocate. This allows + * for differences in the version of the + * \c struct glx_config stucture used in libGL and in a + * DRI-based driver. + * \returns A pointer to the first element in a linked list of \c count + * stuctures on success, or \c NULL on failure. + */ +_X_HIDDEN struct glx_config * +glx_config_create_list(unsigned count) +{ + const size_t size = sizeof(struct glx_config); + struct glx_config *base = NULL; + struct glx_config **next; + unsigned i; + + next = &base; + for (i = 0; i < count; i++) { + *next = (struct glx_config *) malloc(size); + if (*next == NULL) { + glx_config_destroy_list(base); + base = NULL; + break; + } + + (void) memset(*next, 0, size); + (*next)->visualID = GLX_DONT_CARE; + (*next)->visualType = GLX_DONT_CARE; + (*next)->visualRating = GLX_NONE; + (*next)->transparentPixel = GLX_NONE; + (*next)->transparentRed = GLX_DONT_CARE; + (*next)->transparentGreen = GLX_DONT_CARE; + (*next)->transparentBlue = GLX_DONT_CARE; + (*next)->transparentAlpha = GLX_DONT_CARE; + (*next)->transparentIndex = GLX_DONT_CARE; + (*next)->xRenderable = GLX_DONT_CARE; + (*next)->fbconfigID = GLX_DONT_CARE; + (*next)->swapMethod = GLX_SWAP_UNDEFINED_OML; + (*next)->bindToTextureRgb = GLX_DONT_CARE; + (*next)->bindToTextureRgba = GLX_DONT_CARE; + (*next)->bindToMipmapTexture = GLX_DONT_CARE; + (*next)->bindToTextureTargets = GLX_DONT_CARE; + (*next)->yInverted = GLX_DONT_CARE; + + next = &((*next)->next); + } + + return base; +} + +_X_HIDDEN void +glx_config_destroy_list(struct glx_config *configs) +{ + while (configs != NULL) { + struct glx_config *const next = configs->next; + + free(configs); + configs = next; + } +} + + +/** + * Find a context mode matching a Visual ID. + * + * \param modes List list of context-mode structures to be searched. + * \param vid Visual ID to be found. + * \returns A pointer to a context-mode in \c modes if \c vid was found in + * the list, or \c NULL if it was not. + */ + +_X_HIDDEN struct glx_config * +glx_config_find_visual(struct glx_config *configs, int vid) +{ + struct glx_config *c; + + for (c = configs; c != NULL; c = c->next) + if (c->visualID == vid) + return c; + + return NULL; +} + +_X_HIDDEN struct glx_config * +glx_config_find_fbconfig(struct glx_config *configs, int fbid) +{ + struct glx_config *c; + + for (c = configs; c != NULL; c = c->next) + if (c->fbconfigID == fbid) + return c; + + return NULL; +} diff --git a/src/glx/glxconfig.h b/src/glx/glxconfig.h new file mode 100644 index 0000000..f7ee958 --- /dev/null +++ b/src/glx/glxconfig.h @@ -0,0 +1,133 @@ +/* + * (C) Copyright IBM Corporation 2003 + * 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 + * 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 + * VA LINUX SYSTEM, IBM 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. + */ + +/** + * \file glcontextmodes.h + * \author Ian Romanick + */ + +#ifndef GLCONTEXTMODES_H +#define GLCONTEXTMODES_H + +struct glx_config { + struct glx_config * next; + + GLboolean rgbMode; + GLboolean floatMode; + GLboolean colorIndexMode; + GLuint doubleBufferMode; + GLuint stereoMode; + + GLint redBits, greenBits, blueBits, alphaBits; /* bits per comp */ + GLuint redMask, greenMask, blueMask, alphaMask; + GLint rgbBits; /* total bits for rgb */ + GLint indexBits; /* total bits for colorindex */ + + GLint accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits; + GLint depthBits; + GLint stencilBits; + + GLint numAuxBuffers; + + GLint level; + + GLint pixmapMode; + + /* GLX */ + GLint visualID; + GLint visualType; /**< One of the GLX X visual types. (i.e., + * \c GLX_TRUE_COLOR, etc.) + */ + + /* EXT_visual_rating / GLX 1.2 */ + GLint visualRating; + + /* EXT_visual_info / GLX 1.2 */ + GLint transparentPixel; + /* colors are floats scaled to ints */ + GLint transparentRed, transparentGreen, transparentBlue, transparentAlpha; + GLint transparentIndex; + + /* ARB_multisample / SGIS_multisample */ + GLint sampleBuffers; + GLint samples; + + /* SGIX_fbconfig / GLX 1.3 */ + GLint drawableType; + GLint renderType; + GLint xRenderable; + GLint fbconfigID; + + /* SGIX_pbuffer / GLX 1.3 */ + GLint maxPbufferWidth; + GLint maxPbufferHeight; + GLint maxPbufferPixels; + GLint optimalPbufferWidth; /* Only for SGIX_pbuffer. */ + GLint optimalPbufferHeight; /* Only for SGIX_pbuffer. */ + + /* SGIX_visual_select_group */ + GLint visualSelectGroup; + + /* OML_swap_method */ + GLint swapMethod; + + GLint screen; + + /* EXT_texture_from_pixmap */ + GLint bindToTextureRgb; + GLint bindToTextureRgba; + GLint bindToMipmapTexture; + GLint bindToTextureTargets; + GLint yInverted; +}; + +#define __GLX_MIN_CONFIG_PROPS 18 +#define __GLX_MAX_CONFIG_PROPS 500 +#define __GLX_EXT_CONFIG_PROPS 10 + +/* +** Since we send all non-core visual properties as token, value pairs, +** we require 2 words across the wire. In order to maintain backwards +** compatibility, we need to send the total number of words that the +** VisualConfigs are sent back in so old libraries can simply "ignore" +** the new properties. +*/ +#define __GLX_TOTAL_CONFIG \ + (__GLX_MIN_CONFIG_PROPS + 2 * __GLX_EXT_CONFIG_PROPS) + +extern GLint _gl_convert_from_x_visual_type(int visualType); + +extern int +glx_config_get(struct glx_config * mode, int attribute, int *value_return); +extern struct glx_config * +glx_config_create_list(unsigned count); +extern void +glx_config_destroy_list(struct glx_config *configs); +extern struct glx_config * +glx_config_find_visual(struct glx_config *configs, int vid); +extern struct glx_config * +glx_config_find_fbconfig(struct glx_config *configs, int fbid); + +#endif /* GLCONTEXTMODES_H */ + diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c new file mode 100644 index 0000000..3631738 --- /dev/null +++ b/src/glx/glxcurrent.c @@ -0,0 +1,298 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/** + * \file glxcurrent.c + * Client-side GLX interface for current context management. + */ + +#ifdef PTHREADS +#include +#endif + +#include "glxclient.h" +#ifdef GLX_USE_APPLEGL +#include + +#include "apple_glx.h" +#include "apple_glx_context.h" +#else +#include "glapi.h" +#endif + +/* +** We setup some dummy structures here so that the API can be used +** even if no context is current. +*/ + +static GLubyte dummyBuffer[__GLX_BUFFER_LIMIT_SIZE]; +static struct glx_context_vtable dummyVtable; +/* +** Dummy context used by small commands when there is no current context. +** All the +** gl and glx entry points are designed to operate as nop's when using +** the dummy context structure. +*/ +struct glx_context dummyContext = { + &dummyBuffer[0], + &dummyBuffer[0], + &dummyBuffer[0], + &dummyBuffer[__GLX_BUFFER_LIMIT_SIZE], + sizeof(dummyBuffer), + &dummyVtable +}; + +/* + * Current context management and locking + */ + +#if defined( PTHREADS ) + +_X_HIDDEN pthread_mutex_t __glXmutex = PTHREAD_MUTEX_INITIALIZER; + +# if defined( GLX_USE_TLS ) + +/** + * Per-thread GLX context pointer. + * + * \c __glXSetCurrentContext is written is such a way that this pointer can + * \b never be \c NULL. This is important! Because of this + * \c __glXGetCurrentContext can be implemented as trivial macro. + */ +__thread void *__glX_tls_Context __attribute__ ((tls_model("initial-exec"))) + = &dummyContext; + +_X_HIDDEN void +__glXSetCurrentContext(struct glx_context * c) +{ + __glX_tls_Context = (c != NULL) ? c : &dummyContext; +} + +# else + +static pthread_once_t once_control = PTHREAD_ONCE_INIT; + +/** + * Per-thread data key. + * + * Once \c init_thread_data has been called, the per-thread data key will + * take a value of \c NULL. As each new thread is created the default + * value, in that thread, will be \c NULL. + */ +static pthread_key_t ContextTSD; + +/** + * Initialize the per-thread data key. + * + * This function is called \b exactly once per-process (not per-thread!) to + * initialize the per-thread data key. This is ideally done using the + * \c pthread_once mechanism. + */ +static void +init_thread_data(void) +{ + if (pthread_key_create(&ContextTSD, NULL) != 0) { + perror("pthread_key_create"); + exit(-1); + } +} + +_X_HIDDEN void +__glXSetCurrentContext(struct glx_context * c) +{ + pthread_once(&once_control, init_thread_data); + pthread_setspecific(ContextTSD, c); +} + +_X_HIDDEN struct glx_context * +__glXGetCurrentContext(void) +{ + void *v; + + pthread_once(&once_control, init_thread_data); + + v = pthread_getspecific(ContextTSD); + return (v == NULL) ? &dummyContext : (struct glx_context *) v; +} + +# endif /* defined( GLX_USE_TLS ) */ + +#elif defined( THREADS ) + +#error Unknown threading method specified. + +#else + +/* not thread safe */ +_X_HIDDEN struct glx_context *__glXcurrentContext = &dummyContext; + +#endif + + +_X_HIDDEN void +__glXSetCurrentContextNull(void) +{ + __glXSetCurrentContext(&dummyContext); +#ifndef GLX_USE_APPLEGL +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + _glapi_set_dispatch(NULL); /* no-op functions */ + _glapi_set_context(NULL); +#endif +#endif +} + +_X_EXPORT GLXContext +glXGetCurrentContext(void) +{ + struct glx_context *cx = __glXGetCurrentContext(); + + if (cx == &dummyContext) { + return NULL; + } + else { + return (GLXContext) cx; + } +} + +_X_EXPORT GLXDrawable +glXGetCurrentDrawable(void) +{ + struct glx_context *gc = __glXGetCurrentContext(); + return gc->currentDrawable; +} + +static void +__glXGenerateError(Display * dpy, struct glx_context *gc, XID resource, + BYTE errorCode, CARD16 minorCode) +{ + xError error; + + error.errorCode = errorCode; + error.resourceID = resource; + error.sequenceNumber = dpy->request; + error.type = X_Error; + error.majorCode = gc->majorOpcode; + error.minorCode = minorCode; + _XError(dpy, &error); +} + +/** + * Make a particular context current. + * + * \note This is in this file so that it can access dummyContext. + */ +static Bool +MakeContextCurrent(Display * dpy, GLXDrawable draw, + GLXDrawable read, GLXContext gc_user) +{ + struct glx_context *gc = (struct glx_context *) gc_user; + struct glx_context *oldGC = __glXGetCurrentContext(); + int ret = Success; + + /* Make sure that the new context has a nonzero ID. In the request, + * a zero context ID is used only to mean that we bind to no current + * context. + */ + if ((gc != NULL) && (gc->xid == None)) { + return GL_FALSE; + } + + if (gc == NULL && (draw != None || read != None)) { + __glXGenerateError(dpy, gc, (draw != None) ? draw : read, + BadMatch, X_GLXMakeContextCurrent); + return False; + } + if (gc != NULL && (draw == None || read == None)) { + __glXGenerateError(dpy, gc, None, BadMatch, X_GLXMakeContextCurrent); + return False; + } + + _glapi_check_multithread(); + + if (gc != NULL && gc->thread_id != 0 && gc->thread_id != _glthread_GetID()) { + __glXGenerateError(dpy, gc, gc->xid, + BadAccess, X_GLXMakeContextCurrent); + return False; + } + + if (oldGC == gc && + gc->currentDrawable == draw && gc->currentReadable == read) + return True; + + if (oldGC != &dummyContext) { + oldGC->vtable->unbind(oldGC, gc); + oldGC->currentDpy = 0; + oldGC->currentDrawable = None; + oldGC->currentReadable = None; + oldGC->thread_id = 0; + } + + if (gc) { + gc->currentDpy = dpy; + gc->currentDrawable = draw; + gc->currentReadable = read; + gc->thread_id = _glthread_GetID(); + __glXSetCurrentContext(gc); + ret = gc->vtable->bind(gc, oldGC, draw, read); + } else { + __glXSetCurrentContextNull(); + } + + if (oldGC != &dummyContext && oldGC->xid == None && oldGC != gc) { + /* We are switching away from a context that was + * previously destroyed, so we need to free the memory + * for the old handle. */ + oldGC->vtable->destroy(oldGC); + } + + if (ret) { + __glXGenerateError(dpy, gc, None, ret, X_GLXMakeContextCurrent); + return GL_FALSE; + } + + return GL_TRUE; +} + + +_X_EXPORT Bool +glXMakeCurrent(Display * dpy, GLXDrawable draw, GLXContext gc) +{ + return MakeContextCurrent(dpy, draw, draw, gc); +} + +_X_EXPORT +GLX_ALIAS(Bool, glXMakeCurrentReadSGI, + (Display * dpy, GLXDrawable d, GLXDrawable r, GLXContext ctx), + (dpy, d, r, ctx), MakeContextCurrent) + +_X_EXPORT +GLX_ALIAS(Bool, glXMakeContextCurrent, + (Display * dpy, GLXDrawable d, GLXDrawable r, + GLXContext ctx), (dpy, d, r, ctx), MakeContextCurrent) diff --git a/src/glx/glxext.c b/src/glx/glxext.c new file mode 100644 index 0000000..c75c9bf --- /dev/null +++ b/src/glx/glxext.c @@ -0,0 +1,1097 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/** + * \file glxext.c + * GLX protocol interface boot-strap code. + * + * Direct rendering support added by Precision Insight, Inc. + * + * \author Kevin E. Martin + */ + +#include +#include "glxclient.h" +#include +#include +#ifdef GLX_USE_APPLEGL +#include "apple_glx.h" +#include "apple_visual.h" +#endif +#include "glxextensions.h" + +#ifdef USE_XCB +#include +#include +#include +#endif + + +#ifdef DEBUG +void __glXDumpDrawBuffer(struct glx_context * ctx); +#endif + +/* +** You can set this cell to 1 to force the gl drawing stuff to be +** one command per packet +*/ +_X_HIDDEN int __glXDebug = 0; + +/* Extension required boiler plate */ + +static const char __glXExtensionName[] = GLX_EXTENSION_NAME; + static struct glx_display *glx_displays; + +static /* const */ char *error_list[] = { + "GLXBadContext", + "GLXBadContextState", + "GLXBadDrawable", + "GLXBadPixmap", + "GLXBadContextTag", + "GLXBadCurrentWindow", + "GLXBadRenderRequest", + "GLXBadLargeRequest", + "GLXUnsupportedPrivateRequest", + "GLXBadFBConfig", + "GLXBadPbuffer", + "GLXBadCurrentDrawable", + "GLXBadWindow", +}; + +#ifdef GLX_USE_APPLEGL +static char *__glXErrorString(Display *dpy, int code, XExtCodes *codes, + char *buf, int n); +#endif + +static +XEXT_GENERATE_ERROR_STRING(__glXErrorString, __glXExtensionName, + __GLX_NUMBER_ERRORS, error_list) + +/* + * GLX events are a bit funky. We don't stuff the X event code into + * our user exposed (via XNextEvent) structure. Instead we use the GLX + * private event code namespace (and hope it doesn't conflict). Clients + * have to know that bit 15 in the event type field means they're getting + * a GLX event, and then handle the various sub-event types there, rather + * than simply checking the event code and handling it directly. + */ + +static Bool +__glXWireToEvent(Display *dpy, XEvent *event, xEvent *wire) +{ + struct glx_display *glx_dpy = __glXInitialize(dpy); + + if (glx_dpy == NULL) + return False; + + switch ((wire->u.u.type & 0x7f) - glx_dpy->codes->first_event) { + case GLX_PbufferClobber: + { + GLXPbufferClobberEvent *aevent = (GLXPbufferClobberEvent *)event; + xGLXPbufferClobberEvent *awire = (xGLXPbufferClobberEvent *)wire; + aevent->event_type = awire->type; + aevent->serial = awire->sequenceNumber; + aevent->event_type = awire->event_type; + aevent->draw_type = awire->draw_type; + aevent->drawable = awire->drawable; + aevent->buffer_mask = awire->buffer_mask; + aevent->aux_buffer = awire->aux_buffer; + aevent->x = awire->x; + aevent->y = awire->y; + aevent->width = awire->width; + aevent->height = awire->height; + aevent->count = awire->count; + return True; + } + case GLX_BufferSwapComplete: + { + GLXBufferSwapComplete *aevent = (GLXBufferSwapComplete *)event; + xGLXBufferSwapComplete *awire = (xGLXBufferSwapComplete *)wire; + aevent->event_type = awire->event_type; + aevent->drawable = awire->drawable; + aevent->ust = ((CARD64)awire->ust_hi << 32) | awire->ust_lo; + aevent->msc = ((CARD64)awire->msc_hi << 32) | awire->msc_lo; + aevent->sbc = ((CARD64)awire->sbc_hi << 32) | awire->sbc_lo; + return True; + } + default: + /* client doesn't support server event */ + break; + } + + return False; +} + +/* We don't actually support this. It doesn't make sense for clients to + * send each other GLX events. + */ +static Status +__glXEventToWire(Display *dpy, XEvent *event, xEvent *wire) +{ + struct glx_display *glx_dpy = __glXInitialize(dpy); + + if (glx_dpy == NULL) + return False; + + switch (event->type) { + case GLX_DAMAGED: + break; + case GLX_SAVED: + break; + case GLX_EXCHANGE_COMPLETE_INTEL: + break; + case GLX_COPY_COMPLETE_INTEL: + break; + case GLX_FLIP_COMPLETE_INTEL: + break; + default: + /* client doesn't support server event */ + break; + } + + return Success; +} + +/************************************************************************/ +/* +** Free the per screen configs data as well as the array of +** __glXScreenConfigs. +*/ +static void +FreeScreenConfigs(struct glx_display * priv) +{ + struct glx_screen *psc; + GLint i, screens; + + /* Free screen configuration information */ + screens = ScreenCount(priv->dpy); + for (i = 0; i < screens; i++) { + psc = priv->screens[i]; + if (psc->configs) { + glx_config_destroy_list(psc->configs); + if (psc->effectiveGLXexts) + Xfree(psc->effectiveGLXexts); + psc->configs = NULL; /* NOTE: just for paranoia */ + } + if (psc->visuals) { + glx_config_destroy_list(psc->visuals); + psc->visuals = NULL; /* NOTE: just for paranoia */ + } + Xfree((char *) psc->serverGLXexts); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (psc->driScreen) { + psc->driScreen->destroyScreen(psc); + } else { + Xfree(psc); + } +#else + Xfree(psc); +#endif + } + XFree((char *) priv->screens); + priv->screens = NULL; +} + +static void +glx_display_free(struct glx_display *priv) +{ + struct glx_context *gc; + + gc = __glXGetCurrentContext(); + if (priv->dpy == gc->currentDpy) { + gc->vtable->destroy(gc); + __glXSetCurrentContextNull(); + } + + FreeScreenConfigs(priv); + if (priv->serverGLXvendor) + Xfree((char *) priv->serverGLXvendor); + if (priv->serverGLXversion) + Xfree((char *) priv->serverGLXversion); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + __glxHashDestroy(priv->drawHash); + + /* Free the direct rendering per display data */ + if (priv->driswDisplay) + (*priv->driswDisplay->destroyDisplay) (priv->driswDisplay); + priv->driswDisplay = NULL; + + if (priv->driDisplay) + (*priv->driDisplay->destroyDisplay) (priv->driDisplay); + priv->driDisplay = NULL; + + if (priv->dri2Display) + (*priv->dri2Display->destroyDisplay) (priv->dri2Display); + priv->dri2Display = NULL; +#endif + + Xfree((char *) priv); +} + +static int +__glXCloseDisplay(Display * dpy, XExtCodes * codes) +{ + struct glx_display *priv, **prev; + + _XLockMutex(_Xglobal_lock); + prev = &glx_displays; + for (priv = glx_displays; priv; prev = &priv->next, priv = priv->next) { + if (priv->dpy == dpy) { + (*prev) = priv->next; + break; + } + } + _XUnlockMutex(_Xglobal_lock); + + glx_display_free(priv); + + return 1; +} + +/* +** Query the version of the GLX extension. This procedure works even if +** the client extension is not completely set up. +*/ +static Bool +QueryVersion(Display * dpy, int opcode, int *major, int *minor) +{ +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + xcb_glx_query_version_reply_t *reply = xcb_glx_query_version_reply(c, + xcb_glx_query_version + (c, + GLX_MAJOR_VERSION, + GLX_MINOR_VERSION), + NULL); + + if (reply->major_version != GLX_MAJOR_VERSION) { + free(reply); + return GL_FALSE; + } + *major = reply->major_version; + *minor = min(reply->minor_version, GLX_MINOR_VERSION); + free(reply); + return GL_TRUE; +#else + xGLXQueryVersionReq *req; + xGLXQueryVersionReply reply; + + /* Send the glXQueryVersion request */ + LockDisplay(dpy); + GetReq(GLXQueryVersion, req); + req->reqType = opcode; + req->glxCode = X_GLXQueryVersion; + req->majorVersion = GLX_MAJOR_VERSION; + req->minorVersion = GLX_MINOR_VERSION; + _XReply(dpy, (xReply *) & reply, 0, False); + UnlockDisplay(dpy); + SyncHandle(); + + if (reply.majorVersion != GLX_MAJOR_VERSION) { + /* + ** The server does not support the same major release as this + ** client. + */ + return GL_FALSE; + } + *major = reply.majorVersion; + *minor = min(reply.minorVersion, GLX_MINOR_VERSION); + return GL_TRUE; +#endif /* USE_XCB */ +} + +/* + * We don't want to enable this GLX_OML_swap_method in glxext.h, + * because we can't support it. The X server writes it out though, + * so we should handle it somehow, to avoid false warnings. + */ +enum { + IGNORE_GLX_SWAP_METHOD_OML = 0x8060 +}; + + +static GLint +convert_from_x_visual_type(int visualType) +{ + static const int glx_visual_types[] = { + GLX_STATIC_GRAY, GLX_GRAY_SCALE, + GLX_STATIC_COLOR, GLX_PSEUDO_COLOR, + GLX_TRUE_COLOR, GLX_DIRECT_COLOR + }; + + if (visualType < ARRAY_SIZE(glx_visual_types)) + return glx_visual_types[visualType]; + + return GLX_NONE; +} + +/* + * getVisualConfigs uses the !tagged_only path. + * getFBConfigs uses the tagged_only path. + */ +_X_HIDDEN void +__glXInitializeVisualConfigFromTags(struct glx_config * config, int count, + const INT32 * bp, Bool tagged_only, + Bool fbconfig_style_tags) +{ + int i; + + if (!tagged_only) { + /* Copy in the first set of properties */ + config->visualID = *bp++; + + config->visualType = convert_from_x_visual_type(*bp++); + + config->rgbMode = *bp++; + + config->redBits = *bp++; + config->greenBits = *bp++; + config->blueBits = *bp++; + config->alphaBits = *bp++; + config->accumRedBits = *bp++; + config->accumGreenBits = *bp++; + config->accumBlueBits = *bp++; + config->accumAlphaBits = *bp++; + + config->doubleBufferMode = *bp++; + config->stereoMode = *bp++; + + config->rgbBits = *bp++; + config->depthBits = *bp++; + config->stencilBits = *bp++; + config->numAuxBuffers = *bp++; + config->level = *bp++; + +#ifdef GLX_USE_APPLEGL + /* AppleSGLX supports pixmap and pbuffers with all config. */ + config->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT; + /* Unfortunately this can create an ABI compatibility problem. */ + count -= 18; +#else + count -= __GLX_MIN_CONFIG_PROPS; +#endif + } + + /* + ** Additional properties may be in a list at the end + ** of the reply. They are in pairs of property type + ** and property value. + */ + +#define FETCH_OR_SET(tag) \ + config-> tag = ( fbconfig_style_tags ) ? *bp++ : 1 + + for (i = 0; i < count; i += 2) { + long int tag = *bp++; + + switch (tag) { + case GLX_RGBA: + FETCH_OR_SET(rgbMode); + break; + case GLX_BUFFER_SIZE: + config->rgbBits = *bp++; + break; + case GLX_LEVEL: + config->level = *bp++; + break; + case GLX_DOUBLEBUFFER: + FETCH_OR_SET(doubleBufferMode); + break; + case GLX_STEREO: + FETCH_OR_SET(stereoMode); + break; + case GLX_AUX_BUFFERS: + config->numAuxBuffers = *bp++; + break; + case GLX_RED_SIZE: + config->redBits = *bp++; + break; + case GLX_GREEN_SIZE: + config->greenBits = *bp++; + break; + case GLX_BLUE_SIZE: + config->blueBits = *bp++; + break; + case GLX_ALPHA_SIZE: + config->alphaBits = *bp++; + break; + case GLX_DEPTH_SIZE: + config->depthBits = *bp++; + break; + case GLX_STENCIL_SIZE: + config->stencilBits = *bp++; + break; + case GLX_ACCUM_RED_SIZE: + config->accumRedBits = *bp++; + break; + case GLX_ACCUM_GREEN_SIZE: + config->accumGreenBits = *bp++; + break; + case GLX_ACCUM_BLUE_SIZE: + config->accumBlueBits = *bp++; + break; + case GLX_ACCUM_ALPHA_SIZE: + config->accumAlphaBits = *bp++; + break; + case GLX_VISUAL_CAVEAT_EXT: + config->visualRating = *bp++; + break; + case GLX_X_VISUAL_TYPE: + config->visualType = *bp++; + break; + case GLX_TRANSPARENT_TYPE: + config->transparentPixel = *bp++; + break; + case GLX_TRANSPARENT_INDEX_VALUE: + config->transparentIndex = *bp++; + break; + case GLX_TRANSPARENT_RED_VALUE: + config->transparentRed = *bp++; + break; + case GLX_TRANSPARENT_GREEN_VALUE: + config->transparentGreen = *bp++; + break; + case GLX_TRANSPARENT_BLUE_VALUE: + config->transparentBlue = *bp++; + break; + case GLX_TRANSPARENT_ALPHA_VALUE: + config->transparentAlpha = *bp++; + break; + case GLX_VISUAL_ID: + config->visualID = *bp++; + break; + case GLX_DRAWABLE_TYPE: + config->drawableType = *bp++; +#ifdef GLX_USE_APPLEGL + /* AppleSGLX supports pixmap and pbuffers with all config. */ + config->drawableType |= GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT; +#endif + break; + case GLX_RENDER_TYPE: + config->renderType = *bp++; + break; + case GLX_X_RENDERABLE: + config->xRenderable = *bp++; + break; + case GLX_FBCONFIG_ID: + config->fbconfigID = *bp++; + break; + case GLX_MAX_PBUFFER_WIDTH: + config->maxPbufferWidth = *bp++; + break; + case GLX_MAX_PBUFFER_HEIGHT: + config->maxPbufferHeight = *bp++; + break; + case GLX_MAX_PBUFFER_PIXELS: + config->maxPbufferPixels = *bp++; + break; +#ifndef GLX_USE_APPLEGL + case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX: + config->optimalPbufferWidth = *bp++; + break; + case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX: + config->optimalPbufferHeight = *bp++; + break; + case GLX_VISUAL_SELECT_GROUP_SGIX: + config->visualSelectGroup = *bp++; + break; + case GLX_SWAP_METHOD_OML: + config->swapMethod = *bp++; + break; +#endif + case GLX_SAMPLE_BUFFERS_SGIS: + config->sampleBuffers = *bp++; + break; + case GLX_SAMPLES_SGIS: + config->samples = *bp++; + break; +#ifdef GLX_USE_APPLEGL + case IGNORE_GLX_SWAP_METHOD_OML: + /* We ignore this tag. See the comment above this function. */ + ++bp; + break; +#else + case GLX_BIND_TO_TEXTURE_RGB_EXT: + config->bindToTextureRgb = *bp++; + break; + case GLX_BIND_TO_TEXTURE_RGBA_EXT: + config->bindToTextureRgba = *bp++; + break; + case GLX_BIND_TO_MIPMAP_TEXTURE_EXT: + config->bindToMipmapTexture = *bp++; + break; + case GLX_BIND_TO_TEXTURE_TARGETS_EXT: + config->bindToTextureTargets = *bp++; + break; + case GLX_Y_INVERTED_EXT: + config->yInverted = *bp++; + break; +#endif + case GLX_USE_GL: + if (fbconfig_style_tags) + bp++; + break; + case None: + i = count; + break; + default: + if(getenv("LIBGL_DIAGNOSTIC")) { + long int tagvalue = *bp++; + fprintf(stderr, "WARNING: unknown GLX tag from server: " + "tag 0x%lx value 0x%lx\n", tag, tagvalue); + } else { + /* Ignore the unrecognized tag's value */ + bp++; + } + break; + } + } + + config->renderType = + (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT; +} + +static struct glx_config * +createConfigsFromProperties(Display * dpy, int nvisuals, int nprops, + int screen, GLboolean tagged_only) +{ + INT32 buf[__GLX_TOTAL_CONFIG], *props; + unsigned prop_size; + struct glx_config *modes, *m; + int i; + + if (nprops == 0) + return NULL; + + /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */ + + /* Check number of properties */ + if (nprops < __GLX_MIN_CONFIG_PROPS || nprops > __GLX_MAX_CONFIG_PROPS) + return NULL; + + /* Allocate memory for our config structure */ + modes = glx_config_create_list(nvisuals); + if (!modes) + return NULL; + + prop_size = nprops * __GLX_SIZE_INT32; + if (prop_size <= sizeof(buf)) + props = buf; + else + props = Xmalloc(prop_size); + + /* Read each config structure and convert it into our format */ + m = modes; + for (i = 0; i < nvisuals; i++) { + _XRead(dpy, (char *) props, prop_size); +#ifdef GLX_USE_APPLEGL + /* Older X servers don't send this so we default it here. */ + m->drawableType = GLX_WINDOW_BIT; +#else + /* + * The XQuartz 2.3.2.1 X server doesn't set this properly, so + * set the proper bits here. + * AppleSGLX supports windows, pixmaps, and pbuffers with all config. + */ + m->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT; +#endif + __glXInitializeVisualConfigFromTags(m, nprops, props, + tagged_only, GL_TRUE); + m->screen = screen; + m = m->next; + } + + if (props != buf) + Xfree(props); + + return modes; +} + +static GLboolean +getVisualConfigs(struct glx_screen *psc, + struct glx_display *priv, int screen) +{ + xGLXGetVisualConfigsReq *req; + xGLXGetVisualConfigsReply reply; + Display *dpy = priv->dpy; + + LockDisplay(dpy); + + psc->visuals = NULL; + GetReq(GLXGetVisualConfigs, req); + req->reqType = priv->majorOpcode; + req->glxCode = X_GLXGetVisualConfigs; + req->screen = screen; + + if (!_XReply(dpy, (xReply *) & reply, 0, False)) + goto out; + + psc->visuals = createConfigsFromProperties(dpy, + reply.numVisuals, + reply.numProps, + screen, GL_FALSE); + + out: + UnlockDisplay(dpy); + return psc->visuals != NULL; +} + +static GLboolean + getFBConfigs(struct glx_screen *psc, struct glx_display *priv, int screen) +{ + xGLXGetFBConfigsReq *fb_req; + xGLXGetFBConfigsSGIXReq *sgi_req; + xGLXVendorPrivateWithReplyReq *vpreq; + xGLXGetFBConfigsReply reply; + Display *dpy = priv->dpy; + + psc->serverGLXexts = + __glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS); + + LockDisplay(dpy); + + psc->configs = NULL; + if (atof(priv->serverGLXversion) >= 1.3) { + GetReq(GLXGetFBConfigs, fb_req); + fb_req->reqType = priv->majorOpcode; + fb_req->glxCode = X_GLXGetFBConfigs; + fb_req->screen = screen; + } + else if (strstr(psc->serverGLXexts, "GLX_SGIX_fbconfig") != NULL) { + GetReqExtra(GLXVendorPrivateWithReply, + sz_xGLXGetFBConfigsSGIXReq - + sz_xGLXVendorPrivateWithReplyReq, vpreq); + sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq; + sgi_req->reqType = priv->majorOpcode; + sgi_req->glxCode = X_GLXVendorPrivateWithReply; + sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX; + sgi_req->screen = screen; + } + else + goto out; + + if (!_XReply(dpy, (xReply *) & reply, 0, False)) + goto out; + + psc->configs = createConfigsFromProperties(dpy, + reply.numFBConfigs, + reply.numAttribs * 2, + screen, GL_TRUE); + + out: + UnlockDisplay(dpy); + return psc->configs != NULL; +} + +_X_HIDDEN Bool +glx_screen_init(struct glx_screen *psc, + int screen, struct glx_display * priv) +{ + /* Initialize per screen dynamic client GLX extensions */ + psc->ext_list_first_time = GL_TRUE; + psc->scr = screen; + psc->dpy = priv->dpy; + psc->display = priv; + + getVisualConfigs(psc, priv, screen); + getFBConfigs(psc, priv, screen); + + return GL_TRUE; +} + +/* +** Allocate the memory for the per screen configs for each screen. +** If that works then fetch the per screen configs data. +*/ +static Bool +AllocAndFetchScreenConfigs(Display * dpy, struct glx_display * priv) +{ + struct glx_screen *psc; + GLint i, screens; + + /* + ** First allocate memory for the array of per screen configs. + */ + screens = ScreenCount(dpy); + priv->screens = Xmalloc(screens * sizeof *priv->screens); + if (!priv->screens) + return GL_FALSE; + + priv->serverGLXversion = + __glXQueryServerString(dpy, priv->majorOpcode, 0, GLX_VERSION); + if (priv->serverGLXversion == NULL) { + FreeScreenConfigs(priv); + return GL_FALSE; + } + + for (i = 0; i < screens; i++, psc++) { + psc = NULL; +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (priv->dri2Display) + psc = (*priv->dri2Display->createScreen) (i, priv); + if (psc == NULL && priv->driDisplay) + psc = (*priv->driDisplay->createScreen) (i, priv); + if (psc == NULL && priv->driswDisplay) + psc = (*priv->driswDisplay->createScreen) (i, priv); +#endif +#if defined(GLX_USE_APPLEGL) + if (psc == NULL && priv->appleglDisplay) + psc = (*priv->appleglDisplay->createScreen) (i, priv); +#endif + if (psc == NULL) + psc = indirect_create_screen(i, priv); + priv->screens[i] = psc; + } + SyncHandle(); + return GL_TRUE; +} + +/* +** Initialize the client side extension code. +*/ + _X_HIDDEN struct glx_display * +__glXInitialize(Display * dpy) +{ + struct glx_display *dpyPriv, *d; +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + Bool glx_direct, glx_accel; +#endif + int i; + + _XLockMutex(_Xglobal_lock); + + for (dpyPriv = glx_displays; dpyPriv; dpyPriv = dpyPriv->next) { + if (dpyPriv->dpy == dpy) { + _XUnlockMutex(_Xglobal_lock); + return dpyPriv; + } + } + + /* Drop the lock while we create the display private. */ + _XUnlockMutex(_Xglobal_lock); + + dpyPriv = Xcalloc(1, sizeof *dpyPriv); + if (!dpyPriv) + return NULL; + + dpyPriv->codes = XInitExtension(dpy, __glXExtensionName); + if (!dpyPriv->codes) { + Xfree(dpyPriv); + _XUnlockMutex(_Xglobal_lock); + return NULL; + } + + dpyPriv->dpy = dpy; + dpyPriv->majorOpcode = dpyPriv->codes->major_opcode; + dpyPriv->serverGLXvendor = 0x0; + dpyPriv->serverGLXversion = 0x0; + + /* See if the versions are compatible */ + if (!QueryVersion(dpy, dpyPriv->majorOpcode, + &dpyPriv->majorVersion, &dpyPriv->minorVersion)) { + Xfree(dpyPriv); + _XUnlockMutex(_Xglobal_lock); + return NULL; + } + + for (i = 0; i < __GLX_NUMBER_EVENTS; i++) { + XESetWireToEvent(dpy, dpyPriv->codes->first_event + i, __glXWireToEvent); + XESetEventToWire(dpy, dpyPriv->codes->first_event + i, __glXEventToWire); + } + + XESetCloseDisplay(dpy, dpyPriv->codes->extension, __glXCloseDisplay); + XESetErrorString (dpy, dpyPriv->codes->extension,__glXErrorString); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + glx_direct = (getenv("LIBGL_ALWAYS_INDIRECT") == NULL); + glx_accel = (getenv("LIBGL_ALWAYS_SOFTWARE") == NULL); + + dpyPriv->drawHash = __glxHashCreate(); + + /* + ** Initialize the direct rendering per display data and functions. + ** Note: This _must_ be done before calling any other DRI routines + ** (e.g., those called in AllocAndFetchScreenConfigs). + */ + if (glx_direct && glx_accel) { + dpyPriv->dri2Display = dri2CreateDisplay(dpy); + dpyPriv->driDisplay = driCreateDisplay(dpy); + } + if (glx_direct) + dpyPriv->driswDisplay = driswCreateDisplay(dpy); +#endif + +#ifdef GLX_USE_APPLEGL + if (!applegl_create_display(dpyPriv)) { + Xfree(dpyPriv); + return NULL; + } +#endif + if (!AllocAndFetchScreenConfigs(dpy, dpyPriv)) { + Xfree(dpyPriv); + return NULL; + } + + if (dpyPriv->majorVersion == 1 && dpyPriv->minorVersion >= 1) + __glXClientInfo(dpy, dpyPriv->majorOpcode); + + /* Grab the lock again and add the dispay private, unless somebody + * beat us to initializing on this display in the meantime. */ + _XLockMutex(_Xglobal_lock); + + for (d = glx_displays; d; d = d->next) { + if (d->dpy == dpy) { + _XUnlockMutex(_Xglobal_lock); + glx_display_free(dpyPriv); + return d; + } + } + + dpyPriv->next = glx_displays; + glx_displays = dpyPriv; + + _XUnlockMutex(_Xglobal_lock); + + return dpyPriv; +} + +/* +** Setup for sending a GLX command on dpy. Make sure the extension is +** initialized. Try to avoid calling __glXInitialize as its kinda slow. +*/ +_X_HIDDEN CARD8 +__glXSetupForCommand(Display * dpy) +{ + struct glx_context *gc; + struct glx_display *priv; + + /* If this thread has a current context, flush its rendering commands */ + gc = __glXGetCurrentContext(); + if (gc->currentDpy) { + /* Flush rendering buffer of the current context, if any */ + (void) __glXFlushRenderBuffer(gc, gc->pc); + + if (gc->currentDpy == dpy) { + /* Use opcode from gc because its right */ + return gc->majorOpcode; + } + else { + /* + ** Have to get info about argument dpy because it might be to + ** a different server + */ + } + } + + /* Forced to lookup extension via the slow initialize route */ + priv = __glXInitialize(dpy); + if (!priv) { + return 0; + } + return priv->majorOpcode; +} + +/** + * Flush the drawing command transport buffer. + * + * \param ctx Context whose transport buffer is to be flushed. + * \param pc Pointer to first unused buffer location. + * + * \todo + * Modify this function to use \c ctx->pc instead of the explicit + * \c pc parameter. + */ +_X_HIDDEN GLubyte * +__glXFlushRenderBuffer(struct glx_context * ctx, GLubyte * pc) +{ + Display *const dpy = ctx->currentDpy; +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); +#else + xGLXRenderReq *req; +#endif /* USE_XCB */ + const GLint size = pc - ctx->buf; + + if ((dpy != NULL) && (size > 0)) { +#ifdef USE_XCB + xcb_glx_render(c, ctx->currentContextTag, size, + (const uint8_t *) ctx->buf); +#else + /* Send the entire buffer as an X request */ + LockDisplay(dpy); + GetReq(GLXRender, req); + req->reqType = ctx->majorOpcode; + req->glxCode = X_GLXRender; + req->contextTag = ctx->currentContextTag; + req->length += (size + 3) >> 2; + _XSend(dpy, (char *) ctx->buf, size); + UnlockDisplay(dpy); + SyncHandle(); +#endif + } + + /* Reset pointer and return it */ + ctx->pc = ctx->buf; + return ctx->pc; +} + + +/** + * Send a portion of a GLXRenderLarge command to the server. The advantage of + * this function over \c __glXSendLargeCommand is that callers can use the + * data buffer in the GLX context and may be able to avoid allocating an + * extra buffer. The disadvantage is the clients will have to do more + * GLX protocol work (i.e., calculating \c totalRequests, etc.). + * + * \sa __glXSendLargeCommand + * + * \param gc GLX context + * \param requestNumber Which part of the whole command is this? The first + * request is 1. + * \param totalRequests How many requests will there be? + * \param data Command data. + * \param dataLen Size, in bytes, of the command data. + */ +_X_HIDDEN void +__glXSendLargeChunk(struct glx_context * gc, GLint requestNumber, + GLint totalRequests, const GLvoid * data, GLint dataLen) +{ + Display *dpy = gc->currentDpy; +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + xcb_glx_render_large(c, gc->currentContextTag, requestNumber, + totalRequests, dataLen, data); +#else + xGLXRenderLargeReq *req; + + if (requestNumber == 1) { + LockDisplay(dpy); + } + + GetReq(GLXRenderLarge, req); + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXRenderLarge; + req->contextTag = gc->currentContextTag; + req->length += (dataLen + 3) >> 2; + req->requestNumber = requestNumber; + req->requestTotal = totalRequests; + req->dataBytes = dataLen; + Data(dpy, data, dataLen); + + if (requestNumber == totalRequests) { + UnlockDisplay(dpy); + SyncHandle(); + } +#endif /* USE_XCB */ +} + + +/** + * Send a command that is too large for the GLXRender protocol request. + * + * Send a large command, one that is too large for some reason to + * send using the GLXRender protocol request. One reason to send + * a large command is to avoid copying the data. + * + * \param ctx GLX context + * \param header Header data. + * \param headerLen Size, in bytes, of the header data. It is assumed that + * the header data will always be small enough to fit in + * a single X protocol packet. + * \param data Command data. + * \param dataLen Size, in bytes, of the command data. + */ +_X_HIDDEN void +__glXSendLargeCommand(struct glx_context * ctx, + const GLvoid * header, GLint headerLen, + const GLvoid * data, GLint dataLen) +{ + GLint maxSize; + GLint totalRequests, requestNumber; + + /* + ** Calculate the maximum amount of data can be stuffed into a single + ** packet. sz_xGLXRenderReq is added because bufSize is the maximum + ** packet size minus sz_xGLXRenderReq. + */ + maxSize = (ctx->bufSize + sz_xGLXRenderReq) - sz_xGLXRenderLargeReq; + totalRequests = 1 + (dataLen / maxSize); + if (dataLen % maxSize) + totalRequests++; + + /* + ** Send all of the command, except the large array, as one request. + */ + assert(headerLen <= maxSize); + __glXSendLargeChunk(ctx, 1, totalRequests, header, headerLen); + + /* + ** Send enough requests until the whole array is sent. + */ + for (requestNumber = 2; requestNumber <= (totalRequests - 1); + requestNumber++) { + __glXSendLargeChunk(ctx, requestNumber, totalRequests, data, maxSize); + data = (const GLvoid *) (((const GLubyte *) data) + maxSize); + dataLen -= maxSize; + assert(dataLen > 0); + } + + assert(dataLen <= maxSize); + __glXSendLargeChunk(ctx, requestNumber, totalRequests, data, dataLen); +} + +/************************************************************************/ + +#ifdef DEBUG +_X_HIDDEN void +__glXDumpDrawBuffer(struct glx_context * ctx) +{ + GLubyte *p = ctx->buf; + GLubyte *end = ctx->pc; + GLushort opcode, length; + + while (p < end) { + /* Fetch opcode */ + opcode = *((GLushort *) p); + length = *((GLushort *) (p + 2)); + printf("%2x: %5d: ", opcode, length); + length -= 4; + p += 4; + while (length > 0) { + printf("%08x ", *((unsigned *) p)); + p += 4; + length -= 4; + } + printf("\n"); + } +} +#endif diff --git a/src/glx/glxextensions.c b/src/glx/glxextensions.c new file mode 100644 index 0000000..3a0e64c --- /dev/null +++ b/src/glx/glxextensions.c @@ -0,0 +1,749 @@ +/* + * (C) Copyright IBM Corporation 2002, 2004 + * 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 + * 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 COPYRIGHT HOLDERS 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. + */ + +/** + * \file glxextensions.c + * + * \author Ian Romanick + */ + +#include "glxclient.h" +#include +#include +#include +#include "glxextensions.h" + + +#define SET_BIT(m,b) (m[ (b) / 8 ] |= (1U << ((b) % 8))) +#define CLR_BIT(m,b) (m[ (b) / 8 ] &= ~(1U << ((b) % 8))) +#define IS_SET(m,b) ((m[ (b) / 8 ] & (1U << ((b) % 8))) != 0) +#define CONCAT(a,b) a ## b +#define GLX(n) "GLX_" # n, 4 + sizeof( # n ) - 1, CONCAT(n,_bit) +#define GL(n) "GL_" # n, 3 + sizeof( # n ) - 1, GL_ ## n ## _bit +#define VER(a,b) a, b +#define Y 1 +#define N 0 +#define EXT_ENABLED(bit,supported) (IS_SET( supported, bit )) + + +struct extension_info +{ + const char *const name; + unsigned name_len; + + unsigned char bit; + + /* This is the lowest version of GLX that "requires" this extension. + * For example, GLX 1.3 requires SGIX_fbconfig, SGIX_pbuffer, and + * SGI_make_current_read. If the extension is not required by any known + * version of GLX, use 0, 0. + */ + unsigned char version_major; + unsigned char version_minor; + unsigned char client_support; + unsigned char direct_support; + unsigned char client_only; /** Is the extension client-side only? */ + unsigned char direct_only; /** Is the extension for direct + * contexts only? + */ +}; + +/* *INDENT-OFF* */ +static const struct extension_info known_glx_extensions[] = { + { GLX(ARB_get_proc_address), VER(1,4), Y, N, Y, N }, + { GLX(ARB_multisample), VER(1,4), Y, Y, N, N }, + { GLX(ARB_render_texture), VER(0,0), N, N, N, N }, + { GLX(ATI_pixel_format_float), VER(0,0), N, N, N, N }, +#ifdef GLX_USE_APPLEGL + { GLX(EXT_import_context), VER(0,0), N, N, N, N }, + { GLX(EXT_visual_info), VER(0,0), N, N, N, N }, +#else + { GLX(EXT_import_context), VER(0,0), Y, Y, N, N }, + { GLX(EXT_visual_info), VER(0,0), Y, Y, N, N }, +#endif + { GLX(EXT_visual_rating), VER(0,0), Y, Y, N, N }, +#ifdef GLX_USE_APPLEGL + { GLX(MESA_agp_offset), VER(0,0), N, N, N, N }, /* Deprecated */ + { GLX(MESA_copy_sub_buffer), VER(0,0), N, N, N, N }, +#else + { GLX(MESA_agp_offset), VER(0,0), N, N, N, Y }, /* Deprecated */ + { GLX(MESA_copy_sub_buffer), VER(0,0), Y, N, N, N }, +#endif + { GLX(MESA_pixmap_colormap), VER(0,0), N, N, N, N }, /* Deprecated */ + { GLX(MESA_release_buffers), VER(0,0), N, N, N, N }, /* Deprecated */ +#ifdef GLX_USE_APPLEGL + { GLX(MESA_swap_control), VER(0,0), N, N, N, N }, +#else + { GLX(MESA_swap_control), VER(0,0), Y, N, N, Y }, +#endif + { GLX(NV_float_buffer), VER(0,0), N, N, N, N }, + { GLX(NV_render_depth_texture), VER(0,0), N, N, N, N }, + { GLX(NV_render_texture_rectangle), VER(0,0), N, N, N, N }, +#ifdef GLX_USE_APPLEGL + { GLX(NV_vertex_array_range), VER(0,0), N, N, N, N }, /* Deprecated */ + { GLX(OML_swap_method), VER(0,0), N, N, N, N }, + { GLX(OML_sync_control), VER(0,0), N, N, N, N }, + { GLX(SGI_make_current_read), VER(1,3), N, N, N, N }, + { GLX(SGI_swap_control), VER(0,0), N, N, N, N }, + { GLX(SGI_video_sync), VER(0,0), N, N, N, N }, +#else + { GLX(NV_vertex_array_range), VER(0,0), N, N, N, Y }, /* Deprecated */ + { GLX(OML_swap_method), VER(0,0), Y, Y, N, N }, + { GLX(OML_sync_control), VER(0,0), Y, N, N, Y }, + { GLX(SGI_make_current_read), VER(1,3), Y, N, N, N }, + { GLX(SGI_swap_control), VER(0,0), Y, N, N, N }, + { GLX(SGI_video_sync), VER(0,0), Y, N, N, Y }, +#endif + { GLX(SGIS_blended_overlay), VER(0,0), N, N, N, N }, + { GLX(SGIS_color_range), VER(0,0), N, N, N, N }, +#ifdef GLX_USE_APPLEGL + { GLX(SGIS_multisample), VER(0,0), N, N, N, N }, +#else + { GLX(SGIS_multisample), VER(0,0), Y, Y, N, N }, +#endif + { GLX(SGIX_fbconfig), VER(1,3), Y, Y, N, N }, +#ifdef GLX_USE_APPLEGL + { GLX(SGIX_pbuffer), VER(1,3), N, N, N, N }, +#else + { GLX(SGIX_pbuffer), VER(1,3), Y, Y, N, N }, +#endif + { GLX(SGIX_swap_barrier), VER(0,0), N, N, N, N }, + { GLX(SGIX_swap_group), VER(0,0), N, N, N, N }, +#ifdef GLX_USE_APPLEGL + { GLX(SGIX_visual_select_group), VER(0,0), N, N, N, N }, + { GLX(EXT_texture_from_pixmap), VER(0,0), N, N, N, N }, +#else + { GLX(SGIX_visual_select_group), VER(0,0), Y, Y, N, N }, + { GLX(EXT_texture_from_pixmap), VER(0,0), Y, N, N, N }, +#endif + { GLX(INTEL_swap_event), VER(1,4), Y, Y, N, N }, + { NULL } +}; + +static const struct extension_info known_gl_extensions[] = { + { GL(ARB_depth_texture), VER(1,4), Y, N, N, N }, + { GL(ARB_draw_buffers), VER(0,0), Y, N, N, N }, + { GL(ARB_fragment_program), VER(0,0), Y, N, N, N }, + { GL(ARB_fragment_program_shadow), VER(0,0), Y, N, N, N }, + { GL(ARB_framebuffer_object), VER(0,0), Y, N, N, N }, + { GL(ARB_imaging), VER(0,0), Y, N, N, N }, + { GL(ARB_multisample), VER(1,3), Y, N, N, N }, + { GL(ARB_multitexture), VER(1,3), Y, N, N, N }, + { GL(ARB_occlusion_query), VER(1,5), Y, N, N, N }, + { GL(ARB_point_parameters), VER(1,4), Y, N, N, N }, + { GL(ARB_point_sprite), VER(0,0), Y, N, N, N }, + { GL(ARB_shadow), VER(1,4), Y, N, N, N }, + { GL(ARB_shadow_ambient), VER(0,0), Y, N, N, N }, + { GL(ARB_texture_border_clamp), VER(1,3), Y, N, N, N }, + { GL(ARB_texture_compression), VER(1,3), Y, N, N, N }, + { GL(ARB_texture_cube_map), VER(1,3), Y, N, N, N }, + { GL(ARB_texture_env_add), VER(1,3), Y, N, N, N }, + { GL(ARB_texture_env_combine), VER(1,3), Y, N, N, N }, + { GL(ARB_texture_env_crossbar), VER(1,4), Y, N, N, N }, + { GL(ARB_texture_env_dot3), VER(1,3), Y, N, N, N }, + { GL(ARB_texture_mirrored_repeat), VER(1,4), Y, N, N, N }, + { GL(ARB_texture_non_power_of_two), VER(1,5), Y, N, N, N }, + { GL(ARB_texture_rectangle), VER(0,0), Y, N, N, N }, + { GL(ARB_texture_rg), VER(0,0), Y, N, N, N }, + { GL(ARB_transpose_matrix), VER(1,3), Y, N, Y, N }, + { GL(ARB_vertex_buffer_object), VER(1,5), N, N, N, N }, + { GL(ARB_vertex_program), VER(0,0), Y, N, N, N }, + { GL(ARB_window_pos), VER(1,4), Y, N, N, N }, + { GL(EXT_abgr), VER(0,0), Y, N, N, N }, + { GL(EXT_bgra), VER(1,2), Y, N, N, N }, + { GL(EXT_blend_color), VER(1,4), Y, N, N, N }, + { GL(EXT_blend_equation_separate), VER(0,0), Y, N, N, N }, + { GL(EXT_blend_func_separate), VER(1,4), Y, N, N, N }, + { GL(EXT_blend_logic_op), VER(1,4), Y, N, N, N }, + { GL(EXT_blend_minmax), VER(1,4), Y, N, N, N }, + { GL(EXT_blend_subtract), VER(1,4), Y, N, N, N }, + { GL(EXT_clip_volume_hint), VER(0,0), Y, N, N, N }, + { GL(EXT_compiled_vertex_array), VER(0,0), N, N, N, N }, + { GL(EXT_convolution), VER(0,0), N, N, N, N }, + { GL(EXT_copy_texture), VER(1,1), Y, N, N, N }, + { GL(EXT_cull_vertex), VER(0,0), N, N, N, N }, + { GL(EXT_depth_bounds_test), VER(0,0), N, N, N, N }, + { GL(EXT_draw_range_elements), VER(1,2), Y, N, Y, N }, + { GL(EXT_fog_coord), VER(1,4), Y, N, N, N }, + { GL(EXT_framebuffer_blit), VER(0,0), Y, N, N, N }, + { GL(EXT_framebuffer_multisample), VER(0,0), Y, N, N, N }, + { GL(EXT_framebuffer_object), VER(0,0), Y, N, N, N }, + { GL(EXT_multi_draw_arrays), VER(1,4), Y, N, Y, N }, + { GL(EXT_packed_depth_stencil), VER(0,0), Y, N, N, N }, + { GL(EXT_packed_pixels), VER(1,2), Y, N, N, N }, + { GL(EXT_paletted_texture), VER(0,0), Y, N, N, N }, + { GL(EXT_pixel_buffer_object), VER(0,0), N, N, N, N }, + { GL(EXT_point_parameters), VER(1,4), Y, N, N, N }, + { GL(EXT_polygon_offset), VER(1,1), Y, N, N, N }, + { GL(EXT_rescale_normal), VER(1,2), Y, N, N, N }, + { GL(EXT_secondary_color), VER(1,4), Y, N, N, N }, + { GL(EXT_separate_specular_color), VER(1,2), Y, N, N, N }, + { GL(EXT_shadow_funcs), VER(1,5), Y, N, N, N }, + { GL(EXT_shared_texture_palette), VER(0,0), Y, N, N, N }, + { GL(EXT_stencil_two_side), VER(0,0), Y, N, N, N }, + { GL(EXT_stencil_wrap), VER(1,4), Y, N, N, N }, + { GL(EXT_subtexture), VER(1,1), Y, N, N, N }, + { GL(EXT_texture), VER(1,1), Y, N, N, N }, + { GL(EXT_texture3D), VER(1,2), Y, N, N, N }, + { GL(EXT_texture_compression_dxt1), VER(0,0), Y, N, N, N }, + { GL(EXT_texture_compression_s3tc), VER(0,0), Y, N, N, N }, + { GL(EXT_texture_edge_clamp), VER(1,2), Y, N, N, N }, + { GL(EXT_texture_env_add), VER(1,3), Y, N, N, N }, + { GL(EXT_texture_env_combine), VER(1,3), Y, N, N, N }, + { GL(EXT_texture_env_dot3), VER(0,0), Y, N, N, N }, + { GL(EXT_texture_filter_anisotropic), VER(0,0), Y, N, N, N }, + { GL(EXT_texture_lod), VER(1,2), Y, N, N, N }, + { GL(EXT_texture_lod_bias), VER(1,4), Y, N, N, N }, + { GL(EXT_texture_mirror_clamp), VER(0,0), Y, N, N, N }, + { GL(EXT_texture_object), VER(1,1), Y, N, N, N }, + { GL(EXT_texture_rectangle), VER(0,0), Y, N, N, N }, + { GL(EXT_vertex_array), VER(0,0), Y, N, N, N }, + { GL(3DFX_texture_compression_FXT1), VER(0,0), Y, N, N, N }, + { GL(APPLE_packed_pixels), VER(1,2), Y, N, N, N }, + { GL(APPLE_ycbcr_422), VER(0,0), Y, N, N, N }, + { GL(ATI_draw_buffers), VER(0,0), Y, N, N, N }, + { GL(ATI_text_fragment_shader), VER(0,0), Y, N, N, N }, + { GL(ATI_texture_env_combine3), VER(0,0), Y, N, N, N }, + { GL(ATI_texture_float), VER(0,0), Y, N, N, N }, + { GL(ATI_texture_mirror_once), VER(0,0), Y, N, N, N }, + { GL(ATIX_texture_env_combine3), VER(0,0), Y, N, N, N }, + { GL(HP_convolution_border_modes), VER(0,0), Y, N, N, N }, + { GL(HP_occlusion_test), VER(0,0), Y, N, N, N }, + { GL(IBM_cull_vertex), VER(0,0), Y, N, N, N }, + { GL(IBM_pixel_filter_hint), VER(0,0), Y, N, N, N }, + { GL(IBM_rasterpos_clip), VER(0,0), Y, N, N, N }, + { GL(IBM_texture_clamp_nodraw), VER(0,0), Y, N, N, N }, + { GL(IBM_texture_mirrored_repeat), VER(0,0), Y, N, N, N }, + { GL(INGR_blend_func_separate), VER(0,0), Y, N, N, N }, + { GL(INGR_interlace_read), VER(0,0), Y, N, N, N }, + { GL(MESA_pack_invert), VER(0,0), Y, N, N, N }, + { GL(MESA_ycbcr_texture), VER(0,0), Y, N, N, N }, + { GL(NV_blend_square), VER(1,4), Y, N, N, N }, + { GL(NV_copy_depth_to_color), VER(0,0), Y, N, N, N }, + { GL(NV_depth_clamp), VER(0,0), Y, N, N, N }, + { GL(NV_fog_distance), VER(0,0), Y, N, N, N }, + { GL(NV_fragment_program), VER(0,0), Y, N, N, N }, + { GL(NV_fragment_program_option), VER(0,0), Y, N, N, N }, + { GL(NV_fragment_program2), VER(0,0), Y, N, N, N }, + { GL(NV_light_max_exponent), VER(0,0), Y, N, N, N }, + { GL(NV_multisample_filter_hint), VER(0,0), Y, N, N, N }, + { GL(NV_packed_depth_stencil), VER(0,0), Y, N, N, N }, + { GL(NV_point_sprite), VER(0,0), Y, N, N, N }, + { GL(NV_texgen_reflection), VER(0,0), Y, N, N, N }, + { GL(NV_texture_compression_vtc), VER(0,0), Y, N, N, N }, + { GL(NV_texture_env_combine4), VER(0,0), Y, N, N, N }, + { GL(NV_texture_rectangle), VER(0,0), Y, N, N, N }, + { GL(NV_vertex_program), VER(0,0), Y, N, N, N }, + { GL(NV_vertex_program1_1), VER(0,0), Y, N, N, N }, + { GL(NV_vertex_program2), VER(0,0), Y, N, N, N }, + { GL(NV_vertex_program2_option), VER(0,0), Y, N, N, N }, + { GL(NV_vertex_program3), VER(0,0), Y, N, N, N }, + { GL(OES_read_format), VER(0,0), Y, N, N, N }, + { GL(OES_compressed_paletted_texture),VER(0,0), Y, N, N, N }, + { GL(SGI_color_matrix), VER(0,0), Y, N, N, N }, + { GL(SGI_color_table), VER(0,0), Y, N, N, N }, + { GL(SGI_texture_color_table), VER(0,0), Y, N, N, N }, + { GL(SGIS_generate_mipmap), VER(1,4), Y, N, N, N }, + { GL(SGIS_multisample), VER(0,0), Y, N, N, N }, + { GL(SGIS_texture_border_clamp), VER(1,3), Y, N, N, N }, + { GL(SGIS_texture_edge_clamp), VER(1,2), Y, N, N, N }, + { GL(SGIS_texture_lod), VER(1,2), Y, N, N, N }, + { GL(SGIX_blend_alpha_minmax), VER(0,0), Y, N, N, N }, + { GL(SGIX_clipmap), VER(0,0), Y, N, N, N }, + { GL(SGIX_depth_texture), VER(0,0), Y, N, N, N }, + { GL(SGIX_fog_offset), VER(0,0), Y, N, N, N }, + { GL(SGIX_shadow), VER(0,0), Y, N, N, N }, + { GL(SGIX_shadow_ambient), VER(0,0), Y, N, N, N }, + { GL(SGIX_texture_coordinate_clamp), VER(0,0), Y, N, N, N }, + { GL(SGIX_texture_lod_bias), VER(0,0), Y, N, N, N }, + { GL(SGIX_texture_range), VER(0,0), Y, N, N, N }, + { GL(SGIX_texture_scale_bias), VER(0,0), Y, N, N, N }, + { GL(SGIX_vertex_preclip), VER(0,0), Y, N, N, N }, + { GL(SGIX_vertex_preclip_hint), VER(0,0), Y, N, N, N }, + { GL(SGIX_ycrcb), VER(0,0), Y, N, N, N }, + { GL(SUN_convolution_border_modes), VER(0,0), Y, N, N, N }, + { GL(SUN_multi_draw_arrays), VER(0,0), Y, N, Y, N }, + { GL(SUN_slice_accum), VER(0,0), Y, N, N, N }, + { NULL } +}; +/* *INDENT-ON* */ + + +/* global bit-fields of available extensions and their characteristics */ +static unsigned char client_glx_support[8]; +static unsigned char client_glx_only[8]; +static unsigned char direct_glx_only[8]; +static unsigned char client_gl_support[__GL_EXT_BYTES]; +static unsigned char client_gl_only[__GL_EXT_BYTES]; + +/** + * Bits representing the set of extensions that are enabled by default in all + * direct rendering drivers. + */ +static unsigned char direct_glx_support[8]; + +/** + * Highest core GL version that can be supported for indirect rendering. + */ +static const unsigned gl_major = 1; +static const unsigned gl_minor = 4; + +/* client extensions string */ +static const char *__glXGLXClientExtensions = NULL; + +static void __glXExtensionsCtr(void); +static void __glXExtensionsCtrScreen(struct glx_screen * psc); +static void __glXProcessServerString(const struct extension_info *ext, + const char *server_string, + unsigned char *server_support); + +/** + * Set the state of a GLX extension. + * + * \param name Name of the extension. + * \param name_len Length, in characters, of the extension name. + * \param state New state (either enabled or disabled) of the extension. + * \param supported Table in which the state of the extension is to be set. + */ +static void +set_glx_extension(const struct extension_info *ext, + const char *name, unsigned name_len, GLboolean state, + unsigned char *supported) +{ + unsigned i; + + + for (i = 0; ext[i].name != NULL; i++) { + if ((name_len == ext[i].name_len) + && (strncmp(ext[i].name, name, name_len) == 0)) { + if (state) { + SET_BIT(supported, ext[i].bit); + } + else { + CLR_BIT(supported, ext[i].bit); + } + + return; + } + } +} + + +#define NUL '\0' +#define SEPARATOR ' ' + +/** + * Convert the server's extension string to a bit-field. + * + * \param server_string GLX extension string from the server. + * \param server_support Bit-field of supported extensions. + * + * \note + * This function is used to process both GLX and GL extension strings. The + * bit-fields used to track each of these have different sizes. Therefore, + * the data pointed by \c server_support must be preinitialized to zero. + */ +static void +__glXProcessServerString(const struct extension_info *ext, + const char *server_string, + unsigned char *server_support) +{ + unsigned base; + unsigned len; + + for (base = 0; server_string[base] != NUL; /* empty */ ) { + /* Determine the length of the next extension name. + */ + for (len = 0; (server_string[base + len] != SEPARATOR) + && (server_string[base + len] != NUL); len++) { + /* empty */ + } + + /* Set the bit for the extension in the server_support table. + */ + set_glx_extension(ext, &server_string[base], len, GL_TRUE, + server_support); + + + /* Advance to the next extension string. This means that we skip + * over the previous string and any trialing white-space. + */ + for (base += len; (server_string[base] == SEPARATOR) + && (server_string[base] != NUL); base++) { + /* empty */ + } + } +} + +void +__glXEnableDirectExtension(struct glx_screen * psc, const char *name) +{ + __glXExtensionsCtr(); + __glXExtensionsCtrScreen(psc); + + set_glx_extension(known_glx_extensions, + name, strlen(name), GL_TRUE, psc->direct_support); +} + +/** + * Initialize global extension support tables. + */ + +static void +__glXExtensionsCtr(void) +{ + unsigned i; + static GLboolean ext_list_first_time = GL_TRUE; + + + if (ext_list_first_time) { + ext_list_first_time = GL_FALSE; + + (void) memset(client_glx_support, 0, sizeof(client_glx_support)); + (void) memset(direct_glx_support, 0, sizeof(direct_glx_support)); + (void) memset(client_glx_only, 0, sizeof(client_glx_only)); + (void) memset(direct_glx_only, 0, sizeof(direct_glx_only)); + + (void) memset(client_gl_support, 0, sizeof(client_gl_support)); + (void) memset(client_gl_only, 0, sizeof(client_gl_only)); + + for (i = 0; known_glx_extensions[i].name != NULL; i++) { + const unsigned bit = known_glx_extensions[i].bit; + + if (known_glx_extensions[i].client_support) { + SET_BIT(client_glx_support, bit); + } + + if (known_glx_extensions[i].direct_support) { + SET_BIT(direct_glx_support, bit); + } + + if (known_glx_extensions[i].client_only) { + SET_BIT(client_glx_only, bit); + } + + if (known_glx_extensions[i].direct_only) { + SET_BIT(direct_glx_only, bit); + } + } + + for (i = 0; known_gl_extensions[i].name != NULL; i++) { + const unsigned bit = known_gl_extensions[i].bit; + + if (known_gl_extensions[i].client_support) { + SET_BIT(client_gl_support, bit); + } + + if (known_gl_extensions[i].client_only) { + SET_BIT(client_gl_only, bit); + } + } + +#if 0 + fprintf(stderr, "[%s:%u] Maximum client library version: %u.%u\n", + __func__, __LINE__, gl_major, gl_minor); +#endif + } +} + + +/** + * Make sure that per-screen direct-support table is initialized. + * + * \param psc Pointer to GLX per-screen record. + */ + +static void +__glXExtensionsCtrScreen(struct glx_screen * psc) +{ + if (psc->ext_list_first_time) { + psc->ext_list_first_time = GL_FALSE; + (void) memcpy(psc->direct_support, direct_glx_support, + sizeof(direct_glx_support)); + } +} + + +/** + * Check if a certain extension is enabled on a given screen. + * + * \param psc Pointer to GLX per-screen record. + * \param bit Bit index in the direct-support table. + * \returns If the extension bit is enabled for the screen, \c GL_TRUE is + * returned. If the extension bit is not enabled or if \c psc is + * \c NULL, then \c GL_FALSE is returned. + */ +GLboolean +__glXExtensionBitIsEnabled(struct glx_screen * psc, unsigned bit) +{ + GLboolean enabled = GL_FALSE; + + if (psc != NULL) { + __glXExtensionsCtr(); + __glXExtensionsCtrScreen(psc); + enabled = EXT_ENABLED(bit, psc->direct_support); + } + + return enabled; +} + + +/** + * Check if a certain extension is enabled in a given context. + * + */ +GLboolean +__glExtensionBitIsEnabled(struct glx_context *gc, unsigned bit) +{ + GLboolean enabled = GL_FALSE; + + if (gc != NULL) { + enabled = EXT_ENABLED(bit, gc->gl_extension_bits); + } + + return enabled; +} + + + +/** + * Convert a bit-field to a string of supported extensions. + */ +static char * +__glXGetStringFromTable(const struct extension_info *ext, + const unsigned char *supported) +{ + unsigned i; + unsigned ext_str_len; + char *ext_str; + char *point; + + + ext_str_len = 0; + for (i = 0; ext[i].name != NULL; i++) { + if (EXT_ENABLED(ext[i].bit, supported)) { + ext_str_len += ext[i].name_len + 1; + } + } + + ext_str = Xmalloc(ext_str_len + 1); + if (ext_str != NULL) { + point = ext_str; + + for (i = 0; ext[i].name != NULL; i++) { + if (EXT_ENABLED(ext[i].bit, supported)) { + (void) memcpy(point, ext[i].name, ext[i].name_len); + point += ext[i].name_len; + + *point = ' '; + point++; + } + } + + *point = '\0'; + } + + return ext_str; +} + + +/** + * Get the string of client library supported extensions. + */ +const char * +__glXGetClientExtensions(void) +{ + if (__glXGLXClientExtensions == NULL) { + __glXExtensionsCtr(); + __glXGLXClientExtensions = __glXGetStringFromTable(known_glx_extensions, + client_glx_support); + } + + return __glXGLXClientExtensions; +} + + +/** + * Calculate the list of application usable extensions. The resulting + * string is stored in \c psc->effectiveGLXexts. + * + * \param psc Pointer to GLX per-screen record. + * \param display_is_direct_capable True if the display is capable of + * direct rendering. + * \param minor_version GLX minor version from the server. + */ + +void +__glXCalculateUsableExtensions(struct glx_screen * psc, + GLboolean display_is_direct_capable, + int minor_version) +{ + unsigned char server_support[8]; + unsigned char usable[8]; + unsigned i; + + __glXExtensionsCtr(); + __glXExtensionsCtrScreen(psc); + + (void) memset(server_support, 0, sizeof(server_support)); + __glXProcessServerString(known_glx_extensions, + psc->serverGLXexts, server_support); + + + /* This is a hack. Some servers support GLX 1.3 but don't export + * all of the extensions implied by GLX 1.3. If the server claims + * support for GLX 1.3, enable support for the extensions that can be + * "emulated" as well. + */ + + if (minor_version >= 3) { + SET_BIT(server_support, EXT_visual_info_bit); + SET_BIT(server_support, EXT_visual_rating_bit); + SET_BIT(server_support, SGI_make_current_read_bit); + SET_BIT(server_support, SGIX_fbconfig_bit); + SET_BIT(server_support, SGIX_pbuffer_bit); + + /* This one is a little iffy. GLX 1.3 doesn't incorporate all of this + * extension. However, the only part that is not strictly client-side + * is shared. That's the glXQueryContext / glXQueryContextInfoEXT + * function. + */ + + SET_BIT(server_support, EXT_import_context_bit); + } + + + /* An extension is supported if the client-side (i.e., libGL) supports + * it and the "server" supports it. In this case that means that either + * the true server supports it or it is only for direct-rendering and + * the direct rendering driver supports it. + * + * If the display is not capable of direct rendering, then the extension + * is enabled if and only if the client-side library and the server + * support it. + */ + + if (display_is_direct_capable) { + for (i = 0; i < 8; i++) { + usable[i] = (client_glx_support[i] & client_glx_only[i]) + | (client_glx_support[i] & psc->direct_support[i] & + server_support[i]) + | (client_glx_support[i] & psc->direct_support[i] & + direct_glx_only[i]); + } + } + else { + for (i = 0; i < 8; i++) { + usable[i] = (client_glx_support[i] & client_glx_only[i]) + | (client_glx_support[i] & server_support[i]); + } + } + + psc->effectiveGLXexts = __glXGetStringFromTable(known_glx_extensions, + usable); +} + + +/** + * Calculate the list of application usable extensions. The resulting + * string is stored in \c gc->extensions. + * + * \param gc Pointer to GLX context. + * \param server_string Extension string from the server. + * \param major_version GL major version from the server. + * \param minor_version GL minor version from the server. + */ + +void +__glXCalculateUsableGLExtensions(struct glx_context * gc, + const char *server_string, + int major_version, int minor_version) +{ + unsigned char server_support[__GL_EXT_BYTES]; + unsigned char usable[__GL_EXT_BYTES]; + unsigned i; + + + __glXExtensionsCtr(); + + (void) memset(server_support, 0, sizeof(server_support)); + __glXProcessServerString(known_gl_extensions, server_string, + server_support); + + + /* Handle lazy servers that don't export all the extensions strings that + * are part of the GL core version that they support. + */ + + for (i = 0; i < __GL_EXT_BYTES; i++) { + if ((known_gl_extensions[i].version_major != 0) + && ((major_version > known_gl_extensions[i].version_major) + || ((major_version == known_gl_extensions[i].version_major) + && (minor_version >= + known_gl_extensions[i].version_minor)))) { + SET_BIT(server_support, known_gl_extensions[i].bit); + } + } + + + /* An extension is supported if the client-side (i.e., libGL) supports + * it and the server supports it or the client-side library supports it + * and it only needs client-side support. + */ + + for (i = 0; i < __GL_EXT_BYTES; i++) { + usable[i] = (client_gl_support[i] & client_gl_only[i]) + | (client_gl_support[i] & server_support[i]); + } + + gc->extensions = (unsigned char *) + __glXGetStringFromTable(known_gl_extensions, usable); + (void) memcpy(gc->gl_extension_bits, usable, sizeof(usable)); +} + + +/** + * Calculates the maximum core GL version that can be supported for indirect + * rendering. + */ +void +__glXGetGLVersion(int *major_version, int *minor_version) +{ + __glXExtensionsCtr(); + *major_version = gl_major; + *minor_version = gl_minor; +} + + +/** + * Get a string representing the set of extensions supported by the client + * library. This is currently only used to send the list of extensions + * supported by the client to the server. + */ +char * +__glXGetClientGLExtensionString(void) +{ + __glXExtensionsCtr(); + return __glXGetStringFromTable(known_gl_extensions, client_gl_support); +} diff --git a/src/glx/glxextensions.h b/src/glx/glxextensions.h new file mode 100644 index 0000000..7877661 --- /dev/null +++ b/src/glx/glxextensions.h @@ -0,0 +1,291 @@ +/* + * (C) Copyright IBM Corporation 2002, 2004 + * 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 + * 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 COPYRIGHT HOLDERS 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. + */ + +/** + * \file glxextensions.h + * + * \author Ian Romanick + */ + +#ifndef GLX_GLXEXTENSIONS_H +#define GLX_GLXEXTENSIONS_H + +enum +{ + ARB_get_proc_address_bit = 0, + ARB_multisample_bit, + ARB_render_texture_bit, + ATI_pixel_format_float_bit, + EXT_visual_info_bit, + EXT_visual_rating_bit, + EXT_import_context_bit, + MESA_agp_offset_bit, + MESA_copy_sub_buffer_bit, + MESA_depth_float_bit, + MESA_pixmap_colormap_bit, + MESA_release_buffers_bit, + MESA_swap_control_bit, + MESA_swap_frame_usage_bit, + NV_float_buffer_bit, + NV_render_depth_texture_bit, + NV_render_texture_rectangle_bit, + NV_vertex_array_range_bit, + OML_swap_method_bit, + OML_sync_control_bit, + SGI_make_current_read_bit, + SGI_swap_control_bit, + SGI_video_sync_bit, + SGIS_blended_overlay_bit, + SGIS_color_range_bit, + SGIS_multisample_bit, + SGIX_fbconfig_bit, + SGIX_pbuffer_bit, + SGIX_swap_barrier_bit, + SGIX_swap_group_bit, + SGIX_visual_select_group_bit, + EXT_texture_from_pixmap_bit, + INTEL_swap_event_bit, +}; + +enum +{ + GL_ARB_depth_texture_bit = 0, + GL_ARB_draw_buffers_bit, + GL_ARB_fragment_program_bit, + GL_ARB_fragment_program_shadow_bit, + GL_ARB_framebuffer_object_bit, + GL_ARB_imaging_bit, + GL_ARB_multisample_bit, + GL_ARB_multitexture_bit, + GL_ARB_occlusion_query_bit, + GL_ARB_point_parameters_bit, + GL_ARB_point_sprite_bit, + GL_ARB_shadow_bit, + GL_ARB_shadow_ambient_bit, + GL_ARB_texture_border_clamp_bit, + GL_ARB_texture_cube_map_bit, + GL_ARB_texture_compression_bit, + GL_ARB_texture_env_add_bit, + GL_ARB_texture_env_combine_bit, + GL_ARB_texture_env_crossbar_bit, + GL_ARB_texture_env_dot3_bit, + GL_ARB_texture_mirrored_repeat_bit, + GL_ARB_texture_non_power_of_two_bit, + GL_ARB_texture_rectangle_bit, + GL_ARB_texture_rg_bit, + GL_ARB_transpose_matrix_bit, + GL_ARB_vertex_buffer_object_bit, + GL_ARB_vertex_program_bit, + GL_ARB_window_pos_bit, + GL_EXT_abgr_bit, + GL_EXT_bgra_bit, + GL_EXT_blend_color_bit, + GL_EXT_blend_equation_separate_bit, + GL_EXT_blend_func_separate_bit, + GL_EXT_blend_logic_op_bit, + GL_EXT_blend_minmax_bit, + GL_EXT_blend_subtract_bit, + GL_EXT_clip_volume_hint_bit, + GL_EXT_compiled_vertex_array_bit, + GL_EXT_convolution_bit, + GL_EXT_copy_texture_bit, + GL_EXT_cull_vertex_bit, + GL_EXT_depth_bounds_test_bit, + GL_EXT_draw_range_elements_bit, + GL_EXT_fog_coord_bit, + GL_EXT_framebuffer_blit_bit, + GL_EXT_framebuffer_multisample_bit, + GL_EXT_framebuffer_object_bit, + GL_EXT_multi_draw_arrays_bit, + GL_EXT_packed_depth_stencil_bit, + GL_EXT_packed_pixels_bit, + GL_EXT_paletted_texture_bit, + GL_EXT_pixel_buffer_object_bit, + GL_EXT_polygon_offset_bit, + GL_EXT_rescale_normal_bit, + GL_EXT_secondary_color_bit, + GL_EXT_separate_specular_color_bit, + GL_EXT_shadow_funcs_bit, + GL_EXT_shared_texture_palette_bit, + GL_EXT_stencil_two_side_bit, + GL_EXT_stencil_wrap_bit, + GL_EXT_subtexture_bit, + GL_EXT_texture_bit, + GL_EXT_texture3D_bit, + GL_EXT_texture_compression_dxt1_bit, + GL_EXT_texture_compression_s3tc_bit, + GL_EXT_texture_edge_clamp_bit, + GL_EXT_texture_env_combine_bit, + GL_EXT_texture_env_dot3_bit, + GL_EXT_texture_filter_anisotropic_bit, + GL_EXT_texture_lod_bit, + GL_EXT_texture_lod_bias_bit, + GL_EXT_texture_mirror_clamp_bit, + GL_EXT_texture_object_bit, + GL_EXT_vertex_array_bit, + GL_3DFX_texture_compression_FXT1_bit, + GL_APPLE_packed_pixels_bit, + GL_APPLE_ycbcr_422_bit, + GL_ATI_text_fragment_shader_bit, + GL_ATI_texture_env_combine3_bit, + GL_ATI_texture_float_bit, + GL_ATI_texture_mirror_once_bit, + GL_HP_convolution_border_modes_bit, + GL_HP_occlusion_test_bit, + GL_IBM_cull_vertex_bit, + GL_IBM_pixel_filter_hint_bit, + GL_IBM_rasterpos_clip_bit, + GL_IBM_texture_clamp_nodraw_bit, + GL_INGR_interlace_read_bit, + GL_MESA_pack_invert_bit, + GL_MESA_ycbcr_texture_bit, + GL_NV_blend_square_bit, + GL_NV_copy_depth_to_color_bit, + GL_NV_depth_clamp_bit, + GL_NV_fog_distance_bit, + GL_NV_fragment_program_bit, + GL_NV_fragment_program_option_bit, + GL_NV_fragment_program2_bit, + GL_NV_light_max_exponent_bit, + GL_NV_multisample_filter_hint_bit, + GL_NV_packed_depth_stencil_bit, + GL_NV_point_sprite_bit, + GL_NV_texgen_reflection_bit, + GL_NV_texture_compression_vtc_bit, + GL_NV_texture_env_combine4_bit, + GL_NV_vertex_program_bit, + GL_NV_vertex_program1_1_bit, + GL_NV_vertex_program2_bit, + GL_NV_vertex_program2_option_bit, + GL_NV_vertex_program3_bit, + GL_OES_compressed_paletted_texture_bit, + GL_OES_read_format_bit, + GL_SGI_color_matrix_bit, + GL_SGI_color_table_bit, + GL_SGI_texture_color_table_bit, + GL_SGIS_generate_mipmap_bit, + GL_SGIS_multisample_bit, + GL_SGIS_texture_lod_bit, + GL_SGIX_blend_alpha_minmax_bit, + GL_SGIX_clipmap_bit, + GL_SGIX_depth_texture_bit, + GL_SGIX_fog_offset_bit, + GL_SGIX_shadow_bit, + GL_SGIX_texture_coordinate_clamp_bit, + GL_SGIX_texture_lod_bias_bit, + GL_SGIX_texture_range_bit, + GL_SGIX_texture_scale_bias_bit, + GL_SGIX_vertex_preclip_bit, + GL_SGIX_vertex_preclip_hint_bit, + GL_SGIX_ycrcb_bit, + GL_SUN_convolution_border_modes_bit, + GL_SUN_slice_accum_bit, + + /* This *MUST* go here. If it gets put after the duplicate values it will + * get the value after the last duplicate. + */ + __NUM_GL_EXTS, + + + /* Alias extension bits. These extensions exist in either vendor-specific + * or EXT form and were later promoted to either EXT or ARB form. In all + * cases, the meaning is *exactly* the same. That's why + * EXT_texture_env_combine is *NOT* an alias of ARB_texture_env_combine and + * EXT_texture_env_dot3 is *NOT* an alias of ARB_texture_env_dot3. Be + * careful! When in doubt, src/mesa/main/extensions.c in the Mesa tree + * is a great reference. + */ + + GL_ATI_blend_equation_separate_bit = GL_EXT_blend_equation_separate_bit, + GL_ATI_draw_buffers_bit = GL_ARB_draw_buffers_bit, + GL_ATIX_texture_env_combine3_bit = GL_ATI_texture_env_combine3_bit, + GL_EXT_point_parameters_bit = GL_ARB_point_parameters_bit, + GL_EXT_texture_env_add_bit = GL_ARB_texture_env_add_bit, + GL_EXT_texture_rectangle_bit = GL_ARB_texture_rectangle_bit, + GL_IBM_texture_mirrored_repeat_bit = GL_ARB_texture_mirrored_repeat_bit, + GL_INGR_blend_func_separate_bit = GL_EXT_blend_func_separate_bit, + GL_MESA_window_pos_bit = GL_ARB_window_pos_bit, + GL_NV_texture_rectangle_bit = GL_ARB_texture_rectangle_bit, + GL_SGIS_texture_border_clamp_bit = GL_ARB_texture_border_clamp_bit, + GL_SGIS_texture_edge_clamp_bit = GL_EXT_texture_edge_clamp_bit, + GL_SGIX_shadow_ambient_bit = GL_ARB_shadow_ambient_bit, + GL_SUN_multi_draw_arrays_bit = GL_EXT_multi_draw_arrays_bit +}; + +#define __GL_EXT_BYTES ((__NUM_GL_EXTS + 7) / 8) + +struct glx_screen; +struct glx_context; + +extern GLboolean __glXExtensionBitIsEnabled(struct glx_screen *psc, + unsigned bit); +extern const char *__glXGetClientExtensions(void); +extern void __glXCalculateUsableExtensions(struct glx_screen *psc, + GLboolean + display_is_direct_capable, + int server_minor_version); + +extern void __glXCalculateUsableGLExtensions(struct glx_context *gc, + const char *server_string, + int major_version, + int minor_version); +extern void __glXGetGLVersion(int *major_version, int *minor_version); +extern char *__glXGetClientGLExtensionString(void); + +extern GLboolean __glExtensionBitIsEnabled(struct glx_context *gc, + unsigned bit); + +extern void +__glXEnableDirectExtension(struct glx_screen *psc, const char *name); + +/* Source-level backwards compatibility with old drivers. They won't + * find the respective functions, though. + */ +typedef void (*PFNGLXENABLEEXTENSIONPROC) (const char *name, + GLboolean force_client); +typedef void (*PFNGLXDISABLEEXTENSIONPROC) (const char *name); + +/* GLX_ALIAS should be used for functions with a non-void return type. + GLX_ALIAS_VOID is for functions with a void return type. */ +#ifdef GLX_NO_STATIC_EXTENSION_FUNCTIONS +# define GLX_ALIAS(return_type, real_func, proto_args, args, aliased_func) +# define GLX_ALIAS_VOID(real_func, proto_args, args, aliased_func) +#else +# if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED) +# define GLX_ALIAS(return_type, real_func, proto_args, args, aliased_func) \ + return_type real_func proto_args \ + __attribute__ ((alias( # aliased_func ) )); +# define GLX_ALIAS_VOID(real_func, proto_args, args, aliased_func) \ + GLX_ALIAS(void, real_func, proto_args, args, aliased_func) +# else +# define GLX_ALIAS(return_type, real_func, proto_args, args, aliased_func) \ + return_type real_func proto_args \ + { return aliased_func args ; } +# define GLX_ALIAS_VOID(real_func, proto_args, args, aliased_func) \ + void real_func proto_args \ + { aliased_func args ; } +# endif /* __GNUC__ */ +#endif /* GLX_NO_STATIC_EXTENSION_FUNCTIONS */ + +#endif /* GLX_GLXEXTENSIONS_H */ diff --git a/src/glx/glxhash.c b/src/glx/glxhash.c new file mode 100644 index 0000000..b76ec32 --- /dev/null +++ b/src/glx/glxhash.c @@ -0,0 +1,473 @@ +/* glxhash.c -- Small hash table support for integer -> integer mapping + * Taken from libdrm. + * + * Created: Sun Apr 18 09:35:45 1999 by faith@precisioninsight.com + * + * Copyright 1999 Precision Insight, 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, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PRECISION INSIGHT 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. + * + * Authors: Rickard E. (Rik) Faith + * + * DESCRIPTION + * + * This file contains a straightforward implementation of a fixed-sized + * hash table using self-organizing linked lists [Knuth73, pp. 398-399] for + * collision resolution. There are two potentially interesting things + * about this implementation: + * + * 1) The table is power-of-two sized. Prime sized tables are more + * traditional, but do not have a significant advantage over power-of-two + * sized table, especially when double hashing is not used for collision + * resolution. + * + * 2) The hash computation uses a table of random integers [Hanson97, + * pp. 39-41]. + * + * FUTURE ENHANCEMENTS + * + * With a table size of 512, the current implementation is sufficient for a + * few hundred keys. Since this is well above the expected size of the + * tables for which this implementation was designed, the implementation of + * dynamic hash tables was postponed until the need arises. A common (and + * naive) approach to dynamic hash table implementation simply creates a + * new hash table when necessary, rehashes all the data into the new table, + * and destroys the old table. The approach in [Larson88] is superior in + * two ways: 1) only a portion of the table is expanded when needed, + * distributing the expansion cost over several insertions, and 2) portions + * of the table can be locked, enabling a scalable thread-safe + * implementation. + * + * REFERENCES + * + * [Hanson97] David R. Hanson. C Interfaces and Implementations: + * Techniques for Creating Reusable Software. Reading, Massachusetts: + * Addison-Wesley, 1997. + * + * [Knuth73] Donald E. Knuth. The Art of Computer Programming. Volume 3: + * Sorting and Searching. Reading, Massachusetts: Addison-Wesley, 1973. + * + * [Larson88] Per-Ake Larson. "Dynamic Hash Tables". CACM 31(4), April + * 1988, pp. 446-457. + * + */ + +#include "glxhash.h" +#include + +#define HASH_MAIN 0 + +#include +#include +#include + +#define HASH_MAGIC 0xdeadbeef +#define HASH_DEBUG 0 +#define HASH_SIZE 512 /* Good for about 100 entries */ + /* If you change this value, you probably + have to change the HashHash hashing + function! */ + +#define HASH_ALLOC malloc +#define HASH_FREE free +#ifndef __GLIBC__ +#define HASH_RANDOM_DECL char *ps, rs[256] +#define HASH_RANDOM_INIT(seed) ps = initstate(seed, rs, sizeof(rs)) +#define HASH_RANDOM random() +#define HASH_RANDOM_DESTROY setstate(ps) +#else +#define HASH_RANDOM_DECL struct random_data rd; int32_t rv; char rs[256] +#define HASH_RANDOM_INIT(seed) \ + do { \ + (void) memset(&rd, 0, sizeof(rd)); \ + (void) initstate_r(seed, rs, sizeof(rs), &rd); \ + } while(0) +#define HASH_RANDOM ((void) random_r(&rd, &rv), rv) +#define HASH_RANDOM_DESTROY +#endif + +typedef struct __glxHashBucket +{ + unsigned long key; + void *value; + struct __glxHashBucket *next; +} __glxHashBucket, *__glxHashBucketPtr; + +typedef struct __glxHashTable *__glxHashTablePtr; +struct __glxHashTable +{ + unsigned long magic; + unsigned long hits; /* At top of linked list */ + unsigned long partials; /* Not at top of linked list */ + unsigned long misses; /* Not in table */ + __glxHashBucketPtr buckets[HASH_SIZE]; + int p0; + __glxHashBucketPtr p1; +}; + +static unsigned long +HashHash(unsigned long key) +{ + unsigned long hash = 0; + unsigned long tmp = key; + static int init = 0; + static unsigned long scatter[256]; + int i; + + if (!init) { + HASH_RANDOM_DECL; + HASH_RANDOM_INIT(37); + for (i = 0; i < 256; i++) + scatter[i] = HASH_RANDOM; + HASH_RANDOM_DESTROY; + ++init; + } + + while (tmp) { + hash = (hash << 1) + scatter[tmp & 0xff]; + tmp >>= 8; + } + + hash %= HASH_SIZE; +#if HASH_DEBUG + printf("Hash(%d) = %d\n", key, hash); +#endif + return hash; +} + +_X_HIDDEN __glxHashTable * +__glxHashCreate(void) +{ + __glxHashTablePtr table; + int i; + + table = HASH_ALLOC(sizeof(*table)); + if (!table) + return NULL; + table->magic = HASH_MAGIC; + table->hits = 0; + table->partials = 0; + table->misses = 0; + + for (i = 0; i < HASH_SIZE; i++) + table->buckets[i] = NULL; + return table; +} + +_X_HIDDEN int +__glxHashDestroy(__glxHashTable * t) +{ + __glxHashTablePtr table = (__glxHashTablePtr) t; + __glxHashBucketPtr bucket; + __glxHashBucketPtr next; + int i; + + if (table->magic != HASH_MAGIC) + return -1; /* Bad magic */ + + for (i = 0; i < HASH_SIZE; i++) { + for (bucket = table->buckets[i]; bucket;) { + next = bucket->next; + HASH_FREE(bucket); + bucket = next; + } + } + HASH_FREE(table); + return 0; +} + +/* Find the bucket and organize the list so that this bucket is at the + top. */ + +static __glxHashBucketPtr +HashFind(__glxHashTablePtr table, unsigned long key, unsigned long *h) +{ + unsigned long hash = HashHash(key); + __glxHashBucketPtr prev = NULL; + __glxHashBucketPtr bucket; + + if (h) + *h = hash; + + for (bucket = table->buckets[hash]; bucket; bucket = bucket->next) { + if (bucket->key == key) { + if (prev) { + /* Organize */ + prev->next = bucket->next; + bucket->next = table->buckets[hash]; + table->buckets[hash] = bucket; + ++table->partials; + } + else { + ++table->hits; + } + return bucket; + } + prev = bucket; + } + ++table->misses; + return NULL; +} + +_X_HIDDEN int +__glxHashLookup(__glxHashTable * t, unsigned long key, void **value) +{ + __glxHashTablePtr table = (__glxHashTablePtr) t; + __glxHashBucketPtr bucket; + + if (!table || table->magic != HASH_MAGIC) + return -1; /* Bad magic */ + + bucket = HashFind(table, key, NULL); + if (!bucket) + return 1; /* Not found */ + *value = bucket->value; + return 0; /* Found */ +} + +_X_HIDDEN int +__glxHashInsert(__glxHashTable * t, unsigned long key, void *value) +{ + __glxHashTablePtr table = (__glxHashTablePtr) t; + __glxHashBucketPtr bucket; + unsigned long hash; + + if (table->magic != HASH_MAGIC) + return -1; /* Bad magic */ + + if (HashFind(table, key, &hash)) + return 1; /* Already in table */ + + bucket = HASH_ALLOC(sizeof(*bucket)); + if (!bucket) + return -1; /* Error */ + bucket->key = key; + bucket->value = value; + bucket->next = table->buckets[hash]; + table->buckets[hash] = bucket; +#if HASH_DEBUG + printf("Inserted %d at %d/%p\n", key, hash, bucket); +#endif + return 0; /* Added to table */ +} + +_X_HIDDEN int +__glxHashDelete(__glxHashTable * t, unsigned long key) +{ + __glxHashTablePtr table = (__glxHashTablePtr) t; + unsigned long hash; + __glxHashBucketPtr bucket; + + if (table->magic != HASH_MAGIC) + return -1; /* Bad magic */ + + bucket = HashFind(table, key, &hash); + + if (!bucket) + return 1; /* Not found */ + + table->buckets[hash] = bucket->next; + HASH_FREE(bucket); + return 0; +} + +_X_HIDDEN int +__glxHashNext(__glxHashTable * t, unsigned long *key, void **value) +{ + __glxHashTablePtr table = (__glxHashTablePtr) t; + + while (table->p0 < HASH_SIZE) { + if (table->p1) { + *key = table->p1->key; + *value = table->p1->value; + table->p1 = table->p1->next; + return 1; + } + table->p1 = table->buckets[table->p0]; + ++table->p0; + } + return 0; +} + +_X_HIDDEN int +__glxHashFirst(__glxHashTable * t, unsigned long *key, void **value) +{ + __glxHashTablePtr table = (__glxHashTablePtr) t; + + if (table->magic != HASH_MAGIC) + return -1; /* Bad magic */ + + table->p0 = 0; + table->p1 = table->buckets[0]; + return __glxHashNext(table, key, value); +} + +#if HASH_MAIN +#define DIST_LIMIT 10 +static int dist[DIST_LIMIT]; + +static void +clear_dist(void) +{ + int i; + + for (i = 0; i < DIST_LIMIT; i++) + dist[i] = 0; +} + +static int +count_entries(__glxHashBucketPtr bucket) +{ + int count = 0; + + for (; bucket; bucket = bucket->next) + ++count; + return count; +} + +static void +update_dist(int count) +{ + if (count >= DIST_LIMIT) + ++dist[DIST_LIMIT - 1]; + else + ++dist[count]; +} + +static void +compute_dist(__glxHashTablePtr table) +{ + int i; + __glxHashBucketPtr bucket; + + printf("Hits = %ld, partials = %ld, misses = %ld\n", + table->hits, table->partials, table->misses); + clear_dist(); + for (i = 0; i < HASH_SIZE; i++) { + bucket = table->buckets[i]; + update_dist(count_entries(bucket)); + } + for (i = 0; i < DIST_LIMIT; i++) { + if (i != DIST_LIMIT - 1) + printf("%5d %10d\n", i, dist[i]); + else + printf("other %10d\n", dist[i]); + } +} + +static void +check_table(__glxHashTablePtr table, unsigned long key, unsigned long value) +{ + unsigned long retval = 0; + int retcode = __glxHashLookup(table, key, &retval); + + switch (retcode) { + case -1: + printf("Bad magic = 0x%08lx:" + " key = %lu, expected = %lu, returned = %lu\n", + table->magic, key, value, retval); + break; + case 1: + printf("Not found: key = %lu, expected = %lu returned = %lu\n", + key, value, retval); + break; + case 0: + if (value != retval) + printf("Bad value: key = %lu, expected = %lu, returned = %lu\n", + key, value, retval); + break; + default: + printf("Bad retcode = %d: key = %lu, expected = %lu, returned = %lu\n", + retcode, key, value, retval); + break; + } +} + +int +main(void) +{ + __glxHashTablePtr table; + int i; + + printf("\n***** 256 consecutive integers ****\n"); + table = __glxHashCreate(); + for (i = 0; i < 256; i++) + __glxHashInsert(table, i, i); + for (i = 0; i < 256; i++) + check_table(table, i, i); + for (i = 256; i >= 0; i--) + check_table(table, i, i); + compute_dist(table); + __glxHashDestroy(table); + + printf("\n***** 1024 consecutive integers ****\n"); + table = __glxHashCreate(); + for (i = 0; i < 1024; i++) + __glxHashInsert(table, i, i); + for (i = 0; i < 1024; i++) + check_table(table, i, i); + for (i = 1024; i >= 0; i--) + check_table(table, i, i); + compute_dist(table); + __glxHashDestroy(table); + + printf("\n***** 1024 consecutive page addresses (4k pages) ****\n"); + table = __glxHashCreate(); + for (i = 0; i < 1024; i++) + __glxHashInsert(table, i * 4096, i); + for (i = 0; i < 1024; i++) + check_table(table, i * 4096, i); + for (i = 1024; i >= 0; i--) + check_table(table, i * 4096, i); + compute_dist(table); + __glxHashDestroy(table); + + printf("\n***** 1024 random integers ****\n"); + table = __glxHashCreate(); + srandom(0xbeefbeef); + for (i = 0; i < 1024; i++) + __glxHashInsert(table, random(), i); + srandom(0xbeefbeef); + for (i = 0; i < 1024; i++) + check_table(table, random(), i); + srandom(0xbeefbeef); + for (i = 0; i < 1024; i++) + check_table(table, random(), i); + compute_dist(table); + __glxHashDestroy(table); + + printf("\n***** 5000 random integers ****\n"); + table = __glxHashCreate(); + srandom(0xbeefbeef); + for (i = 0; i < 5000; i++) + __glxHashInsert(table, random(), i); + srandom(0xbeefbeef); + for (i = 0; i < 5000; i++) + check_table(table, random(), i); + srandom(0xbeefbeef); + for (i = 0; i < 5000; i++) + check_table(table, random(), i); + compute_dist(table); + __glxHashDestroy(table); + + return 0; +} +#endif diff --git a/src/glx/glxhash.h b/src/glx/glxhash.h new file mode 100644 index 0000000..710712d --- /dev/null +++ b/src/glx/glxhash.h @@ -0,0 +1,20 @@ +#ifndef _GLX_HASH_H_ +#define _GLX_HASH_H_ + + +typedef struct __glxHashTable __glxHashTable; + +/* Hash table routines */ +extern __glxHashTable *__glxHashCreate(void); +extern int __glxHashDestroy(__glxHashTable * t); +extern int __glxHashLookup(__glxHashTable * t, unsigned long key, + void **value); +extern int __glxHashInsert(__glxHashTable * t, unsigned long key, + void *value); +extern int __glxHashDelete(__glxHashTable * t, unsigned long key); +extern int __glxHashFirst(__glxHashTable * t, unsigned long *key, + void **value); +extern int __glxHashNext(__glxHashTable * t, unsigned long *key, + void **value); + +#endif /* _GLX_HASH_H_ */ diff --git a/src/glx/indirect.c b/src/glx/indirect.c new file mode 100644 index 0000000..49938a1 --- /dev/null +++ b/src/glx/indirect.c @@ -0,0 +1,10661 @@ +/* DO NOT EDIT - This file generated automatically by glX_proto_send.py (from Mesa) script */ + +/* + * (C) Copyright IBM Corporation 2004, 2005 + * 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 + * IBM, + * 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 +#include "indirect.h" +#include "glxclient.h" +#include "indirect_size.h" +#include "glapi.h" +#include "glthread.h" +#include +#ifdef USE_XCB +#include +#include +#include +#endif /* USE_XCB */ + +#define __GLX_PAD(n) (((n) + 3) & ~3) + +# if defined(__i386__) && defined(__GNUC__) && !defined(__CYGWIN__) && !defined(__MINGW32__) +# define FASTCALL __attribute__((fastcall)) +# else +# define FASTCALL +# endif +# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define NOINLINE __attribute__((noinline)) +# else +# define NOINLINE +# endif + +#ifndef __GNUC__ +# define __builtin_expect(x, y) x +#endif + +/* If the size and opcode values are known at compile-time, this will, on + * x86 at least, emit them with a single instruction. + */ +#define emit_header(dest, op, size) \ + do { union { short s[2]; int i; } temp; \ + temp.s[0] = (size); temp.s[1] = (op); \ + *((int *)(dest)) = temp.i; } while(0) + +NOINLINE CARD32 +__glXReadReply(Display * dpy, size_t size, void *dest, + GLboolean reply_is_always_array) +{ + xGLXSingleReply reply; + + (void) _XReply(dpy, (xReply *) & reply, 0, False); + if (size != 0) { + if ((reply.length > 0) || reply_is_always_array) { + const GLint bytes = (reply_is_always_array) + ? (4 * reply.length) : (reply.size * size); + const GLint extra = 4 - (bytes & 3); + + _XRead(dpy, dest, bytes); + if (extra < 4) { + _XEatData(dpy, extra); + } + } else { + (void) memcpy(dest, &(reply.pad3), size); + } + } + + return reply.retval; +} + +NOINLINE void +__glXReadPixelReply(Display * dpy, struct glx_context *gc, unsigned max_dim, + GLint width, GLint height, GLint depth, GLenum format, + GLenum type, void *dest, GLboolean dimensions_in_reply) +{ + xGLXSingleReply reply; + GLint size; + + (void) _XReply(dpy, (xReply *) & reply, 0, False); + + if (dimensions_in_reply) { + width = reply.pad3; + height = reply.pad4; + depth = reply.pad5; + + if ((height == 0) || (max_dim < 2)) { + height = 1; + } + if ((depth == 0) || (max_dim < 3)) { + depth = 1; + } + } + + size = reply.length * 4; + if (size != 0) { + void *buf = Xmalloc(size); + + if (buf == NULL) { + _XEatData(dpy, size); + __glXSetError(gc, GL_OUT_OF_MEMORY); + } else { + const GLint extra = 4 - (size & 3); + + _XRead(dpy, buf, size); + if (extra < 4) { + _XEatData(dpy, extra); + } + + __glEmptyImage(gc, 3, width, height, depth, format, type, + buf, dest); + Xfree(buf); + } + } +} + +#define X_GLXSingle 0 + +NOINLINE FASTCALL GLubyte * +__glXSetupSingleRequest(struct glx_context *gc, GLint sop, GLint cmdlen) +{ + xGLXSingleReq *req; + Display *const dpy = gc->currentDpy; + + (void) __glXFlushRenderBuffer(gc, gc->pc); + LockDisplay(dpy); + GetReqExtra(GLXSingle, cmdlen, req); + req->reqType = gc->majorOpcode; + req->contextTag = gc->currentContextTag; + req->glxCode = sop; + return (GLubyte *) (req) + sz_xGLXSingleReq; +} + +NOINLINE FASTCALL GLubyte * +__glXSetupVendorRequest(struct glx_context *gc, GLint code, GLint vop, + GLint cmdlen) +{ + xGLXVendorPrivateReq *req; + Display *const dpy = gc->currentDpy; + + (void) __glXFlushRenderBuffer(gc, gc->pc); + LockDisplay(dpy); + GetReqExtra(GLXVendorPrivate, cmdlen, req); + req->reqType = gc->majorOpcode; + req->glxCode = code; + req->vendorCode = vop; + req->contextTag = gc->currentContextTag; + return (GLubyte *) (req) + sz_xGLXVendorPrivateReq; +} + +const GLuint __glXDefaultPixelStore[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + +#define zero (__glXDefaultPixelStore+0) +#define one (__glXDefaultPixelStore+8) +#define default_pixel_store_1D (__glXDefaultPixelStore+4) +#define default_pixel_store_1D_size 20 +#define default_pixel_store_2D (__glXDefaultPixelStore+4) +#define default_pixel_store_2D_size 20 +#define default_pixel_store_3D (__glXDefaultPixelStore+0) +#define default_pixel_store_3D_size 36 +#define default_pixel_store_4D (__glXDefaultPixelStore+0) +#define default_pixel_store_4D_size 36 + +static FASTCALL NOINLINE void +generic_3_byte(GLint rop, const void *ptr) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + + emit_header(gc->pc, rop, cmdlen); + (void) memcpy((void *) (gc->pc + 4), ptr, 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +static FASTCALL NOINLINE void +generic_4_byte(GLint rop, const void *ptr) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + + emit_header(gc->pc, rop, cmdlen); + (void) memcpy((void *) (gc->pc + 4), ptr, 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +static FASTCALL NOINLINE void +generic_6_byte(GLint rop, const void *ptr) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + + emit_header(gc->pc, rop, cmdlen); + (void) memcpy((void *) (gc->pc + 4), ptr, 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +static FASTCALL NOINLINE void +generic_8_byte(GLint rop, const void *ptr) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + + emit_header(gc->pc, rop, cmdlen); + (void) memcpy((void *) (gc->pc + 4), ptr, 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +static FASTCALL NOINLINE void +generic_12_byte(GLint rop, const void *ptr) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + + emit_header(gc->pc, rop, cmdlen); + (void) memcpy((void *) (gc->pc + 4), ptr, 12); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +static FASTCALL NOINLINE void +generic_16_byte(GLint rop, const void *ptr) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + + emit_header(gc->pc, rop, cmdlen); + (void) memcpy((void *) (gc->pc + 4), ptr, 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +static FASTCALL NOINLINE void +generic_24_byte(GLint rop, const void *ptr) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + + emit_header(gc->pc, rop, cmdlen); + (void) memcpy((void *) (gc->pc + 4), ptr, 24); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +static FASTCALL NOINLINE void +generic_32_byte(GLint rop, const void *ptr) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 36; + + emit_header(gc->pc, rop, cmdlen); + (void) memcpy((void *) (gc->pc + 4), ptr, 32); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLsop_NewList 101 +void +__indirect_glNewList(GLuint list, GLenum mode) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_new_list(c, gc->currentContextTag, list, mode); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_NewList, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&list), 4); + (void) memcpy((void *) (pc + 4), (void *) (&mode), 4); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_EndList 102 +void +__indirect_glEndList(void) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 0; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_end_list(c, gc->currentContextTag); +#else + (void) __glXSetupSingleRequest(gc, X_GLsop_EndList, cmdlen); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLrop_CallList 1 +void +__indirect_glCallList(GLuint list) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_CallList, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&list), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_CallLists 2 +void +__indirect_glCallLists(GLsizei n, GLenum type, const GLvoid * lists) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glCallLists_size(type); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * n)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((n >= 0) && (gc->currentDpy != NULL), 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, X_GLrop_CallLists, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&type), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (lists), + (compsize * n)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = X_GLrop_CallLists; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 8), (void *) (&n), 4); + (void) memcpy((void *) (pc + 12), (void *) (&type), 4); + __glXSendLargeCommand(gc, pc, 16, lists, (compsize * n)); + } + } +} + +#define X_GLsop_DeleteLists 103 +void +__indirect_glDeleteLists(GLuint list, GLsizei range) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_delete_lists(c, gc->currentContextTag, list, range); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_DeleteLists, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&list), 4); + (void) memcpy((void *) (pc + 4), (void *) (&range), 4); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GenLists 104 +GLuint +__indirect_glGenLists(GLsizei range) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + GLuint retval = (GLuint) 0; +#ifndef USE_XCB + const GLuint cmdlen = 4; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_gen_lists_reply_t *reply = + xcb_glx_gen_lists_reply(c, + xcb_glx_gen_lists(c, + gc->currentContextTag, + range), NULL); + retval = reply->ret_val; + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GenLists, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&range), 4); + retval = (GLuint) __glXReadReply(dpy, 0, NULL, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return retval; +} + +#define X_GLrop_ListBase 3 +void +__indirect_glListBase(GLuint base) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_ListBase, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&base), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Begin 4 +void +__indirect_glBegin(GLenum mode) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_Begin, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&mode), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Bitmap 5 +void +__indirect_glBitmap(GLsizei width, GLsizei height, GLfloat xorig, + GLfloat yorig, GLfloat xmove, GLfloat ymove, + const GLubyte *bitmap) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = + (bitmap != NULL) ? __glImageSize(width, height, 1, GL_COLOR_INDEX, + GL_BITMAP, 0) : 0; + const GLuint cmdlen = 48 + __GLX_PAD(compsize); + if (__builtin_expect(gc->currentDpy != NULL, 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, X_GLrop_Bitmap, cmdlen); + (void) memcpy((void *) (gc->pc + 24), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 28), (void *) (&height), 4); + (void) memcpy((void *) (gc->pc + 32), (void *) (&xorig), 4); + (void) memcpy((void *) (gc->pc + 36), (void *) (&yorig), 4); + (void) memcpy((void *) (gc->pc + 40), (void *) (&xmove), 4); + (void) memcpy((void *) (gc->pc + 44), (void *) (&ymove), 4); + if (compsize > 0) { + (*gc->fillImage) (gc, 2, width, height, 1, GL_COLOR_INDEX, + GL_BITMAP, bitmap, gc->pc + 48, gc->pc + 4); + } else { + (void) memcpy(gc->pc + 4, default_pixel_store_2D, + default_pixel_store_2D_size); + } + gc->pc += cmdlen; + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = X_GLrop_Bitmap; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 28), (void *) (&width), 4); + (void) memcpy((void *) (pc + 32), (void *) (&height), 4); + (void) memcpy((void *) (pc + 36), (void *) (&xorig), 4); + (void) memcpy((void *) (pc + 40), (void *) (&yorig), 4); + (void) memcpy((void *) (pc + 44), (void *) (&xmove), 4); + (void) memcpy((void *) (pc + 48), (void *) (&ymove), 4); + __glXSendLargeImage(gc, compsize, 2, width, height, 1, + GL_COLOR_INDEX, GL_BITMAP, bitmap, pc + 52, + pc + 8); + } + } +} + +#define X_GLrop_Color3bv 6 +void +__indirect_glColor3b(GLbyte red, GLbyte green, GLbyte blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_Color3bv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 1); + (void) memcpy((void *) (gc->pc + 5), (void *) (&green), 1); + (void) memcpy((void *) (gc->pc + 6), (void *) (&blue), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color3bv 6 +void +__indirect_glColor3bv(const GLbyte *v) +{ + generic_3_byte(X_GLrop_Color3bv, v); +} + +#define X_GLrop_Color3dv 7 +void +__indirect_glColor3d(GLdouble red, GLdouble green, GLdouble blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_Color3dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&green), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&blue), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color3dv 7 +void +__indirect_glColor3dv(const GLdouble * v) +{ + generic_24_byte(X_GLrop_Color3dv, v); +} + +#define X_GLrop_Color3fv 8 +void +__indirect_glColor3f(GLfloat red, GLfloat green, GLfloat blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_Color3fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&green), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&blue), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color3fv 8 +void +__indirect_glColor3fv(const GLfloat * v) +{ + generic_12_byte(X_GLrop_Color3fv, v); +} + +#define X_GLrop_Color3iv 9 +void +__indirect_glColor3i(GLint red, GLint green, GLint blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_Color3iv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&green), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&blue), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color3iv 9 +void +__indirect_glColor3iv(const GLint * v) +{ + generic_12_byte(X_GLrop_Color3iv, v); +} + +#define X_GLrop_Color3sv 10 +void +__indirect_glColor3s(GLshort red, GLshort green, GLshort blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Color3sv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&green), 2); + (void) memcpy((void *) (gc->pc + 8), (void *) (&blue), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color3sv 10 +void +__indirect_glColor3sv(const GLshort * v) +{ + generic_6_byte(X_GLrop_Color3sv, v); +} + +#define X_GLrop_Color3ubv 11 +void +__indirect_glColor3ub(GLubyte red, GLubyte green, GLubyte blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_Color3ubv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 1); + (void) memcpy((void *) (gc->pc + 5), (void *) (&green), 1); + (void) memcpy((void *) (gc->pc + 6), (void *) (&blue), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color3ubv 11 +void +__indirect_glColor3ubv(const GLubyte *v) +{ + generic_3_byte(X_GLrop_Color3ubv, v); +} + +#define X_GLrop_Color3uiv 12 +void +__indirect_glColor3ui(GLuint red, GLuint green, GLuint blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_Color3uiv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&green), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&blue), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color3uiv 12 +void +__indirect_glColor3uiv(const GLuint * v) +{ + generic_12_byte(X_GLrop_Color3uiv, v); +} + +#define X_GLrop_Color3usv 13 +void +__indirect_glColor3us(GLushort red, GLushort green, GLushort blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Color3usv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&green), 2); + (void) memcpy((void *) (gc->pc + 8), (void *) (&blue), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color3usv 13 +void +__indirect_glColor3usv(const GLushort * v) +{ + generic_6_byte(X_GLrop_Color3usv, v); +} + +#define X_GLrop_Color4bv 14 +void +__indirect_glColor4b(GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_Color4bv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 1); + (void) memcpy((void *) (gc->pc + 5), (void *) (&green), 1); + (void) memcpy((void *) (gc->pc + 6), (void *) (&blue), 1); + (void) memcpy((void *) (gc->pc + 7), (void *) (&alpha), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color4bv 14 +void +__indirect_glColor4bv(const GLbyte *v) +{ + generic_4_byte(X_GLrop_Color4bv, v); +} + +#define X_GLrop_Color4dv 15 +void +__indirect_glColor4d(GLdouble red, GLdouble green, GLdouble blue, + GLdouble alpha) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 36; + emit_header(gc->pc, X_GLrop_Color4dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&green), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&blue), 8); + (void) memcpy((void *) (gc->pc + 28), (void *) (&alpha), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color4dv 15 +void +__indirect_glColor4dv(const GLdouble * v) +{ + generic_32_byte(X_GLrop_Color4dv, v); +} + +#define X_GLrop_Color4fv 16 +void +__indirect_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_Color4fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&green), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&blue), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&alpha), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color4fv 16 +void +__indirect_glColor4fv(const GLfloat * v) +{ + generic_16_byte(X_GLrop_Color4fv, v); +} + +#define X_GLrop_Color4iv 17 +void +__indirect_glColor4i(GLint red, GLint green, GLint blue, GLint alpha) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_Color4iv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&green), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&blue), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&alpha), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color4iv 17 +void +__indirect_glColor4iv(const GLint * v) +{ + generic_16_byte(X_GLrop_Color4iv, v); +} + +#define X_GLrop_Color4sv 18 +void +__indirect_glColor4s(GLshort red, GLshort green, GLshort blue, GLshort alpha) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Color4sv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&green), 2); + (void) memcpy((void *) (gc->pc + 8), (void *) (&blue), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&alpha), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color4sv 18 +void +__indirect_glColor4sv(const GLshort * v) +{ + generic_8_byte(X_GLrop_Color4sv, v); +} + +#define X_GLrop_Color4ubv 19 +void +__indirect_glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_Color4ubv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 1); + (void) memcpy((void *) (gc->pc + 5), (void *) (&green), 1); + (void) memcpy((void *) (gc->pc + 6), (void *) (&blue), 1); + (void) memcpy((void *) (gc->pc + 7), (void *) (&alpha), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color4ubv 19 +void +__indirect_glColor4ubv(const GLubyte *v) +{ + generic_4_byte(X_GLrop_Color4ubv, v); +} + +#define X_GLrop_Color4uiv 20 +void +__indirect_glColor4ui(GLuint red, GLuint green, GLuint blue, GLuint alpha) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_Color4uiv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&green), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&blue), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&alpha), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color4uiv 20 +void +__indirect_glColor4uiv(const GLuint * v) +{ + generic_16_byte(X_GLrop_Color4uiv, v); +} + +#define X_GLrop_Color4usv 21 +void +__indirect_glColor4us(GLushort red, GLushort green, GLushort blue, + GLushort alpha) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Color4usv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&green), 2); + (void) memcpy((void *) (gc->pc + 8), (void *) (&blue), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&alpha), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Color4usv 21 +void +__indirect_glColor4usv(const GLushort * v) +{ + generic_8_byte(X_GLrop_Color4usv, v); +} + +#define X_GLrop_EdgeFlagv 22 +void +__indirect_glEdgeFlag(GLboolean flag) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_EdgeFlagv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&flag), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_EdgeFlagv 22 +void +__indirect_glEdgeFlagv(const GLboolean * flag) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_EdgeFlagv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (flag), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_End 23 +void +__indirect_glEnd(void) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 4; + emit_header(gc->pc, X_GLrop_End, cmdlen); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Indexdv 24 +void +__indirect_glIndexd(GLdouble c) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Indexdv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&c), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Indexdv 24 +void +__indirect_glIndexdv(const GLdouble * c) +{ + generic_8_byte(X_GLrop_Indexdv, c); +} + +#define X_GLrop_Indexfv 25 +void +__indirect_glIndexf(GLfloat c) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_Indexfv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&c), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Indexfv 25 +void +__indirect_glIndexfv(const GLfloat * c) +{ + generic_4_byte(X_GLrop_Indexfv, c); +} + +#define X_GLrop_Indexiv 26 +void +__indirect_glIndexi(GLint c) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_Indexiv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&c), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Indexiv 26 +void +__indirect_glIndexiv(const GLint * c) +{ + generic_4_byte(X_GLrop_Indexiv, c); +} + +#define X_GLrop_Indexsv 27 +void +__indirect_glIndexs(GLshort c) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_Indexsv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&c), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Indexsv 27 +void +__indirect_glIndexsv(const GLshort * c) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_Indexsv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (c), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Normal3bv 28 +void +__indirect_glNormal3b(GLbyte nx, GLbyte ny, GLbyte nz) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_Normal3bv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&nx), 1); + (void) memcpy((void *) (gc->pc + 5), (void *) (&ny), 1); + (void) memcpy((void *) (gc->pc + 6), (void *) (&nz), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Normal3bv 28 +void +__indirect_glNormal3bv(const GLbyte *v) +{ + generic_3_byte(X_GLrop_Normal3bv, v); +} + +#define X_GLrop_Normal3dv 29 +void +__indirect_glNormal3d(GLdouble nx, GLdouble ny, GLdouble nz) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_Normal3dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&nx), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&ny), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&nz), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Normal3dv 29 +void +__indirect_glNormal3dv(const GLdouble * v) +{ + generic_24_byte(X_GLrop_Normal3dv, v); +} + +#define X_GLrop_Normal3fv 30 +void +__indirect_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_Normal3fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&nx), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&ny), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&nz), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Normal3fv 30 +void +__indirect_glNormal3fv(const GLfloat * v) +{ + generic_12_byte(X_GLrop_Normal3fv, v); +} + +#define X_GLrop_Normal3iv 31 +void +__indirect_glNormal3i(GLint nx, GLint ny, GLint nz) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_Normal3iv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&nx), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&ny), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&nz), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Normal3iv 31 +void +__indirect_glNormal3iv(const GLint * v) +{ + generic_12_byte(X_GLrop_Normal3iv, v); +} + +#define X_GLrop_Normal3sv 32 +void +__indirect_glNormal3s(GLshort nx, GLshort ny, GLshort nz) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Normal3sv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&nx), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&ny), 2); + (void) memcpy((void *) (gc->pc + 8), (void *) (&nz), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Normal3sv 32 +void +__indirect_glNormal3sv(const GLshort * v) +{ + generic_6_byte(X_GLrop_Normal3sv, v); +} + +#define X_GLrop_RasterPos2dv 33 +void +__indirect_glRasterPos2d(GLdouble x, GLdouble y) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_RasterPos2dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_RasterPos2dv 33 +void +__indirect_glRasterPos2dv(const GLdouble * v) +{ + generic_16_byte(X_GLrop_RasterPos2dv, v); +} + +#define X_GLrop_RasterPos2fv 34 +void +__indirect_glRasterPos2f(GLfloat x, GLfloat y) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_RasterPos2fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_RasterPos2fv 34 +void +__indirect_glRasterPos2fv(const GLfloat * v) +{ + generic_8_byte(X_GLrop_RasterPos2fv, v); +} + +#define X_GLrop_RasterPos2iv 35 +void +__indirect_glRasterPos2i(GLint x, GLint y) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_RasterPos2iv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_RasterPos2iv 35 +void +__indirect_glRasterPos2iv(const GLint * v) +{ + generic_8_byte(X_GLrop_RasterPos2iv, v); +} + +#define X_GLrop_RasterPos2sv 36 +void +__indirect_glRasterPos2s(GLshort x, GLshort y) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_RasterPos2sv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&y), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_RasterPos2sv 36 +void +__indirect_glRasterPos2sv(const GLshort * v) +{ + generic_4_byte(X_GLrop_RasterPos2sv, v); +} + +#define X_GLrop_RasterPos3dv 37 +void +__indirect_glRasterPos3d(GLdouble x, GLdouble y, GLdouble z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_RasterPos3dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&z), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_RasterPos3dv 37 +void +__indirect_glRasterPos3dv(const GLdouble * v) +{ + generic_24_byte(X_GLrop_RasterPos3dv, v); +} + +#define X_GLrop_RasterPos3fv 38 +void +__indirect_glRasterPos3f(GLfloat x, GLfloat y, GLfloat z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_RasterPos3fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_RasterPos3fv 38 +void +__indirect_glRasterPos3fv(const GLfloat * v) +{ + generic_12_byte(X_GLrop_RasterPos3fv, v); +} + +#define X_GLrop_RasterPos3iv 39 +void +__indirect_glRasterPos3i(GLint x, GLint y, GLint z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_RasterPos3iv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_RasterPos3iv 39 +void +__indirect_glRasterPos3iv(const GLint * v) +{ + generic_12_byte(X_GLrop_RasterPos3iv, v); +} + +#define X_GLrop_RasterPos3sv 40 +void +__indirect_glRasterPos3s(GLshort x, GLshort y, GLshort z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_RasterPos3sv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&y), 2); + (void) memcpy((void *) (gc->pc + 8), (void *) (&z), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_RasterPos3sv 40 +void +__indirect_glRasterPos3sv(const GLshort * v) +{ + generic_6_byte(X_GLrop_RasterPos3sv, v); +} + +#define X_GLrop_RasterPos4dv 41 +void +__indirect_glRasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 36; + emit_header(gc->pc, X_GLrop_RasterPos4dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&z), 8); + (void) memcpy((void *) (gc->pc + 28), (void *) (&w), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_RasterPos4dv 41 +void +__indirect_glRasterPos4dv(const GLdouble * v) +{ + generic_32_byte(X_GLrop_RasterPos4dv, v); +} + +#define X_GLrop_RasterPos4fv 42 +void +__indirect_glRasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_RasterPos4fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&w), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_RasterPos4fv 42 +void +__indirect_glRasterPos4fv(const GLfloat * v) +{ + generic_16_byte(X_GLrop_RasterPos4fv, v); +} + +#define X_GLrop_RasterPos4iv 43 +void +__indirect_glRasterPos4i(GLint x, GLint y, GLint z, GLint w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_RasterPos4iv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&w), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_RasterPos4iv 43 +void +__indirect_glRasterPos4iv(const GLint * v) +{ + generic_16_byte(X_GLrop_RasterPos4iv, v); +} + +#define X_GLrop_RasterPos4sv 44 +void +__indirect_glRasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_RasterPos4sv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&y), 2); + (void) memcpy((void *) (gc->pc + 8), (void *) (&z), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&w), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_RasterPos4sv 44 +void +__indirect_glRasterPos4sv(const GLshort * v) +{ + generic_8_byte(X_GLrop_RasterPos4sv, v); +} + +#define X_GLrop_Rectdv 45 +void +__indirect_glRectd(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 36; + emit_header(gc->pc, X_GLrop_Rectdv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x1), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y1), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&x2), 8); + (void) memcpy((void *) (gc->pc + 28), (void *) (&y2), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Rectdv 45 +void +__indirect_glRectdv(const GLdouble * v1, const GLdouble * v2) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 36; + emit_header(gc->pc, X_GLrop_Rectdv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (v1), 16); + (void) memcpy((void *) (gc->pc + 20), (void *) (v2), 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Rectfv 46 +void +__indirect_glRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_Rectfv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x1), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y1), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&x2), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y2), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Rectfv 46 +void +__indirect_glRectfv(const GLfloat * v1, const GLfloat * v2) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_Rectfv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (v1), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (v2), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Rectiv 47 +void +__indirect_glRecti(GLint x1, GLint y1, GLint x2, GLint y2) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_Rectiv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x1), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y1), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&x2), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y2), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Rectiv 47 +void +__indirect_glRectiv(const GLint * v1, const GLint * v2) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_Rectiv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (v1), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (v2), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Rectsv 48 +void +__indirect_glRects(GLshort x1, GLshort y1, GLshort x2, GLshort y2) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Rectsv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x1), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&y1), 2); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x2), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&y2), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Rectsv 48 +void +__indirect_glRectsv(const GLshort * v1, const GLshort * v2) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Rectsv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (v1), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v2), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord1dv 49 +void +__indirect_glTexCoord1d(GLdouble s) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_TexCoord1dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord1dv 49 +void +__indirect_glTexCoord1dv(const GLdouble * v) +{ + generic_8_byte(X_GLrop_TexCoord1dv, v); +} + +#define X_GLrop_TexCoord1fv 50 +void +__indirect_glTexCoord1f(GLfloat s) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_TexCoord1fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord1fv 50 +void +__indirect_glTexCoord1fv(const GLfloat * v) +{ + generic_4_byte(X_GLrop_TexCoord1fv, v); +} + +#define X_GLrop_TexCoord1iv 51 +void +__indirect_glTexCoord1i(GLint s) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_TexCoord1iv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord1iv 51 +void +__indirect_glTexCoord1iv(const GLint * v) +{ + generic_4_byte(X_GLrop_TexCoord1iv, v); +} + +#define X_GLrop_TexCoord1sv 52 +void +__indirect_glTexCoord1s(GLshort s) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_TexCoord1sv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord1sv 52 +void +__indirect_glTexCoord1sv(const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_TexCoord1sv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (v), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord2dv 53 +void +__indirect_glTexCoord2d(GLdouble s, GLdouble t) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_TexCoord2dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&t), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord2dv 53 +void +__indirect_glTexCoord2dv(const GLdouble * v) +{ + generic_16_byte(X_GLrop_TexCoord2dv, v); +} + +#define X_GLrop_TexCoord2fv 54 +void +__indirect_glTexCoord2f(GLfloat s, GLfloat t) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_TexCoord2fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&t), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord2fv 54 +void +__indirect_glTexCoord2fv(const GLfloat * v) +{ + generic_8_byte(X_GLrop_TexCoord2fv, v); +} + +#define X_GLrop_TexCoord2iv 55 +void +__indirect_glTexCoord2i(GLint s, GLint t) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_TexCoord2iv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&t), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord2iv 55 +void +__indirect_glTexCoord2iv(const GLint * v) +{ + generic_8_byte(X_GLrop_TexCoord2iv, v); +} + +#define X_GLrop_TexCoord2sv 56 +void +__indirect_glTexCoord2s(GLshort s, GLshort t) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_TexCoord2sv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&t), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord2sv 56 +void +__indirect_glTexCoord2sv(const GLshort * v) +{ + generic_4_byte(X_GLrop_TexCoord2sv, v); +} + +#define X_GLrop_TexCoord3dv 57 +void +__indirect_glTexCoord3d(GLdouble s, GLdouble t, GLdouble r) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_TexCoord3dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&t), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&r), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord3dv 57 +void +__indirect_glTexCoord3dv(const GLdouble * v) +{ + generic_24_byte(X_GLrop_TexCoord3dv, v); +} + +#define X_GLrop_TexCoord3fv 58 +void +__indirect_glTexCoord3f(GLfloat s, GLfloat t, GLfloat r) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_TexCoord3fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&t), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&r), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord3fv 58 +void +__indirect_glTexCoord3fv(const GLfloat * v) +{ + generic_12_byte(X_GLrop_TexCoord3fv, v); +} + +#define X_GLrop_TexCoord3iv 59 +void +__indirect_glTexCoord3i(GLint s, GLint t, GLint r) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_TexCoord3iv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&t), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&r), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord3iv 59 +void +__indirect_glTexCoord3iv(const GLint * v) +{ + generic_12_byte(X_GLrop_TexCoord3iv, v); +} + +#define X_GLrop_TexCoord3sv 60 +void +__indirect_glTexCoord3s(GLshort s, GLshort t, GLshort r) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_TexCoord3sv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&t), 2); + (void) memcpy((void *) (gc->pc + 8), (void *) (&r), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord3sv 60 +void +__indirect_glTexCoord3sv(const GLshort * v) +{ + generic_6_byte(X_GLrop_TexCoord3sv, v); +} + +#define X_GLrop_TexCoord4dv 61 +void +__indirect_glTexCoord4d(GLdouble s, GLdouble t, GLdouble r, GLdouble q) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 36; + emit_header(gc->pc, X_GLrop_TexCoord4dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&t), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&r), 8); + (void) memcpy((void *) (gc->pc + 28), (void *) (&q), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord4dv 61 +void +__indirect_glTexCoord4dv(const GLdouble * v) +{ + generic_32_byte(X_GLrop_TexCoord4dv, v); +} + +#define X_GLrop_TexCoord4fv 62 +void +__indirect_glTexCoord4f(GLfloat s, GLfloat t, GLfloat r, GLfloat q) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_TexCoord4fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&t), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&r), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&q), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord4fv 62 +void +__indirect_glTexCoord4fv(const GLfloat * v) +{ + generic_16_byte(X_GLrop_TexCoord4fv, v); +} + +#define X_GLrop_TexCoord4iv 63 +void +__indirect_glTexCoord4i(GLint s, GLint t, GLint r, GLint q) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_TexCoord4iv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&t), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&r), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&q), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord4iv 63 +void +__indirect_glTexCoord4iv(const GLint * v) +{ + generic_16_byte(X_GLrop_TexCoord4iv, v); +} + +#define X_GLrop_TexCoord4sv 64 +void +__indirect_glTexCoord4s(GLshort s, GLshort t, GLshort r, GLshort q) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_TexCoord4sv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&t), 2); + (void) memcpy((void *) (gc->pc + 8), (void *) (&r), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&q), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexCoord4sv 64 +void +__indirect_glTexCoord4sv(const GLshort * v) +{ + generic_8_byte(X_GLrop_TexCoord4sv, v); +} + +#define X_GLrop_Vertex2dv 65 +void +__indirect_glVertex2d(GLdouble x, GLdouble y) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_Vertex2dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Vertex2dv 65 +void +__indirect_glVertex2dv(const GLdouble * v) +{ + generic_16_byte(X_GLrop_Vertex2dv, v); +} + +#define X_GLrop_Vertex2fv 66 +void +__indirect_glVertex2f(GLfloat x, GLfloat y) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Vertex2fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Vertex2fv 66 +void +__indirect_glVertex2fv(const GLfloat * v) +{ + generic_8_byte(X_GLrop_Vertex2fv, v); +} + +#define X_GLrop_Vertex2iv 67 +void +__indirect_glVertex2i(GLint x, GLint y) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Vertex2iv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Vertex2iv 67 +void +__indirect_glVertex2iv(const GLint * v) +{ + generic_8_byte(X_GLrop_Vertex2iv, v); +} + +#define X_GLrop_Vertex2sv 68 +void +__indirect_glVertex2s(GLshort x, GLshort y) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_Vertex2sv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&y), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Vertex2sv 68 +void +__indirect_glVertex2sv(const GLshort * v) +{ + generic_4_byte(X_GLrop_Vertex2sv, v); +} + +#define X_GLrop_Vertex3dv 69 +void +__indirect_glVertex3d(GLdouble x, GLdouble y, GLdouble z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_Vertex3dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&z), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Vertex3dv 69 +void +__indirect_glVertex3dv(const GLdouble * v) +{ + generic_24_byte(X_GLrop_Vertex3dv, v); +} + +#define X_GLrop_Vertex3fv 70 +void +__indirect_glVertex3f(GLfloat x, GLfloat y, GLfloat z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_Vertex3fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Vertex3fv 70 +void +__indirect_glVertex3fv(const GLfloat * v) +{ + generic_12_byte(X_GLrop_Vertex3fv, v); +} + +#define X_GLrop_Vertex3iv 71 +void +__indirect_glVertex3i(GLint x, GLint y, GLint z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_Vertex3iv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Vertex3iv 71 +void +__indirect_glVertex3iv(const GLint * v) +{ + generic_12_byte(X_GLrop_Vertex3iv, v); +} + +#define X_GLrop_Vertex3sv 72 +void +__indirect_glVertex3s(GLshort x, GLshort y, GLshort z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Vertex3sv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&y), 2); + (void) memcpy((void *) (gc->pc + 8), (void *) (&z), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Vertex3sv 72 +void +__indirect_glVertex3sv(const GLshort * v) +{ + generic_6_byte(X_GLrop_Vertex3sv, v); +} + +#define X_GLrop_Vertex4dv 73 +void +__indirect_glVertex4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 36; + emit_header(gc->pc, X_GLrop_Vertex4dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&z), 8); + (void) memcpy((void *) (gc->pc + 28), (void *) (&w), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Vertex4dv 73 +void +__indirect_glVertex4dv(const GLdouble * v) +{ + generic_32_byte(X_GLrop_Vertex4dv, v); +} + +#define X_GLrop_Vertex4fv 74 +void +__indirect_glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_Vertex4fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&w), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Vertex4fv 74 +void +__indirect_glVertex4fv(const GLfloat * v) +{ + generic_16_byte(X_GLrop_Vertex4fv, v); +} + +#define X_GLrop_Vertex4iv 75 +void +__indirect_glVertex4i(GLint x, GLint y, GLint z, GLint w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_Vertex4iv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&w), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Vertex4iv 75 +void +__indirect_glVertex4iv(const GLint * v) +{ + generic_16_byte(X_GLrop_Vertex4iv, v); +} + +#define X_GLrop_Vertex4sv 76 +void +__indirect_glVertex4s(GLshort x, GLshort y, GLshort z, GLshort w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Vertex4sv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&y), 2); + (void) memcpy((void *) (gc->pc + 8), (void *) (&z), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&w), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Vertex4sv 76 +void +__indirect_glVertex4sv(const GLshort * v) +{ + generic_8_byte(X_GLrop_Vertex4sv, v); +} + +#define X_GLrop_ClipPlane 77 +void +__indirect_glClipPlane(GLenum plane, const GLdouble * equation) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 40; + emit_header(gc->pc, X_GLrop_ClipPlane, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (equation), 32); + (void) memcpy((void *) (gc->pc + 36), (void *) (&plane), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ColorMaterial 78 +void +__indirect_glColorMaterial(GLenum face, GLenum mode) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_ColorMaterial, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&face), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&mode), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_CullFace 79 +void +__indirect_glCullFace(GLenum mode) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_CullFace, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&mode), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Fogf 80 +void +__indirect_glFogf(GLenum pname, GLfloat param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Fogf, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Fogfv 81 +void +__indirect_glFogfv(GLenum pname, const GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glFogfv_size(pname); + const GLuint cmdlen = 8 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_Fogfv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Fogi 82 +void +__indirect_glFogi(GLenum pname, GLint param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Fogi, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Fogiv 83 +void +__indirect_glFogiv(GLenum pname, const GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glFogiv_size(pname); + const GLuint cmdlen = 8 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_Fogiv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_FrontFace 84 +void +__indirect_glFrontFace(GLenum mode) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_FrontFace, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&mode), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Hint 85 +void +__indirect_glHint(GLenum target, GLenum mode) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Hint, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&mode), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Lightf 86 +void +__indirect_glLightf(GLenum light, GLenum pname, GLfloat param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_Lightf, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&light), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Lightfv 87 +void +__indirect_glLightfv(GLenum light, GLenum pname, const GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glLightfv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_Lightfv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&light), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Lighti 88 +void +__indirect_glLighti(GLenum light, GLenum pname, GLint param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_Lighti, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&light), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Lightiv 89 +void +__indirect_glLightiv(GLenum light, GLenum pname, const GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glLightiv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_Lightiv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&light), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_LightModelf 90 +void +__indirect_glLightModelf(GLenum pname, GLfloat param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_LightModelf, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_LightModelfv 91 +void +__indirect_glLightModelfv(GLenum pname, const GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glLightModelfv_size(pname); + const GLuint cmdlen = 8 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_LightModelfv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_LightModeli 92 +void +__indirect_glLightModeli(GLenum pname, GLint param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_LightModeli, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_LightModeliv 93 +void +__indirect_glLightModeliv(GLenum pname, const GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glLightModeliv_size(pname); + const GLuint cmdlen = 8 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_LightModeliv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_LineStipple 94 +void +__indirect_glLineStipple(GLint factor, GLushort pattern) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_LineStipple, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&factor), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pattern), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_LineWidth 95 +void +__indirect_glLineWidth(GLfloat width) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_LineWidth, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&width), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Materialf 96 +void +__indirect_glMaterialf(GLenum face, GLenum pname, GLfloat param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_Materialf, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&face), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Materialfv 97 +void +__indirect_glMaterialfv(GLenum face, GLenum pname, const GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glMaterialfv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_Materialfv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&face), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Materiali 98 +void +__indirect_glMateriali(GLenum face, GLenum pname, GLint param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_Materiali, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&face), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Materialiv 99 +void +__indirect_glMaterialiv(GLenum face, GLenum pname, const GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glMaterialiv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_Materialiv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&face), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PointSize 100 +void +__indirect_glPointSize(GLfloat size) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_PointSize, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&size), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PolygonMode 101 +void +__indirect_glPolygonMode(GLenum face, GLenum mode) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_PolygonMode, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&face), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&mode), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PolygonStipple 102 +void +__indirect_glPolygonStipple(const GLubyte *mask) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = + (mask != NULL) ? __glImageSize(32, 32, 1, GL_COLOR_INDEX, GL_BITMAP, + 0) : 0; + const GLuint cmdlen = 24 + __GLX_PAD(compsize); + emit_header(gc->pc, X_GLrop_PolygonStipple, cmdlen); + if (compsize > 0) { + (*gc->fillImage) (gc, 2, 32, 32, 1, GL_COLOR_INDEX, GL_BITMAP, mask, + gc->pc + 24, gc->pc + 4); + } else { + (void) memcpy(gc->pc + 4, default_pixel_store_2D, + default_pixel_store_2D_size); + } + gc->pc += cmdlen; + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Scissor 103 +void +__indirect_glScissor(GLint x, GLint y, GLsizei width, GLsizei height) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_Scissor, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&height), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ShadeModel 104 +void +__indirect_glShadeModel(GLenum mode) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_ShadeModel, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&mode), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexParameterf 105 +void +__indirect_glTexParameterf(GLenum target, GLenum pname, GLfloat param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_TexParameterf, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexParameterfv 106 +void +__indirect_glTexParameterfv(GLenum target, GLenum pname, + const GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glTexParameterfv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_TexParameterfv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexParameteri 107 +void +__indirect_glTexParameteri(GLenum target, GLenum pname, GLint param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_TexParameteri, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexParameteriv 108 +void +__indirect_glTexParameteriv(GLenum target, GLenum pname, const GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glTexParameteriv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_TexParameteriv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +static void +__glx_TexImage_1D2D(unsigned opcode, unsigned dim, GLenum target, GLint level, + GLint internalformat, GLsizei width, GLsizei height, + GLint border, GLenum format, GLenum type, + const GLvoid * pixels) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = + __glImageSize(width, height, 1, format, type, target); + const GLuint cmdlen = 56 + __GLX_PAD(compsize); + if (__builtin_expect(gc->currentDpy != NULL, 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, opcode, cmdlen); + (void) memcpy((void *) (gc->pc + 24), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 28), (void *) (&level), 4); + (void) memcpy((void *) (gc->pc + 32), (void *) (&internalformat), + 4); + (void) memcpy((void *) (gc->pc + 36), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 40), (void *) (&height), 4); + (void) memcpy((void *) (gc->pc + 44), (void *) (&border), 4); + (void) memcpy((void *) (gc->pc + 48), (void *) (&format), 4); + (void) memcpy((void *) (gc->pc + 52), (void *) (&type), 4); + if ((compsize > 0) && (pixels != NULL)) { + (*gc->fillImage) (gc, dim, width, height, 1, format, type, + pixels, gc->pc + 56, gc->pc + 4); + } else { + (void) memcpy(gc->pc + 4, default_pixel_store_2D, + default_pixel_store_2D_size); + } + gc->pc += cmdlen; + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = opcode; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 28), (void *) (&target), 4); + (void) memcpy((void *) (pc + 32), (void *) (&level), 4); + (void) memcpy((void *) (pc + 36), (void *) (&internalformat), 4); + (void) memcpy((void *) (pc + 40), (void *) (&width), 4); + (void) memcpy((void *) (pc + 44), (void *) (&height), 4); + (void) memcpy((void *) (pc + 48), (void *) (&border), 4); + (void) memcpy((void *) (pc + 52), (void *) (&format), 4); + (void) memcpy((void *) (pc + 56), (void *) (&type), 4); + __glXSendLargeImage(gc, compsize, dim, width, height, 1, format, + type, pixels, pc + 60, pc + 8); + } + } +} + +#define X_GLrop_TexImage1D 109 +void +__indirect_glTexImage1D(GLenum target, GLint level, GLint internalformat, + GLsizei width, GLint border, GLenum format, + GLenum type, const GLvoid * pixels) +{ + __glx_TexImage_1D2D(X_GLrop_TexImage1D, 1, target, level, internalformat, + width, 1, border, format, type, pixels); +} + +#define X_GLrop_TexImage2D 110 +void +__indirect_glTexImage2D(GLenum target, GLint level, GLint internalformat, + GLsizei width, GLsizei height, GLint border, + GLenum format, GLenum type, const GLvoid * pixels) +{ + __glx_TexImage_1D2D(X_GLrop_TexImage2D, 2, target, level, internalformat, + width, height, border, format, type, pixels); +} + +#define X_GLrop_TexEnvf 111 +void +__indirect_glTexEnvf(GLenum target, GLenum pname, GLfloat param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_TexEnvf, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexEnvfv 112 +void +__indirect_glTexEnvfv(GLenum target, GLenum pname, const GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glTexEnvfv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_TexEnvfv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexEnvi 113 +void +__indirect_glTexEnvi(GLenum target, GLenum pname, GLint param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_TexEnvi, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexEnviv 114 +void +__indirect_glTexEnviv(GLenum target, GLenum pname, const GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glTexEnviv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_TexEnviv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexGend 115 +void +__indirect_glTexGend(GLenum coord, GLenum pname, GLdouble param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_TexGend, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (¶m), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&coord), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&pname), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexGendv 116 +void +__indirect_glTexGendv(GLenum coord, GLenum pname, const GLdouble * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glTexGendv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 8)); + emit_header(gc->pc, X_GLrop_TexGendv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&coord), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 8)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexGenf 117 +void +__indirect_glTexGenf(GLenum coord, GLenum pname, GLfloat param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_TexGenf, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&coord), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexGenfv 118 +void +__indirect_glTexGenfv(GLenum coord, GLenum pname, const GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glTexGenfv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_TexGenfv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&coord), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexGeni 119 +void +__indirect_glTexGeni(GLenum coord, GLenum pname, GLint param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_TexGeni, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&coord), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_TexGeniv 120 +void +__indirect_glTexGeniv(GLenum coord, GLenum pname, const GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glTexGeniv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_TexGeniv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&coord), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_InitNames 121 +void +__indirect_glInitNames(void) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 4; + emit_header(gc->pc, X_GLrop_InitNames, cmdlen); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_LoadName 122 +void +__indirect_glLoadName(GLuint name) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_LoadName, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&name), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PassThrough 123 +void +__indirect_glPassThrough(GLfloat token) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_PassThrough, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&token), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PopName 124 +void +__indirect_glPopName(void) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 4; + emit_header(gc->pc, X_GLrop_PopName, cmdlen); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PushName 125 +void +__indirect_glPushName(GLuint name) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_PushName, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&name), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_DrawBuffer 126 +void +__indirect_glDrawBuffer(GLenum mode) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_DrawBuffer, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&mode), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Clear 127 +void +__indirect_glClear(GLbitfield mask) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_Clear, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&mask), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ClearAccum 128 +void +__indirect_glClearAccum(GLfloat red, GLfloat green, GLfloat blue, + GLfloat alpha) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_ClearAccum, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&green), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&blue), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&alpha), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ClearIndex 129 +void +__indirect_glClearIndex(GLfloat c) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_ClearIndex, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&c), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ClearColor 130 +void +__indirect_glClearColor(GLclampf red, GLclampf green, GLclampf blue, + GLclampf alpha) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_ClearColor, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&green), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&blue), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&alpha), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ClearStencil 131 +void +__indirect_glClearStencil(GLint s) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_ClearStencil, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ClearDepth 132 +void +__indirect_glClearDepth(GLclampd depth) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_ClearDepth, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&depth), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_StencilMask 133 +void +__indirect_glStencilMask(GLuint mask) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_StencilMask, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&mask), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ColorMask 134 +void +__indirect_glColorMask(GLboolean red, GLboolean green, GLboolean blue, + GLboolean alpha) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_ColorMask, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 1); + (void) memcpy((void *) (gc->pc + 5), (void *) (&green), 1); + (void) memcpy((void *) (gc->pc + 6), (void *) (&blue), 1); + (void) memcpy((void *) (gc->pc + 7), (void *) (&alpha), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_DepthMask 135 +void +__indirect_glDepthMask(GLboolean flag) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_DepthMask, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&flag), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_IndexMask 136 +void +__indirect_glIndexMask(GLuint mask) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_IndexMask, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&mask), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Accum 137 +void +__indirect_glAccum(GLenum op, GLfloat value) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_Accum, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&value), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PopAttrib 141 +void +__indirect_glPopAttrib(void) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 4; + emit_header(gc->pc, X_GLrop_PopAttrib, cmdlen); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PushAttrib 142 +void +__indirect_glPushAttrib(GLbitfield mask) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_PushAttrib, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&mask), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MapGrid1d 147 +void +__indirect_glMapGrid1d(GLint un, GLdouble u1, GLdouble u2) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_MapGrid1d, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&u1), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&u2), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&un), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MapGrid1f 148 +void +__indirect_glMapGrid1f(GLint un, GLfloat u1, GLfloat u2) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_MapGrid1f, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&un), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&u1), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&u2), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MapGrid2d 149 +void +__indirect_glMapGrid2d(GLint un, GLdouble u1, GLdouble u2, GLint vn, + GLdouble v1, GLdouble v2) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 44; + emit_header(gc->pc, X_GLrop_MapGrid2d, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&u1), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&u2), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&v1), 8); + (void) memcpy((void *) (gc->pc + 28), (void *) (&v2), 8); + (void) memcpy((void *) (gc->pc + 36), (void *) (&un), 4); + (void) memcpy((void *) (gc->pc + 40), (void *) (&vn), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MapGrid2f 150 +void +__indirect_glMapGrid2f(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, + GLfloat v2) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_MapGrid2f, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&un), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&u1), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&u2), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&vn), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&v1), 4); + (void) memcpy((void *) (gc->pc + 24), (void *) (&v2), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_EvalCoord1dv 151 +void +__indirect_glEvalCoord1d(GLdouble u) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_EvalCoord1dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&u), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_EvalCoord1dv 151 +void +__indirect_glEvalCoord1dv(const GLdouble * u) +{ + generic_8_byte(X_GLrop_EvalCoord1dv, u); +} + +#define X_GLrop_EvalCoord1fv 152 +void +__indirect_glEvalCoord1f(GLfloat u) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_EvalCoord1fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&u), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_EvalCoord1fv 152 +void +__indirect_glEvalCoord1fv(const GLfloat * u) +{ + generic_4_byte(X_GLrop_EvalCoord1fv, u); +} + +#define X_GLrop_EvalCoord2dv 153 +void +__indirect_glEvalCoord2d(GLdouble u, GLdouble v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_EvalCoord2dv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&u), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&v), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_EvalCoord2dv 153 +void +__indirect_glEvalCoord2dv(const GLdouble * u) +{ + generic_16_byte(X_GLrop_EvalCoord2dv, u); +} + +#define X_GLrop_EvalCoord2fv 154 +void +__indirect_glEvalCoord2f(GLfloat u, GLfloat v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_EvalCoord2fv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&u), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&v), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_EvalCoord2fv 154 +void +__indirect_glEvalCoord2fv(const GLfloat * u) +{ + generic_8_byte(X_GLrop_EvalCoord2fv, u); +} + +#define X_GLrop_EvalMesh1 155 +void +__indirect_glEvalMesh1(GLenum mode, GLint i1, GLint i2) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_EvalMesh1, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&mode), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&i1), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&i2), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_EvalPoint1 156 +void +__indirect_glEvalPoint1(GLint i) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_EvalPoint1, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&i), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_EvalMesh2 157 +void +__indirect_glEvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_EvalMesh2, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&mode), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&i1), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&i2), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&j1), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&j2), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_EvalPoint2 158 +void +__indirect_glEvalPoint2(GLint i, GLint j) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_EvalPoint2, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&i), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&j), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_AlphaFunc 159 +void +__indirect_glAlphaFunc(GLenum func, GLclampf ref) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_AlphaFunc, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&func), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&ref), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_BlendFunc 160 +void +__indirect_glBlendFunc(GLenum sfactor, GLenum dfactor) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_BlendFunc, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&sfactor), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&dfactor), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_LogicOp 161 +void +__indirect_glLogicOp(GLenum opcode) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_LogicOp, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&opcode), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_StencilFunc 162 +void +__indirect_glStencilFunc(GLenum func, GLint ref, GLuint mask) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_StencilFunc, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&func), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&ref), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&mask), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_StencilOp 163 +void +__indirect_glStencilOp(GLenum fail, GLenum zfail, GLenum zpass) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_StencilOp, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&fail), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&zfail), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&zpass), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_DepthFunc 164 +void +__indirect_glDepthFunc(GLenum func) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_DepthFunc, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&func), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PixelZoom 165 +void +__indirect_glPixelZoom(GLfloat xfactor, GLfloat yfactor) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_PixelZoom, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&xfactor), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&yfactor), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PixelTransferf 166 +void +__indirect_glPixelTransferf(GLenum pname, GLfloat param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_PixelTransferf, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PixelTransferi 167 +void +__indirect_glPixelTransferi(GLenum pname, GLint param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_PixelTransferi, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PixelMapfv 168 +void +__indirect_glPixelMapfv(GLenum map, GLsizei mapsize, const GLfloat * values) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((mapsize * 4)); + if (mapsize < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((mapsize >= 0) && (gc->currentDpy != NULL), 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, X_GLrop_PixelMapfv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&map), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&mapsize), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (values), + (mapsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = X_GLrop_PixelMapfv; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 8), (void *) (&map), 4); + (void) memcpy((void *) (pc + 12), (void *) (&mapsize), 4); + __glXSendLargeCommand(gc, pc, 16, values, (mapsize * 4)); + } + } +} + +#define X_GLrop_PixelMapuiv 169 +void +__indirect_glPixelMapuiv(GLenum map, GLsizei mapsize, const GLuint * values) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((mapsize * 4)); + if (mapsize < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((mapsize >= 0) && (gc->currentDpy != NULL), 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, X_GLrop_PixelMapuiv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&map), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&mapsize), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (values), + (mapsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = X_GLrop_PixelMapuiv; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 8), (void *) (&map), 4); + (void) memcpy((void *) (pc + 12), (void *) (&mapsize), 4); + __glXSendLargeCommand(gc, pc, 16, values, (mapsize * 4)); + } + } +} + +#define X_GLrop_PixelMapusv 170 +void +__indirect_glPixelMapusv(GLenum map, GLsizei mapsize, const GLushort * values) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((mapsize * 2)); + if (mapsize < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((mapsize >= 0) && (gc->currentDpy != NULL), 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, X_GLrop_PixelMapusv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&map), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&mapsize), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (values), + (mapsize * 2)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = X_GLrop_PixelMapusv; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 8), (void *) (&map), 4); + (void) memcpy((void *) (pc + 12), (void *) (&mapsize), 4); + __glXSendLargeCommand(gc, pc, 16, values, (mapsize * 2)); + } + } +} + +#define X_GLrop_ReadBuffer 171 +void +__indirect_glReadBuffer(GLenum mode) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_ReadBuffer, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&mode), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_CopyPixels 172 +void +__indirect_glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, + GLenum type) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_CopyPixels, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&height), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&type), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLsop_ReadPixels 111 +void +__indirect_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, GLvoid * pixels) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const __GLXattribute *const state = gc->client_state_private; + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 28; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_read_pixels_reply_t *reply = + xcb_glx_read_pixels_reply(c, + xcb_glx_read_pixels(c, + gc-> + currentContextTag, + x, y, width, height, + format, type, + state->storePack. + swapEndian, 0), + NULL); + (void) memcpy(pixels, xcb_glx_read_pixels_data(reply), + xcb_glx_read_pixels_data_length(reply) * + sizeof(GLvoid)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_ReadPixels, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&x), 4); + (void) memcpy((void *) (pc + 4), (void *) (&y), 4); + (void) memcpy((void *) (pc + 8), (void *) (&width), 4); + (void) memcpy((void *) (pc + 12), (void *) (&height), 4); + (void) memcpy((void *) (pc + 16), (void *) (&format), 4); + (void) memcpy((void *) (pc + 20), (void *) (&type), 4); + *(int32_t *) (pc + 24) = 0; + *(int8_t *) (pc + 24) = state->storePack.swapEndian; + __glXReadPixelReply(dpy, gc, 2, width, height, 1, format, type, + pixels, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLrop_DrawPixels 173 +void +__indirect_glDrawPixels(GLsizei width, GLsizei height, GLenum format, + GLenum type, const GLvoid * pixels) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = + (pixels != NULL) ? __glImageSize(width, height, 1, format, type, + 0) : 0; + const GLuint cmdlen = 40 + __GLX_PAD(compsize); + if (__builtin_expect(gc->currentDpy != NULL, 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, X_GLrop_DrawPixels, cmdlen); + (void) memcpy((void *) (gc->pc + 24), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 28), (void *) (&height), 4); + (void) memcpy((void *) (gc->pc + 32), (void *) (&format), 4); + (void) memcpy((void *) (gc->pc + 36), (void *) (&type), 4); + if (compsize > 0) { + (*gc->fillImage) (gc, 2, width, height, 1, format, type, + pixels, gc->pc + 40, gc->pc + 4); + } else { + (void) memcpy(gc->pc + 4, default_pixel_store_2D, + default_pixel_store_2D_size); + } + gc->pc += cmdlen; + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = X_GLrop_DrawPixels; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 28), (void *) (&width), 4); + (void) memcpy((void *) (pc + 32), (void *) (&height), 4); + (void) memcpy((void *) (pc + 36), (void *) (&format), 4); + (void) memcpy((void *) (pc + 40), (void *) (&type), 4); + __glXSendLargeImage(gc, compsize, 2, width, height, 1, format, + type, pixels, pc + 44, pc + 8); + } + } +} + +#define X_GLsop_GetClipPlane 113 +void +__indirect_glGetClipPlane(GLenum plane, GLdouble * equation) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 4; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_clip_plane_reply_t *reply = + xcb_glx_get_clip_plane_reply(c, + xcb_glx_get_clip_plane(c, + gc-> + currentContextTag, + plane), NULL); + (void) memcpy(equation, xcb_glx_get_clip_plane_data(reply), + xcb_glx_get_clip_plane_data_length(reply) * + sizeof(GLdouble)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetClipPlane, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&plane), 4); + (void) __glXReadReply(dpy, 8, equation, GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetLightfv 118 +void +__indirect_glGetLightfv(GLenum light, GLenum pname, GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_lightfv_reply_t *reply = + xcb_glx_get_lightfv_reply(c, + xcb_glx_get_lightfv(c, + gc-> + currentContextTag, + light, pname), + NULL); + if (xcb_glx_get_lightfv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_lightfv_data(reply), + xcb_glx_get_lightfv_data_length(reply) * + sizeof(GLfloat)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetLightfv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&light), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetLightiv 119 +void +__indirect_glGetLightiv(GLenum light, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_lightiv_reply_t *reply = + xcb_glx_get_lightiv_reply(c, + xcb_glx_get_lightiv(c, + gc-> + currentContextTag, + light, pname), + NULL); + if (xcb_glx_get_lightiv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_lightiv_data(reply), + xcb_glx_get_lightiv_data_length(reply) * + sizeof(GLint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetLightiv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&light), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetMapdv 120 +void +__indirect_glGetMapdv(GLenum target, GLenum query, GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_mapdv_reply_t *reply = + xcb_glx_get_mapdv_reply(c, + xcb_glx_get_mapdv(c, + gc->currentContextTag, + target, query), NULL); + if (xcb_glx_get_mapdv_data_length(reply) == 0) + (void) memcpy(v, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(v, xcb_glx_get_mapdv_data(reply), + xcb_glx_get_mapdv_data_length(reply) * + sizeof(GLdouble)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetMapdv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&query), 4); + (void) __glXReadReply(dpy, 8, v, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetMapfv 121 +void +__indirect_glGetMapfv(GLenum target, GLenum query, GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_mapfv_reply_t *reply = + xcb_glx_get_mapfv_reply(c, + xcb_glx_get_mapfv(c, + gc->currentContextTag, + target, query), NULL); + if (xcb_glx_get_mapfv_data_length(reply) == 0) + (void) memcpy(v, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(v, xcb_glx_get_mapfv_data(reply), + xcb_glx_get_mapfv_data_length(reply) * + sizeof(GLfloat)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetMapfv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&query), 4); + (void) __glXReadReply(dpy, 4, v, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetMapiv 122 +void +__indirect_glGetMapiv(GLenum target, GLenum query, GLint * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_mapiv_reply_t *reply = + xcb_glx_get_mapiv_reply(c, + xcb_glx_get_mapiv(c, + gc->currentContextTag, + target, query), NULL); + if (xcb_glx_get_mapiv_data_length(reply) == 0) + (void) memcpy(v, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(v, xcb_glx_get_mapiv_data(reply), + xcb_glx_get_mapiv_data_length(reply) * + sizeof(GLint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetMapiv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&query), 4); + (void) __glXReadReply(dpy, 4, v, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetMaterialfv 123 +void +__indirect_glGetMaterialfv(GLenum face, GLenum pname, GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_materialfv_reply_t *reply = + xcb_glx_get_materialfv_reply(c, + xcb_glx_get_materialfv(c, + gc-> + currentContextTag, + face, pname), + NULL); + if (xcb_glx_get_materialfv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_materialfv_data(reply), + xcb_glx_get_materialfv_data_length(reply) * + sizeof(GLfloat)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetMaterialfv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&face), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetMaterialiv 124 +void +__indirect_glGetMaterialiv(GLenum face, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_materialiv_reply_t *reply = + xcb_glx_get_materialiv_reply(c, + xcb_glx_get_materialiv(c, + gc-> + currentContextTag, + face, pname), + NULL); + if (xcb_glx_get_materialiv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_materialiv_data(reply), + xcb_glx_get_materialiv_data_length(reply) * + sizeof(GLint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetMaterialiv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&face), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetPixelMapfv 125 +void +__indirect_glGetPixelMapfv(GLenum map, GLfloat * values) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 4; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_pixel_mapfv_reply_t *reply = + xcb_glx_get_pixel_mapfv_reply(c, + xcb_glx_get_pixel_mapfv(c, + gc-> + currentContextTag, + map), NULL); + if (xcb_glx_get_pixel_mapfv_data_length(reply) == 0) + (void) memcpy(values, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(values, xcb_glx_get_pixel_mapfv_data(reply), + xcb_glx_get_pixel_mapfv_data_length(reply) * + sizeof(GLfloat)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetPixelMapfv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&map), 4); + (void) __glXReadReply(dpy, 4, values, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetPixelMapuiv 126 +void +__indirect_glGetPixelMapuiv(GLenum map, GLuint * values) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 4; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_pixel_mapuiv_reply_t *reply = + xcb_glx_get_pixel_mapuiv_reply(c, + xcb_glx_get_pixel_mapuiv(c, + gc-> + currentContextTag, + map), + NULL); + if (xcb_glx_get_pixel_mapuiv_data_length(reply) == 0) + (void) memcpy(values, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(values, xcb_glx_get_pixel_mapuiv_data(reply), + xcb_glx_get_pixel_mapuiv_data_length(reply) * + sizeof(GLuint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetPixelMapuiv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&map), 4); + (void) __glXReadReply(dpy, 4, values, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetPixelMapusv 127 +void +__indirect_glGetPixelMapusv(GLenum map, GLushort * values) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 4; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_pixel_mapusv_reply_t *reply = + xcb_glx_get_pixel_mapusv_reply(c, + xcb_glx_get_pixel_mapusv(c, + gc-> + currentContextTag, + map), + NULL); + if (xcb_glx_get_pixel_mapusv_data_length(reply) == 0) + (void) memcpy(values, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(values, xcb_glx_get_pixel_mapusv_data(reply), + xcb_glx_get_pixel_mapusv_data_length(reply) * + sizeof(GLushort)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetPixelMapusv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&map), 4); + (void) __glXReadReply(dpy, 2, values, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetPolygonStipple 128 +void +__indirect_glGetPolygonStipple(GLubyte *mask) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 4; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_polygon_stipple_reply_t *reply = + xcb_glx_get_polygon_stipple_reply(c, + xcb_glx_get_polygon_stipple(c, + gc-> + currentContextTag, + 0), + NULL); + (void) memcpy(mask, xcb_glx_get_polygon_stipple_data(reply), + xcb_glx_get_polygon_stipple_data_length(reply) * + sizeof(GLubyte)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetPolygonStipple, cmdlen); + *(int32_t *) (pc + 0) = 0; + __glXReadPixelReply(dpy, gc, 2, 32, 32, 1, GL_COLOR_INDEX, GL_BITMAP, + mask, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetTexEnvfv 130 +void +__indirect_glGetTexEnvfv(GLenum target, GLenum pname, GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_tex_envfv_reply_t *reply = + xcb_glx_get_tex_envfv_reply(c, + xcb_glx_get_tex_envfv(c, + gc-> + currentContextTag, + target, pname), + NULL); + if (xcb_glx_get_tex_envfv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_tex_envfv_data(reply), + xcb_glx_get_tex_envfv_data_length(reply) * + sizeof(GLfloat)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetTexEnvfv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetTexEnviv 131 +void +__indirect_glGetTexEnviv(GLenum target, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_tex_enviv_reply_t *reply = + xcb_glx_get_tex_enviv_reply(c, + xcb_glx_get_tex_enviv(c, + gc-> + currentContextTag, + target, pname), + NULL); + if (xcb_glx_get_tex_enviv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_tex_enviv_data(reply), + xcb_glx_get_tex_enviv_data_length(reply) * + sizeof(GLint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetTexEnviv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetTexGendv 132 +void +__indirect_glGetTexGendv(GLenum coord, GLenum pname, GLdouble * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_tex_gendv_reply_t *reply = + xcb_glx_get_tex_gendv_reply(c, + xcb_glx_get_tex_gendv(c, + gc-> + currentContextTag, + coord, pname), + NULL); + if (xcb_glx_get_tex_gendv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_tex_gendv_data(reply), + xcb_glx_get_tex_gendv_data_length(reply) * + sizeof(GLdouble)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetTexGendv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&coord), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 8, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetTexGenfv 133 +void +__indirect_glGetTexGenfv(GLenum coord, GLenum pname, GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_tex_genfv_reply_t *reply = + xcb_glx_get_tex_genfv_reply(c, + xcb_glx_get_tex_genfv(c, + gc-> + currentContextTag, + coord, pname), + NULL); + if (xcb_glx_get_tex_genfv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_tex_genfv_data(reply), + xcb_glx_get_tex_genfv_data_length(reply) * + sizeof(GLfloat)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetTexGenfv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&coord), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetTexGeniv 134 +void +__indirect_glGetTexGeniv(GLenum coord, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_tex_geniv_reply_t *reply = + xcb_glx_get_tex_geniv_reply(c, + xcb_glx_get_tex_geniv(c, + gc-> + currentContextTag, + coord, pname), + NULL); + if (xcb_glx_get_tex_geniv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_tex_geniv_data(reply), + xcb_glx_get_tex_geniv_data_length(reply) * + sizeof(GLint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetTexGeniv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&coord), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetTexImage 135 +void +__indirect_glGetTexImage(GLenum target, GLint level, GLenum format, + GLenum type, GLvoid * pixels) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const __GLXattribute *const state = gc->client_state_private; + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 20; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_tex_image_reply_t *reply = + xcb_glx_get_tex_image_reply(c, + xcb_glx_get_tex_image(c, + gc-> + currentContextTag, + target, level, + format, type, + state-> + storePack. + swapEndian), + NULL); + (void) memcpy(pixels, xcb_glx_get_tex_image_data(reply), + xcb_glx_get_tex_image_data_length(reply) * + sizeof(GLvoid)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetTexImage, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&level), 4); + (void) memcpy((void *) (pc + 8), (void *) (&format), 4); + (void) memcpy((void *) (pc + 12), (void *) (&type), 4); + *(int32_t *) (pc + 16) = 0; + *(int8_t *) (pc + 16) = state->storePack.swapEndian; + __glXReadPixelReply(dpy, gc, 3, 0, 0, 0, format, type, pixels, + GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetTexParameterfv 136 +void +__indirect_glGetTexParameterfv(GLenum target, GLenum pname, GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_tex_parameterfv_reply_t *reply = + xcb_glx_get_tex_parameterfv_reply(c, + xcb_glx_get_tex_parameterfv(c, + gc-> + currentContextTag, + target, + pname), + NULL); + if (xcb_glx_get_tex_parameterfv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_tex_parameterfv_data(reply), + xcb_glx_get_tex_parameterfv_data_length(reply) * + sizeof(GLfloat)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetTexParameterfv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetTexParameteriv 137 +void +__indirect_glGetTexParameteriv(GLenum target, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_tex_parameteriv_reply_t *reply = + xcb_glx_get_tex_parameteriv_reply(c, + xcb_glx_get_tex_parameteriv(c, + gc-> + currentContextTag, + target, + pname), + NULL); + if (xcb_glx_get_tex_parameteriv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_tex_parameteriv_data(reply), + xcb_glx_get_tex_parameteriv_data_length(reply) * + sizeof(GLint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetTexParameteriv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetTexLevelParameterfv 138 +void +__indirect_glGetTexLevelParameterfv(GLenum target, GLint level, GLenum pname, + GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 12; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_tex_level_parameterfv_reply_t *reply = + xcb_glx_get_tex_level_parameterfv_reply(c, + xcb_glx_get_tex_level_parameterfv + (c, gc->currentContextTag, + target, level, pname), + NULL); + if (xcb_glx_get_tex_level_parameterfv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, + xcb_glx_get_tex_level_parameterfv_data(reply), + xcb_glx_get_tex_level_parameterfv_data_length(reply) + * sizeof(GLfloat)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetTexLevelParameterfv, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&level), 4); + (void) memcpy((void *) (pc + 8), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetTexLevelParameteriv 139 +void +__indirect_glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, + GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 12; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_tex_level_parameteriv_reply_t *reply = + xcb_glx_get_tex_level_parameteriv_reply(c, + xcb_glx_get_tex_level_parameteriv + (c, gc->currentContextTag, + target, level, pname), + NULL); + if (xcb_glx_get_tex_level_parameteriv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, + xcb_glx_get_tex_level_parameteriv_data(reply), + xcb_glx_get_tex_level_parameteriv_data_length(reply) + * sizeof(GLint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetTexLevelParameteriv, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&level), 4); + (void) memcpy((void *) (pc + 8), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_IsList 141 +GLboolean +__indirect_glIsList(GLuint list) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + GLboolean retval = (GLboolean) 0; +#ifndef USE_XCB + const GLuint cmdlen = 4; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_is_list_reply_t *reply = + xcb_glx_is_list_reply(c, + xcb_glx_is_list(c, gc->currentContextTag, + list), NULL); + retval = reply->ret_val; + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_IsList, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&list), 4); + retval = (GLboolean) __glXReadReply(dpy, 0, NULL, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return retval; +} + +#define X_GLrop_DepthRange 174 +void +__indirect_glDepthRange(GLclampd zNear, GLclampd zFar) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_DepthRange, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&zNear), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&zFar), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Frustum 175 +void +__indirect_glFrustum(GLdouble left, GLdouble right, GLdouble bottom, + GLdouble top, GLdouble zNear, GLdouble zFar) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 52; + emit_header(gc->pc, X_GLrop_Frustum, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&left), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&right), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&bottom), 8); + (void) memcpy((void *) (gc->pc + 28), (void *) (&top), 8); + (void) memcpy((void *) (gc->pc + 36), (void *) (&zNear), 8); + (void) memcpy((void *) (gc->pc + 44), (void *) (&zFar), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_LoadIdentity 176 +void +__indirect_glLoadIdentity(void) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 4; + emit_header(gc->pc, X_GLrop_LoadIdentity, cmdlen); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_LoadMatrixf 177 +void +__indirect_glLoadMatrixf(const GLfloat * m) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 68; + emit_header(gc->pc, X_GLrop_LoadMatrixf, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (m), 64); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_LoadMatrixd 178 +void +__indirect_glLoadMatrixd(const GLdouble * m) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 132; + emit_header(gc->pc, X_GLrop_LoadMatrixd, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (m), 128); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MatrixMode 179 +void +__indirect_glMatrixMode(GLenum mode) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_MatrixMode, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&mode), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultMatrixf 180 +void +__indirect_glMultMatrixf(const GLfloat * m) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 68; + emit_header(gc->pc, X_GLrop_MultMatrixf, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (m), 64); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultMatrixd 181 +void +__indirect_glMultMatrixd(const GLdouble * m) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 132; + emit_header(gc->pc, X_GLrop_MultMatrixd, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (m), 128); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Ortho 182 +void +__indirect_glOrtho(GLdouble left, GLdouble right, GLdouble bottom, + GLdouble top, GLdouble zNear, GLdouble zFar) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 52; + emit_header(gc->pc, X_GLrop_Ortho, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&left), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&right), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&bottom), 8); + (void) memcpy((void *) (gc->pc + 28), (void *) (&top), 8); + (void) memcpy((void *) (gc->pc + 36), (void *) (&zNear), 8); + (void) memcpy((void *) (gc->pc + 44), (void *) (&zFar), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PopMatrix 183 +void +__indirect_glPopMatrix(void) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 4; + emit_header(gc->pc, X_GLrop_PopMatrix, cmdlen); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PushMatrix 184 +void +__indirect_glPushMatrix(void) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 4; + emit_header(gc->pc, X_GLrop_PushMatrix, cmdlen); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Rotated 185 +void +__indirect_glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 36; + emit_header(gc->pc, X_GLrop_Rotated, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&angle), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&y), 8); + (void) memcpy((void *) (gc->pc + 28), (void *) (&z), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Rotatef 186 +void +__indirect_glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_Rotatef, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&angle), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&z), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Scaled 187 +void +__indirect_glScaled(GLdouble x, GLdouble y, GLdouble z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_Scaled, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&z), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Scalef 188 +void +__indirect_glScalef(GLfloat x, GLfloat y, GLfloat z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_Scalef, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Translated 189 +void +__indirect_glTranslated(GLdouble x, GLdouble y, GLdouble z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_Translated, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&z), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Translatef 190 +void +__indirect_glTranslatef(GLfloat x, GLfloat y, GLfloat z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_Translatef, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Viewport 191 +void +__indirect_glViewport(GLint x, GLint y, GLsizei width, GLsizei height) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_Viewport, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&height), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_BindTexture 4117 +void +__indirect_glBindTexture(GLenum target, GLuint texture) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_BindTexture, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&texture), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Indexubv 194 +void +__indirect_glIndexub(GLubyte c) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_Indexubv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&c), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Indexubv 194 +void +__indirect_glIndexubv(const GLubyte *c) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_Indexubv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (c), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PolygonOffset 192 +void +__indirect_glPolygonOffset(GLfloat factor, GLfloat units) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_PolygonOffset, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&factor), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&units), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_CopyTexImage1D 4119 +void +__indirect_glCopyTexImage1D(GLenum target, GLint level, GLenum internalformat, + GLint x, GLint y, GLsizei width, GLint border) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 32; + emit_header(gc->pc, X_GLrop_CopyTexImage1D, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&level), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&internalformat), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 24), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 28), (void *) (&border), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_CopyTexImage2D 4120 +void +__indirect_glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, + GLint x, GLint y, GLsizei width, GLsizei height, + GLint border) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 36; + emit_header(gc->pc, X_GLrop_CopyTexImage2D, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&level), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&internalformat), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 24), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 28), (void *) (&height), 4); + (void) memcpy((void *) (gc->pc + 32), (void *) (&border), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_CopyTexSubImage1D 4121 +void +__indirect_glCopyTexSubImage1D(GLenum target, GLint level, GLint xoffset, + GLint x, GLint y, GLsizei width) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_CopyTexSubImage1D, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&level), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&xoffset), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 24), (void *) (&width), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_CopyTexSubImage2D 4122 +void +__indirect_glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, + GLint yoffset, GLint x, GLint y, GLsizei width, + GLsizei height) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 36; + emit_header(gc->pc, X_GLrop_CopyTexSubImage2D, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&level), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&xoffset), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&yoffset), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 24), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 28), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 32), (void *) (&height), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLsop_DeleteTextures 144 +void +__indirect_glDeleteTextures(GLsizei n, const GLuint * textures) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 4 + __GLX_PAD((n * 4)); +#endif + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_delete_textures(c, gc->currentContextTag, n, textures); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_DeleteTextures, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) memcpy((void *) (pc + 4), (void *) (textures), (n * 4)); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLvop_DeleteTexturesEXT 12 +void +glDeleteTexturesEXT(GLsizei n, const GLuint * textures) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->DeleteTextures(n, textures); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 4 + __GLX_PAD((n * 4)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivate, + X_GLvop_DeleteTexturesEXT, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) memcpy((void *) (pc + 4), (void *) (textures), (n * 4)); + UnlockDisplay(dpy); + SyncHandle(); + } + return; + } +} + +#define X_GLsop_GenTextures 145 +void +__indirect_glGenTextures(GLsizei n, GLuint * textures) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 4; +#endif + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_gen_textures_reply_t *reply = + xcb_glx_gen_textures_reply(c, + xcb_glx_gen_textures(c, + gc-> + currentContextTag, + n), NULL); + (void) memcpy(textures, xcb_glx_gen_textures_data(reply), + xcb_glx_gen_textures_data_length(reply) * + sizeof(GLuint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GenTextures, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) __glXReadReply(dpy, 4, textures, GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLvop_GenTexturesEXT 13 +void +glGenTexturesEXT(GLsizei n, GLuint * textures) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->GenTextures(n, textures); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 4; + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GenTexturesEXT, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) __glXReadReply(dpy, 4, textures, GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; + } +} + +#define X_GLsop_IsTexture 146 +GLboolean +__indirect_glIsTexture(GLuint texture) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + GLboolean retval = (GLboolean) 0; +#ifndef USE_XCB + const GLuint cmdlen = 4; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_is_texture_reply_t *reply = + xcb_glx_is_texture_reply(c, + xcb_glx_is_texture(c, + gc->currentContextTag, + texture), NULL); + retval = reply->ret_val; + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_IsTexture, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&texture), 4); + retval = (GLboolean) __glXReadReply(dpy, 0, NULL, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return retval; +} + +#define X_GLvop_IsTextureEXT 14 +GLboolean +glIsTextureEXT(GLuint texture) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + return GET_DISPATCH()->IsTexture(texture); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + GLboolean retval = (GLboolean) 0; + const GLuint cmdlen = 4; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_IsTextureEXT, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&texture), 4); + retval = (GLboolean) __glXReadReply(dpy, 0, NULL, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return retval; + } +} + +#define X_GLrop_PrioritizeTextures 4118 +void +__indirect_glPrioritizeTextures(GLsizei n, const GLuint * textures, + const GLclampf * priorities) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8 + __GLX_PAD((n * 4)) + __GLX_PAD((n * 4)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_PrioritizeTextures, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (textures), (n * 4)); + (void) memcpy((void *) (gc->pc + 8 + (n * 4)), (void *) (priorities), + (n * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +static void +__glx_TexSubImage_1D2D(unsigned opcode, unsigned dim, GLenum target, + GLint level, GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, GLenum format, + GLenum type, const GLvoid * pixels) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = + (pixels != NULL) ? __glImageSize(width, height, 1, format, type, + target) : 0; + const GLuint cmdlen = 60 + __GLX_PAD(compsize); + if (__builtin_expect(gc->currentDpy != NULL, 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, opcode, cmdlen); + (void) memcpy((void *) (gc->pc + 24), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 28), (void *) (&level), 4); + (void) memcpy((void *) (gc->pc + 32), (void *) (&xoffset), 4); + (void) memcpy((void *) (gc->pc + 36), (void *) (&yoffset), 4); + (void) memcpy((void *) (gc->pc + 40), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 44), (void *) (&height), 4); + (void) memcpy((void *) (gc->pc + 48), (void *) (&format), 4); + (void) memcpy((void *) (gc->pc + 52), (void *) (&type), 4); + (void) memset((void *) (gc->pc + 56), 0, 4); + if (compsize > 0) { + (*gc->fillImage) (gc, dim, width, height, 1, format, type, + pixels, gc->pc + 60, gc->pc + 4); + } else { + (void) memcpy(gc->pc + 4, default_pixel_store_2D, + default_pixel_store_2D_size); + } + gc->pc += cmdlen; + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = opcode; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 28), (void *) (&target), 4); + (void) memcpy((void *) (pc + 32), (void *) (&level), 4); + (void) memcpy((void *) (pc + 36), (void *) (&xoffset), 4); + (void) memcpy((void *) (pc + 40), (void *) (&yoffset), 4); + (void) memcpy((void *) (pc + 44), (void *) (&width), 4); + (void) memcpy((void *) (pc + 48), (void *) (&height), 4); + (void) memcpy((void *) (pc + 52), (void *) (&format), 4); + (void) memcpy((void *) (pc + 56), (void *) (&type), 4); + (void) memset((void *) (pc + 60), 0, 4); + __glXSendLargeImage(gc, compsize, dim, width, height, 1, format, + type, pixels, pc + 64, pc + 8); + } + } +} + +#define X_GLrop_TexSubImage1D 4099 +void +__indirect_glTexSubImage1D(GLenum target, GLint level, GLint xoffset, + GLsizei width, GLenum format, GLenum type, + const GLvoid * pixels) +{ + __glx_TexSubImage_1D2D(X_GLrop_TexSubImage1D, 1, target, level, xoffset, + 1, width, 1, format, type, pixels); +} + +#define X_GLrop_TexSubImage2D 4100 +void +__indirect_glTexSubImage2D(GLenum target, GLint level, GLint xoffset, + GLint yoffset, GLsizei width, GLsizei height, + GLenum format, GLenum type, const GLvoid * pixels) +{ + __glx_TexSubImage_1D2D(X_GLrop_TexSubImage2D, 2, target, level, xoffset, + yoffset, width, height, format, type, pixels); +} + +#define X_GLrop_BlendColor 4096 +void +__indirect_glBlendColor(GLclampf red, GLclampf green, GLclampf blue, + GLclampf alpha) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_BlendColor, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&green), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&blue), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&alpha), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_BlendEquation 4097 +void +__indirect_glBlendEquation(GLenum mode) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_BlendEquation, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&mode), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ColorTable 2053 +void +__indirect_glColorTable(GLenum target, GLenum internalformat, GLsizei width, + GLenum format, GLenum type, const GLvoid * table) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = + (table != NULL) ? __glImageSize(width, 1, 1, format, type, + target) : 0; + const GLuint cmdlen = 44 + __GLX_PAD(compsize); + if (__builtin_expect(gc->currentDpy != NULL, 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, X_GLrop_ColorTable, cmdlen); + (void) memcpy((void *) (gc->pc + 24), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 28), (void *) (&internalformat), + 4); + (void) memcpy((void *) (gc->pc + 32), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 36), (void *) (&format), 4); + (void) memcpy((void *) (gc->pc + 40), (void *) (&type), 4); + if (compsize > 0) { + (*gc->fillImage) (gc, 1, width, 1, 1, format, type, table, + gc->pc + 44, gc->pc + 4); + } else { + (void) memcpy(gc->pc + 4, default_pixel_store_1D, + default_pixel_store_1D_size); + } + gc->pc += cmdlen; + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = X_GLrop_ColorTable; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 28), (void *) (&target), 4); + (void) memcpy((void *) (pc + 32), (void *) (&internalformat), 4); + (void) memcpy((void *) (pc + 36), (void *) (&width), 4); + (void) memcpy((void *) (pc + 40), (void *) (&format), 4); + (void) memcpy((void *) (pc + 44), (void *) (&type), 4); + __glXSendLargeImage(gc, compsize, 1, width, 1, 1, format, type, + table, pc + 48, pc + 8); + } + } +} + +#define X_GLrop_ColorTableParameterfv 2054 +void +__indirect_glColorTableParameterfv(GLenum target, GLenum pname, + const GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glColorTableParameterfv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_ColorTableParameterfv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ColorTableParameteriv 2055 +void +__indirect_glColorTableParameteriv(GLenum target, GLenum pname, + const GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glColorTableParameteriv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_ColorTableParameteriv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_CopyColorTable 2056 +void +__indirect_glCopyColorTable(GLenum target, GLenum internalformat, GLint x, + GLint y, GLsizei width) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_CopyColorTable, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&internalformat), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&width), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLsop_GetColorTable 147 +void +__indirect_glGetColorTable(GLenum target, GLenum format, GLenum type, + GLvoid * table) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const __GLXattribute *const state = gc->client_state_private; + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 16; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_color_table_reply_t *reply = + xcb_glx_get_color_table_reply(c, + xcb_glx_get_color_table(c, + gc-> + currentContextTag, + target, + format, + type, + state-> + storePack. + swapEndian), + NULL); + (void) memcpy(table, xcb_glx_get_color_table_data(reply), + xcb_glx_get_color_table_data_length(reply) * + sizeof(GLvoid)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetColorTable, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&format), 4); + (void) memcpy((void *) (pc + 8), (void *) (&type), 4); + *(int32_t *) (pc + 12) = 0; + *(int8_t *) (pc + 12) = state->storePack.swapEndian; + __glXReadPixelReply(dpy, gc, 1, 0, 0, 0, format, type, table, + GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLvop_GetColorTableSGI 4098 +void +glGetColorTableEXT(GLenum target, GLenum format, GLenum type, GLvoid * table) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->GetColorTable(target, format, type, table); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + const __GLXattribute *const state = gc->client_state_private; + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 16; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetColorTableSGI, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&format), 4); + (void) memcpy((void *) (pc + 8), (void *) (&type), 4); + *(int32_t *) (pc + 12) = 0; + *(int8_t *) (pc + 12) = state->storePack.swapEndian; + __glXReadPixelReply(dpy, gc, 1, 0, 0, 0, format, type, table, + GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; + } +} + +#define X_GLsop_GetColorTableParameterfv 148 +void +__indirect_glGetColorTableParameterfv(GLenum target, GLenum pname, + GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_color_table_parameterfv_reply_t *reply = + xcb_glx_get_color_table_parameterfv_reply(c, + xcb_glx_get_color_table_parameterfv + (c, + gc->currentContextTag, + target, pname), NULL); + if (xcb_glx_get_color_table_parameterfv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, + xcb_glx_get_color_table_parameterfv_data(reply), + xcb_glx_get_color_table_parameterfv_data_length + (reply) * sizeof(GLfloat)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetColorTableParameterfv, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLvop_GetColorTableParameterfvSGI 4099 +void +glGetColorTableParameterfvEXT(GLenum target, GLenum pname, GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->GetColorTableParameterfv(target, pname, params); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetColorTableParameterfvSGI, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; + } +} + +#define X_GLsop_GetColorTableParameteriv 149 +void +__indirect_glGetColorTableParameteriv(GLenum target, GLenum pname, + GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_color_table_parameteriv_reply_t *reply = + xcb_glx_get_color_table_parameteriv_reply(c, + xcb_glx_get_color_table_parameteriv + (c, + gc->currentContextTag, + target, pname), NULL); + if (xcb_glx_get_color_table_parameteriv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, + xcb_glx_get_color_table_parameteriv_data(reply), + xcb_glx_get_color_table_parameteriv_data_length + (reply) * sizeof(GLint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetColorTableParameteriv, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLvop_GetColorTableParameterivSGI 4100 +void +glGetColorTableParameterivEXT(GLenum target, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->GetColorTableParameteriv(target, pname, params); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetColorTableParameterivSGI, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; + } +} + +#define X_GLrop_ColorSubTable 195 +void +__indirect_glColorSubTable(GLenum target, GLsizei start, GLsizei count, + GLenum format, GLenum type, const GLvoid * data) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = + (data != NULL) ? __glImageSize(count, 1, 1, format, type, target) : 0; + const GLuint cmdlen = 44 + __GLX_PAD(compsize); + if (__builtin_expect(gc->currentDpy != NULL, 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, X_GLrop_ColorSubTable, cmdlen); + (void) memcpy((void *) (gc->pc + 24), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 28), (void *) (&start), 4); + (void) memcpy((void *) (gc->pc + 32), (void *) (&count), 4); + (void) memcpy((void *) (gc->pc + 36), (void *) (&format), 4); + (void) memcpy((void *) (gc->pc + 40), (void *) (&type), 4); + if (compsize > 0) { + (*gc->fillImage) (gc, 1, count, 1, 1, format, type, data, + gc->pc + 44, gc->pc + 4); + } else { + (void) memcpy(gc->pc + 4, default_pixel_store_1D, + default_pixel_store_1D_size); + } + gc->pc += cmdlen; + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = X_GLrop_ColorSubTable; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 28), (void *) (&target), 4); + (void) memcpy((void *) (pc + 32), (void *) (&start), 4); + (void) memcpy((void *) (pc + 36), (void *) (&count), 4); + (void) memcpy((void *) (pc + 40), (void *) (&format), 4); + (void) memcpy((void *) (pc + 44), (void *) (&type), 4); + __glXSendLargeImage(gc, compsize, 1, count, 1, 1, format, type, + data, pc + 48, pc + 8); + } + } +} + +#define X_GLrop_CopyColorSubTable 196 +void +__indirect_glCopyColorSubTable(GLenum target, GLsizei start, GLint x, GLint y, + GLsizei width) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_CopyColorSubTable, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&start), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&width), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +static void +__glx_ConvolutionFilter_1D2D(unsigned opcode, unsigned dim, GLenum target, + GLenum internalformat, GLsizei width, + GLsizei height, GLenum format, GLenum type, + const GLvoid * image) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = + (image != NULL) ? __glImageSize(width, height, 1, format, type, + target) : 0; + const GLuint cmdlen = 48 + __GLX_PAD(compsize); + if (__builtin_expect(gc->currentDpy != NULL, 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, opcode, cmdlen); + (void) memcpy((void *) (gc->pc + 24), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 28), (void *) (&internalformat), + 4); + (void) memcpy((void *) (gc->pc + 32), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 36), (void *) (&height), 4); + (void) memcpy((void *) (gc->pc + 40), (void *) (&format), 4); + (void) memcpy((void *) (gc->pc + 44), (void *) (&type), 4); + if (compsize > 0) { + (*gc->fillImage) (gc, dim, width, height, 1, format, type, + image, gc->pc + 48, gc->pc + 4); + } else { + (void) memcpy(gc->pc + 4, default_pixel_store_2D, + default_pixel_store_2D_size); + } + gc->pc += cmdlen; + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = opcode; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 28), (void *) (&target), 4); + (void) memcpy((void *) (pc + 32), (void *) (&internalformat), 4); + (void) memcpy((void *) (pc + 36), (void *) (&width), 4); + (void) memcpy((void *) (pc + 40), (void *) (&height), 4); + (void) memcpy((void *) (pc + 44), (void *) (&format), 4); + (void) memcpy((void *) (pc + 48), (void *) (&type), 4); + __glXSendLargeImage(gc, compsize, dim, width, height, 1, format, + type, image, pc + 52, pc + 8); + } + } +} + +#define X_GLrop_ConvolutionFilter1D 4101 +void +__indirect_glConvolutionFilter1D(GLenum target, GLenum internalformat, + GLsizei width, GLenum format, GLenum type, + const GLvoid * image) +{ + __glx_ConvolutionFilter_1D2D(X_GLrop_ConvolutionFilter1D, 1, target, + internalformat, width, 1, format, type, + image); +} + +#define X_GLrop_ConvolutionFilter2D 4102 +void +__indirect_glConvolutionFilter2D(GLenum target, GLenum internalformat, + GLsizei width, GLsizei height, GLenum format, + GLenum type, const GLvoid * image) +{ + __glx_ConvolutionFilter_1D2D(X_GLrop_ConvolutionFilter2D, 2, target, + internalformat, width, height, format, type, + image); +} + +#define X_GLrop_ConvolutionParameterf 4103 +void +__indirect_glConvolutionParameterf(GLenum target, GLenum pname, + GLfloat params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_ConvolutionParameterf, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (¶ms), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ConvolutionParameterfv 4104 +void +__indirect_glConvolutionParameterfv(GLenum target, GLenum pname, + const GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glConvolutionParameterfv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_ConvolutionParameterfv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ConvolutionParameteri 4105 +void +__indirect_glConvolutionParameteri(GLenum target, GLenum pname, GLint params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_ConvolutionParameteri, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (¶ms), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ConvolutionParameteriv 4106 +void +__indirect_glConvolutionParameteriv(GLenum target, GLenum pname, + const GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glConvolutionParameteriv_size(pname); + const GLuint cmdlen = 12 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_ConvolutionParameteriv, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_CopyConvolutionFilter1D 4107 +void +__indirect_glCopyConvolutionFilter1D(GLenum target, GLenum internalformat, + GLint x, GLint y, GLsizei width) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_CopyConvolutionFilter1D, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&internalformat), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&width), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_CopyConvolutionFilter2D 4108 +void +__indirect_glCopyConvolutionFilter2D(GLenum target, GLenum internalformat, + GLint x, GLint y, GLsizei width, + GLsizei height) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_CopyConvolutionFilter2D, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&internalformat), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 24), (void *) (&height), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLsop_GetConvolutionFilter 150 +void +__indirect_glGetConvolutionFilter(GLenum target, GLenum format, GLenum type, + GLvoid * image) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const __GLXattribute *const state = gc->client_state_private; + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 16; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_convolution_filter_reply_t *reply = + xcb_glx_get_convolution_filter_reply(c, + xcb_glx_get_convolution_filter + (c, gc->currentContextTag, + target, format, type, + state->storePack. + swapEndian), NULL); + (void) memcpy(image, xcb_glx_get_convolution_filter_data(reply), + xcb_glx_get_convolution_filter_data_length(reply) * + sizeof(GLvoid)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetConvolutionFilter, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&format), 4); + (void) memcpy((void *) (pc + 8), (void *) (&type), 4); + *(int32_t *) (pc + 12) = 0; + *(int8_t *) (pc + 12) = state->storePack.swapEndian; + __glXReadPixelReply(dpy, gc, 2, 0, 0, 0, format, type, image, + GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLvop_GetConvolutionFilterEXT 1 +void +gl_dispatch_stub_356(GLenum target, GLenum format, GLenum type, + GLvoid * image) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->GetConvolutionFilter(target, format, type, image); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + const __GLXattribute *const state = gc->client_state_private; + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 16; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetConvolutionFilterEXT, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&format), 4); + (void) memcpy((void *) (pc + 8), (void *) (&type), 4); + *(int32_t *) (pc + 12) = 0; + *(int8_t *) (pc + 12) = state->storePack.swapEndian; + __glXReadPixelReply(dpy, gc, 2, 0, 0, 0, format, type, image, + GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; + } +} + +#define X_GLsop_GetConvolutionParameterfv 151 +void +__indirect_glGetConvolutionParameterfv(GLenum target, GLenum pname, + GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_convolution_parameterfv_reply_t *reply = + xcb_glx_get_convolution_parameterfv_reply(c, + xcb_glx_get_convolution_parameterfv + (c, + gc->currentContextTag, + target, pname), NULL); + if (xcb_glx_get_convolution_parameterfv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, + xcb_glx_get_convolution_parameterfv_data(reply), + xcb_glx_get_convolution_parameterfv_data_length + (reply) * sizeof(GLfloat)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetConvolutionParameterfv, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLvop_GetConvolutionParameterfvEXT 2 +void +gl_dispatch_stub_357(GLenum target, GLenum pname, GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->GetConvolutionParameterfv(target, pname, params); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetConvolutionParameterfvEXT, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; + } +} + +#define X_GLsop_GetConvolutionParameteriv 152 +void +__indirect_glGetConvolutionParameteriv(GLenum target, GLenum pname, + GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_convolution_parameteriv_reply_t *reply = + xcb_glx_get_convolution_parameteriv_reply(c, + xcb_glx_get_convolution_parameteriv + (c, + gc->currentContextTag, + target, pname), NULL); + if (xcb_glx_get_convolution_parameteriv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, + xcb_glx_get_convolution_parameteriv_data(reply), + xcb_glx_get_convolution_parameteriv_data_length + (reply) * sizeof(GLint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetConvolutionParameteriv, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLvop_GetConvolutionParameterivEXT 3 +void +gl_dispatch_stub_358(GLenum target, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->GetConvolutionParameteriv(target, pname, params); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetConvolutionParameterivEXT, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; + } +} + +#define X_GLsop_GetHistogram 154 +void +__indirect_glGetHistogram(GLenum target, GLboolean reset, GLenum format, + GLenum type, GLvoid * values) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const __GLXattribute *const state = gc->client_state_private; + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 16; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_histogram_reply_t *reply = + xcb_glx_get_histogram_reply(c, + xcb_glx_get_histogram(c, + gc-> + currentContextTag, + target, reset, + format, type, + state-> + storePack. + swapEndian), + NULL); + (void) memcpy(values, xcb_glx_get_histogram_data(reply), + xcb_glx_get_histogram_data_length(reply) * + sizeof(GLvoid)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetHistogram, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&format), 4); + (void) memcpy((void *) (pc + 8), (void *) (&type), 4); + *(int32_t *) (pc + 12) = 0; + *(int8_t *) (pc + 12) = state->storePack.swapEndian; + *(int8_t *) (pc + 13) = reset; + __glXReadPixelReply(dpy, gc, 1, 0, 0, 0, format, type, values, + GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLvop_GetHistogramEXT 5 +void +gl_dispatch_stub_361(GLenum target, GLboolean reset, GLenum format, + GLenum type, GLvoid * values) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->GetHistogram(target, reset, format, type, values); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + const __GLXattribute *const state = gc->client_state_private; + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 16; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetHistogramEXT, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&format), 4); + (void) memcpy((void *) (pc + 8), (void *) (&type), 4); + *(int32_t *) (pc + 12) = 0; + *(int8_t *) (pc + 12) = state->storePack.swapEndian; + *(int8_t *) (pc + 13) = reset; + __glXReadPixelReply(dpy, gc, 1, 0, 0, 0, format, type, values, + GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; + } +} + +#define X_GLsop_GetHistogramParameterfv 155 +void +__indirect_glGetHistogramParameterfv(GLenum target, GLenum pname, + GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_histogram_parameterfv_reply_t *reply = + xcb_glx_get_histogram_parameterfv_reply(c, + xcb_glx_get_histogram_parameterfv + (c, gc->currentContextTag, + target, pname), NULL); + if (xcb_glx_get_histogram_parameterfv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, + xcb_glx_get_histogram_parameterfv_data(reply), + xcb_glx_get_histogram_parameterfv_data_length(reply) + * sizeof(GLfloat)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetHistogramParameterfv, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLvop_GetHistogramParameterfvEXT 6 +void +gl_dispatch_stub_362(GLenum target, GLenum pname, GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->GetHistogramParameterfv(target, pname, params); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetHistogramParameterfvEXT, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; + } +} + +#define X_GLsop_GetHistogramParameteriv 156 +void +__indirect_glGetHistogramParameteriv(GLenum target, GLenum pname, + GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_histogram_parameteriv_reply_t *reply = + xcb_glx_get_histogram_parameteriv_reply(c, + xcb_glx_get_histogram_parameteriv + (c, gc->currentContextTag, + target, pname), NULL); + if (xcb_glx_get_histogram_parameteriv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, + xcb_glx_get_histogram_parameteriv_data(reply), + xcb_glx_get_histogram_parameteriv_data_length(reply) + * sizeof(GLint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetHistogramParameteriv, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLvop_GetHistogramParameterivEXT 7 +void +gl_dispatch_stub_363(GLenum target, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->GetHistogramParameteriv(target, pname, params); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetHistogramParameterivEXT, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; + } +} + +#define X_GLsop_GetMinmax 157 +void +__indirect_glGetMinmax(GLenum target, GLboolean reset, GLenum format, + GLenum type, GLvoid * values) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const __GLXattribute *const state = gc->client_state_private; + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 16; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_minmax_reply_t *reply = + xcb_glx_get_minmax_reply(c, + xcb_glx_get_minmax(c, + gc->currentContextTag, + target, reset, format, + type, + state->storePack. + swapEndian), NULL); + (void) memcpy(values, xcb_glx_get_minmax_data(reply), + xcb_glx_get_minmax_data_length(reply) * sizeof(GLvoid)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetMinmax, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&format), 4); + (void) memcpy((void *) (pc + 8), (void *) (&type), 4); + *(int32_t *) (pc + 12) = 0; + *(int8_t *) (pc + 12) = state->storePack.swapEndian; + *(int8_t *) (pc + 13) = reset; + __glXReadPixelReply(dpy, gc, 1, 2, 1, 1, format, type, values, + GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLvop_GetMinmaxEXT 8 +void +gl_dispatch_stub_364(GLenum target, GLboolean reset, GLenum format, + GLenum type, GLvoid * values) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->GetMinmax(target, reset, format, type, values); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + const __GLXattribute *const state = gc->client_state_private; + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 16; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetMinmaxEXT, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&format), 4); + (void) memcpy((void *) (pc + 8), (void *) (&type), 4); + *(int32_t *) (pc + 12) = 0; + *(int8_t *) (pc + 12) = state->storePack.swapEndian; + *(int8_t *) (pc + 13) = reset; + __glXReadPixelReply(dpy, gc, 1, 2, 1, 1, format, type, values, + GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; + } +} + +#define X_GLsop_GetMinmaxParameterfv 158 +void +__indirect_glGetMinmaxParameterfv(GLenum target, GLenum pname, + GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_minmax_parameterfv_reply_t *reply = + xcb_glx_get_minmax_parameterfv_reply(c, + xcb_glx_get_minmax_parameterfv + (c, gc->currentContextTag, + target, pname), NULL); + if (xcb_glx_get_minmax_parameterfv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_minmax_parameterfv_data(reply), + xcb_glx_get_minmax_parameterfv_data_length(reply) * + sizeof(GLfloat)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetMinmaxParameterfv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLvop_GetMinmaxParameterfvEXT 9 +void +gl_dispatch_stub_365(GLenum target, GLenum pname, GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->GetMinmaxParameterfv(target, pname, params); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetMinmaxParameterfvEXT, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; + } +} + +#define X_GLsop_GetMinmaxParameteriv 159 +void +__indirect_glGetMinmaxParameteriv(GLenum target, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_minmax_parameteriv_reply_t *reply = + xcb_glx_get_minmax_parameteriv_reply(c, + xcb_glx_get_minmax_parameteriv + (c, gc->currentContextTag, + target, pname), NULL); + if (xcb_glx_get_minmax_parameteriv_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_minmax_parameteriv_data(reply), + xcb_glx_get_minmax_parameteriv_data_length(reply) * + sizeof(GLint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetMinmaxParameteriv, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLvop_GetMinmaxParameterivEXT 10 +void +gl_dispatch_stub_366(GLenum target, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->GetMinmaxParameteriv(target, pname, params); + } else +#endif + { + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetMinmaxParameterivEXT, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; + } +} + +#define X_GLrop_Histogram 4110 +void +__indirect_glHistogram(GLenum target, GLsizei width, GLenum internalformat, + GLboolean sink) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_Histogram, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&internalformat), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&sink), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_Minmax 4111 +void +__indirect_glMinmax(GLenum target, GLenum internalformat, GLboolean sink) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_Minmax, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&internalformat), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&sink), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ResetHistogram 4112 +void +__indirect_glResetHistogram(GLenum target) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_ResetHistogram, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ResetMinmax 4113 +void +__indirect_glResetMinmax(GLenum target) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_ResetMinmax, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +static void +__glx_TexImage_3D4D(unsigned opcode, unsigned dim, GLenum target, GLint level, + GLint internalformat, GLsizei width, GLsizei height, + GLsizei depth, GLsizei extent, GLint border, + GLenum format, GLenum type, const GLvoid * pixels) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = + (pixels != NULL) ? __glImageSize(width, height, depth, format, type, + target) : 0; + const GLuint cmdlen = 84 + __GLX_PAD(compsize); + if (__builtin_expect(gc->currentDpy != NULL, 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, opcode, cmdlen); + (void) memcpy((void *) (gc->pc + 40), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 44), (void *) (&level), 4); + (void) memcpy((void *) (gc->pc + 48), (void *) (&internalformat), + 4); + (void) memcpy((void *) (gc->pc + 52), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 56), (void *) (&height), 4); + (void) memcpy((void *) (gc->pc + 60), (void *) (&depth), 4); + (void) memcpy((void *) (gc->pc + 64), (void *) (&extent), 4); + (void) memcpy((void *) (gc->pc + 68), (void *) (&border), 4); + (void) memcpy((void *) (gc->pc + 72), (void *) (&format), 4); + (void) memcpy((void *) (gc->pc + 76), (void *) (&type), 4); + (void) memcpy((void *) (gc->pc + 80), + (void *) ((pixels == NULL) ? one : zero), 4); + if (compsize > 0) { + (*gc->fillImage) (gc, dim, width, height, depth, format, type, + pixels, gc->pc + 84, gc->pc + 4); + } else { + (void) memcpy(gc->pc + 4, default_pixel_store_4D, + default_pixel_store_4D_size); + } + gc->pc += cmdlen; + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = opcode; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 44), (void *) (&target), 4); + (void) memcpy((void *) (pc + 48), (void *) (&level), 4); + (void) memcpy((void *) (pc + 52), (void *) (&internalformat), 4); + (void) memcpy((void *) (pc + 56), (void *) (&width), 4); + (void) memcpy((void *) (pc + 60), (void *) (&height), 4); + (void) memcpy((void *) (pc + 64), (void *) (&depth), 4); + (void) memcpy((void *) (pc + 68), (void *) (&extent), 4); + (void) memcpy((void *) (pc + 72), (void *) (&border), 4); + (void) memcpy((void *) (pc + 76), (void *) (&format), 4); + (void) memcpy((void *) (pc + 80), (void *) (&type), 4); + (void) memcpy((void *) (pc + 84), zero, 4); + __glXSendLargeImage(gc, compsize, dim, width, height, depth, + format, type, pixels, pc + 88, pc + 8); + } + } +} + +#define X_GLrop_TexImage3D 4114 +void +__indirect_glTexImage3D(GLenum target, GLint level, GLint internalformat, + GLsizei width, GLsizei height, GLsizei depth, + GLint border, GLenum format, GLenum type, + const GLvoid * pixels) +{ + __glx_TexImage_3D4D(X_GLrop_TexImage3D, 3, target, level, internalformat, + width, height, depth, 1, border, format, type, + pixels); +} + +static void +__glx_TexSubImage_3D4D(unsigned opcode, unsigned dim, GLenum target, + GLint level, GLint xoffset, GLint yoffset, + GLint zoffset, GLint woffset, GLsizei width, + GLsizei height, GLsizei depth, GLsizei extent, + GLenum format, GLenum type, const GLvoid * pixels) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = + (pixels != NULL) ? __glImageSize(width, height, depth, format, type, + target) : 0; + const GLuint cmdlen = 92 + __GLX_PAD(compsize); + if (__builtin_expect(gc->currentDpy != NULL, 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, opcode, cmdlen); + (void) memcpy((void *) (gc->pc + 40), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 44), (void *) (&level), 4); + (void) memcpy((void *) (gc->pc + 48), (void *) (&xoffset), 4); + (void) memcpy((void *) (gc->pc + 52), (void *) (&yoffset), 4); + (void) memcpy((void *) (gc->pc + 56), (void *) (&zoffset), 4); + (void) memcpy((void *) (gc->pc + 60), (void *) (&woffset), 4); + (void) memcpy((void *) (gc->pc + 64), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 68), (void *) (&height), 4); + (void) memcpy((void *) (gc->pc + 72), (void *) (&depth), 4); + (void) memcpy((void *) (gc->pc + 76), (void *) (&extent), 4); + (void) memcpy((void *) (gc->pc + 80), (void *) (&format), 4); + (void) memcpy((void *) (gc->pc + 84), (void *) (&type), 4); + (void) memset((void *) (gc->pc + 88), 0, 4); + if (compsize > 0) { + (*gc->fillImage) (gc, dim, width, height, depth, format, type, + pixels, gc->pc + 92, gc->pc + 4); + } else { + (void) memcpy(gc->pc + 4, default_pixel_store_4D, + default_pixel_store_4D_size); + } + gc->pc += cmdlen; + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = opcode; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 44), (void *) (&target), 4); + (void) memcpy((void *) (pc + 48), (void *) (&level), 4); + (void) memcpy((void *) (pc + 52), (void *) (&xoffset), 4); + (void) memcpy((void *) (pc + 56), (void *) (&yoffset), 4); + (void) memcpy((void *) (pc + 60), (void *) (&zoffset), 4); + (void) memcpy((void *) (pc + 64), (void *) (&woffset), 4); + (void) memcpy((void *) (pc + 68), (void *) (&width), 4); + (void) memcpy((void *) (pc + 72), (void *) (&height), 4); + (void) memcpy((void *) (pc + 76), (void *) (&depth), 4); + (void) memcpy((void *) (pc + 80), (void *) (&extent), 4); + (void) memcpy((void *) (pc + 84), (void *) (&format), 4); + (void) memcpy((void *) (pc + 88), (void *) (&type), 4); + (void) memset((void *) (pc + 92), 0, 4); + __glXSendLargeImage(gc, compsize, dim, width, height, depth, + format, type, pixels, pc + 96, pc + 8); + } + } +} + +#define X_GLrop_TexSubImage3D 4115 +void +__indirect_glTexSubImage3D(GLenum target, GLint level, GLint xoffset, + GLint yoffset, GLint zoffset, GLsizei width, + GLsizei height, GLsizei depth, GLenum format, + GLenum type, const GLvoid * pixels) +{ + __glx_TexSubImage_3D4D(X_GLrop_TexSubImage3D, 3, target, level, xoffset, + yoffset, zoffset, 1, width, height, depth, 1, + format, type, pixels); +} + +#define X_GLrop_CopyTexSubImage3D 4123 +void +__indirect_glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, + GLint yoffset, GLint zoffset, GLint x, GLint y, + GLsizei width, GLsizei height) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 40; + emit_header(gc->pc, X_GLrop_CopyTexSubImage3D, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&level), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&xoffset), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&yoffset), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&zoffset), 4); + (void) memcpy((void *) (gc->pc + 24), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 28), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 32), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 36), (void *) (&height), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ActiveTextureARB 197 +void +__indirect_glActiveTextureARB(GLenum texture) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_ActiveTextureARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&texture), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord1dvARB 198 +void +__indirect_glMultiTexCoord1dARB(GLenum target, GLdouble s) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_MultiTexCoord1dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&target), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord1dvARB 198 +void +__indirect_glMultiTexCoord1dvARB(GLenum target, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_MultiTexCoord1dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (v), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&target), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord1fvARB 199 +void +__indirect_glMultiTexCoord1fARB(GLenum target, GLfloat s) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_MultiTexCoord1fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&s), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord1fvARB 199 +void +__indirect_glMultiTexCoord1fvARB(GLenum target, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_MultiTexCoord1fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord1ivARB 200 +void +__indirect_glMultiTexCoord1iARB(GLenum target, GLint s) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_MultiTexCoord1ivARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&s), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord1ivARB 200 +void +__indirect_glMultiTexCoord1ivARB(GLenum target, const GLint * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_MultiTexCoord1ivARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord1svARB 201 +void +__indirect_glMultiTexCoord1sARB(GLenum target, GLshort s) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_MultiTexCoord1svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&s), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord1svARB 201 +void +__indirect_glMultiTexCoord1svARB(GLenum target, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_MultiTexCoord1svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord2dvARB 202 +void +__indirect_glMultiTexCoord2dARB(GLenum target, GLdouble s, GLdouble t) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_MultiTexCoord2dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&t), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&target), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord2dvARB 202 +void +__indirect_glMultiTexCoord2dvARB(GLenum target, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_MultiTexCoord2dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (v), 16); + (void) memcpy((void *) (gc->pc + 20), (void *) (&target), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord2fvARB 203 +void +__indirect_glMultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_MultiTexCoord2fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&s), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&t), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord2fvARB 203 +void +__indirect_glMultiTexCoord2fvARB(GLenum target, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_MultiTexCoord2fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord2ivARB 204 +void +__indirect_glMultiTexCoord2iARB(GLenum target, GLint s, GLint t) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_MultiTexCoord2ivARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&s), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&t), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord2ivARB 204 +void +__indirect_glMultiTexCoord2ivARB(GLenum target, const GLint * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_MultiTexCoord2ivARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord2svARB 205 +void +__indirect_glMultiTexCoord2sARB(GLenum target, GLshort s, GLshort t) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_MultiTexCoord2svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&s), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&t), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord2svARB 205 +void +__indirect_glMultiTexCoord2svARB(GLenum target, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_MultiTexCoord2svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord3dvARB 206 +void +__indirect_glMultiTexCoord3dARB(GLenum target, GLdouble s, GLdouble t, + GLdouble r) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 32; + emit_header(gc->pc, X_GLrop_MultiTexCoord3dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&t), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&r), 8); + (void) memcpy((void *) (gc->pc + 28), (void *) (&target), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord3dvARB 206 +void +__indirect_glMultiTexCoord3dvARB(GLenum target, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 32; + emit_header(gc->pc, X_GLrop_MultiTexCoord3dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (v), 24); + (void) memcpy((void *) (gc->pc + 28), (void *) (&target), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord3fvARB 207 +void +__indirect_glMultiTexCoord3fARB(GLenum target, GLfloat s, GLfloat t, + GLfloat r) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_MultiTexCoord3fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&s), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&t), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&r), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord3fvARB 207 +void +__indirect_glMultiTexCoord3fvARB(GLenum target, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_MultiTexCoord3fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 12); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord3ivARB 208 +void +__indirect_glMultiTexCoord3iARB(GLenum target, GLint s, GLint t, GLint r) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_MultiTexCoord3ivARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&s), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&t), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&r), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord3ivARB 208 +void +__indirect_glMultiTexCoord3ivARB(GLenum target, const GLint * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_MultiTexCoord3ivARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 12); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord3svARB 209 +void +__indirect_glMultiTexCoord3sARB(GLenum target, GLshort s, GLshort t, + GLshort r) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_MultiTexCoord3svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&s), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&t), 2); + (void) memcpy((void *) (gc->pc + 12), (void *) (&r), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord3svARB 209 +void +__indirect_glMultiTexCoord3svARB(GLenum target, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_MultiTexCoord3svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 6); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord4dvARB 210 +void +__indirect_glMultiTexCoord4dARB(GLenum target, GLdouble s, GLdouble t, + GLdouble r, GLdouble q) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 40; + emit_header(gc->pc, X_GLrop_MultiTexCoord4dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&s), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&t), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&r), 8); + (void) memcpy((void *) (gc->pc + 28), (void *) (&q), 8); + (void) memcpy((void *) (gc->pc + 36), (void *) (&target), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord4dvARB 210 +void +__indirect_glMultiTexCoord4dvARB(GLenum target, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 40; + emit_header(gc->pc, X_GLrop_MultiTexCoord4dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (v), 32); + (void) memcpy((void *) (gc->pc + 36), (void *) (&target), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord4fvARB 211 +void +__indirect_glMultiTexCoord4fARB(GLenum target, GLfloat s, GLfloat t, + GLfloat r, GLfloat q) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_MultiTexCoord4fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&s), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&t), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&r), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&q), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord4fvARB 211 +void +__indirect_glMultiTexCoord4fvARB(GLenum target, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_MultiTexCoord4fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord4ivARB 212 +void +__indirect_glMultiTexCoord4iARB(GLenum target, GLint s, GLint t, GLint r, + GLint q) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_MultiTexCoord4ivARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&s), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&t), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&r), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&q), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord4ivARB 212 +void +__indirect_glMultiTexCoord4ivARB(GLenum target, const GLint * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_MultiTexCoord4ivARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord4svARB 213 +void +__indirect_glMultiTexCoord4sARB(GLenum target, GLshort s, GLshort t, + GLshort r, GLshort q) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_MultiTexCoord4svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&s), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&t), 2); + (void) memcpy((void *) (gc->pc + 12), (void *) (&r), 2); + (void) memcpy((void *) (gc->pc + 14), (void *) (&q), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_MultiTexCoord4svARB 213 +void +__indirect_glMultiTexCoord4svARB(GLenum target, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_MultiTexCoord4svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_SampleCoverageARB 229 +void +__indirect_glSampleCoverageARB(GLclampf value, GLboolean invert) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_SampleCoverageARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&value), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&invert), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLvop_GetProgramStringARB 1308 +void +__indirect_glGetProgramStringARB(GLenum target, GLenum pname, GLvoid * string) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetProgramStringARB, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 1, string, GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLvop_GetProgramivARB 1307 +void +__indirect_glGetProgramivARB(GLenum target, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetProgramivARB, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLrop_ProgramEnvParameter4dvARB 4185 +void +__indirect_glProgramEnvParameter4dARB(GLenum target, GLuint index, GLdouble x, + GLdouble y, GLdouble z, GLdouble w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 44; + emit_header(gc->pc, X_GLrop_ProgramEnvParameter4dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&y), 8); + (void) memcpy((void *) (gc->pc + 28), (void *) (&z), 8); + (void) memcpy((void *) (gc->pc + 36), (void *) (&w), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ProgramEnvParameter4dvARB 4185 +void +__indirect_glProgramEnvParameter4dvARB(GLenum target, GLuint index, + const GLdouble * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 44; + emit_header(gc->pc, X_GLrop_ProgramEnvParameter4dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), 32); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ProgramEnvParameter4fvARB 4184 +void +__indirect_glProgramEnvParameter4fARB(GLenum target, GLuint index, GLfloat x, + GLfloat y, GLfloat z, GLfloat w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_ProgramEnvParameter4fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&z), 4); + (void) memcpy((void *) (gc->pc + 24), (void *) (&w), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ProgramEnvParameter4fvARB 4184 +void +__indirect_glProgramEnvParameter4fvARB(GLenum target, GLuint index, + const GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_ProgramEnvParameter4fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ProgramLocalParameter4dvARB 4216 +void +__indirect_glProgramLocalParameter4dARB(GLenum target, GLuint index, + GLdouble x, GLdouble y, GLdouble z, + GLdouble w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 44; + emit_header(gc->pc, X_GLrop_ProgramLocalParameter4dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&y), 8); + (void) memcpy((void *) (gc->pc + 28), (void *) (&z), 8); + (void) memcpy((void *) (gc->pc + 36), (void *) (&w), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ProgramLocalParameter4dvARB 4216 +void +__indirect_glProgramLocalParameter4dvARB(GLenum target, GLuint index, + const GLdouble * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 44; + emit_header(gc->pc, X_GLrop_ProgramLocalParameter4dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), 32); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ProgramLocalParameter4fvARB 4215 +void +__indirect_glProgramLocalParameter4fARB(GLenum target, GLuint index, + GLfloat x, GLfloat y, GLfloat z, + GLfloat w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_ProgramLocalParameter4fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&z), 4); + (void) memcpy((void *) (gc->pc + 24), (void *) (&w), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ProgramLocalParameter4fvARB 4215 +void +__indirect_glProgramLocalParameter4fvARB(GLenum target, GLuint index, + const GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_ProgramLocalParameter4fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ProgramStringARB 4217 +void +__indirect_glProgramStringARB(GLenum target, GLenum format, GLsizei len, + const GLvoid * string) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16 + __GLX_PAD(len); + if (len < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((len >= 0) && (gc->currentDpy != NULL), 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, X_GLrop_ProgramStringARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&format), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&len), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (string), len); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = X_GLrop_ProgramStringARB; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 8), (void *) (&target), 4); + (void) memcpy((void *) (pc + 12), (void *) (&format), 4); + (void) memcpy((void *) (pc + 16), (void *) (&len), 4); + __glXSendLargeCommand(gc, pc, 20, string, len); + } + } +} + +#define X_GLrop_VertexAttrib1dvARB 4197 +void +__indirect_glVertexAttrib1dARB(GLuint index, GLdouble x) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib1dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib1dvARB 4197 +void +__indirect_glVertexAttrib1dvARB(GLuint index, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib1dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib1fvARB 4193 +void +__indirect_glVertexAttrib1fARB(GLuint index, GLfloat x) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib1fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib1fvARB 4193 +void +__indirect_glVertexAttrib1fvARB(GLuint index, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib1fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib1svARB 4189 +void +__indirect_glVertexAttrib1sARB(GLuint index, GLshort x) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib1svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib1svARB 4189 +void +__indirect_glVertexAttrib1svARB(GLuint index, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib1svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib2dvARB 4198 +void +__indirect_glVertexAttrib2dARB(GLuint index, GLdouble x, GLdouble y) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_VertexAttrib2dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib2dvARB 4198 +void +__indirect_glVertexAttrib2dvARB(GLuint index, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_VertexAttrib2dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib2fvARB 4194 +void +__indirect_glVertexAttrib2fARB(GLuint index, GLfloat x, GLfloat y) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib2fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib2fvARB 4194 +void +__indirect_glVertexAttrib2fvARB(GLuint index, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib2fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib2svARB 4190 +void +__indirect_glVertexAttrib2sARB(GLuint index, GLshort x, GLshort y) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib2svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&y), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib2svARB 4190 +void +__indirect_glVertexAttrib2svARB(GLuint index, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib2svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib3dvARB 4199 +void +__indirect_glVertexAttrib3dARB(GLuint index, GLdouble x, GLdouble y, + GLdouble z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 32; + emit_header(gc->pc, X_GLrop_VertexAttrib3dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y), 8); + (void) memcpy((void *) (gc->pc + 24), (void *) (&z), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib3dvARB 4199 +void +__indirect_glVertexAttrib3dvARB(GLuint index, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 32; + emit_header(gc->pc, X_GLrop_VertexAttrib3dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 24); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib3fvARB 4195 +void +__indirect_glVertexAttrib3fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_VertexAttrib3fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&z), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib3fvARB 4195 +void +__indirect_glVertexAttrib3fvARB(GLuint index, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_VertexAttrib3fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 12); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib3svARB 4191 +void +__indirect_glVertexAttrib3sARB(GLuint index, GLshort x, GLshort y, GLshort z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib3svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&y), 2); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib3svARB 4191 +void +__indirect_glVertexAttrib3svARB(GLuint index, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib3svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 6); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4NbvARB 4235 +void +__indirect_glVertexAttrib4NbvARB(GLuint index, const GLbyte *v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib4NbvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4NivARB 4237 +void +__indirect_glVertexAttrib4NivARB(GLuint index, const GLint * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_VertexAttrib4NivARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4NsvARB 4236 +void +__indirect_glVertexAttrib4NsvARB(GLuint index, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib4NsvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4NubvARB 4201 +void +__indirect_glVertexAttrib4NubARB(GLuint index, GLubyte x, GLubyte y, + GLubyte z, GLubyte w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib4NubvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 1); + (void) memcpy((void *) (gc->pc + 9), (void *) (&y), 1); + (void) memcpy((void *) (gc->pc + 10), (void *) (&z), 1); + (void) memcpy((void *) (gc->pc + 11), (void *) (&w), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4NubvARB 4201 +void +__indirect_glVertexAttrib4NubvARB(GLuint index, const GLubyte *v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib4NubvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4NuivARB 4239 +void +__indirect_glVertexAttrib4NuivARB(GLuint index, const GLuint * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_VertexAttrib4NuivARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4NusvARB 4238 +void +__indirect_glVertexAttrib4NusvARB(GLuint index, const GLushort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib4NusvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4bvARB 4230 +void +__indirect_glVertexAttrib4bvARB(GLuint index, const GLbyte *v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib4bvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4dvARB 4200 +void +__indirect_glVertexAttrib4dARB(GLuint index, GLdouble x, GLdouble y, + GLdouble z, GLdouble w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 40; + emit_header(gc->pc, X_GLrop_VertexAttrib4dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y), 8); + (void) memcpy((void *) (gc->pc + 24), (void *) (&z), 8); + (void) memcpy((void *) (gc->pc + 32), (void *) (&w), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4dvARB 4200 +void +__indirect_glVertexAttrib4dvARB(GLuint index, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 40; + emit_header(gc->pc, X_GLrop_VertexAttrib4dvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 32); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4fvARB 4196 +void +__indirect_glVertexAttrib4fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z, + GLfloat w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_VertexAttrib4fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&z), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&w), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4fvARB 4196 +void +__indirect_glVertexAttrib4fvARB(GLuint index, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_VertexAttrib4fvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4ivARB 4231 +void +__indirect_glVertexAttrib4ivARB(GLuint index, const GLint * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_VertexAttrib4ivARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4svARB 4192 +void +__indirect_glVertexAttrib4sARB(GLuint index, GLshort x, GLshort y, GLshort z, + GLshort w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib4svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&y), 2); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 2); + (void) memcpy((void *) (gc->pc + 14), (void *) (&w), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4svARB 4192 +void +__indirect_glVertexAttrib4svARB(GLuint index, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib4svARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4ubvARB 4232 +void +__indirect_glVertexAttrib4ubvARB(GLuint index, const GLubyte *v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib4ubvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4uivARB 4234 +void +__indirect_glVertexAttrib4uivARB(GLuint index, const GLuint * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_VertexAttrib4uivARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4usvARB 4233 +void +__indirect_glVertexAttrib4usvARB(GLuint index, const GLushort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib4usvARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_BeginQueryARB 231 +void +__indirect_glBeginQueryARB(GLenum target, GLuint id) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_BeginQueryARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&id), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLsop_DeleteQueriesARB 161 +void +__indirect_glDeleteQueriesARB(GLsizei n, const GLuint * ids) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 4 + __GLX_PAD((n * 4)); +#endif + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_delete_queries_arb(c, gc->currentContextTag, n, ids); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_DeleteQueriesARB, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) memcpy((void *) (pc + 4), (void *) (ids), (n * 4)); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLrop_EndQueryARB 232 +void +__indirect_glEndQueryARB(GLenum target) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_EndQueryARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLsop_GenQueriesARB 162 +void +__indirect_glGenQueriesARB(GLsizei n, GLuint * ids) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 4; +#endif + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_gen_queries_arb_reply_t *reply = + xcb_glx_gen_queries_arb_reply(c, + xcb_glx_gen_queries_arb(c, + gc-> + currentContextTag, + n), NULL); + (void) memcpy(ids, xcb_glx_gen_queries_arb_data(reply), + xcb_glx_gen_queries_arb_data_length(reply) * + sizeof(GLuint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GenQueriesARB, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) __glXReadReply(dpy, 4, ids, GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetQueryObjectivARB 165 +void +__indirect_glGetQueryObjectivARB(GLuint id, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_query_objectiv_arb_reply_t *reply = + xcb_glx_get_query_objectiv_arb_reply(c, + xcb_glx_get_query_objectiv_arb + (c, gc->currentContextTag, + id, pname), NULL); + if (xcb_glx_get_query_objectiv_arb_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_query_objectiv_arb_data(reply), + xcb_glx_get_query_objectiv_arb_data_length(reply) * + sizeof(GLint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetQueryObjectivARB, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&id), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetQueryObjectuivARB 166 +void +__indirect_glGetQueryObjectuivARB(GLuint id, GLenum pname, GLuint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_query_objectuiv_arb_reply_t *reply = + xcb_glx_get_query_objectuiv_arb_reply(c, + xcb_glx_get_query_objectuiv_arb + (c, gc->currentContextTag, + id, pname), NULL); + if (xcb_glx_get_query_objectuiv_arb_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_query_objectuiv_arb_data(reply), + xcb_glx_get_query_objectuiv_arb_data_length(reply) * + sizeof(GLuint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetQueryObjectuivARB, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&id), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_GetQueryivARB 164 +void +__indirect_glGetQueryivARB(GLenum target, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; +#ifndef USE_XCB + const GLuint cmdlen = 8; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_get_queryiv_arb_reply_t *reply = + xcb_glx_get_queryiv_arb_reply(c, + xcb_glx_get_queryiv_arb(c, + gc-> + currentContextTag, + target, + pname), + NULL); + if (xcb_glx_get_queryiv_arb_data_length(reply) == 0) + (void) memcpy(params, &reply->datum, sizeof(reply->datum)); + else + (void) memcpy(params, xcb_glx_get_queryiv_arb_data(reply), + xcb_glx_get_queryiv_arb_data_length(reply) * + sizeof(GLint)); + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_GetQueryivARB, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return; +} + +#define X_GLsop_IsQueryARB 163 +GLboolean +__indirect_glIsQueryARB(GLuint id) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + GLboolean retval = (GLboolean) 0; +#ifndef USE_XCB + const GLuint cmdlen = 4; +#endif + if (__builtin_expect(dpy != NULL, 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_is_query_arb_reply_t *reply = + xcb_glx_is_query_arb_reply(c, + xcb_glx_is_query_arb(c, + gc-> + currentContextTag, + id), NULL); + retval = reply->ret_val; + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_IsQueryARB, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&id), 4); + retval = (GLboolean) __glXReadReply(dpy, 0, NULL, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return retval; +} + +#define X_GLrop_DrawBuffersARB 233 +void +__indirect_glDrawBuffersARB(GLsizei n, const GLenum * bufs) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8 + __GLX_PAD((n * 4)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((n >= 0) && (gc->currentDpy != NULL), 1)) { + if (cmdlen <= gc->maxSmallRenderCommandSize) { + if ((gc->pc + cmdlen) > gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + emit_header(gc->pc, X_GLrop_DrawBuffersARB, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (bufs), (n * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } else { + const GLint op = X_GLrop_DrawBuffersARB; + const GLuint cmdlenLarge = cmdlen + 4; + GLubyte *const pc = __glXFlushRenderBuffer(gc, gc->pc); + (void) memcpy((void *) (pc + 0), (void *) (&cmdlenLarge), 4); + (void) memcpy((void *) (pc + 4), (void *) (&op), 4); + (void) memcpy((void *) (pc + 8), (void *) (&n), 4); + __glXSendLargeCommand(gc, pc, 12, bufs, (n * 4)); + } + } +} + +#define X_GLrop_RenderbufferStorageMultisample 4331 +void +__indirect_glRenderbufferStorageMultisample(GLenum target, GLsizei samples, + GLenum internalformat, + GLsizei width, GLsizei height) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_RenderbufferStorageMultisample, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&samples), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&internalformat), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&height), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_SampleMaskSGIS 2048 +void +__indirect_glSampleMaskSGIS(GLclampf value, GLboolean invert) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_SampleMaskSGIS, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&value), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&invert), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_SamplePatternSGIS 2049 +void +__indirect_glSamplePatternSGIS(GLenum pattern) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_SamplePatternSGIS, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pattern), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PointParameterfEXT 2065 +void +__indirect_glPointParameterfEXT(GLenum pname, GLfloat param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_PointParameterfEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PointParameterfvEXT 2066 +void +__indirect_glPointParameterfvEXT(GLenum pname, const GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glPointParameterfvEXT_size(pname); + const GLuint cmdlen = 8 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_PointParameterfvEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_SecondaryColor3bvEXT 4126 +void +__indirect_glSecondaryColor3bEXT(GLbyte red, GLbyte green, GLbyte blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_SecondaryColor3bvEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 1); + (void) memcpy((void *) (gc->pc + 5), (void *) (&green), 1); + (void) memcpy((void *) (gc->pc + 6), (void *) (&blue), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_SecondaryColor3bvEXT 4126 +void +__indirect_glSecondaryColor3bvEXT(const GLbyte *v) +{ + generic_3_byte(X_GLrop_SecondaryColor3bvEXT, v); +} + +#define X_GLrop_SecondaryColor3dvEXT 4130 +void +__indirect_glSecondaryColor3dEXT(GLdouble red, GLdouble green, GLdouble blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_SecondaryColor3dvEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&green), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&blue), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_SecondaryColor3dvEXT 4130 +void +__indirect_glSecondaryColor3dvEXT(const GLdouble * v) +{ + generic_24_byte(X_GLrop_SecondaryColor3dvEXT, v); +} + +#define X_GLrop_SecondaryColor3fvEXT 4129 +void +__indirect_glSecondaryColor3fEXT(GLfloat red, GLfloat green, GLfloat blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_SecondaryColor3fvEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&green), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&blue), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_SecondaryColor3fvEXT 4129 +void +__indirect_glSecondaryColor3fvEXT(const GLfloat * v) +{ + generic_12_byte(X_GLrop_SecondaryColor3fvEXT, v); +} + +#define X_GLrop_SecondaryColor3ivEXT 4128 +void +__indirect_glSecondaryColor3iEXT(GLint red, GLint green, GLint blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_SecondaryColor3ivEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&green), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&blue), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_SecondaryColor3ivEXT 4128 +void +__indirect_glSecondaryColor3ivEXT(const GLint * v) +{ + generic_12_byte(X_GLrop_SecondaryColor3ivEXT, v); +} + +#define X_GLrop_SecondaryColor3svEXT 4127 +void +__indirect_glSecondaryColor3sEXT(GLshort red, GLshort green, GLshort blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_SecondaryColor3svEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&green), 2); + (void) memcpy((void *) (gc->pc + 8), (void *) (&blue), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_SecondaryColor3svEXT 4127 +void +__indirect_glSecondaryColor3svEXT(const GLshort * v) +{ + generic_6_byte(X_GLrop_SecondaryColor3svEXT, v); +} + +#define X_GLrop_SecondaryColor3ubvEXT 4131 +void +__indirect_glSecondaryColor3ubEXT(GLubyte red, GLubyte green, GLubyte blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_SecondaryColor3ubvEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 1); + (void) memcpy((void *) (gc->pc + 5), (void *) (&green), 1); + (void) memcpy((void *) (gc->pc + 6), (void *) (&blue), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_SecondaryColor3ubvEXT 4131 +void +__indirect_glSecondaryColor3ubvEXT(const GLubyte *v) +{ + generic_3_byte(X_GLrop_SecondaryColor3ubvEXT, v); +} + +#define X_GLrop_SecondaryColor3uivEXT 4133 +void +__indirect_glSecondaryColor3uiEXT(GLuint red, GLuint green, GLuint blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_SecondaryColor3uivEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&green), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&blue), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_SecondaryColor3uivEXT 4133 +void +__indirect_glSecondaryColor3uivEXT(const GLuint * v) +{ + generic_12_byte(X_GLrop_SecondaryColor3uivEXT, v); +} + +#define X_GLrop_SecondaryColor3usvEXT 4132 +void +__indirect_glSecondaryColor3usEXT(GLushort red, GLushort green, GLushort blue) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_SecondaryColor3usvEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&red), 2); + (void) memcpy((void *) (gc->pc + 6), (void *) (&green), 2); + (void) memcpy((void *) (gc->pc + 8), (void *) (&blue), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_SecondaryColor3usvEXT 4132 +void +__indirect_glSecondaryColor3usvEXT(const GLushort * v) +{ + generic_6_byte(X_GLrop_SecondaryColor3usvEXT, v); +} + +#define X_GLrop_FogCoorddvEXT 4125 +void +__indirect_glFogCoorddEXT(GLdouble coord) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_FogCoorddvEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&coord), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_FogCoorddvEXT 4125 +void +__indirect_glFogCoorddvEXT(const GLdouble * coord) +{ + generic_8_byte(X_GLrop_FogCoorddvEXT, coord); +} + +#define X_GLrop_FogCoordfvEXT 4124 +void +__indirect_glFogCoordfEXT(GLfloat coord) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_FogCoordfvEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&coord), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_FogCoordfvEXT 4124 +void +__indirect_glFogCoordfvEXT(const GLfloat * coord) +{ + generic_4_byte(X_GLrop_FogCoordfvEXT, coord); +} + +#define X_GLrop_BlendFuncSeparateEXT 4134 +void +__indirect_glBlendFuncSeparateEXT(GLenum sfactorRGB, GLenum dfactorRGB, + GLenum sfactorAlpha, GLenum dfactorAlpha) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_BlendFuncSeparateEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&sfactorRGB), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&dfactorRGB), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&sfactorAlpha), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&dfactorAlpha), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_WindowPos3fvMESA 230 +void +__indirect_glWindowPos3fMESA(GLfloat x, GLfloat y, GLfloat z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_WindowPos3fvMESA, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_WindowPos3fvMESA 230 +void +__indirect_glWindowPos3fvMESA(const GLfloat * v) +{ + generic_12_byte(X_GLrop_WindowPos3fvMESA, v); +} + +#define X_GLvop_AreProgramsResidentNV 1293 +GLboolean +__indirect_glAreProgramsResidentNV(GLsizei n, const GLuint * ids, + GLboolean * residences) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + GLboolean retval = (GLboolean) 0; + const GLuint cmdlen = 4 + __GLX_PAD((n * 4)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return 0; + } + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_AreProgramsResidentNV, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) memcpy((void *) (pc + 4), (void *) (ids), (n * 4)); + retval = (GLboolean) __glXReadReply(dpy, 1, residences, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return retval; +} + +#define X_GLrop_BindProgramNV 4180 +void +__indirect_glBindProgramNV(GLenum target, GLuint program) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_BindProgramNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&program), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLvop_DeleteProgramsNV 1294 +void +__indirect_glDeleteProgramsNV(GLsizei n, const GLuint * programs) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 4 + __GLX_PAD((n * 4)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivate, + X_GLvop_DeleteProgramsNV, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) memcpy((void *) (pc + 4), (void *) (programs), (n * 4)); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLrop_ExecuteProgramNV 4181 +void +__indirect_glExecuteProgramNV(GLenum target, GLuint id, + const GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_ExecuteProgramNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&id), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (params), 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLvop_GenProgramsNV 1295 +void +__indirect_glGenProgramsNV(GLsizei n, GLuint * programs) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 4; + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GenProgramsNV, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) __glXReadReply(dpy, 4, programs, GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLvop_GetProgramParameterdvNV 1297 +void +__indirect_glGetProgramParameterdvNV(GLenum target, GLuint index, + GLenum pname, GLdouble * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 12; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetProgramParameterdvNV, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (pc + 8), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 8, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLvop_GetProgramParameterfvNV 1296 +void +__indirect_glGetProgramParameterfvNV(GLenum target, GLuint index, + GLenum pname, GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 12; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetProgramParameterfvNV, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (pc + 8), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLvop_GetProgramStringNV 1299 +void +__indirect_glGetProgramStringNV(GLuint id, GLenum pname, GLubyte *program) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetProgramStringNV, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&id), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 1, program, GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLvop_GetProgramivNV 1298 +void +__indirect_glGetProgramivNV(GLuint id, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetProgramivNV, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&id), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLvop_GetTrackMatrixivNV 1300 +void +__indirect_glGetTrackMatrixivNV(GLenum target, GLuint address, GLenum pname, + GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 12; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetTrackMatrixivNV, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&address), 4); + (void) memcpy((void *) (pc + 8), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLvop_GetVertexAttribdvNV 1301 +void +__indirect_glGetVertexAttribdvNV(GLuint index, GLenum pname, + GLdouble * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetVertexAttribdvNV, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&index), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 8, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLvop_GetVertexAttribfvNV 1302 +void +__indirect_glGetVertexAttribfvNV(GLuint index, GLenum pname, GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetVertexAttribfvNV, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&index), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLvop_GetVertexAttribivNV 1303 +void +__indirect_glGetVertexAttribivNV(GLuint index, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetVertexAttribivNV, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&index), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLvop_IsProgramNV 1304 +GLboolean +__indirect_glIsProgramNV(GLuint program) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + GLboolean retval = (GLboolean) 0; + const GLuint cmdlen = 4; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_IsProgramNV, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&program), 4); + retval = (GLboolean) __glXReadReply(dpy, 0, NULL, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return retval; +} + +#define X_GLrop_LoadProgramNV 4183 +void +__indirect_glLoadProgramNV(GLenum target, GLuint id, GLsizei len, + const GLubyte *program) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16 + __GLX_PAD(len); + if (len < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(len >= 0, 1)) { + emit_header(gc->pc, X_GLrop_LoadProgramNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&id), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&len), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (program), len); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_ProgramParameters4dvNV 4187 +void +__indirect_glProgramParameters4dvNV(GLenum target, GLuint index, GLsizei num, + const GLdouble * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16 + __GLX_PAD((num * 32)); + if (num < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(num >= 0, 1)) { + emit_header(gc->pc, X_GLrop_ProgramParameters4dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&num), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (params), (num * 32)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_ProgramParameters4fvNV 4186 +void +__indirect_glProgramParameters4fvNV(GLenum target, GLuint index, GLsizei num, + const GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16 + __GLX_PAD((num * 16)); + if (num < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(num >= 0, 1)) { + emit_header(gc->pc, X_GLrop_ProgramParameters4fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&num), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (params), (num * 16)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_RequestResidentProgramsNV 4182 +void +__indirect_glRequestResidentProgramsNV(GLsizei n, const GLuint * ids) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8 + __GLX_PAD((n * 4)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_RequestResidentProgramsNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (ids), (n * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_TrackMatrixNV 4188 +void +__indirect_glTrackMatrixNV(GLenum target, GLuint address, GLenum matrix, + GLenum transform) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_TrackMatrixNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&address), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&matrix), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&transform), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib1dvNV 4273 +void +__indirect_glVertexAttrib1dNV(GLuint index, GLdouble x) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib1dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib1dvNV 4273 +void +__indirect_glVertexAttrib1dvNV(GLuint index, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib1dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib1fvNV 4269 +void +__indirect_glVertexAttrib1fNV(GLuint index, GLfloat x) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib1fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib1fvNV 4269 +void +__indirect_glVertexAttrib1fvNV(GLuint index, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib1fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib1svNV 4265 +void +__indirect_glVertexAttrib1sNV(GLuint index, GLshort x) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib1svNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib1svNV 4265 +void +__indirect_glVertexAttrib1svNV(GLuint index, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib1svNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib2dvNV 4274 +void +__indirect_glVertexAttrib2dNV(GLuint index, GLdouble x, GLdouble y) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_VertexAttrib2dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib2dvNV 4274 +void +__indirect_glVertexAttrib2dvNV(GLuint index, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_VertexAttrib2dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib2fvNV 4270 +void +__indirect_glVertexAttrib2fNV(GLuint index, GLfloat x, GLfloat y) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib2fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib2fvNV 4270 +void +__indirect_glVertexAttrib2fvNV(GLuint index, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib2fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib2svNV 4266 +void +__indirect_glVertexAttrib2sNV(GLuint index, GLshort x, GLshort y) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib2svNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&y), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib2svNV 4266 +void +__indirect_glVertexAttrib2svNV(GLuint index, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib2svNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib3dvNV 4275 +void +__indirect_glVertexAttrib3dNV(GLuint index, GLdouble x, GLdouble y, + GLdouble z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 32; + emit_header(gc->pc, X_GLrop_VertexAttrib3dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y), 8); + (void) memcpy((void *) (gc->pc + 24), (void *) (&z), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib3dvNV 4275 +void +__indirect_glVertexAttrib3dvNV(GLuint index, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 32; + emit_header(gc->pc, X_GLrop_VertexAttrib3dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 24); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib3fvNV 4271 +void +__indirect_glVertexAttrib3fNV(GLuint index, GLfloat x, GLfloat y, GLfloat z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_VertexAttrib3fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&z), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib3fvNV 4271 +void +__indirect_glVertexAttrib3fvNV(GLuint index, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_VertexAttrib3fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 12); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib3svNV 4267 +void +__indirect_glVertexAttrib3sNV(GLuint index, GLshort x, GLshort y, GLshort z) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib3svNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&y), 2); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib3svNV 4267 +void +__indirect_glVertexAttrib3svNV(GLuint index, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib3svNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 6); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4dvNV 4276 +void +__indirect_glVertexAttrib4dNV(GLuint index, GLdouble x, GLdouble y, + GLdouble z, GLdouble w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 40; + emit_header(gc->pc, X_GLrop_VertexAttrib4dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y), 8); + (void) memcpy((void *) (gc->pc + 24), (void *) (&z), 8); + (void) memcpy((void *) (gc->pc + 32), (void *) (&w), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4dvNV 4276 +void +__indirect_glVertexAttrib4dvNV(GLuint index, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 40; + emit_header(gc->pc, X_GLrop_VertexAttrib4dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 32); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4fvNV 4272 +void +__indirect_glVertexAttrib4fNV(GLuint index, GLfloat x, GLfloat y, GLfloat z, + GLfloat w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_VertexAttrib4fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&z), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&w), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4fvNV 4272 +void +__indirect_glVertexAttrib4fvNV(GLuint index, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_VertexAttrib4fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 16); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4svNV 4268 +void +__indirect_glVertexAttrib4sNV(GLuint index, GLshort x, GLshort y, GLshort z, + GLshort w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib4svNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 2); + (void) memcpy((void *) (gc->pc + 10), (void *) (&y), 2); + (void) memcpy((void *) (gc->pc + 12), (void *) (&z), 2); + (void) memcpy((void *) (gc->pc + 14), (void *) (&w), 2); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4svNV 4268 +void +__indirect_glVertexAttrib4svNV(GLuint index, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 16; + emit_header(gc->pc, X_GLrop_VertexAttrib4svNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 8); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4ubvNV 4277 +void +__indirect_glVertexAttrib4ubNV(GLuint index, GLubyte x, GLubyte y, GLubyte z, + GLubyte w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib4ubvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&x), 1); + (void) memcpy((void *) (gc->pc + 9), (void *) (&y), 1); + (void) memcpy((void *) (gc->pc + 10), (void *) (&z), 1); + (void) memcpy((void *) (gc->pc + 11), (void *) (&w), 1); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttrib4ubvNV 4277 +void +__indirect_glVertexAttrib4ubvNV(GLuint index, const GLubyte *v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_VertexAttrib4ubvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (v), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_VertexAttribs1dvNV 4210 +void +__indirect_glVertexAttribs1dvNV(GLuint index, GLsizei n, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((n * 8)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_VertexAttribs1dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (v), (n * 8)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_VertexAttribs1fvNV 4206 +void +__indirect_glVertexAttribs1fvNV(GLuint index, GLsizei n, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((n * 4)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_VertexAttribs1fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (v), (n * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_VertexAttribs1svNV 4202 +void +__indirect_glVertexAttribs1svNV(GLuint index, GLsizei n, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((n * 2)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_VertexAttribs1svNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (v), (n * 2)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_VertexAttribs2dvNV 4211 +void +__indirect_glVertexAttribs2dvNV(GLuint index, GLsizei n, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((n * 16)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_VertexAttribs2dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (v), (n * 16)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_VertexAttribs2fvNV 4207 +void +__indirect_glVertexAttribs2fvNV(GLuint index, GLsizei n, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((n * 8)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_VertexAttribs2fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (v), (n * 8)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_VertexAttribs2svNV 4203 +void +__indirect_glVertexAttribs2svNV(GLuint index, GLsizei n, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((n * 4)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_VertexAttribs2svNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (v), (n * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_VertexAttribs3dvNV 4212 +void +__indirect_glVertexAttribs3dvNV(GLuint index, GLsizei n, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((n * 24)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_VertexAttribs3dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (v), (n * 24)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_VertexAttribs3fvNV 4208 +void +__indirect_glVertexAttribs3fvNV(GLuint index, GLsizei n, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((n * 12)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_VertexAttribs3fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (v), (n * 12)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_VertexAttribs3svNV 4204 +void +__indirect_glVertexAttribs3svNV(GLuint index, GLsizei n, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((n * 6)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_VertexAttribs3svNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (v), (n * 6)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_VertexAttribs4dvNV 4213 +void +__indirect_glVertexAttribs4dvNV(GLuint index, GLsizei n, const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((n * 32)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_VertexAttribs4dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (v), (n * 32)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_VertexAttribs4fvNV 4209 +void +__indirect_glVertexAttribs4fvNV(GLuint index, GLsizei n, const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((n * 16)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_VertexAttribs4fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (v), (n * 16)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_VertexAttribs4svNV 4205 +void +__indirect_glVertexAttribs4svNV(GLuint index, GLsizei n, const GLshort * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((n * 8)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_VertexAttribs4svNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (v), (n * 8)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_VertexAttribs4ubvNV 4214 +void +__indirect_glVertexAttribs4ubvNV(GLuint index, GLsizei n, const GLubyte *v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12 + __GLX_PAD((n * 4)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_VertexAttribs4ubvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&index), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (v), (n * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_PointParameteriNV 4221 +void +__indirect_glPointParameteriNV(GLenum pname, GLint param) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_PointParameteriNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (¶m), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_PointParameterivNV 4222 +void +__indirect_glPointParameterivNV(GLenum pname, const GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint compsize = __glPointParameterivNV_size(pname); + const GLuint cmdlen = 8 + __GLX_PAD((compsize * 4)); + emit_header(gc->pc, X_GLrop_PointParameterivNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&pname), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (params), (compsize * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_ActiveStencilFaceEXT 4220 +void +__indirect_glActiveStencilFaceEXT(GLenum face) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_ActiveStencilFaceEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&face), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLvop_GetProgramNamedParameterdvNV 1311 +void +__indirect_glGetProgramNamedParameterdvNV(GLuint id, GLsizei len, + const GLubyte *name, + GLdouble * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8 + __GLX_PAD(len); + if (len < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((len >= 0) && (dpy != NULL), 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetProgramNamedParameterdvNV, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&id), 4); + (void) memcpy((void *) (pc + 4), (void *) (&len), 4); + (void) memcpy((void *) (pc + 8), (void *) (name), len); + (void) __glXReadReply(dpy, 8, params, GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLvop_GetProgramNamedParameterfvNV 1310 +void +__indirect_glGetProgramNamedParameterfvNV(GLuint id, GLsizei len, + const GLubyte *name, + GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8 + __GLX_PAD(len); + if (len < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((len >= 0) && (dpy != NULL), 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetProgramNamedParameterfvNV, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&id), 4); + (void) memcpy((void *) (pc + 4), (void *) (&len), 4); + (void) memcpy((void *) (pc + 8), (void *) (name), len); + (void) __glXReadReply(dpy, 4, params, GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLrop_ProgramNamedParameter4dvNV 4219 +void +__indirect_glProgramNamedParameter4dNV(GLuint id, GLsizei len, + const GLubyte *name, GLdouble x, + GLdouble y, GLdouble z, GLdouble w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 44 + __GLX_PAD(len); + if (len < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(len >= 0, 1)) { + emit_header(gc->pc, X_GLrop_ProgramNamedParameter4dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&x), 8); + (void) memcpy((void *) (gc->pc + 12), (void *) (&y), 8); + (void) memcpy((void *) (gc->pc + 20), (void *) (&z), 8); + (void) memcpy((void *) (gc->pc + 28), (void *) (&w), 8); + (void) memcpy((void *) (gc->pc + 36), (void *) (&id), 4); + (void) memcpy((void *) (gc->pc + 40), (void *) (&len), 4); + (void) memcpy((void *) (gc->pc + 44), (void *) (name), len); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_ProgramNamedParameter4dvNV 4219 +void +__indirect_glProgramNamedParameter4dvNV(GLuint id, GLsizei len, + const GLubyte *name, + const GLdouble * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 44 + __GLX_PAD(len); + if (len < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(len >= 0, 1)) { + emit_header(gc->pc, X_GLrop_ProgramNamedParameter4dvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (v), 32); + (void) memcpy((void *) (gc->pc + 36), (void *) (&id), 4); + (void) memcpy((void *) (gc->pc + 40), (void *) (&len), 4); + (void) memcpy((void *) (gc->pc + 44), (void *) (name), len); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_ProgramNamedParameter4fvNV 4218 +void +__indirect_glProgramNamedParameter4fNV(GLuint id, GLsizei len, + const GLubyte *name, GLfloat x, + GLfloat y, GLfloat z, GLfloat w) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28 + __GLX_PAD(len); + if (len < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(len >= 0, 1)) { + emit_header(gc->pc, X_GLrop_ProgramNamedParameter4fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&id), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&len), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&x), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&y), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&z), 4); + (void) memcpy((void *) (gc->pc + 24), (void *) (&w), 4); + (void) memcpy((void *) (gc->pc + 28), (void *) (name), len); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_ProgramNamedParameter4fvNV 4218 +void +__indirect_glProgramNamedParameter4fvNV(GLuint id, GLsizei len, + const GLubyte *name, + const GLfloat * v) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28 + __GLX_PAD(len); + if (len < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(len >= 0, 1)) { + emit_header(gc->pc, X_GLrop_ProgramNamedParameter4fvNV, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&id), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&len), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (v), 16); + (void) memcpy((void *) (gc->pc + 28), (void *) (name), len); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_BlendEquationSeparateEXT 4228 +void +__indirect_glBlendEquationSeparateEXT(GLenum modeRGB, GLenum modeA) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_BlendEquationSeparateEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&modeRGB), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&modeA), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_BindFramebufferEXT 4319 +void +__indirect_glBindFramebufferEXT(GLenum target, GLuint framebuffer) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_BindFramebufferEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&framebuffer), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_BindRenderbufferEXT 4316 +void +__indirect_glBindRenderbufferEXT(GLenum target, GLuint renderbuffer) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 12; + emit_header(gc->pc, X_GLrop_BindRenderbufferEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&renderbuffer), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLvop_CheckFramebufferStatusEXT 1427 +GLenum +__indirect_glCheckFramebufferStatusEXT(GLenum target) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + GLenum retval = (GLenum) 0; + const GLuint cmdlen = 4; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_CheckFramebufferStatusEXT, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + retval = (GLenum) __glXReadReply(dpy, 0, NULL, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return retval; +} + +#define X_GLrop_DeleteFramebuffersEXT 4320 +void +__indirect_glDeleteFramebuffersEXT(GLsizei n, const GLuint * framebuffers) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8 + __GLX_PAD((n * 4)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_DeleteFramebuffersEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (framebuffers), + (n * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_DeleteRenderbuffersEXT 4317 +void +__indirect_glDeleteRenderbuffersEXT(GLsizei n, const GLuint * renderbuffers) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8 + __GLX_PAD((n * 4)); + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect(n >= 0, 1)) { + emit_header(gc->pc, X_GLrop_DeleteRenderbuffersEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&n), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (renderbuffers), + (n * 4)); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + +#define X_GLrop_FramebufferRenderbufferEXT 4324 +void +__indirect_glFramebufferRenderbufferEXT(GLenum target, GLenum attachment, + GLenum renderbuffertarget, + GLuint renderbuffer) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_FramebufferRenderbufferEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&attachment), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&renderbuffertarget), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&renderbuffer), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_FramebufferTexture1DEXT 4321 +void +__indirect_glFramebufferTexture1DEXT(GLenum target, GLenum attachment, + GLenum textarget, GLuint texture, + GLint level) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_FramebufferTexture1DEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&attachment), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&textarget), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&texture), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&level), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_FramebufferTexture2DEXT 4322 +void +__indirect_glFramebufferTexture2DEXT(GLenum target, GLenum attachment, + GLenum textarget, GLuint texture, + GLint level) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_FramebufferTexture2DEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&attachment), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&textarget), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&texture), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&level), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_FramebufferTexture3DEXT 4323 +void +__indirect_glFramebufferTexture3DEXT(GLenum target, GLenum attachment, + GLenum textarget, GLuint texture, + GLint level, GLint zoffset) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 28; + emit_header(gc->pc, X_GLrop_FramebufferTexture3DEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&attachment), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&textarget), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&texture), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&level), 4); + (void) memcpy((void *) (gc->pc + 24), (void *) (&zoffset), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLvop_GenFramebuffersEXT 1426 +void +__indirect_glGenFramebuffersEXT(GLsizei n, GLuint * framebuffers) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 4; + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GenFramebuffersEXT, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) __glXReadReply(dpy, 4, framebuffers, GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLvop_GenRenderbuffersEXT 1423 +void +__indirect_glGenRenderbuffersEXT(GLsizei n, GLuint * renderbuffers) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 4; + if (n < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GenRenderbuffersEXT, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) __glXReadReply(dpy, 4, renderbuffers, GL_TRUE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLrop_GenerateMipmapEXT 4325 +void +__indirect_glGenerateMipmapEXT(GLenum target) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 8; + emit_header(gc->pc, X_GLrop_GenerateMipmapEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLvop_GetFramebufferAttachmentParameterivEXT 1428 +void +__indirect_glGetFramebufferAttachmentParameterivEXT(GLenum target, + GLenum attachment, + GLenum pname, + GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 12; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetFramebufferAttachmentParameterivEXT, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&attachment), 4); + (void) memcpy((void *) (pc + 8), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLvop_GetRenderbufferParameterivEXT 1424 +void +__indirect_glGetRenderbufferParameterivEXT(GLenum target, GLenum pname, + GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetRenderbufferParameterivEXT, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&pname), 4); + (void) __glXReadReply(dpy, 4, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +#define X_GLvop_IsFramebufferEXT 1425 +GLboolean +__indirect_glIsFramebufferEXT(GLuint framebuffer) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + GLboolean retval = (GLboolean) 0; + const GLuint cmdlen = 4; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_IsFramebufferEXT, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&framebuffer), 4); + retval = (GLboolean) __glXReadReply(dpy, 0, NULL, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return retval; +} + +#define X_GLvop_IsRenderbufferEXT 1422 +GLboolean +__indirect_glIsRenderbufferEXT(GLuint renderbuffer) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + GLboolean retval = (GLboolean) 0; + const GLuint cmdlen = 4; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_IsRenderbufferEXT, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&renderbuffer), 4); + retval = (GLboolean) __glXReadReply(dpy, 0, NULL, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return retval; +} + +#define X_GLrop_RenderbufferStorageEXT 4318 +void +__indirect_glRenderbufferStorageEXT(GLenum target, GLenum internalformat, + GLsizei width, GLsizei height) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 20; + emit_header(gc->pc, X_GLrop_RenderbufferStorageEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&internalformat), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&width), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&height), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_BlitFramebufferEXT 4330 +void +__indirect_glBlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, + GLint srcY1, GLint dstX0, GLint dstY0, + GLint dstX1, GLint dstY1, GLbitfield mask, + GLenum filter) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 44; + emit_header(gc->pc, X_GLrop_BlitFramebufferEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&srcX0), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&srcY0), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&srcX1), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&srcY1), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&dstX0), 4); + (void) memcpy((void *) (gc->pc + 24), (void *) (&dstY0), 4); + (void) memcpy((void *) (gc->pc + 28), (void *) (&dstX1), 4); + (void) memcpy((void *) (gc->pc + 32), (void *) (&dstY1), 4); + (void) memcpy((void *) (gc->pc + 36), (void *) (&mask), 4); + (void) memcpy((void *) (gc->pc + 40), (void *) (&filter), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + +#define X_GLrop_FramebufferTextureLayerEXT 237 +void +__indirect_glFramebufferTextureLayerEXT(GLenum target, GLenum attachment, + GLuint texture, GLint level, + GLint layer) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + const GLuint cmdlen = 24; + emit_header(gc->pc, X_GLrop_FramebufferTextureLayerEXT, cmdlen); + (void) memcpy((void *) (gc->pc + 4), (void *) (&target), 4); + (void) memcpy((void *) (gc->pc + 8), (void *) (&attachment), 4); + (void) memcpy((void *) (gc->pc + 12), (void *) (&texture), 4); + (void) memcpy((void *) (gc->pc + 16), (void *) (&level), 4); + (void) memcpy((void *) (gc->pc + 20), (void *) (&layer), 4); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + + +# undef FASTCALL +# undef NOINLINE diff --git a/src/glx/indirect.h b/src/glx/indirect.h new file mode 100644 index 0000000..f322207 --- /dev/null +++ b/src/glx/indirect.h @@ -0,0 +1,722 @@ +/* DO NOT EDIT - This file generated automatically by glX_proto_send.py (from Mesa) script */ + +/* + * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. + * (C) Copyright IBM Corporation 2004 + * 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 + * PRECISION INSIGHT, IBM, + * 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. + */ + +#if !defined( _INDIRECT_H_ ) +# define _INDIRECT_H_ + +/** + * \file + * Prototypes for indirect rendering functions. + * + * \author Kevin E. Martin + * \author Ian Romanick + */ + +# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) && defined(__ELF__) +# define HIDDEN __attribute__((visibility("hidden"))) +# else +# define HIDDEN +# endif +# if defined(__i386__) && defined(__GNUC__) && !defined(__CYGWIN__) && !defined(__MINGW32__) +# define FASTCALL __attribute__((fastcall)) +# else +# define FASTCALL +# endif +# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define NOINLINE __attribute__((noinline)) +# else +# define NOINLINE +# endif + +#include "glxclient.h" + +extern HIDDEN NOINLINE CARD32 __glXReadReply( Display *dpy, size_t size, + void * dest, GLboolean reply_is_always_array ); + +extern HIDDEN NOINLINE void __glXReadPixelReply( Display *dpy, + struct glx_context * gc, unsigned max_dim, GLint width, GLint height, + GLint depth, GLenum format, GLenum type, void * dest, + GLboolean dimensions_in_reply ); + +extern HIDDEN NOINLINE FASTCALL GLubyte * __glXSetupSingleRequest( + struct glx_context * gc, GLint sop, GLint cmdlen ); + +extern HIDDEN NOINLINE FASTCALL GLubyte * __glXSetupVendorRequest( + struct glx_context * gc, GLint code, GLint vop, GLint cmdlen ); + +extern HIDDEN void __indirect_glNewList(GLuint list, GLenum mode); +extern HIDDEN void __indirect_glEndList(void); +extern HIDDEN void __indirect_glCallList(GLuint list); +extern HIDDEN void __indirect_glCallLists(GLsizei n, GLenum type, const GLvoid * lists); +extern HIDDEN void __indirect_glDeleteLists(GLuint list, GLsizei range); +extern HIDDEN GLuint __indirect_glGenLists(GLsizei range); +extern HIDDEN void __indirect_glListBase(GLuint base); +extern HIDDEN void __indirect_glBegin(GLenum mode); +extern HIDDEN void __indirect_glBitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte * bitmap); +extern HIDDEN void __indirect_glColor3b(GLbyte red, GLbyte green, GLbyte blue); +extern HIDDEN void __indirect_glColor3bv(const GLbyte * v); +extern HIDDEN void __indirect_glColor3d(GLdouble red, GLdouble green, GLdouble blue); +extern HIDDEN void __indirect_glColor3dv(const GLdouble * v); +extern HIDDEN void __indirect_glColor3f(GLfloat red, GLfloat green, GLfloat blue); +extern HIDDEN void __indirect_glColor3fv(const GLfloat * v); +extern HIDDEN void __indirect_glColor3i(GLint red, GLint green, GLint blue); +extern HIDDEN void __indirect_glColor3iv(const GLint * v); +extern HIDDEN void __indirect_glColor3s(GLshort red, GLshort green, GLshort blue); +extern HIDDEN void __indirect_glColor3sv(const GLshort * v); +extern HIDDEN void __indirect_glColor3ub(GLubyte red, GLubyte green, GLubyte blue); +extern HIDDEN void __indirect_glColor3ubv(const GLubyte * v); +extern HIDDEN void __indirect_glColor3ui(GLuint red, GLuint green, GLuint blue); +extern HIDDEN void __indirect_glColor3uiv(const GLuint * v); +extern HIDDEN void __indirect_glColor3us(GLushort red, GLushort green, GLushort blue); +extern HIDDEN void __indirect_glColor3usv(const GLushort * v); +extern HIDDEN void __indirect_glColor4b(GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha); +extern HIDDEN void __indirect_glColor4bv(const GLbyte * v); +extern HIDDEN void __indirect_glColor4d(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha); +extern HIDDEN void __indirect_glColor4dv(const GLdouble * v); +extern HIDDEN void __indirect_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +extern HIDDEN void __indirect_glColor4fv(const GLfloat * v); +extern HIDDEN void __indirect_glColor4i(GLint red, GLint green, GLint blue, GLint alpha); +extern HIDDEN void __indirect_glColor4iv(const GLint * v); +extern HIDDEN void __indirect_glColor4s(GLshort red, GLshort green, GLshort blue, GLshort alpha); +extern HIDDEN void __indirect_glColor4sv(const GLshort * v); +extern HIDDEN void __indirect_glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); +extern HIDDEN void __indirect_glColor4ubv(const GLubyte * v); +extern HIDDEN void __indirect_glColor4ui(GLuint red, GLuint green, GLuint blue, GLuint alpha); +extern HIDDEN void __indirect_glColor4uiv(const GLuint * v); +extern HIDDEN void __indirect_glColor4us(GLushort red, GLushort green, GLushort blue, GLushort alpha); +extern HIDDEN void __indirect_glColor4usv(const GLushort * v); +extern HIDDEN void __indirect_glEdgeFlag(GLboolean flag); +extern HIDDEN void __indirect_glEdgeFlagv(const GLboolean * flag); +extern HIDDEN void __indirect_glEnd(void); +extern HIDDEN void __indirect_glIndexd(GLdouble c); +extern HIDDEN void __indirect_glIndexdv(const GLdouble * c); +extern HIDDEN void __indirect_glIndexf(GLfloat c); +extern HIDDEN void __indirect_glIndexfv(const GLfloat * c); +extern HIDDEN void __indirect_glIndexi(GLint c); +extern HIDDEN void __indirect_glIndexiv(const GLint * c); +extern HIDDEN void __indirect_glIndexs(GLshort c); +extern HIDDEN void __indirect_glIndexsv(const GLshort * c); +extern HIDDEN void __indirect_glNormal3b(GLbyte nx, GLbyte ny, GLbyte nz); +extern HIDDEN void __indirect_glNormal3bv(const GLbyte * v); +extern HIDDEN void __indirect_glNormal3d(GLdouble nx, GLdouble ny, GLdouble nz); +extern HIDDEN void __indirect_glNormal3dv(const GLdouble * v); +extern HIDDEN void __indirect_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz); +extern HIDDEN void __indirect_glNormal3fv(const GLfloat * v); +extern HIDDEN void __indirect_glNormal3i(GLint nx, GLint ny, GLint nz); +extern HIDDEN void __indirect_glNormal3iv(const GLint * v); +extern HIDDEN void __indirect_glNormal3s(GLshort nx, GLshort ny, GLshort nz); +extern HIDDEN void __indirect_glNormal3sv(const GLshort * v); +extern HIDDEN void __indirect_glRasterPos2d(GLdouble x, GLdouble y); +extern HIDDEN void __indirect_glRasterPos2dv(const GLdouble * v); +extern HIDDEN void __indirect_glRasterPos2f(GLfloat x, GLfloat y); +extern HIDDEN void __indirect_glRasterPos2fv(const GLfloat * v); +extern HIDDEN void __indirect_glRasterPos2i(GLint x, GLint y); +extern HIDDEN void __indirect_glRasterPos2iv(const GLint * v); +extern HIDDEN void __indirect_glRasterPos2s(GLshort x, GLshort y); +extern HIDDEN void __indirect_glRasterPos2sv(const GLshort * v); +extern HIDDEN void __indirect_glRasterPos3d(GLdouble x, GLdouble y, GLdouble z); +extern HIDDEN void __indirect_glRasterPos3dv(const GLdouble * v); +extern HIDDEN void __indirect_glRasterPos3f(GLfloat x, GLfloat y, GLfloat z); +extern HIDDEN void __indirect_glRasterPos3fv(const GLfloat * v); +extern HIDDEN void __indirect_glRasterPos3i(GLint x, GLint y, GLint z); +extern HIDDEN void __indirect_glRasterPos3iv(const GLint * v); +extern HIDDEN void __indirect_glRasterPos3s(GLshort x, GLshort y, GLshort z); +extern HIDDEN void __indirect_glRasterPos3sv(const GLshort * v); +extern HIDDEN void __indirect_glRasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w); +extern HIDDEN void __indirect_glRasterPos4dv(const GLdouble * v); +extern HIDDEN void __indirect_glRasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w); +extern HIDDEN void __indirect_glRasterPos4fv(const GLfloat * v); +extern HIDDEN void __indirect_glRasterPos4i(GLint x, GLint y, GLint z, GLint w); +extern HIDDEN void __indirect_glRasterPos4iv(const GLint * v); +extern HIDDEN void __indirect_glRasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w); +extern HIDDEN void __indirect_glRasterPos4sv(const GLshort * v); +extern HIDDEN void __indirect_glRectd(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2); +extern HIDDEN void __indirect_glRectdv(const GLdouble * v1, const GLdouble * v2); +extern HIDDEN void __indirect_glRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2); +extern HIDDEN void __indirect_glRectfv(const GLfloat * v1, const GLfloat * v2); +extern HIDDEN void __indirect_glRecti(GLint x1, GLint y1, GLint x2, GLint y2); +extern HIDDEN void __indirect_glRectiv(const GLint * v1, const GLint * v2); +extern HIDDEN void __indirect_glRects(GLshort x1, GLshort y1, GLshort x2, GLshort y2); +extern HIDDEN void __indirect_glRectsv(const GLshort * v1, const GLshort * v2); +extern HIDDEN void __indirect_glTexCoord1d(GLdouble s); +extern HIDDEN void __indirect_glTexCoord1dv(const GLdouble * v); +extern HIDDEN void __indirect_glTexCoord1f(GLfloat s); +extern HIDDEN void __indirect_glTexCoord1fv(const GLfloat * v); +extern HIDDEN void __indirect_glTexCoord1i(GLint s); +extern HIDDEN void __indirect_glTexCoord1iv(const GLint * v); +extern HIDDEN void __indirect_glTexCoord1s(GLshort s); +extern HIDDEN void __indirect_glTexCoord1sv(const GLshort * v); +extern HIDDEN void __indirect_glTexCoord2d(GLdouble s, GLdouble t); +extern HIDDEN void __indirect_glTexCoord2dv(const GLdouble * v); +extern HIDDEN void __indirect_glTexCoord2f(GLfloat s, GLfloat t); +extern HIDDEN void __indirect_glTexCoord2fv(const GLfloat * v); +extern HIDDEN void __indirect_glTexCoord2i(GLint s, GLint t); +extern HIDDEN void __indirect_glTexCoord2iv(const GLint * v); +extern HIDDEN void __indirect_glTexCoord2s(GLshort s, GLshort t); +extern HIDDEN void __indirect_glTexCoord2sv(const GLshort * v); +extern HIDDEN void __indirect_glTexCoord3d(GLdouble s, GLdouble t, GLdouble r); +extern HIDDEN void __indirect_glTexCoord3dv(const GLdouble * v); +extern HIDDEN void __indirect_glTexCoord3f(GLfloat s, GLfloat t, GLfloat r); +extern HIDDEN void __indirect_glTexCoord3fv(const GLfloat * v); +extern HIDDEN void __indirect_glTexCoord3i(GLint s, GLint t, GLint r); +extern HIDDEN void __indirect_glTexCoord3iv(const GLint * v); +extern HIDDEN void __indirect_glTexCoord3s(GLshort s, GLshort t, GLshort r); +extern HIDDEN void __indirect_glTexCoord3sv(const GLshort * v); +extern HIDDEN void __indirect_glTexCoord4d(GLdouble s, GLdouble t, GLdouble r, GLdouble q); +extern HIDDEN void __indirect_glTexCoord4dv(const GLdouble * v); +extern HIDDEN void __indirect_glTexCoord4f(GLfloat s, GLfloat t, GLfloat r, GLfloat q); +extern HIDDEN void __indirect_glTexCoord4fv(const GLfloat * v); +extern HIDDEN void __indirect_glTexCoord4i(GLint s, GLint t, GLint r, GLint q); +extern HIDDEN void __indirect_glTexCoord4iv(const GLint * v); +extern HIDDEN void __indirect_glTexCoord4s(GLshort s, GLshort t, GLshort r, GLshort q); +extern HIDDEN void __indirect_glTexCoord4sv(const GLshort * v); +extern HIDDEN void __indirect_glVertex2d(GLdouble x, GLdouble y); +extern HIDDEN void __indirect_glVertex2dv(const GLdouble * v); +extern HIDDEN void __indirect_glVertex2f(GLfloat x, GLfloat y); +extern HIDDEN void __indirect_glVertex2fv(const GLfloat * v); +extern HIDDEN void __indirect_glVertex2i(GLint x, GLint y); +extern HIDDEN void __indirect_glVertex2iv(const GLint * v); +extern HIDDEN void __indirect_glVertex2s(GLshort x, GLshort y); +extern HIDDEN void __indirect_glVertex2sv(const GLshort * v); +extern HIDDEN void __indirect_glVertex3d(GLdouble x, GLdouble y, GLdouble z); +extern HIDDEN void __indirect_glVertex3dv(const GLdouble * v); +extern HIDDEN void __indirect_glVertex3f(GLfloat x, GLfloat y, GLfloat z); +extern HIDDEN void __indirect_glVertex3fv(const GLfloat * v); +extern HIDDEN void __indirect_glVertex3i(GLint x, GLint y, GLint z); +extern HIDDEN void __indirect_glVertex3iv(const GLint * v); +extern HIDDEN void __indirect_glVertex3s(GLshort x, GLshort y, GLshort z); +extern HIDDEN void __indirect_glVertex3sv(const GLshort * v); +extern HIDDEN void __indirect_glVertex4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w); +extern HIDDEN void __indirect_glVertex4dv(const GLdouble * v); +extern HIDDEN void __indirect_glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w); +extern HIDDEN void __indirect_glVertex4fv(const GLfloat * v); +extern HIDDEN void __indirect_glVertex4i(GLint x, GLint y, GLint z, GLint w); +extern HIDDEN void __indirect_glVertex4iv(const GLint * v); +extern HIDDEN void __indirect_glVertex4s(GLshort x, GLshort y, GLshort z, GLshort w); +extern HIDDEN void __indirect_glVertex4sv(const GLshort * v); +extern HIDDEN void __indirect_glClipPlane(GLenum plane, const GLdouble * equation); +extern HIDDEN void __indirect_glColorMaterial(GLenum face, GLenum mode); +extern HIDDEN void __indirect_glCullFace(GLenum mode); +extern HIDDEN void __indirect_glFogf(GLenum pname, GLfloat param); +extern HIDDEN void __indirect_glFogfv(GLenum pname, const GLfloat * params); +extern HIDDEN void __indirect_glFogi(GLenum pname, GLint param); +extern HIDDEN void __indirect_glFogiv(GLenum pname, const GLint * params); +extern HIDDEN void __indirect_glFrontFace(GLenum mode); +extern HIDDEN void __indirect_glHint(GLenum target, GLenum mode); +extern HIDDEN void __indirect_glLightf(GLenum light, GLenum pname, GLfloat param); +extern HIDDEN void __indirect_glLightfv(GLenum light, GLenum pname, const GLfloat * params); +extern HIDDEN void __indirect_glLighti(GLenum light, GLenum pname, GLint param); +extern HIDDEN void __indirect_glLightiv(GLenum light, GLenum pname, const GLint * params); +extern HIDDEN void __indirect_glLightModelf(GLenum pname, GLfloat param); +extern HIDDEN void __indirect_glLightModelfv(GLenum pname, const GLfloat * params); +extern HIDDEN void __indirect_glLightModeli(GLenum pname, GLint param); +extern HIDDEN void __indirect_glLightModeliv(GLenum pname, const GLint * params); +extern HIDDEN void __indirect_glLineStipple(GLint factor, GLushort pattern); +extern HIDDEN void __indirect_glLineWidth(GLfloat width); +extern HIDDEN void __indirect_glMaterialf(GLenum face, GLenum pname, GLfloat param); +extern HIDDEN void __indirect_glMaterialfv(GLenum face, GLenum pname, const GLfloat * params); +extern HIDDEN void __indirect_glMateriali(GLenum face, GLenum pname, GLint param); +extern HIDDEN void __indirect_glMaterialiv(GLenum face, GLenum pname, const GLint * params); +extern HIDDEN void __indirect_glPointSize(GLfloat size); +extern HIDDEN void __indirect_glPolygonMode(GLenum face, GLenum mode); +extern HIDDEN void __indirect_glPolygonStipple(const GLubyte * mask); +extern HIDDEN void __indirect_glScissor(GLint x, GLint y, GLsizei width, GLsizei height); +extern HIDDEN void __indirect_glShadeModel(GLenum mode); +extern HIDDEN void __indirect_glTexParameterf(GLenum target, GLenum pname, GLfloat param); +extern HIDDEN void __indirect_glTexParameterfv(GLenum target, GLenum pname, const GLfloat * params); +extern HIDDEN void __indirect_glTexParameteri(GLenum target, GLenum pname, GLint param); +extern HIDDEN void __indirect_glTexParameteriv(GLenum target, GLenum pname, const GLint * params); +extern HIDDEN void __indirect_glTexImage1D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid * pixels); +extern HIDDEN void __indirect_glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * pixels); +extern HIDDEN void __indirect_glTexEnvf(GLenum target, GLenum pname, GLfloat param); +extern HIDDEN void __indirect_glTexEnvfv(GLenum target, GLenum pname, const GLfloat * params); +extern HIDDEN void __indirect_glTexEnvi(GLenum target, GLenum pname, GLint param); +extern HIDDEN void __indirect_glTexEnviv(GLenum target, GLenum pname, const GLint * params); +extern HIDDEN void __indirect_glTexGend(GLenum coord, GLenum pname, GLdouble param); +extern HIDDEN void __indirect_glTexGendv(GLenum coord, GLenum pname, const GLdouble * params); +extern HIDDEN void __indirect_glTexGenf(GLenum coord, GLenum pname, GLfloat param); +extern HIDDEN void __indirect_glTexGenfv(GLenum coord, GLenum pname, const GLfloat * params); +extern HIDDEN void __indirect_glTexGeni(GLenum coord, GLenum pname, GLint param); +extern HIDDEN void __indirect_glTexGeniv(GLenum coord, GLenum pname, const GLint * params); +extern HIDDEN void __indirect_glFeedbackBuffer(GLsizei size, GLenum type, GLfloat * buffer); +extern HIDDEN void __indirect_glSelectBuffer(GLsizei size, GLuint * buffer); +extern HIDDEN GLint __indirect_glRenderMode(GLenum mode); +extern HIDDEN void __indirect_glInitNames(void); +extern HIDDEN void __indirect_glLoadName(GLuint name); +extern HIDDEN void __indirect_glPassThrough(GLfloat token); +extern HIDDEN void __indirect_glPopName(void); +extern HIDDEN void __indirect_glPushName(GLuint name); +extern HIDDEN void __indirect_glDrawBuffer(GLenum mode); +extern HIDDEN void __indirect_glClear(GLbitfield mask); +extern HIDDEN void __indirect_glClearAccum(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +extern HIDDEN void __indirect_glClearIndex(GLfloat c); +extern HIDDEN void __indirect_glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +extern HIDDEN void __indirect_glClearStencil(GLint s); +extern HIDDEN void __indirect_glClearDepth(GLclampd depth); +extern HIDDEN void __indirect_glStencilMask(GLuint mask); +extern HIDDEN void __indirect_glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +extern HIDDEN void __indirect_glDepthMask(GLboolean flag); +extern HIDDEN void __indirect_glIndexMask(GLuint mask); +extern HIDDEN void __indirect_glAccum(GLenum op, GLfloat value); +extern HIDDEN void __indirect_glDisable(GLenum cap); +extern HIDDEN void __indirect_glEnable(GLenum cap); +extern HIDDEN void __indirect_glFinish(void); +extern HIDDEN void __indirect_glFlush(void); +extern HIDDEN void __indirect_glPopAttrib(void); +extern HIDDEN void __indirect_glPushAttrib(GLbitfield mask); +extern HIDDEN void __indirect_glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble * points); +extern HIDDEN void __indirect_glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat * points); +extern HIDDEN void __indirect_glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble * points); +extern HIDDEN void __indirect_glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat * points); +extern HIDDEN void __indirect_glMapGrid1d(GLint un, GLdouble u1, GLdouble u2); +extern HIDDEN void __indirect_glMapGrid1f(GLint un, GLfloat u1, GLfloat u2); +extern HIDDEN void __indirect_glMapGrid2d(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2); +extern HIDDEN void __indirect_glMapGrid2f(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2); +extern HIDDEN void __indirect_glEvalCoord1d(GLdouble u); +extern HIDDEN void __indirect_glEvalCoord1dv(const GLdouble * u); +extern HIDDEN void __indirect_glEvalCoord1f(GLfloat u); +extern HIDDEN void __indirect_glEvalCoord1fv(const GLfloat * u); +extern HIDDEN void __indirect_glEvalCoord2d(GLdouble u, GLdouble v); +extern HIDDEN void __indirect_glEvalCoord2dv(const GLdouble * u); +extern HIDDEN void __indirect_glEvalCoord2f(GLfloat u, GLfloat v); +extern HIDDEN void __indirect_glEvalCoord2fv(const GLfloat * u); +extern HIDDEN void __indirect_glEvalMesh1(GLenum mode, GLint i1, GLint i2); +extern HIDDEN void __indirect_glEvalPoint1(GLint i); +extern HIDDEN void __indirect_glEvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2); +extern HIDDEN void __indirect_glEvalPoint2(GLint i, GLint j); +extern HIDDEN void __indirect_glAlphaFunc(GLenum func, GLclampf ref); +extern HIDDEN void __indirect_glBlendFunc(GLenum sfactor, GLenum dfactor); +extern HIDDEN void __indirect_glLogicOp(GLenum opcode); +extern HIDDEN void __indirect_glStencilFunc(GLenum func, GLint ref, GLuint mask); +extern HIDDEN void __indirect_glStencilOp(GLenum fail, GLenum zfail, GLenum zpass); +extern HIDDEN void __indirect_glDepthFunc(GLenum func); +extern HIDDEN void __indirect_glPixelZoom(GLfloat xfactor, GLfloat yfactor); +extern HIDDEN void __indirect_glPixelTransferf(GLenum pname, GLfloat param); +extern HIDDEN void __indirect_glPixelTransferi(GLenum pname, GLint param); +extern HIDDEN void __indirect_glPixelStoref(GLenum pname, GLfloat param); +extern HIDDEN void __indirect_glPixelStorei(GLenum pname, GLint param); +extern HIDDEN void __indirect_glPixelMapfv(GLenum map, GLsizei mapsize, const GLfloat * values); +extern HIDDEN void __indirect_glPixelMapuiv(GLenum map, GLsizei mapsize, const GLuint * values); +extern HIDDEN void __indirect_glPixelMapusv(GLenum map, GLsizei mapsize, const GLushort * values); +extern HIDDEN void __indirect_glReadBuffer(GLenum mode); +extern HIDDEN void __indirect_glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type); +extern HIDDEN void __indirect_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * pixels); +extern HIDDEN void __indirect_glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * pixels); +extern HIDDEN void __indirect_glGetBooleanv(GLenum pname, GLboolean * params); +extern HIDDEN void __indirect_glGetClipPlane(GLenum plane, GLdouble * equation); +extern HIDDEN void __indirect_glGetDoublev(GLenum pname, GLdouble * params); +extern HIDDEN GLenum __indirect_glGetError(void); +extern HIDDEN void __indirect_glGetFloatv(GLenum pname, GLfloat * params); +extern HIDDEN void __indirect_glGetIntegerv(GLenum pname, GLint * params); +extern HIDDEN void __indirect_glGetLightfv(GLenum light, GLenum pname, GLfloat * params); +extern HIDDEN void __indirect_glGetLightiv(GLenum light, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glGetMapdv(GLenum target, GLenum query, GLdouble * v); +extern HIDDEN void __indirect_glGetMapfv(GLenum target, GLenum query, GLfloat * v); +extern HIDDEN void __indirect_glGetMapiv(GLenum target, GLenum query, GLint * v); +extern HIDDEN void __indirect_glGetMaterialfv(GLenum face, GLenum pname, GLfloat * params); +extern HIDDEN void __indirect_glGetMaterialiv(GLenum face, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glGetPixelMapfv(GLenum map, GLfloat * values); +extern HIDDEN void __indirect_glGetPixelMapuiv(GLenum map, GLuint * values); +extern HIDDEN void __indirect_glGetPixelMapusv(GLenum map, GLushort * values); +extern HIDDEN void __indirect_glGetPolygonStipple(GLubyte * mask); +extern HIDDEN const GLubyte * __indirect_glGetString(GLenum name); +extern HIDDEN void __indirect_glGetTexEnvfv(GLenum target, GLenum pname, GLfloat * params); +extern HIDDEN void __indirect_glGetTexEnviv(GLenum target, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glGetTexGendv(GLenum coord, GLenum pname, GLdouble * params); +extern HIDDEN void __indirect_glGetTexGenfv(GLenum coord, GLenum pname, GLfloat * params); +extern HIDDEN void __indirect_glGetTexGeniv(GLenum coord, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid * pixels); +extern HIDDEN void __indirect_glGetTexParameterfv(GLenum target, GLenum pname, GLfloat * params); +extern HIDDEN void __indirect_glGetTexParameteriv(GLenum target, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glGetTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat * params); +extern HIDDEN void __indirect_glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint * params); +extern HIDDEN GLboolean __indirect_glIsEnabled(GLenum cap); +extern HIDDEN GLboolean __indirect_glIsList(GLuint list); +extern HIDDEN void __indirect_glDepthRange(GLclampd zNear, GLclampd zFar); +extern HIDDEN void __indirect_glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +extern HIDDEN void __indirect_glLoadIdentity(void); +extern HIDDEN void __indirect_glLoadMatrixf(const GLfloat * m); +extern HIDDEN void __indirect_glLoadMatrixd(const GLdouble * m); +extern HIDDEN void __indirect_glMatrixMode(GLenum mode); +extern HIDDEN void __indirect_glMultMatrixf(const GLfloat * m); +extern HIDDEN void __indirect_glMultMatrixd(const GLdouble * m); +extern HIDDEN void __indirect_glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +extern HIDDEN void __indirect_glPopMatrix(void); +extern HIDDEN void __indirect_glPushMatrix(void); +extern HIDDEN void __indirect_glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z); +extern HIDDEN void __indirect_glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +extern HIDDEN void __indirect_glScaled(GLdouble x, GLdouble y, GLdouble z); +extern HIDDEN void __indirect_glScalef(GLfloat x, GLfloat y, GLfloat z); +extern HIDDEN void __indirect_glTranslated(GLdouble x, GLdouble y, GLdouble z); +extern HIDDEN void __indirect_glTranslatef(GLfloat x, GLfloat y, GLfloat z); +extern HIDDEN void __indirect_glViewport(GLint x, GLint y, GLsizei width, GLsizei height); +extern HIDDEN void __indirect_glArrayElement(GLint i); +extern HIDDEN void __indirect_glBindTexture(GLenum target, GLuint texture); +extern HIDDEN void __indirect_glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer); +extern HIDDEN void __indirect_glDisableClientState(GLenum array); +extern HIDDEN void __indirect_glDrawArrays(GLenum mode, GLint first, GLsizei count); +extern HIDDEN void __indirect_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices); +extern HIDDEN void __indirect_glEdgeFlagPointer(GLsizei stride, const GLvoid * pointer); +extern HIDDEN void __indirect_glEnableClientState(GLenum array); +extern HIDDEN void __indirect_glIndexPointer(GLenum type, GLsizei stride, const GLvoid * pointer); +extern HIDDEN void __indirect_glIndexub(GLubyte c); +extern HIDDEN void __indirect_glIndexubv(const GLubyte * c); +extern HIDDEN void __indirect_glInterleavedArrays(GLenum format, GLsizei stride, const GLvoid * pointer); +extern HIDDEN void __indirect_glNormalPointer(GLenum type, GLsizei stride, const GLvoid * pointer); +extern HIDDEN void __indirect_glPolygonOffset(GLfloat factor, GLfloat units); +extern HIDDEN void __indirect_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer); +extern HIDDEN void __indirect_glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer); +extern HIDDEN GLboolean __indirect_glAreTexturesResident(GLsizei n, const GLuint * textures, GLboolean * residences); +GLAPI GLboolean GLAPIENTRY glAreTexturesResidentEXT(GLsizei n, const GLuint * textures, GLboolean * residences); +extern HIDDEN void __indirect_glCopyTexImage1D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +extern HIDDEN void __indirect_glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +extern HIDDEN void __indirect_glCopyTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +extern HIDDEN void __indirect_glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +extern HIDDEN void __indirect_glDeleteTextures(GLsizei n, const GLuint * textures); +GLAPI void GLAPIENTRY glDeleteTexturesEXT(GLsizei n, const GLuint * textures); +extern HIDDEN void __indirect_glGenTextures(GLsizei n, GLuint * textures); +GLAPI void GLAPIENTRY glGenTexturesEXT(GLsizei n, GLuint * textures); +extern HIDDEN void __indirect_glGetPointerv(GLenum pname, GLvoid ** params); +extern HIDDEN GLboolean __indirect_glIsTexture(GLuint texture); +GLAPI GLboolean GLAPIENTRY glIsTextureEXT(GLuint texture); +extern HIDDEN void __indirect_glPrioritizeTextures(GLsizei n, const GLuint * textures, const GLclampf * priorities); +extern HIDDEN void __indirect_glTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid * pixels); +extern HIDDEN void __indirect_glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * pixels); +extern HIDDEN void __indirect_glPopClientAttrib(void); +extern HIDDEN void __indirect_glPushClientAttrib(GLbitfield mask); +extern HIDDEN void __indirect_glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +extern HIDDEN void __indirect_glBlendEquation(GLenum mode); +extern HIDDEN void __indirect_glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid * indices); +extern HIDDEN void __indirect_glColorTable(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid * table); +extern HIDDEN void __indirect_glColorTableParameterfv(GLenum target, GLenum pname, const GLfloat * params); +extern HIDDEN void __indirect_glColorTableParameteriv(GLenum target, GLenum pname, const GLint * params); +extern HIDDEN void __indirect_glCopyColorTable(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +extern HIDDEN void __indirect_glGetColorTable(GLenum target, GLenum format, GLenum type, GLvoid * table); +GLAPI void GLAPIENTRY glGetColorTableEXT(GLenum target, GLenum format, GLenum type, GLvoid * table); +extern HIDDEN void __indirect_glGetColorTableParameterfv(GLenum target, GLenum pname, GLfloat * params); +GLAPI void GLAPIENTRY glGetColorTableParameterfvEXT(GLenum target, GLenum pname, GLfloat * params); +extern HIDDEN void __indirect_glGetColorTableParameteriv(GLenum target, GLenum pname, GLint * params); +GLAPI void GLAPIENTRY glGetColorTableParameterivEXT(GLenum target, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glColorSubTable(GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid * data); +extern HIDDEN void __indirect_glCopyColorSubTable(GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +extern HIDDEN void __indirect_glConvolutionFilter1D(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid * image); +extern HIDDEN void __indirect_glConvolutionFilter2D(GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * image); +extern HIDDEN void __indirect_glConvolutionParameterf(GLenum target, GLenum pname, GLfloat params); +extern HIDDEN void __indirect_glConvolutionParameterfv(GLenum target, GLenum pname, const GLfloat * params); +extern HIDDEN void __indirect_glConvolutionParameteri(GLenum target, GLenum pname, GLint params); +extern HIDDEN void __indirect_glConvolutionParameteriv(GLenum target, GLenum pname, const GLint * params); +extern HIDDEN void __indirect_glCopyConvolutionFilter1D(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +extern HIDDEN void __indirect_glCopyConvolutionFilter2D(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +extern HIDDEN void __indirect_glGetConvolutionFilter(GLenum target, GLenum format, GLenum type, GLvoid * image); +extern HIDDEN void gl_dispatch_stub_356(GLenum target, GLenum format, GLenum type, GLvoid * image); +extern HIDDEN void __indirect_glGetConvolutionParameterfv(GLenum target, GLenum pname, GLfloat * params); +extern HIDDEN void gl_dispatch_stub_357(GLenum target, GLenum pname, GLfloat * params); +extern HIDDEN void __indirect_glGetConvolutionParameteriv(GLenum target, GLenum pname, GLint * params); +extern HIDDEN void gl_dispatch_stub_358(GLenum target, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glGetSeparableFilter(GLenum target, GLenum format, GLenum type, GLvoid * row, GLvoid * column, GLvoid * span); +extern HIDDEN void gl_dispatch_stub_359(GLenum target, GLenum format, GLenum type, GLvoid * row, GLvoid * column, GLvoid * span); +#define gl_dispatch_stub_GetSeparableFilterEXT gl_dispatch_stub_359 +extern HIDDEN void __indirect_glSeparableFilter2D(GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * row, const GLvoid * column); +extern HIDDEN void __indirect_glGetHistogram(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid * values); +extern HIDDEN void gl_dispatch_stub_361(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid * values); +extern HIDDEN void __indirect_glGetHistogramParameterfv(GLenum target, GLenum pname, GLfloat * params); +extern HIDDEN void gl_dispatch_stub_362(GLenum target, GLenum pname, GLfloat * params); +extern HIDDEN void __indirect_glGetHistogramParameteriv(GLenum target, GLenum pname, GLint * params); +extern HIDDEN void gl_dispatch_stub_363(GLenum target, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glGetMinmax(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid * values); +extern HIDDEN void gl_dispatch_stub_364(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid * values); +extern HIDDEN void __indirect_glGetMinmaxParameterfv(GLenum target, GLenum pname, GLfloat * params); +extern HIDDEN void gl_dispatch_stub_365(GLenum target, GLenum pname, GLfloat * params); +extern HIDDEN void __indirect_glGetMinmaxParameteriv(GLenum target, GLenum pname, GLint * params); +extern HIDDEN void gl_dispatch_stub_366(GLenum target, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glHistogram(GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +extern HIDDEN void __indirect_glMinmax(GLenum target, GLenum internalformat, GLboolean sink); +extern HIDDEN void __indirect_glResetHistogram(GLenum target); +extern HIDDEN void __indirect_glResetMinmax(GLenum target); +extern HIDDEN void __indirect_glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid * pixels); +extern HIDDEN void __indirect_glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid * pixels); +extern HIDDEN void __indirect_glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +extern HIDDEN void __indirect_glActiveTextureARB(GLenum texture); +extern HIDDEN void __indirect_glClientActiveTextureARB(GLenum texture); +extern HIDDEN void __indirect_glMultiTexCoord1dARB(GLenum target, GLdouble s); +extern HIDDEN void __indirect_glMultiTexCoord1dvARB(GLenum target, const GLdouble * v); +extern HIDDEN void __indirect_glMultiTexCoord1fARB(GLenum target, GLfloat s); +extern HIDDEN void __indirect_glMultiTexCoord1fvARB(GLenum target, const GLfloat * v); +extern HIDDEN void __indirect_glMultiTexCoord1iARB(GLenum target, GLint s); +extern HIDDEN void __indirect_glMultiTexCoord1ivARB(GLenum target, const GLint * v); +extern HIDDEN void __indirect_glMultiTexCoord1sARB(GLenum target, GLshort s); +extern HIDDEN void __indirect_glMultiTexCoord1svARB(GLenum target, const GLshort * v); +extern HIDDEN void __indirect_glMultiTexCoord2dARB(GLenum target, GLdouble s, GLdouble t); +extern HIDDEN void __indirect_glMultiTexCoord2dvARB(GLenum target, const GLdouble * v); +extern HIDDEN void __indirect_glMultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t); +extern HIDDEN void __indirect_glMultiTexCoord2fvARB(GLenum target, const GLfloat * v); +extern HIDDEN void __indirect_glMultiTexCoord2iARB(GLenum target, GLint s, GLint t); +extern HIDDEN void __indirect_glMultiTexCoord2ivARB(GLenum target, const GLint * v); +extern HIDDEN void __indirect_glMultiTexCoord2sARB(GLenum target, GLshort s, GLshort t); +extern HIDDEN void __indirect_glMultiTexCoord2svARB(GLenum target, const GLshort * v); +extern HIDDEN void __indirect_glMultiTexCoord3dARB(GLenum target, GLdouble s, GLdouble t, GLdouble r); +extern HIDDEN void __indirect_glMultiTexCoord3dvARB(GLenum target, const GLdouble * v); +extern HIDDEN void __indirect_glMultiTexCoord3fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r); +extern HIDDEN void __indirect_glMultiTexCoord3fvARB(GLenum target, const GLfloat * v); +extern HIDDEN void __indirect_glMultiTexCoord3iARB(GLenum target, GLint s, GLint t, GLint r); +extern HIDDEN void __indirect_glMultiTexCoord3ivARB(GLenum target, const GLint * v); +extern HIDDEN void __indirect_glMultiTexCoord3sARB(GLenum target, GLshort s, GLshort t, GLshort r); +extern HIDDEN void __indirect_glMultiTexCoord3svARB(GLenum target, const GLshort * v); +extern HIDDEN void __indirect_glMultiTexCoord4dARB(GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +extern HIDDEN void __indirect_glMultiTexCoord4dvARB(GLenum target, const GLdouble * v); +extern HIDDEN void __indirect_glMultiTexCoord4fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +extern HIDDEN void __indirect_glMultiTexCoord4fvARB(GLenum target, const GLfloat * v); +extern HIDDEN void __indirect_glMultiTexCoord4iARB(GLenum target, GLint s, GLint t, GLint r, GLint q); +extern HIDDEN void __indirect_glMultiTexCoord4ivARB(GLenum target, const GLint * v); +extern HIDDEN void __indirect_glMultiTexCoord4sARB(GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +extern HIDDEN void __indirect_glMultiTexCoord4svARB(GLenum target, const GLshort * v); +extern HIDDEN void __indirect_glLoadTransposeMatrixdARB(const GLdouble * m); +extern HIDDEN void __indirect_glLoadTransposeMatrixfARB(const GLfloat * m); +extern HIDDEN void __indirect_glMultTransposeMatrixdARB(const GLdouble * m); +extern HIDDEN void __indirect_glMultTransposeMatrixfARB(const GLfloat * m); +extern HIDDEN void __indirect_glSampleCoverageARB(GLclampf value, GLboolean invert); +extern HIDDEN void __indirect_glCompressedTexImage1DARB(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid * data); +extern HIDDEN void __indirect_glCompressedTexImage2DARB(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data); +extern HIDDEN void __indirect_glCompressedTexImage3DARB(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid * data); +extern HIDDEN void __indirect_glCompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid * data); +extern HIDDEN void __indirect_glCompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid * data); +extern HIDDEN void __indirect_glCompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid * data); +extern HIDDEN void __indirect_glGetCompressedTexImageARB(GLenum target, GLint level, GLvoid * img); +extern HIDDEN void __indirect_glDisableVertexAttribArrayARB(GLuint index); +extern HIDDEN void __indirect_glEnableVertexAttribArrayARB(GLuint index); +extern HIDDEN void __indirect_glGetProgramEnvParameterdvARB(GLenum target, GLuint index, GLdouble * params); +extern HIDDEN void __indirect_glGetProgramEnvParameterfvARB(GLenum target, GLuint index, GLfloat * params); +extern HIDDEN void __indirect_glGetProgramLocalParameterdvARB(GLenum target, GLuint index, GLdouble * params); +extern HIDDEN void __indirect_glGetProgramLocalParameterfvARB(GLenum target, GLuint index, GLfloat * params); +extern HIDDEN void __indirect_glGetProgramStringARB(GLenum target, GLenum pname, GLvoid * string); +extern HIDDEN void __indirect_glGetProgramivARB(GLenum target, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glGetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble * params); +extern HIDDEN void __indirect_glGetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat * params); +extern HIDDEN void __indirect_glGetVertexAttribivARB(GLuint index, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glProgramEnvParameter4dARB(GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +extern HIDDEN void __indirect_glProgramEnvParameter4dvARB(GLenum target, GLuint index, const GLdouble * params); +extern HIDDEN void __indirect_glProgramEnvParameter4fARB(GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +extern HIDDEN void __indirect_glProgramEnvParameter4fvARB(GLenum target, GLuint index, const GLfloat * params); +extern HIDDEN void __indirect_glProgramLocalParameter4dARB(GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +extern HIDDEN void __indirect_glProgramLocalParameter4dvARB(GLenum target, GLuint index, const GLdouble * params); +extern HIDDEN void __indirect_glProgramLocalParameter4fARB(GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +extern HIDDEN void __indirect_glProgramLocalParameter4fvARB(GLenum target, GLuint index, const GLfloat * params); +extern HIDDEN void __indirect_glProgramStringARB(GLenum target, GLenum format, GLsizei len, const GLvoid * string); +extern HIDDEN void __indirect_glVertexAttrib1dARB(GLuint index, GLdouble x); +extern HIDDEN void __indirect_glVertexAttrib1dvARB(GLuint index, const GLdouble * v); +extern HIDDEN void __indirect_glVertexAttrib1fARB(GLuint index, GLfloat x); +extern HIDDEN void __indirect_glVertexAttrib1fvARB(GLuint index, const GLfloat * v); +extern HIDDEN void __indirect_glVertexAttrib1sARB(GLuint index, GLshort x); +extern HIDDEN void __indirect_glVertexAttrib1svARB(GLuint index, const GLshort * v); +extern HIDDEN void __indirect_glVertexAttrib2dARB(GLuint index, GLdouble x, GLdouble y); +extern HIDDEN void __indirect_glVertexAttrib2dvARB(GLuint index, const GLdouble * v); +extern HIDDEN void __indirect_glVertexAttrib2fARB(GLuint index, GLfloat x, GLfloat y); +extern HIDDEN void __indirect_glVertexAttrib2fvARB(GLuint index, const GLfloat * v); +extern HIDDEN void __indirect_glVertexAttrib2sARB(GLuint index, GLshort x, GLshort y); +extern HIDDEN void __indirect_glVertexAttrib2svARB(GLuint index, const GLshort * v); +extern HIDDEN void __indirect_glVertexAttrib3dARB(GLuint index, GLdouble x, GLdouble y, GLdouble z); +extern HIDDEN void __indirect_glVertexAttrib3dvARB(GLuint index, const GLdouble * v); +extern HIDDEN void __indirect_glVertexAttrib3fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z); +extern HIDDEN void __indirect_glVertexAttrib3fvARB(GLuint index, const GLfloat * v); +extern HIDDEN void __indirect_glVertexAttrib3sARB(GLuint index, GLshort x, GLshort y, GLshort z); +extern HIDDEN void __indirect_glVertexAttrib3svARB(GLuint index, const GLshort * v); +extern HIDDEN void __indirect_glVertexAttrib4NbvARB(GLuint index, const GLbyte * v); +extern HIDDEN void __indirect_glVertexAttrib4NivARB(GLuint index, const GLint * v); +extern HIDDEN void __indirect_glVertexAttrib4NsvARB(GLuint index, const GLshort * v); +extern HIDDEN void __indirect_glVertexAttrib4NubARB(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +extern HIDDEN void __indirect_glVertexAttrib4NubvARB(GLuint index, const GLubyte * v); +extern HIDDEN void __indirect_glVertexAttrib4NuivARB(GLuint index, const GLuint * v); +extern HIDDEN void __indirect_glVertexAttrib4NusvARB(GLuint index, const GLushort * v); +extern HIDDEN void __indirect_glVertexAttrib4bvARB(GLuint index, const GLbyte * v); +extern HIDDEN void __indirect_glVertexAttrib4dARB(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +extern HIDDEN void __indirect_glVertexAttrib4dvARB(GLuint index, const GLdouble * v); +extern HIDDEN void __indirect_glVertexAttrib4fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +extern HIDDEN void __indirect_glVertexAttrib4fvARB(GLuint index, const GLfloat * v); +extern HIDDEN void __indirect_glVertexAttrib4ivARB(GLuint index, const GLint * v); +extern HIDDEN void __indirect_glVertexAttrib4sARB(GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +extern HIDDEN void __indirect_glVertexAttrib4svARB(GLuint index, const GLshort * v); +extern HIDDEN void __indirect_glVertexAttrib4ubvARB(GLuint index, const GLubyte * v); +extern HIDDEN void __indirect_glVertexAttrib4uivARB(GLuint index, const GLuint * v); +extern HIDDEN void __indirect_glVertexAttrib4usvARB(GLuint index, const GLushort * v); +extern HIDDEN void __indirect_glVertexAttribPointerARB(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer); +extern HIDDEN void __indirect_glBeginQueryARB(GLenum target, GLuint id); +extern HIDDEN void __indirect_glDeleteQueriesARB(GLsizei n, const GLuint * ids); +extern HIDDEN void __indirect_glEndQueryARB(GLenum target); +extern HIDDEN void __indirect_glGenQueriesARB(GLsizei n, GLuint * ids); +extern HIDDEN void __indirect_glGetQueryObjectivARB(GLuint id, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glGetQueryObjectuivARB(GLuint id, GLenum pname, GLuint * params); +extern HIDDEN void __indirect_glGetQueryivARB(GLenum target, GLenum pname, GLint * params); +extern HIDDEN GLboolean __indirect_glIsQueryARB(GLuint id); +extern HIDDEN void __indirect_glDrawBuffersARB(GLsizei n, const GLenum * bufs); +extern HIDDEN void __indirect_glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +extern HIDDEN void __indirect_glSampleMaskSGIS(GLclampf value, GLboolean invert); +extern HIDDEN void __indirect_glSamplePatternSGIS(GLenum pattern); +extern HIDDEN void __indirect_glColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer); +extern HIDDEN void __indirect_glEdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean * pointer); +extern HIDDEN void __indirect_glIndexPointerEXT(GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer); +extern HIDDEN void __indirect_glNormalPointerEXT(GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer); +extern HIDDEN void __indirect_glTexCoordPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer); +extern HIDDEN void __indirect_glVertexPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer); +extern HIDDEN void __indirect_glPointParameterfEXT(GLenum pname, GLfloat param); +extern HIDDEN void __indirect_glPointParameterfvEXT(GLenum pname, const GLfloat * params); +extern HIDDEN void __indirect_glSecondaryColor3bEXT(GLbyte red, GLbyte green, GLbyte blue); +extern HIDDEN void __indirect_glSecondaryColor3bvEXT(const GLbyte * v); +extern HIDDEN void __indirect_glSecondaryColor3dEXT(GLdouble red, GLdouble green, GLdouble blue); +extern HIDDEN void __indirect_glSecondaryColor3dvEXT(const GLdouble * v); +extern HIDDEN void __indirect_glSecondaryColor3fEXT(GLfloat red, GLfloat green, GLfloat blue); +extern HIDDEN void __indirect_glSecondaryColor3fvEXT(const GLfloat * v); +extern HIDDEN void __indirect_glSecondaryColor3iEXT(GLint red, GLint green, GLint blue); +extern HIDDEN void __indirect_glSecondaryColor3ivEXT(const GLint * v); +extern HIDDEN void __indirect_glSecondaryColor3sEXT(GLshort red, GLshort green, GLshort blue); +extern HIDDEN void __indirect_glSecondaryColor3svEXT(const GLshort * v); +extern HIDDEN void __indirect_glSecondaryColor3ubEXT(GLubyte red, GLubyte green, GLubyte blue); +extern HIDDEN void __indirect_glSecondaryColor3ubvEXT(const GLubyte * v); +extern HIDDEN void __indirect_glSecondaryColor3uiEXT(GLuint red, GLuint green, GLuint blue); +extern HIDDEN void __indirect_glSecondaryColor3uivEXT(const GLuint * v); +extern HIDDEN void __indirect_glSecondaryColor3usEXT(GLushort red, GLushort green, GLushort blue); +extern HIDDEN void __indirect_glSecondaryColor3usvEXT(const GLushort * v); +extern HIDDEN void __indirect_glSecondaryColorPointerEXT(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer); +extern HIDDEN void __indirect_glMultiDrawArraysEXT(GLenum mode, const GLint * first, const GLsizei * count, GLsizei primcount); +extern HIDDEN void __indirect_glMultiDrawElementsEXT(GLenum mode, const GLsizei * count, GLenum type, const GLvoid ** indices, GLsizei primcount); +extern HIDDEN void __indirect_glFogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid * pointer); +extern HIDDEN void __indirect_glFogCoorddEXT(GLdouble coord); +extern HIDDEN void __indirect_glFogCoorddvEXT(const GLdouble * coord); +extern HIDDEN void __indirect_glFogCoordfEXT(GLfloat coord); +extern HIDDEN void __indirect_glFogCoordfvEXT(const GLfloat * coord); +extern HIDDEN void __indirect_glBlendFuncSeparateEXT(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +extern HIDDEN void __indirect_glWindowPos2dMESA(GLdouble x, GLdouble y); +extern HIDDEN void __indirect_glWindowPos2dvMESA(const GLdouble * v); +extern HIDDEN void __indirect_glWindowPos2fMESA(GLfloat x, GLfloat y); +extern HIDDEN void __indirect_glWindowPos2fvMESA(const GLfloat * v); +extern HIDDEN void __indirect_glWindowPos2iMESA(GLint x, GLint y); +extern HIDDEN void __indirect_glWindowPos2ivMESA(const GLint * v); +extern HIDDEN void __indirect_glWindowPos2sMESA(GLshort x, GLshort y); +extern HIDDEN void __indirect_glWindowPos2svMESA(const GLshort * v); +extern HIDDEN void __indirect_glWindowPos3dMESA(GLdouble x, GLdouble y, GLdouble z); +extern HIDDEN void __indirect_glWindowPos3dvMESA(const GLdouble * v); +extern HIDDEN void __indirect_glWindowPos3fMESA(GLfloat x, GLfloat y, GLfloat z); +extern HIDDEN void __indirect_glWindowPos3fvMESA(const GLfloat * v); +extern HIDDEN void __indirect_glWindowPos3iMESA(GLint x, GLint y, GLint z); +extern HIDDEN void __indirect_glWindowPos3ivMESA(const GLint * v); +extern HIDDEN void __indirect_glWindowPos3sMESA(GLshort x, GLshort y, GLshort z); +extern HIDDEN void __indirect_glWindowPos3svMESA(const GLshort * v); +extern HIDDEN GLboolean __indirect_glAreProgramsResidentNV(GLsizei n, const GLuint * ids, GLboolean * residences); +extern HIDDEN void __indirect_glBindProgramNV(GLenum target, GLuint program); +extern HIDDEN void __indirect_glDeleteProgramsNV(GLsizei n, const GLuint * programs); +extern HIDDEN void __indirect_glExecuteProgramNV(GLenum target, GLuint id, const GLfloat * params); +extern HIDDEN void __indirect_glGenProgramsNV(GLsizei n, GLuint * programs); +extern HIDDEN void __indirect_glGetProgramParameterdvNV(GLenum target, GLuint index, GLenum pname, GLdouble * params); +extern HIDDEN void __indirect_glGetProgramParameterfvNV(GLenum target, GLuint index, GLenum pname, GLfloat * params); +extern HIDDEN void __indirect_glGetProgramStringNV(GLuint id, GLenum pname, GLubyte * program); +extern HIDDEN void __indirect_glGetProgramivNV(GLuint id, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glGetTrackMatrixivNV(GLenum target, GLuint address, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glGetVertexAttribPointervNV(GLuint index, GLenum pname, GLvoid ** pointer); +extern HIDDEN void __indirect_glGetVertexAttribdvNV(GLuint index, GLenum pname, GLdouble * params); +extern HIDDEN void __indirect_glGetVertexAttribfvNV(GLuint index, GLenum pname, GLfloat * params); +extern HIDDEN void __indirect_glGetVertexAttribivNV(GLuint index, GLenum pname, GLint * params); +extern HIDDEN GLboolean __indirect_glIsProgramNV(GLuint program); +extern HIDDEN void __indirect_glLoadProgramNV(GLenum target, GLuint id, GLsizei len, const GLubyte * program); +extern HIDDEN void __indirect_glProgramParameters4dvNV(GLenum target, GLuint index, GLsizei num, const GLdouble * params); +extern HIDDEN void __indirect_glProgramParameters4fvNV(GLenum target, GLuint index, GLsizei num, const GLfloat * params); +extern HIDDEN void __indirect_glRequestResidentProgramsNV(GLsizei n, const GLuint * ids); +extern HIDDEN void __indirect_glTrackMatrixNV(GLenum target, GLuint address, GLenum matrix, GLenum transform); +extern HIDDEN void __indirect_glVertexAttrib1dNV(GLuint index, GLdouble x); +extern HIDDEN void __indirect_glVertexAttrib1dvNV(GLuint index, const GLdouble * v); +extern HIDDEN void __indirect_glVertexAttrib1fNV(GLuint index, GLfloat x); +extern HIDDEN void __indirect_glVertexAttrib1fvNV(GLuint index, const GLfloat * v); +extern HIDDEN void __indirect_glVertexAttrib1sNV(GLuint index, GLshort x); +extern HIDDEN void __indirect_glVertexAttrib1svNV(GLuint index, const GLshort * v); +extern HIDDEN void __indirect_glVertexAttrib2dNV(GLuint index, GLdouble x, GLdouble y); +extern HIDDEN void __indirect_glVertexAttrib2dvNV(GLuint index, const GLdouble * v); +extern HIDDEN void __indirect_glVertexAttrib2fNV(GLuint index, GLfloat x, GLfloat y); +extern HIDDEN void __indirect_glVertexAttrib2fvNV(GLuint index, const GLfloat * v); +extern HIDDEN void __indirect_glVertexAttrib2sNV(GLuint index, GLshort x, GLshort y); +extern HIDDEN void __indirect_glVertexAttrib2svNV(GLuint index, const GLshort * v); +extern HIDDEN void __indirect_glVertexAttrib3dNV(GLuint index, GLdouble x, GLdouble y, GLdouble z); +extern HIDDEN void __indirect_glVertexAttrib3dvNV(GLuint index, const GLdouble * v); +extern HIDDEN void __indirect_glVertexAttrib3fNV(GLuint index, GLfloat x, GLfloat y, GLfloat z); +extern HIDDEN void __indirect_glVertexAttrib3fvNV(GLuint index, const GLfloat * v); +extern HIDDEN void __indirect_glVertexAttrib3sNV(GLuint index, GLshort x, GLshort y, GLshort z); +extern HIDDEN void __indirect_glVertexAttrib3svNV(GLuint index, const GLshort * v); +extern HIDDEN void __indirect_glVertexAttrib4dNV(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +extern HIDDEN void __indirect_glVertexAttrib4dvNV(GLuint index, const GLdouble * v); +extern HIDDEN void __indirect_glVertexAttrib4fNV(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +extern HIDDEN void __indirect_glVertexAttrib4fvNV(GLuint index, const GLfloat * v); +extern HIDDEN void __indirect_glVertexAttrib4sNV(GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +extern HIDDEN void __indirect_glVertexAttrib4svNV(GLuint index, const GLshort * v); +extern HIDDEN void __indirect_glVertexAttrib4ubNV(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +extern HIDDEN void __indirect_glVertexAttrib4ubvNV(GLuint index, const GLubyte * v); +extern HIDDEN void __indirect_glVertexAttribPointerNV(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer); +extern HIDDEN void __indirect_glVertexAttribs1dvNV(GLuint index, GLsizei n, const GLdouble * v); +extern HIDDEN void __indirect_glVertexAttribs1fvNV(GLuint index, GLsizei n, const GLfloat * v); +extern HIDDEN void __indirect_glVertexAttribs1svNV(GLuint index, GLsizei n, const GLshort * v); +extern HIDDEN void __indirect_glVertexAttribs2dvNV(GLuint index, GLsizei n, const GLdouble * v); +extern HIDDEN void __indirect_glVertexAttribs2fvNV(GLuint index, GLsizei n, const GLfloat * v); +extern HIDDEN void __indirect_glVertexAttribs2svNV(GLuint index, GLsizei n, const GLshort * v); +extern HIDDEN void __indirect_glVertexAttribs3dvNV(GLuint index, GLsizei n, const GLdouble * v); +extern HIDDEN void __indirect_glVertexAttribs3fvNV(GLuint index, GLsizei n, const GLfloat * v); +extern HIDDEN void __indirect_glVertexAttribs3svNV(GLuint index, GLsizei n, const GLshort * v); +extern HIDDEN void __indirect_glVertexAttribs4dvNV(GLuint index, GLsizei n, const GLdouble * v); +extern HIDDEN void __indirect_glVertexAttribs4fvNV(GLuint index, GLsizei n, const GLfloat * v); +extern HIDDEN void __indirect_glVertexAttribs4svNV(GLuint index, GLsizei n, const GLshort * v); +extern HIDDEN void __indirect_glVertexAttribs4ubvNV(GLuint index, GLsizei n, const GLubyte * v); +extern HIDDEN void __indirect_glPointParameteriNV(GLenum pname, GLint param); +extern HIDDEN void __indirect_glPointParameterivNV(GLenum pname, const GLint * params); +extern HIDDEN void __indirect_glActiveStencilFaceEXT(GLenum face); +extern HIDDEN void __indirect_glGetProgramNamedParameterdvNV(GLuint id, GLsizei len, const GLubyte * name, GLdouble * params); +extern HIDDEN void __indirect_glGetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte * name, GLfloat * params); +extern HIDDEN void __indirect_glProgramNamedParameter4dNV(GLuint id, GLsizei len, const GLubyte * name, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +extern HIDDEN void __indirect_glProgramNamedParameter4dvNV(GLuint id, GLsizei len, const GLubyte * name, const GLdouble * v); +extern HIDDEN void __indirect_glProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte * name, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +extern HIDDEN void __indirect_glProgramNamedParameter4fvNV(GLuint id, GLsizei len, const GLubyte * name, const GLfloat * v); +extern HIDDEN void __indirect_glBlendEquationSeparateEXT(GLenum modeRGB, GLenum modeA); +extern HIDDEN void __indirect_glBindFramebufferEXT(GLenum target, GLuint framebuffer); +extern HIDDEN void __indirect_glBindRenderbufferEXT(GLenum target, GLuint renderbuffer); +extern HIDDEN GLenum __indirect_glCheckFramebufferStatusEXT(GLenum target); +extern HIDDEN void __indirect_glDeleteFramebuffersEXT(GLsizei n, const GLuint * framebuffers); +extern HIDDEN void __indirect_glDeleteRenderbuffersEXT(GLsizei n, const GLuint * renderbuffers); +extern HIDDEN void __indirect_glFramebufferRenderbufferEXT(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +extern HIDDEN void __indirect_glFramebufferTexture1DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +extern HIDDEN void __indirect_glFramebufferTexture2DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +extern HIDDEN void __indirect_glFramebufferTexture3DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +extern HIDDEN void __indirect_glGenFramebuffersEXT(GLsizei n, GLuint * framebuffers); +extern HIDDEN void __indirect_glGenRenderbuffersEXT(GLsizei n, GLuint * renderbuffers); +extern HIDDEN void __indirect_glGenerateMipmapEXT(GLenum target); +extern HIDDEN void __indirect_glGetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, GLenum pname, GLint * params); +extern HIDDEN void __indirect_glGetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint * params); +extern HIDDEN GLboolean __indirect_glIsFramebufferEXT(GLuint framebuffer); +extern HIDDEN GLboolean __indirect_glIsRenderbufferEXT(GLuint renderbuffer); +extern HIDDEN void __indirect_glRenderbufferStorageEXT(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +extern HIDDEN void __indirect_glBlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +extern HIDDEN void __indirect_glFramebufferTextureLayerEXT(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); + +# undef HIDDEN +# undef FASTCALL +# undef NOINLINE + +#endif /* !defined( _INDIRECT_H_ ) */ diff --git a/src/glx/indirect_glx.c b/src/glx/indirect_glx.c new file mode 100644 index 0000000..1870ede --- /dev/null +++ b/src/glx/indirect_glx.c @@ -0,0 +1,462 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Soft- + * ware"), to deal in the Software without restriction, including without + * limitation the rights to use, copy, modify, merge, publish, distribute, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, provided that the above copyright + * notice(s) and this permission notice appear in all copies of the Soft- + * ware and that both the above copyright notice(s) and this permission + * notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- + * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY + * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN + * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- + * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR- + * MANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder shall + * not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization of + * the copyright holder. + * + * Authors: + * Kristian Høgsberg (krh@bitplanet.net) + */ + +#include "glapi.h" +#include "glxclient.h" + +extern struct _glapi_table *__glXNewIndirectAPI(void); + +/* +** All indirect rendering contexts will share the same indirect dispatch table. +*/ +static struct _glapi_table *IndirectAPI = NULL; + +static void +indirect_destroy_context(struct glx_context *gc) +{ + if (!gc->imported && gc->xid) + glx_send_destroy_context(gc->psc->dpy, gc->xid); + + __glXFreeVertexArrayState(gc); + + if (gc->vendor) + XFree((char *) gc->vendor); + if (gc->renderer) + XFree((char *) gc->renderer); + if (gc->version) + XFree((char *) gc->version); + if (gc->extensions) + XFree((char *) gc->extensions); + __glFreeAttributeState(gc); + XFree((char *) gc->buf); + Xfree((char *) gc->client_state_private); + XFree((char *) gc); +} + +static Bool +SendMakeCurrentRequest(Display * dpy, CARD8 opcode, + GLXContextID gc_id, GLXContextTag gc_tag, + GLXDrawable draw, GLXDrawable read, + xGLXMakeCurrentReply * reply) +{ + Bool ret; + + LockDisplay(dpy); + + if (draw == read) { + xGLXMakeCurrentReq *req; + + GetReq(GLXMakeCurrent, req); + req->reqType = opcode; + req->glxCode = X_GLXMakeCurrent; + req->drawable = draw; + req->context = gc_id; + req->oldContextTag = gc_tag; + } + else { + struct glx_display *priv = __glXInitialize(dpy); + + /* If the server can support the GLX 1.3 version, we should + * perfer that. Not only that, some servers support GLX 1.3 but + * not the SGI extension. + */ + + if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { + xGLXMakeContextCurrentReq *req; + + GetReq(GLXMakeContextCurrent, req); + req->reqType = opcode; + req->glxCode = X_GLXMakeContextCurrent; + req->drawable = draw; + req->readdrawable = read; + req->context = gc_id; + req->oldContextTag = gc_tag; + } + else { + xGLXVendorPrivateWithReplyReq *vpreq; + xGLXMakeCurrentReadSGIReq *req; + + GetReqExtra(GLXVendorPrivateWithReply, + sz_xGLXMakeCurrentReadSGIReq - + sz_xGLXVendorPrivateWithReplyReq, vpreq); + req = (xGLXMakeCurrentReadSGIReq *) vpreq; + req->reqType = opcode; + req->glxCode = X_GLXVendorPrivateWithReply; + req->vendorCode = X_GLXvop_MakeCurrentReadSGI; + req->drawable = draw; + req->readable = read; + req->context = gc_id; + req->oldContextTag = gc_tag; + } + } + + ret = _XReply(dpy, (xReply *) reply, 0, False); + + UnlockDisplay(dpy); + SyncHandle(); + + return ret; +} + +static int +indirect_bind_context(struct glx_context *gc, struct glx_context *old, + GLXDrawable draw, GLXDrawable read) +{ + xGLXMakeCurrentReply reply; + GLXContextTag tag; + __GLXattribute *state; + Display *dpy = gc->psc->dpy; + int opcode = __glXSetupForCommand(dpy); + + if (old != &dummyContext && !old->isDirect && old->psc->dpy == dpy) { + tag = old->currentContextTag; + old->currentContextTag = 0; + } else { + tag = 0; + } + + SendMakeCurrentRequest(dpy, opcode, gc->xid, tag, draw, read, &reply); + + if (!IndirectAPI) + IndirectAPI = __glXNewIndirectAPI(); + _glapi_set_dispatch(IndirectAPI); + + gc->currentContextTag = reply.contextTag; + state = gc->client_state_private; + if (state->array_state == NULL) { + glGetString(GL_EXTENSIONS); + glGetString(GL_VERSION); + __glXInitVertexArrayState(gc); + } + + return Success; +} + +static void +indirect_unbind_context(struct glx_context *gc, struct glx_context *new) +{ + Display *dpy = gc->psc->dpy; + int opcode = __glXSetupForCommand(dpy); + xGLXMakeCurrentReply reply; + + if (gc == new) + return; + + /* We are either switching to no context, away from a indirect + * context to a direct context or from one dpy to another and have + * to send a request to the dpy to unbind the previous context. + */ + if (!new || new->isDirect || new->psc->dpy != dpy) { + SendMakeCurrentRequest(dpy, opcode, None, + gc->currentContextTag, None, None, &reply); + gc->currentContextTag = 0; + } +} + +static void +indirect_wait_gl(struct glx_context *gc) +{ + xGLXWaitGLReq *req; + Display *dpy = gc->currentDpy; + + /* Flush any pending commands out */ + __glXFlushRenderBuffer(gc, gc->pc); + + /* Send the glXWaitGL request */ + LockDisplay(dpy); + GetReq(GLXWaitGL, req); + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXWaitGL; + req->contextTag = gc->currentContextTag; + UnlockDisplay(dpy); + SyncHandle(); +} + +static void +indirect_wait_x(struct glx_context *gc) +{ + xGLXWaitXReq *req; + Display *dpy = gc->currentDpy; + + /* Flush any pending commands out */ + __glXFlushRenderBuffer(gc, gc->pc); + + LockDisplay(dpy); + GetReq(GLXWaitX, req); + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXWaitX; + req->contextTag = gc->currentContextTag; + UnlockDisplay(dpy); + SyncHandle(); +} + +static void +indirect_use_x_font(struct glx_context *gc, + Font font, int first, int count, int listBase) +{ + xGLXUseXFontReq *req; + Display *dpy = gc->currentDpy; + + /* Flush any pending commands out */ + __glXFlushRenderBuffer(gc, gc->pc); + + /* Send the glXUseFont request */ + LockDisplay(dpy); + GetReq(GLXUseXFont, req); + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXUseXFont; + req->contextTag = gc->currentContextTag; + req->font = font; + req->first = first; + req->count = count; + req->listBase = listBase; + UnlockDisplay(dpy); + SyncHandle(); +} + +static void +indirect_bind_tex_image(Display * dpy, + GLXDrawable drawable, + int buffer, const int *attrib_list) +{ + xGLXVendorPrivateReq *req; + struct glx_context *gc = __glXGetCurrentContext(); + CARD32 *drawable_ptr; + INT32 *buffer_ptr; + CARD32 *num_attrib_ptr; + CARD32 *attrib_ptr; + CARD8 opcode; + unsigned int i; + + i = 0; + if (attrib_list) { + while (attrib_list[i * 2] != None) + i++; + } + + opcode = __glXSetupForCommand(dpy); + if (!opcode) + return; + + LockDisplay(dpy); + GetReqExtra(GLXVendorPrivate, 12 + 8 * i, req); + req->reqType = opcode; + req->glxCode = X_GLXVendorPrivate; + req->vendorCode = X_GLXvop_BindTexImageEXT; + req->contextTag = gc->currentContextTag; + + drawable_ptr = (CARD32 *) (req + 1); + buffer_ptr = (INT32 *) (drawable_ptr + 1); + num_attrib_ptr = (CARD32 *) (buffer_ptr + 1); + attrib_ptr = (CARD32 *) (num_attrib_ptr + 1); + + *drawable_ptr = drawable; + *buffer_ptr = buffer; + *num_attrib_ptr = (CARD32) i; + + i = 0; + if (attrib_list) { + while (attrib_list[i * 2] != None) { + *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 0]; + *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 1]; + i++; + } + } + + UnlockDisplay(dpy); + SyncHandle(); +} + +static void +indirect_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer) +{ + xGLXVendorPrivateReq *req; + struct glx_context *gc = __glXGetCurrentContext(); + CARD32 *drawable_ptr; + INT32 *buffer_ptr; + CARD8 opcode; + + opcode = __glXSetupForCommand(dpy); + if (!opcode) + return; + + LockDisplay(dpy); + GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32), req); + req->reqType = opcode; + req->glxCode = X_GLXVendorPrivate; + req->vendorCode = X_GLXvop_ReleaseTexImageEXT; + req->contextTag = gc->currentContextTag; + + drawable_ptr = (CARD32 *) (req + 1); + buffer_ptr = (INT32 *) (drawable_ptr + 1); + + *drawable_ptr = drawable; + *buffer_ptr = buffer; + + UnlockDisplay(dpy); + SyncHandle(); +} + +static const struct glx_context_vtable indirect_context_vtable = { + indirect_destroy_context, + indirect_bind_context, + indirect_unbind_context, + indirect_wait_gl, + indirect_wait_x, + indirect_use_x_font, + indirect_bind_tex_image, + indirect_release_tex_image, +}; + +/** + * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new + * function called \c __glXAllocateClientState that allocates the memory and + * does all the initialization (including the pixel pack / unpack). + */ +_X_HIDDEN struct glx_context * +indirect_create_context(struct glx_screen *psc, + struct glx_config *mode, + struct glx_context *shareList, int renderType) +{ + struct glx_context *gc; + int bufSize; + CARD8 opcode; + __GLXattribute *state; + + opcode = __glXSetupForCommand(psc->dpy); + if (!opcode) { + return NULL; + } + + /* Allocate our context record */ + gc = Xmalloc(sizeof *gc); + if (!gc) { + /* Out of memory */ + return NULL; + } + memset(gc, 0, sizeof *gc); + + glx_context_init(gc, psc, mode); + gc->isDirect = GL_FALSE; + gc->vtable = &indirect_context_vtable; + state = Xmalloc(sizeof(struct __GLXattributeRec)); + if (state == NULL) { + /* Out of memory */ + Xfree(gc); + return NULL; + } + gc->client_state_private = state; + memset(gc->client_state_private, 0, sizeof(struct __GLXattributeRec)); + state->NoDrawArraysProtocol = (getenv("LIBGL_NO_DRAWARRAYS") != NULL); + + /* + ** Create a temporary buffer to hold GLX rendering commands. The size + ** of the buffer is selected so that the maximum number of GLX rendering + ** commands can fit in a single X packet and still have room in the X + ** packet for the GLXRenderReq header. + */ + + bufSize = (XMaxRequestSize(psc->dpy) * 4) - sz_xGLXRenderReq; + gc->buf = (GLubyte *) Xmalloc(bufSize); + if (!gc->buf) { + Xfree(gc->client_state_private); + Xfree(gc); + return NULL; + } + gc->bufSize = bufSize; + + /* Fill in the new context */ + gc->renderMode = GL_RENDER; + + state->storePack.alignment = 4; + state->storeUnpack.alignment = 4; + + gc->attributes.stackPointer = &gc->attributes.stack[0]; + + /* + ** PERFORMANCE NOTE: A mode dependent fill image can speed things up. + ** Other code uses the fastImageUnpack bit, but it is never set + ** to GL_TRUE. + */ + gc->fastImageUnpack = GL_FALSE; + gc->fillImage = __glFillImage; + gc->pc = gc->buf; + gc->bufEnd = gc->buf + bufSize; + gc->isDirect = GL_FALSE; + if (__glXDebug) { + /* + ** Set limit register so that there will be one command per packet + */ + gc->limit = gc->buf; + } + else { + gc->limit = gc->buf + bufSize - __GLX_BUFFER_LIMIT_SIZE; + } + gc->majorOpcode = opcode; + + /* + ** Constrain the maximum drawing command size allowed to be + ** transfered using the X_GLXRender protocol request. First + ** constrain by a software limit, then constrain by the protocl + ** limit. + */ + if (bufSize > __GLX_RENDER_CMD_SIZE_LIMIT) { + bufSize = __GLX_RENDER_CMD_SIZE_LIMIT; + } + if (bufSize > __GLX_MAX_RENDER_CMD_SIZE) { + bufSize = __GLX_MAX_RENDER_CMD_SIZE; + } + gc->maxSmallRenderCommandSize = bufSize; + + + return gc; +} + +struct glx_screen_vtable indirect_screen_vtable = { + indirect_create_context +}; + +_X_HIDDEN struct glx_screen * +indirect_create_screen(int screen, struct glx_display * priv) +{ + struct glx_screen *psc; + + psc = Xmalloc(sizeof *psc); + if (psc == NULL) + return NULL; + + memset(psc, 0, sizeof *psc); + glx_screen_init(psc, screen, priv); + psc->vtable = &indirect_screen_vtable; + + return psc; +} diff --git a/src/glx/indirect_init.c b/src/glx/indirect_init.c new file mode 100644 index 0000000..9f1ee59 --- /dev/null +++ b/src/glx/indirect_init.c @@ -0,0 +1,785 @@ +/* DO NOT EDIT - This file generated automatically by glX_proto_send.py (from Mesa) script */ + +/* + * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. + * (C) Copyright IBM Corporation 2004 + * 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 + * PRECISION INSIGHT, IBM, + * 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. + */ + +/** + * \file indirect_init.c + * Initialize indirect rendering dispatch table. + * + * \author Kevin E. Martin + * \author Brian Paul + * \author Ian Romanick + */ + +#include "indirect_init.h" +#include "indirect.h" +#include "glapi.h" + + +/** + * No-op function used to initialize functions that have no GLX protocol + * support. + */ +static int NoOp(void) +{ + return 0; +} + +/** + * Create and initialize a new GL dispatch table. The table is initialized + * with GLX indirect rendering protocol functions. + */ +struct _glapi_table * __glXNewIndirectAPI( void ) +{ + struct _glapi_table *glAPI; + GLuint entries; + + entries = _glapi_get_dispatch_table_size(); + glAPI = (struct _glapi_table *) Xmalloc(entries * sizeof(void *)); + + /* first, set all entries to point to no-op functions */ + { + int i; + void **dispatch = (void **) glAPI; + for (i = 0; i < entries; i++) { + dispatch[i] = (void *) NoOp; + } + } + + /* now, initialize the entries we understand */ + + /* 1.0 */ + + glAPI->Accum = __indirect_glAccum; + glAPI->AlphaFunc = __indirect_glAlphaFunc; + glAPI->Begin = __indirect_glBegin; + glAPI->Bitmap = __indirect_glBitmap; + glAPI->BlendFunc = __indirect_glBlendFunc; + glAPI->CallList = __indirect_glCallList; + glAPI->CallLists = __indirect_glCallLists; + glAPI->Clear = __indirect_glClear; + glAPI->ClearAccum = __indirect_glClearAccum; + glAPI->ClearColor = __indirect_glClearColor; + glAPI->ClearDepth = __indirect_glClearDepth; + glAPI->ClearIndex = __indirect_glClearIndex; + glAPI->ClearStencil = __indirect_glClearStencil; + glAPI->ClipPlane = __indirect_glClipPlane; + glAPI->Color3b = __indirect_glColor3b; + glAPI->Color3bv = __indirect_glColor3bv; + glAPI->Color3d = __indirect_glColor3d; + glAPI->Color3dv = __indirect_glColor3dv; + glAPI->Color3f = __indirect_glColor3f; + glAPI->Color3fv = __indirect_glColor3fv; + glAPI->Color3i = __indirect_glColor3i; + glAPI->Color3iv = __indirect_glColor3iv; + glAPI->Color3s = __indirect_glColor3s; + glAPI->Color3sv = __indirect_glColor3sv; + glAPI->Color3ub = __indirect_glColor3ub; + glAPI->Color3ubv = __indirect_glColor3ubv; + glAPI->Color3ui = __indirect_glColor3ui; + glAPI->Color3uiv = __indirect_glColor3uiv; + glAPI->Color3us = __indirect_glColor3us; + glAPI->Color3usv = __indirect_glColor3usv; + glAPI->Color4b = __indirect_glColor4b; + glAPI->Color4bv = __indirect_glColor4bv; + glAPI->Color4d = __indirect_glColor4d; + glAPI->Color4dv = __indirect_glColor4dv; + glAPI->Color4f = __indirect_glColor4f; + glAPI->Color4fv = __indirect_glColor4fv; + glAPI->Color4i = __indirect_glColor4i; + glAPI->Color4iv = __indirect_glColor4iv; + glAPI->Color4s = __indirect_glColor4s; + glAPI->Color4sv = __indirect_glColor4sv; + glAPI->Color4ub = __indirect_glColor4ub; + glAPI->Color4ubv = __indirect_glColor4ubv; + glAPI->Color4ui = __indirect_glColor4ui; + glAPI->Color4uiv = __indirect_glColor4uiv; + glAPI->Color4us = __indirect_glColor4us; + glAPI->Color4usv = __indirect_glColor4usv; + glAPI->ColorMask = __indirect_glColorMask; + glAPI->ColorMaterial = __indirect_glColorMaterial; + glAPI->CopyPixels = __indirect_glCopyPixels; + glAPI->CullFace = __indirect_glCullFace; + glAPI->DeleteLists = __indirect_glDeleteLists; + glAPI->DepthFunc = __indirect_glDepthFunc; + glAPI->DepthMask = __indirect_glDepthMask; + glAPI->DepthRange = __indirect_glDepthRange; + glAPI->Disable = __indirect_glDisable; + glAPI->DrawBuffer = __indirect_glDrawBuffer; + glAPI->DrawPixels = __indirect_glDrawPixels; + glAPI->EdgeFlag = __indirect_glEdgeFlag; + glAPI->EdgeFlagv = __indirect_glEdgeFlagv; + glAPI->Enable = __indirect_glEnable; + glAPI->End = __indirect_glEnd; + glAPI->EndList = __indirect_glEndList; + glAPI->EvalCoord1d = __indirect_glEvalCoord1d; + glAPI->EvalCoord1dv = __indirect_glEvalCoord1dv; + glAPI->EvalCoord1f = __indirect_glEvalCoord1f; + glAPI->EvalCoord1fv = __indirect_glEvalCoord1fv; + glAPI->EvalCoord2d = __indirect_glEvalCoord2d; + glAPI->EvalCoord2dv = __indirect_glEvalCoord2dv; + glAPI->EvalCoord2f = __indirect_glEvalCoord2f; + glAPI->EvalCoord2fv = __indirect_glEvalCoord2fv; + glAPI->EvalMesh1 = __indirect_glEvalMesh1; + glAPI->EvalMesh2 = __indirect_glEvalMesh2; + glAPI->EvalPoint1 = __indirect_glEvalPoint1; + glAPI->EvalPoint2 = __indirect_glEvalPoint2; + glAPI->FeedbackBuffer = __indirect_glFeedbackBuffer; + glAPI->Finish = __indirect_glFinish; + glAPI->Flush = __indirect_glFlush; + glAPI->Fogf = __indirect_glFogf; + glAPI->Fogfv = __indirect_glFogfv; + glAPI->Fogi = __indirect_glFogi; + glAPI->Fogiv = __indirect_glFogiv; + glAPI->FrontFace = __indirect_glFrontFace; + glAPI->Frustum = __indirect_glFrustum; + glAPI->GenLists = __indirect_glGenLists; + glAPI->GetBooleanv = __indirect_glGetBooleanv; + glAPI->GetClipPlane = __indirect_glGetClipPlane; + glAPI->GetDoublev = __indirect_glGetDoublev; + glAPI->GetError = __indirect_glGetError; + glAPI->GetFloatv = __indirect_glGetFloatv; + glAPI->GetIntegerv = __indirect_glGetIntegerv; + glAPI->GetLightfv = __indirect_glGetLightfv; + glAPI->GetLightiv = __indirect_glGetLightiv; + glAPI->GetMapdv = __indirect_glGetMapdv; + glAPI->GetMapfv = __indirect_glGetMapfv; + glAPI->GetMapiv = __indirect_glGetMapiv; + glAPI->GetMaterialfv = __indirect_glGetMaterialfv; + glAPI->GetMaterialiv = __indirect_glGetMaterialiv; + glAPI->GetPixelMapfv = __indirect_glGetPixelMapfv; + glAPI->GetPixelMapuiv = __indirect_glGetPixelMapuiv; + glAPI->GetPixelMapusv = __indirect_glGetPixelMapusv; + glAPI->GetPolygonStipple = __indirect_glGetPolygonStipple; + glAPI->GetString = __indirect_glGetString; + glAPI->GetTexEnvfv = __indirect_glGetTexEnvfv; + glAPI->GetTexEnviv = __indirect_glGetTexEnviv; + glAPI->GetTexGendv = __indirect_glGetTexGendv; + glAPI->GetTexGenfv = __indirect_glGetTexGenfv; + glAPI->GetTexGeniv = __indirect_glGetTexGeniv; + glAPI->GetTexImage = __indirect_glGetTexImage; + glAPI->GetTexLevelParameterfv = __indirect_glGetTexLevelParameterfv; + glAPI->GetTexLevelParameteriv = __indirect_glGetTexLevelParameteriv; + glAPI->GetTexParameterfv = __indirect_glGetTexParameterfv; + glAPI->GetTexParameteriv = __indirect_glGetTexParameteriv; + glAPI->Hint = __indirect_glHint; + glAPI->IndexMask = __indirect_glIndexMask; + glAPI->Indexd = __indirect_glIndexd; + glAPI->Indexdv = __indirect_glIndexdv; + glAPI->Indexf = __indirect_glIndexf; + glAPI->Indexfv = __indirect_glIndexfv; + glAPI->Indexi = __indirect_glIndexi; + glAPI->Indexiv = __indirect_glIndexiv; + glAPI->Indexs = __indirect_glIndexs; + glAPI->Indexsv = __indirect_glIndexsv; + glAPI->InitNames = __indirect_glInitNames; + glAPI->IsEnabled = __indirect_glIsEnabled; + glAPI->IsList = __indirect_glIsList; + glAPI->LightModelf = __indirect_glLightModelf; + glAPI->LightModelfv = __indirect_glLightModelfv; + glAPI->LightModeli = __indirect_glLightModeli; + glAPI->LightModeliv = __indirect_glLightModeliv; + glAPI->Lightf = __indirect_glLightf; + glAPI->Lightfv = __indirect_glLightfv; + glAPI->Lighti = __indirect_glLighti; + glAPI->Lightiv = __indirect_glLightiv; + glAPI->LineStipple = __indirect_glLineStipple; + glAPI->LineWidth = __indirect_glLineWidth; + glAPI->ListBase = __indirect_glListBase; + glAPI->LoadIdentity = __indirect_glLoadIdentity; + glAPI->LoadMatrixd = __indirect_glLoadMatrixd; + glAPI->LoadMatrixf = __indirect_glLoadMatrixf; + glAPI->LoadName = __indirect_glLoadName; + glAPI->LogicOp = __indirect_glLogicOp; + glAPI->Map1d = __indirect_glMap1d; + glAPI->Map1f = __indirect_glMap1f; + glAPI->Map2d = __indirect_glMap2d; + glAPI->Map2f = __indirect_glMap2f; + glAPI->MapGrid1d = __indirect_glMapGrid1d; + glAPI->MapGrid1f = __indirect_glMapGrid1f; + glAPI->MapGrid2d = __indirect_glMapGrid2d; + glAPI->MapGrid2f = __indirect_glMapGrid2f; + glAPI->Materialf = __indirect_glMaterialf; + glAPI->Materialfv = __indirect_glMaterialfv; + glAPI->Materiali = __indirect_glMateriali; + glAPI->Materialiv = __indirect_glMaterialiv; + glAPI->MatrixMode = __indirect_glMatrixMode; + glAPI->MultMatrixd = __indirect_glMultMatrixd; + glAPI->MultMatrixf = __indirect_glMultMatrixf; + glAPI->NewList = __indirect_glNewList; + glAPI->Normal3b = __indirect_glNormal3b; + glAPI->Normal3bv = __indirect_glNormal3bv; + glAPI->Normal3d = __indirect_glNormal3d; + glAPI->Normal3dv = __indirect_glNormal3dv; + glAPI->Normal3f = __indirect_glNormal3f; + glAPI->Normal3fv = __indirect_glNormal3fv; + glAPI->Normal3i = __indirect_glNormal3i; + glAPI->Normal3iv = __indirect_glNormal3iv; + glAPI->Normal3s = __indirect_glNormal3s; + glAPI->Normal3sv = __indirect_glNormal3sv; + glAPI->Ortho = __indirect_glOrtho; + glAPI->PassThrough = __indirect_glPassThrough; + glAPI->PixelMapfv = __indirect_glPixelMapfv; + glAPI->PixelMapuiv = __indirect_glPixelMapuiv; + glAPI->PixelMapusv = __indirect_glPixelMapusv; + glAPI->PixelStoref = __indirect_glPixelStoref; + glAPI->PixelStorei = __indirect_glPixelStorei; + glAPI->PixelTransferf = __indirect_glPixelTransferf; + glAPI->PixelTransferi = __indirect_glPixelTransferi; + glAPI->PixelZoom = __indirect_glPixelZoom; + glAPI->PointSize = __indirect_glPointSize; + glAPI->PolygonMode = __indirect_glPolygonMode; + glAPI->PolygonStipple = __indirect_glPolygonStipple; + glAPI->PopAttrib = __indirect_glPopAttrib; + glAPI->PopMatrix = __indirect_glPopMatrix; + glAPI->PopName = __indirect_glPopName; + glAPI->PushAttrib = __indirect_glPushAttrib; + glAPI->PushMatrix = __indirect_glPushMatrix; + glAPI->PushName = __indirect_glPushName; + glAPI->RasterPos2d = __indirect_glRasterPos2d; + glAPI->RasterPos2dv = __indirect_glRasterPos2dv; + glAPI->RasterPos2f = __indirect_glRasterPos2f; + glAPI->RasterPos2fv = __indirect_glRasterPos2fv; + glAPI->RasterPos2i = __indirect_glRasterPos2i; + glAPI->RasterPos2iv = __indirect_glRasterPos2iv; + glAPI->RasterPos2s = __indirect_glRasterPos2s; + glAPI->RasterPos2sv = __indirect_glRasterPos2sv; + glAPI->RasterPos3d = __indirect_glRasterPos3d; + glAPI->RasterPos3dv = __indirect_glRasterPos3dv; + glAPI->RasterPos3f = __indirect_glRasterPos3f; + glAPI->RasterPos3fv = __indirect_glRasterPos3fv; + glAPI->RasterPos3i = __indirect_glRasterPos3i; + glAPI->RasterPos3iv = __indirect_glRasterPos3iv; + glAPI->RasterPos3s = __indirect_glRasterPos3s; + glAPI->RasterPos3sv = __indirect_glRasterPos3sv; + glAPI->RasterPos4d = __indirect_glRasterPos4d; + glAPI->RasterPos4dv = __indirect_glRasterPos4dv; + glAPI->RasterPos4f = __indirect_glRasterPos4f; + glAPI->RasterPos4fv = __indirect_glRasterPos4fv; + glAPI->RasterPos4i = __indirect_glRasterPos4i; + glAPI->RasterPos4iv = __indirect_glRasterPos4iv; + glAPI->RasterPos4s = __indirect_glRasterPos4s; + glAPI->RasterPos4sv = __indirect_glRasterPos4sv; + glAPI->ReadBuffer = __indirect_glReadBuffer; + glAPI->ReadPixels = __indirect_glReadPixels; + glAPI->Rectd = __indirect_glRectd; + glAPI->Rectdv = __indirect_glRectdv; + glAPI->Rectf = __indirect_glRectf; + glAPI->Rectfv = __indirect_glRectfv; + glAPI->Recti = __indirect_glRecti; + glAPI->Rectiv = __indirect_glRectiv; + glAPI->Rects = __indirect_glRects; + glAPI->Rectsv = __indirect_glRectsv; + glAPI->RenderMode = __indirect_glRenderMode; + glAPI->Rotated = __indirect_glRotated; + glAPI->Rotatef = __indirect_glRotatef; + glAPI->Scaled = __indirect_glScaled; + glAPI->Scalef = __indirect_glScalef; + glAPI->Scissor = __indirect_glScissor; + glAPI->SelectBuffer = __indirect_glSelectBuffer; + glAPI->ShadeModel = __indirect_glShadeModel; + glAPI->StencilFunc = __indirect_glStencilFunc; + glAPI->StencilMask = __indirect_glStencilMask; + glAPI->StencilOp = __indirect_glStencilOp; + glAPI->TexCoord1d = __indirect_glTexCoord1d; + glAPI->TexCoord1dv = __indirect_glTexCoord1dv; + glAPI->TexCoord1f = __indirect_glTexCoord1f; + glAPI->TexCoord1fv = __indirect_glTexCoord1fv; + glAPI->TexCoord1i = __indirect_glTexCoord1i; + glAPI->TexCoord1iv = __indirect_glTexCoord1iv; + glAPI->TexCoord1s = __indirect_glTexCoord1s; + glAPI->TexCoord1sv = __indirect_glTexCoord1sv; + glAPI->TexCoord2d = __indirect_glTexCoord2d; + glAPI->TexCoord2dv = __indirect_glTexCoord2dv; + glAPI->TexCoord2f = __indirect_glTexCoord2f; + glAPI->TexCoord2fv = __indirect_glTexCoord2fv; + glAPI->TexCoord2i = __indirect_glTexCoord2i; + glAPI->TexCoord2iv = __indirect_glTexCoord2iv; + glAPI->TexCoord2s = __indirect_glTexCoord2s; + glAPI->TexCoord2sv = __indirect_glTexCoord2sv; + glAPI->TexCoord3d = __indirect_glTexCoord3d; + glAPI->TexCoord3dv = __indirect_glTexCoord3dv; + glAPI->TexCoord3f = __indirect_glTexCoord3f; + glAPI->TexCoord3fv = __indirect_glTexCoord3fv; + glAPI->TexCoord3i = __indirect_glTexCoord3i; + glAPI->TexCoord3iv = __indirect_glTexCoord3iv; + glAPI->TexCoord3s = __indirect_glTexCoord3s; + glAPI->TexCoord3sv = __indirect_glTexCoord3sv; + glAPI->TexCoord4d = __indirect_glTexCoord4d; + glAPI->TexCoord4dv = __indirect_glTexCoord4dv; + glAPI->TexCoord4f = __indirect_glTexCoord4f; + glAPI->TexCoord4fv = __indirect_glTexCoord4fv; + glAPI->TexCoord4i = __indirect_glTexCoord4i; + glAPI->TexCoord4iv = __indirect_glTexCoord4iv; + glAPI->TexCoord4s = __indirect_glTexCoord4s; + glAPI->TexCoord4sv = __indirect_glTexCoord4sv; + glAPI->TexEnvf = __indirect_glTexEnvf; + glAPI->TexEnvfv = __indirect_glTexEnvfv; + glAPI->TexEnvi = __indirect_glTexEnvi; + glAPI->TexEnviv = __indirect_glTexEnviv; + glAPI->TexGend = __indirect_glTexGend; + glAPI->TexGendv = __indirect_glTexGendv; + glAPI->TexGenf = __indirect_glTexGenf; + glAPI->TexGenfv = __indirect_glTexGenfv; + glAPI->TexGeni = __indirect_glTexGeni; + glAPI->TexGeniv = __indirect_glTexGeniv; + glAPI->TexImage1D = __indirect_glTexImage1D; + glAPI->TexImage2D = __indirect_glTexImage2D; + glAPI->TexParameterf = __indirect_glTexParameterf; + glAPI->TexParameterfv = __indirect_glTexParameterfv; + glAPI->TexParameteri = __indirect_glTexParameteri; + glAPI->TexParameteriv = __indirect_glTexParameteriv; + glAPI->Translated = __indirect_glTranslated; + glAPI->Translatef = __indirect_glTranslatef; + glAPI->Vertex2d = __indirect_glVertex2d; + glAPI->Vertex2dv = __indirect_glVertex2dv; + glAPI->Vertex2f = __indirect_glVertex2f; + glAPI->Vertex2fv = __indirect_glVertex2fv; + glAPI->Vertex2i = __indirect_glVertex2i; + glAPI->Vertex2iv = __indirect_glVertex2iv; + glAPI->Vertex2s = __indirect_glVertex2s; + glAPI->Vertex2sv = __indirect_glVertex2sv; + glAPI->Vertex3d = __indirect_glVertex3d; + glAPI->Vertex3dv = __indirect_glVertex3dv; + glAPI->Vertex3f = __indirect_glVertex3f; + glAPI->Vertex3fv = __indirect_glVertex3fv; + glAPI->Vertex3i = __indirect_glVertex3i; + glAPI->Vertex3iv = __indirect_glVertex3iv; + glAPI->Vertex3s = __indirect_glVertex3s; + glAPI->Vertex3sv = __indirect_glVertex3sv; + glAPI->Vertex4d = __indirect_glVertex4d; + glAPI->Vertex4dv = __indirect_glVertex4dv; + glAPI->Vertex4f = __indirect_glVertex4f; + glAPI->Vertex4fv = __indirect_glVertex4fv; + glAPI->Vertex4i = __indirect_glVertex4i; + glAPI->Vertex4iv = __indirect_glVertex4iv; + glAPI->Vertex4s = __indirect_glVertex4s; + glAPI->Vertex4sv = __indirect_glVertex4sv; + glAPI->Viewport = __indirect_glViewport; + + /* 1.1 */ + + glAPI->AreTexturesResident = __indirect_glAreTexturesResident; + glAPI->ArrayElement = __indirect_glArrayElement; + glAPI->BindTexture = __indirect_glBindTexture; + glAPI->ColorPointer = __indirect_glColorPointer; + glAPI->CopyTexImage1D = __indirect_glCopyTexImage1D; + glAPI->CopyTexImage2D = __indirect_glCopyTexImage2D; + glAPI->CopyTexSubImage1D = __indirect_glCopyTexSubImage1D; + glAPI->CopyTexSubImage2D = __indirect_glCopyTexSubImage2D; + glAPI->DeleteTextures = __indirect_glDeleteTextures; + glAPI->DisableClientState = __indirect_glDisableClientState; + glAPI->DrawArrays = __indirect_glDrawArrays; + glAPI->DrawElements = __indirect_glDrawElements; + glAPI->EdgeFlagPointer = __indirect_glEdgeFlagPointer; + glAPI->EnableClientState = __indirect_glEnableClientState; + glAPI->GenTextures = __indirect_glGenTextures; + glAPI->GetPointerv = __indirect_glGetPointerv; + glAPI->IndexPointer = __indirect_glIndexPointer; + glAPI->Indexub = __indirect_glIndexub; + glAPI->Indexubv = __indirect_glIndexubv; + glAPI->InterleavedArrays = __indirect_glInterleavedArrays; + glAPI->IsTexture = __indirect_glIsTexture; + glAPI->NormalPointer = __indirect_glNormalPointer; + glAPI->PolygonOffset = __indirect_glPolygonOffset; + glAPI->PopClientAttrib = __indirect_glPopClientAttrib; + glAPI->PrioritizeTextures = __indirect_glPrioritizeTextures; + glAPI->PushClientAttrib = __indirect_glPushClientAttrib; + glAPI->TexCoordPointer = __indirect_glTexCoordPointer; + glAPI->TexSubImage1D = __indirect_glTexSubImage1D; + glAPI->TexSubImage2D = __indirect_glTexSubImage2D; + glAPI->VertexPointer = __indirect_glVertexPointer; + + /* 1.2 */ + + glAPI->BlendColor = __indirect_glBlendColor; + glAPI->BlendEquation = __indirect_glBlendEquation; + glAPI->ColorSubTable = __indirect_glColorSubTable; + glAPI->ColorTable = __indirect_glColorTable; + glAPI->ColorTableParameterfv = __indirect_glColorTableParameterfv; + glAPI->ColorTableParameteriv = __indirect_glColorTableParameteriv; + glAPI->ConvolutionFilter1D = __indirect_glConvolutionFilter1D; + glAPI->ConvolutionFilter2D = __indirect_glConvolutionFilter2D; + glAPI->ConvolutionParameterf = __indirect_glConvolutionParameterf; + glAPI->ConvolutionParameterfv = __indirect_glConvolutionParameterfv; + glAPI->ConvolutionParameteri = __indirect_glConvolutionParameteri; + glAPI->ConvolutionParameteriv = __indirect_glConvolutionParameteriv; + glAPI->CopyColorSubTable = __indirect_glCopyColorSubTable; + glAPI->CopyColorTable = __indirect_glCopyColorTable; + glAPI->CopyConvolutionFilter1D = __indirect_glCopyConvolutionFilter1D; + glAPI->CopyConvolutionFilter2D = __indirect_glCopyConvolutionFilter2D; + glAPI->CopyTexSubImage3D = __indirect_glCopyTexSubImage3D; + glAPI->DrawRangeElements = __indirect_glDrawRangeElements; + glAPI->GetColorTable = __indirect_glGetColorTable; + glAPI->GetColorTableParameterfv = __indirect_glGetColorTableParameterfv; + glAPI->GetColorTableParameteriv = __indirect_glGetColorTableParameteriv; + glAPI->GetConvolutionFilter = __indirect_glGetConvolutionFilter; + glAPI->GetConvolutionParameterfv = __indirect_glGetConvolutionParameterfv; + glAPI->GetConvolutionParameteriv = __indirect_glGetConvolutionParameteriv; + glAPI->GetHistogram = __indirect_glGetHistogram; + glAPI->GetHistogramParameterfv = __indirect_glGetHistogramParameterfv; + glAPI->GetHistogramParameteriv = __indirect_glGetHistogramParameteriv; + glAPI->GetMinmax = __indirect_glGetMinmax; + glAPI->GetMinmaxParameterfv = __indirect_glGetMinmaxParameterfv; + glAPI->GetMinmaxParameteriv = __indirect_glGetMinmaxParameteriv; + glAPI->GetSeparableFilter = __indirect_glGetSeparableFilter; + glAPI->Histogram = __indirect_glHistogram; + glAPI->Minmax = __indirect_glMinmax; + glAPI->ResetHistogram = __indirect_glResetHistogram; + glAPI->ResetMinmax = __indirect_glResetMinmax; + glAPI->SeparableFilter2D = __indirect_glSeparableFilter2D; + glAPI->TexImage3D = __indirect_glTexImage3D; + glAPI->TexSubImage3D = __indirect_glTexSubImage3D; + + /* 1. GL_ARB_multitexture */ + + glAPI->ActiveTextureARB = __indirect_glActiveTextureARB; + glAPI->ClientActiveTextureARB = __indirect_glClientActiveTextureARB; + glAPI->MultiTexCoord1dARB = __indirect_glMultiTexCoord1dARB; + glAPI->MultiTexCoord1dvARB = __indirect_glMultiTexCoord1dvARB; + glAPI->MultiTexCoord1fARB = __indirect_glMultiTexCoord1fARB; + glAPI->MultiTexCoord1fvARB = __indirect_glMultiTexCoord1fvARB; + glAPI->MultiTexCoord1iARB = __indirect_glMultiTexCoord1iARB; + glAPI->MultiTexCoord1ivARB = __indirect_glMultiTexCoord1ivARB; + glAPI->MultiTexCoord1sARB = __indirect_glMultiTexCoord1sARB; + glAPI->MultiTexCoord1svARB = __indirect_glMultiTexCoord1svARB; + glAPI->MultiTexCoord2dARB = __indirect_glMultiTexCoord2dARB; + glAPI->MultiTexCoord2dvARB = __indirect_glMultiTexCoord2dvARB; + glAPI->MultiTexCoord2fARB = __indirect_glMultiTexCoord2fARB; + glAPI->MultiTexCoord2fvARB = __indirect_glMultiTexCoord2fvARB; + glAPI->MultiTexCoord2iARB = __indirect_glMultiTexCoord2iARB; + glAPI->MultiTexCoord2ivARB = __indirect_glMultiTexCoord2ivARB; + glAPI->MultiTexCoord2sARB = __indirect_glMultiTexCoord2sARB; + glAPI->MultiTexCoord2svARB = __indirect_glMultiTexCoord2svARB; + glAPI->MultiTexCoord3dARB = __indirect_glMultiTexCoord3dARB; + glAPI->MultiTexCoord3dvARB = __indirect_glMultiTexCoord3dvARB; + glAPI->MultiTexCoord3fARB = __indirect_glMultiTexCoord3fARB; + glAPI->MultiTexCoord3fvARB = __indirect_glMultiTexCoord3fvARB; + glAPI->MultiTexCoord3iARB = __indirect_glMultiTexCoord3iARB; + glAPI->MultiTexCoord3ivARB = __indirect_glMultiTexCoord3ivARB; + glAPI->MultiTexCoord3sARB = __indirect_glMultiTexCoord3sARB; + glAPI->MultiTexCoord3svARB = __indirect_glMultiTexCoord3svARB; + glAPI->MultiTexCoord4dARB = __indirect_glMultiTexCoord4dARB; + glAPI->MultiTexCoord4dvARB = __indirect_glMultiTexCoord4dvARB; + glAPI->MultiTexCoord4fARB = __indirect_glMultiTexCoord4fARB; + glAPI->MultiTexCoord4fvARB = __indirect_glMultiTexCoord4fvARB; + glAPI->MultiTexCoord4iARB = __indirect_glMultiTexCoord4iARB; + glAPI->MultiTexCoord4ivARB = __indirect_glMultiTexCoord4ivARB; + glAPI->MultiTexCoord4sARB = __indirect_glMultiTexCoord4sARB; + glAPI->MultiTexCoord4svARB = __indirect_glMultiTexCoord4svARB; + + /* 3. GL_ARB_transpose_matrix */ + + glAPI->LoadTransposeMatrixdARB = __indirect_glLoadTransposeMatrixdARB; + glAPI->LoadTransposeMatrixfARB = __indirect_glLoadTransposeMatrixfARB; + glAPI->MultTransposeMatrixdARB = __indirect_glMultTransposeMatrixdARB; + glAPI->MultTransposeMatrixfARB = __indirect_glMultTransposeMatrixfARB; + + /* 5. GL_ARB_multisample */ + + glAPI->SampleCoverageARB = __indirect_glSampleCoverageARB; + + /* 12. GL_ARB_texture_compression */ + + glAPI->CompressedTexImage1DARB = __indirect_glCompressedTexImage1DARB; + glAPI->CompressedTexImage2DARB = __indirect_glCompressedTexImage2DARB; + glAPI->CompressedTexImage3DARB = __indirect_glCompressedTexImage3DARB; + glAPI->CompressedTexSubImage1DARB = __indirect_glCompressedTexSubImage1DARB; + glAPI->CompressedTexSubImage2DARB = __indirect_glCompressedTexSubImage2DARB; + glAPI->CompressedTexSubImage3DARB = __indirect_glCompressedTexSubImage3DARB; + glAPI->GetCompressedTexImageARB = __indirect_glGetCompressedTexImageARB; + + /* 26. GL_ARB_vertex_program */ + + glAPI->DisableVertexAttribArrayARB = __indirect_glDisableVertexAttribArrayARB; + glAPI->EnableVertexAttribArrayARB = __indirect_glEnableVertexAttribArrayARB; + glAPI->GetProgramEnvParameterdvARB = __indirect_glGetProgramEnvParameterdvARB; + glAPI->GetProgramEnvParameterfvARB = __indirect_glGetProgramEnvParameterfvARB; + glAPI->GetProgramLocalParameterdvARB = __indirect_glGetProgramLocalParameterdvARB; + glAPI->GetProgramLocalParameterfvARB = __indirect_glGetProgramLocalParameterfvARB; + glAPI->GetProgramStringARB = __indirect_glGetProgramStringARB; + glAPI->GetProgramivARB = __indirect_glGetProgramivARB; + glAPI->GetVertexAttribdvARB = __indirect_glGetVertexAttribdvARB; + glAPI->GetVertexAttribfvARB = __indirect_glGetVertexAttribfvARB; + glAPI->GetVertexAttribivARB = __indirect_glGetVertexAttribivARB; + glAPI->ProgramEnvParameter4dARB = __indirect_glProgramEnvParameter4dARB; + glAPI->ProgramEnvParameter4dvARB = __indirect_glProgramEnvParameter4dvARB; + glAPI->ProgramEnvParameter4fARB = __indirect_glProgramEnvParameter4fARB; + glAPI->ProgramEnvParameter4fvARB = __indirect_glProgramEnvParameter4fvARB; + glAPI->ProgramLocalParameter4dARB = __indirect_glProgramLocalParameter4dARB; + glAPI->ProgramLocalParameter4dvARB = __indirect_glProgramLocalParameter4dvARB; + glAPI->ProgramLocalParameter4fARB = __indirect_glProgramLocalParameter4fARB; + glAPI->ProgramLocalParameter4fvARB = __indirect_glProgramLocalParameter4fvARB; + glAPI->ProgramStringARB = __indirect_glProgramStringARB; + glAPI->VertexAttrib1dARB = __indirect_glVertexAttrib1dARB; + glAPI->VertexAttrib1dvARB = __indirect_glVertexAttrib1dvARB; + glAPI->VertexAttrib1fARB = __indirect_glVertexAttrib1fARB; + glAPI->VertexAttrib1fvARB = __indirect_glVertexAttrib1fvARB; + glAPI->VertexAttrib1sARB = __indirect_glVertexAttrib1sARB; + glAPI->VertexAttrib1svARB = __indirect_glVertexAttrib1svARB; + glAPI->VertexAttrib2dARB = __indirect_glVertexAttrib2dARB; + glAPI->VertexAttrib2dvARB = __indirect_glVertexAttrib2dvARB; + glAPI->VertexAttrib2fARB = __indirect_glVertexAttrib2fARB; + glAPI->VertexAttrib2fvARB = __indirect_glVertexAttrib2fvARB; + glAPI->VertexAttrib2sARB = __indirect_glVertexAttrib2sARB; + glAPI->VertexAttrib2svARB = __indirect_glVertexAttrib2svARB; + glAPI->VertexAttrib3dARB = __indirect_glVertexAttrib3dARB; + glAPI->VertexAttrib3dvARB = __indirect_glVertexAttrib3dvARB; + glAPI->VertexAttrib3fARB = __indirect_glVertexAttrib3fARB; + glAPI->VertexAttrib3fvARB = __indirect_glVertexAttrib3fvARB; + glAPI->VertexAttrib3sARB = __indirect_glVertexAttrib3sARB; + glAPI->VertexAttrib3svARB = __indirect_glVertexAttrib3svARB; + glAPI->VertexAttrib4NbvARB = __indirect_glVertexAttrib4NbvARB; + glAPI->VertexAttrib4NivARB = __indirect_glVertexAttrib4NivARB; + glAPI->VertexAttrib4NsvARB = __indirect_glVertexAttrib4NsvARB; + glAPI->VertexAttrib4NubARB = __indirect_glVertexAttrib4NubARB; + glAPI->VertexAttrib4NubvARB = __indirect_glVertexAttrib4NubvARB; + glAPI->VertexAttrib4NuivARB = __indirect_glVertexAttrib4NuivARB; + glAPI->VertexAttrib4NusvARB = __indirect_glVertexAttrib4NusvARB; + glAPI->VertexAttrib4bvARB = __indirect_glVertexAttrib4bvARB; + glAPI->VertexAttrib4dARB = __indirect_glVertexAttrib4dARB; + glAPI->VertexAttrib4dvARB = __indirect_glVertexAttrib4dvARB; + glAPI->VertexAttrib4fARB = __indirect_glVertexAttrib4fARB; + glAPI->VertexAttrib4fvARB = __indirect_glVertexAttrib4fvARB; + glAPI->VertexAttrib4ivARB = __indirect_glVertexAttrib4ivARB; + glAPI->VertexAttrib4sARB = __indirect_glVertexAttrib4sARB; + glAPI->VertexAttrib4svARB = __indirect_glVertexAttrib4svARB; + glAPI->VertexAttrib4ubvARB = __indirect_glVertexAttrib4ubvARB; + glAPI->VertexAttrib4uivARB = __indirect_glVertexAttrib4uivARB; + glAPI->VertexAttrib4usvARB = __indirect_glVertexAttrib4usvARB; + glAPI->VertexAttribPointerARB = __indirect_glVertexAttribPointerARB; + + /* 29. GL_ARB_occlusion_query */ + + glAPI->BeginQueryARB = __indirect_glBeginQueryARB; + glAPI->DeleteQueriesARB = __indirect_glDeleteQueriesARB; + glAPI->EndQueryARB = __indirect_glEndQueryARB; + glAPI->GenQueriesARB = __indirect_glGenQueriesARB; + glAPI->GetQueryObjectivARB = __indirect_glGetQueryObjectivARB; + glAPI->GetQueryObjectuivARB = __indirect_glGetQueryObjectuivARB; + glAPI->GetQueryivARB = __indirect_glGetQueryivARB; + glAPI->IsQueryARB = __indirect_glIsQueryARB; + + /* 37. GL_ARB_draw_buffers */ + + glAPI->DrawBuffersARB = __indirect_glDrawBuffersARB; + + /* 45. GL_ARB_framebuffer_object */ + + glAPI->RenderbufferStorageMultisample = __indirect_glRenderbufferStorageMultisample; + + /* 25. GL_SGIS_multisample */ + + glAPI->SampleMaskSGIS = __indirect_glSampleMaskSGIS; + glAPI->SamplePatternSGIS = __indirect_glSamplePatternSGIS; + + /* 30. GL_EXT_vertex_array */ + + glAPI->ColorPointerEXT = __indirect_glColorPointerEXT; + glAPI->EdgeFlagPointerEXT = __indirect_glEdgeFlagPointerEXT; + glAPI->IndexPointerEXT = __indirect_glIndexPointerEXT; + glAPI->NormalPointerEXT = __indirect_glNormalPointerEXT; + glAPI->TexCoordPointerEXT = __indirect_glTexCoordPointerEXT; + glAPI->VertexPointerEXT = __indirect_glVertexPointerEXT; + + /* 54. GL_EXT_point_parameters */ + + glAPI->PointParameterfEXT = __indirect_glPointParameterfEXT; + glAPI->PointParameterfvEXT = __indirect_glPointParameterfvEXT; + + /* 145. GL_EXT_secondary_color */ + + glAPI->SecondaryColor3bEXT = __indirect_glSecondaryColor3bEXT; + glAPI->SecondaryColor3bvEXT = __indirect_glSecondaryColor3bvEXT; + glAPI->SecondaryColor3dEXT = __indirect_glSecondaryColor3dEXT; + glAPI->SecondaryColor3dvEXT = __indirect_glSecondaryColor3dvEXT; + glAPI->SecondaryColor3fEXT = __indirect_glSecondaryColor3fEXT; + glAPI->SecondaryColor3fvEXT = __indirect_glSecondaryColor3fvEXT; + glAPI->SecondaryColor3iEXT = __indirect_glSecondaryColor3iEXT; + glAPI->SecondaryColor3ivEXT = __indirect_glSecondaryColor3ivEXT; + glAPI->SecondaryColor3sEXT = __indirect_glSecondaryColor3sEXT; + glAPI->SecondaryColor3svEXT = __indirect_glSecondaryColor3svEXT; + glAPI->SecondaryColor3ubEXT = __indirect_glSecondaryColor3ubEXT; + glAPI->SecondaryColor3ubvEXT = __indirect_glSecondaryColor3ubvEXT; + glAPI->SecondaryColor3uiEXT = __indirect_glSecondaryColor3uiEXT; + glAPI->SecondaryColor3uivEXT = __indirect_glSecondaryColor3uivEXT; + glAPI->SecondaryColor3usEXT = __indirect_glSecondaryColor3usEXT; + glAPI->SecondaryColor3usvEXT = __indirect_glSecondaryColor3usvEXT; + glAPI->SecondaryColorPointerEXT = __indirect_glSecondaryColorPointerEXT; + + /* 148. GL_EXT_multi_draw_arrays */ + + glAPI->MultiDrawArraysEXT = __indirect_glMultiDrawArraysEXT; + glAPI->MultiDrawElementsEXT = __indirect_glMultiDrawElementsEXT; + + /* 149. GL_EXT_fog_coord */ + + glAPI->FogCoordPointerEXT = __indirect_glFogCoordPointerEXT; + glAPI->FogCoorddEXT = __indirect_glFogCoorddEXT; + glAPI->FogCoorddvEXT = __indirect_glFogCoorddvEXT; + glAPI->FogCoordfEXT = __indirect_glFogCoordfEXT; + glAPI->FogCoordfvEXT = __indirect_glFogCoordfvEXT; + + /* 173. GL_EXT_blend_func_separate */ + + glAPI->BlendFuncSeparateEXT = __indirect_glBlendFuncSeparateEXT; + + /* 197. GL_MESA_window_pos */ + + glAPI->WindowPos2dMESA = __indirect_glWindowPos2dMESA; + glAPI->WindowPos2dvMESA = __indirect_glWindowPos2dvMESA; + glAPI->WindowPos2fMESA = __indirect_glWindowPos2fMESA; + glAPI->WindowPos2fvMESA = __indirect_glWindowPos2fvMESA; + glAPI->WindowPos2iMESA = __indirect_glWindowPos2iMESA; + glAPI->WindowPos2ivMESA = __indirect_glWindowPos2ivMESA; + glAPI->WindowPos2sMESA = __indirect_glWindowPos2sMESA; + glAPI->WindowPos2svMESA = __indirect_glWindowPos2svMESA; + glAPI->WindowPos3dMESA = __indirect_glWindowPos3dMESA; + glAPI->WindowPos3dvMESA = __indirect_glWindowPos3dvMESA; + glAPI->WindowPos3fMESA = __indirect_glWindowPos3fMESA; + glAPI->WindowPos3fvMESA = __indirect_glWindowPos3fvMESA; + glAPI->WindowPos3iMESA = __indirect_glWindowPos3iMESA; + glAPI->WindowPos3ivMESA = __indirect_glWindowPos3ivMESA; + glAPI->WindowPos3sMESA = __indirect_glWindowPos3sMESA; + glAPI->WindowPos3svMESA = __indirect_glWindowPos3svMESA; + + /* 233. GL_NV_vertex_program */ + + glAPI->AreProgramsResidentNV = __indirect_glAreProgramsResidentNV; + glAPI->BindProgramNV = __indirect_glBindProgramNV; + glAPI->DeleteProgramsNV = __indirect_glDeleteProgramsNV; + glAPI->ExecuteProgramNV = __indirect_glExecuteProgramNV; + glAPI->GenProgramsNV = __indirect_glGenProgramsNV; + glAPI->GetProgramParameterdvNV = __indirect_glGetProgramParameterdvNV; + glAPI->GetProgramParameterfvNV = __indirect_glGetProgramParameterfvNV; + glAPI->GetProgramStringNV = __indirect_glGetProgramStringNV; + glAPI->GetProgramivNV = __indirect_glGetProgramivNV; + glAPI->GetTrackMatrixivNV = __indirect_glGetTrackMatrixivNV; + glAPI->GetVertexAttribPointervNV = __indirect_glGetVertexAttribPointervNV; + glAPI->GetVertexAttribdvNV = __indirect_glGetVertexAttribdvNV; + glAPI->GetVertexAttribfvNV = __indirect_glGetVertexAttribfvNV; + glAPI->GetVertexAttribivNV = __indirect_glGetVertexAttribivNV; + glAPI->IsProgramNV = __indirect_glIsProgramNV; + glAPI->LoadProgramNV = __indirect_glLoadProgramNV; + glAPI->ProgramParameters4dvNV = __indirect_glProgramParameters4dvNV; + glAPI->ProgramParameters4fvNV = __indirect_glProgramParameters4fvNV; + glAPI->RequestResidentProgramsNV = __indirect_glRequestResidentProgramsNV; + glAPI->TrackMatrixNV = __indirect_glTrackMatrixNV; + glAPI->VertexAttrib1dNV = __indirect_glVertexAttrib1dNV; + glAPI->VertexAttrib1dvNV = __indirect_glVertexAttrib1dvNV; + glAPI->VertexAttrib1fNV = __indirect_glVertexAttrib1fNV; + glAPI->VertexAttrib1fvNV = __indirect_glVertexAttrib1fvNV; + glAPI->VertexAttrib1sNV = __indirect_glVertexAttrib1sNV; + glAPI->VertexAttrib1svNV = __indirect_glVertexAttrib1svNV; + glAPI->VertexAttrib2dNV = __indirect_glVertexAttrib2dNV; + glAPI->VertexAttrib2dvNV = __indirect_glVertexAttrib2dvNV; + glAPI->VertexAttrib2fNV = __indirect_glVertexAttrib2fNV; + glAPI->VertexAttrib2fvNV = __indirect_glVertexAttrib2fvNV; + glAPI->VertexAttrib2sNV = __indirect_glVertexAttrib2sNV; + glAPI->VertexAttrib2svNV = __indirect_glVertexAttrib2svNV; + glAPI->VertexAttrib3dNV = __indirect_glVertexAttrib3dNV; + glAPI->VertexAttrib3dvNV = __indirect_glVertexAttrib3dvNV; + glAPI->VertexAttrib3fNV = __indirect_glVertexAttrib3fNV; + glAPI->VertexAttrib3fvNV = __indirect_glVertexAttrib3fvNV; + glAPI->VertexAttrib3sNV = __indirect_glVertexAttrib3sNV; + glAPI->VertexAttrib3svNV = __indirect_glVertexAttrib3svNV; + glAPI->VertexAttrib4dNV = __indirect_glVertexAttrib4dNV; + glAPI->VertexAttrib4dvNV = __indirect_glVertexAttrib4dvNV; + glAPI->VertexAttrib4fNV = __indirect_glVertexAttrib4fNV; + glAPI->VertexAttrib4fvNV = __indirect_glVertexAttrib4fvNV; + glAPI->VertexAttrib4sNV = __indirect_glVertexAttrib4sNV; + glAPI->VertexAttrib4svNV = __indirect_glVertexAttrib4svNV; + glAPI->VertexAttrib4ubNV = __indirect_glVertexAttrib4ubNV; + glAPI->VertexAttrib4ubvNV = __indirect_glVertexAttrib4ubvNV; + glAPI->VertexAttribPointerNV = __indirect_glVertexAttribPointerNV; + glAPI->VertexAttribs1dvNV = __indirect_glVertexAttribs1dvNV; + glAPI->VertexAttribs1fvNV = __indirect_glVertexAttribs1fvNV; + glAPI->VertexAttribs1svNV = __indirect_glVertexAttribs1svNV; + glAPI->VertexAttribs2dvNV = __indirect_glVertexAttribs2dvNV; + glAPI->VertexAttribs2fvNV = __indirect_glVertexAttribs2fvNV; + glAPI->VertexAttribs2svNV = __indirect_glVertexAttribs2svNV; + glAPI->VertexAttribs3dvNV = __indirect_glVertexAttribs3dvNV; + glAPI->VertexAttribs3fvNV = __indirect_glVertexAttribs3fvNV; + glAPI->VertexAttribs3svNV = __indirect_glVertexAttribs3svNV; + glAPI->VertexAttribs4dvNV = __indirect_glVertexAttribs4dvNV; + glAPI->VertexAttribs4fvNV = __indirect_glVertexAttribs4fvNV; + glAPI->VertexAttribs4svNV = __indirect_glVertexAttribs4svNV; + glAPI->VertexAttribs4ubvNV = __indirect_glVertexAttribs4ubvNV; + + /* 262. GL_NV_point_sprite */ + + glAPI->PointParameteriNV = __indirect_glPointParameteriNV; + glAPI->PointParameterivNV = __indirect_glPointParameterivNV; + + /* 268. GL_EXT_stencil_two_side */ + + glAPI->ActiveStencilFaceEXT = __indirect_glActiveStencilFaceEXT; + + /* 282. GL_NV_fragment_program */ + + glAPI->GetProgramNamedParameterdvNV = __indirect_glGetProgramNamedParameterdvNV; + glAPI->GetProgramNamedParameterfvNV = __indirect_glGetProgramNamedParameterfvNV; + glAPI->ProgramNamedParameter4dNV = __indirect_glProgramNamedParameter4dNV; + glAPI->ProgramNamedParameter4dvNV = __indirect_glProgramNamedParameter4dvNV; + glAPI->ProgramNamedParameter4fNV = __indirect_glProgramNamedParameter4fNV; + glAPI->ProgramNamedParameter4fvNV = __indirect_glProgramNamedParameter4fvNV; + + /* 299. GL_EXT_blend_equation_separate */ + + glAPI->BlendEquationSeparateEXT = __indirect_glBlendEquationSeparateEXT; + + /* 310. GL_EXT_framebuffer_object */ + + glAPI->BindFramebufferEXT = __indirect_glBindFramebufferEXT; + glAPI->BindRenderbufferEXT = __indirect_glBindRenderbufferEXT; + glAPI->CheckFramebufferStatusEXT = __indirect_glCheckFramebufferStatusEXT; + glAPI->DeleteFramebuffersEXT = __indirect_glDeleteFramebuffersEXT; + glAPI->DeleteRenderbuffersEXT = __indirect_glDeleteRenderbuffersEXT; + glAPI->FramebufferRenderbufferEXT = __indirect_glFramebufferRenderbufferEXT; + glAPI->FramebufferTexture1DEXT = __indirect_glFramebufferTexture1DEXT; + glAPI->FramebufferTexture2DEXT = __indirect_glFramebufferTexture2DEXT; + glAPI->FramebufferTexture3DEXT = __indirect_glFramebufferTexture3DEXT; + glAPI->GenFramebuffersEXT = __indirect_glGenFramebuffersEXT; + glAPI->GenRenderbuffersEXT = __indirect_glGenRenderbuffersEXT; + glAPI->GenerateMipmapEXT = __indirect_glGenerateMipmapEXT; + glAPI->GetFramebufferAttachmentParameterivEXT = __indirect_glGetFramebufferAttachmentParameterivEXT; + glAPI->GetRenderbufferParameterivEXT = __indirect_glGetRenderbufferParameterivEXT; + glAPI->IsFramebufferEXT = __indirect_glIsFramebufferEXT; + glAPI->IsRenderbufferEXT = __indirect_glIsRenderbufferEXT; + glAPI->RenderbufferStorageEXT = __indirect_glRenderbufferStorageEXT; + + /* 316. GL_EXT_framebuffer_blit */ + + glAPI->BlitFramebufferEXT = __indirect_glBlitFramebufferEXT; + + /* 329. GL_EXT_texture_array */ + + glAPI->FramebufferTextureLayerEXT = __indirect_glFramebufferTextureLayerEXT; + + return glAPI; +} + diff --git a/src/glx/indirect_init.h b/src/glx/indirect_init.h new file mode 100644 index 0000000..2ba01f5 --- /dev/null +++ b/src/glx/indirect_init.h @@ -0,0 +1,41 @@ +/************************************************************************** + +Copyright 1998-1999 Precision Insight, 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 PRECISION INSIGHT 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. + +**************************************************************************/ + +/* + * Authors: + * Kevin E. Martin + * + */ + +#ifndef _INDIRECT_INIT_H_ +#define _INDIRECT_INIT_H_ + +#include "glxclient.h" + +extern struct _glapi_table *__glXNewIndirectAPI(void); + +#endif /* _INDIRECT_INIT_H_ */ diff --git a/src/glx/indirect_size.c b/src/glx/indirect_size.c new file mode 100644 index 0000000..411a0e4 --- /dev/null +++ b/src/glx/indirect_size.c @@ -0,0 +1,388 @@ +/* DO NOT EDIT - This file generated automatically by glX_proto_size.py (from Mesa) script */ + +/* + * (C) Copyright IBM Corporation 2004 + * 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 + * IBM, + * 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 +#include "indirect_size.h" + +# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define PURE __attribute__((pure)) +# else +# define PURE +# endif + +# if defined(__i386__) && defined(__GNUC__) && !defined(__CYGWIN__) && !defined(__MINGW32__) +# define FASTCALL __attribute__((fastcall)) +# else +# define FASTCALL +# endif + +# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) && defined(__ELF__) +# define INTERNAL __attribute__((visibility("internal"))) +# else +# define INTERNAL +# endif + + +#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(GLX_USE_APPLEGL) +# undef HAVE_ALIAS +#endif +#ifdef HAVE_ALIAS +# define ALIAS2(from,to) \ + INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \ + __attribute__ ((alias( # to ))); +# define ALIAS(from,to) ALIAS2( from, __gl ## to ## _size ) +#else +# define ALIAS(from,to) \ + INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \ + { return __gl ## to ## _size( e ); } +#endif + + +INTERNAL PURE FASTCALL GLint +__glCallLists_size(GLenum e) +{ + switch (e) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + return 1; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_2_BYTES: + case GL_HALF_FLOAT: + return 2; + case GL_3_BYTES: + return 3; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + case GL_4_BYTES: + return 4; + default: + return 0; + } +} + +INTERNAL PURE FASTCALL GLint +__glFogfv_size(GLenum e) +{ + switch (e) { + case GL_FOG_INDEX: + case GL_FOG_DENSITY: + case GL_FOG_START: + case GL_FOG_END: + case GL_FOG_MODE: + case GL_FOG_OFFSET_VALUE_SGIX: + case GL_FOG_DISTANCE_MODE_NV: + return 1; + case GL_FOG_COLOR: + return 4; + default: + return 0; + } +} + +INTERNAL PURE FASTCALL GLint +__glLightfv_size(GLenum e) +{ + switch (e) { + case GL_SPOT_EXPONENT: + case GL_SPOT_CUTOFF: + case GL_CONSTANT_ATTENUATION: + case GL_LINEAR_ATTENUATION: + case GL_QUADRATIC_ATTENUATION: + return 1; + case GL_SPOT_DIRECTION: + return 3; + case GL_AMBIENT: + case GL_DIFFUSE: + case GL_SPECULAR: + case GL_POSITION: + return 4; + default: + return 0; + } +} + +INTERNAL PURE FASTCALL GLint +__glLightModelfv_size(GLenum e) +{ + switch (e) { + case GL_LIGHT_MODEL_LOCAL_VIEWER: + case GL_LIGHT_MODEL_TWO_SIDE: + case GL_LIGHT_MODEL_COLOR_CONTROL: +/* case GL_LIGHT_MODEL_COLOR_CONTROL_EXT:*/ + return 1; + case GL_LIGHT_MODEL_AMBIENT: + return 4; + default: + return 0; + } +} + +INTERNAL PURE FASTCALL GLint +__glMaterialfv_size(GLenum e) +{ + switch (e) { + case GL_SHININESS: + return 1; + case GL_COLOR_INDEXES: + return 3; + case GL_AMBIENT: + case GL_DIFFUSE: + case GL_SPECULAR: + case GL_EMISSION: + case GL_AMBIENT_AND_DIFFUSE: + return 4; + default: + return 0; + } +} + +INTERNAL PURE FASTCALL GLint +__glTexParameterfv_size(GLenum e) +{ + switch (e) { + case GL_TEXTURE_MAG_FILTER: + case GL_TEXTURE_MIN_FILTER: + case GL_TEXTURE_WRAP_S: + case GL_TEXTURE_WRAP_T: + case GL_TEXTURE_PRIORITY: + case GL_TEXTURE_WRAP_R: + case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB: +/* case GL_SHADOW_AMBIENT_SGIX:*/ + case GL_TEXTURE_MIN_LOD: + case GL_TEXTURE_MAX_LOD: + case GL_TEXTURE_BASE_LEVEL: + case GL_TEXTURE_MAX_LEVEL: + case GL_TEXTURE_CLIPMAP_FRAME_SGIX: + case GL_TEXTURE_LOD_BIAS_S_SGIX: + case GL_TEXTURE_LOD_BIAS_T_SGIX: + case GL_TEXTURE_LOD_BIAS_R_SGIX: + case GL_GENERATE_MIPMAP: +/* case GL_GENERATE_MIPMAP_SGIS:*/ + case GL_TEXTURE_COMPARE_SGIX: + case GL_TEXTURE_COMPARE_OPERATOR_SGIX: + case GL_TEXTURE_MAX_CLAMP_S_SGIX: + case GL_TEXTURE_MAX_CLAMP_T_SGIX: + case GL_TEXTURE_MAX_CLAMP_R_SGIX: + case GL_TEXTURE_MAX_ANISOTROPY_EXT: + case GL_TEXTURE_LOD_BIAS: +/* case GL_TEXTURE_LOD_BIAS_EXT:*/ + case GL_TEXTURE_STORAGE_HINT_APPLE: + case GL_STORAGE_PRIVATE_APPLE: + case GL_STORAGE_CACHED_APPLE: + case GL_STORAGE_SHARED_APPLE: + case GL_DEPTH_TEXTURE_MODE: +/* case GL_DEPTH_TEXTURE_MODE_ARB:*/ + case GL_TEXTURE_COMPARE_MODE: +/* case GL_TEXTURE_COMPARE_MODE_ARB:*/ + case GL_TEXTURE_COMPARE_FUNC: +/* case GL_TEXTURE_COMPARE_FUNC_ARB:*/ + case GL_TEXTURE_UNSIGNED_REMAP_MODE_NV: + return 1; + case GL_TEXTURE_CLIPMAP_CENTER_SGIX: + case GL_TEXTURE_CLIPMAP_OFFSET_SGIX: + return 2; + case GL_TEXTURE_CLIPMAP_VIRTUAL_DEPTH_SGIX: + return 3; + case GL_TEXTURE_BORDER_COLOR: + case GL_POST_TEXTURE_FILTER_BIAS_SGIX: + case GL_POST_TEXTURE_FILTER_SCALE_SGIX: + return 4; + default: + return 0; + } +} + +INTERNAL PURE FASTCALL GLint +__glTexEnvfv_size(GLenum e) +{ + switch (e) { + case GL_ALPHA_SCALE: + case GL_TEXTURE_ENV_MODE: + case GL_TEXTURE_LOD_BIAS: + case GL_COMBINE_RGB: + case GL_COMBINE_ALPHA: + case GL_RGB_SCALE: + case GL_SOURCE0_RGB: + case GL_SOURCE1_RGB: + case GL_SOURCE2_RGB: + case GL_SOURCE3_RGB_NV: + case GL_SOURCE0_ALPHA: + case GL_SOURCE1_ALPHA: + case GL_SOURCE2_ALPHA: + case GL_SOURCE3_ALPHA_NV: + case GL_OPERAND0_RGB: + case GL_OPERAND1_RGB: + case GL_OPERAND2_RGB: + case GL_OPERAND3_RGB_NV: + case GL_OPERAND0_ALPHA: + case GL_OPERAND1_ALPHA: + case GL_OPERAND2_ALPHA: + case GL_OPERAND3_ALPHA_NV: + case GL_BUMP_TARGET_ATI: + case GL_COORD_REPLACE_ARB: +/* case GL_COORD_REPLACE_NV:*/ + return 1; + case GL_TEXTURE_ENV_COLOR: + return 4; + default: + return 0; + } +} + +INTERNAL PURE FASTCALL GLint +__glTexGendv_size(GLenum e) +{ + switch (e) { + case GL_TEXTURE_GEN_MODE: + return 1; + case GL_OBJECT_PLANE: + case GL_EYE_PLANE: + return 4; + default: + return 0; + } +} + +INTERNAL PURE FASTCALL GLint +__glMap1d_size(GLenum e) +{ + switch (e) { + case GL_MAP1_INDEX: + case GL_MAP1_TEXTURE_COORD_1: + return 1; + case GL_MAP1_TEXTURE_COORD_2: + return 2; + case GL_MAP1_NORMAL: + case GL_MAP1_TEXTURE_COORD_3: + case GL_MAP1_VERTEX_3: + return 3; + case GL_MAP1_COLOR_4: + case GL_MAP1_TEXTURE_COORD_4: + case GL_MAP1_VERTEX_4: + return 4; + default: + return 0; + } +} + +INTERNAL PURE FASTCALL GLint +__glMap2d_size(GLenum e) +{ + switch (e) { + case GL_MAP2_INDEX: + case GL_MAP2_TEXTURE_COORD_1: + return 1; + case GL_MAP2_TEXTURE_COORD_2: + return 2; + case GL_MAP2_NORMAL: + case GL_MAP2_TEXTURE_COORD_3: + case GL_MAP2_VERTEX_3: + return 3; + case GL_MAP2_COLOR_4: + case GL_MAP2_TEXTURE_COORD_4: + case GL_MAP2_VERTEX_4: + return 4; + default: + return 0; + } +} + +INTERNAL PURE FASTCALL GLint +__glColorTableParameterfv_size(GLenum e) +{ + switch (e) { + case GL_COLOR_TABLE_SCALE: + case GL_COLOR_TABLE_BIAS: + return 4; + default: + return 0; + } +} + +INTERNAL PURE FASTCALL GLint +__glConvolutionParameterfv_size(GLenum e) +{ + switch (e) { + case GL_CONVOLUTION_BORDER_MODE: +/* case GL_CONVOLUTION_BORDER_MODE_EXT:*/ + return 1; + case GL_CONVOLUTION_FILTER_SCALE: +/* case GL_CONVOLUTION_FILTER_SCALE_EXT:*/ + case GL_CONVOLUTION_FILTER_BIAS: +/* case GL_CONVOLUTION_FILTER_BIAS_EXT:*/ + case GL_CONVOLUTION_BORDER_COLOR: +/* case GL_CONVOLUTION_BORDER_COLOR_HP:*/ + return 4; + default: + return 0; + } +} + +INTERNAL PURE FASTCALL GLint +__glPointParameterfvEXT_size(GLenum e) +{ + switch (e) { + case GL_POINT_SIZE_MIN: +/* case GL_POINT_SIZE_MIN_ARB:*/ +/* case GL_POINT_SIZE_MIN_SGIS:*/ + case GL_POINT_SIZE_MAX: +/* case GL_POINT_SIZE_MAX_ARB:*/ +/* case GL_POINT_SIZE_MAX_SGIS:*/ + case GL_POINT_FADE_THRESHOLD_SIZE: +/* case GL_POINT_FADE_THRESHOLD_SIZE_ARB:*/ +/* case GL_POINT_FADE_THRESHOLD_SIZE_SGIS:*/ + case GL_POINT_SPRITE_R_MODE_NV: + case GL_POINT_SPRITE_COORD_ORIGIN: + return 1; + case GL_POINT_DISTANCE_ATTENUATION: +/* case GL_POINT_DISTANCE_ATTENUATION_ARB:*/ +/* case GL_POINT_DISTANCE_ATTENUATION_SGIS:*/ + return 3; + default: + return 0; + } +} + +ALIAS(Fogiv, Fogfv) + ALIAS(Lightiv, Lightfv) + ALIAS(LightModeliv, LightModelfv) + ALIAS(Materialiv, Materialfv) + ALIAS(TexParameteriv, TexParameterfv) + ALIAS(TexEnviv, TexEnvfv) + ALIAS(TexGenfv, TexGendv) + ALIAS(TexGeniv, TexGendv) + ALIAS(Map1f, Map1d) + ALIAS(Map2f, Map2d) + ALIAS(ColorTableParameteriv, ColorTableParameterfv) + ALIAS(ConvolutionParameteriv, ConvolutionParameterfv) + ALIAS(PointParameterivNV, PointParameterfvEXT) +# undef PURE +# undef FASTCALL +# undef INTERNAL diff --git a/src/glx/indirect_size.h b/src/glx/indirect_size.h new file mode 100644 index 0000000..79b849b --- /dev/null +++ b/src/glx/indirect_size.h @@ -0,0 +1,88 @@ +/* DO NOT EDIT - This file generated automatically by glX_proto_size.py (from Mesa) script */ + +/* + * (C) Copyright IBM Corporation 2004 + * 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 + * IBM, + * 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. + */ + +#if !defined( _INDIRECT_SIZE_H_ ) +# define _INDIRECT_SIZE_H_ + +/** + * \file + * Prototypes for functions used to determine the number of data elements in + * various GLX protocol messages. + * + * \author Ian Romanick + */ + +# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define PURE __attribute__((pure)) +# else +# define PURE +# endif + +# if defined(__i386__) && defined(__GNUC__) && !defined(__CYGWIN__) && !defined(__MINGW32__) +# define FASTCALL __attribute__((fastcall)) +# else +# define FASTCALL +# endif + +# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) && defined(__ELF__) +# define INTERNAL __attribute__((visibility("internal"))) +# else +# define INTERNAL +# endif + +extern INTERNAL PURE FASTCALL GLint __glCallLists_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glFogfv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glFogiv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glLightfv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glLightiv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glLightModelfv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glLightModeliv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glMaterialfv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glMaterialiv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glTexParameterfv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glTexParameteriv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glTexEnvfv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glTexEnviv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glTexGendv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glTexGenfv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glTexGeniv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glMap1d_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glMap1f_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glMap2d_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glMap2f_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glColorTableParameterfv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glColorTableParameteriv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glConvolutionParameterfv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glConvolutionParameteriv_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glPointParameterfvEXT_size(GLenum); +extern INTERNAL PURE FASTCALL GLint __glPointParameterivNV_size(GLenum); + +# undef PURE +# undef FASTCALL +# undef INTERNAL + +#endif /* !defined( _INDIRECT_SIZE_H_ ) */ diff --git a/src/glx/indirect_texture_compression.c b/src/glx/indirect_texture_compression.c new file mode 100644 index 0000000..fa927eb --- /dev/null +++ b/src/glx/indirect_texture_compression.c @@ -0,0 +1,343 @@ +/* + * (C) Copyright IBM Corporation 2004 + * 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 + * 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 COPYRIGHT HOLDERS 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. + */ + +/** + * \file glx_texture_compression.c + * Contains the routines required to implement GLX protocol for + * ARB_texture_compression and related extensions. + * + * \sa http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_compression.txt + * + * \author Ian Romanick + */ + +#include "packrender.h" +#include "packsingle.h" +#include "indirect.h" + +#include + + +void +__indirect_glGetCompressedTexImageARB(GLenum target, GLint level, + GLvoid * img) +{ + __GLX_SINGLE_DECLARE_VARIABLES(); + xGLXGetTexImageReply reply; + size_t image_bytes; + + __GLX_SINGLE_LOAD_VARIABLES(); + __GLX_SINGLE_BEGIN(X_GLsop_GetCompressedTexImage, 8); + __GLX_SINGLE_PUT_LONG(0, target); + __GLX_SINGLE_PUT_LONG(4, level); + __GLX_SINGLE_READ_XREPLY(); + + image_bytes = reply.width; + assert(image_bytes <= ((4 * reply.length) - 0)); + assert(image_bytes >= ((4 * reply.length) - 3)); + + if (image_bytes != 0) { + _XRead(dpy, (char *) img, image_bytes); + if (image_bytes < (4 * reply.length)) { + _XEatData(dpy, (4 * reply.length) - image_bytes); + } + } + + __GLX_SINGLE_END(); +} + + +/** + * Internal function used for \c glCompressedTexImage1D and + * \c glCompressedTexImage2D. + */ +static void +CompressedTexImage1D2D(GLenum target, GLint level, + GLenum internal_format, + GLsizei width, GLsizei height, + GLint border, GLsizei image_size, + const GLvoid * data, CARD32 rop) +{ + __GLX_DECLARE_VARIABLES(); + + __GLX_LOAD_VARIABLES(); + if (gc->currentDpy == NULL) { + return; + } + + if ((target == GL_PROXY_TEXTURE_1D) + || (target == GL_PROXY_TEXTURE_2D) + || (target == GL_PROXY_TEXTURE_CUBE_MAP)) { + compsize = 0; + } + else { + compsize = image_size; + } + + cmdlen = __GLX_PAD(__GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE + compsize); + if (cmdlen <= gc->maxSmallRenderCommandSize) { + __GLX_BEGIN_VARIABLE(rop, cmdlen); + __GLX_PUT_LONG(4, target); + __GLX_PUT_LONG(8, level); + __GLX_PUT_LONG(12, internal_format); + __GLX_PUT_LONG(16, width); + __GLX_PUT_LONG(20, height); + __GLX_PUT_LONG(24, border); + __GLX_PUT_LONG(28, image_size); + if (compsize != 0) { + __GLX_PUT_CHAR_ARRAY(__GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE, + data, image_size); + } + __GLX_END(cmdlen); + } + else { + assert(compsize != 0); + + __GLX_BEGIN_VARIABLE_LARGE(rop, cmdlen + 4); + __GLX_PUT_LONG(8, target); + __GLX_PUT_LONG(12, level); + __GLX_PUT_LONG(16, internal_format); + __GLX_PUT_LONG(20, width); + __GLX_PUT_LONG(24, height); + __GLX_PUT_LONG(28, border); + __GLX_PUT_LONG(32, image_size); + __glXSendLargeCommand(gc, gc->pc, + __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE + 4, + data, image_size); + } +} + + +/** + * Internal function used for \c glCompressedTexSubImage1D and + * \c glCompressedTexSubImage2D. + */ +static void +CompressedTexSubImage1D2D(GLenum target, GLint level, + GLsizei xoffset, GLsizei yoffset, + GLsizei width, GLsizei height, + GLenum format, GLsizei image_size, + const GLvoid * data, CARD32 rop) +{ + __GLX_DECLARE_VARIABLES(); + + __GLX_LOAD_VARIABLES(); + if (gc->currentDpy == NULL) { + return; + } + + if (target == GL_PROXY_TEXTURE_3D) { + compsize = 0; + } + else { + compsize = image_size; + } + + cmdlen = __GLX_PAD(__GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE + compsize); + if (cmdlen <= gc->maxSmallRenderCommandSize) { + __GLX_BEGIN_VARIABLE(rop, cmdlen); + __GLX_PUT_LONG(4, target); + __GLX_PUT_LONG(8, level); + __GLX_PUT_LONG(12, xoffset); + __GLX_PUT_LONG(16, yoffset); + __GLX_PUT_LONG(20, width); + __GLX_PUT_LONG(24, height); + __GLX_PUT_LONG(28, format); + __GLX_PUT_LONG(32, image_size); + if (compsize != 0) { + __GLX_PUT_CHAR_ARRAY(__GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE, + data, image_size); + } + __GLX_END(cmdlen); + } + else { + assert(compsize != 0); + + __GLX_BEGIN_VARIABLE_LARGE(rop, cmdlen + 4); + __GLX_PUT_LONG(8, target); + __GLX_PUT_LONG(12, level); + __GLX_PUT_LONG(16, xoffset); + __GLX_PUT_LONG(20, yoffset); + __GLX_PUT_LONG(24, width); + __GLX_PUT_LONG(28, height); + __GLX_PUT_LONG(32, format); + __GLX_PUT_LONG(36, image_size); + __glXSendLargeCommand(gc, gc->pc, + __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE + 4, + data, image_size); + } +} + + +void +__indirect_glCompressedTexImage1DARB(GLenum target, GLint level, + GLenum internal_format, GLsizei width, + GLint border, GLsizei image_size, + const GLvoid * data) +{ + CompressedTexImage1D2D(target, level, internal_format, width, 0, + border, image_size, data, + X_GLrop_CompressedTexImage1D); +} + + +void +__indirect_glCompressedTexImage2DARB(GLenum target, GLint level, + GLenum internal_format, + GLsizei width, GLsizei height, + GLint border, GLsizei image_size, + const GLvoid * data) +{ + CompressedTexImage1D2D(target, level, internal_format, width, height, + border, image_size, data, + X_GLrop_CompressedTexImage2D); +} + + +void +__indirect_glCompressedTexImage3DARB(GLenum target, GLint level, + GLenum internal_format, + GLsizei width, GLsizei height, + GLsizei depth, GLint border, + GLsizei image_size, const GLvoid * data) +{ + __GLX_DECLARE_VARIABLES(); + + __GLX_LOAD_VARIABLES(); + if (gc->currentDpy == NULL) { + return; + } + + cmdlen = __GLX_PAD(__GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE + image_size); + if (cmdlen <= gc->maxSmallRenderCommandSize) { + __GLX_BEGIN_VARIABLE(X_GLrop_CompressedTexImage3D, cmdlen); + __GLX_PUT_LONG(4, target); + __GLX_PUT_LONG(8, level); + __GLX_PUT_LONG(12, internal_format); + __GLX_PUT_LONG(16, width); + __GLX_PUT_LONG(20, height); + __GLX_PUT_LONG(24, depth); + __GLX_PUT_LONG(28, border); + __GLX_PUT_LONG(32, image_size); + if (image_size != 0) { + __GLX_PUT_CHAR_ARRAY(__GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE, + data, image_size); + } + __GLX_END(cmdlen); + } + else { + __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_CompressedTexImage3D, cmdlen + 4); + __GLX_PUT_LONG(8, target); + __GLX_PUT_LONG(12, level); + __GLX_PUT_LONG(16, internal_format); + __GLX_PUT_LONG(20, width); + __GLX_PUT_LONG(24, height); + __GLX_PUT_LONG(28, depth); + __GLX_PUT_LONG(32, border); + __GLX_PUT_LONG(36, image_size); + __glXSendLargeCommand(gc, gc->pc, + __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE + 4, + data, image_size); + } +} + + +void +__indirect_glCompressedTexSubImage1DARB(GLenum target, GLint level, + GLint xoffset, + GLsizei width, + GLenum format, GLsizei image_size, + const GLvoid * data) +{ + CompressedTexSubImage1D2D(target, level, xoffset, 0, width, 0, + format, image_size, data, + X_GLrop_CompressedTexSubImage1D); +} + + +void +__indirect_glCompressedTexSubImage2DARB(GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLsizei image_size, + const GLvoid * data) +{ + CompressedTexSubImage1D2D(target, level, xoffset, yoffset, width, height, + format, image_size, data, + X_GLrop_CompressedTexSubImage2D); +} + + +void +__indirect_glCompressedTexSubImage3DARB(GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint zoffset, GLsizei width, + GLsizei height, GLsizei depth, + GLenum format, GLsizei image_size, + const GLvoid * data) +{ + __GLX_DECLARE_VARIABLES(); + + __GLX_LOAD_VARIABLES(); + if (gc->currentDpy == NULL) { + return; + } + + cmdlen = __GLX_PAD(__GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE + + image_size); + if (cmdlen <= gc->maxSmallRenderCommandSize) { + __GLX_BEGIN_VARIABLE(X_GLrop_CompressedTexSubImage3D, cmdlen); + __GLX_PUT_LONG(4, target); + __GLX_PUT_LONG(8, level); + __GLX_PUT_LONG(12, xoffset); + __GLX_PUT_LONG(16, yoffset); + __GLX_PUT_LONG(20, zoffset); + __GLX_PUT_LONG(24, width); + __GLX_PUT_LONG(28, height); + __GLX_PUT_LONG(32, depth); + __GLX_PUT_LONG(36, format); + __GLX_PUT_LONG(40, image_size); + if (image_size != 0) { + __GLX_PUT_CHAR_ARRAY(__GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE, + data, image_size); + } + __GLX_END(cmdlen); + } + else { + __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_CompressedTexSubImage3D, cmdlen + 4); + __GLX_PUT_LONG(8, target); + __GLX_PUT_LONG(12, level); + __GLX_PUT_LONG(16, xoffset); + __GLX_PUT_LONG(20, yoffset); + __GLX_PUT_LONG(24, zoffset); + __GLX_PUT_LONG(28, width); + __GLX_PUT_LONG(32, height); + __GLX_PUT_LONG(36, depth); + __GLX_PUT_LONG(40, format); + __GLX_PUT_LONG(44, image_size); + __glXSendLargeCommand(gc, gc->pc, + __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE + 4, + data, image_size); + } +} diff --git a/src/glx/indirect_transpose_matrix.c b/src/glx/indirect_transpose_matrix.c new file mode 100644 index 0000000..618db9f --- /dev/null +++ b/src/glx/indirect_transpose_matrix.c @@ -0,0 +1,85 @@ +/* + * (C) Copyright IBM Corporation 2004 + * 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 + * 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 COPYRIGHT HOLDERS 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 +#include "indirect.h" + +static void +TransposeMatrixf(const GLfloat s[16], GLfloat d[16]) +{ + int i, j; + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + d[i * 4 + j] = s[j * 4 + i]; + } + } +} + +static void +TransposeMatrixd(const GLdouble s[16], GLdouble d[16]) +{ + int i, j; + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + d[i * 4 + j] = s[j * 4 + i]; + } + } +} + + +void +__indirect_glLoadTransposeMatrixdARB(const GLdouble * m) +{ + GLdouble mt[16]; + + TransposeMatrixd(m, mt); + __indirect_glLoadMatrixd(mt); +} + +void +__indirect_glLoadTransposeMatrixfARB(const GLfloat * m) +{ + GLfloat mt[16]; + + TransposeMatrixf(m, mt); + __indirect_glLoadMatrixf(mt); +} + +void +__indirect_glMultTransposeMatrixdARB(const GLdouble * m) +{ + GLdouble mt[16]; + + TransposeMatrixd(m, mt); + __indirect_glMultMatrixd(mt); +} + +void +__indirect_glMultTransposeMatrixfARB(const GLfloat * m) +{ + GLfloat mt[16]; + + TransposeMatrixf(m, mt); + __indirect_glMultMatrixf(mt); +} diff --git a/src/glx/indirect_vertex_array.c b/src/glx/indirect_vertex_array.c new file mode 100644 index 0000000..115f755 --- /dev/null +++ b/src/glx/indirect_vertex_array.c @@ -0,0 +1,1986 @@ +/* + * (C) Copyright IBM Corporation 2004, 2005 + * 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 + * IBM, + * 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 +#include +#include + +#include "glxclient.h" +#include "indirect.h" +#include +#include "glxextensions.h" +#include "indirect_vertex_array.h" +#include "indirect_vertex_array_priv.h" + +#define __GLX_PAD(n) (((n)+3) & ~3) + +/** + * \file indirect_vertex_array.c + * Implement GLX protocol for vertex arrays and vertex buffer objects. + * + * The most important function in this fill is \c fill_array_info_cache. + * The \c array_state_vector contains a cache of the ARRAY_INFO data sent + * in the DrawArrays protocol. Certain operations, such as enabling or + * disabling an array, can invalidate this cache. \c fill_array_info_cache + * fills-in this data. Additionally, it examines the enabled state and + * other factors to determine what "version" of DrawArrays protocoal can be + * used. + * + * Current, only two versions of DrawArrays protocol are implemented. The + * first version is the "none" protocol. This is the fallback when the + * server does not support GL 1.1 / EXT_vertex_arrays. It is implemented + * by sending batches of immediate mode commands that are equivalent to the + * DrawArrays protocol. + * + * The other protocol that is currently implemented is the "old" protocol. + * This is the GL 1.1 DrawArrays protocol. The only difference between GL + * 1.1 and EXT_vertex_arrays is the opcode used for the DrawArrays command. + * This protocol is called "old" because the ARB is in the process of + * defining a new protocol, which will probably be called wither "new" or + * "vbo", to support multiple texture coordinate arrays, generic attributes, + * and vertex buffer objects. + * + * \author Ian Romanick + */ + +static void emit_DrawArrays_none(GLenum mode, GLint first, GLsizei count); +static void emit_DrawArrays_old(GLenum mode, GLint first, GLsizei count); + +static void emit_DrawElements_none(GLenum mode, GLsizei count, GLenum type, + const GLvoid * indices); +static void emit_DrawElements_old(GLenum mode, GLsizei count, GLenum type, + const GLvoid * indices); + + +static GLubyte *emit_element_none(GLubyte * dst, + const struct array_state_vector *arrays, + unsigned index); +static GLubyte *emit_element_old(GLubyte * dst, + const struct array_state_vector *arrays, + unsigned index); +static struct array_state *get_array_entry(const struct array_state_vector + *arrays, GLenum key, + unsigned index); +static void fill_array_info_cache(struct array_state_vector *arrays); +static GLboolean validate_mode(struct glx_context * gc, GLenum mode); +static GLboolean validate_count(struct glx_context * gc, GLsizei count); +static GLboolean validate_type(struct glx_context * gc, GLenum type); + + +/** + * Table of sizes, in bytes, of a GL types. All of the type enums are be in + * the range 0x1400 - 0x140F. That includes types added by extensions (i.e., + * \c GL_HALF_FLOAT_NV). This elements of this table correspond to the + * type enums masked with 0x0f. + * + * \notes + * \c GL_HALF_FLOAT_NV is not included. Neither are \c GL_2_BYTES, + * \c GL_3_BYTES, or \c GL_4_BYTES. + */ +const GLuint __glXTypeSize_table[16] = { + 1, 1, 2, 2, 4, 4, 4, 0, 0, 0, 8, 0, 0, 0, 0, 0 +}; + + +/** + * Free the per-context array state that was allocated with + * __glXInitVertexArrayState(). + */ +void +__glXFreeVertexArrayState(struct glx_context * gc) +{ + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + + if (arrays) { + if (arrays->stack) { + free(arrays->stack); + arrays->stack = NULL; + } + if (arrays->arrays) { + free(arrays->arrays); + arrays->arrays = NULL; + } + free(arrays); + state->array_state = NULL; + } +} + + +/** + * Initialize vertex array state of a GLX context. + * + * \param gc GLX context whose vertex array state is to be initialized. + * + * \warning + * This function may only be called after struct glx_context::gl_extension_bits, + * struct glx_context::server_minor, and __GLXcontext::server_major have been + * initialized. These values are used to determine what vertex arrays are + * supported. + * + * \bug + * Return values from malloc are not properly tested. + */ +void +__glXInitVertexArrayState(struct glx_context * gc) +{ + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays; + + unsigned array_count; + int texture_units = 1, vertex_program_attribs = 0; + unsigned i, j; + + GLboolean got_fog = GL_FALSE; + GLboolean got_secondary_color = GL_FALSE; + + + arrays = calloc(1, sizeof(struct array_state_vector)); + state->array_state = arrays; + + arrays->old_DrawArrays_possible = !state->NoDrawArraysProtocol; + arrays->new_DrawArrays_possible = GL_FALSE; + arrays->DrawArrays = NULL; + + arrays->active_texture_unit = 0; + + + /* Determine how many arrays are actually needed. Only arrays that + * are supported by the server are create. For example, if the server + * supports only 2 texture units, then only 2 texture coordinate arrays + * are created. + * + * At the very least, GL_VERTEX_ARRAY, GL_NORMAL_ARRAY, + * GL_COLOR_ARRAY, GL_INDEX_ARRAY, GL_TEXTURE_COORD_ARRAY, and + * GL_EDGE_FLAG_ARRAY are supported. + */ + + array_count = 5; + + if (__glExtensionBitIsEnabled(gc, GL_EXT_fog_coord_bit) + || (gc->server_major > 1) || (gc->server_minor >= 4)) { + got_fog = GL_TRUE; + array_count++; + } + + if (__glExtensionBitIsEnabled(gc, GL_EXT_secondary_color_bit) + || (gc->server_major > 1) || (gc->server_minor >= 4)) { + got_secondary_color = GL_TRUE; + array_count++; + } + + if (__glExtensionBitIsEnabled(gc, GL_ARB_multitexture_bit) + || (gc->server_major > 1) || (gc->server_minor >= 3)) { + __indirect_glGetIntegerv(GL_MAX_TEXTURE_UNITS, &texture_units); + } + + if (__glExtensionBitIsEnabled(gc, GL_ARB_vertex_program_bit)) { + __indirect_glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, + GL_MAX_PROGRAM_ATTRIBS_ARB, + &vertex_program_attribs); + } + + arrays->num_texture_units = texture_units; + arrays->num_vertex_program_attribs = vertex_program_attribs; + array_count += texture_units + vertex_program_attribs; + arrays->num_arrays = array_count; + arrays->arrays = calloc(array_count, sizeof(struct array_state)); + + arrays->arrays[0].data_type = GL_FLOAT; + arrays->arrays[0].count = 3; + arrays->arrays[0].key = GL_NORMAL_ARRAY; + arrays->arrays[0].normalized = GL_TRUE; + arrays->arrays[0].old_DrawArrays_possible = GL_TRUE; + + arrays->arrays[1].data_type = GL_FLOAT; + arrays->arrays[1].count = 4; + arrays->arrays[1].key = GL_COLOR_ARRAY; + arrays->arrays[1].normalized = GL_TRUE; + arrays->arrays[1].old_DrawArrays_possible = GL_TRUE; + + arrays->arrays[2].data_type = GL_FLOAT; + arrays->arrays[2].count = 1; + arrays->arrays[2].key = GL_INDEX_ARRAY; + arrays->arrays[2].old_DrawArrays_possible = GL_TRUE; + + arrays->arrays[3].data_type = GL_UNSIGNED_BYTE; + arrays->arrays[3].count = 1; + arrays->arrays[3].key = GL_EDGE_FLAG_ARRAY; + arrays->arrays[3].old_DrawArrays_possible = GL_TRUE; + + for (i = 0; i < texture_units; i++) { + arrays->arrays[4 + i].data_type = GL_FLOAT; + arrays->arrays[4 + i].count = 4; + arrays->arrays[4 + i].key = GL_TEXTURE_COORD_ARRAY; + + arrays->arrays[4 + i].old_DrawArrays_possible = (i == 0); + arrays->arrays[4 + i].index = i; + + arrays->arrays[4 + i].header[1] = i + GL_TEXTURE0; + } + + i = 4 + texture_units; + + if (got_fog) { + arrays->arrays[i].data_type = GL_FLOAT; + arrays->arrays[i].count = 1; + arrays->arrays[i].key = GL_FOG_COORDINATE_ARRAY; + arrays->arrays[i].old_DrawArrays_possible = GL_TRUE; + i++; + } + + if (got_secondary_color) { + arrays->arrays[i].data_type = GL_FLOAT; + arrays->arrays[i].count = 3; + arrays->arrays[i].key = GL_SECONDARY_COLOR_ARRAY; + arrays->arrays[i].old_DrawArrays_possible = GL_TRUE; + arrays->arrays[i].normalized = GL_TRUE; + i++; + } + + + for (j = 0; j < vertex_program_attribs; j++) { + const unsigned idx = (vertex_program_attribs - (j + 1)); + + + arrays->arrays[idx + i].data_type = GL_FLOAT; + arrays->arrays[idx + i].count = 4; + arrays->arrays[idx + i].key = GL_VERTEX_ATTRIB_ARRAY_POINTER; + + arrays->arrays[idx + i].old_DrawArrays_possible = 0; + arrays->arrays[idx + i].index = idx; + + arrays->arrays[idx + i].header[1] = idx; + } + + i += vertex_program_attribs; + + + /* Vertex array *must* be last becuase of the way that + * emit_DrawArrays_none works. + */ + + arrays->arrays[i].data_type = GL_FLOAT; + arrays->arrays[i].count = 4; + arrays->arrays[i].key = GL_VERTEX_ARRAY; + arrays->arrays[i].old_DrawArrays_possible = GL_TRUE; + + assert((i + 1) == arrays->num_arrays); + + arrays->stack_index = 0; + arrays->stack = malloc(sizeof(struct array_stack_state) + * arrays->num_arrays + * __GL_CLIENT_ATTRIB_STACK_DEPTH); +} + + +/** + * Calculate the size of a single vertex for the "none" protocol. This is + * essentially the size of all the immediate-mode commands required to + * implement the enabled vertex arrays. + */ +static size_t +calculate_single_vertex_size_none(const struct array_state_vector *arrays) +{ + size_t single_vertex_size = 0; + unsigned i; + + + for (i = 0; i < arrays->num_arrays; i++) { + if (arrays->arrays[i].enabled) { + single_vertex_size += ((uint16_t *) arrays->arrays[i].header)[0]; + } + } + + return single_vertex_size; +} + + +/** + * Emit a single element using non-DrawArrays protocol. + */ +GLubyte * +emit_element_none(GLubyte * dst, + const struct array_state_vector * arrays, unsigned index) +{ + unsigned i; + + + for (i = 0; i < arrays->num_arrays; i++) { + if (arrays->arrays[i].enabled) { + const size_t offset = index * arrays->arrays[i].true_stride; + + /* The generic attributes can have more data than is in the + * elements. This is because a vertex array can be a 2 element, + * normalized, unsigned short, but the "closest" immediate mode + * protocol is for a 4Nus. Since the sizes are small, the + * performance impact on modern processors should be negligible. + */ + (void) memset(dst, 0, ((uint16_t *) arrays->arrays[i].header)[0]); + + (void) memcpy(dst, arrays->arrays[i].header, + arrays->arrays[i].header_size); + + dst += arrays->arrays[i].header_size; + + (void) memcpy(dst, ((GLubyte *) arrays->arrays[i].data) + offset, + arrays->arrays[i].element_size); + + dst += __GLX_PAD(arrays->arrays[i].element_size); + } + } + + return dst; +} + + +/** + * Emit a single element using "old" DrawArrays protocol from + * EXT_vertex_arrays / OpenGL 1.1. + */ +GLubyte * +emit_element_old(GLubyte * dst, + const struct array_state_vector * arrays, unsigned index) +{ + unsigned i; + + + for (i = 0; i < arrays->num_arrays; i++) { + if (arrays->arrays[i].enabled) { + const size_t offset = index * arrays->arrays[i].true_stride; + + (void) memcpy(dst, ((GLubyte *) arrays->arrays[i].data) + offset, + arrays->arrays[i].element_size); + + dst += __GLX_PAD(arrays->arrays[i].element_size); + } + } + + return dst; +} + + +struct array_state * +get_array_entry(const struct array_state_vector *arrays, + GLenum key, unsigned index) +{ + unsigned i; + + for (i = 0; i < arrays->num_arrays; i++) { + if ((arrays->arrays[i].key == key) + && (arrays->arrays[i].index == index)) { + return &arrays->arrays[i]; + } + } + + return NULL; +} + + +static GLboolean +allocate_array_info_cache(struct array_state_vector *arrays, + size_t required_size) +{ +#define MAX_HEADER_SIZE 20 + if (arrays->array_info_cache_buffer_size < required_size) { + GLubyte *temp = realloc(arrays->array_info_cache_base, + required_size + MAX_HEADER_SIZE); + + if (temp == NULL) { + return GL_FALSE; + } + + arrays->array_info_cache_base = temp; + arrays->array_info_cache = temp + MAX_HEADER_SIZE; + arrays->array_info_cache_buffer_size = required_size; + } + + arrays->array_info_cache_size = required_size; + return GL_TRUE; +} + + +/** + */ +void +fill_array_info_cache(struct array_state_vector *arrays) +{ + GLboolean old_DrawArrays_possible; + unsigned i; + + + /* Determine how many arrays are enabled. + */ + + arrays->enabled_client_array_count = 0; + old_DrawArrays_possible = arrays->old_DrawArrays_possible; + for (i = 0; i < arrays->num_arrays; i++) { + if (arrays->arrays[i].enabled) { + arrays->enabled_client_array_count++; + old_DrawArrays_possible &= arrays->arrays[i].old_DrawArrays_possible; + } + } + + if (arrays->new_DrawArrays_possible) { + assert(!arrays->new_DrawArrays_possible); + } + else if (old_DrawArrays_possible) { + const size_t required_size = arrays->enabled_client_array_count * 12; + uint32_t *info; + + + if (!allocate_array_info_cache(arrays, required_size)) { + return; + } + + + info = (uint32_t *) arrays->array_info_cache; + for (i = 0; i < arrays->num_arrays; i++) { + if (arrays->arrays[i].enabled) { + *(info++) = arrays->arrays[i].data_type; + *(info++) = arrays->arrays[i].count; + *(info++) = arrays->arrays[i].key; + } + } + + arrays->DrawArrays = emit_DrawArrays_old; + arrays->DrawElements = emit_DrawElements_old; + } + else { + arrays->DrawArrays = emit_DrawArrays_none; + arrays->DrawElements = emit_DrawElements_none; + } + + arrays->array_info_cache_valid = GL_TRUE; +} + + +/** + * Emit a \c glDrawArrays command using the "none" protocol. That is, + * emit immediate-mode commands that are equivalent to the requiested + * \c glDrawArrays command. This is used with servers that don't support + * the OpenGL 1.1 / EXT_vertex_arrays DrawArrays protocol or in cases where + * vertex state is enabled that is not compatible with that protocol. + */ +void +emit_DrawArrays_none(GLenum mode, GLint first, GLsizei count) +{ + struct glx_context *gc = __glXGetCurrentContext(); + const __GLXattribute *state = + (const __GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + + size_t single_vertex_size; + GLubyte *pc; + unsigned i; + static const uint16_t begin_cmd[2] = { 8, X_GLrop_Begin }; + static const uint16_t end_cmd[2] = { 4, X_GLrop_End }; + + + single_vertex_size = calculate_single_vertex_size_none(arrays); + + pc = gc->pc; + + (void) memcpy(pc, begin_cmd, 4); + *(int *) (pc + 4) = mode; + + pc += 8; + + for (i = 0; i < count; i++) { + if ((pc + single_vertex_size) >= gc->bufEnd) { + pc = __glXFlushRenderBuffer(gc, pc); + } + + pc = emit_element_none(pc, arrays, first + i); + } + + if ((pc + 4) >= gc->bufEnd) { + pc = __glXFlushRenderBuffer(gc, pc); + } + + (void) memcpy(pc, end_cmd, 4); + pc += 4; + + gc->pc = pc; + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + + +/** + * Emit the header data for the GL 1.1 / EXT_vertex_arrays DrawArrays + * protocol. + * + * \param gc GLX context. + * \param arrays Array state. + * \param elements_per_request Location to store the number of elements that + * can fit in a single Render / RenderLarge + * command. + * \param total_request Total number of requests for a RenderLarge + * command. If a Render command is used, this + * will be zero. + * \param mode Drawing mode. + * \param count Number of vertices. + * + * \returns + * A pointer to the buffer for array data. + */ +static GLubyte * +emit_DrawArrays_header_old(struct glx_context * gc, + struct array_state_vector *arrays, + size_t * elements_per_request, + unsigned int *total_requests, + GLenum mode, GLsizei count) +{ + size_t command_size; + size_t single_vertex_size; + const unsigned header_size = 16; + unsigned i; + GLubyte *pc; + + + /* Determine the size of the whole command. This includes the header, + * the ARRAY_INFO data and the array data. Once this size is calculated, + * it will be known whether a Render or RenderLarge command is needed. + */ + + single_vertex_size = 0; + for (i = 0; i < arrays->num_arrays; i++) { + if (arrays->arrays[i].enabled) { + single_vertex_size += __GLX_PAD(arrays->arrays[i].element_size); + } + } + + command_size = arrays->array_info_cache_size + header_size + + (single_vertex_size * count); + + + /* Write the header for either a Render command or a RenderLarge + * command. After the header is written, write the ARRAY_INFO data. + */ + + if (command_size > gc->maxSmallRenderCommandSize) { + /* maxSize is the maximum amount of data can be stuffed into a single + * packet. sz_xGLXRenderReq is added because bufSize is the maximum + * packet size minus sz_xGLXRenderReq. + */ + const size_t maxSize = (gc->bufSize + sz_xGLXRenderReq) + - sz_xGLXRenderLargeReq; + unsigned vertex_requests; + + + /* Calculate the number of data packets that will be required to send + * the whole command. To do this, the number of verticies that + * will fit in a single buffer must be calculated. + * + * The important value here is elements_per_request. This is the + * number of complete array elements that will fit in a single + * buffer. There may be some wasted space at the end of the buffer, + * but splitting elements across buffer boundries would be painful. + */ + + elements_per_request[0] = maxSize / single_vertex_size; + + vertex_requests = (count + elements_per_request[0] - 1) + / elements_per_request[0]; + + *total_requests = vertex_requests + 1; + + + __glXFlushRenderBuffer(gc, gc->pc); + + command_size += 4; + + pc = ((GLubyte *) arrays->array_info_cache) - (header_size + 4); + *(uint32_t *) (pc + 0) = command_size; + *(uint32_t *) (pc + 4) = X_GLrop_DrawArrays; + *(uint32_t *) (pc + 8) = count; + *(uint32_t *) (pc + 12) = arrays->enabled_client_array_count; + *(uint32_t *) (pc + 16) = mode; + + __glXSendLargeChunk(gc, 1, *total_requests, pc, + header_size + 4 + arrays->array_info_cache_size); + + pc = gc->pc; + } + else { + if ((gc->pc + command_size) >= gc->bufEnd) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + + pc = gc->pc; + *(uint16_t *) (pc + 0) = command_size; + *(uint16_t *) (pc + 2) = X_GLrop_DrawArrays; + *(uint32_t *) (pc + 4) = count; + *(uint32_t *) (pc + 8) = arrays->enabled_client_array_count; + *(uint32_t *) (pc + 12) = mode; + + pc += header_size; + + (void) memcpy(pc, arrays->array_info_cache, + arrays->array_info_cache_size); + pc += arrays->array_info_cache_size; + + *elements_per_request = count; + *total_requests = 0; + } + + + return pc; +} + + +/** + */ +void +emit_DrawArrays_old(GLenum mode, GLint first, GLsizei count) +{ + struct glx_context *gc = __glXGetCurrentContext(); + const __GLXattribute *state = + (const __GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + + GLubyte *pc; + size_t elements_per_request; + unsigned total_requests = 0; + unsigned i; + size_t total_sent = 0; + + + pc = emit_DrawArrays_header_old(gc, arrays, &elements_per_request, + &total_requests, mode, count); + + + /* Write the arrays. + */ + + if (total_requests == 0) { + assert(elements_per_request >= count); + + for (i = 0; i < count; i++) { + pc = emit_element_old(pc, arrays, i + first); + } + + assert(pc <= gc->bufEnd); + + gc->pc = pc; + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } + else { + unsigned req; + + + for (req = 2; req <= total_requests; req++) { + if (count < elements_per_request) { + elements_per_request = count; + } + + pc = gc->pc; + for (i = 0; i < elements_per_request; i++) { + pc = emit_element_old(pc, arrays, i + first); + } + + first += elements_per_request; + + total_sent += (size_t) (pc - gc->pc); + __glXSendLargeChunk(gc, req, total_requests, gc->pc, pc - gc->pc); + + count -= elements_per_request; + } + } +} + + +void +emit_DrawElements_none(GLenum mode, GLsizei count, GLenum type, + const GLvoid * indices) +{ + struct glx_context *gc = __glXGetCurrentContext(); + const __GLXattribute *state = + (const __GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + static const uint16_t begin_cmd[2] = { 8, X_GLrop_Begin }; + static const uint16_t end_cmd[2] = { 4, X_GLrop_End }; + + GLubyte *pc; + size_t single_vertex_size; + unsigned i; + + + single_vertex_size = calculate_single_vertex_size_none(arrays); + + + if ((gc->pc + single_vertex_size) >= gc->bufEnd) { + gc->pc = __glXFlushRenderBuffer(gc, gc->pc); + } + + pc = gc->pc; + + (void) memcpy(pc, begin_cmd, 4); + *(int *) (pc + 4) = mode; + + pc += 8; + + for (i = 0; i < count; i++) { + unsigned index = 0; + + if ((pc + single_vertex_size) >= gc->bufEnd) { + pc = __glXFlushRenderBuffer(gc, pc); + } + + switch (type) { + case GL_UNSIGNED_INT: + index = (unsigned) (((GLuint *) indices)[i]); + break; + case GL_UNSIGNED_SHORT: + index = (unsigned) (((GLushort *) indices)[i]); + break; + case GL_UNSIGNED_BYTE: + index = (unsigned) (((GLubyte *) indices)[i]); + break; + } + pc = emit_element_none(pc, arrays, index); + } + + if ((pc + 4) >= gc->bufEnd) { + pc = __glXFlushRenderBuffer(gc, pc); + } + + (void) memcpy(pc, end_cmd, 4); + pc += 4; + + gc->pc = pc; + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + + +/** + */ +void +emit_DrawElements_old(GLenum mode, GLsizei count, GLenum type, + const GLvoid * indices) +{ + struct glx_context *gc = __glXGetCurrentContext(); + const __GLXattribute *state = + (const __GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + + GLubyte *pc; + size_t elements_per_request; + unsigned total_requests = 0; + unsigned i; + unsigned req; + unsigned req_element = 0; + + + pc = emit_DrawArrays_header_old(gc, arrays, &elements_per_request, + &total_requests, mode, count); + + + /* Write the arrays. + */ + + req = 2; + while (count > 0) { + if (count < elements_per_request) { + elements_per_request = count; + } + + switch (type) { + case GL_UNSIGNED_INT:{ + const GLuint *ui_ptr = (const GLuint *) indices + req_element; + + for (i = 0; i < elements_per_request; i++) { + const GLint index = (GLint) * (ui_ptr++); + pc = emit_element_old(pc, arrays, index); + } + break; + } + case GL_UNSIGNED_SHORT:{ + const GLushort *us_ptr = (const GLushort *) indices + req_element; + + for (i = 0; i < elements_per_request; i++) { + const GLint index = (GLint) * (us_ptr++); + pc = emit_element_old(pc, arrays, index); + } + break; + } + case GL_UNSIGNED_BYTE:{ + const GLubyte *ub_ptr = (const GLubyte *) indices + req_element; + + for (i = 0; i < elements_per_request; i++) { + const GLint index = (GLint) * (ub_ptr++); + pc = emit_element_old(pc, arrays, index); + } + break; + } + } + + if (total_requests != 0) { + __glXSendLargeChunk(gc, req, total_requests, gc->pc, pc - gc->pc); + pc = gc->pc; + req++; + } + + count -= elements_per_request; + req_element += elements_per_request; + } + + + assert((total_requests == 0) || ((req - 1) == total_requests)); + + if (total_requests == 0) { + assert(pc <= gc->bufEnd); + + gc->pc = pc; + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } + } +} + + +/** + * Validate that the \c mode parameter to \c glDrawArrays, et. al. is valid. + * If it is not valid, then an error code is set in the GLX context. + * + * \returns + * \c GL_TRUE if the argument is valid, \c GL_FALSE if is not. + */ +static GLboolean +validate_mode(struct glx_context * gc, GLenum mode) +{ + switch (mode) { + case GL_POINTS: + case GL_LINE_STRIP: + case GL_LINE_LOOP: + case GL_LINES: + case GL_TRIANGLE_STRIP: + case GL_TRIANGLE_FAN: + case GL_TRIANGLES: + case GL_QUAD_STRIP: + case GL_QUADS: + case GL_POLYGON: + break; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return GL_FALSE; + } + + return GL_TRUE; +} + + +/** + * Validate that the \c count parameter to \c glDrawArrays, et. al. is valid. + * A value less than zero is invalid and will result in \c GL_INVALID_VALUE + * being set. A value of zero will not result in an error being set, but + * will result in \c GL_FALSE being returned. + * + * \returns + * \c GL_TRUE if the argument is valid, \c GL_FALSE if it is not. + */ +static GLboolean +validate_count(struct glx_context * gc, GLsizei count) +{ + if (count < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + } + + return (count > 0); +} + + +/** + * Validate that the \c type parameter to \c glDrawElements, et. al. is + * valid. Only \c GL_UNSIGNED_BYTE, \c GL_UNSIGNED_SHORT, and + * \c GL_UNSIGNED_INT are valid. + * + * \returns + * \c GL_TRUE if the argument is valid, \c GL_FALSE if it is not. + */ +static GLboolean +validate_type(struct glx_context * gc, GLenum type) +{ + switch (type) { + case GL_UNSIGNED_INT: + case GL_UNSIGNED_SHORT: + case GL_UNSIGNED_BYTE: + return GL_TRUE; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return GL_FALSE; + } +} + + +void +__indirect_glDrawArrays(GLenum mode, GLint first, GLsizei count) +{ + struct glx_context *gc = __glXGetCurrentContext(); + const __GLXattribute *state = + (const __GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + + + if (validate_mode(gc, mode) && validate_count(gc, count)) { + if (!arrays->array_info_cache_valid) { + fill_array_info_cache(arrays); + } + + arrays->DrawArrays(mode, first, count); + } +} + + +void +__indirect_glArrayElement(GLint index) +{ + struct glx_context *gc = __glXGetCurrentContext(); + const __GLXattribute *state = + (const __GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + + size_t single_vertex_size; + + + single_vertex_size = calculate_single_vertex_size_none(arrays); + + if ((gc->pc + single_vertex_size) >= gc->bufEnd) { + gc->pc = __glXFlushRenderBuffer(gc, gc->pc); + } + + gc->pc = emit_element_none(gc->pc, arrays, index); + + if (gc->pc > gc->limit) { + (void) __glXFlushRenderBuffer(gc, gc->pc); + } +} + + +void +__indirect_glDrawElements(GLenum mode, GLsizei count, GLenum type, + const GLvoid * indices) +{ + struct glx_context *gc = __glXGetCurrentContext(); + const __GLXattribute *state = + (const __GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + + + if (validate_mode(gc, mode) && validate_count(gc, count) + && validate_type(gc, type)) { + if (!arrays->array_info_cache_valid) { + fill_array_info_cache(arrays); + } + + arrays->DrawElements(mode, count, type, indices); + } +} + + +void +__indirect_glDrawRangeElements(GLenum mode, GLuint start, GLuint end, + GLsizei count, GLenum type, + const GLvoid * indices) +{ + struct glx_context *gc = __glXGetCurrentContext(); + const __GLXattribute *state = + (const __GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + + + if (validate_mode(gc, mode) && validate_count(gc, count) + && validate_type(gc, type)) { + if (end < start) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + + if (!arrays->array_info_cache_valid) { + fill_array_info_cache(arrays); + } + + arrays->DrawElements(mode, count, type, indices); + } +} + + +void +__indirect_glMultiDrawArraysEXT(GLenum mode, const GLint *first, + const GLsizei *count, GLsizei primcount) +{ + struct glx_context *gc = __glXGetCurrentContext(); + const __GLXattribute *state = + (const __GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + GLsizei i; + + + if (validate_mode(gc, mode)) { + if (!arrays->array_info_cache_valid) { + fill_array_info_cache(arrays); + } + + for (i = 0; i < primcount; i++) { + if (validate_count(gc, count[i])) { + arrays->DrawArrays(mode, first[i], count[i]); + } + } + } +} + + +void +__indirect_glMultiDrawElementsEXT(GLenum mode, const GLsizei * count, + GLenum type, const GLvoid ** indices, + GLsizei primcount) +{ + struct glx_context *gc = __glXGetCurrentContext(); + const __GLXattribute *state = + (const __GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + GLsizei i; + + + if (validate_mode(gc, mode) && validate_type(gc, type)) { + if (!arrays->array_info_cache_valid) { + fill_array_info_cache(arrays); + } + + for (i = 0; i < primcount; i++) { + if (validate_count(gc, count[i])) { + arrays->DrawElements(mode, count[i], type, indices[i]); + } + } + } +} + + +#define COMMON_ARRAY_DATA_INIT(a, PTR, TYPE, STRIDE, COUNT, NORMALIZED, HDR_SIZE, OPCODE) \ + do { \ + (a)->data = PTR; \ + (a)->data_type = TYPE; \ + (a)->user_stride = STRIDE; \ + (a)->count = COUNT; \ + (a)->normalized = NORMALIZED; \ + \ + (a)->element_size = __glXTypeSize( TYPE ) * COUNT; \ + (a)->true_stride = (STRIDE == 0) \ + ? (a)->element_size : STRIDE; \ + \ + (a)->header_size = HDR_SIZE; \ + ((uint16_t *) (a)->header)[0] = __GLX_PAD((a)->header_size + (a)->element_size); \ + ((uint16_t *) (a)->header)[1] = OPCODE; \ + } while(0) + + +void +__indirect_glVertexPointer(GLint size, GLenum type, GLsizei stride, + const GLvoid * pointer) +{ + static const uint16_t short_ops[5] = { + 0, 0, X_GLrop_Vertex2sv, X_GLrop_Vertex3sv, X_GLrop_Vertex4sv + }; + static const uint16_t int_ops[5] = { + 0, 0, X_GLrop_Vertex2iv, X_GLrop_Vertex3iv, X_GLrop_Vertex4iv + }; + static const uint16_t float_ops[5] = { + 0, 0, X_GLrop_Vertex2fv, X_GLrop_Vertex3fv, X_GLrop_Vertex4fv + }; + static const uint16_t double_ops[5] = { + 0, 0, X_GLrop_Vertex2dv, X_GLrop_Vertex3dv, X_GLrop_Vertex4dv + }; + uint16_t opcode; + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + struct array_state *a; + + + if (size < 2 || size > 4 || stride < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + + switch (type) { + case GL_SHORT: + opcode = short_ops[size]; + break; + case GL_INT: + opcode = int_ops[size]; + break; + case GL_FLOAT: + opcode = float_ops[size]; + break; + case GL_DOUBLE: + opcode = double_ops[size]; + break; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + + a = get_array_entry(arrays, GL_VERTEX_ARRAY, 0); + assert(a != NULL); + COMMON_ARRAY_DATA_INIT(a, pointer, type, stride, size, GL_FALSE, 4, + opcode); + + if (a->enabled) { + arrays->array_info_cache_valid = GL_FALSE; + } +} + + +void +__indirect_glNormalPointer(GLenum type, GLsizei stride, + const GLvoid * pointer) +{ + uint16_t opcode; + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + struct array_state *a; + + + if (stride < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + + switch (type) { + case GL_BYTE: + opcode = X_GLrop_Normal3bv; + break; + case GL_SHORT: + opcode = X_GLrop_Normal3sv; + break; + case GL_INT: + opcode = X_GLrop_Normal3iv; + break; + case GL_FLOAT: + opcode = X_GLrop_Normal3fv; + break; + case GL_DOUBLE: + opcode = X_GLrop_Normal3dv; + break; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + + a = get_array_entry(arrays, GL_NORMAL_ARRAY, 0); + assert(a != NULL); + COMMON_ARRAY_DATA_INIT(a, pointer, type, stride, 3, GL_TRUE, 4, opcode); + + if (a->enabled) { + arrays->array_info_cache_valid = GL_FALSE; + } +} + + +void +__indirect_glColorPointer(GLint size, GLenum type, GLsizei stride, + const GLvoid * pointer) +{ + static const uint16_t byte_ops[5] = { + 0, 0, 0, X_GLrop_Color3bv, X_GLrop_Color4bv + }; + static const uint16_t ubyte_ops[5] = { + 0, 0, 0, X_GLrop_Color3ubv, X_GLrop_Color4ubv + }; + static const uint16_t short_ops[5] = { + 0, 0, 0, X_GLrop_Color3sv, X_GLrop_Color4sv + }; + static const uint16_t ushort_ops[5] = { + 0, 0, 0, X_GLrop_Color3usv, X_GLrop_Color4usv + }; + static const uint16_t int_ops[5] = { + 0, 0, 0, X_GLrop_Color3iv, X_GLrop_Color4iv + }; + static const uint16_t uint_ops[5] = { + 0, 0, 0, X_GLrop_Color3uiv, X_GLrop_Color4uiv + }; + static const uint16_t float_ops[5] = { + 0, 0, 0, X_GLrop_Color3fv, X_GLrop_Color4fv + }; + static const uint16_t double_ops[5] = { + 0, 0, 0, X_GLrop_Color3dv, X_GLrop_Color4dv + }; + uint16_t opcode; + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + struct array_state *a; + + + if (size < 3 || size > 4 || stride < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + + switch (type) { + case GL_BYTE: + opcode = byte_ops[size]; + break; + case GL_UNSIGNED_BYTE: + opcode = ubyte_ops[size]; + break; + case GL_SHORT: + opcode = short_ops[size]; + break; + case GL_UNSIGNED_SHORT: + opcode = ushort_ops[size]; + break; + case GL_INT: + opcode = int_ops[size]; + break; + case GL_UNSIGNED_INT: + opcode = uint_ops[size]; + break; + case GL_FLOAT: + opcode = float_ops[size]; + break; + case GL_DOUBLE: + opcode = double_ops[size]; + break; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + + a = get_array_entry(arrays, GL_COLOR_ARRAY, 0); + assert(a != NULL); + COMMON_ARRAY_DATA_INIT(a, pointer, type, stride, size, GL_TRUE, 4, opcode); + + if (a->enabled) { + arrays->array_info_cache_valid = GL_FALSE; + } +} + + +void +__indirect_glIndexPointer(GLenum type, GLsizei stride, const GLvoid * pointer) +{ + uint16_t opcode; + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + struct array_state *a; + + + if (stride < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + + switch (type) { + case GL_UNSIGNED_BYTE: + opcode = X_GLrop_Indexubv; + break; + case GL_SHORT: + opcode = X_GLrop_Indexsv; + break; + case GL_INT: + opcode = X_GLrop_Indexiv; + break; + case GL_FLOAT: + opcode = X_GLrop_Indexfv; + break; + case GL_DOUBLE: + opcode = X_GLrop_Indexdv; + break; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + + a = get_array_entry(arrays, GL_INDEX_ARRAY, 0); + assert(a != NULL); + COMMON_ARRAY_DATA_INIT(a, pointer, type, stride, 1, GL_FALSE, 4, opcode); + + if (a->enabled) { + arrays->array_info_cache_valid = GL_FALSE; + } +} + + +void +__indirect_glEdgeFlagPointer(GLsizei stride, const GLvoid * pointer) +{ + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + struct array_state *a; + + + if (stride < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + + + a = get_array_entry(arrays, GL_EDGE_FLAG_ARRAY, 0); + assert(a != NULL); + COMMON_ARRAY_DATA_INIT(a, pointer, GL_UNSIGNED_BYTE, stride, 1, GL_FALSE, + 4, X_GLrop_EdgeFlagv); + + if (a->enabled) { + arrays->array_info_cache_valid = GL_FALSE; + } +} + + +void +__indirect_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, + const GLvoid * pointer) +{ + static const uint16_t short_ops[5] = { + 0, X_GLrop_TexCoord1sv, X_GLrop_TexCoord2sv, X_GLrop_TexCoord3sv, + X_GLrop_TexCoord4sv + }; + static const uint16_t int_ops[5] = { + 0, X_GLrop_TexCoord1iv, X_GLrop_TexCoord2iv, X_GLrop_TexCoord3iv, + X_GLrop_TexCoord4iv + }; + static const uint16_t float_ops[5] = { + 0, X_GLrop_TexCoord1dv, X_GLrop_TexCoord2fv, X_GLrop_TexCoord3fv, + X_GLrop_TexCoord4fv + }; + static const uint16_t double_ops[5] = { + 0, X_GLrop_TexCoord1dv, X_GLrop_TexCoord2dv, X_GLrop_TexCoord3dv, + X_GLrop_TexCoord4dv + }; + + static const uint16_t mshort_ops[5] = { + 0, X_GLrop_MultiTexCoord1svARB, X_GLrop_MultiTexCoord2svARB, + X_GLrop_MultiTexCoord3svARB, X_GLrop_MultiTexCoord4svARB + }; + static const uint16_t mint_ops[5] = { + 0, X_GLrop_MultiTexCoord1ivARB, X_GLrop_MultiTexCoord2ivARB, + X_GLrop_MultiTexCoord3ivARB, X_GLrop_MultiTexCoord4ivARB + }; + static const uint16_t mfloat_ops[5] = { + 0, X_GLrop_MultiTexCoord1dvARB, X_GLrop_MultiTexCoord2fvARB, + X_GLrop_MultiTexCoord3fvARB, X_GLrop_MultiTexCoord4fvARB + }; + static const uint16_t mdouble_ops[5] = { + 0, X_GLrop_MultiTexCoord1dvARB, X_GLrop_MultiTexCoord2dvARB, + X_GLrop_MultiTexCoord3dvARB, X_GLrop_MultiTexCoord4dvARB + }; + + uint16_t opcode; + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + struct array_state *a; + unsigned header_size; + unsigned index; + + + if (size < 1 || size > 4 || stride < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + + index = arrays->active_texture_unit; + if (index == 0) { + switch (type) { + case GL_SHORT: + opcode = short_ops[size]; + break; + case GL_INT: + opcode = int_ops[size]; + break; + case GL_FLOAT: + opcode = float_ops[size]; + break; + case GL_DOUBLE: + opcode = double_ops[size]; + break; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + + header_size = 4; + } + else { + switch (type) { + case GL_SHORT: + opcode = mshort_ops[size]; + break; + case GL_INT: + opcode = mint_ops[size]; + break; + case GL_FLOAT: + opcode = mfloat_ops[size]; + break; + case GL_DOUBLE: + opcode = mdouble_ops[size]; + break; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + + header_size = 8; + } + + a = get_array_entry(arrays, GL_TEXTURE_COORD_ARRAY, index); + assert(a != NULL); + COMMON_ARRAY_DATA_INIT(a, pointer, type, stride, size, GL_FALSE, + header_size, opcode); + + if (a->enabled) { + arrays->array_info_cache_valid = GL_FALSE; + } +} + + +void +__indirect_glSecondaryColorPointerEXT(GLint size, GLenum type, GLsizei stride, + const GLvoid * pointer) +{ + uint16_t opcode; + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + struct array_state *a; + + + if (size != 3 || stride < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + + switch (type) { + case GL_BYTE: + opcode = 4126; + break; + case GL_UNSIGNED_BYTE: + opcode = 4131; + break; + case GL_SHORT: + opcode = 4127; + break; + case GL_UNSIGNED_SHORT: + opcode = 4132; + break; + case GL_INT: + opcode = 4128; + break; + case GL_UNSIGNED_INT: + opcode = 4133; + break; + case GL_FLOAT: + opcode = 4129; + break; + case GL_DOUBLE: + opcode = 4130; + break; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + + a = get_array_entry(arrays, GL_SECONDARY_COLOR_ARRAY, 0); + if (a == NULL) { + __glXSetError(gc, GL_INVALID_OPERATION); + return; + } + + COMMON_ARRAY_DATA_INIT(a, pointer, type, stride, size, GL_TRUE, 4, opcode); + + if (a->enabled) { + arrays->array_info_cache_valid = GL_FALSE; + } +} + + +void +__indirect_glFogCoordPointerEXT(GLenum type, GLsizei stride, + const GLvoid * pointer) +{ + uint16_t opcode; + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + struct array_state *a; + + + if (stride < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + + switch (type) { + case GL_FLOAT: + opcode = 4124; + break; + case GL_DOUBLE: + opcode = 4125; + break; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + + a = get_array_entry(arrays, GL_FOG_COORD_ARRAY, 0); + if (a == NULL) { + __glXSetError(gc, GL_INVALID_OPERATION); + return; + } + + COMMON_ARRAY_DATA_INIT(a, pointer, type, stride, 1, GL_FALSE, 4, opcode); + + if (a->enabled) { + arrays->array_info_cache_valid = GL_FALSE; + } +} + + +void +__indirect_glVertexAttribPointerARB(GLuint index, GLint size, + GLenum type, GLboolean normalized, + GLsizei stride, const GLvoid * pointer) +{ + static const uint16_t short_ops[5] = { 0, 4189, 4190, 4191, 4192 }; + static const uint16_t float_ops[5] = { 0, 4193, 4194, 4195, 4196 }; + static const uint16_t double_ops[5] = { 0, 4197, 4198, 4199, 4200 }; + + uint16_t opcode; + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + struct array_state_vector *arrays = state->array_state; + struct array_state *a; + unsigned true_immediate_count; + unsigned true_immediate_size; + + + if ((size < 1) || (size > 4) || (stride < 0) + || (index > arrays->num_vertex_program_attribs)) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + + if (normalized && (type != GL_FLOAT) && (type != GL_DOUBLE)) { + switch (type) { + case GL_BYTE: + opcode = X_GLrop_VertexAttrib4NbvARB; + break; + case GL_UNSIGNED_BYTE: + opcode = X_GLrop_VertexAttrib4NubvARB; + break; + case GL_SHORT: + opcode = X_GLrop_VertexAttrib4NsvARB; + break; + case GL_UNSIGNED_SHORT: + opcode = X_GLrop_VertexAttrib4NusvARB; + break; + case GL_INT: + opcode = X_GLrop_VertexAttrib4NivARB; + break; + case GL_UNSIGNED_INT: + opcode = X_GLrop_VertexAttrib4NuivARB; + break; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + + true_immediate_count = 4; + } + else { + true_immediate_count = size; + + switch (type) { + case GL_BYTE: + opcode = X_GLrop_VertexAttrib4bvARB; + true_immediate_count = 4; + break; + case GL_UNSIGNED_BYTE: + opcode = X_GLrop_VertexAttrib4ubvARB; + true_immediate_count = 4; + break; + case GL_SHORT: + opcode = short_ops[size]; + break; + case GL_UNSIGNED_SHORT: + opcode = X_GLrop_VertexAttrib4usvARB; + true_immediate_count = 4; + break; + case GL_INT: + opcode = X_GLrop_VertexAttrib4ivARB; + true_immediate_count = 4; + break; + case GL_UNSIGNED_INT: + opcode = X_GLrop_VertexAttrib4uivARB; + true_immediate_count = 4; + break; + case GL_FLOAT: + opcode = float_ops[size]; + break; + case GL_DOUBLE: + opcode = double_ops[size]; + break; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + } + + a = get_array_entry(arrays, GL_VERTEX_ATTRIB_ARRAY_POINTER, index); + if (a == NULL) { + __glXSetError(gc, GL_INVALID_OPERATION); + return; + } + + COMMON_ARRAY_DATA_INIT(a, pointer, type, stride, size, normalized, 8, + opcode); + + true_immediate_size = __glXTypeSize(type) * true_immediate_count; + ((uint16_t *) (a)->header)[0] = __GLX_PAD(a->header_size + + true_immediate_size); + + if (a->enabled) { + arrays->array_info_cache_valid = GL_FALSE; + } +} + + +/** + * I don't have 100% confidence that this is correct. The different rules + * about whether or not generic vertex attributes alias "classic" vertex + * attributes (i.e., attrib1 ?= primary color) between ARB_vertex_program, + * ARB_vertex_shader, and NV_vertex_program are a bit confusing. My + * feeling is that the client-side doesn't have to worry about it. The + * client just sends all the data to the server and lets the server deal + * with it. + */ +void +__indirect_glVertexAttribPointerNV(GLuint index, GLint size, + GLenum type, GLsizei stride, + const GLvoid * pointer) +{ + struct glx_context *gc = __glXGetCurrentContext(); + GLboolean normalized = GL_FALSE; + + + switch (type) { + case GL_UNSIGNED_BYTE: + if (size != 4) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + normalized = GL_TRUE; + + case GL_SHORT: + case GL_FLOAT: + case GL_DOUBLE: + __indirect_glVertexAttribPointerARB(index, size, type, + normalized, stride, pointer); + return; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return; + } +} + + +void +__indirect_glClientActiveTextureARB(GLenum texture) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + __GLXattribute *const state = + (__GLXattribute *) (gc->client_state_private); + struct array_state_vector *const arrays = state->array_state; + const GLint unit = (GLint) texture - GL_TEXTURE0; + + + if ((unit < 0) || (unit >= arrays->num_texture_units)) { + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + + arrays->active_texture_unit = unit; +} + + +/** + * Modify the enable state for the selected array + */ +GLboolean +__glXSetArrayEnable(__GLXattribute * state, GLenum key, unsigned index, + GLboolean enable) +{ + struct array_state_vector *arrays = state->array_state; + struct array_state *a; + + + /* Texture coordinate arrays have an implict index set when the + * application calls glClientActiveTexture. + */ + if (key == GL_TEXTURE_COORD_ARRAY) { + index = arrays->active_texture_unit; + } + + a = get_array_entry(arrays, key, index); + + if ((a != NULL) && (a->enabled != enable)) { + a->enabled = enable; + arrays->array_info_cache_valid = GL_FALSE; + } + + return (a != NULL); +} + + +void +__glXArrayDisableAll(__GLXattribute * state) +{ + struct array_state_vector *arrays = state->array_state; + unsigned i; + + + for (i = 0; i < arrays->num_arrays; i++) { + arrays->arrays[i].enabled = GL_FALSE; + } + + arrays->array_info_cache_valid = GL_FALSE; +} + + +/** + */ +GLboolean +__glXGetArrayEnable(const __GLXattribute * const state, + GLenum key, unsigned index, GLintptr * dest) +{ + const struct array_state_vector *arrays = state->array_state; + const struct array_state *a = + get_array_entry((struct array_state_vector *) arrays, + key, index); + + if (a != NULL) { + *dest = (GLintptr) a->enabled; + } + + return (a != NULL); +} + + +/** + */ +GLboolean +__glXGetArrayType(const __GLXattribute * const state, + GLenum key, unsigned index, GLintptr * dest) +{ + const struct array_state_vector *arrays = state->array_state; + const struct array_state *a = + get_array_entry((struct array_state_vector *) arrays, + key, index); + + if (a != NULL) { + *dest = (GLintptr) a->data_type; + } + + return (a != NULL); +} + + +/** + */ +GLboolean +__glXGetArraySize(const __GLXattribute * const state, + GLenum key, unsigned index, GLintptr * dest) +{ + const struct array_state_vector *arrays = state->array_state; + const struct array_state *a = + get_array_entry((struct array_state_vector *) arrays, + key, index); + + if (a != NULL) { + *dest = (GLintptr) a->count; + } + + return (a != NULL); +} + + +/** + */ +GLboolean +__glXGetArrayStride(const __GLXattribute * const state, + GLenum key, unsigned index, GLintptr * dest) +{ + const struct array_state_vector *arrays = state->array_state; + const struct array_state *a = + get_array_entry((struct array_state_vector *) arrays, + key, index); + + if (a != NULL) { + *dest = (GLintptr) a->user_stride; + } + + return (a != NULL); +} + + +/** + */ +GLboolean +__glXGetArrayPointer(const __GLXattribute * const state, + GLenum key, unsigned index, void **dest) +{ + const struct array_state_vector *arrays = state->array_state; + const struct array_state *a = + get_array_entry((struct array_state_vector *) arrays, + key, index); + + + if (a != NULL) { + *dest = (void *) (a->data); + } + + return (a != NULL); +} + + +/** + */ +GLboolean +__glXGetArrayNormalized(const __GLXattribute * const state, + GLenum key, unsigned index, GLintptr * dest) +{ + const struct array_state_vector *arrays = state->array_state; + const struct array_state *a = + get_array_entry((struct array_state_vector *) arrays, + key, index); + + + if (a != NULL) { + *dest = (GLintptr) a->normalized; + } + + return (a != NULL); +} + + +/** + */ +GLuint +__glXGetActiveTextureUnit(const __GLXattribute * const state) +{ + return state->array_state->active_texture_unit; +} + + +void +__glXPushArrayState(__GLXattribute * state) +{ + struct array_state_vector *arrays = state->array_state; + struct array_stack_state *stack = + &arrays->stack[(arrays->stack_index * arrays->num_arrays)]; + unsigned i; + + /* XXX are we pushing _all_ the necessary fields? */ + for (i = 0; i < arrays->num_arrays; i++) { + stack[i].data = arrays->arrays[i].data; + stack[i].data_type = arrays->arrays[i].data_type; + stack[i].user_stride = arrays->arrays[i].user_stride; + stack[i].count = arrays->arrays[i].count; + stack[i].key = arrays->arrays[i].key; + stack[i].index = arrays->arrays[i].index; + stack[i].enabled = arrays->arrays[i].enabled; + } + + arrays->active_texture_unit_stack[arrays->stack_index] = + arrays->active_texture_unit; + + arrays->stack_index++; +} + + +void +__glXPopArrayState(__GLXattribute * state) +{ + struct array_state_vector *arrays = state->array_state; + struct array_stack_state *stack; + unsigned i; + + + arrays->stack_index--; + stack = &arrays->stack[(arrays->stack_index * arrays->num_arrays)]; + + for (i = 0; i < arrays->num_arrays; i++) { + switch (stack[i].key) { + case GL_NORMAL_ARRAY: + __indirect_glNormalPointer(stack[i].data_type, + stack[i].user_stride, stack[i].data); + break; + case GL_COLOR_ARRAY: + __indirect_glColorPointer(stack[i].count, + stack[i].data_type, + stack[i].user_stride, stack[i].data); + break; + case GL_INDEX_ARRAY: + __indirect_glIndexPointer(stack[i].data_type, + stack[i].user_stride, stack[i].data); + break; + case GL_EDGE_FLAG_ARRAY: + __indirect_glEdgeFlagPointer(stack[i].user_stride, stack[i].data); + break; + case GL_TEXTURE_COORD_ARRAY: + arrays->active_texture_unit = stack[i].index; + __indirect_glTexCoordPointer(stack[i].count, + stack[i].data_type, + stack[i].user_stride, stack[i].data); + break; + case GL_SECONDARY_COLOR_ARRAY: + __indirect_glSecondaryColorPointerEXT(stack[i].count, + stack[i].data_type, + stack[i].user_stride, + stack[i].data); + break; + case GL_FOG_COORDINATE_ARRAY: + __indirect_glFogCoordPointerEXT(stack[i].data_type, + stack[i].user_stride, stack[i].data); + break; + + } + + __glXSetArrayEnable(state, stack[i].key, stack[i].index, + stack[i].enabled); + } + + arrays->active_texture_unit = + arrays->active_texture_unit_stack[arrays->stack_index]; +} diff --git a/src/glx/indirect_vertex_array.h b/src/glx/indirect_vertex_array.h new file mode 100644 index 0000000..3738032 --- /dev/null +++ b/src/glx/indirect_vertex_array.h @@ -0,0 +1,64 @@ +/* + * (C) Copyright IBM Corporation 2004, 2005 + * 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 + * IBM, + * 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 INDIRECT_VERTEX_ARRAY_H +#define INDIRECT_VERTEX_ARRAY_H + +extern const GLuint __glXTypeSize_table[16]; + +#define __glXTypeSize(e) ((((e) & ~0x0f) != 0x1400) \ + ? 0 : __glXTypeSize_table[ (e) & 0x0f ]) + +extern void __glXArrayDisableAll(__GLXattribute * state); + +extern GLboolean __glXSetArrayEnable(__GLXattribute * state, + GLenum key, unsigned index, + GLboolean enable); + +extern GLboolean __glXGetArrayEnable(const __GLXattribute * const state, + GLenum key, unsigned index, + GLintptr * dest); +extern GLboolean __glXGetArraySize(const __GLXattribute * const state, + GLenum key, unsigned index, + GLintptr * dest); +extern GLboolean __glXGetArrayType(const __GLXattribute * const state, + GLenum key, unsigned index, + GLintptr * dest); +extern GLboolean __glXGetArrayStride(const __GLXattribute * const state, + GLenum key, unsigned index, + GLintptr * dest); +extern GLboolean __glXGetArrayPointer(const __GLXattribute * const state, + GLenum key, unsigned index, + void **dest); +extern GLboolean __glXGetArrayNormalized(const __GLXattribute * const state, + GLenum key, unsigned index, + GLintptr * dest); + +extern void __glXPushArrayState(__GLXattribute * state); +extern void __glXPopArrayState(__GLXattribute * state); + +extern GLuint __glXGetActiveTextureUnit(const __GLXattribute * const state); + +#endif /* INDIRECT_VERTEX_ARRAY_H */ diff --git a/src/glx/indirect_vertex_array_priv.h b/src/glx/indirect_vertex_array_priv.h new file mode 100644 index 0000000..56dac37 --- /dev/null +++ b/src/glx/indirect_vertex_array_priv.h @@ -0,0 +1,311 @@ +/* + * (C) Copyright IBM Corporation 2004, 2005 + * 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 + * IBM, + * 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 _INDIRECT_VA_PRIVATE_ +#define _INDIRECT_VA_PRIVATE_ + +/** + * \file indirect_va_private.h + * + * \author Ian Romanick + */ + +#include + +#include "glxclient.h" +#include "indirect.h" +#include + + +/** + * State descriptor for a single array of vertex data. + */ +struct array_state +{ + /** + * Pointer to the application supplied data. + */ + const void *data; + + /** + * Enum representing the type of the application supplied data. + */ + GLenum data_type; + + /** + * Stride value supplied by the application. This value is not used + * internally. It is only kept so that it can be queried by the + * application using glGet*v. + */ + GLsizei user_stride; + + /** + * Calculated size, in bytes, of a single element in the array. This + * is calculated based on \c count and the size of the data type + * represented by \c data_type. + */ + GLsizei element_size; + + /** + * Actual byte-stride from one element to the next. This value will + * be equal to either \c user_stride or \c element_stride. + */ + GLsizei true_stride; + + /** + * Number of data values in each element. + */ + GLint count; + + /** + * "Normalized" data is on the range [0,1] (unsigned) or [-1,1] (signed). + * This is used for mapping integral types to floating point types. + */ + GLboolean normalized; + + /** + * Pre-calculated GLX protocol command header. + */ + uint32_t header[2]; + + /** + * Size of the header data. For simple data, like glColorPointerfv, + * this is 4. For complex data that requires either a count (e.g., + * glWeightfvARB), an index (e.g., glVertexAttrib1fvARB), or a + * selector enum (e.g., glMultiTexCoord2fv) this is 8. + */ + unsigned header_size; + + /** + * Set to \c GL_TRUE if this array is enabled. Otherwise, it is set + * to \c GL_FALSE. + */ + GLboolean enabled; + + /** + * For multi-arrayed data (e.g., texture coordinates, generic vertex + * program attributes, etc.), this specifies which array this is. + */ + unsigned index; + + /** + * Per-array-type key. For most arrays, this will be the GL enum for + * that array (e.g., GL_VERTEX_ARRAY for vertex data, GL_NORMAL_ARRAY + * for normal data, GL_TEXTURE_COORD_ARRAY for texture coordinate data, + * etc.). + */ + GLenum key; + + /** + * If this array can be used with the "classic" \c glDrawArrays protocol, + * this is set to \c GL_TRUE. Otherwise, it is set to \c GL_FALSE. + */ + GLboolean old_DrawArrays_possible; +}; + + +/** + * Array state that is pushed / poped by \c glPushClientAttrib and + * \c glPopClientAttrib. + */ +struct array_stack_state +{ + /** + * Pointer to the application supplied data. + */ + const void *data; + + /** + * Enum representing the type of the application supplied data. + */ + GLenum data_type; + + /** + * Stride value supplied by the application. This value is not used + * internally. It is only kept so that it can be queried by the + * application using glGet*v. + */ + GLsizei user_stride; + + /** + * Number of data values in each element. + */ + GLint count; + + /** + * Per-array-type key. For most arrays, this will be the GL enum for + * that array (e.g., GL_VERTEX_ARRAY for vertex data, GL_NORMAL_ARRAY + * for normal data, GL_TEXTURE_COORD_ARRAY for texture coordinate data, + * etc.). + */ + GLenum key; + + /** + * For multi-arrayed data (e.g., texture coordinates, generic vertex + * program attributes, etc.), this specifies which array this is. + */ + unsigned index; + + /** + * Set to \c GL_TRUE if this array is enabled. Otherwise, it is set + * to \c GL_FALSE. + */ + GLboolean enabled; +}; + + +/** + * Collection of all the vertex array state. + */ +struct array_state_vector +{ + /** + * Number of arrays tracked by \c ::arrays. + */ + size_t num_arrays; + + /** + * Array of vertex array state. This array contains all of the valid + * vertex arrays. If a vertex array isn't in this array, then it isn't + * valid. For example, if an implementation does not support + * EXT_fog_coord, there won't be a GL_FOG_COORD_ARRAY entry in this + * array. + */ + struct array_state *arrays; + + /** + * Number of currently enabled client-side arrays. The value of this + * field is only valid if \c array_info_cache_valid is true. + */ + size_t enabled_client_array_count; + + /** + * \name ARRAY_INFO cache. + * + * These fields track the state of the ARRAY_INFO cache. The + * \c array_info_cache_size is the size of the actual data stored in + * \c array_info_cache. \c array_info_cache_buffer_size is the size of + * the buffer. This will always be greater than or equal to + * \c array_info_cache_size. + * + * \note + * There are some bytes of extra data before \c array_info_cache that is + * used to hold the header for RenderLarge commands. This is + * \b not included in \c array_info_cache_size or + * \c array_info_cache_buffer_size. \c array_info_cache_base stores a + * pointer to the true start of the buffer (i.e., what malloc returned). + */ + /*@{ */ + size_t array_info_cache_size; + size_t array_info_cache_buffer_size; + void *array_info_cache; + void *array_info_cache_base; + /*@} */ + + + /** + * Is the cache of ARRAY_INFO data valid? The cache can become invalid + * when one of several state changes occur. Among these chages are + * modifying the array settings for an enabled array and enabling / + * disabling an array. + */ + GLboolean array_info_cache_valid; + + /** + * Is it possible to use the GL 1.1 / EXT_vertex_arrays protocol? Use + * of this protocol is disabled with really old servers (i.e., servers + * that don't support GL 1.1 or EXT_vertex_arrays) or when an environment + * variable is set. + * + * \todo + * GL 1.1 and EXT_vertex_arrays use identical protocol, but have different + * opcodes for \c glDrawArrays. For servers that advertise one or the + * other, there should be a way to select which opcode to use. + */ + GLboolean old_DrawArrays_possible; + + /** + * Is it possible to use the new GL X.X / ARB_vertex_buffer_object + * protocol? + * + * \todo + * This protocol has not yet been defined by the ARB, but is currently a + * work in progress. This field is a place-holder. + */ + GLboolean new_DrawArrays_possible; + + /** + * Active texture unit set by \c glClientActiveTexture. + * + * \sa __glXGetActiveTextureUnit + */ + unsigned active_texture_unit; + + /** + * Number of supported texture units. Even if ARB_multitexture / + * GL 1.3 are not supported, this will be at least 1. When multitexture + * is supported, this will be the value queried by calling + * \c glGetIntegerv with \c GL_MAX_TEXTURE_UNITS. + * + * \todo + * Investigate if this should be the value of \c GL_MAX_TEXTURE_COORDS + * instead (if GL 2.0 / ARB_fragment_shader / ARB_fragment_program / + * NV_fragment_program are supported). + */ + unsigned num_texture_units; + + /** + * Number of generic vertex program attribs. If GL_ARB_vertex_program + * is not supported, this will be zero. Otherwise it will be the value + * queries by calling \c glGetProgramiv with \c GL_VERTEX_PROGRAM_ARB + * and \c GL_MAX_PROGRAM_ATTRIBS_ARB. + */ + unsigned num_vertex_program_attribs; + + /** + * \n Methods for implementing various GL functions. + * + * These method pointers are only valid \c array_info_cache_valid is set. + * When each function starts, it much check \c array_info_cache_valid. + * If it is not set, it must call \c fill_array_info_cache and call + * the new method. + * + * \sa fill_array_info_cache + * + * \todo + * Write code to plug these functions directly into the dispatch table. + */ + /*@{ */ + void (*DrawArrays) (GLenum, GLint, GLsizei); + void (*DrawElements) (GLenum mode, GLsizei count, GLenum type, + const GLvoid * indices); + /*@} */ + + struct array_stack_state *stack; + unsigned active_texture_unit_stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]; + unsigned stack_index; +}; + +#endif /* _INDIRECT_VA_PRIVATE_ */ diff --git a/src/glx/indirect_vertex_program.c b/src/glx/indirect_vertex_program.c new file mode 100644 index 0000000..d955fdf --- /dev/null +++ b/src/glx/indirect_vertex_program.c @@ -0,0 +1,293 @@ +/* + * (C) Copyright IBM Corporation 2005 + * 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 + * IBM, + * 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 +#include +#include "indirect.h" +#include "glxclient.h" +#include "indirect_vertex_array.h" +#include + +#if !defined(__GNUC__) +# define __builtin_expect(x, y) x +#endif + +static void +do_vertex_attrib_enable(GLuint index, GLboolean val) +{ + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + + if (!__glXSetArrayEnable(state, GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB, + index, val)) { + __glXSetError(gc, GL_INVALID_ENUM); + } +} + + +void +__indirect_glEnableVertexAttribArrayARB(GLuint index) +{ + do_vertex_attrib_enable(index, GL_TRUE); +} + + +void +__indirect_glDisableVertexAttribArrayARB(GLuint index) +{ + do_vertex_attrib_enable(index, GL_FALSE); +} + + +static void +get_parameter(unsigned opcode, unsigned size, GLenum target, GLuint index, + void *params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 12; + + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = __glXSetupVendorRequest(gc, + X_GLXVendorPrivateWithReply, + opcode, cmdlen); + + *((GLenum *) (pc + 0)) = target; + *((GLuint *) (pc + 4)) = index; + *((GLuint *) (pc + 8)) = 0; + + (void) __glXReadReply(dpy, size, params, GL_FALSE); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + + +void +__indirect_glGetProgramEnvParameterfvARB(GLenum target, GLuint index, + GLfloat * params) +{ + get_parameter(1296, 4, target, index, params); +} + + +void +__indirect_glGetProgramEnvParameterdvARB(GLenum target, GLuint index, + GLdouble * params) +{ + get_parameter(1297, 8, target, index, params); +} + + +void +__indirect_glGetProgramLocalParameterfvARB(GLenum target, GLuint index, + GLfloat * params) +{ + get_parameter(1305, 4, target, index, params); +} + + +void +__indirect_glGetProgramLocalParameterdvARB(GLenum target, GLuint index, + GLdouble * params) +{ + get_parameter(1306, 8, target, index, params); +} + + +void +__indirect_glGetVertexAttribPointervNV(GLuint index, GLenum pname, + GLvoid ** pointer) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + + if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) { + __glXSetError(gc, GL_INVALID_ENUM); + } + + if (!__glXGetArrayPointer(state, GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB, + index, pointer)) { + __glXSetError(gc, GL_INVALID_VALUE); + } +} + + +/** + * Get the selected attribute from the vertex array state vector. + * + * \returns + * On success \c GL_TRUE is returned. Otherwise, \c GL_FALSE is returned. + */ +static GLboolean +get_attrib_array_data(__GLXattribute * state, GLuint index, GLenum cap, + GLintptr * data) +{ + GLboolean retval = GL_FALSE; + const GLenum attrib = GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB; + + switch (cap) { + case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB: + retval = __glXGetArrayEnable(state, attrib, index, data); + break; + + case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB: + retval = __glXGetArraySize(state, attrib, index, data); + break; + + case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB: + retval = __glXGetArrayStride(state, attrib, index, data); + break; + + case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB: + retval = __glXGetArrayType(state, attrib, index, data); + break; + + case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB: + retval = __glXGetArrayNormalized(state, attrib, index, data); + break; + } + + + return retval; +} + + +static void +get_vertex_attrib(struct glx_context * gc, unsigned vop, + GLuint index, GLenum pname, xReply * reply) +{ + Display *const dpy = gc->currentDpy; + GLubyte *const pc = __glXSetupVendorRequest(gc, + X_GLXVendorPrivateWithReply, + vop, 8); + + *((uint32_t *) (pc + 0)) = index; + *((uint32_t *) (pc + 4)) = pname; + + (void) _XReply(dpy, reply, 0, False); +} + + +void +__indirect_glGetVertexAttribivARB(GLuint index, GLenum pname, GLint * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + xGLXSingleReply reply; + + + get_vertex_attrib(gc, 1303, index, pname, (xReply *) & reply); + + if (reply.size != 0) { + GLintptr data; + + + if (get_attrib_array_data(state, index, pname, &data)) { + *params = (GLint) data; + } + else { + if (reply.size == 1) { + *params = (GLint) reply.pad3; + } + else { + _XRead(dpy, (void *) params, 4 * reply.size); + } + } + } + + UnlockDisplay(dpy); + SyncHandle(); +} + + +void +__indirect_glGetVertexAttribfvARB(GLuint index, GLenum pname, + GLfloat * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + xGLXSingleReply reply; + + + get_vertex_attrib(gc, 1302, index, pname, (xReply *) & reply); + + if (reply.size != 0) { + GLintptr data; + + + if (get_attrib_array_data(state, index, pname, &data)) { + *params = (GLfloat) data; + } + else { + if (reply.size == 1) { + (void) memcpy(params, &reply.pad3, sizeof(GLfloat)); + } + else { + _XRead(dpy, (void *) params, 4 * reply.size); + } + } + } + + UnlockDisplay(dpy); + SyncHandle(); +} + + +void +__indirect_glGetVertexAttribdvARB(GLuint index, GLenum pname, + GLdouble * params) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + xGLXSingleReply reply; + + + get_vertex_attrib(gc, 1301, index, pname, (xReply *) & reply); + + if (reply.size != 0) { + GLintptr data; + + + if (get_attrib_array_data(state, index, pname, &data)) { + *params = (GLdouble) data; + } + else { + if (reply.size == 1) { + (void) memcpy(params, &reply.pad3, sizeof(GLdouble)); + } + else { + _XRead(dpy, (void *) params, 8 * reply.size); + } + } + } + + UnlockDisplay(dpy); + SyncHandle(); +} diff --git a/src/glx/indirect_window_pos.c b/src/glx/indirect_window_pos.c new file mode 100644 index 0000000..e97be35 --- /dev/null +++ b/src/glx/indirect_window_pos.c @@ -0,0 +1,112 @@ +/* + * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. + * (C) Copyright IBM Corporation 2004 + * 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 + * PRECISION INSIGHT, IBM, + * 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 +#include "indirect.h" + +void +__indirect_glWindowPos2dMESA(GLdouble x, GLdouble y) +{ + __indirect_glWindowPos3fMESA(x, y, 0.0); +} + +void +__indirect_glWindowPos2iMESA(GLint x, GLint y) +{ + __indirect_glWindowPos3fMESA(x, y, 0.0); +} + +void +__indirect_glWindowPos2fMESA(GLfloat x, GLfloat y) +{ + __indirect_glWindowPos3fMESA(x, y, 0.0); +} + +void +__indirect_glWindowPos2sMESA(GLshort x, GLshort y) +{ + __indirect_glWindowPos3fMESA(x, y, 0.0); +} + +void +__indirect_glWindowPos2dvMESA(const GLdouble * p) +{ + __indirect_glWindowPos3fMESA(p[0], p[1], 0.0); +} + +void +__indirect_glWindowPos2fvMESA(const GLfloat * p) +{ + __indirect_glWindowPos3fMESA(p[0], p[1], 0.0); +} + +void +__indirect_glWindowPos2ivMESA(const GLint * p) +{ + __indirect_glWindowPos3fMESA(p[0], p[1], 0.0); +} + +void +__indirect_glWindowPos2svMESA(const GLshort * p) +{ + __indirect_glWindowPos3fMESA(p[0], p[1], 0.0); +} + +void +__indirect_glWindowPos3dMESA(GLdouble x, GLdouble y, GLdouble z) +{ + __indirect_glWindowPos3fMESA(x, y, z); +} + +void +__indirect_glWindowPos3iMESA(GLint x, GLint y, GLint z) +{ + __indirect_glWindowPos3fMESA(x, y, z); +} + +void +__indirect_glWindowPos3sMESA(GLshort x, GLshort y, GLshort z) +{ + __indirect_glWindowPos3fMESA(x, y, z); +} + +void +__indirect_glWindowPos3dvMESA(const GLdouble * p) +{ + __indirect_glWindowPos3fMESA(p[0], p[1], p[2]); +} + +void +__indirect_glWindowPos3ivMESA(const GLint * p) +{ + __indirect_glWindowPos3fMESA(p[0], p[1], p[2]); +} + +void +__indirect_glWindowPos3svMESA(const GLshort * p) +{ + __indirect_glWindowPos3fMESA(p[0], p[1], p[2]); +} diff --git a/src/glx/packrender.h b/src/glx/packrender.h new file mode 100644 index 0000000..4266d5c --- /dev/null +++ b/src/glx/packrender.h @@ -0,0 +1,243 @@ +#ifndef __GLX_packrender_h__ +#define __GLX_packrender_h__ + +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "glxclient.h" + +/* +** The macros in this header convert the client machine's native data types to +** wire protocol data types. The header is part of the porting layer of the +** client library, and it is intended that hardware vendors will rewrite this +** header to suit their own machines. +*/ + +/* +** Pad a count of bytes to the nearest multiple of 4. The X protocol +** transfers data in 4 byte quantities, so this macro is used to +** insure the right amount of data being sent. +*/ +#define __GLX_PAD(a) (((a)+3) & ~3) + +/* +** Network size parameters +*/ +#define sz_double 8 + +/* Setup for all commands */ +#define __GLX_DECLARE_VARIABLES() \ + struct glx_context *gc; \ + GLubyte *pc, *pixelHeaderPC; \ + GLuint compsize, cmdlen + +#define __GLX_LOAD_VARIABLES() \ + gc = __glXGetCurrentContext(); \ + pc = gc->pc; \ + /* Muffle compilers */ \ + cmdlen = 0; (void)cmdlen; \ + compsize = 0; (void)compsize; \ + pixelHeaderPC = 0; (void)pixelHeaderPC + +/* +** Variable sized command support macro. This macro is used by calls +** that are potentially larger than __GLX_SMALL_RENDER_CMD_SIZE. +** Because of their size, they may not automatically fit in the buffer. +** If the buffer can't hold the command then it is flushed so that +** the command will fit in the next buffer. +*/ +#define __GLX_BEGIN_VARIABLE(opcode,size) \ + if (pc + (size) > gc->bufEnd) { \ + pc = __glXFlushRenderBuffer(gc, pc); \ + } \ + __GLX_PUT_SHORT(0,size); \ + __GLX_PUT_SHORT(2,opcode) + +#define __GLX_BEGIN_VARIABLE_LARGE(opcode,size) \ + pc = __glXFlushRenderBuffer(gc, pc); \ + __GLX_PUT_LONG(0,size); \ + __GLX_PUT_LONG(4,opcode) + +#define __GLX_BEGIN_VARIABLE_WITH_PIXEL(opcode,size) \ + if (pc + (size) > gc->bufEnd) { \ + pc = __glXFlushRenderBuffer(gc, pc); \ + } \ + __GLX_PUT_SHORT(0,size); \ + __GLX_PUT_SHORT(2,opcode); \ + pc += __GLX_RENDER_HDR_SIZE; \ + pixelHeaderPC = pc; \ + pc += __GLX_PIXEL_HDR_SIZE + +#define __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(opcode,size) \ + pc = __glXFlushRenderBuffer(gc, pc); \ + __GLX_PUT_LONG(0,size); \ + __GLX_PUT_LONG(4,opcode); \ + pc += __GLX_RENDER_LARGE_HDR_SIZE; \ + pixelHeaderPC = pc; \ + pc += __GLX_PIXEL_HDR_SIZE + +#define __GLX_BEGIN_VARIABLE_WITH_PIXEL_3D(opcode,size) \ + if (pc + (size) > gc->bufEnd) { \ + pc = __glXFlushRenderBuffer(gc, pc); \ + } \ + __GLX_PUT_SHORT(0,size); \ + __GLX_PUT_SHORT(2,opcode); \ + pc += __GLX_RENDER_HDR_SIZE; \ + pixelHeaderPC = pc; \ + pc += __GLX_PIXEL_3D_HDR_SIZE + +#define __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL_3D(opcode,size) \ + pc = __glXFlushRenderBuffer(gc, pc); \ + __GLX_PUT_LONG(0,size); \ + __GLX_PUT_LONG(4,opcode); \ + pc += __GLX_RENDER_LARGE_HDR_SIZE; \ + pixelHeaderPC = pc; \ + pc += __GLX_PIXEL_3D_HDR_SIZE + +/* +** Fixed size command support macro. This macro is used by calls that +** are never larger than __GLX_SMALL_RENDER_CMD_SIZE. Because they +** always fit in the buffer, and because the buffer promises to +** maintain enough room for them, we don't need to check for space +** before doing the storage work. +*/ +#define __GLX_BEGIN(opcode,size) \ + __GLX_PUT_SHORT(0,size); \ + __GLX_PUT_SHORT(2,opcode) + +/* +** Finish a rendering command by advancing the pc. If the pc is now past +** the limit pointer then there is no longer room for a +** __GLX_SMALL_RENDER_CMD_SIZE sized command, which will break the +** assumptions present in the __GLX_BEGIN macro. In this case the +** rendering buffer is flushed out into the X protocol stream (which may +** or may not do I/O). +*/ +#define __GLX_END(size) \ + pc += size; \ + if (pc > gc->limit) { \ + (void) __glXFlushRenderBuffer(gc, pc); \ + } else { \ + gc->pc = pc; \ + } + +/* Array copy macros */ +#define __GLX_MEM_COPY(dest,src,bytes) \ + if (src && dest) \ + memcpy(dest, src, bytes) + +/* Single item copy macros */ +#define __GLX_PUT_CHAR(offset,a) \ + *((INT8 *) (pc + offset)) = a + +#ifndef _CRAY +#define __GLX_PUT_SHORT(offset,a) \ + *((INT16 *) (pc + offset)) = a + +#define __GLX_PUT_LONG(offset,a) \ + *((INT32 *) (pc + offset)) = a + +#define __GLX_PUT_FLOAT(offset,a) \ + *((FLOAT32 *) (pc + offset)) = a + +#else +#define __GLX_PUT_SHORT(offset,a) \ + { GLubyte *cp = (pc+offset); \ + int shift = (64-16) - ((int)(cp) >> (64-6)); \ + *(int *)cp = (*(int *)cp & ~(0xffff << shift)) | ((a & 0xffff) << shift); } + +#define __GLX_PUT_LONG(offset,a) \ + { GLubyte *cp = (pc+offset); \ + int shift = (64-32) - ((int)(cp) >> (64-6)); \ + *(int *)cp = (*(int *)cp & ~(0xffffffff << shift)) | ((a & 0xffffffff) << shift); } + +#define __GLX_PUT_FLOAT(offset,a) \ + gl_put_float((pc + offset),a) + +#define __GLX_PUT_DOUBLE(offset,a) \ + gl_put_double(pc + offset, a) + +extern void gl_put_float( /*GLubyte *, struct cray_single */ ); +extern void gl_put_double( /*GLubyte *, struct cray_double */ ); +#endif + +#ifndef _CRAY + +#ifdef __GLX_ALIGN64 +/* +** This can certainly be done better for a particular machine +** architecture! +*/ +#define __GLX_PUT_DOUBLE(offset,a) \ + __GLX_MEM_COPY(pc + offset, &a, 8) +#else +#define __GLX_PUT_DOUBLE(offset,a) \ + *((FLOAT64 *) (pc + offset)) = a +#endif + +#endif + +#define __GLX_PUT_CHAR_ARRAY(offset,a,alen) \ + __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT8) + +#ifndef _CRAY +#define __GLX_PUT_SHORT_ARRAY(offset,a,alen) \ + __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT16) + +#define __GLX_PUT_LONG_ARRAY(offset,a,alen) \ + __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT32) + +#define __GLX_PUT_FLOAT_ARRAY(offset,a,alen) \ + __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_FLOAT32) + +#define __GLX_PUT_DOUBLE_ARRAY(offset,a,alen) \ + __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_FLOAT64) + +#else +#define __GLX_PUT_SHORT_ARRAY(offset,a,alen) \ + gl_put_short_array((GLubyte *)(pc + offset), a, alen * __GLX_SIZE_INT16) + +#define __GLX_PUT_LONG_ARRAY(offset,a,alen) \ + gl_put_long_array((GLubyte *)(pc + offset), (long *)a, alen * __GLX_SIZE_INT32) + +#define __GLX_PUT_FLOAT_ARRAY(offset,a,alen) \ + gl_put_float_array((GLubyte *)(pc + offset), (float *)a, alen * __GLX_SIZE_FLOAT32) + +#define __GLX_PUT_DOUBLE_ARRAY(offset,a,alen) \ + gl_put_double_array((GLubyte *)(pc + offset), (double *)a, alen * __GLX_SIZE_FLOAT64) + +extern gl_put_short_array(GLubyte *, short *, int); +extern gl_put_long_array(GLubyte *, long *, int); +extern gl_put_float_array(GLubyte *, float *, int); +extern gl_put_double_array(GLubyte *, double *, int); + +#endif /* _CRAY */ + +#endif /* !__GLX_packrender_h__ */ diff --git a/src/glx/packsingle.h b/src/glx/packsingle.h new file mode 100644 index 0000000..037265a --- /dev/null +++ b/src/glx/packsingle.h @@ -0,0 +1,213 @@ +#ifndef __GLX_packsingle_h__ +#define __GLX_packsingle_h__ + +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "packrender.h" + +/* +** The macros in this header convert wire protocol data types to the client +** machine's native data types. The header is part of the porting layer of +** the client library, and it is intended that hardware vendors will rewrite +** this header to suit their own machines. +*/ + +/* +** Dummy define to make the GetReqExtra macro happy. The value is not +** used, but instead the code in __GLX_SINGLE_BEGIN issues its own store +** to req->reqType with the proper code (our extension code). +*/ +#define X_GLXSingle 0 + +/* Declare common variables used during a single command */ +#define __GLX_SINGLE_DECLARE_VARIABLES() \ + struct glx_context *gc = __glXGetCurrentContext(); \ + GLubyte *pc, *pixelHeaderPC; \ + GLuint compsize, cmdlen; \ + Display *dpy = gc->currentDpy; \ + xGLXSingleReq *req + +#define __GLX_SINGLE_LOAD_VARIABLES() \ + pc = gc->pc; \ + /* Muffle compilers */ \ + pixelHeaderPC = 0; (void)pixelHeaderPC; \ + compsize = 0; (void)compsize; \ + cmdlen = 0; (void)cmdlen + +/* Start a single command */ +#define __GLX_SINGLE_BEGIN(opcode,bytes) \ + if (dpy) { \ + (void) __glXFlushRenderBuffer(gc, pc); \ + LockDisplay(dpy); \ + GetReqExtra(GLXSingle,bytes,req); \ + req->reqType = gc->majorOpcode; \ + req->glxCode = opcode; \ + req->contextTag = gc->currentContextTag; \ + pc = ((GLubyte *)(req) + sz_xGLXSingleReq) + +/* End a single command */ +#define __GLX_SINGLE_END() \ + UnlockDisplay(dpy); \ + SyncHandle(); \ + } + +/* Store data to sending for a single command */ +#define __GLX_SINGLE_PUT_CHAR(offset,a) \ + *((INT8 *) (pc + offset)) = a + +#ifndef CRAY +#define __GLX_SINGLE_PUT_SHORT(offset,a) \ + *((INT16 *) (pc + offset)) = a + +#define __GLX_SINGLE_PUT_LONG(offset,a) \ + *((INT32 *) (pc + offset)) = a + +#define __GLX_SINGLE_PUT_FLOAT(offset,a) \ + *((FLOAT32 *) (pc + offset)) = a + +#else +#define __GLX_SINGLE_PUT_SHORT(offset,a) \ + { GLubyte *cp = (pc+offset); \ + int shift = (64-16) - ((int)(cp) >> (64-6)); \ + *(int *)cp = (*(int *)cp & ~(0xffff << shift)) | ((a & 0xffff) << shift); } + +#define __GLX_SINGLE_PUT_LONG(offset,a) \ + { GLubyte *cp = (pc+offset); \ + int shift = (64-32) - ((int)(cp) >> (64-6)); \ + *(int *)cp = (*(int *)cp & ~(0xffffffff << shift)) | ((a & 0xffffffff) << shift); } + +#define __GLX_SINGLE_PUT_FLOAT(offset,a) \ + gl_put_float(pc + offset, a) +#endif + +/* Read support macros */ +#define __GLX_SINGLE_READ_XREPLY() \ + (void) _XReply(dpy, (xReply*) &reply, 0, False) + +#define __GLX_SINGLE_GET_RETVAL(a,cast) \ + a = (cast) reply.retval + +#define __GLX_SINGLE_GET_SIZE(a) \ + a = (GLint) reply.size + +#ifndef _CRAY +#define __GLX_SINGLE_GET_CHAR(p) \ + *p = *(GLbyte *)&reply.pad3; + +#define __GLX_SINGLE_GET_SHORT(p) \ + *p = *(GLshort *)&reply.pad3; + +#define __GLX_SINGLE_GET_LONG(p) \ + *p = *(GLint *)&reply.pad3; + +#define __GLX_SINGLE_GET_FLOAT(p) \ + *p = *(GLfloat *)&reply.pad3; + +#else +#define __GLX_SINGLE_GET_CHAR(p) \ + *p = reply.pad3 >> 24; + +#define __GLX_SINGLE_GET_SHORT(p) \ + {int t = reply.pad3 >> 16; \ + *p = (t & 0x8000) ? (t | ~0xffff) : (t & 0xffff);} + +#define __GLX_SINGLE_GET_LONG(p) \ + {int t = reply.pad3; \ + *p = (t & 0x80000000) ? (t | ~0xffffffff) : (t & 0xffffffff);} + +#define PAD3OFFSET 16 +#define __GLX_SINGLE_GET_FLOAT(p) \ + *p = gl_ntoh_float((GLubyte *)&reply + PAD3OFFSET); + +#define __GLX_SINGLE_GET_DOUBLE(p) \ + *p = gl_ntoh_double((GLubyte *)&reply + PAD3OFFSET); + +extern float gl_ntoh_float(GLubyte *); +extern float gl_ntoh_double(GLubyte *); +#endif + +#ifndef _CRAY + +#ifdef __GLX_ALIGN64 +#define __GLX_SINGLE_GET_DOUBLE(p) \ + __GLX_MEM_COPY(p, &reply.pad3, 8) +#else +#define __GLX_SINGLE_GET_DOUBLE(p) \ + *p = *(GLdouble *)&reply.pad3 +#endif + +#endif + +/* Get an array of typed data */ +#define __GLX_SINGLE_GET_VOID_ARRAY(a,alen) \ + { \ + GLint slop = alen*__GLX_SIZE_INT8 & 3; \ + _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT8); \ + if (slop) _XEatData(dpy,4-slop); \ + } + +#define __GLX_SINGLE_GET_CHAR_ARRAY(a,alen) \ + { \ + GLint slop = alen*__GLX_SIZE_INT8 & 3; \ + _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT8); \ + if (slop) _XEatData(dpy,4-slop); \ + } + + +#define __GLX_SINGLE_GET_SHORT_ARRAY(a,alen) \ + { \ + GLint slop = (alen*__GLX_SIZE_INT16) & 3; \ + _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT16); \ + if (slop) _XEatData(dpy,4-slop); \ + } + +#define __GLX_SINGLE_GET_LONG_ARRAY(a,alen) \ + _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT32); + +#ifndef _CRAY +#define __GLX_SINGLE_GET_FLOAT_ARRAY(a,alen) \ + _XRead(dpy,(char *)a,alen*__GLX_SIZE_FLOAT32); + +#define __GLX_SINGLE_GET_DOUBLE_ARRAY(a,alen) \ + _XRead(dpy,(char *)a,alen*__GLX_SIZE_FLOAT64); + +#else +#define __GLX_SINGLE_GET_FLOAT_ARRAY(a,alen) \ + gl_get_float_array(dpy,a,alen); + +#define __GLX_SINGLE_GET_DOUBLE_ARRAY(a,alen) \ + gl_get_double_array(dpy, a, alen); + +extern void gl_get_float_array(Display * dpy, float *a, int alen); +extern void gl_get_double_array(Display * dpy, double *a, int alen); +#endif + +#endif /* !__GLX_packsingle_h__ */ diff --git a/src/glx/pixel.c b/src/glx/pixel.c new file mode 100644 index 0000000..d508d62 --- /dev/null +++ b/src/glx/pixel.c @@ -0,0 +1,461 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "packrender.h" + +static const GLubyte MsbToLsbTable[256] = { + 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, + 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, + 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, + 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, + 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, + 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, + 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, + 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, + 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, + 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, + 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, + 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, + 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, + 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, + 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, + 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, + 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, + 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, + 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, + 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, + 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, + 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, + 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, + 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, + 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, + 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, + 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, + 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, + 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, + 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, + 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, + 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff, +}; + +static const GLubyte LowBitsMask[9] = { + 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, +}; + +static const GLubyte HighBitsMask[9] = { + 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff, +}; + + +/* +** Copy bitmap data from clients packed memory applying unpacking modes as the +** data is transfered into the destImage buffer. Return in modes the +** set of pixel modes that are to be done by the server. +*/ +static void +FillBitmap(struct glx_context * gc, GLint width, GLint height, + GLenum format, const GLvoid * userdata, GLubyte * destImage) +{ + const __GLXattribute *state = gc->client_state_private; + GLint rowLength = state->storeUnpack.rowLength; + GLint alignment = state->storeUnpack.alignment; + GLint skipPixels = state->storeUnpack.skipPixels; + GLint skipRows = state->storeUnpack.skipRows; + GLint lsbFirst = state->storeUnpack.lsbFirst; + GLint elementsLeft, bitOffset, currentByte, nextByte, highBitMask; + GLint lowBitMask, i; + GLint components, groupsPerRow, rowSize, padding, elementsPerRow; + const GLubyte *start, *iter; + + if (rowLength > 0) { + groupsPerRow = rowLength; + } + else { + groupsPerRow = width; + } + components = __glElementsPerGroup(format, GL_BITMAP); + rowSize = (groupsPerRow * components + 7) >> 3; + padding = (rowSize % alignment); + if (padding) { + rowSize += alignment - padding; + } + start = ((const GLubyte *) userdata) + skipRows * rowSize + + ((skipPixels * components) >> 3); + bitOffset = (skipPixels * components) & 7; + highBitMask = LowBitsMask[8 - bitOffset]; + lowBitMask = HighBitsMask[bitOffset]; + elementsPerRow = width * components; + for (i = 0; i < height; i++) { + elementsLeft = elementsPerRow; + iter = start; + while (elementsLeft) { + /* First retrieve low bits from current byte */ + if (lsbFirst) { + currentByte = MsbToLsbTable[iter[0]]; + } + else { + currentByte = iter[0]; + } + if (bitOffset) { + /* Need to read next byte to finish current byte */ + if (elementsLeft > (8 - bitOffset)) { + if (lsbFirst) { + nextByte = MsbToLsbTable[iter[1]]; + } + else { + nextByte = iter[1]; + } + currentByte = + ((currentByte & highBitMask) << bitOffset) | + ((nextByte & lowBitMask) >> (8 - bitOffset)); + } + else { + currentByte = ((currentByte & highBitMask) << bitOffset); + } + } + if (elementsLeft >= 8) { + *destImage = currentByte; + elementsLeft -= 8; + } + else { + *destImage = currentByte & HighBitsMask[elementsLeft]; + elementsLeft = 0; + } + destImage++; + iter++; + } + start += rowSize; + } +} + +/* +** Extract array from user's data applying all pixel store modes. +** The internal packed array format used has LSB_FIRST = FALSE and +** ALIGNMENT = 1. +*/ +void +__glFillImage(struct glx_context * gc, GLint dim, GLint width, GLint height, + GLint depth, GLenum format, GLenum type, + const GLvoid * userdata, GLubyte * newimage, GLubyte * modes) +{ + const __GLXattribute *state = gc->client_state_private; + GLint rowLength = state->storeUnpack.rowLength; + GLint imageHeight = state->storeUnpack.imageHeight; + GLint alignment = state->storeUnpack.alignment; + GLint skipPixels = state->storeUnpack.skipPixels; + GLint skipRows = state->storeUnpack.skipRows; + GLint skipImages = state->storeUnpack.skipImages; + GLint swapBytes = state->storeUnpack.swapEndian; + GLint components, elementSize, rowSize, padding, groupsPerRow, groupSize; + GLint elementsPerRow, imageSize, rowsPerImage, h, i, j, k; + const GLubyte *start, *iter, *itera, *iterb, *iterc; + GLubyte *iter2; + + if (type == GL_BITMAP) { + FillBitmap(gc, width, height, format, userdata, newimage); + } + else { + components = __glElementsPerGroup(format, type); + if (rowLength > 0) { + groupsPerRow = rowLength; + } + else { + groupsPerRow = width; + } + if (imageHeight > 0) { + rowsPerImage = imageHeight; + } + else { + rowsPerImage = height; + } + + elementSize = __glBytesPerElement(type); + groupSize = elementSize * components; + if (elementSize == 1) + swapBytes = 0; + + rowSize = groupsPerRow * groupSize; + padding = (rowSize % alignment); + if (padding) { + rowSize += alignment - padding; + } + imageSize = rowSize * rowsPerImage; + start = ((const GLubyte *) userdata) + skipImages * imageSize + + skipRows * rowSize + skipPixels * groupSize; + iter2 = newimage; + elementsPerRow = width * components; + + if (swapBytes) { + itera = start; + for (h = 0; h < depth; h++) { + iterb = itera; + for (i = 0; i < height; i++) { + iterc = iterb; + for (j = 0; j < elementsPerRow; j++) { + for (k = 1; k <= elementSize; k++) { + iter2[k - 1] = iterc[elementSize - k]; + } + iter2 += elementSize; + iterc += elementSize; + } + iterb += rowSize; + } + itera += imageSize; + } + } + else { + itera = start; + for (h = 0; h < depth; h++) { + if (rowSize == elementsPerRow * elementSize) { + /* Ha! This is mondo easy! */ + __GLX_MEM_COPY(iter2, itera, + elementsPerRow * elementSize * height); + iter2 += elementsPerRow * elementSize * height; + } + else { + iter = itera; + for (i = 0; i < height; i++) { + __GLX_MEM_COPY(iter2, iter, elementsPerRow * elementSize); + iter2 += elementsPerRow * elementSize; + iter += rowSize; + } + } + itera += imageSize; + } + } + } + + /* Setup store modes that describe what we just did */ + if (modes) { + if (dim < 3) { + (void) memcpy(modes, __glXDefaultPixelStore + 4, 20); + } + else { + (void) memcpy(modes, __glXDefaultPixelStore + 0, 36); + } + } +} + +/* +** Empty a bitmap in LSB_FIRST=GL_FALSE and ALIGNMENT=4 format packing it +** into the clients memory using the pixel store PACK modes. +*/ +static void +EmptyBitmap(struct glx_context * gc, GLint width, GLint height, + GLenum format, const GLubyte * sourceImage, GLvoid * userdata) +{ + const __GLXattribute *state = gc->client_state_private; + GLint rowLength = state->storePack.rowLength; + GLint alignment = state->storePack.alignment; + GLint skipPixels = state->storePack.skipPixels; + GLint skipRows = state->storePack.skipRows; + GLint lsbFirst = state->storePack.lsbFirst; + GLint components, groupsPerRow, rowSize, padding, elementsPerRow; + GLint sourceRowSize, sourcePadding, sourceSkip; + GLubyte *start, *iter; + GLint elementsLeft, bitOffset, currentByte, highBitMask, lowBitMask; + GLint writeMask, i; + GLubyte writeByte; + + components = __glElementsPerGroup(format, GL_BITMAP); + if (rowLength > 0) { + groupsPerRow = rowLength; + } + else { + groupsPerRow = width; + } + + rowSize = (groupsPerRow * components + 7) >> 3; + padding = (rowSize % alignment); + if (padding) { + rowSize += alignment - padding; + } + sourceRowSize = (width * components + 7) >> 3; + sourcePadding = (sourceRowSize % 4); + if (sourcePadding) { + sourceSkip = 4 - sourcePadding; + } + else { + sourceSkip = 0; + } + start = ((GLubyte *) userdata) + skipRows * rowSize + + ((skipPixels * components) >> 3); + bitOffset = (skipPixels * components) & 7; + highBitMask = LowBitsMask[8 - bitOffset]; + lowBitMask = HighBitsMask[bitOffset]; + elementsPerRow = width * components; + for (i = 0; i < height; i++) { + elementsLeft = elementsPerRow; + iter = start; + writeMask = highBitMask; + writeByte = 0; + while (elementsLeft) { + /* Set up writeMask (to write to current byte) */ + if (elementsLeft + bitOffset < 8) { + /* Need to trim writeMask */ + writeMask &= HighBitsMask[bitOffset + elementsLeft]; + } + + if (lsbFirst) { + currentByte = MsbToLsbTable[iter[0]]; + } + else { + currentByte = iter[0]; + } + + if (bitOffset) { + writeByte |= (sourceImage[0] >> bitOffset); + currentByte = (currentByte & ~writeMask) | + (writeByte & writeMask); + writeByte = (sourceImage[0] << (8 - bitOffset)); + } + else { + currentByte = (currentByte & ~writeMask) | + (sourceImage[0] & writeMask); + } + + if (lsbFirst) { + iter[0] = MsbToLsbTable[currentByte]; + } + else { + iter[0] = currentByte; + } + + if (elementsLeft >= 8) { + elementsLeft -= 8; + } + else { + elementsLeft = 0; + } + sourceImage++; + iter++; + writeMask = 0xff; + } + if (writeByte) { + /* Some data left over that still needs writing */ + writeMask &= lowBitMask; + if (lsbFirst) { + currentByte = MsbToLsbTable[iter[0]]; + } + else { + currentByte = iter[0]; + } + currentByte = (currentByte & ~writeMask) | (writeByte & writeMask); + if (lsbFirst) { + iter[0] = MsbToLsbTable[currentByte]; + } + else { + iter[0] = currentByte; + } + } + start += rowSize; + sourceImage += sourceSkip; + } +} + +/* +** Insert array into user's data applying all pixel store modes. +** The packed array format from the server is LSB_FIRST = FALSE, +** SWAP_BYTES = the current pixel storage pack mode, and ALIGNMENT = 4. +** Named __glEmptyImage() because it is the opposite of __glFillImage(). +*/ +/* ARGSUSED */ +void +__glEmptyImage(struct glx_context * gc, GLint dim, GLint width, GLint height, + GLint depth, GLenum format, GLenum type, + const GLubyte * sourceImage, GLvoid * userdata) +{ + const __GLXattribute *state = gc->client_state_private; + GLint rowLength = state->storePack.rowLength; + GLint imageHeight = state->storePack.imageHeight; + GLint alignment = state->storePack.alignment; + GLint skipPixels = state->storePack.skipPixels; + GLint skipRows = state->storePack.skipRows; + GLint skipImages = state->storePack.skipImages; + GLint components, elementSize, rowSize, padding, groupsPerRow, groupSize; + GLint elementsPerRow, sourceRowSize, sourcePadding, h, i; + GLint imageSize, rowsPerImage; + GLubyte *start, *iter, *itera; + + if (type == GL_BITMAP) { + EmptyBitmap(gc, width, height, format, sourceImage, userdata); + } + else { + components = __glElementsPerGroup(format, type); + if (rowLength > 0) { + groupsPerRow = rowLength; + } + else { + groupsPerRow = width; + } + if (imageHeight > 0) { + rowsPerImage = imageHeight; + } + else { + rowsPerImage = height; + } + elementSize = __glBytesPerElement(type); + groupSize = elementSize * components; + rowSize = groupsPerRow * groupSize; + padding = (rowSize % alignment); + if (padding) { + rowSize += alignment - padding; + } + sourceRowSize = width * groupSize; + sourcePadding = (sourceRowSize % 4); + if (sourcePadding) { + sourceRowSize += 4 - sourcePadding; + } + imageSize = sourceRowSize * rowsPerImage; + start = ((GLubyte *) userdata) + skipImages * imageSize + + skipRows * rowSize + skipPixels * groupSize; + elementsPerRow = width * components; + + itera = start; + for (h = 0; h < depth; h++) { + if ((rowSize == sourceRowSize) && (sourcePadding == 0)) { + /* Ha! This is mondo easy! */ + __GLX_MEM_COPY(itera, sourceImage, + elementsPerRow * elementSize * height); + sourceImage += elementsPerRow * elementSize * height; + } + else { + iter = itera; + for (i = 0; i < height; i++) { + __GLX_MEM_COPY(iter, sourceImage, + elementsPerRow * elementSize); + sourceImage += sourceRowSize; + iter += rowSize; + } + } + itera += imageSize; + } + } +} diff --git a/src/glx/pixelstore.c b/src/glx/pixelstore.c new file mode 100644 index 0000000..1d776b8 --- /dev/null +++ b/src/glx/pixelstore.c @@ -0,0 +1,352 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "glxclient.h" +#include "indirect.h" + +#if !defined(__GNUC__) +# define __builtin_expect(x, y) x +#endif + +/** + * Send glPixelStore command to the server + * + * \param gc Current GLX context + * \param sop Either \c X_GLsop_PixelStoref or \c X_GLsop_PixelStorei + * \param pname Selector of which pixel parameter is to be set. + * \param param Value that \c pname is set to. + * + * \sa __indirect_glPixelStorei, __indirect_glPixelStoref + */ +static void +send_PixelStore(struct glx_context * gc, unsigned sop, GLenum pname, + const void *param) +{ + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = 8; + if (__builtin_expect(dpy != NULL, 1)) { + GLubyte const *pc = __glXSetupSingleRequest(gc, sop, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&pname), 4); + (void) memcpy((void *) (pc + 4), param, 4); + UnlockDisplay(dpy); + SyncHandle(); + } + return; +} + +/* +** Specify parameters that control the storage format of pixel arrays. +*/ +void +__indirect_glPixelStoref(GLenum pname, GLfloat param) +{ + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = gc->client_state_private; + Display *dpy = gc->currentDpy; + GLuint a; + + if (!dpy) + return; + + switch (pname) { + case GL_PACK_ROW_LENGTH: + a = (GLuint) (param + 0.5); + if (((GLint) a) < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storePack.rowLength = a; + break; + case GL_PACK_IMAGE_HEIGHT: + a = (GLuint) (param + 0.5); + if (((GLint) a) < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storePack.imageHeight = a; + break; + case GL_PACK_SKIP_ROWS: + a = (GLuint) (param + 0.5); + if (((GLint) a) < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storePack.skipRows = a; + break; + case GL_PACK_SKIP_PIXELS: + a = (GLuint) (param + 0.5); + if (((GLint) a) < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storePack.skipPixels = a; + break; + case GL_PACK_SKIP_IMAGES: + a = (GLuint) (param + 0.5); + if (((GLint) a) < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storePack.skipImages = a; + break; + case GL_PACK_ALIGNMENT: + a = (GLint) (param + 0.5); + switch (a) { + case 1: + case 2: + case 4: + case 8: + state->storePack.alignment = a; + break; + default: + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + break; + case GL_PACK_SWAP_BYTES: + state->storePack.swapEndian = (param != 0); + break; + case GL_PACK_LSB_FIRST: + state->storePack.lsbFirst = (param != 0); + break; + + case GL_UNPACK_ROW_LENGTH: + a = (GLuint) (param + 0.5); + if (((GLint) a) < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storeUnpack.rowLength = a; + break; + case GL_UNPACK_IMAGE_HEIGHT: + a = (GLuint) (param + 0.5); + if (((GLint) a) < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storeUnpack.imageHeight = a; + break; + case GL_UNPACK_SKIP_ROWS: + a = (GLuint) (param + 0.5); + if (((GLint) a) < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storeUnpack.skipRows = a; + break; + case GL_UNPACK_SKIP_PIXELS: + a = (GLuint) (param + 0.5); + if (((GLint) a) < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storeUnpack.skipPixels = a; + break; + case GL_UNPACK_SKIP_IMAGES: + a = (GLuint) (param + 0.5); + if (((GLint) a) < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storeUnpack.skipImages = a; + break; + case GL_UNPACK_ALIGNMENT: + a = (GLint) (param + 0.5); + switch (a) { + case 1: + case 2: + case 4: + case 8: + state->storeUnpack.alignment = a; + break; + default: + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + break; + case GL_UNPACK_SWAP_BYTES: + state->storeUnpack.swapEndian = (param != 0); + break; + case GL_UNPACK_LSB_FIRST: + state->storeUnpack.lsbFirst = (param != 0); + break; + + /* Group all of the pixel store modes that need to be sent to the + * server here. Care must be used to only send modes to the server that + * won't affect the size of the data sent to or received from the + * server. GL_PACK_INVERT_MESA is safe in this respect, but other, + * future modes may not be. + */ + case GL_PACK_INVERT_MESA: + send_PixelStore(gc, X_GLsop_PixelStoref, pname, ¶m); + break; + + default: + __glXSetError(gc, GL_INVALID_ENUM); + break; + } +} + +void +__indirect_glPixelStorei(GLenum pname, GLint param) +{ + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = gc->client_state_private; + Display *dpy = gc->currentDpy; + + if (!dpy) + return; + + switch (pname) { + case GL_PACK_ROW_LENGTH: + if (param < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storePack.rowLength = param; + break; + case GL_PACK_IMAGE_HEIGHT: + if (param < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storePack.imageHeight = param; + break; + case GL_PACK_SKIP_ROWS: + if (param < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storePack.skipRows = param; + break; + case GL_PACK_SKIP_PIXELS: + if (param < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storePack.skipPixels = param; + break; + case GL_PACK_SKIP_IMAGES: + if (param < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storePack.skipImages = param; + break; + case GL_PACK_ALIGNMENT: + switch (param) { + case 1: + case 2: + case 4: + case 8: + state->storePack.alignment = param; + break; + default: + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + break; + case GL_PACK_SWAP_BYTES: + state->storePack.swapEndian = (param != 0); + break; + case GL_PACK_LSB_FIRST: + state->storePack.lsbFirst = (param != 0); + break; + + case GL_UNPACK_ROW_LENGTH: + if (param < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storeUnpack.rowLength = param; + break; + case GL_UNPACK_IMAGE_HEIGHT: + if (param < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storeUnpack.imageHeight = param; + break; + case GL_UNPACK_SKIP_ROWS: + if (param < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storeUnpack.skipRows = param; + break; + case GL_UNPACK_SKIP_PIXELS: + if (param < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storeUnpack.skipPixels = param; + break; + case GL_UNPACK_SKIP_IMAGES: + if (param < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + state->storeUnpack.skipImages = param; + break; + case GL_UNPACK_ALIGNMENT: + switch (param) { + case 1: + case 2: + case 4: + case 8: + state->storeUnpack.alignment = param; + break; + default: + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + break; + case GL_UNPACK_SWAP_BYTES: + state->storeUnpack.swapEndian = (param != 0); + break; + case GL_UNPACK_LSB_FIRST: + state->storeUnpack.lsbFirst = (param != 0); + break; + + /* Group all of the pixel store modes that need to be sent to the + * server here. Care must be used to only send modes to the server that + * won't affect the size of the data sent to or received from the + * server. GL_PACK_INVERT_MESA is safe in this respect, but other, + * future modes may not be. + */ + case GL_PACK_INVERT_MESA: + send_PixelStore(gc, X_GLsop_PixelStorei, pname, ¶m); + break; + + default: + __glXSetError(gc, GL_INVALID_ENUM); + break; + } +} diff --git a/src/glx/render2.c b/src/glx/render2.c new file mode 100644 index 0000000..762950f --- /dev/null +++ b/src/glx/render2.c @@ -0,0 +1,381 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "packrender.h" +#include "indirect.h" +#include "indirect_size.h" + +/* +** This file contains routines that might need to be transported as +** GLXRender or GLXRenderLarge commands, and these commands don't +** use the pixel header. See renderpix.c for those routines. +*/ + +void +__indirect_glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride, + GLint order, const GLdouble * pnts) +{ + __GLX_DECLARE_VARIABLES(); + GLint k; + + __GLX_LOAD_VARIABLES(); + k = __glMap1d_size(target); + if (k == 0) { + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + else if (stride < k || order <= 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + compsize = k * order * __GLX_SIZE_FLOAT64; + cmdlen = 28 + compsize; + if (!gc->currentDpy) + return; + + if (cmdlen <= gc->maxSmallRenderCommandSize) { + /* Use GLXRender protocol to send small command */ + __GLX_BEGIN_VARIABLE(X_GLrop_Map1d, cmdlen); + __GLX_PUT_DOUBLE(4, u1); + __GLX_PUT_DOUBLE(12, u2); + __GLX_PUT_LONG(20, target); + __GLX_PUT_LONG(24, order); + /* + ** NOTE: the doubles that follow are not aligned because of 3 + ** longs preceeding + */ + __glFillMap1d(k, order, stride, pnts, (pc + 28)); + __GLX_END(cmdlen); + } + else { + /* Use GLXRenderLarge protocol to send command */ + __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1d, cmdlen + 4); + __GLX_PUT_DOUBLE(8, u1); + __GLX_PUT_DOUBLE(16, u2); + __GLX_PUT_LONG(24, target); + __GLX_PUT_LONG(28, order); + + /* + ** NOTE: the doubles that follow are not aligned because of 3 + ** longs preceeding + */ + if (stride != k) { + GLubyte *buf; + + buf = (GLubyte *) Xmalloc(compsize); + if (!buf) { + __glXSetError(gc, GL_OUT_OF_MEMORY); + return; + } + __glFillMap1d(k, order, stride, pnts, buf); + __glXSendLargeCommand(gc, pc, 32, buf, compsize); + Xfree((char *) buf); + } + else { + /* Data is already packed. Just send it out */ + __glXSendLargeCommand(gc, pc, 32, pnts, compsize); + } + } +} + +void +__indirect_glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride, + GLint order, const GLfloat * pnts) +{ + __GLX_DECLARE_VARIABLES(); + GLint k; + + __GLX_LOAD_VARIABLES(); + k = __glMap1f_size(target); + if (k == 0) { + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + else if (stride < k || order <= 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + compsize = k * order * __GLX_SIZE_FLOAT32; + cmdlen = 20 + compsize; + if (!gc->currentDpy) + return; + + /* + ** The order that arguments are packed is different from the order + ** for glMap1d. + */ + if (cmdlen <= gc->maxSmallRenderCommandSize) { + /* Use GLXRender protocol to send small command */ + __GLX_BEGIN_VARIABLE(X_GLrop_Map1f, cmdlen); + __GLX_PUT_LONG(4, target); + __GLX_PUT_FLOAT(8, u1); + __GLX_PUT_FLOAT(12, u2); + __GLX_PUT_LONG(16, order); + __glFillMap1f(k, order, stride, pnts, (GLubyte *) (pc + 20)); + __GLX_END(cmdlen); + } + else { + /* Use GLXRenderLarge protocol to send command */ + __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1f, cmdlen + 4); + __GLX_PUT_LONG(8, target); + __GLX_PUT_FLOAT(12, u1); + __GLX_PUT_FLOAT(16, u2); + __GLX_PUT_LONG(20, order); + + if (stride != k) { + GLubyte *buf; + + buf = (GLubyte *) Xmalloc(compsize); + if (!buf) { + __glXSetError(gc, GL_OUT_OF_MEMORY); + return; + } + __glFillMap1f(k, order, stride, pnts, buf); + __glXSendLargeCommand(gc, pc, 24, buf, compsize); + Xfree((char *) buf); + } + else { + /* Data is already packed. Just send it out */ + __glXSendLargeCommand(gc, pc, 24, pnts, compsize); + } + } +} + +void +__indirect_glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustr, + GLint uord, GLdouble v1, GLdouble v2, GLint vstr, + GLint vord, const GLdouble * pnts) +{ + __GLX_DECLARE_VARIABLES(); + GLint k; + + __GLX_LOAD_VARIABLES(); + k = __glMap2d_size(target); + if (k == 0) { + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + compsize = k * uord * vord * __GLX_SIZE_FLOAT64; + cmdlen = 48 + compsize; + if (!gc->currentDpy) + return; + + if (cmdlen <= gc->maxSmallRenderCommandSize) { + /* Use GLXRender protocol to send small command */ + __GLX_BEGIN_VARIABLE(X_GLrop_Map2d, cmdlen); + __GLX_PUT_DOUBLE(4, u1); + __GLX_PUT_DOUBLE(12, u2); + __GLX_PUT_DOUBLE(20, v1); + __GLX_PUT_DOUBLE(28, v2); + __GLX_PUT_LONG(36, target); + __GLX_PUT_LONG(40, uord); + __GLX_PUT_LONG(44, vord); + /* + ** Pack into a u-major ordering. + ** NOTE: the doubles that follow are not aligned because of 5 + ** longs preceeding + */ + __glFillMap2d(k, uord, vord, ustr, vstr, pnts, (GLdouble *) (pc + 48)); + __GLX_END(cmdlen); + } + else { + /* Use GLXRenderLarge protocol to send command */ + __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2d, cmdlen + 4); + __GLX_PUT_DOUBLE(8, u1); + __GLX_PUT_DOUBLE(16, u2); + __GLX_PUT_DOUBLE(24, v1); + __GLX_PUT_DOUBLE(32, v2); + __GLX_PUT_LONG(40, target); + __GLX_PUT_LONG(44, uord); + __GLX_PUT_LONG(48, vord); + + /* + ** NOTE: the doubles that follow are not aligned because of 5 + ** longs preceeding + */ + if ((vstr != k) || (ustr != k * vord)) { + GLdouble *buf; + + buf = (GLdouble *) Xmalloc(compsize); + if (!buf) { + __glXSetError(gc, GL_OUT_OF_MEMORY); + return; + } + /* + ** Pack into a u-major ordering. + */ + __glFillMap2d(k, uord, vord, ustr, vstr, pnts, buf); + __glXSendLargeCommand(gc, pc, 52, buf, compsize); + Xfree((char *) buf); + } + else { + /* Data is already packed. Just send it out */ + __glXSendLargeCommand(gc, pc, 52, pnts, compsize); + } + } +} + +void +__indirect_glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustr, + GLint uord, GLfloat v1, GLfloat v2, GLint vstr, GLint vord, + const GLfloat * pnts) +{ + __GLX_DECLARE_VARIABLES(); + GLint k; + + __GLX_LOAD_VARIABLES(); + k = __glMap2f_size(target); + if (k == 0) { + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + compsize = k * uord * vord * __GLX_SIZE_FLOAT32; + cmdlen = 32 + compsize; + if (!gc->currentDpy) + return; + + /* + ** The order that arguments are packed is different from the order + ** for glMap2d. + */ + if (cmdlen <= gc->maxSmallRenderCommandSize) { + /* Use GLXRender protocol to send small command */ + __GLX_BEGIN_VARIABLE(X_GLrop_Map2f, cmdlen); + __GLX_PUT_LONG(4, target); + __GLX_PUT_FLOAT(8, u1); + __GLX_PUT_FLOAT(12, u2); + __GLX_PUT_LONG(16, uord); + __GLX_PUT_FLOAT(20, v1); + __GLX_PUT_FLOAT(24, v2); + __GLX_PUT_LONG(28, vord); + /* + ** Pack into a u-major ordering. + */ + __glFillMap2f(k, uord, vord, ustr, vstr, pnts, (GLfloat *) (pc + 32)); + __GLX_END(cmdlen); + } + else { + /* Use GLXRenderLarge protocol to send command */ + __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2f, cmdlen + 4); + __GLX_PUT_LONG(8, target); + __GLX_PUT_FLOAT(12, u1); + __GLX_PUT_FLOAT(16, u2); + __GLX_PUT_LONG(20, uord); + __GLX_PUT_FLOAT(24, v1); + __GLX_PUT_FLOAT(28, v2); + __GLX_PUT_LONG(32, vord); + + if ((vstr != k) || (ustr != k * vord)) { + GLfloat *buf; + + buf = (GLfloat *) Xmalloc(compsize); + if (!buf) { + __glXSetError(gc, GL_OUT_OF_MEMORY); + return; + } + /* + ** Pack into a u-major ordering. + */ + __glFillMap2f(k, uord, vord, ustr, vstr, pnts, buf); + __glXSendLargeCommand(gc, pc, 36, buf, compsize); + Xfree((char *) buf); + } + else { + /* Data is already packed. Just send it out */ + __glXSendLargeCommand(gc, pc, 36, pnts, compsize); + } + } +} + +void +__indirect_glEnable(GLenum cap) +{ + __GLX_DECLARE_VARIABLES(); + + __GLX_LOAD_VARIABLES(); + if (!gc->currentDpy) + return; + + switch (cap) { + case GL_COLOR_ARRAY: + case GL_EDGE_FLAG_ARRAY: + case GL_INDEX_ARRAY: + case GL_NORMAL_ARRAY: + case GL_TEXTURE_COORD_ARRAY: + case GL_VERTEX_ARRAY: + case GL_SECONDARY_COLOR_ARRAY: + case GL_FOG_COORD_ARRAY: + __indirect_glEnableClientState(cap); + return; + default: + break; + } + + __GLX_BEGIN(X_GLrop_Enable, 8); + __GLX_PUT_LONG(4, cap); + __GLX_END(8); +} + +void +__indirect_glDisable(GLenum cap) +{ + __GLX_DECLARE_VARIABLES(); + + __GLX_LOAD_VARIABLES(); + if (!gc->currentDpy) + return; + + switch (cap) { + case GL_COLOR_ARRAY: + case GL_EDGE_FLAG_ARRAY: + case GL_INDEX_ARRAY: + case GL_NORMAL_ARRAY: + case GL_TEXTURE_COORD_ARRAY: + case GL_VERTEX_ARRAY: + case GL_SECONDARY_COLOR_ARRAY: + case GL_FOG_COORD_ARRAY: + __indirect_glDisableClientState(cap); + return; + default: + break; + } + + __GLX_BEGIN(X_GLrop_Disable, 8); + __GLX_PUT_LONG(4, cap); + __GLX_END(8); +} diff --git a/src/glx/renderpix.c b/src/glx/renderpix.c new file mode 100644 index 0000000..8234bbe --- /dev/null +++ b/src/glx/renderpix.c @@ -0,0 +1,218 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +/* + * (C) Copyright IBM Corporation 2005 + * 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 + * IBM, + * 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 "packrender.h" +#include "indirect.h" + +/** + * Send a large image to the server. If necessary, a buffer is allocated + * to hold the unpacked data that is copied from the clients memory. + * + * \param gc Current GLX context + * \param compsize Size, in bytes, of the image portion + * \param dim Number of dimensions of the image + * \param width Width of the image + * \param height Height of the image, must be 1 for 1D images + * \param depth Depth of the image, must be 1 for 1D or 2D images + * \param format Format of the image + * \param type Data type of the image + * \param src Pointer to the image data + * \param pc Pointer to end of the command header + * \param modes Pointer to the pixel unpack data + * + * \todo + * Modify this function so that \c NULL images are sent using + * \c __glXSendLargeChunk instead of __glXSendLargeCommand. Doing this + * will eliminate the need to allocate a buffer for that case. + * + * \bugs + * The \c fastImageUnpack path, which is thankfully never used, is completely + * broken. + */ +void +__glXSendLargeImage(struct glx_context * gc, GLint compsize, GLint dim, + GLint width, GLint height, GLint depth, + GLenum format, GLenum type, const GLvoid * src, + GLubyte * pc, GLubyte * modes) +{ + if (!gc->fastImageUnpack || (src == NULL)) { + /* Allocate a temporary holding buffer */ + GLubyte *buf = (GLubyte *) Xmalloc(compsize); + if (!buf) { + __glXSetError(gc, GL_OUT_OF_MEMORY); + return; + } + + /* Apply pixel store unpack modes to copy data into buf */ + if (src != NULL) { + (*gc->fillImage) (gc, dim, width, height, depth, format, type, + src, buf, modes); + } + else { + if (dim < 3) { + (void) memcpy(modes, __glXDefaultPixelStore + 4, 20); + } + else { + (void) memcpy(modes, __glXDefaultPixelStore + 0, 36); + } + } + + /* Send large command */ + __glXSendLargeCommand(gc, gc->pc, pc - gc->pc, buf, compsize); + + /* Free buffer */ + Xfree((char *) buf); + } + else { + /* Just send the data straight as is */ + __glXSendLargeCommand(gc, gc->pc, pc - gc->pc, pc, compsize); + } +} + +/************************************************************************/ + +/** + * Implement GLX protocol for \c glSeparableFilter2D. + * + * \bugs + * The \c fastImageUnpack path, which is thankfully never used, is completely + * broken. + */ +void +__indirect_glSeparableFilter2D(GLenum target, GLenum internalformat, + GLsizei width, GLsizei height, GLenum format, + GLenum type, const GLvoid * row, + const GLvoid * column) +{ + __GLX_DECLARE_VARIABLES(); + GLuint compsize2, hdrlen, totalhdrlen, image1len, image2len; + + __GLX_LOAD_VARIABLES(); + compsize = __glImageSize(width, 1, 1, format, type, 0); + compsize2 = __glImageSize(height, 1, 1, format, type, 0); + totalhdrlen = __GLX_PAD(__GLX_CONV_FILT_CMD_HDR_SIZE); + hdrlen = __GLX_PAD(__GLX_CONV_FILT_HDR_SIZE); + image1len = __GLX_PAD(compsize); + image2len = __GLX_PAD(compsize2); + cmdlen = totalhdrlen + image1len + image2len; + if (!gc->currentDpy) + return; + + if (cmdlen <= gc->maxSmallRenderCommandSize) { + /* Use GLXRender protocol to send small command */ + __GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_SeparableFilter2D, cmdlen); + __GLX_PUT_LONG(0, target); + __GLX_PUT_LONG(4, internalformat); + __GLX_PUT_LONG(8, width); + __GLX_PUT_LONG(12, height); + __GLX_PUT_LONG(16, format); + __GLX_PUT_LONG(20, type); + pc += hdrlen; + if (compsize > 0) { + (*gc->fillImage) (gc, 1, width, 1, 1, format, type, + row, pc, pixelHeaderPC); + pc += image1len; + } + if (compsize2 > 0) { + (*gc->fillImage) (gc, 1, height, 1, 1, format, type, + column, pc, NULL); + pc += image2len; + } + if ((compsize == 0) && (compsize2 == 0)) { + /* Setup default store modes */ + (void) memcpy(pixelHeaderPC, __glXDefaultPixelStore + 4, 20); + } + __GLX_END(0); + } + else { + const GLint bufsize = image1len + image2len; + + /* Use GLXRenderLarge protocol to send command */ + __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_SeparableFilter2D, + cmdlen + 4); + __GLX_PUT_LONG(0, target); + __GLX_PUT_LONG(4, internalformat); + __GLX_PUT_LONG(8, width); + __GLX_PUT_LONG(12, height); + __GLX_PUT_LONG(16, format); + __GLX_PUT_LONG(20, type); + pc += hdrlen; + + if (!gc->fastImageUnpack) { + /* Allocate a temporary holding buffer */ + GLubyte *buf = (GLubyte *) Xmalloc(bufsize); + if (!buf) { + __glXSetError(gc, GL_OUT_OF_MEMORY); + return; + } + (*gc->fillImage) (gc, 1, width, 1, 1, format, type, row, buf, + pixelHeaderPC); + + (*gc->fillImage) (gc, 1, height, 1, 1, format, type, column, + buf + image1len, pixelHeaderPC); + + /* Send large command */ + __glXSendLargeCommand(gc, gc->pc, (GLint) (pc - gc->pc), buf, + bufsize); + /* Free buffer */ + Xfree((char *) buf); + } + else { + /* Just send the data straight as is */ + __glXSendLargeCommand(gc, gc->pc, (GLint) (pc - gc->pc), pc, + bufsize); + } + } +} diff --git a/src/glx/single2.c b/src/glx/single2.c new file mode 100644 index 0000000..66281fa --- /dev/null +++ b/src/glx/single2.c @@ -0,0 +1,975 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include +#include +#include "glxclient.h" +#include "packsingle.h" +#include "glxextensions.h" +#include "indirect.h" +#include "indirect_vertex_array.h" +#include "glapitable.h" +#include "glapi.h" +#ifdef USE_XCB +#include +#include +#include +#endif /* USE_XCB */ + +#if !defined(__GNUC__) +# define __builtin_expect(x, y) x +#endif + +/* Used for GL_ARB_transpose_matrix */ +static void +TransposeMatrixf(GLfloat m[16]) +{ + int i, j; + for (i = 0; i < 4; i++) { + for (j = 0; j < i; j++) { + GLfloat tmp = m[i * 4 + j]; + m[i * 4 + j] = m[j * 4 + i]; + m[j * 4 + i] = tmp; + } + } +} + +/* Used for GL_ARB_transpose_matrix */ +static void +TransposeMatrixb(GLboolean m[16]) +{ + int i, j; + for (i = 0; i < 4; i++) { + for (j = 0; j < i; j++) { + GLboolean tmp = m[i * 4 + j]; + m[i * 4 + j] = m[j * 4 + i]; + m[j * 4 + i] = tmp; + } + } +} + +/* Used for GL_ARB_transpose_matrix */ +static void +TransposeMatrixd(GLdouble m[16]) +{ + int i, j; + for (i = 0; i < 4; i++) { + for (j = 0; j < i; j++) { + GLdouble tmp = m[i * 4 + j]; + m[i * 4 + j] = m[j * 4 + i]; + m[j * 4 + i] = tmp; + } + } +} + +/* Used for GL_ARB_transpose_matrix */ +static void +TransposeMatrixi(GLint m[16]) +{ + int i, j; + for (i = 0; i < 4; i++) { + for (j = 0; j < i; j++) { + GLint tmp = m[i * 4 + j]; + m[i * 4 + j] = m[j * 4 + i]; + m[j * 4 + i] = tmp; + } + } +} + + +/** + * Remap a transpose-matrix enum to a non-transpose-matrix enum. Enums + * that are not transpose-matrix enums are unaffected. + */ +static GLenum +RemapTransposeEnum(GLenum e) +{ + switch (e) { + case GL_TRANSPOSE_MODELVIEW_MATRIX: + case GL_TRANSPOSE_PROJECTION_MATRIX: + case GL_TRANSPOSE_TEXTURE_MATRIX: + return e - (GL_TRANSPOSE_MODELVIEW_MATRIX - GL_MODELVIEW_MATRIX); + case GL_TRANSPOSE_COLOR_MATRIX: + return GL_COLOR_MATRIX; + default: + return e; + }; +} + + +GLenum +__indirect_glGetError(void) +{ + __GLX_SINGLE_DECLARE_VARIABLES(); + GLuint retval = GL_NO_ERROR; + xGLXGetErrorReply reply; + + if (gc->error) { + /* Use internal error first */ + retval = gc->error; + gc->error = GL_NO_ERROR; + return retval; + } + + __GLX_SINGLE_LOAD_VARIABLES(); + __GLX_SINGLE_BEGIN(X_GLsop_GetError, 0); + __GLX_SINGLE_READ_XREPLY(); + retval = reply.error; + __GLX_SINGLE_END(); + + return retval; +} + + +/** + * Get the selected attribute from the client state. + * + * \returns + * On success \c GL_TRUE is returned. Otherwise, \c GL_FALSE is returned. + */ +static GLboolean +get_client_data(struct glx_context * gc, GLenum cap, GLintptr * data) +{ + GLboolean retval = GL_TRUE; + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + const GLint tex_unit = __glXGetActiveTextureUnit(state); + + + switch (cap) { + case GL_VERTEX_ARRAY: + case GL_NORMAL_ARRAY: + case GL_COLOR_ARRAY: + case GL_INDEX_ARRAY: + case GL_EDGE_FLAG_ARRAY: + case GL_SECONDARY_COLOR_ARRAY: + case GL_FOG_COORD_ARRAY: + retval = __glXGetArrayEnable(state, cap, 0, data); + break; + + case GL_VERTEX_ARRAY_SIZE: + retval = __glXGetArraySize(state, GL_VERTEX_ARRAY, 0, data); + break; + case GL_COLOR_ARRAY_SIZE: + retval = __glXGetArraySize(state, GL_COLOR_ARRAY, 0, data); + break; + case GL_SECONDARY_COLOR_ARRAY_SIZE: + retval = __glXGetArraySize(state, GL_SECONDARY_COLOR_ARRAY, 0, data); + break; + + case GL_VERTEX_ARRAY_TYPE: + retval = __glXGetArrayType(state, GL_VERTEX_ARRAY, 0, data); + break; + case GL_NORMAL_ARRAY_TYPE: + retval = __glXGetArrayType(state, GL_NORMAL_ARRAY, 0, data); + break; + case GL_INDEX_ARRAY_TYPE: + retval = __glXGetArrayType(state, GL_INDEX_ARRAY, 0, data); + break; + case GL_COLOR_ARRAY_TYPE: + retval = __glXGetArrayType(state, GL_COLOR_ARRAY, 0, data); + break; + case GL_SECONDARY_COLOR_ARRAY_TYPE: + retval = __glXGetArrayType(state, GL_SECONDARY_COLOR_ARRAY, 0, data); + break; + case GL_FOG_COORD_ARRAY_TYPE: + retval = __glXGetArrayType(state, GL_FOG_COORD_ARRAY, 0, data); + break; + + case GL_VERTEX_ARRAY_STRIDE: + retval = __glXGetArrayStride(state, GL_VERTEX_ARRAY, 0, data); + break; + case GL_NORMAL_ARRAY_STRIDE: + retval = __glXGetArrayStride(state, GL_NORMAL_ARRAY, 0, data); + break; + case GL_INDEX_ARRAY_STRIDE: + retval = __glXGetArrayStride(state, GL_INDEX_ARRAY, 0, data); + break; + case GL_EDGE_FLAG_ARRAY_STRIDE: + retval = __glXGetArrayStride(state, GL_EDGE_FLAG_ARRAY, 0, data); + break; + case GL_COLOR_ARRAY_STRIDE: + retval = __glXGetArrayStride(state, GL_COLOR_ARRAY, 0, data); + break; + case GL_SECONDARY_COLOR_ARRAY_STRIDE: + retval = __glXGetArrayStride(state, GL_SECONDARY_COLOR_ARRAY, 0, data); + break; + case GL_FOG_COORD_ARRAY_STRIDE: + retval = __glXGetArrayStride(state, GL_FOG_COORD_ARRAY, 0, data); + break; + + case GL_TEXTURE_COORD_ARRAY: + retval = + __glXGetArrayEnable(state, GL_TEXTURE_COORD_ARRAY, tex_unit, data); + break; + case GL_TEXTURE_COORD_ARRAY_SIZE: + retval = + __glXGetArraySize(state, GL_TEXTURE_COORD_ARRAY, tex_unit, data); + break; + case GL_TEXTURE_COORD_ARRAY_TYPE: + retval = + __glXGetArrayType(state, GL_TEXTURE_COORD_ARRAY, tex_unit, data); + break; + case GL_TEXTURE_COORD_ARRAY_STRIDE: + retval = + __glXGetArrayStride(state, GL_TEXTURE_COORD_ARRAY, tex_unit, data); + break; + + case GL_MAX_ELEMENTS_VERTICES: + case GL_MAX_ELEMENTS_INDICES: + retval = GL_TRUE; + *data = ~0UL; + break; + + + case GL_PACK_ROW_LENGTH: + *data = (GLintptr) state->storePack.rowLength; + break; + case GL_PACK_IMAGE_HEIGHT: + *data = (GLintptr) state->storePack.imageHeight; + break; + case GL_PACK_SKIP_ROWS: + *data = (GLintptr) state->storePack.skipRows; + break; + case GL_PACK_SKIP_PIXELS: + *data = (GLintptr) state->storePack.skipPixels; + break; + case GL_PACK_SKIP_IMAGES: + *data = (GLintptr) state->storePack.skipImages; + break; + case GL_PACK_ALIGNMENT: + *data = (GLintptr) state->storePack.alignment; + break; + case GL_PACK_SWAP_BYTES: + *data = (GLintptr) state->storePack.swapEndian; + break; + case GL_PACK_LSB_FIRST: + *data = (GLintptr) state->storePack.lsbFirst; + break; + case GL_UNPACK_ROW_LENGTH: + *data = (GLintptr) state->storeUnpack.rowLength; + break; + case GL_UNPACK_IMAGE_HEIGHT: + *data = (GLintptr) state->storeUnpack.imageHeight; + break; + case GL_UNPACK_SKIP_ROWS: + *data = (GLintptr) state->storeUnpack.skipRows; + break; + case GL_UNPACK_SKIP_PIXELS: + *data = (GLintptr) state->storeUnpack.skipPixels; + break; + case GL_UNPACK_SKIP_IMAGES: + *data = (GLintptr) state->storeUnpack.skipImages; + break; + case GL_UNPACK_ALIGNMENT: + *data = (GLintptr) state->storeUnpack.alignment; + break; + case GL_UNPACK_SWAP_BYTES: + *data = (GLintptr) state->storeUnpack.swapEndian; + break; + case GL_UNPACK_LSB_FIRST: + *data = (GLintptr) state->storeUnpack.lsbFirst; + break; + case GL_CLIENT_ATTRIB_STACK_DEPTH: + *data = (GLintptr) (gc->attributes.stackPointer - gc->attributes.stack); + break; + case GL_MAX_CLIENT_ATTRIB_STACK_DEPTH: + *data = (GLintptr) __GL_CLIENT_ATTRIB_STACK_DEPTH; + break; + case GL_CLIENT_ACTIVE_TEXTURE: + *data = (GLintptr) (tex_unit + GL_TEXTURE0); + break; + + default: + retval = GL_FALSE; + break; + } + + + return retval; +} + + +void +__indirect_glGetBooleanv(GLenum val, GLboolean * b) +{ + const GLenum origVal = val; + __GLX_SINGLE_DECLARE_VARIABLES(); + xGLXSingleReply reply; + + val = RemapTransposeEnum(val); + + __GLX_SINGLE_LOAD_VARIABLES(); + __GLX_SINGLE_BEGIN(X_GLsop_GetBooleanv, 4); + __GLX_SINGLE_PUT_LONG(0, val); + __GLX_SINGLE_READ_XREPLY(); + __GLX_SINGLE_GET_SIZE(compsize); + + if (compsize == 0) { + /* + ** Error occured; don't modify user's buffer. + */ + } + else { + GLintptr data; + + /* + ** We still needed to send the request to the server in order to + ** find out whether it was legal to make a query (it's illegal, + ** for example, to call a query between glBegin() and glEnd()). + */ + + if (get_client_data(gc, val, &data)) { + *b = (GLboolean) data; + } + else { + /* + ** Not a local value, so use what we got from the server. + */ + if (compsize == 1) { + __GLX_SINGLE_GET_CHAR(b); + } + else { + __GLX_SINGLE_GET_CHAR_ARRAY(b, compsize); + if (val != origVal) { + /* matrix transpose */ + TransposeMatrixb(b); + } + } + } + } + __GLX_SINGLE_END(); +} + +void +__indirect_glGetDoublev(GLenum val, GLdouble * d) +{ + const GLenum origVal = val; + __GLX_SINGLE_DECLARE_VARIABLES(); + xGLXSingleReply reply; + + val = RemapTransposeEnum(val); + + __GLX_SINGLE_LOAD_VARIABLES(); + __GLX_SINGLE_BEGIN(X_GLsop_GetDoublev, 4); + __GLX_SINGLE_PUT_LONG(0, val); + __GLX_SINGLE_READ_XREPLY(); + __GLX_SINGLE_GET_SIZE(compsize); + + if (compsize == 0) { + /* + ** Error occured; don't modify user's buffer. + */ + } + else { + GLintptr data; + + /* + ** We still needed to send the request to the server in order to + ** find out whether it was legal to make a query (it's illegal, + ** for example, to call a query between glBegin() and glEnd()). + */ + + if (get_client_data(gc, val, &data)) { + *d = (GLdouble) data; + } + else { + /* + ** Not a local value, so use what we got from the server. + */ + if (compsize == 1) { + __GLX_SINGLE_GET_DOUBLE(d); + } + else { + __GLX_SINGLE_GET_DOUBLE_ARRAY(d, compsize); + if (val != origVal) { + /* matrix transpose */ + TransposeMatrixd(d); + } + } + } + } + __GLX_SINGLE_END(); +} + +void +__indirect_glGetFloatv(GLenum val, GLfloat * f) +{ + const GLenum origVal = val; + __GLX_SINGLE_DECLARE_VARIABLES(); + xGLXSingleReply reply; + + val = RemapTransposeEnum(val); + + __GLX_SINGLE_LOAD_VARIABLES(); + __GLX_SINGLE_BEGIN(X_GLsop_GetFloatv, 4); + __GLX_SINGLE_PUT_LONG(0, val); + __GLX_SINGLE_READ_XREPLY(); + __GLX_SINGLE_GET_SIZE(compsize); + + if (compsize == 0) { + /* + ** Error occured; don't modify user's buffer. + */ + } + else { + GLintptr data; + + /* + ** We still needed to send the request to the server in order to + ** find out whether it was legal to make a query (it's illegal, + ** for example, to call a query between glBegin() and glEnd()). + */ + + if (get_client_data(gc, val, &data)) { + *f = (GLfloat) data; + } + else { + /* + ** Not a local value, so use what we got from the server. + */ + if (compsize == 1) { + __GLX_SINGLE_GET_FLOAT(f); + } + else { + __GLX_SINGLE_GET_FLOAT_ARRAY(f, compsize); + if (val != origVal) { + /* matrix transpose */ + TransposeMatrixf(f); + } + } + } + } + __GLX_SINGLE_END(); +} + +void +__indirect_glGetIntegerv(GLenum val, GLint * i) +{ + const GLenum origVal = val; + __GLX_SINGLE_DECLARE_VARIABLES(); + xGLXSingleReply reply; + + val = RemapTransposeEnum(val); + + __GLX_SINGLE_LOAD_VARIABLES(); + __GLX_SINGLE_BEGIN(X_GLsop_GetIntegerv, 4); + __GLX_SINGLE_PUT_LONG(0, val); + __GLX_SINGLE_READ_XREPLY(); + __GLX_SINGLE_GET_SIZE(compsize); + + if (compsize == 0) { + /* + ** Error occured; don't modify user's buffer. + */ + } + else { + GLintptr data; + + /* + ** We still needed to send the request to the server in order to + ** find out whether it was legal to make a query (it's illegal, + ** for example, to call a query between glBegin() and glEnd()). + */ + + if (get_client_data(gc, val, &data)) { + *i = (GLint) data; + } + else { + /* + ** Not a local value, so use what we got from the server. + */ + if (compsize == 1) { + __GLX_SINGLE_GET_LONG(i); + } + else { + __GLX_SINGLE_GET_LONG_ARRAY(i, compsize); + if (val != origVal) { + /* matrix transpose */ + TransposeMatrixi(i); + } + } + } + } + __GLX_SINGLE_END(); +} + +/* +** Send all pending commands to server. +*/ +void +__indirect_glFlush(void) +{ + __GLX_SINGLE_DECLARE_VARIABLES(); + + if (!dpy) + return; + + __GLX_SINGLE_LOAD_VARIABLES(); + __GLX_SINGLE_BEGIN(X_GLsop_Flush, 0); + __GLX_SINGLE_END(); + + /* And finally flush the X protocol data */ + XFlush(dpy); +} + +void +__indirect_glFeedbackBuffer(GLsizei size, GLenum type, GLfloat * buffer) +{ + __GLX_SINGLE_DECLARE_VARIABLES(); + + if (!dpy) + return; + + __GLX_SINGLE_LOAD_VARIABLES(); + __GLX_SINGLE_BEGIN(X_GLsop_FeedbackBuffer, 8); + __GLX_SINGLE_PUT_LONG(0, size); + __GLX_SINGLE_PUT_LONG(4, type); + __GLX_SINGLE_END(); + + gc->feedbackBuf = buffer; +} + +void +__indirect_glSelectBuffer(GLsizei numnames, GLuint * buffer) +{ + __GLX_SINGLE_DECLARE_VARIABLES(); + + if (!dpy) + return; + + __GLX_SINGLE_LOAD_VARIABLES(); + __GLX_SINGLE_BEGIN(X_GLsop_SelectBuffer, 4); + __GLX_SINGLE_PUT_LONG(0, numnames); + __GLX_SINGLE_END(); + + gc->selectBuf = buffer; +} + +GLint +__indirect_glRenderMode(GLenum mode) +{ + __GLX_SINGLE_DECLARE_VARIABLES(); + GLint retval = 0; + xGLXRenderModeReply reply; + + if (!dpy) + return -1; + + __GLX_SINGLE_LOAD_VARIABLES(); + __GLX_SINGLE_BEGIN(X_GLsop_RenderMode, 4); + __GLX_SINGLE_PUT_LONG(0, mode); + __GLX_SINGLE_READ_XREPLY(); + __GLX_SINGLE_GET_RETVAL(retval, GLint); + + if (reply.newMode != mode) { + /* + ** Switch to new mode did not take effect, therefore an error + ** occured. When an error happens the server won't send us any + ** other data. + */ + } + else { + /* Read the feedback or selection data */ + if (gc->renderMode == GL_FEEDBACK) { + __GLX_SINGLE_GET_SIZE(compsize); + __GLX_SINGLE_GET_FLOAT_ARRAY(gc->feedbackBuf, compsize); + } + else if (gc->renderMode == GL_SELECT) { + __GLX_SINGLE_GET_SIZE(compsize); + __GLX_SINGLE_GET_LONG_ARRAY(gc->selectBuf, compsize); + } + gc->renderMode = mode; + } + __GLX_SINGLE_END(); + + return retval; +} + +void +__indirect_glFinish(void) +{ + __GLX_SINGLE_DECLARE_VARIABLES(); + xGLXSingleReply reply; + + __GLX_SINGLE_LOAD_VARIABLES(); + __GLX_SINGLE_BEGIN(X_GLsop_Finish, 0); + __GLX_SINGLE_READ_XREPLY(); + __GLX_SINGLE_END(); +} + + +/** + * Extract the major and minor version numbers from a version string. + */ +static void +version_from_string(const char *ver, int *major_version, int *minor_version) +{ + const char *end; + long major; + long minor; + + major = strtol(ver, (char **) &end, 10); + minor = strtol(end + 1, NULL, 10); + *major_version = major; + *minor_version = minor; +} + + +const GLubyte * +__indirect_glGetString(GLenum name) +{ + struct glx_context *gc = __glXGetCurrentContext(); + Display *dpy = gc->currentDpy; + GLubyte *s = NULL; + + if (!dpy) + return 0; + + /* + ** Return the cached copy if the string has already been fetched + */ + switch (name) { + case GL_VENDOR: + if (gc->vendor) + return gc->vendor; + break; + case GL_RENDERER: + if (gc->renderer) + return gc->renderer; + break; + case GL_VERSION: + if (gc->version) + return gc->version; + break; + case GL_EXTENSIONS: + if (gc->extensions) + return gc->extensions; + break; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return 0; + } + + /* + ** Get requested string from server + */ + + (void) __glXFlushRenderBuffer(gc, gc->pc); + s = (GLubyte *) __glXGetString(dpy, gc->majorOpcode, gc->currentContextTag, + name); + if (!s) { + /* Throw data on the floor */ + __glXSetError(gc, GL_OUT_OF_MEMORY); + } + else { + /* + ** Update local cache + */ + switch (name) { + case GL_VENDOR: + gc->vendor = s; + break; + + case GL_RENDERER: + gc->renderer = s; + break; + + case GL_VERSION:{ + int client_major; + int client_minor; + + version_from_string((char *) s, + &gc->server_major, &gc->server_minor); + __glXGetGLVersion(&client_major, &client_minor); + + if ((gc->server_major < client_major) + || ((gc->server_major == client_major) + && (gc->server_minor <= client_minor))) { + gc->version = s; + } + else { + /* Allow 7 bytes for the client-side GL version. This allows + * for upto version 999.999. I'm not holding my breath for + * that one! The extra 4 is for the ' ()\0' that will be + * added. + */ + const size_t size = 7 + strlen((char *) s) + 4; + + gc->version = Xmalloc(size); + if (gc->version == NULL) { + /* If we couldn't allocate memory for the new string, + * make a best-effort and just copy the client-side version + * to the string and use that. It probably doesn't + * matter what is done here. If there not memory available + * for a short string, the system is probably going to die + * soon anyway. + */ + snprintf((char *) s, strlen((char *) s) + 1, "%u.%u", + client_major, client_minor); + gc->version = s; + } + else { + snprintf((char *) gc->version, size, "%u.%u (%s)", + client_major, client_minor, s); + Xfree(s); + s = gc->version; + } + } + break; + } + + case GL_EXTENSIONS:{ + int major = 1; + int minor = 0; + + /* This code is currently disabled. I was reminded that some + * vendors intentionally exclude some extensions from their + * extension string that are part of the core version they + * advertise. In particular, on Nvidia drivers this means that + * the functionality is supported by the driver, but is not + * hardware accelerated. For example, a TNT will show core + * version 1.5, but most of the post-1.2 functionality is a + * software fallback. + * + * I don't want to break applications that rely on this odd + * behavior. At the same time, the code is written and tested, + * so I didn't want to throw it away. Therefore, the code is here + * but disabled. In the future, we may wish to and an environment + * variable to enable it. + */ + +#if 0 + /* Call glGetString just to make sure that gc->server_major and + * gc->server_minor are set. This version may be higher than we + * can completely support, but it may imply support for some + * extensions that we can support. + * + * For example, at the time of this writing, the client-side + * library only supports upto core GL version 1.2. However, cubic + * textures, multitexture, multisampling, and some other 1.3 + * features are supported. If the server reports back version + * 1.3, but does not report all of those extensions, we will + * enable them. + */ + (void *) glGetString(GL_VERSION); + major = gc->server_major, minor = gc->server_minor; +#endif + + __glXCalculateUsableGLExtensions(gc, (char *) s, major, minor); + XFree(s); + s = gc->extensions; + break; + } + } + } + return s; +} + +GLboolean +__indirect_glIsEnabled(GLenum cap) +{ + __GLX_SINGLE_DECLARE_VARIABLES(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + xGLXSingleReply reply; + GLboolean retval = 0; + GLintptr enable; + + if (!dpy) + return 0; + + switch (cap) { + case GL_VERTEX_ARRAY: + case GL_NORMAL_ARRAY: + case GL_COLOR_ARRAY: + case GL_INDEX_ARRAY: + case GL_EDGE_FLAG_ARRAY: + case GL_SECONDARY_COLOR_ARRAY: + case GL_FOG_COORD_ARRAY: + retval = __glXGetArrayEnable(state, cap, 0, &enable); + assert(retval); + return (GLboolean) enable; + break; + case GL_TEXTURE_COORD_ARRAY: + retval = __glXGetArrayEnable(state, GL_TEXTURE_COORD_ARRAY, + __glXGetActiveTextureUnit(state), &enable); + assert(retval); + return (GLboolean) enable; + break; + } + + __GLX_SINGLE_LOAD_VARIABLES(); + __GLX_SINGLE_BEGIN(X_GLsop_IsEnabled, 4); + __GLX_SINGLE_PUT_LONG(0, cap); + __GLX_SINGLE_READ_XREPLY(); + __GLX_SINGLE_GET_RETVAL(retval, GLboolean); + __GLX_SINGLE_END(); + return retval; +} + +void +__indirect_glGetPointerv(GLenum pname, void **params) +{ + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + Display *dpy = gc->currentDpy; + + if (!dpy) + return; + + switch (pname) { + case GL_VERTEX_ARRAY_POINTER: + case GL_NORMAL_ARRAY_POINTER: + case GL_COLOR_ARRAY_POINTER: + case GL_INDEX_ARRAY_POINTER: + case GL_EDGE_FLAG_ARRAY_POINTER: + __glXGetArrayPointer(state, pname - GL_VERTEX_ARRAY_POINTER + + GL_VERTEX_ARRAY, 0, params); + return; + case GL_TEXTURE_COORD_ARRAY_POINTER: + __glXGetArrayPointer(state, GL_TEXTURE_COORD_ARRAY, + __glXGetActiveTextureUnit(state), params); + return; + case GL_SECONDARY_COLOR_ARRAY_POINTER: + case GL_FOG_COORD_ARRAY_POINTER: + __glXGetArrayPointer(state, pname - GL_FOG_COORD_ARRAY_POINTER + + GL_FOG_COORD_ARRAY, 0, params); + return; + case GL_FEEDBACK_BUFFER_POINTER: + *params = (void *) gc->feedbackBuf; + return; + case GL_SELECTION_BUFFER_POINTER: + *params = (void *) gc->selectBuf; + return; + default: + __glXSetError(gc, GL_INVALID_ENUM); + return; + } +} + + + +/** + * This was previously auto-generated, but we need to special-case + * how we handle writing into the 'residences' buffer when n%4!=0. + */ +#define X_GLsop_AreTexturesResident 143 +GLboolean +__indirect_glAreTexturesResident(GLsizei n, const GLuint * textures, + GLboolean * residences) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + GLboolean retval = (GLboolean) 0; + const GLuint cmdlen = 4 + __GLX_PAD((n * 4)); + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { +#ifdef USE_XCB + xcb_connection_t *c = XGetXCBConnection(dpy); + (void) __glXFlushRenderBuffer(gc, gc->pc); + xcb_glx_are_textures_resident_reply_t *reply = + xcb_glx_are_textures_resident_reply(c, + xcb_glx_are_textures_resident + (c, gc->currentContextTag, n, + textures), NULL); + (void) memcpy(residences, xcb_glx_are_textures_resident_data(reply), + xcb_glx_are_textures_resident_data_length(reply) * + sizeof(GLboolean)); + retval = reply->ret_val; + free(reply); +#else + GLubyte const *pc = + __glXSetupSingleRequest(gc, X_GLsop_AreTexturesResident, cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) memcpy((void *) (pc + 4), (void *) (textures), (n * 4)); + if (n & 3) { + /* n is not a multiple of four. + * When reply_is_always_array is TRUE, __glXReadReply() will + * put a multiple of four bytes into the dest buffer. If the + * caller's buffer is not a multiple of four in size, we'll write + * out of bounds. So use a temporary buffer that's a few bytes + * larger. + */ + GLboolean *res4 = malloc((n + 3) & ~3); + retval = (GLboolean) __glXReadReply(dpy, 1, res4, GL_TRUE); + memcpy(residences, res4, n); + free(res4); + } + else { + retval = (GLboolean) __glXReadReply(dpy, 1, residences, GL_TRUE); + } + UnlockDisplay(dpy); + SyncHandle(); +#endif /* USE_XCB */ + } + return retval; +} + + +/** + * This was previously auto-generated, but we need to special-case + * how we handle writing into the 'residences' buffer when n%4!=0. + */ +#define X_GLvop_AreTexturesResidentEXT 11 +GLboolean +glAreTexturesResidentEXT(GLsizei n, const GLuint * textures, + GLboolean * residences) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + + if (gc->isDirect) { + return GET_DISPATCH()->AreTexturesResident(n, textures, residences); + } + else { + struct glx_context *const gc = __glXGetCurrentContext(); + Display *const dpy = gc->currentDpy; + GLboolean retval = (GLboolean) 0; + const GLuint cmdlen = 4 + __GLX_PAD((n * 4)); + if (__builtin_expect((n >= 0) && (dpy != NULL), 1)) { + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_AreTexturesResidentEXT, + cmdlen); + (void) memcpy((void *) (pc + 0), (void *) (&n), 4); + (void) memcpy((void *) (pc + 4), (void *) (textures), (n * 4)); + if (n & 3) { + /* see comments in __indirect_glAreTexturesResident() */ + GLboolean *res4 = malloc((n + 3) & ~3); + retval = (GLboolean) __glXReadReply(dpy, 1, res4, GL_TRUE); + memcpy(residences, res4, n); + free(res4); + } + else { + retval = (GLboolean) __glXReadReply(dpy, 1, residences, GL_TRUE); + } + UnlockDisplay(dpy); + SyncHandle(); + } + return retval; + } +} diff --git a/src/glx/singlepix.c b/src/glx/singlepix.c new file mode 100644 index 0000000..d8a7166 --- /dev/null +++ b/src/glx/singlepix.c @@ -0,0 +1,192 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "packsingle.h" +#include "indirect.h" +#include "glapitable.h" +#include "glapi.h" +#include "glthread.h" +#include + +void +__indirect_glGetSeparableFilter(GLenum target, GLenum format, GLenum type, + GLvoid * row, GLvoid * column, GLvoid * span) +{ + __GLX_SINGLE_DECLARE_VARIABLES(); + const __GLXattribute *state; + xGLXGetSeparableFilterReply reply; + GLubyte *rowBuf, *colBuf; + + if (!dpy) + return; + __GLX_SINGLE_LOAD_VARIABLES(); + state = gc->client_state_private; + + /* Send request */ + __GLX_SINGLE_BEGIN(X_GLsop_GetSeparableFilter, __GLX_PAD(13)); + __GLX_SINGLE_PUT_LONG(0, target); + __GLX_SINGLE_PUT_LONG(4, format); + __GLX_SINGLE_PUT_LONG(8, type); + __GLX_SINGLE_PUT_CHAR(12, state->storePack.swapEndian); + __GLX_SINGLE_READ_XREPLY(); + compsize = reply.length << 2; + + if (compsize != 0) { + GLint width, height; + GLint widthsize, heightsize; + + width = reply.width; + height = reply.height; + + widthsize = __glImageSize(width, 1, 1, format, type, 0); + heightsize = __glImageSize(height, 1, 1, format, type, 0); + + /* Allocate a holding buffer to transform the data from */ + rowBuf = (GLubyte *) Xmalloc(widthsize); + if (!rowBuf) { + /* Throw data away */ + _XEatData(dpy, compsize); + __glXSetError(gc, GL_OUT_OF_MEMORY); + UnlockDisplay(dpy); + SyncHandle(); + return; + } + else { + __GLX_SINGLE_GET_CHAR_ARRAY(((char *) rowBuf), widthsize); + __glEmptyImage(gc, 1, width, 1, 1, format, type, rowBuf, row); + Xfree((char *) rowBuf); + } + colBuf = (GLubyte *) Xmalloc(heightsize); + if (!colBuf) { + /* Throw data away */ + _XEatData(dpy, compsize - __GLX_PAD(widthsize)); + __glXSetError(gc, GL_OUT_OF_MEMORY); + UnlockDisplay(dpy); + SyncHandle(); + return; + } + else { + __GLX_SINGLE_GET_CHAR_ARRAY(((char *) colBuf), heightsize); + __glEmptyImage(gc, 1, height, 1, 1, format, type, colBuf, column); + Xfree((char *) colBuf); + } + } + else { + /* + ** don't modify user's buffer. + */ + } + __GLX_SINGLE_END(); + +} + + +/* it is defined to gl_dispatch_stub_NNN in indirect.h */ +void gl_dispatch_stub_GetSeparableFilterEXT (GLenum target, GLenum format, + GLenum type, GLvoid * row, + GLvoid * column, GLvoid * span) +{ + struct glx_context *const gc = __glXGetCurrentContext(); + +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) + if (gc->isDirect) { + GET_DISPATCH()->GetSeparableFilter(target, format, type, + row, column, span); + return; + } + else +#endif + { + Display *const dpy = gc->currentDpy; + const GLuint cmdlen = __GLX_PAD(13); + + if (dpy != NULL) { + const __GLXattribute *const state = gc->client_state_private; + xGLXGetSeparableFilterReply reply; + GLubyte const *pc = + __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, + X_GLvop_GetSeparableFilterEXT, cmdlen); + unsigned compsize; + + + (void) memcpy((void *) (pc + 0), (void *) (&target), 4); + (void) memcpy((void *) (pc + 4), (void *) (&format), 4); + (void) memcpy((void *) (pc + 8), (void *) (&type), 4); + *(int8_t *) (pc + 12) = state->storePack.swapEndian; + + (void) _XReply(dpy, (xReply *) & reply, 0, False); + + compsize = reply.length << 2; + + if (compsize != 0) { + const GLint width = reply.width; + const GLint height = reply.height; + const GLint widthsize = + __glImageSize(width, 1, 1, format, type, 0); + const GLint heightsize = + __glImageSize(height, 1, 1, format, type, 0); + GLubyte *const buf = + (GLubyte *) Xmalloc((widthsize > heightsize) ? widthsize : + heightsize); + + if (buf == NULL) { + /* Throw data away */ + _XEatData(dpy, compsize); + __glXSetError(gc, GL_OUT_OF_MEMORY); + + UnlockDisplay(dpy); + SyncHandle(); + return; + } + else { + int extra; + + extra = 4 - (widthsize & 3); + _XRead(dpy, (char *) buf, widthsize); + if (extra < 4) { + _XEatData(dpy, extra); + } + + __glEmptyImage(gc, 1, width, 1, 1, format, type, buf, row); + + extra = 4 - (heightsize & 3); + _XRead(dpy, (char *) buf, heightsize); + if (extra < 4) { + _XEatData(dpy, extra); + } + + __glEmptyImage(gc, 1, height, 1, 1, format, type, buf, column); + + Xfree((char *) buf); + } + } + } + } +} diff --git a/src/glx/vertarr.c b/src/glx/vertarr.c new file mode 100644 index 0000000..609cafa --- /dev/null +++ b/src/glx/vertarr.c @@ -0,0 +1,212 @@ +/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, 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 including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * 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 + * SILICON GRAPHICS, INC. 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 Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "glxclient.h" +#include "indirect.h" +#include "indirect_vertex_array.h" + + +/*****************************************************************************/ + +/** + * \name Vertex array pointer bridge functions + * + * When EXT_vertex_array was moved into the core GL spec, the \c count + * parameter was lost. This libGL really only wants to implement the GL 1.1 + * version, but we need to support applications that were written to the old + * interface. These bridge functions are part of the glue that makes this + * happen. + */ +/*@{*/ +void +__indirect_glColorPointerEXT(GLint size, GLenum type, GLsizei stride, + GLsizei count, const GLvoid * pointer) +{ + (void) count; + __indirect_glColorPointer(size, type, stride, pointer); +} + +void +__indirect_glEdgeFlagPointerEXT(GLsizei stride, + GLsizei count, const GLboolean * pointer) +{ + (void) count; + __indirect_glEdgeFlagPointer(stride, pointer); +} + +void +__indirect_glIndexPointerEXT(GLenum type, GLsizei stride, + GLsizei count, const GLvoid * pointer) +{ + (void) count; + __indirect_glIndexPointer(type, stride, pointer); +} + +void +__indirect_glNormalPointerEXT(GLenum type, GLsizei stride, GLsizei count, + const GLvoid * pointer) +{ + (void) count; + __indirect_glNormalPointer(type, stride, pointer); +} + +void +__indirect_glTexCoordPointerEXT(GLint size, GLenum type, GLsizei stride, + GLsizei count, const GLvoid * pointer) +{ + (void) count; + __indirect_glTexCoordPointer(size, type, stride, pointer); +} + +void +__indirect_glVertexPointerEXT(GLint size, GLenum type, GLsizei stride, + GLsizei count, const GLvoid * pointer) +{ + (void) count; + __indirect_glVertexPointer(size, type, stride, pointer); +} + +/*@}*/ + +/*****************************************************************************/ + +void +__indirect_glInterleavedArrays(GLenum format, GLsizei stride, + const GLvoid * pointer) +{ + struct glx_context *gc = __glXGetCurrentContext(); + __GLXattribute *state = (__GLXattribute *) (gc->client_state_private); + +#define NONE {0, 0, 0} +#define F(x) {GL_FLOAT, x, x * sizeof(GLfloat)} +#define UB4 {GL_UNSIGNED_BYTE, 4, 4 * sizeof(GLubyte)} + + /* Each row in this array describes the elements of a particular + * interleaved array mode. Each column describes, in the order in which + * they appear in the interleaved arrays, one of the four possible types + * of vertex data that can appear in an interleaved array. + */ + struct + { + /** + * The enum describing the GL type, as would be passed to the + * appropriate gl*Pointer function. + */ + GLushort type; + + /** + * Number of elements in the subarray, as would be passed (as the + * \c size parameter) to the appropriate gl*Pointer function. + */ + GLubyte count; + + /** + * True size of a single element in the subarray, as would be passed + * (as the \c stride parameter) to the appropriate gl*Pointer + * function. + */ + GLubyte size; + } + static const modes[14][4] = { + /* texture color normal vertex */ + {NONE, NONE, NONE, F(2)}, /* GL_V2F */ + {NONE, NONE, NONE, F(3)}, /* GL_V3F */ + {NONE, UB4, NONE, F(2)}, /* GL_C4UB_V2F */ + {NONE, UB4, NONE, F(3)}, /* GL_C4UB_V3F */ + {NONE, F(3), NONE, F(3)}, /* GL_C3F_V3F */ + {NONE, NONE, F(3), F(3)}, /* GL_N3F_V3F */ + {NONE, F(4), F(3), F(3)}, /* GL_C4F_N3F_V3F */ + {F(2), NONE, NONE, F(3)}, /* GL_T2F_V3F */ + {F(4), NONE, NONE, F(4)}, /* GL_T4F_V4F */ + {F(2), UB4, NONE, F(3)}, /* GL_T2F_C4UB_V3F */ + {F(2), F(3), NONE, F(3)}, /* GL_T2F_C3F_V3F */ + {F(2), NONE, F(3), F(3)}, /* GL_T2F_N3F_V3F */ + {F(2), F(4), F(3), F(3)}, /* GL_T2F_C4F_N3F_V3F */ + {F(4), F(4), F(3), F(4)}, /* GL_T4F_C4F_N3F_V4F */ + }; +#undef NONE +#undef F +#undef UB4 + + GLint trueStride, size; + int offsets[4]; + unsigned i; + const int idx = format - GL_V2F; + + + /* All valid formats are on the range [GL_V2F, GL_V2F+0x0D]. Since idx + * is just the format biased by -GL_V2F, all valid idx values are on the + * range [0, 0x0D]. + */ + if ((idx < 0) || (idx > 0x0D)) { + __glXSetError(gc, GL_INVALID_ENUM); + return; + } + + if (stride < 0) { + __glXSetError(gc, GL_INVALID_VALUE); + return; + } + + + /* If the 'count' for a subarray is non-zero, then the offset of its + * first element is at the currently accumulated 'size'. + */ + size = 0; + for (i = 0; i < 4; i++) { + offsets[i] = (modes[idx][i].count != 0) ? size : -1; + size += modes[idx][i].size; + } + + trueStride = (stride == 0) ? size : stride; + + __glXArrayDisableAll(state); + + if (offsets[0] >= 0) { + __indirect_glEnableClientState(GL_TEXTURE_COORD_ARRAY); + __indirect_glTexCoordPointer(modes[idx][0].count, GL_FLOAT, + trueStride, (const char *) pointer); + } + if (offsets[1] >= 0) { + __indirect_glEnableClientState(GL_COLOR_ARRAY); + __indirect_glColorPointer(modes[idx][1].count, modes[idx][1].type, + trueStride, + (const char *) pointer + offsets[1]); + } + if (offsets[2] >= 0) { + __indirect_glEnableClientState(GL_NORMAL_ARRAY); + __indirect_glNormalPointer(GL_FLOAT, trueStride, + (const char *) pointer + offsets[2]); + } + __indirect_glEnableClientState(GL_VERTEX_ARRAY); + __indirect_glVertexPointer(modes[idx][3].count, GL_FLOAT, + trueStride, + (const char *) pointer + offsets[3]); +} diff --git a/src/glx/xf86dri.h b/src/glx/xf86dri.h new file mode 100644 index 0000000..ba26600 --- /dev/null +++ b/src/glx/xf86dri.h @@ -0,0 +1,124 @@ +/************************************************************************** + +Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. +Copyright 2000 VA Linux Systems, 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 PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/** + * \file xf86dri.h + * Protocol numbers and function prototypes for DRI X protocol. + * + * \author Kevin E. Martin + * \author Jens Owen + * \author Rickard E. (Rik) Faith + */ + +#ifndef _XF86DRI_H_ +#define _XF86DRI_H_ + +#include +#include + +#define X_XF86DRIQueryVersion 0 +#define X_XF86DRIQueryDirectRenderingCapable 1 +#define X_XF86DRIOpenConnection 2 +#define X_XF86DRICloseConnection 3 +#define X_XF86DRIGetClientDriverName 4 +#define X_XF86DRICreateContext 5 +#define X_XF86DRIDestroyContext 6 +#define X_XF86DRICreateDrawable 7 +#define X_XF86DRIDestroyDrawable 8 +#define X_XF86DRIGetDrawableInfo 9 +#define X_XF86DRIGetDeviceInfo 10 +#define X_XF86DRIAuthConnection 11 +#define X_XF86DRIOpenFullScreen 12 /* Deprecated */ +#define X_XF86DRICloseFullScreen 13 /* Deprecated */ + +#define XF86DRINumberEvents 0 + +#define XF86DRIClientNotLocal 0 +#define XF86DRIOperationNotSupported 1 +#define XF86DRINumberErrors (XF86DRIOperationNotSupported + 1) + +#ifndef _XF86DRI_SERVER_ + +_XFUNCPROTOBEGIN + Bool XF86DRIQueryExtension(Display * dpy, int *event_base, + int *error_base); + +Bool XF86DRIQueryVersion(Display * dpy, int *majorVersion, int *minorVersion, + int *patchVersion); + +Bool XF86DRIQueryDirectRenderingCapable(Display * dpy, int screen, + Bool * isCapable); + +Bool XF86DRIOpenConnection(Display * dpy, int screen, drm_handle_t * hSAREA, + char **busIDString); + +Bool XF86DRIAuthConnection(Display * dpy, int screen, drm_magic_t magic); + +Bool XF86DRICloseConnection(Display * dpy, int screen); + +Bool XF86DRIGetClientDriverName(Display * dpy, int screen, + int *ddxDriverMajorVersion, + int *ddxDriverMinorVersion, + int *ddxDriverPatchVersion, + char **clientDriverName); + +Bool XF86DRICreateContext(Display * dpy, int screen, Visual * visual, + XID * ptr_to_returned_context_id, + drm_context_t * hHWContext); + +Bool XF86DRICreateContextWithConfig(Display * dpy, int screen, int configID, + XID * ptr_to_returned_context_id, + drm_context_t * hHWContext); + +extern Bool XF86DRIDestroyContext(Display * dpy, int screen, XID context_id); + +extern Bool XF86DRICreateDrawable(Display * dpy, int screen, + XID drawable, drm_drawable_t * hHWDrawable); + +extern Bool XF86DRIDestroyDrawable(Display * dpy, int screen, XID drawable); + +Bool XF86DRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable, + unsigned int *index, unsigned int *stamp, + int *X, int *Y, int *W, int *H, + int *numClipRects, drm_clip_rect_t ** pClipRects, + int *backX, int *backY, + int *numBackClipRects, + drm_clip_rect_t ** pBackClipRects); + +Bool XF86DRIGetDeviceInfo(Display * dpy, int screen, + drm_handle_t * hFrameBuffer, int *fbOrigin, + int *fbSize, int *fbStride, int *devPrivateSize, + void **pDevPrivate); + +Bool XF86DRIOpenFullScreen(Display * dpy, int screen, Drawable drawable); + +Bool XF86DRICloseFullScreen(Display * dpy, int screen, Drawable drawable); + +_XFUNCPROTOEND +#endif /* _XF86DRI_SERVER_ */ +#endif /* _XF86DRI_H_ */ diff --git a/src/glx/xf86dristr.h b/src/glx/xf86dristr.h new file mode 100644 index 0000000..c8fbe9d --- /dev/null +++ b/src/glx/xf86dristr.h @@ -0,0 +1,367 @@ +/************************************************************************** + +Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. +Copyright 2000 VA Linux Systems, 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 PRECISION INSIGHT 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. + +**************************************************************************/ + +/* + * Authors: + * Kevin E. Martin + * Jens Owen + * Rickard E. (Rik) Fiath + * + */ + +#ifndef _XF86DRISTR_H_ +#define _XF86DRISTR_H_ + +#include "xf86dri.h" + +#define XF86DRINAME "XFree86-DRI" + +/* The DRI version number. This was originally set to be the same of the + * XFree86 version number. However, this version is really indepedent of + * the XFree86 version. + * + * Version History: + * 4.0.0: Original + * 4.0.1: Patch to bump clipstamp when windows are destroyed, 28 May 02 + * 4.1.0: Add transition from single to multi in DRMInfo rec, 24 Jun 02 + */ +#define XF86DRI_MAJOR_VERSION 4 +#define XF86DRI_MINOR_VERSION 1 +#define XF86DRI_PATCH_VERSION 0 + +typedef struct _XF86DRIQueryVersion +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRIQueryVersion */ + CARD16 length B16; +} xXF86DRIQueryVersionReq; +#define sz_xXF86DRIQueryVersionReq 4 + +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD16 majorVersion B16; /* major version of DRI protocol */ + CARD16 minorVersion B16; /* minor version of DRI protocol */ + CARD32 patchVersion B32; /* patch version of DRI protocol */ + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; +} xXF86DRIQueryVersionReply; +#define sz_xXF86DRIQueryVersionReply 32 + +typedef struct _XF86DRIQueryDirectRenderingCapable +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* X_DRIQueryDirectRenderingCapable */ + CARD16 length B16; + CARD32 screen B32; +} xXF86DRIQueryDirectRenderingCapableReq; +#define sz_xXF86DRIQueryDirectRenderingCapableReq 8 + +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + BOOL isCapable; + BOOL pad2; + BOOL pad3; + BOOL pad4; + CARD32 pad5 B32; + CARD32 pad6 B32; + CARD32 pad7 B32; + CARD32 pad8 B32; + CARD32 pad9 B32; +} xXF86DRIQueryDirectRenderingCapableReply; +#define sz_xXF86DRIQueryDirectRenderingCapableReply 32 + +typedef struct _XF86DRIOpenConnection +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRIOpenConnection */ + CARD16 length B16; + CARD32 screen B32; +} xXF86DRIOpenConnectionReq; +#define sz_xXF86DRIOpenConnectionReq 8 + +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 hSAREALow B32; + CARD32 hSAREAHigh B32; + CARD32 busIdStringLength B32; + CARD32 pad6 B32; + CARD32 pad7 B32; + CARD32 pad8 B32; +} xXF86DRIOpenConnectionReply; +#define sz_xXF86DRIOpenConnectionReply 32 + +typedef struct _XF86DRIAuthConnection +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRICloseConnection */ + CARD16 length B16; + CARD32 screen B32; + CARD32 magic B32; +} xXF86DRIAuthConnectionReq; +#define sz_xXF86DRIAuthConnectionReq 12 + +typedef struct +{ + BYTE type; + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 authenticated B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; +} xXF86DRIAuthConnectionReply; +#define zx_xXF86DRIAuthConnectionReply 32 + +typedef struct _XF86DRICloseConnection +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRICloseConnection */ + CARD16 length B16; + CARD32 screen B32; +} xXF86DRICloseConnectionReq; +#define sz_xXF86DRICloseConnectionReq 8 + +typedef struct _XF86DRIGetClientDriverName +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRIGetClientDriverName */ + CARD16 length B16; + CARD32 screen B32; +} xXF86DRIGetClientDriverNameReq; +#define sz_xXF86DRIGetClientDriverNameReq 8 + +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 ddxDriverMajorVersion B32; + CARD32 ddxDriverMinorVersion B32; + CARD32 ddxDriverPatchVersion B32; + CARD32 clientDriverNameLength B32; + CARD32 pad5 B32; + CARD32 pad6 B32; +} xXF86DRIGetClientDriverNameReply; +#define sz_xXF86DRIGetClientDriverNameReply 32 + +typedef struct _XF86DRICreateContext +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRICreateContext */ + CARD16 length B16; + CARD32 screen B32; + CARD32 visual B32; + CARD32 context B32; +} xXF86DRICreateContextReq; +#define sz_xXF86DRICreateContextReq 16 + +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 hHWContext B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; +} xXF86DRICreateContextReply; +#define sz_xXF86DRICreateContextReply 32 + +typedef struct _XF86DRIDestroyContext +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRIDestroyContext */ + CARD16 length B16; + CARD32 screen B32; + CARD32 context B32; +} xXF86DRIDestroyContextReq; +#define sz_xXF86DRIDestroyContextReq 12 + +typedef struct _XF86DRICreateDrawable +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRICreateDrawable */ + CARD16 length B16; + CARD32 screen B32; + CARD32 drawable B32; +} xXF86DRICreateDrawableReq; +#define sz_xXF86DRICreateDrawableReq 12 + +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 hHWDrawable B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; +} xXF86DRICreateDrawableReply; +#define sz_xXF86DRICreateDrawableReply 32 + +typedef struct _XF86DRIDestroyDrawable +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRIDestroyDrawable */ + CARD16 length B16; + CARD32 screen B32; + CARD32 drawable B32; +} xXF86DRIDestroyDrawableReq; +#define sz_xXF86DRIDestroyDrawableReq 12 + +typedef struct _XF86DRIGetDrawableInfo +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRIGetDrawableInfo */ + CARD16 length B16; + CARD32 screen B32; + CARD32 drawable B32; +} xXF86DRIGetDrawableInfoReq; +#define sz_xXF86DRIGetDrawableInfoReq 12 + +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 drawableTableIndex B32; + CARD32 drawableTableStamp B32; + INT16 drawableX B16; + INT16 drawableY B16; + INT16 drawableWidth B16; + INT16 drawableHeight B16; + CARD32 numClipRects B32; + INT16 backX B16; + INT16 backY B16; + CARD32 numBackClipRects B32; +} xXF86DRIGetDrawableInfoReply; + +#define sz_xXF86DRIGetDrawableInfoReply 36 + + +typedef struct _XF86DRIGetDeviceInfo +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRIGetDeviceInfo */ + CARD16 length B16; + CARD32 screen B32; +} xXF86DRIGetDeviceInfoReq; +#define sz_xXF86DRIGetDeviceInfoReq 8 + +typedef struct +{ + BYTE type; /* X_Reply */ + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 hFrameBufferLow B32; + CARD32 hFrameBufferHigh B32; + CARD32 framebufferOrigin B32; + CARD32 framebufferSize B32; + CARD32 framebufferStride B32; + CARD32 devPrivateSize B32; +} xXF86DRIGetDeviceInfoReply; +#define sz_xXF86DRIGetDeviceInfoReply 32 + +typedef struct _XF86DRIOpenFullScreen +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRIOpenFullScreen */ + CARD16 length B16; + CARD32 screen B32; + CARD32 drawable B32; +} xXF86DRIOpenFullScreenReq; +#define sz_xXF86DRIOpenFullScreenReq 12 + +typedef struct +{ + BYTE type; + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 isFullScreen B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; +} xXF86DRIOpenFullScreenReply; +#define sz_xXF86DRIOpenFullScreenReply 32 + +typedef struct _XF86DRICloseFullScreen +{ + CARD8 reqType; /* always DRIReqCode */ + CARD8 driReqType; /* always X_DRICloseFullScreen */ + CARD16 length B16; + CARD32 screen B32; + CARD32 drawable B32; +} xXF86DRICloseFullScreenReq; +#define sz_xXF86DRICloseFullScreenReq 12 + +typedef struct +{ + BYTE type; + BOOL pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; + CARD32 pad7 B32; +} xXF86DRICloseFullScreenReply; +#define sz_xXF86DRICloseFullScreenReply 32 + + +#endif /* _XF86DRISTR_H_ */ diff --git a/src/glx/xfont.c b/src/glx/xfont.c new file mode 100644 index 0000000..4ca2c8f --- /dev/null +++ b/src/glx/xfont.c @@ -0,0 +1,375 @@ +/* + * Mesa 3-D graphics library + * Version: 3.1 + * + * Copyright (C) 1999 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. + */ + + +/* xfonts.c -- glXUseXFont() for Mesa written by + * Copyright (C) 1995 Thorsten.Ohl @ Physik.TH-Darmstadt.de + */ + +/* + This was take from Mesa and modified to work in the real GLX structure. + It provides a fully client side implementation of glXUseXFont and is + called by that routine when direct rendering is enabled. +*/ + +#ifdef GLX_DIRECT_RENDERING + +#include "glxclient.h" + +/* Some debugging info. */ + +#ifdef DEBUG +#undef _R +#undef _G +#undef _B +#include + +int debug_xfonts = 0; + +static void +dump_char_struct(XCharStruct * ch, char *prefix) +{ + printf("%slbearing = %d, rbearing = %d, width = %d\n", + prefix, ch->lbearing, ch->rbearing, ch->width); + printf("%sascent = %d, descent = %d, attributes = %u\n", + prefix, ch->ascent, ch->descent, (unsigned int) ch->attributes); +} + +static void +dump_font_struct(XFontStruct * font) +{ + printf("ascent = %d, descent = %d\n", font->ascent, font->descent); + printf("char_or_byte2 = (%u,%u)\n", + font->min_char_or_byte2, font->max_char_or_byte2); + printf("byte1 = (%u,%u)\n", font->min_byte1, font->max_byte1); + printf("all_chars_exist = %s\n", font->all_chars_exist ? "True" : "False"); + printf("default_char = %c (\\%03o)\n", + (char) (isprint(font->default_char) ? font->default_char : ' '), + font->default_char); + dump_char_struct(&font->min_bounds, "min> "); + dump_char_struct(&font->max_bounds, "max> "); +#if 0 + for (c = font->min_char_or_byte2; c <= font->max_char_or_byte2; c++) { + char prefix[8]; + sprintf(prefix, "%d> ", c); + dump_char_struct(&font->per_char[c], prefix); + } +#endif +} + +static void +dump_bitmap(unsigned int width, unsigned int height, GLubyte * bitmap) +{ + unsigned int x, y; + + printf(" "); + for (x = 0; x < 8 * width; x++) + printf("%o", 7 - (x % 8)); + putchar('\n'); + for (y = 0; y < height; y++) { + printf("%3o:", y); + for (x = 0; x < 8 * width; x++) + putchar((bitmap[width * (height - y - 1) + x / 8] & (1 << (7 - (x % + 8)))) + ? '*' : '.'); + printf(" "); + for (x = 0; x < width; x++) + printf("0x%02x, ", bitmap[width * (height - y - 1) + x]); + putchar('\n'); + } +} +#endif /* DEBUG */ + + +/* Implementation. */ + +/* Fill a BITMAP with a character C from thew current font + in the graphics context GC. WIDTH is the width in bytes + and HEIGHT is the height in bits. + + Note that the generated bitmaps must be used with + + glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE); + glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE); + glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei (GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei (GL_UNPACK_ALIGNMENT, 1); + + Possible optimizations: + + * use only one reusable pixmap with the maximum dimensions. + * draw the entire font into a single pixmap (careful with + proportional fonts!). +*/ + + +/* + * Generate OpenGL-compatible bitmap. + */ +static void +fill_bitmap(Display * dpy, Window win, GC gc, + unsigned int width, unsigned int height, + int x0, int y0, unsigned int c, GLubyte * bitmap) +{ + XImage *image; + unsigned int x, y; + Pixmap pixmap; + XChar2b char2b; + + pixmap = XCreatePixmap(dpy, win, 8 * width, height, 1); + XSetForeground(dpy, gc, 0); + XFillRectangle(dpy, pixmap, gc, 0, 0, 8 * width, height); + XSetForeground(dpy, gc, 1); + + char2b.byte1 = (c >> 8) & 0xff; + char2b.byte2 = (c & 0xff); + + XDrawString16(dpy, pixmap, gc, x0, y0, &char2b, 1); + + image = XGetImage(dpy, pixmap, 0, 0, 8 * width, height, 1, XYPixmap); + if (image) { + /* Fill the bitmap (X11 and OpenGL are upside down wrt each other). */ + for (y = 0; y < height; y++) + for (x = 0; x < 8 * width; x++) + if (XGetPixel(image, x, y)) + bitmap[width * (height - y - 1) + x / 8] |= + (1 << (7 - (x % 8))); + XDestroyImage(image); + } + + XFreePixmap(dpy, pixmap); +} + +/* + * determine if a given glyph is valid and return the + * corresponding XCharStruct. + */ +static XCharStruct * +isvalid(XFontStruct * fs, int which) +{ + unsigned int rows, pages; + int byte1 = 0, byte2 = 0; + int i, valid = 1; + + rows = fs->max_byte1 - fs->min_byte1 + 1; + pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1; + + if (rows == 1) { + /* "linear" fonts */ + if ((fs->min_char_or_byte2 > which) || (fs->max_char_or_byte2 < which)) + valid = 0; + } + else { + /* "matrix" fonts */ + byte2 = which & 0xff; + byte1 = which >> 8; + if ((fs->min_char_or_byte2 > byte2) || + (fs->max_char_or_byte2 < byte2) || + (fs->min_byte1 > byte1) || (fs->max_byte1 < byte1)) + valid = 0; + } + + if (valid) { + if (fs->per_char) { + if (rows == 1) { + /* "linear" fonts */ + return (fs->per_char + (which - fs->min_char_or_byte2)); + } + else { + /* "matrix" fonts */ + i = ((byte1 - fs->min_byte1) * pages) + + (byte2 - fs->min_char_or_byte2); + return (fs->per_char + i); + } + } + else { + return (&fs->min_bounds); + } + } + return (NULL); +} + +_X_HIDDEN void +DRI_glXUseXFont(struct glx_context *CC, Font font, int first, int count, int listbase) +{ + Display *dpy; + Window win; + Pixmap pixmap; + GC gc; + XGCValues values; + unsigned long valuemask; + XFontStruct *fs; + + GLint swapbytes, lsbfirst, rowlength; + GLint skiprows, skippixels, alignment; + + unsigned int max_width, max_height, max_bm_width, max_bm_height; + GLubyte *bm; + + int i; + + dpy = CC->currentDpy; + win = CC->currentDrawable; + + fs = XQueryFont(dpy, font); + if (!fs) { + __glXSetError(CC, GL_INVALID_VALUE); + return; + } + + /* Allocate a bitmap that can fit all characters. */ + max_width = fs->max_bounds.rbearing - fs->min_bounds.lbearing; + max_height = fs->max_bounds.ascent + fs->max_bounds.descent; + max_bm_width = (max_width + 7) / 8; + max_bm_height = max_height; + + bm = (GLubyte *) Xmalloc((max_bm_width * max_bm_height) * sizeof(GLubyte)); + if (!bm) { + XFreeFontInfo(NULL, fs, 1); + __glXSetError(CC, GL_OUT_OF_MEMORY); + return; + } + +#if 0 + /* get the page info */ + pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1; + firstchar = (fs->min_byte1 << 8) + fs->min_char_or_byte2; + lastchar = (fs->max_byte1 << 8) + fs->max_char_or_byte2; + rows = fs->max_byte1 - fs->min_byte1 + 1; + unsigned int first_char, last_char, pages, rows; +#endif + + /* Save the current packing mode for bitmaps. */ + glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes); + glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst); + glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength); + glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows); + glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels); + glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); + + /* Enforce a standard packing mode which is compatible with + fill_bitmap() from above. This is actually the default mode, + except for the (non)alignment. */ + glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); + glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + pixmap = XCreatePixmap(dpy, win, 10, 10, 1); + values.foreground = BlackPixel(dpy, DefaultScreen(dpy)); + values.background = WhitePixel(dpy, DefaultScreen(dpy)); + values.font = fs->fid; + valuemask = GCForeground | GCBackground | GCFont; + gc = XCreateGC(dpy, pixmap, valuemask, &values); + XFreePixmap(dpy, pixmap); + +#ifdef DEBUG + if (debug_xfonts) + dump_font_struct(fs); +#endif + + for (i = 0; i < count; i++) { + unsigned int width, height, bm_width, bm_height; + GLfloat x0, y0, dx, dy; + XCharStruct *ch; + int x, y; + unsigned int c = first + i; + int list = listbase + i; + int valid; + + /* check on index validity and get the bounds */ + ch = isvalid(fs, c); + if (!ch) { + ch = &fs->max_bounds; + valid = 0; + } + else { + valid = 1; + } + +#ifdef DEBUG + if (debug_xfonts) { + char s[7]; + sprintf(s, isprint(c) ? "%c> " : "\\%03o> ", c); + dump_char_struct(ch, s); + } +#endif + + /* glBitmap()' parameters: + straight from the glXUseXFont(3) manpage. */ + width = ch->rbearing - ch->lbearing; + height = ch->ascent + ch->descent; + x0 = -ch->lbearing; + y0 = ch->descent - 1; + dx = ch->width; + dy = 0; + + /* X11's starting point. */ + x = -ch->lbearing; + y = ch->ascent; + + /* Round the width to a multiple of eight. We will use this also + for the pixmap for capturing the X11 font. This is slightly + inefficient, but it makes the OpenGL part real easy. */ + bm_width = (width + 7) / 8; + bm_height = height; + + glNewList(list, GL_COMPILE); + if (valid && (bm_width > 0) && (bm_height > 0)) { + + memset(bm, '\0', bm_width * bm_height); + fill_bitmap(dpy, win, gc, bm_width, bm_height, x, y, c, bm); + + glBitmap(width, height, x0, y0, dx, dy, bm); +#ifdef DEBUG + if (debug_xfonts) { + printf("width/height = %u/%u\n", width, height); + printf("bm_width/bm_height = %u/%u\n", bm_width, bm_height); + dump_bitmap(bm_width, bm_height, bm); + } +#endif + } + else { + glBitmap(0, 0, 0.0, 0.0, dx, dy, NULL); + } + glEndList(); + } + + Xfree(bm); + XFreeFontInfo(NULL, fs, 1); + XFreeGC(dpy, gc); + + /* Restore saved packing modes. */ + glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes); + glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst); + glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength); + glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels); + glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); +} + +#endif diff --git a/src/mapi/es1api/Makefile b/src/mapi/es1api/Makefile new file mode 100644 index 0000000..576ac5a --- /dev/null +++ b/src/mapi/es1api/Makefile @@ -0,0 +1,144 @@ +# src/mapi/es1api/Makefile + +TOP := ../../.. +include $(TOP)/configs/current + +# this Makefile can build both OpenGL ES 1.1 and 2.0 +ifeq ($(ES),) +ES := es1 + +GLES_HEADER := GLES +GLES_PC := glesv1_cm.pc + +GLES_LIB := $(GLESv1_CM_LIB) +GLES_LIB_NAME := $(GLESv1_CM_LIB_NAME) +GLES_LIB_GLOB := $(GLESv1_CM_LIB_GLOB) +GLES_LIB_DEPS := $(GLESv1_CM_LIB_DEPS) +GLES_LIB_MAJOR := 1 +GLES_LIB_MINOR := 1 +GLES_LIB_PATCH := 0 +else +GLES_HEADER := GLES2 +GLES_PC := glesv2.pc + +GLES_LIB := $(GLESv2_LIB) +GLES_LIB_NAME := $(GLESv2_LIB_NAME) +GLES_LIB_GLOB := $(GLESv2_LIB_GLOB) +GLES_LIB_DEPS := $(GLESv2_LIB_DEPS) +GLES_LIB_MAJOR := 2 +GLES_LIB_MINOR := 0 +GLES_LIB_PATCH := 0 +endif + +ESAPI = $(ES)api + +GLAPI := $(TOP)/src/mapi/glapi +MAPI := $(TOP)/src/mapi/mapi +# directory for generated sources/headers +GEN := glapi + +include $(GLAPI)/sources.mak +GLAPI_OBJECTS := $(GLAPI_SOURCES:.c=.o) +GLAPI_SOURCES := $(addprefix $(GLAPI)/, $(GLAPI_SOURCES)) +GLAPI_ASM_OBJECTS := $(GLAPI_ASM_SOURCES:.S=.o) +GLAPI_ASM_SOURCES := $(addprefix $(GEN)/, $(GLAPI_ASM_SOURCES)) + +include $(MAPI)/sources.mak +MAPI_GLAPI_OBJECTS := $(MAPI_GLAPI_SOURCES:.c=.o) +MAPI_GLAPI_SOURCES := $(addprefix $(MAPI)/, $(MAPI_GLAPI_SOURCES)) + +ESAPI_OBJECTS = $(GLAPI_OBJECTS) $(GLAPI_ASM_OBJECTS) $(MAPI_GLAPI_OBJECTS) + +INCLUDE_DIRS = \ + -I$(TOP)/include \ + -I$(TOP)/src/mapi/$(ESAPI) \ + -I$(TOP)/src/mapi \ + -I$(TOP)/src/mesa + +.PHONY: default +default: depend $(TOP)/$(LIB_DIR)/$(GLES_LIB_NAME) + +$(TOP)/$(LIB_DIR)/$(GLES_LIB_NAME): $(ESAPI_OBJECTS) + $(MKLIB) -o $(GLES_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + -major $(GLES_LIB_MAJOR) \ + -minor $(GLES_LIB_MINOR) \ + -patch $(GLES_LIB_PATCH) \ + -id $(INSTALL_LIB_DIR)/lib$(GLES_LIB).$(GLES_LIB_MAJOR).dylib \ + $(MKLIB_OPTIONS) -install $(TOP)/$(LIB_DIR) \ + $(ESAPI_OBJECTS) $(GLES_LIB_DEPS) + +# not used, but kept for completeness +lib$(ESAPI).a: $(ESAPI_OBJECTS) + @$(MKLIB) -o $(ESAPI) -static $(ESAPI_OBJECTS) + +$(GLAPI_OBJECTS): %.o: $(GLAPI)/%.c + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + +$(GLAPI_ASM_OBJECTS): %.o: $(GEN)/%.S + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + +$(MAPI_GLAPI_OBJECTS): %.o: $(MAPI)/%.c + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) -DMAPI_GLAPI_CURRENT $< -o $@ + +$(GLAPI_SOURCES) $(GLAPI_ASM_SOURCES): | glapi-stamp + +glapi-stamp: + @# generate sources/headers + @$(MAKE) -C $(GLAPI)/gen-es $(ES) + @touch $@ + +.PHONY: clean +clean: + -rm -f $(GLES_PC) + -rm -f $(TOP)/$(LIB_DIR)/$(GLES_LIB_NAME) + -rm -f lib$(ESAPI).a + -rm -f $(ESAPI_OBJECTS) + -rm -f depend depend.bak + -rm -f glapi-stamp + @# clean generated sources/headers + @$(MAKE) -C $(GLAPI)/gen-es clean-$(ES) + +pcedit = \ + -e 's,@INSTALL_DIR@,$(INSTALL_DIR),' \ + -e 's,@INSTALL_LIB_DIR@,$(INSTALL_LIB_DIR),' \ + -e 's,@INSTALL_INC_DIR@,$(INSTALL_INC_DIR),' \ + -e 's,@VERSION@,$(MESA_MAJOR).$(MESA_MINOR).$(MESA_TINY),' \ + +pcedit-es1 = \ + $(pcedit) \ + -e 's,@GLESv1_CM_PC_REQ_PRIV@,$(GLESv1_CM_PC_REQ_PRIV),' \ + -e 's,@GLESv1_CM_PC_LIB_PRIV@,$(GLESv1_CM_PC_LIB_PRIV),' \ + -e 's,@GLESv1_CM_PC_CFLAGS@,$(GLESv1_CM_PC_CFLAGS),' \ + -e 's,@GLESv1_CM_LIB@,$(GLESv1_CM_LIB),' + +pcedit-es2 = \ + $(pcedit) \ + -e 's,@GLESv2_PC_REQ_PRIV@,$(GLESv2_PC_REQ_PRIV),' \ + -e 's,@GLESv2_PC_LIB_PRIV@,$(GLESv2_PC_LIB_PRIV),' \ + -e 's,@GLESv2_PC_CFLAGS@,$(GLESv2_PC_CFLAGS),' \ + -e 's,@GLESv2_LIB@,$(GLESv2_LIB),' + +$(GLES_PC): $(GLES_PC).in + @sed $(pcedit-$(ES)) $< > $@ + +install-headers: + $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/$(GLES_HEADER) + $(INSTALL) -m 644 $(TOP)/include/$(GLES_HEADER)/*.h \ + $(DESTDIR)$(INSTALL_INC_DIR)/$(GLES_HEADER) + +install-pc: $(GLES_PC) + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig + $(INSTALL) -m 644 $(GLES_PC) $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig + +install: default install-headers install-pc + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR) + $(MINSTALL) $(TOP)/$(LIB_DIR)/$(GLES_LIB_GLOB) \ + $(DESTDIR)$(INSTALL_LIB_DIR) + +depend: $(GLAPI_SOURCES) $(MAPI_GLAPI_SOURCES) + @echo "running $(MKDEP)" + @touch depend + @$(MKDEP) $(MKDEP_OPTIONS) -f- $(DEFINES) $(INCLUDE_DIRS) \ + -DMAPI_GLAPI_CURRENT $(GLAPI_SOURCES) $(MAPI_GLAPI_SOURCES) \ + 2>/dev/null | sed -e 's,^$(GLAPI)/,,' -e 's,^$(MAPI)/,,' \ + > depend diff --git a/src/mapi/es1api/glesv1_cm.pc.in b/src/mapi/es1api/glesv1_cm.pc.in new file mode 100644 index 0000000..291f5ab --- /dev/null +++ b/src/mapi/es1api/glesv1_cm.pc.in @@ -0,0 +1,12 @@ +prefix=@INSTALL_DIR@ +exec_prefix=${prefix} +libdir=@INSTALL_LIB_DIR@ +includedir=@INSTALL_INC_DIR@ + +Name: glesv1_cm +Description: Mesa OpenGL ES 1.1 CM library +Requires.private: @GLESv1_CM_PC_REQ_PRIV@ +Version: @VERSION@ +Libs: -L${libdir} -l@GLESv1_CM_LIB@ +Libs.private: @GLESv1_CM_PC_LIB_PRIV@ +Cflags: -I${includedir} @GLESv1_CM_PC_CFLAGS@ diff --git a/src/mapi/es2api/Makefile b/src/mapi/es2api/Makefile new file mode 100644 index 0000000..21816a6 --- /dev/null +++ b/src/mapi/es2api/Makefile @@ -0,0 +1,3 @@ +# src/mapi/es2api/Makefile +ES := es2 +include ../es1api/Makefile diff --git a/src/mapi/es2api/glesv2.pc.in b/src/mapi/es2api/glesv2.pc.in new file mode 100644 index 0000000..3b747cb --- /dev/null +++ b/src/mapi/es2api/glesv2.pc.in @@ -0,0 +1,12 @@ +prefix=@INSTALL_DIR@ +exec_prefix=${prefix} +libdir=@INSTALL_LIB_DIR@ +includedir=@INSTALL_INC_DIR@ + +Name: glesv2 +Description: Mesa OpenGL ES 2.0 library +Requires.private: @GLESv2_PC_REQ_PRIV@ +Version: @VERSION@ +Libs: -L${libdir} -l@GLESv2_LIB@ +Libs.private: @GLESv2_PC_LIB_PRIV@ +Cflags: -I${includedir} @GLESv2_PC_CFLAGS@ diff --git a/src/mapi/glapi/Makefile b/src/mapi/glapi/Makefile new file mode 100644 index 0000000..ca9381d --- /dev/null +++ b/src/mapi/glapi/Makefile @@ -0,0 +1,53 @@ +# src/mapi/glapi/Makefile + +TOP = ../../.. +include $(TOP)/configs/current + +TARGET = glapi + +MAPI = $(TOP)/src/mapi/mapi + +include sources.mak +GLAPI_OBJECTS = $(GLAPI_SOURCES:.c=.o) +GLAPI_ASM_OBJECTS = $(GLAPI_ASM_SOURCES:.S=.o) + +include $(MAPI)/sources.mak +MAPI_GLAPI_OBJECTS := $(MAPI_GLAPI_SOURCES:.c=.o) +MAPI_GLAPI_SOURCES := $(addprefix $(MAPI)/, $(MAPI_GLAPI_SOURCES)) + +TARGET_OBJECTS = $(GLAPI_OBJECTS) $(GLAPI_ASM_OBJECTS) $(MAPI_GLAPI_OBJECTS) + +INCLUDE_DIRS = \ + -I$(TOP)/include \ + -I$(TOP)/src/mapi \ + -I$(TOP)/src/mesa + +default: depend lib$(TARGET).a + +lib$(TARGET).a: $(TARGET_OBJECTS) + @$(MKLIB) -o $(TARGET) -static $(TARGET_OBJECTS) + +$(GLAPI_OBJECTS): %.o: %.c + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + +$(GLAPI_ASM_OBJECTS): %.o: %.S + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ + +$(MAPI_GLAPI_OBJECTS): %.o: $(MAPI)/%.c + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) -DMAPI_GLAPI_CURRENT $< -o $@ + +install: + +clean: + -rm -f $(TARGET_OBJECTS) + -rm -f lib$(TARGET).a + -rm -f depend depend.bak + +depend: $(GLAPI_SOURCES) $(MAPI_GLAPI_SOURCES) + @ echo "running $(MKDEP)" + @ touch depend + @$(MKDEP) $(MKDEP_OPTIONS) -f- $(DEFINES) $(INCLUDE_DIRS) \ + -DMAPI_GLAPI_CURRENT $(GLAPI_SOURCES) $(MAPI_GLAPI_SOURCES) \ + 2>/dev/null | sed -e 's,^$(MAPI)/,,' > depend + +-include depend diff --git a/src/mapi/glapi/SConscript b/src/mapi/glapi/SConscript new file mode 100644 index 0000000..4ef855f --- /dev/null +++ b/src/mapi/glapi/SConscript @@ -0,0 +1,82 @@ +####################################################################### +# SConscript for glapi + + +Import('*') + +if env['platform'] != 'winddk': + + env = env.Clone() + + env.Append(CPPDEFINES = [ + 'MAPI_GLAPI_CURRENT', + ]) + + if env['platform'] == 'windows': + env.Append(CPPDEFINES = [ + '_GDI32_', # prevent gl* being declared __declspec(dllimport) in MS headers + 'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers + ]) + + env.Append(CPPPATH = [ + '#/src/mapi', + '#/src/mesa', + ]) + + glapi_sources = [ + 'glapi_dispatch.c', + 'glapi_entrypoint.c', + 'glapi_getproc.c', + 'glapi_nop.c', + 'glthread.c', + ] + + mapi_sources = [ + 'u_current.c', + 'u_execmem.c', + 'u_thread.c', + ] + for s in mapi_sources: + o = env.SharedObject(s[:-2], '../mapi/' + s) + glapi_sources.append(o) + + # + # Assembly sources + # + if env['gcc'] and env['platform'] != 'windows': + if env['machine'] == 'x86': + env.Append(CPPDEFINES = [ + 'USE_X86_ASM', + 'USE_MMX_ASM', + 'USE_3DNOW_ASM', + 'USE_SSE_ASM', + ]) + glapi_sources += [ + 'glapi_x86.S', + ] + elif env['machine'] == 'x86_64': + env.Append(CPPDEFINES = [ + 'USE_X86_64_ASM', + ]) + glapi_sources += [ + 'glapi_x86-64.S' + ] + elif env['machine'] == 'ppc': + env.Append(CPPDEFINES = [ + 'USE_PPC_ASM', + 'USE_VMX_ASM', + ]) + glapi_sources += [ + ] + elif env['machine'] == 'sparc': + glapi_sources += [ + 'glapi_sparc.S' + ] + else: + pass + + glapi = env.ConvenienceLibrary( + target = 'glapi', + source = glapi_sources, + ) + Export('glapi') diff --git a/src/mapi/glapi/gen-es/Makefile b/src/mapi/glapi/gen-es/Makefile new file mode 100644 index 0000000..8375792 --- /dev/null +++ b/src/mapi/glapi/gen-es/Makefile @@ -0,0 +1,92 @@ +TOP = ../../../.. +GLAPI = ../gen +include $(TOP)/configs/current + +OUTPUTS := \ + glapi/glapitable.h \ + glapi/glapitemp.h \ + glapi/glprocs.h \ + glapi/glapi_sparc.S \ + glapi/glapi_x86-64.S \ + glapi/glapi_x86.S \ + main/glapidispatch.h \ + main/remap_helper.h + +COMMON = gl_XML.py glX_XML.py license.py typeexpr.py +COMMON := $(addprefix $(GLAPI)/, $(COMMON)) + +ES1_APIXML := es1_API.xml +ES2_APIXML := es2_API.xml +ES1_OUTPUT_DIR := $(TOP)/src/mapi/es1api +ES2_OUTPUT_DIR := $(TOP)/src/mapi/es2api + +ES1_DEPS = $(ES1_APIXML) base1_API.xml es1_EXT.xml es_EXT.xml \ + es1_COMPAT.xml es_COMPAT.xml +ES2_DEPS = $(ES2_APIXML) base2_API.xml es2_EXT.xml es_EXT.xml \ + es2_COMPAT.xml es_COMPAT.xml + +ES1_OUTPUTS := $(addprefix $(ES1_OUTPUT_DIR)/, $(OUTPUTS)) +ES2_OUTPUTS := $(addprefix $(ES2_OUTPUT_DIR)/, $(OUTPUTS)) + +all: es1 es2 + +es1: $(ES1_OUTPUTS) +es2: $(ES2_OUTPUTS) + +$(ES1_OUTPUTS): APIXML := $(ES1_APIXML) +$(ES2_OUTPUTS): APIXML := $(ES2_APIXML) +$(ES1_OUTPUTS): $(ES1_DEPS) +$(ES2_OUTPUTS): $(ES2_DEPS) + +define gen-glapi + @mkdir -p $(dir $@) + $(PYTHON2) $(PYTHON_FLAGS) $< -f $(APIXML) $(1) > $@ +endef + +%/glapidispatch.h: $(GLAPI)/gl_table.py $(COMMON) + $(call gen-glapi,-c -m remap_table) + +%/glapitable.h: $(GLAPI)/gl_table.py $(COMMON) + $(call gen-glapi,-c) + +%/glapitemp.h: $(GLAPI)/gl_apitemp.py $(COMMON) + $(call gen-glapi,-c) + +%/glprocs.h: $(GLAPI)/gl_procs.py $(COMMON) + $(call gen-glapi,-c) + +%/glapi_sparc.S: $(GLAPI)/gl_SPARC_asm.py $(COMMON) + $(call gen-glapi) + +%/glapi_x86-64.S: $(GLAPI)/gl_x86-64_asm.py $(COMMON) + $(call gen-glapi) + +%/glapi_x86.S: $(GLAPI)/gl_x86_asm.py $(COMMON) + $(call gen-glapi) + +%/main/remap_helper.h: $(GLAPI)/remap_helper.py $(COMMON) + $(call gen-glapi) + +verify_xml: + @if [ ! -f gl.h ]; then \ + echo "Please copy gl.h and gl2.h to this directory"; \ + exit 1; \ + fi + @echo "Verifying that es1_API.xml covers OpenGL ES 1.1..." + @$(PYTHON2) $(PYTHON_FLAGS) gl_parse_header.py gl.h > tmp.xml + @$(PYTHON2) $(PYTHON_FLAGS) gl_compare.py difference tmp.xml es1_API.xml + @echo "Verifying that es2_API.xml covers OpenGL ES 2.0..." + @$(PYTHON2) $(PYTHON_FLAGS) gl_parse_header.py gl2.h > tmp.xml + @$(PYTHON2) $(PYTHON_FLAGS) gl_compare.py difference tmp.xml es2_API.xml + @rm -f tmp.xml + +clean-es1: + -rm -rf $(ES1_OUTPUT_DIR)/glapi + -rm -rf $(ES1_OUTPUT_DIR)/main + +clean-es2: + -rm -rf $(ES2_OUTPUT_DIR)/glapi + -rm -rf $(ES2_OUTPUT_DIR)/main + +clean: clean-es1 clean-es2 + -rm -f *~ *.pyc *.pyo diff --git a/src/mapi/glapi/gen-es/base1_API.xml b/src/mapi/glapi/gen-es/base1_API.xml new file mode 100644 index 0000000..720be25 --- /dev/null +++ b/src/mapi/glapi/gen-es/base1_API.xml @@ -0,0 +1,744 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen-es/base2_API.xml b/src/mapi/glapi/gen-es/base2_API.xml new file mode 100644 index 0000000..b59ef62 --- /dev/null +++ b/src/mapi/glapi/gen-es/base2_API.xml @@ -0,0 +1,533 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen-es/es1_API.xml b/src/mapi/glapi/gen-es/es1_API.xml new file mode 100644 index 0000000..3428ae5 --- /dev/null +++ b/src/mapi/glapi/gen-es/es1_API.xml @@ -0,0 +1,1100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen-es/es1_COMPAT.xml b/src/mapi/glapi/gen-es/es1_COMPAT.xml new file mode 100644 index 0000000..096cea8 --- /dev/null +++ b/src/mapi/glapi/gen-es/es1_COMPAT.xml @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen-es/es1_EXT.xml b/src/mapi/glapi/gen-es/es1_EXT.xml new file mode 100644 index 0000000..c1e8637 --- /dev/null +++ b/src/mapi/glapi/gen-es/es1_EXT.xml @@ -0,0 +1,699 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen-es/es2_API.xml b/src/mapi/glapi/gen-es/es2_API.xml new file mode 100644 index 0000000..f8af63b --- /dev/null +++ b/src/mapi/glapi/gen-es/es2_API.xml @@ -0,0 +1,294 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen-es/es2_COMPAT.xml b/src/mapi/glapi/gen-es/es2_COMPAT.xml new file mode 100644 index 0000000..1bd3569 --- /dev/null +++ b/src/mapi/glapi/gen-es/es2_COMPAT.xml @@ -0,0 +1,368 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen-es/es2_EXT.xml b/src/mapi/glapi/gen-es/es2_EXT.xml new file mode 100644 index 0000000..4a67952 --- /dev/null +++ b/src/mapi/glapi/gen-es/es2_EXT.xml @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen-es/es_COMPAT.xml b/src/mapi/glapi/gen-es/es_COMPAT.xml new file mode 100644 index 0000000..7c72926 --- /dev/null +++ b/src/mapi/glapi/gen-es/es_COMPAT.xml @@ -0,0 +1,2646 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen-es/es_EXT.xml b/src/mapi/glapi/gen-es/es_EXT.xml new file mode 100644 index 0000000..0013df8 --- /dev/null +++ b/src/mapi/glapi/gen-es/es_EXT.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen-es/gl_compare.py b/src/mapi/glapi/gen-es/gl_compare.py new file mode 100644 index 0000000..6b5e43b --- /dev/null +++ b/src/mapi/glapi/gen-es/gl_compare.py @@ -0,0 +1,354 @@ +#!/usr/bin/python +# +# Copyright (C) 2009 Chia-I Wu +# +# 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 +# IBM 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. + +import sys +import os.path +import getopt + +GLAPI = "../../glapi/gen" +sys.path.append(GLAPI) + +import gl_XML +import glX_XML + +class ApiSet(object): + def __init__(self, api, elts=["enum", "type", "function"]): + self.api = api + self.elts = elts + + def _check_enum(self, e1, e2, strict=True): + if e1.name != e2.name: + raise ValueError("%s: name mismatch" % e1.name) + if e1.value != e2.value: + raise ValueError("%s: value 0x%04x != 0x%04x" + % (e1.name, e1.value, e2.value)) + + def _check_type(self, t1, t2, strict=True): + if t1.name != t2.name: + raise ValueError("%s: name mismatch" % t1.name) + if t1.type_expr.string() != t2.type_expr.string(): + raise ValueError("%s: type %s != %s" + % (t1.name, t1.type_expr.string(), t2.type_expr.string())) + + def _check_function(self, f1, f2, strict=True): + if f1.name != f2.name: + raise ValueError("%s: name mismatch" % f1.name) + if f1.return_type != f2.return_type: + raise ValueError("%s: return type %s != %s" + % (f1.name, f1.return_type, f2.return_type)) + # there might be padded parameters + if strict and len(f1.parameters) != len(f2.parameters): + raise ValueError("%s: parameter length %d != %d" + % (f1.name, len(f1.parameters), len(f2.parameters))) + if f1.assign_offset != f2.assign_offset: + if ((f1.assign_offset and f2.offset < 0) or + (f2.assign_offset and f1.offset < 0)): + raise ValueError("%s: assign offset %d != %d" + % (f1.name, f1.assign_offset, f2.assign_offset)) + elif not f1.assign_offset: + if f1.offset != f2.offset: + raise ValueError("%s: offset %d != %d" + % (f1.name, f1.offset, f2.offset)) + + if strict: + l1 = f1.entry_points + l2 = f2.entry_points + l1.sort() + l2.sort() + if l1 != l2: + raise ValueError("%s: entry points %s != %s" + % (f1.name, l1, l2)) + + l1 = f1.static_entry_points + l2 = f2.static_entry_points + l1.sort() + l2.sort() + if l1 != l2: + raise ValueError("%s: static entry points %s != %s" + % (f1.name, l1, l2)) + + pad = 0 + for i in xrange(len(f1.parameters)): + p1 = f1.parameters[i] + p2 = f2.parameters[i + pad] + + if not strict and p1.is_padding != p2.is_padding: + if p1.is_padding: + pad -= 1 + continue + else: + pad += 1 + p2 = f2.parameters[i + pad] + + if strict and p1.name != p2.name: + raise ValueError("%s: parameter %d name %s != %s" + % (f1.name, i, p1.name, p2.name)) + if p1.type_expr.string() != p2.type_expr.string(): + if (strict or + # special case + f1.name == "TexImage2D" and p1.name != "internalformat"): + raise ValueError("%s: parameter %s type %s != %s" + % (f1.name, p1.name, p1.type_expr.string(), + p2.type_expr.string())) + + def union(self, other): + union = gl_XML.gl_api(None) + + if "enum" in self.elts: + union.enums_by_name = other.enums_by_name.copy() + for key, val in self.api.enums_by_name.iteritems(): + if key not in union.enums_by_name: + union.enums_by_name[key] = val + else: + self._check_enum(val, other.enums_by_name[key]) + + if "type" in self.elts: + union.types_by_name = other.types_by_name.copy() + for key, val in self.api.types_by_name.iteritems(): + if key not in union.types_by_name: + union.types_by_name[key] = val + else: + self._check_type(val, other.types_by_name[key]) + + if "function" in self.elts: + union.functions_by_name = other.functions_by_name.copy() + for key, val in self.api.functions_by_name.iteritems(): + if key not in union.functions_by_name: + union.functions_by_name[key] = val + else: + self._check_function(val, other.functions_by_name[key]) + + return union + + def intersection(self, other): + intersection = gl_XML.gl_api(None) + + if "enum" in self.elts: + for key, val in self.api.enums_by_name.iteritems(): + if key in other.enums_by_name: + self._check_enum(val, other.enums_by_name[key]) + intersection.enums_by_name[key] = val + + if "type" in self.elts: + for key, val in self.api.types_by_name.iteritems(): + if key in other.types_by_name: + self._check_type(val, other.types_by_name[key]) + intersection.types_by_name[key] = val + + if "function" in self.elts: + for key, val in self.api.functions_by_name.iteritems(): + if key in other.functions_by_name: + self._check_function(val, other.functions_by_name[key]) + intersection.functions_by_name[key] = val + + return intersection + + def difference(self, other): + difference = gl_XML.gl_api(None) + + if "enum" in self.elts: + for key, val in self.api.enums_by_name.iteritems(): + if key not in other.enums_by_name: + difference.enums_by_name[key] = val + else: + self._check_enum(val, other.enums_by_name[key]) + + if "type" in self.elts: + for key, val in self.api.types_by_name.iteritems(): + if key not in other.types_by_name: + difference.types_by_name[key] = val + else: + self._check_type(val, other.types_by_name[key]) + + if "function" in self.elts: + for key, val in self.api.functions_by_name.iteritems(): + if key not in other.functions_by_name: + difference.functions_by_name[key] = val + else: + self._check_function(val, other.functions_by_name[key], False) + + return difference + +def cmp_enum(e1, e2): + if e1.value < e2.value: + return -1 + elif e1.value > e2.value: + return 1 + else: + return 0 + +def cmp_type(t1, t2): + return t1.size - t2.size + +def cmp_function(f1, f2): + if f1.name > f2.name: + return 1 + elif f1.name < f2.name: + return -1 + else: + return 0 + +def spaces(n, str=""): + spaces = n - len(str) + if spaces < 1: + spaces = 1 + return " " * spaces + +def output_enum(e, indent=0): + attrs = 'name="%s"' % e.name + if e.default_count > 0: + tab = spaces(37, attrs) + attrs += '%scount="%d"' % (tab, e.default_count) + tab = spaces(48, attrs) + val = "%04x" % e.value + val = "0x" + val.upper() + attrs += '%svalue="%s"' % (tab, val) + + # no child + if not e.functions: + print '%s' % (spaces(indent), attrs) + return + + print '%s' % (spaces(indent), attrs) + for key, val in e.functions.iteritems(): + attrs = 'name="%s"' % key + if val[0] != e.default_count: + attrs += ' count="%d"' % val[0] + if not val[1]: + attrs += ' mode="get"' + + print '%s' % (spaces(indent * 2), attrs) + + print '%s' % spaces(indent) + +def output_type(t, indent=0): + tab = spaces(16, t.name) + attrs = 'name="%s"%ssize="%d"' % (t.name, tab, t.size) + ctype = t.type_expr.string() + if ctype.find("unsigned") != -1: + attrs += ' unsigned="true"' + elif ctype.find("signed") == -1: + attrs += ' float="true"' + print '%s' % (spaces(indent), attrs) + +def output_function(f, indent=0): + attrs = 'name="%s"' % f.name + if f.offset > 0: + if f.assign_offset: + attrs += ' offset="assign"' + else: + attrs += ' offset="%d"' % f.offset + print '%s' % (spaces(indent), attrs) + + for p in f.parameters: + attrs = 'name="%s" type="%s"' \ + % (p.name, p.type_expr.original_string) + print '%s' % (spaces(indent * 2), attrs) + if f.return_type != "void": + attrs = 'type="%s"' % f.return_type + print '%s' % (spaces(indent * 2), attrs) + + print '%s' % spaces(indent) + +def output_category(api, indent=0): + enums = api.enums_by_name.values() + enums.sort(cmp_enum) + types = api.types_by_name.values() + types.sort(cmp_type) + functions = api.functions_by_name.values() + functions.sort(cmp_function) + + for e in enums: + output_enum(e, indent) + if enums and types: + print + for t in types: + output_type(t, indent) + if enums or types: + print + for f in functions: + output_function(f, indent) + if f != functions[-1]: + print + +def is_api_empty(api): + return bool(not api.enums_by_name and + not api.types_by_name and + not api.functions_by_name) + +def show_usage(ops): + print "Usage: %s [-k elts] <%s> " % (sys.argv[0], "|".join(ops)) + print " -k elts A comma separated string of types of elements to" + print " skip. Possible types are enum, type, and function." + sys.exit(1) + +def main(): + ops = ["union", "intersection", "difference"] + elts = ["enum", "type", "function"] + + try: + options, args = getopt.getopt(sys.argv[1:], "k:") + except Exception, e: + show_usage(ops) + + if len(args) != 3: + show_usage(ops) + op, file1, file2 = args + if op not in ops: + show_usage(ops) + + skips = [] + for opt, val in options: + if opt == "-k": + skips = val.split(",") + + for elt in skips: + try: + elts.remove(elt) + except ValueError: + show_usage(ops) + + api1 = gl_XML.parse_GL_API(file1, glX_XML.glx_item_factory()) + api2 = gl_XML.parse_GL_API(file2, glX_XML.glx_item_factory()) + + set = ApiSet(api1, elts) + func = getattr(set, op) + result = func(api2) + + if not is_api_empty(result): + cat_name = "%s_of_%s_and_%s" \ + % (op, os.path.basename(file1), os.path.basename(file2)) + + print '' + print '' % GLAPI + print + print '' + print + print '' % (cat_name) + output_category(result, 4) + print '' + print + print '' + +if __name__ == "__main__": + main() diff --git a/src/mapi/glapi/gen-es/gl_parse_header.py b/src/mapi/glapi/gen-es/gl_parse_header.py new file mode 100644 index 0000000..5382eba --- /dev/null +++ b/src/mapi/glapi/gen-es/gl_parse_header.py @@ -0,0 +1,450 @@ +#!/usr/bin/python +# +# Copyright (C) 2009 Chia-I Wu +# +# 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 +# IBM 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. + +import sys +import os.path +import getopt +import re + +GLAPI = "../../glapi/gen" +sys.path.append(GLAPI) + +class HeaderParser(object): + """Parser for GL header files.""" + + def __init__(self, verbose=0): + # match #if and #ifdef + self.IFDEF = re.compile('#\s*if(n?def\s+(?P\w+)|\s+(?P.+))') + # match #endif + self.ENDIF = re.compile('#\s*endif') + # match typedef abc def; + self.TYPEDEF = re.compile('typedef\s+(?P[\w ]+)\s+(?P\w+);') + # match #define XYZ VAL + self.DEFINE = re.compile('#\s*define\s+(?P\w+)(?P\s+[\w"]*)?') + # match GLAPI + self.GLAPI = re.compile('^GL_?API(CALL)?\s+(?P[\w\s*]+[\w*])\s+(GL)?_?APIENTRY\s+(?P\w+)\s*\((?P[\w\s(,*\[\])]+)\)\s*;') + + self.split_params = re.compile('\s*,\s*') + self.split_ctype = re.compile('(\W)') + # ignore GL_VERSION_X_Y + self.ignore_enum = re.compile('GL(_ES)?_VERSION(_ES_C[ML])?_\d_\d') + + self.verbose = verbose + self._reset() + + def _reset(self): + """Reset to initial state.""" + self.ifdef_levels = [] + self.need_char = False + + # use typeexpr? + def _format_ctype(self, ctype, fix=True): + """Format a ctype string, optionally fix it.""" + # split the type string + tmp = self.split_ctype.split(ctype) + tmp = [s for s in tmp if s and s != " "] + + pretty = "" + for i in xrange(len(tmp)): + # add missing GL prefix + if (fix and tmp[i] != "const" and tmp[i] != "*" and + not tmp[i].startswith("GL")): + tmp[i] = "GL" + tmp[i] + + if i == 0: + pretty = tmp[i] + else: + sep = " " + if tmp[i - 1] == "*": + sep = "" + pretty += sep + tmp[i] + return pretty + + # use typeexpr? + def _get_ctype_attrs(self, ctype): + """Get the attributes of a ctype.""" + is_float = (ctype.find("float") != -1 or ctype.find("double") != -1) + is_signed = not (ctype.find("unsigned") != -1) + + size = 0 + if ctype.find("char") != -1: + size = 1 + elif ctype.find("short") != -1: + size = 2 + elif ctype.find("int") != -1: + size = 4 + elif is_float: + if ctype.find("float") != -1: + size = 4 + else: + size = 8 + + return (size, is_float, is_signed) + + def _parse_define(self, line): + """Parse a #define line for an .""" + m = self.DEFINE.search(line) + if not m: + if self.verbose and line.find("#define") >= 0: + print "ignore %s" % (line) + return None + + key = m.group("key").strip() + val = m.group("value").strip() + + # enum must begin with GL_ and be all uppercase + if ((not (key.startswith("GL_") and key.isupper())) or + (self.ignore_enum.match(key) and val == "1")): + if self.verbose: + print "ignore enum %s" % (key) + return None + + return (key, val) + + def _parse_typedef(self, line): + """Parse a typedef line for a .""" + m = self.TYPEDEF.search(line) + if not m: + if self.verbose and line.find("typedef") >= 0: + print "ignore %s" % (line) + return None + + f = m.group("from").strip() + t = m.group("to").strip() + if not t.startswith("GL"): + if self.verbose: + print "ignore type %s" % (t) + return None + attrs = self._get_ctype_attrs(f) + + return (f, t, attrs) + + def _parse_gl_api(self, line): + """Parse a GLAPI line for a .""" + m = self.GLAPI.search(line) + if not m: + if self.verbose and line.find("APIENTRY") >= 0: + print "ignore %s" % (line) + return None + + rettype = m.group("return") + rettype = self._format_ctype(rettype) + if rettype == "GLvoid": + rettype = "" + + name = m.group("name") + + param_str = m.group("params") + chunks = self.split_params.split(param_str) + chunks = [s.strip() for s in chunks] + if len(chunks) == 1 and (chunks[0] == "void" or chunks[0] == "GLvoid"): + chunks = [] + + params = [] + for c in chunks: + # split type and variable name + idx = c.rfind("*") + if idx < 0: + idx = c.rfind(" ") + if idx >= 0: + idx += 1 + ctype = c[:idx] + var = c[idx:] + else: + ctype = c + var = "unnamed" + + # convert array to pointer + idx = var.find("[") + if idx >= 0: + var = var[:idx] + ctype += "*" + + ctype = self._format_ctype(ctype) + var = var.strip() + + if not self.need_char and ctype.find("GLchar") >= 0: + self.need_char = True + + params.append((ctype, var)) + + return (rettype, name, params) + + def _change_level(self, line): + """Parse a #ifdef line and change level.""" + m = self.IFDEF.search(line) + if m: + ifdef = m.group("ifdef") + if not ifdef: + ifdef = m.group("if") + self.ifdef_levels.append(ifdef) + return True + m = self.ENDIF.search(line) + if m: + self.ifdef_levels.pop() + return True + return False + + def _read_header(self, header): + """Open a header file and read its contents.""" + lines = [] + try: + fp = open(header, "rb") + lines = fp.readlines() + fp.close() + except IOError, e: + print "failed to read %s: %s" % (header, e) + return lines + + def _cmp_enum(self, enum1, enum2): + """Compare two enums.""" + # sort by length of the values as strings + val1 = enum1[1] + val2 = enum2[1] + ret = len(val1) - len(val2) + # sort by the values + if not ret: + val1 = int(val1, 16) + val2 = int(val2, 16) + ret = val1 - val2 + # in case int cannot hold the result + if ret > 0: + ret = 1 + elif ret < 0: + ret = -1 + # sort by the names + if not ret: + if enum1[0] < enum2[0]: + ret = -1 + elif enum1[0] > enum2[0]: + ret = 1 + return ret + + def _cmp_type(self, type1, type2): + """Compare two types.""" + attrs1 = type1[2] + attrs2 = type2[2] + # sort by type size + ret = attrs1[0] - attrs2[0] + # float is larger + if not ret: + ret = attrs1[1] - attrs2[1] + # signed is larger + if not ret: + ret = attrs1[2] - attrs2[2] + # reverse + ret = -ret + return ret + + def _cmp_function(self, func1, func2): + """Compare two functions.""" + name1 = func1[1] + name2 = func2[1] + ret = 0 + # sort by the names + if name1 < name2: + ret = -1 + elif name1 > name2: + ret = 1 + return ret + + def _postprocess_dict(self, hdict): + """Post-process a header dict and return an ordered list.""" + hlist = [] + largest = 0 + for key, cat in hdict.iteritems(): + size = len(cat["enums"]) + len(cat["types"]) + len(cat["functions"]) + # ignore empty category + if not size: + continue + + cat["enums"].sort(self._cmp_enum) + # remove duplicates + dup = [] + for i in xrange(1, len(cat["enums"])): + if cat["enums"][i] == cat["enums"][i - 1]: + dup.insert(0, i) + for i in dup: + e = cat["enums"].pop(i) + if self.verbose: + print "remove duplicate enum %s" % e[0] + + cat["types"].sort(self._cmp_type) + cat["functions"].sort(self._cmp_function) + + # largest category comes first + if size > largest: + hlist.insert(0, (key, cat)) + largest = size + else: + hlist.append((key, cat)) + return hlist + + def parse(self, header): + """Parse a header file.""" + self._reset() + + if self.verbose: + print "Parsing %s" % (header) + + hdict = {} + lines = self._read_header(header) + for line in lines: + if self._change_level(line): + continue + + # skip until the first ifdef (i.e. __gl_h_) + if not self.ifdef_levels: + continue + + cat_name = os.path.basename(header) + # check if we are in an extension + if (len(self.ifdef_levels) > 1 and + self.ifdef_levels[-1].startswith("GL_")): + cat_name = self.ifdef_levels[-1] + + try: + cat = hdict[cat_name] + except KeyError: + cat = { + "enums": [], + "types": [], + "functions": [] + } + hdict[cat_name] = cat + + key = "enums" + elem = self._parse_define(line) + if not elem: + key = "types" + elem = self._parse_typedef(line) + if not elem: + key = "functions" + elem = self._parse_gl_api(line) + + if elem: + cat[key].append(elem) + + if self.need_char: + if self.verbose: + print "define GLchar" + elem = self._parse_typedef("typedef char GLchar;") + cat["types"].append(elem) + return self._postprocess_dict(hdict) + +def spaces(n, str=""): + spaces = n - len(str) + if spaces < 1: + spaces = 1 + return " " * spaces + +def output_xml(name, hlist): + """Output a parsed header in OpenGLAPI XML.""" + + for i in xrange(len(hlist)): + cat_name, cat = hlist[i] + + print '' % (cat_name) + indent = 4 + + for enum in cat["enums"]: + name = enum[0][3:] + value = enum[1] + tab = spaces(41, name) + attrs = 'name="%s"%svalue="%s"' % (name, tab, value) + print '%s' % (spaces(indent), attrs) + + if cat["enums"] and cat["types"]: + print + + for type in cat["types"]: + ctype = type[0] + size, is_float, is_signed = type[2] + + attrs = 'name="%s"' % (type[1][2:]) + attrs += spaces(16, attrs) + 'size="%d"' % (size) + if is_float: + attrs += ' float="true"' + elif not is_signed: + attrs += ' unsigned="true"' + + print '%s' % (spaces(indent), attrs) + + for func in cat["functions"]: + print + ret = func[0] + name = func[1][2:] + params = func[2] + + attrs = 'name="%s" offset="assign"' % name + print '%s' % (spaces(indent), attrs) + + for param in params: + attrs = 'name="%s" type="%s"' % (param[1], param[0]) + print '%s' % (spaces(indent * 2), attrs) + if ret: + attrs = 'type="%s"' % ret + print '%s' % (spaces(indent * 2), attrs) + + print '%s' % spaces(indent) + + print '' + print + +def show_usage(): + print "Usage: %s [-v]
    ..." % sys.argv[0] + sys.exit(1) + +def main(): + try: + args, headers = getopt.getopt(sys.argv[1:], "v") + except Exception, e: + show_usage() + if not headers: + show_usage() + + verbose = 0 + for arg in args: + if arg[0] == "-v": + verbose += 1 + + need_xml_header = True + parser = HeaderParser(verbose) + for h in headers: + h = os.path.abspath(h) + hlist = parser.parse(h) + + if need_xml_header: + print '' + print '' % GLAPI + need_xml_header = False + + print + print '' % (h) + print '' + print + output_xml(h, hlist) + print '' + +if __name__ == '__main__': + main() diff --git a/src/mapi/glapi/gen/APPLE_object_purgeable.xml b/src/mapi/glapi/gen/APPLE_object_purgeable.xml new file mode 100644 index 0000000..62fa64a --- /dev/null +++ b/src/mapi/glapi/gen/APPLE_object_purgeable.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/APPLE_vertex_array_object.xml b/src/mapi/glapi/gen/APPLE_vertex_array_object.xml new file mode 100644 index 0000000..bd8427e --- /dev/null +++ b/src/mapi/glapi/gen/APPLE_vertex_array_object.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/ARB_ES2_compatibility.xml b/src/mapi/glapi/gen/ARB_ES2_compatibility.xml new file mode 100644 index 0000000..d52a88c --- /dev/null +++ b/src/mapi/glapi/gen/ARB_ES2_compatibility.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/ARB_copy_buffer.xml b/src/mapi/glapi/gen/ARB_copy_buffer.xml new file mode 100644 index 0000000..719816d --- /dev/null +++ b/src/mapi/glapi/gen/ARB_copy_buffer.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/ARB_depth_clamp.xml b/src/mapi/glapi/gen/ARB_depth_clamp.xml new file mode 100644 index 0000000..157c9a8 --- /dev/null +++ b/src/mapi/glapi/gen/ARB_depth_clamp.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/ARB_draw_elements_base_vertex.xml b/src/mapi/glapi/gen/ARB_draw_elements_base_vertex.xml new file mode 100644 index 0000000..f4067f4 --- /dev/null +++ b/src/mapi/glapi/gen/ARB_draw_elements_base_vertex.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/ARB_draw_instanced.xml b/src/mapi/glapi/gen/ARB_draw_instanced.xml new file mode 100644 index 0000000..57bb776 --- /dev/null +++ b/src/mapi/glapi/gen/ARB_draw_instanced.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/ARB_framebuffer_object.xml b/src/mapi/glapi/gen/ARB_framebuffer_object.xml new file mode 100644 index 0000000..e6bdcd6 --- /dev/null +++ b/src/mapi/glapi/gen/ARB_framebuffer_object.xml @@ -0,0 +1,275 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/ARB_geometry_shader4.xml b/src/mapi/glapi/gen/ARB_geometry_shader4.xml new file mode 100644 index 0000000..ca9a101 --- /dev/null +++ b/src/mapi/glapi/gen/ARB_geometry_shader4.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/ARB_map_buffer_range.xml b/src/mapi/glapi/gen/ARB_map_buffer_range.xml new file mode 100644 index 0000000..afcb9b6 --- /dev/null +++ b/src/mapi/glapi/gen/ARB_map_buffer_range.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/ARB_seamless_cube_map.xml b/src/mapi/glapi/gen/ARB_seamless_cube_map.xml new file mode 100644 index 0000000..8dc827c --- /dev/null +++ b/src/mapi/glapi/gen/ARB_seamless_cube_map.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/ARB_sync.xml b/src/mapi/glapi/gen/ARB_sync.xml new file mode 100644 index 0000000..4e4eeba --- /dev/null +++ b/src/mapi/glapi/gen/ARB_sync.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/ARB_vertex_array_object.xml b/src/mapi/glapi/gen/ARB_vertex_array_object.xml new file mode 100644 index 0000000..3b4ab64 --- /dev/null +++ b/src/mapi/glapi/gen/ARB_vertex_array_object.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/EXT_draw_buffers2.xml b/src/mapi/glapi/gen/EXT_draw_buffers2.xml new file mode 100644 index 0000000..efbe61f --- /dev/null +++ b/src/mapi/glapi/gen/EXT_draw_buffers2.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/EXT_framebuffer_object.xml b/src/mapi/glapi/gen/EXT_framebuffer_object.xml new file mode 100644 index 0000000..4f418f7 --- /dev/null +++ b/src/mapi/glapi/gen/EXT_framebuffer_object.xml @@ -0,0 +1,235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/EXT_gpu_shader4.xml b/src/mapi/glapi/gen/EXT_gpu_shader4.xml new file mode 100644 index 0000000..7a8944e --- /dev/null +++ b/src/mapi/glapi/gen/EXT_gpu_shader4.xml @@ -0,0 +1,244 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/EXT_packed_depth_stencil.xml b/src/mapi/glapi/gen/EXT_packed_depth_stencil.xml new file mode 100644 index 0000000..5be8103 --- /dev/null +++ b/src/mapi/glapi/gen/EXT_packed_depth_stencil.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/EXT_provoking_vertex.xml b/src/mapi/glapi/gen/EXT_provoking_vertex.xml new file mode 100644 index 0000000..71d2c72 --- /dev/null +++ b/src/mapi/glapi/gen/EXT_provoking_vertex.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/EXT_separate_shader_objects.xml b/src/mapi/glapi/gen/EXT_separate_shader_objects.xml new file mode 100644 index 0000000..6ec5615 --- /dev/null +++ b/src/mapi/glapi/gen/EXT_separate_shader_objects.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/EXT_texture_array.xml b/src/mapi/glapi/gen/EXT_texture_array.xml new file mode 100644 index 0000000..b5b8bd4 --- /dev/null +++ b/src/mapi/glapi/gen/EXT_texture_array.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/EXT_texture_integer.xml b/src/mapi/glapi/gen/EXT_texture_integer.xml new file mode 100644 index 0000000..7e5a8cb --- /dev/null +++ b/src/mapi/glapi/gen/EXT_texture_integer.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/EXT_transform_feedback.xml b/src/mapi/glapi/gen/EXT_transform_feedback.xml new file mode 100644 index 0000000..051f1e0 --- /dev/null +++ b/src/mapi/glapi/gen/EXT_transform_feedback.xml @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/GL3x.xml b/src/mapi/glapi/gen/GL3x.xml new file mode 100644 index 0000000..8d15c94 --- /dev/null +++ b/src/mapi/glapi/gen/GL3x.xml @@ -0,0 +1,589 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/Makefile b/src/mapi/glapi/gen/Makefile new file mode 100644 index 0000000..c08be38 --- /dev/null +++ b/src/mapi/glapi/gen/Makefile @@ -0,0 +1,211 @@ +# This file isn't used during a normal compilation since we don't want to +# require Python in order to compile Mesa. +# Instead, when the Mesa developers update/change the API interface it's +# up to him/her to re-run this makefile and check in the newly generated files. + + +TOP = ../../../.. +include $(TOP)/configs/current + +MESA_DIR = $(TOP)/src/mesa +MESA_GLAPI_DIR = $(TOP)/src/mapi/glapi +MESA_GLX_DIR = $(TOP)/src/glx + +MESA_GLAPI_OUTPUTS = \ + $(MESA_GLAPI_DIR)/glprocs.h \ + $(MESA_GLAPI_DIR)/glapitemp.h \ + $(MESA_GLAPI_DIR)/glapitable.h + +MESA_GLAPI_ASM_OUTPUTS = \ + $(MESA_GLAPI_DIR)/glapi_x86.S \ + $(MESA_GLAPI_DIR)/glapi_x86-64.S \ + $(MESA_GLAPI_DIR)/glapi_sparc.S + +MESA_OUTPUTS = \ + $(MESA_GLAPI_OUTPUTS) \ + $(MESA_GLAPI_ASM_OUTPUTS) \ + $(MESA_DIR)/main/enums.c \ + $(MESA_DIR)/main/glapidispatch.h \ + $(MESA_DIR)/main/remap_helper.h \ + $(MESA_GLX_DIR)/indirect.c \ + $(MESA_GLX_DIR)/indirect.h \ + $(MESA_GLX_DIR)/indirect_init.c \ + $(MESA_GLX_DIR)/indirect_size.h \ + $(MESA_GLX_DIR)/indirect_size.c + +###################################################################### + +XORG_GLX_DIR = $(XORG_BASE)/glx +XORG_GLAPI_DIR = $(XORG_BASE)/glx + +XORG_GLAPI_FILES = \ + $(XORG_GLAPI_DIR)/glapi.h \ + $(XORG_GLAPI_DIR)/glapi.c \ + $(XORG_GLAPI_DIR)/glapi_getproc.c \ + $(XORG_GLAPI_DIR)/glapi_nop.c \ + $(XORG_GLAPI_DIR)/glthread.c \ + $(XORG_GLAPI_DIR)/glthread.h + +XORG_GLAPI_OUTPUTS = \ + $(XORG_GLAPI_DIR)/glprocs.h \ + $(XORG_GLAPI_DIR)/glapitemp.h \ + $(XORG_GLAPI_DIR)/glapioffsets.h \ + $(XORG_GLAPI_DIR)/glapitable.h \ + $(XORG_GLAPI_DIR)/glapidispatch.h + +XORG_OUTPUTS = \ + $(XORG_GLAPI_FILES) \ + $(XORG_GLAPI_OUTPUTS) \ + $(XORG_GLX_DIR)/indirect_dispatch.c \ + $(XORG_GLX_DIR)/indirect_dispatch_swap.c \ + $(XORG_GLX_DIR)/indirect_dispatch.h \ + $(XORG_GLX_DIR)/indirect_reqsize.c \ + $(XORG_GLX_DIR)/indirect_reqsize.h \ + $(XORG_GLX_DIR)/indirect_size.h \ + $(XORG_GLX_DIR)/indirect_size_get.c \ + $(XORG_GLX_DIR)/indirect_size_get.h \ + $(XORG_GLX_DIR)/indirect_table.c + +###################################################################### + +API_XML = \ + gl_API.xml \ + ARB_copy_buffer.xml \ + ARB_depth_clamp.xml \ + ARB_draw_elements_base_vertex.xml \ + ARB_draw_instanced.xml \ + ARB_ES2_compatibility.xml \ + ARB_framebuffer_object.xml \ + ARB_geometry_shader4.xml \ + ARB_map_buffer_range.xml \ + ARB_seamless_cube_map.xml \ + ARB_sync.xml \ + ARB_vertex_array_object.xml \ + APPLE_object_purgeable.xml \ + APPLE_vertex_array_object.xml \ + EXT_draw_buffers2.xml \ + EXT_framebuffer_object.xml \ + EXT_gpu_shader4.xml \ + EXT_packed_depth_stencil.xml \ + EXT_provoking_vertex.xml \ + EXT_separate_shader_objects.xml \ + EXT_texture_array.xml \ + EXT_texture_integer.xml \ + EXT_transform_feedback.xml \ + NV_conditional_render.xml \ + NV_primitive_restart.xml \ + OES_EGL_image.xml \ + GL3x.xml + + +COMMON = $(API_XML) gl_XML.py glX_XML.py license.py typeexpr.py + +COMMON_GLX = $(COMMON) glX_API.xml glX_XML.py glX_proto_common.py + +###################################################################### + +all: mesa xorg + +mesa: $(MESA_OUTPUTS) + +xorg: check-xorg-source $(XORG_OUTPUTS) + +check-xorg-source: + @if ! test -d $(XORG_GLX_DIR); then \ + echo "ERROR: Must specify path to xserver/GL/ checkout; set XORG_BASE env var."; \ + exit 1; \ + fi + +clean: + -rm -f *~ *.pyo + -rm -f $(MESA_OUTPUTS) + +###################################################################### + +$(XORG_GLAPI_DIR)/%.c: $(MESA_GLAPI_DIR)/%.c + cp $< $@ + +$(XORG_GLAPI_DIR)/%.h: $(MESA_GLAPI_DIR)/%.h + cp $< $@ + +###################################################################### + +$(MESA_GLAPI_DIR)/glprocs.h: gl_procs.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< > $@ + +$(MESA_GLAPI_DIR)/glapitemp.h: gl_apitemp.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< > $@ + +$(MESA_GLAPI_DIR)/glapitable.h: gl_table.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< > $@ + +###################################################################### + +$(MESA_GLAPI_DIR)/glapi_x86.S: gl_x86_asm.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< > $@ + +$(MESA_GLAPI_DIR)/glapi_x86-64.S: gl_x86-64_asm.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< > $@ + +$(MESA_GLAPI_DIR)/glapi_sparc.S: gl_SPARC_asm.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< > $@ + +###################################################################### + +$(MESA_DIR)/main/enums.c: gl_enums.py $(COMMON) $(ES_API) + $(PYTHON2) $(PYTHON_FLAGS) $< -f gl_API.xml \ + -f $(MESA_GLAPI_DIR)/gen-es/es1_API.xml \ + -f $(MESA_GLAPI_DIR)/gen-es/es2_API.xml > $@ + +$(MESA_DIR)/main/glapidispatch.h: gl_table.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< -m remap_table > $@ + +$(MESA_DIR)/main/remap_helper.h: remap_helper.py $(COMMON) + $(PYTHON2) $(PYTHON_FLAGS) $< > $@ + +###################################################################### + +$(MESA_GLX_DIR)/indirect.c: glX_proto_send.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m proto | $(INDENT) $(INDENT_FLAGS) > $@ + +$(MESA_GLX_DIR)/indirect.h: glX_proto_send.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m init_h > $@ + +$(MESA_GLX_DIR)/indirect_init.c: glX_proto_send.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m init_c > $@ + +$(MESA_GLX_DIR)/indirect_size.h $(XORG_GLX_DIR)/indirect_size.h: glX_proto_size.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m size_h --only-set -h _INDIRECT_SIZE_H_ \ + | $(INDENT) $(INDENT_FLAGS) > $@ + +$(MESA_GLX_DIR)/indirect_size.c: glX_proto_size.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m size_c --only-set \ + | $(INDENT) $(INDENT_FLAGS) > $@ + +###################################################################### + +$(XORG_GLX_DIR)/indirect_dispatch.c: glX_proto_recv.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m dispatch_c > $@ + +$(XORG_GLX_DIR)/indirect_dispatch_swap.c: glX_proto_recv.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m dispatch_c -s > $@ + +$(XORG_GLX_DIR)/indirect_dispatch.h: glX_proto_recv.py gl_and_glX_API.xml $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m dispatch_h -f gl_and_glX_API.xml -s > $@ + +$(XORG_GLX_DIR)/indirect_size_get.h: glX_proto_size.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m size_h --only-get -h '_INDIRECT_SIZE_GET_H_' \ + | $(INDENT) $(INDENT_FLAGS) > $@ + +$(XORG_GLX_DIR)/indirect_size_get.c: glX_proto_size.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m size_c | $(INDENT) $(INDENT_FLAGS) > $@ + +$(XORG_GLX_DIR)/indirect_reqsize.h: glX_proto_size.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m reqsize_h --only-get -h '_INDIRECT_SIZE_GET_H_' \ + | $(INDENT) $(INDENT_FLAGS) -l200 > $@ + +$(XORG_GLX_DIR)/indirect_reqsize.c: glX_proto_size.py $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -m reqsize_c | $(INDENT) $(INDENT_FLAGS) > $@ + +$(XORG_GLX_DIR)/indirect_table.c: glX_server_table.py gl_and_glX_API.xml $(COMMON_GLX) + $(PYTHON2) $(PYTHON_FLAGS) $< -f gl_and_glX_API.xml > $@ diff --git a/src/mapi/glapi/gen/NV_conditional_render.xml b/src/mapi/glapi/gen/NV_conditional_render.xml new file mode 100644 index 0000000..8bb31dd --- /dev/null +++ b/src/mapi/glapi/gen/NV_conditional_render.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/NV_primitive_restart.xml b/src/mapi/glapi/gen/NV_primitive_restart.xml new file mode 100644 index 0000000..abe7dda --- /dev/null +++ b/src/mapi/glapi/gen/NV_primitive_restart.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/OES_EGL_image.xml b/src/mapi/glapi/gen/OES_EGL_image.xml new file mode 100644 index 0000000..1cb43d4 --- /dev/null +++ b/src/mapi/glapi/gen/OES_EGL_image.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/extension_helper.py b/src/mapi/glapi/gen/extension_helper.py new file mode 100644 index 0000000..2c83b4e --- /dev/null +++ b/src/mapi/glapi/gen/extension_helper.py @@ -0,0 +1,324 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import gl_XML +import license +import sys, getopt, string + +vtxfmt = [ + "ArrayElement", \ + "Color3f", \ + "Color3fv", \ + "Color4f", \ + "Color4fv", \ + "EdgeFlag", \ + "EdgeFlagv", \ + "EvalCoord1f", \ + "EvalCoord1fv", \ + "EvalCoord2f", \ + "EvalCoord2fv", \ + "EvalPoint1", \ + "EvalPoint2", \ + "FogCoordfEXT", \ + "FogCoordfvEXT", \ + "Indexf", \ + "Indexfv", \ + "Materialfv", \ + "MultiTexCoord1fARB", \ + "MultiTexCoord1fvARB", \ + "MultiTexCoord2fARB", \ + "MultiTexCoord2fvARB", \ + "MultiTexCoord3fARB", \ + "MultiTexCoord3fvARB", \ + "MultiTexCoord4fARB", \ + "MultiTexCoord4fvARB", \ + "Normal3f", \ + "Normal3fv", \ + "SecondaryColor3fEXT", \ + "SecondaryColor3fvEXT", \ + "TexCoord1f", \ + "TexCoord1fv", \ + "TexCoord2f", \ + "TexCoord2fv", \ + "TexCoord3f", \ + "TexCoord3fv", \ + "TexCoord4f", \ + "TexCoord4fv", \ + "Vertex2f", \ + "Vertex2fv", \ + "Vertex3f", \ + "Vertex3fv", \ + "Vertex4f", \ + "Vertex4fv", \ + "CallList", \ + "CallLists", \ + "Begin", \ + "End", \ + "VertexAttrib1fNV", \ + "VertexAttrib1fvNV", \ + "VertexAttrib2fNV", \ + "VertexAttrib2fvNV", \ + "VertexAttrib3fNV", \ + "VertexAttrib3fvNV", \ + "VertexAttrib4fNV", \ + "VertexAttrib4fvNV", \ + "VertexAttrib1fARB", \ + "VertexAttrib1fvARB", \ + "VertexAttrib2fARB", \ + "VertexAttrib2fvARB", \ + "VertexAttrib3fARB", \ + "VertexAttrib3fvARB", \ + "VertexAttrib4fARB", \ + "VertexAttrib4fvARB", \ + "Rectf", \ + "DrawArrays", \ + "DrawElements", \ + "DrawRangeElements", \ + "EvalMesh1", \ + "EvalMesh2", \ +] + +def all_entrypoints_in_abi(f, abi, api): + for n in f.entry_points: + [category, num] = api.get_category_for_name( n ) + if category not in abi: + return 0 + + return 1 + + +def any_entrypoints_in_abi(f, abi, api): + for n in f.entry_points: + [category, num] = api.get_category_for_name( n ) + if category in abi: + return 1 + + return 0 + + +def condition_for_function(f, abi, all_not_in_ABI): + """Create a C-preprocessor condition for the function. + + There are two modes of operation. If all_not_in_ABI is set, a + condition is only created is all of the entry-point names for f are + not in the selected ABI. If all_not_in_ABI is not set, a condition + is created if any entryp-point name is not in the selected ABI. + """ + + condition = [] + for n in f.entry_points: + [category, num] = api.get_category_for_name( n ) + if category not in abi: + condition.append( 'defined(need_%s)' % (gl_XML.real_category_name( category )) ) + elif all_not_in_ABI: + return [] + + return condition + + +class PrintGlExtensionGlue(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "extension_helper.py (from Mesa)" + self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM") + return + + + def printRealHeader(self): + print '#include "utils.h"' + print '#include "main/dispatch.h"' + print '' + return + + + def printBody(self, api): + abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ] + + category_list = {} + + print '#ifndef NULL' + print '# define NULL 0' + print '#endif' + print '' + + for f in api.functionIterateAll(): + condition = condition_for_function(f, abi, 0) + if len(condition): + print '#if %s' % (string.join(condition, " || ")) + print 'static const char %s_names[] =' % (f.name) + + parameter_signature = '' + for p in f.parameterIterator(): + if p.is_padding: + continue + + # FIXME: This is a *really* ugly hack. :( + + tn = p.type_expr.get_base_type_node() + if p.is_pointer(): + parameter_signature += 'p' + elif tn.integer: + parameter_signature += 'i' + elif tn.size == 4: + parameter_signature += 'f' + else: + parameter_signature += 'd' + + print ' "%s\\0" /* Parameter signature */' % (parameter_signature) + + for n in f.entry_points: + print ' "gl%s\\0"' % (n) + + [category, num] = api.get_category_for_name( n ) + if category not in abi: + c = gl_XML.real_category_name(category) + if not category_list.has_key(c): + category_list[ c ] = [] + + category_list[ c ].append( f ) + + print ' "";' + print '#endif' + print '' + + keys = category_list.keys() + keys.sort() + + for category in keys: + print '#if defined(need_%s)' % (category) + print 'static const struct dri_extension_function %s_functions[] = {' % (category) + + for f in category_list[ category ]: + # A function either has an offset that is + # assigned by the ABI, or it has a remap + # index. + if any_entrypoints_in_abi(f, abi, api): + index_name = "-1" + offset = f.offset + else: + index_name = "%s_remap_index" % (f.name) + offset = -1 + + print ' { %s_names, %s, %d },' % (f.name, index_name, offset) + + + print ' { NULL, 0, 0 }' + print '};' + print '#endif' + print '' + + return + + +class PrintInitDispatch(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "extension_helper.py (from Mesa)" + self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM") + return + + + def do_function_body(self, api, abi, vtxfmt_only): + last_condition_string = None + for f in api.functionIterateByOffset(): + if (f.name in vtxfmt) and not vtxfmt_only: + continue + + if (f.name not in vtxfmt) and vtxfmt_only: + continue + + condition = condition_for_function(f, abi, 1) + condition_string = string.join(condition, " || ") + + if condition_string != last_condition_string: + if last_condition_string: + print '#endif /* %s */' % (last_condition_string) + + if condition_string: + print '#if %s' % (condition_string) + + if vtxfmt_only: + print ' disp->%s = vfmt->%s;' % (f.name, f.name) + else: + print ' disp->%s = _mesa_%s;' % (f.name, f.name) + + last_condition_string = condition_string + + if last_condition_string: + print '#endif /* %s */' % (last_condition_string) + + + + def printBody(self, api): + abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ] + + print 'void driver_init_exec_table(struct _glapi_table *disp)' + print '{' + self.do_function_body(api, abi, 0) + print '}' + print '' + print 'void driver_install_vtxfmt(struct _glapi_table *disp, const GLvertexformat *vfmt)' + print '{' + self.do_function_body(api, abi, 1) + print '}' + + return + + +def show_usage(): + print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0] + print " -m output_mode Output mode can be one of 'extensions' or 'exec_init'." + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:m:") + except Exception,e: + show_usage() + + mode = "extensions" + for (arg,val) in args: + if arg == "-f": + file_name = val + if arg == '-m': + mode = val + + + api = gl_XML.parse_GL_API( file_name ) + + if mode == "extensions": + printer = PrintGlExtensionGlue() + elif mode == "exec_init": + printer = PrintInitDispatch() + else: + show_usage() + + printer.Print( api ) diff --git a/src/mapi/glapi/gen/glX_API.xml b/src/mapi/glapi/gen/glX_API.xml new file mode 100644 index 0000000..9e02aa4 --- /dev/null +++ b/src/mapi/glapi/gen/glX_API.xml @@ -0,0 +1,220 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/glX_XML.py b/src/mapi/glapi/gen/glX_XML.py new file mode 100644 index 0000000..4c2e0f9 --- /dev/null +++ b/src/mapi/glapi/gen/glX_XML.py @@ -0,0 +1,570 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import gl_XML +import license +import sys, getopt, string + + +class glx_item_factory(gl_XML.gl_item_factory): + """Factory to create GLX protocol oriented objects derived from gl_item.""" + + def create_item(self, name, element, context): + if name == "function": + return glx_function(element, context) + elif name == "enum": + return glx_enum(element, context) + elif name == "api": + return glx_api(self) + else: + return gl_XML.gl_item_factory.create_item(self, name, element, context) + + +class glx_enum(gl_XML.gl_enum): + def __init__(self, element, context): + gl_XML.gl_enum.__init__(self, element, context) + + self.functions = {} + + child = element.children + while child: + if child.type == "element" and child.name == "size": + n = child.nsProp( "name", None ) + c = child.nsProp( "count", None ) + m = child.nsProp( "mode", None ) + + if not c: + c = self.default_count + else: + c = int(c) + + if m == "get": + mode = 0 + else: + mode = 1 + + if not self.functions.has_key(n): + self.functions[ n ] = [c, mode] + + child = child.next + + return + + +class glx_function(gl_XML.gl_function): + def __init__(self, element, context): + self.glx_rop = 0 + self.glx_sop = 0 + self.glx_vendorpriv = 0 + + self.glx_vendorpriv_names = [] + + # If this is set to true, it means that GLdouble parameters should be + # written to the GLX protocol packet in the order they appear in the + # prototype. This is different from the "classic" ordering. In the + # classic ordering GLdoubles are written to the protocol packet first, + # followed by non-doubles. NV_vertex_program was the first extension + # to break with this tradition. + + self.glx_doubles_in_order = 0 + + self.vectorequiv = None + self.output = None + self.can_be_large = 0 + self.reply_always_array = 0 + self.dimensions_in_reply = 0 + self.img_reset = None + + self.server_handcode = 0 + self.client_handcode = 0 + self.ignore = 0 + + self.count_parameter_list = [] + self.counter_list = [] + self.parameters_by_name = {} + self.offsets_calculated = 0 + + gl_XML.gl_function.__init__(self, element, context) + return + + + def process_element(self, element): + gl_XML.gl_function.process_element(self, element) + + # If the function already has a vector equivalent set, don't + # set it again. This can happen if an alias to a function + # appears after the function that it aliases. + + if not self.vectorequiv: + self.vectorequiv = element.nsProp("vectorequiv", None) + + + name = element.nsProp("name", None) + if name == self.name: + for param in self.parameters: + self.parameters_by_name[ param.name ] = param + + if len(param.count_parameter_list): + self.count_parameter_list.extend( param.count_parameter_list ) + + if param.counter and param.counter not in self.counter_list: + self.counter_list.append(param.counter) + + + child = element.children + while child: + if child.type == "element" and child.name == "glx": + rop = child.nsProp( 'rop', None ) + sop = child.nsProp( 'sop', None ) + vop = child.nsProp( 'vendorpriv', None ) + + if rop: + self.glx_rop = int(rop) + + if sop: + self.glx_sop = int(sop) + + if vop: + self.glx_vendorpriv = int(vop) + self.glx_vendorpriv_names.append(name) + + self.img_reset = child.nsProp( 'img_reset', None ) + + # The 'handcode' attribute can be one of 'true', + # 'false', 'client', or 'server'. + + handcode = child.nsProp( 'handcode', None ) + if handcode == "false": + self.server_handcode = 0 + self.client_handcode = 0 + elif handcode == "true": + self.server_handcode = 1 + self.client_handcode = 1 + elif handcode == "client": + self.server_handcode = 0 + self.client_handcode = 1 + elif handcode == "server": + self.server_handcode = 1 + self.client_handcode = 0 + else: + raise RuntimeError('Invalid handcode mode "%s" in function "%s".' % (handcode, self.name)) + + self.ignore = gl_XML.is_attr_true( child, 'ignore' ) + self.can_be_large = gl_XML.is_attr_true( child, 'large' ) + self.glx_doubles_in_order = gl_XML.is_attr_true( child, 'doubles_in_order' ) + self.reply_always_array = gl_XML.is_attr_true( child, 'always_array' ) + self.dimensions_in_reply = gl_XML.is_attr_true( child, 'dimensions_in_reply' ) + + child = child.next + + + # Do some validation of the GLX protocol information. As + # new tests are discovered, they should be added here. + + for param in self.parameters: + if param.is_output and self.glx_rop != 0: + raise RuntimeError("Render / RenderLarge commands cannot have outputs (%s)." % (self.name)) + + return + + + def has_variable_size_request(self): + """Determine if the GLX request packet is variable sized. + + The GLX request packet is variable sized in several common + situations. + + 1. The function has a non-output parameter that is counted + by another parameter (e.g., the 'textures' parameter of + glDeleteTextures). + + 2. The function has a non-output parameter whose count is + determined by another parameter that is an enum (e.g., the + 'params' parameter of glLightfv). + + 3. The function has a non-output parameter that is an + image. + + 4. The function must be hand-coded on the server. + """ + + if self.glx_rop == 0: + return 0 + + if self.server_handcode or self.images: + return 1 + + for param in self.parameters: + if not param.is_output: + if param.counter or len(param.count_parameter_list): + return 1 + + return 0 + + + def variable_length_parameter(self): + for param in self.parameters: + if not param.is_output: + if param.counter or len(param.count_parameter_list): + return param + + return None + + + def calculate_offsets(self): + if not self.offsets_calculated: + # Calculate the offset of the first function parameter + # in the GLX command packet. This byte offset is + # measured from the end of the Render / RenderLarge + # header. The offset for all non-pixel commends is + # zero. The offset for pixel commands depends on the + # number of dimensions of the pixel data. + + if len(self.images) and not self.images[0].is_output: + [dim, junk, junk, junk, junk] = self.images[0].get_dimensions() + + # The base size is the size of the pixel pack info + # header used by images with the specified number + # of dimensions. + + if dim <= 2: + offset = 20 + elif dim <= 4: + offset = 36 + else: + raise RuntimeError('Invalid number of dimensions %u for parameter "%s" in function "%s".' % (dim, self.image.name, self.name)) + else: + offset = 0 + + for param in self.parameterIterateGlxSend(): + if param.img_null_flag: + offset += 4 + + if param.name != self.img_reset: + param.offset = offset + if not param.is_variable_length() and not param.is_client_only: + offset += param.size() + + if self.pad_after( param ): + offset += 4 + + + self.offsets_calculated = 1 + return + + + def offset_of(self, param_name): + self.calculate_offsets() + return self.parameters_by_name[ param_name ].offset + + + def parameterIterateGlxSend(self, include_variable_parameters = 1): + """Create an iterator for parameters in GLX request order.""" + + # The parameter lists are usually quite short, so it's easier + # (i.e., less code) to just generate a new list with the + # required elements than it is to create a new iterator class. + + temp = [ [], [], [] ] + for param in self.parameters: + if param.is_output: continue + + if param.is_variable_length(): + temp[2].append( param ) + elif not self.glx_doubles_in_order and param.is_64_bit(): + temp[0].append( param ) + else: + temp[1].append( param ) + + parameters = temp[0] + parameters.extend( temp[1] ) + if include_variable_parameters: + parameters.extend( temp[2] ) + return parameters.__iter__() + + + def parameterIterateCounters(self): + temp = [] + for name in self.counter_list: + temp.append( self.parameters_by_name[ name ] ) + + return temp.__iter__() + + + def parameterIterateOutputs(self): + temp = [] + for p in self.parameters: + if p.is_output: + temp.append( p ) + + return temp + + + def command_fixed_length(self): + """Return the length, in bytes as an integer, of the + fixed-size portion of the command.""" + + if len(self.parameters) == 0: + return 0 + + self.calculate_offsets() + + size = 0 + for param in self.parameterIterateGlxSend(0): + if param.name != self.img_reset and not param.is_client_only: + if size == 0: + size = param.offset + param.size() + else: + size += param.size() + + if self.pad_after( param ): + size += 4 + + for param in self.images: + if param.img_null_flag or param.is_output: + size += 4 + + return size + + + def command_variable_length(self): + """Return the length, as a string, of the variable-sized + portion of the command.""" + + size_string = "" + for p in self.parameterIterateGlxSend(): + if (not p.is_output) and (p.is_variable_length() or p.is_image()): + # FIXME Replace the 1 in the size_string call + # FIXME w/0 to eliminate some un-needed parnes + # FIXME This would already be done, but it + # FIXME adds some extra diffs to the generated + # FIXME code. + + size_string = size_string + " + __GLX_PAD(%s)" % (p.size_string(1)) + + return size_string + + + def command_length(self): + size = self.command_fixed_length() + + if self.glx_rop != 0: + size += 4 + + size = ((size + 3) & ~3) + return "%u%s" % (size, self.command_variable_length()) + + + def opcode_real_value(self): + """Get the true numeric value of the GLX opcode + + Behaves similarly to opcode_value, except for + X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands. + In these cases the value for the GLX opcode field (i.e., + 16 for X_GLXVendorPrivate or 17 for + X_GLXVendorPrivateWithReply) is returned. For other 'single' + commands, the opcode for the command (e.g., 101 for + X_GLsop_NewList) is returned.""" + + if self.glx_vendorpriv != 0: + if self.needs_reply(): + return 17 + else: + return 16 + else: + return self.opcode_value() + + + def opcode_value(self): + """Get the unique protocol opcode for the glXFunction""" + + if (self.glx_rop == 0) and self.vectorequiv: + equiv = self.context.functions_by_name[ self.vectorequiv ] + self.glx_rop = equiv.glx_rop + + + if self.glx_rop != 0: + return self.glx_rop + elif self.glx_sop != 0: + return self.glx_sop + elif self.glx_vendorpriv != 0: + return self.glx_vendorpriv + else: + return -1 + + + def opcode_rop_basename(self): + """Return either the name to be used for GLX protocol enum. + + Returns either the name of the function or the name of the + name of the equivalent vector (e.g., glVertex3fv for + glVertex3f) function.""" + + if self.vectorequiv == None: + return self.name + else: + return self.vectorequiv + + + def opcode_name(self): + """Get the unique protocol enum name for the glXFunction""" + + if (self.glx_rop == 0) and self.vectorequiv: + equiv = self.context.functions_by_name[ self.vectorequiv ] + self.glx_rop = equiv.glx_rop + self.glx_doubles_in_order = equiv.glx_doubles_in_order + + + if self.glx_rop != 0: + return "X_GLrop_%s" % (self.opcode_rop_basename()) + elif self.glx_sop != 0: + return "X_GLsop_%s" % (self.name) + elif self.glx_vendorpriv != 0: + return "X_GLvop_%s" % (self.name) + else: + raise RuntimeError('Function "%s" has no opcode.' % (self.name)) + + + def opcode_vendor_name(self, name): + if name in self.glx_vendorpriv_names: + return "X_GLvop_%s" % (name) + else: + raise RuntimeError('Function "%s" has no VendorPrivate opcode.' % (name)) + + + def opcode_real_name(self): + """Get the true protocol enum name for the GLX opcode + + Behaves similarly to opcode_name, except for + X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands. + In these cases the string 'X_GLXVendorPrivate' or + 'X_GLXVendorPrivateWithReply' is returned. For other + single or render commands 'X_GLsop' or 'X_GLrop' plus the + name of the function returned.""" + + if self.glx_vendorpriv != 0: + if self.needs_reply(): + return "X_GLXVendorPrivateWithReply" + else: + return "X_GLXVendorPrivate" + else: + return self.opcode_name() + + + def needs_reply(self): + try: + x = self._needs_reply + except Exception, e: + x = 0 + if self.return_type != 'void': + x = 1 + + for param in self.parameters: + if param.is_output: + x = 1 + break + + self._needs_reply = x + + return x + + + def pad_after(self, p): + """Returns the name of the field inserted after the + specified field to pad out the command header.""" + + for image in self.images: + if image.img_pad_dimensions: + if not image.height: + if p.name == image.width: + return "height" + elif p.name == image.img_xoff: + return "yoffset" + elif not image.extent: + if p.name == image.depth: + # Should this be "size4d"? + return "extent" + elif p.name == image.img_zoff: + return "woffset" + + return None + + + def has_different_protocol(self, name): + """Returns true if the named version of the function uses different protocol from the other versions. + + Some functions, such as glDeleteTextures and + glDeleteTexturesEXT are functionally identical, but have + different protocol. This function returns true if the + named function is an alias name and that named version uses + different protocol from the function that is aliased. + """ + + return (name in self.glx_vendorpriv_names) and self.glx_sop + + + def static_glx_name(self, name): + if self.has_different_protocol(name): + for n in self.glx_vendorpriv_names: + if n in self.static_entry_points: + return n + + return self.static_name(name) + + + def client_supported_for_indirect(self): + """Returns true if the function is supported on the client + side for indirect rendering.""" + + return not self.ignore and (self.offset != -1) and (self.glx_rop or self.glx_sop or self.glx_vendorpriv or self.vectorequiv or self.client_handcode) + + +class glx_function_iterator: + """Class to iterate over a list of glXFunctions""" + + def __init__(self, context): + self.iterator = context.functionIterateByOffset() + return + + + def __iter__(self): + return self + + + def next(self): + f = self.iterator.next() + + if f.client_supported_for_indirect(): + return f + else: + return self.next() + + +class glx_api(gl_XML.gl_api): + def functionIterateGlx(self): + return glx_function_iterator(self) + diff --git a/src/mapi/glapi/gen/glX_doc.py b/src/mapi/glapi/gen/glX_doc.py new file mode 100644 index 0000000..e9fbbe6 --- /dev/null +++ b/src/mapi/glapi/gen/glX_doc.py @@ -0,0 +1,280 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import gl_XML, glX_XML, glX_proto_common, license +import sys, getopt + + +class glx_doc_item_factory(glX_proto_common.glx_proto_item_factory): + """Factory to create GLX protocol documentation oriented objects derived from glItem.""" + + def create_item(self, name, element, context): + if name == "parameter": + return glx_doc_parameter(element, context) + else: + return glX_proto_common.glx_proto_item_factory.create_item(self, name, element, context) + + +class glx_doc_parameter(gl_XML.gl_parameter): + def packet_type(self, type_dict): + """Get the type string for the packet header + + GLX protocol documentation uses type names like CARD32, + FLOAT64, LISTofCARD8, and ENUM. This function converts the + type of the parameter to one of these names.""" + + list_of = "" + if self.is_array(): + list_of = "LISTof" + + t_name = self.get_base_type_string() + if not type_dict.has_key( t_name ): + type_name = "CARD8" + else: + type_name = type_dict[ t_name ] + + return "%s%s" % (list_of, type_name) + + + def packet_size(self): + p = None + s = self.size() + if s == 0: + a_prod = "n" + b_prod = self.p_type.size + + if not self.count_parameter_list and self.counter: + a_prod = self.counter + elif self.count_parameter_list and not self.counter or self.is_output: + pass + elif self.count_parameter_list and self.counter: + b_prod = self.counter + else: + raise RuntimeError("Parameter '%s' to function '%s' has size 0." % (self.name, self.context.name)) + + ss = "%s*%s" % (a_prod, b_prod) + + return [ss, p] + else: + if s % 4 != 0: + p = "p" + + return [str(s), p] + +class PrintGlxProtoText(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + self.license = "" + + + def printHeader(self): + return + + + def body_size(self, f): + # At some point, refactor this function and + # glXFunction::command_payload_length. + + size = 0; + size_str = "" + pad_str = "" + plus = "" + for p in f.parameterIterateGlxSend(): + [s, pad] = p.packet_size() + try: + size += int(s) + except Exception,e: + size_str += "%s%s" % (plus, s) + plus = "+" + + if pad != None: + pad_str = pad + + return [size, size_str, pad_str] + + + def print_render_header(self, f): + [size, size_str, pad_str] = self.body_size(f) + size += 4; + + if size_str == "": + s = "%u" % ((size + 3) & ~3) + elif pad_str != "": + s = "%u+%s+%s" % (size, size_str, pad_str) + else: + s = "%u+%s" % (size, size_str) + + print ' 2 %-15s rendering command length' % (s) + print ' 2 %-4u rendering command opcode' % (f.glx_rop) + return + + + def print_single_header(self, f): + [size, size_str, pad_str] = self.body_size(f) + size = ((size + 3) / 4) + 2; + + if f.glx_vendorpriv != 0: + size += 1 + + print ' 1 CARD8 opcode (X assigned)' + print ' 1 %-4u GLX opcode (%s)' % (f.opcode_real_value(), f.opcode_real_name()) + + if size_str == "": + s = "%u" % (size) + elif pad_str != "": + s = "%u+((%s+%s)/4)" % (size, size_str, pad_str) + else: + s = "%u+((%s)/4)" % (size, size_str) + + print ' 2 %-15s request length' % (s) + + if f.glx_vendorpriv != 0: + print ' 4 %-4u vendor specific opcode' % (f.opcode_value()) + + print ' 4 GLX_CONTEXT_TAG context tag' + + return + + + def print_reply(self, f): + print ' =>' + print ' 1 1 reply' + print ' 1 unused' + print ' 2 CARD16 sequence number' + + if f.output == None: + print ' 4 0 reply length' + elif f.reply_always_array: + print ' 4 m reply length' + else: + print ' 4 m reply length, m = (n == 1 ? 0 : n)' + + + output = None + for x in f.parameterIterateOutputs(): + output = x + break + + + unused = 24 + if f.return_type != 'void': + print ' 4 %-15s return value' % (f.return_type) + unused -= 4 + elif output != None: + print ' 4 unused' + unused -= 4 + + if output != None: + print ' 4 CARD32 n' + unused -= 4 + + if output != None: + if not f.reply_always_array: + print '' + print ' if (n = 1) this follows:' + print '' + print ' 4 CARD32 %s' % (output.name) + print ' %-2u unused' % (unused - 4) + print '' + print ' otherwise this follows:' + print '' + + print ' %-2u unused' % (unused) + + [s, pad] = output.packet_size() + print ' %-8s %-15s %s' % (s, output.packet_type( self.type_map ), output.name) + if pad != None: + try: + bytes = int(s) + bytes = 4 - (bytes & 3) + print ' %-8u %-15s unused' % (bytes, "") + except Exception,e: + print ' %-8s %-15s unused, %s=pad(%s)' % (pad, "", pad, s) + else: + print ' %-2u unused' % (unused) + + + def print_body(self, f): + for p in f.parameterIterateGlxSend(): + [s, pad] = p.packet_size() + print ' %-8s %-15s %s' % (s, p.packet_type( self.type_map ), p.name) + if pad != None: + try: + bytes = int(s) + bytes = 4 - (bytes & 3) + print ' %-8u %-15s unused' % (bytes, "") + except Exception,e: + print ' %-8s %-15s unused, %s=pad(%s)' % (pad, "", pad, s) + + def printBody(self, api): + self.type_map = {} + for t in api.typeIterate(): + self.type_map[ "GL" + t.name ] = t.glx_name + + + # At some point this should be expanded to support pixel + # functions, but I'm not going to lose any sleep over it now. + + for f in api.functionIterateByOffset(): + if f.client_handcode or f.server_handcode or f.vectorequiv or len(f.get_images()): + continue + + + if f.glx_rop: + print ' %s' % (f.name) + self.print_render_header(f) + elif f.glx_sop or f.glx_vendorpriv: + print ' %s' % (f.name) + self.print_single_header(f) + else: + continue + + self.print_body(f) + + if f.needs_reply(): + self.print_reply(f) + + print '' + return + + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:") + except Exception,e: + show_usage() + + for (arg,val) in args: + if arg == "-f": + file_name = val + + api = gl_XML.parse_GL_API( file_name, glx_doc_item_factory() ) + + printer = PrintGlxProtoText() + printer.Print( api ) diff --git a/src/mapi/glapi/gen/glX_proto_common.py b/src/mapi/glapi/gen/glX_proto_common.py new file mode 100644 index 0000000..6f094e2 --- /dev/null +++ b/src/mapi/glapi/gen/glX_proto_common.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import gl_XML, glX_XML +import string + + +class glx_proto_item_factory(glX_XML.glx_item_factory): + """Factory to create GLX protocol oriented objects derived from gl_item.""" + + def create_item(self, name, element, context): + if name == "type": + return glx_proto_type(element, context) + else: + return glX_XML.glx_item_factory.create_item(self, name, element, context) + + +class glx_proto_type(gl_XML.gl_type): + def __init__(self, element, context): + gl_XML.gl_type.__init__(self, element, context) + + self.glx_name = element.nsProp( "glx_name", None ) + return + + +class glx_print_proto(gl_XML.gl_print_base): + def size_call(self, func, outputs_also = 0): + """Create C code to calculate 'compsize'. + + Creates code to calculate 'compsize'. If the function does + not need 'compsize' to be calculated, None will be + returned.""" + + compsize = None + + for param in func.parameterIterator(): + if outputs_also or not param.is_output: + if param.is_image(): + [dim, w, h, d, junk] = param.get_dimensions() + + compsize = '__glImageSize(%s, %s, %s, %s, %s, %s)' % (w, h, d, param.img_format, param.img_type, param.img_target) + if not param.img_send_null: + compsize = '(%s != NULL) ? %s : 0' % (param.name, compsize) + + return compsize + + elif len(param.count_parameter_list): + parameters = string.join( param.count_parameter_list, "," ) + compsize = "__gl%s_size(%s)" % (func.name, parameters) + + return compsize + + return None + + + def emit_packet_size_calculation(self, f, bias): + # compsize is only used in the command size calculation if + # the function has a non-output parameter that has a non-empty + # counter_parameter_list. + + compsize = self.size_call(f) + if compsize: + print ' const GLuint compsize = %s;' % (compsize) + + if bias: + print ' const GLuint cmdlen = %s - %u;' % (f.command_length(), bias) + else: + print ' const GLuint cmdlen = %s;' % (f.command_length()) + + #print '' + return compsize diff --git a/src/mapi/glapi/gen/glX_proto_recv.py b/src/mapi/glapi/gen/glX_proto_recv.py new file mode 100644 index 0000000..887f631 --- /dev/null +++ b/src/mapi/glapi/gen/glX_proto_recv.py @@ -0,0 +1,554 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import gl_XML, glX_XML, glX_proto_common, license +import sys, getopt, string + + +class PrintGlxDispatch_h(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "glX_proto_recv.py (from Mesa)" + self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM") + + self.header_tag = "_INDIRECT_DISPATCH_H_" + return + + + def printRealHeader(self): + self.printVisibility( "HIDDEN", "hidden" ) + print 'struct __GLXclientStateRec;' + print '' + return + + + def printBody(self, api): + for func in api.functionIterateAll(): + if not func.ignore and not func.vectorequiv: + if func.glx_rop: + print 'extern HIDDEN void __glXDisp_%s(GLbyte * pc);' % (func.name) + print 'extern HIDDEN void __glXDispSwap_%s(GLbyte * pc);' % (func.name) + elif func.glx_sop or func.glx_vendorpriv: + print 'extern HIDDEN int __glXDisp_%s(struct __GLXclientStateRec *, GLbyte *);' % (func.name) + print 'extern HIDDEN int __glXDispSwap_%s(struct __GLXclientStateRec *, GLbyte *);' % (func.name) + + if func.glx_sop and func.glx_vendorpriv: + n = func.glx_vendorpriv_names[0] + print 'extern HIDDEN int __glXDisp_%s(struct __GLXclientStateRec *, GLbyte *);' % (n) + print 'extern HIDDEN int __glXDispSwap_%s(struct __GLXclientStateRec *, GLbyte *);' % (n) + + return + + +class PrintGlxDispatchFunctions(glX_proto_common.glx_print_proto): + def __init__(self, do_swap): + gl_XML.gl_print_base.__init__(self) + self.name = "glX_proto_recv.py (from Mesa)" + self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM") + + self.real_types = [ '', '', 'uint16_t', '', 'uint32_t', '', '', '', 'uint64_t' ] + self.do_swap = do_swap + return + + + def printRealHeader(self): + print '#include ' + print '#include ' + print '#include ' + + print '#include ' + print '#include "indirect_size.h"' + print '#include "indirect_size_get.h"' + print '#include "indirect_dispatch.h"' + print '#include "glxserver.h"' + print '#include "glxbyteorder.h"' + print '#include "indirect_util.h"' + print '#include "singlesize.h"' + print '#include "glapi.h"' + print '#include "glapitable.h"' + print '#include "glthread.h"' + print '#include "glapidispatch.h"' + print '' + print '#define __GLX_PAD(x) (((x) + 3) & ~3)' + print '' + print 'typedef struct {' + print ' __GLX_PIXEL_3D_HDR;' + print '} __GLXpixel3DHeader;' + print '' + print 'extern GLboolean __glXErrorOccured( void );' + print 'extern void __glXClearErrorOccured( void );' + print '' + print 'static const unsigned dummy_answer[2] = {0, 0};' + print '' + return + + + def printBody(self, api): + if self.do_swap: + self.emit_swap_wrappers(api) + + + for func in api.functionIterateByOffset(): + if not func.ignore and not func.server_handcode and not func.vectorequiv and (func.glx_rop or func.glx_sop or func.glx_vendorpriv): + self.printFunction(func, func.name) + if func.glx_sop and func.glx_vendorpriv: + self.printFunction(func, func.glx_vendorpriv_names[0]) + + + return + + + def printFunction(self, f, name): + if (f.glx_sop or f.glx_vendorpriv) and (len(f.get_images()) != 0): + return + + if not self.do_swap: + base = '__glXDisp' + else: + base = '__glXDispSwap' + + if f.glx_rop: + print 'void %s_%s(GLbyte * pc)' % (base, name) + else: + print 'int %s_%s(__GLXclientState *cl, GLbyte *pc)' % (base, name) + + print '{' + + if f.glx_rop or f.vectorequiv: + self.printRenderFunction(f) + elif f.glx_sop or f.glx_vendorpriv: + if len(f.get_images()) == 0: + self.printSingleFunction(f, name) + else: + print "/* Missing GLX protocol for %s. */" % (name) + + print '}' + print '' + return + + + def swap_name(self, bytes): + return 'bswap_%u_array' % (8 * bytes) + + + def emit_swap_wrappers(self, api): + self.type_map = {} + already_done = [ ] + + for t in api.typeIterate(): + te = t.get_type_expression() + t_size = te.get_element_size() + + if t_size > 1 and t.glx_name: + + t_name = "GL" + t.name + self.type_map[ t_name ] = t.glx_name + + if t.glx_name not in already_done: + real_name = self.real_types[t_size] + + print 'static %s' % (t_name) + print 'bswap_%s( const void * src )' % (t.glx_name) + print '{' + print ' union { %s dst; %s ret; } x;' % (real_name, t_name) + print ' x.dst = bswap_%u( *(%s *) src );' % (t_size * 8, real_name) + print ' return x.ret;' + print '}' + print '' + already_done.append( t.glx_name ) + + for bits in [16, 32, 64]: + print 'static void *' + print 'bswap_%u_array( uint%u_t * src, unsigned count )' % (bits, bits) + print '{' + print ' unsigned i;' + print '' + print ' for ( i = 0 ; i < count ; i++ ) {' + print ' uint%u_t temp = bswap_%u( src[i] );' % (bits, bits) + print ' src[i] = temp;' + print ' }' + print '' + print ' return src;' + print '}' + print '' + + + def fetch_param(self, param): + t = param.type_string() + o = param.offset + element_size = param.size() / param.get_element_count() + + if self.do_swap and (element_size != 1): + if param.is_array(): + real_name = self.real_types[ element_size ] + + swap_func = self.swap_name( element_size ) + return ' (%-8s)%s( (%s *) (pc + %2s), %s )' % (t, swap_func, real_name, o, param.count) + else: + t_name = param.get_base_type_string() + return ' (%-8s)bswap_%-7s( pc + %2s )' % (t, self.type_map[ t_name ], o) + else: + if param.is_array(): + return ' (%-8s)(pc + %2u)' % (t, o) + else: + return '*(%-8s *)(pc + %2u)' % (t, o) + + return None + + + def emit_function_call(self, f, retval_assign, indent): + list = [] + + for param in f.parameterIterator(): + if param.is_padding: + continue + + if param.is_counter or param.is_image() or param.is_output or param.name in f.count_parameter_list or len(param.count_parameter_list): + location = param.name + else: + location = self.fetch_param(param) + + list.append( '%s %s' % (indent, location) ) + + + if len( list ): + print '%s %sCALL_%s( GET_DISPATCH(), (' % (indent, retval_assign, f.name) + print string.join( list, ",\n" ) + print '%s ) );' % (indent) + else: + print '%s %sCALL_%s( GET_DISPATCH(), () );' % (indent, retval_assign, f.name) + return + + + def common_func_print_just_start(self, f, indent): + align64 = 0 + need_blank = 0 + + + f.calculate_offsets() + for param in f.parameterIterateGlxSend(): + # If any parameter has a 64-bit base type, then we + # have to do alignment magic for the while thing. + + if param.is_64_bit(): + align64 = 1 + + + # FIXME img_null_flag is over-loaded. In addition to + # FIXME being used for images, it is used to signify + # FIXME NULL data pointers for vertex buffer object + # FIXME related functions. Re-name it to null_data + # FIXME or something similar. + + if param.img_null_flag: + print '%s const CARD32 ptr_is_null = *(CARD32 *)(pc + %s);' % (indent, param.offset - 4) + cond = '(ptr_is_null != 0) ? NULL : ' + else: + cond = "" + + + type_string = param.type_string() + + if param.is_image(): + offset = f.offset_of( param.name ) + + print '%s %s const %s = (%s) (%s(pc + %s));' % (indent, type_string, param.name, type_string, cond, offset) + + if param.depth: + print '%s __GLXpixel3DHeader * const hdr = (__GLXpixel3DHeader *)(pc);' % (indent) + else: + print '%s __GLXpixelHeader * const hdr = (__GLXpixelHeader *)(pc);' % (indent) + + need_blank = 1 + elif param.is_counter or param.name in f.count_parameter_list: + location = self.fetch_param(param) + print '%s const %s %s = %s;' % (indent, type_string, param.name, location) + need_blank = 1 + elif len(param.count_parameter_list): + if param.size() == 1 and not self.do_swap: + location = self.fetch_param(param) + print '%s %s %s = %s%s;' % (indent, type_string, param.name, cond, location) + else: + print '%s %s %s;' % (indent, type_string, param.name) + need_blank = 1 + + + + if need_blank: + print '' + + if align64: + print '#ifdef __GLX_ALIGN64' + + if f.has_variable_size_request(): + self.emit_packet_size_calculation(f, 4) + s = "cmdlen" + else: + s = str((f.command_fixed_length() + 3) & ~3) + + print ' if ((unsigned long)(pc) & 7) {' + print ' (void) memmove(pc-4, pc, %s);' % (s) + print ' pc -= 4;' + print ' }' + print '#endif' + print '' + + + need_blank = 0 + if self.do_swap: + for param in f.parameterIterateGlxSend(): + if param.count_parameter_list: + o = param.offset + count = param.get_element_count() + type_size = param.size() / count + + if param.counter: + count_name = param.counter + else: + count_name = str(count) + + # This is basically an ugly special- + # case for glCallLists. + + if type_size == 1: + x = [] + x.append( [1, ['BYTE', 'UNSIGNED_BYTE', '2_BYTES', '3_BYTES', '4_BYTES']] ) + x.append( [2, ['SHORT', 'UNSIGNED_SHORT']] ) + x.append( [4, ['INT', 'UNSIGNED_INT', 'FLOAT']] ) + + print ' switch(%s) {' % (param.count_parameter_list[0]) + for sub in x: + for t_name in sub[1]: + print ' case GL_%s:' % (t_name) + + if sub[0] == 1: + print ' %s = (%s) (pc + %s); break;' % (param.name, param.type_string(), o) + else: + swap_func = self.swap_name(sub[0]) + print ' %s = (%s) %s( (%s *) (pc + %s), %s ); break;' % (param.name, param.type_string(), swap_func, self.real_types[sub[0]], o, count_name) + print ' default:' + print ' return;' + print ' }' + else: + swap_func = self.swap_name(type_size) + compsize = self.size_call(f, 1) + print ' %s = (%s) %s( (%s *) (pc + %s), %s );' % (param.name, param.type_string(), swap_func, self.real_types[type_size], o, compsize) + + need_blank = 1 + + else: + for param in f.parameterIterateGlxSend(): + if param.count_parameter_list: + print '%s %s = (%s) (pc + %s);' % (indent, param.name, param.type_string(), param.offset) + need_blank = 1 + + + if need_blank: + print '' + + + return + + + def printSingleFunction(self, f, name): + if name not in f.glx_vendorpriv_names: + print ' xGLXSingleReq * const req = (xGLXSingleReq *) pc;' + else: + print ' xGLXVendorPrivateReq * const req = (xGLXVendorPrivateReq *) pc;' + + print ' int error;' + + if self.do_swap: + print ' struct glx_context * const cx = __glXForceCurrent(cl, bswap_CARD32( &req->contextTag ), &error);' + else: + print ' struct glx_context * const cx = __glXForceCurrent(cl, req->contextTag, &error);' + + print '' + if name not in f.glx_vendorpriv_names: + print ' pc += __GLX_SINGLE_HDR_SIZE;' + else: + print ' pc += __GLX_VENDPRIV_HDR_SIZE;' + + print ' if ( cx != NULL ) {' + self.common_func_print_just_start(f, " ") + + + if f.return_type != 'void': + print ' %s retval;' % (f.return_type) + retval_string = "retval" + retval_assign = "retval = " + else: + retval_string = "0" + retval_assign = "" + + + type_size = 0 + answer_string = "dummy_answer" + answer_count = "0" + is_array_string = "GL_FALSE" + + for param in f.parameterIterateOutputs(): + answer_type = param.get_base_type_string() + if answer_type == "GLvoid": + answer_type = "GLubyte" + + + c = param.get_element_count() + type_size = (param.size() / c) + if type_size == 1: + size_scale = "" + else: + size_scale = " * %u" % (type_size) + + + if param.count_parameter_list: + print ' const GLuint compsize = %s;' % (self.size_call(f, 1)) + print ' %s answerBuffer[200];' % (answer_type) + print ' %s %s = __glXGetAnswerBuffer(cl, compsize%s, answerBuffer, sizeof(answerBuffer), %u);' % (param.type_string(), param.name, size_scale, type_size ) + answer_string = param.name + answer_count = "compsize" + + print '' + print ' if (%s == NULL) return BadAlloc;' % (param.name) + print ' __glXClearErrorOccured();' + print '' + elif param.counter: + print ' %s answerBuffer[200];' % (answer_type) + print ' %s %s = __glXGetAnswerBuffer(cl, %s%s, answerBuffer, sizeof(answerBuffer), %u);' % (param.type_string(), param.name, param.counter, size_scale, type_size) + answer_string = param.name + answer_count = param.counter + elif c >= 1: + print ' %s %s[%u];' % (answer_type, param.name, c) + answer_string = param.name + answer_count = "%u" % (c) + + if f.reply_always_array: + is_array_string = "GL_TRUE" + + + self.emit_function_call(f, retval_assign, " ") + + + if f.needs_reply(): + if self.do_swap: + for param in f.parameterIterateOutputs(): + c = param.get_element_count() + type_size = (param.size() / c) + + if type_size > 1: + swap_name = self.swap_name( type_size ) + print ' (void) %s( (uint%u_t *) %s, %s );' % (swap_name, 8 * type_size, param.name, answer_count) + + + reply_func = '__glXSendReplySwap' + else: + reply_func = '__glXSendReply' + + print ' %s(cl->client, %s, %s, %u, %s, %s);' % (reply_func, answer_string, answer_count, type_size, is_array_string, retval_string) + #elif f.note_unflushed: + # print ' cx->hasUnflushedCommands = GL_TRUE;' + + print ' error = Success;' + print ' }' + print '' + print ' return error;' + return + + + def printRenderFunction(self, f): + # There are 4 distinct phases in a rendering dispatch function. + # In the first phase we compute the sizes and offsets of each + # element in the command. In the second phase we (optionally) + # re-align 64-bit data elements. In the third phase we + # (optionally) byte-swap array data. Finally, in the fourth + # phase we actually dispatch the function. + + self.common_func_print_just_start(f, "") + + images = f.get_images() + if len(images): + if self.do_swap: + pre = "bswap_CARD32( & " + post = " )" + else: + pre = "" + post = "" + + img = images[0] + + # swapBytes and lsbFirst are single byte fields, so + # the must NEVER be byte-swapped. + + if not (img.img_type == "GL_BITMAP" and img.img_format == "GL_COLOR_INDEX"): + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SWAP_BYTES, hdr->swapBytes) );' + + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_LSB_FIRST, hdr->lsbFirst) );' + + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ROW_LENGTH, (GLint) %shdr->rowLength%s) );' % (pre, post) + if img.depth: + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_IMAGE_HEIGHT, (GLint) %shdr->imageHeight%s) );' % (pre, post) + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_ROWS, (GLint) %shdr->skipRows%s) );' % (pre, post) + if img.depth: + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_IMAGES, (GLint) %shdr->skipImages%s) );' % (pre, post) + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_PIXELS, (GLint) %shdr->skipPixels%s) );' % (pre, post) + print ' CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ALIGNMENT, (GLint) %shdr->alignment%s) );' % (pre, post) + print '' + + + self.emit_function_call(f, "", "") + return + + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:m:s") + except Exception,e: + show_usage() + + mode = "dispatch_c" + do_swap = 0 + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-m": + mode = val + elif arg == "-s": + do_swap = 1 + + if mode == "dispatch_c": + printer = PrintGlxDispatchFunctions(do_swap) + elif mode == "dispatch_h": + printer = PrintGlxDispatch_h() + else: + show_usage() + + api = gl_XML.parse_GL_API( file_name, glX_proto_common.glx_proto_item_factory() ) + + printer.Print( api ) diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py new file mode 100644 index 0000000..17ebad0 --- /dev/null +++ b/src/mapi/glapi/gen/glX_proto_send.py @@ -0,0 +1,1044 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick +# Jeremy Kolb + +import gl_XML, glX_XML, glX_proto_common, license +import sys, getopt, copy, string + +def convertStringForXCB(str): + tmp = "" + special = [ "ARB" ] + i = 0 + while i < len(str): + if str[i:i+3] in special: + tmp = '%s_%s' % (tmp, string.lower(str[i:i+3])) + i = i + 2; + elif str[i].isupper(): + tmp = '%s_%s' % (tmp, string.lower(str[i])) + else: + tmp = '%s%s' % (tmp, str[i]) + i += 1 + return tmp + +def hash_pixel_function(func): + """Generate a 'unique' key for a pixel function. The key is based on + the parameters written in the command packet. This includes any + padding that might be added for the original function and the 'NULL + image' flag.""" + + + h = "" + hash_pre = "" + hash_suf = "" + for param in func.parameterIterateGlxSend(): + if param.is_image(): + [dim, junk, junk, junk, junk] = param.get_dimensions() + + d = (dim + 1) & ~1 + hash_pre = "%uD%uD_" % (d - 1, d) + + if param.img_null_flag: + hash_suf = "_NF" + + h += "%u" % (param.size()) + + if func.pad_after(param): + h += "4" + + + n = func.name.replace("%uD" % (dim), "") + n = "__glx_%s_%uD%uD" % (n, d - 1, d) + + h = hash_pre + h + hash_suf + return [h, n] + + +class glx_pixel_function_stub(glX_XML.glx_function): + """Dummy class used to generate pixel "utility" functions that are + shared by multiple dimension image functions. For example, these + objects are used to generate shared functions used to send GLX + protocol for TexImage1D and TexImage2D, TexSubImage1D and + TexSubImage2D, etc.""" + + def __init__(self, func, name): + # The parameters to the utility function are the same as the + # parameters to the real function except for the added "pad" + # parameters. + + self.name = name + self.images = [] + self.parameters = [] + self.parameters_by_name = {} + for _p in func.parameterIterator(): + p = copy.copy(_p) + self.parameters.append(p) + self.parameters_by_name[ p.name ] = p + + + if p.is_image(): + self.images.append(p) + p.height = "height" + + if p.img_yoff == None: + p.img_yoff = "yoffset" + + if p.depth: + if p.extent == None: + p.extent = "extent" + + if p.img_woff == None: + p.img_woff = "woffset" + + + pad_name = func.pad_after(p) + if pad_name: + pad = copy.copy(p) + pad.name = pad_name + self.parameters.append(pad) + self.parameters_by_name[ pad.name ] = pad + + + self.return_type = func.return_type + + self.glx_rop = ~0 + self.glx_sop = 0 + self.glx_vendorpriv = 0 + + self.glx_doubles_in_order = func.glx_doubles_in_order + + self.vectorequiv = None + self.output = None + self.can_be_large = func.can_be_large + self.reply_always_array = func.reply_always_array + self.dimensions_in_reply = func.dimensions_in_reply + self.img_reset = None + + self.server_handcode = 0 + self.client_handcode = 0 + self.ignore = 0 + + self.count_parameter_list = func.count_parameter_list + self.counter_list = func.counter_list + self.offsets_calculated = 0 + return + + +class PrintGlxProtoStubs(glX_proto_common.glx_print_proto): + def __init__(self): + glX_proto_common.glx_print_proto.__init__(self) + self.name = "glX_proto_send.py (from Mesa)" + self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004, 2005", "IBM") + + + self.last_category = "" + self.generic_sizes = [3, 4, 6, 8, 12, 16, 24, 32] + self.pixel_stubs = {} + self.debug = 0 + return + + def printRealHeader(self): + print '' + print '#include ' + print '#include "indirect.h"' + print '#include "glxclient.h"' + print '#include "indirect_size.h"' + print '#include "glapi.h"' + print '#include "glthread.h"' + print '#include ' + print '#ifdef USE_XCB' + print '#include ' + print '#include ' + print '#include ' + print '#endif /* USE_XCB */' + + print '' + print '#define __GLX_PAD(n) (((n) + 3) & ~3)' + print '' + self.printFastcall() + self.printNoinline() + print '' + print '#ifndef __GNUC__' + print '# define __builtin_expect(x, y) x' + print '#endif' + print '' + print '/* If the size and opcode values are known at compile-time, this will, on' + print ' * x86 at least, emit them with a single instruction.' + print ' */' + print '#define emit_header(dest, op, size) \\' + print ' do { union { short s[2]; int i; } temp; \\' + print ' temp.s[0] = (size); temp.s[1] = (op); \\' + print ' *((int *)(dest)) = temp.i; } while(0)' + print '' + print """NOINLINE CARD32 +__glXReadReply( Display *dpy, size_t size, void * dest, GLboolean reply_is_always_array ) +{ + xGLXSingleReply reply; + + (void) _XReply(dpy, (xReply *) & reply, 0, False); + if (size != 0) { + if ((reply.length > 0) || reply_is_always_array) { + const GLint bytes = (reply_is_always_array) + ? (4 * reply.length) : (reply.size * size); + const GLint extra = 4 - (bytes & 3); + + _XRead(dpy, dest, bytes); + if ( extra < 4 ) { + _XEatData(dpy, extra); + } + } + else { + (void) memcpy( dest, &(reply.pad3), size); + } + } + + return reply.retval; +} + +NOINLINE void +__glXReadPixelReply( Display *dpy, struct glx_context * gc, unsigned max_dim, + GLint width, GLint height, GLint depth, GLenum format, GLenum type, + void * dest, GLboolean dimensions_in_reply ) +{ + xGLXSingleReply reply; + GLint size; + + (void) _XReply(dpy, (xReply *) & reply, 0, False); + + if ( dimensions_in_reply ) { + width = reply.pad3; + height = reply.pad4; + depth = reply.pad5; + + if ((height == 0) || (max_dim < 2)) { height = 1; } + if ((depth == 0) || (max_dim < 3)) { depth = 1; } + } + + size = reply.length * 4; + if (size != 0) { + void * buf = Xmalloc( size ); + + if ( buf == NULL ) { + _XEatData(dpy, size); + __glXSetError(gc, GL_OUT_OF_MEMORY); + } + else { + const GLint extra = 4 - (size & 3); + + _XRead(dpy, buf, size); + if ( extra < 4 ) { + _XEatData(dpy, extra); + } + + __glEmptyImage(gc, 3, width, height, depth, format, type, + buf, dest); + Xfree(buf); + } + } +} + +#define X_GLXSingle 0 + +NOINLINE FASTCALL GLubyte * +__glXSetupSingleRequest( struct glx_context * gc, GLint sop, GLint cmdlen ) +{ + xGLXSingleReq * req; + Display * const dpy = gc->currentDpy; + + (void) __glXFlushRenderBuffer(gc, gc->pc); + LockDisplay(dpy); + GetReqExtra(GLXSingle, cmdlen, req); + req->reqType = gc->majorOpcode; + req->contextTag = gc->currentContextTag; + req->glxCode = sop; + return (GLubyte *)(req) + sz_xGLXSingleReq; +} + +NOINLINE FASTCALL GLubyte * +__glXSetupVendorRequest( struct glx_context * gc, GLint code, GLint vop, GLint cmdlen ) +{ + xGLXVendorPrivateReq * req; + Display * const dpy = gc->currentDpy; + + (void) __glXFlushRenderBuffer(gc, gc->pc); + LockDisplay(dpy); + GetReqExtra(GLXVendorPrivate, cmdlen, req); + req->reqType = gc->majorOpcode; + req->glxCode = code; + req->vendorCode = vop; + req->contextTag = gc->currentContextTag; + return (GLubyte *)(req) + sz_xGLXVendorPrivateReq; +} + +const GLuint __glXDefaultPixelStore[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; + +#define zero (__glXDefaultPixelStore+0) +#define one (__glXDefaultPixelStore+8) +#define default_pixel_store_1D (__glXDefaultPixelStore+4) +#define default_pixel_store_1D_size 20 +#define default_pixel_store_2D (__glXDefaultPixelStore+4) +#define default_pixel_store_2D_size 20 +#define default_pixel_store_3D (__glXDefaultPixelStore+0) +#define default_pixel_store_3D_size 36 +#define default_pixel_store_4D (__glXDefaultPixelStore+0) +#define default_pixel_store_4D_size 36 +""" + + for size in self.generic_sizes: + self.print_generic_function(size) + return + + + def printBody(self, api): + + self.pixel_stubs = {} + generated_stubs = [] + + for func in api.functionIterateGlx(): + if func.client_handcode: continue + + # If the function is a pixel function with a certain + # GLX protocol signature, create a fake stub function + # for it. For example, create a single stub function + # that is used to implement both glTexImage1D and + # glTexImage2D. + + if func.glx_rop != 0: + do_it = 0 + for image in func.get_images(): + if image.img_pad_dimensions: + do_it = 1 + break + + + if do_it: + [h, n] = hash_pixel_function(func) + + + self.pixel_stubs[ func.name ] = n + if h not in generated_stubs: + generated_stubs.append(h) + + fake_func = glx_pixel_function_stub( func, n ) + self.printFunction(fake_func, fake_func.name) + + + self.printFunction(func, func.name) + if func.glx_sop and func.glx_vendorpriv: + self.printFunction(func, func.glx_vendorpriv_names[0]) + + return + + + def printFunction(self, func, name): + footer = '}\n' + if func.glx_rop == ~0: + print 'static %s' % (func.return_type) + print '%s( unsigned opcode, unsigned dim, %s )' % (func.name, func.get_parameter_string()) + print '{' + else: + if func.has_different_protocol(name): + if func.return_type == "void": + ret_string = '' + else: + ret_string = "return " + + func_name = func.static_glx_name(name) + print '#define %s %d' % (func.opcode_vendor_name(name), func.glx_vendorpriv) + print '%s gl%s(%s)' % (func.return_type, func_name, func.get_parameter_string()) + print '{' + print ' struct glx_context * const gc = __glXGetCurrentContext();' + print '' + print '#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)' + print ' if (gc->isDirect) {' + print ' %sGET_DISPATCH()->%s(%s);' % (ret_string, func.name, func.get_called_parameter_string()) + print ' } else' + print '#endif' + print ' {' + + footer = '}\n}\n' + else: + print '#define %s %d' % (func.opcode_name(), func.opcode_value()) + + print '%s __indirect_gl%s(%s)' % (func.return_type, name, func.get_parameter_string()) + print '{' + + + if func.glx_rop != 0 or func.vectorequiv != None: + if len(func.images): + self.printPixelFunction(func) + else: + self.printRenderFunction(func) + elif func.glx_sop != 0 or func.glx_vendorpriv != 0: + self.printSingleFunction(func, name) + pass + else: + print "/* Missing GLX protocol for %s. */" % (name) + + print footer + return + + + def print_generic_function(self, n): + size = (n + 3) & ~3 + print """static FASTCALL NOINLINE void +generic_%u_byte( GLint rop, const void * ptr ) +{ + struct glx_context * const gc = __glXGetCurrentContext(); + const GLuint cmdlen = %u; + + emit_header(gc->pc, rop, cmdlen); + (void) memcpy((void *)(gc->pc + 4), ptr, %u); + gc->pc += cmdlen; + if (__builtin_expect(gc->pc > gc->limit, 0)) { (void) __glXFlushRenderBuffer(gc, gc->pc); } +} +""" % (n, size + 4, size) + return + + + def common_emit_one_arg(self, p, pc, adjust, extra_offset): + if p.is_array(): + src_ptr = p.name + else: + src_ptr = "&" + p.name + + if p.is_padding: + print '(void) memset((void *)(%s + %u), 0, %s);' \ + % (pc, p.offset + adjust, p.size_string() ) + elif not extra_offset: + print '(void) memcpy((void *)(%s + %u), (void *)(%s), %s);' \ + % (pc, p.offset + adjust, src_ptr, p.size_string() ) + else: + print '(void) memcpy((void *)(%s + %u + %s), (void *)(%s), %s);' \ + % (pc, p.offset + adjust, extra_offset, src_ptr, p.size_string() ) + + def common_emit_args(self, f, pc, adjust, skip_vla): + extra_offset = None + + for p in f.parameterIterateGlxSend( not skip_vla ): + if p.name != f.img_reset: + self.common_emit_one_arg(p, pc, adjust, extra_offset) + + if p.is_variable_length(): + temp = p.size_string() + if extra_offset: + extra_offset += " + %s" % (temp) + else: + extra_offset = temp + + return + + + def pixel_emit_args(self, f, pc, large): + """Emit the arguments for a pixel function. This differs from + common_emit_args in that pixel functions may require padding + be inserted (i.e., for the missing width field for + TexImage1D), and they may also require a 'NULL image' flag + be inserted before the image data.""" + + if large: + adjust = 8 + else: + adjust = 4 + + for param in f.parameterIterateGlxSend(): + if not param.is_image(): + self.common_emit_one_arg(param, pc, adjust, None) + + if f.pad_after(param): + print '(void) memcpy((void *)(%s + %u), zero, 4);' % (pc, (param.offset + param.size()) + adjust) + + else: + [dim, width, height, depth, extent] = param.get_dimensions() + if f.glx_rop == ~0: + dim_str = "dim" + else: + dim_str = str(dim) + + if param.is_padding: + print '(void) memset((void *)(%s + %u), 0, %s);' \ + % (pc, (param.offset - 4) + adjust, param.size_string() ) + + if param.img_null_flag: + if large: + print '(void) memcpy((void *)(%s + %u), zero, 4);' % (pc, (param.offset - 4) + adjust) + else: + print '(void) memcpy((void *)(%s + %u), (void *)((%s == NULL) ? one : zero), 4);' % (pc, (param.offset - 4) + adjust, param.name) + + + pixHeaderPtr = "%s + %u" % (pc, adjust) + pcPtr = "%s + %u" % (pc, param.offset + adjust) + + if not large: + if param.img_send_null: + condition = '(compsize > 0) && (%s != NULL)' % (param.name) + else: + condition = 'compsize > 0' + + print 'if (%s) {' % (condition) + print ' (*gc->fillImage)(gc, %s, %s, %s, %s, %s, %s, %s, %s, %s);' % (dim_str, width, height, depth, param.img_format, param.img_type, param.name, pcPtr, pixHeaderPtr) + print '} else {' + print ' (void) memcpy( %s, default_pixel_store_%uD, default_pixel_store_%uD_size );' % (pixHeaderPtr, dim, dim) + print '}' + else: + print '__glXSendLargeImage(gc, compsize, %s, %s, %s, %s, %s, %s, %s, %s, %s);' % (dim_str, width, height, depth, param.img_format, param.img_type, param.name, pcPtr, pixHeaderPtr) + + return + + + def large_emit_begin(self, f, op_name = None): + if not op_name: + op_name = f.opcode_real_name() + + print 'const GLint op = %s;' % (op_name) + print 'const GLuint cmdlenLarge = cmdlen + 4;' + print 'GLubyte * const pc = __glXFlushRenderBuffer(gc, gc->pc);' + print '(void) memcpy((void *)(pc + 0), (void *)(&cmdlenLarge), 4);' + print '(void) memcpy((void *)(pc + 4), (void *)(&op), 4);' + return + + + def common_func_print_just_start(self, f, name): + print ' struct glx_context * const gc = __glXGetCurrentContext();' + + # The only reason that single and vendor private commands need + # a variable called 'dpy' is becuase they use the SyncHandle + # macro. For whatever brain-dead reason, that macro is hard- + # coded to use a variable called 'dpy' instead of taking a + # parameter. + + # FIXME Simplify the logic related to skip_condition and + # FIXME condition_list in this function. Basically, remove + # FIXME skip_condition, and just append the "dpy != NULL" type + # FIXME condition to condition_list from the start. The only + # FIXME reason it's done in this confusing way now is to + # FIXME minimize the diffs in the generated code. + + if not f.glx_rop: + for p in f.parameterIterateOutputs(): + if p.is_image() and (p.img_format != "GL_COLOR_INDEX" or p.img_type != "GL_BITMAP"): + print ' const __GLXattribute * const state = gc->client_state_private;' + break + + print ' Display * const dpy = gc->currentDpy;' + skip_condition = "dpy != NULL" + elif f.can_be_large: + skip_condition = "gc->currentDpy != NULL" + else: + skip_condition = None + + + if f.return_type != 'void': + print ' %s retval = (%s) 0;' % (f.return_type, f.return_type) + + + if name != None and name not in f.glx_vendorpriv_names: + print '#ifndef USE_XCB' + self.emit_packet_size_calculation(f, 0) + if name != None and name not in f.glx_vendorpriv_names: + print '#endif' + + condition_list = [] + for p in f.parameterIterateCounters(): + condition_list.append( "%s >= 0" % (p.name) ) + # 'counter' parameters cannot be negative + print " if (%s < 0) {" % p.name + print " __glXSetError(gc, GL_INVALID_VALUE);" + if f.return_type != 'void': + print " return 0;" + else: + print " return;" + print " }" + + if skip_condition: + condition_list.append( skip_condition ) + + if len( condition_list ) > 0: + if len( condition_list ) > 1: + skip_condition = "(%s)" % (string.join( condition_list, ") && (" )) + else: + skip_condition = "%s" % (condition_list.pop(0)) + + print ' if (__builtin_expect(%s, 1)) {' % (skip_condition) + return 1 + else: + return 0 + + + def printSingleFunction(self, f, name): + self.common_func_print_just_start(f, name) + + if self.debug: + print ' printf( "Enter %%s...\\n", "gl%s" );' % (f.name) + + if name not in f.glx_vendorpriv_names: + + # XCB specific: + print '#ifdef USE_XCB' + if self.debug: + print ' printf("\\tUsing XCB.\\n");' + print ' xcb_connection_t *c = XGetXCBConnection(dpy);' + print ' (void) __glXFlushRenderBuffer(gc, gc->pc);' + xcb_name = 'xcb_glx%s' % convertStringForXCB(name) + + iparams=[] + extra_iparams = [] + output = None + for p in f.parameterIterator(): + if p.is_output: + output = p + + if p.is_image(): + if p.img_format != "GL_COLOR_INDEX" or p.img_type != "GL_BITMAP": + extra_iparams.append("state->storePack.swapEndian") + else: + extra_iparams.append("0") + + # Hardcode this in. lsb_first param (apparently always GL_FALSE) + # also present in GetPolygonStipple, but taken care of above. + if xcb_name == "xcb_glx_read_pixels": + extra_iparams.append("0") + else: + iparams.append(p.name) + + + xcb_request = '%s(%s)' % (xcb_name, ", ".join(["c", "gc->currentContextTag"] + iparams + extra_iparams)) + + if f.needs_reply(): + print ' %s_reply_t *reply = %s_reply(c, %s, NULL);' % (xcb_name, xcb_name, xcb_request) + if output and f.reply_always_array: + print ' (void)memcpy(%s, %s_data(reply), %s_data_length(reply) * sizeof(%s));' % (output.name, xcb_name, xcb_name, output.get_base_type_string()) + + elif output and not f.reply_always_array: + if not output.is_image(): + print ' if (%s_data_length(reply) == 0)' % (xcb_name) + print ' (void)memcpy(%s, &reply->datum, sizeof(reply->datum));' % (output.name) + print ' else' + print ' (void)memcpy(%s, %s_data(reply), %s_data_length(reply) * sizeof(%s));' % (output.name, xcb_name, xcb_name, output.get_base_type_string()) + + + if f.return_type != 'void': + print ' retval = reply->ret_val;' + print ' free(reply);' + else: + print ' ' + xcb_request + ';' + print '#else' + # End of XCB specific. + + + if f.parameters != []: + pc_decl = "GLubyte const * pc =" + else: + pc_decl = "(void)" + + if name in f.glx_vendorpriv_names: + print ' %s __glXSetupVendorRequest(gc, %s, %s, cmdlen);' % (pc_decl, f.opcode_real_name(), f.opcode_vendor_name(name)) + else: + print ' %s __glXSetupSingleRequest(gc, %s, cmdlen);' % (pc_decl, f.opcode_name()) + + self.common_emit_args(f, "pc", 0, 0) + + images = f.get_images() + + for img in images: + if img.is_output: + o = f.command_fixed_length() - 4 + print ' *(int32_t *)(pc + %u) = 0;' % (o) + if img.img_format != "GL_COLOR_INDEX" or img.img_type != "GL_BITMAP": + print ' * (int8_t *)(pc + %u) = state->storePack.swapEndian;' % (o) + + if f.img_reset: + print ' * (int8_t *)(pc + %u) = %s;' % (o + 1, f.img_reset) + + + return_name = '' + if f.needs_reply(): + if f.return_type != 'void': + return_name = " retval" + return_str = " retval = (%s)" % (f.return_type) + else: + return_str = " (void)" + + got_reply = 0 + + for p in f.parameterIterateOutputs(): + if p.is_image(): + [dim, w, h, d, junk] = p.get_dimensions() + if f.dimensions_in_reply: + print " __glXReadPixelReply(dpy, gc, %u, 0, 0, 0, %s, %s, %s, GL_TRUE);" % (dim, p.img_format, p.img_type, p.name) + else: + print " __glXReadPixelReply(dpy, gc, %u, %s, %s, %s, %s, %s, %s, GL_FALSE);" % (dim, w, h, d, p.img_format, p.img_type, p.name) + + got_reply = 1 + else: + if f.reply_always_array: + aa = "GL_TRUE" + else: + aa = "GL_FALSE" + + # gl_parameter.size() returns the size + # of the entire data item. If the + # item is a fixed-size array, this is + # the size of the whole array. This + # is not what __glXReadReply wants. It + # wants the size of a single data + # element in the reply packet. + # Dividing by the array size (1 for + # non-arrays) gives us this. + + s = p.size() / p.get_element_count() + print " %s __glXReadReply(dpy, %s, %s, %s);" % (return_str, s, p.name, aa) + got_reply = 1 + + + # If a reply wasn't read to fill an output parameter, + # read a NULL reply to get the return value. + + if not got_reply: + print " %s __glXReadReply(dpy, 0, NULL, GL_FALSE);" % (return_str) + + + elif self.debug: + # Only emit the extra glFinish call for functions + # that don't already require a reply from the server. + print ' __indirect_glFinish();' + + if self.debug: + print ' printf( "Exit %%s.\\n", "gl%s" );' % (name) + + + print ' UnlockDisplay(dpy); SyncHandle();' + + if name not in f.glx_vendorpriv_names: + print '#endif /* USE_XCB */' + + print ' }' + print ' return%s;' % (return_name) + return + + + def printPixelFunction(self, f): + if self.pixel_stubs.has_key( f.name ): + # Normally gl_function::get_parameter_string could be + # used. However, this call needs to have the missing + # dimensions (e.g., a fake height value for + # glTexImage1D) added in. + + p_string = "" + for param in f.parameterIterateGlxSend(): + if param.is_padding: + continue + + p_string += ", " + param.name + + if param.is_image(): + [dim, junk, junk, junk, junk] = param.get_dimensions() + + if f.pad_after(param): + p_string += ", 1" + + print ' %s(%s, %u%s );' % (self.pixel_stubs[f.name] , f.opcode_name(), dim, p_string) + return + + + if self.common_func_print_just_start(f, None): + trailer = " }" + else: + trailer = None + + + if f.can_be_large: + print 'if (cmdlen <= gc->maxSmallRenderCommandSize) {' + print ' if ( (gc->pc + cmdlen) > gc->bufEnd ) {' + print ' (void) __glXFlushRenderBuffer(gc, gc->pc);' + print ' }' + + if f.glx_rop == ~0: + opcode = "opcode" + else: + opcode = f.opcode_real_name() + + print 'emit_header(gc->pc, %s, cmdlen);' % (opcode) + + self.pixel_emit_args( f, "gc->pc", 0 ) + print 'gc->pc += cmdlen;' + print 'if (gc->pc > gc->limit) { (void) __glXFlushRenderBuffer(gc, gc->pc); }' + + if f.can_be_large: + print '}' + print 'else {' + + self.large_emit_begin(f, opcode) + self.pixel_emit_args(f, "pc", 1) + + print '}' + + if trailer: print trailer + return + + + def printRenderFunction(self, f): + # There is a class of GL functions that take a single pointer + # as a parameter. This pointer points to a fixed-size chunk + # of data, and the protocol for this functions is very + # regular. Since they are so regular and there are so many + # of them, special case them with generic functions. On + # x86, this saves about 26KB in the libGL.so binary. + + if f.variable_length_parameter() == None and len(f.parameters) == 1: + p = f.parameters[0] + if p.is_pointer(): + cmdlen = f.command_fixed_length() + if cmdlen in self.generic_sizes: + print ' generic_%u_byte( %s, %s );' % (cmdlen, f.opcode_real_name(), p.name) + return + + if self.common_func_print_just_start(f, None): + trailer = " }" + else: + trailer = None + + if self.debug: + print 'printf( "Enter %%s...\\n", "gl%s" );' % (f.name) + + if f.can_be_large: + print 'if (cmdlen <= gc->maxSmallRenderCommandSize) {' + print ' if ( (gc->pc + cmdlen) > gc->bufEnd ) {' + print ' (void) __glXFlushRenderBuffer(gc, gc->pc);' + print ' }' + + print 'emit_header(gc->pc, %s, cmdlen);' % (f.opcode_real_name()) + + self.common_emit_args(f, "gc->pc", 4, 0) + print 'gc->pc += cmdlen;' + print 'if (__builtin_expect(gc->pc > gc->limit, 0)) { (void) __glXFlushRenderBuffer(gc, gc->pc); }' + + if f.can_be_large: + print '}' + print 'else {' + + self.large_emit_begin(f) + self.common_emit_args(f, "pc", 8, 1) + + p = f.variable_length_parameter() + print ' __glXSendLargeCommand(gc, pc, %u, %s, %s);' % (p.offset + 8, p.name, p.size_string()) + print '}' + + if self.debug: + print '__indirect_glFinish();' + print 'printf( "Exit %%s.\\n", "gl%s" );' % (f.name) + + if trailer: print trailer + return + + +class PrintGlxProtoInit_c(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "glX_proto_send.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. +(C) Copyright IBM Corporation 2004""", "PRECISION INSIGHT, IBM") + return + + + def printRealHeader(self): + print """/** + * \\file indirect_init.c + * Initialize indirect rendering dispatch table. + * + * \\author Kevin E. Martin + * \\author Brian Paul + * \\author Ian Romanick + */ + +#include "indirect_init.h" +#include "indirect.h" +#include "glapi.h" + + +/** + * No-op function used to initialize functions that have no GLX protocol + * support. + */ +static int NoOp(void) +{ + return 0; +} + +/** + * Create and initialize a new GL dispatch table. The table is initialized + * with GLX indirect rendering protocol functions. + */ +struct _glapi_table * __glXNewIndirectAPI( void ) +{ + struct _glapi_table *glAPI; + GLuint entries; + + entries = _glapi_get_dispatch_table_size(); + glAPI = (struct _glapi_table *) Xmalloc(entries * sizeof(void *)); + + /* first, set all entries to point to no-op functions */ + { + int i; + void **dispatch = (void **) glAPI; + for (i = 0; i < entries; i++) { + dispatch[i] = (void *) NoOp; + } + } + + /* now, initialize the entries we understand */""" + + def printRealFooter(self): + print """ + return glAPI; +} +""" + return + + + def printBody(self, api): + for [name, number] in api.categoryIterate(): + if number != None: + preamble = '\n /* %3u. %s */\n\n' % (int(number), name) + else: + preamble = '\n /* %s */\n\n' % (name) + + for func in api.functionIterateByCategory(name): + if func.client_supported_for_indirect(): + print '%s glAPI->%s = __indirect_gl%s;' % (preamble, func.name, func.name) + preamble = '' + + return + + +class PrintGlxProtoInit_h(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "glX_proto_send.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. +(C) Copyright IBM Corporation 2004""", "PRECISION INSIGHT, IBM") + self.header_tag = "_INDIRECT_H_" + + self.last_category = "" + return + + + def printRealHeader(self): + print """/** + * \\file + * Prototypes for indirect rendering functions. + * + * \\author Kevin E. Martin + * \\author Ian Romanick + */ +""" + self.printVisibility( "HIDDEN", "hidden" ) + self.printFastcall() + self.printNoinline() + + print """ +#include "glxclient.h" + +extern HIDDEN NOINLINE CARD32 __glXReadReply( Display *dpy, size_t size, + void * dest, GLboolean reply_is_always_array ); + +extern HIDDEN NOINLINE void __glXReadPixelReply( Display *dpy, + struct glx_context * gc, unsigned max_dim, GLint width, GLint height, + GLint depth, GLenum format, GLenum type, void * dest, + GLboolean dimensions_in_reply ); + +extern HIDDEN NOINLINE FASTCALL GLubyte * __glXSetupSingleRequest( + struct glx_context * gc, GLint sop, GLint cmdlen ); + +extern HIDDEN NOINLINE FASTCALL GLubyte * __glXSetupVendorRequest( + struct glx_context * gc, GLint code, GLint vop, GLint cmdlen ); +""" + + + def printBody(self, api): + for func in api.functionIterateGlx(): + params = func.get_parameter_string() + + print 'extern HIDDEN %s __indirect_gl%s(%s);' % (func.return_type, func.name, params) + + for n in func.entry_points: + if func.has_different_protocol(n): + asdf = func.static_glx_name(n) + if asdf not in func.static_entry_points: + print 'extern HIDDEN %s gl%s(%s);' % (func.return_type, asdf, params) + # give it a easy-to-remember name + if func.client_handcode: + print '#define gl_dispatch_stub_%s gl%s' % (n, asdf) + else: + print 'GLAPI %s GLAPIENTRY gl%s(%s);' % (func.return_type, asdf, params) + + break + + + +def show_usage(): + print "Usage: %s [-f input_file_name] [-m output_mode] [-d]" % sys.argv[0] + print " -m output_mode Output mode can be one of 'proto', 'init_c' or 'init_h'." + print " -d Enable extra debug information in the generated code." + sys.exit(1) + + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:m:d") + except Exception,e: + show_usage() + + debug = 0 + mode = "proto" + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-m": + mode = val + elif arg == "-d": + debug = 1 + + if mode == "proto": + printer = PrintGlxProtoStubs() + elif mode == "init_c": + printer = PrintGlxProtoInit_c() + elif mode == "init_h": + printer = PrintGlxProtoInit_h() + else: + show_usage() + + + printer.debug = debug + api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() ) + + printer.Print( api ) diff --git a/src/mapi/glapi/gen/glX_proto_size.py b/src/mapi/glapi/gen/glX_proto_size.py new file mode 100644 index 0000000..f16ea4c --- /dev/null +++ b/src/mapi/glapi/gen/glX_proto_size.py @@ -0,0 +1,704 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import gl_XML, glX_XML +import license +import sys, getopt, copy, string + + +class glx_enum_function: + def __init__(self, func_name, enum_dict): + self.name = func_name + self.mode = 1 + self.sig = None + + # "enums" is a set of lists. The element in the set is the + # value of the enum. The list is the list of names for that + # value. For example, [0x8126] = {"POINT_SIZE_MIN", + # "POINT_SIZE_MIN_ARB", "POINT_SIZE_MIN_EXT", + # "POINT_SIZE_MIN_SGIS"}. + + self.enums = {} + + # "count" is indexed by count values. Each element of count + # is a list of index to "enums" that have that number of + # associated data elements. For example, [4] = + # {GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION, + # GL_AMBIENT_AND_DIFFUSE} (the enum names are used here, + # but the actual hexadecimal values would be in the array). + + self.count = {} + + + # Fill self.count and self.enums using the dictionary of enums + # that was passed in. The generic Get functions (e.g., + # GetBooleanv and friends) are handled specially here. In + # the data the generic Get functions are refered to as "Get". + + if func_name in ["GetIntegerv", "GetBooleanv", "GetFloatv", "GetDoublev"]: + match_name = "Get" + else: + match_name = func_name + + mode_set = 0 + for enum_name in enum_dict: + e = enum_dict[ enum_name ] + + if e.functions.has_key( match_name ): + [count, mode] = e.functions[ match_name ] + + if mode_set and mode != self.mode: + raise RuntimeError("Not all enums for %s have the same mode." % (func_name)) + + self.mode = mode + + if self.enums.has_key( e.value ): + if e.name not in self.enums[ e.value ]: + self.enums[ e.value ].append( e ) + else: + if not self.count.has_key( count ): + self.count[ count ] = [] + + self.enums[ e.value ] = [ e ] + self.count[ count ].append( e.value ) + + + return + + + def signature( self ): + if self.sig == None: + self.sig = "" + for i in self.count: + if i == None: + raise RuntimeError("i is None. WTF?") + + self.count[i].sort() + for e in self.count[i]: + self.sig += "%04x,%d," % (e, i) + + return self.sig + + + def is_set( self ): + return self.mode + + + def PrintUsingTable(self): + """Emit the body of the __gl*_size function using a pair + of look-up tables and a mask. The mask is calculated such + that (e & mask) is unique for all the valid values of e for + this function. The result of (e & mask) is used as an index + into the first look-up table. If it matches e, then the + same entry of the second table is returned. Otherwise zero + is returned. + + It seems like this should cause better code to be generated. + However, on x86 at least, the resulting .o file is about 20% + larger then the switch-statment version. I am leaving this + code in because the results may be different on other + platforms (e.g., PowerPC or x86-64).""" + + return 0 + count = 0 + for a in self.enums: + count += 1 + + if self.count.has_key(-1): + return 0 + + # Determine if there is some mask M, such that M = (2^N) - 1, + # that will generate unique values for all of the enums. + + mask = 0 + for i in [1, 2, 3, 4, 5, 6, 7, 8]: + mask = (1 << i) - 1 + + fail = 0; + for a in self.enums: + for b in self.enums: + if a != b: + if (a & mask) == (b & mask): + fail = 1; + + if not fail: + break; + else: + mask = 0 + + if (mask != 0) and (mask < (2 * count)): + masked_enums = {} + masked_count = {} + + for i in range(0, mask + 1): + masked_enums[i] = "0"; + masked_count[i] = 0; + + for c in self.count: + for e in self.count[c]: + i = e & mask + enum_obj = self.enums[e][0] + masked_enums[i] = '0x%04x /* %s */' % (e, enum_obj.name ) + masked_count[i] = c + + + print ' static const GLushort a[%u] = {' % (mask + 1) + for e in masked_enums: + print ' %s, ' % (masked_enums[e]) + print ' };' + + print ' static const GLubyte b[%u] = {' % (mask + 1) + for c in masked_count: + print ' %u, ' % (masked_count[c]) + print ' };' + + print ' const unsigned idx = (e & 0x%02xU);' % (mask) + print '' + print ' return (e == a[idx]) ? (GLint) b[idx] : 0;' + return 1; + else: + return 0; + + + def PrintUsingSwitch(self, name): + """Emit the body of the __gl*_size function using a + switch-statement.""" + + print ' switch( e ) {' + + for c in self.count: + for e in self.count[c]: + first = 1 + + # There may be multiple enums with the same + # value. This happens has extensions are + # promoted from vendor-specific or EXT to + # ARB and to the core. Emit the first one as + # a case label, and emit the others as + # commented-out case labels. + + list = {} + for enum_obj in self.enums[e]: + list[ enum_obj.priority() ] = enum_obj.name + + keys = list.keys() + keys.sort() + for k in keys: + j = list[k] + if first: + print ' case GL_%s:' % (j) + first = 0 + else: + print '/* case GL_%s:*/' % (j) + + if c == -1: + print ' return __gl%s_variable_size( e );' % (name) + else: + print ' return %u;' % (c) + + print ' default: return 0;' + print ' }' + + + def Print(self, name): + print 'INTERNAL PURE FASTCALL GLint' + print '__gl%s_size( GLenum e )' % (name) + print '{' + + if not self.PrintUsingTable(): + self.PrintUsingSwitch(name) + + print '}' + print '' + + +class glx_server_enum_function(glx_enum_function): + def __init__(self, func, enum_dict): + glx_enum_function.__init__(self, func.name, enum_dict) + + self.function = func + return + + + def signature( self ): + if self.sig == None: + sig = glx_enum_function.signature(self) + + p = self.function.variable_length_parameter() + if p: + sig += "%u" % (p.size()) + + self.sig = sig + + return self.sig; + + + def Print(self, name, printer): + f = self.function + printer.common_func_print_just_header( f ) + + fixup = [] + + foo = {} + for param_name in f.count_parameter_list: + o = f.offset_of( param_name ) + foo[o] = param_name + + for param_name in f.counter_list: + o = f.offset_of( param_name ) + foo[o] = param_name + + keys = foo.keys() + keys.sort() + for o in keys: + p = f.parameters_by_name[ foo[o] ] + + printer.common_emit_one_arg(p, "pc", 0) + fixup.append( p.name ) + + + print ' GLsizei compsize;' + print '' + + printer.common_emit_fixups(fixup) + + print '' + print ' compsize = __gl%s_size(%s);' % (f.name, string.join(f.count_parameter_list, ",")) + p = f.variable_length_parameter() + print ' return __GLX_PAD(%s);' % (p.size_string()) + + print '}' + print '' + + +class PrintGlxSizeStubs_common(gl_XML.gl_print_base): + do_get = (1 << 0) + do_set = (1 << 1) + + def __init__(self, which_functions): + gl_XML.gl_print_base.__init__(self) + + self.name = "glX_proto_size.py (from Mesa)" + self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004", "IBM") + + self.emit_set = ((which_functions & PrintGlxSizeStubs_common.do_set) != 0) + self.emit_get = ((which_functions & PrintGlxSizeStubs_common.do_get) != 0) + return + + +class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common): + def printRealHeader(self): + print '' + print '#include ' + if self.emit_get: + print '#include "indirect_size_get.h"' + print '#include "glxserver.h"' + print '#include "indirect_util.h"' + + print '#include "indirect_size.h"' + + print '' + self.printPure() + print '' + self.printFastcall() + print '' + self.printVisibility( "INTERNAL", "internal" ) + print '' + print '' + print '#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(GLX_USE_APPLEGL)' + print '# undef HAVE_ALIAS' + print '#endif' + print '#ifdef HAVE_ALIAS' + print '# define ALIAS2(from,to) \\' + print ' INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\' + print ' __attribute__ ((alias( # to )));' + print '# define ALIAS(from,to) ALIAS2( from, __gl ## to ## _size )' + print '#else' + print '# define ALIAS(from,to) \\' + print ' INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\' + print ' { return __gl ## to ## _size( e ); }' + print '#endif' + print '' + print '' + + + def printBody(self, api): + enum_sigs = {} + aliases = [] + + for func in api.functionIterateGlx(): + ef = glx_enum_function( func.name, api.enums_by_name ) + if len(ef.enums) == 0: + continue + + if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get): + sig = ef.signature() + if enum_sigs.has_key( sig ): + aliases.append( [func.name, enum_sigs[ sig ]] ) + else: + enum_sigs[ sig ] = func.name + ef.Print( func.name ) + + + for [alias_name, real_name] in aliases: + print 'ALIAS( %s, %s )' % (alias_name, real_name) + + + +class PrintGlxSizeStubs_h(PrintGlxSizeStubs_common): + def printRealHeader(self): + print """/** + * \\file + * Prototypes for functions used to determine the number of data elements in + * various GLX protocol messages. + * + * \\author Ian Romanick + */ +""" + self.printPure(); + print '' + self.printFastcall(); + print '' + self.printVisibility( "INTERNAL", "internal" ); + print '' + + + def printBody(self, api): + for func in api.functionIterateGlx(): + ef = glx_enum_function( func.name, api.enums_by_name ) + if len(ef.enums) == 0: + continue + + if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get): + print 'extern INTERNAL PURE FASTCALL GLint __gl%s_size(GLenum);' % (func.name) + + +class PrintGlxReqSize_common(gl_XML.gl_print_base): + """Common base class for PrintGlxSizeReq_h and PrintGlxSizeReq_h. + + The main purpose of this common base class is to provide the infrastructure + for the derrived classes to iterate over the same set of functions. + """ + + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "glX_proto_size.py (from Mesa)" + self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM") + + +class PrintGlxReqSize_h(PrintGlxReqSize_common): + def __init__(self): + PrintGlxReqSize_common.__init__(self) + self.header_tag = "_INDIRECT_REQSIZE_H_" + + + def printRealHeader(self): + self.printVisibility("HIDDEN", "hidden") + print '' + self.printPure() + print '' + + + def printBody(self, api): + for func in api.functionIterateGlx(): + if not func.ignore and func.has_variable_size_request(): + print 'extern PURE HIDDEN int __glX%sReqSize(const GLbyte *pc, Bool swap);' % (func.name) + + +class PrintGlxReqSize_c(PrintGlxReqSize_common): + """Create the server-side 'request size' functions. + + Create the server-side functions that are used to determine what the + size of a varible length command should be. The server then uses + this value to determine if the incoming command packed it malformed. + """ + + def __init__(self): + PrintGlxReqSize_common.__init__(self) + self.counter_sigs = {} + + + def printRealHeader(self): + print '' + print '#include ' + print '#include "glxserver.h"' + print '#include "glxbyteorder.h"' + print '#include "indirect_size.h"' + print '#include "indirect_reqsize.h"' + print '' + print '#define __GLX_PAD(x) (((x) + 3) & ~3)' + print '' + print '#if defined(__CYGWIN__) || defined(__MINGW32__)' + print '# undef HAVE_ALIAS' + print '#endif' + print '#ifdef HAVE_ALIAS' + print '# define ALIAS2(from,to) \\' + print ' GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap ) \\' + print ' __attribute__ ((alias( # to )));' + print '# define ALIAS(from,to) ALIAS2( from, __glX ## to ## ReqSize )' + print '#else' + print '# define ALIAS(from,to) \\' + print ' GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap ) \\' + print ' { return __glX ## to ## ReqSize( pc, swap ); }' + print '#endif' + print '' + print '' + + + def printBody(self, api): + aliases = [] + enum_functions = {} + enum_sigs = {} + + for func in api.functionIterateGlx(): + if not func.has_variable_size_request(): continue + + ef = glx_server_enum_function( func, api.enums_by_name ) + if len(ef.enums) == 0: continue + + sig = ef.signature() + + if not enum_functions.has_key(func.name): + enum_functions[ func.name ] = sig + + if not enum_sigs.has_key( sig ): + enum_sigs[ sig ] = ef + + + + for func in api.functionIterateGlx(): + # Even though server-handcode fuctions are on "the + # list", and prototypes are generated for them, there + # isn't enough information to generate a size + # function. If there was enough information, they + # probably wouldn't need to be handcoded in the first + # place! + + if func.server_handcode: continue + if not func.has_variable_size_request(): continue + + if enum_functions.has_key(func.name): + sig = enum_functions[func.name] + ef = enum_sigs[ sig ] + + if ef.name != func.name: + aliases.append( [func.name, ef.name] ) + else: + ef.Print( func.name, self ) + + elif func.images: + self.printPixelFunction(func) + elif func.has_variable_size_request(): + a = self.printCountedFunction(func) + if a: aliases.append(a) + + + for [alias_name, real_name] in aliases: + print 'ALIAS( %s, %s )' % (alias_name, real_name) + + return + + + def common_emit_fixups(self, fixup): + """Utility function to emit conditional byte-swaps.""" + + if fixup: + print ' if (swap) {' + for name in fixup: + print ' %s = bswap_32(%s);' % (name, name) + print ' }' + + return + + + def common_emit_one_arg(self, p, pc, adjust): + offset = p.offset + dst = p.string() + src = '(%s *)' % (p.type_string()) + print '%-18s = *%11s(%s + %u);' % (dst, src, pc, offset + adjust); + return + + + def common_func_print_just_header(self, f): + print 'int' + print '__glX%sReqSize( const GLbyte * pc, Bool swap )' % (f.name) + print '{' + + + def printPixelFunction(self, f): + self.common_func_print_just_header(f) + + f.offset_of( f.parameters[0].name ) + [dim, w, h, d, junk] = f.get_images()[0].get_dimensions() + + print ' GLint row_length = * (GLint *)(pc + 4);' + + if dim < 3: + fixup = ['row_length', 'skip_rows', 'alignment'] + print ' GLint image_height = 0;' + print ' GLint skip_images = 0;' + print ' GLint skip_rows = * (GLint *)(pc + 8);' + print ' GLint alignment = * (GLint *)(pc + 16);' + else: + fixup = ['row_length', 'image_height', 'skip_rows', 'skip_images', 'alignment'] + print ' GLint image_height = * (GLint *)(pc + 8);' + print ' GLint skip_rows = * (GLint *)(pc + 16);' + print ' GLint skip_images = * (GLint *)(pc + 20);' + print ' GLint alignment = * (GLint *)(pc + 32);' + + img = f.images[0] + for p in f.parameterIterateGlxSend(): + if p.name in [w, h, d, img.img_format, img.img_type, img.img_target]: + self.common_emit_one_arg(p, "pc", 0) + fixup.append( p.name ) + + print '' + + self.common_emit_fixups(fixup) + + if img.img_null_flag: + print '' + print ' if (*(CARD32 *) (pc + %s))' % (img.offset - 4) + print ' return 0;' + + print '' + print ' return __glXImageSize(%s, %s, %s, %s, %s, %s,' % (img.img_format, img.img_type, img.img_target, w, h, d ) + print ' image_height, row_length, skip_images,' + print ' skip_rows, alignment);' + print '}' + print '' + return + + + def printCountedFunction(self, f): + + sig = "" + offset = 0 + fixup = [] + params = [] + plus = '' + size = '' + param_offsets = {} + + # Calculate the offset of each counter parameter and the + # size string for the variable length parameter(s). While + # that is being done, calculate a unique signature for this + # function. + + for p in f.parameterIterateGlxSend(): + if p.is_counter: + fixup.append( p.name ) + params.append( p ) + elif p.counter: + s = p.size() + if s == 0: s = 1 + + sig += "(%u,%u)" % (f.offset_of(p.counter), s) + size += '%s%s' % (plus, p.size_string()) + plus = ' + ' + + + # If the calculated signature matches a function that has + # already be emitted, don't emit this function. Instead, add + # it to the list of function aliases. + + if self.counter_sigs.has_key(sig): + n = self.counter_sigs[sig]; + alias = [f.name, n] + else: + alias = None + self.counter_sigs[sig] = f.name + + self.common_func_print_just_header(f) + + for p in params: + self.common_emit_one_arg(p, "pc", 0) + + + print '' + self.common_emit_fixups(fixup) + print '' + + print ' return __GLX_PAD(%s);' % (size) + print '}' + print '' + + return alias + + +def show_usage(): + print "Usage: %s [-f input_file_name] -m output_mode [--only-get | --only-set] [--get-alias-set]" % sys.argv[0] + print " -m output_mode Output mode can be one of 'size_c' or 'size_h'." + print " --only-get Only emit 'get'-type functions." + print " --only-set Only emit 'set'-type functions." + print "" + print "By default, both 'get' and 'set'-type functions are emitted." + sys.exit(1) + + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:m:h:", ["only-get", "only-set", "header-tag"]) + except Exception,e: + show_usage() + + mode = None + header_tag = None + which_functions = PrintGlxSizeStubs_common.do_get | PrintGlxSizeStubs_common.do_set + + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-m": + mode = val + elif arg == "--only-get": + which_functions = PrintGlxSizeStubs_common.do_get + elif arg == "--only-set": + which_functions = PrintGlxSizeStubs_common.do_set + elif (arg == '-h') or (arg == "--header-tag"): + header_tag = val + + if mode == "size_c": + printer = PrintGlxSizeStubs_c( which_functions ) + elif mode == "size_h": + printer = PrintGlxSizeStubs_h( which_functions ) + if header_tag: + printer.header_tag = header_tag + elif mode == "reqsize_c": + printer = PrintGlxReqSize_c() + elif mode == "reqsize_h": + printer = PrintGlxReqSize_h() + else: + show_usage() + + api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() ) + + + printer.Print( api ) diff --git a/src/mapi/glapi/gen/glX_server_table.py b/src/mapi/glapi/gen/glX_server_table.py new file mode 100644 index 0000000..f3962f8 --- /dev/null +++ b/src/mapi/glapi/gen/glX_server_table.py @@ -0,0 +1,411 @@ +#!/bin/env python + +# (C) Copyright IBM Corporation 2005, 2006 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import gl_XML, glX_XML, glX_proto_common, license +import sys, getopt + + +def log2(value): + for i in range(0, 30): + p = 1 << i + if p >= value: + return i + + return -1 + + +def round_down_to_power_of_two(n): + """Returns the nearest power-of-two less than or equal to n.""" + + for i in range(30, 0, -1): + p = 1 << i + if p <= n: + return p + + return -1 + + +class function_table: + def __init__(self, name, do_size_check): + self.name_base = name + self.do_size_check = do_size_check + + + self.max_bits = 1 + self.next_opcode_threshold = (1 << self.max_bits) + self.max_opcode = 0 + + self.functions = {} + self.lookup_table = [] + + # Minimum number of opcodes in a leaf node. + self.min_op_bits = 3 + self.min_op_count = (1 << self.min_op_bits) + return + + + def append(self, opcode, func): + self.functions[opcode] = func + + if opcode > self.max_opcode: + self.max_opcode = opcode + + if opcode > self.next_opcode_threshold: + bits = log2(opcode) + if (1 << bits) <= opcode: + bits += 1 + + self.max_bits = bits + self.next_opcode_threshold = 1 << bits + return + + + def divide_group(self, min_opcode, total): + """Divide the group starting min_opcode into subgroups. + Returns a tuple containing the number of bits consumed by + the node, the list of the children's tuple, and the number + of entries in the final array used by this node and its + children, and the depth of the subtree rooted at the node.""" + + remaining_bits = self.max_bits - total + next_opcode = min_opcode + (1 << remaining_bits) + empty_children = 0 + + for M in range(0, remaining_bits): + op_count = 1 << (remaining_bits - M); + child_count = 1 << M; + + empty_children = 0 + full_children = 0 + for i in range(min_opcode, next_opcode, op_count): + used = 0 + empty = 0 + + for j in range(i, i + op_count): + if self.functions.has_key(j): + used += 1; + else: + empty += 1; + + + if empty == op_count: + empty_children += 1 + + if used == op_count: + full_children += 1 + + if (empty_children > 0) or (full_children == child_count) or (op_count <= self.min_op_count): + break + + + # If all the remaining bits are used by this node, as is the + # case when M is 0 or remaining_bits, the node is a leaf. + + if (M == 0) or (M == remaining_bits): + return [remaining_bits, [], 0, 0] + else: + children = [] + count = 1 + depth = 1 + all_children_are_nonempty_leaf_nodes = 1 + for i in range(min_opcode, next_opcode, op_count): + n = self.divide_group(i, total + M) + + if not (n[1] == [] and not self.is_empty_leaf(i, n[0])): + all_children_are_nonempty_leaf_nodes = 0 + + children.append(n) + count += n[2] + 1 + + if n[3] >= depth: + depth = n[3] + 1 + + # If all of the child nodes are non-empty leaf nodes, pull + # them up and make this node a leaf. + + if all_children_are_nonempty_leaf_nodes: + return [remaining_bits, [], 0, 0] + else: + return [M, children, count, depth] + + + def is_empty_leaf(self, base_opcode, M): + for op in range(base_opcode, base_opcode + (1 << M)): + if self.functions.has_key(op): + return 0 + break + + return 1 + + + def dump_tree(self, node, base_opcode, remaining_bits, base_entry, depth): + M = node[0] + children = node[1] + child_M = remaining_bits - M + + + # This actually an error condition. + if children == []: + return + + print ' /* [%u] -> opcode range [%u, %u], node depth %u */' % (base_entry, base_opcode, base_opcode + (1 << remaining_bits), depth) + print ' %u,' % (M) + + base_entry += (1 << M) + 1 + + child_index = base_entry + child_base_opcode = base_opcode + for child in children: + if child[1] == []: + if self.is_empty_leaf(child_base_opcode, child_M): + print ' EMPTY_LEAF,' + else: + # Emit the index of the next dispatch + # function. Then add all the + # dispatch functions for this leaf + # node to the dispatch function + # lookup table. + + print ' LEAF(%u),' % (len(self.lookup_table)) + + for op in range(child_base_opcode, child_base_opcode + (1 << child_M)): + if self.functions.has_key(op): + func = self.functions[op] + size = func.command_fixed_length() + + if func.glx_rop != 0: + size += 4 + + size = ((size + 3) & ~3) + + if func.has_variable_size_request(): + size_name = "__glX%sReqSize" % (func.name) + else: + size_name = "" + + if func.glx_vendorpriv == op: + func_name = func.glx_vendorpriv_names[0] + else: + func_name = func.name + + temp = [op, "__glXDisp_%s" % (func_name), "__glXDispSwap_%s" % (func_name), size, size_name] + else: + temp = [op, "NULL", "NULL", 0, ""] + + self.lookup_table.append(temp) + else: + print ' %u,' % (child_index) + child_index += child[2] + + child_base_opcode += 1 << child_M + + print '' + + child_index = base_entry + for child in children: + if child[1] != []: + self.dump_tree(child, base_opcode, remaining_bits - M, child_index, depth + 1) + child_index += child[2] + + base_opcode += 1 << (remaining_bits - M) + + + def Print(self): + # Each dispatch table consists of two data structures. + # + # The first structure is an N-way tree where the opcode for + # the function is the key. Each node switches on a range of + # bits from the opcode. M bits are extracted from the opcde + # and are used as an index to select one of the N, where + # N = 2^M, children. + # + # The tree is stored as a flat array. The first value is the + # number of bits, M, used by the node. For inner nodes, the + # following 2^M values are indexes into the array for the + # child nodes. For leaf nodes, the followign 2^M values are + # indexes into the second data structure. + # + # If an inner node's child index is 0, the child is an empty + # leaf node. That is, none of the opcodes selectable from + # that child exist. Since most of the possible opcode space + # is unused, this allows compact data storage. + # + # The second data structure is an array of pairs of function + # pointers. Each function contains a pointer to a protocol + # decode function and a pointer to a byte-swapped protocol + # decode function. Elements in this array are selected by the + # leaf nodes of the first data structure. + # + # As the tree is traversed, an accumulator is kept. This + # accumulator counts the bits of the opcode consumed by the + # traversal. When accumulator + M = B, where B is the + # maximum number of bits in an opcode, the traversal has + # reached a leaf node. The traversal starts with the most + # significant bits and works down to the least significant + # bits. + # + # Creation of the tree is the most complicated part. At + # each node the elements are divided into groups of 2^M + # elements. The value of M selected is the smallest possible + # value where all of the groups are either empty or full, or + # the groups are a preset minimum size. If all the children + # of a node are non-empty leaf nodes, the children are merged + # to create a single leaf node that replaces the parent. + + tree = self.divide_group(0, 0) + + print '/*****************************************************************/' + print '/* tree depth = %u */' % (tree[3]) + print 'static const int_fast16_t %s_dispatch_tree[%u] = {' % (self.name_base, tree[2]) + self.dump_tree(tree, 0, self.max_bits, 0, 1) + print '};\n' + + # After dumping the tree, dump the function lookup table. + + print 'static const void *%s_function_table[%u][2] = {' % (self.name_base, len(self.lookup_table)) + index = 0 + for func in self.lookup_table: + opcode = func[0] + name = func[1] + name_swap = func[2] + + print ' /* [% 3u] = %5u */ {%s, %s},' % (index, opcode, name, name_swap) + + index += 1 + + print '};\n' + + if self.do_size_check: + var_table = [] + + print 'static const int_fast16_t %s_size_table[%u][2] = {' % (self.name_base, len(self.lookup_table)) + index = 0 + var_table = [] + for func in self.lookup_table: + opcode = func[0] + fixed = func[3] + var = func[4] + + if var != "": + var_offset = "%2u" % (len(var_table)) + var_table.append(var) + else: + var_offset = "~0" + + print ' /* [%3u] = %5u */ {%3u, %s},' % (index, opcode, fixed, var_offset) + index += 1 + + + print '};\n' + + + print 'static const gl_proto_size_func %s_size_func_table[%u] = {' % (self.name_base, len(var_table)) + for func in var_table: + print ' %s,' % (func) + + print '};\n' + + + print 'const struct __glXDispatchInfo %s_dispatch_info = {' % (self.name_base) + print ' %u,' % (self.max_bits) + print ' %s_dispatch_tree,' % (self.name_base) + print ' %s_function_table,' % (self.name_base) + if self.do_size_check: + print ' %s_size_table,' % (self.name_base) + print ' %s_size_func_table' % (self.name_base) + else: + print ' NULL,' + print ' NULL' + print '};\n' + return + + +class PrintGlxDispatchTables(glX_proto_common.glx_print_proto): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + self.name = "glX_server_table.py (from Mesa)" + self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005, 2006", "IBM") + + self.rop_functions = function_table("Render", 1) + self.sop_functions = function_table("Single", 0) + self.vop_functions = function_table("VendorPriv", 0) + return + + + def printRealHeader(self): + print '#include ' + print '#include "glxserver.h"' + print '#include "glxext.h"' + print '#include "indirect_dispatch.h"' + print '#include "indirect_reqsize.h"' + print '#include "g_disptab.h"' + print '#include "indirect_table.h"' + print '' + return + + + def printBody(self, api): + for f in api.functionIterateAll(): + if not f.ignore and f.vectorequiv == None: + if f.glx_rop != 0: + self.rop_functions.append(f.glx_rop, f) + if f.glx_sop != 0: + self.sop_functions.append(f.glx_sop, f) + if f.glx_vendorpriv != 0: + self.vop_functions.append(f.glx_vendorpriv, f) + + self.sop_functions.Print() + self.rop_functions.Print() + self.vop_functions.Print() + return + + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:m") + except Exception,e: + show_usage() + + mode = "table_c" + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-m": + mode = val + + if mode == "table_c": + printer = PrintGlxDispatchTables() + else: + show_usage() + + + api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() ) + + + printer.Print( api ) diff --git a/src/mapi/glapi/gen/gl_API.dtd b/src/mapi/glapi/gen/gl_API.dtd new file mode 100644 index 0000000..30c646c --- /dev/null +++ b/src/mapi/glapi/gen/gl_API.dtd @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml new file mode 100644 index 0000000..0fc44b5 --- /dev/null +++ b/src/mapi/glapi/gen/gl_API.xml @@ -0,0 +1,12527 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/gl_SPARC_asm.py b/src/mapi/glapi/gen/gl_SPARC_asm.py new file mode 100644 index 0000000..400e684 --- /dev/null +++ b/src/mapi/glapi/gen/gl_SPARC_asm.py @@ -0,0 +1,273 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import license +import gl_XML, glX_XML +import sys, getopt + +class PrintGenericStubs(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + self.name = "gl_SPARC_asm.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright (C) 1999-2003 Brian Paul All Rights Reserved. +(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") + + + def printRealHeader(self): + print '#ifdef __arch64__' + print '#define GL_OFF(N)\t((N) * 8)' + print '#define GL_LL\t\tldx' + print '#define GL_TIE_LD(SYM)\t%tie_ldx(SYM)' + print '#define GL_STACK_SIZE\t128' + print '#else' + print '#define GL_OFF(N)\t((N) * 4)' + print '#define GL_LL\t\tld' + print '#define GL_TIE_LD(SYM)\t%tie_ld(SYM)' + print '#define GL_STACK_SIZE\t64' + print '#endif' + print '' + print '#define GLOBL_FN(x) .globl x ; .type x, @function' + print '#define HIDDEN(x) .hidden x' + print '' + print '\t.register %g2, #scratch' + print '\t.register %g3, #scratch' + print '' + print '\t.text' + print '' + print '\tGLOBL_FN(__glapi_sparc_icache_flush)' + print '\tHIDDEN(__glapi_sparc_icache_flush)' + print '\t.type\t__glapi_sparc_icache_flush, @function' + print '__glapi_sparc_icache_flush: /* %o0 = insn_addr */' + print '\tflush\t%o0' + print '\tretl' + print '\t nop' + print '' + print '\t.align\t32' + print '' + print '\t.type\t__glapi_sparc_get_pc, @function' + print '__glapi_sparc_get_pc:' + print '\tretl' + print '\t add\t%o7, %g2, %g2' + print '\t.size\t__glapi_sparc_get_pc, .-__glapi_sparc_get_pc' + print '' + print '#ifdef GLX_USE_TLS' + print '' + print '\tGLOBL_FN(__glapi_sparc_get_dispatch)' + print '\tHIDDEN(__glapi_sparc_get_dispatch)' + print '__glapi_sparc_get_dispatch:' + print '\tmov\t%o7, %g1' + print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' + print '\tcall\t__glapi_sparc_get_pc' + print '\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' + print '\tmov\t%g1, %o7' + print '\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1' + print '\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1' + print '\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)' + print '\tretl' + print '\t mov\t%g2, %o0' + print '' + print '\t.data' + print '\t.align\t32' + print '' + print '\t/* --> sethi %hi(_glapi_tls_Dispatch), %g1 */' + print '\t/* --> or %g1, %lo(_glapi_tls_Dispatch), %g1 */' + print '\tGLOBL_FN(__glapi_sparc_tls_stub)' + print '\tHIDDEN(__glapi_sparc_tls_stub)' + print '__glapi_sparc_tls_stub: /* Call offset in %g3 */' + print '\tmov\t%o7, %g1' + print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' + print '\tcall\t__glapi_sparc_get_pc' + print '\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' + print '\tmov\t%g1, %o7' + print '\tsrl\t%g3, 10, %g3' + print '\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1' + print '\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1' + print '\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)' + print '\tGL_LL\t[%g7+%g2], %g1' + print '\tGL_LL\t[%g1 + %g3], %g1' + print '\tjmp\t%g1' + print '\t nop' + print '\t.size\t__glapi_sparc_tls_stub, .-__glapi_sparc_tls_stub' + print '' + print '#define GL_STUB(fn, off)\t\t\t\t\\' + print '\tGLOBL_FN(fn);\t\t\t\t\t\\' + print 'fn:\tba\t__glapi_sparc_tls_stub;\t\t\t\\' + print '\t sethi\tGL_OFF(off), %g3;\t\t\t\\' + print '\t.size\tfn,.-fn;' + print '' + print '#elif defined(PTHREADS)' + print '' + print '\t/* 64-bit 0x00 --> sethi %hh(_glapi_Dispatch), %g1 */' + print '\t/* 64-bit 0x04 --> sethi %lm(_glapi_Dispatch), %g2 */' + print '\t/* 64-bit 0x08 --> or %g1, %hm(_glapi_Dispatch), %g1 */' + print '\t/* 64-bit 0x0c --> sllx %g1, 32, %g1 */' + print '\t/* 64-bit 0x10 --> add %g1, %g2, %g1 */' + print '\t/* 64-bit 0x14 --> ldx [%g1 + %lo(_glapi_Dispatch)], %g1 */' + print '' + print '\t/* 32-bit 0x00 --> sethi %hi(_glapi_Dispatch), %g1 */' + print '\t/* 32-bit 0x04 --> ld [%g1 + %lo(_glapi_Dispatch)], %g1 */' + print '' + print '\t.data' + print '\t.align\t32' + print '' + print '\tGLOBL_FN(__glapi_sparc_pthread_stub)' + print '\tHIDDEN(__glapi_sparc_pthread_stub)' + print '__glapi_sparc_pthread_stub: /* Call offset in %g3 */' + print '\tmov\t%o7, %g1' + print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' + print '\tcall\t__glapi_sparc_get_pc' + print '\t add\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' + print '\tmov\t%g1, %o7' + print '\tsethi\t%hi(_glapi_Dispatch), %g1' + print '\tor\t%g1, %lo(_glapi_Dispatch), %g1' + print '\tsrl\t%g3, 10, %g3' + print '\tGL_LL\t[%g2+%g1], %g2' + print '\tGL_LL\t[%g2], %g1' + print '\tcmp\t%g1, 0' + print '\tbe\t2f' + print '\t nop' + print '1:\tGL_LL\t[%g1 + %g3], %g1' + print '\tjmp\t%g1' + print '\t nop' + print '2:\tsave\t%sp, GL_STACK_SIZE, %sp' + print '\tmov\t%g3, %l0' + print '\tcall\t_glapi_get_dispatch' + print '\t nop' + print '\tmov\t%o0, %g1' + print '\tmov\t%l0, %g3' + print '\tba\t1b' + print '\t restore %g0, %g0, %g0' + print '\t.size\t__glapi_sparc_pthread_stub, .-__glapi_sparc_pthread_stub' + print '' + print '#define GL_STUB(fn, off)\t\t\t\\' + print '\tGLOBL_FN(fn);\t\t\t\t\\' + print 'fn:\tba\t__glapi_sparc_pthread_stub;\t\\' + print '\t sethi\tGL_OFF(off), %g3;\t\t\\' + print '\t.size\tfn,.-fn;' + print '' + print '#else /* Non-threaded version. */' + print '' + print '\t.type __glapi_sparc_nothread_stub, @function' + print '__glapi_sparc_nothread_stub: /* Call offset in %g3 */' + print '\tmov\t%o7, %g1' + print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2' + print '\tcall\t__glapi_sparc_get_pc' + print '\t add\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2' + print '\tmov\t%g1, %o7' + print '\tsrl\t%g3, 10, %g3' + print '\tsethi\t%hi(_glapi_Dispatch), %g1' + print '\tor\t%g1, %lo(_glapi_Dispatch), %g1' + print '\tGL_LL\t[%g2+%g1], %g2' + print '\tGL_LL\t[%g2], %g1' + print '\tGL_LL\t[%g1 + %g3], %g1' + print '\tjmp\t%g1' + print '\t nop' + print '\t.size\t__glapi_sparc_nothread_stub, .-__glapi_sparc_nothread_stub' + print '' + print '#define GL_STUB(fn, off)\t\t\t\\' + print '\tGLOBL_FN(fn);\t\t\t\t\\' + print 'fn:\tba\t__glapi_sparc_nothread_stub;\t\\' + print '\t sethi\tGL_OFF(off), %g3;\t\t\\' + print '\t.size\tfn,.-fn;' + print '' + print '#endif' + print '' + print '#define GL_STUB_ALIAS(fn, alias) \\' + print ' .globl fn; \\' + print ' .set fn, alias' + print '' + print '\t.text' + print '\t.align\t32' + print '' + print '\t.globl\tgl_dispatch_functions_start' + print '\tHIDDEN(gl_dispatch_functions_start)' + print 'gl_dispatch_functions_start:' + print '' + return + + def printRealFooter(self): + print '' + print '\t.globl\tgl_dispatch_functions_end' + print '\tHIDDEN(gl_dispatch_functions_end)' + print 'gl_dispatch_functions_end:' + return + + def printBody(self, api): + for f in api.functionIterateByOffset(): + name = f.dispatch_name() + + print '\tGL_STUB(gl%s, %d)' % (name, f.offset) + + if not f.is_static_entry_point(f.name): + print '\tHIDDEN(gl%s)' % (name) + + for f in api.functionIterateByOffset(): + name = f.dispatch_name() + + if f.is_static_entry_point(f.name): + for n in f.entry_points: + if n != f.name: + text = '\tGL_STUB_ALIAS(gl%s, gl%s)' % (n, f.name) + + if f.has_different_protocol(n): + print '#ifndef GLX_INDIRECT_RENDERING' + print text + print '#endif' + else: + print text + + return + + +def show_usage(): + print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0] + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + mode = "generic" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "m:f:") + except Exception,e: + show_usage() + + for (arg,val) in args: + if arg == '-m': + mode = val + elif arg == "-f": + file_name = val + + if mode == "generic": + printer = PrintGenericStubs() + else: + print "ERROR: Invalid mode \"%s\" specified." % mode + show_usage() + + api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) + printer.Print(api) diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py new file mode 100644 index 0000000..660c8cf --- /dev/null +++ b/src/mapi/glapi/gen/gl_XML.py @@ -0,0 +1,967 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import libxml2 +import re, sys, string +import typeexpr + + +def parse_GL_API( file_name, factory = None ): + doc = libxml2.readFile( file_name, None, libxml2.XML_PARSE_XINCLUDE + libxml2.XML_PARSE_NOBLANKS + libxml2.XML_PARSE_DTDVALID + libxml2.XML_PARSE_DTDATTR + libxml2.XML_PARSE_DTDLOAD + libxml2.XML_PARSE_NOENT ) + ret = doc.xincludeProcess() + + if not factory: + factory = gl_item_factory() + + api = factory.create_item( "api", None, None ) + api.process_element( doc ) + + # After the XML has been processed, we need to go back and assign + # dispatch offsets to the functions that request that their offsets + # be assigned by the scripts. Typically this means all functions + # that are not part of the ABI. + + for func in api.functionIterateByCategory(): + if func.assign_offset: + func.offset = api.next_offset; + api.next_offset += 1 + + doc.freeDoc() + + return api + + +def is_attr_true( element, name ): + """Read a name value from an element's attributes. + + The value read from the attribute list must be either 'true' or + 'false'. If the value is 'false', zero will be returned. If the + value is 'true', non-zero will be returned. An exception will be + raised for any other value.""" + + value = element.nsProp( name, None ) + if value == "true": + return 1 + elif value == "false": + return 0 + else: + raise RuntimeError('Invalid value "%s" for boolean "%s".' % (value, name)) + + +class gl_print_base: + """Base class of all API pretty-printers. + + In the model-view-controller pattern, this is the view. Any derived + class will want to over-ride the printBody, printRealHader, and + printRealFooter methods. Some derived classes may want to over-ride + printHeader and printFooter, or even Print (though this is unlikely). + """ + + def __init__(self): + # Name of the script that is generating the output file. + # Every derived class should set this to the name of its + # source file. + + self.name = "a" + + + # License on the *generated* source file. This may differ + # from the license on the script that is generating the file. + # Every derived class should set this to some reasonable + # value. + # + # See license.py for an example of a reasonable value. + + self.license = "The license for this file is unspecified." + + + # The header_tag is the name of the C preprocessor define + # used to prevent multiple inclusion. Typically only + # generated C header files need this to be set. Setting it + # causes code to be generated automatically in printHeader + # and printFooter. + + self.header_tag = None + + + # List of file-private defines that must be undefined at the + # end of the file. This can be used in header files to define + # names for use in the file, then undefine them at the end of + # the header file. + + self.undef_list = [] + return + + + def Print(self, api): + self.printHeader() + self.printBody(api) + self.printFooter() + return + + + def printHeader(self): + """Print the header associated with all files and call the printRealHeader method.""" + + print '/* DO NOT EDIT - This file generated automatically by %s script */' \ + % (self.name) + print '' + print '/*' + print ' * ' + self.license.replace('\n', '\n * ') + print ' */' + print '' + if self.header_tag: + print '#if !defined( %s )' % (self.header_tag) + print '# define %s' % (self.header_tag) + print '' + self.printRealHeader(); + return + + + def printFooter(self): + """Print the header associated with all files and call the printRealFooter method.""" + + self.printRealFooter() + + if self.undef_list: + print '' + for u in self.undef_list: + print "# undef %s" % (u) + + if self.header_tag: + print '' + print '#endif /* !defined( %s ) */' % (self.header_tag) + + + def printRealHeader(self): + """Print the "real" header for the created file. + + In the base class, this function is empty. All derived + classes should over-ride this function.""" + return + + + def printRealFooter(self): + """Print the "real" footer for the created file. + + In the base class, this function is empty. All derived + classes should over-ride this function.""" + return + + + def printPure(self): + """Conditionally define `PURE' function attribute. + + Conditionally defines a preprocessor macro `PURE' that wraps + GCC's `pure' function attribute. The conditional code can be + easilly adapted to other compilers that support a similar + feature. + + The name is also added to the file's undef_list. + """ + self.undef_list.append("PURE") + print """# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define PURE __attribute__((pure)) +# else +# define PURE +# endif""" + return + + + def printFastcall(self): + """Conditionally define `FASTCALL' function attribute. + + Conditionally defines a preprocessor macro `FASTCALL' that + wraps GCC's `fastcall' function attribute. The conditional + code can be easilly adapted to other compilers that support a + similar feature. + + The name is also added to the file's undef_list. + """ + + self.undef_list.append("FASTCALL") + print """# if defined(__i386__) && defined(__GNUC__) && !defined(__CYGWIN__) && !defined(__MINGW32__) +# define FASTCALL __attribute__((fastcall)) +# else +# define FASTCALL +# endif""" + return + + + def printVisibility(self, S, s): + """Conditionally define visibility function attribute. + + Conditionally defines a preprocessor macro name S that wraps + GCC's visibility function attribute. The visibility used is + the parameter s. The conditional code can be easilly adapted + to other compilers that support a similar feature. + + The name is also added to the file's undef_list. + """ + + self.undef_list.append(S) + print """# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) && defined(__ELF__) +# define %s __attribute__((visibility("%s"))) +# else +# define %s +# endif""" % (S, s, S) + return + + + def printNoinline(self): + """Conditionally define `NOINLINE' function attribute. + + Conditionally defines a preprocessor macro `NOINLINE' that + wraps GCC's `noinline' function attribute. The conditional + code can be easilly adapted to other compilers that support a + similar feature. + + The name is also added to the file's undef_list. + """ + + self.undef_list.append("NOINLINE") + print """# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define NOINLINE __attribute__((noinline)) +# else +# define NOINLINE +# endif""" + return + + +def real_function_name(element): + name = element.nsProp( "name", None ) + alias = element.nsProp( "alias", None ) + + if alias: + return alias + else: + return name + + +def real_category_name(c): + if re.compile("[1-9][0-9]*[.][0-9]+").match(c): + return "GL_VERSION_" + c.replace(".", "_") + else: + return c + + +def classify_category(name, number): + """Based on the category name and number, select a numerical class for it. + + Categories are divided into four classes numbered 0 through 3. The + classes are: + + 0. Core GL versions, sorted by version number. + 1. ARB extensions, sorted by extension number. + 2. Non-ARB extensions, sorted by extension number. + 3. Un-numbered extensions, sorted by extension name. + """ + + try: + core_version = float(name) + except Exception,e: + core_version = 0.0 + + if core_version > 0.0: + cat_type = 0 + key = name + elif name.startswith("GL_ARB_") or name.startswith("GLX_ARB_") or name.startswith("WGL_ARB_"): + cat_type = 1 + key = int(number) + else: + if number != None: + cat_type = 2 + key = int(number) + else: + cat_type = 3 + key = name + + + return [cat_type, key] + + +def create_parameter_string(parameters, include_names): + """Create a parameter string from a list of gl_parameters.""" + + list = [] + for p in parameters: + if p.is_padding: + continue + + if include_names: + list.append( p.string() ) + else: + list.append( p.type_string() ) + + if len(list) == 0: list = ["void"] + + return string.join(list, ", ") + + +class gl_item: + def __init__(self, element, context): + self.context = context + self.name = element.nsProp( "name", None ) + self.category = real_category_name( element.parent.nsProp( "name", None ) ) + return + + +class gl_type( gl_item ): + def __init__(self, element, context): + gl_item.__init__(self, element, context) + self.size = int( element.nsProp( "size", None ), 0 ) + + te = typeexpr.type_expression( None ) + tn = typeexpr.type_node() + tn.size = int( element.nsProp( "size", None ), 0 ) + tn.integer = not is_attr_true( element, "float" ) + tn.unsigned = is_attr_true( element, "unsigned" ) + tn.name = "GL" + self.name + te.set_base_type_node( tn ) + + self.type_expr = te + return + + + def get_type_expression(self): + return self.type_expr + + +class gl_enum( gl_item ): + def __init__(self, element, context): + gl_item.__init__(self, element, context) + self.value = int( element.nsProp( "value", None ), 0 ) + + temp = element.nsProp( "count", None ) + if not temp or temp == "?": + self.default_count = -1 + else: + try: + c = int(temp) + except Exception,e: + raise RuntimeError('Invalid count value "%s" for enum "%s" in function "%s" when an integer was expected.' % (temp, self.name, n)) + + self.default_count = c + + return + + + def priority(self): + """Calculate a 'priority' for this enum name. + + When an enum is looked up by number, there may be many + possible names, but only one is the 'prefered' name. The + priority is used to select which name is the 'best'. + + Highest precedence is given to core GL name. ARB extension + names have the next highest, followed by EXT extension names. + Vendor extension names are the lowest. + """ + + if self.name.endswith( "_BIT" ): + bias = 1 + else: + bias = 0 + + if self.category.startswith( "GL_VERSION_" ): + priority = 0 + elif self.category.startswith( "GL_ARB_" ): + priority = 2 + elif self.category.startswith( "GL_EXT_" ): + priority = 4 + else: + priority = 6 + + return priority + bias + + + +class gl_parameter: + def __init__(self, element, context): + self.name = element.nsProp( "name", None ) + + ts = element.nsProp( "type", None ) + self.type_expr = typeexpr.type_expression( ts, context ) + + temp = element.nsProp( "variable_param", None ) + if temp: + self.count_parameter_list = temp.split( ' ' ) + else: + self.count_parameter_list = [] + + # The count tag can be either a numeric string or the name of + # a variable. If it is the name of a variable, the int(c) + # statement will throw an exception, and the except block will + # take over. + + c = element.nsProp( "count", None ) + try: + count = int(c) + self.count = count + self.counter = None + except Exception,e: + count = 1 + self.count = 0 + self.counter = c + + self.count_scale = int(element.nsProp( "count_scale", None )) + + elements = (count * self.count_scale) + if elements == 1: + elements = 0 + + #if ts == "GLdouble": + # print '/* stack size -> %s = %u (before)*/' % (self.name, self.type_expr.get_stack_size()) + # print '/* # elements = %u */' % (elements) + self.type_expr.set_elements( elements ) + #if ts == "GLdouble": + # print '/* stack size -> %s = %u (after) */' % (self.name, self.type_expr.get_stack_size()) + + self.is_client_only = is_attr_true( element, 'client_only' ) + self.is_counter = is_attr_true( element, 'counter' ) + self.is_output = is_attr_true( element, 'output' ) + + + # Pixel data has special parameters. + + self.width = element.nsProp('img_width', None) + self.height = element.nsProp('img_height', None) + self.depth = element.nsProp('img_depth', None) + self.extent = element.nsProp('img_extent', None) + + self.img_xoff = element.nsProp('img_xoff', None) + self.img_yoff = element.nsProp('img_yoff', None) + self.img_zoff = element.nsProp('img_zoff', None) + self.img_woff = element.nsProp('img_woff', None) + + self.img_format = element.nsProp('img_format', None) + self.img_type = element.nsProp('img_type', None) + self.img_target = element.nsProp('img_target', None) + + self.img_pad_dimensions = is_attr_true( element, 'img_pad_dimensions' ) + self.img_null_flag = is_attr_true( element, 'img_null_flag' ) + self.img_send_null = is_attr_true( element, 'img_send_null' ) + + self.is_padding = is_attr_true( element, 'padding' ) + return + + + def compatible(self, other): + return 1 + + + def is_array(self): + return self.is_pointer() + + + def is_pointer(self): + return self.type_expr.is_pointer() + + + def is_image(self): + if self.width: + return 1 + else: + return 0 + + + def is_variable_length(self): + return len(self.count_parameter_list) or self.counter + + + def is_64_bit(self): + count = self.type_expr.get_element_count() + if count: + if (self.size() / count) == 8: + return 1 + else: + if self.size() == 8: + return 1 + + return 0 + + + def string(self): + return self.type_expr.original_string + " " + self.name + + + def type_string(self): + return self.type_expr.original_string + + + def get_base_type_string(self): + return self.type_expr.get_base_name() + + + def get_dimensions(self): + if not self.width: + return [ 0, "0", "0", "0", "0" ] + + dim = 1 + w = self.width + h = "1" + d = "1" + e = "1" + + if self.height: + dim = 2 + h = self.height + + if self.depth: + dim = 3 + d = self.depth + + if self.extent: + dim = 4 + e = self.extent + + return [ dim, w, h, d, e ] + + + def get_stack_size(self): + return self.type_expr.get_stack_size() + + + def size(self): + if self.is_image(): + return 0 + else: + return self.type_expr.get_element_size() + + + def get_element_count(self): + c = self.type_expr.get_element_count() + if c == 0: + return 1 + + return c + + + def size_string(self, use_parens = 1): + s = self.size() + if self.counter or self.count_parameter_list: + list = [ "compsize" ] + + if self.counter and self.count_parameter_list: + list.append( self.counter ) + elif self.counter: + list = [ self.counter ] + + if s > 1: + list.append( str(s) ) + + if len(list) > 1 and use_parens : + return "(%s)" % (string.join(list, " * ")) + else: + return string.join(list, " * ") + + elif self.is_image(): + return "compsize" + else: + return str(s) + + + def format_string(self): + if self.type_expr.original_string == "GLenum": + return "0x%x" + else: + return self.type_expr.format_string() + + + +class gl_function( gl_item ): + def __init__(self, element, context): + self.context = context + self.name = None + + self.entry_points = [] + self.return_type = "void" + self.parameters = [] + self.offset = -1 + self.initialized = 0 + self.images = [] + + self.assign_offset = 0 + + self.static_entry_points = [] + + # Track the parameter string (for the function prototype) + # for each entry-point. This is done because some functions + # change their prototype slightly when promoted from extension + # to ARB extension to core. glTexImage3DEXT and glTexImage3D + # are good examples of this. Scripts that need to generate + # code for these differing aliases need to real prototype + # for each entry-point. Otherwise, they may generate code + # that won't compile. + + self.parameter_strings = {} + + self.process_element( element ) + + return + + + def process_element(self, element): + name = element.nsProp( "name", None ) + alias = element.nsProp( "alias", None ) + + if is_attr_true(element, "static_dispatch"): + self.static_entry_points.append(name) + + self.entry_points.append( name ) + if alias: + true_name = alias + else: + true_name = name + + # Only try to set the offset when a non-alias + # entry-point is being processes. + + offset = element.nsProp( "offset", None ) + if offset: + try: + o = int( offset ) + self.offset = o + except Exception, e: + self.offset = -1 + if offset == "assign": + self.assign_offset = 1 + + + if not self.name: + self.name = true_name + elif self.name != true_name: + raise RuntimeError("Function true name redefined. Was %s, now %s." % (self.name, true_name)) + + + # There are two possible cases. The first time an entry-point + # with data is seen, self.initialized will be 0. On that + # pass, we just fill in the data. The next time an + # entry-point with data is seen, self.initialized will be 1. + # On that pass we have to make that the new values match the + # valuse from the previous entry-point. + + parameters = [] + return_type = "void" + child = element.children + while child: + if child.type == "element": + if child.name == "return": + return_type = child.nsProp( "type", None ) + elif child.name == "param": + param = self.context.factory.create_item( "parameter", child, self.context) + parameters.append( param ) + + child = child.next + + + if self.initialized: + if self.return_type != return_type: + raise RuntimeError( "Return type changed in %s. Was %s, now %s." % (name, self.return_type, return_type)) + + if len(parameters) != len(self.parameters): + raise RuntimeError( "Parameter count mismatch in %s. Was %d, now %d." % (name, len(self.parameters), len(parameters))) + + for j in range(0, len(parameters)): + p1 = parameters[j] + p2 = self.parameters[j] + if not p1.compatible( p2 ): + raise RuntimeError( 'Parameter type mismatch in %s. "%s" was "%s", now "%s".' % (name, p2.name, p2.type_expr.original_string, p1.type_expr.original_string)) + + + if true_name == name or not self.initialized: + self.return_type = return_type + self.parameters = parameters + + for param in self.parameters: + if param.is_image(): + self.images.append( param ) + + if element.children: + self.initialized = 1 + self.parameter_strings[name] = create_parameter_string(parameters, 1) + else: + self.parameter_strings[name] = None + + return + + + def get_images(self): + """Return potentially empty list of input images.""" + return self.images + + + def parameterIterator(self): + return self.parameters.__iter__(); + + + def get_parameter_string(self, entrypoint = None): + if entrypoint: + s = self.parameter_strings[ entrypoint ] + if s: + return s + + return create_parameter_string( self.parameters, 1 ) + + def get_called_parameter_string(self): + p_string = "" + comma = "" + + for p in self.parameterIterator(): + p_string = p_string + comma + p.name + comma = ", " + + return p_string + + + def is_abi(self): + return (self.offset >= 0 and not self.assign_offset) + + def is_static_entry_point(self, name): + return name in self.static_entry_points + + def dispatch_name(self): + if self.name in self.static_entry_points: + return self.name + else: + return "_dispatch_stub_%u" % (self.offset) + + def static_name(self, name): + if name in self.static_entry_points: + return name + else: + return "_dispatch_stub_%u" % (self.offset) + + +class gl_item_factory: + """Factory to create objects derived from gl_item.""" + + def create_item(self, item_name, element, context): + if item_name == "function": + return gl_function(element, context) + if item_name == "type": + return gl_type(element, context) + elif item_name == "enum": + return gl_enum(element, context) + elif item_name == "parameter": + return gl_parameter(element, context) + elif item_name == "api": + return gl_api(self) + else: + return None + + +class gl_api: + def __init__(self, factory): + self.functions_by_name = {} + self.enums_by_name = {} + self.types_by_name = {} + + self.category_dict = {} + self.categories = [{}, {}, {}, {}] + + self.factory = factory + + self.next_offset = 0 + + typeexpr.create_initial_types() + return + + + def process_element(self, doc): + element = doc.children + while element.type != "element" or element.name != "OpenGLAPI": + element = element.next + + if element: + self.process_OpenGLAPI(element) + return + + + def process_OpenGLAPI(self, element): + child = element.children + while child: + if child.type == "element": + if child.name == "category": + self.process_category( child ) + elif child.name == "OpenGLAPI": + self.process_OpenGLAPI( child ) + + child = child.next + + return + + + def process_category(self, cat): + cat_name = cat.nsProp( "name", None ) + cat_number = cat.nsProp( "number", None ) + + [cat_type, key] = classify_category(cat_name, cat_number) + self.categories[cat_type][key] = [cat_name, cat_number] + + child = cat.children + while child: + if child.type == "element": + if child.name == "function": + func_name = real_function_name( child ) + + temp_name = child.nsProp( "name", None ) + self.category_dict[ temp_name ] = [cat_name, cat_number] + + if self.functions_by_name.has_key( func_name ): + func = self.functions_by_name[ func_name ] + func.process_element( child ) + else: + func = self.factory.create_item( "function", child, self ) + self.functions_by_name[ func_name ] = func + + if func.offset >= self.next_offset: + self.next_offset = func.offset + 1 + + + elif child.name == "enum": + enum = self.factory.create_item( "enum", child, self ) + self.enums_by_name[ enum.name ] = enum + elif child.name == "type": + t = self.factory.create_item( "type", child, self ) + self.types_by_name[ "GL" + t.name ] = t + + + child = child.next + + return + + + def functionIterateByCategory(self, cat = None): + """Iterate over functions by category. + + If cat is None, all known functions are iterated in category + order. See classify_category for details of the ordering. + Within a category, functions are sorted by name. If cat is + not None, then only functions in that category are iterated. + """ + lists = [{}, {}, {}, {}] + + for func in self.functionIterateAll(): + [cat_name, cat_number] = self.category_dict[func.name] + + if (cat == None) or (cat == cat_name): + [func_cat_type, key] = classify_category(cat_name, cat_number) + + if not lists[func_cat_type].has_key(key): + lists[func_cat_type][key] = {} + + lists[func_cat_type][key][func.name] = func + + + functions = [] + for func_cat_type in range(0,4): + keys = lists[func_cat_type].keys() + keys.sort() + + for key in keys: + names = lists[func_cat_type][key].keys() + names.sort() + + for name in names: + functions.append(lists[func_cat_type][key][name]) + + return functions.__iter__() + + + def functionIterateByOffset(self): + max_offset = -1 + for func in self.functions_by_name.itervalues(): + if func.offset > max_offset: + max_offset = func.offset + + + temp = [None for i in range(0, max_offset + 1)] + for func in self.functions_by_name.itervalues(): + if func.offset != -1: + temp[ func.offset ] = func + + + list = [] + for i in range(0, max_offset + 1): + if temp[i]: + list.append(temp[i]) + + return list.__iter__(); + + + def functionIterateAll(self): + return self.functions_by_name.itervalues() + + + def enumIterateByName(self): + keys = self.enums_by_name.keys() + keys.sort() + + list = [] + for enum in keys: + list.append( self.enums_by_name[ enum ] ) + + return list.__iter__() + + + def categoryIterate(self): + """Iterate over categories. + + Iterate over all known categories in the order specified by + classify_category. Each iterated value is a tuple of the + name and number (which may be None) of the category. + """ + + list = [] + for cat_type in range(0,4): + keys = self.categories[cat_type].keys() + keys.sort() + + for key in keys: + list.append(self.categories[cat_type][key]) + + return list.__iter__() + + + def get_category_for_name( self, name ): + if self.category_dict.has_key(name): + return self.category_dict[name] + else: + return ["", None] + + + def typeIterate(self): + return self.types_by_name.itervalues() + + + def find_type( self, type_name ): + if type_name in self.types_by_name: + return self.types_by_name[ type_name ].type_expr + else: + print "Unable to find base type matching \"%s\"." % (type_name) + return None diff --git a/src/mapi/glapi/gen/gl_and_glX_API.xml b/src/mapi/glapi/gen/gl_and_glX_API.xml new file mode 100644 index 0000000..34c977e --- /dev/null +++ b/src/mapi/glapi/gen/gl_and_glX_API.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/mapi/glapi/gen/gl_apitemp.py b/src/mapi/glapi/gen/gl_apitemp.py new file mode 100644 index 0000000..41a40fb --- /dev/null +++ b/src/mapi/glapi/gen/gl_apitemp.py @@ -0,0 +1,320 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import gl_XML, glX_XML +import license +import sys, getopt + +class PrintGlOffsets(gl_XML.gl_print_base): + def __init__(self, es=False): + gl_XML.gl_print_base.__init__(self) + + self.name = "gl_apitemp.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved. +(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") + + self.es = es + + self.undef_list.append( "KEYWORD1" ) + self.undef_list.append( "KEYWORD1_ALT" ) + self.undef_list.append( "KEYWORD2" ) + self.undef_list.append( "NAME" ) + self.undef_list.append( "DISPATCH" ) + self.undef_list.append( "RETURN_DISPATCH" ) + self.undef_list.append( "DISPATCH_TABLE_NAME" ) + self.undef_list.append( "UNUSED_TABLE_NAME" ) + self.undef_list.append( "TABLE_ENTRY" ) + + + def printFunction(self, f, name): + p_string = "" + o_string = "" + t_string = "" + comma = "" + + if f.is_static_entry_point(name): + keyword = "KEYWORD1" + else: + keyword = "KEYWORD1_ALT" + + n = f.static_name(name) + + for p in f.parameterIterator(): + if p.is_padding: + continue + + if p.is_pointer(): + cast = "(const void *) " + else: + cast = "" + + t_string = t_string + comma + p.format_string() + p_string = p_string + comma + p.name + o_string = o_string + comma + cast + p.name + comma = ", " + + + if f.return_type != 'void': + dispatch = "RETURN_DISPATCH" + else: + dispatch = "DISPATCH" + + need_proto = False + if not f.is_static_entry_point(name): + need_proto = True + elif self.es: + cat, num = api.get_category_for_name(name) + if (cat.startswith("es") or cat.startswith("GL_OES")): + need_proto = True + if need_proto: + print '%s %s KEYWORD2 NAME(%s)(%s);' % (keyword, f.return_type, n, f.get_parameter_string(name)) + print '' + + print '%s %s KEYWORD2 NAME(%s)(%s)' % (keyword, f.return_type, n, f.get_parameter_string(name)) + print '{' + if p_string == "": + print ' %s(%s, (), (F, "gl%s();\\n"));' \ + % (dispatch, f.name, name) + else: + print ' %s(%s, (%s), (F, "gl%s(%s);\\n", %s));' \ + % (dispatch, f.name, p_string, name, t_string, o_string) + print '}' + print '' + return + + def printRealHeader(self): + print '' + self.printVisibility( "HIDDEN", "hidden" ) + print """ +/* + * This file is a template which generates the OpenGL API entry point + * functions. It should be included by a .c file which first defines + * the following macros: + * KEYWORD1 - usually nothing, but might be __declspec(dllexport) on Win32 + * KEYWORD2 - usually nothing, but might be __stdcall on Win32 + * NAME(n) - builds the final function name (usually add "gl" prefix) + * DISPATCH(func, args, msg) - code to do dispatch of named function. + * msg is a printf-style debug message. + * RETURN_DISPATCH(func, args, msg) - code to do dispatch with a return value + * + * Here is an example which generates the usual OpenGL functions: + * #define KEYWORD1 + * #define KEYWORD2 + * #define NAME(func) gl##func + * #define DISPATCH(func, args, msg) \\ + * struct _glapi_table *dispatch = CurrentDispatch; \\ + * (*dispatch->func) args + * #define RETURN DISPATCH(func, args, msg) \\ + * struct _glapi_table *dispatch = CurrentDispatch; \\ + * return (*dispatch->func) args + * + */ + + +#if defined( NAME ) +#ifndef KEYWORD1 +#define KEYWORD1 +#endif + +#ifndef KEYWORD1_ALT +#define KEYWORD1_ALT HIDDEN +#endif + +#ifndef KEYWORD2 +#define KEYWORD2 +#endif + +#ifndef DISPATCH +#error DISPATCH must be defined +#endif + +#ifndef RETURN_DISPATCH +#error RETURN_DISPATCH must be defined +#endif + +""" + return + + + + def printInitDispatch(self, api): + print """ +#endif /* defined( NAME ) */ + +/* + * This is how a dispatch table can be initialized with all the functions + * we generated above. + */ +#ifdef DISPATCH_TABLE_NAME + +#ifndef TABLE_ENTRY +#error TABLE_ENTRY must be defined +#endif + +#ifdef _GLAPI_SKIP_NORMAL_ENTRY_POINTS +#error _GLAPI_SKIP_NORMAL_ENTRY_POINTS must not be defined +#endif + +_glapi_proc DISPATCH_TABLE_NAME[] = {""" + for f in api.functionIterateByOffset(): + print ' TABLE_ENTRY(%s),' % (f.dispatch_name()) + + print ' /* A whole bunch of no-op functions. These might be called' + print ' * when someone tries to call a dynamically-registered' + print ' * extension function without a current rendering context.' + print ' */' + for i in range(1, 100): + print ' TABLE_ENTRY(Unused),' + + print '};' + print '#endif /* DISPATCH_TABLE_NAME */' + print '' + return + + + def printAliasedTable(self, api): + print """ +/* + * This is just used to silence compiler warnings. + * We list the functions which are not otherwise used. + */ +#ifdef UNUSED_TABLE_NAME +_glapi_proc UNUSED_TABLE_NAME[] = {""" + + normal_entries = [] + proto_entries = [] + for f in api.functionIterateByOffset(): + normal_ents, proto_ents = self.classifyEntryPoints(f) + + # exclude f.name + if f.name in normal_ents: + normal_ents.remove(f.name) + elif f.name in proto_ents: + proto_ents.remove(f.name) + + normal_ents = [f.static_name(ent) for ent in normal_ents] + proto_ents = [f.static_name(ent) for ent in proto_ents] + + normal_entries.extend(normal_ents) + proto_entries.extend(proto_ents) + + print '#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS' + for ent in normal_entries: + print ' TABLE_ENTRY(%s),' % (ent) + print '#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */' + print '#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS' + for ent in proto_entries: + print ' TABLE_ENTRY(%s),' % (ent) + print '#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */' + + print '};' + print '#endif /*UNUSED_TABLE_NAME*/' + print '' + return + + + def classifyEntryPoints(self, func): + normal_names = [] + normal_stubs = [] + proto_names = [] + proto_stubs = [] + # classify the entry points + for name in func.entry_points: + if func.has_different_protocol(name): + if func.is_static_entry_point(name): + proto_names.append(name) + else: + proto_stubs.append(name) + else: + if func.is_static_entry_point(name): + normal_names.append(name) + else: + normal_stubs.append(name) + # there can be at most one stub for a function + if normal_stubs: + normal_names.append(normal_stubs[0]) + elif proto_stubs: + proto_names.append(proto_stubs[0]) + + return (normal_names, proto_names) + + def printBody(self, api): + normal_entry_points = [] + proto_entry_points = [] + for func in api.functionIterateByOffset(): + normal_ents, proto_ents = self.classifyEntryPoints(func) + normal_entry_points.append((func, normal_ents)) + proto_entry_points.append((func, proto_ents)) + + print '#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS' + print '' + for func, ents in normal_entry_points: + for ent in ents: + self.printFunction(func, ent) + print '' + print '#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */' + print '' + print '/* these entry points might require different protocols */' + print '#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS' + print '' + for func, ents in proto_entry_points: + for ent in ents: + self.printFunction(func, ent) + print '' + print '#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */' + print '' + + self.printInitDispatch(api) + self.printAliasedTable(api) + return + + +def show_usage(): + print "Usage: %s [-f input_file_name] [-c]" % sys.argv[0] + print "-c Enable compatibility with OpenGL ES." + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:c") + except Exception,e: + show_usage() + + es = False + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-c": + es = True + + api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) + + printer = PrintGlOffsets(es) + printer.Print(api) diff --git a/src/mapi/glapi/gen/gl_enums.py b/src/mapi/glapi/gen/gl_enums.py new file mode 100644 index 0000000..0caa010 --- /dev/null +++ b/src/mapi/glapi/gen/gl_enums.py @@ -0,0 +1,248 @@ +#!/usr/bin/python2 +# -*- Mode: Python; py-indent-offset: 8 -*- + +# (C) Copyright Zack Rusin 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Zack Rusin + +import license +import gl_XML +import sys, getopt + +class PrintGlEnums(gl_XML.gl_print_base): + + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "gl_enums.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright (C) 1999-2005 Brian Paul All Rights Reserved.""", "BRIAN PAUL") + self.enum_table = {} + + + def printRealHeader(self): + print '#include "main/glheader.h"' + print '#include "main/mfeatures.h"' + print '#include "main/enums.h"' + print '#include "main/imports.h"' + print '' + print 'typedef struct {' + print ' size_t offset;' + print ' int n;' + print '} enum_elt;' + print '' + return + + def print_code(self): + print """ +typedef int (*cfunc)(const void *, const void *); + +/** + * Compare a key name to an element in the \c all_enums array. + * + * \c bsearch always passes the key as the first parameter and the pointer + * to the array element as the second parameter. We can elimiate some + * extra work by taking advantage of that fact. + * + * \param a Pointer to the desired enum name. + * \param b Pointer to an element of the \c all_enums array. + */ +static int compar_name( const char *a, const enum_elt *b ) +{ + return strcmp( a, & enum_string_table[ b->offset ] ); +} + +/** + * Compare a key enum value to an element in the \c all_enums array. + * + * \c bsearch always passes the key as the first parameter and the pointer + * to the array element as the second parameter. We can elimiate some + * extra work by taking advantage of that fact. + * + * \param a Pointer to the desired enum name. + * \param b Pointer to an index into the \c all_enums array. + */ +static int compar_nr( const int *a, const unsigned *b ) +{ + return a[0] - all_enums[*b].n; +} + + +static char token_tmp[20]; + +const char *_mesa_lookup_enum_by_nr( int nr ) +{ + unsigned * i; + + i = (unsigned *) _mesa_bsearch(& nr, reduced_enums, + Elements(reduced_enums), + sizeof(reduced_enums[0]), + (cfunc) compar_nr); + + if ( i != NULL ) { + return & enum_string_table[ all_enums[ *i ].offset ]; + } + else { + /* this is not re-entrant safe, no big deal here */ + _mesa_snprintf(token_tmp, sizeof(token_tmp) - 1, "0x%x", nr); + token_tmp[sizeof(token_tmp) - 1] = '\\0'; + return token_tmp; + } +} + +/* Get the name of an enum given that it is a primitive type. Avoids + * GL_FALSE/GL_POINTS ambiguity and others. + */ +const char *_mesa_lookup_prim_by_nr( int nr ) +{ + switch (nr) { + case GL_POINTS: return "GL_POINTS"; + case GL_LINES: return "GL_LINES"; + case GL_LINE_STRIP: return "GL_LINE_STRIP"; + case GL_LINE_LOOP: return "GL_LINE_LOOP"; + case GL_TRIANGLES: return "GL_TRIANGLES"; + case GL_TRIANGLE_STRIP: return "GL_TRIANGLE_STRIP"; + case GL_TRIANGLE_FAN: return "GL_TRIANGLE_FAN"; + case GL_QUADS: return "GL_QUADS"; + case GL_QUAD_STRIP: return "GL_QUAD_STRIP"; + case GL_POLYGON: return "GL_POLYGON"; + case GL_POLYGON+1: return "OUTSIDE_BEGIN_END"; + default: return ""; + } +} + + + +int _mesa_lookup_enum_by_name( const char *symbol ) +{ + enum_elt * f = NULL; + + if ( symbol != NULL ) { + f = (enum_elt *) _mesa_bsearch(symbol, all_enums, + Elements(all_enums), + sizeof( enum_elt ), + (cfunc) compar_name); + } + + return (f != NULL) ? f->n : -1; +} + +""" + return + + + def printBody(self, api_list): + self.enum_table = {} + for api in api_list: + self.process_enums( api ) + + keys = self.enum_table.keys() + keys.sort() + + name_table = [] + enum_table = {} + + for enum in keys: + low_pri = 9 + for [name, pri] in self.enum_table[ enum ]: + name_table.append( [name, enum] ) + + if pri < low_pri: + low_pri = pri + enum_table[enum] = name + + + name_table.sort() + + string_offsets = {} + i = 0; + print 'LONGSTRING static const char enum_string_table[] = ' + for [name, enum] in name_table: + print ' "%s\\0"' % (name) + string_offsets[ name ] = i + i += len(name) + 1 + + print ' ;' + print '' + + + print 'static const enum_elt all_enums[%u] =' % (len(name_table)) + print '{' + for [name, enum] in name_table: + print ' { %5u, 0x%08X }, /* %s */' % (string_offsets[name], enum, name) + print '};' + print '' + + print 'static const unsigned reduced_enums[%u] =' % (len(keys)) + print '{' + for enum in keys: + name = enum_table[ enum ] + if [name, enum] not in name_table: + print ' /* Error! %s, 0x%04x */ 0,' % (name, enum) + else: + i = name_table.index( [name, enum] ) + + print ' %4u, /* %s */' % (i, name) + print '};' + + + self.print_code() + return + + + def process_enums(self, api): + for obj in api.enumIterateByName(): + if obj.value not in self.enum_table: + self.enum_table[ obj.value ] = [] + + + enum = self.enum_table[ obj.value ] + name = "GL_" + obj.name + priority = obj.priority() + already_in = False; + for n, p in enum: + if n == name: + already_in = True + if not already_in: + enum.append( [name, priority] ) + + +def show_usage(): + print "Usage: %s [-f input_file_name]" % sys.argv[0] + sys.exit(1) + +if __name__ == '__main__': + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:") + except Exception,e: + show_usage() + + api_list = [] + for (arg,val) in args: + if arg == "-f": + api = gl_XML.parse_GL_API( val ) + api_list.append(api); + + printer = PrintGlEnums() + printer.Print( api_list ) diff --git a/src/mapi/glapi/gen/gl_offsets.py b/src/mapi/glapi/gen/gl_offsets.py new file mode 100644 index 0000000..54867b3 --- /dev/null +++ b/src/mapi/glapi/gen/gl_offsets.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import gl_XML +import license +import sys, getopt + +class PrintGlOffsets(gl_XML.gl_print_base): + def __init__(self, es=False): + gl_XML.gl_print_base.__init__(self) + + self.es = es + self.name = "gl_offsets.py (from Mesa)" + self.header_tag = '_GLAPI_OFFSETS_H_' + self.license = license.bsd_license_template % ( \ +"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved. +(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") + return + + def printBody(self, api): + print '/* this file should not be included directly in mesa */' + print '' + + functions = [] + abi_functions = [] + alias_functions = [] + count = 0 + for f in api.functionIterateByOffset(): + if not f.is_abi(): + functions.append( [f, count] ) + count += 1 + else: + abi_functions.append( f ) + + if self.es: + # remember functions with aliases + if len(f.entry_points) > 1: + alias_functions.append(f) + + for f in abi_functions: + print '#define _gloffset_%s %d' % (f.name, f.offset) + last_static = f.offset + + print '' + print '#if !defined(_GLAPI_USE_REMAP_TABLE)' + print '' + + for [f, index] in functions: + print '#define _gloffset_%s %d' % (f.name, f.offset) + + print '#define _gloffset_FIRST_DYNAMIC %d' % (api.next_offset) + + print '' + print '#else' + print '' + + for [f, index] in functions: + print '#define _gloffset_%s driDispatchRemapTable[%s_remap_index]' % (f.name, f.name) + + print '' + print '#endif /* !defined(_GLAPI_USE_REMAP_TABLE) */' + + if alias_functions: + print '' + print '/* define aliases for compatibility */' + for f in alias_functions: + for name in f.entry_points: + if name != f.name: + print '#define _gloffset_%s _gloffset_%s' % (name, f.name) + return + + +def show_usage(): + print "Usage: %s [-f input_file_name] [-c]" % sys.argv[0] + print " -c Enable compatibility with OpenGL ES." + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:c") + except Exception,e: + show_usage() + + es = False + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-c": + es = True + + api = gl_XML.parse_GL_API( file_name ) + + printer = PrintGlOffsets(es) + printer.Print( api ) diff --git a/src/mapi/glapi/gen/gl_procs.py b/src/mapi/glapi/gen/gl_procs.py new file mode 100644 index 0000000..a9ba482 --- /dev/null +++ b/src/mapi/glapi/gen/gl_procs.py @@ -0,0 +1,215 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import license +import gl_XML, glX_XML +import sys, getopt + +class PrintGlProcs(gl_XML.gl_print_base): + def __init__(self, long_strings, es=False): + gl_XML.gl_print_base.__init__(self) + + self.es = es + self.long_strings = long_strings + self.name = "gl_procs.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved. +(C) Copyright IBM Corporation 2004, 2006""", "BRIAN PAUL, IBM") + + + def printRealHeader(self): + print """ +/* This file is only included by glapi.c and is used for + * the GetProcAddress() function + */ + +typedef struct { + GLint Name_offset; +#if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) + _glapi_proc Address; +#endif + GLuint Offset; +} glprocs_table_t; + +#if !defined(NEED_FUNCTION_POINTER) && !defined(GLX_INDIRECT_RENDERING) +# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , o } +#elif defined(NEED_FUNCTION_POINTER) && !defined(GLX_INDIRECT_RENDERING) +# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f1 , o } +#elif defined(NEED_FUNCTION_POINTER) && defined(GLX_INDIRECT_RENDERING) +# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f2 , o } +#elif !defined(NEED_FUNCTION_POINTER) && defined(GLX_INDIRECT_RENDERING) +# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f3 , o } +#endif + +""" + return + + def printRealFooter(self): + print '' + print '#undef NAME_FUNC_OFFSET' + return + + def printFunctionString(self, name): + if self.long_strings: + print ' "gl%s\\0"' % (name) + else: + print " 'g','l',", + for c in name: + print "'%s'," % (c), + + print "'\\0'," + + + def printBody(self, api): + print '' + if self.long_strings: + print 'static const char gl_string_table[] =' + else: + print 'static const char gl_string_table[] = {' + + base_offset = 0 + table = [] + for func in api.functionIterateByOffset(): + name = func.dispatch_name() + self.printFunctionString(func.name) + table.append((base_offset, "gl" + name, "gl" + name, "NULL", func.offset)) + + # The length of the function's name, plus 2 for "gl", + # plus 1 for the NUL. + + base_offset += len(func.name) + 3 + + + for func in api.functionIterateByOffset(): + for n in func.entry_points: + if n != func.name: + name = func.dispatch_name() + self.printFunctionString( n ) + + if func.has_different_protocol(n): + alt_name = "gl" + func.static_glx_name(n) + table.append((base_offset, "gl" + name, alt_name, alt_name, func.offset)) + else: + table.append((base_offset, "gl" + name, "gl" + name, "NULL", func.offset)) + + base_offset += len(n) + 3 + + + if self.long_strings: + print ' ;' + else: + print '};' + + print '' + print '' + print "#ifdef USE_MGL_NAMESPACE" + for func in api.functionIterateByOffset(): + for n in func.entry_points: + if (not func.is_static_entry_point(func.name)) or (func.has_different_protocol(n) and not func.is_static_entry_point(n)): + print '#define gl_dispatch_stub_%u mgl_dispatch_stub_%u' % (func.offset, func.offset) + break + print "#endif /* USE_MGL_NAMESPACE */" + print '' + print '' + print '#if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING)' + for func in api.functionIterateByOffset(): + for n in func.entry_points: + if (not func.is_static_entry_point(func.name)) or (func.has_different_protocol(n) and not func.is_static_entry_point(n)): + print '%s GLAPIENTRY gl_dispatch_stub_%u(%s);' % (func.return_type, func.offset, func.get_parameter_string()) + break + + if self.es: + categories = {} + for func in api.functionIterateByOffset(): + for n in func.entry_points: + cat, num = api.get_category_for_name(n) + if (cat.startswith("es") or cat.startswith("GL_OES")): + if not categories.has_key(cat): + categories[cat] = [] + proto = 'GLAPI %s GLAPIENTRY %s(%s);' \ + % (func.return_type, "gl" + n, func.get_parameter_string(n)) + categories[cat].append(proto) + if categories: + print '' + print '/* OpenGL ES specific prototypes */' + print '' + keys = categories.keys() + keys.sort() + for key in keys: + print '/* category %s */' % key + print "\n".join(categories[key]) + print '' + + print '#endif /* defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) */' + + print '' + print 'static const glprocs_table_t static_functions[] = {' + + for info in table: + print ' NAME_FUNC_OFFSET(%5u, %s, %s, %s, %d),' % info + + print ' NAME_FUNC_OFFSET(-1, NULL, NULL, NULL, 0)' + print '};' + return + + +def show_usage(): + print "Usage: %s [-f input_file_name] [-m mode] [-c]" % sys.argv[0] + print "-c Enable compatibility with OpenGL ES." + print "-m mode mode can be one of:" + print " long - Create code for compilers that can handle very" + print " long string constants. (default)" + print " short - Create code for compilers that can only handle" + print " ANSI C89 string constants." + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:m:c") + except Exception,e: + show_usage() + + long_string = 1 + es = False + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-m": + if val == "short": + long_string = 0 + elif val == "long": + long_string = 1 + else: + show_usage() + elif arg == "-c": + es = True + + api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) + printer = PrintGlProcs(long_string, es) + printer.Print(api) diff --git a/src/mapi/glapi/gen/gl_table.py b/src/mapi/glapi/gen/gl_table.py new file mode 100644 index 0000000..c7cb5a4 --- /dev/null +++ b/src/mapi/glapi/gen/gl_table.py @@ -0,0 +1,231 @@ +#!/usr/bin/python2 + +# (C) Copyright IBM Corporation 2004 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import gl_XML +import license +import sys, getopt + +class PrintGlTable(gl_XML.gl_print_base): + def __init__(self, es=False): + gl_XML.gl_print_base.__init__(self) + + self.es = es + self.header_tag = '_GLAPI_TABLE_H_' + self.name = "gl_table.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright (C) 1999-2003 Brian Paul All Rights Reserved. +(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") + return + + + def printBody(self, api): + for f in api.functionIterateByOffset(): + arg_string = f.get_parameter_string() + print ' %s (GLAPIENTRYP %s)(%s); /* %d */' % (f.return_type, f.name, arg_string, f.offset) + + + def printRealHeader(self): + print '#ifndef GLAPIENTRYP' + print '# ifndef GLAPIENTRY' + print '# define GLAPIENTRY' + print '# endif' + print '' + print '# define GLAPIENTRYP GLAPIENTRY *' + print '#endif' + print '' + print '' + print 'struct _glapi_table' + print '{' + return + + + def printRealFooter(self): + print '};' + return + + +class PrintRemapTable(gl_XML.gl_print_base): + def __init__(self, es=False): + gl_XML.gl_print_base.__init__(self) + + self.es = es + self.header_tag = '_GLAPI_DISPATCH_H_' + self.name = "gl_table.py (from Mesa)" + self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM") + return + + + def printRealHeader(self): + print """ +/* this file should not be included directly in mesa */ + +/** + * \\file glapidispatch.h + * Macros for handling GL dispatch tables. + * + * For each known GL function, there are 3 macros in this file. The first + * macro is named CALL_FuncName and is used to call that GL function using + * the specified dispatch table. The other 2 macros, called GET_FuncName + * can SET_FuncName, are used to get and set the dispatch pointer for the + * named function in the specified dispatch table. + */ +""" + + return + + def printBody(self, api): + print '#define CALL_by_offset(disp, cast, offset, parameters) \\' + print ' (*(cast (GET_by_offset(disp, offset)))) parameters' + print '#define GET_by_offset(disp, offset) \\' + print ' (offset >= 0) ? (((_glapi_proc *)(disp))[offset]) : NULL' + print '#define SET_by_offset(disp, offset, fn) \\' + print ' do { \\' + print ' if ( (offset) < 0 ) { \\' + print ' /* fprintf( stderr, "[%s:%u] SET_by_offset(%p, %d, %s)!\\n", */ \\' + print ' /* __func__, __LINE__, disp, offset, # fn); */ \\' + print ' /* abort(); */ \\' + print ' } \\' + print ' else { \\' + print ' ( (_glapi_proc *) (disp) )[offset] = (_glapi_proc) fn; \\' + print ' } \\' + print ' } while(0)' + print '' + + functions = [] + abi_functions = [] + alias_functions = [] + count = 0 + for f in api.functionIterateByOffset(): + if not f.is_abi(): + functions.append( [f, count] ) + count += 1 + else: + abi_functions.append( [f, -1] ) + + if self.es: + # remember functions with aliases + if len(f.entry_points) > 1: + alias_functions.append(f) + + print '/* total number of offsets below */' + print '#define _gloffset_COUNT %d' % (len(abi_functions + functions)) + print '' + + for f, index in abi_functions: + print '#define _gloffset_%s %d' % (f.name, f.offset) + + print '' + print '#if !defined(_GLAPI_USE_REMAP_TABLE)' + print '' + + for f, index in functions: + print '#define _gloffset_%s %d' % (f.name, f.offset) + + print '' + print '#else /* !_GLAPI_USE_REMAP_TABLE */' + print '' + + print '#define driDispatchRemapTable_size %u' % (count) + print 'extern int driDispatchRemapTable[ driDispatchRemapTable_size ];' + print '' + + for f, index in functions: + print '#define %s_remap_index %u' % (f.name, index) + + print '' + + for f, index in functions: + print '#define _gloffset_%s driDispatchRemapTable[%s_remap_index]' % (f.name, f.name) + + print '' + print '#endif /* _GLAPI_USE_REMAP_TABLE */' + print '' + + for f, index in abi_functions + functions: + arg_string = gl_XML.create_parameter_string( f.parameters, 0 ) + cast = '%s (GLAPIENTRYP)(%s)' % (f.return_type, arg_string) + + print '#define CALL_%s(disp, parameters) CALL_by_offset(disp, (%s), _gloffset_%s, parameters)' % (f.name, cast, f.name) + print '#define GET_%s(disp) GET_by_offset(disp, _gloffset_%s)' % (f.name, f.name) + print '#define SET_%s(disp, fn) SET_by_offset(disp, _gloffset_%s, fn)' % (f.name, f.name) + + if alias_functions: + print '' + print '/* define aliases for compatibility */' + for f in alias_functions: + for name in f.entry_points: + if name != f.name: + print '#define CALL_%s(disp, parameters) CALL_%s(disp, parameters)' % (name, f.name) + print '#define GET_%s(disp) GET_%s(disp)' % (name, f.name) + print '#define SET_%s(disp, fn) SET_%s(disp, fn)' % (name, f.name) + print '' + + print '#if defined(_GLAPI_USE_REMAP_TABLE)' + for f in alias_functions: + for name in f.entry_points: + if name != f.name: + print '#define %s_remap_index %s_remap_index' % (name, f.name) + print '#endif /* defined(_GLAPI_USE_REMAP_TABLE) */' + print '' + + return + + +def show_usage(): + print "Usage: %s [-f input_file_name] [-m mode] [-c]" % sys.argv[0] + print " -m mode Mode can be 'table' or 'remap_table'." + print " -c Enable compatibility with OpenGL ES." + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:m:c") + except Exception,e: + show_usage() + + mode = "table" + es = False + for (arg,val) in args: + if arg == "-f": + file_name = val + elif arg == "-m": + mode = val + elif arg == "-c": + es = True + + if mode == "table": + printer = PrintGlTable(es) + elif mode == "remap_table": + printer = PrintRemapTable(es) + else: + show_usage() + + api = gl_XML.parse_GL_API( file_name ) + + printer.Print( api ) diff --git a/src/mapi/glapi/gen/gl_x86-64_asm.py b/src/mapi/glapi/gen/gl_x86-64_asm.py new file mode 100644 index 0000000..11cd9af --- /dev/null +++ b/src/mapi/glapi/gen/gl_x86-64_asm.py @@ -0,0 +1,335 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import license +import gl_XML, glX_XML +import sys, getopt, copy + +def should_use_push(registers): + for [reg, offset] in registers: + if reg[1:4] == "xmm": + return 0 + + N = len(registers) + return (N & 1) != 0 + + +def local_size(registers): + # The x86-64 ABI says "the value (%rsp - 8) is always a multiple of + # 16 when control is transfered to the function entry point." This + # means that the local stack usage must be (16*N)+8 for some value + # of N. (16*N)+8 = (8*(2N))+8 = 8*(2N+1). As long as N is odd, we + # meet this requirement. + + N = (len(registers) | 1) + return 8*N + + +def save_all_regs(registers): + adjust_stack = 0 + if not should_use_push(registers): + adjust_stack = local_size(registers) + print '\tsubq\t$%u, %%rsp' % (adjust_stack) + + for [reg, stack_offset] in registers: + save_reg( reg, stack_offset, adjust_stack ) + return + + +def restore_all_regs(registers): + adjust_stack = 0 + if not should_use_push(registers): + adjust_stack = local_size(registers) + + temp = copy.deepcopy(registers) + while len(temp): + [reg, stack_offset] = temp.pop() + restore_reg(reg, stack_offset, adjust_stack) + + if adjust_stack: + print '\taddq\t$%u, %%rsp' % (adjust_stack) + return + + +def save_reg(reg, offset, use_move): + if use_move: + if offset == 0: + print '\tmovq\t%s, (%%rsp)' % (reg) + else: + print '\tmovq\t%s, %u(%%rsp)' % (reg, offset) + else: + print '\tpushq\t%s' % (reg) + + return + + +def restore_reg(reg, offset, use_move): + if use_move: + if offset == 0: + print '\tmovq\t(%%rsp), %s' % (reg) + else: + print '\tmovq\t%u(%%rsp), %s' % (offset, reg) + else: + print '\tpopq\t%s' % (reg) + + return + + +class PrintGenericStubs(gl_XML.gl_print_base): + + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "gl_x86-64_asm.py (from Mesa)" + self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM") + return + + + def get_stack_size(self, f): + size = 0 + for p in f.parameterIterator(): + size += p.get_stack_size() + + return size + + + def printRealHeader(self): + print "/* If we build with gcc's -fvisibility=hidden flag, we'll need to change" + print " * the symbol visibility mode to 'default'." + print ' */' + print '' + print '#include "x86/assyntax.h"' + print '' + print '#ifdef __GNUC__' + print '# pragma GCC visibility push(default)' + print '# define HIDDEN(x) .hidden x' + print '#else' + print '# define HIDDEN(x)' + print '#endif' + print '' + print '# if defined(USE_MGL_NAMESPACE)' + print '# define GL_PREFIX(n) GLNAME(CONCAT(mgl,n))' + print '# define _glapi_Dispatch _mglapi_Dispatch' + print '# else' + print '# define GL_PREFIX(n) GLNAME(CONCAT(gl,n))' + print '# endif' + print '' + print '#if defined(PTHREADS) || defined(WIN32) || defined(BEOS_THREADS)' + print '# define THREADS' + print '#endif' + print '' + print '\t.text' + print '' + print '#ifdef GLX_USE_TLS' + print '' + print '\t.globl _x86_64_get_get_dispatch; HIDDEN(_x86_64_get_get_dispatch)' + print '_x86_64_get_get_dispatch:' + print '\tlea\t_x86_64_get_dispatch(%rip), %rax' + print '\tret' + print '' + print '\t.p2align\t4,,15' + print '_x86_64_get_dispatch:' + print '\tmovq\t_glapi_tls_Dispatch@GOTTPOFF(%rip), %rax' + print '\tmovq\t%fs:(%rax), %rax' + print '\tret' + print '\t.size\t_x86_64_get_dispatch, .-_x86_64_get_dispatch' + print '' + print '#elif defined(PTHREADS)' + print '' + print '\t.extern\t_glapi_Dispatch' + print '\t.extern\t_gl_DispatchTSD' + print '\t.extern\tpthread_getspecific' + print '' + print '\t.p2align\t4,,15' + print '_x86_64_get_dispatch:' + print '\tmovq\t_gl_DispatchTSD@GOTPCREL(%rip), %rax' + print '\tmovl\t(%rax), %edi' + print '\tjmp\tpthread_getspecific@PLT' + print '' + print '#elif defined(THREADS)' + print '' + print '\t.extern\t_glapi_get_dispatch' + print '' + print '#endif' + print '' + return + + + def printRealFooter(self): + print '' + print '#if defined(GLX_USE_TLS) && defined(__linux__)' + print ' .section ".note.ABI-tag", "a"' + print ' .p2align 2' + print ' .long 1f - 0f /* name length */' + print ' .long 3f - 2f /* data length */' + print ' .long 1 /* note length */' + print '0: .asciz "GNU" /* vendor name */' + print '1: .p2align 2' + print '2: .long 0 /* note data: the ABI tag */' + print ' .long 2,4,20 /* Minimum kernel version w/TLS */' + print '3: .p2align 2 /* pad out section */' + print '#endif /* GLX_USE_TLS */' + print '' + print '#if defined (__ELF__) && defined (__linux__)' + print ' .section .note.GNU-stack,"",%progbits' + print '#endif' + return + + + def printFunction(self, f): + + # The x86-64 ABI divides function parameters into a couple + # classes. For the OpenGL interface, the only ones that are + # relevent are INTEGER and SSE. Basically, the first 8 + # GLfloat or GLdouble parameters are placed in %xmm0 - %xmm7, + # the first 6 non-GLfloat / non-GLdouble parameters are placed + # in registers listed in int_parameters. + # + # If more parameters than that are required, they are passed + # on the stack. Therefore, we just have to make sure that + # %esp hasn't changed when we jump to the actual function. + # Since we're jumping to the function (and not calling it), we + # have to make sure of that anyway! + + int_parameters = ["%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9"] + + int_class = 0 + sse_class = 0 + stack_offset = 0 + registers = [] + for p in f.parameterIterator(): + type_name = p.get_base_type_string() + + if p.is_pointer() or (type_name != "GLfloat" and type_name != "GLdouble"): + if int_class < 6: + registers.append( [int_parameters[int_class], stack_offset] ) + int_class += 1 + stack_offset += 8 + else: + if sse_class < 8: + registers.append( ["%%xmm%u" % (sse_class), stack_offset] ) + sse_class += 1 + stack_offset += 8 + + if ((int_class & 1) == 0) and (sse_class == 0): + registers.append( ["%rbp", 0] ) + + + name = f.dispatch_name() + + print '\t.p2align\t4,,15' + print '\t.globl\tGL_PREFIX(%s)' % (name) + print '\t.type\tGL_PREFIX(%s), @function' % (name) + if not f.is_static_entry_point(f.name): + print '\tHIDDEN(GL_PREFIX(%s))' % (name) + print 'GL_PREFIX(%s):' % (name) + print '#if defined(GLX_USE_TLS)' + print '\tcall\t_x86_64_get_dispatch@PLT' + print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8) + print '\tjmp\t*%r11' + print '#elif defined(PTHREADS)' + + save_all_regs(registers) + print '\tcall\t_x86_64_get_dispatch@PLT' + restore_all_regs(registers) + + if f.offset == 0: + print '\tmovq\t(%rax), %r11' + else: + print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8) + + print '\tjmp\t*%r11' + + print '#else' + print '\tmovq\t_glapi_Dispatch(%rip), %rax' + print '\ttestq\t%rax, %rax' + print '\tje\t1f' + print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8) + print '\tjmp\t*%r11' + print '1:' + + save_all_regs(registers) + print '\tcall\t_glapi_get_dispatch' + restore_all_regs(registers) + + print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8) + print '\tjmp\t*%r11' + print '#endif /* defined(GLX_USE_TLS) */' + + print '\t.size\tGL_PREFIX(%s), .-GL_PREFIX(%s)' % (name, name) + print '' + return + + + def printBody(self, api): + for f in api.functionIterateByOffset(): + self.printFunction(f) + + + for f in api.functionIterateByOffset(): + dispatch = f.dispatch_name() + for n in f.entry_points: + if n != f.name: + if f.is_static_entry_point(n): + text = '\t.globl GL_PREFIX(%s) ; .set GL_PREFIX(%s), GL_PREFIX(%s)' % (n, n, dispatch) + + if f.has_different_protocol(n): + print '#ifndef GLX_INDIRECT_RENDERING' + print text + print '#endif' + else: + print text + + return + +def show_usage(): + print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0] + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + mode = "generic" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "m:f:") + except Exception,e: + show_usage() + + for (arg,val) in args: + if arg == '-m': + mode = val + elif arg == "-f": + file_name = val + + if mode == "generic": + printer = PrintGenericStubs() + else: + print "ERROR: Invalid mode \"%s\" specified." % mode + show_usage() + + api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) + printer.Print(api) diff --git a/src/mapi/glapi/gen/gl_x86_asm.py b/src/mapi/glapi/gen/gl_x86_asm.py new file mode 100644 index 0000000..4ef4acb --- /dev/null +++ b/src/mapi/glapi/gen/gl_x86_asm.py @@ -0,0 +1,269 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2004, 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import license +import gl_XML, glX_XML +import sys, getopt + +class PrintGenericStubs(gl_XML.gl_print_base): + + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "gl_x86_asm.py (from Mesa)" + self.license = license.bsd_license_template % ( \ +"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved. +(C) Copyright IBM Corporation 2004, 2005""", "BRIAN PAUL, IBM") + return + + + def get_stack_size(self, f): + size = 0 + for p in f.parameterIterator(): + if p.is_padding: + continue + + size += p.get_stack_size() + + return size + + + def printRealHeader(self): + print '#include "x86/assyntax.h"' + print '' + print '#if defined(STDCALL_API)' + print '# if defined(USE_MGL_NAMESPACE)' + print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n2))' + print '# else' + print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))' + print '# endif' + print '#else' + print '# if defined(USE_MGL_NAMESPACE)' + print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))' + print '# define _glapi_Dispatch _mglapi_Dispatch' + print '# else' + print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))' + print '# endif' + print '#endif' + print '' + print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))' + print '' + print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__) && !defined(__APPLE__)' + print '#define GLOBL_FN(x) GLOBL x ; .type x, @function' + print '#else' + print '#define GLOBL_FN(x) GLOBL x' + print '#endif' + print '' + print '#if defined(PTHREADS) || defined(WIN32) || defined(BEOS_THREADS)' + print '# define THREADS' + print '#endif' + print '' + print '#ifdef GLX_USE_TLS' + print '' + print '#ifdef GLX_X86_READONLY_TEXT' + print '# define CTX_INSNS MOV_L(GS:(EAX), EAX)' + print '#else' + print '# define CTX_INSNS NOP /* Pad for init_glapi_relocs() */' + print '#endif' + print '' + print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\' + print 'ALIGNTEXT16;\t\t\t\t\t\t\\' + print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\' + print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\' + print '\tCALL(_x86_get_dispatch) ;\t\t\t\\' + print '\tCTX_INSNS ; \\' + print '\tJMP(GL_OFFSET(off))' + print '' + print '#elif defined(PTHREADS)' + print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\' + print 'ALIGNTEXT16;\t\t\t\t\t\t\\' + print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\' + print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\' + print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\' + print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\' + print '\tJE(1f) ;\t\t\t\t\t\\' + print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\' + print '1:\tCALL(_x86_get_dispatch) ;\t\t\t\\' + print '\tJMP(GL_OFFSET(off))' + print '#elif defined(THREADS)' + print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\' + print 'ALIGNTEXT16;\t\t\t\t\t\t\\' + print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\' + print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\' + print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\' + print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\' + print '\tJE(1f) ;\t\t\t\t\t\\' + print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\' + print '1:\tCALL(_glapi_get_dispatch) ;\t\t\t\\' + print '\tJMP(GL_OFFSET(off))' + print '#else /* Non-threaded version. */' + print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\' + print 'ALIGNTEXT16;\t\t\t\t\t\t\\' + print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\' + print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\' + print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\' + print '\tJMP(GL_OFFSET(off))' + print '#endif' + print '' + print '#ifdef HAVE_ALIAS' + print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\' + print '\t.globl\tGL_PREFIX(fn, fn_alt) ;\t\t\t\\' + print '\t.set\tGL_PREFIX(fn, fn_alt), GL_PREFIX(alias, alias_alt)' + print '#else' + print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\' + print ' GL_STUB(fn, off, fn_alt)' + print '#endif' + print '' + print 'SEG_TEXT' + print '' + print '#ifdef GLX_USE_TLS' + print '' + print '\tGLOBL\tGLNAME(_x86_get_dispatch)' + print '\tHIDDEN(GLNAME(_x86_get_dispatch))' + print 'ALIGNTEXT16' + print 'GLNAME(_x86_get_dispatch):' + print '\tcall 1f' + print '1:\tpopl %eax' + print '\taddl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax' + print '\tmovl _glapi_tls_Dispatch@GOTNTPOFF(%eax), %eax' + print '\tret' + print '' + print '#elif defined(PTHREADS)' + print 'EXTERN GLNAME(_glapi_Dispatch)' + print 'EXTERN GLNAME(_gl_DispatchTSD)' + print 'EXTERN GLNAME(pthread_getspecific)' + print '' + print 'ALIGNTEXT16' + print 'GLNAME(_x86_get_dispatch):' + print '\tSUB_L(CONST(24), ESP)' + print '\tPUSH_L(GLNAME(_gl_DispatchTSD))' + print '\tCALL(GLNAME(pthread_getspecific))' + print '\tADD_L(CONST(28), ESP)' + print '\tRET' + print '#elif defined(THREADS)' + print 'EXTERN GLNAME(_glapi_get_dispatch)' + print '#endif' + print '' + + print '#if defined( GLX_USE_TLS ) && !defined( GLX_X86_READONLY_TEXT )' + print '\t\t.section\twtext, "awx", @progbits' + print '#endif /* defined( GLX_USE_TLS ) */' + + print '' + print '\t\tALIGNTEXT16' + print '\t\tGLOBL GLNAME(gl_dispatch_functions_start)' + print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_start))' + print 'GLNAME(gl_dispatch_functions_start):' + print '' + return + + + def printRealFooter(self): + print '' + print '\t\tGLOBL\tGLNAME(gl_dispatch_functions_end)' + print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_end))' + print '\t\tALIGNTEXT16' + print 'GLNAME(gl_dispatch_functions_end):' + print '' + print '#if defined(GLX_USE_TLS) && defined(__linux__)' + print ' .section ".note.ABI-tag", "a"' + print ' .p2align 2' + print ' .long 1f - 0f /* name length */' + print ' .long 3f - 2f /* data length */' + print ' .long 1 /* note length */' + print '0: .asciz "GNU" /* vendor name */' + print '1: .p2align 2' + print '2: .long 0 /* note data: the ABI tag */' + print ' .long 2,4,20 /* Minimum kernel version w/TLS */' + print '3: .p2align 2 /* pad out section */' + print '#endif /* GLX_USE_TLS */' + print '' + print '#if defined (__ELF__) && defined (__linux__)' + print ' .section .note.GNU-stack,"",%progbits' + print '#endif' + return + + + def printBody(self, api): + for f in api.functionIterateByOffset(): + name = f.dispatch_name() + stack = self.get_stack_size(f) + alt = "%s@%u" % (name, stack) + + print '\tGL_STUB(%s, %d, %s)' % (name, f.offset, alt) + + if not f.is_static_entry_point(f.name): + print '\tHIDDEN(GL_PREFIX(%s, %s))' % (name, alt) + + + for f in api.functionIterateByOffset(): + name = f.dispatch_name() + stack = self.get_stack_size(f) + alt = "%s@%u" % (name, stack) + + for n in f.entry_points: + if f.is_static_entry_point(n): + if n != f.name: + alt2 = "%s@%u" % (n, stack) + text = '\tGL_STUB_ALIAS(%s, %d, %s, %s, %s)' % (n, f.offset, alt2, name, alt) + + if f.has_different_protocol(n): + print '#ifndef GLX_INDIRECT_RENDERING' + print text + print '#endif' + else: + print text + + return + +def show_usage(): + print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0] + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + mode = "generic" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "m:f:") + except Exception,e: + show_usage() + + for (arg,val) in args: + if arg == '-m': + mode = val + elif arg == "-f": + file_name = val + + if mode == "generic": + printer = PrintGenericStubs() + else: + print "ERROR: Invalid mode \"%s\" specified." % mode + show_usage() + + api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) + printer.Print(api) diff --git a/src/mapi/glapi/gen/license.py b/src/mapi/glapi/gen/license.py new file mode 100644 index 0000000..0218164 --- /dev/null +++ b/src/mapi/glapi/gen/license.py @@ -0,0 +1,47 @@ +# (C) Copyright IBM Corporation 2004 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +bsd_license_template = """%s +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 +%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.""" diff --git a/src/mapi/glapi/gen/mesadef.py b/src/mapi/glapi/gen/mesadef.py new file mode 100644 index 0000000..38b0246 --- /dev/null +++ b/src/mapi/glapi/gen/mesadef.py @@ -0,0 +1,216 @@ +#!/usr/bin/env python + + +# Mesa 3-D graphics library +# Version: 4.1 +# +# 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. + + +# Generate the mesa.def file for Windows. +# +# Usage: +# mesadef.py >mesa.def +# Then copy to src/mesa/drivers/windows/gdi +# +# Dependencies: +# The apispec file must be in the current directory. + + + +import apiparser +import string + + +def PrintHead(): + print '; DO NOT EDIT - This file generated automatically by mesadef.py script' + print 'DESCRIPTION \'Mesa (OpenGL work-alike) for Win32\'' + print 'VERSION 6.0' + print ';' + print '; Module definition file for Mesa (OPENGL32.DLL)' + print ';' + print '; Note: The OpenGL functions use the STDCALL' + print '; function calling convention. Microsoft\'s' + print '; OPENGL32 uses this convention and so must the' + print '; Mesa OPENGL32 so that the Mesa DLL can be used' + print '; as a drop-in replacement.' + print ';' + print '; The linker exports STDCALL entry points with' + print '; \'decorated\' names; e.g., _glBegin@0, where the' + print '; trailing number is the number of bytes of ' + print '; parameter data pushed onto the stack. The' + print '; callee is responsible for popping this data' + print '; off the stack, usually via a RETF n instruction.' + print ';' + print '; However, the Microsoft OPENGL32.DLL does not export' + print '; the decorated names, even though the calling convention' + print '; is STDCALL. So, this module definition file is' + print '; needed to force the Mesa OPENGL32.DLL to export the' + print '; symbols in the same manner as the Microsoft DLL.' + print '; Were it not for this problem, this file would not' + print '; be needed (for the gl* functions) since the entry' + print '; points are compiled with dllexport declspec.' + print ';' + print '; However, this file is still needed to export "internal"' + print '; Mesa symbols for the benefit of the OSMESA32.DLL.' + print ';' + print 'EXPORTS' + return +#enddef + + +def PrintTail(): + print ';' + print '; WGL API' + print '\twglChoosePixelFormat' + print '\twglCopyContext' + print '\twglCreateContext' + print '\twglCreateLayerContext' + print '\twglDeleteContext' + print '\twglDescribeLayerPlane' + print '\twglDescribePixelFormat' + print '\twglGetCurrentContext' + print '\twglGetCurrentDC' + print '\twglGetExtensionsStringARB' + print '\twglGetLayerPaletteEntries' + print '\twglGetPixelFormat' + print '\twglGetProcAddress' + print '\twglMakeCurrent' + print '\twglRealizeLayerPalette' + print '\twglSetLayerPaletteEntries' + print '\twglSetPixelFormat' + print '\twglShareLists' + print '\twglSwapBuffers' + print '\twglSwapLayerBuffers' + print '\twglUseFontBitmapsA' + print '\twglUseFontBitmapsW' + print '\twglUseFontOutlinesA' + print '\twglUseFontOutlinesW' + print ';' + print '; Mesa internals - mostly for OSMESA' + print '\t_ac_CreateContext' + print '\t_ac_DestroyContext' + print '\t_ac_InvalidateState' + print '\t_glapi_get_context' + print '\t_glapi_get_proc_address' + print '\t_mesa_buffer_data' + print '\t_mesa_buffer_map' + print '\t_mesa_buffer_subdata' + print '\t_mesa_choose_tex_format' + print '\t_mesa_compressed_texture_size' + print '\t_mesa_create_framebuffer' + print '\t_mesa_create_visual' + print '\t_mesa_delete_buffer_object' + print '\t_mesa_delete_texture_object' + print '\t_mesa_destroy_framebuffer' + print '\t_mesa_destroy_visual' + print '\t_mesa_enable_1_3_extensions' + print '\t_mesa_enable_1_4_extensions' + print '\t_mesa_enable_1_5_extensions' + print '\t_mesa_enable_sw_extensions' + print '\t_mesa_error' + print '\t_mesa_free_context_data' + print '\t_mesa_get_current_context' + print '\t_mesa_init_default_imports' + print '\t_mesa_initialize_context' + print '\t_mesa_make_current' + print '\t_mesa_new_buffer_object' + print '\t_mesa_new_texture_object' + print '\t_mesa_problem' + print '\t_mesa_ResizeBuffersMESA' + print '\t_mesa_store_compressed_teximage1d' + print '\t_mesa_store_compressed_teximage2d' + print '\t_mesa_store_compressed_teximage3d' + print '\t_mesa_store_compressed_texsubimage1d' + print '\t_mesa_store_compressed_texsubimage2d' + print '\t_mesa_store_compressed_texsubimage3d' + print '\t_mesa_store_teximage1d' + print '\t_mesa_store_teximage2d' + print '\t_mesa_store_teximage3d' + print '\t_mesa_store_texsubimage1d' + print '\t_mesa_store_texsubimage2d' + print '\t_mesa_store_texsubimage3d' + print '\t_mesa_test_proxy_teximage' + print '\t_mesa_Viewport' + print '\t_mesa_meta_CopyColorSubTable' + print '\t_mesa_meta_CopyColorTable' + print '\t_mesa_meta_CopyConvolutionFilter1D' + print '\t_mesa_meta_CopyConvolutionFilter2D' + print '\t_mesa_meta_CopyTexImage1D' + print '\t_mesa_meta_CopyTexImage2D' + print '\t_mesa_meta_CopyTexSubImage1D' + print '\t_mesa_meta_CopyTexSubImage2D' + print '\t_mesa_meta_CopyTexSubImage3D' + print '\t_swrast_Accum' + print '\t_swrast_alloc_buffers' + print '\t_swrast_Bitmap' + print '\t_swrast_CopyPixels' + print '\t_swrast_DrawPixels' + print '\t_swrast_GetDeviceDriverReference' + print '\t_swrast_Clear' + print '\t_swrast_choose_line' + print '\t_swrast_choose_triangle' + print '\t_swrast_CreateContext' + print '\t_swrast_DestroyContext' + print '\t_swrast_InvalidateState' + print '\t_swrast_ReadPixels' + print '\t_swrast_zbuffer_address' + print '\t_swsetup_Wakeup' + print '\t_swsetup_CreateContext' + print '\t_swsetup_DestroyContext' + print '\t_swsetup_InvalidateState' + print '\t_tnl_CreateContext' + print '\t_tnl_DestroyContext' + print '\t_tnl_InvalidateState' + print '\t_tnl_MakeCurrent' + print '\t_tnl_run_pipeline' +#enddef + + +records = [] + +def FindOffset(funcName): + for (name, alias, offset) in records: + if name == funcName: + return offset + #endif + #endfor + return -1 +#enddef + + +def EmitEntry(name, returnType, argTypeList, argNameList, alias, offset): + if alias == '': + dispatchName = name + else: + dispatchName = alias + if offset < 0: + offset = FindOffset(dispatchName) + if offset >= 0 and string.find(name, "unused") == -1: + print '\tgl%s' % (name) + # save this info in case we need to look up an alias later + records.append((name, dispatchName, offset)) + +#enddef + + +PrintHead() +apiparser.ProcessSpecFile("APIspec", EmitEntry) +PrintTail() diff --git a/src/mapi/glapi/gen/remap_helper.py b/src/mapi/glapi/gen/remap_helper.py new file mode 100644 index 0000000..69b8e5e --- /dev/null +++ b/src/mapi/glapi/gen/remap_helper.py @@ -0,0 +1,218 @@ +#!/usr/bin/env python + +# Copyright (C) 2009 Chia-I Wu +# All Rights Reserved. +# +# This is based on extension_helper.py by Ian Romanick. +# +# 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 +# IBM 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. + +import gl_XML +import license +import sys, getopt, string + +def get_function_spec(func): + sig = "" + # derive parameter signature + for p in func.parameterIterator(): + if p.is_padding: + continue + # FIXME: This is a *really* ugly hack. :( + tn = p.type_expr.get_base_type_node() + if p.is_pointer(): + sig += 'p' + elif tn.integer: + sig += 'i' + elif tn.size == 4: + sig += 'f' + else: + sig += 'd' + + spec = [sig] + for ent in func.entry_points: + spec.append("gl" + ent) + + # spec is terminated by an empty string + spec.append('') + + return spec + +class PrintGlRemap(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "remap_helper.py (from Mesa)" + self.license = license.bsd_license_template % ("Copyright (C) 2009 Chia-I Wu ", "Chia-I Wu") + return + + + def printRealHeader(self): + print '#include "main/dispatch.h"' + print '#include "main/remap.h"' + print '' + return + + + def printBody(self, api): + pool_indices = {} + + print '/* this is internal to remap.c */' + print '#ifdef need_MESA_remap_table' + print '' + print 'static const char _mesa_function_pool[] =' + + # output string pool + index = 0; + for f in api.functionIterateAll(): + pool_indices[f] = index + + spec = get_function_spec(f) + + # a function has either assigned offset, fixed offset, + # or no offset + if f.assign_offset: + comments = "will be remapped" + elif f.offset > 0: + comments = "offset %d" % f.offset + else: + comments = "dynamic" + + print ' /* _mesa_function_pool[%d]: %s (%s) */' \ + % (index, f.name, comments) + for line in spec: + print ' "%s\\0"' % line + index += len(line) + 1 + print ' ;' + print '' + + print '/* these functions need to be remapped */' + print 'static const struct gl_function_pool_remap MESA_remap_table_functions[] = {' + # output all functions that need to be remapped + # iterate by offsets so that they are sorted by remap indices + for f in api.functionIterateByOffset(): + if not f.assign_offset: + continue + print ' { %5d, %s_remap_index },' \ + % (pool_indices[f], f.name) + print ' { -1, -1 }' + print '};' + print '' + + # collect functions by versions/extensions + extension_functions = {} + abi_extensions = [] + for f in api.functionIterateAll(): + for n in f.entry_points: + category, num = api.get_category_for_name(n) + # consider only GL_VERSION_X_Y or extensions + c = gl_XML.real_category_name(category) + if c.startswith("GL_"): + if not extension_functions.has_key(c): + extension_functions[c] = [] + extension_functions[c].append(f) + # remember the ext names of the ABI + if (f.is_abi() and n == f.name and + c not in abi_extensions): + abi_extensions.append(c) + # ignore the ABI itself + for ext in abi_extensions: + extension_functions.pop(ext) + + extensions = extension_functions.keys() + extensions.sort() + + # output ABI functions that have alternative names (with ext suffix) + print '/* these functions are in the ABI, but have alternative names */' + print 'static const struct gl_function_remap MESA_alt_functions[] = {' + for ext in extensions: + funcs = [] + for f in extension_functions[ext]: + # test if the function is in the ABI and has alt names + if f.is_abi() and len(f.entry_points) > 1: + funcs.append(f) + if not funcs: + continue + print ' /* from %s */' % ext + for f in funcs: + print ' { %5d, _gloffset_%s },' \ + % (pool_indices[f], f.name) + print ' { -1, -1 }' + print '};' + print '' + + print '#endif /* need_MESA_remap_table */' + print '' + + # output remap helpers for DRI drivers + + for ext in extensions: + funcs = [] + remapped = [] + for f in extension_functions[ext]: + if f.assign_offset: + # these are handled above + remapped.append(f) + else: + # these functions are either in the + # abi, or have offset -1 + funcs.append(f) + + print '#if defined(need_%s)' % (ext) + if remapped: + print '/* functions defined in MESA_remap_table_functions are excluded */' + + # output extension functions that need to be mapped + print 'static const struct gl_function_remap %s_functions[] = {' % (ext) + for f in funcs: + if f.offset >= 0: + print ' { %5d, _gloffset_%s },' \ + % (pool_indices[f], f.name) + else: + print ' { %5d, -1 }, /* %s */' % \ + (pool_indices[f], f.name) + print ' { -1, -1 }' + print '};' + + print '#endif' + print '' + + return + + +def show_usage(): + print "Usage: %s [-f input_file_name]" % sys.argv[0] + sys.exit(1) + +if __name__ == '__main__': + file_name = "gl_API.xml" + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:") + except Exception,e: + show_usage() + + for (arg,val) in args: + if arg == "-f": + file_name = val + + api = gl_XML.parse_GL_API( file_name ) + + printer = PrintGlRemap() + printer.Print( api ) diff --git a/src/mapi/glapi/gen/typeexpr.py b/src/mapi/glapi/gen/typeexpr.py new file mode 100644 index 0000000..8ba7de4 --- /dev/null +++ b/src/mapi/glapi/gen/typeexpr.py @@ -0,0 +1,292 @@ +#!/usr/bin/env python + +# (C) Copyright IBM Corporation 2005 +# 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 +# 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 +# IBM 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. +# +# Authors: +# Ian Romanick + +import string, copy + +class type_node: + def __init__(self): + self.pointer = 0 # bool + self.const = 0 # bool + self.signed = 1 # bool + self.integer = 1 # bool + + # If elements is set to non-zero, then field is an array. + self.elements = 0 + + self.name = None + self.size = 0 # type's size in bytes + return + + + def string(self): + """Return string representation of this type_node.""" + s = "" + + if self.pointer: + s = "* " + + if self.const: + s += "const " + + if not self.pointer: + if self.integer: + if self.signed: + s += "signed " + else: + s += "unsigned " + + if self.name: + s += "%s " % (self.name) + + return s + + +class type_table: + def __init__(self): + self.types_by_name = {} + return + + + def add_type(self, type_expr): + self.types_by_name[ type_expr.get_base_name() ] = type_expr + return + + + def find_type(self, name): + if name in self.types_by_name: + return self.types_by_name[ name ] + else: + return None + + +def create_initial_types(): + tt = type_table() + + basic_types = [ + ("char", 1, 1), + ("short", 2, 1), + ("int", 4, 1), + ("long", 4, 1), + ("float", 4, 0), + ("double", 8, 0), + ("enum", 4, 1) + ] + + for (type_name, type_size, integer) in basic_types: + te = type_expression(None) + tn = type_node() + tn.name = type_name + tn.size = type_size + tn.integer = integer + te.expr.append(tn) + tt.add_type( te ) + + type_expression.built_in_types = tt + return + + +class type_expression: + built_in_types = None + + def __init__(self, type_string, extra_types = None): + self.expr = [] + + if not type_string: + return + + self.original_string = type_string + + if not type_expression.built_in_types: + raise RuntimeError("create_initial_types must be called before creating type_expression objects.") + + # Replace '*' with ' * ' in type_string. Then, split the string + # into tokens, separated by spaces. + tokens = string.split( string.replace( type_string, "*", " * " ) ) + + const = 0 + t = None + signed = 0 + unsigned = 0 + + for i in tokens: + if i == "const": + if t and t.pointer: + t.const = 1 + else: + const = 1 + elif i == "signed": + signed = 1 + elif i == "unsigned": + unsigned = 1 + elif i == "*": + # This is a quirky special-case because of the + # way the C works for types. If 'unsigned' is + # specified all by itself, it is treated the + # same as "unsigned int". + + if unsigned: + self.set_base_type( "int", signed, unsigned, const, extra_types ) + const = 0 + signed = 0 + unsigned = 0 + + if not self.expr: + raise RuntimeError("Invalid type expression (dangling pointer)") + + if signed: + raise RuntimeError("Invalid type expression (signed / unsigned applied to pointer)") + + t = type_node() + t.pointer = 1 + self.expr.append( t ) + else: + if self.expr: + raise RuntimeError('Invalid type expression (garbage after pointer qualifier -> "%s")' % (self.original_string)) + + self.set_base_type( i, signed, unsigned, const, extra_types ) + const = 0 + signed = 0 + unsigned = 0 + + if signed and unsigned: + raise RuntimeError("Invalid type expression (both signed and unsigned specified)") + + + if const: + raise RuntimeError("Invalid type expression (dangling const)") + + if unsigned: + raise RuntimeError("Invalid type expression (dangling signed)") + + if signed: + raise RuntimeError("Invalid type expression (dangling unsigned)") + + return + + + def set_base_type(self, type_name, signed, unsigned, const, extra_types): + te = type_expression.built_in_types.find_type( type_name ) + if not te: + te = extra_types.find_type( type_name ) + + if not te: + raise RuntimeError('Unknown base type "%s".' % (type_name)) + + self.expr = copy.deepcopy(te.expr) + + t = self.expr[ len(self.expr) - 1 ] + t.const = const + if signed: + t.signed = 1 + elif unsigned: + t.signed = 0 + + + def set_base_type_node(self, tn): + self.expr = [tn] + return + + + def set_elements(self, count): + tn = self.expr[0] + + tn.elements = count + return + + + def string(self): + s = "" + for t in self.expr: + s += t.string() + + return s + + + def get_base_type_node(self): + return self.expr[0] + + + def get_base_name(self): + if len(self.expr): + return self.expr[0].name + else: + return None + + + def get_element_size(self): + tn = self.expr[0] + + if tn.elements: + return tn.elements * tn.size + else: + return tn.size + + + def get_element_count(self): + tn = self.expr[0] + return tn.elements + + + def get_stack_size(self): + tn = self.expr[ len(self.expr) - 1 ] + + if tn.elements or tn.pointer: + return 4 + elif not tn.integer: + return tn.size + else: + return 4 + + + def is_pointer(self): + tn = self.expr[ len(self.expr) - 1 ] + return tn.pointer + + + def format_string(self): + tn = self.expr[ len(self.expr) - 1 ] + if tn.pointer: + return "%p" + elif not tn.integer: + return "%f" + else: + return "%d" + + + +if __name__ == '__main__': + + types_to_try = [ "int", "int *", "const int *", "int * const", "const int * const", \ + "unsigned * const *", \ + "float", "const double", "double * const"] + + create_initial_types() + + for t in types_to_try: + print 'Trying "%s"...' % (t) + te = type_expression( t ) + print 'Got "%s" (%u, %u).' % (te.string(), te.get_stack_size(), te.get_element_size()) diff --git a/src/mapi/glapi/glapi.h b/src/mapi/glapi/glapi.h new file mode 100644 index 0000000..8cca504 --- /dev/null +++ b/src/mapi/glapi/glapi.h @@ -0,0 +1,182 @@ +/* + * Mesa 3-D graphics library + * Version: 7.1 + * + * Copyright (C) 1999-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. + */ + + +/** + * \mainpage Mesa GL API Module + * + * \section GLAPIIntroduction Introduction + * + * The Mesa GL API module is responsible for dispatching all the + * gl*() functions. All GL functions are dispatched by jumping through + * the current dispatch table (basically a struct full of function + * pointers.) + * + * A per-thread current dispatch table and per-thread current context + * pointer are managed by this module too. + * + * This module is intended to be non-Mesa-specific so it can be used + * with the X/DRI libGL also. + */ + + +#ifndef _GLAPI_H +#define _GLAPI_H + + +/* opengl.dll does not export _glapi_* */ +#if defined(_WIN32) +#define _GLAPI_NO_EXPORTS +#endif + +#ifdef _GLAPI_NO_EXPORTS +# define _GLAPI_EXPORT +#else /* _GLAPI_NO_EXPORTS */ +# ifdef _WIN32 +# ifdef _GLAPI_DLL_EXPORTS +# define _GLAPI_EXPORT __declspec(dllexport) +# else +# define _GLAPI_EXPORT __declspec(dllimport) +# endif +# elif defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define _GLAPI_EXPORT __attribute__((visibility("default"))) +# else +# define _GLAPI_EXPORT +# endif +#endif /* _GLAPI_NO_EXPORTS */ + + +/* Is this needed? It is incomplete anyway. */ +#ifdef USE_MGL_NAMESPACE +#define _glapi_set_dispatch _mglapi_set_dispatch +#define _glapi_get_dispatch _mglapi_get_dispatch +#define _glapi_set_context _mglapi_set_context +#define _glapi_get_context _mglapi_get_context +#define _glapi_Dispatch _mglapi_Dispatch +#define _glapi_Context _mglapi_Context +#endif + +#include "glapi/glthread.h" + +typedef void (*_glapi_proc)(void); +struct _glapi_table; + + +#if defined (GLX_USE_TLS) + +_GLAPI_EXPORT extern __thread struct _glapi_table * _glapi_tls_Dispatch + __attribute__((tls_model("initial-exec"))); + +_GLAPI_EXPORT extern __thread void * _glapi_tls_Context + __attribute__((tls_model("initial-exec"))); + +_GLAPI_EXPORT extern const struct _glapi_table *_glapi_Dispatch; +_GLAPI_EXPORT extern const void *_glapi_Context; + +# define GET_DISPATCH() _glapi_tls_Dispatch +# define GET_CURRENT_CONTEXT(C) struct gl_context *C = (struct gl_context *) _glapi_tls_Context + +#else + +_GLAPI_EXPORT extern struct _glapi_table *_glapi_Dispatch; +_GLAPI_EXPORT extern void *_glapi_Context; + +# ifdef THREADS + +# define GET_DISPATCH() \ + (likely(_glapi_Dispatch) ? _glapi_Dispatch : _glapi_get_dispatch()) + +# define GET_CURRENT_CONTEXT(C) struct gl_context *C = (struct gl_context *) \ + (likely(_glapi_Context) ? _glapi_Context : _glapi_get_context()) + +# else + +# define GET_DISPATCH() _glapi_Dispatch +# define GET_CURRENT_CONTEXT(C) struct gl_context *C = (struct gl_context *) _glapi_Context + +# endif + +#endif /* defined (GLX_USE_TLS) */ + + +void +_glapi_destroy_multithread(void); + + +_GLAPI_EXPORT void +_glapi_check_multithread(void); + + +_GLAPI_EXPORT void +_glapi_set_context(void *context); + + +_GLAPI_EXPORT void * +_glapi_get_context(void); + + +_GLAPI_EXPORT void +_glapi_set_dispatch(struct _glapi_table *dispatch); + + +_GLAPI_EXPORT struct _glapi_table * +_glapi_get_dispatch(void); + + +_GLAPI_EXPORT unsigned int +_glapi_get_dispatch_table_size(void); + + +_GLAPI_EXPORT int +_glapi_add_dispatch( const char * const * function_names, + const char * parameter_signature ); + +_GLAPI_EXPORT int +_glapi_get_proc_offset(const char *funcName); + + +_GLAPI_EXPORT _glapi_proc +_glapi_get_proc_address(const char *funcName); + + +_GLAPI_EXPORT const char * +_glapi_get_proc_name(unsigned int offset); + + +_GLAPI_EXPORT unsigned long +_glthread_GetID(void); + + +/* + * These stubs are kept so that the old DRI drivers still load. + */ +_GLAPI_EXPORT void +_glapi_noop_enable_warnings(unsigned char enable); + + +_GLAPI_EXPORT void +_glapi_set_warning_func(_glapi_proc func); + + +#endif /* _GLAPI_H */ diff --git a/src/mapi/glapi/glapi_dispatch.c b/src/mapi/glapi/glapi_dispatch.c new file mode 100644 index 0000000..989f4a3 --- /dev/null +++ b/src/mapi/glapi/glapi_dispatch.c @@ -0,0 +1,92 @@ +/* + * Mesa 3-D graphics library + * Version: 6.3 + * + * Copyright (C) 1999-2004 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. + */ + + +/** + * \file glapi_dispatch.c + * + * This file generates all the gl* function entrypoints. This code is not + * used if optimized assembly stubs are available (e.g., using + * glapi/glapi_x86.S on IA32 or glapi/glapi_sparc.S on SPARC). + * + * \note + * This file is also used to build the client-side libGL that loads DRI-based + * device drivers. At build-time it is symlinked to src/glx. + * + * \author Brian Paul + */ + +#include "glapi/glapi_priv.h" +#include "glapi/glapitable.h" + + +#if !(defined(USE_X86_ASM) || defined(USE_X86_64_ASM) || defined(USE_SPARC_ASM)) + +#if defined(WIN32) +#define KEYWORD1 GLAPI +#else +#define KEYWORD1 PUBLIC +#endif + +#define KEYWORD2 GLAPIENTRY + +#if defined(USE_MGL_NAMESPACE) +#define NAME(func) mgl##func +#else +#define NAME(func) gl##func +#endif + +#if 0 /* Use this to log GL calls to stdout (for DEBUG only!) */ + +#define F stdout +#define DISPATCH(FUNC, ARGS, MESSAGE) \ + fprintf MESSAGE; \ + GET_DISPATCH()->FUNC ARGS + +#define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \ + fprintf MESSAGE; \ + return GET_DISPATCH()->FUNC ARGS + +#else + +#define DISPATCH(FUNC, ARGS, MESSAGE) \ + GET_DISPATCH()->FUNC ARGS + +#define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \ + return GET_DISPATCH()->FUNC ARGS + +#endif /* logging */ + + +#ifndef GLAPIENTRY +#define GLAPIENTRY +#endif + +#ifdef GLX_INDIRECT_RENDERING +/* those link to libglapi.a should provide the entry points */ +#define _GLAPI_SKIP_PROTO_ENTRY_POINTS +#endif +#include "glapi/glapitemp.h" + +#endif /* USE_X86_ASM */ diff --git a/src/mapi/glapi/glapi_entrypoint.c b/src/mapi/glapi/glapi_entrypoint.c new file mode 100644 index 0000000..993ccb9 --- /dev/null +++ b/src/mapi/glapi/glapi_entrypoint.c @@ -0,0 +1,344 @@ +/* + * Mesa 3-D graphics library + * Version: 7.1 + * + * Copyright (C) 1999-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. + */ + +/** + * \file glapi_entrypoint.c + * + * Arch-specific code for manipulating GL API entrypoints (dispatch stubs). + */ + + +#include "glapi/glapi_priv.h" +#include "mapi/u_execmem.h" + + +#ifdef USE_X86_ASM + +#if defined( GLX_USE_TLS ) +extern GLubyte gl_dispatch_functions_start[]; +extern GLubyte gl_dispatch_functions_end[]; +#else +extern const GLubyte gl_dispatch_functions_start[]; +#endif + +#endif /* USE_X86_ASM */ + + +#if defined(DISPATCH_FUNCTION_SIZE) + +_glapi_proc +get_entrypoint_address(unsigned int functionOffset) +{ + return (_glapi_proc) (gl_dispatch_functions_start + + (DISPATCH_FUNCTION_SIZE * functionOffset)); +} + +#endif + + +#if defined(USE_X86_ASM) + +/** + * Perform platform-specific GL API entry-point fixups. + */ +static void +init_glapi_relocs( void ) +{ +#if defined(GLX_USE_TLS) && !defined(GLX_X86_READONLY_TEXT) + extern unsigned long _x86_get_dispatch(void); + char run_time_patch[] = { + 0x65, 0xa1, 0, 0, 0, 0 /* movl %gs:0,%eax */ + }; + GLuint *offset = (GLuint *) &run_time_patch[2]; /* 32-bits for x86/32 */ + const GLubyte * const get_disp = (const GLubyte *) run_time_patch; + GLubyte * curr_func = (GLubyte *) gl_dispatch_functions_start; + + *offset = _x86_get_dispatch(); + while ( curr_func != (GLubyte *) gl_dispatch_functions_end ) { + (void) memcpy( curr_func, get_disp, sizeof(run_time_patch)); + curr_func += DISPATCH_FUNCTION_SIZE; + } +#endif +} + + +/** + * Generate a dispatch function (entrypoint) which jumps through + * the given slot number (offset) in the current dispatch table. + * We need assembly language in order to accomplish this. + */ +_glapi_proc +generate_entrypoint(unsigned int functionOffset) +{ + /* 32 is chosen as something of a magic offset. For x86, the dispatch + * at offset 32 is the first one where the offset in the + * "jmp OFFSET*4(%eax)" can't be encoded in a single byte. + */ + const GLubyte * const template_func = gl_dispatch_functions_start + + (DISPATCH_FUNCTION_SIZE * 32); + GLubyte * const code = (GLubyte *) u_execmem_alloc(DISPATCH_FUNCTION_SIZE); + + + if ( code != NULL ) { + (void) memcpy(code, template_func, DISPATCH_FUNCTION_SIZE); + fill_in_entrypoint_offset( (_glapi_proc) code, functionOffset ); + } + + return (_glapi_proc) code; +} + + +/** + * This function inserts a new dispatch offset into the assembly language + * stub that was generated with the preceeding function. + */ +void +fill_in_entrypoint_offset(_glapi_proc entrypoint, unsigned int offset) +{ + GLubyte * const code = (GLubyte *) entrypoint; + +#if defined(GLX_USE_TLS) + *((unsigned int *)(code + 8)) = 4 * offset; +#elif defined(THREADS) + *((unsigned int *)(code + 11)) = 4 * offset; + *((unsigned int *)(code + 22)) = 4 * offset; +#else + *((unsigned int *)(code + 7)) = 4 * offset; +#endif +} + + +#elif defined(USE_SPARC_ASM) + +extern void __glapi_sparc_icache_flush(unsigned int *); + +static void +init_glapi_relocs( void ) +{ +#if defined(PTHREADS) || defined(GLX_USE_TLS) + static const unsigned int template[] = { +#ifdef GLX_USE_TLS + 0x05000000, /* sethi %hi(_glapi_tls_Dispatch), %g2 */ + 0x8730e00a, /* srl %g3, 10, %g3 */ + 0x8410a000, /* or %g2, %lo(_glapi_tls_Dispatch), %g2 */ +#ifdef __arch64__ + 0xc259c002, /* ldx [%g7 + %g2], %g1 */ + 0xc2584003, /* ldx [%g1 + %g3], %g1 */ +#else + 0xc201c002, /* ld [%g7 + %g2], %g1 */ + 0xc2004003, /* ld [%g1 + %g3], %g1 */ +#endif + 0x81c04000, /* jmp %g1 */ + 0x01000000, /* nop */ +#else +#ifdef __arch64__ + 0x03000000, /* 64-bit 0x00 --> sethi %hh(_glapi_Dispatch), %g1 */ + 0x05000000, /* 64-bit 0x04 --> sethi %lm(_glapi_Dispatch), %g2 */ + 0x82106000, /* 64-bit 0x08 --> or %g1, %hm(_glapi_Dispatch), %g1 */ + 0x8730e00a, /* 64-bit 0x0c --> srl %g3, 10, %g3 */ + 0x83287020, /* 64-bit 0x10 --> sllx %g1, 32, %g1 */ + 0x82004002, /* 64-bit 0x14 --> add %g1, %g2, %g1 */ + 0xc2586000, /* 64-bit 0x18 --> ldx [%g1 + %lo(_glapi_Dispatch)], %g1 */ +#else + 0x03000000, /* 32-bit 0x00 --> sethi %hi(_glapi_Dispatch), %g1 */ + 0x8730e00a, /* 32-bit 0x04 --> srl %g3, 10, %g3 */ + 0xc2006000, /* 32-bit 0x08 --> ld [%g1 + %lo(_glapi_Dispatch)], %g1 */ +#endif + 0x80a06000, /* --> cmp %g1, 0 */ + 0x02800005, /* --> be +4*5 */ + 0x01000000, /* --> nop */ +#ifdef __arch64__ + 0xc2584003, /* 64-bit --> ldx [%g1 + %g3], %g1 */ +#else + 0xc2004003, /* 32-bit --> ld [%g1 + %g3], %g1 */ +#endif + 0x81c04000, /* --> jmp %g1 */ + 0x01000000, /* --> nop */ +#ifdef __arch64__ + 0x9de3bf80, /* 64-bit --> save %sp, -128, %sp */ +#else + 0x9de3bfc0, /* 32-bit --> save %sp, -64, %sp */ +#endif + 0xa0100003, /* --> mov %g3, %l0 */ + 0x40000000, /* --> call _glapi_get_dispatch */ + 0x01000000, /* --> nop */ + 0x82100008, /* --> mov %o0, %g1 */ + 0x86100010, /* --> mov %l0, %g3 */ + 0x10bffff7, /* --> ba -4*9 */ + 0x81e80000, /* --> restore */ +#endif + }; +#ifdef GLX_USE_TLS + extern unsigned int __glapi_sparc_tls_stub; + extern unsigned long __glapi_sparc_get_dispatch(void); + unsigned int *code = &__glapi_sparc_tls_stub; + unsigned long dispatch = __glapi_sparc_get_dispatch(); +#else + extern unsigned int __glapi_sparc_pthread_stub; + unsigned int *code = &__glapi_sparc_pthread_stub; + unsigned long dispatch = (unsigned long) &_glapi_Dispatch; + unsigned long call_dest = (unsigned long ) &_glapi_get_dispatch; + int idx; +#endif + +#ifdef GLX_USE_TLS + code[0] = template[0] | (dispatch >> 10); + code[1] = template[1]; + __glapi_sparc_icache_flush(&code[0]); + code[2] = template[2] | (dispatch & 0x3ff); + code[3] = template[3]; + __glapi_sparc_icache_flush(&code[2]); + code[4] = template[4]; + code[5] = template[5]; + __glapi_sparc_icache_flush(&code[4]); + code[6] = template[6]; + __glapi_sparc_icache_flush(&code[6]); +#else +#if defined(__arch64__) + code[0] = template[0] | (dispatch >> (32 + 10)); + code[1] = template[1] | ((dispatch & 0xffffffff) >> 10); + __glapi_sparc_icache_flush(&code[0]); + code[2] = template[2] | ((dispatch >> 32) & 0x3ff); + code[3] = template[3]; + __glapi_sparc_icache_flush(&code[2]); + code[4] = template[4]; + code[5] = template[5]; + __glapi_sparc_icache_flush(&code[4]); + code[6] = template[6] | (dispatch & 0x3ff); + idx = 7; +#else + code[0] = template[0] | (dispatch >> 10); + code[1] = template[1]; + __glapi_sparc_icache_flush(&code[0]); + code[2] = template[2] | (dispatch & 0x3ff); + idx = 3; +#endif + code[idx + 0] = template[idx + 0]; + __glapi_sparc_icache_flush(&code[idx - 1]); + code[idx + 1] = template[idx + 1]; + code[idx + 2] = template[idx + 2]; + __glapi_sparc_icache_flush(&code[idx + 1]); + code[idx + 3] = template[idx + 3]; + code[idx + 4] = template[idx + 4]; + __glapi_sparc_icache_flush(&code[idx + 3]); + code[idx + 5] = template[idx + 5]; + code[idx + 6] = template[idx + 6]; + __glapi_sparc_icache_flush(&code[idx + 5]); + code[idx + 7] = template[idx + 7]; + code[idx + 8] = template[idx + 8] | + (((call_dest - ((unsigned long) &code[idx + 8])) + >> 2) & 0x3fffffff); + __glapi_sparc_icache_flush(&code[idx + 7]); + code[idx + 9] = template[idx + 9]; + code[idx + 10] = template[idx + 10]; + __glapi_sparc_icache_flush(&code[idx + 9]); + code[idx + 11] = template[idx + 11]; + code[idx + 12] = template[idx + 12]; + __glapi_sparc_icache_flush(&code[idx + 11]); + code[idx + 13] = template[idx + 13]; + __glapi_sparc_icache_flush(&code[idx + 13]); +#endif +#endif +} + + +_glapi_proc +generate_entrypoint(GLuint functionOffset) +{ +#if defined(PTHREADS) || defined(GLX_USE_TLS) + static const unsigned int template[] = { + 0x07000000, /* sethi %hi(0), %g3 */ + 0x8210000f, /* mov %o7, %g1 */ + 0x40000000, /* call */ + 0x9e100001, /* mov %g1, %o7 */ + }; +#ifdef GLX_USE_TLS + extern unsigned int __glapi_sparc_tls_stub; + unsigned long call_dest = (unsigned long ) &__glapi_sparc_tls_stub; +#else + extern unsigned int __glapi_sparc_pthread_stub; + unsigned long call_dest = (unsigned long ) &__glapi_sparc_pthread_stub; +#endif + unsigned int *code = (unsigned int *) u_execmem_alloc(sizeof(template)); + if (code) { + code[0] = template[0] | (functionOffset & 0x3fffff); + code[1] = template[1]; + __glapi_sparc_icache_flush(&code[0]); + code[2] = template[2] | + (((call_dest - ((unsigned long) &code[2])) + >> 2) & 0x3fffffff); + code[3] = template[3]; + __glapi_sparc_icache_flush(&code[2]); + } + return (_glapi_proc) code; +#endif +} + + +void +fill_in_entrypoint_offset(_glapi_proc entrypoint, GLuint offset) +{ + unsigned int *code = (unsigned int *) entrypoint; + + code[0] &= ~0x3fffff; + code[0] |= (offset * sizeof(void *)) & 0x3fffff; + __glapi_sparc_icache_flush(&code[0]); +} + + +#else /* USE_*_ASM */ + +static void +init_glapi_relocs( void ) +{ +} + + +_glapi_proc +generate_entrypoint(GLuint functionOffset) +{ + (void) functionOffset; + return NULL; +} + + +void +fill_in_entrypoint_offset(_glapi_proc entrypoint, GLuint offset) +{ + /* an unimplemented architecture */ + (void) entrypoint; + (void) offset; +} + +#endif /* USE_*_ASM */ + + +void +init_glapi_relocs_once( void ) +{ +#if defined(PTHREADS) || defined(GLX_USE_TLS) + static pthread_once_t once_control = PTHREAD_ONCE_INIT; + pthread_once( & once_control, init_glapi_relocs ); +#endif +} diff --git a/src/mapi/glapi/glapi_getproc.c b/src/mapi/glapi/glapi_getproc.c new file mode 100644 index 0000000..0a6ff77 --- /dev/null +++ b/src/mapi/glapi/glapi_getproc.c @@ -0,0 +1,666 @@ +/* + * Mesa 3-D graphics library + * Version: 7.1 + * + * Copyright (C) 1999-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. + */ + +/** + * \file glapi_getproc.c + * + * Code for implementing glXGetProcAddress(), etc. + * This was originally in glapi.c but refactored out. + */ + + +#include "glapi/glapi_priv.h" +#include "glapi/glapitable.h" + + +#define FIRST_DYNAMIC_OFFSET (sizeof(struct _glapi_table) / sizeof(void *)) + + +/********************************************************************** + * Static function management. + */ + + +#if !defined(DISPATCH_FUNCTION_SIZE) +# define NEED_FUNCTION_POINTER +#endif +#include "glapi/glprocs.h" + + +/** + * Search the table of static entrypoint functions for the named function + * and return the corresponding glprocs_table_t entry. + */ +static const glprocs_table_t * +get_static_proc( const char * n ) +{ + GLuint i; + for (i = 0; static_functions[i].Name_offset >= 0; i++) { + const char *testName = gl_string_table + static_functions[i].Name_offset; +#ifdef MANGLE + /* skip the prefix on the name */ + if (strcmp(testName, n + 1) == 0) +#else + if (strcmp(testName, n) == 0) +#endif + { + return &static_functions[i]; + } + } + return NULL; +} + + +/** + * Return dispatch table offset of the named static (built-in) function. + * Return -1 if function not found. + */ +static GLint +get_static_proc_offset(const char *funcName) +{ + const glprocs_table_t * const f = get_static_proc( funcName ); + if (f == NULL) { + return -1; + } + + return f->Offset; +} + + + +/** + * Return dispatch function address for the named static (built-in) function. + * Return NULL if function not found. + */ +static _glapi_proc +get_static_proc_address(const char *funcName) +{ + const glprocs_table_t * const f = get_static_proc( funcName ); + if (f == NULL) { + return NULL; + } + +#if defined(DISPATCH_FUNCTION_SIZE) && defined(GLX_INDIRECT_RENDERING) + return (f->Address == NULL) + ? get_entrypoint_address(f->Offset) + : f->Address; +#elif defined(DISPATCH_FUNCTION_SIZE) + return get_entrypoint_address(f->Offset); +#else + return f->Address; +#endif +} + + + +/** + * Return the name of the function at the given offset in the dispatch + * table. For debugging only. + */ +static const char * +get_static_proc_name( GLuint offset ) +{ + GLuint i; + for (i = 0; static_functions[i].Name_offset >= 0; i++) { + if (static_functions[i].Offset == offset) { + return gl_string_table + static_functions[i].Name_offset; + } + } + return NULL; +} + + + +/********************************************************************** + * Extension function management. + */ + + +/** + * Track information about a function added to the GL API. + */ +struct _glapi_function { + /** + * Name of the function. + */ + const char * name; + + + /** + * Text string that describes the types of the parameters passed to the + * named function. Parameter types are converted to characters using the + * following rules: + * - 'i' for \c GLint, \c GLuint, and \c GLenum + * - 'p' for any pointer type + * - 'f' for \c GLfloat and \c GLclampf + * - 'd' for \c GLdouble and \c GLclampd + */ + const char * parameter_signature; + + + /** + * Offset in the dispatch table where the pointer to the real function is + * located. If the driver has not requested that the named function be + * added to the dispatch table, this will have the value ~0. + */ + unsigned dispatch_offset; + + + /** + * Pointer to the dispatch stub for the named function. + * + * \todo + * The semantic of this field should be changed slightly. Currently, it + * is always expected to be non-\c NULL. However, it would be better to + * only allocate the entry-point stub when the application requests the + * function via \c glXGetProcAddress. This would save memory for all the + * functions that the driver exports but that the application never wants + * to call. + */ + _glapi_proc dispatch_stub; +}; + + +static struct _glapi_function ExtEntryTable[MAX_EXTENSION_FUNCS]; +static GLuint NumExtEntryPoints = 0; + + +static struct _glapi_function * +get_extension_proc(const char *funcName) +{ + GLuint i; + for (i = 0; i < NumExtEntryPoints; i++) { + if (strcmp(ExtEntryTable[i].name, funcName) == 0) { + return & ExtEntryTable[i]; + } + } + return NULL; +} + + +static GLint +get_extension_proc_offset(const char *funcName) +{ + const struct _glapi_function * const f = get_extension_proc( funcName ); + if (f == NULL) { + return -1; + } + + return f->dispatch_offset; +} + + +static _glapi_proc +get_extension_proc_address(const char *funcName) +{ + const struct _glapi_function * const f = get_extension_proc( funcName ); + if (f == NULL) { + return NULL; + } + + return f->dispatch_stub; +} + + +static const char * +get_extension_proc_name(GLuint offset) +{ + GLuint i; + for (i = 0; i < NumExtEntryPoints; i++) { + if (ExtEntryTable[i].dispatch_offset == offset) { + return ExtEntryTable[i].name; + } + } + return NULL; +} + + +/** + * strdup() is actually not a standard ANSI C or POSIX routine. + * Irix will not define it if ANSI mode is in effect. + */ +static char * +str_dup(const char *str) +{ + char *copy; + copy = (char*) malloc(strlen(str) + 1); + if (!copy) + return NULL; + strcpy(copy, str); + return copy; +} + + +/** + * Generate new entrypoint + * + * Use a temporary dispatch offset of ~0 (i.e. -1). Later, when the driver + * calls \c _glapi_add_dispatch we'll put in the proper offset. If that + * never happens, and the user calls this function, he'll segfault. That's + * what you get when you try calling a GL function that doesn't really exist. + * + * \param funcName Name of the function to create an entry-point for. + * + * \sa _glapi_add_entrypoint + */ + +static struct _glapi_function * +add_function_name( const char * funcName ) +{ + struct _glapi_function * entry = NULL; + _glapi_proc entrypoint = NULL; + char * name_dup = NULL; + + if (NumExtEntryPoints >= MAX_EXTENSION_FUNCS) + return NULL; + + if (funcName == NULL) + return NULL; + + name_dup = str_dup(funcName); + if (name_dup == NULL) + return NULL; + + entrypoint = generate_entrypoint(~0); + + if (entrypoint == NULL) { + free(name_dup); + return NULL; + } + + entry = & ExtEntryTable[NumExtEntryPoints]; + NumExtEntryPoints++; + + entry->name = name_dup; + entry->parameter_signature = NULL; + entry->dispatch_offset = ~0; + entry->dispatch_stub = entrypoint; + + return entry; +} + + +static struct _glapi_function * +set_entry_info( struct _glapi_function * entry, const char * signature, unsigned offset ) +{ + char * sig_dup = NULL; + + if (signature == NULL) + return NULL; + + sig_dup = str_dup(signature); + if (sig_dup == NULL) + return NULL; + + fill_in_entrypoint_offset(entry->dispatch_stub, offset); + + entry->parameter_signature = sig_dup; + entry->dispatch_offset = offset; + + return entry; +} + + +/** + * Fill-in the dispatch stub for the named function. + * + * This function is intended to be called by a hardware driver. When called, + * a dispatch stub may be created created for the function. A pointer to this + * dispatch function will be returned by glXGetProcAddress. + * + * \param function_names Array of pointers to function names that should + * share a common dispatch offset. + * \param parameter_signature String representing the types of the parameters + * passed to the named function. Parameter types + * are converted to characters using the following + * rules: + * - 'i' for \c GLint, \c GLuint, and \c GLenum + * - 'p' for any pointer type + * - 'f' for \c GLfloat and \c GLclampf + * - 'd' for \c GLdouble and \c GLclampd + * + * \returns + * The offset in the dispatch table of the named function. A pointer to the + * driver's implementation of the named function should be stored at + * \c dispatch_table[\c offset]. Return -1 if error/problem. + * + * \sa glXGetProcAddress + * + * \warning + * This function can only handle up to 8 names at a time. As far as I know, + * the maximum number of names ever associated with an existing GL function is + * 4 (\c glPointParameterfSGIS, \c glPointParameterfEXT, + * \c glPointParameterfARB, and \c glPointParameterf), so this should not be + * too painful of a limitation. + * + * \todo + * Determine whether or not \c parameter_signature should be allowed to be + * \c NULL. It doesn't seem like much of a hardship for drivers to have to + * pass in an empty string. + * + * \todo + * Determine if code should be added to reject function names that start with + * 'glX'. + * + * \bug + * Add code to compare \c parameter_signature with the parameter signature of + * a static function. In order to do that, we need to find a way to \b get + * the parameter signature of a static function. + */ + +int +_glapi_add_dispatch( const char * const * function_names, + const char * parameter_signature ) +{ + static int next_dynamic_offset = FIRST_DYNAMIC_OFFSET; + const char * const real_sig = (parameter_signature != NULL) + ? parameter_signature : ""; + struct _glapi_function * entry[8]; + GLboolean is_static[8]; + unsigned i; + int offset = ~0; + + init_glapi_relocs_once(); + + (void) memset( is_static, 0, sizeof( is_static ) ); + (void) memset( entry, 0, sizeof( entry ) ); + + /* Find the _single_ dispatch offset for all function names that already + * exist (and have a dispatch offset). + */ + + for ( i = 0 ; function_names[i] != NULL ; i++ ) { + const char * funcName = function_names[i]; + int static_offset; + int extension_offset; + + if (funcName[0] != 'g' || funcName[1] != 'l') + return -1; + + /* search built-in functions */ + static_offset = get_static_proc_offset(funcName); + + if (static_offset >= 0) { + + is_static[i] = GL_TRUE; + + /* FIXME: Make sure the parameter signatures match! How do we get + * FIXME: the parameter signature for static functions? + */ + + if ( (offset != ~0) && (static_offset != offset) ) { + return -1; + } + + offset = static_offset; + + continue; + } + + /* search added extension functions */ + entry[i] = get_extension_proc(funcName); + + if (entry[i] != NULL) { + extension_offset = entry[i]->dispatch_offset; + + /* The offset may be ~0 if the function name was added by + * glXGetProcAddress but never filled in by the driver. + */ + + if (extension_offset == ~0) { + continue; + } + + if (strcmp(real_sig, entry[i]->parameter_signature) != 0) { + return -1; + } + + if ( (offset != ~0) && (extension_offset != offset) ) { + return -1; + } + + offset = extension_offset; + } + } + + /* If all function names are either new (or with no dispatch offset), + * allocate a new dispatch offset. + */ + + if (offset == ~0) { + offset = next_dynamic_offset; + next_dynamic_offset++; + } + + /* Fill in the dispatch offset for the new function names (and those with + * no dispatch offset). + */ + + for ( i = 0 ; function_names[i] != NULL ; i++ ) { + if (is_static[i]) { + continue; + } + + /* generate entrypoints for new function names */ + if (entry[i] == NULL) { + entry[i] = add_function_name( function_names[i] ); + if (entry[i] == NULL) { + /* FIXME: Possible memory leak here. */ + return -1; + } + } + + if (entry[i]->dispatch_offset == ~0) { + set_entry_info( entry[i], real_sig, offset ); + } + } + + return offset; +} + + +/** + * Return offset of entrypoint for named function within dispatch table. + */ +GLint +_glapi_get_proc_offset(const char *funcName) +{ + GLint offset; + + /* search extension functions first */ + offset = get_extension_proc_offset(funcName); + if (offset >= 0) + return offset; + + /* search static functions */ + return get_static_proc_offset(funcName); +} + + + +/** + * Return pointer to the named function. If the function name isn't found + * in the name of static functions, try generating a new API entrypoint on + * the fly with assembly language. + */ +_glapi_proc +_glapi_get_proc_address(const char *funcName) +{ + _glapi_proc func; + struct _glapi_function * entry; + + init_glapi_relocs_once(); + +#ifdef MANGLE + /* skip the prefix on the name */ + if (funcName[1] != 'g' || funcName[2] != 'l') + return NULL; +#else + if (funcName[0] != 'g' || funcName[1] != 'l') + return NULL; +#endif + + /* search extension functions first */ + func = get_extension_proc_address(funcName); + if (func) + return func; + + /* search static functions */ + func = get_static_proc_address(funcName); + if (func) + return func; + + /* generate entrypoint, dispatch offset must be filled in by the driver */ + entry = add_function_name(funcName); + if (entry == NULL) + return NULL; + + return entry->dispatch_stub; +} + + + +/** + * Return the name of the function at the given dispatch offset. + * This is only intended for debugging. + */ +const char * +_glapi_get_proc_name(GLuint offset) +{ + const char * n; + + /* search built-in functions */ + n = get_static_proc_name(offset); + if ( n != NULL ) { + return n; + } + + /* search added extension functions */ + return get_extension_proc_name(offset); +} + + + +/********************************************************************** + * GL API table functions. + */ + + +/** + * Return size of dispatch table struct as number of functions (or + * slots). + */ +GLuint +_glapi_get_dispatch_table_size(void) +{ + /* + * The dispatch table size (number of entries) is the size of the + * _glapi_table struct plus the number of dynamic entries we can add. + * The extra slots can be filled in by DRI drivers that register new + * extension functions. + */ + return FIRST_DYNAMIC_OFFSET + MAX_EXTENSION_FUNCS; +} + + +/** + * Make sure there are no NULL pointers in the given dispatch table. + * Intended for debugging purposes. + */ +void +_glapi_check_table_not_null(const struct _glapi_table *table) +{ +#ifdef EXTRA_DEBUG /* set to DEBUG for extra DEBUG */ + const GLuint entries = _glapi_get_dispatch_table_size(); + const void **tab = (const void **) table; + GLuint i; + for (i = 1; i < entries; i++) { + assert(tab[i]); + } +#else + (void) table; +#endif +} + + +/** + * Do some spot checks to be sure that the dispatch table + * slots are assigned correctly. For debugging only. + */ +void +_glapi_check_table(const struct _glapi_table *table) +{ +#ifdef EXTRA_DEBUG /* set to DEBUG for extra DEBUG */ + { + GLuint BeginOffset = _glapi_get_proc_offset("glBegin"); + char *BeginFunc = (char*) &table->Begin; + GLuint offset = (BeginFunc - (char *) table) / sizeof(void *); + assert(BeginOffset == offset); + } + { + GLuint viewportOffset = _glapi_get_proc_offset("glViewport"); + char *viewportFunc = (char*) &table->Viewport; + GLuint offset = (viewportFunc - (char *) table) / sizeof(void *); + assert(viewportOffset == offset); + } + { + GLuint VertexPointerOffset = _glapi_get_proc_offset("glVertexPointer"); + char *VertexPointerFunc = (char*) &table->VertexPointer; + GLuint offset = (VertexPointerFunc - (char *) table) / sizeof(void *); + assert(VertexPointerOffset == offset); + } + { + GLuint ResetMinMaxOffset = _glapi_get_proc_offset("glResetMinmax"); + char *ResetMinMaxFunc = (char*) &table->ResetMinmax; + GLuint offset = (ResetMinMaxFunc - (char *) table) / sizeof(void *); + assert(ResetMinMaxOffset == offset); + } + { + GLuint blendColorOffset = _glapi_get_proc_offset("glBlendColor"); + char *blendColorFunc = (char*) &table->BlendColor; + GLuint offset = (blendColorFunc - (char *) table) / sizeof(void *); + assert(blendColorOffset == offset); + } + { + GLuint secondaryColor3fOffset = _glapi_get_proc_offset("glSecondaryColor3fEXT"); + char *secondaryColor3fFunc = (char*) &table->SecondaryColor3fEXT; + GLuint offset = (secondaryColor3fFunc - (char *) table) / sizeof(void *); + assert(secondaryColor3fOffset == offset); + } + { + GLuint pointParameterivOffset = _glapi_get_proc_offset("glPointParameterivNV"); + char *pointParameterivFunc = (char*) &table->PointParameterivNV; + GLuint offset = (pointParameterivFunc - (char *) table) / sizeof(void *); + assert(pointParameterivOffset == offset); + } + { + GLuint setFenceOffset = _glapi_get_proc_offset("glSetFenceNV"); + char *setFenceFunc = (char*) &table->SetFenceNV; + GLuint offset = (setFenceFunc - (char *) table) / sizeof(void *); + assert(setFenceOffset == offset); + } +#else + (void) table; +#endif +} diff --git a/src/mapi/glapi/glapi_nop.c b/src/mapi/glapi/glapi_nop.c new file mode 100644 index 0000000..9b09297 --- /dev/null +++ b/src/mapi/glapi/glapi_nop.c @@ -0,0 +1,117 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (C) 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 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. + */ + + +/** + * No-op dispatch table. + * + * This file defines a special dispatch table which is loaded with no-op + * functions. + * + * When there's no current rendering context, calling a GL function like + * glBegin() is a no-op. Apps should never normally do this. So as a + * debugging aid, each of the no-op functions will emit a warning to + * stderr if the MESA_DEBUG or LIBGL_DEBUG env var is set. + */ + + + +#include "glapi/glapi_priv.h" + + +void +_glapi_noop_enable_warnings(unsigned char enable) +{ +} + +void +_glapi_set_warning_func(_glapi_proc func) +{ +} + +#ifdef DEBUG + +/** + * Called by each of the no-op GL entrypoints. + */ +static int +Warn(const char *func) +{ +#if !defined(_WIN32_WCE) + if (getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG")) { + fprintf(stderr, "GL User Error: gl%s called without a rendering context\n", + func); + } +#endif + return 0; +} + + +/** + * This is called if the user somehow calls an unassigned GL dispatch function. + */ +static GLint +NoOpUnused(void) +{ + return Warn(" function"); +} + +/* + * Defines for the glapitemp.h functions. + */ +#define KEYWORD1 static +#define KEYWORD1_ALT static +#define KEYWORD2 GLAPIENTRY +#define NAME(func) NoOp##func +#define DISPATCH(func, args, msg) Warn(#func); +#define RETURN_DISPATCH(func, args, msg) Warn(#func); return 0 + + +/* + * Defines for the table of no-op entry points. + */ +#define TABLE_ENTRY(name) (_glapi_proc) NoOp##name + +#else + +static int +NoOpGeneric(void) +{ +#if !defined(_WIN32_WCE) + if (getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG")) { + fprintf(stderr, "GL User Error: calling GL function without a rendering context\n"); + } +#endif + return 0; +} + +#define TABLE_ENTRY(name) (_glapi_proc) NoOpGeneric + +#endif + +#define DISPATCH_TABLE_NAME __glapi_noop_table +#define UNUSED_TABLE_NAME __unused_noop_functions + +#include "glapi/glapitemp.h" diff --git a/src/mapi/glapi/glapi_priv.h b/src/mapi/glapi/glapi_priv.h new file mode 100644 index 0000000..3ab553a --- /dev/null +++ b/src/mapi/glapi/glapi_priv.h @@ -0,0 +1,114 @@ +/* + * Mesa 3-D graphics library + * Version: 7.1 + * + * Copyright (C) 1999-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. + */ + + +#ifndef _GLAPI_PRIV_H +#define _GLAPI_PRIV_H + +#include +#include +#include + +#ifdef HAVE_DIX_CONFIG_H +#include +#include "glapi/mesa.h" +#else /* HAVE_DIX_CONFIG_H */ +#define GL_GLEXT_PROTOTYPES +#include "GL/gl.h" +#include "GL/glext.h" + +#ifndef GL_OES_fixed_point +typedef int GLfixed; +typedef int GLclampx; +#endif + +#ifndef GL_OES_EGL_image +typedef void *GLeglImageOES; +#endif + +#endif /* HAVE_DIX_CONFIG_H */ + +#include "glapi/glapi.h" + + +/* getproc */ + +extern void +_glapi_check_table_not_null(const struct _glapi_table *table); + + +extern void +_glapi_check_table(const struct _glapi_table *table); + + +/* entrypoint */ + +extern void +init_glapi_relocs_once(void); + + +extern _glapi_proc +generate_entrypoint(unsigned int functionOffset); + + +extern void +fill_in_entrypoint_offset(_glapi_proc entrypoint, unsigned int offset); + + +extern _glapi_proc +get_entrypoint_address(unsigned int functionOffset); + + +/** + * Size (in bytes) of dispatch function (entrypoint). + */ +#if defined(USE_X86_ASM) +# if defined(GLX_USE_TLS) +# define DISPATCH_FUNCTION_SIZE 16 +# elif defined(THREADS) +# define DISPATCH_FUNCTION_SIZE 32 +# else +# define DISPATCH_FUNCTION_SIZE 16 +# endif +#endif + +#if defined(USE_X64_64_ASM) +# if defined(GLX_USE_TLS) +# define DISPATCH_FUNCTION_SIZE 16 +# endif +#endif + + +/** + * Number of extension functions which we can dynamically add at runtime. + * + * Number of extension functions is also subject to the size of backing exec + * mem we allocate. For the common case of dispatch stubs with size 16 bytes, + * the two limits will be hit simultaneously. For larger dispatch function + * sizes, MAX_EXTENSION_FUNCS is effectively reduced. + */ +#define MAX_EXTENSION_FUNCS 256 + + +#endif diff --git a/src/mapi/glapi/glapi_sparc.S b/src/mapi/glapi/glapi_sparc.S new file mode 100644 index 0000000..b919c28 --- /dev/null +++ b/src/mapi/glapi/glapi_sparc.S @@ -0,0 +1,1514 @@ +/* DO NOT EDIT - This file generated automatically by gl_SPARC_asm.py (from Mesa) script */ + +/* + * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. + * (C) Copyright IBM Corporation 2004 + * 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 + * BRIAN PAUL, IBM, + * 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. + */ + +#ifdef __arch64__ +#define GL_OFF(N) ((N) * 8) +#define GL_LL ldx +#define GL_TIE_LD(SYM) %tie_ldx(SYM) +#define GL_STACK_SIZE 128 +#else +#define GL_OFF(N) ((N) * 4) +#define GL_LL ld +#define GL_TIE_LD(SYM) %tie_ld(SYM) +#define GL_STACK_SIZE 64 +#endif + +#define GLOBL_FN(x) .globl x ; .type x, @function +#define HIDDEN(x) .hidden x + + .register %g2, #scratch + .register %g3, #scratch + + .text + + GLOBL_FN(__glapi_sparc_icache_flush) + HIDDEN(__glapi_sparc_icache_flush) + .type __glapi_sparc_icache_flush, @function +__glapi_sparc_icache_flush: /* %o0 = insn_addr */ + flush %o0 + retl + nop + + .align 32 + + .type __glapi_sparc_get_pc, @function +__glapi_sparc_get_pc: + retl + add %o7, %g2, %g2 + .size __glapi_sparc_get_pc, .-__glapi_sparc_get_pc + +#ifdef GLX_USE_TLS + + GLOBL_FN(__glapi_sparc_get_dispatch) + HIDDEN(__glapi_sparc_get_dispatch) +__glapi_sparc_get_dispatch: + mov %o7, %g1 + sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %g2 + call __glapi_sparc_get_pc + add %g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2 + mov %g1, %o7 + sethi %tie_hi22(_glapi_tls_Dispatch), %g1 + add %g1, %tie_lo10(_glapi_tls_Dispatch), %g1 + GL_LL [%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch) + retl + mov %g2, %o0 + + .data + .align 32 + + /* --> sethi %hi(_glapi_tls_Dispatch), %g1 */ + /* --> or %g1, %lo(_glapi_tls_Dispatch), %g1 */ + GLOBL_FN(__glapi_sparc_tls_stub) + HIDDEN(__glapi_sparc_tls_stub) +__glapi_sparc_tls_stub: /* Call offset in %g3 */ + mov %o7, %g1 + sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %g2 + call __glapi_sparc_get_pc + add %g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2 + mov %g1, %o7 + srl %g3, 10, %g3 + sethi %tie_hi22(_glapi_tls_Dispatch), %g1 + add %g1, %tie_lo10(_glapi_tls_Dispatch), %g1 + GL_LL [%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch) + GL_LL [%g7+%g2], %g1 + GL_LL [%g1 + %g3], %g1 + jmp %g1 + nop + .size __glapi_sparc_tls_stub, .-__glapi_sparc_tls_stub + +#define GL_STUB(fn, off) \ + GLOBL_FN(fn); \ +fn: ba __glapi_sparc_tls_stub; \ + sethi GL_OFF(off), %g3; \ + .size fn,.-fn; + +#elif defined(PTHREADS) + + /* 64-bit 0x00 --> sethi %hh(_glapi_Dispatch), %g1 */ + /* 64-bit 0x04 --> sethi %lm(_glapi_Dispatch), %g2 */ + /* 64-bit 0x08 --> or %g1, %hm(_glapi_Dispatch), %g1 */ + /* 64-bit 0x0c --> sllx %g1, 32, %g1 */ + /* 64-bit 0x10 --> add %g1, %g2, %g1 */ + /* 64-bit 0x14 --> ldx [%g1 + %lo(_glapi_Dispatch)], %g1 */ + + /* 32-bit 0x00 --> sethi %hi(_glapi_Dispatch), %g1 */ + /* 32-bit 0x04 --> ld [%g1 + %lo(_glapi_Dispatch)], %g1 */ + + .data + .align 32 + + GLOBL_FN(__glapi_sparc_pthread_stub) + HIDDEN(__glapi_sparc_pthread_stub) +__glapi_sparc_pthread_stub: /* Call offset in %g3 */ + mov %o7, %g1 + sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %g2 + call __glapi_sparc_get_pc + add %g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2 + mov %g1, %o7 + sethi %hi(_glapi_Dispatch), %g1 + or %g1, %lo(_glapi_Dispatch), %g1 + srl %g3, 10, %g3 + GL_LL [%g2+%g1], %g2 + GL_LL [%g2], %g1 + cmp %g1, 0 + be 2f + nop +1: GL_LL [%g1 + %g3], %g1 + jmp %g1 + nop +2: save %sp, GL_STACK_SIZE, %sp + mov %g3, %l0 + call _glapi_get_dispatch + nop + mov %o0, %g1 + mov %l0, %g3 + ba 1b + restore %g0, %g0, %g0 + .size __glapi_sparc_pthread_stub, .-__glapi_sparc_pthread_stub + +#define GL_STUB(fn, off) \ + GLOBL_FN(fn); \ +fn: ba __glapi_sparc_pthread_stub; \ + sethi GL_OFF(off), %g3; \ + .size fn,.-fn; + +#else /* Non-threaded version. */ + + .type __glapi_sparc_nothread_stub, @function +__glapi_sparc_nothread_stub: /* Call offset in %g3 */ + mov %o7, %g1 + sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %g2 + call __glapi_sparc_get_pc + add %g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2 + mov %g1, %o7 + srl %g3, 10, %g3 + sethi %hi(_glapi_Dispatch), %g1 + or %g1, %lo(_glapi_Dispatch), %g1 + GL_LL [%g2+%g1], %g2 + GL_LL [%g2], %g1 + GL_LL [%g1 + %g3], %g1 + jmp %g1 + nop + .size __glapi_sparc_nothread_stub, .-__glapi_sparc_nothread_stub + +#define GL_STUB(fn, off) \ + GLOBL_FN(fn); \ +fn: ba __glapi_sparc_nothread_stub; \ + sethi GL_OFF(off), %g3; \ + .size fn,.-fn; + +#endif + +#define GL_STUB_ALIAS(fn, alias) \ + .globl fn; \ + .set fn, alias + + .text + .align 32 + + .globl gl_dispatch_functions_start + HIDDEN(gl_dispatch_functions_start) +gl_dispatch_functions_start: + + GL_STUB(glNewList, 0) + GL_STUB(glEndList, 1) + GL_STUB(glCallList, 2) + GL_STUB(glCallLists, 3) + GL_STUB(glDeleteLists, 4) + GL_STUB(glGenLists, 5) + GL_STUB(glListBase, 6) + GL_STUB(glBegin, 7) + GL_STUB(glBitmap, 8) + GL_STUB(glColor3b, 9) + GL_STUB(glColor3bv, 10) + GL_STUB(glColor3d, 11) + GL_STUB(glColor3dv, 12) + GL_STUB(glColor3f, 13) + GL_STUB(glColor3fv, 14) + GL_STUB(glColor3i, 15) + GL_STUB(glColor3iv, 16) + GL_STUB(glColor3s, 17) + GL_STUB(glColor3sv, 18) + GL_STUB(glColor3ub, 19) + GL_STUB(glColor3ubv, 20) + GL_STUB(glColor3ui, 21) + GL_STUB(glColor3uiv, 22) + GL_STUB(glColor3us, 23) + GL_STUB(glColor3usv, 24) + GL_STUB(glColor4b, 25) + GL_STUB(glColor4bv, 26) + GL_STUB(glColor4d, 27) + GL_STUB(glColor4dv, 28) + GL_STUB(glColor4f, 29) + GL_STUB(glColor4fv, 30) + GL_STUB(glColor4i, 31) + GL_STUB(glColor4iv, 32) + GL_STUB(glColor4s, 33) + GL_STUB(glColor4sv, 34) + GL_STUB(glColor4ub, 35) + GL_STUB(glColor4ubv, 36) + GL_STUB(glColor4ui, 37) + GL_STUB(glColor4uiv, 38) + GL_STUB(glColor4us, 39) + GL_STUB(glColor4usv, 40) + GL_STUB(glEdgeFlag, 41) + GL_STUB(glEdgeFlagv, 42) + GL_STUB(glEnd, 43) + GL_STUB(glIndexd, 44) + GL_STUB(glIndexdv, 45) + GL_STUB(glIndexf, 46) + GL_STUB(glIndexfv, 47) + GL_STUB(glIndexi, 48) + GL_STUB(glIndexiv, 49) + GL_STUB(glIndexs, 50) + GL_STUB(glIndexsv, 51) + GL_STUB(glNormal3b, 52) + GL_STUB(glNormal3bv, 53) + GL_STUB(glNormal3d, 54) + GL_STUB(glNormal3dv, 55) + GL_STUB(glNormal3f, 56) + GL_STUB(glNormal3fv, 57) + GL_STUB(glNormal3i, 58) + GL_STUB(glNormal3iv, 59) + GL_STUB(glNormal3s, 60) + GL_STUB(glNormal3sv, 61) + GL_STUB(glRasterPos2d, 62) + GL_STUB(glRasterPos2dv, 63) + GL_STUB(glRasterPos2f, 64) + GL_STUB(glRasterPos2fv, 65) + GL_STUB(glRasterPos2i, 66) + GL_STUB(glRasterPos2iv, 67) + GL_STUB(glRasterPos2s, 68) + GL_STUB(glRasterPos2sv, 69) + GL_STUB(glRasterPos3d, 70) + GL_STUB(glRasterPos3dv, 71) + GL_STUB(glRasterPos3f, 72) + GL_STUB(glRasterPos3fv, 73) + GL_STUB(glRasterPos3i, 74) + GL_STUB(glRasterPos3iv, 75) + GL_STUB(glRasterPos3s, 76) + GL_STUB(glRasterPos3sv, 77) + GL_STUB(glRasterPos4d, 78) + GL_STUB(glRasterPos4dv, 79) + GL_STUB(glRasterPos4f, 80) + GL_STUB(glRasterPos4fv, 81) + GL_STUB(glRasterPos4i, 82) + GL_STUB(glRasterPos4iv, 83) + GL_STUB(glRasterPos4s, 84) + GL_STUB(glRasterPos4sv, 85) + GL_STUB(glRectd, 86) + GL_STUB(glRectdv, 87) + GL_STUB(glRectf, 88) + GL_STUB(glRectfv, 89) + GL_STUB(glRecti, 90) + GL_STUB(glRectiv, 91) + GL_STUB(glRects, 92) + GL_STUB(glRectsv, 93) + GL_STUB(glTexCoord1d, 94) + GL_STUB(glTexCoord1dv, 95) + GL_STUB(glTexCoord1f, 96) + GL_STUB(glTexCoord1fv, 97) + GL_STUB(glTexCoord1i, 98) + GL_STUB(glTexCoord1iv, 99) + GL_STUB(glTexCoord1s, 100) + GL_STUB(glTexCoord1sv, 101) + GL_STUB(glTexCoord2d, 102) + GL_STUB(glTexCoord2dv, 103) + GL_STUB(glTexCoord2f, 104) + GL_STUB(glTexCoord2fv, 105) + GL_STUB(glTexCoord2i, 106) + GL_STUB(glTexCoord2iv, 107) + GL_STUB(glTexCoord2s, 108) + GL_STUB(glTexCoord2sv, 109) + GL_STUB(glTexCoord3d, 110) + GL_STUB(glTexCoord3dv, 111) + GL_STUB(glTexCoord3f, 112) + GL_STUB(glTexCoord3fv, 113) + GL_STUB(glTexCoord3i, 114) + GL_STUB(glTexCoord3iv, 115) + GL_STUB(glTexCoord3s, 116) + GL_STUB(glTexCoord3sv, 117) + GL_STUB(glTexCoord4d, 118) + GL_STUB(glTexCoord4dv, 119) + GL_STUB(glTexCoord4f, 120) + GL_STUB(glTexCoord4fv, 121) + GL_STUB(glTexCoord4i, 122) + GL_STUB(glTexCoord4iv, 123) + GL_STUB(glTexCoord4s, 124) + GL_STUB(glTexCoord4sv, 125) + GL_STUB(glVertex2d, 126) + GL_STUB(glVertex2dv, 127) + GL_STUB(glVertex2f, 128) + GL_STUB(glVertex2fv, 129) + GL_STUB(glVertex2i, 130) + GL_STUB(glVertex2iv, 131) + GL_STUB(glVertex2s, 132) + GL_STUB(glVertex2sv, 133) + GL_STUB(glVertex3d, 134) + GL_STUB(glVertex3dv, 135) + GL_STUB(glVertex3f, 136) + GL_STUB(glVertex3fv, 137) + GL_STUB(glVertex3i, 138) + GL_STUB(glVertex3iv, 139) + GL_STUB(glVertex3s, 140) + GL_STUB(glVertex3sv, 141) + GL_STUB(glVertex4d, 142) + GL_STUB(glVertex4dv, 143) + GL_STUB(glVertex4f, 144) + GL_STUB(glVertex4fv, 145) + GL_STUB(glVertex4i, 146) + GL_STUB(glVertex4iv, 147) + GL_STUB(glVertex4s, 148) + GL_STUB(glVertex4sv, 149) + GL_STUB(glClipPlane, 150) + GL_STUB(glColorMaterial, 151) + GL_STUB(glCullFace, 152) + GL_STUB(glFogf, 153) + GL_STUB(glFogfv, 154) + GL_STUB(glFogi, 155) + GL_STUB(glFogiv, 156) + GL_STUB(glFrontFace, 157) + GL_STUB(glHint, 158) + GL_STUB(glLightf, 159) + GL_STUB(glLightfv, 160) + GL_STUB(glLighti, 161) + GL_STUB(glLightiv, 162) + GL_STUB(glLightModelf, 163) + GL_STUB(glLightModelfv, 164) + GL_STUB(glLightModeli, 165) + GL_STUB(glLightModeliv, 166) + GL_STUB(glLineStipple, 167) + GL_STUB(glLineWidth, 168) + GL_STUB(glMaterialf, 169) + GL_STUB(glMaterialfv, 170) + GL_STUB(glMateriali, 171) + GL_STUB(glMaterialiv, 172) + GL_STUB(glPointSize, 173) + GL_STUB(glPolygonMode, 174) + GL_STUB(glPolygonStipple, 175) + GL_STUB(glScissor, 176) + GL_STUB(glShadeModel, 177) + GL_STUB(glTexParameterf, 178) + GL_STUB(glTexParameterfv, 179) + GL_STUB(glTexParameteri, 180) + GL_STUB(glTexParameteriv, 181) + GL_STUB(glTexImage1D, 182) + GL_STUB(glTexImage2D, 183) + GL_STUB(glTexEnvf, 184) + GL_STUB(glTexEnvfv, 185) + GL_STUB(glTexEnvi, 186) + GL_STUB(glTexEnviv, 187) + GL_STUB(glTexGend, 188) + GL_STUB(glTexGendv, 189) + GL_STUB(glTexGenf, 190) + GL_STUB(glTexGenfv, 191) + GL_STUB(glTexGeni, 192) + GL_STUB(glTexGeniv, 193) + GL_STUB(glFeedbackBuffer, 194) + GL_STUB(glSelectBuffer, 195) + GL_STUB(glRenderMode, 196) + GL_STUB(glInitNames, 197) + GL_STUB(glLoadName, 198) + GL_STUB(glPassThrough, 199) + GL_STUB(glPopName, 200) + GL_STUB(glPushName, 201) + GL_STUB(glDrawBuffer, 202) + GL_STUB(glClear, 203) + GL_STUB(glClearAccum, 204) + GL_STUB(glClearIndex, 205) + GL_STUB(glClearColor, 206) + GL_STUB(glClearStencil, 207) + GL_STUB(glClearDepth, 208) + GL_STUB(glStencilMask, 209) + GL_STUB(glColorMask, 210) + GL_STUB(glDepthMask, 211) + GL_STUB(glIndexMask, 212) + GL_STUB(glAccum, 213) + GL_STUB(glDisable, 214) + GL_STUB(glEnable, 215) + GL_STUB(glFinish, 216) + GL_STUB(glFlush, 217) + GL_STUB(glPopAttrib, 218) + GL_STUB(glPushAttrib, 219) + GL_STUB(glMap1d, 220) + GL_STUB(glMap1f, 221) + GL_STUB(glMap2d, 222) + GL_STUB(glMap2f, 223) + GL_STUB(glMapGrid1d, 224) + GL_STUB(glMapGrid1f, 225) + GL_STUB(glMapGrid2d, 226) + GL_STUB(glMapGrid2f, 227) + GL_STUB(glEvalCoord1d, 228) + GL_STUB(glEvalCoord1dv, 229) + GL_STUB(glEvalCoord1f, 230) + GL_STUB(glEvalCoord1fv, 231) + GL_STUB(glEvalCoord2d, 232) + GL_STUB(glEvalCoord2dv, 233) + GL_STUB(glEvalCoord2f, 234) + GL_STUB(glEvalCoord2fv, 235) + GL_STUB(glEvalMesh1, 236) + GL_STUB(glEvalPoint1, 237) + GL_STUB(glEvalMesh2, 238) + GL_STUB(glEvalPoint2, 239) + GL_STUB(glAlphaFunc, 240) + GL_STUB(glBlendFunc, 241) + GL_STUB(glLogicOp, 242) + GL_STUB(glStencilFunc, 243) + GL_STUB(glStencilOp, 244) + GL_STUB(glDepthFunc, 245) + GL_STUB(glPixelZoom, 246) + GL_STUB(glPixelTransferf, 247) + GL_STUB(glPixelTransferi, 248) + GL_STUB(glPixelStoref, 249) + GL_STUB(glPixelStorei, 250) + GL_STUB(glPixelMapfv, 251) + GL_STUB(glPixelMapuiv, 252) + GL_STUB(glPixelMapusv, 253) + GL_STUB(glReadBuffer, 254) + GL_STUB(glCopyPixels, 255) + GL_STUB(glReadPixels, 256) + GL_STUB(glDrawPixels, 257) + GL_STUB(glGetBooleanv, 258) + GL_STUB(glGetClipPlane, 259) + GL_STUB(glGetDoublev, 260) + GL_STUB(glGetError, 261) + GL_STUB(glGetFloatv, 262) + GL_STUB(glGetIntegerv, 263) + GL_STUB(glGetLightfv, 264) + GL_STUB(glGetLightiv, 265) + GL_STUB(glGetMapdv, 266) + GL_STUB(glGetMapfv, 267) + GL_STUB(glGetMapiv, 268) + GL_STUB(glGetMaterialfv, 269) + GL_STUB(glGetMaterialiv, 270) + GL_STUB(glGetPixelMapfv, 271) + GL_STUB(glGetPixelMapuiv, 272) + GL_STUB(glGetPixelMapusv, 273) + GL_STUB(glGetPolygonStipple, 274) + GL_STUB(glGetString, 275) + GL_STUB(glGetTexEnvfv, 276) + GL_STUB(glGetTexEnviv, 277) + GL_STUB(glGetTexGendv, 278) + GL_STUB(glGetTexGenfv, 279) + GL_STUB(glGetTexGeniv, 280) + GL_STUB(glGetTexImage, 281) + GL_STUB(glGetTexParameterfv, 282) + GL_STUB(glGetTexParameteriv, 283) + GL_STUB(glGetTexLevelParameterfv, 284) + GL_STUB(glGetTexLevelParameteriv, 285) + GL_STUB(glIsEnabled, 286) + GL_STUB(glIsList, 287) + GL_STUB(glDepthRange, 288) + GL_STUB(glFrustum, 289) + GL_STUB(glLoadIdentity, 290) + GL_STUB(glLoadMatrixf, 291) + GL_STUB(glLoadMatrixd, 292) + GL_STUB(glMatrixMode, 293) + GL_STUB(glMultMatrixf, 294) + GL_STUB(glMultMatrixd, 295) + GL_STUB(glOrtho, 296) + GL_STUB(glPopMatrix, 297) + GL_STUB(glPushMatrix, 298) + GL_STUB(glRotated, 299) + GL_STUB(glRotatef, 300) + GL_STUB(glScaled, 301) + GL_STUB(glScalef, 302) + GL_STUB(glTranslated, 303) + GL_STUB(glTranslatef, 304) + GL_STUB(glViewport, 305) + GL_STUB(glArrayElement, 306) + GL_STUB(glBindTexture, 307) + GL_STUB(glColorPointer, 308) + GL_STUB(glDisableClientState, 309) + GL_STUB(glDrawArrays, 310) + GL_STUB(glDrawElements, 311) + GL_STUB(glEdgeFlagPointer, 312) + GL_STUB(glEnableClientState, 313) + GL_STUB(glIndexPointer, 314) + GL_STUB(glIndexub, 315) + GL_STUB(glIndexubv, 316) + GL_STUB(glInterleavedArrays, 317) + GL_STUB(glNormalPointer, 318) + GL_STUB(glPolygonOffset, 319) + GL_STUB(glTexCoordPointer, 320) + GL_STUB(glVertexPointer, 321) + GL_STUB(glAreTexturesResident, 322) + GL_STUB(glCopyTexImage1D, 323) + GL_STUB(glCopyTexImage2D, 324) + GL_STUB(glCopyTexSubImage1D, 325) + GL_STUB(glCopyTexSubImage2D, 326) + GL_STUB(glDeleteTextures, 327) + GL_STUB(glGenTextures, 328) + GL_STUB(glGetPointerv, 329) + GL_STUB(glIsTexture, 330) + GL_STUB(glPrioritizeTextures, 331) + GL_STUB(glTexSubImage1D, 332) + GL_STUB(glTexSubImage2D, 333) + GL_STUB(glPopClientAttrib, 334) + GL_STUB(glPushClientAttrib, 335) + GL_STUB(glBlendColor, 336) + GL_STUB(glBlendEquation, 337) + GL_STUB(glDrawRangeElements, 338) + GL_STUB(glColorTable, 339) + GL_STUB(glColorTableParameterfv, 340) + GL_STUB(glColorTableParameteriv, 341) + GL_STUB(glCopyColorTable, 342) + GL_STUB(glGetColorTable, 343) + GL_STUB(glGetColorTableParameterfv, 344) + GL_STUB(glGetColorTableParameteriv, 345) + GL_STUB(glColorSubTable, 346) + GL_STUB(glCopyColorSubTable, 347) + GL_STUB(glConvolutionFilter1D, 348) + GL_STUB(glConvolutionFilter2D, 349) + GL_STUB(glConvolutionParameterf, 350) + GL_STUB(glConvolutionParameterfv, 351) + GL_STUB(glConvolutionParameteri, 352) + GL_STUB(glConvolutionParameteriv, 353) + GL_STUB(glCopyConvolutionFilter1D, 354) + GL_STUB(glCopyConvolutionFilter2D, 355) + GL_STUB(glGetConvolutionFilter, 356) + GL_STUB(glGetConvolutionParameterfv, 357) + GL_STUB(glGetConvolutionParameteriv, 358) + GL_STUB(glGetSeparableFilter, 359) + GL_STUB(glSeparableFilter2D, 360) + GL_STUB(glGetHistogram, 361) + GL_STUB(glGetHistogramParameterfv, 362) + GL_STUB(glGetHistogramParameteriv, 363) + GL_STUB(glGetMinmax, 364) + GL_STUB(glGetMinmaxParameterfv, 365) + GL_STUB(glGetMinmaxParameteriv, 366) + GL_STUB(glHistogram, 367) + GL_STUB(glMinmax, 368) + GL_STUB(glResetHistogram, 369) + GL_STUB(glResetMinmax, 370) + GL_STUB(glTexImage3D, 371) + GL_STUB(glTexSubImage3D, 372) + GL_STUB(glCopyTexSubImage3D, 373) + GL_STUB(glActiveTextureARB, 374) + GL_STUB(glClientActiveTextureARB, 375) + GL_STUB(glMultiTexCoord1dARB, 376) + GL_STUB(glMultiTexCoord1dvARB, 377) + GL_STUB(glMultiTexCoord1fARB, 378) + GL_STUB(glMultiTexCoord1fvARB, 379) + GL_STUB(glMultiTexCoord1iARB, 380) + GL_STUB(glMultiTexCoord1ivARB, 381) + GL_STUB(glMultiTexCoord1sARB, 382) + GL_STUB(glMultiTexCoord1svARB, 383) + GL_STUB(glMultiTexCoord2dARB, 384) + GL_STUB(glMultiTexCoord2dvARB, 385) + GL_STUB(glMultiTexCoord2fARB, 386) + GL_STUB(glMultiTexCoord2fvARB, 387) + GL_STUB(glMultiTexCoord2iARB, 388) + GL_STUB(glMultiTexCoord2ivARB, 389) + GL_STUB(glMultiTexCoord2sARB, 390) + GL_STUB(glMultiTexCoord2svARB, 391) + GL_STUB(glMultiTexCoord3dARB, 392) + GL_STUB(glMultiTexCoord3dvARB, 393) + GL_STUB(glMultiTexCoord3fARB, 394) + GL_STUB(glMultiTexCoord3fvARB, 395) + GL_STUB(glMultiTexCoord3iARB, 396) + GL_STUB(glMultiTexCoord3ivARB, 397) + GL_STUB(glMultiTexCoord3sARB, 398) + GL_STUB(glMultiTexCoord3svARB, 399) + GL_STUB(glMultiTexCoord4dARB, 400) + GL_STUB(glMultiTexCoord4dvARB, 401) + GL_STUB(glMultiTexCoord4fARB, 402) + GL_STUB(glMultiTexCoord4fvARB, 403) + GL_STUB(glMultiTexCoord4iARB, 404) + GL_STUB(glMultiTexCoord4ivARB, 405) + GL_STUB(glMultiTexCoord4sARB, 406) + GL_STUB(glMultiTexCoord4svARB, 407) + GL_STUB(glAttachShader, 408) + GL_STUB(glCreateProgram, 409) + GL_STUB(glCreateShader, 410) + GL_STUB(glDeleteProgram, 411) + GL_STUB(glDeleteShader, 412) + GL_STUB(glDetachShader, 413) + GL_STUB(glGetAttachedShaders, 414) + GL_STUB(glGetProgramInfoLog, 415) + GL_STUB(glGetProgramiv, 416) + GL_STUB(glGetShaderInfoLog, 417) + GL_STUB(glGetShaderiv, 418) + GL_STUB(glIsProgram, 419) + GL_STUB(glIsShader, 420) + GL_STUB(glStencilFuncSeparate, 421) + GL_STUB(glStencilMaskSeparate, 422) + GL_STUB(glStencilOpSeparate, 423) + GL_STUB(glUniformMatrix2x3fv, 424) + GL_STUB(glUniformMatrix2x4fv, 425) + GL_STUB(glUniformMatrix3x2fv, 426) + GL_STUB(glUniformMatrix3x4fv, 427) + GL_STUB(glUniformMatrix4x2fv, 428) + GL_STUB(glUniformMatrix4x3fv, 429) + GL_STUB(glClampColor, 430) + GL_STUB(glClearBufferfi, 431) + GL_STUB(glClearBufferfv, 432) + GL_STUB(glClearBufferiv, 433) + GL_STUB(glClearBufferuiv, 434) + GL_STUB(glGetStringi, 435) + GL_STUB(glTexBuffer, 436) + GL_STUB(glFramebufferTexture, 437) + GL_STUB(glGetBufferParameteri64v, 438) + GL_STUB(glGetInteger64i_v, 439) + GL_STUB(glVertexAttribDivisor, 440) + GL_STUB(glLoadTransposeMatrixdARB, 441) + GL_STUB(glLoadTransposeMatrixfARB, 442) + GL_STUB(glMultTransposeMatrixdARB, 443) + GL_STUB(glMultTransposeMatrixfARB, 444) + GL_STUB(glSampleCoverageARB, 445) + GL_STUB(glCompressedTexImage1DARB, 446) + GL_STUB(glCompressedTexImage2DARB, 447) + GL_STUB(glCompressedTexImage3DARB, 448) + GL_STUB(glCompressedTexSubImage1DARB, 449) + GL_STUB(glCompressedTexSubImage2DARB, 450) + GL_STUB(glCompressedTexSubImage3DARB, 451) + GL_STUB(glGetCompressedTexImageARB, 452) + GL_STUB(glDisableVertexAttribArrayARB, 453) + GL_STUB(glEnableVertexAttribArrayARB, 454) + GL_STUB(glGetProgramEnvParameterdvARB, 455) + GL_STUB(glGetProgramEnvParameterfvARB, 456) + GL_STUB(glGetProgramLocalParameterdvARB, 457) + GL_STUB(glGetProgramLocalParameterfvARB, 458) + GL_STUB(glGetProgramStringARB, 459) + GL_STUB(glGetProgramivARB, 460) + GL_STUB(glGetVertexAttribdvARB, 461) + GL_STUB(glGetVertexAttribfvARB, 462) + GL_STUB(glGetVertexAttribivARB, 463) + GL_STUB(glProgramEnvParameter4dARB, 464) + GL_STUB(glProgramEnvParameter4dvARB, 465) + GL_STUB(glProgramEnvParameter4fARB, 466) + GL_STUB(glProgramEnvParameter4fvARB, 467) + GL_STUB(glProgramLocalParameter4dARB, 468) + GL_STUB(glProgramLocalParameter4dvARB, 469) + GL_STUB(glProgramLocalParameter4fARB, 470) + GL_STUB(glProgramLocalParameter4fvARB, 471) + GL_STUB(glProgramStringARB, 472) + GL_STUB(glVertexAttrib1dARB, 473) + GL_STUB(glVertexAttrib1dvARB, 474) + GL_STUB(glVertexAttrib1fARB, 475) + GL_STUB(glVertexAttrib1fvARB, 476) + GL_STUB(glVertexAttrib1sARB, 477) + GL_STUB(glVertexAttrib1svARB, 478) + GL_STUB(glVertexAttrib2dARB, 479) + GL_STUB(glVertexAttrib2dvARB, 480) + GL_STUB(glVertexAttrib2fARB, 481) + GL_STUB(glVertexAttrib2fvARB, 482) + GL_STUB(glVertexAttrib2sARB, 483) + GL_STUB(glVertexAttrib2svARB, 484) + GL_STUB(glVertexAttrib3dARB, 485) + GL_STUB(glVertexAttrib3dvARB, 486) + GL_STUB(glVertexAttrib3fARB, 487) + GL_STUB(glVertexAttrib3fvARB, 488) + GL_STUB(glVertexAttrib3sARB, 489) + GL_STUB(glVertexAttrib3svARB, 490) + GL_STUB(glVertexAttrib4NbvARB, 491) + GL_STUB(glVertexAttrib4NivARB, 492) + GL_STUB(glVertexAttrib4NsvARB, 493) + GL_STUB(glVertexAttrib4NubARB, 494) + GL_STUB(glVertexAttrib4NubvARB, 495) + GL_STUB(glVertexAttrib4NuivARB, 496) + GL_STUB(glVertexAttrib4NusvARB, 497) + GL_STUB(glVertexAttrib4bvARB, 498) + GL_STUB(glVertexAttrib4dARB, 499) + GL_STUB(glVertexAttrib4dvARB, 500) + GL_STUB(glVertexAttrib4fARB, 501) + GL_STUB(glVertexAttrib4fvARB, 502) + GL_STUB(glVertexAttrib4ivARB, 503) + GL_STUB(glVertexAttrib4sARB, 504) + GL_STUB(glVertexAttrib4svARB, 505) + GL_STUB(glVertexAttrib4ubvARB, 506) + GL_STUB(glVertexAttrib4uivARB, 507) + GL_STUB(glVertexAttrib4usvARB, 508) + GL_STUB(glVertexAttribPointerARB, 509) + GL_STUB(glBindBufferARB, 510) + GL_STUB(glBufferDataARB, 511) + GL_STUB(glBufferSubDataARB, 512) + GL_STUB(glDeleteBuffersARB, 513) + GL_STUB(glGenBuffersARB, 514) + GL_STUB(glGetBufferParameterivARB, 515) + GL_STUB(glGetBufferPointervARB, 516) + GL_STUB(glGetBufferSubDataARB, 517) + GL_STUB(glIsBufferARB, 518) + GL_STUB(glMapBufferARB, 519) + GL_STUB(glUnmapBufferARB, 520) + GL_STUB(glBeginQueryARB, 521) + GL_STUB(glDeleteQueriesARB, 522) + GL_STUB(glEndQueryARB, 523) + GL_STUB(glGenQueriesARB, 524) + GL_STUB(glGetQueryObjectivARB, 525) + GL_STUB(glGetQueryObjectuivARB, 526) + GL_STUB(glGetQueryivARB, 527) + GL_STUB(glIsQueryARB, 528) + GL_STUB(glAttachObjectARB, 529) + GL_STUB(glCompileShaderARB, 530) + GL_STUB(glCreateProgramObjectARB, 531) + GL_STUB(glCreateShaderObjectARB, 532) + GL_STUB(glDeleteObjectARB, 533) + GL_STUB(glDetachObjectARB, 534) + GL_STUB(glGetActiveUniformARB, 535) + GL_STUB(glGetAttachedObjectsARB, 536) + GL_STUB(glGetHandleARB, 537) + GL_STUB(glGetInfoLogARB, 538) + GL_STUB(glGetObjectParameterfvARB, 539) + GL_STUB(glGetObjectParameterivARB, 540) + GL_STUB(glGetShaderSourceARB, 541) + GL_STUB(glGetUniformLocationARB, 542) + GL_STUB(glGetUniformfvARB, 543) + GL_STUB(glGetUniformivARB, 544) + GL_STUB(glLinkProgramARB, 545) + GL_STUB(glShaderSourceARB, 546) + GL_STUB(glUniform1fARB, 547) + GL_STUB(glUniform1fvARB, 548) + GL_STUB(glUniform1iARB, 549) + GL_STUB(glUniform1ivARB, 550) + GL_STUB(glUniform2fARB, 551) + GL_STUB(glUniform2fvARB, 552) + GL_STUB(glUniform2iARB, 553) + GL_STUB(glUniform2ivARB, 554) + GL_STUB(glUniform3fARB, 555) + GL_STUB(glUniform3fvARB, 556) + GL_STUB(glUniform3iARB, 557) + GL_STUB(glUniform3ivARB, 558) + GL_STUB(glUniform4fARB, 559) + GL_STUB(glUniform4fvARB, 560) + GL_STUB(glUniform4iARB, 561) + GL_STUB(glUniform4ivARB, 562) + GL_STUB(glUniformMatrix2fvARB, 563) + GL_STUB(glUniformMatrix3fvARB, 564) + GL_STUB(glUniformMatrix4fvARB, 565) + GL_STUB(glUseProgramObjectARB, 566) + GL_STUB(glValidateProgramARB, 567) + GL_STUB(glBindAttribLocationARB, 568) + GL_STUB(glGetActiveAttribARB, 569) + GL_STUB(glGetAttribLocationARB, 570) + GL_STUB(glDrawBuffersARB, 571) + GL_STUB(glDrawArraysInstancedARB, 572) + GL_STUB(glDrawElementsInstancedARB, 573) + GL_STUB(glRenderbufferStorageMultisample, 574) + GL_STUB(glFramebufferTextureARB, 575) + GL_STUB(glFramebufferTextureFaceARB, 576) + GL_STUB(glProgramParameteriARB, 577) + GL_STUB(glFlushMappedBufferRange, 578) + GL_STUB(glMapBufferRange, 579) + GL_STUB(glBindVertexArray, 580) + GL_STUB(glGenVertexArrays, 581) + GL_STUB(glCopyBufferSubData, 582) + GL_STUB(glClientWaitSync, 583) + GL_STUB(glDeleteSync, 584) + GL_STUB(glFenceSync, 585) + GL_STUB(glGetInteger64v, 586) + GL_STUB(glGetSynciv, 587) + GL_STUB(glIsSync, 588) + GL_STUB(glWaitSync, 589) + GL_STUB(glDrawElementsBaseVertex, 590) + GL_STUB(glDrawRangeElementsBaseVertex, 591) + GL_STUB(glMultiDrawElementsBaseVertex, 592) + GL_STUB(glBindTransformFeedback, 593) + GL_STUB(glDeleteTransformFeedbacks, 594) + GL_STUB(glDrawTransformFeedback, 595) + GL_STUB(glGenTransformFeedbacks, 596) + GL_STUB(glIsTransformFeedback, 597) + GL_STUB(glPauseTransformFeedback, 598) + GL_STUB(glResumeTransformFeedback, 599) + GL_STUB(glClearDepthf, 600) + GL_STUB(glDepthRangef, 601) + GL_STUB(glGetShaderPrecisionFormat, 602) + GL_STUB(glReleaseShaderCompiler, 603) + GL_STUB(glShaderBinary, 604) + GL_STUB(glPolygonOffsetEXT, 605) + GL_STUB(gl_dispatch_stub_606, 606) + HIDDEN(gl_dispatch_stub_606) + GL_STUB(gl_dispatch_stub_607, 607) + HIDDEN(gl_dispatch_stub_607) + GL_STUB(gl_dispatch_stub_608, 608) + HIDDEN(gl_dispatch_stub_608) + GL_STUB(gl_dispatch_stub_609, 609) + HIDDEN(gl_dispatch_stub_609) + GL_STUB(gl_dispatch_stub_610, 610) + HIDDEN(gl_dispatch_stub_610) + GL_STUB(gl_dispatch_stub_611, 611) + HIDDEN(gl_dispatch_stub_611) + GL_STUB(gl_dispatch_stub_612, 612) + HIDDEN(gl_dispatch_stub_612) + GL_STUB(gl_dispatch_stub_613, 613) + HIDDEN(gl_dispatch_stub_613) + GL_STUB(glColorPointerEXT, 614) + GL_STUB(glEdgeFlagPointerEXT, 615) + GL_STUB(glIndexPointerEXT, 616) + GL_STUB(glNormalPointerEXT, 617) + GL_STUB(glTexCoordPointerEXT, 618) + GL_STUB(glVertexPointerEXT, 619) + GL_STUB(glPointParameterfEXT, 620) + GL_STUB(glPointParameterfvEXT, 621) + GL_STUB(glLockArraysEXT, 622) + GL_STUB(glUnlockArraysEXT, 623) + GL_STUB(glSecondaryColor3bEXT, 624) + GL_STUB(glSecondaryColor3bvEXT, 625) + GL_STUB(glSecondaryColor3dEXT, 626) + GL_STUB(glSecondaryColor3dvEXT, 627) + GL_STUB(glSecondaryColor3fEXT, 628) + GL_STUB(glSecondaryColor3fvEXT, 629) + GL_STUB(glSecondaryColor3iEXT, 630) + GL_STUB(glSecondaryColor3ivEXT, 631) + GL_STUB(glSecondaryColor3sEXT, 632) + GL_STUB(glSecondaryColor3svEXT, 633) + GL_STUB(glSecondaryColor3ubEXT, 634) + GL_STUB(glSecondaryColor3ubvEXT, 635) + GL_STUB(glSecondaryColor3uiEXT, 636) + GL_STUB(glSecondaryColor3uivEXT, 637) + GL_STUB(glSecondaryColor3usEXT, 638) + GL_STUB(glSecondaryColor3usvEXT, 639) + GL_STUB(glSecondaryColorPointerEXT, 640) + GL_STUB(glMultiDrawArraysEXT, 641) + GL_STUB(glMultiDrawElementsEXT, 642) + GL_STUB(glFogCoordPointerEXT, 643) + GL_STUB(glFogCoorddEXT, 644) + GL_STUB(glFogCoorddvEXT, 645) + GL_STUB(glFogCoordfEXT, 646) + GL_STUB(glFogCoordfvEXT, 647) + GL_STUB(gl_dispatch_stub_648, 648) + HIDDEN(gl_dispatch_stub_648) + GL_STUB(glBlendFuncSeparateEXT, 649) + GL_STUB(glFlushVertexArrayRangeNV, 650) + GL_STUB(glVertexArrayRangeNV, 651) + GL_STUB(glCombinerInputNV, 652) + GL_STUB(glCombinerOutputNV, 653) + GL_STUB(glCombinerParameterfNV, 654) + GL_STUB(glCombinerParameterfvNV, 655) + GL_STUB(glCombinerParameteriNV, 656) + GL_STUB(glCombinerParameterivNV, 657) + GL_STUB(glFinalCombinerInputNV, 658) + GL_STUB(glGetCombinerInputParameterfvNV, 659) + GL_STUB(glGetCombinerInputParameterivNV, 660) + GL_STUB(glGetCombinerOutputParameterfvNV, 661) + GL_STUB(glGetCombinerOutputParameterivNV, 662) + GL_STUB(glGetFinalCombinerInputParameterfvNV, 663) + GL_STUB(glGetFinalCombinerInputParameterivNV, 664) + GL_STUB(glResizeBuffersMESA, 665) + GL_STUB(glWindowPos2dMESA, 666) + GL_STUB(glWindowPos2dvMESA, 667) + GL_STUB(glWindowPos2fMESA, 668) + GL_STUB(glWindowPos2fvMESA, 669) + GL_STUB(glWindowPos2iMESA, 670) + GL_STUB(glWindowPos2ivMESA, 671) + GL_STUB(glWindowPos2sMESA, 672) + GL_STUB(glWindowPos2svMESA, 673) + GL_STUB(glWindowPos3dMESA, 674) + GL_STUB(glWindowPos3dvMESA, 675) + GL_STUB(glWindowPos3fMESA, 676) + GL_STUB(glWindowPos3fvMESA, 677) + GL_STUB(glWindowPos3iMESA, 678) + GL_STUB(glWindowPos3ivMESA, 679) + GL_STUB(glWindowPos3sMESA, 680) + GL_STUB(glWindowPos3svMESA, 681) + GL_STUB(glWindowPos4dMESA, 682) + GL_STUB(glWindowPos4dvMESA, 683) + GL_STUB(glWindowPos4fMESA, 684) + GL_STUB(glWindowPos4fvMESA, 685) + GL_STUB(glWindowPos4iMESA, 686) + GL_STUB(glWindowPos4ivMESA, 687) + GL_STUB(glWindowPos4sMESA, 688) + GL_STUB(glWindowPos4svMESA, 689) + GL_STUB(gl_dispatch_stub_690, 690) + HIDDEN(gl_dispatch_stub_690) + GL_STUB(gl_dispatch_stub_691, 691) + HIDDEN(gl_dispatch_stub_691) + GL_STUB(gl_dispatch_stub_692, 692) + HIDDEN(gl_dispatch_stub_692) + GL_STUB(gl_dispatch_stub_693, 693) + HIDDEN(gl_dispatch_stub_693) + GL_STUB(gl_dispatch_stub_694, 694) + HIDDEN(gl_dispatch_stub_694) + GL_STUB(gl_dispatch_stub_695, 695) + HIDDEN(gl_dispatch_stub_695) + GL_STUB(gl_dispatch_stub_696, 696) + HIDDEN(gl_dispatch_stub_696) + GL_STUB(gl_dispatch_stub_697, 697) + HIDDEN(gl_dispatch_stub_697) + GL_STUB(gl_dispatch_stub_698, 698) + HIDDEN(gl_dispatch_stub_698) + GL_STUB(glAreProgramsResidentNV, 699) + GL_STUB(glBindProgramNV, 700) + GL_STUB(glDeleteProgramsNV, 701) + GL_STUB(glExecuteProgramNV, 702) + GL_STUB(glGenProgramsNV, 703) + GL_STUB(glGetProgramParameterdvNV, 704) + GL_STUB(glGetProgramParameterfvNV, 705) + GL_STUB(glGetProgramStringNV, 706) + GL_STUB(glGetProgramivNV, 707) + GL_STUB(glGetTrackMatrixivNV, 708) + GL_STUB(glGetVertexAttribPointervNV, 709) + GL_STUB(glGetVertexAttribdvNV, 710) + GL_STUB(glGetVertexAttribfvNV, 711) + GL_STUB(glGetVertexAttribivNV, 712) + GL_STUB(glIsProgramNV, 713) + GL_STUB(glLoadProgramNV, 714) + GL_STUB(glProgramParameters4dvNV, 715) + GL_STUB(glProgramParameters4fvNV, 716) + GL_STUB(glRequestResidentProgramsNV, 717) + GL_STUB(glTrackMatrixNV, 718) + GL_STUB(glVertexAttrib1dNV, 719) + GL_STUB(glVertexAttrib1dvNV, 720) + GL_STUB(glVertexAttrib1fNV, 721) + GL_STUB(glVertexAttrib1fvNV, 722) + GL_STUB(glVertexAttrib1sNV, 723) + GL_STUB(glVertexAttrib1svNV, 724) + GL_STUB(glVertexAttrib2dNV, 725) + GL_STUB(glVertexAttrib2dvNV, 726) + GL_STUB(glVertexAttrib2fNV, 727) + GL_STUB(glVertexAttrib2fvNV, 728) + GL_STUB(glVertexAttrib2sNV, 729) + GL_STUB(glVertexAttrib2svNV, 730) + GL_STUB(glVertexAttrib3dNV, 731) + GL_STUB(glVertexAttrib3dvNV, 732) + GL_STUB(glVertexAttrib3fNV, 733) + GL_STUB(glVertexAttrib3fvNV, 734) + GL_STUB(glVertexAttrib3sNV, 735) + GL_STUB(glVertexAttrib3svNV, 736) + GL_STUB(glVertexAttrib4dNV, 737) + GL_STUB(glVertexAttrib4dvNV, 738) + GL_STUB(glVertexAttrib4fNV, 739) + GL_STUB(glVertexAttrib4fvNV, 740) + GL_STUB(glVertexAttrib4sNV, 741) + GL_STUB(glVertexAttrib4svNV, 742) + GL_STUB(glVertexAttrib4ubNV, 743) + GL_STUB(glVertexAttrib4ubvNV, 744) + GL_STUB(glVertexAttribPointerNV, 745) + GL_STUB(glVertexAttribs1dvNV, 746) + GL_STUB(glVertexAttribs1fvNV, 747) + GL_STUB(glVertexAttribs1svNV, 748) + GL_STUB(glVertexAttribs2dvNV, 749) + GL_STUB(glVertexAttribs2fvNV, 750) + GL_STUB(glVertexAttribs2svNV, 751) + GL_STUB(glVertexAttribs3dvNV, 752) + GL_STUB(glVertexAttribs3fvNV, 753) + GL_STUB(glVertexAttribs3svNV, 754) + GL_STUB(glVertexAttribs4dvNV, 755) + GL_STUB(glVertexAttribs4fvNV, 756) + GL_STUB(glVertexAttribs4svNV, 757) + GL_STUB(glVertexAttribs4ubvNV, 758) + GL_STUB(glGetTexBumpParameterfvATI, 759) + GL_STUB(glGetTexBumpParameterivATI, 760) + GL_STUB(glTexBumpParameterfvATI, 761) + GL_STUB(glTexBumpParameterivATI, 762) + GL_STUB(glAlphaFragmentOp1ATI, 763) + GL_STUB(glAlphaFragmentOp2ATI, 764) + GL_STUB(glAlphaFragmentOp3ATI, 765) + GL_STUB(glBeginFragmentShaderATI, 766) + GL_STUB(glBindFragmentShaderATI, 767) + GL_STUB(glColorFragmentOp1ATI, 768) + GL_STUB(glColorFragmentOp2ATI, 769) + GL_STUB(glColorFragmentOp3ATI, 770) + GL_STUB(glDeleteFragmentShaderATI, 771) + GL_STUB(glEndFragmentShaderATI, 772) + GL_STUB(glGenFragmentShadersATI, 773) + GL_STUB(glPassTexCoordATI, 774) + GL_STUB(glSampleMapATI, 775) + GL_STUB(glSetFragmentShaderConstantATI, 776) + GL_STUB(glPointParameteriNV, 777) + GL_STUB(glPointParameterivNV, 778) + GL_STUB(gl_dispatch_stub_779, 779) + HIDDEN(gl_dispatch_stub_779) + GL_STUB(gl_dispatch_stub_780, 780) + HIDDEN(gl_dispatch_stub_780) + GL_STUB(gl_dispatch_stub_781, 781) + HIDDEN(gl_dispatch_stub_781) + GL_STUB(gl_dispatch_stub_782, 782) + HIDDEN(gl_dispatch_stub_782) + GL_STUB(gl_dispatch_stub_783, 783) + HIDDEN(gl_dispatch_stub_783) + GL_STUB(glGetProgramNamedParameterdvNV, 784) + GL_STUB(glGetProgramNamedParameterfvNV, 785) + GL_STUB(glProgramNamedParameter4dNV, 786) + GL_STUB(glProgramNamedParameter4dvNV, 787) + GL_STUB(glProgramNamedParameter4fNV, 788) + GL_STUB(glProgramNamedParameter4fvNV, 789) + GL_STUB(glPrimitiveRestartIndexNV, 790) + GL_STUB(glPrimitiveRestartNV, 791) + GL_STUB(gl_dispatch_stub_792, 792) + HIDDEN(gl_dispatch_stub_792) + GL_STUB(gl_dispatch_stub_793, 793) + HIDDEN(gl_dispatch_stub_793) + GL_STUB(glBindFramebufferEXT, 794) + GL_STUB(glBindRenderbufferEXT, 795) + GL_STUB(glCheckFramebufferStatusEXT, 796) + GL_STUB(glDeleteFramebuffersEXT, 797) + GL_STUB(glDeleteRenderbuffersEXT, 798) + GL_STUB(glFramebufferRenderbufferEXT, 799) + GL_STUB(glFramebufferTexture1DEXT, 800) + GL_STUB(glFramebufferTexture2DEXT, 801) + GL_STUB(glFramebufferTexture3DEXT, 802) + GL_STUB(glGenFramebuffersEXT, 803) + GL_STUB(glGenRenderbuffersEXT, 804) + GL_STUB(glGenerateMipmapEXT, 805) + GL_STUB(glGetFramebufferAttachmentParameterivEXT, 806) + GL_STUB(glGetRenderbufferParameterivEXT, 807) + GL_STUB(glIsFramebufferEXT, 808) + GL_STUB(glIsRenderbufferEXT, 809) + GL_STUB(glRenderbufferStorageEXT, 810) + GL_STUB(gl_dispatch_stub_811, 811) + HIDDEN(gl_dispatch_stub_811) + GL_STUB(gl_dispatch_stub_812, 812) + HIDDEN(gl_dispatch_stub_812) + GL_STUB(gl_dispatch_stub_813, 813) + HIDDEN(gl_dispatch_stub_813) + GL_STUB(glBindFragDataLocationEXT, 814) + GL_STUB(glGetFragDataLocationEXT, 815) + GL_STUB(glGetUniformuivEXT, 816) + GL_STUB(glGetVertexAttribIivEXT, 817) + GL_STUB(glGetVertexAttribIuivEXT, 818) + GL_STUB(glUniform1uiEXT, 819) + GL_STUB(glUniform1uivEXT, 820) + GL_STUB(glUniform2uiEXT, 821) + GL_STUB(glUniform2uivEXT, 822) + GL_STUB(glUniform3uiEXT, 823) + GL_STUB(glUniform3uivEXT, 824) + GL_STUB(glUniform4uiEXT, 825) + GL_STUB(glUniform4uivEXT, 826) + GL_STUB(glVertexAttribI1iEXT, 827) + GL_STUB(glVertexAttribI1ivEXT, 828) + GL_STUB(glVertexAttribI1uiEXT, 829) + GL_STUB(glVertexAttribI1uivEXT, 830) + GL_STUB(glVertexAttribI2iEXT, 831) + GL_STUB(glVertexAttribI2ivEXT, 832) + GL_STUB(glVertexAttribI2uiEXT, 833) + GL_STUB(glVertexAttribI2uivEXT, 834) + GL_STUB(glVertexAttribI3iEXT, 835) + GL_STUB(glVertexAttribI3ivEXT, 836) + GL_STUB(glVertexAttribI3uiEXT, 837) + GL_STUB(glVertexAttribI3uivEXT, 838) + GL_STUB(glVertexAttribI4bvEXT, 839) + GL_STUB(glVertexAttribI4iEXT, 840) + GL_STUB(glVertexAttribI4ivEXT, 841) + GL_STUB(glVertexAttribI4svEXT, 842) + GL_STUB(glVertexAttribI4ubvEXT, 843) + GL_STUB(glVertexAttribI4uiEXT, 844) + GL_STUB(glVertexAttribI4uivEXT, 845) + GL_STUB(glVertexAttribI4usvEXT, 846) + GL_STUB(glVertexAttribIPointerEXT, 847) + GL_STUB(glFramebufferTextureLayerEXT, 848) + GL_STUB(glColorMaskIndexedEXT, 849) + GL_STUB(glDisableIndexedEXT, 850) + GL_STUB(glEnableIndexedEXT, 851) + GL_STUB(glGetBooleanIndexedvEXT, 852) + GL_STUB(glGetIntegerIndexedvEXT, 853) + GL_STUB(glIsEnabledIndexedEXT, 854) + GL_STUB(glClearColorIiEXT, 855) + GL_STUB(glClearColorIuiEXT, 856) + GL_STUB(glGetTexParameterIivEXT, 857) + GL_STUB(glGetTexParameterIuivEXT, 858) + GL_STUB(glTexParameterIivEXT, 859) + GL_STUB(glTexParameterIuivEXT, 860) + GL_STUB(glBeginConditionalRenderNV, 861) + GL_STUB(glEndConditionalRenderNV, 862) + GL_STUB(glBeginTransformFeedbackEXT, 863) + GL_STUB(glBindBufferBaseEXT, 864) + GL_STUB(glBindBufferOffsetEXT, 865) + GL_STUB(glBindBufferRangeEXT, 866) + GL_STUB(glEndTransformFeedbackEXT, 867) + GL_STUB(glGetTransformFeedbackVaryingEXT, 868) + GL_STUB(glTransformFeedbackVaryingsEXT, 869) + GL_STUB(glProvokingVertexEXT, 870) + GL_STUB(gl_dispatch_stub_871, 871) + HIDDEN(gl_dispatch_stub_871) + GL_STUB(gl_dispatch_stub_872, 872) + HIDDEN(gl_dispatch_stub_872) + GL_STUB(glGetObjectParameterivAPPLE, 873) + GL_STUB(glObjectPurgeableAPPLE, 874) + GL_STUB(glObjectUnpurgeableAPPLE, 875) + GL_STUB(glActiveProgramEXT, 876) + GL_STUB(glCreateShaderProgramEXT, 877) + GL_STUB(glUseShaderProgramEXT, 878) + GL_STUB(gl_dispatch_stub_879, 879) + HIDDEN(gl_dispatch_stub_879) + GL_STUB(gl_dispatch_stub_880, 880) + HIDDEN(gl_dispatch_stub_880) + GL_STUB(gl_dispatch_stub_881, 881) + HIDDEN(gl_dispatch_stub_881) + GL_STUB(gl_dispatch_stub_882, 882) + HIDDEN(gl_dispatch_stub_882) + GL_STUB(gl_dispatch_stub_883, 883) + HIDDEN(gl_dispatch_stub_883) + GL_STUB(glEGLImageTargetRenderbufferStorageOES, 884) + GL_STUB(glEGLImageTargetTexture2DOES, 885) + GL_STUB_ALIAS(glArrayElementEXT, glArrayElement) + GL_STUB_ALIAS(glBindTextureEXT, glBindTexture) + GL_STUB_ALIAS(glDrawArraysEXT, glDrawArrays) +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glAreTexturesResidentEXT, glAreTexturesResident) +#endif + GL_STUB_ALIAS(glCopyTexImage1DEXT, glCopyTexImage1D) + GL_STUB_ALIAS(glCopyTexImage2DEXT, glCopyTexImage2D) + GL_STUB_ALIAS(glCopyTexSubImage1DEXT, glCopyTexSubImage1D) + GL_STUB_ALIAS(glCopyTexSubImage2DEXT, glCopyTexSubImage2D) +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glDeleteTexturesEXT, glDeleteTextures) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGenTexturesEXT, glGenTextures) +#endif + GL_STUB_ALIAS(glGetPointervEXT, glGetPointerv) +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glIsTextureEXT, glIsTexture) +#endif + GL_STUB_ALIAS(glPrioritizeTexturesEXT, glPrioritizeTextures) + GL_STUB_ALIAS(glTexSubImage1DEXT, glTexSubImage1D) + GL_STUB_ALIAS(glTexSubImage2DEXT, glTexSubImage2D) + GL_STUB_ALIAS(glBlendColorEXT, glBlendColor) + GL_STUB_ALIAS(glBlendEquationEXT, glBlendEquation) + GL_STUB_ALIAS(glDrawRangeElementsEXT, glDrawRangeElements) + GL_STUB_ALIAS(glColorTableSGI, glColorTable) + GL_STUB_ALIAS(glColorTableEXT, glColorTable) + GL_STUB_ALIAS(glColorTableParameterfvSGI, glColorTableParameterfv) + GL_STUB_ALIAS(glColorTableParameterivSGI, glColorTableParameteriv) + GL_STUB_ALIAS(glCopyColorTableSGI, glCopyColorTable) +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetColorTableSGI, glGetColorTable) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetColorTableEXT, glGetColorTable) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetColorTableParameterfvSGI, glGetColorTableParameterfv) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetColorTableParameterfvEXT, glGetColorTableParameterfv) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetColorTableParameterivSGI, glGetColorTableParameteriv) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetColorTableParameterivEXT, glGetColorTableParameteriv) +#endif + GL_STUB_ALIAS(glColorSubTableEXT, glColorSubTable) + GL_STUB_ALIAS(glCopyColorSubTableEXT, glCopyColorSubTable) + GL_STUB_ALIAS(glConvolutionFilter1DEXT, glConvolutionFilter1D) + GL_STUB_ALIAS(glConvolutionFilter2DEXT, glConvolutionFilter2D) + GL_STUB_ALIAS(glConvolutionParameterfEXT, glConvolutionParameterf) + GL_STUB_ALIAS(glConvolutionParameterfvEXT, glConvolutionParameterfv) + GL_STUB_ALIAS(glConvolutionParameteriEXT, glConvolutionParameteri) + GL_STUB_ALIAS(glConvolutionParameterivEXT, glConvolutionParameteriv) + GL_STUB_ALIAS(glCopyConvolutionFilter1DEXT, glCopyConvolutionFilter1D) + GL_STUB_ALIAS(glCopyConvolutionFilter2DEXT, glCopyConvolutionFilter2D) +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetConvolutionFilterEXT, glGetConvolutionFilter) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetConvolutionParameterfvEXT, glGetConvolutionParameterfv) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetConvolutionParameterivEXT, glGetConvolutionParameteriv) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetSeparableFilterEXT, glGetSeparableFilter) +#endif + GL_STUB_ALIAS(glSeparableFilter2DEXT, glSeparableFilter2D) +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetHistogramEXT, glGetHistogram) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetHistogramParameterfvEXT, glGetHistogramParameterfv) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetHistogramParameterivEXT, glGetHistogramParameteriv) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetMinmaxEXT, glGetMinmax) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetMinmaxParameterfvEXT, glGetMinmaxParameterfv) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(glGetMinmaxParameterivEXT, glGetMinmaxParameteriv) +#endif + GL_STUB_ALIAS(glHistogramEXT, glHistogram) + GL_STUB_ALIAS(glMinmaxEXT, glMinmax) + GL_STUB_ALIAS(glResetHistogramEXT, glResetHistogram) + GL_STUB_ALIAS(glResetMinmaxEXT, glResetMinmax) + GL_STUB_ALIAS(glTexImage3DEXT, glTexImage3D) + GL_STUB_ALIAS(glTexSubImage3DEXT, glTexSubImage3D) + GL_STUB_ALIAS(glCopyTexSubImage3DEXT, glCopyTexSubImage3D) + GL_STUB_ALIAS(glActiveTexture, glActiveTextureARB) + GL_STUB_ALIAS(glClientActiveTexture, glClientActiveTextureARB) + GL_STUB_ALIAS(glMultiTexCoord1d, glMultiTexCoord1dARB) + GL_STUB_ALIAS(glMultiTexCoord1dv, glMultiTexCoord1dvARB) + GL_STUB_ALIAS(glMultiTexCoord1f, glMultiTexCoord1fARB) + GL_STUB_ALIAS(glMultiTexCoord1fv, glMultiTexCoord1fvARB) + GL_STUB_ALIAS(glMultiTexCoord1i, glMultiTexCoord1iARB) + GL_STUB_ALIAS(glMultiTexCoord1iv, glMultiTexCoord1ivARB) + GL_STUB_ALIAS(glMultiTexCoord1s, glMultiTexCoord1sARB) + GL_STUB_ALIAS(glMultiTexCoord1sv, glMultiTexCoord1svARB) + GL_STUB_ALIAS(glMultiTexCoord2d, glMultiTexCoord2dARB) + GL_STUB_ALIAS(glMultiTexCoord2dv, glMultiTexCoord2dvARB) + GL_STUB_ALIAS(glMultiTexCoord2f, glMultiTexCoord2fARB) + GL_STUB_ALIAS(glMultiTexCoord2fv, glMultiTexCoord2fvARB) + GL_STUB_ALIAS(glMultiTexCoord2i, glMultiTexCoord2iARB) + GL_STUB_ALIAS(glMultiTexCoord2iv, glMultiTexCoord2ivARB) + GL_STUB_ALIAS(glMultiTexCoord2s, glMultiTexCoord2sARB) + GL_STUB_ALIAS(glMultiTexCoord2sv, glMultiTexCoord2svARB) + GL_STUB_ALIAS(glMultiTexCoord3d, glMultiTexCoord3dARB) + GL_STUB_ALIAS(glMultiTexCoord3dv, glMultiTexCoord3dvARB) + GL_STUB_ALIAS(glMultiTexCoord3f, glMultiTexCoord3fARB) + GL_STUB_ALIAS(glMultiTexCoord3fv, glMultiTexCoord3fvARB) + GL_STUB_ALIAS(glMultiTexCoord3i, glMultiTexCoord3iARB) + GL_STUB_ALIAS(glMultiTexCoord3iv, glMultiTexCoord3ivARB) + GL_STUB_ALIAS(glMultiTexCoord3s, glMultiTexCoord3sARB) + GL_STUB_ALIAS(glMultiTexCoord3sv, glMultiTexCoord3svARB) + GL_STUB_ALIAS(glMultiTexCoord4d, glMultiTexCoord4dARB) + GL_STUB_ALIAS(glMultiTexCoord4dv, glMultiTexCoord4dvARB) + GL_STUB_ALIAS(glMultiTexCoord4f, glMultiTexCoord4fARB) + GL_STUB_ALIAS(glMultiTexCoord4fv, glMultiTexCoord4fvARB) + GL_STUB_ALIAS(glMultiTexCoord4i, glMultiTexCoord4iARB) + GL_STUB_ALIAS(glMultiTexCoord4iv, glMultiTexCoord4ivARB) + GL_STUB_ALIAS(glMultiTexCoord4s, glMultiTexCoord4sARB) + GL_STUB_ALIAS(glMultiTexCoord4sv, glMultiTexCoord4svARB) + GL_STUB_ALIAS(glStencilOpSeparateATI, glStencilOpSeparate) + GL_STUB_ALIAS(glLoadTransposeMatrixd, glLoadTransposeMatrixdARB) + GL_STUB_ALIAS(glLoadTransposeMatrixf, glLoadTransposeMatrixfARB) + GL_STUB_ALIAS(glMultTransposeMatrixd, glMultTransposeMatrixdARB) + GL_STUB_ALIAS(glMultTransposeMatrixf, glMultTransposeMatrixfARB) + GL_STUB_ALIAS(glSampleCoverage, glSampleCoverageARB) + GL_STUB_ALIAS(glCompressedTexImage1D, glCompressedTexImage1DARB) + GL_STUB_ALIAS(glCompressedTexImage2D, glCompressedTexImage2DARB) + GL_STUB_ALIAS(glCompressedTexImage3D, glCompressedTexImage3DARB) + GL_STUB_ALIAS(glCompressedTexSubImage1D, glCompressedTexSubImage1DARB) + GL_STUB_ALIAS(glCompressedTexSubImage2D, glCompressedTexSubImage2DARB) + GL_STUB_ALIAS(glCompressedTexSubImage3D, glCompressedTexSubImage3DARB) + GL_STUB_ALIAS(glGetCompressedTexImage, glGetCompressedTexImageARB) + GL_STUB_ALIAS(glDisableVertexAttribArray, glDisableVertexAttribArrayARB) + GL_STUB_ALIAS(glEnableVertexAttribArray, glEnableVertexAttribArrayARB) + GL_STUB_ALIAS(glGetVertexAttribdv, glGetVertexAttribdvARB) + GL_STUB_ALIAS(glGetVertexAttribfv, glGetVertexAttribfvARB) + GL_STUB_ALIAS(glGetVertexAttribiv, glGetVertexAttribivARB) + GL_STUB_ALIAS(glProgramParameter4dNV, glProgramEnvParameter4dARB) + GL_STUB_ALIAS(glProgramParameter4dvNV, glProgramEnvParameter4dvARB) + GL_STUB_ALIAS(glProgramParameter4fNV, glProgramEnvParameter4fARB) + GL_STUB_ALIAS(glProgramParameter4fvNV, glProgramEnvParameter4fvARB) + GL_STUB_ALIAS(glVertexAttrib1d, glVertexAttrib1dARB) + GL_STUB_ALIAS(glVertexAttrib1dv, glVertexAttrib1dvARB) + GL_STUB_ALIAS(glVertexAttrib1f, glVertexAttrib1fARB) + GL_STUB_ALIAS(glVertexAttrib1fv, glVertexAttrib1fvARB) + GL_STUB_ALIAS(glVertexAttrib1s, glVertexAttrib1sARB) + GL_STUB_ALIAS(glVertexAttrib1sv, glVertexAttrib1svARB) + GL_STUB_ALIAS(glVertexAttrib2d, glVertexAttrib2dARB) + GL_STUB_ALIAS(glVertexAttrib2dv, glVertexAttrib2dvARB) + GL_STUB_ALIAS(glVertexAttrib2f, glVertexAttrib2fARB) + GL_STUB_ALIAS(glVertexAttrib2fv, glVertexAttrib2fvARB) + GL_STUB_ALIAS(glVertexAttrib2s, glVertexAttrib2sARB) + GL_STUB_ALIAS(glVertexAttrib2sv, glVertexAttrib2svARB) + GL_STUB_ALIAS(glVertexAttrib3d, glVertexAttrib3dARB) + GL_STUB_ALIAS(glVertexAttrib3dv, glVertexAttrib3dvARB) + GL_STUB_ALIAS(glVertexAttrib3f, glVertexAttrib3fARB) + GL_STUB_ALIAS(glVertexAttrib3fv, glVertexAttrib3fvARB) + GL_STUB_ALIAS(glVertexAttrib3s, glVertexAttrib3sARB) + GL_STUB_ALIAS(glVertexAttrib3sv, glVertexAttrib3svARB) + GL_STUB_ALIAS(glVertexAttrib4Nbv, glVertexAttrib4NbvARB) + GL_STUB_ALIAS(glVertexAttrib4Niv, glVertexAttrib4NivARB) + GL_STUB_ALIAS(glVertexAttrib4Nsv, glVertexAttrib4NsvARB) + GL_STUB_ALIAS(glVertexAttrib4Nub, glVertexAttrib4NubARB) + GL_STUB_ALIAS(glVertexAttrib4Nubv, glVertexAttrib4NubvARB) + GL_STUB_ALIAS(glVertexAttrib4Nuiv, glVertexAttrib4NuivARB) + GL_STUB_ALIAS(glVertexAttrib4Nusv, glVertexAttrib4NusvARB) + GL_STUB_ALIAS(glVertexAttrib4bv, glVertexAttrib4bvARB) + GL_STUB_ALIAS(glVertexAttrib4d, glVertexAttrib4dARB) + GL_STUB_ALIAS(glVertexAttrib4dv, glVertexAttrib4dvARB) + GL_STUB_ALIAS(glVertexAttrib4f, glVertexAttrib4fARB) + GL_STUB_ALIAS(glVertexAttrib4fv, glVertexAttrib4fvARB) + GL_STUB_ALIAS(glVertexAttrib4iv, glVertexAttrib4ivARB) + GL_STUB_ALIAS(glVertexAttrib4s, glVertexAttrib4sARB) + GL_STUB_ALIAS(glVertexAttrib4sv, glVertexAttrib4svARB) + GL_STUB_ALIAS(glVertexAttrib4ubv, glVertexAttrib4ubvARB) + GL_STUB_ALIAS(glVertexAttrib4uiv, glVertexAttrib4uivARB) + GL_STUB_ALIAS(glVertexAttrib4usv, glVertexAttrib4usvARB) + GL_STUB_ALIAS(glVertexAttribPointer, glVertexAttribPointerARB) + GL_STUB_ALIAS(glBindBuffer, glBindBufferARB) + GL_STUB_ALIAS(glBufferData, glBufferDataARB) + GL_STUB_ALIAS(glBufferSubData, glBufferSubDataARB) + GL_STUB_ALIAS(glDeleteBuffers, glDeleteBuffersARB) + GL_STUB_ALIAS(glGenBuffers, glGenBuffersARB) + GL_STUB_ALIAS(glGetBufferParameteriv, glGetBufferParameterivARB) + GL_STUB_ALIAS(glGetBufferPointerv, glGetBufferPointervARB) + GL_STUB_ALIAS(glGetBufferSubData, glGetBufferSubDataARB) + GL_STUB_ALIAS(glIsBuffer, glIsBufferARB) + GL_STUB_ALIAS(glMapBuffer, glMapBufferARB) + GL_STUB_ALIAS(glUnmapBuffer, glUnmapBufferARB) + GL_STUB_ALIAS(glBeginQuery, glBeginQueryARB) + GL_STUB_ALIAS(glDeleteQueries, glDeleteQueriesARB) + GL_STUB_ALIAS(glEndQuery, glEndQueryARB) + GL_STUB_ALIAS(glGenQueries, glGenQueriesARB) + GL_STUB_ALIAS(glGetQueryObjectiv, glGetQueryObjectivARB) + GL_STUB_ALIAS(glGetQueryObjectuiv, glGetQueryObjectuivARB) + GL_STUB_ALIAS(glGetQueryiv, glGetQueryivARB) + GL_STUB_ALIAS(glIsQuery, glIsQueryARB) + GL_STUB_ALIAS(glCompileShader, glCompileShaderARB) + GL_STUB_ALIAS(glGetActiveUniform, glGetActiveUniformARB) + GL_STUB_ALIAS(glGetShaderSource, glGetShaderSourceARB) + GL_STUB_ALIAS(glGetUniformLocation, glGetUniformLocationARB) + GL_STUB_ALIAS(glGetUniformfv, glGetUniformfvARB) + GL_STUB_ALIAS(glGetUniformiv, glGetUniformivARB) + GL_STUB_ALIAS(glLinkProgram, glLinkProgramARB) + GL_STUB_ALIAS(glShaderSource, glShaderSourceARB) + GL_STUB_ALIAS(glUniform1f, glUniform1fARB) + GL_STUB_ALIAS(glUniform1fv, glUniform1fvARB) + GL_STUB_ALIAS(glUniform1i, glUniform1iARB) + GL_STUB_ALIAS(glUniform1iv, glUniform1ivARB) + GL_STUB_ALIAS(glUniform2f, glUniform2fARB) + GL_STUB_ALIAS(glUniform2fv, glUniform2fvARB) + GL_STUB_ALIAS(glUniform2i, glUniform2iARB) + GL_STUB_ALIAS(glUniform2iv, glUniform2ivARB) + GL_STUB_ALIAS(glUniform3f, glUniform3fARB) + GL_STUB_ALIAS(glUniform3fv, glUniform3fvARB) + GL_STUB_ALIAS(glUniform3i, glUniform3iARB) + GL_STUB_ALIAS(glUniform3iv, glUniform3ivARB) + GL_STUB_ALIAS(glUniform4f, glUniform4fARB) + GL_STUB_ALIAS(glUniform4fv, glUniform4fvARB) + GL_STUB_ALIAS(glUniform4i, glUniform4iARB) + GL_STUB_ALIAS(glUniform4iv, glUniform4ivARB) + GL_STUB_ALIAS(glUniformMatrix2fv, glUniformMatrix2fvARB) + GL_STUB_ALIAS(glUniformMatrix3fv, glUniformMatrix3fvARB) + GL_STUB_ALIAS(glUniformMatrix4fv, glUniformMatrix4fvARB) + GL_STUB_ALIAS(glUseProgram, glUseProgramObjectARB) + GL_STUB_ALIAS(glValidateProgram, glValidateProgramARB) + GL_STUB_ALIAS(glBindAttribLocation, glBindAttribLocationARB) + GL_STUB_ALIAS(glGetActiveAttrib, glGetActiveAttribARB) + GL_STUB_ALIAS(glGetAttribLocation, glGetAttribLocationARB) + GL_STUB_ALIAS(glDrawBuffers, glDrawBuffersARB) + GL_STUB_ALIAS(glDrawBuffersATI, glDrawBuffersARB) + GL_STUB_ALIAS(glDrawArraysInstancedEXT, glDrawArraysInstancedARB) + GL_STUB_ALIAS(glDrawArraysInstanced, glDrawArraysInstancedARB) + GL_STUB_ALIAS(glDrawElementsInstancedEXT, glDrawElementsInstancedARB) + GL_STUB_ALIAS(glDrawElementsInstanced, glDrawElementsInstancedARB) + GL_STUB_ALIAS(glRenderbufferStorageMultisampleEXT, glRenderbufferStorageMultisample) + GL_STUB_ALIAS(glPointParameterf, glPointParameterfEXT) + GL_STUB_ALIAS(glPointParameterfARB, glPointParameterfEXT) + GL_STUB_ALIAS(glPointParameterfSGIS, glPointParameterfEXT) + GL_STUB_ALIAS(glPointParameterfv, glPointParameterfvEXT) + GL_STUB_ALIAS(glPointParameterfvARB, glPointParameterfvEXT) + GL_STUB_ALIAS(glPointParameterfvSGIS, glPointParameterfvEXT) + GL_STUB_ALIAS(glSecondaryColor3b, glSecondaryColor3bEXT) + GL_STUB_ALIAS(glSecondaryColor3bv, glSecondaryColor3bvEXT) + GL_STUB_ALIAS(glSecondaryColor3d, glSecondaryColor3dEXT) + GL_STUB_ALIAS(glSecondaryColor3dv, glSecondaryColor3dvEXT) + GL_STUB_ALIAS(glSecondaryColor3f, glSecondaryColor3fEXT) + GL_STUB_ALIAS(glSecondaryColor3fv, glSecondaryColor3fvEXT) + GL_STUB_ALIAS(glSecondaryColor3i, glSecondaryColor3iEXT) + GL_STUB_ALIAS(glSecondaryColor3iv, glSecondaryColor3ivEXT) + GL_STUB_ALIAS(glSecondaryColor3s, glSecondaryColor3sEXT) + GL_STUB_ALIAS(glSecondaryColor3sv, glSecondaryColor3svEXT) + GL_STUB_ALIAS(glSecondaryColor3ub, glSecondaryColor3ubEXT) + GL_STUB_ALIAS(glSecondaryColor3ubv, glSecondaryColor3ubvEXT) + GL_STUB_ALIAS(glSecondaryColor3ui, glSecondaryColor3uiEXT) + GL_STUB_ALIAS(glSecondaryColor3uiv, glSecondaryColor3uivEXT) + GL_STUB_ALIAS(glSecondaryColor3us, glSecondaryColor3usEXT) + GL_STUB_ALIAS(glSecondaryColor3usv, glSecondaryColor3usvEXT) + GL_STUB_ALIAS(glSecondaryColorPointer, glSecondaryColorPointerEXT) + GL_STUB_ALIAS(glMultiDrawArrays, glMultiDrawArraysEXT) + GL_STUB_ALIAS(glMultiDrawElements, glMultiDrawElementsEXT) + GL_STUB_ALIAS(glFogCoordPointer, glFogCoordPointerEXT) + GL_STUB_ALIAS(glFogCoordd, glFogCoorddEXT) + GL_STUB_ALIAS(glFogCoorddv, glFogCoorddvEXT) + GL_STUB_ALIAS(glFogCoordf, glFogCoordfEXT) + GL_STUB_ALIAS(glFogCoordfv, glFogCoordfvEXT) + GL_STUB_ALIAS(glBlendFuncSeparate, glBlendFuncSeparateEXT) + GL_STUB_ALIAS(glBlendFuncSeparateINGR, glBlendFuncSeparateEXT) + GL_STUB_ALIAS(glWindowPos2d, glWindowPos2dMESA) + GL_STUB_ALIAS(glWindowPos2dARB, glWindowPos2dMESA) + GL_STUB_ALIAS(glWindowPos2dv, glWindowPos2dvMESA) + GL_STUB_ALIAS(glWindowPos2dvARB, glWindowPos2dvMESA) + GL_STUB_ALIAS(glWindowPos2f, glWindowPos2fMESA) + GL_STUB_ALIAS(glWindowPos2fARB, glWindowPos2fMESA) + GL_STUB_ALIAS(glWindowPos2fv, glWindowPos2fvMESA) + GL_STUB_ALIAS(glWindowPos2fvARB, glWindowPos2fvMESA) + GL_STUB_ALIAS(glWindowPos2i, glWindowPos2iMESA) + GL_STUB_ALIAS(glWindowPos2iARB, glWindowPos2iMESA) + GL_STUB_ALIAS(glWindowPos2iv, glWindowPos2ivMESA) + GL_STUB_ALIAS(glWindowPos2ivARB, glWindowPos2ivMESA) + GL_STUB_ALIAS(glWindowPos2s, glWindowPos2sMESA) + GL_STUB_ALIAS(glWindowPos2sARB, glWindowPos2sMESA) + GL_STUB_ALIAS(glWindowPos2sv, glWindowPos2svMESA) + GL_STUB_ALIAS(glWindowPos2svARB, glWindowPos2svMESA) + GL_STUB_ALIAS(glWindowPos3d, glWindowPos3dMESA) + GL_STUB_ALIAS(glWindowPos3dARB, glWindowPos3dMESA) + GL_STUB_ALIAS(glWindowPos3dv, glWindowPos3dvMESA) + GL_STUB_ALIAS(glWindowPos3dvARB, glWindowPos3dvMESA) + GL_STUB_ALIAS(glWindowPos3f, glWindowPos3fMESA) + GL_STUB_ALIAS(glWindowPos3fARB, glWindowPos3fMESA) + GL_STUB_ALIAS(glWindowPos3fv, glWindowPos3fvMESA) + GL_STUB_ALIAS(glWindowPos3fvARB, glWindowPos3fvMESA) + GL_STUB_ALIAS(glWindowPos3i, glWindowPos3iMESA) + GL_STUB_ALIAS(glWindowPos3iARB, glWindowPos3iMESA) + GL_STUB_ALIAS(glWindowPos3iv, glWindowPos3ivMESA) + GL_STUB_ALIAS(glWindowPos3ivARB, glWindowPos3ivMESA) + GL_STUB_ALIAS(glWindowPos3s, glWindowPos3sMESA) + GL_STUB_ALIAS(glWindowPos3sARB, glWindowPos3sMESA) + GL_STUB_ALIAS(glWindowPos3sv, glWindowPos3svMESA) + GL_STUB_ALIAS(glWindowPos3svARB, glWindowPos3svMESA) + GL_STUB_ALIAS(glBindProgramARB, glBindProgramNV) + GL_STUB_ALIAS(glDeleteProgramsARB, glDeleteProgramsNV) + GL_STUB_ALIAS(glGenProgramsARB, glGenProgramsNV) + GL_STUB_ALIAS(glGetVertexAttribPointerv, glGetVertexAttribPointervNV) + GL_STUB_ALIAS(glGetVertexAttribPointervARB, glGetVertexAttribPointervNV) + GL_STUB_ALIAS(glIsProgramARB, glIsProgramNV) + GL_STUB_ALIAS(glPointParameteri, glPointParameteriNV) + GL_STUB_ALIAS(glPointParameteriv, glPointParameterivNV) + GL_STUB_ALIAS(glPrimitiveRestartIndex, glPrimitiveRestartIndexNV) + GL_STUB_ALIAS(glBindFramebuffer, glBindFramebufferEXT) + GL_STUB_ALIAS(glBindRenderbuffer, glBindRenderbufferEXT) + GL_STUB_ALIAS(glCheckFramebufferStatus, glCheckFramebufferStatusEXT) + GL_STUB_ALIAS(glDeleteFramebuffers, glDeleteFramebuffersEXT) + GL_STUB_ALIAS(glDeleteRenderbuffers, glDeleteRenderbuffersEXT) + GL_STUB_ALIAS(glFramebufferRenderbuffer, glFramebufferRenderbufferEXT) + GL_STUB_ALIAS(glFramebufferTexture1D, glFramebufferTexture1DEXT) + GL_STUB_ALIAS(glFramebufferTexture2D, glFramebufferTexture2DEXT) + GL_STUB_ALIAS(glFramebufferTexture3D, glFramebufferTexture3DEXT) + GL_STUB_ALIAS(glGenFramebuffers, glGenFramebuffersEXT) + GL_STUB_ALIAS(glGenRenderbuffers, glGenRenderbuffersEXT) + GL_STUB_ALIAS(glGenerateMipmap, glGenerateMipmapEXT) + GL_STUB_ALIAS(glGetFramebufferAttachmentParameteriv, glGetFramebufferAttachmentParameterivEXT) + GL_STUB_ALIAS(glGetRenderbufferParameteriv, glGetRenderbufferParameterivEXT) + GL_STUB_ALIAS(glIsFramebuffer, glIsFramebufferEXT) + GL_STUB_ALIAS(glIsRenderbuffer, glIsRenderbufferEXT) + GL_STUB_ALIAS(glRenderbufferStorage, glRenderbufferStorageEXT) + GL_STUB_ALIAS(glBindFragDataLocation, glBindFragDataLocationEXT) + GL_STUB_ALIAS(glGetFragDataLocation, glGetFragDataLocationEXT) + GL_STUB_ALIAS(glGetUniformuiv, glGetUniformuivEXT) + GL_STUB_ALIAS(glGetVertexAttribIiv, glGetVertexAttribIivEXT) + GL_STUB_ALIAS(glGetVertexAttribIuiv, glGetVertexAttribIuivEXT) + GL_STUB_ALIAS(glUniform1ui, glUniform1uiEXT) + GL_STUB_ALIAS(glUniform1uiv, glUniform1uivEXT) + GL_STUB_ALIAS(glUniform2ui, glUniform2uiEXT) + GL_STUB_ALIAS(glUniform2uiv, glUniform2uivEXT) + GL_STUB_ALIAS(glUniform3ui, glUniform3uiEXT) + GL_STUB_ALIAS(glUniform3uiv, glUniform3uivEXT) + GL_STUB_ALIAS(glUniform4ui, glUniform4uiEXT) + GL_STUB_ALIAS(glUniform4uiv, glUniform4uivEXT) + GL_STUB_ALIAS(glVertexAttribI1i, glVertexAttribI1iEXT) + GL_STUB_ALIAS(glVertexAttribI1iv, glVertexAttribI1ivEXT) + GL_STUB_ALIAS(glVertexAttribI1ui, glVertexAttribI1uiEXT) + GL_STUB_ALIAS(glVertexAttribI1uiv, glVertexAttribI1uivEXT) + GL_STUB_ALIAS(glVertexAttribI2i, glVertexAttribI2iEXT) + GL_STUB_ALIAS(glVertexAttribI2iv, glVertexAttribI2ivEXT) + GL_STUB_ALIAS(glVertexAttribI2ui, glVertexAttribI2uiEXT) + GL_STUB_ALIAS(glVertexAttribI2uiv, glVertexAttribI2uivEXT) + GL_STUB_ALIAS(glVertexAttribI3i, glVertexAttribI3iEXT) + GL_STUB_ALIAS(glVertexAttribI3iv, glVertexAttribI3ivEXT) + GL_STUB_ALIAS(glVertexAttribI3ui, glVertexAttribI3uiEXT) + GL_STUB_ALIAS(glVertexAttribI3uiv, glVertexAttribI3uivEXT) + GL_STUB_ALIAS(glVertexAttribI4bv, glVertexAttribI4bvEXT) + GL_STUB_ALIAS(glVertexAttribI4i, glVertexAttribI4iEXT) + GL_STUB_ALIAS(glVertexAttribI4iv, glVertexAttribI4ivEXT) + GL_STUB_ALIAS(glVertexAttribI4sv, glVertexAttribI4svEXT) + GL_STUB_ALIAS(glVertexAttribI4ubv, glVertexAttribI4ubvEXT) + GL_STUB_ALIAS(glVertexAttribI4ui, glVertexAttribI4uiEXT) + GL_STUB_ALIAS(glVertexAttribI4uiv, glVertexAttribI4uivEXT) + GL_STUB_ALIAS(glVertexAttribI4usv, glVertexAttribI4usvEXT) + GL_STUB_ALIAS(glVertexAttribIPointer, glVertexAttribIPointerEXT) + GL_STUB_ALIAS(glFramebufferTextureLayer, glFramebufferTextureLayerEXT) + GL_STUB_ALIAS(glColorMaski, glColorMaskIndexedEXT) + GL_STUB_ALIAS(glDisablei, glDisableIndexedEXT) + GL_STUB_ALIAS(glEnablei, glEnableIndexedEXT) + GL_STUB_ALIAS(glGetBooleani_v, glGetBooleanIndexedvEXT) + GL_STUB_ALIAS(glGetIntegeri_v, glGetIntegerIndexedvEXT) + GL_STUB_ALIAS(glIsEnabledi, glIsEnabledIndexedEXT) + GL_STUB_ALIAS(glGetTexParameterIiv, glGetTexParameterIivEXT) + GL_STUB_ALIAS(glGetTexParameterIuiv, glGetTexParameterIuivEXT) + GL_STUB_ALIAS(glTexParameterIiv, glTexParameterIivEXT) + GL_STUB_ALIAS(glTexParameterIuiv, glTexParameterIuivEXT) + GL_STUB_ALIAS(glBeginConditionalRender, glBeginConditionalRenderNV) + GL_STUB_ALIAS(glEndConditionalRender, glEndConditionalRenderNV) + GL_STUB_ALIAS(glBeginTransformFeedback, glBeginTransformFeedbackEXT) + GL_STUB_ALIAS(glBindBufferBase, glBindBufferBaseEXT) + GL_STUB_ALIAS(glBindBufferRange, glBindBufferRangeEXT) + GL_STUB_ALIAS(glEndTransformFeedback, glEndTransformFeedbackEXT) + GL_STUB_ALIAS(glGetTransformFeedbackVarying, glGetTransformFeedbackVaryingEXT) + GL_STUB_ALIAS(glTransformFeedbackVaryings, glTransformFeedbackVaryingsEXT) + GL_STUB_ALIAS(glProvokingVertex, glProvokingVertexEXT) + + .globl gl_dispatch_functions_end + HIDDEN(gl_dispatch_functions_end) +gl_dispatch_functions_end: diff --git a/src/mapi/glapi/glapi_x86-64.S b/src/mapi/glapi/glapi_x86-64.S new file mode 100644 index 0000000..486cf73 --- /dev/null +++ b/src/mapi/glapi/glapi_x86-64.S @@ -0,0 +1,33941 @@ +/* DO NOT EDIT - This file generated automatically by gl_x86-64_asm.py (from Mesa) script */ + +/* + * (C) Copyright IBM Corporation 2005 + * 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 + * IBM, + * 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. + */ + +/* If we build with gcc's -fvisibility=hidden flag, we'll need to change + * the symbol visibility mode to 'default'. + */ + +#include "x86/assyntax.h" + +#ifdef __GNUC__ +# pragma GCC visibility push(default) +# define HIDDEN(x) .hidden x +#else +# define HIDDEN(x) +#endif + +# if defined(USE_MGL_NAMESPACE) +# define GL_PREFIX(n) GLNAME(CONCAT(mgl,n)) +# define _glapi_Dispatch _mglapi_Dispatch +# else +# define GL_PREFIX(n) GLNAME(CONCAT(gl,n)) +# endif + +#if defined(PTHREADS) || defined(WIN32) || defined(BEOS_THREADS) +# define THREADS +#endif + + .text + +#ifdef GLX_USE_TLS + + .globl _x86_64_get_get_dispatch; HIDDEN(_x86_64_get_get_dispatch) +_x86_64_get_get_dispatch: + lea _x86_64_get_dispatch(%rip), %rax + ret + + .p2align 4,,15 +_x86_64_get_dispatch: + movq _glapi_tls_Dispatch@GOTTPOFF(%rip), %rax + movq %fs:(%rax), %rax + ret + .size _x86_64_get_dispatch, .-_x86_64_get_dispatch + +#elif defined(PTHREADS) + + .extern _glapi_Dispatch + .extern _gl_DispatchTSD + .extern pthread_getspecific + + .p2align 4,,15 +_x86_64_get_dispatch: + movq _gl_DispatchTSD@GOTPCREL(%rip), %rax + movl (%rax), %edi + jmp pthread_getspecific@PLT + +#elif defined(THREADS) + + .extern _glapi_get_dispatch + +#endif + + .p2align 4,,15 + .globl GL_PREFIX(NewList) + .type GL_PREFIX(NewList), @function +GL_PREFIX(NewList): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 0(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq (%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 0(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 0(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(NewList), .-GL_PREFIX(NewList) + + .p2align 4,,15 + .globl GL_PREFIX(EndList) + .type GL_PREFIX(EndList), @function +GL_PREFIX(EndList): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 8(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 8(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 8(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 8(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EndList), .-GL_PREFIX(EndList) + + .p2align 4,,15 + .globl GL_PREFIX(CallList) + .type GL_PREFIX(CallList), @function +GL_PREFIX(CallList): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 16(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 16(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 16(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 16(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CallList), .-GL_PREFIX(CallList) + + .p2align 4,,15 + .globl GL_PREFIX(CallLists) + .type GL_PREFIX(CallLists), @function +GL_PREFIX(CallLists): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 24(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 24(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 24(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 24(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CallLists), .-GL_PREFIX(CallLists) + + .p2align 4,,15 + .globl GL_PREFIX(DeleteLists) + .type GL_PREFIX(DeleteLists), @function +GL_PREFIX(DeleteLists): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 32(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 32(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 32(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 32(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DeleteLists), .-GL_PREFIX(DeleteLists) + + .p2align 4,,15 + .globl GL_PREFIX(GenLists) + .type GL_PREFIX(GenLists), @function +GL_PREFIX(GenLists): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 40(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 40(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 40(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 40(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GenLists), .-GL_PREFIX(GenLists) + + .p2align 4,,15 + .globl GL_PREFIX(ListBase) + .type GL_PREFIX(ListBase), @function +GL_PREFIX(ListBase): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 48(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 48(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 48(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 48(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ListBase), .-GL_PREFIX(ListBase) + + .p2align 4,,15 + .globl GL_PREFIX(Begin) + .type GL_PREFIX(Begin), @function +GL_PREFIX(Begin): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 56(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 56(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 56(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 56(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Begin), .-GL_PREFIX(Begin) + + .p2align 4,,15 + .globl GL_PREFIX(Bitmap) + .type GL_PREFIX(Bitmap), @function +GL_PREFIX(Bitmap): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 64(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $56, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + movq %xmm1, 24(%rsp) + movq %xmm2, 32(%rsp) + movq %xmm3, 40(%rsp) + movq %rdx, 48(%rsp) + call _x86_64_get_dispatch@PLT + movq 48(%rsp), %rdx + movq 40(%rsp), %xmm3 + movq 32(%rsp), %xmm2 + movq 24(%rsp), %xmm1 + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $56, %rsp + movq 64(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 64(%rax), %r11 + jmp *%r11 +1: + subq $56, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + movq %xmm1, 24(%rsp) + movq %xmm2, 32(%rsp) + movq %xmm3, 40(%rsp) + movq %rdx, 48(%rsp) + call _glapi_get_dispatch + movq 48(%rsp), %rdx + movq 40(%rsp), %xmm3 + movq 32(%rsp), %xmm2 + movq 24(%rsp), %xmm1 + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $56, %rsp + movq 64(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Bitmap), .-GL_PREFIX(Bitmap) + + .p2align 4,,15 + .globl GL_PREFIX(Color3b) + .type GL_PREFIX(Color3b), @function +GL_PREFIX(Color3b): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 72(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 72(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 72(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 72(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3b), .-GL_PREFIX(Color3b) + + .p2align 4,,15 + .globl GL_PREFIX(Color3bv) + .type GL_PREFIX(Color3bv), @function +GL_PREFIX(Color3bv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 80(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 80(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 80(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 80(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3bv), .-GL_PREFIX(Color3bv) + + .p2align 4,,15 + .globl GL_PREFIX(Color3d) + .type GL_PREFIX(Color3d), @function +GL_PREFIX(Color3d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 88(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 88(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 88(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 88(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3d), .-GL_PREFIX(Color3d) + + .p2align 4,,15 + .globl GL_PREFIX(Color3dv) + .type GL_PREFIX(Color3dv), @function +GL_PREFIX(Color3dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 96(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 96(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 96(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 96(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3dv), .-GL_PREFIX(Color3dv) + + .p2align 4,,15 + .globl GL_PREFIX(Color3f) + .type GL_PREFIX(Color3f), @function +GL_PREFIX(Color3f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 104(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 104(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 104(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 104(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3f), .-GL_PREFIX(Color3f) + + .p2align 4,,15 + .globl GL_PREFIX(Color3fv) + .type GL_PREFIX(Color3fv), @function +GL_PREFIX(Color3fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 112(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 112(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 112(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 112(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3fv), .-GL_PREFIX(Color3fv) + + .p2align 4,,15 + .globl GL_PREFIX(Color3i) + .type GL_PREFIX(Color3i), @function +GL_PREFIX(Color3i): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 120(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 120(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 120(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 120(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3i), .-GL_PREFIX(Color3i) + + .p2align 4,,15 + .globl GL_PREFIX(Color3iv) + .type GL_PREFIX(Color3iv), @function +GL_PREFIX(Color3iv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 128(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 128(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 128(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 128(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3iv), .-GL_PREFIX(Color3iv) + + .p2align 4,,15 + .globl GL_PREFIX(Color3s) + .type GL_PREFIX(Color3s), @function +GL_PREFIX(Color3s): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 136(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 136(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 136(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 136(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3s), .-GL_PREFIX(Color3s) + + .p2align 4,,15 + .globl GL_PREFIX(Color3sv) + .type GL_PREFIX(Color3sv), @function +GL_PREFIX(Color3sv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 144(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 144(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 144(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 144(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3sv), .-GL_PREFIX(Color3sv) + + .p2align 4,,15 + .globl GL_PREFIX(Color3ub) + .type GL_PREFIX(Color3ub), @function +GL_PREFIX(Color3ub): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 152(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 152(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 152(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 152(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3ub), .-GL_PREFIX(Color3ub) + + .p2align 4,,15 + .globl GL_PREFIX(Color3ubv) + .type GL_PREFIX(Color3ubv), @function +GL_PREFIX(Color3ubv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 160(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 160(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 160(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 160(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3ubv), .-GL_PREFIX(Color3ubv) + + .p2align 4,,15 + .globl GL_PREFIX(Color3ui) + .type GL_PREFIX(Color3ui), @function +GL_PREFIX(Color3ui): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 168(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 168(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 168(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 168(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3ui), .-GL_PREFIX(Color3ui) + + .p2align 4,,15 + .globl GL_PREFIX(Color3uiv) + .type GL_PREFIX(Color3uiv), @function +GL_PREFIX(Color3uiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 176(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 176(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 176(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 176(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3uiv), .-GL_PREFIX(Color3uiv) + + .p2align 4,,15 + .globl GL_PREFIX(Color3us) + .type GL_PREFIX(Color3us), @function +GL_PREFIX(Color3us): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 184(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 184(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 184(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 184(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3us), .-GL_PREFIX(Color3us) + + .p2align 4,,15 + .globl GL_PREFIX(Color3usv) + .type GL_PREFIX(Color3usv), @function +GL_PREFIX(Color3usv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 192(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 192(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 192(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 192(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color3usv), .-GL_PREFIX(Color3usv) + + .p2align 4,,15 + .globl GL_PREFIX(Color4b) + .type GL_PREFIX(Color4b), @function +GL_PREFIX(Color4b): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 200(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 200(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 200(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 200(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4b), .-GL_PREFIX(Color4b) + + .p2align 4,,15 + .globl GL_PREFIX(Color4bv) + .type GL_PREFIX(Color4bv), @function +GL_PREFIX(Color4bv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 208(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 208(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 208(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 208(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4bv), .-GL_PREFIX(Color4bv) + + .p2align 4,,15 + .globl GL_PREFIX(Color4d) + .type GL_PREFIX(Color4d), @function +GL_PREFIX(Color4d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 216(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 216(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 216(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 216(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4d), .-GL_PREFIX(Color4d) + + .p2align 4,,15 + .globl GL_PREFIX(Color4dv) + .type GL_PREFIX(Color4dv), @function +GL_PREFIX(Color4dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 224(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 224(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 224(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 224(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4dv), .-GL_PREFIX(Color4dv) + + .p2align 4,,15 + .globl GL_PREFIX(Color4f) + .type GL_PREFIX(Color4f), @function +GL_PREFIX(Color4f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 232(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 232(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 232(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 232(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4f), .-GL_PREFIX(Color4f) + + .p2align 4,,15 + .globl GL_PREFIX(Color4fv) + .type GL_PREFIX(Color4fv), @function +GL_PREFIX(Color4fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 240(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 240(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 240(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 240(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4fv), .-GL_PREFIX(Color4fv) + + .p2align 4,,15 + .globl GL_PREFIX(Color4i) + .type GL_PREFIX(Color4i), @function +GL_PREFIX(Color4i): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 248(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 248(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 248(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 248(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4i), .-GL_PREFIX(Color4i) + + .p2align 4,,15 + .globl GL_PREFIX(Color4iv) + .type GL_PREFIX(Color4iv), @function +GL_PREFIX(Color4iv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 256(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 256(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 256(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 256(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4iv), .-GL_PREFIX(Color4iv) + + .p2align 4,,15 + .globl GL_PREFIX(Color4s) + .type GL_PREFIX(Color4s), @function +GL_PREFIX(Color4s): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 264(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 264(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 264(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 264(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4s), .-GL_PREFIX(Color4s) + + .p2align 4,,15 + .globl GL_PREFIX(Color4sv) + .type GL_PREFIX(Color4sv), @function +GL_PREFIX(Color4sv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 272(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 272(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 272(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 272(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4sv), .-GL_PREFIX(Color4sv) + + .p2align 4,,15 + .globl GL_PREFIX(Color4ub) + .type GL_PREFIX(Color4ub), @function +GL_PREFIX(Color4ub): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 280(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 280(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 280(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 280(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4ub), .-GL_PREFIX(Color4ub) + + .p2align 4,,15 + .globl GL_PREFIX(Color4ubv) + .type GL_PREFIX(Color4ubv), @function +GL_PREFIX(Color4ubv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 288(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 288(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 288(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 288(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4ubv), .-GL_PREFIX(Color4ubv) + + .p2align 4,,15 + .globl GL_PREFIX(Color4ui) + .type GL_PREFIX(Color4ui), @function +GL_PREFIX(Color4ui): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 296(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 296(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 296(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 296(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4ui), .-GL_PREFIX(Color4ui) + + .p2align 4,,15 + .globl GL_PREFIX(Color4uiv) + .type GL_PREFIX(Color4uiv), @function +GL_PREFIX(Color4uiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 304(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 304(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 304(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 304(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4uiv), .-GL_PREFIX(Color4uiv) + + .p2align 4,,15 + .globl GL_PREFIX(Color4us) + .type GL_PREFIX(Color4us), @function +GL_PREFIX(Color4us): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 312(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 312(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 312(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 312(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4us), .-GL_PREFIX(Color4us) + + .p2align 4,,15 + .globl GL_PREFIX(Color4usv) + .type GL_PREFIX(Color4usv), @function +GL_PREFIX(Color4usv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 320(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 320(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 320(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 320(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Color4usv), .-GL_PREFIX(Color4usv) + + .p2align 4,,15 + .globl GL_PREFIX(EdgeFlag) + .type GL_PREFIX(EdgeFlag), @function +GL_PREFIX(EdgeFlag): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 328(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 328(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 328(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 328(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EdgeFlag), .-GL_PREFIX(EdgeFlag) + + .p2align 4,,15 + .globl GL_PREFIX(EdgeFlagv) + .type GL_PREFIX(EdgeFlagv), @function +GL_PREFIX(EdgeFlagv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 336(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 336(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 336(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 336(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EdgeFlagv), .-GL_PREFIX(EdgeFlagv) + + .p2align 4,,15 + .globl GL_PREFIX(End) + .type GL_PREFIX(End), @function +GL_PREFIX(End): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 344(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 344(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 344(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 344(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(End), .-GL_PREFIX(End) + + .p2align 4,,15 + .globl GL_PREFIX(Indexd) + .type GL_PREFIX(Indexd), @function +GL_PREFIX(Indexd): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 352(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $8, %rsp + movq %xmm0, (%rsp) + call _x86_64_get_dispatch@PLT + movq (%rsp), %xmm0 + addq $8, %rsp + movq 352(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 352(%rax), %r11 + jmp *%r11 +1: + subq $8, %rsp + movq %xmm0, (%rsp) + call _glapi_get_dispatch + movq (%rsp), %xmm0 + addq $8, %rsp + movq 352(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Indexd), .-GL_PREFIX(Indexd) + + .p2align 4,,15 + .globl GL_PREFIX(Indexdv) + .type GL_PREFIX(Indexdv), @function +GL_PREFIX(Indexdv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 360(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 360(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 360(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 360(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Indexdv), .-GL_PREFIX(Indexdv) + + .p2align 4,,15 + .globl GL_PREFIX(Indexf) + .type GL_PREFIX(Indexf), @function +GL_PREFIX(Indexf): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 368(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $8, %rsp + movq %xmm0, (%rsp) + call _x86_64_get_dispatch@PLT + movq (%rsp), %xmm0 + addq $8, %rsp + movq 368(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 368(%rax), %r11 + jmp *%r11 +1: + subq $8, %rsp + movq %xmm0, (%rsp) + call _glapi_get_dispatch + movq (%rsp), %xmm0 + addq $8, %rsp + movq 368(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Indexf), .-GL_PREFIX(Indexf) + + .p2align 4,,15 + .globl GL_PREFIX(Indexfv) + .type GL_PREFIX(Indexfv), @function +GL_PREFIX(Indexfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 376(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 376(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 376(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 376(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Indexfv), .-GL_PREFIX(Indexfv) + + .p2align 4,,15 + .globl GL_PREFIX(Indexi) + .type GL_PREFIX(Indexi), @function +GL_PREFIX(Indexi): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 384(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 384(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 384(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 384(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Indexi), .-GL_PREFIX(Indexi) + + .p2align 4,,15 + .globl GL_PREFIX(Indexiv) + .type GL_PREFIX(Indexiv), @function +GL_PREFIX(Indexiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 392(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 392(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 392(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 392(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Indexiv), .-GL_PREFIX(Indexiv) + + .p2align 4,,15 + .globl GL_PREFIX(Indexs) + .type GL_PREFIX(Indexs), @function +GL_PREFIX(Indexs): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 400(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 400(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 400(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 400(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Indexs), .-GL_PREFIX(Indexs) + + .p2align 4,,15 + .globl GL_PREFIX(Indexsv) + .type GL_PREFIX(Indexsv), @function +GL_PREFIX(Indexsv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 408(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 408(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 408(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 408(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Indexsv), .-GL_PREFIX(Indexsv) + + .p2align 4,,15 + .globl GL_PREFIX(Normal3b) + .type GL_PREFIX(Normal3b), @function +GL_PREFIX(Normal3b): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 416(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 416(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 416(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 416(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Normal3b), .-GL_PREFIX(Normal3b) + + .p2align 4,,15 + .globl GL_PREFIX(Normal3bv) + .type GL_PREFIX(Normal3bv), @function +GL_PREFIX(Normal3bv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 424(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 424(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 424(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 424(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Normal3bv), .-GL_PREFIX(Normal3bv) + + .p2align 4,,15 + .globl GL_PREFIX(Normal3d) + .type GL_PREFIX(Normal3d), @function +GL_PREFIX(Normal3d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 432(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 432(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 432(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 432(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Normal3d), .-GL_PREFIX(Normal3d) + + .p2align 4,,15 + .globl GL_PREFIX(Normal3dv) + .type GL_PREFIX(Normal3dv), @function +GL_PREFIX(Normal3dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 440(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 440(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 440(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 440(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Normal3dv), .-GL_PREFIX(Normal3dv) + + .p2align 4,,15 + .globl GL_PREFIX(Normal3f) + .type GL_PREFIX(Normal3f), @function +GL_PREFIX(Normal3f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 448(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 448(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 448(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 448(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Normal3f), .-GL_PREFIX(Normal3f) + + .p2align 4,,15 + .globl GL_PREFIX(Normal3fv) + .type GL_PREFIX(Normal3fv), @function +GL_PREFIX(Normal3fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 456(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 456(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 456(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 456(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Normal3fv), .-GL_PREFIX(Normal3fv) + + .p2align 4,,15 + .globl GL_PREFIX(Normal3i) + .type GL_PREFIX(Normal3i), @function +GL_PREFIX(Normal3i): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 464(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 464(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 464(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 464(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Normal3i), .-GL_PREFIX(Normal3i) + + .p2align 4,,15 + .globl GL_PREFIX(Normal3iv) + .type GL_PREFIX(Normal3iv), @function +GL_PREFIX(Normal3iv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 472(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 472(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 472(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 472(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Normal3iv), .-GL_PREFIX(Normal3iv) + + .p2align 4,,15 + .globl GL_PREFIX(Normal3s) + .type GL_PREFIX(Normal3s), @function +GL_PREFIX(Normal3s): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 480(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 480(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 480(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 480(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Normal3s), .-GL_PREFIX(Normal3s) + + .p2align 4,,15 + .globl GL_PREFIX(Normal3sv) + .type GL_PREFIX(Normal3sv), @function +GL_PREFIX(Normal3sv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 488(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 488(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 488(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 488(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Normal3sv), .-GL_PREFIX(Normal3sv) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos2d) + .type GL_PREFIX(RasterPos2d), @function +GL_PREFIX(RasterPos2d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 496(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 496(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 496(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 496(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos2d), .-GL_PREFIX(RasterPos2d) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos2dv) + .type GL_PREFIX(RasterPos2dv), @function +GL_PREFIX(RasterPos2dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 504(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 504(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 504(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 504(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos2dv), .-GL_PREFIX(RasterPos2dv) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos2f) + .type GL_PREFIX(RasterPos2f), @function +GL_PREFIX(RasterPos2f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 512(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 512(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 512(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 512(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos2f), .-GL_PREFIX(RasterPos2f) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos2fv) + .type GL_PREFIX(RasterPos2fv), @function +GL_PREFIX(RasterPos2fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 520(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 520(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 520(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 520(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos2fv), .-GL_PREFIX(RasterPos2fv) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos2i) + .type GL_PREFIX(RasterPos2i), @function +GL_PREFIX(RasterPos2i): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 528(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 528(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 528(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 528(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos2i), .-GL_PREFIX(RasterPos2i) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos2iv) + .type GL_PREFIX(RasterPos2iv), @function +GL_PREFIX(RasterPos2iv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 536(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 536(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 536(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 536(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos2iv), .-GL_PREFIX(RasterPos2iv) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos2s) + .type GL_PREFIX(RasterPos2s), @function +GL_PREFIX(RasterPos2s): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 544(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 544(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 544(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 544(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos2s), .-GL_PREFIX(RasterPos2s) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos2sv) + .type GL_PREFIX(RasterPos2sv), @function +GL_PREFIX(RasterPos2sv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 552(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 552(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 552(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 552(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos2sv), .-GL_PREFIX(RasterPos2sv) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos3d) + .type GL_PREFIX(RasterPos3d), @function +GL_PREFIX(RasterPos3d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 560(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 560(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 560(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 560(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos3d), .-GL_PREFIX(RasterPos3d) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos3dv) + .type GL_PREFIX(RasterPos3dv), @function +GL_PREFIX(RasterPos3dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 568(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 568(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 568(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 568(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos3dv), .-GL_PREFIX(RasterPos3dv) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos3f) + .type GL_PREFIX(RasterPos3f), @function +GL_PREFIX(RasterPos3f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 576(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 576(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 576(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 576(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos3f), .-GL_PREFIX(RasterPos3f) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos3fv) + .type GL_PREFIX(RasterPos3fv), @function +GL_PREFIX(RasterPos3fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 584(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 584(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 584(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 584(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos3fv), .-GL_PREFIX(RasterPos3fv) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos3i) + .type GL_PREFIX(RasterPos3i), @function +GL_PREFIX(RasterPos3i): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 592(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 592(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 592(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 592(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos3i), .-GL_PREFIX(RasterPos3i) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos3iv) + .type GL_PREFIX(RasterPos3iv), @function +GL_PREFIX(RasterPos3iv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 600(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 600(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 600(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 600(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos3iv), .-GL_PREFIX(RasterPos3iv) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos3s) + .type GL_PREFIX(RasterPos3s), @function +GL_PREFIX(RasterPos3s): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 608(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 608(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 608(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 608(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos3s), .-GL_PREFIX(RasterPos3s) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos3sv) + .type GL_PREFIX(RasterPos3sv), @function +GL_PREFIX(RasterPos3sv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 616(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 616(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 616(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 616(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos3sv), .-GL_PREFIX(RasterPos3sv) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos4d) + .type GL_PREFIX(RasterPos4d), @function +GL_PREFIX(RasterPos4d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 624(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 624(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 624(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 624(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos4d), .-GL_PREFIX(RasterPos4d) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos4dv) + .type GL_PREFIX(RasterPos4dv), @function +GL_PREFIX(RasterPos4dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 632(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 632(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 632(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 632(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos4dv), .-GL_PREFIX(RasterPos4dv) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos4f) + .type GL_PREFIX(RasterPos4f), @function +GL_PREFIX(RasterPos4f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 640(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 640(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 640(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 640(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos4f), .-GL_PREFIX(RasterPos4f) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos4fv) + .type GL_PREFIX(RasterPos4fv), @function +GL_PREFIX(RasterPos4fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 648(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 648(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 648(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 648(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos4fv), .-GL_PREFIX(RasterPos4fv) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos4i) + .type GL_PREFIX(RasterPos4i), @function +GL_PREFIX(RasterPos4i): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 656(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 656(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 656(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 656(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos4i), .-GL_PREFIX(RasterPos4i) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos4iv) + .type GL_PREFIX(RasterPos4iv), @function +GL_PREFIX(RasterPos4iv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 664(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 664(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 664(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 664(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos4iv), .-GL_PREFIX(RasterPos4iv) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos4s) + .type GL_PREFIX(RasterPos4s), @function +GL_PREFIX(RasterPos4s): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 672(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 672(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 672(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 672(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos4s), .-GL_PREFIX(RasterPos4s) + + .p2align 4,,15 + .globl GL_PREFIX(RasterPos4sv) + .type GL_PREFIX(RasterPos4sv), @function +GL_PREFIX(RasterPos4sv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 680(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 680(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 680(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 680(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RasterPos4sv), .-GL_PREFIX(RasterPos4sv) + + .p2align 4,,15 + .globl GL_PREFIX(Rectd) + .type GL_PREFIX(Rectd), @function +GL_PREFIX(Rectd): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 688(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 688(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 688(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 688(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Rectd), .-GL_PREFIX(Rectd) + + .p2align 4,,15 + .globl GL_PREFIX(Rectdv) + .type GL_PREFIX(Rectdv), @function +GL_PREFIX(Rectdv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 696(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 696(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 696(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 696(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Rectdv), .-GL_PREFIX(Rectdv) + + .p2align 4,,15 + .globl GL_PREFIX(Rectf) + .type GL_PREFIX(Rectf), @function +GL_PREFIX(Rectf): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 704(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 704(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 704(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 704(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Rectf), .-GL_PREFIX(Rectf) + + .p2align 4,,15 + .globl GL_PREFIX(Rectfv) + .type GL_PREFIX(Rectfv), @function +GL_PREFIX(Rectfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 712(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 712(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 712(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 712(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Rectfv), .-GL_PREFIX(Rectfv) + + .p2align 4,,15 + .globl GL_PREFIX(Recti) + .type GL_PREFIX(Recti), @function +GL_PREFIX(Recti): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 720(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 720(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 720(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 720(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Recti), .-GL_PREFIX(Recti) + + .p2align 4,,15 + .globl GL_PREFIX(Rectiv) + .type GL_PREFIX(Rectiv), @function +GL_PREFIX(Rectiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 728(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 728(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 728(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 728(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Rectiv), .-GL_PREFIX(Rectiv) + + .p2align 4,,15 + .globl GL_PREFIX(Rects) + .type GL_PREFIX(Rects), @function +GL_PREFIX(Rects): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 736(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 736(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 736(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 736(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Rects), .-GL_PREFIX(Rects) + + .p2align 4,,15 + .globl GL_PREFIX(Rectsv) + .type GL_PREFIX(Rectsv), @function +GL_PREFIX(Rectsv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 744(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 744(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 744(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 744(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Rectsv), .-GL_PREFIX(Rectsv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord1d) + .type GL_PREFIX(TexCoord1d), @function +GL_PREFIX(TexCoord1d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 752(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $8, %rsp + movq %xmm0, (%rsp) + call _x86_64_get_dispatch@PLT + movq (%rsp), %xmm0 + addq $8, %rsp + movq 752(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 752(%rax), %r11 + jmp *%r11 +1: + subq $8, %rsp + movq %xmm0, (%rsp) + call _glapi_get_dispatch + movq (%rsp), %xmm0 + addq $8, %rsp + movq 752(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord1d), .-GL_PREFIX(TexCoord1d) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord1dv) + .type GL_PREFIX(TexCoord1dv), @function +GL_PREFIX(TexCoord1dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 760(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 760(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 760(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 760(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord1dv), .-GL_PREFIX(TexCoord1dv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord1f) + .type GL_PREFIX(TexCoord1f), @function +GL_PREFIX(TexCoord1f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 768(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $8, %rsp + movq %xmm0, (%rsp) + call _x86_64_get_dispatch@PLT + movq (%rsp), %xmm0 + addq $8, %rsp + movq 768(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 768(%rax), %r11 + jmp *%r11 +1: + subq $8, %rsp + movq %xmm0, (%rsp) + call _glapi_get_dispatch + movq (%rsp), %xmm0 + addq $8, %rsp + movq 768(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord1f), .-GL_PREFIX(TexCoord1f) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord1fv) + .type GL_PREFIX(TexCoord1fv), @function +GL_PREFIX(TexCoord1fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 776(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 776(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 776(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 776(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord1fv), .-GL_PREFIX(TexCoord1fv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord1i) + .type GL_PREFIX(TexCoord1i), @function +GL_PREFIX(TexCoord1i): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 784(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 784(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 784(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 784(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord1i), .-GL_PREFIX(TexCoord1i) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord1iv) + .type GL_PREFIX(TexCoord1iv), @function +GL_PREFIX(TexCoord1iv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 792(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 792(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 792(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 792(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord1iv), .-GL_PREFIX(TexCoord1iv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord1s) + .type GL_PREFIX(TexCoord1s), @function +GL_PREFIX(TexCoord1s): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 800(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 800(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 800(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 800(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord1s), .-GL_PREFIX(TexCoord1s) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord1sv) + .type GL_PREFIX(TexCoord1sv), @function +GL_PREFIX(TexCoord1sv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 808(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 808(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 808(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 808(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord1sv), .-GL_PREFIX(TexCoord1sv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord2d) + .type GL_PREFIX(TexCoord2d), @function +GL_PREFIX(TexCoord2d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 816(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 816(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 816(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 816(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord2d), .-GL_PREFIX(TexCoord2d) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord2dv) + .type GL_PREFIX(TexCoord2dv), @function +GL_PREFIX(TexCoord2dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 824(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 824(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 824(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 824(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord2dv), .-GL_PREFIX(TexCoord2dv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord2f) + .type GL_PREFIX(TexCoord2f), @function +GL_PREFIX(TexCoord2f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 832(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 832(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 832(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 832(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord2f), .-GL_PREFIX(TexCoord2f) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord2fv) + .type GL_PREFIX(TexCoord2fv), @function +GL_PREFIX(TexCoord2fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 840(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 840(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 840(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 840(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord2fv), .-GL_PREFIX(TexCoord2fv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord2i) + .type GL_PREFIX(TexCoord2i), @function +GL_PREFIX(TexCoord2i): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 848(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 848(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 848(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 848(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord2i), .-GL_PREFIX(TexCoord2i) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord2iv) + .type GL_PREFIX(TexCoord2iv), @function +GL_PREFIX(TexCoord2iv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 856(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 856(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 856(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 856(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord2iv), .-GL_PREFIX(TexCoord2iv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord2s) + .type GL_PREFIX(TexCoord2s), @function +GL_PREFIX(TexCoord2s): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 864(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 864(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 864(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 864(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord2s), .-GL_PREFIX(TexCoord2s) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord2sv) + .type GL_PREFIX(TexCoord2sv), @function +GL_PREFIX(TexCoord2sv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 872(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 872(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 872(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 872(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord2sv), .-GL_PREFIX(TexCoord2sv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord3d) + .type GL_PREFIX(TexCoord3d), @function +GL_PREFIX(TexCoord3d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 880(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 880(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 880(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 880(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord3d), .-GL_PREFIX(TexCoord3d) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord3dv) + .type GL_PREFIX(TexCoord3dv), @function +GL_PREFIX(TexCoord3dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 888(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 888(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 888(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 888(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord3dv), .-GL_PREFIX(TexCoord3dv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord3f) + .type GL_PREFIX(TexCoord3f), @function +GL_PREFIX(TexCoord3f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 896(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 896(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 896(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 896(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord3f), .-GL_PREFIX(TexCoord3f) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord3fv) + .type GL_PREFIX(TexCoord3fv), @function +GL_PREFIX(TexCoord3fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 904(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 904(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 904(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 904(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord3fv), .-GL_PREFIX(TexCoord3fv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord3i) + .type GL_PREFIX(TexCoord3i), @function +GL_PREFIX(TexCoord3i): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 912(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 912(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 912(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 912(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord3i), .-GL_PREFIX(TexCoord3i) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord3iv) + .type GL_PREFIX(TexCoord3iv), @function +GL_PREFIX(TexCoord3iv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 920(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 920(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 920(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 920(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord3iv), .-GL_PREFIX(TexCoord3iv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord3s) + .type GL_PREFIX(TexCoord3s), @function +GL_PREFIX(TexCoord3s): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 928(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 928(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 928(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 928(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord3s), .-GL_PREFIX(TexCoord3s) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord3sv) + .type GL_PREFIX(TexCoord3sv), @function +GL_PREFIX(TexCoord3sv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 936(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 936(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 936(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 936(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord3sv), .-GL_PREFIX(TexCoord3sv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord4d) + .type GL_PREFIX(TexCoord4d), @function +GL_PREFIX(TexCoord4d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 944(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 944(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 944(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 944(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord4d), .-GL_PREFIX(TexCoord4d) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord4dv) + .type GL_PREFIX(TexCoord4dv), @function +GL_PREFIX(TexCoord4dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 952(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 952(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 952(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 952(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord4dv), .-GL_PREFIX(TexCoord4dv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord4f) + .type GL_PREFIX(TexCoord4f), @function +GL_PREFIX(TexCoord4f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 960(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 960(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 960(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 960(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord4f), .-GL_PREFIX(TexCoord4f) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord4fv) + .type GL_PREFIX(TexCoord4fv), @function +GL_PREFIX(TexCoord4fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 968(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 968(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 968(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 968(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord4fv), .-GL_PREFIX(TexCoord4fv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord4i) + .type GL_PREFIX(TexCoord4i), @function +GL_PREFIX(TexCoord4i): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 976(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 976(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 976(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 976(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord4i), .-GL_PREFIX(TexCoord4i) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord4iv) + .type GL_PREFIX(TexCoord4iv), @function +GL_PREFIX(TexCoord4iv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 984(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 984(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 984(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 984(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord4iv), .-GL_PREFIX(TexCoord4iv) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord4s) + .type GL_PREFIX(TexCoord4s), @function +GL_PREFIX(TexCoord4s): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 992(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 992(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 992(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 992(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord4s), .-GL_PREFIX(TexCoord4s) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoord4sv) + .type GL_PREFIX(TexCoord4sv), @function +GL_PREFIX(TexCoord4sv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1000(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1000(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1000(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1000(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoord4sv), .-GL_PREFIX(TexCoord4sv) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex2d) + .type GL_PREFIX(Vertex2d), @function +GL_PREFIX(Vertex2d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1008(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 1008(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1008(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 1008(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex2d), .-GL_PREFIX(Vertex2d) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex2dv) + .type GL_PREFIX(Vertex2dv), @function +GL_PREFIX(Vertex2dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1016(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1016(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1016(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1016(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex2dv), .-GL_PREFIX(Vertex2dv) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex2f) + .type GL_PREFIX(Vertex2f), @function +GL_PREFIX(Vertex2f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1024(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 1024(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1024(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 1024(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex2f), .-GL_PREFIX(Vertex2f) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex2fv) + .type GL_PREFIX(Vertex2fv), @function +GL_PREFIX(Vertex2fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1032(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1032(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1032(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1032(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex2fv), .-GL_PREFIX(Vertex2fv) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex2i) + .type GL_PREFIX(Vertex2i), @function +GL_PREFIX(Vertex2i): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1040(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1040(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1040(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1040(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex2i), .-GL_PREFIX(Vertex2i) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex2iv) + .type GL_PREFIX(Vertex2iv), @function +GL_PREFIX(Vertex2iv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1048(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1048(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1048(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1048(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex2iv), .-GL_PREFIX(Vertex2iv) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex2s) + .type GL_PREFIX(Vertex2s), @function +GL_PREFIX(Vertex2s): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1056(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1056(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1056(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1056(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex2s), .-GL_PREFIX(Vertex2s) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex2sv) + .type GL_PREFIX(Vertex2sv), @function +GL_PREFIX(Vertex2sv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1064(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1064(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1064(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1064(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex2sv), .-GL_PREFIX(Vertex2sv) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex3d) + .type GL_PREFIX(Vertex3d), @function +GL_PREFIX(Vertex3d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1072(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 1072(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1072(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 1072(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex3d), .-GL_PREFIX(Vertex3d) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex3dv) + .type GL_PREFIX(Vertex3dv), @function +GL_PREFIX(Vertex3dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1080(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1080(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1080(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1080(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex3dv), .-GL_PREFIX(Vertex3dv) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex3f) + .type GL_PREFIX(Vertex3f), @function +GL_PREFIX(Vertex3f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1088(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 1088(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1088(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 1088(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex3f), .-GL_PREFIX(Vertex3f) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex3fv) + .type GL_PREFIX(Vertex3fv), @function +GL_PREFIX(Vertex3fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1096(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1096(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1096(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1096(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex3fv), .-GL_PREFIX(Vertex3fv) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex3i) + .type GL_PREFIX(Vertex3i), @function +GL_PREFIX(Vertex3i): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1104(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1104(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1104(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1104(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex3i), .-GL_PREFIX(Vertex3i) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex3iv) + .type GL_PREFIX(Vertex3iv), @function +GL_PREFIX(Vertex3iv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1112(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1112(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1112(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1112(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex3iv), .-GL_PREFIX(Vertex3iv) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex3s) + .type GL_PREFIX(Vertex3s), @function +GL_PREFIX(Vertex3s): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1120(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1120(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1120(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1120(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex3s), .-GL_PREFIX(Vertex3s) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex3sv) + .type GL_PREFIX(Vertex3sv), @function +GL_PREFIX(Vertex3sv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1128(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1128(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1128(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1128(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex3sv), .-GL_PREFIX(Vertex3sv) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex4d) + .type GL_PREFIX(Vertex4d), @function +GL_PREFIX(Vertex4d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1136(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 1136(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1136(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 1136(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex4d), .-GL_PREFIX(Vertex4d) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex4dv) + .type GL_PREFIX(Vertex4dv), @function +GL_PREFIX(Vertex4dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1144(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1144(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1144(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1144(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex4dv), .-GL_PREFIX(Vertex4dv) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex4f) + .type GL_PREFIX(Vertex4f), @function +GL_PREFIX(Vertex4f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1152(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 1152(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1152(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 1152(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex4f), .-GL_PREFIX(Vertex4f) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex4fv) + .type GL_PREFIX(Vertex4fv), @function +GL_PREFIX(Vertex4fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1160(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1160(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1160(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1160(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex4fv), .-GL_PREFIX(Vertex4fv) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex4i) + .type GL_PREFIX(Vertex4i), @function +GL_PREFIX(Vertex4i): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1168(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1168(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1168(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1168(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex4i), .-GL_PREFIX(Vertex4i) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex4iv) + .type GL_PREFIX(Vertex4iv), @function +GL_PREFIX(Vertex4iv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1176(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1176(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1176(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1176(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex4iv), .-GL_PREFIX(Vertex4iv) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex4s) + .type GL_PREFIX(Vertex4s), @function +GL_PREFIX(Vertex4s): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1184(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1184(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1184(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1184(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex4s), .-GL_PREFIX(Vertex4s) + + .p2align 4,,15 + .globl GL_PREFIX(Vertex4sv) + .type GL_PREFIX(Vertex4sv), @function +GL_PREFIX(Vertex4sv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1192(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1192(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1192(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1192(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Vertex4sv), .-GL_PREFIX(Vertex4sv) + + .p2align 4,,15 + .globl GL_PREFIX(ClipPlane) + .type GL_PREFIX(ClipPlane), @function +GL_PREFIX(ClipPlane): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1200(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1200(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1200(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1200(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClipPlane), .-GL_PREFIX(ClipPlane) + + .p2align 4,,15 + .globl GL_PREFIX(ColorMaterial) + .type GL_PREFIX(ColorMaterial), @function +GL_PREFIX(ColorMaterial): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1208(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1208(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1208(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1208(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ColorMaterial), .-GL_PREFIX(ColorMaterial) + + .p2align 4,,15 + .globl GL_PREFIX(CullFace) + .type GL_PREFIX(CullFace), @function +GL_PREFIX(CullFace): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1216(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1216(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1216(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1216(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CullFace), .-GL_PREFIX(CullFace) + + .p2align 4,,15 + .globl GL_PREFIX(Fogf) + .type GL_PREFIX(Fogf), @function +GL_PREFIX(Fogf): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1224(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 1224(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1224(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 1224(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Fogf), .-GL_PREFIX(Fogf) + + .p2align 4,,15 + .globl GL_PREFIX(Fogfv) + .type GL_PREFIX(Fogfv), @function +GL_PREFIX(Fogfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1232(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1232(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1232(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1232(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Fogfv), .-GL_PREFIX(Fogfv) + + .p2align 4,,15 + .globl GL_PREFIX(Fogi) + .type GL_PREFIX(Fogi), @function +GL_PREFIX(Fogi): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1240(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1240(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1240(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1240(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Fogi), .-GL_PREFIX(Fogi) + + .p2align 4,,15 + .globl GL_PREFIX(Fogiv) + .type GL_PREFIX(Fogiv), @function +GL_PREFIX(Fogiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1248(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1248(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1248(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1248(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Fogiv), .-GL_PREFIX(Fogiv) + + .p2align 4,,15 + .globl GL_PREFIX(FrontFace) + .type GL_PREFIX(FrontFace), @function +GL_PREFIX(FrontFace): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1256(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1256(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1256(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1256(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FrontFace), .-GL_PREFIX(FrontFace) + + .p2align 4,,15 + .globl GL_PREFIX(Hint) + .type GL_PREFIX(Hint), @function +GL_PREFIX(Hint): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1264(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1264(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1264(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1264(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Hint), .-GL_PREFIX(Hint) + + .p2align 4,,15 + .globl GL_PREFIX(Lightf) + .type GL_PREFIX(Lightf), @function +GL_PREFIX(Lightf): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1272(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $24, %rsp + movq 1272(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1272(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $24, %rsp + movq 1272(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Lightf), .-GL_PREFIX(Lightf) + + .p2align 4,,15 + .globl GL_PREFIX(Lightfv) + .type GL_PREFIX(Lightfv), @function +GL_PREFIX(Lightfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1280(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1280(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1280(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1280(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Lightfv), .-GL_PREFIX(Lightfv) + + .p2align 4,,15 + .globl GL_PREFIX(Lighti) + .type GL_PREFIX(Lighti), @function +GL_PREFIX(Lighti): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1288(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1288(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1288(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1288(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Lighti), .-GL_PREFIX(Lighti) + + .p2align 4,,15 + .globl GL_PREFIX(Lightiv) + .type GL_PREFIX(Lightiv), @function +GL_PREFIX(Lightiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1296(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1296(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1296(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1296(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Lightiv), .-GL_PREFIX(Lightiv) + + .p2align 4,,15 + .globl GL_PREFIX(LightModelf) + .type GL_PREFIX(LightModelf), @function +GL_PREFIX(LightModelf): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1304(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 1304(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1304(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 1304(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LightModelf), .-GL_PREFIX(LightModelf) + + .p2align 4,,15 + .globl GL_PREFIX(LightModelfv) + .type GL_PREFIX(LightModelfv), @function +GL_PREFIX(LightModelfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1312(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1312(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1312(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1312(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LightModelfv), .-GL_PREFIX(LightModelfv) + + .p2align 4,,15 + .globl GL_PREFIX(LightModeli) + .type GL_PREFIX(LightModeli), @function +GL_PREFIX(LightModeli): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1320(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1320(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1320(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1320(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LightModeli), .-GL_PREFIX(LightModeli) + + .p2align 4,,15 + .globl GL_PREFIX(LightModeliv) + .type GL_PREFIX(LightModeliv), @function +GL_PREFIX(LightModeliv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1328(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1328(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1328(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1328(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LightModeliv), .-GL_PREFIX(LightModeliv) + + .p2align 4,,15 + .globl GL_PREFIX(LineStipple) + .type GL_PREFIX(LineStipple), @function +GL_PREFIX(LineStipple): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1336(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1336(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1336(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1336(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LineStipple), .-GL_PREFIX(LineStipple) + + .p2align 4,,15 + .globl GL_PREFIX(LineWidth) + .type GL_PREFIX(LineWidth), @function +GL_PREFIX(LineWidth): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1344(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $8, %rsp + movq %xmm0, (%rsp) + call _x86_64_get_dispatch@PLT + movq (%rsp), %xmm0 + addq $8, %rsp + movq 1344(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1344(%rax), %r11 + jmp *%r11 +1: + subq $8, %rsp + movq %xmm0, (%rsp) + call _glapi_get_dispatch + movq (%rsp), %xmm0 + addq $8, %rsp + movq 1344(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LineWidth), .-GL_PREFIX(LineWidth) + + .p2align 4,,15 + .globl GL_PREFIX(Materialf) + .type GL_PREFIX(Materialf), @function +GL_PREFIX(Materialf): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1352(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $24, %rsp + movq 1352(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1352(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $24, %rsp + movq 1352(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Materialf), .-GL_PREFIX(Materialf) + + .p2align 4,,15 + .globl GL_PREFIX(Materialfv) + .type GL_PREFIX(Materialfv), @function +GL_PREFIX(Materialfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1360(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1360(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1360(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1360(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Materialfv), .-GL_PREFIX(Materialfv) + + .p2align 4,,15 + .globl GL_PREFIX(Materiali) + .type GL_PREFIX(Materiali), @function +GL_PREFIX(Materiali): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1368(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1368(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1368(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1368(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Materiali), .-GL_PREFIX(Materiali) + + .p2align 4,,15 + .globl GL_PREFIX(Materialiv) + .type GL_PREFIX(Materialiv), @function +GL_PREFIX(Materialiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1376(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1376(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1376(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1376(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Materialiv), .-GL_PREFIX(Materialiv) + + .p2align 4,,15 + .globl GL_PREFIX(PointSize) + .type GL_PREFIX(PointSize), @function +GL_PREFIX(PointSize): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1384(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $8, %rsp + movq %xmm0, (%rsp) + call _x86_64_get_dispatch@PLT + movq (%rsp), %xmm0 + addq $8, %rsp + movq 1384(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1384(%rax), %r11 + jmp *%r11 +1: + subq $8, %rsp + movq %xmm0, (%rsp) + call _glapi_get_dispatch + movq (%rsp), %xmm0 + addq $8, %rsp + movq 1384(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PointSize), .-GL_PREFIX(PointSize) + + .p2align 4,,15 + .globl GL_PREFIX(PolygonMode) + .type GL_PREFIX(PolygonMode), @function +GL_PREFIX(PolygonMode): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1392(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1392(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1392(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1392(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PolygonMode), .-GL_PREFIX(PolygonMode) + + .p2align 4,,15 + .globl GL_PREFIX(PolygonStipple) + .type GL_PREFIX(PolygonStipple), @function +GL_PREFIX(PolygonStipple): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1400(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1400(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1400(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1400(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PolygonStipple), .-GL_PREFIX(PolygonStipple) + + .p2align 4,,15 + .globl GL_PREFIX(Scissor) + .type GL_PREFIX(Scissor), @function +GL_PREFIX(Scissor): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1408(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1408(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1408(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1408(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Scissor), .-GL_PREFIX(Scissor) + + .p2align 4,,15 + .globl GL_PREFIX(ShadeModel) + .type GL_PREFIX(ShadeModel), @function +GL_PREFIX(ShadeModel): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1416(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1416(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1416(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1416(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ShadeModel), .-GL_PREFIX(ShadeModel) + + .p2align 4,,15 + .globl GL_PREFIX(TexParameterf) + .type GL_PREFIX(TexParameterf), @function +GL_PREFIX(TexParameterf): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1424(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $24, %rsp + movq 1424(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1424(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $24, %rsp + movq 1424(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexParameterf), .-GL_PREFIX(TexParameterf) + + .p2align 4,,15 + .globl GL_PREFIX(TexParameterfv) + .type GL_PREFIX(TexParameterfv), @function +GL_PREFIX(TexParameterfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1432(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1432(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1432(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1432(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexParameterfv), .-GL_PREFIX(TexParameterfv) + + .p2align 4,,15 + .globl GL_PREFIX(TexParameteri) + .type GL_PREFIX(TexParameteri), @function +GL_PREFIX(TexParameteri): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1440(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1440(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1440(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1440(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexParameteri), .-GL_PREFIX(TexParameteri) + + .p2align 4,,15 + .globl GL_PREFIX(TexParameteriv) + .type GL_PREFIX(TexParameteriv), @function +GL_PREFIX(TexParameteriv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1448(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1448(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1448(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1448(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexParameteriv), .-GL_PREFIX(TexParameteriv) + + .p2align 4,,15 + .globl GL_PREFIX(TexImage1D) + .type GL_PREFIX(TexImage1D), @function +GL_PREFIX(TexImage1D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1456(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1456(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1456(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1456(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexImage1D), .-GL_PREFIX(TexImage1D) + + .p2align 4,,15 + .globl GL_PREFIX(TexImage2D) + .type GL_PREFIX(TexImage2D), @function +GL_PREFIX(TexImage2D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1464(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1464(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1464(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1464(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexImage2D), .-GL_PREFIX(TexImage2D) + + .p2align 4,,15 + .globl GL_PREFIX(TexEnvf) + .type GL_PREFIX(TexEnvf), @function +GL_PREFIX(TexEnvf): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1472(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $24, %rsp + movq 1472(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1472(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $24, %rsp + movq 1472(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexEnvf), .-GL_PREFIX(TexEnvf) + + .p2align 4,,15 + .globl GL_PREFIX(TexEnvfv) + .type GL_PREFIX(TexEnvfv), @function +GL_PREFIX(TexEnvfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1480(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1480(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1480(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1480(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexEnvfv), .-GL_PREFIX(TexEnvfv) + + .p2align 4,,15 + .globl GL_PREFIX(TexEnvi) + .type GL_PREFIX(TexEnvi), @function +GL_PREFIX(TexEnvi): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1488(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1488(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1488(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1488(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexEnvi), .-GL_PREFIX(TexEnvi) + + .p2align 4,,15 + .globl GL_PREFIX(TexEnviv) + .type GL_PREFIX(TexEnviv), @function +GL_PREFIX(TexEnviv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1496(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1496(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1496(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1496(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexEnviv), .-GL_PREFIX(TexEnviv) + + .p2align 4,,15 + .globl GL_PREFIX(TexGend) + .type GL_PREFIX(TexGend), @function +GL_PREFIX(TexGend): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1504(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $24, %rsp + movq 1504(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1504(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $24, %rsp + movq 1504(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexGend), .-GL_PREFIX(TexGend) + + .p2align 4,,15 + .globl GL_PREFIX(TexGendv) + .type GL_PREFIX(TexGendv), @function +GL_PREFIX(TexGendv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1512(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1512(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1512(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1512(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexGendv), .-GL_PREFIX(TexGendv) + + .p2align 4,,15 + .globl GL_PREFIX(TexGenf) + .type GL_PREFIX(TexGenf), @function +GL_PREFIX(TexGenf): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1520(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $24, %rsp + movq 1520(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1520(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $24, %rsp + movq 1520(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexGenf), .-GL_PREFIX(TexGenf) + + .p2align 4,,15 + .globl GL_PREFIX(TexGenfv) + .type GL_PREFIX(TexGenfv), @function +GL_PREFIX(TexGenfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1528(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1528(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1528(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1528(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexGenfv), .-GL_PREFIX(TexGenfv) + + .p2align 4,,15 + .globl GL_PREFIX(TexGeni) + .type GL_PREFIX(TexGeni), @function +GL_PREFIX(TexGeni): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1536(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1536(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1536(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1536(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexGeni), .-GL_PREFIX(TexGeni) + + .p2align 4,,15 + .globl GL_PREFIX(TexGeniv) + .type GL_PREFIX(TexGeniv), @function +GL_PREFIX(TexGeniv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1544(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1544(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1544(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1544(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexGeniv), .-GL_PREFIX(TexGeniv) + + .p2align 4,,15 + .globl GL_PREFIX(FeedbackBuffer) + .type GL_PREFIX(FeedbackBuffer), @function +GL_PREFIX(FeedbackBuffer): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1552(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1552(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1552(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1552(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FeedbackBuffer), .-GL_PREFIX(FeedbackBuffer) + + .p2align 4,,15 + .globl GL_PREFIX(SelectBuffer) + .type GL_PREFIX(SelectBuffer), @function +GL_PREFIX(SelectBuffer): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1560(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1560(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1560(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1560(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SelectBuffer), .-GL_PREFIX(SelectBuffer) + + .p2align 4,,15 + .globl GL_PREFIX(RenderMode) + .type GL_PREFIX(RenderMode), @function +GL_PREFIX(RenderMode): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1568(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1568(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1568(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1568(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RenderMode), .-GL_PREFIX(RenderMode) + + .p2align 4,,15 + .globl GL_PREFIX(InitNames) + .type GL_PREFIX(InitNames), @function +GL_PREFIX(InitNames): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1576(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 1576(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1576(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 1576(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(InitNames), .-GL_PREFIX(InitNames) + + .p2align 4,,15 + .globl GL_PREFIX(LoadName) + .type GL_PREFIX(LoadName), @function +GL_PREFIX(LoadName): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1584(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1584(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1584(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1584(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LoadName), .-GL_PREFIX(LoadName) + + .p2align 4,,15 + .globl GL_PREFIX(PassThrough) + .type GL_PREFIX(PassThrough), @function +GL_PREFIX(PassThrough): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1592(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $8, %rsp + movq %xmm0, (%rsp) + call _x86_64_get_dispatch@PLT + movq (%rsp), %xmm0 + addq $8, %rsp + movq 1592(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1592(%rax), %r11 + jmp *%r11 +1: + subq $8, %rsp + movq %xmm0, (%rsp) + call _glapi_get_dispatch + movq (%rsp), %xmm0 + addq $8, %rsp + movq 1592(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PassThrough), .-GL_PREFIX(PassThrough) + + .p2align 4,,15 + .globl GL_PREFIX(PopName) + .type GL_PREFIX(PopName), @function +GL_PREFIX(PopName): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1600(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 1600(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1600(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 1600(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PopName), .-GL_PREFIX(PopName) + + .p2align 4,,15 + .globl GL_PREFIX(PushName) + .type GL_PREFIX(PushName), @function +GL_PREFIX(PushName): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1608(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1608(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1608(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1608(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PushName), .-GL_PREFIX(PushName) + + .p2align 4,,15 + .globl GL_PREFIX(DrawBuffer) + .type GL_PREFIX(DrawBuffer), @function +GL_PREFIX(DrawBuffer): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1616(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1616(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1616(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1616(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DrawBuffer), .-GL_PREFIX(DrawBuffer) + + .p2align 4,,15 + .globl GL_PREFIX(Clear) + .type GL_PREFIX(Clear), @function +GL_PREFIX(Clear): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1624(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1624(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1624(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1624(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Clear), .-GL_PREFIX(Clear) + + .p2align 4,,15 + .globl GL_PREFIX(ClearAccum) + .type GL_PREFIX(ClearAccum), @function +GL_PREFIX(ClearAccum): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1632(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 1632(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1632(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 1632(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClearAccum), .-GL_PREFIX(ClearAccum) + + .p2align 4,,15 + .globl GL_PREFIX(ClearIndex) + .type GL_PREFIX(ClearIndex), @function +GL_PREFIX(ClearIndex): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1640(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $8, %rsp + movq %xmm0, (%rsp) + call _x86_64_get_dispatch@PLT + movq (%rsp), %xmm0 + addq $8, %rsp + movq 1640(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1640(%rax), %r11 + jmp *%r11 +1: + subq $8, %rsp + movq %xmm0, (%rsp) + call _glapi_get_dispatch + movq (%rsp), %xmm0 + addq $8, %rsp + movq 1640(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClearIndex), .-GL_PREFIX(ClearIndex) + + .p2align 4,,15 + .globl GL_PREFIX(ClearColor) + .type GL_PREFIX(ClearColor), @function +GL_PREFIX(ClearColor): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1648(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1648(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1648(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1648(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClearColor), .-GL_PREFIX(ClearColor) + + .p2align 4,,15 + .globl GL_PREFIX(ClearStencil) + .type GL_PREFIX(ClearStencil), @function +GL_PREFIX(ClearStencil): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1656(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1656(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1656(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1656(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClearStencil), .-GL_PREFIX(ClearStencil) + + .p2align 4,,15 + .globl GL_PREFIX(ClearDepth) + .type GL_PREFIX(ClearDepth), @function +GL_PREFIX(ClearDepth): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1664(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1664(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1664(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1664(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClearDepth), .-GL_PREFIX(ClearDepth) + + .p2align 4,,15 + .globl GL_PREFIX(StencilMask) + .type GL_PREFIX(StencilMask), @function +GL_PREFIX(StencilMask): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1672(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1672(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1672(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1672(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(StencilMask), .-GL_PREFIX(StencilMask) + + .p2align 4,,15 + .globl GL_PREFIX(ColorMask) + .type GL_PREFIX(ColorMask), @function +GL_PREFIX(ColorMask): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1680(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1680(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1680(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1680(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ColorMask), .-GL_PREFIX(ColorMask) + + .p2align 4,,15 + .globl GL_PREFIX(DepthMask) + .type GL_PREFIX(DepthMask), @function +GL_PREFIX(DepthMask): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1688(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1688(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1688(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1688(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DepthMask), .-GL_PREFIX(DepthMask) + + .p2align 4,,15 + .globl GL_PREFIX(IndexMask) + .type GL_PREFIX(IndexMask), @function +GL_PREFIX(IndexMask): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1696(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1696(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1696(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1696(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IndexMask), .-GL_PREFIX(IndexMask) + + .p2align 4,,15 + .globl GL_PREFIX(Accum) + .type GL_PREFIX(Accum), @function +GL_PREFIX(Accum): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1704(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 1704(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1704(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 1704(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Accum), .-GL_PREFIX(Accum) + + .p2align 4,,15 + .globl GL_PREFIX(Disable) + .type GL_PREFIX(Disable), @function +GL_PREFIX(Disable): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1712(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1712(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1712(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1712(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Disable), .-GL_PREFIX(Disable) + + .p2align 4,,15 + .globl GL_PREFIX(Enable) + .type GL_PREFIX(Enable), @function +GL_PREFIX(Enable): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1720(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1720(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1720(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1720(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Enable), .-GL_PREFIX(Enable) + + .p2align 4,,15 + .globl GL_PREFIX(Finish) + .type GL_PREFIX(Finish), @function +GL_PREFIX(Finish): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1728(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 1728(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1728(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 1728(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Finish), .-GL_PREFIX(Finish) + + .p2align 4,,15 + .globl GL_PREFIX(Flush) + .type GL_PREFIX(Flush), @function +GL_PREFIX(Flush): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1736(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 1736(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1736(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 1736(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Flush), .-GL_PREFIX(Flush) + + .p2align 4,,15 + .globl GL_PREFIX(PopAttrib) + .type GL_PREFIX(PopAttrib), @function +GL_PREFIX(PopAttrib): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1744(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 1744(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1744(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 1744(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PopAttrib), .-GL_PREFIX(PopAttrib) + + .p2align 4,,15 + .globl GL_PREFIX(PushAttrib) + .type GL_PREFIX(PushAttrib), @function +GL_PREFIX(PushAttrib): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1752(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1752(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1752(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1752(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PushAttrib), .-GL_PREFIX(PushAttrib) + + .p2align 4,,15 + .globl GL_PREFIX(Map1d) + .type GL_PREFIX(Map1d), @function +GL_PREFIX(Map1d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1760(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $56, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %rsi, 24(%rsp) + movq %rdx, 32(%rsp) + movq %rcx, 40(%rsp) + call _x86_64_get_dispatch@PLT + movq 40(%rsp), %rcx + movq 32(%rsp), %rdx + movq 24(%rsp), %rsi + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $56, %rsp + movq 1760(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1760(%rax), %r11 + jmp *%r11 +1: + subq $56, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %rsi, 24(%rsp) + movq %rdx, 32(%rsp) + movq %rcx, 40(%rsp) + call _glapi_get_dispatch + movq 40(%rsp), %rcx + movq 32(%rsp), %rdx + movq 24(%rsp), %rsi + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $56, %rsp + movq 1760(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Map1d), .-GL_PREFIX(Map1d) + + .p2align 4,,15 + .globl GL_PREFIX(Map1f) + .type GL_PREFIX(Map1f), @function +GL_PREFIX(Map1f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1768(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $56, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %rsi, 24(%rsp) + movq %rdx, 32(%rsp) + movq %rcx, 40(%rsp) + call _x86_64_get_dispatch@PLT + movq 40(%rsp), %rcx + movq 32(%rsp), %rdx + movq 24(%rsp), %rsi + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $56, %rsp + movq 1768(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1768(%rax), %r11 + jmp *%r11 +1: + subq $56, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %rsi, 24(%rsp) + movq %rdx, 32(%rsp) + movq %rcx, 40(%rsp) + call _glapi_get_dispatch + movq 40(%rsp), %rcx + movq 32(%rsp), %rdx + movq 24(%rsp), %rsi + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $56, %rsp + movq 1768(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Map1f), .-GL_PREFIX(Map1f) + + .p2align 4,,15 + .globl GL_PREFIX(Map2d) + .type GL_PREFIX(Map2d), @function +GL_PREFIX(Map2d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1776(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $88, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %rsi, 24(%rsp) + movq %rdx, 32(%rsp) + movq %xmm2, 40(%rsp) + movq %xmm3, 48(%rsp) + movq %rcx, 56(%rsp) + movq %r8, 64(%rsp) + movq %r9, 72(%rsp) + call _x86_64_get_dispatch@PLT + movq 72(%rsp), %r9 + movq 64(%rsp), %r8 + movq 56(%rsp), %rcx + movq 48(%rsp), %xmm3 + movq 40(%rsp), %xmm2 + movq 32(%rsp), %rdx + movq 24(%rsp), %rsi + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $88, %rsp + movq 1776(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1776(%rax), %r11 + jmp *%r11 +1: + subq $88, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %rsi, 24(%rsp) + movq %rdx, 32(%rsp) + movq %xmm2, 40(%rsp) + movq %xmm3, 48(%rsp) + movq %rcx, 56(%rsp) + movq %r8, 64(%rsp) + movq %r9, 72(%rsp) + call _glapi_get_dispatch + movq 72(%rsp), %r9 + movq 64(%rsp), %r8 + movq 56(%rsp), %rcx + movq 48(%rsp), %xmm3 + movq 40(%rsp), %xmm2 + movq 32(%rsp), %rdx + movq 24(%rsp), %rsi + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $88, %rsp + movq 1776(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Map2d), .-GL_PREFIX(Map2d) + + .p2align 4,,15 + .globl GL_PREFIX(Map2f) + .type GL_PREFIX(Map2f), @function +GL_PREFIX(Map2f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1784(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $88, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %rsi, 24(%rsp) + movq %rdx, 32(%rsp) + movq %xmm2, 40(%rsp) + movq %xmm3, 48(%rsp) + movq %rcx, 56(%rsp) + movq %r8, 64(%rsp) + movq %r9, 72(%rsp) + call _x86_64_get_dispatch@PLT + movq 72(%rsp), %r9 + movq 64(%rsp), %r8 + movq 56(%rsp), %rcx + movq 48(%rsp), %xmm3 + movq 40(%rsp), %xmm2 + movq 32(%rsp), %rdx + movq 24(%rsp), %rsi + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $88, %rsp + movq 1784(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1784(%rax), %r11 + jmp *%r11 +1: + subq $88, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %rsi, 24(%rsp) + movq %rdx, 32(%rsp) + movq %xmm2, 40(%rsp) + movq %xmm3, 48(%rsp) + movq %rcx, 56(%rsp) + movq %r8, 64(%rsp) + movq %r9, 72(%rsp) + call _glapi_get_dispatch + movq 72(%rsp), %r9 + movq 64(%rsp), %r8 + movq 56(%rsp), %rcx + movq 48(%rsp), %xmm3 + movq 40(%rsp), %xmm2 + movq 32(%rsp), %rdx + movq 24(%rsp), %rsi + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $88, %rsp + movq 1784(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Map2f), .-GL_PREFIX(Map2f) + + .p2align 4,,15 + .globl GL_PREFIX(MapGrid1d) + .type GL_PREFIX(MapGrid1d), @function +GL_PREFIX(MapGrid1d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1792(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 1792(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1792(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 1792(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MapGrid1d), .-GL_PREFIX(MapGrid1d) + + .p2align 4,,15 + .globl GL_PREFIX(MapGrid1f) + .type GL_PREFIX(MapGrid1f), @function +GL_PREFIX(MapGrid1f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1800(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 1800(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1800(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 1800(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MapGrid1f), .-GL_PREFIX(MapGrid1f) + + .p2align 4,,15 + .globl GL_PREFIX(MapGrid2d) + .type GL_PREFIX(MapGrid2d), @function +GL_PREFIX(MapGrid2d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1808(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $56, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %rsi, 24(%rsp) + movq %xmm2, 32(%rsp) + movq %xmm3, 40(%rsp) + call _x86_64_get_dispatch@PLT + movq 40(%rsp), %xmm3 + movq 32(%rsp), %xmm2 + movq 24(%rsp), %rsi + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $56, %rsp + movq 1808(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1808(%rax), %r11 + jmp *%r11 +1: + subq $56, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %rsi, 24(%rsp) + movq %xmm2, 32(%rsp) + movq %xmm3, 40(%rsp) + call _glapi_get_dispatch + movq 40(%rsp), %xmm3 + movq 32(%rsp), %xmm2 + movq 24(%rsp), %rsi + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $56, %rsp + movq 1808(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MapGrid2d), .-GL_PREFIX(MapGrid2d) + + .p2align 4,,15 + .globl GL_PREFIX(MapGrid2f) + .type GL_PREFIX(MapGrid2f), @function +GL_PREFIX(MapGrid2f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1816(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $56, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %rsi, 24(%rsp) + movq %xmm2, 32(%rsp) + movq %xmm3, 40(%rsp) + call _x86_64_get_dispatch@PLT + movq 40(%rsp), %xmm3 + movq 32(%rsp), %xmm2 + movq 24(%rsp), %rsi + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $56, %rsp + movq 1816(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1816(%rax), %r11 + jmp *%r11 +1: + subq $56, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %rsi, 24(%rsp) + movq %xmm2, 32(%rsp) + movq %xmm3, 40(%rsp) + call _glapi_get_dispatch + movq 40(%rsp), %xmm3 + movq 32(%rsp), %xmm2 + movq 24(%rsp), %rsi + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $56, %rsp + movq 1816(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MapGrid2f), .-GL_PREFIX(MapGrid2f) + + .p2align 4,,15 + .globl GL_PREFIX(EvalCoord1d) + .type GL_PREFIX(EvalCoord1d), @function +GL_PREFIX(EvalCoord1d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1824(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $8, %rsp + movq %xmm0, (%rsp) + call _x86_64_get_dispatch@PLT + movq (%rsp), %xmm0 + addq $8, %rsp + movq 1824(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1824(%rax), %r11 + jmp *%r11 +1: + subq $8, %rsp + movq %xmm0, (%rsp) + call _glapi_get_dispatch + movq (%rsp), %xmm0 + addq $8, %rsp + movq 1824(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EvalCoord1d), .-GL_PREFIX(EvalCoord1d) + + .p2align 4,,15 + .globl GL_PREFIX(EvalCoord1dv) + .type GL_PREFIX(EvalCoord1dv), @function +GL_PREFIX(EvalCoord1dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1832(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1832(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1832(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1832(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EvalCoord1dv), .-GL_PREFIX(EvalCoord1dv) + + .p2align 4,,15 + .globl GL_PREFIX(EvalCoord1f) + .type GL_PREFIX(EvalCoord1f), @function +GL_PREFIX(EvalCoord1f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1840(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $8, %rsp + movq %xmm0, (%rsp) + call _x86_64_get_dispatch@PLT + movq (%rsp), %xmm0 + addq $8, %rsp + movq 1840(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1840(%rax), %r11 + jmp *%r11 +1: + subq $8, %rsp + movq %xmm0, (%rsp) + call _glapi_get_dispatch + movq (%rsp), %xmm0 + addq $8, %rsp + movq 1840(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EvalCoord1f), .-GL_PREFIX(EvalCoord1f) + + .p2align 4,,15 + .globl GL_PREFIX(EvalCoord1fv) + .type GL_PREFIX(EvalCoord1fv), @function +GL_PREFIX(EvalCoord1fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1848(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1848(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1848(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1848(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EvalCoord1fv), .-GL_PREFIX(EvalCoord1fv) + + .p2align 4,,15 + .globl GL_PREFIX(EvalCoord2d) + .type GL_PREFIX(EvalCoord2d), @function +GL_PREFIX(EvalCoord2d): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1856(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 1856(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1856(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 1856(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EvalCoord2d), .-GL_PREFIX(EvalCoord2d) + + .p2align 4,,15 + .globl GL_PREFIX(EvalCoord2dv) + .type GL_PREFIX(EvalCoord2dv), @function +GL_PREFIX(EvalCoord2dv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1864(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1864(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1864(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1864(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EvalCoord2dv), .-GL_PREFIX(EvalCoord2dv) + + .p2align 4,,15 + .globl GL_PREFIX(EvalCoord2f) + .type GL_PREFIX(EvalCoord2f), @function +GL_PREFIX(EvalCoord2f): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1872(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 1872(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1872(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 1872(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EvalCoord2f), .-GL_PREFIX(EvalCoord2f) + + .p2align 4,,15 + .globl GL_PREFIX(EvalCoord2fv) + .type GL_PREFIX(EvalCoord2fv), @function +GL_PREFIX(EvalCoord2fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1880(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1880(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1880(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1880(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EvalCoord2fv), .-GL_PREFIX(EvalCoord2fv) + + .p2align 4,,15 + .globl GL_PREFIX(EvalMesh1) + .type GL_PREFIX(EvalMesh1), @function +GL_PREFIX(EvalMesh1): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1888(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1888(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1888(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1888(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EvalMesh1), .-GL_PREFIX(EvalMesh1) + + .p2align 4,,15 + .globl GL_PREFIX(EvalPoint1) + .type GL_PREFIX(EvalPoint1), @function +GL_PREFIX(EvalPoint1): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1896(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1896(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1896(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1896(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EvalPoint1), .-GL_PREFIX(EvalPoint1) + + .p2align 4,,15 + .globl GL_PREFIX(EvalMesh2) + .type GL_PREFIX(EvalMesh2), @function +GL_PREFIX(EvalMesh2): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1904(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1904(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1904(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 1904(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EvalMesh2), .-GL_PREFIX(EvalMesh2) + + .p2align 4,,15 + .globl GL_PREFIX(EvalPoint2) + .type GL_PREFIX(EvalPoint2), @function +GL_PREFIX(EvalPoint2): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1912(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1912(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1912(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1912(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EvalPoint2), .-GL_PREFIX(EvalPoint2) + + .p2align 4,,15 + .globl GL_PREFIX(AlphaFunc) + .type GL_PREFIX(AlphaFunc), @function +GL_PREFIX(AlphaFunc): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1920(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1920(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1920(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1920(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(AlphaFunc), .-GL_PREFIX(AlphaFunc) + + .p2align 4,,15 + .globl GL_PREFIX(BlendFunc) + .type GL_PREFIX(BlendFunc), @function +GL_PREFIX(BlendFunc): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1928(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1928(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1928(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1928(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BlendFunc), .-GL_PREFIX(BlendFunc) + + .p2align 4,,15 + .globl GL_PREFIX(LogicOp) + .type GL_PREFIX(LogicOp), @function +GL_PREFIX(LogicOp): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1936(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1936(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1936(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1936(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LogicOp), .-GL_PREFIX(LogicOp) + + .p2align 4,,15 + .globl GL_PREFIX(StencilFunc) + .type GL_PREFIX(StencilFunc), @function +GL_PREFIX(StencilFunc): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1944(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1944(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1944(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1944(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(StencilFunc), .-GL_PREFIX(StencilFunc) + + .p2align 4,,15 + .globl GL_PREFIX(StencilOp) + .type GL_PREFIX(StencilOp), @function +GL_PREFIX(StencilOp): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1952(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 1952(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1952(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 1952(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(StencilOp), .-GL_PREFIX(StencilOp) + + .p2align 4,,15 + .globl GL_PREFIX(DepthFunc) + .type GL_PREFIX(DepthFunc), @function +GL_PREFIX(DepthFunc): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1960(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 1960(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1960(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 1960(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DepthFunc), .-GL_PREFIX(DepthFunc) + + .p2align 4,,15 + .globl GL_PREFIX(PixelZoom) + .type GL_PREFIX(PixelZoom), @function +GL_PREFIX(PixelZoom): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1968(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 1968(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1968(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 1968(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PixelZoom), .-GL_PREFIX(PixelZoom) + + .p2align 4,,15 + .globl GL_PREFIX(PixelTransferf) + .type GL_PREFIX(PixelTransferf), @function +GL_PREFIX(PixelTransferf): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1976(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 1976(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1976(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 1976(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PixelTransferf), .-GL_PREFIX(PixelTransferf) + + .p2align 4,,15 + .globl GL_PREFIX(PixelTransferi) + .type GL_PREFIX(PixelTransferi), @function +GL_PREFIX(PixelTransferi): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1984(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 1984(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1984(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 1984(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PixelTransferi), .-GL_PREFIX(PixelTransferi) + + .p2align 4,,15 + .globl GL_PREFIX(PixelStoref) + .type GL_PREFIX(PixelStoref), @function +GL_PREFIX(PixelStoref): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 1992(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 1992(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 1992(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 1992(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PixelStoref), .-GL_PREFIX(PixelStoref) + + .p2align 4,,15 + .globl GL_PREFIX(PixelStorei) + .type GL_PREFIX(PixelStorei), @function +GL_PREFIX(PixelStorei): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2000(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2000(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2000(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2000(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PixelStorei), .-GL_PREFIX(PixelStorei) + + .p2align 4,,15 + .globl GL_PREFIX(PixelMapfv) + .type GL_PREFIX(PixelMapfv), @function +GL_PREFIX(PixelMapfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2008(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2008(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2008(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2008(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PixelMapfv), .-GL_PREFIX(PixelMapfv) + + .p2align 4,,15 + .globl GL_PREFIX(PixelMapuiv) + .type GL_PREFIX(PixelMapuiv), @function +GL_PREFIX(PixelMapuiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2016(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2016(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2016(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2016(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PixelMapuiv), .-GL_PREFIX(PixelMapuiv) + + .p2align 4,,15 + .globl GL_PREFIX(PixelMapusv) + .type GL_PREFIX(PixelMapusv), @function +GL_PREFIX(PixelMapusv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2024(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2024(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2024(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2024(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PixelMapusv), .-GL_PREFIX(PixelMapusv) + + .p2align 4,,15 + .globl GL_PREFIX(ReadBuffer) + .type GL_PREFIX(ReadBuffer), @function +GL_PREFIX(ReadBuffer): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2032(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2032(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2032(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2032(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ReadBuffer), .-GL_PREFIX(ReadBuffer) + + .p2align 4,,15 + .globl GL_PREFIX(CopyPixels) + .type GL_PREFIX(CopyPixels), @function +GL_PREFIX(CopyPixels): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2040(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2040(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2040(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2040(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CopyPixels), .-GL_PREFIX(CopyPixels) + + .p2align 4,,15 + .globl GL_PREFIX(ReadPixels) + .type GL_PREFIX(ReadPixels), @function +GL_PREFIX(ReadPixels): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2048(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2048(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2048(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2048(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ReadPixels), .-GL_PREFIX(ReadPixels) + + .p2align 4,,15 + .globl GL_PREFIX(DrawPixels) + .type GL_PREFIX(DrawPixels), @function +GL_PREFIX(DrawPixels): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2056(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2056(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2056(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2056(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DrawPixels), .-GL_PREFIX(DrawPixels) + + .p2align 4,,15 + .globl GL_PREFIX(GetBooleanv) + .type GL_PREFIX(GetBooleanv), @function +GL_PREFIX(GetBooleanv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2064(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2064(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2064(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2064(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetBooleanv), .-GL_PREFIX(GetBooleanv) + + .p2align 4,,15 + .globl GL_PREFIX(GetClipPlane) + .type GL_PREFIX(GetClipPlane), @function +GL_PREFIX(GetClipPlane): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2072(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2072(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2072(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2072(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetClipPlane), .-GL_PREFIX(GetClipPlane) + + .p2align 4,,15 + .globl GL_PREFIX(GetDoublev) + .type GL_PREFIX(GetDoublev), @function +GL_PREFIX(GetDoublev): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2080(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2080(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2080(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2080(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetDoublev), .-GL_PREFIX(GetDoublev) + + .p2align 4,,15 + .globl GL_PREFIX(GetError) + .type GL_PREFIX(GetError), @function +GL_PREFIX(GetError): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2088(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 2088(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2088(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 2088(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetError), .-GL_PREFIX(GetError) + + .p2align 4,,15 + .globl GL_PREFIX(GetFloatv) + .type GL_PREFIX(GetFloatv), @function +GL_PREFIX(GetFloatv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2096(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2096(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2096(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2096(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetFloatv), .-GL_PREFIX(GetFloatv) + + .p2align 4,,15 + .globl GL_PREFIX(GetIntegerv) + .type GL_PREFIX(GetIntegerv), @function +GL_PREFIX(GetIntegerv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2104(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2104(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2104(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2104(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetIntegerv), .-GL_PREFIX(GetIntegerv) + + .p2align 4,,15 + .globl GL_PREFIX(GetLightfv) + .type GL_PREFIX(GetLightfv), @function +GL_PREFIX(GetLightfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2112(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2112(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2112(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2112(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetLightfv), .-GL_PREFIX(GetLightfv) + + .p2align 4,,15 + .globl GL_PREFIX(GetLightiv) + .type GL_PREFIX(GetLightiv), @function +GL_PREFIX(GetLightiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2120(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2120(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2120(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2120(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetLightiv), .-GL_PREFIX(GetLightiv) + + .p2align 4,,15 + .globl GL_PREFIX(GetMapdv) + .type GL_PREFIX(GetMapdv), @function +GL_PREFIX(GetMapdv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2128(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2128(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2128(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2128(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetMapdv), .-GL_PREFIX(GetMapdv) + + .p2align 4,,15 + .globl GL_PREFIX(GetMapfv) + .type GL_PREFIX(GetMapfv), @function +GL_PREFIX(GetMapfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2136(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2136(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2136(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2136(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetMapfv), .-GL_PREFIX(GetMapfv) + + .p2align 4,,15 + .globl GL_PREFIX(GetMapiv) + .type GL_PREFIX(GetMapiv), @function +GL_PREFIX(GetMapiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2144(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2144(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2144(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2144(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetMapiv), .-GL_PREFIX(GetMapiv) + + .p2align 4,,15 + .globl GL_PREFIX(GetMaterialfv) + .type GL_PREFIX(GetMaterialfv), @function +GL_PREFIX(GetMaterialfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2152(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2152(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2152(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2152(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetMaterialfv), .-GL_PREFIX(GetMaterialfv) + + .p2align 4,,15 + .globl GL_PREFIX(GetMaterialiv) + .type GL_PREFIX(GetMaterialiv), @function +GL_PREFIX(GetMaterialiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2160(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2160(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2160(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2160(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetMaterialiv), .-GL_PREFIX(GetMaterialiv) + + .p2align 4,,15 + .globl GL_PREFIX(GetPixelMapfv) + .type GL_PREFIX(GetPixelMapfv), @function +GL_PREFIX(GetPixelMapfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2168(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2168(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2168(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2168(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetPixelMapfv), .-GL_PREFIX(GetPixelMapfv) + + .p2align 4,,15 + .globl GL_PREFIX(GetPixelMapuiv) + .type GL_PREFIX(GetPixelMapuiv), @function +GL_PREFIX(GetPixelMapuiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2176(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2176(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2176(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2176(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetPixelMapuiv), .-GL_PREFIX(GetPixelMapuiv) + + .p2align 4,,15 + .globl GL_PREFIX(GetPixelMapusv) + .type GL_PREFIX(GetPixelMapusv), @function +GL_PREFIX(GetPixelMapusv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2184(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2184(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2184(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2184(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetPixelMapusv), .-GL_PREFIX(GetPixelMapusv) + + .p2align 4,,15 + .globl GL_PREFIX(GetPolygonStipple) + .type GL_PREFIX(GetPolygonStipple), @function +GL_PREFIX(GetPolygonStipple): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2192(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2192(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2192(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2192(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetPolygonStipple), .-GL_PREFIX(GetPolygonStipple) + + .p2align 4,,15 + .globl GL_PREFIX(GetString) + .type GL_PREFIX(GetString), @function +GL_PREFIX(GetString): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2200(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2200(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2200(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2200(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetString), .-GL_PREFIX(GetString) + + .p2align 4,,15 + .globl GL_PREFIX(GetTexEnvfv) + .type GL_PREFIX(GetTexEnvfv), @function +GL_PREFIX(GetTexEnvfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2208(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2208(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2208(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2208(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTexEnvfv), .-GL_PREFIX(GetTexEnvfv) + + .p2align 4,,15 + .globl GL_PREFIX(GetTexEnviv) + .type GL_PREFIX(GetTexEnviv), @function +GL_PREFIX(GetTexEnviv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2216(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2216(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2216(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2216(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTexEnviv), .-GL_PREFIX(GetTexEnviv) + + .p2align 4,,15 + .globl GL_PREFIX(GetTexGendv) + .type GL_PREFIX(GetTexGendv), @function +GL_PREFIX(GetTexGendv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2224(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2224(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2224(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2224(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTexGendv), .-GL_PREFIX(GetTexGendv) + + .p2align 4,,15 + .globl GL_PREFIX(GetTexGenfv) + .type GL_PREFIX(GetTexGenfv), @function +GL_PREFIX(GetTexGenfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2232(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2232(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2232(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2232(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTexGenfv), .-GL_PREFIX(GetTexGenfv) + + .p2align 4,,15 + .globl GL_PREFIX(GetTexGeniv) + .type GL_PREFIX(GetTexGeniv), @function +GL_PREFIX(GetTexGeniv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2240(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2240(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2240(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2240(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTexGeniv), .-GL_PREFIX(GetTexGeniv) + + .p2align 4,,15 + .globl GL_PREFIX(GetTexImage) + .type GL_PREFIX(GetTexImage), @function +GL_PREFIX(GetTexImage): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2248(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2248(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2248(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2248(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTexImage), .-GL_PREFIX(GetTexImage) + + .p2align 4,,15 + .globl GL_PREFIX(GetTexParameterfv) + .type GL_PREFIX(GetTexParameterfv), @function +GL_PREFIX(GetTexParameterfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2256(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2256(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2256(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2256(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTexParameterfv), .-GL_PREFIX(GetTexParameterfv) + + .p2align 4,,15 + .globl GL_PREFIX(GetTexParameteriv) + .type GL_PREFIX(GetTexParameteriv), @function +GL_PREFIX(GetTexParameteriv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2264(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2264(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2264(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2264(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTexParameteriv), .-GL_PREFIX(GetTexParameteriv) + + .p2align 4,,15 + .globl GL_PREFIX(GetTexLevelParameterfv) + .type GL_PREFIX(GetTexLevelParameterfv), @function +GL_PREFIX(GetTexLevelParameterfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2272(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2272(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2272(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2272(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTexLevelParameterfv), .-GL_PREFIX(GetTexLevelParameterfv) + + .p2align 4,,15 + .globl GL_PREFIX(GetTexLevelParameteriv) + .type GL_PREFIX(GetTexLevelParameteriv), @function +GL_PREFIX(GetTexLevelParameteriv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2280(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2280(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2280(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2280(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTexLevelParameteriv), .-GL_PREFIX(GetTexLevelParameteriv) + + .p2align 4,,15 + .globl GL_PREFIX(IsEnabled) + .type GL_PREFIX(IsEnabled), @function +GL_PREFIX(IsEnabled): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2288(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2288(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2288(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2288(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IsEnabled), .-GL_PREFIX(IsEnabled) + + .p2align 4,,15 + .globl GL_PREFIX(IsList) + .type GL_PREFIX(IsList), @function +GL_PREFIX(IsList): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2296(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2296(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2296(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2296(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IsList), .-GL_PREFIX(IsList) + + .p2align 4,,15 + .globl GL_PREFIX(DepthRange) + .type GL_PREFIX(DepthRange), @function +GL_PREFIX(DepthRange): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2304(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2304(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2304(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2304(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DepthRange), .-GL_PREFIX(DepthRange) + + .p2align 4,,15 + .globl GL_PREFIX(Frustum) + .type GL_PREFIX(Frustum), @function +GL_PREFIX(Frustum): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2312(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $56, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + movq %xmm4, 32(%rsp) + movq %xmm5, 40(%rsp) + call _x86_64_get_dispatch@PLT + movq 40(%rsp), %xmm5 + movq 32(%rsp), %xmm4 + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $56, %rsp + movq 2312(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2312(%rax), %r11 + jmp *%r11 +1: + subq $56, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + movq %xmm4, 32(%rsp) + movq %xmm5, 40(%rsp) + call _glapi_get_dispatch + movq 40(%rsp), %xmm5 + movq 32(%rsp), %xmm4 + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $56, %rsp + movq 2312(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Frustum), .-GL_PREFIX(Frustum) + + .p2align 4,,15 + .globl GL_PREFIX(LoadIdentity) + .type GL_PREFIX(LoadIdentity), @function +GL_PREFIX(LoadIdentity): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2320(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 2320(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2320(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 2320(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LoadIdentity), .-GL_PREFIX(LoadIdentity) + + .p2align 4,,15 + .globl GL_PREFIX(LoadMatrixf) + .type GL_PREFIX(LoadMatrixf), @function +GL_PREFIX(LoadMatrixf): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2328(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2328(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2328(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2328(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LoadMatrixf), .-GL_PREFIX(LoadMatrixf) + + .p2align 4,,15 + .globl GL_PREFIX(LoadMatrixd) + .type GL_PREFIX(LoadMatrixd), @function +GL_PREFIX(LoadMatrixd): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2336(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2336(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2336(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2336(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LoadMatrixd), .-GL_PREFIX(LoadMatrixd) + + .p2align 4,,15 + .globl GL_PREFIX(MatrixMode) + .type GL_PREFIX(MatrixMode), @function +GL_PREFIX(MatrixMode): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2344(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2344(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2344(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2344(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MatrixMode), .-GL_PREFIX(MatrixMode) + + .p2align 4,,15 + .globl GL_PREFIX(MultMatrixf) + .type GL_PREFIX(MultMatrixf), @function +GL_PREFIX(MultMatrixf): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2352(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2352(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2352(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2352(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultMatrixf), .-GL_PREFIX(MultMatrixf) + + .p2align 4,,15 + .globl GL_PREFIX(MultMatrixd) + .type GL_PREFIX(MultMatrixd), @function +GL_PREFIX(MultMatrixd): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2360(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2360(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2360(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2360(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultMatrixd), .-GL_PREFIX(MultMatrixd) + + .p2align 4,,15 + .globl GL_PREFIX(Ortho) + .type GL_PREFIX(Ortho), @function +GL_PREFIX(Ortho): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2368(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $56, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + movq %xmm4, 32(%rsp) + movq %xmm5, 40(%rsp) + call _x86_64_get_dispatch@PLT + movq 40(%rsp), %xmm5 + movq 32(%rsp), %xmm4 + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $56, %rsp + movq 2368(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2368(%rax), %r11 + jmp *%r11 +1: + subq $56, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + movq %xmm4, 32(%rsp) + movq %xmm5, 40(%rsp) + call _glapi_get_dispatch + movq 40(%rsp), %xmm5 + movq 32(%rsp), %xmm4 + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $56, %rsp + movq 2368(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Ortho), .-GL_PREFIX(Ortho) + + .p2align 4,,15 + .globl GL_PREFIX(PopMatrix) + .type GL_PREFIX(PopMatrix), @function +GL_PREFIX(PopMatrix): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2376(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 2376(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2376(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 2376(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PopMatrix), .-GL_PREFIX(PopMatrix) + + .p2align 4,,15 + .globl GL_PREFIX(PushMatrix) + .type GL_PREFIX(PushMatrix), @function +GL_PREFIX(PushMatrix): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2384(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 2384(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2384(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 2384(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PushMatrix), .-GL_PREFIX(PushMatrix) + + .p2align 4,,15 + .globl GL_PREFIX(Rotated) + .type GL_PREFIX(Rotated), @function +GL_PREFIX(Rotated): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2392(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 2392(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2392(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 2392(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Rotated), .-GL_PREFIX(Rotated) + + .p2align 4,,15 + .globl GL_PREFIX(Rotatef) + .type GL_PREFIX(Rotatef), @function +GL_PREFIX(Rotatef): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2400(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 2400(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2400(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 2400(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Rotatef), .-GL_PREFIX(Rotatef) + + .p2align 4,,15 + .globl GL_PREFIX(Scaled) + .type GL_PREFIX(Scaled), @function +GL_PREFIX(Scaled): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2408(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 2408(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2408(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 2408(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Scaled), .-GL_PREFIX(Scaled) + + .p2align 4,,15 + .globl GL_PREFIX(Scalef) + .type GL_PREFIX(Scalef), @function +GL_PREFIX(Scalef): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2416(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 2416(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2416(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 2416(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Scalef), .-GL_PREFIX(Scalef) + + .p2align 4,,15 + .globl GL_PREFIX(Translated) + .type GL_PREFIX(Translated), @function +GL_PREFIX(Translated): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2424(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 2424(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2424(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 2424(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Translated), .-GL_PREFIX(Translated) + + .p2align 4,,15 + .globl GL_PREFIX(Translatef) + .type GL_PREFIX(Translatef), @function +GL_PREFIX(Translatef): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2432(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 2432(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2432(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 2432(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Translatef), .-GL_PREFIX(Translatef) + + .p2align 4,,15 + .globl GL_PREFIX(Viewport) + .type GL_PREFIX(Viewport), @function +GL_PREFIX(Viewport): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2440(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2440(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2440(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2440(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Viewport), .-GL_PREFIX(Viewport) + + .p2align 4,,15 + .globl GL_PREFIX(ArrayElement) + .type GL_PREFIX(ArrayElement), @function +GL_PREFIX(ArrayElement): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2448(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2448(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2448(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2448(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ArrayElement), .-GL_PREFIX(ArrayElement) + + .p2align 4,,15 + .globl GL_PREFIX(BindTexture) + .type GL_PREFIX(BindTexture), @function +GL_PREFIX(BindTexture): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2456(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2456(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2456(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2456(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BindTexture), .-GL_PREFIX(BindTexture) + + .p2align 4,,15 + .globl GL_PREFIX(ColorPointer) + .type GL_PREFIX(ColorPointer), @function +GL_PREFIX(ColorPointer): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2464(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2464(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2464(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2464(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ColorPointer), .-GL_PREFIX(ColorPointer) + + .p2align 4,,15 + .globl GL_PREFIX(DisableClientState) + .type GL_PREFIX(DisableClientState), @function +GL_PREFIX(DisableClientState): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2472(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2472(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2472(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2472(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DisableClientState), .-GL_PREFIX(DisableClientState) + + .p2align 4,,15 + .globl GL_PREFIX(DrawArrays) + .type GL_PREFIX(DrawArrays), @function +GL_PREFIX(DrawArrays): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2480(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2480(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2480(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2480(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DrawArrays), .-GL_PREFIX(DrawArrays) + + .p2align 4,,15 + .globl GL_PREFIX(DrawElements) + .type GL_PREFIX(DrawElements), @function +GL_PREFIX(DrawElements): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2488(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2488(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2488(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2488(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DrawElements), .-GL_PREFIX(DrawElements) + + .p2align 4,,15 + .globl GL_PREFIX(EdgeFlagPointer) + .type GL_PREFIX(EdgeFlagPointer), @function +GL_PREFIX(EdgeFlagPointer): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2496(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2496(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2496(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2496(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EdgeFlagPointer), .-GL_PREFIX(EdgeFlagPointer) + + .p2align 4,,15 + .globl GL_PREFIX(EnableClientState) + .type GL_PREFIX(EnableClientState), @function +GL_PREFIX(EnableClientState): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2504(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2504(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2504(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2504(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EnableClientState), .-GL_PREFIX(EnableClientState) + + .p2align 4,,15 + .globl GL_PREFIX(IndexPointer) + .type GL_PREFIX(IndexPointer), @function +GL_PREFIX(IndexPointer): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2512(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2512(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2512(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2512(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IndexPointer), .-GL_PREFIX(IndexPointer) + + .p2align 4,,15 + .globl GL_PREFIX(Indexub) + .type GL_PREFIX(Indexub), @function +GL_PREFIX(Indexub): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2520(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2520(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2520(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2520(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Indexub), .-GL_PREFIX(Indexub) + + .p2align 4,,15 + .globl GL_PREFIX(Indexubv) + .type GL_PREFIX(Indexubv), @function +GL_PREFIX(Indexubv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2528(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2528(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2528(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2528(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Indexubv), .-GL_PREFIX(Indexubv) + + .p2align 4,,15 + .globl GL_PREFIX(InterleavedArrays) + .type GL_PREFIX(InterleavedArrays), @function +GL_PREFIX(InterleavedArrays): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2536(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2536(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2536(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2536(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(InterleavedArrays), .-GL_PREFIX(InterleavedArrays) + + .p2align 4,,15 + .globl GL_PREFIX(NormalPointer) + .type GL_PREFIX(NormalPointer), @function +GL_PREFIX(NormalPointer): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2544(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2544(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2544(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2544(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(NormalPointer), .-GL_PREFIX(NormalPointer) + + .p2align 4,,15 + .globl GL_PREFIX(PolygonOffset) + .type GL_PREFIX(PolygonOffset), @function +GL_PREFIX(PolygonOffset): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2552(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 2552(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2552(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 2552(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PolygonOffset), .-GL_PREFIX(PolygonOffset) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoordPointer) + .type GL_PREFIX(TexCoordPointer), @function +GL_PREFIX(TexCoordPointer): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2560(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2560(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2560(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2560(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoordPointer), .-GL_PREFIX(TexCoordPointer) + + .p2align 4,,15 + .globl GL_PREFIX(VertexPointer) + .type GL_PREFIX(VertexPointer), @function +GL_PREFIX(VertexPointer): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2568(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2568(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2568(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2568(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexPointer), .-GL_PREFIX(VertexPointer) + + .p2align 4,,15 + .globl GL_PREFIX(AreTexturesResident) + .type GL_PREFIX(AreTexturesResident), @function +GL_PREFIX(AreTexturesResident): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2576(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2576(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2576(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2576(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(AreTexturesResident), .-GL_PREFIX(AreTexturesResident) + + .p2align 4,,15 + .globl GL_PREFIX(CopyTexImage1D) + .type GL_PREFIX(CopyTexImage1D), @function +GL_PREFIX(CopyTexImage1D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2584(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2584(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2584(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2584(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CopyTexImage1D), .-GL_PREFIX(CopyTexImage1D) + + .p2align 4,,15 + .globl GL_PREFIX(CopyTexImage2D) + .type GL_PREFIX(CopyTexImage2D), @function +GL_PREFIX(CopyTexImage2D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2592(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2592(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2592(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2592(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CopyTexImage2D), .-GL_PREFIX(CopyTexImage2D) + + .p2align 4,,15 + .globl GL_PREFIX(CopyTexSubImage1D) + .type GL_PREFIX(CopyTexSubImage1D), @function +GL_PREFIX(CopyTexSubImage1D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2600(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2600(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2600(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2600(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CopyTexSubImage1D), .-GL_PREFIX(CopyTexSubImage1D) + + .p2align 4,,15 + .globl GL_PREFIX(CopyTexSubImage2D) + .type GL_PREFIX(CopyTexSubImage2D), @function +GL_PREFIX(CopyTexSubImage2D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2608(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2608(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2608(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2608(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CopyTexSubImage2D), .-GL_PREFIX(CopyTexSubImage2D) + + .p2align 4,,15 + .globl GL_PREFIX(DeleteTextures) + .type GL_PREFIX(DeleteTextures), @function +GL_PREFIX(DeleteTextures): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2616(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2616(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2616(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2616(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DeleteTextures), .-GL_PREFIX(DeleteTextures) + + .p2align 4,,15 + .globl GL_PREFIX(GenTextures) + .type GL_PREFIX(GenTextures), @function +GL_PREFIX(GenTextures): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2624(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2624(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2624(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2624(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GenTextures), .-GL_PREFIX(GenTextures) + + .p2align 4,,15 + .globl GL_PREFIX(GetPointerv) + .type GL_PREFIX(GetPointerv), @function +GL_PREFIX(GetPointerv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2632(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 2632(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2632(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 2632(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetPointerv), .-GL_PREFIX(GetPointerv) + + .p2align 4,,15 + .globl GL_PREFIX(IsTexture) + .type GL_PREFIX(IsTexture), @function +GL_PREFIX(IsTexture): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2640(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2640(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2640(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2640(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IsTexture), .-GL_PREFIX(IsTexture) + + .p2align 4,,15 + .globl GL_PREFIX(PrioritizeTextures) + .type GL_PREFIX(PrioritizeTextures), @function +GL_PREFIX(PrioritizeTextures): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2648(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2648(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2648(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2648(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PrioritizeTextures), .-GL_PREFIX(PrioritizeTextures) + + .p2align 4,,15 + .globl GL_PREFIX(TexSubImage1D) + .type GL_PREFIX(TexSubImage1D), @function +GL_PREFIX(TexSubImage1D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2656(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2656(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2656(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2656(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexSubImage1D), .-GL_PREFIX(TexSubImage1D) + + .p2align 4,,15 + .globl GL_PREFIX(TexSubImage2D) + .type GL_PREFIX(TexSubImage2D), @function +GL_PREFIX(TexSubImage2D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2664(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2664(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2664(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2664(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexSubImage2D), .-GL_PREFIX(TexSubImage2D) + + .p2align 4,,15 + .globl GL_PREFIX(PopClientAttrib) + .type GL_PREFIX(PopClientAttrib), @function +GL_PREFIX(PopClientAttrib): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2672(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 2672(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2672(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 2672(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PopClientAttrib), .-GL_PREFIX(PopClientAttrib) + + .p2align 4,,15 + .globl GL_PREFIX(PushClientAttrib) + .type GL_PREFIX(PushClientAttrib), @function +GL_PREFIX(PushClientAttrib): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2680(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2680(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2680(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2680(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PushClientAttrib), .-GL_PREFIX(PushClientAttrib) + + .p2align 4,,15 + .globl GL_PREFIX(BlendColor) + .type GL_PREFIX(BlendColor), @function +GL_PREFIX(BlendColor): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2688(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2688(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2688(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2688(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BlendColor), .-GL_PREFIX(BlendColor) + + .p2align 4,,15 + .globl GL_PREFIX(BlendEquation) + .type GL_PREFIX(BlendEquation), @function +GL_PREFIX(BlendEquation): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2696(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2696(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2696(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2696(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BlendEquation), .-GL_PREFIX(BlendEquation) + + .p2align 4,,15 + .globl GL_PREFIX(DrawRangeElements) + .type GL_PREFIX(DrawRangeElements), @function +GL_PREFIX(DrawRangeElements): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2704(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2704(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2704(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2704(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DrawRangeElements), .-GL_PREFIX(DrawRangeElements) + + .p2align 4,,15 + .globl GL_PREFIX(ColorTable) + .type GL_PREFIX(ColorTable), @function +GL_PREFIX(ColorTable): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2712(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2712(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2712(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2712(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ColorTable), .-GL_PREFIX(ColorTable) + + .p2align 4,,15 + .globl GL_PREFIX(ColorTableParameterfv) + .type GL_PREFIX(ColorTableParameterfv), @function +GL_PREFIX(ColorTableParameterfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2720(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2720(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2720(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2720(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ColorTableParameterfv), .-GL_PREFIX(ColorTableParameterfv) + + .p2align 4,,15 + .globl GL_PREFIX(ColorTableParameteriv) + .type GL_PREFIX(ColorTableParameteriv), @function +GL_PREFIX(ColorTableParameteriv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2728(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2728(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2728(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2728(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ColorTableParameteriv), .-GL_PREFIX(ColorTableParameteriv) + + .p2align 4,,15 + .globl GL_PREFIX(CopyColorTable) + .type GL_PREFIX(CopyColorTable), @function +GL_PREFIX(CopyColorTable): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2736(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2736(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2736(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2736(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CopyColorTable), .-GL_PREFIX(CopyColorTable) + + .p2align 4,,15 + .globl GL_PREFIX(GetColorTable) + .type GL_PREFIX(GetColorTable), @function +GL_PREFIX(GetColorTable): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2744(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2744(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2744(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2744(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetColorTable), .-GL_PREFIX(GetColorTable) + + .p2align 4,,15 + .globl GL_PREFIX(GetColorTableParameterfv) + .type GL_PREFIX(GetColorTableParameterfv), @function +GL_PREFIX(GetColorTableParameterfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2752(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2752(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2752(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2752(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetColorTableParameterfv), .-GL_PREFIX(GetColorTableParameterfv) + + .p2align 4,,15 + .globl GL_PREFIX(GetColorTableParameteriv) + .type GL_PREFIX(GetColorTableParameteriv), @function +GL_PREFIX(GetColorTableParameteriv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2760(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2760(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2760(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2760(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetColorTableParameteriv), .-GL_PREFIX(GetColorTableParameteriv) + + .p2align 4,,15 + .globl GL_PREFIX(ColorSubTable) + .type GL_PREFIX(ColorSubTable), @function +GL_PREFIX(ColorSubTable): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2768(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2768(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2768(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2768(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ColorSubTable), .-GL_PREFIX(ColorSubTable) + + .p2align 4,,15 + .globl GL_PREFIX(CopyColorSubTable) + .type GL_PREFIX(CopyColorSubTable), @function +GL_PREFIX(CopyColorSubTable): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2776(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2776(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2776(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2776(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CopyColorSubTable), .-GL_PREFIX(CopyColorSubTable) + + .p2align 4,,15 + .globl GL_PREFIX(ConvolutionFilter1D) + .type GL_PREFIX(ConvolutionFilter1D), @function +GL_PREFIX(ConvolutionFilter1D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2784(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2784(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2784(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2784(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ConvolutionFilter1D), .-GL_PREFIX(ConvolutionFilter1D) + + .p2align 4,,15 + .globl GL_PREFIX(ConvolutionFilter2D) + .type GL_PREFIX(ConvolutionFilter2D), @function +GL_PREFIX(ConvolutionFilter2D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2792(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2792(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2792(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2792(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ConvolutionFilter2D), .-GL_PREFIX(ConvolutionFilter2D) + + .p2align 4,,15 + .globl GL_PREFIX(ConvolutionParameterf) + .type GL_PREFIX(ConvolutionParameterf), @function +GL_PREFIX(ConvolutionParameterf): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2800(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $24, %rsp + movq 2800(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2800(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $24, %rsp + movq 2800(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ConvolutionParameterf), .-GL_PREFIX(ConvolutionParameterf) + + .p2align 4,,15 + .globl GL_PREFIX(ConvolutionParameterfv) + .type GL_PREFIX(ConvolutionParameterfv), @function +GL_PREFIX(ConvolutionParameterfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2808(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2808(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2808(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2808(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ConvolutionParameterfv), .-GL_PREFIX(ConvolutionParameterfv) + + .p2align 4,,15 + .globl GL_PREFIX(ConvolutionParameteri) + .type GL_PREFIX(ConvolutionParameteri), @function +GL_PREFIX(ConvolutionParameteri): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2816(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2816(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2816(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2816(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ConvolutionParameteri), .-GL_PREFIX(ConvolutionParameteri) + + .p2align 4,,15 + .globl GL_PREFIX(ConvolutionParameteriv) + .type GL_PREFIX(ConvolutionParameteriv), @function +GL_PREFIX(ConvolutionParameteriv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2824(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2824(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2824(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2824(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ConvolutionParameteriv), .-GL_PREFIX(ConvolutionParameteriv) + + .p2align 4,,15 + .globl GL_PREFIX(CopyConvolutionFilter1D) + .type GL_PREFIX(CopyConvolutionFilter1D), @function +GL_PREFIX(CopyConvolutionFilter1D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2832(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2832(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2832(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2832(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CopyConvolutionFilter1D), .-GL_PREFIX(CopyConvolutionFilter1D) + + .p2align 4,,15 + .globl GL_PREFIX(CopyConvolutionFilter2D) + .type GL_PREFIX(CopyConvolutionFilter2D), @function +GL_PREFIX(CopyConvolutionFilter2D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2840(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2840(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2840(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2840(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CopyConvolutionFilter2D), .-GL_PREFIX(CopyConvolutionFilter2D) + + .p2align 4,,15 + .globl GL_PREFIX(GetConvolutionFilter) + .type GL_PREFIX(GetConvolutionFilter), @function +GL_PREFIX(GetConvolutionFilter): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2848(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2848(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2848(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2848(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetConvolutionFilter), .-GL_PREFIX(GetConvolutionFilter) + + .p2align 4,,15 + .globl GL_PREFIX(GetConvolutionParameterfv) + .type GL_PREFIX(GetConvolutionParameterfv), @function +GL_PREFIX(GetConvolutionParameterfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2856(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2856(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2856(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2856(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetConvolutionParameterfv), .-GL_PREFIX(GetConvolutionParameterfv) + + .p2align 4,,15 + .globl GL_PREFIX(GetConvolutionParameteriv) + .type GL_PREFIX(GetConvolutionParameteriv), @function +GL_PREFIX(GetConvolutionParameteriv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2864(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2864(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2864(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2864(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetConvolutionParameteriv), .-GL_PREFIX(GetConvolutionParameteriv) + + .p2align 4,,15 + .globl GL_PREFIX(GetSeparableFilter) + .type GL_PREFIX(GetSeparableFilter), @function +GL_PREFIX(GetSeparableFilter): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2872(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2872(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2872(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2872(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetSeparableFilter), .-GL_PREFIX(GetSeparableFilter) + + .p2align 4,,15 + .globl GL_PREFIX(SeparableFilter2D) + .type GL_PREFIX(SeparableFilter2D), @function +GL_PREFIX(SeparableFilter2D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2880(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2880(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2880(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2880(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SeparableFilter2D), .-GL_PREFIX(SeparableFilter2D) + + .p2align 4,,15 + .globl GL_PREFIX(GetHistogram) + .type GL_PREFIX(GetHistogram), @function +GL_PREFIX(GetHistogram): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2888(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2888(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2888(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2888(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetHistogram), .-GL_PREFIX(GetHistogram) + + .p2align 4,,15 + .globl GL_PREFIX(GetHistogramParameterfv) + .type GL_PREFIX(GetHistogramParameterfv), @function +GL_PREFIX(GetHistogramParameterfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2896(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2896(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2896(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2896(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetHistogramParameterfv), .-GL_PREFIX(GetHistogramParameterfv) + + .p2align 4,,15 + .globl GL_PREFIX(GetHistogramParameteriv) + .type GL_PREFIX(GetHistogramParameteriv), @function +GL_PREFIX(GetHistogramParameteriv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2904(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2904(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2904(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2904(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetHistogramParameteriv), .-GL_PREFIX(GetHistogramParameteriv) + + .p2align 4,,15 + .globl GL_PREFIX(GetMinmax) + .type GL_PREFIX(GetMinmax), @function +GL_PREFIX(GetMinmax): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2912(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2912(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2912(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2912(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetMinmax), .-GL_PREFIX(GetMinmax) + + .p2align 4,,15 + .globl GL_PREFIX(GetMinmaxParameterfv) + .type GL_PREFIX(GetMinmaxParameterfv), @function +GL_PREFIX(GetMinmaxParameterfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2920(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2920(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2920(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2920(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetMinmaxParameterfv), .-GL_PREFIX(GetMinmaxParameterfv) + + .p2align 4,,15 + .globl GL_PREFIX(GetMinmaxParameteriv) + .type GL_PREFIX(GetMinmaxParameteriv), @function +GL_PREFIX(GetMinmaxParameteriv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2928(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2928(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2928(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2928(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetMinmaxParameteriv), .-GL_PREFIX(GetMinmaxParameteriv) + + .p2align 4,,15 + .globl GL_PREFIX(Histogram) + .type GL_PREFIX(Histogram), @function +GL_PREFIX(Histogram): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2936(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2936(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2936(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2936(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Histogram), .-GL_PREFIX(Histogram) + + .p2align 4,,15 + .globl GL_PREFIX(Minmax) + .type GL_PREFIX(Minmax), @function +GL_PREFIX(Minmax): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2944(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 2944(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2944(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 2944(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Minmax), .-GL_PREFIX(Minmax) + + .p2align 4,,15 + .globl GL_PREFIX(ResetHistogram) + .type GL_PREFIX(ResetHistogram), @function +GL_PREFIX(ResetHistogram): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2952(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2952(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2952(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2952(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ResetHistogram), .-GL_PREFIX(ResetHistogram) + + .p2align 4,,15 + .globl GL_PREFIX(ResetMinmax) + .type GL_PREFIX(ResetMinmax), @function +GL_PREFIX(ResetMinmax): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2960(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2960(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2960(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2960(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ResetMinmax), .-GL_PREFIX(ResetMinmax) + + .p2align 4,,15 + .globl GL_PREFIX(TexImage3D) + .type GL_PREFIX(TexImage3D), @function +GL_PREFIX(TexImage3D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2968(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2968(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2968(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2968(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexImage3D), .-GL_PREFIX(TexImage3D) + + .p2align 4,,15 + .globl GL_PREFIX(TexSubImage3D) + .type GL_PREFIX(TexSubImage3D), @function +GL_PREFIX(TexSubImage3D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2976(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2976(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2976(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2976(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexSubImage3D), .-GL_PREFIX(TexSubImage3D) + + .p2align 4,,15 + .globl GL_PREFIX(CopyTexSubImage3D) + .type GL_PREFIX(CopyTexSubImage3D), @function +GL_PREFIX(CopyTexSubImage3D): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2984(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2984(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2984(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 2984(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CopyTexSubImage3D), .-GL_PREFIX(CopyTexSubImage3D) + + .p2align 4,,15 + .globl GL_PREFIX(ActiveTextureARB) + .type GL_PREFIX(ActiveTextureARB), @function +GL_PREFIX(ActiveTextureARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 2992(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 2992(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 2992(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 2992(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ActiveTextureARB), .-GL_PREFIX(ActiveTextureARB) + + .p2align 4,,15 + .globl GL_PREFIX(ClientActiveTextureARB) + .type GL_PREFIX(ClientActiveTextureARB), @function +GL_PREFIX(ClientActiveTextureARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3000(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 3000(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3000(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 3000(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClientActiveTextureARB), .-GL_PREFIX(ClientActiveTextureARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord1dARB) + .type GL_PREFIX(MultiTexCoord1dARB), @function +GL_PREFIX(MultiTexCoord1dARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3008(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3008(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3008(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3008(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord1dARB), .-GL_PREFIX(MultiTexCoord1dARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord1dvARB) + .type GL_PREFIX(MultiTexCoord1dvARB), @function +GL_PREFIX(MultiTexCoord1dvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3016(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3016(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3016(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3016(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord1dvARB), .-GL_PREFIX(MultiTexCoord1dvARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord1fARB) + .type GL_PREFIX(MultiTexCoord1fARB), @function +GL_PREFIX(MultiTexCoord1fARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3024(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3024(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3024(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3024(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord1fARB), .-GL_PREFIX(MultiTexCoord1fARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord1fvARB) + .type GL_PREFIX(MultiTexCoord1fvARB), @function +GL_PREFIX(MultiTexCoord1fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3032(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3032(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3032(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3032(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord1fvARB), .-GL_PREFIX(MultiTexCoord1fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord1iARB) + .type GL_PREFIX(MultiTexCoord1iARB), @function +GL_PREFIX(MultiTexCoord1iARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3040(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3040(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3040(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3040(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord1iARB), .-GL_PREFIX(MultiTexCoord1iARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord1ivARB) + .type GL_PREFIX(MultiTexCoord1ivARB), @function +GL_PREFIX(MultiTexCoord1ivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3048(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3048(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3048(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3048(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord1ivARB), .-GL_PREFIX(MultiTexCoord1ivARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord1sARB) + .type GL_PREFIX(MultiTexCoord1sARB), @function +GL_PREFIX(MultiTexCoord1sARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3056(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3056(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3056(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3056(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord1sARB), .-GL_PREFIX(MultiTexCoord1sARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord1svARB) + .type GL_PREFIX(MultiTexCoord1svARB), @function +GL_PREFIX(MultiTexCoord1svARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3064(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3064(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3064(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3064(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord1svARB), .-GL_PREFIX(MultiTexCoord1svARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord2dARB) + .type GL_PREFIX(MultiTexCoord2dARB), @function +GL_PREFIX(MultiTexCoord2dARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3072(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3072(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3072(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3072(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord2dARB), .-GL_PREFIX(MultiTexCoord2dARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord2dvARB) + .type GL_PREFIX(MultiTexCoord2dvARB), @function +GL_PREFIX(MultiTexCoord2dvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3080(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3080(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3080(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3080(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord2dvARB), .-GL_PREFIX(MultiTexCoord2dvARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord2fARB) + .type GL_PREFIX(MultiTexCoord2fARB), @function +GL_PREFIX(MultiTexCoord2fARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3088(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3088(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3088(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3088(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord2fARB), .-GL_PREFIX(MultiTexCoord2fARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord2fvARB) + .type GL_PREFIX(MultiTexCoord2fvARB), @function +GL_PREFIX(MultiTexCoord2fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3096(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3096(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3096(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3096(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord2fvARB), .-GL_PREFIX(MultiTexCoord2fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord2iARB) + .type GL_PREFIX(MultiTexCoord2iARB), @function +GL_PREFIX(MultiTexCoord2iARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3104(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3104(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3104(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3104(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord2iARB), .-GL_PREFIX(MultiTexCoord2iARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord2ivARB) + .type GL_PREFIX(MultiTexCoord2ivARB), @function +GL_PREFIX(MultiTexCoord2ivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3112(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3112(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3112(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3112(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord2ivARB), .-GL_PREFIX(MultiTexCoord2ivARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord2sARB) + .type GL_PREFIX(MultiTexCoord2sARB), @function +GL_PREFIX(MultiTexCoord2sARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3120(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3120(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3120(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3120(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord2sARB), .-GL_PREFIX(MultiTexCoord2sARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord2svARB) + .type GL_PREFIX(MultiTexCoord2svARB), @function +GL_PREFIX(MultiTexCoord2svARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3128(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3128(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3128(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3128(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord2svARB), .-GL_PREFIX(MultiTexCoord2svARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord3dARB) + .type GL_PREFIX(MultiTexCoord3dARB), @function +GL_PREFIX(MultiTexCoord3dARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3136(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 3136(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3136(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 3136(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord3dARB), .-GL_PREFIX(MultiTexCoord3dARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord3dvARB) + .type GL_PREFIX(MultiTexCoord3dvARB), @function +GL_PREFIX(MultiTexCoord3dvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3144(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3144(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3144(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3144(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord3dvARB), .-GL_PREFIX(MultiTexCoord3dvARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord3fARB) + .type GL_PREFIX(MultiTexCoord3fARB), @function +GL_PREFIX(MultiTexCoord3fARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3152(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 3152(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3152(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 3152(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord3fARB), .-GL_PREFIX(MultiTexCoord3fARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord3fvARB) + .type GL_PREFIX(MultiTexCoord3fvARB), @function +GL_PREFIX(MultiTexCoord3fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3160(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3160(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3160(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3160(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord3fvARB), .-GL_PREFIX(MultiTexCoord3fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord3iARB) + .type GL_PREFIX(MultiTexCoord3iARB), @function +GL_PREFIX(MultiTexCoord3iARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3168(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3168(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3168(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3168(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord3iARB), .-GL_PREFIX(MultiTexCoord3iARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord3ivARB) + .type GL_PREFIX(MultiTexCoord3ivARB), @function +GL_PREFIX(MultiTexCoord3ivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3176(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3176(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3176(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3176(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord3ivARB), .-GL_PREFIX(MultiTexCoord3ivARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord3sARB) + .type GL_PREFIX(MultiTexCoord3sARB), @function +GL_PREFIX(MultiTexCoord3sARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3184(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3184(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3184(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3184(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord3sARB), .-GL_PREFIX(MultiTexCoord3sARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord3svARB) + .type GL_PREFIX(MultiTexCoord3svARB), @function +GL_PREFIX(MultiTexCoord3svARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3192(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3192(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3192(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3192(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord3svARB), .-GL_PREFIX(MultiTexCoord3svARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord4dARB) + .type GL_PREFIX(MultiTexCoord4dARB), @function +GL_PREFIX(MultiTexCoord4dARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3200(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + movq %xmm3, 32(%rsp) + call _x86_64_get_dispatch@PLT + movq 32(%rsp), %xmm3 + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 3200(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3200(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + movq %xmm3, 32(%rsp) + call _glapi_get_dispatch + movq 32(%rsp), %xmm3 + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 3200(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord4dARB), .-GL_PREFIX(MultiTexCoord4dARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord4dvARB) + .type GL_PREFIX(MultiTexCoord4dvARB), @function +GL_PREFIX(MultiTexCoord4dvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3208(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3208(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3208(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3208(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord4dvARB), .-GL_PREFIX(MultiTexCoord4dvARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord4fARB) + .type GL_PREFIX(MultiTexCoord4fARB), @function +GL_PREFIX(MultiTexCoord4fARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3216(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + movq %xmm3, 32(%rsp) + call _x86_64_get_dispatch@PLT + movq 32(%rsp), %xmm3 + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 3216(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3216(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + movq %xmm3, 32(%rsp) + call _glapi_get_dispatch + movq 32(%rsp), %xmm3 + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 3216(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord4fARB), .-GL_PREFIX(MultiTexCoord4fARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord4fvARB) + .type GL_PREFIX(MultiTexCoord4fvARB), @function +GL_PREFIX(MultiTexCoord4fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3224(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3224(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3224(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3224(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord4fvARB), .-GL_PREFIX(MultiTexCoord4fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord4iARB) + .type GL_PREFIX(MultiTexCoord4iARB), @function +GL_PREFIX(MultiTexCoord4iARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3232(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3232(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3232(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3232(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord4iARB), .-GL_PREFIX(MultiTexCoord4iARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord4ivARB) + .type GL_PREFIX(MultiTexCoord4ivARB), @function +GL_PREFIX(MultiTexCoord4ivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3240(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3240(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3240(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3240(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord4ivARB), .-GL_PREFIX(MultiTexCoord4ivARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord4sARB) + .type GL_PREFIX(MultiTexCoord4sARB), @function +GL_PREFIX(MultiTexCoord4sARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3248(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3248(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3248(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3248(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord4sARB), .-GL_PREFIX(MultiTexCoord4sARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultiTexCoord4svARB) + .type GL_PREFIX(MultiTexCoord4svARB), @function +GL_PREFIX(MultiTexCoord4svARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3256(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3256(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3256(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3256(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiTexCoord4svARB), .-GL_PREFIX(MultiTexCoord4svARB) + + .p2align 4,,15 + .globl GL_PREFIX(AttachShader) + .type GL_PREFIX(AttachShader), @function +GL_PREFIX(AttachShader): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3264(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3264(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3264(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3264(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(AttachShader), .-GL_PREFIX(AttachShader) + + .p2align 4,,15 + .globl GL_PREFIX(CreateProgram) + .type GL_PREFIX(CreateProgram), @function +GL_PREFIX(CreateProgram): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3272(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 3272(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3272(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 3272(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CreateProgram), .-GL_PREFIX(CreateProgram) + + .p2align 4,,15 + .globl GL_PREFIX(CreateShader) + .type GL_PREFIX(CreateShader), @function +GL_PREFIX(CreateShader): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3280(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 3280(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3280(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 3280(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CreateShader), .-GL_PREFIX(CreateShader) + + .p2align 4,,15 + .globl GL_PREFIX(DeleteProgram) + .type GL_PREFIX(DeleteProgram), @function +GL_PREFIX(DeleteProgram): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3288(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 3288(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3288(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 3288(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DeleteProgram), .-GL_PREFIX(DeleteProgram) + + .p2align 4,,15 + .globl GL_PREFIX(DeleteShader) + .type GL_PREFIX(DeleteShader), @function +GL_PREFIX(DeleteShader): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3296(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 3296(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3296(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 3296(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DeleteShader), .-GL_PREFIX(DeleteShader) + + .p2align 4,,15 + .globl GL_PREFIX(DetachShader) + .type GL_PREFIX(DetachShader), @function +GL_PREFIX(DetachShader): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3304(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3304(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3304(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3304(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DetachShader), .-GL_PREFIX(DetachShader) + + .p2align 4,,15 + .globl GL_PREFIX(GetAttachedShaders) + .type GL_PREFIX(GetAttachedShaders), @function +GL_PREFIX(GetAttachedShaders): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3312(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3312(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3312(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3312(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetAttachedShaders), .-GL_PREFIX(GetAttachedShaders) + + .p2align 4,,15 + .globl GL_PREFIX(GetProgramInfoLog) + .type GL_PREFIX(GetProgramInfoLog), @function +GL_PREFIX(GetProgramInfoLog): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3320(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3320(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3320(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3320(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetProgramInfoLog), .-GL_PREFIX(GetProgramInfoLog) + + .p2align 4,,15 + .globl GL_PREFIX(GetProgramiv) + .type GL_PREFIX(GetProgramiv), @function +GL_PREFIX(GetProgramiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3328(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3328(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3328(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3328(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetProgramiv), .-GL_PREFIX(GetProgramiv) + + .p2align 4,,15 + .globl GL_PREFIX(GetShaderInfoLog) + .type GL_PREFIX(GetShaderInfoLog), @function +GL_PREFIX(GetShaderInfoLog): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3336(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3336(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3336(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3336(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetShaderInfoLog), .-GL_PREFIX(GetShaderInfoLog) + + .p2align 4,,15 + .globl GL_PREFIX(GetShaderiv) + .type GL_PREFIX(GetShaderiv), @function +GL_PREFIX(GetShaderiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3344(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3344(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3344(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3344(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetShaderiv), .-GL_PREFIX(GetShaderiv) + + .p2align 4,,15 + .globl GL_PREFIX(IsProgram) + .type GL_PREFIX(IsProgram), @function +GL_PREFIX(IsProgram): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3352(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 3352(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3352(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 3352(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IsProgram), .-GL_PREFIX(IsProgram) + + .p2align 4,,15 + .globl GL_PREFIX(IsShader) + .type GL_PREFIX(IsShader), @function +GL_PREFIX(IsShader): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3360(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 3360(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3360(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 3360(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IsShader), .-GL_PREFIX(IsShader) + + .p2align 4,,15 + .globl GL_PREFIX(StencilFuncSeparate) + .type GL_PREFIX(StencilFuncSeparate), @function +GL_PREFIX(StencilFuncSeparate): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3368(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3368(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3368(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3368(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(StencilFuncSeparate), .-GL_PREFIX(StencilFuncSeparate) + + .p2align 4,,15 + .globl GL_PREFIX(StencilMaskSeparate) + .type GL_PREFIX(StencilMaskSeparate), @function +GL_PREFIX(StencilMaskSeparate): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3376(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3376(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3376(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3376(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(StencilMaskSeparate), .-GL_PREFIX(StencilMaskSeparate) + + .p2align 4,,15 + .globl GL_PREFIX(StencilOpSeparate) + .type GL_PREFIX(StencilOpSeparate), @function +GL_PREFIX(StencilOpSeparate): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3384(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3384(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3384(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3384(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(StencilOpSeparate), .-GL_PREFIX(StencilOpSeparate) + + .p2align 4,,15 + .globl GL_PREFIX(UniformMatrix2x3fv) + .type GL_PREFIX(UniformMatrix2x3fv), @function +GL_PREFIX(UniformMatrix2x3fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3392(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3392(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3392(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3392(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(UniformMatrix2x3fv), .-GL_PREFIX(UniformMatrix2x3fv) + + .p2align 4,,15 + .globl GL_PREFIX(UniformMatrix2x4fv) + .type GL_PREFIX(UniformMatrix2x4fv), @function +GL_PREFIX(UniformMatrix2x4fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3400(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3400(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3400(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3400(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(UniformMatrix2x4fv), .-GL_PREFIX(UniformMatrix2x4fv) + + .p2align 4,,15 + .globl GL_PREFIX(UniformMatrix3x2fv) + .type GL_PREFIX(UniformMatrix3x2fv), @function +GL_PREFIX(UniformMatrix3x2fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3408(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3408(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3408(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3408(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(UniformMatrix3x2fv), .-GL_PREFIX(UniformMatrix3x2fv) + + .p2align 4,,15 + .globl GL_PREFIX(UniformMatrix3x4fv) + .type GL_PREFIX(UniformMatrix3x4fv), @function +GL_PREFIX(UniformMatrix3x4fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3416(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3416(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3416(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3416(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(UniformMatrix3x4fv), .-GL_PREFIX(UniformMatrix3x4fv) + + .p2align 4,,15 + .globl GL_PREFIX(UniformMatrix4x2fv) + .type GL_PREFIX(UniformMatrix4x2fv), @function +GL_PREFIX(UniformMatrix4x2fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3424(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3424(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3424(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3424(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(UniformMatrix4x2fv), .-GL_PREFIX(UniformMatrix4x2fv) + + .p2align 4,,15 + .globl GL_PREFIX(UniformMatrix4x3fv) + .type GL_PREFIX(UniformMatrix4x3fv), @function +GL_PREFIX(UniformMatrix4x3fv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3432(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3432(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3432(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3432(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(UniformMatrix4x3fv), .-GL_PREFIX(UniformMatrix4x3fv) + + .p2align 4,,15 + .globl GL_PREFIX(ClampColor) + .type GL_PREFIX(ClampColor), @function +GL_PREFIX(ClampColor): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3440(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3440(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3440(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3440(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClampColor), .-GL_PREFIX(ClampColor) + + .p2align 4,,15 + .globl GL_PREFIX(ClearBufferfi) + .type GL_PREFIX(ClearBufferfi), @function +GL_PREFIX(ClearBufferfi): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3448(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + movq %rdx, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %rdx + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $40, %rsp + movq 3448(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3448(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + movq %rdx, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %rdx + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $40, %rsp + movq 3448(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClearBufferfi), .-GL_PREFIX(ClearBufferfi) + + .p2align 4,,15 + .globl GL_PREFIX(ClearBufferfv) + .type GL_PREFIX(ClearBufferfv), @function +GL_PREFIX(ClearBufferfv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3456(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3456(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3456(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3456(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClearBufferfv), .-GL_PREFIX(ClearBufferfv) + + .p2align 4,,15 + .globl GL_PREFIX(ClearBufferiv) + .type GL_PREFIX(ClearBufferiv), @function +GL_PREFIX(ClearBufferiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3464(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3464(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3464(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3464(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClearBufferiv), .-GL_PREFIX(ClearBufferiv) + + .p2align 4,,15 + .globl GL_PREFIX(ClearBufferuiv) + .type GL_PREFIX(ClearBufferuiv), @function +GL_PREFIX(ClearBufferuiv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3472(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3472(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3472(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3472(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClearBufferuiv), .-GL_PREFIX(ClearBufferuiv) + + .p2align 4,,15 + .globl GL_PREFIX(GetStringi) + .type GL_PREFIX(GetStringi), @function +GL_PREFIX(GetStringi): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3480(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3480(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3480(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3480(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetStringi), .-GL_PREFIX(GetStringi) + + .p2align 4,,15 + .globl GL_PREFIX(TexBuffer) + .type GL_PREFIX(TexBuffer), @function +GL_PREFIX(TexBuffer): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3488(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3488(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3488(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3488(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexBuffer), .-GL_PREFIX(TexBuffer) + + .p2align 4,,15 + .globl GL_PREFIX(FramebufferTexture) + .type GL_PREFIX(FramebufferTexture), @function +GL_PREFIX(FramebufferTexture): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3496(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3496(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3496(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3496(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FramebufferTexture), .-GL_PREFIX(FramebufferTexture) + + .p2align 4,,15 + .globl GL_PREFIX(GetBufferParameteri64v) + .type GL_PREFIX(GetBufferParameteri64v), @function +GL_PREFIX(GetBufferParameteri64v): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3504(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3504(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3504(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3504(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetBufferParameteri64v), .-GL_PREFIX(GetBufferParameteri64v) + + .p2align 4,,15 + .globl GL_PREFIX(GetInteger64i_v) + .type GL_PREFIX(GetInteger64i_v), @function +GL_PREFIX(GetInteger64i_v): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3512(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3512(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3512(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3512(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetInteger64i_v), .-GL_PREFIX(GetInteger64i_v) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribDivisor) + .type GL_PREFIX(VertexAttribDivisor), @function +GL_PREFIX(VertexAttribDivisor): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3520(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3520(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3520(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3520(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribDivisor), .-GL_PREFIX(VertexAttribDivisor) + + .p2align 4,,15 + .globl GL_PREFIX(LoadTransposeMatrixdARB) + .type GL_PREFIX(LoadTransposeMatrixdARB), @function +GL_PREFIX(LoadTransposeMatrixdARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3528(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 3528(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3528(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 3528(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LoadTransposeMatrixdARB), .-GL_PREFIX(LoadTransposeMatrixdARB) + + .p2align 4,,15 + .globl GL_PREFIX(LoadTransposeMatrixfARB) + .type GL_PREFIX(LoadTransposeMatrixfARB), @function +GL_PREFIX(LoadTransposeMatrixfARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3536(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 3536(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3536(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 3536(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LoadTransposeMatrixfARB), .-GL_PREFIX(LoadTransposeMatrixfARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultTransposeMatrixdARB) + .type GL_PREFIX(MultTransposeMatrixdARB), @function +GL_PREFIX(MultTransposeMatrixdARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3544(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 3544(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3544(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 3544(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultTransposeMatrixdARB), .-GL_PREFIX(MultTransposeMatrixdARB) + + .p2align 4,,15 + .globl GL_PREFIX(MultTransposeMatrixfARB) + .type GL_PREFIX(MultTransposeMatrixfARB), @function +GL_PREFIX(MultTransposeMatrixfARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3552(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 3552(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3552(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 3552(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultTransposeMatrixfARB), .-GL_PREFIX(MultTransposeMatrixfARB) + + .p2align 4,,15 + .globl GL_PREFIX(SampleCoverageARB) + .type GL_PREFIX(SampleCoverageARB), @function +GL_PREFIX(SampleCoverageARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3560(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3560(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3560(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3560(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SampleCoverageARB), .-GL_PREFIX(SampleCoverageARB) + + .p2align 4,,15 + .globl GL_PREFIX(CompressedTexImage1DARB) + .type GL_PREFIX(CompressedTexImage1DARB), @function +GL_PREFIX(CompressedTexImage1DARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3568(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3568(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3568(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3568(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CompressedTexImage1DARB), .-GL_PREFIX(CompressedTexImage1DARB) + + .p2align 4,,15 + .globl GL_PREFIX(CompressedTexImage2DARB) + .type GL_PREFIX(CompressedTexImage2DARB), @function +GL_PREFIX(CompressedTexImage2DARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3576(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3576(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3576(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3576(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CompressedTexImage2DARB), .-GL_PREFIX(CompressedTexImage2DARB) + + .p2align 4,,15 + .globl GL_PREFIX(CompressedTexImage3DARB) + .type GL_PREFIX(CompressedTexImage3DARB), @function +GL_PREFIX(CompressedTexImage3DARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3584(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3584(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3584(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3584(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CompressedTexImage3DARB), .-GL_PREFIX(CompressedTexImage3DARB) + + .p2align 4,,15 + .globl GL_PREFIX(CompressedTexSubImage1DARB) + .type GL_PREFIX(CompressedTexSubImage1DARB), @function +GL_PREFIX(CompressedTexSubImage1DARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3592(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3592(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3592(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3592(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CompressedTexSubImage1DARB), .-GL_PREFIX(CompressedTexSubImage1DARB) + + .p2align 4,,15 + .globl GL_PREFIX(CompressedTexSubImage2DARB) + .type GL_PREFIX(CompressedTexSubImage2DARB), @function +GL_PREFIX(CompressedTexSubImage2DARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3600(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3600(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3600(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3600(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CompressedTexSubImage2DARB), .-GL_PREFIX(CompressedTexSubImage2DARB) + + .p2align 4,,15 + .globl GL_PREFIX(CompressedTexSubImage3DARB) + .type GL_PREFIX(CompressedTexSubImage3DARB), @function +GL_PREFIX(CompressedTexSubImage3DARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3608(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3608(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3608(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3608(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CompressedTexSubImage3DARB), .-GL_PREFIX(CompressedTexSubImage3DARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetCompressedTexImageARB) + .type GL_PREFIX(GetCompressedTexImageARB), @function +GL_PREFIX(GetCompressedTexImageARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3616(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3616(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3616(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3616(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetCompressedTexImageARB), .-GL_PREFIX(GetCompressedTexImageARB) + + .p2align 4,,15 + .globl GL_PREFIX(DisableVertexAttribArrayARB) + .type GL_PREFIX(DisableVertexAttribArrayARB), @function +GL_PREFIX(DisableVertexAttribArrayARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3624(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 3624(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3624(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 3624(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DisableVertexAttribArrayARB), .-GL_PREFIX(DisableVertexAttribArrayARB) + + .p2align 4,,15 + .globl GL_PREFIX(EnableVertexAttribArrayARB) + .type GL_PREFIX(EnableVertexAttribArrayARB), @function +GL_PREFIX(EnableVertexAttribArrayARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3632(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 3632(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3632(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 3632(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EnableVertexAttribArrayARB), .-GL_PREFIX(EnableVertexAttribArrayARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetProgramEnvParameterdvARB) + .type GL_PREFIX(GetProgramEnvParameterdvARB), @function +GL_PREFIX(GetProgramEnvParameterdvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3640(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3640(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3640(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3640(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetProgramEnvParameterdvARB), .-GL_PREFIX(GetProgramEnvParameterdvARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetProgramEnvParameterfvARB) + .type GL_PREFIX(GetProgramEnvParameterfvARB), @function +GL_PREFIX(GetProgramEnvParameterfvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3648(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3648(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3648(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3648(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetProgramEnvParameterfvARB), .-GL_PREFIX(GetProgramEnvParameterfvARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetProgramLocalParameterdvARB) + .type GL_PREFIX(GetProgramLocalParameterdvARB), @function +GL_PREFIX(GetProgramLocalParameterdvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3656(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3656(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3656(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3656(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetProgramLocalParameterdvARB), .-GL_PREFIX(GetProgramLocalParameterdvARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetProgramLocalParameterfvARB) + .type GL_PREFIX(GetProgramLocalParameterfvARB), @function +GL_PREFIX(GetProgramLocalParameterfvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3664(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3664(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3664(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3664(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetProgramLocalParameterfvARB), .-GL_PREFIX(GetProgramLocalParameterfvARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetProgramStringARB) + .type GL_PREFIX(GetProgramStringARB), @function +GL_PREFIX(GetProgramStringARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3672(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3672(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3672(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3672(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetProgramStringARB), .-GL_PREFIX(GetProgramStringARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetProgramivARB) + .type GL_PREFIX(GetProgramivARB), @function +GL_PREFIX(GetProgramivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3680(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3680(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3680(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3680(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetProgramivARB), .-GL_PREFIX(GetProgramivARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetVertexAttribdvARB) + .type GL_PREFIX(GetVertexAttribdvARB), @function +GL_PREFIX(GetVertexAttribdvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3688(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3688(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3688(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3688(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetVertexAttribdvARB), .-GL_PREFIX(GetVertexAttribdvARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetVertexAttribfvARB) + .type GL_PREFIX(GetVertexAttribfvARB), @function +GL_PREFIX(GetVertexAttribfvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3696(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3696(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3696(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3696(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetVertexAttribfvARB), .-GL_PREFIX(GetVertexAttribfvARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetVertexAttribivARB) + .type GL_PREFIX(GetVertexAttribivARB), @function +GL_PREFIX(GetVertexAttribivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3704(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3704(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3704(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3704(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetVertexAttribivARB), .-GL_PREFIX(GetVertexAttribivARB) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramEnvParameter4dARB) + .type GL_PREFIX(ProgramEnvParameter4dARB), @function +GL_PREFIX(ProgramEnvParameter4dARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3712(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $56, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + movq %xmm1, 24(%rsp) + movq %xmm2, 32(%rsp) + movq %xmm3, 40(%rsp) + call _x86_64_get_dispatch@PLT + movq 40(%rsp), %xmm3 + movq 32(%rsp), %xmm2 + movq 24(%rsp), %xmm1 + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $56, %rsp + movq 3712(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3712(%rax), %r11 + jmp *%r11 +1: + subq $56, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + movq %xmm1, 24(%rsp) + movq %xmm2, 32(%rsp) + movq %xmm3, 40(%rsp) + call _glapi_get_dispatch + movq 40(%rsp), %xmm3 + movq 32(%rsp), %xmm2 + movq 24(%rsp), %xmm1 + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $56, %rsp + movq 3712(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramEnvParameter4dARB), .-GL_PREFIX(ProgramEnvParameter4dARB) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramEnvParameter4dvARB) + .type GL_PREFIX(ProgramEnvParameter4dvARB), @function +GL_PREFIX(ProgramEnvParameter4dvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3720(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3720(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3720(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3720(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramEnvParameter4dvARB), .-GL_PREFIX(ProgramEnvParameter4dvARB) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramEnvParameter4fARB) + .type GL_PREFIX(ProgramEnvParameter4fARB), @function +GL_PREFIX(ProgramEnvParameter4fARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3728(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $56, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + movq %xmm1, 24(%rsp) + movq %xmm2, 32(%rsp) + movq %xmm3, 40(%rsp) + call _x86_64_get_dispatch@PLT + movq 40(%rsp), %xmm3 + movq 32(%rsp), %xmm2 + movq 24(%rsp), %xmm1 + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $56, %rsp + movq 3728(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3728(%rax), %r11 + jmp *%r11 +1: + subq $56, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + movq %xmm1, 24(%rsp) + movq %xmm2, 32(%rsp) + movq %xmm3, 40(%rsp) + call _glapi_get_dispatch + movq 40(%rsp), %xmm3 + movq 32(%rsp), %xmm2 + movq 24(%rsp), %xmm1 + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $56, %rsp + movq 3728(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramEnvParameter4fARB), .-GL_PREFIX(ProgramEnvParameter4fARB) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramEnvParameter4fvARB) + .type GL_PREFIX(ProgramEnvParameter4fvARB), @function +GL_PREFIX(ProgramEnvParameter4fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3736(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3736(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3736(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3736(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramEnvParameter4fvARB), .-GL_PREFIX(ProgramEnvParameter4fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramLocalParameter4dARB) + .type GL_PREFIX(ProgramLocalParameter4dARB), @function +GL_PREFIX(ProgramLocalParameter4dARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3744(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $56, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + movq %xmm1, 24(%rsp) + movq %xmm2, 32(%rsp) + movq %xmm3, 40(%rsp) + call _x86_64_get_dispatch@PLT + movq 40(%rsp), %xmm3 + movq 32(%rsp), %xmm2 + movq 24(%rsp), %xmm1 + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $56, %rsp + movq 3744(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3744(%rax), %r11 + jmp *%r11 +1: + subq $56, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + movq %xmm1, 24(%rsp) + movq %xmm2, 32(%rsp) + movq %xmm3, 40(%rsp) + call _glapi_get_dispatch + movq 40(%rsp), %xmm3 + movq 32(%rsp), %xmm2 + movq 24(%rsp), %xmm1 + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $56, %rsp + movq 3744(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramLocalParameter4dARB), .-GL_PREFIX(ProgramLocalParameter4dARB) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramLocalParameter4dvARB) + .type GL_PREFIX(ProgramLocalParameter4dvARB), @function +GL_PREFIX(ProgramLocalParameter4dvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3752(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3752(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3752(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3752(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramLocalParameter4dvARB), .-GL_PREFIX(ProgramLocalParameter4dvARB) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramLocalParameter4fARB) + .type GL_PREFIX(ProgramLocalParameter4fARB), @function +GL_PREFIX(ProgramLocalParameter4fARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3760(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $56, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + movq %xmm1, 24(%rsp) + movq %xmm2, 32(%rsp) + movq %xmm3, 40(%rsp) + call _x86_64_get_dispatch@PLT + movq 40(%rsp), %xmm3 + movq 32(%rsp), %xmm2 + movq 24(%rsp), %xmm1 + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $56, %rsp + movq 3760(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3760(%rax), %r11 + jmp *%r11 +1: + subq $56, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %xmm0, 16(%rsp) + movq %xmm1, 24(%rsp) + movq %xmm2, 32(%rsp) + movq %xmm3, 40(%rsp) + call _glapi_get_dispatch + movq 40(%rsp), %xmm3 + movq 32(%rsp), %xmm2 + movq 24(%rsp), %xmm1 + movq 16(%rsp), %xmm0 + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $56, %rsp + movq 3760(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramLocalParameter4fARB), .-GL_PREFIX(ProgramLocalParameter4fARB) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramLocalParameter4fvARB) + .type GL_PREFIX(ProgramLocalParameter4fvARB), @function +GL_PREFIX(ProgramLocalParameter4fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3768(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3768(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3768(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3768(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramLocalParameter4fvARB), .-GL_PREFIX(ProgramLocalParameter4fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramStringARB) + .type GL_PREFIX(ProgramStringARB), @function +GL_PREFIX(ProgramStringARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3776(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3776(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3776(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3776(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramStringARB), .-GL_PREFIX(ProgramStringARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib1dARB) + .type GL_PREFIX(VertexAttrib1dARB), @function +GL_PREFIX(VertexAttrib1dARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3784(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3784(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3784(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3784(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib1dARB), .-GL_PREFIX(VertexAttrib1dARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib1dvARB) + .type GL_PREFIX(VertexAttrib1dvARB), @function +GL_PREFIX(VertexAttrib1dvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3792(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3792(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3792(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3792(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib1dvARB), .-GL_PREFIX(VertexAttrib1dvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib1fARB) + .type GL_PREFIX(VertexAttrib1fARB), @function +GL_PREFIX(VertexAttrib1fARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3800(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3800(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3800(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3800(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib1fARB), .-GL_PREFIX(VertexAttrib1fARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib1fvARB) + .type GL_PREFIX(VertexAttrib1fvARB), @function +GL_PREFIX(VertexAttrib1fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3808(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3808(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3808(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3808(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib1fvARB), .-GL_PREFIX(VertexAttrib1fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib1sARB) + .type GL_PREFIX(VertexAttrib1sARB), @function +GL_PREFIX(VertexAttrib1sARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3816(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3816(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3816(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3816(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib1sARB), .-GL_PREFIX(VertexAttrib1sARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib1svARB) + .type GL_PREFIX(VertexAttrib1svARB), @function +GL_PREFIX(VertexAttrib1svARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3824(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3824(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3824(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3824(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib1svARB), .-GL_PREFIX(VertexAttrib1svARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib2dARB) + .type GL_PREFIX(VertexAttrib2dARB), @function +GL_PREFIX(VertexAttrib2dARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3832(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3832(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3832(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3832(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib2dARB), .-GL_PREFIX(VertexAttrib2dARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib2dvARB) + .type GL_PREFIX(VertexAttrib2dvARB), @function +GL_PREFIX(VertexAttrib2dvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3840(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3840(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3840(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3840(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib2dvARB), .-GL_PREFIX(VertexAttrib2dvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib2fARB) + .type GL_PREFIX(VertexAttrib2fARB), @function +GL_PREFIX(VertexAttrib2fARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3848(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3848(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3848(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 3848(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib2fARB), .-GL_PREFIX(VertexAttrib2fARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib2fvARB) + .type GL_PREFIX(VertexAttrib2fvARB), @function +GL_PREFIX(VertexAttrib2fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3856(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3856(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3856(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3856(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib2fvARB), .-GL_PREFIX(VertexAttrib2fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib2sARB) + .type GL_PREFIX(VertexAttrib2sARB), @function +GL_PREFIX(VertexAttrib2sARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3864(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 3864(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3864(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 3864(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib2sARB), .-GL_PREFIX(VertexAttrib2sARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib2svARB) + .type GL_PREFIX(VertexAttrib2svARB), @function +GL_PREFIX(VertexAttrib2svARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3872(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3872(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3872(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3872(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib2svARB), .-GL_PREFIX(VertexAttrib2svARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib3dARB) + .type GL_PREFIX(VertexAttrib3dARB), @function +GL_PREFIX(VertexAttrib3dARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3880(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 3880(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3880(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 3880(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib3dARB), .-GL_PREFIX(VertexAttrib3dARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib3dvARB) + .type GL_PREFIX(VertexAttrib3dvARB), @function +GL_PREFIX(VertexAttrib3dvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3888(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3888(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3888(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3888(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib3dvARB), .-GL_PREFIX(VertexAttrib3dvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib3fARB) + .type GL_PREFIX(VertexAttrib3fARB), @function +GL_PREFIX(VertexAttrib3fARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3896(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 3896(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3896(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 3896(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib3fARB), .-GL_PREFIX(VertexAttrib3fARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib3fvARB) + .type GL_PREFIX(VertexAttrib3fvARB), @function +GL_PREFIX(VertexAttrib3fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3904(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3904(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3904(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3904(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib3fvARB), .-GL_PREFIX(VertexAttrib3fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib3sARB) + .type GL_PREFIX(VertexAttrib3sARB), @function +GL_PREFIX(VertexAttrib3sARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3912(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3912(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3912(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3912(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib3sARB), .-GL_PREFIX(VertexAttrib3sARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib3svARB) + .type GL_PREFIX(VertexAttrib3svARB), @function +GL_PREFIX(VertexAttrib3svARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3920(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3920(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3920(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3920(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib3svARB), .-GL_PREFIX(VertexAttrib3svARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4NbvARB) + .type GL_PREFIX(VertexAttrib4NbvARB), @function +GL_PREFIX(VertexAttrib4NbvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3928(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3928(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3928(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3928(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4NbvARB), .-GL_PREFIX(VertexAttrib4NbvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4NivARB) + .type GL_PREFIX(VertexAttrib4NivARB), @function +GL_PREFIX(VertexAttrib4NivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3936(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3936(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3936(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3936(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4NivARB), .-GL_PREFIX(VertexAttrib4NivARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4NsvARB) + .type GL_PREFIX(VertexAttrib4NsvARB), @function +GL_PREFIX(VertexAttrib4NsvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3944(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3944(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3944(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3944(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4NsvARB), .-GL_PREFIX(VertexAttrib4NsvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4NubARB) + .type GL_PREFIX(VertexAttrib4NubARB), @function +GL_PREFIX(VertexAttrib4NubARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3952(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3952(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3952(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 3952(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4NubARB), .-GL_PREFIX(VertexAttrib4NubARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4NubvARB) + .type GL_PREFIX(VertexAttrib4NubvARB), @function +GL_PREFIX(VertexAttrib4NubvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3960(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3960(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3960(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3960(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4NubvARB), .-GL_PREFIX(VertexAttrib4NubvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4NuivARB) + .type GL_PREFIX(VertexAttrib4NuivARB), @function +GL_PREFIX(VertexAttrib4NuivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3968(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3968(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3968(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3968(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4NuivARB), .-GL_PREFIX(VertexAttrib4NuivARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4NusvARB) + .type GL_PREFIX(VertexAttrib4NusvARB), @function +GL_PREFIX(VertexAttrib4NusvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3976(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3976(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3976(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3976(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4NusvARB), .-GL_PREFIX(VertexAttrib4NusvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4bvARB) + .type GL_PREFIX(VertexAttrib4bvARB), @function +GL_PREFIX(VertexAttrib4bvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3984(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 3984(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3984(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 3984(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4bvARB), .-GL_PREFIX(VertexAttrib4bvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4dARB) + .type GL_PREFIX(VertexAttrib4dARB), @function +GL_PREFIX(VertexAttrib4dARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 3992(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + movq %xmm3, 32(%rsp) + call _x86_64_get_dispatch@PLT + movq 32(%rsp), %xmm3 + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 3992(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 3992(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + movq %xmm3, 32(%rsp) + call _glapi_get_dispatch + movq 32(%rsp), %xmm3 + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 3992(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4dARB), .-GL_PREFIX(VertexAttrib4dARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4dvARB) + .type GL_PREFIX(VertexAttrib4dvARB), @function +GL_PREFIX(VertexAttrib4dvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4000(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4000(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4000(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4000(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4dvARB), .-GL_PREFIX(VertexAttrib4dvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4fARB) + .type GL_PREFIX(VertexAttrib4fARB), @function +GL_PREFIX(VertexAttrib4fARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4008(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + movq %xmm3, 32(%rsp) + call _x86_64_get_dispatch@PLT + movq 32(%rsp), %xmm3 + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 4008(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4008(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + movq %xmm3, 32(%rsp) + call _glapi_get_dispatch + movq 32(%rsp), %xmm3 + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 4008(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4fARB), .-GL_PREFIX(VertexAttrib4fARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4fvARB) + .type GL_PREFIX(VertexAttrib4fvARB), @function +GL_PREFIX(VertexAttrib4fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4016(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4016(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4016(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4016(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4fvARB), .-GL_PREFIX(VertexAttrib4fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4ivARB) + .type GL_PREFIX(VertexAttrib4ivARB), @function +GL_PREFIX(VertexAttrib4ivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4024(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4024(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4024(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4024(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4ivARB), .-GL_PREFIX(VertexAttrib4ivARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4sARB) + .type GL_PREFIX(VertexAttrib4sARB), @function +GL_PREFIX(VertexAttrib4sARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4032(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4032(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4032(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4032(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4sARB), .-GL_PREFIX(VertexAttrib4sARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4svARB) + .type GL_PREFIX(VertexAttrib4svARB), @function +GL_PREFIX(VertexAttrib4svARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4040(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4040(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4040(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4040(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4svARB), .-GL_PREFIX(VertexAttrib4svARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4ubvARB) + .type GL_PREFIX(VertexAttrib4ubvARB), @function +GL_PREFIX(VertexAttrib4ubvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4048(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4048(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4048(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4048(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4ubvARB), .-GL_PREFIX(VertexAttrib4ubvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4uivARB) + .type GL_PREFIX(VertexAttrib4uivARB), @function +GL_PREFIX(VertexAttrib4uivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4056(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4056(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4056(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4056(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4uivARB), .-GL_PREFIX(VertexAttrib4uivARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4usvARB) + .type GL_PREFIX(VertexAttrib4usvARB), @function +GL_PREFIX(VertexAttrib4usvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4064(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4064(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4064(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4064(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4usvARB), .-GL_PREFIX(VertexAttrib4usvARB) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribPointerARB) + .type GL_PREFIX(VertexAttribPointerARB), @function +GL_PREFIX(VertexAttribPointerARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4072(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4072(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4072(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4072(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribPointerARB), .-GL_PREFIX(VertexAttribPointerARB) + + .p2align 4,,15 + .globl GL_PREFIX(BindBufferARB) + .type GL_PREFIX(BindBufferARB), @function +GL_PREFIX(BindBufferARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4080(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4080(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4080(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4080(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BindBufferARB), .-GL_PREFIX(BindBufferARB) + + .p2align 4,,15 + .globl GL_PREFIX(BufferDataARB) + .type GL_PREFIX(BufferDataARB), @function +GL_PREFIX(BufferDataARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4088(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4088(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4088(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4088(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BufferDataARB), .-GL_PREFIX(BufferDataARB) + + .p2align 4,,15 + .globl GL_PREFIX(BufferSubDataARB) + .type GL_PREFIX(BufferSubDataARB), @function +GL_PREFIX(BufferSubDataARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4096(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4096(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4096(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4096(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BufferSubDataARB), .-GL_PREFIX(BufferSubDataARB) + + .p2align 4,,15 + .globl GL_PREFIX(DeleteBuffersARB) + .type GL_PREFIX(DeleteBuffersARB), @function +GL_PREFIX(DeleteBuffersARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4104(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4104(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4104(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4104(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DeleteBuffersARB), .-GL_PREFIX(DeleteBuffersARB) + + .p2align 4,,15 + .globl GL_PREFIX(GenBuffersARB) + .type GL_PREFIX(GenBuffersARB), @function +GL_PREFIX(GenBuffersARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4112(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4112(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4112(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4112(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GenBuffersARB), .-GL_PREFIX(GenBuffersARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetBufferParameterivARB) + .type GL_PREFIX(GetBufferParameterivARB), @function +GL_PREFIX(GetBufferParameterivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4120(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4120(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4120(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4120(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetBufferParameterivARB), .-GL_PREFIX(GetBufferParameterivARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetBufferPointervARB) + .type GL_PREFIX(GetBufferPointervARB), @function +GL_PREFIX(GetBufferPointervARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4128(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4128(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4128(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4128(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetBufferPointervARB), .-GL_PREFIX(GetBufferPointervARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetBufferSubDataARB) + .type GL_PREFIX(GetBufferSubDataARB), @function +GL_PREFIX(GetBufferSubDataARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4136(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4136(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4136(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4136(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetBufferSubDataARB), .-GL_PREFIX(GetBufferSubDataARB) + + .p2align 4,,15 + .globl GL_PREFIX(IsBufferARB) + .type GL_PREFIX(IsBufferARB), @function +GL_PREFIX(IsBufferARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4144(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4144(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4144(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4144(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IsBufferARB), .-GL_PREFIX(IsBufferARB) + + .p2align 4,,15 + .globl GL_PREFIX(MapBufferARB) + .type GL_PREFIX(MapBufferARB), @function +GL_PREFIX(MapBufferARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4152(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4152(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4152(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4152(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MapBufferARB), .-GL_PREFIX(MapBufferARB) + + .p2align 4,,15 + .globl GL_PREFIX(UnmapBufferARB) + .type GL_PREFIX(UnmapBufferARB), @function +GL_PREFIX(UnmapBufferARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4160(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4160(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4160(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4160(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(UnmapBufferARB), .-GL_PREFIX(UnmapBufferARB) + + .p2align 4,,15 + .globl GL_PREFIX(BeginQueryARB) + .type GL_PREFIX(BeginQueryARB), @function +GL_PREFIX(BeginQueryARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4168(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4168(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4168(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4168(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BeginQueryARB), .-GL_PREFIX(BeginQueryARB) + + .p2align 4,,15 + .globl GL_PREFIX(DeleteQueriesARB) + .type GL_PREFIX(DeleteQueriesARB), @function +GL_PREFIX(DeleteQueriesARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4176(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4176(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4176(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4176(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DeleteQueriesARB), .-GL_PREFIX(DeleteQueriesARB) + + .p2align 4,,15 + .globl GL_PREFIX(EndQueryARB) + .type GL_PREFIX(EndQueryARB), @function +GL_PREFIX(EndQueryARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4184(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4184(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4184(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4184(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EndQueryARB), .-GL_PREFIX(EndQueryARB) + + .p2align 4,,15 + .globl GL_PREFIX(GenQueriesARB) + .type GL_PREFIX(GenQueriesARB), @function +GL_PREFIX(GenQueriesARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4192(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4192(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4192(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4192(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GenQueriesARB), .-GL_PREFIX(GenQueriesARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetQueryObjectivARB) + .type GL_PREFIX(GetQueryObjectivARB), @function +GL_PREFIX(GetQueryObjectivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4200(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4200(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4200(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4200(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetQueryObjectivARB), .-GL_PREFIX(GetQueryObjectivARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetQueryObjectuivARB) + .type GL_PREFIX(GetQueryObjectuivARB), @function +GL_PREFIX(GetQueryObjectuivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4208(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4208(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4208(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4208(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetQueryObjectuivARB), .-GL_PREFIX(GetQueryObjectuivARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetQueryivARB) + .type GL_PREFIX(GetQueryivARB), @function +GL_PREFIX(GetQueryivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4216(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4216(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4216(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4216(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetQueryivARB), .-GL_PREFIX(GetQueryivARB) + + .p2align 4,,15 + .globl GL_PREFIX(IsQueryARB) + .type GL_PREFIX(IsQueryARB), @function +GL_PREFIX(IsQueryARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4224(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4224(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4224(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4224(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IsQueryARB), .-GL_PREFIX(IsQueryARB) + + .p2align 4,,15 + .globl GL_PREFIX(AttachObjectARB) + .type GL_PREFIX(AttachObjectARB), @function +GL_PREFIX(AttachObjectARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4232(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4232(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4232(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4232(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(AttachObjectARB), .-GL_PREFIX(AttachObjectARB) + + .p2align 4,,15 + .globl GL_PREFIX(CompileShaderARB) + .type GL_PREFIX(CompileShaderARB), @function +GL_PREFIX(CompileShaderARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4240(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4240(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4240(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4240(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CompileShaderARB), .-GL_PREFIX(CompileShaderARB) + + .p2align 4,,15 + .globl GL_PREFIX(CreateProgramObjectARB) + .type GL_PREFIX(CreateProgramObjectARB), @function +GL_PREFIX(CreateProgramObjectARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4248(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 4248(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4248(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 4248(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CreateProgramObjectARB), .-GL_PREFIX(CreateProgramObjectARB) + + .p2align 4,,15 + .globl GL_PREFIX(CreateShaderObjectARB) + .type GL_PREFIX(CreateShaderObjectARB), @function +GL_PREFIX(CreateShaderObjectARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4256(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4256(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4256(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4256(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CreateShaderObjectARB), .-GL_PREFIX(CreateShaderObjectARB) + + .p2align 4,,15 + .globl GL_PREFIX(DeleteObjectARB) + .type GL_PREFIX(DeleteObjectARB), @function +GL_PREFIX(DeleteObjectARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4264(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4264(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4264(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4264(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DeleteObjectARB), .-GL_PREFIX(DeleteObjectARB) + + .p2align 4,,15 + .globl GL_PREFIX(DetachObjectARB) + .type GL_PREFIX(DetachObjectARB), @function +GL_PREFIX(DetachObjectARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4272(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4272(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4272(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4272(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DetachObjectARB), .-GL_PREFIX(DetachObjectARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetActiveUniformARB) + .type GL_PREFIX(GetActiveUniformARB), @function +GL_PREFIX(GetActiveUniformARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4280(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4280(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4280(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4280(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetActiveUniformARB), .-GL_PREFIX(GetActiveUniformARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetAttachedObjectsARB) + .type GL_PREFIX(GetAttachedObjectsARB), @function +GL_PREFIX(GetAttachedObjectsARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4288(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4288(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4288(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4288(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetAttachedObjectsARB), .-GL_PREFIX(GetAttachedObjectsARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetHandleARB) + .type GL_PREFIX(GetHandleARB), @function +GL_PREFIX(GetHandleARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4296(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4296(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4296(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4296(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetHandleARB), .-GL_PREFIX(GetHandleARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetInfoLogARB) + .type GL_PREFIX(GetInfoLogARB), @function +GL_PREFIX(GetInfoLogARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4304(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4304(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4304(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4304(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetInfoLogARB), .-GL_PREFIX(GetInfoLogARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetObjectParameterfvARB) + .type GL_PREFIX(GetObjectParameterfvARB), @function +GL_PREFIX(GetObjectParameterfvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4312(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4312(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4312(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4312(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetObjectParameterfvARB), .-GL_PREFIX(GetObjectParameterfvARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetObjectParameterivARB) + .type GL_PREFIX(GetObjectParameterivARB), @function +GL_PREFIX(GetObjectParameterivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4320(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4320(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4320(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4320(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetObjectParameterivARB), .-GL_PREFIX(GetObjectParameterivARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetShaderSourceARB) + .type GL_PREFIX(GetShaderSourceARB), @function +GL_PREFIX(GetShaderSourceARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4328(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4328(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4328(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4328(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetShaderSourceARB), .-GL_PREFIX(GetShaderSourceARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetUniformLocationARB) + .type GL_PREFIX(GetUniformLocationARB), @function +GL_PREFIX(GetUniformLocationARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4336(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4336(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4336(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4336(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetUniformLocationARB), .-GL_PREFIX(GetUniformLocationARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetUniformfvARB) + .type GL_PREFIX(GetUniformfvARB), @function +GL_PREFIX(GetUniformfvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4344(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4344(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4344(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4344(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetUniformfvARB), .-GL_PREFIX(GetUniformfvARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetUniformivARB) + .type GL_PREFIX(GetUniformivARB), @function +GL_PREFIX(GetUniformivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4352(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4352(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4352(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4352(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetUniformivARB), .-GL_PREFIX(GetUniformivARB) + + .p2align 4,,15 + .globl GL_PREFIX(LinkProgramARB) + .type GL_PREFIX(LinkProgramARB), @function +GL_PREFIX(LinkProgramARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4360(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4360(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4360(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4360(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LinkProgramARB), .-GL_PREFIX(LinkProgramARB) + + .p2align 4,,15 + .globl GL_PREFIX(ShaderSourceARB) + .type GL_PREFIX(ShaderSourceARB), @function +GL_PREFIX(ShaderSourceARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4368(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4368(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4368(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4368(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ShaderSourceARB), .-GL_PREFIX(ShaderSourceARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform1fARB) + .type GL_PREFIX(Uniform1fARB), @function +GL_PREFIX(Uniform1fARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4376(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 4376(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4376(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 4376(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform1fARB), .-GL_PREFIX(Uniform1fARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform1fvARB) + .type GL_PREFIX(Uniform1fvARB), @function +GL_PREFIX(Uniform1fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4384(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4384(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4384(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4384(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform1fvARB), .-GL_PREFIX(Uniform1fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform1iARB) + .type GL_PREFIX(Uniform1iARB), @function +GL_PREFIX(Uniform1iARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4392(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4392(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4392(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4392(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform1iARB), .-GL_PREFIX(Uniform1iARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform1ivARB) + .type GL_PREFIX(Uniform1ivARB), @function +GL_PREFIX(Uniform1ivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4400(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4400(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4400(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4400(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform1ivARB), .-GL_PREFIX(Uniform1ivARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform2fARB) + .type GL_PREFIX(Uniform2fARB), @function +GL_PREFIX(Uniform2fARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4408(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 4408(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4408(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 4408(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform2fARB), .-GL_PREFIX(Uniform2fARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform2fvARB) + .type GL_PREFIX(Uniform2fvARB), @function +GL_PREFIX(Uniform2fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4416(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4416(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4416(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4416(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform2fvARB), .-GL_PREFIX(Uniform2fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform2iARB) + .type GL_PREFIX(Uniform2iARB), @function +GL_PREFIX(Uniform2iARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4424(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4424(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4424(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4424(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform2iARB), .-GL_PREFIX(Uniform2iARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform2ivARB) + .type GL_PREFIX(Uniform2ivARB), @function +GL_PREFIX(Uniform2ivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4432(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4432(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4432(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4432(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform2ivARB), .-GL_PREFIX(Uniform2ivARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform3fARB) + .type GL_PREFIX(Uniform3fARB), @function +GL_PREFIX(Uniform3fARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4440(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 4440(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4440(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 4440(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform3fARB), .-GL_PREFIX(Uniform3fARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform3fvARB) + .type GL_PREFIX(Uniform3fvARB), @function +GL_PREFIX(Uniform3fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4448(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4448(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4448(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4448(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform3fvARB), .-GL_PREFIX(Uniform3fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform3iARB) + .type GL_PREFIX(Uniform3iARB), @function +GL_PREFIX(Uniform3iARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4456(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4456(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4456(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4456(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform3iARB), .-GL_PREFIX(Uniform3iARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform3ivARB) + .type GL_PREFIX(Uniform3ivARB), @function +GL_PREFIX(Uniform3ivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4464(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4464(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4464(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4464(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform3ivARB), .-GL_PREFIX(Uniform3ivARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform4fARB) + .type GL_PREFIX(Uniform4fARB), @function +GL_PREFIX(Uniform4fARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4472(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + movq %xmm3, 32(%rsp) + call _x86_64_get_dispatch@PLT + movq 32(%rsp), %xmm3 + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 4472(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4472(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + movq %xmm3, 32(%rsp) + call _glapi_get_dispatch + movq 32(%rsp), %xmm3 + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 4472(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform4fARB), .-GL_PREFIX(Uniform4fARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform4fvARB) + .type GL_PREFIX(Uniform4fvARB), @function +GL_PREFIX(Uniform4fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4480(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4480(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4480(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4480(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform4fvARB), .-GL_PREFIX(Uniform4fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform4iARB) + .type GL_PREFIX(Uniform4iARB), @function +GL_PREFIX(Uniform4iARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4488(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4488(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4488(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4488(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform4iARB), .-GL_PREFIX(Uniform4iARB) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform4ivARB) + .type GL_PREFIX(Uniform4ivARB), @function +GL_PREFIX(Uniform4ivARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4496(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4496(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4496(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4496(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform4ivARB), .-GL_PREFIX(Uniform4ivARB) + + .p2align 4,,15 + .globl GL_PREFIX(UniformMatrix2fvARB) + .type GL_PREFIX(UniformMatrix2fvARB), @function +GL_PREFIX(UniformMatrix2fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4504(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4504(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4504(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4504(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(UniformMatrix2fvARB), .-GL_PREFIX(UniformMatrix2fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(UniformMatrix3fvARB) + .type GL_PREFIX(UniformMatrix3fvARB), @function +GL_PREFIX(UniformMatrix3fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4512(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4512(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4512(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4512(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(UniformMatrix3fvARB), .-GL_PREFIX(UniformMatrix3fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(UniformMatrix4fvARB) + .type GL_PREFIX(UniformMatrix4fvARB), @function +GL_PREFIX(UniformMatrix4fvARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4520(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4520(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4520(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4520(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(UniformMatrix4fvARB), .-GL_PREFIX(UniformMatrix4fvARB) + + .p2align 4,,15 + .globl GL_PREFIX(UseProgramObjectARB) + .type GL_PREFIX(UseProgramObjectARB), @function +GL_PREFIX(UseProgramObjectARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4528(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4528(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4528(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4528(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(UseProgramObjectARB), .-GL_PREFIX(UseProgramObjectARB) + + .p2align 4,,15 + .globl GL_PREFIX(ValidateProgramARB) + .type GL_PREFIX(ValidateProgramARB), @function +GL_PREFIX(ValidateProgramARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4536(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4536(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4536(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4536(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ValidateProgramARB), .-GL_PREFIX(ValidateProgramARB) + + .p2align 4,,15 + .globl GL_PREFIX(BindAttribLocationARB) + .type GL_PREFIX(BindAttribLocationARB), @function +GL_PREFIX(BindAttribLocationARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4544(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4544(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4544(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4544(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BindAttribLocationARB), .-GL_PREFIX(BindAttribLocationARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetActiveAttribARB) + .type GL_PREFIX(GetActiveAttribARB), @function +GL_PREFIX(GetActiveAttribARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4552(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4552(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4552(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4552(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetActiveAttribARB), .-GL_PREFIX(GetActiveAttribARB) + + .p2align 4,,15 + .globl GL_PREFIX(GetAttribLocationARB) + .type GL_PREFIX(GetAttribLocationARB), @function +GL_PREFIX(GetAttribLocationARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4560(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4560(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4560(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4560(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetAttribLocationARB), .-GL_PREFIX(GetAttribLocationARB) + + .p2align 4,,15 + .globl GL_PREFIX(DrawBuffersARB) + .type GL_PREFIX(DrawBuffersARB), @function +GL_PREFIX(DrawBuffersARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4568(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4568(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4568(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4568(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DrawBuffersARB), .-GL_PREFIX(DrawBuffersARB) + + .p2align 4,,15 + .globl GL_PREFIX(DrawArraysInstancedARB) + .type GL_PREFIX(DrawArraysInstancedARB), @function +GL_PREFIX(DrawArraysInstancedARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4576(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4576(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4576(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4576(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DrawArraysInstancedARB), .-GL_PREFIX(DrawArraysInstancedARB) + + .p2align 4,,15 + .globl GL_PREFIX(DrawElementsInstancedARB) + .type GL_PREFIX(DrawElementsInstancedARB), @function +GL_PREFIX(DrawElementsInstancedARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4584(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4584(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4584(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4584(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DrawElementsInstancedARB), .-GL_PREFIX(DrawElementsInstancedARB) + + .p2align 4,,15 + .globl GL_PREFIX(RenderbufferStorageMultisample) + .type GL_PREFIX(RenderbufferStorageMultisample), @function +GL_PREFIX(RenderbufferStorageMultisample): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4592(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4592(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4592(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4592(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RenderbufferStorageMultisample), .-GL_PREFIX(RenderbufferStorageMultisample) + + .p2align 4,,15 + .globl GL_PREFIX(FramebufferTextureARB) + .type GL_PREFIX(FramebufferTextureARB), @function +GL_PREFIX(FramebufferTextureARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4600(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4600(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4600(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4600(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FramebufferTextureARB), .-GL_PREFIX(FramebufferTextureARB) + + .p2align 4,,15 + .globl GL_PREFIX(FramebufferTextureFaceARB) + .type GL_PREFIX(FramebufferTextureFaceARB), @function +GL_PREFIX(FramebufferTextureFaceARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4608(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4608(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4608(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4608(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FramebufferTextureFaceARB), .-GL_PREFIX(FramebufferTextureFaceARB) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramParameteriARB) + .type GL_PREFIX(ProgramParameteriARB), @function +GL_PREFIX(ProgramParameteriARB): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4616(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4616(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4616(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4616(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramParameteriARB), .-GL_PREFIX(ProgramParameteriARB) + + .p2align 4,,15 + .globl GL_PREFIX(FlushMappedBufferRange) + .type GL_PREFIX(FlushMappedBufferRange), @function +GL_PREFIX(FlushMappedBufferRange): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4624(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4624(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4624(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4624(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FlushMappedBufferRange), .-GL_PREFIX(FlushMappedBufferRange) + + .p2align 4,,15 + .globl GL_PREFIX(MapBufferRange) + .type GL_PREFIX(MapBufferRange), @function +GL_PREFIX(MapBufferRange): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4632(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4632(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4632(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4632(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MapBufferRange), .-GL_PREFIX(MapBufferRange) + + .p2align 4,,15 + .globl GL_PREFIX(BindVertexArray) + .type GL_PREFIX(BindVertexArray), @function +GL_PREFIX(BindVertexArray): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4640(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4640(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4640(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4640(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BindVertexArray), .-GL_PREFIX(BindVertexArray) + + .p2align 4,,15 + .globl GL_PREFIX(GenVertexArrays) + .type GL_PREFIX(GenVertexArrays), @function +GL_PREFIX(GenVertexArrays): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4648(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4648(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4648(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4648(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GenVertexArrays), .-GL_PREFIX(GenVertexArrays) + + .p2align 4,,15 + .globl GL_PREFIX(CopyBufferSubData) + .type GL_PREFIX(CopyBufferSubData), @function +GL_PREFIX(CopyBufferSubData): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4656(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4656(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4656(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4656(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CopyBufferSubData), .-GL_PREFIX(CopyBufferSubData) + + .p2align 4,,15 + .globl GL_PREFIX(ClientWaitSync) + .type GL_PREFIX(ClientWaitSync), @function +GL_PREFIX(ClientWaitSync): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4664(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4664(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4664(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4664(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClientWaitSync), .-GL_PREFIX(ClientWaitSync) + + .p2align 4,,15 + .globl GL_PREFIX(DeleteSync) + .type GL_PREFIX(DeleteSync), @function +GL_PREFIX(DeleteSync): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4672(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4672(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4672(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4672(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DeleteSync), .-GL_PREFIX(DeleteSync) + + .p2align 4,,15 + .globl GL_PREFIX(FenceSync) + .type GL_PREFIX(FenceSync), @function +GL_PREFIX(FenceSync): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4680(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4680(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4680(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4680(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FenceSync), .-GL_PREFIX(FenceSync) + + .p2align 4,,15 + .globl GL_PREFIX(GetInteger64v) + .type GL_PREFIX(GetInteger64v), @function +GL_PREFIX(GetInteger64v): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4688(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4688(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4688(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4688(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetInteger64v), .-GL_PREFIX(GetInteger64v) + + .p2align 4,,15 + .globl GL_PREFIX(GetSynciv) + .type GL_PREFIX(GetSynciv), @function +GL_PREFIX(GetSynciv): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4696(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4696(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4696(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4696(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetSynciv), .-GL_PREFIX(GetSynciv) + + .p2align 4,,15 + .globl GL_PREFIX(IsSync) + .type GL_PREFIX(IsSync), @function +GL_PREFIX(IsSync): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4704(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4704(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4704(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4704(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IsSync), .-GL_PREFIX(IsSync) + + .p2align 4,,15 + .globl GL_PREFIX(WaitSync) + .type GL_PREFIX(WaitSync), @function +GL_PREFIX(WaitSync): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4712(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4712(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4712(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4712(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WaitSync), .-GL_PREFIX(WaitSync) + + .p2align 4,,15 + .globl GL_PREFIX(DrawElementsBaseVertex) + .type GL_PREFIX(DrawElementsBaseVertex), @function +GL_PREFIX(DrawElementsBaseVertex): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4720(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4720(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4720(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4720(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DrawElementsBaseVertex), .-GL_PREFIX(DrawElementsBaseVertex) + + .p2align 4,,15 + .globl GL_PREFIX(DrawRangeElementsBaseVertex) + .type GL_PREFIX(DrawRangeElementsBaseVertex), @function +GL_PREFIX(DrawRangeElementsBaseVertex): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4728(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4728(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4728(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4728(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DrawRangeElementsBaseVertex), .-GL_PREFIX(DrawRangeElementsBaseVertex) + + .p2align 4,,15 + .globl GL_PREFIX(MultiDrawElementsBaseVertex) + .type GL_PREFIX(MultiDrawElementsBaseVertex), @function +GL_PREFIX(MultiDrawElementsBaseVertex): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4736(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4736(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4736(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4736(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiDrawElementsBaseVertex), .-GL_PREFIX(MultiDrawElementsBaseVertex) + + .p2align 4,,15 + .globl GL_PREFIX(BindTransformFeedback) + .type GL_PREFIX(BindTransformFeedback), @function +GL_PREFIX(BindTransformFeedback): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4744(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4744(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4744(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4744(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BindTransformFeedback), .-GL_PREFIX(BindTransformFeedback) + + .p2align 4,,15 + .globl GL_PREFIX(DeleteTransformFeedbacks) + .type GL_PREFIX(DeleteTransformFeedbacks), @function +GL_PREFIX(DeleteTransformFeedbacks): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4752(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4752(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4752(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4752(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DeleteTransformFeedbacks), .-GL_PREFIX(DeleteTransformFeedbacks) + + .p2align 4,,15 + .globl GL_PREFIX(DrawTransformFeedback) + .type GL_PREFIX(DrawTransformFeedback), @function +GL_PREFIX(DrawTransformFeedback): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4760(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4760(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4760(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4760(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DrawTransformFeedback), .-GL_PREFIX(DrawTransformFeedback) + + .p2align 4,,15 + .globl GL_PREFIX(GenTransformFeedbacks) + .type GL_PREFIX(GenTransformFeedbacks), @function +GL_PREFIX(GenTransformFeedbacks): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4768(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4768(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4768(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4768(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GenTransformFeedbacks), .-GL_PREFIX(GenTransformFeedbacks) + + .p2align 4,,15 + .globl GL_PREFIX(IsTransformFeedback) + .type GL_PREFIX(IsTransformFeedback), @function +GL_PREFIX(IsTransformFeedback): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4776(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4776(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4776(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4776(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IsTransformFeedback), .-GL_PREFIX(IsTransformFeedback) + + .p2align 4,,15 + .globl GL_PREFIX(PauseTransformFeedback) + .type GL_PREFIX(PauseTransformFeedback), @function +GL_PREFIX(PauseTransformFeedback): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4784(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 4784(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4784(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 4784(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PauseTransformFeedback), .-GL_PREFIX(PauseTransformFeedback) + + .p2align 4,,15 + .globl GL_PREFIX(ResumeTransformFeedback) + .type GL_PREFIX(ResumeTransformFeedback), @function +GL_PREFIX(ResumeTransformFeedback): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4792(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 4792(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4792(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 4792(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ResumeTransformFeedback), .-GL_PREFIX(ResumeTransformFeedback) + + .p2align 4,,15 + .globl GL_PREFIX(ClearDepthf) + .type GL_PREFIX(ClearDepthf), @function +GL_PREFIX(ClearDepthf): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4800(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4800(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4800(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4800(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClearDepthf), .-GL_PREFIX(ClearDepthf) + + .p2align 4,,15 + .globl GL_PREFIX(DepthRangef) + .type GL_PREFIX(DepthRangef), @function +GL_PREFIX(DepthRangef): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4808(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4808(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4808(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4808(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DepthRangef), .-GL_PREFIX(DepthRangef) + + .p2align 4,,15 + .globl GL_PREFIX(GetShaderPrecisionFormat) + .type GL_PREFIX(GetShaderPrecisionFormat), @function +GL_PREFIX(GetShaderPrecisionFormat): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4816(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4816(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4816(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4816(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetShaderPrecisionFormat), .-GL_PREFIX(GetShaderPrecisionFormat) + + .p2align 4,,15 + .globl GL_PREFIX(ReleaseShaderCompiler) + .type GL_PREFIX(ReleaseShaderCompiler), @function +GL_PREFIX(ReleaseShaderCompiler): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4824(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 4824(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4824(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 4824(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ReleaseShaderCompiler), .-GL_PREFIX(ReleaseShaderCompiler) + + .p2align 4,,15 + .globl GL_PREFIX(ShaderBinary) + .type GL_PREFIX(ShaderBinary), @function +GL_PREFIX(ShaderBinary): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4832(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4832(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4832(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4832(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ShaderBinary), .-GL_PREFIX(ShaderBinary) + + .p2align 4,,15 + .globl GL_PREFIX(PolygonOffsetEXT) + .type GL_PREFIX(PolygonOffsetEXT), @function +GL_PREFIX(PolygonOffsetEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4840(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 4840(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4840(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 4840(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PolygonOffsetEXT), .-GL_PREFIX(PolygonOffsetEXT) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_606) + .type GL_PREFIX(_dispatch_stub_606), @function + HIDDEN(GL_PREFIX(_dispatch_stub_606)) +GL_PREFIX(_dispatch_stub_606): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4848(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4848(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4848(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4848(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_606), .-GL_PREFIX(_dispatch_stub_606) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_607) + .type GL_PREFIX(_dispatch_stub_607), @function + HIDDEN(GL_PREFIX(_dispatch_stub_607)) +GL_PREFIX(_dispatch_stub_607): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4856(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4856(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4856(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4856(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_607), .-GL_PREFIX(_dispatch_stub_607) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_608) + .type GL_PREFIX(_dispatch_stub_608), @function + HIDDEN(GL_PREFIX(_dispatch_stub_608)) +GL_PREFIX(_dispatch_stub_608): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4864(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 4864(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4864(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 4864(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_608), .-GL_PREFIX(_dispatch_stub_608) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_609) + .type GL_PREFIX(_dispatch_stub_609), @function + HIDDEN(GL_PREFIX(_dispatch_stub_609)) +GL_PREFIX(_dispatch_stub_609): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4872(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4872(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4872(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4872(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_609), .-GL_PREFIX(_dispatch_stub_609) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_610) + .type GL_PREFIX(_dispatch_stub_610), @function + HIDDEN(GL_PREFIX(_dispatch_stub_610)) +GL_PREFIX(_dispatch_stub_610): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4880(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4880(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4880(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4880(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_610), .-GL_PREFIX(_dispatch_stub_610) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_611) + .type GL_PREFIX(_dispatch_stub_611), @function + HIDDEN(GL_PREFIX(_dispatch_stub_611)) +GL_PREFIX(_dispatch_stub_611): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4888(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4888(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4888(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4888(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_611), .-GL_PREFIX(_dispatch_stub_611) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_612) + .type GL_PREFIX(_dispatch_stub_612), @function + HIDDEN(GL_PREFIX(_dispatch_stub_612)) +GL_PREFIX(_dispatch_stub_612): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4896(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4896(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4896(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4896(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_612), .-GL_PREFIX(_dispatch_stub_612) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_613) + .type GL_PREFIX(_dispatch_stub_613), @function + HIDDEN(GL_PREFIX(_dispatch_stub_613)) +GL_PREFIX(_dispatch_stub_613): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4904(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 4904(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4904(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 4904(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_613), .-GL_PREFIX(_dispatch_stub_613) + + .p2align 4,,15 + .globl GL_PREFIX(ColorPointerEXT) + .type GL_PREFIX(ColorPointerEXT), @function +GL_PREFIX(ColorPointerEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4912(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4912(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4912(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4912(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ColorPointerEXT), .-GL_PREFIX(ColorPointerEXT) + + .p2align 4,,15 + .globl GL_PREFIX(EdgeFlagPointerEXT) + .type GL_PREFIX(EdgeFlagPointerEXT), @function +GL_PREFIX(EdgeFlagPointerEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4920(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4920(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4920(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4920(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EdgeFlagPointerEXT), .-GL_PREFIX(EdgeFlagPointerEXT) + + .p2align 4,,15 + .globl GL_PREFIX(IndexPointerEXT) + .type GL_PREFIX(IndexPointerEXT), @function +GL_PREFIX(IndexPointerEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4928(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4928(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4928(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4928(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IndexPointerEXT), .-GL_PREFIX(IndexPointerEXT) + + .p2align 4,,15 + .globl GL_PREFIX(NormalPointerEXT) + .type GL_PREFIX(NormalPointerEXT), @function +GL_PREFIX(NormalPointerEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4936(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4936(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4936(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4936(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(NormalPointerEXT), .-GL_PREFIX(NormalPointerEXT) + + .p2align 4,,15 + .globl GL_PREFIX(TexCoordPointerEXT) + .type GL_PREFIX(TexCoordPointerEXT), @function +GL_PREFIX(TexCoordPointerEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4944(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4944(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4944(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4944(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexCoordPointerEXT), .-GL_PREFIX(TexCoordPointerEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexPointerEXT) + .type GL_PREFIX(VertexPointerEXT), @function +GL_PREFIX(VertexPointerEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4952(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4952(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4952(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 4952(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexPointerEXT), .-GL_PREFIX(VertexPointerEXT) + + .p2align 4,,15 + .globl GL_PREFIX(PointParameterfEXT) + .type GL_PREFIX(PointParameterfEXT), @function +GL_PREFIX(PointParameterfEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4960(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 4960(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4960(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 4960(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PointParameterfEXT), .-GL_PREFIX(PointParameterfEXT) + + .p2align 4,,15 + .globl GL_PREFIX(PointParameterfvEXT) + .type GL_PREFIX(PointParameterfvEXT), @function +GL_PREFIX(PointParameterfvEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4968(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4968(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4968(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4968(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PointParameterfvEXT), .-GL_PREFIX(PointParameterfvEXT) + + .p2align 4,,15 + .globl GL_PREFIX(LockArraysEXT) + .type GL_PREFIX(LockArraysEXT), @function +GL_PREFIX(LockArraysEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4976(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 4976(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4976(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 4976(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LockArraysEXT), .-GL_PREFIX(LockArraysEXT) + + .p2align 4,,15 + .globl GL_PREFIX(UnlockArraysEXT) + .type GL_PREFIX(UnlockArraysEXT), @function +GL_PREFIX(UnlockArraysEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4984(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 4984(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4984(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 4984(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(UnlockArraysEXT), .-GL_PREFIX(UnlockArraysEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3bEXT) + .type GL_PREFIX(SecondaryColor3bEXT), @function +GL_PREFIX(SecondaryColor3bEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 4992(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 4992(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 4992(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 4992(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3bEXT), .-GL_PREFIX(SecondaryColor3bEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3bvEXT) + .type GL_PREFIX(SecondaryColor3bvEXT), @function +GL_PREFIX(SecondaryColor3bvEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5000(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5000(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5000(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5000(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3bvEXT), .-GL_PREFIX(SecondaryColor3bvEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3dEXT) + .type GL_PREFIX(SecondaryColor3dEXT), @function +GL_PREFIX(SecondaryColor3dEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5008(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 5008(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5008(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 5008(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3dEXT), .-GL_PREFIX(SecondaryColor3dEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3dvEXT) + .type GL_PREFIX(SecondaryColor3dvEXT), @function +GL_PREFIX(SecondaryColor3dvEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5016(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5016(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5016(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5016(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3dvEXT), .-GL_PREFIX(SecondaryColor3dvEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3fEXT) + .type GL_PREFIX(SecondaryColor3fEXT), @function +GL_PREFIX(SecondaryColor3fEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5024(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 5024(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5024(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 5024(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3fEXT), .-GL_PREFIX(SecondaryColor3fEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3fvEXT) + .type GL_PREFIX(SecondaryColor3fvEXT), @function +GL_PREFIX(SecondaryColor3fvEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5032(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5032(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5032(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5032(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3fvEXT), .-GL_PREFIX(SecondaryColor3fvEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3iEXT) + .type GL_PREFIX(SecondaryColor3iEXT), @function +GL_PREFIX(SecondaryColor3iEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5040(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5040(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5040(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5040(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3iEXT), .-GL_PREFIX(SecondaryColor3iEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3ivEXT) + .type GL_PREFIX(SecondaryColor3ivEXT), @function +GL_PREFIX(SecondaryColor3ivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5048(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5048(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5048(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5048(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3ivEXT), .-GL_PREFIX(SecondaryColor3ivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3sEXT) + .type GL_PREFIX(SecondaryColor3sEXT), @function +GL_PREFIX(SecondaryColor3sEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5056(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5056(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5056(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5056(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3sEXT), .-GL_PREFIX(SecondaryColor3sEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3svEXT) + .type GL_PREFIX(SecondaryColor3svEXT), @function +GL_PREFIX(SecondaryColor3svEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5064(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5064(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5064(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5064(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3svEXT), .-GL_PREFIX(SecondaryColor3svEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3ubEXT) + .type GL_PREFIX(SecondaryColor3ubEXT), @function +GL_PREFIX(SecondaryColor3ubEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5072(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5072(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5072(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5072(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3ubEXT), .-GL_PREFIX(SecondaryColor3ubEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3ubvEXT) + .type GL_PREFIX(SecondaryColor3ubvEXT), @function +GL_PREFIX(SecondaryColor3ubvEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5080(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5080(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5080(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5080(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3ubvEXT), .-GL_PREFIX(SecondaryColor3ubvEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3uiEXT) + .type GL_PREFIX(SecondaryColor3uiEXT), @function +GL_PREFIX(SecondaryColor3uiEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5088(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5088(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5088(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5088(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3uiEXT), .-GL_PREFIX(SecondaryColor3uiEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3uivEXT) + .type GL_PREFIX(SecondaryColor3uivEXT), @function +GL_PREFIX(SecondaryColor3uivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5096(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5096(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5096(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5096(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3uivEXT), .-GL_PREFIX(SecondaryColor3uivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3usEXT) + .type GL_PREFIX(SecondaryColor3usEXT), @function +GL_PREFIX(SecondaryColor3usEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5104(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5104(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5104(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5104(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3usEXT), .-GL_PREFIX(SecondaryColor3usEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColor3usvEXT) + .type GL_PREFIX(SecondaryColor3usvEXT), @function +GL_PREFIX(SecondaryColor3usvEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5112(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5112(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5112(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5112(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColor3usvEXT), .-GL_PREFIX(SecondaryColor3usvEXT) + + .p2align 4,,15 + .globl GL_PREFIX(SecondaryColorPointerEXT) + .type GL_PREFIX(SecondaryColorPointerEXT), @function +GL_PREFIX(SecondaryColorPointerEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5120(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5120(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5120(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5120(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SecondaryColorPointerEXT), .-GL_PREFIX(SecondaryColorPointerEXT) + + .p2align 4,,15 + .globl GL_PREFIX(MultiDrawArraysEXT) + .type GL_PREFIX(MultiDrawArraysEXT), @function +GL_PREFIX(MultiDrawArraysEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5128(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5128(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5128(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5128(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiDrawArraysEXT), .-GL_PREFIX(MultiDrawArraysEXT) + + .p2align 4,,15 + .globl GL_PREFIX(MultiDrawElementsEXT) + .type GL_PREFIX(MultiDrawElementsEXT), @function +GL_PREFIX(MultiDrawElementsEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5136(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5136(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5136(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5136(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(MultiDrawElementsEXT), .-GL_PREFIX(MultiDrawElementsEXT) + + .p2align 4,,15 + .globl GL_PREFIX(FogCoordPointerEXT) + .type GL_PREFIX(FogCoordPointerEXT), @function +GL_PREFIX(FogCoordPointerEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5144(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5144(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5144(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5144(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FogCoordPointerEXT), .-GL_PREFIX(FogCoordPointerEXT) + + .p2align 4,,15 + .globl GL_PREFIX(FogCoorddEXT) + .type GL_PREFIX(FogCoorddEXT), @function +GL_PREFIX(FogCoorddEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5152(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $8, %rsp + movq %xmm0, (%rsp) + call _x86_64_get_dispatch@PLT + movq (%rsp), %xmm0 + addq $8, %rsp + movq 5152(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5152(%rax), %r11 + jmp *%r11 +1: + subq $8, %rsp + movq %xmm0, (%rsp) + call _glapi_get_dispatch + movq (%rsp), %xmm0 + addq $8, %rsp + movq 5152(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FogCoorddEXT), .-GL_PREFIX(FogCoorddEXT) + + .p2align 4,,15 + .globl GL_PREFIX(FogCoorddvEXT) + .type GL_PREFIX(FogCoorddvEXT), @function +GL_PREFIX(FogCoorddvEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5160(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5160(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5160(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5160(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FogCoorddvEXT), .-GL_PREFIX(FogCoorddvEXT) + + .p2align 4,,15 + .globl GL_PREFIX(FogCoordfEXT) + .type GL_PREFIX(FogCoordfEXT), @function +GL_PREFIX(FogCoordfEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5168(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $8, %rsp + movq %xmm0, (%rsp) + call _x86_64_get_dispatch@PLT + movq (%rsp), %xmm0 + addq $8, %rsp + movq 5168(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5168(%rax), %r11 + jmp *%r11 +1: + subq $8, %rsp + movq %xmm0, (%rsp) + call _glapi_get_dispatch + movq (%rsp), %xmm0 + addq $8, %rsp + movq 5168(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FogCoordfEXT), .-GL_PREFIX(FogCoordfEXT) + + .p2align 4,,15 + .globl GL_PREFIX(FogCoordfvEXT) + .type GL_PREFIX(FogCoordfvEXT), @function +GL_PREFIX(FogCoordfvEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5176(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5176(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5176(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5176(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FogCoordfvEXT), .-GL_PREFIX(FogCoordfvEXT) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_648) + .type GL_PREFIX(_dispatch_stub_648), @function + HIDDEN(GL_PREFIX(_dispatch_stub_648)) +GL_PREFIX(_dispatch_stub_648): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5184(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5184(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5184(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5184(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_648), .-GL_PREFIX(_dispatch_stub_648) + + .p2align 4,,15 + .globl GL_PREFIX(BlendFuncSeparateEXT) + .type GL_PREFIX(BlendFuncSeparateEXT), @function +GL_PREFIX(BlendFuncSeparateEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5192(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5192(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5192(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5192(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BlendFuncSeparateEXT), .-GL_PREFIX(BlendFuncSeparateEXT) + + .p2align 4,,15 + .globl GL_PREFIX(FlushVertexArrayRangeNV) + .type GL_PREFIX(FlushVertexArrayRangeNV), @function +GL_PREFIX(FlushVertexArrayRangeNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5200(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 5200(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5200(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 5200(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FlushVertexArrayRangeNV), .-GL_PREFIX(FlushVertexArrayRangeNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexArrayRangeNV) + .type GL_PREFIX(VertexArrayRangeNV), @function +GL_PREFIX(VertexArrayRangeNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5208(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5208(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5208(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5208(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexArrayRangeNV), .-GL_PREFIX(VertexArrayRangeNV) + + .p2align 4,,15 + .globl GL_PREFIX(CombinerInputNV) + .type GL_PREFIX(CombinerInputNV), @function +GL_PREFIX(CombinerInputNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5216(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5216(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5216(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5216(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CombinerInputNV), .-GL_PREFIX(CombinerInputNV) + + .p2align 4,,15 + .globl GL_PREFIX(CombinerOutputNV) + .type GL_PREFIX(CombinerOutputNV), @function +GL_PREFIX(CombinerOutputNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5224(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5224(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5224(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5224(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CombinerOutputNV), .-GL_PREFIX(CombinerOutputNV) + + .p2align 4,,15 + .globl GL_PREFIX(CombinerParameterfNV) + .type GL_PREFIX(CombinerParameterfNV), @function +GL_PREFIX(CombinerParameterfNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5232(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 5232(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5232(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 5232(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CombinerParameterfNV), .-GL_PREFIX(CombinerParameterfNV) + + .p2align 4,,15 + .globl GL_PREFIX(CombinerParameterfvNV) + .type GL_PREFIX(CombinerParameterfvNV), @function +GL_PREFIX(CombinerParameterfvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5240(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5240(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5240(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5240(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CombinerParameterfvNV), .-GL_PREFIX(CombinerParameterfvNV) + + .p2align 4,,15 + .globl GL_PREFIX(CombinerParameteriNV) + .type GL_PREFIX(CombinerParameteriNV), @function +GL_PREFIX(CombinerParameteriNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5248(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5248(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5248(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5248(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CombinerParameteriNV), .-GL_PREFIX(CombinerParameteriNV) + + .p2align 4,,15 + .globl GL_PREFIX(CombinerParameterivNV) + .type GL_PREFIX(CombinerParameterivNV), @function +GL_PREFIX(CombinerParameterivNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5256(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5256(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5256(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5256(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CombinerParameterivNV), .-GL_PREFIX(CombinerParameterivNV) + + .p2align 4,,15 + .globl GL_PREFIX(FinalCombinerInputNV) + .type GL_PREFIX(FinalCombinerInputNV), @function +GL_PREFIX(FinalCombinerInputNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5264(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5264(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5264(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5264(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FinalCombinerInputNV), .-GL_PREFIX(FinalCombinerInputNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetCombinerInputParameterfvNV) + .type GL_PREFIX(GetCombinerInputParameterfvNV), @function +GL_PREFIX(GetCombinerInputParameterfvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5272(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5272(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5272(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5272(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetCombinerInputParameterfvNV), .-GL_PREFIX(GetCombinerInputParameterfvNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetCombinerInputParameterivNV) + .type GL_PREFIX(GetCombinerInputParameterivNV), @function +GL_PREFIX(GetCombinerInputParameterivNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5280(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5280(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5280(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5280(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetCombinerInputParameterivNV), .-GL_PREFIX(GetCombinerInputParameterivNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetCombinerOutputParameterfvNV) + .type GL_PREFIX(GetCombinerOutputParameterfvNV), @function +GL_PREFIX(GetCombinerOutputParameterfvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5288(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5288(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5288(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5288(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetCombinerOutputParameterfvNV), .-GL_PREFIX(GetCombinerOutputParameterfvNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetCombinerOutputParameterivNV) + .type GL_PREFIX(GetCombinerOutputParameterivNV), @function +GL_PREFIX(GetCombinerOutputParameterivNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5296(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5296(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5296(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5296(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetCombinerOutputParameterivNV), .-GL_PREFIX(GetCombinerOutputParameterivNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetFinalCombinerInputParameterfvNV) + .type GL_PREFIX(GetFinalCombinerInputParameterfvNV), @function +GL_PREFIX(GetFinalCombinerInputParameterfvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5304(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5304(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5304(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5304(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetFinalCombinerInputParameterfvNV), .-GL_PREFIX(GetFinalCombinerInputParameterfvNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetFinalCombinerInputParameterivNV) + .type GL_PREFIX(GetFinalCombinerInputParameterivNV), @function +GL_PREFIX(GetFinalCombinerInputParameterivNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5312(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5312(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5312(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5312(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetFinalCombinerInputParameterivNV), .-GL_PREFIX(GetFinalCombinerInputParameterivNV) + + .p2align 4,,15 + .globl GL_PREFIX(ResizeBuffersMESA) + .type GL_PREFIX(ResizeBuffersMESA), @function +GL_PREFIX(ResizeBuffersMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5320(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 5320(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5320(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 5320(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ResizeBuffersMESA), .-GL_PREFIX(ResizeBuffersMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos2dMESA) + .type GL_PREFIX(WindowPos2dMESA), @function +GL_PREFIX(WindowPos2dMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5328(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 5328(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5328(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 5328(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos2dMESA), .-GL_PREFIX(WindowPos2dMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos2dvMESA) + .type GL_PREFIX(WindowPos2dvMESA), @function +GL_PREFIX(WindowPos2dvMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5336(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5336(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5336(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5336(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos2dvMESA), .-GL_PREFIX(WindowPos2dvMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos2fMESA) + .type GL_PREFIX(WindowPos2fMESA), @function +GL_PREFIX(WindowPos2fMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5344(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 5344(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5344(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 5344(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos2fMESA), .-GL_PREFIX(WindowPos2fMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos2fvMESA) + .type GL_PREFIX(WindowPos2fvMESA), @function +GL_PREFIX(WindowPos2fvMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5352(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5352(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5352(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5352(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos2fvMESA), .-GL_PREFIX(WindowPos2fvMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos2iMESA) + .type GL_PREFIX(WindowPos2iMESA), @function +GL_PREFIX(WindowPos2iMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5360(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5360(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5360(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5360(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos2iMESA), .-GL_PREFIX(WindowPos2iMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos2ivMESA) + .type GL_PREFIX(WindowPos2ivMESA), @function +GL_PREFIX(WindowPos2ivMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5368(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5368(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5368(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5368(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos2ivMESA), .-GL_PREFIX(WindowPos2ivMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos2sMESA) + .type GL_PREFIX(WindowPos2sMESA), @function +GL_PREFIX(WindowPos2sMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5376(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5376(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5376(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5376(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos2sMESA), .-GL_PREFIX(WindowPos2sMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos2svMESA) + .type GL_PREFIX(WindowPos2svMESA), @function +GL_PREFIX(WindowPos2svMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5384(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5384(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5384(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5384(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos2svMESA), .-GL_PREFIX(WindowPos2svMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos3dMESA) + .type GL_PREFIX(WindowPos3dMESA), @function +GL_PREFIX(WindowPos3dMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5392(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 5392(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5392(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 5392(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos3dMESA), .-GL_PREFIX(WindowPos3dMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos3dvMESA) + .type GL_PREFIX(WindowPos3dvMESA), @function +GL_PREFIX(WindowPos3dvMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5400(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5400(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5400(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5400(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos3dvMESA), .-GL_PREFIX(WindowPos3dvMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos3fMESA) + .type GL_PREFIX(WindowPos3fMESA), @function +GL_PREFIX(WindowPos3fMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5408(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 5408(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5408(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $24, %rsp + movq 5408(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos3fMESA), .-GL_PREFIX(WindowPos3fMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos3fvMESA) + .type GL_PREFIX(WindowPos3fvMESA), @function +GL_PREFIX(WindowPos3fvMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5416(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5416(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5416(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5416(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos3fvMESA), .-GL_PREFIX(WindowPos3fvMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos3iMESA) + .type GL_PREFIX(WindowPos3iMESA), @function +GL_PREFIX(WindowPos3iMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5424(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5424(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5424(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5424(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos3iMESA), .-GL_PREFIX(WindowPos3iMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos3ivMESA) + .type GL_PREFIX(WindowPos3ivMESA), @function +GL_PREFIX(WindowPos3ivMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5432(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5432(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5432(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5432(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos3ivMESA), .-GL_PREFIX(WindowPos3ivMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos3sMESA) + .type GL_PREFIX(WindowPos3sMESA), @function +GL_PREFIX(WindowPos3sMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5440(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5440(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5440(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5440(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos3sMESA), .-GL_PREFIX(WindowPos3sMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos3svMESA) + .type GL_PREFIX(WindowPos3svMESA), @function +GL_PREFIX(WindowPos3svMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5448(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5448(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5448(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5448(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos3svMESA), .-GL_PREFIX(WindowPos3svMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos4dMESA) + .type GL_PREFIX(WindowPos4dMESA), @function +GL_PREFIX(WindowPos4dMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5456(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 5456(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5456(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 5456(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos4dMESA), .-GL_PREFIX(WindowPos4dMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos4dvMESA) + .type GL_PREFIX(WindowPos4dvMESA), @function +GL_PREFIX(WindowPos4dvMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5464(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5464(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5464(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5464(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos4dvMESA), .-GL_PREFIX(WindowPos4dvMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos4fMESA) + .type GL_PREFIX(WindowPos4fMESA), @function +GL_PREFIX(WindowPos4fMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5472(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 5472(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5472(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %xmm0, (%rsp) + movq %xmm1, 8(%rsp) + movq %xmm2, 16(%rsp) + movq %xmm3, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm3 + movq 16(%rsp), %xmm2 + movq 8(%rsp), %xmm1 + movq (%rsp), %xmm0 + addq $40, %rsp + movq 5472(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos4fMESA), .-GL_PREFIX(WindowPos4fMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos4fvMESA) + .type GL_PREFIX(WindowPos4fvMESA), @function +GL_PREFIX(WindowPos4fvMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5480(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5480(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5480(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5480(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos4fvMESA), .-GL_PREFIX(WindowPos4fvMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos4iMESA) + .type GL_PREFIX(WindowPos4iMESA), @function +GL_PREFIX(WindowPos4iMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5488(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5488(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5488(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5488(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos4iMESA), .-GL_PREFIX(WindowPos4iMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos4ivMESA) + .type GL_PREFIX(WindowPos4ivMESA), @function +GL_PREFIX(WindowPos4ivMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5496(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5496(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5496(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5496(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos4ivMESA), .-GL_PREFIX(WindowPos4ivMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos4sMESA) + .type GL_PREFIX(WindowPos4sMESA), @function +GL_PREFIX(WindowPos4sMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5504(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5504(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5504(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5504(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos4sMESA), .-GL_PREFIX(WindowPos4sMESA) + + .p2align 4,,15 + .globl GL_PREFIX(WindowPos4svMESA) + .type GL_PREFIX(WindowPos4svMESA), @function +GL_PREFIX(WindowPos4svMESA): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5512(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5512(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5512(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5512(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(WindowPos4svMESA), .-GL_PREFIX(WindowPos4svMESA) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_690) + .type GL_PREFIX(_dispatch_stub_690), @function + HIDDEN(GL_PREFIX(_dispatch_stub_690)) +GL_PREFIX(_dispatch_stub_690): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5520(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5520(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5520(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5520(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_690), .-GL_PREFIX(_dispatch_stub_690) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_691) + .type GL_PREFIX(_dispatch_stub_691), @function + HIDDEN(GL_PREFIX(_dispatch_stub_691)) +GL_PREFIX(_dispatch_stub_691): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5528(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5528(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5528(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5528(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_691), .-GL_PREFIX(_dispatch_stub_691) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_692) + .type GL_PREFIX(_dispatch_stub_692), @function + HIDDEN(GL_PREFIX(_dispatch_stub_692)) +GL_PREFIX(_dispatch_stub_692): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5536(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5536(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5536(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5536(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_692), .-GL_PREFIX(_dispatch_stub_692) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_693) + .type GL_PREFIX(_dispatch_stub_693), @function + HIDDEN(GL_PREFIX(_dispatch_stub_693)) +GL_PREFIX(_dispatch_stub_693): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5544(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5544(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5544(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5544(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_693), .-GL_PREFIX(_dispatch_stub_693) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_694) + .type GL_PREFIX(_dispatch_stub_694), @function + HIDDEN(GL_PREFIX(_dispatch_stub_694)) +GL_PREFIX(_dispatch_stub_694): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5552(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5552(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5552(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5552(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_694), .-GL_PREFIX(_dispatch_stub_694) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_695) + .type GL_PREFIX(_dispatch_stub_695), @function + HIDDEN(GL_PREFIX(_dispatch_stub_695)) +GL_PREFIX(_dispatch_stub_695): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5560(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5560(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5560(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5560(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_695), .-GL_PREFIX(_dispatch_stub_695) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_696) + .type GL_PREFIX(_dispatch_stub_696), @function + HIDDEN(GL_PREFIX(_dispatch_stub_696)) +GL_PREFIX(_dispatch_stub_696): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5568(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5568(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5568(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5568(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_696), .-GL_PREFIX(_dispatch_stub_696) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_697) + .type GL_PREFIX(_dispatch_stub_697), @function + HIDDEN(GL_PREFIX(_dispatch_stub_697)) +GL_PREFIX(_dispatch_stub_697): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5576(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5576(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5576(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5576(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_697), .-GL_PREFIX(_dispatch_stub_697) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_698) + .type GL_PREFIX(_dispatch_stub_698), @function + HIDDEN(GL_PREFIX(_dispatch_stub_698)) +GL_PREFIX(_dispatch_stub_698): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5584(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5584(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5584(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5584(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_698), .-GL_PREFIX(_dispatch_stub_698) + + .p2align 4,,15 + .globl GL_PREFIX(AreProgramsResidentNV) + .type GL_PREFIX(AreProgramsResidentNV), @function +GL_PREFIX(AreProgramsResidentNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5592(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5592(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5592(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5592(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(AreProgramsResidentNV), .-GL_PREFIX(AreProgramsResidentNV) + + .p2align 4,,15 + .globl GL_PREFIX(BindProgramNV) + .type GL_PREFIX(BindProgramNV), @function +GL_PREFIX(BindProgramNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5600(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5600(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5600(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5600(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BindProgramNV), .-GL_PREFIX(BindProgramNV) + + .p2align 4,,15 + .globl GL_PREFIX(DeleteProgramsNV) + .type GL_PREFIX(DeleteProgramsNV), @function +GL_PREFIX(DeleteProgramsNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5608(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5608(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5608(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5608(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DeleteProgramsNV), .-GL_PREFIX(DeleteProgramsNV) + + .p2align 4,,15 + .globl GL_PREFIX(ExecuteProgramNV) + .type GL_PREFIX(ExecuteProgramNV), @function +GL_PREFIX(ExecuteProgramNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5616(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5616(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5616(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5616(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ExecuteProgramNV), .-GL_PREFIX(ExecuteProgramNV) + + .p2align 4,,15 + .globl GL_PREFIX(GenProgramsNV) + .type GL_PREFIX(GenProgramsNV), @function +GL_PREFIX(GenProgramsNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5624(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5624(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5624(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5624(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GenProgramsNV), .-GL_PREFIX(GenProgramsNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetProgramParameterdvNV) + .type GL_PREFIX(GetProgramParameterdvNV), @function +GL_PREFIX(GetProgramParameterdvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5632(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5632(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5632(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5632(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetProgramParameterdvNV), .-GL_PREFIX(GetProgramParameterdvNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetProgramParameterfvNV) + .type GL_PREFIX(GetProgramParameterfvNV), @function +GL_PREFIX(GetProgramParameterfvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5640(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5640(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5640(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5640(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetProgramParameterfvNV), .-GL_PREFIX(GetProgramParameterfvNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetProgramStringNV) + .type GL_PREFIX(GetProgramStringNV), @function +GL_PREFIX(GetProgramStringNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5648(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5648(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5648(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5648(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetProgramStringNV), .-GL_PREFIX(GetProgramStringNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetProgramivNV) + .type GL_PREFIX(GetProgramivNV), @function +GL_PREFIX(GetProgramivNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5656(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5656(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5656(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5656(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetProgramivNV), .-GL_PREFIX(GetProgramivNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetTrackMatrixivNV) + .type GL_PREFIX(GetTrackMatrixivNV), @function +GL_PREFIX(GetTrackMatrixivNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5664(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5664(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5664(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5664(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTrackMatrixivNV), .-GL_PREFIX(GetTrackMatrixivNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetVertexAttribPointervNV) + .type GL_PREFIX(GetVertexAttribPointervNV), @function +GL_PREFIX(GetVertexAttribPointervNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5672(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5672(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5672(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5672(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetVertexAttribPointervNV), .-GL_PREFIX(GetVertexAttribPointervNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetVertexAttribdvNV) + .type GL_PREFIX(GetVertexAttribdvNV), @function +GL_PREFIX(GetVertexAttribdvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5680(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5680(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5680(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5680(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetVertexAttribdvNV), .-GL_PREFIX(GetVertexAttribdvNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetVertexAttribfvNV) + .type GL_PREFIX(GetVertexAttribfvNV), @function +GL_PREFIX(GetVertexAttribfvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5688(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5688(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5688(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5688(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetVertexAttribfvNV), .-GL_PREFIX(GetVertexAttribfvNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetVertexAttribivNV) + .type GL_PREFIX(GetVertexAttribivNV), @function +GL_PREFIX(GetVertexAttribivNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5696(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5696(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5696(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5696(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetVertexAttribivNV), .-GL_PREFIX(GetVertexAttribivNV) + + .p2align 4,,15 + .globl GL_PREFIX(IsProgramNV) + .type GL_PREFIX(IsProgramNV), @function +GL_PREFIX(IsProgramNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5704(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 5704(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5704(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 5704(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IsProgramNV), .-GL_PREFIX(IsProgramNV) + + .p2align 4,,15 + .globl GL_PREFIX(LoadProgramNV) + .type GL_PREFIX(LoadProgramNV), @function +GL_PREFIX(LoadProgramNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5712(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5712(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5712(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5712(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(LoadProgramNV), .-GL_PREFIX(LoadProgramNV) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramParameters4dvNV) + .type GL_PREFIX(ProgramParameters4dvNV), @function +GL_PREFIX(ProgramParameters4dvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5720(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5720(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5720(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5720(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramParameters4dvNV), .-GL_PREFIX(ProgramParameters4dvNV) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramParameters4fvNV) + .type GL_PREFIX(ProgramParameters4fvNV), @function +GL_PREFIX(ProgramParameters4fvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5728(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5728(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5728(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5728(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramParameters4fvNV), .-GL_PREFIX(ProgramParameters4fvNV) + + .p2align 4,,15 + .globl GL_PREFIX(RequestResidentProgramsNV) + .type GL_PREFIX(RequestResidentProgramsNV), @function +GL_PREFIX(RequestResidentProgramsNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5736(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5736(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5736(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5736(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RequestResidentProgramsNV), .-GL_PREFIX(RequestResidentProgramsNV) + + .p2align 4,,15 + .globl GL_PREFIX(TrackMatrixNV) + .type GL_PREFIX(TrackMatrixNV), @function +GL_PREFIX(TrackMatrixNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5744(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5744(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5744(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5744(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TrackMatrixNV), .-GL_PREFIX(TrackMatrixNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib1dNV) + .type GL_PREFIX(VertexAttrib1dNV), @function +GL_PREFIX(VertexAttrib1dNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5752(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 5752(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5752(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 5752(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib1dNV), .-GL_PREFIX(VertexAttrib1dNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib1dvNV) + .type GL_PREFIX(VertexAttrib1dvNV), @function +GL_PREFIX(VertexAttrib1dvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5760(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5760(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5760(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5760(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib1dvNV), .-GL_PREFIX(VertexAttrib1dvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib1fNV) + .type GL_PREFIX(VertexAttrib1fNV), @function +GL_PREFIX(VertexAttrib1fNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5768(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _x86_64_get_dispatch@PLT + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 5768(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5768(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + call _glapi_get_dispatch + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 5768(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib1fNV), .-GL_PREFIX(VertexAttrib1fNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib1fvNV) + .type GL_PREFIX(VertexAttrib1fvNV), @function +GL_PREFIX(VertexAttrib1fvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5776(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5776(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5776(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5776(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib1fvNV), .-GL_PREFIX(VertexAttrib1fvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib1sNV) + .type GL_PREFIX(VertexAttrib1sNV), @function +GL_PREFIX(VertexAttrib1sNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5784(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5784(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5784(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5784(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib1sNV), .-GL_PREFIX(VertexAttrib1sNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib1svNV) + .type GL_PREFIX(VertexAttrib1svNV), @function +GL_PREFIX(VertexAttrib1svNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5792(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5792(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5792(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5792(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib1svNV), .-GL_PREFIX(VertexAttrib1svNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib2dNV) + .type GL_PREFIX(VertexAttrib2dNV), @function +GL_PREFIX(VertexAttrib2dNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5800(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 5800(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5800(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 5800(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib2dNV), .-GL_PREFIX(VertexAttrib2dNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib2dvNV) + .type GL_PREFIX(VertexAttrib2dvNV), @function +GL_PREFIX(VertexAttrib2dvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5808(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5808(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5808(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5808(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib2dvNV), .-GL_PREFIX(VertexAttrib2dvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib2fNV) + .type GL_PREFIX(VertexAttrib2fNV), @function +GL_PREFIX(VertexAttrib2fNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5816(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _x86_64_get_dispatch@PLT + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 5816(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5816(%rax), %r11 + jmp *%r11 +1: + subq $24, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + call _glapi_get_dispatch + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $24, %rsp + movq 5816(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib2fNV), .-GL_PREFIX(VertexAttrib2fNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib2fvNV) + .type GL_PREFIX(VertexAttrib2fvNV), @function +GL_PREFIX(VertexAttrib2fvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5824(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5824(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5824(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5824(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib2fvNV), .-GL_PREFIX(VertexAttrib2fvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib2sNV) + .type GL_PREFIX(VertexAttrib2sNV), @function +GL_PREFIX(VertexAttrib2sNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5832(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5832(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5832(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5832(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib2sNV), .-GL_PREFIX(VertexAttrib2sNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib2svNV) + .type GL_PREFIX(VertexAttrib2svNV), @function +GL_PREFIX(VertexAttrib2svNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5840(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5840(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5840(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5840(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib2svNV), .-GL_PREFIX(VertexAttrib2svNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib3dNV) + .type GL_PREFIX(VertexAttrib3dNV), @function +GL_PREFIX(VertexAttrib3dNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5848(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 5848(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5848(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 5848(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib3dNV), .-GL_PREFIX(VertexAttrib3dNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib3dvNV) + .type GL_PREFIX(VertexAttrib3dvNV), @function +GL_PREFIX(VertexAttrib3dvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5856(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5856(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5856(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5856(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib3dvNV), .-GL_PREFIX(VertexAttrib3dvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib3fNV) + .type GL_PREFIX(VertexAttrib3fNV), @function +GL_PREFIX(VertexAttrib3fNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5864(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + call _x86_64_get_dispatch@PLT + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 5864(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5864(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + call _glapi_get_dispatch + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 5864(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib3fNV), .-GL_PREFIX(VertexAttrib3fNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib3fvNV) + .type GL_PREFIX(VertexAttrib3fvNV), @function +GL_PREFIX(VertexAttrib3fvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5872(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5872(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5872(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5872(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib3fvNV), .-GL_PREFIX(VertexAttrib3fvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib3sNV) + .type GL_PREFIX(VertexAttrib3sNV), @function +GL_PREFIX(VertexAttrib3sNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5880(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5880(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5880(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5880(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib3sNV), .-GL_PREFIX(VertexAttrib3sNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib3svNV) + .type GL_PREFIX(VertexAttrib3svNV), @function +GL_PREFIX(VertexAttrib3svNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5888(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5888(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5888(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5888(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib3svNV), .-GL_PREFIX(VertexAttrib3svNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4dNV) + .type GL_PREFIX(VertexAttrib4dNV), @function +GL_PREFIX(VertexAttrib4dNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5896(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + movq %xmm3, 32(%rsp) + call _x86_64_get_dispatch@PLT + movq 32(%rsp), %xmm3 + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 5896(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5896(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + movq %xmm3, 32(%rsp) + call _glapi_get_dispatch + movq 32(%rsp), %xmm3 + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 5896(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4dNV), .-GL_PREFIX(VertexAttrib4dNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4dvNV) + .type GL_PREFIX(VertexAttrib4dvNV), @function +GL_PREFIX(VertexAttrib4dvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5904(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5904(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5904(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5904(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4dvNV), .-GL_PREFIX(VertexAttrib4dvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4fNV) + .type GL_PREFIX(VertexAttrib4fNV), @function +GL_PREFIX(VertexAttrib4fNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5912(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + movq %xmm3, 32(%rsp) + call _x86_64_get_dispatch@PLT + movq 32(%rsp), %xmm3 + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 5912(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5912(%rax), %r11 + jmp *%r11 +1: + subq $40, %rsp + movq %rdi, (%rsp) + movq %xmm0, 8(%rsp) + movq %xmm1, 16(%rsp) + movq %xmm2, 24(%rsp) + movq %xmm3, 32(%rsp) + call _glapi_get_dispatch + movq 32(%rsp), %xmm3 + movq 24(%rsp), %xmm2 + movq 16(%rsp), %xmm1 + movq 8(%rsp), %xmm0 + movq (%rsp), %rdi + addq $40, %rsp + movq 5912(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4fNV), .-GL_PREFIX(VertexAttrib4fNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4fvNV) + .type GL_PREFIX(VertexAttrib4fvNV), @function +GL_PREFIX(VertexAttrib4fvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5920(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5920(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5920(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5920(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4fvNV), .-GL_PREFIX(VertexAttrib4fvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4sNV) + .type GL_PREFIX(VertexAttrib4sNV), @function +GL_PREFIX(VertexAttrib4sNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5928(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5928(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5928(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5928(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4sNV), .-GL_PREFIX(VertexAttrib4sNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4svNV) + .type GL_PREFIX(VertexAttrib4svNV), @function +GL_PREFIX(VertexAttrib4svNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5936(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5936(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5936(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5936(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4svNV), .-GL_PREFIX(VertexAttrib4svNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4ubNV) + .type GL_PREFIX(VertexAttrib4ubNV), @function +GL_PREFIX(VertexAttrib4ubNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5944(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5944(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5944(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5944(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4ubNV), .-GL_PREFIX(VertexAttrib4ubNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttrib4ubvNV) + .type GL_PREFIX(VertexAttrib4ubvNV), @function +GL_PREFIX(VertexAttrib4ubvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5952(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 5952(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5952(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 5952(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttrib4ubvNV), .-GL_PREFIX(VertexAttrib4ubvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribPointerNV) + .type GL_PREFIX(VertexAttribPointerNV), @function +GL_PREFIX(VertexAttribPointerNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5960(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5960(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5960(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 5960(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribPointerNV), .-GL_PREFIX(VertexAttribPointerNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribs1dvNV) + .type GL_PREFIX(VertexAttribs1dvNV), @function +GL_PREFIX(VertexAttribs1dvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5968(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5968(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5968(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5968(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribs1dvNV), .-GL_PREFIX(VertexAttribs1dvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribs1fvNV) + .type GL_PREFIX(VertexAttribs1fvNV), @function +GL_PREFIX(VertexAttribs1fvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5976(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5976(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5976(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5976(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribs1fvNV), .-GL_PREFIX(VertexAttribs1fvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribs1svNV) + .type GL_PREFIX(VertexAttribs1svNV), @function +GL_PREFIX(VertexAttribs1svNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5984(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5984(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5984(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5984(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribs1svNV), .-GL_PREFIX(VertexAttribs1svNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribs2dvNV) + .type GL_PREFIX(VertexAttribs2dvNV), @function +GL_PREFIX(VertexAttribs2dvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 5992(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 5992(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 5992(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 5992(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribs2dvNV), .-GL_PREFIX(VertexAttribs2dvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribs2fvNV) + .type GL_PREFIX(VertexAttribs2fvNV), @function +GL_PREFIX(VertexAttribs2fvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6000(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6000(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6000(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6000(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribs2fvNV), .-GL_PREFIX(VertexAttribs2fvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribs2svNV) + .type GL_PREFIX(VertexAttribs2svNV), @function +GL_PREFIX(VertexAttribs2svNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6008(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6008(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6008(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6008(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribs2svNV), .-GL_PREFIX(VertexAttribs2svNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribs3dvNV) + .type GL_PREFIX(VertexAttribs3dvNV), @function +GL_PREFIX(VertexAttribs3dvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6016(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6016(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6016(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6016(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribs3dvNV), .-GL_PREFIX(VertexAttribs3dvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribs3fvNV) + .type GL_PREFIX(VertexAttribs3fvNV), @function +GL_PREFIX(VertexAttribs3fvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6024(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6024(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6024(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6024(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribs3fvNV), .-GL_PREFIX(VertexAttribs3fvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribs3svNV) + .type GL_PREFIX(VertexAttribs3svNV), @function +GL_PREFIX(VertexAttribs3svNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6032(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6032(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6032(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6032(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribs3svNV), .-GL_PREFIX(VertexAttribs3svNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribs4dvNV) + .type GL_PREFIX(VertexAttribs4dvNV), @function +GL_PREFIX(VertexAttribs4dvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6040(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6040(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6040(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6040(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribs4dvNV), .-GL_PREFIX(VertexAttribs4dvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribs4fvNV) + .type GL_PREFIX(VertexAttribs4fvNV), @function +GL_PREFIX(VertexAttribs4fvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6048(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6048(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6048(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6048(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribs4fvNV), .-GL_PREFIX(VertexAttribs4fvNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribs4svNV) + .type GL_PREFIX(VertexAttribs4svNV), @function +GL_PREFIX(VertexAttribs4svNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6056(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6056(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6056(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6056(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribs4svNV), .-GL_PREFIX(VertexAttribs4svNV) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribs4ubvNV) + .type GL_PREFIX(VertexAttribs4ubvNV), @function +GL_PREFIX(VertexAttribs4ubvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6064(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6064(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6064(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6064(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribs4ubvNV), .-GL_PREFIX(VertexAttribs4ubvNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetTexBumpParameterfvATI) + .type GL_PREFIX(GetTexBumpParameterfvATI), @function +GL_PREFIX(GetTexBumpParameterfvATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6072(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6072(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6072(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6072(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTexBumpParameterfvATI), .-GL_PREFIX(GetTexBumpParameterfvATI) + + .p2align 4,,15 + .globl GL_PREFIX(GetTexBumpParameterivATI) + .type GL_PREFIX(GetTexBumpParameterivATI), @function +GL_PREFIX(GetTexBumpParameterivATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6080(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6080(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6080(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6080(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTexBumpParameterivATI), .-GL_PREFIX(GetTexBumpParameterivATI) + + .p2align 4,,15 + .globl GL_PREFIX(TexBumpParameterfvATI) + .type GL_PREFIX(TexBumpParameterfvATI), @function +GL_PREFIX(TexBumpParameterfvATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6088(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6088(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6088(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6088(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexBumpParameterfvATI), .-GL_PREFIX(TexBumpParameterfvATI) + + .p2align 4,,15 + .globl GL_PREFIX(TexBumpParameterivATI) + .type GL_PREFIX(TexBumpParameterivATI), @function +GL_PREFIX(TexBumpParameterivATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6096(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6096(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6096(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6096(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexBumpParameterivATI), .-GL_PREFIX(TexBumpParameterivATI) + + .p2align 4,,15 + .globl GL_PREFIX(AlphaFragmentOp1ATI) + .type GL_PREFIX(AlphaFragmentOp1ATI), @function +GL_PREFIX(AlphaFragmentOp1ATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6104(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6104(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6104(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6104(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(AlphaFragmentOp1ATI), .-GL_PREFIX(AlphaFragmentOp1ATI) + + .p2align 4,,15 + .globl GL_PREFIX(AlphaFragmentOp2ATI) + .type GL_PREFIX(AlphaFragmentOp2ATI), @function +GL_PREFIX(AlphaFragmentOp2ATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6112(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6112(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6112(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6112(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(AlphaFragmentOp2ATI), .-GL_PREFIX(AlphaFragmentOp2ATI) + + .p2align 4,,15 + .globl GL_PREFIX(AlphaFragmentOp3ATI) + .type GL_PREFIX(AlphaFragmentOp3ATI), @function +GL_PREFIX(AlphaFragmentOp3ATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6120(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6120(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6120(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6120(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(AlphaFragmentOp3ATI), .-GL_PREFIX(AlphaFragmentOp3ATI) + + .p2align 4,,15 + .globl GL_PREFIX(BeginFragmentShaderATI) + .type GL_PREFIX(BeginFragmentShaderATI), @function +GL_PREFIX(BeginFragmentShaderATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6128(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 6128(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6128(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 6128(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BeginFragmentShaderATI), .-GL_PREFIX(BeginFragmentShaderATI) + + .p2align 4,,15 + .globl GL_PREFIX(BindFragmentShaderATI) + .type GL_PREFIX(BindFragmentShaderATI), @function +GL_PREFIX(BindFragmentShaderATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6136(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 6136(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6136(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 6136(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BindFragmentShaderATI), .-GL_PREFIX(BindFragmentShaderATI) + + .p2align 4,,15 + .globl GL_PREFIX(ColorFragmentOp1ATI) + .type GL_PREFIX(ColorFragmentOp1ATI), @function +GL_PREFIX(ColorFragmentOp1ATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6144(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6144(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6144(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6144(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ColorFragmentOp1ATI), .-GL_PREFIX(ColorFragmentOp1ATI) + + .p2align 4,,15 + .globl GL_PREFIX(ColorFragmentOp2ATI) + .type GL_PREFIX(ColorFragmentOp2ATI), @function +GL_PREFIX(ColorFragmentOp2ATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6152(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6152(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6152(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6152(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ColorFragmentOp2ATI), .-GL_PREFIX(ColorFragmentOp2ATI) + + .p2align 4,,15 + .globl GL_PREFIX(ColorFragmentOp3ATI) + .type GL_PREFIX(ColorFragmentOp3ATI), @function +GL_PREFIX(ColorFragmentOp3ATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6160(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6160(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6160(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6160(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ColorFragmentOp3ATI), .-GL_PREFIX(ColorFragmentOp3ATI) + + .p2align 4,,15 + .globl GL_PREFIX(DeleteFragmentShaderATI) + .type GL_PREFIX(DeleteFragmentShaderATI), @function +GL_PREFIX(DeleteFragmentShaderATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6168(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 6168(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6168(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 6168(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DeleteFragmentShaderATI), .-GL_PREFIX(DeleteFragmentShaderATI) + + .p2align 4,,15 + .globl GL_PREFIX(EndFragmentShaderATI) + .type GL_PREFIX(EndFragmentShaderATI), @function +GL_PREFIX(EndFragmentShaderATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6176(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 6176(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6176(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 6176(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EndFragmentShaderATI), .-GL_PREFIX(EndFragmentShaderATI) + + .p2align 4,,15 + .globl GL_PREFIX(GenFragmentShadersATI) + .type GL_PREFIX(GenFragmentShadersATI), @function +GL_PREFIX(GenFragmentShadersATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6184(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 6184(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6184(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 6184(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GenFragmentShadersATI), .-GL_PREFIX(GenFragmentShadersATI) + + .p2align 4,,15 + .globl GL_PREFIX(PassTexCoordATI) + .type GL_PREFIX(PassTexCoordATI), @function +GL_PREFIX(PassTexCoordATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6192(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6192(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6192(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6192(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PassTexCoordATI), .-GL_PREFIX(PassTexCoordATI) + + .p2align 4,,15 + .globl GL_PREFIX(SampleMapATI) + .type GL_PREFIX(SampleMapATI), @function +GL_PREFIX(SampleMapATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6200(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6200(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6200(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6200(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SampleMapATI), .-GL_PREFIX(SampleMapATI) + + .p2align 4,,15 + .globl GL_PREFIX(SetFragmentShaderConstantATI) + .type GL_PREFIX(SetFragmentShaderConstantATI), @function +GL_PREFIX(SetFragmentShaderConstantATI): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6208(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6208(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6208(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6208(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(SetFragmentShaderConstantATI), .-GL_PREFIX(SetFragmentShaderConstantATI) + + .p2align 4,,15 + .globl GL_PREFIX(PointParameteriNV) + .type GL_PREFIX(PointParameteriNV), @function +GL_PREFIX(PointParameteriNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6216(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6216(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6216(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6216(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PointParameteriNV), .-GL_PREFIX(PointParameteriNV) + + .p2align 4,,15 + .globl GL_PREFIX(PointParameterivNV) + .type GL_PREFIX(PointParameterivNV), @function +GL_PREFIX(PointParameterivNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6224(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6224(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6224(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6224(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PointParameterivNV), .-GL_PREFIX(PointParameterivNV) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_779) + .type GL_PREFIX(_dispatch_stub_779), @function + HIDDEN(GL_PREFIX(_dispatch_stub_779)) +GL_PREFIX(_dispatch_stub_779): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6232(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 6232(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6232(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 6232(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_779), .-GL_PREFIX(_dispatch_stub_779) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_780) + .type GL_PREFIX(_dispatch_stub_780), @function + HIDDEN(GL_PREFIX(_dispatch_stub_780)) +GL_PREFIX(_dispatch_stub_780): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6240(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 6240(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6240(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 6240(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_780), .-GL_PREFIX(_dispatch_stub_780) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_781) + .type GL_PREFIX(_dispatch_stub_781), @function + HIDDEN(GL_PREFIX(_dispatch_stub_781)) +GL_PREFIX(_dispatch_stub_781): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6248(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6248(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6248(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6248(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_781), .-GL_PREFIX(_dispatch_stub_781) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_782) + .type GL_PREFIX(_dispatch_stub_782), @function + HIDDEN(GL_PREFIX(_dispatch_stub_782)) +GL_PREFIX(_dispatch_stub_782): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6256(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6256(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6256(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6256(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_782), .-GL_PREFIX(_dispatch_stub_782) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_783) + .type GL_PREFIX(_dispatch_stub_783), @function + HIDDEN(GL_PREFIX(_dispatch_stub_783)) +GL_PREFIX(_dispatch_stub_783): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6264(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 6264(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6264(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 6264(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_783), .-GL_PREFIX(_dispatch_stub_783) + + .p2align 4,,15 + .globl GL_PREFIX(GetProgramNamedParameterdvNV) + .type GL_PREFIX(GetProgramNamedParameterdvNV), @function +GL_PREFIX(GetProgramNamedParameterdvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6272(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6272(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6272(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6272(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetProgramNamedParameterdvNV), .-GL_PREFIX(GetProgramNamedParameterdvNV) + + .p2align 4,,15 + .globl GL_PREFIX(GetProgramNamedParameterfvNV) + .type GL_PREFIX(GetProgramNamedParameterfvNV), @function +GL_PREFIX(GetProgramNamedParameterfvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6280(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6280(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6280(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6280(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetProgramNamedParameterfvNV), .-GL_PREFIX(GetProgramNamedParameterfvNV) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramNamedParameter4dNV) + .type GL_PREFIX(ProgramNamedParameter4dNV), @function +GL_PREFIX(ProgramNamedParameter4dNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6288(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $56, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %rdx, 16(%rsp) + movq %xmm0, 24(%rsp) + movq %xmm1, 32(%rsp) + movq %xmm2, 40(%rsp) + movq %xmm3, 48(%rsp) + call _x86_64_get_dispatch@PLT + movq 48(%rsp), %xmm3 + movq 40(%rsp), %xmm2 + movq 32(%rsp), %xmm1 + movq 24(%rsp), %xmm0 + movq 16(%rsp), %rdx + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $56, %rsp + movq 6288(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6288(%rax), %r11 + jmp *%r11 +1: + subq $56, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %rdx, 16(%rsp) + movq %xmm0, 24(%rsp) + movq %xmm1, 32(%rsp) + movq %xmm2, 40(%rsp) + movq %xmm3, 48(%rsp) + call _glapi_get_dispatch + movq 48(%rsp), %xmm3 + movq 40(%rsp), %xmm2 + movq 32(%rsp), %xmm1 + movq 24(%rsp), %xmm0 + movq 16(%rsp), %rdx + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $56, %rsp + movq 6288(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramNamedParameter4dNV), .-GL_PREFIX(ProgramNamedParameter4dNV) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramNamedParameter4dvNV) + .type GL_PREFIX(ProgramNamedParameter4dvNV), @function +GL_PREFIX(ProgramNamedParameter4dvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6296(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6296(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6296(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6296(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramNamedParameter4dvNV), .-GL_PREFIX(ProgramNamedParameter4dvNV) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramNamedParameter4fNV) + .type GL_PREFIX(ProgramNamedParameter4fNV), @function +GL_PREFIX(ProgramNamedParameter4fNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6304(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + subq $56, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %rdx, 16(%rsp) + movq %xmm0, 24(%rsp) + movq %xmm1, 32(%rsp) + movq %xmm2, 40(%rsp) + movq %xmm3, 48(%rsp) + call _x86_64_get_dispatch@PLT + movq 48(%rsp), %xmm3 + movq 40(%rsp), %xmm2 + movq 32(%rsp), %xmm1 + movq 24(%rsp), %xmm0 + movq 16(%rsp), %rdx + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $56, %rsp + movq 6304(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6304(%rax), %r11 + jmp *%r11 +1: + subq $56, %rsp + movq %rdi, (%rsp) + movq %rsi, 8(%rsp) + movq %rdx, 16(%rsp) + movq %xmm0, 24(%rsp) + movq %xmm1, 32(%rsp) + movq %xmm2, 40(%rsp) + movq %xmm3, 48(%rsp) + call _glapi_get_dispatch + movq 48(%rsp), %xmm3 + movq 40(%rsp), %xmm2 + movq 32(%rsp), %xmm1 + movq 24(%rsp), %xmm0 + movq 16(%rsp), %rdx + movq 8(%rsp), %rsi + movq (%rsp), %rdi + addq $56, %rsp + movq 6304(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramNamedParameter4fNV), .-GL_PREFIX(ProgramNamedParameter4fNV) + + .p2align 4,,15 + .globl GL_PREFIX(ProgramNamedParameter4fvNV) + .type GL_PREFIX(ProgramNamedParameter4fvNV), @function +GL_PREFIX(ProgramNamedParameter4fvNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6312(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6312(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6312(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6312(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProgramNamedParameter4fvNV), .-GL_PREFIX(ProgramNamedParameter4fvNV) + + .p2align 4,,15 + .globl GL_PREFIX(PrimitiveRestartIndexNV) + .type GL_PREFIX(PrimitiveRestartIndexNV), @function +GL_PREFIX(PrimitiveRestartIndexNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6320(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 6320(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6320(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 6320(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PrimitiveRestartIndexNV), .-GL_PREFIX(PrimitiveRestartIndexNV) + + .p2align 4,,15 + .globl GL_PREFIX(PrimitiveRestartNV) + .type GL_PREFIX(PrimitiveRestartNV), @function +GL_PREFIX(PrimitiveRestartNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6328(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 6328(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6328(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 6328(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(PrimitiveRestartNV), .-GL_PREFIX(PrimitiveRestartNV) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_792) + .type GL_PREFIX(_dispatch_stub_792), @function + HIDDEN(GL_PREFIX(_dispatch_stub_792)) +GL_PREFIX(_dispatch_stub_792): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6336(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6336(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6336(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6336(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_792), .-GL_PREFIX(_dispatch_stub_792) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_793) + .type GL_PREFIX(_dispatch_stub_793), @function + HIDDEN(GL_PREFIX(_dispatch_stub_793)) +GL_PREFIX(_dispatch_stub_793): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6344(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6344(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6344(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6344(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_793), .-GL_PREFIX(_dispatch_stub_793) + + .p2align 4,,15 + .globl GL_PREFIX(BindFramebufferEXT) + .type GL_PREFIX(BindFramebufferEXT), @function +GL_PREFIX(BindFramebufferEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6352(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6352(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6352(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6352(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BindFramebufferEXT), .-GL_PREFIX(BindFramebufferEXT) + + .p2align 4,,15 + .globl GL_PREFIX(BindRenderbufferEXT) + .type GL_PREFIX(BindRenderbufferEXT), @function +GL_PREFIX(BindRenderbufferEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6360(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6360(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6360(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6360(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BindRenderbufferEXT), .-GL_PREFIX(BindRenderbufferEXT) + + .p2align 4,,15 + .globl GL_PREFIX(CheckFramebufferStatusEXT) + .type GL_PREFIX(CheckFramebufferStatusEXT), @function +GL_PREFIX(CheckFramebufferStatusEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6368(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 6368(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6368(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 6368(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CheckFramebufferStatusEXT), .-GL_PREFIX(CheckFramebufferStatusEXT) + + .p2align 4,,15 + .globl GL_PREFIX(DeleteFramebuffersEXT) + .type GL_PREFIX(DeleteFramebuffersEXT), @function +GL_PREFIX(DeleteFramebuffersEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6376(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6376(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6376(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6376(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DeleteFramebuffersEXT), .-GL_PREFIX(DeleteFramebuffersEXT) + + .p2align 4,,15 + .globl GL_PREFIX(DeleteRenderbuffersEXT) + .type GL_PREFIX(DeleteRenderbuffersEXT), @function +GL_PREFIX(DeleteRenderbuffersEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6384(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6384(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6384(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6384(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DeleteRenderbuffersEXT), .-GL_PREFIX(DeleteRenderbuffersEXT) + + .p2align 4,,15 + .globl GL_PREFIX(FramebufferRenderbufferEXT) + .type GL_PREFIX(FramebufferRenderbufferEXT), @function +GL_PREFIX(FramebufferRenderbufferEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6392(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6392(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6392(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6392(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FramebufferRenderbufferEXT), .-GL_PREFIX(FramebufferRenderbufferEXT) + + .p2align 4,,15 + .globl GL_PREFIX(FramebufferTexture1DEXT) + .type GL_PREFIX(FramebufferTexture1DEXT), @function +GL_PREFIX(FramebufferTexture1DEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6400(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6400(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6400(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6400(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FramebufferTexture1DEXT), .-GL_PREFIX(FramebufferTexture1DEXT) + + .p2align 4,,15 + .globl GL_PREFIX(FramebufferTexture2DEXT) + .type GL_PREFIX(FramebufferTexture2DEXT), @function +GL_PREFIX(FramebufferTexture2DEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6408(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6408(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6408(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6408(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FramebufferTexture2DEXT), .-GL_PREFIX(FramebufferTexture2DEXT) + + .p2align 4,,15 + .globl GL_PREFIX(FramebufferTexture3DEXT) + .type GL_PREFIX(FramebufferTexture3DEXT), @function +GL_PREFIX(FramebufferTexture3DEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6416(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6416(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6416(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6416(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FramebufferTexture3DEXT), .-GL_PREFIX(FramebufferTexture3DEXT) + + .p2align 4,,15 + .globl GL_PREFIX(GenFramebuffersEXT) + .type GL_PREFIX(GenFramebuffersEXT), @function +GL_PREFIX(GenFramebuffersEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6424(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6424(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6424(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6424(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GenFramebuffersEXT), .-GL_PREFIX(GenFramebuffersEXT) + + .p2align 4,,15 + .globl GL_PREFIX(GenRenderbuffersEXT) + .type GL_PREFIX(GenRenderbuffersEXT), @function +GL_PREFIX(GenRenderbuffersEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6432(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6432(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6432(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6432(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GenRenderbuffersEXT), .-GL_PREFIX(GenRenderbuffersEXT) + + .p2align 4,,15 + .globl GL_PREFIX(GenerateMipmapEXT) + .type GL_PREFIX(GenerateMipmapEXT), @function +GL_PREFIX(GenerateMipmapEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6440(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 6440(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6440(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 6440(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GenerateMipmapEXT), .-GL_PREFIX(GenerateMipmapEXT) + + .p2align 4,,15 + .globl GL_PREFIX(GetFramebufferAttachmentParameterivEXT) + .type GL_PREFIX(GetFramebufferAttachmentParameterivEXT), @function +GL_PREFIX(GetFramebufferAttachmentParameterivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6448(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6448(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6448(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6448(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetFramebufferAttachmentParameterivEXT), .-GL_PREFIX(GetFramebufferAttachmentParameterivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(GetRenderbufferParameterivEXT) + .type GL_PREFIX(GetRenderbufferParameterivEXT), @function +GL_PREFIX(GetRenderbufferParameterivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6456(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6456(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6456(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6456(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetRenderbufferParameterivEXT), .-GL_PREFIX(GetRenderbufferParameterivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(IsFramebufferEXT) + .type GL_PREFIX(IsFramebufferEXT), @function +GL_PREFIX(IsFramebufferEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6464(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 6464(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6464(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 6464(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IsFramebufferEXT), .-GL_PREFIX(IsFramebufferEXT) + + .p2align 4,,15 + .globl GL_PREFIX(IsRenderbufferEXT) + .type GL_PREFIX(IsRenderbufferEXT), @function +GL_PREFIX(IsRenderbufferEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6472(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 6472(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6472(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 6472(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IsRenderbufferEXT), .-GL_PREFIX(IsRenderbufferEXT) + + .p2align 4,,15 + .globl GL_PREFIX(RenderbufferStorageEXT) + .type GL_PREFIX(RenderbufferStorageEXT), @function +GL_PREFIX(RenderbufferStorageEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6480(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6480(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6480(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6480(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(RenderbufferStorageEXT), .-GL_PREFIX(RenderbufferStorageEXT) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_811) + .type GL_PREFIX(_dispatch_stub_811), @function + HIDDEN(GL_PREFIX(_dispatch_stub_811)) +GL_PREFIX(_dispatch_stub_811): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6488(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6488(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6488(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6488(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_811), .-GL_PREFIX(_dispatch_stub_811) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_812) + .type GL_PREFIX(_dispatch_stub_812), @function + HIDDEN(GL_PREFIX(_dispatch_stub_812)) +GL_PREFIX(_dispatch_stub_812): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6496(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6496(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6496(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6496(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_812), .-GL_PREFIX(_dispatch_stub_812) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_813) + .type GL_PREFIX(_dispatch_stub_813), @function + HIDDEN(GL_PREFIX(_dispatch_stub_813)) +GL_PREFIX(_dispatch_stub_813): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6504(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6504(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6504(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6504(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_813), .-GL_PREFIX(_dispatch_stub_813) + + .p2align 4,,15 + .globl GL_PREFIX(BindFragDataLocationEXT) + .type GL_PREFIX(BindFragDataLocationEXT), @function +GL_PREFIX(BindFragDataLocationEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6512(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6512(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6512(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6512(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BindFragDataLocationEXT), .-GL_PREFIX(BindFragDataLocationEXT) + + .p2align 4,,15 + .globl GL_PREFIX(GetFragDataLocationEXT) + .type GL_PREFIX(GetFragDataLocationEXT), @function +GL_PREFIX(GetFragDataLocationEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6520(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6520(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6520(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6520(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetFragDataLocationEXT), .-GL_PREFIX(GetFragDataLocationEXT) + + .p2align 4,,15 + .globl GL_PREFIX(GetUniformuivEXT) + .type GL_PREFIX(GetUniformuivEXT), @function +GL_PREFIX(GetUniformuivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6528(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6528(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6528(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6528(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetUniformuivEXT), .-GL_PREFIX(GetUniformuivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(GetVertexAttribIivEXT) + .type GL_PREFIX(GetVertexAttribIivEXT), @function +GL_PREFIX(GetVertexAttribIivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6536(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6536(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6536(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6536(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetVertexAttribIivEXT), .-GL_PREFIX(GetVertexAttribIivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(GetVertexAttribIuivEXT) + .type GL_PREFIX(GetVertexAttribIuivEXT), @function +GL_PREFIX(GetVertexAttribIuivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6544(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6544(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6544(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6544(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetVertexAttribIuivEXT), .-GL_PREFIX(GetVertexAttribIuivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform1uiEXT) + .type GL_PREFIX(Uniform1uiEXT), @function +GL_PREFIX(Uniform1uiEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6552(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6552(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6552(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6552(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform1uiEXT), .-GL_PREFIX(Uniform1uiEXT) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform1uivEXT) + .type GL_PREFIX(Uniform1uivEXT), @function +GL_PREFIX(Uniform1uivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6560(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6560(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6560(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6560(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform1uivEXT), .-GL_PREFIX(Uniform1uivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform2uiEXT) + .type GL_PREFIX(Uniform2uiEXT), @function +GL_PREFIX(Uniform2uiEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6568(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6568(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6568(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6568(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform2uiEXT), .-GL_PREFIX(Uniform2uiEXT) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform2uivEXT) + .type GL_PREFIX(Uniform2uivEXT), @function +GL_PREFIX(Uniform2uivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6576(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6576(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6576(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6576(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform2uivEXT), .-GL_PREFIX(Uniform2uivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform3uiEXT) + .type GL_PREFIX(Uniform3uiEXT), @function +GL_PREFIX(Uniform3uiEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6584(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6584(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6584(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6584(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform3uiEXT), .-GL_PREFIX(Uniform3uiEXT) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform3uivEXT) + .type GL_PREFIX(Uniform3uivEXT), @function +GL_PREFIX(Uniform3uivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6592(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6592(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6592(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6592(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform3uivEXT), .-GL_PREFIX(Uniform3uivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform4uiEXT) + .type GL_PREFIX(Uniform4uiEXT), @function +GL_PREFIX(Uniform4uiEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6600(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6600(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6600(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6600(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform4uiEXT), .-GL_PREFIX(Uniform4uiEXT) + + .p2align 4,,15 + .globl GL_PREFIX(Uniform4uivEXT) + .type GL_PREFIX(Uniform4uivEXT), @function +GL_PREFIX(Uniform4uivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6608(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6608(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6608(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6608(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(Uniform4uivEXT), .-GL_PREFIX(Uniform4uivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI1iEXT) + .type GL_PREFIX(VertexAttribI1iEXT), @function +GL_PREFIX(VertexAttribI1iEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6616(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6616(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6616(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6616(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI1iEXT), .-GL_PREFIX(VertexAttribI1iEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI1ivEXT) + .type GL_PREFIX(VertexAttribI1ivEXT), @function +GL_PREFIX(VertexAttribI1ivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6624(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6624(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6624(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6624(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI1ivEXT), .-GL_PREFIX(VertexAttribI1ivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI1uiEXT) + .type GL_PREFIX(VertexAttribI1uiEXT), @function +GL_PREFIX(VertexAttribI1uiEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6632(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6632(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6632(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6632(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI1uiEXT), .-GL_PREFIX(VertexAttribI1uiEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI1uivEXT) + .type GL_PREFIX(VertexAttribI1uivEXT), @function +GL_PREFIX(VertexAttribI1uivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6640(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6640(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6640(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6640(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI1uivEXT), .-GL_PREFIX(VertexAttribI1uivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI2iEXT) + .type GL_PREFIX(VertexAttribI2iEXT), @function +GL_PREFIX(VertexAttribI2iEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6648(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6648(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6648(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6648(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI2iEXT), .-GL_PREFIX(VertexAttribI2iEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI2ivEXT) + .type GL_PREFIX(VertexAttribI2ivEXT), @function +GL_PREFIX(VertexAttribI2ivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6656(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6656(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6656(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6656(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI2ivEXT), .-GL_PREFIX(VertexAttribI2ivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI2uiEXT) + .type GL_PREFIX(VertexAttribI2uiEXT), @function +GL_PREFIX(VertexAttribI2uiEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6664(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6664(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6664(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6664(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI2uiEXT), .-GL_PREFIX(VertexAttribI2uiEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI2uivEXT) + .type GL_PREFIX(VertexAttribI2uivEXT), @function +GL_PREFIX(VertexAttribI2uivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6672(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6672(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6672(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6672(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI2uivEXT), .-GL_PREFIX(VertexAttribI2uivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI3iEXT) + .type GL_PREFIX(VertexAttribI3iEXT), @function +GL_PREFIX(VertexAttribI3iEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6680(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6680(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6680(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6680(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI3iEXT), .-GL_PREFIX(VertexAttribI3iEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI3ivEXT) + .type GL_PREFIX(VertexAttribI3ivEXT), @function +GL_PREFIX(VertexAttribI3ivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6688(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6688(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6688(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6688(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI3ivEXT), .-GL_PREFIX(VertexAttribI3ivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI3uiEXT) + .type GL_PREFIX(VertexAttribI3uiEXT), @function +GL_PREFIX(VertexAttribI3uiEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6696(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6696(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6696(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6696(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI3uiEXT), .-GL_PREFIX(VertexAttribI3uiEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI3uivEXT) + .type GL_PREFIX(VertexAttribI3uivEXT), @function +GL_PREFIX(VertexAttribI3uivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6704(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6704(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6704(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6704(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI3uivEXT), .-GL_PREFIX(VertexAttribI3uivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI4bvEXT) + .type GL_PREFIX(VertexAttribI4bvEXT), @function +GL_PREFIX(VertexAttribI4bvEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6712(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6712(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6712(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6712(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI4bvEXT), .-GL_PREFIX(VertexAttribI4bvEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI4iEXT) + .type GL_PREFIX(VertexAttribI4iEXT), @function +GL_PREFIX(VertexAttribI4iEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6720(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6720(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6720(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6720(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI4iEXT), .-GL_PREFIX(VertexAttribI4iEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI4ivEXT) + .type GL_PREFIX(VertexAttribI4ivEXT), @function +GL_PREFIX(VertexAttribI4ivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6728(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6728(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6728(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6728(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI4ivEXT), .-GL_PREFIX(VertexAttribI4ivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI4svEXT) + .type GL_PREFIX(VertexAttribI4svEXT), @function +GL_PREFIX(VertexAttribI4svEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6736(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6736(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6736(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6736(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI4svEXT), .-GL_PREFIX(VertexAttribI4svEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI4ubvEXT) + .type GL_PREFIX(VertexAttribI4ubvEXT), @function +GL_PREFIX(VertexAttribI4ubvEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6744(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6744(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6744(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6744(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI4ubvEXT), .-GL_PREFIX(VertexAttribI4ubvEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI4uiEXT) + .type GL_PREFIX(VertexAttribI4uiEXT), @function +GL_PREFIX(VertexAttribI4uiEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6752(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6752(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6752(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6752(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI4uiEXT), .-GL_PREFIX(VertexAttribI4uiEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI4uivEXT) + .type GL_PREFIX(VertexAttribI4uivEXT), @function +GL_PREFIX(VertexAttribI4uivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6760(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6760(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6760(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6760(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI4uivEXT), .-GL_PREFIX(VertexAttribI4uivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribI4usvEXT) + .type GL_PREFIX(VertexAttribI4usvEXT), @function +GL_PREFIX(VertexAttribI4usvEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6768(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6768(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6768(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6768(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribI4usvEXT), .-GL_PREFIX(VertexAttribI4usvEXT) + + .p2align 4,,15 + .globl GL_PREFIX(VertexAttribIPointerEXT) + .type GL_PREFIX(VertexAttribIPointerEXT), @function +GL_PREFIX(VertexAttribIPointerEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6776(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6776(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6776(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6776(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(VertexAttribIPointerEXT), .-GL_PREFIX(VertexAttribIPointerEXT) + + .p2align 4,,15 + .globl GL_PREFIX(FramebufferTextureLayerEXT) + .type GL_PREFIX(FramebufferTextureLayerEXT), @function +GL_PREFIX(FramebufferTextureLayerEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6784(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6784(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6784(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6784(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(FramebufferTextureLayerEXT), .-GL_PREFIX(FramebufferTextureLayerEXT) + + .p2align 4,,15 + .globl GL_PREFIX(ColorMaskIndexedEXT) + .type GL_PREFIX(ColorMaskIndexedEXT), @function +GL_PREFIX(ColorMaskIndexedEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6792(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6792(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6792(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6792(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ColorMaskIndexedEXT), .-GL_PREFIX(ColorMaskIndexedEXT) + + .p2align 4,,15 + .globl GL_PREFIX(DisableIndexedEXT) + .type GL_PREFIX(DisableIndexedEXT), @function +GL_PREFIX(DisableIndexedEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6800(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6800(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6800(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6800(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(DisableIndexedEXT), .-GL_PREFIX(DisableIndexedEXT) + + .p2align 4,,15 + .globl GL_PREFIX(EnableIndexedEXT) + .type GL_PREFIX(EnableIndexedEXT), @function +GL_PREFIX(EnableIndexedEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6808(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6808(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6808(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6808(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EnableIndexedEXT), .-GL_PREFIX(EnableIndexedEXT) + + .p2align 4,,15 + .globl GL_PREFIX(GetBooleanIndexedvEXT) + .type GL_PREFIX(GetBooleanIndexedvEXT), @function +GL_PREFIX(GetBooleanIndexedvEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6816(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6816(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6816(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6816(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetBooleanIndexedvEXT), .-GL_PREFIX(GetBooleanIndexedvEXT) + + .p2align 4,,15 + .globl GL_PREFIX(GetIntegerIndexedvEXT) + .type GL_PREFIX(GetIntegerIndexedvEXT), @function +GL_PREFIX(GetIntegerIndexedvEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6824(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6824(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6824(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6824(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetIntegerIndexedvEXT), .-GL_PREFIX(GetIntegerIndexedvEXT) + + .p2align 4,,15 + .globl GL_PREFIX(IsEnabledIndexedEXT) + .type GL_PREFIX(IsEnabledIndexedEXT), @function +GL_PREFIX(IsEnabledIndexedEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6832(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6832(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6832(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6832(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(IsEnabledIndexedEXT), .-GL_PREFIX(IsEnabledIndexedEXT) + + .p2align 4,,15 + .globl GL_PREFIX(ClearColorIiEXT) + .type GL_PREFIX(ClearColorIiEXT), @function +GL_PREFIX(ClearColorIiEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6840(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6840(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6840(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6840(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClearColorIiEXT), .-GL_PREFIX(ClearColorIiEXT) + + .p2align 4,,15 + .globl GL_PREFIX(ClearColorIuiEXT) + .type GL_PREFIX(ClearColorIuiEXT), @function +GL_PREFIX(ClearColorIuiEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6848(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6848(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6848(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6848(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ClearColorIuiEXT), .-GL_PREFIX(ClearColorIuiEXT) + + .p2align 4,,15 + .globl GL_PREFIX(GetTexParameterIivEXT) + .type GL_PREFIX(GetTexParameterIivEXT), @function +GL_PREFIX(GetTexParameterIivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6856(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6856(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6856(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6856(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTexParameterIivEXT), .-GL_PREFIX(GetTexParameterIivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(GetTexParameterIuivEXT) + .type GL_PREFIX(GetTexParameterIuivEXT), @function +GL_PREFIX(GetTexParameterIuivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6864(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6864(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6864(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6864(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTexParameterIuivEXT), .-GL_PREFIX(GetTexParameterIuivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(TexParameterIivEXT) + .type GL_PREFIX(TexParameterIivEXT), @function +GL_PREFIX(TexParameterIivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6872(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6872(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6872(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6872(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexParameterIivEXT), .-GL_PREFIX(TexParameterIivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(TexParameterIuivEXT) + .type GL_PREFIX(TexParameterIuivEXT), @function +GL_PREFIX(TexParameterIuivEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6880(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6880(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6880(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6880(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TexParameterIuivEXT), .-GL_PREFIX(TexParameterIuivEXT) + + .p2align 4,,15 + .globl GL_PREFIX(BeginConditionalRenderNV) + .type GL_PREFIX(BeginConditionalRenderNV), @function +GL_PREFIX(BeginConditionalRenderNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6888(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 6888(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6888(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 6888(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BeginConditionalRenderNV), .-GL_PREFIX(BeginConditionalRenderNV) + + .p2align 4,,15 + .globl GL_PREFIX(EndConditionalRenderNV) + .type GL_PREFIX(EndConditionalRenderNV), @function +GL_PREFIX(EndConditionalRenderNV): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6896(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 6896(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6896(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 6896(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EndConditionalRenderNV), .-GL_PREFIX(EndConditionalRenderNV) + + .p2align 4,,15 + .globl GL_PREFIX(BeginTransformFeedbackEXT) + .type GL_PREFIX(BeginTransformFeedbackEXT), @function +GL_PREFIX(BeginTransformFeedbackEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6904(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 6904(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6904(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 6904(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BeginTransformFeedbackEXT), .-GL_PREFIX(BeginTransformFeedbackEXT) + + .p2align 4,,15 + .globl GL_PREFIX(BindBufferBaseEXT) + .type GL_PREFIX(BindBufferBaseEXT), @function +GL_PREFIX(BindBufferBaseEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6912(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6912(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6912(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6912(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BindBufferBaseEXT), .-GL_PREFIX(BindBufferBaseEXT) + + .p2align 4,,15 + .globl GL_PREFIX(BindBufferOffsetEXT) + .type GL_PREFIX(BindBufferOffsetEXT), @function +GL_PREFIX(BindBufferOffsetEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6920(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6920(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6920(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6920(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BindBufferOffsetEXT), .-GL_PREFIX(BindBufferOffsetEXT) + + .p2align 4,,15 + .globl GL_PREFIX(BindBufferRangeEXT) + .type GL_PREFIX(BindBufferRangeEXT), @function +GL_PREFIX(BindBufferRangeEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6928(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _x86_64_get_dispatch@PLT + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6928(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6928(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + call _glapi_get_dispatch + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6928(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(BindBufferRangeEXT), .-GL_PREFIX(BindBufferRangeEXT) + + .p2align 4,,15 + .globl GL_PREFIX(EndTransformFeedbackEXT) + .type GL_PREFIX(EndTransformFeedbackEXT), @function +GL_PREFIX(EndTransformFeedbackEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6936(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + movq 6936(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6936(%rax), %r11 + jmp *%r11 +1: + pushq %rbp + call _glapi_get_dispatch + popq %rbp + movq 6936(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EndTransformFeedbackEXT), .-GL_PREFIX(EndTransformFeedbackEXT) + + .p2align 4,,15 + .globl GL_PREFIX(GetTransformFeedbackVaryingEXT) + .type GL_PREFIX(GetTransformFeedbackVaryingEXT), @function +GL_PREFIX(GetTransformFeedbackVaryingEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6944(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6944(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6944(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %r8 + pushq %r9 + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %r9 + popq %r8 + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6944(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetTransformFeedbackVaryingEXT), .-GL_PREFIX(GetTransformFeedbackVaryingEXT) + + .p2align 4,,15 + .globl GL_PREFIX(TransformFeedbackVaryingsEXT) + .type GL_PREFIX(TransformFeedbackVaryingsEXT), @function +GL_PREFIX(TransformFeedbackVaryingsEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6952(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6952(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6952(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6952(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(TransformFeedbackVaryingsEXT), .-GL_PREFIX(TransformFeedbackVaryingsEXT) + + .p2align 4,,15 + .globl GL_PREFIX(ProvokingVertexEXT) + .type GL_PREFIX(ProvokingVertexEXT), @function +GL_PREFIX(ProvokingVertexEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6960(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 6960(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6960(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 6960(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ProvokingVertexEXT), .-GL_PREFIX(ProvokingVertexEXT) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_871) + .type GL_PREFIX(_dispatch_stub_871), @function + HIDDEN(GL_PREFIX(_dispatch_stub_871)) +GL_PREFIX(_dispatch_stub_871): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6968(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6968(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6968(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6968(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_871), .-GL_PREFIX(_dispatch_stub_871) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_872) + .type GL_PREFIX(_dispatch_stub_872), @function + HIDDEN(GL_PREFIX(_dispatch_stub_872)) +GL_PREFIX(_dispatch_stub_872): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6976(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6976(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6976(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6976(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_872), .-GL_PREFIX(_dispatch_stub_872) + + .p2align 4,,15 + .globl GL_PREFIX(GetObjectParameterivAPPLE) + .type GL_PREFIX(GetObjectParameterivAPPLE), @function +GL_PREFIX(GetObjectParameterivAPPLE): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6984(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6984(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6984(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 6984(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(GetObjectParameterivAPPLE), .-GL_PREFIX(GetObjectParameterivAPPLE) + + .p2align 4,,15 + .globl GL_PREFIX(ObjectPurgeableAPPLE) + .type GL_PREFIX(ObjectPurgeableAPPLE), @function +GL_PREFIX(ObjectPurgeableAPPLE): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 6992(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 6992(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 6992(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 6992(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ObjectPurgeableAPPLE), .-GL_PREFIX(ObjectPurgeableAPPLE) + + .p2align 4,,15 + .globl GL_PREFIX(ObjectUnpurgeableAPPLE) + .type GL_PREFIX(ObjectUnpurgeableAPPLE), @function +GL_PREFIX(ObjectUnpurgeableAPPLE): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 7000(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 7000(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 7000(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 7000(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ObjectUnpurgeableAPPLE), .-GL_PREFIX(ObjectUnpurgeableAPPLE) + + .p2align 4,,15 + .globl GL_PREFIX(ActiveProgramEXT) + .type GL_PREFIX(ActiveProgramEXT), @function +GL_PREFIX(ActiveProgramEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 7008(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + call _x86_64_get_dispatch@PLT + popq %rdi + movq 7008(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 7008(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + call _glapi_get_dispatch + popq %rdi + movq 7008(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(ActiveProgramEXT), .-GL_PREFIX(ActiveProgramEXT) + + .p2align 4,,15 + .globl GL_PREFIX(CreateShaderProgramEXT) + .type GL_PREFIX(CreateShaderProgramEXT), @function +GL_PREFIX(CreateShaderProgramEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 7016(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 7016(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 7016(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 7016(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(CreateShaderProgramEXT), .-GL_PREFIX(CreateShaderProgramEXT) + + .p2align 4,,15 + .globl GL_PREFIX(UseShaderProgramEXT) + .type GL_PREFIX(UseShaderProgramEXT), @function +GL_PREFIX(UseShaderProgramEXT): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 7024(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 7024(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 7024(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 7024(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(UseShaderProgramEXT), .-GL_PREFIX(UseShaderProgramEXT) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_879) + .type GL_PREFIX(_dispatch_stub_879), @function + HIDDEN(GL_PREFIX(_dispatch_stub_879)) +GL_PREFIX(_dispatch_stub_879): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 7032(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 7032(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 7032(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 7032(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_879), .-GL_PREFIX(_dispatch_stub_879) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_880) + .type GL_PREFIX(_dispatch_stub_880), @function + HIDDEN(GL_PREFIX(_dispatch_stub_880)) +GL_PREFIX(_dispatch_stub_880): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 7040(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 7040(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 7040(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 7040(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_880), .-GL_PREFIX(_dispatch_stub_880) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_881) + .type GL_PREFIX(_dispatch_stub_881), @function + HIDDEN(GL_PREFIX(_dispatch_stub_881)) +GL_PREFIX(_dispatch_stub_881): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 7048(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 7048(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 7048(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + pushq %rcx + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rcx + popq %rdx + popq %rsi + popq %rdi + movq 7048(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_881), .-GL_PREFIX(_dispatch_stub_881) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_882) + .type GL_PREFIX(_dispatch_stub_882), @function + HIDDEN(GL_PREFIX(_dispatch_stub_882)) +GL_PREFIX(_dispatch_stub_882): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 7056(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 7056(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 7056(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 7056(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_882), .-GL_PREFIX(_dispatch_stub_882) + + .p2align 4,,15 + .globl GL_PREFIX(_dispatch_stub_883) + .type GL_PREFIX(_dispatch_stub_883), @function + HIDDEN(GL_PREFIX(_dispatch_stub_883)) +GL_PREFIX(_dispatch_stub_883): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 7064(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rdx + call _x86_64_get_dispatch@PLT + popq %rdx + popq %rsi + popq %rdi + movq 7064(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 7064(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rdx + call _glapi_get_dispatch + popq %rdx + popq %rsi + popq %rdi + movq 7064(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(_dispatch_stub_883), .-GL_PREFIX(_dispatch_stub_883) + + .p2align 4,,15 + .globl GL_PREFIX(EGLImageTargetRenderbufferStorageOES) + .type GL_PREFIX(EGLImageTargetRenderbufferStorageOES), @function +GL_PREFIX(EGLImageTargetRenderbufferStorageOES): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 7072(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 7072(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 7072(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 7072(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EGLImageTargetRenderbufferStorageOES), .-GL_PREFIX(EGLImageTargetRenderbufferStorageOES) + + .p2align 4,,15 + .globl GL_PREFIX(EGLImageTargetTexture2DOES) + .type GL_PREFIX(EGLImageTargetTexture2DOES), @function +GL_PREFIX(EGLImageTargetTexture2DOES): +#if defined(GLX_USE_TLS) + call _x86_64_get_dispatch@PLT + movq 7080(%rax), %r11 + jmp *%r11 +#elif defined(PTHREADS) + pushq %rdi + pushq %rsi + pushq %rbp + call _x86_64_get_dispatch@PLT + popq %rbp + popq %rsi + popq %rdi + movq 7080(%rax), %r11 + jmp *%r11 +#else + movq _glapi_Dispatch(%rip), %rax + testq %rax, %rax + je 1f + movq 7080(%rax), %r11 + jmp *%r11 +1: + pushq %rdi + pushq %rsi + pushq %rbp + call _glapi_get_dispatch + popq %rbp + popq %rsi + popq %rdi + movq 7080(%rax), %r11 + jmp *%r11 +#endif /* defined(GLX_USE_TLS) */ + .size GL_PREFIX(EGLImageTargetTexture2DOES), .-GL_PREFIX(EGLImageTargetTexture2DOES) + + .globl GL_PREFIX(ArrayElementEXT) ; .set GL_PREFIX(ArrayElementEXT), GL_PREFIX(ArrayElement) + .globl GL_PREFIX(BindTextureEXT) ; .set GL_PREFIX(BindTextureEXT), GL_PREFIX(BindTexture) + .globl GL_PREFIX(DrawArraysEXT) ; .set GL_PREFIX(DrawArraysEXT), GL_PREFIX(DrawArrays) +#ifndef GLX_INDIRECT_RENDERING + .globl GL_PREFIX(AreTexturesResidentEXT) ; .set GL_PREFIX(AreTexturesResidentEXT), GL_PREFIX(AreTexturesResident) +#endif + .globl GL_PREFIX(CopyTexImage1DEXT) ; .set GL_PREFIX(CopyTexImage1DEXT), GL_PREFIX(CopyTexImage1D) + .globl GL_PREFIX(CopyTexImage2DEXT) ; .set GL_PREFIX(CopyTexImage2DEXT), GL_PREFIX(CopyTexImage2D) + .globl GL_PREFIX(CopyTexSubImage1DEXT) ; .set GL_PREFIX(CopyTexSubImage1DEXT), GL_PREFIX(CopyTexSubImage1D) + .globl GL_PREFIX(CopyTexSubImage2DEXT) ; .set GL_PREFIX(CopyTexSubImage2DEXT), GL_PREFIX(CopyTexSubImage2D) +#ifndef GLX_INDIRECT_RENDERING + .globl GL_PREFIX(DeleteTexturesEXT) ; .set GL_PREFIX(DeleteTexturesEXT), GL_PREFIX(DeleteTextures) +#endif +#ifndef GLX_INDIRECT_RENDERING + .globl GL_PREFIX(GenTexturesEXT) ; .set GL_PREFIX(GenTexturesEXT), GL_PREFIX(GenTextures) +#endif + .globl GL_PREFIX(GetPointervEXT) ; .set GL_PREFIX(GetPointervEXT), GL_PREFIX(GetPointerv) +#ifndef GLX_INDIRECT_RENDERING + .globl GL_PREFIX(IsTextureEXT) ; .set GL_PREFIX(IsTextureEXT), GL_PREFIX(IsTexture) +#endif + .globl GL_PREFIX(PrioritizeTexturesEXT) ; .set GL_PREFIX(PrioritizeTexturesEXT), GL_PREFIX(PrioritizeTextures) + .globl GL_PREFIX(TexSubImage1DEXT) ; .set GL_PREFIX(TexSubImage1DEXT), GL_PREFIX(TexSubImage1D) + .globl GL_PREFIX(TexSubImage2DEXT) ; .set GL_PREFIX(TexSubImage2DEXT), GL_PREFIX(TexSubImage2D) + .globl GL_PREFIX(BlendColorEXT) ; .set GL_PREFIX(BlendColorEXT), GL_PREFIX(BlendColor) + .globl GL_PREFIX(BlendEquationEXT) ; .set GL_PREFIX(BlendEquationEXT), GL_PREFIX(BlendEquation) + .globl GL_PREFIX(DrawRangeElementsEXT) ; .set GL_PREFIX(DrawRangeElementsEXT), GL_PREFIX(DrawRangeElements) + .globl GL_PREFIX(ColorTableEXT) ; .set GL_PREFIX(ColorTableEXT), GL_PREFIX(ColorTable) +#ifndef GLX_INDIRECT_RENDERING + .globl GL_PREFIX(GetColorTableEXT) ; .set GL_PREFIX(GetColorTableEXT), GL_PREFIX(GetColorTable) +#endif +#ifndef GLX_INDIRECT_RENDERING + .globl GL_PREFIX(GetColorTableParameterfvEXT) ; .set GL_PREFIX(GetColorTableParameterfvEXT), GL_PREFIX(GetColorTableParameterfv) +#endif +#ifndef GLX_INDIRECT_RENDERING + .globl GL_PREFIX(GetColorTableParameterivEXT) ; .set GL_PREFIX(GetColorTableParameterivEXT), GL_PREFIX(GetColorTableParameteriv) +#endif + .globl GL_PREFIX(TexImage3DEXT) ; .set GL_PREFIX(TexImage3DEXT), GL_PREFIX(TexImage3D) + .globl GL_PREFIX(TexSubImage3DEXT) ; .set GL_PREFIX(TexSubImage3DEXT), GL_PREFIX(TexSubImage3D) + .globl GL_PREFIX(CopyTexSubImage3DEXT) ; .set GL_PREFIX(CopyTexSubImage3DEXT), GL_PREFIX(CopyTexSubImage3D) + .globl GL_PREFIX(ActiveTexture) ; .set GL_PREFIX(ActiveTexture), GL_PREFIX(ActiveTextureARB) + .globl GL_PREFIX(ClientActiveTexture) ; .set GL_PREFIX(ClientActiveTexture), GL_PREFIX(ClientActiveTextureARB) + .globl GL_PREFIX(MultiTexCoord1d) ; .set GL_PREFIX(MultiTexCoord1d), GL_PREFIX(MultiTexCoord1dARB) + .globl GL_PREFIX(MultiTexCoord1dv) ; .set GL_PREFIX(MultiTexCoord1dv), GL_PREFIX(MultiTexCoord1dvARB) + .globl GL_PREFIX(MultiTexCoord1f) ; .set GL_PREFIX(MultiTexCoord1f), GL_PREFIX(MultiTexCoord1fARB) + .globl GL_PREFIX(MultiTexCoord1fv) ; .set GL_PREFIX(MultiTexCoord1fv), GL_PREFIX(MultiTexCoord1fvARB) + .globl GL_PREFIX(MultiTexCoord1i) ; .set GL_PREFIX(MultiTexCoord1i), GL_PREFIX(MultiTexCoord1iARB) + .globl GL_PREFIX(MultiTexCoord1iv) ; .set GL_PREFIX(MultiTexCoord1iv), GL_PREFIX(MultiTexCoord1ivARB) + .globl GL_PREFIX(MultiTexCoord1s) ; .set GL_PREFIX(MultiTexCoord1s), GL_PREFIX(MultiTexCoord1sARB) + .globl GL_PREFIX(MultiTexCoord1sv) ; .set GL_PREFIX(MultiTexCoord1sv), GL_PREFIX(MultiTexCoord1svARB) + .globl GL_PREFIX(MultiTexCoord2d) ; .set GL_PREFIX(MultiTexCoord2d), GL_PREFIX(MultiTexCoord2dARB) + .globl GL_PREFIX(MultiTexCoord2dv) ; .set GL_PREFIX(MultiTexCoord2dv), GL_PREFIX(MultiTexCoord2dvARB) + .globl GL_PREFIX(MultiTexCoord2f) ; .set GL_PREFIX(MultiTexCoord2f), GL_PREFIX(MultiTexCoord2fARB) + .globl GL_PREFIX(MultiTexCoord2fv) ; .set GL_PREFIX(MultiTexCoord2fv), GL_PREFIX(MultiTexCoord2fvARB) + .globl GL_PREFIX(MultiTexCoord2i) ; .set GL_PREFIX(MultiTexCoord2i), GL_PREFIX(MultiTexCoord2iARB) + .globl GL_PREFIX(MultiTexCoord2iv) ; .set GL_PREFIX(MultiTexCoord2iv), GL_PREFIX(MultiTexCoord2ivARB) + .globl GL_PREFIX(MultiTexCoord2s) ; .set GL_PREFIX(MultiTexCoord2s), GL_PREFIX(MultiTexCoord2sARB) + .globl GL_PREFIX(MultiTexCoord2sv) ; .set GL_PREFIX(MultiTexCoord2sv), GL_PREFIX(MultiTexCoord2svARB) + .globl GL_PREFIX(MultiTexCoord3d) ; .set GL_PREFIX(MultiTexCoord3d), GL_PREFIX(MultiTexCoord3dARB) + .globl GL_PREFIX(MultiTexCoord3dv) ; .set GL_PREFIX(MultiTexCoord3dv), GL_PREFIX(MultiTexCoord3dvARB) + .globl GL_PREFIX(MultiTexCoord3f) ; .set GL_PREFIX(MultiTexCoord3f), GL_PREFIX(MultiTexCoord3fARB) + .globl GL_PREFIX(MultiTexCoord3fv) ; .set GL_PREFIX(MultiTexCoord3fv), GL_PREFIX(MultiTexCoord3fvARB) + .globl GL_PREFIX(MultiTexCoord3i) ; .set GL_PREFIX(MultiTexCoord3i), GL_PREFIX(MultiTexCoord3iARB) + .globl GL_PREFIX(MultiTexCoord3iv) ; .set GL_PREFIX(MultiTexCoord3iv), GL_PREFIX(MultiTexCoord3ivARB) + .globl GL_PREFIX(MultiTexCoord3s) ; .set GL_PREFIX(MultiTexCoord3s), GL_PREFIX(MultiTexCoord3sARB) + .globl GL_PREFIX(MultiTexCoord3sv) ; .set GL_PREFIX(MultiTexCoord3sv), GL_PREFIX(MultiTexCoord3svARB) + .globl GL_PREFIX(MultiTexCoord4d) ; .set GL_PREFIX(MultiTexCoord4d), GL_PREFIX(MultiTexCoord4dARB) + .globl GL_PREFIX(MultiTexCoord4dv) ; .set GL_PREFIX(MultiTexCoord4dv), GL_PREFIX(MultiTexCoord4dvARB) + .globl GL_PREFIX(MultiTexCoord4f) ; .set GL_PREFIX(MultiTexCoord4f), GL_PREFIX(MultiTexCoord4fARB) + .globl GL_PREFIX(MultiTexCoord4fv) ; .set GL_PREFIX(MultiTexCoord4fv), GL_PREFIX(MultiTexCoord4fvARB) + .globl GL_PREFIX(MultiTexCoord4i) ; .set GL_PREFIX(MultiTexCoord4i), GL_PREFIX(MultiTexCoord4iARB) + .globl GL_PREFIX(MultiTexCoord4iv) ; .set GL_PREFIX(MultiTexCoord4iv), GL_PREFIX(MultiTexCoord4ivARB) + .globl GL_PREFIX(MultiTexCoord4s) ; .set GL_PREFIX(MultiTexCoord4s), GL_PREFIX(MultiTexCoord4sARB) + .globl GL_PREFIX(MultiTexCoord4sv) ; .set GL_PREFIX(MultiTexCoord4sv), GL_PREFIX(MultiTexCoord4svARB) + .globl GL_PREFIX(LoadTransposeMatrixd) ; .set GL_PREFIX(LoadTransposeMatrixd), GL_PREFIX(LoadTransposeMatrixdARB) + .globl GL_PREFIX(LoadTransposeMatrixf) ; .set GL_PREFIX(LoadTransposeMatrixf), GL_PREFIX(LoadTransposeMatrixfARB) + .globl GL_PREFIX(MultTransposeMatrixd) ; .set GL_PREFIX(MultTransposeMatrixd), GL_PREFIX(MultTransposeMatrixdARB) + .globl GL_PREFIX(MultTransposeMatrixf) ; .set GL_PREFIX(MultTransposeMatrixf), GL_PREFIX(MultTransposeMatrixfARB) + .globl GL_PREFIX(SampleCoverage) ; .set GL_PREFIX(SampleCoverage), GL_PREFIX(SampleCoverageARB) + .globl GL_PREFIX(CompressedTexImage1D) ; .set GL_PREFIX(CompressedTexImage1D), GL_PREFIX(CompressedTexImage1DARB) + .globl GL_PREFIX(CompressedTexImage2D) ; .set GL_PREFIX(CompressedTexImage2D), GL_PREFIX(CompressedTexImage2DARB) + .globl GL_PREFIX(CompressedTexImage3D) ; .set GL_PREFIX(CompressedTexImage3D), GL_PREFIX(CompressedTexImage3DARB) + .globl GL_PREFIX(CompressedTexSubImage1D) ; .set GL_PREFIX(CompressedTexSubImage1D), GL_PREFIX(CompressedTexSubImage1DARB) + .globl GL_PREFIX(CompressedTexSubImage2D) ; .set GL_PREFIX(CompressedTexSubImage2D), GL_PREFIX(CompressedTexSubImage2DARB) + .globl GL_PREFIX(CompressedTexSubImage3D) ; .set GL_PREFIX(CompressedTexSubImage3D), GL_PREFIX(CompressedTexSubImage3DARB) + .globl GL_PREFIX(GetCompressedTexImage) ; .set GL_PREFIX(GetCompressedTexImage), GL_PREFIX(GetCompressedTexImageARB) + .globl GL_PREFIX(DisableVertexAttribArray) ; .set GL_PREFIX(DisableVertexAttribArray), GL_PREFIX(DisableVertexAttribArrayARB) + .globl GL_PREFIX(EnableVertexAttribArray) ; .set GL_PREFIX(EnableVertexAttribArray), GL_PREFIX(EnableVertexAttribArrayARB) + .globl GL_PREFIX(GetVertexAttribdv) ; .set GL_PREFIX(GetVertexAttribdv), GL_PREFIX(GetVertexAttribdvARB) + .globl GL_PREFIX(GetVertexAttribfv) ; .set GL_PREFIX(GetVertexAttribfv), GL_PREFIX(GetVertexAttribfvARB) + .globl GL_PREFIX(GetVertexAttribiv) ; .set GL_PREFIX(GetVertexAttribiv), GL_PREFIX(GetVertexAttribivARB) + .globl GL_PREFIX(ProgramParameter4dNV) ; .set GL_PREFIX(ProgramParameter4dNV), GL_PREFIX(ProgramEnvParameter4dARB) + .globl GL_PREFIX(ProgramParameter4dvNV) ; .set GL_PREFIX(ProgramParameter4dvNV), GL_PREFIX(ProgramEnvParameter4dvARB) + .globl GL_PREFIX(ProgramParameter4fNV) ; .set GL_PREFIX(ProgramParameter4fNV), GL_PREFIX(ProgramEnvParameter4fARB) + .globl GL_PREFIX(ProgramParameter4fvNV) ; .set GL_PREFIX(ProgramParameter4fvNV), GL_PREFIX(ProgramEnvParameter4fvARB) + .globl GL_PREFIX(VertexAttrib1d) ; .set GL_PREFIX(VertexAttrib1d), GL_PREFIX(VertexAttrib1dARB) + .globl GL_PREFIX(VertexAttrib1dv) ; .set GL_PREFIX(VertexAttrib1dv), GL_PREFIX(VertexAttrib1dvARB) + .globl GL_PREFIX(VertexAttrib1f) ; .set GL_PREFIX(VertexAttrib1f), GL_PREFIX(VertexAttrib1fARB) + .globl GL_PREFIX(VertexAttrib1fv) ; .set GL_PREFIX(VertexAttrib1fv), GL_PREFIX(VertexAttrib1fvARB) + .globl GL_PREFIX(VertexAttrib1s) ; .set GL_PREFIX(VertexAttrib1s), GL_PREFIX(VertexAttrib1sARB) + .globl GL_PREFIX(VertexAttrib1sv) ; .set GL_PREFIX(VertexAttrib1sv), GL_PREFIX(VertexAttrib1svARB) + .globl GL_PREFIX(VertexAttrib2d) ; .set GL_PREFIX(VertexAttrib2d), GL_PREFIX(VertexAttrib2dARB) + .globl GL_PREFIX(VertexAttrib2dv) ; .set GL_PREFIX(VertexAttrib2dv), GL_PREFIX(VertexAttrib2dvARB) + .globl GL_PREFIX(VertexAttrib2f) ; .set GL_PREFIX(VertexAttrib2f), GL_PREFIX(VertexAttrib2fARB) + .globl GL_PREFIX(VertexAttrib2fv) ; .set GL_PREFIX(VertexAttrib2fv), GL_PREFIX(VertexAttrib2fvARB) + .globl GL_PREFIX(VertexAttrib2s) ; .set GL_PREFIX(VertexAttrib2s), GL_PREFIX(VertexAttrib2sARB) + .globl GL_PREFIX(VertexAttrib2sv) ; .set GL_PREFIX(VertexAttrib2sv), GL_PREFIX(VertexAttrib2svARB) + .globl GL_PREFIX(VertexAttrib3d) ; .set GL_PREFIX(VertexAttrib3d), GL_PREFIX(VertexAttrib3dARB) + .globl GL_PREFIX(VertexAttrib3dv) ; .set GL_PREFIX(VertexAttrib3dv), GL_PREFIX(VertexAttrib3dvARB) + .globl GL_PREFIX(VertexAttrib3f) ; .set GL_PREFIX(VertexAttrib3f), GL_PREFIX(VertexAttrib3fARB) + .globl GL_PREFIX(VertexAttrib3fv) ; .set GL_PREFIX(VertexAttrib3fv), GL_PREFIX(VertexAttrib3fvARB) + .globl GL_PREFIX(VertexAttrib3s) ; .set GL_PREFIX(VertexAttrib3s), GL_PREFIX(VertexAttrib3sARB) + .globl GL_PREFIX(VertexAttrib3sv) ; .set GL_PREFIX(VertexAttrib3sv), GL_PREFIX(VertexAttrib3svARB) + .globl GL_PREFIX(VertexAttrib4Nbv) ; .set GL_PREFIX(VertexAttrib4Nbv), GL_PREFIX(VertexAttrib4NbvARB) + .globl GL_PREFIX(VertexAttrib4Niv) ; .set GL_PREFIX(VertexAttrib4Niv), GL_PREFIX(VertexAttrib4NivARB) + .globl GL_PREFIX(VertexAttrib4Nsv) ; .set GL_PREFIX(VertexAttrib4Nsv), GL_PREFIX(VertexAttrib4NsvARB) + .globl GL_PREFIX(VertexAttrib4Nub) ; .set GL_PREFIX(VertexAttrib4Nub), GL_PREFIX(VertexAttrib4NubARB) + .globl GL_PREFIX(VertexAttrib4Nubv) ; .set GL_PREFIX(VertexAttrib4Nubv), GL_PREFIX(VertexAttrib4NubvARB) + .globl GL_PREFIX(VertexAttrib4Nuiv) ; .set GL_PREFIX(VertexAttrib4Nuiv), GL_PREFIX(VertexAttrib4NuivARB) + .globl GL_PREFIX(VertexAttrib4Nusv) ; .set GL_PREFIX(VertexAttrib4Nusv), GL_PREFIX(VertexAttrib4NusvARB) + .globl GL_PREFIX(VertexAttrib4bv) ; .set GL_PREFIX(VertexAttrib4bv), GL_PREFIX(VertexAttrib4bvARB) + .globl GL_PREFIX(VertexAttrib4d) ; .set GL_PREFIX(VertexAttrib4d), GL_PREFIX(VertexAttrib4dARB) + .globl GL_PREFIX(VertexAttrib4dv) ; .set GL_PREFIX(VertexAttrib4dv), GL_PREFIX(VertexAttrib4dvARB) + .globl GL_PREFIX(VertexAttrib4f) ; .set GL_PREFIX(VertexAttrib4f), GL_PREFIX(VertexAttrib4fARB) + .globl GL_PREFIX(VertexAttrib4fv) ; .set GL_PREFIX(VertexAttrib4fv), GL_PREFIX(VertexAttrib4fvARB) + .globl GL_PREFIX(VertexAttrib4iv) ; .set GL_PREFIX(VertexAttrib4iv), GL_PREFIX(VertexAttrib4ivARB) + .globl GL_PREFIX(VertexAttrib4s) ; .set GL_PREFIX(VertexAttrib4s), GL_PREFIX(VertexAttrib4sARB) + .globl GL_PREFIX(VertexAttrib4sv) ; .set GL_PREFIX(VertexAttrib4sv), GL_PREFIX(VertexAttrib4svARB) + .globl GL_PREFIX(VertexAttrib4ubv) ; .set GL_PREFIX(VertexAttrib4ubv), GL_PREFIX(VertexAttrib4ubvARB) + .globl GL_PREFIX(VertexAttrib4uiv) ; .set GL_PREFIX(VertexAttrib4uiv), GL_PREFIX(VertexAttrib4uivARB) + .globl GL_PREFIX(VertexAttrib4usv) ; .set GL_PREFIX(VertexAttrib4usv), GL_PREFIX(VertexAttrib4usvARB) + .globl GL_PREFIX(VertexAttribPointer) ; .set GL_PREFIX(VertexAttribPointer), GL_PREFIX(VertexAttribPointerARB) + .globl GL_PREFIX(BindBuffer) ; .set GL_PREFIX(BindBuffer), GL_PREFIX(BindBufferARB) + .globl GL_PREFIX(BufferData) ; .set GL_PREFIX(BufferData), GL_PREFIX(BufferDataARB) + .globl GL_PREFIX(BufferSubData) ; .set GL_PREFIX(BufferSubData), GL_PREFIX(BufferSubDataARB) + .globl GL_PREFIX(DeleteBuffers) ; .set GL_PREFIX(DeleteBuffers), GL_PREFIX(DeleteBuffersARB) + .globl GL_PREFIX(GenBuffers) ; .set GL_PREFIX(GenBuffers), GL_PREFIX(GenBuffersARB) + .globl GL_PREFIX(GetBufferParameteriv) ; .set GL_PREFIX(GetBufferParameteriv), GL_PREFIX(GetBufferParameterivARB) + .globl GL_PREFIX(GetBufferPointerv) ; .set GL_PREFIX(GetBufferPointerv), GL_PREFIX(GetBufferPointervARB) + .globl GL_PREFIX(GetBufferSubData) ; .set GL_PREFIX(GetBufferSubData), GL_PREFIX(GetBufferSubDataARB) + .globl GL_PREFIX(IsBuffer) ; .set GL_PREFIX(IsBuffer), GL_PREFIX(IsBufferARB) + .globl GL_PREFIX(MapBuffer) ; .set GL_PREFIX(MapBuffer), GL_PREFIX(MapBufferARB) + .globl GL_PREFIX(UnmapBuffer) ; .set GL_PREFIX(UnmapBuffer), GL_PREFIX(UnmapBufferARB) + .globl GL_PREFIX(BeginQuery) ; .set GL_PREFIX(BeginQuery), GL_PREFIX(BeginQueryARB) + .globl GL_PREFIX(DeleteQueries) ; .set GL_PREFIX(DeleteQueries), GL_PREFIX(DeleteQueriesARB) + .globl GL_PREFIX(EndQuery) ; .set GL_PREFIX(EndQuery), GL_PREFIX(EndQueryARB) + .globl GL_PREFIX(GenQueries) ; .set GL_PREFIX(GenQueries), GL_PREFIX(GenQueriesARB) + .globl GL_PREFIX(GetQueryObjectiv) ; .set GL_PREFIX(GetQueryObjectiv), GL_PREFIX(GetQueryObjectivARB) + .globl GL_PREFIX(GetQueryObjectuiv) ; .set GL_PREFIX(GetQueryObjectuiv), GL_PREFIX(GetQueryObjectuivARB) + .globl GL_PREFIX(GetQueryiv) ; .set GL_PREFIX(GetQueryiv), GL_PREFIX(GetQueryivARB) + .globl GL_PREFIX(IsQuery) ; .set GL_PREFIX(IsQuery), GL_PREFIX(IsQueryARB) + .globl GL_PREFIX(CompileShader) ; .set GL_PREFIX(CompileShader), GL_PREFIX(CompileShaderARB) + .globl GL_PREFIX(GetActiveUniform) ; .set GL_PREFIX(GetActiveUniform), GL_PREFIX(GetActiveUniformARB) + .globl GL_PREFIX(GetShaderSource) ; .set GL_PREFIX(GetShaderSource), GL_PREFIX(GetShaderSourceARB) + .globl GL_PREFIX(GetUniformLocation) ; .set GL_PREFIX(GetUniformLocation), GL_PREFIX(GetUniformLocationARB) + .globl GL_PREFIX(GetUniformfv) ; .set GL_PREFIX(GetUniformfv), GL_PREFIX(GetUniformfvARB) + .globl GL_PREFIX(GetUniformiv) ; .set GL_PREFIX(GetUniformiv), GL_PREFIX(GetUniformivARB) + .globl GL_PREFIX(LinkProgram) ; .set GL_PREFIX(LinkProgram), GL_PREFIX(LinkProgramARB) + .globl GL_PREFIX(ShaderSource) ; .set GL_PREFIX(ShaderSource), GL_PREFIX(ShaderSourceARB) + .globl GL_PREFIX(Uniform1f) ; .set GL_PREFIX(Uniform1f), GL_PREFIX(Uniform1fARB) + .globl GL_PREFIX(Uniform1fv) ; .set GL_PREFIX(Uniform1fv), GL_PREFIX(Uniform1fvARB) + .globl GL_PREFIX(Uniform1i) ; .set GL_PREFIX(Uniform1i), GL_PREFIX(Uniform1iARB) + .globl GL_PREFIX(Uniform1iv) ; .set GL_PREFIX(Uniform1iv), GL_PREFIX(Uniform1ivARB) + .globl GL_PREFIX(Uniform2f) ; .set GL_PREFIX(Uniform2f), GL_PREFIX(Uniform2fARB) + .globl GL_PREFIX(Uniform2fv) ; .set GL_PREFIX(Uniform2fv), GL_PREFIX(Uniform2fvARB) + .globl GL_PREFIX(Uniform2i) ; .set GL_PREFIX(Uniform2i), GL_PREFIX(Uniform2iARB) + .globl GL_PREFIX(Uniform2iv) ; .set GL_PREFIX(Uniform2iv), GL_PREFIX(Uniform2ivARB) + .globl GL_PREFIX(Uniform3f) ; .set GL_PREFIX(Uniform3f), GL_PREFIX(Uniform3fARB) + .globl GL_PREFIX(Uniform3fv) ; .set GL_PREFIX(Uniform3fv), GL_PREFIX(Uniform3fvARB) + .globl GL_PREFIX(Uniform3i) ; .set GL_PREFIX(Uniform3i), GL_PREFIX(Uniform3iARB) + .globl GL_PREFIX(Uniform3iv) ; .set GL_PREFIX(Uniform3iv), GL_PREFIX(Uniform3ivARB) + .globl GL_PREFIX(Uniform4f) ; .set GL_PREFIX(Uniform4f), GL_PREFIX(Uniform4fARB) + .globl GL_PREFIX(Uniform4fv) ; .set GL_PREFIX(Uniform4fv), GL_PREFIX(Uniform4fvARB) + .globl GL_PREFIX(Uniform4i) ; .set GL_PREFIX(Uniform4i), GL_PREFIX(Uniform4iARB) + .globl GL_PREFIX(Uniform4iv) ; .set GL_PREFIX(Uniform4iv), GL_PREFIX(Uniform4ivARB) + .globl GL_PREFIX(UniformMatrix2fv) ; .set GL_PREFIX(UniformMatrix2fv), GL_PREFIX(UniformMatrix2fvARB) + .globl GL_PREFIX(UniformMatrix3fv) ; .set GL_PREFIX(UniformMatrix3fv), GL_PREFIX(UniformMatrix3fvARB) + .globl GL_PREFIX(UniformMatrix4fv) ; .set GL_PREFIX(UniformMatrix4fv), GL_PREFIX(UniformMatrix4fvARB) + .globl GL_PREFIX(UseProgram) ; .set GL_PREFIX(UseProgram), GL_PREFIX(UseProgramObjectARB) + .globl GL_PREFIX(ValidateProgram) ; .set GL_PREFIX(ValidateProgram), GL_PREFIX(ValidateProgramARB) + .globl GL_PREFIX(BindAttribLocation) ; .set GL_PREFIX(BindAttribLocation), GL_PREFIX(BindAttribLocationARB) + .globl GL_PREFIX(GetActiveAttrib) ; .set GL_PREFIX(GetActiveAttrib), GL_PREFIX(GetActiveAttribARB) + .globl GL_PREFIX(GetAttribLocation) ; .set GL_PREFIX(GetAttribLocation), GL_PREFIX(GetAttribLocationARB) + .globl GL_PREFIX(DrawBuffers) ; .set GL_PREFIX(DrawBuffers), GL_PREFIX(DrawBuffersARB) + .globl GL_PREFIX(DrawBuffersATI) ; .set GL_PREFIX(DrawBuffersATI), GL_PREFIX(DrawBuffersARB) + .globl GL_PREFIX(DrawArraysInstancedEXT) ; .set GL_PREFIX(DrawArraysInstancedEXT), GL_PREFIX(DrawArraysInstancedARB) + .globl GL_PREFIX(DrawArraysInstanced) ; .set GL_PREFIX(DrawArraysInstanced), GL_PREFIX(DrawArraysInstancedARB) + .globl GL_PREFIX(DrawElementsInstancedEXT) ; .set GL_PREFIX(DrawElementsInstancedEXT), GL_PREFIX(DrawElementsInstancedARB) + .globl GL_PREFIX(DrawElementsInstanced) ; .set GL_PREFIX(DrawElementsInstanced), GL_PREFIX(DrawElementsInstancedARB) + .globl GL_PREFIX(RenderbufferStorageMultisampleEXT) ; .set GL_PREFIX(RenderbufferStorageMultisampleEXT), GL_PREFIX(RenderbufferStorageMultisample) + .globl GL_PREFIX(PointParameterf) ; .set GL_PREFIX(PointParameterf), GL_PREFIX(PointParameterfEXT) + .globl GL_PREFIX(PointParameterfARB) ; .set GL_PREFIX(PointParameterfARB), GL_PREFIX(PointParameterfEXT) + .globl GL_PREFIX(PointParameterfv) ; .set GL_PREFIX(PointParameterfv), GL_PREFIX(PointParameterfvEXT) + .globl GL_PREFIX(PointParameterfvARB) ; .set GL_PREFIX(PointParameterfvARB), GL_PREFIX(PointParameterfvEXT) + .globl GL_PREFIX(SecondaryColor3b) ; .set GL_PREFIX(SecondaryColor3b), GL_PREFIX(SecondaryColor3bEXT) + .globl GL_PREFIX(SecondaryColor3bv) ; .set GL_PREFIX(SecondaryColor3bv), GL_PREFIX(SecondaryColor3bvEXT) + .globl GL_PREFIX(SecondaryColor3d) ; .set GL_PREFIX(SecondaryColor3d), GL_PREFIX(SecondaryColor3dEXT) + .globl GL_PREFIX(SecondaryColor3dv) ; .set GL_PREFIX(SecondaryColor3dv), GL_PREFIX(SecondaryColor3dvEXT) + .globl GL_PREFIX(SecondaryColor3f) ; .set GL_PREFIX(SecondaryColor3f), GL_PREFIX(SecondaryColor3fEXT) + .globl GL_PREFIX(SecondaryColor3fv) ; .set GL_PREFIX(SecondaryColor3fv), GL_PREFIX(SecondaryColor3fvEXT) + .globl GL_PREFIX(SecondaryColor3i) ; .set GL_PREFIX(SecondaryColor3i), GL_PREFIX(SecondaryColor3iEXT) + .globl GL_PREFIX(SecondaryColor3iv) ; .set GL_PREFIX(SecondaryColor3iv), GL_PREFIX(SecondaryColor3ivEXT) + .globl GL_PREFIX(SecondaryColor3s) ; .set GL_PREFIX(SecondaryColor3s), GL_PREFIX(SecondaryColor3sEXT) + .globl GL_PREFIX(SecondaryColor3sv) ; .set GL_PREFIX(SecondaryColor3sv), GL_PREFIX(SecondaryColor3svEXT) + .globl GL_PREFIX(SecondaryColor3ub) ; .set GL_PREFIX(SecondaryColor3ub), GL_PREFIX(SecondaryColor3ubEXT) + .globl GL_PREFIX(SecondaryColor3ubv) ; .set GL_PREFIX(SecondaryColor3ubv), GL_PREFIX(SecondaryColor3ubvEXT) + .globl GL_PREFIX(SecondaryColor3ui) ; .set GL_PREFIX(SecondaryColor3ui), GL_PREFIX(SecondaryColor3uiEXT) + .globl GL_PREFIX(SecondaryColor3uiv) ; .set GL_PREFIX(SecondaryColor3uiv), GL_PREFIX(SecondaryColor3uivEXT) + .globl GL_PREFIX(SecondaryColor3us) ; .set GL_PREFIX(SecondaryColor3us), GL_PREFIX(SecondaryColor3usEXT) + .globl GL_PREFIX(SecondaryColor3usv) ; .set GL_PREFIX(SecondaryColor3usv), GL_PREFIX(SecondaryColor3usvEXT) + .globl GL_PREFIX(SecondaryColorPointer) ; .set GL_PREFIX(SecondaryColorPointer), GL_PREFIX(SecondaryColorPointerEXT) + .globl GL_PREFIX(MultiDrawArrays) ; .set GL_PREFIX(MultiDrawArrays), GL_PREFIX(MultiDrawArraysEXT) + .globl GL_PREFIX(MultiDrawElements) ; .set GL_PREFIX(MultiDrawElements), GL_PREFIX(MultiDrawElementsEXT) + .globl GL_PREFIX(FogCoordPointer) ; .set GL_PREFIX(FogCoordPointer), GL_PREFIX(FogCoordPointerEXT) + .globl GL_PREFIX(FogCoordd) ; .set GL_PREFIX(FogCoordd), GL_PREFIX(FogCoorddEXT) + .globl GL_PREFIX(FogCoorddv) ; .set GL_PREFIX(FogCoorddv), GL_PREFIX(FogCoorddvEXT) + .globl GL_PREFIX(FogCoordf) ; .set GL_PREFIX(FogCoordf), GL_PREFIX(FogCoordfEXT) + .globl GL_PREFIX(FogCoordfv) ; .set GL_PREFIX(FogCoordfv), GL_PREFIX(FogCoordfvEXT) + .globl GL_PREFIX(BlendFuncSeparate) ; .set GL_PREFIX(BlendFuncSeparate), GL_PREFIX(BlendFuncSeparateEXT) + .globl GL_PREFIX(WindowPos2d) ; .set GL_PREFIX(WindowPos2d), GL_PREFIX(WindowPos2dMESA) + .globl GL_PREFIX(WindowPos2dARB) ; .set GL_PREFIX(WindowPos2dARB), GL_PREFIX(WindowPos2dMESA) + .globl GL_PREFIX(WindowPos2dv) ; .set GL_PREFIX(WindowPos2dv), GL_PREFIX(WindowPos2dvMESA) + .globl GL_PREFIX(WindowPos2dvARB) ; .set GL_PREFIX(WindowPos2dvARB), GL_PREFIX(WindowPos2dvMESA) + .globl GL_PREFIX(WindowPos2f) ; .set GL_PREFIX(WindowPos2f), GL_PREFIX(WindowPos2fMESA) + .globl GL_PREFIX(WindowPos2fARB) ; .set GL_PREFIX(WindowPos2fARB), GL_PREFIX(WindowPos2fMESA) + .globl GL_PREFIX(WindowPos2fv) ; .set GL_PREFIX(WindowPos2fv), GL_PREFIX(WindowPos2fvMESA) + .globl GL_PREFIX(WindowPos2fvARB) ; .set GL_PREFIX(WindowPos2fvARB), GL_PREFIX(WindowPos2fvMESA) + .globl GL_PREFIX(WindowPos2i) ; .set GL_PREFIX(WindowPos2i), GL_PREFIX(WindowPos2iMESA) + .globl GL_PREFIX(WindowPos2iARB) ; .set GL_PREFIX(WindowPos2iARB), GL_PREFIX(WindowPos2iMESA) + .globl GL_PREFIX(WindowPos2iv) ; .set GL_PREFIX(WindowPos2iv), GL_PREFIX(WindowPos2ivMESA) + .globl GL_PREFIX(WindowPos2ivARB) ; .set GL_PREFIX(WindowPos2ivARB), GL_PREFIX(WindowPos2ivMESA) + .globl GL_PREFIX(WindowPos2s) ; .set GL_PREFIX(WindowPos2s), GL_PREFIX(WindowPos2sMESA) + .globl GL_PREFIX(WindowPos2sARB) ; .set GL_PREFIX(WindowPos2sARB), GL_PREFIX(WindowPos2sMESA) + .globl GL_PREFIX(WindowPos2sv) ; .set GL_PREFIX(WindowPos2sv), GL_PREFIX(WindowPos2svMESA) + .globl GL_PREFIX(WindowPos2svARB) ; .set GL_PREFIX(WindowPos2svARB), GL_PREFIX(WindowPos2svMESA) + .globl GL_PREFIX(WindowPos3d) ; .set GL_PREFIX(WindowPos3d), GL_PREFIX(WindowPos3dMESA) + .globl GL_PREFIX(WindowPos3dARB) ; .set GL_PREFIX(WindowPos3dARB), GL_PREFIX(WindowPos3dMESA) + .globl GL_PREFIX(WindowPos3dv) ; .set GL_PREFIX(WindowPos3dv), GL_PREFIX(WindowPos3dvMESA) + .globl GL_PREFIX(WindowPos3dvARB) ; .set GL_PREFIX(WindowPos3dvARB), GL_PREFIX(WindowPos3dvMESA) + .globl GL_PREFIX(WindowPos3f) ; .set GL_PREFIX(WindowPos3f), GL_PREFIX(WindowPos3fMESA) + .globl GL_PREFIX(WindowPos3fARB) ; .set GL_PREFIX(WindowPos3fARB), GL_PREFIX(WindowPos3fMESA) + .globl GL_PREFIX(WindowPos3fv) ; .set GL_PREFIX(WindowPos3fv), GL_PREFIX(WindowPos3fvMESA) + .globl GL_PREFIX(WindowPos3fvARB) ; .set GL_PREFIX(WindowPos3fvARB), GL_PREFIX(WindowPos3fvMESA) + .globl GL_PREFIX(WindowPos3i) ; .set GL_PREFIX(WindowPos3i), GL_PREFIX(WindowPos3iMESA) + .globl GL_PREFIX(WindowPos3iARB) ; .set GL_PREFIX(WindowPos3iARB), GL_PREFIX(WindowPos3iMESA) + .globl GL_PREFIX(WindowPos3iv) ; .set GL_PREFIX(WindowPos3iv), GL_PREFIX(WindowPos3ivMESA) + .globl GL_PREFIX(WindowPos3ivARB) ; .set GL_PREFIX(WindowPos3ivARB), GL_PREFIX(WindowPos3ivMESA) + .globl GL_PREFIX(WindowPos3s) ; .set GL_PREFIX(WindowPos3s), GL_PREFIX(WindowPos3sMESA) + .globl GL_PREFIX(WindowPos3sARB) ; .set GL_PREFIX(WindowPos3sARB), GL_PREFIX(WindowPos3sMESA) + .globl GL_PREFIX(WindowPos3sv) ; .set GL_PREFIX(WindowPos3sv), GL_PREFIX(WindowPos3svMESA) + .globl GL_PREFIX(WindowPos3svARB) ; .set GL_PREFIX(WindowPos3svARB), GL_PREFIX(WindowPos3svMESA) + .globl GL_PREFIX(BindProgramARB) ; .set GL_PREFIX(BindProgramARB), GL_PREFIX(BindProgramNV) + .globl GL_PREFIX(DeleteProgramsARB) ; .set GL_PREFIX(DeleteProgramsARB), GL_PREFIX(DeleteProgramsNV) + .globl GL_PREFIX(GenProgramsARB) ; .set GL_PREFIX(GenProgramsARB), GL_PREFIX(GenProgramsNV) + .globl GL_PREFIX(GetVertexAttribPointerv) ; .set GL_PREFIX(GetVertexAttribPointerv), GL_PREFIX(GetVertexAttribPointervNV) + .globl GL_PREFIX(GetVertexAttribPointervARB) ; .set GL_PREFIX(GetVertexAttribPointervARB), GL_PREFIX(GetVertexAttribPointervNV) + .globl GL_PREFIX(IsProgramARB) ; .set GL_PREFIX(IsProgramARB), GL_PREFIX(IsProgramNV) + .globl GL_PREFIX(PointParameteri) ; .set GL_PREFIX(PointParameteri), GL_PREFIX(PointParameteriNV) + .globl GL_PREFIX(PointParameteriv) ; .set GL_PREFIX(PointParameteriv), GL_PREFIX(PointParameterivNV) + .globl GL_PREFIX(DeleteVertexArrays) ; .set GL_PREFIX(DeleteVertexArrays), GL_PREFIX(_dispatch_stub_781) + .globl GL_PREFIX(IsVertexArray) ; .set GL_PREFIX(IsVertexArray), GL_PREFIX(_dispatch_stub_783) + .globl GL_PREFIX(PrimitiveRestartIndex) ; .set GL_PREFIX(PrimitiveRestartIndex), GL_PREFIX(PrimitiveRestartIndexNV) + .globl GL_PREFIX(BlendEquationSeparate) ; .set GL_PREFIX(BlendEquationSeparate), GL_PREFIX(_dispatch_stub_793) + .globl GL_PREFIX(BindFramebuffer) ; .set GL_PREFIX(BindFramebuffer), GL_PREFIX(BindFramebufferEXT) + .globl GL_PREFIX(BindRenderbuffer) ; .set GL_PREFIX(BindRenderbuffer), GL_PREFIX(BindRenderbufferEXT) + .globl GL_PREFIX(CheckFramebufferStatus) ; .set GL_PREFIX(CheckFramebufferStatus), GL_PREFIX(CheckFramebufferStatusEXT) + .globl GL_PREFIX(DeleteFramebuffers) ; .set GL_PREFIX(DeleteFramebuffers), GL_PREFIX(DeleteFramebuffersEXT) + .globl GL_PREFIX(DeleteRenderbuffers) ; .set GL_PREFIX(DeleteRenderbuffers), GL_PREFIX(DeleteRenderbuffersEXT) + .globl GL_PREFIX(FramebufferRenderbuffer) ; .set GL_PREFIX(FramebufferRenderbuffer), GL_PREFIX(FramebufferRenderbufferEXT) + .globl GL_PREFIX(FramebufferTexture1D) ; .set GL_PREFIX(FramebufferTexture1D), GL_PREFIX(FramebufferTexture1DEXT) + .globl GL_PREFIX(FramebufferTexture2D) ; .set GL_PREFIX(FramebufferTexture2D), GL_PREFIX(FramebufferTexture2DEXT) + .globl GL_PREFIX(FramebufferTexture3D) ; .set GL_PREFIX(FramebufferTexture3D), GL_PREFIX(FramebufferTexture3DEXT) + .globl GL_PREFIX(GenFramebuffers) ; .set GL_PREFIX(GenFramebuffers), GL_PREFIX(GenFramebuffersEXT) + .globl GL_PREFIX(GenRenderbuffers) ; .set GL_PREFIX(GenRenderbuffers), GL_PREFIX(GenRenderbuffersEXT) + .globl GL_PREFIX(GenerateMipmap) ; .set GL_PREFIX(GenerateMipmap), GL_PREFIX(GenerateMipmapEXT) + .globl GL_PREFIX(GetFramebufferAttachmentParameteriv) ; .set GL_PREFIX(GetFramebufferAttachmentParameteriv), GL_PREFIX(GetFramebufferAttachmentParameterivEXT) + .globl GL_PREFIX(GetRenderbufferParameteriv) ; .set GL_PREFIX(GetRenderbufferParameteriv), GL_PREFIX(GetRenderbufferParameterivEXT) + .globl GL_PREFIX(IsFramebuffer) ; .set GL_PREFIX(IsFramebuffer), GL_PREFIX(IsFramebufferEXT) + .globl GL_PREFIX(IsRenderbuffer) ; .set GL_PREFIX(IsRenderbuffer), GL_PREFIX(IsRenderbufferEXT) + .globl GL_PREFIX(RenderbufferStorage) ; .set GL_PREFIX(RenderbufferStorage), GL_PREFIX(RenderbufferStorageEXT) + .globl GL_PREFIX(BlitFramebuffer) ; .set GL_PREFIX(BlitFramebuffer), GL_PREFIX(_dispatch_stub_811) + .globl GL_PREFIX(BindFragDataLocation) ; .set GL_PREFIX(BindFragDataLocation), GL_PREFIX(BindFragDataLocationEXT) + .globl GL_PREFIX(GetFragDataLocation) ; .set GL_PREFIX(GetFragDataLocation), GL_PREFIX(GetFragDataLocationEXT) + .globl GL_PREFIX(GetUniformuiv) ; .set GL_PREFIX(GetUniformuiv), GL_PREFIX(GetUniformuivEXT) + .globl GL_PREFIX(GetVertexAttribIiv) ; .set GL_PREFIX(GetVertexAttribIiv), GL_PREFIX(GetVertexAttribIivEXT) + .globl GL_PREFIX(GetVertexAttribIuiv) ; .set GL_PREFIX(GetVertexAttribIuiv), GL_PREFIX(GetVertexAttribIuivEXT) + .globl GL_PREFIX(Uniform1ui) ; .set GL_PREFIX(Uniform1ui), GL_PREFIX(Uniform1uiEXT) + .globl GL_PREFIX(Uniform1uiv) ; .set GL_PREFIX(Uniform1uiv), GL_PREFIX(Uniform1uivEXT) + .globl GL_PREFIX(Uniform2ui) ; .set GL_PREFIX(Uniform2ui), GL_PREFIX(Uniform2uiEXT) + .globl GL_PREFIX(Uniform2uiv) ; .set GL_PREFIX(Uniform2uiv), GL_PREFIX(Uniform2uivEXT) + .globl GL_PREFIX(Uniform3ui) ; .set GL_PREFIX(Uniform3ui), GL_PREFIX(Uniform3uiEXT) + .globl GL_PREFIX(Uniform3uiv) ; .set GL_PREFIX(Uniform3uiv), GL_PREFIX(Uniform3uivEXT) + .globl GL_PREFIX(Uniform4ui) ; .set GL_PREFIX(Uniform4ui), GL_PREFIX(Uniform4uiEXT) + .globl GL_PREFIX(Uniform4uiv) ; .set GL_PREFIX(Uniform4uiv), GL_PREFIX(Uniform4uivEXT) + .globl GL_PREFIX(VertexAttribI1i) ; .set GL_PREFIX(VertexAttribI1i), GL_PREFIX(VertexAttribI1iEXT) + .globl GL_PREFIX(VertexAttribI1iv) ; .set GL_PREFIX(VertexAttribI1iv), GL_PREFIX(VertexAttribI1ivEXT) + .globl GL_PREFIX(VertexAttribI1ui) ; .set GL_PREFIX(VertexAttribI1ui), GL_PREFIX(VertexAttribI1uiEXT) + .globl GL_PREFIX(VertexAttribI1uiv) ; .set GL_PREFIX(VertexAttribI1uiv), GL_PREFIX(VertexAttribI1uivEXT) + .globl GL_PREFIX(VertexAttribI2i) ; .set GL_PREFIX(VertexAttribI2i), GL_PREFIX(VertexAttribI2iEXT) + .globl GL_PREFIX(VertexAttribI2iv) ; .set GL_PREFIX(VertexAttribI2iv), GL_PREFIX(VertexAttribI2ivEXT) + .globl GL_PREFIX(VertexAttribI2ui) ; .set GL_PREFIX(VertexAttribI2ui), GL_PREFIX(VertexAttribI2uiEXT) + .globl GL_PREFIX(VertexAttribI2uiv) ; .set GL_PREFIX(VertexAttribI2uiv), GL_PREFIX(VertexAttribI2uivEXT) + .globl GL_PREFIX(VertexAttribI3i) ; .set GL_PREFIX(VertexAttribI3i), GL_PREFIX(VertexAttribI3iEXT) + .globl GL_PREFIX(VertexAttribI3iv) ; .set GL_PREFIX(VertexAttribI3iv), GL_PREFIX(VertexAttribI3ivEXT) + .globl GL_PREFIX(VertexAttribI3ui) ; .set GL_PREFIX(VertexAttribI3ui), GL_PREFIX(VertexAttribI3uiEXT) + .globl GL_PREFIX(VertexAttribI3uiv) ; .set GL_PREFIX(VertexAttribI3uiv), GL_PREFIX(VertexAttribI3uivEXT) + .globl GL_PREFIX(VertexAttribI4bv) ; .set GL_PREFIX(VertexAttribI4bv), GL_PREFIX(VertexAttribI4bvEXT) + .globl GL_PREFIX(VertexAttribI4i) ; .set GL_PREFIX(VertexAttribI4i), GL_PREFIX(VertexAttribI4iEXT) + .globl GL_PREFIX(VertexAttribI4iv) ; .set GL_PREFIX(VertexAttribI4iv), GL_PREFIX(VertexAttribI4ivEXT) + .globl GL_PREFIX(VertexAttribI4sv) ; .set GL_PREFIX(VertexAttribI4sv), GL_PREFIX(VertexAttribI4svEXT) + .globl GL_PREFIX(VertexAttribI4ubv) ; .set GL_PREFIX(VertexAttribI4ubv), GL_PREFIX(VertexAttribI4ubvEXT) + .globl GL_PREFIX(VertexAttribI4ui) ; .set GL_PREFIX(VertexAttribI4ui), GL_PREFIX(VertexAttribI4uiEXT) + .globl GL_PREFIX(VertexAttribI4uiv) ; .set GL_PREFIX(VertexAttribI4uiv), GL_PREFIX(VertexAttribI4uivEXT) + .globl GL_PREFIX(VertexAttribI4usv) ; .set GL_PREFIX(VertexAttribI4usv), GL_PREFIX(VertexAttribI4usvEXT) + .globl GL_PREFIX(VertexAttribIPointer) ; .set GL_PREFIX(VertexAttribIPointer), GL_PREFIX(VertexAttribIPointerEXT) + .globl GL_PREFIX(FramebufferTextureLayer) ; .set GL_PREFIX(FramebufferTextureLayer), GL_PREFIX(FramebufferTextureLayerEXT) + .globl GL_PREFIX(ColorMaski) ; .set GL_PREFIX(ColorMaski), GL_PREFIX(ColorMaskIndexedEXT) + .globl GL_PREFIX(Disablei) ; .set GL_PREFIX(Disablei), GL_PREFIX(DisableIndexedEXT) + .globl GL_PREFIX(Enablei) ; .set GL_PREFIX(Enablei), GL_PREFIX(EnableIndexedEXT) + .globl GL_PREFIX(GetBooleani_v) ; .set GL_PREFIX(GetBooleani_v), GL_PREFIX(GetBooleanIndexedvEXT) + .globl GL_PREFIX(GetIntegeri_v) ; .set GL_PREFIX(GetIntegeri_v), GL_PREFIX(GetIntegerIndexedvEXT) + .globl GL_PREFIX(IsEnabledi) ; .set GL_PREFIX(IsEnabledi), GL_PREFIX(IsEnabledIndexedEXT) + .globl GL_PREFIX(GetTexParameterIiv) ; .set GL_PREFIX(GetTexParameterIiv), GL_PREFIX(GetTexParameterIivEXT) + .globl GL_PREFIX(GetTexParameterIuiv) ; .set GL_PREFIX(GetTexParameterIuiv), GL_PREFIX(GetTexParameterIuivEXT) + .globl GL_PREFIX(TexParameterIiv) ; .set GL_PREFIX(TexParameterIiv), GL_PREFIX(TexParameterIivEXT) + .globl GL_PREFIX(TexParameterIuiv) ; .set GL_PREFIX(TexParameterIuiv), GL_PREFIX(TexParameterIuivEXT) + .globl GL_PREFIX(BeginConditionalRender) ; .set GL_PREFIX(BeginConditionalRender), GL_PREFIX(BeginConditionalRenderNV) + .globl GL_PREFIX(EndConditionalRender) ; .set GL_PREFIX(EndConditionalRender), GL_PREFIX(EndConditionalRenderNV) + .globl GL_PREFIX(BeginTransformFeedback) ; .set GL_PREFIX(BeginTransformFeedback), GL_PREFIX(BeginTransformFeedbackEXT) + .globl GL_PREFIX(BindBufferBase) ; .set GL_PREFIX(BindBufferBase), GL_PREFIX(BindBufferBaseEXT) + .globl GL_PREFIX(BindBufferRange) ; .set GL_PREFIX(BindBufferRange), GL_PREFIX(BindBufferRangeEXT) + .globl GL_PREFIX(EndTransformFeedback) ; .set GL_PREFIX(EndTransformFeedback), GL_PREFIX(EndTransformFeedbackEXT) + .globl GL_PREFIX(GetTransformFeedbackVarying) ; .set GL_PREFIX(GetTransformFeedbackVarying), GL_PREFIX(GetTransformFeedbackVaryingEXT) + .globl GL_PREFIX(TransformFeedbackVaryings) ; .set GL_PREFIX(TransformFeedbackVaryings), GL_PREFIX(TransformFeedbackVaryingsEXT) + .globl GL_PREFIX(ProvokingVertex) ; .set GL_PREFIX(ProvokingVertex), GL_PREFIX(ProvokingVertexEXT) + +#if defined(GLX_USE_TLS) && defined(__linux__) + .section ".note.ABI-tag", "a" + .p2align 2 + .long 1f - 0f /* name length */ + .long 3f - 2f /* data length */ + .long 1 /* note length */ +0: .asciz "GNU" /* vendor name */ +1: .p2align 2 +2: .long 0 /* note data: the ABI tag */ + .long 2,4,20 /* Minimum kernel version w/TLS */ +3: .p2align 2 /* pad out section */ +#endif /* GLX_USE_TLS */ + +#if defined (__ELF__) && defined (__linux__) + .section .note.GNU-stack,"",%progbits +#endif diff --git a/src/mapi/glapi/glapi_x86.S b/src/mapi/glapi/glapi_x86.S new file mode 100644 index 0000000..605bebc --- /dev/null +++ b/src/mapi/glapi/glapi_x86.S @@ -0,0 +1,1429 @@ +/* DO NOT EDIT - This file generated automatically by gl_x86_asm.py (from Mesa) script */ + +/* + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * (C) Copyright IBM Corporation 2004, 2005 + * 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 + * BRIAN PAUL, IBM, + * 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 "x86/assyntax.h" + +#if defined(STDCALL_API) +# if defined(USE_MGL_NAMESPACE) +# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n2)) +# else +# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2)) +# endif +#else +# if defined(USE_MGL_NAMESPACE) +# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n)) +# define _glapi_Dispatch _mglapi_Dispatch +# else +# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n)) +# endif +#endif + +#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX)) + +#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__) && !defined(__APPLE__) +#define GLOBL_FN(x) GLOBL x ; .type x, @function +#else +#define GLOBL_FN(x) GLOBL x +#endif + +#if defined(PTHREADS) || defined(WIN32) || defined(BEOS_THREADS) +# define THREADS +#endif + +#ifdef GLX_USE_TLS + +#ifdef GLX_X86_READONLY_TEXT +# define CTX_INSNS MOV_L(GS:(EAX), EAX) +#else +# define CTX_INSNS NOP /* Pad for init_glapi_relocs() */ +#endif + +# define GL_STUB(fn,off,fn_alt) \ +ALIGNTEXT16; \ +GLOBL_FN(GL_PREFIX(fn, fn_alt)); \ +GL_PREFIX(fn, fn_alt): \ + CALL(_x86_get_dispatch) ; \ + CTX_INSNS ; \ + JMP(GL_OFFSET(off)) + +#elif defined(PTHREADS) +# define GL_STUB(fn,off,fn_alt) \ +ALIGNTEXT16; \ +GLOBL_FN(GL_PREFIX(fn, fn_alt)); \ +GL_PREFIX(fn, fn_alt): \ + MOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ; \ + TEST_L(EAX, EAX) ; \ + JE(1f) ; \ + JMP(GL_OFFSET(off)) ; \ +1: CALL(_x86_get_dispatch) ; \ + JMP(GL_OFFSET(off)) +#elif defined(THREADS) +# define GL_STUB(fn,off,fn_alt) \ +ALIGNTEXT16; \ +GLOBL_FN(GL_PREFIX(fn, fn_alt)); \ +GL_PREFIX(fn, fn_alt): \ + MOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ; \ + TEST_L(EAX, EAX) ; \ + JE(1f) ; \ + JMP(GL_OFFSET(off)) ; \ +1: CALL(_glapi_get_dispatch) ; \ + JMP(GL_OFFSET(off)) +#else /* Non-threaded version. */ +# define GL_STUB(fn,off,fn_alt) \ +ALIGNTEXT16; \ +GLOBL_FN(GL_PREFIX(fn, fn_alt)); \ +GL_PREFIX(fn, fn_alt): \ + MOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ; \ + JMP(GL_OFFSET(off)) +#endif + +#ifdef HAVE_ALIAS +# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt) \ + .globl GL_PREFIX(fn, fn_alt) ; \ + .set GL_PREFIX(fn, fn_alt), GL_PREFIX(alias, alias_alt) +#else +# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt) \ + GL_STUB(fn, off, fn_alt) +#endif + +SEG_TEXT + +#ifdef GLX_USE_TLS + + GLOBL GLNAME(_x86_get_dispatch) + HIDDEN(GLNAME(_x86_get_dispatch)) +ALIGNTEXT16 +GLNAME(_x86_get_dispatch): + call 1f +1: popl %eax + addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax + movl _glapi_tls_Dispatch@GOTNTPOFF(%eax), %eax + ret + +#elif defined(PTHREADS) +EXTERN GLNAME(_glapi_Dispatch) +EXTERN GLNAME(_gl_DispatchTSD) +EXTERN GLNAME(pthread_getspecific) + +ALIGNTEXT16 +GLNAME(_x86_get_dispatch): + SUB_L(CONST(24), ESP) + PUSH_L(GLNAME(_gl_DispatchTSD)) + CALL(GLNAME(pthread_getspecific)) + ADD_L(CONST(28), ESP) + RET +#elif defined(THREADS) +EXTERN GLNAME(_glapi_get_dispatch) +#endif + +#if defined( GLX_USE_TLS ) && !defined( GLX_X86_READONLY_TEXT ) + .section wtext, "awx", @progbits +#endif /* defined( GLX_USE_TLS ) */ + + ALIGNTEXT16 + GLOBL GLNAME(gl_dispatch_functions_start) + HIDDEN(GLNAME(gl_dispatch_functions_start)) +GLNAME(gl_dispatch_functions_start): + + GL_STUB(NewList, 0, NewList@8) + GL_STUB(EndList, 1, EndList@0) + GL_STUB(CallList, 2, CallList@4) + GL_STUB(CallLists, 3, CallLists@12) + GL_STUB(DeleteLists, 4, DeleteLists@8) + GL_STUB(GenLists, 5, GenLists@4) + GL_STUB(ListBase, 6, ListBase@4) + GL_STUB(Begin, 7, Begin@4) + GL_STUB(Bitmap, 8, Bitmap@28) + GL_STUB(Color3b, 9, Color3b@12) + GL_STUB(Color3bv, 10, Color3bv@4) + GL_STUB(Color3d, 11, Color3d@24) + GL_STUB(Color3dv, 12, Color3dv@4) + GL_STUB(Color3f, 13, Color3f@12) + GL_STUB(Color3fv, 14, Color3fv@4) + GL_STUB(Color3i, 15, Color3i@12) + GL_STUB(Color3iv, 16, Color3iv@4) + GL_STUB(Color3s, 17, Color3s@12) + GL_STUB(Color3sv, 18, Color3sv@4) + GL_STUB(Color3ub, 19, Color3ub@12) + GL_STUB(Color3ubv, 20, Color3ubv@4) + GL_STUB(Color3ui, 21, Color3ui@12) + GL_STUB(Color3uiv, 22, Color3uiv@4) + GL_STUB(Color3us, 23, Color3us@12) + GL_STUB(Color3usv, 24, Color3usv@4) + GL_STUB(Color4b, 25, Color4b@16) + GL_STUB(Color4bv, 26, Color4bv@4) + GL_STUB(Color4d, 27, Color4d@32) + GL_STUB(Color4dv, 28, Color4dv@4) + GL_STUB(Color4f, 29, Color4f@16) + GL_STUB(Color4fv, 30, Color4fv@4) + GL_STUB(Color4i, 31, Color4i@16) + GL_STUB(Color4iv, 32, Color4iv@4) + GL_STUB(Color4s, 33, Color4s@16) + GL_STUB(Color4sv, 34, Color4sv@4) + GL_STUB(Color4ub, 35, Color4ub@16) + GL_STUB(Color4ubv, 36, Color4ubv@4) + GL_STUB(Color4ui, 37, Color4ui@16) + GL_STUB(Color4uiv, 38, Color4uiv@4) + GL_STUB(Color4us, 39, Color4us@16) + GL_STUB(Color4usv, 40, Color4usv@4) + GL_STUB(EdgeFlag, 41, EdgeFlag@4) + GL_STUB(EdgeFlagv, 42, EdgeFlagv@4) + GL_STUB(End, 43, End@0) + GL_STUB(Indexd, 44, Indexd@8) + GL_STUB(Indexdv, 45, Indexdv@4) + GL_STUB(Indexf, 46, Indexf@4) + GL_STUB(Indexfv, 47, Indexfv@4) + GL_STUB(Indexi, 48, Indexi@4) + GL_STUB(Indexiv, 49, Indexiv@4) + GL_STUB(Indexs, 50, Indexs@4) + GL_STUB(Indexsv, 51, Indexsv@4) + GL_STUB(Normal3b, 52, Normal3b@12) + GL_STUB(Normal3bv, 53, Normal3bv@4) + GL_STUB(Normal3d, 54, Normal3d@24) + GL_STUB(Normal3dv, 55, Normal3dv@4) + GL_STUB(Normal3f, 56, Normal3f@12) + GL_STUB(Normal3fv, 57, Normal3fv@4) + GL_STUB(Normal3i, 58, Normal3i@12) + GL_STUB(Normal3iv, 59, Normal3iv@4) + GL_STUB(Normal3s, 60, Normal3s@12) + GL_STUB(Normal3sv, 61, Normal3sv@4) + GL_STUB(RasterPos2d, 62, RasterPos2d@16) + GL_STUB(RasterPos2dv, 63, RasterPos2dv@4) + GL_STUB(RasterPos2f, 64, RasterPos2f@8) + GL_STUB(RasterPos2fv, 65, RasterPos2fv@4) + GL_STUB(RasterPos2i, 66, RasterPos2i@8) + GL_STUB(RasterPos2iv, 67, RasterPos2iv@4) + GL_STUB(RasterPos2s, 68, RasterPos2s@8) + GL_STUB(RasterPos2sv, 69, RasterPos2sv@4) + GL_STUB(RasterPos3d, 70, RasterPos3d@24) + GL_STUB(RasterPos3dv, 71, RasterPos3dv@4) + GL_STUB(RasterPos3f, 72, RasterPos3f@12) + GL_STUB(RasterPos3fv, 73, RasterPos3fv@4) + GL_STUB(RasterPos3i, 74, RasterPos3i@12) + GL_STUB(RasterPos3iv, 75, RasterPos3iv@4) + GL_STUB(RasterPos3s, 76, RasterPos3s@12) + GL_STUB(RasterPos3sv, 77, RasterPos3sv@4) + GL_STUB(RasterPos4d, 78, RasterPos4d@32) + GL_STUB(RasterPos4dv, 79, RasterPos4dv@4) + GL_STUB(RasterPos4f, 80, RasterPos4f@16) + GL_STUB(RasterPos4fv, 81, RasterPos4fv@4) + GL_STUB(RasterPos4i, 82, RasterPos4i@16) + GL_STUB(RasterPos4iv, 83, RasterPos4iv@4) + GL_STUB(RasterPos4s, 84, RasterPos4s@16) + GL_STUB(RasterPos4sv, 85, RasterPos4sv@4) + GL_STUB(Rectd, 86, Rectd@32) + GL_STUB(Rectdv, 87, Rectdv@8) + GL_STUB(Rectf, 88, Rectf@16) + GL_STUB(Rectfv, 89, Rectfv@8) + GL_STUB(Recti, 90, Recti@16) + GL_STUB(Rectiv, 91, Rectiv@8) + GL_STUB(Rects, 92, Rects@16) + GL_STUB(Rectsv, 93, Rectsv@8) + GL_STUB(TexCoord1d, 94, TexCoord1d@8) + GL_STUB(TexCoord1dv, 95, TexCoord1dv@4) + GL_STUB(TexCoord1f, 96, TexCoord1f@4) + GL_STUB(TexCoord1fv, 97, TexCoord1fv@4) + GL_STUB(TexCoord1i, 98, TexCoord1i@4) + GL_STUB(TexCoord1iv, 99, TexCoord1iv@4) + GL_STUB(TexCoord1s, 100, TexCoord1s@4) + GL_STUB(TexCoord1sv, 101, TexCoord1sv@4) + GL_STUB(TexCoord2d, 102, TexCoord2d@16) + GL_STUB(TexCoord2dv, 103, TexCoord2dv@4) + GL_STUB(TexCoord2f, 104, TexCoord2f@8) + GL_STUB(TexCoord2fv, 105, TexCoord2fv@4) + GL_STUB(TexCoord2i, 106, TexCoord2i@8) + GL_STUB(TexCoord2iv, 107, TexCoord2iv@4) + GL_STUB(TexCoord2s, 108, TexCoord2s@8) + GL_STUB(TexCoord2sv, 109, TexCoord2sv@4) + GL_STUB(TexCoord3d, 110, TexCoord3d@24) + GL_STUB(TexCoord3dv, 111, TexCoord3dv@4) + GL_STUB(TexCoord3f, 112, TexCoord3f@12) + GL_STUB(TexCoord3fv, 113, TexCoord3fv@4) + GL_STUB(TexCoord3i, 114, TexCoord3i@12) + GL_STUB(TexCoord3iv, 115, TexCoord3iv@4) + GL_STUB(TexCoord3s, 116, TexCoord3s@12) + GL_STUB(TexCoord3sv, 117, TexCoord3sv@4) + GL_STUB(TexCoord4d, 118, TexCoord4d@32) + GL_STUB(TexCoord4dv, 119, TexCoord4dv@4) + GL_STUB(TexCoord4f, 120, TexCoord4f@16) + GL_STUB(TexCoord4fv, 121, TexCoord4fv@4) + GL_STUB(TexCoord4i, 122, TexCoord4i@16) + GL_STUB(TexCoord4iv, 123, TexCoord4iv@4) + GL_STUB(TexCoord4s, 124, TexCoord4s@16) + GL_STUB(TexCoord4sv, 125, TexCoord4sv@4) + GL_STUB(Vertex2d, 126, Vertex2d@16) + GL_STUB(Vertex2dv, 127, Vertex2dv@4) + GL_STUB(Vertex2f, 128, Vertex2f@8) + GL_STUB(Vertex2fv, 129, Vertex2fv@4) + GL_STUB(Vertex2i, 130, Vertex2i@8) + GL_STUB(Vertex2iv, 131, Vertex2iv@4) + GL_STUB(Vertex2s, 132, Vertex2s@8) + GL_STUB(Vertex2sv, 133, Vertex2sv@4) + GL_STUB(Vertex3d, 134, Vertex3d@24) + GL_STUB(Vertex3dv, 135, Vertex3dv@4) + GL_STUB(Vertex3f, 136, Vertex3f@12) + GL_STUB(Vertex3fv, 137, Vertex3fv@4) + GL_STUB(Vertex3i, 138, Vertex3i@12) + GL_STUB(Vertex3iv, 139, Vertex3iv@4) + GL_STUB(Vertex3s, 140, Vertex3s@12) + GL_STUB(Vertex3sv, 141, Vertex3sv@4) + GL_STUB(Vertex4d, 142, Vertex4d@32) + GL_STUB(Vertex4dv, 143, Vertex4dv@4) + GL_STUB(Vertex4f, 144, Vertex4f@16) + GL_STUB(Vertex4fv, 145, Vertex4fv@4) + GL_STUB(Vertex4i, 146, Vertex4i@16) + GL_STUB(Vertex4iv, 147, Vertex4iv@4) + GL_STUB(Vertex4s, 148, Vertex4s@16) + GL_STUB(Vertex4sv, 149, Vertex4sv@4) + GL_STUB(ClipPlane, 150, ClipPlane@8) + GL_STUB(ColorMaterial, 151, ColorMaterial@8) + GL_STUB(CullFace, 152, CullFace@4) + GL_STUB(Fogf, 153, Fogf@8) + GL_STUB(Fogfv, 154, Fogfv@8) + GL_STUB(Fogi, 155, Fogi@8) + GL_STUB(Fogiv, 156, Fogiv@8) + GL_STUB(FrontFace, 157, FrontFace@4) + GL_STUB(Hint, 158, Hint@8) + GL_STUB(Lightf, 159, Lightf@12) + GL_STUB(Lightfv, 160, Lightfv@12) + GL_STUB(Lighti, 161, Lighti@12) + GL_STUB(Lightiv, 162, Lightiv@12) + GL_STUB(LightModelf, 163, LightModelf@8) + GL_STUB(LightModelfv, 164, LightModelfv@8) + GL_STUB(LightModeli, 165, LightModeli@8) + GL_STUB(LightModeliv, 166, LightModeliv@8) + GL_STUB(LineStipple, 167, LineStipple@8) + GL_STUB(LineWidth, 168, LineWidth@4) + GL_STUB(Materialf, 169, Materialf@12) + GL_STUB(Materialfv, 170, Materialfv@12) + GL_STUB(Materiali, 171, Materiali@12) + GL_STUB(Materialiv, 172, Materialiv@12) + GL_STUB(PointSize, 173, PointSize@4) + GL_STUB(PolygonMode, 174, PolygonMode@8) + GL_STUB(PolygonStipple, 175, PolygonStipple@4) + GL_STUB(Scissor, 176, Scissor@16) + GL_STUB(ShadeModel, 177, ShadeModel@4) + GL_STUB(TexParameterf, 178, TexParameterf@12) + GL_STUB(TexParameterfv, 179, TexParameterfv@12) + GL_STUB(TexParameteri, 180, TexParameteri@12) + GL_STUB(TexParameteriv, 181, TexParameteriv@12) + GL_STUB(TexImage1D, 182, TexImage1D@32) + GL_STUB(TexImage2D, 183, TexImage2D@36) + GL_STUB(TexEnvf, 184, TexEnvf@12) + GL_STUB(TexEnvfv, 185, TexEnvfv@12) + GL_STUB(TexEnvi, 186, TexEnvi@12) + GL_STUB(TexEnviv, 187, TexEnviv@12) + GL_STUB(TexGend, 188, TexGend@16) + GL_STUB(TexGendv, 189, TexGendv@12) + GL_STUB(TexGenf, 190, TexGenf@12) + GL_STUB(TexGenfv, 191, TexGenfv@12) + GL_STUB(TexGeni, 192, TexGeni@12) + GL_STUB(TexGeniv, 193, TexGeniv@12) + GL_STUB(FeedbackBuffer, 194, FeedbackBuffer@12) + GL_STUB(SelectBuffer, 195, SelectBuffer@8) + GL_STUB(RenderMode, 196, RenderMode@4) + GL_STUB(InitNames, 197, InitNames@0) + GL_STUB(LoadName, 198, LoadName@4) + GL_STUB(PassThrough, 199, PassThrough@4) + GL_STUB(PopName, 200, PopName@0) + GL_STUB(PushName, 201, PushName@4) + GL_STUB(DrawBuffer, 202, DrawBuffer@4) + GL_STUB(Clear, 203, Clear@4) + GL_STUB(ClearAccum, 204, ClearAccum@16) + GL_STUB(ClearIndex, 205, ClearIndex@4) + GL_STUB(ClearColor, 206, ClearColor@16) + GL_STUB(ClearStencil, 207, ClearStencil@4) + GL_STUB(ClearDepth, 208, ClearDepth@8) + GL_STUB(StencilMask, 209, StencilMask@4) + GL_STUB(ColorMask, 210, ColorMask@16) + GL_STUB(DepthMask, 211, DepthMask@4) + GL_STUB(IndexMask, 212, IndexMask@4) + GL_STUB(Accum, 213, Accum@8) + GL_STUB(Disable, 214, Disable@4) + GL_STUB(Enable, 215, Enable@4) + GL_STUB(Finish, 216, Finish@0) + GL_STUB(Flush, 217, Flush@0) + GL_STUB(PopAttrib, 218, PopAttrib@0) + GL_STUB(PushAttrib, 219, PushAttrib@4) + GL_STUB(Map1d, 220, Map1d@32) + GL_STUB(Map1f, 221, Map1f@24) + GL_STUB(Map2d, 222, Map2d@56) + GL_STUB(Map2f, 223, Map2f@40) + GL_STUB(MapGrid1d, 224, MapGrid1d@20) + GL_STUB(MapGrid1f, 225, MapGrid1f@12) + GL_STUB(MapGrid2d, 226, MapGrid2d@40) + GL_STUB(MapGrid2f, 227, MapGrid2f@24) + GL_STUB(EvalCoord1d, 228, EvalCoord1d@8) + GL_STUB(EvalCoord1dv, 229, EvalCoord1dv@4) + GL_STUB(EvalCoord1f, 230, EvalCoord1f@4) + GL_STUB(EvalCoord1fv, 231, EvalCoord1fv@4) + GL_STUB(EvalCoord2d, 232, EvalCoord2d@16) + GL_STUB(EvalCoord2dv, 233, EvalCoord2dv@4) + GL_STUB(EvalCoord2f, 234, EvalCoord2f@8) + GL_STUB(EvalCoord2fv, 235, EvalCoord2fv@4) + GL_STUB(EvalMesh1, 236, EvalMesh1@12) + GL_STUB(EvalPoint1, 237, EvalPoint1@4) + GL_STUB(EvalMesh2, 238, EvalMesh2@20) + GL_STUB(EvalPoint2, 239, EvalPoint2@8) + GL_STUB(AlphaFunc, 240, AlphaFunc@8) + GL_STUB(BlendFunc, 241, BlendFunc@8) + GL_STUB(LogicOp, 242, LogicOp@4) + GL_STUB(StencilFunc, 243, StencilFunc@12) + GL_STUB(StencilOp, 244, StencilOp@12) + GL_STUB(DepthFunc, 245, DepthFunc@4) + GL_STUB(PixelZoom, 246, PixelZoom@8) + GL_STUB(PixelTransferf, 247, PixelTransferf@8) + GL_STUB(PixelTransferi, 248, PixelTransferi@8) + GL_STUB(PixelStoref, 249, PixelStoref@8) + GL_STUB(PixelStorei, 250, PixelStorei@8) + GL_STUB(PixelMapfv, 251, PixelMapfv@12) + GL_STUB(PixelMapuiv, 252, PixelMapuiv@12) + GL_STUB(PixelMapusv, 253, PixelMapusv@12) + GL_STUB(ReadBuffer, 254, ReadBuffer@4) + GL_STUB(CopyPixels, 255, CopyPixels@20) + GL_STUB(ReadPixels, 256, ReadPixels@28) + GL_STUB(DrawPixels, 257, DrawPixels@20) + GL_STUB(GetBooleanv, 258, GetBooleanv@8) + GL_STUB(GetClipPlane, 259, GetClipPlane@8) + GL_STUB(GetDoublev, 260, GetDoublev@8) + GL_STUB(GetError, 261, GetError@0) + GL_STUB(GetFloatv, 262, GetFloatv@8) + GL_STUB(GetIntegerv, 263, GetIntegerv@8) + GL_STUB(GetLightfv, 264, GetLightfv@12) + GL_STUB(GetLightiv, 265, GetLightiv@12) + GL_STUB(GetMapdv, 266, GetMapdv@12) + GL_STUB(GetMapfv, 267, GetMapfv@12) + GL_STUB(GetMapiv, 268, GetMapiv@12) + GL_STUB(GetMaterialfv, 269, GetMaterialfv@12) + GL_STUB(GetMaterialiv, 270, GetMaterialiv@12) + GL_STUB(GetPixelMapfv, 271, GetPixelMapfv@8) + GL_STUB(GetPixelMapuiv, 272, GetPixelMapuiv@8) + GL_STUB(GetPixelMapusv, 273, GetPixelMapusv@8) + GL_STUB(GetPolygonStipple, 274, GetPolygonStipple@4) + GL_STUB(GetString, 275, GetString@4) + GL_STUB(GetTexEnvfv, 276, GetTexEnvfv@12) + GL_STUB(GetTexEnviv, 277, GetTexEnviv@12) + GL_STUB(GetTexGendv, 278, GetTexGendv@12) + GL_STUB(GetTexGenfv, 279, GetTexGenfv@12) + GL_STUB(GetTexGeniv, 280, GetTexGeniv@12) + GL_STUB(GetTexImage, 281, GetTexImage@20) + GL_STUB(GetTexParameterfv, 282, GetTexParameterfv@12) + GL_STUB(GetTexParameteriv, 283, GetTexParameteriv@12) + GL_STUB(GetTexLevelParameterfv, 284, GetTexLevelParameterfv@16) + GL_STUB(GetTexLevelParameteriv, 285, GetTexLevelParameteriv@16) + GL_STUB(IsEnabled, 286, IsEnabled@4) + GL_STUB(IsList, 287, IsList@4) + GL_STUB(DepthRange, 288, DepthRange@16) + GL_STUB(Frustum, 289, Frustum@48) + GL_STUB(LoadIdentity, 290, LoadIdentity@0) + GL_STUB(LoadMatrixf, 291, LoadMatrixf@4) + GL_STUB(LoadMatrixd, 292, LoadMatrixd@4) + GL_STUB(MatrixMode, 293, MatrixMode@4) + GL_STUB(MultMatrixf, 294, MultMatrixf@4) + GL_STUB(MultMatrixd, 295, MultMatrixd@4) + GL_STUB(Ortho, 296, Ortho@48) + GL_STUB(PopMatrix, 297, PopMatrix@0) + GL_STUB(PushMatrix, 298, PushMatrix@0) + GL_STUB(Rotated, 299, Rotated@32) + GL_STUB(Rotatef, 300, Rotatef@16) + GL_STUB(Scaled, 301, Scaled@24) + GL_STUB(Scalef, 302, Scalef@12) + GL_STUB(Translated, 303, Translated@24) + GL_STUB(Translatef, 304, Translatef@12) + GL_STUB(Viewport, 305, Viewport@16) + GL_STUB(ArrayElement, 306, ArrayElement@4) + GL_STUB(BindTexture, 307, BindTexture@8) + GL_STUB(ColorPointer, 308, ColorPointer@16) + GL_STUB(DisableClientState, 309, DisableClientState@4) + GL_STUB(DrawArrays, 310, DrawArrays@12) + GL_STUB(DrawElements, 311, DrawElements@16) + GL_STUB(EdgeFlagPointer, 312, EdgeFlagPointer@8) + GL_STUB(EnableClientState, 313, EnableClientState@4) + GL_STUB(IndexPointer, 314, IndexPointer@12) + GL_STUB(Indexub, 315, Indexub@4) + GL_STUB(Indexubv, 316, Indexubv@4) + GL_STUB(InterleavedArrays, 317, InterleavedArrays@12) + GL_STUB(NormalPointer, 318, NormalPointer@12) + GL_STUB(PolygonOffset, 319, PolygonOffset@8) + GL_STUB(TexCoordPointer, 320, TexCoordPointer@16) + GL_STUB(VertexPointer, 321, VertexPointer@16) + GL_STUB(AreTexturesResident, 322, AreTexturesResident@12) + GL_STUB(CopyTexImage1D, 323, CopyTexImage1D@28) + GL_STUB(CopyTexImage2D, 324, CopyTexImage2D@32) + GL_STUB(CopyTexSubImage1D, 325, CopyTexSubImage1D@24) + GL_STUB(CopyTexSubImage2D, 326, CopyTexSubImage2D@32) + GL_STUB(DeleteTextures, 327, DeleteTextures@8) + GL_STUB(GenTextures, 328, GenTextures@8) + GL_STUB(GetPointerv, 329, GetPointerv@8) + GL_STUB(IsTexture, 330, IsTexture@4) + GL_STUB(PrioritizeTextures, 331, PrioritizeTextures@12) + GL_STUB(TexSubImage1D, 332, TexSubImage1D@28) + GL_STUB(TexSubImage2D, 333, TexSubImage2D@36) + GL_STUB(PopClientAttrib, 334, PopClientAttrib@0) + GL_STUB(PushClientAttrib, 335, PushClientAttrib@4) + GL_STUB(BlendColor, 336, BlendColor@16) + GL_STUB(BlendEquation, 337, BlendEquation@4) + GL_STUB(DrawRangeElements, 338, DrawRangeElements@24) + GL_STUB(ColorTable, 339, ColorTable@24) + GL_STUB(ColorTableParameterfv, 340, ColorTableParameterfv@12) + GL_STUB(ColorTableParameteriv, 341, ColorTableParameteriv@12) + GL_STUB(CopyColorTable, 342, CopyColorTable@20) + GL_STUB(GetColorTable, 343, GetColorTable@16) + GL_STUB(GetColorTableParameterfv, 344, GetColorTableParameterfv@12) + GL_STUB(GetColorTableParameteriv, 345, GetColorTableParameteriv@12) + GL_STUB(ColorSubTable, 346, ColorSubTable@24) + GL_STUB(CopyColorSubTable, 347, CopyColorSubTable@20) + GL_STUB(ConvolutionFilter1D, 348, ConvolutionFilter1D@24) + GL_STUB(ConvolutionFilter2D, 349, ConvolutionFilter2D@28) + GL_STUB(ConvolutionParameterf, 350, ConvolutionParameterf@12) + GL_STUB(ConvolutionParameterfv, 351, ConvolutionParameterfv@12) + GL_STUB(ConvolutionParameteri, 352, ConvolutionParameteri@12) + GL_STUB(ConvolutionParameteriv, 353, ConvolutionParameteriv@12) + GL_STUB(CopyConvolutionFilter1D, 354, CopyConvolutionFilter1D@20) + GL_STUB(CopyConvolutionFilter2D, 355, CopyConvolutionFilter2D@24) + GL_STUB(GetConvolutionFilter, 356, GetConvolutionFilter@16) + GL_STUB(GetConvolutionParameterfv, 357, GetConvolutionParameterfv@12) + GL_STUB(GetConvolutionParameteriv, 358, GetConvolutionParameteriv@12) + GL_STUB(GetSeparableFilter, 359, GetSeparableFilter@24) + GL_STUB(SeparableFilter2D, 360, SeparableFilter2D@32) + GL_STUB(GetHistogram, 361, GetHistogram@20) + GL_STUB(GetHistogramParameterfv, 362, GetHistogramParameterfv@12) + GL_STUB(GetHistogramParameteriv, 363, GetHistogramParameteriv@12) + GL_STUB(GetMinmax, 364, GetMinmax@20) + GL_STUB(GetMinmaxParameterfv, 365, GetMinmaxParameterfv@12) + GL_STUB(GetMinmaxParameteriv, 366, GetMinmaxParameteriv@12) + GL_STUB(Histogram, 367, Histogram@16) + GL_STUB(Minmax, 368, Minmax@12) + GL_STUB(ResetHistogram, 369, ResetHistogram@4) + GL_STUB(ResetMinmax, 370, ResetMinmax@4) + GL_STUB(TexImage3D, 371, TexImage3D@40) + GL_STUB(TexSubImage3D, 372, TexSubImage3D@44) + GL_STUB(CopyTexSubImage3D, 373, CopyTexSubImage3D@36) + GL_STUB(ActiveTextureARB, 374, ActiveTextureARB@4) + GL_STUB(ClientActiveTextureARB, 375, ClientActiveTextureARB@4) + GL_STUB(MultiTexCoord1dARB, 376, MultiTexCoord1dARB@12) + GL_STUB(MultiTexCoord1dvARB, 377, MultiTexCoord1dvARB@8) + GL_STUB(MultiTexCoord1fARB, 378, MultiTexCoord1fARB@8) + GL_STUB(MultiTexCoord1fvARB, 379, MultiTexCoord1fvARB@8) + GL_STUB(MultiTexCoord1iARB, 380, MultiTexCoord1iARB@8) + GL_STUB(MultiTexCoord1ivARB, 381, MultiTexCoord1ivARB@8) + GL_STUB(MultiTexCoord1sARB, 382, MultiTexCoord1sARB@8) + GL_STUB(MultiTexCoord1svARB, 383, MultiTexCoord1svARB@8) + GL_STUB(MultiTexCoord2dARB, 384, MultiTexCoord2dARB@20) + GL_STUB(MultiTexCoord2dvARB, 385, MultiTexCoord2dvARB@8) + GL_STUB(MultiTexCoord2fARB, 386, MultiTexCoord2fARB@12) + GL_STUB(MultiTexCoord2fvARB, 387, MultiTexCoord2fvARB@8) + GL_STUB(MultiTexCoord2iARB, 388, MultiTexCoord2iARB@12) + GL_STUB(MultiTexCoord2ivARB, 389, MultiTexCoord2ivARB@8) + GL_STUB(MultiTexCoord2sARB, 390, MultiTexCoord2sARB@12) + GL_STUB(MultiTexCoord2svARB, 391, MultiTexCoord2svARB@8) + GL_STUB(MultiTexCoord3dARB, 392, MultiTexCoord3dARB@28) + GL_STUB(MultiTexCoord3dvARB, 393, MultiTexCoord3dvARB@8) + GL_STUB(MultiTexCoord3fARB, 394, MultiTexCoord3fARB@16) + GL_STUB(MultiTexCoord3fvARB, 395, MultiTexCoord3fvARB@8) + GL_STUB(MultiTexCoord3iARB, 396, MultiTexCoord3iARB@16) + GL_STUB(MultiTexCoord3ivARB, 397, MultiTexCoord3ivARB@8) + GL_STUB(MultiTexCoord3sARB, 398, MultiTexCoord3sARB@16) + GL_STUB(MultiTexCoord3svARB, 399, MultiTexCoord3svARB@8) + GL_STUB(MultiTexCoord4dARB, 400, MultiTexCoord4dARB@36) + GL_STUB(MultiTexCoord4dvARB, 401, MultiTexCoord4dvARB@8) + GL_STUB(MultiTexCoord4fARB, 402, MultiTexCoord4fARB@20) + GL_STUB(MultiTexCoord4fvARB, 403, MultiTexCoord4fvARB@8) + GL_STUB(MultiTexCoord4iARB, 404, MultiTexCoord4iARB@20) + GL_STUB(MultiTexCoord4ivARB, 405, MultiTexCoord4ivARB@8) + GL_STUB(MultiTexCoord4sARB, 406, MultiTexCoord4sARB@20) + GL_STUB(MultiTexCoord4svARB, 407, MultiTexCoord4svARB@8) + GL_STUB(AttachShader, 408, AttachShader@8) + GL_STUB(CreateProgram, 409, CreateProgram@0) + GL_STUB(CreateShader, 410, CreateShader@4) + GL_STUB(DeleteProgram, 411, DeleteProgram@4) + GL_STUB(DeleteShader, 412, DeleteShader@4) + GL_STUB(DetachShader, 413, DetachShader@8) + GL_STUB(GetAttachedShaders, 414, GetAttachedShaders@16) + GL_STUB(GetProgramInfoLog, 415, GetProgramInfoLog@16) + GL_STUB(GetProgramiv, 416, GetProgramiv@12) + GL_STUB(GetShaderInfoLog, 417, GetShaderInfoLog@16) + GL_STUB(GetShaderiv, 418, GetShaderiv@12) + GL_STUB(IsProgram, 419, IsProgram@4) + GL_STUB(IsShader, 420, IsShader@4) + GL_STUB(StencilFuncSeparate, 421, StencilFuncSeparate@16) + GL_STUB(StencilMaskSeparate, 422, StencilMaskSeparate@8) + GL_STUB(StencilOpSeparate, 423, StencilOpSeparate@16) + GL_STUB(UniformMatrix2x3fv, 424, UniformMatrix2x3fv@16) + GL_STUB(UniformMatrix2x4fv, 425, UniformMatrix2x4fv@16) + GL_STUB(UniformMatrix3x2fv, 426, UniformMatrix3x2fv@16) + GL_STUB(UniformMatrix3x4fv, 427, UniformMatrix3x4fv@16) + GL_STUB(UniformMatrix4x2fv, 428, UniformMatrix4x2fv@16) + GL_STUB(UniformMatrix4x3fv, 429, UniformMatrix4x3fv@16) + GL_STUB(ClampColor, 430, ClampColor@8) + GL_STUB(ClearBufferfi, 431, ClearBufferfi@16) + GL_STUB(ClearBufferfv, 432, ClearBufferfv@12) + GL_STUB(ClearBufferiv, 433, ClearBufferiv@12) + GL_STUB(ClearBufferuiv, 434, ClearBufferuiv@12) + GL_STUB(GetStringi, 435, GetStringi@8) + GL_STUB(TexBuffer, 436, TexBuffer@12) + GL_STUB(FramebufferTexture, 437, FramebufferTexture@16) + GL_STUB(GetBufferParameteri64v, 438, GetBufferParameteri64v@12) + GL_STUB(GetInteger64i_v, 439, GetInteger64i_v@12) + GL_STUB(VertexAttribDivisor, 440, VertexAttribDivisor@8) + GL_STUB(LoadTransposeMatrixdARB, 441, LoadTransposeMatrixdARB@4) + GL_STUB(LoadTransposeMatrixfARB, 442, LoadTransposeMatrixfARB@4) + GL_STUB(MultTransposeMatrixdARB, 443, MultTransposeMatrixdARB@4) + GL_STUB(MultTransposeMatrixfARB, 444, MultTransposeMatrixfARB@4) + GL_STUB(SampleCoverageARB, 445, SampleCoverageARB@8) + GL_STUB(CompressedTexImage1DARB, 446, CompressedTexImage1DARB@28) + GL_STUB(CompressedTexImage2DARB, 447, CompressedTexImage2DARB@32) + GL_STUB(CompressedTexImage3DARB, 448, CompressedTexImage3DARB@36) + GL_STUB(CompressedTexSubImage1DARB, 449, CompressedTexSubImage1DARB@28) + GL_STUB(CompressedTexSubImage2DARB, 450, CompressedTexSubImage2DARB@36) + GL_STUB(CompressedTexSubImage3DARB, 451, CompressedTexSubImage3DARB@44) + GL_STUB(GetCompressedTexImageARB, 452, GetCompressedTexImageARB@12) + GL_STUB(DisableVertexAttribArrayARB, 453, DisableVertexAttribArrayARB@4) + GL_STUB(EnableVertexAttribArrayARB, 454, EnableVertexAttribArrayARB@4) + GL_STUB(GetProgramEnvParameterdvARB, 455, GetProgramEnvParameterdvARB@12) + GL_STUB(GetProgramEnvParameterfvARB, 456, GetProgramEnvParameterfvARB@12) + GL_STUB(GetProgramLocalParameterdvARB, 457, GetProgramLocalParameterdvARB@12) + GL_STUB(GetProgramLocalParameterfvARB, 458, GetProgramLocalParameterfvARB@12) + GL_STUB(GetProgramStringARB, 459, GetProgramStringARB@12) + GL_STUB(GetProgramivARB, 460, GetProgramivARB@12) + GL_STUB(GetVertexAttribdvARB, 461, GetVertexAttribdvARB@12) + GL_STUB(GetVertexAttribfvARB, 462, GetVertexAttribfvARB@12) + GL_STUB(GetVertexAttribivARB, 463, GetVertexAttribivARB@12) + GL_STUB(ProgramEnvParameter4dARB, 464, ProgramEnvParameter4dARB@40) + GL_STUB(ProgramEnvParameter4dvARB, 465, ProgramEnvParameter4dvARB@12) + GL_STUB(ProgramEnvParameter4fARB, 466, ProgramEnvParameter4fARB@24) + GL_STUB(ProgramEnvParameter4fvARB, 467, ProgramEnvParameter4fvARB@12) + GL_STUB(ProgramLocalParameter4dARB, 468, ProgramLocalParameter4dARB@40) + GL_STUB(ProgramLocalParameter4dvARB, 469, ProgramLocalParameter4dvARB@12) + GL_STUB(ProgramLocalParameter4fARB, 470, ProgramLocalParameter4fARB@24) + GL_STUB(ProgramLocalParameter4fvARB, 471, ProgramLocalParameter4fvARB@12) + GL_STUB(ProgramStringARB, 472, ProgramStringARB@16) + GL_STUB(VertexAttrib1dARB, 473, VertexAttrib1dARB@12) + GL_STUB(VertexAttrib1dvARB, 474, VertexAttrib1dvARB@8) + GL_STUB(VertexAttrib1fARB, 475, VertexAttrib1fARB@8) + GL_STUB(VertexAttrib1fvARB, 476, VertexAttrib1fvARB@8) + GL_STUB(VertexAttrib1sARB, 477, VertexAttrib1sARB@8) + GL_STUB(VertexAttrib1svARB, 478, VertexAttrib1svARB@8) + GL_STUB(VertexAttrib2dARB, 479, VertexAttrib2dARB@20) + GL_STUB(VertexAttrib2dvARB, 480, VertexAttrib2dvARB@8) + GL_STUB(VertexAttrib2fARB, 481, VertexAttrib2fARB@12) + GL_STUB(VertexAttrib2fvARB, 482, VertexAttrib2fvARB@8) + GL_STUB(VertexAttrib2sARB, 483, VertexAttrib2sARB@12) + GL_STUB(VertexAttrib2svARB, 484, VertexAttrib2svARB@8) + GL_STUB(VertexAttrib3dARB, 485, VertexAttrib3dARB@28) + GL_STUB(VertexAttrib3dvARB, 486, VertexAttrib3dvARB@8) + GL_STUB(VertexAttrib3fARB, 487, VertexAttrib3fARB@16) + GL_STUB(VertexAttrib3fvARB, 488, VertexAttrib3fvARB@8) + GL_STUB(VertexAttrib3sARB, 489, VertexAttrib3sARB@16) + GL_STUB(VertexAttrib3svARB, 490, VertexAttrib3svARB@8) + GL_STUB(VertexAttrib4NbvARB, 491, VertexAttrib4NbvARB@8) + GL_STUB(VertexAttrib4NivARB, 492, VertexAttrib4NivARB@8) + GL_STUB(VertexAttrib4NsvARB, 493, VertexAttrib4NsvARB@8) + GL_STUB(VertexAttrib4NubARB, 494, VertexAttrib4NubARB@20) + GL_STUB(VertexAttrib4NubvARB, 495, VertexAttrib4NubvARB@8) + GL_STUB(VertexAttrib4NuivARB, 496, VertexAttrib4NuivARB@8) + GL_STUB(VertexAttrib4NusvARB, 497, VertexAttrib4NusvARB@8) + GL_STUB(VertexAttrib4bvARB, 498, VertexAttrib4bvARB@8) + GL_STUB(VertexAttrib4dARB, 499, VertexAttrib4dARB@36) + GL_STUB(VertexAttrib4dvARB, 500, VertexAttrib4dvARB@8) + GL_STUB(VertexAttrib4fARB, 501, VertexAttrib4fARB@20) + GL_STUB(VertexAttrib4fvARB, 502, VertexAttrib4fvARB@8) + GL_STUB(VertexAttrib4ivARB, 503, VertexAttrib4ivARB@8) + GL_STUB(VertexAttrib4sARB, 504, VertexAttrib4sARB@20) + GL_STUB(VertexAttrib4svARB, 505, VertexAttrib4svARB@8) + GL_STUB(VertexAttrib4ubvARB, 506, VertexAttrib4ubvARB@8) + GL_STUB(VertexAttrib4uivARB, 507, VertexAttrib4uivARB@8) + GL_STUB(VertexAttrib4usvARB, 508, VertexAttrib4usvARB@8) + GL_STUB(VertexAttribPointerARB, 509, VertexAttribPointerARB@24) + GL_STUB(BindBufferARB, 510, BindBufferARB@8) + GL_STUB(BufferDataARB, 511, BufferDataARB@16) + GL_STUB(BufferSubDataARB, 512, BufferSubDataARB@16) + GL_STUB(DeleteBuffersARB, 513, DeleteBuffersARB@8) + GL_STUB(GenBuffersARB, 514, GenBuffersARB@8) + GL_STUB(GetBufferParameterivARB, 515, GetBufferParameterivARB@12) + GL_STUB(GetBufferPointervARB, 516, GetBufferPointervARB@12) + GL_STUB(GetBufferSubDataARB, 517, GetBufferSubDataARB@16) + GL_STUB(IsBufferARB, 518, IsBufferARB@4) + GL_STUB(MapBufferARB, 519, MapBufferARB@8) + GL_STUB(UnmapBufferARB, 520, UnmapBufferARB@4) + GL_STUB(BeginQueryARB, 521, BeginQueryARB@8) + GL_STUB(DeleteQueriesARB, 522, DeleteQueriesARB@8) + GL_STUB(EndQueryARB, 523, EndQueryARB@4) + GL_STUB(GenQueriesARB, 524, GenQueriesARB@8) + GL_STUB(GetQueryObjectivARB, 525, GetQueryObjectivARB@12) + GL_STUB(GetQueryObjectuivARB, 526, GetQueryObjectuivARB@12) + GL_STUB(GetQueryivARB, 527, GetQueryivARB@12) + GL_STUB(IsQueryARB, 528, IsQueryARB@4) + GL_STUB(AttachObjectARB, 529, AttachObjectARB@8) + GL_STUB(CompileShaderARB, 530, CompileShaderARB@4) + GL_STUB(CreateProgramObjectARB, 531, CreateProgramObjectARB@0) + GL_STUB(CreateShaderObjectARB, 532, CreateShaderObjectARB@4) + GL_STUB(DeleteObjectARB, 533, DeleteObjectARB@4) + GL_STUB(DetachObjectARB, 534, DetachObjectARB@8) + GL_STUB(GetActiveUniformARB, 535, GetActiveUniformARB@28) + GL_STUB(GetAttachedObjectsARB, 536, GetAttachedObjectsARB@16) + GL_STUB(GetHandleARB, 537, GetHandleARB@4) + GL_STUB(GetInfoLogARB, 538, GetInfoLogARB@16) + GL_STUB(GetObjectParameterfvARB, 539, GetObjectParameterfvARB@12) + GL_STUB(GetObjectParameterivARB, 540, GetObjectParameterivARB@12) + GL_STUB(GetShaderSourceARB, 541, GetShaderSourceARB@16) + GL_STUB(GetUniformLocationARB, 542, GetUniformLocationARB@8) + GL_STUB(GetUniformfvARB, 543, GetUniformfvARB@12) + GL_STUB(GetUniformivARB, 544, GetUniformivARB@12) + GL_STUB(LinkProgramARB, 545, LinkProgramARB@4) + GL_STUB(ShaderSourceARB, 546, ShaderSourceARB@16) + GL_STUB(Uniform1fARB, 547, Uniform1fARB@8) + GL_STUB(Uniform1fvARB, 548, Uniform1fvARB@12) + GL_STUB(Uniform1iARB, 549, Uniform1iARB@8) + GL_STUB(Uniform1ivARB, 550, Uniform1ivARB@12) + GL_STUB(Uniform2fARB, 551, Uniform2fARB@12) + GL_STUB(Uniform2fvARB, 552, Uniform2fvARB@12) + GL_STUB(Uniform2iARB, 553, Uniform2iARB@12) + GL_STUB(Uniform2ivARB, 554, Uniform2ivARB@12) + GL_STUB(Uniform3fARB, 555, Uniform3fARB@16) + GL_STUB(Uniform3fvARB, 556, Uniform3fvARB@12) + GL_STUB(Uniform3iARB, 557, Uniform3iARB@16) + GL_STUB(Uniform3ivARB, 558, Uniform3ivARB@12) + GL_STUB(Uniform4fARB, 559, Uniform4fARB@20) + GL_STUB(Uniform4fvARB, 560, Uniform4fvARB@12) + GL_STUB(Uniform4iARB, 561, Uniform4iARB@20) + GL_STUB(Uniform4ivARB, 562, Uniform4ivARB@12) + GL_STUB(UniformMatrix2fvARB, 563, UniformMatrix2fvARB@16) + GL_STUB(UniformMatrix3fvARB, 564, UniformMatrix3fvARB@16) + GL_STUB(UniformMatrix4fvARB, 565, UniformMatrix4fvARB@16) + GL_STUB(UseProgramObjectARB, 566, UseProgramObjectARB@4) + GL_STUB(ValidateProgramARB, 567, ValidateProgramARB@4) + GL_STUB(BindAttribLocationARB, 568, BindAttribLocationARB@12) + GL_STUB(GetActiveAttribARB, 569, GetActiveAttribARB@28) + GL_STUB(GetAttribLocationARB, 570, GetAttribLocationARB@8) + GL_STUB(DrawBuffersARB, 571, DrawBuffersARB@8) + GL_STUB(DrawArraysInstancedARB, 572, DrawArraysInstancedARB@16) + GL_STUB(DrawElementsInstancedARB, 573, DrawElementsInstancedARB@20) + GL_STUB(RenderbufferStorageMultisample, 574, RenderbufferStorageMultisample@20) + GL_STUB(FramebufferTextureARB, 575, FramebufferTextureARB@16) + GL_STUB(FramebufferTextureFaceARB, 576, FramebufferTextureFaceARB@20) + GL_STUB(ProgramParameteriARB, 577, ProgramParameteriARB@12) + GL_STUB(FlushMappedBufferRange, 578, FlushMappedBufferRange@12) + GL_STUB(MapBufferRange, 579, MapBufferRange@16) + GL_STUB(BindVertexArray, 580, BindVertexArray@4) + GL_STUB(GenVertexArrays, 581, GenVertexArrays@8) + GL_STUB(CopyBufferSubData, 582, CopyBufferSubData@20) + GL_STUB(ClientWaitSync, 583, ClientWaitSync@12) + GL_STUB(DeleteSync, 584, DeleteSync@4) + GL_STUB(FenceSync, 585, FenceSync@8) + GL_STUB(GetInteger64v, 586, GetInteger64v@8) + GL_STUB(GetSynciv, 587, GetSynciv@20) + GL_STUB(IsSync, 588, IsSync@4) + GL_STUB(WaitSync, 589, WaitSync@12) + GL_STUB(DrawElementsBaseVertex, 590, DrawElementsBaseVertex@20) + GL_STUB(DrawRangeElementsBaseVertex, 591, DrawRangeElementsBaseVertex@28) + GL_STUB(MultiDrawElementsBaseVertex, 592, MultiDrawElementsBaseVertex@24) + GL_STUB(BindTransformFeedback, 593, BindTransformFeedback@8) + GL_STUB(DeleteTransformFeedbacks, 594, DeleteTransformFeedbacks@8) + GL_STUB(DrawTransformFeedback, 595, DrawTransformFeedback@8) + GL_STUB(GenTransformFeedbacks, 596, GenTransformFeedbacks@8) + GL_STUB(IsTransformFeedback, 597, IsTransformFeedback@4) + GL_STUB(PauseTransformFeedback, 598, PauseTransformFeedback@0) + GL_STUB(ResumeTransformFeedback, 599, ResumeTransformFeedback@0) + GL_STUB(ClearDepthf, 600, ClearDepthf@4) + GL_STUB(DepthRangef, 601, DepthRangef@8) + GL_STUB(GetShaderPrecisionFormat, 602, GetShaderPrecisionFormat@16) + GL_STUB(ReleaseShaderCompiler, 603, ReleaseShaderCompiler@0) + GL_STUB(ShaderBinary, 604, ShaderBinary@20) + GL_STUB(PolygonOffsetEXT, 605, PolygonOffsetEXT@8) + GL_STUB(_dispatch_stub_606, 606, _dispatch_stub_606@8) + HIDDEN(GL_PREFIX(_dispatch_stub_606, _dispatch_stub_606@8)) + GL_STUB(_dispatch_stub_607, 607, _dispatch_stub_607@8) + HIDDEN(GL_PREFIX(_dispatch_stub_607, _dispatch_stub_607@8)) + GL_STUB(_dispatch_stub_608, 608, _dispatch_stub_608@8) + HIDDEN(GL_PREFIX(_dispatch_stub_608, _dispatch_stub_608@8)) + GL_STUB(_dispatch_stub_609, 609, _dispatch_stub_609@8) + HIDDEN(GL_PREFIX(_dispatch_stub_609, _dispatch_stub_609@8)) + GL_STUB(_dispatch_stub_610, 610, _dispatch_stub_610@8) + HIDDEN(GL_PREFIX(_dispatch_stub_610, _dispatch_stub_610@8)) + GL_STUB(_dispatch_stub_611, 611, _dispatch_stub_611@8) + HIDDEN(GL_PREFIX(_dispatch_stub_611, _dispatch_stub_611@8)) + GL_STUB(_dispatch_stub_612, 612, _dispatch_stub_612@8) + HIDDEN(GL_PREFIX(_dispatch_stub_612, _dispatch_stub_612@8)) + GL_STUB(_dispatch_stub_613, 613, _dispatch_stub_613@4) + HIDDEN(GL_PREFIX(_dispatch_stub_613, _dispatch_stub_613@4)) + GL_STUB(ColorPointerEXT, 614, ColorPointerEXT@20) + GL_STUB(EdgeFlagPointerEXT, 615, EdgeFlagPointerEXT@12) + GL_STUB(IndexPointerEXT, 616, IndexPointerEXT@16) + GL_STUB(NormalPointerEXT, 617, NormalPointerEXT@16) + GL_STUB(TexCoordPointerEXT, 618, TexCoordPointerEXT@20) + GL_STUB(VertexPointerEXT, 619, VertexPointerEXT@20) + GL_STUB(PointParameterfEXT, 620, PointParameterfEXT@8) + GL_STUB(PointParameterfvEXT, 621, PointParameterfvEXT@8) + GL_STUB(LockArraysEXT, 622, LockArraysEXT@8) + GL_STUB(UnlockArraysEXT, 623, UnlockArraysEXT@0) + GL_STUB(SecondaryColor3bEXT, 624, SecondaryColor3bEXT@12) + GL_STUB(SecondaryColor3bvEXT, 625, SecondaryColor3bvEXT@4) + GL_STUB(SecondaryColor3dEXT, 626, SecondaryColor3dEXT@24) + GL_STUB(SecondaryColor3dvEXT, 627, SecondaryColor3dvEXT@4) + GL_STUB(SecondaryColor3fEXT, 628, SecondaryColor3fEXT@12) + GL_STUB(SecondaryColor3fvEXT, 629, SecondaryColor3fvEXT@4) + GL_STUB(SecondaryColor3iEXT, 630, SecondaryColor3iEXT@12) + GL_STUB(SecondaryColor3ivEXT, 631, SecondaryColor3ivEXT@4) + GL_STUB(SecondaryColor3sEXT, 632, SecondaryColor3sEXT@12) + GL_STUB(SecondaryColor3svEXT, 633, SecondaryColor3svEXT@4) + GL_STUB(SecondaryColor3ubEXT, 634, SecondaryColor3ubEXT@12) + GL_STUB(SecondaryColor3ubvEXT, 635, SecondaryColor3ubvEXT@4) + GL_STUB(SecondaryColor3uiEXT, 636, SecondaryColor3uiEXT@12) + GL_STUB(SecondaryColor3uivEXT, 637, SecondaryColor3uivEXT@4) + GL_STUB(SecondaryColor3usEXT, 638, SecondaryColor3usEXT@12) + GL_STUB(SecondaryColor3usvEXT, 639, SecondaryColor3usvEXT@4) + GL_STUB(SecondaryColorPointerEXT, 640, SecondaryColorPointerEXT@16) + GL_STUB(MultiDrawArraysEXT, 641, MultiDrawArraysEXT@16) + GL_STUB(MultiDrawElementsEXT, 642, MultiDrawElementsEXT@20) + GL_STUB(FogCoordPointerEXT, 643, FogCoordPointerEXT@12) + GL_STUB(FogCoorddEXT, 644, FogCoorddEXT@8) + GL_STUB(FogCoorddvEXT, 645, FogCoorddvEXT@4) + GL_STUB(FogCoordfEXT, 646, FogCoordfEXT@4) + GL_STUB(FogCoordfvEXT, 647, FogCoordfvEXT@4) + GL_STUB(_dispatch_stub_648, 648, _dispatch_stub_648@4) + HIDDEN(GL_PREFIX(_dispatch_stub_648, _dispatch_stub_648@4)) + GL_STUB(BlendFuncSeparateEXT, 649, BlendFuncSeparateEXT@16) + GL_STUB(FlushVertexArrayRangeNV, 650, FlushVertexArrayRangeNV@0) + GL_STUB(VertexArrayRangeNV, 651, VertexArrayRangeNV@8) + GL_STUB(CombinerInputNV, 652, CombinerInputNV@24) + GL_STUB(CombinerOutputNV, 653, CombinerOutputNV@40) + GL_STUB(CombinerParameterfNV, 654, CombinerParameterfNV@8) + GL_STUB(CombinerParameterfvNV, 655, CombinerParameterfvNV@8) + GL_STUB(CombinerParameteriNV, 656, CombinerParameteriNV@8) + GL_STUB(CombinerParameterivNV, 657, CombinerParameterivNV@8) + GL_STUB(FinalCombinerInputNV, 658, FinalCombinerInputNV@16) + GL_STUB(GetCombinerInputParameterfvNV, 659, GetCombinerInputParameterfvNV@20) + GL_STUB(GetCombinerInputParameterivNV, 660, GetCombinerInputParameterivNV@20) + GL_STUB(GetCombinerOutputParameterfvNV, 661, GetCombinerOutputParameterfvNV@16) + GL_STUB(GetCombinerOutputParameterivNV, 662, GetCombinerOutputParameterivNV@16) + GL_STUB(GetFinalCombinerInputParameterfvNV, 663, GetFinalCombinerInputParameterfvNV@12) + GL_STUB(GetFinalCombinerInputParameterivNV, 664, GetFinalCombinerInputParameterivNV@12) + GL_STUB(ResizeBuffersMESA, 665, ResizeBuffersMESA@0) + GL_STUB(WindowPos2dMESA, 666, WindowPos2dMESA@16) + GL_STUB(WindowPos2dvMESA, 667, WindowPos2dvMESA@4) + GL_STUB(WindowPos2fMESA, 668, WindowPos2fMESA@8) + GL_STUB(WindowPos2fvMESA, 669, WindowPos2fvMESA@4) + GL_STUB(WindowPos2iMESA, 670, WindowPos2iMESA@8) + GL_STUB(WindowPos2ivMESA, 671, WindowPos2ivMESA@4) + GL_STUB(WindowPos2sMESA, 672, WindowPos2sMESA@8) + GL_STUB(WindowPos2svMESA, 673, WindowPos2svMESA@4) + GL_STUB(WindowPos3dMESA, 674, WindowPos3dMESA@24) + GL_STUB(WindowPos3dvMESA, 675, WindowPos3dvMESA@4) + GL_STUB(WindowPos3fMESA, 676, WindowPos3fMESA@12) + GL_STUB(WindowPos3fvMESA, 677, WindowPos3fvMESA@4) + GL_STUB(WindowPos3iMESA, 678, WindowPos3iMESA@12) + GL_STUB(WindowPos3ivMESA, 679, WindowPos3ivMESA@4) + GL_STUB(WindowPos3sMESA, 680, WindowPos3sMESA@12) + GL_STUB(WindowPos3svMESA, 681, WindowPos3svMESA@4) + GL_STUB(WindowPos4dMESA, 682, WindowPos4dMESA@32) + GL_STUB(WindowPos4dvMESA, 683, WindowPos4dvMESA@4) + GL_STUB(WindowPos4fMESA, 684, WindowPos4fMESA@16) + GL_STUB(WindowPos4fvMESA, 685, WindowPos4fvMESA@4) + GL_STUB(WindowPos4iMESA, 686, WindowPos4iMESA@16) + GL_STUB(WindowPos4ivMESA, 687, WindowPos4ivMESA@4) + GL_STUB(WindowPos4sMESA, 688, WindowPos4sMESA@16) + GL_STUB(WindowPos4svMESA, 689, WindowPos4svMESA@4) + GL_STUB(_dispatch_stub_690, 690, _dispatch_stub_690@20) + HIDDEN(GL_PREFIX(_dispatch_stub_690, _dispatch_stub_690@20)) + GL_STUB(_dispatch_stub_691, 691, _dispatch_stub_691@24) + HIDDEN(GL_PREFIX(_dispatch_stub_691, _dispatch_stub_691@24)) + GL_STUB(_dispatch_stub_692, 692, _dispatch_stub_692@8) + HIDDEN(GL_PREFIX(_dispatch_stub_692, _dispatch_stub_692@8)) + GL_STUB(_dispatch_stub_693, 693, _dispatch_stub_693@4) + HIDDEN(GL_PREFIX(_dispatch_stub_693, _dispatch_stub_693@4)) + GL_STUB(_dispatch_stub_694, 694, _dispatch_stub_694@8) + HIDDEN(GL_PREFIX(_dispatch_stub_694, _dispatch_stub_694@8)) + GL_STUB(_dispatch_stub_695, 695, _dispatch_stub_695@12) + HIDDEN(GL_PREFIX(_dispatch_stub_695, _dispatch_stub_695@12)) + GL_STUB(_dispatch_stub_696, 696, _dispatch_stub_696@4) + HIDDEN(GL_PREFIX(_dispatch_stub_696, _dispatch_stub_696@4)) + GL_STUB(_dispatch_stub_697, 697, _dispatch_stub_697@8) + HIDDEN(GL_PREFIX(_dispatch_stub_697, _dispatch_stub_697@8)) + GL_STUB(_dispatch_stub_698, 698, _dispatch_stub_698@4) + HIDDEN(GL_PREFIX(_dispatch_stub_698, _dispatch_stub_698@4)) + GL_STUB(AreProgramsResidentNV, 699, AreProgramsResidentNV@12) + GL_STUB(BindProgramNV, 700, BindProgramNV@8) + GL_STUB(DeleteProgramsNV, 701, DeleteProgramsNV@8) + GL_STUB(ExecuteProgramNV, 702, ExecuteProgramNV@12) + GL_STUB(GenProgramsNV, 703, GenProgramsNV@8) + GL_STUB(GetProgramParameterdvNV, 704, GetProgramParameterdvNV@16) + GL_STUB(GetProgramParameterfvNV, 705, GetProgramParameterfvNV@16) + GL_STUB(GetProgramStringNV, 706, GetProgramStringNV@12) + GL_STUB(GetProgramivNV, 707, GetProgramivNV@12) + GL_STUB(GetTrackMatrixivNV, 708, GetTrackMatrixivNV@16) + GL_STUB(GetVertexAttribPointervNV, 709, GetVertexAttribPointervNV@12) + GL_STUB(GetVertexAttribdvNV, 710, GetVertexAttribdvNV@12) + GL_STUB(GetVertexAttribfvNV, 711, GetVertexAttribfvNV@12) + GL_STUB(GetVertexAttribivNV, 712, GetVertexAttribivNV@12) + GL_STUB(IsProgramNV, 713, IsProgramNV@4) + GL_STUB(LoadProgramNV, 714, LoadProgramNV@16) + GL_STUB(ProgramParameters4dvNV, 715, ProgramParameters4dvNV@16) + GL_STUB(ProgramParameters4fvNV, 716, ProgramParameters4fvNV@16) + GL_STUB(RequestResidentProgramsNV, 717, RequestResidentProgramsNV@8) + GL_STUB(TrackMatrixNV, 718, TrackMatrixNV@16) + GL_STUB(VertexAttrib1dNV, 719, VertexAttrib1dNV@12) + GL_STUB(VertexAttrib1dvNV, 720, VertexAttrib1dvNV@8) + GL_STUB(VertexAttrib1fNV, 721, VertexAttrib1fNV@8) + GL_STUB(VertexAttrib1fvNV, 722, VertexAttrib1fvNV@8) + GL_STUB(VertexAttrib1sNV, 723, VertexAttrib1sNV@8) + GL_STUB(VertexAttrib1svNV, 724, VertexAttrib1svNV@8) + GL_STUB(VertexAttrib2dNV, 725, VertexAttrib2dNV@20) + GL_STUB(VertexAttrib2dvNV, 726, VertexAttrib2dvNV@8) + GL_STUB(VertexAttrib2fNV, 727, VertexAttrib2fNV@12) + GL_STUB(VertexAttrib2fvNV, 728, VertexAttrib2fvNV@8) + GL_STUB(VertexAttrib2sNV, 729, VertexAttrib2sNV@12) + GL_STUB(VertexAttrib2svNV, 730, VertexAttrib2svNV@8) + GL_STUB(VertexAttrib3dNV, 731, VertexAttrib3dNV@28) + GL_STUB(VertexAttrib3dvNV, 732, VertexAttrib3dvNV@8) + GL_STUB(VertexAttrib3fNV, 733, VertexAttrib3fNV@16) + GL_STUB(VertexAttrib3fvNV, 734, VertexAttrib3fvNV@8) + GL_STUB(VertexAttrib3sNV, 735, VertexAttrib3sNV@16) + GL_STUB(VertexAttrib3svNV, 736, VertexAttrib3svNV@8) + GL_STUB(VertexAttrib4dNV, 737, VertexAttrib4dNV@36) + GL_STUB(VertexAttrib4dvNV, 738, VertexAttrib4dvNV@8) + GL_STUB(VertexAttrib4fNV, 739, VertexAttrib4fNV@20) + GL_STUB(VertexAttrib4fvNV, 740, VertexAttrib4fvNV@8) + GL_STUB(VertexAttrib4sNV, 741, VertexAttrib4sNV@20) + GL_STUB(VertexAttrib4svNV, 742, VertexAttrib4svNV@8) + GL_STUB(VertexAttrib4ubNV, 743, VertexAttrib4ubNV@20) + GL_STUB(VertexAttrib4ubvNV, 744, VertexAttrib4ubvNV@8) + GL_STUB(VertexAttribPointerNV, 745, VertexAttribPointerNV@20) + GL_STUB(VertexAttribs1dvNV, 746, VertexAttribs1dvNV@12) + GL_STUB(VertexAttribs1fvNV, 747, VertexAttribs1fvNV@12) + GL_STUB(VertexAttribs1svNV, 748, VertexAttribs1svNV@12) + GL_STUB(VertexAttribs2dvNV, 749, VertexAttribs2dvNV@12) + GL_STUB(VertexAttribs2fvNV, 750, VertexAttribs2fvNV@12) + GL_STUB(VertexAttribs2svNV, 751, VertexAttribs2svNV@12) + GL_STUB(VertexAttribs3dvNV, 752, VertexAttribs3dvNV@12) + GL_STUB(VertexAttribs3fvNV, 753, VertexAttribs3fvNV@12) + GL_STUB(VertexAttribs3svNV, 754, VertexAttribs3svNV@12) + GL_STUB(VertexAttribs4dvNV, 755, VertexAttribs4dvNV@12) + GL_STUB(VertexAttribs4fvNV, 756, VertexAttribs4fvNV@12) + GL_STUB(VertexAttribs4svNV, 757, VertexAttribs4svNV@12) + GL_STUB(VertexAttribs4ubvNV, 758, VertexAttribs4ubvNV@12) + GL_STUB(GetTexBumpParameterfvATI, 759, GetTexBumpParameterfvATI@8) + GL_STUB(GetTexBumpParameterivATI, 760, GetTexBumpParameterivATI@8) + GL_STUB(TexBumpParameterfvATI, 761, TexBumpParameterfvATI@8) + GL_STUB(TexBumpParameterivATI, 762, TexBumpParameterivATI@8) + GL_STUB(AlphaFragmentOp1ATI, 763, AlphaFragmentOp1ATI@24) + GL_STUB(AlphaFragmentOp2ATI, 764, AlphaFragmentOp2ATI@36) + GL_STUB(AlphaFragmentOp3ATI, 765, AlphaFragmentOp3ATI@48) + GL_STUB(BeginFragmentShaderATI, 766, BeginFragmentShaderATI@0) + GL_STUB(BindFragmentShaderATI, 767, BindFragmentShaderATI@4) + GL_STUB(ColorFragmentOp1ATI, 768, ColorFragmentOp1ATI@28) + GL_STUB(ColorFragmentOp2ATI, 769, ColorFragmentOp2ATI@40) + GL_STUB(ColorFragmentOp3ATI, 770, ColorFragmentOp3ATI@52) + GL_STUB(DeleteFragmentShaderATI, 771, DeleteFragmentShaderATI@4) + GL_STUB(EndFragmentShaderATI, 772, EndFragmentShaderATI@0) + GL_STUB(GenFragmentShadersATI, 773, GenFragmentShadersATI@4) + GL_STUB(PassTexCoordATI, 774, PassTexCoordATI@12) + GL_STUB(SampleMapATI, 775, SampleMapATI@12) + GL_STUB(SetFragmentShaderConstantATI, 776, SetFragmentShaderConstantATI@8) + GL_STUB(PointParameteriNV, 777, PointParameteriNV@8) + GL_STUB(PointParameterivNV, 778, PointParameterivNV@8) + GL_STUB(_dispatch_stub_779, 779, _dispatch_stub_779@4) + HIDDEN(GL_PREFIX(_dispatch_stub_779, _dispatch_stub_779@4)) + GL_STUB(_dispatch_stub_780, 780, _dispatch_stub_780@4) + HIDDEN(GL_PREFIX(_dispatch_stub_780, _dispatch_stub_780@4)) + GL_STUB(_dispatch_stub_781, 781, _dispatch_stub_781@8) + HIDDEN(GL_PREFIX(_dispatch_stub_781, _dispatch_stub_781@8)) + GL_STUB(_dispatch_stub_782, 782, _dispatch_stub_782@8) + HIDDEN(GL_PREFIX(_dispatch_stub_782, _dispatch_stub_782@8)) + GL_STUB(_dispatch_stub_783, 783, _dispatch_stub_783@4) + HIDDEN(GL_PREFIX(_dispatch_stub_783, _dispatch_stub_783@4)) + GL_STUB(GetProgramNamedParameterdvNV, 784, GetProgramNamedParameterdvNV@16) + GL_STUB(GetProgramNamedParameterfvNV, 785, GetProgramNamedParameterfvNV@16) + GL_STUB(ProgramNamedParameter4dNV, 786, ProgramNamedParameter4dNV@44) + GL_STUB(ProgramNamedParameter4dvNV, 787, ProgramNamedParameter4dvNV@16) + GL_STUB(ProgramNamedParameter4fNV, 788, ProgramNamedParameter4fNV@28) + GL_STUB(ProgramNamedParameter4fvNV, 789, ProgramNamedParameter4fvNV@16) + GL_STUB(PrimitiveRestartIndexNV, 790, PrimitiveRestartIndexNV@4) + GL_STUB(PrimitiveRestartNV, 791, PrimitiveRestartNV@0) + GL_STUB(_dispatch_stub_792, 792, _dispatch_stub_792@16) + HIDDEN(GL_PREFIX(_dispatch_stub_792, _dispatch_stub_792@16)) + GL_STUB(_dispatch_stub_793, 793, _dispatch_stub_793@8) + HIDDEN(GL_PREFIX(_dispatch_stub_793, _dispatch_stub_793@8)) + GL_STUB(BindFramebufferEXT, 794, BindFramebufferEXT@8) + GL_STUB(BindRenderbufferEXT, 795, BindRenderbufferEXT@8) + GL_STUB(CheckFramebufferStatusEXT, 796, CheckFramebufferStatusEXT@4) + GL_STUB(DeleteFramebuffersEXT, 797, DeleteFramebuffersEXT@8) + GL_STUB(DeleteRenderbuffersEXT, 798, DeleteRenderbuffersEXT@8) + GL_STUB(FramebufferRenderbufferEXT, 799, FramebufferRenderbufferEXT@16) + GL_STUB(FramebufferTexture1DEXT, 800, FramebufferTexture1DEXT@20) + GL_STUB(FramebufferTexture2DEXT, 801, FramebufferTexture2DEXT@20) + GL_STUB(FramebufferTexture3DEXT, 802, FramebufferTexture3DEXT@24) + GL_STUB(GenFramebuffersEXT, 803, GenFramebuffersEXT@8) + GL_STUB(GenRenderbuffersEXT, 804, GenRenderbuffersEXT@8) + GL_STUB(GenerateMipmapEXT, 805, GenerateMipmapEXT@4) + GL_STUB(GetFramebufferAttachmentParameterivEXT, 806, GetFramebufferAttachmentParameterivEXT@16) + GL_STUB(GetRenderbufferParameterivEXT, 807, GetRenderbufferParameterivEXT@12) + GL_STUB(IsFramebufferEXT, 808, IsFramebufferEXT@4) + GL_STUB(IsRenderbufferEXT, 809, IsRenderbufferEXT@4) + GL_STUB(RenderbufferStorageEXT, 810, RenderbufferStorageEXT@16) + GL_STUB(_dispatch_stub_811, 811, _dispatch_stub_811@40) + HIDDEN(GL_PREFIX(_dispatch_stub_811, _dispatch_stub_811@40)) + GL_STUB(_dispatch_stub_812, 812, _dispatch_stub_812@12) + HIDDEN(GL_PREFIX(_dispatch_stub_812, _dispatch_stub_812@12)) + GL_STUB(_dispatch_stub_813, 813, _dispatch_stub_813@12) + HIDDEN(GL_PREFIX(_dispatch_stub_813, _dispatch_stub_813@12)) + GL_STUB(BindFragDataLocationEXT, 814, BindFragDataLocationEXT@12) + GL_STUB(GetFragDataLocationEXT, 815, GetFragDataLocationEXT@8) + GL_STUB(GetUniformuivEXT, 816, GetUniformuivEXT@12) + GL_STUB(GetVertexAttribIivEXT, 817, GetVertexAttribIivEXT@12) + GL_STUB(GetVertexAttribIuivEXT, 818, GetVertexAttribIuivEXT@12) + GL_STUB(Uniform1uiEXT, 819, Uniform1uiEXT@8) + GL_STUB(Uniform1uivEXT, 820, Uniform1uivEXT@12) + GL_STUB(Uniform2uiEXT, 821, Uniform2uiEXT@12) + GL_STUB(Uniform2uivEXT, 822, Uniform2uivEXT@12) + GL_STUB(Uniform3uiEXT, 823, Uniform3uiEXT@16) + GL_STUB(Uniform3uivEXT, 824, Uniform3uivEXT@12) + GL_STUB(Uniform4uiEXT, 825, Uniform4uiEXT@20) + GL_STUB(Uniform4uivEXT, 826, Uniform4uivEXT@12) + GL_STUB(VertexAttribI1iEXT, 827, VertexAttribI1iEXT@8) + GL_STUB(VertexAttribI1ivEXT, 828, VertexAttribI1ivEXT@8) + GL_STUB(VertexAttribI1uiEXT, 829, VertexAttribI1uiEXT@8) + GL_STUB(VertexAttribI1uivEXT, 830, VertexAttribI1uivEXT@8) + GL_STUB(VertexAttribI2iEXT, 831, VertexAttribI2iEXT@12) + GL_STUB(VertexAttribI2ivEXT, 832, VertexAttribI2ivEXT@8) + GL_STUB(VertexAttribI2uiEXT, 833, VertexAttribI2uiEXT@12) + GL_STUB(VertexAttribI2uivEXT, 834, VertexAttribI2uivEXT@8) + GL_STUB(VertexAttribI3iEXT, 835, VertexAttribI3iEXT@16) + GL_STUB(VertexAttribI3ivEXT, 836, VertexAttribI3ivEXT@8) + GL_STUB(VertexAttribI3uiEXT, 837, VertexAttribI3uiEXT@16) + GL_STUB(VertexAttribI3uivEXT, 838, VertexAttribI3uivEXT@8) + GL_STUB(VertexAttribI4bvEXT, 839, VertexAttribI4bvEXT@8) + GL_STUB(VertexAttribI4iEXT, 840, VertexAttribI4iEXT@20) + GL_STUB(VertexAttribI4ivEXT, 841, VertexAttribI4ivEXT@8) + GL_STUB(VertexAttribI4svEXT, 842, VertexAttribI4svEXT@8) + GL_STUB(VertexAttribI4ubvEXT, 843, VertexAttribI4ubvEXT@8) + GL_STUB(VertexAttribI4uiEXT, 844, VertexAttribI4uiEXT@20) + GL_STUB(VertexAttribI4uivEXT, 845, VertexAttribI4uivEXT@8) + GL_STUB(VertexAttribI4usvEXT, 846, VertexAttribI4usvEXT@8) + GL_STUB(VertexAttribIPointerEXT, 847, VertexAttribIPointerEXT@20) + GL_STUB(FramebufferTextureLayerEXT, 848, FramebufferTextureLayerEXT@20) + GL_STUB(ColorMaskIndexedEXT, 849, ColorMaskIndexedEXT@20) + GL_STUB(DisableIndexedEXT, 850, DisableIndexedEXT@8) + GL_STUB(EnableIndexedEXT, 851, EnableIndexedEXT@8) + GL_STUB(GetBooleanIndexedvEXT, 852, GetBooleanIndexedvEXT@12) + GL_STUB(GetIntegerIndexedvEXT, 853, GetIntegerIndexedvEXT@12) + GL_STUB(IsEnabledIndexedEXT, 854, IsEnabledIndexedEXT@8) + GL_STUB(ClearColorIiEXT, 855, ClearColorIiEXT@16) + GL_STUB(ClearColorIuiEXT, 856, ClearColorIuiEXT@16) + GL_STUB(GetTexParameterIivEXT, 857, GetTexParameterIivEXT@12) + GL_STUB(GetTexParameterIuivEXT, 858, GetTexParameterIuivEXT@12) + GL_STUB(TexParameterIivEXT, 859, TexParameterIivEXT@12) + GL_STUB(TexParameterIuivEXT, 860, TexParameterIuivEXT@12) + GL_STUB(BeginConditionalRenderNV, 861, BeginConditionalRenderNV@8) + GL_STUB(EndConditionalRenderNV, 862, EndConditionalRenderNV@0) + GL_STUB(BeginTransformFeedbackEXT, 863, BeginTransformFeedbackEXT@4) + GL_STUB(BindBufferBaseEXT, 864, BindBufferBaseEXT@12) + GL_STUB(BindBufferOffsetEXT, 865, BindBufferOffsetEXT@16) + GL_STUB(BindBufferRangeEXT, 866, BindBufferRangeEXT@20) + GL_STUB(EndTransformFeedbackEXT, 867, EndTransformFeedbackEXT@0) + GL_STUB(GetTransformFeedbackVaryingEXT, 868, GetTransformFeedbackVaryingEXT@28) + GL_STUB(TransformFeedbackVaryingsEXT, 869, TransformFeedbackVaryingsEXT@16) + GL_STUB(ProvokingVertexEXT, 870, ProvokingVertexEXT@4) + GL_STUB(_dispatch_stub_871, 871, _dispatch_stub_871@12) + HIDDEN(GL_PREFIX(_dispatch_stub_871, _dispatch_stub_871@12)) + GL_STUB(_dispatch_stub_872, 872, _dispatch_stub_872@12) + HIDDEN(GL_PREFIX(_dispatch_stub_872, _dispatch_stub_872@12)) + GL_STUB(GetObjectParameterivAPPLE, 873, GetObjectParameterivAPPLE@16) + GL_STUB(ObjectPurgeableAPPLE, 874, ObjectPurgeableAPPLE@12) + GL_STUB(ObjectUnpurgeableAPPLE, 875, ObjectUnpurgeableAPPLE@12) + GL_STUB(ActiveProgramEXT, 876, ActiveProgramEXT@4) + GL_STUB(CreateShaderProgramEXT, 877, CreateShaderProgramEXT@8) + GL_STUB(UseShaderProgramEXT, 878, UseShaderProgramEXT@8) + GL_STUB(_dispatch_stub_879, 879, _dispatch_stub_879@16) + HIDDEN(GL_PREFIX(_dispatch_stub_879, _dispatch_stub_879@16)) + GL_STUB(_dispatch_stub_880, 880, _dispatch_stub_880@16) + HIDDEN(GL_PREFIX(_dispatch_stub_880, _dispatch_stub_880@16)) + GL_STUB(_dispatch_stub_881, 881, _dispatch_stub_881@16) + HIDDEN(GL_PREFIX(_dispatch_stub_881, _dispatch_stub_881@16)) + GL_STUB(_dispatch_stub_882, 882, _dispatch_stub_882@12) + HIDDEN(GL_PREFIX(_dispatch_stub_882, _dispatch_stub_882@12)) + GL_STUB(_dispatch_stub_883, 883, _dispatch_stub_883@12) + HIDDEN(GL_PREFIX(_dispatch_stub_883, _dispatch_stub_883@12)) + GL_STUB(EGLImageTargetRenderbufferStorageOES, 884, EGLImageTargetRenderbufferStorageOES@8) + GL_STUB(EGLImageTargetTexture2DOES, 885, EGLImageTargetTexture2DOES@8) + GL_STUB_ALIAS(ArrayElementEXT, 306, ArrayElementEXT@4, ArrayElement, ArrayElement@4) + GL_STUB_ALIAS(BindTextureEXT, 307, BindTextureEXT@8, BindTexture, BindTexture@8) + GL_STUB_ALIAS(DrawArraysEXT, 310, DrawArraysEXT@12, DrawArrays, DrawArrays@12) +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(AreTexturesResidentEXT, 322, AreTexturesResidentEXT@12, AreTexturesResident, AreTexturesResident@12) +#endif + GL_STUB_ALIAS(CopyTexImage1DEXT, 323, CopyTexImage1DEXT@28, CopyTexImage1D, CopyTexImage1D@28) + GL_STUB_ALIAS(CopyTexImage2DEXT, 324, CopyTexImage2DEXT@32, CopyTexImage2D, CopyTexImage2D@32) + GL_STUB_ALIAS(CopyTexSubImage1DEXT, 325, CopyTexSubImage1DEXT@24, CopyTexSubImage1D, CopyTexSubImage1D@24) + GL_STUB_ALIAS(CopyTexSubImage2DEXT, 326, CopyTexSubImage2DEXT@32, CopyTexSubImage2D, CopyTexSubImage2D@32) +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(DeleteTexturesEXT, 327, DeleteTexturesEXT@8, DeleteTextures, DeleteTextures@8) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(GenTexturesEXT, 328, GenTexturesEXT@8, GenTextures, GenTextures@8) +#endif + GL_STUB_ALIAS(GetPointervEXT, 329, GetPointervEXT@8, GetPointerv, GetPointerv@8) +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(IsTextureEXT, 330, IsTextureEXT@4, IsTexture, IsTexture@4) +#endif + GL_STUB_ALIAS(PrioritizeTexturesEXT, 331, PrioritizeTexturesEXT@12, PrioritizeTextures, PrioritizeTextures@12) + GL_STUB_ALIAS(TexSubImage1DEXT, 332, TexSubImage1DEXT@28, TexSubImage1D, TexSubImage1D@28) + GL_STUB_ALIAS(TexSubImage2DEXT, 333, TexSubImage2DEXT@36, TexSubImage2D, TexSubImage2D@36) + GL_STUB_ALIAS(BlendColorEXT, 336, BlendColorEXT@16, BlendColor, BlendColor@16) + GL_STUB_ALIAS(BlendEquationEXT, 337, BlendEquationEXT@4, BlendEquation, BlendEquation@4) + GL_STUB_ALIAS(DrawRangeElementsEXT, 338, DrawRangeElementsEXT@24, DrawRangeElements, DrawRangeElements@24) + GL_STUB_ALIAS(ColorTableEXT, 339, ColorTableEXT@24, ColorTable, ColorTable@24) +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(GetColorTableEXT, 343, GetColorTableEXT@16, GetColorTable, GetColorTable@16) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(GetColorTableParameterfvEXT, 344, GetColorTableParameterfvEXT@12, GetColorTableParameterfv, GetColorTableParameterfv@12) +#endif +#ifndef GLX_INDIRECT_RENDERING + GL_STUB_ALIAS(GetColorTableParameterivEXT, 345, GetColorTableParameterivEXT@12, GetColorTableParameteriv, GetColorTableParameteriv@12) +#endif + GL_STUB_ALIAS(TexImage3DEXT, 371, TexImage3DEXT@40, TexImage3D, TexImage3D@40) + GL_STUB_ALIAS(TexSubImage3DEXT, 372, TexSubImage3DEXT@44, TexSubImage3D, TexSubImage3D@44) + GL_STUB_ALIAS(CopyTexSubImage3DEXT, 373, CopyTexSubImage3DEXT@36, CopyTexSubImage3D, CopyTexSubImage3D@36) + GL_STUB_ALIAS(ActiveTexture, 374, ActiveTexture@4, ActiveTextureARB, ActiveTextureARB@4) + GL_STUB_ALIAS(ClientActiveTexture, 375, ClientActiveTexture@4, ClientActiveTextureARB, ClientActiveTextureARB@4) + GL_STUB_ALIAS(MultiTexCoord1d, 376, MultiTexCoord1d@12, MultiTexCoord1dARB, MultiTexCoord1dARB@12) + GL_STUB_ALIAS(MultiTexCoord1dv, 377, MultiTexCoord1dv@8, MultiTexCoord1dvARB, MultiTexCoord1dvARB@8) + GL_STUB_ALIAS(MultiTexCoord1f, 378, MultiTexCoord1f@8, MultiTexCoord1fARB, MultiTexCoord1fARB@8) + GL_STUB_ALIAS(MultiTexCoord1fv, 379, MultiTexCoord1fv@8, MultiTexCoord1fvARB, MultiTexCoord1fvARB@8) + GL_STUB_ALIAS(MultiTexCoord1i, 380, MultiTexCoord1i@8, MultiTexCoord1iARB, MultiTexCoord1iARB@8) + GL_STUB_ALIAS(MultiTexCoord1iv, 381, MultiTexCoord1iv@8, MultiTexCoord1ivARB, MultiTexCoord1ivARB@8) + GL_STUB_ALIAS(MultiTexCoord1s, 382, MultiTexCoord1s@8, MultiTexCoord1sARB, MultiTexCoord1sARB@8) + GL_STUB_ALIAS(MultiTexCoord1sv, 383, MultiTexCoord1sv@8, MultiTexCoord1svARB, MultiTexCoord1svARB@8) + GL_STUB_ALIAS(MultiTexCoord2d, 384, MultiTexCoord2d@20, MultiTexCoord2dARB, MultiTexCoord2dARB@20) + GL_STUB_ALIAS(MultiTexCoord2dv, 385, MultiTexCoord2dv@8, MultiTexCoord2dvARB, MultiTexCoord2dvARB@8) + GL_STUB_ALIAS(MultiTexCoord2f, 386, MultiTexCoord2f@12, MultiTexCoord2fARB, MultiTexCoord2fARB@12) + GL_STUB_ALIAS(MultiTexCoord2fv, 387, MultiTexCoord2fv@8, MultiTexCoord2fvARB, MultiTexCoord2fvARB@8) + GL_STUB_ALIAS(MultiTexCoord2i, 388, MultiTexCoord2i@12, MultiTexCoord2iARB, MultiTexCoord2iARB@12) + GL_STUB_ALIAS(MultiTexCoord2iv, 389, MultiTexCoord2iv@8, MultiTexCoord2ivARB, MultiTexCoord2ivARB@8) + GL_STUB_ALIAS(MultiTexCoord2s, 390, MultiTexCoord2s@12, MultiTexCoord2sARB, MultiTexCoord2sARB@12) + GL_STUB_ALIAS(MultiTexCoord2sv, 391, MultiTexCoord2sv@8, MultiTexCoord2svARB, MultiTexCoord2svARB@8) + GL_STUB_ALIAS(MultiTexCoord3d, 392, MultiTexCoord3d@28, MultiTexCoord3dARB, MultiTexCoord3dARB@28) + GL_STUB_ALIAS(MultiTexCoord3dv, 393, MultiTexCoord3dv@8, MultiTexCoord3dvARB, MultiTexCoord3dvARB@8) + GL_STUB_ALIAS(MultiTexCoord3f, 394, MultiTexCoord3f@16, MultiTexCoord3fARB, MultiTexCoord3fARB@16) + GL_STUB_ALIAS(MultiTexCoord3fv, 395, MultiTexCoord3fv@8, MultiTexCoord3fvARB, MultiTexCoord3fvARB@8) + GL_STUB_ALIAS(MultiTexCoord3i, 396, MultiTexCoord3i@16, MultiTexCoord3iARB, MultiTexCoord3iARB@16) + GL_STUB_ALIAS(MultiTexCoord3iv, 397, MultiTexCoord3iv@8, MultiTexCoord3ivARB, MultiTexCoord3ivARB@8) + GL_STUB_ALIAS(MultiTexCoord3s, 398, MultiTexCoord3s@16, MultiTexCoord3sARB, MultiTexCoord3sARB@16) + GL_STUB_ALIAS(MultiTexCoord3sv, 399, MultiTexCoord3sv@8, MultiTexCoord3svARB, MultiTexCoord3svARB@8) + GL_STUB_ALIAS(MultiTexCoord4d, 400, MultiTexCoord4d@36, MultiTexCoord4dARB, MultiTexCoord4dARB@36) + GL_STUB_ALIAS(MultiTexCoord4dv, 401, MultiTexCoord4dv@8, MultiTexCoord4dvARB, MultiTexCoord4dvARB@8) + GL_STUB_ALIAS(MultiTexCoord4f, 402, MultiTexCoord4f@20, MultiTexCoord4fARB, MultiTexCoord4fARB@20) + GL_STUB_ALIAS(MultiTexCoord4fv, 403, MultiTexCoord4fv@8, MultiTexCoord4fvARB, MultiTexCoord4fvARB@8) + GL_STUB_ALIAS(MultiTexCoord4i, 404, MultiTexCoord4i@20, MultiTexCoord4iARB, MultiTexCoord4iARB@20) + GL_STUB_ALIAS(MultiTexCoord4iv, 405, MultiTexCoord4iv@8, MultiTexCoord4ivARB, MultiTexCoord4ivARB@8) + GL_STUB_ALIAS(MultiTexCoord4s, 406, MultiTexCoord4s@20, MultiTexCoord4sARB, MultiTexCoord4sARB@20) + GL_STUB_ALIAS(MultiTexCoord4sv, 407, MultiTexCoord4sv@8, MultiTexCoord4svARB, MultiTexCoord4svARB@8) + GL_STUB_ALIAS(LoadTransposeMatrixd, 441, LoadTransposeMatrixd@4, LoadTransposeMatrixdARB, LoadTransposeMatrixdARB@4) + GL_STUB_ALIAS(LoadTransposeMatrixf, 442, LoadTransposeMatrixf@4, LoadTransposeMatrixfARB, LoadTransposeMatrixfARB@4) + GL_STUB_ALIAS(MultTransposeMatrixd, 443, MultTransposeMatrixd@4, MultTransposeMatrixdARB, MultTransposeMatrixdARB@4) + GL_STUB_ALIAS(MultTransposeMatrixf, 444, MultTransposeMatrixf@4, MultTransposeMatrixfARB, MultTransposeMatrixfARB@4) + GL_STUB_ALIAS(SampleCoverage, 445, SampleCoverage@8, SampleCoverageARB, SampleCoverageARB@8) + GL_STUB_ALIAS(CompressedTexImage1D, 446, CompressedTexImage1D@28, CompressedTexImage1DARB, CompressedTexImage1DARB@28) + GL_STUB_ALIAS(CompressedTexImage2D, 447, CompressedTexImage2D@32, CompressedTexImage2DARB, CompressedTexImage2DARB@32) + GL_STUB_ALIAS(CompressedTexImage3D, 448, CompressedTexImage3D@36, CompressedTexImage3DARB, CompressedTexImage3DARB@36) + GL_STUB_ALIAS(CompressedTexSubImage1D, 449, CompressedTexSubImage1D@28, CompressedTexSubImage1DARB, CompressedTexSubImage1DARB@28) + GL_STUB_ALIAS(CompressedTexSubImage2D, 450, CompressedTexSubImage2D@36, CompressedTexSubImage2DARB, CompressedTexSubImage2DARB@36) + GL_STUB_ALIAS(CompressedTexSubImage3D, 451, CompressedTexSubImage3D@44, CompressedTexSubImage3DARB, CompressedTexSubImage3DARB@44) + GL_STUB_ALIAS(GetCompressedTexImage, 452, GetCompressedTexImage@12, GetCompressedTexImageARB, GetCompressedTexImageARB@12) + GL_STUB_ALIAS(DisableVertexAttribArray, 453, DisableVertexAttribArray@4, DisableVertexAttribArrayARB, DisableVertexAttribArrayARB@4) + GL_STUB_ALIAS(EnableVertexAttribArray, 454, EnableVertexAttribArray@4, EnableVertexAttribArrayARB, EnableVertexAttribArrayARB@4) + GL_STUB_ALIAS(GetVertexAttribdv, 461, GetVertexAttribdv@12, GetVertexAttribdvARB, GetVertexAttribdvARB@12) + GL_STUB_ALIAS(GetVertexAttribfv, 462, GetVertexAttribfv@12, GetVertexAttribfvARB, GetVertexAttribfvARB@12) + GL_STUB_ALIAS(GetVertexAttribiv, 463, GetVertexAttribiv@12, GetVertexAttribivARB, GetVertexAttribivARB@12) + GL_STUB_ALIAS(ProgramParameter4dNV, 464, ProgramParameter4dNV@40, ProgramEnvParameter4dARB, ProgramEnvParameter4dARB@40) + GL_STUB_ALIAS(ProgramParameter4dvNV, 465, ProgramParameter4dvNV@12, ProgramEnvParameter4dvARB, ProgramEnvParameter4dvARB@12) + GL_STUB_ALIAS(ProgramParameter4fNV, 466, ProgramParameter4fNV@24, ProgramEnvParameter4fARB, ProgramEnvParameter4fARB@24) + GL_STUB_ALIAS(ProgramParameter4fvNV, 467, ProgramParameter4fvNV@12, ProgramEnvParameter4fvARB, ProgramEnvParameter4fvARB@12) + GL_STUB_ALIAS(VertexAttrib1d, 473, VertexAttrib1d@12, VertexAttrib1dARB, VertexAttrib1dARB@12) + GL_STUB_ALIAS(VertexAttrib1dv, 474, VertexAttrib1dv@8, VertexAttrib1dvARB, VertexAttrib1dvARB@8) + GL_STUB_ALIAS(VertexAttrib1f, 475, VertexAttrib1f@8, VertexAttrib1fARB, VertexAttrib1fARB@8) + GL_STUB_ALIAS(VertexAttrib1fv, 476, VertexAttrib1fv@8, VertexAttrib1fvARB, VertexAttrib1fvARB@8) + GL_STUB_ALIAS(VertexAttrib1s, 477, VertexAttrib1s@8, VertexAttrib1sARB, VertexAttrib1sARB@8) + GL_STUB_ALIAS(VertexAttrib1sv, 478, VertexAttrib1sv@8, VertexAttrib1svARB, VertexAttrib1svARB@8) + GL_STUB_ALIAS(VertexAttrib2d, 479, VertexAttrib2d@20, VertexAttrib2dARB, VertexAttrib2dARB@20) + GL_STUB_ALIAS(VertexAttrib2dv, 480, VertexAttrib2dv@8, VertexAttrib2dvARB, VertexAttrib2dvARB@8) + GL_STUB_ALIAS(VertexAttrib2f, 481, VertexAttrib2f@12, VertexAttrib2fARB, VertexAttrib2fARB@12) + GL_STUB_ALIAS(VertexAttrib2fv, 482, VertexAttrib2fv@8, VertexAttrib2fvARB, VertexAttrib2fvARB@8) + GL_STUB_ALIAS(VertexAttrib2s, 483, VertexAttrib2s@12, VertexAttrib2sARB, VertexAttrib2sARB@12) + GL_STUB_ALIAS(VertexAttrib2sv, 484, VertexAttrib2sv@8, VertexAttrib2svARB, VertexAttrib2svARB@8) + GL_STUB_ALIAS(VertexAttrib3d, 485, VertexAttrib3d@28, VertexAttrib3dARB, VertexAttrib3dARB@28) + GL_STUB_ALIAS(VertexAttrib3dv, 486, VertexAttrib3dv@8, VertexAttrib3dvARB, VertexAttrib3dvARB@8) + GL_STUB_ALIAS(VertexAttrib3f, 487, VertexAttrib3f@16, VertexAttrib3fARB, VertexAttrib3fARB@16) + GL_STUB_ALIAS(VertexAttrib3fv, 488, VertexAttrib3fv@8, VertexAttrib3fvARB, VertexAttrib3fvARB@8) + GL_STUB_ALIAS(VertexAttrib3s, 489, VertexAttrib3s@16, VertexAttrib3sARB, VertexAttrib3sARB@16) + GL_STUB_ALIAS(VertexAttrib3sv, 490, VertexAttrib3sv@8, VertexAttrib3svARB, VertexAttrib3svARB@8) + GL_STUB_ALIAS(VertexAttrib4Nbv, 491, VertexAttrib4Nbv@8, VertexAttrib4NbvARB, VertexAttrib4NbvARB@8) + GL_STUB_ALIAS(VertexAttrib4Niv, 492, VertexAttrib4Niv@8, VertexAttrib4NivARB, VertexAttrib4NivARB@8) + GL_STUB_ALIAS(VertexAttrib4Nsv, 493, VertexAttrib4Nsv@8, VertexAttrib4NsvARB, VertexAttrib4NsvARB@8) + GL_STUB_ALIAS(VertexAttrib4Nub, 494, VertexAttrib4Nub@20, VertexAttrib4NubARB, VertexAttrib4NubARB@20) + GL_STUB_ALIAS(VertexAttrib4Nubv, 495, VertexAttrib4Nubv@8, VertexAttrib4NubvARB, VertexAttrib4NubvARB@8) + GL_STUB_ALIAS(VertexAttrib4Nuiv, 496, VertexAttrib4Nuiv@8, VertexAttrib4NuivARB, VertexAttrib4NuivARB@8) + GL_STUB_ALIAS(VertexAttrib4Nusv, 497, VertexAttrib4Nusv@8, VertexAttrib4NusvARB, VertexAttrib4NusvARB@8) + GL_STUB_ALIAS(VertexAttrib4bv, 498, VertexAttrib4bv@8, VertexAttrib4bvARB, VertexAttrib4bvARB@8) + GL_STUB_ALIAS(VertexAttrib4d, 499, VertexAttrib4d@36, VertexAttrib4dARB, VertexAttrib4dARB@36) + GL_STUB_ALIAS(VertexAttrib4dv, 500, VertexAttrib4dv@8, VertexAttrib4dvARB, VertexAttrib4dvARB@8) + GL_STUB_ALIAS(VertexAttrib4f, 501, VertexAttrib4f@20, VertexAttrib4fARB, VertexAttrib4fARB@20) + GL_STUB_ALIAS(VertexAttrib4fv, 502, VertexAttrib4fv@8, VertexAttrib4fvARB, VertexAttrib4fvARB@8) + GL_STUB_ALIAS(VertexAttrib4iv, 503, VertexAttrib4iv@8, VertexAttrib4ivARB, VertexAttrib4ivARB@8) + GL_STUB_ALIAS(VertexAttrib4s, 504, VertexAttrib4s@20, VertexAttrib4sARB, VertexAttrib4sARB@20) + GL_STUB_ALIAS(VertexAttrib4sv, 505, VertexAttrib4sv@8, VertexAttrib4svARB, VertexAttrib4svARB@8) + GL_STUB_ALIAS(VertexAttrib4ubv, 506, VertexAttrib4ubv@8, VertexAttrib4ubvARB, VertexAttrib4ubvARB@8) + GL_STUB_ALIAS(VertexAttrib4uiv, 507, VertexAttrib4uiv@8, VertexAttrib4uivARB, VertexAttrib4uivARB@8) + GL_STUB_ALIAS(VertexAttrib4usv, 508, VertexAttrib4usv@8, VertexAttrib4usvARB, VertexAttrib4usvARB@8) + GL_STUB_ALIAS(VertexAttribPointer, 509, VertexAttribPointer@24, VertexAttribPointerARB, VertexAttribPointerARB@24) + GL_STUB_ALIAS(BindBuffer, 510, BindBuffer@8, BindBufferARB, BindBufferARB@8) + GL_STUB_ALIAS(BufferData, 511, BufferData@16, BufferDataARB, BufferDataARB@16) + GL_STUB_ALIAS(BufferSubData, 512, BufferSubData@16, BufferSubDataARB, BufferSubDataARB@16) + GL_STUB_ALIAS(DeleteBuffers, 513, DeleteBuffers@8, DeleteBuffersARB, DeleteBuffersARB@8) + GL_STUB_ALIAS(GenBuffers, 514, GenBuffers@8, GenBuffersARB, GenBuffersARB@8) + GL_STUB_ALIAS(GetBufferParameteriv, 515, GetBufferParameteriv@12, GetBufferParameterivARB, GetBufferParameterivARB@12) + GL_STUB_ALIAS(GetBufferPointerv, 516, GetBufferPointerv@12, GetBufferPointervARB, GetBufferPointervARB@12) + GL_STUB_ALIAS(GetBufferSubData, 517, GetBufferSubData@16, GetBufferSubDataARB, GetBufferSubDataARB@16) + GL_STUB_ALIAS(IsBuffer, 518, IsBuffer@4, IsBufferARB, IsBufferARB@4) + GL_STUB_ALIAS(MapBuffer, 519, MapBuffer@8, MapBufferARB, MapBufferARB@8) + GL_STUB_ALIAS(UnmapBuffer, 520, UnmapBuffer@4, UnmapBufferARB, UnmapBufferARB@4) + GL_STUB_ALIAS(BeginQuery, 521, BeginQuery@8, BeginQueryARB, BeginQueryARB@8) + GL_STUB_ALIAS(DeleteQueries, 522, DeleteQueries@8, DeleteQueriesARB, DeleteQueriesARB@8) + GL_STUB_ALIAS(EndQuery, 523, EndQuery@4, EndQueryARB, EndQueryARB@4) + GL_STUB_ALIAS(GenQueries, 524, GenQueries@8, GenQueriesARB, GenQueriesARB@8) + GL_STUB_ALIAS(GetQueryObjectiv, 525, GetQueryObjectiv@12, GetQueryObjectivARB, GetQueryObjectivARB@12) + GL_STUB_ALIAS(GetQueryObjectuiv, 526, GetQueryObjectuiv@12, GetQueryObjectuivARB, GetQueryObjectuivARB@12) + GL_STUB_ALIAS(GetQueryiv, 527, GetQueryiv@12, GetQueryivARB, GetQueryivARB@12) + GL_STUB_ALIAS(IsQuery, 528, IsQuery@4, IsQueryARB, IsQueryARB@4) + GL_STUB_ALIAS(CompileShader, 530, CompileShader@4, CompileShaderARB, CompileShaderARB@4) + GL_STUB_ALIAS(GetActiveUniform, 535, GetActiveUniform@28, GetActiveUniformARB, GetActiveUniformARB@28) + GL_STUB_ALIAS(GetShaderSource, 541, GetShaderSource@16, GetShaderSourceARB, GetShaderSourceARB@16) + GL_STUB_ALIAS(GetUniformLocation, 542, GetUniformLocation@8, GetUniformLocationARB, GetUniformLocationARB@8) + GL_STUB_ALIAS(GetUniformfv, 543, GetUniformfv@12, GetUniformfvARB, GetUniformfvARB@12) + GL_STUB_ALIAS(GetUniformiv, 544, GetUniformiv@12, GetUniformivARB, GetUniformivARB@12) + GL_STUB_ALIAS(LinkProgram, 545, LinkProgram@4, LinkProgramARB, LinkProgramARB@4) + GL_STUB_ALIAS(ShaderSource, 546, ShaderSource@16, ShaderSourceARB, ShaderSourceARB@16) + GL_STUB_ALIAS(Uniform1f, 547, Uniform1f@8, Uniform1fARB, Uniform1fARB@8) + GL_STUB_ALIAS(Uniform1fv, 548, Uniform1fv@12, Uniform1fvARB, Uniform1fvARB@12) + GL_STUB_ALIAS(Uniform1i, 549, Uniform1i@8, Uniform1iARB, Uniform1iARB@8) + GL_STUB_ALIAS(Uniform1iv, 550, Uniform1iv@12, Uniform1ivARB, Uniform1ivARB@12) + GL_STUB_ALIAS(Uniform2f, 551, Uniform2f@12, Uniform2fARB, Uniform2fARB@12) + GL_STUB_ALIAS(Uniform2fv, 552, Uniform2fv@12, Uniform2fvARB, Uniform2fvARB@12) + GL_STUB_ALIAS(Uniform2i, 553, Uniform2i@12, Uniform2iARB, Uniform2iARB@12) + GL_STUB_ALIAS(Uniform2iv, 554, Uniform2iv@12, Uniform2ivARB, Uniform2ivARB@12) + GL_STUB_ALIAS(Uniform3f, 555, Uniform3f@16, Uniform3fARB, Uniform3fARB@16) + GL_STUB_ALIAS(Uniform3fv, 556, Uniform3fv@12, Uniform3fvARB, Uniform3fvARB@12) + GL_STUB_ALIAS(Uniform3i, 557, Uniform3i@16, Uniform3iARB, Uniform3iARB@16) + GL_STUB_ALIAS(Uniform3iv, 558, Uniform3iv@12, Uniform3ivARB, Uniform3ivARB@12) + GL_STUB_ALIAS(Uniform4f, 559, Uniform4f@20, Uniform4fARB, Uniform4fARB@20) + GL_STUB_ALIAS(Uniform4fv, 560, Uniform4fv@12, Uniform4fvARB, Uniform4fvARB@12) + GL_STUB_ALIAS(Uniform4i, 561, Uniform4i@20, Uniform4iARB, Uniform4iARB@20) + GL_STUB_ALIAS(Uniform4iv, 562, Uniform4iv@12, Uniform4ivARB, Uniform4ivARB@12) + GL_STUB_ALIAS(UniformMatrix2fv, 563, UniformMatrix2fv@16, UniformMatrix2fvARB, UniformMatrix2fvARB@16) + GL_STUB_ALIAS(UniformMatrix3fv, 564, UniformMatrix3fv@16, UniformMatrix3fvARB, UniformMatrix3fvARB@16) + GL_STUB_ALIAS(UniformMatrix4fv, 565, UniformMatrix4fv@16, UniformMatrix4fvARB, UniformMatrix4fvARB@16) + GL_STUB_ALIAS(UseProgram, 566, UseProgram@4, UseProgramObjectARB, UseProgramObjectARB@4) + GL_STUB_ALIAS(ValidateProgram, 567, ValidateProgram@4, ValidateProgramARB, ValidateProgramARB@4) + GL_STUB_ALIAS(BindAttribLocation, 568, BindAttribLocation@12, BindAttribLocationARB, BindAttribLocationARB@12) + GL_STUB_ALIAS(GetActiveAttrib, 569, GetActiveAttrib@28, GetActiveAttribARB, GetActiveAttribARB@28) + GL_STUB_ALIAS(GetAttribLocation, 570, GetAttribLocation@8, GetAttribLocationARB, GetAttribLocationARB@8) + GL_STUB_ALIAS(DrawBuffers, 571, DrawBuffers@8, DrawBuffersARB, DrawBuffersARB@8) + GL_STUB_ALIAS(DrawBuffersATI, 571, DrawBuffersATI@8, DrawBuffersARB, DrawBuffersARB@8) + GL_STUB_ALIAS(DrawArraysInstancedEXT, 572, DrawArraysInstancedEXT@16, DrawArraysInstancedARB, DrawArraysInstancedARB@16) + GL_STUB_ALIAS(DrawArraysInstanced, 572, DrawArraysInstanced@16, DrawArraysInstancedARB, DrawArraysInstancedARB@16) + GL_STUB_ALIAS(DrawElementsInstancedEXT, 573, DrawElementsInstancedEXT@20, DrawElementsInstancedARB, DrawElementsInstancedARB@20) + GL_STUB_ALIAS(DrawElementsInstanced, 573, DrawElementsInstanced@20, DrawElementsInstancedARB, DrawElementsInstancedARB@20) + GL_STUB_ALIAS(RenderbufferStorageMultisampleEXT, 574, RenderbufferStorageMultisampleEXT@20, RenderbufferStorageMultisample, RenderbufferStorageMultisample@20) + GL_STUB_ALIAS(PointParameterf, 620, PointParameterf@8, PointParameterfEXT, PointParameterfEXT@8) + GL_STUB_ALIAS(PointParameterfARB, 620, PointParameterfARB@8, PointParameterfEXT, PointParameterfEXT@8) + GL_STUB_ALIAS(PointParameterfv, 621, PointParameterfv@8, PointParameterfvEXT, PointParameterfvEXT@8) + GL_STUB_ALIAS(PointParameterfvARB, 621, PointParameterfvARB@8, PointParameterfvEXT, PointParameterfvEXT@8) + GL_STUB_ALIAS(SecondaryColor3b, 624, SecondaryColor3b@12, SecondaryColor3bEXT, SecondaryColor3bEXT@12) + GL_STUB_ALIAS(SecondaryColor3bv, 625, SecondaryColor3bv@4, SecondaryColor3bvEXT, SecondaryColor3bvEXT@4) + GL_STUB_ALIAS(SecondaryColor3d, 626, SecondaryColor3d@24, SecondaryColor3dEXT, SecondaryColor3dEXT@24) + GL_STUB_ALIAS(SecondaryColor3dv, 627, SecondaryColor3dv@4, SecondaryColor3dvEXT, SecondaryColor3dvEXT@4) + GL_STUB_ALIAS(SecondaryColor3f, 628, SecondaryColor3f@12, SecondaryColor3fEXT, SecondaryColor3fEXT@12) + GL_STUB_ALIAS(SecondaryColor3fv, 629, SecondaryColor3fv@4, SecondaryColor3fvEXT, SecondaryColor3fvEXT@4) + GL_STUB_ALIAS(SecondaryColor3i, 630, SecondaryColor3i@12, SecondaryColor3iEXT, SecondaryColor3iEXT@12) + GL_STUB_ALIAS(SecondaryColor3iv, 631, SecondaryColor3iv@4, SecondaryColor3ivEXT, SecondaryColor3ivEXT@4) + GL_STUB_ALIAS(SecondaryColor3s, 632, SecondaryColor3s@12, SecondaryColor3sEXT, SecondaryColor3sEXT@12) + GL_STUB_ALIAS(SecondaryColor3sv, 633, SecondaryColor3sv@4, SecondaryColor3svEXT, SecondaryColor3svEXT@4) + GL_STUB_ALIAS(SecondaryColor3ub, 634, SecondaryColor3ub@12, SecondaryColor3ubEXT, SecondaryColor3ubEXT@12) + GL_STUB_ALIAS(SecondaryColor3ubv, 635, SecondaryColor3ubv@4, SecondaryColor3ubvEXT, SecondaryColor3ubvEXT@4) + GL_STUB_ALIAS(SecondaryColor3ui, 636, SecondaryColor3ui@12, SecondaryColor3uiEXT, SecondaryColor3uiEXT@12) + GL_STUB_ALIAS(SecondaryColor3uiv, 637, SecondaryColor3uiv@4, SecondaryColor3uivEXT, SecondaryColor3uivEXT@4) + GL_STUB_ALIAS(SecondaryColor3us, 638, SecondaryColor3us@12, SecondaryColor3usEXT, SecondaryColor3usEXT@12) + GL_STUB_ALIAS(SecondaryColor3usv, 639, SecondaryColor3usv@4, SecondaryColor3usvEXT, SecondaryColor3usvEXT@4) + GL_STUB_ALIAS(SecondaryColorPointer, 640, SecondaryColorPointer@16, SecondaryColorPointerEXT, SecondaryColorPointerEXT@16) + GL_STUB_ALIAS(MultiDrawArrays, 641, MultiDrawArrays@16, MultiDrawArraysEXT, MultiDrawArraysEXT@16) + GL_STUB_ALIAS(MultiDrawElements, 642, MultiDrawElements@20, MultiDrawElementsEXT, MultiDrawElementsEXT@20) + GL_STUB_ALIAS(FogCoordPointer, 643, FogCoordPointer@12, FogCoordPointerEXT, FogCoordPointerEXT@12) + GL_STUB_ALIAS(FogCoordd, 644, FogCoordd@8, FogCoorddEXT, FogCoorddEXT@8) + GL_STUB_ALIAS(FogCoorddv, 645, FogCoorddv@4, FogCoorddvEXT, FogCoorddvEXT@4) + GL_STUB_ALIAS(FogCoordf, 646, FogCoordf@4, FogCoordfEXT, FogCoordfEXT@4) + GL_STUB_ALIAS(FogCoordfv, 647, FogCoordfv@4, FogCoordfvEXT, FogCoordfvEXT@4) + GL_STUB_ALIAS(BlendFuncSeparate, 649, BlendFuncSeparate@16, BlendFuncSeparateEXT, BlendFuncSeparateEXT@16) + GL_STUB_ALIAS(WindowPos2d, 666, WindowPos2d@16, WindowPos2dMESA, WindowPos2dMESA@16) + GL_STUB_ALIAS(WindowPos2dARB, 666, WindowPos2dARB@16, WindowPos2dMESA, WindowPos2dMESA@16) + GL_STUB_ALIAS(WindowPos2dv, 667, WindowPos2dv@4, WindowPos2dvMESA, WindowPos2dvMESA@4) + GL_STUB_ALIAS(WindowPos2dvARB, 667, WindowPos2dvARB@4, WindowPos2dvMESA, WindowPos2dvMESA@4) + GL_STUB_ALIAS(WindowPos2f, 668, WindowPos2f@8, WindowPos2fMESA, WindowPos2fMESA@8) + GL_STUB_ALIAS(WindowPos2fARB, 668, WindowPos2fARB@8, WindowPos2fMESA, WindowPos2fMESA@8) + GL_STUB_ALIAS(WindowPos2fv, 669, WindowPos2fv@4, WindowPos2fvMESA, WindowPos2fvMESA@4) + GL_STUB_ALIAS(WindowPos2fvARB, 669, WindowPos2fvARB@4, WindowPos2fvMESA, WindowPos2fvMESA@4) + GL_STUB_ALIAS(WindowPos2i, 670, WindowPos2i@8, WindowPos2iMESA, WindowPos2iMESA@8) + GL_STUB_ALIAS(WindowPos2iARB, 670, WindowPos2iARB@8, WindowPos2iMESA, WindowPos2iMESA@8) + GL_STUB_ALIAS(WindowPos2iv, 671, WindowPos2iv@4, WindowPos2ivMESA, WindowPos2ivMESA@4) + GL_STUB_ALIAS(WindowPos2ivARB, 671, WindowPos2ivARB@4, WindowPos2ivMESA, WindowPos2ivMESA@4) + GL_STUB_ALIAS(WindowPos2s, 672, WindowPos2s@8, WindowPos2sMESA, WindowPos2sMESA@8) + GL_STUB_ALIAS(WindowPos2sARB, 672, WindowPos2sARB@8, WindowPos2sMESA, WindowPos2sMESA@8) + GL_STUB_ALIAS(WindowPos2sv, 673, WindowPos2sv@4, WindowPos2svMESA, WindowPos2svMESA@4) + GL_STUB_ALIAS(WindowPos2svARB, 673, WindowPos2svARB@4, WindowPos2svMESA, WindowPos2svMESA@4) + GL_STUB_ALIAS(WindowPos3d, 674, WindowPos3d@24, WindowPos3dMESA, WindowPos3dMESA@24) + GL_STUB_ALIAS(WindowPos3dARB, 674, WindowPos3dARB@24, WindowPos3dMESA, WindowPos3dMESA@24) + GL_STUB_ALIAS(WindowPos3dv, 675, WindowPos3dv@4, WindowPos3dvMESA, WindowPos3dvMESA@4) + GL_STUB_ALIAS(WindowPos3dvARB, 675, WindowPos3dvARB@4, WindowPos3dvMESA, WindowPos3dvMESA@4) + GL_STUB_ALIAS(WindowPos3f, 676, WindowPos3f@12, WindowPos3fMESA, WindowPos3fMESA@12) + GL_STUB_ALIAS(WindowPos3fARB, 676, WindowPos3fARB@12, WindowPos3fMESA, WindowPos3fMESA@12) + GL_STUB_ALIAS(WindowPos3fv, 677, WindowPos3fv@4, WindowPos3fvMESA, WindowPos3fvMESA@4) + GL_STUB_ALIAS(WindowPos3fvARB, 677, WindowPos3fvARB@4, WindowPos3fvMESA, WindowPos3fvMESA@4) + GL_STUB_ALIAS(WindowPos3i, 678, WindowPos3i@12, WindowPos3iMESA, WindowPos3iMESA@12) + GL_STUB_ALIAS(WindowPos3iARB, 678, WindowPos3iARB@12, WindowPos3iMESA, WindowPos3iMESA@12) + GL_STUB_ALIAS(WindowPos3iv, 679, WindowPos3iv@4, WindowPos3ivMESA, WindowPos3ivMESA@4) + GL_STUB_ALIAS(WindowPos3ivARB, 679, WindowPos3ivARB@4, WindowPos3ivMESA, WindowPos3ivMESA@4) + GL_STUB_ALIAS(WindowPos3s, 680, WindowPos3s@12, WindowPos3sMESA, WindowPos3sMESA@12) + GL_STUB_ALIAS(WindowPos3sARB, 680, WindowPos3sARB@12, WindowPos3sMESA, WindowPos3sMESA@12) + GL_STUB_ALIAS(WindowPos3sv, 681, WindowPos3sv@4, WindowPos3svMESA, WindowPos3svMESA@4) + GL_STUB_ALIAS(WindowPos3svARB, 681, WindowPos3svARB@4, WindowPos3svMESA, WindowPos3svMESA@4) + GL_STUB_ALIAS(BindProgramARB, 700, BindProgramARB@8, BindProgramNV, BindProgramNV@8) + GL_STUB_ALIAS(DeleteProgramsARB, 701, DeleteProgramsARB@8, DeleteProgramsNV, DeleteProgramsNV@8) + GL_STUB_ALIAS(GenProgramsARB, 703, GenProgramsARB@8, GenProgramsNV, GenProgramsNV@8) + GL_STUB_ALIAS(GetVertexAttribPointerv, 709, GetVertexAttribPointerv@12, GetVertexAttribPointervNV, GetVertexAttribPointervNV@12) + GL_STUB_ALIAS(GetVertexAttribPointervARB, 709, GetVertexAttribPointervARB@12, GetVertexAttribPointervNV, GetVertexAttribPointervNV@12) + GL_STUB_ALIAS(IsProgramARB, 713, IsProgramARB@4, IsProgramNV, IsProgramNV@4) + GL_STUB_ALIAS(PointParameteri, 777, PointParameteri@8, PointParameteriNV, PointParameteriNV@8) + GL_STUB_ALIAS(PointParameteriv, 778, PointParameteriv@8, PointParameterivNV, PointParameterivNV@8) + GL_STUB_ALIAS(DeleteVertexArrays, 781, DeleteVertexArrays@8, _dispatch_stub_781, _dispatch_stub_781@8) + GL_STUB_ALIAS(IsVertexArray, 783, IsVertexArray@4, _dispatch_stub_783, _dispatch_stub_783@4) + GL_STUB_ALIAS(PrimitiveRestartIndex, 790, PrimitiveRestartIndex@4, PrimitiveRestartIndexNV, PrimitiveRestartIndexNV@4) + GL_STUB_ALIAS(BlendEquationSeparate, 793, BlendEquationSeparate@8, _dispatch_stub_793, _dispatch_stub_793@8) + GL_STUB_ALIAS(BindFramebuffer, 794, BindFramebuffer@8, BindFramebufferEXT, BindFramebufferEXT@8) + GL_STUB_ALIAS(BindRenderbuffer, 795, BindRenderbuffer@8, BindRenderbufferEXT, BindRenderbufferEXT@8) + GL_STUB_ALIAS(CheckFramebufferStatus, 796, CheckFramebufferStatus@4, CheckFramebufferStatusEXT, CheckFramebufferStatusEXT@4) + GL_STUB_ALIAS(DeleteFramebuffers, 797, DeleteFramebuffers@8, DeleteFramebuffersEXT, DeleteFramebuffersEXT@8) + GL_STUB_ALIAS(DeleteRenderbuffers, 798, DeleteRenderbuffers@8, DeleteRenderbuffersEXT, DeleteRenderbuffersEXT@8) + GL_STUB_ALIAS(FramebufferRenderbuffer, 799, FramebufferRenderbuffer@16, FramebufferRenderbufferEXT, FramebufferRenderbufferEXT@16) + GL_STUB_ALIAS(FramebufferTexture1D, 800, FramebufferTexture1D@20, FramebufferTexture1DEXT, FramebufferTexture1DEXT@20) + GL_STUB_ALIAS(FramebufferTexture2D, 801, FramebufferTexture2D@20, FramebufferTexture2DEXT, FramebufferTexture2DEXT@20) + GL_STUB_ALIAS(FramebufferTexture3D, 802, FramebufferTexture3D@24, FramebufferTexture3DEXT, FramebufferTexture3DEXT@24) + GL_STUB_ALIAS(GenFramebuffers, 803, GenFramebuffers@8, GenFramebuffersEXT, GenFramebuffersEXT@8) + GL_STUB_ALIAS(GenRenderbuffers, 804, GenRenderbuffers@8, GenRenderbuffersEXT, GenRenderbuffersEXT@8) + GL_STUB_ALIAS(GenerateMipmap, 805, GenerateMipmap@4, GenerateMipmapEXT, GenerateMipmapEXT@4) + GL_STUB_ALIAS(GetFramebufferAttachmentParameteriv, 806, GetFramebufferAttachmentParameteriv@16, GetFramebufferAttachmentParameterivEXT, GetFramebufferAttachmentParameterivEXT@16) + GL_STUB_ALIAS(GetRenderbufferParameteriv, 807, GetRenderbufferParameteriv@12, GetRenderbufferParameterivEXT, GetRenderbufferParameterivEXT@12) + GL_STUB_ALIAS(IsFramebuffer, 808, IsFramebuffer@4, IsFramebufferEXT, IsFramebufferEXT@4) + GL_STUB_ALIAS(IsRenderbuffer, 809, IsRenderbuffer@4, IsRenderbufferEXT, IsRenderbufferEXT@4) + GL_STUB_ALIAS(RenderbufferStorage, 810, RenderbufferStorage@16, RenderbufferStorageEXT, RenderbufferStorageEXT@16) + GL_STUB_ALIAS(BlitFramebuffer, 811, BlitFramebuffer@40, _dispatch_stub_811, _dispatch_stub_811@40) + GL_STUB_ALIAS(BindFragDataLocation, 814, BindFragDataLocation@12, BindFragDataLocationEXT, BindFragDataLocationEXT@12) + GL_STUB_ALIAS(GetFragDataLocation, 815, GetFragDataLocation@8, GetFragDataLocationEXT, GetFragDataLocationEXT@8) + GL_STUB_ALIAS(GetUniformuiv, 816, GetUniformuiv@12, GetUniformuivEXT, GetUniformuivEXT@12) + GL_STUB_ALIAS(GetVertexAttribIiv, 817, GetVertexAttribIiv@12, GetVertexAttribIivEXT, GetVertexAttribIivEXT@12) + GL_STUB_ALIAS(GetVertexAttribIuiv, 818, GetVertexAttribIuiv@12, GetVertexAttribIuivEXT, GetVertexAttribIuivEXT@12) + GL_STUB_ALIAS(Uniform1ui, 819, Uniform1ui@8, Uniform1uiEXT, Uniform1uiEXT@8) + GL_STUB_ALIAS(Uniform1uiv, 820, Uniform1uiv@12, Uniform1uivEXT, Uniform1uivEXT@12) + GL_STUB_ALIAS(Uniform2ui, 821, Uniform2ui@12, Uniform2uiEXT, Uniform2uiEXT@12) + GL_STUB_ALIAS(Uniform2uiv, 822, Uniform2uiv@12, Uniform2uivEXT, Uniform2uivEXT@12) + GL_STUB_ALIAS(Uniform3ui, 823, Uniform3ui@16, Uniform3uiEXT, Uniform3uiEXT@16) + GL_STUB_ALIAS(Uniform3uiv, 824, Uniform3uiv@12, Uniform3uivEXT, Uniform3uivEXT@12) + GL_STUB_ALIAS(Uniform4ui, 825, Uniform4ui@20, Uniform4uiEXT, Uniform4uiEXT@20) + GL_STUB_ALIAS(Uniform4uiv, 826, Uniform4uiv@12, Uniform4uivEXT, Uniform4uivEXT@12) + GL_STUB_ALIAS(VertexAttribI1i, 827, VertexAttribI1i@8, VertexAttribI1iEXT, VertexAttribI1iEXT@8) + GL_STUB_ALIAS(VertexAttribI1iv, 828, VertexAttribI1iv@8, VertexAttribI1ivEXT, VertexAttribI1ivEXT@8) + GL_STUB_ALIAS(VertexAttribI1ui, 829, VertexAttribI1ui@8, VertexAttribI1uiEXT, VertexAttribI1uiEXT@8) + GL_STUB_ALIAS(VertexAttribI1uiv, 830, VertexAttribI1uiv@8, VertexAttribI1uivEXT, VertexAttribI1uivEXT@8) + GL_STUB_ALIAS(VertexAttribI2i, 831, VertexAttribI2i@12, VertexAttribI2iEXT, VertexAttribI2iEXT@12) + GL_STUB_ALIAS(VertexAttribI2iv, 832, VertexAttribI2iv@8, VertexAttribI2ivEXT, VertexAttribI2ivEXT@8) + GL_STUB_ALIAS(VertexAttribI2ui, 833, VertexAttribI2ui@12, VertexAttribI2uiEXT, VertexAttribI2uiEXT@12) + GL_STUB_ALIAS(VertexAttribI2uiv, 834, VertexAttribI2uiv@8, VertexAttribI2uivEXT, VertexAttribI2uivEXT@8) + GL_STUB_ALIAS(VertexAttribI3i, 835, VertexAttribI3i@16, VertexAttribI3iEXT, VertexAttribI3iEXT@16) + GL_STUB_ALIAS(VertexAttribI3iv, 836, VertexAttribI3iv@8, VertexAttribI3ivEXT, VertexAttribI3ivEXT@8) + GL_STUB_ALIAS(VertexAttribI3ui, 837, VertexAttribI3ui@16, VertexAttribI3uiEXT, VertexAttribI3uiEXT@16) + GL_STUB_ALIAS(VertexAttribI3uiv, 838, VertexAttribI3uiv@8, VertexAttribI3uivEXT, VertexAttribI3uivEXT@8) + GL_STUB_ALIAS(VertexAttribI4bv, 839, VertexAttribI4bv@8, VertexAttribI4bvEXT, VertexAttribI4bvEXT@8) + GL_STUB_ALIAS(VertexAttribI4i, 840, VertexAttribI4i@20, VertexAttribI4iEXT, VertexAttribI4iEXT@20) + GL_STUB_ALIAS(VertexAttribI4iv, 841, VertexAttribI4iv@8, VertexAttribI4ivEXT, VertexAttribI4ivEXT@8) + GL_STUB_ALIAS(VertexAttribI4sv, 842, VertexAttribI4sv@8, VertexAttribI4svEXT, VertexAttribI4svEXT@8) + GL_STUB_ALIAS(VertexAttribI4ubv, 843, VertexAttribI4ubv@8, VertexAttribI4ubvEXT, VertexAttribI4ubvEXT@8) + GL_STUB_ALIAS(VertexAttribI4ui, 844, VertexAttribI4ui@20, VertexAttribI4uiEXT, VertexAttribI4uiEXT@20) + GL_STUB_ALIAS(VertexAttribI4uiv, 845, VertexAttribI4uiv@8, VertexAttribI4uivEXT, VertexAttribI4uivEXT@8) + GL_STUB_ALIAS(VertexAttribI4usv, 846, VertexAttribI4usv@8, VertexAttribI4usvEXT, VertexAttribI4usvEXT@8) + GL_STUB_ALIAS(VertexAttribIPointer, 847, VertexAttribIPointer@20, VertexAttribIPointerEXT, VertexAttribIPointerEXT@20) + GL_STUB_ALIAS(FramebufferTextureLayer, 848, FramebufferTextureLayer@20, FramebufferTextureLayerEXT, FramebufferTextureLayerEXT@20) + GL_STUB_ALIAS(ColorMaski, 849, ColorMaski@20, ColorMaskIndexedEXT, ColorMaskIndexedEXT@20) + GL_STUB_ALIAS(Disablei, 850, Disablei@8, DisableIndexedEXT, DisableIndexedEXT@8) + GL_STUB_ALIAS(Enablei, 851, Enablei@8, EnableIndexedEXT, EnableIndexedEXT@8) + GL_STUB_ALIAS(GetBooleani_v, 852, GetBooleani_v@12, GetBooleanIndexedvEXT, GetBooleanIndexedvEXT@12) + GL_STUB_ALIAS(GetIntegeri_v, 853, GetIntegeri_v@12, GetIntegerIndexedvEXT, GetIntegerIndexedvEXT@12) + GL_STUB_ALIAS(IsEnabledi, 854, IsEnabledi@8, IsEnabledIndexedEXT, IsEnabledIndexedEXT@8) + GL_STUB_ALIAS(GetTexParameterIiv, 857, GetTexParameterIiv@12, GetTexParameterIivEXT, GetTexParameterIivEXT@12) + GL_STUB_ALIAS(GetTexParameterIuiv, 858, GetTexParameterIuiv@12, GetTexParameterIuivEXT, GetTexParameterIuivEXT@12) + GL_STUB_ALIAS(TexParameterIiv, 859, TexParameterIiv@12, TexParameterIivEXT, TexParameterIivEXT@12) + GL_STUB_ALIAS(TexParameterIuiv, 860, TexParameterIuiv@12, TexParameterIuivEXT, TexParameterIuivEXT@12) + GL_STUB_ALIAS(BeginConditionalRender, 861, BeginConditionalRender@8, BeginConditionalRenderNV, BeginConditionalRenderNV@8) + GL_STUB_ALIAS(EndConditionalRender, 862, EndConditionalRender@0, EndConditionalRenderNV, EndConditionalRenderNV@0) + GL_STUB_ALIAS(BeginTransformFeedback, 863, BeginTransformFeedback@4, BeginTransformFeedbackEXT, BeginTransformFeedbackEXT@4) + GL_STUB_ALIAS(BindBufferBase, 864, BindBufferBase@12, BindBufferBaseEXT, BindBufferBaseEXT@12) + GL_STUB_ALIAS(BindBufferRange, 866, BindBufferRange@20, BindBufferRangeEXT, BindBufferRangeEXT@20) + GL_STUB_ALIAS(EndTransformFeedback, 867, EndTransformFeedback@0, EndTransformFeedbackEXT, EndTransformFeedbackEXT@0) + GL_STUB_ALIAS(GetTransformFeedbackVarying, 868, GetTransformFeedbackVarying@28, GetTransformFeedbackVaryingEXT, GetTransformFeedbackVaryingEXT@28) + GL_STUB_ALIAS(TransformFeedbackVaryings, 869, TransformFeedbackVaryings@16, TransformFeedbackVaryingsEXT, TransformFeedbackVaryingsEXT@16) + GL_STUB_ALIAS(ProvokingVertex, 870, ProvokingVertex@4, ProvokingVertexEXT, ProvokingVertexEXT@4) + + GLOBL GLNAME(gl_dispatch_functions_end) + HIDDEN(GLNAME(gl_dispatch_functions_end)) + ALIGNTEXT16 +GLNAME(gl_dispatch_functions_end): + +#if defined(GLX_USE_TLS) && defined(__linux__) + .section ".note.ABI-tag", "a" + .p2align 2 + .long 1f - 0f /* name length */ + .long 3f - 2f /* data length */ + .long 1 /* note length */ +0: .asciz "GNU" /* vendor name */ +1: .p2align 2 +2: .long 0 /* note data: the ABI tag */ + .long 2,4,20 /* Minimum kernel version w/TLS */ +3: .p2align 2 /* pad out section */ +#endif /* GLX_USE_TLS */ + +#if defined (__ELF__) && defined (__linux__) + .section .note.GNU-stack,"",%progbits +#endif diff --git a/src/mapi/glapi/glapitable.h b/src/mapi/glapi/glapitable.h new file mode 100644 index 0000000..ff662dc --- /dev/null +++ b/src/mapi/glapi/glapitable.h @@ -0,0 +1,931 @@ +/* DO NOT EDIT - This file generated automatically by gl_table.py (from Mesa) script */ + +/* + * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. + * (C) Copyright IBM Corporation 2004 + * 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 + * BRIAN PAUL, IBM, + * 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. + */ + +#if !defined( _GLAPI_TABLE_H_ ) +# define _GLAPI_TABLE_H_ + +#ifndef GLAPIENTRYP +# ifndef GLAPIENTRY +# define GLAPIENTRY +# endif + +# define GLAPIENTRYP GLAPIENTRY * +#endif + + +struct _glapi_table +{ + void (GLAPIENTRYP NewList)(GLuint list, GLenum mode); /* 0 */ + void (GLAPIENTRYP EndList)(void); /* 1 */ + void (GLAPIENTRYP CallList)(GLuint list); /* 2 */ + void (GLAPIENTRYP CallLists)(GLsizei n, GLenum type, const GLvoid * lists); /* 3 */ + void (GLAPIENTRYP DeleteLists)(GLuint list, GLsizei range); /* 4 */ + GLuint (GLAPIENTRYP GenLists)(GLsizei range); /* 5 */ + void (GLAPIENTRYP ListBase)(GLuint base); /* 6 */ + void (GLAPIENTRYP Begin)(GLenum mode); /* 7 */ + void (GLAPIENTRYP Bitmap)(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte * bitmap); /* 8 */ + void (GLAPIENTRYP Color3b)(GLbyte red, GLbyte green, GLbyte blue); /* 9 */ + void (GLAPIENTRYP Color3bv)(const GLbyte * v); /* 10 */ + void (GLAPIENTRYP Color3d)(GLdouble red, GLdouble green, GLdouble blue); /* 11 */ + void (GLAPIENTRYP Color3dv)(const GLdouble * v); /* 12 */ + void (GLAPIENTRYP Color3f)(GLfloat red, GLfloat green, GLfloat blue); /* 13 */ + void (GLAPIENTRYP Color3fv)(const GLfloat * v); /* 14 */ + void (GLAPIENTRYP Color3i)(GLint red, GLint green, GLint blue); /* 15 */ + void (GLAPIENTRYP Color3iv)(const GLint * v); /* 16 */ + void (GLAPIENTRYP Color3s)(GLshort red, GLshort green, GLshort blue); /* 17 */ + void (GLAPIENTRYP Color3sv)(const GLshort * v); /* 18 */ + void (GLAPIENTRYP Color3ub)(GLubyte red, GLubyte green, GLubyte blue); /* 19 */ + void (GLAPIENTRYP Color3ubv)(const GLubyte * v); /* 20 */ + void (GLAPIENTRYP Color3ui)(GLuint red, GLuint green, GLuint blue); /* 21 */ + void (GLAPIENTRYP Color3uiv)(const GLuint * v); /* 22 */ + void (GLAPIENTRYP Color3us)(GLushort red, GLushort green, GLushort blue); /* 23 */ + void (GLAPIENTRYP Color3usv)(const GLushort * v); /* 24 */ + void (GLAPIENTRYP Color4b)(GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha); /* 25 */ + void (GLAPIENTRYP Color4bv)(const GLbyte * v); /* 26 */ + void (GLAPIENTRYP Color4d)(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha); /* 27 */ + void (GLAPIENTRYP Color4dv)(const GLdouble * v); /* 28 */ + void (GLAPIENTRYP Color4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); /* 29 */ + void (GLAPIENTRYP Color4fv)(const GLfloat * v); /* 30 */ + void (GLAPIENTRYP Color4i)(GLint red, GLint green, GLint blue, GLint alpha); /* 31 */ + void (GLAPIENTRYP Color4iv)(const GLint * v); /* 32 */ + void (GLAPIENTRYP Color4s)(GLshort red, GLshort green, GLshort blue, GLshort alpha); /* 33 */ + void (GLAPIENTRYP Color4sv)(const GLshort * v); /* 34 */ + void (GLAPIENTRYP Color4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); /* 35 */ + void (GLAPIENTRYP Color4ubv)(const GLubyte * v); /* 36 */ + void (GLAPIENTRYP Color4ui)(GLuint red, GLuint green, GLuint blue, GLuint alpha); /* 37 */ + void (GLAPIENTRYP Color4uiv)(const GLuint * v); /* 38 */ + void (GLAPIENTRYP Color4us)(GLushort red, GLushort green, GLushort blue, GLushort alpha); /* 39 */ + void (GLAPIENTRYP Color4usv)(const GLushort * v); /* 40 */ + void (GLAPIENTRYP EdgeFlag)(GLboolean flag); /* 41 */ + void (GLAPIENTRYP EdgeFlagv)(const GLboolean * flag); /* 42 */ + void (GLAPIENTRYP End)(void); /* 43 */ + void (GLAPIENTRYP Indexd)(GLdouble c); /* 44 */ + void (GLAPIENTRYP Indexdv)(const GLdouble * c); /* 45 */ + void (GLAPIENTRYP Indexf)(GLfloat c); /* 46 */ + void (GLAPIENTRYP Indexfv)(const GLfloat * c); /* 47 */ + void (GLAPIENTRYP Indexi)(GLint c); /* 48 */ + void (GLAPIENTRYP Indexiv)(const GLint * c); /* 49 */ + void (GLAPIENTRYP Indexs)(GLshort c); /* 50 */ + void (GLAPIENTRYP Indexsv)(const GLshort * c); /* 51 */ + void (GLAPIENTRYP Normal3b)(GLbyte nx, GLbyte ny, GLbyte nz); /* 52 */ + void (GLAPIENTRYP Normal3bv)(const GLbyte * v); /* 53 */ + void (GLAPIENTRYP Normal3d)(GLdouble nx, GLdouble ny, GLdouble nz); /* 54 */ + void (GLAPIENTRYP Normal3dv)(const GLdouble * v); /* 55 */ + void (GLAPIENTRYP Normal3f)(GLfloat nx, GLfloat ny, GLfloat nz); /* 56 */ + void (GLAPIENTRYP Normal3fv)(const GLfloat * v); /* 57 */ + void (GLAPIENTRYP Normal3i)(GLint nx, GLint ny, GLint nz); /* 58 */ + void (GLAPIENTRYP Normal3iv)(const GLint * v); /* 59 */ + void (GLAPIENTRYP Normal3s)(GLshort nx, GLshort ny, GLshort nz); /* 60 */ + void (GLAPIENTRYP Normal3sv)(const GLshort * v); /* 61 */ + void (GLAPIENTRYP RasterPos2d)(GLdouble x, GLdouble y); /* 62 */ + void (GLAPIENTRYP RasterPos2dv)(const GLdouble * v); /* 63 */ + void (GLAPIENTRYP RasterPos2f)(GLfloat x, GLfloat y); /* 64 */ + void (GLAPIENTRYP RasterPos2fv)(const GLfloat * v); /* 65 */ + void (GLAPIENTRYP RasterPos2i)(GLint x, GLint y); /* 66 */ + void (GLAPIENTRYP RasterPos2iv)(const GLint * v); /* 67 */ + void (GLAPIENTRYP RasterPos2s)(GLshort x, GLshort y); /* 68 */ + void (GLAPIENTRYP RasterPos2sv)(const GLshort * v); /* 69 */ + void (GLAPIENTRYP RasterPos3d)(GLdouble x, GLdouble y, GLdouble z); /* 70 */ + void (GLAPIENTRYP RasterPos3dv)(const GLdouble * v); /* 71 */ + void (GLAPIENTRYP RasterPos3f)(GLfloat x, GLfloat y, GLfloat z); /* 72 */ + void (GLAPIENTRYP RasterPos3fv)(const GLfloat * v); /* 73 */ + void (GLAPIENTRYP RasterPos3i)(GLint x, GLint y, GLint z); /* 74 */ + void (GLAPIENTRYP RasterPos3iv)(const GLint * v); /* 75 */ + void (GLAPIENTRYP RasterPos3s)(GLshort x, GLshort y, GLshort z); /* 76 */ + void (GLAPIENTRYP RasterPos3sv)(const GLshort * v); /* 77 */ + void (GLAPIENTRYP RasterPos4d)(GLdouble x, GLdouble y, GLdouble z, GLdouble w); /* 78 */ + void (GLAPIENTRYP RasterPos4dv)(const GLdouble * v); /* 79 */ + void (GLAPIENTRYP RasterPos4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w); /* 80 */ + void (GLAPIENTRYP RasterPos4fv)(const GLfloat * v); /* 81 */ + void (GLAPIENTRYP RasterPos4i)(GLint x, GLint y, GLint z, GLint w); /* 82 */ + void (GLAPIENTRYP RasterPos4iv)(const GLint * v); /* 83 */ + void (GLAPIENTRYP RasterPos4s)(GLshort x, GLshort y, GLshort z, GLshort w); /* 84 */ + void (GLAPIENTRYP RasterPos4sv)(const GLshort * v); /* 85 */ + void (GLAPIENTRYP Rectd)(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2); /* 86 */ + void (GLAPIENTRYP Rectdv)(const GLdouble * v1, const GLdouble * v2); /* 87 */ + void (GLAPIENTRYP Rectf)(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2); /* 88 */ + void (GLAPIENTRYP Rectfv)(const GLfloat * v1, const GLfloat * v2); /* 89 */ + void (GLAPIENTRYP Recti)(GLint x1, GLint y1, GLint x2, GLint y2); /* 90 */ + void (GLAPIENTRYP Rectiv)(const GLint * v1, const GLint * v2); /* 91 */ + void (GLAPIENTRYP Rects)(GLshort x1, GLshort y1, GLshort x2, GLshort y2); /* 92 */ + void (GLAPIENTRYP Rectsv)(const GLshort * v1, const GLshort * v2); /* 93 */ + void (GLAPIENTRYP TexCoord1d)(GLdouble s); /* 94 */ + void (GLAPIENTRYP TexCoord1dv)(const GLdouble * v); /* 95 */ + void (GLAPIENTRYP TexCoord1f)(GLfloat s); /* 96 */ + void (GLAPIENTRYP TexCoord1fv)(const GLfloat * v); /* 97 */ + void (GLAPIENTRYP TexCoord1i)(GLint s); /* 98 */ + void (GLAPIENTRYP TexCoord1iv)(const GLint * v); /* 99 */ + void (GLAPIENTRYP TexCoord1s)(GLshort s); /* 100 */ + void (GLAPIENTRYP TexCoord1sv)(const GLshort * v); /* 101 */ + void (GLAPIENTRYP TexCoord2d)(GLdouble s, GLdouble t); /* 102 */ + void (GLAPIENTRYP TexCoord2dv)(const GLdouble * v); /* 103 */ + void (GLAPIENTRYP TexCoord2f)(GLfloat s, GLfloat t); /* 104 */ + void (GLAPIENTRYP TexCoord2fv)(const GLfloat * v); /* 105 */ + void (GLAPIENTRYP TexCoord2i)(GLint s, GLint t); /* 106 */ + void (GLAPIENTRYP TexCoord2iv)(const GLint * v); /* 107 */ + void (GLAPIENTRYP TexCoord2s)(GLshort s, GLshort t); /* 108 */ + void (GLAPIENTRYP TexCoord2sv)(const GLshort * v); /* 109 */ + void (GLAPIENTRYP TexCoord3d)(GLdouble s, GLdouble t, GLdouble r); /* 110 */ + void (GLAPIENTRYP TexCoord3dv)(const GLdouble * v); /* 111 */ + void (GLAPIENTRYP TexCoord3f)(GLfloat s, GLfloat t, GLfloat r); /* 112 */ + void (GLAPIENTRYP TexCoord3fv)(const GLfloat * v); /* 113 */ + void (GLAPIENTRYP TexCoord3i)(GLint s, GLint t, GLint r); /* 114 */ + void (GLAPIENTRYP TexCoord3iv)(const GLint * v); /* 115 */ + void (GLAPIENTRYP TexCoord3s)(GLshort s, GLshort t, GLshort r); /* 116 */ + void (GLAPIENTRYP TexCoord3sv)(const GLshort * v); /* 117 */ + void (GLAPIENTRYP TexCoord4d)(GLdouble s, GLdouble t, GLdouble r, GLdouble q); /* 118 */ + void (GLAPIENTRYP TexCoord4dv)(const GLdouble * v); /* 119 */ + void (GLAPIENTRYP TexCoord4f)(GLfloat s, GLfloat t, GLfloat r, GLfloat q); /* 120 */ + void (GLAPIENTRYP TexCoord4fv)(const GLfloat * v); /* 121 */ + void (GLAPIENTRYP TexCoord4i)(GLint s, GLint t, GLint r, GLint q); /* 122 */ + void (GLAPIENTRYP TexCoord4iv)(const GLint * v); /* 123 */ + void (GLAPIENTRYP TexCoord4s)(GLshort s, GLshort t, GLshort r, GLshort q); /* 124 */ + void (GLAPIENTRYP TexCoord4sv)(const GLshort * v); /* 125 */ + void (GLAPIENTRYP Vertex2d)(GLdouble x, GLdouble y); /* 126 */ + void (GLAPIENTRYP Vertex2dv)(const GLdouble * v); /* 127 */ + void (GLAPIENTRYP Vertex2f)(GLfloat x, GLfloat y); /* 128 */ + void (GLAPIENTRYP Vertex2fv)(const GLfloat * v); /* 129 */ + void (GLAPIENTRYP Vertex2i)(GLint x, GLint y); /* 130 */ + void (GLAPIENTRYP Vertex2iv)(const GLint * v); /* 131 */ + void (GLAPIENTRYP Vertex2s)(GLshort x, GLshort y); /* 132 */ + void (GLAPIENTRYP Vertex2sv)(const GLshort * v); /* 133 */ + void (GLAPIENTRYP Vertex3d)(GLdouble x, GLdouble y, GLdouble z); /* 134 */ + void (GLAPIENTRYP Vertex3dv)(const GLdouble * v); /* 135 */ + void (GLAPIENTRYP Vertex3f)(GLfloat x, GLfloat y, GLfloat z); /* 136 */ + void (GLAPIENTRYP Vertex3fv)(const GLfloat * v); /* 137 */ + void (GLAPIENTRYP Vertex3i)(GLint x, GLint y, GLint z); /* 138 */ + void (GLAPIENTRYP Vertex3iv)(const GLint * v); /* 139 */ + void (GLAPIENTRYP Vertex3s)(GLshort x, GLshort y, GLshort z); /* 140 */ + void (GLAPIENTRYP Vertex3sv)(const GLshort * v); /* 141 */ + void (GLAPIENTRYP Vertex4d)(GLdouble x, GLdouble y, GLdouble z, GLdouble w); /* 142 */ + void (GLAPIENTRYP Vertex4dv)(const GLdouble * v); /* 143 */ + void (GLAPIENTRYP Vertex4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w); /* 144 */ + void (GLAPIENTRYP Vertex4fv)(const GLfloat * v); /* 145 */ + void (GLAPIENTRYP Vertex4i)(GLint x, GLint y, GLint z, GLint w); /* 146 */ + void (GLAPIENTRYP Vertex4iv)(const GLint * v); /* 147 */ + void (GLAPIENTRYP Vertex4s)(GLshort x, GLshort y, GLshort z, GLshort w); /* 148 */ + void (GLAPIENTRYP Vertex4sv)(const GLshort * v); /* 149 */ + void (GLAPIENTRYP ClipPlane)(GLenum plane, const GLdouble * equation); /* 150 */ + void (GLAPIENTRYP ColorMaterial)(GLenum face, GLenum mode); /* 151 */ + void (GLAPIENTRYP CullFace)(GLenum mode); /* 152 */ + void (GLAPIENTRYP Fogf)(GLenum pname, GLfloat param); /* 153 */ + void (GLAPIENTRYP Fogfv)(GLenum pname, const GLfloat * params); /* 154 */ + void (GLAPIENTRYP Fogi)(GLenum pname, GLint param); /* 155 */ + void (GLAPIENTRYP Fogiv)(GLenum pname, const GLint * params); /* 156 */ + void (GLAPIENTRYP FrontFace)(GLenum mode); /* 157 */ + void (GLAPIENTRYP Hint)(GLenum target, GLenum mode); /* 158 */ + void (GLAPIENTRYP Lightf)(GLenum light, GLenum pname, GLfloat param); /* 159 */ + void (GLAPIENTRYP Lightfv)(GLenum light, GLenum pname, const GLfloat * params); /* 160 */ + void (GLAPIENTRYP Lighti)(GLenum light, GLenum pname, GLint param); /* 161 */ + void (GLAPIENTRYP Lightiv)(GLenum light, GLenum pname, const GLint * params); /* 162 */ + void (GLAPIENTRYP LightModelf)(GLenum pname, GLfloat param); /* 163 */ + void (GLAPIENTRYP LightModelfv)(GLenum pname, const GLfloat * params); /* 164 */ + void (GLAPIENTRYP LightModeli)(GLenum pname, GLint param); /* 165 */ + void (GLAPIENTRYP LightModeliv)(GLenum pname, const GLint * params); /* 166 */ + void (GLAPIENTRYP LineStipple)(GLint factor, GLushort pattern); /* 167 */ + void (GLAPIENTRYP LineWidth)(GLfloat width); /* 168 */ + void (GLAPIENTRYP Materialf)(GLenum face, GLenum pname, GLfloat param); /* 169 */ + void (GLAPIENTRYP Materialfv)(GLenum face, GLenum pname, const GLfloat * params); /* 170 */ + void (GLAPIENTRYP Materiali)(GLenum face, GLenum pname, GLint param); /* 171 */ + void (GLAPIENTRYP Materialiv)(GLenum face, GLenum pname, const GLint * params); /* 172 */ + void (GLAPIENTRYP PointSize)(GLfloat size); /* 173 */ + void (GLAPIENTRYP PolygonMode)(GLenum face, GLenum mode); /* 174 */ + void (GLAPIENTRYP PolygonStipple)(const GLubyte * mask); /* 175 */ + void (GLAPIENTRYP Scissor)(GLint x, GLint y, GLsizei width, GLsizei height); /* 176 */ + void (GLAPIENTRYP ShadeModel)(GLenum mode); /* 177 */ + void (GLAPIENTRYP TexParameterf)(GLenum target, GLenum pname, GLfloat param); /* 178 */ + void (GLAPIENTRYP TexParameterfv)(GLenum target, GLenum pname, const GLfloat * params); /* 179 */ + void (GLAPIENTRYP TexParameteri)(GLenum target, GLenum pname, GLint param); /* 180 */ + void (GLAPIENTRYP TexParameteriv)(GLenum target, GLenum pname, const GLint * params); /* 181 */ + void (GLAPIENTRYP TexImage1D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid * pixels); /* 182 */ + void (GLAPIENTRYP TexImage2D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * pixels); /* 183 */ + void (GLAPIENTRYP TexEnvf)(GLenum target, GLenum pname, GLfloat param); /* 184 */ + void (GLAPIENTRYP TexEnvfv)(GLenum target, GLenum pname, const GLfloat * params); /* 185 */ + void (GLAPIENTRYP TexEnvi)(GLenum target, GLenum pname, GLint param); /* 186 */ + void (GLAPIENTRYP TexEnviv)(GLenum target, GLenum pname, const GLint * params); /* 187 */ + void (GLAPIENTRYP TexGend)(GLenum coord, GLenum pname, GLdouble param); /* 188 */ + void (GLAPIENTRYP TexGendv)(GLenum coord, GLenum pname, const GLdouble * params); /* 189 */ + void (GLAPIENTRYP TexGenf)(GLenum coord, GLenum pname, GLfloat param); /* 190 */ + void (GLAPIENTRYP TexGenfv)(GLenum coord, GLenum pname, const GLfloat * params); /* 191 */ + void (GLAPIENTRYP TexGeni)(GLenum coord, GLenum pname, GLint param); /* 192 */ + void (GLAPIENTRYP TexGeniv)(GLenum coord, GLenum pname, const GLint * params); /* 193 */ + void (GLAPIENTRYP FeedbackBuffer)(GLsizei size, GLenum type, GLfloat * buffer); /* 194 */ + void (GLAPIENTRYP SelectBuffer)(GLsizei size, GLuint * buffer); /* 195 */ + GLint (GLAPIENTRYP RenderMode)(GLenum mode); /* 196 */ + void (GLAPIENTRYP InitNames)(void); /* 197 */ + void (GLAPIENTRYP LoadName)(GLuint name); /* 198 */ + void (GLAPIENTRYP PassThrough)(GLfloat token); /* 199 */ + void (GLAPIENTRYP PopName)(void); /* 200 */ + void (GLAPIENTRYP PushName)(GLuint name); /* 201 */ + void (GLAPIENTRYP DrawBuffer)(GLenum mode); /* 202 */ + void (GLAPIENTRYP Clear)(GLbitfield mask); /* 203 */ + void (GLAPIENTRYP ClearAccum)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); /* 204 */ + void (GLAPIENTRYP ClearIndex)(GLfloat c); /* 205 */ + void (GLAPIENTRYP ClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); /* 206 */ + void (GLAPIENTRYP ClearStencil)(GLint s); /* 207 */ + void (GLAPIENTRYP ClearDepth)(GLclampd depth); /* 208 */ + void (GLAPIENTRYP StencilMask)(GLuint mask); /* 209 */ + void (GLAPIENTRYP ColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); /* 210 */ + void (GLAPIENTRYP DepthMask)(GLboolean flag); /* 211 */ + void (GLAPIENTRYP IndexMask)(GLuint mask); /* 212 */ + void (GLAPIENTRYP Accum)(GLenum op, GLfloat value); /* 213 */ + void (GLAPIENTRYP Disable)(GLenum cap); /* 214 */ + void (GLAPIENTRYP Enable)(GLenum cap); /* 215 */ + void (GLAPIENTRYP Finish)(void); /* 216 */ + void (GLAPIENTRYP Flush)(void); /* 217 */ + void (GLAPIENTRYP PopAttrib)(void); /* 218 */ + void (GLAPIENTRYP PushAttrib)(GLbitfield mask); /* 219 */ + void (GLAPIENTRYP Map1d)(GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble * points); /* 220 */ + void (GLAPIENTRYP Map1f)(GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat * points); /* 221 */ + void (GLAPIENTRYP Map2d)(GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble * points); /* 222 */ + void (GLAPIENTRYP Map2f)(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat * points); /* 223 */ + void (GLAPIENTRYP MapGrid1d)(GLint un, GLdouble u1, GLdouble u2); /* 224 */ + void (GLAPIENTRYP MapGrid1f)(GLint un, GLfloat u1, GLfloat u2); /* 225 */ + void (GLAPIENTRYP MapGrid2d)(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2); /* 226 */ + void (GLAPIENTRYP MapGrid2f)(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2); /* 227 */ + void (GLAPIENTRYP EvalCoord1d)(GLdouble u); /* 228 */ + void (GLAPIENTRYP EvalCoord1dv)(const GLdouble * u); /* 229 */ + void (GLAPIENTRYP EvalCoord1f)(GLfloat u); /* 230 */ + void (GLAPIENTRYP EvalCoord1fv)(const GLfloat * u); /* 231 */ + void (GLAPIENTRYP EvalCoord2d)(GLdouble u, GLdouble v); /* 232 */ + void (GLAPIENTRYP EvalCoord2dv)(const GLdouble * u); /* 233 */ + void (GLAPIENTRYP EvalCoord2f)(GLfloat u, GLfloat v); /* 234 */ + void (GLAPIENTRYP EvalCoord2fv)(const GLfloat * u); /* 235 */ + void (GLAPIENTRYP EvalMesh1)(GLenum mode, GLint i1, GLint i2); /* 236 */ + void (GLAPIENTRYP EvalPoint1)(GLint i); /* 237 */ + void (GLAPIENTRYP EvalMesh2)(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2); /* 238 */ + void (GLAPIENTRYP EvalPoint2)(GLint i, GLint j); /* 239 */ + void (GLAPIENTRYP AlphaFunc)(GLenum func, GLclampf ref); /* 240 */ + void (GLAPIENTRYP BlendFunc)(GLenum sfactor, GLenum dfactor); /* 241 */ + void (GLAPIENTRYP LogicOp)(GLenum opcode); /* 242 */ + void (GLAPIENTRYP StencilFunc)(GLenum func, GLint ref, GLuint mask); /* 243 */ + void (GLAPIENTRYP StencilOp)(GLenum fail, GLenum zfail, GLenum zpass); /* 244 */ + void (GLAPIENTRYP DepthFunc)(GLenum func); /* 245 */ + void (GLAPIENTRYP PixelZoom)(GLfloat xfactor, GLfloat yfactor); /* 246 */ + void (GLAPIENTRYP PixelTransferf)(GLenum pname, GLfloat param); /* 247 */ + void (GLAPIENTRYP PixelTransferi)(GLenum pname, GLint param); /* 248 */ + void (GLAPIENTRYP PixelStoref)(GLenum pname, GLfloat param); /* 249 */ + void (GLAPIENTRYP PixelStorei)(GLenum pname, GLint param); /* 250 */ + void (GLAPIENTRYP PixelMapfv)(GLenum map, GLsizei mapsize, const GLfloat * values); /* 251 */ + void (GLAPIENTRYP PixelMapuiv)(GLenum map, GLsizei mapsize, const GLuint * values); /* 252 */ + void (GLAPIENTRYP PixelMapusv)(GLenum map, GLsizei mapsize, const GLushort * values); /* 253 */ + void (GLAPIENTRYP ReadBuffer)(GLenum mode); /* 254 */ + void (GLAPIENTRYP CopyPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type); /* 255 */ + void (GLAPIENTRYP ReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * pixels); /* 256 */ + void (GLAPIENTRYP DrawPixels)(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * pixels); /* 257 */ + void (GLAPIENTRYP GetBooleanv)(GLenum pname, GLboolean * params); /* 258 */ + void (GLAPIENTRYP GetClipPlane)(GLenum plane, GLdouble * equation); /* 259 */ + void (GLAPIENTRYP GetDoublev)(GLenum pname, GLdouble * params); /* 260 */ + GLenum (GLAPIENTRYP GetError)(void); /* 261 */ + void (GLAPIENTRYP GetFloatv)(GLenum pname, GLfloat * params); /* 262 */ + void (GLAPIENTRYP GetIntegerv)(GLenum pname, GLint * params); /* 263 */ + void (GLAPIENTRYP GetLightfv)(GLenum light, GLenum pname, GLfloat * params); /* 264 */ + void (GLAPIENTRYP GetLightiv)(GLenum light, GLenum pname, GLint * params); /* 265 */ + void (GLAPIENTRYP GetMapdv)(GLenum target, GLenum query, GLdouble * v); /* 266 */ + void (GLAPIENTRYP GetMapfv)(GLenum target, GLenum query, GLfloat * v); /* 267 */ + void (GLAPIENTRYP GetMapiv)(GLenum target, GLenum query, GLint * v); /* 268 */ + void (GLAPIENTRYP GetMaterialfv)(GLenum face, GLenum pname, GLfloat * params); /* 269 */ + void (GLAPIENTRYP GetMaterialiv)(GLenum face, GLenum pname, GLint * params); /* 270 */ + void (GLAPIENTRYP GetPixelMapfv)(GLenum map, GLfloat * values); /* 271 */ + void (GLAPIENTRYP GetPixelMapuiv)(GLenum map, GLuint * values); /* 272 */ + void (GLAPIENTRYP GetPixelMapusv)(GLenum map, GLushort * values); /* 273 */ + void (GLAPIENTRYP GetPolygonStipple)(GLubyte * mask); /* 274 */ + const GLubyte * (GLAPIENTRYP GetString)(GLenum name); /* 275 */ + void (GLAPIENTRYP GetTexEnvfv)(GLenum target, GLenum pname, GLfloat * params); /* 276 */ + void (GLAPIENTRYP GetTexEnviv)(GLenum target, GLenum pname, GLint * params); /* 277 */ + void (GLAPIENTRYP GetTexGendv)(GLenum coord, GLenum pname, GLdouble * params); /* 278 */ + void (GLAPIENTRYP GetTexGenfv)(GLenum coord, GLenum pname, GLfloat * params); /* 279 */ + void (GLAPIENTRYP GetTexGeniv)(GLenum coord, GLenum pname, GLint * params); /* 280 */ + void (GLAPIENTRYP GetTexImage)(GLenum target, GLint level, GLenum format, GLenum type, GLvoid * pixels); /* 281 */ + void (GLAPIENTRYP GetTexParameterfv)(GLenum target, GLenum pname, GLfloat * params); /* 282 */ + void (GLAPIENTRYP GetTexParameteriv)(GLenum target, GLenum pname, GLint * params); /* 283 */ + void (GLAPIENTRYP GetTexLevelParameterfv)(GLenum target, GLint level, GLenum pname, GLfloat * params); /* 284 */ + void (GLAPIENTRYP GetTexLevelParameteriv)(GLenum target, GLint level, GLenum pname, GLint * params); /* 285 */ + GLboolean (GLAPIENTRYP IsEnabled)(GLenum cap); /* 286 */ + GLboolean (GLAPIENTRYP IsList)(GLuint list); /* 287 */ + void (GLAPIENTRYP DepthRange)(GLclampd zNear, GLclampd zFar); /* 288 */ + void (GLAPIENTRYP Frustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); /* 289 */ + void (GLAPIENTRYP LoadIdentity)(void); /* 290 */ + void (GLAPIENTRYP LoadMatrixf)(const GLfloat * m); /* 291 */ + void (GLAPIENTRYP LoadMatrixd)(const GLdouble * m); /* 292 */ + void (GLAPIENTRYP MatrixMode)(GLenum mode); /* 293 */ + void (GLAPIENTRYP MultMatrixf)(const GLfloat * m); /* 294 */ + void (GLAPIENTRYP MultMatrixd)(const GLdouble * m); /* 295 */ + void (GLAPIENTRYP Ortho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); /* 296 */ + void (GLAPIENTRYP PopMatrix)(void); /* 297 */ + void (GLAPIENTRYP PushMatrix)(void); /* 298 */ + void (GLAPIENTRYP Rotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z); /* 299 */ + void (GLAPIENTRYP Rotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); /* 300 */ + void (GLAPIENTRYP Scaled)(GLdouble x, GLdouble y, GLdouble z); /* 301 */ + void (GLAPIENTRYP Scalef)(GLfloat x, GLfloat y, GLfloat z); /* 302 */ + void (GLAPIENTRYP Translated)(GLdouble x, GLdouble y, GLdouble z); /* 303 */ + void (GLAPIENTRYP Translatef)(GLfloat x, GLfloat y, GLfloat z); /* 304 */ + void (GLAPIENTRYP Viewport)(GLint x, GLint y, GLsizei width, GLsizei height); /* 305 */ + void (GLAPIENTRYP ArrayElement)(GLint i); /* 306 */ + void (GLAPIENTRYP BindTexture)(GLenum target, GLuint texture); /* 307 */ + void (GLAPIENTRYP ColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer); /* 308 */ + void (GLAPIENTRYP DisableClientState)(GLenum array); /* 309 */ + void (GLAPIENTRYP DrawArrays)(GLenum mode, GLint first, GLsizei count); /* 310 */ + void (GLAPIENTRYP DrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices); /* 311 */ + void (GLAPIENTRYP EdgeFlagPointer)(GLsizei stride, const GLvoid * pointer); /* 312 */ + void (GLAPIENTRYP EnableClientState)(GLenum array); /* 313 */ + void (GLAPIENTRYP IndexPointer)(GLenum type, GLsizei stride, const GLvoid * pointer); /* 314 */ + void (GLAPIENTRYP Indexub)(GLubyte c); /* 315 */ + void (GLAPIENTRYP Indexubv)(const GLubyte * c); /* 316 */ + void (GLAPIENTRYP InterleavedArrays)(GLenum format, GLsizei stride, const GLvoid * pointer); /* 317 */ + void (GLAPIENTRYP NormalPointer)(GLenum type, GLsizei stride, const GLvoid * pointer); /* 318 */ + void (GLAPIENTRYP PolygonOffset)(GLfloat factor, GLfloat units); /* 319 */ + void (GLAPIENTRYP TexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer); /* 320 */ + void (GLAPIENTRYP VertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer); /* 321 */ + GLboolean (GLAPIENTRYP AreTexturesResident)(GLsizei n, const GLuint * textures, GLboolean * residences); /* 322 */ + void (GLAPIENTRYP CopyTexImage1D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); /* 323 */ + void (GLAPIENTRYP CopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); /* 324 */ + void (GLAPIENTRYP CopyTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); /* 325 */ + void (GLAPIENTRYP CopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); /* 326 */ + void (GLAPIENTRYP DeleteTextures)(GLsizei n, const GLuint * textures); /* 327 */ + void (GLAPIENTRYP GenTextures)(GLsizei n, GLuint * textures); /* 328 */ + void (GLAPIENTRYP GetPointerv)(GLenum pname, GLvoid ** params); /* 329 */ + GLboolean (GLAPIENTRYP IsTexture)(GLuint texture); /* 330 */ + void (GLAPIENTRYP PrioritizeTextures)(GLsizei n, const GLuint * textures, const GLclampf * priorities); /* 331 */ + void (GLAPIENTRYP TexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid * pixels); /* 332 */ + void (GLAPIENTRYP TexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * pixels); /* 333 */ + void (GLAPIENTRYP PopClientAttrib)(void); /* 334 */ + void (GLAPIENTRYP PushClientAttrib)(GLbitfield mask); /* 335 */ + void (GLAPIENTRYP BlendColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); /* 336 */ + void (GLAPIENTRYP BlendEquation)(GLenum mode); /* 337 */ + void (GLAPIENTRYP DrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid * indices); /* 338 */ + void (GLAPIENTRYP ColorTable)(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid * table); /* 339 */ + void (GLAPIENTRYP ColorTableParameterfv)(GLenum target, GLenum pname, const GLfloat * params); /* 340 */ + void (GLAPIENTRYP ColorTableParameteriv)(GLenum target, GLenum pname, const GLint * params); /* 341 */ + void (GLAPIENTRYP CopyColorTable)(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); /* 342 */ + void (GLAPIENTRYP GetColorTable)(GLenum target, GLenum format, GLenum type, GLvoid * table); /* 343 */ + void (GLAPIENTRYP GetColorTableParameterfv)(GLenum target, GLenum pname, GLfloat * params); /* 344 */ + void (GLAPIENTRYP GetColorTableParameteriv)(GLenum target, GLenum pname, GLint * params); /* 345 */ + void (GLAPIENTRYP ColorSubTable)(GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid * data); /* 346 */ + void (GLAPIENTRYP CopyColorSubTable)(GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); /* 347 */ + void (GLAPIENTRYP ConvolutionFilter1D)(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid * image); /* 348 */ + void (GLAPIENTRYP ConvolutionFilter2D)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * image); /* 349 */ + void (GLAPIENTRYP ConvolutionParameterf)(GLenum target, GLenum pname, GLfloat params); /* 350 */ + void (GLAPIENTRYP ConvolutionParameterfv)(GLenum target, GLenum pname, const GLfloat * params); /* 351 */ + void (GLAPIENTRYP ConvolutionParameteri)(GLenum target, GLenum pname, GLint params); /* 352 */ + void (GLAPIENTRYP ConvolutionParameteriv)(GLenum target, GLenum pname, const GLint * params); /* 353 */ + void (GLAPIENTRYP CopyConvolutionFilter1D)(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); /* 354 */ + void (GLAPIENTRYP CopyConvolutionFilter2D)(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); /* 355 */ + void (GLAPIENTRYP GetConvolutionFilter)(GLenum target, GLenum format, GLenum type, GLvoid * image); /* 356 */ + void (GLAPIENTRYP GetConvolutionParameterfv)(GLenum target, GLenum pname, GLfloat * params); /* 357 */ + void (GLAPIENTRYP GetConvolutionParameteriv)(GLenum target, GLenum pname, GLint * params); /* 358 */ + void (GLAPIENTRYP GetSeparableFilter)(GLenum target, GLenum format, GLenum type, GLvoid * row, GLvoid * column, GLvoid * span); /* 359 */ + void (GLAPIENTRYP SeparableFilter2D)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * row, const GLvoid * column); /* 360 */ + void (GLAPIENTRYP GetHistogram)(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid * values); /* 361 */ + void (GLAPIENTRYP GetHistogramParameterfv)(GLenum target, GLenum pname, GLfloat * params); /* 362 */ + void (GLAPIENTRYP GetHistogramParameteriv)(GLenum target, GLenum pname, GLint * params); /* 363 */ + void (GLAPIENTRYP GetMinmax)(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid * values); /* 364 */ + void (GLAPIENTRYP GetMinmaxParameterfv)(GLenum target, GLenum pname, GLfloat * params); /* 365 */ + void (GLAPIENTRYP GetMinmaxParameteriv)(GLenum target, GLenum pname, GLint * params); /* 366 */ + void (GLAPIENTRYP Histogram)(GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); /* 367 */ + void (GLAPIENTRYP Minmax)(GLenum target, GLenum internalformat, GLboolean sink); /* 368 */ + void (GLAPIENTRYP ResetHistogram)(GLenum target); /* 369 */ + void (GLAPIENTRYP ResetMinmax)(GLenum target); /* 370 */ + void (GLAPIENTRYP TexImage3D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid * pixels); /* 371 */ + void (GLAPIENTRYP TexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid * pixels); /* 372 */ + void (GLAPIENTRYP CopyTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); /* 373 */ + void (GLAPIENTRYP ActiveTextureARB)(GLenum texture); /* 374 */ + void (GLAPIENTRYP ClientActiveTextureARB)(GLenum texture); /* 375 */ + void (GLAPIENTRYP MultiTexCoord1dARB)(GLenum target, GLdouble s); /* 376 */ + void (GLAPIENTRYP MultiTexCoord1dvARB)(GLenum target, const GLdouble * v); /* 377 */ + void (GLAPIENTRYP MultiTexCoord1fARB)(GLenum target, GLfloat s); /* 378 */ + void (GLAPIENTRYP MultiTexCoord1fvARB)(GLenum target, const GLfloat * v); /* 379 */ + void (GLAPIENTRYP MultiTexCoord1iARB)(GLenum target, GLint s); /* 380 */ + void (GLAPIENTRYP MultiTexCoord1ivARB)(GLenum target, const GLint * v); /* 381 */ + void (GLAPIENTRYP MultiTexCoord1sARB)(GLenum target, GLshort s); /* 382 */ + void (GLAPIENTRYP MultiTexCoord1svARB)(GLenum target, const GLshort * v); /* 383 */ + void (GLAPIENTRYP MultiTexCoord2dARB)(GLenum target, GLdouble s, GLdouble t); /* 384 */ + void (GLAPIENTRYP MultiTexCoord2dvARB)(GLenum target, const GLdouble * v); /* 385 */ + void (GLAPIENTRYP MultiTexCoord2fARB)(GLenum target, GLfloat s, GLfloat t); /* 386 */ + void (GLAPIENTRYP MultiTexCoord2fvARB)(GLenum target, const GLfloat * v); /* 387 */ + void (GLAPIENTRYP MultiTexCoord2iARB)(GLenum target, GLint s, GLint t); /* 388 */ + void (GLAPIENTRYP MultiTexCoord2ivARB)(GLenum target, const GLint * v); /* 389 */ + void (GLAPIENTRYP MultiTexCoord2sARB)(GLenum target, GLshort s, GLshort t); /* 390 */ + void (GLAPIENTRYP MultiTexCoord2svARB)(GLenum target, const GLshort * v); /* 391 */ + void (GLAPIENTRYP MultiTexCoord3dARB)(GLenum target, GLdouble s, GLdouble t, GLdouble r); /* 392 */ + void (GLAPIENTRYP MultiTexCoord3dvARB)(GLenum target, const GLdouble * v); /* 393 */ + void (GLAPIENTRYP MultiTexCoord3fARB)(GLenum target, GLfloat s, GLfloat t, GLfloat r); /* 394 */ + void (GLAPIENTRYP MultiTexCoord3fvARB)(GLenum target, const GLfloat * v); /* 395 */ + void (GLAPIENTRYP MultiTexCoord3iARB)(GLenum target, GLint s, GLint t, GLint r); /* 396 */ + void (GLAPIENTRYP MultiTexCoord3ivARB)(GLenum target, const GLint * v); /* 397 */ + void (GLAPIENTRYP MultiTexCoord3sARB)(GLenum target, GLshort s, GLshort t, GLshort r); /* 398 */ + void (GLAPIENTRYP MultiTexCoord3svARB)(GLenum target, const GLshort * v); /* 399 */ + void (GLAPIENTRYP MultiTexCoord4dARB)(GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); /* 400 */ + void (GLAPIENTRYP MultiTexCoord4dvARB)(GLenum target, const GLdouble * v); /* 401 */ + void (GLAPIENTRYP MultiTexCoord4fARB)(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); /* 402 */ + void (GLAPIENTRYP MultiTexCoord4fvARB)(GLenum target, const GLfloat * v); /* 403 */ + void (GLAPIENTRYP MultiTexCoord4iARB)(GLenum target, GLint s, GLint t, GLint r, GLint q); /* 404 */ + void (GLAPIENTRYP MultiTexCoord4ivARB)(GLenum target, const GLint * v); /* 405 */ + void (GLAPIENTRYP MultiTexCoord4sARB)(GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); /* 406 */ + void (GLAPIENTRYP MultiTexCoord4svARB)(GLenum target, const GLshort * v); /* 407 */ + void (GLAPIENTRYP AttachShader)(GLuint program, GLuint shader); /* 408 */ + GLuint (GLAPIENTRYP CreateProgram)(void); /* 409 */ + GLuint (GLAPIENTRYP CreateShader)(GLenum type); /* 410 */ + void (GLAPIENTRYP DeleteProgram)(GLuint program); /* 411 */ + void (GLAPIENTRYP DeleteShader)(GLuint program); /* 412 */ + void (GLAPIENTRYP DetachShader)(GLuint program, GLuint shader); /* 413 */ + void (GLAPIENTRYP GetAttachedShaders)(GLuint program, GLsizei maxCount, GLsizei * count, GLuint * obj); /* 414 */ + void (GLAPIENTRYP GetProgramInfoLog)(GLuint program, GLsizei bufSize, GLsizei * length, GLchar * infoLog); /* 415 */ + void (GLAPIENTRYP GetProgramiv)(GLuint program, GLenum pname, GLint * params); /* 416 */ + void (GLAPIENTRYP GetShaderInfoLog)(GLuint shader, GLsizei bufSize, GLsizei * length, GLchar * infoLog); /* 417 */ + void (GLAPIENTRYP GetShaderiv)(GLuint shader, GLenum pname, GLint * params); /* 418 */ + GLboolean (GLAPIENTRYP IsProgram)(GLuint program); /* 419 */ + GLboolean (GLAPIENTRYP IsShader)(GLuint shader); /* 420 */ + void (GLAPIENTRYP StencilFuncSeparate)(GLenum face, GLenum func, GLint ref, GLuint mask); /* 421 */ + void (GLAPIENTRYP StencilMaskSeparate)(GLenum face, GLuint mask); /* 422 */ + void (GLAPIENTRYP StencilOpSeparate)(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass); /* 423 */ + void (GLAPIENTRYP UniformMatrix2x3fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); /* 424 */ + void (GLAPIENTRYP UniformMatrix2x4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); /* 425 */ + void (GLAPIENTRYP UniformMatrix3x2fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); /* 426 */ + void (GLAPIENTRYP UniformMatrix3x4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); /* 427 */ + void (GLAPIENTRYP UniformMatrix4x2fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); /* 428 */ + void (GLAPIENTRYP UniformMatrix4x3fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); /* 429 */ + void (GLAPIENTRYP ClampColor)(GLenum target, GLenum clamp); /* 430 */ + void (GLAPIENTRYP ClearBufferfi)(GLenum buffer, GLint drawbuffer, const GLfloat depth, const GLint stencil); /* 431 */ + void (GLAPIENTRYP ClearBufferfv)(GLenum buffer, GLint drawbuffer, const GLfloat * value); /* 432 */ + void (GLAPIENTRYP ClearBufferiv)(GLenum buffer, GLint drawbuffer, const GLint * value); /* 433 */ + void (GLAPIENTRYP ClearBufferuiv)(GLenum buffer, GLint drawbuffer, const GLuint * value); /* 434 */ + const GLubyte * (GLAPIENTRYP GetStringi)(GLenum name, GLuint index); /* 435 */ + void (GLAPIENTRYP TexBuffer)(GLenum target, GLenum internalFormat, GLuint buffer); /* 436 */ + void (GLAPIENTRYP FramebufferTexture)(GLenum target, GLenum attachment, GLuint texture, GLint level); /* 437 */ + void (GLAPIENTRYP GetBufferParameteri64v)(GLenum target, GLenum pname, GLint64 * params); /* 438 */ + void (GLAPIENTRYP GetInteger64i_v)(GLenum cap, GLuint index, GLint64 * data); /* 439 */ + void (GLAPIENTRYP VertexAttribDivisor)(GLuint index, GLuint divisor); /* 440 */ + void (GLAPIENTRYP LoadTransposeMatrixdARB)(const GLdouble * m); /* 441 */ + void (GLAPIENTRYP LoadTransposeMatrixfARB)(const GLfloat * m); /* 442 */ + void (GLAPIENTRYP MultTransposeMatrixdARB)(const GLdouble * m); /* 443 */ + void (GLAPIENTRYP MultTransposeMatrixfARB)(const GLfloat * m); /* 444 */ + void (GLAPIENTRYP SampleCoverageARB)(GLclampf value, GLboolean invert); /* 445 */ + void (GLAPIENTRYP CompressedTexImage1DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid * data); /* 446 */ + void (GLAPIENTRYP CompressedTexImage2DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data); /* 447 */ + void (GLAPIENTRYP CompressedTexImage3DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid * data); /* 448 */ + void (GLAPIENTRYP CompressedTexSubImage1DARB)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid * data); /* 449 */ + void (GLAPIENTRYP CompressedTexSubImage2DARB)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid * data); /* 450 */ + void (GLAPIENTRYP CompressedTexSubImage3DARB)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid * data); /* 451 */ + void (GLAPIENTRYP GetCompressedTexImageARB)(GLenum target, GLint level, GLvoid * img); /* 452 */ + void (GLAPIENTRYP DisableVertexAttribArrayARB)(GLuint index); /* 453 */ + void (GLAPIENTRYP EnableVertexAttribArrayARB)(GLuint index); /* 454 */ + void (GLAPIENTRYP GetProgramEnvParameterdvARB)(GLenum target, GLuint index, GLdouble * params); /* 455 */ + void (GLAPIENTRYP GetProgramEnvParameterfvARB)(GLenum target, GLuint index, GLfloat * params); /* 456 */ + void (GLAPIENTRYP GetProgramLocalParameterdvARB)(GLenum target, GLuint index, GLdouble * params); /* 457 */ + void (GLAPIENTRYP GetProgramLocalParameterfvARB)(GLenum target, GLuint index, GLfloat * params); /* 458 */ + void (GLAPIENTRYP GetProgramStringARB)(GLenum target, GLenum pname, GLvoid * string); /* 459 */ + void (GLAPIENTRYP GetProgramivARB)(GLenum target, GLenum pname, GLint * params); /* 460 */ + void (GLAPIENTRYP GetVertexAttribdvARB)(GLuint index, GLenum pname, GLdouble * params); /* 461 */ + void (GLAPIENTRYP GetVertexAttribfvARB)(GLuint index, GLenum pname, GLfloat * params); /* 462 */ + void (GLAPIENTRYP GetVertexAttribivARB)(GLuint index, GLenum pname, GLint * params); /* 463 */ + void (GLAPIENTRYP ProgramEnvParameter4dARB)(GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); /* 464 */ + void (GLAPIENTRYP ProgramEnvParameter4dvARB)(GLenum target, GLuint index, const GLdouble * params); /* 465 */ + void (GLAPIENTRYP ProgramEnvParameter4fARB)(GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); /* 466 */ + void (GLAPIENTRYP ProgramEnvParameter4fvARB)(GLenum target, GLuint index, const GLfloat * params); /* 467 */ + void (GLAPIENTRYP ProgramLocalParameter4dARB)(GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); /* 468 */ + void (GLAPIENTRYP ProgramLocalParameter4dvARB)(GLenum target, GLuint index, const GLdouble * params); /* 469 */ + void (GLAPIENTRYP ProgramLocalParameter4fARB)(GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); /* 470 */ + void (GLAPIENTRYP ProgramLocalParameter4fvARB)(GLenum target, GLuint index, const GLfloat * params); /* 471 */ + void (GLAPIENTRYP ProgramStringARB)(GLenum target, GLenum format, GLsizei len, const GLvoid * string); /* 472 */ + void (GLAPIENTRYP VertexAttrib1dARB)(GLuint index, GLdouble x); /* 473 */ + void (GLAPIENTRYP VertexAttrib1dvARB)(GLuint index, const GLdouble * v); /* 474 */ + void (GLAPIENTRYP VertexAttrib1fARB)(GLuint index, GLfloat x); /* 475 */ + void (GLAPIENTRYP VertexAttrib1fvARB)(GLuint index, const GLfloat * v); /* 476 */ + void (GLAPIENTRYP VertexAttrib1sARB)(GLuint index, GLshort x); /* 477 */ + void (GLAPIENTRYP VertexAttrib1svARB)(GLuint index, const GLshort * v); /* 478 */ + void (GLAPIENTRYP VertexAttrib2dARB)(GLuint index, GLdouble x, GLdouble y); /* 479 */ + void (GLAPIENTRYP VertexAttrib2dvARB)(GLuint index, const GLdouble * v); /* 480 */ + void (GLAPIENTRYP VertexAttrib2fARB)(GLuint index, GLfloat x, GLfloat y); /* 481 */ + void (GLAPIENTRYP VertexAttrib2fvARB)(GLuint index, const GLfloat * v); /* 482 */ + void (GLAPIENTRYP VertexAttrib2sARB)(GLuint index, GLshort x, GLshort y); /* 483 */ + void (GLAPIENTRYP VertexAttrib2svARB)(GLuint index, const GLshort * v); /* 484 */ + void (GLAPIENTRYP VertexAttrib3dARB)(GLuint index, GLdouble x, GLdouble y, GLdouble z); /* 485 */ + void (GLAPIENTRYP VertexAttrib3dvARB)(GLuint index, const GLdouble * v); /* 486 */ + void (GLAPIENTRYP VertexAttrib3fARB)(GLuint index, GLfloat x, GLfloat y, GLfloat z); /* 487 */ + void (GLAPIENTRYP VertexAttrib3fvARB)(GLuint index, const GLfloat * v); /* 488 */ + void (GLAPIENTRYP VertexAttrib3sARB)(GLuint index, GLshort x, GLshort y, GLshort z); /* 489 */ + void (GLAPIENTRYP VertexAttrib3svARB)(GLuint index, const GLshort * v); /* 490 */ + void (GLAPIENTRYP VertexAttrib4NbvARB)(GLuint index, const GLbyte * v); /* 491 */ + void (GLAPIENTRYP VertexAttrib4NivARB)(GLuint index, const GLint * v); /* 492 */ + void (GLAPIENTRYP VertexAttrib4NsvARB)(GLuint index, const GLshort * v); /* 493 */ + void (GLAPIENTRYP VertexAttrib4NubARB)(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); /* 494 */ + void (GLAPIENTRYP VertexAttrib4NubvARB)(GLuint index, const GLubyte * v); /* 495 */ + void (GLAPIENTRYP VertexAttrib4NuivARB)(GLuint index, const GLuint * v); /* 496 */ + void (GLAPIENTRYP VertexAttrib4NusvARB)(GLuint index, const GLushort * v); /* 497 */ + void (GLAPIENTRYP VertexAttrib4bvARB)(GLuint index, const GLbyte * v); /* 498 */ + void (GLAPIENTRYP VertexAttrib4dARB)(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); /* 499 */ + void (GLAPIENTRYP VertexAttrib4dvARB)(GLuint index, const GLdouble * v); /* 500 */ + void (GLAPIENTRYP VertexAttrib4fARB)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); /* 501 */ + void (GLAPIENTRYP VertexAttrib4fvARB)(GLuint index, const GLfloat * v); /* 502 */ + void (GLAPIENTRYP VertexAttrib4ivARB)(GLuint index, const GLint * v); /* 503 */ + void (GLAPIENTRYP VertexAttrib4sARB)(GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); /* 504 */ + void (GLAPIENTRYP VertexAttrib4svARB)(GLuint index, const GLshort * v); /* 505 */ + void (GLAPIENTRYP VertexAttrib4ubvARB)(GLuint index, const GLubyte * v); /* 506 */ + void (GLAPIENTRYP VertexAttrib4uivARB)(GLuint index, const GLuint * v); /* 507 */ + void (GLAPIENTRYP VertexAttrib4usvARB)(GLuint index, const GLushort * v); /* 508 */ + void (GLAPIENTRYP VertexAttribPointerARB)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer); /* 509 */ + void (GLAPIENTRYP BindBufferARB)(GLenum target, GLuint buffer); /* 510 */ + void (GLAPIENTRYP BufferDataARB)(GLenum target, GLsizeiptrARB size, const GLvoid * data, GLenum usage); /* 511 */ + void (GLAPIENTRYP BufferSubDataARB)(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid * data); /* 512 */ + void (GLAPIENTRYP DeleteBuffersARB)(GLsizei n, const GLuint * buffer); /* 513 */ + void (GLAPIENTRYP GenBuffersARB)(GLsizei n, GLuint * buffer); /* 514 */ + void (GLAPIENTRYP GetBufferParameterivARB)(GLenum target, GLenum pname, GLint * params); /* 515 */ + void (GLAPIENTRYP GetBufferPointervARB)(GLenum target, GLenum pname, GLvoid ** params); /* 516 */ + void (GLAPIENTRYP GetBufferSubDataARB)(GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid * data); /* 517 */ + GLboolean (GLAPIENTRYP IsBufferARB)(GLuint buffer); /* 518 */ + GLvoid * (GLAPIENTRYP MapBufferARB)(GLenum target, GLenum access); /* 519 */ + GLboolean (GLAPIENTRYP UnmapBufferARB)(GLenum target); /* 520 */ + void (GLAPIENTRYP BeginQueryARB)(GLenum target, GLuint id); /* 521 */ + void (GLAPIENTRYP DeleteQueriesARB)(GLsizei n, const GLuint * ids); /* 522 */ + void (GLAPIENTRYP EndQueryARB)(GLenum target); /* 523 */ + void (GLAPIENTRYP GenQueriesARB)(GLsizei n, GLuint * ids); /* 524 */ + void (GLAPIENTRYP GetQueryObjectivARB)(GLuint id, GLenum pname, GLint * params); /* 525 */ + void (GLAPIENTRYP GetQueryObjectuivARB)(GLuint id, GLenum pname, GLuint * params); /* 526 */ + void (GLAPIENTRYP GetQueryivARB)(GLenum target, GLenum pname, GLint * params); /* 527 */ + GLboolean (GLAPIENTRYP IsQueryARB)(GLuint id); /* 528 */ + void (GLAPIENTRYP AttachObjectARB)(GLhandleARB containerObj, GLhandleARB obj); /* 529 */ + void (GLAPIENTRYP CompileShaderARB)(GLhandleARB shader); /* 530 */ + GLhandleARB (GLAPIENTRYP CreateProgramObjectARB)(void); /* 531 */ + GLhandleARB (GLAPIENTRYP CreateShaderObjectARB)(GLenum shaderType); /* 532 */ + void (GLAPIENTRYP DeleteObjectARB)(GLhandleARB obj); /* 533 */ + void (GLAPIENTRYP DetachObjectARB)(GLhandleARB containerObj, GLhandleARB attachedObj); /* 534 */ + void (GLAPIENTRYP GetActiveUniformARB)(GLhandleARB program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLcharARB * name); /* 535 */ + void (GLAPIENTRYP GetAttachedObjectsARB)(GLhandleARB containerObj, GLsizei maxLength, GLsizei * length, GLhandleARB * infoLog); /* 536 */ + GLhandleARB (GLAPIENTRYP GetHandleARB)(GLenum pname); /* 537 */ + void (GLAPIENTRYP GetInfoLogARB)(GLhandleARB obj, GLsizei maxLength, GLsizei * length, GLcharARB * infoLog); /* 538 */ + void (GLAPIENTRYP GetObjectParameterfvARB)(GLhandleARB obj, GLenum pname, GLfloat * params); /* 539 */ + void (GLAPIENTRYP GetObjectParameterivARB)(GLhandleARB obj, GLenum pname, GLint * params); /* 540 */ + void (GLAPIENTRYP GetShaderSourceARB)(GLhandleARB shader, GLsizei bufSize, GLsizei * length, GLcharARB * source); /* 541 */ + GLint (GLAPIENTRYP GetUniformLocationARB)(GLhandleARB program, const GLcharARB * name); /* 542 */ + void (GLAPIENTRYP GetUniformfvARB)(GLhandleARB program, GLint location, GLfloat * params); /* 543 */ + void (GLAPIENTRYP GetUniformivARB)(GLhandleARB program, GLint location, GLint * params); /* 544 */ + void (GLAPIENTRYP LinkProgramARB)(GLhandleARB program); /* 545 */ + void (GLAPIENTRYP ShaderSourceARB)(GLhandleARB shader, GLsizei count, const GLcharARB ** string, const GLint * length); /* 546 */ + void (GLAPIENTRYP Uniform1fARB)(GLint location, GLfloat v0); /* 547 */ + void (GLAPIENTRYP Uniform1fvARB)(GLint location, GLsizei count, const GLfloat * value); /* 548 */ + void (GLAPIENTRYP Uniform1iARB)(GLint location, GLint v0); /* 549 */ + void (GLAPIENTRYP Uniform1ivARB)(GLint location, GLsizei count, const GLint * value); /* 550 */ + void (GLAPIENTRYP Uniform2fARB)(GLint location, GLfloat v0, GLfloat v1); /* 551 */ + void (GLAPIENTRYP Uniform2fvARB)(GLint location, GLsizei count, const GLfloat * value); /* 552 */ + void (GLAPIENTRYP Uniform2iARB)(GLint location, GLint v0, GLint v1); /* 553 */ + void (GLAPIENTRYP Uniform2ivARB)(GLint location, GLsizei count, const GLint * value); /* 554 */ + void (GLAPIENTRYP Uniform3fARB)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2); /* 555 */ + void (GLAPIENTRYP Uniform3fvARB)(GLint location, GLsizei count, const GLfloat * value); /* 556 */ + void (GLAPIENTRYP Uniform3iARB)(GLint location, GLint v0, GLint v1, GLint v2); /* 557 */ + void (GLAPIENTRYP Uniform3ivARB)(GLint location, GLsizei count, const GLint * value); /* 558 */ + void (GLAPIENTRYP Uniform4fARB)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); /* 559 */ + void (GLAPIENTRYP Uniform4fvARB)(GLint location, GLsizei count, const GLfloat * value); /* 560 */ + void (GLAPIENTRYP Uniform4iARB)(GLint location, GLint v0, GLint v1, GLint v2, GLint v3); /* 561 */ + void (GLAPIENTRYP Uniform4ivARB)(GLint location, GLsizei count, const GLint * value); /* 562 */ + void (GLAPIENTRYP UniformMatrix2fvARB)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); /* 563 */ + void (GLAPIENTRYP UniformMatrix3fvARB)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); /* 564 */ + void (GLAPIENTRYP UniformMatrix4fvARB)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value); /* 565 */ + void (GLAPIENTRYP UseProgramObjectARB)(GLhandleARB program); /* 566 */ + void (GLAPIENTRYP ValidateProgramARB)(GLhandleARB program); /* 567 */ + void (GLAPIENTRYP BindAttribLocationARB)(GLhandleARB program, GLuint index, const GLcharARB * name); /* 568 */ + void (GLAPIENTRYP GetActiveAttribARB)(GLhandleARB program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLcharARB * name); /* 569 */ + GLint (GLAPIENTRYP GetAttribLocationARB)(GLhandleARB program, const GLcharARB * name); /* 570 */ + void (GLAPIENTRYP DrawBuffersARB)(GLsizei n, const GLenum * bufs); /* 571 */ + void (GLAPIENTRYP DrawArraysInstancedARB)(GLenum mode, GLint first, GLsizei count, GLsizei primcount); /* 572 */ + void (GLAPIENTRYP DrawElementsInstancedARB)(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices, GLsizei primcount); /* 573 */ + void (GLAPIENTRYP RenderbufferStorageMultisample)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); /* 574 */ + void (GLAPIENTRYP FramebufferTextureARB)(GLenum target, GLenum attachment, GLuint texture, GLint level); /* 575 */ + void (GLAPIENTRYP FramebufferTextureFaceARB)(GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face); /* 576 */ + void (GLAPIENTRYP ProgramParameteriARB)(GLuint program, GLenum pname, GLint value); /* 577 */ + void (GLAPIENTRYP FlushMappedBufferRange)(GLenum target, GLintptr offset, GLsizeiptr length); /* 578 */ + GLvoid * (GLAPIENTRYP MapBufferRange)(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); /* 579 */ + void (GLAPIENTRYP BindVertexArray)(GLuint array); /* 580 */ + void (GLAPIENTRYP GenVertexArrays)(GLsizei n, GLuint * arrays); /* 581 */ + void (GLAPIENTRYP CopyBufferSubData)(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); /* 582 */ + GLenum (GLAPIENTRYP ClientWaitSync)(GLsync sync, GLbitfield flags, GLuint64 timeout); /* 583 */ + void (GLAPIENTRYP DeleteSync)(GLsync sync); /* 584 */ + GLsync (GLAPIENTRYP FenceSync)(GLenum condition, GLbitfield flags); /* 585 */ + void (GLAPIENTRYP GetInteger64v)(GLenum pname, GLint64 * params); /* 586 */ + void (GLAPIENTRYP GetSynciv)(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei * length, GLint * values); /* 587 */ + GLboolean (GLAPIENTRYP IsSync)(GLsync sync); /* 588 */ + void (GLAPIENTRYP WaitSync)(GLsync sync, GLbitfield flags, GLuint64 timeout); /* 589 */ + void (GLAPIENTRYP DrawElementsBaseVertex)(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices, GLint basevertex); /* 590 */ + void (GLAPIENTRYP DrawRangeElementsBaseVertex)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid * indices, GLint basevertex); /* 591 */ + void (GLAPIENTRYP MultiDrawElementsBaseVertex)(GLenum mode, const GLsizei * count, GLenum type, const GLvoid ** indices, GLsizei primcount, const GLint * basevertex); /* 592 */ + void (GLAPIENTRYP BindTransformFeedback)(GLenum target, GLuint id); /* 593 */ + void (GLAPIENTRYP DeleteTransformFeedbacks)(GLsizei n, const GLuint * ids); /* 594 */ + void (GLAPIENTRYP DrawTransformFeedback)(GLenum mode, GLuint id); /* 595 */ + void (GLAPIENTRYP GenTransformFeedbacks)(GLsizei n, GLuint * ids); /* 596 */ + GLboolean (GLAPIENTRYP IsTransformFeedback)(GLuint id); /* 597 */ + void (GLAPIENTRYP PauseTransformFeedback)(void); /* 598 */ + void (GLAPIENTRYP ResumeTransformFeedback)(void); /* 599 */ + void (GLAPIENTRYP ClearDepthf)(GLclampf depth); /* 600 */ + void (GLAPIENTRYP DepthRangef)(GLclampf zNear, GLclampf zFar); /* 601 */ + void (GLAPIENTRYP GetShaderPrecisionFormat)(GLenum shadertype, GLenum precisiontype, GLint * range, GLint * precision); /* 602 */ + void (GLAPIENTRYP ReleaseShaderCompiler)(void); /* 603 */ + void (GLAPIENTRYP ShaderBinary)(GLsizei n, const GLuint * shaders, GLenum binaryformat, const GLvoid * binary, GLsizei length); /* 604 */ + void (GLAPIENTRYP PolygonOffsetEXT)(GLfloat factor, GLfloat bias); /* 605 */ + void (GLAPIENTRYP GetPixelTexGenParameterfvSGIS)(GLenum pname, GLfloat * params); /* 606 */ + void (GLAPIENTRYP GetPixelTexGenParameterivSGIS)(GLenum pname, GLint * params); /* 607 */ + void (GLAPIENTRYP PixelTexGenParameterfSGIS)(GLenum pname, GLfloat param); /* 608 */ + void (GLAPIENTRYP PixelTexGenParameterfvSGIS)(GLenum pname, const GLfloat * params); /* 609 */ + void (GLAPIENTRYP PixelTexGenParameteriSGIS)(GLenum pname, GLint param); /* 610 */ + void (GLAPIENTRYP PixelTexGenParameterivSGIS)(GLenum pname, const GLint * params); /* 611 */ + void (GLAPIENTRYP SampleMaskSGIS)(GLclampf value, GLboolean invert); /* 612 */ + void (GLAPIENTRYP SamplePatternSGIS)(GLenum pattern); /* 613 */ + void (GLAPIENTRYP ColorPointerEXT)(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer); /* 614 */ + void (GLAPIENTRYP EdgeFlagPointerEXT)(GLsizei stride, GLsizei count, const GLboolean * pointer); /* 615 */ + void (GLAPIENTRYP IndexPointerEXT)(GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer); /* 616 */ + void (GLAPIENTRYP NormalPointerEXT)(GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer); /* 617 */ + void (GLAPIENTRYP TexCoordPointerEXT)(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer); /* 618 */ + void (GLAPIENTRYP VertexPointerEXT)(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer); /* 619 */ + void (GLAPIENTRYP PointParameterfEXT)(GLenum pname, GLfloat param); /* 620 */ + void (GLAPIENTRYP PointParameterfvEXT)(GLenum pname, const GLfloat * params); /* 621 */ + void (GLAPIENTRYP LockArraysEXT)(GLint first, GLsizei count); /* 622 */ + void (GLAPIENTRYP UnlockArraysEXT)(void); /* 623 */ + void (GLAPIENTRYP SecondaryColor3bEXT)(GLbyte red, GLbyte green, GLbyte blue); /* 624 */ + void (GLAPIENTRYP SecondaryColor3bvEXT)(const GLbyte * v); /* 625 */ + void (GLAPIENTRYP SecondaryColor3dEXT)(GLdouble red, GLdouble green, GLdouble blue); /* 626 */ + void (GLAPIENTRYP SecondaryColor3dvEXT)(const GLdouble * v); /* 627 */ + void (GLAPIENTRYP SecondaryColor3fEXT)(GLfloat red, GLfloat green, GLfloat blue); /* 628 */ + void (GLAPIENTRYP SecondaryColor3fvEXT)(const GLfloat * v); /* 629 */ + void (GLAPIENTRYP SecondaryColor3iEXT)(GLint red, GLint green, GLint blue); /* 630 */ + void (GLAPIENTRYP SecondaryColor3ivEXT)(const GLint * v); /* 631 */ + void (GLAPIENTRYP SecondaryColor3sEXT)(GLshort red, GLshort green, GLshort blue); /* 632 */ + void (GLAPIENTRYP SecondaryColor3svEXT)(const GLshort * v); /* 633 */ + void (GLAPIENTRYP SecondaryColor3ubEXT)(GLubyte red, GLubyte green, GLubyte blue); /* 634 */ + void (GLAPIENTRYP SecondaryColor3ubvEXT)(const GLubyte * v); /* 635 */ + void (GLAPIENTRYP SecondaryColor3uiEXT)(GLuint red, GLuint green, GLuint blue); /* 636 */ + void (GLAPIENTRYP SecondaryColor3uivEXT)(const GLuint * v); /* 637 */ + void (GLAPIENTRYP SecondaryColor3usEXT)(GLushort red, GLushort green, GLushort blue); /* 638 */ + void (GLAPIENTRYP SecondaryColor3usvEXT)(const GLushort * v); /* 639 */ + void (GLAPIENTRYP SecondaryColorPointerEXT)(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer); /* 640 */ + void (GLAPIENTRYP MultiDrawArraysEXT)(GLenum mode, const GLint * first, const GLsizei * count, GLsizei primcount); /* 641 */ + void (GLAPIENTRYP MultiDrawElementsEXT)(GLenum mode, const GLsizei * count, GLenum type, const GLvoid ** indices, GLsizei primcount); /* 642 */ + void (GLAPIENTRYP FogCoordPointerEXT)(GLenum type, GLsizei stride, const GLvoid * pointer); /* 643 */ + void (GLAPIENTRYP FogCoorddEXT)(GLdouble coord); /* 644 */ + void (GLAPIENTRYP FogCoorddvEXT)(const GLdouble * coord); /* 645 */ + void (GLAPIENTRYP FogCoordfEXT)(GLfloat coord); /* 646 */ + void (GLAPIENTRYP FogCoordfvEXT)(const GLfloat * coord); /* 647 */ + void (GLAPIENTRYP PixelTexGenSGIX)(GLenum mode); /* 648 */ + void (GLAPIENTRYP BlendFuncSeparateEXT)(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); /* 649 */ + void (GLAPIENTRYP FlushVertexArrayRangeNV)(void); /* 650 */ + void (GLAPIENTRYP VertexArrayRangeNV)(GLsizei length, const GLvoid * pointer); /* 651 */ + void (GLAPIENTRYP CombinerInputNV)(GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); /* 652 */ + void (GLAPIENTRYP CombinerOutputNV)(GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum); /* 653 */ + void (GLAPIENTRYP CombinerParameterfNV)(GLenum pname, GLfloat param); /* 654 */ + void (GLAPIENTRYP CombinerParameterfvNV)(GLenum pname, const GLfloat * params); /* 655 */ + void (GLAPIENTRYP CombinerParameteriNV)(GLenum pname, GLint param); /* 656 */ + void (GLAPIENTRYP CombinerParameterivNV)(GLenum pname, const GLint * params); /* 657 */ + void (GLAPIENTRYP FinalCombinerInputNV)(GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); /* 658 */ + void (GLAPIENTRYP GetCombinerInputParameterfvNV)(GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat * params); /* 659 */ + void (GLAPIENTRYP GetCombinerInputParameterivNV)(GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint * params); /* 660 */ + void (GLAPIENTRYP GetCombinerOutputParameterfvNV)(GLenum stage, GLenum portion, GLenum pname, GLfloat * params); /* 661 */ + void (GLAPIENTRYP GetCombinerOutputParameterivNV)(GLenum stage, GLenum portion, GLenum pname, GLint * params); /* 662 */ + void (GLAPIENTRYP GetFinalCombinerInputParameterfvNV)(GLenum variable, GLenum pname, GLfloat * params); /* 663 */ + void (GLAPIENTRYP GetFinalCombinerInputParameterivNV)(GLenum variable, GLenum pname, GLint * params); /* 664 */ + void (GLAPIENTRYP ResizeBuffersMESA)(void); /* 665 */ + void (GLAPIENTRYP WindowPos2dMESA)(GLdouble x, GLdouble y); /* 666 */ + void (GLAPIENTRYP WindowPos2dvMESA)(const GLdouble * v); /* 667 */ + void (GLAPIENTRYP WindowPos2fMESA)(GLfloat x, GLfloat y); /* 668 */ + void (GLAPIENTRYP WindowPos2fvMESA)(const GLfloat * v); /* 669 */ + void (GLAPIENTRYP WindowPos2iMESA)(GLint x, GLint y); /* 670 */ + void (GLAPIENTRYP WindowPos2ivMESA)(const GLint * v); /* 671 */ + void (GLAPIENTRYP WindowPos2sMESA)(GLshort x, GLshort y); /* 672 */ + void (GLAPIENTRYP WindowPos2svMESA)(const GLshort * v); /* 673 */ + void (GLAPIENTRYP WindowPos3dMESA)(GLdouble x, GLdouble y, GLdouble z); /* 674 */ + void (GLAPIENTRYP WindowPos3dvMESA)(const GLdouble * v); /* 675 */ + void (GLAPIENTRYP WindowPos3fMESA)(GLfloat x, GLfloat y, GLfloat z); /* 676 */ + void (GLAPIENTRYP WindowPos3fvMESA)(const GLfloat * v); /* 677 */ + void (GLAPIENTRYP WindowPos3iMESA)(GLint x, GLint y, GLint z); /* 678 */ + void (GLAPIENTRYP WindowPos3ivMESA)(const GLint * v); /* 679 */ + void (GLAPIENTRYP WindowPos3sMESA)(GLshort x, GLshort y, GLshort z); /* 680 */ + void (GLAPIENTRYP WindowPos3svMESA)(const GLshort * v); /* 681 */ + void (GLAPIENTRYP WindowPos4dMESA)(GLdouble x, GLdouble y, GLdouble z, GLdouble w); /* 682 */ + void (GLAPIENTRYP WindowPos4dvMESA)(const GLdouble * v); /* 683 */ + void (GLAPIENTRYP WindowPos4fMESA)(GLfloat x, GLfloat y, GLfloat z, GLfloat w); /* 684 */ + void (GLAPIENTRYP WindowPos4fvMESA)(const GLfloat * v); /* 685 */ + void (GLAPIENTRYP WindowPos4iMESA)(GLint x, GLint y, GLint z, GLint w); /* 686 */ + void (GLAPIENTRYP WindowPos4ivMESA)(const GLint * v); /* 687 */ + void (GLAPIENTRYP WindowPos4sMESA)(GLshort x, GLshort y, GLshort z, GLshort w); /* 688 */ + void (GLAPIENTRYP WindowPos4svMESA)(const GLshort * v); /* 689 */ + void (GLAPIENTRYP MultiModeDrawArraysIBM)(const GLenum * mode, const GLint * first, const GLsizei * count, GLsizei primcount, GLint modestride); /* 690 */ + void (GLAPIENTRYP MultiModeDrawElementsIBM)(const GLenum * mode, const GLsizei * count, GLenum type, const GLvoid * const * indices, GLsizei primcount, GLint modestride); /* 691 */ + void (GLAPIENTRYP DeleteFencesNV)(GLsizei n, const GLuint * fences); /* 692 */ + void (GLAPIENTRYP FinishFenceNV)(GLuint fence); /* 693 */ + void (GLAPIENTRYP GenFencesNV)(GLsizei n, GLuint * fences); /* 694 */ + void (GLAPIENTRYP GetFenceivNV)(GLuint fence, GLenum pname, GLint * params); /* 695 */ + GLboolean (GLAPIENTRYP IsFenceNV)(GLuint fence); /* 696 */ + void (GLAPIENTRYP SetFenceNV)(GLuint fence, GLenum condition); /* 697 */ + GLboolean (GLAPIENTRYP TestFenceNV)(GLuint fence); /* 698 */ + GLboolean (GLAPIENTRYP AreProgramsResidentNV)(GLsizei n, const GLuint * ids, GLboolean * residences); /* 699 */ + void (GLAPIENTRYP BindProgramNV)(GLenum target, GLuint program); /* 700 */ + void (GLAPIENTRYP DeleteProgramsNV)(GLsizei n, const GLuint * programs); /* 701 */ + void (GLAPIENTRYP ExecuteProgramNV)(GLenum target, GLuint id, const GLfloat * params); /* 702 */ + void (GLAPIENTRYP GenProgramsNV)(GLsizei n, GLuint * programs); /* 703 */ + void (GLAPIENTRYP GetProgramParameterdvNV)(GLenum target, GLuint index, GLenum pname, GLdouble * params); /* 704 */ + void (GLAPIENTRYP GetProgramParameterfvNV)(GLenum target, GLuint index, GLenum pname, GLfloat * params); /* 705 */ + void (GLAPIENTRYP GetProgramStringNV)(GLuint id, GLenum pname, GLubyte * program); /* 706 */ + void (GLAPIENTRYP GetProgramivNV)(GLuint id, GLenum pname, GLint * params); /* 707 */ + void (GLAPIENTRYP GetTrackMatrixivNV)(GLenum target, GLuint address, GLenum pname, GLint * params); /* 708 */ + void (GLAPIENTRYP GetVertexAttribPointervNV)(GLuint index, GLenum pname, GLvoid ** pointer); /* 709 */ + void (GLAPIENTRYP GetVertexAttribdvNV)(GLuint index, GLenum pname, GLdouble * params); /* 710 */ + void (GLAPIENTRYP GetVertexAttribfvNV)(GLuint index, GLenum pname, GLfloat * params); /* 711 */ + void (GLAPIENTRYP GetVertexAttribivNV)(GLuint index, GLenum pname, GLint * params); /* 712 */ + GLboolean (GLAPIENTRYP IsProgramNV)(GLuint program); /* 713 */ + void (GLAPIENTRYP LoadProgramNV)(GLenum target, GLuint id, GLsizei len, const GLubyte * program); /* 714 */ + void (GLAPIENTRYP ProgramParameters4dvNV)(GLenum target, GLuint index, GLsizei num, const GLdouble * params); /* 715 */ + void (GLAPIENTRYP ProgramParameters4fvNV)(GLenum target, GLuint index, GLsizei num, const GLfloat * params); /* 716 */ + void (GLAPIENTRYP RequestResidentProgramsNV)(GLsizei n, const GLuint * ids); /* 717 */ + void (GLAPIENTRYP TrackMatrixNV)(GLenum target, GLuint address, GLenum matrix, GLenum transform); /* 718 */ + void (GLAPIENTRYP VertexAttrib1dNV)(GLuint index, GLdouble x); /* 719 */ + void (GLAPIENTRYP VertexAttrib1dvNV)(GLuint index, const GLdouble * v); /* 720 */ + void (GLAPIENTRYP VertexAttrib1fNV)(GLuint index, GLfloat x); /* 721 */ + void (GLAPIENTRYP VertexAttrib1fvNV)(GLuint index, const GLfloat * v); /* 722 */ + void (GLAPIENTRYP VertexAttrib1sNV)(GLuint index, GLshort x); /* 723 */ + void (GLAPIENTRYP VertexAttrib1svNV)(GLuint index, const GLshort * v); /* 724 */ + void (GLAPIENTRYP VertexAttrib2dNV)(GLuint index, GLdouble x, GLdouble y); /* 725 */ + void (GLAPIENTRYP VertexAttrib2dvNV)(GLuint index, const GLdouble * v); /* 726 */ + void (GLAPIENTRYP VertexAttrib2fNV)(GLuint index, GLfloat x, GLfloat y); /* 727 */ + void (GLAPIENTRYP VertexAttrib2fvNV)(GLuint index, const GLfloat * v); /* 728 */ + void (GLAPIENTRYP VertexAttrib2sNV)(GLuint index, GLshort x, GLshort y); /* 729 */ + void (GLAPIENTRYP VertexAttrib2svNV)(GLuint index, const GLshort * v); /* 730 */ + void (GLAPIENTRYP VertexAttrib3dNV)(GLuint index, GLdouble x, GLdouble y, GLdouble z); /* 731 */ + void (GLAPIENTRYP VertexAttrib3dvNV)(GLuint index, const GLdouble * v); /* 732 */ + void (GLAPIENTRYP VertexAttrib3fNV)(GLuint index, GLfloat x, GLfloat y, GLfloat z); /* 733 */ + void (GLAPIENTRYP VertexAttrib3fvNV)(GLuint index, const GLfloat * v); /* 734 */ + void (GLAPIENTRYP VertexAttrib3sNV)(GLuint index, GLshort x, GLshort y, GLshort z); /* 735 */ + void (GLAPIENTRYP VertexAttrib3svNV)(GLuint index, const GLshort * v); /* 736 */ + void (GLAPIENTRYP VertexAttrib4dNV)(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); /* 737 */ + void (GLAPIENTRYP VertexAttrib4dvNV)(GLuint index, const GLdouble * v); /* 738 */ + void (GLAPIENTRYP VertexAttrib4fNV)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); /* 739 */ + void (GLAPIENTRYP VertexAttrib4fvNV)(GLuint index, const GLfloat * v); /* 740 */ + void (GLAPIENTRYP VertexAttrib4sNV)(GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); /* 741 */ + void (GLAPIENTRYP VertexAttrib4svNV)(GLuint index, const GLshort * v); /* 742 */ + void (GLAPIENTRYP VertexAttrib4ubNV)(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); /* 743 */ + void (GLAPIENTRYP VertexAttrib4ubvNV)(GLuint index, const GLubyte * v); /* 744 */ + void (GLAPIENTRYP VertexAttribPointerNV)(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer); /* 745 */ + void (GLAPIENTRYP VertexAttribs1dvNV)(GLuint index, GLsizei n, const GLdouble * v); /* 746 */ + void (GLAPIENTRYP VertexAttribs1fvNV)(GLuint index, GLsizei n, const GLfloat * v); /* 747 */ + void (GLAPIENTRYP VertexAttribs1svNV)(GLuint index, GLsizei n, const GLshort * v); /* 748 */ + void (GLAPIENTRYP VertexAttribs2dvNV)(GLuint index, GLsizei n, const GLdouble * v); /* 749 */ + void (GLAPIENTRYP VertexAttribs2fvNV)(GLuint index, GLsizei n, const GLfloat * v); /* 750 */ + void (GLAPIENTRYP VertexAttribs2svNV)(GLuint index, GLsizei n, const GLshort * v); /* 751 */ + void (GLAPIENTRYP VertexAttribs3dvNV)(GLuint index, GLsizei n, const GLdouble * v); /* 752 */ + void (GLAPIENTRYP VertexAttribs3fvNV)(GLuint index, GLsizei n, const GLfloat * v); /* 753 */ + void (GLAPIENTRYP VertexAttribs3svNV)(GLuint index, GLsizei n, const GLshort * v); /* 754 */ + void (GLAPIENTRYP VertexAttribs4dvNV)(GLuint index, GLsizei n, const GLdouble * v); /* 755 */ + void (GLAPIENTRYP VertexAttribs4fvNV)(GLuint index, GLsizei n, const GLfloat * v); /* 756 */ + void (GLAPIENTRYP VertexAttribs4svNV)(GLuint index, GLsizei n, const GLshort * v); /* 757 */ + void (GLAPIENTRYP VertexAttribs4ubvNV)(GLuint index, GLsizei n, const GLubyte * v); /* 758 */ + void (GLAPIENTRYP GetTexBumpParameterfvATI)(GLenum pname, GLfloat * param); /* 759 */ + void (GLAPIENTRYP GetTexBumpParameterivATI)(GLenum pname, GLint * param); /* 760 */ + void (GLAPIENTRYP TexBumpParameterfvATI)(GLenum pname, const GLfloat * param); /* 761 */ + void (GLAPIENTRYP TexBumpParameterivATI)(GLenum pname, const GLint * param); /* 762 */ + void (GLAPIENTRYP AlphaFragmentOp1ATI)(GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); /* 763 */ + void (GLAPIENTRYP AlphaFragmentOp2ATI)(GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); /* 764 */ + void (GLAPIENTRYP AlphaFragmentOp3ATI)(GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); /* 765 */ + void (GLAPIENTRYP BeginFragmentShaderATI)(void); /* 766 */ + void (GLAPIENTRYP BindFragmentShaderATI)(GLuint id); /* 767 */ + void (GLAPIENTRYP ColorFragmentOp1ATI)(GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); /* 768 */ + void (GLAPIENTRYP ColorFragmentOp2ATI)(GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); /* 769 */ + void (GLAPIENTRYP ColorFragmentOp3ATI)(GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); /* 770 */ + void (GLAPIENTRYP DeleteFragmentShaderATI)(GLuint id); /* 771 */ + void (GLAPIENTRYP EndFragmentShaderATI)(void); /* 772 */ + GLuint (GLAPIENTRYP GenFragmentShadersATI)(GLuint range); /* 773 */ + void (GLAPIENTRYP PassTexCoordATI)(GLuint dst, GLuint coord, GLenum swizzle); /* 774 */ + void (GLAPIENTRYP SampleMapATI)(GLuint dst, GLuint interp, GLenum swizzle); /* 775 */ + void (GLAPIENTRYP SetFragmentShaderConstantATI)(GLuint dst, const GLfloat * value); /* 776 */ + void (GLAPIENTRYP PointParameteriNV)(GLenum pname, GLint param); /* 777 */ + void (GLAPIENTRYP PointParameterivNV)(GLenum pname, const GLint * params); /* 778 */ + void (GLAPIENTRYP ActiveStencilFaceEXT)(GLenum face); /* 779 */ + void (GLAPIENTRYP BindVertexArrayAPPLE)(GLuint array); /* 780 */ + void (GLAPIENTRYP DeleteVertexArraysAPPLE)(GLsizei n, const GLuint * arrays); /* 781 */ + void (GLAPIENTRYP GenVertexArraysAPPLE)(GLsizei n, GLuint * arrays); /* 782 */ + GLboolean (GLAPIENTRYP IsVertexArrayAPPLE)(GLuint array); /* 783 */ + void (GLAPIENTRYP GetProgramNamedParameterdvNV)(GLuint id, GLsizei len, const GLubyte * name, GLdouble * params); /* 784 */ + void (GLAPIENTRYP GetProgramNamedParameterfvNV)(GLuint id, GLsizei len, const GLubyte * name, GLfloat * params); /* 785 */ + void (GLAPIENTRYP ProgramNamedParameter4dNV)(GLuint id, GLsizei len, const GLubyte * name, GLdouble x, GLdouble y, GLdouble z, GLdouble w); /* 786 */ + void (GLAPIENTRYP ProgramNamedParameter4dvNV)(GLuint id, GLsizei len, const GLubyte * name, const GLdouble * v); /* 787 */ + void (GLAPIENTRYP ProgramNamedParameter4fNV)(GLuint id, GLsizei len, const GLubyte * name, GLfloat x, GLfloat y, GLfloat z, GLfloat w); /* 788 */ + void (GLAPIENTRYP ProgramNamedParameter4fvNV)(GLuint id, GLsizei len, const GLubyte * name, const GLfloat * v); /* 789 */ + void (GLAPIENTRYP PrimitiveRestartIndexNV)(GLuint index); /* 790 */ + void (GLAPIENTRYP PrimitiveRestartNV)(void); /* 791 */ + void (GLAPIENTRYP DepthBoundsEXT)(GLclampd zmin, GLclampd zmax); /* 792 */ + void (GLAPIENTRYP BlendEquationSeparateEXT)(GLenum modeRGB, GLenum modeA); /* 793 */ + void (GLAPIENTRYP BindFramebufferEXT)(GLenum target, GLuint framebuffer); /* 794 */ + void (GLAPIENTRYP BindRenderbufferEXT)(GLenum target, GLuint renderbuffer); /* 795 */ + GLenum (GLAPIENTRYP CheckFramebufferStatusEXT)(GLenum target); /* 796 */ + void (GLAPIENTRYP DeleteFramebuffersEXT)(GLsizei n, const GLuint * framebuffers); /* 797 */ + void (GLAPIENTRYP DeleteRenderbuffersEXT)(GLsizei n, const GLuint * renderbuffers); /* 798 */ + void (GLAPIENTRYP FramebufferRenderbufferEXT)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); /* 799 */ + void (GLAPIENTRYP FramebufferTexture1DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); /* 800 */ + void (GLAPIENTRYP FramebufferTexture2DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); /* 801 */ + void (GLAPIENTRYP FramebufferTexture3DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); /* 802 */ + void (GLAPIENTRYP GenFramebuffersEXT)(GLsizei n, GLuint * framebuffers); /* 803 */ + void (GLAPIENTRYP GenRenderbuffersEXT)(GLsizei n, GLuint * renderbuffers); /* 804 */ + void (GLAPIENTRYP GenerateMipmapEXT)(GLenum target); /* 805 */ + void (GLAPIENTRYP GetFramebufferAttachmentParameterivEXT)(GLenum target, GLenum attachment, GLenum pname, GLint * params); /* 806 */ + void (GLAPIENTRYP GetRenderbufferParameterivEXT)(GLenum target, GLenum pname, GLint * params); /* 807 */ + GLboolean (GLAPIENTRYP IsFramebufferEXT)(GLuint framebuffer); /* 808 */ + GLboolean (GLAPIENTRYP IsRenderbufferEXT)(GLuint renderbuffer); /* 809 */ + void (GLAPIENTRYP RenderbufferStorageEXT)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); /* 810 */ + void (GLAPIENTRYP BlitFramebufferEXT)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); /* 811 */ + void (GLAPIENTRYP BufferParameteriAPPLE)(GLenum target, GLenum pname, GLint param); /* 812 */ + void (GLAPIENTRYP FlushMappedBufferRangeAPPLE)(GLenum target, GLintptr offset, GLsizeiptr size); /* 813 */ + void (GLAPIENTRYP BindFragDataLocationEXT)(GLuint program, GLuint colorNumber, const GLchar * name); /* 814 */ + GLint (GLAPIENTRYP GetFragDataLocationEXT)(GLuint program, const GLchar * name); /* 815 */ + void (GLAPIENTRYP GetUniformuivEXT)(GLuint program, GLint location, GLuint * params); /* 816 */ + void (GLAPIENTRYP GetVertexAttribIivEXT)(GLuint index, GLenum pname, GLint * params); /* 817 */ + void (GLAPIENTRYP GetVertexAttribIuivEXT)(GLuint index, GLenum pname, GLuint * params); /* 818 */ + void (GLAPIENTRYP Uniform1uiEXT)(GLint location, GLuint x); /* 819 */ + void (GLAPIENTRYP Uniform1uivEXT)(GLint location, GLsizei count, const GLuint * value); /* 820 */ + void (GLAPIENTRYP Uniform2uiEXT)(GLint location, GLuint x, GLuint y); /* 821 */ + void (GLAPIENTRYP Uniform2uivEXT)(GLint location, GLsizei count, const GLuint * value); /* 822 */ + void (GLAPIENTRYP Uniform3uiEXT)(GLint location, GLuint x, GLuint y, GLuint z); /* 823 */ + void (GLAPIENTRYP Uniform3uivEXT)(GLint location, GLsizei count, const GLuint * value); /* 824 */ + void (GLAPIENTRYP Uniform4uiEXT)(GLint location, GLuint x, GLuint y, GLuint z, GLuint w); /* 825 */ + void (GLAPIENTRYP Uniform4uivEXT)(GLint location, GLsizei count, const GLuint * value); /* 826 */ + void (GLAPIENTRYP VertexAttribI1iEXT)(GLuint index, GLint x); /* 827 */ + void (GLAPIENTRYP VertexAttribI1ivEXT)(GLuint index, const GLint * v); /* 828 */ + void (GLAPIENTRYP VertexAttribI1uiEXT)(GLuint index, GLuint x); /* 829 */ + void (GLAPIENTRYP VertexAttribI1uivEXT)(GLuint index, const GLuint * v); /* 830 */ + void (GLAPIENTRYP VertexAttribI2iEXT)(GLuint index, GLint x, GLint y); /* 831 */ + void (GLAPIENTRYP VertexAttribI2ivEXT)(GLuint index, const GLint * v); /* 832 */ + void (GLAPIENTRYP VertexAttribI2uiEXT)(GLuint index, GLuint x, GLuint y); /* 833 */ + void (GLAPIENTRYP VertexAttribI2uivEXT)(GLuint index, const GLuint * v); /* 834 */ + void (GLAPIENTRYP VertexAttribI3iEXT)(GLuint index, GLint x, GLint y, GLint z); /* 835 */ + void (GLAPIENTRYP VertexAttribI3ivEXT)(GLuint index, const GLint * v); /* 836 */ + void (GLAPIENTRYP VertexAttribI3uiEXT)(GLuint index, GLuint x, GLuint y, GLuint z); /* 837 */ + void (GLAPIENTRYP VertexAttribI3uivEXT)(GLuint index, const GLuint * v); /* 838 */ + void (GLAPIENTRYP VertexAttribI4bvEXT)(GLuint index, const GLbyte * v); /* 839 */ + void (GLAPIENTRYP VertexAttribI4iEXT)(GLuint index, GLint x, GLint y, GLint z, GLint w); /* 840 */ + void (GLAPIENTRYP VertexAttribI4ivEXT)(GLuint index, const GLint * v); /* 841 */ + void (GLAPIENTRYP VertexAttribI4svEXT)(GLuint index, const GLshort * v); /* 842 */ + void (GLAPIENTRYP VertexAttribI4ubvEXT)(GLuint index, const GLubyte * v); /* 843 */ + void (GLAPIENTRYP VertexAttribI4uiEXT)(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); /* 844 */ + void (GLAPIENTRYP VertexAttribI4uivEXT)(GLuint index, const GLuint * v); /* 845 */ + void (GLAPIENTRYP VertexAttribI4usvEXT)(GLuint index, const GLushort * v); /* 846 */ + void (GLAPIENTRYP VertexAttribIPointerEXT)(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer); /* 847 */ + void (GLAPIENTRYP FramebufferTextureLayerEXT)(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); /* 848 */ + void (GLAPIENTRYP ColorMaskIndexedEXT)(GLuint buf, GLboolean r, GLboolean g, GLboolean b, GLboolean a); /* 849 */ + void (GLAPIENTRYP DisableIndexedEXT)(GLenum target, GLuint index); /* 850 */ + void (GLAPIENTRYP EnableIndexedEXT)(GLenum target, GLuint index); /* 851 */ + void (GLAPIENTRYP GetBooleanIndexedvEXT)(GLenum value, GLuint index, GLboolean * data); /* 852 */ + void (GLAPIENTRYP GetIntegerIndexedvEXT)(GLenum value, GLuint index, GLint * data); /* 853 */ + GLboolean (GLAPIENTRYP IsEnabledIndexedEXT)(GLenum target, GLuint index); /* 854 */ + void (GLAPIENTRYP ClearColorIiEXT)(GLint r, GLint g, GLint b, GLint a); /* 855 */ + void (GLAPIENTRYP ClearColorIuiEXT)(GLuint r, GLuint g, GLuint b, GLuint a); /* 856 */ + void (GLAPIENTRYP GetTexParameterIivEXT)(GLenum target, GLenum pname, GLint * params); /* 857 */ + void (GLAPIENTRYP GetTexParameterIuivEXT)(GLenum target, GLenum pname, GLuint * params); /* 858 */ + void (GLAPIENTRYP TexParameterIivEXT)(GLenum target, GLenum pname, const GLint * params); /* 859 */ + void (GLAPIENTRYP TexParameterIuivEXT)(GLenum target, GLenum pname, const GLuint * params); /* 860 */ + void (GLAPIENTRYP BeginConditionalRenderNV)(GLuint query, GLenum mode); /* 861 */ + void (GLAPIENTRYP EndConditionalRenderNV)(void); /* 862 */ + void (GLAPIENTRYP BeginTransformFeedbackEXT)(GLenum mode); /* 863 */ + void (GLAPIENTRYP BindBufferBaseEXT)(GLenum target, GLuint index, GLuint buffer); /* 864 */ + void (GLAPIENTRYP BindBufferOffsetEXT)(GLenum target, GLuint index, GLuint buffer, GLintptr offset); /* 865 */ + void (GLAPIENTRYP BindBufferRangeEXT)(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); /* 866 */ + void (GLAPIENTRYP EndTransformFeedbackEXT)(void); /* 867 */ + void (GLAPIENTRYP GetTransformFeedbackVaryingEXT)(GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLsizei * size, GLenum * type, GLchar * name); /* 868 */ + void (GLAPIENTRYP TransformFeedbackVaryingsEXT)(GLuint program, GLsizei count, const char ** varyings, GLenum bufferMode); /* 869 */ + void (GLAPIENTRYP ProvokingVertexEXT)(GLenum mode); /* 870 */ + void (GLAPIENTRYP GetTexParameterPointervAPPLE)(GLenum target, GLenum pname, GLvoid ** params); /* 871 */ + void (GLAPIENTRYP TextureRangeAPPLE)(GLenum target, GLsizei length, GLvoid * pointer); /* 872 */ + void (GLAPIENTRYP GetObjectParameterivAPPLE)(GLenum objectType, GLuint name, GLenum pname, GLint * value); /* 873 */ + GLenum (GLAPIENTRYP ObjectPurgeableAPPLE)(GLenum objectType, GLuint name, GLenum option); /* 874 */ + GLenum (GLAPIENTRYP ObjectUnpurgeableAPPLE)(GLenum objectType, GLuint name, GLenum option); /* 875 */ + void (GLAPIENTRYP ActiveProgramEXT)(GLuint program); /* 876 */ + GLuint (GLAPIENTRYP CreateShaderProgramEXT)(GLenum type, const GLchar * string); /* 877 */ + void (GLAPIENTRYP UseShaderProgramEXT)(GLenum type, GLuint program); /* 878 */ + void (GLAPIENTRYP StencilFuncSeparateATI)(GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); /* 879 */ + void (GLAPIENTRYP ProgramEnvParameters4fvEXT)(GLenum target, GLuint index, GLsizei count, const GLfloat * params); /* 880 */ + void (GLAPIENTRYP ProgramLocalParameters4fvEXT)(GLenum target, GLuint index, GLsizei count, const GLfloat * params); /* 881 */ + void (GLAPIENTRYP GetQueryObjecti64vEXT)(GLuint id, GLenum pname, GLint64EXT * params); /* 882 */ + void (GLAPIENTRYP GetQueryObjectui64vEXT)(GLuint id, GLenum pname, GLuint64EXT * params); /* 883 */ + void (GLAPIENTRYP EGLImageTargetRenderbufferStorageOES)(GLenum target, GLvoid * writeOffset); /* 884 */ + void (GLAPIENTRYP EGLImageTargetTexture2DOES)(GLenum target, GLvoid * writeOffset); /* 885 */ +}; + +#endif /* !defined( _GLAPI_TABLE_H_ ) */ diff --git a/src/mapi/glapi/glapitemp.h b/src/mapi/glapi/glapitemp.h new file mode 100644 index 0000000..2ccb299 --- /dev/null +++ b/src/mapi/glapi/glapitemp.h @@ -0,0 +1,7836 @@ +/* DO NOT EDIT - This file generated automatically by gl_apitemp.py (from Mesa) script */ + +/* + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * (C) Copyright IBM Corporation 2004 + * 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 + * BRIAN PAUL, IBM, + * 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. + */ + + +# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) && defined(__ELF__) +# define HIDDEN __attribute__((visibility("hidden"))) +# else +# define HIDDEN +# endif + +/* + * This file is a template which generates the OpenGL API entry point + * functions. It should be included by a .c file which first defines + * the following macros: + * KEYWORD1 - usually nothing, but might be __declspec(dllexport) on Win32 + * KEYWORD2 - usually nothing, but might be __stdcall on Win32 + * NAME(n) - builds the final function name (usually add "gl" prefix) + * DISPATCH(func, args, msg) - code to do dispatch of named function. + * msg is a printf-style debug message. + * RETURN_DISPATCH(func, args, msg) - code to do dispatch with a return value + * + * Here is an example which generates the usual OpenGL functions: + * #define KEYWORD1 + * #define KEYWORD2 + * #define NAME(func) gl##func + * #define DISPATCH(func, args, msg) \ + * struct _glapi_table *dispatch = CurrentDispatch; \ + * (*dispatch->func) args + * #define RETURN DISPATCH(func, args, msg) \ + * struct _glapi_table *dispatch = CurrentDispatch; \ + * return (*dispatch->func) args + * + */ + + +#if defined( NAME ) +#ifndef KEYWORD1 +#define KEYWORD1 +#endif + +#ifndef KEYWORD1_ALT +#define KEYWORD1_ALT HIDDEN +#endif + +#ifndef KEYWORD2 +#define KEYWORD2 +#endif + +#ifndef DISPATCH +#error DISPATCH must be defined +#endif + +#ifndef RETURN_DISPATCH +#error RETURN_DISPATCH must be defined +#endif + + +#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS + +KEYWORD1 void KEYWORD2 NAME(NewList)(GLuint list, GLenum mode) +{ + DISPATCH(NewList, (list, mode), (F, "glNewList(%d, 0x%x);\n", list, mode)); +} + +KEYWORD1 void KEYWORD2 NAME(EndList)(void) +{ + DISPATCH(EndList, (), (F, "glEndList();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(CallList)(GLuint list) +{ + DISPATCH(CallList, (list), (F, "glCallList(%d);\n", list)); +} + +KEYWORD1 void KEYWORD2 NAME(CallLists)(GLsizei n, GLenum type, const GLvoid * lists) +{ + DISPATCH(CallLists, (n, type, lists), (F, "glCallLists(%d, 0x%x, %p);\n", n, type, (const void *) lists)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteLists)(GLuint list, GLsizei range) +{ + DISPATCH(DeleteLists, (list, range), (F, "glDeleteLists(%d, %d);\n", list, range)); +} + +KEYWORD1 GLuint KEYWORD2 NAME(GenLists)(GLsizei range) +{ + RETURN_DISPATCH(GenLists, (range), (F, "glGenLists(%d);\n", range)); +} + +KEYWORD1 void KEYWORD2 NAME(ListBase)(GLuint base) +{ + DISPATCH(ListBase, (base), (F, "glListBase(%d);\n", base)); +} + +KEYWORD1 void KEYWORD2 NAME(Begin)(GLenum mode) +{ + DISPATCH(Begin, (mode), (F, "glBegin(0x%x);\n", mode)); +} + +KEYWORD1 void KEYWORD2 NAME(Bitmap)(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte * bitmap) +{ + DISPATCH(Bitmap, (width, height, xorig, yorig, xmove, ymove, bitmap), (F, "glBitmap(%d, %d, %f, %f, %f, %f, %p);\n", width, height, xorig, yorig, xmove, ymove, (const void *) bitmap)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3b)(GLbyte red, GLbyte green, GLbyte blue) +{ + DISPATCH(Color3b, (red, green, blue), (F, "glColor3b(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3bv)(const GLbyte * v) +{ + DISPATCH(Color3bv, (v), (F, "glColor3bv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3d)(GLdouble red, GLdouble green, GLdouble blue) +{ + DISPATCH(Color3d, (red, green, blue), (F, "glColor3d(%f, %f, %f);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3dv)(const GLdouble * v) +{ + DISPATCH(Color3dv, (v), (F, "glColor3dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3f)(GLfloat red, GLfloat green, GLfloat blue) +{ + DISPATCH(Color3f, (red, green, blue), (F, "glColor3f(%f, %f, %f);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3fv)(const GLfloat * v) +{ + DISPATCH(Color3fv, (v), (F, "glColor3fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3i)(GLint red, GLint green, GLint blue) +{ + DISPATCH(Color3i, (red, green, blue), (F, "glColor3i(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3iv)(const GLint * v) +{ + DISPATCH(Color3iv, (v), (F, "glColor3iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3s)(GLshort red, GLshort green, GLshort blue) +{ + DISPATCH(Color3s, (red, green, blue), (F, "glColor3s(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3sv)(const GLshort * v) +{ + DISPATCH(Color3sv, (v), (F, "glColor3sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3ub)(GLubyte red, GLubyte green, GLubyte blue) +{ + DISPATCH(Color3ub, (red, green, blue), (F, "glColor3ub(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3ubv)(const GLubyte * v) +{ + DISPATCH(Color3ubv, (v), (F, "glColor3ubv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3ui)(GLuint red, GLuint green, GLuint blue) +{ + DISPATCH(Color3ui, (red, green, blue), (F, "glColor3ui(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3uiv)(const GLuint * v) +{ + DISPATCH(Color3uiv, (v), (F, "glColor3uiv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3us)(GLushort red, GLushort green, GLushort blue) +{ + DISPATCH(Color3us, (red, green, blue), (F, "glColor3us(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(Color3usv)(const GLushort * v) +{ + DISPATCH(Color3usv, (v), (F, "glColor3usv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4b)(GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha) +{ + DISPATCH(Color4b, (red, green, blue, alpha), (F, "glColor4b(%d, %d, %d, %d);\n", red, green, blue, alpha)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4bv)(const GLbyte * v) +{ + DISPATCH(Color4bv, (v), (F, "glColor4bv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4d)(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha) +{ + DISPATCH(Color4d, (red, green, blue, alpha), (F, "glColor4d(%f, %f, %f, %f);\n", red, green, blue, alpha)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4dv)(const GLdouble * v) +{ + DISPATCH(Color4dv, (v), (F, "glColor4dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) +{ + DISPATCH(Color4f, (red, green, blue, alpha), (F, "glColor4f(%f, %f, %f, %f);\n", red, green, blue, alpha)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4fv)(const GLfloat * v) +{ + DISPATCH(Color4fv, (v), (F, "glColor4fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4i)(GLint red, GLint green, GLint blue, GLint alpha) +{ + DISPATCH(Color4i, (red, green, blue, alpha), (F, "glColor4i(%d, %d, %d, %d);\n", red, green, blue, alpha)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4iv)(const GLint * v) +{ + DISPATCH(Color4iv, (v), (F, "glColor4iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4s)(GLshort red, GLshort green, GLshort blue, GLshort alpha) +{ + DISPATCH(Color4s, (red, green, blue, alpha), (F, "glColor4s(%d, %d, %d, %d);\n", red, green, blue, alpha)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4sv)(const GLshort * v) +{ + DISPATCH(Color4sv, (v), (F, "glColor4sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) +{ + DISPATCH(Color4ub, (red, green, blue, alpha), (F, "glColor4ub(%d, %d, %d, %d);\n", red, green, blue, alpha)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4ubv)(const GLubyte * v) +{ + DISPATCH(Color4ubv, (v), (F, "glColor4ubv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4ui)(GLuint red, GLuint green, GLuint blue, GLuint alpha) +{ + DISPATCH(Color4ui, (red, green, blue, alpha), (F, "glColor4ui(%d, %d, %d, %d);\n", red, green, blue, alpha)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4uiv)(const GLuint * v) +{ + DISPATCH(Color4uiv, (v), (F, "glColor4uiv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4us)(GLushort red, GLushort green, GLushort blue, GLushort alpha) +{ + DISPATCH(Color4us, (red, green, blue, alpha), (F, "glColor4us(%d, %d, %d, %d);\n", red, green, blue, alpha)); +} + +KEYWORD1 void KEYWORD2 NAME(Color4usv)(const GLushort * v) +{ + DISPATCH(Color4usv, (v), (F, "glColor4usv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(EdgeFlag)(GLboolean flag) +{ + DISPATCH(EdgeFlag, (flag), (F, "glEdgeFlag(%d);\n", flag)); +} + +KEYWORD1 void KEYWORD2 NAME(EdgeFlagv)(const GLboolean * flag) +{ + DISPATCH(EdgeFlagv, (flag), (F, "glEdgeFlagv(%p);\n", (const void *) flag)); +} + +KEYWORD1 void KEYWORD2 NAME(End)(void) +{ + DISPATCH(End, (), (F, "glEnd();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(Indexd)(GLdouble c) +{ + DISPATCH(Indexd, (c), (F, "glIndexd(%f);\n", c)); +} + +KEYWORD1 void KEYWORD2 NAME(Indexdv)(const GLdouble * c) +{ + DISPATCH(Indexdv, (c), (F, "glIndexdv(%p);\n", (const void *) c)); +} + +KEYWORD1 void KEYWORD2 NAME(Indexf)(GLfloat c) +{ + DISPATCH(Indexf, (c), (F, "glIndexf(%f);\n", c)); +} + +KEYWORD1 void KEYWORD2 NAME(Indexfv)(const GLfloat * c) +{ + DISPATCH(Indexfv, (c), (F, "glIndexfv(%p);\n", (const void *) c)); +} + +KEYWORD1 void KEYWORD2 NAME(Indexi)(GLint c) +{ + DISPATCH(Indexi, (c), (F, "glIndexi(%d);\n", c)); +} + +KEYWORD1 void KEYWORD2 NAME(Indexiv)(const GLint * c) +{ + DISPATCH(Indexiv, (c), (F, "glIndexiv(%p);\n", (const void *) c)); +} + +KEYWORD1 void KEYWORD2 NAME(Indexs)(GLshort c) +{ + DISPATCH(Indexs, (c), (F, "glIndexs(%d);\n", c)); +} + +KEYWORD1 void KEYWORD2 NAME(Indexsv)(const GLshort * c) +{ + DISPATCH(Indexsv, (c), (F, "glIndexsv(%p);\n", (const void *) c)); +} + +KEYWORD1 void KEYWORD2 NAME(Normal3b)(GLbyte nx, GLbyte ny, GLbyte nz) +{ + DISPATCH(Normal3b, (nx, ny, nz), (F, "glNormal3b(%d, %d, %d);\n", nx, ny, nz)); +} + +KEYWORD1 void KEYWORD2 NAME(Normal3bv)(const GLbyte * v) +{ + DISPATCH(Normal3bv, (v), (F, "glNormal3bv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Normal3d)(GLdouble nx, GLdouble ny, GLdouble nz) +{ + DISPATCH(Normal3d, (nx, ny, nz), (F, "glNormal3d(%f, %f, %f);\n", nx, ny, nz)); +} + +KEYWORD1 void KEYWORD2 NAME(Normal3dv)(const GLdouble * v) +{ + DISPATCH(Normal3dv, (v), (F, "glNormal3dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Normal3f)(GLfloat nx, GLfloat ny, GLfloat nz) +{ + DISPATCH(Normal3f, (nx, ny, nz), (F, "glNormal3f(%f, %f, %f);\n", nx, ny, nz)); +} + +KEYWORD1 void KEYWORD2 NAME(Normal3fv)(const GLfloat * v) +{ + DISPATCH(Normal3fv, (v), (F, "glNormal3fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Normal3i)(GLint nx, GLint ny, GLint nz) +{ + DISPATCH(Normal3i, (nx, ny, nz), (F, "glNormal3i(%d, %d, %d);\n", nx, ny, nz)); +} + +KEYWORD1 void KEYWORD2 NAME(Normal3iv)(const GLint * v) +{ + DISPATCH(Normal3iv, (v), (F, "glNormal3iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Normal3s)(GLshort nx, GLshort ny, GLshort nz) +{ + DISPATCH(Normal3s, (nx, ny, nz), (F, "glNormal3s(%d, %d, %d);\n", nx, ny, nz)); +} + +KEYWORD1 void KEYWORD2 NAME(Normal3sv)(const GLshort * v) +{ + DISPATCH(Normal3sv, (v), (F, "glNormal3sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos2d)(GLdouble x, GLdouble y) +{ + DISPATCH(RasterPos2d, (x, y), (F, "glRasterPos2d(%f, %f);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos2dv)(const GLdouble * v) +{ + DISPATCH(RasterPos2dv, (v), (F, "glRasterPos2dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos2f)(GLfloat x, GLfloat y) +{ + DISPATCH(RasterPos2f, (x, y), (F, "glRasterPos2f(%f, %f);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos2fv)(const GLfloat * v) +{ + DISPATCH(RasterPos2fv, (v), (F, "glRasterPos2fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos2i)(GLint x, GLint y) +{ + DISPATCH(RasterPos2i, (x, y), (F, "glRasterPos2i(%d, %d);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos2iv)(const GLint * v) +{ + DISPATCH(RasterPos2iv, (v), (F, "glRasterPos2iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos2s)(GLshort x, GLshort y) +{ + DISPATCH(RasterPos2s, (x, y), (F, "glRasterPos2s(%d, %d);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos2sv)(const GLshort * v) +{ + DISPATCH(RasterPos2sv, (v), (F, "glRasterPos2sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos3d)(GLdouble x, GLdouble y, GLdouble z) +{ + DISPATCH(RasterPos3d, (x, y, z), (F, "glRasterPos3d(%f, %f, %f);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos3dv)(const GLdouble * v) +{ + DISPATCH(RasterPos3dv, (v), (F, "glRasterPos3dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos3f)(GLfloat x, GLfloat y, GLfloat z) +{ + DISPATCH(RasterPos3f, (x, y, z), (F, "glRasterPos3f(%f, %f, %f);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos3fv)(const GLfloat * v) +{ + DISPATCH(RasterPos3fv, (v), (F, "glRasterPos3fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos3i)(GLint x, GLint y, GLint z) +{ + DISPATCH(RasterPos3i, (x, y, z), (F, "glRasterPos3i(%d, %d, %d);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos3iv)(const GLint * v) +{ + DISPATCH(RasterPos3iv, (v), (F, "glRasterPos3iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos3s)(GLshort x, GLshort y, GLshort z) +{ + DISPATCH(RasterPos3s, (x, y, z), (F, "glRasterPos3s(%d, %d, %d);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos3sv)(const GLshort * v) +{ + DISPATCH(RasterPos3sv, (v), (F, "glRasterPos3sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos4d)(GLdouble x, GLdouble y, GLdouble z, GLdouble w) +{ + DISPATCH(RasterPos4d, (x, y, z, w), (F, "glRasterPos4d(%f, %f, %f, %f);\n", x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos4dv)(const GLdouble * v) +{ + DISPATCH(RasterPos4dv, (v), (F, "glRasterPos4dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + DISPATCH(RasterPos4f, (x, y, z, w), (F, "glRasterPos4f(%f, %f, %f, %f);\n", x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos4fv)(const GLfloat * v) +{ + DISPATCH(RasterPos4fv, (v), (F, "glRasterPos4fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos4i)(GLint x, GLint y, GLint z, GLint w) +{ + DISPATCH(RasterPos4i, (x, y, z, w), (F, "glRasterPos4i(%d, %d, %d, %d);\n", x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos4iv)(const GLint * v) +{ + DISPATCH(RasterPos4iv, (v), (F, "glRasterPos4iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos4s)(GLshort x, GLshort y, GLshort z, GLshort w) +{ + DISPATCH(RasterPos4s, (x, y, z, w), (F, "glRasterPos4s(%d, %d, %d, %d);\n", x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(RasterPos4sv)(const GLshort * v) +{ + DISPATCH(RasterPos4sv, (v), (F, "glRasterPos4sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Rectd)(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2) +{ + DISPATCH(Rectd, (x1, y1, x2, y2), (F, "glRectd(%f, %f, %f, %f);\n", x1, y1, x2, y2)); +} + +KEYWORD1 void KEYWORD2 NAME(Rectdv)(const GLdouble * v1, const GLdouble * v2) +{ + DISPATCH(Rectdv, (v1, v2), (F, "glRectdv(%p, %p);\n", (const void *) v1, (const void *) v2)); +} + +KEYWORD1 void KEYWORD2 NAME(Rectf)(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) +{ + DISPATCH(Rectf, (x1, y1, x2, y2), (F, "glRectf(%f, %f, %f, %f);\n", x1, y1, x2, y2)); +} + +KEYWORD1 void KEYWORD2 NAME(Rectfv)(const GLfloat * v1, const GLfloat * v2) +{ + DISPATCH(Rectfv, (v1, v2), (F, "glRectfv(%p, %p);\n", (const void *) v1, (const void *) v2)); +} + +KEYWORD1 void KEYWORD2 NAME(Recti)(GLint x1, GLint y1, GLint x2, GLint y2) +{ + DISPATCH(Recti, (x1, y1, x2, y2), (F, "glRecti(%d, %d, %d, %d);\n", x1, y1, x2, y2)); +} + +KEYWORD1 void KEYWORD2 NAME(Rectiv)(const GLint * v1, const GLint * v2) +{ + DISPATCH(Rectiv, (v1, v2), (F, "glRectiv(%p, %p);\n", (const void *) v1, (const void *) v2)); +} + +KEYWORD1 void KEYWORD2 NAME(Rects)(GLshort x1, GLshort y1, GLshort x2, GLshort y2) +{ + DISPATCH(Rects, (x1, y1, x2, y2), (F, "glRects(%d, %d, %d, %d);\n", x1, y1, x2, y2)); +} + +KEYWORD1 void KEYWORD2 NAME(Rectsv)(const GLshort * v1, const GLshort * v2) +{ + DISPATCH(Rectsv, (v1, v2), (F, "glRectsv(%p, %p);\n", (const void *) v1, (const void *) v2)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord1d)(GLdouble s) +{ + DISPATCH(TexCoord1d, (s), (F, "glTexCoord1d(%f);\n", s)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord1dv)(const GLdouble * v) +{ + DISPATCH(TexCoord1dv, (v), (F, "glTexCoord1dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord1f)(GLfloat s) +{ + DISPATCH(TexCoord1f, (s), (F, "glTexCoord1f(%f);\n", s)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord1fv)(const GLfloat * v) +{ + DISPATCH(TexCoord1fv, (v), (F, "glTexCoord1fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord1i)(GLint s) +{ + DISPATCH(TexCoord1i, (s), (F, "glTexCoord1i(%d);\n", s)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord1iv)(const GLint * v) +{ + DISPATCH(TexCoord1iv, (v), (F, "glTexCoord1iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord1s)(GLshort s) +{ + DISPATCH(TexCoord1s, (s), (F, "glTexCoord1s(%d);\n", s)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord1sv)(const GLshort * v) +{ + DISPATCH(TexCoord1sv, (v), (F, "glTexCoord1sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord2d)(GLdouble s, GLdouble t) +{ + DISPATCH(TexCoord2d, (s, t), (F, "glTexCoord2d(%f, %f);\n", s, t)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord2dv)(const GLdouble * v) +{ + DISPATCH(TexCoord2dv, (v), (F, "glTexCoord2dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord2f)(GLfloat s, GLfloat t) +{ + DISPATCH(TexCoord2f, (s, t), (F, "glTexCoord2f(%f, %f);\n", s, t)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord2fv)(const GLfloat * v) +{ + DISPATCH(TexCoord2fv, (v), (F, "glTexCoord2fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord2i)(GLint s, GLint t) +{ + DISPATCH(TexCoord2i, (s, t), (F, "glTexCoord2i(%d, %d);\n", s, t)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord2iv)(const GLint * v) +{ + DISPATCH(TexCoord2iv, (v), (F, "glTexCoord2iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord2s)(GLshort s, GLshort t) +{ + DISPATCH(TexCoord2s, (s, t), (F, "glTexCoord2s(%d, %d);\n", s, t)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord2sv)(const GLshort * v) +{ + DISPATCH(TexCoord2sv, (v), (F, "glTexCoord2sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord3d)(GLdouble s, GLdouble t, GLdouble r) +{ + DISPATCH(TexCoord3d, (s, t, r), (F, "glTexCoord3d(%f, %f, %f);\n", s, t, r)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord3dv)(const GLdouble * v) +{ + DISPATCH(TexCoord3dv, (v), (F, "glTexCoord3dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord3f)(GLfloat s, GLfloat t, GLfloat r) +{ + DISPATCH(TexCoord3f, (s, t, r), (F, "glTexCoord3f(%f, %f, %f);\n", s, t, r)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord3fv)(const GLfloat * v) +{ + DISPATCH(TexCoord3fv, (v), (F, "glTexCoord3fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord3i)(GLint s, GLint t, GLint r) +{ + DISPATCH(TexCoord3i, (s, t, r), (F, "glTexCoord3i(%d, %d, %d);\n", s, t, r)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord3iv)(const GLint * v) +{ + DISPATCH(TexCoord3iv, (v), (F, "glTexCoord3iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord3s)(GLshort s, GLshort t, GLshort r) +{ + DISPATCH(TexCoord3s, (s, t, r), (F, "glTexCoord3s(%d, %d, %d);\n", s, t, r)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord3sv)(const GLshort * v) +{ + DISPATCH(TexCoord3sv, (v), (F, "glTexCoord3sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord4d)(GLdouble s, GLdouble t, GLdouble r, GLdouble q) +{ + DISPATCH(TexCoord4d, (s, t, r, q), (F, "glTexCoord4d(%f, %f, %f, %f);\n", s, t, r, q)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord4dv)(const GLdouble * v) +{ + DISPATCH(TexCoord4dv, (v), (F, "glTexCoord4dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord4f)(GLfloat s, GLfloat t, GLfloat r, GLfloat q) +{ + DISPATCH(TexCoord4f, (s, t, r, q), (F, "glTexCoord4f(%f, %f, %f, %f);\n", s, t, r, q)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord4fv)(const GLfloat * v) +{ + DISPATCH(TexCoord4fv, (v), (F, "glTexCoord4fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord4i)(GLint s, GLint t, GLint r, GLint q) +{ + DISPATCH(TexCoord4i, (s, t, r, q), (F, "glTexCoord4i(%d, %d, %d, %d);\n", s, t, r, q)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord4iv)(const GLint * v) +{ + DISPATCH(TexCoord4iv, (v), (F, "glTexCoord4iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord4s)(GLshort s, GLshort t, GLshort r, GLshort q) +{ + DISPATCH(TexCoord4s, (s, t, r, q), (F, "glTexCoord4s(%d, %d, %d, %d);\n", s, t, r, q)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoord4sv)(const GLshort * v) +{ + DISPATCH(TexCoord4sv, (v), (F, "glTexCoord4sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex2d)(GLdouble x, GLdouble y) +{ + DISPATCH(Vertex2d, (x, y), (F, "glVertex2d(%f, %f);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex2dv)(const GLdouble * v) +{ + DISPATCH(Vertex2dv, (v), (F, "glVertex2dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex2f)(GLfloat x, GLfloat y) +{ + DISPATCH(Vertex2f, (x, y), (F, "glVertex2f(%f, %f);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex2fv)(const GLfloat * v) +{ + DISPATCH(Vertex2fv, (v), (F, "glVertex2fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex2i)(GLint x, GLint y) +{ + DISPATCH(Vertex2i, (x, y), (F, "glVertex2i(%d, %d);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex2iv)(const GLint * v) +{ + DISPATCH(Vertex2iv, (v), (F, "glVertex2iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex2s)(GLshort x, GLshort y) +{ + DISPATCH(Vertex2s, (x, y), (F, "glVertex2s(%d, %d);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex2sv)(const GLshort * v) +{ + DISPATCH(Vertex2sv, (v), (F, "glVertex2sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex3d)(GLdouble x, GLdouble y, GLdouble z) +{ + DISPATCH(Vertex3d, (x, y, z), (F, "glVertex3d(%f, %f, %f);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex3dv)(const GLdouble * v) +{ + DISPATCH(Vertex3dv, (v), (F, "glVertex3dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex3f)(GLfloat x, GLfloat y, GLfloat z) +{ + DISPATCH(Vertex3f, (x, y, z), (F, "glVertex3f(%f, %f, %f);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex3fv)(const GLfloat * v) +{ + DISPATCH(Vertex3fv, (v), (F, "glVertex3fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex3i)(GLint x, GLint y, GLint z) +{ + DISPATCH(Vertex3i, (x, y, z), (F, "glVertex3i(%d, %d, %d);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex3iv)(const GLint * v) +{ + DISPATCH(Vertex3iv, (v), (F, "glVertex3iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex3s)(GLshort x, GLshort y, GLshort z) +{ + DISPATCH(Vertex3s, (x, y, z), (F, "glVertex3s(%d, %d, %d);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex3sv)(const GLshort * v) +{ + DISPATCH(Vertex3sv, (v), (F, "glVertex3sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex4d)(GLdouble x, GLdouble y, GLdouble z, GLdouble w) +{ + DISPATCH(Vertex4d, (x, y, z, w), (F, "glVertex4d(%f, %f, %f, %f);\n", x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex4dv)(const GLdouble * v) +{ + DISPATCH(Vertex4dv, (v), (F, "glVertex4dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + DISPATCH(Vertex4f, (x, y, z, w), (F, "glVertex4f(%f, %f, %f, %f);\n", x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex4fv)(const GLfloat * v) +{ + DISPATCH(Vertex4fv, (v), (F, "glVertex4fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex4i)(GLint x, GLint y, GLint z, GLint w) +{ + DISPATCH(Vertex4i, (x, y, z, w), (F, "glVertex4i(%d, %d, %d, %d);\n", x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex4iv)(const GLint * v) +{ + DISPATCH(Vertex4iv, (v), (F, "glVertex4iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex4s)(GLshort x, GLshort y, GLshort z, GLshort w) +{ + DISPATCH(Vertex4s, (x, y, z, w), (F, "glVertex4s(%d, %d, %d, %d);\n", x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(Vertex4sv)(const GLshort * v) +{ + DISPATCH(Vertex4sv, (v), (F, "glVertex4sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(ClipPlane)(GLenum plane, const GLdouble * equation) +{ + DISPATCH(ClipPlane, (plane, equation), (F, "glClipPlane(0x%x, %p);\n", plane, (const void *) equation)); +} + +KEYWORD1 void KEYWORD2 NAME(ColorMaterial)(GLenum face, GLenum mode) +{ + DISPATCH(ColorMaterial, (face, mode), (F, "glColorMaterial(0x%x, 0x%x);\n", face, mode)); +} + +KEYWORD1 void KEYWORD2 NAME(CullFace)(GLenum mode) +{ + DISPATCH(CullFace, (mode), (F, "glCullFace(0x%x);\n", mode)); +} + +KEYWORD1 void KEYWORD2 NAME(Fogf)(GLenum pname, GLfloat param) +{ + DISPATCH(Fogf, (pname, param), (F, "glFogf(0x%x, %f);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(Fogfv)(GLenum pname, const GLfloat * params) +{ + DISPATCH(Fogfv, (pname, params), (F, "glFogfv(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(Fogi)(GLenum pname, GLint param) +{ + DISPATCH(Fogi, (pname, param), (F, "glFogi(0x%x, %d);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(Fogiv)(GLenum pname, const GLint * params) +{ + DISPATCH(Fogiv, (pname, params), (F, "glFogiv(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(FrontFace)(GLenum mode) +{ + DISPATCH(FrontFace, (mode), (F, "glFrontFace(0x%x);\n", mode)); +} + +KEYWORD1 void KEYWORD2 NAME(Hint)(GLenum target, GLenum mode) +{ + DISPATCH(Hint, (target, mode), (F, "glHint(0x%x, 0x%x);\n", target, mode)); +} + +KEYWORD1 void KEYWORD2 NAME(Lightf)(GLenum light, GLenum pname, GLfloat param) +{ + DISPATCH(Lightf, (light, pname, param), (F, "glLightf(0x%x, 0x%x, %f);\n", light, pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(Lightfv)(GLenum light, GLenum pname, const GLfloat * params) +{ + DISPATCH(Lightfv, (light, pname, params), (F, "glLightfv(0x%x, 0x%x, %p);\n", light, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(Lighti)(GLenum light, GLenum pname, GLint param) +{ + DISPATCH(Lighti, (light, pname, param), (F, "glLighti(0x%x, 0x%x, %d);\n", light, pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(Lightiv)(GLenum light, GLenum pname, const GLint * params) +{ + DISPATCH(Lightiv, (light, pname, params), (F, "glLightiv(0x%x, 0x%x, %p);\n", light, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(LightModelf)(GLenum pname, GLfloat param) +{ + DISPATCH(LightModelf, (pname, param), (F, "glLightModelf(0x%x, %f);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(LightModelfv)(GLenum pname, const GLfloat * params) +{ + DISPATCH(LightModelfv, (pname, params), (F, "glLightModelfv(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(LightModeli)(GLenum pname, GLint param) +{ + DISPATCH(LightModeli, (pname, param), (F, "glLightModeli(0x%x, %d);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(LightModeliv)(GLenum pname, const GLint * params) +{ + DISPATCH(LightModeliv, (pname, params), (F, "glLightModeliv(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(LineStipple)(GLint factor, GLushort pattern) +{ + DISPATCH(LineStipple, (factor, pattern), (F, "glLineStipple(%d, %d);\n", factor, pattern)); +} + +KEYWORD1 void KEYWORD2 NAME(LineWidth)(GLfloat width) +{ + DISPATCH(LineWidth, (width), (F, "glLineWidth(%f);\n", width)); +} + +KEYWORD1 void KEYWORD2 NAME(Materialf)(GLenum face, GLenum pname, GLfloat param) +{ + DISPATCH(Materialf, (face, pname, param), (F, "glMaterialf(0x%x, 0x%x, %f);\n", face, pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(Materialfv)(GLenum face, GLenum pname, const GLfloat * params) +{ + DISPATCH(Materialfv, (face, pname, params), (F, "glMaterialfv(0x%x, 0x%x, %p);\n", face, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(Materiali)(GLenum face, GLenum pname, GLint param) +{ + DISPATCH(Materiali, (face, pname, param), (F, "glMateriali(0x%x, 0x%x, %d);\n", face, pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(Materialiv)(GLenum face, GLenum pname, const GLint * params) +{ + DISPATCH(Materialiv, (face, pname, params), (F, "glMaterialiv(0x%x, 0x%x, %p);\n", face, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(PointSize)(GLfloat size) +{ + DISPATCH(PointSize, (size), (F, "glPointSize(%f);\n", size)); +} + +KEYWORD1 void KEYWORD2 NAME(PolygonMode)(GLenum face, GLenum mode) +{ + DISPATCH(PolygonMode, (face, mode), (F, "glPolygonMode(0x%x, 0x%x);\n", face, mode)); +} + +KEYWORD1 void KEYWORD2 NAME(PolygonStipple)(const GLubyte * mask) +{ + DISPATCH(PolygonStipple, (mask), (F, "glPolygonStipple(%p);\n", (const void *) mask)); +} + +KEYWORD1 void KEYWORD2 NAME(Scissor)(GLint x, GLint y, GLsizei width, GLsizei height) +{ + DISPATCH(Scissor, (x, y, width, height), (F, "glScissor(%d, %d, %d, %d);\n", x, y, width, height)); +} + +KEYWORD1 void KEYWORD2 NAME(ShadeModel)(GLenum mode) +{ + DISPATCH(ShadeModel, (mode), (F, "glShadeModel(0x%x);\n", mode)); +} + +KEYWORD1 void KEYWORD2 NAME(TexParameterf)(GLenum target, GLenum pname, GLfloat param) +{ + DISPATCH(TexParameterf, (target, pname, param), (F, "glTexParameterf(0x%x, 0x%x, %f);\n", target, pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(TexParameterfv)(GLenum target, GLenum pname, const GLfloat * params) +{ + DISPATCH(TexParameterfv, (target, pname, params), (F, "glTexParameterfv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(TexParameteri)(GLenum target, GLenum pname, GLint param) +{ + DISPATCH(TexParameteri, (target, pname, param), (F, "glTexParameteri(0x%x, 0x%x, %d);\n", target, pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(TexParameteriv)(GLenum target, GLenum pname, const GLint * params) +{ + DISPATCH(TexParameteriv, (target, pname, params), (F, "glTexParameteriv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(TexImage1D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid * pixels) +{ + DISPATCH(TexImage1D, (target, level, internalformat, width, border, format, type, pixels), (F, "glTexImage1D(0x%x, %d, %d, %d, %d, 0x%x, 0x%x, %p);\n", target, level, internalformat, width, border, format, type, (const void *) pixels)); +} + +KEYWORD1 void KEYWORD2 NAME(TexImage2D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * pixels) +{ + DISPATCH(TexImage2D, (target, level, internalformat, width, height, border, format, type, pixels), (F, "glTexImage2D(0x%x, %d, %d, %d, %d, %d, 0x%x, 0x%x, %p);\n", target, level, internalformat, width, height, border, format, type, (const void *) pixels)); +} + +KEYWORD1 void KEYWORD2 NAME(TexEnvf)(GLenum target, GLenum pname, GLfloat param) +{ + DISPATCH(TexEnvf, (target, pname, param), (F, "glTexEnvf(0x%x, 0x%x, %f);\n", target, pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(TexEnvfv)(GLenum target, GLenum pname, const GLfloat * params) +{ + DISPATCH(TexEnvfv, (target, pname, params), (F, "glTexEnvfv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(TexEnvi)(GLenum target, GLenum pname, GLint param) +{ + DISPATCH(TexEnvi, (target, pname, param), (F, "glTexEnvi(0x%x, 0x%x, %d);\n", target, pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(TexEnviv)(GLenum target, GLenum pname, const GLint * params) +{ + DISPATCH(TexEnviv, (target, pname, params), (F, "glTexEnviv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(TexGend)(GLenum coord, GLenum pname, GLdouble param) +{ + DISPATCH(TexGend, (coord, pname, param), (F, "glTexGend(0x%x, 0x%x, %f);\n", coord, pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(TexGendv)(GLenum coord, GLenum pname, const GLdouble * params) +{ + DISPATCH(TexGendv, (coord, pname, params), (F, "glTexGendv(0x%x, 0x%x, %p);\n", coord, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(TexGenf)(GLenum coord, GLenum pname, GLfloat param) +{ + DISPATCH(TexGenf, (coord, pname, param), (F, "glTexGenf(0x%x, 0x%x, %f);\n", coord, pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(TexGenfv)(GLenum coord, GLenum pname, const GLfloat * params) +{ + DISPATCH(TexGenfv, (coord, pname, params), (F, "glTexGenfv(0x%x, 0x%x, %p);\n", coord, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(TexGeni)(GLenum coord, GLenum pname, GLint param) +{ + DISPATCH(TexGeni, (coord, pname, param), (F, "glTexGeni(0x%x, 0x%x, %d);\n", coord, pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(TexGeniv)(GLenum coord, GLenum pname, const GLint * params) +{ + DISPATCH(TexGeniv, (coord, pname, params), (F, "glTexGeniv(0x%x, 0x%x, %p);\n", coord, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(FeedbackBuffer)(GLsizei size, GLenum type, GLfloat * buffer) +{ + DISPATCH(FeedbackBuffer, (size, type, buffer), (F, "glFeedbackBuffer(%d, 0x%x, %p);\n", size, type, (const void *) buffer)); +} + +KEYWORD1 void KEYWORD2 NAME(SelectBuffer)(GLsizei size, GLuint * buffer) +{ + DISPATCH(SelectBuffer, (size, buffer), (F, "glSelectBuffer(%d, %p);\n", size, (const void *) buffer)); +} + +KEYWORD1 GLint KEYWORD2 NAME(RenderMode)(GLenum mode) +{ + RETURN_DISPATCH(RenderMode, (mode), (F, "glRenderMode(0x%x);\n", mode)); +} + +KEYWORD1 void KEYWORD2 NAME(InitNames)(void) +{ + DISPATCH(InitNames, (), (F, "glInitNames();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(LoadName)(GLuint name) +{ + DISPATCH(LoadName, (name), (F, "glLoadName(%d);\n", name)); +} + +KEYWORD1 void KEYWORD2 NAME(PassThrough)(GLfloat token) +{ + DISPATCH(PassThrough, (token), (F, "glPassThrough(%f);\n", token)); +} + +KEYWORD1 void KEYWORD2 NAME(PopName)(void) +{ + DISPATCH(PopName, (), (F, "glPopName();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(PushName)(GLuint name) +{ + DISPATCH(PushName, (name), (F, "glPushName(%d);\n", name)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawBuffer)(GLenum mode) +{ + DISPATCH(DrawBuffer, (mode), (F, "glDrawBuffer(0x%x);\n", mode)); +} + +KEYWORD1 void KEYWORD2 NAME(Clear)(GLbitfield mask) +{ + DISPATCH(Clear, (mask), (F, "glClear(%d);\n", mask)); +} + +KEYWORD1 void KEYWORD2 NAME(ClearAccum)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) +{ + DISPATCH(ClearAccum, (red, green, blue, alpha), (F, "glClearAccum(%f, %f, %f, %f);\n", red, green, blue, alpha)); +} + +KEYWORD1 void KEYWORD2 NAME(ClearIndex)(GLfloat c) +{ + DISPATCH(ClearIndex, (c), (F, "glClearIndex(%f);\n", c)); +} + +KEYWORD1 void KEYWORD2 NAME(ClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) +{ + DISPATCH(ClearColor, (red, green, blue, alpha), (F, "glClearColor(%f, %f, %f, %f);\n", red, green, blue, alpha)); +} + +KEYWORD1 void KEYWORD2 NAME(ClearStencil)(GLint s) +{ + DISPATCH(ClearStencil, (s), (F, "glClearStencil(%d);\n", s)); +} + +KEYWORD1 void KEYWORD2 NAME(ClearDepth)(GLclampd depth) +{ + DISPATCH(ClearDepth, (depth), (F, "glClearDepth(%f);\n", depth)); +} + +KEYWORD1 void KEYWORD2 NAME(StencilMask)(GLuint mask) +{ + DISPATCH(StencilMask, (mask), (F, "glStencilMask(%d);\n", mask)); +} + +KEYWORD1 void KEYWORD2 NAME(ColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) +{ + DISPATCH(ColorMask, (red, green, blue, alpha), (F, "glColorMask(%d, %d, %d, %d);\n", red, green, blue, alpha)); +} + +KEYWORD1 void KEYWORD2 NAME(DepthMask)(GLboolean flag) +{ + DISPATCH(DepthMask, (flag), (F, "glDepthMask(%d);\n", flag)); +} + +KEYWORD1 void KEYWORD2 NAME(IndexMask)(GLuint mask) +{ + DISPATCH(IndexMask, (mask), (F, "glIndexMask(%d);\n", mask)); +} + +KEYWORD1 void KEYWORD2 NAME(Accum)(GLenum op, GLfloat value) +{ + DISPATCH(Accum, (op, value), (F, "glAccum(0x%x, %f);\n", op, value)); +} + +KEYWORD1 void KEYWORD2 NAME(Disable)(GLenum cap) +{ + DISPATCH(Disable, (cap), (F, "glDisable(0x%x);\n", cap)); +} + +KEYWORD1 void KEYWORD2 NAME(Enable)(GLenum cap) +{ + DISPATCH(Enable, (cap), (F, "glEnable(0x%x);\n", cap)); +} + +KEYWORD1 void KEYWORD2 NAME(Finish)(void) +{ + DISPATCH(Finish, (), (F, "glFinish();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(Flush)(void) +{ + DISPATCH(Flush, (), (F, "glFlush();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(PopAttrib)(void) +{ + DISPATCH(PopAttrib, (), (F, "glPopAttrib();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(PushAttrib)(GLbitfield mask) +{ + DISPATCH(PushAttrib, (mask), (F, "glPushAttrib(%d);\n", mask)); +} + +KEYWORD1 void KEYWORD2 NAME(Map1d)(GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble * points) +{ + DISPATCH(Map1d, (target, u1, u2, stride, order, points), (F, "glMap1d(0x%x, %f, %f, %d, %d, %p);\n", target, u1, u2, stride, order, (const void *) points)); +} + +KEYWORD1 void KEYWORD2 NAME(Map1f)(GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat * points) +{ + DISPATCH(Map1f, (target, u1, u2, stride, order, points), (F, "glMap1f(0x%x, %f, %f, %d, %d, %p);\n", target, u1, u2, stride, order, (const void *) points)); +} + +KEYWORD1 void KEYWORD2 NAME(Map2d)(GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble * points) +{ + DISPATCH(Map2d, (target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points), (F, "glMap2d(0x%x, %f, %f, %d, %d, %f, %f, %d, %d, %p);\n", target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, (const void *) points)); +} + +KEYWORD1 void KEYWORD2 NAME(Map2f)(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat * points) +{ + DISPATCH(Map2f, (target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points), (F, "glMap2f(0x%x, %f, %f, %d, %d, %f, %f, %d, %d, %p);\n", target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, (const void *) points)); +} + +KEYWORD1 void KEYWORD2 NAME(MapGrid1d)(GLint un, GLdouble u1, GLdouble u2) +{ + DISPATCH(MapGrid1d, (un, u1, u2), (F, "glMapGrid1d(%d, %f, %f);\n", un, u1, u2)); +} + +KEYWORD1 void KEYWORD2 NAME(MapGrid1f)(GLint un, GLfloat u1, GLfloat u2) +{ + DISPATCH(MapGrid1f, (un, u1, u2), (F, "glMapGrid1f(%d, %f, %f);\n", un, u1, u2)); +} + +KEYWORD1 void KEYWORD2 NAME(MapGrid2d)(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2) +{ + DISPATCH(MapGrid2d, (un, u1, u2, vn, v1, v2), (F, "glMapGrid2d(%d, %f, %f, %d, %f, %f);\n", un, u1, u2, vn, v1, v2)); +} + +KEYWORD1 void KEYWORD2 NAME(MapGrid2f)(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2) +{ + DISPATCH(MapGrid2f, (un, u1, u2, vn, v1, v2), (F, "glMapGrid2f(%d, %f, %f, %d, %f, %f);\n", un, u1, u2, vn, v1, v2)); +} + +KEYWORD1 void KEYWORD2 NAME(EvalCoord1d)(GLdouble u) +{ + DISPATCH(EvalCoord1d, (u), (F, "glEvalCoord1d(%f);\n", u)); +} + +KEYWORD1 void KEYWORD2 NAME(EvalCoord1dv)(const GLdouble * u) +{ + DISPATCH(EvalCoord1dv, (u), (F, "glEvalCoord1dv(%p);\n", (const void *) u)); +} + +KEYWORD1 void KEYWORD2 NAME(EvalCoord1f)(GLfloat u) +{ + DISPATCH(EvalCoord1f, (u), (F, "glEvalCoord1f(%f);\n", u)); +} + +KEYWORD1 void KEYWORD2 NAME(EvalCoord1fv)(const GLfloat * u) +{ + DISPATCH(EvalCoord1fv, (u), (F, "glEvalCoord1fv(%p);\n", (const void *) u)); +} + +KEYWORD1 void KEYWORD2 NAME(EvalCoord2d)(GLdouble u, GLdouble v) +{ + DISPATCH(EvalCoord2d, (u, v), (F, "glEvalCoord2d(%f, %f);\n", u, v)); +} + +KEYWORD1 void KEYWORD2 NAME(EvalCoord2dv)(const GLdouble * u) +{ + DISPATCH(EvalCoord2dv, (u), (F, "glEvalCoord2dv(%p);\n", (const void *) u)); +} + +KEYWORD1 void KEYWORD2 NAME(EvalCoord2f)(GLfloat u, GLfloat v) +{ + DISPATCH(EvalCoord2f, (u, v), (F, "glEvalCoord2f(%f, %f);\n", u, v)); +} + +KEYWORD1 void KEYWORD2 NAME(EvalCoord2fv)(const GLfloat * u) +{ + DISPATCH(EvalCoord2fv, (u), (F, "glEvalCoord2fv(%p);\n", (const void *) u)); +} + +KEYWORD1 void KEYWORD2 NAME(EvalMesh1)(GLenum mode, GLint i1, GLint i2) +{ + DISPATCH(EvalMesh1, (mode, i1, i2), (F, "glEvalMesh1(0x%x, %d, %d);\n", mode, i1, i2)); +} + +KEYWORD1 void KEYWORD2 NAME(EvalPoint1)(GLint i) +{ + DISPATCH(EvalPoint1, (i), (F, "glEvalPoint1(%d);\n", i)); +} + +KEYWORD1 void KEYWORD2 NAME(EvalMesh2)(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2) +{ + DISPATCH(EvalMesh2, (mode, i1, i2, j1, j2), (F, "glEvalMesh2(0x%x, %d, %d, %d, %d);\n", mode, i1, i2, j1, j2)); +} + +KEYWORD1 void KEYWORD2 NAME(EvalPoint2)(GLint i, GLint j) +{ + DISPATCH(EvalPoint2, (i, j), (F, "glEvalPoint2(%d, %d);\n", i, j)); +} + +KEYWORD1 void KEYWORD2 NAME(AlphaFunc)(GLenum func, GLclampf ref) +{ + DISPATCH(AlphaFunc, (func, ref), (F, "glAlphaFunc(0x%x, %f);\n", func, ref)); +} + +KEYWORD1 void KEYWORD2 NAME(BlendFunc)(GLenum sfactor, GLenum dfactor) +{ + DISPATCH(BlendFunc, (sfactor, dfactor), (F, "glBlendFunc(0x%x, 0x%x);\n", sfactor, dfactor)); +} + +KEYWORD1 void KEYWORD2 NAME(LogicOp)(GLenum opcode) +{ + DISPATCH(LogicOp, (opcode), (F, "glLogicOp(0x%x);\n", opcode)); +} + +KEYWORD1 void KEYWORD2 NAME(StencilFunc)(GLenum func, GLint ref, GLuint mask) +{ + DISPATCH(StencilFunc, (func, ref, mask), (F, "glStencilFunc(0x%x, %d, %d);\n", func, ref, mask)); +} + +KEYWORD1 void KEYWORD2 NAME(StencilOp)(GLenum fail, GLenum zfail, GLenum zpass) +{ + DISPATCH(StencilOp, (fail, zfail, zpass), (F, "glStencilOp(0x%x, 0x%x, 0x%x);\n", fail, zfail, zpass)); +} + +KEYWORD1 void KEYWORD2 NAME(DepthFunc)(GLenum func) +{ + DISPATCH(DepthFunc, (func), (F, "glDepthFunc(0x%x);\n", func)); +} + +KEYWORD1 void KEYWORD2 NAME(PixelZoom)(GLfloat xfactor, GLfloat yfactor) +{ + DISPATCH(PixelZoom, (xfactor, yfactor), (F, "glPixelZoom(%f, %f);\n", xfactor, yfactor)); +} + +KEYWORD1 void KEYWORD2 NAME(PixelTransferf)(GLenum pname, GLfloat param) +{ + DISPATCH(PixelTransferf, (pname, param), (F, "glPixelTransferf(0x%x, %f);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(PixelTransferi)(GLenum pname, GLint param) +{ + DISPATCH(PixelTransferi, (pname, param), (F, "glPixelTransferi(0x%x, %d);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(PixelStoref)(GLenum pname, GLfloat param) +{ + DISPATCH(PixelStoref, (pname, param), (F, "glPixelStoref(0x%x, %f);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(PixelStorei)(GLenum pname, GLint param) +{ + DISPATCH(PixelStorei, (pname, param), (F, "glPixelStorei(0x%x, %d);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(PixelMapfv)(GLenum map, GLsizei mapsize, const GLfloat * values) +{ + DISPATCH(PixelMapfv, (map, mapsize, values), (F, "glPixelMapfv(0x%x, %d, %p);\n", map, mapsize, (const void *) values)); +} + +KEYWORD1 void KEYWORD2 NAME(PixelMapuiv)(GLenum map, GLsizei mapsize, const GLuint * values) +{ + DISPATCH(PixelMapuiv, (map, mapsize, values), (F, "glPixelMapuiv(0x%x, %d, %p);\n", map, mapsize, (const void *) values)); +} + +KEYWORD1 void KEYWORD2 NAME(PixelMapusv)(GLenum map, GLsizei mapsize, const GLushort * values) +{ + DISPATCH(PixelMapusv, (map, mapsize, values), (F, "glPixelMapusv(0x%x, %d, %p);\n", map, mapsize, (const void *) values)); +} + +KEYWORD1 void KEYWORD2 NAME(ReadBuffer)(GLenum mode) +{ + DISPATCH(ReadBuffer, (mode), (F, "glReadBuffer(0x%x);\n", mode)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type) +{ + DISPATCH(CopyPixels, (x, y, width, height, type), (F, "glCopyPixels(%d, %d, %d, %d, 0x%x);\n", x, y, width, height, type)); +} + +KEYWORD1 void KEYWORD2 NAME(ReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * pixels) +{ + DISPATCH(ReadPixels, (x, y, width, height, format, type, pixels), (F, "glReadPixels(%d, %d, %d, %d, 0x%x, 0x%x, %p);\n", x, y, width, height, format, type, (const void *) pixels)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawPixels)(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * pixels) +{ + DISPATCH(DrawPixels, (width, height, format, type, pixels), (F, "glDrawPixels(%d, %d, 0x%x, 0x%x, %p);\n", width, height, format, type, (const void *) pixels)); +} + +KEYWORD1 void KEYWORD2 NAME(GetBooleanv)(GLenum pname, GLboolean * params) +{ + DISPATCH(GetBooleanv, (pname, params), (F, "glGetBooleanv(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetClipPlane)(GLenum plane, GLdouble * equation) +{ + DISPATCH(GetClipPlane, (plane, equation), (F, "glGetClipPlane(0x%x, %p);\n", plane, (const void *) equation)); +} + +KEYWORD1 void KEYWORD2 NAME(GetDoublev)(GLenum pname, GLdouble * params) +{ + DISPATCH(GetDoublev, (pname, params), (F, "glGetDoublev(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 GLenum KEYWORD2 NAME(GetError)(void) +{ + RETURN_DISPATCH(GetError, (), (F, "glGetError();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(GetFloatv)(GLenum pname, GLfloat * params) +{ + DISPATCH(GetFloatv, (pname, params), (F, "glGetFloatv(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetIntegerv)(GLenum pname, GLint * params) +{ + DISPATCH(GetIntegerv, (pname, params), (F, "glGetIntegerv(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetLightfv)(GLenum light, GLenum pname, GLfloat * params) +{ + DISPATCH(GetLightfv, (light, pname, params), (F, "glGetLightfv(0x%x, 0x%x, %p);\n", light, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetLightiv)(GLenum light, GLenum pname, GLint * params) +{ + DISPATCH(GetLightiv, (light, pname, params), (F, "glGetLightiv(0x%x, 0x%x, %p);\n", light, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetMapdv)(GLenum target, GLenum query, GLdouble * v) +{ + DISPATCH(GetMapdv, (target, query, v), (F, "glGetMapdv(0x%x, 0x%x, %p);\n", target, query, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(GetMapfv)(GLenum target, GLenum query, GLfloat * v) +{ + DISPATCH(GetMapfv, (target, query, v), (F, "glGetMapfv(0x%x, 0x%x, %p);\n", target, query, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(GetMapiv)(GLenum target, GLenum query, GLint * v) +{ + DISPATCH(GetMapiv, (target, query, v), (F, "glGetMapiv(0x%x, 0x%x, %p);\n", target, query, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(GetMaterialfv)(GLenum face, GLenum pname, GLfloat * params) +{ + DISPATCH(GetMaterialfv, (face, pname, params), (F, "glGetMaterialfv(0x%x, 0x%x, %p);\n", face, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetMaterialiv)(GLenum face, GLenum pname, GLint * params) +{ + DISPATCH(GetMaterialiv, (face, pname, params), (F, "glGetMaterialiv(0x%x, 0x%x, %p);\n", face, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetPixelMapfv)(GLenum map, GLfloat * values) +{ + DISPATCH(GetPixelMapfv, (map, values), (F, "glGetPixelMapfv(0x%x, %p);\n", map, (const void *) values)); +} + +KEYWORD1 void KEYWORD2 NAME(GetPixelMapuiv)(GLenum map, GLuint * values) +{ + DISPATCH(GetPixelMapuiv, (map, values), (F, "glGetPixelMapuiv(0x%x, %p);\n", map, (const void *) values)); +} + +KEYWORD1 void KEYWORD2 NAME(GetPixelMapusv)(GLenum map, GLushort * values) +{ + DISPATCH(GetPixelMapusv, (map, values), (F, "glGetPixelMapusv(0x%x, %p);\n", map, (const void *) values)); +} + +KEYWORD1 void KEYWORD2 NAME(GetPolygonStipple)(GLubyte * mask) +{ + DISPATCH(GetPolygonStipple, (mask), (F, "glGetPolygonStipple(%p);\n", (const void *) mask)); +} + +KEYWORD1 const GLubyte * KEYWORD2 NAME(GetString)(GLenum name) +{ + RETURN_DISPATCH(GetString, (name), (F, "glGetString(0x%x);\n", name)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexEnvfv)(GLenum target, GLenum pname, GLfloat * params) +{ + DISPATCH(GetTexEnvfv, (target, pname, params), (F, "glGetTexEnvfv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexEnviv)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetTexEnviv, (target, pname, params), (F, "glGetTexEnviv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexGendv)(GLenum coord, GLenum pname, GLdouble * params) +{ + DISPATCH(GetTexGendv, (coord, pname, params), (F, "glGetTexGendv(0x%x, 0x%x, %p);\n", coord, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexGenfv)(GLenum coord, GLenum pname, GLfloat * params) +{ + DISPATCH(GetTexGenfv, (coord, pname, params), (F, "glGetTexGenfv(0x%x, 0x%x, %p);\n", coord, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexGeniv)(GLenum coord, GLenum pname, GLint * params) +{ + DISPATCH(GetTexGeniv, (coord, pname, params), (F, "glGetTexGeniv(0x%x, 0x%x, %p);\n", coord, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexImage)(GLenum target, GLint level, GLenum format, GLenum type, GLvoid * pixels) +{ + DISPATCH(GetTexImage, (target, level, format, type, pixels), (F, "glGetTexImage(0x%x, %d, 0x%x, 0x%x, %p);\n", target, level, format, type, (const void *) pixels)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexParameterfv)(GLenum target, GLenum pname, GLfloat * params) +{ + DISPATCH(GetTexParameterfv, (target, pname, params), (F, "glGetTexParameterfv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexParameteriv)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetTexParameteriv, (target, pname, params), (F, "glGetTexParameteriv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexLevelParameterfv)(GLenum target, GLint level, GLenum pname, GLfloat * params) +{ + DISPATCH(GetTexLevelParameterfv, (target, level, pname, params), (F, "glGetTexLevelParameterfv(0x%x, %d, 0x%x, %p);\n", target, level, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexLevelParameteriv)(GLenum target, GLint level, GLenum pname, GLint * params) +{ + DISPATCH(GetTexLevelParameteriv, (target, level, pname, params), (F, "glGetTexLevelParameteriv(0x%x, %d, 0x%x, %p);\n", target, level, pname, (const void *) params)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsEnabled)(GLenum cap) +{ + RETURN_DISPATCH(IsEnabled, (cap), (F, "glIsEnabled(0x%x);\n", cap)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsList)(GLuint list) +{ + RETURN_DISPATCH(IsList, (list), (F, "glIsList(%d);\n", list)); +} + +KEYWORD1 void KEYWORD2 NAME(DepthRange)(GLclampd zNear, GLclampd zFar) +{ + DISPATCH(DepthRange, (zNear, zFar), (F, "glDepthRange(%f, %f);\n", zNear, zFar)); +} + +KEYWORD1 void KEYWORD2 NAME(Frustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar) +{ + DISPATCH(Frustum, (left, right, bottom, top, zNear, zFar), (F, "glFrustum(%f, %f, %f, %f, %f, %f);\n", left, right, bottom, top, zNear, zFar)); +} + +KEYWORD1 void KEYWORD2 NAME(LoadIdentity)(void) +{ + DISPATCH(LoadIdentity, (), (F, "glLoadIdentity();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(LoadMatrixf)(const GLfloat * m) +{ + DISPATCH(LoadMatrixf, (m), (F, "glLoadMatrixf(%p);\n", (const void *) m)); +} + +KEYWORD1 void KEYWORD2 NAME(LoadMatrixd)(const GLdouble * m) +{ + DISPATCH(LoadMatrixd, (m), (F, "glLoadMatrixd(%p);\n", (const void *) m)); +} + +KEYWORD1 void KEYWORD2 NAME(MatrixMode)(GLenum mode) +{ + DISPATCH(MatrixMode, (mode), (F, "glMatrixMode(0x%x);\n", mode)); +} + +KEYWORD1 void KEYWORD2 NAME(MultMatrixf)(const GLfloat * m) +{ + DISPATCH(MultMatrixf, (m), (F, "glMultMatrixf(%p);\n", (const void *) m)); +} + +KEYWORD1 void KEYWORD2 NAME(MultMatrixd)(const GLdouble * m) +{ + DISPATCH(MultMatrixd, (m), (F, "glMultMatrixd(%p);\n", (const void *) m)); +} + +KEYWORD1 void KEYWORD2 NAME(Ortho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar) +{ + DISPATCH(Ortho, (left, right, bottom, top, zNear, zFar), (F, "glOrtho(%f, %f, %f, %f, %f, %f);\n", left, right, bottom, top, zNear, zFar)); +} + +KEYWORD1 void KEYWORD2 NAME(PopMatrix)(void) +{ + DISPATCH(PopMatrix, (), (F, "glPopMatrix();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(PushMatrix)(void) +{ + DISPATCH(PushMatrix, (), (F, "glPushMatrix();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(Rotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) +{ + DISPATCH(Rotated, (angle, x, y, z), (F, "glRotated(%f, %f, %f, %f);\n", angle, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(Rotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) +{ + DISPATCH(Rotatef, (angle, x, y, z), (F, "glRotatef(%f, %f, %f, %f);\n", angle, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(Scaled)(GLdouble x, GLdouble y, GLdouble z) +{ + DISPATCH(Scaled, (x, y, z), (F, "glScaled(%f, %f, %f);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(Scalef)(GLfloat x, GLfloat y, GLfloat z) +{ + DISPATCH(Scalef, (x, y, z), (F, "glScalef(%f, %f, %f);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(Translated)(GLdouble x, GLdouble y, GLdouble z) +{ + DISPATCH(Translated, (x, y, z), (F, "glTranslated(%f, %f, %f);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(Translatef)(GLfloat x, GLfloat y, GLfloat z) +{ + DISPATCH(Translatef, (x, y, z), (F, "glTranslatef(%f, %f, %f);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(Viewport)(GLint x, GLint y, GLsizei width, GLsizei height) +{ + DISPATCH(Viewport, (x, y, width, height), (F, "glViewport(%d, %d, %d, %d);\n", x, y, width, height)); +} + +KEYWORD1 void KEYWORD2 NAME(ArrayElement)(GLint i) +{ + DISPATCH(ArrayElement, (i), (F, "glArrayElement(%d);\n", i)); +} + +KEYWORD1 void KEYWORD2 NAME(ArrayElementEXT)(GLint i) +{ + DISPATCH(ArrayElement, (i), (F, "glArrayElementEXT(%d);\n", i)); +} + +KEYWORD1 void KEYWORD2 NAME(BindTexture)(GLenum target, GLuint texture) +{ + DISPATCH(BindTexture, (target, texture), (F, "glBindTexture(0x%x, %d);\n", target, texture)); +} + +KEYWORD1 void KEYWORD2 NAME(BindTextureEXT)(GLenum target, GLuint texture) +{ + DISPATCH(BindTexture, (target, texture), (F, "glBindTextureEXT(0x%x, %d);\n", target, texture)); +} + +KEYWORD1 void KEYWORD2 NAME(ColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(ColorPointer, (size, type, stride, pointer), (F, "glColorPointer(%d, 0x%x, %d, %p);\n", size, type, stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(DisableClientState)(GLenum array) +{ + DISPATCH(DisableClientState, (array), (F, "glDisableClientState(0x%x);\n", array)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawArrays)(GLenum mode, GLint first, GLsizei count) +{ + DISPATCH(DrawArrays, (mode, first, count), (F, "glDrawArrays(0x%x, %d, %d);\n", mode, first, count)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawArraysEXT)(GLenum mode, GLint first, GLsizei count) +{ + DISPATCH(DrawArrays, (mode, first, count), (F, "glDrawArraysEXT(0x%x, %d, %d);\n", mode, first, count)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices) +{ + DISPATCH(DrawElements, (mode, count, type, indices), (F, "glDrawElements(0x%x, %d, 0x%x, %p);\n", mode, count, type, (const void *) indices)); +} + +KEYWORD1 void KEYWORD2 NAME(EdgeFlagPointer)(GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(EdgeFlagPointer, (stride, pointer), (F, "glEdgeFlagPointer(%d, %p);\n", stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(EnableClientState)(GLenum array) +{ + DISPATCH(EnableClientState, (array), (F, "glEnableClientState(0x%x);\n", array)); +} + +KEYWORD1 void KEYWORD2 NAME(IndexPointer)(GLenum type, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(IndexPointer, (type, stride, pointer), (F, "glIndexPointer(0x%x, %d, %p);\n", type, stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(Indexub)(GLubyte c) +{ + DISPATCH(Indexub, (c), (F, "glIndexub(%d);\n", c)); +} + +KEYWORD1 void KEYWORD2 NAME(Indexubv)(const GLubyte * c) +{ + DISPATCH(Indexubv, (c), (F, "glIndexubv(%p);\n", (const void *) c)); +} + +KEYWORD1 void KEYWORD2 NAME(InterleavedArrays)(GLenum format, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(InterleavedArrays, (format, stride, pointer), (F, "glInterleavedArrays(0x%x, %d, %p);\n", format, stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(NormalPointer)(GLenum type, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(NormalPointer, (type, stride, pointer), (F, "glNormalPointer(0x%x, %d, %p);\n", type, stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(PolygonOffset)(GLfloat factor, GLfloat units) +{ + DISPATCH(PolygonOffset, (factor, units), (F, "glPolygonOffset(%f, %f);\n", factor, units)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(TexCoordPointer, (size, type, stride, pointer), (F, "glTexCoordPointer(%d, 0x%x, %d, %p);\n", size, type, stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(VertexPointer, (size, type, stride, pointer), (F, "glVertexPointer(%d, 0x%x, %d, %p);\n", size, type, stride, (const void *) pointer)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(AreTexturesResident)(GLsizei n, const GLuint * textures, GLboolean * residences) +{ + RETURN_DISPATCH(AreTexturesResident, (n, textures, residences), (F, "glAreTexturesResident(%d, %p, %p);\n", n, (const void *) textures, (const void *) residences)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyTexImage1D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border) +{ + DISPATCH(CopyTexImage1D, (target, level, internalformat, x, y, width, border), (F, "glCopyTexImage1D(0x%x, %d, 0x%x, %d, %d, %d, %d);\n", target, level, internalformat, x, y, width, border)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyTexImage1DEXT)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border) +{ + DISPATCH(CopyTexImage1D, (target, level, internalformat, x, y, width, border), (F, "glCopyTexImage1DEXT(0x%x, %d, 0x%x, %d, %d, %d, %d);\n", target, level, internalformat, x, y, width, border)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) +{ + DISPATCH(CopyTexImage2D, (target, level, internalformat, x, y, width, height, border), (F, "glCopyTexImage2D(0x%x, %d, 0x%x, %d, %d, %d, %d, %d);\n", target, level, internalformat, x, y, width, height, border)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyTexImage2DEXT)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) +{ + DISPATCH(CopyTexImage2D, (target, level, internalformat, x, y, width, height, border), (F, "glCopyTexImage2DEXT(0x%x, %d, 0x%x, %d, %d, %d, %d, %d);\n", target, level, internalformat, x, y, width, height, border)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width) +{ + DISPATCH(CopyTexSubImage1D, (target, level, xoffset, x, y, width), (F, "glCopyTexSubImage1D(0x%x, %d, %d, %d, %d, %d);\n", target, level, xoffset, x, y, width)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyTexSubImage1DEXT)(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width) +{ + DISPATCH(CopyTexSubImage1D, (target, level, xoffset, x, y, width), (F, "glCopyTexSubImage1DEXT(0x%x, %d, %d, %d, %d, %d);\n", target, level, xoffset, x, y, width)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) +{ + DISPATCH(CopyTexSubImage2D, (target, level, xoffset, yoffset, x, y, width, height), (F, "glCopyTexSubImage2D(0x%x, %d, %d, %d, %d, %d, %d, %d);\n", target, level, xoffset, yoffset, x, y, width, height)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyTexSubImage2DEXT)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) +{ + DISPATCH(CopyTexSubImage2D, (target, level, xoffset, yoffset, x, y, width, height), (F, "glCopyTexSubImage2DEXT(0x%x, %d, %d, %d, %d, %d, %d, %d);\n", target, level, xoffset, yoffset, x, y, width, height)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteTextures)(GLsizei n, const GLuint * textures) +{ + DISPATCH(DeleteTextures, (n, textures), (F, "glDeleteTextures(%d, %p);\n", n, (const void *) textures)); +} + +KEYWORD1 void KEYWORD2 NAME(GenTextures)(GLsizei n, GLuint * textures) +{ + DISPATCH(GenTextures, (n, textures), (F, "glGenTextures(%d, %p);\n", n, (const void *) textures)); +} + +KEYWORD1 void KEYWORD2 NAME(GetPointerv)(GLenum pname, GLvoid ** params) +{ + DISPATCH(GetPointerv, (pname, params), (F, "glGetPointerv(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetPointervEXT)(GLenum pname, GLvoid ** params) +{ + DISPATCH(GetPointerv, (pname, params), (F, "glGetPointervEXT(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsTexture)(GLuint texture) +{ + RETURN_DISPATCH(IsTexture, (texture), (F, "glIsTexture(%d);\n", texture)); +} + +KEYWORD1 void KEYWORD2 NAME(PrioritizeTextures)(GLsizei n, const GLuint * textures, const GLclampf * priorities) +{ + DISPATCH(PrioritizeTextures, (n, textures, priorities), (F, "glPrioritizeTextures(%d, %p, %p);\n", n, (const void *) textures, (const void *) priorities)); +} + +KEYWORD1 void KEYWORD2 NAME(PrioritizeTexturesEXT)(GLsizei n, const GLuint * textures, const GLclampf * priorities) +{ + DISPATCH(PrioritizeTextures, (n, textures, priorities), (F, "glPrioritizeTexturesEXT(%d, %p, %p);\n", n, (const void *) textures, (const void *) priorities)); +} + +KEYWORD1 void KEYWORD2 NAME(TexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid * pixels) +{ + DISPATCH(TexSubImage1D, (target, level, xoffset, width, format, type, pixels), (F, "glTexSubImage1D(0x%x, %d, %d, %d, 0x%x, 0x%x, %p);\n", target, level, xoffset, width, format, type, (const void *) pixels)); +} + +KEYWORD1 void KEYWORD2 NAME(TexSubImage1DEXT)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid * pixels) +{ + DISPATCH(TexSubImage1D, (target, level, xoffset, width, format, type, pixels), (F, "glTexSubImage1DEXT(0x%x, %d, %d, %d, 0x%x, 0x%x, %p);\n", target, level, xoffset, width, format, type, (const void *) pixels)); +} + +KEYWORD1 void KEYWORD2 NAME(TexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * pixels) +{ + DISPATCH(TexSubImage2D, (target, level, xoffset, yoffset, width, height, format, type, pixels), (F, "glTexSubImage2D(0x%x, %d, %d, %d, %d, %d, 0x%x, 0x%x, %p);\n", target, level, xoffset, yoffset, width, height, format, type, (const void *) pixels)); +} + +KEYWORD1 void KEYWORD2 NAME(TexSubImage2DEXT)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * pixels) +{ + DISPATCH(TexSubImage2D, (target, level, xoffset, yoffset, width, height, format, type, pixels), (F, "glTexSubImage2DEXT(0x%x, %d, %d, %d, %d, %d, 0x%x, 0x%x, %p);\n", target, level, xoffset, yoffset, width, height, format, type, (const void *) pixels)); +} + +KEYWORD1 void KEYWORD2 NAME(PopClientAttrib)(void) +{ + DISPATCH(PopClientAttrib, (), (F, "glPopClientAttrib();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(PushClientAttrib)(GLbitfield mask) +{ + DISPATCH(PushClientAttrib, (mask), (F, "glPushClientAttrib(%d);\n", mask)); +} + +KEYWORD1 void KEYWORD2 NAME(BlendColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) +{ + DISPATCH(BlendColor, (red, green, blue, alpha), (F, "glBlendColor(%f, %f, %f, %f);\n", red, green, blue, alpha)); +} + +KEYWORD1 void KEYWORD2 NAME(BlendColorEXT)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) +{ + DISPATCH(BlendColor, (red, green, blue, alpha), (F, "glBlendColorEXT(%f, %f, %f, %f);\n", red, green, blue, alpha)); +} + +KEYWORD1 void KEYWORD2 NAME(BlendEquation)(GLenum mode) +{ + DISPATCH(BlendEquation, (mode), (F, "glBlendEquation(0x%x);\n", mode)); +} + +KEYWORD1 void KEYWORD2 NAME(BlendEquationEXT)(GLenum mode) +{ + DISPATCH(BlendEquation, (mode), (F, "glBlendEquationEXT(0x%x);\n", mode)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid * indices) +{ + DISPATCH(DrawRangeElements, (mode, start, end, count, type, indices), (F, "glDrawRangeElements(0x%x, %d, %d, %d, 0x%x, %p);\n", mode, start, end, count, type, (const void *) indices)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawRangeElementsEXT)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid * indices) +{ + DISPATCH(DrawRangeElements, (mode, start, end, count, type, indices), (F, "glDrawRangeElementsEXT(0x%x, %d, %d, %d, 0x%x, %p);\n", mode, start, end, count, type, (const void *) indices)); +} + +KEYWORD1 void KEYWORD2 NAME(ColorTable)(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid * table) +{ + DISPATCH(ColorTable, (target, internalformat, width, format, type, table), (F, "glColorTable(0x%x, 0x%x, %d, 0x%x, 0x%x, %p);\n", target, internalformat, width, format, type, (const void *) table)); +} + +KEYWORD1 void KEYWORD2 NAME(ColorTableEXT)(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid * table) +{ + DISPATCH(ColorTable, (target, internalformat, width, format, type, table), (F, "glColorTableEXT(0x%x, 0x%x, %d, 0x%x, 0x%x, %p);\n", target, internalformat, width, format, type, (const void *) table)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_339)(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid * table); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_339)(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid * table) +{ + DISPATCH(ColorTable, (target, internalformat, width, format, type, table), (F, "glColorTableSGI(0x%x, 0x%x, %d, 0x%x, 0x%x, %p);\n", target, internalformat, width, format, type, (const void *) table)); +} + +KEYWORD1 void KEYWORD2 NAME(ColorTableParameterfv)(GLenum target, GLenum pname, const GLfloat * params) +{ + DISPATCH(ColorTableParameterfv, (target, pname, params), (F, "glColorTableParameterfv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_340)(GLenum target, GLenum pname, const GLfloat * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_340)(GLenum target, GLenum pname, const GLfloat * params) +{ + DISPATCH(ColorTableParameterfv, (target, pname, params), (F, "glColorTableParameterfvSGI(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(ColorTableParameteriv)(GLenum target, GLenum pname, const GLint * params) +{ + DISPATCH(ColorTableParameteriv, (target, pname, params), (F, "glColorTableParameteriv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_341)(GLenum target, GLenum pname, const GLint * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_341)(GLenum target, GLenum pname, const GLint * params) +{ + DISPATCH(ColorTableParameteriv, (target, pname, params), (F, "glColorTableParameterivSGI(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyColorTable)(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width) +{ + DISPATCH(CopyColorTable, (target, internalformat, x, y, width), (F, "glCopyColorTable(0x%x, 0x%x, %d, %d, %d);\n", target, internalformat, x, y, width)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_342)(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_342)(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width) +{ + DISPATCH(CopyColorTable, (target, internalformat, x, y, width), (F, "glCopyColorTableSGI(0x%x, 0x%x, %d, %d, %d);\n", target, internalformat, x, y, width)); +} + +KEYWORD1 void KEYWORD2 NAME(GetColorTable)(GLenum target, GLenum format, GLenum type, GLvoid * table) +{ + DISPATCH(GetColorTable, (target, format, type, table), (F, "glGetColorTable(0x%x, 0x%x, 0x%x, %p);\n", target, format, type, (const void *) table)); +} + +KEYWORD1 void KEYWORD2 NAME(GetColorTableParameterfv)(GLenum target, GLenum pname, GLfloat * params) +{ + DISPATCH(GetColorTableParameterfv, (target, pname, params), (F, "glGetColorTableParameterfv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetColorTableParameteriv)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetColorTableParameteriv, (target, pname, params), (F, "glGetColorTableParameteriv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(ColorSubTable)(GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid * data) +{ + DISPATCH(ColorSubTable, (target, start, count, format, type, data), (F, "glColorSubTable(0x%x, %d, %d, 0x%x, 0x%x, %p);\n", target, start, count, format, type, (const void *) data)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_346)(GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid * data); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_346)(GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid * data) +{ + DISPATCH(ColorSubTable, (target, start, count, format, type, data), (F, "glColorSubTableEXT(0x%x, %d, %d, 0x%x, 0x%x, %p);\n", target, start, count, format, type, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyColorSubTable)(GLenum target, GLsizei start, GLint x, GLint y, GLsizei width) +{ + DISPATCH(CopyColorSubTable, (target, start, x, y, width), (F, "glCopyColorSubTable(0x%x, %d, %d, %d, %d);\n", target, start, x, y, width)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_347)(GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_347)(GLenum target, GLsizei start, GLint x, GLint y, GLsizei width) +{ + DISPATCH(CopyColorSubTable, (target, start, x, y, width), (F, "glCopyColorSubTableEXT(0x%x, %d, %d, %d, %d);\n", target, start, x, y, width)); +} + +KEYWORD1 void KEYWORD2 NAME(ConvolutionFilter1D)(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid * image) +{ + DISPATCH(ConvolutionFilter1D, (target, internalformat, width, format, type, image), (F, "glConvolutionFilter1D(0x%x, 0x%x, %d, 0x%x, 0x%x, %p);\n", target, internalformat, width, format, type, (const void *) image)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_348)(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid * image); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_348)(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid * image) +{ + DISPATCH(ConvolutionFilter1D, (target, internalformat, width, format, type, image), (F, "glConvolutionFilter1DEXT(0x%x, 0x%x, %d, 0x%x, 0x%x, %p);\n", target, internalformat, width, format, type, (const void *) image)); +} + +KEYWORD1 void KEYWORD2 NAME(ConvolutionFilter2D)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * image) +{ + DISPATCH(ConvolutionFilter2D, (target, internalformat, width, height, format, type, image), (F, "glConvolutionFilter2D(0x%x, 0x%x, %d, %d, 0x%x, 0x%x, %p);\n", target, internalformat, width, height, format, type, (const void *) image)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_349)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * image); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_349)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * image) +{ + DISPATCH(ConvolutionFilter2D, (target, internalformat, width, height, format, type, image), (F, "glConvolutionFilter2DEXT(0x%x, 0x%x, %d, %d, 0x%x, 0x%x, %p);\n", target, internalformat, width, height, format, type, (const void *) image)); +} + +KEYWORD1 void KEYWORD2 NAME(ConvolutionParameterf)(GLenum target, GLenum pname, GLfloat params) +{ + DISPATCH(ConvolutionParameterf, (target, pname, params), (F, "glConvolutionParameterf(0x%x, 0x%x, %f);\n", target, pname, params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_350)(GLenum target, GLenum pname, GLfloat params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_350)(GLenum target, GLenum pname, GLfloat params) +{ + DISPATCH(ConvolutionParameterf, (target, pname, params), (F, "glConvolutionParameterfEXT(0x%x, 0x%x, %f);\n", target, pname, params)); +} + +KEYWORD1 void KEYWORD2 NAME(ConvolutionParameterfv)(GLenum target, GLenum pname, const GLfloat * params) +{ + DISPATCH(ConvolutionParameterfv, (target, pname, params), (F, "glConvolutionParameterfv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_351)(GLenum target, GLenum pname, const GLfloat * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_351)(GLenum target, GLenum pname, const GLfloat * params) +{ + DISPATCH(ConvolutionParameterfv, (target, pname, params), (F, "glConvolutionParameterfvEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(ConvolutionParameteri)(GLenum target, GLenum pname, GLint params) +{ + DISPATCH(ConvolutionParameteri, (target, pname, params), (F, "glConvolutionParameteri(0x%x, 0x%x, %d);\n", target, pname, params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_352)(GLenum target, GLenum pname, GLint params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_352)(GLenum target, GLenum pname, GLint params) +{ + DISPATCH(ConvolutionParameteri, (target, pname, params), (F, "glConvolutionParameteriEXT(0x%x, 0x%x, %d);\n", target, pname, params)); +} + +KEYWORD1 void KEYWORD2 NAME(ConvolutionParameteriv)(GLenum target, GLenum pname, const GLint * params) +{ + DISPATCH(ConvolutionParameteriv, (target, pname, params), (F, "glConvolutionParameteriv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_353)(GLenum target, GLenum pname, const GLint * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_353)(GLenum target, GLenum pname, const GLint * params) +{ + DISPATCH(ConvolutionParameteriv, (target, pname, params), (F, "glConvolutionParameterivEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyConvolutionFilter1D)(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width) +{ + DISPATCH(CopyConvolutionFilter1D, (target, internalformat, x, y, width), (F, "glCopyConvolutionFilter1D(0x%x, 0x%x, %d, %d, %d);\n", target, internalformat, x, y, width)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_354)(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_354)(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width) +{ + DISPATCH(CopyConvolutionFilter1D, (target, internalformat, x, y, width), (F, "glCopyConvolutionFilter1DEXT(0x%x, 0x%x, %d, %d, %d);\n", target, internalformat, x, y, width)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyConvolutionFilter2D)(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height) +{ + DISPATCH(CopyConvolutionFilter2D, (target, internalformat, x, y, width, height), (F, "glCopyConvolutionFilter2D(0x%x, 0x%x, %d, %d, %d, %d);\n", target, internalformat, x, y, width, height)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_355)(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_355)(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height) +{ + DISPATCH(CopyConvolutionFilter2D, (target, internalformat, x, y, width, height), (F, "glCopyConvolutionFilter2DEXT(0x%x, 0x%x, %d, %d, %d, %d);\n", target, internalformat, x, y, width, height)); +} + +KEYWORD1 void KEYWORD2 NAME(GetConvolutionFilter)(GLenum target, GLenum format, GLenum type, GLvoid * image) +{ + DISPATCH(GetConvolutionFilter, (target, format, type, image), (F, "glGetConvolutionFilter(0x%x, 0x%x, 0x%x, %p);\n", target, format, type, (const void *) image)); +} + +KEYWORD1 void KEYWORD2 NAME(GetConvolutionParameterfv)(GLenum target, GLenum pname, GLfloat * params) +{ + DISPATCH(GetConvolutionParameterfv, (target, pname, params), (F, "glGetConvolutionParameterfv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetConvolutionParameteriv)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetConvolutionParameteriv, (target, pname, params), (F, "glGetConvolutionParameteriv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetSeparableFilter)(GLenum target, GLenum format, GLenum type, GLvoid * row, GLvoid * column, GLvoid * span) +{ + DISPATCH(GetSeparableFilter, (target, format, type, row, column, span), (F, "glGetSeparableFilter(0x%x, 0x%x, 0x%x, %p, %p, %p);\n", target, format, type, (const void *) row, (const void *) column, (const void *) span)); +} + +KEYWORD1 void KEYWORD2 NAME(SeparableFilter2D)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * row, const GLvoid * column) +{ + DISPATCH(SeparableFilter2D, (target, internalformat, width, height, format, type, row, column), (F, "glSeparableFilter2D(0x%x, 0x%x, %d, %d, 0x%x, 0x%x, %p, %p);\n", target, internalformat, width, height, format, type, (const void *) row, (const void *) column)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_360)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * row, const GLvoid * column); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_360)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * row, const GLvoid * column) +{ + DISPATCH(SeparableFilter2D, (target, internalformat, width, height, format, type, row, column), (F, "glSeparableFilter2DEXT(0x%x, 0x%x, %d, %d, 0x%x, 0x%x, %p, %p);\n", target, internalformat, width, height, format, type, (const void *) row, (const void *) column)); +} + +KEYWORD1 void KEYWORD2 NAME(GetHistogram)(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid * values) +{ + DISPATCH(GetHistogram, (target, reset, format, type, values), (F, "glGetHistogram(0x%x, %d, 0x%x, 0x%x, %p);\n", target, reset, format, type, (const void *) values)); +} + +KEYWORD1 void KEYWORD2 NAME(GetHistogramParameterfv)(GLenum target, GLenum pname, GLfloat * params) +{ + DISPATCH(GetHistogramParameterfv, (target, pname, params), (F, "glGetHistogramParameterfv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetHistogramParameteriv)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetHistogramParameteriv, (target, pname, params), (F, "glGetHistogramParameteriv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetMinmax)(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid * values) +{ + DISPATCH(GetMinmax, (target, reset, format, type, values), (F, "glGetMinmax(0x%x, %d, 0x%x, 0x%x, %p);\n", target, reset, format, type, (const void *) values)); +} + +KEYWORD1 void KEYWORD2 NAME(GetMinmaxParameterfv)(GLenum target, GLenum pname, GLfloat * params) +{ + DISPATCH(GetMinmaxParameterfv, (target, pname, params), (F, "glGetMinmaxParameterfv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetMinmaxParameteriv)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetMinmaxParameteriv, (target, pname, params), (F, "glGetMinmaxParameteriv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(Histogram)(GLenum target, GLsizei width, GLenum internalformat, GLboolean sink) +{ + DISPATCH(Histogram, (target, width, internalformat, sink), (F, "glHistogram(0x%x, %d, 0x%x, %d);\n", target, width, internalformat, sink)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_367)(GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_367)(GLenum target, GLsizei width, GLenum internalformat, GLboolean sink) +{ + DISPATCH(Histogram, (target, width, internalformat, sink), (F, "glHistogramEXT(0x%x, %d, 0x%x, %d);\n", target, width, internalformat, sink)); +} + +KEYWORD1 void KEYWORD2 NAME(Minmax)(GLenum target, GLenum internalformat, GLboolean sink) +{ + DISPATCH(Minmax, (target, internalformat, sink), (F, "glMinmax(0x%x, 0x%x, %d);\n", target, internalformat, sink)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_368)(GLenum target, GLenum internalformat, GLboolean sink); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_368)(GLenum target, GLenum internalformat, GLboolean sink) +{ + DISPATCH(Minmax, (target, internalformat, sink), (F, "glMinmaxEXT(0x%x, 0x%x, %d);\n", target, internalformat, sink)); +} + +KEYWORD1 void KEYWORD2 NAME(ResetHistogram)(GLenum target) +{ + DISPATCH(ResetHistogram, (target), (F, "glResetHistogram(0x%x);\n", target)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_369)(GLenum target); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_369)(GLenum target) +{ + DISPATCH(ResetHistogram, (target), (F, "glResetHistogramEXT(0x%x);\n", target)); +} + +KEYWORD1 void KEYWORD2 NAME(ResetMinmax)(GLenum target) +{ + DISPATCH(ResetMinmax, (target), (F, "glResetMinmax(0x%x);\n", target)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_370)(GLenum target); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_370)(GLenum target) +{ + DISPATCH(ResetMinmax, (target), (F, "glResetMinmaxEXT(0x%x);\n", target)); +} + +KEYWORD1 void KEYWORD2 NAME(TexImage3D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid * pixels) +{ + DISPATCH(TexImage3D, (target, level, internalformat, width, height, depth, border, format, type, pixels), (F, "glTexImage3D(0x%x, %d, %d, %d, %d, %d, %d, 0x%x, 0x%x, %p);\n", target, level, internalformat, width, height, depth, border, format, type, (const void *) pixels)); +} + +KEYWORD1 void KEYWORD2 NAME(TexImage3DEXT)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid * pixels) +{ + DISPATCH(TexImage3D, (target, level, internalformat, width, height, depth, border, format, type, pixels), (F, "glTexImage3DEXT(0x%x, %d, %d, %d, %d, %d, %d, 0x%x, 0x%x, %p);\n", target, level, internalformat, width, height, depth, border, format, type, (const void *) pixels)); +} + +KEYWORD1 void KEYWORD2 NAME(TexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid * pixels) +{ + DISPATCH(TexSubImage3D, (target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels), (F, "glTexSubImage3D(0x%x, %d, %d, %d, %d, %d, %d, %d, 0x%x, 0x%x, %p);\n", target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, (const void *) pixels)); +} + +KEYWORD1 void KEYWORD2 NAME(TexSubImage3DEXT)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid * pixels) +{ + DISPATCH(TexSubImage3D, (target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels), (F, "glTexSubImage3DEXT(0x%x, %d, %d, %d, %d, %d, %d, %d, 0x%x, 0x%x, %p);\n", target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, (const void *) pixels)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) +{ + DISPATCH(CopyTexSubImage3D, (target, level, xoffset, yoffset, zoffset, x, y, width, height), (F, "glCopyTexSubImage3D(0x%x, %d, %d, %d, %d, %d, %d, %d, %d);\n", target, level, xoffset, yoffset, zoffset, x, y, width, height)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyTexSubImage3DEXT)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) +{ + DISPATCH(CopyTexSubImage3D, (target, level, xoffset, yoffset, zoffset, x, y, width, height), (F, "glCopyTexSubImage3DEXT(0x%x, %d, %d, %d, %d, %d, %d, %d, %d);\n", target, level, xoffset, yoffset, zoffset, x, y, width, height)); +} + +KEYWORD1 void KEYWORD2 NAME(ActiveTexture)(GLenum texture) +{ + DISPATCH(ActiveTextureARB, (texture), (F, "glActiveTexture(0x%x);\n", texture)); +} + +KEYWORD1 void KEYWORD2 NAME(ActiveTextureARB)(GLenum texture) +{ + DISPATCH(ActiveTextureARB, (texture), (F, "glActiveTextureARB(0x%x);\n", texture)); +} + +KEYWORD1 void KEYWORD2 NAME(ClientActiveTexture)(GLenum texture) +{ + DISPATCH(ClientActiveTextureARB, (texture), (F, "glClientActiveTexture(0x%x);\n", texture)); +} + +KEYWORD1 void KEYWORD2 NAME(ClientActiveTextureARB)(GLenum texture) +{ + DISPATCH(ClientActiveTextureARB, (texture), (F, "glClientActiveTextureARB(0x%x);\n", texture)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1d)(GLenum target, GLdouble s) +{ + DISPATCH(MultiTexCoord1dARB, (target, s), (F, "glMultiTexCoord1d(0x%x, %f);\n", target, s)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1dARB)(GLenum target, GLdouble s) +{ + DISPATCH(MultiTexCoord1dARB, (target, s), (F, "glMultiTexCoord1dARB(0x%x, %f);\n", target, s)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1dv)(GLenum target, const GLdouble * v) +{ + DISPATCH(MultiTexCoord1dvARB, (target, v), (F, "glMultiTexCoord1dv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1dvARB)(GLenum target, const GLdouble * v) +{ + DISPATCH(MultiTexCoord1dvARB, (target, v), (F, "glMultiTexCoord1dvARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1f)(GLenum target, GLfloat s) +{ + DISPATCH(MultiTexCoord1fARB, (target, s), (F, "glMultiTexCoord1f(0x%x, %f);\n", target, s)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1fARB)(GLenum target, GLfloat s) +{ + DISPATCH(MultiTexCoord1fARB, (target, s), (F, "glMultiTexCoord1fARB(0x%x, %f);\n", target, s)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1fv)(GLenum target, const GLfloat * v) +{ + DISPATCH(MultiTexCoord1fvARB, (target, v), (F, "glMultiTexCoord1fv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1fvARB)(GLenum target, const GLfloat * v) +{ + DISPATCH(MultiTexCoord1fvARB, (target, v), (F, "glMultiTexCoord1fvARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1i)(GLenum target, GLint s) +{ + DISPATCH(MultiTexCoord1iARB, (target, s), (F, "glMultiTexCoord1i(0x%x, %d);\n", target, s)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1iARB)(GLenum target, GLint s) +{ + DISPATCH(MultiTexCoord1iARB, (target, s), (F, "glMultiTexCoord1iARB(0x%x, %d);\n", target, s)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1iv)(GLenum target, const GLint * v) +{ + DISPATCH(MultiTexCoord1ivARB, (target, v), (F, "glMultiTexCoord1iv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1ivARB)(GLenum target, const GLint * v) +{ + DISPATCH(MultiTexCoord1ivARB, (target, v), (F, "glMultiTexCoord1ivARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1s)(GLenum target, GLshort s) +{ + DISPATCH(MultiTexCoord1sARB, (target, s), (F, "glMultiTexCoord1s(0x%x, %d);\n", target, s)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1sARB)(GLenum target, GLshort s) +{ + DISPATCH(MultiTexCoord1sARB, (target, s), (F, "glMultiTexCoord1sARB(0x%x, %d);\n", target, s)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1sv)(GLenum target, const GLshort * v) +{ + DISPATCH(MultiTexCoord1svARB, (target, v), (F, "glMultiTexCoord1sv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord1svARB)(GLenum target, const GLshort * v) +{ + DISPATCH(MultiTexCoord1svARB, (target, v), (F, "glMultiTexCoord1svARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2d)(GLenum target, GLdouble s, GLdouble t) +{ + DISPATCH(MultiTexCoord2dARB, (target, s, t), (F, "glMultiTexCoord2d(0x%x, %f, %f);\n", target, s, t)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2dARB)(GLenum target, GLdouble s, GLdouble t) +{ + DISPATCH(MultiTexCoord2dARB, (target, s, t), (F, "glMultiTexCoord2dARB(0x%x, %f, %f);\n", target, s, t)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2dv)(GLenum target, const GLdouble * v) +{ + DISPATCH(MultiTexCoord2dvARB, (target, v), (F, "glMultiTexCoord2dv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2dvARB)(GLenum target, const GLdouble * v) +{ + DISPATCH(MultiTexCoord2dvARB, (target, v), (F, "glMultiTexCoord2dvARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2f)(GLenum target, GLfloat s, GLfloat t) +{ + DISPATCH(MultiTexCoord2fARB, (target, s, t), (F, "glMultiTexCoord2f(0x%x, %f, %f);\n", target, s, t)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2fARB)(GLenum target, GLfloat s, GLfloat t) +{ + DISPATCH(MultiTexCoord2fARB, (target, s, t), (F, "glMultiTexCoord2fARB(0x%x, %f, %f);\n", target, s, t)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2fv)(GLenum target, const GLfloat * v) +{ + DISPATCH(MultiTexCoord2fvARB, (target, v), (F, "glMultiTexCoord2fv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2fvARB)(GLenum target, const GLfloat * v) +{ + DISPATCH(MultiTexCoord2fvARB, (target, v), (F, "glMultiTexCoord2fvARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2i)(GLenum target, GLint s, GLint t) +{ + DISPATCH(MultiTexCoord2iARB, (target, s, t), (F, "glMultiTexCoord2i(0x%x, %d, %d);\n", target, s, t)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2iARB)(GLenum target, GLint s, GLint t) +{ + DISPATCH(MultiTexCoord2iARB, (target, s, t), (F, "glMultiTexCoord2iARB(0x%x, %d, %d);\n", target, s, t)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2iv)(GLenum target, const GLint * v) +{ + DISPATCH(MultiTexCoord2ivARB, (target, v), (F, "glMultiTexCoord2iv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2ivARB)(GLenum target, const GLint * v) +{ + DISPATCH(MultiTexCoord2ivARB, (target, v), (F, "glMultiTexCoord2ivARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2s)(GLenum target, GLshort s, GLshort t) +{ + DISPATCH(MultiTexCoord2sARB, (target, s, t), (F, "glMultiTexCoord2s(0x%x, %d, %d);\n", target, s, t)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2sARB)(GLenum target, GLshort s, GLshort t) +{ + DISPATCH(MultiTexCoord2sARB, (target, s, t), (F, "glMultiTexCoord2sARB(0x%x, %d, %d);\n", target, s, t)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2sv)(GLenum target, const GLshort * v) +{ + DISPATCH(MultiTexCoord2svARB, (target, v), (F, "glMultiTexCoord2sv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord2svARB)(GLenum target, const GLshort * v) +{ + DISPATCH(MultiTexCoord2svARB, (target, v), (F, "glMultiTexCoord2svARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3d)(GLenum target, GLdouble s, GLdouble t, GLdouble r) +{ + DISPATCH(MultiTexCoord3dARB, (target, s, t, r), (F, "glMultiTexCoord3d(0x%x, %f, %f, %f);\n", target, s, t, r)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3dARB)(GLenum target, GLdouble s, GLdouble t, GLdouble r) +{ + DISPATCH(MultiTexCoord3dARB, (target, s, t, r), (F, "glMultiTexCoord3dARB(0x%x, %f, %f, %f);\n", target, s, t, r)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3dv)(GLenum target, const GLdouble * v) +{ + DISPATCH(MultiTexCoord3dvARB, (target, v), (F, "glMultiTexCoord3dv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3dvARB)(GLenum target, const GLdouble * v) +{ + DISPATCH(MultiTexCoord3dvARB, (target, v), (F, "glMultiTexCoord3dvARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3f)(GLenum target, GLfloat s, GLfloat t, GLfloat r) +{ + DISPATCH(MultiTexCoord3fARB, (target, s, t, r), (F, "glMultiTexCoord3f(0x%x, %f, %f, %f);\n", target, s, t, r)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3fARB)(GLenum target, GLfloat s, GLfloat t, GLfloat r) +{ + DISPATCH(MultiTexCoord3fARB, (target, s, t, r), (F, "glMultiTexCoord3fARB(0x%x, %f, %f, %f);\n", target, s, t, r)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3fv)(GLenum target, const GLfloat * v) +{ + DISPATCH(MultiTexCoord3fvARB, (target, v), (F, "glMultiTexCoord3fv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3fvARB)(GLenum target, const GLfloat * v) +{ + DISPATCH(MultiTexCoord3fvARB, (target, v), (F, "glMultiTexCoord3fvARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3i)(GLenum target, GLint s, GLint t, GLint r) +{ + DISPATCH(MultiTexCoord3iARB, (target, s, t, r), (F, "glMultiTexCoord3i(0x%x, %d, %d, %d);\n", target, s, t, r)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3iARB)(GLenum target, GLint s, GLint t, GLint r) +{ + DISPATCH(MultiTexCoord3iARB, (target, s, t, r), (F, "glMultiTexCoord3iARB(0x%x, %d, %d, %d);\n", target, s, t, r)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3iv)(GLenum target, const GLint * v) +{ + DISPATCH(MultiTexCoord3ivARB, (target, v), (F, "glMultiTexCoord3iv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3ivARB)(GLenum target, const GLint * v) +{ + DISPATCH(MultiTexCoord3ivARB, (target, v), (F, "glMultiTexCoord3ivARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3s)(GLenum target, GLshort s, GLshort t, GLshort r) +{ + DISPATCH(MultiTexCoord3sARB, (target, s, t, r), (F, "glMultiTexCoord3s(0x%x, %d, %d, %d);\n", target, s, t, r)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3sARB)(GLenum target, GLshort s, GLshort t, GLshort r) +{ + DISPATCH(MultiTexCoord3sARB, (target, s, t, r), (F, "glMultiTexCoord3sARB(0x%x, %d, %d, %d);\n", target, s, t, r)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3sv)(GLenum target, const GLshort * v) +{ + DISPATCH(MultiTexCoord3svARB, (target, v), (F, "glMultiTexCoord3sv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord3svARB)(GLenum target, const GLshort * v) +{ + DISPATCH(MultiTexCoord3svARB, (target, v), (F, "glMultiTexCoord3svARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4d)(GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q) +{ + DISPATCH(MultiTexCoord4dARB, (target, s, t, r, q), (F, "glMultiTexCoord4d(0x%x, %f, %f, %f, %f);\n", target, s, t, r, q)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4dARB)(GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q) +{ + DISPATCH(MultiTexCoord4dARB, (target, s, t, r, q), (F, "glMultiTexCoord4dARB(0x%x, %f, %f, %f, %f);\n", target, s, t, r, q)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4dv)(GLenum target, const GLdouble * v) +{ + DISPATCH(MultiTexCoord4dvARB, (target, v), (F, "glMultiTexCoord4dv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4dvARB)(GLenum target, const GLdouble * v) +{ + DISPATCH(MultiTexCoord4dvARB, (target, v), (F, "glMultiTexCoord4dvARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4f)(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) +{ + DISPATCH(MultiTexCoord4fARB, (target, s, t, r, q), (F, "glMultiTexCoord4f(0x%x, %f, %f, %f, %f);\n", target, s, t, r, q)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4fARB)(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) +{ + DISPATCH(MultiTexCoord4fARB, (target, s, t, r, q), (F, "glMultiTexCoord4fARB(0x%x, %f, %f, %f, %f);\n", target, s, t, r, q)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4fv)(GLenum target, const GLfloat * v) +{ + DISPATCH(MultiTexCoord4fvARB, (target, v), (F, "glMultiTexCoord4fv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4fvARB)(GLenum target, const GLfloat * v) +{ + DISPATCH(MultiTexCoord4fvARB, (target, v), (F, "glMultiTexCoord4fvARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4i)(GLenum target, GLint s, GLint t, GLint r, GLint q) +{ + DISPATCH(MultiTexCoord4iARB, (target, s, t, r, q), (F, "glMultiTexCoord4i(0x%x, %d, %d, %d, %d);\n", target, s, t, r, q)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4iARB)(GLenum target, GLint s, GLint t, GLint r, GLint q) +{ + DISPATCH(MultiTexCoord4iARB, (target, s, t, r, q), (F, "glMultiTexCoord4iARB(0x%x, %d, %d, %d, %d);\n", target, s, t, r, q)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4iv)(GLenum target, const GLint * v) +{ + DISPATCH(MultiTexCoord4ivARB, (target, v), (F, "glMultiTexCoord4iv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4ivARB)(GLenum target, const GLint * v) +{ + DISPATCH(MultiTexCoord4ivARB, (target, v), (F, "glMultiTexCoord4ivARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4s)(GLenum target, GLshort s, GLshort t, GLshort r, GLshort q) +{ + DISPATCH(MultiTexCoord4sARB, (target, s, t, r, q), (F, "glMultiTexCoord4s(0x%x, %d, %d, %d, %d);\n", target, s, t, r, q)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4sARB)(GLenum target, GLshort s, GLshort t, GLshort r, GLshort q) +{ + DISPATCH(MultiTexCoord4sARB, (target, s, t, r, q), (F, "glMultiTexCoord4sARB(0x%x, %d, %d, %d, %d);\n", target, s, t, r, q)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4sv)(GLenum target, const GLshort * v) +{ + DISPATCH(MultiTexCoord4svARB, (target, v), (F, "glMultiTexCoord4sv(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiTexCoord4svARB)(GLenum target, const GLshort * v) +{ + DISPATCH(MultiTexCoord4svARB, (target, v), (F, "glMultiTexCoord4svARB(0x%x, %p);\n", target, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(AttachShader)(GLuint program, GLuint shader) +{ + DISPATCH(AttachShader, (program, shader), (F, "glAttachShader(%d, %d);\n", program, shader)); +} + +KEYWORD1 GLuint KEYWORD2 NAME(CreateProgram)(void) +{ + RETURN_DISPATCH(CreateProgram, (), (F, "glCreateProgram();\n")); +} + +KEYWORD1 GLuint KEYWORD2 NAME(CreateShader)(GLenum type) +{ + RETURN_DISPATCH(CreateShader, (type), (F, "glCreateShader(0x%x);\n", type)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteProgram)(GLuint program) +{ + DISPATCH(DeleteProgram, (program), (F, "glDeleteProgram(%d);\n", program)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteShader)(GLuint program) +{ + DISPATCH(DeleteShader, (program), (F, "glDeleteShader(%d);\n", program)); +} + +KEYWORD1 void KEYWORD2 NAME(DetachShader)(GLuint program, GLuint shader) +{ + DISPATCH(DetachShader, (program, shader), (F, "glDetachShader(%d, %d);\n", program, shader)); +} + +KEYWORD1 void KEYWORD2 NAME(GetAttachedShaders)(GLuint program, GLsizei maxCount, GLsizei * count, GLuint * obj) +{ + DISPATCH(GetAttachedShaders, (program, maxCount, count, obj), (F, "glGetAttachedShaders(%d, %d, %p, %p);\n", program, maxCount, (const void *) count, (const void *) obj)); +} + +KEYWORD1 void KEYWORD2 NAME(GetProgramInfoLog)(GLuint program, GLsizei bufSize, GLsizei * length, GLchar * infoLog) +{ + DISPATCH(GetProgramInfoLog, (program, bufSize, length, infoLog), (F, "glGetProgramInfoLog(%d, %d, %p, %p);\n", program, bufSize, (const void *) length, (const void *) infoLog)); +} + +KEYWORD1 void KEYWORD2 NAME(GetProgramiv)(GLuint program, GLenum pname, GLint * params) +{ + DISPATCH(GetProgramiv, (program, pname, params), (F, "glGetProgramiv(%d, 0x%x, %p);\n", program, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetShaderInfoLog)(GLuint shader, GLsizei bufSize, GLsizei * length, GLchar * infoLog) +{ + DISPATCH(GetShaderInfoLog, (shader, bufSize, length, infoLog), (F, "glGetShaderInfoLog(%d, %d, %p, %p);\n", shader, bufSize, (const void *) length, (const void *) infoLog)); +} + +KEYWORD1 void KEYWORD2 NAME(GetShaderiv)(GLuint shader, GLenum pname, GLint * params) +{ + DISPATCH(GetShaderiv, (shader, pname, params), (F, "glGetShaderiv(%d, 0x%x, %p);\n", shader, pname, (const void *) params)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsProgram)(GLuint program) +{ + RETURN_DISPATCH(IsProgram, (program), (F, "glIsProgram(%d);\n", program)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsShader)(GLuint shader) +{ + RETURN_DISPATCH(IsShader, (shader), (F, "glIsShader(%d);\n", shader)); +} + +KEYWORD1 void KEYWORD2 NAME(StencilFuncSeparate)(GLenum face, GLenum func, GLint ref, GLuint mask) +{ + DISPATCH(StencilFuncSeparate, (face, func, ref, mask), (F, "glStencilFuncSeparate(0x%x, 0x%x, %d, %d);\n", face, func, ref, mask)); +} + +KEYWORD1 void KEYWORD2 NAME(StencilMaskSeparate)(GLenum face, GLuint mask) +{ + DISPATCH(StencilMaskSeparate, (face, mask), (F, "glStencilMaskSeparate(0x%x, %d);\n", face, mask)); +} + +KEYWORD1 void KEYWORD2 NAME(StencilOpSeparate)(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass) +{ + DISPATCH(StencilOpSeparate, (face, sfail, zfail, zpass), (F, "glStencilOpSeparate(0x%x, 0x%x, 0x%x, 0x%x);\n", face, sfail, zfail, zpass)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_423)(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_423)(GLenum face, GLenum sfail, GLenum zfail, GLenum zpass) +{ + DISPATCH(StencilOpSeparate, (face, sfail, zfail, zpass), (F, "glStencilOpSeparateATI(0x%x, 0x%x, 0x%x, 0x%x);\n", face, sfail, zfail, zpass)); +} + +KEYWORD1 void KEYWORD2 NAME(UniformMatrix2x3fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) +{ + DISPATCH(UniformMatrix2x3fv, (location, count, transpose, value), (F, "glUniformMatrix2x3fv(%d, %d, %d, %p);\n", location, count, transpose, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(UniformMatrix2x4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) +{ + DISPATCH(UniformMatrix2x4fv, (location, count, transpose, value), (F, "glUniformMatrix2x4fv(%d, %d, %d, %p);\n", location, count, transpose, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(UniformMatrix3x2fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) +{ + DISPATCH(UniformMatrix3x2fv, (location, count, transpose, value), (F, "glUniformMatrix3x2fv(%d, %d, %d, %p);\n", location, count, transpose, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(UniformMatrix3x4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) +{ + DISPATCH(UniformMatrix3x4fv, (location, count, transpose, value), (F, "glUniformMatrix3x4fv(%d, %d, %d, %p);\n", location, count, transpose, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(UniformMatrix4x2fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) +{ + DISPATCH(UniformMatrix4x2fv, (location, count, transpose, value), (F, "glUniformMatrix4x2fv(%d, %d, %d, %p);\n", location, count, transpose, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(UniformMatrix4x3fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) +{ + DISPATCH(UniformMatrix4x3fv, (location, count, transpose, value), (F, "glUniformMatrix4x3fv(%d, %d, %d, %p);\n", location, count, transpose, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(ClampColor)(GLenum target, GLenum clamp) +{ + DISPATCH(ClampColor, (target, clamp), (F, "glClampColor(0x%x, 0x%x);\n", target, clamp)); +} + +KEYWORD1 void KEYWORD2 NAME(ClearBufferfi)(GLenum buffer, GLint drawbuffer, const GLfloat depth, const GLint stencil) +{ + DISPATCH(ClearBufferfi, (buffer, drawbuffer, depth, stencil), (F, "glClearBufferfi(0x%x, %d, %f, %d);\n", buffer, drawbuffer, depth, stencil)); +} + +KEYWORD1 void KEYWORD2 NAME(ClearBufferfv)(GLenum buffer, GLint drawbuffer, const GLfloat * value) +{ + DISPATCH(ClearBufferfv, (buffer, drawbuffer, value), (F, "glClearBufferfv(0x%x, %d, %p);\n", buffer, drawbuffer, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(ClearBufferiv)(GLenum buffer, GLint drawbuffer, const GLint * value) +{ + DISPATCH(ClearBufferiv, (buffer, drawbuffer, value), (F, "glClearBufferiv(0x%x, %d, %p);\n", buffer, drawbuffer, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(ClearBufferuiv)(GLenum buffer, GLint drawbuffer, const GLuint * value) +{ + DISPATCH(ClearBufferuiv, (buffer, drawbuffer, value), (F, "glClearBufferuiv(0x%x, %d, %p);\n", buffer, drawbuffer, (const void *) value)); +} + +KEYWORD1 const GLubyte * KEYWORD2 NAME(GetStringi)(GLenum name, GLuint index) +{ + RETURN_DISPATCH(GetStringi, (name, index), (F, "glGetStringi(0x%x, %d);\n", name, index)); +} + +KEYWORD1 void KEYWORD2 NAME(TexBuffer)(GLenum target, GLenum internalFormat, GLuint buffer) +{ + DISPATCH(TexBuffer, (target, internalFormat, buffer), (F, "glTexBuffer(0x%x, 0x%x, %d);\n", target, internalFormat, buffer)); +} + +KEYWORD1 void KEYWORD2 NAME(FramebufferTexture)(GLenum target, GLenum attachment, GLuint texture, GLint level) +{ + DISPATCH(FramebufferTexture, (target, attachment, texture, level), (F, "glFramebufferTexture(0x%x, 0x%x, %d, %d);\n", target, attachment, texture, level)); +} + +KEYWORD1 void KEYWORD2 NAME(GetBufferParameteri64v)(GLenum target, GLenum pname, GLint64 * params) +{ + DISPATCH(GetBufferParameteri64v, (target, pname, params), (F, "glGetBufferParameteri64v(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetInteger64i_v)(GLenum cap, GLuint index, GLint64 * data) +{ + DISPATCH(GetInteger64i_v, (cap, index, data), (F, "glGetInteger64i_v(0x%x, %d, %p);\n", cap, index, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribDivisor)(GLuint index, GLuint divisor) +{ + DISPATCH(VertexAttribDivisor, (index, divisor), (F, "glVertexAttribDivisor(%d, %d);\n", index, divisor)); +} + +KEYWORD1 void KEYWORD2 NAME(LoadTransposeMatrixd)(const GLdouble * m) +{ + DISPATCH(LoadTransposeMatrixdARB, (m), (F, "glLoadTransposeMatrixd(%p);\n", (const void *) m)); +} + +KEYWORD1 void KEYWORD2 NAME(LoadTransposeMatrixdARB)(const GLdouble * m) +{ + DISPATCH(LoadTransposeMatrixdARB, (m), (F, "glLoadTransposeMatrixdARB(%p);\n", (const void *) m)); +} + +KEYWORD1 void KEYWORD2 NAME(LoadTransposeMatrixf)(const GLfloat * m) +{ + DISPATCH(LoadTransposeMatrixfARB, (m), (F, "glLoadTransposeMatrixf(%p);\n", (const void *) m)); +} + +KEYWORD1 void KEYWORD2 NAME(LoadTransposeMatrixfARB)(const GLfloat * m) +{ + DISPATCH(LoadTransposeMatrixfARB, (m), (F, "glLoadTransposeMatrixfARB(%p);\n", (const void *) m)); +} + +KEYWORD1 void KEYWORD2 NAME(MultTransposeMatrixd)(const GLdouble * m) +{ + DISPATCH(MultTransposeMatrixdARB, (m), (F, "glMultTransposeMatrixd(%p);\n", (const void *) m)); +} + +KEYWORD1 void KEYWORD2 NAME(MultTransposeMatrixdARB)(const GLdouble * m) +{ + DISPATCH(MultTransposeMatrixdARB, (m), (F, "glMultTransposeMatrixdARB(%p);\n", (const void *) m)); +} + +KEYWORD1 void KEYWORD2 NAME(MultTransposeMatrixf)(const GLfloat * m) +{ + DISPATCH(MultTransposeMatrixfARB, (m), (F, "glMultTransposeMatrixf(%p);\n", (const void *) m)); +} + +KEYWORD1 void KEYWORD2 NAME(MultTransposeMatrixfARB)(const GLfloat * m) +{ + DISPATCH(MultTransposeMatrixfARB, (m), (F, "glMultTransposeMatrixfARB(%p);\n", (const void *) m)); +} + +KEYWORD1 void KEYWORD2 NAME(SampleCoverage)(GLclampf value, GLboolean invert) +{ + DISPATCH(SampleCoverageARB, (value, invert), (F, "glSampleCoverage(%f, %d);\n", value, invert)); +} + +KEYWORD1 void KEYWORD2 NAME(SampleCoverageARB)(GLclampf value, GLboolean invert) +{ + DISPATCH(SampleCoverageARB, (value, invert), (F, "glSampleCoverageARB(%f, %d);\n", value, invert)); +} + +KEYWORD1 void KEYWORD2 NAME(CompressedTexImage1D)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid * data) +{ + DISPATCH(CompressedTexImage1DARB, (target, level, internalformat, width, border, imageSize, data), (F, "glCompressedTexImage1D(0x%x, %d, 0x%x, %d, %d, %d, %p);\n", target, level, internalformat, width, border, imageSize, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(CompressedTexImage1DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid * data) +{ + DISPATCH(CompressedTexImage1DARB, (target, level, internalformat, width, border, imageSize, data), (F, "glCompressedTexImage1DARB(0x%x, %d, 0x%x, %d, %d, %d, %p);\n", target, level, internalformat, width, border, imageSize, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(CompressedTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data) +{ + DISPATCH(CompressedTexImage2DARB, (target, level, internalformat, width, height, border, imageSize, data), (F, "glCompressedTexImage2D(0x%x, %d, 0x%x, %d, %d, %d, %d, %p);\n", target, level, internalformat, width, height, border, imageSize, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(CompressedTexImage2DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data) +{ + DISPATCH(CompressedTexImage2DARB, (target, level, internalformat, width, height, border, imageSize, data), (F, "glCompressedTexImage2DARB(0x%x, %d, 0x%x, %d, %d, %d, %d, %p);\n", target, level, internalformat, width, height, border, imageSize, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(CompressedTexImage3D)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid * data) +{ + DISPATCH(CompressedTexImage3DARB, (target, level, internalformat, width, height, depth, border, imageSize, data), (F, "glCompressedTexImage3D(0x%x, %d, 0x%x, %d, %d, %d, %d, %d, %p);\n", target, level, internalformat, width, height, depth, border, imageSize, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(CompressedTexImage3DARB)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid * data) +{ + DISPATCH(CompressedTexImage3DARB, (target, level, internalformat, width, height, depth, border, imageSize, data), (F, "glCompressedTexImage3DARB(0x%x, %d, 0x%x, %d, %d, %d, %d, %d, %p);\n", target, level, internalformat, width, height, depth, border, imageSize, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(CompressedTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid * data) +{ + DISPATCH(CompressedTexSubImage1DARB, (target, level, xoffset, width, format, imageSize, data), (F, "glCompressedTexSubImage1D(0x%x, %d, %d, %d, 0x%x, %d, %p);\n", target, level, xoffset, width, format, imageSize, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(CompressedTexSubImage1DARB)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid * data) +{ + DISPATCH(CompressedTexSubImage1DARB, (target, level, xoffset, width, format, imageSize, data), (F, "glCompressedTexSubImage1DARB(0x%x, %d, %d, %d, 0x%x, %d, %p);\n", target, level, xoffset, width, format, imageSize, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(CompressedTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid * data) +{ + DISPATCH(CompressedTexSubImage2DARB, (target, level, xoffset, yoffset, width, height, format, imageSize, data), (F, "glCompressedTexSubImage2D(0x%x, %d, %d, %d, %d, %d, 0x%x, %d, %p);\n", target, level, xoffset, yoffset, width, height, format, imageSize, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(CompressedTexSubImage2DARB)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid * data) +{ + DISPATCH(CompressedTexSubImage2DARB, (target, level, xoffset, yoffset, width, height, format, imageSize, data), (F, "glCompressedTexSubImage2DARB(0x%x, %d, %d, %d, %d, %d, 0x%x, %d, %p);\n", target, level, xoffset, yoffset, width, height, format, imageSize, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(CompressedTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid * data) +{ + DISPATCH(CompressedTexSubImage3DARB, (target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data), (F, "glCompressedTexSubImage3D(0x%x, %d, %d, %d, %d, %d, %d, %d, 0x%x, %d, %p);\n", target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(CompressedTexSubImage3DARB)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid * data) +{ + DISPATCH(CompressedTexSubImage3DARB, (target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data), (F, "glCompressedTexSubImage3DARB(0x%x, %d, %d, %d, %d, %d, %d, %d, 0x%x, %d, %p);\n", target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(GetCompressedTexImage)(GLenum target, GLint level, GLvoid * img) +{ + DISPATCH(GetCompressedTexImageARB, (target, level, img), (F, "glGetCompressedTexImage(0x%x, %d, %p);\n", target, level, (const void *) img)); +} + +KEYWORD1 void KEYWORD2 NAME(GetCompressedTexImageARB)(GLenum target, GLint level, GLvoid * img) +{ + DISPATCH(GetCompressedTexImageARB, (target, level, img), (F, "glGetCompressedTexImageARB(0x%x, %d, %p);\n", target, level, (const void *) img)); +} + +KEYWORD1 void KEYWORD2 NAME(DisableVertexAttribArray)(GLuint index) +{ + DISPATCH(DisableVertexAttribArrayARB, (index), (F, "glDisableVertexAttribArray(%d);\n", index)); +} + +KEYWORD1 void KEYWORD2 NAME(DisableVertexAttribArrayARB)(GLuint index) +{ + DISPATCH(DisableVertexAttribArrayARB, (index), (F, "glDisableVertexAttribArrayARB(%d);\n", index)); +} + +KEYWORD1 void KEYWORD2 NAME(EnableVertexAttribArray)(GLuint index) +{ + DISPATCH(EnableVertexAttribArrayARB, (index), (F, "glEnableVertexAttribArray(%d);\n", index)); +} + +KEYWORD1 void KEYWORD2 NAME(EnableVertexAttribArrayARB)(GLuint index) +{ + DISPATCH(EnableVertexAttribArrayARB, (index), (F, "glEnableVertexAttribArrayARB(%d);\n", index)); +} + +KEYWORD1 void KEYWORD2 NAME(GetProgramEnvParameterdvARB)(GLenum target, GLuint index, GLdouble * params) +{ + DISPATCH(GetProgramEnvParameterdvARB, (target, index, params), (F, "glGetProgramEnvParameterdvARB(0x%x, %d, %p);\n", target, index, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetProgramEnvParameterfvARB)(GLenum target, GLuint index, GLfloat * params) +{ + DISPATCH(GetProgramEnvParameterfvARB, (target, index, params), (F, "glGetProgramEnvParameterfvARB(0x%x, %d, %p);\n", target, index, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetProgramLocalParameterdvARB)(GLenum target, GLuint index, GLdouble * params) +{ + DISPATCH(GetProgramLocalParameterdvARB, (target, index, params), (F, "glGetProgramLocalParameterdvARB(0x%x, %d, %p);\n", target, index, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetProgramLocalParameterfvARB)(GLenum target, GLuint index, GLfloat * params) +{ + DISPATCH(GetProgramLocalParameterfvARB, (target, index, params), (F, "glGetProgramLocalParameterfvARB(0x%x, %d, %p);\n", target, index, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetProgramStringARB)(GLenum target, GLenum pname, GLvoid * string) +{ + DISPATCH(GetProgramStringARB, (target, pname, string), (F, "glGetProgramStringARB(0x%x, 0x%x, %p);\n", target, pname, (const void *) string)); +} + +KEYWORD1 void KEYWORD2 NAME(GetProgramivARB)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetProgramivARB, (target, pname, params), (F, "glGetProgramivARB(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribdv)(GLuint index, GLenum pname, GLdouble * params) +{ + DISPATCH(GetVertexAttribdvARB, (index, pname, params), (F, "glGetVertexAttribdv(%d, 0x%x, %p);\n", index, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribdvARB)(GLuint index, GLenum pname, GLdouble * params) +{ + DISPATCH(GetVertexAttribdvARB, (index, pname, params), (F, "glGetVertexAttribdvARB(%d, 0x%x, %p);\n", index, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribfv)(GLuint index, GLenum pname, GLfloat * params) +{ + DISPATCH(GetVertexAttribfvARB, (index, pname, params), (F, "glGetVertexAttribfv(%d, 0x%x, %p);\n", index, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribfvARB)(GLuint index, GLenum pname, GLfloat * params) +{ + DISPATCH(GetVertexAttribfvARB, (index, pname, params), (F, "glGetVertexAttribfvARB(%d, 0x%x, %p);\n", index, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribiv)(GLuint index, GLenum pname, GLint * params) +{ + DISPATCH(GetVertexAttribivARB, (index, pname, params), (F, "glGetVertexAttribiv(%d, 0x%x, %p);\n", index, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribivARB)(GLuint index, GLenum pname, GLint * params) +{ + DISPATCH(GetVertexAttribivARB, (index, pname, params), (F, "glGetVertexAttribivARB(%d, 0x%x, %p);\n", index, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramEnvParameter4dARB)(GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w) +{ + DISPATCH(ProgramEnvParameter4dARB, (target, index, x, y, z, w), (F, "glProgramEnvParameter4dARB(0x%x, %d, %f, %f, %f, %f);\n", target, index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramParameter4dNV)(GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w) +{ + DISPATCH(ProgramEnvParameter4dARB, (target, index, x, y, z, w), (F, "glProgramParameter4dNV(0x%x, %d, %f, %f, %f, %f);\n", target, index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramEnvParameter4dvARB)(GLenum target, GLuint index, const GLdouble * params) +{ + DISPATCH(ProgramEnvParameter4dvARB, (target, index, params), (F, "glProgramEnvParameter4dvARB(0x%x, %d, %p);\n", target, index, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramParameter4dvNV)(GLenum target, GLuint index, const GLdouble * params) +{ + DISPATCH(ProgramEnvParameter4dvARB, (target, index, params), (F, "glProgramParameter4dvNV(0x%x, %d, %p);\n", target, index, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramEnvParameter4fARB)(GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + DISPATCH(ProgramEnvParameter4fARB, (target, index, x, y, z, w), (F, "glProgramEnvParameter4fARB(0x%x, %d, %f, %f, %f, %f);\n", target, index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramParameter4fNV)(GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + DISPATCH(ProgramEnvParameter4fARB, (target, index, x, y, z, w), (F, "glProgramParameter4fNV(0x%x, %d, %f, %f, %f, %f);\n", target, index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramEnvParameter4fvARB)(GLenum target, GLuint index, const GLfloat * params) +{ + DISPATCH(ProgramEnvParameter4fvARB, (target, index, params), (F, "glProgramEnvParameter4fvARB(0x%x, %d, %p);\n", target, index, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramParameter4fvNV)(GLenum target, GLuint index, const GLfloat * params) +{ + DISPATCH(ProgramEnvParameter4fvARB, (target, index, params), (F, "glProgramParameter4fvNV(0x%x, %d, %p);\n", target, index, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramLocalParameter4dARB)(GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w) +{ + DISPATCH(ProgramLocalParameter4dARB, (target, index, x, y, z, w), (F, "glProgramLocalParameter4dARB(0x%x, %d, %f, %f, %f, %f);\n", target, index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramLocalParameter4dvARB)(GLenum target, GLuint index, const GLdouble * params) +{ + DISPATCH(ProgramLocalParameter4dvARB, (target, index, params), (F, "glProgramLocalParameter4dvARB(0x%x, %d, %p);\n", target, index, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramLocalParameter4fARB)(GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + DISPATCH(ProgramLocalParameter4fARB, (target, index, x, y, z, w), (F, "glProgramLocalParameter4fARB(0x%x, %d, %f, %f, %f, %f);\n", target, index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramLocalParameter4fvARB)(GLenum target, GLuint index, const GLfloat * params) +{ + DISPATCH(ProgramLocalParameter4fvARB, (target, index, params), (F, "glProgramLocalParameter4fvARB(0x%x, %d, %p);\n", target, index, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramStringARB)(GLenum target, GLenum format, GLsizei len, const GLvoid * string) +{ + DISPATCH(ProgramStringARB, (target, format, len, string), (F, "glProgramStringARB(0x%x, 0x%x, %d, %p);\n", target, format, len, (const void *) string)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1d)(GLuint index, GLdouble x) +{ + DISPATCH(VertexAttrib1dARB, (index, x), (F, "glVertexAttrib1d(%d, %f);\n", index, x)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1dARB)(GLuint index, GLdouble x) +{ + DISPATCH(VertexAttrib1dARB, (index, x), (F, "glVertexAttrib1dARB(%d, %f);\n", index, x)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1dv)(GLuint index, const GLdouble * v) +{ + DISPATCH(VertexAttrib1dvARB, (index, v), (F, "glVertexAttrib1dv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1dvARB)(GLuint index, const GLdouble * v) +{ + DISPATCH(VertexAttrib1dvARB, (index, v), (F, "glVertexAttrib1dvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1f)(GLuint index, GLfloat x) +{ + DISPATCH(VertexAttrib1fARB, (index, x), (F, "glVertexAttrib1f(%d, %f);\n", index, x)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1fARB)(GLuint index, GLfloat x) +{ + DISPATCH(VertexAttrib1fARB, (index, x), (F, "glVertexAttrib1fARB(%d, %f);\n", index, x)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1fv)(GLuint index, const GLfloat * v) +{ + DISPATCH(VertexAttrib1fvARB, (index, v), (F, "glVertexAttrib1fv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1fvARB)(GLuint index, const GLfloat * v) +{ + DISPATCH(VertexAttrib1fvARB, (index, v), (F, "glVertexAttrib1fvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1s)(GLuint index, GLshort x) +{ + DISPATCH(VertexAttrib1sARB, (index, x), (F, "glVertexAttrib1s(%d, %d);\n", index, x)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1sARB)(GLuint index, GLshort x) +{ + DISPATCH(VertexAttrib1sARB, (index, x), (F, "glVertexAttrib1sARB(%d, %d);\n", index, x)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1sv)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttrib1svARB, (index, v), (F, "glVertexAttrib1sv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1svARB)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttrib1svARB, (index, v), (F, "glVertexAttrib1svARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2d)(GLuint index, GLdouble x, GLdouble y) +{ + DISPATCH(VertexAttrib2dARB, (index, x, y), (F, "glVertexAttrib2d(%d, %f, %f);\n", index, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2dARB)(GLuint index, GLdouble x, GLdouble y) +{ + DISPATCH(VertexAttrib2dARB, (index, x, y), (F, "glVertexAttrib2dARB(%d, %f, %f);\n", index, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2dv)(GLuint index, const GLdouble * v) +{ + DISPATCH(VertexAttrib2dvARB, (index, v), (F, "glVertexAttrib2dv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2dvARB)(GLuint index, const GLdouble * v) +{ + DISPATCH(VertexAttrib2dvARB, (index, v), (F, "glVertexAttrib2dvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2f)(GLuint index, GLfloat x, GLfloat y) +{ + DISPATCH(VertexAttrib2fARB, (index, x, y), (F, "glVertexAttrib2f(%d, %f, %f);\n", index, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2fARB)(GLuint index, GLfloat x, GLfloat y) +{ + DISPATCH(VertexAttrib2fARB, (index, x, y), (F, "glVertexAttrib2fARB(%d, %f, %f);\n", index, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2fv)(GLuint index, const GLfloat * v) +{ + DISPATCH(VertexAttrib2fvARB, (index, v), (F, "glVertexAttrib2fv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2fvARB)(GLuint index, const GLfloat * v) +{ + DISPATCH(VertexAttrib2fvARB, (index, v), (F, "glVertexAttrib2fvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2s)(GLuint index, GLshort x, GLshort y) +{ + DISPATCH(VertexAttrib2sARB, (index, x, y), (F, "glVertexAttrib2s(%d, %d, %d);\n", index, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2sARB)(GLuint index, GLshort x, GLshort y) +{ + DISPATCH(VertexAttrib2sARB, (index, x, y), (F, "glVertexAttrib2sARB(%d, %d, %d);\n", index, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2sv)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttrib2svARB, (index, v), (F, "glVertexAttrib2sv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2svARB)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttrib2svARB, (index, v), (F, "glVertexAttrib2svARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3d)(GLuint index, GLdouble x, GLdouble y, GLdouble z) +{ + DISPATCH(VertexAttrib3dARB, (index, x, y, z), (F, "glVertexAttrib3d(%d, %f, %f, %f);\n", index, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3dARB)(GLuint index, GLdouble x, GLdouble y, GLdouble z) +{ + DISPATCH(VertexAttrib3dARB, (index, x, y, z), (F, "glVertexAttrib3dARB(%d, %f, %f, %f);\n", index, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3dv)(GLuint index, const GLdouble * v) +{ + DISPATCH(VertexAttrib3dvARB, (index, v), (F, "glVertexAttrib3dv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3dvARB)(GLuint index, const GLdouble * v) +{ + DISPATCH(VertexAttrib3dvARB, (index, v), (F, "glVertexAttrib3dvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3f)(GLuint index, GLfloat x, GLfloat y, GLfloat z) +{ + DISPATCH(VertexAttrib3fARB, (index, x, y, z), (F, "glVertexAttrib3f(%d, %f, %f, %f);\n", index, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3fARB)(GLuint index, GLfloat x, GLfloat y, GLfloat z) +{ + DISPATCH(VertexAttrib3fARB, (index, x, y, z), (F, "glVertexAttrib3fARB(%d, %f, %f, %f);\n", index, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3fv)(GLuint index, const GLfloat * v) +{ + DISPATCH(VertexAttrib3fvARB, (index, v), (F, "glVertexAttrib3fv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3fvARB)(GLuint index, const GLfloat * v) +{ + DISPATCH(VertexAttrib3fvARB, (index, v), (F, "glVertexAttrib3fvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3s)(GLuint index, GLshort x, GLshort y, GLshort z) +{ + DISPATCH(VertexAttrib3sARB, (index, x, y, z), (F, "glVertexAttrib3s(%d, %d, %d, %d);\n", index, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3sARB)(GLuint index, GLshort x, GLshort y, GLshort z) +{ + DISPATCH(VertexAttrib3sARB, (index, x, y, z), (F, "glVertexAttrib3sARB(%d, %d, %d, %d);\n", index, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3sv)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttrib3svARB, (index, v), (F, "glVertexAttrib3sv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3svARB)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttrib3svARB, (index, v), (F, "glVertexAttrib3svARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4Nbv)(GLuint index, const GLbyte * v) +{ + DISPATCH(VertexAttrib4NbvARB, (index, v), (F, "glVertexAttrib4Nbv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4NbvARB)(GLuint index, const GLbyte * v) +{ + DISPATCH(VertexAttrib4NbvARB, (index, v), (F, "glVertexAttrib4NbvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4Niv)(GLuint index, const GLint * v) +{ + DISPATCH(VertexAttrib4NivARB, (index, v), (F, "glVertexAttrib4Niv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4NivARB)(GLuint index, const GLint * v) +{ + DISPATCH(VertexAttrib4NivARB, (index, v), (F, "glVertexAttrib4NivARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4Nsv)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttrib4NsvARB, (index, v), (F, "glVertexAttrib4Nsv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4NsvARB)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttrib4NsvARB, (index, v), (F, "glVertexAttrib4NsvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4Nub)(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w) +{ + DISPATCH(VertexAttrib4NubARB, (index, x, y, z, w), (F, "glVertexAttrib4Nub(%d, %d, %d, %d, %d);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4NubARB)(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w) +{ + DISPATCH(VertexAttrib4NubARB, (index, x, y, z, w), (F, "glVertexAttrib4NubARB(%d, %d, %d, %d, %d);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4Nubv)(GLuint index, const GLubyte * v) +{ + DISPATCH(VertexAttrib4NubvARB, (index, v), (F, "glVertexAttrib4Nubv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4NubvARB)(GLuint index, const GLubyte * v) +{ + DISPATCH(VertexAttrib4NubvARB, (index, v), (F, "glVertexAttrib4NubvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4Nuiv)(GLuint index, const GLuint * v) +{ + DISPATCH(VertexAttrib4NuivARB, (index, v), (F, "glVertexAttrib4Nuiv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4NuivARB)(GLuint index, const GLuint * v) +{ + DISPATCH(VertexAttrib4NuivARB, (index, v), (F, "glVertexAttrib4NuivARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4Nusv)(GLuint index, const GLushort * v) +{ + DISPATCH(VertexAttrib4NusvARB, (index, v), (F, "glVertexAttrib4Nusv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4NusvARB)(GLuint index, const GLushort * v) +{ + DISPATCH(VertexAttrib4NusvARB, (index, v), (F, "glVertexAttrib4NusvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4bv)(GLuint index, const GLbyte * v) +{ + DISPATCH(VertexAttrib4bvARB, (index, v), (F, "glVertexAttrib4bv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4bvARB)(GLuint index, const GLbyte * v) +{ + DISPATCH(VertexAttrib4bvARB, (index, v), (F, "glVertexAttrib4bvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4d)(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w) +{ + DISPATCH(VertexAttrib4dARB, (index, x, y, z, w), (F, "glVertexAttrib4d(%d, %f, %f, %f, %f);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4dARB)(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w) +{ + DISPATCH(VertexAttrib4dARB, (index, x, y, z, w), (F, "glVertexAttrib4dARB(%d, %f, %f, %f, %f);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4dv)(GLuint index, const GLdouble * v) +{ + DISPATCH(VertexAttrib4dvARB, (index, v), (F, "glVertexAttrib4dv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4dvARB)(GLuint index, const GLdouble * v) +{ + DISPATCH(VertexAttrib4dvARB, (index, v), (F, "glVertexAttrib4dvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4f)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + DISPATCH(VertexAttrib4fARB, (index, x, y, z, w), (F, "glVertexAttrib4f(%d, %f, %f, %f, %f);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4fARB)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + DISPATCH(VertexAttrib4fARB, (index, x, y, z, w), (F, "glVertexAttrib4fARB(%d, %f, %f, %f, %f);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4fv)(GLuint index, const GLfloat * v) +{ + DISPATCH(VertexAttrib4fvARB, (index, v), (F, "glVertexAttrib4fv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4fvARB)(GLuint index, const GLfloat * v) +{ + DISPATCH(VertexAttrib4fvARB, (index, v), (F, "glVertexAttrib4fvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4iv)(GLuint index, const GLint * v) +{ + DISPATCH(VertexAttrib4ivARB, (index, v), (F, "glVertexAttrib4iv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4ivARB)(GLuint index, const GLint * v) +{ + DISPATCH(VertexAttrib4ivARB, (index, v), (F, "glVertexAttrib4ivARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4s)(GLuint index, GLshort x, GLshort y, GLshort z, GLshort w) +{ + DISPATCH(VertexAttrib4sARB, (index, x, y, z, w), (F, "glVertexAttrib4s(%d, %d, %d, %d, %d);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4sARB)(GLuint index, GLshort x, GLshort y, GLshort z, GLshort w) +{ + DISPATCH(VertexAttrib4sARB, (index, x, y, z, w), (F, "glVertexAttrib4sARB(%d, %d, %d, %d, %d);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4sv)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttrib4svARB, (index, v), (F, "glVertexAttrib4sv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4svARB)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttrib4svARB, (index, v), (F, "glVertexAttrib4svARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4ubv)(GLuint index, const GLubyte * v) +{ + DISPATCH(VertexAttrib4ubvARB, (index, v), (F, "glVertexAttrib4ubv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4ubvARB)(GLuint index, const GLubyte * v) +{ + DISPATCH(VertexAttrib4ubvARB, (index, v), (F, "glVertexAttrib4ubvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4uiv)(GLuint index, const GLuint * v) +{ + DISPATCH(VertexAttrib4uivARB, (index, v), (F, "glVertexAttrib4uiv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4uivARB)(GLuint index, const GLuint * v) +{ + DISPATCH(VertexAttrib4uivARB, (index, v), (F, "glVertexAttrib4uivARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4usv)(GLuint index, const GLushort * v) +{ + DISPATCH(VertexAttrib4usvARB, (index, v), (F, "glVertexAttrib4usv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4usvARB)(GLuint index, const GLushort * v) +{ + DISPATCH(VertexAttrib4usvARB, (index, v), (F, "glVertexAttrib4usvARB(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribPointer)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(VertexAttribPointerARB, (index, size, type, normalized, stride, pointer), (F, "glVertexAttribPointer(%d, %d, 0x%x, %d, %d, %p);\n", index, size, type, normalized, stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribPointerARB)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(VertexAttribPointerARB, (index, size, type, normalized, stride, pointer), (F, "glVertexAttribPointerARB(%d, %d, 0x%x, %d, %d, %p);\n", index, size, type, normalized, stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(BindBuffer)(GLenum target, GLuint buffer) +{ + DISPATCH(BindBufferARB, (target, buffer), (F, "glBindBuffer(0x%x, %d);\n", target, buffer)); +} + +KEYWORD1 void KEYWORD2 NAME(BindBufferARB)(GLenum target, GLuint buffer) +{ + DISPATCH(BindBufferARB, (target, buffer), (F, "glBindBufferARB(0x%x, %d);\n", target, buffer)); +} + +KEYWORD1 void KEYWORD2 NAME(BufferData)(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage) +{ + DISPATCH(BufferDataARB, (target, size, data, usage), (F, "glBufferData(0x%x, %d, %p, 0x%x);\n", target, size, (const void *) data, usage)); +} + +KEYWORD1 void KEYWORD2 NAME(BufferDataARB)(GLenum target, GLsizeiptrARB size, const GLvoid * data, GLenum usage) +{ + DISPATCH(BufferDataARB, (target, size, data, usage), (F, "glBufferDataARB(0x%x, %d, %p, 0x%x);\n", target, size, (const void *) data, usage)); +} + +KEYWORD1 void KEYWORD2 NAME(BufferSubData)(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) +{ + DISPATCH(BufferSubDataARB, (target, offset, size, data), (F, "glBufferSubData(0x%x, %d, %d, %p);\n", target, offset, size, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(BufferSubDataARB)(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid * data) +{ + DISPATCH(BufferSubDataARB, (target, offset, size, data), (F, "glBufferSubDataARB(0x%x, %d, %d, %p);\n", target, offset, size, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteBuffers)(GLsizei n, const GLuint * buffer) +{ + DISPATCH(DeleteBuffersARB, (n, buffer), (F, "glDeleteBuffers(%d, %p);\n", n, (const void *) buffer)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteBuffersARB)(GLsizei n, const GLuint * buffer) +{ + DISPATCH(DeleteBuffersARB, (n, buffer), (F, "glDeleteBuffersARB(%d, %p);\n", n, (const void *) buffer)); +} + +KEYWORD1 void KEYWORD2 NAME(GenBuffers)(GLsizei n, GLuint * buffer) +{ + DISPATCH(GenBuffersARB, (n, buffer), (F, "glGenBuffers(%d, %p);\n", n, (const void *) buffer)); +} + +KEYWORD1 void KEYWORD2 NAME(GenBuffersARB)(GLsizei n, GLuint * buffer) +{ + DISPATCH(GenBuffersARB, (n, buffer), (F, "glGenBuffersARB(%d, %p);\n", n, (const void *) buffer)); +} + +KEYWORD1 void KEYWORD2 NAME(GetBufferParameteriv)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetBufferParameterivARB, (target, pname, params), (F, "glGetBufferParameteriv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetBufferParameterivARB)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetBufferParameterivARB, (target, pname, params), (F, "glGetBufferParameterivARB(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetBufferPointerv)(GLenum target, GLenum pname, GLvoid ** params) +{ + DISPATCH(GetBufferPointervARB, (target, pname, params), (F, "glGetBufferPointerv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetBufferPointervARB)(GLenum target, GLenum pname, GLvoid ** params) +{ + DISPATCH(GetBufferPointervARB, (target, pname, params), (F, "glGetBufferPointervARB(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetBufferSubData)(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid * data) +{ + DISPATCH(GetBufferSubDataARB, (target, offset, size, data), (F, "glGetBufferSubData(0x%x, %d, %d, %p);\n", target, offset, size, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(GetBufferSubDataARB)(GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid * data) +{ + DISPATCH(GetBufferSubDataARB, (target, offset, size, data), (F, "glGetBufferSubDataARB(0x%x, %d, %d, %p);\n", target, offset, size, (const void *) data)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsBuffer)(GLuint buffer) +{ + RETURN_DISPATCH(IsBufferARB, (buffer), (F, "glIsBuffer(%d);\n", buffer)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsBufferARB)(GLuint buffer) +{ + RETURN_DISPATCH(IsBufferARB, (buffer), (F, "glIsBufferARB(%d);\n", buffer)); +} + +KEYWORD1 GLvoid * KEYWORD2 NAME(MapBuffer)(GLenum target, GLenum access) +{ + RETURN_DISPATCH(MapBufferARB, (target, access), (F, "glMapBuffer(0x%x, 0x%x);\n", target, access)); +} + +KEYWORD1 GLvoid * KEYWORD2 NAME(MapBufferARB)(GLenum target, GLenum access) +{ + RETURN_DISPATCH(MapBufferARB, (target, access), (F, "glMapBufferARB(0x%x, 0x%x);\n", target, access)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(UnmapBuffer)(GLenum target) +{ + RETURN_DISPATCH(UnmapBufferARB, (target), (F, "glUnmapBuffer(0x%x);\n", target)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(UnmapBufferARB)(GLenum target) +{ + RETURN_DISPATCH(UnmapBufferARB, (target), (F, "glUnmapBufferARB(0x%x);\n", target)); +} + +KEYWORD1 void KEYWORD2 NAME(BeginQuery)(GLenum target, GLuint id) +{ + DISPATCH(BeginQueryARB, (target, id), (F, "glBeginQuery(0x%x, %d);\n", target, id)); +} + +KEYWORD1 void KEYWORD2 NAME(BeginQueryARB)(GLenum target, GLuint id) +{ + DISPATCH(BeginQueryARB, (target, id), (F, "glBeginQueryARB(0x%x, %d);\n", target, id)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteQueries)(GLsizei n, const GLuint * ids) +{ + DISPATCH(DeleteQueriesARB, (n, ids), (F, "glDeleteQueries(%d, %p);\n", n, (const void *) ids)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteQueriesARB)(GLsizei n, const GLuint * ids) +{ + DISPATCH(DeleteQueriesARB, (n, ids), (F, "glDeleteQueriesARB(%d, %p);\n", n, (const void *) ids)); +} + +KEYWORD1 void KEYWORD2 NAME(EndQuery)(GLenum target) +{ + DISPATCH(EndQueryARB, (target), (F, "glEndQuery(0x%x);\n", target)); +} + +KEYWORD1 void KEYWORD2 NAME(EndQueryARB)(GLenum target) +{ + DISPATCH(EndQueryARB, (target), (F, "glEndQueryARB(0x%x);\n", target)); +} + +KEYWORD1 void KEYWORD2 NAME(GenQueries)(GLsizei n, GLuint * ids) +{ + DISPATCH(GenQueriesARB, (n, ids), (F, "glGenQueries(%d, %p);\n", n, (const void *) ids)); +} + +KEYWORD1 void KEYWORD2 NAME(GenQueriesARB)(GLsizei n, GLuint * ids) +{ + DISPATCH(GenQueriesARB, (n, ids), (F, "glGenQueriesARB(%d, %p);\n", n, (const void *) ids)); +} + +KEYWORD1 void KEYWORD2 NAME(GetQueryObjectiv)(GLuint id, GLenum pname, GLint * params) +{ + DISPATCH(GetQueryObjectivARB, (id, pname, params), (F, "glGetQueryObjectiv(%d, 0x%x, %p);\n", id, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetQueryObjectivARB)(GLuint id, GLenum pname, GLint * params) +{ + DISPATCH(GetQueryObjectivARB, (id, pname, params), (F, "glGetQueryObjectivARB(%d, 0x%x, %p);\n", id, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetQueryObjectuiv)(GLuint id, GLenum pname, GLuint * params) +{ + DISPATCH(GetQueryObjectuivARB, (id, pname, params), (F, "glGetQueryObjectuiv(%d, 0x%x, %p);\n", id, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetQueryObjectuivARB)(GLuint id, GLenum pname, GLuint * params) +{ + DISPATCH(GetQueryObjectuivARB, (id, pname, params), (F, "glGetQueryObjectuivARB(%d, 0x%x, %p);\n", id, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetQueryiv)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetQueryivARB, (target, pname, params), (F, "glGetQueryiv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetQueryivARB)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetQueryivARB, (target, pname, params), (F, "glGetQueryivARB(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsQuery)(GLuint id) +{ + RETURN_DISPATCH(IsQueryARB, (id), (F, "glIsQuery(%d);\n", id)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsQueryARB)(GLuint id) +{ + RETURN_DISPATCH(IsQueryARB, (id), (F, "glIsQueryARB(%d);\n", id)); +} + +KEYWORD1 void KEYWORD2 NAME(AttachObjectARB)(GLhandleARB containerObj, GLhandleARB obj) +{ + DISPATCH(AttachObjectARB, (containerObj, obj), (F, "glAttachObjectARB(%d, %d);\n", containerObj, obj)); +} + +KEYWORD1 void KEYWORD2 NAME(CompileShader)(GLuint shader) +{ + DISPATCH(CompileShaderARB, (shader), (F, "glCompileShader(%d);\n", shader)); +} + +KEYWORD1 void KEYWORD2 NAME(CompileShaderARB)(GLhandleARB shader) +{ + DISPATCH(CompileShaderARB, (shader), (F, "glCompileShaderARB(%d);\n", shader)); +} + +KEYWORD1 GLhandleARB KEYWORD2 NAME(CreateProgramObjectARB)(void) +{ + RETURN_DISPATCH(CreateProgramObjectARB, (), (F, "glCreateProgramObjectARB();\n")); +} + +KEYWORD1 GLhandleARB KEYWORD2 NAME(CreateShaderObjectARB)(GLenum shaderType) +{ + RETURN_DISPATCH(CreateShaderObjectARB, (shaderType), (F, "glCreateShaderObjectARB(0x%x);\n", shaderType)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteObjectARB)(GLhandleARB obj) +{ + DISPATCH(DeleteObjectARB, (obj), (F, "glDeleteObjectARB(%d);\n", obj)); +} + +KEYWORD1 void KEYWORD2 NAME(DetachObjectARB)(GLhandleARB containerObj, GLhandleARB attachedObj) +{ + DISPATCH(DetachObjectARB, (containerObj, attachedObj), (F, "glDetachObjectARB(%d, %d);\n", containerObj, attachedObj)); +} + +KEYWORD1 void KEYWORD2 NAME(GetActiveUniform)(GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLchar * name) +{ + DISPATCH(GetActiveUniformARB, (program, index, bufSize, length, size, type, name), (F, "glGetActiveUniform(%d, %d, %d, %p, %p, %p, %p);\n", program, index, bufSize, (const void *) length, (const void *) size, (const void *) type, (const void *) name)); +} + +KEYWORD1 void KEYWORD2 NAME(GetActiveUniformARB)(GLhandleARB program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLcharARB * name) +{ + DISPATCH(GetActiveUniformARB, (program, index, bufSize, length, size, type, name), (F, "glGetActiveUniformARB(%d, %d, %d, %p, %p, %p, %p);\n", program, index, bufSize, (const void *) length, (const void *) size, (const void *) type, (const void *) name)); +} + +KEYWORD1 void KEYWORD2 NAME(GetAttachedObjectsARB)(GLhandleARB containerObj, GLsizei maxLength, GLsizei * length, GLhandleARB * infoLog) +{ + DISPATCH(GetAttachedObjectsARB, (containerObj, maxLength, length, infoLog), (F, "glGetAttachedObjectsARB(%d, %d, %p, %p);\n", containerObj, maxLength, (const void *) length, (const void *) infoLog)); +} + +KEYWORD1 GLhandleARB KEYWORD2 NAME(GetHandleARB)(GLenum pname) +{ + RETURN_DISPATCH(GetHandleARB, (pname), (F, "glGetHandleARB(0x%x);\n", pname)); +} + +KEYWORD1 void KEYWORD2 NAME(GetInfoLogARB)(GLhandleARB obj, GLsizei maxLength, GLsizei * length, GLcharARB * infoLog) +{ + DISPATCH(GetInfoLogARB, (obj, maxLength, length, infoLog), (F, "glGetInfoLogARB(%d, %d, %p, %p);\n", obj, maxLength, (const void *) length, (const void *) infoLog)); +} + +KEYWORD1 void KEYWORD2 NAME(GetObjectParameterfvARB)(GLhandleARB obj, GLenum pname, GLfloat * params) +{ + DISPATCH(GetObjectParameterfvARB, (obj, pname, params), (F, "glGetObjectParameterfvARB(%d, 0x%x, %p);\n", obj, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetObjectParameterivARB)(GLhandleARB obj, GLenum pname, GLint * params) +{ + DISPATCH(GetObjectParameterivARB, (obj, pname, params), (F, "glGetObjectParameterivARB(%d, 0x%x, %p);\n", obj, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetShaderSource)(GLuint shader, GLsizei bufSize, GLsizei * length, GLchar * source) +{ + DISPATCH(GetShaderSourceARB, (shader, bufSize, length, source), (F, "glGetShaderSource(%d, %d, %p, %p);\n", shader, bufSize, (const void *) length, (const void *) source)); +} + +KEYWORD1 void KEYWORD2 NAME(GetShaderSourceARB)(GLhandleARB shader, GLsizei bufSize, GLsizei * length, GLcharARB * source) +{ + DISPATCH(GetShaderSourceARB, (shader, bufSize, length, source), (F, "glGetShaderSourceARB(%d, %d, %p, %p);\n", shader, bufSize, (const void *) length, (const void *) source)); +} + +KEYWORD1 GLint KEYWORD2 NAME(GetUniformLocation)(GLuint program, const GLchar * name) +{ + RETURN_DISPATCH(GetUniformLocationARB, (program, name), (F, "glGetUniformLocation(%d, %p);\n", program, (const void *) name)); +} + +KEYWORD1 GLint KEYWORD2 NAME(GetUniformLocationARB)(GLhandleARB program, const GLcharARB * name) +{ + RETURN_DISPATCH(GetUniformLocationARB, (program, name), (F, "glGetUniformLocationARB(%d, %p);\n", program, (const void *) name)); +} + +KEYWORD1 void KEYWORD2 NAME(GetUniformfv)(GLuint program, GLint location, GLfloat * params) +{ + DISPATCH(GetUniformfvARB, (program, location, params), (F, "glGetUniformfv(%d, %d, %p);\n", program, location, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetUniformfvARB)(GLhandleARB program, GLint location, GLfloat * params) +{ + DISPATCH(GetUniformfvARB, (program, location, params), (F, "glGetUniformfvARB(%d, %d, %p);\n", program, location, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetUniformiv)(GLuint program, GLint location, GLint * params) +{ + DISPATCH(GetUniformivARB, (program, location, params), (F, "glGetUniformiv(%d, %d, %p);\n", program, location, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetUniformivARB)(GLhandleARB program, GLint location, GLint * params) +{ + DISPATCH(GetUniformivARB, (program, location, params), (F, "glGetUniformivARB(%d, %d, %p);\n", program, location, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(LinkProgram)(GLuint program) +{ + DISPATCH(LinkProgramARB, (program), (F, "glLinkProgram(%d);\n", program)); +} + +KEYWORD1 void KEYWORD2 NAME(LinkProgramARB)(GLhandleARB program) +{ + DISPATCH(LinkProgramARB, (program), (F, "glLinkProgramARB(%d);\n", program)); +} + +KEYWORD1 void KEYWORD2 NAME(ShaderSource)(GLuint shader, GLsizei count, const GLchar ** string, const GLint * length) +{ + DISPATCH(ShaderSourceARB, (shader, count, string, length), (F, "glShaderSource(%d, %d, %p, %p);\n", shader, count, (const void *) string, (const void *) length)); +} + +KEYWORD1 void KEYWORD2 NAME(ShaderSourceARB)(GLhandleARB shader, GLsizei count, const GLcharARB ** string, const GLint * length) +{ + DISPATCH(ShaderSourceARB, (shader, count, string, length), (F, "glShaderSourceARB(%d, %d, %p, %p);\n", shader, count, (const void *) string, (const void *) length)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform1f)(GLint location, GLfloat v0) +{ + DISPATCH(Uniform1fARB, (location, v0), (F, "glUniform1f(%d, %f);\n", location, v0)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform1fARB)(GLint location, GLfloat v0) +{ + DISPATCH(Uniform1fARB, (location, v0), (F, "glUniform1fARB(%d, %f);\n", location, v0)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform1fv)(GLint location, GLsizei count, const GLfloat * value) +{ + DISPATCH(Uniform1fvARB, (location, count, value), (F, "glUniform1fv(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform1fvARB)(GLint location, GLsizei count, const GLfloat * value) +{ + DISPATCH(Uniform1fvARB, (location, count, value), (F, "glUniform1fvARB(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform1i)(GLint location, GLint v0) +{ + DISPATCH(Uniform1iARB, (location, v0), (F, "glUniform1i(%d, %d);\n", location, v0)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform1iARB)(GLint location, GLint v0) +{ + DISPATCH(Uniform1iARB, (location, v0), (F, "glUniform1iARB(%d, %d);\n", location, v0)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform1iv)(GLint location, GLsizei count, const GLint * value) +{ + DISPATCH(Uniform1ivARB, (location, count, value), (F, "glUniform1iv(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform1ivARB)(GLint location, GLsizei count, const GLint * value) +{ + DISPATCH(Uniform1ivARB, (location, count, value), (F, "glUniform1ivARB(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform2f)(GLint location, GLfloat v0, GLfloat v1) +{ + DISPATCH(Uniform2fARB, (location, v0, v1), (F, "glUniform2f(%d, %f, %f);\n", location, v0, v1)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform2fARB)(GLint location, GLfloat v0, GLfloat v1) +{ + DISPATCH(Uniform2fARB, (location, v0, v1), (F, "glUniform2fARB(%d, %f, %f);\n", location, v0, v1)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform2fv)(GLint location, GLsizei count, const GLfloat * value) +{ + DISPATCH(Uniform2fvARB, (location, count, value), (F, "glUniform2fv(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform2fvARB)(GLint location, GLsizei count, const GLfloat * value) +{ + DISPATCH(Uniform2fvARB, (location, count, value), (F, "glUniform2fvARB(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform2i)(GLint location, GLint v0, GLint v1) +{ + DISPATCH(Uniform2iARB, (location, v0, v1), (F, "glUniform2i(%d, %d, %d);\n", location, v0, v1)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform2iARB)(GLint location, GLint v0, GLint v1) +{ + DISPATCH(Uniform2iARB, (location, v0, v1), (F, "glUniform2iARB(%d, %d, %d);\n", location, v0, v1)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform2iv)(GLint location, GLsizei count, const GLint * value) +{ + DISPATCH(Uniform2ivARB, (location, count, value), (F, "glUniform2iv(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform2ivARB)(GLint location, GLsizei count, const GLint * value) +{ + DISPATCH(Uniform2ivARB, (location, count, value), (F, "glUniform2ivARB(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform3f)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) +{ + DISPATCH(Uniform3fARB, (location, v0, v1, v2), (F, "glUniform3f(%d, %f, %f, %f);\n", location, v0, v1, v2)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform3fARB)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) +{ + DISPATCH(Uniform3fARB, (location, v0, v1, v2), (F, "glUniform3fARB(%d, %f, %f, %f);\n", location, v0, v1, v2)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform3fv)(GLint location, GLsizei count, const GLfloat * value) +{ + DISPATCH(Uniform3fvARB, (location, count, value), (F, "glUniform3fv(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform3fvARB)(GLint location, GLsizei count, const GLfloat * value) +{ + DISPATCH(Uniform3fvARB, (location, count, value), (F, "glUniform3fvARB(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform3i)(GLint location, GLint v0, GLint v1, GLint v2) +{ + DISPATCH(Uniform3iARB, (location, v0, v1, v2), (F, "glUniform3i(%d, %d, %d, %d);\n", location, v0, v1, v2)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform3iARB)(GLint location, GLint v0, GLint v1, GLint v2) +{ + DISPATCH(Uniform3iARB, (location, v0, v1, v2), (F, "glUniform3iARB(%d, %d, %d, %d);\n", location, v0, v1, v2)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform3iv)(GLint location, GLsizei count, const GLint * value) +{ + DISPATCH(Uniform3ivARB, (location, count, value), (F, "glUniform3iv(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform3ivARB)(GLint location, GLsizei count, const GLint * value) +{ + DISPATCH(Uniform3ivARB, (location, count, value), (F, "glUniform3ivARB(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform4f)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) +{ + DISPATCH(Uniform4fARB, (location, v0, v1, v2, v3), (F, "glUniform4f(%d, %f, %f, %f, %f);\n", location, v0, v1, v2, v3)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform4fARB)(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) +{ + DISPATCH(Uniform4fARB, (location, v0, v1, v2, v3), (F, "glUniform4fARB(%d, %f, %f, %f, %f);\n", location, v0, v1, v2, v3)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform4fv)(GLint location, GLsizei count, const GLfloat * value) +{ + DISPATCH(Uniform4fvARB, (location, count, value), (F, "glUniform4fv(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform4fvARB)(GLint location, GLsizei count, const GLfloat * value) +{ + DISPATCH(Uniform4fvARB, (location, count, value), (F, "glUniform4fvARB(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform4i)(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) +{ + DISPATCH(Uniform4iARB, (location, v0, v1, v2, v3), (F, "glUniform4i(%d, %d, %d, %d, %d);\n", location, v0, v1, v2, v3)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform4iARB)(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) +{ + DISPATCH(Uniform4iARB, (location, v0, v1, v2, v3), (F, "glUniform4iARB(%d, %d, %d, %d, %d);\n", location, v0, v1, v2, v3)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform4iv)(GLint location, GLsizei count, const GLint * value) +{ + DISPATCH(Uniform4ivARB, (location, count, value), (F, "glUniform4iv(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform4ivARB)(GLint location, GLsizei count, const GLint * value) +{ + DISPATCH(Uniform4ivARB, (location, count, value), (F, "glUniform4ivARB(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(UniformMatrix2fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) +{ + DISPATCH(UniformMatrix2fvARB, (location, count, transpose, value), (F, "glUniformMatrix2fv(%d, %d, %d, %p);\n", location, count, transpose, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(UniformMatrix2fvARB)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) +{ + DISPATCH(UniformMatrix2fvARB, (location, count, transpose, value), (F, "glUniformMatrix2fvARB(%d, %d, %d, %p);\n", location, count, transpose, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(UniformMatrix3fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) +{ + DISPATCH(UniformMatrix3fvARB, (location, count, transpose, value), (F, "glUniformMatrix3fv(%d, %d, %d, %p);\n", location, count, transpose, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(UniformMatrix3fvARB)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) +{ + DISPATCH(UniformMatrix3fvARB, (location, count, transpose, value), (F, "glUniformMatrix3fvARB(%d, %d, %d, %p);\n", location, count, transpose, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(UniformMatrix4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) +{ + DISPATCH(UniformMatrix4fvARB, (location, count, transpose, value), (F, "glUniformMatrix4fv(%d, %d, %d, %p);\n", location, count, transpose, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(UniformMatrix4fvARB)(GLint location, GLsizei count, GLboolean transpose, const GLfloat * value) +{ + DISPATCH(UniformMatrix4fvARB, (location, count, transpose, value), (F, "glUniformMatrix4fvARB(%d, %d, %d, %p);\n", location, count, transpose, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(UseProgram)(GLuint program) +{ + DISPATCH(UseProgramObjectARB, (program), (F, "glUseProgram(%d);\n", program)); +} + +KEYWORD1 void KEYWORD2 NAME(UseProgramObjectARB)(GLhandleARB program) +{ + DISPATCH(UseProgramObjectARB, (program), (F, "glUseProgramObjectARB(%d);\n", program)); +} + +KEYWORD1 void KEYWORD2 NAME(ValidateProgram)(GLuint program) +{ + DISPATCH(ValidateProgramARB, (program), (F, "glValidateProgram(%d);\n", program)); +} + +KEYWORD1 void KEYWORD2 NAME(ValidateProgramARB)(GLhandleARB program) +{ + DISPATCH(ValidateProgramARB, (program), (F, "glValidateProgramARB(%d);\n", program)); +} + +KEYWORD1 void KEYWORD2 NAME(BindAttribLocation)(GLuint program, GLuint index, const GLchar * name) +{ + DISPATCH(BindAttribLocationARB, (program, index, name), (F, "glBindAttribLocation(%d, %d, %p);\n", program, index, (const void *) name)); +} + +KEYWORD1 void KEYWORD2 NAME(BindAttribLocationARB)(GLhandleARB program, GLuint index, const GLcharARB * name) +{ + DISPATCH(BindAttribLocationARB, (program, index, name), (F, "glBindAttribLocationARB(%d, %d, %p);\n", program, index, (const void *) name)); +} + +KEYWORD1 void KEYWORD2 NAME(GetActiveAttrib)(GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLchar * name) +{ + DISPATCH(GetActiveAttribARB, (program, index, bufSize, length, size, type, name), (F, "glGetActiveAttrib(%d, %d, %d, %p, %p, %p, %p);\n", program, index, bufSize, (const void *) length, (const void *) size, (const void *) type, (const void *) name)); +} + +KEYWORD1 void KEYWORD2 NAME(GetActiveAttribARB)(GLhandleARB program, GLuint index, GLsizei bufSize, GLsizei * length, GLint * size, GLenum * type, GLcharARB * name) +{ + DISPATCH(GetActiveAttribARB, (program, index, bufSize, length, size, type, name), (F, "glGetActiveAttribARB(%d, %d, %d, %p, %p, %p, %p);\n", program, index, bufSize, (const void *) length, (const void *) size, (const void *) type, (const void *) name)); +} + +KEYWORD1 GLint KEYWORD2 NAME(GetAttribLocation)(GLuint program, const GLchar * name) +{ + RETURN_DISPATCH(GetAttribLocationARB, (program, name), (F, "glGetAttribLocation(%d, %p);\n", program, (const void *) name)); +} + +KEYWORD1 GLint KEYWORD2 NAME(GetAttribLocationARB)(GLhandleARB program, const GLcharARB * name) +{ + RETURN_DISPATCH(GetAttribLocationARB, (program, name), (F, "glGetAttribLocationARB(%d, %p);\n", program, (const void *) name)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawBuffers)(GLsizei n, const GLenum * bufs) +{ + DISPATCH(DrawBuffersARB, (n, bufs), (F, "glDrawBuffers(%d, %p);\n", n, (const void *) bufs)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawBuffersARB)(GLsizei n, const GLenum * bufs) +{ + DISPATCH(DrawBuffersARB, (n, bufs), (F, "glDrawBuffersARB(%d, %p);\n", n, (const void *) bufs)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawBuffersATI)(GLsizei n, const GLenum * bufs) +{ + DISPATCH(DrawBuffersARB, (n, bufs), (F, "glDrawBuffersATI(%d, %p);\n", n, (const void *) bufs)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawArraysInstancedARB)(GLenum mode, GLint first, GLsizei count, GLsizei primcount) +{ + DISPATCH(DrawArraysInstancedARB, (mode, first, count, primcount), (F, "glDrawArraysInstancedARB(0x%x, %d, %d, %d);\n", mode, first, count, primcount)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawArraysInstancedEXT)(GLenum mode, GLint first, GLsizei count, GLsizei primcount) +{ + DISPATCH(DrawArraysInstancedARB, (mode, first, count, primcount), (F, "glDrawArraysInstancedEXT(0x%x, %d, %d, %d);\n", mode, first, count, primcount)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawArraysInstanced)(GLenum mode, GLint first, GLsizei count, GLsizei primcount) +{ + DISPATCH(DrawArraysInstancedARB, (mode, first, count, primcount), (F, "glDrawArraysInstanced(0x%x, %d, %d, %d);\n", mode, first, count, primcount)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawElementsInstancedARB)(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices, GLsizei primcount) +{ + DISPATCH(DrawElementsInstancedARB, (mode, count, type, indices, primcount), (F, "glDrawElementsInstancedARB(0x%x, %d, 0x%x, %p, %d);\n", mode, count, type, (const void *) indices, primcount)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawElementsInstancedEXT)(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices, GLsizei primcount) +{ + DISPATCH(DrawElementsInstancedARB, (mode, count, type, indices, primcount), (F, "glDrawElementsInstancedEXT(0x%x, %d, 0x%x, %p, %d);\n", mode, count, type, (const void *) indices, primcount)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawElementsInstanced)(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices, GLsizei primcount) +{ + DISPATCH(DrawElementsInstancedARB, (mode, count, type, indices, primcount), (F, "glDrawElementsInstanced(0x%x, %d, 0x%x, %p, %d);\n", mode, count, type, (const void *) indices, primcount)); +} + +KEYWORD1 void KEYWORD2 NAME(RenderbufferStorageMultisample)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) +{ + DISPATCH(RenderbufferStorageMultisample, (target, samples, internalformat, width, height), (F, "glRenderbufferStorageMultisample(0x%x, %d, 0x%x, %d, %d);\n", target, samples, internalformat, width, height)); +} + +KEYWORD1 void KEYWORD2 NAME(RenderbufferStorageMultisampleEXT)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) +{ + DISPATCH(RenderbufferStorageMultisample, (target, samples, internalformat, width, height), (F, "glRenderbufferStorageMultisampleEXT(0x%x, %d, 0x%x, %d, %d);\n", target, samples, internalformat, width, height)); +} + +KEYWORD1 void KEYWORD2 NAME(FramebufferTextureARB)(GLenum target, GLenum attachment, GLuint texture, GLint level) +{ + DISPATCH(FramebufferTextureARB, (target, attachment, texture, level), (F, "glFramebufferTextureARB(0x%x, 0x%x, %d, %d);\n", target, attachment, texture, level)); +} + +KEYWORD1 void KEYWORD2 NAME(FramebufferTextureFaceARB)(GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face) +{ + DISPATCH(FramebufferTextureFaceARB, (target, attachment, texture, level, face), (F, "glFramebufferTextureFaceARB(0x%x, 0x%x, %d, %d, 0x%x);\n", target, attachment, texture, level, face)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramParameteriARB)(GLuint program, GLenum pname, GLint value) +{ + DISPATCH(ProgramParameteriARB, (program, pname, value), (F, "glProgramParameteriARB(%d, 0x%x, %d);\n", program, pname, value)); +} + +KEYWORD1 void KEYWORD2 NAME(FlushMappedBufferRange)(GLenum target, GLintptr offset, GLsizeiptr length) +{ + DISPATCH(FlushMappedBufferRange, (target, offset, length), (F, "glFlushMappedBufferRange(0x%x, %d, %d);\n", target, offset, length)); +} + +KEYWORD1 GLvoid * KEYWORD2 NAME(MapBufferRange)(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) +{ + RETURN_DISPATCH(MapBufferRange, (target, offset, length, access), (F, "glMapBufferRange(0x%x, %d, %d, %d);\n", target, offset, length, access)); +} + +KEYWORD1 void KEYWORD2 NAME(BindVertexArray)(GLuint array) +{ + DISPATCH(BindVertexArray, (array), (F, "glBindVertexArray(%d);\n", array)); +} + +KEYWORD1 void KEYWORD2 NAME(GenVertexArrays)(GLsizei n, GLuint * arrays) +{ + DISPATCH(GenVertexArrays, (n, arrays), (F, "glGenVertexArrays(%d, %p);\n", n, (const void *) arrays)); +} + +KEYWORD1 void KEYWORD2 NAME(CopyBufferSubData)(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) +{ + DISPATCH(CopyBufferSubData, (readTarget, writeTarget, readOffset, writeOffset, size), (F, "glCopyBufferSubData(0x%x, 0x%x, %d, %d, %d);\n", readTarget, writeTarget, readOffset, writeOffset, size)); +} + +KEYWORD1 GLenum KEYWORD2 NAME(ClientWaitSync)(GLsync sync, GLbitfield flags, GLuint64 timeout) +{ + RETURN_DISPATCH(ClientWaitSync, (sync, flags, timeout), (F, "glClientWaitSync(%d, %d, %d);\n", sync, flags, timeout)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteSync)(GLsync sync) +{ + DISPATCH(DeleteSync, (sync), (F, "glDeleteSync(%d);\n", sync)); +} + +KEYWORD1 GLsync KEYWORD2 NAME(FenceSync)(GLenum condition, GLbitfield flags) +{ + RETURN_DISPATCH(FenceSync, (condition, flags), (F, "glFenceSync(0x%x, %d);\n", condition, flags)); +} + +KEYWORD1 void KEYWORD2 NAME(GetInteger64v)(GLenum pname, GLint64 * params) +{ + DISPATCH(GetInteger64v, (pname, params), (F, "glGetInteger64v(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetSynciv)(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei * length, GLint * values) +{ + DISPATCH(GetSynciv, (sync, pname, bufSize, length, values), (F, "glGetSynciv(%d, 0x%x, %d, %p, %p);\n", sync, pname, bufSize, (const void *) length, (const void *) values)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsSync)(GLsync sync) +{ + RETURN_DISPATCH(IsSync, (sync), (F, "glIsSync(%d);\n", sync)); +} + +KEYWORD1 void KEYWORD2 NAME(WaitSync)(GLsync sync, GLbitfield flags, GLuint64 timeout) +{ + DISPATCH(WaitSync, (sync, flags, timeout), (F, "glWaitSync(%d, %d, %d);\n", sync, flags, timeout)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawElementsBaseVertex)(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices, GLint basevertex) +{ + DISPATCH(DrawElementsBaseVertex, (mode, count, type, indices, basevertex), (F, "glDrawElementsBaseVertex(0x%x, %d, 0x%x, %p, %d);\n", mode, count, type, (const void *) indices, basevertex)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawRangeElementsBaseVertex)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid * indices, GLint basevertex) +{ + DISPATCH(DrawRangeElementsBaseVertex, (mode, start, end, count, type, indices, basevertex), (F, "glDrawRangeElementsBaseVertex(0x%x, %d, %d, %d, 0x%x, %p, %d);\n", mode, start, end, count, type, (const void *) indices, basevertex)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiDrawElementsBaseVertex)(GLenum mode, const GLsizei * count, GLenum type, const GLvoid ** indices, GLsizei primcount, const GLint * basevertex) +{ + DISPATCH(MultiDrawElementsBaseVertex, (mode, count, type, indices, primcount, basevertex), (F, "glMultiDrawElementsBaseVertex(0x%x, %p, 0x%x, %p, %d, %p);\n", mode, (const void *) count, type, (const void *) indices, primcount, (const void *) basevertex)); +} + +KEYWORD1 void KEYWORD2 NAME(BindTransformFeedback)(GLenum target, GLuint id) +{ + DISPATCH(BindTransformFeedback, (target, id), (F, "glBindTransformFeedback(0x%x, %d);\n", target, id)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteTransformFeedbacks)(GLsizei n, const GLuint * ids) +{ + DISPATCH(DeleteTransformFeedbacks, (n, ids), (F, "glDeleteTransformFeedbacks(%d, %p);\n", n, (const void *) ids)); +} + +KEYWORD1 void KEYWORD2 NAME(DrawTransformFeedback)(GLenum mode, GLuint id) +{ + DISPATCH(DrawTransformFeedback, (mode, id), (F, "glDrawTransformFeedback(0x%x, %d);\n", mode, id)); +} + +KEYWORD1 void KEYWORD2 NAME(GenTransformFeedbacks)(GLsizei n, GLuint * ids) +{ + DISPATCH(GenTransformFeedbacks, (n, ids), (F, "glGenTransformFeedbacks(%d, %p);\n", n, (const void *) ids)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsTransformFeedback)(GLuint id) +{ + RETURN_DISPATCH(IsTransformFeedback, (id), (F, "glIsTransformFeedback(%d);\n", id)); +} + +KEYWORD1 void KEYWORD2 NAME(PauseTransformFeedback)(void) +{ + DISPATCH(PauseTransformFeedback, (), (F, "glPauseTransformFeedback();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(ResumeTransformFeedback)(void) +{ + DISPATCH(ResumeTransformFeedback, (), (F, "glResumeTransformFeedback();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(ClearDepthf)(GLclampf depth) +{ + DISPATCH(ClearDepthf, (depth), (F, "glClearDepthf(%f);\n", depth)); +} + +KEYWORD1 void KEYWORD2 NAME(DepthRangef)(GLclampf zNear, GLclampf zFar) +{ + DISPATCH(DepthRangef, (zNear, zFar), (F, "glDepthRangef(%f, %f);\n", zNear, zFar)); +} + +KEYWORD1 void KEYWORD2 NAME(GetShaderPrecisionFormat)(GLenum shadertype, GLenum precisiontype, GLint * range, GLint * precision) +{ + DISPATCH(GetShaderPrecisionFormat, (shadertype, precisiontype, range, precision), (F, "glGetShaderPrecisionFormat(0x%x, 0x%x, %p, %p);\n", shadertype, precisiontype, (const void *) range, (const void *) precision)); +} + +KEYWORD1 void KEYWORD2 NAME(ReleaseShaderCompiler)(void) +{ + DISPATCH(ReleaseShaderCompiler, (), (F, "glReleaseShaderCompiler();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(ShaderBinary)(GLsizei n, const GLuint * shaders, GLenum binaryformat, const GLvoid * binary, GLsizei length) +{ + DISPATCH(ShaderBinary, (n, shaders, binaryformat, binary, length), (F, "glShaderBinary(%d, %p, 0x%x, %p, %d);\n", n, (const void *) shaders, binaryformat, (const void *) binary, length)); +} + +KEYWORD1 void KEYWORD2 NAME(PolygonOffsetEXT)(GLfloat factor, GLfloat bias) +{ + DISPATCH(PolygonOffsetEXT, (factor, bias), (F, "glPolygonOffsetEXT(%f, %f);\n", factor, bias)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_606)(GLenum pname, GLfloat * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_606)(GLenum pname, GLfloat * params) +{ + DISPATCH(GetPixelTexGenParameterfvSGIS, (pname, params), (F, "glGetPixelTexGenParameterfvSGIS(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_607)(GLenum pname, GLint * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_607)(GLenum pname, GLint * params) +{ + DISPATCH(GetPixelTexGenParameterivSGIS, (pname, params), (F, "glGetPixelTexGenParameterivSGIS(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_608)(GLenum pname, GLfloat param); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_608)(GLenum pname, GLfloat param) +{ + DISPATCH(PixelTexGenParameterfSGIS, (pname, param), (F, "glPixelTexGenParameterfSGIS(0x%x, %f);\n", pname, param)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_609)(GLenum pname, const GLfloat * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_609)(GLenum pname, const GLfloat * params) +{ + DISPATCH(PixelTexGenParameterfvSGIS, (pname, params), (F, "glPixelTexGenParameterfvSGIS(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_610)(GLenum pname, GLint param); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_610)(GLenum pname, GLint param) +{ + DISPATCH(PixelTexGenParameteriSGIS, (pname, param), (F, "glPixelTexGenParameteriSGIS(0x%x, %d);\n", pname, param)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_611)(GLenum pname, const GLint * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_611)(GLenum pname, const GLint * params) +{ + DISPATCH(PixelTexGenParameterivSGIS, (pname, params), (F, "glPixelTexGenParameterivSGIS(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_612)(GLclampf value, GLboolean invert); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_612)(GLclampf value, GLboolean invert) +{ + DISPATCH(SampleMaskSGIS, (value, invert), (F, "glSampleMaskSGIS(%f, %d);\n", value, invert)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_613)(GLenum pattern); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_613)(GLenum pattern) +{ + DISPATCH(SamplePatternSGIS, (pattern), (F, "glSamplePatternSGIS(0x%x);\n", pattern)); +} + +KEYWORD1 void KEYWORD2 NAME(ColorPointerEXT)(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer) +{ + DISPATCH(ColorPointerEXT, (size, type, stride, count, pointer), (F, "glColorPointerEXT(%d, 0x%x, %d, %d, %p);\n", size, type, stride, count, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(EdgeFlagPointerEXT)(GLsizei stride, GLsizei count, const GLboolean * pointer) +{ + DISPATCH(EdgeFlagPointerEXT, (stride, count, pointer), (F, "glEdgeFlagPointerEXT(%d, %d, %p);\n", stride, count, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(IndexPointerEXT)(GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer) +{ + DISPATCH(IndexPointerEXT, (type, stride, count, pointer), (F, "glIndexPointerEXT(0x%x, %d, %d, %p);\n", type, stride, count, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(NormalPointerEXT)(GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer) +{ + DISPATCH(NormalPointerEXT, (type, stride, count, pointer), (F, "glNormalPointerEXT(0x%x, %d, %d, %p);\n", type, stride, count, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(TexCoordPointerEXT)(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer) +{ + DISPATCH(TexCoordPointerEXT, (size, type, stride, count, pointer), (F, "glTexCoordPointerEXT(%d, 0x%x, %d, %d, %p);\n", size, type, stride, count, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexPointerEXT)(GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid * pointer) +{ + DISPATCH(VertexPointerEXT, (size, type, stride, count, pointer), (F, "glVertexPointerEXT(%d, 0x%x, %d, %d, %p);\n", size, type, stride, count, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(PointParameterf)(GLenum pname, GLfloat param) +{ + DISPATCH(PointParameterfEXT, (pname, param), (F, "glPointParameterf(0x%x, %f);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(PointParameterfARB)(GLenum pname, GLfloat param) +{ + DISPATCH(PointParameterfEXT, (pname, param), (F, "glPointParameterfARB(0x%x, %f);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(PointParameterfEXT)(GLenum pname, GLfloat param) +{ + DISPATCH(PointParameterfEXT, (pname, param), (F, "glPointParameterfEXT(0x%x, %f);\n", pname, param)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_620)(GLenum pname, GLfloat param); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_620)(GLenum pname, GLfloat param) +{ + DISPATCH(PointParameterfEXT, (pname, param), (F, "glPointParameterfSGIS(0x%x, %f);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(PointParameterfv)(GLenum pname, const GLfloat * params) +{ + DISPATCH(PointParameterfvEXT, (pname, params), (F, "glPointParameterfv(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(PointParameterfvARB)(GLenum pname, const GLfloat * params) +{ + DISPATCH(PointParameterfvEXT, (pname, params), (F, "glPointParameterfvARB(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(PointParameterfvEXT)(GLenum pname, const GLfloat * params) +{ + DISPATCH(PointParameterfvEXT, (pname, params), (F, "glPointParameterfvEXT(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_621)(GLenum pname, const GLfloat * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_621)(GLenum pname, const GLfloat * params) +{ + DISPATCH(PointParameterfvEXT, (pname, params), (F, "glPointParameterfvSGIS(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(LockArraysEXT)(GLint first, GLsizei count) +{ + DISPATCH(LockArraysEXT, (first, count), (F, "glLockArraysEXT(%d, %d);\n", first, count)); +} + +KEYWORD1 void KEYWORD2 NAME(UnlockArraysEXT)(void) +{ + DISPATCH(UnlockArraysEXT, (), (F, "glUnlockArraysEXT();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3b)(GLbyte red, GLbyte green, GLbyte blue) +{ + DISPATCH(SecondaryColor3bEXT, (red, green, blue), (F, "glSecondaryColor3b(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3bEXT)(GLbyte red, GLbyte green, GLbyte blue) +{ + DISPATCH(SecondaryColor3bEXT, (red, green, blue), (F, "glSecondaryColor3bEXT(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3bv)(const GLbyte * v) +{ + DISPATCH(SecondaryColor3bvEXT, (v), (F, "glSecondaryColor3bv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3bvEXT)(const GLbyte * v) +{ + DISPATCH(SecondaryColor3bvEXT, (v), (F, "glSecondaryColor3bvEXT(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3d)(GLdouble red, GLdouble green, GLdouble blue) +{ + DISPATCH(SecondaryColor3dEXT, (red, green, blue), (F, "glSecondaryColor3d(%f, %f, %f);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3dEXT)(GLdouble red, GLdouble green, GLdouble blue) +{ + DISPATCH(SecondaryColor3dEXT, (red, green, blue), (F, "glSecondaryColor3dEXT(%f, %f, %f);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3dv)(const GLdouble * v) +{ + DISPATCH(SecondaryColor3dvEXT, (v), (F, "glSecondaryColor3dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3dvEXT)(const GLdouble * v) +{ + DISPATCH(SecondaryColor3dvEXT, (v), (F, "glSecondaryColor3dvEXT(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3f)(GLfloat red, GLfloat green, GLfloat blue) +{ + DISPATCH(SecondaryColor3fEXT, (red, green, blue), (F, "glSecondaryColor3f(%f, %f, %f);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3fEXT)(GLfloat red, GLfloat green, GLfloat blue) +{ + DISPATCH(SecondaryColor3fEXT, (red, green, blue), (F, "glSecondaryColor3fEXT(%f, %f, %f);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3fv)(const GLfloat * v) +{ + DISPATCH(SecondaryColor3fvEXT, (v), (F, "glSecondaryColor3fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3fvEXT)(const GLfloat * v) +{ + DISPATCH(SecondaryColor3fvEXT, (v), (F, "glSecondaryColor3fvEXT(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3i)(GLint red, GLint green, GLint blue) +{ + DISPATCH(SecondaryColor3iEXT, (red, green, blue), (F, "glSecondaryColor3i(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3iEXT)(GLint red, GLint green, GLint blue) +{ + DISPATCH(SecondaryColor3iEXT, (red, green, blue), (F, "glSecondaryColor3iEXT(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3iv)(const GLint * v) +{ + DISPATCH(SecondaryColor3ivEXT, (v), (F, "glSecondaryColor3iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3ivEXT)(const GLint * v) +{ + DISPATCH(SecondaryColor3ivEXT, (v), (F, "glSecondaryColor3ivEXT(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3s)(GLshort red, GLshort green, GLshort blue) +{ + DISPATCH(SecondaryColor3sEXT, (red, green, blue), (F, "glSecondaryColor3s(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3sEXT)(GLshort red, GLshort green, GLshort blue) +{ + DISPATCH(SecondaryColor3sEXT, (red, green, blue), (F, "glSecondaryColor3sEXT(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3sv)(const GLshort * v) +{ + DISPATCH(SecondaryColor3svEXT, (v), (F, "glSecondaryColor3sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3svEXT)(const GLshort * v) +{ + DISPATCH(SecondaryColor3svEXT, (v), (F, "glSecondaryColor3svEXT(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3ub)(GLubyte red, GLubyte green, GLubyte blue) +{ + DISPATCH(SecondaryColor3ubEXT, (red, green, blue), (F, "glSecondaryColor3ub(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3ubEXT)(GLubyte red, GLubyte green, GLubyte blue) +{ + DISPATCH(SecondaryColor3ubEXT, (red, green, blue), (F, "glSecondaryColor3ubEXT(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3ubv)(const GLubyte * v) +{ + DISPATCH(SecondaryColor3ubvEXT, (v), (F, "glSecondaryColor3ubv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3ubvEXT)(const GLubyte * v) +{ + DISPATCH(SecondaryColor3ubvEXT, (v), (F, "glSecondaryColor3ubvEXT(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3ui)(GLuint red, GLuint green, GLuint blue) +{ + DISPATCH(SecondaryColor3uiEXT, (red, green, blue), (F, "glSecondaryColor3ui(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3uiEXT)(GLuint red, GLuint green, GLuint blue) +{ + DISPATCH(SecondaryColor3uiEXT, (red, green, blue), (F, "glSecondaryColor3uiEXT(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3uiv)(const GLuint * v) +{ + DISPATCH(SecondaryColor3uivEXT, (v), (F, "glSecondaryColor3uiv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3uivEXT)(const GLuint * v) +{ + DISPATCH(SecondaryColor3uivEXT, (v), (F, "glSecondaryColor3uivEXT(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3us)(GLushort red, GLushort green, GLushort blue) +{ + DISPATCH(SecondaryColor3usEXT, (red, green, blue), (F, "glSecondaryColor3us(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3usEXT)(GLushort red, GLushort green, GLushort blue) +{ + DISPATCH(SecondaryColor3usEXT, (red, green, blue), (F, "glSecondaryColor3usEXT(%d, %d, %d);\n", red, green, blue)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3usv)(const GLushort * v) +{ + DISPATCH(SecondaryColor3usvEXT, (v), (F, "glSecondaryColor3usv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColor3usvEXT)(const GLushort * v) +{ + DISPATCH(SecondaryColor3usvEXT, (v), (F, "glSecondaryColor3usvEXT(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(SecondaryColorPointerEXT, (size, type, stride, pointer), (F, "glSecondaryColorPointer(%d, 0x%x, %d, %p);\n", size, type, stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(SecondaryColorPointerEXT)(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(SecondaryColorPointerEXT, (size, type, stride, pointer), (F, "glSecondaryColorPointerEXT(%d, 0x%x, %d, %p);\n", size, type, stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiDrawArrays)(GLenum mode, const GLint * first, const GLsizei * count, GLsizei primcount) +{ + DISPATCH(MultiDrawArraysEXT, (mode, first, count, primcount), (F, "glMultiDrawArrays(0x%x, %p, %p, %d);\n", mode, (const void *) first, (const void *) count, primcount)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiDrawArraysEXT)(GLenum mode, const GLint * first, const GLsizei * count, GLsizei primcount) +{ + DISPATCH(MultiDrawArraysEXT, (mode, first, count, primcount), (F, "glMultiDrawArraysEXT(0x%x, %p, %p, %d);\n", mode, (const void *) first, (const void *) count, primcount)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiDrawElements)(GLenum mode, const GLsizei * count, GLenum type, const GLvoid ** indices, GLsizei primcount) +{ + DISPATCH(MultiDrawElementsEXT, (mode, count, type, indices, primcount), (F, "glMultiDrawElements(0x%x, %p, 0x%x, %p, %d);\n", mode, (const void *) count, type, (const void *) indices, primcount)); +} + +KEYWORD1 void KEYWORD2 NAME(MultiDrawElementsEXT)(GLenum mode, const GLsizei * count, GLenum type, const GLvoid ** indices, GLsizei primcount) +{ + DISPATCH(MultiDrawElementsEXT, (mode, count, type, indices, primcount), (F, "glMultiDrawElementsEXT(0x%x, %p, 0x%x, %p, %d);\n", mode, (const void *) count, type, (const void *) indices, primcount)); +} + +KEYWORD1 void KEYWORD2 NAME(FogCoordPointer)(GLenum type, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(FogCoordPointerEXT, (type, stride, pointer), (F, "glFogCoordPointer(0x%x, %d, %p);\n", type, stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(FogCoordPointerEXT)(GLenum type, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(FogCoordPointerEXT, (type, stride, pointer), (F, "glFogCoordPointerEXT(0x%x, %d, %p);\n", type, stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(FogCoordd)(GLdouble coord) +{ + DISPATCH(FogCoorddEXT, (coord), (F, "glFogCoordd(%f);\n", coord)); +} + +KEYWORD1 void KEYWORD2 NAME(FogCoorddEXT)(GLdouble coord) +{ + DISPATCH(FogCoorddEXT, (coord), (F, "glFogCoorddEXT(%f);\n", coord)); +} + +KEYWORD1 void KEYWORD2 NAME(FogCoorddv)(const GLdouble * coord) +{ + DISPATCH(FogCoorddvEXT, (coord), (F, "glFogCoorddv(%p);\n", (const void *) coord)); +} + +KEYWORD1 void KEYWORD2 NAME(FogCoorddvEXT)(const GLdouble * coord) +{ + DISPATCH(FogCoorddvEXT, (coord), (F, "glFogCoorddvEXT(%p);\n", (const void *) coord)); +} + +KEYWORD1 void KEYWORD2 NAME(FogCoordf)(GLfloat coord) +{ + DISPATCH(FogCoordfEXT, (coord), (F, "glFogCoordf(%f);\n", coord)); +} + +KEYWORD1 void KEYWORD2 NAME(FogCoordfEXT)(GLfloat coord) +{ + DISPATCH(FogCoordfEXT, (coord), (F, "glFogCoordfEXT(%f);\n", coord)); +} + +KEYWORD1 void KEYWORD2 NAME(FogCoordfv)(const GLfloat * coord) +{ + DISPATCH(FogCoordfvEXT, (coord), (F, "glFogCoordfv(%p);\n", (const void *) coord)); +} + +KEYWORD1 void KEYWORD2 NAME(FogCoordfvEXT)(const GLfloat * coord) +{ + DISPATCH(FogCoordfvEXT, (coord), (F, "glFogCoordfvEXT(%p);\n", (const void *) coord)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_648)(GLenum mode); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_648)(GLenum mode) +{ + DISPATCH(PixelTexGenSGIX, (mode), (F, "glPixelTexGenSGIX(0x%x);\n", mode)); +} + +KEYWORD1 void KEYWORD2 NAME(BlendFuncSeparate)(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) +{ + DISPATCH(BlendFuncSeparateEXT, (sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha), (F, "glBlendFuncSeparate(0x%x, 0x%x, 0x%x, 0x%x);\n", sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha)); +} + +KEYWORD1 void KEYWORD2 NAME(BlendFuncSeparateEXT)(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) +{ + DISPATCH(BlendFuncSeparateEXT, (sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha), (F, "glBlendFuncSeparateEXT(0x%x, 0x%x, 0x%x, 0x%x);\n", sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_649)(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_649)(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) +{ + DISPATCH(BlendFuncSeparateEXT, (sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha), (F, "glBlendFuncSeparateINGR(0x%x, 0x%x, 0x%x, 0x%x);\n", sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha)); +} + +KEYWORD1 void KEYWORD2 NAME(FlushVertexArrayRangeNV)(void) +{ + DISPATCH(FlushVertexArrayRangeNV, (), (F, "glFlushVertexArrayRangeNV();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(VertexArrayRangeNV)(GLsizei length, const GLvoid * pointer) +{ + DISPATCH(VertexArrayRangeNV, (length, pointer), (F, "glVertexArrayRangeNV(%d, %p);\n", length, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(CombinerInputNV)(GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage) +{ + DISPATCH(CombinerInputNV, (stage, portion, variable, input, mapping, componentUsage), (F, "glCombinerInputNV(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x);\n", stage, portion, variable, input, mapping, componentUsage)); +} + +KEYWORD1 void KEYWORD2 NAME(CombinerOutputNV)(GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum) +{ + DISPATCH(CombinerOutputNV, (stage, portion, abOutput, cdOutput, sumOutput, scale, bias, abDotProduct, cdDotProduct, muxSum), (F, "glCombinerOutputNV(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, %d, %d, %d);\n", stage, portion, abOutput, cdOutput, sumOutput, scale, bias, abDotProduct, cdDotProduct, muxSum)); +} + +KEYWORD1 void KEYWORD2 NAME(CombinerParameterfNV)(GLenum pname, GLfloat param) +{ + DISPATCH(CombinerParameterfNV, (pname, param), (F, "glCombinerParameterfNV(0x%x, %f);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(CombinerParameterfvNV)(GLenum pname, const GLfloat * params) +{ + DISPATCH(CombinerParameterfvNV, (pname, params), (F, "glCombinerParameterfvNV(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(CombinerParameteriNV)(GLenum pname, GLint param) +{ + DISPATCH(CombinerParameteriNV, (pname, param), (F, "glCombinerParameteriNV(0x%x, %d);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(CombinerParameterivNV)(GLenum pname, const GLint * params) +{ + DISPATCH(CombinerParameterivNV, (pname, params), (F, "glCombinerParameterivNV(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(FinalCombinerInputNV)(GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage) +{ + DISPATCH(FinalCombinerInputNV, (variable, input, mapping, componentUsage), (F, "glFinalCombinerInputNV(0x%x, 0x%x, 0x%x, 0x%x);\n", variable, input, mapping, componentUsage)); +} + +KEYWORD1 void KEYWORD2 NAME(GetCombinerInputParameterfvNV)(GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat * params) +{ + DISPATCH(GetCombinerInputParameterfvNV, (stage, portion, variable, pname, params), (F, "glGetCombinerInputParameterfvNV(0x%x, 0x%x, 0x%x, 0x%x, %p);\n", stage, portion, variable, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetCombinerInputParameterivNV)(GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint * params) +{ + DISPATCH(GetCombinerInputParameterivNV, (stage, portion, variable, pname, params), (F, "glGetCombinerInputParameterivNV(0x%x, 0x%x, 0x%x, 0x%x, %p);\n", stage, portion, variable, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetCombinerOutputParameterfvNV)(GLenum stage, GLenum portion, GLenum pname, GLfloat * params) +{ + DISPATCH(GetCombinerOutputParameterfvNV, (stage, portion, pname, params), (F, "glGetCombinerOutputParameterfvNV(0x%x, 0x%x, 0x%x, %p);\n", stage, portion, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetCombinerOutputParameterivNV)(GLenum stage, GLenum portion, GLenum pname, GLint * params) +{ + DISPATCH(GetCombinerOutputParameterivNV, (stage, portion, pname, params), (F, "glGetCombinerOutputParameterivNV(0x%x, 0x%x, 0x%x, %p);\n", stage, portion, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetFinalCombinerInputParameterfvNV)(GLenum variable, GLenum pname, GLfloat * params) +{ + DISPATCH(GetFinalCombinerInputParameterfvNV, (variable, pname, params), (F, "glGetFinalCombinerInputParameterfvNV(0x%x, 0x%x, %p);\n", variable, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetFinalCombinerInputParameterivNV)(GLenum variable, GLenum pname, GLint * params) +{ + DISPATCH(GetFinalCombinerInputParameterivNV, (variable, pname, params), (F, "glGetFinalCombinerInputParameterivNV(0x%x, 0x%x, %p);\n", variable, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(ResizeBuffersMESA)(void) +{ + DISPATCH(ResizeBuffersMESA, (), (F, "glResizeBuffersMESA();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2d)(GLdouble x, GLdouble y) +{ + DISPATCH(WindowPos2dMESA, (x, y), (F, "glWindowPos2d(%f, %f);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2dARB)(GLdouble x, GLdouble y) +{ + DISPATCH(WindowPos2dMESA, (x, y), (F, "glWindowPos2dARB(%f, %f);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2dMESA)(GLdouble x, GLdouble y) +{ + DISPATCH(WindowPos2dMESA, (x, y), (F, "glWindowPos2dMESA(%f, %f);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2dv)(const GLdouble * v) +{ + DISPATCH(WindowPos2dvMESA, (v), (F, "glWindowPos2dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2dvARB)(const GLdouble * v) +{ + DISPATCH(WindowPos2dvMESA, (v), (F, "glWindowPos2dvARB(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2dvMESA)(const GLdouble * v) +{ + DISPATCH(WindowPos2dvMESA, (v), (F, "glWindowPos2dvMESA(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2f)(GLfloat x, GLfloat y) +{ + DISPATCH(WindowPos2fMESA, (x, y), (F, "glWindowPos2f(%f, %f);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2fARB)(GLfloat x, GLfloat y) +{ + DISPATCH(WindowPos2fMESA, (x, y), (F, "glWindowPos2fARB(%f, %f);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2fMESA)(GLfloat x, GLfloat y) +{ + DISPATCH(WindowPos2fMESA, (x, y), (F, "glWindowPos2fMESA(%f, %f);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2fv)(const GLfloat * v) +{ + DISPATCH(WindowPos2fvMESA, (v), (F, "glWindowPos2fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2fvARB)(const GLfloat * v) +{ + DISPATCH(WindowPos2fvMESA, (v), (F, "glWindowPos2fvARB(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2fvMESA)(const GLfloat * v) +{ + DISPATCH(WindowPos2fvMESA, (v), (F, "glWindowPos2fvMESA(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2i)(GLint x, GLint y) +{ + DISPATCH(WindowPos2iMESA, (x, y), (F, "glWindowPos2i(%d, %d);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2iARB)(GLint x, GLint y) +{ + DISPATCH(WindowPos2iMESA, (x, y), (F, "glWindowPos2iARB(%d, %d);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2iMESA)(GLint x, GLint y) +{ + DISPATCH(WindowPos2iMESA, (x, y), (F, "glWindowPos2iMESA(%d, %d);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2iv)(const GLint * v) +{ + DISPATCH(WindowPos2ivMESA, (v), (F, "glWindowPos2iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2ivARB)(const GLint * v) +{ + DISPATCH(WindowPos2ivMESA, (v), (F, "glWindowPos2ivARB(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2ivMESA)(const GLint * v) +{ + DISPATCH(WindowPos2ivMESA, (v), (F, "glWindowPos2ivMESA(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2s)(GLshort x, GLshort y) +{ + DISPATCH(WindowPos2sMESA, (x, y), (F, "glWindowPos2s(%d, %d);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2sARB)(GLshort x, GLshort y) +{ + DISPATCH(WindowPos2sMESA, (x, y), (F, "glWindowPos2sARB(%d, %d);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2sMESA)(GLshort x, GLshort y) +{ + DISPATCH(WindowPos2sMESA, (x, y), (F, "glWindowPos2sMESA(%d, %d);\n", x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2sv)(const GLshort * v) +{ + DISPATCH(WindowPos2svMESA, (v), (F, "glWindowPos2sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2svARB)(const GLshort * v) +{ + DISPATCH(WindowPos2svMESA, (v), (F, "glWindowPos2svARB(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos2svMESA)(const GLshort * v) +{ + DISPATCH(WindowPos2svMESA, (v), (F, "glWindowPos2svMESA(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3d)(GLdouble x, GLdouble y, GLdouble z) +{ + DISPATCH(WindowPos3dMESA, (x, y, z), (F, "glWindowPos3d(%f, %f, %f);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3dARB)(GLdouble x, GLdouble y, GLdouble z) +{ + DISPATCH(WindowPos3dMESA, (x, y, z), (F, "glWindowPos3dARB(%f, %f, %f);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3dMESA)(GLdouble x, GLdouble y, GLdouble z) +{ + DISPATCH(WindowPos3dMESA, (x, y, z), (F, "glWindowPos3dMESA(%f, %f, %f);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3dv)(const GLdouble * v) +{ + DISPATCH(WindowPos3dvMESA, (v), (F, "glWindowPos3dv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3dvARB)(const GLdouble * v) +{ + DISPATCH(WindowPos3dvMESA, (v), (F, "glWindowPos3dvARB(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3dvMESA)(const GLdouble * v) +{ + DISPATCH(WindowPos3dvMESA, (v), (F, "glWindowPos3dvMESA(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3f)(GLfloat x, GLfloat y, GLfloat z) +{ + DISPATCH(WindowPos3fMESA, (x, y, z), (F, "glWindowPos3f(%f, %f, %f);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3fARB)(GLfloat x, GLfloat y, GLfloat z) +{ + DISPATCH(WindowPos3fMESA, (x, y, z), (F, "glWindowPos3fARB(%f, %f, %f);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3fMESA)(GLfloat x, GLfloat y, GLfloat z) +{ + DISPATCH(WindowPos3fMESA, (x, y, z), (F, "glWindowPos3fMESA(%f, %f, %f);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3fv)(const GLfloat * v) +{ + DISPATCH(WindowPos3fvMESA, (v), (F, "glWindowPos3fv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3fvARB)(const GLfloat * v) +{ + DISPATCH(WindowPos3fvMESA, (v), (F, "glWindowPos3fvARB(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3fvMESA)(const GLfloat * v) +{ + DISPATCH(WindowPos3fvMESA, (v), (F, "glWindowPos3fvMESA(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3i)(GLint x, GLint y, GLint z) +{ + DISPATCH(WindowPos3iMESA, (x, y, z), (F, "glWindowPos3i(%d, %d, %d);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3iARB)(GLint x, GLint y, GLint z) +{ + DISPATCH(WindowPos3iMESA, (x, y, z), (F, "glWindowPos3iARB(%d, %d, %d);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3iMESA)(GLint x, GLint y, GLint z) +{ + DISPATCH(WindowPos3iMESA, (x, y, z), (F, "glWindowPos3iMESA(%d, %d, %d);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3iv)(const GLint * v) +{ + DISPATCH(WindowPos3ivMESA, (v), (F, "glWindowPos3iv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3ivARB)(const GLint * v) +{ + DISPATCH(WindowPos3ivMESA, (v), (F, "glWindowPos3ivARB(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3ivMESA)(const GLint * v) +{ + DISPATCH(WindowPos3ivMESA, (v), (F, "glWindowPos3ivMESA(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3s)(GLshort x, GLshort y, GLshort z) +{ + DISPATCH(WindowPos3sMESA, (x, y, z), (F, "glWindowPos3s(%d, %d, %d);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3sARB)(GLshort x, GLshort y, GLshort z) +{ + DISPATCH(WindowPos3sMESA, (x, y, z), (F, "glWindowPos3sARB(%d, %d, %d);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3sMESA)(GLshort x, GLshort y, GLshort z) +{ + DISPATCH(WindowPos3sMESA, (x, y, z), (F, "glWindowPos3sMESA(%d, %d, %d);\n", x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3sv)(const GLshort * v) +{ + DISPATCH(WindowPos3svMESA, (v), (F, "glWindowPos3sv(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3svARB)(const GLshort * v) +{ + DISPATCH(WindowPos3svMESA, (v), (F, "glWindowPos3svARB(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos3svMESA)(const GLshort * v) +{ + DISPATCH(WindowPos3svMESA, (v), (F, "glWindowPos3svMESA(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos4dMESA)(GLdouble x, GLdouble y, GLdouble z, GLdouble w) +{ + DISPATCH(WindowPos4dMESA, (x, y, z, w), (F, "glWindowPos4dMESA(%f, %f, %f, %f);\n", x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos4dvMESA)(const GLdouble * v) +{ + DISPATCH(WindowPos4dvMESA, (v), (F, "glWindowPos4dvMESA(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos4fMESA)(GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + DISPATCH(WindowPos4fMESA, (x, y, z, w), (F, "glWindowPos4fMESA(%f, %f, %f, %f);\n", x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos4fvMESA)(const GLfloat * v) +{ + DISPATCH(WindowPos4fvMESA, (v), (F, "glWindowPos4fvMESA(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos4iMESA)(GLint x, GLint y, GLint z, GLint w) +{ + DISPATCH(WindowPos4iMESA, (x, y, z, w), (F, "glWindowPos4iMESA(%d, %d, %d, %d);\n", x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos4ivMESA)(const GLint * v) +{ + DISPATCH(WindowPos4ivMESA, (v), (F, "glWindowPos4ivMESA(%p);\n", (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos4sMESA)(GLshort x, GLshort y, GLshort z, GLshort w) +{ + DISPATCH(WindowPos4sMESA, (x, y, z, w), (F, "glWindowPos4sMESA(%d, %d, %d, %d);\n", x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(WindowPos4svMESA)(const GLshort * v) +{ + DISPATCH(WindowPos4svMESA, (v), (F, "glWindowPos4svMESA(%p);\n", (const void *) v)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_690)(const GLenum * mode, const GLint * first, const GLsizei * count, GLsizei primcount, GLint modestride); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_690)(const GLenum * mode, const GLint * first, const GLsizei * count, GLsizei primcount, GLint modestride) +{ + DISPATCH(MultiModeDrawArraysIBM, (mode, first, count, primcount, modestride), (F, "glMultiModeDrawArraysIBM(%p, %p, %p, %d, %d);\n", (const void *) mode, (const void *) first, (const void *) count, primcount, modestride)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_691)(const GLenum * mode, const GLsizei * count, GLenum type, const GLvoid * const * indices, GLsizei primcount, GLint modestride); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_691)(const GLenum * mode, const GLsizei * count, GLenum type, const GLvoid * const * indices, GLsizei primcount, GLint modestride) +{ + DISPATCH(MultiModeDrawElementsIBM, (mode, count, type, indices, primcount, modestride), (F, "glMultiModeDrawElementsIBM(%p, %p, 0x%x, %p, %d, %d);\n", (const void *) mode, (const void *) count, type, (const void *) indices, primcount, modestride)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_692)(GLsizei n, const GLuint * fences); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_692)(GLsizei n, const GLuint * fences) +{ + DISPATCH(DeleteFencesNV, (n, fences), (F, "glDeleteFencesNV(%d, %p);\n", n, (const void *) fences)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_693)(GLuint fence); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_693)(GLuint fence) +{ + DISPATCH(FinishFenceNV, (fence), (F, "glFinishFenceNV(%d);\n", fence)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_694)(GLsizei n, GLuint * fences); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_694)(GLsizei n, GLuint * fences) +{ + DISPATCH(GenFencesNV, (n, fences), (F, "glGenFencesNV(%d, %p);\n", n, (const void *) fences)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_695)(GLuint fence, GLenum pname, GLint * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_695)(GLuint fence, GLenum pname, GLint * params) +{ + DISPATCH(GetFenceivNV, (fence, pname, params), (F, "glGetFenceivNV(%d, 0x%x, %p);\n", fence, pname, (const void *) params)); +} + +KEYWORD1_ALT GLboolean KEYWORD2 NAME(_dispatch_stub_696)(GLuint fence); + +KEYWORD1_ALT GLboolean KEYWORD2 NAME(_dispatch_stub_696)(GLuint fence) +{ + RETURN_DISPATCH(IsFenceNV, (fence), (F, "glIsFenceNV(%d);\n", fence)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_697)(GLuint fence, GLenum condition); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_697)(GLuint fence, GLenum condition) +{ + DISPATCH(SetFenceNV, (fence, condition), (F, "glSetFenceNV(%d, 0x%x);\n", fence, condition)); +} + +KEYWORD1_ALT GLboolean KEYWORD2 NAME(_dispatch_stub_698)(GLuint fence); + +KEYWORD1_ALT GLboolean KEYWORD2 NAME(_dispatch_stub_698)(GLuint fence) +{ + RETURN_DISPATCH(TestFenceNV, (fence), (F, "glTestFenceNV(%d);\n", fence)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(AreProgramsResidentNV)(GLsizei n, const GLuint * ids, GLboolean * residences) +{ + RETURN_DISPATCH(AreProgramsResidentNV, (n, ids, residences), (F, "glAreProgramsResidentNV(%d, %p, %p);\n", n, (const void *) ids, (const void *) residences)); +} + +KEYWORD1 void KEYWORD2 NAME(BindProgramARB)(GLenum target, GLuint program) +{ + DISPATCH(BindProgramNV, (target, program), (F, "glBindProgramARB(0x%x, %d);\n", target, program)); +} + +KEYWORD1 void KEYWORD2 NAME(BindProgramNV)(GLenum target, GLuint program) +{ + DISPATCH(BindProgramNV, (target, program), (F, "glBindProgramNV(0x%x, %d);\n", target, program)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteProgramsARB)(GLsizei n, const GLuint * programs) +{ + DISPATCH(DeleteProgramsNV, (n, programs), (F, "glDeleteProgramsARB(%d, %p);\n", n, (const void *) programs)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteProgramsNV)(GLsizei n, const GLuint * programs) +{ + DISPATCH(DeleteProgramsNV, (n, programs), (F, "glDeleteProgramsNV(%d, %p);\n", n, (const void *) programs)); +} + +KEYWORD1 void KEYWORD2 NAME(ExecuteProgramNV)(GLenum target, GLuint id, const GLfloat * params) +{ + DISPATCH(ExecuteProgramNV, (target, id, params), (F, "glExecuteProgramNV(0x%x, %d, %p);\n", target, id, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GenProgramsARB)(GLsizei n, GLuint * programs) +{ + DISPATCH(GenProgramsNV, (n, programs), (F, "glGenProgramsARB(%d, %p);\n", n, (const void *) programs)); +} + +KEYWORD1 void KEYWORD2 NAME(GenProgramsNV)(GLsizei n, GLuint * programs) +{ + DISPATCH(GenProgramsNV, (n, programs), (F, "glGenProgramsNV(%d, %p);\n", n, (const void *) programs)); +} + +KEYWORD1 void KEYWORD2 NAME(GetProgramParameterdvNV)(GLenum target, GLuint index, GLenum pname, GLdouble * params) +{ + DISPATCH(GetProgramParameterdvNV, (target, index, pname, params), (F, "glGetProgramParameterdvNV(0x%x, %d, 0x%x, %p);\n", target, index, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetProgramParameterfvNV)(GLenum target, GLuint index, GLenum pname, GLfloat * params) +{ + DISPATCH(GetProgramParameterfvNV, (target, index, pname, params), (F, "glGetProgramParameterfvNV(0x%x, %d, 0x%x, %p);\n", target, index, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetProgramStringNV)(GLuint id, GLenum pname, GLubyte * program) +{ + DISPATCH(GetProgramStringNV, (id, pname, program), (F, "glGetProgramStringNV(%d, 0x%x, %p);\n", id, pname, (const void *) program)); +} + +KEYWORD1 void KEYWORD2 NAME(GetProgramivNV)(GLuint id, GLenum pname, GLint * params) +{ + DISPATCH(GetProgramivNV, (id, pname, params), (F, "glGetProgramivNV(%d, 0x%x, %p);\n", id, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTrackMatrixivNV)(GLenum target, GLuint address, GLenum pname, GLint * params) +{ + DISPATCH(GetTrackMatrixivNV, (target, address, pname, params), (F, "glGetTrackMatrixivNV(0x%x, %d, 0x%x, %p);\n", target, address, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribPointerv)(GLuint index, GLenum pname, GLvoid ** pointer) +{ + DISPATCH(GetVertexAttribPointervNV, (index, pname, pointer), (F, "glGetVertexAttribPointerv(%d, 0x%x, %p);\n", index, pname, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribPointervARB)(GLuint index, GLenum pname, GLvoid ** pointer) +{ + DISPATCH(GetVertexAttribPointervNV, (index, pname, pointer), (F, "glGetVertexAttribPointervARB(%d, 0x%x, %p);\n", index, pname, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribPointervNV)(GLuint index, GLenum pname, GLvoid ** pointer) +{ + DISPATCH(GetVertexAttribPointervNV, (index, pname, pointer), (F, "glGetVertexAttribPointervNV(%d, 0x%x, %p);\n", index, pname, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribdvNV)(GLuint index, GLenum pname, GLdouble * params) +{ + DISPATCH(GetVertexAttribdvNV, (index, pname, params), (F, "glGetVertexAttribdvNV(%d, 0x%x, %p);\n", index, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribfvNV)(GLuint index, GLenum pname, GLfloat * params) +{ + DISPATCH(GetVertexAttribfvNV, (index, pname, params), (F, "glGetVertexAttribfvNV(%d, 0x%x, %p);\n", index, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribivNV)(GLuint index, GLenum pname, GLint * params) +{ + DISPATCH(GetVertexAttribivNV, (index, pname, params), (F, "glGetVertexAttribivNV(%d, 0x%x, %p);\n", index, pname, (const void *) params)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsProgramARB)(GLuint program) +{ + RETURN_DISPATCH(IsProgramNV, (program), (F, "glIsProgramARB(%d);\n", program)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsProgramNV)(GLuint program) +{ + RETURN_DISPATCH(IsProgramNV, (program), (F, "glIsProgramNV(%d);\n", program)); +} + +KEYWORD1 void KEYWORD2 NAME(LoadProgramNV)(GLenum target, GLuint id, GLsizei len, const GLubyte * program) +{ + DISPATCH(LoadProgramNV, (target, id, len, program), (F, "glLoadProgramNV(0x%x, %d, %d, %p);\n", target, id, len, (const void *) program)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramParameters4dvNV)(GLenum target, GLuint index, GLsizei num, const GLdouble * params) +{ + DISPATCH(ProgramParameters4dvNV, (target, index, num, params), (F, "glProgramParameters4dvNV(0x%x, %d, %d, %p);\n", target, index, num, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramParameters4fvNV)(GLenum target, GLuint index, GLsizei num, const GLfloat * params) +{ + DISPATCH(ProgramParameters4fvNV, (target, index, num, params), (F, "glProgramParameters4fvNV(0x%x, %d, %d, %p);\n", target, index, num, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(RequestResidentProgramsNV)(GLsizei n, const GLuint * ids) +{ + DISPATCH(RequestResidentProgramsNV, (n, ids), (F, "glRequestResidentProgramsNV(%d, %p);\n", n, (const void *) ids)); +} + +KEYWORD1 void KEYWORD2 NAME(TrackMatrixNV)(GLenum target, GLuint address, GLenum matrix, GLenum transform) +{ + DISPATCH(TrackMatrixNV, (target, address, matrix, transform), (F, "glTrackMatrixNV(0x%x, %d, 0x%x, 0x%x);\n", target, address, matrix, transform)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1dNV)(GLuint index, GLdouble x) +{ + DISPATCH(VertexAttrib1dNV, (index, x), (F, "glVertexAttrib1dNV(%d, %f);\n", index, x)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1dvNV)(GLuint index, const GLdouble * v) +{ + DISPATCH(VertexAttrib1dvNV, (index, v), (F, "glVertexAttrib1dvNV(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1fNV)(GLuint index, GLfloat x) +{ + DISPATCH(VertexAttrib1fNV, (index, x), (F, "glVertexAttrib1fNV(%d, %f);\n", index, x)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1fvNV)(GLuint index, const GLfloat * v) +{ + DISPATCH(VertexAttrib1fvNV, (index, v), (F, "glVertexAttrib1fvNV(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1sNV)(GLuint index, GLshort x) +{ + DISPATCH(VertexAttrib1sNV, (index, x), (F, "glVertexAttrib1sNV(%d, %d);\n", index, x)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib1svNV)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttrib1svNV, (index, v), (F, "glVertexAttrib1svNV(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2dNV)(GLuint index, GLdouble x, GLdouble y) +{ + DISPATCH(VertexAttrib2dNV, (index, x, y), (F, "glVertexAttrib2dNV(%d, %f, %f);\n", index, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2dvNV)(GLuint index, const GLdouble * v) +{ + DISPATCH(VertexAttrib2dvNV, (index, v), (F, "glVertexAttrib2dvNV(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2fNV)(GLuint index, GLfloat x, GLfloat y) +{ + DISPATCH(VertexAttrib2fNV, (index, x, y), (F, "glVertexAttrib2fNV(%d, %f, %f);\n", index, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2fvNV)(GLuint index, const GLfloat * v) +{ + DISPATCH(VertexAttrib2fvNV, (index, v), (F, "glVertexAttrib2fvNV(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2sNV)(GLuint index, GLshort x, GLshort y) +{ + DISPATCH(VertexAttrib2sNV, (index, x, y), (F, "glVertexAttrib2sNV(%d, %d, %d);\n", index, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib2svNV)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttrib2svNV, (index, v), (F, "glVertexAttrib2svNV(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3dNV)(GLuint index, GLdouble x, GLdouble y, GLdouble z) +{ + DISPATCH(VertexAttrib3dNV, (index, x, y, z), (F, "glVertexAttrib3dNV(%d, %f, %f, %f);\n", index, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3dvNV)(GLuint index, const GLdouble * v) +{ + DISPATCH(VertexAttrib3dvNV, (index, v), (F, "glVertexAttrib3dvNV(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3fNV)(GLuint index, GLfloat x, GLfloat y, GLfloat z) +{ + DISPATCH(VertexAttrib3fNV, (index, x, y, z), (F, "glVertexAttrib3fNV(%d, %f, %f, %f);\n", index, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3fvNV)(GLuint index, const GLfloat * v) +{ + DISPATCH(VertexAttrib3fvNV, (index, v), (F, "glVertexAttrib3fvNV(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3sNV)(GLuint index, GLshort x, GLshort y, GLshort z) +{ + DISPATCH(VertexAttrib3sNV, (index, x, y, z), (F, "glVertexAttrib3sNV(%d, %d, %d, %d);\n", index, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib3svNV)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttrib3svNV, (index, v), (F, "glVertexAttrib3svNV(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4dNV)(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w) +{ + DISPATCH(VertexAttrib4dNV, (index, x, y, z, w), (F, "glVertexAttrib4dNV(%d, %f, %f, %f, %f);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4dvNV)(GLuint index, const GLdouble * v) +{ + DISPATCH(VertexAttrib4dvNV, (index, v), (F, "glVertexAttrib4dvNV(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4fNV)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + DISPATCH(VertexAttrib4fNV, (index, x, y, z, w), (F, "glVertexAttrib4fNV(%d, %f, %f, %f, %f);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4fvNV)(GLuint index, const GLfloat * v) +{ + DISPATCH(VertexAttrib4fvNV, (index, v), (F, "glVertexAttrib4fvNV(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4sNV)(GLuint index, GLshort x, GLshort y, GLshort z, GLshort w) +{ + DISPATCH(VertexAttrib4sNV, (index, x, y, z, w), (F, "glVertexAttrib4sNV(%d, %d, %d, %d, %d);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4svNV)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttrib4svNV, (index, v), (F, "glVertexAttrib4svNV(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4ubNV)(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w) +{ + DISPATCH(VertexAttrib4ubNV, (index, x, y, z, w), (F, "glVertexAttrib4ubNV(%d, %d, %d, %d, %d);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttrib4ubvNV)(GLuint index, const GLubyte * v) +{ + DISPATCH(VertexAttrib4ubvNV, (index, v), (F, "glVertexAttrib4ubvNV(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribPointerNV)(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(VertexAttribPointerNV, (index, size, type, stride, pointer), (F, "glVertexAttribPointerNV(%d, %d, 0x%x, %d, %p);\n", index, size, type, stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribs1dvNV)(GLuint index, GLsizei n, const GLdouble * v) +{ + DISPATCH(VertexAttribs1dvNV, (index, n, v), (F, "glVertexAttribs1dvNV(%d, %d, %p);\n", index, n, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribs1fvNV)(GLuint index, GLsizei n, const GLfloat * v) +{ + DISPATCH(VertexAttribs1fvNV, (index, n, v), (F, "glVertexAttribs1fvNV(%d, %d, %p);\n", index, n, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribs1svNV)(GLuint index, GLsizei n, const GLshort * v) +{ + DISPATCH(VertexAttribs1svNV, (index, n, v), (F, "glVertexAttribs1svNV(%d, %d, %p);\n", index, n, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribs2dvNV)(GLuint index, GLsizei n, const GLdouble * v) +{ + DISPATCH(VertexAttribs2dvNV, (index, n, v), (F, "glVertexAttribs2dvNV(%d, %d, %p);\n", index, n, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribs2fvNV)(GLuint index, GLsizei n, const GLfloat * v) +{ + DISPATCH(VertexAttribs2fvNV, (index, n, v), (F, "glVertexAttribs2fvNV(%d, %d, %p);\n", index, n, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribs2svNV)(GLuint index, GLsizei n, const GLshort * v) +{ + DISPATCH(VertexAttribs2svNV, (index, n, v), (F, "glVertexAttribs2svNV(%d, %d, %p);\n", index, n, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribs3dvNV)(GLuint index, GLsizei n, const GLdouble * v) +{ + DISPATCH(VertexAttribs3dvNV, (index, n, v), (F, "glVertexAttribs3dvNV(%d, %d, %p);\n", index, n, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribs3fvNV)(GLuint index, GLsizei n, const GLfloat * v) +{ + DISPATCH(VertexAttribs3fvNV, (index, n, v), (F, "glVertexAttribs3fvNV(%d, %d, %p);\n", index, n, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribs3svNV)(GLuint index, GLsizei n, const GLshort * v) +{ + DISPATCH(VertexAttribs3svNV, (index, n, v), (F, "glVertexAttribs3svNV(%d, %d, %p);\n", index, n, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribs4dvNV)(GLuint index, GLsizei n, const GLdouble * v) +{ + DISPATCH(VertexAttribs4dvNV, (index, n, v), (F, "glVertexAttribs4dvNV(%d, %d, %p);\n", index, n, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribs4fvNV)(GLuint index, GLsizei n, const GLfloat * v) +{ + DISPATCH(VertexAttribs4fvNV, (index, n, v), (F, "glVertexAttribs4fvNV(%d, %d, %p);\n", index, n, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribs4svNV)(GLuint index, GLsizei n, const GLshort * v) +{ + DISPATCH(VertexAttribs4svNV, (index, n, v), (F, "glVertexAttribs4svNV(%d, %d, %p);\n", index, n, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribs4ubvNV)(GLuint index, GLsizei n, const GLubyte * v) +{ + DISPATCH(VertexAttribs4ubvNV, (index, n, v), (F, "glVertexAttribs4ubvNV(%d, %d, %p);\n", index, n, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexBumpParameterfvATI)(GLenum pname, GLfloat * param) +{ + DISPATCH(GetTexBumpParameterfvATI, (pname, param), (F, "glGetTexBumpParameterfvATI(0x%x, %p);\n", pname, (const void *) param)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexBumpParameterivATI)(GLenum pname, GLint * param) +{ + DISPATCH(GetTexBumpParameterivATI, (pname, param), (F, "glGetTexBumpParameterivATI(0x%x, %p);\n", pname, (const void *) param)); +} + +KEYWORD1 void KEYWORD2 NAME(TexBumpParameterfvATI)(GLenum pname, const GLfloat * param) +{ + DISPATCH(TexBumpParameterfvATI, (pname, param), (F, "glTexBumpParameterfvATI(0x%x, %p);\n", pname, (const void *) param)); +} + +KEYWORD1 void KEYWORD2 NAME(TexBumpParameterivATI)(GLenum pname, const GLint * param) +{ + DISPATCH(TexBumpParameterivATI, (pname, param), (F, "glTexBumpParameterivATI(0x%x, %p);\n", pname, (const void *) param)); +} + +KEYWORD1 void KEYWORD2 NAME(AlphaFragmentOp1ATI)(GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod) +{ + DISPATCH(AlphaFragmentOp1ATI, (op, dst, dstMod, arg1, arg1Rep, arg1Mod), (F, "glAlphaFragmentOp1ATI(0x%x, %d, %d, %d, %d, %d);\n", op, dst, dstMod, arg1, arg1Rep, arg1Mod)); +} + +KEYWORD1 void KEYWORD2 NAME(AlphaFragmentOp2ATI)(GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod) +{ + DISPATCH(AlphaFragmentOp2ATI, (op, dst, dstMod, arg1, arg1Rep, arg1Mod, arg2, arg2Rep, arg2Mod), (F, "glAlphaFragmentOp2ATI(0x%x, %d, %d, %d, %d, %d, %d, %d, %d);\n", op, dst, dstMod, arg1, arg1Rep, arg1Mod, arg2, arg2Rep, arg2Mod)); +} + +KEYWORD1 void KEYWORD2 NAME(AlphaFragmentOp3ATI)(GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod) +{ + DISPATCH(AlphaFragmentOp3ATI, (op, dst, dstMod, arg1, arg1Rep, arg1Mod, arg2, arg2Rep, arg2Mod, arg3, arg3Rep, arg3Mod), (F, "glAlphaFragmentOp3ATI(0x%x, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d);\n", op, dst, dstMod, arg1, arg1Rep, arg1Mod, arg2, arg2Rep, arg2Mod, arg3, arg3Rep, arg3Mod)); +} + +KEYWORD1 void KEYWORD2 NAME(BeginFragmentShaderATI)(void) +{ + DISPATCH(BeginFragmentShaderATI, (), (F, "glBeginFragmentShaderATI();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(BindFragmentShaderATI)(GLuint id) +{ + DISPATCH(BindFragmentShaderATI, (id), (F, "glBindFragmentShaderATI(%d);\n", id)); +} + +KEYWORD1 void KEYWORD2 NAME(ColorFragmentOp1ATI)(GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod) +{ + DISPATCH(ColorFragmentOp1ATI, (op, dst, dstMask, dstMod, arg1, arg1Rep, arg1Mod), (F, "glColorFragmentOp1ATI(0x%x, %d, %d, %d, %d, %d, %d);\n", op, dst, dstMask, dstMod, arg1, arg1Rep, arg1Mod)); +} + +KEYWORD1 void KEYWORD2 NAME(ColorFragmentOp2ATI)(GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod) +{ + DISPATCH(ColorFragmentOp2ATI, (op, dst, dstMask, dstMod, arg1, arg1Rep, arg1Mod, arg2, arg2Rep, arg2Mod), (F, "glColorFragmentOp2ATI(0x%x, %d, %d, %d, %d, %d, %d, %d, %d, %d);\n", op, dst, dstMask, dstMod, arg1, arg1Rep, arg1Mod, arg2, arg2Rep, arg2Mod)); +} + +KEYWORD1 void KEYWORD2 NAME(ColorFragmentOp3ATI)(GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod) +{ + DISPATCH(ColorFragmentOp3ATI, (op, dst, dstMask, dstMod, arg1, arg1Rep, arg1Mod, arg2, arg2Rep, arg2Mod, arg3, arg3Rep, arg3Mod), (F, "glColorFragmentOp3ATI(0x%x, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d);\n", op, dst, dstMask, dstMod, arg1, arg1Rep, arg1Mod, arg2, arg2Rep, arg2Mod, arg3, arg3Rep, arg3Mod)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteFragmentShaderATI)(GLuint id) +{ + DISPATCH(DeleteFragmentShaderATI, (id), (F, "glDeleteFragmentShaderATI(%d);\n", id)); +} + +KEYWORD1 void KEYWORD2 NAME(EndFragmentShaderATI)(void) +{ + DISPATCH(EndFragmentShaderATI, (), (F, "glEndFragmentShaderATI();\n")); +} + +KEYWORD1 GLuint KEYWORD2 NAME(GenFragmentShadersATI)(GLuint range) +{ + RETURN_DISPATCH(GenFragmentShadersATI, (range), (F, "glGenFragmentShadersATI(%d);\n", range)); +} + +KEYWORD1 void KEYWORD2 NAME(PassTexCoordATI)(GLuint dst, GLuint coord, GLenum swizzle) +{ + DISPATCH(PassTexCoordATI, (dst, coord, swizzle), (F, "glPassTexCoordATI(%d, %d, 0x%x);\n", dst, coord, swizzle)); +} + +KEYWORD1 void KEYWORD2 NAME(SampleMapATI)(GLuint dst, GLuint interp, GLenum swizzle) +{ + DISPATCH(SampleMapATI, (dst, interp, swizzle), (F, "glSampleMapATI(%d, %d, 0x%x);\n", dst, interp, swizzle)); +} + +KEYWORD1 void KEYWORD2 NAME(SetFragmentShaderConstantATI)(GLuint dst, const GLfloat * value) +{ + DISPATCH(SetFragmentShaderConstantATI, (dst, value), (F, "glSetFragmentShaderConstantATI(%d, %p);\n", dst, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(PointParameteri)(GLenum pname, GLint param) +{ + DISPATCH(PointParameteriNV, (pname, param), (F, "glPointParameteri(0x%x, %d);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(PointParameteriNV)(GLenum pname, GLint param) +{ + DISPATCH(PointParameteriNV, (pname, param), (F, "glPointParameteriNV(0x%x, %d);\n", pname, param)); +} + +KEYWORD1 void KEYWORD2 NAME(PointParameteriv)(GLenum pname, const GLint * params) +{ + DISPATCH(PointParameterivNV, (pname, params), (F, "glPointParameteriv(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(PointParameterivNV)(GLenum pname, const GLint * params) +{ + DISPATCH(PointParameterivNV, (pname, params), (F, "glPointParameterivNV(0x%x, %p);\n", pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_779)(GLenum face); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_779)(GLenum face) +{ + DISPATCH(ActiveStencilFaceEXT, (face), (F, "glActiveStencilFaceEXT(0x%x);\n", face)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_780)(GLuint array); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_780)(GLuint array) +{ + DISPATCH(BindVertexArrayAPPLE, (array), (F, "glBindVertexArrayAPPLE(%d);\n", array)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteVertexArrays)(GLsizei n, const GLuint * arrays) +{ + DISPATCH(DeleteVertexArraysAPPLE, (n, arrays), (F, "glDeleteVertexArrays(%d, %p);\n", n, (const void *) arrays)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_781)(GLsizei n, const GLuint * arrays); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_781)(GLsizei n, const GLuint * arrays) +{ + DISPATCH(DeleteVertexArraysAPPLE, (n, arrays), (F, "glDeleteVertexArraysAPPLE(%d, %p);\n", n, (const void *) arrays)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_782)(GLsizei n, GLuint * arrays); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_782)(GLsizei n, GLuint * arrays) +{ + DISPATCH(GenVertexArraysAPPLE, (n, arrays), (F, "glGenVertexArraysAPPLE(%d, %p);\n", n, (const void *) arrays)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsVertexArray)(GLuint array) +{ + RETURN_DISPATCH(IsVertexArrayAPPLE, (array), (F, "glIsVertexArray(%d);\n", array)); +} + +KEYWORD1_ALT GLboolean KEYWORD2 NAME(_dispatch_stub_783)(GLuint array); + +KEYWORD1_ALT GLboolean KEYWORD2 NAME(_dispatch_stub_783)(GLuint array) +{ + RETURN_DISPATCH(IsVertexArrayAPPLE, (array), (F, "glIsVertexArrayAPPLE(%d);\n", array)); +} + +KEYWORD1 void KEYWORD2 NAME(GetProgramNamedParameterdvNV)(GLuint id, GLsizei len, const GLubyte * name, GLdouble * params) +{ + DISPATCH(GetProgramNamedParameterdvNV, (id, len, name, params), (F, "glGetProgramNamedParameterdvNV(%d, %d, %p, %p);\n", id, len, (const void *) name, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetProgramNamedParameterfvNV)(GLuint id, GLsizei len, const GLubyte * name, GLfloat * params) +{ + DISPATCH(GetProgramNamedParameterfvNV, (id, len, name, params), (F, "glGetProgramNamedParameterfvNV(%d, %d, %p, %p);\n", id, len, (const void *) name, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramNamedParameter4dNV)(GLuint id, GLsizei len, const GLubyte * name, GLdouble x, GLdouble y, GLdouble z, GLdouble w) +{ + DISPATCH(ProgramNamedParameter4dNV, (id, len, name, x, y, z, w), (F, "glProgramNamedParameter4dNV(%d, %d, %p, %f, %f, %f, %f);\n", id, len, (const void *) name, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramNamedParameter4dvNV)(GLuint id, GLsizei len, const GLubyte * name, const GLdouble * v) +{ + DISPATCH(ProgramNamedParameter4dvNV, (id, len, name, v), (F, "glProgramNamedParameter4dvNV(%d, %d, %p, %p);\n", id, len, (const void *) name, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramNamedParameter4fNV)(GLuint id, GLsizei len, const GLubyte * name, GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + DISPATCH(ProgramNamedParameter4fNV, (id, len, name, x, y, z, w), (F, "glProgramNamedParameter4fNV(%d, %d, %p, %f, %f, %f, %f);\n", id, len, (const void *) name, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(ProgramNamedParameter4fvNV)(GLuint id, GLsizei len, const GLubyte * name, const GLfloat * v) +{ + DISPATCH(ProgramNamedParameter4fvNV, (id, len, name, v), (F, "glProgramNamedParameter4fvNV(%d, %d, %p, %p);\n", id, len, (const void *) name, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(PrimitiveRestartIndexNV)(GLuint index) +{ + DISPATCH(PrimitiveRestartIndexNV, (index), (F, "glPrimitiveRestartIndexNV(%d);\n", index)); +} + +KEYWORD1 void KEYWORD2 NAME(PrimitiveRestartIndex)(GLuint index) +{ + DISPATCH(PrimitiveRestartIndexNV, (index), (F, "glPrimitiveRestartIndex(%d);\n", index)); +} + +KEYWORD1 void KEYWORD2 NAME(PrimitiveRestartNV)(void) +{ + DISPATCH(PrimitiveRestartNV, (), (F, "glPrimitiveRestartNV();\n")); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_792)(GLclampd zmin, GLclampd zmax); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_792)(GLclampd zmin, GLclampd zmax) +{ + DISPATCH(DepthBoundsEXT, (zmin, zmax), (F, "glDepthBoundsEXT(%f, %f);\n", zmin, zmax)); +} + +KEYWORD1 void KEYWORD2 NAME(BlendEquationSeparate)(GLenum modeRGB, GLenum modeA) +{ + DISPATCH(BlendEquationSeparateEXT, (modeRGB, modeA), (F, "glBlendEquationSeparate(0x%x, 0x%x);\n", modeRGB, modeA)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_793)(GLenum modeRGB, GLenum modeA); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_793)(GLenum modeRGB, GLenum modeA) +{ + DISPATCH(BlendEquationSeparateEXT, (modeRGB, modeA), (F, "glBlendEquationSeparateEXT(0x%x, 0x%x);\n", modeRGB, modeA)); +} + +KEYWORD1 void KEYWORD2 NAME(BindFramebuffer)(GLenum target, GLuint framebuffer) +{ + DISPATCH(BindFramebufferEXT, (target, framebuffer), (F, "glBindFramebuffer(0x%x, %d);\n", target, framebuffer)); +} + +KEYWORD1 void KEYWORD2 NAME(BindFramebufferEXT)(GLenum target, GLuint framebuffer) +{ + DISPATCH(BindFramebufferEXT, (target, framebuffer), (F, "glBindFramebufferEXT(0x%x, %d);\n", target, framebuffer)); +} + +KEYWORD1 void KEYWORD2 NAME(BindRenderbuffer)(GLenum target, GLuint renderbuffer) +{ + DISPATCH(BindRenderbufferEXT, (target, renderbuffer), (F, "glBindRenderbuffer(0x%x, %d);\n", target, renderbuffer)); +} + +KEYWORD1 void KEYWORD2 NAME(BindRenderbufferEXT)(GLenum target, GLuint renderbuffer) +{ + DISPATCH(BindRenderbufferEXT, (target, renderbuffer), (F, "glBindRenderbufferEXT(0x%x, %d);\n", target, renderbuffer)); +} + +KEYWORD1 GLenum KEYWORD2 NAME(CheckFramebufferStatus)(GLenum target) +{ + RETURN_DISPATCH(CheckFramebufferStatusEXT, (target), (F, "glCheckFramebufferStatus(0x%x);\n", target)); +} + +KEYWORD1 GLenum KEYWORD2 NAME(CheckFramebufferStatusEXT)(GLenum target) +{ + RETURN_DISPATCH(CheckFramebufferStatusEXT, (target), (F, "glCheckFramebufferStatusEXT(0x%x);\n", target)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteFramebuffers)(GLsizei n, const GLuint * framebuffers) +{ + DISPATCH(DeleteFramebuffersEXT, (n, framebuffers), (F, "glDeleteFramebuffers(%d, %p);\n", n, (const void *) framebuffers)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteFramebuffersEXT)(GLsizei n, const GLuint * framebuffers) +{ + DISPATCH(DeleteFramebuffersEXT, (n, framebuffers), (F, "glDeleteFramebuffersEXT(%d, %p);\n", n, (const void *) framebuffers)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteRenderbuffers)(GLsizei n, const GLuint * renderbuffers) +{ + DISPATCH(DeleteRenderbuffersEXT, (n, renderbuffers), (F, "glDeleteRenderbuffers(%d, %p);\n", n, (const void *) renderbuffers)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteRenderbuffersEXT)(GLsizei n, const GLuint * renderbuffers) +{ + DISPATCH(DeleteRenderbuffersEXT, (n, renderbuffers), (F, "glDeleteRenderbuffersEXT(%d, %p);\n", n, (const void *) renderbuffers)); +} + +KEYWORD1 void KEYWORD2 NAME(FramebufferRenderbuffer)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) +{ + DISPATCH(FramebufferRenderbufferEXT, (target, attachment, renderbuffertarget, renderbuffer), (F, "glFramebufferRenderbuffer(0x%x, 0x%x, 0x%x, %d);\n", target, attachment, renderbuffertarget, renderbuffer)); +} + +KEYWORD1 void KEYWORD2 NAME(FramebufferRenderbufferEXT)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) +{ + DISPATCH(FramebufferRenderbufferEXT, (target, attachment, renderbuffertarget, renderbuffer), (F, "glFramebufferRenderbufferEXT(0x%x, 0x%x, 0x%x, %d);\n", target, attachment, renderbuffertarget, renderbuffer)); +} + +KEYWORD1 void KEYWORD2 NAME(FramebufferTexture1D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) +{ + DISPATCH(FramebufferTexture1DEXT, (target, attachment, textarget, texture, level), (F, "glFramebufferTexture1D(0x%x, 0x%x, 0x%x, %d, %d);\n", target, attachment, textarget, texture, level)); +} + +KEYWORD1 void KEYWORD2 NAME(FramebufferTexture1DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) +{ + DISPATCH(FramebufferTexture1DEXT, (target, attachment, textarget, texture, level), (F, "glFramebufferTexture1DEXT(0x%x, 0x%x, 0x%x, %d, %d);\n", target, attachment, textarget, texture, level)); +} + +KEYWORD1 void KEYWORD2 NAME(FramebufferTexture2D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) +{ + DISPATCH(FramebufferTexture2DEXT, (target, attachment, textarget, texture, level), (F, "glFramebufferTexture2D(0x%x, 0x%x, 0x%x, %d, %d);\n", target, attachment, textarget, texture, level)); +} + +KEYWORD1 void KEYWORD2 NAME(FramebufferTexture2DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) +{ + DISPATCH(FramebufferTexture2DEXT, (target, attachment, textarget, texture, level), (F, "glFramebufferTexture2DEXT(0x%x, 0x%x, 0x%x, %d, %d);\n", target, attachment, textarget, texture, level)); +} + +KEYWORD1 void KEYWORD2 NAME(FramebufferTexture3D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset) +{ + DISPATCH(FramebufferTexture3DEXT, (target, attachment, textarget, texture, level, zoffset), (F, "glFramebufferTexture3D(0x%x, 0x%x, 0x%x, %d, %d, %d);\n", target, attachment, textarget, texture, level, zoffset)); +} + +KEYWORD1 void KEYWORD2 NAME(FramebufferTexture3DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset) +{ + DISPATCH(FramebufferTexture3DEXT, (target, attachment, textarget, texture, level, zoffset), (F, "glFramebufferTexture3DEXT(0x%x, 0x%x, 0x%x, %d, %d, %d);\n", target, attachment, textarget, texture, level, zoffset)); +} + +KEYWORD1 void KEYWORD2 NAME(GenFramebuffers)(GLsizei n, GLuint * framebuffers) +{ + DISPATCH(GenFramebuffersEXT, (n, framebuffers), (F, "glGenFramebuffers(%d, %p);\n", n, (const void *) framebuffers)); +} + +KEYWORD1 void KEYWORD2 NAME(GenFramebuffersEXT)(GLsizei n, GLuint * framebuffers) +{ + DISPATCH(GenFramebuffersEXT, (n, framebuffers), (F, "glGenFramebuffersEXT(%d, %p);\n", n, (const void *) framebuffers)); +} + +KEYWORD1 void KEYWORD2 NAME(GenRenderbuffers)(GLsizei n, GLuint * renderbuffers) +{ + DISPATCH(GenRenderbuffersEXT, (n, renderbuffers), (F, "glGenRenderbuffers(%d, %p);\n", n, (const void *) renderbuffers)); +} + +KEYWORD1 void KEYWORD2 NAME(GenRenderbuffersEXT)(GLsizei n, GLuint * renderbuffers) +{ + DISPATCH(GenRenderbuffersEXT, (n, renderbuffers), (F, "glGenRenderbuffersEXT(%d, %p);\n", n, (const void *) renderbuffers)); +} + +KEYWORD1 void KEYWORD2 NAME(GenerateMipmap)(GLenum target) +{ + DISPATCH(GenerateMipmapEXT, (target), (F, "glGenerateMipmap(0x%x);\n", target)); +} + +KEYWORD1 void KEYWORD2 NAME(GenerateMipmapEXT)(GLenum target) +{ + DISPATCH(GenerateMipmapEXT, (target), (F, "glGenerateMipmapEXT(0x%x);\n", target)); +} + +KEYWORD1 void KEYWORD2 NAME(GetFramebufferAttachmentParameteriv)(GLenum target, GLenum attachment, GLenum pname, GLint * params) +{ + DISPATCH(GetFramebufferAttachmentParameterivEXT, (target, attachment, pname, params), (F, "glGetFramebufferAttachmentParameteriv(0x%x, 0x%x, 0x%x, %p);\n", target, attachment, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetFramebufferAttachmentParameterivEXT)(GLenum target, GLenum attachment, GLenum pname, GLint * params) +{ + DISPATCH(GetFramebufferAttachmentParameterivEXT, (target, attachment, pname, params), (F, "glGetFramebufferAttachmentParameterivEXT(0x%x, 0x%x, 0x%x, %p);\n", target, attachment, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetRenderbufferParameteriv)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetRenderbufferParameterivEXT, (target, pname, params), (F, "glGetRenderbufferParameteriv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetRenderbufferParameterivEXT)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetRenderbufferParameterivEXT, (target, pname, params), (F, "glGetRenderbufferParameterivEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsFramebuffer)(GLuint framebuffer) +{ + RETURN_DISPATCH(IsFramebufferEXT, (framebuffer), (F, "glIsFramebuffer(%d);\n", framebuffer)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsFramebufferEXT)(GLuint framebuffer) +{ + RETURN_DISPATCH(IsFramebufferEXT, (framebuffer), (F, "glIsFramebufferEXT(%d);\n", framebuffer)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsRenderbuffer)(GLuint renderbuffer) +{ + RETURN_DISPATCH(IsRenderbufferEXT, (renderbuffer), (F, "glIsRenderbuffer(%d);\n", renderbuffer)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsRenderbufferEXT)(GLuint renderbuffer) +{ + RETURN_DISPATCH(IsRenderbufferEXT, (renderbuffer), (F, "glIsRenderbufferEXT(%d);\n", renderbuffer)); +} + +KEYWORD1 void KEYWORD2 NAME(RenderbufferStorage)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) +{ + DISPATCH(RenderbufferStorageEXT, (target, internalformat, width, height), (F, "glRenderbufferStorage(0x%x, 0x%x, %d, %d);\n", target, internalformat, width, height)); +} + +KEYWORD1 void KEYWORD2 NAME(RenderbufferStorageEXT)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) +{ + DISPATCH(RenderbufferStorageEXT, (target, internalformat, width, height), (F, "glRenderbufferStorageEXT(0x%x, 0x%x, %d, %d);\n", target, internalformat, width, height)); +} + +KEYWORD1 void KEYWORD2 NAME(BlitFramebuffer)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) +{ + DISPATCH(BlitFramebufferEXT, (srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter), (F, "glBlitFramebuffer(%d, %d, %d, %d, %d, %d, %d, %d, %d, 0x%x);\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_811)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_811)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) +{ + DISPATCH(BlitFramebufferEXT, (srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter), (F, "glBlitFramebufferEXT(%d, %d, %d, %d, %d, %d, %d, %d, %d, 0x%x);\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_812)(GLenum target, GLenum pname, GLint param); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_812)(GLenum target, GLenum pname, GLint param) +{ + DISPATCH(BufferParameteriAPPLE, (target, pname, param), (F, "glBufferParameteriAPPLE(0x%x, 0x%x, %d);\n", target, pname, param)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_813)(GLenum target, GLintptr offset, GLsizeiptr size); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_813)(GLenum target, GLintptr offset, GLsizeiptr size) +{ + DISPATCH(FlushMappedBufferRangeAPPLE, (target, offset, size), (F, "glFlushMappedBufferRangeAPPLE(0x%x, %d, %d);\n", target, offset, size)); +} + +KEYWORD1 void KEYWORD2 NAME(BindFragDataLocationEXT)(GLuint program, GLuint colorNumber, const GLchar * name) +{ + DISPATCH(BindFragDataLocationEXT, (program, colorNumber, name), (F, "glBindFragDataLocationEXT(%d, %d, %p);\n", program, colorNumber, (const void *) name)); +} + +KEYWORD1 void KEYWORD2 NAME(BindFragDataLocation)(GLuint program, GLuint colorNumber, const GLchar * name) +{ + DISPATCH(BindFragDataLocationEXT, (program, colorNumber, name), (F, "glBindFragDataLocation(%d, %d, %p);\n", program, colorNumber, (const void *) name)); +} + +KEYWORD1 GLint KEYWORD2 NAME(GetFragDataLocationEXT)(GLuint program, const GLchar * name) +{ + RETURN_DISPATCH(GetFragDataLocationEXT, (program, name), (F, "glGetFragDataLocationEXT(%d, %p);\n", program, (const void *) name)); +} + +KEYWORD1 GLint KEYWORD2 NAME(GetFragDataLocation)(GLuint program, const GLchar * name) +{ + RETURN_DISPATCH(GetFragDataLocationEXT, (program, name), (F, "glGetFragDataLocation(%d, %p);\n", program, (const void *) name)); +} + +KEYWORD1 void KEYWORD2 NAME(GetUniformuivEXT)(GLuint program, GLint location, GLuint * params) +{ + DISPATCH(GetUniformuivEXT, (program, location, params), (F, "glGetUniformuivEXT(%d, %d, %p);\n", program, location, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetUniformuiv)(GLuint program, GLint location, GLuint * params) +{ + DISPATCH(GetUniformuivEXT, (program, location, params), (F, "glGetUniformuiv(%d, %d, %p);\n", program, location, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribIivEXT)(GLuint index, GLenum pname, GLint * params) +{ + DISPATCH(GetVertexAttribIivEXT, (index, pname, params), (F, "glGetVertexAttribIivEXT(%d, 0x%x, %p);\n", index, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribIiv)(GLuint index, GLenum pname, GLint * params) +{ + DISPATCH(GetVertexAttribIivEXT, (index, pname, params), (F, "glGetVertexAttribIiv(%d, 0x%x, %p);\n", index, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribIuivEXT)(GLuint index, GLenum pname, GLuint * params) +{ + DISPATCH(GetVertexAttribIuivEXT, (index, pname, params), (F, "glGetVertexAttribIuivEXT(%d, 0x%x, %p);\n", index, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetVertexAttribIuiv)(GLuint index, GLenum pname, GLuint * params) +{ + DISPATCH(GetVertexAttribIuivEXT, (index, pname, params), (F, "glGetVertexAttribIuiv(%d, 0x%x, %p);\n", index, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform1uiEXT)(GLint location, GLuint x) +{ + DISPATCH(Uniform1uiEXT, (location, x), (F, "glUniform1uiEXT(%d, %d);\n", location, x)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform1ui)(GLint location, GLuint x) +{ + DISPATCH(Uniform1uiEXT, (location, x), (F, "glUniform1ui(%d, %d);\n", location, x)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform1uivEXT)(GLint location, GLsizei count, const GLuint * value) +{ + DISPATCH(Uniform1uivEXT, (location, count, value), (F, "glUniform1uivEXT(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform1uiv)(GLint location, GLsizei count, const GLuint * value) +{ + DISPATCH(Uniform1uivEXT, (location, count, value), (F, "glUniform1uiv(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform2uiEXT)(GLint location, GLuint x, GLuint y) +{ + DISPATCH(Uniform2uiEXT, (location, x, y), (F, "glUniform2uiEXT(%d, %d, %d);\n", location, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform2ui)(GLint location, GLuint x, GLuint y) +{ + DISPATCH(Uniform2uiEXT, (location, x, y), (F, "glUniform2ui(%d, %d, %d);\n", location, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform2uivEXT)(GLint location, GLsizei count, const GLuint * value) +{ + DISPATCH(Uniform2uivEXT, (location, count, value), (F, "glUniform2uivEXT(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform2uiv)(GLint location, GLsizei count, const GLuint * value) +{ + DISPATCH(Uniform2uivEXT, (location, count, value), (F, "glUniform2uiv(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform3uiEXT)(GLint location, GLuint x, GLuint y, GLuint z) +{ + DISPATCH(Uniform3uiEXT, (location, x, y, z), (F, "glUniform3uiEXT(%d, %d, %d, %d);\n", location, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform3ui)(GLint location, GLuint x, GLuint y, GLuint z) +{ + DISPATCH(Uniform3uiEXT, (location, x, y, z), (F, "glUniform3ui(%d, %d, %d, %d);\n", location, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform3uivEXT)(GLint location, GLsizei count, const GLuint * value) +{ + DISPATCH(Uniform3uivEXT, (location, count, value), (F, "glUniform3uivEXT(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform3uiv)(GLint location, GLsizei count, const GLuint * value) +{ + DISPATCH(Uniform3uivEXT, (location, count, value), (F, "glUniform3uiv(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform4uiEXT)(GLint location, GLuint x, GLuint y, GLuint z, GLuint w) +{ + DISPATCH(Uniform4uiEXT, (location, x, y, z, w), (F, "glUniform4uiEXT(%d, %d, %d, %d, %d);\n", location, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform4ui)(GLint location, GLuint x, GLuint y, GLuint z, GLuint w) +{ + DISPATCH(Uniform4uiEXT, (location, x, y, z, w), (F, "glUniform4ui(%d, %d, %d, %d, %d);\n", location, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform4uivEXT)(GLint location, GLsizei count, const GLuint * value) +{ + DISPATCH(Uniform4uivEXT, (location, count, value), (F, "glUniform4uivEXT(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(Uniform4uiv)(GLint location, GLsizei count, const GLuint * value) +{ + DISPATCH(Uniform4uivEXT, (location, count, value), (F, "glUniform4uiv(%d, %d, %p);\n", location, count, (const void *) value)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI1iEXT)(GLuint index, GLint x) +{ + DISPATCH(VertexAttribI1iEXT, (index, x), (F, "glVertexAttribI1iEXT(%d, %d);\n", index, x)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI1i)(GLuint index, GLint x) +{ + DISPATCH(VertexAttribI1iEXT, (index, x), (F, "glVertexAttribI1i(%d, %d);\n", index, x)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI1ivEXT)(GLuint index, const GLint * v) +{ + DISPATCH(VertexAttribI1ivEXT, (index, v), (F, "glVertexAttribI1ivEXT(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI1iv)(GLuint index, const GLint * v) +{ + DISPATCH(VertexAttribI1ivEXT, (index, v), (F, "glVertexAttribI1iv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI1uiEXT)(GLuint index, GLuint x) +{ + DISPATCH(VertexAttribI1uiEXT, (index, x), (F, "glVertexAttribI1uiEXT(%d, %d);\n", index, x)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI1ui)(GLuint index, GLuint x) +{ + DISPATCH(VertexAttribI1uiEXT, (index, x), (F, "glVertexAttribI1ui(%d, %d);\n", index, x)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI1uivEXT)(GLuint index, const GLuint * v) +{ + DISPATCH(VertexAttribI1uivEXT, (index, v), (F, "glVertexAttribI1uivEXT(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI1uiv)(GLuint index, const GLuint * v) +{ + DISPATCH(VertexAttribI1uivEXT, (index, v), (F, "glVertexAttribI1uiv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI2iEXT)(GLuint index, GLint x, GLint y) +{ + DISPATCH(VertexAttribI2iEXT, (index, x, y), (F, "glVertexAttribI2iEXT(%d, %d, %d);\n", index, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI2i)(GLuint index, GLint x, GLint y) +{ + DISPATCH(VertexAttribI2iEXT, (index, x, y), (F, "glVertexAttribI2i(%d, %d, %d);\n", index, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI2ivEXT)(GLuint index, const GLint * v) +{ + DISPATCH(VertexAttribI2ivEXT, (index, v), (F, "glVertexAttribI2ivEXT(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI2iv)(GLuint index, const GLint * v) +{ + DISPATCH(VertexAttribI2ivEXT, (index, v), (F, "glVertexAttribI2iv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI2uiEXT)(GLuint index, GLuint x, GLuint y) +{ + DISPATCH(VertexAttribI2uiEXT, (index, x, y), (F, "glVertexAttribI2uiEXT(%d, %d, %d);\n", index, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI2ui)(GLuint index, GLuint x, GLuint y) +{ + DISPATCH(VertexAttribI2uiEXT, (index, x, y), (F, "glVertexAttribI2ui(%d, %d, %d);\n", index, x, y)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI2uivEXT)(GLuint index, const GLuint * v) +{ + DISPATCH(VertexAttribI2uivEXT, (index, v), (F, "glVertexAttribI2uivEXT(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI2uiv)(GLuint index, const GLuint * v) +{ + DISPATCH(VertexAttribI2uivEXT, (index, v), (F, "glVertexAttribI2uiv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI3iEXT)(GLuint index, GLint x, GLint y, GLint z) +{ + DISPATCH(VertexAttribI3iEXT, (index, x, y, z), (F, "glVertexAttribI3iEXT(%d, %d, %d, %d);\n", index, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI3i)(GLuint index, GLint x, GLint y, GLint z) +{ + DISPATCH(VertexAttribI3iEXT, (index, x, y, z), (F, "glVertexAttribI3i(%d, %d, %d, %d);\n", index, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI3ivEXT)(GLuint index, const GLint * v) +{ + DISPATCH(VertexAttribI3ivEXT, (index, v), (F, "glVertexAttribI3ivEXT(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI3iv)(GLuint index, const GLint * v) +{ + DISPATCH(VertexAttribI3ivEXT, (index, v), (F, "glVertexAttribI3iv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI3uiEXT)(GLuint index, GLuint x, GLuint y, GLuint z) +{ + DISPATCH(VertexAttribI3uiEXT, (index, x, y, z), (F, "glVertexAttribI3uiEXT(%d, %d, %d, %d);\n", index, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI3ui)(GLuint index, GLuint x, GLuint y, GLuint z) +{ + DISPATCH(VertexAttribI3uiEXT, (index, x, y, z), (F, "glVertexAttribI3ui(%d, %d, %d, %d);\n", index, x, y, z)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI3uivEXT)(GLuint index, const GLuint * v) +{ + DISPATCH(VertexAttribI3uivEXT, (index, v), (F, "glVertexAttribI3uivEXT(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI3uiv)(GLuint index, const GLuint * v) +{ + DISPATCH(VertexAttribI3uivEXT, (index, v), (F, "glVertexAttribI3uiv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4bvEXT)(GLuint index, const GLbyte * v) +{ + DISPATCH(VertexAttribI4bvEXT, (index, v), (F, "glVertexAttribI4bvEXT(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4bv)(GLuint index, const GLbyte * v) +{ + DISPATCH(VertexAttribI4bvEXT, (index, v), (F, "glVertexAttribI4bv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4iEXT)(GLuint index, GLint x, GLint y, GLint z, GLint w) +{ + DISPATCH(VertexAttribI4iEXT, (index, x, y, z, w), (F, "glVertexAttribI4iEXT(%d, %d, %d, %d, %d);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4i)(GLuint index, GLint x, GLint y, GLint z, GLint w) +{ + DISPATCH(VertexAttribI4iEXT, (index, x, y, z, w), (F, "glVertexAttribI4i(%d, %d, %d, %d, %d);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4ivEXT)(GLuint index, const GLint * v) +{ + DISPATCH(VertexAttribI4ivEXT, (index, v), (F, "glVertexAttribI4ivEXT(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4iv)(GLuint index, const GLint * v) +{ + DISPATCH(VertexAttribI4ivEXT, (index, v), (F, "glVertexAttribI4iv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4svEXT)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttribI4svEXT, (index, v), (F, "glVertexAttribI4svEXT(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4sv)(GLuint index, const GLshort * v) +{ + DISPATCH(VertexAttribI4svEXT, (index, v), (F, "glVertexAttribI4sv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4ubvEXT)(GLuint index, const GLubyte * v) +{ + DISPATCH(VertexAttribI4ubvEXT, (index, v), (F, "glVertexAttribI4ubvEXT(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4ubv)(GLuint index, const GLubyte * v) +{ + DISPATCH(VertexAttribI4ubvEXT, (index, v), (F, "glVertexAttribI4ubv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4uiEXT)(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w) +{ + DISPATCH(VertexAttribI4uiEXT, (index, x, y, z, w), (F, "glVertexAttribI4uiEXT(%d, %d, %d, %d, %d);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4ui)(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w) +{ + DISPATCH(VertexAttribI4uiEXT, (index, x, y, z, w), (F, "glVertexAttribI4ui(%d, %d, %d, %d, %d);\n", index, x, y, z, w)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4uivEXT)(GLuint index, const GLuint * v) +{ + DISPATCH(VertexAttribI4uivEXT, (index, v), (F, "glVertexAttribI4uivEXT(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4uiv)(GLuint index, const GLuint * v) +{ + DISPATCH(VertexAttribI4uivEXT, (index, v), (F, "glVertexAttribI4uiv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4usvEXT)(GLuint index, const GLushort * v) +{ + DISPATCH(VertexAttribI4usvEXT, (index, v), (F, "glVertexAttribI4usvEXT(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribI4usv)(GLuint index, const GLushort * v) +{ + DISPATCH(VertexAttribI4usvEXT, (index, v), (F, "glVertexAttribI4usv(%d, %p);\n", index, (const void *) v)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribIPointerEXT)(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(VertexAttribIPointerEXT, (index, size, type, stride, pointer), (F, "glVertexAttribIPointerEXT(%d, %d, 0x%x, %d, %p);\n", index, size, type, stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(VertexAttribIPointer)(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) +{ + DISPATCH(VertexAttribIPointerEXT, (index, size, type, stride, pointer), (F, "glVertexAttribIPointer(%d, %d, 0x%x, %d, %p);\n", index, size, type, stride, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(FramebufferTextureLayer)(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer) +{ + DISPATCH(FramebufferTextureLayerEXT, (target, attachment, texture, level, layer), (F, "glFramebufferTextureLayer(0x%x, 0x%x, %d, %d, %d);\n", target, attachment, texture, level, layer)); +} + +KEYWORD1 void KEYWORD2 NAME(FramebufferTextureLayerEXT)(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer) +{ + DISPATCH(FramebufferTextureLayerEXT, (target, attachment, texture, level, layer), (F, "glFramebufferTextureLayerEXT(0x%x, 0x%x, %d, %d, %d);\n", target, attachment, texture, level, layer)); +} + +KEYWORD1 void KEYWORD2 NAME(ColorMaskIndexedEXT)(GLuint buf, GLboolean r, GLboolean g, GLboolean b, GLboolean a) +{ + DISPATCH(ColorMaskIndexedEXT, (buf, r, g, b, a), (F, "glColorMaskIndexedEXT(%d, %d, %d, %d, %d);\n", buf, r, g, b, a)); +} + +KEYWORD1 void KEYWORD2 NAME(ColorMaski)(GLuint buf, GLboolean r, GLboolean g, GLboolean b, GLboolean a) +{ + DISPATCH(ColorMaskIndexedEXT, (buf, r, g, b, a), (F, "glColorMaski(%d, %d, %d, %d, %d);\n", buf, r, g, b, a)); +} + +KEYWORD1 void KEYWORD2 NAME(DisableIndexedEXT)(GLenum target, GLuint index) +{ + DISPATCH(DisableIndexedEXT, (target, index), (F, "glDisableIndexedEXT(0x%x, %d);\n", target, index)); +} + +KEYWORD1 void KEYWORD2 NAME(Disablei)(GLenum target, GLuint index) +{ + DISPATCH(DisableIndexedEXT, (target, index), (F, "glDisablei(0x%x, %d);\n", target, index)); +} + +KEYWORD1 void KEYWORD2 NAME(EnableIndexedEXT)(GLenum target, GLuint index) +{ + DISPATCH(EnableIndexedEXT, (target, index), (F, "glEnableIndexedEXT(0x%x, %d);\n", target, index)); +} + +KEYWORD1 void KEYWORD2 NAME(Enablei)(GLenum target, GLuint index) +{ + DISPATCH(EnableIndexedEXT, (target, index), (F, "glEnablei(0x%x, %d);\n", target, index)); +} + +KEYWORD1 void KEYWORD2 NAME(GetBooleanIndexedvEXT)(GLenum value, GLuint index, GLboolean * data) +{ + DISPATCH(GetBooleanIndexedvEXT, (value, index, data), (F, "glGetBooleanIndexedvEXT(0x%x, %d, %p);\n", value, index, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(GetBooleani_v)(GLenum value, GLuint index, GLboolean * data) +{ + DISPATCH(GetBooleanIndexedvEXT, (value, index, data), (F, "glGetBooleani_v(0x%x, %d, %p);\n", value, index, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(GetIntegerIndexedvEXT)(GLenum value, GLuint index, GLint * data) +{ + DISPATCH(GetIntegerIndexedvEXT, (value, index, data), (F, "glGetIntegerIndexedvEXT(0x%x, %d, %p);\n", value, index, (const void *) data)); +} + +KEYWORD1 void KEYWORD2 NAME(GetIntegeri_v)(GLenum value, GLuint index, GLint * data) +{ + DISPATCH(GetIntegerIndexedvEXT, (value, index, data), (F, "glGetIntegeri_v(0x%x, %d, %p);\n", value, index, (const void *) data)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsEnabledIndexedEXT)(GLenum target, GLuint index) +{ + RETURN_DISPATCH(IsEnabledIndexedEXT, (target, index), (F, "glIsEnabledIndexedEXT(0x%x, %d);\n", target, index)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsEnabledi)(GLenum target, GLuint index) +{ + RETURN_DISPATCH(IsEnabledIndexedEXT, (target, index), (F, "glIsEnabledi(0x%x, %d);\n", target, index)); +} + +KEYWORD1 void KEYWORD2 NAME(ClearColorIiEXT)(GLint r, GLint g, GLint b, GLint a) +{ + DISPATCH(ClearColorIiEXT, (r, g, b, a), (F, "glClearColorIiEXT(%d, %d, %d, %d);\n", r, g, b, a)); +} + +KEYWORD1 void KEYWORD2 NAME(ClearColorIuiEXT)(GLuint r, GLuint g, GLuint b, GLuint a) +{ + DISPATCH(ClearColorIuiEXT, (r, g, b, a), (F, "glClearColorIuiEXT(%d, %d, %d, %d);\n", r, g, b, a)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexParameterIivEXT)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetTexParameterIivEXT, (target, pname, params), (F, "glGetTexParameterIivEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexParameterIiv)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetTexParameterIivEXT, (target, pname, params), (F, "glGetTexParameterIiv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexParameterIuivEXT)(GLenum target, GLenum pname, GLuint * params) +{ + DISPATCH(GetTexParameterIuivEXT, (target, pname, params), (F, "glGetTexParameterIuivEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTexParameterIuiv)(GLenum target, GLenum pname, GLuint * params) +{ + DISPATCH(GetTexParameterIuivEXT, (target, pname, params), (F, "glGetTexParameterIuiv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(TexParameterIivEXT)(GLenum target, GLenum pname, const GLint * params) +{ + DISPATCH(TexParameterIivEXT, (target, pname, params), (F, "glTexParameterIivEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(TexParameterIiv)(GLenum target, GLenum pname, const GLint * params) +{ + DISPATCH(TexParameterIivEXT, (target, pname, params), (F, "glTexParameterIiv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(TexParameterIuivEXT)(GLenum target, GLenum pname, const GLuint * params) +{ + DISPATCH(TexParameterIuivEXT, (target, pname, params), (F, "glTexParameterIuivEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(TexParameterIuiv)(GLenum target, GLenum pname, const GLuint * params) +{ + DISPATCH(TexParameterIuivEXT, (target, pname, params), (F, "glTexParameterIuiv(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(BeginConditionalRenderNV)(GLuint query, GLenum mode) +{ + DISPATCH(BeginConditionalRenderNV, (query, mode), (F, "glBeginConditionalRenderNV(%d, 0x%x);\n", query, mode)); +} + +KEYWORD1 void KEYWORD2 NAME(BeginConditionalRender)(GLuint query, GLenum mode) +{ + DISPATCH(BeginConditionalRenderNV, (query, mode), (F, "glBeginConditionalRender(%d, 0x%x);\n", query, mode)); +} + +KEYWORD1 void KEYWORD2 NAME(EndConditionalRenderNV)(void) +{ + DISPATCH(EndConditionalRenderNV, (), (F, "glEndConditionalRenderNV();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(EndConditionalRender)(void) +{ + DISPATCH(EndConditionalRenderNV, (), (F, "glEndConditionalRender();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(BeginTransformFeedbackEXT)(GLenum mode) +{ + DISPATCH(BeginTransformFeedbackEXT, (mode), (F, "glBeginTransformFeedbackEXT(0x%x);\n", mode)); +} + +KEYWORD1 void KEYWORD2 NAME(BeginTransformFeedback)(GLenum mode) +{ + DISPATCH(BeginTransformFeedbackEXT, (mode), (F, "glBeginTransformFeedback(0x%x);\n", mode)); +} + +KEYWORD1 void KEYWORD2 NAME(BindBufferBaseEXT)(GLenum target, GLuint index, GLuint buffer) +{ + DISPATCH(BindBufferBaseEXT, (target, index, buffer), (F, "glBindBufferBaseEXT(0x%x, %d, %d);\n", target, index, buffer)); +} + +KEYWORD1 void KEYWORD2 NAME(BindBufferBase)(GLenum target, GLuint index, GLuint buffer) +{ + DISPATCH(BindBufferBaseEXT, (target, index, buffer), (F, "glBindBufferBase(0x%x, %d, %d);\n", target, index, buffer)); +} + +KEYWORD1 void KEYWORD2 NAME(BindBufferOffsetEXT)(GLenum target, GLuint index, GLuint buffer, GLintptr offset) +{ + DISPATCH(BindBufferOffsetEXT, (target, index, buffer, offset), (F, "glBindBufferOffsetEXT(0x%x, %d, %d, %d);\n", target, index, buffer, offset)); +} + +KEYWORD1 void KEYWORD2 NAME(BindBufferRangeEXT)(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size) +{ + DISPATCH(BindBufferRangeEXT, (target, index, buffer, offset, size), (F, "glBindBufferRangeEXT(0x%x, %d, %d, %d, %d);\n", target, index, buffer, offset, size)); +} + +KEYWORD1 void KEYWORD2 NAME(BindBufferRange)(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size) +{ + DISPATCH(BindBufferRangeEXT, (target, index, buffer, offset, size), (F, "glBindBufferRange(0x%x, %d, %d, %d, %d);\n", target, index, buffer, offset, size)); +} + +KEYWORD1 void KEYWORD2 NAME(EndTransformFeedbackEXT)(void) +{ + DISPATCH(EndTransformFeedbackEXT, (), (F, "glEndTransformFeedbackEXT();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(EndTransformFeedback)(void) +{ + DISPATCH(EndTransformFeedbackEXT, (), (F, "glEndTransformFeedback();\n")); +} + +KEYWORD1 void KEYWORD2 NAME(GetTransformFeedbackVaryingEXT)(GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLsizei * size, GLenum * type, GLchar * name) +{ + DISPATCH(GetTransformFeedbackVaryingEXT, (program, index, bufSize, length, size, type, name), (F, "glGetTransformFeedbackVaryingEXT(%d, %d, %d, %p, %p, %p, %p);\n", program, index, bufSize, (const void *) length, (const void *) size, (const void *) type, (const void *) name)); +} + +KEYWORD1 void KEYWORD2 NAME(GetTransformFeedbackVarying)(GLuint program, GLuint index, GLsizei bufSize, GLsizei * length, GLsizei * size, GLenum * type, GLchar * name) +{ + DISPATCH(GetTransformFeedbackVaryingEXT, (program, index, bufSize, length, size, type, name), (F, "glGetTransformFeedbackVarying(%d, %d, %d, %p, %p, %p, %p);\n", program, index, bufSize, (const void *) length, (const void *) size, (const void *) type, (const void *) name)); +} + +KEYWORD1 void KEYWORD2 NAME(TransformFeedbackVaryingsEXT)(GLuint program, GLsizei count, const char ** varyings, GLenum bufferMode) +{ + DISPATCH(TransformFeedbackVaryingsEXT, (program, count, varyings, bufferMode), (F, "glTransformFeedbackVaryingsEXT(%d, %d, %p, 0x%x);\n", program, count, (const void *) varyings, bufferMode)); +} + +KEYWORD1 void KEYWORD2 NAME(TransformFeedbackVaryings)(GLuint program, GLsizei count, const GLchar* * varyings, GLenum bufferMode) +{ + DISPATCH(TransformFeedbackVaryingsEXT, (program, count, varyings, bufferMode), (F, "glTransformFeedbackVaryings(%d, %d, %p, 0x%x);\n", program, count, (const void *) varyings, bufferMode)); +} + +KEYWORD1 void KEYWORD2 NAME(ProvokingVertexEXT)(GLenum mode) +{ + DISPATCH(ProvokingVertexEXT, (mode), (F, "glProvokingVertexEXT(0x%x);\n", mode)); +} + +KEYWORD1 void KEYWORD2 NAME(ProvokingVertex)(GLenum mode) +{ + DISPATCH(ProvokingVertexEXT, (mode), (F, "glProvokingVertex(0x%x);\n", mode)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_871)(GLenum target, GLenum pname, GLvoid ** params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_871)(GLenum target, GLenum pname, GLvoid ** params) +{ + DISPATCH(GetTexParameterPointervAPPLE, (target, pname, params), (F, "glGetTexParameterPointervAPPLE(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_872)(GLenum target, GLsizei length, GLvoid * pointer); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_872)(GLenum target, GLsizei length, GLvoid * pointer) +{ + DISPATCH(TextureRangeAPPLE, (target, length, pointer), (F, "glTextureRangeAPPLE(0x%x, %d, %p);\n", target, length, (const void *) pointer)); +} + +KEYWORD1 void KEYWORD2 NAME(GetObjectParameterivAPPLE)(GLenum objectType, GLuint name, GLenum pname, GLint * value) +{ + DISPATCH(GetObjectParameterivAPPLE, (objectType, name, pname, value), (F, "glGetObjectParameterivAPPLE(0x%x, %d, 0x%x, %p);\n", objectType, name, pname, (const void *) value)); +} + +KEYWORD1 GLenum KEYWORD2 NAME(ObjectPurgeableAPPLE)(GLenum objectType, GLuint name, GLenum option) +{ + RETURN_DISPATCH(ObjectPurgeableAPPLE, (objectType, name, option), (F, "glObjectPurgeableAPPLE(0x%x, %d, 0x%x);\n", objectType, name, option)); +} + +KEYWORD1 GLenum KEYWORD2 NAME(ObjectUnpurgeableAPPLE)(GLenum objectType, GLuint name, GLenum option) +{ + RETURN_DISPATCH(ObjectUnpurgeableAPPLE, (objectType, name, option), (F, "glObjectUnpurgeableAPPLE(0x%x, %d, 0x%x);\n", objectType, name, option)); +} + +KEYWORD1 void KEYWORD2 NAME(ActiveProgramEXT)(GLuint program) +{ + DISPATCH(ActiveProgramEXT, (program), (F, "glActiveProgramEXT(%d);\n", program)); +} + +KEYWORD1 GLuint KEYWORD2 NAME(CreateShaderProgramEXT)(GLenum type, const GLchar * string) +{ + RETURN_DISPATCH(CreateShaderProgramEXT, (type, string), (F, "glCreateShaderProgramEXT(0x%x, %p);\n", type, (const void *) string)); +} + +KEYWORD1 void KEYWORD2 NAME(UseShaderProgramEXT)(GLenum type, GLuint program) +{ + DISPATCH(UseShaderProgramEXT, (type, program), (F, "glUseShaderProgramEXT(0x%x, %d);\n", type, program)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_879)(GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_879)(GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask) +{ + DISPATCH(StencilFuncSeparateATI, (frontfunc, backfunc, ref, mask), (F, "glStencilFuncSeparateATI(0x%x, 0x%x, %d, %d);\n", frontfunc, backfunc, ref, mask)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_880)(GLenum target, GLuint index, GLsizei count, const GLfloat * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_880)(GLenum target, GLuint index, GLsizei count, const GLfloat * params) +{ + DISPATCH(ProgramEnvParameters4fvEXT, (target, index, count, params), (F, "glProgramEnvParameters4fvEXT(0x%x, %d, %d, %p);\n", target, index, count, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_881)(GLenum target, GLuint index, GLsizei count, const GLfloat * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_881)(GLenum target, GLuint index, GLsizei count, const GLfloat * params) +{ + DISPATCH(ProgramLocalParameters4fvEXT, (target, index, count, params), (F, "glProgramLocalParameters4fvEXT(0x%x, %d, %d, %p);\n", target, index, count, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_882)(GLuint id, GLenum pname, GLint64EXT * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_882)(GLuint id, GLenum pname, GLint64EXT * params) +{ + DISPATCH(GetQueryObjecti64vEXT, (id, pname, params), (F, "glGetQueryObjecti64vEXT(%d, 0x%x, %p);\n", id, pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_883)(GLuint id, GLenum pname, GLuint64EXT * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_883)(GLuint id, GLenum pname, GLuint64EXT * params) +{ + DISPATCH(GetQueryObjectui64vEXT, (id, pname, params), (F, "glGetQueryObjectui64vEXT(%d, 0x%x, %p);\n", id, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(EGLImageTargetRenderbufferStorageOES)(GLenum target, GLvoid * writeOffset) +{ + DISPATCH(EGLImageTargetRenderbufferStorageOES, (target, writeOffset), (F, "glEGLImageTargetRenderbufferStorageOES(0x%x, %p);\n", target, (const void *) writeOffset)); +} + +KEYWORD1 void KEYWORD2 NAME(EGLImageTargetTexture2DOES)(GLenum target, GLvoid * writeOffset) +{ + DISPATCH(EGLImageTargetTexture2DOES, (target, writeOffset), (F, "glEGLImageTargetTexture2DOES(0x%x, %p);\n", target, (const void *) writeOffset)); +} + + +#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */ + +/* these entry points might require different protocols */ +#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS + +KEYWORD1 GLboolean KEYWORD2 NAME(AreTexturesResidentEXT)(GLsizei n, const GLuint * textures, GLboolean * residences) +{ + RETURN_DISPATCH(AreTexturesResident, (n, textures, residences), (F, "glAreTexturesResidentEXT(%d, %p, %p);\n", n, (const void *) textures, (const void *) residences)); +} + +KEYWORD1 void KEYWORD2 NAME(DeleteTexturesEXT)(GLsizei n, const GLuint * textures) +{ + DISPATCH(DeleteTextures, (n, textures), (F, "glDeleteTexturesEXT(%d, %p);\n", n, (const void *) textures)); +} + +KEYWORD1 void KEYWORD2 NAME(GenTexturesEXT)(GLsizei n, GLuint * textures) +{ + DISPATCH(GenTextures, (n, textures), (F, "glGenTexturesEXT(%d, %p);\n", n, (const void *) textures)); +} + +KEYWORD1 GLboolean KEYWORD2 NAME(IsTextureEXT)(GLuint texture) +{ + RETURN_DISPATCH(IsTexture, (texture), (F, "glIsTextureEXT(%d);\n", texture)); +} + +KEYWORD1 void KEYWORD2 NAME(GetColorTableEXT)(GLenum target, GLenum format, GLenum type, GLvoid * table) +{ + DISPATCH(GetColorTable, (target, format, type, table), (F, "glGetColorTableEXT(0x%x, 0x%x, 0x%x, %p);\n", target, format, type, (const void *) table)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_343)(GLenum target, GLenum format, GLenum type, GLvoid * table); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_343)(GLenum target, GLenum format, GLenum type, GLvoid * table) +{ + DISPATCH(GetColorTable, (target, format, type, table), (F, "glGetColorTableSGI(0x%x, 0x%x, 0x%x, %p);\n", target, format, type, (const void *) table)); +} + +KEYWORD1 void KEYWORD2 NAME(GetColorTableParameterfvEXT)(GLenum target, GLenum pname, GLfloat * params) +{ + DISPATCH(GetColorTableParameterfv, (target, pname, params), (F, "glGetColorTableParameterfvEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_344)(GLenum target, GLenum pname, GLfloat * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_344)(GLenum target, GLenum pname, GLfloat * params) +{ + DISPATCH(GetColorTableParameterfv, (target, pname, params), (F, "glGetColorTableParameterfvSGI(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1 void KEYWORD2 NAME(GetColorTableParameterivEXT)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetColorTableParameteriv, (target, pname, params), (F, "glGetColorTableParameterivEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_345)(GLenum target, GLenum pname, GLint * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_345)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetColorTableParameteriv, (target, pname, params), (F, "glGetColorTableParameterivSGI(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_356)(GLenum target, GLenum format, GLenum type, GLvoid * image); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_356)(GLenum target, GLenum format, GLenum type, GLvoid * image) +{ + DISPATCH(GetConvolutionFilter, (target, format, type, image), (F, "glGetConvolutionFilterEXT(0x%x, 0x%x, 0x%x, %p);\n", target, format, type, (const void *) image)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_357)(GLenum target, GLenum pname, GLfloat * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_357)(GLenum target, GLenum pname, GLfloat * params) +{ + DISPATCH(GetConvolutionParameterfv, (target, pname, params), (F, "glGetConvolutionParameterfvEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_358)(GLenum target, GLenum pname, GLint * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_358)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetConvolutionParameteriv, (target, pname, params), (F, "glGetConvolutionParameterivEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_359)(GLenum target, GLenum format, GLenum type, GLvoid * row, GLvoid * column, GLvoid * span); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_359)(GLenum target, GLenum format, GLenum type, GLvoid * row, GLvoid * column, GLvoid * span) +{ + DISPATCH(GetSeparableFilter, (target, format, type, row, column, span), (F, "glGetSeparableFilterEXT(0x%x, 0x%x, 0x%x, %p, %p, %p);\n", target, format, type, (const void *) row, (const void *) column, (const void *) span)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_361)(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid * values); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_361)(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid * values) +{ + DISPATCH(GetHistogram, (target, reset, format, type, values), (F, "glGetHistogramEXT(0x%x, %d, 0x%x, 0x%x, %p);\n", target, reset, format, type, (const void *) values)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_362)(GLenum target, GLenum pname, GLfloat * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_362)(GLenum target, GLenum pname, GLfloat * params) +{ + DISPATCH(GetHistogramParameterfv, (target, pname, params), (F, "glGetHistogramParameterfvEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_363)(GLenum target, GLenum pname, GLint * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_363)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetHistogramParameteriv, (target, pname, params), (F, "glGetHistogramParameterivEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_364)(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid * values); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_364)(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid * values) +{ + DISPATCH(GetMinmax, (target, reset, format, type, values), (F, "glGetMinmaxEXT(0x%x, %d, 0x%x, 0x%x, %p);\n", target, reset, format, type, (const void *) values)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_365)(GLenum target, GLenum pname, GLfloat * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_365)(GLenum target, GLenum pname, GLfloat * params) +{ + DISPATCH(GetMinmaxParameterfv, (target, pname, params), (F, "glGetMinmaxParameterfvEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_366)(GLenum target, GLenum pname, GLint * params); + +KEYWORD1_ALT void KEYWORD2 NAME(_dispatch_stub_366)(GLenum target, GLenum pname, GLint * params) +{ + DISPATCH(GetMinmaxParameteriv, (target, pname, params), (F, "glGetMinmaxParameterivEXT(0x%x, 0x%x, %p);\n", target, pname, (const void *) params)); +} + + +#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */ + + +#endif /* defined( NAME ) */ + +/* + * This is how a dispatch table can be initialized with all the functions + * we generated above. + */ +#ifdef DISPATCH_TABLE_NAME + +#ifndef TABLE_ENTRY +#error TABLE_ENTRY must be defined +#endif + +#ifdef _GLAPI_SKIP_NORMAL_ENTRY_POINTS +#error _GLAPI_SKIP_NORMAL_ENTRY_POINTS must not be defined +#endif + +_glapi_proc DISPATCH_TABLE_NAME[] = { + TABLE_ENTRY(NewList), + TABLE_ENTRY(EndList), + TABLE_ENTRY(CallList), + TABLE_ENTRY(CallLists), + TABLE_ENTRY(DeleteLists), + TABLE_ENTRY(GenLists), + TABLE_ENTRY(ListBase), + TABLE_ENTRY(Begin), + TABLE_ENTRY(Bitmap), + TABLE_ENTRY(Color3b), + TABLE_ENTRY(Color3bv), + TABLE_ENTRY(Color3d), + TABLE_ENTRY(Color3dv), + TABLE_ENTRY(Color3f), + TABLE_ENTRY(Color3fv), + TABLE_ENTRY(Color3i), + TABLE_ENTRY(Color3iv), + TABLE_ENTRY(Color3s), + TABLE_ENTRY(Color3sv), + TABLE_ENTRY(Color3ub), + TABLE_ENTRY(Color3ubv), + TABLE_ENTRY(Color3ui), + TABLE_ENTRY(Color3uiv), + TABLE_ENTRY(Color3us), + TABLE_ENTRY(Color3usv), + TABLE_ENTRY(Color4b), + TABLE_ENTRY(Color4bv), + TABLE_ENTRY(Color4d), + TABLE_ENTRY(Color4dv), + TABLE_ENTRY(Color4f), + TABLE_ENTRY(Color4fv), + TABLE_ENTRY(Color4i), + TABLE_ENTRY(Color4iv), + TABLE_ENTRY(Color4s), + TABLE_ENTRY(Color4sv), + TABLE_ENTRY(Color4ub), + TABLE_ENTRY(Color4ubv), + TABLE_ENTRY(Color4ui), + TABLE_ENTRY(Color4uiv), + TABLE_ENTRY(Color4us), + TABLE_ENTRY(Color4usv), + TABLE_ENTRY(EdgeFlag), + TABLE_ENTRY(EdgeFlagv), + TABLE_ENTRY(End), + TABLE_ENTRY(Indexd), + TABLE_ENTRY(Indexdv), + TABLE_ENTRY(Indexf), + TABLE_ENTRY(Indexfv), + TABLE_ENTRY(Indexi), + TABLE_ENTRY(Indexiv), + TABLE_ENTRY(Indexs), + TABLE_ENTRY(Indexsv), + TABLE_ENTRY(Normal3b), + TABLE_ENTRY(Normal3bv), + TABLE_ENTRY(Normal3d), + TABLE_ENTRY(Normal3dv), + TABLE_ENTRY(Normal3f), + TABLE_ENTRY(Normal3fv), + TABLE_ENTRY(Normal3i), + TABLE_ENTRY(Normal3iv), + TABLE_ENTRY(Normal3s), + TABLE_ENTRY(Normal3sv), + TABLE_ENTRY(RasterPos2d), + TABLE_ENTRY(RasterPos2dv), + TABLE_ENTRY(RasterPos2f), + TABLE_ENTRY(RasterPos2fv), + TABLE_ENTRY(RasterPos2i), + TABLE_ENTRY(RasterPos2iv), + TABLE_ENTRY(RasterPos2s), + TABLE_ENTRY(RasterPos2sv), + TABLE_ENTRY(RasterPos3d), + TABLE_ENTRY(RasterPos3dv), + TABLE_ENTRY(RasterPos3f), + TABLE_ENTRY(RasterPos3fv), + TABLE_ENTRY(RasterPos3i), + TABLE_ENTRY(RasterPos3iv), + TABLE_ENTRY(RasterPos3s), + TABLE_ENTRY(RasterPos3sv), + TABLE_ENTRY(RasterPos4d), + TABLE_ENTRY(RasterPos4dv), + TABLE_ENTRY(RasterPos4f), + TABLE_ENTRY(RasterPos4fv), + TABLE_ENTRY(RasterPos4i), + TABLE_ENTRY(RasterPos4iv), + TABLE_ENTRY(RasterPos4s), + TABLE_ENTRY(RasterPos4sv), + TABLE_ENTRY(Rectd), + TABLE_ENTRY(Rectdv), + TABLE_ENTRY(Rectf), + TABLE_ENTRY(Rectfv), + TABLE_ENTRY(Recti), + TABLE_ENTRY(Rectiv), + TABLE_ENTRY(Rects), + TABLE_ENTRY(Rectsv), + TABLE_ENTRY(TexCoord1d), + TABLE_ENTRY(TexCoord1dv), + TABLE_ENTRY(TexCoord1f), + TABLE_ENTRY(TexCoord1fv), + TABLE_ENTRY(TexCoord1i), + TABLE_ENTRY(TexCoord1iv), + TABLE_ENTRY(TexCoord1s), + TABLE_ENTRY(TexCoord1sv), + TABLE_ENTRY(TexCoord2d), + TABLE_ENTRY(TexCoord2dv), + TABLE_ENTRY(TexCoord2f), + TABLE_ENTRY(TexCoord2fv), + TABLE_ENTRY(TexCoord2i), + TABLE_ENTRY(TexCoord2iv), + TABLE_ENTRY(TexCoord2s), + TABLE_ENTRY(TexCoord2sv), + TABLE_ENTRY(TexCoord3d), + TABLE_ENTRY(TexCoord3dv), + TABLE_ENTRY(TexCoord3f), + TABLE_ENTRY(TexCoord3fv), + TABLE_ENTRY(TexCoord3i), + TABLE_ENTRY(TexCoord3iv), + TABLE_ENTRY(TexCoord3s), + TABLE_ENTRY(TexCoord3sv), + TABLE_ENTRY(TexCoord4d), + TABLE_ENTRY(TexCoord4dv), + TABLE_ENTRY(TexCoord4f), + TABLE_ENTRY(TexCoord4fv), + TABLE_ENTRY(TexCoord4i), + TABLE_ENTRY(TexCoord4iv), + TABLE_ENTRY(TexCoord4s), + TABLE_ENTRY(TexCoord4sv), + TABLE_ENTRY(Vertex2d), + TABLE_ENTRY(Vertex2dv), + TABLE_ENTRY(Vertex2f), + TABLE_ENTRY(Vertex2fv), + TABLE_ENTRY(Vertex2i), + TABLE_ENTRY(Vertex2iv), + TABLE_ENTRY(Vertex2s), + TABLE_ENTRY(Vertex2sv), + TABLE_ENTRY(Vertex3d), + TABLE_ENTRY(Vertex3dv), + TABLE_ENTRY(Vertex3f), + TABLE_ENTRY(Vertex3fv), + TABLE_ENTRY(Vertex3i), + TABLE_ENTRY(Vertex3iv), + TABLE_ENTRY(Vertex3s), + TABLE_ENTRY(Vertex3sv), + TABLE_ENTRY(Vertex4d), + TABLE_ENTRY(Vertex4dv), + TABLE_ENTRY(Vertex4f), + TABLE_ENTRY(Vertex4fv), + TABLE_ENTRY(Vertex4i), + TABLE_ENTRY(Vertex4iv), + TABLE_ENTRY(Vertex4s), + TABLE_ENTRY(Vertex4sv), + TABLE_ENTRY(ClipPlane), + TABLE_ENTRY(ColorMaterial), + TABLE_ENTRY(CullFace), + TABLE_ENTRY(Fogf), + TABLE_ENTRY(Fogfv), + TABLE_ENTRY(Fogi), + TABLE_ENTRY(Fogiv), + TABLE_ENTRY(FrontFace), + TABLE_ENTRY(Hint), + TABLE_ENTRY(Lightf), + TABLE_ENTRY(Lightfv), + TABLE_ENTRY(Lighti), + TABLE_ENTRY(Lightiv), + TABLE_ENTRY(LightModelf), + TABLE_ENTRY(LightModelfv), + TABLE_ENTRY(LightModeli), + TABLE_ENTRY(LightModeliv), + TABLE_ENTRY(LineStipple), + TABLE_ENTRY(LineWidth), + TABLE_ENTRY(Materialf), + TABLE_ENTRY(Materialfv), + TABLE_ENTRY(Materiali), + TABLE_ENTRY(Materialiv), + TABLE_ENTRY(PointSize), + TABLE_ENTRY(PolygonMode), + TABLE_ENTRY(PolygonStipple), + TABLE_ENTRY(Scissor), + TABLE_ENTRY(ShadeModel), + TABLE_ENTRY(TexParameterf), + TABLE_ENTRY(TexParameterfv), + TABLE_ENTRY(TexParameteri), + TABLE_ENTRY(TexParameteriv), + TABLE_ENTRY(TexImage1D), + TABLE_ENTRY(TexImage2D), + TABLE_ENTRY(TexEnvf), + TABLE_ENTRY(TexEnvfv), + TABLE_ENTRY(TexEnvi), + TABLE_ENTRY(TexEnviv), + TABLE_ENTRY(TexGend), + TABLE_ENTRY(TexGendv), + TABLE_ENTRY(TexGenf), + TABLE_ENTRY(TexGenfv), + TABLE_ENTRY(TexGeni), + TABLE_ENTRY(TexGeniv), + TABLE_ENTRY(FeedbackBuffer), + TABLE_ENTRY(SelectBuffer), + TABLE_ENTRY(RenderMode), + TABLE_ENTRY(InitNames), + TABLE_ENTRY(LoadName), + TABLE_ENTRY(PassThrough), + TABLE_ENTRY(PopName), + TABLE_ENTRY(PushName), + TABLE_ENTRY(DrawBuffer), + TABLE_ENTRY(Clear), + TABLE_ENTRY(ClearAccum), + TABLE_ENTRY(ClearIndex), + TABLE_ENTRY(ClearColor), + TABLE_ENTRY(ClearStencil), + TABLE_ENTRY(ClearDepth), + TABLE_ENTRY(StencilMask), + TABLE_ENTRY(ColorMask), + TABLE_ENTRY(DepthMask), + TABLE_ENTRY(IndexMask), + TABLE_ENTRY(Accum), + TABLE_ENTRY(Disable), + TABLE_ENTRY(Enable), + TABLE_ENTRY(Finish), + TABLE_ENTRY(Flush), + TABLE_ENTRY(PopAttrib), + TABLE_ENTRY(PushAttrib), + TABLE_ENTRY(Map1d), + TABLE_ENTRY(Map1f), + TABLE_ENTRY(Map2d), + TABLE_ENTRY(Map2f), + TABLE_ENTRY(MapGrid1d), + TABLE_ENTRY(MapGrid1f), + TABLE_ENTRY(MapGrid2d), + TABLE_ENTRY(MapGrid2f), + TABLE_ENTRY(EvalCoord1d), + TABLE_ENTRY(EvalCoord1dv), + TABLE_ENTRY(EvalCoord1f), + TABLE_ENTRY(EvalCoord1fv), + TABLE_ENTRY(EvalCoord2d), + TABLE_ENTRY(EvalCoord2dv), + TABLE_ENTRY(EvalCoord2f), + TABLE_ENTRY(EvalCoord2fv), + TABLE_ENTRY(EvalMesh1), + TABLE_ENTRY(EvalPoint1), + TABLE_ENTRY(EvalMesh2), + TABLE_ENTRY(EvalPoint2), + TABLE_ENTRY(AlphaFunc), + TABLE_ENTRY(BlendFunc), + TABLE_ENTRY(LogicOp), + TABLE_ENTRY(StencilFunc), + TABLE_ENTRY(StencilOp), + TABLE_ENTRY(DepthFunc), + TABLE_ENTRY(PixelZoom), + TABLE_ENTRY(PixelTransferf), + TABLE_ENTRY(PixelTransferi), + TABLE_ENTRY(PixelStoref), + TABLE_ENTRY(PixelStorei), + TABLE_ENTRY(PixelMapfv), + TABLE_ENTRY(PixelMapuiv), + TABLE_ENTRY(PixelMapusv), + TABLE_ENTRY(ReadBuffer), + TABLE_ENTRY(CopyPixels), + TABLE_ENTRY(ReadPixels), + TABLE_ENTRY(DrawPixels), + TABLE_ENTRY(GetBooleanv), + TABLE_ENTRY(GetClipPlane), + TABLE_ENTRY(GetDoublev), + TABLE_ENTRY(GetError), + TABLE_ENTRY(GetFloatv), + TABLE_ENTRY(GetIntegerv), + TABLE_ENTRY(GetLightfv), + TABLE_ENTRY(GetLightiv), + TABLE_ENTRY(GetMapdv), + TABLE_ENTRY(GetMapfv), + TABLE_ENTRY(GetMapiv), + TABLE_ENTRY(GetMaterialfv), + TABLE_ENTRY(GetMaterialiv), + TABLE_ENTRY(GetPixelMapfv), + TABLE_ENTRY(GetPixelMapuiv), + TABLE_ENTRY(GetPixelMapusv), + TABLE_ENTRY(GetPolygonStipple), + TABLE_ENTRY(GetString), + TABLE_ENTRY(GetTexEnvfv), + TABLE_ENTRY(GetTexEnviv), + TABLE_ENTRY(GetTexGendv), + TABLE_ENTRY(GetTexGenfv), + TABLE_ENTRY(GetTexGeniv), + TABLE_ENTRY(GetTexImage), + TABLE_ENTRY(GetTexParameterfv), + TABLE_ENTRY(GetTexParameteriv), + TABLE_ENTRY(GetTexLevelParameterfv), + TABLE_ENTRY(GetTexLevelParameteriv), + TABLE_ENTRY(IsEnabled), + TABLE_ENTRY(IsList), + TABLE_ENTRY(DepthRange), + TABLE_ENTRY(Frustum), + TABLE_ENTRY(LoadIdentity), + TABLE_ENTRY(LoadMatrixf), + TABLE_ENTRY(LoadMatrixd), + TABLE_ENTRY(MatrixMode), + TABLE_ENTRY(MultMatrixf), + TABLE_ENTRY(MultMatrixd), + TABLE_ENTRY(Ortho), + TABLE_ENTRY(PopMatrix), + TABLE_ENTRY(PushMatrix), + TABLE_ENTRY(Rotated), + TABLE_ENTRY(Rotatef), + TABLE_ENTRY(Scaled), + TABLE_ENTRY(Scalef), + TABLE_ENTRY(Translated), + TABLE_ENTRY(Translatef), + TABLE_ENTRY(Viewport), + TABLE_ENTRY(ArrayElement), + TABLE_ENTRY(BindTexture), + TABLE_ENTRY(ColorPointer), + TABLE_ENTRY(DisableClientState), + TABLE_ENTRY(DrawArrays), + TABLE_ENTRY(DrawElements), + TABLE_ENTRY(EdgeFlagPointer), + TABLE_ENTRY(EnableClientState), + TABLE_ENTRY(IndexPointer), + TABLE_ENTRY(Indexub), + TABLE_ENTRY(Indexubv), + TABLE_ENTRY(InterleavedArrays), + TABLE_ENTRY(NormalPointer), + TABLE_ENTRY(PolygonOffset), + TABLE_ENTRY(TexCoordPointer), + TABLE_ENTRY(VertexPointer), + TABLE_ENTRY(AreTexturesResident), + TABLE_ENTRY(CopyTexImage1D), + TABLE_ENTRY(CopyTexImage2D), + TABLE_ENTRY(CopyTexSubImage1D), + TABLE_ENTRY(CopyTexSubImage2D), + TABLE_ENTRY(DeleteTextures), + TABLE_ENTRY(GenTextures), + TABLE_ENTRY(GetPointerv), + TABLE_ENTRY(IsTexture), + TABLE_ENTRY(PrioritizeTextures), + TABLE_ENTRY(TexSubImage1D), + TABLE_ENTRY(TexSubImage2D), + TABLE_ENTRY(PopClientAttrib), + TABLE_ENTRY(PushClientAttrib), + TABLE_ENTRY(BlendColor), + TABLE_ENTRY(BlendEquation), + TABLE_ENTRY(DrawRangeElements), + TABLE_ENTRY(ColorTable), + TABLE_ENTRY(ColorTableParameterfv), + TABLE_ENTRY(ColorTableParameteriv), + TABLE_ENTRY(CopyColorTable), + TABLE_ENTRY(GetColorTable), + TABLE_ENTRY(GetColorTableParameterfv), + TABLE_ENTRY(GetColorTableParameteriv), + TABLE_ENTRY(ColorSubTable), + TABLE_ENTRY(CopyColorSubTable), + TABLE_ENTRY(ConvolutionFilter1D), + TABLE_ENTRY(ConvolutionFilter2D), + TABLE_ENTRY(ConvolutionParameterf), + TABLE_ENTRY(ConvolutionParameterfv), + TABLE_ENTRY(ConvolutionParameteri), + TABLE_ENTRY(ConvolutionParameteriv), + TABLE_ENTRY(CopyConvolutionFilter1D), + TABLE_ENTRY(CopyConvolutionFilter2D), + TABLE_ENTRY(GetConvolutionFilter), + TABLE_ENTRY(GetConvolutionParameterfv), + TABLE_ENTRY(GetConvolutionParameteriv), + TABLE_ENTRY(GetSeparableFilter), + TABLE_ENTRY(SeparableFilter2D), + TABLE_ENTRY(GetHistogram), + TABLE_ENTRY(GetHistogramParameterfv), + TABLE_ENTRY(GetHistogramParameteriv), + TABLE_ENTRY(GetMinmax), + TABLE_ENTRY(GetMinmaxParameterfv), + TABLE_ENTRY(GetMinmaxParameteriv), + TABLE_ENTRY(Histogram), + TABLE_ENTRY(Minmax), + TABLE_ENTRY(ResetHistogram), + TABLE_ENTRY(ResetMinmax), + TABLE_ENTRY(TexImage3D), + TABLE_ENTRY(TexSubImage3D), + TABLE_ENTRY(CopyTexSubImage3D), + TABLE_ENTRY(ActiveTextureARB), + TABLE_ENTRY(ClientActiveTextureARB), + TABLE_ENTRY(MultiTexCoord1dARB), + TABLE_ENTRY(MultiTexCoord1dvARB), + TABLE_ENTRY(MultiTexCoord1fARB), + TABLE_ENTRY(MultiTexCoord1fvARB), + TABLE_ENTRY(MultiTexCoord1iARB), + TABLE_ENTRY(MultiTexCoord1ivARB), + TABLE_ENTRY(MultiTexCoord1sARB), + TABLE_ENTRY(MultiTexCoord1svARB), + TABLE_ENTRY(MultiTexCoord2dARB), + TABLE_ENTRY(MultiTexCoord2dvARB), + TABLE_ENTRY(MultiTexCoord2fARB), + TABLE_ENTRY(MultiTexCoord2fvARB), + TABLE_ENTRY(MultiTexCoord2iARB), + TABLE_ENTRY(MultiTexCoord2ivARB), + TABLE_ENTRY(MultiTexCoord2sARB), + TABLE_ENTRY(MultiTexCoord2svARB), + TABLE_ENTRY(MultiTexCoord3dARB), + TABLE_ENTRY(MultiTexCoord3dvARB), + TABLE_ENTRY(MultiTexCoord3fARB), + TABLE_ENTRY(MultiTexCoord3fvARB), + TABLE_ENTRY(MultiTexCoord3iARB), + TABLE_ENTRY(MultiTexCoord3ivARB), + TABLE_ENTRY(MultiTexCoord3sARB), + TABLE_ENTRY(MultiTexCoord3svARB), + TABLE_ENTRY(MultiTexCoord4dARB), + TABLE_ENTRY(MultiTexCoord4dvARB), + TABLE_ENTRY(MultiTexCoord4fARB), + TABLE_ENTRY(MultiTexCoord4fvARB), + TABLE_ENTRY(MultiTexCoord4iARB), + TABLE_ENTRY(MultiTexCoord4ivARB), + TABLE_ENTRY(MultiTexCoord4sARB), + TABLE_ENTRY(MultiTexCoord4svARB), + TABLE_ENTRY(AttachShader), + TABLE_ENTRY(CreateProgram), + TABLE_ENTRY(CreateShader), + TABLE_ENTRY(DeleteProgram), + TABLE_ENTRY(DeleteShader), + TABLE_ENTRY(DetachShader), + TABLE_ENTRY(GetAttachedShaders), + TABLE_ENTRY(GetProgramInfoLog), + TABLE_ENTRY(GetProgramiv), + TABLE_ENTRY(GetShaderInfoLog), + TABLE_ENTRY(GetShaderiv), + TABLE_ENTRY(IsProgram), + TABLE_ENTRY(IsShader), + TABLE_ENTRY(StencilFuncSeparate), + TABLE_ENTRY(StencilMaskSeparate), + TABLE_ENTRY(StencilOpSeparate), + TABLE_ENTRY(UniformMatrix2x3fv), + TABLE_ENTRY(UniformMatrix2x4fv), + TABLE_ENTRY(UniformMatrix3x2fv), + TABLE_ENTRY(UniformMatrix3x4fv), + TABLE_ENTRY(UniformMatrix4x2fv), + TABLE_ENTRY(UniformMatrix4x3fv), + TABLE_ENTRY(ClampColor), + TABLE_ENTRY(ClearBufferfi), + TABLE_ENTRY(ClearBufferfv), + TABLE_ENTRY(ClearBufferiv), + TABLE_ENTRY(ClearBufferuiv), + TABLE_ENTRY(GetStringi), + TABLE_ENTRY(TexBuffer), + TABLE_ENTRY(FramebufferTexture), + TABLE_ENTRY(GetBufferParameteri64v), + TABLE_ENTRY(GetInteger64i_v), + TABLE_ENTRY(VertexAttribDivisor), + TABLE_ENTRY(LoadTransposeMatrixdARB), + TABLE_ENTRY(LoadTransposeMatrixfARB), + TABLE_ENTRY(MultTransposeMatrixdARB), + TABLE_ENTRY(MultTransposeMatrixfARB), + TABLE_ENTRY(SampleCoverageARB), + TABLE_ENTRY(CompressedTexImage1DARB), + TABLE_ENTRY(CompressedTexImage2DARB), + TABLE_ENTRY(CompressedTexImage3DARB), + TABLE_ENTRY(CompressedTexSubImage1DARB), + TABLE_ENTRY(CompressedTexSubImage2DARB), + TABLE_ENTRY(CompressedTexSubImage3DARB), + TABLE_ENTRY(GetCompressedTexImageARB), + TABLE_ENTRY(DisableVertexAttribArrayARB), + TABLE_ENTRY(EnableVertexAttribArrayARB), + TABLE_ENTRY(GetProgramEnvParameterdvARB), + TABLE_ENTRY(GetProgramEnvParameterfvARB), + TABLE_ENTRY(GetProgramLocalParameterdvARB), + TABLE_ENTRY(GetProgramLocalParameterfvARB), + TABLE_ENTRY(GetProgramStringARB), + TABLE_ENTRY(GetProgramivARB), + TABLE_ENTRY(GetVertexAttribdvARB), + TABLE_ENTRY(GetVertexAttribfvARB), + TABLE_ENTRY(GetVertexAttribivARB), + TABLE_ENTRY(ProgramEnvParameter4dARB), + TABLE_ENTRY(ProgramEnvParameter4dvARB), + TABLE_ENTRY(ProgramEnvParameter4fARB), + TABLE_ENTRY(ProgramEnvParameter4fvARB), + TABLE_ENTRY(ProgramLocalParameter4dARB), + TABLE_ENTRY(ProgramLocalParameter4dvARB), + TABLE_ENTRY(ProgramLocalParameter4fARB), + TABLE_ENTRY(ProgramLocalParameter4fvARB), + TABLE_ENTRY(ProgramStringARB), + TABLE_ENTRY(VertexAttrib1dARB), + TABLE_ENTRY(VertexAttrib1dvARB), + TABLE_ENTRY(VertexAttrib1fARB), + TABLE_ENTRY(VertexAttrib1fvARB), + TABLE_ENTRY(VertexAttrib1sARB), + TABLE_ENTRY(VertexAttrib1svARB), + TABLE_ENTRY(VertexAttrib2dARB), + TABLE_ENTRY(VertexAttrib2dvARB), + TABLE_ENTRY(VertexAttrib2fARB), + TABLE_ENTRY(VertexAttrib2fvARB), + TABLE_ENTRY(VertexAttrib2sARB), + TABLE_ENTRY(VertexAttrib2svARB), + TABLE_ENTRY(VertexAttrib3dARB), + TABLE_ENTRY(VertexAttrib3dvARB), + TABLE_ENTRY(VertexAttrib3fARB), + TABLE_ENTRY(VertexAttrib3fvARB), + TABLE_ENTRY(VertexAttrib3sARB), + TABLE_ENTRY(VertexAttrib3svARB), + TABLE_ENTRY(VertexAttrib4NbvARB), + TABLE_ENTRY(VertexAttrib4NivARB), + TABLE_ENTRY(VertexAttrib4NsvARB), + TABLE_ENTRY(VertexAttrib4NubARB), + TABLE_ENTRY(VertexAttrib4NubvARB), + TABLE_ENTRY(VertexAttrib4NuivARB), + TABLE_ENTRY(VertexAttrib4NusvARB), + TABLE_ENTRY(VertexAttrib4bvARB), + TABLE_ENTRY(VertexAttrib4dARB), + TABLE_ENTRY(VertexAttrib4dvARB), + TABLE_ENTRY(VertexAttrib4fARB), + TABLE_ENTRY(VertexAttrib4fvARB), + TABLE_ENTRY(VertexAttrib4ivARB), + TABLE_ENTRY(VertexAttrib4sARB), + TABLE_ENTRY(VertexAttrib4svARB), + TABLE_ENTRY(VertexAttrib4ubvARB), + TABLE_ENTRY(VertexAttrib4uivARB), + TABLE_ENTRY(VertexAttrib4usvARB), + TABLE_ENTRY(VertexAttribPointerARB), + TABLE_ENTRY(BindBufferARB), + TABLE_ENTRY(BufferDataARB), + TABLE_ENTRY(BufferSubDataARB), + TABLE_ENTRY(DeleteBuffersARB), + TABLE_ENTRY(GenBuffersARB), + TABLE_ENTRY(GetBufferParameterivARB), + TABLE_ENTRY(GetBufferPointervARB), + TABLE_ENTRY(GetBufferSubDataARB), + TABLE_ENTRY(IsBufferARB), + TABLE_ENTRY(MapBufferARB), + TABLE_ENTRY(UnmapBufferARB), + TABLE_ENTRY(BeginQueryARB), + TABLE_ENTRY(DeleteQueriesARB), + TABLE_ENTRY(EndQueryARB), + TABLE_ENTRY(GenQueriesARB), + TABLE_ENTRY(GetQueryObjectivARB), + TABLE_ENTRY(GetQueryObjectuivARB), + TABLE_ENTRY(GetQueryivARB), + TABLE_ENTRY(IsQueryARB), + TABLE_ENTRY(AttachObjectARB), + TABLE_ENTRY(CompileShaderARB), + TABLE_ENTRY(CreateProgramObjectARB), + TABLE_ENTRY(CreateShaderObjectARB), + TABLE_ENTRY(DeleteObjectARB), + TABLE_ENTRY(DetachObjectARB), + TABLE_ENTRY(GetActiveUniformARB), + TABLE_ENTRY(GetAttachedObjectsARB), + TABLE_ENTRY(GetHandleARB), + TABLE_ENTRY(GetInfoLogARB), + TABLE_ENTRY(GetObjectParameterfvARB), + TABLE_ENTRY(GetObjectParameterivARB), + TABLE_ENTRY(GetShaderSourceARB), + TABLE_ENTRY(GetUniformLocationARB), + TABLE_ENTRY(GetUniformfvARB), + TABLE_ENTRY(GetUniformivARB), + TABLE_ENTRY(LinkProgramARB), + TABLE_ENTRY(ShaderSourceARB), + TABLE_ENTRY(Uniform1fARB), + TABLE_ENTRY(Uniform1fvARB), + TABLE_ENTRY(Uniform1iARB), + TABLE_ENTRY(Uniform1ivARB), + TABLE_ENTRY(Uniform2fARB), + TABLE_ENTRY(Uniform2fvARB), + TABLE_ENTRY(Uniform2iARB), + TABLE_ENTRY(Uniform2ivARB), + TABLE_ENTRY(Uniform3fARB), + TABLE_ENTRY(Uniform3fvARB), + TABLE_ENTRY(Uniform3iARB), + TABLE_ENTRY(Uniform3ivARB), + TABLE_ENTRY(Uniform4fARB), + TABLE_ENTRY(Uniform4fvARB), + TABLE_ENTRY(Uniform4iARB), + TABLE_ENTRY(Uniform4ivARB), + TABLE_ENTRY(UniformMatrix2fvARB), + TABLE_ENTRY(UniformMatrix3fvARB), + TABLE_ENTRY(UniformMatrix4fvARB), + TABLE_ENTRY(UseProgramObjectARB), + TABLE_ENTRY(ValidateProgramARB), + TABLE_ENTRY(BindAttribLocationARB), + TABLE_ENTRY(GetActiveAttribARB), + TABLE_ENTRY(GetAttribLocationARB), + TABLE_ENTRY(DrawBuffersARB), + TABLE_ENTRY(DrawArraysInstancedARB), + TABLE_ENTRY(DrawElementsInstancedARB), + TABLE_ENTRY(RenderbufferStorageMultisample), + TABLE_ENTRY(FramebufferTextureARB), + TABLE_ENTRY(FramebufferTextureFaceARB), + TABLE_ENTRY(ProgramParameteriARB), + TABLE_ENTRY(FlushMappedBufferRange), + TABLE_ENTRY(MapBufferRange), + TABLE_ENTRY(BindVertexArray), + TABLE_ENTRY(GenVertexArrays), + TABLE_ENTRY(CopyBufferSubData), + TABLE_ENTRY(ClientWaitSync), + TABLE_ENTRY(DeleteSync), + TABLE_ENTRY(FenceSync), + TABLE_ENTRY(GetInteger64v), + TABLE_ENTRY(GetSynciv), + TABLE_ENTRY(IsSync), + TABLE_ENTRY(WaitSync), + TABLE_ENTRY(DrawElementsBaseVertex), + TABLE_ENTRY(DrawRangeElementsBaseVertex), + TABLE_ENTRY(MultiDrawElementsBaseVertex), + TABLE_ENTRY(BindTransformFeedback), + TABLE_ENTRY(DeleteTransformFeedbacks), + TABLE_ENTRY(DrawTransformFeedback), + TABLE_ENTRY(GenTransformFeedbacks), + TABLE_ENTRY(IsTransformFeedback), + TABLE_ENTRY(PauseTransformFeedback), + TABLE_ENTRY(ResumeTransformFeedback), + TABLE_ENTRY(ClearDepthf), + TABLE_ENTRY(DepthRangef), + TABLE_ENTRY(GetShaderPrecisionFormat), + TABLE_ENTRY(ReleaseShaderCompiler), + TABLE_ENTRY(ShaderBinary), + TABLE_ENTRY(PolygonOffsetEXT), + TABLE_ENTRY(_dispatch_stub_606), + TABLE_ENTRY(_dispatch_stub_607), + TABLE_ENTRY(_dispatch_stub_608), + TABLE_ENTRY(_dispatch_stub_609), + TABLE_ENTRY(_dispatch_stub_610), + TABLE_ENTRY(_dispatch_stub_611), + TABLE_ENTRY(_dispatch_stub_612), + TABLE_ENTRY(_dispatch_stub_613), + TABLE_ENTRY(ColorPointerEXT), + TABLE_ENTRY(EdgeFlagPointerEXT), + TABLE_ENTRY(IndexPointerEXT), + TABLE_ENTRY(NormalPointerEXT), + TABLE_ENTRY(TexCoordPointerEXT), + TABLE_ENTRY(VertexPointerEXT), + TABLE_ENTRY(PointParameterfEXT), + TABLE_ENTRY(PointParameterfvEXT), + TABLE_ENTRY(LockArraysEXT), + TABLE_ENTRY(UnlockArraysEXT), + TABLE_ENTRY(SecondaryColor3bEXT), + TABLE_ENTRY(SecondaryColor3bvEXT), + TABLE_ENTRY(SecondaryColor3dEXT), + TABLE_ENTRY(SecondaryColor3dvEXT), + TABLE_ENTRY(SecondaryColor3fEXT), + TABLE_ENTRY(SecondaryColor3fvEXT), + TABLE_ENTRY(SecondaryColor3iEXT), + TABLE_ENTRY(SecondaryColor3ivEXT), + TABLE_ENTRY(SecondaryColor3sEXT), + TABLE_ENTRY(SecondaryColor3svEXT), + TABLE_ENTRY(SecondaryColor3ubEXT), + TABLE_ENTRY(SecondaryColor3ubvEXT), + TABLE_ENTRY(SecondaryColor3uiEXT), + TABLE_ENTRY(SecondaryColor3uivEXT), + TABLE_ENTRY(SecondaryColor3usEXT), + TABLE_ENTRY(SecondaryColor3usvEXT), + TABLE_ENTRY(SecondaryColorPointerEXT), + TABLE_ENTRY(MultiDrawArraysEXT), + TABLE_ENTRY(MultiDrawElementsEXT), + TABLE_ENTRY(FogCoordPointerEXT), + TABLE_ENTRY(FogCoorddEXT), + TABLE_ENTRY(FogCoorddvEXT), + TABLE_ENTRY(FogCoordfEXT), + TABLE_ENTRY(FogCoordfvEXT), + TABLE_ENTRY(_dispatch_stub_648), + TABLE_ENTRY(BlendFuncSeparateEXT), + TABLE_ENTRY(FlushVertexArrayRangeNV), + TABLE_ENTRY(VertexArrayRangeNV), + TABLE_ENTRY(CombinerInputNV), + TABLE_ENTRY(CombinerOutputNV), + TABLE_ENTRY(CombinerParameterfNV), + TABLE_ENTRY(CombinerParameterfvNV), + TABLE_ENTRY(CombinerParameteriNV), + TABLE_ENTRY(CombinerParameterivNV), + TABLE_ENTRY(FinalCombinerInputNV), + TABLE_ENTRY(GetCombinerInputParameterfvNV), + TABLE_ENTRY(GetCombinerInputParameterivNV), + TABLE_ENTRY(GetCombinerOutputParameterfvNV), + TABLE_ENTRY(GetCombinerOutputParameterivNV), + TABLE_ENTRY(GetFinalCombinerInputParameterfvNV), + TABLE_ENTRY(GetFinalCombinerInputParameterivNV), + TABLE_ENTRY(ResizeBuffersMESA), + TABLE_ENTRY(WindowPos2dMESA), + TABLE_ENTRY(WindowPos2dvMESA), + TABLE_ENTRY(WindowPos2fMESA), + TABLE_ENTRY(WindowPos2fvMESA), + TABLE_ENTRY(WindowPos2iMESA), + TABLE_ENTRY(WindowPos2ivMESA), + TABLE_ENTRY(WindowPos2sMESA), + TABLE_ENTRY(WindowPos2svMESA), + TABLE_ENTRY(WindowPos3dMESA), + TABLE_ENTRY(WindowPos3dvMESA), + TABLE_ENTRY(WindowPos3fMESA), + TABLE_ENTRY(WindowPos3fvMESA), + TABLE_ENTRY(WindowPos3iMESA), + TABLE_ENTRY(WindowPos3ivMESA), + TABLE_ENTRY(WindowPos3sMESA), + TABLE_ENTRY(WindowPos3svMESA), + TABLE_ENTRY(WindowPos4dMESA), + TABLE_ENTRY(WindowPos4dvMESA), + TABLE_ENTRY(WindowPos4fMESA), + TABLE_ENTRY(WindowPos4fvMESA), + TABLE_ENTRY(WindowPos4iMESA), + TABLE_ENTRY(WindowPos4ivMESA), + TABLE_ENTRY(WindowPos4sMESA), + TABLE_ENTRY(WindowPos4svMESA), + TABLE_ENTRY(_dispatch_stub_690), + TABLE_ENTRY(_dispatch_stub_691), + TABLE_ENTRY(_dispatch_stub_692), + TABLE_ENTRY(_dispatch_stub_693), + TABLE_ENTRY(_dispatch_stub_694), + TABLE_ENTRY(_dispatch_stub_695), + TABLE_ENTRY(_dispatch_stub_696), + TABLE_ENTRY(_dispatch_stub_697), + TABLE_ENTRY(_dispatch_stub_698), + TABLE_ENTRY(AreProgramsResidentNV), + TABLE_ENTRY(BindProgramNV), + TABLE_ENTRY(DeleteProgramsNV), + TABLE_ENTRY(ExecuteProgramNV), + TABLE_ENTRY(GenProgramsNV), + TABLE_ENTRY(GetProgramParameterdvNV), + TABLE_ENTRY(GetProgramParameterfvNV), + TABLE_ENTRY(GetProgramStringNV), + TABLE_ENTRY(GetProgramivNV), + TABLE_ENTRY(GetTrackMatrixivNV), + TABLE_ENTRY(GetVertexAttribPointervNV), + TABLE_ENTRY(GetVertexAttribdvNV), + TABLE_ENTRY(GetVertexAttribfvNV), + TABLE_ENTRY(GetVertexAttribivNV), + TABLE_ENTRY(IsProgramNV), + TABLE_ENTRY(LoadProgramNV), + TABLE_ENTRY(ProgramParameters4dvNV), + TABLE_ENTRY(ProgramParameters4fvNV), + TABLE_ENTRY(RequestResidentProgramsNV), + TABLE_ENTRY(TrackMatrixNV), + TABLE_ENTRY(VertexAttrib1dNV), + TABLE_ENTRY(VertexAttrib1dvNV), + TABLE_ENTRY(VertexAttrib1fNV), + TABLE_ENTRY(VertexAttrib1fvNV), + TABLE_ENTRY(VertexAttrib1sNV), + TABLE_ENTRY(VertexAttrib1svNV), + TABLE_ENTRY(VertexAttrib2dNV), + TABLE_ENTRY(VertexAttrib2dvNV), + TABLE_ENTRY(VertexAttrib2fNV), + TABLE_ENTRY(VertexAttrib2fvNV), + TABLE_ENTRY(VertexAttrib2sNV), + TABLE_ENTRY(VertexAttrib2svNV), + TABLE_ENTRY(VertexAttrib3dNV), + TABLE_ENTRY(VertexAttrib3dvNV), + TABLE_ENTRY(VertexAttrib3fNV), + TABLE_ENTRY(VertexAttrib3fvNV), + TABLE_ENTRY(VertexAttrib3sNV), + TABLE_ENTRY(VertexAttrib3svNV), + TABLE_ENTRY(VertexAttrib4dNV), + TABLE_ENTRY(VertexAttrib4dvNV), + TABLE_ENTRY(VertexAttrib4fNV), + TABLE_ENTRY(VertexAttrib4fvNV), + TABLE_ENTRY(VertexAttrib4sNV), + TABLE_ENTRY(VertexAttrib4svNV), + TABLE_ENTRY(VertexAttrib4ubNV), + TABLE_ENTRY(VertexAttrib4ubvNV), + TABLE_ENTRY(VertexAttribPointerNV), + TABLE_ENTRY(VertexAttribs1dvNV), + TABLE_ENTRY(VertexAttribs1fvNV), + TABLE_ENTRY(VertexAttribs1svNV), + TABLE_ENTRY(VertexAttribs2dvNV), + TABLE_ENTRY(VertexAttribs2fvNV), + TABLE_ENTRY(VertexAttribs2svNV), + TABLE_ENTRY(VertexAttribs3dvNV), + TABLE_ENTRY(VertexAttribs3fvNV), + TABLE_ENTRY(VertexAttribs3svNV), + TABLE_ENTRY(VertexAttribs4dvNV), + TABLE_ENTRY(VertexAttribs4fvNV), + TABLE_ENTRY(VertexAttribs4svNV), + TABLE_ENTRY(VertexAttribs4ubvNV), + TABLE_ENTRY(GetTexBumpParameterfvATI), + TABLE_ENTRY(GetTexBumpParameterivATI), + TABLE_ENTRY(TexBumpParameterfvATI), + TABLE_ENTRY(TexBumpParameterivATI), + TABLE_ENTRY(AlphaFragmentOp1ATI), + TABLE_ENTRY(AlphaFragmentOp2ATI), + TABLE_ENTRY(AlphaFragmentOp3ATI), + TABLE_ENTRY(BeginFragmentShaderATI), + TABLE_ENTRY(BindFragmentShaderATI), + TABLE_ENTRY(ColorFragmentOp1ATI), + TABLE_ENTRY(ColorFragmentOp2ATI), + TABLE_ENTRY(ColorFragmentOp3ATI), + TABLE_ENTRY(DeleteFragmentShaderATI), + TABLE_ENTRY(EndFragmentShaderATI), + TABLE_ENTRY(GenFragmentShadersATI), + TABLE_ENTRY(PassTexCoordATI), + TABLE_ENTRY(SampleMapATI), + TABLE_ENTRY(SetFragmentShaderConstantATI), + TABLE_ENTRY(PointParameteriNV), + TABLE_ENTRY(PointParameterivNV), + TABLE_ENTRY(_dispatch_stub_779), + TABLE_ENTRY(_dispatch_stub_780), + TABLE_ENTRY(_dispatch_stub_781), + TABLE_ENTRY(_dispatch_stub_782), + TABLE_ENTRY(_dispatch_stub_783), + TABLE_ENTRY(GetProgramNamedParameterdvNV), + TABLE_ENTRY(GetProgramNamedParameterfvNV), + TABLE_ENTRY(ProgramNamedParameter4dNV), + TABLE_ENTRY(ProgramNamedParameter4dvNV), + TABLE_ENTRY(ProgramNamedParameter4fNV), + TABLE_ENTRY(ProgramNamedParameter4fvNV), + TABLE_ENTRY(PrimitiveRestartIndexNV), + TABLE_ENTRY(PrimitiveRestartNV), + TABLE_ENTRY(_dispatch_stub_792), + TABLE_ENTRY(_dispatch_stub_793), + TABLE_ENTRY(BindFramebufferEXT), + TABLE_ENTRY(BindRenderbufferEXT), + TABLE_ENTRY(CheckFramebufferStatusEXT), + TABLE_ENTRY(DeleteFramebuffersEXT), + TABLE_ENTRY(DeleteRenderbuffersEXT), + TABLE_ENTRY(FramebufferRenderbufferEXT), + TABLE_ENTRY(FramebufferTexture1DEXT), + TABLE_ENTRY(FramebufferTexture2DEXT), + TABLE_ENTRY(FramebufferTexture3DEXT), + TABLE_ENTRY(GenFramebuffersEXT), + TABLE_ENTRY(GenRenderbuffersEXT), + TABLE_ENTRY(GenerateMipmapEXT), + TABLE_ENTRY(GetFramebufferAttachmentParameterivEXT), + TABLE_ENTRY(GetRenderbufferParameterivEXT), + TABLE_ENTRY(IsFramebufferEXT), + TABLE_ENTRY(IsRenderbufferEXT), + TABLE_ENTRY(RenderbufferStorageEXT), + TABLE_ENTRY(_dispatch_stub_811), + TABLE_ENTRY(_dispatch_stub_812), + TABLE_ENTRY(_dispatch_stub_813), + TABLE_ENTRY(BindFragDataLocationEXT), + TABLE_ENTRY(GetFragDataLocationEXT), + TABLE_ENTRY(GetUniformuivEXT), + TABLE_ENTRY(GetVertexAttribIivEXT), + TABLE_ENTRY(GetVertexAttribIuivEXT), + TABLE_ENTRY(Uniform1uiEXT), + TABLE_ENTRY(Uniform1uivEXT), + TABLE_ENTRY(Uniform2uiEXT), + TABLE_ENTRY(Uniform2uivEXT), + TABLE_ENTRY(Uniform3uiEXT), + TABLE_ENTRY(Uniform3uivEXT), + TABLE_ENTRY(Uniform4uiEXT), + TABLE_ENTRY(Uniform4uivEXT), + TABLE_ENTRY(VertexAttribI1iEXT), + TABLE_ENTRY(VertexAttribI1ivEXT), + TABLE_ENTRY(VertexAttribI1uiEXT), + TABLE_ENTRY(VertexAttribI1uivEXT), + TABLE_ENTRY(VertexAttribI2iEXT), + TABLE_ENTRY(VertexAttribI2ivEXT), + TABLE_ENTRY(VertexAttribI2uiEXT), + TABLE_ENTRY(VertexAttribI2uivEXT), + TABLE_ENTRY(VertexAttribI3iEXT), + TABLE_ENTRY(VertexAttribI3ivEXT), + TABLE_ENTRY(VertexAttribI3uiEXT), + TABLE_ENTRY(VertexAttribI3uivEXT), + TABLE_ENTRY(VertexAttribI4bvEXT), + TABLE_ENTRY(VertexAttribI4iEXT), + TABLE_ENTRY(VertexAttribI4ivEXT), + TABLE_ENTRY(VertexAttribI4svEXT), + TABLE_ENTRY(VertexAttribI4ubvEXT), + TABLE_ENTRY(VertexAttribI4uiEXT), + TABLE_ENTRY(VertexAttribI4uivEXT), + TABLE_ENTRY(VertexAttribI4usvEXT), + TABLE_ENTRY(VertexAttribIPointerEXT), + TABLE_ENTRY(FramebufferTextureLayerEXT), + TABLE_ENTRY(ColorMaskIndexedEXT), + TABLE_ENTRY(DisableIndexedEXT), + TABLE_ENTRY(EnableIndexedEXT), + TABLE_ENTRY(GetBooleanIndexedvEXT), + TABLE_ENTRY(GetIntegerIndexedvEXT), + TABLE_ENTRY(IsEnabledIndexedEXT), + TABLE_ENTRY(ClearColorIiEXT), + TABLE_ENTRY(ClearColorIuiEXT), + TABLE_ENTRY(GetTexParameterIivEXT), + TABLE_ENTRY(GetTexParameterIuivEXT), + TABLE_ENTRY(TexParameterIivEXT), + TABLE_ENTRY(TexParameterIuivEXT), + TABLE_ENTRY(BeginConditionalRenderNV), + TABLE_ENTRY(EndConditionalRenderNV), + TABLE_ENTRY(BeginTransformFeedbackEXT), + TABLE_ENTRY(BindBufferBaseEXT), + TABLE_ENTRY(BindBufferOffsetEXT), + TABLE_ENTRY(BindBufferRangeEXT), + TABLE_ENTRY(EndTransformFeedbackEXT), + TABLE_ENTRY(GetTransformFeedbackVaryingEXT), + TABLE_ENTRY(TransformFeedbackVaryingsEXT), + TABLE_ENTRY(ProvokingVertexEXT), + TABLE_ENTRY(_dispatch_stub_871), + TABLE_ENTRY(_dispatch_stub_872), + TABLE_ENTRY(GetObjectParameterivAPPLE), + TABLE_ENTRY(ObjectPurgeableAPPLE), + TABLE_ENTRY(ObjectUnpurgeableAPPLE), + TABLE_ENTRY(ActiveProgramEXT), + TABLE_ENTRY(CreateShaderProgramEXT), + TABLE_ENTRY(UseShaderProgramEXT), + TABLE_ENTRY(_dispatch_stub_879), + TABLE_ENTRY(_dispatch_stub_880), + TABLE_ENTRY(_dispatch_stub_881), + TABLE_ENTRY(_dispatch_stub_882), + TABLE_ENTRY(_dispatch_stub_883), + TABLE_ENTRY(EGLImageTargetRenderbufferStorageOES), + TABLE_ENTRY(EGLImageTargetTexture2DOES), + /* A whole bunch of no-op functions. These might be called + * when someone tries to call a dynamically-registered + * extension function without a current rendering context. + */ + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), + TABLE_ENTRY(Unused), +}; +#endif /* DISPATCH_TABLE_NAME */ + + +/* + * This is just used to silence compiler warnings. + * We list the functions which are not otherwise used. + */ +#ifdef UNUSED_TABLE_NAME +_glapi_proc UNUSED_TABLE_NAME[] = { +#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS + TABLE_ENTRY(ArrayElementEXT), + TABLE_ENTRY(BindTextureEXT), + TABLE_ENTRY(DrawArraysEXT), + TABLE_ENTRY(CopyTexImage1DEXT), + TABLE_ENTRY(CopyTexImage2DEXT), + TABLE_ENTRY(CopyTexSubImage1DEXT), + TABLE_ENTRY(CopyTexSubImage2DEXT), + TABLE_ENTRY(GetPointervEXT), + TABLE_ENTRY(PrioritizeTexturesEXT), + TABLE_ENTRY(TexSubImage1DEXT), + TABLE_ENTRY(TexSubImage2DEXT), + TABLE_ENTRY(BlendColorEXT), + TABLE_ENTRY(BlendEquationEXT), + TABLE_ENTRY(DrawRangeElementsEXT), + TABLE_ENTRY(ColorTableEXT), + TABLE_ENTRY(_dispatch_stub_339), + TABLE_ENTRY(_dispatch_stub_340), + TABLE_ENTRY(_dispatch_stub_341), + TABLE_ENTRY(_dispatch_stub_342), + TABLE_ENTRY(_dispatch_stub_346), + TABLE_ENTRY(_dispatch_stub_347), + TABLE_ENTRY(_dispatch_stub_348), + TABLE_ENTRY(_dispatch_stub_349), + TABLE_ENTRY(_dispatch_stub_350), + TABLE_ENTRY(_dispatch_stub_351), + TABLE_ENTRY(_dispatch_stub_352), + TABLE_ENTRY(_dispatch_stub_353), + TABLE_ENTRY(_dispatch_stub_354), + TABLE_ENTRY(_dispatch_stub_355), + TABLE_ENTRY(_dispatch_stub_360), + TABLE_ENTRY(_dispatch_stub_367), + TABLE_ENTRY(_dispatch_stub_368), + TABLE_ENTRY(_dispatch_stub_369), + TABLE_ENTRY(_dispatch_stub_370), + TABLE_ENTRY(TexImage3DEXT), + TABLE_ENTRY(TexSubImage3DEXT), + TABLE_ENTRY(CopyTexSubImage3DEXT), + TABLE_ENTRY(ActiveTexture), + TABLE_ENTRY(ClientActiveTexture), + TABLE_ENTRY(MultiTexCoord1d), + TABLE_ENTRY(MultiTexCoord1dv), + TABLE_ENTRY(MultiTexCoord1f), + TABLE_ENTRY(MultiTexCoord1fv), + TABLE_ENTRY(MultiTexCoord1i), + TABLE_ENTRY(MultiTexCoord1iv), + TABLE_ENTRY(MultiTexCoord1s), + TABLE_ENTRY(MultiTexCoord1sv), + TABLE_ENTRY(MultiTexCoord2d), + TABLE_ENTRY(MultiTexCoord2dv), + TABLE_ENTRY(MultiTexCoord2f), + TABLE_ENTRY(MultiTexCoord2fv), + TABLE_ENTRY(MultiTexCoord2i), + TABLE_ENTRY(MultiTexCoord2iv), + TABLE_ENTRY(MultiTexCoord2s), + TABLE_ENTRY(MultiTexCoord2sv), + TABLE_ENTRY(MultiTexCoord3d), + TABLE_ENTRY(MultiTexCoord3dv), + TABLE_ENTRY(MultiTexCoord3f), + TABLE_ENTRY(MultiTexCoord3fv), + TABLE_ENTRY(MultiTexCoord3i), + TABLE_ENTRY(MultiTexCoord3iv), + TABLE_ENTRY(MultiTexCoord3s), + TABLE_ENTRY(MultiTexCoord3sv), + TABLE_ENTRY(MultiTexCoord4d), + TABLE_ENTRY(MultiTexCoord4dv), + TABLE_ENTRY(MultiTexCoord4f), + TABLE_ENTRY(MultiTexCoord4fv), + TABLE_ENTRY(MultiTexCoord4i), + TABLE_ENTRY(MultiTexCoord4iv), + TABLE_ENTRY(MultiTexCoord4s), + TABLE_ENTRY(MultiTexCoord4sv), + TABLE_ENTRY(_dispatch_stub_423), + TABLE_ENTRY(LoadTransposeMatrixd), + TABLE_ENTRY(LoadTransposeMatrixf), + TABLE_ENTRY(MultTransposeMatrixd), + TABLE_ENTRY(MultTransposeMatrixf), + TABLE_ENTRY(SampleCoverage), + TABLE_ENTRY(CompressedTexImage1D), + TABLE_ENTRY(CompressedTexImage2D), + TABLE_ENTRY(CompressedTexImage3D), + TABLE_ENTRY(CompressedTexSubImage1D), + TABLE_ENTRY(CompressedTexSubImage2D), + TABLE_ENTRY(CompressedTexSubImage3D), + TABLE_ENTRY(GetCompressedTexImage), + TABLE_ENTRY(DisableVertexAttribArray), + TABLE_ENTRY(EnableVertexAttribArray), + TABLE_ENTRY(GetVertexAttribdv), + TABLE_ENTRY(GetVertexAttribfv), + TABLE_ENTRY(GetVertexAttribiv), + TABLE_ENTRY(ProgramParameter4dNV), + TABLE_ENTRY(ProgramParameter4dvNV), + TABLE_ENTRY(ProgramParameter4fNV), + TABLE_ENTRY(ProgramParameter4fvNV), + TABLE_ENTRY(VertexAttrib1d), + TABLE_ENTRY(VertexAttrib1dv), + TABLE_ENTRY(VertexAttrib1f), + TABLE_ENTRY(VertexAttrib1fv), + TABLE_ENTRY(VertexAttrib1s), + TABLE_ENTRY(VertexAttrib1sv), + TABLE_ENTRY(VertexAttrib2d), + TABLE_ENTRY(VertexAttrib2dv), + TABLE_ENTRY(VertexAttrib2f), + TABLE_ENTRY(VertexAttrib2fv), + TABLE_ENTRY(VertexAttrib2s), + TABLE_ENTRY(VertexAttrib2sv), + TABLE_ENTRY(VertexAttrib3d), + TABLE_ENTRY(VertexAttrib3dv), + TABLE_ENTRY(VertexAttrib3f), + TABLE_ENTRY(VertexAttrib3fv), + TABLE_ENTRY(VertexAttrib3s), + TABLE_ENTRY(VertexAttrib3sv), + TABLE_ENTRY(VertexAttrib4Nbv), + TABLE_ENTRY(VertexAttrib4Niv), + TABLE_ENTRY(VertexAttrib4Nsv), + TABLE_ENTRY(VertexAttrib4Nub), + TABLE_ENTRY(VertexAttrib4Nubv), + TABLE_ENTRY(VertexAttrib4Nuiv), + TABLE_ENTRY(VertexAttrib4Nusv), + TABLE_ENTRY(VertexAttrib4bv), + TABLE_ENTRY(VertexAttrib4d), + TABLE_ENTRY(VertexAttrib4dv), + TABLE_ENTRY(VertexAttrib4f), + TABLE_ENTRY(VertexAttrib4fv), + TABLE_ENTRY(VertexAttrib4iv), + TABLE_ENTRY(VertexAttrib4s), + TABLE_ENTRY(VertexAttrib4sv), + TABLE_ENTRY(VertexAttrib4ubv), + TABLE_ENTRY(VertexAttrib4uiv), + TABLE_ENTRY(VertexAttrib4usv), + TABLE_ENTRY(VertexAttribPointer), + TABLE_ENTRY(BindBuffer), + TABLE_ENTRY(BufferData), + TABLE_ENTRY(BufferSubData), + TABLE_ENTRY(DeleteBuffers), + TABLE_ENTRY(GenBuffers), + TABLE_ENTRY(GetBufferParameteriv), + TABLE_ENTRY(GetBufferPointerv), + TABLE_ENTRY(GetBufferSubData), + TABLE_ENTRY(IsBuffer), + TABLE_ENTRY(MapBuffer), + TABLE_ENTRY(UnmapBuffer), + TABLE_ENTRY(BeginQuery), + TABLE_ENTRY(DeleteQueries), + TABLE_ENTRY(EndQuery), + TABLE_ENTRY(GenQueries), + TABLE_ENTRY(GetQueryObjectiv), + TABLE_ENTRY(GetQueryObjectuiv), + TABLE_ENTRY(GetQueryiv), + TABLE_ENTRY(IsQuery), + TABLE_ENTRY(CompileShader), + TABLE_ENTRY(GetActiveUniform), + TABLE_ENTRY(GetShaderSource), + TABLE_ENTRY(GetUniformLocation), + TABLE_ENTRY(GetUniformfv), + TABLE_ENTRY(GetUniformiv), + TABLE_ENTRY(LinkProgram), + TABLE_ENTRY(ShaderSource), + TABLE_ENTRY(Uniform1f), + TABLE_ENTRY(Uniform1fv), + TABLE_ENTRY(Uniform1i), + TABLE_ENTRY(Uniform1iv), + TABLE_ENTRY(Uniform2f), + TABLE_ENTRY(Uniform2fv), + TABLE_ENTRY(Uniform2i), + TABLE_ENTRY(Uniform2iv), + TABLE_ENTRY(Uniform3f), + TABLE_ENTRY(Uniform3fv), + TABLE_ENTRY(Uniform3i), + TABLE_ENTRY(Uniform3iv), + TABLE_ENTRY(Uniform4f), + TABLE_ENTRY(Uniform4fv), + TABLE_ENTRY(Uniform4i), + TABLE_ENTRY(Uniform4iv), + TABLE_ENTRY(UniformMatrix2fv), + TABLE_ENTRY(UniformMatrix3fv), + TABLE_ENTRY(UniformMatrix4fv), + TABLE_ENTRY(UseProgram), + TABLE_ENTRY(ValidateProgram), + TABLE_ENTRY(BindAttribLocation), + TABLE_ENTRY(GetActiveAttrib), + TABLE_ENTRY(GetAttribLocation), + TABLE_ENTRY(DrawBuffers), + TABLE_ENTRY(DrawBuffersATI), + TABLE_ENTRY(DrawArraysInstancedEXT), + TABLE_ENTRY(DrawArraysInstanced), + TABLE_ENTRY(DrawElementsInstancedEXT), + TABLE_ENTRY(DrawElementsInstanced), + TABLE_ENTRY(RenderbufferStorageMultisampleEXT), + TABLE_ENTRY(PointParameterf), + TABLE_ENTRY(PointParameterfARB), + TABLE_ENTRY(_dispatch_stub_620), + TABLE_ENTRY(PointParameterfv), + TABLE_ENTRY(PointParameterfvARB), + TABLE_ENTRY(_dispatch_stub_621), + TABLE_ENTRY(SecondaryColor3b), + TABLE_ENTRY(SecondaryColor3bv), + TABLE_ENTRY(SecondaryColor3d), + TABLE_ENTRY(SecondaryColor3dv), + TABLE_ENTRY(SecondaryColor3f), + TABLE_ENTRY(SecondaryColor3fv), + TABLE_ENTRY(SecondaryColor3i), + TABLE_ENTRY(SecondaryColor3iv), + TABLE_ENTRY(SecondaryColor3s), + TABLE_ENTRY(SecondaryColor3sv), + TABLE_ENTRY(SecondaryColor3ub), + TABLE_ENTRY(SecondaryColor3ubv), + TABLE_ENTRY(SecondaryColor3ui), + TABLE_ENTRY(SecondaryColor3uiv), + TABLE_ENTRY(SecondaryColor3us), + TABLE_ENTRY(SecondaryColor3usv), + TABLE_ENTRY(SecondaryColorPointer), + TABLE_ENTRY(MultiDrawArrays), + TABLE_ENTRY(MultiDrawElements), + TABLE_ENTRY(FogCoordPointer), + TABLE_ENTRY(FogCoordd), + TABLE_ENTRY(FogCoorddv), + TABLE_ENTRY(FogCoordf), + TABLE_ENTRY(FogCoordfv), + TABLE_ENTRY(BlendFuncSeparate), + TABLE_ENTRY(_dispatch_stub_649), + TABLE_ENTRY(WindowPos2d), + TABLE_ENTRY(WindowPos2dARB), + TABLE_ENTRY(WindowPos2dv), + TABLE_ENTRY(WindowPos2dvARB), + TABLE_ENTRY(WindowPos2f), + TABLE_ENTRY(WindowPos2fARB), + TABLE_ENTRY(WindowPos2fv), + TABLE_ENTRY(WindowPos2fvARB), + TABLE_ENTRY(WindowPos2i), + TABLE_ENTRY(WindowPos2iARB), + TABLE_ENTRY(WindowPos2iv), + TABLE_ENTRY(WindowPos2ivARB), + TABLE_ENTRY(WindowPos2s), + TABLE_ENTRY(WindowPos2sARB), + TABLE_ENTRY(WindowPos2sv), + TABLE_ENTRY(WindowPos2svARB), + TABLE_ENTRY(WindowPos3d), + TABLE_ENTRY(WindowPos3dARB), + TABLE_ENTRY(WindowPos3dv), + TABLE_ENTRY(WindowPos3dvARB), + TABLE_ENTRY(WindowPos3f), + TABLE_ENTRY(WindowPos3fARB), + TABLE_ENTRY(WindowPos3fv), + TABLE_ENTRY(WindowPos3fvARB), + TABLE_ENTRY(WindowPos3i), + TABLE_ENTRY(WindowPos3iARB), + TABLE_ENTRY(WindowPos3iv), + TABLE_ENTRY(WindowPos3ivARB), + TABLE_ENTRY(WindowPos3s), + TABLE_ENTRY(WindowPos3sARB), + TABLE_ENTRY(WindowPos3sv), + TABLE_ENTRY(WindowPos3svARB), + TABLE_ENTRY(BindProgramARB), + TABLE_ENTRY(DeleteProgramsARB), + TABLE_ENTRY(GenProgramsARB), + TABLE_ENTRY(GetVertexAttribPointerv), + TABLE_ENTRY(GetVertexAttribPointervARB), + TABLE_ENTRY(IsProgramARB), + TABLE_ENTRY(PointParameteri), + TABLE_ENTRY(PointParameteriv), + TABLE_ENTRY(DeleteVertexArrays), + TABLE_ENTRY(IsVertexArray), + TABLE_ENTRY(PrimitiveRestartIndex), + TABLE_ENTRY(BlendEquationSeparate), + TABLE_ENTRY(BindFramebuffer), + TABLE_ENTRY(BindRenderbuffer), + TABLE_ENTRY(CheckFramebufferStatus), + TABLE_ENTRY(DeleteFramebuffers), + TABLE_ENTRY(DeleteRenderbuffers), + TABLE_ENTRY(FramebufferRenderbuffer), + TABLE_ENTRY(FramebufferTexture1D), + TABLE_ENTRY(FramebufferTexture2D), + TABLE_ENTRY(FramebufferTexture3D), + TABLE_ENTRY(GenFramebuffers), + TABLE_ENTRY(GenRenderbuffers), + TABLE_ENTRY(GenerateMipmap), + TABLE_ENTRY(GetFramebufferAttachmentParameteriv), + TABLE_ENTRY(GetRenderbufferParameteriv), + TABLE_ENTRY(IsFramebuffer), + TABLE_ENTRY(IsRenderbuffer), + TABLE_ENTRY(RenderbufferStorage), + TABLE_ENTRY(BlitFramebuffer), + TABLE_ENTRY(BindFragDataLocation), + TABLE_ENTRY(GetFragDataLocation), + TABLE_ENTRY(GetUniformuiv), + TABLE_ENTRY(GetVertexAttribIiv), + TABLE_ENTRY(GetVertexAttribIuiv), + TABLE_ENTRY(Uniform1ui), + TABLE_ENTRY(Uniform1uiv), + TABLE_ENTRY(Uniform2ui), + TABLE_ENTRY(Uniform2uiv), + TABLE_ENTRY(Uniform3ui), + TABLE_ENTRY(Uniform3uiv), + TABLE_ENTRY(Uniform4ui), + TABLE_ENTRY(Uniform4uiv), + TABLE_ENTRY(VertexAttribI1i), + TABLE_ENTRY(VertexAttribI1iv), + TABLE_ENTRY(VertexAttribI1ui), + TABLE_ENTRY(VertexAttribI1uiv), + TABLE_ENTRY(VertexAttribI2i), + TABLE_ENTRY(VertexAttribI2iv), + TABLE_ENTRY(VertexAttribI2ui), + TABLE_ENTRY(VertexAttribI2uiv), + TABLE_ENTRY(VertexAttribI3i), + TABLE_ENTRY(VertexAttribI3iv), + TABLE_ENTRY(VertexAttribI3ui), + TABLE_ENTRY(VertexAttribI3uiv), + TABLE_ENTRY(VertexAttribI4bv), + TABLE_ENTRY(VertexAttribI4i), + TABLE_ENTRY(VertexAttribI4iv), + TABLE_ENTRY(VertexAttribI4sv), + TABLE_ENTRY(VertexAttribI4ubv), + TABLE_ENTRY(VertexAttribI4ui), + TABLE_ENTRY(VertexAttribI4uiv), + TABLE_ENTRY(VertexAttribI4usv), + TABLE_ENTRY(VertexAttribIPointer), + TABLE_ENTRY(FramebufferTextureLayer), + TABLE_ENTRY(ColorMaski), + TABLE_ENTRY(Disablei), + TABLE_ENTRY(Enablei), + TABLE_ENTRY(GetBooleani_v), + TABLE_ENTRY(GetIntegeri_v), + TABLE_ENTRY(IsEnabledi), + TABLE_ENTRY(GetTexParameterIiv), + TABLE_ENTRY(GetTexParameterIuiv), + TABLE_ENTRY(TexParameterIiv), + TABLE_ENTRY(TexParameterIuiv), + TABLE_ENTRY(BeginConditionalRender), + TABLE_ENTRY(EndConditionalRender), + TABLE_ENTRY(BeginTransformFeedback), + TABLE_ENTRY(BindBufferBase), + TABLE_ENTRY(BindBufferRange), + TABLE_ENTRY(EndTransformFeedback), + TABLE_ENTRY(GetTransformFeedbackVarying), + TABLE_ENTRY(TransformFeedbackVaryings), + TABLE_ENTRY(ProvokingVertex), +#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */ +#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS + TABLE_ENTRY(AreTexturesResidentEXT), + TABLE_ENTRY(DeleteTexturesEXT), + TABLE_ENTRY(GenTexturesEXT), + TABLE_ENTRY(IsTextureEXT), + TABLE_ENTRY(GetColorTableEXT), + TABLE_ENTRY(_dispatch_stub_343), + TABLE_ENTRY(GetColorTableParameterfvEXT), + TABLE_ENTRY(_dispatch_stub_344), + TABLE_ENTRY(GetColorTableParameterivEXT), + TABLE_ENTRY(_dispatch_stub_345), + TABLE_ENTRY(_dispatch_stub_356), + TABLE_ENTRY(_dispatch_stub_357), + TABLE_ENTRY(_dispatch_stub_358), + TABLE_ENTRY(_dispatch_stub_359), + TABLE_ENTRY(_dispatch_stub_361), + TABLE_ENTRY(_dispatch_stub_362), + TABLE_ENTRY(_dispatch_stub_363), + TABLE_ENTRY(_dispatch_stub_364), + TABLE_ENTRY(_dispatch_stub_365), + TABLE_ENTRY(_dispatch_stub_366), +#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */ +}; +#endif /*UNUSED_TABLE_NAME*/ + + +# undef KEYWORD1 +# undef KEYWORD1_ALT +# undef KEYWORD2 +# undef NAME +# undef DISPATCH +# undef RETURN_DISPATCH +# undef DISPATCH_TABLE_NAME +# undef UNUSED_TABLE_NAME +# undef TABLE_ENTRY +# undef HIDDEN diff --git a/src/mapi/glapi/glprocs.h b/src/mapi/glapi/glprocs.h new file mode 100644 index 0000000..315847e --- /dev/null +++ b/src/mapi/glapi/glprocs.h @@ -0,0 +1,2655 @@ +/* DO NOT EDIT - This file generated automatically by gl_procs.py (from Mesa) script */ + +/* + * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * (C) Copyright IBM Corporation 2004, 2006 + * 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 + * BRIAN PAUL, IBM, + * 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. + */ + + +/* This file is only included by glapi.c and is used for + * the GetProcAddress() function + */ + +typedef struct { + GLint Name_offset; +#if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) + _glapi_proc Address; +#endif + GLuint Offset; +} glprocs_table_t; + +#if !defined(NEED_FUNCTION_POINTER) && !defined(GLX_INDIRECT_RENDERING) +# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , o } +#elif defined(NEED_FUNCTION_POINTER) && !defined(GLX_INDIRECT_RENDERING) +# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f1 , o } +#elif defined(NEED_FUNCTION_POINTER) && defined(GLX_INDIRECT_RENDERING) +# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f2 , o } +#elif !defined(NEED_FUNCTION_POINTER) && defined(GLX_INDIRECT_RENDERING) +# define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f3 , o } +#endif + + + +static const char gl_string_table[] = + "glNewList\0" + "glEndList\0" + "glCallList\0" + "glCallLists\0" + "glDeleteLists\0" + "glGenLists\0" + "glListBase\0" + "glBegin\0" + "glBitmap\0" + "glColor3b\0" + "glColor3bv\0" + "glColor3d\0" + "glColor3dv\0" + "glColor3f\0" + "glColor3fv\0" + "glColor3i\0" + "glColor3iv\0" + "glColor3s\0" + "glColor3sv\0" + "glColor3ub\0" + "glColor3ubv\0" + "glColor3ui\0" + "glColor3uiv\0" + "glColor3us\0" + "glColor3usv\0" + "glColor4b\0" + "glColor4bv\0" + "glColor4d\0" + "glColor4dv\0" + "glColor4f\0" + "glColor4fv\0" + "glColor4i\0" + "glColor4iv\0" + "glColor4s\0" + "glColor4sv\0" + "glColor4ub\0" + "glColor4ubv\0" + "glColor4ui\0" + "glColor4uiv\0" + "glColor4us\0" + "glColor4usv\0" + "glEdgeFlag\0" + "glEdgeFlagv\0" + "glEnd\0" + "glIndexd\0" + "glIndexdv\0" + "glIndexf\0" + "glIndexfv\0" + "glIndexi\0" + "glIndexiv\0" + "glIndexs\0" + "glIndexsv\0" + "glNormal3b\0" + "glNormal3bv\0" + "glNormal3d\0" + "glNormal3dv\0" + "glNormal3f\0" + "glNormal3fv\0" + "glNormal3i\0" + "glNormal3iv\0" + "glNormal3s\0" + "glNormal3sv\0" + "glRasterPos2d\0" + "glRasterPos2dv\0" + "glRasterPos2f\0" + "glRasterPos2fv\0" + "glRasterPos2i\0" + "glRasterPos2iv\0" + "glRasterPos2s\0" + "glRasterPos2sv\0" + "glRasterPos3d\0" + "glRasterPos3dv\0" + "glRasterPos3f\0" + "glRasterPos3fv\0" + "glRasterPos3i\0" + "glRasterPos3iv\0" + "glRasterPos3s\0" + "glRasterPos3sv\0" + "glRasterPos4d\0" + "glRasterPos4dv\0" + "glRasterPos4f\0" + "glRasterPos4fv\0" + "glRasterPos4i\0" + "glRasterPos4iv\0" + "glRasterPos4s\0" + "glRasterPos4sv\0" + "glRectd\0" + "glRectdv\0" + "glRectf\0" + "glRectfv\0" + "glRecti\0" + "glRectiv\0" + "glRects\0" + "glRectsv\0" + "glTexCoord1d\0" + "glTexCoord1dv\0" + "glTexCoord1f\0" + "glTexCoord1fv\0" + "glTexCoord1i\0" + "glTexCoord1iv\0" + "glTexCoord1s\0" + "glTexCoord1sv\0" + "glTexCoord2d\0" + "glTexCoord2dv\0" + "glTexCoord2f\0" + "glTexCoord2fv\0" + "glTexCoord2i\0" + "glTexCoord2iv\0" + "glTexCoord2s\0" + "glTexCoord2sv\0" + "glTexCoord3d\0" + "glTexCoord3dv\0" + "glTexCoord3f\0" + "glTexCoord3fv\0" + "glTexCoord3i\0" + "glTexCoord3iv\0" + "glTexCoord3s\0" + "glTexCoord3sv\0" + "glTexCoord4d\0" + "glTexCoord4dv\0" + "glTexCoord4f\0" + "glTexCoord4fv\0" + "glTexCoord4i\0" + "glTexCoord4iv\0" + "glTexCoord4s\0" + "glTexCoord4sv\0" + "glVertex2d\0" + "glVertex2dv\0" + "glVertex2f\0" + "glVertex2fv\0" + "glVertex2i\0" + "glVertex2iv\0" + "glVertex2s\0" + "glVertex2sv\0" + "glVertex3d\0" + "glVertex3dv\0" + "glVertex3f\0" + "glVertex3fv\0" + "glVertex3i\0" + "glVertex3iv\0" + "glVertex3s\0" + "glVertex3sv\0" + "glVertex4d\0" + "glVertex4dv\0" + "glVertex4f\0" + "glVertex4fv\0" + "glVertex4i\0" + "glVertex4iv\0" + "glVertex4s\0" + "glVertex4sv\0" + "glClipPlane\0" + "glColorMaterial\0" + "glCullFace\0" + "glFogf\0" + "glFogfv\0" + "glFogi\0" + "glFogiv\0" + "glFrontFace\0" + "glHint\0" + "glLightf\0" + "glLightfv\0" + "glLighti\0" + "glLightiv\0" + "glLightModelf\0" + "glLightModelfv\0" + "glLightModeli\0" + "glLightModeliv\0" + "glLineStipple\0" + "glLineWidth\0" + "glMaterialf\0" + "glMaterialfv\0" + "glMateriali\0" + "glMaterialiv\0" + "glPointSize\0" + "glPolygonMode\0" + "glPolygonStipple\0" + "glScissor\0" + "glShadeModel\0" + "glTexParameterf\0" + "glTexParameterfv\0" + "glTexParameteri\0" + "glTexParameteriv\0" + "glTexImage1D\0" + "glTexImage2D\0" + "glTexEnvf\0" + "glTexEnvfv\0" + "glTexEnvi\0" + "glTexEnviv\0" + "glTexGend\0" + "glTexGendv\0" + "glTexGenf\0" + "glTexGenfv\0" + "glTexGeni\0" + "glTexGeniv\0" + "glFeedbackBuffer\0" + "glSelectBuffer\0" + "glRenderMode\0" + "glInitNames\0" + "glLoadName\0" + "glPassThrough\0" + "glPopName\0" + "glPushName\0" + "glDrawBuffer\0" + "glClear\0" + "glClearAccum\0" + "glClearIndex\0" + "glClearColor\0" + "glClearStencil\0" + "glClearDepth\0" + "glStencilMask\0" + "glColorMask\0" + "glDepthMask\0" + "glIndexMask\0" + "glAccum\0" + "glDisable\0" + "glEnable\0" + "glFinish\0" + "glFlush\0" + "glPopAttrib\0" + "glPushAttrib\0" + "glMap1d\0" + "glMap1f\0" + "glMap2d\0" + "glMap2f\0" + "glMapGrid1d\0" + "glMapGrid1f\0" + "glMapGrid2d\0" + "glMapGrid2f\0" + "glEvalCoord1d\0" + "glEvalCoord1dv\0" + "glEvalCoord1f\0" + "glEvalCoord1fv\0" + "glEvalCoord2d\0" + "glEvalCoord2dv\0" + "glEvalCoord2f\0" + "glEvalCoord2fv\0" + "glEvalMesh1\0" + "glEvalPoint1\0" + "glEvalMesh2\0" + "glEvalPoint2\0" + "glAlphaFunc\0" + "glBlendFunc\0" + "glLogicOp\0" + "glStencilFunc\0" + "glStencilOp\0" + "glDepthFunc\0" + "glPixelZoom\0" + "glPixelTransferf\0" + "glPixelTransferi\0" + "glPixelStoref\0" + "glPixelStorei\0" + "glPixelMapfv\0" + "glPixelMapuiv\0" + "glPixelMapusv\0" + "glReadBuffer\0" + "glCopyPixels\0" + "glReadPixels\0" + "glDrawPixels\0" + "glGetBooleanv\0" + "glGetClipPlane\0" + "glGetDoublev\0" + "glGetError\0" + "glGetFloatv\0" + "glGetIntegerv\0" + "glGetLightfv\0" + "glGetLightiv\0" + "glGetMapdv\0" + "glGetMapfv\0" + "glGetMapiv\0" + "glGetMaterialfv\0" + "glGetMaterialiv\0" + "glGetPixelMapfv\0" + "glGetPixelMapuiv\0" + "glGetPixelMapusv\0" + "glGetPolygonStipple\0" + "glGetString\0" + "glGetTexEnvfv\0" + "glGetTexEnviv\0" + "glGetTexGendv\0" + "glGetTexGenfv\0" + "glGetTexGeniv\0" + "glGetTexImage\0" + "glGetTexParameterfv\0" + "glGetTexParameteriv\0" + "glGetTexLevelParameterfv\0" + "glGetTexLevelParameteriv\0" + "glIsEnabled\0" + "glIsList\0" + "glDepthRange\0" + "glFrustum\0" + "glLoadIdentity\0" + "glLoadMatrixf\0" + "glLoadMatrixd\0" + "glMatrixMode\0" + "glMultMatrixf\0" + "glMultMatrixd\0" + "glOrtho\0" + "glPopMatrix\0" + "glPushMatrix\0" + "glRotated\0" + "glRotatef\0" + "glScaled\0" + "glScalef\0" + "glTranslated\0" + "glTranslatef\0" + "glViewport\0" + "glArrayElement\0" + "glBindTexture\0" + "glColorPointer\0" + "glDisableClientState\0" + "glDrawArrays\0" + "glDrawElements\0" + "glEdgeFlagPointer\0" + "glEnableClientState\0" + "glIndexPointer\0" + "glIndexub\0" + "glIndexubv\0" + "glInterleavedArrays\0" + "glNormalPointer\0" + "glPolygonOffset\0" + "glTexCoordPointer\0" + "glVertexPointer\0" + "glAreTexturesResident\0" + "glCopyTexImage1D\0" + "glCopyTexImage2D\0" + "glCopyTexSubImage1D\0" + "glCopyTexSubImage2D\0" + "glDeleteTextures\0" + "glGenTextures\0" + "glGetPointerv\0" + "glIsTexture\0" + "glPrioritizeTextures\0" + "glTexSubImage1D\0" + "glTexSubImage2D\0" + "glPopClientAttrib\0" + "glPushClientAttrib\0" + "glBlendColor\0" + "glBlendEquation\0" + "glDrawRangeElements\0" + "glColorTable\0" + "glColorTableParameterfv\0" + "glColorTableParameteriv\0" + "glCopyColorTable\0" + "glGetColorTable\0" + "glGetColorTableParameterfv\0" + "glGetColorTableParameteriv\0" + "glColorSubTable\0" + "glCopyColorSubTable\0" + "glConvolutionFilter1D\0" + "glConvolutionFilter2D\0" + "glConvolutionParameterf\0" + "glConvolutionParameterfv\0" + "glConvolutionParameteri\0" + "glConvolutionParameteriv\0" + "glCopyConvolutionFilter1D\0" + "glCopyConvolutionFilter2D\0" + "glGetConvolutionFilter\0" + "glGetConvolutionParameterfv\0" + "glGetConvolutionParameteriv\0" + "glGetSeparableFilter\0" + "glSeparableFilter2D\0" + "glGetHistogram\0" + "glGetHistogramParameterfv\0" + "glGetHistogramParameteriv\0" + "glGetMinmax\0" + "glGetMinmaxParameterfv\0" + "glGetMinmaxParameteriv\0" + "glHistogram\0" + "glMinmax\0" + "glResetHistogram\0" + "glResetMinmax\0" + "glTexImage3D\0" + "glTexSubImage3D\0" + "glCopyTexSubImage3D\0" + "glActiveTextureARB\0" + "glClientActiveTextureARB\0" + "glMultiTexCoord1dARB\0" + "glMultiTexCoord1dvARB\0" + "glMultiTexCoord1fARB\0" + "glMultiTexCoord1fvARB\0" + "glMultiTexCoord1iARB\0" + "glMultiTexCoord1ivARB\0" + "glMultiTexCoord1sARB\0" + "glMultiTexCoord1svARB\0" + "glMultiTexCoord2dARB\0" + "glMultiTexCoord2dvARB\0" + "glMultiTexCoord2fARB\0" + "glMultiTexCoord2fvARB\0" + "glMultiTexCoord2iARB\0" + "glMultiTexCoord2ivARB\0" + "glMultiTexCoord2sARB\0" + "glMultiTexCoord2svARB\0" + "glMultiTexCoord3dARB\0" + "glMultiTexCoord3dvARB\0" + "glMultiTexCoord3fARB\0" + "glMultiTexCoord3fvARB\0" + "glMultiTexCoord3iARB\0" + "glMultiTexCoord3ivARB\0" + "glMultiTexCoord3sARB\0" + "glMultiTexCoord3svARB\0" + "glMultiTexCoord4dARB\0" + "glMultiTexCoord4dvARB\0" + "glMultiTexCoord4fARB\0" + "glMultiTexCoord4fvARB\0" + "glMultiTexCoord4iARB\0" + "glMultiTexCoord4ivARB\0" + "glMultiTexCoord4sARB\0" + "glMultiTexCoord4svARB\0" + "glAttachShader\0" + "glCreateProgram\0" + "glCreateShader\0" + "glDeleteProgram\0" + "glDeleteShader\0" + "glDetachShader\0" + "glGetAttachedShaders\0" + "glGetProgramInfoLog\0" + "glGetProgramiv\0" + "glGetShaderInfoLog\0" + "glGetShaderiv\0" + "glIsProgram\0" + "glIsShader\0" + "glStencilFuncSeparate\0" + "glStencilMaskSeparate\0" + "glStencilOpSeparate\0" + "glUniformMatrix2x3fv\0" + "glUniformMatrix2x4fv\0" + "glUniformMatrix3x2fv\0" + "glUniformMatrix3x4fv\0" + "glUniformMatrix4x2fv\0" + "glUniformMatrix4x3fv\0" + "glClampColor\0" + "glClearBufferfi\0" + "glClearBufferfv\0" + "glClearBufferiv\0" + "glClearBufferuiv\0" + "glGetStringi\0" + "glTexBuffer\0" + "glFramebufferTexture\0" + "glGetBufferParameteri64v\0" + "glGetInteger64i_v\0" + "glVertexAttribDivisor\0" + "glLoadTransposeMatrixdARB\0" + "glLoadTransposeMatrixfARB\0" + "glMultTransposeMatrixdARB\0" + "glMultTransposeMatrixfARB\0" + "glSampleCoverageARB\0" + "glCompressedTexImage1DARB\0" + "glCompressedTexImage2DARB\0" + "glCompressedTexImage3DARB\0" + "glCompressedTexSubImage1DARB\0" + "glCompressedTexSubImage2DARB\0" + "glCompressedTexSubImage3DARB\0" + "glGetCompressedTexImageARB\0" + "glDisableVertexAttribArrayARB\0" + "glEnableVertexAttribArrayARB\0" + "glGetProgramEnvParameterdvARB\0" + "glGetProgramEnvParameterfvARB\0" + "glGetProgramLocalParameterdvARB\0" + "glGetProgramLocalParameterfvARB\0" + "glGetProgramStringARB\0" + "glGetProgramivARB\0" + "glGetVertexAttribdvARB\0" + "glGetVertexAttribfvARB\0" + "glGetVertexAttribivARB\0" + "glProgramEnvParameter4dARB\0" + "glProgramEnvParameter4dvARB\0" + "glProgramEnvParameter4fARB\0" + "glProgramEnvParameter4fvARB\0" + "glProgramLocalParameter4dARB\0" + "glProgramLocalParameter4dvARB\0" + "glProgramLocalParameter4fARB\0" + "glProgramLocalParameter4fvARB\0" + "glProgramStringARB\0" + "glVertexAttrib1dARB\0" + "glVertexAttrib1dvARB\0" + "glVertexAttrib1fARB\0" + "glVertexAttrib1fvARB\0" + "glVertexAttrib1sARB\0" + "glVertexAttrib1svARB\0" + "glVertexAttrib2dARB\0" + "glVertexAttrib2dvARB\0" + "glVertexAttrib2fARB\0" + "glVertexAttrib2fvARB\0" + "glVertexAttrib2sARB\0" + "glVertexAttrib2svARB\0" + "glVertexAttrib3dARB\0" + "glVertexAttrib3dvARB\0" + "glVertexAttrib3fARB\0" + "glVertexAttrib3fvARB\0" + "glVertexAttrib3sARB\0" + "glVertexAttrib3svARB\0" + "glVertexAttrib4NbvARB\0" + "glVertexAttrib4NivARB\0" + "glVertexAttrib4NsvARB\0" + "glVertexAttrib4NubARB\0" + "glVertexAttrib4NubvARB\0" + "glVertexAttrib4NuivARB\0" + "glVertexAttrib4NusvARB\0" + "glVertexAttrib4bvARB\0" + "glVertexAttrib4dARB\0" + "glVertexAttrib4dvARB\0" + "glVertexAttrib4fARB\0" + "glVertexAttrib4fvARB\0" + "glVertexAttrib4ivARB\0" + "glVertexAttrib4sARB\0" + "glVertexAttrib4svARB\0" + "glVertexAttrib4ubvARB\0" + "glVertexAttrib4uivARB\0" + "glVertexAttrib4usvARB\0" + "glVertexAttribPointerARB\0" + "glBindBufferARB\0" + "glBufferDataARB\0" + "glBufferSubDataARB\0" + "glDeleteBuffersARB\0" + "glGenBuffersARB\0" + "glGetBufferParameterivARB\0" + "glGetBufferPointervARB\0" + "glGetBufferSubDataARB\0" + "glIsBufferARB\0" + "glMapBufferARB\0" + "glUnmapBufferARB\0" + "glBeginQueryARB\0" + "glDeleteQueriesARB\0" + "glEndQueryARB\0" + "glGenQueriesARB\0" + "glGetQueryObjectivARB\0" + "glGetQueryObjectuivARB\0" + "glGetQueryivARB\0" + "glIsQueryARB\0" + "glAttachObjectARB\0" + "glCompileShaderARB\0" + "glCreateProgramObjectARB\0" + "glCreateShaderObjectARB\0" + "glDeleteObjectARB\0" + "glDetachObjectARB\0" + "glGetActiveUniformARB\0" + "glGetAttachedObjectsARB\0" + "glGetHandleARB\0" + "glGetInfoLogARB\0" + "glGetObjectParameterfvARB\0" + "glGetObjectParameterivARB\0" + "glGetShaderSourceARB\0" + "glGetUniformLocationARB\0" + "glGetUniformfvARB\0" + "glGetUniformivARB\0" + "glLinkProgramARB\0" + "glShaderSourceARB\0" + "glUniform1fARB\0" + "glUniform1fvARB\0" + "glUniform1iARB\0" + "glUniform1ivARB\0" + "glUniform2fARB\0" + "glUniform2fvARB\0" + "glUniform2iARB\0" + "glUniform2ivARB\0" + "glUniform3fARB\0" + "glUniform3fvARB\0" + "glUniform3iARB\0" + "glUniform3ivARB\0" + "glUniform4fARB\0" + "glUniform4fvARB\0" + "glUniform4iARB\0" + "glUniform4ivARB\0" + "glUniformMatrix2fvARB\0" + "glUniformMatrix3fvARB\0" + "glUniformMatrix4fvARB\0" + "glUseProgramObjectARB\0" + "glValidateProgramARB\0" + "glBindAttribLocationARB\0" + "glGetActiveAttribARB\0" + "glGetAttribLocationARB\0" + "glDrawBuffersARB\0" + "glDrawArraysInstancedARB\0" + "glDrawElementsInstancedARB\0" + "glRenderbufferStorageMultisample\0" + "glFramebufferTextureARB\0" + "glFramebufferTextureFaceARB\0" + "glProgramParameteriARB\0" + "glFlushMappedBufferRange\0" + "glMapBufferRange\0" + "glBindVertexArray\0" + "glGenVertexArrays\0" + "glCopyBufferSubData\0" + "glClientWaitSync\0" + "glDeleteSync\0" + "glFenceSync\0" + "glGetInteger64v\0" + "glGetSynciv\0" + "glIsSync\0" + "glWaitSync\0" + "glDrawElementsBaseVertex\0" + "glDrawRangeElementsBaseVertex\0" + "glMultiDrawElementsBaseVertex\0" + "glBindTransformFeedback\0" + "glDeleteTransformFeedbacks\0" + "glDrawTransformFeedback\0" + "glGenTransformFeedbacks\0" + "glIsTransformFeedback\0" + "glPauseTransformFeedback\0" + "glResumeTransformFeedback\0" + "glClearDepthf\0" + "glDepthRangef\0" + "glGetShaderPrecisionFormat\0" + "glReleaseShaderCompiler\0" + "glShaderBinary\0" + "glPolygonOffsetEXT\0" + "glGetPixelTexGenParameterfvSGIS\0" + "glGetPixelTexGenParameterivSGIS\0" + "glPixelTexGenParameterfSGIS\0" + "glPixelTexGenParameterfvSGIS\0" + "glPixelTexGenParameteriSGIS\0" + "glPixelTexGenParameterivSGIS\0" + "glSampleMaskSGIS\0" + "glSamplePatternSGIS\0" + "glColorPointerEXT\0" + "glEdgeFlagPointerEXT\0" + "glIndexPointerEXT\0" + "glNormalPointerEXT\0" + "glTexCoordPointerEXT\0" + "glVertexPointerEXT\0" + "glPointParameterfEXT\0" + "glPointParameterfvEXT\0" + "glLockArraysEXT\0" + "glUnlockArraysEXT\0" + "glSecondaryColor3bEXT\0" + "glSecondaryColor3bvEXT\0" + "glSecondaryColor3dEXT\0" + "glSecondaryColor3dvEXT\0" + "glSecondaryColor3fEXT\0" + "glSecondaryColor3fvEXT\0" + "glSecondaryColor3iEXT\0" + "glSecondaryColor3ivEXT\0" + "glSecondaryColor3sEXT\0" + "glSecondaryColor3svEXT\0" + "glSecondaryColor3ubEXT\0" + "glSecondaryColor3ubvEXT\0" + "glSecondaryColor3uiEXT\0" + "glSecondaryColor3uivEXT\0" + "glSecondaryColor3usEXT\0" + "glSecondaryColor3usvEXT\0" + "glSecondaryColorPointerEXT\0" + "glMultiDrawArraysEXT\0" + "glMultiDrawElementsEXT\0" + "glFogCoordPointerEXT\0" + "glFogCoorddEXT\0" + "glFogCoorddvEXT\0" + "glFogCoordfEXT\0" + "glFogCoordfvEXT\0" + "glPixelTexGenSGIX\0" + "glBlendFuncSeparateEXT\0" + "glFlushVertexArrayRangeNV\0" + "glVertexArrayRangeNV\0" + "glCombinerInputNV\0" + "glCombinerOutputNV\0" + "glCombinerParameterfNV\0" + "glCombinerParameterfvNV\0" + "glCombinerParameteriNV\0" + "glCombinerParameterivNV\0" + "glFinalCombinerInputNV\0" + "glGetCombinerInputParameterfvNV\0" + "glGetCombinerInputParameterivNV\0" + "glGetCombinerOutputParameterfvNV\0" + "glGetCombinerOutputParameterivNV\0" + "glGetFinalCombinerInputParameterfvNV\0" + "glGetFinalCombinerInputParameterivNV\0" + "glResizeBuffersMESA\0" + "glWindowPos2dMESA\0" + "glWindowPos2dvMESA\0" + "glWindowPos2fMESA\0" + "glWindowPos2fvMESA\0" + "glWindowPos2iMESA\0" + "glWindowPos2ivMESA\0" + "glWindowPos2sMESA\0" + "glWindowPos2svMESA\0" + "glWindowPos3dMESA\0" + "glWindowPos3dvMESA\0" + "glWindowPos3fMESA\0" + "glWindowPos3fvMESA\0" + "glWindowPos3iMESA\0" + "glWindowPos3ivMESA\0" + "glWindowPos3sMESA\0" + "glWindowPos3svMESA\0" + "glWindowPos4dMESA\0" + "glWindowPos4dvMESA\0" + "glWindowPos4fMESA\0" + "glWindowPos4fvMESA\0" + "glWindowPos4iMESA\0" + "glWindowPos4ivMESA\0" + "glWindowPos4sMESA\0" + "glWindowPos4svMESA\0" + "glMultiModeDrawArraysIBM\0" + "glMultiModeDrawElementsIBM\0" + "glDeleteFencesNV\0" + "glFinishFenceNV\0" + "glGenFencesNV\0" + "glGetFenceivNV\0" + "glIsFenceNV\0" + "glSetFenceNV\0" + "glTestFenceNV\0" + "glAreProgramsResidentNV\0" + "glBindProgramNV\0" + "glDeleteProgramsNV\0" + "glExecuteProgramNV\0" + "glGenProgramsNV\0" + "glGetProgramParameterdvNV\0" + "glGetProgramParameterfvNV\0" + "glGetProgramStringNV\0" + "glGetProgramivNV\0" + "glGetTrackMatrixivNV\0" + "glGetVertexAttribPointervNV\0" + "glGetVertexAttribdvNV\0" + "glGetVertexAttribfvNV\0" + "glGetVertexAttribivNV\0" + "glIsProgramNV\0" + "glLoadProgramNV\0" + "glProgramParameters4dvNV\0" + "glProgramParameters4fvNV\0" + "glRequestResidentProgramsNV\0" + "glTrackMatrixNV\0" + "glVertexAttrib1dNV\0" + "glVertexAttrib1dvNV\0" + "glVertexAttrib1fNV\0" + "glVertexAttrib1fvNV\0" + "glVertexAttrib1sNV\0" + "glVertexAttrib1svNV\0" + "glVertexAttrib2dNV\0" + "glVertexAttrib2dvNV\0" + "glVertexAttrib2fNV\0" + "glVertexAttrib2fvNV\0" + "glVertexAttrib2sNV\0" + "glVertexAttrib2svNV\0" + "glVertexAttrib3dNV\0" + "glVertexAttrib3dvNV\0" + "glVertexAttrib3fNV\0" + "glVertexAttrib3fvNV\0" + "glVertexAttrib3sNV\0" + "glVertexAttrib3svNV\0" + "glVertexAttrib4dNV\0" + "glVertexAttrib4dvNV\0" + "glVertexAttrib4fNV\0" + "glVertexAttrib4fvNV\0" + "glVertexAttrib4sNV\0" + "glVertexAttrib4svNV\0" + "glVertexAttrib4ubNV\0" + "glVertexAttrib4ubvNV\0" + "glVertexAttribPointerNV\0" + "glVertexAttribs1dvNV\0" + "glVertexAttribs1fvNV\0" + "glVertexAttribs1svNV\0" + "glVertexAttribs2dvNV\0" + "glVertexAttribs2fvNV\0" + "glVertexAttribs2svNV\0" + "glVertexAttribs3dvNV\0" + "glVertexAttribs3fvNV\0" + "glVertexAttribs3svNV\0" + "glVertexAttribs4dvNV\0" + "glVertexAttribs4fvNV\0" + "glVertexAttribs4svNV\0" + "glVertexAttribs4ubvNV\0" + "glGetTexBumpParameterfvATI\0" + "glGetTexBumpParameterivATI\0" + "glTexBumpParameterfvATI\0" + "glTexBumpParameterivATI\0" + "glAlphaFragmentOp1ATI\0" + "glAlphaFragmentOp2ATI\0" + "glAlphaFragmentOp3ATI\0" + "glBeginFragmentShaderATI\0" + "glBindFragmentShaderATI\0" + "glColorFragmentOp1ATI\0" + "glColorFragmentOp2ATI\0" + "glColorFragmentOp3ATI\0" + "glDeleteFragmentShaderATI\0" + "glEndFragmentShaderATI\0" + "glGenFragmentShadersATI\0" + "glPassTexCoordATI\0" + "glSampleMapATI\0" + "glSetFragmentShaderConstantATI\0" + "glPointParameteriNV\0" + "glPointParameterivNV\0" + "glActiveStencilFaceEXT\0" + "glBindVertexArrayAPPLE\0" + "glDeleteVertexArraysAPPLE\0" + "glGenVertexArraysAPPLE\0" + "glIsVertexArrayAPPLE\0" + "glGetProgramNamedParameterdvNV\0" + "glGetProgramNamedParameterfvNV\0" + "glProgramNamedParameter4dNV\0" + "glProgramNamedParameter4dvNV\0" + "glProgramNamedParameter4fNV\0" + "glProgramNamedParameter4fvNV\0" + "glPrimitiveRestartIndexNV\0" + "glPrimitiveRestartNV\0" + "glDepthBoundsEXT\0" + "glBlendEquationSeparateEXT\0" + "glBindFramebufferEXT\0" + "glBindRenderbufferEXT\0" + "glCheckFramebufferStatusEXT\0" + "glDeleteFramebuffersEXT\0" + "glDeleteRenderbuffersEXT\0" + "glFramebufferRenderbufferEXT\0" + "glFramebufferTexture1DEXT\0" + "glFramebufferTexture2DEXT\0" + "glFramebufferTexture3DEXT\0" + "glGenFramebuffersEXT\0" + "glGenRenderbuffersEXT\0" + "glGenerateMipmapEXT\0" + "glGetFramebufferAttachmentParameterivEXT\0" + "glGetRenderbufferParameterivEXT\0" + "glIsFramebufferEXT\0" + "glIsRenderbufferEXT\0" + "glRenderbufferStorageEXT\0" + "glBlitFramebufferEXT\0" + "glBufferParameteriAPPLE\0" + "glFlushMappedBufferRangeAPPLE\0" + "glBindFragDataLocationEXT\0" + "glGetFragDataLocationEXT\0" + "glGetUniformuivEXT\0" + "glGetVertexAttribIivEXT\0" + "glGetVertexAttribIuivEXT\0" + "glUniform1uiEXT\0" + "glUniform1uivEXT\0" + "glUniform2uiEXT\0" + "glUniform2uivEXT\0" + "glUniform3uiEXT\0" + "glUniform3uivEXT\0" + "glUniform4uiEXT\0" + "glUniform4uivEXT\0" + "glVertexAttribI1iEXT\0" + "glVertexAttribI1ivEXT\0" + "glVertexAttribI1uiEXT\0" + "glVertexAttribI1uivEXT\0" + "glVertexAttribI2iEXT\0" + "glVertexAttribI2ivEXT\0" + "glVertexAttribI2uiEXT\0" + "glVertexAttribI2uivEXT\0" + "glVertexAttribI3iEXT\0" + "glVertexAttribI3ivEXT\0" + "glVertexAttribI3uiEXT\0" + "glVertexAttribI3uivEXT\0" + "glVertexAttribI4bvEXT\0" + "glVertexAttribI4iEXT\0" + "glVertexAttribI4ivEXT\0" + "glVertexAttribI4svEXT\0" + "glVertexAttribI4ubvEXT\0" + "glVertexAttribI4uiEXT\0" + "glVertexAttribI4uivEXT\0" + "glVertexAttribI4usvEXT\0" + "glVertexAttribIPointerEXT\0" + "glFramebufferTextureLayerEXT\0" + "glColorMaskIndexedEXT\0" + "glDisableIndexedEXT\0" + "glEnableIndexedEXT\0" + "glGetBooleanIndexedvEXT\0" + "glGetIntegerIndexedvEXT\0" + "glIsEnabledIndexedEXT\0" + "glClearColorIiEXT\0" + "glClearColorIuiEXT\0" + "glGetTexParameterIivEXT\0" + "glGetTexParameterIuivEXT\0" + "glTexParameterIivEXT\0" + "glTexParameterIuivEXT\0" + "glBeginConditionalRenderNV\0" + "glEndConditionalRenderNV\0" + "glBeginTransformFeedbackEXT\0" + "glBindBufferBaseEXT\0" + "glBindBufferOffsetEXT\0" + "glBindBufferRangeEXT\0" + "glEndTransformFeedbackEXT\0" + "glGetTransformFeedbackVaryingEXT\0" + "glTransformFeedbackVaryingsEXT\0" + "glProvokingVertexEXT\0" + "glGetTexParameterPointervAPPLE\0" + "glTextureRangeAPPLE\0" + "glGetObjectParameterivAPPLE\0" + "glObjectPurgeableAPPLE\0" + "glObjectUnpurgeableAPPLE\0" + "glActiveProgramEXT\0" + "glCreateShaderProgramEXT\0" + "glUseShaderProgramEXT\0" + "glStencilFuncSeparateATI\0" + "glProgramEnvParameters4fvEXT\0" + "glProgramLocalParameters4fvEXT\0" + "glGetQueryObjecti64vEXT\0" + "glGetQueryObjectui64vEXT\0" + "glEGLImageTargetRenderbufferStorageOES\0" + "glEGLImageTargetTexture2DOES\0" + "glArrayElementEXT\0" + "glBindTextureEXT\0" + "glDrawArraysEXT\0" + "glAreTexturesResidentEXT\0" + "glCopyTexImage1DEXT\0" + "glCopyTexImage2DEXT\0" + "glCopyTexSubImage1DEXT\0" + "glCopyTexSubImage2DEXT\0" + "glDeleteTexturesEXT\0" + "glGenTexturesEXT\0" + "glGetPointervEXT\0" + "glIsTextureEXT\0" + "glPrioritizeTexturesEXT\0" + "glTexSubImage1DEXT\0" + "glTexSubImage2DEXT\0" + "glBlendColorEXT\0" + "glBlendEquationEXT\0" + "glDrawRangeElementsEXT\0" + "glColorTableSGI\0" + "glColorTableEXT\0" + "glColorTableParameterfvSGI\0" + "glColorTableParameterivSGI\0" + "glCopyColorTableSGI\0" + "glGetColorTableSGI\0" + "glGetColorTableEXT\0" + "glGetColorTableParameterfvSGI\0" + "glGetColorTableParameterfvEXT\0" + "glGetColorTableParameterivSGI\0" + "glGetColorTableParameterivEXT\0" + "glColorSubTableEXT\0" + "glCopyColorSubTableEXT\0" + "glConvolutionFilter1DEXT\0" + "glConvolutionFilter2DEXT\0" + "glConvolutionParameterfEXT\0" + "glConvolutionParameterfvEXT\0" + "glConvolutionParameteriEXT\0" + "glConvolutionParameterivEXT\0" + "glCopyConvolutionFilter1DEXT\0" + "glCopyConvolutionFilter2DEXT\0" + "glGetConvolutionFilterEXT\0" + "glGetConvolutionParameterfvEXT\0" + "glGetConvolutionParameterivEXT\0" + "glGetSeparableFilterEXT\0" + "glSeparableFilter2DEXT\0" + "glGetHistogramEXT\0" + "glGetHistogramParameterfvEXT\0" + "glGetHistogramParameterivEXT\0" + "glGetMinmaxEXT\0" + "glGetMinmaxParameterfvEXT\0" + "glGetMinmaxParameterivEXT\0" + "glHistogramEXT\0" + "glMinmaxEXT\0" + "glResetHistogramEXT\0" + "glResetMinmaxEXT\0" + "glTexImage3DEXT\0" + "glTexSubImage3DEXT\0" + "glCopyTexSubImage3DEXT\0" + "glActiveTexture\0" + "glClientActiveTexture\0" + "glMultiTexCoord1d\0" + "glMultiTexCoord1dv\0" + "glMultiTexCoord1f\0" + "glMultiTexCoord1fv\0" + "glMultiTexCoord1i\0" + "glMultiTexCoord1iv\0" + "glMultiTexCoord1s\0" + "glMultiTexCoord1sv\0" + "glMultiTexCoord2d\0" + "glMultiTexCoord2dv\0" + "glMultiTexCoord2f\0" + "glMultiTexCoord2fv\0" + "glMultiTexCoord2i\0" + "glMultiTexCoord2iv\0" + "glMultiTexCoord2s\0" + "glMultiTexCoord2sv\0" + "glMultiTexCoord3d\0" + "glMultiTexCoord3dv\0" + "glMultiTexCoord3f\0" + "glMultiTexCoord3fv\0" + "glMultiTexCoord3i\0" + "glMultiTexCoord3iv\0" + "glMultiTexCoord3s\0" + "glMultiTexCoord3sv\0" + "glMultiTexCoord4d\0" + "glMultiTexCoord4dv\0" + "glMultiTexCoord4f\0" + "glMultiTexCoord4fv\0" + "glMultiTexCoord4i\0" + "glMultiTexCoord4iv\0" + "glMultiTexCoord4s\0" + "glMultiTexCoord4sv\0" + "glStencilOpSeparateATI\0" + "glLoadTransposeMatrixd\0" + "glLoadTransposeMatrixf\0" + "glMultTransposeMatrixd\0" + "glMultTransposeMatrixf\0" + "glSampleCoverage\0" + "glCompressedTexImage1D\0" + "glCompressedTexImage2D\0" + "glCompressedTexImage3D\0" + "glCompressedTexSubImage1D\0" + "glCompressedTexSubImage2D\0" + "glCompressedTexSubImage3D\0" + "glGetCompressedTexImage\0" + "glDisableVertexAttribArray\0" + "glEnableVertexAttribArray\0" + "glGetVertexAttribdv\0" + "glGetVertexAttribfv\0" + "glGetVertexAttribiv\0" + "glProgramParameter4dNV\0" + "glProgramParameter4dvNV\0" + "glProgramParameter4fNV\0" + "glProgramParameter4fvNV\0" + "glVertexAttrib1d\0" + "glVertexAttrib1dv\0" + "glVertexAttrib1f\0" + "glVertexAttrib1fv\0" + "glVertexAttrib1s\0" + "glVertexAttrib1sv\0" + "glVertexAttrib2d\0" + "glVertexAttrib2dv\0" + "glVertexAttrib2f\0" + "glVertexAttrib2fv\0" + "glVertexAttrib2s\0" + "glVertexAttrib2sv\0" + "glVertexAttrib3d\0" + "glVertexAttrib3dv\0" + "glVertexAttrib3f\0" + "glVertexAttrib3fv\0" + "glVertexAttrib3s\0" + "glVertexAttrib3sv\0" + "glVertexAttrib4Nbv\0" + "glVertexAttrib4Niv\0" + "glVertexAttrib4Nsv\0" + "glVertexAttrib4Nub\0" + "glVertexAttrib4Nubv\0" + "glVertexAttrib4Nuiv\0" + "glVertexAttrib4Nusv\0" + "glVertexAttrib4bv\0" + "glVertexAttrib4d\0" + "glVertexAttrib4dv\0" + "glVertexAttrib4f\0" + "glVertexAttrib4fv\0" + "glVertexAttrib4iv\0" + "glVertexAttrib4s\0" + "glVertexAttrib4sv\0" + "glVertexAttrib4ubv\0" + "glVertexAttrib4uiv\0" + "glVertexAttrib4usv\0" + "glVertexAttribPointer\0" + "glBindBuffer\0" + "glBufferData\0" + "glBufferSubData\0" + "glDeleteBuffers\0" + "glGenBuffers\0" + "glGetBufferParameteriv\0" + "glGetBufferPointerv\0" + "glGetBufferSubData\0" + "glIsBuffer\0" + "glMapBuffer\0" + "glUnmapBuffer\0" + "glBeginQuery\0" + "glDeleteQueries\0" + "glEndQuery\0" + "glGenQueries\0" + "glGetQueryObjectiv\0" + "glGetQueryObjectuiv\0" + "glGetQueryiv\0" + "glIsQuery\0" + "glCompileShader\0" + "glGetActiveUniform\0" + "glGetShaderSource\0" + "glGetUniformLocation\0" + "glGetUniformfv\0" + "glGetUniformiv\0" + "glLinkProgram\0" + "glShaderSource\0" + "glUniform1f\0" + "glUniform1fv\0" + "glUniform1i\0" + "glUniform1iv\0" + "glUniform2f\0" + "glUniform2fv\0" + "glUniform2i\0" + "glUniform2iv\0" + "glUniform3f\0" + "glUniform3fv\0" + "glUniform3i\0" + "glUniform3iv\0" + "glUniform4f\0" + "glUniform4fv\0" + "glUniform4i\0" + "glUniform4iv\0" + "glUniformMatrix2fv\0" + "glUniformMatrix3fv\0" + "glUniformMatrix4fv\0" + "glUseProgram\0" + "glValidateProgram\0" + "glBindAttribLocation\0" + "glGetActiveAttrib\0" + "glGetAttribLocation\0" + "glDrawBuffers\0" + "glDrawBuffersATI\0" + "glDrawArraysInstancedEXT\0" + "glDrawArraysInstanced\0" + "glDrawElementsInstancedEXT\0" + "glDrawElementsInstanced\0" + "glRenderbufferStorageMultisampleEXT\0" + "glSampleMaskEXT\0" + "glSamplePatternEXT\0" + "glPointParameterf\0" + "glPointParameterfARB\0" + "glPointParameterfSGIS\0" + "glPointParameterfv\0" + "glPointParameterfvARB\0" + "glPointParameterfvSGIS\0" + "glSecondaryColor3b\0" + "glSecondaryColor3bv\0" + "glSecondaryColor3d\0" + "glSecondaryColor3dv\0" + "glSecondaryColor3f\0" + "glSecondaryColor3fv\0" + "glSecondaryColor3i\0" + "glSecondaryColor3iv\0" + "glSecondaryColor3s\0" + "glSecondaryColor3sv\0" + "glSecondaryColor3ub\0" + "glSecondaryColor3ubv\0" + "glSecondaryColor3ui\0" + "glSecondaryColor3uiv\0" + "glSecondaryColor3us\0" + "glSecondaryColor3usv\0" + "glSecondaryColorPointer\0" + "glMultiDrawArrays\0" + "glMultiDrawElements\0" + "glFogCoordPointer\0" + "glFogCoordd\0" + "glFogCoorddv\0" + "glFogCoordf\0" + "glFogCoordfv\0" + "glBlendFuncSeparate\0" + "glBlendFuncSeparateINGR\0" + "glWindowPos2d\0" + "glWindowPos2dARB\0" + "glWindowPos2dv\0" + "glWindowPos2dvARB\0" + "glWindowPos2f\0" + "glWindowPos2fARB\0" + "glWindowPos2fv\0" + "glWindowPos2fvARB\0" + "glWindowPos2i\0" + "glWindowPos2iARB\0" + "glWindowPos2iv\0" + "glWindowPos2ivARB\0" + "glWindowPos2s\0" + "glWindowPos2sARB\0" + "glWindowPos2sv\0" + "glWindowPos2svARB\0" + "glWindowPos3d\0" + "glWindowPos3dARB\0" + "glWindowPos3dv\0" + "glWindowPos3dvARB\0" + "glWindowPos3f\0" + "glWindowPos3fARB\0" + "glWindowPos3fv\0" + "glWindowPos3fvARB\0" + "glWindowPos3i\0" + "glWindowPos3iARB\0" + "glWindowPos3iv\0" + "glWindowPos3ivARB\0" + "glWindowPos3s\0" + "glWindowPos3sARB\0" + "glWindowPos3sv\0" + "glWindowPos3svARB\0" + "glBindProgramARB\0" + "glDeleteProgramsARB\0" + "glGenProgramsARB\0" + "glGetVertexAttribPointerv\0" + "glGetVertexAttribPointervARB\0" + "glIsProgramARB\0" + "glPointParameteri\0" + "glPointParameteriv\0" + "glDeleteVertexArrays\0" + "glIsVertexArray\0" + "glPrimitiveRestartIndex\0" + "glBlendEquationSeparate\0" + "glBlendEquationSeparateATI\0" + "glBindFramebuffer\0" + "glBindRenderbuffer\0" + "glCheckFramebufferStatus\0" + "glDeleteFramebuffers\0" + "glDeleteRenderbuffers\0" + "glFramebufferRenderbuffer\0" + "glFramebufferTexture1D\0" + "glFramebufferTexture2D\0" + "glFramebufferTexture3D\0" + "glGenFramebuffers\0" + "glGenRenderbuffers\0" + "glGenerateMipmap\0" + "glGetFramebufferAttachmentParameteriv\0" + "glGetRenderbufferParameteriv\0" + "glIsFramebuffer\0" + "glIsRenderbuffer\0" + "glRenderbufferStorage\0" + "glBlitFramebuffer\0" + "glBindFragDataLocation\0" + "glGetFragDataLocation\0" + "glGetUniformuiv\0" + "glGetVertexAttribIiv\0" + "glGetVertexAttribIuiv\0" + "glUniform1ui\0" + "glUniform1uiv\0" + "glUniform2ui\0" + "glUniform2uiv\0" + "glUniform3ui\0" + "glUniform3uiv\0" + "glUniform4ui\0" + "glUniform4uiv\0" + "glVertexAttribI1i\0" + "glVertexAttribI1iv\0" + "glVertexAttribI1ui\0" + "glVertexAttribI1uiv\0" + "glVertexAttribI2i\0" + "glVertexAttribI2iv\0" + "glVertexAttribI2ui\0" + "glVertexAttribI2uiv\0" + "glVertexAttribI3i\0" + "glVertexAttribI3iv\0" + "glVertexAttribI3ui\0" + "glVertexAttribI3uiv\0" + "glVertexAttribI4bv\0" + "glVertexAttribI4i\0" + "glVertexAttribI4iv\0" + "glVertexAttribI4sv\0" + "glVertexAttribI4ubv\0" + "glVertexAttribI4ui\0" + "glVertexAttribI4uiv\0" + "glVertexAttribI4usv\0" + "glVertexAttribIPointer\0" + "glFramebufferTextureLayer\0" + "glColorMaski\0" + "glDisablei\0" + "glEnablei\0" + "glGetBooleani_v\0" + "glGetIntegeri_v\0" + "glIsEnabledi\0" + "glGetTexParameterIiv\0" + "glGetTexParameterIuiv\0" + "glTexParameterIiv\0" + "glTexParameterIuiv\0" + "glBeginConditionalRender\0" + "glEndConditionalRender\0" + "glBeginTransformFeedback\0" + "glBindBufferBase\0" + "glBindBufferRange\0" + "glEndTransformFeedback\0" + "glGetTransformFeedbackVarying\0" + "glTransformFeedbackVaryings\0" + "glProvokingVertex\0" + ; + + +#ifdef USE_MGL_NAMESPACE +#define gl_dispatch_stub_343 mgl_dispatch_stub_343 +#define gl_dispatch_stub_344 mgl_dispatch_stub_344 +#define gl_dispatch_stub_345 mgl_dispatch_stub_345 +#define gl_dispatch_stub_356 mgl_dispatch_stub_356 +#define gl_dispatch_stub_357 mgl_dispatch_stub_357 +#define gl_dispatch_stub_358 mgl_dispatch_stub_358 +#define gl_dispatch_stub_359 mgl_dispatch_stub_359 +#define gl_dispatch_stub_361 mgl_dispatch_stub_361 +#define gl_dispatch_stub_362 mgl_dispatch_stub_362 +#define gl_dispatch_stub_363 mgl_dispatch_stub_363 +#define gl_dispatch_stub_364 mgl_dispatch_stub_364 +#define gl_dispatch_stub_365 mgl_dispatch_stub_365 +#define gl_dispatch_stub_366 mgl_dispatch_stub_366 +#define gl_dispatch_stub_606 mgl_dispatch_stub_606 +#define gl_dispatch_stub_607 mgl_dispatch_stub_607 +#define gl_dispatch_stub_608 mgl_dispatch_stub_608 +#define gl_dispatch_stub_609 mgl_dispatch_stub_609 +#define gl_dispatch_stub_610 mgl_dispatch_stub_610 +#define gl_dispatch_stub_611 mgl_dispatch_stub_611 +#define gl_dispatch_stub_612 mgl_dispatch_stub_612 +#define gl_dispatch_stub_613 mgl_dispatch_stub_613 +#define gl_dispatch_stub_648 mgl_dispatch_stub_648 +#define gl_dispatch_stub_690 mgl_dispatch_stub_690 +#define gl_dispatch_stub_691 mgl_dispatch_stub_691 +#define gl_dispatch_stub_692 mgl_dispatch_stub_692 +#define gl_dispatch_stub_693 mgl_dispatch_stub_693 +#define gl_dispatch_stub_694 mgl_dispatch_stub_694 +#define gl_dispatch_stub_695 mgl_dispatch_stub_695 +#define gl_dispatch_stub_696 mgl_dispatch_stub_696 +#define gl_dispatch_stub_697 mgl_dispatch_stub_697 +#define gl_dispatch_stub_698 mgl_dispatch_stub_698 +#define gl_dispatch_stub_779 mgl_dispatch_stub_779 +#define gl_dispatch_stub_780 mgl_dispatch_stub_780 +#define gl_dispatch_stub_781 mgl_dispatch_stub_781 +#define gl_dispatch_stub_782 mgl_dispatch_stub_782 +#define gl_dispatch_stub_783 mgl_dispatch_stub_783 +#define gl_dispatch_stub_792 mgl_dispatch_stub_792 +#define gl_dispatch_stub_793 mgl_dispatch_stub_793 +#define gl_dispatch_stub_811 mgl_dispatch_stub_811 +#define gl_dispatch_stub_812 mgl_dispatch_stub_812 +#define gl_dispatch_stub_813 mgl_dispatch_stub_813 +#define gl_dispatch_stub_871 mgl_dispatch_stub_871 +#define gl_dispatch_stub_872 mgl_dispatch_stub_872 +#define gl_dispatch_stub_879 mgl_dispatch_stub_879 +#define gl_dispatch_stub_880 mgl_dispatch_stub_880 +#define gl_dispatch_stub_881 mgl_dispatch_stub_881 +#define gl_dispatch_stub_882 mgl_dispatch_stub_882 +#define gl_dispatch_stub_883 mgl_dispatch_stub_883 +#endif /* USE_MGL_NAMESPACE */ + + +#if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) +void GLAPIENTRY gl_dispatch_stub_343(GLenum target, GLenum format, GLenum type, GLvoid * table); +void GLAPIENTRY gl_dispatch_stub_344(GLenum target, GLenum pname, GLfloat * params); +void GLAPIENTRY gl_dispatch_stub_345(GLenum target, GLenum pname, GLint * params); +void GLAPIENTRY gl_dispatch_stub_356(GLenum target, GLenum format, GLenum type, GLvoid * image); +void GLAPIENTRY gl_dispatch_stub_357(GLenum target, GLenum pname, GLfloat * params); +void GLAPIENTRY gl_dispatch_stub_358(GLenum target, GLenum pname, GLint * params); +void GLAPIENTRY gl_dispatch_stub_359(GLenum target, GLenum format, GLenum type, GLvoid * row, GLvoid * column, GLvoid * span); +void GLAPIENTRY gl_dispatch_stub_361(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid * values); +void GLAPIENTRY gl_dispatch_stub_362(GLenum target, GLenum pname, GLfloat * params); +void GLAPIENTRY gl_dispatch_stub_363(GLenum target, GLenum pname, GLint * params); +void GLAPIENTRY gl_dispatch_stub_364(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid * values); +void GLAPIENTRY gl_dispatch_stub_365(GLenum target, GLenum pname, GLfloat * params); +void GLAPIENTRY gl_dispatch_stub_366(GLenum target, GLenum pname, GLint * params); +void GLAPIENTRY gl_dispatch_stub_606(GLenum pname, GLfloat * params); +void GLAPIENTRY gl_dispatch_stub_607(GLenum pname, GLint * params); +void GLAPIENTRY gl_dispatch_stub_608(GLenum pname, GLfloat param); +void GLAPIENTRY gl_dispatch_stub_609(GLenum pname, const GLfloat * params); +void GLAPIENTRY gl_dispatch_stub_610(GLenum pname, GLint param); +void GLAPIENTRY gl_dispatch_stub_611(GLenum pname, const GLint * params); +void GLAPIENTRY gl_dispatch_stub_612(GLclampf value, GLboolean invert); +void GLAPIENTRY gl_dispatch_stub_613(GLenum pattern); +void GLAPIENTRY gl_dispatch_stub_648(GLenum mode); +void GLAPIENTRY gl_dispatch_stub_690(const GLenum * mode, const GLint * first, const GLsizei * count, GLsizei primcount, GLint modestride); +void GLAPIENTRY gl_dispatch_stub_691(const GLenum * mode, const GLsizei * count, GLenum type, const GLvoid * const * indices, GLsizei primcount, GLint modestride); +void GLAPIENTRY gl_dispatch_stub_692(GLsizei n, const GLuint * fences); +void GLAPIENTRY gl_dispatch_stub_693(GLuint fence); +void GLAPIENTRY gl_dispatch_stub_694(GLsizei n, GLuint * fences); +void GLAPIENTRY gl_dispatch_stub_695(GLuint fence, GLenum pname, GLint * params); +GLboolean GLAPIENTRY gl_dispatch_stub_696(GLuint fence); +void GLAPIENTRY gl_dispatch_stub_697(GLuint fence, GLenum condition); +GLboolean GLAPIENTRY gl_dispatch_stub_698(GLuint fence); +void GLAPIENTRY gl_dispatch_stub_779(GLenum face); +void GLAPIENTRY gl_dispatch_stub_780(GLuint array); +void GLAPIENTRY gl_dispatch_stub_781(GLsizei n, const GLuint * arrays); +void GLAPIENTRY gl_dispatch_stub_782(GLsizei n, GLuint * arrays); +GLboolean GLAPIENTRY gl_dispatch_stub_783(GLuint array); +void GLAPIENTRY gl_dispatch_stub_792(GLclampd zmin, GLclampd zmax); +void GLAPIENTRY gl_dispatch_stub_793(GLenum modeRGB, GLenum modeA); +void GLAPIENTRY gl_dispatch_stub_811(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +void GLAPIENTRY gl_dispatch_stub_812(GLenum target, GLenum pname, GLint param); +void GLAPIENTRY gl_dispatch_stub_813(GLenum target, GLintptr offset, GLsizeiptr size); +void GLAPIENTRY gl_dispatch_stub_871(GLenum target, GLenum pname, GLvoid ** params); +void GLAPIENTRY gl_dispatch_stub_872(GLenum target, GLsizei length, GLvoid * pointer); +void GLAPIENTRY gl_dispatch_stub_879(GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); +void GLAPIENTRY gl_dispatch_stub_880(GLenum target, GLuint index, GLsizei count, const GLfloat * params); +void GLAPIENTRY gl_dispatch_stub_881(GLenum target, GLuint index, GLsizei count, const GLfloat * params); +void GLAPIENTRY gl_dispatch_stub_882(GLuint id, GLenum pname, GLint64EXT * params); +void GLAPIENTRY gl_dispatch_stub_883(GLuint id, GLenum pname, GLuint64EXT * params); +#endif /* defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) */ + +static const glprocs_table_t static_functions[] = { + NAME_FUNC_OFFSET( 0, glNewList, glNewList, NULL, 0), + NAME_FUNC_OFFSET( 10, glEndList, glEndList, NULL, 1), + NAME_FUNC_OFFSET( 20, glCallList, glCallList, NULL, 2), + NAME_FUNC_OFFSET( 31, glCallLists, glCallLists, NULL, 3), + NAME_FUNC_OFFSET( 43, glDeleteLists, glDeleteLists, NULL, 4), + NAME_FUNC_OFFSET( 57, glGenLists, glGenLists, NULL, 5), + NAME_FUNC_OFFSET( 68, glListBase, glListBase, NULL, 6), + NAME_FUNC_OFFSET( 79, glBegin, glBegin, NULL, 7), + NAME_FUNC_OFFSET( 87, glBitmap, glBitmap, NULL, 8), + NAME_FUNC_OFFSET( 96, glColor3b, glColor3b, NULL, 9), + NAME_FUNC_OFFSET( 106, glColor3bv, glColor3bv, NULL, 10), + NAME_FUNC_OFFSET( 117, glColor3d, glColor3d, NULL, 11), + NAME_FUNC_OFFSET( 127, glColor3dv, glColor3dv, NULL, 12), + NAME_FUNC_OFFSET( 138, glColor3f, glColor3f, NULL, 13), + NAME_FUNC_OFFSET( 148, glColor3fv, glColor3fv, NULL, 14), + NAME_FUNC_OFFSET( 159, glColor3i, glColor3i, NULL, 15), + NAME_FUNC_OFFSET( 169, glColor3iv, glColor3iv, NULL, 16), + NAME_FUNC_OFFSET( 180, glColor3s, glColor3s, NULL, 17), + NAME_FUNC_OFFSET( 190, glColor3sv, glColor3sv, NULL, 18), + NAME_FUNC_OFFSET( 201, glColor3ub, glColor3ub, NULL, 19), + NAME_FUNC_OFFSET( 212, glColor3ubv, glColor3ubv, NULL, 20), + NAME_FUNC_OFFSET( 224, glColor3ui, glColor3ui, NULL, 21), + NAME_FUNC_OFFSET( 235, glColor3uiv, glColor3uiv, NULL, 22), + NAME_FUNC_OFFSET( 247, glColor3us, glColor3us, NULL, 23), + NAME_FUNC_OFFSET( 258, glColor3usv, glColor3usv, NULL, 24), + NAME_FUNC_OFFSET( 270, glColor4b, glColor4b, NULL, 25), + NAME_FUNC_OFFSET( 280, glColor4bv, glColor4bv, NULL, 26), + NAME_FUNC_OFFSET( 291, glColor4d, glColor4d, NULL, 27), + NAME_FUNC_OFFSET( 301, glColor4dv, glColor4dv, NULL, 28), + NAME_FUNC_OFFSET( 312, glColor4f, glColor4f, NULL, 29), + NAME_FUNC_OFFSET( 322, glColor4fv, glColor4fv, NULL, 30), + NAME_FUNC_OFFSET( 333, glColor4i, glColor4i, NULL, 31), + NAME_FUNC_OFFSET( 343, glColor4iv, glColor4iv, NULL, 32), + NAME_FUNC_OFFSET( 354, glColor4s, glColor4s, NULL, 33), + NAME_FUNC_OFFSET( 364, glColor4sv, glColor4sv, NULL, 34), + NAME_FUNC_OFFSET( 375, glColor4ub, glColor4ub, NULL, 35), + NAME_FUNC_OFFSET( 386, glColor4ubv, glColor4ubv, NULL, 36), + NAME_FUNC_OFFSET( 398, glColor4ui, glColor4ui, NULL, 37), + NAME_FUNC_OFFSET( 409, glColor4uiv, glColor4uiv, NULL, 38), + NAME_FUNC_OFFSET( 421, glColor4us, glColor4us, NULL, 39), + NAME_FUNC_OFFSET( 432, glColor4usv, glColor4usv, NULL, 40), + NAME_FUNC_OFFSET( 444, glEdgeFlag, glEdgeFlag, NULL, 41), + NAME_FUNC_OFFSET( 455, glEdgeFlagv, glEdgeFlagv, NULL, 42), + NAME_FUNC_OFFSET( 467, glEnd, glEnd, NULL, 43), + NAME_FUNC_OFFSET( 473, glIndexd, glIndexd, NULL, 44), + NAME_FUNC_OFFSET( 482, glIndexdv, glIndexdv, NULL, 45), + NAME_FUNC_OFFSET( 492, glIndexf, glIndexf, NULL, 46), + NAME_FUNC_OFFSET( 501, glIndexfv, glIndexfv, NULL, 47), + NAME_FUNC_OFFSET( 511, glIndexi, glIndexi, NULL, 48), + NAME_FUNC_OFFSET( 520, glIndexiv, glIndexiv, NULL, 49), + NAME_FUNC_OFFSET( 530, glIndexs, glIndexs, NULL, 50), + NAME_FUNC_OFFSET( 539, glIndexsv, glIndexsv, NULL, 51), + NAME_FUNC_OFFSET( 549, glNormal3b, glNormal3b, NULL, 52), + NAME_FUNC_OFFSET( 560, glNormal3bv, glNormal3bv, NULL, 53), + NAME_FUNC_OFFSET( 572, glNormal3d, glNormal3d, NULL, 54), + NAME_FUNC_OFFSET( 583, glNormal3dv, glNormal3dv, NULL, 55), + NAME_FUNC_OFFSET( 595, glNormal3f, glNormal3f, NULL, 56), + NAME_FUNC_OFFSET( 606, glNormal3fv, glNormal3fv, NULL, 57), + NAME_FUNC_OFFSET( 618, glNormal3i, glNormal3i, NULL, 58), + NAME_FUNC_OFFSET( 629, glNormal3iv, glNormal3iv, NULL, 59), + NAME_FUNC_OFFSET( 641, glNormal3s, glNormal3s, NULL, 60), + NAME_FUNC_OFFSET( 652, glNormal3sv, glNormal3sv, NULL, 61), + NAME_FUNC_OFFSET( 664, glRasterPos2d, glRasterPos2d, NULL, 62), + NAME_FUNC_OFFSET( 678, glRasterPos2dv, glRasterPos2dv, NULL, 63), + NAME_FUNC_OFFSET( 693, glRasterPos2f, glRasterPos2f, NULL, 64), + NAME_FUNC_OFFSET( 707, glRasterPos2fv, glRasterPos2fv, NULL, 65), + NAME_FUNC_OFFSET( 722, glRasterPos2i, glRasterPos2i, NULL, 66), + NAME_FUNC_OFFSET( 736, glRasterPos2iv, glRasterPos2iv, NULL, 67), + NAME_FUNC_OFFSET( 751, glRasterPos2s, glRasterPos2s, NULL, 68), + NAME_FUNC_OFFSET( 765, glRasterPos2sv, glRasterPos2sv, NULL, 69), + NAME_FUNC_OFFSET( 780, glRasterPos3d, glRasterPos3d, NULL, 70), + NAME_FUNC_OFFSET( 794, glRasterPos3dv, glRasterPos3dv, NULL, 71), + NAME_FUNC_OFFSET( 809, glRasterPos3f, glRasterPos3f, NULL, 72), + NAME_FUNC_OFFSET( 823, glRasterPos3fv, glRasterPos3fv, NULL, 73), + NAME_FUNC_OFFSET( 838, glRasterPos3i, glRasterPos3i, NULL, 74), + NAME_FUNC_OFFSET( 852, glRasterPos3iv, glRasterPos3iv, NULL, 75), + NAME_FUNC_OFFSET( 867, glRasterPos3s, glRasterPos3s, NULL, 76), + NAME_FUNC_OFFSET( 881, glRasterPos3sv, glRasterPos3sv, NULL, 77), + NAME_FUNC_OFFSET( 896, glRasterPos4d, glRasterPos4d, NULL, 78), + NAME_FUNC_OFFSET( 910, glRasterPos4dv, glRasterPos4dv, NULL, 79), + NAME_FUNC_OFFSET( 925, glRasterPos4f, glRasterPos4f, NULL, 80), + NAME_FUNC_OFFSET( 939, glRasterPos4fv, glRasterPos4fv, NULL, 81), + NAME_FUNC_OFFSET( 954, glRasterPos4i, glRasterPos4i, NULL, 82), + NAME_FUNC_OFFSET( 968, glRasterPos4iv, glRasterPos4iv, NULL, 83), + NAME_FUNC_OFFSET( 983, glRasterPos4s, glRasterPos4s, NULL, 84), + NAME_FUNC_OFFSET( 997, glRasterPos4sv, glRasterPos4sv, NULL, 85), + NAME_FUNC_OFFSET( 1012, glRectd, glRectd, NULL, 86), + NAME_FUNC_OFFSET( 1020, glRectdv, glRectdv, NULL, 87), + NAME_FUNC_OFFSET( 1029, glRectf, glRectf, NULL, 88), + NAME_FUNC_OFFSET( 1037, glRectfv, glRectfv, NULL, 89), + NAME_FUNC_OFFSET( 1046, glRecti, glRecti, NULL, 90), + NAME_FUNC_OFFSET( 1054, glRectiv, glRectiv, NULL, 91), + NAME_FUNC_OFFSET( 1063, glRects, glRects, NULL, 92), + NAME_FUNC_OFFSET( 1071, glRectsv, glRectsv, NULL, 93), + NAME_FUNC_OFFSET( 1080, glTexCoord1d, glTexCoord1d, NULL, 94), + NAME_FUNC_OFFSET( 1093, glTexCoord1dv, glTexCoord1dv, NULL, 95), + NAME_FUNC_OFFSET( 1107, glTexCoord1f, glTexCoord1f, NULL, 96), + NAME_FUNC_OFFSET( 1120, glTexCoord1fv, glTexCoord1fv, NULL, 97), + NAME_FUNC_OFFSET( 1134, glTexCoord1i, glTexCoord1i, NULL, 98), + NAME_FUNC_OFFSET( 1147, glTexCoord1iv, glTexCoord1iv, NULL, 99), + NAME_FUNC_OFFSET( 1161, glTexCoord1s, glTexCoord1s, NULL, 100), + NAME_FUNC_OFFSET( 1174, glTexCoord1sv, glTexCoord1sv, NULL, 101), + NAME_FUNC_OFFSET( 1188, glTexCoord2d, glTexCoord2d, NULL, 102), + NAME_FUNC_OFFSET( 1201, glTexCoord2dv, glTexCoord2dv, NULL, 103), + NAME_FUNC_OFFSET( 1215, glTexCoord2f, glTexCoord2f, NULL, 104), + NAME_FUNC_OFFSET( 1228, glTexCoord2fv, glTexCoord2fv, NULL, 105), + NAME_FUNC_OFFSET( 1242, glTexCoord2i, glTexCoord2i, NULL, 106), + NAME_FUNC_OFFSET( 1255, glTexCoord2iv, glTexCoord2iv, NULL, 107), + NAME_FUNC_OFFSET( 1269, glTexCoord2s, glTexCoord2s, NULL, 108), + NAME_FUNC_OFFSET( 1282, glTexCoord2sv, glTexCoord2sv, NULL, 109), + NAME_FUNC_OFFSET( 1296, glTexCoord3d, glTexCoord3d, NULL, 110), + NAME_FUNC_OFFSET( 1309, glTexCoord3dv, glTexCoord3dv, NULL, 111), + NAME_FUNC_OFFSET( 1323, glTexCoord3f, glTexCoord3f, NULL, 112), + NAME_FUNC_OFFSET( 1336, glTexCoord3fv, glTexCoord3fv, NULL, 113), + NAME_FUNC_OFFSET( 1350, glTexCoord3i, glTexCoord3i, NULL, 114), + NAME_FUNC_OFFSET( 1363, glTexCoord3iv, glTexCoord3iv, NULL, 115), + NAME_FUNC_OFFSET( 1377, glTexCoord3s, glTexCoord3s, NULL, 116), + NAME_FUNC_OFFSET( 1390, glTexCoord3sv, glTexCoord3sv, NULL, 117), + NAME_FUNC_OFFSET( 1404, glTexCoord4d, glTexCoord4d, NULL, 118), + NAME_FUNC_OFFSET( 1417, glTexCoord4dv, glTexCoord4dv, NULL, 119), + NAME_FUNC_OFFSET( 1431, glTexCoord4f, glTexCoord4f, NULL, 120), + NAME_FUNC_OFFSET( 1444, glTexCoord4fv, glTexCoord4fv, NULL, 121), + NAME_FUNC_OFFSET( 1458, glTexCoord4i, glTexCoord4i, NULL, 122), + NAME_FUNC_OFFSET( 1471, glTexCoord4iv, glTexCoord4iv, NULL, 123), + NAME_FUNC_OFFSET( 1485, glTexCoord4s, glTexCoord4s, NULL, 124), + NAME_FUNC_OFFSET( 1498, glTexCoord4sv, glTexCoord4sv, NULL, 125), + NAME_FUNC_OFFSET( 1512, glVertex2d, glVertex2d, NULL, 126), + NAME_FUNC_OFFSET( 1523, glVertex2dv, glVertex2dv, NULL, 127), + NAME_FUNC_OFFSET( 1535, glVertex2f, glVertex2f, NULL, 128), + NAME_FUNC_OFFSET( 1546, glVertex2fv, glVertex2fv, NULL, 129), + NAME_FUNC_OFFSET( 1558, glVertex2i, glVertex2i, NULL, 130), + NAME_FUNC_OFFSET( 1569, glVertex2iv, glVertex2iv, NULL, 131), + NAME_FUNC_OFFSET( 1581, glVertex2s, glVertex2s, NULL, 132), + NAME_FUNC_OFFSET( 1592, glVertex2sv, glVertex2sv, NULL, 133), + NAME_FUNC_OFFSET( 1604, glVertex3d, glVertex3d, NULL, 134), + NAME_FUNC_OFFSET( 1615, glVertex3dv, glVertex3dv, NULL, 135), + NAME_FUNC_OFFSET( 1627, glVertex3f, glVertex3f, NULL, 136), + NAME_FUNC_OFFSET( 1638, glVertex3fv, glVertex3fv, NULL, 137), + NAME_FUNC_OFFSET( 1650, glVertex3i, glVertex3i, NULL, 138), + NAME_FUNC_OFFSET( 1661, glVertex3iv, glVertex3iv, NULL, 139), + NAME_FUNC_OFFSET( 1673, glVertex3s, glVertex3s, NULL, 140), + NAME_FUNC_OFFSET( 1684, glVertex3sv, glVertex3sv, NULL, 141), + NAME_FUNC_OFFSET( 1696, glVertex4d, glVertex4d, NULL, 142), + NAME_FUNC_OFFSET( 1707, glVertex4dv, glVertex4dv, NULL, 143), + NAME_FUNC_OFFSET( 1719, glVertex4f, glVertex4f, NULL, 144), + NAME_FUNC_OFFSET( 1730, glVertex4fv, glVertex4fv, NULL, 145), + NAME_FUNC_OFFSET( 1742, glVertex4i, glVertex4i, NULL, 146), + NAME_FUNC_OFFSET( 1753, glVertex4iv, glVertex4iv, NULL, 147), + NAME_FUNC_OFFSET( 1765, glVertex4s, glVertex4s, NULL, 148), + NAME_FUNC_OFFSET( 1776, glVertex4sv, glVertex4sv, NULL, 149), + NAME_FUNC_OFFSET( 1788, glClipPlane, glClipPlane, NULL, 150), + NAME_FUNC_OFFSET( 1800, glColorMaterial, glColorMaterial, NULL, 151), + NAME_FUNC_OFFSET( 1816, glCullFace, glCullFace, NULL, 152), + NAME_FUNC_OFFSET( 1827, glFogf, glFogf, NULL, 153), + NAME_FUNC_OFFSET( 1834, glFogfv, glFogfv, NULL, 154), + NAME_FUNC_OFFSET( 1842, glFogi, glFogi, NULL, 155), + NAME_FUNC_OFFSET( 1849, glFogiv, glFogiv, NULL, 156), + NAME_FUNC_OFFSET( 1857, glFrontFace, glFrontFace, NULL, 157), + NAME_FUNC_OFFSET( 1869, glHint, glHint, NULL, 158), + NAME_FUNC_OFFSET( 1876, glLightf, glLightf, NULL, 159), + NAME_FUNC_OFFSET( 1885, glLightfv, glLightfv, NULL, 160), + NAME_FUNC_OFFSET( 1895, glLighti, glLighti, NULL, 161), + NAME_FUNC_OFFSET( 1904, glLightiv, glLightiv, NULL, 162), + NAME_FUNC_OFFSET( 1914, glLightModelf, glLightModelf, NULL, 163), + NAME_FUNC_OFFSET( 1928, glLightModelfv, glLightModelfv, NULL, 164), + NAME_FUNC_OFFSET( 1943, glLightModeli, glLightModeli, NULL, 165), + NAME_FUNC_OFFSET( 1957, glLightModeliv, glLightModeliv, NULL, 166), + NAME_FUNC_OFFSET( 1972, glLineStipple, glLineStipple, NULL, 167), + NAME_FUNC_OFFSET( 1986, glLineWidth, glLineWidth, NULL, 168), + NAME_FUNC_OFFSET( 1998, glMaterialf, glMaterialf, NULL, 169), + NAME_FUNC_OFFSET( 2010, glMaterialfv, glMaterialfv, NULL, 170), + NAME_FUNC_OFFSET( 2023, glMateriali, glMateriali, NULL, 171), + NAME_FUNC_OFFSET( 2035, glMaterialiv, glMaterialiv, NULL, 172), + NAME_FUNC_OFFSET( 2048, glPointSize, glPointSize, NULL, 173), + NAME_FUNC_OFFSET( 2060, glPolygonMode, glPolygonMode, NULL, 174), + NAME_FUNC_OFFSET( 2074, glPolygonStipple, glPolygonStipple, NULL, 175), + NAME_FUNC_OFFSET( 2091, glScissor, glScissor, NULL, 176), + NAME_FUNC_OFFSET( 2101, glShadeModel, glShadeModel, NULL, 177), + NAME_FUNC_OFFSET( 2114, glTexParameterf, glTexParameterf, NULL, 178), + NAME_FUNC_OFFSET( 2130, glTexParameterfv, glTexParameterfv, NULL, 179), + NAME_FUNC_OFFSET( 2147, glTexParameteri, glTexParameteri, NULL, 180), + NAME_FUNC_OFFSET( 2163, glTexParameteriv, glTexParameteriv, NULL, 181), + NAME_FUNC_OFFSET( 2180, glTexImage1D, glTexImage1D, NULL, 182), + NAME_FUNC_OFFSET( 2193, glTexImage2D, glTexImage2D, NULL, 183), + NAME_FUNC_OFFSET( 2206, glTexEnvf, glTexEnvf, NULL, 184), + NAME_FUNC_OFFSET( 2216, glTexEnvfv, glTexEnvfv, NULL, 185), + NAME_FUNC_OFFSET( 2227, glTexEnvi, glTexEnvi, NULL, 186), + NAME_FUNC_OFFSET( 2237, glTexEnviv, glTexEnviv, NULL, 187), + NAME_FUNC_OFFSET( 2248, glTexGend, glTexGend, NULL, 188), + NAME_FUNC_OFFSET( 2258, glTexGendv, glTexGendv, NULL, 189), + NAME_FUNC_OFFSET( 2269, glTexGenf, glTexGenf, NULL, 190), + NAME_FUNC_OFFSET( 2279, glTexGenfv, glTexGenfv, NULL, 191), + NAME_FUNC_OFFSET( 2290, glTexGeni, glTexGeni, NULL, 192), + NAME_FUNC_OFFSET( 2300, glTexGeniv, glTexGeniv, NULL, 193), + NAME_FUNC_OFFSET( 2311, glFeedbackBuffer, glFeedbackBuffer, NULL, 194), + NAME_FUNC_OFFSET( 2328, glSelectBuffer, glSelectBuffer, NULL, 195), + NAME_FUNC_OFFSET( 2343, glRenderMode, glRenderMode, NULL, 196), + NAME_FUNC_OFFSET( 2356, glInitNames, glInitNames, NULL, 197), + NAME_FUNC_OFFSET( 2368, glLoadName, glLoadName, NULL, 198), + NAME_FUNC_OFFSET( 2379, glPassThrough, glPassThrough, NULL, 199), + NAME_FUNC_OFFSET( 2393, glPopName, glPopName, NULL, 200), + NAME_FUNC_OFFSET( 2403, glPushName, glPushName, NULL, 201), + NAME_FUNC_OFFSET( 2414, glDrawBuffer, glDrawBuffer, NULL, 202), + NAME_FUNC_OFFSET( 2427, glClear, glClear, NULL, 203), + NAME_FUNC_OFFSET( 2435, glClearAccum, glClearAccum, NULL, 204), + NAME_FUNC_OFFSET( 2448, glClearIndex, glClearIndex, NULL, 205), + NAME_FUNC_OFFSET( 2461, glClearColor, glClearColor, NULL, 206), + NAME_FUNC_OFFSET( 2474, glClearStencil, glClearStencil, NULL, 207), + NAME_FUNC_OFFSET( 2489, glClearDepth, glClearDepth, NULL, 208), + NAME_FUNC_OFFSET( 2502, glStencilMask, glStencilMask, NULL, 209), + NAME_FUNC_OFFSET( 2516, glColorMask, glColorMask, NULL, 210), + NAME_FUNC_OFFSET( 2528, glDepthMask, glDepthMask, NULL, 211), + NAME_FUNC_OFFSET( 2540, glIndexMask, glIndexMask, NULL, 212), + NAME_FUNC_OFFSET( 2552, glAccum, glAccum, NULL, 213), + NAME_FUNC_OFFSET( 2560, glDisable, glDisable, NULL, 214), + NAME_FUNC_OFFSET( 2570, glEnable, glEnable, NULL, 215), + NAME_FUNC_OFFSET( 2579, glFinish, glFinish, NULL, 216), + NAME_FUNC_OFFSET( 2588, glFlush, glFlush, NULL, 217), + NAME_FUNC_OFFSET( 2596, glPopAttrib, glPopAttrib, NULL, 218), + NAME_FUNC_OFFSET( 2608, glPushAttrib, glPushAttrib, NULL, 219), + NAME_FUNC_OFFSET( 2621, glMap1d, glMap1d, NULL, 220), + NAME_FUNC_OFFSET( 2629, glMap1f, glMap1f, NULL, 221), + NAME_FUNC_OFFSET( 2637, glMap2d, glMap2d, NULL, 222), + NAME_FUNC_OFFSET( 2645, glMap2f, glMap2f, NULL, 223), + NAME_FUNC_OFFSET( 2653, glMapGrid1d, glMapGrid1d, NULL, 224), + NAME_FUNC_OFFSET( 2665, glMapGrid1f, glMapGrid1f, NULL, 225), + NAME_FUNC_OFFSET( 2677, glMapGrid2d, glMapGrid2d, NULL, 226), + NAME_FUNC_OFFSET( 2689, glMapGrid2f, glMapGrid2f, NULL, 227), + NAME_FUNC_OFFSET( 2701, glEvalCoord1d, glEvalCoord1d, NULL, 228), + NAME_FUNC_OFFSET( 2715, glEvalCoord1dv, glEvalCoord1dv, NULL, 229), + NAME_FUNC_OFFSET( 2730, glEvalCoord1f, glEvalCoord1f, NULL, 230), + NAME_FUNC_OFFSET( 2744, glEvalCoord1fv, glEvalCoord1fv, NULL, 231), + NAME_FUNC_OFFSET( 2759, glEvalCoord2d, glEvalCoord2d, NULL, 232), + NAME_FUNC_OFFSET( 2773, glEvalCoord2dv, glEvalCoord2dv, NULL, 233), + NAME_FUNC_OFFSET( 2788, glEvalCoord2f, glEvalCoord2f, NULL, 234), + NAME_FUNC_OFFSET( 2802, glEvalCoord2fv, glEvalCoord2fv, NULL, 235), + NAME_FUNC_OFFSET( 2817, glEvalMesh1, glEvalMesh1, NULL, 236), + NAME_FUNC_OFFSET( 2829, glEvalPoint1, glEvalPoint1, NULL, 237), + NAME_FUNC_OFFSET( 2842, glEvalMesh2, glEvalMesh2, NULL, 238), + NAME_FUNC_OFFSET( 2854, glEvalPoint2, glEvalPoint2, NULL, 239), + NAME_FUNC_OFFSET( 2867, glAlphaFunc, glAlphaFunc, NULL, 240), + NAME_FUNC_OFFSET( 2879, glBlendFunc, glBlendFunc, NULL, 241), + NAME_FUNC_OFFSET( 2891, glLogicOp, glLogicOp, NULL, 242), + NAME_FUNC_OFFSET( 2901, glStencilFunc, glStencilFunc, NULL, 243), + NAME_FUNC_OFFSET( 2915, glStencilOp, glStencilOp, NULL, 244), + NAME_FUNC_OFFSET( 2927, glDepthFunc, glDepthFunc, NULL, 245), + NAME_FUNC_OFFSET( 2939, glPixelZoom, glPixelZoom, NULL, 246), + NAME_FUNC_OFFSET( 2951, glPixelTransferf, glPixelTransferf, NULL, 247), + NAME_FUNC_OFFSET( 2968, glPixelTransferi, glPixelTransferi, NULL, 248), + NAME_FUNC_OFFSET( 2985, glPixelStoref, glPixelStoref, NULL, 249), + NAME_FUNC_OFFSET( 2999, glPixelStorei, glPixelStorei, NULL, 250), + NAME_FUNC_OFFSET( 3013, glPixelMapfv, glPixelMapfv, NULL, 251), + NAME_FUNC_OFFSET( 3026, glPixelMapuiv, glPixelMapuiv, NULL, 252), + NAME_FUNC_OFFSET( 3040, glPixelMapusv, glPixelMapusv, NULL, 253), + NAME_FUNC_OFFSET( 3054, glReadBuffer, glReadBuffer, NULL, 254), + NAME_FUNC_OFFSET( 3067, glCopyPixels, glCopyPixels, NULL, 255), + NAME_FUNC_OFFSET( 3080, glReadPixels, glReadPixels, NULL, 256), + NAME_FUNC_OFFSET( 3093, glDrawPixels, glDrawPixels, NULL, 257), + NAME_FUNC_OFFSET( 3106, glGetBooleanv, glGetBooleanv, NULL, 258), + NAME_FUNC_OFFSET( 3120, glGetClipPlane, glGetClipPlane, NULL, 259), + NAME_FUNC_OFFSET( 3135, glGetDoublev, glGetDoublev, NULL, 260), + NAME_FUNC_OFFSET( 3148, glGetError, glGetError, NULL, 261), + NAME_FUNC_OFFSET( 3159, glGetFloatv, glGetFloatv, NULL, 262), + NAME_FUNC_OFFSET( 3171, glGetIntegerv, glGetIntegerv, NULL, 263), + NAME_FUNC_OFFSET( 3185, glGetLightfv, glGetLightfv, NULL, 264), + NAME_FUNC_OFFSET( 3198, glGetLightiv, glGetLightiv, NULL, 265), + NAME_FUNC_OFFSET( 3211, glGetMapdv, glGetMapdv, NULL, 266), + NAME_FUNC_OFFSET( 3222, glGetMapfv, glGetMapfv, NULL, 267), + NAME_FUNC_OFFSET( 3233, glGetMapiv, glGetMapiv, NULL, 268), + NAME_FUNC_OFFSET( 3244, glGetMaterialfv, glGetMaterialfv, NULL, 269), + NAME_FUNC_OFFSET( 3260, glGetMaterialiv, glGetMaterialiv, NULL, 270), + NAME_FUNC_OFFSET( 3276, glGetPixelMapfv, glGetPixelMapfv, NULL, 271), + NAME_FUNC_OFFSET( 3292, glGetPixelMapuiv, glGetPixelMapuiv, NULL, 272), + NAME_FUNC_OFFSET( 3309, glGetPixelMapusv, glGetPixelMapusv, NULL, 273), + NAME_FUNC_OFFSET( 3326, glGetPolygonStipple, glGetPolygonStipple, NULL, 274), + NAME_FUNC_OFFSET( 3346, glGetString, glGetString, NULL, 275), + NAME_FUNC_OFFSET( 3358, glGetTexEnvfv, glGetTexEnvfv, NULL, 276), + NAME_FUNC_OFFSET( 3372, glGetTexEnviv, glGetTexEnviv, NULL, 277), + NAME_FUNC_OFFSET( 3386, glGetTexGendv, glGetTexGendv, NULL, 278), + NAME_FUNC_OFFSET( 3400, glGetTexGenfv, glGetTexGenfv, NULL, 279), + NAME_FUNC_OFFSET( 3414, glGetTexGeniv, glGetTexGeniv, NULL, 280), + NAME_FUNC_OFFSET( 3428, glGetTexImage, glGetTexImage, NULL, 281), + NAME_FUNC_OFFSET( 3442, glGetTexParameterfv, glGetTexParameterfv, NULL, 282), + NAME_FUNC_OFFSET( 3462, glGetTexParameteriv, glGetTexParameteriv, NULL, 283), + NAME_FUNC_OFFSET( 3482, glGetTexLevelParameterfv, glGetTexLevelParameterfv, NULL, 284), + NAME_FUNC_OFFSET( 3507, glGetTexLevelParameteriv, glGetTexLevelParameteriv, NULL, 285), + NAME_FUNC_OFFSET( 3532, glIsEnabled, glIsEnabled, NULL, 286), + NAME_FUNC_OFFSET( 3544, glIsList, glIsList, NULL, 287), + NAME_FUNC_OFFSET( 3553, glDepthRange, glDepthRange, NULL, 288), + NAME_FUNC_OFFSET( 3566, glFrustum, glFrustum, NULL, 289), + NAME_FUNC_OFFSET( 3576, glLoadIdentity, glLoadIdentity, NULL, 290), + NAME_FUNC_OFFSET( 3591, glLoadMatrixf, glLoadMatrixf, NULL, 291), + NAME_FUNC_OFFSET( 3605, glLoadMatrixd, glLoadMatrixd, NULL, 292), + NAME_FUNC_OFFSET( 3619, glMatrixMode, glMatrixMode, NULL, 293), + NAME_FUNC_OFFSET( 3632, glMultMatrixf, glMultMatrixf, NULL, 294), + NAME_FUNC_OFFSET( 3646, glMultMatrixd, glMultMatrixd, NULL, 295), + NAME_FUNC_OFFSET( 3660, glOrtho, glOrtho, NULL, 296), + NAME_FUNC_OFFSET( 3668, glPopMatrix, glPopMatrix, NULL, 297), + NAME_FUNC_OFFSET( 3680, glPushMatrix, glPushMatrix, NULL, 298), + NAME_FUNC_OFFSET( 3693, glRotated, glRotated, NULL, 299), + NAME_FUNC_OFFSET( 3703, glRotatef, glRotatef, NULL, 300), + NAME_FUNC_OFFSET( 3713, glScaled, glScaled, NULL, 301), + NAME_FUNC_OFFSET( 3722, glScalef, glScalef, NULL, 302), + NAME_FUNC_OFFSET( 3731, glTranslated, glTranslated, NULL, 303), + NAME_FUNC_OFFSET( 3744, glTranslatef, glTranslatef, NULL, 304), + NAME_FUNC_OFFSET( 3757, glViewport, glViewport, NULL, 305), + NAME_FUNC_OFFSET( 3768, glArrayElement, glArrayElement, NULL, 306), + NAME_FUNC_OFFSET( 3783, glBindTexture, glBindTexture, NULL, 307), + NAME_FUNC_OFFSET( 3797, glColorPointer, glColorPointer, NULL, 308), + NAME_FUNC_OFFSET( 3812, glDisableClientState, glDisableClientState, NULL, 309), + NAME_FUNC_OFFSET( 3833, glDrawArrays, glDrawArrays, NULL, 310), + NAME_FUNC_OFFSET( 3846, glDrawElements, glDrawElements, NULL, 311), + NAME_FUNC_OFFSET( 3861, glEdgeFlagPointer, glEdgeFlagPointer, NULL, 312), + NAME_FUNC_OFFSET( 3879, glEnableClientState, glEnableClientState, NULL, 313), + NAME_FUNC_OFFSET( 3899, glIndexPointer, glIndexPointer, NULL, 314), + NAME_FUNC_OFFSET( 3914, glIndexub, glIndexub, NULL, 315), + NAME_FUNC_OFFSET( 3924, glIndexubv, glIndexubv, NULL, 316), + NAME_FUNC_OFFSET( 3935, glInterleavedArrays, glInterleavedArrays, NULL, 317), + NAME_FUNC_OFFSET( 3955, glNormalPointer, glNormalPointer, NULL, 318), + NAME_FUNC_OFFSET( 3971, glPolygonOffset, glPolygonOffset, NULL, 319), + NAME_FUNC_OFFSET( 3987, glTexCoordPointer, glTexCoordPointer, NULL, 320), + NAME_FUNC_OFFSET( 4005, glVertexPointer, glVertexPointer, NULL, 321), + NAME_FUNC_OFFSET( 4021, glAreTexturesResident, glAreTexturesResident, NULL, 322), + NAME_FUNC_OFFSET( 4043, glCopyTexImage1D, glCopyTexImage1D, NULL, 323), + NAME_FUNC_OFFSET( 4060, glCopyTexImage2D, glCopyTexImage2D, NULL, 324), + NAME_FUNC_OFFSET( 4077, glCopyTexSubImage1D, glCopyTexSubImage1D, NULL, 325), + NAME_FUNC_OFFSET( 4097, glCopyTexSubImage2D, glCopyTexSubImage2D, NULL, 326), + NAME_FUNC_OFFSET( 4117, glDeleteTextures, glDeleteTextures, NULL, 327), + NAME_FUNC_OFFSET( 4134, glGenTextures, glGenTextures, NULL, 328), + NAME_FUNC_OFFSET( 4148, glGetPointerv, glGetPointerv, NULL, 329), + NAME_FUNC_OFFSET( 4162, glIsTexture, glIsTexture, NULL, 330), + NAME_FUNC_OFFSET( 4174, glPrioritizeTextures, glPrioritizeTextures, NULL, 331), + NAME_FUNC_OFFSET( 4195, glTexSubImage1D, glTexSubImage1D, NULL, 332), + NAME_FUNC_OFFSET( 4211, glTexSubImage2D, glTexSubImage2D, NULL, 333), + NAME_FUNC_OFFSET( 4227, glPopClientAttrib, glPopClientAttrib, NULL, 334), + NAME_FUNC_OFFSET( 4245, glPushClientAttrib, glPushClientAttrib, NULL, 335), + NAME_FUNC_OFFSET( 4264, glBlendColor, glBlendColor, NULL, 336), + NAME_FUNC_OFFSET( 4277, glBlendEquation, glBlendEquation, NULL, 337), + NAME_FUNC_OFFSET( 4293, glDrawRangeElements, glDrawRangeElements, NULL, 338), + NAME_FUNC_OFFSET( 4313, glColorTable, glColorTable, NULL, 339), + NAME_FUNC_OFFSET( 4326, glColorTableParameterfv, glColorTableParameterfv, NULL, 340), + NAME_FUNC_OFFSET( 4350, glColorTableParameteriv, glColorTableParameteriv, NULL, 341), + NAME_FUNC_OFFSET( 4374, glCopyColorTable, glCopyColorTable, NULL, 342), + NAME_FUNC_OFFSET( 4391, glGetColorTable, glGetColorTable, NULL, 343), + NAME_FUNC_OFFSET( 4407, glGetColorTableParameterfv, glGetColorTableParameterfv, NULL, 344), + NAME_FUNC_OFFSET( 4434, glGetColorTableParameteriv, glGetColorTableParameteriv, NULL, 345), + NAME_FUNC_OFFSET( 4461, glColorSubTable, glColorSubTable, NULL, 346), + NAME_FUNC_OFFSET( 4477, glCopyColorSubTable, glCopyColorSubTable, NULL, 347), + NAME_FUNC_OFFSET( 4497, glConvolutionFilter1D, glConvolutionFilter1D, NULL, 348), + NAME_FUNC_OFFSET( 4519, glConvolutionFilter2D, glConvolutionFilter2D, NULL, 349), + NAME_FUNC_OFFSET( 4541, glConvolutionParameterf, glConvolutionParameterf, NULL, 350), + NAME_FUNC_OFFSET( 4565, glConvolutionParameterfv, glConvolutionParameterfv, NULL, 351), + NAME_FUNC_OFFSET( 4590, glConvolutionParameteri, glConvolutionParameteri, NULL, 352), + NAME_FUNC_OFFSET( 4614, glConvolutionParameteriv, glConvolutionParameteriv, NULL, 353), + NAME_FUNC_OFFSET( 4639, glCopyConvolutionFilter1D, glCopyConvolutionFilter1D, NULL, 354), + NAME_FUNC_OFFSET( 4665, glCopyConvolutionFilter2D, glCopyConvolutionFilter2D, NULL, 355), + NAME_FUNC_OFFSET( 4691, glGetConvolutionFilter, glGetConvolutionFilter, NULL, 356), + NAME_FUNC_OFFSET( 4714, glGetConvolutionParameterfv, glGetConvolutionParameterfv, NULL, 357), + NAME_FUNC_OFFSET( 4742, glGetConvolutionParameteriv, glGetConvolutionParameteriv, NULL, 358), + NAME_FUNC_OFFSET( 4770, glGetSeparableFilter, glGetSeparableFilter, NULL, 359), + NAME_FUNC_OFFSET( 4791, glSeparableFilter2D, glSeparableFilter2D, NULL, 360), + NAME_FUNC_OFFSET( 4811, glGetHistogram, glGetHistogram, NULL, 361), + NAME_FUNC_OFFSET( 4826, glGetHistogramParameterfv, glGetHistogramParameterfv, NULL, 362), + NAME_FUNC_OFFSET( 4852, glGetHistogramParameteriv, glGetHistogramParameteriv, NULL, 363), + NAME_FUNC_OFFSET( 4878, glGetMinmax, glGetMinmax, NULL, 364), + NAME_FUNC_OFFSET( 4890, glGetMinmaxParameterfv, glGetMinmaxParameterfv, NULL, 365), + NAME_FUNC_OFFSET( 4913, glGetMinmaxParameteriv, glGetMinmaxParameteriv, NULL, 366), + NAME_FUNC_OFFSET( 4936, glHistogram, glHistogram, NULL, 367), + NAME_FUNC_OFFSET( 4948, glMinmax, glMinmax, NULL, 368), + NAME_FUNC_OFFSET( 4957, glResetHistogram, glResetHistogram, NULL, 369), + NAME_FUNC_OFFSET( 4974, glResetMinmax, glResetMinmax, NULL, 370), + NAME_FUNC_OFFSET( 4988, glTexImage3D, glTexImage3D, NULL, 371), + NAME_FUNC_OFFSET( 5001, glTexSubImage3D, glTexSubImage3D, NULL, 372), + NAME_FUNC_OFFSET( 5017, glCopyTexSubImage3D, glCopyTexSubImage3D, NULL, 373), + NAME_FUNC_OFFSET( 5037, glActiveTextureARB, glActiveTextureARB, NULL, 374), + NAME_FUNC_OFFSET( 5056, glClientActiveTextureARB, glClientActiveTextureARB, NULL, 375), + NAME_FUNC_OFFSET( 5081, glMultiTexCoord1dARB, glMultiTexCoord1dARB, NULL, 376), + NAME_FUNC_OFFSET( 5102, glMultiTexCoord1dvARB, glMultiTexCoord1dvARB, NULL, 377), + NAME_FUNC_OFFSET( 5124, glMultiTexCoord1fARB, glMultiTexCoord1fARB, NULL, 378), + NAME_FUNC_OFFSET( 5145, glMultiTexCoord1fvARB, glMultiTexCoord1fvARB, NULL, 379), + NAME_FUNC_OFFSET( 5167, glMultiTexCoord1iARB, glMultiTexCoord1iARB, NULL, 380), + NAME_FUNC_OFFSET( 5188, glMultiTexCoord1ivARB, glMultiTexCoord1ivARB, NULL, 381), + NAME_FUNC_OFFSET( 5210, glMultiTexCoord1sARB, glMultiTexCoord1sARB, NULL, 382), + NAME_FUNC_OFFSET( 5231, glMultiTexCoord1svARB, glMultiTexCoord1svARB, NULL, 383), + NAME_FUNC_OFFSET( 5253, glMultiTexCoord2dARB, glMultiTexCoord2dARB, NULL, 384), + NAME_FUNC_OFFSET( 5274, glMultiTexCoord2dvARB, glMultiTexCoord2dvARB, NULL, 385), + NAME_FUNC_OFFSET( 5296, glMultiTexCoord2fARB, glMultiTexCoord2fARB, NULL, 386), + NAME_FUNC_OFFSET( 5317, glMultiTexCoord2fvARB, glMultiTexCoord2fvARB, NULL, 387), + NAME_FUNC_OFFSET( 5339, glMultiTexCoord2iARB, glMultiTexCoord2iARB, NULL, 388), + NAME_FUNC_OFFSET( 5360, glMultiTexCoord2ivARB, glMultiTexCoord2ivARB, NULL, 389), + NAME_FUNC_OFFSET( 5382, glMultiTexCoord2sARB, glMultiTexCoord2sARB, NULL, 390), + NAME_FUNC_OFFSET( 5403, glMultiTexCoord2svARB, glMultiTexCoord2svARB, NULL, 391), + NAME_FUNC_OFFSET( 5425, glMultiTexCoord3dARB, glMultiTexCoord3dARB, NULL, 392), + NAME_FUNC_OFFSET( 5446, glMultiTexCoord3dvARB, glMultiTexCoord3dvARB, NULL, 393), + NAME_FUNC_OFFSET( 5468, glMultiTexCoord3fARB, glMultiTexCoord3fARB, NULL, 394), + NAME_FUNC_OFFSET( 5489, glMultiTexCoord3fvARB, glMultiTexCoord3fvARB, NULL, 395), + NAME_FUNC_OFFSET( 5511, glMultiTexCoord3iARB, glMultiTexCoord3iARB, NULL, 396), + NAME_FUNC_OFFSET( 5532, glMultiTexCoord3ivARB, glMultiTexCoord3ivARB, NULL, 397), + NAME_FUNC_OFFSET( 5554, glMultiTexCoord3sARB, glMultiTexCoord3sARB, NULL, 398), + NAME_FUNC_OFFSET( 5575, glMultiTexCoord3svARB, glMultiTexCoord3svARB, NULL, 399), + NAME_FUNC_OFFSET( 5597, glMultiTexCoord4dARB, glMultiTexCoord4dARB, NULL, 400), + NAME_FUNC_OFFSET( 5618, glMultiTexCoord4dvARB, glMultiTexCoord4dvARB, NULL, 401), + NAME_FUNC_OFFSET( 5640, glMultiTexCoord4fARB, glMultiTexCoord4fARB, NULL, 402), + NAME_FUNC_OFFSET( 5661, glMultiTexCoord4fvARB, glMultiTexCoord4fvARB, NULL, 403), + NAME_FUNC_OFFSET( 5683, glMultiTexCoord4iARB, glMultiTexCoord4iARB, NULL, 404), + NAME_FUNC_OFFSET( 5704, glMultiTexCoord4ivARB, glMultiTexCoord4ivARB, NULL, 405), + NAME_FUNC_OFFSET( 5726, glMultiTexCoord4sARB, glMultiTexCoord4sARB, NULL, 406), + NAME_FUNC_OFFSET( 5747, glMultiTexCoord4svARB, glMultiTexCoord4svARB, NULL, 407), + NAME_FUNC_OFFSET( 5769, glAttachShader, glAttachShader, NULL, 408), + NAME_FUNC_OFFSET( 5784, glCreateProgram, glCreateProgram, NULL, 409), + NAME_FUNC_OFFSET( 5800, glCreateShader, glCreateShader, NULL, 410), + NAME_FUNC_OFFSET( 5815, glDeleteProgram, glDeleteProgram, NULL, 411), + NAME_FUNC_OFFSET( 5831, glDeleteShader, glDeleteShader, NULL, 412), + NAME_FUNC_OFFSET( 5846, glDetachShader, glDetachShader, NULL, 413), + NAME_FUNC_OFFSET( 5861, glGetAttachedShaders, glGetAttachedShaders, NULL, 414), + NAME_FUNC_OFFSET( 5882, glGetProgramInfoLog, glGetProgramInfoLog, NULL, 415), + NAME_FUNC_OFFSET( 5902, glGetProgramiv, glGetProgramiv, NULL, 416), + NAME_FUNC_OFFSET( 5917, glGetShaderInfoLog, glGetShaderInfoLog, NULL, 417), + NAME_FUNC_OFFSET( 5936, glGetShaderiv, glGetShaderiv, NULL, 418), + NAME_FUNC_OFFSET( 5950, glIsProgram, glIsProgram, NULL, 419), + NAME_FUNC_OFFSET( 5962, glIsShader, glIsShader, NULL, 420), + NAME_FUNC_OFFSET( 5973, glStencilFuncSeparate, glStencilFuncSeparate, NULL, 421), + NAME_FUNC_OFFSET( 5995, glStencilMaskSeparate, glStencilMaskSeparate, NULL, 422), + NAME_FUNC_OFFSET( 6017, glStencilOpSeparate, glStencilOpSeparate, NULL, 423), + NAME_FUNC_OFFSET( 6037, glUniformMatrix2x3fv, glUniformMatrix2x3fv, NULL, 424), + NAME_FUNC_OFFSET( 6058, glUniformMatrix2x4fv, glUniformMatrix2x4fv, NULL, 425), + NAME_FUNC_OFFSET( 6079, glUniformMatrix3x2fv, glUniformMatrix3x2fv, NULL, 426), + NAME_FUNC_OFFSET( 6100, glUniformMatrix3x4fv, glUniformMatrix3x4fv, NULL, 427), + NAME_FUNC_OFFSET( 6121, glUniformMatrix4x2fv, glUniformMatrix4x2fv, NULL, 428), + NAME_FUNC_OFFSET( 6142, glUniformMatrix4x3fv, glUniformMatrix4x3fv, NULL, 429), + NAME_FUNC_OFFSET( 6163, glClampColor, glClampColor, NULL, 430), + NAME_FUNC_OFFSET( 6176, glClearBufferfi, glClearBufferfi, NULL, 431), + NAME_FUNC_OFFSET( 6192, glClearBufferfv, glClearBufferfv, NULL, 432), + NAME_FUNC_OFFSET( 6208, glClearBufferiv, glClearBufferiv, NULL, 433), + NAME_FUNC_OFFSET( 6224, glClearBufferuiv, glClearBufferuiv, NULL, 434), + NAME_FUNC_OFFSET( 6241, glGetStringi, glGetStringi, NULL, 435), + NAME_FUNC_OFFSET( 6254, glTexBuffer, glTexBuffer, NULL, 436), + NAME_FUNC_OFFSET( 6266, glFramebufferTexture, glFramebufferTexture, NULL, 437), + NAME_FUNC_OFFSET( 6287, glGetBufferParameteri64v, glGetBufferParameteri64v, NULL, 438), + NAME_FUNC_OFFSET( 6312, glGetInteger64i_v, glGetInteger64i_v, NULL, 439), + NAME_FUNC_OFFSET( 6330, glVertexAttribDivisor, glVertexAttribDivisor, NULL, 440), + NAME_FUNC_OFFSET( 6352, glLoadTransposeMatrixdARB, glLoadTransposeMatrixdARB, NULL, 441), + NAME_FUNC_OFFSET( 6378, glLoadTransposeMatrixfARB, glLoadTransposeMatrixfARB, NULL, 442), + NAME_FUNC_OFFSET( 6404, glMultTransposeMatrixdARB, glMultTransposeMatrixdARB, NULL, 443), + NAME_FUNC_OFFSET( 6430, glMultTransposeMatrixfARB, glMultTransposeMatrixfARB, NULL, 444), + NAME_FUNC_OFFSET( 6456, glSampleCoverageARB, glSampleCoverageARB, NULL, 445), + NAME_FUNC_OFFSET( 6476, glCompressedTexImage1DARB, glCompressedTexImage1DARB, NULL, 446), + NAME_FUNC_OFFSET( 6502, glCompressedTexImage2DARB, glCompressedTexImage2DARB, NULL, 447), + NAME_FUNC_OFFSET( 6528, glCompressedTexImage3DARB, glCompressedTexImage3DARB, NULL, 448), + NAME_FUNC_OFFSET( 6554, glCompressedTexSubImage1DARB, glCompressedTexSubImage1DARB, NULL, 449), + NAME_FUNC_OFFSET( 6583, glCompressedTexSubImage2DARB, glCompressedTexSubImage2DARB, NULL, 450), + NAME_FUNC_OFFSET( 6612, glCompressedTexSubImage3DARB, glCompressedTexSubImage3DARB, NULL, 451), + NAME_FUNC_OFFSET( 6641, glGetCompressedTexImageARB, glGetCompressedTexImageARB, NULL, 452), + NAME_FUNC_OFFSET( 6668, glDisableVertexAttribArrayARB, glDisableVertexAttribArrayARB, NULL, 453), + NAME_FUNC_OFFSET( 6698, glEnableVertexAttribArrayARB, glEnableVertexAttribArrayARB, NULL, 454), + NAME_FUNC_OFFSET( 6727, glGetProgramEnvParameterdvARB, glGetProgramEnvParameterdvARB, NULL, 455), + NAME_FUNC_OFFSET( 6757, glGetProgramEnvParameterfvARB, glGetProgramEnvParameterfvARB, NULL, 456), + NAME_FUNC_OFFSET( 6787, glGetProgramLocalParameterdvARB, glGetProgramLocalParameterdvARB, NULL, 457), + NAME_FUNC_OFFSET( 6819, glGetProgramLocalParameterfvARB, glGetProgramLocalParameterfvARB, NULL, 458), + NAME_FUNC_OFFSET( 6851, glGetProgramStringARB, glGetProgramStringARB, NULL, 459), + NAME_FUNC_OFFSET( 6873, glGetProgramivARB, glGetProgramivARB, NULL, 460), + NAME_FUNC_OFFSET( 6891, glGetVertexAttribdvARB, glGetVertexAttribdvARB, NULL, 461), + NAME_FUNC_OFFSET( 6914, glGetVertexAttribfvARB, glGetVertexAttribfvARB, NULL, 462), + NAME_FUNC_OFFSET( 6937, glGetVertexAttribivARB, glGetVertexAttribivARB, NULL, 463), + NAME_FUNC_OFFSET( 6960, glProgramEnvParameter4dARB, glProgramEnvParameter4dARB, NULL, 464), + NAME_FUNC_OFFSET( 6987, glProgramEnvParameter4dvARB, glProgramEnvParameter4dvARB, NULL, 465), + NAME_FUNC_OFFSET( 7015, glProgramEnvParameter4fARB, glProgramEnvParameter4fARB, NULL, 466), + NAME_FUNC_OFFSET( 7042, glProgramEnvParameter4fvARB, glProgramEnvParameter4fvARB, NULL, 467), + NAME_FUNC_OFFSET( 7070, glProgramLocalParameter4dARB, glProgramLocalParameter4dARB, NULL, 468), + NAME_FUNC_OFFSET( 7099, glProgramLocalParameter4dvARB, glProgramLocalParameter4dvARB, NULL, 469), + NAME_FUNC_OFFSET( 7129, glProgramLocalParameter4fARB, glProgramLocalParameter4fARB, NULL, 470), + NAME_FUNC_OFFSET( 7158, glProgramLocalParameter4fvARB, glProgramLocalParameter4fvARB, NULL, 471), + NAME_FUNC_OFFSET( 7188, glProgramStringARB, glProgramStringARB, NULL, 472), + NAME_FUNC_OFFSET( 7207, glVertexAttrib1dARB, glVertexAttrib1dARB, NULL, 473), + NAME_FUNC_OFFSET( 7227, glVertexAttrib1dvARB, glVertexAttrib1dvARB, NULL, 474), + NAME_FUNC_OFFSET( 7248, glVertexAttrib1fARB, glVertexAttrib1fARB, NULL, 475), + NAME_FUNC_OFFSET( 7268, glVertexAttrib1fvARB, glVertexAttrib1fvARB, NULL, 476), + NAME_FUNC_OFFSET( 7289, glVertexAttrib1sARB, glVertexAttrib1sARB, NULL, 477), + NAME_FUNC_OFFSET( 7309, glVertexAttrib1svARB, glVertexAttrib1svARB, NULL, 478), + NAME_FUNC_OFFSET( 7330, glVertexAttrib2dARB, glVertexAttrib2dARB, NULL, 479), + NAME_FUNC_OFFSET( 7350, glVertexAttrib2dvARB, glVertexAttrib2dvARB, NULL, 480), + NAME_FUNC_OFFSET( 7371, glVertexAttrib2fARB, glVertexAttrib2fARB, NULL, 481), + NAME_FUNC_OFFSET( 7391, glVertexAttrib2fvARB, glVertexAttrib2fvARB, NULL, 482), + NAME_FUNC_OFFSET( 7412, glVertexAttrib2sARB, glVertexAttrib2sARB, NULL, 483), + NAME_FUNC_OFFSET( 7432, glVertexAttrib2svARB, glVertexAttrib2svARB, NULL, 484), + NAME_FUNC_OFFSET( 7453, glVertexAttrib3dARB, glVertexAttrib3dARB, NULL, 485), + NAME_FUNC_OFFSET( 7473, glVertexAttrib3dvARB, glVertexAttrib3dvARB, NULL, 486), + NAME_FUNC_OFFSET( 7494, glVertexAttrib3fARB, glVertexAttrib3fARB, NULL, 487), + NAME_FUNC_OFFSET( 7514, glVertexAttrib3fvARB, glVertexAttrib3fvARB, NULL, 488), + NAME_FUNC_OFFSET( 7535, glVertexAttrib3sARB, glVertexAttrib3sARB, NULL, 489), + NAME_FUNC_OFFSET( 7555, glVertexAttrib3svARB, glVertexAttrib3svARB, NULL, 490), + NAME_FUNC_OFFSET( 7576, glVertexAttrib4NbvARB, glVertexAttrib4NbvARB, NULL, 491), + NAME_FUNC_OFFSET( 7598, glVertexAttrib4NivARB, glVertexAttrib4NivARB, NULL, 492), + NAME_FUNC_OFFSET( 7620, glVertexAttrib4NsvARB, glVertexAttrib4NsvARB, NULL, 493), + NAME_FUNC_OFFSET( 7642, glVertexAttrib4NubARB, glVertexAttrib4NubARB, NULL, 494), + NAME_FUNC_OFFSET( 7664, glVertexAttrib4NubvARB, glVertexAttrib4NubvARB, NULL, 495), + NAME_FUNC_OFFSET( 7687, glVertexAttrib4NuivARB, glVertexAttrib4NuivARB, NULL, 496), + NAME_FUNC_OFFSET( 7710, glVertexAttrib4NusvARB, glVertexAttrib4NusvARB, NULL, 497), + NAME_FUNC_OFFSET( 7733, glVertexAttrib4bvARB, glVertexAttrib4bvARB, NULL, 498), + NAME_FUNC_OFFSET( 7754, glVertexAttrib4dARB, glVertexAttrib4dARB, NULL, 499), + NAME_FUNC_OFFSET( 7774, glVertexAttrib4dvARB, glVertexAttrib4dvARB, NULL, 500), + NAME_FUNC_OFFSET( 7795, glVertexAttrib4fARB, glVertexAttrib4fARB, NULL, 501), + NAME_FUNC_OFFSET( 7815, glVertexAttrib4fvARB, glVertexAttrib4fvARB, NULL, 502), + NAME_FUNC_OFFSET( 7836, glVertexAttrib4ivARB, glVertexAttrib4ivARB, NULL, 503), + NAME_FUNC_OFFSET( 7857, glVertexAttrib4sARB, glVertexAttrib4sARB, NULL, 504), + NAME_FUNC_OFFSET( 7877, glVertexAttrib4svARB, glVertexAttrib4svARB, NULL, 505), + NAME_FUNC_OFFSET( 7898, glVertexAttrib4ubvARB, glVertexAttrib4ubvARB, NULL, 506), + NAME_FUNC_OFFSET( 7920, glVertexAttrib4uivARB, glVertexAttrib4uivARB, NULL, 507), + NAME_FUNC_OFFSET( 7942, glVertexAttrib4usvARB, glVertexAttrib4usvARB, NULL, 508), + NAME_FUNC_OFFSET( 7964, glVertexAttribPointerARB, glVertexAttribPointerARB, NULL, 509), + NAME_FUNC_OFFSET( 7989, glBindBufferARB, glBindBufferARB, NULL, 510), + NAME_FUNC_OFFSET( 8005, glBufferDataARB, glBufferDataARB, NULL, 511), + NAME_FUNC_OFFSET( 8021, glBufferSubDataARB, glBufferSubDataARB, NULL, 512), + NAME_FUNC_OFFSET( 8040, glDeleteBuffersARB, glDeleteBuffersARB, NULL, 513), + NAME_FUNC_OFFSET( 8059, glGenBuffersARB, glGenBuffersARB, NULL, 514), + NAME_FUNC_OFFSET( 8075, glGetBufferParameterivARB, glGetBufferParameterivARB, NULL, 515), + NAME_FUNC_OFFSET( 8101, glGetBufferPointervARB, glGetBufferPointervARB, NULL, 516), + NAME_FUNC_OFFSET( 8124, glGetBufferSubDataARB, glGetBufferSubDataARB, NULL, 517), + NAME_FUNC_OFFSET( 8146, glIsBufferARB, glIsBufferARB, NULL, 518), + NAME_FUNC_OFFSET( 8160, glMapBufferARB, glMapBufferARB, NULL, 519), + NAME_FUNC_OFFSET( 8175, glUnmapBufferARB, glUnmapBufferARB, NULL, 520), + NAME_FUNC_OFFSET( 8192, glBeginQueryARB, glBeginQueryARB, NULL, 521), + NAME_FUNC_OFFSET( 8208, glDeleteQueriesARB, glDeleteQueriesARB, NULL, 522), + NAME_FUNC_OFFSET( 8227, glEndQueryARB, glEndQueryARB, NULL, 523), + NAME_FUNC_OFFSET( 8241, glGenQueriesARB, glGenQueriesARB, NULL, 524), + NAME_FUNC_OFFSET( 8257, glGetQueryObjectivARB, glGetQueryObjectivARB, NULL, 525), + NAME_FUNC_OFFSET( 8279, glGetQueryObjectuivARB, glGetQueryObjectuivARB, NULL, 526), + NAME_FUNC_OFFSET( 8302, glGetQueryivARB, glGetQueryivARB, NULL, 527), + NAME_FUNC_OFFSET( 8318, glIsQueryARB, glIsQueryARB, NULL, 528), + NAME_FUNC_OFFSET( 8331, glAttachObjectARB, glAttachObjectARB, NULL, 529), + NAME_FUNC_OFFSET( 8349, glCompileShaderARB, glCompileShaderARB, NULL, 530), + NAME_FUNC_OFFSET( 8368, glCreateProgramObjectARB, glCreateProgramObjectARB, NULL, 531), + NAME_FUNC_OFFSET( 8393, glCreateShaderObjectARB, glCreateShaderObjectARB, NULL, 532), + NAME_FUNC_OFFSET( 8417, glDeleteObjectARB, glDeleteObjectARB, NULL, 533), + NAME_FUNC_OFFSET( 8435, glDetachObjectARB, glDetachObjectARB, NULL, 534), + NAME_FUNC_OFFSET( 8453, glGetActiveUniformARB, glGetActiveUniformARB, NULL, 535), + NAME_FUNC_OFFSET( 8475, glGetAttachedObjectsARB, glGetAttachedObjectsARB, NULL, 536), + NAME_FUNC_OFFSET( 8499, glGetHandleARB, glGetHandleARB, NULL, 537), + NAME_FUNC_OFFSET( 8514, glGetInfoLogARB, glGetInfoLogARB, NULL, 538), + NAME_FUNC_OFFSET( 8530, glGetObjectParameterfvARB, glGetObjectParameterfvARB, NULL, 539), + NAME_FUNC_OFFSET( 8556, glGetObjectParameterivARB, glGetObjectParameterivARB, NULL, 540), + NAME_FUNC_OFFSET( 8582, glGetShaderSourceARB, glGetShaderSourceARB, NULL, 541), + NAME_FUNC_OFFSET( 8603, glGetUniformLocationARB, glGetUniformLocationARB, NULL, 542), + NAME_FUNC_OFFSET( 8627, glGetUniformfvARB, glGetUniformfvARB, NULL, 543), + NAME_FUNC_OFFSET( 8645, glGetUniformivARB, glGetUniformivARB, NULL, 544), + NAME_FUNC_OFFSET( 8663, glLinkProgramARB, glLinkProgramARB, NULL, 545), + NAME_FUNC_OFFSET( 8680, glShaderSourceARB, glShaderSourceARB, NULL, 546), + NAME_FUNC_OFFSET( 8698, glUniform1fARB, glUniform1fARB, NULL, 547), + NAME_FUNC_OFFSET( 8713, glUniform1fvARB, glUniform1fvARB, NULL, 548), + NAME_FUNC_OFFSET( 8729, glUniform1iARB, glUniform1iARB, NULL, 549), + NAME_FUNC_OFFSET( 8744, glUniform1ivARB, glUniform1ivARB, NULL, 550), + NAME_FUNC_OFFSET( 8760, glUniform2fARB, glUniform2fARB, NULL, 551), + NAME_FUNC_OFFSET( 8775, glUniform2fvARB, glUniform2fvARB, NULL, 552), + NAME_FUNC_OFFSET( 8791, glUniform2iARB, glUniform2iARB, NULL, 553), + NAME_FUNC_OFFSET( 8806, glUniform2ivARB, glUniform2ivARB, NULL, 554), + NAME_FUNC_OFFSET( 8822, glUniform3fARB, glUniform3fARB, NULL, 555), + NAME_FUNC_OFFSET( 8837, glUniform3fvARB, glUniform3fvARB, NULL, 556), + NAME_FUNC_OFFSET( 8853, glUniform3iARB, glUniform3iARB, NULL, 557), + NAME_FUNC_OFFSET( 8868, glUniform3ivARB, glUniform3ivARB, NULL, 558), + NAME_FUNC_OFFSET( 8884, glUniform4fARB, glUniform4fARB, NULL, 559), + NAME_FUNC_OFFSET( 8899, glUniform4fvARB, glUniform4fvARB, NULL, 560), + NAME_FUNC_OFFSET( 8915, glUniform4iARB, glUniform4iARB, NULL, 561), + NAME_FUNC_OFFSET( 8930, glUniform4ivARB, glUniform4ivARB, NULL, 562), + NAME_FUNC_OFFSET( 8946, glUniformMatrix2fvARB, glUniformMatrix2fvARB, NULL, 563), + NAME_FUNC_OFFSET( 8968, glUniformMatrix3fvARB, glUniformMatrix3fvARB, NULL, 564), + NAME_FUNC_OFFSET( 8990, glUniformMatrix4fvARB, glUniformMatrix4fvARB, NULL, 565), + NAME_FUNC_OFFSET( 9012, glUseProgramObjectARB, glUseProgramObjectARB, NULL, 566), + NAME_FUNC_OFFSET( 9034, glValidateProgramARB, glValidateProgramARB, NULL, 567), + NAME_FUNC_OFFSET( 9055, glBindAttribLocationARB, glBindAttribLocationARB, NULL, 568), + NAME_FUNC_OFFSET( 9079, glGetActiveAttribARB, glGetActiveAttribARB, NULL, 569), + NAME_FUNC_OFFSET( 9100, glGetAttribLocationARB, glGetAttribLocationARB, NULL, 570), + NAME_FUNC_OFFSET( 9123, glDrawBuffersARB, glDrawBuffersARB, NULL, 571), + NAME_FUNC_OFFSET( 9140, glDrawArraysInstancedARB, glDrawArraysInstancedARB, NULL, 572), + NAME_FUNC_OFFSET( 9165, glDrawElementsInstancedARB, glDrawElementsInstancedARB, NULL, 573), + NAME_FUNC_OFFSET( 9192, glRenderbufferStorageMultisample, glRenderbufferStorageMultisample, NULL, 574), + NAME_FUNC_OFFSET( 9225, glFramebufferTextureARB, glFramebufferTextureARB, NULL, 575), + NAME_FUNC_OFFSET( 9249, glFramebufferTextureFaceARB, glFramebufferTextureFaceARB, NULL, 576), + NAME_FUNC_OFFSET( 9277, glProgramParameteriARB, glProgramParameteriARB, NULL, 577), + NAME_FUNC_OFFSET( 9300, glFlushMappedBufferRange, glFlushMappedBufferRange, NULL, 578), + NAME_FUNC_OFFSET( 9325, glMapBufferRange, glMapBufferRange, NULL, 579), + NAME_FUNC_OFFSET( 9342, glBindVertexArray, glBindVertexArray, NULL, 580), + NAME_FUNC_OFFSET( 9360, glGenVertexArrays, glGenVertexArrays, NULL, 581), + NAME_FUNC_OFFSET( 9378, glCopyBufferSubData, glCopyBufferSubData, NULL, 582), + NAME_FUNC_OFFSET( 9398, glClientWaitSync, glClientWaitSync, NULL, 583), + NAME_FUNC_OFFSET( 9415, glDeleteSync, glDeleteSync, NULL, 584), + NAME_FUNC_OFFSET( 9428, glFenceSync, glFenceSync, NULL, 585), + NAME_FUNC_OFFSET( 9440, glGetInteger64v, glGetInteger64v, NULL, 586), + NAME_FUNC_OFFSET( 9456, glGetSynciv, glGetSynciv, NULL, 587), + NAME_FUNC_OFFSET( 9468, glIsSync, glIsSync, NULL, 588), + NAME_FUNC_OFFSET( 9477, glWaitSync, glWaitSync, NULL, 589), + NAME_FUNC_OFFSET( 9488, glDrawElementsBaseVertex, glDrawElementsBaseVertex, NULL, 590), + NAME_FUNC_OFFSET( 9513, glDrawRangeElementsBaseVertex, glDrawRangeElementsBaseVertex, NULL, 591), + NAME_FUNC_OFFSET( 9543, glMultiDrawElementsBaseVertex, glMultiDrawElementsBaseVertex, NULL, 592), + NAME_FUNC_OFFSET( 9573, glBindTransformFeedback, glBindTransformFeedback, NULL, 593), + NAME_FUNC_OFFSET( 9597, glDeleteTransformFeedbacks, glDeleteTransformFeedbacks, NULL, 594), + NAME_FUNC_OFFSET( 9624, glDrawTransformFeedback, glDrawTransformFeedback, NULL, 595), + NAME_FUNC_OFFSET( 9648, glGenTransformFeedbacks, glGenTransformFeedbacks, NULL, 596), + NAME_FUNC_OFFSET( 9672, glIsTransformFeedback, glIsTransformFeedback, NULL, 597), + NAME_FUNC_OFFSET( 9694, glPauseTransformFeedback, glPauseTransformFeedback, NULL, 598), + NAME_FUNC_OFFSET( 9719, glResumeTransformFeedback, glResumeTransformFeedback, NULL, 599), + NAME_FUNC_OFFSET( 9745, glClearDepthf, glClearDepthf, NULL, 600), + NAME_FUNC_OFFSET( 9759, glDepthRangef, glDepthRangef, NULL, 601), + NAME_FUNC_OFFSET( 9773, glGetShaderPrecisionFormat, glGetShaderPrecisionFormat, NULL, 602), + NAME_FUNC_OFFSET( 9800, glReleaseShaderCompiler, glReleaseShaderCompiler, NULL, 603), + NAME_FUNC_OFFSET( 9824, glShaderBinary, glShaderBinary, NULL, 604), + NAME_FUNC_OFFSET( 9839, glPolygonOffsetEXT, glPolygonOffsetEXT, NULL, 605), + NAME_FUNC_OFFSET( 9858, gl_dispatch_stub_606, gl_dispatch_stub_606, NULL, 606), + NAME_FUNC_OFFSET( 9890, gl_dispatch_stub_607, gl_dispatch_stub_607, NULL, 607), + NAME_FUNC_OFFSET( 9922, gl_dispatch_stub_608, gl_dispatch_stub_608, NULL, 608), + NAME_FUNC_OFFSET( 9950, gl_dispatch_stub_609, gl_dispatch_stub_609, NULL, 609), + NAME_FUNC_OFFSET( 9979, gl_dispatch_stub_610, gl_dispatch_stub_610, NULL, 610), + NAME_FUNC_OFFSET(10007, gl_dispatch_stub_611, gl_dispatch_stub_611, NULL, 611), + NAME_FUNC_OFFSET(10036, gl_dispatch_stub_612, gl_dispatch_stub_612, NULL, 612), + NAME_FUNC_OFFSET(10053, gl_dispatch_stub_613, gl_dispatch_stub_613, NULL, 613), + NAME_FUNC_OFFSET(10073, glColorPointerEXT, glColorPointerEXT, NULL, 614), + NAME_FUNC_OFFSET(10091, glEdgeFlagPointerEXT, glEdgeFlagPointerEXT, NULL, 615), + NAME_FUNC_OFFSET(10112, glIndexPointerEXT, glIndexPointerEXT, NULL, 616), + NAME_FUNC_OFFSET(10130, glNormalPointerEXT, glNormalPointerEXT, NULL, 617), + NAME_FUNC_OFFSET(10149, glTexCoordPointerEXT, glTexCoordPointerEXT, NULL, 618), + NAME_FUNC_OFFSET(10170, glVertexPointerEXT, glVertexPointerEXT, NULL, 619), + NAME_FUNC_OFFSET(10189, glPointParameterfEXT, glPointParameterfEXT, NULL, 620), + NAME_FUNC_OFFSET(10210, glPointParameterfvEXT, glPointParameterfvEXT, NULL, 621), + NAME_FUNC_OFFSET(10232, glLockArraysEXT, glLockArraysEXT, NULL, 622), + NAME_FUNC_OFFSET(10248, glUnlockArraysEXT, glUnlockArraysEXT, NULL, 623), + NAME_FUNC_OFFSET(10266, glSecondaryColor3bEXT, glSecondaryColor3bEXT, NULL, 624), + NAME_FUNC_OFFSET(10288, glSecondaryColor3bvEXT, glSecondaryColor3bvEXT, NULL, 625), + NAME_FUNC_OFFSET(10311, glSecondaryColor3dEXT, glSecondaryColor3dEXT, NULL, 626), + NAME_FUNC_OFFSET(10333, glSecondaryColor3dvEXT, glSecondaryColor3dvEXT, NULL, 627), + NAME_FUNC_OFFSET(10356, glSecondaryColor3fEXT, glSecondaryColor3fEXT, NULL, 628), + NAME_FUNC_OFFSET(10378, glSecondaryColor3fvEXT, glSecondaryColor3fvEXT, NULL, 629), + NAME_FUNC_OFFSET(10401, glSecondaryColor3iEXT, glSecondaryColor3iEXT, NULL, 630), + NAME_FUNC_OFFSET(10423, glSecondaryColor3ivEXT, glSecondaryColor3ivEXT, NULL, 631), + NAME_FUNC_OFFSET(10446, glSecondaryColor3sEXT, glSecondaryColor3sEXT, NULL, 632), + NAME_FUNC_OFFSET(10468, glSecondaryColor3svEXT, glSecondaryColor3svEXT, NULL, 633), + NAME_FUNC_OFFSET(10491, glSecondaryColor3ubEXT, glSecondaryColor3ubEXT, NULL, 634), + NAME_FUNC_OFFSET(10514, glSecondaryColor3ubvEXT, glSecondaryColor3ubvEXT, NULL, 635), + NAME_FUNC_OFFSET(10538, glSecondaryColor3uiEXT, glSecondaryColor3uiEXT, NULL, 636), + NAME_FUNC_OFFSET(10561, glSecondaryColor3uivEXT, glSecondaryColor3uivEXT, NULL, 637), + NAME_FUNC_OFFSET(10585, glSecondaryColor3usEXT, glSecondaryColor3usEXT, NULL, 638), + NAME_FUNC_OFFSET(10608, glSecondaryColor3usvEXT, glSecondaryColor3usvEXT, NULL, 639), + NAME_FUNC_OFFSET(10632, glSecondaryColorPointerEXT, glSecondaryColorPointerEXT, NULL, 640), + NAME_FUNC_OFFSET(10659, glMultiDrawArraysEXT, glMultiDrawArraysEXT, NULL, 641), + NAME_FUNC_OFFSET(10680, glMultiDrawElementsEXT, glMultiDrawElementsEXT, NULL, 642), + NAME_FUNC_OFFSET(10703, glFogCoordPointerEXT, glFogCoordPointerEXT, NULL, 643), + NAME_FUNC_OFFSET(10724, glFogCoorddEXT, glFogCoorddEXT, NULL, 644), + NAME_FUNC_OFFSET(10739, glFogCoorddvEXT, glFogCoorddvEXT, NULL, 645), + NAME_FUNC_OFFSET(10755, glFogCoordfEXT, glFogCoordfEXT, NULL, 646), + NAME_FUNC_OFFSET(10770, glFogCoordfvEXT, glFogCoordfvEXT, NULL, 647), + NAME_FUNC_OFFSET(10786, gl_dispatch_stub_648, gl_dispatch_stub_648, NULL, 648), + NAME_FUNC_OFFSET(10804, glBlendFuncSeparateEXT, glBlendFuncSeparateEXT, NULL, 649), + NAME_FUNC_OFFSET(10827, glFlushVertexArrayRangeNV, glFlushVertexArrayRangeNV, NULL, 650), + NAME_FUNC_OFFSET(10853, glVertexArrayRangeNV, glVertexArrayRangeNV, NULL, 651), + NAME_FUNC_OFFSET(10874, glCombinerInputNV, glCombinerInputNV, NULL, 652), + NAME_FUNC_OFFSET(10892, glCombinerOutputNV, glCombinerOutputNV, NULL, 653), + NAME_FUNC_OFFSET(10911, glCombinerParameterfNV, glCombinerParameterfNV, NULL, 654), + NAME_FUNC_OFFSET(10934, glCombinerParameterfvNV, glCombinerParameterfvNV, NULL, 655), + NAME_FUNC_OFFSET(10958, glCombinerParameteriNV, glCombinerParameteriNV, NULL, 656), + NAME_FUNC_OFFSET(10981, glCombinerParameterivNV, glCombinerParameterivNV, NULL, 657), + NAME_FUNC_OFFSET(11005, glFinalCombinerInputNV, glFinalCombinerInputNV, NULL, 658), + NAME_FUNC_OFFSET(11028, glGetCombinerInputParameterfvNV, glGetCombinerInputParameterfvNV, NULL, 659), + NAME_FUNC_OFFSET(11060, glGetCombinerInputParameterivNV, glGetCombinerInputParameterivNV, NULL, 660), + NAME_FUNC_OFFSET(11092, glGetCombinerOutputParameterfvNV, glGetCombinerOutputParameterfvNV, NULL, 661), + NAME_FUNC_OFFSET(11125, glGetCombinerOutputParameterivNV, glGetCombinerOutputParameterivNV, NULL, 662), + NAME_FUNC_OFFSET(11158, glGetFinalCombinerInputParameterfvNV, glGetFinalCombinerInputParameterfvNV, NULL, 663), + NAME_FUNC_OFFSET(11195, glGetFinalCombinerInputParameterivNV, glGetFinalCombinerInputParameterivNV, NULL, 664), + NAME_FUNC_OFFSET(11232, glResizeBuffersMESA, glResizeBuffersMESA, NULL, 665), + NAME_FUNC_OFFSET(11252, glWindowPos2dMESA, glWindowPos2dMESA, NULL, 666), + NAME_FUNC_OFFSET(11270, glWindowPos2dvMESA, glWindowPos2dvMESA, NULL, 667), + NAME_FUNC_OFFSET(11289, glWindowPos2fMESA, glWindowPos2fMESA, NULL, 668), + NAME_FUNC_OFFSET(11307, glWindowPos2fvMESA, glWindowPos2fvMESA, NULL, 669), + NAME_FUNC_OFFSET(11326, glWindowPos2iMESA, glWindowPos2iMESA, NULL, 670), + NAME_FUNC_OFFSET(11344, glWindowPos2ivMESA, glWindowPos2ivMESA, NULL, 671), + NAME_FUNC_OFFSET(11363, glWindowPos2sMESA, glWindowPos2sMESA, NULL, 672), + NAME_FUNC_OFFSET(11381, glWindowPos2svMESA, glWindowPos2svMESA, NULL, 673), + NAME_FUNC_OFFSET(11400, glWindowPos3dMESA, glWindowPos3dMESA, NULL, 674), + NAME_FUNC_OFFSET(11418, glWindowPos3dvMESA, glWindowPos3dvMESA, NULL, 675), + NAME_FUNC_OFFSET(11437, glWindowPos3fMESA, glWindowPos3fMESA, NULL, 676), + NAME_FUNC_OFFSET(11455, glWindowPos3fvMESA, glWindowPos3fvMESA, NULL, 677), + NAME_FUNC_OFFSET(11474, glWindowPos3iMESA, glWindowPos3iMESA, NULL, 678), + NAME_FUNC_OFFSET(11492, glWindowPos3ivMESA, glWindowPos3ivMESA, NULL, 679), + NAME_FUNC_OFFSET(11511, glWindowPos3sMESA, glWindowPos3sMESA, NULL, 680), + NAME_FUNC_OFFSET(11529, glWindowPos3svMESA, glWindowPos3svMESA, NULL, 681), + NAME_FUNC_OFFSET(11548, glWindowPos4dMESA, glWindowPos4dMESA, NULL, 682), + NAME_FUNC_OFFSET(11566, glWindowPos4dvMESA, glWindowPos4dvMESA, NULL, 683), + NAME_FUNC_OFFSET(11585, glWindowPos4fMESA, glWindowPos4fMESA, NULL, 684), + NAME_FUNC_OFFSET(11603, glWindowPos4fvMESA, glWindowPos4fvMESA, NULL, 685), + NAME_FUNC_OFFSET(11622, glWindowPos4iMESA, glWindowPos4iMESA, NULL, 686), + NAME_FUNC_OFFSET(11640, glWindowPos4ivMESA, glWindowPos4ivMESA, NULL, 687), + NAME_FUNC_OFFSET(11659, glWindowPos4sMESA, glWindowPos4sMESA, NULL, 688), + NAME_FUNC_OFFSET(11677, glWindowPos4svMESA, glWindowPos4svMESA, NULL, 689), + NAME_FUNC_OFFSET(11696, gl_dispatch_stub_690, gl_dispatch_stub_690, NULL, 690), + NAME_FUNC_OFFSET(11721, gl_dispatch_stub_691, gl_dispatch_stub_691, NULL, 691), + NAME_FUNC_OFFSET(11748, gl_dispatch_stub_692, gl_dispatch_stub_692, NULL, 692), + NAME_FUNC_OFFSET(11765, gl_dispatch_stub_693, gl_dispatch_stub_693, NULL, 693), + NAME_FUNC_OFFSET(11781, gl_dispatch_stub_694, gl_dispatch_stub_694, NULL, 694), + NAME_FUNC_OFFSET(11795, gl_dispatch_stub_695, gl_dispatch_stub_695, NULL, 695), + NAME_FUNC_OFFSET(11810, gl_dispatch_stub_696, gl_dispatch_stub_696, NULL, 696), + NAME_FUNC_OFFSET(11822, gl_dispatch_stub_697, gl_dispatch_stub_697, NULL, 697), + NAME_FUNC_OFFSET(11835, gl_dispatch_stub_698, gl_dispatch_stub_698, NULL, 698), + NAME_FUNC_OFFSET(11849, glAreProgramsResidentNV, glAreProgramsResidentNV, NULL, 699), + NAME_FUNC_OFFSET(11873, glBindProgramNV, glBindProgramNV, NULL, 700), + NAME_FUNC_OFFSET(11889, glDeleteProgramsNV, glDeleteProgramsNV, NULL, 701), + NAME_FUNC_OFFSET(11908, glExecuteProgramNV, glExecuteProgramNV, NULL, 702), + NAME_FUNC_OFFSET(11927, glGenProgramsNV, glGenProgramsNV, NULL, 703), + NAME_FUNC_OFFSET(11943, glGetProgramParameterdvNV, glGetProgramParameterdvNV, NULL, 704), + NAME_FUNC_OFFSET(11969, glGetProgramParameterfvNV, glGetProgramParameterfvNV, NULL, 705), + NAME_FUNC_OFFSET(11995, glGetProgramStringNV, glGetProgramStringNV, NULL, 706), + NAME_FUNC_OFFSET(12016, glGetProgramivNV, glGetProgramivNV, NULL, 707), + NAME_FUNC_OFFSET(12033, glGetTrackMatrixivNV, glGetTrackMatrixivNV, NULL, 708), + NAME_FUNC_OFFSET(12054, glGetVertexAttribPointervNV, glGetVertexAttribPointervNV, NULL, 709), + NAME_FUNC_OFFSET(12082, glGetVertexAttribdvNV, glGetVertexAttribdvNV, NULL, 710), + NAME_FUNC_OFFSET(12104, glGetVertexAttribfvNV, glGetVertexAttribfvNV, NULL, 711), + NAME_FUNC_OFFSET(12126, glGetVertexAttribivNV, glGetVertexAttribivNV, NULL, 712), + NAME_FUNC_OFFSET(12148, glIsProgramNV, glIsProgramNV, NULL, 713), + NAME_FUNC_OFFSET(12162, glLoadProgramNV, glLoadProgramNV, NULL, 714), + NAME_FUNC_OFFSET(12178, glProgramParameters4dvNV, glProgramParameters4dvNV, NULL, 715), + NAME_FUNC_OFFSET(12203, glProgramParameters4fvNV, glProgramParameters4fvNV, NULL, 716), + NAME_FUNC_OFFSET(12228, glRequestResidentProgramsNV, glRequestResidentProgramsNV, NULL, 717), + NAME_FUNC_OFFSET(12256, glTrackMatrixNV, glTrackMatrixNV, NULL, 718), + NAME_FUNC_OFFSET(12272, glVertexAttrib1dNV, glVertexAttrib1dNV, NULL, 719), + NAME_FUNC_OFFSET(12291, glVertexAttrib1dvNV, glVertexAttrib1dvNV, NULL, 720), + NAME_FUNC_OFFSET(12311, glVertexAttrib1fNV, glVertexAttrib1fNV, NULL, 721), + NAME_FUNC_OFFSET(12330, glVertexAttrib1fvNV, glVertexAttrib1fvNV, NULL, 722), + NAME_FUNC_OFFSET(12350, glVertexAttrib1sNV, glVertexAttrib1sNV, NULL, 723), + NAME_FUNC_OFFSET(12369, glVertexAttrib1svNV, glVertexAttrib1svNV, NULL, 724), + NAME_FUNC_OFFSET(12389, glVertexAttrib2dNV, glVertexAttrib2dNV, NULL, 725), + NAME_FUNC_OFFSET(12408, glVertexAttrib2dvNV, glVertexAttrib2dvNV, NULL, 726), + NAME_FUNC_OFFSET(12428, glVertexAttrib2fNV, glVertexAttrib2fNV, NULL, 727), + NAME_FUNC_OFFSET(12447, glVertexAttrib2fvNV, glVertexAttrib2fvNV, NULL, 728), + NAME_FUNC_OFFSET(12467, glVertexAttrib2sNV, glVertexAttrib2sNV, NULL, 729), + NAME_FUNC_OFFSET(12486, glVertexAttrib2svNV, glVertexAttrib2svNV, NULL, 730), + NAME_FUNC_OFFSET(12506, glVertexAttrib3dNV, glVertexAttrib3dNV, NULL, 731), + NAME_FUNC_OFFSET(12525, glVertexAttrib3dvNV, glVertexAttrib3dvNV, NULL, 732), + NAME_FUNC_OFFSET(12545, glVertexAttrib3fNV, glVertexAttrib3fNV, NULL, 733), + NAME_FUNC_OFFSET(12564, glVertexAttrib3fvNV, glVertexAttrib3fvNV, NULL, 734), + NAME_FUNC_OFFSET(12584, glVertexAttrib3sNV, glVertexAttrib3sNV, NULL, 735), + NAME_FUNC_OFFSET(12603, glVertexAttrib3svNV, glVertexAttrib3svNV, NULL, 736), + NAME_FUNC_OFFSET(12623, glVertexAttrib4dNV, glVertexAttrib4dNV, NULL, 737), + NAME_FUNC_OFFSET(12642, glVertexAttrib4dvNV, glVertexAttrib4dvNV, NULL, 738), + NAME_FUNC_OFFSET(12662, glVertexAttrib4fNV, glVertexAttrib4fNV, NULL, 739), + NAME_FUNC_OFFSET(12681, glVertexAttrib4fvNV, glVertexAttrib4fvNV, NULL, 740), + NAME_FUNC_OFFSET(12701, glVertexAttrib4sNV, glVertexAttrib4sNV, NULL, 741), + NAME_FUNC_OFFSET(12720, glVertexAttrib4svNV, glVertexAttrib4svNV, NULL, 742), + NAME_FUNC_OFFSET(12740, glVertexAttrib4ubNV, glVertexAttrib4ubNV, NULL, 743), + NAME_FUNC_OFFSET(12760, glVertexAttrib4ubvNV, glVertexAttrib4ubvNV, NULL, 744), + NAME_FUNC_OFFSET(12781, glVertexAttribPointerNV, glVertexAttribPointerNV, NULL, 745), + NAME_FUNC_OFFSET(12805, glVertexAttribs1dvNV, glVertexAttribs1dvNV, NULL, 746), + NAME_FUNC_OFFSET(12826, glVertexAttribs1fvNV, glVertexAttribs1fvNV, NULL, 747), + NAME_FUNC_OFFSET(12847, glVertexAttribs1svNV, glVertexAttribs1svNV, NULL, 748), + NAME_FUNC_OFFSET(12868, glVertexAttribs2dvNV, glVertexAttribs2dvNV, NULL, 749), + NAME_FUNC_OFFSET(12889, glVertexAttribs2fvNV, glVertexAttribs2fvNV, NULL, 750), + NAME_FUNC_OFFSET(12910, glVertexAttribs2svNV, glVertexAttribs2svNV, NULL, 751), + NAME_FUNC_OFFSET(12931, glVertexAttribs3dvNV, glVertexAttribs3dvNV, NULL, 752), + NAME_FUNC_OFFSET(12952, glVertexAttribs3fvNV, glVertexAttribs3fvNV, NULL, 753), + NAME_FUNC_OFFSET(12973, glVertexAttribs3svNV, glVertexAttribs3svNV, NULL, 754), + NAME_FUNC_OFFSET(12994, glVertexAttribs4dvNV, glVertexAttribs4dvNV, NULL, 755), + NAME_FUNC_OFFSET(13015, glVertexAttribs4fvNV, glVertexAttribs4fvNV, NULL, 756), + NAME_FUNC_OFFSET(13036, glVertexAttribs4svNV, glVertexAttribs4svNV, NULL, 757), + NAME_FUNC_OFFSET(13057, glVertexAttribs4ubvNV, glVertexAttribs4ubvNV, NULL, 758), + NAME_FUNC_OFFSET(13079, glGetTexBumpParameterfvATI, glGetTexBumpParameterfvATI, NULL, 759), + NAME_FUNC_OFFSET(13106, glGetTexBumpParameterivATI, glGetTexBumpParameterivATI, NULL, 760), + NAME_FUNC_OFFSET(13133, glTexBumpParameterfvATI, glTexBumpParameterfvATI, NULL, 761), + NAME_FUNC_OFFSET(13157, glTexBumpParameterivATI, glTexBumpParameterivATI, NULL, 762), + NAME_FUNC_OFFSET(13181, glAlphaFragmentOp1ATI, glAlphaFragmentOp1ATI, NULL, 763), + NAME_FUNC_OFFSET(13203, glAlphaFragmentOp2ATI, glAlphaFragmentOp2ATI, NULL, 764), + NAME_FUNC_OFFSET(13225, glAlphaFragmentOp3ATI, glAlphaFragmentOp3ATI, NULL, 765), + NAME_FUNC_OFFSET(13247, glBeginFragmentShaderATI, glBeginFragmentShaderATI, NULL, 766), + NAME_FUNC_OFFSET(13272, glBindFragmentShaderATI, glBindFragmentShaderATI, NULL, 767), + NAME_FUNC_OFFSET(13296, glColorFragmentOp1ATI, glColorFragmentOp1ATI, NULL, 768), + NAME_FUNC_OFFSET(13318, glColorFragmentOp2ATI, glColorFragmentOp2ATI, NULL, 769), + NAME_FUNC_OFFSET(13340, glColorFragmentOp3ATI, glColorFragmentOp3ATI, NULL, 770), + NAME_FUNC_OFFSET(13362, glDeleteFragmentShaderATI, glDeleteFragmentShaderATI, NULL, 771), + NAME_FUNC_OFFSET(13388, glEndFragmentShaderATI, glEndFragmentShaderATI, NULL, 772), + NAME_FUNC_OFFSET(13411, glGenFragmentShadersATI, glGenFragmentShadersATI, NULL, 773), + NAME_FUNC_OFFSET(13435, glPassTexCoordATI, glPassTexCoordATI, NULL, 774), + NAME_FUNC_OFFSET(13453, glSampleMapATI, glSampleMapATI, NULL, 775), + NAME_FUNC_OFFSET(13468, glSetFragmentShaderConstantATI, glSetFragmentShaderConstantATI, NULL, 776), + NAME_FUNC_OFFSET(13499, glPointParameteriNV, glPointParameteriNV, NULL, 777), + NAME_FUNC_OFFSET(13519, glPointParameterivNV, glPointParameterivNV, NULL, 778), + NAME_FUNC_OFFSET(13540, gl_dispatch_stub_779, gl_dispatch_stub_779, NULL, 779), + NAME_FUNC_OFFSET(13563, gl_dispatch_stub_780, gl_dispatch_stub_780, NULL, 780), + NAME_FUNC_OFFSET(13586, gl_dispatch_stub_781, gl_dispatch_stub_781, NULL, 781), + NAME_FUNC_OFFSET(13612, gl_dispatch_stub_782, gl_dispatch_stub_782, NULL, 782), + NAME_FUNC_OFFSET(13635, gl_dispatch_stub_783, gl_dispatch_stub_783, NULL, 783), + NAME_FUNC_OFFSET(13656, glGetProgramNamedParameterdvNV, glGetProgramNamedParameterdvNV, NULL, 784), + NAME_FUNC_OFFSET(13687, glGetProgramNamedParameterfvNV, glGetProgramNamedParameterfvNV, NULL, 785), + NAME_FUNC_OFFSET(13718, glProgramNamedParameter4dNV, glProgramNamedParameter4dNV, NULL, 786), + NAME_FUNC_OFFSET(13746, glProgramNamedParameter4dvNV, glProgramNamedParameter4dvNV, NULL, 787), + NAME_FUNC_OFFSET(13775, glProgramNamedParameter4fNV, glProgramNamedParameter4fNV, NULL, 788), + NAME_FUNC_OFFSET(13803, glProgramNamedParameter4fvNV, glProgramNamedParameter4fvNV, NULL, 789), + NAME_FUNC_OFFSET(13832, glPrimitiveRestartIndexNV, glPrimitiveRestartIndexNV, NULL, 790), + NAME_FUNC_OFFSET(13858, glPrimitiveRestartNV, glPrimitiveRestartNV, NULL, 791), + NAME_FUNC_OFFSET(13879, gl_dispatch_stub_792, gl_dispatch_stub_792, NULL, 792), + NAME_FUNC_OFFSET(13896, gl_dispatch_stub_793, gl_dispatch_stub_793, NULL, 793), + NAME_FUNC_OFFSET(13923, glBindFramebufferEXT, glBindFramebufferEXT, NULL, 794), + NAME_FUNC_OFFSET(13944, glBindRenderbufferEXT, glBindRenderbufferEXT, NULL, 795), + NAME_FUNC_OFFSET(13966, glCheckFramebufferStatusEXT, glCheckFramebufferStatusEXT, NULL, 796), + NAME_FUNC_OFFSET(13994, glDeleteFramebuffersEXT, glDeleteFramebuffersEXT, NULL, 797), + NAME_FUNC_OFFSET(14018, glDeleteRenderbuffersEXT, glDeleteRenderbuffersEXT, NULL, 798), + NAME_FUNC_OFFSET(14043, glFramebufferRenderbufferEXT, glFramebufferRenderbufferEXT, NULL, 799), + NAME_FUNC_OFFSET(14072, glFramebufferTexture1DEXT, glFramebufferTexture1DEXT, NULL, 800), + NAME_FUNC_OFFSET(14098, glFramebufferTexture2DEXT, glFramebufferTexture2DEXT, NULL, 801), + NAME_FUNC_OFFSET(14124, glFramebufferTexture3DEXT, glFramebufferTexture3DEXT, NULL, 802), + NAME_FUNC_OFFSET(14150, glGenFramebuffersEXT, glGenFramebuffersEXT, NULL, 803), + NAME_FUNC_OFFSET(14171, glGenRenderbuffersEXT, glGenRenderbuffersEXT, NULL, 804), + NAME_FUNC_OFFSET(14193, glGenerateMipmapEXT, glGenerateMipmapEXT, NULL, 805), + NAME_FUNC_OFFSET(14213, glGetFramebufferAttachmentParameterivEXT, glGetFramebufferAttachmentParameterivEXT, NULL, 806), + NAME_FUNC_OFFSET(14254, glGetRenderbufferParameterivEXT, glGetRenderbufferParameterivEXT, NULL, 807), + NAME_FUNC_OFFSET(14286, glIsFramebufferEXT, glIsFramebufferEXT, NULL, 808), + NAME_FUNC_OFFSET(14305, glIsRenderbufferEXT, glIsRenderbufferEXT, NULL, 809), + NAME_FUNC_OFFSET(14325, glRenderbufferStorageEXT, glRenderbufferStorageEXT, NULL, 810), + NAME_FUNC_OFFSET(14350, gl_dispatch_stub_811, gl_dispatch_stub_811, NULL, 811), + NAME_FUNC_OFFSET(14371, gl_dispatch_stub_812, gl_dispatch_stub_812, NULL, 812), + NAME_FUNC_OFFSET(14395, gl_dispatch_stub_813, gl_dispatch_stub_813, NULL, 813), + NAME_FUNC_OFFSET(14425, glBindFragDataLocationEXT, glBindFragDataLocationEXT, NULL, 814), + NAME_FUNC_OFFSET(14451, glGetFragDataLocationEXT, glGetFragDataLocationEXT, NULL, 815), + NAME_FUNC_OFFSET(14476, glGetUniformuivEXT, glGetUniformuivEXT, NULL, 816), + NAME_FUNC_OFFSET(14495, glGetVertexAttribIivEXT, glGetVertexAttribIivEXT, NULL, 817), + NAME_FUNC_OFFSET(14519, glGetVertexAttribIuivEXT, glGetVertexAttribIuivEXT, NULL, 818), + NAME_FUNC_OFFSET(14544, glUniform1uiEXT, glUniform1uiEXT, NULL, 819), + NAME_FUNC_OFFSET(14560, glUniform1uivEXT, glUniform1uivEXT, NULL, 820), + NAME_FUNC_OFFSET(14577, glUniform2uiEXT, glUniform2uiEXT, NULL, 821), + NAME_FUNC_OFFSET(14593, glUniform2uivEXT, glUniform2uivEXT, NULL, 822), + NAME_FUNC_OFFSET(14610, glUniform3uiEXT, glUniform3uiEXT, NULL, 823), + NAME_FUNC_OFFSET(14626, glUniform3uivEXT, glUniform3uivEXT, NULL, 824), + NAME_FUNC_OFFSET(14643, glUniform4uiEXT, glUniform4uiEXT, NULL, 825), + NAME_FUNC_OFFSET(14659, glUniform4uivEXT, glUniform4uivEXT, NULL, 826), + NAME_FUNC_OFFSET(14676, glVertexAttribI1iEXT, glVertexAttribI1iEXT, NULL, 827), + NAME_FUNC_OFFSET(14697, glVertexAttribI1ivEXT, glVertexAttribI1ivEXT, NULL, 828), + NAME_FUNC_OFFSET(14719, glVertexAttribI1uiEXT, glVertexAttribI1uiEXT, NULL, 829), + NAME_FUNC_OFFSET(14741, glVertexAttribI1uivEXT, glVertexAttribI1uivEXT, NULL, 830), + NAME_FUNC_OFFSET(14764, glVertexAttribI2iEXT, glVertexAttribI2iEXT, NULL, 831), + NAME_FUNC_OFFSET(14785, glVertexAttribI2ivEXT, glVertexAttribI2ivEXT, NULL, 832), + NAME_FUNC_OFFSET(14807, glVertexAttribI2uiEXT, glVertexAttribI2uiEXT, NULL, 833), + NAME_FUNC_OFFSET(14829, glVertexAttribI2uivEXT, glVertexAttribI2uivEXT, NULL, 834), + NAME_FUNC_OFFSET(14852, glVertexAttribI3iEXT, glVertexAttribI3iEXT, NULL, 835), + NAME_FUNC_OFFSET(14873, glVertexAttribI3ivEXT, glVertexAttribI3ivEXT, NULL, 836), + NAME_FUNC_OFFSET(14895, glVertexAttribI3uiEXT, glVertexAttribI3uiEXT, NULL, 837), + NAME_FUNC_OFFSET(14917, glVertexAttribI3uivEXT, glVertexAttribI3uivEXT, NULL, 838), + NAME_FUNC_OFFSET(14940, glVertexAttribI4bvEXT, glVertexAttribI4bvEXT, NULL, 839), + NAME_FUNC_OFFSET(14962, glVertexAttribI4iEXT, glVertexAttribI4iEXT, NULL, 840), + NAME_FUNC_OFFSET(14983, glVertexAttribI4ivEXT, glVertexAttribI4ivEXT, NULL, 841), + NAME_FUNC_OFFSET(15005, glVertexAttribI4svEXT, glVertexAttribI4svEXT, NULL, 842), + NAME_FUNC_OFFSET(15027, glVertexAttribI4ubvEXT, glVertexAttribI4ubvEXT, NULL, 843), + NAME_FUNC_OFFSET(15050, glVertexAttribI4uiEXT, glVertexAttribI4uiEXT, NULL, 844), + NAME_FUNC_OFFSET(15072, glVertexAttribI4uivEXT, glVertexAttribI4uivEXT, NULL, 845), + NAME_FUNC_OFFSET(15095, glVertexAttribI4usvEXT, glVertexAttribI4usvEXT, NULL, 846), + NAME_FUNC_OFFSET(15118, glVertexAttribIPointerEXT, glVertexAttribIPointerEXT, NULL, 847), + NAME_FUNC_OFFSET(15144, glFramebufferTextureLayerEXT, glFramebufferTextureLayerEXT, NULL, 848), + NAME_FUNC_OFFSET(15173, glColorMaskIndexedEXT, glColorMaskIndexedEXT, NULL, 849), + NAME_FUNC_OFFSET(15195, glDisableIndexedEXT, glDisableIndexedEXT, NULL, 850), + NAME_FUNC_OFFSET(15215, glEnableIndexedEXT, glEnableIndexedEXT, NULL, 851), + NAME_FUNC_OFFSET(15234, glGetBooleanIndexedvEXT, glGetBooleanIndexedvEXT, NULL, 852), + NAME_FUNC_OFFSET(15258, glGetIntegerIndexedvEXT, glGetIntegerIndexedvEXT, NULL, 853), + NAME_FUNC_OFFSET(15282, glIsEnabledIndexedEXT, glIsEnabledIndexedEXT, NULL, 854), + NAME_FUNC_OFFSET(15304, glClearColorIiEXT, glClearColorIiEXT, NULL, 855), + NAME_FUNC_OFFSET(15322, glClearColorIuiEXT, glClearColorIuiEXT, NULL, 856), + NAME_FUNC_OFFSET(15341, glGetTexParameterIivEXT, glGetTexParameterIivEXT, NULL, 857), + NAME_FUNC_OFFSET(15365, glGetTexParameterIuivEXT, glGetTexParameterIuivEXT, NULL, 858), + NAME_FUNC_OFFSET(15390, glTexParameterIivEXT, glTexParameterIivEXT, NULL, 859), + NAME_FUNC_OFFSET(15411, glTexParameterIuivEXT, glTexParameterIuivEXT, NULL, 860), + NAME_FUNC_OFFSET(15433, glBeginConditionalRenderNV, glBeginConditionalRenderNV, NULL, 861), + NAME_FUNC_OFFSET(15460, glEndConditionalRenderNV, glEndConditionalRenderNV, NULL, 862), + NAME_FUNC_OFFSET(15485, glBeginTransformFeedbackEXT, glBeginTransformFeedbackEXT, NULL, 863), + NAME_FUNC_OFFSET(15513, glBindBufferBaseEXT, glBindBufferBaseEXT, NULL, 864), + NAME_FUNC_OFFSET(15533, glBindBufferOffsetEXT, glBindBufferOffsetEXT, NULL, 865), + NAME_FUNC_OFFSET(15555, glBindBufferRangeEXT, glBindBufferRangeEXT, NULL, 866), + NAME_FUNC_OFFSET(15576, glEndTransformFeedbackEXT, glEndTransformFeedbackEXT, NULL, 867), + NAME_FUNC_OFFSET(15602, glGetTransformFeedbackVaryingEXT, glGetTransformFeedbackVaryingEXT, NULL, 868), + NAME_FUNC_OFFSET(15635, glTransformFeedbackVaryingsEXT, glTransformFeedbackVaryingsEXT, NULL, 869), + NAME_FUNC_OFFSET(15666, glProvokingVertexEXT, glProvokingVertexEXT, NULL, 870), + NAME_FUNC_OFFSET(15687, gl_dispatch_stub_871, gl_dispatch_stub_871, NULL, 871), + NAME_FUNC_OFFSET(15718, gl_dispatch_stub_872, gl_dispatch_stub_872, NULL, 872), + NAME_FUNC_OFFSET(15738, glGetObjectParameterivAPPLE, glGetObjectParameterivAPPLE, NULL, 873), + NAME_FUNC_OFFSET(15766, glObjectPurgeableAPPLE, glObjectPurgeableAPPLE, NULL, 874), + NAME_FUNC_OFFSET(15789, glObjectUnpurgeableAPPLE, glObjectUnpurgeableAPPLE, NULL, 875), + NAME_FUNC_OFFSET(15814, glActiveProgramEXT, glActiveProgramEXT, NULL, 876), + NAME_FUNC_OFFSET(15833, glCreateShaderProgramEXT, glCreateShaderProgramEXT, NULL, 877), + NAME_FUNC_OFFSET(15858, glUseShaderProgramEXT, glUseShaderProgramEXT, NULL, 878), + NAME_FUNC_OFFSET(15880, gl_dispatch_stub_879, gl_dispatch_stub_879, NULL, 879), + NAME_FUNC_OFFSET(15905, gl_dispatch_stub_880, gl_dispatch_stub_880, NULL, 880), + NAME_FUNC_OFFSET(15934, gl_dispatch_stub_881, gl_dispatch_stub_881, NULL, 881), + NAME_FUNC_OFFSET(15965, gl_dispatch_stub_882, gl_dispatch_stub_882, NULL, 882), + NAME_FUNC_OFFSET(15989, gl_dispatch_stub_883, gl_dispatch_stub_883, NULL, 883), + NAME_FUNC_OFFSET(16014, glEGLImageTargetRenderbufferStorageOES, glEGLImageTargetRenderbufferStorageOES, NULL, 884), + NAME_FUNC_OFFSET(16053, glEGLImageTargetTexture2DOES, glEGLImageTargetTexture2DOES, NULL, 885), + NAME_FUNC_OFFSET(16082, glArrayElement, glArrayElement, NULL, 306), + NAME_FUNC_OFFSET(16100, glBindTexture, glBindTexture, NULL, 307), + NAME_FUNC_OFFSET(16117, glDrawArrays, glDrawArrays, NULL, 310), + NAME_FUNC_OFFSET(16133, glAreTexturesResident, glAreTexturesResidentEXT, glAreTexturesResidentEXT, 322), + NAME_FUNC_OFFSET(16158, glCopyTexImage1D, glCopyTexImage1D, NULL, 323), + NAME_FUNC_OFFSET(16178, glCopyTexImage2D, glCopyTexImage2D, NULL, 324), + NAME_FUNC_OFFSET(16198, glCopyTexSubImage1D, glCopyTexSubImage1D, NULL, 325), + NAME_FUNC_OFFSET(16221, glCopyTexSubImage2D, glCopyTexSubImage2D, NULL, 326), + NAME_FUNC_OFFSET(16244, glDeleteTextures, glDeleteTexturesEXT, glDeleteTexturesEXT, 327), + NAME_FUNC_OFFSET(16264, glGenTextures, glGenTexturesEXT, glGenTexturesEXT, 328), + NAME_FUNC_OFFSET(16281, glGetPointerv, glGetPointerv, NULL, 329), + NAME_FUNC_OFFSET(16298, glIsTexture, glIsTextureEXT, glIsTextureEXT, 330), + NAME_FUNC_OFFSET(16313, glPrioritizeTextures, glPrioritizeTextures, NULL, 331), + NAME_FUNC_OFFSET(16337, glTexSubImage1D, glTexSubImage1D, NULL, 332), + NAME_FUNC_OFFSET(16356, glTexSubImage2D, glTexSubImage2D, NULL, 333), + NAME_FUNC_OFFSET(16375, glBlendColor, glBlendColor, NULL, 336), + NAME_FUNC_OFFSET(16391, glBlendEquation, glBlendEquation, NULL, 337), + NAME_FUNC_OFFSET(16410, glDrawRangeElements, glDrawRangeElements, NULL, 338), + NAME_FUNC_OFFSET(16433, glColorTable, glColorTable, NULL, 339), + NAME_FUNC_OFFSET(16449, glColorTable, glColorTable, NULL, 339), + NAME_FUNC_OFFSET(16465, glColorTableParameterfv, glColorTableParameterfv, NULL, 340), + NAME_FUNC_OFFSET(16492, glColorTableParameteriv, glColorTableParameteriv, NULL, 341), + NAME_FUNC_OFFSET(16519, glCopyColorTable, glCopyColorTable, NULL, 342), + NAME_FUNC_OFFSET(16539, glGetColorTable, glGetColorTableEXT, glGetColorTableEXT, 343), + NAME_FUNC_OFFSET(16558, glGetColorTable, glGetColorTableEXT, glGetColorTableEXT, 343), + NAME_FUNC_OFFSET(16577, glGetColorTableParameterfv, glGetColorTableParameterfvEXT, glGetColorTableParameterfvEXT, 344), + NAME_FUNC_OFFSET(16607, glGetColorTableParameterfv, glGetColorTableParameterfvEXT, glGetColorTableParameterfvEXT, 344), + NAME_FUNC_OFFSET(16637, glGetColorTableParameteriv, glGetColorTableParameterivEXT, glGetColorTableParameterivEXT, 345), + NAME_FUNC_OFFSET(16667, glGetColorTableParameteriv, glGetColorTableParameterivEXT, glGetColorTableParameterivEXT, 345), + NAME_FUNC_OFFSET(16697, glColorSubTable, glColorSubTable, NULL, 346), + NAME_FUNC_OFFSET(16716, glCopyColorSubTable, glCopyColorSubTable, NULL, 347), + NAME_FUNC_OFFSET(16739, glConvolutionFilter1D, glConvolutionFilter1D, NULL, 348), + NAME_FUNC_OFFSET(16764, glConvolutionFilter2D, glConvolutionFilter2D, NULL, 349), + NAME_FUNC_OFFSET(16789, glConvolutionParameterf, glConvolutionParameterf, NULL, 350), + NAME_FUNC_OFFSET(16816, glConvolutionParameterfv, glConvolutionParameterfv, NULL, 351), + NAME_FUNC_OFFSET(16844, glConvolutionParameteri, glConvolutionParameteri, NULL, 352), + NAME_FUNC_OFFSET(16871, glConvolutionParameteriv, glConvolutionParameteriv, NULL, 353), + NAME_FUNC_OFFSET(16899, glCopyConvolutionFilter1D, glCopyConvolutionFilter1D, NULL, 354), + NAME_FUNC_OFFSET(16928, glCopyConvolutionFilter2D, glCopyConvolutionFilter2D, NULL, 355), + NAME_FUNC_OFFSET(16957, glGetConvolutionFilter, gl_dispatch_stub_356, gl_dispatch_stub_356, 356), + NAME_FUNC_OFFSET(16983, glGetConvolutionParameterfv, gl_dispatch_stub_357, gl_dispatch_stub_357, 357), + NAME_FUNC_OFFSET(17014, glGetConvolutionParameteriv, gl_dispatch_stub_358, gl_dispatch_stub_358, 358), + NAME_FUNC_OFFSET(17045, glGetSeparableFilter, gl_dispatch_stub_359, gl_dispatch_stub_359, 359), + NAME_FUNC_OFFSET(17069, glSeparableFilter2D, glSeparableFilter2D, NULL, 360), + NAME_FUNC_OFFSET(17092, glGetHistogram, gl_dispatch_stub_361, gl_dispatch_stub_361, 361), + NAME_FUNC_OFFSET(17110, glGetHistogramParameterfv, gl_dispatch_stub_362, gl_dispatch_stub_362, 362), + NAME_FUNC_OFFSET(17139, glGetHistogramParameteriv, gl_dispatch_stub_363, gl_dispatch_stub_363, 363), + NAME_FUNC_OFFSET(17168, glGetMinmax, gl_dispatch_stub_364, gl_dispatch_stub_364, 364), + NAME_FUNC_OFFSET(17183, glGetMinmaxParameterfv, gl_dispatch_stub_365, gl_dispatch_stub_365, 365), + NAME_FUNC_OFFSET(17209, glGetMinmaxParameteriv, gl_dispatch_stub_366, gl_dispatch_stub_366, 366), + NAME_FUNC_OFFSET(17235, glHistogram, glHistogram, NULL, 367), + NAME_FUNC_OFFSET(17250, glMinmax, glMinmax, NULL, 368), + NAME_FUNC_OFFSET(17262, glResetHistogram, glResetHistogram, NULL, 369), + NAME_FUNC_OFFSET(17282, glResetMinmax, glResetMinmax, NULL, 370), + NAME_FUNC_OFFSET(17299, glTexImage3D, glTexImage3D, NULL, 371), + NAME_FUNC_OFFSET(17315, glTexSubImage3D, glTexSubImage3D, NULL, 372), + NAME_FUNC_OFFSET(17334, glCopyTexSubImage3D, glCopyTexSubImage3D, NULL, 373), + NAME_FUNC_OFFSET(17357, glActiveTextureARB, glActiveTextureARB, NULL, 374), + NAME_FUNC_OFFSET(17373, glClientActiveTextureARB, glClientActiveTextureARB, NULL, 375), + NAME_FUNC_OFFSET(17395, glMultiTexCoord1dARB, glMultiTexCoord1dARB, NULL, 376), + NAME_FUNC_OFFSET(17413, glMultiTexCoord1dvARB, glMultiTexCoord1dvARB, NULL, 377), + NAME_FUNC_OFFSET(17432, glMultiTexCoord1fARB, glMultiTexCoord1fARB, NULL, 378), + NAME_FUNC_OFFSET(17450, glMultiTexCoord1fvARB, glMultiTexCoord1fvARB, NULL, 379), + NAME_FUNC_OFFSET(17469, glMultiTexCoord1iARB, glMultiTexCoord1iARB, NULL, 380), + NAME_FUNC_OFFSET(17487, glMultiTexCoord1ivARB, glMultiTexCoord1ivARB, NULL, 381), + NAME_FUNC_OFFSET(17506, glMultiTexCoord1sARB, glMultiTexCoord1sARB, NULL, 382), + NAME_FUNC_OFFSET(17524, glMultiTexCoord1svARB, glMultiTexCoord1svARB, NULL, 383), + NAME_FUNC_OFFSET(17543, glMultiTexCoord2dARB, glMultiTexCoord2dARB, NULL, 384), + NAME_FUNC_OFFSET(17561, glMultiTexCoord2dvARB, glMultiTexCoord2dvARB, NULL, 385), + NAME_FUNC_OFFSET(17580, glMultiTexCoord2fARB, glMultiTexCoord2fARB, NULL, 386), + NAME_FUNC_OFFSET(17598, glMultiTexCoord2fvARB, glMultiTexCoord2fvARB, NULL, 387), + NAME_FUNC_OFFSET(17617, glMultiTexCoord2iARB, glMultiTexCoord2iARB, NULL, 388), + NAME_FUNC_OFFSET(17635, glMultiTexCoord2ivARB, glMultiTexCoord2ivARB, NULL, 389), + NAME_FUNC_OFFSET(17654, glMultiTexCoord2sARB, glMultiTexCoord2sARB, NULL, 390), + NAME_FUNC_OFFSET(17672, glMultiTexCoord2svARB, glMultiTexCoord2svARB, NULL, 391), + NAME_FUNC_OFFSET(17691, glMultiTexCoord3dARB, glMultiTexCoord3dARB, NULL, 392), + NAME_FUNC_OFFSET(17709, glMultiTexCoord3dvARB, glMultiTexCoord3dvARB, NULL, 393), + NAME_FUNC_OFFSET(17728, glMultiTexCoord3fARB, glMultiTexCoord3fARB, NULL, 394), + NAME_FUNC_OFFSET(17746, glMultiTexCoord3fvARB, glMultiTexCoord3fvARB, NULL, 395), + NAME_FUNC_OFFSET(17765, glMultiTexCoord3iARB, glMultiTexCoord3iARB, NULL, 396), + NAME_FUNC_OFFSET(17783, glMultiTexCoord3ivARB, glMultiTexCoord3ivARB, NULL, 397), + NAME_FUNC_OFFSET(17802, glMultiTexCoord3sARB, glMultiTexCoord3sARB, NULL, 398), + NAME_FUNC_OFFSET(17820, glMultiTexCoord3svARB, glMultiTexCoord3svARB, NULL, 399), + NAME_FUNC_OFFSET(17839, glMultiTexCoord4dARB, glMultiTexCoord4dARB, NULL, 400), + NAME_FUNC_OFFSET(17857, glMultiTexCoord4dvARB, glMultiTexCoord4dvARB, NULL, 401), + NAME_FUNC_OFFSET(17876, glMultiTexCoord4fARB, glMultiTexCoord4fARB, NULL, 402), + NAME_FUNC_OFFSET(17894, glMultiTexCoord4fvARB, glMultiTexCoord4fvARB, NULL, 403), + NAME_FUNC_OFFSET(17913, glMultiTexCoord4iARB, glMultiTexCoord4iARB, NULL, 404), + NAME_FUNC_OFFSET(17931, glMultiTexCoord4ivARB, glMultiTexCoord4ivARB, NULL, 405), + NAME_FUNC_OFFSET(17950, glMultiTexCoord4sARB, glMultiTexCoord4sARB, NULL, 406), + NAME_FUNC_OFFSET(17968, glMultiTexCoord4svARB, glMultiTexCoord4svARB, NULL, 407), + NAME_FUNC_OFFSET(17987, glStencilOpSeparate, glStencilOpSeparate, NULL, 423), + NAME_FUNC_OFFSET(18010, glLoadTransposeMatrixdARB, glLoadTransposeMatrixdARB, NULL, 441), + NAME_FUNC_OFFSET(18033, glLoadTransposeMatrixfARB, glLoadTransposeMatrixfARB, NULL, 442), + NAME_FUNC_OFFSET(18056, glMultTransposeMatrixdARB, glMultTransposeMatrixdARB, NULL, 443), + NAME_FUNC_OFFSET(18079, glMultTransposeMatrixfARB, glMultTransposeMatrixfARB, NULL, 444), + NAME_FUNC_OFFSET(18102, glSampleCoverageARB, glSampleCoverageARB, NULL, 445), + NAME_FUNC_OFFSET(18119, glCompressedTexImage1DARB, glCompressedTexImage1DARB, NULL, 446), + NAME_FUNC_OFFSET(18142, glCompressedTexImage2DARB, glCompressedTexImage2DARB, NULL, 447), + NAME_FUNC_OFFSET(18165, glCompressedTexImage3DARB, glCompressedTexImage3DARB, NULL, 448), + NAME_FUNC_OFFSET(18188, glCompressedTexSubImage1DARB, glCompressedTexSubImage1DARB, NULL, 449), + NAME_FUNC_OFFSET(18214, glCompressedTexSubImage2DARB, glCompressedTexSubImage2DARB, NULL, 450), + NAME_FUNC_OFFSET(18240, glCompressedTexSubImage3DARB, glCompressedTexSubImage3DARB, NULL, 451), + NAME_FUNC_OFFSET(18266, glGetCompressedTexImageARB, glGetCompressedTexImageARB, NULL, 452), + NAME_FUNC_OFFSET(18290, glDisableVertexAttribArrayARB, glDisableVertexAttribArrayARB, NULL, 453), + NAME_FUNC_OFFSET(18317, glEnableVertexAttribArrayARB, glEnableVertexAttribArrayARB, NULL, 454), + NAME_FUNC_OFFSET(18343, glGetVertexAttribdvARB, glGetVertexAttribdvARB, NULL, 461), + NAME_FUNC_OFFSET(18363, glGetVertexAttribfvARB, glGetVertexAttribfvARB, NULL, 462), + NAME_FUNC_OFFSET(18383, glGetVertexAttribivARB, glGetVertexAttribivARB, NULL, 463), + NAME_FUNC_OFFSET(18403, glProgramEnvParameter4dARB, glProgramEnvParameter4dARB, NULL, 464), + NAME_FUNC_OFFSET(18426, glProgramEnvParameter4dvARB, glProgramEnvParameter4dvARB, NULL, 465), + NAME_FUNC_OFFSET(18450, glProgramEnvParameter4fARB, glProgramEnvParameter4fARB, NULL, 466), + NAME_FUNC_OFFSET(18473, glProgramEnvParameter4fvARB, glProgramEnvParameter4fvARB, NULL, 467), + NAME_FUNC_OFFSET(18497, glVertexAttrib1dARB, glVertexAttrib1dARB, NULL, 473), + NAME_FUNC_OFFSET(18514, glVertexAttrib1dvARB, glVertexAttrib1dvARB, NULL, 474), + NAME_FUNC_OFFSET(18532, glVertexAttrib1fARB, glVertexAttrib1fARB, NULL, 475), + NAME_FUNC_OFFSET(18549, glVertexAttrib1fvARB, glVertexAttrib1fvARB, NULL, 476), + NAME_FUNC_OFFSET(18567, glVertexAttrib1sARB, glVertexAttrib1sARB, NULL, 477), + NAME_FUNC_OFFSET(18584, glVertexAttrib1svARB, glVertexAttrib1svARB, NULL, 478), + NAME_FUNC_OFFSET(18602, glVertexAttrib2dARB, glVertexAttrib2dARB, NULL, 479), + NAME_FUNC_OFFSET(18619, glVertexAttrib2dvARB, glVertexAttrib2dvARB, NULL, 480), + NAME_FUNC_OFFSET(18637, glVertexAttrib2fARB, glVertexAttrib2fARB, NULL, 481), + NAME_FUNC_OFFSET(18654, glVertexAttrib2fvARB, glVertexAttrib2fvARB, NULL, 482), + NAME_FUNC_OFFSET(18672, glVertexAttrib2sARB, glVertexAttrib2sARB, NULL, 483), + NAME_FUNC_OFFSET(18689, glVertexAttrib2svARB, glVertexAttrib2svARB, NULL, 484), + NAME_FUNC_OFFSET(18707, glVertexAttrib3dARB, glVertexAttrib3dARB, NULL, 485), + NAME_FUNC_OFFSET(18724, glVertexAttrib3dvARB, glVertexAttrib3dvARB, NULL, 486), + NAME_FUNC_OFFSET(18742, glVertexAttrib3fARB, glVertexAttrib3fARB, NULL, 487), + NAME_FUNC_OFFSET(18759, glVertexAttrib3fvARB, glVertexAttrib3fvARB, NULL, 488), + NAME_FUNC_OFFSET(18777, glVertexAttrib3sARB, glVertexAttrib3sARB, NULL, 489), + NAME_FUNC_OFFSET(18794, glVertexAttrib3svARB, glVertexAttrib3svARB, NULL, 490), + NAME_FUNC_OFFSET(18812, glVertexAttrib4NbvARB, glVertexAttrib4NbvARB, NULL, 491), + NAME_FUNC_OFFSET(18831, glVertexAttrib4NivARB, glVertexAttrib4NivARB, NULL, 492), + NAME_FUNC_OFFSET(18850, glVertexAttrib4NsvARB, glVertexAttrib4NsvARB, NULL, 493), + NAME_FUNC_OFFSET(18869, glVertexAttrib4NubARB, glVertexAttrib4NubARB, NULL, 494), + NAME_FUNC_OFFSET(18888, glVertexAttrib4NubvARB, glVertexAttrib4NubvARB, NULL, 495), + NAME_FUNC_OFFSET(18908, glVertexAttrib4NuivARB, glVertexAttrib4NuivARB, NULL, 496), + NAME_FUNC_OFFSET(18928, glVertexAttrib4NusvARB, glVertexAttrib4NusvARB, NULL, 497), + NAME_FUNC_OFFSET(18948, glVertexAttrib4bvARB, glVertexAttrib4bvARB, NULL, 498), + NAME_FUNC_OFFSET(18966, glVertexAttrib4dARB, glVertexAttrib4dARB, NULL, 499), + NAME_FUNC_OFFSET(18983, glVertexAttrib4dvARB, glVertexAttrib4dvARB, NULL, 500), + NAME_FUNC_OFFSET(19001, glVertexAttrib4fARB, glVertexAttrib4fARB, NULL, 501), + NAME_FUNC_OFFSET(19018, glVertexAttrib4fvARB, glVertexAttrib4fvARB, NULL, 502), + NAME_FUNC_OFFSET(19036, glVertexAttrib4ivARB, glVertexAttrib4ivARB, NULL, 503), + NAME_FUNC_OFFSET(19054, glVertexAttrib4sARB, glVertexAttrib4sARB, NULL, 504), + NAME_FUNC_OFFSET(19071, glVertexAttrib4svARB, glVertexAttrib4svARB, NULL, 505), + NAME_FUNC_OFFSET(19089, glVertexAttrib4ubvARB, glVertexAttrib4ubvARB, NULL, 506), + NAME_FUNC_OFFSET(19108, glVertexAttrib4uivARB, glVertexAttrib4uivARB, NULL, 507), + NAME_FUNC_OFFSET(19127, glVertexAttrib4usvARB, glVertexAttrib4usvARB, NULL, 508), + NAME_FUNC_OFFSET(19146, glVertexAttribPointerARB, glVertexAttribPointerARB, NULL, 509), + NAME_FUNC_OFFSET(19168, glBindBufferARB, glBindBufferARB, NULL, 510), + NAME_FUNC_OFFSET(19181, glBufferDataARB, glBufferDataARB, NULL, 511), + NAME_FUNC_OFFSET(19194, glBufferSubDataARB, glBufferSubDataARB, NULL, 512), + NAME_FUNC_OFFSET(19210, glDeleteBuffersARB, glDeleteBuffersARB, NULL, 513), + NAME_FUNC_OFFSET(19226, glGenBuffersARB, glGenBuffersARB, NULL, 514), + NAME_FUNC_OFFSET(19239, glGetBufferParameterivARB, glGetBufferParameterivARB, NULL, 515), + NAME_FUNC_OFFSET(19262, glGetBufferPointervARB, glGetBufferPointervARB, NULL, 516), + NAME_FUNC_OFFSET(19282, glGetBufferSubDataARB, glGetBufferSubDataARB, NULL, 517), + NAME_FUNC_OFFSET(19301, glIsBufferARB, glIsBufferARB, NULL, 518), + NAME_FUNC_OFFSET(19312, glMapBufferARB, glMapBufferARB, NULL, 519), + NAME_FUNC_OFFSET(19324, glUnmapBufferARB, glUnmapBufferARB, NULL, 520), + NAME_FUNC_OFFSET(19338, glBeginQueryARB, glBeginQueryARB, NULL, 521), + NAME_FUNC_OFFSET(19351, glDeleteQueriesARB, glDeleteQueriesARB, NULL, 522), + NAME_FUNC_OFFSET(19367, glEndQueryARB, glEndQueryARB, NULL, 523), + NAME_FUNC_OFFSET(19378, glGenQueriesARB, glGenQueriesARB, NULL, 524), + NAME_FUNC_OFFSET(19391, glGetQueryObjectivARB, glGetQueryObjectivARB, NULL, 525), + NAME_FUNC_OFFSET(19410, glGetQueryObjectuivARB, glGetQueryObjectuivARB, NULL, 526), + NAME_FUNC_OFFSET(19430, glGetQueryivARB, glGetQueryivARB, NULL, 527), + NAME_FUNC_OFFSET(19443, glIsQueryARB, glIsQueryARB, NULL, 528), + NAME_FUNC_OFFSET(19453, glCompileShaderARB, glCompileShaderARB, NULL, 530), + NAME_FUNC_OFFSET(19469, glGetActiveUniformARB, glGetActiveUniformARB, NULL, 535), + NAME_FUNC_OFFSET(19488, glGetShaderSourceARB, glGetShaderSourceARB, NULL, 541), + NAME_FUNC_OFFSET(19506, glGetUniformLocationARB, glGetUniformLocationARB, NULL, 542), + NAME_FUNC_OFFSET(19527, glGetUniformfvARB, glGetUniformfvARB, NULL, 543), + NAME_FUNC_OFFSET(19542, glGetUniformivARB, glGetUniformivARB, NULL, 544), + NAME_FUNC_OFFSET(19557, glLinkProgramARB, glLinkProgramARB, NULL, 545), + NAME_FUNC_OFFSET(19571, glShaderSourceARB, glShaderSourceARB, NULL, 546), + NAME_FUNC_OFFSET(19586, glUniform1fARB, glUniform1fARB, NULL, 547), + NAME_FUNC_OFFSET(19598, glUniform1fvARB, glUniform1fvARB, NULL, 548), + NAME_FUNC_OFFSET(19611, glUniform1iARB, glUniform1iARB, NULL, 549), + NAME_FUNC_OFFSET(19623, glUniform1ivARB, glUniform1ivARB, NULL, 550), + NAME_FUNC_OFFSET(19636, glUniform2fARB, glUniform2fARB, NULL, 551), + NAME_FUNC_OFFSET(19648, glUniform2fvARB, glUniform2fvARB, NULL, 552), + NAME_FUNC_OFFSET(19661, glUniform2iARB, glUniform2iARB, NULL, 553), + NAME_FUNC_OFFSET(19673, glUniform2ivARB, glUniform2ivARB, NULL, 554), + NAME_FUNC_OFFSET(19686, glUniform3fARB, glUniform3fARB, NULL, 555), + NAME_FUNC_OFFSET(19698, glUniform3fvARB, glUniform3fvARB, NULL, 556), + NAME_FUNC_OFFSET(19711, glUniform3iARB, glUniform3iARB, NULL, 557), + NAME_FUNC_OFFSET(19723, glUniform3ivARB, glUniform3ivARB, NULL, 558), + NAME_FUNC_OFFSET(19736, glUniform4fARB, glUniform4fARB, NULL, 559), + NAME_FUNC_OFFSET(19748, glUniform4fvARB, glUniform4fvARB, NULL, 560), + NAME_FUNC_OFFSET(19761, glUniform4iARB, glUniform4iARB, NULL, 561), + NAME_FUNC_OFFSET(19773, glUniform4ivARB, glUniform4ivARB, NULL, 562), + NAME_FUNC_OFFSET(19786, glUniformMatrix2fvARB, glUniformMatrix2fvARB, NULL, 563), + NAME_FUNC_OFFSET(19805, glUniformMatrix3fvARB, glUniformMatrix3fvARB, NULL, 564), + NAME_FUNC_OFFSET(19824, glUniformMatrix4fvARB, glUniformMatrix4fvARB, NULL, 565), + NAME_FUNC_OFFSET(19843, glUseProgramObjectARB, glUseProgramObjectARB, NULL, 566), + NAME_FUNC_OFFSET(19856, glValidateProgramARB, glValidateProgramARB, NULL, 567), + NAME_FUNC_OFFSET(19874, glBindAttribLocationARB, glBindAttribLocationARB, NULL, 568), + NAME_FUNC_OFFSET(19895, glGetActiveAttribARB, glGetActiveAttribARB, NULL, 569), + NAME_FUNC_OFFSET(19913, glGetAttribLocationARB, glGetAttribLocationARB, NULL, 570), + NAME_FUNC_OFFSET(19933, glDrawBuffersARB, glDrawBuffersARB, NULL, 571), + NAME_FUNC_OFFSET(19947, glDrawBuffersARB, glDrawBuffersARB, NULL, 571), + NAME_FUNC_OFFSET(19964, glDrawArraysInstancedARB, glDrawArraysInstancedARB, NULL, 572), + NAME_FUNC_OFFSET(19989, glDrawArraysInstancedARB, glDrawArraysInstancedARB, NULL, 572), + NAME_FUNC_OFFSET(20011, glDrawElementsInstancedARB, glDrawElementsInstancedARB, NULL, 573), + NAME_FUNC_OFFSET(20038, glDrawElementsInstancedARB, glDrawElementsInstancedARB, NULL, 573), + NAME_FUNC_OFFSET(20062, glRenderbufferStorageMultisample, glRenderbufferStorageMultisample, NULL, 574), + NAME_FUNC_OFFSET(20098, gl_dispatch_stub_612, gl_dispatch_stub_612, NULL, 612), + NAME_FUNC_OFFSET(20114, gl_dispatch_stub_613, gl_dispatch_stub_613, NULL, 613), + NAME_FUNC_OFFSET(20133, glPointParameterfEXT, glPointParameterfEXT, NULL, 620), + NAME_FUNC_OFFSET(20151, glPointParameterfEXT, glPointParameterfEXT, NULL, 620), + NAME_FUNC_OFFSET(20172, glPointParameterfEXT, glPointParameterfEXT, NULL, 620), + NAME_FUNC_OFFSET(20194, glPointParameterfvEXT, glPointParameterfvEXT, NULL, 621), + NAME_FUNC_OFFSET(20213, glPointParameterfvEXT, glPointParameterfvEXT, NULL, 621), + NAME_FUNC_OFFSET(20235, glPointParameterfvEXT, glPointParameterfvEXT, NULL, 621), + NAME_FUNC_OFFSET(20258, glSecondaryColor3bEXT, glSecondaryColor3bEXT, NULL, 624), + NAME_FUNC_OFFSET(20277, glSecondaryColor3bvEXT, glSecondaryColor3bvEXT, NULL, 625), + NAME_FUNC_OFFSET(20297, glSecondaryColor3dEXT, glSecondaryColor3dEXT, NULL, 626), + NAME_FUNC_OFFSET(20316, glSecondaryColor3dvEXT, glSecondaryColor3dvEXT, NULL, 627), + NAME_FUNC_OFFSET(20336, glSecondaryColor3fEXT, glSecondaryColor3fEXT, NULL, 628), + NAME_FUNC_OFFSET(20355, glSecondaryColor3fvEXT, glSecondaryColor3fvEXT, NULL, 629), + NAME_FUNC_OFFSET(20375, glSecondaryColor3iEXT, glSecondaryColor3iEXT, NULL, 630), + NAME_FUNC_OFFSET(20394, glSecondaryColor3ivEXT, glSecondaryColor3ivEXT, NULL, 631), + NAME_FUNC_OFFSET(20414, glSecondaryColor3sEXT, glSecondaryColor3sEXT, NULL, 632), + NAME_FUNC_OFFSET(20433, glSecondaryColor3svEXT, glSecondaryColor3svEXT, NULL, 633), + NAME_FUNC_OFFSET(20453, glSecondaryColor3ubEXT, glSecondaryColor3ubEXT, NULL, 634), + NAME_FUNC_OFFSET(20473, glSecondaryColor3ubvEXT, glSecondaryColor3ubvEXT, NULL, 635), + NAME_FUNC_OFFSET(20494, glSecondaryColor3uiEXT, glSecondaryColor3uiEXT, NULL, 636), + NAME_FUNC_OFFSET(20514, glSecondaryColor3uivEXT, glSecondaryColor3uivEXT, NULL, 637), + NAME_FUNC_OFFSET(20535, glSecondaryColor3usEXT, glSecondaryColor3usEXT, NULL, 638), + NAME_FUNC_OFFSET(20555, glSecondaryColor3usvEXT, glSecondaryColor3usvEXT, NULL, 639), + NAME_FUNC_OFFSET(20576, glSecondaryColorPointerEXT, glSecondaryColorPointerEXT, NULL, 640), + NAME_FUNC_OFFSET(20600, glMultiDrawArraysEXT, glMultiDrawArraysEXT, NULL, 641), + NAME_FUNC_OFFSET(20618, glMultiDrawElementsEXT, glMultiDrawElementsEXT, NULL, 642), + NAME_FUNC_OFFSET(20638, glFogCoordPointerEXT, glFogCoordPointerEXT, NULL, 643), + NAME_FUNC_OFFSET(20656, glFogCoorddEXT, glFogCoorddEXT, NULL, 644), + NAME_FUNC_OFFSET(20668, glFogCoorddvEXT, glFogCoorddvEXT, NULL, 645), + NAME_FUNC_OFFSET(20681, glFogCoordfEXT, glFogCoordfEXT, NULL, 646), + NAME_FUNC_OFFSET(20693, glFogCoordfvEXT, glFogCoordfvEXT, NULL, 647), + NAME_FUNC_OFFSET(20706, glBlendFuncSeparateEXT, glBlendFuncSeparateEXT, NULL, 649), + NAME_FUNC_OFFSET(20726, glBlendFuncSeparateEXT, glBlendFuncSeparateEXT, NULL, 649), + NAME_FUNC_OFFSET(20750, glWindowPos2dMESA, glWindowPos2dMESA, NULL, 666), + NAME_FUNC_OFFSET(20764, glWindowPos2dMESA, glWindowPos2dMESA, NULL, 666), + NAME_FUNC_OFFSET(20781, glWindowPos2dvMESA, glWindowPos2dvMESA, NULL, 667), + NAME_FUNC_OFFSET(20796, glWindowPos2dvMESA, glWindowPos2dvMESA, NULL, 667), + NAME_FUNC_OFFSET(20814, glWindowPos2fMESA, glWindowPos2fMESA, NULL, 668), + NAME_FUNC_OFFSET(20828, glWindowPos2fMESA, glWindowPos2fMESA, NULL, 668), + NAME_FUNC_OFFSET(20845, glWindowPos2fvMESA, glWindowPos2fvMESA, NULL, 669), + NAME_FUNC_OFFSET(20860, glWindowPos2fvMESA, glWindowPos2fvMESA, NULL, 669), + NAME_FUNC_OFFSET(20878, glWindowPos2iMESA, glWindowPos2iMESA, NULL, 670), + NAME_FUNC_OFFSET(20892, glWindowPos2iMESA, glWindowPos2iMESA, NULL, 670), + NAME_FUNC_OFFSET(20909, glWindowPos2ivMESA, glWindowPos2ivMESA, NULL, 671), + NAME_FUNC_OFFSET(20924, glWindowPos2ivMESA, glWindowPos2ivMESA, NULL, 671), + NAME_FUNC_OFFSET(20942, glWindowPos2sMESA, glWindowPos2sMESA, NULL, 672), + NAME_FUNC_OFFSET(20956, glWindowPos2sMESA, glWindowPos2sMESA, NULL, 672), + NAME_FUNC_OFFSET(20973, glWindowPos2svMESA, glWindowPos2svMESA, NULL, 673), + NAME_FUNC_OFFSET(20988, glWindowPos2svMESA, glWindowPos2svMESA, NULL, 673), + NAME_FUNC_OFFSET(21006, glWindowPos3dMESA, glWindowPos3dMESA, NULL, 674), + NAME_FUNC_OFFSET(21020, glWindowPos3dMESA, glWindowPos3dMESA, NULL, 674), + NAME_FUNC_OFFSET(21037, glWindowPos3dvMESA, glWindowPos3dvMESA, NULL, 675), + NAME_FUNC_OFFSET(21052, glWindowPos3dvMESA, glWindowPos3dvMESA, NULL, 675), + NAME_FUNC_OFFSET(21070, glWindowPos3fMESA, glWindowPos3fMESA, NULL, 676), + NAME_FUNC_OFFSET(21084, glWindowPos3fMESA, glWindowPos3fMESA, NULL, 676), + NAME_FUNC_OFFSET(21101, glWindowPos3fvMESA, glWindowPos3fvMESA, NULL, 677), + NAME_FUNC_OFFSET(21116, glWindowPos3fvMESA, glWindowPos3fvMESA, NULL, 677), + NAME_FUNC_OFFSET(21134, glWindowPos3iMESA, glWindowPos3iMESA, NULL, 678), + NAME_FUNC_OFFSET(21148, glWindowPos3iMESA, glWindowPos3iMESA, NULL, 678), + NAME_FUNC_OFFSET(21165, glWindowPos3ivMESA, glWindowPos3ivMESA, NULL, 679), + NAME_FUNC_OFFSET(21180, glWindowPos3ivMESA, glWindowPos3ivMESA, NULL, 679), + NAME_FUNC_OFFSET(21198, glWindowPos3sMESA, glWindowPos3sMESA, NULL, 680), + NAME_FUNC_OFFSET(21212, glWindowPos3sMESA, glWindowPos3sMESA, NULL, 680), + NAME_FUNC_OFFSET(21229, glWindowPos3svMESA, glWindowPos3svMESA, NULL, 681), + NAME_FUNC_OFFSET(21244, glWindowPos3svMESA, glWindowPos3svMESA, NULL, 681), + NAME_FUNC_OFFSET(21262, glBindProgramNV, glBindProgramNV, NULL, 700), + NAME_FUNC_OFFSET(21279, glDeleteProgramsNV, glDeleteProgramsNV, NULL, 701), + NAME_FUNC_OFFSET(21299, glGenProgramsNV, glGenProgramsNV, NULL, 703), + NAME_FUNC_OFFSET(21316, glGetVertexAttribPointervNV, glGetVertexAttribPointervNV, NULL, 709), + NAME_FUNC_OFFSET(21342, glGetVertexAttribPointervNV, glGetVertexAttribPointervNV, NULL, 709), + NAME_FUNC_OFFSET(21371, glIsProgramNV, glIsProgramNV, NULL, 713), + NAME_FUNC_OFFSET(21386, glPointParameteriNV, glPointParameteriNV, NULL, 777), + NAME_FUNC_OFFSET(21404, glPointParameterivNV, glPointParameterivNV, NULL, 778), + NAME_FUNC_OFFSET(21423, gl_dispatch_stub_781, gl_dispatch_stub_781, NULL, 781), + NAME_FUNC_OFFSET(21444, gl_dispatch_stub_783, gl_dispatch_stub_783, NULL, 783), + NAME_FUNC_OFFSET(21460, glPrimitiveRestartIndexNV, glPrimitiveRestartIndexNV, NULL, 790), + NAME_FUNC_OFFSET(21484, gl_dispatch_stub_793, gl_dispatch_stub_793, NULL, 793), + NAME_FUNC_OFFSET(21508, gl_dispatch_stub_793, gl_dispatch_stub_793, NULL, 793), + NAME_FUNC_OFFSET(21535, glBindFramebufferEXT, glBindFramebufferEXT, NULL, 794), + NAME_FUNC_OFFSET(21553, glBindRenderbufferEXT, glBindRenderbufferEXT, NULL, 795), + NAME_FUNC_OFFSET(21572, glCheckFramebufferStatusEXT, glCheckFramebufferStatusEXT, NULL, 796), + NAME_FUNC_OFFSET(21597, glDeleteFramebuffersEXT, glDeleteFramebuffersEXT, NULL, 797), + NAME_FUNC_OFFSET(21618, glDeleteRenderbuffersEXT, glDeleteRenderbuffersEXT, NULL, 798), + NAME_FUNC_OFFSET(21640, glFramebufferRenderbufferEXT, glFramebufferRenderbufferEXT, NULL, 799), + NAME_FUNC_OFFSET(21666, glFramebufferTexture1DEXT, glFramebufferTexture1DEXT, NULL, 800), + NAME_FUNC_OFFSET(21689, glFramebufferTexture2DEXT, glFramebufferTexture2DEXT, NULL, 801), + NAME_FUNC_OFFSET(21712, glFramebufferTexture3DEXT, glFramebufferTexture3DEXT, NULL, 802), + NAME_FUNC_OFFSET(21735, glGenFramebuffersEXT, glGenFramebuffersEXT, NULL, 803), + NAME_FUNC_OFFSET(21753, glGenRenderbuffersEXT, glGenRenderbuffersEXT, NULL, 804), + NAME_FUNC_OFFSET(21772, glGenerateMipmapEXT, glGenerateMipmapEXT, NULL, 805), + NAME_FUNC_OFFSET(21789, glGetFramebufferAttachmentParameterivEXT, glGetFramebufferAttachmentParameterivEXT, NULL, 806), + NAME_FUNC_OFFSET(21827, glGetRenderbufferParameterivEXT, glGetRenderbufferParameterivEXT, NULL, 807), + NAME_FUNC_OFFSET(21856, glIsFramebufferEXT, glIsFramebufferEXT, NULL, 808), + NAME_FUNC_OFFSET(21872, glIsRenderbufferEXT, glIsRenderbufferEXT, NULL, 809), + NAME_FUNC_OFFSET(21889, glRenderbufferStorageEXT, glRenderbufferStorageEXT, NULL, 810), + NAME_FUNC_OFFSET(21911, gl_dispatch_stub_811, gl_dispatch_stub_811, NULL, 811), + NAME_FUNC_OFFSET(21929, glBindFragDataLocationEXT, glBindFragDataLocationEXT, NULL, 814), + NAME_FUNC_OFFSET(21952, glGetFragDataLocationEXT, glGetFragDataLocationEXT, NULL, 815), + NAME_FUNC_OFFSET(21974, glGetUniformuivEXT, glGetUniformuivEXT, NULL, 816), + NAME_FUNC_OFFSET(21990, glGetVertexAttribIivEXT, glGetVertexAttribIivEXT, NULL, 817), + NAME_FUNC_OFFSET(22011, glGetVertexAttribIuivEXT, glGetVertexAttribIuivEXT, NULL, 818), + NAME_FUNC_OFFSET(22033, glUniform1uiEXT, glUniform1uiEXT, NULL, 819), + NAME_FUNC_OFFSET(22046, glUniform1uivEXT, glUniform1uivEXT, NULL, 820), + NAME_FUNC_OFFSET(22060, glUniform2uiEXT, glUniform2uiEXT, NULL, 821), + NAME_FUNC_OFFSET(22073, glUniform2uivEXT, glUniform2uivEXT, NULL, 822), + NAME_FUNC_OFFSET(22087, glUniform3uiEXT, glUniform3uiEXT, NULL, 823), + NAME_FUNC_OFFSET(22100, glUniform3uivEXT, glUniform3uivEXT, NULL, 824), + NAME_FUNC_OFFSET(22114, glUniform4uiEXT, glUniform4uiEXT, NULL, 825), + NAME_FUNC_OFFSET(22127, glUniform4uivEXT, glUniform4uivEXT, NULL, 826), + NAME_FUNC_OFFSET(22141, glVertexAttribI1iEXT, glVertexAttribI1iEXT, NULL, 827), + NAME_FUNC_OFFSET(22159, glVertexAttribI1ivEXT, glVertexAttribI1ivEXT, NULL, 828), + NAME_FUNC_OFFSET(22178, glVertexAttribI1uiEXT, glVertexAttribI1uiEXT, NULL, 829), + NAME_FUNC_OFFSET(22197, glVertexAttribI1uivEXT, glVertexAttribI1uivEXT, NULL, 830), + NAME_FUNC_OFFSET(22217, glVertexAttribI2iEXT, glVertexAttribI2iEXT, NULL, 831), + NAME_FUNC_OFFSET(22235, glVertexAttribI2ivEXT, glVertexAttribI2ivEXT, NULL, 832), + NAME_FUNC_OFFSET(22254, glVertexAttribI2uiEXT, glVertexAttribI2uiEXT, NULL, 833), + NAME_FUNC_OFFSET(22273, glVertexAttribI2uivEXT, glVertexAttribI2uivEXT, NULL, 834), + NAME_FUNC_OFFSET(22293, glVertexAttribI3iEXT, glVertexAttribI3iEXT, NULL, 835), + NAME_FUNC_OFFSET(22311, glVertexAttribI3ivEXT, glVertexAttribI3ivEXT, NULL, 836), + NAME_FUNC_OFFSET(22330, glVertexAttribI3uiEXT, glVertexAttribI3uiEXT, NULL, 837), + NAME_FUNC_OFFSET(22349, glVertexAttribI3uivEXT, glVertexAttribI3uivEXT, NULL, 838), + NAME_FUNC_OFFSET(22369, glVertexAttribI4bvEXT, glVertexAttribI4bvEXT, NULL, 839), + NAME_FUNC_OFFSET(22388, glVertexAttribI4iEXT, glVertexAttribI4iEXT, NULL, 840), + NAME_FUNC_OFFSET(22406, glVertexAttribI4ivEXT, glVertexAttribI4ivEXT, NULL, 841), + NAME_FUNC_OFFSET(22425, glVertexAttribI4svEXT, glVertexAttribI4svEXT, NULL, 842), + NAME_FUNC_OFFSET(22444, glVertexAttribI4ubvEXT, glVertexAttribI4ubvEXT, NULL, 843), + NAME_FUNC_OFFSET(22464, glVertexAttribI4uiEXT, glVertexAttribI4uiEXT, NULL, 844), + NAME_FUNC_OFFSET(22483, glVertexAttribI4uivEXT, glVertexAttribI4uivEXT, NULL, 845), + NAME_FUNC_OFFSET(22503, glVertexAttribI4usvEXT, glVertexAttribI4usvEXT, NULL, 846), + NAME_FUNC_OFFSET(22523, glVertexAttribIPointerEXT, glVertexAttribIPointerEXT, NULL, 847), + NAME_FUNC_OFFSET(22546, glFramebufferTextureLayerEXT, glFramebufferTextureLayerEXT, NULL, 848), + NAME_FUNC_OFFSET(22572, glColorMaskIndexedEXT, glColorMaskIndexedEXT, NULL, 849), + NAME_FUNC_OFFSET(22585, glDisableIndexedEXT, glDisableIndexedEXT, NULL, 850), + NAME_FUNC_OFFSET(22596, glEnableIndexedEXT, glEnableIndexedEXT, NULL, 851), + NAME_FUNC_OFFSET(22606, glGetBooleanIndexedvEXT, glGetBooleanIndexedvEXT, NULL, 852), + NAME_FUNC_OFFSET(22622, glGetIntegerIndexedvEXT, glGetIntegerIndexedvEXT, NULL, 853), + NAME_FUNC_OFFSET(22638, glIsEnabledIndexedEXT, glIsEnabledIndexedEXT, NULL, 854), + NAME_FUNC_OFFSET(22651, glGetTexParameterIivEXT, glGetTexParameterIivEXT, NULL, 857), + NAME_FUNC_OFFSET(22672, glGetTexParameterIuivEXT, glGetTexParameterIuivEXT, NULL, 858), + NAME_FUNC_OFFSET(22694, glTexParameterIivEXT, glTexParameterIivEXT, NULL, 859), + NAME_FUNC_OFFSET(22712, glTexParameterIuivEXT, glTexParameterIuivEXT, NULL, 860), + NAME_FUNC_OFFSET(22731, glBeginConditionalRenderNV, glBeginConditionalRenderNV, NULL, 861), + NAME_FUNC_OFFSET(22756, glEndConditionalRenderNV, glEndConditionalRenderNV, NULL, 862), + NAME_FUNC_OFFSET(22779, glBeginTransformFeedbackEXT, glBeginTransformFeedbackEXT, NULL, 863), + NAME_FUNC_OFFSET(22804, glBindBufferBaseEXT, glBindBufferBaseEXT, NULL, 864), + NAME_FUNC_OFFSET(22821, glBindBufferRangeEXT, glBindBufferRangeEXT, NULL, 866), + NAME_FUNC_OFFSET(22839, glEndTransformFeedbackEXT, glEndTransformFeedbackEXT, NULL, 867), + NAME_FUNC_OFFSET(22862, glGetTransformFeedbackVaryingEXT, glGetTransformFeedbackVaryingEXT, NULL, 868), + NAME_FUNC_OFFSET(22892, glTransformFeedbackVaryingsEXT, glTransformFeedbackVaryingsEXT, NULL, 869), + NAME_FUNC_OFFSET(22920, glProvokingVertexEXT, glProvokingVertexEXT, NULL, 870), + NAME_FUNC_OFFSET(-1, NULL, NULL, NULL, 0) +}; + +#undef NAME_FUNC_OFFSET diff --git a/src/mapi/glapi/glthread.c b/src/mapi/glapi/glthread.c new file mode 100644 index 0000000..0091538 --- /dev/null +++ b/src/mapi/glapi/glthread.c @@ -0,0 +1,7 @@ +#include "glapi/glapi.h" + +unsigned long +_glthread_GetID(void) +{ + return u_thread_self(); +} diff --git a/src/mapi/glapi/glthread.h b/src/mapi/glapi/glthread.h new file mode 100644 index 0000000..fc4ece7 --- /dev/null +++ b/src/mapi/glapi/glthread.h @@ -0,0 +1,20 @@ +#ifndef GLTHREAD_H +#define GLTHREAD_H + +#include "mapi/u_thread.h" + +#define _glthread_DECLARE_STATIC_MUTEX(name) u_mutex_declare_static(name) +#define _glthread_INIT_MUTEX(name) u_mutex_init(name) +#define _glthread_DESTROY_MUTEX(name) u_mutex_destroy(name) +#define _glthread_LOCK_MUTEX(name) u_mutex_lock(name) +#define _glthread_UNLOCK_MUTEX(name) u_mutex_unlock(name) + +#define _glthread_InitTSD(tsd) u_tsd_init(tsd); +#define _glthread_DestroyTSD(tsd) u_tsd_destroy(tsd); +#define _glthread_GetTSD(tsd) u_tsd_get(tsd); +#define _glthread_SetTSD(tsd, ptr) u_tsd_set(tsd, ptr); + +typedef struct u_tsd _glthread_TSD; +typedef u_mutex _glthread_Mutex; + +#endif /* GLTHREAD_H */ diff --git a/src/mapi/glapi/sources.mak b/src/mapi/glapi/sources.mak new file mode 100644 index 0000000..cdcfa36 --- /dev/null +++ b/src/mapi/glapi/sources.mak @@ -0,0 +1,17 @@ +# src/mapi/glapi/sources.mak + +GLAPI_SOURCES = \ + glapi_dispatch.c \ + glapi_entrypoint.c \ + glapi_getproc.c \ + glapi_nop.c \ + glthread.c + +X86_API = \ + glapi_x86.S + +X86-64_API = \ + glapi_x86-64.S + +SPARC_API = \ + glapi_sparc.S diff --git a/src/mapi/mapi/entry.c b/src/mapi/mapi/entry.c new file mode 100644 index 0000000..fdf2a89 --- /dev/null +++ b/src/mapi/mapi/entry.c @@ -0,0 +1,65 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "entry.h" + +#if defined(USE_X86_ASM) && defined(__GNUC__) +# ifdef GLX_USE_TLS +# include "entry_x86_tls.h" +# else +# include "entry_x86_tsd.h" +# endif +#elif defined(USE_X86_64_ASM) && defined(__GNUC__) && defined(GLX_USE_TLS) +# include "entry_x86-64_tls.h" +#else + +#include +#include "u_current.h" +#include "table.h" + +/* C version of the public entries */ +#define MAPI_TMP_PUBLIC_ENTRIES +#include "mapi_tmp.h" + +void +entry_patch_public(void) +{ +} + +mapi_func +entry_generate(int slot) +{ + return NULL; +} + +void +entry_patch(mapi_func entry, int slot) +{ +} + +#endif /* asm */ diff --git a/src/mapi/mapi/entry.h b/src/mapi/mapi/entry.h new file mode 100644 index 0000000..48ed3f9 --- /dev/null +++ b/src/mapi/mapi/entry.h @@ -0,0 +1,49 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _ENTRY_H_ +#define _ENTRY_H_ + +#include "u_compiler.h" +#include "stub.h" + +/* declare public entries */ +#define MAPI_TMP_DEFINES +#define MAPI_TMP_PUBLIC_DECLARES +#include "mapi_tmp.h" + +void +entry_patch_public(void); + +mapi_func +entry_generate(int slot); + +void +entry_patch(mapi_func entry, int slot); + +#endif /* _ENTRY_H_ */ diff --git a/src/mapi/mapi/entry_x86-64_tls.h b/src/mapi/mapi/entry_x86-64_tls.h new file mode 100644 index 0000000..2fbe73b --- /dev/null +++ b/src/mapi/mapi/entry_x86-64_tls.h @@ -0,0 +1,97 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include +#include "u_execmem.h" +#include "u_macros.h" + +__asm__(".text"); + +__asm__("x86_64_current_tls:\n\t" + "movq u_current_table_tls@GOTTPOFF(%rip), %rax\n\t" + "ret"); + +#define STUB_ASM_ENTRY(func) \ + ".globl " func "\n" \ + ".type " func ", @function\n" \ + ".balign 32\n" \ + func ":" + +#define STUB_ASM_CODE(slot) \ + "movq u_current_table_tls@GOTTPOFF(%rip), %rax\n\t" \ + "movq %fs:(%rax), %r11\n\t" \ + "jmp *(8 * " slot ")(%r11)" + +#define MAPI_TMP_STUB_ASM_GCC +#include "mapi_tmp.h" + +extern unsigned long +x86_64_current_tls(); + +void +entry_patch_public(void) +{ +} + +void +entry_patch(mapi_func entry, int slot) +{ + char *code = (char *) entry; + *((unsigned int *) (code + 12)) = slot * sizeof(mapi_func); +} + +mapi_func +entry_generate(int slot) +{ + const char code_templ[16] = { + /* movq %fs:0, %r11 */ + 0x64, 0x4c, 0x8b, 0x1c, 0x25, 0x00, 0x00, 0x00, 0x00, + /* jmp *0x1234(%r11) */ + 0x41, 0xff, 0xa3, 0x34, 0x12, 0x00, 0x00, + }; + unsigned long addr; + void *code; + mapi_func entry; + + addr = x86_64_current_tls(); + if ((addr >> 32) != 0xffffffff) + return NULL; + addr &= 0xffffffff; + + code = u_execmem_alloc(sizeof(code_templ)); + if (!code) + return NULL; + + memcpy(code, code_templ, sizeof(code_templ)); + + *((unsigned int *) (code + 5)) = addr; + entry = (mapi_func) code; + entry_patch(entry, slot); + + return entry; +} diff --git a/src/mapi/mapi/entry_x86_tls.h b/src/mapi/mapi/entry_x86_tls.h new file mode 100644 index 0000000..d4f7d98 --- /dev/null +++ b/src/mapi/mapi/entry_x86_tls.h @@ -0,0 +1,120 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include +#include "u_execmem.h" +#include "u_macros.h" + +__asm__(".text"); + +__asm__("x86_current_tls:\n\t" + "call 1f\n" + "1:\n\t" + "popl %eax\n\t" + "addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax\n\t" + "movl u_current_table_tls@GOTNTPOFF(%eax), %eax\n\t" + "ret"); + +#ifndef GLX_X86_READONLY_TEXT +__asm__(".section wtext, \"awx\", @progbits\n" + ".balign 16\n" + "x86_entry_start:"); +#endif /* GLX_X86_READONLY_TEXT */ + +#define STUB_ASM_ENTRY(func) \ + ".globl " func "\n" \ + ".type " func ", @function\n" \ + ".balign 16\n" \ + func ":" + +#define STUB_ASM_CODE(slot) \ + "call x86_current_tls\n\t" \ + "movl %gs:(%eax), %eax\n\t" \ + "jmp *(4 * " slot ")(%eax)" + +#define MAPI_TMP_STUB_ASM_GCC +#include "mapi_tmp.h" + +#ifndef GLX_X86_READONLY_TEXT +__asm__(".balign 16\n" + "x86_entry_end:"); +__asm__(".text"); +#endif /* GLX_X86_READONLY_TEXT */ + +extern unsigned long +x86_current_tls(); + +void +entry_patch_public(void) +{ +#ifndef GLX_X86_READONLY_TEXT + extern char x86_entry_start[]; + extern char x86_entry_end[]; + char patch[8] = { + 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, /* movl %gs:0x0, %eax */ + 0x90, 0x90 /* nop's */ + }; + char *entry; + + *((unsigned long *) (patch + 2)) = x86_current_tls(); + + for (entry = x86_entry_start; entry < x86_entry_end; entry += 16) + memcpy(entry, patch, sizeof(patch)); +#endif +} + +void +entry_patch(mapi_func entry, int slot) +{ + char *code = (char *) entry; + *((unsigned long *) (code + 8)) = slot * sizeof(mapi_func); +} + +mapi_func +entry_generate(int slot) +{ + const char code_templ[16] = { + 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, /* movl %gs:0x0, %eax */ + 0xff, 0xa0, 0x34, 0x12, 0x00, 0x00, /* jmp *0x1234(%eax) */ + 0x90, 0x90, 0x90, 0x90 /* nop's */ + }; + void *code; + mapi_func entry; + + code = u_execmem_alloc(sizeof(code_templ)); + if (!code) + return NULL; + + memcpy(code, code_templ, sizeof(code_templ)); + + *((unsigned long *) (code + 2)) = x86_current_tls(); + entry = (mapi_func) code; + entry_patch(entry, slot); + + return entry; +} diff --git a/src/mapi/mapi/entry_x86_tsd.h b/src/mapi/mapi/entry_x86_tsd.h new file mode 100644 index 0000000..f37c747 --- /dev/null +++ b/src/mapi/mapi/entry_x86_tsd.h @@ -0,0 +1,89 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include +#include "u_execmem.h" +#include "u_macros.h" + +#define X86_ENTRY_SIZE 32 + +__asm__(".text"); + +#define STUB_ASM_ENTRY(func) \ + ".globl " func "\n" \ + ".type " func ", @function\n" \ + ".balign 32\n" \ + func ":" + +#define STUB_ASM_CODE(slot) \ + "movl u_current_table, %eax\n\t" \ + "testl %eax, %eax\n\t" \ + "je 1f\n\t" \ + "jmp *(4 * " slot ")(%eax)\n" \ + "1:\n\t" \ + "call u_current_get_internal\n\t"\ + "jmp *(4 * " slot ")(%eax)" + +#define MAPI_TMP_STUB_ASM_GCC +#include "mapi_tmp.h" + +__asm__(".balign 32\n" + "x86_entry_end:"); + +void +entry_patch_public(void) +{ +} + +void +entry_patch(mapi_func entry, int slot) +{ + char *code = (char *) entry; + + *((unsigned long *) (code + 11)) = slot * sizeof(mapi_func); + *((unsigned long *) (code + 22)) = slot * sizeof(mapi_func); +} + +mapi_func +entry_generate(int slot) +{ + extern const char x86_entry_end[]; + const char *code_templ = x86_entry_end - X86_ENTRY_SIZE; + void *code; + mapi_func entry; + + code = u_execmem_alloc(X86_ENTRY_SIZE); + if (!code) + return NULL; + + memcpy(code, code_templ, X86_ENTRY_SIZE); + entry = (mapi_func) code; + entry_patch(entry, slot); + + return entry; +} diff --git a/src/mapi/mapi/mapi.c b/src/mapi/mapi/mapi.c new file mode 100644 index 0000000..5476d37 --- /dev/null +++ b/src/mapi/mapi/mapi.c @@ -0,0 +1,190 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include +#include + +#include "u_current.h" +#include "u_thread.h" +#include "mapi.h" +#include "stub.h" +#include "table.h" + +/* dynamic stubs will run out before this array */ +static const struct mapi_stub *mapi_stub_map[MAPI_TABLE_NUM_SLOTS]; +static int mapi_num_stubs; + +static const struct mapi_stub * +get_stub(const char *name, const struct mapi_stub *alias) +{ + const struct mapi_stub *stub; + + stub = stub_find_public(name); + if (!stub) { + struct mapi_stub *dyn = stub_find_dynamic(name, 1); + if (dyn) { + stub_fix_dynamic(dyn, alias); + stub = dyn; + } + } + + return stub; +} + +/** + * Initialize mapi. spec consists of NULL-separated strings. The first string + * denotes the version. It is followed by variable numbers of entries. Each + * entry can have multiple names. An empty name terminates an entry. An empty + * entry terminates the spec. A spec of two entries, Foo and Bar, is as + * follows + * + * "1\0" + * "Foo\0" + * "FooEXT\0" + * "\0" + * "Bar\0" + * "\0" + */ +void +mapi_init(const char *spec) +{ + u_mutex_declare_static(mutex); + const char *p; + int ver, count; + + u_mutex_lock(mutex); + + /* already initialized */ + if (mapi_num_stubs) { + u_mutex_unlock(mutex); + return; + } + + count = 0; + p = spec; + + /* parse version string */ + ver = atoi(p); + if (ver != 1) { + u_mutex_unlock(mutex); + return; + } + p += strlen(p) + 1; + + while (*p) { + const struct mapi_stub *stub; + + stub = get_stub(p, NULL); + /* out of dynamic entries */ + if (!stub) + break; + p += strlen(p) + 1; + + while (*p) { + get_stub(p, stub); + p += strlen(p) + 1; + } + + mapi_stub_map[count++] = stub; + p++; + } + + mapi_num_stubs = count; + + u_mutex_unlock(mutex); +} + +/** + * Return the address of an entry. Optionally generate the entry if it does + * not exist. + */ +mapi_proc +mapi_get_proc_address(const char *name) +{ + const struct mapi_stub *stub; + + stub = stub_find_public(name); + if (!stub) + stub = stub_find_dynamic(name, 0); + + return (stub) ? (mapi_proc) stub->addr : NULL; +} + +/** + * Create a dispatch table. + */ +struct mapi_table * +mapi_table_create(void) +{ + const struct mapi_table *noop = table_get_noop(); + struct mapi_table *tbl; + + tbl = malloc(MAPI_TABLE_SIZE); + if (tbl) + memcpy(tbl, noop, MAPI_TABLE_SIZE); + + return tbl; +} + +/** + * Destroy a dispatch table. + */ +void +mapi_table_destroy(struct mapi_table *tbl) +{ + free(tbl); +} + +/** + * Fill a dispatch table. The order of the procs is determined when mapi_init + * is called. + */ +void +mapi_table_fill(struct mapi_table *tbl, const mapi_proc *procs) +{ + const struct mapi_table *noop = table_get_noop(); + int i; + + for (i = 0; i < mapi_num_stubs; i++) { + const struct mapi_stub *stub = mapi_stub_map[i]; + mapi_func func = (mapi_func) procs[i]; + + if (!func) + func = table_get_func(noop, stub); + table_set_func(tbl, stub, func); + } +} + +/** + * Make a dispatch table current. + */ +void +mapi_table_make_current(const struct mapi_table *tbl) +{ + u_current_set(tbl); +} diff --git a/src/mapi/mapi/mapi.h b/src/mapi/mapi/mapi.h new file mode 100644 index 0000000..c7e43e2 --- /dev/null +++ b/src/mapi/mapi/mapi.h @@ -0,0 +1,66 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _MAPI_H_ +#define _MAPI_H_ + +#include "u_compiler.h" + +#ifdef _WIN32 +#ifdef MAPI_DLL_EXPORTS +#define MAPI_EXPORT __declspec(dllexport) +#else +#define MAPI_EXPORT __declspec(dllimport) +#endif +#else /* _WIN32 */ +#define MAPI_EXPORT PUBLIC +#endif + +typedef void (*mapi_proc)(void); + +struct mapi_table; + +MAPI_EXPORT void +mapi_init(const char *spec); + +MAPI_EXPORT mapi_proc +mapi_get_proc_address(const char *name); + +MAPI_EXPORT struct mapi_table * +mapi_table_create(void); + +MAPI_EXPORT void +mapi_table_destroy(struct mapi_table *tbl); + +MAPI_EXPORT void +mapi_table_fill(struct mapi_table *tbl, const mapi_proc *procs); + +MAPI_EXPORT void +mapi_table_make_current(const struct mapi_table *tbl); + +#endif /* _MAPI_H_ */ diff --git a/src/mapi/mapi/mapi_abi.py b/src/mapi/mapi/mapi_abi.py new file mode 100644 index 0000000..3a87266 --- /dev/null +++ b/src/mapi/mapi/mapi_abi.py @@ -0,0 +1,561 @@ +#!/usr/bin/env python + +# Mesa 3-D graphics library +# Version: 7.9 +# +# Copyright (C) 2010 LunarG Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# +# Authors: +# Chia-I Wu + +import sys +import re +from optparse import OptionParser + +# number of dynamic entries +ABI_NUM_DYNAMIC_ENTRIES = 256 + +class ABIEntry(object): + """Represent an ABI entry.""" + + _match_c_param = re.compile( + '^(?P[\w\s*]+?)(?P\w+)(\[(?P\d+)\])?$') + + def __init__(self, cols, attrs): + self._parse(cols) + + self.slot = attrs['slot'] + self.hidden = attrs['hidden'] + self.alias = attrs['alias'] + + def c_prototype(self): + return '%s %s(%s)' % (self.c_return(), self.name, self.c_params()) + + def c_return(self): + ret = self.ret + if not ret: + ret = 'void' + + return ret + + def c_params(self): + """Return the parameter list used in the entry prototype.""" + c_params = [] + for t, n, a in self.params: + sep = '' if t.endswith('*') else ' ' + arr = '[%d]' % a if a else '' + c_params.append(t + sep + n + arr) + if not c_params: + c_params.append('void') + + return ", ".join(c_params) + + def c_args(self): + """Return the argument list used in the entry invocation.""" + c_args = [] + for t, n, a in self.params: + c_args.append(n) + + return ", ".join(c_args) + + def _parse(self, cols): + ret = cols.pop(0) + if ret == 'void': + ret = None + + name = cols.pop(0) + + params = [] + if not cols: + raise Exception(cols) + elif len(cols) == 1 and cols[0] == 'void': + pass + else: + for val in cols: + params.append(self._parse_param(val)) + + self.ret = ret + self.name = name + self.params = params + + def _parse_param(self, c_param): + m = self._match_c_param.match(c_param) + if not m: + raise Exception('unrecognized param ' + c_param) + + c_type = m.group('type').strip() + c_name = m.group('name') + c_array = m.group('array') + c_array = int(c_array) if c_array else 0 + + return (c_type, c_name, c_array) + + def __str__(self): + return self.c_prototype() + + def __cmp__(self, other): + # compare slot, alias, and then name + res = cmp(self.slot, other.slot) + if not res: + if not self.alias: + res = -1 + elif not other.alias: + res = 1 + + if not res: + res = cmp(self.name, other.name) + + return res + +def abi_parse_line(line): + cols = [col.strip() for col in line.split(',')] + + attrs = { + 'slot': -1, + 'hidden': False, + 'alias': None, + } + + # extract attributes from the first column + vals = cols[0].split(':') + while len(vals) > 1: + val = vals.pop(0) + if val.startswith('slot='): + attrs['slot'] = int(val[5:]) + elif val == 'hidden': + attrs['hidden'] = True + elif val.startswith('alias='): + attrs['alias'] = val[6:] + elif not val: + pass + else: + raise Exception('unknown attribute %s' % val) + cols[0] = vals[0] + + return (attrs, cols) + +def abi_parse(filename): + """Parse a CSV file for ABI entries.""" + fp = open(filename) if filename != '-' else sys.stdin + lines = [line.strip() for line in fp.readlines() + if not line.startswith('#') and line.strip()] + + entry_dict = {} + next_slot = 0 + for line in lines: + attrs, cols = abi_parse_line(line) + + # post-process attributes + if attrs['alias']: + try: + ent = entry_dict[attrs['alias']] + slot = ent.slot + except KeyError: + raise Exception('failed to alias %s' % attrs['alias']) + else: + slot = next_slot + next_slot += 1 + + if attrs['slot'] < 0: + attrs['slot'] = slot + elif attrs['slot'] != slot: + raise Exception('invalid slot in %s' % (line)) + + ent = ABIEntry(cols, attrs) + if entry_dict.has_key(ent.name): + raise Exception('%s is duplicated' % (ent.name)) + entry_dict[ent.name] = ent + + entries = entry_dict.values() + entries.sort() + + # sanity check + i = 0 + for slot in xrange(next_slot): + if entries[i].slot != slot: + raise Exception('entries are not ordered by slots') + if entries[i].alias: + raise Exception('first entry of slot %d aliases %s' + % (slot, entries[i].alias)) + while i < len(entries) and entries[i].slot == slot: + i += 1 + if i < len(entries): + raise Exception('there are %d invalid entries' % (len(entries) - 1)) + + return entries + +class ABIPrinter(object): + """MAPI Printer""" + + def __init__(self, entries): + self.entries = entries + + # sort entries by their names + self.entries_sorted_by_names = self.entries[:] + self.entries_sorted_by_names.sort(lambda x, y: cmp(x.name, y.name)) + + self.indent = ' ' * 3 + self.noop_warn = 'noop_warn' + self.noop_generic = 'noop_generic' + + self.api_defines = [] + self.api_headers = ['"KHR/khrplatform.h"'] + self.api_call = 'KHRONOS_APICALL' + self.api_entry = 'KHRONOS_APIENTRY' + self.api_attrs = 'KHRONOS_APIATTRIBUTES' + + def c_header(self): + return '/* This file is automatically generated by mapi_abi.py. Do not modify. */' + + def c_includes(self): + """Return includes of the client API headers.""" + defines = ['#define ' + d for d in self.api_defines] + includes = ['#include ' + h for h in self.api_headers] + return "\n".join(defines + includes) + + def c_mapi_table(self): + """Return defines of the dispatch table size.""" + num_static_entries = 0 + for ent in self.entries: + if not ent.alias: + num_static_entries += 1 + + return ('#define MAPI_TABLE_NUM_STATIC %d\n' + \ + '#define MAPI_TABLE_NUM_DYNAMIC %d') % ( + num_static_entries, ABI_NUM_DYNAMIC_ENTRIES) + + def c_mapi_table_initializer(self, prefix): + """Return the array initializer for mapi_table_fill.""" + entries = [ent.name for ent in self.entries if not ent.alias] + pre = self.indent + '(mapi_proc) ' + prefix + return pre + (',\n' + pre).join(entries) + + def c_mapi_table_spec(self): + """Return the spec for mapi_init.""" + specv1 = [] + line = '"1' + for ent in self.entries: + if not ent.alias: + line += '\\0"\n' + specv1.append(line) + line = '"' + line += '%s\\0' % ent.name + line += '";' + specv1.append(line) + + return self.indent + self.indent.join(specv1) + + def _c_decl(self, ent, prefix, need_attr=True): + """Return the C declaration for the entry.""" + decl = '%s %s %s%s(%s)' % (ent.c_return(), self.api_entry, + prefix, ent.name, ent.c_params()) + if need_attr and self.api_attrs: + decl += ' ' + self.api_attrs + + return decl + + def _c_cast(self, ent): + """Return the C cast for the entry.""" + cast = '%s (%s *)(%s)' % ( + ent.c_return(), self.api_entry, ent.c_params()) + + return cast + + def c_private_declarations(self, prefix): + """Return the declarations of private functions.""" + decls = [self._c_decl(ent, prefix) + for ent in self.entries if not ent.alias] + + return ";\n".join(decls) + ";" + + def c_public_dispatches(self, prefix): + """Return the public dispatch functions.""" + dispatches = [] + for ent in self.entries: + if ent.hidden: + continue + + proto = self.api_call + ' ' + self._c_decl(ent, prefix) + cast = self._c_cast(ent) + + ret = '' + if ent.ret: + ret = 'return ' + stmt1 = self.indent + stmt1 += 'const struct mapi_table *tbl = u_current_get();' + stmt2 = self.indent + stmt2 += 'mapi_func func = ((const mapi_func *) tbl)[%d];' % ( + ent.slot) + stmt3 = self.indent + stmt3 += '%s((%s) func)(%s);' % (ret, cast, ent.c_args()) + + disp = '%s\n{\n%s\n%s\n%s\n}' % (proto, stmt1, stmt2, stmt3) + dispatches.append(disp) + + return '\n\n'.join(dispatches) + + def c_stub_string_pool(self): + """Return the string pool for use by stubs.""" + # sort entries by their names + sorted_entries = self.entries[:] + sorted_entries.sort(lambda x, y: cmp(x.name, y.name)) + + pool = [] + offsets = {} + count = 0 + for ent in sorted_entries: + offsets[ent] = count + pool.append('%s' % (ent.name)) + count += len(ent.name) + 1 + + pool_str = self.indent + '"' + \ + ('\\0"\n' + self.indent + '"').join(pool) + '";' + return (pool_str, offsets) + + def c_stub_initializer(self, prefix, pool_offsets): + """Return the initializer for struct mapi_stub array.""" + stubs = [] + for ent in self.entries_sorted_by_names: + stubs.append('%s{ (mapi_func) %s%s, %d, (void *) %d }' % ( + self.indent, prefix, ent.name, ent.slot, pool_offsets[ent])) + + return ',\n'.join(stubs) + + def c_noop_functions(self, prefix, warn_prefix): + """Return the noop functions.""" + noops = [] + for ent in self.entries: + if ent.alias: + continue + + proto = 'static ' + self._c_decl(ent, prefix) + + stmt1 = self.indent + '%s("%s%s");' % ( + self.noop_warn, warn_prefix, ent.name) + + if ent.ret: + stmt2 = self.indent + 'return (%s) 0;' % (ent.ret) + noop = '%s\n{\n%s\n%s\n}' % (proto, stmt1, stmt2) + else: + noop = '%s\n{\n%s\n}' % (proto, stmt1) + + noops.append(noop) + + return '\n\n'.join(noops) + + def c_noop_initializer(self, prefix, use_generic): + """Return an initializer for the noop dispatch table.""" + entries = [prefix + ent.name for ent in self.entries if not ent.alias] + if use_generic: + entries = [self.noop_generic] * len(entries) + + entries.extend([self.noop_generic] * ABI_NUM_DYNAMIC_ENTRIES) + + pre = self.indent + '(mapi_func) ' + return pre + (',\n' + pre).join(entries) + + def c_asm_gcc(self, prefix): + asm = [] + to_name = None + + asm.append('__asm__(') + for ent in self.entries: + name = prefix + ent.name + + if ent.hidden: + asm.append('".hidden %s\\n"' % (name)) + + if ent.alias: + asm.append('".globl %s\\n"' % (name)) + asm.append('".set %s, %s\\n"' % (name, to_name)) + else: + asm.append('STUB_ASM_ENTRY("%s")"\\n"' % (name)) + asm.append('"\\t"STUB_ASM_CODE("%d")"\\n"' % (ent.slot)) + to_name = name + asm.append(');') + + return "\n".join(asm) + + def output_for_lib(self): + print self.c_header() + print + print '#ifdef MAPI_TMP_DEFINES' + print self.c_includes() + print '#undef MAPI_TMP_DEFINES' + print '#endif /* MAPI_TMP_DEFINES */' + print + print '#ifdef MAPI_TMP_TABLE' + print self.c_mapi_table() + print '#undef MAPI_TMP_TABLE' + print '#endif /* MAPI_TMP_TABLE */' + print + + pool, pool_offsets = self.c_stub_string_pool() + print '#ifdef MAPI_TMP_PUBLIC_STUBS' + print 'static const char public_string_pool[] =' + print pool + print + print 'static const struct mapi_stub public_stubs[] = {' + print self.c_stub_initializer(self.prefix_lib, pool_offsets) + print '};' + print '#undef MAPI_TMP_PUBLIC_STUBS' + print '#endif /* MAPI_TMP_PUBLIC_STUBS */' + print + + print '#ifdef MAPI_TMP_PUBLIC_ENTRIES' + print self.c_public_dispatches(self.prefix_lib) + print '#undef MAPI_TMP_PUBLIC_ENTRIES' + print '#endif /* MAPI_TMP_PUBLIC_ENTRIES */' + print + + print '#ifdef MAPI_TMP_NOOP_ARRAY' + print '#ifdef DEBUG' + print + print self.c_noop_functions(self.prefix_noop, self.prefix_lib) + print + print 'const mapi_func table_%s_array[] = {' % (self.prefix_noop) + print self.c_noop_initializer(self.prefix_noop, False) + print '};' + print + print '#else /* DEBUG */' + print + print 'const mapi_func table_%s_array[] = {' % (self.prefix_noop) + print self.c_noop_initializer(self.prefix_noop, True) + print '};' + print '#endif /* DEBUG */' + print '#undef MAPI_TMP_NOOP_ARRAY' + print '#endif /* MAPI_TMP_NOOP_ARRAY */' + print + + print '#ifdef MAPI_TMP_STUB_ASM_GCC' + print self.c_asm_gcc(self.prefix_lib) + print '#undef MAPI_TMP_STUB_ASM_GCC' + print '#endif /* MAPI_TMP_STUB_ASM_GCC */' + + def output_for_app(self): + print self.c_header() + print + print self.c_private_declarations(self.prefix_app) + print + print '#ifdef API_TMP_DEFINE_SPEC' + print + print 'static const char %s_spec[] =' % (self.prefix_app) + print self.c_mapi_table_spec() + print + print 'static const mapi_proc %s_procs[] = {' % (self.prefix_app) + print self.c_mapi_table_initializer(self.prefix_app) + print '};' + print + print '#endif /* API_TMP_DEFINE_SPEC */' + +class GLAPIPrinter(ABIPrinter): + """OpenGL API Printer""" + + def __init__(self, entries): + super(GLAPIPrinter, self).__init__(entries) + + self.api_defines = ['GL_GLEXT_PROTOTYPES'] + self.api_headers = ['"GL/gl.h"', '"GL/glext.h"'] + self.api_call = 'GLAPI' + self.api_entry = 'APIENTRY' + self.api_attrs = '' + + self.prefix_lib = 'gl' + self.prefix_app = '_mesa_' + self.prefix_noop = 'noop' + + def output_for_app(self): + # not used + pass + +class ES1APIPrinter(GLAPIPrinter): + """OpenGL ES 1.x API Printer""" + + def __init__(self, entries): + super(ES1APIPrinter, self).__init__(entries) + + self.api_headers = ['"GLES/gl.h"', '"GLES/glext.h"'] + self.api_call = 'GL_API' + self.api_entry = 'GL_APIENTRY' + +class ES2APIPrinter(GLAPIPrinter): + """OpenGL ES 2.x API Printer""" + + def __init__(self, entries): + super(ES2APIPrinter, self).__init__(entries) + + self.api_headers = ['"GLES2/gl2.h"', '"GLES2/gl2ext.h"'] + self.api_call = 'GL_APICALL' + self.api_entry = 'GL_APIENTRY' + +class VGAPIPrinter(ABIPrinter): + """OpenVG API Printer""" + + def __init__(self, entries): + super(VGAPIPrinter, self).__init__(entries) + + self.api_defines = ['VG_VGEXT_PROTOTYPES'] + self.api_headers = ['"VG/openvg.h"', '"VG/vgext.h"'] + self.api_call = 'VG_API_CALL' + self.api_entry = 'VG_API_ENTRY' + self.api_attrs = 'VG_API_EXIT' + + self.prefix_lib = 'vg' + self.prefix_app = 'vega' + self.prefix_noop = 'noop' + +def parse_args(): + printers = ['glapi', 'es1api', 'es2api', 'vgapi'] + modes = ['lib', 'app'] + + parser = OptionParser(usage='usage: %prog [options] ') + parser.add_option('-p', '--printer', dest='printer', + help='printer to use: %s' % (", ".join(printers))) + parser.add_option('-m', '--mode', dest='mode', + help='target user: %s' % (", ".join(modes))) + + options, args = parser.parse_args() + if not args or options.printer not in printers or \ + options.mode not in modes: + parser.print_help() + sys.exit(1) + + return (args[0], options) + +def main(): + printers = { + 'vgapi': VGAPIPrinter, + 'glapi': GLAPIPrinter, + 'es1api': ES1APIPrinter, + 'es2api': ES2APIPrinter + } + + filename, options = parse_args() + + entries = abi_parse(filename) + printer = printers[options.printer](entries) + if options.mode == 'lib': + printer.output_for_lib() + else: + printer.output_for_app() + +if __name__ == '__main__': + main() diff --git a/src/mapi/mapi/mapi_tmp.h b/src/mapi/mapi/mapi_tmp.h new file mode 100644 index 0000000..a1b067f --- /dev/null +++ b/src/mapi/mapi/mapi_tmp.h @@ -0,0 +1,33 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef MAPI_ABI_HEADER +#error "MAPI_ABI_HEADER must be defined" +#endif + +#include MAPI_ABI_HEADER diff --git a/src/mapi/mapi/sources.mak b/src/mapi/mapi/sources.mak new file mode 100644 index 0000000..5f327f3 --- /dev/null +++ b/src/mapi/mapi/sources.mak @@ -0,0 +1,19 @@ +# src/mapi/mapi/sources.mak +# +# When MAPI_GLAPI_CURRENT is defined, MAPI_GLAPI_SOURCES can be built without +# MAPI_SOURCES and it is used by glapi. +# +# Otherwise, MAPI_ABI_HEADER must be defined. It should expand to the header +# generated by mapi_abi.py. + +MAPI_GLAPI_SOURCES = \ + u_current.c \ + u_execmem.c \ + u_thread.c + +MAPI_SOURCES = \ + entry.c \ + mapi.c \ + stub.c \ + table.c \ + $(MAPI_GLAPI_SOURCES) diff --git a/src/mapi/mapi/stub.c b/src/mapi/mapi/stub.c new file mode 100644 index 0000000..3594eac --- /dev/null +++ b/src/mapi/mapi/stub.c @@ -0,0 +1,166 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include +#include /* for offsetof */ +#include +#include + +#include "u_current.h" +#include "u_thread.h" +#include "entry.h" +#include "stub.h" +#include "table.h" + +#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) + +/* define public_string_pool and public_stubs */ +#define MAPI_TMP_PUBLIC_STUBS +#include "mapi_tmp.h" + +static struct mapi_stub dynamic_stubs[MAPI_TABLE_NUM_DYNAMIC]; +static int num_dynamic_stubs; +static int next_dynamic_slot = MAPI_TABLE_NUM_STATIC; + +void +stub_init_once(void) +{ +#ifdef PTHREADS + static pthread_once_t once = PTHREAD_ONCE_INIT; + pthread_once(&once, entry_patch_public); +#else + static int first = 1; + if (first) { + first = 0; + entry_patch_public(); + } +#endif +} + +static int +stub_compare(const void *key, const void *elem) +{ + const char *name = (const char *) key; + const struct mapi_stub *stub = (const struct mapi_stub *) elem; + const char *stub_name; + + stub_name = &public_string_pool[(unsigned long) stub->name]; + + return strcmp(name, stub_name); +} + +/** + * Return the public stub with the given name. + */ +const struct mapi_stub * +stub_find_public(const char *name) +{ + return (const struct mapi_stub *) bsearch(name, public_stubs, + ARRAY_SIZE(public_stubs), sizeof(public_stubs[0]), stub_compare); +} + +/** + * Add a dynamic stub. + */ +static struct mapi_stub * +stub_add_dynamic(const char *name) +{ + struct mapi_stub *stub; + int idx; + + idx = num_dynamic_stubs; + /* minus 1 to make sure we can never reach the last slot */ + if (idx >= MAPI_TABLE_NUM_DYNAMIC - 1) + return NULL; + + stub = &dynamic_stubs[idx]; + + /* dispatch to the last slot, which is reserved for no-op */ + stub->addr = entry_generate( + MAPI_TABLE_NUM_STATIC + MAPI_TABLE_NUM_DYNAMIC - 1); + if (!stub->addr) + return NULL; + + stub->name = (const void *) name; + /* to be fixed later */ + stub->slot = -1; + + num_dynamic_stubs = idx + 1; + + return stub; +} + +/** + * Return the dynamic stub with the given name. If no such stub exists and + * generate is true, a new stub is generated. + */ +struct mapi_stub * +stub_find_dynamic(const char *name, int generate) +{ + u_mutex_declare_static(dynamic_mutex); + struct mapi_stub *stub = NULL; + int count, i; + + u_mutex_lock(dynamic_mutex); + + if (generate) + assert(!stub_find_public(name)); + + count = num_dynamic_stubs; + for (i = 0; i < count; i++) { + if (strcmp(name, (const char *) dynamic_stubs[i].name) == 0) { + stub = &dynamic_stubs[i]; + break; + } + } + + /* generate a dynamic stub */ + if (generate && !stub) + stub = stub_add_dynamic(name); + + u_mutex_unlock(dynamic_mutex); + + return stub; +} + +void +stub_fix_dynamic(struct mapi_stub *stub, const struct mapi_stub *alias) +{ + int slot; + + if (stub->slot >= 0) + return; + + if (alias) + slot = alias->slot; + else + slot = next_dynamic_slot++; + + entry_patch(stub->addr, slot); + stub->slot = slot; +} diff --git a/src/mapi/mapi/stub.h b/src/mapi/mapi/stub.h new file mode 100644 index 0000000..c7e194c --- /dev/null +++ b/src/mapi/mapi/stub.h @@ -0,0 +1,52 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _STUB_H_ +#define _STUB_H_ + +typedef void (*mapi_func)(void); + +struct mapi_stub { + mapi_func addr; + int slot; + const void *name; +}; + +void +stub_init_once(void); + +const struct mapi_stub * +stub_find_public(const char *name); + +struct mapi_stub * +stub_find_dynamic(const char *name, int generate); + +void +stub_fix_dynamic(struct mapi_stub *stub, const struct mapi_stub *alias); + +#endif /* _STUB_H_ */ diff --git a/src/mapi/mapi/table.c b/src/mapi/mapi/table.c new file mode 100644 index 0000000..8f4f700 --- /dev/null +++ b/src/mapi/mapi/table.c @@ -0,0 +1,56 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include +#include + +#include "stub.h" +#include "table.h" + +static void +noop_warn(const char *name) +{ + static int debug = -1; + + if (debug < 0) + debug = (getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG")); + + if (debug) + fprintf(stderr, "%s is no-op", name); +} + +static int +noop_generic(void) +{ + noop_warn("function"); + return 0; +} + +/* define noop_array */ +#define MAPI_TMP_NOOP_ARRAY +#include "mapi_tmp.h" diff --git a/src/mapi/mapi/table.h b/src/mapi/mapi/table.h new file mode 100644 index 0000000..ca2be56 --- /dev/null +++ b/src/mapi/mapi/table.h @@ -0,0 +1,74 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _TABLE_H_ +#define _TABLE_H_ + +#include "u_compiler.h" +#include "stub.h" + +#define MAPI_TMP_DEFINES +#define MAPI_TMP_TABLE +#include "mapi_tmp.h" + +#define MAPI_TABLE_NUM_SLOTS (MAPI_TABLE_NUM_STATIC + MAPI_TABLE_NUM_DYNAMIC) +#define MAPI_TABLE_SIZE (MAPI_TABLE_NUM_SLOTS * sizeof(mapi_func)) + +extern const mapi_func table_noop_array[]; + +/** + * Get the no-op dispatch table. + */ +static INLINE const struct mapi_table * +table_get_noop(void) +{ + return (const struct mapi_table *) table_noop_array; +} + +/** + * Update the dispatch table to dispatch a stub to the given function. + */ +static INLINE void +table_set_func(struct mapi_table *tbl, + const struct mapi_stub *stub, mapi_func func) +{ + mapi_func *funcs = (mapi_func *) tbl; + funcs[stub->slot] = func; +} + +/** + * Return the dispatched function of a stub. + */ +static INLINE mapi_func +table_get_func(const struct mapi_table *tbl, const struct mapi_stub *stub) +{ + const mapi_func *funcs = (const mapi_func *) tbl; + return funcs[stub->slot]; +} + +#endif /* _TABLE_H_ */ diff --git a/src/mapi/mapi/u_compiler.h b/src/mapi/mapi/u_compiler.h new file mode 100644 index 0000000..f1752d1 --- /dev/null +++ b/src/mapi/mapi/u_compiler.h @@ -0,0 +1,48 @@ +#ifndef _U_COMPILER_H_ +#define _U_COMPILER_H_ + +/* Function inlining */ +#ifndef INLINE +# ifdef __cplusplus +# define INLINE inline +# elif defined(__GNUC__) +# define INLINE __inline__ +# elif defined(_MSC_VER) +# define INLINE __inline +# elif defined(__ICL) +# define INLINE __inline +# elif defined(__INTEL_COMPILER) +# define INLINE inline +# elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100) +# define INLINE __inline +# elif defined(__SUNPRO_C) && defined(__C99FEATURES__) +# define INLINE inline +# elif (__STDC_VERSION__ >= 199901L) /* C99 */ +# define INLINE inline +# else +# define INLINE +# endif +#endif + +/* Function visibility */ +#ifndef PUBLIC +# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# define PUBLIC __attribute__((visibility("default"))) +# elif defined(_MSC_VER) +# define PUBLIC __declspec(dllexport) +# else +# define PUBLIC +# endif +#endif + +#ifndef likely +# if defined(__GNUC__) +# define likely(x) __builtin_expect(!!(x), 1) +# define unlikely(x) __builtin_expect(!!(x), 0) +# else +# define likely(x) (x) +# define unlikely(x) (x) +# endif +#endif + +#endif /* _U_COMPILER_H_ */ diff --git a/src/mapi/mapi/u_current.c b/src/mapi/mapi/u_current.c new file mode 100644 index 0000000..77a593b --- /dev/null +++ b/src/mapi/mapi/u_current.c @@ -0,0 +1,277 @@ +/* + * Mesa 3-D graphics library + * Version: 7.1 + * + * Copyright (C) 1999-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. + */ + + +/* + * This file manages the OpenGL API dispatch layer. + * The dispatch table (struct _glapi_table) is basically just a list + * of function pointers. + * There are functions to set/get the current dispatch table for the + * current thread and to manage registration/dispatch of dynamically + * added extension functions. + * + * It's intended that this file and the other glapi*.[ch] files are + * flexible enough to be reused in several places: XFree86, DRI- + * based libGL.so, and perhaps the SGI SI. + * + * NOTE: There are no dependencies on Mesa in this code. + * + * Versions (API changes): + * 2000/02/23 - original version for Mesa 3.3 and XFree86 4.0 + * 2001/01/16 - added dispatch override feature for Mesa 3.5 + * 2002/06/28 - added _glapi_set_warning_func(), Mesa 4.1. + * 2002/10/01 - _glapi_get_proc_address() will now generate new entrypoints + * itself (using offset ~0). _glapi_add_entrypoint() can be + * called afterward and it'll fill in the correct dispatch + * offset. This allows DRI libGL to avoid probing for DRI + * drivers! No changes to the public glapi interface. + */ + +#include "u_current.h" +#include "u_thread.h" + +#ifndef MAPI_GLAPI_CURRENT + +#include "table.h" +#include "stub.h" + +#else + +extern void init_glapi_relocs_once(void); +extern void (*__glapi_noop_table[])(void); + +#define table_noop_array __glapi_noop_table +#define stub_init_once() init_glapi_relocs_once() + +#endif + +/** + * \name Current dispatch and current context control variables + * + * Depending on whether or not multithreading is support, and the type of + * support available, several variables are used to store the current context + * pointer and the current dispatch table pointer. In the non-threaded case, + * the variables \c _glapi_Dispatch and \c _glapi_Context are used for this + * purpose. + * + * In the "normal" threaded case, the variables \c _glapi_Dispatch and + * \c _glapi_Context will be \c NULL if an application is detected as being + * multithreaded. Single-threaded applications will use \c _glapi_Dispatch + * and \c _glapi_Context just like the case without any threading support. + * When \c _glapi_Dispatch and \c _glapi_Context are \c NULL, the thread state + * data \c _gl_DispatchTSD and \c ContextTSD are used. Drivers and the + * static dispatch functions access these variables via \c _glapi_get_dispatch + * and \c _glapi_get_context. + * + * There is a race condition in setting \c _glapi_Dispatch to \c NULL. It is + * possible for the original thread to be setting it at the same instant a new + * thread, perhaps running on a different processor, is clearing it. Because + * of that, \c ThreadSafe, which can only ever be changed to \c GL_TRUE, is + * used to determine whether or not the application is multithreaded. + * + * In the TLS case, the variables \c _glapi_Dispatch and \c _glapi_Context are + * hardcoded to \c NULL. Instead the TLS variables \c _glapi_tls_Dispatch and + * \c _glapi_tls_Context are used. Having \c _glapi_Dispatch and + * \c _glapi_Context be hardcoded to \c NULL maintains binary compatability + * between TLS enabled loaders and non-TLS DRI drivers. + */ +/*@{*/ +#if defined(GLX_USE_TLS) + +__thread struct mapi_table *u_current_table_tls + __attribute__((tls_model("initial-exec"))) + = (struct mapi_table *) table_noop_array; + +__thread void *u_current_user_tls + __attribute__((tls_model("initial-exec"))); + +const struct mapi_table *u_current_table; +const void *u_current_user; + +#else + +struct mapi_table *u_current_table = + (struct mapi_table *) table_noop_array; +void *u_current_user; + +#ifdef THREADS +struct u_tsd u_current_table_tsd; +static struct u_tsd u_current_user_tsd; +static int ThreadSafe; +#endif /* THREADS */ + +#endif /* defined(GLX_USE_TLS) */ +/*@}*/ + + +void +u_current_destroy(void) +{ +#if defined(THREADS) && defined(WIN32) + u_tsd_destroy(&u_current_table_tsd); + u_tsd_destroy(&u_current_user_tsd); +#endif +} + + +#if defined(THREADS) && !defined(GLX_USE_TLS) + +static void +u_current_init_tsd(void) +{ + u_tsd_init(&u_current_table_tsd); + u_tsd_init(&u_current_user_tsd); +} + +/** + * Mutex for multithread check. + */ +#ifdef WIN32 +/* _glthread_DECLARE_STATIC_MUTEX is broken on windows. There will be race! */ +#define CHECK_MULTITHREAD_LOCK() +#define CHECK_MULTITHREAD_UNLOCK() +#else +u_mutex_declare_static(ThreadCheckMutex); +#define CHECK_MULTITHREAD_LOCK() u_mutex_lock(ThreadCheckMutex) +#define CHECK_MULTITHREAD_UNLOCK() u_mutex_unlock(ThreadCheckMutex) +#endif + +/** + * We should call this periodically from a function such as glXMakeCurrent + * in order to test if multiple threads are being used. + */ +void +u_current_init(void) +{ + static unsigned long knownID; + static int firstCall = 1; + + if (ThreadSafe) + return; + + CHECK_MULTITHREAD_LOCK(); + if (firstCall) { + u_current_init_tsd(); + + knownID = u_thread_self(); + firstCall = 0; + } + else if (knownID != u_thread_self()) { + ThreadSafe = 1; + u_current_set_internal(NULL); + u_current_set_user_internal(NULL); + } + CHECK_MULTITHREAD_UNLOCK(); +} + +#else + +void +u_current_init(void) +{ +} + +#endif + + + +/** + * Set the current context pointer for this thread. + * The context pointer is an opaque type which should be cast to + * void from the real context pointer type. + */ +void +u_current_set_user_internal(void *ptr) +{ + u_current_init(); + +#if defined(GLX_USE_TLS) + u_current_user_tls = ptr; +#elif defined(THREADS) + u_tsd_set(&u_current_user_tsd, ptr); + u_current_user = (ThreadSafe) ? NULL : ptr; +#else + u_current_user = ptr; +#endif +} + +/** + * Get the current context pointer for this thread. + * The context pointer is an opaque type which should be cast from + * void to the real context pointer type. + */ +void * +u_current_get_user_internal(void) +{ +#if defined(GLX_USE_TLS) + return u_current_user_tls; +#elif defined(THREADS) + return (ThreadSafe) + ? u_tsd_get(&u_current_user_tsd) + : u_current_user; +#else + return u_current_user; +#endif +} + +/** + * Set the global or per-thread dispatch table pointer. + * If the dispatch parameter is NULL we'll plug in the no-op dispatch + * table (__glapi_noop_table). + */ +void +u_current_set_internal(struct mapi_table *tbl) +{ + u_current_init(); + + stub_init_once(); + + if (!tbl) + tbl = (struct mapi_table *) table_noop_array; + +#if defined(GLX_USE_TLS) + u_current_table_tls = tbl; +#elif defined(THREADS) + u_tsd_set(&u_current_table_tsd, (void *) tbl); + u_current_table = (ThreadSafe) ? NULL : tbl; +#else + u_current_table = tbl; +#endif +} + +/** + * Return pointer to current dispatch table for calling thread. + */ +struct mapi_table * +u_current_get_internal(void) +{ +#if defined(GLX_USE_TLS) + return u_current_table_tls; +#elif defined(THREADS) + return (struct mapi_table *) ((ThreadSafe) ? + u_tsd_get(&u_current_table_tsd) : (void *) u_current_table); +#else + return u_current_table; +#endif +} diff --git a/src/mapi/mapi/u_current.h b/src/mapi/mapi/u_current.h new file mode 100644 index 0000000..62e54c6 --- /dev/null +++ b/src/mapi/mapi/u_current.h @@ -0,0 +1,102 @@ +#ifndef _U_CURRENT_H_ +#define _U_CURRENT_H_ + +#ifdef MAPI_GLAPI_CURRENT + +#include "glapi/glapi.h" + +/* ugly renames to match glapi.h */ +#define mapi_table _glapi_table + +#define u_current_table_tls _glapi_tls_Dispatch +#define u_current_user_tls _glapi_tls_Context +#define u_current_table _glapi_Dispatch +#define u_current_user _glapi_Context + +#define u_current_destroy _glapi_destroy_multithread +#define u_current_init _glapi_check_multithread +#define u_current_set_internal _glapi_set_dispatch +#define u_current_get_internal _glapi_get_dispatch +#define u_current_set_user_internal _glapi_set_context +#define u_current_get_user_internal _glapi_get_context + +#define u_current_table_tsd _gl_DispatchTSD + +#else /* MAPI_GLAPI_CURRENT */ + +#include "u_compiler.h" + +struct mapi_table; + +#ifdef GLX_USE_TLS + +extern __thread struct mapi_table *u_current_table_tls + __attribute__((tls_model("initial-exec"))); + +extern __thread void *u_current_user_tls + __attribute__((tls_model("initial-exec"))); + +extern const struct mapi_table *u_current_table; +extern const void *u_current_user; + +#else /* GLX_USE_TLS */ + +extern struct mapi_table *u_current_table; +extern void *u_current_user; + +#endif /* GLX_USE_TLS */ + +void +u_current_init(void); + +void +u_current_destroy(void); + +void +u_current_set_internal(struct mapi_table *tbl); + +struct mapi_table * +u_current_get_internal(void); + +void +u_current_set_user_internal(void *ptr); + +void * +u_current_get_user_internal(void); + +static INLINE void +u_current_set(const struct mapi_table *tbl) +{ + u_current_set_internal((struct mapi_table *) tbl); +} + +static INLINE const struct mapi_table * +u_current_get(void) +{ +#ifdef GLX_USE_TLS + return (const struct mapi_table *) u_current_table_tls; +#else + return (likely(u_current_table) ? + (const struct mapi_table *) u_current_table : u_current_get_internal()); +#endif +} + +static INLINE void +u_current_set_user(void *ptr) +{ + u_current_set_internal(ptr); +} + +static INLINE void * +u_current_get_user(void) +{ +#ifdef GLX_USE_TLS + return u_current_user_tls; +#else + return likely(u_current_user) ? u_current_user : u_current_get_user_internal(); +#endif +} + +#endif /* MAPI_GLAPI_CURRENT */ + +#endif /* _U_CURRENT_H_ */ diff --git a/src/mapi/mapi/u_execmem.c b/src/mapi/mapi/u_execmem.c new file mode 100644 index 0000000..e5072e0 --- /dev/null +++ b/src/mapi/mapi/u_execmem.c @@ -0,0 +1,145 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 1999-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. + */ + + +/** + * \file glapi_execmem.c + * + * Function for allocating executable memory for dispatch stubs. + * + * Copied from main/execmem.c and simplified for dispatch stubs. + */ + + +#include "u_compiler.h" +#include "u_thread.h" +#include "u_execmem.h" + + +#define EXEC_MAP_SIZE (4*1024) + +u_mutex_declare_static(exec_mutex); + +static unsigned int head = 0; + +static unsigned char *exec_mem = (unsigned char *)0; + + +#if defined(__linux__) || defined(__OpenBSD__) || defined(_NetBSD__) || defined(__sun) + +#include +#include + +#ifdef MESA_SELINUX +#include +#endif + + +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS MAP_ANON +#endif + + +/* + * Dispatch stubs are of fixed size and never freed. Thus, we do not need to + * overlay a heap, we just mmap a page and manage through an index. + */ + +static int +init_map(void) +{ +#ifdef MESA_SELINUX + if (is_selinux_enabled()) { + if (!security_get_boolean_active("allow_execmem") || + !security_get_boolean_pending("allow_execmem")) + return 0; + } +#endif + + if (!exec_mem) + exec_mem = mmap(NULL, EXEC_MAP_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + + return (exec_mem != MAP_FAILED); +} + + +#elif defined(_WIN32) + +#include + + +/* + * Avoid Data Execution Prevention. + */ + +static int +init_map(void) +{ + exec_mem = VirtualAlloc(NULL, EXEC_MAP_SIZE, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + + return (exec_mem != NULL); +} + + +#else + +#include + +static int +init_map(void) +{ + exec_mem = malloc(EXEC_MAP_SIZE); + + return (exec_mem != NULL); +} + + +#endif + +void * +u_execmem_alloc(unsigned int size) +{ + void *addr = NULL; + + u_mutex_lock(exec_mutex); + + if (!init_map()) + goto bail; + + /* free space check, assumes no integer overflow */ + if (head + size > EXEC_MAP_SIZE) + goto bail; + + /* allocation, assumes proper addr and size alignement */ + addr = exec_mem + head; + head += size; + +bail: + u_mutex_unlock(exec_mutex); + + return addr; +} + + diff --git a/src/mapi/mapi/u_execmem.h b/src/mapi/mapi/u_execmem.h new file mode 100644 index 0000000..13fff8d --- /dev/null +++ b/src/mapi/mapi/u_execmem.h @@ -0,0 +1,7 @@ +#ifndef _U_EXECMEM_H_ +#define _U_EXECMEM_H_ + +void * +u_execmem_alloc(unsigned int size); + +#endif /* _U_EXECMEM_H_ */ diff --git a/src/mapi/mapi/u_macros.h b/src/mapi/mapi/u_macros.h new file mode 100644 index 0000000..72345b5 --- /dev/null +++ b/src/mapi/mapi/u_macros.h @@ -0,0 +1,12 @@ +#ifndef _U_MACROS_ +#define _U_MACROS_ + +#define _U_STRINGIFY(x) #x +#define _U_CONCAT(x, y) x ## y +#define _U_CONCAT_STR(x, y) #x#y + +#define U_STRINGIFY(x) _U_STRINGIFY(x) +#define U_CONCAT(x, y) _U_CONCAT(x, y) +#define U_CONCAT_STR(x, y) _U_CONCAT_STR(x, y) + +#endif /* _U_MACROS_ */ diff --git a/src/mapi/mapi/u_thread.c b/src/mapi/mapi/u_thread.c new file mode 100644 index 0000000..e9eae55 --- /dev/null +++ b/src/mapi/mapi/u_thread.c @@ -0,0 +1,254 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5.1 + * + * Copyright (C) 1999-2006 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. + */ + + +#include +#include +#include "u_compiler.h" +#include "u_thread.h" + + +/* + * This file should still compile even when THREADS is not defined. + * This is to make things easier to deal with on the makefile scene.. + */ +#ifdef THREADS +#include + +/* + * Error messages + */ +#define INIT_TSD_ERROR "_glthread_: failed to allocate key for thread specific data" +#define GET_TSD_ERROR "_glthread_: failed to get thread specific data" +#define SET_TSD_ERROR "_glthread_: thread failed to set thread specific data" + + +/* + * Magic number to determine if a TSD object has been initialized. + * Kind of a hack but there doesn't appear to be a better cross-platform + * solution. + */ +#define INIT_MAGIC 0xff8adc98 + + + +/* + * POSIX Threads -- The best way to go if your platform supports them. + * Solaris >= 2.5 have POSIX threads, IRIX >= 6.4 reportedly + * has them, and many of the free Unixes now have them. + * Be sure to use appropriate -mt or -D_REENTRANT type + * compile flags when building. + */ +#ifdef PTHREADS + +unsigned long +u_thread_self(void) +{ + return (unsigned long) pthread_self(); +} + + +void +u_tsd_init(struct u_tsd *tsd) +{ + if (pthread_key_create(&tsd->key, NULL/*free*/) != 0) { + perror(INIT_TSD_ERROR); + exit(-1); + } + tsd->initMagic = INIT_MAGIC; +} + + +void * +u_tsd_get(struct u_tsd *tsd) +{ + if (tsd->initMagic != (int) INIT_MAGIC) { + u_tsd_init(tsd); + } + return pthread_getspecific(tsd->key); +} + + +void +u_tsd_set(struct u_tsd *tsd, void *ptr) +{ + if (tsd->initMagic != (int) INIT_MAGIC) { + u_tsd_init(tsd); + } + if (pthread_setspecific(tsd->key, ptr) != 0) { + perror(SET_TSD_ERROR); + exit(-1); + } +} + +#endif /* PTHREADS */ + + + +/* + * Win32 Threads. The only available option for Windows 95/NT. + * Be sure that you compile using the Multithreaded runtime, otherwise + * bad things will happen. + */ +#ifdef WIN32 + +static void InsteadOf_exit(int nCode) +{ + DWORD dwErr = GetLastError(); +} + +unsigned long +u_thread_self(void) +{ + return GetCurrentThreadId(); +} + + +void +u_tsd_init(struct u_tsd *tsd) +{ + tsd->key = TlsAlloc(); + if (tsd->key == TLS_OUT_OF_INDEXES) { + perror(INIT_TSD_ERROR); + InsteadOf_exit(-1); + } + tsd->initMagic = INIT_MAGIC; +} + + +void +u_tsd_destroy(struct u_tsd *tsd) +{ + if (tsd->initMagic != INIT_MAGIC) { + return; + } + TlsFree(tsd->key); + tsd->initMagic = 0x0; +} + + +void * +u_tsd_get(struct u_tsd *tsd) +{ + if (tsd->initMagic != INIT_MAGIC) { + u_tsd_init(tsd); + } + return TlsGetValue(tsd->key); +} + + +void +u_tsd_set(struct u_tsd *tsd, void *ptr) +{ + /* the following code assumes that the struct u_tsd has been initialized + to zero at creation */ + if (tsd->initMagic != INIT_MAGIC) { + u_tsd_init(tsd); + } + if (TlsSetValue(tsd->key, ptr) == 0) { + perror(SET_TSD_ERROR); + InsteadOf_exit(-1); + } +} + +#endif /* WIN32 */ + +/* + * BeOS threads + */ +#ifdef BEOS_THREADS + +unsigned long +u_thread_self(void) +{ + return (unsigned long) find_thread(NULL); +} + +void +u_tsd_init(struct u_tsd *tsd) +{ + tsd->key = tls_allocate(); + tsd->initMagic = INIT_MAGIC; +} + +void * +u_tsd_get(struct u_tsd *tsd) +{ + if (tsd->initMagic != (int) INIT_MAGIC) { + u_tsd_init(tsd); + } + return tls_get(tsd->key); +} + +void +u_tsd_set(struct u_tsd *tsd, void *ptr) +{ + if (tsd->initMagic != (int) INIT_MAGIC) { + u_tsd_init(tsd); + } + tls_set(tsd->key, ptr); +} + +#endif /* BEOS_THREADS */ + + + +#else /* THREADS */ + + +/* + * no-op functions + */ + +unsigned long +_glthread_GetID(void) +{ + return 0; +} + + +void +u_tsd_init(struct u_tsd *tsd) +{ + (void) tsd; +} + + +void * +u_tsd_get(struct u_tsd *tsd) +{ + (void) tsd; + return NULL; +} + + +void +u_tsd_set(struct u_tsd *tsd, void *ptr) +{ + (void) tsd; + (void) ptr; +} + + +#endif /* THREADS */ diff --git a/src/mapi/mapi/u_thread.h b/src/mapi/mapi/u_thread.h new file mode 100644 index 0000000..92a0a39 --- /dev/null +++ b/src/mapi/mapi/u_thread.h @@ -0,0 +1,201 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5.2 + * + * Copyright (C) 1999-2006 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. + */ + + +/* + * Thread support for gl dispatch. + * + * Initial version by John Stone (j.stone@acm.org) (johns@cs.umr.edu) + * and Christoph Poliwoda (poliwoda@volumegraphics.com) + * Revised by Keith Whitwell + * Adapted for new gl dispatcher by Brian Paul + * Modified for use in mapi by Chia-I Wu + */ + +/* + * If this file is accidentally included by a non-threaded build, + * it should not cause the build to fail, or otherwise cause problems. + * In general, it should only be included when needed however. + */ + +#ifndef _U_THREAD_H_ +#define _U_THREAD_H_ + +#include "u_compiler.h" + +#if defined(PTHREADS) || defined(WIN32) || defined(BEOS_THREADS) +#ifndef THREADS +#define THREADS +#endif +#endif + +/* + * POSIX threads. This should be your choice in the Unix world + * whenever possible. When building with POSIX threads, be sure + * to enable any compiler flags which will cause the MT-safe + * libc (if one exists) to be used when linking, as well as any + * header macros for MT-safe errno, etc. For Solaris, this is the -mt + * compiler flag. On Solaris with gcc, use -D_REENTRANT to enable + * proper compiling for MT-safe libc etc. + */ +#if defined(PTHREADS) +#include /* POSIX threads headers */ + +struct u_tsd { + pthread_key_t key; + int initMagic; +}; + +typedef pthread_mutex_t u_mutex; + +#define u_mutex_declare_static(name) \ + static u_mutex name = PTHREAD_MUTEX_INITIALIZER + +#define u_mutex_init(name) pthread_mutex_init(&(name), NULL) +#define u_mutex_destroy(name) pthread_mutex_destroy(&(name)) +#define u_mutex_lock(name) (void) pthread_mutex_lock(&(name)) +#define u_mutex_unlock(name) (void) pthread_mutex_unlock(&(name)) + +#endif /* PTHREADS */ + + +/* + * Windows threads. Should work with Windows NT and 95. + * IMPORTANT: Link with multithreaded runtime library when THREADS are + * used! + */ +#ifdef WIN32 +#include + +struct u_tsd { + DWORD key; + int initMagic; +}; + +typedef CRITICAL_SECTION u_mutex; + +/* http://locklessinc.com/articles/pthreads_on_windows/ */ +#define u_mutex_declare_static(name) \ + /* static */ u_mutex name = {(void*)-1, -1, 0, 0, 0, 0} + +#define u_mutex_init(name) InitializeCriticalSection(&name) +#define u_mutex_destroy(name) DeleteCriticalSection(&name) +#define u_mutex_lock(name) EnterCriticalSection(&name) +#define u_mutex_unlock(name) LeaveCriticalSection(&name) + +#endif /* WIN32 */ + + +/* + * BeOS threads. R5.x required. + */ +#ifdef BEOS_THREADS + +/* Problem with OS.h and this file on haiku */ +#ifndef __HAIKU__ +#include +#endif + +#include + +/* The only two typedefs required here + * this is cause of the OS.h problem + */ +#ifdef __HAIKU__ +typedef int32 thread_id; +typedef int32 sem_id; +#endif + +struct u_tsd { + int32 key; + int initMagic; +}; + +/* Use Benaphore, aka speeder semaphore */ +typedef struct { + int32 lock; + sem_id sem; +} benaphore; +typedef benaphore u_mutex; + +#define u_mutex_declare_static(name) \ + static u_mutex name = { 0, 0 } + +#define u_mutex_init(name) \ + name.sem = create_sem(0, #name"_benaphore"), \ + name.lock = 0 + +#define u_mutex_destroy(name) \ + delete_sem(name.sem), \ + name.lock = 0 + +#define u_mutex_lock(name) \ + if (name.sem == 0) \ + u_mutex_init(name); \ + if (atomic_add(&(name.lock), 1) >= 1) \ + acquire_sem(name.sem) + +#define u_mutex_unlock(name) \ + if (atomic_add(&(name.lock), -1) > 1) \ + release_sem(name.sem) + +#endif /* BEOS_THREADS */ + + +/* + * THREADS not defined + */ +#ifndef THREADS + +struct u_tsd { + int initMagic; +}; + +typedef unsigned u_mutex; + +#define u_mutex_declare_static(name) static u_mutex name = 0 +#define u_mutex_init(name) (void) name +#define u_mutex_destroy(name) (void) name +#define u_mutex_lock(name) (void) name +#define u_mutex_unlock(name) (void) name + +#endif /* THREADS */ + + +unsigned long +u_thread_self(void); + +void +u_tsd_init(struct u_tsd *tsd); + +void +u_tsd_destroy(struct u_tsd *tsd); /* WIN32 only */ + +void * +u_tsd_get(struct u_tsd *tsd); + +void +u_tsd_set(struct u_tsd *tsd, void *ptr); + +#endif /* _U_THREAD_H_ */ diff --git a/src/mapi/vgapi/Makefile b/src/mapi/vgapi/Makefile new file mode 100644 index 0000000..e239e20 --- /dev/null +++ b/src/mapi/vgapi/Makefile @@ -0,0 +1,91 @@ +# src/mapi/vgapi/Makefile + +TOP := ../../.. +include $(TOP)/configs/current + +VG_LIB_MAJOR = 1 +VG_LIB_MINOR = 0 +VG_LIB_PATCH = 0 + +MAPI := $(TOP)/src/mapi/mapi + +include $(MAPI)/sources.mak +VGAPI_SOURCES := $(addprefix $(MAPI)/, $(MAPI_SOURCES)) +VGAPI_OBJECTS := $(MAPI_SOURCES:.c=.o) + +VGAPI_CPPFLAGS := -DMAPI_ABI_HEADER=\"vgapi/vgapi_tmp.h\" + +GENERATED_SOURCES := vgapi_tmp.h + +INCLUDE_DIRS := \ + -I$(TOP)/include \ + -I$(TOP)/src/mapi + +.PHONY: default +default: depend $(TOP)/$(LIB_DIR)/$(VG_LIB_NAME) + +$(TOP)/$(LIB_DIR)/$(VG_LIB_NAME): $(VGAPI_OBJECTS) + $(MKLIB) -o $(VG_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + -major $(VG_LIB_MAJOR) \ + -minor $(VG_LIB_MINOR) \ + -patch $(VG_LIB_PATCH) \ + -id $(INSTALL_LIB_DIR)/lib$(VG_LIB).$(VG_LIB_MAJOR).dylib \ + $(MKLIB_OPTIONS) -install $(TOP)/$(LIB_DIR) \ + $(VGAPI_OBJECTS) $(VG_LIB_DEPS) + +# not used, but kept for completeness +libvgapi.a: $(VGAPI_OBJECTS) + @$(MKLIB) -o vgapi -static $(VGAPI_OBJECTS) + +$(VGAPI_SOURCES): | $(GENERATED_SOURCES) + +$(VGAPI_OBJECTS): %.o: $(MAPI)/%.c + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $(VGAPI_CPPFLAGS) $< -o $@ + +vgapi_tmp.h: vgapi.csv $(MAPI)/mapi_abi.py + $(PYTHON2) $(PYTHON_FLAGS) $(MAPI)/mapi_abi.py \ + --printer vgapi --mode lib $< > $@ + +.PHONY: clean +clean: + -rm -f vg.pc + -rm -f $(TOP)/$(LIB_DIR)/$(VG_LIB_NAME) + -rm -f libvgapi.a + -rm -f $(VGAPI_OBJECTS) + -rm -f depend depend.bak + -rm -f $(GENERATED_SOURCES) + +pcedit = \ + -e 's,@INSTALL_DIR@,$(INSTALL_DIR),' \ + -e 's,@INSTALL_LIB_DIR@,$(INSTALL_LIB_DIR),' \ + -e 's,@INSTALL_INC_DIR@,$(INSTALL_INC_DIR),' \ + -e 's,@VERSION@,$(MESA_MAJOR).$(MESA_MINOR).$(MESA_TINY),' \ + -e 's,@VG_PC_REQ_PRIV@,$(VG_PC_REQ_PRIV),' \ + -e 's,@VG_PC_LIB_PRIV@,$(VG_PC_LIB_PRIV),' \ + -e 's,@VG_PC_CFLAGS@,$(VG_PC_CFLAGS),' \ + -e 's,@VG_LIB@,$(VG_LIB),' + +vg.pc: vg.pc.in + @sed $(pcedit) $< > $@ + +install-pc: vg.pc + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig + $(INSTALL) -m 644 $< $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig + +install-headers: + $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/VG + $(INSTALL) -m 644 $(TOP)/include/VG/*.h $(DESTDIR)$(INSTALL_INC_DIR)/VG + +install: default install-headers install-pc + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR) + $(MINSTALL) $(TOP)/$(LIB_DIR)/$(VG_LIB_GLOB) \ + $(DESTDIR)$(INSTALL_LIB_DIR) + +depend: $(VGAPI_SOURCES) + @echo "running $(MKDEP)" + @touch depend + @$(MKDEP) $(MKDEP_OPTIONS) -f- $(DEFINES) $(INCLUDE_DIRS) \ + $(VGAPI_CPPFLAGS) $(VGAPI_SOURCES) 2>/dev/null | \ + sed -e 's,^$(MAPI)/,,' > depend + +-include depend diff --git a/src/mapi/vgapi/vg.pc.in b/src/mapi/vgapi/vg.pc.in new file mode 100644 index 0000000..63e9af8 --- /dev/null +++ b/src/mapi/vgapi/vg.pc.in @@ -0,0 +1,12 @@ +prefix=@INSTALL_DIR@ +exec_prefix=${prefix} +libdir=@INSTALL_LIB_DIR@ +includedir=@INSTALL_INC_DIR@ + +Name: vg +Description: Mesa OpenVG 1.0 library +Requires.private: @VG_PC_REQ_PRIV@ +Version: @VERSION@ +Libs: -L${libdir} -l@VG_LIB@ +Libs.private: @VG_PC_LIB_PRIV@ +Cflags: -I${includedir} @VG_PC_CFLAGS@ diff --git a/src/mapi/vgapi/vgapi.csv b/src/mapi/vgapi/vgapi.csv new file mode 100644 index 0000000..5b11d06 --- /dev/null +++ b/src/mapi/vgapi/vgapi.csv @@ -0,0 +1,93 @@ +# This is the source file for the various generate structs/tables/functions +# used in st/vega. + +# OpenVG 1.0 +void, AppendPath, VGPath dstPath, VGPath srcPath +void, AppendPathData, VGPath dstPath, VGint numSegments, const VGubyte *pathSegments, const void *pathData +VGImage, ChildImage, VGImage parent, VGint x, VGint y, VGint width, VGint height +void, Clear, VGint x, VGint y, VGint width, VGint height +void, ClearImage, VGImage image, VGint x, VGint y, VGint width, VGint height +void, ClearPath, VGPath path, VGbitfield capabilities +void, ColorMatrix, VGImage dst, VGImage src, const VGfloat *matrix +void, Convolve, VGImage dst, VGImage src, VGint kernelWidth, VGint kernelHeight, VGint shiftX, VGint shiftY, const VGshort *kernel, VGfloat scale, VGfloat bias, VGTilingMode tilingMode +void, CopyImage, VGImage dst, VGint dx, VGint dy, VGImage src, VGint sx, VGint sy, VGint width, VGint height, VGboolean dither +void, CopyPixels, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height +VGImage, CreateImage, VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality +VGPaint, CreatePaint, void +VGPath, CreatePath, VGint pathFormat, VGPathDatatype datatype, VGfloat scale, VGfloat bias, VGint segmentCapacityHint, VGint coordCapacityHint, VGbitfield capabilities +void, DestroyImage, VGImage image +void, DestroyPaint, VGPaint paint +void, DestroyPath, VGPath path +void, DrawImage, VGImage image +void, DrawPath, VGPath path, VGbitfield paintModes +void, Finish, void +void, Flush, void +void, GaussianBlur, VGImage dst, VGImage src, VGfloat stdDeviationX, VGfloat stdDeviationY, VGTilingMode tilingMode +VGuint, GetColor, VGPaint paint +VGErrorCode, GetError, void +void, GetImageSubData, VGImage image, void *data, VGint dataStride, VGImageFormat dataFormat, VGint x, VGint y, VGint width, VGint height +void, GetMatrix, VGfloat *m +VGPaint, GetPaint, VGPaintMode paintMode +VGint, GetParameterVectorSize, VGHandle object, VGint paramType +VGfloat, GetParameterf, VGHandle object, VGint paramType +void, GetParameterfv, VGHandle object, VGint paramType, VGint count, VGfloat *values +VGint, GetParameteri, VGHandle object, VGint paramType +void, GetParameteriv, VGHandle object, VGint paramType, VGint count, VGint *values +VGImage, GetParent, VGImage image +VGbitfield, GetPathCapabilities, VGPath path +void, GetPixels, VGImage dst, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height +const VGubyte *, GetString, VGStringID name +VGint, GetVectorSize, VGParamType type +VGfloat, Getf, VGParamType type +void, Getfv, VGParamType type, VGint count, VGfloat *values +VGint, Geti, VGParamType type +void, Getiv, VGParamType type, VGint count, VGint *values +VGHardwareQueryResult, HardwareQuery, VGHardwareQueryType key, VGint setting +void, ImageSubData, VGImage image, const void *data, VGint dataStride, VGImageFormat dataFormat, VGint x, VGint y, VGint width, VGint height +VGboolean, InterpolatePath, VGPath dstPath, VGPath startPath, VGPath endPath, VGfloat amount +void, LoadIdentity, void +void, LoadMatrix, const VGfloat *m +void, Lookup, VGImage dst, VGImage src, const VGubyte *redLUT, const VGubyte *greenLUT, const VGubyte *blueLUT, const VGubyte *alphaLUT, VGboolean outputLinear, VGboolean outputPremultiplied +void, LookupSingle, VGImage dst, VGImage src, const VGuint *lookupTable, VGImageChannel sourceChannel, VGboolean outputLinear, VGboolean outputPremultiplied +void, Mask, VGHandle mask, VGMaskOperation operation, VGint x, VGint y, VGint width, VGint height +void, ModifyPathCoords, VGPath dstPath, VGint startIndex, VGint numSegments, const void *pathData +void, MultMatrix, const VGfloat *m +void, PaintPattern, VGPaint paint, VGImage pattern +void, PathBounds, VGPath path, VGfloat *minX, VGfloat *minY, VGfloat *width, VGfloat *height +VGfloat, PathLength, VGPath path, VGint startSegment, VGint numSegments +void, PathTransformedBounds, VGPath path, VGfloat *minX, VGfloat *minY, VGfloat *width, VGfloat *height +void, PointAlongPath, VGPath path, VGint startSegment, VGint numSegments, VGfloat distance, VGfloat *x, VGfloat *y, VGfloat *tangentX, VGfloat *tangentY +void, ReadPixels, void *data, VGint dataStride, VGImageFormat dataFormat, VGint sx, VGint sy, VGint width, VGint height +void, RemovePathCapabilities, VGPath path, VGbitfield capabilities +void, Rotate, VGfloat angle +void, Scale, VGfloat sx, VGfloat sy +void, SeparableConvolve, VGImage dst, VGImage src, VGint kernelWidth, VGint kernelHeight, VGint shiftX, VGint shiftY, const VGshort *kernelX, const VGshort *kernelY, VGfloat scale, VGfloat bias, VGTilingMode tilingMode +void, SetColor, VGPaint paint, VGuint rgba +void, SetPaint, VGPaint paint, VGbitfield paintModes +void, SetParameterf, VGHandle object, VGint paramType, VGfloat value +void, SetParameterfv, VGHandle object, VGint paramType, VGint count, const VGfloat *values +void, SetParameteri, VGHandle object, VGint paramType, VGint value +void, SetParameteriv, VGHandle object, VGint paramType, VGint count, const VGint *values +void, SetPixels, VGint dx, VGint dy, VGImage src, VGint sx, VGint sy, VGint width, VGint height +void, Setf, VGParamType type, VGfloat value +void, Setfv, VGParamType type, VGint count, const VGfloat *values +void, Seti, VGParamType type, VGint value +void, Setiv, VGParamType type, VGint count, const VGint *values +void, Shear, VGfloat shx, VGfloat shy +void, TransformPath, VGPath dstPath, VGPath srcPath +void, Translate, VGfloat tx, VGfloat ty +void, WritePixels, const void *data, VGint dataStride, VGImageFormat dataFormat, VGint dx, VGint dy, VGint width, VGint height + +## OpenVG 1.1 +void, ClearGlyph, VGFont font, VGuint glyphIndex +void, CopyMask, VGMaskLayer maskLayer, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height +VGFont, CreateFont, VGint glyphCapacityHint +VGMaskLayer, CreateMaskLayer, VGint width, VGint height +void, DestroyFont, VGFont font +void, DestroyMaskLayer, VGMaskLayer maskLayer +void, DrawGlyph, VGFont font, VGuint glyphIndex, VGbitfield paintModes, VGboolean allowAutoHinting +void, DrawGlyphs, VGFont font, VGint glyphCount, const VGuint *glyphIndices, const VGfloat *adjustments_x, const VGfloat *adjustments_y, VGbitfield paintModes, VGboolean allowAutoHinting +void, FillMaskLayer, VGMaskLayer maskLayer, VGint x, VGint y, VGint width, VGint height, VGfloat value +void, RenderToMask, VGPath path, VGbitfield paintModes, VGMaskOperation operation +void, SetGlyphToImage, VGFont font, VGuint glyphIndex, VGImage image, const VGfloat glyphOrigin[2], const VGfloat escapement[2] +void, SetGlyphToPath, VGFont font, VGuint glyphIndex, VGPath path, VGboolean isHinted, const VGfloat glyphOrigin[2], const VGfloat escapement[2] diff --git a/src/mesa/Makefile b/src/mesa/Makefile new file mode 100644 index 0000000..c41c38c --- /dev/null +++ b/src/mesa/Makefile @@ -0,0 +1,260 @@ +# src/mesa/Makefile + +TOP = ../.. +include $(TOP)/configs/current + +MESA_LIBS := libmesa.a libmesagallium.a +DEPENDS := depend + +ifeq ($(GLES_OVERLAY),1) +ES1_LIBS := libes1gallium.a +ES2_LIBS := libes2gallium.a +DEPENDS += depend.es1 depend.es2 +endif + +MESA_OBJ_DIR := . +ES1_OBJ_DIR := objs-es1 +ES2_OBJ_DIR := objs-es2 + + +include sources.mak + +# adjust object dirs +ES1_OBJECTS := $(addprefix $(ES1_OBJ_DIR)/, $(MESA_OBJECTS)) +ES2_OBJECTS := $(addprefix $(ES2_OBJ_DIR)/, $(MESA_OBJECTS)) +MESA_OBJECTS := $(addprefix $(MESA_OBJ_DIR)/, $(MESA_OBJECTS)) + +ES1_GALLIUM_OBJECTS := $(addprefix $(ES1_OBJ_DIR)/, $(MESA_GALLIUM_OBJECTS)) +ES2_GALLIUM_OBJECTS := $(addprefix $(ES2_OBJ_DIR)/, $(MESA_GALLIUM_OBJECTS)) +MESA_GALLIUM_OBJECTS := $(addprefix $(MESA_OBJ_DIR)/, $(MESA_GALLIUM_OBJECTS)) + +# define preprocessor flags +MESA_CPPFLAGS := $(API_DEFINES) $(DEFINES) +ES1_CPPFLAGS := -DFEATURE_ES1=1 $(DEFINES) +ES2_CPPFLAGS := -DFEATURE_ES2=1 $(DEFINES) + +# append include dirs +MESA_CPPFLAGS += $(INCLUDE_DIRS) +ES1_CPPFLAGS += -I$(TOP)/src/mapi/es1api $(INCLUDE_DIRS) +ES2_CPPFLAGS += -I$(TOP)/src/mapi/es2api $(INCLUDE_DIRS) + +# tidy compiler flags +CFLAGS := $(filter-out $(DEFINES), $(CFLAGS)) +CXXFLAGS := $(filter-out $(DEFINES), $(CXXFLAGS)) + +# LLVM is needed for the state tracker +MESA_CFLAGS := $(LLVM_CFLAGS) +ES1_CFLAGS := $(LLVM_CFLAGS) +ES2_CFLAGS := $(LLVM_CFLAGS) + +define mesa-cc-c + @mkdir -p $(dir $@) + $(CC) -c -o $@ $< $($(1)_CPPFLAGS) $($(1)_CFLAGS) $(CFLAGS) +endef + +define mesa-cxx-c + @mkdir -p $(dir $@) + $(CXX) -c -o $@ $< $($(1)_CPPFLAGS) $($(1)_CFLAGS) $(CXXFLAGS) +endef + +$(MESA_OBJ_DIR)/%.o: %.c + $(call mesa-cc-c,MESA) + +$(MESA_OBJ_DIR)/%.o: %.cpp + $(call mesa-cxx-c,MESA) + +$(MESA_OBJ_DIR)/%.o: %.S + $(call mesa-cc-c,MESA) + +$(ES1_OBJ_DIR)/%.o: %.c + $(call mesa-cc-c,ES1) + +$(ES1_OBJ_DIR)/%.o: %.cpp + $(call mesa-cxx-c,ES1) + +$(ES1_OBJ_DIR)/%.o: %.S + $(call mesa-cc-c,ES1) + +$(ES2_OBJ_DIR)/%.o: %.c + $(call mesa-cc-c,ES2) + +$(ES2_OBJ_DIR)/%.o: %.cpp + $(call mesa-cxx-c,ES2) + +$(ES2_OBJ_DIR)/%.o: %.S + $(call mesa-cc-c,ES2) + + +# Default: build dependencies, then asm_subdirs, GLSL built-in lib, +# then convenience libs (.a) and finally the device drivers: +default: $(DEPENDS) asm_subdirs \ + $(MESA_LIBS) $(ES1_LIBS) $(ES2_LIBS) driver_subdirs + +main/api_exec_es1.c: main/APIspec.xml main/es_generator.py main/APIspecutil.py main/APIspec.py + $(PYTHON2) $(PYTHON_FLAGS) main/es_generator.py -S main/APIspec.xml -V GLES1.1 > $@ + +main/api_exec_es2.c: main/APIspec.xml main/es_generator.py main/APIspecutil.py main/APIspec.py + $(PYTHON2) $(PYTHON_FLAGS) main/es_generator.py -S main/APIspec.xml -V GLES2.0 > $@ + +###################################################################### +# Helper libraries used by many drivers: + +# Make archive of core mesa object files +libmesa.a: $(MESA_OBJECTS) $(GLSL_LIBS) + @ $(MKLIB) -o mesa -static $(MESA_OBJECTS) $(GLSL_LIBS) + +libes1.a: $(ES1_OBJECTS) $(GLSL_LIBS) + @$(MKLIB) -o es1 -static $(ES1_OBJECTS) $(GLSL_LIBS) + +libes2.a: $(ES2_OBJECTS) $(GLSL_LIBS) + @$(MKLIB) -o es2 -static $(ES2_OBJECTS) $(GLSL_LIBS) + +# Make archive of subset of core mesa object files for gallium +libmesagallium.a: $(MESA_GALLIUM_OBJECTS) $(GLSL_LIBS) + @ $(MKLIB) -o mesagallium -static $(MESA_GALLIUM_OBJECTS) $(GLSL_LIBS) + +libes1gallium.a: $(ES1_GALLIUM_OBJECTS) $(GLSL_LIBS) + @$(MKLIB) -o es1gallium -static $(ES1_GALLIUM_OBJECTS) $(GLSL_LIBS) + +libes2gallium.a: $(ES2_GALLIUM_OBJECTS) $(GLSL_LIBS) + @$(MKLIB) -o es2gallium -static $(ES2_GALLIUM_OBJECTS) $(GLSL_LIBS) + +###################################################################### +# Device drivers +driver_subdirs: $(MESA_LIBS) + @ (cd drivers && $(MAKE)) + + +###################################################################### +# Assembly subdirs +asm_subdirs: + @ if echo "$(ASM_FLAGS)" | grep -q USE_X86_ASM ; then \ + (cd x86 && $(MAKE)) || exit 1 ; \ + fi + @ if echo "$(ASM_FLAGS)" | grep -q USE_X86_64_ASM ; then \ + (cd x86 && $(MAKE)) || exit 1 ; \ + (cd x86-64 && $(MAKE)) || exit 1 ; \ + fi + + +###################################################################### +# Dependency generation + +depend: $(ALL_SOURCES) + @ echo "running $(MKDEP)" + @ touch depend + @$(MKDEP) $(MKDEP_OPTIONS) -p$(MESA_OBJ_DIR)/ $(MESA_CPPFLAGS) \ + $(ALL_SOURCES) > /dev/null 2>/dev/null + +depend.es1: $(ALL_SOURCES) + @echo "running $(MKDEP) for ES1" + @touch $@ + @$(MKDEP) $(MKDEP_OPTIONS) -f$@ -p$(ES1_OBJ_DIR)/ $(ES1_CPPFLAGS) \ + $(ALL_SOURCES) > /dev/null 2>/dev/null + +depend.es2: $(ALL_SOURCES) + @echo "running $(MKDEP) for ES2" + @touch $@ + @$(MKDEP) $(MKDEP_OPTIONS) -f$@ -p$(ES2_OBJ_DIR)/ $(ES2_CPPFLAGS) \ + $(ALL_SOURCES) > /dev/null 2>/dev/null + +###################################################################### +# Installation rules + +# this isn't fleshed out yet but is probably the way to go in the future +new_install: + (cd drivers && $(MAKE) install) + + +# XXX replace this with new_install above someday +install: default + @for driver in $(DRIVER_DIRS) ; do \ + case "$$driver" in \ + osmesa) if [ "$(DRIVER_DIRS)" = osmesa ]; then \ + $(MAKE) install-headers install-osmesa || exit 1 ; \ + else \ + $(MAKE) install-osmesa || exit 1 ; \ + fi ;; \ + dri) $(MAKE) install-libgl install-dri || exit 1 ;; \ + *) $(MAKE) install-libgl || exit 1 ;; \ + esac ; \ + done + +pcedit = \ + -e 's,@INSTALL_DIR@,$(INSTALL_DIR),' \ + -e 's,@INSTALL_LIB_DIR@,$(INSTALL_LIB_DIR),' \ + -e 's,@INSTALL_INC_DIR@,$(INSTALL_INC_DIR),' \ + -e 's,@VERSION@,$(MESA_MAJOR).$(MESA_MINOR).$(MESA_TINY),' \ + + +gl_pcedit = sed \ + $(pcedit) \ + -e 's,@GL_PC_REQ_PRIV@,$(GL_PC_REQ_PRIV),' \ + -e 's,@GL_PC_LIB_PRIV@,$(GL_PC_LIB_PRIV),' \ + -e 's,@GL_PC_CFLAGS@,$(GL_PC_CFLAGS),' \ + -e 's,@GL_LIB@,$(GL_LIB),' + +gl.pc: gl.pc.in + $(gl_pcedit) $< > $@ + +osmesa_pcedit = sed \ + $(pcedit) \ + -e 's,@OSMESA_LIB@,$(OSMESA_LIB),' \ + -e 's,@OSMESA_PC_REQ@,$(OSMESA_PC_REQ),' \ + -e 's,@OSMESA_PC_LIB_PRIV@,$(OSMESA_PC_LIB_PRIV),' + +osmesa.pc: osmesa.pc.in + $(osmesa_pcedit) $< > $@ + +install-headers: + $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/GL + $(INSTALL) -m 644 $(TOP)/include/GL/*.h \ + $(DESTDIR)$(INSTALL_INC_DIR)/GL + +install-libgl: default gl.pc install-headers + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR) + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig + $(MINSTALL) $(TOP)/$(LIB_DIR)/$(GL_LIB_GLOB) \ + $(DESTDIR)$(INSTALL_LIB_DIR) + $(INSTALL) -m 644 gl.pc $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig + +install-osmesa: default osmesa.pc + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR) + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig + $(MINSTALL) $(TOP)/$(LIB_DIR)/$(OSMESA_LIB_GLOB) \ + $(DESTDIR)$(INSTALL_LIB_DIR) + $(INSTALL) -m 644 osmesa.pc $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig + +install-dri: default + cd drivers/dri && $(MAKE) install + + + +# Emacs tags +tags: + etags `find . -name \*.[ch]` $(TOP)/include/GL/*.h + +clean-es1: + -rm -f $(ES1_LIBS) + -rm -rf $(ES1_OBJ_DIR) + -rm -f depend.es1 depend.es1.bak + +clean-es2: + -rm -f $(ES2_LIBS) + -rm -rf $(ES2_OBJ_DIR) + -rm -f depend.es2 depend.es2.bak + +clean: clean-es1 clean-es2 + -rm -f */*.o + -rm -f */*/*.o + -rm -f depend depend.bak libmesa.a libmesagallium.a + -rm -f drivers/*/*.o + -rm -f *.pc + -@cd drivers/dri && $(MAKE) clean + -@cd drivers/x11 && $(MAKE) clean + -@cd drivers/osmesa && $(MAKE) clean + -@cd x86 && $(MAKE) clean + -@cd x86-64 && $(MAKE) clean + + +-include $(DEPENDS) diff --git a/src/mesa/Makefile.mgw b/src/mesa/Makefile.mgw new file mode 100644 index 0000000..fc0ff28 --- /dev/null +++ b/src/mesa/Makefile.mgw @@ -0,0 +1,234 @@ +# Mesa 3-D graphics library +# Version: 7.0 +# +# Copyright (C) 1999-2003 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. + +# MinGW core makefile v1.4 for Mesa +# +# Copyright (C) 2002 - Daniel Borca +# Email : dborca@users.sourceforge.net +# Web : http://www.geocities.com/dborca + +# MinGW core-gl makefile updated for Mesa 7.0 +# +# updated : by Heromyth, on 2007-7-21 +# Email : zxpmyth@yahoo.com.cn +# Bugs : 1) All the default settings work fine. But the setting X86=1 can't work. +# The others havn't been tested yet. +# 2) The generated DLLs are *not* compatible with the ones built +# with the other compilers like VC8, especially for GLUT. +# 3) Although more tests are needed, it can be used individually! + + +# +# Available options: +# +# Environment variables: +# CFLAGS +# +# GLIDE path to Glide3 SDK; used with FX. +# default = $(TOP)/glide3 +# FX=1 build for 3dfx Glide3. Note that this disables +# compilation of most WMesa code and requires fxMesa. +# As a consequence, you'll need the Win32 Glide3 +# library to build any application. +# default = no +# ICD=1 build the installable client driver interface +# (windows opengl driver interface) +# default = no +# X86=1 optimize for x86 (if possible, use MMX, SSE, 3DNow). +# default = no +# +# Targets: +# all: build GL +# clean: remove object files +# + + +.PHONY: all clean +.INTERMEDIATE: x86/gen_matypes.exe +.SUFFIXES: .rc .res + +# Set this to the prefix of your build tools, i.e. mingw32- +TOOLS_PREFIX = mingw32- + +ifeq ($(ICD),1) + LIB_NAME = mesa32 +else + LIB_NAME = opengl32 +endif + +DLL_EXT = .dll +IMP_EXT = .a +LIB_PRE = lib +STRIP = -s + +AR = ar +ARFLAGS = crus +DLLTOOL = dlltool + +TOP = ../.. +GLIDE ?= $(TOP)/glide3 +LIBDIR = $(TOP)/lib + +GL_DLL = $(LIB_NAME)$(DLL_EXT) +GL_IMP = $(LIB_PRE)$(LIB_NAME)$(IMP_EXT) + +MESA_LIB = libmesa.a +CC = $(TOOLS_PREFIX)gcc + +LDLIBS = -lgdi32 -luser32 -liberty +LDFLAGS = $(STRIP) -shared -fPIC -Wl,--kill-at + +CFLAGS += -DBUILD_GL32 -D_DLL -DMESA_MINWARN +CFLAGS += -DNDEBUG -DUSE_EXTERNAL_DXTN_LIB=1 + +ifeq ($(FX),1) + CFLAGS += -I$(GLIDE)/include -DFX + LDLIBS += -L$(GLIDE)/lib -lglide3x + GL_DEF = drivers/windows/fx/fxopengl.def + GL_RES = drivers/windows/fx/fx.rc +else + ifeq ($(ICD),1) + CFLAGS += -DUSE_MGL_NAMESPACE + GL_DEF = drivers/windows/icd/mesa.def + else + GL_DEF = $(LIB_NAME).def + endif +endif + + + +UNLINK = del $(subst /,\,$(1)) +ifneq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),) +UNLINK = $(RM) $(1) +endif +ifneq ($(wildcard $(addsuffix /rm,$(subst :, ,$(PATH)))),) +UNLINK = $(RM) $(1) +endif + +include sources.mak + +CFLAGS += $(INCLUDE_DIRS) + +ifeq ($(X86),1) +CFLAGS += -DUSE_X86_ASM +CFLAGS += -DUSE_MMX_ASM +CFLAGS += -DUSE_SSE_ASM +CFLAGS += -DUSE_3DNOW_ASM +X86_SOURCES += $(X86_API) +else +X86_SOURCES = +endif + +ifeq ($(FX),1) +DRIVER_SOURCES = \ + $(GLIDE_DRIVER_SOURCES) \ + drivers/windows/fx/fxwgl.c +else +ifeq ($(ICD),1) +DRIVER_SOURCES = \ + drivers/windows/gdi/wmesa.c \ + drivers/windows/icd/icd.c +else +DRIVER_SOURCES = \ + drivers/windows/gdi/wmesa.c \ + drivers/windows/gdi/wgl.c +endif +endif + +SOURCES = $(MESA_SOURCES) $(GLAPI_SOURCES) $(X86_SOURCES) $(DRIVER_SOURCES) + +OBJECTS = $(addsuffix .o,$(basename $(SOURCES))) + +X86_OBJECTS = $(addsuffix .o,$(basename $(X86_SOURCES))) + +RESOURCE = $(GL_RES:.rc=.res) + +.c.o: + $(CC) -o $@ $(CFLAGS) -c $< +.s.o: + $(CC) -o $@ $(CFLAGS) -x assembler-with-cpp -c $< + +.rc.res: + windres -o $@ -Irc -Ocoff $< + + +all: $(LIBDIR) $(LIBDIR)/$(GL_DLL) $(LIBDIR)/$(GL_IMP) + +$(LIBDIR): + mkdir -p $(LIBDIR) + +$(LIBDIR)/$(GL_DLL) $(LIBDIR)/$(GL_IMP): $(OBJECTS) $(RESOURCE) + $(CC) $(LDFLAGS) -o $(LIBDIR)/$(GL_DLL) $^ $(LDLIBS) + $(DLLTOOL) --as=as --dllname $(LIB_NAME) --output-def $(LIBDIR)/$(GL_DEF) $^ + $(DLLTOOL) --as=as -k --dllname $(LIB_NAME) --output-lib $(LIBDIR)/$(GL_IMP) --def $(LIBDIR)/$(GL_DEF) + + +$(X86_OBJECTS): x86/matypes.h + +x86/matypes.h: x86/gen_matypes.exe + $(subst /,\,$< > $@) + +x86/gen_matypes.exe: x86/gen_matypes.c + $(CC) -o $@ $(CFLAGS) -s $< + +# [dBorca] +# glapi_x86.S needs some adjustments +# in order to generate correct entrypoints +# Trick: change the following condition to +# be always false if you need C entrypoints +# with USE_X86_ASM (useful for trace/debug) +ifeq (1,1) +x86/glapi_x86.o: x86/glapi_x86.S + $(CC) -o $@ $(CFLAGS) -DSTDCALL_API -c $< +else +glapi/glapi_dispatch.o: glapi/glapi_dispatch.c + $(CC) -o $@ $(CFLAGS) -UUSE_X86_ASM -c $< +glapi/glapi.o: glapi/glapi.c + $(CC) -o $@ $(CFLAGS) -UUSE_X86_ASM -c $< +endif + +# [dBorca] +# if we want codegen, we have to stdcall +tnl/t_vtx_x86_gcc.o: tnl/t_vtx_x86_gcc.S + $(CC) -o $@ $(CFLAGS) -DSTDCALL_API -c $< + +clean: + -$(call UNLINK,glapi/*.o) + -$(call UNLINK,main/*.o) + -$(call UNLINK,math/*.o) + -$(call UNLINK,vbo/*.o) + -$(call UNLINK,program/*.o) + -$(call UNLINK,slang/*.o) + -$(call UNLINK,sparc/*.o) + -$(call UNLINK,ppc/*.o) + -$(call UNLINK,swrast/*.o) + -$(call UNLINK,swrast_setup/*.o) + -$(call UNLINK,tnl/*.o) + -$(call UNLINK,x86/*.o) + -$(call UNLINK,x86/rtasm/*.o) + -$(call UNLINK,x86-64/*.o) + -$(call UNLINK,drivers/common/*.o) + -$(call UNLINK,drivers/glide/*.o) + -$(call UNLINK,drivers/windows/fx/*.o) + -$(call UNLINK,drivers/windows/fx/*.res) + -$(call UNLINK,drivers/windows/gdi/*.o) + -$(call UNLINK,drivers/windows/icd/*.o) diff --git a/src/mesa/depend b/src/mesa/depend new file mode 100644 index 0000000..e69de29 diff --git a/src/mesa/descrip.mms b/src/mesa/descrip.mms new file mode 100644 index 0000000..dbfa336 --- /dev/null +++ b/src/mesa/descrip.mms @@ -0,0 +1,27 @@ +# Makefile for Mesa for VMS +# contributed by Jouk Jansen joukj@hrem.nano.tudelft.nl +# Date last revision : 7 March 2007 + +all : + set default [.main] + $(MMS)$(MMSQUALIFIERS) + set default [-.glapi] + $(MMS)$(MMSQUALIFIERS) + set default [-.shader] + $(MMS)$(MMSQUALIFIERS) + set default [-.drivers.common] + $(MMS)$(MMSQUALIFIERS) + set default [-.x11] + $(MMS)$(MMSQUALIFIERS) + set default [-.osmesa] + $(MMS)$(MMSQUALIFIERS) + set default [--.math] + $(MMS)$(MMSQUALIFIERS) + set default [-.tnl] + $(MMS)$(MMSQUALIFIERS) + set default [-.swrast] + $(MMS)$(MMSQUALIFIERS) + set default [-.swrast_setup] + $(MMS)$(MMSQUALIFIERS) + set default [-.vbo] + $(MMS)$(MMSQUALIFIERS) diff --git a/src/mesa/drivers/Makefile b/src/mesa/drivers/Makefile new file mode 100644 index 0000000..c599841 --- /dev/null +++ b/src/mesa/drivers/Makefile @@ -0,0 +1,29 @@ +# src/mesa/drivers/Makefile + +TOP = ../../.. +include $(TOP)/configs/current + + +default: + @for dir in $(DRIVER_DIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE)) || exit 1; \ + fi \ + done + + +clean: + @for dir in $(DRIVER_DIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) clean) || exit 1; \ + fi \ + done + + +install: + @for dir in $(DRIVER_DIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) install) || exit 1; \ + fi \ + done + diff --git a/src/mesa/drivers/beos/GLView.cpp b/src/mesa/drivers/beos/GLView.cpp new file mode 100644 index 0000000..ee3415b --- /dev/null +++ b/src/mesa/drivers/beos/GLView.cpp @@ -0,0 +1,1573 @@ +/* + * Mesa 3-D graphics library + * Version: 6.1 + * + * Copyright (C) 1999-2004 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. + */ + + +#include +#include + +extern "C" { + +#include "glheader.h" +#include "version.h" +#include "buffers.h" +#include "bufferobj.h" +#include "context.h" +#include "colormac.h" +#include "depth.h" +#include "extensions.h" +#include "macros.h" +#include "matrix.h" +#include "mtypes.h" +#include "texformat.h" +#include "texobj.h" +#include "teximage.h" +#include "texstore.h" +#include "vbo/vbo.h" +#include "swrast/swrast.h" +#include "swrast_setup/swrast_setup.h" +#include "swrast/s_context.h" +#include "swrast/s_depth.h" +#include "swrast/s_lines.h" +#include "swrast/s_triangle.h" +#include "swrast/s_trispan.h" +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" + +#include "drivers/common/driverfuncs.h" + +} // extern "C" + +#include +#include + +// BeOS component ordering for B_RGBA32 bitmap format +#if B_HOST_IS_LENDIAN + #define BE_RCOMP 2 + #define BE_GCOMP 1 + #define BE_BCOMP 0 + #define BE_ACOMP 3 + + #define PACK_B_RGBA32(color) (color[BCOMP] | (color[GCOMP] << 8) | \ + (color[RCOMP] << 16) | (color[ACOMP] << 24)) + + #define PACK_B_RGB32(color) (color[BCOMP] | (color[GCOMP] << 8) | \ + (color[RCOMP] << 16) | 0xFF000000) +#else + // Big Endian B_RGBA32 bitmap format + #define BE_RCOMP 1 + #define BE_GCOMP 2 + #define BE_BCOMP 3 + #define BE_ACOMP 0 + + #define PACK_B_RGBA32(color) (color[ACOMP] | (color[RCOMP] << 8) | \ + (color[GCOMP] << 16) | (color[BCOMP] << 24)) + + #define PACK_B_RGB32(color) ((color[RCOMP] << 8) | (color[GCOMP] << 16) | \ + (color[BCOMP] << 24) | 0xFF000000) +#endif + +#define FLIP(coord) (LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.y-(coord) - 1) + +const char * color_space_name(color_space space); + +// +// This object hangs off of the BGLView object. We have to use +// Be's BGLView class as-is to maintain binary compatibility (we +// can't add new members to it). Instead we just put all our data +// in this class and use BGLVIew::m_gc to point to it. +// +class MesaDriver +{ +friend class BGLView; +public: + MesaDriver(); + ~MesaDriver(); + + void Init(BGLView * bglview, struct gl_context * c, struct gl_config * v, struct gl_framebuffer * b); + + void LockGL(); + void UnlockGL(); + void SwapBuffers() const; + status_t CopyPixelsOut(BPoint source, BBitmap *dest); + status_t CopyPixelsIn(BBitmap *source, BPoint dest); + + void CopySubBuffer(GLint x, GLint y, GLuint width, GLuint height) const; + void Draw(BRect updateRect) const; + +private: + MesaDriver(const MesaDriver &rhs); // copy constructor illegal + MesaDriver &operator=(const MesaDriver &rhs); // assignment oper. illegal + + struct gl_context * m_glcontext; + struct gl_config * m_glvisual; + struct gl_framebuffer * m_glframebuffer; + + BGLView * m_bglview; + BBitmap * m_bitmap; + + GLchan m_clear_color[4]; // buffer clear color + GLuint m_clear_index; // buffer clear color index + GLint m_bottom; // used for flipping Y coords + GLuint m_width; + GLuint m_height; + + // Mesa Device Driver callback functions + static void UpdateState(struct gl_context *ctx, GLuint new_state); + static void ClearIndex(struct gl_context *ctx, GLuint index); + static void ClearColor(struct gl_context *ctx, const GLfloat color[4]); + static void Clear(struct gl_context *ctx, GLbitfield mask, + GLboolean all, GLint x, GLint y, + GLint width, GLint height); + static void ClearFront(struct gl_context *ctx, GLboolean all, GLint x, GLint y, + GLint width, GLint height); + static void ClearBack(struct gl_context *ctx, GLboolean all, GLint x, GLint y, + GLint width, GLint height); + static void Index(struct gl_context *ctx, GLuint index); + static void Color(struct gl_context *ctx, GLubyte r, GLubyte g, + GLubyte b, GLubyte a); + static void SetBuffer(struct gl_context *ctx, struct gl_framebuffer *colorBuffer, + GLenum mode); + static void GetBufferSize(struct gl_framebuffer * framebuffer, GLuint *width, + GLuint *height); + static void Error(struct gl_context *ctx); + static const GLubyte * GetString(struct gl_context *ctx, GLenum name); + static void Viewport(struct gl_context *ctx, GLint x, GLint y, GLsizei w, GLsizei h); + + // Front-buffer functions + static void WriteRGBASpanFront(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + CONST GLubyte rgba[][4], + const GLubyte mask[]); + static void WriteRGBSpanFront(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + CONST GLubyte rgba[][3], + const GLubyte mask[]); + static void WriteMonoRGBASpanFront(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + const GLchan color[4], + const GLubyte mask[]); + static void WriteRGBAPixelsFront(const struct gl_context *ctx, GLuint n, + const GLint x[], const GLint y[], + CONST GLubyte rgba[][4], + const GLubyte mask[]); + static void WriteMonoRGBAPixelsFront(const struct gl_context *ctx, GLuint n, + const GLint x[], const GLint y[], + const GLchan color[4], + const GLubyte mask[]); + static void WriteCI32SpanFront(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + const GLuint index[], const GLubyte mask[]); + static void WriteCI8SpanFront(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + const GLubyte index[], const GLubyte mask[]); + static void WriteMonoCISpanFront(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + GLuint colorIndex, const GLubyte mask[]); + static void WriteCI32PixelsFront(const struct gl_context *ctx, + GLuint n, const GLint x[], const GLint y[], + const GLuint index[], const GLubyte mask[]); + static void WriteMonoCIPixelsFront(const struct gl_context *ctx, GLuint n, + const GLint x[], const GLint y[], + GLuint colorIndex, const GLubyte mask[]); + static void ReadCI32SpanFront(const struct gl_context *ctx, + GLuint n, GLint x, GLint y, GLuint index[]); + static void ReadRGBASpanFront(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + GLubyte rgba[][4]); + static void ReadCI32PixelsFront(const struct gl_context *ctx, + GLuint n, const GLint x[], const GLint y[], + GLuint indx[], const GLubyte mask[]); + static void ReadRGBAPixelsFront(const struct gl_context *ctx, + GLuint n, const GLint x[], const GLint y[], + GLubyte rgba[][4], const GLubyte mask[]); + + // Back buffer functions + static void WriteRGBASpanBack(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + CONST GLubyte rgba[][4], + const GLubyte mask[]); + static void WriteRGBSpanBack(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + CONST GLubyte rgba[][3], + const GLubyte mask[]); + static void WriteMonoRGBASpanBack(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + const GLchan color[4], + const GLubyte mask[]); + static void WriteRGBAPixelsBack(const struct gl_context *ctx, GLuint n, + const GLint x[], const GLint y[], + CONST GLubyte rgba[][4], + const GLubyte mask[]); + static void WriteMonoRGBAPixelsBack(const struct gl_context *ctx, GLuint n, + const GLint x[], const GLint y[], + const GLchan color[4], + const GLubyte mask[]); + static void WriteCI32SpanBack(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + const GLuint index[], const GLubyte mask[]); + static void WriteCI8SpanBack(const struct gl_context *ctx, GLuint n, GLint x, GLint y, + const GLubyte index[], const GLubyte mask[]); + static void WriteMonoCISpanBack(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, GLuint colorIndex, + const GLubyte mask[]); + static void WriteCI32PixelsBack(const struct gl_context *ctx, + GLuint n, const GLint x[], const GLint y[], + const GLuint index[], const GLubyte mask[]); + static void WriteMonoCIPixelsBack(const struct gl_context *ctx, + GLuint n, const GLint x[], const GLint y[], + GLuint colorIndex, const GLubyte mask[]); + static void ReadCI32SpanBack(const struct gl_context *ctx, + GLuint n, GLint x, GLint y, GLuint index[]); + static void ReadRGBASpanBack(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + GLubyte rgba[][4]); + static void ReadCI32PixelsBack(const struct gl_context *ctx, + GLuint n, const GLint x[], const GLint y[], + GLuint indx[], const GLubyte mask[]); + static void ReadRGBAPixelsBack(const struct gl_context *ctx, + GLuint n, const GLint x[], const GLint y[], + GLubyte rgba[][4], const GLubyte mask[]); + +}; + +//------------------------------------------------------------------ +// Public interface methods +//------------------------------------------------------------------ + + +// +// Input: rect - initial rectangle +// name - window name +// resizingMode - example: B_FOLLOW_NONE +// mode - usually 0 ? +// options - Bitwise-OR of BGL_* tokens +// +BGLView::BGLView(BRect rect, char *name, + ulong resizingMode, ulong mode, + ulong options) + : BView(rect, name, B_FOLLOW_ALL_SIDES, mode | B_WILL_DRAW | B_FRAME_EVENTS) // | B_FULL_UPDATE_ON_RESIZE) +{ + // We don't support single buffering (yet): double buffering forced. + options |= BGL_DOUBLE; + + const GLboolean rgbFlag = ((options & BGL_INDEX) == 0); + const GLboolean alphaFlag = ((options & BGL_ALPHA) == BGL_ALPHA); + const GLboolean dblFlag = ((options & BGL_DOUBLE) == BGL_DOUBLE); + const GLboolean stereoFlag = false; + const GLint depth = (options & BGL_DEPTH) ? 16 : 0; + const GLint stencil = (options & BGL_STENCIL) ? 8 : 0; + const GLint accum = (options & BGL_ACCUM) ? 16 : 0; + const GLint index = (options & BGL_INDEX) ? 32 : 0; + const GLint red = rgbFlag ? 8 : 0; + const GLint green = rgbFlag ? 8 : 0; + const GLint blue = rgbFlag ? 8 : 0; + const GLint alpha = alphaFlag ? 8 : 0; + + m_options = options | BGL_INDIRECT; + + struct dd_function_table functions; + + if (!rgbFlag) { + fprintf(stderr, "Mesa Warning: color index mode not supported\n"); + } + + // Allocate auxiliary data object + MesaDriver * md = new MesaDriver(); + + // examine option flags and create gl_context struct + struct gl_config * visual = _mesa_create_visual( dblFlag, + stereoFlag, + red, green, blue, alpha, + depth, + stencil, + accum, accum, accum, accum, + 1 + ); + + // Initialize device driver function table + _mesa_init_driver_functions(&functions); + + functions.GetString = md->GetString; + functions.UpdateState = md->UpdateState; + functions.GetBufferSize = md->GetBufferSize; + functions.Clear = md->Clear; + functions.ClearIndex = md->ClearIndex; + functions.ClearColor = md->ClearColor; + functions.Error = md->Error; + functions.Viewport = md->Viewport; + + // create core context + struct gl_context *ctx = _mesa_create_context(visual, NULL, &functions, md); + if (! ctx) { + _mesa_destroy_visual(visual); + delete md; + return; + } + _mesa_enable_sw_extensions(ctx); + _mesa_enable_1_3_extensions(ctx); + _mesa_enable_1_4_extensions(ctx); + _mesa_enable_1_5_extensions(ctx); + + + // create core framebuffer + struct gl_framebuffer * buffer = _mesa_create_framebuffer(visual, + depth > 0 ? GL_TRUE : GL_FALSE, + stencil > 0 ? GL_TRUE: GL_FALSE, + accum > 0 ? GL_TRUE : GL_FALSE, + alphaFlag + ); + + /* Initialize the software rasterizer and helper modules. + */ + _swrast_CreateContext(ctx); + _vbo_CreateContext(ctx); + _tnl_CreateContext(ctx); + _swsetup_CreateContext(ctx); + _swsetup_Wakeup(ctx); + + md->Init(this, ctx, visual, buffer ); + + // Hook aux data into BGLView object + m_gc = md; + + // some stupid applications (Quake2) don't even think about calling LockGL() + // before using glGetString and friends... so make sure there is at least a + // valid context. + if (!_mesa_get_current_context()) { + LockGL(); + // not needed, we don't have a looper yet: UnlockLooper(); + } + +} + + +BGLView::~BGLView() +{ + // printf("BGLView destructor\n"); + MesaDriver * md = (MesaDriver *) m_gc; + assert(md); + delete md; +} + +void BGLView::LockGL() +{ + MesaDriver * md = (MesaDriver *) m_gc; + assert(md); + md->LockGL(); +} + +void BGLView::UnlockGL() +{ + MesaDriver * md = (MesaDriver *) m_gc; + assert(md); + md->UnlockGL(); +} + +void BGLView::SwapBuffers() +{ + SwapBuffers(false); +} + +void BGLView::SwapBuffers(bool vSync) +{ + MesaDriver * md = (MesaDriver *) m_gc; + assert(md); + md->SwapBuffers(); + + if (vSync) { + BScreen screen(Window()); + screen.WaitForRetrace(); + } +} + + +#if 0 +void BGLView::CopySubBufferMESA(GLint x, GLint y, GLuint width, GLuint height) +{ + MesaDriver * md = (MesaDriver *) m_gc; + assert(md); + md->CopySubBuffer(x, y, width, height); +} +#endif + +BView * BGLView::EmbeddedView() +{ + return NULL; +} + +status_t BGLView::CopyPixelsOut(BPoint source, BBitmap *dest) +{ + if (! dest || ! dest->Bounds().IsValid()) + return B_BAD_VALUE; + + MesaDriver * md = (MesaDriver *) m_gc; + assert(md); + return md->CopyPixelsOut(source, dest); +} + +status_t BGLView::CopyPixelsIn(BBitmap *source, BPoint dest) +{ + if (! source || ! source->Bounds().IsValid()) + return B_BAD_VALUE; + + MesaDriver * md = (MesaDriver *) m_gc; + assert(md); + return md->CopyPixelsIn(source, dest); +} + + +void BGLView::ErrorCallback(unsigned long errorCode) // Mesa's GLenum is not ulong but uint! +{ + char msg[32]; + sprintf(msg, "GL: Error code $%04lx.", errorCode); + // debugger(msg); + fprintf(stderr, "%s\n", msg); + return; +} + +void BGLView::Draw(BRect updateRect) +{ + // printf("BGLView::Draw()\n"); + MesaDriver * md = (MesaDriver *) m_gc; + assert(md); + md->Draw(updateRect); +} + +void BGLView::AttachedToWindow() +{ + BView::AttachedToWindow(); + + // don't paint window background white when resized + SetViewColor(B_TRANSPARENT_32_BIT); +} + +void BGLView::AllAttached() +{ + BView::AllAttached(); +// printf("BGLView AllAttached\n"); +} + +void BGLView::DetachedFromWindow() +{ + BView::DetachedFromWindow(); +} + +void BGLView::AllDetached() +{ + BView::AllDetached(); +// printf("BGLView AllDetached"); +} + +void BGLView::FrameResized(float width, float height) +{ + return BView::FrameResized(width, height); +} + +status_t BGLView::Perform(perform_code d, void *arg) +{ + return BView::Perform(d, arg); +} + + +status_t BGLView::Archive(BMessage *data, bool deep) const +{ + return BView::Archive(data, deep); +} + +void BGLView::MessageReceived(BMessage *msg) +{ + BView::MessageReceived(msg); +} + +void BGLView::SetResizingMode(uint32 mode) +{ + BView::SetResizingMode(mode); +} + +void BGLView::Show() +{ + BView::Show(); +} + +void BGLView::Hide() +{ + BView::Hide(); +} + +BHandler *BGLView::ResolveSpecifier(BMessage *msg, int32 index, + BMessage *specifier, int32 form, + const char *property) +{ + return BView::ResolveSpecifier(msg, index, specifier, form, property); +} + +status_t BGLView::GetSupportedSuites(BMessage *data) +{ + return BView::GetSupportedSuites(data); +} + +void BGLView::DirectConnected( direct_buffer_info *info ) +{ +#if 0 + if (! m_direct_connected && m_direct_connection_disabled) + return; + + direct_info_locker->Lock(); + switch(info->buffer_state & B_DIRECT_MODE_MASK) { + case B_DIRECT_START: + m_direct_connected = true; + case B_DIRECT_MODIFY: + // Get clipping information + if (m_clip_list) + free(m_clip_list); + m_clip_list_count = info->clip_list_count; + m_clip_list = (clipping_rect *) malloc(m_clip_list_count*sizeof(clipping_rect)); + if (m_clip_list) { + memcpy(m_clip_list, info->clip_list, m_clip_list_count*sizeof(clipping_rect)); + fBits = (uint8 *) info->bits; + fRowBytes = info->bytes_per_row; + fFormat = info->pixel_format; + fBounds = info->window_bounds; + fDirty = true; + } + break; + case B_DIRECT_STOP: + fConnected = false; + break; + } + direct_info_locker->Unlock(); +#endif +} + +void BGLView::EnableDirectMode( bool enabled ) +{ + // TODO +} + + +//---- virtual reserved methods ---------- + +void BGLView::_ReservedGLView1() {} +void BGLView::_ReservedGLView2() {} +void BGLView::_ReservedGLView3() {} +void BGLView::_ReservedGLView4() {} +void BGLView::_ReservedGLView5() {} +void BGLView::_ReservedGLView6() {} +void BGLView::_ReservedGLView7() {} +void BGLView::_ReservedGLView8() {} + +#if 0 +// Not implemented!!! + +BGLView::BGLView(const BGLView &v) + : BView(v) +{ + // XXX not sure how this should work + printf("Warning BGLView::copy constructor not implemented\n"); +} + +BGLView &BGLView::operator=(const BGLView &v) +{ + printf("Warning BGLView::operator= not implemented\n"); + return *this; +} +#endif + +void BGLView::dither_front() +{ + // no-op +} + +bool BGLView::confirm_dither() +{ + // no-op + return false; +} + +void BGLView::draw(BRect r) +{ + // XXX no-op ??? +} + +/* Direct Window stuff */ +void BGLView::drawScanline( int x1, int x2, int y, void *data ) +{ + // no-op +} + +void BGLView::scanlineHandler(struct rasStateRec *state, + GLint x1, GLint x2) +{ + // no-op +} + +void BGLView::lock_draw() +{ + // no-op +} + +void BGLView::unlock_draw() +{ + // no-op +} + +bool BGLView::validateView() +{ + // no-op + return true; +} + +// #pragma mark - + +MesaDriver::MesaDriver() +{ + m_glcontext = NULL; + m_glvisual = NULL; + m_glframebuffer = NULL; + m_bglview = NULL; + m_bitmap = NULL; + + m_clear_color[BE_RCOMP] = 0; + m_clear_color[BE_GCOMP] = 0; + m_clear_color[BE_BCOMP] = 0; + m_clear_color[BE_ACOMP] = 0; + + m_clear_index = 0; +} + + +MesaDriver::~MesaDriver() +{ + _mesa_destroy_visual(m_glvisual); + _mesa_destroy_framebuffer(m_glframebuffer); + _mesa_destroy_context(m_glcontext); + + delete m_bitmap; +} + + +void MesaDriver::Init(BGLView * bglview, struct gl_context * ctx, struct gl_config * visual, struct gl_framebuffer * framebuffer) +{ + m_bglview = bglview; + m_glcontext = ctx; + m_glvisual = visual; + m_glframebuffer = framebuffer; + + MesaDriver * md = (MesaDriver *) ctx->DriverCtx; + struct swrast_device_driver * swdd = _swrast_GetDeviceDriverReference( ctx ); + TNLcontext * tnl = TNL_CONTEXT(ctx); + + assert(md->m_glcontext == ctx ); + assert(tnl); + assert(swdd); + + // Use default TCL pipeline + tnl->Driver.RunPipeline = _tnl_run_pipeline; + + swdd->SetBuffer = this->SetBuffer; +} + + +void MesaDriver::LockGL() +{ + m_bglview->LockLooper(); + + UpdateState(m_glcontext, 0); + _mesa_make_current(m_glcontext, m_glframebuffer); +} + + +void MesaDriver::UnlockGL() +{ + if (m_bglview->Looper()->IsLocked()) + m_bglview->UnlockLooper(); + // Could call _mesa_make_current(NULL, NULL) but it would just + // hinder performance +} + + +void MesaDriver::SwapBuffers() const +{ + _mesa_notifySwapBuffers(m_glcontext); + + if (m_bitmap) { + m_bglview->LockLooper(); + m_bglview->DrawBitmap(m_bitmap); + m_bglview->UnlockLooper(); + }; +} + + +void MesaDriver::CopySubBuffer(GLint x, GLint y, GLuint width, GLuint height) const +{ + if (m_bitmap) { + // Source bitmap and view's bitmap are same size. + // Source and dest rectangle are the same. + // Note (x,y) = (0,0) is the lower-left corner, have to flip Y + BRect srcAndDest; + srcAndDest.left = x; + srcAndDest.right = x + width - 1; + srcAndDest.bottom = m_bottom - y; + srcAndDest.top = srcAndDest.bottom - height + 1; + m_bglview->DrawBitmap(m_bitmap, srcAndDest, srcAndDest); + } +} + +status_t MesaDriver::CopyPixelsOut(BPoint location, BBitmap *bitmap) +{ + color_space scs = m_bitmap->ColorSpace(); + color_space dcs = bitmap->ColorSpace(); + + if (scs != dcs && (scs != B_RGBA32 || dcs != B_RGB32)) { + printf("CopyPixelsOut(): incompatible color space: %s != %s\n", + color_space_name(scs), + color_space_name(dcs)); + return B_BAD_TYPE; + } + + // debugger("CopyPixelsOut()"); + + BRect sr = m_bitmap->Bounds(); + BRect dr = bitmap->Bounds(); + + sr = sr & dr.OffsetBySelf(location); + dr = sr.OffsetByCopy(-location.x, -location.y); + + uint8 *ps = (uint8 *) m_bitmap->Bits(); + uint8 *pd = (uint8 *) bitmap->Bits(); + uint32 *s, *d; + uint32 y; + for (y = (uint32) sr.top; y <= (uint32) sr.bottom; y++) { + s = (uint32 *) (ps + y * m_bitmap->BytesPerRow()); + s += (uint32) sr.left; + + d = (uint32 *) (pd + (y + (uint32) (dr.top - sr.top)) * bitmap->BytesPerRow()); + d += (uint32) dr.left; + + memcpy(d, s, dr.IntegerWidth() * 4); + } + return B_OK; +} + +status_t MesaDriver::CopyPixelsIn(BBitmap *bitmap, BPoint location) +{ + color_space scs = bitmap->ColorSpace(); + color_space dcs = m_bitmap->ColorSpace(); + + if (scs != dcs && (dcs != B_RGBA32 || scs != B_RGB32)) { + printf("CopyPixelsIn(): incompatible color space: %s != %s\n", + color_space_name(scs), + color_space_name(dcs)); + return B_BAD_TYPE; + } + + // debugger("CopyPixelsIn()"); + + BRect sr = bitmap->Bounds(); + BRect dr = m_bitmap->Bounds(); + + sr = sr & dr.OffsetBySelf(location); + dr = sr.OffsetByCopy(-location.x, -location.y); + + uint8 *ps = (uint8 *) bitmap->Bits(); + uint8 *pd = (uint8 *) m_bitmap->Bits(); + uint32 *s, *d; + uint32 y; + for (y = (uint32) sr.top; y <= (uint32) sr.bottom; y++) { + s = (uint32 *) (ps + y * bitmap->BytesPerRow()); + s += (uint32) sr.left; + + d = (uint32 *) (pd + (y + (uint32) (dr.top - sr.top)) * m_bitmap->BytesPerRow()); + d += (uint32) dr.left; + + memcpy(d, s, dr.IntegerWidth() * 4); + } + return B_OK; +} + + +void MesaDriver::Draw(BRect updateRect) const +{ + if (m_bitmap) + m_bglview->DrawBitmap(m_bitmap, updateRect, updateRect); +} + + +void MesaDriver::Error(struct gl_context *ctx) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + if (md && md->m_bglview) + md->m_bglview->ErrorCallback((unsigned long) ctx->ErrorValue); +} + +void MesaDriver::UpdateState( struct gl_context *ctx, GLuint new_state ) +{ + struct swrast_device_driver * swdd = _swrast_GetDeviceDriverReference( ctx ); + + _swrast_InvalidateState( ctx, new_state ); + _swsetup_InvalidateState( ctx, new_state ); + _vbo_InvalidateState( ctx, new_state ); + _tnl_InvalidateState( ctx, new_state ); + + if (ctx->Color.DrawBuffer[0] == GL_FRONT) { + /* read/write front buffer */ + swdd->WriteRGBASpan = MesaDriver::WriteRGBASpanFront; + swdd->WriteRGBSpan = MesaDriver::WriteRGBSpanFront; + swdd->WriteRGBAPixels = MesaDriver::WriteRGBAPixelsFront; + swdd->WriteMonoRGBASpan = MesaDriver::WriteMonoRGBASpanFront; + swdd->WriteMonoRGBAPixels = MesaDriver::WriteMonoRGBAPixelsFront; + swdd->WriteCI32Span = MesaDriver::WriteCI32SpanFront; + swdd->WriteCI8Span = MesaDriver::WriteCI8SpanFront; + swdd->WriteMonoCISpan = MesaDriver::WriteMonoCISpanFront; + swdd->WriteCI32Pixels = MesaDriver::WriteCI32PixelsFront; + swdd->WriteMonoCIPixels = MesaDriver::WriteMonoCIPixelsFront; + swdd->ReadRGBASpan = MesaDriver::ReadRGBASpanFront; + swdd->ReadRGBAPixels = MesaDriver::ReadRGBAPixelsFront; + swdd->ReadCI32Span = MesaDriver::ReadCI32SpanFront; + swdd->ReadCI32Pixels = MesaDriver::ReadCI32PixelsFront; + } + else { + /* read/write back buffer */ + swdd->WriteRGBASpan = MesaDriver::WriteRGBASpanBack; + swdd->WriteRGBSpan = MesaDriver::WriteRGBSpanBack; + swdd->WriteRGBAPixels = MesaDriver::WriteRGBAPixelsBack; + swdd->WriteMonoRGBASpan = MesaDriver::WriteMonoRGBASpanBack; + swdd->WriteMonoRGBAPixels = MesaDriver::WriteMonoRGBAPixelsBack; + swdd->WriteCI32Span = MesaDriver::WriteCI32SpanBack; + swdd->WriteCI8Span = MesaDriver::WriteCI8SpanBack; + swdd->WriteMonoCISpan = MesaDriver::WriteMonoCISpanBack; + swdd->WriteCI32Pixels = MesaDriver::WriteCI32PixelsBack; + swdd->WriteMonoCIPixels = MesaDriver::WriteMonoCIPixelsBack; + swdd->ReadRGBASpan = MesaDriver::ReadRGBASpanBack; + swdd->ReadRGBAPixels = MesaDriver::ReadRGBAPixelsBack; + swdd->ReadCI32Span = MesaDriver::ReadCI32SpanBack; + swdd->ReadCI32Pixels = MesaDriver::ReadCI32PixelsBack; + } +} + + +void MesaDriver::ClearIndex(struct gl_context *ctx, GLuint index) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + md->m_clear_index = index; +} + + +void MesaDriver::ClearColor(struct gl_context *ctx, const GLfloat color[4]) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + CLAMPED_FLOAT_TO_CHAN(md->m_clear_color[BE_RCOMP], color[0]); + CLAMPED_FLOAT_TO_CHAN(md->m_clear_color[BE_GCOMP], color[1]); + CLAMPED_FLOAT_TO_CHAN(md->m_clear_color[BE_BCOMP], color[2]); + CLAMPED_FLOAT_TO_CHAN(md->m_clear_color[BE_ACOMP], color[3]); + assert(md->m_bglview); +} + + +void MesaDriver::Clear(struct gl_context *ctx, GLbitfield mask, + GLboolean all, GLint x, GLint y, + GLint width, GLint height) +{ + if (mask & DD_FRONT_LEFT_BIT) + ClearFront(ctx, all, x, y, width, height); + if (mask & DD_BACK_LEFT_BIT) + ClearBack(ctx, all, x, y, width, height); + + mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT); + if (mask) + _swrast_Clear( ctx, mask, all, x, y, width, height ); + + return; +} + + +void MesaDriver::ClearFront(struct gl_context *ctx, + GLboolean all, GLint x, GLint y, + GLint width, GLint height) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + BGLView *bglview = md->m_bglview; + assert(bglview); + + bglview->SetHighColor(md->m_clear_color[BE_RCOMP], + md->m_clear_color[BE_GCOMP], + md->m_clear_color[BE_BCOMP], + md->m_clear_color[BE_ACOMP]); + bglview->SetLowColor(md->m_clear_color[BE_RCOMP], + md->m_clear_color[BE_GCOMP], + md->m_clear_color[BE_BCOMP], + md->m_clear_color[BE_ACOMP]); + if (all) { + BRect b = bglview->Bounds(); + bglview->FillRect(b); + } + else { + // XXX untested + BRect b; + b.left = x; + b.right = x + width; + b.bottom = md->m_height - y - 1; + b.top = b.bottom - height; + bglview->FillRect(b); + } + + // restore drawing color +#if 0 + bglview->SetHighColor(md->mColor[BE_RCOMP], + md->mColor[BE_GCOMP], + md->mColor[BE_BCOMP], + md->mColor[BE_ACOMP]); + bglview->SetLowColor(md->mColor[BE_RCOMP], + md->mColor[BE_GCOMP], + md->mColor[BE_BCOMP], + md->mColor[BE_ACOMP]); +#endif +} + + +void MesaDriver::ClearBack(struct gl_context *ctx, + GLboolean all, GLint x, GLint y, + GLint width, GLint height) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + BGLView *bglview = md->m_bglview; + assert(bglview); + BBitmap *bitmap = md->m_bitmap; + assert(bitmap); + GLuint *start = (GLuint *) bitmap->Bits(); + const GLuint *clearPixelPtr = (const GLuint *) md->m_clear_color; + const GLuint clearPixel = B_LENDIAN_TO_HOST_INT32(*clearPixelPtr); + + if (all) { + const int numPixels = md->m_width * md->m_height; + if (clearPixel == 0) { + memset(start, 0, numPixels * 4); + } + else { + for (int i = 0; i < numPixels; i++) { + start[i] = clearPixel; + } + } + } + else { + // XXX untested + start += y * md->m_width + x; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + start[j] = clearPixel; + } + start += md->m_width; + } + } +} + + +void MesaDriver::SetBuffer(struct gl_context *ctx, struct gl_framebuffer *buffer, + GLenum mode) +{ + /* TODO */ + (void) ctx; + (void) buffer; + (void) mode; +} + +void MesaDriver::GetBufferSize(struct gl_framebuffer * framebuffer, GLuint *width, + GLuint *height) +{ + GET_CURRENT_CONTEXT(ctx); + if (!ctx) + return; + + MesaDriver * md = (MesaDriver *) ctx->DriverCtx; + BGLView *bglview = md->m_bglview; + assert(bglview); + + BRect b = bglview->Bounds(); + *width = (GLuint) b.IntegerWidth() + 1; // (b.right - b.left + 1); + *height = (GLuint) b.IntegerHeight() + 1; // (b.bottom - b.top + 1); + md->m_bottom = (GLint) b.bottom; + + if (ctx->Visual.doubleBufferMode) { + if (*width != md->m_width || *height != md->m_height) { + // allocate new size of back buffer bitmap + if (md->m_bitmap) + delete md->m_bitmap; + BRect rect(0.0, 0.0, *width - 1, *height - 1); + md->m_bitmap = new BBitmap(rect, B_RGBA32); + } + } + else + { + md->m_bitmap = NULL; + } + + md->m_width = *width; + md->m_height = *height; +} + + +void MesaDriver::Viewport(struct gl_context *ctx, GLint x, GLint y, GLsizei w, GLsizei h) +{ + /* poll for window size change and realloc software Z/stencil/etc if needed */ + _mesa_ResizeBuffersMESA(); +} + + +const GLubyte *MesaDriver::GetString(struct gl_context *ctx, GLenum name) +{ + switch (name) { + case GL_RENDERER: + return (const GLubyte *) "Mesa " MESA_VERSION_STRING " powered BGLView (software)"; + default: + // Let core library handle all other cases + return NULL; + } +} + + +// Plot a pixel. (0,0) is upper-left corner +// This is only used when drawing to the front buffer. +inline void Plot(BGLView *bglview, int x, int y) +{ + // XXX There's got to be a better way! + BPoint p(x, y), q(x+1, y); + bglview->StrokeLine(p, q); +} + + +void MesaDriver::WriteRGBASpanFront(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + CONST GLubyte rgba[][4], + const GLubyte mask[]) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + BGLView *bglview = md->m_bglview; + assert(bglview); + int flippedY = md->m_bottom - y; + if (mask) { + for (GLuint i = 0; i < n; i++) { + if (mask[i]) { + bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2], rgba[i][3]); + Plot(bglview, x++, flippedY); + } + } + } + else { + for (GLuint i = 0; i < n; i++) { + bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2], rgba[i][3]); + Plot(bglview, x++, flippedY); + } + } +} + +void MesaDriver::WriteRGBSpanFront(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + CONST GLubyte rgba[][3], + const GLubyte mask[]) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + BGLView *bglview = md->m_bglview; + assert(bglview); + int flippedY = md->m_bottom - y; + if (mask) { + for (GLuint i = 0; i < n; i++) { + if (mask[i]) { + bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2]); + Plot(bglview, x++, flippedY); + } + } + } + else { + for (GLuint i = 0; i < n; i++) { + bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2]); + Plot(bglview, x++, flippedY); + } + } +} + +void MesaDriver::WriteMonoRGBASpanFront(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + const GLchan color[4], + const GLubyte mask[]) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + BGLView *bglview = md->m_bglview; + assert(bglview); + int flippedY = md->m_bottom - y; + bglview->SetHighColor(color[RCOMP], color[GCOMP], color[BCOMP]); + if (mask) { + for (GLuint i = 0; i < n; i++) { + if (mask[i]) { + Plot(bglview, x++, flippedY); + } + } + } + else { + for (GLuint i = 0; i < n; i++) { + Plot(bglview, x++, flippedY); + } + } +} + +void MesaDriver::WriteRGBAPixelsFront(const struct gl_context *ctx, + GLuint n, const GLint x[], const GLint y[], + CONST GLubyte rgba[][4], + const GLubyte mask[] ) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + BGLView *bglview = md->m_bglview; + assert(bglview); + if (mask) { + for (GLuint i = 0; i < n; i++) { + if (mask[i]) { + bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2]); + Plot(bglview, x[i], md->m_bottom - y[i]); + } + } + } + else { + for (GLuint i = 0; i < n; i++) { + bglview->SetHighColor(rgba[i][0], rgba[i][1], rgba[i][2]); + Plot(bglview, x[i], md->m_bottom - y[i]); + } + } +} + + +void MesaDriver::WriteMonoRGBAPixelsFront(const struct gl_context *ctx, GLuint n, + const GLint x[], const GLint y[], + const GLchan color[4], + const GLubyte mask[]) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + BGLView *bglview = md->m_bglview; + assert(bglview); + // plot points using current color + bglview->SetHighColor(color[RCOMP], color[GCOMP], color[BCOMP]); + if (mask) { + for (GLuint i = 0; i < n; i++) { + if (mask[i]) { + Plot(bglview, x[i], md->m_bottom - y[i]); + } + } + } + else { + for (GLuint i = 0; i < n; i++) { + Plot(bglview, x[i], md->m_bottom - y[i]); + } + } +} + + +void MesaDriver::WriteCI32SpanFront( const struct gl_context *ctx, GLuint n, GLint x, GLint y, + const GLuint index[], const GLubyte mask[] ) +{ + printf("WriteCI32SpanFront() not implemented yet!\n"); + // TODO +} + +void MesaDriver::WriteCI8SpanFront( const struct gl_context *ctx, GLuint n, GLint x, GLint y, + const GLubyte index[], const GLubyte mask[] ) +{ + printf("WriteCI8SpanFront() not implemented yet!\n"); + // TODO +} + +void MesaDriver::WriteMonoCISpanFront( const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + GLuint colorIndex, const GLubyte mask[] ) +{ + printf("WriteMonoCISpanFront() not implemented yet!\n"); + // TODO +} + + +void MesaDriver::WriteCI32PixelsFront( const struct gl_context *ctx, GLuint n, + const GLint x[], const GLint y[], + const GLuint index[], const GLubyte mask[] ) +{ + printf("WriteCI32PixelsFront() not implemented yet!\n"); + // TODO +} + +void MesaDriver::WriteMonoCIPixelsFront( const struct gl_context *ctx, GLuint n, + const GLint x[], const GLint y[], + GLuint colorIndex, const GLubyte mask[] ) +{ + printf("WriteMonoCIPixelsFront() not implemented yet!\n"); + // TODO +} + + +void MesaDriver::ReadCI32SpanFront( const struct gl_context *ctx, + GLuint n, GLint x, GLint y, GLuint index[] ) +{ + printf("ReadCI32SpanFront() not implemented yet!\n"); + // TODO +} + + +void MesaDriver::ReadRGBASpanFront( const struct gl_context *ctx, GLuint n, + GLint x, GLint y, GLubyte rgba[][4] ) +{ + printf("ReadRGBASpanFront() not implemented yet!\n"); + // TODO +} + + +void MesaDriver::ReadCI32PixelsFront( const struct gl_context *ctx, + GLuint n, const GLint x[], const GLint y[], + GLuint indx[], const GLubyte mask[] ) +{ + printf("ReadCI32PixelsFront() not implemented yet!\n"); + // TODO +} + + +void MesaDriver::ReadRGBAPixelsFront( const struct gl_context *ctx, + GLuint n, const GLint x[], const GLint y[], + GLubyte rgba[][4], const GLubyte mask[] ) +{ + printf("ReadRGBAPixelsFront() not implemented yet!\n"); + // TODO +} + + + + +void MesaDriver::WriteRGBASpanBack(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + CONST GLubyte rgba[][4], + const GLubyte mask[]) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + BBitmap *bitmap = md->m_bitmap; + + assert(bitmap); + + int row = md->m_bottom - y; + uint8 * ptr = (uint8 *) bitmap->Bits() + (row * bitmap->BytesPerRow()) + x * 4; + uint32 * pixel = (uint32 *) ptr; + + if (mask) { + while(n--) { + if (*mask++) + *pixel = PACK_B_RGBA32(rgba[0]); + pixel++; + rgba++; + }; + } else { + while(n--) { + *pixel++ = PACK_B_RGBA32(rgba[0]); + rgba++; + }; + }; + } + + +void MesaDriver::WriteRGBSpanBack(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + CONST GLubyte rgb[][3], + const GLubyte mask[]) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + BBitmap *bitmap = md->m_bitmap; + + assert(bitmap); + + int row = md->m_bottom - y; + uint8 * ptr = (uint8 *) bitmap->Bits() + (row * bitmap->BytesPerRow()) + x * 4; + uint32 * pixel = (uint32 *) ptr; + + if (mask) { + while(n--) { + if (*mask++) + *pixel = PACK_B_RGB32(rgb[0]); + pixel++; + rgb++; + }; + } else { + while(n--) { + *pixel++ = PACK_B_RGB32(rgb[0]); + rgb++; + }; + }; +} + + + + +void MesaDriver::WriteMonoRGBASpanBack(const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + const GLchan color[4], const GLubyte mask[]) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + BBitmap *bitmap = md->m_bitmap; + + assert(bitmap); + + int row = md->m_bottom - y; + uint8 * ptr = (uint8 *) bitmap->Bits() + (row * bitmap->BytesPerRow()) + x * 4; + uint32 * pixel = (uint32 *) ptr; + uint32 pixel_color = PACK_B_RGBA32(color); + + if (mask) { + while(n--) { + if (*mask++) + *pixel = pixel_color; + pixel++; + }; + } else { + while(n--) { + *pixel++ = pixel_color; + }; + }; +} + + +void MesaDriver::WriteRGBAPixelsBack(const struct gl_context *ctx, + GLuint n, const GLint x[], const GLint y[], + CONST GLubyte rgba[][4], + const GLubyte mask[] ) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + BBitmap *bitmap = md->m_bitmap; + + assert(bitmap); +#if 0 + while(n--) { + if (*mask++) { + int row = md->m_bottom - *y; + uint8 * pixel = (uint8 *) bitmap->Bits() + (row * bitmap->BytesPerRow()) + *x * 4; + *((uint32 *) pixel) = PACK_B_RGBA32(rgba[0]); + }; + x++; + y++; + rgba++; + }; +#else + if (mask) { + for (GLuint i = 0; i < n; i++) { + if (mask[i]) { + GLubyte *pixel = (GLubyte *) bitmap->Bits() + + ((md->m_bottom - y[i]) * bitmap->BytesPerRow()) + x[i] * 4; + pixel[BE_RCOMP] = rgba[i][RCOMP]; + pixel[BE_GCOMP] = rgba[i][GCOMP]; + pixel[BE_BCOMP] = rgba[i][BCOMP]; + pixel[BE_ACOMP] = rgba[i][ACOMP]; + } + } + } + else { + for (GLuint i = 0; i < n; i++) { + GLubyte *pixel = (GLubyte *) bitmap->Bits() + + ((md->m_bottom - y[i]) * bitmap->BytesPerRow()) + x[i] * 4; + pixel[BE_RCOMP] = rgba[i][RCOMP]; + pixel[BE_GCOMP] = rgba[i][GCOMP]; + pixel[BE_BCOMP] = rgba[i][BCOMP]; + pixel[BE_ACOMP] = rgba[i][ACOMP]; + } + } +#endif +} + + +void MesaDriver::WriteMonoRGBAPixelsBack(const struct gl_context *ctx, GLuint n, + const GLint x[], const GLint y[], + const GLchan color[4], + const GLubyte mask[]) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + BBitmap *bitmap = md->m_bitmap; + + assert(bitmap); + + uint32 pixel_color = PACK_B_RGBA32(color); +#if 0 + while(n--) { + if (*mask++) { + int row = md->m_bottom - *y; + uint8 * pixel = (uint8 *) bitmap->Bits() + (row * bitmap->BytesPerRow()) + *x * 4; + + *((uint32 *) pixel) = pixel_color; + }; + x++; + y++; + }; +#else + if (mask) { + for (GLuint i = 0; i < n; i++) { + if (mask[i]) { + GLubyte * ptr = (GLubyte *) bitmap->Bits() + + ((md->m_bottom - y[i]) * bitmap->BytesPerRow()) + x[i] * 4; + *((uint32 *) ptr) = pixel_color; + } + } + } + else { + for (GLuint i = 0; i < n; i++) { + GLubyte * ptr = (GLubyte *) bitmap->Bits() + + ((md->m_bottom - y[i]) * bitmap->BytesPerRow()) + x[i] * 4; + *((uint32 *) ptr) = pixel_color; + } + } +#endif +} + + +void MesaDriver::WriteCI32SpanBack( const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + const GLuint index[], const GLubyte mask[] ) +{ + printf("WriteCI32SpanBack() not implemented yet!\n"); + // TODO +} + +void MesaDriver::WriteCI8SpanBack( const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + const GLubyte index[], const GLubyte mask[] ) +{ + printf("WriteCI8SpanBack() not implemented yet!\n"); + // TODO +} + +void MesaDriver::WriteMonoCISpanBack( const struct gl_context *ctx, GLuint n, + GLint x, GLint y, + GLuint colorIndex, const GLubyte mask[] ) +{ + printf("WriteMonoCISpanBack() not implemented yet!\n"); + // TODO +} + + +void MesaDriver::WriteCI32PixelsBack( const struct gl_context *ctx, GLuint n, + const GLint x[], const GLint y[], + const GLuint index[], const GLubyte mask[] ) +{ + printf("WriteCI32PixelsBack() not implemented yet!\n"); + // TODO +} + +void MesaDriver::WriteMonoCIPixelsBack( const struct gl_context *ctx, GLuint n, + const GLint x[], const GLint y[], + GLuint colorIndex, const GLubyte mask[] ) +{ + printf("WriteMonoCIPixelsBack() not implemented yet!\n"); + // TODO +} + + +void MesaDriver::ReadCI32SpanBack( const struct gl_context *ctx, + GLuint n, GLint x, GLint y, GLuint index[] ) +{ + printf("ReadCI32SpanBack() not implemented yet!\n"); + // TODO +} + + +void MesaDriver::ReadRGBASpanBack( const struct gl_context *ctx, GLuint n, + GLint x, GLint y, GLubyte rgba[][4] ) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + const BBitmap *bitmap = md->m_bitmap; + assert(bitmap); + int row = md->m_bottom - y; + const GLubyte *pixel = (GLubyte *) bitmap->Bits() + + (row * bitmap->BytesPerRow()) + x * 4; + + for (GLuint i = 0; i < n; i++) { + rgba[i][RCOMP] = pixel[BE_RCOMP]; + rgba[i][GCOMP] = pixel[BE_GCOMP]; + rgba[i][BCOMP] = pixel[BE_BCOMP]; + rgba[i][ACOMP] = pixel[BE_ACOMP]; + pixel += 4; + } +} + + +void MesaDriver::ReadCI32PixelsBack( const struct gl_context *ctx, + GLuint n, const GLint x[], const GLint y[], + GLuint indx[], const GLubyte mask[] ) +{ + printf("ReadCI32PixelsBack() not implemented yet!\n"); + // TODO +} + + +void MesaDriver::ReadRGBAPixelsBack( const struct gl_context *ctx, + GLuint n, const GLint x[], const GLint y[], + GLubyte rgba[][4], const GLubyte mask[] ) +{ + MesaDriver *md = (MesaDriver *) ctx->DriverCtx; + const BBitmap *bitmap = md->m_bitmap; + assert(bitmap); + + if (mask) { + for (GLuint i = 0; i < n; i++) { + if (mask[i]) { + GLubyte *pixel = (GLubyte *) bitmap->Bits() + + ((md->m_bottom - y[i]) * bitmap->BytesPerRow()) + x[i] * 4; + rgba[i][RCOMP] = pixel[BE_RCOMP]; + rgba[i][GCOMP] = pixel[BE_GCOMP]; + rgba[i][BCOMP] = pixel[BE_BCOMP]; + rgba[i][ACOMP] = pixel[BE_ACOMP]; + }; + }; + } else { + for (GLuint i = 0; i < n; i++) { + GLubyte *pixel = (GLubyte *) bitmap->Bits() + + ((md->m_bottom - y[i]) * bitmap->BytesPerRow()) + x[i] * 4; + rgba[i][RCOMP] = pixel[BE_RCOMP]; + rgba[i][GCOMP] = pixel[BE_GCOMP]; + rgba[i][BCOMP] = pixel[BE_BCOMP]; + rgba[i][ACOMP] = pixel[BE_ACOMP]; + }; + }; +} + +const char * color_space_name(color_space space) +{ +#define C2N(a) case a: return #a + + switch (space) { + C2N(B_RGB24); + C2N(B_RGB32); + C2N(B_RGBA32); + C2N(B_RGB32_BIG); + C2N(B_RGBA32_BIG); + C2N(B_GRAY8); + C2N(B_GRAY1); + C2N(B_RGB16); + C2N(B_RGB15); + C2N(B_RGBA15); + C2N(B_CMAP8); + default: + return "Unknown!"; + }; + +#undef C2N +}; + + diff --git a/src/mesa/drivers/beos/Makefile b/src/mesa/drivers/beos/Makefile new file mode 100644 index 0000000..c79dd24 --- /dev/null +++ b/src/mesa/drivers/beos/Makefile @@ -0,0 +1,199 @@ +# src/mesa/drivers/beos/Makefile + +TOP = ../../../.. +include $(TOP)/configs/current + +include $(TOP)/src/mesa/sources + +MESA_MODULES = $(TOP)/src/mesa/mesa.a +# To switch back to old Mesa GLU implementation (but why do +# you want this!), uncomment this next line: + +# GLU_DIR = $(TOP)/src/glu/mesa +ifeq ($(GLU_DIR),) +# By default, we build the SGI GLU implementation + GLU_DIR = $(TOP)/src/glu/sgi +endif + +ifeq ($(GLU_DIR), $(TOP)/src/glu/mesa) + GLU_MODULES = \ + $(GLU_DIR)/glu.o \ + $(GLU_DIR)/mipmap.o \ + $(GLU_DIR)/nurbs.o \ + $(GLU_DIR)/nurbscrv.o \ + $(GLU_DIR)/nurbssrf.o \ + $(GLU_DIR)/nurbsutl.o \ + $(GLU_DIR)/polytest.o \ + $(GLU_DIR)/project.o \ + $(GLU_DIR)/quadric.o \ + $(GLU_DIR)/tess.o \ + $(GLU_DIR)/tesselat.o +else + GLU_MODULES = \ + $(GLU_DIR)/libutil/error.o \ + $(GLU_DIR)/libutil/glue.o \ + $(GLU_DIR)/libutil/mipmap.o \ + $(GLU_DIR)/libutil/project.o \ + $(GLU_DIR)/libutil/quad.o \ + $(GLU_DIR)/libutil/registry.o \ + $(GLU_DIR)/libtess/dict.o \ + $(GLU_DIR)/libtess/geom.o \ + $(GLU_DIR)/libtess/memalloc.o \ + $(GLU_DIR)/libtess/mesh.o \ + $(GLU_DIR)/libtess/normal.o \ + $(GLU_DIR)/libtess/priorityq.o \ + $(GLU_DIR)/libtess/render.o \ + $(GLU_DIR)/libtess/sweep.o \ + $(GLU_DIR)/libtess/tess.o \ + $(GLU_DIR)/libtess/tessmono.o \ + $(GLU_DIR)/libnurbs/interface/bezierEval.o \ + $(GLU_DIR)/libnurbs/interface/bezierPatch.o \ + $(GLU_DIR)/libnurbs/interface/bezierPatchMesh.o \ + $(GLU_DIR)/libnurbs/interface/glcurveval.o \ + $(GLU_DIR)/libnurbs/interface/glinterface.o \ + $(GLU_DIR)/libnurbs/interface/glrenderer.o \ + $(GLU_DIR)/libnurbs/interface/glsurfeval.o \ + $(GLU_DIR)/libnurbs/interface/incurveeval.o \ + $(GLU_DIR)/libnurbs/interface/insurfeval.o \ + $(GLU_DIR)/libnurbs/internals/arc.o \ + $(GLU_DIR)/libnurbs/internals/arcsorter.o \ + $(GLU_DIR)/libnurbs/internals/arctess.o \ + $(GLU_DIR)/libnurbs/internals/backend.o \ + $(GLU_DIR)/libnurbs/internals/basiccrveval.o \ + $(GLU_DIR)/libnurbs/internals/basicsurfeval.o \ + $(GLU_DIR)/libnurbs/internals/bin.o \ + $(GLU_DIR)/libnurbs/internals/bufpool.o \ + $(GLU_DIR)/libnurbs/internals/cachingeval.o \ + $(GLU_DIR)/libnurbs/internals/ccw.o \ + $(GLU_DIR)/libnurbs/internals/coveandtiler.o \ + $(GLU_DIR)/libnurbs/internals/curve.o \ + $(GLU_DIR)/libnurbs/internals/curvelist.o \ + $(GLU_DIR)/libnurbs/internals/curvesub.o \ + $(GLU_DIR)/libnurbs/internals/dataTransform.o \ + $(GLU_DIR)/libnurbs/internals/displaylist.o \ + $(GLU_DIR)/libnurbs/internals/flist.o \ + $(GLU_DIR)/libnurbs/internals/flistsorter.o \ + $(GLU_DIR)/libnurbs/internals/hull.o \ + $(GLU_DIR)/libnurbs/internals/intersect.o \ + $(GLU_DIR)/libnurbs/internals/knotvector.o \ + $(GLU_DIR)/libnurbs/internals/mapdesc.o \ + $(GLU_DIR)/libnurbs/internals/mapdescv.o \ + $(GLU_DIR)/libnurbs/internals/maplist.o \ + $(GLU_DIR)/libnurbs/internals/mesher.o \ + $(GLU_DIR)/libnurbs/internals/monoTriangulationBackend.o \ + $(GLU_DIR)/libnurbs/internals/monotonizer.o \ + $(GLU_DIR)/libnurbs/internals/mycode.o \ + $(GLU_DIR)/libnurbs/internals/nurbsinterfac.o \ + $(GLU_DIR)/libnurbs/internals/nurbstess.o \ + $(GLU_DIR)/libnurbs/internals/patch.o \ + $(GLU_DIR)/libnurbs/internals/patchlist.o \ + $(GLU_DIR)/libnurbs/internals/quilt.o \ + $(GLU_DIR)/libnurbs/internals/reader.o \ + $(GLU_DIR)/libnurbs/internals/renderhints.o \ + $(GLU_DIR)/libnurbs/internals/slicer.o \ + $(GLU_DIR)/libnurbs/internals/sorter.o \ + $(GLU_DIR)/libnurbs/internals/splitarcs.o \ + $(GLU_DIR)/libnurbs/internals/subdivider.o \ + $(GLU_DIR)/libnurbs/internals/tobezier.o \ + $(GLU_DIR)/libnurbs/internals/trimline.o \ + $(GLU_DIR)/libnurbs/internals/trimregion.o \ + $(GLU_DIR)/libnurbs/internals/trimvertpool.o \ + $(GLU_DIR)/libnurbs/internals/uarray.o \ + $(GLU_DIR)/libnurbs/internals/varray.o \ + $(GLU_DIR)/libnurbs/nurbtess/directedLine.o \ + $(GLU_DIR)/libnurbs/nurbtess/gridWrap.o \ + $(GLU_DIR)/libnurbs/nurbtess/monoChain.o \ + $(GLU_DIR)/libnurbs/nurbtess/monoPolyPart.o \ + $(GLU_DIR)/libnurbs/nurbtess/monoTriangulation.o \ + $(GLU_DIR)/libnurbs/nurbtess/partitionX.o \ + $(GLU_DIR)/libnurbs/nurbtess/partitionY.o \ + $(GLU_DIR)/libnurbs/nurbtess/polyDBG.o \ + $(GLU_DIR)/libnurbs/nurbtess/polyUtil.o \ + $(GLU_DIR)/libnurbs/nurbtess/primitiveStream.o \ + $(GLU_DIR)/libnurbs/nurbtess/quicksort.o \ + $(GLU_DIR)/libnurbs/nurbtess/rectBlock.o \ + $(GLU_DIR)/libnurbs/nurbtess/sampleComp.o \ + $(GLU_DIR)/libnurbs/nurbtess/sampleCompBot.o \ + $(GLU_DIR)/libnurbs/nurbtess/sampleCompRight.o \ + $(GLU_DIR)/libnurbs/nurbtess/sampleCompTop.o \ + $(GLU_DIR)/libnurbs/nurbtess/sampleMonoPoly.o \ + $(GLU_DIR)/libnurbs/nurbtess/sampledLine.o \ + $(GLU_DIR)/libnurbs/nurbtess/searchTree.o +endif + +INCLUDES = \ + -I../common \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/mesa/array_cache \ + -I$(TOP)/src/mesa/main \ + -I$(TOP)/src/mesa/glapi \ + -I$(TOP)/src/mesa/math \ + -I$(TOP)/src/mesa/shader \ + -I$(TOP)/src/mesa/swrast \ + -I$(TOP)/src/mesa/swrast_setup \ + -I$(TOP)/src/mesa/tnl \ + -I$(TOP)/src/mesa/tnl_dd \ + -I$(TOP)/src/mesa/x86 \ + -I. \ + -I- \ + -I$(TOP)/include + +DRIVER_SOURCES = \ + GLView.cpp \ + ../common/driverfuncs.c \ + $(addprefix ../../, $(GLAPI_SOURCES)) + +ifeq ($(CPU), x86) + DRIVER_SOURCES += $(addprefix ../../, $(X86_API)) +else +# No GL API PPC optimization yet +endif + +DRIVER_OBJECTS = $(DRIVER_SOURCES:.c=.o) +DRIVER_OBJECTS := $(DRIVER_OBJECTS:.S=.o) + +OBJECTS := $(DRIVER_OBJECTS:.cpp=.o) + + +# Rules + +.c.o: + $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@ + +.cpp.o: + $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@ + +.S.o: + $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@ + + +default: depend $(TOP)/$(LIB_DIR) $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) + +# XXX FIXME: mesa.a might be libmesa.a now +$(MESA_MODULES): + cd $(TOP)/src/mesa && $(MAKE) mesa.a ; + mimeset -f "$@" + +$(GLU_MODULES): + cd $(GLU_DIR) && $(MAKE) $(subst $(GLU_DIR)/,,$(GLU_MODULES)) ; + +$(TOP)/$(LIB_DIR): + mkdir $(TOP)/$(LIB_DIR) + +$(TOP)/$(LIB_DIR)/$(GL_LIB_NAME): $(OBJECTS) $(MESA_MODULES) $(GLU_MODULES) + @$(MKLIB) -o $(GL_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + -major $(MESA_MAJOR) -minor $(MESA_MINOR) -patch $(MESA_TINY) \ + -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) $(GL_LIB_DEPS) \ + $(OBJECTS) $(MESA_MODULES) $(GLU_MODULES) + +# $(GLU_OBJECTS): +# cd $(GLU_DIR) && $(MAKE) $< ; + +depend: $(DRIVER_SOURCES) $(GLU_SOURCES) + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(DRIVER_SOURCES) $(GLU_SOURCES) > /dev/null + +clean: + -rm -f depend depend.bak $(OBJECTS) + +include depend diff --git a/src/mesa/drivers/common/descrip.mms b/src/mesa/drivers/common/descrip.mms new file mode 100644 index 0000000..d5bbc69 --- /dev/null +++ b/src/mesa/drivers/common/descrip.mms @@ -0,0 +1,42 @@ +# Makefile for core library for VMS +# contributed by Jouk Jansen joukj@hrem.nano.tudelft.nl +# Last revision : 29 September 2008 + +.first + define gl [----.include.gl] + define math [--.math] + define tnl [--.tnl] + define swrast [--.swrast] + define glapi [--.glapi] + define shader [--.shader] + define main [--.main] + +.include [----]mms-config. + +##### MACROS ##### + +VPATH = RCS + +INCDIR = [----.include],[--.main],[--.glapi],[--.shader] +LIBDIR = [----.lib] +CFLAGS = /include=($(INCDIR),[])/define=(PTHREADS=1)/name=(as_is,short)\ + /float=ieee/ieee=denorm/warn=disable=(PTRMISMATCH) + +SOURCES = driverfuncs.c + +OBJECTS =driverfuncs.obj + +##### RULES ##### + +VERSION=Mesa V3.4 + +##### TARGETS ##### +# Make the library +$(LIBDIR)$(GL_LIB) : $(OBJECTS) + @ library $(LIBDIR)$(GL_LIB) $(OBJECTS) + +clean : + purge + delete *.obj;* + +driverfuncs.obj : driverfuncs.c diff --git a/src/mesa/drivers/common/driverfuncs.c b/src/mesa/drivers/common/driverfuncs.c new file mode 100644 index 0000000..fc67bee --- /dev/null +++ b/src/mesa/drivers/common/driverfuncs.c @@ -0,0 +1,324 @@ +/* + * Mesa 3-D graphics library + * Version: 7.1 + * + * Copyright (C) 1999-2007 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. + */ + + +#include "main/glheader.h" +#include "main/imports.h" +#include "main/arrayobj.h" +#include "main/context.h" +#include "main/framebuffer.h" +#include "main/mipmap.h" +#include "main/queryobj.h" +#include "main/renderbuffer.h" +#include "main/shaderobj.h" +#include "main/texcompress.h" +#include "main/texformat.h" +#include "main/texgetimage.h" +#include "main/teximage.h" +#include "main/texobj.h" +#include "main/texstore.h" +#include "main/bufferobj.h" +#include "main/fbobject.h" +#include "main/texrender.h" +#include "main/syncobj.h" +#include "main/transformfeedback.h" + +#include "program/program.h" +#include "tnl/tnl.h" +#include "swrast/swrast.h" + +#include "driverfuncs.h" +#include "meta.h" + + + +/** + * Plug in default functions for all pointers in the dd_function_table + * structure. + * Device drivers should call this function and then plug in any + * functions which it wants to override. + * Some functions (pointers) MUST be implemented by all drivers (REQUIRED). + * + * \param table the dd_function_table to initialize + */ +void +_mesa_init_driver_functions(struct dd_function_table *driver) +{ + memset(driver, 0, sizeof(*driver)); + + driver->GetString = NULL; /* REQUIRED! */ + driver->UpdateState = NULL; /* REQUIRED! */ + driver->GetBufferSize = NULL; /* REQUIRED! */ + driver->ResizeBuffers = _mesa_resize_framebuffer; + driver->Error = NULL; + + driver->Finish = NULL; + driver->Flush = NULL; + + /* framebuffer/image functions */ + driver->Clear = _swrast_Clear; + driver->Accum = _swrast_Accum; + driver->RasterPos = _tnl_RasterPos; + driver->DrawPixels = _swrast_DrawPixels; + driver->ReadPixels = _swrast_ReadPixels; + driver->CopyPixels = _swrast_CopyPixels; + driver->Bitmap = _swrast_Bitmap; + + /* Texture functions */ + driver->ChooseTextureFormat = _mesa_choose_tex_format; + driver->TexImage1D = _mesa_store_teximage1d; + driver->TexImage2D = _mesa_store_teximage2d; + driver->TexImage3D = _mesa_store_teximage3d; + driver->TexSubImage1D = _mesa_store_texsubimage1d; + driver->TexSubImage2D = _mesa_store_texsubimage2d; + driver->TexSubImage3D = _mesa_store_texsubimage3d; + driver->GetTexImage = _mesa_get_teximage; + driver->CopyTexImage1D = _mesa_meta_CopyTexImage1D; + driver->CopyTexImage2D = _mesa_meta_CopyTexImage2D; + driver->CopyTexSubImage1D = _mesa_meta_CopyTexSubImage1D; + driver->CopyTexSubImage2D = _mesa_meta_CopyTexSubImage2D; + driver->CopyTexSubImage3D = _mesa_meta_CopyTexSubImage3D; + driver->GenerateMipmap = _mesa_meta_GenerateMipmap; + driver->TestProxyTexImage = _mesa_test_proxy_teximage; + driver->CompressedTexImage1D = _mesa_store_compressed_teximage1d; + driver->CompressedTexImage2D = _mesa_store_compressed_teximage2d; + driver->CompressedTexImage3D = _mesa_store_compressed_teximage3d; + driver->CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d; + driver->CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d; + driver->CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d; + driver->GetCompressedTexImage = _mesa_get_compressed_teximage; + driver->BindTexture = NULL; + driver->NewTextureObject = _mesa_new_texture_object; + driver->DeleteTexture = _mesa_delete_texture_object; + driver->NewTextureImage = _mesa_new_texture_image; + driver->FreeTexImageData = _mesa_free_texture_image_data; + driver->MapTexture = NULL; + driver->UnmapTexture = NULL; + driver->TextureMemCpy = memcpy; + driver->IsTextureResident = NULL; + driver->UpdateTexturePalette = NULL; + + /* imaging */ + driver->CopyColorTable = _mesa_meta_CopyColorTable; + driver->CopyColorSubTable = _mesa_meta_CopyColorSubTable; + + /* Vertex/fragment programs */ + driver->BindProgram = NULL; + driver->NewProgram = _mesa_new_program; + driver->DeleteProgram = _mesa_delete_program; + + /* simple state commands */ + driver->AlphaFunc = NULL; + driver->BlendColor = NULL; + driver->BlendEquationSeparate = NULL; + driver->BlendFuncSeparate = NULL; + driver->ClearColor = NULL; + driver->ClearDepth = NULL; + driver->ClearStencil = NULL; + driver->ClipPlane = NULL; + driver->ColorMask = NULL; + driver->ColorMaterial = NULL; + driver->CullFace = NULL; + driver->DrawBuffer = NULL; + driver->DrawBuffers = NULL; + driver->FrontFace = NULL; + driver->DepthFunc = NULL; + driver->DepthMask = NULL; + driver->DepthRange = NULL; + driver->Enable = NULL; + driver->Fogfv = NULL; + driver->Hint = NULL; + driver->Lightfv = NULL; + driver->LightModelfv = NULL; + driver->LineStipple = NULL; + driver->LineWidth = NULL; + driver->LogicOpcode = NULL; + driver->PointParameterfv = NULL; + driver->PointSize = NULL; + driver->PolygonMode = NULL; + driver->PolygonOffset = NULL; + driver->PolygonStipple = NULL; + driver->ReadBuffer = NULL; + driver->RenderMode = NULL; + driver->Scissor = NULL; + driver->ShadeModel = NULL; + driver->StencilFuncSeparate = NULL; + driver->StencilOpSeparate = NULL; + driver->StencilMaskSeparate = NULL; + driver->TexGen = NULL; + driver->TexEnv = NULL; + driver->TexParameter = NULL; + driver->Viewport = NULL; + + /* buffer objects */ + _mesa_init_buffer_object_functions(driver); + + /* query objects */ + _mesa_init_query_object_functions(driver); + + _mesa_init_sync_object_functions(driver); + + driver->NewFramebuffer = _mesa_new_framebuffer; + driver->NewRenderbuffer = _mesa_new_soft_renderbuffer; + driver->RenderTexture = _mesa_render_texture; + driver->FinishRenderTexture = _mesa_finish_render_texture; + driver->FramebufferRenderbuffer = _mesa_framebuffer_renderbuffer; + + driver->BlitFramebuffer = _swrast_BlitFramebuffer; + + /* APPLE_vertex_array_object */ + driver->NewArrayObject = _mesa_new_array_object; + driver->DeleteArrayObject = _mesa_delete_array_object; + driver->BindArrayObject = NULL; + + _mesa_init_shader_object_functions(driver); + + _mesa_init_transform_feedback_functions(driver); + + /* T&L stuff */ + driver->NeedValidate = GL_FALSE; + driver->ValidateTnlModule = NULL; + driver->CurrentExecPrimitive = 0; + driver->CurrentSavePrimitive = 0; + driver->NeedFlush = 0; + driver->SaveNeedFlush = 0; + + driver->ProgramStringNotify = _tnl_program_string; + driver->FlushVertices = NULL; + driver->SaveFlushVertices = NULL; + driver->NotifySaveBegin = NULL; + driver->LightingSpaceChange = NULL; + + /* display list */ + driver->NewList = NULL; + driver->EndList = NULL; + driver->BeginCallList = NULL; + driver->EndCallList = NULL; +} + + +/** + * Call the ctx->Driver.* state functions with current values to initialize + * driver state. + * Only the Intel drivers use this so far. + */ +void +_mesa_init_driver_state(struct gl_context *ctx) +{ + ctx->Driver.AlphaFunc(ctx, ctx->Color.AlphaFunc, ctx->Color.AlphaRef); + + ctx->Driver.BlendColor(ctx, ctx->Color.BlendColor); + + ctx->Driver.BlendEquationSeparate(ctx, + ctx->Color.BlendEquationRGB, + ctx->Color.BlendEquationA); + + ctx->Driver.BlendFuncSeparate(ctx, + ctx->Color.BlendSrcRGB, + ctx->Color.BlendDstRGB, + ctx->Color.BlendSrcA, ctx->Color.BlendDstA); + + if (ctx->Driver.ColorMaskIndexed) { + GLuint i; + for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) { + ctx->Driver.ColorMaskIndexed(ctx, i, + ctx->Color.ColorMask[0][RCOMP], + ctx->Color.ColorMask[0][GCOMP], + ctx->Color.ColorMask[0][BCOMP], + ctx->Color.ColorMask[0][ACOMP]); + } + } + else { + ctx->Driver.ColorMask(ctx, + ctx->Color.ColorMask[0][RCOMP], + ctx->Color.ColorMask[0][GCOMP], + ctx->Color.ColorMask[0][BCOMP], + ctx->Color.ColorMask[0][ACOMP]); + } + + ctx->Driver.CullFace(ctx, ctx->Polygon.CullFaceMode); + ctx->Driver.DepthFunc(ctx, ctx->Depth.Func); + ctx->Driver.DepthMask(ctx, ctx->Depth.Mask); + + ctx->Driver.Enable(ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled); + ctx->Driver.Enable(ctx, GL_BLEND, ctx->Color.BlendEnabled); + ctx->Driver.Enable(ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled); + ctx->Driver.Enable(ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled); + ctx->Driver.Enable(ctx, GL_CULL_FACE, ctx->Polygon.CullFlag); + ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test); + ctx->Driver.Enable(ctx, GL_DITHER, ctx->Color.DitherFlag); + ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled); + ctx->Driver.Enable(ctx, GL_LIGHTING, ctx->Light.Enabled); + ctx->Driver.Enable(ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag); + ctx->Driver.Enable(ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag); + ctx->Driver.Enable(ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled); + ctx->Driver.Enable(ctx, GL_STENCIL_TEST, ctx->Stencil._Enabled); + ctx->Driver.Enable(ctx, GL_TEXTURE_1D, GL_FALSE); + ctx->Driver.Enable(ctx, GL_TEXTURE_2D, GL_FALSE); + ctx->Driver.Enable(ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE); + ctx->Driver.Enable(ctx, GL_TEXTURE_3D, GL_FALSE); + ctx->Driver.Enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE); + + ctx->Driver.Fogfv(ctx, GL_FOG_COLOR, ctx->Fog.Color); + ctx->Driver.Fogfv(ctx, GL_FOG_MODE, 0); + ctx->Driver.Fogfv(ctx, GL_FOG_DENSITY, &ctx->Fog.Density); + ctx->Driver.Fogfv(ctx, GL_FOG_START, &ctx->Fog.Start); + ctx->Driver.Fogfv(ctx, GL_FOG_END, &ctx->Fog.End); + + ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace); + + { + GLfloat f = (GLfloat) ctx->Light.Model.ColorControl; + ctx->Driver.LightModelfv(ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f); + } + + ctx->Driver.LineWidth(ctx, ctx->Line.Width); + ctx->Driver.LogicOpcode(ctx, ctx->Color.LogicOp); + ctx->Driver.PointSize(ctx, ctx->Point.Size); + ctx->Driver.PolygonStipple(ctx, (const GLubyte *) ctx->PolygonStipple); + ctx->Driver.Scissor(ctx, ctx->Scissor.X, ctx->Scissor.Y, + ctx->Scissor.Width, ctx->Scissor.Height); + ctx->Driver.ShadeModel(ctx, ctx->Light.ShadeModel); + ctx->Driver.StencilFuncSeparate(ctx, GL_FRONT, + ctx->Stencil.Function[0], + ctx->Stencil.Ref[0], + ctx->Stencil.ValueMask[0]); + ctx->Driver.StencilFuncSeparate(ctx, GL_BACK, + ctx->Stencil.Function[1], + ctx->Stencil.Ref[1], + ctx->Stencil.ValueMask[1]); + ctx->Driver.StencilMaskSeparate(ctx, GL_FRONT, ctx->Stencil.WriteMask[0]); + ctx->Driver.StencilMaskSeparate(ctx, GL_BACK, ctx->Stencil.WriteMask[1]); + ctx->Driver.StencilOpSeparate(ctx, GL_FRONT, + ctx->Stencil.FailFunc[0], + ctx->Stencil.ZFailFunc[0], + ctx->Stencil.ZPassFunc[0]); + ctx->Driver.StencilOpSeparate(ctx, GL_BACK, + ctx->Stencil.FailFunc[1], + ctx->Stencil.ZFailFunc[1], + ctx->Stencil.ZPassFunc[1]); + + + ctx->Driver.DrawBuffer(ctx, ctx->Color.DrawBuffer[0]); +} diff --git a/src/mesa/drivers/common/driverfuncs.h b/src/mesa/drivers/common/driverfuncs.h new file mode 100644 index 0000000..212f307 --- /dev/null +++ b/src/mesa/drivers/common/driverfuncs.h @@ -0,0 +1,37 @@ +/* + * Mesa 3-D graphics library + * Version: 7.1 + * + * Copyright (C) 1999-2007 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. + */ + + +#ifndef DRIVERFUNCS_H +#define DRIVERFUNCS_H + +extern void +_mesa_init_driver_functions(struct dd_function_table *driver); + + +extern void +_mesa_init_driver_state(struct gl_context *ctx); + + +#endif diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c new file mode 100644 index 0000000..cdb2500 --- /dev/null +++ b/src/mesa/drivers/common/meta.c @@ -0,0 +1,2854 @@ +/* + * Mesa 3-D graphics library + * Version: 7.6 + * + * Copyright (C) 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 + * 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. + */ + +/** + * Meta operations. Some GL operations can be expressed in terms of + * other GL operations. For example, glBlitFramebuffer() can be done + * with texture mapping and glClear() can be done with polygon rendering. + * + * \author Brian Paul + */ + + +#include "main/glheader.h" +#include "main/mtypes.h" +#include "main/imports.h" +#include "main/arbprogram.h" +#include "main/arrayobj.h" +#include "main/blend.h" +#include "main/bufferobj.h" +#include "main/buffers.h" +#include "main/colortab.h" +#include "main/depth.h" +#include "main/enable.h" +#include "main/fbobject.h" +#include "main/formats.h" +#include "main/image.h" +#include "main/macros.h" +#include "main/matrix.h" +#include "main/mipmap.h" +#include "main/polygon.h" +#include "main/readpix.h" +#include "main/scissor.h" +#include "main/shaderapi.h" +#include "main/shaderobj.h" +#include "main/state.h" +#include "main/stencil.h" +#include "main/texobj.h" +#include "main/texenv.h" +#include "main/teximage.h" +#include "main/texparam.h" +#include "main/texstate.h" +#include "main/varray.h" +#include "main/viewport.h" +#include "program/program.h" +#include "swrast/swrast.h" +#include "drivers/common/meta.h" + + +/** Return offset in bytes of the field within a vertex struct */ +#define OFFSET(FIELD) ((void *) offsetof(struct vertex, FIELD)) + + +/** + * Flags passed to _mesa_meta_begin(). + */ +/*@{*/ +#define META_ALL ~0x0 +#define META_ALPHA_TEST 0x1 +#define META_BLEND 0x2 /**< includes logicop */ +#define META_COLOR_MASK 0x4 +#define META_DEPTH_TEST 0x8 +#define META_FOG 0x10 +#define META_PIXEL_STORE 0x20 +#define META_PIXEL_TRANSFER 0x40 +#define META_RASTERIZATION 0x80 +#define META_SCISSOR 0x100 +#define META_SHADER 0x200 +#define META_STENCIL_TEST 0x400 +#define META_TRANSFORM 0x800 /**< modelview, projection, clip planes */ +#define META_TEXTURE 0x1000 +#define META_VERTEX 0x2000 +#define META_VIEWPORT 0x4000 +/*@}*/ + + +/** + * State which we may save/restore across meta ops. + * XXX this may be incomplete... + */ +struct save_state +{ + GLbitfield SavedState; /**< bitmask of META_* flags */ + + /** META_ALPHA_TEST */ + GLboolean AlphaEnabled; + GLenum AlphaFunc; + GLclampf AlphaRef; + + /** META_BLEND */ + GLbitfield BlendEnabled; + GLboolean ColorLogicOpEnabled; + + /** META_COLOR_MASK */ + GLubyte ColorMask[MAX_DRAW_BUFFERS][4]; + + /** META_DEPTH_TEST */ + struct gl_depthbuffer_attrib Depth; + + /** META_FOG */ + GLboolean Fog; + + /** META_PIXEL_STORE */ + struct gl_pixelstore_attrib Pack, Unpack; + + /** META_PIXEL_TRANSFER */ + GLfloat RedBias, RedScale; + GLfloat GreenBias, GreenScale; + GLfloat BlueBias, BlueScale; + GLfloat AlphaBias, AlphaScale; + GLfloat DepthBias, DepthScale; + GLboolean MapColorFlag; + + /** META_RASTERIZATION */ + GLenum FrontPolygonMode, BackPolygonMode; + GLboolean PolygonOffset; + GLboolean PolygonSmooth; + GLboolean PolygonStipple; + GLboolean PolygonCull; + + /** META_SCISSOR */ + struct gl_scissor_attrib Scissor; + + /** META_SHADER */ + GLboolean VertexProgramEnabled; + struct gl_vertex_program *VertexProgram; + GLboolean FragmentProgramEnabled; + struct gl_fragment_program *FragmentProgram; + struct gl_shader_program *VertexShader; + struct gl_shader_program *GeometryShader; + struct gl_shader_program *FragmentShader; + struct gl_shader_program *ActiveShader; + + /** META_STENCIL_TEST */ + struct gl_stencil_attrib Stencil; + + /** META_TRANSFORM */ + GLenum MatrixMode; + GLfloat ModelviewMatrix[16]; + GLfloat ProjectionMatrix[16]; + GLfloat TextureMatrix[16]; + GLbitfield ClipPlanesEnabled; + + /** META_TEXTURE */ + GLuint ActiveUnit; + GLuint ClientActiveUnit; + /** for unit[0] only */ + struct gl_texture_object *CurrentTexture[NUM_TEXTURE_TARGETS]; + /** mask of TEXTURE_2D_BIT, etc */ + GLbitfield TexEnabled[MAX_TEXTURE_UNITS]; + GLbitfield TexGenEnabled[MAX_TEXTURE_UNITS]; + GLuint EnvMode; /* unit[0] only */ + + /** META_VERTEX */ + struct gl_array_object *ArrayObj; + struct gl_buffer_object *ArrayBufferObj; + + /** META_VIEWPORT */ + GLint ViewportX, ViewportY, ViewportW, ViewportH; + GLclampd DepthNear, DepthFar; + + /** Miscellaneous (always disabled) */ + GLboolean Lighting; +}; + + +/** + * Temporary texture used for glBlitFramebuffer, glDrawPixels, etc. + * This is currently shared by all the meta ops. But we could create a + * separate one for each of glDrawPixel, glBlitFramebuffer, glCopyPixels, etc. + */ +struct temp_texture +{ + GLuint TexObj; + GLenum Target; /**< GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE */ + GLsizei MinSize; /**< Min texture size to allocate */ + GLsizei MaxSize; /**< Max possible texture size */ + GLboolean NPOT; /**< Non-power of two size OK? */ + GLsizei Width, Height; /**< Current texture size */ + GLenum IntFormat; + GLfloat Sright, Ttop; /**< right, top texcoords */ +}; + + +/** + * State for glBlitFramebufer() + */ +struct blit_state +{ + GLuint ArrayObj; + GLuint VBO; + GLuint DepthFP; +}; + + +/** + * State for glClear() + */ +struct clear_state +{ + GLuint ArrayObj; + GLuint VBO; +}; + + +/** + * State for glCopyPixels() + */ +struct copypix_state +{ + GLuint ArrayObj; + GLuint VBO; +}; + + +/** + * State for glDrawPixels() + */ +struct drawpix_state +{ + GLuint ArrayObj; + + GLuint StencilFP; /**< Fragment program for drawing stencil images */ + GLuint DepthFP; /**< Fragment program for drawing depth images */ +}; + + +/** + * State for glBitmap() + */ +struct bitmap_state +{ + GLuint ArrayObj; + GLuint VBO; + struct temp_texture Tex; /**< separate texture from other meta ops */ +}; + + +/** + * State for _mesa_meta_generate_mipmap() + */ +struct gen_mipmap_state +{ + GLuint ArrayObj; + GLuint VBO; + GLuint FBO; +}; + +#define MAX_META_OPS_DEPTH 2 +/** + * All per-context meta state. + */ +struct gl_meta_state +{ + /** Stack of state saved during meta-ops */ + struct save_state Save[MAX_META_OPS_DEPTH]; + /** Save stack depth */ + GLuint SaveStackDepth; + + struct temp_texture TempTex; + + struct blit_state Blit; /**< For _mesa_meta_BlitFramebuffer() */ + struct clear_state Clear; /**< For _mesa_meta_Clear() */ + struct copypix_state CopyPix; /**< For _mesa_meta_CopyPixels() */ + struct drawpix_state DrawPix; /**< For _mesa_meta_DrawPixels() */ + struct bitmap_state Bitmap; /**< For _mesa_meta_Bitmap() */ + struct gen_mipmap_state Mipmap; /**< For _mesa_meta_GenerateMipmap() */ +}; + + +/** + * Initialize meta-ops for a context. + * To be called once during context creation. + */ +void +_mesa_meta_init(struct gl_context *ctx) +{ + ASSERT(!ctx->Meta); + + ctx->Meta = CALLOC_STRUCT(gl_meta_state); +} + + +/** + * Free context meta-op state. + * To be called once during context destruction. + */ +void +_mesa_meta_free(struct gl_context *ctx) +{ + /* Note: Any textures, VBOs, etc, that we allocate should get + * freed by the normal context destruction code. But this would be + * the place to free other meta data someday. + */ + free(ctx->Meta); + ctx->Meta = NULL; +} + + +/** + * Enter meta state. This is like a light-weight version of glPushAttrib + * but it also resets most GL state back to default values. + * + * \param state bitmask of META_* flags indicating which attribute groups + * to save and reset to their defaults + */ +static void +_mesa_meta_begin(struct gl_context *ctx, GLbitfield state) +{ + struct save_state *save; + + /* hope MAX_META_OPS_DEPTH is large enough */ + assert(ctx->Meta->SaveStackDepth < MAX_META_OPS_DEPTH); + + save = &ctx->Meta->Save[ctx->Meta->SaveStackDepth++]; + memset(save, 0, sizeof(*save)); + save->SavedState = state; + + if (state & META_ALPHA_TEST) { + save->AlphaEnabled = ctx->Color.AlphaEnabled; + save->AlphaFunc = ctx->Color.AlphaFunc; + save->AlphaRef = ctx->Color.AlphaRef; + if (ctx->Color.AlphaEnabled) + _mesa_set_enable(ctx, GL_ALPHA_TEST, GL_FALSE); + } + + if (state & META_BLEND) { + save->BlendEnabled = ctx->Color.BlendEnabled; + if (ctx->Color.BlendEnabled) { + if (ctx->Extensions.EXT_draw_buffers2) { + GLuint i; + for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) { + _mesa_set_enablei(ctx, GL_BLEND, i, GL_FALSE); + } + } + else { + _mesa_set_enable(ctx, GL_BLEND, GL_FALSE); + } + } + save->ColorLogicOpEnabled = ctx->Color.ColorLogicOpEnabled; + if (ctx->Color.ColorLogicOpEnabled) + _mesa_set_enable(ctx, GL_COLOR_LOGIC_OP, GL_FALSE); + } + + if (state & META_COLOR_MASK) { + memcpy(save->ColorMask, ctx->Color.ColorMask, + sizeof(ctx->Color.ColorMask)); + if (!ctx->Color.ColorMask[0][0] || + !ctx->Color.ColorMask[0][1] || + !ctx->Color.ColorMask[0][2] || + !ctx->Color.ColorMask[0][3]) + _mesa_ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + } + + if (state & META_DEPTH_TEST) { + save->Depth = ctx->Depth; /* struct copy */ + if (ctx->Depth.Test) + _mesa_set_enable(ctx, GL_DEPTH_TEST, GL_FALSE); + } + + if (state & META_FOG) { + save->Fog = ctx->Fog.Enabled; + if (ctx->Fog.Enabled) + _mesa_set_enable(ctx, GL_FOG, GL_FALSE); + } + + if (state & META_PIXEL_STORE) { + save->Pack = ctx->Pack; + save->Unpack = ctx->Unpack; + ctx->Pack = ctx->DefaultPacking; + ctx->Unpack = ctx->DefaultPacking; + } + + if (state & META_PIXEL_TRANSFER) { + save->RedScale = ctx->Pixel.RedScale; + save->RedBias = ctx->Pixel.RedBias; + save->GreenScale = ctx->Pixel.GreenScale; + save->GreenBias = ctx->Pixel.GreenBias; + save->BlueScale = ctx->Pixel.BlueScale; + save->BlueBias = ctx->Pixel.BlueBias; + save->AlphaScale = ctx->Pixel.AlphaScale; + save->AlphaBias = ctx->Pixel.AlphaBias; + save->MapColorFlag = ctx->Pixel.MapColorFlag; + ctx->Pixel.RedScale = 1.0F; + ctx->Pixel.RedBias = 0.0F; + ctx->Pixel.GreenScale = 1.0F; + ctx->Pixel.GreenBias = 0.0F; + ctx->Pixel.BlueScale = 1.0F; + ctx->Pixel.BlueBias = 0.0F; + ctx->Pixel.AlphaScale = 1.0F; + ctx->Pixel.AlphaBias = 0.0F; + ctx->Pixel.MapColorFlag = GL_FALSE; + /* XXX more state */ + ctx->NewState |=_NEW_PIXEL; + } + + if (state & META_RASTERIZATION) { + save->FrontPolygonMode = ctx->Polygon.FrontMode; + save->BackPolygonMode = ctx->Polygon.BackMode; + save->PolygonOffset = ctx->Polygon.OffsetFill; + save->PolygonSmooth = ctx->Polygon.SmoothFlag; + save->PolygonStipple = ctx->Polygon.StippleFlag; + save->PolygonCull = ctx->Polygon.CullFlag; + _mesa_PolygonMode(GL_FRONT_AND_BACK, GL_FILL); + _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL, GL_FALSE); + _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, GL_FALSE); + _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, GL_FALSE); + _mesa_set_enable(ctx, GL_CULL_FACE, GL_FALSE); + } + + if (state & META_SCISSOR) { + save->Scissor = ctx->Scissor; /* struct copy */ + _mesa_set_enable(ctx, GL_SCISSOR_TEST, GL_FALSE); + } + + if (state & META_SHADER) { + if (ctx->Extensions.ARB_vertex_program) { + save->VertexProgramEnabled = ctx->VertexProgram.Enabled; + _mesa_reference_vertprog(ctx, &save->VertexProgram, + ctx->VertexProgram.Current); + _mesa_set_enable(ctx, GL_VERTEX_PROGRAM_ARB, GL_FALSE); + } + + if (ctx->Extensions.ARB_fragment_program) { + save->FragmentProgramEnabled = ctx->FragmentProgram.Enabled; + _mesa_reference_fragprog(ctx, &save->FragmentProgram, + ctx->FragmentProgram.Current); + _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, GL_FALSE); + } + + if (ctx->Extensions.ARB_shader_objects) { + _mesa_reference_shader_program(ctx, &save->VertexShader, + ctx->Shader.CurrentVertexProgram); + _mesa_reference_shader_program(ctx, &save->GeometryShader, + ctx->Shader.CurrentGeometryProgram); + _mesa_reference_shader_program(ctx, &save->FragmentShader, + ctx->Shader.CurrentFragmentProgram); + _mesa_reference_shader_program(ctx, &save->ActiveShader, + ctx->Shader.CurrentFragmentProgram); + + _mesa_UseProgramObjectARB(0); + } + } + + if (state & META_STENCIL_TEST) { + save->Stencil = ctx->Stencil; /* struct copy */ + if (ctx->Stencil.Enabled) + _mesa_set_enable(ctx, GL_STENCIL_TEST, GL_FALSE); + /* NOTE: other stencil state not reset */ + } + + if (state & META_TEXTURE) { + GLuint u, tgt; + + save->ActiveUnit = ctx->Texture.CurrentUnit; + save->ClientActiveUnit = ctx->Array.ActiveTexture; + save->EnvMode = ctx->Texture.Unit[0].EnvMode; + + /* Disable all texture units */ + for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { + save->TexEnabled[u] = ctx->Texture.Unit[u].Enabled; + save->TexGenEnabled[u] = ctx->Texture.Unit[u].TexGenEnabled; + if (ctx->Texture.Unit[u].Enabled || + ctx->Texture.Unit[u].TexGenEnabled) { + _mesa_ActiveTextureARB(GL_TEXTURE0 + u); + _mesa_set_enable(ctx, GL_TEXTURE_1D, GL_FALSE); + _mesa_set_enable(ctx, GL_TEXTURE_2D, GL_FALSE); + _mesa_set_enable(ctx, GL_TEXTURE_3D, GL_FALSE); + if (ctx->Extensions.ARB_texture_cube_map) + _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE); + _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE, GL_FALSE); + _mesa_set_enable(ctx, GL_TEXTURE_GEN_S, GL_FALSE); + _mesa_set_enable(ctx, GL_TEXTURE_GEN_T, GL_FALSE); + _mesa_set_enable(ctx, GL_TEXTURE_GEN_R, GL_FALSE); + _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q, GL_FALSE); + } + } + + /* save current texture objects for unit[0] only */ + for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) { + _mesa_reference_texobj(&save->CurrentTexture[tgt], + ctx->Texture.Unit[0].CurrentTex[tgt]); + } + + /* set defaults for unit[0] */ + _mesa_ActiveTextureARB(GL_TEXTURE0); + _mesa_ClientActiveTextureARB(GL_TEXTURE0); + _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + } + + if (state & META_TRANSFORM) { + GLuint activeTexture = ctx->Texture.CurrentUnit; + memcpy(save->ModelviewMatrix, ctx->ModelviewMatrixStack.Top->m, + 16 * sizeof(GLfloat)); + memcpy(save->ProjectionMatrix, ctx->ProjectionMatrixStack.Top->m, + 16 * sizeof(GLfloat)); + memcpy(save->TextureMatrix, ctx->TextureMatrixStack[0].Top->m, + 16 * sizeof(GLfloat)); + save->MatrixMode = ctx->Transform.MatrixMode; + /* set 1:1 vertex:pixel coordinate transform */ + _mesa_ActiveTextureARB(GL_TEXTURE0); + _mesa_MatrixMode(GL_TEXTURE); + _mesa_LoadIdentity(); + _mesa_ActiveTextureARB(GL_TEXTURE0 + activeTexture); + _mesa_MatrixMode(GL_MODELVIEW); + _mesa_LoadIdentity(); + _mesa_MatrixMode(GL_PROJECTION); + _mesa_LoadIdentity(); + _mesa_Ortho(0.0, ctx->DrawBuffer->Width, + 0.0, ctx->DrawBuffer->Height, + -1.0, 1.0); + save->ClipPlanesEnabled = ctx->Transform.ClipPlanesEnabled; + if (ctx->Transform.ClipPlanesEnabled) { + GLuint i; + for (i = 0; i < ctx->Const.MaxClipPlanes; i++) { + _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_FALSE); + } + } + } + + if (state & META_VERTEX) { + /* save vertex array object state */ + _mesa_reference_array_object(ctx, &save->ArrayObj, + ctx->Array.ArrayObj); + _mesa_reference_buffer_object(ctx, &save->ArrayBufferObj, + ctx->Array.ArrayBufferObj); + /* set some default state? */ + } + + if (state & META_VIEWPORT) { + /* save viewport state */ + save->ViewportX = ctx->Viewport.X; + save->ViewportY = ctx->Viewport.Y; + save->ViewportW = ctx->Viewport.Width; + save->ViewportH = ctx->Viewport.Height; + /* set viewport to match window size */ + if (ctx->Viewport.X != 0 || + ctx->Viewport.Y != 0 || + ctx->Viewport.Width != ctx->DrawBuffer->Width || + ctx->Viewport.Height != ctx->DrawBuffer->Height) { + _mesa_set_viewport(ctx, 0, 0, + ctx->DrawBuffer->Width, ctx->DrawBuffer->Height); + } + /* save depth range state */ + save->DepthNear = ctx->Viewport.Near; + save->DepthFar = ctx->Viewport.Far; + /* set depth range to default */ + _mesa_DepthRange(0.0, 1.0); + } + + /* misc */ + { + save->Lighting = ctx->Light.Enabled; + if (ctx->Light.Enabled) + _mesa_set_enable(ctx, GL_LIGHTING, GL_FALSE); + } +} + + +/** + * Leave meta state. This is like a light-weight version of glPopAttrib(). + */ +static void +_mesa_meta_end(struct gl_context *ctx) +{ + struct save_state *save = &ctx->Meta->Save[--ctx->Meta->SaveStackDepth]; + const GLbitfield state = save->SavedState; + + if (state & META_ALPHA_TEST) { + if (ctx->Color.AlphaEnabled != save->AlphaEnabled) + _mesa_set_enable(ctx, GL_ALPHA_TEST, save->AlphaEnabled); + _mesa_AlphaFunc(save->AlphaFunc, save->AlphaRef); + } + + if (state & META_BLEND) { + if (ctx->Color.BlendEnabled != save->BlendEnabled) { + if (ctx->Extensions.EXT_draw_buffers2) { + GLuint i; + for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) { + _mesa_set_enablei(ctx, GL_BLEND, i, (save->BlendEnabled >> i) & 1); + } + } + else { + _mesa_set_enable(ctx, GL_BLEND, (save->BlendEnabled & 1)); + } + } + if (ctx->Color.ColorLogicOpEnabled != save->ColorLogicOpEnabled) + _mesa_set_enable(ctx, GL_COLOR_LOGIC_OP, save->ColorLogicOpEnabled); + } + + if (state & META_COLOR_MASK) { + GLuint i; + for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) { + if (!TEST_EQ_4V(ctx->Color.ColorMask[i], save->ColorMask[i])) { + if (i == 0) { + _mesa_ColorMask(save->ColorMask[i][0], save->ColorMask[i][1], + save->ColorMask[i][2], save->ColorMask[i][3]); + } + else { + _mesa_ColorMaskIndexed(i, + save->ColorMask[i][0], + save->ColorMask[i][1], + save->ColorMask[i][2], + save->ColorMask[i][3]); + } + } + } + } + + if (state & META_DEPTH_TEST) { + if (ctx->Depth.Test != save->Depth.Test) + _mesa_set_enable(ctx, GL_DEPTH_TEST, save->Depth.Test); + _mesa_DepthFunc(save->Depth.Func); + _mesa_DepthMask(save->Depth.Mask); + } + + if (state & META_FOG) { + _mesa_set_enable(ctx, GL_FOG, save->Fog); + } + + if (state & META_PIXEL_STORE) { + ctx->Pack = save->Pack; + ctx->Unpack = save->Unpack; + } + + if (state & META_PIXEL_TRANSFER) { + ctx->Pixel.RedScale = save->RedScale; + ctx->Pixel.RedBias = save->RedBias; + ctx->Pixel.GreenScale = save->GreenScale; + ctx->Pixel.GreenBias = save->GreenBias; + ctx->Pixel.BlueScale = save->BlueScale; + ctx->Pixel.BlueBias = save->BlueBias; + ctx->Pixel.AlphaScale = save->AlphaScale; + ctx->Pixel.AlphaBias = save->AlphaBias; + ctx->Pixel.MapColorFlag = save->MapColorFlag; + /* XXX more state */ + ctx->NewState |=_NEW_PIXEL; + } + + if (state & META_RASTERIZATION) { + _mesa_PolygonMode(GL_FRONT, save->FrontPolygonMode); + _mesa_PolygonMode(GL_BACK, save->BackPolygonMode); + _mesa_set_enable(ctx, GL_POLYGON_STIPPLE, save->PolygonStipple); + _mesa_set_enable(ctx, GL_POLYGON_OFFSET_FILL, save->PolygonOffset); + _mesa_set_enable(ctx, GL_POLYGON_SMOOTH, save->PolygonSmooth); + _mesa_set_enable(ctx, GL_CULL_FACE, save->PolygonCull); + } + + if (state & META_SCISSOR) { + _mesa_set_enable(ctx, GL_SCISSOR_TEST, save->Scissor.Enabled); + _mesa_Scissor(save->Scissor.X, save->Scissor.Y, + save->Scissor.Width, save->Scissor.Height); + } + + if (state & META_SHADER) { + if (ctx->Extensions.ARB_vertex_program) { + _mesa_set_enable(ctx, GL_VERTEX_PROGRAM_ARB, + save->VertexProgramEnabled); + _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, + save->VertexProgram); + _mesa_reference_vertprog(ctx, &save->VertexProgram, NULL); + } + + if (ctx->Extensions.ARB_fragment_program) { + _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, + save->FragmentProgramEnabled); + _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, + save->FragmentProgram); + _mesa_reference_fragprog(ctx, &save->FragmentProgram, NULL); + } + + if (ctx->Extensions.ARB_vertex_shader) + _mesa_use_shader_program(ctx, GL_VERTEX_SHADER, save->VertexShader); + + if (ctx->Extensions.ARB_geometry_shader4) + _mesa_use_shader_program(ctx, GL_GEOMETRY_SHADER_ARB, + save->GeometryShader); + + if (ctx->Extensions.ARB_fragment_shader) + _mesa_use_shader_program(ctx, GL_FRAGMENT_SHADER, + save->FragmentShader); + + _mesa_reference_shader_program(ctx, &ctx->Shader.ActiveProgram, + save->ActiveShader); + } + + if (state & META_STENCIL_TEST) { + const struct gl_stencil_attrib *stencil = &save->Stencil; + + _mesa_set_enable(ctx, GL_STENCIL_TEST, stencil->Enabled); + _mesa_ClearStencil(stencil->Clear); + if (ctx->Extensions.EXT_stencil_two_side) { + _mesa_set_enable(ctx, GL_STENCIL_TEST_TWO_SIDE_EXT, + stencil->TestTwoSide); + _mesa_ActiveStencilFaceEXT(stencil->ActiveFace + ? GL_BACK : GL_FRONT); + } + /* front state */ + _mesa_StencilFuncSeparate(GL_FRONT, + stencil->Function[0], + stencil->Ref[0], + stencil->ValueMask[0]); + _mesa_StencilMaskSeparate(GL_FRONT, stencil->WriteMask[0]); + _mesa_StencilOpSeparate(GL_FRONT, stencil->FailFunc[0], + stencil->ZFailFunc[0], + stencil->ZPassFunc[0]); + /* back state */ + _mesa_StencilFuncSeparate(GL_BACK, + stencil->Function[1], + stencil->Ref[1], + stencil->ValueMask[1]); + _mesa_StencilMaskSeparate(GL_BACK, stencil->WriteMask[1]); + _mesa_StencilOpSeparate(GL_BACK, stencil->FailFunc[1], + stencil->ZFailFunc[1], + stencil->ZPassFunc[1]); + } + + if (state & META_TEXTURE) { + GLuint u, tgt; + + ASSERT(ctx->Texture.CurrentUnit == 0); + + /* restore texenv for unit[0] */ + _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, save->EnvMode); + + /* restore texture objects for unit[0] only */ + for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) { + _mesa_reference_texobj(&ctx->Texture.Unit[0].CurrentTex[tgt], + save->CurrentTexture[tgt]); + _mesa_reference_texobj(&save->CurrentTexture[tgt], NULL); + } + + /* Re-enable textures, texgen */ + for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { + if (save->TexEnabled[u]) { + _mesa_ActiveTextureARB(GL_TEXTURE0 + u); + + if (save->TexEnabled[u] & TEXTURE_1D_BIT) + _mesa_set_enable(ctx, GL_TEXTURE_1D, GL_TRUE); + if (save->TexEnabled[u] & TEXTURE_2D_BIT) + _mesa_set_enable(ctx, GL_TEXTURE_2D, GL_TRUE); + if (save->TexEnabled[u] & TEXTURE_3D_BIT) + _mesa_set_enable(ctx, GL_TEXTURE_3D, GL_TRUE); + if (save->TexEnabled[u] & TEXTURE_CUBE_BIT) + _mesa_set_enable(ctx, GL_TEXTURE_CUBE_MAP, GL_TRUE); + if (save->TexEnabled[u] & TEXTURE_RECT_BIT) + _mesa_set_enable(ctx, GL_TEXTURE_RECTANGLE, GL_TRUE); + } + + if (save->TexGenEnabled[u]) { + _mesa_ActiveTextureARB(GL_TEXTURE0 + u); + + if (save->TexGenEnabled[u] & S_BIT) + _mesa_set_enable(ctx, GL_TEXTURE_GEN_S, GL_TRUE); + if (save->TexGenEnabled[u] & T_BIT) + _mesa_set_enable(ctx, GL_TEXTURE_GEN_T, GL_TRUE); + if (save->TexGenEnabled[u] & R_BIT) + _mesa_set_enable(ctx, GL_TEXTURE_GEN_R, GL_TRUE); + if (save->TexGenEnabled[u] & Q_BIT) + _mesa_set_enable(ctx, GL_TEXTURE_GEN_Q, GL_TRUE); + } + } + + /* restore current unit state */ + _mesa_ActiveTextureARB(GL_TEXTURE0 + save->ActiveUnit); + _mesa_ClientActiveTextureARB(GL_TEXTURE0 + save->ClientActiveUnit); + } + + if (state & META_TRANSFORM) { + GLuint activeTexture = ctx->Texture.CurrentUnit; + _mesa_ActiveTextureARB(GL_TEXTURE0); + _mesa_MatrixMode(GL_TEXTURE); + _mesa_LoadMatrixf(save->TextureMatrix); + _mesa_ActiveTextureARB(GL_TEXTURE0 + activeTexture); + + _mesa_MatrixMode(GL_MODELVIEW); + _mesa_LoadMatrixf(save->ModelviewMatrix); + + _mesa_MatrixMode(GL_PROJECTION); + _mesa_LoadMatrixf(save->ProjectionMatrix); + + _mesa_MatrixMode(save->MatrixMode); + + if (save->ClipPlanesEnabled) { + GLuint i; + for (i = 0; i < ctx->Const.MaxClipPlanes; i++) { + if (save->ClipPlanesEnabled & (1 << i)) { + _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_TRUE); + } + } + } + } + + if (state & META_VERTEX) { + /* restore vertex buffer object */ + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, save->ArrayBufferObj->Name); + _mesa_reference_buffer_object(ctx, &save->ArrayBufferObj, NULL); + + /* restore vertex array object */ + _mesa_BindVertexArray(save->ArrayObj->Name); + _mesa_reference_array_object(ctx, &save->ArrayObj, NULL); + } + + if (state & META_VIEWPORT) { + if (save->ViewportX != ctx->Viewport.X || + save->ViewportY != ctx->Viewport.Y || + save->ViewportW != ctx->Viewport.Width || + save->ViewportH != ctx->Viewport.Height) { + _mesa_set_viewport(ctx, save->ViewportX, save->ViewportY, + save->ViewportW, save->ViewportH); + } + _mesa_DepthRange(save->DepthNear, save->DepthFar); + } + + /* misc */ + if (save->Lighting) { + _mesa_set_enable(ctx, GL_LIGHTING, GL_TRUE); + } +} + + +/** + * Convert Z from a normalized value in the range [0, 1] to an object-space + * Z coordinate in [-1, +1] so that drawing at the new Z position with the + * default/identity ortho projection results in the original Z value. + * Used by the meta-Clear, Draw/CopyPixels and Bitmap functions where the Z + * value comes from the clear value or raster position. + */ +static INLINE GLfloat +invert_z(GLfloat normZ) +{ + GLfloat objZ = 1.0 - 2.0 * normZ; + return objZ; +} + + +/** + * One-time init for a temp_texture object. + * Choose tex target, compute max tex size, etc. + */ +static void +init_temp_texture(struct gl_context *ctx, struct temp_texture *tex) +{ + /* prefer texture rectangle */ + if (ctx->Extensions.NV_texture_rectangle) { + tex->Target = GL_TEXTURE_RECTANGLE; + tex->MaxSize = ctx->Const.MaxTextureRectSize; + tex->NPOT = GL_TRUE; + } + else { + /* use 2D texture, NPOT if possible */ + tex->Target = GL_TEXTURE_2D; + tex->MaxSize = 1 << (ctx->Const.MaxTextureLevels - 1); + tex->NPOT = ctx->Extensions.ARB_texture_non_power_of_two; + } + tex->MinSize = 16; /* 16 x 16 at least */ + assert(tex->MaxSize > 0); + + _mesa_GenTextures(1, &tex->TexObj); +} + + +/** + * Return pointer to temp_texture info for non-bitmap ops. + * This does some one-time init if needed. + */ +static struct temp_texture * +get_temp_texture(struct gl_context *ctx) +{ + struct temp_texture *tex = &ctx->Meta->TempTex; + + if (!tex->TexObj) { + init_temp_texture(ctx, tex); + } + + return tex; +} + + +/** + * Return pointer to temp_texture info for _mesa_meta_bitmap(). + * We use a separate texture for bitmaps to reduce texture + * allocation/deallocation. + */ +static struct temp_texture * +get_bitmap_temp_texture(struct gl_context *ctx) +{ + struct temp_texture *tex = &ctx->Meta->Bitmap.Tex; + + if (!tex->TexObj) { + init_temp_texture(ctx, tex); + } + + return tex; +} + + +/** + * Compute the width/height of texture needed to draw an image of the + * given size. Return a flag indicating whether the current texture + * can be re-used (glTexSubImage2D) or if a new texture needs to be + * allocated (glTexImage2D). + * Also, compute s/t texcoords for drawing. + * + * \return GL_TRUE if new texture is needed, GL_FALSE otherwise + */ +static GLboolean +alloc_texture(struct temp_texture *tex, + GLsizei width, GLsizei height, GLenum intFormat) +{ + GLboolean newTex = GL_FALSE; + + ASSERT(width <= tex->MaxSize); + ASSERT(height <= tex->MaxSize); + + if (width > tex->Width || + height > tex->Height || + intFormat != tex->IntFormat) { + /* alloc new texture (larger or different format) */ + + if (tex->NPOT) { + /* use non-power of two size */ + tex->Width = MAX2(tex->MinSize, width); + tex->Height = MAX2(tex->MinSize, height); + } + else { + /* find power of two size */ + GLsizei w, h; + w = h = tex->MinSize; + while (w < width) + w *= 2; + while (h < height) + h *= 2; + tex->Width = w; + tex->Height = h; + } + + tex->IntFormat = intFormat; + + newTex = GL_TRUE; + } + + /* compute texcoords */ + if (tex->Target == GL_TEXTURE_RECTANGLE) { + tex->Sright = (GLfloat) width; + tex->Ttop = (GLfloat) height; + } + else { + tex->Sright = (GLfloat) width / tex->Width; + tex->Ttop = (GLfloat) height / tex->Height; + } + + return newTex; +} + + +/** + * Setup/load texture for glCopyPixels or glBlitFramebuffer. + */ +static void +setup_copypix_texture(struct temp_texture *tex, + GLboolean newTex, + GLint srcX, GLint srcY, + GLsizei width, GLsizei height, GLenum intFormat, + GLenum filter) +{ + _mesa_BindTexture(tex->Target, tex->TexObj); + _mesa_TexParameteri(tex->Target, GL_TEXTURE_MIN_FILTER, filter); + _mesa_TexParameteri(tex->Target, GL_TEXTURE_MAG_FILTER, filter); + _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + /* copy framebuffer image to texture */ + if (newTex) { + /* create new tex image */ + if (tex->Width == width && tex->Height == height) { + /* create new tex with framebuffer data */ + _mesa_CopyTexImage2D(tex->Target, 0, tex->IntFormat, + srcX, srcY, width, height, 0); + } + else { + /* create empty texture */ + _mesa_TexImage2D(tex->Target, 0, tex->IntFormat, + tex->Width, tex->Height, 0, + intFormat, GL_UNSIGNED_BYTE, NULL); + /* load image */ + _mesa_CopyTexSubImage2D(tex->Target, 0, + 0, 0, srcX, srcY, width, height); + } + } + else { + /* replace existing tex image */ + _mesa_CopyTexSubImage2D(tex->Target, 0, + 0, 0, srcX, srcY, width, height); + } +} + + +/** + * Setup/load texture for glDrawPixels. + */ +static void +setup_drawpix_texture(struct gl_context *ctx, + struct temp_texture *tex, + GLboolean newTex, + GLenum texIntFormat, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels) +{ + _mesa_BindTexture(tex->Target, tex->TexObj); + _mesa_TexParameteri(tex->Target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + _mesa_TexParameteri(tex->Target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + /* copy pixel data to texture */ + if (newTex) { + /* create new tex image */ + if (tex->Width == width && tex->Height == height) { + /* create new tex and load image data */ + _mesa_TexImage2D(tex->Target, 0, tex->IntFormat, + tex->Width, tex->Height, 0, format, type, pixels); + } + else { + struct gl_buffer_object *save_unpack_obj = NULL; + + _mesa_reference_buffer_object(ctx, &save_unpack_obj, + ctx->Unpack.BufferObj); + _mesa_BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0); + /* create empty texture */ + _mesa_TexImage2D(tex->Target, 0, tex->IntFormat, + tex->Width, tex->Height, 0, format, type, NULL); + if (save_unpack_obj != NULL) + _mesa_BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, + save_unpack_obj->Name); + /* load image */ + _mesa_TexSubImage2D(tex->Target, 0, + 0, 0, width, height, format, type, pixels); + } + } + else { + /* replace existing tex image */ + _mesa_TexSubImage2D(tex->Target, 0, + 0, 0, width, height, format, type, pixels); + } +} + + + +/** + * One-time init for drawing depth pixels. + */ +static void +init_blit_depth_pixels(struct gl_context *ctx) +{ + static const char *program = + "!!ARBfp1.0\n" + "TEX result.depth, fragment.texcoord[0], texture[0], %s; \n" + "END \n"; + char program2[200]; + struct blit_state *blit = &ctx->Meta->Blit; + struct temp_texture *tex = get_temp_texture(ctx); + const char *texTarget; + + assert(blit->DepthFP == 0); + + /* replace %s with "RECT" or "2D" */ + assert(strlen(program) + 4 < sizeof(program2)); + if (tex->Target == GL_TEXTURE_RECTANGLE) + texTarget = "RECT"; + else + texTarget = "2D"; + _mesa_snprintf(program2, sizeof(program2), program, texTarget); + + _mesa_GenPrograms(1, &blit->DepthFP); + _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, blit->DepthFP); + _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(program2), (const GLubyte *) program2); +} + + +/** + * Try to do a glBlitFramebuffer using no-copy texturing. + * We can do this when the src renderbuffer is actually a texture. + * But if the src buffer == dst buffer we cannot do this. + * + * \return new buffer mask indicating the buffers left to blit using the + * normal path. + */ +static GLbitfield +blitframebuffer_texture(struct gl_context *ctx, + GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, + GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, + GLbitfield mask, GLenum filter) +{ + if (mask & GL_COLOR_BUFFER_BIT) { + const struct gl_framebuffer *drawFb = ctx->DrawBuffer; + const struct gl_framebuffer *readFb = ctx->ReadBuffer; + const struct gl_renderbuffer_attachment *drawAtt = + &drawFb->Attachment[drawFb->_ColorDrawBufferIndexes[0]]; + const struct gl_renderbuffer_attachment *readAtt = + &readFb->Attachment[readFb->_ColorReadBufferIndex]; + + if (readAtt && readAtt->Texture) { + const struct gl_texture_object *texObj = readAtt->Texture; + const GLuint srcLevel = readAtt->TextureLevel; + const GLenum minFilterSave = texObj->MinFilter; + const GLenum magFilterSave = texObj->MagFilter; + const GLint baseLevelSave = texObj->BaseLevel; + const GLint maxLevelSave = texObj->MaxLevel; + const GLenum wrapSSave = texObj->WrapS; + const GLenum wrapTSave = texObj->WrapT; + const GLenum target = texObj->Target; + + if (drawAtt->Texture == readAtt->Texture) { + /* Can't use same texture as both the source and dest. We need + * to handle overlapping blits and besides, some hw may not + * support this. + */ + return mask; + } + + if (target != GL_TEXTURE_2D && target != GL_TEXTURE_RECTANGLE_ARB) { + /* Can't handle other texture types at this time */ + return mask; + } + + /* + printf("Blit from texture!\n"); + printf(" srcAtt %p dstAtt %p\n", readAtt, drawAtt); + printf(" srcTex %p dstText %p\n", texObj, drawAtt->Texture); + */ + + /* Prepare src texture state */ + _mesa_BindTexture(target, texObj->Name); + _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, filter); + _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, filter); + if (target != GL_TEXTURE_RECTANGLE_ARB) { + _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, srcLevel); + _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, srcLevel); + } + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + _mesa_set_enable(ctx, target, GL_TRUE); + + /* Prepare vertex data (the VBO was previously created and bound) */ + { + struct vertex { + GLfloat x, y, s, t; + }; + struct vertex verts[4]; + GLfloat s0, t0, s1, t1; + + if (target == GL_TEXTURE_2D) { + const struct gl_texture_image *texImage + = _mesa_select_tex_image(ctx, texObj, target, srcLevel); + s0 = srcX0 / (float) texImage->Width; + s1 = srcX1 / (float) texImage->Width; + t0 = srcY0 / (float) texImage->Height; + t1 = srcY1 / (float) texImage->Height; + } + else { + assert(target == GL_TEXTURE_RECTANGLE_ARB); + s0 = srcX0; + s1 = srcX1; + t0 = srcY0; + t1 = srcY1; + } + + verts[0].x = (GLfloat) dstX0; + verts[0].y = (GLfloat) dstY0; + verts[1].x = (GLfloat) dstX1; + verts[1].y = (GLfloat) dstY0; + verts[2].x = (GLfloat) dstX1; + verts[2].y = (GLfloat) dstY1; + verts[3].x = (GLfloat) dstX0; + verts[3].y = (GLfloat) dstY1; + + verts[0].s = s0; + verts[0].t = t0; + verts[1].s = s1; + verts[1].t = t0; + verts[2].s = s1; + verts[2].t = t1; + verts[3].s = s0; + verts[3].t = t1; + + _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts); + } + + _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4); + + /* Restore texture object state, the texture binding will + * be restored by _mesa_meta_end(). + */ + _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilterSave); + _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilterSave); + if (target != GL_TEXTURE_RECTANGLE_ARB) { + _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, baseLevelSave); + _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, maxLevelSave); + } + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, wrapSSave); + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, wrapTSave); + + /* Done with color buffer */ + mask &= ~GL_COLOR_BUFFER_BIT; + } + } + + return mask; +} + + +/** + * Meta implementation of ctx->Driver.BlitFramebuffer() in terms + * of texture mapping and polygon rendering. + */ +void +_mesa_meta_BlitFramebuffer(struct gl_context *ctx, + GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, + GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, + GLbitfield mask, GLenum filter) +{ + struct blit_state *blit = &ctx->Meta->Blit; + struct temp_texture *tex = get_temp_texture(ctx); + const GLsizei maxTexSize = tex->MaxSize; + const GLint srcX = MIN2(srcX0, srcX1); + const GLint srcY = MIN2(srcY0, srcY1); + const GLint srcW = abs(srcX1 - srcX0); + const GLint srcH = abs(srcY1 - srcY0); + const GLboolean srcFlipX = srcX1 < srcX0; + const GLboolean srcFlipY = srcY1 < srcY0; + struct vertex { + GLfloat x, y, s, t; + }; + struct vertex verts[4]; + GLboolean newTex; + + if (srcW > maxTexSize || srcH > maxTexSize) { + /* XXX avoid this fallback */ + _swrast_BlitFramebuffer(ctx, srcX0, srcY0, srcX1, srcY1, + dstX0, dstY0, dstX1, dstY1, mask, filter); + return; + } + + if (srcFlipX) { + GLint tmp = dstX0; + dstX0 = dstX1; + dstX1 = tmp; + } + + if (srcFlipY) { + GLint tmp = dstY0; + dstY0 = dstY1; + dstY1 = tmp; + } + + /* only scissor effects blit so save/clear all other relevant state */ + _mesa_meta_begin(ctx, ~META_SCISSOR); + + if (blit->ArrayObj == 0) { + /* one-time setup */ + + /* create vertex array object */ + _mesa_GenVertexArrays(1, &blit->ArrayObj); + _mesa_BindVertexArray(blit->ArrayObj); + + /* create vertex array buffer */ + _mesa_GenBuffersARB(1, &blit->VBO); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, blit->VBO); + _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), + NULL, GL_DYNAMIC_DRAW_ARB); + + /* setup vertex arrays */ + _mesa_VertexPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(x)); + _mesa_TexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(s)); + _mesa_EnableClientState(GL_VERTEX_ARRAY); + _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY); + } + else { + _mesa_BindVertexArray(blit->ArrayObj); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, blit->VBO); + } + + /* Try faster, direct texture approach first */ + mask = blitframebuffer_texture(ctx, srcX0, srcY0, srcX1, srcY1, + dstX0, dstY0, dstX1, dstY1, mask, filter); + if (mask == 0x0) { + _mesa_meta_end(ctx); + return; + } + + /* Continue with "normal" approach which involves copying the src rect + * into a temporary texture and is "blitted" by drawing a textured quad. + */ + + newTex = alloc_texture(tex, srcW, srcH, GL_RGBA); + + /* vertex positions/texcoords (after texture allocation!) */ + { + verts[0].x = (GLfloat) dstX0; + verts[0].y = (GLfloat) dstY0; + verts[1].x = (GLfloat) dstX1; + verts[1].y = (GLfloat) dstY0; + verts[2].x = (GLfloat) dstX1; + verts[2].y = (GLfloat) dstY1; + verts[3].x = (GLfloat) dstX0; + verts[3].y = (GLfloat) dstY1; + + verts[0].s = 0.0F; + verts[0].t = 0.0F; + verts[1].s = tex->Sright; + verts[1].t = 0.0F; + verts[2].s = tex->Sright; + verts[2].t = tex->Ttop; + verts[3].s = 0.0F; + verts[3].t = tex->Ttop; + + /* upload new vertex data */ + _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts); + } + + _mesa_set_enable(ctx, tex->Target, GL_TRUE); + + if (mask & GL_COLOR_BUFFER_BIT) { + setup_copypix_texture(tex, newTex, srcX, srcY, srcW, srcH, + GL_RGBA, filter); + _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4); + mask &= ~GL_COLOR_BUFFER_BIT; + } + + if (mask & GL_DEPTH_BUFFER_BIT) { + GLuint *tmp = (GLuint *) malloc(srcW * srcH * sizeof(GLuint)); + if (tmp) { + if (!blit->DepthFP) + init_blit_depth_pixels(ctx); + + /* maybe change tex format here */ + newTex = alloc_texture(tex, srcW, srcH, GL_DEPTH_COMPONENT); + + _mesa_ReadPixels(srcX, srcY, srcW, srcH, + GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, tmp); + + setup_drawpix_texture(ctx, tex, newTex, GL_DEPTH_COMPONENT, srcW, srcH, + GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, tmp); + + _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, blit->DepthFP); + _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, GL_TRUE); + _mesa_ColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + _mesa_set_enable(ctx, GL_DEPTH_TEST, GL_TRUE); + _mesa_DepthFunc(GL_ALWAYS); + _mesa_DepthMask(GL_TRUE); + + _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4); + mask &= ~GL_DEPTH_BUFFER_BIT; + + free(tmp); + } + } + + if (mask & GL_STENCIL_BUFFER_BIT) { + /* XXX can't easily do stencil */ + } + + _mesa_set_enable(ctx, tex->Target, GL_FALSE); + + _mesa_meta_end(ctx); + + if (mask) { + _swrast_BlitFramebuffer(ctx, srcX0, srcY0, srcX1, srcY1, + dstX0, dstY0, dstX1, dstY1, mask, filter); + } +} + + +/** + * Meta implementation of ctx->Driver.Clear() in terms of polygon rendering. + */ +void +_mesa_meta_Clear(struct gl_context *ctx, GLbitfield buffers) +{ + struct clear_state *clear = &ctx->Meta->Clear; + struct vertex { + GLfloat x, y, z, r, g, b, a; + }; + struct vertex verts[4]; + /* save all state but scissor, pixel pack/unpack */ + GLbitfield metaSave = META_ALL - META_SCISSOR - META_PIXEL_STORE; + const GLuint stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1; + + if (buffers & BUFFER_BITS_COLOR) { + /* if clearing color buffers, don't save/restore colormask */ + metaSave -= META_COLOR_MASK; + } + + _mesa_meta_begin(ctx, metaSave); + + if (clear->ArrayObj == 0) { + /* one-time setup */ + + /* create vertex array object */ + _mesa_GenVertexArrays(1, &clear->ArrayObj); + _mesa_BindVertexArray(clear->ArrayObj); + + /* create vertex array buffer */ + _mesa_GenBuffersARB(1, &clear->VBO); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, clear->VBO); + + /* setup vertex arrays */ + _mesa_VertexPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(x)); + _mesa_ColorPointer(4, GL_FLOAT, sizeof(struct vertex), OFFSET(r)); + _mesa_EnableClientState(GL_VERTEX_ARRAY); + _mesa_EnableClientState(GL_COLOR_ARRAY); + } + else { + _mesa_BindVertexArray(clear->ArrayObj); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, clear->VBO); + } + + /* GL_COLOR_BUFFER_BIT */ + if (buffers & BUFFER_BITS_COLOR) { + /* leave colormask, glDrawBuffer state as-is */ + } + else { + ASSERT(metaSave & META_COLOR_MASK); + _mesa_ColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + } + + /* GL_DEPTH_BUFFER_BIT */ + if (buffers & BUFFER_BIT_DEPTH) { + _mesa_set_enable(ctx, GL_DEPTH_TEST, GL_TRUE); + _mesa_DepthFunc(GL_ALWAYS); + _mesa_DepthMask(GL_TRUE); + } + else { + assert(!ctx->Depth.Test); + } + + /* GL_STENCIL_BUFFER_BIT */ + if (buffers & BUFFER_BIT_STENCIL) { + _mesa_set_enable(ctx, GL_STENCIL_TEST, GL_TRUE); + _mesa_StencilOpSeparate(GL_FRONT_AND_BACK, + GL_REPLACE, GL_REPLACE, GL_REPLACE); + _mesa_StencilFuncSeparate(GL_FRONT_AND_BACK, GL_ALWAYS, + ctx->Stencil.Clear & stencilMax, + ctx->Stencil.WriteMask[0]); + } + else { + assert(!ctx->Stencil.Enabled); + } + + /* vertex positions/colors */ + { + const GLfloat x0 = (GLfloat) ctx->DrawBuffer->_Xmin; + const GLfloat y0 = (GLfloat) ctx->DrawBuffer->_Ymin; + const GLfloat x1 = (GLfloat) ctx->DrawBuffer->_Xmax; + const GLfloat y1 = (GLfloat) ctx->DrawBuffer->_Ymax; + const GLfloat z = invert_z(ctx->Depth.Clear); + GLuint i; + + verts[0].x = x0; + verts[0].y = y0; + verts[0].z = z; + verts[1].x = x1; + verts[1].y = y0; + verts[1].z = z; + verts[2].x = x1; + verts[2].y = y1; + verts[2].z = z; + verts[3].x = x0; + verts[3].y = y1; + verts[3].z = z; + + /* vertex colors */ + for (i = 0; i < 4; i++) { + verts[i].r = ctx->Color.ClearColor[0]; + verts[i].g = ctx->Color.ClearColor[1]; + verts[i].b = ctx->Color.ClearColor[2]; + verts[i].a = ctx->Color.ClearColor[3]; + } + + /* upload new vertex data */ + _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts, + GL_DYNAMIC_DRAW_ARB); + } + + /* draw quad */ + _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4); + + _mesa_meta_end(ctx); +} + + +/** + * Meta implementation of ctx->Driver.CopyPixels() in terms + * of texture mapping and polygon rendering. + */ +void +_mesa_meta_CopyPixels(struct gl_context *ctx, GLint srcX, GLint srcY, + GLsizei width, GLsizei height, + GLint dstX, GLint dstY, GLenum type) +{ + struct copypix_state *copypix = &ctx->Meta->CopyPix; + struct temp_texture *tex = get_temp_texture(ctx); + struct vertex { + GLfloat x, y, z, s, t; + }; + struct vertex verts[4]; + GLboolean newTex; + GLenum intFormat = GL_RGBA; + + if (type != GL_COLOR || + ctx->_ImageTransferState || + ctx->Fog.Enabled || + width > tex->MaxSize || + height > tex->MaxSize) { + /* XXX avoid this fallback */ + _swrast_CopyPixels(ctx, srcX, srcY, width, height, dstX, dstY, type); + return; + } + + /* Most GL state applies to glCopyPixels, but a there's a few things + * we need to override: + */ + _mesa_meta_begin(ctx, (META_RASTERIZATION | + META_SHADER | + META_TEXTURE | + META_TRANSFORM | + META_VERTEX | + META_VIEWPORT)); + + if (copypix->ArrayObj == 0) { + /* one-time setup */ + + /* create vertex array object */ + _mesa_GenVertexArrays(1, ©pix->ArrayObj); + _mesa_BindVertexArray(copypix->ArrayObj); + + /* create vertex array buffer */ + _mesa_GenBuffersARB(1, ©pix->VBO); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, copypix->VBO); + _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), + NULL, GL_DYNAMIC_DRAW_ARB); + + /* setup vertex arrays */ + _mesa_VertexPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(x)); + _mesa_TexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(s)); + _mesa_EnableClientState(GL_VERTEX_ARRAY); + _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY); + } + else { + _mesa_BindVertexArray(copypix->ArrayObj); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, copypix->VBO); + } + + newTex = alloc_texture(tex, width, height, intFormat); + + /* vertex positions, texcoords (after texture allocation!) */ + { + const GLfloat dstX0 = (GLfloat) dstX; + const GLfloat dstY0 = (GLfloat) dstY; + const GLfloat dstX1 = dstX + width * ctx->Pixel.ZoomX; + const GLfloat dstY1 = dstY + height * ctx->Pixel.ZoomY; + const GLfloat z = invert_z(ctx->Current.RasterPos[2]); + + verts[0].x = dstX0; + verts[0].y = dstY0; + verts[0].z = z; + verts[0].s = 0.0F; + verts[0].t = 0.0F; + verts[1].x = dstX1; + verts[1].y = dstY0; + verts[1].z = z; + verts[1].s = tex->Sright; + verts[1].t = 0.0F; + verts[2].x = dstX1; + verts[2].y = dstY1; + verts[2].z = z; + verts[2].s = tex->Sright; + verts[2].t = tex->Ttop; + verts[3].x = dstX0; + verts[3].y = dstY1; + verts[3].z = z; + verts[3].s = 0.0F; + verts[3].t = tex->Ttop; + + /* upload new vertex data */ + _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts); + } + + /* Alloc/setup texture */ + setup_copypix_texture(tex, newTex, srcX, srcY, width, height, + GL_RGBA, GL_NEAREST); + + _mesa_set_enable(ctx, tex->Target, GL_TRUE); + + /* draw textured quad */ + _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4); + + _mesa_set_enable(ctx, tex->Target, GL_FALSE); + + _mesa_meta_end(ctx); +} + + + +/** + * When the glDrawPixels() image size is greater than the max rectangle + * texture size we use this function to break the glDrawPixels() image + * into tiles which fit into the max texture size. + */ +static void +tiled_draw_pixels(struct gl_context *ctx, + GLint tileSize, + GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *unpack, + const GLvoid *pixels) +{ + struct gl_pixelstore_attrib tileUnpack = *unpack; + GLint i, j; + + if (tileUnpack.RowLength == 0) + tileUnpack.RowLength = width; + + for (i = 0; i < width; i += tileSize) { + const GLint tileWidth = MIN2(tileSize, width - i); + const GLint tileX = (GLint) (x + i * ctx->Pixel.ZoomX); + + tileUnpack.SkipPixels = unpack->SkipPixels + i; + + for (j = 0; j < height; j += tileSize) { + const GLint tileHeight = MIN2(tileSize, height - j); + const GLint tileY = (GLint) (y + j * ctx->Pixel.ZoomY); + + tileUnpack.SkipRows = unpack->SkipRows + j; + + _mesa_meta_DrawPixels(ctx, tileX, tileY, tileWidth, tileHeight, + format, type, &tileUnpack, pixels); + } + } +} + + +/** + * One-time init for drawing stencil pixels. + */ +static void +init_draw_stencil_pixels(struct gl_context *ctx) +{ + /* This program is run eight times, once for each stencil bit. + * The stencil values to draw are found in an 8-bit alpha texture. + * We read the texture/stencil value and test if bit 'b' is set. + * If the bit is not set, use KIL to kill the fragment. + * Finally, we use the stencil test to update the stencil buffer. + * + * The basic algorithm for checking if a bit is set is: + * if (is_odd(value / (1 << bit))) + * result is one (or non-zero). + * else + * result is zero. + * The program parameter contains three values: + * parm.x = 255 / (1 << bit) + * parm.y = 0.5 + * parm.z = 0.0 + */ + static const char *program = + "!!ARBfp1.0\n" + "PARAM parm = program.local[0]; \n" + "TEMP t; \n" + "TEX t, fragment.texcoord[0], texture[0], %s; \n" /* NOTE %s here! */ + "# t = t * 255 / bit \n" + "MUL t.x, t.a, parm.x; \n" + "# t = (int) t \n" + "FRC t.y, t.x; \n" + "SUB t.x, t.x, t.y; \n" + "# t = t * 0.5 \n" + "MUL t.x, t.x, parm.y; \n" + "# t = fract(t.x) \n" + "FRC t.x, t.x; # if t.x != 0, then the bit is set \n" + "# t.x = (t.x == 0 ? 1 : 0) \n" + "SGE t.x, -t.x, parm.z; \n" + "KIL -t.x; \n" + "# for debug only \n" + "#MOV result.color, t.x; \n" + "END \n"; + char program2[1000]; + struct drawpix_state *drawpix = &ctx->Meta->DrawPix; + struct temp_texture *tex = get_temp_texture(ctx); + const char *texTarget; + + assert(drawpix->StencilFP == 0); + + /* replace %s with "RECT" or "2D" */ + assert(strlen(program) + 4 < sizeof(program2)); + if (tex->Target == GL_TEXTURE_RECTANGLE) + texTarget = "RECT"; + else + texTarget = "2D"; + _mesa_snprintf(program2, sizeof(program2), program, texTarget); + + _mesa_GenPrograms(1, &drawpix->StencilFP); + _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, drawpix->StencilFP); + _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(program2), (const GLubyte *) program2); +} + + +/** + * One-time init for drawing depth pixels. + */ +static void +init_draw_depth_pixels(struct gl_context *ctx) +{ + static const char *program = + "!!ARBfp1.0\n" + "PARAM color = program.local[0]; \n" + "TEX result.depth, fragment.texcoord[0], texture[0], %s; \n" + "MOV result.color, color; \n" + "END \n"; + char program2[200]; + struct drawpix_state *drawpix = &ctx->Meta->DrawPix; + struct temp_texture *tex = get_temp_texture(ctx); + const char *texTarget; + + assert(drawpix->DepthFP == 0); + + /* replace %s with "RECT" or "2D" */ + assert(strlen(program) + 4 < sizeof(program2)); + if (tex->Target == GL_TEXTURE_RECTANGLE) + texTarget = "RECT"; + else + texTarget = "2D"; + _mesa_snprintf(program2, sizeof(program2), program, texTarget); + + _mesa_GenPrograms(1, &drawpix->DepthFP); + _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, drawpix->DepthFP); + _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(program2), (const GLubyte *) program2); +} + + +/** + * Meta implementation of ctx->Driver.DrawPixels() in terms + * of texture mapping and polygon rendering. + */ +void +_mesa_meta_DrawPixels(struct gl_context *ctx, + GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *unpack, + const GLvoid *pixels) +{ + struct drawpix_state *drawpix = &ctx->Meta->DrawPix; + struct temp_texture *tex = get_temp_texture(ctx); + const struct gl_pixelstore_attrib unpackSave = ctx->Unpack; + const GLuint origStencilMask = ctx->Stencil.WriteMask[0]; + struct vertex { + GLfloat x, y, z, s, t; + }; + struct vertex verts[4]; + GLenum texIntFormat; + GLboolean fallback, newTex; + GLbitfield metaExtraSave = 0x0; + GLuint vbo; + + /* + * Determine if we can do the glDrawPixels with texture mapping. + */ + fallback = GL_FALSE; + if (ctx->_ImageTransferState || + ctx->Fog.Enabled) { + fallback = GL_TRUE; + } + + if (_mesa_is_color_format(format)) { + /* use more compact format when possible */ + /* XXX disable special case for GL_LUMINANCE for now to work around + * apparent i965 driver bug (see bug #23670). + */ + if (/*format == GL_LUMINANCE ||*/ format == GL_LUMINANCE_ALPHA) + texIntFormat = format; + else + texIntFormat = GL_RGBA; + } + else if (_mesa_is_stencil_format(format)) { + if (ctx->Extensions.ARB_fragment_program && + ctx->Pixel.IndexShift == 0 && + ctx->Pixel.IndexOffset == 0 && + type == GL_UNSIGNED_BYTE) { + /* We'll store stencil as alpha. This only works for GLubyte + * image data because of how incoming values are mapped to alpha + * in [0,1]. + */ + texIntFormat = GL_ALPHA; + metaExtraSave = (META_COLOR_MASK | + META_DEPTH_TEST | + META_SHADER | + META_STENCIL_TEST); + } + else { + fallback = GL_TRUE; + } + } + else if (_mesa_is_depth_format(format)) { + if (ctx->Extensions.ARB_depth_texture && + ctx->Extensions.ARB_fragment_program) { + texIntFormat = GL_DEPTH_COMPONENT; + metaExtraSave = (META_SHADER); + } + else { + fallback = GL_TRUE; + } + } + else { + fallback = GL_TRUE; + } + + if (fallback) { + _swrast_DrawPixels(ctx, x, y, width, height, + format, type, unpack, pixels); + return; + } + + /* + * Check image size against max texture size, draw as tiles if needed. + */ + if (width > tex->MaxSize || height > tex->MaxSize) { + tiled_draw_pixels(ctx, tex->MaxSize, x, y, width, height, + format, type, unpack, pixels); + return; + } + + /* Most GL state applies to glDrawPixels (like blending, stencil, etc), + * but a there's a few things we need to override: + */ + _mesa_meta_begin(ctx, (META_RASTERIZATION | + META_SHADER | + META_TEXTURE | + META_TRANSFORM | + META_VERTEX | + META_VIEWPORT | + metaExtraSave)); + + newTex = alloc_texture(tex, width, height, texIntFormat); + + /* vertex positions, texcoords (after texture allocation!) */ + { + const GLfloat x0 = (GLfloat) x; + const GLfloat y0 = (GLfloat) y; + const GLfloat x1 = x + width * ctx->Pixel.ZoomX; + const GLfloat y1 = y + height * ctx->Pixel.ZoomY; + const GLfloat z = invert_z(ctx->Current.RasterPos[2]); + + verts[0].x = x0; + verts[0].y = y0; + verts[0].z = z; + verts[0].s = 0.0F; + verts[0].t = 0.0F; + verts[1].x = x1; + verts[1].y = y0; + verts[1].z = z; + verts[1].s = tex->Sright; + verts[1].t = 0.0F; + verts[2].x = x1; + verts[2].y = y1; + verts[2].z = z; + verts[2].s = tex->Sright; + verts[2].t = tex->Ttop; + verts[3].x = x0; + verts[3].y = y1; + verts[3].z = z; + verts[3].s = 0.0F; + verts[3].t = tex->Ttop; + } + + if (drawpix->ArrayObj == 0) { + /* one-time setup: create vertex array object */ + _mesa_GenVertexArrays(1, &drawpix->ArrayObj); + } + _mesa_BindVertexArray(drawpix->ArrayObj); + + /* create vertex array buffer */ + _mesa_GenBuffersARB(1, &vbo); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, vbo); + _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), + verts, GL_DYNAMIC_DRAW_ARB); + + /* setup vertex arrays */ + _mesa_VertexPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(x)); + _mesa_TexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(s)); + _mesa_EnableClientState(GL_VERTEX_ARRAY); + _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY); + + /* set given unpack params */ + ctx->Unpack = *unpack; + + _mesa_set_enable(ctx, tex->Target, GL_TRUE); + + if (_mesa_is_stencil_format(format)) { + /* Drawing stencil */ + GLint bit; + + if (!drawpix->StencilFP) + init_draw_stencil_pixels(ctx); + + setup_drawpix_texture(ctx, tex, newTex, texIntFormat, width, height, + GL_ALPHA, type, pixels); + + _mesa_ColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + + _mesa_set_enable(ctx, GL_STENCIL_TEST, GL_TRUE); + + /* set all stencil bits to 0 */ + _mesa_StencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); + _mesa_StencilFunc(GL_ALWAYS, 0, 255); + _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4); + + /* set stencil bits to 1 where needed */ + _mesa_StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + + _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, drawpix->StencilFP); + _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, GL_TRUE); + + for (bit = 0; bit < ctx->DrawBuffer->Visual.stencilBits; bit++) { + const GLuint mask = 1 << bit; + if (mask & origStencilMask) { + _mesa_StencilFunc(GL_ALWAYS, mask, mask); + _mesa_StencilMask(mask); + + _mesa_ProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, + 255.0 / mask, 0.5, 0.0, 0.0); + + _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4); + } + } + } + else if (_mesa_is_depth_format(format)) { + /* Drawing depth */ + if (!drawpix->DepthFP) + init_draw_depth_pixels(ctx); + + _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, drawpix->DepthFP); + _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, GL_TRUE); + + /* polygon color = current raster color */ + _mesa_ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0, + ctx->Current.RasterColor); + + setup_drawpix_texture(ctx, tex, newTex, texIntFormat, width, height, + format, type, pixels); + + _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4); + } + else { + /* Drawing RGBA */ + setup_drawpix_texture(ctx, tex, newTex, texIntFormat, width, height, + format, type, pixels); + _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4); + } + + _mesa_set_enable(ctx, tex->Target, GL_FALSE); + + _mesa_DeleteBuffersARB(1, &vbo); + + /* restore unpack params */ + ctx->Unpack = unpackSave; + + _mesa_meta_end(ctx); +} + +static GLboolean +alpha_test_raster_color(struct gl_context *ctx) +{ + GLfloat alpha = ctx->Current.RasterColor[ACOMP]; + GLfloat ref = ctx->Color.AlphaRef; + + switch (ctx->Color.AlphaFunc) { + case GL_NEVER: + return GL_FALSE; + case GL_LESS: + return alpha < ref; + case GL_EQUAL: + return alpha == ref; + case GL_LEQUAL: + return alpha <= ref; + case GL_GREATER: + return alpha > ref; + case GL_NOTEQUAL: + return alpha != ref; + case GL_GEQUAL: + return alpha >= ref; + case GL_ALWAYS: + return GL_TRUE; + default: + assert(0); + return GL_FALSE; + } +} + +/** + * Do glBitmap with a alpha texture quad. Use the alpha test to cull + * the 'off' bits. A bitmap cache as in the gallium/mesa state + * tracker would improve performance a lot. + */ +void +_mesa_meta_Bitmap(struct gl_context *ctx, + GLint x, GLint y, GLsizei width, GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte *bitmap1) +{ + struct bitmap_state *bitmap = &ctx->Meta->Bitmap; + struct temp_texture *tex = get_bitmap_temp_texture(ctx); + const GLenum texIntFormat = GL_ALPHA; + const struct gl_pixelstore_attrib unpackSave = *unpack; + GLubyte fg, bg; + struct vertex { + GLfloat x, y, z, s, t, r, g, b, a; + }; + struct vertex verts[4]; + GLboolean newTex; + GLubyte *bitmap8; + + /* + * Check if swrast fallback is needed. + */ + if (ctx->_ImageTransferState || + ctx->FragmentProgram._Enabled || + ctx->Fog.Enabled || + ctx->Texture._EnabledUnits || + width > tex->MaxSize || + height > tex->MaxSize) { + _swrast_Bitmap(ctx, x, y, width, height, unpack, bitmap1); + return; + } + + if (ctx->Color.AlphaEnabled && !alpha_test_raster_color(ctx)) + return; + + /* Most GL state applies to glBitmap (like blending, stencil, etc), + * but a there's a few things we need to override: + */ + _mesa_meta_begin(ctx, (META_ALPHA_TEST | + META_PIXEL_STORE | + META_RASTERIZATION | + META_SHADER | + META_TEXTURE | + META_TRANSFORM | + META_VERTEX | + META_VIEWPORT)); + + if (bitmap->ArrayObj == 0) { + /* one-time setup */ + + /* create vertex array object */ + _mesa_GenVertexArraysAPPLE(1, &bitmap->ArrayObj); + _mesa_BindVertexArrayAPPLE(bitmap->ArrayObj); + + /* create vertex array buffer */ + _mesa_GenBuffersARB(1, &bitmap->VBO); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, bitmap->VBO); + _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), + NULL, GL_DYNAMIC_DRAW_ARB); + + /* setup vertex arrays */ + _mesa_VertexPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(x)); + _mesa_TexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(s)); + _mesa_ColorPointer(4, GL_FLOAT, sizeof(struct vertex), OFFSET(r)); + _mesa_EnableClientState(GL_VERTEX_ARRAY); + _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY); + _mesa_EnableClientState(GL_COLOR_ARRAY); + } + else { + _mesa_BindVertexArray(bitmap->ArrayObj); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, bitmap->VBO); + } + + newTex = alloc_texture(tex, width, height, texIntFormat); + + /* vertex positions, texcoords, colors (after texture allocation!) */ + { + const GLfloat x0 = (GLfloat) x; + const GLfloat y0 = (GLfloat) y; + const GLfloat x1 = (GLfloat) (x + width); + const GLfloat y1 = (GLfloat) (y + height); + const GLfloat z = invert_z(ctx->Current.RasterPos[2]); + GLuint i; + + verts[0].x = x0; + verts[0].y = y0; + verts[0].z = z; + verts[0].s = 0.0F; + verts[0].t = 0.0F; + verts[1].x = x1; + verts[1].y = y0; + verts[1].z = z; + verts[1].s = tex->Sright; + verts[1].t = 0.0F; + verts[2].x = x1; + verts[2].y = y1; + verts[2].z = z; + verts[2].s = tex->Sright; + verts[2].t = tex->Ttop; + verts[3].x = x0; + verts[3].y = y1; + verts[3].z = z; + verts[3].s = 0.0F; + verts[3].t = tex->Ttop; + + for (i = 0; i < 4; i++) { + verts[i].r = ctx->Current.RasterColor[0]; + verts[i].g = ctx->Current.RasterColor[1]; + verts[i].b = ctx->Current.RasterColor[2]; + verts[i].a = ctx->Current.RasterColor[3]; + } + + /* upload new vertex data */ + _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts); + } + + /* choose different foreground/background alpha values */ + CLAMPED_FLOAT_TO_UBYTE(fg, ctx->Current.RasterColor[ACOMP]); + bg = (fg > 127 ? 0 : 255); + + bitmap1 = _mesa_map_pbo_source(ctx, &unpackSave, bitmap1); + if (!bitmap1) { + _mesa_meta_end(ctx); + return; + } + + bitmap8 = (GLubyte *) malloc(width * height); + if (bitmap8) { + memset(bitmap8, bg, width * height); + _mesa_expand_bitmap(width, height, &unpackSave, bitmap1, + bitmap8, width, fg); + + _mesa_set_enable(ctx, tex->Target, GL_TRUE); + + _mesa_set_enable(ctx, GL_ALPHA_TEST, GL_TRUE); + _mesa_AlphaFunc(GL_NOTEQUAL, UBYTE_TO_FLOAT(bg)); + + setup_drawpix_texture(ctx, tex, newTex, texIntFormat, width, height, + GL_ALPHA, GL_UNSIGNED_BYTE, bitmap8); + + _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4); + + _mesa_set_enable(ctx, tex->Target, GL_FALSE); + + free(bitmap8); + } + + _mesa_unmap_pbo_source(ctx, &unpackSave); + + _mesa_meta_end(ctx); +} + + +/** + * Check if the call to _mesa_meta_GenerateMipmap() will require a + * software fallback. The fallback path will require that the texture + * images are mapped. + * \return GL_TRUE if a fallback is needed, GL_FALSE otherwise + */ +GLboolean +_mesa_meta_check_generate_mipmap_fallback(struct gl_context *ctx, GLenum target, + struct gl_texture_object *texObj) +{ + const GLuint fboSave = ctx->DrawBuffer->Name; + struct gen_mipmap_state *mipmap = &ctx->Meta->Mipmap; + struct gl_texture_image *baseImage; + GLuint srcLevel; + GLenum status; + + /* check for fallbacks */ + if (!ctx->Extensions.EXT_framebuffer_object || + target == GL_TEXTURE_3D) { + return GL_TRUE; + } + + srcLevel = texObj->BaseLevel; + baseImage = _mesa_select_tex_image(ctx, texObj, target, srcLevel); + if (!baseImage || _mesa_is_format_compressed(baseImage->TexFormat)) { + return GL_TRUE; + } + + /* + * Test that we can actually render in the texture's format. + */ + if (!mipmap->FBO) + _mesa_GenFramebuffersEXT(1, &mipmap->FBO); + _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, mipmap->FBO); + + if (target == GL_TEXTURE_1D) { + _mesa_FramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + target, texObj->Name, srcLevel); + } +#if 0 + /* other work is needed to enable 3D mipmap generation */ + else if (target == GL_TEXTURE_3D) { + GLint zoffset = 0; + _mesa_FramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + target, texObj->Name, srcLevel, zoffset); + } +#endif + else { + /* 2D / cube */ + _mesa_FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + target, texObj->Name, srcLevel); + } + + status = _mesa_CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + + _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboSave); + + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + return GL_TRUE; + } + + return GL_FALSE; +} + + +/** + * Called via ctx->Driver.GenerateMipmap() + * Note: texture borders and 3D texture support not yet complete. + */ +void +_mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, + struct gl_texture_object *texObj) +{ + struct gen_mipmap_state *mipmap = &ctx->Meta->Mipmap; + struct vertex { + GLfloat x, y, s, t, r; + }; + struct vertex verts[4]; + const GLuint baseLevel = texObj->BaseLevel; + const GLuint maxLevel = texObj->MaxLevel; + const GLenum minFilterSave = texObj->MinFilter; + const GLenum magFilterSave = texObj->MagFilter; + const GLint baseLevelSave = texObj->BaseLevel; + const GLint maxLevelSave = texObj->MaxLevel; + const GLboolean genMipmapSave = texObj->GenerateMipmap; + const GLenum wrapSSave = texObj->WrapS; + const GLenum wrapTSave = texObj->WrapT; + const GLenum wrapRSave = texObj->WrapR; + const GLuint fboSave = ctx->DrawBuffer->Name; + const GLuint original_active_unit = ctx->Texture.CurrentUnit; + GLenum faceTarget; + GLuint dstLevel; + GLuint border = 0; + + if (_mesa_meta_check_generate_mipmap_fallback(ctx, target, texObj)) { + _mesa_generate_mipmap(ctx, target, texObj); + return; + } + + if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && + target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z) { + faceTarget = target; + target = GL_TEXTURE_CUBE_MAP; + } + else { + faceTarget = target; + } + + _mesa_meta_begin(ctx, META_ALL); + + if (original_active_unit != 0) + _mesa_BindTexture(target, texObj->Name); + + if (mipmap->ArrayObj == 0) { + /* one-time setup */ + + /* create vertex array object */ + _mesa_GenVertexArraysAPPLE(1, &mipmap->ArrayObj); + _mesa_BindVertexArrayAPPLE(mipmap->ArrayObj); + + /* create vertex array buffer */ + _mesa_GenBuffersARB(1, &mipmap->VBO); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, mipmap->VBO); + _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), + NULL, GL_DYNAMIC_DRAW_ARB); + + /* setup vertex arrays */ + _mesa_VertexPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(x)); + _mesa_TexCoordPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(s)); + _mesa_EnableClientState(GL_VERTEX_ARRAY); + _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY); + } + else { + _mesa_BindVertexArray(mipmap->ArrayObj); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, mipmap->VBO); + } + + if (!mipmap->FBO) { + _mesa_GenFramebuffersEXT(1, &mipmap->FBO); + } + _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, mipmap->FBO); + + _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + _mesa_TexParameteri(target, GL_GENERATE_MIPMAP, GL_FALSE); + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); + + _mesa_set_enable(ctx, target, GL_TRUE); + + /* setup texcoords once (XXX what about border?) */ + switch (faceTarget) { + case GL_TEXTURE_1D: + case GL_TEXTURE_2D: + verts[0].s = 0.0F; + verts[0].t = 0.0F; + verts[0].r = 0.0F; + verts[1].s = 1.0F; + verts[1].t = 0.0F; + verts[1].r = 0.0F; + verts[2].s = 1.0F; + verts[2].t = 1.0F; + verts[2].r = 0.0F; + verts[3].s = 0.0F; + verts[3].t = 1.0F; + verts[3].r = 0.0F; + break; + case GL_TEXTURE_3D: + abort(); + break; + default: + /* cube face */ + { + static const GLfloat st[4][2] = { + {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f} + }; + GLuint i; + + /* loop over quad verts */ + for (i = 0; i < 4; i++) { + /* Compute sc = +/-scale and tc = +/-scale. + * Not +/-1 to avoid cube face selection ambiguity near the edges, + * though that can still sometimes happen with this scale factor... + */ + const GLfloat scale = 0.9999f; + const GLfloat sc = (2.0f * st[i][0] - 1.0f) * scale; + const GLfloat tc = (2.0f * st[i][1] - 1.0f) * scale; + + switch (faceTarget) { + case GL_TEXTURE_CUBE_MAP_POSITIVE_X: + verts[i].s = 1.0f; + verts[i].t = -tc; + verts[i].r = -sc; + break; + case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: + verts[i].s = -1.0f; + verts[i].t = -tc; + verts[i].r = sc; + break; + case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: + verts[i].s = sc; + verts[i].t = 1.0f; + verts[i].r = tc; + break; + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: + verts[i].s = sc; + verts[i].t = -1.0f; + verts[i].r = -tc; + break; + case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: + verts[i].s = sc; + verts[i].t = -tc; + verts[i].r = 1.0f; + break; + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: + verts[i].s = -sc; + verts[i].t = -tc; + verts[i].r = -1.0f; + break; + default: + assert(0); + } + } + } + } + + _mesa_set_enable(ctx, target, GL_TRUE); + + /* setup vertex positions */ + { + verts[0].x = 0.0F; + verts[0].y = 0.0F; + verts[1].x = 1.0F; + verts[1].y = 0.0F; + verts[2].x = 1.0F; + verts[2].y = 1.0F; + verts[3].x = 0.0F; + verts[3].y = 1.0F; + + /* upload new vertex data */ + _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts); + } + + /* setup projection matrix */ + _mesa_MatrixMode(GL_PROJECTION); + _mesa_LoadIdentity(); + _mesa_Ortho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); + + /* texture is already locked, unlock now */ + _mesa_unlock_texture(ctx, texObj); + + for (dstLevel = baseLevel + 1; dstLevel <= maxLevel; dstLevel++) { + const struct gl_texture_image *srcImage; + const GLuint srcLevel = dstLevel - 1; + GLsizei srcWidth, srcHeight, srcDepth; + GLsizei dstWidth, dstHeight, dstDepth; + GLenum status; + + srcImage = _mesa_select_tex_image(ctx, texObj, faceTarget, srcLevel); + assert(srcImage->Border == 0); /* XXX we can fix this */ + + /* src size w/out border */ + srcWidth = srcImage->Width - 2 * border; + srcHeight = srcImage->Height - 2 * border; + srcDepth = srcImage->Depth - 2 * border; + + /* new dst size w/ border */ + dstWidth = MAX2(1, srcWidth / 2) + 2 * border; + dstHeight = MAX2(1, srcHeight / 2) + 2 * border; + dstDepth = MAX2(1, srcDepth / 2) + 2 * border; + + if (dstWidth == srcImage->Width && + dstHeight == srcImage->Height && + dstDepth == srcImage->Depth) { + /* all done */ + break; + } + + /* Set MaxLevel large enough to hold the new level when we allocate it */ + _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, dstLevel); + + /* Create empty dest image */ + if (target == GL_TEXTURE_1D) { + _mesa_TexImage1D(target, dstLevel, srcImage->InternalFormat, + dstWidth, border, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + } + else if (target == GL_TEXTURE_3D) { + _mesa_TexImage3D(target, dstLevel, srcImage->InternalFormat, + dstWidth, dstHeight, dstDepth, border, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + } + else { + /* 2D or cube */ + _mesa_TexImage2D(faceTarget, dstLevel, srcImage->InternalFormat, + dstWidth, dstHeight, border, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + + if (target == GL_TEXTURE_CUBE_MAP) { + /* If texturing from a cube, we need to make sure all src faces + * have been defined (even if we're not sampling from them.) + * Otherwise the texture object will be 'incomplete' and + * texturing from it will not be allowed. + */ + GLuint face; + for (face = 0; face < 6; face++) { + if (!texObj->Image[face][srcLevel] || + texObj->Image[face][srcLevel]->Width != srcWidth) { + _mesa_TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, + srcLevel, srcImage->InternalFormat, + srcWidth, srcHeight, border, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + } + } + } + } + + /* limit sampling to src level */ + _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, srcLevel); + _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, srcLevel); + + /* Set to draw into the current dstLevel */ + if (target == GL_TEXTURE_1D) { + _mesa_FramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + target, + texObj->Name, + dstLevel); + } + else if (target == GL_TEXTURE_3D) { + GLint zoffset = 0; /* XXX unfinished */ + _mesa_FramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + target, + texObj->Name, + dstLevel, zoffset); + } + else { + /* 2D / cube */ + _mesa_FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, + GL_COLOR_ATTACHMENT0_EXT, + faceTarget, + texObj->Name, + dstLevel); + } + + _mesa_DrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + + /* sanity check */ + status = _mesa_CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + abort(); + break; + } + + assert(dstWidth == ctx->DrawBuffer->Width); + assert(dstHeight == ctx->DrawBuffer->Height); + + /* setup viewport */ + _mesa_set_viewport(ctx, 0, 0, dstWidth, dstHeight); + + _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4); + } + + _mesa_lock_texture(ctx, texObj); /* relock */ + + _mesa_meta_end(ctx); + + _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilterSave); + _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilterSave); + _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, baseLevelSave); + _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, maxLevelSave); + _mesa_TexParameteri(target, GL_GENERATE_MIPMAP, genMipmapSave); + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, wrapSSave); + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, wrapTSave); + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, wrapRSave); + + _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboSave); +} + + +/** + * Determine the GL data type to use for the temporary image read with + * ReadPixels() and passed to Tex[Sub]Image(). + */ +static GLenum +get_temp_image_type(struct gl_context *ctx, GLenum baseFormat) +{ + switch (baseFormat) { + case GL_RGBA: + case GL_RGB: + case GL_ALPHA: + case GL_LUMINANCE: + case GL_LUMINANCE_ALPHA: + case GL_INTENSITY: + if (ctx->DrawBuffer->Visual.redBits <= 8) + return GL_UNSIGNED_BYTE; + else if (ctx->DrawBuffer->Visual.redBits <= 8) + return GL_UNSIGNED_SHORT; + else + return GL_FLOAT; + case GL_DEPTH_COMPONENT: + return GL_UNSIGNED_INT; + case GL_DEPTH_STENCIL: + return GL_UNSIGNED_INT_24_8; + default: + _mesa_problem(ctx, "Unexpected format in get_temp_image_type()"); + return 0; + } +} + + +/** + * Helper for _mesa_meta_CopyTexImage1/2D() functions. + * Have to be careful with locking and meta state for pixel transfer. + */ +static void +copy_tex_image(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, + GLenum internalFormat, GLint x, GLint y, + GLsizei width, GLsizei height, GLint border) +{ + struct gl_texture_object *texObj; + struct gl_texture_image *texImage; + GLenum format, type; + GLint bpp; + void *buf; + + texObj = _mesa_get_current_tex_object(ctx, target); + texImage = _mesa_get_tex_image(ctx, texObj, target, level); + + /* Choose format/type for temporary image buffer */ + format = _mesa_base_tex_format(ctx, internalFormat); + type = get_temp_image_type(ctx, format); + bpp = _mesa_bytes_per_pixel(format, type); + if (bpp <= 0) { + _mesa_problem(ctx, "Bad bpp in meta copy_tex_image()"); + return; + } + + /* + * Alloc image buffer (XXX could use a PBO) + */ + buf = malloc(width * height * bpp); + if (!buf) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage%uD", dims); + return; + } + + _mesa_unlock_texture(ctx, texObj); /* need to unlock first */ + + /* + * Read image from framebuffer (disable pixel transfer ops) + */ + _mesa_meta_begin(ctx, META_PIXEL_STORE | META_PIXEL_TRANSFER); + ctx->Driver.ReadPixels(ctx, x, y, width, height, + format, type, &ctx->Pack, buf); + _mesa_meta_end(ctx); + + if (texImage->Data) { + ctx->Driver.FreeTexImageData(ctx, texImage); + } + + /* The texture's format was already chosen in _mesa_CopyTexImage() */ + ASSERT(texImage->TexFormat != MESA_FORMAT_NONE); + + /* + * Store texture data (with pixel transfer ops) + */ + _mesa_meta_begin(ctx, META_PIXEL_STORE); + + _mesa_update_state(ctx); /* to update pixel transfer state */ + + if (target == GL_TEXTURE_1D) { + ctx->Driver.TexImage1D(ctx, target, level, internalFormat, + width, border, format, type, + buf, &ctx->Unpack, texObj, texImage); + } + else { + ctx->Driver.TexImage2D(ctx, target, level, internalFormat, + width, height, border, format, type, + buf, &ctx->Unpack, texObj, texImage); + } + _mesa_meta_end(ctx); + + _mesa_lock_texture(ctx, texObj); /* re-lock */ + + free(buf); +} + + +void +_mesa_meta_CopyTexImage1D(struct gl_context *ctx, GLenum target, GLint level, + GLenum internalFormat, GLint x, GLint y, + GLsizei width, GLint border) +{ + copy_tex_image(ctx, 1, target, level, internalFormat, x, y, + width, 1, border); +} + + +void +_mesa_meta_CopyTexImage2D(struct gl_context *ctx, GLenum target, GLint level, + GLenum internalFormat, GLint x, GLint y, + GLsizei width, GLsizei height, GLint border) +{ + copy_tex_image(ctx, 2, target, level, internalFormat, x, y, + width, height, border); +} + + + +/** + * Helper for _mesa_meta_CopyTexSubImage1/2/3D() functions. + * Have to be careful with locking and meta state for pixel transfer. + */ +static void +copy_tex_sub_image(struct gl_context *ctx, + GLuint dims, GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, + GLint x, GLint y, + GLsizei width, GLsizei height) +{ + struct gl_texture_object *texObj; + struct gl_texture_image *texImage; + GLenum format, type; + GLint bpp; + void *buf; + + texObj = _mesa_get_current_tex_object(ctx, target); + texImage = _mesa_select_tex_image(ctx, texObj, target, level); + + /* Choose format/type for temporary image buffer */ + format = _mesa_get_format_base_format(texImage->TexFormat); + type = get_temp_image_type(ctx, format); + bpp = _mesa_bytes_per_pixel(format, type); + if (bpp <= 0) { + _mesa_problem(ctx, "Bad bpp in meta copy_tex_sub_image()"); + return; + } + + /* + * Alloc image buffer (XXX could use a PBO) + */ + buf = malloc(width * height * bpp); + if (!buf) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage%uD", dims); + return; + } + + _mesa_unlock_texture(ctx, texObj); /* need to unlock first */ + + /* + * Read image from framebuffer (disable pixel transfer ops) + */ + _mesa_meta_begin(ctx, META_PIXEL_STORE | META_PIXEL_TRANSFER); + ctx->Driver.ReadPixels(ctx, x, y, width, height, + format, type, &ctx->Pack, buf); + _mesa_meta_end(ctx); + + _mesa_update_state(ctx); /* to update pixel transfer state */ + + /* + * Store texture data (with pixel transfer ops) + */ + _mesa_meta_begin(ctx, META_PIXEL_STORE); + if (target == GL_TEXTURE_1D) { + ctx->Driver.TexSubImage1D(ctx, target, level, xoffset, + width, format, type, buf, + &ctx->Unpack, texObj, texImage); + } + else if (target == GL_TEXTURE_3D) { + ctx->Driver.TexSubImage3D(ctx, target, level, xoffset, yoffset, zoffset, + width, height, 1, format, type, buf, + &ctx->Unpack, texObj, texImage); + } + else { + ctx->Driver.TexSubImage2D(ctx, target, level, xoffset, yoffset, + width, height, format, type, buf, + &ctx->Unpack, texObj, texImage); + } + _mesa_meta_end(ctx); + + _mesa_lock_texture(ctx, texObj); /* re-lock */ + + free(buf); +} + + +void +_mesa_meta_CopyTexSubImage1D(struct gl_context *ctx, GLenum target, GLint level, + GLint xoffset, + GLint x, GLint y, GLsizei width) +{ + copy_tex_sub_image(ctx, 1, target, level, xoffset, 0, 0, + x, y, width, 1); +} + + +void +_mesa_meta_CopyTexSubImage2D(struct gl_context *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint x, GLint y, + GLsizei width, GLsizei height) +{ + copy_tex_sub_image(ctx, 2, target, level, xoffset, yoffset, 0, + x, y, width, height); +} + + +void +_mesa_meta_CopyTexSubImage3D(struct gl_context *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, + GLint x, GLint y, + GLsizei width, GLsizei height) +{ + copy_tex_sub_image(ctx, 3, target, level, xoffset, yoffset, zoffset, + x, y, width, height); +} + + +void +_mesa_meta_CopyColorTable(struct gl_context *ctx, + GLenum target, GLenum internalformat, + GLint x, GLint y, GLsizei width) +{ + GLfloat *buf; + + buf = (GLfloat *) malloc(width * 4 * sizeof(GLfloat)); + if (!buf) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyColorTable"); + return; + } + + /* + * Read image from framebuffer (disable pixel transfer ops) + */ + _mesa_meta_begin(ctx, META_PIXEL_STORE | META_PIXEL_TRANSFER); + ctx->Driver.ReadPixels(ctx, x, y, width, 1, + GL_RGBA, GL_FLOAT, &ctx->Pack, buf); + + _mesa_ColorTable(target, internalformat, width, GL_RGBA, GL_FLOAT, buf); + + _mesa_meta_end(ctx); + + free(buf); +} + + +void +_mesa_meta_CopyColorSubTable(struct gl_context *ctx,GLenum target, GLsizei start, + GLint x, GLint y, GLsizei width) +{ + GLfloat *buf; + + buf = (GLfloat *) malloc(width * 4 * sizeof(GLfloat)); + if (!buf) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyColorSubTable"); + return; + } + + /* + * Read image from framebuffer (disable pixel transfer ops) + */ + _mesa_meta_begin(ctx, META_PIXEL_STORE | META_PIXEL_TRANSFER); + ctx->Driver.ReadPixels(ctx, x, y, width, 1, + GL_RGBA, GL_FLOAT, &ctx->Pack, buf); + + _mesa_ColorSubTable(target, start, width, GL_RGBA, GL_FLOAT, buf); + + _mesa_meta_end(ctx); + + free(buf); +} diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h new file mode 100644 index 0000000..b0797d3 --- /dev/null +++ b/src/mesa/drivers/common/meta.h @@ -0,0 +1,118 @@ +/* + * Mesa 3-D graphics library + * Version: 7.6 + * + * Copyright (C) 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 + * 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. + */ + + +#ifndef META_H +#define META_H + + +extern void +_mesa_meta_init(struct gl_context *ctx); + +extern void +_mesa_meta_free(struct gl_context *ctx); + +extern void +_mesa_meta_BlitFramebuffer(struct gl_context *ctx, + GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, + GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, + GLbitfield mask, GLenum filter); + +extern void +_mesa_meta_Clear(struct gl_context *ctx, GLbitfield buffers); + +extern void +_mesa_meta_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy, + GLsizei width, GLsizei height, + GLint dstx, GLint dsty, GLenum type); + +extern void +_mesa_meta_DrawPixels(struct gl_context *ctx, + GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, + const struct gl_pixelstore_attrib *unpack, + const GLvoid *pixels); + +extern void +_mesa_meta_Bitmap(struct gl_context *ctx, + GLint x, GLint y, GLsizei width, GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte *bitmap); + +extern GLboolean +_mesa_meta_check_generate_mipmap_fallback(struct gl_context *ctx, GLenum target, + struct gl_texture_object *texObj); + +extern void +_mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, + struct gl_texture_object *texObj); + +extern void +_mesa_meta_CopyTexImage1D(struct gl_context *ctx, GLenum target, GLint level, + GLenum internalFormat, GLint x, GLint y, + GLsizei width, GLint border); + +extern void +_mesa_meta_CopyTexImage2D(struct gl_context *ctx, GLenum target, GLint level, + GLenum internalFormat, GLint x, GLint y, + GLsizei width, GLsizei height, GLint border); + +extern void +_mesa_meta_CopyTexSubImage1D(struct gl_context *ctx, GLenum target, GLint level, + GLint xoffset, + GLint x, GLint y, GLsizei width); + +extern void +_mesa_meta_CopyTexSubImage2D(struct gl_context *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint x, GLint y, + GLsizei width, GLsizei height); + +extern void +_mesa_meta_CopyTexSubImage3D(struct gl_context *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, + GLint x, GLint y, + GLsizei width, GLsizei height); + +extern void +_mesa_meta_CopyColorTable(struct gl_context *ctx, + GLenum target, GLenum internalformat, + GLint x, GLint y, GLsizei width); + +extern void +_mesa_meta_CopyColorSubTable(struct gl_context *ctx,GLenum target, GLsizei start, + GLint x, GLint y, GLsizei width); + +extern void +_mesa_meta_CopyConvolutionFilter1D(struct gl_context *ctx, GLenum target, + GLenum internalFormat, + GLint x, GLint y, GLsizei width); + +extern void +_mesa_meta_CopyConvolutionFilter2D(struct gl_context *ctx, GLenum target, + GLenum internalFormat, GLint x, GLint y, + GLsizei width, GLsizei height); + + +#endif /* META_H */ diff --git a/src/mesa/drivers/dri/Makefile b/src/mesa/drivers/dri/Makefile new file mode 100644 index 0000000..264648c --- /dev/null +++ b/src/mesa/drivers/dri/Makefile @@ -0,0 +1,55 @@ +# src/mesa/drivers/dri/Makefile + +TOP = ../../../.. + +include $(TOP)/configs/current + + + +default: $(TOP)/$(LIB_DIR) subdirs dri.pc + + +$(TOP)/$(LIB_DIR): + -mkdir $(TOP)/$(LIB_DIR) + + +subdirs: + @for dir in $(DRI_DIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE)) || exit 1 ; \ + fi \ + done + +pcedit = sed \ + -e 's,@INSTALL_DIR@,$(INSTALL_DIR),' \ + -e 's,@INSTALL_LIB_DIR@,$(INSTALL_LIB_DIR),' \ + -e 's,@INSTALL_INC_DIR@,$(INSTALL_INC_DIR),' \ + -e 's,@VERSION@,$(MESA_MAJOR).$(MESA_MINOR).$(MESA_TINY),' \ + -e 's,@DRI_DRIVER_DIR@,$(DRI_DRIVER_INSTALL_DIR),' \ + -e 's,@DRI_PC_REQ_PRIV@,$(DRI_PC_REQ_PRIV),' + +dri.pc: dri.pc.in + $(pcedit) $< > $@ + + +install: dri.pc + @for dir in $(DRI_DIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) install) || exit 1 ; \ + fi \ + done + $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/GL/internal + $(INSTALL) -m 0644 $(TOP)/include/GL/internal/dri_interface.h \ + $(DESTDIR)$(INSTALL_INC_DIR)/GL/internal + $(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig + $(INSTALL) -m 0644 dri.pc $(DESTDIR)$(INSTALL_LIB_DIR)/pkgconfig + + +clean: + -@for dir in $(DRI_DIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) clean) ; \ + fi \ + done + -rm -f common/*.o + -rm -f *.pc diff --git a/src/mesa/drivers/dri/Makefile.template b/src/mesa/drivers/dri/Makefile.template new file mode 100644 index 0000000..4ecddbc --- /dev/null +++ b/src/mesa/drivers/dri/Makefile.template @@ -0,0 +1,114 @@ +# -*-makefile-*- + +MESA_MODULES = $(TOP)/src/mesa/libmesa.a + +COMMON_GALLIUM_SOURCES = \ + ../common/utils.c \ + ../common/vblank.c \ + ../common/dri_util.c \ + ../common/xmlconfig.c + +COMMON_SOURCES = $(COMMON_GALLIUM_SOURCES) \ + ../../common/driverfuncs.c \ + ../common/texmem.c \ + ../common/drirenderbuffer.c \ + ../common/dri_metaops.c + +INCLUDES = $(SHARED_INCLUDES) $(EXPAT_INCLUDES) + +OBJECTS = $(C_SOURCES:.c=.o) \ + $(CXX_SOURCES:.cpp=.o) \ + $(ASM_SOURCES:.S=.o) + + +### Include directories +SHARED_INCLUDES = \ + -I. \ + -I$(TOP)/src/mesa/drivers/dri/common \ + -Iserver \ + -I$(TOP)/include \ + -I$(TOP)/src/mapi \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/egl/main \ + -I$(TOP)/src/egl/drivers/dri \ + $(LIBDRM_CFLAGS) + +CFLAGS += $(API_DEFINES) +CXXFLAGS += $(API_DEFINES) + +##### RULES ##### + +.c.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + +.cpp.o: + $(CC) -c $(INCLUDES) $(CXXFLAGS) $(DRIVER_DEFINES) $< -o $@ + +.S.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + + +##### TARGETS ##### + +default: subdirs lib + + +.PHONY: lib +lib: symlinks subdirs depend + @$(MAKE) $(LIBNAME) $(TOP)/$(LIB_DIR)/$(LIBNAME) + +$(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(EXTRA_MODULES) Makefile \ + $(TOP)/src/mesa/drivers/dri/Makefile.template $(TOP)/src/mesa/drivers/dri/common/dri_test.o + $(MKLIB) -o $@.tmp -noprefix -linker '$(CXX)' -ldflags '$(LDFLAGS)' \ + $(OBJECTS) $(MESA_MODULES) $(EXTRA_MODULES) $(DRI_LIB_DEPS) + $(CXX) $(CFLAGS) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS) + @rm -f $@.test + mv -f $@.tmp $@ + + +$(TOP)/$(LIB_DIR)/$(LIBNAME): $(LIBNAME) + $(INSTALL) $(LIBNAME) $(TOP)/$(LIB_DIR) + + +# If the Makefile defined SUBDIRS, run make in each +.PHONY: subdirs +subdirs: + @if test -n "$(SUBDIRS)" ; then \ + for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE)) || exit 1; \ + fi \ + done \ + fi + + +.PHONY: symlinks +symlinks: + + +depend: $(C_SOURCES) $(CXX_SOURCES) $(ASM_SOURCES) $(SYMLINKS) + @ echo "running $(MKDEP)" + @ rm -f depend + @ touch depend + @ $(MKDEP) $(MKDEP_OPTIONS) $(DRIVER_DEFINES) $(INCLUDES) \ + $(C_SOURCES) $(CXX_SOURCES) \ + $(ASM_SOURCES) > /dev/null 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/mesa/drivers/dri/common/depthtmp.h b/src/mesa/drivers/dri/common/depthtmp.h new file mode 100644 index 0000000..81bec9c --- /dev/null +++ b/src/mesa/drivers/dri/common/depthtmp.h @@ -0,0 +1,270 @@ + +/* + * Notes: + * 1. These functions plug into the gl_renderbuffer structure. + * 2. The 'values' parameter always points to GLuint values, regardless of + * the actual Z buffer depth. + */ + + +#include "spantmp_common.h" + +#ifndef DBG +#define DBG 0 +#endif + +#ifndef HAVE_HW_DEPTH_SPANS +#define HAVE_HW_DEPTH_SPANS 0 +#endif + +#ifndef HAVE_HW_DEPTH_PIXELS +#define HAVE_HW_DEPTH_PIXELS 0 +#endif + +static void TAG(WriteDepthSpan)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, GLint x, GLint y, + const void *values, + const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + const VALUE_TYPE *depth = (const VALUE_TYPE *) values; + GLint x1; + GLint n1; + LOCAL_DEPTH_VARS; + + y = Y_FLIP( y ); + +#if HAVE_HW_DEPTH_SPANS + (void) x1; (void) n1; + + if ( DBG ) fprintf( stderr, "WriteDepthSpan 0..%d (x1 %d)\n", + (int)n, (int)x ); + + WRITE_DEPTH_SPAN(); +#else + HW_CLIPLOOP() + { + GLint i = 0; + CLIPSPAN( x, y, n, x1, n1, i ); + + if ( DBG ) fprintf( stderr, "WriteDepthSpan %d..%d (x1 %d) (mask %p)\n", + (int)i, (int)n1, (int)x1, mask ); + + if ( mask ) { + for ( ; n1>0 ; i++, x1++, n1-- ) { + if ( mask[i] ) WRITE_DEPTH( x1, y, depth[i] ); + } + } else { + for ( ; n1>0 ; i++, x1++, n1-- ) { + WRITE_DEPTH( x1, y, depth[i] ); + } + } + } + HW_ENDCLIPLOOP(); +#endif + } + HW_WRITE_UNLOCK(); +} + + +#if HAVE_HW_DEPTH_SPANS +/* implement MonoWriteDepthSpan() in terms of WriteDepthSpan() */ +static void +TAG(WriteMonoDepthSpan)( struct gl_context *ctx, struct gl_renderbuffer *rb, + GLuint n, GLint x, GLint y, + const void *value, const GLubyte mask[] ) +{ + const GLuint depthVal = *((GLuint *) value); + GLuint depths[MAX_WIDTH]; + GLuint i; + for (i = 0; i < n; i++) + depths[i] = depthVal; + TAG(WriteDepthSpan)(ctx, rb, n, x, y, depths, mask); +} +#else +static void TAG(WriteMonoDepthSpan)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, GLint x, GLint y, + const void *value, + const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + const GLuint depth = *((GLuint *) value); + GLint x1; + GLint n1; + LOCAL_DEPTH_VARS; + + y = Y_FLIP( y ); + + HW_CLIPLOOP() + { + GLint i = 0; + CLIPSPAN( x, y, n, x1, n1, i ); + + if ( DBG ) fprintf( stderr, "%s %d..%d (x1 %d) = %u\n", + __FUNCTION__, (int)i, (int)n1, (int)x1, (GLuint)depth ); + + if ( mask ) { + for ( ; n1>0 ; i++, x1++, n1-- ) { + if ( mask[i] ) WRITE_DEPTH( x1, y, depth ); + } + } else { + for ( ; n1>0 ; x1++, n1-- ) { + WRITE_DEPTH( x1, y, depth ); + } + } + } + HW_ENDCLIPLOOP(); + } + HW_WRITE_UNLOCK(); +} +#endif + + +static void TAG(WriteDepthPixels)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, + const GLint x[], + const GLint y[], + const void *values, + const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + const VALUE_TYPE *depth = (const VALUE_TYPE *) values; + GLuint i; + LOCAL_DEPTH_VARS; + + if ( DBG ) fprintf( stderr, "WriteDepthPixels\n" ); + +#if HAVE_HW_DEPTH_PIXELS + (void) i; + + WRITE_DEPTH_PIXELS(); +#else + HW_CLIPLOOP() + { + if ( mask ) { + for ( i = 0 ; i < n ; i++ ) { + if ( mask[i] ) { + const int fy = Y_FLIP( y[i] ); + if ( CLIPPIXEL( x[i], fy ) ) + WRITE_DEPTH( x[i], fy, depth[i] ); + } + } + } + else { + for ( i = 0 ; i < n ; i++ ) { + const int fy = Y_FLIP( y[i] ); + if ( CLIPPIXEL( x[i], fy ) ) + WRITE_DEPTH( x[i], fy, depth[i] ); + } + } + } + HW_ENDCLIPLOOP(); +#endif + } + HW_WRITE_UNLOCK(); +} + + +/* Read depth spans and pixels + */ +static void TAG(ReadDepthSpan)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, GLint x, GLint y, + void *values ) +{ + HW_READ_LOCK() + { + VALUE_TYPE *depth = (VALUE_TYPE *) values; + GLint x1, n1; + LOCAL_DEPTH_VARS; + + y = Y_FLIP( y ); + + if ( DBG ) fprintf( stderr, "ReadDepthSpan\n" ); + +#if HAVE_HW_DEPTH_SPANS + (void) x1; (void) n1; + + READ_DEPTH_SPAN(); +#else + HW_CLIPLOOP() + { + GLint i = 0; + CLIPSPAN( x, y, n, x1, n1, i ); + for ( ; n1>0 ; i++, n1-- ) { + READ_DEPTH( depth[i], x+i, y ); + } + } + HW_ENDCLIPLOOP(); +#endif + } + HW_READ_UNLOCK(); +} + +static void TAG(ReadDepthPixels)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, + const GLint x[], const GLint y[], + void *values ) +{ + HW_READ_LOCK() + { + VALUE_TYPE *depth = (VALUE_TYPE *) values; + GLuint i; + LOCAL_DEPTH_VARS; + + if ( DBG ) fprintf( stderr, "ReadDepthPixels\n" ); + +#if HAVE_HW_DEPTH_PIXELS + (void) i; + + READ_DEPTH_PIXELS(); +#else + HW_CLIPLOOP() + { + for ( i = 0 ; i < n ;i++ ) { + int fy = Y_FLIP( y[i] ); + if ( CLIPPIXEL( x[i], fy ) ) + READ_DEPTH( depth[i], x[i], fy ); + } + } + HW_ENDCLIPLOOP(); +#endif + } + HW_READ_UNLOCK(); +} + + +/** + * Initialize the given renderbuffer's span routines to point to + * the depth/z functions we generated above. + */ +static void TAG(InitDepthPointers)(struct gl_renderbuffer *rb) +{ + rb->GetRow = TAG(ReadDepthSpan); + rb->GetValues = TAG(ReadDepthPixels); + rb->PutRow = TAG(WriteDepthSpan); + rb->PutRowRGB = NULL; + rb->PutMonoRow = TAG(WriteMonoDepthSpan); + rb->PutValues = TAG(WriteDepthPixels); + rb->PutMonoValues = NULL; +} + + +#if HAVE_HW_DEPTH_SPANS +#undef WRITE_DEPTH_SPAN +#undef WRITE_DEPTH_PIXELS +#undef READ_DEPTH_SPAN +#undef READ_DEPTH_PIXELS +#else +#undef WRITE_DEPTH +#undef READ_DEPTH +#endif +#undef TAG +#undef VALUE_TYPE diff --git a/src/mesa/drivers/dri/common/dri_metaops.c b/src/mesa/drivers/dri/common/dri_metaops.c new file mode 100644 index 0000000..e0bc3b8 --- /dev/null +++ b/src/mesa/drivers/dri/common/dri_metaops.c @@ -0,0 +1,291 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2009 Intel Corporation. + * 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. + * + **************************************************************************/ + +#include "main/arbprogram.h" +#include "main/arrayobj.h" +#include "main/bufferobj.h" +#include "main/context.h" +#include "main/enable.h" +#include "main/matrix.h" +#include "main/texstate.h" +#include "main/varray.h" +#include "main/viewport.h" +#include "program/program.h" +#include "dri_metaops.h" + +void +meta_set_passthrough_transform(struct dri_metaops *meta) +{ + struct gl_context *ctx = meta->ctx; + + meta->saved_vp_x = ctx->Viewport.X; + meta->saved_vp_y = ctx->Viewport.Y; + meta->saved_vp_width = ctx->Viewport.Width; + meta->saved_vp_height = ctx->Viewport.Height; + meta->saved_matrix_mode = ctx->Transform.MatrixMode; + + meta->internal_viewport_call = GL_TRUE; + _mesa_Viewport(0, 0, ctx->DrawBuffer->Width, ctx->DrawBuffer->Height); + meta->internal_viewport_call = GL_FALSE; + + _mesa_MatrixMode(GL_PROJECTION); + _mesa_PushMatrix(); + _mesa_LoadIdentity(); + _mesa_Ortho(0, ctx->DrawBuffer->Width, 0, ctx->DrawBuffer->Height, 1, -1); + + _mesa_MatrixMode(GL_MODELVIEW); + _mesa_PushMatrix(); + _mesa_LoadIdentity(); +} + +void +meta_restore_transform(struct dri_metaops *meta) +{ + _mesa_MatrixMode(GL_PROJECTION); + _mesa_PopMatrix(); + _mesa_MatrixMode(GL_MODELVIEW); + _mesa_PopMatrix(); + + _mesa_MatrixMode(meta->saved_matrix_mode); + + meta->internal_viewport_call = GL_TRUE; + _mesa_Viewport(meta->saved_vp_x, meta->saved_vp_y, + meta->saved_vp_width, meta->saved_vp_height); + meta->internal_viewport_call = GL_FALSE; +} + + +/** + * Set up a vertex program to pass through the position and first texcoord + * for pixel path. + */ +void +meta_set_passthrough_vertex_program(struct dri_metaops *meta) +{ + struct gl_context *ctx = meta->ctx; + static const char *vp = + "!!ARBvp1.0\n" + "TEMP vertexClip;\n" + "DP4 vertexClip.x, state.matrix.mvp.row[0], vertex.position;\n" + "DP4 vertexClip.y, state.matrix.mvp.row[1], vertex.position;\n" + "DP4 vertexClip.z, state.matrix.mvp.row[2], vertex.position;\n" + "DP4 vertexClip.w, state.matrix.mvp.row[3], vertex.position;\n" + "MOV result.position, vertexClip;\n" + "MOV result.texcoord[0], vertex.texcoord[0];\n" + "MOV result.color, vertex.color;\n" + "END\n"; + + assert(meta->saved_vp == NULL); + + _mesa_reference_vertprog(ctx, &meta->saved_vp, + ctx->VertexProgram.Current); + if (meta->passthrough_vp == NULL) { + GLuint prog_name; + _mesa_GenPrograms(1, &prog_name); + _mesa_BindProgram(GL_VERTEX_PROGRAM_ARB, prog_name); + _mesa_ProgramStringARB(GL_VERTEX_PROGRAM_ARB, + GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(vp), (const GLubyte *)vp); + _mesa_reference_vertprog(ctx, &meta->passthrough_vp, + ctx->VertexProgram.Current); + _mesa_DeletePrograms(1, &prog_name); + } + + FLUSH_VERTICES(ctx, _NEW_PROGRAM); + _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, + meta->passthrough_vp); + ctx->Driver.BindProgram(ctx, GL_VERTEX_PROGRAM_ARB, + &meta->passthrough_vp->Base); + + meta->saved_vp_enable = ctx->VertexProgram.Enabled; + _mesa_Enable(GL_VERTEX_PROGRAM_ARB); +} + +/** + * Restores the previous vertex program after + * meta_set_passthrough_vertex_program() + */ +void +meta_restore_vertex_program(struct dri_metaops *meta) +{ + struct gl_context *ctx = meta->ctx; + + FLUSH_VERTICES(ctx, _NEW_PROGRAM); + _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, + meta->saved_vp); + _mesa_reference_vertprog(ctx, &meta->saved_vp, NULL); + ctx->Driver.BindProgram(ctx, GL_VERTEX_PROGRAM_ARB, + &ctx->VertexProgram.Current->Base); + + if (!meta->saved_vp_enable) + _mesa_Disable(GL_VERTEX_PROGRAM_ARB); +} + +/** + * Binds the given program string to GL_FRAGMENT_PROGRAM_ARB, caching the + * program object. + */ +void +meta_set_fragment_program(struct dri_metaops *meta, + struct gl_fragment_program **prog, + const char *prog_string) +{ + struct gl_context *ctx = meta->ctx; + assert(meta->saved_fp == NULL); + + _mesa_reference_fragprog(ctx, &meta->saved_fp, + ctx->FragmentProgram.Current); + if (*prog == NULL) { + GLuint prog_name; + _mesa_GenPrograms(1, &prog_name); + _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, prog_name); + _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, + GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(prog_string), (const GLubyte *)prog_string); + _mesa_reference_fragprog(ctx, prog, ctx->FragmentProgram.Current); + /* Note that DeletePrograms unbinds the program on us */ + _mesa_DeletePrograms(1, &prog_name); + } + + FLUSH_VERTICES(ctx, _NEW_PROGRAM); + _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, *prog); + ctx->Driver.BindProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, &((*prog)->Base)); + + meta->saved_fp_enable = ctx->FragmentProgram.Enabled; + _mesa_Enable(GL_FRAGMENT_PROGRAM_ARB); +} + +/** + * Restores the previous fragment program after + * meta_set_fragment_program() + */ +void +meta_restore_fragment_program(struct dri_metaops *meta) +{ + struct gl_context *ctx = meta->ctx; + + FLUSH_VERTICES(ctx, _NEW_PROGRAM); + _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, + meta->saved_fp); + _mesa_reference_fragprog(ctx, &meta->saved_fp, NULL); + ctx->Driver.BindProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, + &ctx->FragmentProgram.Current->Base); + + if (!meta->saved_fp_enable) + _mesa_Disable(GL_FRAGMENT_PROGRAM_ARB); +} + +static const float default_texcoords[4][2] = { { 0.0, 0.0 }, + { 1.0, 0.0 }, + { 1.0, 1.0 }, + { 0.0, 1.0 } }; + +void +meta_set_default_texrect(struct dri_metaops *meta) +{ + struct gl_context *ctx = meta->ctx; + struct gl_client_array *old_texcoord_array; + + meta->saved_active_texture = ctx->Texture.CurrentUnit; + if (meta->saved_array_vbo == NULL) { + _mesa_reference_buffer_object(ctx, &meta->saved_array_vbo, + ctx->Array.ArrayBufferObj); + } + + old_texcoord_array = &ctx->Array.ArrayObj->TexCoord[0]; + meta->saved_texcoord_type = old_texcoord_array->Type; + meta->saved_texcoord_size = old_texcoord_array->Size; + meta->saved_texcoord_stride = old_texcoord_array->Stride; + meta->saved_texcoord_enable = old_texcoord_array->Enabled; + meta->saved_texcoord_ptr = old_texcoord_array->Ptr; + _mesa_reference_buffer_object(ctx, &meta->saved_texcoord_vbo, + old_texcoord_array->BufferObj); + + _mesa_ClientActiveTextureARB(GL_TEXTURE0); + + if (meta->texcoord_vbo == NULL) { + GLuint vbo_name; + + _mesa_GenBuffersARB(1, &vbo_name); + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, vbo_name); + _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(default_texcoords), + default_texcoords, GL_STATIC_DRAW_ARB); + _mesa_reference_buffer_object(ctx, &meta->texcoord_vbo, + ctx->Array.ArrayBufferObj); + } else { + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, + meta->texcoord_vbo->Name); + } + _mesa_TexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), NULL); + + _mesa_Enable(GL_TEXTURE_COORD_ARRAY); +} + +void +meta_restore_texcoords(struct dri_metaops *meta) +{ + struct gl_context *ctx = meta->ctx; + + /* Restore the old TexCoordPointer */ + if (meta->saved_texcoord_vbo) { + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, + meta->saved_texcoord_vbo->Name); + _mesa_reference_buffer_object(ctx, &meta->saved_texcoord_vbo, NULL); + } else { + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + } + + _mesa_TexCoordPointer(meta->saved_texcoord_size, + meta->saved_texcoord_type, + meta->saved_texcoord_stride, + meta->saved_texcoord_ptr); + if (!meta->saved_texcoord_enable) + _mesa_Disable(GL_TEXTURE_COORD_ARRAY); + + _mesa_ClientActiveTextureARB(GL_TEXTURE0 + + meta->saved_active_texture); + + if (meta->saved_array_vbo) { + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, + meta->saved_array_vbo->Name); + _mesa_reference_buffer_object(ctx, &meta->saved_array_vbo, NULL); + } else { + _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + } +} + + +void meta_init_metaops(struct gl_context *ctx, struct dri_metaops *meta) +{ + meta->ctx = ctx; +} + +void meta_destroy_metaops(struct dri_metaops *meta) +{ + +} diff --git a/src/mesa/drivers/dri/common/dri_metaops.h b/src/mesa/drivers/dri/common/dri_metaops.h new file mode 100644 index 0000000..aa7d4ba --- /dev/null +++ b/src/mesa/drivers/dri/common/dri_metaops.h @@ -0,0 +1,81 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2009 Intel Corporation. + * 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. + * + **************************************************************************/ + +#ifndef DRI_METAOPS_H +#define DRI_METAOPS_H + + +struct dri_metaops { + struct gl_context *ctx; + GLboolean internal_viewport_call; + struct gl_fragment_program *bitmap_fp; + struct gl_vertex_program *passthrough_vp; + struct gl_buffer_object *texcoord_vbo; + + struct gl_fragment_program *saved_fp; + GLboolean saved_fp_enable; + struct gl_vertex_program *saved_vp; + GLboolean saved_vp_enable; + + struct gl_fragment_program *tex2d_fp; + + GLboolean saved_texcoord_enable; + struct gl_buffer_object *saved_array_vbo, *saved_texcoord_vbo; + GLenum saved_texcoord_type; + GLsizei saved_texcoord_size, saved_texcoord_stride; + const void *saved_texcoord_ptr; + int saved_active_texture; + + GLint saved_vp_x, saved_vp_y; + GLsizei saved_vp_width, saved_vp_height; + GLenum saved_matrix_mode; +}; + + +void meta_set_passthrough_transform(struct dri_metaops *meta); + +void meta_restore_transform(struct dri_metaops *meta); + +void meta_set_passthrough_vertex_program(struct dri_metaops *meta); + +void meta_restore_vertex_program(struct dri_metaops *meta); + +void meta_set_fragment_program(struct dri_metaops *meta, + struct gl_fragment_program **prog, + const char *prog_string); + +void meta_restore_fragment_program(struct dri_metaops *meta); + +void meta_set_default_texrect(struct dri_metaops *meta); + +void meta_restore_texcoords(struct dri_metaops *meta); + +void meta_init_metaops(struct gl_context *ctx, struct dri_metaops *meta); +void meta_destroy_metaops(struct dri_metaops *meta); + +#endif diff --git a/src/mesa/drivers/dri/common/dri_test.c b/src/mesa/drivers/dri/common/dri_test.c new file mode 100644 index 0000000..793f0c3 --- /dev/null +++ b/src/mesa/drivers/dri/common/dri_test.c @@ -0,0 +1,89 @@ +#include "main/glheader.h" +#include "main/compiler.h" +#include "glapi/glapi.h" + +/* This is just supposed to make sure we get a reference to + the driver entry symbol that the compiler doesn't optimize away */ + +extern char __driDriverExtensions[]; + +/* provide glapi symbols */ + +#if defined(GLX_USE_TLS) + +PUBLIC __thread struct _glapi_table * _glapi_tls_Dispatch + __attribute__((tls_model("initial-exec"))); + +PUBLIC __thread void * _glapi_tls_Context + __attribute__((tls_model("initial-exec"))); + +PUBLIC const struct _glapi_table *_glapi_Dispatch; +PUBLIC const void *_glapi_Context; + +#else + +PUBLIC struct _glapi_table *_glapi_Dispatch; +PUBLIC void *_glapi_Context; + +#endif + +PUBLIC void +_glapi_check_multithread(void) +{} + +PUBLIC void +_glapi_set_context(void *context) +{} + +PUBLIC void * +_glapi_get_context(void) +{ + return 0; +} + +PUBLIC void +_glapi_set_dispatch(struct _glapi_table *dispatch) +{} + +PUBLIC struct _glapi_table * +_glapi_get_dispatch(void) +{ + return 0; +} + +PUBLIC int +_glapi_add_dispatch( const char * const * function_names, + const char * parameter_signature ) +{ + return 0; +} + +PUBLIC GLint +_glapi_get_proc_offset(const char *funcName) +{ + return 0; +} + +PUBLIC _glapi_proc +_glapi_get_proc_address(const char *funcName) +{ + return 0; +} + +PUBLIC GLuint +_glapi_get_dispatch_table_size(void) +{ + return 0; +} + +PUBLIC unsigned long +_glthread_GetID(void) +{ + return 0; +} + +int main(int argc, char** argv) +{ + void* p = __driDriverExtensions; + return (int)(unsigned long)p; +} diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c new file mode 100644 index 0000000..bf8cf6e --- /dev/null +++ b/src/mesa/drivers/dri/common/dri_util.c @@ -0,0 +1,1012 @@ +/** + * \file dri_util.c + * DRI utility functions. + * + * This module acts as glue between GLX and the actual hardware driver. A DRI + * driver doesn't really \e have to use any of this - it's optional. But, some + * useful stuff is done here that otherwise would have to be duplicated in most + * drivers. + * + * Basically, these utility functions take care of some of the dirty details of + * screen initialization, context creation, context binding, DRM setup, etc. + * + * These functions are compiled into each DRI driver so libGL.so knows nothing + * about them. + */ + + +#include +#include +#include +#include +#include + +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif + +#include "main/imports.h" +#define None 0 + +#include "dri_util.h" +#include "drm_sarea.h" +#include "utils.h" +#include "xmlpool.h" +#include "../glsl/glsl_parser_extras.h" + +PUBLIC const char __dri2ConfigOptions[] = + DRI_CONF_BEGIN + DRI_CONF_SECTION_PERFORMANCE + DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_1) + DRI_CONF_SECTION_END + DRI_CONF_END; + +static const uint __dri2NConfigOptions = 1; + +#ifndef GLX_OML_sync_control +typedef GLboolean ( * PFNGLXGETMSCRATEOMLPROC) (__DRIdrawable *drawable, int32_t *numerator, int32_t *denominator); +#endif + +static void dri_get_drawable(__DRIdrawable *pdp); +static void dri_put_drawable(__DRIdrawable *pdp); + +/** + * This is just a token extension used to signal that the driver + * supports setting a read drawable. + */ +const __DRIextension driReadDrawableExtension = { + __DRI_READ_DRAWABLE, __DRI_READ_DRAWABLE_VERSION +}; + +GLint +driIntersectArea( drm_clip_rect_t rect1, drm_clip_rect_t rect2 ) +{ + if (rect2.x1 > rect1.x1) rect1.x1 = rect2.x1; + if (rect2.x2 < rect1.x2) rect1.x2 = rect2.x2; + if (rect2.y1 > rect1.y1) rect1.y1 = rect2.y1; + if (rect2.y2 < rect1.y2) rect1.y2 = rect2.y2; + + if (rect1.x1 > rect1.x2 || rect1.y1 > rect1.y2) return 0; + + return (rect1.x2 - rect1.x1) * (rect1.y2 - rect1.y1); +} + +/*****************************************************************/ +/** \name Context (un)binding functions */ +/*****************************************************************/ +/*@{*/ + +/** + * Unbind context. + * + * \param scrn the screen. + * \param gc context. + * + * \return \c GL_TRUE on success, or \c GL_FALSE on failure. + * + * \internal + * This function calls __DriverAPIRec::UnbindContext, and then decrements + * __DRIdrawableRec::refcount which must be non-zero for a successful + * return. + * + * While casting the opaque private pointers associated with the parameters + * into their respective real types it also assures they are not \c NULL. + */ +static int driUnbindContext(__DRIcontext *pcp) +{ + __DRIscreen *psp; + __DRIdrawable *pdp; + __DRIdrawable *prp; + + /* + ** Assume error checking is done properly in glXMakeCurrent before + ** calling driUnbindContext. + */ + + if (pcp == NULL) + return GL_FALSE; + + psp = pcp->driScreenPriv; + pdp = pcp->driDrawablePriv; + prp = pcp->driReadablePriv; + + /* already unbound */ + if (!pdp && !prp) + return GL_TRUE; + /* Let driver unbind drawable from context */ + (*psp->DriverAPI.UnbindContext)(pcp); + + assert(pdp); + if (pdp->refcount == 0) { + /* ERROR!!! */ + return GL_FALSE; + } + + dri_put_drawable(pdp); + + if (prp != pdp) { + if (prp->refcount == 0) { + /* ERROR!!! */ + return GL_FALSE; + } + + dri_put_drawable(prp); + } + + + /* XXX this is disabled so that if we call SwapBuffers on an unbound + * window we can determine the last context bound to the window and + * use that context's lock. (BrianP, 2-Dec-2000) + */ + pcp->driDrawablePriv = pcp->driReadablePriv = NULL; + + return GL_TRUE; +} + +/** + * This function takes both a read buffer and a draw buffer. This is needed + * for \c glXMakeCurrentReadSGI or GLX 1.3's \c glXMakeContextCurrent + * function. + */ +static int driBindContext(__DRIcontext *pcp, + __DRIdrawable *pdp, + __DRIdrawable *prp) +{ + __DRIscreen *psp = NULL; + + /* + ** Assume error checking is done properly in glXMakeCurrent before + ** calling driUnbindContext. + */ + + if (!pcp) + return GL_FALSE; + + /* Bind the drawable to the context */ + psp = pcp->driScreenPriv; + pcp->driDrawablePriv = pdp; + pcp->driReadablePriv = prp; + if (pdp) { + pdp->driContextPriv = pcp; + dri_get_drawable(pdp); + } + if (prp && pdp != prp) { + dri_get_drawable(prp); + } + + /* + ** Now that we have a context associated with this drawable, we can + ** initialize the drawable information if has not been done before. + */ + + if (!psp->dri2.enabled) { + if (pdp && !pdp->pStamp) { + DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); + __driUtilUpdateDrawableInfo(pdp); + DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); + } + if (prp && pdp != prp && !prp->pStamp) { + DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); + __driUtilUpdateDrawableInfo(prp); + DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); + } + } + + /* Call device-specific MakeCurrent */ + return (*psp->DriverAPI.MakeCurrent)(pcp, pdp, prp); +} + +/*@}*/ + + +/*****************************************************************/ +/** \name Drawable handling functions */ +/*****************************************************************/ +/*@{*/ + +/** + * Update private drawable information. + * + * \param pdp pointer to the private drawable information to update. + * + * This function basically updates the __DRIdrawable struct's + * cliprect information by calling \c __DRIinterfaceMethods::getDrawableInfo. + * This is usually called by the DRI_VALIDATE_DRAWABLE_INFO macro which + * compares the __DRIdrwablePrivate pStamp and lastStamp values. If + * the values are different that means we have to update the clipping + * info. + */ +void +__driUtilUpdateDrawableInfo(__DRIdrawable *pdp) +{ + __DRIscreen *psp = pdp->driScreenPriv; + __DRIcontext *pcp = pdp->driContextPriv; + + if (!pcp + || ((pdp != pcp->driDrawablePriv) && (pdp != pcp->driReadablePriv))) { + /* ERROR!!! + * ...but we must ignore it. There can be many contexts bound to a + * drawable. + */ + } + + if (pdp->pClipRects) { + free(pdp->pClipRects); + pdp->pClipRects = NULL; + } + + if (pdp->pBackClipRects) { + free(pdp->pBackClipRects); + pdp->pBackClipRects = NULL; + } + + DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); + + if (! (*psp->getDrawableInfo->getDrawableInfo)(pdp, + &pdp->index, &pdp->lastStamp, + &pdp->x, &pdp->y, &pdp->w, &pdp->h, + &pdp->numClipRects, &pdp->pClipRects, + &pdp->backX, + &pdp->backY, + &pdp->numBackClipRects, + &pdp->pBackClipRects, + pdp->loaderPrivate)) { + /* Error -- eg the window may have been destroyed. Keep going + * with no cliprects. + */ + pdp->pStamp = &pdp->lastStamp; /* prevent endless loop */ + pdp->numClipRects = 0; + pdp->pClipRects = NULL; + pdp->numBackClipRects = 0; + pdp->pBackClipRects = NULL; + } + else + pdp->pStamp = &(psp->pSAREA->drawableTable[pdp->index].stamp); + + DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); +} + +/*@}*/ + +/*****************************************************************/ +/** \name GLX callbacks */ +/*****************************************************************/ +/*@{*/ + +static void driReportDamage(__DRIdrawable *pdp, + struct drm_clip_rect *pClipRects, int numClipRects) +{ + __DRIscreen *psp = pdp->driScreenPriv; + + /* Check that we actually have the new damage report method */ + if (psp->damage) { + /* Report the damage. Currently, all our drivers draw + * directly to the front buffer, so we report the damage there + * rather than to the backing storein (if any). + */ + (*psp->damage->reportDamage)(pdp, + pdp->x, pdp->y, + pClipRects, numClipRects, + GL_TRUE, pdp->loaderPrivate); + } +} + + +/** + * Swap buffers. + * + * \param drawablePrivate opaque pointer to the per-drawable private info. + * + * \internal + * This function calls __DRIdrawable::swapBuffers. + * + * Is called directly from glXSwapBuffers(). + */ +static void driSwapBuffers(__DRIdrawable *dPriv) +{ + __DRIscreen *psp = dPriv->driScreenPriv; + drm_clip_rect_t *rects; + int i; + + psp->DriverAPI.SwapBuffers(dPriv); + + if (!dPriv->numClipRects) + return; + + rects = malloc(sizeof(*rects) * dPriv->numClipRects); + + if (!rects) + return; + + for (i = 0; i < dPriv->numClipRects; i++) { + rects[i].x1 = dPriv->pClipRects[i].x1 - dPriv->x; + rects[i].y1 = dPriv->pClipRects[i].y1 - dPriv->y; + rects[i].x2 = dPriv->pClipRects[i].x2 - dPriv->x; + rects[i].y2 = dPriv->pClipRects[i].y2 - dPriv->y; + } + + driReportDamage(dPriv, rects, dPriv->numClipRects); + free(rects); +} + +static int driDrawableGetMSC( __DRIscreen *sPriv, __DRIdrawable *dPriv, + int64_t *msc ) +{ + return sPriv->DriverAPI.GetDrawableMSC(sPriv, dPriv, msc); +} + + +static int driWaitForMSC(__DRIdrawable *dPriv, int64_t target_msc, + int64_t divisor, int64_t remainder, + int64_t * msc, int64_t * sbc) +{ + __DRIswapInfo sInfo; + int status; + + status = dPriv->driScreenPriv->DriverAPI.WaitForMSC( dPriv, target_msc, + divisor, remainder, + msc ); + + /* GetSwapInfo() may not be provided by the driver if GLX_SGI_video_sync + * is supported but GLX_OML_sync_control is not. Therefore, don't return + * an error value if GetSwapInfo() is not implemented. + */ + if ( status == 0 + && dPriv->driScreenPriv->DriverAPI.GetSwapInfo ) { + status = dPriv->driScreenPriv->DriverAPI.GetSwapInfo( dPriv, & sInfo ); + *sbc = sInfo.swap_count; + } + + return status; +} + + +const __DRImediaStreamCounterExtension driMediaStreamCounterExtension = { + { __DRI_MEDIA_STREAM_COUNTER, __DRI_MEDIA_STREAM_COUNTER_VERSION }, + driWaitForMSC, + driDrawableGetMSC, +}; + + +static void driCopySubBuffer(__DRIdrawable *dPriv, + int x, int y, int w, int h) +{ + drm_clip_rect_t rect; + + rect.x1 = x; + rect.y1 = dPriv->h - y - h; + rect.x2 = x + w; + rect.y2 = rect.y1 + h; + driReportDamage(dPriv, &rect, 1); + + dPriv->driScreenPriv->DriverAPI.CopySubBuffer(dPriv, x, y, w, h); +} + +const __DRIcopySubBufferExtension driCopySubBufferExtension = { + { __DRI_COPY_SUB_BUFFER, __DRI_COPY_SUB_BUFFER_VERSION }, + driCopySubBuffer +}; + +static void driSetSwapInterval(__DRIdrawable *dPriv, unsigned int interval) +{ + dPriv->swap_interval = interval; +} + +static unsigned int driGetSwapInterval(__DRIdrawable *dPriv) +{ + return dPriv->swap_interval; +} + +const __DRIswapControlExtension driSwapControlExtension = { + { __DRI_SWAP_CONTROL, __DRI_SWAP_CONTROL_VERSION }, + driSetSwapInterval, + driGetSwapInterval +}; + + +/** + * This is called via __DRIscreenRec's createNewDrawable pointer. + */ +static __DRIdrawable * +driCreateNewDrawable(__DRIscreen *psp, const __DRIconfig *config, + drm_drawable_t hwDrawable, int renderType, + const int *attrs, void *data) +{ + __DRIdrawable *pdp; + + /* Since pbuffers are not yet supported, no drawable attributes are + * supported either. + */ + (void) attrs; + + pdp = malloc(sizeof *pdp); + if (!pdp) { + return NULL; + } + + pdp->driContextPriv = NULL; + pdp->loaderPrivate = data; + pdp->hHWDrawable = hwDrawable; + pdp->refcount = 1; + pdp->pStamp = NULL; + pdp->lastStamp = 0; + pdp->index = 0; + pdp->x = 0; + pdp->y = 0; + pdp->w = 0; + pdp->h = 0; + pdp->numClipRects = 0; + pdp->numBackClipRects = 0; + pdp->pClipRects = NULL; + pdp->pBackClipRects = NULL; + pdp->vblSeq = 0; + pdp->vblFlags = 0; + + pdp->driScreenPriv = psp; + + if (!(*psp->DriverAPI.CreateBuffer)(psp, pdp, &config->modes, 0)) { + free(pdp); + return NULL; + } + + pdp->msc_base = 0; + + /* This special default value is replaced with the configured + * default value when the drawable is first bound to a direct + * rendering context. + */ + pdp->swap_interval = (unsigned)-1; + + return pdp; +} + + +static __DRIdrawable * +dri2CreateNewDrawable(__DRIscreen *screen, + const __DRIconfig *config, + void *loaderPrivate) +{ + __DRIdrawable *pdraw; + + pdraw = driCreateNewDrawable(screen, config, 0, 0, NULL, loaderPrivate); + if (!pdraw) + return NULL; + + pdraw->pClipRects = &pdraw->dri2.clipRect; + pdraw->pBackClipRects = &pdraw->dri2.clipRect; + + pdraw->pStamp = &pdraw->dri2.stamp; + *pdraw->pStamp = pdraw->lastStamp + 1; + + return pdraw; +} + +static int +dri2ConfigQueryb(__DRIscreen *screen, const char *var, GLboolean *val) +{ + if (!driCheckOption(&screen->optionCache, var, DRI_BOOL)) + return -1; + + *val = driQueryOptionb(&screen->optionCache, var); + + return 0; +} + +static int +dri2ConfigQueryi(__DRIscreen *screen, const char *var, GLint *val) +{ + if (!driCheckOption(&screen->optionCache, var, DRI_INT) && + !driCheckOption(&screen->optionCache, var, DRI_ENUM)) + return -1; + + *val = driQueryOptioni(&screen->optionCache, var); + + return 0; +} + +static int +dri2ConfigQueryf(__DRIscreen *screen, const char *var, GLfloat *val) +{ + if (!driCheckOption(&screen->optionCache, var, DRI_FLOAT)) + return -1; + + *val = driQueryOptionf(&screen->optionCache, var); + + return 0; +} + + +static void dri_get_drawable(__DRIdrawable *pdp) +{ + pdp->refcount++; +} + +static void dri_put_drawable(__DRIdrawable *pdp) +{ + __DRIscreen *psp; + + if (pdp) { + pdp->refcount--; + if (pdp->refcount) + return; + + psp = pdp->driScreenPriv; + (*psp->DriverAPI.DestroyBuffer)(pdp); + if (pdp->pClipRects && pdp->pClipRects != &pdp->dri2.clipRect) { + free(pdp->pClipRects); + pdp->pClipRects = NULL; + } + if (pdp->pBackClipRects && pdp->pClipRects != &pdp->dri2.clipRect) { + free(pdp->pBackClipRects); + pdp->pBackClipRects = NULL; + } + free(pdp); + } +} + +static void +driDestroyDrawable(__DRIdrawable *pdp) +{ + dri_put_drawable(pdp); +} + +/*@}*/ + + +/*****************************************************************/ +/** \name Context handling functions */ +/*****************************************************************/ +/*@{*/ + +/** + * Destroy the per-context private information. + * + * \internal + * This function calls __DriverAPIRec::DestroyContext on \p contextPrivate, calls + * drmDestroyContext(), and finally frees \p contextPrivate. + */ +static void +driDestroyContext(__DRIcontext *pcp) +{ + if (pcp) { + (*pcp->driScreenPriv->DriverAPI.DestroyContext)(pcp); + free(pcp); + } +} + + +/** + * Create the per-drawable private driver information. + * + * \param render_type Type of rendering target. \c GLX_RGBA is the only + * type likely to ever be supported for direct-rendering. + * \param shared Context with which to share textures, etc. or NULL + * + * \returns An opaque pointer to the per-context private information on + * success, or \c NULL on failure. + * + * \internal + * This function allocates and fills a __DRIcontextRec structure. It + * performs some device independent initialization and passes all the + * relevent information to __DriverAPIRec::CreateContext to create the + * context. + * + */ +static __DRIcontext * +driCreateNewContext(__DRIscreen *psp, const __DRIconfig *config, + int render_type, __DRIcontext *shared, + drm_context_t hwContext, void *data) +{ + __DRIcontext *pcp; + void * const shareCtx = (shared != NULL) ? shared->driverPrivate : NULL; + + pcp = malloc(sizeof *pcp); + if (!pcp) + return NULL; + + pcp->driScreenPriv = psp; + pcp->driDrawablePriv = NULL; + pcp->loaderPrivate = data; + + pcp->dri2.draw_stamp = 0; + pcp->dri2.read_stamp = 0; + + pcp->hHWContext = hwContext; + + if ( !(*psp->DriverAPI.CreateContext)(API_OPENGL, + &config->modes, pcp, shareCtx) ) { + free(pcp); + return NULL; + } + + return pcp; +} + +static unsigned int +dri2GetAPIMask(__DRIscreen *screen) +{ + return screen->api_mask; +} + +static __DRIcontext * +dri2CreateNewContextForAPI(__DRIscreen *screen, int api, + const __DRIconfig *config, + __DRIcontext *shared, void *data) +{ + __DRIcontext *context; + const struct gl_config *modes = (config != NULL) ? &config->modes : NULL; + void *shareCtx = (shared != NULL) ? shared->driverPrivate : NULL; + gl_api mesa_api; + + if (!(screen->api_mask & (1 << api))) + return NULL; + + switch (api) { + case __DRI_API_OPENGL: + mesa_api = API_OPENGL; + break; + case __DRI_API_GLES: + mesa_api = API_OPENGLES; + break; + case __DRI_API_GLES2: + mesa_api = API_OPENGLES2; + break; + default: + return NULL; + } + + context = malloc(sizeof *context); + if (!context) + return NULL; + + context->driScreenPriv = screen; + context->driDrawablePriv = NULL; + context->loaderPrivate = data; + + if (!(*screen->DriverAPI.CreateContext)(mesa_api, modes, + context, shareCtx) ) { + free(context); + return NULL; + } + + return context; +} + + +static __DRIcontext * +dri2CreateNewContext(__DRIscreen *screen, const __DRIconfig *config, + __DRIcontext *shared, void *data) +{ + return dri2CreateNewContextForAPI(screen, __DRI_API_OPENGL, + config, shared, data); +} + +static int +driCopyContext(__DRIcontext *dest, __DRIcontext *src, unsigned long mask) +{ + return GL_FALSE; +} + +/*@}*/ + + +/*****************************************************************/ +/** \name Screen handling functions */ +/*****************************************************************/ +/*@{*/ + +/** + * Destroy the per-screen private information. + * + * \internal + * This function calls __DriverAPIRec::DestroyScreen on \p screenPrivate, calls + * drmClose(), and finally frees \p screenPrivate. + */ +static void driDestroyScreen(__DRIscreen *psp) +{ + if (psp) { + /* No interaction with the X-server is possible at this point. This + * routine is called after XCloseDisplay, so there is no protocol + * stream open to the X-server anymore. + */ + + _mesa_destroy_shader_compiler(); + + if (psp->DriverAPI.DestroyScreen) + (*psp->DriverAPI.DestroyScreen)(psp); + + if (!psp->dri2.enabled) { + (void)drmUnmap((drmAddress)psp->pSAREA, SAREA_MAX); + (void)drmUnmap((drmAddress)psp->pFB, psp->fbSize); + (void)drmCloseOnce(psp->fd); + } else { + driDestroyOptionCache(&psp->optionCache); + driDestroyOptionInfo(&psp->optionInfo); + } + + free(psp); + } +} + +static void +setupLoaderExtensions(__DRIscreen *psp, + const __DRIextension **extensions) +{ + int i; + + for (i = 0; extensions[i]; i++) { + if (strcmp(extensions[i]->name, __DRI_GET_DRAWABLE_INFO) == 0) + psp->getDrawableInfo = (__DRIgetDrawableInfoExtension *) extensions[i]; + if (strcmp(extensions[i]->name, __DRI_DAMAGE) == 0) + psp->damage = (__DRIdamageExtension *) extensions[i]; + if (strcmp(extensions[i]->name, __DRI_SYSTEM_TIME) == 0) + psp->systemTime = (__DRIsystemTimeExtension *) extensions[i]; + if (strcmp(extensions[i]->name, __DRI_DRI2_LOADER) == 0) + psp->dri2.loader = (__DRIdri2LoaderExtension *) extensions[i]; + if (strcmp(extensions[i]->name, __DRI_IMAGE_LOOKUP) == 0) + psp->dri2.image = (__DRIimageLookupExtension *) extensions[i]; + if (strcmp(extensions[i]->name, __DRI_USE_INVALIDATE) == 0) + psp->dri2.useInvalidate = (__DRIuseInvalidateExtension *) extensions[i]; + } +} + +/** + * This is the bootstrap function for the driver. libGL supplies all of the + * requisite information about the system, and the driver initializes itself. + * This routine also fills in the linked list pointed to by \c driver_modes + * with the \c struct gl_config that the driver can support for windows or + * pbuffers. + * + * For legacy DRI. + * + * \param scrn Index of the screen + * \param ddx_version Version of the 2D DDX. This may not be meaningful for + * all drivers. + * \param dri_version Version of the "server-side" DRI. + * \param drm_version Version of the kernel DRM. + * \param frame_buffer Data describing the location and layout of the + * framebuffer. + * \param pSAREA Pointer to the SAREA. + * \param fd Device handle for the DRM. + * \param extensions ?? + * \param driver_modes Returns modes suppoted by the driver + * \param loaderPrivate ?? + * + * \note There is no need to check the minimum API version in this + * function. Since the name of this function is versioned, it is + * impossible for a loader that is too old to even load this driver. + */ +static __DRIscreen * +driCreateNewScreen(int scrn, + const __DRIversion *ddx_version, + const __DRIversion *dri_version, + const __DRIversion *drm_version, + const __DRIframebuffer *frame_buffer, + drmAddress pSAREA, int fd, + const __DRIextension **extensions, + const __DRIconfig ***driver_modes, + void *loaderPrivate) +{ + static const __DRIextension *emptyExtensionList[] = { NULL }; + __DRIscreen *psp; + + if (driDriverAPI.InitScreen == NULL) + return NULL; + + psp = calloc(1, sizeof *psp); + if (!psp) + return NULL; + + setupLoaderExtensions(psp, extensions); + + /* + ** NOT_DONE: This is used by the X server to detect when the client + ** has died while holding the drawable lock. The client sets the + ** drawable lock to this value. + */ + psp->drawLockID = 1; + + psp->drm_version = *drm_version; + psp->ddx_version = *ddx_version; + psp->dri_version = *dri_version; + + psp->pSAREA = pSAREA; + psp->lock = (drmLock *) &psp->pSAREA->lock; + + psp->pFB = frame_buffer->base; + psp->fbSize = frame_buffer->size; + psp->fbStride = frame_buffer->stride; + psp->fbWidth = frame_buffer->width; + psp->fbHeight = frame_buffer->height; + psp->devPrivSize = frame_buffer->dev_priv_size; + psp->pDevPriv = frame_buffer->dev_priv; + psp->fbBPP = psp->fbStride * 8 / frame_buffer->width; + + psp->extensions = emptyExtensionList; + psp->fd = fd; + psp->myNum = scrn; + psp->dri2.enabled = GL_FALSE; + + psp->DriverAPI = driDriverAPI; + psp->api_mask = (1 << __DRI_API_OPENGL); + + *driver_modes = driDriverAPI.InitScreen(psp); + if (*driver_modes == NULL) { + free(psp); + return NULL; + } + + return psp; +} + +/** + * DRI2 + */ +static __DRIscreen * +dri2CreateNewScreen(int scrn, int fd, + const __DRIextension **extensions, + const __DRIconfig ***driver_configs, void *data) +{ + static const __DRIextension *emptyExtensionList[] = { NULL }; + __DRIscreen *psp; + drmVersionPtr version; + + if (driDriverAPI.InitScreen2 == NULL) + return NULL; + + psp = calloc(1, sizeof(*psp)); + if (!psp) + return NULL; + + setupLoaderExtensions(psp, extensions); + + version = drmGetVersion(fd); + if (version) { + psp->drm_version.major = version->version_major; + psp->drm_version.minor = version->version_minor; + psp->drm_version.patch = version->version_patchlevel; + drmFreeVersion(version); + } + + psp->extensions = emptyExtensionList; + psp->fd = fd; + psp->myNum = scrn; + psp->dri2.enabled = GL_TRUE; + + psp->DriverAPI = driDriverAPI; + psp->api_mask = (1 << __DRI_API_OPENGL); + *driver_configs = driDriverAPI.InitScreen2(psp); + if (*driver_configs == NULL) { + free(psp); + return NULL; + } + + psp->DriverAPI = driDriverAPI; + psp->loaderPrivate = data; + + driParseOptionInfo(&psp->optionInfo, __dri2ConfigOptions, + __dri2NConfigOptions); + driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum, + "dri2"); + + return psp; +} + +static const __DRIextension **driGetExtensions(__DRIscreen *psp) +{ + return psp->extensions; +} + +/** Core interface */ +const __DRIcoreExtension driCoreExtension = { + { __DRI_CORE, __DRI_CORE_VERSION }, + NULL, + driDestroyScreen, + driGetExtensions, + driGetConfigAttrib, + driIndexConfigAttrib, + NULL, + driDestroyDrawable, + driSwapBuffers, + NULL, + driCopyContext, + driDestroyContext, + driBindContext, + driUnbindContext +}; + +/** Legacy DRI interface */ +const __DRIlegacyExtension driLegacyExtension = { + { __DRI_LEGACY, __DRI_LEGACY_VERSION }, + driCreateNewScreen, + driCreateNewDrawable, + driCreateNewContext, +}; + +/** DRI2 interface */ +const __DRIdri2Extension driDRI2Extension = { + { __DRI_DRI2, __DRI_DRI2_VERSION }, + dri2CreateNewScreen, + dri2CreateNewDrawable, + dri2CreateNewContext, + dri2GetAPIMask, + dri2CreateNewContextForAPI +}; + +const __DRI2configQueryExtension dri2ConfigQueryExtension = { + { __DRI2_CONFIG_QUERY, __DRI2_CONFIG_QUERY_VERSION }, + dri2ConfigQueryb, + dri2ConfigQueryi, + dri2ConfigQueryf, +}; + +/** + * Calculate amount of swap interval used between GLX buffer swaps. + * + * The usage value, on the range [0,max], is the fraction of total swap + * interval time used between GLX buffer swaps is calculated. + * + * \f$p = t_d / (i * t_r)\f$ + * + * Where \f$t_d\f$ is the time since the last GLX buffer swap, \f$i\f$ is the + * swap interval (as set by \c glXSwapIntervalSGI), and \f$t_r\f$ time + * required for a single vertical refresh period (as returned by \c + * glXGetMscRateOML). + * + * See the documentation for the GLX_MESA_swap_frame_usage extension for more + * details. + * + * \param dPriv Pointer to the private drawable structure. + * \return If less than a single swap interval time period was required + * between GLX buffer swaps, a number greater than 0 and less than + * 1.0 is returned. If exactly one swap interval time period is + * required, 1.0 is returned, and if more than one is required then + * a number greater than 1.0 will be returned. + * + * \sa glXSwapIntervalSGI glXGetMscRateOML + * + * \todo Instead of caching the \c glXGetMscRateOML function pointer, would it + * be possible to cache the sync rate? + */ +float +driCalculateSwapUsage( __DRIdrawable *dPriv, int64_t last_swap_ust, + int64_t current_ust ) +{ + int32_t n; + int32_t d; + int interval; + float usage = 1.0; + __DRIscreen *psp = dPriv->driScreenPriv; + + if ( (*psp->systemTime->getMSCRate)(dPriv, &n, &d, dPriv->loaderPrivate) ) { + interval = (dPriv->swap_interval != 0) ? dPriv->swap_interval : 1; + + + /* We want to calculate + * (current_UST - last_swap_UST) / (interval * us_per_refresh). We get + * current_UST by calling __glXGetUST. last_swap_UST is stored in + * dPriv->swap_ust. interval has already been calculated. + * + * The only tricky part is us_per_refresh. us_per_refresh is + * 1000000 / MSC_rate. We know the MSC_rate is n / d. We can flip it + * around and say us_per_refresh = 1000000 * d / n. Since this goes in + * the denominator of the final calculation, we calculate + * (interval * 1000000 * d) and move n into the numerator. + */ + + usage = (current_ust - last_swap_ust); + usage *= n; + usage /= (interval * d); + usage /= 1000000.0; + } + + return usage; +} + +void +dri2InvalidateDrawable(__DRIdrawable *drawable) +{ + drawable->dri2.stamp++; +} + +/*@}*/ diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h new file mode 100644 index 0000000..ffffb99 --- /dev/null +++ b/src/mesa/drivers/dri/common/dri_util.h @@ -0,0 +1,557 @@ +/* + * Copyright 1998-1999 Precision Insight, 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 PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * \file dri_util.h + * DRI utility functions definitions. + * + * This module acts as glue between GLX and the actual hardware driver. A DRI + * driver doesn't really \e have to use any of this - it's optional. But, some + * useful stuff is done here that otherwise would have to be duplicated in most + * drivers. + * + * Basically, these utility functions take care of some of the dirty details of + * screen initialization, context creation, context binding, DRM setup, etc. + * + * These functions are compiled into each DRI driver so libGL.so knows nothing + * about them. + * + * \sa dri_util.c. + * + * \author Kevin E. Martin + * \author Brian Paul + */ + +#ifndef _DRI_UTIL_H_ +#define _DRI_UTIL_H_ + +#include +#include +#include +#include +#include "xmlconfig.h" +#include "main/glheader.h" +#include "main/mtypes.h" +#include "GL/internal/dri_interface.h" + +#define GLX_BAD_CONTEXT 5 + +typedef struct __DRIswapInfoRec __DRIswapInfo; + +/** + * Extensions. + */ +extern const __DRIlegacyExtension driLegacyExtension; +extern const __DRIcoreExtension driCoreExtension; +extern const __DRIdri2Extension driDRI2Extension; +extern const __DRIextension driReadDrawableExtension; +extern const __DRIcopySubBufferExtension driCopySubBufferExtension; +extern const __DRIswapControlExtension driSwapControlExtension; +extern const __DRImediaStreamCounterExtension driMediaStreamCounterExtension; +extern const __DRI2configQueryExtension dri2ConfigQueryExtension; + +/** + * Used by DRI_VALIDATE_DRAWABLE_INFO + */ +#define DRI_VALIDATE_DRAWABLE_INFO_ONCE(pDrawPriv) \ + do { \ + if (*(pDrawPriv->pStamp) != pDrawPriv->lastStamp) { \ + __driUtilUpdateDrawableInfo(pDrawPriv); \ + } \ + } while (0) + + +/** + * Utility macro to validate the drawable information. + * + * See __DRIdrawable::pStamp and __DRIdrawable::lastStamp. + */ +#define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp) \ +do { \ + while (*(pdp->pStamp) != pdp->lastStamp) { \ + register unsigned int hwContext = psp->pSAREA->lock.lock & \ + ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \ + DRM_UNLOCK(psp->fd, &psp->pSAREA->lock, hwContext); \ + \ + DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \ + DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \ + DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \ + \ + DRM_LIGHT_LOCK(psp->fd, &psp->pSAREA->lock, hwContext); \ + } \ +} while (0) + +/** + * Same as above, but for two drawables simultaneously. + * + */ + +#define DRI_VALIDATE_TWO_DRAWABLES_INFO(psp, pdp, prp) \ +do { \ + while (*((pdp)->pStamp) != (pdp)->lastStamp || \ + *((prp)->pStamp) != (prp)->lastStamp) { \ + register unsigned int hwContext = (psp)->pSAREA->lock.lock & \ + ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \ + DRM_UNLOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext); \ + \ + DRM_SPINLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \ + DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \ + DRI_VALIDATE_DRAWABLE_INFO_ONCE(prp); \ + DRM_SPINUNLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \ + \ + DRM_LIGHT_LOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext); \ + } \ +} while (0) + + +/** + * Driver callback functions. + * + * Each DRI driver must have one of these structures with all the pointers set + * to appropriate functions within the driver. + * + * When glXCreateContext() is called, for example, it'll call a helper function + * dri_util.c which in turn will jump through the \a CreateContext pointer in + * this structure. + */ +struct __DriverAPIRec { + const __DRIconfig **(*InitScreen) (__DRIscreen * priv); + + /** + * Screen destruction callback + */ + void (*DestroyScreen)(__DRIscreen *driScrnPriv); + + /** + * Context creation callback + */ + GLboolean (*CreateContext)(gl_api api, + const struct gl_config *glVis, + __DRIcontext *driContextPriv, + void *sharedContextPrivate); + + /** + * Context destruction callback + */ + void (*DestroyContext)(__DRIcontext *driContextPriv); + + /** + * Buffer (drawable) creation callback + */ + GLboolean (*CreateBuffer)(__DRIscreen *driScrnPriv, + __DRIdrawable *driDrawPriv, + const struct gl_config *glVis, + GLboolean pixmapBuffer); + + /** + * Buffer (drawable) destruction callback + */ + void (*DestroyBuffer)(__DRIdrawable *driDrawPriv); + + /** + * Buffer swapping callback + */ + void (*SwapBuffers)(__DRIdrawable *driDrawPriv); + + /** + * Context activation callback + */ + GLboolean (*MakeCurrent)(__DRIcontext *driContextPriv, + __DRIdrawable *driDrawPriv, + __DRIdrawable *driReadPriv); + + /** + * Context unbinding callback + */ + GLboolean (*UnbindContext)(__DRIcontext *driContextPriv); + + /** + * Retrieves statistics about buffer swap operations. Required if + * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported. + */ + int (*GetSwapInfo)( __DRIdrawable *dPriv, __DRIswapInfo * sInfo ); + + + /** + * These are required if GLX_OML_sync_control is supported. + */ + /*@{*/ + int (*WaitForMSC)( __DRIdrawable *priv, int64_t target_msc, + int64_t divisor, int64_t remainder, + int64_t * msc ); + int (*WaitForSBC)( __DRIdrawable *priv, int64_t target_sbc, + int64_t * msc, int64_t * sbc ); + + int64_t (*SwapBuffersMSC)( __DRIdrawable *priv, int64_t target_msc, + int64_t divisor, int64_t remainder ); + /*@}*/ + void (*CopySubBuffer)(__DRIdrawable *driDrawPriv, + int x, int y, int w, int h); + + /** + * New version of GetMSC so we can pass drawable data to the low + * level DRM driver (e.g. pipe info). Required if + * GLX_SGI_video_sync or GLX_OML_sync_control is supported. + */ + int (*GetDrawableMSC) ( __DRIscreen * priv, + __DRIdrawable *drawablePrivate, + int64_t *count); + + + + /* DRI2 Entry point */ + const __DRIconfig **(*InitScreen2) (__DRIscreen * priv); +}; + +extern const struct __DriverAPIRec driDriverAPI; + + +struct __DRIswapInfoRec { + /** + * Number of swapBuffers operations that have been *completed*. + */ + uint64_t swap_count; + + /** + * Unadjusted system time of the last buffer swap. This is the time + * when the swap completed, not the time when swapBuffers was called. + */ + int64_t swap_ust; + + /** + * Number of swap operations that occurred after the swap deadline. That + * is if a swap happens more than swap_interval frames after the previous + * swap, it has missed its deadline. If swap_interval is 0, then the + * swap deadline is 1 frame after the previous swap. + */ + uint64_t swap_missed_count; + + /** + * Amount of time used by the last swap that missed its deadline. This + * is calculated as (__glXGetUST() - swap_ust) / (swap_interval * + * time_for_single_vrefresh)). If the actual value of swap_interval is + * 0, then 1 is used instead. If swap_missed_count is non-zero, this + * should be greater-than 1.0. + */ + float swap_missed_usage; +}; + + +/** + * Per-drawable private DRI driver information. + */ +struct __DRIdrawableRec { + /** + * Kernel drawable handle + */ + drm_drawable_t hHWDrawable; + + /** + * Driver's private drawable information. + * + * This structure is opaque. + */ + void *driverPrivate; + + /** + * Private data from the loader. We just hold on to it and pass + * it back when calling into loader provided functions. + */ + void *loaderPrivate; + + /** + * Reference count for number of context's currently bound to this + * drawable. + * + * Once it reaches zero, the drawable can be destroyed. + * + * \note This behavior will change with GLX 1.3. + */ + int refcount; + + /** + * Index of this drawable information in the SAREA. + */ + unsigned int index; + + /** + * Pointer to the "drawable has changed ID" stamp in the SAREA (or + * to dri2.stamp if DRI2 is being used). + */ + unsigned int *pStamp; + + /** + * Last value of the stamp. + * + * If this differs from the value stored at __DRIdrawable::pStamp, + * then the drawable information has been modified by the X server, and the + * drawable information (below) should be retrieved from the X server. + */ + unsigned int lastStamp; + + /** + * \name Drawable + * + * Drawable information used in software fallbacks. + */ + /*@{*/ + int x; + int y; + int w; + int h; + int numClipRects; + drm_clip_rect_t *pClipRects; + /*@}*/ + + /** + * \name Back and depthbuffer + * + * Information about the back and depthbuffer where different from above. + */ + /*@{*/ + int backX; + int backY; + int backClipRectType; + int numBackClipRects; + drm_clip_rect_t *pBackClipRects; + /*@}*/ + + /** + * \name Vertical blank tracking information + * Used for waiting on vertical blank events. + */ + /*@{*/ + unsigned int vblSeq; + unsigned int vblFlags; + /*@}*/ + + /** + * \name Monotonic MSC tracking + * + * Low level driver is responsible for updating msc_base and + * vblSeq values so that higher level code can calculate + * a new msc value or msc target for a WaitMSC call. The new value + * will be: + * msc = msc_base + get_vblank_count() - vblank_base; + * + * And for waiting on a value, core code will use: + * actual_target = target_msc - msc_base + vblank_base; + */ + /*@{*/ + int64_t vblank_base; + int64_t msc_base; + /*@}*/ + + /** + * Pointer to context to which this drawable is currently bound. + */ + __DRIcontext *driContextPriv; + + /** + * Pointer to screen on which this drawable was created. + */ + __DRIscreen *driScreenPriv; + + /** + * Controls swap interval as used by GLX_SGI_swap_control and + * GLX_MESA_swap_control. + */ + unsigned int swap_interval; + + struct { + unsigned int stamp; + drm_clip_rect_t clipRect; + } dri2; +}; + +/** + * Per-context private driver information. + */ +struct __DRIcontextRec { + /** + * Kernel context handle used to access the device lock. + */ + drm_context_t hHWContext; + + /** + * Device driver's private context data. This structure is opaque. + */ + void *driverPrivate; + + /** + * Pointer to drawable currently bound to this context for drawing. + */ + __DRIdrawable *driDrawablePriv; + + /** + * Pointer to drawable currently bound to this context for reading. + */ + __DRIdrawable *driReadablePriv; + + /** + * Pointer to screen on which this context was created. + */ + __DRIscreen *driScreenPriv; + + /** + * The loaders's private context data. This structure is opaque. + */ + void *loaderPrivate; + + struct { + int draw_stamp; + int read_stamp; + } dri2; +}; + +/** + * Per-screen private driver information. + */ +struct __DRIscreenRec { + /** + * Current screen's number + */ + int myNum; + + /** + * Callback functions into the hardware-specific DRI driver code. + */ + struct __DriverAPIRec DriverAPI; + + const __DRIextension **extensions; + /** + * DDX / 2D driver version information. + */ + __DRIversion ddx_version; + + /** + * DRI X extension version information. + */ + __DRIversion dri_version; + + /** + * DRM (kernel module) version information. + */ + __DRIversion drm_version; + + /** + * ID used when the client sets the drawable lock. + * + * The X server uses this value to detect if the client has died while + * holding the drawable lock. + */ + int drawLockID; + + /** + * File descriptor returned when the kernel device driver is opened. + * + * Used to: + * - authenticate client to kernel + * - map the frame buffer, SAREA, etc. + * - close the kernel device driver + */ + int fd; + + /** + * SAREA pointer + * + * Used to access: + * - the device lock + * - the device-independent per-drawable and per-context(?) information + */ + drm_sarea_t *pSAREA; + + /** + * \name Direct frame buffer access information + * Used for software fallbacks. + */ + /*@{*/ + unsigned char *pFB; + int fbSize; + int fbOrigin; + int fbStride; + int fbWidth; + int fbHeight; + int fbBPP; + /*@}*/ + + /** + * \name Device-dependent private information (stored in the SAREA). + * + * This data is accessed by the client driver only. + */ + /*@{*/ + void *pDevPriv; + int devPrivSize; + /*@}*/ + + /** + * Device-dependent private information (not stored in the SAREA). + * + * This pointer is never touched by the DRI layer. + */ +#ifdef __cplusplus + void *priv; +#else + void *private; +#endif + + /* Extensions provided by the loader. */ + const __DRIgetDrawableInfoExtension *getDrawableInfo; + const __DRIsystemTimeExtension *systemTime; + const __DRIdamageExtension *damage; + + struct { + /* Flag to indicate that this is a DRI2 screen. Many of the above + * fields will not be valid or initializaed in that case. */ + int enabled; + __DRIdri2LoaderExtension *loader; + __DRIimageLookupExtension *image; + __DRIuseInvalidateExtension *useInvalidate; + } dri2; + + /* The lock actually in use, old sarea or DRI2 */ + drmLock *lock; + + driOptionCache optionInfo; + driOptionCache optionCache; + unsigned int api_mask; + void *loaderPrivate; +}; + +extern void +__driUtilUpdateDrawableInfo(__DRIdrawable *pdp); + +extern float +driCalculateSwapUsage( __DRIdrawable *dPriv, + int64_t last_swap_ust, int64_t current_ust ); + +extern GLint +driIntersectArea( drm_clip_rect_t rect1, drm_clip_rect_t rect2 ); + +extern void +dri2InvalidateDrawable(__DRIdrawable *drawable); + +#endif /* _DRI_UTIL_H_ */ diff --git a/src/mesa/drivers/dri/common/drirenderbuffer.c b/src/mesa/drivers/dri/common/drirenderbuffer.c new file mode 100644 index 0000000..7ac1ab1 --- /dev/null +++ b/src/mesa/drivers/dri/common/drirenderbuffer.c @@ -0,0 +1,200 @@ + +#include "main/mtypes.h" +#include "main/formats.h" +#include "main/renderbuffer.h" +#include "main/imports.h" +#include "drirenderbuffer.h" + + +/** + * This will get called when a window (gl_framebuffer) is resized (probably + * via driUpdateFramebufferSize(), below). + * Just update width, height and internal format fields for now. + * There's usually no memory allocation above because the present + * DRI drivers use statically-allocated full-screen buffers. If that's not + * the case for a DRI driver, a different AllocStorage method should + * be used. + */ +static GLboolean +driRenderbufferStorage(struct gl_context *ctx, struct gl_renderbuffer *rb, + GLenum internalFormat, GLuint width, GLuint height) +{ + rb->Width = width; + rb->Height = height; + rb->InternalFormat = internalFormat; + return GL_TRUE; +} + + +static void +driDeleteRenderbuffer(struct gl_renderbuffer *rb) +{ + /* don't free rb->Data Chances are it's a memory mapped region for + * the dri drivers. + */ + free(rb); +} + + +/** + * Allocate a new driRenderbuffer object. + * Individual drivers are free to implement different versions of + * this function. + * + * At this time, this function can only be used for window-system + * renderbuffers, not user-created RBOs. + * + * \param format Either GL_RGBA, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, + * GL_DEPTH_COMPONENT32, or GL_STENCIL_INDEX8_EXT (for now). + * \param addr address in main memory of the buffer. Probably a memory + * mapped region. + * \param cpp chars or bytes per pixel + * \param offset start of renderbuffer with respect to start of framebuffer + * \param pitch pixels per row + */ +driRenderbuffer * +driNewRenderbuffer(gl_format format, GLvoid *addr, + GLint cpp, GLint offset, GLint pitch, + __DRIdrawable *dPriv) +{ + driRenderbuffer *drb; + + assert(cpp > 0); + assert(pitch > 0); + + drb = calloc(1, sizeof(driRenderbuffer)); + if (drb) { + const GLuint name = 0; + + _mesa_init_renderbuffer(&drb->Base, name); + + /* Make sure we're using a null-valued GetPointer routine */ + assert(drb->Base.GetPointer(NULL, &drb->Base, 0, 0) == NULL); + + switch (format) { + case MESA_FORMAT_ARGB8888: + if (cpp == 2) { + /* override format */ + format = MESA_FORMAT_RGB565; + } + drb->Base.DataType = GL_UNSIGNED_BYTE; + break; + case MESA_FORMAT_Z16: + /* Depth */ + /* we always Get/Put 32-bit Z values */ + drb->Base.DataType = GL_UNSIGNED_INT; + assert(cpp == 2); + break; + case MESA_FORMAT_Z32: + /* Depth */ + /* we always Get/Put 32-bit Z values */ + drb->Base.DataType = GL_UNSIGNED_INT; + assert(cpp == 4); + break; + case MESA_FORMAT_Z24_S8: + drb->Base.DataType = GL_UNSIGNED_INT_24_8_EXT; + assert(cpp == 4); + break; + case MESA_FORMAT_S8_Z24: + drb->Base.DataType = GL_UNSIGNED_INT_24_8_EXT; + assert(cpp == 4); + break; + case MESA_FORMAT_S8: + /* Stencil */ + drb->Base.DataType = GL_UNSIGNED_BYTE; + break; + default: + _mesa_problem(NULL, "Bad format 0x%x in driNewRenderbuffer", format); + return NULL; + } + + drb->Base.Format = format; + + drb->Base.InternalFormat = + drb->Base._BaseFormat = _mesa_get_format_base_format(format); + + drb->Base.AllocStorage = driRenderbufferStorage; + drb->Base.Delete = driDeleteRenderbuffer; + + drb->Base.Data = addr; + + /* DRI renderbuffer-specific fields: */ + drb->dPriv = dPriv; + drb->offset = offset; + drb->pitch = pitch; + drb->cpp = cpp; + + /* may be changed if page flipping is active: */ + drb->flippedOffset = offset; + drb->flippedPitch = pitch; + drb->flippedData = addr; + } + return drb; +} + + +/** + * Update the front and back renderbuffers' flippedPitch/Offset/Data fields. + * If stereo, flip both the left and right pairs. + * This is used when we do double buffering via page flipping. + * \param fb the framebuffer we're page flipping + * \param flipped if true, set flipped values, else set non-flipped values + */ +void +driFlipRenderbuffers(struct gl_framebuffer *fb, GLboolean flipped) +{ + const GLuint count = fb->Visual.stereoMode ? 2 : 1; + GLuint lr; /* left or right */ + + /* we shouldn't really call this function if single-buffered, but + * play it safe. + */ + if (!fb->Visual.doubleBufferMode) + return; + + for (lr = 0; lr < count; lr++) { + GLuint frontBuf = (lr == 0) ? BUFFER_FRONT_LEFT : BUFFER_FRONT_RIGHT; + GLuint backBuf = (lr == 0) ? BUFFER_BACK_LEFT : BUFFER_BACK_RIGHT; + driRenderbuffer *front_drb + = (driRenderbuffer *) fb->Attachment[frontBuf].Renderbuffer; + driRenderbuffer *back_drb + = (driRenderbuffer *) fb->Attachment[backBuf].Renderbuffer; + + if (flipped) { + front_drb->flippedOffset = back_drb->offset; + front_drb->flippedPitch = back_drb->pitch; + front_drb->flippedData = back_drb->Base.Data; + back_drb->flippedOffset = front_drb->offset; + back_drb->flippedPitch = front_drb->pitch; + back_drb->flippedData = front_drb->Base.Data; + } + else { + front_drb->flippedOffset = front_drb->offset; + front_drb->flippedPitch = front_drb->pitch; + front_drb->flippedData = front_drb->Base.Data; + back_drb->flippedOffset = back_drb->offset; + back_drb->flippedPitch = back_drb->pitch; + back_drb->flippedData = back_drb->Base.Data; + } + } +} + + +/** + * Check that the gl_framebuffer associated with dPriv is the right size. + * Resize the gl_framebuffer if needed. + * It's expected that the dPriv->driverPrivate member points to a + * gl_framebuffer object. + */ +void +driUpdateFramebufferSize(struct gl_context *ctx, const __DRIdrawable *dPriv) +{ + struct gl_framebuffer *fb = (struct gl_framebuffer *) dPriv->driverPrivate; + if (fb && (dPriv->w != fb->Width || dPriv->h != fb->Height)) { + ctx->Driver.ResizeBuffers(ctx, fb, dPriv->w, dPriv->h); + /* if the driver needs the hw lock for ResizeBuffers, the drawable + might have changed again by now */ + assert(fb->Width == dPriv->w); + assert(fb->Height == dPriv->h); + } +} diff --git a/src/mesa/drivers/dri/common/drirenderbuffer.h b/src/mesa/drivers/dri/common/drirenderbuffer.h new file mode 100644 index 0000000..0cae730 --- /dev/null +++ b/src/mesa/drivers/dri/common/drirenderbuffer.h @@ -0,0 +1,79 @@ + +/** + * A driRenderbuffer is dervied from gl_renderbuffer. + * It describes a color buffer (front or back), a depth buffer, or stencil + * buffer etc. + * Specific to DRI drivers are the offset and pitch fields. + */ + + +#ifndef DRIRENDERBUFFER_H +#define DRIRENDERBUFFER_H + +#include "main/mtypes.h" +#include "main/formats.h" +#include "dri_util.h" + + +typedef struct { + struct gl_renderbuffer Base; + + /* Chars or bytes per pixel. If Z and Stencil are stored together this + * will typically be 32 whether this a depth or stencil renderbuffer. + */ + GLint cpp; + + /* Buffer position and pitch (row stride). Recall that for today's DRI + * drivers, we have statically allocated color/depth/stencil buffers. + * So this information describes the whole screen, not just a window. + * To address pixels in a window, we need to know the window's position + * and size with respect to the screen. + */ + GLint offset; /* in bytes */ + GLint pitch; /* in pixels */ + + /* If the driver can do page flipping (full-screen double buffering) + * the current front/back buffers may get swapped. + * If page flipping is disabled, these fields will be identical to + * the offset/pitch/Data above. + * If page flipping is enabled, and this is the front(back) renderbuffer, + * flippedOffset/Pitch/Data will have the back(front) renderbuffer's values. + */ + GLint flippedOffset; + GLint flippedPitch; + GLvoid *flippedData; /* mmap'd address of buffer memory, if used */ + + /* Pointer to corresponding __DRIdrawable. This is used to compute + * the window's position within the framebuffer. + */ + __DRIdrawable *dPriv; + + /* XXX this is for radeon/r200 only. We should really create a new + * r200Renderbuffer class, derived from this class... not a huge deal. + */ + GLboolean depthHasSurface; + + /** + * A handy flag to know if this is the back color buffer. + * + * \note + * This is currently only used by tdfx. + */ + GLboolean backBuffer; +} driRenderbuffer; + + +extern driRenderbuffer * +driNewRenderbuffer(gl_format format, GLvoid *addr, + GLint cpp, GLint offset, GLint pitch, + __DRIdrawable *dPriv); + +extern void +driFlipRenderbuffers(struct gl_framebuffer *fb, GLboolean flipped); + + +extern void +driUpdateFramebufferSize(struct gl_context *ctx, const __DRIdrawable *dPriv); + + +#endif /* DRIRENDERBUFFER_H */ diff --git a/src/mesa/drivers/dri/common/drisw_util.c b/src/mesa/drivers/dri/common/drisw_util.c new file mode 100644 index 0000000..1529c23 --- /dev/null +++ b/src/mesa/drivers/dri/common/drisw_util.c @@ -0,0 +1,273 @@ +/* + * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. + * 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, 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. + */ + +/** + * \file drisw_util.c + * + * DRISW utility functions, i.e. dri_util.c stripped from drm-specific bits. + */ + +#include "drisw_util.h" +#include "utils.h" + + +/** + * Screen functions + */ + +static void +setupLoaderExtensions(__DRIscreen *psp, + const __DRIextension **extensions) +{ + int i; + + for (i = 0; extensions[i]; i++) { + if (strcmp(extensions[i]->name, __DRI_SWRAST_LOADER) == 0) + psp->swrast_loader = (__DRIswrastLoaderExtension *) extensions[i]; + } +} + +static __DRIscreen * +driCreateNewScreen(int scrn, const __DRIextension **extensions, + const __DRIconfig ***driver_configs, void *data) +{ + static const __DRIextension *emptyExtensionList[] = { NULL }; + __DRIscreen *psp; + + (void) data; + + psp = CALLOC_STRUCT(__DRIscreenRec); + if (!psp) + return NULL; + + setupLoaderExtensions(psp, extensions); + + psp->extensions = emptyExtensionList; + psp->fd = -1; + psp->myNum = scrn; + + *driver_configs = driDriverAPI.InitScreen(psp); + + if (*driver_configs == NULL) { + FREE(psp); + return NULL; + } + + return psp; +} + +static void driDestroyScreen(__DRIscreen *psp) +{ + if (psp) { + driDriverAPI.DestroyScreen(psp); + + FREE(psp); + } +} + +static const __DRIextension **driGetExtensions(__DRIscreen *psp) +{ + return psp->extensions; +} + + +/** + * Context functions + */ + +static __DRIcontext * +driCreateNewContext(__DRIscreen *psp, const __DRIconfig *config, + __DRIcontext *shared, void *data) +{ + __DRIcontext *pcp; + void * const shareCtx = (shared != NULL) ? shared->driverPrivate : NULL; + + pcp = CALLOC_STRUCT(__DRIcontextRec); + if (!pcp) + return NULL; + + pcp->loaderPrivate = data; + + pcp->driScreenPriv = psp; + pcp->driDrawablePriv = NULL; + pcp->driReadablePriv = NULL; + + if (!driDriverAPI.CreateContext(API_OPENGL, + &config->modes, pcp, shareCtx)) { + FREE(pcp); + return NULL; + } + + return pcp; +} + +static void +driDestroyContext(__DRIcontext *pcp) +{ + if (pcp) { + driDriverAPI.DestroyContext(pcp); + FREE(pcp); + } +} + +static int +driCopyContext(__DRIcontext *dst, __DRIcontext *src, unsigned long mask) +{ + return GL_FALSE; +} + +static void dri_get_drawable(__DRIdrawable *pdp); +static void dri_put_drawable(__DRIdrawable *pdp); + +static int driBindContext(__DRIcontext *pcp, + __DRIdrawable *pdp, + __DRIdrawable *prp) +{ + /* Bind the drawable to the context */ + if (pcp) { + pcp->driDrawablePriv = pdp; + pcp->driReadablePriv = prp; + if (pdp) { + pdp->driContextPriv = pcp; + dri_get_drawable(pdp); + } + if ( prp && pdp != prp ) { + dri_get_drawable(prp); + } + } + + return driDriverAPI.MakeCurrent(pcp, pdp, prp); +} + +static int driUnbindContext(__DRIcontext *pcp) +{ + __DRIdrawable *pdp; + __DRIdrawable *prp; + + if (pcp == NULL) + return GL_FALSE; + + pdp = pcp->driDrawablePriv; + prp = pcp->driReadablePriv; + + /* already unbound */ + if (!pdp && !prp) + return GL_TRUE; + + driDriverAPI.UnbindContext(pcp); + + dri_put_drawable(pdp); + + if (prp != pdp) { + dri_put_drawable(prp); + } + + pcp->driDrawablePriv = NULL; + pcp->driReadablePriv = NULL; + + return GL_TRUE; +} + + +/** + * Drawable functions + */ + +static void dri_get_drawable(__DRIdrawable *pdp) +{ + pdp->refcount++; +} + +static void dri_put_drawable(__DRIdrawable *pdp) +{ + if (pdp) { + pdp->refcount--; + if (pdp->refcount) + return; + + driDriverAPI.DestroyBuffer(pdp); + + FREE(pdp); + } +} + +static __DRIdrawable * +driCreateNewDrawable(__DRIscreen *psp, + const __DRIconfig *config, void *data) +{ + __DRIdrawable *pdp; + + pdp = CALLOC_STRUCT(__DRIdrawableRec); + if (!pdp) + return NULL; + + pdp->loaderPrivate = data; + + pdp->driScreenPriv = psp; + pdp->driContextPriv = NULL; + + dri_get_drawable(pdp); + + if (!driDriverAPI.CreateBuffer(psp, pdp, &config->modes, GL_FALSE)) { + FREE(pdp); + return NULL; + } + + pdp->lastStamp = 1; /* const */ + + return pdp; +} + +static void +driDestroyDrawable(__DRIdrawable *pdp) +{ + dri_put_drawable(pdp); +} + +static void driSwapBuffers(__DRIdrawable *pdp) +{ + driDriverAPI.SwapBuffers(pdp); +} + +const __DRIcoreExtension driCoreExtension = { + { __DRI_CORE, __DRI_CORE_VERSION }, + NULL, /* driCreateNewScreen */ + driDestroyScreen, + driGetExtensions, + driGetConfigAttrib, + driIndexConfigAttrib, + NULL, /* driCreateNewDrawable */ + driDestroyDrawable, + driSwapBuffers, + driCreateNewContext, + driCopyContext, + driDestroyContext, + driBindContext, + driUnbindContext +}; + +const __DRIswrastExtension driSWRastExtension = { + { __DRI_SWRAST, __DRI_SWRAST_VERSION }, + driCreateNewScreen, + driCreateNewDrawable +}; diff --git a/src/mesa/drivers/dri/common/drisw_util.h b/src/mesa/drivers/dri/common/drisw_util.h new file mode 100644 index 0000000..d43f523 --- /dev/null +++ b/src/mesa/drivers/dri/common/drisw_util.h @@ -0,0 +1,134 @@ +/* + * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. + * 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, 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. + */ + +/** + * @file + * Binding of the DRI interface (dri_interface.h) for DRISW. + * + * The DRISW structs are 'base classes' of the corresponding DRI1 / DRI2 (DRM) + * structs. The bindings for SW and DRM can be unified by making the DRM structs + * 'sub-classes' of the SW structs, either proper or with field re-ordering. + * + * The code can also be unified but that requires cluttering the common code + * with ifdef's and guarding with (__DRIscreen::fd >= 0) for DRM. + */ + +#ifndef _DRISW_UTIL_H +#define _DRISW_UTIL_H + +#include "main/mtypes.h" + +#include +#include +typedef struct _drmLock drmLock; + + +/** + * Extensions + */ +extern const __DRIcoreExtension driCoreExtension; +extern const __DRIswrastExtension driSWRastExtension; + + +/** + * Driver callback functions + */ +struct __DriverAPIRec { + const __DRIconfig **(*InitScreen) (__DRIscreen * priv); + + void (*DestroyScreen)(__DRIscreen *driScrnPriv); + + GLboolean (*CreateContext)(gl_api glapi, + const struct gl_config *glVis, + __DRIcontext *driContextPriv, + void *sharedContextPrivate); + + void (*DestroyContext)(__DRIcontext *driContextPriv); + + GLboolean (*CreateBuffer)(__DRIscreen *driScrnPriv, + __DRIdrawable *driDrawPriv, + const struct gl_config *glVis, + GLboolean pixmapBuffer); + + void (*DestroyBuffer)(__DRIdrawable *driDrawPriv); + + void (*SwapBuffers)(__DRIdrawable *driDrawPriv); + + GLboolean (*MakeCurrent)(__DRIcontext *driContextPriv, + __DRIdrawable *driDrawPriv, + __DRIdrawable *driReadPriv); + + GLboolean (*UnbindContext)(__DRIcontext *driContextPriv); +}; + +extern const struct __DriverAPIRec driDriverAPI; + + +/** + * Data types + */ +struct __DRIscreenRec { + int myNum; + + int fd; + + void *private; + + const __DRIextension **extensions; + + const __DRIswrastLoaderExtension *swrast_loader; +}; + +struct __DRIcontextRec { + + void *driverPrivate; + + void *loaderPrivate; + + __DRIdrawable *driDrawablePriv; + + __DRIdrawable *driReadablePriv; + + __DRIscreen *driScreenPriv; +}; + +struct __DRIdrawableRec { + + void *driverPrivate; + + void *loaderPrivate; + + __DRIcontext *driContextPriv; + + __DRIscreen *driScreenPriv; + + int refcount; + + /* gallium */ + unsigned int lastStamp; + + int w; + int h; +}; + +#endif /* _DRISW_UTIL_H */ diff --git a/src/mesa/drivers/dri/common/memops.h b/src/mesa/drivers/dri/common/memops.h new file mode 100644 index 0000000..9cd1d8e --- /dev/null +++ b/src/mesa/drivers/dri/common/memops.h @@ -0,0 +1,17 @@ +#ifndef DRIMEMSETIO_H +#define DRIMEMSETIO_H +/* +* memset an area in I/O space +* We need to be careful about this on some archs +*/ +static INLINE void drimemsetio(void* address, int c, int size) +{ +#if defined(__powerpc__) || defined(__ia64__) + int i; + for(i=0;i + */ + + +#ifndef MMIO_H +#define MMIO_H + +#include "main/glheader.h" + +#if defined( __powerpc__ ) + +static INLINE uint32_t +read_MMIO_LE32( volatile void * base, unsigned long offset ) +{ + uint32_t val; + + __asm__ __volatile__( "lwbrx %0, %1, %2 ; eieio" + : "=r" (val) + : "b" (base), "r" (offset) ); + return val; +} + +#else + +static INLINE uint32_t +read_MMIO_LE32( volatile void * base, unsigned long offset ) +{ + volatile uint32_t * p = (volatile uint32_t *) (((volatile char *) base) + offset); + return LE32_TO_CPU( p[0] ); +} + +#endif + +#endif /* MMIO_H */ diff --git a/src/mesa/drivers/dri/common/mmx.h b/src/mesa/drivers/dri/common/mmx.h new file mode 100644 index 0000000..49ce7e3 --- /dev/null +++ b/src/mesa/drivers/dri/common/mmx.h @@ -0,0 +1,560 @@ +/* mmx.h + + MultiMedia eXtensions GCC interface library for IA32. + + To use this library, simply include this header file + and compile with GCC. You MUST have inlining enabled + in order for mmx_ok() to work; this can be done by + simply using -O on the GCC command line. + + Compiling with -DMMX_TRACE will cause detailed trace + output to be sent to stderr for each mmx operation. + This adds lots of code, and obviously slows execution to + a crawl, but can be very useful for debugging. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT + LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR ANY PARTICULAR PURPOSE. + + 1997-98 by H. Dietz and R. Fisher + + History: + 97-98* R.Fisher Early versions + 980501 R.Fisher Original Release + 980611* H.Dietz Rewrite, correctly implementing inlines, and + R.Fisher including direct register accesses. + 980616 R.Fisher Release of 980611 as 980616. + 980714 R.Fisher Minor corrections to Makefile, etc. + 980715 R.Fisher mmx_ok() now prevents optimizer from using + clobbered values. + mmx_ok() now checks if cpuid instruction is + available before trying to use it. + 980726* R.Fisher mm_support() searches for AMD 3DNow, Cyrix + Extended MMX, and standard MMX. It returns a + value which is positive if any of these are + supported, and can be masked with constants to + see which. mmx_ok() is now a call to this + 980726* R.Fisher Added i2r support for shift functions + 980919 R.Fisher Fixed AMD extended feature recognition bug. + 980921 R.Fisher Added definition/check for _MMX_H. + Added "float s[2]" to mmx_t for use with + 3DNow and EMMX. So same mmx_t can be used. + 981013 R.Fisher Fixed cpuid function 1 bug (looked at wrong reg) + Fixed psllq_i2r error in mmxtest.c + + * Unreleased (internal or interim) versions + + Notes: + It appears that the latest gas has the pand problem fixed, therefore + I'll undefine BROKEN_PAND by default. + String compares may be quicker than the multiple test/jumps in vendor + test sequence in mmx_ok(), but I'm not concerned with that right now. + + Acknowledgments: + Jussi Laako for pointing out the errors ultimately found to be + connected to the failure to notify the optimizer of clobbered values. + Roger Hardiman for reminding us that CPUID isn't everywhere, and that + someone may actually try to use this on a machine without CPUID. + Also for suggesting code for checking this. + Robert Dale for pointing out the AMD recognition bug. + Jimmy Mayfield and Carl Witty for pointing out the Intel recognition + bug. + Carl Witty for pointing out the psllq_i2r test bug. +*/ + +#ifndef _MMX_H +#define _MMX_H + +//#define MMX_TRACE + +/* Warning: at this writing, the version of GAS packaged + with most Linux distributions does not handle the + parallel AND operation mnemonic correctly. If the + symbol BROKEN_PAND is defined, a slower alternative + coding will be used. If execution of mmxtest results + in an illegal instruction fault, define this symbol. +*/ +#undef BROKEN_PAND + + +/* The type of an value that fits in an MMX register + (note that long long constant values MUST be suffixed + by LL and unsigned long long values by ULL, lest + they be truncated by the compiler) +*/ +typedef union { + long long q; /* Quadword (64-bit) value */ + unsigned long long uq; /* Unsigned Quadword */ + int d[2]; /* 2 Doubleword (32-bit) values */ + unsigned int ud[2]; /* 2 Unsigned Doubleword */ + short w[4]; /* 4 Word (16-bit) values */ + unsigned short uw[4]; /* 4 Unsigned Word */ + char b[8]; /* 8 Byte (8-bit) values */ + unsigned char ub[8]; /* 8 Unsigned Byte */ + float s[2]; /* Single-precision (32-bit) value */ +} mmx_t; + +/* Helper functions for the instruction macros that follow... + (note that memory-to-register, m2r, instructions are nearly + as efficient as register-to-register, r2r, instructions; + however, memory-to-memory instructions are really simulated + as a convenience, and are only 1/3 as efficient) +*/ +#ifdef MMX_TRACE + +/* Include the stuff for printing a trace to stderr... +*/ + +#include + +#define mmx_i2r(op, imm, reg) \ + { \ + mmx_t mmx_trace; \ + mmx_trace = (imm); \ + fprintf(stderr, #op "_i2r(" #imm "=0x%016llx, ", mmx_trace.q); \ + __asm__ __volatile__ ("movq %%" #reg ", %0" \ + : "=X" (mmx_trace) \ + : /* nothing */ ); \ + fprintf(stderr, #reg "=0x%016llx) => ", mmx_trace.q); \ + __asm__ __volatile__ (#op " %0, %%" #reg \ + : /* nothing */ \ + : "X" (imm)); \ + __asm__ __volatile__ ("movq %%" #reg ", %0" \ + : "=X" (mmx_trace) \ + : /* nothing */ ); \ + fprintf(stderr, #reg "=0x%016llx\n", mmx_trace.q); \ + } + +#define mmx_m2r(op, mem, reg) \ + { \ + mmx_t mmx_trace; \ + mmx_trace = (mem); \ + fprintf(stderr, #op "_m2r(" #mem "=0x%016llx, ", mmx_trace.q); \ + __asm__ __volatile__ ("movq %%" #reg ", %0" \ + : "=X" (mmx_trace) \ + : /* nothing */ ); \ + fprintf(stderr, #reg "=0x%016llx) => ", mmx_trace.q); \ + __asm__ __volatile__ (#op " %0, %%" #reg \ + : /* nothing */ \ + : "X" (mem)); \ + __asm__ __volatile__ ("movq %%" #reg ", %0" \ + : "=X" (mmx_trace) \ + : /* nothing */ ); \ + fprintf(stderr, #reg "=0x%016llx\n", mmx_trace.q); \ + } + +#define mmx_r2m(op, reg, mem) \ + { \ + mmx_t mmx_trace; \ + __asm__ __volatile__ ("movq %%" #reg ", %0" \ + : "=X" (mmx_trace) \ + : /* nothing */ ); \ + fprintf(stderr, #op "_r2m(" #reg "=0x%016llx, ", mmx_trace.q); \ + mmx_trace = (mem); \ + fprintf(stderr, #mem "=0x%016llx) => ", mmx_trace.q); \ + __asm__ __volatile__ (#op " %%" #reg ", %0" \ + : "=X" (mem) \ + : /* nothing */ ); \ + mmx_trace = (mem); \ + fprintf(stderr, #mem "=0x%016llx\n", mmx_trace.q); \ + } + +#define mmx_r2r(op, regs, regd) \ + { \ + mmx_t mmx_trace; \ + __asm__ __volatile__ ("movq %%" #regs ", %0" \ + : "=X" (mmx_trace) \ + : /* nothing */ ); \ + fprintf(stderr, #op "_r2r(" #regs "=0x%016llx, ", mmx_trace.q); \ + __asm__ __volatile__ ("movq %%" #regd ", %0" \ + : "=X" (mmx_trace) \ + : /* nothing */ ); \ + fprintf(stderr, #regd "=0x%016llx) => ", mmx_trace.q); \ + __asm__ __volatile__ (#op " %" #regs ", %" #regd); \ + __asm__ __volatile__ ("movq %%" #regd ", %0" \ + : "=X" (mmx_trace) \ + : /* nothing */ ); \ + fprintf(stderr, #regd "=0x%016llx\n", mmx_trace.q); \ + } + +#define mmx_m2m(op, mems, memd) \ + { \ + mmx_t mmx_trace; \ + mmx_trace = (mems); \ + fprintf(stderr, #op "_m2m(" #mems "=0x%016llx, ", mmx_trace.q); \ + mmx_trace = (memd); \ + fprintf(stderr, #memd "=0x%016llx) => ", mmx_trace.q); \ + __asm__ __volatile__ ("movq %0, %%mm0\n\t" \ + #op " %1, %%mm0\n\t" \ + "movq %%mm0, %0" \ + : "=X" (memd) \ + : "X" (mems)); \ + mmx_trace = (memd); \ + fprintf(stderr, #memd "=0x%016llx\n", mmx_trace.q); \ + } + +#else + +/* These macros are a lot simpler without the tracing... +*/ + +#define mmx_i2r(op, imm, reg) \ + __asm__ __volatile__ (#op " $" #imm ", %%" #reg \ + : /* nothing */ \ + : /* nothing */); + +#define mmx_m2r(op, mem, reg) \ + __asm__ __volatile__ (#op " %0, %%" #reg \ + : /* nothing */ \ + : "X" (mem)) + +#define mmx_r2m(op, reg, mem) \ + __asm__ __volatile__ (#op " %%" #reg ", %0" \ + : "=X" (mem) \ + : /* nothing */ ) + +#define mmx_r2r(op, regs, regd) \ + __asm__ __volatile__ (#op " %" #regs ", %" #regd) + +#define mmx_m2m(op, mems, memd) \ + __asm__ __volatile__ ("movq %0, %%mm0\n\t" \ + #op " %1, %%mm0\n\t" \ + "movq %%mm0, %0" \ + : "=X" (memd) \ + : "X" (mems)) + +#endif + + +/* 1x64 MOVe Quadword + (this is both a load and a store... + in fact, it is the only way to store) +*/ +#define movq_m2r(var, reg) mmx_m2r(movq, var, reg) +#define movq_r2m(reg, var) mmx_r2m(movq, reg, var) +#define movq_r2r(regs, regd) mmx_r2r(movq, regs, regd) +#define movq(vars, vard) \ + __asm__ __volatile__ ("movq %1, %%mm0\n\t" \ + "movq %%mm0, %0" \ + : "=X" (vard) \ + : "X" (vars)) + + +/* 1x32 MOVe Doubleword + (like movq, this is both load and store... + but is most useful for moving things between + mmx registers and ordinary registers) +*/ +#define movd_m2r(var, reg) mmx_m2r(movd, var, reg) +#define movd_r2m(reg, var) mmx_r2m(movd, reg, var) +#define movd_r2r(regs, regd) mmx_r2r(movd, regs, regd) +#define movd(vars, vard) \ + __asm__ __volatile__ ("movd %1, %%mm0\n\t" \ + "movd %%mm0, %0" \ + : "=X" (vard) \ + : "X" (vars)) + + +/* 2x32, 4x16, and 8x8 Parallel ADDs +*/ +#define paddd_m2r(var, reg) mmx_m2r(paddd, var, reg) +#define paddd_r2r(regs, regd) mmx_r2r(paddd, regs, regd) +#define paddd(vars, vard) mmx_m2m(paddd, vars, vard) + +#define paddw_m2r(var, reg) mmx_m2r(paddw, var, reg) +#define paddw_r2r(regs, regd) mmx_r2r(paddw, regs, regd) +#define paddw(vars, vard) mmx_m2m(paddw, vars, vard) + +#define paddb_m2r(var, reg) mmx_m2r(paddb, var, reg) +#define paddb_r2r(regs, regd) mmx_r2r(paddb, regs, regd) +#define paddb(vars, vard) mmx_m2m(paddb, vars, vard) + + +/* 4x16 and 8x8 Parallel ADDs using Saturation arithmetic +*/ +#define paddsw_m2r(var, reg) mmx_m2r(paddsw, var, reg) +#define paddsw_r2r(regs, regd) mmx_r2r(paddsw, regs, regd) +#define paddsw(vars, vard) mmx_m2m(paddsw, vars, vard) + +#define paddsb_m2r(var, reg) mmx_m2r(paddsb, var, reg) +#define paddsb_r2r(regs, regd) mmx_r2r(paddsb, regs, regd) +#define paddsb(vars, vard) mmx_m2m(paddsb, vars, vard) + + +/* 4x16 and 8x8 Parallel ADDs using Unsigned Saturation arithmetic +*/ +#define paddusw_m2r(var, reg) mmx_m2r(paddusw, var, reg) +#define paddusw_r2r(regs, regd) mmx_r2r(paddusw, regs, regd) +#define paddusw(vars, vard) mmx_m2m(paddusw, vars, vard) + +#define paddusb_m2r(var, reg) mmx_m2r(paddusb, var, reg) +#define paddusb_r2r(regs, regd) mmx_r2r(paddusb, regs, regd) +#define paddusb(vars, vard) mmx_m2m(paddusb, vars, vard) + + +/* 2x32, 4x16, and 8x8 Parallel SUBs +*/ +#define psubd_m2r(var, reg) mmx_m2r(psubd, var, reg) +#define psubd_r2r(regs, regd) mmx_r2r(psubd, regs, regd) +#define psubd(vars, vard) mmx_m2m(psubd, vars, vard) + +#define psubw_m2r(var, reg) mmx_m2r(psubw, var, reg) +#define psubw_r2r(regs, regd) mmx_r2r(psubw, regs, regd) +#define psubw(vars, vard) mmx_m2m(psubw, vars, vard) + +#define psubb_m2r(var, reg) mmx_m2r(psubb, var, reg) +#define psubb_r2r(regs, regd) mmx_r2r(psubb, regs, regd) +#define psubb(vars, vard) mmx_m2m(psubb, vars, vard) + + +/* 4x16 and 8x8 Parallel SUBs using Saturation arithmetic +*/ +#define psubsw_m2r(var, reg) mmx_m2r(psubsw, var, reg) +#define psubsw_r2r(regs, regd) mmx_r2r(psubsw, regs, regd) +#define psubsw(vars, vard) mmx_m2m(psubsw, vars, vard) + +#define psubsb_m2r(var, reg) mmx_m2r(psubsb, var, reg) +#define psubsb_r2r(regs, regd) mmx_r2r(psubsb, regs, regd) +#define psubsb(vars, vard) mmx_m2m(psubsb, vars, vard) + + +/* 4x16 and 8x8 Parallel SUBs using Unsigned Saturation arithmetic +*/ +#define psubusw_m2r(var, reg) mmx_m2r(psubusw, var, reg) +#define psubusw_r2r(regs, regd) mmx_r2r(psubusw, regs, regd) +#define psubusw(vars, vard) mmx_m2m(psubusw, vars, vard) + +#define psubusb_m2r(var, reg) mmx_m2r(psubusb, var, reg) +#define psubusb_r2r(regs, regd) mmx_r2r(psubusb, regs, regd) +#define psubusb(vars, vard) mmx_m2m(psubusb, vars, vard) + + +/* 4x16 Parallel MULs giving Low 4x16 portions of results +*/ +#define pmullw_m2r(var, reg) mmx_m2r(pmullw, var, reg) +#define pmullw_r2r(regs, regd) mmx_r2r(pmullw, regs, regd) +#define pmullw(vars, vard) mmx_m2m(pmullw, vars, vard) + + +/* 4x16 Parallel MULs giving High 4x16 portions of results +*/ +#define pmulhw_m2r(var, reg) mmx_m2r(pmulhw, var, reg) +#define pmulhw_r2r(regs, regd) mmx_r2r(pmulhw, regs, regd) +#define pmulhw(vars, vard) mmx_m2m(pmulhw, vars, vard) + + +/* 4x16->2x32 Parallel Mul-ADD + (muls like pmullw, then adds adjacent 16-bit fields + in the multiply result to make the final 2x32 result) +*/ +#define pmaddwd_m2r(var, reg) mmx_m2r(pmaddwd, var, reg) +#define pmaddwd_r2r(regs, regd) mmx_r2r(pmaddwd, regs, regd) +#define pmaddwd(vars, vard) mmx_m2m(pmaddwd, vars, vard) + + +/* 1x64 bitwise AND +*/ +#ifdef BROKEN_PAND +#define pand_m2r(var, reg) \ + { \ + mmx_m2r(pandn, (mmx_t) -1LL, reg); \ + mmx_m2r(pandn, var, reg); \ + } +#define pand_r2r(regs, regd) \ + { \ + mmx_m2r(pandn, (mmx_t) -1LL, regd); \ + mmx_r2r(pandn, regs, regd) \ + } +#define pand(vars, vard) \ + { \ + movq_m2r(vard, mm0); \ + mmx_m2r(pandn, (mmx_t) -1LL, mm0); \ + mmx_m2r(pandn, vars, mm0); \ + movq_r2m(mm0, vard); \ + } +#else +#define pand_m2r(var, reg) mmx_m2r(pand, var, reg) +#define pand_r2r(regs, regd) mmx_r2r(pand, regs, regd) +#define pand(vars, vard) mmx_m2m(pand, vars, vard) +#endif + + +/* 1x64 bitwise AND with Not the destination +*/ +#define pandn_m2r(var, reg) mmx_m2r(pandn, var, reg) +#define pandn_r2r(regs, regd) mmx_r2r(pandn, regs, regd) +#define pandn(vars, vard) mmx_m2m(pandn, vars, vard) + + +/* 1x64 bitwise OR +*/ +#define por_m2r(var, reg) mmx_m2r(por, var, reg) +#define por_r2r(regs, regd) mmx_r2r(por, regs, regd) +#define por(vars, vard) mmx_m2m(por, vars, vard) + + +/* 1x64 bitwise eXclusive OR +*/ +#define pxor_m2r(var, reg) mmx_m2r(pxor, var, reg) +#define pxor_r2r(regs, regd) mmx_r2r(pxor, regs, regd) +#define pxor(vars, vard) mmx_m2m(pxor, vars, vard) + + +/* 2x32, 4x16, and 8x8 Parallel CoMPare for EQuality + (resulting fields are either 0 or -1) +*/ +#define pcmpeqd_m2r(var, reg) mmx_m2r(pcmpeqd, var, reg) +#define pcmpeqd_r2r(regs, regd) mmx_r2r(pcmpeqd, regs, regd) +#define pcmpeqd(vars, vard) mmx_m2m(pcmpeqd, vars, vard) + +#define pcmpeqw_m2r(var, reg) mmx_m2r(pcmpeqw, var, reg) +#define pcmpeqw_r2r(regs, regd) mmx_r2r(pcmpeqw, regs, regd) +#define pcmpeqw(vars, vard) mmx_m2m(pcmpeqw, vars, vard) + +#define pcmpeqb_m2r(var, reg) mmx_m2r(pcmpeqb, var, reg) +#define pcmpeqb_r2r(regs, regd) mmx_r2r(pcmpeqb, regs, regd) +#define pcmpeqb(vars, vard) mmx_m2m(pcmpeqb, vars, vard) + + +/* 2x32, 4x16, and 8x8 Parallel CoMPare for Greater Than + (resulting fields are either 0 or -1) +*/ +#define pcmpgtd_m2r(var, reg) mmx_m2r(pcmpgtd, var, reg) +#define pcmpgtd_r2r(regs, regd) mmx_r2r(pcmpgtd, regs, regd) +#define pcmpgtd(vars, vard) mmx_m2m(pcmpgtd, vars, vard) + +#define pcmpgtw_m2r(var, reg) mmx_m2r(pcmpgtw, var, reg) +#define pcmpgtw_r2r(regs, regd) mmx_r2r(pcmpgtw, regs, regd) +#define pcmpgtw(vars, vard) mmx_m2m(pcmpgtw, vars, vard) + +#define pcmpgtb_m2r(var, reg) mmx_m2r(pcmpgtb, var, reg) +#define pcmpgtb_r2r(regs, regd) mmx_r2r(pcmpgtb, regs, regd) +#define pcmpgtb(vars, vard) mmx_m2m(pcmpgtb, vars, vard) + + +/* 1x64, 2x32, and 4x16 Parallel Shift Left Logical +*/ +#define psllq_i2r(imm, reg) mmx_i2r(psllq, imm, reg) +#define psllq_m2r(var, reg) mmx_m2r(psllq, var, reg) +#define psllq_r2r(regs, regd) mmx_r2r(psllq, regs, regd) +#define psllq(vars, vard) mmx_m2m(psllq, vars, vard) + +#define pslld_i2r(imm, reg) mmx_i2r(pslld, imm, reg) +#define pslld_m2r(var, reg) mmx_m2r(pslld, var, reg) +#define pslld_r2r(regs, regd) mmx_r2r(pslld, regs, regd) +#define pslld(vars, vard) mmx_m2m(pslld, vars, vard) + +#define psllw_i2r(imm, reg) mmx_i2r(psllw, imm, reg) +#define psllw_m2r(var, reg) mmx_m2r(psllw, var, reg) +#define psllw_r2r(regs, regd) mmx_r2r(psllw, regs, regd) +#define psllw(vars, vard) mmx_m2m(psllw, vars, vard) + + +/* 1x64, 2x32, and 4x16 Parallel Shift Right Logical +*/ +#define psrlq_i2r(imm, reg) mmx_i2r(psrlq, imm, reg) +#define psrlq_m2r(var, reg) mmx_m2r(psrlq, var, reg) +#define psrlq_r2r(regs, regd) mmx_r2r(psrlq, regs, regd) +#define psrlq(vars, vard) mmx_m2m(psrlq, vars, vard) + +#define psrld_i2r(imm, reg) mmx_i2r(psrld, imm, reg) +#define psrld_m2r(var, reg) mmx_m2r(psrld, var, reg) +#define psrld_r2r(regs, regd) mmx_r2r(psrld, regs, regd) +#define psrld(vars, vard) mmx_m2m(psrld, vars, vard) + +#define psrlw_i2r(imm, reg) mmx_i2r(psrlw, imm, reg) +#define psrlw_m2r(var, reg) mmx_m2r(psrlw, var, reg) +#define psrlw_r2r(regs, regd) mmx_r2r(psrlw, regs, regd) +#define psrlw(vars, vard) mmx_m2m(psrlw, vars, vard) + + +/* 2x32 and 4x16 Parallel Shift Right Arithmetic +*/ +#define psrad_i2r(imm, reg) mmx_i2r(psrad, imm, reg) +#define psrad_m2r(var, reg) mmx_m2r(psrad, var, reg) +#define psrad_r2r(regs, regd) mmx_r2r(psrad, regs, regd) +#define psrad(vars, vard) mmx_m2m(psrad, vars, vard) + +#define psraw_i2r(imm, reg) mmx_i2r(psraw, imm, reg) +#define psraw_m2r(var, reg) mmx_m2r(psraw, var, reg) +#define psraw_r2r(regs, regd) mmx_r2r(psraw, regs, regd) +#define psraw(vars, vard) mmx_m2m(psraw, vars, vard) + + +/* 2x32->4x16 and 4x16->8x8 PACK and Signed Saturate + (packs source and dest fields into dest in that order) +*/ +#define packssdw_m2r(var, reg) mmx_m2r(packssdw, var, reg) +#define packssdw_r2r(regs, regd) mmx_r2r(packssdw, regs, regd) +#define packssdw(vars, vard) mmx_m2m(packssdw, vars, vard) + +#define packsswb_m2r(var, reg) mmx_m2r(packsswb, var, reg) +#define packsswb_r2r(regs, regd) mmx_r2r(packsswb, regs, regd) +#define packsswb(vars, vard) mmx_m2m(packsswb, vars, vard) + + +/* 4x16->8x8 PACK and Unsigned Saturate + (packs source and dest fields into dest in that order) +*/ +#define packuswb_m2r(var, reg) mmx_m2r(packuswb, var, reg) +#define packuswb_r2r(regs, regd) mmx_r2r(packuswb, regs, regd) +#define packuswb(vars, vard) mmx_m2m(packuswb, vars, vard) + + +/* 2x32->1x64, 4x16->2x32, and 8x8->4x16 UNPaCK Low + (interleaves low half of dest with low half of source + as padding in each result field) +*/ +#define punpckldq_m2r(var, reg) mmx_m2r(punpckldq, var, reg) +#define punpckldq_r2r(regs, regd) mmx_r2r(punpckldq, regs, regd) +#define punpckldq(vars, vard) mmx_m2m(punpckldq, vars, vard) + +#define punpcklwd_m2r(var, reg) mmx_m2r(punpcklwd, var, reg) +#define punpcklwd_r2r(regs, regd) mmx_r2r(punpcklwd, regs, regd) +#define punpcklwd(vars, vard) mmx_m2m(punpcklwd, vars, vard) + +#define punpcklbw_m2r(var, reg) mmx_m2r(punpcklbw, var, reg) +#define punpcklbw_r2r(regs, regd) mmx_r2r(punpcklbw, regs, regd) +#define punpcklbw(vars, vard) mmx_m2m(punpcklbw, vars, vard) + + +/* 2x32->1x64, 4x16->2x32, and 8x8->4x16 UNPaCK High + (interleaves high half of dest with high half of source + as padding in each result field) +*/ +#define punpckhdq_m2r(var, reg) mmx_m2r(punpckhdq, var, reg) +#define punpckhdq_r2r(regs, regd) mmx_r2r(punpckhdq, regs, regd) +#define punpckhdq(vars, vard) mmx_m2m(punpckhdq, vars, vard) + +#define punpckhwd_m2r(var, reg) mmx_m2r(punpckhwd, var, reg) +#define punpckhwd_r2r(regs, regd) mmx_r2r(punpckhwd, regs, regd) +#define punpckhwd(vars, vard) mmx_m2m(punpckhwd, vars, vard) + +#define punpckhbw_m2r(var, reg) mmx_m2r(punpckhbw, var, reg) +#define punpckhbw_r2r(regs, regd) mmx_r2r(punpckhbw, regs, regd) +#define punpckhbw(vars, vard) mmx_m2m(punpckhbw, vars, vard) + + +/* Empty MMx State + (used to clean-up when going from mmx to float use + of the registers that are shared by both; note that + there is no float-to-mmx operation needed, because + only the float tag word info is corruptible) +*/ +#ifdef MMX_TRACE + +#define emms() \ + { \ + fprintf(stderr, "emms()\n"); \ + __asm__ __volatile__ ("emms"); \ + } + +#else + +#define emms() __asm__ __volatile__ ("emms") + +#endif + +#endif + diff --git a/src/mesa/drivers/dri/common/spantmp.h b/src/mesa/drivers/dri/common/spantmp.h new file mode 100644 index 0000000..f0af5b1 --- /dev/null +++ b/src/mesa/drivers/dri/common/spantmp.h @@ -0,0 +1,325 @@ +/* + * Copyright 2000-2001 VA Linux Systems, Inc. + * (C) Copyright IBM Corporation 2002, 2003 + * 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 + * 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 + * VA LINUX SYSTEM, IBM 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. + * + * Authors: + * Keith Whitwell + * Gareth Hughes + */ + +#include "spantmp_common.h" + +#ifndef DBG +#define DBG 0 +#endif + +#ifndef HW_READ_CLIPLOOP +#define HW_READ_CLIPLOOP() HW_CLIPLOOP() +#endif + +#ifndef HW_WRITE_CLIPLOOP +#define HW_WRITE_CLIPLOOP() HW_CLIPLOOP() +#endif + + +static void TAG(WriteRGBASpan)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, GLint x, GLint y, + const void *values, const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values; + GLint x1; + GLint n1; + LOCAL_VARS; + + y = Y_FLIP(y); + + HW_WRITE_CLIPLOOP() + { + GLint i = 0; + CLIPSPAN(x,y,n,x1,n1,i); + + if (DBG) fprintf(stderr, "WriteRGBASpan %d..%d (x1 %d)\n", + (int)i, (int)n1, (int)x1); + + if (mask) + { + for (;n1>0;i++,x1++,n1--) + if (mask[i]) + WRITE_RGBA( x1, y, + rgba[i][0], rgba[i][1], + rgba[i][2], rgba[i][3] ); + } + else + { + for (;n1>0;i++,x1++,n1--) + WRITE_RGBA( x1, y, + rgba[i][0], rgba[i][1], + rgba[i][2], rgba[i][3] ); + } + } + HW_ENDCLIPLOOP(); + } + HW_WRITE_UNLOCK(); +} + +static void TAG(WriteRGBSpan)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, GLint x, GLint y, + const void *values, const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values; + GLint x1; + GLint n1; + LOCAL_VARS; + + y = Y_FLIP(y); + + HW_WRITE_CLIPLOOP() + { + GLint i = 0; + CLIPSPAN(x,y,n,x1,n1,i); + + if (DBG) fprintf(stderr, "WriteRGBSpan %d..%d (x1 %d)\n", + (int)i, (int)n1, (int)x1); + + if (mask) + { + for (;n1>0;i++,x1++,n1--) + if (mask[i]) + WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 ); + } + else + { + for (;n1>0;i++,x1++,n1--) + WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 ); + } + } + HW_ENDCLIPLOOP(); + } + HW_WRITE_UNLOCK(); +} + +static void TAG(WriteRGBAPixels)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, const GLint x[], const GLint y[], + const void *values, const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values; + GLuint i; + LOCAL_VARS; + + if (DBG) fprintf(stderr, "WriteRGBAPixels\n"); + + HW_WRITE_CLIPLOOP() + { + if (mask) + { + for (i=0;i0;i++,x1++,n1--) + if (mask[i]) + WRITE_PIXEL( x1, y, p ); + } + else + { + for (;n1>0;i++,x1++,n1--) + WRITE_PIXEL( x1, y, p ); + } + } + HW_ENDCLIPLOOP(); + } + HW_WRITE_UNLOCK(); +} + + +static void TAG(WriteMonoRGBAPixels)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, + const GLint x[], const GLint y[], + const void *value, + const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + const GLubyte *color = (const GLubyte *) value; + GLuint i; + LOCAL_VARS; + INIT_MONO_PIXEL(p, color); + + if (DBG) fprintf(stderr, "WriteMonoRGBAPixels\n"); + + HW_WRITE_CLIPLOOP() + { + if (mask) + { + for (i=0;i0;i++,x1++,n1--) + READ_RGBA( rgba[i], x1, y ); + } + HW_ENDCLIPLOOP(); + } + HW_READ_UNLOCK(); +} + + +static void TAG(ReadRGBAPixels)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, const GLint x[], const GLint y[], + void *values ) +{ + HW_READ_LOCK() + { + GLubyte (*rgba)[4] = (GLubyte (*)[4]) values; + GLuint i; + LOCAL_VARS; + + if (DBG) fprintf(stderr, "ReadRGBAPixels\n"); + + HW_READ_CLIPLOOP() + { + for (i=0;iPutRow = TAG(WriteRGBASpan); + rb->PutRowRGB = TAG(WriteRGBSpan); + rb->PutMonoRow = TAG(WriteMonoRGBASpan); + rb->PutValues = TAG(WriteRGBAPixels); + rb->PutMonoValues = TAG(WriteMonoRGBAPixels); + rb->GetValues = TAG(ReadRGBAPixels); + rb->GetRow = TAG(ReadRGBASpan); +} + + +#undef WRITE_PIXEL +#undef WRITE_RGBA +#undef READ_RGBA +#undef TAG diff --git a/src/mesa/drivers/dri/common/spantmp2.h b/src/mesa/drivers/dri/common/spantmp2.h new file mode 100644 index 0000000..f436d13 --- /dev/null +++ b/src/mesa/drivers/dri/common/spantmp2.h @@ -0,0 +1,1038 @@ +/* + * Copyright 2000-2001 VA Linux Systems, Inc. + * (C) Copyright IBM Corporation 2004 + * 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 + * 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 + * VA LINUX SYSTEM, IBM 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. + */ + +/** + * \file spantmp2.h + * + * Template file of span read / write functions. + * + * \author Keith Whitwell + * \author Gareth Hughes + * \author Ian Romanick + */ + +#include "main/colormac.h" +#include "spantmp_common.h" + +#ifndef DBG +#define DBG 0 +#endif + +#ifndef HW_READ_CLIPLOOP +#define HW_READ_CLIPLOOP() HW_CLIPLOOP() +#endif + +#ifndef HW_WRITE_CLIPLOOP +#define HW_WRITE_CLIPLOOP() HW_CLIPLOOP() +#endif + +#ifdef SPANTMP_MESA_FMT +#define SPANTMP_PIXEL_FMT GL_NONE +#define SPANTMP_PIXEL_TYPE GL_NONE +#endif + +#ifndef SPANTMP_MESA_FMT +#define SPANTMP_MESA_FMT MESA_FORMAT_COUNT +#endif + +#if (SPANTMP_PIXEL_FMT == GL_RGB) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5) + +/** + ** GL_RGB, GL_UNSIGNED_SHORT_5_6_5 + **/ + +#ifndef GET_VALUE +#ifndef GET_PTR +#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch) +#endif + +#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y)) +#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v) +#endif /* GET_VALUE */ + +#define INIT_MONO_PIXEL(p, color) \ + p = PACK_COLOR_565( color[0], color[1], color[2] ) + +#define WRITE_RGBA( _x, _y, r, g, b, a ) \ + PUT_VALUE(_x, _y, ((((int)r & 0xf8) << 8) | \ + (((int)g & 0xfc) << 3) | \ + (((int)b & 0xf8) >> 3))) \ + +#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p) + +#define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLushort p = GET_VALUE(_x, _y); \ + rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8; \ + rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc; \ + rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \ + rgba[3] = 0xff; \ + } while (0) + +#elif (SPANTMP_PIXEL_FMT == GL_RGB) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5_REV) + +/** + ** GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV + **/ + +#ifndef GET_VALUE +#ifndef GET_PTR +#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch) +#endif + +#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y)) +#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v) +#endif /* GET_VALUE */ + +#define INIT_MONO_PIXEL(p, color) \ + p = PACK_COLOR_565_REV( color[0], color[1], color[2] ) + +#define WRITE_RGBA( _x, _y, r, g, b, a ) \ + PUT_VALUE(_x, _y, PACK_COLOR_565_REV( r, g, b )) + +#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p) + +#define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLushort p = GET_VALUE(_x, _y); \ + p = p << 8 | p >> 8; \ + rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8; \ + rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc; \ + rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \ + rgba[3] = 0xff; \ + } while (0) + +#elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_4_4_4_4) + +/** + ** GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4 + **/ + +#ifndef GET_VALUE +#ifndef GET_PTR +#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch) +#endif + +#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y)) +#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v) +#endif /* GET_VALUE */ + +#define INIT_MONO_PIXEL(p, color) \ + p = PACK_COLOR_4444_REV(color[3], color[0], color[1], color[2]) + +#define WRITE_RGBA( _x, _y, r, g, b, a ) \ + PUT_VALUE(_x, _y, PACK_COLOR_4444_REV(a, r, g, b)) \ + +#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p) + +#define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLushort p = GET_VALUE(_x, _y); \ + rgba[0] = ((p >> 0) & 0xf) * 0x11; \ + rgba[1] = ((p >> 12) & 0xf) * 0x11; \ + rgba[2] = ((p >> 4) & 0xf) * 0x11; \ + rgba[3] = ((p >> 8) & 0xf) * 0x11; \ + } while (0) + + +#elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_4_4_4_4_REV) + +/** + ** GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV + **/ + +#ifndef GET_VALUE +#ifndef GET_PTR +#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch) +#endif + +#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y)) +#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v) +#endif /* GET_VALUE */ + +#define INIT_MONO_PIXEL(p, color) \ + p = PACK_COLOR_4444(color[3], color[0], color[1], color[2]) + +#define WRITE_RGBA( _x, _y, r, g, b, a ) \ + PUT_VALUE(_x, _y, PACK_COLOR_4444(a, r, g, b)) \ + +#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p) + +#define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLushort p = GET_VALUE(_x, _y); \ + rgba[0] = ((p >> 8) & 0xf) * 0x11; \ + rgba[1] = ((p >> 4) & 0xf) * 0x11; \ + rgba[2] = ((p >> 0) & 0xf) * 0x11; \ + rgba[3] = ((p >> 12) & 0xf) * 0x11; \ + } while (0) + + +#elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_1_5_5_5_REV) + +/** + ** GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV + **/ + +#ifndef GET_VALUE +#ifndef GET_PTR +#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch) +#endif + +#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y)) +#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v) +#endif /* GET_VALUE */ + +#define INIT_MONO_PIXEL(p, color) \ + p = PACK_COLOR_1555(color[3], color[0], color[1], color[2]) + +#define WRITE_RGBA( _x, _y, r, g, b, a ) \ + PUT_VALUE(_x, _y, PACK_COLOR_1555(a, r, g, b)) \ + +#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p) + +#define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLushort p = GET_VALUE(_x, _y); \ + rgba[0] = ((p >> 7) & 0xf8) * 255 / 0xf8; \ + rgba[1] = ((p >> 2) & 0xf8) * 255 / 0xf8; \ + rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \ + rgba[3] = ((p >> 15) & 0x1) * 0xff; \ + } while (0) + +#elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_1_5_5_5) + +/** + ** GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5 + **/ + +#ifndef GET_VALUE +#ifndef GET_PTR +#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch) +#endif + +#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y)) +#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v) +#endif /* GET_VALUE */ + +#define INIT_MONO_PIXEL(p, color) \ + p = PACK_COLOR_1555_REV(color[3], color[0], color[1], color[2]) + +#define WRITE_RGBA( _x, _y, r, g, b, a ) \ + PUT_VALUE(_x, _y, PACK_COLOR_1555_REV(a, r, g, b)) \ + +#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p) + +#define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLushort p = GET_VALUE(_x, _y); \ + p = p << 8 | p >> 8; \ + rgba[0] = ((p >> 7) & 0xf8) * 255 / 0xf8; \ + rgba[1] = ((p >> 2) & 0xf8) * 255 / 0xf8; \ + rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \ + rgba[3] = ((p >> 15) & 0x1) * 0xff; \ + } while (0) + +#elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV) + +/** + ** GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV + **/ + +#ifndef GET_VALUE +#ifndef GET_PTR +#define GET_PTR(_x, _y) ( buf + (_x) * 4 + (_y) * pitch) +#endif + +#define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y)) +#define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v) +#endif /* GET_VALUE */ + +# define INIT_MONO_PIXEL(p, color) \ + p = PACK_COLOR_8888(color[3], color[0], color[1], color[2]) + +# define WRITE_RGBA(_x, _y, r, g, b, a) \ + PUT_VALUE(_x, _y, ((r << 16) | \ + (g << 8) | \ + (b << 0) | \ + (a << 24))) + +#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p) + +# if defined( USE_X86_ASM ) +# define READ_RGBA(rgba, _x, _y) \ + do { \ + GLuint p = GET_VALUE(_x, _y); \ + __asm__ __volatile__( "bswap %0; rorl $8, %0" \ + : "=r" (p) : "0" (p) ); \ + ((GLuint *)rgba)[0] = p; \ + } while (0) +# elif defined( MESA_BIG_ENDIAN ) + /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single + * rotlwi instruction. It also produces good code on SPARC. + */ +# define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLuint p = GET_VALUE(_x, _y); \ + GLuint t = p; \ + *((uint32_t *) rgba) = (t >> 24) | (p << 8); \ + } while (0) +# else +# define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLuint p = GET_VALUE(_x, _y); \ + rgba[0] = (p >> 16) & 0xff; \ + rgba[1] = (p >> 8) & 0xff; \ + rgba[2] = (p >> 0) & 0xff; \ + rgba[3] = (p >> 24) & 0xff; \ + } while (0) +# endif + +#elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8) + +/** + ** GL_BGRA, GL_UNSIGNED_INT_8_8_8_8 + **/ + +#ifndef GET_VALUE +#ifndef GET_PTR +#define GET_PTR(_x, _y) ( buf + (_x) * 4 + (_y) * pitch) +#endif + +#define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y)) +#define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v) +#endif /* GET_VALUE */ + +# define INIT_MONO_PIXEL(p, color) \ + p = PACK_COLOR_8888(color[2], color[1], color[0], color[3]) + +# define WRITE_RGBA(_x, _y, r, g, b, a) \ + PUT_VALUE(_x, _y, ((r << 8) | \ + (g << 16) | \ + (b << 24) | \ + (a << 0))) + +#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p) + +# if defined( USE_X86_ASM ) +# define READ_RGBA(rgba, _x, _y) \ + do { \ + GLuint p = GET_VALUE(_x, _y); \ + __asm__ __volatile__( "rorl $8, %0" \ + : "=r" (p) : "0" (p) ); \ + ((GLuint *)rgba)[0] = p; \ + } while (0) +# elif defined( MESA_BIG_ENDIAN ) + /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single + * rotlwi instruction. It also produces good code on SPARC. + */ +# define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLuint p = CPU_TO_LE32(GET_VALUE(_x, _y)); \ + GLuint t = p; \ + *((uint32_t *) rgba) = (t >> 24) | (p << 8); \ + } while (0) +# else +# define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLuint p = GET_VALUE(_x, _y); \ + rgba[0] = (p >> 8) & 0xff; \ + rgba[1] = (p >> 16) & 0xff; \ + rgba[2] = (p >> 24) & 0xff; \ + rgba[3] = (p >> 0) & 0xff; \ + } while (0) +# endif + +#elif (SPANTMP_PIXEL_FMT == GL_BGR) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV) + +/** + ** GL_BGR, GL_UNSIGNED_INT_8_8_8_8_REV + ** + ** This is really for MESA_FORMAT_XRGB8888. The spantmp code needs to be + ** kicked to the curb, and we need to just code-gen this. + **/ + +#ifndef GET_VALUE +#ifndef GET_PTR +#define GET_PTR(_x, _y) ( buf + (_x) * 4 + (_y) * pitch) +#endif + +#define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y)) +#define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v) +#endif /* GET_VALUE */ + +# define INIT_MONO_PIXEL(p, color) \ + p = PACK_COLOR_8888(0xff, color[0], color[1], color[2]) + +# define WRITE_RGBA(_x, _y, r, g, b, a) \ + PUT_VALUE(_x, _y, ((r << 16) | \ + (g << 8) | \ + (b << 0) | \ + (0xff << 24))) + +#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p) + +# if defined( USE_X86_ASM ) +# define READ_RGBA(rgba, _x, _y) \ + do { \ + GLuint p = GET_VALUE(_x, _y); \ + __asm__ __volatile__( "bswap %0; rorl $8, %0" \ + : "=r" (p) : "0" (p) ); \ + ((GLuint *)rgba)[0] = p | 0xff000000; \ + } while (0) +# elif defined( MESA_BIG_ENDIAN ) + /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single + * rotlwi instruction. It also produces good code on SPARC. + */ +# define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLuint p = GET_VALUE(_x, _y); \ + *((uint32_t *) rgba) = (p << 8) | 0xff; \ + } while (0) +# else +# define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLuint p = GET_VALUE(_x, _y); \ + rgba[0] = (p >> 16) & 0xff; \ + rgba[1] = (p >> 8) & 0xff; \ + rgba[2] = (p >> 0) & 0xff; \ + rgba[3] = 0xff; \ + } while (0) +# endif + +#elif (SPANTMP_PIXEL_FMT == GL_ALPHA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_BYTE) + +/** + ** GL_ALPHA, GL_UNSIGNED_BYTE + **/ + +#ifndef GET_VALUE +#ifndef GET_PTR +#define GET_PTR(_x, _y) ( buf + (_x) + (_y) * pitch) +#endif + +#define GET_VALUE(_x, _y) *(volatile GLubyte *)(GET_PTR(_x, _y)) +#define PUT_VALUE(_x, _y, _v) *(volatile GLubyte *)(GET_PTR(_x, _y)) = (_v) +#endif /* GET_VALUE */ + +# define INIT_MONO_PIXEL(p, color) \ + p = color[3] + +# define WRITE_RGBA(_x, _y, r, g, b, a) \ + PUT_VALUE(_x, _y, a | (r & 0 /* quiet warnings */)) + +#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p) + +#define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLubyte p = GET_VALUE(_x, _y); \ + rgba[0] = 0; \ + rgba[1] = 0; \ + rgba[2] = 0; \ + rgba[3] = p; \ + } while (0) + +#elif (SPANTMP_MESA_FMT == MESA_FORMAT_R8) + +#ifndef GET_VALUE +#ifndef GET_PTR +#define GET_PTR(_x, _y) ( buf + (_x) + (_y) * pitch) +#endif + +#define GET_VALUE(_x, _y) *(volatile GLubyte *)(GET_PTR(_x, _y)) +#define PUT_VALUE(_x, _y, _v) *(volatile GLubyte *)(GET_PTR(_x, _y)) = (_v) +#endif /* GET_VALUE */ + +# define INIT_MONO_PIXEL(p, color) \ + p = color[0] + +# define WRITE_RGBA(_x, _y, r, g, b, a) \ + PUT_VALUE(_x, _y, r) + +#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p) + +#define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLubyte p = GET_VALUE(_x, _y); \ + rgba[0] = p; \ + rgba[1] = 0; \ + rgba[2] = 0; \ + rgba[3] = 0; \ + } while (0) + +#elif (SPANTMP_MESA_FMT == MESA_FORMAT_RG88) + +#ifndef GET_VALUE +#ifndef GET_PTR +#define GET_PTR(_x, _y) ( buf + (_x) * 2 + (_y) * pitch) +#endif + +#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y)) +#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v) +#endif /* GET_VALUE */ + +# define INIT_MONO_PIXEL(p, color) \ + PACK_COLOR_8888(color[0], color[1], 0, 0) + +# define WRITE_RGBA(_x, _y, r, g, b, a) \ + PUT_VALUE(_x, _y, r) + +#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p) + +#define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLushort p = GET_VALUE(_x, _y); \ + rgba[0] = p & 0xff; \ + rgba[1] = (p >> 8) & 0xff; \ + rgba[2] = 0; \ + rgba[3] = 0; \ + } while (0) + +#elif (SPANTMP_MESA_FMT == MESA_FORMAT_R16) + +#ifndef GET_VALUE +#ifndef GET_PTR +#define GET_PTR(_x, _y) ( buf + (_x) * 2 + (_y) * pitch) +#endif + +#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y)) +#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v) +#endif /* GET_VALUE */ + +# define INIT_MONO_PIXEL(p, color) \ + p = color[0] + +# define WRITE_RGBA(_x, _y, r, g, b, a) \ + PUT_VALUE(_x, _y, r) + +#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p) + +#define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLushort p = GET_VALUE(_x, _y); \ + rgba[0] = p; \ + rgba[1] = 0; \ + rgba[2] = 0; \ + rgba[3] = 0; \ + } while (0) + +#elif (SPANTMP_MESA_FMT == MESA_FORMAT_RG1616) + +#ifndef GET_VALUE +#ifndef GET_PTR +#define GET_PTR(_x, _y) ( buf + (_x) * 4 + (_y) * pitch) +#endif + +#define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y)) +#define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v) +#endif /* GET_VALUE */ + +# define INIT_MONO_PIXEL(p, color) \ + ((color[1] << 16) | (color[0])) + +# define WRITE_RGBA(_x, _y, r, g, b, a) \ + PUT_VALUE(_x, _y, r) + +#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p) + +#define READ_RGBA( rgba, _x, _y ) \ + do { \ + GLuint p = GET_VALUE(_x, _y); \ + rgba[0] = p & 0xffff; \ + rgba[1] = (p >> 16) & 0xffff; \ + rgba[2] = 0; \ + rgba[3] = 0; \ + } while (0) + +#else +#error SPANTMP_PIXEL_FMT must be set to a valid value! +#endif + + + +/** + ** Assembly routines. + **/ + +#if defined( USE_MMX_ASM ) || defined( USE_SSE_ASM ) +#include "x86/read_rgba_span_x86.h" +#include "x86/common_x86_asm.h" +#endif + +static void TAG(WriteRGBASpan)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, GLint x, GLint y, + const void *values, const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values; + GLint x1; + GLint n1; + LOCAL_VARS; + + y = Y_FLIP(y); + + HW_WRITE_CLIPLOOP() + { + GLint i = 0; + CLIPSPAN(x,y,n,x1,n1,i); + + if (DBG) fprintf(stderr, "WriteRGBASpan %d..%d (x1 %d)\n", + (int)i, (int)n1, (int)x1); + + if (mask) + { + for (;n1>0;i++,x1++,n1--) + if (mask[i]) + WRITE_RGBA( x1, y, + rgba[i][0], rgba[i][1], + rgba[i][2], rgba[i][3] ); + } + else + { + for (;n1>0;i++,x1++,n1--) + WRITE_RGBA( x1, y, + rgba[i][0], rgba[i][1], + rgba[i][2], rgba[i][3] ); + } + } + HW_ENDCLIPLOOP(); + } + HW_WRITE_UNLOCK(); +} + +static void TAG(WriteRGBSpan)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, GLint x, GLint y, + const void *values, const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values; + GLint x1; + GLint n1; + LOCAL_VARS; + + y = Y_FLIP(y); + + HW_WRITE_CLIPLOOP() + { + GLint i = 0; + CLIPSPAN(x,y,n,x1,n1,i); + + if (DBG) fprintf(stderr, "WriteRGBSpan %d..%d (x1 %d)\n", + (int)i, (int)n1, (int)x1); + + if (mask) + { + for (;n1>0;i++,x1++,n1--) + if (mask[i]) + WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 ); + } + else + { + for (;n1>0;i++,x1++,n1--) + WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 ); + } + } + HW_ENDCLIPLOOP(); + } + HW_WRITE_UNLOCK(); +} + +static void TAG(WriteRGBAPixels)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, const GLint x[], const GLint y[], + const void *values, const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values; + GLint i; + LOCAL_VARS; + + if (DBG) fprintf(stderr, "WriteRGBAPixels\n"); + + HW_WRITE_CLIPLOOP() + { + if (mask) + { + for (i=0;i0;i++,x1++,n1--) + if (mask[i]) + WRITE_PIXEL( x1, y, p ); + } + else + { + for (;n1>0;i++,x1++,n1--) + WRITE_PIXEL( x1, y, p ); + } + } + HW_ENDCLIPLOOP(); + } + HW_WRITE_UNLOCK(); +} + + +static void TAG(WriteMonoRGBAPixels)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, + const GLint x[], const GLint y[], + const void *value, + const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + const GLubyte *color = (const GLubyte *) value; + GLint i; + LOCAL_VARS; + INIT_MONO_PIXEL(p, color); + + if (DBG) fprintf(stderr, "WriteMonoRGBAPixels\n"); + + HW_WRITE_CLIPLOOP() + { + if (mask) + { + for (i=0;i0;i++,x1++,n1--) + READ_RGBA( rgba[i], x1, y ); + } + HW_ENDCLIPLOOP(); + } + HW_READ_UNLOCK(); +} + + +#if defined(GET_PTR) && \ + defined(USE_MMX_ASM) && \ + (((SPANTMP_PIXEL_FMT == GL_BGRA) && \ + (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)) || \ + ((SPANTMP_PIXEL_FMT == GL_RGB) && \ + (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5))) +static void TAG2(ReadRGBASpan,_MMX)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, GLint x, GLint y, void *values) +{ +#ifndef USE_INNER_EMMS + /* The EMMS instruction is directly in-lined here because using GCC's + * built-in _mm_empty function was found to utterly destroy performance. + */ + __asm__ __volatile__( "emms" ); +#endif + + HW_READ_LOCK() + { + GLubyte (*rgba)[4] = (GLubyte (*)[4]) values; + GLint x1,n1; + LOCAL_VARS; + + y = Y_FLIP(y); + + if (DBG) fprintf(stderr, "ReadRGBASpan\n"); + + HW_READ_CLIPLOOP() + { + GLint i = 0; + CLIPSPAN(x,y,n,x1,n1,i); + + { + const void * src = GET_PTR( x1, y ); +#if (SPANTMP_PIXEL_FMT == GL_RGB) && \ + (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5) + _generic_read_RGBA_span_RGB565_MMX( src, rgba[i], n1 ); +#else + _generic_read_RGBA_span_BGRA8888_REV_MMX( src, rgba[i], n1 ); +#endif + } + } + HW_ENDCLIPLOOP(); + } + HW_READ_UNLOCK(); +#ifndef USE_INNER_EMMS + __asm__ __volatile__( "emms" ); +#endif +} +#endif + + +#if defined(GET_PTR) && \ + defined(USE_SSE_ASM) && \ + (SPANTMP_PIXEL_FMT == GL_BGRA) && \ + (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV) +static void TAG2(ReadRGBASpan,_SSE2)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, GLint x, GLint y, + void *values) +{ + HW_READ_LOCK() + { + GLubyte (*rgba)[4] = (GLubyte (*)[4]) values; + GLint x1,n1; + LOCAL_VARS; + + y = Y_FLIP(y); + + if (DBG) fprintf(stderr, "ReadRGBASpan\n"); + + HW_READ_CLIPLOOP() + { + GLint i = 0; + CLIPSPAN(x,y,n,x1,n1,i); + + { + const void * src = GET_PTR( x1, y ); + _generic_read_RGBA_span_BGRA8888_REV_SSE2( src, rgba[i], n1 ); + } + } + HW_ENDCLIPLOOP(); + } + HW_READ_UNLOCK(); +} +#endif + +#if defined(GET_PTR) && \ + defined(USE_SSE_ASM) && \ + (SPANTMP_PIXEL_FMT == GL_BGRA) && \ + (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV) +static void TAG2(ReadRGBASpan,_SSE)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, GLint x, GLint y, + void *values) +{ +#ifndef USE_INNER_EMMS + /* The EMMS instruction is directly in-lined here because using GCC's + * built-in _mm_empty function was found to utterly destroy performance. + */ + __asm__ __volatile__( "emms" ); +#endif + + HW_READ_LOCK() + { + GLubyte (*rgba)[4] = (GLubyte (*)[4]) values; + GLint x1,n1; + LOCAL_VARS; + + y = Y_FLIP(y); + + if (DBG) fprintf(stderr, "ReadRGBASpan\n"); + + HW_READ_CLIPLOOP() + { + GLint i = 0; + CLIPSPAN(x,y,n,x1,n1,i); + + { + const void * src = GET_PTR( x1, y ); + _generic_read_RGBA_span_BGRA8888_REV_SSE( src, rgba[i], n1 ); + } + } + HW_ENDCLIPLOOP(); + } + HW_READ_UNLOCK(); +#ifndef USE_INNER_EMMS + __asm__ __volatile__( "emms" ); +#endif +} +#endif + + +static void TAG(ReadRGBAPixels)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, const GLint x[], const GLint y[], + void *values ) +{ + HW_READ_LOCK() + { + GLubyte (*rgba)[4] = (GLubyte (*)[4]) values; + GLint i; + LOCAL_VARS; + + if (DBG) fprintf(stderr, "ReadRGBAPixels\n"); + + HW_READ_CLIPLOOP() + { + for (i=0;iPutRow = TAG(WriteRGBASpan); + rb->PutRowRGB = TAG(WriteRGBSpan); + rb->PutMonoRow = TAG(WriteMonoRGBASpan); + rb->PutValues = TAG(WriteRGBAPixels); + rb->PutMonoValues = TAG(WriteMonoRGBAPixels); + rb->GetValues = TAG(ReadRGBAPixels); + +#if defined(GET_PTR) +#if defined(USE_SSE_ASM) && \ + (SPANTMP_PIXEL_FMT == GL_BGRA) && \ + (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV) + if ( cpu_has_xmm2 ) { + if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "SSE2" ); + rb->GetRow = TAG2(ReadRGBASpan, _SSE2); + } + else +#endif +#if defined(USE_SSE_ASM) && \ + (SPANTMP_PIXEL_FMT == GL_BGRA) && \ + (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV) + if ( cpu_has_xmm ) { + if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "SSE" ); + rb->GetRow = TAG2(ReadRGBASpan, _SSE); + } + else +#endif +#if defined(USE_MMX_ASM) && \ + (((SPANTMP_PIXEL_FMT == GL_BGRA) && \ + (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)) || \ + ((SPANTMP_PIXEL_FMT == GL_RGB) && \ + (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5))) + if ( cpu_has_mmx ) { + if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "MMX" ); + rb->GetRow = TAG2(ReadRGBASpan, _MMX); + } + else +#endif +#endif /* GET_PTR */ + { + if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "C" ); + rb->GetRow = TAG(ReadRGBASpan); + } + +} + + +#undef INIT_MONO_PIXEL +#undef WRITE_PIXEL +#undef WRITE_RGBA +#undef READ_RGBA +#undef TAG +#undef TAG2 +#undef GET_VALUE +#undef PUT_VALUE +#undef GET_PTR +#undef SPANTMP_PIXEL_FMT +#undef SPANTMP_PIXEL_TYPE +#undef SPANTMP_MESA_FMT diff --git a/src/mesa/drivers/dri/common/spantmp_common.h b/src/mesa/drivers/dri/common/spantmp_common.h new file mode 100644 index 0000000..a4509a5 --- /dev/null +++ b/src/mesa/drivers/dri/common/spantmp_common.h @@ -0,0 +1,81 @@ +/* + * Copyright 2000-2001 VA Linux Systems, Inc. + * (C) Copyright IBM Corporation 2004 + * 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 + * 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 + * VA LINUX SYSTEM, IBM 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. + */ + +/** + * \file spantmp_common.h + * + * common macros for span read / write functions to be used in the depth, + * stencil and pixel span templates. + */ + +#ifndef HW_WRITE_LOCK +#define HW_WRITE_LOCK() HW_LOCK() +#endif + +#ifndef HW_WRITE_UNLOCK +#define HW_WRITE_UNLOCK() HW_UNLOCK() +#endif + +#ifndef HW_READ_LOCK +#define HW_READ_LOCK() HW_LOCK() +#endif + +#ifndef HW_READ_UNLOCK +#define HW_READ_UNLOCK() HW_UNLOCK() +#endif + +#ifndef HW_CLIPLOOP +#define HW_CLIPLOOP() \ + do { \ + int _nc = dPriv->numClipRects; \ + while ( _nc-- ) { \ + int minx = dPriv->pClipRects[_nc].x1 - dPriv->x; \ + int miny = dPriv->pClipRects[_nc].y1 - dPriv->y; \ + int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x; \ + int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y; +#endif + +#ifndef HW_ENDCLIPLOOP +#define HW_ENDCLIPLOOP() \ + } \ + } while (0) +#endif + +#ifndef CLIPPIXEL +#define CLIPPIXEL( _x, _y ) \ + ((_x >= minx) && (_x < maxx) && (_y >= miny) && (_y < maxy)) +#endif + +#ifndef CLIPSPAN +#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i ) \ + if ( _y < miny || _y >= maxy /*|| _x + n < minx || _x >=maxx*/ ) { \ + _n1 = 0, _x1 = x; \ + } else { \ + _n1 = _n; \ + _x1 = _x; \ + if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \ + if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx); \ + } +#endif diff --git a/src/mesa/drivers/dri/common/stenciltmp.h b/src/mesa/drivers/dri/common/stenciltmp.h new file mode 100644 index 0000000..fef0972 --- /dev/null +++ b/src/mesa/drivers/dri/common/stenciltmp.h @@ -0,0 +1,245 @@ + +#include "spantmp_common.h" + +#ifndef DBG +#define DBG 0 +#endif + +#ifndef HAVE_HW_STENCIL_SPANS +#define HAVE_HW_STENCIL_SPANS 0 +#endif + +#ifndef HAVE_HW_STENCIL_PIXELS +#define HAVE_HW_STENCIL_PIXELS 0 +#endif + +static void TAG(WriteStencilSpan)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, GLint x, GLint y, + const void *values, const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + const GLubyte *stencil = (const GLubyte *) values; + GLint x1; + GLint n1; + LOCAL_STENCIL_VARS; + + y = Y_FLIP(y); + +#if HAVE_HW_STENCIL_SPANS + (void) x1; (void) n1; + + if (DBG) fprintf(stderr, "WriteStencilSpan 0..%d (x1 %d)\n", + (int)n1, (int)x1); + + WRITE_STENCIL_SPAN(); +#else /* HAVE_HW_STENCIL_SPANS */ + HW_CLIPLOOP() + { + GLint i = 0; + CLIPSPAN(x,y,n,x1,n1,i); + + if (DBG) fprintf(stderr, "WriteStencilSpan %d..%d (x1 %d)\n", + (int)i, (int)n1, (int)x1); + + if (mask) + { + for (;n1>0;i++,x1++,n1--) + if (mask[i]) + WRITE_STENCIL( x1, y, stencil[i] ); + } + else + { + for (;n1>0;i++,x1++,n1--) + WRITE_STENCIL( x1, y, stencil[i] ); + } + } + HW_ENDCLIPLOOP(); +#endif /* !HAVE_HW_STENCIL_SPANS */ + } + HW_WRITE_UNLOCK(); +} + +#if HAVE_HW_STENCIL_SPANS +/* implement MonoWriteDepthSpan() in terms of WriteDepthSpan() */ +static void +TAG(WriteMonoStencilSpan)( struct gl_context *ctx, struct gl_renderbuffer *rb, + GLuint n, GLint x, GLint y, + const void *value, const GLubyte mask[] ) +{ + const GLuint stenVal = *((GLuint *) value); + GLuint stens[MAX_WIDTH]; + GLuint i; + for (i = 0; i < n; i++) + stens[i] = stenVal; + TAG(WriteStencilSpan)(ctx, rb, n, x, y, stens, mask); +} +#else /* HAVE_HW_STENCIL_SPANS */ +static void TAG(WriteMonoStencilSpan)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, GLint x, GLint y, + const void *value, + const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + const GLubyte stencil = *((const GLubyte *) value); + GLint x1; + GLint n1; + LOCAL_STENCIL_VARS; + + y = Y_FLIP(y); + + HW_CLIPLOOP() + { + GLint i = 0; + CLIPSPAN(x,y,n,x1,n1,i); + + if (DBG) fprintf(stderr, "WriteStencilSpan %d..%d (x1 %d)\n", + (int)i, (int)n1, (int)x1); + + if (mask) + { + for (;n1>0;i++,x1++,n1--) + if (mask[i]) + WRITE_STENCIL( x1, y, stencil ); + } + else + { + for (;n1>0;i++,x1++,n1--) + WRITE_STENCIL( x1, y, stencil ); + } + } + HW_ENDCLIPLOOP(); + } + HW_WRITE_UNLOCK(); +} +#endif /* !HAVE_HW_STENCIL_SPANS */ + + +static void TAG(WriteStencilPixels)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, + const GLint x[], const GLint y[], + const void *values, const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + const GLubyte *stencil = (const GLubyte *) values; + GLuint i; + LOCAL_STENCIL_VARS; + + if (DBG) fprintf(stderr, "WriteStencilPixels\n"); + +#if HAVE_HW_STENCIL_PIXELS + (void) i; + + WRITE_STENCIL_PIXELS(); +#else /* HAVE_HW_STENCIL_PIXELS */ + HW_CLIPLOOP() + { + for (i=0;i0;i++,n1--) + READ_STENCIL( stencil[i], (x+i), y ); + } + HW_ENDCLIPLOOP(); +#endif /* !HAVE_HW_STENCIL_SPANS */ + } + HW_READ_UNLOCK(); +} + +static void TAG(ReadStencilPixels)( struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint n, const GLint x[], const GLint y[], + void *values ) +{ + HW_READ_LOCK() + { + GLubyte *stencil = (GLubyte *) values; + GLuint i; + LOCAL_STENCIL_VARS; + + if (DBG) fprintf(stderr, "ReadStencilPixels\n"); + +#if HAVE_HW_STENCIL_PIXELS + (void) i; + + READ_STENCIL_PIXELS(); +#else /* HAVE_HW_STENCIL_PIXELS */ + HW_CLIPLOOP() + { + for (i=0;iGetRow = TAG(ReadStencilSpan); + rb->GetValues = TAG(ReadStencilPixels); + rb->PutRow = TAG(WriteStencilSpan); + rb->PutRowRGB = NULL; + rb->PutMonoRow = TAG(WriteMonoStencilSpan); + rb->PutValues = TAG(WriteStencilPixels); + rb->PutMonoValues = NULL; +} + + +#undef WRITE_STENCIL +#undef READ_STENCIL +#undef TAG diff --git a/src/mesa/drivers/dri/common/texmem.c b/src/mesa/drivers/dri/common/texmem.c new file mode 100644 index 0000000..8eec07d --- /dev/null +++ b/src/mesa/drivers/dri/common/texmem.c @@ -0,0 +1,1341 @@ +/* + * Copyright 2000-2001 VA Linux Systems, Inc. + * (C) Copyright IBM Corporation 2002, 2003 + * 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 + * 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 + * VA LINUX SYSTEM, IBM 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. + * + * Authors: + * Ian Romanick + * Keith Whitwell + * Kevin E. Martin + * Gareth Hughes + */ + +/** \file texmem.c + * Implements all of the device-independent texture memory management. + * + * Currently, only a simple LRU texture memory management policy is + * implemented. In the (hopefully very near) future, better policies will be + * implemented. The idea is that the DRI should be able to run in one of two + * modes. In the default mode the DRI will dynamically attempt to discover + * the best texture management policy for the running application. In the + * other mode, the user (via some sort of as yet TBD mechanism) will select + * a texture management policy that is known to work well with the + * application. + */ + +#include "main/imports.h" +#include "main/macros.h" +#include "main/simple_list.h" +#include "texmem.h" + + +static unsigned dummy_swap_counter; + + +/** + * Calculate \f$\log_2\f$ of a value. This is a particularly poor + * implementation of this function. However, since system performance is in + * no way dependent on this function, the slowness of the implementation is + * irrelevent. + * + * \param n Value whose \f$\log_2\f$ is to be calculated + */ + +static GLuint +driLog2( GLuint n ) +{ + GLuint log2; + + for ( log2 = 1 ; n > 1 ; log2++ ) { + n >>= 1; + } + + return log2; +} + + + + +/** + * Determine if a texture is resident in textureable memory. Depending on + * the driver, this may or may not be on-card memory. It could be AGP memory + * or anyother type of memory from which the hardware can directly read + * texels. + * + * This function is intended to be used as the \c IsTextureResident function + * in the device's \c dd_function_table. + * + * \param ctx GL context pointer (currently unused) + * \param texObj Texture object to be tested + */ + +GLboolean +driIsTextureResident( struct gl_context * ctx, + struct gl_texture_object * texObj ) +{ + driTextureObject * t; + + + t = (driTextureObject *) texObj->DriverData; + return( (t != NULL) && (t->memBlock != NULL) ); +} + + + + +/** + * (Re)initialize the global circular LRU list. The last element + * in the array (\a heap->nrRegions) is the sentinal. Keeping it + * at the end of the array allows the other elements of the array + * to be addressed rationally when looking up objects at a particular + * location in texture memory. + * + * \param heap Texture heap to be reset + */ + +static void resetGlobalLRU( driTexHeap * heap ) +{ + drmTextureRegionPtr list = heap->global_regions; + unsigned sz = 1U << heap->logGranularity; + unsigned i; + + for (i = 0 ; (i+1) * sz <= heap->size ; i++) { + list[i].prev = i-1; + list[i].next = i+1; + list[i].age = 0; + } + + i--; + list[0].prev = heap->nrRegions; + list[i].prev = i-1; + list[i].next = heap->nrRegions; + list[heap->nrRegions].prev = i; + list[heap->nrRegions].next = 0; + heap->global_age[0] = 0; +} + +/** + * Print out debugging information about the local texture LRU. + * + * \param heap Texture heap to be printed + * \param callername Name of calling function + */ +static void printLocalLRU( driTexHeap * heap, const char *callername ) +{ + driTextureObject *t; + unsigned sz = 1U << heap->logGranularity; + + fprintf( stderr, "%s in %s:\nLocal LRU, heap %d:\n", + __FUNCTION__, callername, heap->heapId ); + + foreach ( t, &heap->texture_objects ) { + if (!t->memBlock) + continue; + if (!t->tObj) { + fprintf( stderr, "Placeholder (%p) %d at 0x%x sz 0x%x\n", + (void *)t, + t->memBlock->ofs / sz, + t->memBlock->ofs, + t->memBlock->size ); + } else { + fprintf( stderr, "Texture (%p) at 0x%x sz 0x%x\n", + (void *)t, + t->memBlock->ofs, + t->memBlock->size ); + } + } + foreach ( t, heap->swapped_objects ) { + if (!t->tObj) { + fprintf( stderr, "Swapped Placeholder (%p)\n", (void *)t ); + } else { + fprintf( stderr, "Swapped Texture (%p)\n", (void *)t ); + } + } + + fprintf( stderr, "\n" ); +} + +/** + * Print out debugging information about the global texture LRU. + * + * \param heap Texture heap to be printed + * \param callername Name of calling function + */ +static void printGlobalLRU( driTexHeap * heap, const char *callername ) +{ + drmTextureRegionPtr list = heap->global_regions; + unsigned int i, j; + + fprintf( stderr, "%s in %s:\nGlobal LRU, heap %d list %p:\n", + __FUNCTION__, callername, heap->heapId, (void *)list ); + + for ( i = 0, j = heap->nrRegions ; i < heap->nrRegions ; i++ ) { + fprintf( stderr, "list[%d] age %d next %d prev %d in_use %d\n", + j, list[j].age, list[j].next, list[j].prev, list[j].in_use ); + j = list[j].next; + if ( j == heap->nrRegions ) break; + } + + if ( j != heap->nrRegions ) { + fprintf( stderr, "Loop detected in global LRU\n" ); + for ( i = 0 ; i < heap->nrRegions ; i++ ) { + fprintf( stderr, "list[%d] age %d next %d prev %d in_use %d\n", + i, list[i].age, list[i].next, list[i].prev, list[i].in_use ); + } + } + + fprintf( stderr, "\n" ); +} + + +/** + * Called by the client whenever it touches a local texture. + * + * \param t Texture object that the client has accessed + */ + +void driUpdateTextureLRU( driTextureObject * t ) +{ + driTexHeap * heap; + drmTextureRegionPtr list; + unsigned shift; + unsigned start; + unsigned end; + unsigned i; + + + heap = t->heap; + if ( heap != NULL ) { + shift = heap->logGranularity; + start = t->memBlock->ofs >> shift; + end = (t->memBlock->ofs + t->memBlock->size - 1) >> shift; + + + heap->local_age = ++heap->global_age[0]; + list = heap->global_regions; + + + /* Update the context's local LRU + */ + + move_to_head( & heap->texture_objects, t ); + + + for (i = start ; i <= end ; i++) { + list[i].age = heap->local_age; + + /* remove_from_list(i) + */ + list[(unsigned)list[i].next].prev = list[i].prev; + list[(unsigned)list[i].prev].next = list[i].next; + + /* insert_at_head(list, i) + */ + list[i].prev = heap->nrRegions; + list[i].next = list[heap->nrRegions].next; + list[(unsigned)list[heap->nrRegions].next].prev = i; + list[heap->nrRegions].next = i; + } + + if ( 0 ) { + printGlobalLRU( heap, __FUNCTION__ ); + printLocalLRU( heap, __FUNCTION__ ); + } + } +} + + + + +/** + * Keep track of swapped out texture objects. + * + * \param t Texture object to be "swapped" out of its texture heap + */ + +void driSwapOutTextureObject( driTextureObject * t ) +{ + unsigned face; + + + if ( t->memBlock != NULL ) { + assert( t->heap != NULL ); + mmFreeMem( t->memBlock ); + t->memBlock = NULL; + + if (t->timestamp > t->heap->timestamp) + t->heap->timestamp = t->timestamp; + + t->heap->texture_swaps[0]++; + move_to_tail( t->heap->swapped_objects, t ); + t->heap = NULL; + } + else { + assert( t->heap == NULL ); + } + + + for ( face = 0 ; face < 6 ; face++ ) { + t->dirty_images[face] = ~0; + } +} + + + + +/** + * Destroy hardware state associated with texture \a t. Calls the + * \a destroy_texture_object method associated with the heap from which + * \a t was allocated. + * + * \param t Texture object to be destroyed + */ + +void driDestroyTextureObject( driTextureObject * t ) +{ + driTexHeap * heap; + + + if ( 0 ) { + fprintf( stderr, "[%s:%d] freeing %p (tObj = %p, DriverData = %p)\n", + __FILE__, __LINE__, + (void *)t, + (void *)((t != NULL) ? t->tObj : NULL), + (void *)((t != NULL && t->tObj != NULL) ? t->tObj->DriverData : NULL )); + } + + if ( t != NULL ) { + if ( t->memBlock ) { + heap = t->heap; + assert( heap != NULL ); + + heap->texture_swaps[0]++; + + mmFreeMem( t->memBlock ); + t->memBlock = NULL; + + if (t->timestamp > t->heap->timestamp) + t->heap->timestamp = t->timestamp; + + heap->destroy_texture_object( heap->driverContext, t ); + t->heap = NULL; + } + + if ( t->tObj != NULL ) { + assert( t->tObj->DriverData == t ); + t->tObj->DriverData = NULL; + } + + remove_from_list( t ); + FREE( t ); + } + + if ( 0 ) { + fprintf( stderr, "[%s:%d] done freeing %p\n", __FILE__, __LINE__, (void *)t ); + } +} + + + + +/** + * Update the local heap's representation of texture memory based on + * data in the SAREA. This is done each time it is detected that some other + * direct rendering client has held the lock. This pertains to both our local + * textures and the textures belonging to other clients. Keep track of other + * client's textures by pushing a placeholder texture onto the LRU list -- + * these are denoted by \a tObj being \a NULL. + * + * \param heap Heap whose state is to be updated + * \param offset Byte offset in the heap that has been stolen + * \param size Size, in bytes, of the stolen block + * \param in_use Non-zero if the block is pinned/reserved by the kernel + */ + +static void driTexturesGone( driTexHeap * heap, int offset, int size, + int in_use ) +{ + driTextureObject * t; + driTextureObject * tmp; + + + foreach_s ( t, tmp, & heap->texture_objects ) { + if ( (t->memBlock->ofs < (offset + size)) + && ((t->memBlock->ofs + t->memBlock->size) > offset) ) { + /* It overlaps - kick it out. If the texture object is just a + * place holder, then destroy it all together. Otherwise, mark + * it as being swapped out. + */ + + if ( t->tObj != NULL ) { + driSwapOutTextureObject( t ); + } + else { + driDestroyTextureObject( t ); + } + } + } + + + { + t = (driTextureObject *) CALLOC( heap->texture_object_size ); + if ( t == NULL ) return; + + t->memBlock = mmAllocMem( heap->memory_heap, size, 0, offset ); + if ( t->memBlock == NULL ) { + fprintf( stderr, "Couldn't alloc placeholder: heap %u sz %x ofs %x\n", heap->heapId, + (int)size, (int)offset ); + mmDumpMemInfo( heap->memory_heap ); + FREE(t); + return; + } + t->heap = heap; + if (in_use) + t->reserved = 1; + insert_at_head( & heap->texture_objects, t ); + } +} + + + + +/** + * Called by the client on lock contention to determine whether textures have + * been stolen. If another client has modified a region in which we have + * textures, then we need to figure out which of our textures have been + * removed and update our global LRU. + * + * \param heap Texture heap to be updated + */ + +void driAgeTextures( driTexHeap * heap ) +{ + drmTextureRegionPtr list = heap->global_regions; + unsigned sz = 1U << (heap->logGranularity); + unsigned i, nr = 0; + + + /* Have to go right round from the back to ensure stuff ends up + * LRU in the local list... Fix with a cursor pointer. + */ + + for (i = list[heap->nrRegions].prev ; + i != heap->nrRegions && nr < heap->nrRegions ; + i = list[i].prev, nr++) { + /* If switching texturing schemes, then the SAREA might not have been + * properly cleared, so we need to reset the global texture LRU. + */ + + if ( (i * sz) > heap->size ) { + nr = heap->nrRegions; + break; + } + + if (list[i].age > heap->local_age) + driTexturesGone( heap, i * sz, sz, list[i].in_use); + } + + /* Loop or uninitialized heap detected. Reset. + */ + + if (nr == heap->nrRegions) { + driTexturesGone( heap, 0, heap->size, 0); + resetGlobalLRU( heap ); + } + + if ( 0 ) { + printGlobalLRU( heap, __FUNCTION__ ); + printLocalLRU( heap, __FUNCTION__ ); + } + + heap->local_age = heap->global_age[0]; +} + + + + +#define INDEX_ARRAY_SIZE 6 /* I'm not aware of driver with more than 2 heaps */ + +/** + * Allocate memory from a texture heap to hold a texture object. This + * routine will attempt to allocate memory for the texture from the heaps + * specified by \c heap_array in order. That is, first it will try to + * allocate from \c heap_array[0], then \c heap_array[1], and so on. + * + * \param heap_array Array of pointers to texture heaps to use + * \param nr_heaps Number of heap pointer in \a heap_array + * \param t Texture object for which space is needed + * \return The ID of the heap from which memory was allocated, or -1 if + * memory could not be allocated. + * + * \bug The replacement policy implemented by this function is horrible. + */ + + +int +driAllocateTexture( driTexHeap * const * heap_array, unsigned nr_heaps, + driTextureObject * t ) +{ + driTexHeap * heap; + driTextureObject * temp; + driTextureObject * cursor; + unsigned id; + + + /* In case it already has texture space, initialize heap. This also + * prevents GCC from issuing a warning that heap might be used + * uninitialized. + */ + + heap = t->heap; + + + /* Run through each of the existing heaps and try to allocate a buffer + * to hold the texture. + */ + + for ( id = 0 ; (t->memBlock == NULL) && (id < nr_heaps) ; id++ ) { + heap = heap_array[ id ]; + if ( heap != NULL ) { + t->memBlock = mmAllocMem( heap->memory_heap, t->totalSize, + heap->alignmentShift, 0 ); + } + } + + + /* Kick textures out until the requested texture fits. + */ + + if ( t->memBlock == NULL ) { + unsigned index[INDEX_ARRAY_SIZE]; + unsigned nrGoodHeaps = 0; + + /* Trying to avoid dynamic memory allocation. If you have more + * heaps, increase INDEX_ARRAY_SIZE. I'm not aware of any + * drivers with more than 2 tex heaps. */ + assert( nr_heaps < INDEX_ARRAY_SIZE ); + + /* Sort large enough heaps by duty. Insertion sort should be + * fast enough for such a short array. */ + for ( id = 0 ; id < nr_heaps ; id++ ) { + heap = heap_array[ id ]; + + if ( heap != NULL && t->totalSize <= heap->size ) { + unsigned j; + + for ( j = 0 ; j < nrGoodHeaps; j++ ) { + if ( heap->duty > heap_array[ index[ j ] ]->duty ) + break; + } + + if ( j < nrGoodHeaps ) { + memmove( &index[ j+1 ], &index[ j ], + sizeof(index[ 0 ]) * (nrGoodHeaps - j) ); + } + + index[ j ] = id; + + nrGoodHeaps++; + } + } + + for ( id = 0 ; (t->memBlock == NULL) && (id < nrGoodHeaps) ; id++ ) { + heap = heap_array[ index[ id ] ]; + + for ( cursor = heap->texture_objects.prev, temp = cursor->prev; + cursor != &heap->texture_objects ; + cursor = temp, temp = cursor->prev ) { + + /* The the LRU element. If the texture is bound to one of + * the texture units, then we cannot kick it out. + */ + if ( cursor->bound || cursor->reserved ) { + continue; + } + + if ( cursor->memBlock ) + heap->duty -= cursor->memBlock->size; + + /* If this is a placeholder, there's no need to keep it */ + if (cursor->tObj) + driSwapOutTextureObject( cursor ); + else + driDestroyTextureObject( cursor ); + + t->memBlock = mmAllocMem( heap->memory_heap, t->totalSize, + heap->alignmentShift, 0 ); + + if (t->memBlock) + break; + } + } + + /* Rebalance duties. If a heap kicked more data than its duty, + * then all other heaps get that amount multiplied with their + * relative weight added to their duty. The negative duty is + * reset to 0. In the end all heaps have a duty >= 0. + * + * CAUTION: we must not change the heap pointer here, because it + * is used below to update the texture object. + */ + for ( id = 0 ; id < nr_heaps ; id++ ) + if ( heap_array[ id ] != NULL && heap_array[ id ]->duty < 0) { + int duty = -heap_array[ id ]->duty; + double weight = heap_array[ id ]->weight; + unsigned j; + + for ( j = 0 ; j < nr_heaps ; j++ ) + if ( j != id && heap_array[ j ] != NULL ) { + heap_array[ j ]->duty += (double) duty * + heap_array[ j ]->weight / weight; + } + + heap_array[ id ]->duty = 0; + } + } + + + if ( t->memBlock != NULL ) { + /* id and heap->heapId may or may not be the same value here. + */ + + assert( heap != NULL ); + assert( (t->heap == NULL) || (t->heap == heap) ); + + t->heap = heap; + return heap->heapId; + } + else { + assert( t->heap == NULL ); + + fprintf( stderr, "[%s:%d] unable to allocate texture\n", + __FUNCTION__, __LINE__ ); + return -1; + } +} + + + + + + +/** + * Set the location where the texture-swap counter is stored. + */ + +void +driSetTextureSwapCounterLocation( driTexHeap * heap, unsigned * counter ) +{ + heap->texture_swaps = (counter == NULL) ? & dummy_swap_counter : counter; +} + + + + +/** + * Create a new heap for texture data. + * + * \param heap_id Device-dependent heap identifier. This value + * will returned by driAllocateTexture when memory + * is allocated from this heap. + * \param context Device-dependent driver context. This is + * supplied as the first parameter to the + * \c destroy_tex_obj function. + * \param size Size, in bytes, of the texture region + * \param alignmentShift Alignment requirement for textures. If textures + * must be allocated on a 4096 byte boundry, this + * would be 12. + * \param nr_regions Number of regions into which this texture space + * should be partitioned + * \param global_regions Array of \c drmTextureRegion structures in the SAREA + * \param global_age Pointer to the global texture age in the SAREA + * \param swapped_objects Pointer to the list of texture objects that are + * not in texture memory (i.e., have been swapped + * out). + * \param texture_object_size Size, in bytes, of a device-dependent texture + * object + * \param destroy_tex_obj Function used to destroy a device-dependent + * texture object + * + * \sa driDestroyTextureHeap + */ + +driTexHeap * +driCreateTextureHeap( unsigned heap_id, void * context, unsigned size, + unsigned alignmentShift, unsigned nr_regions, + drmTextureRegionPtr global_regions, unsigned * global_age, + driTextureObject * swapped_objects, + unsigned texture_object_size, + destroy_texture_object_t * destroy_tex_obj + ) +{ + driTexHeap * heap; + unsigned l; + + + if ( 0 ) + fprintf( stderr, "%s( %u, %p, %u, %u, %u )\n", + __FUNCTION__, + heap_id, (void *)context, size, alignmentShift, nr_regions ); + + heap = (driTexHeap *) CALLOC( sizeof( driTexHeap ) ); + if ( heap != NULL ) { + l = driLog2( (size - 1) / nr_regions ); + if ( l < alignmentShift ) + { + l = alignmentShift; + } + + heap->logGranularity = l; + heap->size = size & ~((1L << l) - 1); + + heap->memory_heap = mmInit( 0, heap->size ); + if ( heap->memory_heap != NULL ) { + heap->heapId = heap_id; + heap->driverContext = context; + + heap->alignmentShift = alignmentShift; + heap->nrRegions = nr_regions; + heap->global_regions = global_regions; + heap->global_age = global_age; + heap->swapped_objects = swapped_objects; + heap->texture_object_size = texture_object_size; + heap->destroy_texture_object = destroy_tex_obj; + + /* Force global heap init */ + if (heap->global_age[0] == 0) + heap->local_age = ~0; + else + heap->local_age = 0; + + make_empty_list( & heap->texture_objects ); + driSetTextureSwapCounterLocation( heap, NULL ); + + heap->weight = heap->size; + heap->duty = 0; + } + else { + FREE( heap ); + heap = NULL; + } + } + + + if ( 0 ) + fprintf( stderr, "%s returning %p\n", __FUNCTION__, (void *)heap ); + + return heap; +} + + + + +/** Destroys a texture heap + * + * \param heap Texture heap to be destroyed + */ + +void +driDestroyTextureHeap( driTexHeap * heap ) +{ + driTextureObject * t; + driTextureObject * temp; + + + if ( heap != NULL ) { + foreach_s( t, temp, & heap->texture_objects ) { + driDestroyTextureObject( t ); + } + foreach_s( t, temp, heap->swapped_objects ) { + driDestroyTextureObject( t ); + } + + mmDestroy( heap->memory_heap ); + FREE( heap ); + } +} + + + + +/****************************************************************************/ +/** + * Determine how many texels (including all mipmap levels) would be required + * for a texture map of size \f$2^^\c base_size_log2\f$ would require. + * + * \param base_size_log2 \f$log_2\f$ of the size of a side of the texture + * \param dimensions Number of dimensions of the texture. Either 2 or 3. + * \param faces Number of faces of the texture. Either 1 or 6 (for cube maps). + * \return Number of texels + */ + +static unsigned +texels_this_map_size( int base_size_log2, unsigned dimensions, unsigned faces ) +{ + unsigned texels; + + + assert( (faces == 1) || (faces == 6) ); + assert( (dimensions == 2) || (dimensions == 3) ); + + texels = 0; + if ( base_size_log2 >= 0 ) { + texels = (1U << (dimensions * base_size_log2)); + + /* See http://www.mail-archive.com/dri-devel@lists.sourceforge.net/msg03636.html + * for the complete explaination of why this formulation is used. + * Basically, the smaller mipmap levels sum to 0.333 the size of the + * level 0 map. The total size is therefore the size of the map + * multipled by 1.333. The +2 is there to round up. + */ + + texels = (texels * 4 * faces + 2) / 3; + } + + return texels; +} + + + + +struct maps_per_heap { + unsigned c[32]; +}; + +static void +fill_in_maximums( driTexHeap * const * heaps, unsigned nr_heaps, + unsigned max_bytes_per_texel, unsigned max_size, + unsigned mipmaps_at_once, unsigned dimensions, + unsigned faces, struct maps_per_heap * max_textures ) +{ + unsigned heap; + unsigned log2_size; + unsigned mask; + + + /* Determine how many textures of each size can be stored in each + * texture heap. + */ + + for ( heap = 0 ; heap < nr_heaps ; heap++ ) { + if ( heaps[ heap ] == NULL ) { + (void) memset( max_textures[ heap ].c, 0, + sizeof( max_textures[ heap ].c ) ); + continue; + } + + mask = (1U << heaps[ heap ]->logGranularity) - 1; + + if ( 0 ) { + fprintf( stderr, "[%s:%d] heap[%u] = %u bytes, mask = 0x%08x\n", + __FILE__, __LINE__, + heap, heaps[ heap ]->size, mask ); + } + + for ( log2_size = max_size ; log2_size > 0 ; log2_size-- ) { + unsigned total; + + + /* Determine the total number of bytes required by a texture of + * size log2_size. + */ + + total = texels_this_map_size( log2_size, dimensions, faces ) + - texels_this_map_size( log2_size - mipmaps_at_once, + dimensions, faces ); + total *= max_bytes_per_texel; + total = (total + mask) & ~mask; + + /* The number of textures of a given size that will fit in a heap + * is equal to the size of the heap divided by the size of the + * texture. + */ + + max_textures[ heap ].c[ log2_size ] = heaps[ heap ]->size / total; + + if ( 0 ) { + fprintf( stderr, "[%s:%d] max_textures[%u].c[%02u] " + "= 0x%08x / 0x%08x " + "= %u (%u)\n", + __FILE__, __LINE__, + heap, log2_size, + heaps[ heap ]->size, total, + heaps[ heap ]->size / total, + max_textures[ heap ].c[ log2_size ] ); + } + } + } +} + + +static unsigned +get_max_size( unsigned nr_heaps, + unsigned texture_units, + unsigned max_size, + int all_textures_one_heap, + struct maps_per_heap * max_textures ) +{ + unsigned heap; + unsigned log2_size; + + + /* Determine the largest texture size such that a texture of that size + * can be bound to each texture unit at the same time. Some hardware + * may require that all textures be in the same texture heap for + * multitexturing. + */ + + for ( log2_size = max_size ; log2_size > 0 ; log2_size-- ) { + unsigned total = 0; + + for ( heap = 0 ; heap < nr_heaps ; heap++ ) + { + total += max_textures[ heap ].c[ log2_size ]; + + if ( 0 ) { + fprintf( stderr, "[%s:%d] max_textures[%u].c[%02u] = %u, " + "total = %u\n", __FILE__, __LINE__, heap, log2_size, + max_textures[ heap ].c[ log2_size ], total ); + } + + if ( (max_textures[ heap ].c[ log2_size ] >= texture_units) + || (!all_textures_one_heap && (total >= texture_units)) ) { + /* The number of mipmap levels is the log-base-2 of the + * maximum texture size plus 1. If the maximum texture size + * is 1x1, the log-base-2 is 0 and 1 mipmap level (the base + * level) is available. + */ + + return log2_size + 1; + } + } + } + + /* This should NEVER happen. It should always be possible to have at + * *least* a 1x1 texture in memory! + */ + assert( log2_size != 0 ); + return 0; +} + +#define SET_MAX(f,v) \ + do { if ( max_sizes[v] != 0 ) { limits-> f = max_sizes[v]; } } while( 0 ) + +#define SET_MAX_RECT(f,v) \ + do { if ( max_sizes[v] != 0 ) { limits-> f = 1 << (max_sizes[v] - 1); } } while( 0 ) + + +/** + * Given the amount of texture memory, the number of texture units, and the + * maximum size of a texel, calculate the maximum texture size the driver can + * advertise. + * + * \param heaps Texture heaps for this card + * \param nr_heap Number of texture heaps + * \param limits OpenGL contants. MaxTextureUnits must be set. + * \param max_bytes_per_texel Maximum size of a single texel, in bytes + * \param max_2D_size \f$\log_2\f$ of the maximum 2D texture size (i.e., + * 1024x1024 textures, this would be 10) + * \param max_3D_size \f$\log_2\f$ of the maximum 3D texture size (i.e., + * 1024x1024x1024 textures, this would be 10) + * \param max_cube_size \f$\log_2\f$ of the maximum cube texture size (i.e., + * 1024x1024 textures, this would be 10) + * \param max_rect_size \f$\log_2\f$ of the maximum texture rectangle size + * (i.e., 1024x1024 textures, this would be 10). This is a power-of-2 + * even though texture rectangles need not be a power-of-2. + * \param mipmaps_at_once Total number of mipmaps that can be used + * at one time. For most hardware this will be \f$\c max_size + 1\f$. + * For hardware that does not support mipmapping, this will be 1. + * \param all_textures_one_heap True if the hardware requires that all + * textures be in a single texture heap for multitexturing. + * \param allow_larger_textures 0 conservative, 1 calculate limits + * so at least one worst-case texture can fit, 2 just use hw limits. + */ + +void +driCalculateMaxTextureLevels( driTexHeap * const * heaps, + unsigned nr_heaps, + struct gl_constants * limits, + unsigned max_bytes_per_texel, + unsigned max_2D_size, + unsigned max_3D_size, + unsigned max_cube_size, + unsigned max_rect_size, + unsigned mipmaps_at_once, + int all_textures_one_heap, + int allow_larger_textures ) +{ + struct maps_per_heap max_textures[8]; + unsigned i; + const unsigned dimensions[4] = { 2, 3, 2, 2 }; + const unsigned faces[4] = { 1, 1, 6, 1 }; + unsigned max_sizes[4]; + unsigned mipmaps[4]; + + + max_sizes[0] = max_2D_size; + max_sizes[1] = max_3D_size; + max_sizes[2] = max_cube_size; + max_sizes[3] = max_rect_size; + + mipmaps[0] = mipmaps_at_once; + mipmaps[1] = mipmaps_at_once; + mipmaps[2] = mipmaps_at_once; + mipmaps[3] = 1; + + + /* Calculate the maximum number of texture levels in two passes. The + * first pass determines how many textures of each power-of-two size + * (including all mipmap levels for that size) can fit in each texture + * heap. The second pass finds the largest texture size that allows + * a texture of that size to be bound to every texture unit. + */ + + for ( i = 0 ; i < 4 ; i++ ) { + if ( (allow_larger_textures != 2) && (max_sizes[ i ] != 0) ) { + fill_in_maximums( heaps, nr_heaps, max_bytes_per_texel, + max_sizes[ i ], mipmaps[ i ], + dimensions[ i ], faces[ i ], + max_textures ); + + max_sizes[ i ] = get_max_size( nr_heaps, + allow_larger_textures == 1 ? + 1 : limits->MaxTextureUnits, + max_sizes[ i ], + all_textures_one_heap, + max_textures ); + } + else if (max_sizes[ i ] != 0) { + max_sizes[ i ] += 1; + } + } + + SET_MAX( MaxTextureLevels, 0 ); + SET_MAX( Max3DTextureLevels, 1 ); + SET_MAX( MaxCubeTextureLevels, 2 ); + SET_MAX_RECT( MaxTextureRectSize, 3 ); +} + + + + +/** + * Perform initial binding of default textures objects on a per unit, per + * texture target basis. + * + * \param ctx Current OpenGL context + * \param swapped List of swapped-out textures + * \param targets Bit-mask of value texture targets + */ + +void driInitTextureObjects( struct gl_context *ctx, driTextureObject * swapped, + GLuint targets ) +{ + struct gl_texture_object *texObj; + GLuint tmp = ctx->Texture.CurrentUnit; + unsigned i; + + + for ( i = 0 ; i < ctx->Const.MaxTextureUnits ; i++ ) { + ctx->Texture.CurrentUnit = i; + + if ( (targets & DRI_TEXMGR_DO_TEXTURE_1D) != 0 ) { + texObj = ctx->Texture.Unit[i].CurrentTex[TEXTURE_1D_INDEX]; + ctx->Driver.BindTexture( ctx, GL_TEXTURE_1D, texObj ); + move_to_tail( swapped, (driTextureObject *) texObj->DriverData ); + } + + if ( (targets & DRI_TEXMGR_DO_TEXTURE_2D) != 0 ) { + texObj = ctx->Texture.Unit[i].CurrentTex[TEXTURE_2D_INDEX]; + ctx->Driver.BindTexture( ctx, GL_TEXTURE_2D, texObj ); + move_to_tail( swapped, (driTextureObject *) texObj->DriverData ); + } + + if ( (targets & DRI_TEXMGR_DO_TEXTURE_3D) != 0 ) { + texObj = ctx->Texture.Unit[i].CurrentTex[TEXTURE_3D_INDEX]; + ctx->Driver.BindTexture( ctx, GL_TEXTURE_3D, texObj ); + move_to_tail( swapped, (driTextureObject *) texObj->DriverData ); + } + + if ( (targets & DRI_TEXMGR_DO_TEXTURE_CUBE) != 0 ) { + texObj = ctx->Texture.Unit[i].CurrentTex[TEXTURE_CUBE_INDEX]; + ctx->Driver.BindTexture( ctx, GL_TEXTURE_CUBE_MAP_ARB, texObj ); + move_to_tail( swapped, (driTextureObject *) texObj->DriverData ); + } + + if ( (targets & DRI_TEXMGR_DO_TEXTURE_RECT) != 0 ) { + texObj = ctx->Texture.Unit[i].CurrentTex[TEXTURE_RECT_INDEX]; + ctx->Driver.BindTexture( ctx, GL_TEXTURE_RECTANGLE_NV, texObj ); + move_to_tail( swapped, (driTextureObject *) texObj->DriverData ); + } + } + + ctx->Texture.CurrentUnit = tmp; +} + + + + +/** + * Verify that the specified texture is in the specificed heap. + * + * \param tex Texture to be tested. + * \param heap Texture memory heap to be tested. + * \return True if the texture is in the heap, false otherwise. + */ + +static GLboolean +check_in_heap( const driTextureObject * tex, const driTexHeap * heap ) +{ +#if 1 + return tex->heap == heap; +#else + driTextureObject * curr; + + foreach( curr, & heap->texture_objects ) { + if ( curr == tex ) { + break; + } + } + + return curr == tex; +#endif +} + + + +/****************************************************************************/ +/** + * Validate the consistency of a set of texture heaps. + * Original version by Keith Whitwell in r200/r200_sanity.c. + */ + +GLboolean +driValidateTextureHeaps( driTexHeap * const * texture_heaps, + unsigned nr_heaps, const driTextureObject * swapped ) +{ + driTextureObject *t; + unsigned i; + + for ( i = 0 ; i < nr_heaps ; i++ ) { + int last_end = 0; + unsigned textures_in_heap = 0; + unsigned blocks_in_mempool = 0; + const driTexHeap * heap = texture_heaps[i]; + const struct mem_block *p = heap->memory_heap; + + /* Check each texture object has a MemBlock, and is linked into + * the correct heap. + * + * Check the texobj base address corresponds to the MemBlock + * range. Check the texobj size (recalculate?) fits within + * the MemBlock. + * + * Count the number of texobj's using this heap. + */ + + foreach ( t, &heap->texture_objects ) { + if ( !check_in_heap( t, heap ) ) { + fprintf( stderr, "%s memory block for texture object @ %p not " + "found in heap #%d\n", + __FUNCTION__, (void *)t, i ); + return GL_FALSE; + } + + + if ( t->totalSize > t->memBlock->size ) { + fprintf( stderr, "%s: Memory block for texture object @ %p is " + "only %u bytes, but %u are required\n", + __FUNCTION__, (void *)t, t->totalSize, t->memBlock->size ); + return GL_FALSE; + } + + textures_in_heap++; + } + + /* Validate the contents of the heap: + * - Ordering + * - Overlaps + * - Bounds + */ + + while ( p != NULL ) { + if (p->reserved) { + fprintf( stderr, "%s: Block (%08x,%x), is reserved?!\n", + __FUNCTION__, p->ofs, p->size ); + return GL_FALSE; + } + + if (p->ofs != last_end) { + fprintf( stderr, "%s: blocks_in_mempool = %d, last_end = %d, p->ofs = %d\n", + __FUNCTION__, blocks_in_mempool, last_end, p->ofs ); + return GL_FALSE; + } + + if (!p->reserved && !p->free) { + blocks_in_mempool++; + } + + last_end = p->ofs + p->size; + p = p->next; + } + + if (textures_in_heap != blocks_in_mempool) { + fprintf( stderr, "%s: Different number of textures objects (%u) and " + "inuse memory blocks (%u)\n", + __FUNCTION__, textures_in_heap, blocks_in_mempool ); + return GL_FALSE; + } + +#if 0 + fprintf( stderr, "%s: textures_in_heap = %u\n", + __FUNCTION__, textures_in_heap ); +#endif + } + + + /* Check swapped texobj's have zero memblocks + */ + i = 0; + foreach ( t, swapped ) { + if ( t->memBlock != NULL ) { + fprintf( stderr, "%s: Swapped texobj %p has non-NULL memblock %p\n", + __FUNCTION__, (void *)t, (void *)t->memBlock ); + return GL_FALSE; + } + i++; + } + +#if 0 + fprintf( stderr, "%s: swapped texture count = %u\n", __FUNCTION__, i ); +#endif + + return GL_TRUE; +} + + + + +/****************************************************************************/ +/** + * Compute which mipmap levels that really need to be sent to the hardware. + * This depends on the base image size, GL_TEXTURE_MIN_LOD, + * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL. + */ + +void +driCalculateTextureFirstLastLevel( driTextureObject * t ) +{ + struct gl_texture_object * const tObj = t->tObj; + const struct gl_texture_image * const baseImage = + tObj->Image[0][tObj->BaseLevel]; + + /* These must be signed values. MinLod and MaxLod can be negative numbers, + * and having firstLevel and lastLevel as signed prevents the need for + * extra sign checks. + */ + int firstLevel; + int lastLevel; + + /* Yes, this looks overly complicated, but it's all needed. + */ + + switch (tObj->Target) { + case GL_TEXTURE_1D: + case GL_TEXTURE_2D: + case GL_TEXTURE_3D: + case GL_TEXTURE_CUBE_MAP: + if (tObj->MinFilter == GL_NEAREST || tObj->MinFilter == GL_LINEAR) { + /* GL_NEAREST and GL_LINEAR only care about GL_TEXTURE_BASE_LEVEL. + */ + + firstLevel = lastLevel = tObj->BaseLevel; + } + else { + firstLevel = tObj->BaseLevel + (GLint)(tObj->MinLod + 0.5); + firstLevel = MAX2(firstLevel, tObj->BaseLevel); + firstLevel = MIN2(firstLevel, tObj->BaseLevel + baseImage->MaxLog2); + lastLevel = tObj->BaseLevel + (GLint)(tObj->MaxLod + 0.5); + lastLevel = MAX2(lastLevel, t->tObj->BaseLevel); + lastLevel = MIN2(lastLevel, t->tObj->BaseLevel + baseImage->MaxLog2); + lastLevel = MIN2(lastLevel, t->tObj->MaxLevel); + lastLevel = MAX2(firstLevel, lastLevel); /* need at least one level */ + } + break; + case GL_TEXTURE_RECTANGLE_NV: + case GL_TEXTURE_4D_SGIS: + firstLevel = lastLevel = 0; + break; + default: + return; + } + + /* save these values */ + t->firstLevel = firstLevel; + t->lastLevel = lastLevel; +} + + + + +/** + * \name DRI texture formats. These vars are initialized to either the + * big- or little-endian Mesa formats. + */ +/*@{*/ +gl_format _dri_texformat_rgba8888 = MESA_FORMAT_NONE; +gl_format _dri_texformat_argb8888 = MESA_FORMAT_NONE; +gl_format _dri_texformat_rgb565 = MESA_FORMAT_NONE; +gl_format _dri_texformat_argb4444 = MESA_FORMAT_NONE; +gl_format _dri_texformat_argb1555 = MESA_FORMAT_NONE; +gl_format _dri_texformat_al88 = MESA_FORMAT_NONE; +gl_format _dri_texformat_a8 = MESA_FORMAT_A8; +gl_format _dri_texformat_ci8 = MESA_FORMAT_CI8; +gl_format _dri_texformat_i8 = MESA_FORMAT_I8; +gl_format _dri_texformat_l8 = MESA_FORMAT_L8; +/*@}*/ + + +/** + * Initialize _dri_texformat_* vars according to whether we're on + * a big or little endian system. + */ +void +driInitTextureFormats(void) +{ + if (_mesa_little_endian()) { + _dri_texformat_rgba8888 = MESA_FORMAT_RGBA8888; + _dri_texformat_argb8888 = MESA_FORMAT_ARGB8888; + _dri_texformat_rgb565 = MESA_FORMAT_RGB565; + _dri_texformat_argb4444 = MESA_FORMAT_ARGB4444; + _dri_texformat_argb1555 = MESA_FORMAT_ARGB1555; + _dri_texformat_al88 = MESA_FORMAT_AL88; + } + else { + _dri_texformat_rgba8888 = MESA_FORMAT_RGBA8888_REV; + _dri_texformat_argb8888 = MESA_FORMAT_ARGB8888_REV; + _dri_texformat_rgb565 = MESA_FORMAT_RGB565_REV; + _dri_texformat_argb4444 = MESA_FORMAT_ARGB4444_REV; + _dri_texformat_argb1555 = MESA_FORMAT_ARGB1555_REV; + _dri_texformat_al88 = MESA_FORMAT_AL88_REV; + } +} diff --git a/src/mesa/drivers/dri/common/texmem.h b/src/mesa/drivers/dri/common/texmem.h new file mode 100644 index 0000000..6dd07b8 --- /dev/null +++ b/src/mesa/drivers/dri/common/texmem.h @@ -0,0 +1,334 @@ +/* + * Copyright 2000-2001 VA Linux Systems, Inc. + * (c) Copyright IBM Corporation 2002 + * 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 + * 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 + * VA LINUX SYSTEM, IBM 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. + * + * Authors: + * Ian Romanick + * Keith Whitwell + * Kevin E. Martin + * Gareth Hughes + */ + +/** \file texmem.h + * Public interface to the DRI texture memory management routines. + * + * \sa texmem.c + */ + +#ifndef DRI_TEXMEM_H +#define DRI_TEXMEM_H + +#include "main/mtypes.h" +#include "main/formats.h" +#include "main/mm.h" +#include "xf86drm.h" + +struct dri_tex_heap; +typedef struct dri_tex_heap driTexHeap; + +struct dri_texture_object; +typedef struct dri_texture_object driTextureObject; + + +/** + * Base texture object type. Each driver will extend this type with its own + * private data members. + */ + +struct dri_texture_object { + struct dri_texture_object * next; + struct dri_texture_object * prev; + + driTexHeap * heap; /**< Texture heap currently stored in */ + struct gl_texture_object * tObj;/**< Pointer to Mesa texture object + * If NULL, this texture object is a + * "placeholder" object representing + * texture memory in use by another context. + * A placeholder should have a heap and a memBlock. + */ + struct mem_block *memBlock; /**< Memory block containing texture */ + + unsigned reserved; /**< Cannot be swapped out by user contexts. */ + + unsigned bound; /**< Bitmask indicating which tex units + * this texture object is bound to. + * Bit 0 = unit 0, Bit 1 = unit 1, etc + */ + + unsigned totalSize; /**< Total size of the texture, + * including all mipmap levels + */ + + unsigned dirty_images[6]; /**< Flags for whether or not images + * need to be uploaded to local or + * AGP texture space. One flag set + * for each cube face for cubic + * textures. Bit zero corresponds to + * the base-level, which may or may + * not be the level zero mipmap. + */ + + unsigned timestamp; /**< Timestamp used to + * synchronize with 3d engine + * in hardware where textures + * are uploaded directly to + * the framebuffer. + */ + + unsigned firstLevel; /**< Image in \c tObj->Image[0] that + * corresponds to the base-level of + * this texture object. + */ + + unsigned lastLevel; /**< Last image in \c tObj->Image[0] + * used by the + * current LOD settings of + * this texture object. This + * value must be greater than + * or equal to \c firstLevel. + */ +}; + + +typedef void (destroy_texture_object_t)( void * driverContext, + driTextureObject * t ); + +/** + * Client-private representation of texture memory state. + * + * Clients will place one or more of these structs in their driver + * context struct to manage one or more global texture heaps. + */ + +struct dri_tex_heap { + + /** Client-supplied heap identifier + */ + unsigned heapId; + + /** Pointer to the client's private context + */ + void *driverContext; + + /** Total size of the heap, in bytes + */ + unsigned size; + + /** \brief \f$log_2\f$ of size of single heap region + * + * Each context takes memory from the global texture heap in + * \f$2^{logGranularity}\f$ byte blocks. The value of + * \a logGranularity is based on the amount of memory represented + * by the heap and the maximum number of regions in the SAREA. Given + * \a b bytes of texture memory an \a n regions in the SAREA, + * \a logGranularity will be \f$\lfloor\log_2( b / n )\rfloor\f$. + */ + unsigned logGranularity; + + /** \brief Required alignment of allocations in this heap + * + * The alignment shift is supplied to \a mmAllocMem when memory is + * allocated from this heap. The value of \a alignmentShift will + * typically reflect some require of the hardware. This value has + * \b no \b relation to \a logGranularity. \a alignmentShift is a + * per-context value. + * + * \sa mmAllocMem + */ + unsigned alignmentShift; + + /** Number of elements in global list (the SAREA). + */ + unsigned nrRegions; + + /** Pointer to SAREA \a driTexRegion array + */ + drmTextureRegionPtr global_regions; + + /** Pointer to the texture state age (generation number) in the SAREA + */ + unsigned * global_age; + + /** Local age (generation number) of texture state + */ + unsigned local_age; + + /** Memory heap used to manage texture memory represented by + * this texture heap. + */ + struct mem_block * memory_heap; + + /** List of objects that we currently believe to be in texture + * memory. + */ + driTextureObject texture_objects; + + /** Pointer to the list of texture objects that are not in + * texture memory. + */ + driTextureObject * swapped_objects; + + /** Size of the driver-speicific texture object. + */ + unsigned texture_object_size; + + + /** + * \brief Function to destroy driver-specific texture object data. + * + * This function is supplied by the driver so that the texture manager + * can release all resources associated with a texture object. This + * function should only release driver-specific data. That is, + * \a driDestroyTextureObject will release the texture memory + * associated with the texture object, it will release the memory + * for the texture object itself, and it will unlink the texture + * object from the texture object lists. + * + * \param driverContext Pointer to the driver supplied context + * \param t Texture object that is to be destroyed + * \sa driDestroyTextureObject + */ + + destroy_texture_object_t * destroy_texture_object; + + + /** + */ + unsigned * texture_swaps; + + /** + * Timestamp used to synchronize with 3d engine in hardware + * where textures are uploaded directly to the + * framebuffer. + */ + unsigned timestamp; + + /** \brief Kick/upload weight + * + * When not enough free space is available this weight + * influences the choice of the heap from which textures are + * kicked. By default the weight is equal to the heap size. + */ + double weight; + + /** \brief Kick/upload duty + * + * The heap with the highest duty will be chosen for kicking + * textures if not enough free space is available. The duty is + * reduced by the amount of data kicked. Rebalancing of + * negative duties takes the weights into account. + */ + int duty; +}; + + + + +/** + * Called by the client on lock contention to determine whether textures have + * been stolen. If another client has modified a region in which we have + * textures, then we need to figure out which of our textures have been + * removed and update our global LRU. + * + * \param heap Texture heap to be updated + * \hideinitializer + */ + +#define DRI_AGE_TEXTURES( heap ) \ + do { \ + if ( ((heap) != NULL) \ + && ((heap)->local_age != (heap)->global_age[0]) ) \ + driAgeTextures( heap ); \ + } while( 0 ) + + + + +/* This should be called whenever there has been contention on the hardware + * lock. driAgeTextures should not be called directly. Instead, clients + * should use DRI_AGE_TEXTURES, above. + */ + +void driAgeTextures( driTexHeap * heap ); + +void driUpdateTextureLRU( driTextureObject * t ); +void driSwapOutTextureObject( driTextureObject * t ); +void driDestroyTextureObject( driTextureObject * t ); +int driAllocateTexture( driTexHeap * const * heap_array, unsigned nr_heaps, + driTextureObject * t ); + +GLboolean driIsTextureResident( struct gl_context * ctx, + struct gl_texture_object * texObj ); + +driTexHeap * driCreateTextureHeap( unsigned heap_id, void * context, + unsigned size, unsigned alignmentShift, unsigned nr_regions, + drmTextureRegionPtr global_regions, unsigned * global_age, + driTextureObject * swapped_objects, unsigned texture_object_size, + destroy_texture_object_t * destroy_tex_obj ); +void driDestroyTextureHeap( driTexHeap * heap ); + +void +driCalculateMaxTextureLevels( driTexHeap * const * heaps, + unsigned nr_heaps, + struct gl_constants * limits, + unsigned max_bytes_per_texel, + unsigned max_2D_size, + unsigned max_3D_size, + unsigned max_cube_size, + unsigned max_rect_size, + unsigned mipmaps_at_once, + int all_textures_one_heap, + int allow_larger_textures ); + +void +driSetTextureSwapCounterLocation( driTexHeap * heap, unsigned * counter ); + +#define DRI_TEXMGR_DO_TEXTURE_1D 0x0001 +#define DRI_TEXMGR_DO_TEXTURE_2D 0x0002 +#define DRI_TEXMGR_DO_TEXTURE_3D 0x0004 +#define DRI_TEXMGR_DO_TEXTURE_CUBE 0x0008 +#define DRI_TEXMGR_DO_TEXTURE_RECT 0x0010 + +void driInitTextureObjects( struct gl_context *ctx, driTextureObject * swapped, + GLuint targets ); + +GLboolean driValidateTextureHeaps( driTexHeap * const * texture_heaps, + unsigned nr_heaps, const driTextureObject * swapped ); + +extern void driCalculateTextureFirstLastLevel( driTextureObject * t ); + + +extern gl_format _dri_texformat_rgba8888; +extern gl_format _dri_texformat_argb8888; +extern gl_format _dri_texformat_rgb565; +extern gl_format _dri_texformat_argb4444; +extern gl_format _dri_texformat_argb1555; +extern gl_format _dri_texformat_al88; +extern gl_format _dri_texformat_a8; +extern gl_format _dri_texformat_ci8; +extern gl_format _dri_texformat_i8; +extern gl_format _dri_texformat_l8; + +extern void driInitTextureFormats( void ); + +#endif /* DRI_TEXMEM_H */ diff --git a/src/mesa/drivers/dri/common/utils.c b/src/mesa/drivers/dri/common/utils.c new file mode 100644 index 0000000..42be77f --- /dev/null +++ b/src/mesa/drivers/dri/common/utils.c @@ -0,0 +1,821 @@ +/* + * (C) Copyright IBM Corporation 2002, 2004 + * 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 + * 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 + * VA LINUX SYSTEM, IBM 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. + */ + +/** + * \file utils.c + * Utility functions for DRI drivers. + * + * \author Ian Romanick + */ + +#include +#include +#include "main/mtypes.h" +#include "main/cpuinfo.h" +#include "main/extensions.h" +#include "utils.h" + + +/** + * Print message to \c stderr if the \c LIBGL_DEBUG environment variable + * is set. + * + * Is called from the drivers. + * + * \param f \c printf like format string. + */ +void +__driUtilMessage(const char *f, ...) +{ + va_list args; + + if (getenv("LIBGL_DEBUG")) { + fprintf(stderr, "libGL: "); + va_start(args, f); + vfprintf(stderr, f, args); + va_end(args); + fprintf(stderr, "\n"); + } +} + + +unsigned +driParseDebugString( const char * debug, + const struct dri_debug_control * control ) +{ + unsigned flag; + + + flag = 0; + if ( debug != NULL ) { + while( control->string != NULL ) { + if ( !strcmp( debug, "all" ) || + strstr( debug, control->string ) != NULL ) { + flag |= control->flag; + } + + control++; + } + } + + return flag; +} + + + +/** + * Create the \c GL_RENDERER string for DRI drivers. + * + * Almost all DRI drivers use a \c GL_RENDERER string of the form: + * + * "Mesa DRI " + * + * Using the supplied chip name, driver data, and AGP speed, this function + * creates the string. + * + * \param buffer Buffer to hold the \c GL_RENDERER string. + * \param hardware_name Name of the hardware. + * \param driver_date Driver date. + * \param agp_mode AGP mode (speed). + * + * \returns + * The length of the string stored in \c buffer. This does \b not include + * the terminating \c NUL character. + */ +unsigned +driGetRendererString( char * buffer, const char * hardware_name, + const char * driver_date, GLuint agp_mode ) +{ + unsigned offset; + char *cpu; + + offset = sprintf( buffer, "Mesa DRI %s %s", hardware_name, driver_date ); + + /* Append any AGP-specific information. + */ + switch ( agp_mode ) { + case 1: + case 2: + case 4: + case 8: + offset += sprintf( & buffer[ offset ], " AGP %ux", agp_mode ); + break; + + default: + break; + } + + /* Append any CPU-specific information. + */ + cpu = _mesa_get_cpu_string(); + if (cpu) { + offset += sprintf(buffer + offset, " %s", cpu); + free(cpu); + } + + return offset; +} + + + + +#define need_GL_ARB_copy_buffer +#define need_GL_ARB_draw_buffers +#define need_GL_ARB_multisample +#define need_GL_ARB_texture_compression +#define need_GL_ARB_transpose_matrix +#define need_GL_ARB_vertex_buffer_object +#define need_GL_ARB_window_pos +#define need_GL_EXT_compiled_vertex_array +#define need_GL_EXT_multi_draw_arrays +#define need_GL_EXT_polygon_offset +#define need_GL_EXT_texture_object +#define need_GL_EXT_vertex_array +#define need_GL_IBM_multimode_draw_arrays +#define need_GL_MESA_window_pos + +/* These are needed in *all* drivers because Mesa internally implements + * certain functionality in terms of functions provided by these extensions. + * For example, glBlendFunc is implemented by calling glBlendFuncSeparateEXT. + */ +#define need_GL_EXT_blend_func_separate +#define need_GL_NV_vertex_program + +#include "main/remap_helper.h" + +static const struct dri_extension all_mesa_extensions[] = { + { "GL_ARB_copy_buffer", GL_ARB_copy_buffer_functions }, + { "GL_ARB_draw_buffers", GL_ARB_draw_buffers_functions }, + { "GL_ARB_multisample", GL_ARB_multisample_functions }, + { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions }, + { "GL_ARB_transpose_matrix", GL_ARB_transpose_matrix_functions }, + { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions}, + { "GL_ARB_window_pos", GL_ARB_window_pos_functions }, + { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions }, + { "GL_EXT_compiled_vertex_array", GL_EXT_compiled_vertex_array_functions }, + { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions }, + { "GL_EXT_polygon_offset", GL_EXT_polygon_offset_functions }, + { "GL_EXT_texture_object", GL_EXT_texture_object_functions }, + { "GL_EXT_vertex_array", GL_EXT_vertex_array_functions }, + { "GL_IBM_multimode_draw_arrays", GL_IBM_multimode_draw_arrays_functions }, + { "GL_MESA_window_pos", GL_MESA_window_pos_functions }, + { "GL_NV_vertex_program", GL_NV_vertex_program_functions }, + { NULL, NULL } +}; + + +/** + * Enable and map extensions supported by the driver. + * + * When ctx is NULL, extensions are not enabled, but their functions + * are still mapped. When extensions_to_enable is NULL, all static + * functions known to mesa core are mapped. + * + * \bug + * ARB_imaging isn't handled properly. In Mesa, enabling ARB_imaging also + * enables all the sub-extensions that are folded into it. This means that + * we need to add entry-points (via \c driInitSingleExtension) for those + * new functions here. + */ +void driInitExtensions( struct gl_context * ctx, + const struct dri_extension * extensions_to_enable, + GLboolean enable_imaging ) +{ + static int first_time = 1; + unsigned i; + + if ( first_time ) { + first_time = 0; + driInitExtensions( NULL, all_mesa_extensions, GL_FALSE ); + } + + if ( (ctx != NULL) && enable_imaging ) { + _mesa_enable_imaging_extensions( ctx ); + } + + /* The caller is too lazy to list any extension */ + if ( extensions_to_enable == NULL ) { + /* Map the static functions. Together with those mapped by remap + * table, this should cover everything mesa core knows. + */ + _mesa_map_static_functions(); + return; + } + + for ( i = 0 ; extensions_to_enable[i].name != NULL ; i++ ) { + driInitSingleExtension( ctx, & extensions_to_enable[i] ); + } +} + + + + +/** + * Enable and map functions for a single extension + * + * \param ctx Context where extension is to be enabled. + * \param ext Extension that is to be enabled. + * + * \sa driInitExtensions, _mesa_enable_extension, _mesa_map_function_array + */ +void driInitSingleExtension( struct gl_context * ctx, + const struct dri_extension * ext ) +{ + if ( ext->functions != NULL ) { + _mesa_map_function_array(ext->functions); + } + + if ( ctx != NULL ) { + _mesa_enable_extension( ctx, ext->name ); + } +} + + +/** + * Utility function used by drivers to test the verions of other components. + * + * \param driver_name Name of the driver. Used in error messages. + * \param driActual Actual DRI version supplied __driCreateNewScreen. + * \param driExpected Minimum DRI version required by the driver. + * \param ddxActual Actual DDX version supplied __driCreateNewScreen. + * \param ddxExpected Minimum DDX minor and range of DDX major version required by the driver. + * \param drmActual Actual DRM version supplied __driCreateNewScreen. + * \param drmExpected Minimum DRM version required by the driver. + * + * \returns \c GL_TRUE if all version requirements are met. Otherwise, + * \c GL_FALSE is returned. + * + * \sa __driCreateNewScreen, driCheckDriDdxDrmVersions2 + * + * \todo + * Now that the old \c driCheckDriDdxDrmVersions function is gone, this + * function and \c driCheckDriDdxDrmVersions2 should be renamed. + */ +GLboolean +driCheckDriDdxDrmVersions3(const char * driver_name, + const __DRIversion * driActual, + const __DRIversion * driExpected, + const __DRIversion * ddxActual, + const __DRIutilversion2 * ddxExpected, + const __DRIversion * drmActual, + const __DRIversion * drmExpected) +{ + static const char format[] = "%s DRI driver expected %s version %d.%d.x " + "but got version %d.%d.%d\n"; + static const char format2[] = "%s DRI driver expected %s version %d-%d.%d.x " + "but got version %d.%d.%d\n"; + + + /* Check the DRI version */ + if ( (driActual->major != driExpected->major) + || (driActual->minor < driExpected->minor) ) { + fprintf(stderr, format, driver_name, "DRI", + driExpected->major, driExpected->minor, + driActual->major, driActual->minor, driActual->patch); + return GL_FALSE; + } + + /* Check that the DDX driver version is compatible */ + if ( (ddxActual->major < ddxExpected->major_min) + || (ddxActual->major > ddxExpected->major_max) + || (ddxActual->minor < ddxExpected->minor) ) { + fprintf(stderr, format2, driver_name, "DDX", + ddxExpected->major_min, ddxExpected->major_max, ddxExpected->minor, + ddxActual->major, ddxActual->minor, ddxActual->patch); + return GL_FALSE; + } + + /* Check that the DRM driver version is compatible */ + if ( (drmActual->major != drmExpected->major) + || (drmActual->minor < drmExpected->minor) ) { + fprintf(stderr, format, driver_name, "DRM", + drmExpected->major, drmExpected->minor, + drmActual->major, drmActual->minor, drmActual->patch); + return GL_FALSE; + } + + return GL_TRUE; +} + +GLboolean +driCheckDriDdxDrmVersions2(const char * driver_name, + const __DRIversion * driActual, + const __DRIversion * driExpected, + const __DRIversion * ddxActual, + const __DRIversion * ddxExpected, + const __DRIversion * drmActual, + const __DRIversion * drmExpected) +{ + __DRIutilversion2 ddx_expected; + ddx_expected.major_min = ddxExpected->major; + ddx_expected.major_max = ddxExpected->major; + ddx_expected.minor = ddxExpected->minor; + ddx_expected.patch = ddxExpected->patch; + return driCheckDriDdxDrmVersions3(driver_name, driActual, + driExpected, ddxActual, & ddx_expected, + drmActual, drmExpected); +} + +GLboolean driClipRectToFramebuffer( const struct gl_framebuffer *buffer, + GLint *x, GLint *y, + GLsizei *width, GLsizei *height ) +{ + /* left clipping */ + if (*x < buffer->_Xmin) { + *width -= (buffer->_Xmin - *x); + *x = buffer->_Xmin; + } + + /* right clipping */ + if (*x + *width > buffer->_Xmax) + *width -= (*x + *width - buffer->_Xmax - 1); + + if (*width <= 0) + return GL_FALSE; + + /* bottom clipping */ + if (*y < buffer->_Ymin) { + *height -= (buffer->_Ymin - *y); + *y = buffer->_Ymin; + } + + /* top clipping */ + if (*y + *height > buffer->_Ymax) + *height -= (*y + *height - buffer->_Ymax - 1); + + if (*height <= 0) + return GL_FALSE; + + return GL_TRUE; +} + +/** + * Creates a set of \c struct gl_config that a driver will expose. + * + * A set of \c struct gl_config will be created based on the supplied + * parameters. The number of modes processed will be 2 * + * \c num_depth_stencil_bits * \c num_db_modes. + * + * For the most part, data is just copied from \c depth_bits, \c stencil_bits, + * \c db_modes, and \c visType into each \c struct gl_config element. + * However, the meanings of \c fb_format and \c fb_type require further + * explanation. The \c fb_format specifies which color components are in + * each pixel and what the default order is. For example, \c GL_RGB specifies + * that red, green, blue are available and red is in the "most significant" + * position and blue is in the "least significant". The \c fb_type specifies + * the bit sizes of each component and the actual ordering. For example, if + * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11] + * are the blue value, bits [10:5] are the green value, and bits [4:0] are + * the red value. + * + * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either + * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the + * \c struct gl_config structure is \b identical to the \c GL_RGBA or + * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as + * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8 + * still uses 32-bits. + * + * If in doubt, look at the tables used in the function. + * + * \param ptr_to_modes Pointer to a pointer to a linked list of + * \c struct gl_config. Upon completion, a pointer to + * the next element to be process will be stored here. + * If the function fails and returns \c GL_FALSE, this + * value will be unmodified, but some elements in the + * linked list may be modified. + * \param fb_format Format of the framebuffer. Currently only \c GL_RGB, + * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported. + * \param fb_type Type of the pixels in the framebuffer. Currently only + * \c GL_UNSIGNED_SHORT_5_6_5, + * \c GL_UNSIGNED_SHORT_5_6_5_REV, + * \c GL_UNSIGNED_INT_8_8_8_8, and + * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported. + * \param depth_bits Array of depth buffer sizes to be exposed. + * \param stencil_bits Array of stencil buffer sizes to be exposed. + * \param num_depth_stencil_bits Number of entries in both \c depth_bits and + * \c stencil_bits. + * \param db_modes Array of buffer swap modes. If an element has a + * value of \c GLX_NONE, then it represents a + * single-buffered mode. Other valid values are + * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and + * \c GLX_SWAP_UNDEFINED_OML. See the + * GLX_OML_swap_method extension spec for more details. + * \param num_db_modes Number of entries in \c db_modes. + * \param msaa_samples Array of msaa sample count. 0 represents a visual + * without a multisample buffer. + * \param num_msaa_modes Number of entries in \c msaa_samples. + * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or + * \c GLX_DIRECT_COLOR. + * + * \returns + * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only + * cause of failure is a bad parameter (i.e., unsupported \c fb_format or + * \c fb_type). + * + * \todo + * There is currently no way to support packed RGB modes (i.e., modes with + * exactly 3 bytes per pixel) or floating-point modes. This could probably + * be done by creating some new, private enums with clever names likes + * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32, + * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it. + */ +__DRIconfig ** +driCreateConfigs(GLenum fb_format, GLenum fb_type, + const uint8_t * depth_bits, const uint8_t * stencil_bits, + unsigned num_depth_stencil_bits, + const GLenum * db_modes, unsigned num_db_modes, + const uint8_t * msaa_samples, unsigned num_msaa_modes, + GLboolean enable_accum) +{ + static const uint8_t bits_table[4][4] = { + /* R G B A */ + { 3, 3, 2, 0 }, /* Any GL_UNSIGNED_BYTE_3_3_2 */ + { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */ + { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */ + { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */ + }; + + static const uint32_t masks_table_rgb[6][4] = { + { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */ + { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */ + { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */ + { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */ + { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000 }, /* 8_8_8_8 */ + { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 } /* 8_8_8_8_REV */ + }; + + static const uint32_t masks_table_rgba[6][4] = { + { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2 */ + { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV */ + { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */ + { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */ + { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF }, /* 8_8_8_8 */ + { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */ + }; + + static const uint32_t masks_table_bgr[6][4] = { + { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */ + { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */ + { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */ + { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */ + { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, /* 8_8_8_8 */ + { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */ + }; + + static const uint32_t masks_table_bgra[6][4] = { + { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2 */ + { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV */ + { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */ + { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */ + { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, /* 8_8_8_8 */ + { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */ + }; + + static const uint8_t bytes_per_pixel[6] = { + 1, /* 3_3_2 */ + 1, /* 2_3_3_REV */ + 2, /* 5_6_5 */ + 2, /* 5_6_5_REV */ + 4, /* 8_8_8_8 */ + 4 /* 8_8_8_8_REV */ + }; + + const uint8_t * bits; + const uint32_t * masks; + int index; + __DRIconfig **configs, **c; + struct gl_config *modes; + unsigned i, j, k, h; + unsigned num_modes; + unsigned num_accum_bits = (enable_accum) ? 2 : 1; + + switch ( fb_type ) { + case GL_UNSIGNED_BYTE_3_3_2: + index = 0; + break; + case GL_UNSIGNED_BYTE_2_3_3_REV: + index = 1; + break; + case GL_UNSIGNED_SHORT_5_6_5: + index = 2; + break; + case GL_UNSIGNED_SHORT_5_6_5_REV: + index = 3; + break; + case GL_UNSIGNED_INT_8_8_8_8: + index = 4; + break; + case GL_UNSIGNED_INT_8_8_8_8_REV: + index = 5; + break; + default: + fprintf( stderr, "[%s:%u] Unknown framebuffer type 0x%04x.\n", + __FUNCTION__, __LINE__, fb_type ); + return NULL; + } + + + /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and + * the _REV versions. + * + * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA. + */ + + switch ( fb_format ) { + case GL_RGB: + masks = masks_table_rgb[ index ]; + break; + + case GL_RGBA: + masks = masks_table_rgba[ index ]; + break; + + case GL_BGR: + masks = masks_table_bgr[ index ]; + break; + + case GL_BGRA: + masks = masks_table_bgra[ index ]; + break; + + default: + fprintf( stderr, "[%s:%u] Unknown framebuffer format 0x%04x.\n", + __FUNCTION__, __LINE__, fb_format ); + return NULL; + } + + switch ( bytes_per_pixel[ index ] ) { + case 1: + bits = bits_table[0]; + break; + case 2: + bits = bits_table[1]; + break; + default: + bits = ((fb_format == GL_RGB) || (fb_format == GL_BGR)) + ? bits_table[2] + : bits_table[3]; + break; + } + + num_modes = num_depth_stencil_bits * num_db_modes * num_accum_bits * num_msaa_modes; + configs = calloc(1, (num_modes + 1) * sizeof *configs); + if (configs == NULL) + return NULL; + + c = configs; + for ( k = 0 ; k < num_depth_stencil_bits ; k++ ) { + for ( i = 0 ; i < num_db_modes ; i++ ) { + for ( h = 0 ; h < num_msaa_modes; h++ ) { + for ( j = 0 ; j < num_accum_bits ; j++ ) { + *c = malloc (sizeof **c); + modes = &(*c)->modes; + c++; + + memset(modes, 0, sizeof *modes); + modes->redBits = bits[0]; + modes->greenBits = bits[1]; + modes->blueBits = bits[2]; + modes->alphaBits = bits[3]; + modes->redMask = masks[0]; + modes->greenMask = masks[1]; + modes->blueMask = masks[2]; + modes->alphaMask = masks[3]; + modes->rgbBits = modes->redBits + modes->greenBits + + modes->blueBits + modes->alphaBits; + + modes->accumRedBits = 16 * j; + modes->accumGreenBits = 16 * j; + modes->accumBlueBits = 16 * j; + modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0; + modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG; + + modes->stencilBits = stencil_bits[k]; + modes->depthBits = depth_bits[k]; + + modes->transparentPixel = GLX_NONE; + modes->transparentRed = GLX_DONT_CARE; + modes->transparentGreen = GLX_DONT_CARE; + modes->transparentBlue = GLX_DONT_CARE; + modes->transparentAlpha = GLX_DONT_CARE; + modes->transparentIndex = GLX_DONT_CARE; + modes->rgbMode = GL_TRUE; + + if ( db_modes[i] == GLX_NONE ) { + modes->doubleBufferMode = GL_FALSE; + } + else { + modes->doubleBufferMode = GL_TRUE; + modes->swapMethod = db_modes[i]; + } + + modes->samples = msaa_samples[h]; + modes->sampleBuffers = modes->samples ? 1 : 0; + + + modes->haveAccumBuffer = ((modes->accumRedBits + + modes->accumGreenBits + + modes->accumBlueBits + + modes->accumAlphaBits) > 0); + modes->haveDepthBuffer = (modes->depthBits > 0); + modes->haveStencilBuffer = (modes->stencilBits > 0); + + modes->bindToTextureRgb = GL_TRUE; + modes->bindToTextureRgba = GL_TRUE; + modes->bindToMipmapTexture = GL_FALSE; + modes->bindToTextureTargets = + __DRI_ATTRIB_TEXTURE_1D_BIT | + __DRI_ATTRIB_TEXTURE_2D_BIT | + __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT; + } + } + } + } + *c = NULL; + + return configs; +} + +__DRIconfig **driConcatConfigs(__DRIconfig **a, + __DRIconfig **b) +{ + __DRIconfig **all; + int i, j, index; + + i = 0; + while (a[i] != NULL) + i++; + j = 0; + while (b[j] != NULL) + j++; + + all = malloc((i + j + 1) * sizeof *all); + index = 0; + for (i = 0; a[i] != NULL; i++) + all[index++] = a[i]; + for (j = 0; b[j] != NULL; j++) + all[index++] = b[j]; + all[index++] = NULL; + + free(a); + free(b); + + return all; +} + +#define __ATTRIB(attrib, field) \ + { attrib, offsetof(struct gl_config, field) } + +static const struct { unsigned int attrib, offset; } attribMap[] = { + __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits), + __ATTRIB(__DRI_ATTRIB_LEVEL, level), + __ATTRIB(__DRI_ATTRIB_RED_SIZE, redBits), + __ATTRIB(__DRI_ATTRIB_GREEN_SIZE, greenBits), + __ATTRIB(__DRI_ATTRIB_BLUE_SIZE, blueBits), + __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE, alphaBits), + __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE, depthBits), + __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE, stencilBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE, accumRedBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE, accumGreenBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE, accumBlueBits), + __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE, accumAlphaBits), + __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS, sampleBuffers), + __ATTRIB(__DRI_ATTRIB_SAMPLES, samples), + __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER, doubleBufferMode), + __ATTRIB(__DRI_ATTRIB_STEREO, stereoMode), + __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS, numAuxBuffers), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE, transparentPixel), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE, transparentPixel), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE, transparentRed), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE, transparentGreen), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue), + __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha), + __ATTRIB(__DRI_ATTRIB_FLOAT_MODE, floatMode), + __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask), + __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask), + __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask), + __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask), + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth), + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight), + __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels), + __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth), + __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight), + __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod), + __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb), + __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba), + __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE, bindToMipmapTexture), + __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS, bindToTextureTargets), + __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted), + + /* The struct field doesn't matter here, these are handled by the + * switch in driGetConfigAttribIndex. We need them in the array + * so the iterator includes them though.*/ + __ATTRIB(__DRI_ATTRIB_RENDER_TYPE, level), + __ATTRIB(__DRI_ATTRIB_CONFIG_CAVEAT, level), + __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, level) +}; + +#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) + + +/** + * Return the value of a configuration attribute. The attribute is + * indicated by the index. + */ +static int +driGetConfigAttribIndex(const __DRIconfig *config, + unsigned int index, unsigned int *value) +{ + switch (attribMap[index].attrib) { + case __DRI_ATTRIB_RENDER_TYPE: + /* no support for color index mode */ + *value = __DRI_ATTRIB_RGBA_BIT; + break; + case __DRI_ATTRIB_CONFIG_CAVEAT: + if (config->modes.visualRating == GLX_NON_CONFORMANT_CONFIG) + *value = __DRI_ATTRIB_NON_CONFORMANT_CONFIG; + else if (config->modes.visualRating == GLX_SLOW_CONFIG) + *value = __DRI_ATTRIB_SLOW_BIT; + else + *value = 0; + break; + case __DRI_ATTRIB_SWAP_METHOD: + /* XXX no return value??? */ + break; + + case __DRI_ATTRIB_FLOAT_MODE: + /* this field is not int-sized */ + *value = config->modes.floatMode; + break; + + default: + /* any other int-sized field */ + *value = *(unsigned int *) + ((char *) &config->modes + attribMap[index].offset); + + break; + } + + return GL_TRUE; +} + + +/** + * Get the value of a configuration attribute. + * \param attrib the attribute (one of the _DRI_ATTRIB_x tokens) + * \param value returns the attribute's value + * \return 1 for success, 0 for failure + */ +int +driGetConfigAttrib(const __DRIconfig *config, + unsigned int attrib, unsigned int *value) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(attribMap); i++) + if (attribMap[i].attrib == attrib) + return driGetConfigAttribIndex(config, i, value); + + return GL_FALSE; +} + + +/** + * Get a configuration attribute name and value, given an index. + * \param index which field of the __DRIconfig to query + * \param attrib returns the attribute name (one of the _DRI_ATTRIB_x tokens) + * \param value returns the attribute's value + * \return 1 for success, 0 for failure + */ +int +driIndexConfigAttrib(const __DRIconfig *config, int index, + unsigned int *attrib, unsigned int *value) +{ + if (index >= 0 && index < ARRAY_SIZE(attribMap)) { + *attrib = attribMap[index].attrib; + return driGetConfigAttribIndex(config, index, value); + } + + return GL_FALSE; +} diff --git a/src/mesa/drivers/dri/common/utils.h b/src/mesa/drivers/dri/common/utils.h new file mode 100644 index 0000000..6349fb4 --- /dev/null +++ b/src/mesa/drivers/dri/common/utils.h @@ -0,0 +1,123 @@ +/* + * (C) Copyright IBM Corporation 2002, 2004 + * 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 + * 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 + * VA LINUX SYSTEM, IBM 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. + * + * Authors: + * Ian Romanick + */ + +#ifndef DRI_DEBUG_H +#define DRI_DEBUG_H + +#include +#include +#include "main/context.h" +#include "main/remap.h" + +typedef struct __DRIutilversionRec2 __DRIutilversion2; + +struct dri_debug_control { + const char * string; + unsigned flag; +}; + +/** + * Description of the API for an extension to OpenGL. + */ +struct dri_extension { + /** + * Name of the extension. + */ + const char * name; + + + /** + * Pointer to a list of \c dri_extension_function structures. The list + * is terminated by a structure with a \c NULL + * \c dri_extension_function::strings pointer. + */ + const struct gl_function_remap * functions; +}; + +/** + * Used to store a version which includes a major range instead of a single + * major version number. + */ +struct __DRIutilversionRec2 { + int major_min; /** min allowed Major version number. */ + int major_max; /** max allowed Major version number. */ + int minor; /**< Minor version number. */ + int patch; /**< Patch-level. */ +}; + +extern void +__driUtilMessage(const char *f, ...); + +extern unsigned driParseDebugString( const char * debug, + const struct dri_debug_control * control ); + +extern unsigned driGetRendererString( char * buffer, + const char * hardware_name, const char * driver_date, GLuint agp_mode ); + +extern void driInitExtensions( struct gl_context * ctx, + const struct dri_extension * card_extensions, GLboolean enable_imaging ); + +extern void driInitSingleExtension( struct gl_context * ctx, + const struct dri_extension * ext ); + +extern GLboolean driCheckDriDdxDrmVersions2(const char * driver_name, + const __DRIversion * driActual, const __DRIversion * driExpected, + const __DRIversion * ddxActual, const __DRIversion * ddxExpected, + const __DRIversion * drmActual, const __DRIversion * drmExpected); + +extern GLboolean driCheckDriDdxDrmVersions3(const char * driver_name, + const __DRIversion * driActual, const __DRIversion * driExpected, + const __DRIversion * ddxActual, const __DRIutilversion2 * ddxExpected, + const __DRIversion * drmActual, const __DRIversion * drmExpected); + +extern GLboolean driClipRectToFramebuffer( const struct gl_framebuffer *buffer, + GLint *x, GLint *y, + GLsizei *width, GLsizei *height ); + +struct __DRIconfigRec { + struct gl_config modes; +}; + +extern __DRIconfig ** +driCreateConfigs(GLenum fb_format, GLenum fb_type, + const uint8_t * depth_bits, const uint8_t * stencil_bits, + unsigned num_depth_stencil_bits, + const GLenum * db_modes, unsigned num_db_modes, + const uint8_t * msaa_samples, unsigned num_msaa_modes, + GLboolean enable_accum); + +__DRIconfig **driConcatConfigs(__DRIconfig **a, + __DRIconfig **b); + +int +driGetConfigAttrib(const __DRIconfig *config, + unsigned int attrib, unsigned int *value); +int +driIndexConfigAttrib(const __DRIconfig *config, int index, + unsigned int *attrib, unsigned int *value); + +#endif /* DRI_DEBUG_H */ diff --git a/src/mesa/drivers/dri/common/vblank.c b/src/mesa/drivers/dri/common/vblank.c new file mode 100644 index 0000000..cb98dd0 --- /dev/null +++ b/src/mesa/drivers/dri/common/vblank.c @@ -0,0 +1,434 @@ +/* -*- mode: c; c-basic-offset: 3 -*- */ +/* + * (c) Copyright IBM Corporation 2002 + * 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 + * 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 + * VA LINUX SYSTEM, IBM 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. + * + * Authors: + * Ian Romanick + */ + +#include "main/glheader.h" +#include "xf86drm.h" +#include "main/mtypes.h" +#include "main/macros.h" +#include "main/dd.h" +#include "vblank.h" +#include "xmlpool.h" + +static unsigned int msc_to_vblank(__DRIdrawable * dPriv, int64_t msc) +{ + return (unsigned int)(msc - dPriv->msc_base + dPriv->vblank_base); +} + +static int64_t vblank_to_msc(__DRIdrawable * dPriv, unsigned int vblank) +{ + return (int64_t)(vblank - dPriv->vblank_base + dPriv->msc_base); +} + + +/****************************************************************************/ +/** + * Get the current MSC refresh counter. + * + * Stores the 64-bit count of vertical refreshes since some (arbitrary) + * point in time in \c count. Unless the value wraps around, which it + * may, it will never decrease for a given drawable. + * + * \warning This function is called from \c glXGetVideoSyncSGI, which expects + * a \c count of type \c unsigned (32-bit), and \c glXGetSyncValuesOML, which + * expects a \c count of type \c int64_t (signed 64-bit). The kernel ioctl + * currently always returns a \c sequence of type \c unsigned. + * + * \param priv Pointer to the DRI screen private struct. + * \param dPriv Pointer to the DRI drawable private struct + * \param count Storage to hold MSC counter. + * \return Zero is returned on success. A negative errno value + * is returned on failure. + */ +int driDrawableGetMSC32( __DRIscreen * priv, + __DRIdrawable * dPriv, + int64_t * count) +{ + drmVBlank vbl; + int ret; + + /* Don't wait for anything. Just get the current refresh count. */ + + vbl.request.type = DRM_VBLANK_RELATIVE; + vbl.request.sequence = 0; + if ( dPriv && dPriv->vblFlags & VBLANK_FLAG_SECONDARY ) + vbl.request.type |= DRM_VBLANK_SECONDARY; + + ret = drmWaitVBlank( priv->fd, &vbl ); + + if (dPriv) { + *count = vblank_to_msc(dPriv, vbl.reply.sequence); + } else { + /* Old driver (no knowledge of drawable MSC callback) */ + *count = vbl.reply.sequence; + } + + return ret; +} + +/****************************************************************************/ +/** + * Wait for a specified refresh count. This implements most of the + * functionality of \c glXWaitForMscOML from the GLX_OML_sync_control spec. + * Waits for the \c target_msc refresh. If that has already passed, it + * waits until \f$(MSC \bmod divisor)\f$ is equal to \c remainder. If + * \c target_msc is 0, use the behavior of glXWaitVideoSyncSGI(), which + * omits the initial check against a target MSC value. + * + * This function is actually something of a hack. The problem is that, at + * the time of this writing, none of the existing DRM modules support an + * ioctl that returns a 64-bit count (at least not on 32-bit platforms). + * However, this function exists to support a GLX function that requires + * the use of 64-bit counts. As such, there is a little bit of ugly + * hackery at the end of this function to make the 32-bit count act like + * a 64-bit count. There are still some cases where this will break, but + * I believe it catches the most common cases. + * + * The real solution is to provide an ioctl that uses a 64-bit count. + * + * \param dpy Pointer to the \c Display. + * \param priv Pointer to the DRI drawable private. + * \param target_msc Desired refresh count to wait for. A value of 0 + * means to use the glXWaitVideoSyncSGI() behavior. + * \param divisor MSC divisor if \c target_msc is already reached. + * \param remainder Desired MSC remainder if \c target_msc is already + * reached. + * \param msc Buffer to hold MSC when done waiting. + * + * \return Zero on success or \c GLX_BAD_CONTEXT on failure. + */ + +int driWaitForMSC32( __DRIdrawable *priv, + int64_t target_msc, int64_t divisor, int64_t remainder, + int64_t * msc ) +{ + drmVBlank vbl; + + + if ( divisor != 0 ) { + int64_t next = target_msc; + int64_t r; + int dont_wait = (target_msc == 0); + + do { + /* dont_wait means we're using the glXWaitVideoSyncSGI() behavior. + * The first time around, just get the current count and proceed + * to the test for (MSC % divisor) == remainder. + */ + vbl.request.type = dont_wait ? DRM_VBLANK_RELATIVE : + DRM_VBLANK_ABSOLUTE; + vbl.request.sequence = next ? msc_to_vblank(priv, next) : 0; + if ( priv->vblFlags & VBLANK_FLAG_SECONDARY ) + vbl.request.type |= DRM_VBLANK_SECONDARY; + + if ( drmWaitVBlank( priv->driScreenPriv->fd, &vbl ) != 0 ) { + /* FIXME: This doesn't seem like the right thing to return here. + */ + return GLX_BAD_CONTEXT; + } + + *msc = vblank_to_msc(priv, vbl.reply.sequence); + + if (!dont_wait && *msc == next) + break; + dont_wait = 0; + + /* Assuming the wait-done test fails, the next refresh to wait for + * will be one that satisfies (MSC % divisor) == remainder. The + * value (MSC - (MSC % divisor) + remainder) is the refresh value + * closest to the current value that would satisfy the equation. + * If this refresh has already happened, we add divisor to obtain + * the next refresh after the current one that will satisfy it. + */ + r = ((uint64_t)*msc % divisor); + next = (*msc - r + remainder); + if (next <= *msc) + next += divisor; + + } while (r != remainder); + } + else { + /* If the \c divisor is zero, just wait until the MSC is greater + * than or equal to \c target_msc. + */ + + vbl.request.type = DRM_VBLANK_ABSOLUTE; + vbl.request.sequence = target_msc ? msc_to_vblank(priv, target_msc) : 0; + + if ( priv->vblFlags & VBLANK_FLAG_SECONDARY ) + vbl.request.type |= DRM_VBLANK_SECONDARY; + + if ( drmWaitVBlank( priv->driScreenPriv->fd, &vbl ) != 0 ) { + /* FIXME: This doesn't seem like the right thing to return here. + */ + return GLX_BAD_CONTEXT; + } + } + + *msc = vblank_to_msc(priv, vbl.reply.sequence); + + if ( *msc < target_msc ) { + *msc += 0x0000000100000000LL; + } + + return 0; +} + + +/****************************************************************************/ +/** + * Gets a set of default vertical-blank-wait flags based on the internal GLX + * API version and several configuration options. + */ + +GLuint driGetDefaultVBlankFlags( const driOptionCache *optionCache ) +{ + GLuint flags = VBLANK_FLAG_INTERVAL; + int vblank_mode; + + + if ( driCheckOption( optionCache, "vblank_mode", DRI_ENUM ) ) + vblank_mode = driQueryOptioni( optionCache, "vblank_mode" ); + else + vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1; + + switch (vblank_mode) { + case DRI_CONF_VBLANK_NEVER: + flags = 0; + break; + case DRI_CONF_VBLANK_DEF_INTERVAL_0: + break; + case DRI_CONF_VBLANK_DEF_INTERVAL_1: + flags |= VBLANK_FLAG_THROTTLE; + break; + case DRI_CONF_VBLANK_ALWAYS_SYNC: + flags |= VBLANK_FLAG_SYNC; + break; + } + + return flags; +} + + +/****************************************************************************/ +/** + * Wrapper to call \c drmWaitVBlank. The main purpose of this function is to + * wrap the error message logging. The error message should only be logged + * the first time the \c drmWaitVBlank fails. If \c drmWaitVBlank is + * successful, \c vbl_seq will be set the sequence value in the reply. + * + * \param vbl Pointer to drmVBlank packet describing how to wait. + * \param vbl_seq Location to store the current refresh counter. + * \param fd File descriptor use to call into the DRM. + * \return Zero on success or -1 on failure. + */ + +static int do_wait( drmVBlank * vbl, GLuint * vbl_seq, int fd ) +{ + int ret; + + + ret = drmWaitVBlank( fd, vbl ); + if ( ret != 0 ) { + static GLboolean first_time = GL_TRUE; + + if ( first_time ) { + fprintf(stderr, + "%s: drmWaitVBlank returned %d, IRQs don't seem to be" + " working correctly.\nTry adjusting the vblank_mode" + " configuration parameter.\n", __FUNCTION__, ret); + first_time = GL_FALSE; + } + + return -1; + } + + *vbl_seq = vbl->reply.sequence; + return 0; +} + + +/****************************************************************************/ +/** + * Returns the default swap interval of the given drawable. + */ + +static unsigned +driGetDefaultVBlankInterval( const __DRIdrawable *priv ) +{ + if ( (priv->vblFlags & (VBLANK_FLAG_THROTTLE | VBLANK_FLAG_SYNC)) != 0 ) { + return 1; + } + else { + return 0; + } +} + + +/****************************************************************************/ +/** + * Sets the default swap interval when the drawable is first bound to a + * direct rendering context. + */ + +void driDrawableInitVBlank( __DRIdrawable *priv ) +{ + if ( priv->swap_interval == (unsigned)-1 && + !( priv->vblFlags & VBLANK_FLAG_NO_IRQ ) ) { + /* Get current vertical blank sequence */ + drmVBlank vbl; + + vbl.request.type = DRM_VBLANK_RELATIVE; + if ( priv->vblFlags & VBLANK_FLAG_SECONDARY ) + vbl.request.type |= DRM_VBLANK_SECONDARY; + vbl.request.sequence = 0; + do_wait( &vbl, &priv->vblSeq, priv->driScreenPriv->fd ); + priv->vblank_base = priv->vblSeq; + + priv->swap_interval = driGetDefaultVBlankInterval( priv ); + } +} + + +/****************************************************************************/ +/** + * Returns the current swap interval of the given drawable. + */ + +unsigned +driGetVBlankInterval( const __DRIdrawable *priv ) +{ + if ( (priv->vblFlags & VBLANK_FLAG_INTERVAL) != 0 ) { + /* this must have been initialized when the drawable was first bound + * to a direct rendering context. */ + assert ( priv->swap_interval != (unsigned)-1 ); + + return priv->swap_interval; + } + else + return driGetDefaultVBlankInterval( priv ); +} + + +/****************************************************************************/ +/** + * Returns the current vertical blank sequence number of the given drawable. + */ + +void +driGetCurrentVBlank( __DRIdrawable *priv ) +{ + drmVBlank vbl; + + vbl.request.type = DRM_VBLANK_RELATIVE; + if ( priv->vblFlags & VBLANK_FLAG_SECONDARY ) { + vbl.request.type |= DRM_VBLANK_SECONDARY; + } + vbl.request.sequence = 0; + + (void) do_wait( &vbl, &priv->vblSeq, priv->driScreenPriv->fd ); +} + + +/****************************************************************************/ +/** + * Waits for the vertical blank for use with glXSwapBuffers. + * + * \param missed_deadline Set to \c GL_TRUE if the MSC after waiting is later + * than the "target" based on \c priv->vblFlags. The idea is + * that if \c missed_deadline is set, then the application is + * not achieving its desired framerate. + * \return Zero on success, -1 on error. + */ + +int +driWaitForVBlank( __DRIdrawable *priv, GLboolean * missed_deadline ) +{ + drmVBlank vbl; + unsigned original_seq; + unsigned deadline; + unsigned interval; + unsigned diff; + + *missed_deadline = GL_FALSE; + if ( (priv->vblFlags & (VBLANK_FLAG_INTERVAL | + VBLANK_FLAG_THROTTLE | + VBLANK_FLAG_SYNC)) == 0 || + (priv->vblFlags & VBLANK_FLAG_NO_IRQ) != 0 ) { + return 0; + } + + + /* VBLANK_FLAG_SYNC means to wait for at least one vertical blank. If + * that flag is not set, do a fake wait for zero vertical blanking + * periods so that we can get the current MSC. + * + * VBLANK_FLAG_INTERVAL and VBLANK_FLAG_THROTTLE mean to wait for at + * least one vertical blank since the last wait. Since do_wait modifies + * priv->vblSeq, we have to save the original value of priv->vblSeq for the + * VBLANK_FLAG_INTERVAL / VBLANK_FLAG_THROTTLE calculation later. + */ + + original_seq = priv->vblSeq; + interval = driGetVBlankInterval(priv); + deadline = original_seq + interval; + + vbl.request.type = DRM_VBLANK_RELATIVE; + if ( priv->vblFlags & VBLANK_FLAG_SECONDARY ) { + vbl.request.type |= DRM_VBLANK_SECONDARY; + } + vbl.request.sequence = ((priv->vblFlags & VBLANK_FLAG_SYNC) != 0) ? 1 : 0; + + if ( do_wait( & vbl, &priv->vblSeq, priv->driScreenPriv->fd ) != 0 ) { + return -1; + } + + diff = priv->vblSeq - deadline; + + /* No need to wait again if we've already reached the target */ + if (diff <= (1 << 23)) { + *missed_deadline = (priv->vblFlags & VBLANK_FLAG_SYNC) ? (diff > 0) : + GL_TRUE; + return 0; + } + + /* Wait until the target vertical blank. */ + vbl.request.type = DRM_VBLANK_ABSOLUTE; + if ( priv->vblFlags & VBLANK_FLAG_SECONDARY ) { + vbl.request.type |= DRM_VBLANK_SECONDARY; + } + vbl.request.sequence = deadline; + + if ( do_wait( & vbl, &priv->vblSeq, priv->driScreenPriv->fd ) != 0 ) { + return -1; + } + + diff = priv->vblSeq - deadline; + *missed_deadline = diff > 0 && diff <= (1 << 23); + + return 0; +} diff --git a/src/mesa/drivers/dri/common/vblank.h b/src/mesa/drivers/dri/common/vblank.h new file mode 100644 index 0000000..067fb5e --- /dev/null +++ b/src/mesa/drivers/dri/common/vblank.h @@ -0,0 +1,71 @@ +/* -*- mode: c; c-basic-offset: 3 -*- */ +/* + * (c) Copyright IBM Corporation 2002 + * 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 + * 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 + * VA LINUX SYSTEM, IBM 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. + * + * Authors: + * Ian Romanick + */ + +#ifndef DRI_VBLANK_H +#define DRI_VBLANK_H + +#include "main/context.h" +#include "dri_util.h" +#include "xmlconfig.h" + +#define VBLANK_FLAG_INTERVAL (1U << 0) /* Respect the swap_interval setting + */ +#define VBLANK_FLAG_THROTTLE (1U << 1) /* Wait 1 refresh since last call. + */ +#define VBLANK_FLAG_SYNC (1U << 2) /* Sync to the next refresh. + */ +#define VBLANK_FLAG_NO_IRQ (1U << 7) /* DRM has no IRQ to wait on. + */ +#define VBLANK_FLAG_SECONDARY (1U << 8) /* Wait for secondary vblank. + */ + +extern int driGetMSC32( __DRIscreen * priv, int64_t * count ); +extern int driDrawableGetMSC32( __DRIscreen * priv, + __DRIdrawable * drawablePrivate, + int64_t * count); +extern int driWaitForMSC32( __DRIdrawable *priv, + int64_t target_msc, int64_t divisor, int64_t remainder, int64_t * msc ); +extern GLuint driGetDefaultVBlankFlags( const driOptionCache *optionCache ); +extern void driDrawableInitVBlank ( __DRIdrawable *priv ); +extern unsigned driGetVBlankInterval( const __DRIdrawable *priv ); +extern void driGetCurrentVBlank( __DRIdrawable *priv ); +extern int driWaitForVBlank( __DRIdrawable *priv, + GLboolean * missed_deadline ); + +#undef usleep +#include /* for usleep() */ +#include /* for sched_yield() */ + +#define DO_USLEEP(nr) \ + do { \ + if (0) fprintf(stderr, "%s: usleep for %u\n", __FUNCTION__, nr ); \ + if (1) usleep( nr ); \ + sched_yield(); \ + } while( 0 ) + +#endif /* DRI_VBLANK_H */ diff --git a/src/mesa/drivers/dri/common/xmlconfig.c b/src/mesa/drivers/dri/common/xmlconfig.c new file mode 100644 index 0000000..0312c07 --- /dev/null +++ b/src/mesa/drivers/dri/common/xmlconfig.c @@ -0,0 +1,1004 @@ +/* + * XML DRI client-side driver configuration + * Copyright (C) 2003 Felix Kuehling + * + * 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 + * FELIX KUEHLING, OR ANY OTHER CONTRIBUTORS 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 xmlconfig.c + * \brief Driver-independent client-side part of the XML configuration + * \author Felix Kuehling + */ + +#include "main/glheader.h" + +#include +#include +#include +#include +#include +#include +#include "main/imports.h" +#include "utils.h" +#include "xmlconfig.h" + +#undef GET_PROGRAM_NAME + +#if (defined(__GNU_LIBRARY__) || defined(__GLIBC__)) && !defined(__UCLIBC__) +# if !defined(__GLIBC__) || (__GLIBC__ < 2) +/* These aren't declared in any libc5 header */ +extern char *program_invocation_name, *program_invocation_short_name; +# endif +# define GET_PROGRAM_NAME() program_invocation_short_name +#elif defined(__FreeBSD__) && (__FreeBSD__ >= 2) +# include +# if (__FreeBSD_version >= 440000) +# include +# define GET_PROGRAM_NAME() getprogname() +# endif +#elif defined(__NetBSD__) && defined(__NetBSD_Version) && (__NetBSD_Version >= 106000100) +# include +# define GET_PROGRAM_NAME() getprogname() +#elif defined(__APPLE__) +# include +# define GET_PROGRAM_NAME() getprogname() +#elif defined(__sun) +/* Solaris has getexecname() which returns the full path - return just + the basename to match BSD getprogname() */ +# include +# include +# define GET_PROGRAM_NAME() basename(getexecname()) +#endif + +#if !defined(GET_PROGRAM_NAME) +# if defined(__OpenBSD__) || defined(NetBSD) || defined(__UCLIBC__) +/* This is a hack. It's said to work on OpenBSD, NetBSD and GNU. + * Rogelio M.Serrano Jr. reported it's also working with UCLIBC. It's + * used as a last resort, if there is no documented facility available. */ +static const char *__getProgramName () { + extern const char *__progname; + char * arg = strrchr(__progname, '/'); + if (arg) + return arg+1; + else + return __progname; +} +# define GET_PROGRAM_NAME() __getProgramName() +# else +# define GET_PROGRAM_NAME() "" +# warning "Per application configuration won't work with your OS version." +# endif +#endif + +/** \brief Find an option in an option cache with the name as key */ +static GLuint findOption (const driOptionCache *cache, const char *name) { + GLuint len = strlen (name); + GLuint size = 1 << cache->tableSize, mask = size - 1; + GLuint hash = 0; + GLuint i, shift; + + /* compute a hash from the variable length name */ + for (i = 0, shift = 0; i < len; ++i, shift = (shift+8) & 31) + hash += (GLuint)name[i] << shift; + hash *= hash; + hash = (hash >> (16-cache->tableSize/2)) & mask; + + /* this is just the starting point of the linear search for the option */ + for (i = 0; i < size; ++i, hash = (hash+1) & mask) { + /* if we hit an empty entry then the option is not defined (yet) */ + if (cache->info[hash].name == 0) + break; + else if (!strcmp (name, cache->info[hash].name)) + break; + } + /* this assertion fails if the hash table is full */ + assert (i < size); + + return hash; +} + +/** \brief Count the real number of options in an option cache */ +static GLuint countOptions (const driOptionCache *cache) { + GLuint size = 1 << cache->tableSize; + GLuint i, count = 0; + for (i = 0; i < size; ++i) + if (cache->info[i].name) + count++; + return count; +} + +/** \brief Like strdup but using MALLOC and with error checking. */ +#define XSTRDUP(dest,source) do { \ + GLuint len = strlen (source); \ + if (!(dest = MALLOC (len+1))) { \ + fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); \ + abort(); \ + } \ + memcpy (dest, source, len+1); \ +} while (0) + +static int compare (const void *a, const void *b) { + return strcmp (*(char *const*)a, *(char *const*)b); +} +/** \brief Binary search in a string array. */ +static GLuint bsearchStr (const XML_Char *name, + const XML_Char *elems[], GLuint count) { + const XML_Char **found; + found = bsearch (&name, elems, count, sizeof (XML_Char *), compare); + if (found) + return found - elems; + else + return count; +} + +/** \brief Locale-independent integer parser. + * + * Works similar to strtol. Leading space is NOT skipped. The input + * number may have an optional sign. Radix is specified by base. If + * base is 0 then decimal is assumed unless the input number is + * prefixed by 0x or 0X for hexadecimal or 0 for octal. After + * returning tail points to the first character that is not part of + * the integer number. If no number was found then tail points to the + * start of the input string. */ +static GLint strToI (const XML_Char *string, const XML_Char **tail, int base) { + GLint radix = base == 0 ? 10 : base; + GLint result = 0; + GLint sign = 1; + GLboolean numberFound = GL_FALSE; + const XML_Char *start = string; + + assert (radix >= 2 && radix <= 36); + + if (*string == '-') { + sign = -1; + string++; + } else if (*string == '+') + string++; + if (base == 0 && *string == '0') { + numberFound = GL_TRUE; + if (*(string+1) == 'x' || *(string+1) == 'X') { + radix = 16; + string += 2; + } else { + radix = 8; + string++; + } + } + do { + GLint digit = -1; + if (radix <= 10) { + if (*string >= '0' && *string < '0' + radix) + digit = *string - '0'; + } else { + if (*string >= '0' && *string <= '9') + digit = *string - '0'; + else if (*string >= 'a' && *string < 'a' + radix - 10) + digit = *string - 'a' + 10; + else if (*string >= 'A' && *string < 'A' + radix - 10) + digit = *string - 'A' + 10; + } + if (digit != -1) { + numberFound = GL_TRUE; + result = radix*result + digit; + string++; + } else + break; + } while (GL_TRUE); + *tail = numberFound ? string : start; + return sign * result; +} + +/** \brief Locale-independent floating-point parser. + * + * Works similar to strtod. Leading space is NOT skipped. The input + * number may have an optional sign. '.' is interpreted as decimal + * point and may occur at most once. Optionally the number may end in + * [eE], where is an integer as recognized by + * strToI. In that case the result is number * 10^exponent. After + * returning tail points to the first character that is not part of + * the floating point number. If no number was found then tail points + * to the start of the input string. + * + * Uses two passes for maximum accuracy. */ +static GLfloat strToF (const XML_Char *string, const XML_Char **tail) { + GLint nDigits = 0, pointPos, exponent; + GLfloat sign = 1.0f, result = 0.0f, scale; + const XML_Char *start = string, *numStart; + + /* sign */ + if (*string == '-') { + sign = -1.0f; + string++; + } else if (*string == '+') + string++; + + /* first pass: determine position of decimal point, number of + * digits, exponent and the end of the number. */ + numStart = string; + while (*string >= '0' && *string <= '9') { + string++; + nDigits++; + } + pointPos = nDigits; + if (*string == '.') { + string++; + while (*string >= '0' && *string <= '9') { + string++; + nDigits++; + } + } + if (nDigits == 0) { + /* no digits, no number */ + *tail = start; + return 0.0f; + } + *tail = string; + if (*string == 'e' || *string == 'E') { + const XML_Char *expTail; + exponent = strToI (string+1, &expTail, 10); + if (expTail == string+1) + exponent = 0; + else + *tail = expTail; + } else + exponent = 0; + string = numStart; + + /* scale of the first digit */ + scale = sign * (GLfloat)pow (10.0, (GLdouble)(pointPos-1 + exponent)); + + /* second pass: parse digits */ + do { + if (*string != '.') { + assert (*string >= '0' && *string <= '9'); + result += scale * (GLfloat)(*string - '0'); + scale *= 0.1f; + nDigits--; + } + string++; + } while (nDigits > 0); + + return result; +} + +/** \brief Parse a value of a given type. */ +static GLboolean parseValue (driOptionValue *v, driOptionType type, + const XML_Char *string) { + const XML_Char *tail = NULL; + /* skip leading white-space */ + string += strspn (string, " \f\n\r\t\v"); + switch (type) { + case DRI_BOOL: + if (!strcmp (string, "false")) { + v->_bool = GL_FALSE; + tail = string + 5; + } else if (!strcmp (string, "true")) { + v->_bool = GL_TRUE; + tail = string + 4; + } + else + return GL_FALSE; + break; + case DRI_ENUM: /* enum is just a special integer */ + case DRI_INT: + v->_int = strToI (string, &tail, 0); + break; + case DRI_FLOAT: + v->_float = strToF (string, &tail); + break; + } + + if (tail == string) + return GL_FALSE; /* empty string (or containing only white-space) */ + /* skip trailing white space */ + if (*tail) + tail += strspn (tail, " \f\n\r\t\v"); + if (*tail) + return GL_FALSE; /* something left over that is not part of value */ + + return GL_TRUE; +} + +/** \brief Parse a list of ranges of type info->type. */ +static GLboolean parseRanges (driOptionInfo *info, const XML_Char *string) { + XML_Char *cp, *range; + GLuint nRanges, i; + driOptionRange *ranges; + + XSTRDUP (cp, string); + /* pass 1: determine the number of ranges (number of commas + 1) */ + range = cp; + for (nRanges = 1; *range; ++range) + if (*range == ',') + ++nRanges; + + if ((ranges = MALLOC (nRanges*sizeof(driOptionRange))) == NULL) { + fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); + abort(); + } + + /* pass 2: parse all ranges into preallocated array */ + range = cp; + for (i = 0; i < nRanges; ++i) { + XML_Char *end, *sep; + assert (range); + end = strchr (range, ','); + if (end) + *end = '\0'; + sep = strchr (range, ':'); + if (sep) { /* non-empty interval */ + *sep = '\0'; + if (!parseValue (&ranges[i].start, info->type, range) || + !parseValue (&ranges[i].end, info->type, sep+1)) + break; + if (info->type == DRI_INT && + ranges[i].start._int > ranges[i].end._int) + break; + if (info->type == DRI_FLOAT && + ranges[i].start._float > ranges[i].end._float) + break; + } else { /* empty interval */ + if (!parseValue (&ranges[i].start, info->type, range)) + break; + ranges[i].end = ranges[i].start; + } + if (end) + range = end+1; + else + range = NULL; + } + FREE (cp); + if (i < nRanges) { + FREE (ranges); + return GL_FALSE; + } else + assert (range == NULL); + + info->nRanges = nRanges; + info->ranges = ranges; + return GL_TRUE; +} + +/** \brief Check if a value is in one of info->ranges. */ +static GLboolean checkValue (const driOptionValue *v, const driOptionInfo *info) { + GLuint i; + assert (info->type != DRI_BOOL); /* should be caught by the parser */ + if (info->nRanges == 0) + return GL_TRUE; + switch (info->type) { + case DRI_ENUM: /* enum is just a special integer */ + case DRI_INT: + for (i = 0; i < info->nRanges; ++i) + if (v->_int >= info->ranges[i].start._int && + v->_int <= info->ranges[i].end._int) + return GL_TRUE; + break; + case DRI_FLOAT: + for (i = 0; i < info->nRanges; ++i) + if (v->_float >= info->ranges[i].start._float && + v->_float <= info->ranges[i].end._float) + return GL_TRUE; + break; + default: + assert (0); /* should never happen */ + } + return GL_FALSE; +} + +/** \brief Output a warning message. */ +#define XML_WARNING1(msg) do {\ + __driUtilMessage ("Warning in %s line %d, column %d: "msg, data->name, \ + (int) XML_GetCurrentLineNumber(data->parser), \ + (int) XML_GetCurrentColumnNumber(data->parser)); \ +} while (0) +#define XML_WARNING(msg,args...) do { \ + __driUtilMessage ("Warning in %s line %d, column %d: "msg, data->name, \ + (int) XML_GetCurrentLineNumber(data->parser), \ + (int) XML_GetCurrentColumnNumber(data->parser), \ + args); \ +} while (0) +/** \brief Output an error message. */ +#define XML_ERROR1(msg) do { \ + __driUtilMessage ("Error in %s line %d, column %d: "msg, data->name, \ + (int) XML_GetCurrentLineNumber(data->parser), \ + (int) XML_GetCurrentColumnNumber(data->parser)); \ +} while (0) +#define XML_ERROR(msg,args...) do { \ + __driUtilMessage ("Error in %s line %d, column %d: "msg, data->name, \ + (int) XML_GetCurrentLineNumber(data->parser), \ + (int) XML_GetCurrentColumnNumber(data->parser), \ + args); \ +} while (0) +/** \brief Output a fatal error message and abort. */ +#define XML_FATAL1(msg) do { \ + fprintf (stderr, "Fatal error in %s line %d, column %d: "msg"\n", \ + data->name, \ + (int) XML_GetCurrentLineNumber(data->parser), \ + (int) XML_GetCurrentColumnNumber(data->parser)); \ + abort();\ +} while (0) +#define XML_FATAL(msg,args...) do { \ + fprintf (stderr, "Fatal error in %s line %d, column %d: "msg"\n", \ + data->name, \ + (int) XML_GetCurrentLineNumber(data->parser), \ + (int) XML_GetCurrentColumnNumber(data->parser), \ + args); \ + abort();\ +} while (0) + +/** \brief Parser context for __driConfigOptions. */ +struct OptInfoData { + const char *name; + XML_Parser parser; + driOptionCache *cache; + GLboolean inDriInfo; + GLboolean inSection; + GLboolean inDesc; + GLboolean inOption; + GLboolean inEnum; + int curOption; +}; + +/** \brief Elements in __driConfigOptions. */ +enum OptInfoElem { + OI_DESCRIPTION = 0, OI_DRIINFO, OI_ENUM, OI_OPTION, OI_SECTION, OI_COUNT +}; +static const XML_Char *OptInfoElems[] = { + "description", "driinfo", "enum", "option", "section" +}; + +/** \brief Parse attributes of an enum element. + * + * We're not actually interested in the data. Just make sure this is ok + * for external configuration tools. + */ +static void parseEnumAttr (struct OptInfoData *data, const XML_Char **attr) { + GLuint i; + const XML_Char *value = NULL, *text = NULL; + driOptionValue v; + GLuint opt = data->curOption; + for (i = 0; attr[i]; i += 2) { + if (!strcmp (attr[i], "value")) value = attr[i+1]; + else if (!strcmp (attr[i], "text")) text = attr[i+1]; + else XML_FATAL("illegal enum attribute: %s.", attr[i]); + } + if (!value) XML_FATAL1 ("value attribute missing in enum."); + if (!text) XML_FATAL1 ("text attribute missing in enum."); + if (!parseValue (&v, data->cache->info[opt].type, value)) + XML_FATAL ("illegal enum value: %s.", value); + if (!checkValue (&v, &data->cache->info[opt])) + XML_FATAL ("enum value out of valid range: %s.", value); +} + +/** \brief Parse attributes of a description element. + * + * We're not actually interested in the data. Just make sure this is ok + * for external configuration tools. + */ +static void parseDescAttr (struct OptInfoData *data, const XML_Char **attr) { + GLuint i; + const XML_Char *lang = NULL, *text = NULL; + for (i = 0; attr[i]; i += 2) { + if (!strcmp (attr[i], "lang")) lang = attr[i+1]; + else if (!strcmp (attr[i], "text")) text = attr[i+1]; + else XML_FATAL("illegal description attribute: %s.", attr[i]); + } + if (!lang) XML_FATAL1 ("lang attribute missing in description."); + if (!text) XML_FATAL1 ("text attribute missing in description."); +} + +/** \brief Parse attributes of an option element. */ +static void parseOptInfoAttr (struct OptInfoData *data, const XML_Char **attr) { + enum OptAttr {OA_DEFAULT = 0, OA_NAME, OA_TYPE, OA_VALID, OA_COUNT}; + static const XML_Char *optAttr[] = {"default", "name", "type", "valid"}; + const XML_Char *attrVal[OA_COUNT] = {NULL, NULL, NULL, NULL}; + const char *defaultVal; + driOptionCache *cache = data->cache; + GLuint opt, i; + for (i = 0; attr[i]; i += 2) { + GLuint attrName = bsearchStr (attr[i], optAttr, OA_COUNT); + if (attrName >= OA_COUNT) + XML_FATAL ("illegal option attribute: %s", attr[i]); + attrVal[attrName] = attr[i+1]; + } + if (!attrVal[OA_NAME]) XML_FATAL1 ("name attribute missing in option."); + if (!attrVal[OA_TYPE]) XML_FATAL1 ("type attribute missing in option."); + if (!attrVal[OA_DEFAULT]) XML_FATAL1 ("default attribute missing in option."); + + opt = findOption (cache, attrVal[OA_NAME]); + if (cache->info[opt].name) + XML_FATAL ("option %s redefined.", attrVal[OA_NAME]); + data->curOption = opt; + + XSTRDUP (cache->info[opt].name, attrVal[OA_NAME]); + + if (!strcmp (attrVal[OA_TYPE], "bool")) + cache->info[opt].type = DRI_BOOL; + else if (!strcmp (attrVal[OA_TYPE], "enum")) + cache->info[opt].type = DRI_ENUM; + else if (!strcmp (attrVal[OA_TYPE], "int")) + cache->info[opt].type = DRI_INT; + else if (!strcmp (attrVal[OA_TYPE], "float")) + cache->info[opt].type = DRI_FLOAT; + else + XML_FATAL ("illegal type in option: %s.", attrVal[OA_TYPE]); + + defaultVal = getenv (cache->info[opt].name); + if (defaultVal != NULL) { + /* don't use XML_WARNING, we want the user to see this! */ + fprintf (stderr, + "ATTENTION: default value of option %s overridden by environment.\n", + cache->info[opt].name); + } else + defaultVal = attrVal[OA_DEFAULT]; + if (!parseValue (&cache->values[opt], cache->info[opt].type, defaultVal)) + XML_FATAL ("illegal default value: %s.", defaultVal); + + if (attrVal[OA_VALID]) { + if (cache->info[opt].type == DRI_BOOL) + XML_FATAL1 ("boolean option with valid attribute."); + if (!parseRanges (&cache->info[opt], attrVal[OA_VALID])) + XML_FATAL ("illegal valid attribute: %s.", attrVal[OA_VALID]); + if (!checkValue (&cache->values[opt], &cache->info[opt])) + XML_FATAL ("default value out of valid range '%s': %s.", + attrVal[OA_VALID], defaultVal); + } else if (cache->info[opt].type == DRI_ENUM) { + XML_FATAL1 ("valid attribute missing in option (mandatory for enums)."); + } else { + cache->info[opt].nRanges = 0; + cache->info[opt].ranges = NULL; + } +} + +/** \brief Handler for start element events. */ +static void optInfoStartElem (void *userData, const XML_Char *name, + const XML_Char **attr) { + struct OptInfoData *data = (struct OptInfoData *)userData; + enum OptInfoElem elem = bsearchStr (name, OptInfoElems, OI_COUNT); + switch (elem) { + case OI_DRIINFO: + if (data->inDriInfo) + XML_FATAL1 ("nested elements."); + if (attr[0]) + XML_FATAL1 ("attributes specified on element."); + data->inDriInfo = GL_TRUE; + break; + case OI_SECTION: + if (!data->inDriInfo) + XML_FATAL1 ("
    must be inside ."); + if (data->inSection) + XML_FATAL1 ("nested
    elements."); + if (attr[0]) + XML_FATAL1 ("attributes specified on
    element."); + data->inSection = GL_TRUE; + break; + case OI_DESCRIPTION: + if (!data->inSection && !data->inOption) + XML_FATAL1 (" must be inside or inDesc) + XML_FATAL1 ("nested elements."); + data->inDesc = GL_TRUE; + parseDescAttr (data, attr); + break; + case OI_OPTION: + if (!data->inSection) + XML_FATAL1 ("